blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 7 139 | content_id stringlengths 40 40 | detected_licenses listlengths 0 16 | license_type stringclasses 2
values | repo_name stringlengths 7 55 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 6
values | visit_date int64 1,471B 1,694B | revision_date int64 1,378B 1,694B | committer_date int64 1,378B 1,694B | github_id float64 1.33M 604M ⌀ | star_events_count int64 0 43.5k | fork_events_count int64 0 1.5k | gha_license_id stringclasses 6
values | gha_event_created_at int64 1,402B 1,695B ⌀ | gha_created_at int64 1,359B 1,637B ⌀ | gha_language stringclasses 19
values | src_encoding stringclasses 2
values | language stringclasses 1
value | is_vendor bool 1
class | is_generated bool 1
class | length_bytes int64 3 6.4M | extension stringclasses 4
values | content stringlengths 3 6.12M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8d3f413d468db32d62049498d24d0fca31ebfd2e | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /src/Lean/Elab/DeclModifiers.lean | e689a46440ec88898cb999cb446b33d285239a0e | [
"Apache-2.0"
] | permissive | williamdemeo/lean4 | 72161c58fe65c3ad955d6a3050bb7d37c04c0d54 | 6d00fcf1d6d873e195f9220c668ef9c58e9c4a35 | refs/heads/master | 1,678,305,356,877 | 1,614,708,995,000 | 1,614,708,995,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,979 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.Modifiers
import Lean.DocString
import Lean.Elab.Attributes
import Lean.Elab.Exception
import Lean.Elab.DeclUtil
namespace Lean.Elab
def checkNotAlreadyDeclared {m} [Monad m] [MonadEnv m] [MonadError m] (declName : Name) : m Unit := do
let env ← getEnv
if env.contains declName then
match privateToUserName? declName with
| none => throwError! "'{declName}' has already been declared"
| some declName => throwError! "private declaration '{declName}' has already been declared"
if env.contains (mkPrivateName env declName) then
throwError! "a private declaration '{declName}' has already been declared"
match privateToUserName? declName with
| none => pure ()
| some declName =>
if env.contains declName then
throwError! "a non-private declaration '{declName}' has already been declared"
inductive Visibility where
| regular | «protected» | «private»
deriving Inhabited
instance : ToString Visibility := ⟨fun
| Visibility.regular => "regular"
| Visibility.«private» => "private"
| Visibility.«protected» => "protected"⟩
structure Modifiers where
docString? : Option String := none
visibility : Visibility := Visibility.regular
isNoncomputable : Bool := false
isPartial : Bool := false
isUnsafe : Bool := false
attrs : Array Attribute := #[]
deriving Inhabited
def Modifiers.isPrivate : Modifiers → Bool
| { visibility := Visibility.private, .. } => true
| _ => false
def Modifiers.isProtected : Modifiers → Bool
| { visibility := Visibility.protected, .. } => true
| _ => false
def Modifiers.addAttribute (modifiers : Modifiers) (attr : Attribute) : Modifiers :=
{ modifiers with attrs := modifiers.attrs.push attr }
instance : ToFormat Modifiers := ⟨fun m =>
let components : List Format :=
(match m.docString? with
| some str => [f!"/--{str}-/"]
| none => [])
++ (match m.visibility with
| Visibility.regular => []
| Visibility.protected => [f!"protected"]
| Visibility.private => [f!"private"])
++ (if m.isNoncomputable then [f!"noncomputable"] else [])
++ (if m.isPartial then [f!"partial"] else [])
++ (if m.isUnsafe then [f!"unsafe"] else [])
++ m.attrs.toList.map (fun attr => fmt attr)
Format.bracket "{" (Format.joinSep components ("," ++ Format.line)) "}"⟩
instance : ToString Modifiers := ⟨toString ∘ format⟩
def expandOptDocComment? [Monad m] [MonadError m] (optDocComment : Syntax) : m (Option String) :=
match optDocComment.getOptional? with
| none => pure none
| some s => match s[1] with
| Syntax.atom _ val => pure (some (val.extract 0 (val.bsize - 2)))
| _ => throwErrorAt! s "unexpected doc string {s[1]}"
section Methods
variable [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] [MonadMacroAdapter m] [MonadRecDepth m]
def elabModifiers (stx : Syntax) : m Modifiers := do
let docCommentStx := stx[0]
let attrsStx := stx[1]
let visibilityStx := stx[2]
let noncompStx := stx[3]
let unsafeStx := stx[4]
let partialStx := stx[5]
let docString? ← match docCommentStx.getOptional? with
| none => pure none
| some s => match s[1] with
| Syntax.atom _ val => pure (some (val.extract 0 (val.bsize - 2)))
| _ => throwErrorAt! s "unexpected doc string {s[1]}"
let visibility ← match visibilityStx.getOptional? with
| none => pure Visibility.regular
| some v =>
let kind := v.getKind
if kind == `Lean.Parser.Command.private then pure Visibility.private
else if kind == `Lean.Parser.Command.protected then pure Visibility.protected
else throwErrorAt v "unexpected visibility modifier"
let attrs ← match attrsStx.getOptional? with
| none => pure #[]
| some attrs => elabDeclAttrs attrs
pure {
docString? := docString?,
visibility := visibility,
isPartial := !partialStx.isNone,
isUnsafe := !unsafeStx.isNone,
isNoncomputable := !noncompStx.isNone,
attrs := attrs
}
def applyVisibility (visibility : Visibility) (declName : Name) : m Name := do
match visibility with
| Visibility.private =>
let env ← getEnv
let declName := mkPrivateName env declName
checkNotAlreadyDeclared declName
pure declName
| Visibility.protected =>
checkNotAlreadyDeclared declName
let env ← getEnv
let env := addProtected env declName
setEnv env
pure declName
| _ =>
checkNotAlreadyDeclared declName
pure declName
def mkDeclName (currNamespace : Name) (modifiers : Modifiers) (shortName : Name) : m (Name × Name) := do
let name := (extractMacroScopes shortName).name
unless name.isAtomic || isFreshInstanceName name do
throwError! "atomic identifier expected '{shortName}'"
let declName := currNamespace ++ shortName
let declName ← applyVisibility modifiers.visibility declName
match modifiers.visibility with
| Visibility.protected =>
match currNamespace with
| Name.str _ s _ => pure (declName, Name.mkSimple s ++ shortName)
| _ => throwError "protected declarations must be in a namespace"
| _ => pure (declName, shortName)
/-
`declId` is of the form
```
parser! ident >> optional (".{" >> sepBy1 ident ", " >> "}")
```
but we also accept a single identifier to users to make macro writing more convenient .
-/
def expandDeclIdCore (declId : Syntax) : Name × Syntax :=
if declId.isIdent then
(declId.getId, mkNullNode)
else
let id := declId[0].getId
let optUnivDeclStx := declId[1]
(id, optUnivDeclStx)
structure ExpandDeclIdResult where
shortName : Name
declName : Name
levelNames : List Name
def expandDeclId (currNamespace : Name) (currLevelNames : List Name) (declId : Syntax) (modifiers : Modifiers) : m ExpandDeclIdResult := do
-- ident >> optional (".{" >> sepBy1 ident ", " >> "}")
let (shortName, optUnivDeclStx) := expandDeclIdCore declId
let levelNames ←
if optUnivDeclStx.isNone then
pure currLevelNames
else
let extraLevels := optUnivDeclStx[1].getArgs.getEvenElems
extraLevels.foldlM
(fun levelNames idStx =>
let id := idStx.getId
if levelNames.elem id then
withRef idStx $ throwAlreadyDeclaredUniverseLevel id
else
pure (id :: levelNames))
currLevelNames
let (declName, shortName) ← withRef declId $ mkDeclName currNamespace modifiers shortName
addDocString' declName modifiers.docString?
pure { shortName := shortName, declName := declName, levelNames := levelNames }
end Methods
end Lean.Elab
|
198c3958da76d35f88feae9623434f15f1eeb20f | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/dynamics/periodic_pts.lean | 59292cbee574e8652a84ff62adb006a4639d1d3d | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,354 | lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import dynamics.fixed_points.basic
import data.set.lattice
import data.pnat.basic
import data.int.gcd
/-!
# Periodic points
A point `x : α` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`.
## Main definitions
* `is_periodic_pt f n x` : `x` is a periodic point of `f` of period `n`, i.e. `f^[n] x = x`.
We do not require `n > 0` in the definition.
* `pts_of_period f n` : the set `{x | is_periodic_pt f n x}`. Note that `n` is not required to
be the minimal period of `x`.
* `periodic_pts f` : the set of all periodic points of `f`.
* `minimal_period f x` : the minimal period of a point `x` under an endomorphism `f` or zero
if `x` is not a periodic point of `f`.
## Main statements
We provide “dot syntax”-style operations on terms of the form `h : is_periodic_pt f n x` including
arithmetic operations on `n` and `h.map (hg : semiconj_by g f f')`. We also prove that `f`
is bijective on each set `pts_of_period f n` and on `periodic_pts f`. Finally, we prove that `x`
is a periodic point of `f` of period `n` if and only if `minimal_period f x | n`.
## References
* https://en.wikipedia.org/wiki/Periodic_point
-/
open set
namespace function
variables {α : Type*} {β : Type*} {f fa : α → α} {fb : β → β} {x y : α} {m n : ℕ}
/-- A point `x` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`.
Note that we do not require `0 < n` in this definition. Many theorems about periodic points
need this assumption. -/
def is_periodic_pt (f : α → α) (n : ℕ) (x : α) := is_fixed_pt (f^[n]) x
/-- A fixed point of `f` is a periodic point of `f` of any prescribed period. -/
lemma is_fixed_pt.is_periodic_pt (hf : is_fixed_pt f x) (n : ℕ) : is_periodic_pt f n x :=
hf.iterate n
/-- For the identity map, all points are periodic. -/
lemma is_periodic_id (n : ℕ) (x : α) : is_periodic_pt id n x := (is_fixed_pt_id x).is_periodic_pt n
/-- Any point is a periodic point of period `0`. -/
lemma is_periodic_pt_zero (f : α → α) (x : α) : is_periodic_pt f 0 x := is_fixed_pt_id x
namespace is_periodic_pt
instance [decidable_eq α] {f : α → α} {n : ℕ} {x : α} : decidable (is_periodic_pt f n x) :=
is_fixed_pt.decidable
protected lemma is_fixed_pt (hf : is_periodic_pt f n x) : is_fixed_pt (f^[n]) x := hf
protected lemma map (hx : is_periodic_pt fa n x) {g : α → β} (hg : semiconj g fa fb) :
is_periodic_pt fb n (g x) :=
hx.map (hg.iterate_right n)
lemma apply_iterate (hx : is_periodic_pt f n x) (m : ℕ) : is_periodic_pt f n (f^[m] x) :=
hx.map $ commute.iterate_self f m
protected lemma apply (hx : is_periodic_pt f n x) : is_periodic_pt f n (f x) :=
hx.apply_iterate 1
protected lemma add (hn : is_periodic_pt f n x) (hm : is_periodic_pt f m x) :
is_periodic_pt f (n + m) x :=
by { rw [is_periodic_pt, iterate_add], exact hn.comp hm }
lemma left_of_add (hn : is_periodic_pt f (n + m) x) (hm : is_periodic_pt f m x) :
is_periodic_pt f n x :=
by { rw [is_periodic_pt, iterate_add] at hn, exact hn.left_of_comp hm }
lemma right_of_add (hn : is_periodic_pt f (n + m) x) (hm : is_periodic_pt f n x) :
is_periodic_pt f m x :=
by { rw add_comm at hn, exact hn.left_of_add hm }
protected lemma sub (hm : is_periodic_pt f m x) (hn : is_periodic_pt f n x) :
is_periodic_pt f (m - n) x :=
begin
cases le_total n m with h h,
{ refine left_of_add _ hn,
rwa [tsub_add_cancel_of_le h] },
{ rw [tsub_eq_zero_iff_le.mpr h],
apply is_periodic_pt_zero }
end
protected lemma mul_const (hm : is_periodic_pt f m x) (n : ℕ) : is_periodic_pt f (m * n) x :=
by simp only [is_periodic_pt, iterate_mul, hm.is_fixed_pt.iterate n]
protected lemma const_mul (hm : is_periodic_pt f m x) (n : ℕ) : is_periodic_pt f (n * m) x :=
by simp only [mul_comm n, hm.mul_const n]
lemma trans_dvd (hm : is_periodic_pt f m x) {n : ℕ} (hn : m ∣ n) : is_periodic_pt f n x :=
let ⟨k, hk⟩ := hn in hk.symm ▸ hm.mul_const k
protected lemma iterate (hf : is_periodic_pt f n x) (m : ℕ) : is_periodic_pt (f^[m]) n x :=
begin
rw [is_periodic_pt, ← iterate_mul, mul_comm, iterate_mul],
exact hf.is_fixed_pt.iterate m
end
protected lemma mod (hm : is_periodic_pt f m x) (hn : is_periodic_pt f n x) :
is_periodic_pt f (m % n) x :=
begin
rw [← nat.mod_add_div m n] at hm,
exact hm.left_of_add (hn.mul_const _)
end
protected lemma gcd (hm : is_periodic_pt f m x) (hn : is_periodic_pt f n x) :
is_periodic_pt f (m.gcd n) x :=
begin
revert hm hn,
refine nat.gcd.induction m n (λ n h0 hn, _) (λ m n hm ih hm hn, _),
{ rwa [nat.gcd_zero_left], },
{ rw [nat.gcd_rec],
exact ih (hn.mod hm) hm }
end
/-- If `f` sends two periodic points `x` and `y` of the same positive period to the same point,
then `x = y`. For a similar statement about points of different periods see `eq_of_apply_eq`. -/
lemma eq_of_apply_eq_same (hx : is_periodic_pt f n x) (hy : is_periodic_pt f n y) (hn : 0 < n)
(h : f x = f y) :
x = y :=
by rw [← hx.eq, ← hy.eq, ← iterate_pred_comp_of_pos f hn, comp_app, h]
/-- If `f` sends two periodic points `x` and `y` of positive periods to the same point,
then `x = y`. -/
lemma eq_of_apply_eq (hx : is_periodic_pt f m x) (hy : is_periodic_pt f n y) (hm : 0 < m)
(hn : 0 < n) (h : f x = f y) :
x = y :=
(hx.mul_const n).eq_of_apply_eq_same (hy.const_mul m) (mul_pos hm hn) h
end is_periodic_pt
/-- The set of periodic points of a given (possibly non-minimal) period. -/
def pts_of_period (f : α → α) (n : ℕ) : set α := {x : α | is_periodic_pt f n x}
@[simp] lemma mem_pts_of_period : x ∈ pts_of_period f n ↔ is_periodic_pt f n x :=
iff.rfl
lemma semiconj.maps_to_pts_of_period {g : α → β} (h : semiconj g fa fb) (n : ℕ) :
maps_to g (pts_of_period fa n) (pts_of_period fb n) :=
(h.iterate_right n).maps_to_fixed_pts
lemma bij_on_pts_of_period (f : α → α) {n : ℕ} (hn : 0 < n) :
bij_on f (pts_of_period f n) (pts_of_period f n) :=
⟨(commute.refl f).maps_to_pts_of_period n,
λ x hx y hy hxy, hx.eq_of_apply_eq_same hy hn hxy,
λ x hx, ⟨f^[n.pred] x, hx.apply_iterate _,
by rw [← comp_app f, comp_iterate_pred_of_pos f hn, hx.eq]⟩⟩
lemma directed_pts_of_period_pnat (f : α → α) : directed (⊆) (λ n : ℕ+, pts_of_period f n) :=
λ m n, ⟨m * n, λ x hx, hx.mul_const n, λ x hx, hx.const_mul m⟩
/-- The set of periodic points of a map `f : α → α`. -/
def periodic_pts (f : α → α) : set α := {x : α | ∃ n > 0, is_periodic_pt f n x}
lemma mk_mem_periodic_pts (hn : 0 < n) (hx : is_periodic_pt f n x) :
x ∈ periodic_pts f :=
⟨n, hn, hx⟩
lemma mem_periodic_pts : x ∈ periodic_pts f ↔ ∃ n > 0, is_periodic_pt f n x := iff.rfl
variable (f)
lemma bUnion_pts_of_period : (⋃ n > 0, pts_of_period f n) = periodic_pts f :=
set.ext $ λ x, by simp [mem_periodic_pts]
lemma Union_pnat_pts_of_period : (⋃ n : ℕ+, pts_of_period f n) = periodic_pts f :=
supr_subtype.trans $ bUnion_pts_of_period f
lemma bij_on_periodic_pts : bij_on f (periodic_pts f) (periodic_pts f) :=
Union_pnat_pts_of_period f ▸
bij_on_Union_of_directed (directed_pts_of_period_pnat f) (λ i, bij_on_pts_of_period f i.pos)
variable {f}
lemma semiconj.maps_to_periodic_pts {g : α → β} (h : semiconj g fa fb) :
maps_to g (periodic_pts fa) (periodic_pts fb) :=
λ x ⟨n, hn, hx⟩, ⟨n, hn, hx.map h⟩
open_locale classical
noncomputable theory
/-- Minimal period of a point `x` under an endomorphism `f`. If `x` is not a periodic point of `f`,
then `minimal_period f x = 0`. -/
def minimal_period (f : α → α) (x : α) :=
if h : x ∈ periodic_pts f then nat.find h else 0
lemma is_periodic_pt_minimal_period (f : α → α) (x : α) :
is_periodic_pt f (minimal_period f x) x :=
begin
delta minimal_period,
split_ifs with hx,
{ exact (nat.find_spec hx).snd },
{ exact is_periodic_pt_zero f x }
end
lemma iterate_eq_mod_minimal_period : f^[n] x = (f^[n % minimal_period f x] x) :=
begin
conv_lhs { rw ← nat.mod_add_div n (minimal_period f x) },
rw [iterate_add, mul_comm, iterate_mul, comp_app],
congr,
exact is_periodic_pt.iterate (is_periodic_pt_minimal_period _ _) _,
end
lemma minimal_period_pos_of_mem_periodic_pts (hx : x ∈ periodic_pts f) :
0 < minimal_period f x :=
by simp only [minimal_period, dif_pos hx, gt_iff_lt.1 (nat.find_spec hx).fst]
lemma is_periodic_pt.minimal_period_pos (hn : 0 < n) (hx : is_periodic_pt f n x) :
0 < minimal_period f x :=
minimal_period_pos_of_mem_periodic_pts $ mk_mem_periodic_pts hn hx
lemma minimal_period_pos_iff_mem_periodic_pts :
0 < minimal_period f x ↔ x ∈ periodic_pts f :=
⟨not_imp_not.1 $ λ h,
by simp only [minimal_period, dif_neg h, lt_irrefl 0, not_false_iff],
minimal_period_pos_of_mem_periodic_pts⟩
lemma is_periodic_pt.minimal_period_le (hn : 0 < n) (hx : is_periodic_pt f n x) :
minimal_period f x ≤ n :=
begin
rw [minimal_period, dif_pos (mk_mem_periodic_pts hn hx)],
exact nat.find_min' (mk_mem_periodic_pts hn hx) ⟨hn, hx⟩
end
lemma minimal_period_id : minimal_period id x = 1 :=
((is_periodic_id _ _ ).minimal_period_le nat.one_pos).antisymm
(nat.succ_le_of_lt ((is_periodic_id _ _ ).minimal_period_pos nat.one_pos))
lemma is_fixed_point_iff_minimal_period_eq_one : minimal_period f x = 1 ↔ is_fixed_pt f x :=
begin
refine ⟨λ h, _, λ h, _⟩,
{ rw ← iterate_one f,
refine function.is_periodic_pt.is_fixed_pt _,
rw ← h,
exact is_periodic_pt_minimal_period f x },
{ exact ((h.is_periodic_pt 1).minimal_period_le nat.one_pos).antisymm
(nat.succ_le_of_lt ((h.is_periodic_pt 1).minimal_period_pos nat.one_pos)) }
end
lemma is_periodic_pt.eq_zero_of_lt_minimal_period (hx : is_periodic_pt f n x)
(hn : n < minimal_period f x) :
n = 0 :=
eq.symm $ (eq_or_lt_of_le $ n.zero_le).resolve_right $ λ hn0,
not_lt.2 (hx.minimal_period_le hn0) hn
lemma not_is_periodic_pt_of_pos_of_lt_minimal_period :
∀ {n: ℕ} (n0 : n ≠ 0) (hn : n < minimal_period f x), ¬ is_periodic_pt f n x
| 0 n0 _ := (n0 rfl).elim
| (n + 1) _ hn := λ hp, nat.succ_ne_zero _ (hp.eq_zero_of_lt_minimal_period hn)
lemma is_periodic_pt.minimal_period_dvd (hx : is_periodic_pt f n x) :
minimal_period f x ∣ n :=
(eq_or_lt_of_le $ n.zero_le).elim (λ hn0, hn0 ▸ dvd_zero _) $ λ hn0,
(nat.dvd_iff_mod_eq_zero _ _).2 $
(hx.mod $ is_periodic_pt_minimal_period f x).eq_zero_of_lt_minimal_period $
nat.mod_lt _ $ hx.minimal_period_pos hn0
lemma is_periodic_pt_iff_minimal_period_dvd :
is_periodic_pt f n x ↔ minimal_period f x ∣ n :=
⟨is_periodic_pt.minimal_period_dvd, λ h, (is_periodic_pt_minimal_period f x).trans_dvd h⟩
open nat
lemma minimal_period_eq_minimal_period_iff {g : β → β} {y : β} :
minimal_period f x = minimal_period g y ↔ ∀ n, is_periodic_pt f n x ↔ is_periodic_pt g n y :=
by simp_rw [is_periodic_pt_iff_minimal_period_dvd, dvd_right_iff_eq]
lemma minimal_period_eq_prime {p : ℕ} [hp : fact p.prime] (hper : is_periodic_pt f p x)
(hfix : ¬ is_fixed_pt f x) : minimal_period f x = p :=
(hp.out.2 _ (hper.minimal_period_dvd)).resolve_left
(mt is_fixed_point_iff_minimal_period_eq_one.1 hfix)
lemma minimal_period_eq_prime_pow {p k : ℕ} [hp : fact p.prime] (hk : ¬ is_periodic_pt f (p ^ k) x)
(hk1 : is_periodic_pt f (p ^ (k + 1)) x) : minimal_period f x = p ^ (k + 1) :=
begin
apply nat.eq_prime_pow_of_dvd_least_prime_pow hp.out;
rwa ← is_periodic_pt_iff_minimal_period_dvd
end
lemma commute.minimal_period_of_comp_dvd_lcm {g : α → α} (h : function.commute f g) :
minimal_period (f ∘ g) x ∣ nat.lcm (minimal_period f x) (minimal_period g x) :=
begin
rw [← is_periodic_pt_iff_minimal_period_dvd, is_periodic_pt, h.comp_iterate],
refine is_fixed_pt.comp _ _;
rw [← is_periodic_pt, is_periodic_pt_iff_minimal_period_dvd];
exact nat.dvd_lcm_left _ _ <|> exact dvd_lcm_right _ _
end
private lemma minimal_period_iterate_eq_div_gcd_aux (h : 0 < gcd (minimal_period f x) n) :
minimal_period (f ^[n]) x = minimal_period f x / nat.gcd (minimal_period f x) n :=
begin
apply nat.dvd_antisymm,
{ apply is_periodic_pt.minimal_period_dvd,
rw [is_periodic_pt, is_fixed_pt, ← iterate_mul, ← nat.mul_div_assoc _ (gcd_dvd_left _ _),
mul_comm, nat.mul_div_assoc _ (gcd_dvd_right _ _), mul_comm, iterate_mul],
exact (is_periodic_pt_minimal_period f x).iterate _ },
{ apply coprime.dvd_of_dvd_mul_right (coprime_div_gcd_div_gcd h),
apply dvd_of_mul_dvd_mul_right h,
rw [nat.div_mul_cancel (gcd_dvd_left _ _), mul_assoc, nat.div_mul_cancel (gcd_dvd_right _ _),
mul_comm],
apply is_periodic_pt.minimal_period_dvd,
rw [is_periodic_pt, is_fixed_pt, iterate_mul],
exact is_periodic_pt_minimal_period _ _ }
end
lemma minimal_period_iterate_eq_div_gcd (h : n ≠ 0) :
minimal_period (f ^[n]) x = minimal_period f x / nat.gcd (minimal_period f x) n :=
minimal_period_iterate_eq_div_gcd_aux $ gcd_pos_of_pos_right _ (nat.pos_of_ne_zero h)
lemma minimal_period_iterate_eq_div_gcd' (h : x ∈ periodic_pts f) :
minimal_period (f ^[n]) x = minimal_period f x / nat.gcd (minimal_period f x) n :=
minimal_period_iterate_eq_div_gcd_aux $
gcd_pos_of_pos_left n (minimal_period_pos_iff_mem_periodic_pts.mpr h)
end function
|
961b637801b95b9b578b9f267b6b2bd38d8883c2 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/theories/topology/basic.lean | 39bbe89d8cd28a25e16dbf69bebccd8f12231519 | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 11,304 | lean | /-
Copyright (c) 2015 Jacob Gross. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jacob Gross, Jeremy Avigad
Open and closed sets, seperation axioms and generated topologies.
-/
import data.set data.nat
open algebra eq.ops set nat
structure topology [class] (X : Type) :=
(opens : set (set X))
(univ_mem_opens : univ ∈ opens)
(sUnion_mem_opens : ∀ {S : set (set X)}, S ⊆ opens → ⋃₀ S ∈ opens)
(inter_mem_opens : ∀₀ s ∈ opens, ∀₀ t ∈ opens, s ∩ t ∈ opens)
namespace topology
variables {X : Type} [topology X]
/- open sets -/
definition Open (s : set X) : Prop := s ∈ opens X
theorem Open_empty : Open (∅ : set X) :=
have ∅ ⊆ opens X, from empty_subset _,
have ⋃₀ ∅ ∈ opens X, from sUnion_mem_opens this,
show ∅ ∈ opens X, by rewrite -sUnion_empty; apply this
theorem Open_univ : Open (univ : set X) :=
univ_mem_opens X
theorem Open_sUnion {S : set (set X)} (H : ∀₀ t ∈ S, Open t) : Open (⋃₀ S) :=
sUnion_mem_opens H
theorem Open_Union {I : Type} {s : I → set X} (H : ∀ i, Open (s i)) : Open (⋃ i, s i) :=
have ∀₀ t ∈ s ' univ, Open t,
from take t, suppose t ∈ s ' univ,
obtain i [univi (Hi : s i = t)], from this,
show Open t, by rewrite -Hi; exact H i,
using this, by rewrite Union_eq_sUnion_image; apply Open_sUnion this
theorem Open_union {s t : set X} (Hs : Open s) (Ht : Open t) : Open (s ∪ t) :=
have ∀ i, Open (bin_ext s t i), by intro i; cases i; exact Hs; exact Ht,
show Open (s ∪ t), by rewrite -Union_bin_ext; exact Open_Union this
theorem Open_inter {s t : set X} (Hs : Open s) (Ht : Open t) : Open (s ∩ t) :=
inter_mem_opens X Hs Ht
theorem Open_sInter_of_finite {s : set (set X)} [fins : finite s] (H : ∀₀ t ∈ s, Open t) :
Open (⋂₀ s) :=
begin
induction fins with a s fins anins ih,
{rewrite sInter_empty, exact Open_univ},
rewrite sInter_insert,
apply Open_inter,
show Open a, from H (mem_insert a s),
apply ih, intros t ts,
show Open t, from H (mem_insert_of_mem a ts)
end
/- closed sets -/
attribute [reducible]
definition closed (s : set X) : Prop := Open (-s)
theorem closed_iff_Open_compl (s : set X) : closed s ↔ Open (-s) := !iff.refl
theorem Open_iff_closed_compl (s : set X) : Open s ↔ closed (-s) :=
by rewrite [closed_iff_Open_compl, compl_compl]
theorem closed_compl {s : set X} (H : Open s) : closed (-s) :=
by rewrite [-Open_iff_closed_compl]; apply H
theorem closed_empty : closed (∅ : set X) :=
by rewrite [↑closed, compl_empty]; exact Open_univ
theorem closed_univ : closed (univ : set X) :=
by rewrite [↑closed, compl_univ]; exact Open_empty
theorem closed_sInter {S : set (set X)} (H : ∀₀ t ∈ S, closed t) : closed (⋂₀ S) :=
begin
rewrite [↑closed, compl_sInter],
apply Open_sUnion,
intro t,
rewrite [mem_image_compl, Open_iff_closed_compl],
apply H
end
theorem closed_Inter {I : Type} {s : I → set X} (H : ∀ i, closed (s i : set X)) :
closed (⋂ i, s i) :=
by rewrite [↑closed, compl_Inter]; apply Open_Union; apply H
theorem closed_inter {s t : set X} (Hs : closed s) (Ht : closed t) : closed (s ∩ t) :=
by rewrite [↑closed, compl_inter]; apply Open_union; apply Hs; apply Ht
theorem closed_union {s t : set X} (Hs : closed s) (Ht : closed t) : closed (s ∪ t) :=
by rewrite [↑closed, compl_union]; apply Open_inter; apply Hs; apply Ht
theorem closed_sUnion_of_finite {s : set (set X)} [fins : finite s] (H : ∀₀ t ∈ s, closed t) :
closed (⋂₀ s) :=
begin
rewrite [↑closed, compl_sInter],
apply Open_sUnion,
intro t,
rewrite [mem_image_compl, Open_iff_closed_compl],
apply H
end
theorem open_diff {s t : set X} (Hs : Open s) (Ht : closed t) : Open (s \ t) :=
Open_inter Hs Ht
theorem closed_diff {s t : set X} (Hs : closed s) (Ht : Open t) : closed (s \ t) :=
closed_inter Hs (closed_compl Ht)
section
local attribute classical.prop_decidable [instance]
theorem Open_of_forall_exists_Open_nbhd {s : set X} (H : ∀₀ x ∈ s, ∃ tx : set X, Open tx ∧ x ∈ tx ∧ tx ⊆ s) :
Open s :=
let Hset : X → set X := λ x, if Hxs : x ∈ s then some (H Hxs) else univ in
let sFam := image (λ x, Hset x) s in
have H_union_open : Open (⋃₀ sFam), from Open_sUnion
(take t : set X, suppose t ∈ sFam,
have H_preim : ∃ t', t' ∈ s ∧ Hset t' = t, from this,
obtain t' (Ht' : t' ∈ s) (Ht't : Hset t' = t), from H_preim,
have HHsett : t = some (H Ht'), from Ht't ▸ dif_pos Ht',
show Open t, from and.left (HHsett⁻¹ ▸ some_spec (H Ht'))),
have H_subset_union : s ⊆ ⋃₀ sFam, from
(take x : X, suppose x ∈ s,
have HxHset : x ∈ Hset x, from (dif_pos this)⁻¹ ▸ (and.left (and.right (some_spec (H this)))),
show x ∈ ⋃₀ sFam, from mem_sUnion HxHset (mem_image this rfl)),
have H_union_subset : ⋃₀ sFam ⊆ s, from
(take x : X, suppose x ∈ ⋃₀ sFam,
obtain (t : set X) (Ht : t ∈ sFam) (Hxt : x ∈ t), from this,
have H_preim : ∃ t', t' ∈ s ∧ Hset t' = t, from Ht,
obtain t' (Ht' : t' ∈ s) (Ht't : Hset t' = t), from H_preim,
have HHsett : t = some (H Ht'), from Ht't ▸ dif_pos Ht',
have t ⊆ s, from and.right (and.right (HHsett⁻¹ ▸ some_spec (H Ht'))),
show x ∈ s, from this Hxt),
have H_union_eq : ⋃₀ sFam = s, from eq_of_subset_of_subset H_union_subset H_subset_union,
show Open s, from H_union_eq ▸ H_union_open
end
end topology
/- separation -/
structure T0_space [class] (X : Type) extends topology X :=
(T0 : ∀ {x y}, x ≠ y → ∃ U, U ∈ opens ∧ ¬(x ∈ U ↔ y ∈ U))
namespace topology
variables {X : Type} [T0_space X]
theorem separation_T0 {x y : X} : x ≠ y ↔ ∃ U, Open U ∧ ¬(x ∈ U ↔ y ∈ U) :=
iff.intro
(T0_space.T0)
(assume H, obtain U [OpU xyU], from H,
suppose x = y,
have x ∈ U ↔ y ∈ U, from iff.intro
(assume xU, this ▸ xU)
(assume yU, this⁻¹ ▸ yU),
absurd this xyU)
end topology
structure T1_space [class] (X : Type) extends topology X :=
(T1 : ∀ {x y}, x ≠ y → ∃ U, U ∈ opens ∧ x ∈ U ∧ y ∉ U)
attribute [trans_instance]
protected definition T0_space.of_T1 {X : Type} [T : T1_space X] :
T0_space X :=
⦃T0_space, T,
T0 := abstract
take x y, assume H,
obtain U [Uopens [xU ynU]], from T1_space.T1 H,
exists.intro U (and.intro Uopens
(show ¬ (x ∈ U ↔ y ∈ U), from assume H, ynU (iff.mp H xU)))
end ⦄
namespace topology
variables {X : Type} [T1_space X]
theorem separation_T1 {x y : X} : x ≠ y ↔ (∃ U, Open U ∧ x ∈ U ∧ y ∉ U) :=
iff.intro
(T1_space.T1)
(suppose ∃ U, Open U ∧ x ∈ U ∧ y ∉ U,
obtain U [OpU xU nyU], from this,
suppose x = y,
absurd xU (this⁻¹ ▸ nyU))
theorem closed_singleton {a : X} : closed '{a} :=
let T := ⋃₀ {S| Open S ∧ a ∉ S} in
have Open T, from Open_sUnion (λS HS, and.elim_left HS),
have T = -'{a}, from ext(take x, iff.intro
(assume xT, assume xa,
obtain S [[OpS aS] xS], from xT,
have ∃ U, Open U ∧ x ∈ U ∧ a ∉ U, from
exists.intro S (and.intro OpS (and.intro xS aS)),
have x ≠ a, from (iff.elim_right separation_T1) this,
absurd ((iff.elim_left !mem_singleton_iff) xa) this)
(assume xa,
have x ≠ a, from not.intro(
assume H, absurd ((iff.elim_right !mem_singleton_iff) H) xa),
obtain U [OpU xU aU], from (iff.elim_left separation_T1) this,
show _, from exists.intro U (and.intro (and.intro OpU aU) xU))),
show _, from this ▸ `Open T`
end topology
structure T2_space [class] (X : Type) extends topology X :=
(T2 : ∀ {x y}, x ≠ y → ∃ U V, U ∈ opens ∧ V ∈ opens ∧ x ∈ U ∧ y ∈ V ∧ U ∩ V = ∅)
attribute [trans_instance]
protected definition T1_space.of_T2 {X : Type} [T : T2_space X] :
T1_space X :=
⦃T1_space, T,
T1 := abstract
take x y, assume H,
obtain U [V [Uopens [Vopens [xU [yV UVempty]]]]], from T2_space.T2 H,
exists.intro U (and.intro Uopens (and.intro xU
(show y ∉ U, from assume yU,
have y ∈ U ∩ V, from and.intro yU yV,
show y ∈ ∅, from UVempty ▸ this)))
end ⦄
namespace topology
variables {X : Type} [T2_space X]
theorem seperation_T2 {x y : X} : x ≠ y ↔ ∃ U V, Open U ∧ Open V ∧ x ∈ U ∧ y ∈ V ∧ U ∩ V = ∅ :=
iff.intro
(T2_space.T2)
(assume H, obtain U V [OpU OpV xU yV UV], from H,
suppose x = y,
have ¬(x ∈ U ∩ V), from not.intro(
assume xUV, absurd (UV ▸ xUV) !not_mem_empty),
absurd (and.intro xU (`x = y`⁻¹ ▸ yV)) this)
end topology
structure perfect_space [class] (X : Type) extends topology X :=
(perfect : ∀ x, '{x} ∉ opens)
/- topology generated by a set -/
namespace topology
inductive opens_generated_by {X : Type} (B : set (set X)) : set X → Prop :=
| generators_mem : ∀ ⦃s : set X⦄, s ∈ B → opens_generated_by B s
| univ_mem : opens_generated_by B univ
| inter_mem : ∀ ⦃s t⦄, opens_generated_by B s → opens_generated_by B t →
opens_generated_by B (s ∩ t)
| sUnion_mem : ∀ ⦃S : set (set X)⦄, S ⊆ opens_generated_by B → opens_generated_by B (⋃₀ S)
attribute [instance]
protected definition generated_by {X : Type} (B : set (set X)) : topology X :=
⦃topology,
opens := opens_generated_by B,
univ_mem_opens := opens_generated_by.univ_mem B,
inter_mem_opens := λ s Hs t Ht, opens_generated_by.inter_mem Hs Ht,
sUnion_mem_opens := opens_generated_by.sUnion_mem
⦄
theorem generators_mem_topology_generated_by {X : Type} (B : set (set X)) :
let T := topology.generated_by B in
∀₀ s ∈ B, @Open _ T s :=
λ s H, opens_generated_by.generators_mem H
theorem opens_generated_by_initial {X : Type} {B : set (set X)} {T : topology X} (H : B ⊆ @opens _ T) :
opens_generated_by B ⊆ @opens _ T :=
begin
intro s Hs,
induction Hs with s sB s t os ot soX toX S SB SOX,
{exact H sB},
{exact univ_mem_opens X},
{exact inter_mem_opens X soX toX},
exact sUnion_mem_opens SOX
end
theorem topology_generated_by_initial {X : Type} {B : set (set X)} {T : topology X}
(H : ∀₀ s ∈ B, @Open _ T s) {s : set X} (H1 : @Open _ (topology.generated_by B) s) :
@Open _ T s :=
opens_generated_by_initial H H1
section continuity
/- continuous mappings -/
/- continuity at a point -/
variables {M N : Type} [Tm : topology M] [Tn : topology N]
include Tm Tn
definition continuous_at (f : M → N) (x : M) :=
∀ U : set N, f x ∈ U → Open U → ∃ V : set M, x ∈ V ∧ Open V ∧ f 'V ⊆ U
definition continuous (f : M → N) :=
∀ x : M, continuous_at f x
end continuity
section boundary
variables {X : Type} [TX : topology X]
include TX
definition on_boundary (x : X) (u : set X) := ∀ v : set X, Open v → x ∈ v → u ∩ v ≠ ∅ ∧ ¬ v ⊆ u
theorem not_open_of_on_boundary {x : X} {u : set X} (Hxu : x ∈ u) (Hob : on_boundary x u) : ¬ Open u :=
begin
intro Hop,
note Hbxu := Hob _ Hop Hxu,
apply and.right Hbxu,
apply subset.refl
end
end boundary
end topology
|
45103e495afd5cc9143f5946ac59b232a0fabf4b | c777c32c8e484e195053731103c5e52af26a25d1 | /src/field_theory/adjoin.lean | 8d20609ac366519a19c044e1376e76377e17d42d | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 46,159 | lean | /-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import field_theory.intermediate_field
import field_theory.separable
import field_theory.splitting_field
import ring_theory.tensor_product
/-!
# Adjoining Elements to Fields
In this file we introduce the notion of adjoining elements to fields.
This isn't quite the same as adjoining elements to rings.
For example, `algebra.adjoin K {x}` might not include `x⁻¹`.
## Main results
- `adjoin_adjoin_left`: adjoining S and then T is the same as adjoining `S ∪ T`.
- `bot_eq_top_of_rank_adjoin_eq_one`: if `F⟮x⟯` has dimension `1` over `F` for every `x`
in `E` then `F = E`
## Notation
- `F⟮α⟯`: adjoin a single element `α` to `F`.
-/
open finite_dimensional polynomial
open_locale classical polynomial
namespace intermediate_field
section adjoin_def
variables (F : Type*) [field F] {E : Type*} [field E] [algebra F E] (S : set E)
/-- `adjoin F S` extends a field `F` by adjoining a set `S ⊆ E`. -/
def adjoin : intermediate_field F E :=
{ algebra_map_mem' := λ x, subfield.subset_closure (or.inl (set.mem_range_self x)),
..subfield.closure (set.range (algebra_map F E) ∪ S) }
end adjoin_def
section lattice
variables {F : Type*} [field F] {E : Type*} [field E] [algebra F E]
@[simp] lemma adjoin_le_iff {S : set E} {T : intermediate_field F E} : adjoin F S ≤ T ↔ S ≤ T :=
⟨λ H, le_trans (le_trans (set.subset_union_right _ _) subfield.subset_closure) H,
λ H, (@subfield.closure_le E _ (set.range (algebra_map F E) ∪ S) T.to_subfield).mpr
(set.union_subset (intermediate_field.set_range_subset T) H)⟩
lemma gc : galois_connection (adjoin F : set E → intermediate_field F E) coe := λ _ _, adjoin_le_iff
/-- Galois insertion between `adjoin` and `coe`. -/
def gi : galois_insertion (adjoin F : set E → intermediate_field F E) coe :=
{ choice := λ s hs, (adjoin F s).copy s $ le_antisymm (gc.le_u_l s) hs,
gc := intermediate_field.gc,
le_l_u := λ S, (intermediate_field.gc (S : set E) (adjoin F S)).1 $ le_rfl,
choice_eq := λ _ _, copy_eq _ _ _ }
instance : complete_lattice (intermediate_field F E) :=
galois_insertion.lift_complete_lattice intermediate_field.gi
instance : inhabited (intermediate_field F E) := ⟨⊤⟩
lemma coe_bot : ↑(⊥ : intermediate_field F E) = set.range (algebra_map F E) :=
begin
change ↑(subfield.closure (set.range (algebra_map F E) ∪ ∅)) = set.range (algebra_map F E),
simp [←set.image_univ, ←ring_hom.map_field_closure]
end
lemma mem_bot {x : E} : x ∈ (⊥ : intermediate_field F E) ↔ x ∈ set.range (algebra_map F E) :=
set.ext_iff.mp coe_bot x
@[simp] lemma bot_to_subalgebra : (⊥ : intermediate_field F E).to_subalgebra = ⊥ :=
by { ext, rw [mem_to_subalgebra, algebra.mem_bot, mem_bot] }
@[simp] lemma coe_top : ↑(⊤ : intermediate_field F E) = (set.univ : set E) := rfl
@[simp] lemma mem_top {x : E} : x ∈ (⊤ : intermediate_field F E) :=
trivial
@[simp] lemma top_to_subalgebra : (⊤ : intermediate_field F E).to_subalgebra = ⊤ :=
rfl
@[simp] lemma top_to_subfield : (⊤ : intermediate_field F E).to_subfield = ⊤ :=
rfl
@[simp, norm_cast]
lemma coe_inf (S T : intermediate_field F E) : (↑(S ⊓ T) : set E) = S ∩ T := rfl
@[simp]
lemma mem_inf {S T : intermediate_field F E} {x : E} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := iff.rfl
@[simp] lemma inf_to_subalgebra (S T : intermediate_field F E) :
(S ⊓ T).to_subalgebra = S.to_subalgebra ⊓ T.to_subalgebra :=
rfl
@[simp] lemma inf_to_subfield (S T : intermediate_field F E) :
(S ⊓ T).to_subfield = S.to_subfield ⊓ T.to_subfield :=
rfl
@[simp, norm_cast]
lemma coe_Inf (S : set (intermediate_field F E)) : (↑(Inf S) : set E) = Inf (coe '' S) := rfl
@[simp] lemma Inf_to_subalgebra (S : set (intermediate_field F E)) :
(Inf S).to_subalgebra = Inf (to_subalgebra '' S) :=
set_like.coe_injective $ by simp [set.sUnion_image]
@[simp] lemma Inf_to_subfield (S : set (intermediate_field F E)) :
(Inf S).to_subfield = Inf (to_subfield '' S) :=
set_like.coe_injective $ by simp [set.sUnion_image]
@[simp, norm_cast]
lemma coe_infi {ι : Sort*} (S : ι → intermediate_field F E) : (↑(infi S) : set E) = ⋂ i, (S i) :=
by simp [infi]
@[simp] lemma infi_to_subalgebra {ι : Sort*} (S : ι → intermediate_field F E) :
(infi S).to_subalgebra = ⨅ i, (S i).to_subalgebra :=
set_like.coe_injective $ by simp [infi]
@[simp] lemma infi_to_subfield {ι : Sort*} (S : ι → intermediate_field F E) :
(infi S).to_subfield = ⨅ i, (S i).to_subfield :=
set_like.coe_injective $ by simp [infi]
/-- Construct an algebra isomorphism from an equality of intermediate fields -/
@[simps apply]
def equiv_of_eq {S T : intermediate_field F E} (h : S = T) : S ≃ₐ[F] T :=
by refine { to_fun := λ x, ⟨x, _⟩, inv_fun := λ x, ⟨x, _⟩, .. }; tidy
@[simp] lemma equiv_of_eq_symm {S T : intermediate_field F E} (h : S = T) :
(equiv_of_eq h).symm = equiv_of_eq h.symm :=
rfl
@[simp] lemma equiv_of_eq_rfl (S : intermediate_field F E) :
equiv_of_eq (rfl : S = S) = alg_equiv.refl :=
by { ext, refl }
@[simp] lemma equiv_of_eq_trans {S T U : intermediate_field F E} (hST : S = T) (hTU : T = U) :
(equiv_of_eq hST).trans (equiv_of_eq hTU) = equiv_of_eq (trans hST hTU) :=
rfl
variables (F E)
/-- The bottom intermediate_field is isomorphic to the field. -/
noncomputable def bot_equiv : (⊥ : intermediate_field F E) ≃ₐ[F] F :=
(subalgebra.equiv_of_eq _ _ bot_to_subalgebra).trans (algebra.bot_equiv F E)
variables {F E}
@[simp] lemma bot_equiv_def (x : F) :
bot_equiv F E (algebra_map F (⊥ : intermediate_field F E) x) = x :=
alg_equiv.commutes (bot_equiv F E) x
@[simp] lemma bot_equiv_symm (x : F) :
(bot_equiv F E).symm x = algebra_map F _ x :=
rfl
noncomputable instance algebra_over_bot : algebra (⊥ : intermediate_field F E) F :=
(intermediate_field.bot_equiv F E).to_alg_hom.to_ring_hom.to_algebra
lemma coe_algebra_map_over_bot :
(algebra_map (⊥ : intermediate_field F E) F : (⊥ : intermediate_field F E) → F) =
(intermediate_field.bot_equiv F E) :=
rfl
instance is_scalar_tower_over_bot : is_scalar_tower (⊥ : intermediate_field F E) F E :=
is_scalar_tower.of_algebra_map_eq
begin
intro x,
obtain ⟨y, rfl⟩ := (bot_equiv F E).symm.surjective x,
rw [coe_algebra_map_over_bot, (bot_equiv F E).apply_symm_apply, bot_equiv_symm,
is_scalar_tower.algebra_map_apply F (⊥ : intermediate_field F E) E]
end
/-- The top intermediate_field is isomorphic to the field.
This is the intermediate field version of `subalgebra.top_equiv`. -/
@[simps apply] def top_equiv : (⊤ : intermediate_field F E) ≃ₐ[F] E :=
(subalgebra.equiv_of_eq _ _ top_to_subalgebra).trans subalgebra.top_equiv
@[simp] lemma top_equiv_symm_apply_coe (a : E) :
↑((top_equiv.symm) a : (⊤ : intermediate_field F E)) = a := rfl
@[simp] lemma restrict_scalars_bot_eq_self (K : intermediate_field F E) :
(⊥ : intermediate_field K E).restrict_scalars _ = K :=
by { ext, rw [mem_restrict_scalars, mem_bot], exact set.ext_iff.mp subtype.range_coe x }
@[simp] lemma restrict_scalars_top {K : Type*} [field K] [algebra K E] [algebra K F]
[is_scalar_tower K F E] :
(⊤ : intermediate_field F E).restrict_scalars K = ⊤ :=
rfl
lemma _root_.alg_hom.field_range_eq_map {K : Type*} [field K] [algebra F K] (f : E →ₐ[F] K) :
f.field_range = intermediate_field.map f ⊤ :=
set_like.ext' set.image_univ.symm
lemma _root_.alg_hom.map_field_range {K L : Type*} [field K] [field L] [algebra F K] [algebra F L]
(f : E →ₐ[F] K) (g : K →ₐ[F] L) : f.field_range.map g = (g.comp f).field_range :=
set_like.ext' (set.range_comp g f).symm
lemma _root_.alg_hom.field_range_eq_top {K : Type*} [field K] [algebra F K] {f : E →ₐ[F] K} :
f.field_range = ⊤ ↔ function.surjective f :=
set_like.ext'_iff.trans set.range_iff_surjective
@[simp] lemma _root_.alg_equiv.field_range_eq_top {K : Type*} [field K] [algebra F K]
(f : E ≃ₐ[F] K) : (f : E →ₐ[F] K).field_range = ⊤ :=
alg_hom.field_range_eq_top.mpr f.surjective
end lattice
section adjoin_def
variables (F : Type*) [field F] {E : Type*} [field E] [algebra F E] (S : set E)
lemma adjoin_eq_range_algebra_map_adjoin :
(adjoin F S : set E) = set.range (algebra_map (adjoin F S) E) := (subtype.range_coe).symm
lemma adjoin.algebra_map_mem (x : F) : algebra_map F E x ∈ adjoin F S :=
intermediate_field.algebra_map_mem (adjoin F S) x
lemma adjoin.range_algebra_map_subset : set.range (algebra_map F E) ⊆ adjoin F S :=
begin
intros x hx,
cases hx with f hf,
rw ← hf,
exact adjoin.algebra_map_mem F S f,
end
instance adjoin.field_coe : has_coe_t F (adjoin F S) :=
{coe := λ x, ⟨algebra_map F E x, adjoin.algebra_map_mem F S x⟩}
lemma subset_adjoin : S ⊆ adjoin F S :=
λ x hx, subfield.subset_closure (or.inr hx)
instance adjoin.set_coe : has_coe_t S (adjoin F S) :=
{coe := λ x, ⟨x,subset_adjoin F S (subtype.mem x)⟩}
@[mono] lemma adjoin.mono (T : set E) (h : S ⊆ T) : adjoin F S ≤ adjoin F T :=
galois_connection.monotone_l gc h
lemma adjoin_contains_field_as_subfield (F : subfield E) : (F : set E) ⊆ adjoin F S :=
λ x hx, adjoin.algebra_map_mem F S ⟨x, hx⟩
lemma subset_adjoin_of_subset_left {F : subfield E} {T : set E} (HT : T ⊆ F) : T ⊆ adjoin F S :=
λ x hx, (adjoin F S).algebra_map_mem ⟨x, HT hx⟩
lemma subset_adjoin_of_subset_right {T : set E} (H : T ⊆ S) : T ⊆ adjoin F S :=
λ x hx, subset_adjoin F S (H hx)
@[simp] lemma adjoin_empty (F E : Type*) [field F] [field E] [algebra F E] :
adjoin F (∅ : set E) = ⊥ :=
eq_bot_iff.mpr (adjoin_le_iff.mpr (set.empty_subset _))
@[simp] lemma adjoin_univ (F E : Type*) [field F] [field E] [algebra F E] :
adjoin F (set.univ : set E) = ⊤ :=
eq_top_iff.mpr $ subset_adjoin _ _
/-- If `K` is a field with `F ⊆ K` and `S ⊆ K` then `adjoin F S ≤ K`. -/
lemma adjoin_le_subfield {K : subfield E} (HF : set.range (algebra_map F E) ⊆ K)
(HS : S ⊆ K) : (adjoin F S).to_subfield ≤ K :=
begin
apply subfield.closure_le.mpr,
rw set.union_subset_iff,
exact ⟨HF, HS⟩,
end
lemma adjoin_subset_adjoin_iff {F' : Type*} [field F'] [algebra F' E]
{S S' : set E} : (adjoin F S : set E) ⊆ adjoin F' S' ↔
set.range (algebra_map F E) ⊆ adjoin F' S' ∧ S ⊆ adjoin F' S' :=
⟨λ h, ⟨trans (adjoin.range_algebra_map_subset _ _) h, trans (subset_adjoin _ _) h⟩,
λ ⟨hF, hS⟩, subfield.closure_le.mpr (set.union_subset hF hS)⟩
/-- `F[S][T] = F[S ∪ T]` -/
lemma adjoin_adjoin_left (T : set E) :
(adjoin (adjoin F S) T).restrict_scalars _ = adjoin F (S ∪ T) :=
begin
rw set_like.ext'_iff,
change ↑(adjoin (adjoin F S) T) = _,
apply set.eq_of_subset_of_subset; rw adjoin_subset_adjoin_iff; split,
{ rintros _ ⟨⟨x, hx⟩, rfl⟩, exact adjoin.mono _ _ _ (set.subset_union_left _ _) hx },
{ exact subset_adjoin_of_subset_right _ _ (set.subset_union_right _ _) },
{ exact subset_adjoin_of_subset_left _ (adjoin.range_algebra_map_subset _ _) },
{ exact set.union_subset
(subset_adjoin_of_subset_left _ (subset_adjoin _ _))
(subset_adjoin _ _) },
end
@[simp] lemma adjoin_insert_adjoin (x : E) :
adjoin F (insert x (adjoin F S : set E)) = adjoin F (insert x S) :=
le_antisymm
(adjoin_le_iff.mpr (set.insert_subset.mpr ⟨subset_adjoin _ _ (set.mem_insert _ _),
adjoin_le_iff.mpr (subset_adjoin_of_subset_right _ _ (set.subset_insert _ _))⟩))
(adjoin.mono _ _ _ (set.insert_subset_insert (subset_adjoin _ _)))
/-- `F[S][T] = F[T][S]` -/
lemma adjoin_adjoin_comm (T : set E) :
(adjoin (adjoin F S) T).restrict_scalars F = (adjoin (adjoin F T) S).restrict_scalars F :=
by rw [adjoin_adjoin_left, adjoin_adjoin_left, set.union_comm]
lemma adjoin_map {E' : Type*} [field E'] [algebra F E'] (f : E →ₐ[F] E') :
(adjoin F S).map f = adjoin F (f '' S) :=
begin
ext x,
show x ∈ (subfield.closure (set.range (algebra_map F E) ∪ S)).map (f : E →+* E') ↔
x ∈ subfield.closure (set.range (algebra_map F E') ∪ f '' S),
rw [ring_hom.map_field_closure, set.image_union, ← set.range_comp, ← ring_hom.coe_comp,
f.comp_algebra_map],
refl,
end
lemma algebra_adjoin_le_adjoin : algebra.adjoin F S ≤ (adjoin F S).to_subalgebra :=
algebra.adjoin_le (subset_adjoin _ _)
lemma adjoin_eq_algebra_adjoin (inv_mem : ∀ x ∈ algebra.adjoin F S, x⁻¹ ∈ algebra.adjoin F S) :
(adjoin F S).to_subalgebra = algebra.adjoin F S :=
le_antisymm
(show adjoin F S ≤
{ neg_mem' := λ x, (algebra.adjoin F S).neg_mem, inv_mem' := inv_mem, .. algebra.adjoin F S},
from adjoin_le_iff.mpr (algebra.subset_adjoin))
(algebra_adjoin_le_adjoin _ _)
lemma eq_adjoin_of_eq_algebra_adjoin (K : intermediate_field F E)
(h : K.to_subalgebra = algebra.adjoin F S) : K = adjoin F S :=
begin
apply to_subalgebra_injective,
rw h,
refine (adjoin_eq_algebra_adjoin _ _ _).symm,
intros x,
convert K.inv_mem,
rw ← h,
refl
end
@[elab_as_eliminator]
lemma adjoin_induction {s : set E} {p : E → Prop} {x} (h : x ∈ adjoin F s)
(Hs : ∀ x ∈ s, p x) (Hmap : ∀ x, p (algebra_map F E x))
(Hadd : ∀ x y, p x → p y → p (x + y))
(Hneg : ∀ x, p x → p (-x))
(Hinv : ∀ x, p x → p x⁻¹)
(Hmul : ∀ x y, p x → p y → p (x * y)) : p x :=
subfield.closure_induction h (λ x hx, or.cases_on hx (λ ⟨x, hx⟩, hx ▸ Hmap x) (Hs x))
((algebra_map F E).map_one ▸ Hmap 1)
Hadd Hneg Hinv Hmul
/--
Variation on `set.insert` to enable good notation for adjoining elements to fields.
Used to preferentially use `singleton` rather than `insert` when adjoining one element.
-/
--this definition of notation is courtesy of Kyle Miller on zulip
class insert {α : Type*} (s : set α) :=
(insert : α → set α)
@[priority 1000]
instance insert_empty {α : Type*} : insert (∅ : set α) :=
{ insert := λ x, @singleton _ _ set.has_singleton x }
@[priority 900]
instance insert_nonempty {α : Type*} (s : set α) : insert s :=
{ insert := λ x, has_insert.insert x s }
notation K`⟮`:std.prec.max_plus l:(foldr `, ` (h t, insert.insert t h) ∅) `⟯` := adjoin K l
section adjoin_simple
variables (α : E)
lemma mem_adjoin_simple_self : α ∈ F⟮α⟯ :=
subset_adjoin F {α} (set.mem_singleton α)
/-- generator of `F⟮α⟯` -/
def adjoin_simple.gen : F⟮α⟯ := ⟨α, mem_adjoin_simple_self F α⟩
@[simp] lemma adjoin_simple.algebra_map_gen : algebra_map F⟮α⟯ E (adjoin_simple.gen F α) = α := rfl
@[simp] lemma adjoin_simple.is_integral_gen :
is_integral F (adjoin_simple.gen F α) ↔ is_integral F α :=
by { conv_rhs { rw ← adjoin_simple.algebra_map_gen F α },
rw is_integral_algebra_map_iff (algebra_map F⟮α⟯ E).injective,
apply_instance }
lemma adjoin_simple_adjoin_simple (β : E) : F⟮α⟯⟮β⟯.restrict_scalars F = F⟮α, β⟯ :=
adjoin_adjoin_left _ _ _
lemma adjoin_simple_comm (β : E) : F⟮α⟯⟮β⟯.restrict_scalars F = F⟮β⟯⟮α⟯.restrict_scalars F :=
adjoin_adjoin_comm _ _ _
variables {F} {α}
lemma adjoin_algebraic_to_subalgebra
{S : set E} (hS : ∀ x ∈ S, is_algebraic F x) :
(intermediate_field.adjoin F S).to_subalgebra = algebra.adjoin F S :=
begin
simp only [is_algebraic_iff_is_integral] at hS,
have : algebra.is_integral F (algebra.adjoin F S) :=
by rwa [←le_integral_closure_iff_is_integral, algebra.adjoin_le_iff],
have := is_field_of_is_integral_of_is_field' this (field.to_is_field F),
rw ← ((algebra.adjoin F S).to_intermediate_field' this).eq_adjoin_of_eq_algebra_adjoin F S; refl,
end
lemma adjoin_simple_to_subalgebra_of_integral (hα : is_integral F α) :
(F⟮α⟯).to_subalgebra = algebra.adjoin F {α} :=
begin
apply adjoin_algebraic_to_subalgebra,
rintro x (rfl : x = α),
rwa is_algebraic_iff_is_integral,
end
lemma is_splitting_field_iff {p : F[X]} {K : intermediate_field F E} :
p.is_splitting_field F K ↔ p.splits (algebra_map F K) ∧ K = adjoin F (p.root_set E) :=
begin
suffices : _ → ((algebra.adjoin F (p.root_set K) = ⊤ ↔ K = adjoin F (p.root_set E))),
{ exact ⟨λ h, ⟨h.1, (this h.1).mp h.2⟩, λ h, ⟨h.1, (this h.1).mpr h.2⟩⟩ },
simp_rw [set_like.ext_iff, ←mem_to_subalgebra, ←set_like.ext_iff],
rw [←K.range_val, adjoin_algebraic_to_subalgebra (λ x, is_algebraic_of_mem_root_set)],
exact λ hp, (adjoin_root_set_eq_range hp K.val).symm.trans eq_comm,
end
lemma adjoin_root_set_is_splitting_field {p : F[X]} (hp : p.splits (algebra_map F E)) :
p.is_splitting_field F (adjoin F (p.root_set E)) :=
is_splitting_field_iff.mpr ⟨splits_of_splits hp (λ x hx, subset_adjoin F (p.root_set E) hx), rfl⟩
open_locale big_operators
/-- A compositum of splitting fields is a splitting field -/
lemma is_splitting_field_supr {ι : Type*} {t : ι → intermediate_field F E} {p : ι → F[X]}
{s : finset ι} (h0 : ∏ i in s, p i ≠ 0) (h : ∀ i ∈ s, (p i).is_splitting_field F (t i)) :
(∏ i in s, p i).is_splitting_field F (⨆ i ∈ s, t i : intermediate_field F E) :=
begin
let K : intermediate_field F E := ⨆ i ∈ s, t i,
have hK : ∀ i ∈ s, t i ≤ K := λ i hi, le_supr_of_le i (le_supr (λ _, t i) hi),
simp only [is_splitting_field_iff] at h ⊢,
refine ⟨splits_prod (algebra_map F K) (λ i hi, polynomial.splits_comp_of_splits
(algebra_map F (t i)) (inclusion (hK i hi)).to_ring_hom (h i hi).1), _⟩,
simp only [root_set_prod p s h0, ←set.supr_eq_Union, (@gc F _ E _ _).l_supr₂],
exact supr_congr (λ i, supr_congr (λ hi, (h i hi).2)),
end
open set complete_lattice
@[simp] lemma adjoin_simple_le_iff {K : intermediate_field F E} : F⟮α⟯ ≤ K ↔ α ∈ K :=
adjoin_le_iff.trans singleton_subset_iff
/-- Adjoining a single element is compact in the lattice of intermediate fields. -/
lemma adjoin_simple_is_compact_element (x : E) : is_compact_element F⟮x⟯ :=
begin
rw is_compact_element_iff_le_of_directed_Sup_le,
rintros s ⟨F₀, hF₀⟩ hs hx,
simp only [adjoin_simple_le_iff] at hx ⊢,
let F : intermediate_field F E :=
{ carrier := ⋃ E ∈ s, ↑E,
add_mem' := by
{ rintros x₁ x₂ ⟨-, ⟨F₁, rfl⟩, ⟨-, ⟨hF₁, rfl⟩, hx₁⟩⟩ ⟨-, ⟨F₂, rfl⟩, ⟨-, ⟨hF₂, rfl⟩, hx₂⟩⟩,
obtain ⟨F₃, hF₃, h₁₃, h₂₃⟩ := hs F₁ hF₁ F₂ hF₂,
exact mem_Union_of_mem F₃ (mem_Union_of_mem hF₃ (F₃.add_mem (h₁₃ hx₁) (h₂₃ hx₂))) },
neg_mem' := by
{ rintros x ⟨-, ⟨E, rfl⟩, ⟨-, ⟨hE, rfl⟩, hx⟩⟩,
exact mem_Union_of_mem E (mem_Union_of_mem hE (E.neg_mem hx)) },
mul_mem' := by
{ rintros x₁ x₂ ⟨-, ⟨F₁, rfl⟩, ⟨-, ⟨hF₁, rfl⟩, hx₁⟩⟩ ⟨-, ⟨F₂, rfl⟩, ⟨-, ⟨hF₂, rfl⟩, hx₂⟩⟩,
obtain ⟨F₃, hF₃, h₁₃, h₂₃⟩ := hs F₁ hF₁ F₂ hF₂,
exact mem_Union_of_mem F₃ (mem_Union_of_mem hF₃ (F₃.mul_mem (h₁₃ hx₁) (h₂₃ hx₂))) },
inv_mem' := by
{ rintros x ⟨-, ⟨E, rfl⟩, ⟨-, ⟨hE, rfl⟩, hx⟩⟩,
exact mem_Union_of_mem E (mem_Union_of_mem hE (E.inv_mem hx)) },
algebra_map_mem' := λ x, mem_Union_of_mem F₀ (mem_Union_of_mem hF₀ (F₀.algebra_map_mem x)) },
have key : Sup s ≤ F := Sup_le (λ E hE, subset_Union_of_subset E (subset_Union _ hE)),
obtain ⟨-, ⟨E, rfl⟩, -, ⟨hE, rfl⟩, hx⟩ := key hx,
exact ⟨E, hE, hx⟩,
end
/-- Adjoining a finite subset is compact in the lattice of intermediate fields. -/
lemma adjoin_finset_is_compact_element (S : finset E) :
is_compact_element (adjoin F S : intermediate_field F E) :=
begin
have key : adjoin F ↑S = ⨆ x ∈ S, F⟮x⟯ :=
le_antisymm (adjoin_le_iff.mpr (λ x hx, set_like.mem_coe.mpr (adjoin_simple_le_iff.mp
(le_supr_of_le x (le_supr_of_le hx le_rfl)))))
(supr_le (λ x, supr_le (λ hx, adjoin_simple_le_iff.mpr (subset_adjoin F S hx)))),
rw [key, ←finset.sup_eq_supr],
exact finset_sup_compact_of_compact S (λ x hx, adjoin_simple_is_compact_element x),
end
/-- Adjoining a finite subset is compact in the lattice of intermediate fields. -/
lemma adjoin_finite_is_compact_element {S : set E} (h : S.finite) :
is_compact_element (adjoin F S) :=
finite.coe_to_finset h ▸ (adjoin_finset_is_compact_element h.to_finset)
/-- The lattice of intermediate fields is compactly generated. -/
instance : is_compactly_generated (intermediate_field F E) :=
⟨λ s, ⟨(λ x, F⟮x⟯) '' s, ⟨by rintros t ⟨x, hx, rfl⟩; exact adjoin_simple_is_compact_element x,
Sup_image.trans (le_antisymm (supr_le (λ i, supr_le (λ hi, adjoin_simple_le_iff.mpr hi)))
(λ x hx, adjoin_simple_le_iff.mp (le_supr_of_le x (le_supr_of_le hx le_rfl))))⟩⟩⟩
lemma exists_finset_of_mem_supr {ι : Type*} {f : ι → intermediate_field F E}
{x : E} (hx : x ∈ ⨆ i, f i) : ∃ s : finset ι, x ∈ ⨆ i ∈ s, f i :=
begin
have := (adjoin_simple_is_compact_element x).exists_finset_of_le_supr (intermediate_field F E) f,
simp only [adjoin_simple_le_iff] at this,
exact this hx,
end
lemma exists_finset_of_mem_supr' {ι : Type*} {f : ι → intermediate_field F E}
{x : E} (hx : x ∈ ⨆ i, f i) : ∃ s : finset (Σ i, f i), x ∈ ⨆ i ∈ s, F⟮(i.2 : E)⟯ :=
exists_finset_of_mem_supr (set_like.le_def.mp (supr_le
(λ i x h, set_like.le_def.mp (le_supr_of_le ⟨i, x, h⟩ le_rfl) (mem_adjoin_simple_self F x))) hx)
lemma exists_finset_of_mem_supr'' {ι : Type*} {f : ι → intermediate_field F E}
(h : ∀ i, algebra.is_algebraic F (f i)) {x : E} (hx : x ∈ ⨆ i, f i) :
∃ s : finset (Σ i, f i), x ∈ ⨆ i ∈ s, adjoin F ((minpoly F (i.2 : _)).root_set E) :=
begin
refine exists_finset_of_mem_supr (set_like.le_def.mp (supr_le (λ i x hx, set_like.le_def.mp
(le_supr_of_le ⟨i, x, hx⟩ le_rfl) (subset_adjoin F _ _))) hx),
rw [intermediate_field.minpoly_eq, subtype.coe_mk, mem_root_set_of_ne, minpoly.aeval],
exact minpoly.ne_zero (is_integral_iff.mp (is_algebraic_iff_is_integral.mp (h i ⟨x, hx⟩)))
end
end adjoin_simple
end adjoin_def
section adjoin_intermediate_field_lattice
variables {F : Type*} [field F] {E : Type*} [field E] [algebra F E] {α : E} {S : set E}
@[simp] lemma adjoin_eq_bot_iff : adjoin F S = ⊥ ↔ S ⊆ (⊥ : intermediate_field F E) :=
by { rw [eq_bot_iff, adjoin_le_iff], refl, }
@[simp] lemma adjoin_simple_eq_bot_iff : F⟮α⟯ = ⊥ ↔ α ∈ (⊥ : intermediate_field F E) :=
by { rw adjoin_eq_bot_iff, exact set.singleton_subset_iff }
@[simp] lemma adjoin_zero : F⟮(0 : E)⟯ = ⊥ :=
adjoin_simple_eq_bot_iff.mpr (zero_mem ⊥)
@[simp] lemma adjoin_one : F⟮(1 : E)⟯ = ⊥ :=
adjoin_simple_eq_bot_iff.mpr (one_mem ⊥)
@[simp] lemma adjoin_int (n : ℤ) : F⟮(n : E)⟯ = ⊥ :=
adjoin_simple_eq_bot_iff.mpr (coe_int_mem ⊥ n)
@[simp] lemma adjoin_nat (n : ℕ) : F⟮(n : E)⟯ = ⊥ :=
adjoin_simple_eq_bot_iff.mpr (coe_nat_mem ⊥ n)
section adjoin_rank
open finite_dimensional module
variables {K L : intermediate_field F E}
@[simp] lemma rank_eq_one_iff : module.rank F K = 1 ↔ K = ⊥ :=
by rw [← to_subalgebra_eq_iff, ← rank_eq_rank_subalgebra,
subalgebra.rank_eq_one_iff, bot_to_subalgebra]
@[simp] lemma finrank_eq_one_iff : finrank F K = 1 ↔ K = ⊥ :=
by rw [← to_subalgebra_eq_iff, ← finrank_eq_finrank_subalgebra,
subalgebra.finrank_eq_one_iff, bot_to_subalgebra]
@[simp] lemma rank_bot : module.rank F (⊥ : intermediate_field F E) = 1 :=
by rw rank_eq_one_iff
@[simp] lemma finrank_bot : finrank F (⊥ : intermediate_field F E) = 1 :=
by rw finrank_eq_one_iff
lemma rank_adjoin_eq_one_iff : module.rank F (adjoin F S) = 1 ↔ S ⊆ (⊥ : intermediate_field F E) :=
iff.trans rank_eq_one_iff adjoin_eq_bot_iff
lemma rank_adjoin_simple_eq_one_iff : module.rank F F⟮α⟯ = 1 ↔ α ∈ (⊥ : intermediate_field F E) :=
by { rw rank_adjoin_eq_one_iff, exact set.singleton_subset_iff }
lemma finrank_adjoin_eq_one_iff : finrank F (adjoin F S) = 1 ↔ S ⊆ (⊥ : intermediate_field F E) :=
iff.trans finrank_eq_one_iff adjoin_eq_bot_iff
lemma finrank_adjoin_simple_eq_one_iff : finrank F F⟮α⟯ = 1 ↔ α ∈ (⊥ : intermediate_field F E) :=
by { rw [finrank_adjoin_eq_one_iff], exact set.singleton_subset_iff }
/-- If `F⟮x⟯` has dimension `1` over `F` for every `x ∈ E` then `F = E`. -/
lemma bot_eq_top_of_rank_adjoin_eq_one (h : ∀ x : E, module.rank F F⟮x⟯ = 1) :
(⊥ : intermediate_field F E) = ⊤ :=
begin
ext,
rw iff_true_right intermediate_field.mem_top,
exact rank_adjoin_simple_eq_one_iff.mp (h x),
end
lemma bot_eq_top_of_finrank_adjoin_eq_one (h : ∀ x : E, finrank F F⟮x⟯ = 1) :
(⊥ : intermediate_field F E) = ⊤ :=
begin
ext,
rw iff_true_right intermediate_field.mem_top,
exact finrank_adjoin_simple_eq_one_iff.mp (h x),
end
lemma subsingleton_of_rank_adjoin_eq_one (h : ∀ x : E, module.rank F F⟮x⟯ = 1) :
subsingleton (intermediate_field F E) :=
subsingleton_of_bot_eq_top (bot_eq_top_of_rank_adjoin_eq_one h)
lemma subsingleton_of_finrank_adjoin_eq_one (h : ∀ x : E, finrank F F⟮x⟯ = 1) :
subsingleton (intermediate_field F E) :=
subsingleton_of_bot_eq_top (bot_eq_top_of_finrank_adjoin_eq_one h)
/-- If `F⟮x⟯` has dimension `≤1` over `F` for every `x ∈ E` then `F = E`. -/
lemma bot_eq_top_of_finrank_adjoin_le_one [finite_dimensional F E]
(h : ∀ x : E, finrank F F⟮x⟯ ≤ 1) : (⊥ : intermediate_field F E) = ⊤ :=
begin
apply bot_eq_top_of_finrank_adjoin_eq_one,
exact λ x, by linarith [h x, show 0 < finrank F F⟮x⟯, from finrank_pos],
end
lemma subsingleton_of_finrank_adjoin_le_one [finite_dimensional F E]
(h : ∀ x : E, finrank F F⟮x⟯ ≤ 1) : subsingleton (intermediate_field F E) :=
subsingleton_of_bot_eq_top (bot_eq_top_of_finrank_adjoin_le_one h)
end adjoin_rank
end adjoin_intermediate_field_lattice
section adjoin_integral_element
variables {F : Type*} [field F] {E : Type*} [field E] [algebra F E] {α : E}
variables {K : Type*} [field K] [algebra F K]
lemma minpoly_gen {α : E} (h : is_integral F α) :
minpoly F (adjoin_simple.gen F α) = minpoly F α :=
begin
rw ← adjoin_simple.algebra_map_gen F α at h,
have inj := (algebra_map F⟮α⟯ E).injective,
exact minpoly.eq_of_algebra_map_eq inj ((is_integral_algebra_map_iff inj).mp h)
(adjoin_simple.algebra_map_gen _ _).symm
end
variables (F)
lemma aeval_gen_minpoly (α : E) :
aeval (adjoin_simple.gen F α) (minpoly F α) = 0 :=
begin
ext,
convert minpoly.aeval F α,
conv in (aeval α) { rw [← adjoin_simple.algebra_map_gen F α] },
exact (aeval_algebra_map_apply E (adjoin_simple.gen F α) _).symm
end
/-- algebra isomorphism between `adjoin_root` and `F⟮α⟯` -/
noncomputable def adjoin_root_equiv_adjoin (h : is_integral F α) :
adjoin_root (minpoly F α) ≃ₐ[F] F⟮α⟯ :=
alg_equiv.of_bijective
(adjoin_root.lift_hom (minpoly F α) (adjoin_simple.gen F α) (aeval_gen_minpoly F α))
(begin
set f := adjoin_root.lift _ _ (aeval_gen_minpoly F α : _),
haveI := fact.mk (minpoly.irreducible h),
split,
{ exact ring_hom.injective f },
{ suffices : F⟮α⟯.to_subfield ≤ ring_hom.field_range ((F⟮α⟯.to_subfield.subtype).comp f),
{ exact λ x, Exists.cases_on (this (subtype.mem x)) (λ y hy, ⟨y, subtype.ext hy⟩) },
exact subfield.closure_le.mpr (set.union_subset (λ x hx, Exists.cases_on hx (λ y hy,
⟨y, by { rw [ring_hom.comp_apply, adjoin_root.lift_of], exact hy }⟩))
(set.singleton_subset_iff.mpr ⟨adjoin_root.root (minpoly F α),
by { rw [ring_hom.comp_apply, adjoin_root.lift_root], refl }⟩)) } end)
lemma adjoin_root_equiv_adjoin_apply_root (h : is_integral F α) :
adjoin_root_equiv_adjoin F h (adjoin_root.root (minpoly F α)) =
adjoin_simple.gen F α :=
adjoin_root.lift_root (aeval_gen_minpoly F α)
section power_basis
variables {L : Type*} [field L] [algebra K L]
/-- The elements `1, x, ..., x ^ (d - 1)` form a basis for `K⟮x⟯`,
where `d` is the degree of the minimal polynomial of `x`. -/
noncomputable def power_basis_aux {x : L} (hx : is_integral K x) :
basis (fin (minpoly K x).nat_degree) K K⟮x⟯ :=
(adjoin_root.power_basis (minpoly.ne_zero hx)).basis.map
(adjoin_root_equiv_adjoin K hx).to_linear_equiv
/-- The power basis `1, x, ..., x ^ (d - 1)` for `K⟮x⟯`,
where `d` is the degree of the minimal polynomial of `x`. -/
@[simps]
noncomputable def adjoin.power_basis {x : L} (hx : is_integral K x) :
power_basis K K⟮x⟯ :=
{ gen := adjoin_simple.gen K x,
dim := (minpoly K x).nat_degree,
basis := power_basis_aux hx,
basis_eq_pow := λ i,
by rw [power_basis_aux, basis.map_apply, power_basis.basis_eq_pow,
alg_equiv.to_linear_equiv_apply, alg_equiv.map_pow, adjoin_root.power_basis_gen,
adjoin_root_equiv_adjoin_apply_root] }
lemma adjoin.finite_dimensional {x : L} (hx : is_integral K x) : finite_dimensional K K⟮x⟯ :=
power_basis.finite_dimensional (adjoin.power_basis hx)
lemma adjoin.finrank {x : L} (hx : is_integral K x) :
finite_dimensional.finrank K K⟮x⟯ = (minpoly K x).nat_degree :=
begin
rw power_basis.finrank (adjoin.power_basis hx : _),
refl
end
lemma _root_.minpoly.nat_degree_le {x : L} [finite_dimensional K L] (hx : is_integral K x) :
(minpoly K x).nat_degree ≤ finrank K L :=
le_of_eq_of_le (intermediate_field.adjoin.finrank hx).symm K⟮x⟯.to_submodule.finrank_le
lemma _root_.minpoly.degree_le {x : L} [finite_dimensional K L] (hx : is_integral K x) :
(minpoly K x).degree ≤ finrank K L :=
degree_le_of_nat_degree_le (minpoly.nat_degree_le hx)
end power_basis
/-- Algebra homomorphism `F⟮α⟯ →ₐ[F] K` are in bijection with the set of roots
of `minpoly α` in `K`. -/
noncomputable def alg_hom_adjoin_integral_equiv (h : is_integral F α) :
(F⟮α⟯ →ₐ[F] K) ≃ {x // x ∈ ((minpoly F α).map (algebra_map F K)).roots} :=
(adjoin.power_basis h).lift_equiv'.trans ((equiv.refl _).subtype_equiv (λ x,
by rw [adjoin.power_basis_gen, minpoly_gen h, equiv.refl_apply]))
/-- Fintype of algebra homomorphism `F⟮α⟯ →ₐ[F] K` -/
noncomputable def fintype_of_alg_hom_adjoin_integral (h : is_integral F α) :
fintype (F⟮α⟯ →ₐ[F] K) :=
power_basis.alg_hom.fintype (adjoin.power_basis h)
lemma card_alg_hom_adjoin_integral (h : is_integral F α) (h_sep : (minpoly F α).separable)
(h_splits : (minpoly F α).splits (algebra_map F K)) :
@fintype.card (F⟮α⟯ →ₐ[F] K) (fintype_of_alg_hom_adjoin_integral F h) =
(minpoly F α).nat_degree :=
begin
rw alg_hom.card_of_power_basis;
simp only [adjoin.power_basis_dim, adjoin.power_basis_gen, minpoly_gen h, h_sep, h_splits],
end
end adjoin_integral_element
section induction
variables {F : Type*} [field F] {E : Type*} [field E] [algebra F E]
/-- An intermediate field `S` is finitely generated if there exists `t : finset E` such that
`intermediate_field.adjoin F t = S`. -/
def fg (S : intermediate_field F E) : Prop := ∃ (t : finset E), adjoin F ↑t = S
lemma fg_adjoin_finset (t : finset E) : (adjoin F (↑t : set E)).fg :=
⟨t, rfl⟩
theorem fg_def {S : intermediate_field F E} : S.fg ↔ ∃ t : set E, set.finite t ∧ adjoin F t = S :=
iff.symm set.exists_finite_iff_finset
theorem fg_bot : (⊥ : intermediate_field F E).fg :=
⟨∅, adjoin_empty F E⟩
lemma fg_of_fg_to_subalgebra (S : intermediate_field F E)
(h : S.to_subalgebra.fg) : S.fg :=
begin
cases h with t ht,
exact ⟨t, (eq_adjoin_of_eq_algebra_adjoin _ _ _ ht.symm).symm⟩
end
lemma fg_of_noetherian (S : intermediate_field F E)
[is_noetherian F E] : S.fg :=
S.fg_of_fg_to_subalgebra S.to_subalgebra.fg_of_noetherian
lemma induction_on_adjoin_finset (S : finset E) (P : intermediate_field F E → Prop) (base : P ⊥)
(ih : ∀ (K : intermediate_field F E) (x ∈ S), P K → P (K⟮x⟯.restrict_scalars F)) :
P (adjoin F ↑S) :=
begin
apply finset.induction_on' S,
{ exact base },
{ intros a s h1 _ _ h4,
rw [finset.coe_insert, set.insert_eq, set.union_comm, ←adjoin_adjoin_left],
exact ih (adjoin F s) a h1 h4 }
end
lemma induction_on_adjoin_fg (P : intermediate_field F E → Prop)
(base : P ⊥) (ih : ∀ (K : intermediate_field F E) (x : E), P K → P (K⟮x⟯.restrict_scalars F))
(K : intermediate_field F E) (hK : K.fg) : P K :=
begin
obtain ⟨S, rfl⟩ := hK,
exact induction_on_adjoin_finset S P base (λ K x _ hK, ih K x hK),
end
lemma induction_on_adjoin [fd : finite_dimensional F E] (P : intermediate_field F E → Prop)
(base : P ⊥) (ih : ∀ (K : intermediate_field F E) (x : E), P K → P (K⟮x⟯.restrict_scalars F))
(K : intermediate_field F E) : P K :=
begin
letI : is_noetherian F E := is_noetherian.iff_fg.2 infer_instance,
exact induction_on_adjoin_fg P base ih K K.fg_of_noetherian
end
end induction
section alg_hom_mk_adjoin_splits
variables (F E K : Type*) [field F] [field E] [field K] [algebra F E] [algebra F K] {S : set E}
/-- Lifts `L → K` of `F → K` -/
def lifts := Σ (L : intermediate_field F E), (L →ₐ[F] K)
variables {F E K}
instance : partial_order (lifts F E K) :=
{ le := λ x y, x.1 ≤ y.1 ∧ (∀ (s : x.1) (t : y.1), (s : E) = t → x.2 s = y.2 t),
le_refl := λ x, ⟨le_refl x.1, λ s t hst, congr_arg x.2 (subtype.ext hst)⟩,
le_trans := λ x y z hxy hyz, ⟨le_trans hxy.1 hyz.1, λ s u hsu, eq.trans
(hxy.2 s ⟨s, hxy.1 s.mem⟩ rfl) (hyz.2 ⟨s, hxy.1 s.mem⟩ u hsu)⟩,
le_antisymm :=
begin
rintros ⟨x1, x2⟩ ⟨y1, y2⟩ ⟨hxy1, hxy2⟩ ⟨hyx1, hyx2⟩,
obtain rfl : x1 = y1 := le_antisymm hxy1 hyx1,
congr,
exact alg_hom.ext (λ s, hxy2 s s rfl),
end }
noncomputable instance : order_bot (lifts F E K) :=
{ bot := ⟨⊥, (algebra.of_id F K).comp (bot_equiv F E).to_alg_hom⟩,
bot_le := λ x, ⟨bot_le, λ s t hst,
begin
cases intermediate_field.mem_bot.mp s.mem with u hu,
rw [show s = (algebra_map F _) u, from subtype.ext hu.symm, alg_hom.commutes],
rw [show t = (algebra_map F _) u, from subtype.ext (eq.trans hu hst).symm, alg_hom.commutes],
end⟩ }
noncomputable instance : inhabited (lifts F E K) := ⟨⊥⟩
lemma lifts.eq_of_le {x y : lifts F E K} (hxy : x ≤ y) (s : x.1) :
x.2 s = y.2 ⟨s, hxy.1 s.mem⟩ := hxy.2 s ⟨s, hxy.1 s.mem⟩ rfl
lemma lifts.exists_max_two {c : set (lifts F E K)} {x y : lifts F E K} (hc : is_chain (≤) c)
(hx : x ∈ has_insert.insert ⊥ c) (hy : y ∈ has_insert.insert ⊥ c) :
∃ z : lifts F E K, z ∈ has_insert.insert ⊥ c ∧ x ≤ z ∧ y ≤ z :=
begin
cases (hc.insert $ λ _ _ _, or.inl bot_le).total hx hy with hxy hyx,
{ exact ⟨y, hy, hxy, le_refl y⟩ },
{ exact ⟨x, hx, le_refl x, hyx⟩ },
end
lemma lifts.exists_max_three {c : set (lifts F E K)} {x y z : lifts F E K} (hc : is_chain (≤) c)
(hx : x ∈ has_insert.insert ⊥ c) (hy : y ∈ has_insert.insert ⊥ c)
(hz : z ∈ has_insert.insert ⊥ c) :
∃ w : lifts F E K, w ∈ has_insert.insert ⊥ c ∧ x ≤ w ∧ y ≤ w ∧ z ≤ w :=
begin
obtain ⟨v, hv, hxv, hyv⟩ := lifts.exists_max_two hc hx hy,
obtain ⟨w, hw, hzw, hvw⟩ := lifts.exists_max_two hc hz hv,
exact ⟨w, hw, le_trans hxv hvw, le_trans hyv hvw, hzw⟩,
end
/-- An upper bound on a chain of lifts -/
def lifts.upper_bound_intermediate_field {c : set (lifts F E K)} (hc : is_chain (≤) c) :
intermediate_field F E :=
{ carrier := λ s, ∃ x : (lifts F E K), x ∈ has_insert.insert ⊥ c ∧ (s ∈ x.1 : Prop),
zero_mem' := ⟨⊥, set.mem_insert ⊥ c, zero_mem ⊥⟩,
one_mem' := ⟨⊥, set.mem_insert ⊥ c, one_mem ⊥⟩,
neg_mem' := by { rintros _ ⟨x, y, h⟩, exact ⟨x, ⟨y, x.1.neg_mem h⟩⟩ },
inv_mem' := by { rintros _ ⟨x, y, h⟩, exact ⟨x, ⟨y, x.1.inv_mem h⟩⟩ },
add_mem' := by
{ rintros _ _ ⟨x, hx, ha⟩ ⟨y, hy, hb⟩,
obtain ⟨z, hz, hxz, hyz⟩ := lifts.exists_max_two hc hx hy,
exact ⟨z, hz, z.1.add_mem (hxz.1 ha) (hyz.1 hb)⟩ },
mul_mem' := by
{ rintros _ _ ⟨x, hx, ha⟩ ⟨y, hy, hb⟩,
obtain ⟨z, hz, hxz, hyz⟩ := lifts.exists_max_two hc hx hy,
exact ⟨z, hz, z.1.mul_mem (hxz.1 ha) (hyz.1 hb)⟩ },
algebra_map_mem' := λ s, ⟨⊥, set.mem_insert ⊥ c, algebra_map_mem ⊥ s⟩ }
/-- The lift on the upper bound on a chain of lifts -/
noncomputable def lifts.upper_bound_alg_hom {c : set (lifts F E K)} (hc : is_chain (≤) c) :
lifts.upper_bound_intermediate_field hc →ₐ[F] K :=
{ to_fun := λ s, (classical.some s.mem).2 ⟨s, (classical.some_spec s.mem).2⟩,
map_zero' := alg_hom.map_zero _,
map_one' := alg_hom.map_one _,
map_add' := λ s t, begin
obtain ⟨w, hw, hxw, hyw, hzw⟩ := lifts.exists_max_three hc
(classical.some_spec s.mem).1 (classical.some_spec t.mem).1
(classical.some_spec (s + t).mem).1,
rw [lifts.eq_of_le hxw, lifts.eq_of_le hyw, lifts.eq_of_le hzw, ←w.2.map_add],
refl,
end,
map_mul' := λ s t, begin
obtain ⟨w, hw, hxw, hyw, hzw⟩ := lifts.exists_max_three hc
(classical.some_spec s.mem).1 (classical.some_spec t.mem).1
(classical.some_spec (s * t).mem).1,
rw [lifts.eq_of_le hxw, lifts.eq_of_le hyw, lifts.eq_of_le hzw, ←w.2.map_mul],
refl,
end,
commutes' := λ _, alg_hom.commutes _ _ }
/-- An upper bound on a chain of lifts -/
noncomputable def lifts.upper_bound {c : set (lifts F E K)} (hc : is_chain (≤) c) :
lifts F E K :=
⟨lifts.upper_bound_intermediate_field hc, lifts.upper_bound_alg_hom hc⟩
lemma lifts.exists_upper_bound (c : set (lifts F E K)) (hc : is_chain (≤) c) :
∃ ub, ∀ a ∈ c, a ≤ ub :=
⟨lifts.upper_bound hc,
begin
intros x hx,
split,
{ exact λ s hs, ⟨x, set.mem_insert_of_mem ⊥ hx, hs⟩ },
{ intros s t hst,
change x.2 s = (classical.some t.mem).2 ⟨t, (classical.some_spec t.mem).2⟩,
obtain ⟨z, hz, hxz, hyz⟩ := lifts.exists_max_two hc (set.mem_insert_of_mem ⊥ hx)
(classical.some_spec t.mem).1,
rw [lifts.eq_of_le hxz, lifts.eq_of_le hyz],
exact congr_arg z.2 (subtype.ext hst) },
end⟩
/-- Extend a lift `x : lifts F E K` to an element `s : E` whose conjugates are all in `K` -/
noncomputable def lifts.lift_of_splits (x : lifts F E K) {s : E} (h1 : is_integral F s)
(h2 : (minpoly F s).splits (algebra_map F K)) : lifts F E K :=
let h3 : is_integral x.1 s := is_integral_of_is_scalar_tower h1 in
let key : (minpoly x.1 s).splits x.2.to_ring_hom :=
splits_of_splits_of_dvd _ (map_ne_zero (minpoly.ne_zero h1))
((splits_map_iff _ _).mpr (by {convert h2, exact ring_hom.ext (λ y, x.2.commutes y)}))
(minpoly.dvd_map_of_is_scalar_tower _ _ _) in
⟨x.1⟮s⟯.restrict_scalars F, (@alg_hom_equiv_sigma F x.1 (x.1⟮s⟯.restrict_scalars F) K _ _ _ _ _ _ _
(intermediate_field.algebra x.1⟮s⟯) (is_scalar_tower.of_algebra_map_eq (λ _, rfl))).inv_fun
⟨x.2, (@alg_hom_adjoin_integral_equiv x.1 _ E _ _ s K _ x.2.to_ring_hom.to_algebra
h3).inv_fun ⟨root_of_splits x.2.to_ring_hom key (ne_of_gt (minpoly.degree_pos h3)), by
{ simp_rw [mem_roots (map_ne_zero (minpoly.ne_zero h3)), is_root, ←eval₂_eq_eval_map],
exact map_root_of_splits x.2.to_ring_hom key (ne_of_gt (minpoly.degree_pos h3)) }⟩⟩⟩
lemma lifts.le_lifts_of_splits (x : lifts F E K) {s : E} (h1 : is_integral F s)
(h2 : (minpoly F s).splits (algebra_map F K)) : x ≤ x.lift_of_splits h1 h2 :=
⟨λ z hz, algebra_map_mem x.1⟮s⟯ ⟨z, hz⟩, λ t u htu, eq.symm begin
rw [←(show algebra_map x.1 x.1⟮s⟯ t = u, from subtype.ext htu)],
letI : algebra x.1 K := x.2.to_ring_hom.to_algebra,
exact (alg_hom.commutes _ t),
end⟩
lemma lifts.mem_lifts_of_splits (x : lifts F E K) {s : E} (h1 : is_integral F s)
(h2 : (minpoly F s).splits (algebra_map F K)) : s ∈ (x.lift_of_splits h1 h2).1 :=
mem_adjoin_simple_self x.1 s
lemma lifts.exists_lift_of_splits (x : lifts F E K) {s : E} (h1 : is_integral F s)
(h2 : (minpoly F s).splits (algebra_map F K)) : ∃ y, x ≤ y ∧ s ∈ y.1 :=
⟨x.lift_of_splits h1 h2, x.le_lifts_of_splits h1 h2, x.mem_lifts_of_splits h1 h2⟩
lemma alg_hom_mk_adjoin_splits
(hK : ∀ s ∈ S, is_integral F (s : E) ∧ (minpoly F s).splits (algebra_map F K)) :
nonempty (adjoin F S →ₐ[F] K) :=
begin
obtain ⟨x : lifts F E K, hx⟩ := zorn_partial_order lifts.exists_upper_bound,
refine ⟨alg_hom.mk (λ s, x.2 ⟨s, adjoin_le_iff.mpr (λ s hs, _) s.mem⟩) x.2.map_one (λ s t,
x.2.map_mul ⟨s, _⟩ ⟨t, _⟩) x.2.map_zero (λ s t, x.2.map_add ⟨s, _⟩ ⟨t, _⟩) x.2.commutes⟩,
rcases (x.exists_lift_of_splits (hK s hs).1 (hK s hs).2) with ⟨y, h1, h2⟩,
rwa hx y h1 at h2
end
lemma alg_hom_mk_adjoin_splits' (hS : adjoin F S = ⊤)
(hK : ∀ x ∈ S, is_integral F (x : E) ∧ (minpoly F x).splits (algebra_map F K)) :
nonempty (E →ₐ[F] K) :=
begin
cases alg_hom_mk_adjoin_splits hK with ϕ,
rw hS at ϕ,
exact ⟨ϕ.comp top_equiv.symm.to_alg_hom⟩,
end
end alg_hom_mk_adjoin_splits
section supremum
variables {K L : Type*} [field K] [field L] [algebra K L] (E1 E2 : intermediate_field K L)
lemma le_sup_to_subalgebra :
E1.to_subalgebra ⊔ E2.to_subalgebra ≤ (E1 ⊔ E2).to_subalgebra :=
sup_le (show E1 ≤ E1 ⊔ E2, from le_sup_left) (show E2 ≤ E1 ⊔ E2, from le_sup_right)
lemma sup_to_subalgebra [h1 : finite_dimensional K E1] [h2 : finite_dimensional K E2] :
(E1 ⊔ E2).to_subalgebra = E1.to_subalgebra ⊔ E2.to_subalgebra :=
begin
let S1 := E1.to_subalgebra,
let S2 := E2.to_subalgebra,
refine le_antisymm (show _ ≤ (S1 ⊔ S2).to_intermediate_field _, from (sup_le (show S1 ≤ _,
from le_sup_left) (show S2 ≤ _, from le_sup_right))) (le_sup_to_subalgebra E1 E2),
suffices : is_field ↥(S1 ⊔ S2),
{ intros x hx,
by_cases hx' : (⟨x, hx⟩ : S1 ⊔ S2) = 0,
{ rw [←subtype.coe_mk x hx, hx', subalgebra.coe_zero, inv_zero],
exact (S1 ⊔ S2).zero_mem },
{ obtain ⟨y, h⟩ := this.mul_inv_cancel hx',
exact (congr_arg (∈ S1 ⊔ S2) $ eq_inv_of_mul_eq_one_right $ subtype.ext_iff.mp h).mp y.2 } },
exact is_field_of_is_integral_of_is_field'
(is_integral_sup.mpr ⟨algebra.is_integral_of_finite K E1, algebra.is_integral_of_finite K E2⟩)
(field.to_is_field K),
end
instance finite_dimensional_sup [h1 : finite_dimensional K E1] [h2 : finite_dimensional K E2] :
finite_dimensional K ↥(E1 ⊔ E2) :=
begin
let g := algebra.tensor_product.product_map E1.val E2.val,
suffices : g.range = (E1 ⊔ E2).to_subalgebra,
{ have h : finite_dimensional K g.range.to_submodule := g.to_linear_map.finite_dimensional_range,
rwa this at h },
rw [algebra.tensor_product.product_map_range, E1.range_val, E2.range_val, sup_to_subalgebra],
end
instance finite_dimensional_supr_of_finite
{ι : Type*} {t : ι → intermediate_field K L} [h : finite ι] [Π i, finite_dimensional K (t i)] :
finite_dimensional K (⨆ i, t i : intermediate_field K L) :=
begin
rw ← supr_univ,
let P : set ι → Prop := λ s, finite_dimensional K (⨆ i ∈ s, t i : intermediate_field K L),
change P set.univ,
apply set.finite.induction_on,
{ exact set.finite_univ },
all_goals { dsimp only [P] },
{ rw supr_emptyset,
exact (bot_equiv K L).symm.to_linear_equiv.finite_dimensional },
{ intros _ s _ _ hs,
rw supr_insert,
exactI intermediate_field.finite_dimensional_sup _ _ },
end
instance finite_dimensional_supr_of_finset {ι : Type*}
{f : ι → intermediate_field K L} {s : finset ι} [h : Π i ∈ s, finite_dimensional K (f i)] :
finite_dimensional K (⨆ i ∈ s, f i : intermediate_field K L) :=
begin
haveI : Π i : {i // i ∈ s}, finite_dimensional K (f i) := λ i, h i i.2,
have : (⨆ i ∈ s, f i) = ⨆ i : {i // i ∈ s}, f i :=
le_antisymm (supr_le (λ i, supr_le (λ h, le_supr (λ i : {i // i ∈ s}, f i) ⟨i, h⟩)))
(supr_le (λ i, le_supr_of_le i (le_supr_of_le i.2 le_rfl))),
exact this.symm ▸ intermediate_field.finite_dimensional_supr_of_finite,
end
/-- A compositum of algebraic extensions is algebraic -/
lemma is_algebraic_supr {ι : Type*} {f : ι → intermediate_field K L}
(h : ∀ i, algebra.is_algebraic K (f i)) :
algebra.is_algebraic K (⨆ i, f i : intermediate_field K L) :=
begin
rintros ⟨x, hx⟩,
obtain ⟨s, hx⟩ := exists_finset_of_mem_supr' hx,
rw [is_algebraic_iff, subtype.coe_mk, ←subtype.coe_mk x hx, ←is_algebraic_iff],
haveI : ∀ i : (Σ i, f i), finite_dimensional K K⟮(i.2 : L)⟯ :=
λ ⟨i, x⟩, adjoin.finite_dimensional (is_integral_iff.1 (is_algebraic_iff_is_integral.1 (h i x))),
apply algebra.is_algebraic_of_finite,
end
end supremum
end intermediate_field
section power_basis
variables {K L : Type*} [field K] [field L] [algebra K L]
namespace power_basis
open intermediate_field
/-- `pb.equiv_adjoin_simple` is the equivalence between `K⟮pb.gen⟯` and `L` itself. -/
noncomputable def equiv_adjoin_simple (pb : power_basis K L) :
K⟮pb.gen⟯ ≃ₐ[K] L :=
(adjoin.power_basis pb.is_integral_gen).equiv_of_minpoly pb
(minpoly.eq_of_algebra_map_eq (algebra_map K⟮pb.gen⟯ L).injective
(adjoin.power_basis pb.is_integral_gen).is_integral_gen
(by rw [adjoin.power_basis_gen, adjoin_simple.algebra_map_gen]))
@[simp]
lemma equiv_adjoin_simple_aeval (pb : power_basis K L) (f : K[X]) :
pb.equiv_adjoin_simple (aeval (adjoin_simple.gen K pb.gen) f) = aeval pb.gen f :=
equiv_of_minpoly_aeval _ pb _ f
@[simp]
lemma equiv_adjoin_simple_gen (pb : power_basis K L) :
pb.equiv_adjoin_simple (adjoin_simple.gen K pb.gen) = pb.gen :=
equiv_of_minpoly_gen _ pb _
@[simp]
lemma equiv_adjoin_simple_symm_aeval (pb : power_basis K L) (f : K[X]) :
pb.equiv_adjoin_simple.symm (aeval pb.gen f) = aeval (adjoin_simple.gen K pb.gen) f :=
by rw [equiv_adjoin_simple, equiv_of_minpoly_symm, equiv_of_minpoly_aeval, adjoin.power_basis_gen]
@[simp]
lemma equiv_adjoin_simple_symm_gen (pb : power_basis K L) :
pb.equiv_adjoin_simple.symm pb.gen = (adjoin_simple.gen K pb.gen) :=
by rw [equiv_adjoin_simple, equiv_of_minpoly_symm, equiv_of_minpoly_gen, adjoin.power_basis_gen]
end power_basis
end power_basis
|
625b12006fbe3eddafa973fb51bab2bea55fce20 | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/bad_simp.lean | e164bb726a34217e9c02794fc1f588c19320eb46 | [
"Apache-2.0"
] | permissive | codyroux/lean0.1 | 1ce92751d664aacff0529e139083304a7bbc8a71 | 0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef | refs/heads/master | 1,610,830,535,062 | 1,402,150,480,000 | 1,402,150,480,000 | 19,588,851 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 434 | lean | variable f : Nat → Nat
variable g : Nat → Nat
axiom Ax1 : ∀ x, f x = g (f x)
rewrite_set S
add_rewrite Ax1 : S
-- Ax1 is not included in the rewrite rule set because the left-hand-side occurs in the right-hand side
print rewrite_set S
axiom Ax2 : ∀ x, f x > 0 → f x = x
add_rewrite Ax2 : S
-- Ax2 is not included in the rewrite rule set because the left-hand-side occurs in the hypothesis
print rewrite_set S
print "done"
|
17eb6179835e9a86d1669c7f6d195fb920f99c1c | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/combinatorics/colex.lean | 1ed70420debd1f69ae684ffed649f6a9f7165a49 | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,883 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Alena Gusakov
-/
import data.finset
import data.fintype.basic
import algebra.geom_sum
import tactic
/-!
# Colex
We define the colex ordering for finite sets, and give a couple of important
lemmas and properties relating to it.
The colex ordering likes to avoid large values - it can be thought of on
`finset ℕ` as the "binary" ordering. That is, order A based on
`∑_{i ∈ A} 2^i`.
It's defined here in a slightly more general way, requiring only `has_lt α` in
the definition of colex on `finset α`. In the context of the Kruskal-Katona
theorem, we are interested in particular on how colex behaves for sets of a
fixed size. If the size is 3, colex on ℕ starts
123, 124, 134, 234, 125, 135, 235, 145, 245, 345, ...
## Main statements
* `colex_hom`: strictly monotone functions preserve colex
* Colex order properties - linearity, decidability and so on.
* `forall_lt_of_colex_lt_of_forall_lt`: if A < B in colex, and everything
in B is < t, then everything in A is < t. This confirms the idea that
an enumeration under colex will exhaust all sets using elements < t before
allowing t to be included.
* `binary_iff`: colex for α = ℕ is the same as binary
(this also proves binary expansions are unique)
## Notation
We define `<` and `≤` to denote colex ordering, useful in particular when
multiple orderings are available in context.
## Tags
colex, colexicographic, binary
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
## Todo
Show the subset ordering is a sub-relation of the colex ordering.
-/
variable {α : Type*}
open finset
/--
We define this type synonym to refer to the colexicographic ordering on finsets
rather than the natural subset ordering.
-/
@[derive inhabited]
def finset.colex (α) := finset α
/--
A convenience constructor to turn a `finset α` into a `finset.colex α`, useful in order to
use the colex ordering rather than the subset ordering.
-/
def finset.to_colex {α} (s : finset α) : finset.colex α := s
@[simp]
lemma colex.eq_iff (A B : finset α) :
A.to_colex = B.to_colex ↔ A = B := by refl
/--
`A` is less than `B` in the colex ordering if the largest thing that's not in both sets is in B.
In other words, max (A ▵ B) ∈ B (if the maximum exists).
-/
instance [has_lt α] : has_lt (finset.colex α) :=
⟨λ (A B : finset α), ∃ (k : α), (∀ {x}, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A ∧ k ∈ B⟩
/-- We can define (≤) in the obvious way. -/
instance [has_lt α] : has_le (finset.colex α) :=
⟨λ A B, A < B ∨ A = B⟩
lemma colex.lt_def [has_lt α] (A B : finset α) :
A.to_colex < B.to_colex ↔ ∃ k, (∀ {x}, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A ∧ k ∈ B :=
iff.rfl
lemma colex.le_def [has_lt α] (A B : finset α) :
A.to_colex ≤ B.to_colex ↔ A.to_colex < B.to_colex ∨ A = B :=
iff.rfl
/-- If everything in A is less than k, we can bound the sum of powers. -/
lemma nat.sum_sq_lt {k : ℕ} {A : finset ℕ} (h₁ : ∀ {x}, x ∈ A → x < k) :
A.sum (pow 2) < 2^k :=
begin
apply lt_of_le_of_lt (sum_le_sum_of_subset (λ t, mem_range.2 ∘ h₁)),
have z := geom_sum_mul_add 1 k,
rw [geom_sum, mul_one, one_add_one_eq_two] at z,
rw ← z,
apply nat.lt_succ_self,
end
alias nat.sum_sq_lt ← nat.sum_pow_two_lt
namespace colex
/-- Strictly monotone functions preserve the colex ordering. -/
lemma hom {β : Type*} [linear_order α] [decidable_eq β] [preorder β]
{f : α → β} (h₁ : strict_mono f) (A B : finset α) :
(A.image f).to_colex < (B.image f).to_colex ↔ A.to_colex < B.to_colex :=
begin
simp only [colex.lt_def, not_exists, mem_image, exists_prop, not_and],
split,
{ rintro ⟨k, z, q, k', _, rfl⟩,
exact ⟨k', λ x hx, by simpa [h₁.injective.eq_iff] using z (h₁ hx), λ t, q _ t rfl, ‹k' ∈ B›⟩ },
rintro ⟨k, z, ka, _⟩,
refine ⟨f k, λ x hx, _, _, k, ‹k ∈ B›, rfl⟩,
{ split,
any_goals {
rintro ⟨x', hx', rfl⟩,
refine ⟨x', _, rfl⟩,
rwa ← z _ <|> rwa z _,
rwa strict_mono.lt_iff_lt h₁ at hx } },
{ simp only [h₁.injective, function.injective.eq_iff],
exact λ x hx, ne_of_mem_of_not_mem hx ka }
end
/-- A special case of `colex_hom` which is sometimes useful. -/
@[simp] lemma hom_fin {n : ℕ} (A B : finset (fin n)) :
finset.to_colex (A.image (λ n, (n : ℕ))) < finset.to_colex (B.image (λ n, (n : ℕ)))
↔ finset.to_colex A < finset.to_colex B :=
colex.hom (λ x y k, k) _ _
instance [has_lt α] : is_irrefl (finset.colex α) (<) :=
⟨λ A h, exists.elim h (λ _ ⟨_,a,b⟩, a b)⟩
@[trans]
lemma lt_trans [linear_order α] {a b c : finset.colex α} :
a < b → b < c → a < c :=
begin
rintros ⟨k₁, k₁z, notinA, inB⟩ ⟨k₂, k₂z, notinB, inC⟩,
cases lt_or_gt_of_ne (ne_of_mem_of_not_mem inB notinB),
{ refine ⟨k₂, _, by rwa k₁z h, inC⟩,
intros x hx,
rw ← k₂z hx,
apply k₁z (trans h hx) },
{ refine ⟨k₁, _, notinA, by rwa ← k₂z h⟩,
intros x hx,
rw k₁z hx,
apply k₂z (trans h hx) }
end
@[trans]
lemma le_trans [linear_order α] (a b c : finset.colex α) :
a ≤ b → b ≤ c → a ≤ c :=
λ AB BC, AB.elim (λ k, BC.elim (λ t, or.inl (lt_trans k t)) (λ t, t ▸ AB)) (λ k, k.symm ▸ BC)
instance [linear_order α] : is_trans (finset.colex α) (<) := ⟨λ _ _ _, colex.lt_trans⟩
instance [linear_order α] : is_asymm (finset.colex α) (<) := by apply_instance
instance [linear_order α] : is_strict_order (finset.colex α) (<) := {}
lemma lt_trichotomy [linear_order α] (A B : finset.colex α) :
A < B ∨ A = B ∨ B < A :=
begin
by_cases h₁ : (A = B),
{ tauto },
rcases (exists_max_image (A \ B ∪ B \ A) id _) with ⟨k, hk, z⟩,
{ simp only [mem_union, mem_sdiff] at hk,
cases hk,
{ right,
right,
refine ⟨k, λ t th, _, hk.2, hk.1⟩,
specialize z t,
by_contra h₂,
simp only [mem_union, mem_sdiff, id.def] at z,
rw [not_iff, iff_iff_and_or_not_and_not, not_not, and_comm] at h₂,
apply not_le_of_lt th (z h₂) },
{ left,
refine ⟨k, λ t th, _, hk.2, hk.1⟩,
specialize z t,
by_contra h₃,
simp only [mem_union, mem_sdiff, id.def] at z,
rw [not_iff, iff_iff_and_or_not_and_not, not_not, and_comm, or_comm] at h₃,
apply not_le_of_lt th (z h₃) }, },
rw nonempty_iff_ne_empty,
intro a,
simp only [union_eq_empty_iff, sdiff_eq_empty_iff_subset] at a,
apply h₁ (subset.antisymm a.1 a.2)
end
instance [linear_order α] : is_trichotomous (finset.colex α) (<) := ⟨lt_trichotomy⟩
-- It should be possible to do this computably but it doesn't seem to make any difference for now.
noncomputable instance [linear_order α] : linear_order (finset.colex α) :=
{ le_refl := λ A, or.inr rfl,
le_trans := le_trans,
le_antisymm := λ A B AB BA, AB.elim (λ k, BA.elim (λ t, (asymm k t).elim) (λ t, t.symm)) id,
le_total := λ A B,
(lt_trichotomy A B).elim3 (or.inl ∘ or.inl) (or.inl ∘ or.inr) (or.inr ∘ or.inl),
decidable_le := classical.dec_rel _,
..finset.colex.has_le }
instance [linear_order α] : is_incomp_trans (finset.colex α) (<) :=
begin
constructor,
rintros A B C ⟨nAB, nBA⟩ ⟨nBC, nCB⟩,
have : A = B := ((lt_trichotomy A B).resolve_left nAB).resolve_right nBA,
have : B = C := ((lt_trichotomy B C).resolve_left nBC).resolve_right nCB,
rw [‹A = B›, ‹B = C›, and_self],
apply irrefl
end
instance [linear_order α] : is_strict_weak_order (finset.colex α) (<) := {}
instance [linear_order α] : is_strict_total_order (finset.colex α) (<) := {}
/-- If {r} is less than or equal to s in the colexicographical sense,
then s contains an element greater than or equal to r. -/
lemma mem_le_of_singleton_le [linear_order α] {r : α} {s : finset α}:
({r} : finset α).to_colex ≤ s.to_colex → ∃ x ∈ s, r ≤ x :=
begin
intro h,
rw colex.le_def at h,
cases h with lt eq,
{ rw colex.lt_def at lt,
rcases lt with ⟨k, hk, hi, hj⟩,
by_cases hr : r ∈ s,
{ use r,
tauto },
{ contrapose! hk,
simp only [mem_singleton],
specialize hk k,
use r,
split,
{ apply hk,
cc },
{ simp,
exact hr } } },
{ rw ← eq,
use r,
simp only [true_and, eq_self_iff_true, mem_singleton] },
end
/-- s.to_colex < finset.to_colex {r} iff all elements of s are less than r. -/
lemma lt_singleton_iff_mem_lt [linear_order α] {r : α} {s : finset α}:
s.to_colex < finset.to_colex {r} ↔ ∀ x ∈ s, x < r :=
begin
simp only [lt_def, mem_singleton, ← and_assoc, exists_eq_right],
split,
{ rintro ⟨q, rs⟩ x hx,
by_contra h,
rw not_lt at h,
cases lt_or_eq_of_le h with h₁ h₁,
{ rw q h₁ at hx,
subst hx,
apply lt_irrefl x h₁ },
{ apply rs,
rwa h₁ } },
{ intro h,
refine ⟨λ z hz, _, _⟩,
{ split,
{ intro hr,
exfalso,
apply lt_asymm (h _ hr) hz },
{ rintro rfl,
apply (lt_irrefl _ hz).elim } },
{ intro rs,
apply lt_irrefl _ (h _ rs) } }
end
/-- Colex is an extension of the base ordering on α. -/
lemma singleton_lt_iff_lt [linear_order α] {r s : α} :
({r} : finset α).to_colex < ({s} : finset α).to_colex ↔ r < s :=
begin
rw colex.lt_def,
simp only [mem_singleton, ← and_assoc, exists_eq_right],
split,
{ rintro ⟨q, p⟩,
apply lt_of_le_of_ne _ (ne.symm p),
contrapose! p,
rw (q p).1 rfl },
{ intro a,
exact ⟨λ z hz, iff_of_false (ne_of_gt (trans a hz)) (ne_of_gt hz), ne_of_gt a⟩ }
end
/--
If A is before B in colex, and everything in B is small, then everything in A is small.
-/
lemma forall_lt_of_colex_lt_of_forall_lt [linear_order α] {A B : finset α}
(t : α) (h₁ : A.to_colex < B.to_colex) (h₂ : ∀ x ∈ B, x < t) :
∀ x ∈ A, x < t :=
begin
rw colex.lt_def at h₁,
rcases h₁ with ⟨k, z, _, _⟩,
intros x hx,
apply lt_of_not_ge,
intro a,
refine not_lt_of_ge a (h₂ x _),
rwa ← z,
apply lt_of_lt_of_le (h₂ k ‹_›) a,
end
/-- Colex doesn't care if you remove the other set -/
@[simp] lemma sdiff_lt_sdiff_iff_lt [has_lt α] [decidable_eq α] (A B : finset α) :
(A \ B).to_colex < (B \ A).to_colex ↔ A.to_colex < B.to_colex :=
begin
rw [colex.lt_def, colex.lt_def],
apply exists_congr,
intro k,
simp only [mem_sdiff, not_and, not_not],
split,
{ rintro ⟨z, kAB, kB, kA⟩,
refine ⟨_, kA, kB⟩,
{ intros x hx,
specialize z hx,
tauto } },
{ rintro ⟨z, kA, kB⟩,
refine ⟨_, λ _, kB, kB, kA⟩,
intros x hx,
rw z hx },
end
/-- For subsets of ℕ, we can show that colex is equivalent to binary. -/
lemma sum_sq_lt_iff_lt (A B : finset ℕ) : A.sum (pow 2) < B.sum (pow 2) ↔
A.to_colex < B.to_colex :=
begin
have z : ∀ (A B : finset ℕ), A.to_colex < B.to_colex → A.sum (pow 2) < B.sum (pow 2),
{ intros A B,
rw [← sdiff_lt_sdiff_iff_lt, colex.lt_def],
rintro ⟨k, z, kA, kB⟩,
rw ← sdiff_union_inter A B,
conv_rhs { rw ← sdiff_union_inter B A },
rw [sum_union (disjoint_sdiff_inter _ _), sum_union (disjoint_sdiff_inter _ _),
inter_comm, add_lt_add_iff_right],
apply lt_of_lt_of_le (@nat.sum_sq_lt k (A \ B) _),
{ apply single_le_sum (λ _ _, nat.zero_le _) kB },
intros x hx,
apply lt_of_le_of_ne (le_of_not_lt (λ kx, _)),
{ apply (ne_of_mem_of_not_mem hx kA) },
specialize z kx,
have := z.1 hx,
rw mem_sdiff at this hx,
exact hx.2 this.1 },
refine ⟨λ h, (lt_trichotomy A B).resolve_right (λ h₁, h₁.elim _ (not_lt_of_gt h ∘ z _ _)), z A B⟩,
rintro rfl,
apply irrefl _ h
end
end colex
|
879e78d62090738ee953e90b75bd4d72a2665333 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/monoidal/braided.lean | a34aed74d0b9a8b93071a169d47ad560185d4802 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 11,474 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.monoidal.natural_transformation
import category_theory.monoidal.discrete
/-!
# Braided and symmetric monoidal categories
The basic definitions of braided monoidal categories, and symmetric monoidal categories,
as well as braided functors.
## Implementation note
We make `braided_monoidal_category` another typeclass, but then have `symmetric_monoidal_category`
extend this. The rationale is that we are not carrying any additional data,
just requiring a property.
## Future work
* Construct the Drinfeld center of a monoidal category as a braided monoidal category.
* Say something about pseudo-natural transformations.
-/
open category_theory
universes v v₁ v₂ v₃ u u₁ u₂ u₃
namespace category_theory
/--
A braided monoidal category is a monoidal category equipped with a braiding isomorphism
`β_ X Y : X ⊗ Y ≅ Y ⊗ X`
which is natural in both arguments,
and also satisfies the two hexagon identities.
-/
class braided_category (C : Type u) [category.{v} C] [monoidal_category.{v} C] :=
-- braiding natural iso:
(braiding : Π X Y : C, X ⊗ Y ≅ Y ⊗ X)
(braiding_naturality' : ∀ {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y'),
(f ⊗ g) ≫ (braiding Y Y').hom = (braiding X X').hom ≫ (g ⊗ f) . obviously)
-- hexagon identities:
(hexagon_forward' : Π X Y Z : C,
(α_ X Y Z).hom ≫ (braiding X (Y ⊗ Z)).hom ≫ (α_ Y Z X).hom
= ((braiding X Y).hom ⊗ (𝟙 Z)) ≫ (α_ Y X Z).hom ≫ ((𝟙 Y) ⊗ (braiding X Z).hom)
. obviously)
(hexagon_reverse' : Π X Y Z : C,
(α_ X Y Z).inv ≫ (braiding (X ⊗ Y) Z).hom ≫ (α_ Z X Y).inv
= ((𝟙 X) ⊗ (braiding Y Z).hom) ≫ (α_ X Z Y).inv ≫ ((braiding X Z).hom ⊗ (𝟙 Y))
. obviously)
restate_axiom braided_category.braiding_naturality'
attribute [simp,reassoc] braided_category.braiding_naturality
restate_axiom braided_category.hexagon_forward'
restate_axiom braided_category.hexagon_reverse'
open category
open monoidal_category
open braided_category
notation `β_` := braiding
section
/-!
We now establish how the braiding interacts with the unitors.
I couldn't find a detailed proof in print, but this is discussed in:
* Proposition 1 of André Joyal and Ross Street,
"Braided monoidal categories", Macquarie Math Reports 860081 (1986).
* Proposition 2.1 of André Joyal and Ross Street,
"Braided tensor categories" , Adv. Math. 102 (1993), 20–78.
* Exercise 8.1.6 of Etingof, Gelaki, Nikshych, Ostrik,
"Tensor categories", vol 25, Mathematical Surveys and Monographs (2015), AMS.
-/
variables (C : Type u₁) [category.{v₁} C] [monoidal_category C] [braided_category C]
lemma braiding_left_unitor_aux₁ (X : C) :
(α_ (𝟙_ C) (𝟙_ C) X).hom ≫ (𝟙 _ ⊗ (β_ X (𝟙_ C)).inv) ≫ (α_ _ X _).inv ≫ ((λ_ X).hom ⊗ 𝟙 _) =
((λ_ _).hom ⊗ 𝟙 X) ≫ (β_ X _).inv :=
by { rw [←left_unitor_tensor, left_unitor_naturality], simp, }
lemma braiding_left_unitor_aux₂ (X : C) :
((β_ X (𝟙_ C)).hom ⊗ (𝟙 (𝟙_ C))) ≫ ((λ_ X).hom ⊗ (𝟙 (𝟙_ C))) = (ρ_ X).hom ⊗ (𝟙 (𝟙_ C)) :=
calc ((β_ X (𝟙_ C)).hom ⊗ (𝟙 (𝟙_ C))) ≫ ((λ_ X).hom ⊗ (𝟙 (𝟙_ C)))
= ((β_ X (𝟙_ C)).hom ⊗ (𝟙 (𝟙_ C))) ≫ (α_ _ _ _).hom ≫ (α_ _ _ _).inv ≫
((λ_ X).hom ⊗ (𝟙 (𝟙_ C)))
: by simp
... = ((β_ X (𝟙_ C)).hom ⊗ (𝟙 (𝟙_ C))) ≫ (α_ _ _ _).hom ≫ (𝟙 _ ⊗ (β_ X _).hom) ≫
(𝟙 _ ⊗ (β_ X _).inv) ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ⊗ (𝟙 (𝟙_ C)))
: by { slice_rhs 3 4 { rw [←id_tensor_comp, iso.hom_inv_id, tensor_id], }, rw [id_comp], }
... = (α_ _ _ _).hom ≫ (β_ _ _).hom ≫
(α_ _ _ _).hom ≫ (𝟙 _ ⊗ (β_ X _).inv) ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ⊗ (𝟙 (𝟙_ C)))
: by { slice_lhs 1 3 { rw ←hexagon_forward }, simp only [assoc], }
... = (α_ _ _ _).hom ≫ (β_ _ _).hom ≫ ((λ_ _).hom ⊗ 𝟙 X) ≫ (β_ X _).inv
: by rw braiding_left_unitor_aux₁
... = (α_ _ _ _).hom ≫ (𝟙 _ ⊗ (λ_ _).hom) ≫ (β_ _ _).hom ≫ (β_ X _).inv
: by { slice_lhs 2 3 { rw [←braiding_naturality] }, simp only [assoc], }
... = (α_ _ _ _).hom ≫ (𝟙 _ ⊗ (λ_ _).hom)
: by rw [iso.hom_inv_id, comp_id]
... = (ρ_ X).hom ⊗ (𝟙 (𝟙_ C))
: by rw triangle
@[simp]
lemma braiding_left_unitor (X : C) : (β_ X (𝟙_ C)).hom ≫ (λ_ X).hom = (ρ_ X).hom :=
by rw [←tensor_right_iff, comp_tensor_id, braiding_left_unitor_aux₂]
lemma braiding_right_unitor_aux₁ (X : C) :
(α_ X (𝟙_ C) (𝟙_ C)).inv ≫ ((β_ (𝟙_ C) X).inv ⊗ 𝟙 _) ≫ (α_ _ X _).hom ≫ (𝟙 _ ⊗ (ρ_ X).hom) =
(𝟙 X ⊗ (ρ_ _).hom) ≫ (β_ _ X).inv :=
by { rw [←right_unitor_tensor, right_unitor_naturality], simp, }
lemma braiding_right_unitor_aux₂ (X : C) :
((𝟙 (𝟙_ C)) ⊗ (β_ (𝟙_ C) X).hom) ≫ ((𝟙 (𝟙_ C)) ⊗ (ρ_ X).hom) = (𝟙 (𝟙_ C)) ⊗ (λ_ X).hom :=
calc ((𝟙 (𝟙_ C)) ⊗ (β_ (𝟙_ C) X).hom) ≫ ((𝟙 (𝟙_ C)) ⊗ (ρ_ X).hom)
= ((𝟙 (𝟙_ C)) ⊗ (β_ (𝟙_ C) X).hom) ≫ (α_ _ _ _).inv ≫ (α_ _ _ _).hom ≫
((𝟙 (𝟙_ C)) ⊗ (ρ_ X).hom)
: by simp
... = ((𝟙 (𝟙_ C)) ⊗ (β_ (𝟙_ C) X).hom) ≫ (α_ _ _ _).inv ≫ ((β_ _ X).hom ⊗ 𝟙 _) ≫
((β_ _ X).inv ⊗ 𝟙 _) ≫ (α_ _ _ _).hom ≫ ((𝟙 (𝟙_ C)) ⊗ (ρ_ X).hom)
: by { slice_rhs 3 4 { rw [←comp_tensor_id, iso.hom_inv_id, tensor_id], }, rw [id_comp], }
... = (α_ _ _ _).inv ≫ (β_ _ _).hom ≫
(α_ _ _ _).inv ≫ ((β_ _ X).inv ⊗ 𝟙 _) ≫ (α_ _ _ _).hom ≫ ((𝟙 (𝟙_ C)) ⊗ (ρ_ X).hom)
: by { slice_lhs 1 3 { rw ←hexagon_reverse }, simp only [assoc], }
... = (α_ _ _ _).inv ≫ (β_ _ _).hom ≫ (𝟙 X ⊗ (ρ_ _).hom) ≫ (β_ _ X).inv
: by rw braiding_right_unitor_aux₁
... = (α_ _ _ _).inv ≫ ((ρ_ _).hom ⊗ 𝟙 _) ≫ (β_ _ X).hom ≫ (β_ _ _).inv
: by { slice_lhs 2 3 { rw [←braiding_naturality] }, simp only [assoc], }
... = (α_ _ _ _).inv ≫ ((ρ_ _).hom ⊗ 𝟙 _)
: by rw [iso.hom_inv_id, comp_id]
... = (𝟙 (𝟙_ C)) ⊗ (λ_ X).hom
: by rw [triangle_assoc_comp_right]
@[simp]
lemma braiding_right_unitor (X : C) : (β_ (𝟙_ C) X).hom ≫ (ρ_ X).hom = (λ_ X).hom :=
by rw [←tensor_left_iff, id_tensor_comp, braiding_right_unitor_aux₂]
end
/--
A symmetric monoidal category is a braided monoidal category for which the braiding is symmetric.
See https://stacks.math.columbia.edu/tag/0FFW.
-/
class symmetric_category (C : Type u) [category.{v} C] [monoidal_category.{v} C]
extends braided_category.{v} C :=
-- braiding symmetric:
(symmetry' : ∀ X Y : C, (β_ X Y).hom ≫ (β_ Y X).hom = 𝟙 (X ⊗ Y) . obviously)
restate_axiom symmetric_category.symmetry'
attribute [simp,reassoc] symmetric_category.symmetry
variables (C : Type u₁) [category.{v₁} C] [monoidal_category C] [braided_category C]
variables (D : Type u₂) [category.{v₂} D] [monoidal_category D] [braided_category D]
variables (E : Type u₃) [category.{v₃} E] [monoidal_category E] [braided_category E]
/--
A lax braided functor between braided monoidal categories is a lax monoidal functor
which preserves the braiding.
-/
structure lax_braided_functor extends lax_monoidal_functor C D :=
(braided' : ∀ X Y : C, μ X Y ≫ map (β_ X Y).hom = (β_ (obj X) (obj Y)).hom ≫ μ Y X . obviously)
restate_axiom lax_braided_functor.braided'
namespace lax_braided_functor
/-- The identity lax braided monoidal functor. -/
@[simps] def id : lax_braided_functor C C :=
{ .. monoidal_functor.id C }
instance : inhabited (lax_braided_functor C C) := ⟨id C⟩
variables {C D E}
/-- The composition of lax braided monoidal functors. -/
@[simps]
def comp (F : lax_braided_functor C D) (G : lax_braided_functor D E) : lax_braided_functor C E :=
{ braided' := λ X Y,
begin
dsimp,
slice_lhs 2 3 { rw [←category_theory.functor.map_comp, F.braided,
category_theory.functor.map_comp], },
slice_lhs 1 2 { rw [G.braided], },
simp only [category.assoc],
end,
..(lax_monoidal_functor.comp F.to_lax_monoidal_functor G.to_lax_monoidal_functor) }
instance category_lax_braided_functor : category (lax_braided_functor C D) :=
induced_category.category lax_braided_functor.to_lax_monoidal_functor
@[simp] lemma comp_to_nat_trans {F G H : lax_braided_functor C D} {α : F ⟶ G} {β : G ⟶ H} :
(α ≫ β).to_nat_trans =
@category_struct.comp (C ⥤ D) _ _ _ _ (α.to_nat_trans) (β.to_nat_trans) := rfl
/--
Interpret a natural isomorphism of the underlyling lax monoidal functors as an
isomorphism of the lax braided monoidal functors.
-/
@[simps]
def mk_iso {F G : lax_braided_functor C D}
(i : F.to_lax_monoidal_functor ≅ G.to_lax_monoidal_functor) : F ≅ G :=
{ ..i }
end lax_braided_functor
/--
A braided functor between braided monoidal categories is a monoidal functor
which preserves the braiding.
-/
structure braided_functor extends monoidal_functor C D :=
-- Note this is stated differently than for `lax_braided_functor`.
-- We move the `μ X Y` to the right hand side,
-- so that this makes a good `@[simp]` lemma.
(braided' :
∀ X Y : C, map (β_ X Y).hom = inv (μ X Y) ≫ (β_ (obj X) (obj Y)).hom ≫ μ Y X . obviously)
restate_axiom braided_functor.braided'
attribute [simp] braided_functor.braided
namespace braided_functor
/-- Turn a braided functor into a lax braided functor. -/
@[simps]
def to_lax_braided_functor (F : braided_functor C D) : lax_braided_functor C D :=
{ braided' := λ X Y, by { rw F.braided, simp, }
.. F }
/-- The identity braided monoidal functor. -/
@[simps] def id : braided_functor C C :=
{ .. monoidal_functor.id C }
instance : inhabited (braided_functor C C) := ⟨id C⟩
variables {C D E}
/-- The composition of braided monoidal functors. -/
@[simps]
def comp (F : braided_functor C D) (G : braided_functor D E) : braided_functor C E :=
{ ..(monoidal_functor.comp F.to_monoidal_functor G.to_monoidal_functor) }
instance category_braided_functor : category (braided_functor C D) :=
induced_category.category braided_functor.to_monoidal_functor
@[simp] lemma comp_to_nat_trans {F G H : braided_functor C D} {α : F ⟶ G} {β : G ⟶ H} :
(α ≫ β).to_nat_trans =
@category_struct.comp (C ⥤ D) _ _ _ _ (α.to_nat_trans) (β.to_nat_trans) := rfl
/--
Interpret a natural isomorphism of the underlyling monoidal functors as an
isomorphism of the braided monoidal functors.
-/
@[simps]
def mk_iso {F G : braided_functor C D}
(i : F.to_monoidal_functor ≅ G.to_monoidal_functor) : F ≅ G :=
{ ..i }
end braided_functor
section comm_monoid
variables (M : Type u) [comm_monoid M]
instance comm_monoid_discrete : comm_monoid (discrete M) := by { dsimp [discrete], apply_instance }
instance : braided_category (discrete M) :=
{ braiding := λ X Y, eq_to_iso (mul_comm X Y), }
variables {M} {N : Type u} [comm_monoid N]
/--
A multiplicative morphism between commutative monoids gives a braided functor between
the corresponding discrete braided monoidal categories.
-/
@[simps]
def discrete.braided_functor (F : M →* N) : braided_functor (discrete M) (discrete N) :=
{ ..discrete.monoidal_functor F }
end comm_monoid
end category_theory
|
6cc57dde6b01709eb4125ea4728b361f5c28b9c6 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /archive/100-theorems-list/93_birthday_problem.lean | 2e2602bf9ca906cf42b07a95fafb726918118418 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 846 | lean | /-
Copyright (c) 2021 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import data.fintype.card_embedding
/-!
# Birthday Problem
This file proves Theorem 93 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).
As opposed to the standard probabilistic statement, we instead state the birthday problem
in terms of injective functions. The general result about `fintype.card (α ↪ β)` which this proof
uses is `fintype.card_embedding_eq`.
-/
local notation `‖` x `‖` := fintype.card x
theorem birthday :
2 * ‖fin 23 ↪ fin 365‖ < ‖fin 23 → fin 365‖ ∧ 2 * ‖fin 22 ↪ fin 365‖ > ‖fin 22 → fin 365‖ :=
begin
simp only [nat.desc_factorial, fintype.card_fin, fintype.card_embedding_eq, fintype.card_fun],
norm_num
end
|
7509f254657de5c7e89b90b63b555827d71209b0 | 5883d9218e6f144e20eee6ca1dab8529fa1a97c0 | /src/db/type.lean | ce3c27641633c264f9c554bb787540d1edcde525 | [] | no_license | spl/alpha-conversion-is-easy | 0d035bc570e52a6345d4890e4d0c9e3f9b8126c1 | ed937fe85d8495daffd9412a5524c77b9fcda094 | refs/heads/master | 1,607,649,280,020 | 1,517,380,240,000 | 1,517,380,240,000 | 52,174,747 | 4 | 0 | null | 1,456,052,226,000 | 1,456,001,163,000 | Lean | UTF-8 | Lean | false | false | 875 | lean | /-
This file contains the `db` inductive data type for De Bruijn terms.
-/
namespace acie -----------------------------------------------------------------
open nat
inductive db : ℕ → Type
| var : Π {n : ℕ}, fin n → db n -- variable
| app : Π {n : ℕ}, db n → db n → db n -- application
| lam : Π {n : ℕ}, db (succ n) → db n -- lambda abstraction
namespace db -------------------------------------------------------------------
def repr : ∀ {n : ℕ}, db n → string
| n (var N) := _root_.repr N
| n (app f e) := "(" ++ repr f ++ " " ++ repr e ++ ")"
| n (lam e) := "(λ " ++ repr e ++ ")"
instance has_repr (n : ℕ) : has_repr (db n) :=
⟨@repr n⟩
end /- namespace -/ db ---------------------------------------------------------
end /- namespace -/ acie -------------------------------------------------------
|
ba85f4f01617ead2c8d0d6cbba583e407d37fe17 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/data/equiv/local_equiv.lean | 2b68ebe078decfb854f2f067556197a5cddcdd3c | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 33,889 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import data.equiv.basic
import data.set.function
/-!
# Local equivalences
This files defines equivalences between subsets of given types.
An element `e` of `local_equiv α β` is made of two maps `e.to_fun` and `e.inv_fun` respectively
from α to β and from β to α (just like equivs), which are inverse to each other on the subsets
`e.source` and `e.target` of respectively α and β.
They are designed in particular to define charts on manifolds.
The main functionality is `e.trans f`, which composes the two local equivalences by restricting
the source and target to the maximal set where the composition makes sense.
As for equivs, we register a coercion to functions and use it in our simp normal form: we write
`e x` and `e.symm y` instead of `e.to_fun x` and `e.inv_fun y`.
## Main definitions
`equiv.to_local_equiv`: associating a local equiv to an equiv, with source = target = univ
`local_equiv.symm` : the inverse of a local equiv
`local_equiv.trans` : the composition of two local equivs
`local_equiv.refl` : the identity local equiv
`local_equiv.of_set` : the identity on a set `s`
`eq_on_source` : equivalence relation describing the "right" notion of equality for local
equivs (see below in implementation notes)
## Implementation notes
There are at least three possible implementations of local equivalences:
* equivs on subtypes
* pairs of functions taking values in `option α` and `option β`, equal to none where the local
equivalence is not defined
* pairs of functions defined everywhere, keeping the source and target as additional data
Each of these implementations has pros and cons.
* When dealing with subtypes, one still need to define additional API for composition and
restriction of domains. Checking that one always belongs to the right subtype makes things very
tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for
instance).
* With option-valued functions, the composition is very neat (it is just the usual composition, and
the domain is restricted automatically). These are implemented in `pequiv.lean`. For manifolds,
where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of
overhead as one would need to extend all classes of smoothness to option-valued maps.
* The local_equiv version as explained above is easier to use for manifolds. The drawback is that
there is extra useless data (the values of `to_fun` and `inv_fun` outside of `source` and `target`).
In particular, the equality notion between local equivs is not "the right one", i.e., coinciding
source and target and equality there. Moreover, there are no local equivs in this sense between
an empty type and a nonempty type. Since empty types are not that useful, and since one almost never
needs to talk about equal local equivs, this is not an issue in practice.
Still, we introduce an equivalence relation `eq_on_source` that captures this right notion of
equality, and show that many properties are invariant under this equivalence relation.
### Local coding conventions
If a lemma deals with the intersection of a set with either source or target of a `local_equiv`,
then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`.
-/
mk_simp_attribute mfld_simps "The simpset `mfld_simps` records several simp lemmas that are
especially useful in manifolds. It is a subset of the whole set of simp lemmas, but it makes it
possible to have quicker proofs (when used with `squeeze_simp` or `simp only`) while retaining
readability.
The typical use case is the following, in a file on manifolds:
If `simp [foo, bar]` is slow, replace it with `squeeze_simp [foo, bar] with mfld_simps` and paste
its output. The list of lemmas should be reasonable (contrary to the output of
`squeeze_simp [foo, bar]` which might contain tens of lemmas), and the outcome should be quick
enough.
"
-- register in the simpset `mfld_simps` several lemmas that are often useful when dealing
-- with manifolds
attribute [mfld_simps] id.def function.comp.left_id set.mem_set_of_eq set.image_eq_empty
set.univ_inter set.preimage_univ set.prod_mk_mem_set_prod_eq and_true set.mem_univ
set.mem_image_of_mem true_and set.mem_inter_eq set.mem_preimage function.comp_app
set.inter_subset_left set.mem_prod set.range_id set.range_prod_map and_self set.mem_range_self
eq_self_iff_true forall_const forall_true_iff set.inter_univ set.preimage_id function.comp.right_id
not_false_iff and_imp set.prod_inter_prod set.univ_prod_univ true_or or_true prod.map_mk
set.preimage_inter heq_iff_eq equiv.sigma_equiv_prod_apply equiv.sigma_equiv_prod_symm_apply
subtype.coe_mk equiv.to_fun_as_coe equiv.inv_fun_as_coe
/-- Common `@[simps]` configuration options used for manifold-related declarations. -/
def mfld_cfg : simps_cfg := {attrs := [`simp, `mfld_simps], fully_applied := ff}
namespace tactic.interactive
/-- A very basic tactic to show that sets showing up in manifolds coincide or are included in
one another. -/
meta def mfld_set_tac : tactic unit := do
goal ← tactic.target,
match goal with
| `(%%e₁ = %%e₂) :=
`[ext my_y,
split;
{ assume h_my_y,
try { simp only [*, -h_my_y] with mfld_simps at h_my_y },
simp only [*] with mfld_simps }]
| `(%%e₁ ⊆ %%e₂) :=
`[assume my_y h_my_y,
try { simp only [*, -h_my_y] with mfld_simps at h_my_y },
simp only [*] with mfld_simps]
| _ := tactic.fail "goal should be an equality or an inclusion"
end
end tactic.interactive
open function set
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- Local equivalence between subsets `source` and `target` of α and β respectively. The (global)
maps `to_fun : α → β` and `inv_fun : β → α` map `source` to `target` and conversely, and are inverse
to each other there. The values of `to_fun` outside of `source` and of `inv_fun` outside of `target`
are irrelevant. -/
@[nolint has_inhabited_instance]
structure local_equiv (α : Type*) (β : Type*) :=
(to_fun : α → β)
(inv_fun : β → α)
(source : set α)
(target : set β)
(map_source' : ∀{x}, x ∈ source → to_fun x ∈ target)
(map_target' : ∀{x}, x ∈ target → inv_fun x ∈ source)
(left_inv' : ∀{x}, x ∈ source → inv_fun (to_fun x) = x)
(right_inv' : ∀{x}, x ∈ target → to_fun (inv_fun x) = x)
/-- Associating a local_equiv to an equiv-/
def equiv.to_local_equiv (e : α ≃ β) : local_equiv α β :=
{ to_fun := e,
inv_fun := e.symm,
source := univ,
target := univ,
map_source' := λx hx, mem_univ _,
map_target' := λy hy, mem_univ _,
left_inv' := λx hx, e.left_inv x,
right_inv' := λx hx, e.right_inv x }
namespace local_equiv
variables (e : local_equiv α β) (e' : local_equiv β γ)
/-- The inverse of a local equiv -/
protected def symm : local_equiv β α :=
{ to_fun := e.inv_fun,
inv_fun := e.to_fun,
source := e.target,
target := e.source,
map_source' := e.map_target',
map_target' := e.map_source',
left_inv' := e.right_inv',
right_inv' := e.left_inv' }
instance : has_coe_to_fun (local_equiv α β) (λ _, α → β) := ⟨local_equiv.to_fun⟩
/-- See Note [custom simps projection] -/
def simps.symm_apply (e : local_equiv α β) : β → α := e.symm
initialize_simps_projections local_equiv (to_fun → apply, inv_fun → symm_apply)
@[simp, mfld_simps] theorem coe_mk (f : α → β) (g s t ml mr il ir) :
(local_equiv.mk f g s t ml mr il ir : α → β) = f := rfl
@[simp, mfld_simps] theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) :
((local_equiv.mk f g s t ml mr il ir).symm : β → α) = g := rfl
@[simp, mfld_simps] lemma to_fun_as_coe : e.to_fun = e := rfl
@[simp, mfld_simps] lemma inv_fun_as_coe : e.inv_fun = e.symm := rfl
@[simp, mfld_simps] lemma map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target :=
e.map_source' h
@[simp, mfld_simps] lemma map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source :=
e.map_target' h
@[simp, mfld_simps] lemma left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x :=
e.left_inv' h
@[simp, mfld_simps] lemma right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x :=
e.right_inv' h
protected lemma maps_to : maps_to e e.source e.target := λ x, e.map_source
lemma symm_maps_to : maps_to e.symm e.target e.source := e.symm.maps_to
protected lemma left_inv_on : left_inv_on e.symm e e.source := λ x, e.left_inv
protected lemma right_inv_on : right_inv_on e.symm e e.target := λ x, e.right_inv
protected lemma inv_on : inv_on e.symm e e.source e.target := ⟨e.left_inv_on, e.right_inv_on⟩
protected lemma inj_on : inj_on e e.source := e.left_inv_on.inj_on
protected lemma bij_on : bij_on e e.source e.target := e.inv_on.bij_on e.maps_to e.symm_maps_to
protected lemma surj_on : surj_on e e.source e.target := e.bij_on.surj_on
/-- Create a copy of a `local_equiv` providing better definitional equalities. -/
@[simps] def copy (e : local_equiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g)
(s : set α) (hs : e.source = s) (t : set β) (ht : e.target = t) :
local_equiv α β :=
{ to_fun := f,
inv_fun := g,
source := s,
target := t,
map_source' := λ x, ht ▸ hs ▸ hf ▸ e.map_source,
map_target' := λ y, hs ▸ ht ▸ hg ▸ e.map_target,
left_inv' := λ x, hs ▸ hf ▸ hg ▸ e.left_inv,
right_inv' := λ x, ht ▸ hf ▸ hg ▸ e.right_inv }
lemma copy_eq_self (e : local_equiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g)
(s : set α) (hs : e.source = s) (t : set β) (ht : e.target = t) :
e.copy f hf g hg s hs t ht = e :=
by { substs f g s t, cases e, refl }
/-- Associating to a local_equiv an equiv between the source and the target -/
protected def to_equiv : equiv (e.source) (e.target) :=
{ to_fun := λ x, ⟨e x, e.map_source x.mem⟩,
inv_fun := λ y, ⟨e.symm y, e.map_target y.mem⟩,
left_inv := λ⟨x, hx⟩, subtype.eq $ e.left_inv hx,
right_inv := λ⟨y, hy⟩, subtype.eq $ e.right_inv hy }
@[simp, mfld_simps] lemma symm_source : e.symm.source = e.target := rfl
@[simp, mfld_simps] lemma symm_target : e.symm.target = e.source := rfl
@[simp, mfld_simps] lemma symm_symm : e.symm.symm = e := by { cases e, refl }
lemma image_source_eq_target : e '' e.source = e.target := e.bij_on.image_eq
/-- We say that `t : set β` is an image of `s : set α` under a local equivalence if
any of the following equivalent conditions hold:
* `e '' (e.source ∩ s) = e.target ∩ t`;
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
-/
def is_image (s : set α) (t : set β) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s)
namespace is_image
variables {e} {s : set α} {t : set β} {x : α} {y : β}
lemma apply_mem_iff (h : e.is_image s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx
lemma symm_apply_mem_iff (h : e.is_image s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) :=
by { rw [← e.image_source_eq_target, ball_image_iff], intros x hx, rw [e.left_inv hx, h hx] }
protected lemma symm (h : e.is_image s t) : e.symm.is_image t s := h.symm_apply_mem_iff
@[simp] lemma symm_iff : e.symm.is_image t s ↔ e.is_image s t := ⟨λ h, h.symm, λ h, h.symm⟩
protected lemma maps_to (h : e.is_image s t) : maps_to e (e.source ∩ s) (e.target ∩ t) :=
λ x hx, ⟨e.maps_to hx.1, (h hx.1).2 hx.2⟩
lemma symm_maps_to (h : e.is_image s t) : maps_to e.symm (e.target ∩ t) (e.source ∩ s) :=
h.symm.maps_to
/-- Restrict a `local_equiv` to a pair of corresponding sets. -/
@[simps] def restr (h : e.is_image s t) : local_equiv α β :=
{ to_fun := e,
inv_fun := e.symm,
source := e.source ∩ s,
target := e.target ∩ t,
map_source' := h.maps_to,
map_target' := h.symm_maps_to,
left_inv' := e.left_inv_on.mono (inter_subset_left _ _),
right_inv' := e.right_inv_on.mono (inter_subset_left _ _) }
lemma image_eq (h : e.is_image s t) : e '' (e.source ∩ s) = e.target ∩ t :=
h.restr.image_source_eq_target
lemma symm_image_eq (h : e.is_image s t) : e.symm '' (e.target ∩ t) = e.source ∩ s :=
h.symm.image_eq
lemma iff_preimage_eq : e.is_image s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s :=
by simp only [is_image, set.ext_iff, mem_inter_eq, and.congr_right_iff, mem_preimage]
alias iff_preimage_eq ↔ local_equiv.is_image.preimage_eq local_equiv.is_image.of_preimage_eq
lemma iff_symm_preimage_eq : e.is_image s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t :=
symm_iff.symm.trans iff_preimage_eq
alias iff_symm_preimage_eq ↔ local_equiv.is_image.symm_preimage_eq
local_equiv.is_image.of_symm_preimage_eq
lemma of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.is_image s t :=
of_symm_preimage_eq $ eq.trans (of_symm_preimage_eq rfl).image_eq.symm h
lemma of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.is_image s t :=
of_preimage_eq $ eq.trans (of_preimage_eq rfl).symm_image_eq.symm h
protected lemma compl (h : e.is_image s t) : e.is_image sᶜ tᶜ :=
λ x hx, not_congr (h hx)
protected lemma inter {s' t'} (h : e.is_image s t) (h' : e.is_image s' t') :
e.is_image (s ∩ s') (t ∩ t') :=
λ x hx, and_congr (h hx) (h' hx)
protected lemma union {s' t'} (h : e.is_image s t) (h' : e.is_image s' t') :
e.is_image (s ∪ s') (t ∪ t') :=
λ x hx, or_congr (h hx) (h' hx)
protected lemma diff {s' t'} (h : e.is_image s t) (h' : e.is_image s' t') :
e.is_image (s \ s') (t \ t') :=
h.inter h'.compl
lemma left_inv_on_piecewise {e' : local_equiv α β} [∀ i, decidable (i ∈ s)] [∀ i, decidable (i ∈ t)]
(h : e.is_image s t) (h' : e'.is_image s t) :
left_inv_on (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) :=
begin
rintro x (⟨he, hs⟩|⟨he, hs : x ∉ s⟩),
{ rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he], },
{ rw [piecewise_eq_of_not_mem _ _ _ hs, piecewise_eq_of_not_mem _ _ _ ((h'.compl he).2 hs),
e'.left_inv he] }
end
lemma inter_eq_of_inter_eq_of_eq_on {e' : local_equiv α β} (h : e.is_image s t)
(h' : e'.is_image s t) (hs : e.source ∩ s = e'.source ∩ s) (Heq : eq_on e e' (e.source ∩ s)) :
e.target ∩ t = e'.target ∩ t :=
by rw [← h.image_eq, ← h'.image_eq, ← hs, Heq.image_eq]
lemma symm_eq_on_of_inter_eq_of_eq_on {e' : local_equiv α β} (h : e.is_image s t)
(hs : e.source ∩ s = e'.source ∩ s) (Heq : eq_on e e' (e.source ∩ s)) :
eq_on e.symm e'.symm (e.target ∩ t) :=
begin
rw [← h.image_eq],
rintros y ⟨x, hx, rfl⟩,
have hx' := hx, rw hs at hx',
rw [e.left_inv hx.1, Heq hx, e'.left_inv hx'.1]
end
end is_image
lemma is_image_source_target : e.is_image e.source e.target := λ x hx, by simp [hx]
lemma is_image_source_target_of_disjoint (e' : local_equiv α β) (hs : disjoint e.source e'.source)
(ht : disjoint e.target e'.target) :
e.is_image e'.source e'.target :=
assume x hx,
have x ∉ e'.source, from λ hx', hs ⟨hx, hx'⟩,
have e x ∉ e'.target, from λ hx', ht ⟨e.maps_to hx, hx'⟩,
by simp only *
lemma image_source_inter_eq' (s : set α) :
e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s :=
by rw [inter_comm, e.left_inv_on.image_inter', image_source_eq_target, inter_comm]
lemma image_source_inter_eq (s : set α) :
e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) :=
by rw [inter_comm, e.left_inv_on.image_inter, image_source_eq_target, inter_comm]
lemma image_eq_target_inter_inv_preimage {s : set α} (h : s ⊆ e.source) :
e '' s = e.target ∩ e.symm ⁻¹' s :=
by rw [← e.image_source_inter_eq', inter_eq_self_of_subset_right h]
lemma symm_image_eq_source_inter_preimage {s : set β} (h : s ⊆ e.target) :
e.symm '' s = e.source ∩ e ⁻¹' s :=
e.symm.image_eq_target_inter_inv_preimage h
lemma symm_image_target_inter_eq (s : set β) :
e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) :=
e.symm.image_source_inter_eq _
lemma symm_image_target_inter_eq' (s : set β) :
e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
e.symm.image_source_inter_eq' _
lemma source_inter_preimage_inv_preimage (s : set α) :
e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s :=
set.ext $ λ x, and.congr_right_iff.2 $ λ hx, by simp only [mem_preimage, e.left_inv hx]
lemma source_inter_preimage_target_inter (s : set β) :
e.source ∩ (e ⁻¹' (e.target ∩ s)) = e.source ∩ (e ⁻¹' s) :=
ext $ λ x, ⟨λ hx, ⟨hx.1, hx.2.2⟩, λ hx, ⟨hx.1, e.map_source hx.1, hx.2⟩⟩
lemma target_inter_inv_preimage_preimage (s : set β) :
e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s :=
e.symm.source_inter_preimage_inv_preimage _
lemma source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target :=
e.maps_to
lemma symm_image_target_eq_source : e.symm '' e.target = e.source :=
e.symm.image_source_eq_target
lemma target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source :=
e.symm_maps_to
/-- Two local equivs that have the same `source`, same `to_fun` and same `inv_fun`, coincide. -/
@[ext]
protected lemma ext {e e' : local_equiv α β} (h : ∀x, e x = e' x)
(hsymm : ∀x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' :=
begin
have A : (e : α → β) = e', by { ext x, exact h x },
have B : (e.symm : β → α) = e'.symm, by { ext x, exact hsymm x },
have I : e '' e.source = e.target := e.image_source_eq_target,
have I' : e' '' e'.source = e'.target := e'.image_source_eq_target,
rw [A, hs, I'] at I,
cases e; cases e',
simp * at *
end
/-- Restricting a local equivalence to e.source ∩ s -/
protected def restr (s : set α) : local_equiv α β :=
(@is_image.of_symm_preimage_eq α β e s (e.symm ⁻¹' s) rfl).restr
@[simp, mfld_simps] lemma restr_coe (s : set α) : (e.restr s : α → β) = e := rfl
@[simp, mfld_simps] lemma restr_coe_symm (s : set α) : ((e.restr s).symm : β → α) = e.symm := rfl
@[simp, mfld_simps] lemma restr_source (s : set α) : (e.restr s).source = e.source ∩ s := rfl
@[simp, mfld_simps] lemma restr_target (s : set α) :
(e.restr s).target = e.target ∩ e.symm ⁻¹' s := rfl
lemma restr_eq_of_source_subset {e : local_equiv α β} {s : set α} (h : e.source ⊆ s) :
e.restr s = e :=
local_equiv.ext (λ_, rfl) (λ_, rfl) (by simp [inter_eq_self_of_subset_left h])
@[simp, mfld_simps] lemma restr_univ {e : local_equiv α β} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
/-- The identity local equiv -/
protected def refl (α : Type*) : local_equiv α α := (equiv.refl α).to_local_equiv
@[simp, mfld_simps] lemma refl_source : (local_equiv.refl α).source = univ := rfl
@[simp, mfld_simps] lemma refl_target : (local_equiv.refl α).target = univ := rfl
@[simp, mfld_simps] lemma refl_coe : (local_equiv.refl α : α → α) = id := rfl
@[simp, mfld_simps] lemma refl_symm : (local_equiv.refl α).symm = local_equiv.refl α := rfl
@[simp, mfld_simps] lemma refl_restr_source (s : set α) :
((local_equiv.refl α).restr s).source = s :=
by simp
@[simp, mfld_simps] lemma refl_restr_target (s : set α) :
((local_equiv.refl α).restr s).target = s :=
by { change univ ∩ id⁻¹' s = s, simp }
/-- The identity local equiv on a set `s` -/
def of_set (s : set α) : local_equiv α α :=
{ to_fun := id,
inv_fun := id,
source := s,
target := s,
map_source' := λx hx, hx,
map_target' := λx hx, hx,
left_inv' := λx hx, rfl,
right_inv' := λx hx, rfl }
@[simp, mfld_simps] lemma of_set_source (s : set α) : (local_equiv.of_set s).source = s := rfl
@[simp, mfld_simps] lemma of_set_target (s : set α) : (local_equiv.of_set s).target = s := rfl
@[simp, mfld_simps] lemma of_set_coe (s : set α) : (local_equiv.of_set s : α → α) = id := rfl
@[simp, mfld_simps] lemma of_set_symm (s : set α) :
(local_equiv.of_set s).symm = local_equiv.of_set s := rfl
/-- Composing two local equivs if the target of the first coincides with the source of the
second. -/
protected def trans' (e' : local_equiv β γ) (h : e.target = e'.source) :
local_equiv α γ :=
{ to_fun := e' ∘ e,
inv_fun := e.symm ∘ e'.symm,
source := e.source,
target := e'.target,
map_source' := λx hx, by simp [h.symm, hx],
map_target' := λy hy, by simp [h, hy],
left_inv' := λx hx, by simp [hx, h.symm],
right_inv' := λy hy, by simp [hy, h] }
/-- Composing two local equivs, by restricting to the maximal domain where their composition
is well defined. -/
protected def trans : local_equiv α γ :=
local_equiv.trans' (e.symm.restr (e'.source)).symm (e'.restr (e.target)) (inter_comm _ _)
@[simp, mfld_simps] lemma coe_trans : (e.trans e' : α → γ) = e' ∘ e := rfl
@[simp, mfld_simps] lemma coe_trans_symm : ((e.trans e').symm : γ → α) = e.symm ∘ e'.symm := rfl
lemma trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm :=
by cases e; cases e'; refl
@[simp, mfld_simps] lemma trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source := rfl
lemma trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) :=
by mfld_set_tac
lemma trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) :=
by rw [e.trans_source', e.symm_image_target_inter_eq]
lemma image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source :=
(e.symm.restr e'.source).symm.image_source_eq_target
@[simp, mfld_simps] lemma trans_target :
(e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target := rfl
lemma trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) :=
trans_source' e'.symm e.symm
lemma trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) :=
trans_source'' e'.symm e.symm
lemma inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target :=
image_trans_source e'.symm e.symm
lemma trans_assoc (e'' : local_equiv γ δ) : (e.trans e').trans e'' = e.trans (e'.trans e'') :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source, @preimage_comp α β γ, inter_assoc])
@[simp, mfld_simps] lemma trans_refl : e.trans (local_equiv.refl β) = e :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source])
@[simp, mfld_simps] lemma refl_trans : (local_equiv.refl α).trans e = e :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source, preimage_id])
lemma trans_refl_restr (s : set β) :
e.trans ((local_equiv.refl β).restr s) = e.restr (e ⁻¹' s) :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source])
lemma trans_refl_restr' (s : set β) :
e.trans ((local_equiv.refl β).restr s) = e.restr (e.source ∩ e ⁻¹' s) :=
local_equiv.ext (λx, rfl) (λx, rfl) $ by { simp [trans_source], rw [← inter_assoc, inter_self] }
lemma restr_trans (s : set α) :
(e.restr s).trans e' = (e.trans e').restr s :=
local_equiv.ext (λx, rfl) (λx, rfl) $ by { simp [trans_source, inter_comm], rwa inter_assoc }
/-- `eq_on_source e e'` means that `e` and `e'` have the same source, and coincide there. Then `e`
and `e'` should really be considered the same local equiv. -/
def eq_on_source (e e' : local_equiv α β) : Prop :=
e.source = e'.source ∧ (e.source.eq_on e e')
/-- `eq_on_source` is an equivalence relation -/
instance eq_on_source_setoid : setoid (local_equiv α β) :=
{ r := eq_on_source,
iseqv := ⟨
λe, by simp [eq_on_source],
λe e' h, by { simp [eq_on_source, h.1.symm], exact λx hx, (h.2 hx).symm },
λe e' e'' h h', ⟨by rwa [← h'.1, ← h.1], λx hx, by { rw [← h'.2, h.2 hx], rwa ← h.1 }⟩⟩ }
lemma eq_on_source_refl : e ≈ e := setoid.refl _
/-- Two equivalent local equivs have the same source -/
lemma eq_on_source.source_eq {e e' : local_equiv α β} (h : e ≈ e') : e.source = e'.source :=
h.1
/-- Two equivalent local equivs coincide on the source -/
lemma eq_on_source.eq_on {e e' : local_equiv α β} (h : e ≈ e') : e.source.eq_on e e' :=
h.2
/-- Two equivalent local equivs have the same target -/
lemma eq_on_source.target_eq {e e' : local_equiv α β} (h : e ≈ e') : e.target = e'.target :=
by simp only [← image_source_eq_target, ← h.source_eq, h.2.image_eq]
/-- If two local equivs are equivalent, so are their inverses. -/
lemma eq_on_source.symm' {e e' : local_equiv α β} (h : e ≈ e') : e.symm ≈ e'.symm :=
begin
refine ⟨h.target_eq, eq_on_of_left_inv_on_of_right_inv_on e.left_inv_on _ _⟩;
simp only [symm_source, h.target_eq, h.source_eq, e'.symm_maps_to],
exact e'.right_inv_on.congr_right e'.symm_maps_to (h.source_eq ▸ h.eq_on.symm),
end
/-- Two equivalent local equivs have coinciding inverses on the target -/
lemma eq_on_source.symm_eq_on {e e' : local_equiv α β} (h : e ≈ e') :
eq_on e.symm e'.symm e.target :=
h.symm'.eq_on
/-- Composition of local equivs respects equivalence -/
lemma eq_on_source.trans' {e e' : local_equiv α β} {f f' : local_equiv β γ}
(he : e ≈ e') (hf : f ≈ f') : e.trans f ≈ e'.trans f' :=
begin
split,
{ rw [trans_source'', trans_source'', ← he.target_eq, ← hf.1],
exact (he.symm'.eq_on.mono $ inter_subset_left _ _).image_eq },
{ assume x hx,
rw trans_source at hx,
simp [(he.2 hx.1).symm, hf.2 hx.2] }
end
/-- Restriction of local equivs respects equivalence -/
lemma eq_on_source.restr {e e' : local_equiv α β} (he : e ≈ e') (s : set α) :
e.restr s ≈ e'.restr s :=
begin
split,
{ simp [he.1] },
{ assume x hx,
simp only [mem_inter_eq, restr_source] at hx,
exact he.2 hx.1 }
end
/-- Preimages are respected by equivalence -/
lemma eq_on_source.source_inter_preimage_eq {e e' : local_equiv α β} (he : e ≈ e') (s : set β) :
e.source ∩ e ⁻¹' s = e'.source ∩ e' ⁻¹' s :=
by rw [he.eq_on.inter_preimage_eq, he.source_eq]
/-- Composition of a local equiv and its inverse is equivalent to the restriction of the identity
to the source -/
lemma trans_self_symm :
e.trans e.symm ≈ local_equiv.of_set e.source :=
begin
have A : (e.trans e.symm).source = e.source, by mfld_set_tac,
refine ⟨by simp [A], λx hx, _⟩,
rw A at hx,
simp only [hx] with mfld_simps
end
/-- Composition of the inverse of a local equiv and this local equiv is equivalent to the
restriction of the identity to the target -/
lemma trans_symm_self :
e.symm.trans e ≈ local_equiv.of_set e.target :=
trans_self_symm (e.symm)
/-- Two equivalent local equivs are equal when the source and target are univ -/
lemma eq_of_eq_on_source_univ (e e' : local_equiv α β) (h : e ≈ e')
(s : e.source = univ) (t : e.target = univ) : e = e' :=
begin
apply local_equiv.ext (λx, _) (λx, _) h.1,
{ apply h.2,
rw s,
exact mem_univ _ },
{ apply h.symm'.2,
rw [symm_source, t],
exact mem_univ _ }
end
section prod
/-- The product of two local equivs, as a local equiv on the product. -/
def prod (e : local_equiv α β) (e' : local_equiv γ δ) : local_equiv (α × γ) (β × δ) :=
{ source := e.source ×ˢ e'.source,
target := e.target ×ˢ e'.target,
to_fun := λp, (e p.1, e' p.2),
inv_fun := λp, (e.symm p.1, e'.symm p.2),
map_source' := λp hp, by { simp at hp, simp [hp] },
map_target' := λp hp, by { simp at hp, simp [map_target, hp] },
left_inv' := λp hp, by { simp at hp, simp [hp] },
right_inv' := λp hp, by { simp at hp, simp [hp] } }
@[simp, mfld_simps] lemma prod_source (e : local_equiv α β) (e' : local_equiv γ δ) :
(e.prod e').source = e.source ×ˢ e'.source := rfl
@[simp, mfld_simps] lemma prod_target (e : local_equiv α β) (e' : local_equiv γ δ) :
(e.prod e').target = e.target ×ˢ e'.target := rfl
@[simp, mfld_simps] lemma prod_coe (e : local_equiv α β) (e' : local_equiv γ δ) :
((e.prod e') : α × γ → β × δ) = (λp, (e p.1, e' p.2)) := rfl
lemma prod_coe_symm (e : local_equiv α β) (e' : local_equiv γ δ) :
((e.prod e').symm : β × δ → α × γ) = (λp, (e.symm p.1, e'.symm p.2)) := rfl
@[simp, mfld_simps] lemma prod_symm (e : local_equiv α β) (e' : local_equiv γ δ) :
(e.prod e').symm = (e.symm.prod e'.symm) :=
by ext x; simp [prod_coe_symm]
@[simp, mfld_simps] lemma prod_trans {η : Type*} {ε : Type*}
(e : local_equiv α β) (f : local_equiv β γ) (e' : local_equiv δ η) (f' : local_equiv η ε) :
(e.prod e').trans (f.prod f') = (e.trans f).prod (e'.trans f') :=
by ext x; simp [ext_iff]; tauto
end prod
/-- Combine two `local_equiv`s using `set.piecewise`. The source of the new `local_equiv` is
`s.ite e.source e'.source = e.source ∩ s ∪ e'.source \ s`, and similarly for target. The function
sends `e.source ∩ s` to `e.target ∩ t` using `e` and `e'.source \ s` to `e'.target \ t` using `e'`,
and similarly for the inverse function. The definition assumes `e.is_image s t` and
`e'.is_image s t`. -/
@[simps] def piecewise (e e' : local_equiv α β) (s : set α) (t : set β)
[∀ x, decidable (x ∈ s)] [∀ y, decidable (y ∈ t)] (H : e.is_image s t) (H' : e'.is_image s t) :
local_equiv α β :=
{ to_fun := s.piecewise e e',
inv_fun := t.piecewise e.symm e'.symm,
source := s.ite e.source e'.source,
target := t.ite e.target e'.target,
map_source' := H.maps_to.piecewise_ite H'.compl.maps_to,
map_target' := H.symm.maps_to.piecewise_ite H'.symm.compl.maps_to,
left_inv' := H.left_inv_on_piecewise H',
right_inv' := H.symm.left_inv_on_piecewise H'.symm }
lemma symm_piecewise (e e' : local_equiv α β) {s : set α} {t : set β}
[∀ x, decidable (x ∈ s)] [∀ y, decidable (y ∈ t)]
(H : e.is_image s t) (H' : e'.is_image s t) :
(e.piecewise e' s t H H').symm = e.symm.piecewise e'.symm t s H.symm H'.symm :=
rfl
/-- Combine two `local_equiv`s with disjoint sources and disjoint targets. We reuse
`local_equiv.piecewise`, then override `source` and `target` to ensure better definitional
equalities. -/
@[simps] def disjoint_union (e e' : local_equiv α β) (hs : disjoint e.source e'.source)
(ht : disjoint e.target e'.target) [∀ x, decidable (x ∈ e.source)]
[∀ y, decidable (y ∈ e.target)] :
local_equiv α β :=
(e.piecewise e' e.source e.target e.is_image_source_target $
e'.is_image_source_target_of_disjoint _ hs.symm ht.symm).copy
_ rfl _ rfl (e.source ∪ e'.source) (ite_left _ _) (e.target ∪ e'.target) (ite_left _ _)
lemma disjoint_union_eq_piecewise (e e' : local_equiv α β) (hs : disjoint e.source e'.source)
(ht : disjoint e.target e'.target) [∀ x, decidable (x ∈ e.source)]
[∀ y, decidable (y ∈ e.target)] :
e.disjoint_union e' hs ht = e.piecewise e' e.source e.target e.is_image_source_target
(e'.is_image_source_target_of_disjoint _ hs.symm ht.symm) :=
copy_eq_self _ _ _ _ _ _ _ _ _
section pi
variables {ι : Type*} {αi βi : ι → Type*} (ei : Π i, local_equiv (αi i) (βi i))
/-- The product of a family of local equivs, as a local equiv on the pi type. -/
@[simps source target] protected def pi : local_equiv (Π i, αi i) (Π i, βi i) :=
{ to_fun := λ f i, ei i (f i),
inv_fun := λ f i, (ei i).symm (f i),
source := pi univ (λ i, (ei i).source),
target := pi univ (λ i, (ei i).target),
map_source' := λ f hf i hi, (ei i).map_source (hf i hi),
map_target' := λ f hf i hi, (ei i).map_target (hf i hi),
left_inv' := λ f hf, funext $ λ i, (ei i).left_inv (hf i trivial),
right_inv' := λ f hf, funext $ λ i, (ei i).right_inv (hf i trivial) }
attribute [mfld_simps] pi_source pi_target
@[simp, mfld_simps] lemma pi_coe : ⇑(local_equiv.pi ei) = λ (f : Π i, αi i) i, ei i (f i) := rfl
@[simp, mfld_simps] lemma pi_symm :
(local_equiv.pi ei).symm = local_equiv.pi (λ i, (ei i).symm) := rfl
end pi
end local_equiv
namespace set
-- All arguments are explicit to avoid missing information in the pretty printer output
/-- A bijection between two sets `s : set α` and `t : set β` provides a local equivalence
between `α` and `β`. -/
@[simps] noncomputable def bij_on.to_local_equiv [nonempty α] (f : α → β) (s : set α) (t : set β)
(hf : bij_on f s t) :
local_equiv α β :=
{ to_fun := f,
inv_fun := inv_fun_on f s,
source := s,
target := t,
map_source' := hf.maps_to,
map_target' := hf.surj_on.maps_to_inv_fun_on,
left_inv' := hf.inv_on_inv_fun_on.1,
right_inv' := hf.inv_on_inv_fun_on.2 }
/-- A map injective on a subset of its domain provides a local equivalence. -/
@[simp, mfld_simps] noncomputable def inj_on.to_local_equiv [nonempty α] (f : α → β) (s : set α)
(hf : inj_on f s) :
local_equiv α β :=
hf.bij_on_image.to_local_equiv f s (f '' s)
end set
namespace equiv
/- equivs give rise to local_equiv. We set up simp lemmas to reduce most properties of the local
equiv to that of the equiv. -/
variables (e : equiv α β) (e' : equiv β γ)
@[simp, mfld_simps] lemma to_local_equiv_coe : (e.to_local_equiv : α → β) = e := rfl
@[simp, mfld_simps] lemma to_local_equiv_symm_coe : (e.to_local_equiv.symm : β → α) = e.symm := rfl
@[simp, mfld_simps] lemma to_local_equiv_source : e.to_local_equiv.source = univ := rfl
@[simp, mfld_simps] lemma to_local_equiv_target : e.to_local_equiv.target = univ := rfl
@[simp, mfld_simps] lemma refl_to_local_equiv :
(equiv.refl α).to_local_equiv = local_equiv.refl α := rfl
@[simp, mfld_simps] lemma symm_to_local_equiv : e.symm.to_local_equiv = e.to_local_equiv.symm := rfl
@[simp, mfld_simps] lemma trans_to_local_equiv :
(e.trans e').to_local_equiv = e.to_local_equiv.trans e'.to_local_equiv :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [local_equiv.trans_source, equiv.to_local_equiv])
end equiv
|
770ab434ad14ca43a79f682c2df962a3899ec2d0 | bb31430994044506fa42fd667e2d556327e18dfe | /src/analysis/inner_product_space/l2_space.lean | 9937cb02aa50a1ef4e1737a33f9625e0610e80d8 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 25,203 | lean | /-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import analysis.inner_product_space.projection
import analysis.normed_space.lp_space
import analysis.inner_product_space.pi_L2
/-!
# Hilbert sum of a family of inner product spaces
Given a family `(G : ι → Type*) [Π i, inner_product_space 𝕜 (G i)]` of inner product spaces, this
file equips `lp G 2` with an inner product space structure, where `lp G 2` consists of those
dependent functions `f : Π i, G i` for which `∑' i, ‖f i‖ ^ 2`, the sum of the norms-squared, is
summable. This construction is sometimes called the *Hilbert sum* of the family `G`. By choosing
`G` to be `ι → 𝕜`, the Hilbert space `ℓ²(ι, 𝕜)` may be seen as a special case of this construction.
We also define a *predicate* `is_hilbert_sum 𝕜 E V`, where `V : Π i, G i →ₗᵢ[𝕜] E`, expressing that
`V` is an `orthogonal_family` and that the associated map `lp G 2 →ₗᵢ[𝕜] E` is surjective.
## Main definitions
* `orthogonal_family.linear_isometry`: Given a Hilbert space `E`, a family `G` of inner product
spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with
mutually-orthogonal images, there is an induced isometric embedding of the Hilbert sum of `G`
into `E`.
* `is_hilbert_sum`: Given a Hilbert space `E`, a family `G` of inner product
spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E`,
`is_hilbert_sum 𝕜 E V` means that `V` is an `orthogonal_family` and that the above
linear isometry is surjective.
* `is_hilbert_sum.linear_isometry_equiv`: If a Hilbert space `E` is a Hilbert sum of the
inner product spaces `G i` with respect to the family `V : Π i, G i →ₗᵢ[𝕜] E`, then the
corresponding `orthogonal_family.linear_isometry` can be upgraded to a `linear_isometry_equiv`.
* `hilbert_basis`: We define a *Hilbert basis* of a Hilbert space `E` to be a structure whose single
field `hilbert_basis.repr` is an isometric isomorphism of `E` with `ℓ²(ι, 𝕜)` (i.e., the Hilbert
sum of `ι` copies of `𝕜`). This parallels the definition of `basis`, in `linear_algebra.basis`,
as an isomorphism of an `R`-module with `ι →₀ R`.
* `hilbert_basis.has_coe_to_fun`: More conventionally a Hilbert basis is thought of as a family
`ι → E` of vectors in `E` satisfying certain properties (orthonormality, completeness). We obtain
this interpretation of a Hilbert basis `b` by defining `⇑b`, of type `ι → E`, to be the image
under `b.repr` of `lp.single 2 i (1:𝕜)`. This parallels the definition `basis.has_coe_to_fun` in
`linear_algebra.basis`.
* `hilbert_basis.mk`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors
in `E` whose span is dense. This parallels the definition `basis.mk` in `linear_algebra.basis`.
* `hilbert_basis.mk_of_orthogonal_eq_bot`: Make a Hilbert basis of `E` from an orthonormal family
`v : ι → E` of vectors in `E` whose span has trivial orthogonal complement.
## Main results
* `lp.inner_product_space`: Construction of the inner product space instance on the Hilbert sum
`lp G 2`. Note that from the file `analysis.normed_space.lp_space`, the space `lp G 2` already
held a normed space instance (`lp.normed_space`), and if each `G i` is a Hilbert space (i.e.,
complete), then `lp G 2` was already known to be complete (`lp.complete_space`). So the work
here is to define the inner product and show it is compatible.
* `orthogonal_family.range_linear_isometry`: Given a family `G` of inner product spaces and a family
`V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal
images, the image of the embedding `orthogonal_family.linear_isometry` of the Hilbert sum of `G`
into `E` is the closure of the span of the images of the `G i`.
* `hilbert_basis.repr_apply_apply`: Given a Hilbert basis `b` of `E`, the entry `b.repr x i` of
`x`'s representation in `ℓ²(ι, 𝕜)` is the inner product `⟪b i, x⟫`.
* `hilbert_basis.has_sum_repr`: Given a Hilbert basis `b` of `E`, a vector `x` in `E` can be
expressed as the "infinite linear combination" `∑' i, b.repr x i • b i` of the basis vectors
`b i`, with coefficients given by the entries `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)`.
* `exists_hilbert_basis`: A Hilbert space admits a Hilbert basis.
## Keywords
Hilbert space, Hilbert sum, l2, Hilbert basis, unitary equivalence, isometric isomorphism
-/
open is_R_or_C submodule filter
open_locale big_operators nnreal ennreal classical complex_conjugate topological_space
noncomputable theory
variables {ι : Type*}
variables {𝕜 : Type*} [is_R_or_C 𝕜] {E : Type*} [inner_product_space 𝕜 E] [cplt : complete_space E]
variables {G : ι → Type*} [Π i, inner_product_space 𝕜 (G i)]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
notation `ℓ²(`ι`, `𝕜`)` := lp (λ i : ι, 𝕜) 2
/-! ### Inner product space structure on `lp G 2` -/
namespace lp
lemma summable_inner (f g : lp G 2) : summable (λ i, ⟪f i, g i⟫) :=
begin
-- Apply the Direct Comparison Test, comparing with ∑' i, ‖f i‖ * ‖g i‖ (summable by Hölder)
refine summable_of_norm_bounded (λ i, ‖f i‖ * ‖g i‖) (lp.summable_mul _ f g) _,
{ rw real.is_conjugate_exponent_iff; norm_num },
intros i,
-- Then apply Cauchy-Schwarz pointwise
exact norm_inner_le_norm _ _,
end
instance : inner_product_space 𝕜 (lp G 2) :=
{ inner := λ f g, ∑' i, ⟪f i, g i⟫,
norm_sq_eq_inner := λ f, begin
calc ‖f‖ ^ 2 = ‖f‖ ^ (2:ℝ≥0∞).to_real : by norm_cast
... = ∑' i, ‖f i‖ ^ (2:ℝ≥0∞).to_real : lp.norm_rpow_eq_tsum _ f
... = ∑' i, ‖f i‖ ^ 2 : by norm_cast
... = ∑' i, re ⟪f i, f i⟫ : by simp only [norm_sq_eq_inner]
... = re (∑' i, ⟪f i, f i⟫) : (is_R_or_C.re_clm.map_tsum _).symm
... = _ : by congr,
{ norm_num },
{ exact summable_inner f f },
end,
conj_sym := λ f g, begin
calc conj _ = conj ∑' i, ⟪g i, f i⟫ : by congr
... = ∑' i, conj ⟪g i, f i⟫ : is_R_or_C.conj_cle.map_tsum
... = ∑' i, ⟪f i, g i⟫ : by simp only [inner_conj_sym]
... = _ : by congr,
end,
add_left := λ f₁ f₂ g, begin
calc _ = ∑' i, ⟪(f₁ + f₂) i, g i⟫ : _
... = ∑' i, (⟪f₁ i, g i⟫ + ⟪f₂ i, g i⟫) :
by simp only [inner_add_left, pi.add_apply, coe_fn_add]
... = (∑' i, ⟪f₁ i, g i⟫) + ∑' i, ⟪f₂ i, g i⟫ : tsum_add _ _
... = _ : by congr,
{ congr, },
{ exact summable_inner f₁ g },
{ exact summable_inner f₂ g }
end,
smul_left := λ f g c, begin
calc _ = ∑' i, ⟪c • f i, g i⟫ : _
... = ∑' i, conj c * ⟪f i, g i⟫ : by simp only [inner_smul_left]
... = conj c * ∑' i, ⟪f i, g i⟫ : tsum_mul_left
... = _ : _,
{ simp only [coe_fn_smul, pi.smul_apply] },
{ congr },
end,
.. lp.normed_space }
lemma inner_eq_tsum (f g : lp G 2) : ⟪f, g⟫ = ∑' i, ⟪f i, g i⟫ := rfl
lemma has_sum_inner (f g : lp G 2) : has_sum (λ i, ⟪f i, g i⟫) ⟪f, g⟫ :=
(summable_inner f g).has_sum
lemma inner_single_left (i : ι) (a : G i) (f : lp G 2) : ⟪lp.single 2 i a, f⟫ = ⟪a, f i⟫ :=
begin
refine (has_sum_inner (lp.single 2 i a) f).unique _,
convert has_sum_ite_eq i ⟪a, f i⟫,
ext j,
rw lp.single_apply,
split_ifs,
{ subst h },
{ simp }
end
lemma inner_single_right (i : ι) (a : G i) (f : lp G 2) : ⟪f, lp.single 2 i a⟫ = ⟪f i, a⟫ :=
by simpa [inner_conj_sym] using congr_arg conj (inner_single_left i a f)
end lp
/-! ### Identification of a general Hilbert space `E` with a Hilbert sum -/
namespace orthogonal_family
variables {V : Π i, G i →ₗᵢ[𝕜] E} (hV : orthogonal_family 𝕜 V)
include cplt hV
protected lemma summable_of_lp (f : lp G 2) : summable (λ i, V i (f i)) :=
begin
rw hV.summable_iff_norm_sq_summable,
convert (lp.mem_ℓp f).summable _,
{ norm_cast },
{ norm_num }
end
/-- A mutually orthogonal family of subspaces of `E` induce a linear isometry from `lp 2` of the
subspaces into `E`. -/
protected def linear_isometry : lp G 2 →ₗᵢ[𝕜] E :=
{ to_fun := λ f, ∑' i, V i (f i),
map_add' := λ f g, by simp only [tsum_add (hV.summable_of_lp f) (hV.summable_of_lp g),
lp.coe_fn_add, pi.add_apply, linear_isometry.map_add],
map_smul' := λ c f, by simpa only [linear_isometry.map_smul, pi.smul_apply, lp.coe_fn_smul]
using tsum_const_smul (hV.summable_of_lp f),
norm_map' := λ f, begin
classical, -- needed for lattice instance on `finset ι`, for `filter.at_top_ne_bot`
have H : 0 < (2:ℝ≥0∞).to_real := by norm_num,
suffices : ‖∑' (i : ι), V i (f i)‖ ^ ((2:ℝ≥0∞).to_real) = ‖f‖ ^ ((2:ℝ≥0∞).to_real),
{ exact real.rpow_left_inj_on H.ne' (norm_nonneg _) (norm_nonneg _) this },
refine tendsto_nhds_unique _ (lp.has_sum_norm H f),
convert (hV.summable_of_lp f).has_sum.norm.rpow_const (or.inr H.le),
ext s,
exact_mod_cast (hV.norm_sum f s).symm,
end }
protected lemma linear_isometry_apply (f : lp G 2) :
hV.linear_isometry f = ∑' i, V i (f i) :=
rfl
protected lemma has_sum_linear_isometry (f : lp G 2) :
has_sum (λ i, V i (f i)) (hV.linear_isometry f) :=
(hV.summable_of_lp f).has_sum
@[simp] protected lemma linear_isometry_apply_single {i : ι} (x : G i) :
hV.linear_isometry (lp.single 2 i x) = V i x :=
begin
rw [hV.linear_isometry_apply, ← tsum_ite_eq i (V i x)],
congr,
ext j,
rw [lp.single_apply],
split_ifs,
{ subst h },
{ simp }
end
@[simp] protected lemma linear_isometry_apply_dfinsupp_sum_single (W₀ : Π₀ (i : ι), G i) :
hV.linear_isometry (W₀.sum (lp.single 2)) = W₀.sum (λ i, V i) :=
begin
have : hV.linear_isometry (∑ i in W₀.support, lp.single 2 i (W₀ i))
= ∑ i in W₀.support, hV.linear_isometry (lp.single 2 i (W₀ i)),
{ exact hV.linear_isometry.to_linear_map.map_sum },
simp [dfinsupp.sum, this] {contextual := tt},
end
/-- The canonical linear isometry from the `lp 2` of a mutually orthogonal family of subspaces of
`E` into E, has range the closure of the span of the subspaces. -/
protected lemma range_linear_isometry [Π i, complete_space (G i)] :
hV.linear_isometry.to_linear_map.range = (⨆ i, (V i).to_linear_map.range).topological_closure :=
begin
refine le_antisymm _ _,
{ rintros x ⟨f, rfl⟩,
refine mem_closure_of_tendsto (hV.has_sum_linear_isometry f) (eventually_of_forall _),
intros s,
rw set_like.mem_coe,
refine sum_mem _,
intros i hi,
refine mem_supr_of_mem i _,
exact linear_map.mem_range_self _ (f i) },
{ apply topological_closure_minimal,
{ refine supr_le _,
rintros i x ⟨x, rfl⟩,
use lp.single 2 i x,
exact hV.linear_isometry_apply_single x },
exact hV.linear_isometry.isometry.uniform_inducing.is_complete_range.is_closed }
end
end orthogonal_family
section is_hilbert_sum
variables (𝕜 E) (V : Π i, G i →ₗᵢ[𝕜] E) (F : ι → submodule 𝕜 E)
include cplt
/-- Given a family of Hilbert spaces `G : ι → Type*`, a Hilbert sum of `G` consists of a Hilbert
space `E` and an orthogonal family `V : Π i, G i →ₗᵢ[𝕜] E` such that the induced isometry
`Φ : lp G 2 → E` is surjective.
Keeping in mind that `lp G 2` is "the" external Hilbert sum of `G : ι → Type*`, this is analogous
to `direct_sum.is_internal`, except that we don't express it in terms of actual submodules. -/
@[protect_proj] structure is_hilbert_sum : Prop := of_surjective ::
(orthogonal_family : orthogonal_family 𝕜 V)
(surjective_isometry : function.surjective (orthogonal_family.linear_isometry))
variables {𝕜 E V}
/-- If `V : Π i, G i →ₗᵢ[𝕜] E` is an orthogonal family such that the supremum of the ranges of
`V i` is dense, then `(E, V)` is a Hilbert sum of `G`. -/
lemma is_hilbert_sum.mk [Π i, complete_space $ G i]
(hVortho : orthogonal_family 𝕜 V)
(hVtotal : ⊤ ≤ (⨆ i, (V i).to_linear_map.range).topological_closure) :
is_hilbert_sum 𝕜 E V :=
{ orthogonal_family := hVortho,
surjective_isometry :=
begin
rw [←linear_isometry.coe_to_linear_map],
exact linear_map.range_eq_top.mp (eq_top_iff.mpr $
hVtotal.trans_eq hVortho.range_linear_isometry.symm)
end }
/-- This is `orthogonal_family.is_hilbert_sum` in the case of actual inclusions from subspaces. -/
lemma is_hilbert_sum.mk_internal [Π i, complete_space $ F i]
(hFortho : @orthogonal_family 𝕜 E _ _ _ (λ i, F i) _ (λ i, (F i).subtypeₗᵢ))
(hFtotal : ⊤ ≤ (⨆ i, (F i)).topological_closure) :
@is_hilbert_sum _ 𝕜 _ E _ _ (λ i, F i) _ (λ i, (F i).subtypeₗᵢ) :=
is_hilbert_sum.mk hFortho (by simpa [subtypeₗᵢ_to_linear_map, range_subtype] using hFtotal)
/-- *A* Hilbert sum `(E, V)` of `G` is canonically isomorphic to *the* Hilbert sum of `G`,
i.e `lp G 2`.
Note that this goes in the opposite direction from `orthogonal_family.linear_isometry`. -/
noncomputable def is_hilbert_sum.linear_isometry_equiv (hV : is_hilbert_sum 𝕜 E V) :
E ≃ₗᵢ[𝕜] lp G 2 :=
linear_isometry_equiv.symm $
linear_isometry_equiv.of_surjective
hV.orthogonal_family.linear_isometry hV.surjective_isometry
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G` and `lp G 2`,
a vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`. -/
protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply
(hV : is_hilbert_sum 𝕜 E V) (w : lp G 2) :
hV.linear_isometry_equiv.symm w = ∑' i, V i (w i) :=
by simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.linear_isometry_apply]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G` and `lp G 2`,
a vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`, and this
sum indeed converges. -/
protected lemma is_hilbert_sum.has_sum_linear_isometry_equiv_symm
(hV : is_hilbert_sum 𝕜 E V) (w : lp G 2) :
has_sum (λ i, V i (w i)) (hV.linear_isometry_equiv.symm w) :=
by simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.has_sum_linear_isometry]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and
`lp G 2`, an "elementary basis vector" in `lp G 2` supported at `i : ι` is the image of the
associated element in `E`. -/
@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply_single
(hV : is_hilbert_sum 𝕜 E V) {i : ι} (x : G i) :
hV.linear_isometry_equiv.symm (lp.single 2 i x) = V i x :=
by simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.linear_isometry_apply_single]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and
`lp G 2`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of
elements of `E`. -/
@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply_dfinsupp_sum_single
(hV : is_hilbert_sum 𝕜 E V) (W₀ : Π₀ (i : ι), G i) :
hV.linear_isometry_equiv.symm (W₀.sum (lp.single 2)) = (W₀.sum (λ i, V i)) :=
by simp [is_hilbert_sum.linear_isometry_equiv,
orthogonal_family.linear_isometry_apply_dfinsupp_sum_single]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and
`lp G 2`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of
elements of `E`. -/
@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_apply_dfinsupp_sum_single
(hV : is_hilbert_sum 𝕜 E V) (W₀ : Π₀ (i : ι), G i) :
(hV.linear_isometry_equiv (W₀.sum (λ i, V i)) : Π i, G i) = W₀ :=
begin
rw ← hV.linear_isometry_equiv_symm_apply_dfinsupp_sum_single,
rw linear_isometry_equiv.apply_symm_apply,
ext i,
simp [dfinsupp.sum, lp.single_apply] {contextual := tt},
end
/-- Given a total orthonormal family `v : ι → E`, `E` is a Hilbert sum of `λ i : ι, 𝕜` relative to
the family of linear isometries `λ i, λ k, k • v i`. -/
lemma orthonormal.is_hilbert_sum {v : ι → E} (hv : orthonormal 𝕜 v)
(hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :
@is_hilbert_sum _ 𝕜 _ _ _ _ (λ i : ι, 𝕜) _
(λ i, linear_isometry.to_span_singleton 𝕜 E (hv.1 i)) :=
is_hilbert_sum.mk hv.orthogonal_family
begin
convert hsp,
simp [← linear_map.span_singleton_eq_range, ← submodule.span_Union],
end
lemma submodule.is_hilbert_sum_orthogonal (K : submodule 𝕜 E) [hK : complete_space K] :
@is_hilbert_sum _ 𝕜 _ E _ _ (λ b, ((cond b K Kᗮ : submodule 𝕜 E) : Type*)) _
(λ b, (cond b K Kᗮ).subtypeₗᵢ) :=
begin
haveI : Π b, complete_space ((cond b K Kᗮ : submodule 𝕜 E) : Type*),
{ intro b,
cases b;
exact orthogonal.complete_space K <|> assumption },
refine is_hilbert_sum.mk_internal _ K.orthogonal_family_self _,
refine le_trans _ (submodule.le_topological_closure _),
rw [supr_bool_eq, cond, cond],
refine codisjoint.top_le _,
exact submodule.is_compl_orthogonal_of_complete_space.codisjoint
end
end is_hilbert_sum
/-! ### Hilbert bases -/
section
variables (ι) (𝕜) (E)
/-- A Hilbert basis on `ι` for an inner product space `E` is an identification of `E` with the `lp`
space `ℓ²(ι, 𝕜)`. -/
structure hilbert_basis := of_repr :: (repr : E ≃ₗᵢ[𝕜] ℓ²(ι, 𝕜))
end
namespace hilbert_basis
instance {ι : Type*} : inhabited (hilbert_basis ι 𝕜 ℓ²(ι, 𝕜)) :=
⟨of_repr (linear_isometry_equiv.refl 𝕜 _)⟩
/-- `b i` is the `i`th basis vector. -/
instance : has_coe_to_fun (hilbert_basis ι 𝕜 E) (λ _, ι → E) :=
{ coe := λ b i, b.repr.symm (lp.single 2 i (1:𝕜)) }
@[simp] protected lemma repr_symm_single (b : hilbert_basis ι 𝕜 E) (i : ι) :
b.repr.symm (lp.single 2 i (1:𝕜)) = b i :=
rfl
@[simp] protected lemma repr_self (b : hilbert_basis ι 𝕜 E) (i : ι) :
b.repr (b i) = lp.single 2 i (1:𝕜) :=
by rw [← b.repr_symm_single, linear_isometry_equiv.apply_symm_apply]
protected lemma repr_apply_apply (b : hilbert_basis ι 𝕜 E) (v : E) (i : ι) :
b.repr v i = ⟪b i, v⟫ :=
begin
rw [← b.repr.inner_map_map (b i) v, b.repr_self, lp.inner_single_left],
simp,
end
@[simp] protected lemma orthonormal (b : hilbert_basis ι 𝕜 E) : orthonormal 𝕜 b :=
begin
rw orthonormal_iff_ite,
intros i j,
rw [← b.repr.inner_map_map (b i) (b j), b.repr_self, b.repr_self, lp.inner_single_left,
lp.single_apply],
simp,
end
protected lemma has_sum_repr_symm (b : hilbert_basis ι 𝕜 E) (f : ℓ²(ι, 𝕜)) :
has_sum (λ i, f i • b i) (b.repr.symm f) :=
begin
suffices H : (λ (i : ι), f i • b i) =
(λ (b_1 : ι), (b.repr.symm.to_continuous_linear_equiv) ((λ (i : ι), lp.single 2 i (f i)) b_1)),
{ rw H,
have : has_sum (λ (i : ι), lp.single 2 i (f i)) f := lp.has_sum_single ennreal.two_ne_top f,
exact (↑(b.repr.symm.to_continuous_linear_equiv) : ℓ²(ι, 𝕜) →L[𝕜] E).has_sum this },
ext i,
apply b.repr.injective,
have : lp.single 2 i (f i * 1) = f i • lp.single 2 i 1 := lp.single_smul 2 i (1:𝕜) (f i),
rw mul_one at this,
rw [linear_isometry_equiv.map_smul, b.repr_self, ← this,
linear_isometry_equiv.coe_to_continuous_linear_equiv],
exact (b.repr.apply_symm_apply (lp.single 2 i (f i))).symm,
end
protected lemma has_sum_repr (b : hilbert_basis ι 𝕜 E) (x : E) :
has_sum (λ i, b.repr x i • b i) x :=
by simpa using b.has_sum_repr_symm (b.repr x)
@[simp] protected lemma dense_span (b : hilbert_basis ι 𝕜 E) :
(span 𝕜 (set.range b)).topological_closure = ⊤ :=
begin
classical,
rw eq_top_iff,
rintros x -,
refine mem_closure_of_tendsto (b.has_sum_repr x) (eventually_of_forall _),
intros s,
simp only [set_like.mem_coe],
refine sum_mem _,
rintros i -,
refine smul_mem _ _ _,
exact subset_span ⟨i, rfl⟩
end
protected lemma has_sum_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :
has_sum (λ i, ⟪x, b i⟫ * ⟪b i, y⟫) ⟪x, y⟫ :=
begin
convert (b.has_sum_repr y).mapL (innerSL x),
ext i,
rw [innerSL_apply, b.repr_apply_apply, inner_smul_right, mul_comm]
end
protected lemma summable_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :
summable (λ i, ⟪x, b i⟫ * ⟪b i, y⟫) :=
(b.has_sum_inner_mul_inner x y).summable
protected lemma tsum_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :
∑' i, ⟪x, b i⟫ * ⟪b i, y⟫ = ⟪x, y⟫ :=
(b.has_sum_inner_mul_inner x y).tsum_eq
-- Note : this should be `b.repr` composed with an identification of `lp (λ i : ι, 𝕜) p` with
-- `pi_Lp p (λ i : ι, 𝕜)` (in this case with `p = 2`), but we don't have this yet (July 2022).
/-- A finite Hilbert basis is an orthonormal basis. -/
protected def to_orthonormal_basis [fintype ι] (b : hilbert_basis ι 𝕜 E) :
orthonormal_basis ι 𝕜 E :=
orthonormal_basis.mk b.orthonormal
begin
refine eq.ge _,
have := (span 𝕜 (finset.univ.image b : set E)).closed_of_finite_dimensional,
simpa only [finset.coe_image, finset.coe_univ, set.image_univ, hilbert_basis.dense_span] using
this.submodule_topological_closure_eq.symm
end
@[simp] lemma coe_to_orthonormal_basis [fintype ι] (b : hilbert_basis ι 𝕜 E) :
(b.to_orthonormal_basis : ι → E) = b :=
orthonormal_basis.coe_mk _ _
protected lemma has_sum_orthogonal_projection {U : submodule 𝕜 E}
[complete_space U] (b : hilbert_basis ι 𝕜 U) (x : E) :
has_sum (λ i, ⟪(b i : E), x⟫ • b i) (orthogonal_projection U x) :=
by simpa only [b.repr_apply_apply, inner_orthogonal_projection_eq_of_mem_left]
using b.has_sum_repr (orthogonal_projection U x)
lemma finite_spans_dense (b : hilbert_basis ι 𝕜 E) :
(⨆ J : finset ι, span 𝕜 (J.image b : set E)).topological_closure = ⊤ :=
eq_top_iff.mpr $ b.dense_span.ge.trans
begin
simp_rw [← submodule.span_Union],
exact topological_closure_mono (span_mono $ set.range_subset_iff.mpr $
λ i, set.mem_Union_of_mem {i} $ finset.mem_coe.mpr $ finset.mem_image_of_mem _ $
finset.mem_singleton_self i)
end
variables {v : ι → E} (hv : orthonormal 𝕜 v)
include hv cplt
/-- An orthonormal family of vectors whose span is dense in the whole module is a Hilbert basis. -/
protected def mk (hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :
hilbert_basis ι 𝕜 E :=
hilbert_basis.of_repr $
(hv.is_hilbert_sum hsp).linear_isometry_equiv
lemma _root_.orthonormal.linear_isometry_equiv_symm_apply_single_one (h i) :
(hv.is_hilbert_sum h).linear_isometry_equiv.symm (lp.single 2 i 1) = v i :=
by rw [is_hilbert_sum.linear_isometry_equiv_symm_apply_single,
linear_isometry.to_span_singleton_apply, one_smul]
@[simp] protected lemma coe_mk (hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :
⇑(hilbert_basis.mk hv hsp) = v :=
by apply (funext $ orthonormal.linear_isometry_equiv_symm_apply_single_one hv hsp)
/-- An orthonormal family of vectors whose span has trivial orthogonal complement is a Hilbert
basis. -/
protected def mk_of_orthogonal_eq_bot (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) : hilbert_basis ι 𝕜 E :=
hilbert_basis.mk hv
(by rw [← orthogonal_orthogonal_eq_closure, ← eq_top_iff, orthogonal_eq_top_iff, hsp])
@[simp] protected lemma coe_of_orthogonal_eq_bot_mk (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) :
⇑(hilbert_basis.mk_of_orthogonal_eq_bot hv hsp) = v :=
hilbert_basis.coe_mk hv _
omit hv
-- Note : this should be `b.repr` composed with an identification of `lp (λ i : ι, 𝕜) p` with
-- `pi_Lp p (λ i : ι, 𝕜)` (in this case with `p = 2`), but we don't have this yet (July 2022).
/-- An orthonormal basis is an Hilbert basis. -/
protected def _root_.orthonormal_basis.to_hilbert_basis [fintype ι] (b : orthonormal_basis ι 𝕜 E) :
hilbert_basis ι 𝕜 E :=
hilbert_basis.mk b.orthonormal $
by simpa only [← orthonormal_basis.coe_to_basis, b.to_basis.span_eq, eq_top_iff]
using @subset_closure E _ _
@[simp] lemma _root_.orthonormal_basis.coe_to_hilbert_basis [fintype ι]
(b : orthonormal_basis ι 𝕜 E) : (b.to_hilbert_basis : ι → E) = b :=
hilbert_basis.coe_mk _ _
/-- A Hilbert space admits a Hilbert basis extending a given orthonormal subset. -/
lemma _root_.orthonormal.exists_hilbert_basis_extension
{s : set E} (hs : orthonormal 𝕜 (coe : s → E)) :
∃ (w : set E) (b : hilbert_basis w 𝕜 E), s ⊆ w ∧ ⇑b = (coe : w → E) :=
let ⟨w, hws, hw_ortho, hw_max⟩ := exists_maximal_orthonormal hs in
⟨ w,
hilbert_basis.mk_of_orthogonal_eq_bot hw_ortho
(by simpa [maximal_orthonormal_iff_orthogonal_complement_eq_bot hw_ortho] using hw_max),
hws,
hilbert_basis.coe_of_orthogonal_eq_bot_mk _ _ ⟩
variables (𝕜 E)
/-- A Hilbert space admits a Hilbert basis. -/
lemma _root_.exists_hilbert_basis :
∃ (w : set E) (b : hilbert_basis w 𝕜 E), ⇑b = (coe : w → E) :=
let ⟨w, hw, hw', hw''⟩ := (orthonormal_empty 𝕜 E).exists_hilbert_basis_extension in ⟨w, hw, hw''⟩
end hilbert_basis
|
03a98f580909e7ba6914c746267772c7e08e80bb | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/analysis/complex/liouville.lean | 95b25ddbf2e5aa6ab711da4faa49994e72793672 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 5,722 | lean | /-
Copyright (c) 2022 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import analysis.complex.cauchy_integral
import analysis.calculus.fderiv_analytic
import analysis.normed_space.completion
/-!
# Liouville's theorem
In this file we prove Liouville's theorem: if `f : E → F` is complex differentiable on the whole
space and its range is bounded, then the function is a constant. Various versions of this theorem
are formalized in `differentiable.apply_eq_apply_of_bounded`,
`differentiable.exists_const_forall_eq_of_bounded`, and
`differentiable.exists_eq_const_of_bounded`.
The proof is based on the Cauchy integral formula for the derivative of an analytic function, see
`complex.deriv_eq_smul_circle_integral`.
-/
open topological_space metric set filter asymptotics function measure_theory
open_locale topological_space filter nnreal real
universes u v
variables {E : Type u} [normed_add_comm_group E] [normed_space ℂ E]
{F : Type v} [normed_add_comm_group F] [normed_space ℂ F]
local postfix `̂`:100 := uniform_space.completion
namespace complex
/-- If `f` is complex differentiable on an open disc with center `c` and radius `R > 0` and is
continuous on its closure, then `f' c` can be represented as an integral over the corresponding
circle.
TODO: add a version for `w ∈ metric.ball c R`.
TODO: add a version for higher derivatives. -/
lemma deriv_eq_smul_circle_integral [complete_space F] {R : ℝ} {c : ℂ} {f : ℂ → F} (hR : 0 < R)
(hf : diff_cont_on_cl ℂ f (ball c R)) :
deriv f c = (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z :=
begin
lift R to ℝ≥0 using hR.le,
refine (hf.has_fpower_series_on_ball hR).has_fpower_series_at.deriv.trans _,
simp only [cauchy_power_series_apply, one_div, zpow_neg, pow_one, smul_smul, zpow_two, mul_inv]
end
lemma norm_deriv_le_aux [complete_space F] {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R)
(hf : diff_cont_on_cl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) :
‖deriv f c‖ ≤ C / R :=
begin
have : ∀ z ∈ sphere c R, ‖(z - c) ^ (-2 : ℤ) • f z‖ ≤ C / (R * R),
from λ z (hz : abs (z - c) = R), by simpa [-mul_inv_rev, norm_smul, hz, zpow_two,
←div_eq_inv_mul] using (div_le_div_right (mul_pos hR hR)).2 (hC z hz),
calc ‖deriv f c‖ = ‖(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z‖ :
congr_arg norm (deriv_eq_smul_circle_integral hR hf)
... ≤ R * (C / (R * R)) :
circle_integral.norm_two_pi_I_inv_smul_integral_le_of_norm_le_const hR.le this
... = C / R : by rw [mul_div_left_comm, div_self_mul_self', div_eq_mul_inv]
end
/-- If `f` is complex differentiable on an open disc of radius `R > 0`, is continuous on its
closure, and its values on the boundary circle of this disc are bounded from above by `C`, then the
norm of its derivative at the center is at most `C / R`. -/
lemma norm_deriv_le_of_forall_mem_sphere_norm_le {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R)
(hd : diff_cont_on_cl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) :
‖deriv f c‖ ≤ C / R :=
begin
set e : F →L[ℂ] F̂ := uniform_space.completion.to_complL,
have : has_deriv_at (e ∘ f) (e (deriv f c)) c,
from e.has_fderiv_at.comp_has_deriv_at c
(hd.differentiable_at is_open_ball $ mem_ball_self hR).has_deriv_at,
calc ‖deriv f c‖ = ‖deriv (e ∘ f) c‖ :
by { rw this.deriv, exact (uniform_space.completion.norm_coe _).symm }
... ≤ C / R :
norm_deriv_le_aux hR (e.differentiable.comp_diff_cont_on_cl hd)
(λ z hz, (uniform_space.completion.norm_coe _).trans_le (hC z hz))
end
/-- An auxiliary lemma for Liouville's theorem `differentiable.apply_eq_apply_of_bounded`. -/
lemma liouville_theorem_aux {f : ℂ → F} (hf : differentiable ℂ f)
(hb : bounded (range f)) (z w : ℂ) : f z = f w :=
begin
suffices : ∀ c, deriv f c = 0, from is_const_of_deriv_eq_zero hf this z w,
clear z w, intro c,
obtain ⟨C, C₀, hC⟩ : ∃ C > (0 : ℝ), ∀ z, ‖f z‖ ≤ C,
{ rcases bounded_iff_forall_norm_le.1 hb with ⟨C, hC⟩,
exact ⟨max C 1, lt_max_iff.2 (or.inr zero_lt_one),
λ z, (hC (f z) (mem_range_self _)).trans (le_max_left _ _)⟩ },
refine norm_le_zero_iff.1 (le_of_forall_le_of_dense $ λ ε ε₀, _),
calc ‖deriv f c‖ ≤ C / (C / ε) :
norm_deriv_le_of_forall_mem_sphere_norm_le (div_pos C₀ ε₀) hf.diff_cont_on_cl (λ z _, hC z)
... = ε : div_div_cancel' C₀.lt.ne'
end
end complex
namespace differentiable
open complex
/-- **Liouville's theorem**: a complex differentiable bounded function `f : E → F` is a constant. -/
lemma apply_eq_apply_of_bounded {f : E → F} (hf : differentiable ℂ f) (hb : bounded (range f))
(z w : E) : f z = f w :=
begin
set g : ℂ → F := f ∘ (λ t : ℂ, t • (w - z) + z),
suffices : g 0 = g 1, by simpa [g],
apply liouville_theorem_aux,
exacts [hf.comp ((differentiable_id.smul_const (w - z)).add_const z),
hb.mono (range_comp_subset_range _ _)]
end
/-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/
lemma exists_const_forall_eq_of_bounded {f : E → F} (hf : differentiable ℂ f)
(hb : bounded (range f)) : ∃ c, ∀ z, f z = c :=
⟨f 0, λ z, hf.apply_eq_apply_of_bounded hb _ _⟩
/-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/
lemma exists_eq_const_of_bounded {f : E → F} (hf : differentiable ℂ f)
(hb : bounded (range f)) : ∃ c, f = const E c :=
(hf.exists_const_forall_eq_of_bounded hb).imp $ λ c, funext
end differentiable
|
62d7a3d5f8ca3a9d43e1292e80677e755faa8368 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/extra/print_tests.lean | 354e1cf5117508b470ea3ab2d14234879b27259c | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 78 | lean | print notation
print notation ∧ ∨
print notation if
print notation mod
|
8ec76016a946e5d4c5877a4b64d194e504649929 | 618003631150032a5676f229d13a079ac875ff77 | /src/tactic/algebra.lean | 10d2cbe80d865bcfd1f6ea91ad3e9bfc232092c9 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 779 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import tactic.core
open lean.parser
namespace tactic
@[user_attribute]
meta def ancestor_attr : user_attribute unit (list name) :=
{ name := `ancestor,
descr := "ancestor of old structures",
parser := many ident }
meta def get_ancestors (cl : name) : tactic (list name) :=
(++) <$> (prod.fst <$> subobject_names cl <|> pure [])
<*> (user_attribute.get_param ancestor_attr cl <|> pure [])
meta def find_ancestors : name → expr → tactic (list expr) | cl arg :=
do cs ← get_ancestors cl,
r ← cs.mmap $ λ c, list.ret <$> (mk_app c [arg] >>= mk_instance) <|> find_ancestors c arg,
return r.join
end tactic
|
e6513d81eacfeca94707c20c12468f0e604f4ff4 | e58fe8dce8abdb027029831196eef44ecb90a19a | /Imperial/proof_ex.lean | 6397fd132b6f96850824ca88dd5df3a42ab24d5a | [] | no_license | hieule3004/Imperial | 89fc066eded43cf6015e19f6f83677411013b47c | 829d0d96603ff3e68ede818873db4931b8d854da | refs/heads/master | 1,584,834,346,353 | 1,531,250,018,000 | 1,531,250,018,000 | 139,205,362 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 247 | lean | open classical
variables (men : Type) (barber : men)
variable (shaves : men → men → Prop)
example (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=
let h0 := (h barber) in by_cases (λh1, (h0.mp h1) h1) (λh1, h1 (h0.mpr h1)) |
155b0ffd7b368f8a132dea4452a04d9f851dcbe5 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/char_zero/infinite.lean | 38a50918e2cf5d6fd3fab56f2c55962fd7e02e25 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 479 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.char_zero.defs
import data.fintype.lattice
/-! # A characteristic-zero semiring is infinite -/
open set
variables (M : Type*) [add_monoid_with_one M] [char_zero M]
@[priority 100] -- see Note [lower instance priority]
instance char_zero.infinite : infinite M :=
infinite.of_injective coe nat.cast_injective
|
9aa0b56d99176019f551332b27a8fc67d026c866 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/lcnfInliningIssue.lean | bcceecefd093c783e72c2ecba98fa1819c5bfc15 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 903 | lean | namespace MWE
inductive Id {A : Type u} : A → A → Type u
| refl {a : A} : Id a a
attribute [eliminator] Id.casesOn
infix:50 (priority := high) " = " => Id
def symm {A : Type u} {a b : A} (p : a = b) : b = a :=
by { induction p; exact Id.refl }
def map {A : Type u} {B : Type v} {a b : A} (f : A → B) (p : a = b) : f a = f b :=
by { induction p; apply Id.refl }
def transport {A : Type u} (B : A → Type v) {a b : A} (p : a = b) : B a → B b :=
by { induction p; exact id }
def boolToUniverse : Bool → Type
| true => Unit
| false => Empty
def ffNeqTt : false = true → Empty :=
λ p => transport boolToUniverse (symm p) ()
def isZero : Nat → Bool
| Nat.zero => true
| Nat.succ _ => false
set_option pp.funBinderTypes true
set_option pp.letVarTypes true
set_option trace.Compiler.result true
def succNeqZero (n : Nat) : Nat.succ n = 0 → Empty :=
λ h => ffNeqTt (map isZero h)
|
cff29cd3b4dbaa9ccf6d6f1feebfaca4c0962f4f | d1a52c3f208fa42c41df8278c3d280f075eb020c | /tests/lean/run/impByNameResolution.lean | 15f3178767813b947dad4bd41ffcb2cc63b9f411 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 102 | lean |
namespace Foo
def f (x : Nat) : Nat := x + 1
@[implementedBy f] constant g : Nat → Nat
end Foo
|
20890a962cb3a7f7a16a1d488d664a9ffe7828a6 | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /tests/lean/run/lcnf2.lean | 607af19cb22a898ba6471f71aad6837c66d28ff8 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 739 | lean | import Lean
open Lean
def f (x : Nat) : Nat :=
let y := match x with
| 0 => 1
| x + 1 => 2 * x
match y with
| 0 => 2
| z+1 => z + y + 2
#eval Compiler.compile #[``f]
def g (x : Nat) : Bool :=
let pred? := match x with
| 0 => none
| y+1 => some y
match pred? with
| none => true
| some _ => false
set_option trace.Compiler true
#eval Compiler.compile #[``g]
abbrev TupleNTyp : Nat → Type 1
| 0 => Type
| n + 1 => Type → (TupleNTyp n)
noncomputable abbrev TupleN : (n : Fin 1) → TupleNTyp n.val
| 0 => Unit × Unit
set_option pp.proofs true
#eval Compiler.compile #[``TupleN]
def userControlled (a b : Nat) :=
let f := fun _ => a
f () + b
#eval Compiler.compile #[``userControlled]
|
e007a2c3687f1b85e85404abd7f6fd3dd6a2ce74 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/algebra/category/Group/zero.lean | 872c715ca5a34deb21ff808dff5f290d3b89f76e | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 767 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.category.Group.basic
import category_theory.limits.shapes.zero
/-!
# The category of commutative additive groups has a zero object and zero morphism.
-/
open category_theory
open category_theory.limits
universe u
namespace AddCommGroup
instance : has_zero_morphisms.{u} AddCommGroup.{u} :=
{ has_zero := λ X Y, ⟨0⟩ }
instance : has_zero_object.{u} AddCommGroup.{u} :=
{ zero := 0,
unique_to := λ X, ⟨⟨0⟩, λ f, begin ext, cases x, erw add_monoid_hom.map_zero, refl end⟩,
unique_from := λ X, ⟨⟨0⟩, λ f, begin ext, apply subsingleton.elim, end⟩, }
end AddCommGroup
|
cb895d764ad796beee3e5b073cac0b527783139d | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /src/Init/Fix.lean | 90f1a91a89e4d09cb4b6e1027e2155b4067e88ba | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 5,811 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.UInt
universe u
def bfix1 {α β : Type u} (base : α → β) (rec : (α → β) → α → β) : Nat → α → β
| 0, a => base a
| n+1, a => rec (bfix1 n) a
@[extern c inline "lean_fixpoint(#4, #5)"]
def fixCore1 {α β : Type u} (base : @& (α → β)) (rec : (α → β) → α → β) : α → β :=
bfix1 base rec usizeSz
@[inline] def fixCore {α β : Type u} (base : @& (α → β)) (rec : (α → β) → α → β) : α → β :=
fixCore1 base rec
@[inline] def fix1 {α β : Type u} [Inhabited β] (rec : (α → β) → α → β) : α → β :=
fixCore1 (fun _ => arbitrary β) rec
@[inline] def fix {α β : Type u} [Inhabited β] (rec : (α → β) → α → β) : α → β :=
fixCore1 (fun _ => arbitrary β) rec
def bfix2 {α₁ α₂ β : Type u} (base : α₁ → α₂ → β) (rec : (α₁ → α₂ → β) → α₁ → α₂ → β) : Nat → α₁ → α₂ → β
| 0, a₁, a₂ => base a₁ a₂
| n+1, a₁, a₂ => rec (bfix2 n) a₁ a₂
@[extern c inline "lean_fixpoint2(#5, #6, #7)"]
def fixCore2 {α₁ α₂ β : Type u} (base : α₁ → α₂ → β) (rec : (α₁ → α₂ → β) → α₁ → α₂ → β) : α₁ → α₂ → β :=
bfix2 base rec usizeSz
@[inline] def fix2 {α₁ α₂ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → β) → α₁ → α₂ → β) : α₁ → α₂ → β :=
fixCore2 (fun _ _ => arbitrary β) rec
def bfix3 {α₁ α₂ α₃ β : Type u} (base : α₁ → α₂ → α₃ → β) (rec : (α₁ → α₂ → α₃ → β) → α₁ → α₂ → α₃ → β) : Nat → α₁ → α₂ → α₃ → β
| 0, a₁, a₂, a₃ => base a₁ a₂ a₃
| n+1, a₁, a₂, a₃ => rec (bfix3 n) a₁ a₂ a₃
@[extern c inline "lean_fixpoint3(#6, #7, #8, #9)"]
def fixCore3 {α₁ α₂ α₃ β : Type u} (base : α₁ → α₂ → α₃ → β) (rec : (α₁ → α₂ → α₃ → β) → α₁ → α₂ → α₃ → β) : α₁ → α₂ → α₃ → β :=
bfix3 base rec usizeSz
@[inline] def fix3 {α₁ α₂ α₃ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → β) → α₁ → α₂ → α₃ → β) : α₁ → α₂ → α₃ → β :=
fixCore3 (fun _ _ _ => arbitrary β) rec
def bfix4 {α₁ α₂ α₃ α₄ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → β) (rec : (α₁ → α₂ → α₃ → α₄ → β) → α₁ → α₂ → α₃ → α₄ → β) : Nat → α₁ → α₂ → α₃ → α₄ → β
| 0, a₁, a₂, a₃, a₄ => base a₁ a₂ a₃ a₄
| n+1, a₁, a₂, a₃, a₄ => rec (bfix4 n) a₁ a₂ a₃ a₄
@[extern c inline "lean_fixpoint4(#7, #8, #9, #10, #11)"]
def fixCore4 {α₁ α₂ α₃ α₄ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → β) (rec : (α₁ → α₂ → α₃ → α₄ → β) → α₁ → α₂ → α₃ → α₄ → β) : α₁ → α₂ → α₃ → α₄ → β :=
bfix4 base rec usizeSz
@[inline] def fix4 {α₁ α₂ α₃ α₄ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → α₄ → β) → α₁ → α₂ → α₃ → α₄ → β) : α₁ → α₂ → α₃ → α₄ → β :=
fixCore4 (fun _ _ _ _ => arbitrary β) rec
def bfix5 {α₁ α₂ α₃ α₄ α₅ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → β) : Nat → α₁ → α₂ → α₃ → α₄ → α₅ → β
| 0, a₁, a₂, a₃, a₄, a₅ => base a₁ a₂ a₃ a₄ a₅
| n+1, a₁, a₂, a₃, a₄, a₅ => rec (bfix5 n) a₁ a₂ a₃ a₄ a₅
@[extern c inline "lean_fixpoint5(#8, #9, #10, #11, #12, #13)"]
def fixCore5 {α₁ α₂ α₃ α₄ α₅ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → β :=
bfix5 base rec usizeSz
@[inline] def fix5 {α₁ α₂ α₃ α₄ α₅ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → β :=
fixCore5 (fun _ _ _ _ _ => arbitrary β) rec
def bfix6 {α₁ α₂ α₃ α₄ α₅ α₆ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) : Nat → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β
| 0, a₁, a₂, a₃, a₄, a₅, a₆ => base a₁ a₂ a₃ a₄ a₅ a₆
| n+1, a₁, a₂, a₃, a₄, a₅, a₆ => rec (bfix6 n) a₁ a₂ a₃ a₄ a₅ a₆
@[extern c inline "lean_fixpoint6(#9, #10, #11, #12, #13, #14, #15)"]
def fixCore6 {α₁ α₂ α₃ α₄ α₅ α₆ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β :=
bfix6 base rec usizeSz
@[inline] def fix6 {α₁ α₂ α₃ α₄ α₅ α₆ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β :=
fixCore6 (fun _ _ _ _ _ _ => arbitrary β) rec
|
91bc39e20f3039b3b43aa9f467eac289e79c21a7 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/order/category/omega_complete_partial_order.lean | 0c6f4736bbeecd0ccd54cddf27dcb10036df4a28 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,032 | lean | /-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import order.omega_complete_partial_order
import order.category.Preorder
import category_theory.limits.shapes.products
import category_theory.limits.shapes.equalizers
import category_theory.limits.constructions.limits_of_products_and_equalizers
/-!
# Category of types with a omega complete partial order
In this file, we bundle the class `omega_complete_partial_order` into a
concrete category and prove that continuous functions also form
a `omega_complete_partial_order`.
## Main definitions
* `ωCPO`
* an instance of `category` and `concrete_category`
-/
open category_theory
universes u v
/-- The category of types with a omega complete partial order. -/
def ωCPO : Type (u+1) := bundled omega_complete_partial_order
namespace ωCPO
open omega_complete_partial_order
instance : bundled_hom @continuous_hom :=
{ to_fun := @continuous_hom.simps.apply,
id := @continuous_hom.id,
comp := @continuous_hom.comp,
hom_ext := @continuous_hom.coe_inj }
attribute [derive [large_category, concrete_category]] ωCPO
instance : has_coe_to_sort ωCPO Type* := bundled.has_coe_to_sort
/-- Construct a bundled ωCPO from the underlying type and typeclass. -/
def of (α : Type*) [omega_complete_partial_order α] : ωCPO := bundled.of α
instance : inhabited ωCPO := ⟨of punit⟩
instance (α : ωCPO) : omega_complete_partial_order α := α.str
section
open category_theory.limits
namespace has_products
/-- The pi-type gives a cone for a product. -/
def product {J : Type v} (f : J → ωCPO.{v}) : fan f :=
fan.mk (of (Π j, f j)) (λ j, continuous_hom.of_mono (pi.eval_preorder_hom j) (λ c, rfl))
/-- The pi-type is a limit cone for the product. -/
def is_product (J : Type v) (f : J → ωCPO) : is_limit (product f) :=
{ lift := λ s,
⟨⟨λ t j, s.π.app j t, λ x y h j, (s.π.app j).monotone h⟩,
λ x, funext (λ j, (s.π.app j).continuous x)⟩,
uniq' := λ s m w,
begin
ext t j,
change m t j = s.π.app j t,
rw ← w j,
refl,
end }.
instance (J : Type v) (f : J → ωCPO.{v}) : has_product f :=
has_limit.mk ⟨_, is_product _ f⟩
end has_products
instance omega_complete_partial_order_equalizer
{α β : Type*} [omega_complete_partial_order α] [omega_complete_partial_order β]
(f g : α →𝒄 β) : omega_complete_partial_order {a : α // f a = g a} :=
omega_complete_partial_order.subtype _ $ λ c hc,
begin
rw [f.continuous, g.continuous],
congr' 1,
ext,
apply hc _ ⟨_, rfl⟩,
end
namespace has_equalizers
/-- The equalizer inclusion function as a `continuous_hom`. -/
def equalizer_ι {α β : Type*} [omega_complete_partial_order α] [omega_complete_partial_order β]
(f g : α →𝒄 β) :
{a : α // f a = g a} →𝒄 α :=
continuous_hom.of_mono (preorder_hom.subtype.val _) (λ c, rfl)
/-- A construction of the equalizer fork. -/
def equalizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) :
fork f g :=
@fork.of_ι _ _ _ _ _ _ (ωCPO.of {a // f a = g a}) (equalizer_ι f g)
(continuous_hom.ext _ _ (λ x, x.2))
/-- The equalizer fork is a limit. -/
def is_equalizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) : is_limit (equalizer f g) :=
fork.is_limit.mk' _ $ λ s,
⟨{ to_fun := λ x, ⟨s.ι x, by apply continuous_hom.congr_fun s.condition⟩,
monotone' := λ x y h, s.ι.monotone h,
cont := λ x, subtype.ext (s.ι.continuous x) },
by { ext, refl },
λ m hm,
begin
ext,
apply continuous_hom.congr_fun hm,
end⟩
end has_equalizers
instance : has_products ωCPO.{v} :=
λ J, { has_limit := λ F, has_limit_of_iso discrete.nat_iso_functor.symm }
instance {X Y : ωCPO.{v}} (f g : X ⟶ Y) : has_limit (parallel_pair f g) :=
has_limit.mk ⟨_, has_equalizers.is_equalizer f g⟩
instance : has_equalizers ωCPO.{v} := has_equalizers_of_has_limit_parallel_pair _
instance : has_limits ωCPO.{v} := limits_from_equalizers_and_products
end
end ωCPO
|
1679182b1b1a79051b3bdf182d61ebd04228c26a | 0d7f5899c0475f9e105a439896d9377f80c0d7c3 | /src/.old/fron_ralg.lean | 99a987a59bf5fee46a4337fe7a67c9ec11c84f24 | [] | no_license | adamtopaz/UnivAlg | 127038f320e68cdf3efcd0c084c9af02fdb8da3d | 2458d47a6e4fd0525e3a25b07cb7dd518ac173ef | refs/heads/master | 1,670,320,985,286 | 1,597,350,882,000 | 1,597,350,882,000 | 280,585,500 | 4 | 0 | null | 1,597,350,883,000 | 1,595,048,527,000 | Lean | UTF-8 | Lean | false | false | 3,080 | lean | import .free_ralg
namespace ralg
variables {L0 : lang} {L : lang} (ι : L0 →# L)
variables (A : ralg L0)
namespace fron
def rel : (free L A) → (free L A) → Prop := λ x y,
∀ (B : ralg L) (g : A →% B{ι}), (free.lift L g) x = (free.lift L g) y
def setoid : setoid (free L A) := ⟨rel ι A,
begin
refine ⟨_,_,_⟩,
{ intros x B g, refl },
{ intros x y h B g, symmetry, apply h },
{ intros x y z h1 h2 B g, rw [h1,h2] }
end ⟩
end fron
def fron : ralg L :=
{ carrier := quotient (fron.setoid ι A),
appo := λ n t, @vector.quotient_lift _ (quotient (fron.setoid ι A)) (fron.setoid ι A)
_ (λ as, quotient.mk' (applyo t as))
begin
intros as bs h,
dsimp only [],
apply quotient.sound',
intros B g,
simp_rw ←ralg.applyo_map,
apply congr_arg,
simp_rw [vector.eq_iff_to_fn_eq_to_fn,vector.map_to_fn],
ext,
apply h,
end }
namespace fron
def fquot : (free L A) →% (fron ι A) :=
{ to_fn := quotient.mk',
applyo_map := λ n t as,
begin
change vector.quotient_lift _ _ (vector.map quotient.mk _) = _,
rw vector.quotient_lift_eq,
end }
def univ : A →% (fron ι A){ι} :=
{ to_fn := (fquot ι A) ∘ (free.univ L A),
applyo_map := λ n t as,
begin
rw ←vector.map_map,
change applyo (ι t) (vector.map (fquot _ _) _) = (fquot ι A) _,
rw ralg.applyo_map,
apply quotient.sound',
intros B g,
change _ = ((free.lift _ _) ∘ (free.univ _ _)) _,
rw [←ralg.applyo_map,vector.map_map,free.univ_comp_lift],
change applyo _ (vector.map ((free.lift _ _) ∘ (free.univ _ _)) _) = _,
rw [free.univ_comp_lift,←ralg.applyo_map],
refl,
end }
variable {A}
def lift {B : ralg L} (f : A →% B{ι}) : fron ι A →% B :=
{ to_fn := @quotient.lift _ _ (fron.setoid ι A) (free.lift L f)
begin
intros a b h,
apply h,
end,
applyo_map := λ n t as,
begin
rcases vector.exists_rep quotient.mk' as (quot.exists_rep) with ⟨as,rfl⟩,
rw vector.map_map,
have : @quotient.mk' _ (fron.setoid ι A) = (fquot ι A), by refl,
rw this,
erw ralg.applyo_map,
erw ralg.applyo_map,
change _ = quotient.lift _ _ (quotient.mk _),
rw quotient.lift_beta,
end }
theorem univ_comp_lift {B : ralg L} (f : A →% B{ι}) :
(univ ι A).comp ((lift ι f){%ι}) = f :=
begin
ext,
change (lift ι f) (quotient.mk' ((free.univ _ _) _)) = _,
unfold_coes,
dsimp only [],
erw quotient.lift_beta,
refl,
end
theorem lift_unique {B : ralg L} (f : A →% B{ι}) (g : fron ι A →% B) :
(univ ι A).comp (g{%ι}) = f → g = lift ι f := λ hyp,
begin
ext,
rcases quot.exists_rep x with ⟨x,rfl⟩,
unfold_coes,
dsimp only [],
erw quotient.lift_beta,
change _ = (free.lift _ _) x,
change (g ∘ (fquot _ _)) _ = _,
apply congr_fun,
suffices : (fquot ι A).comp g = free.lift L f,
{ replace this := congr_arg (ralgHom.to_fn) this,
assumption },
apply free.lift_unique,
ext y,
change ((univ ι A).comp (g{%ι})) y = _,
rw hyp,
end
end fron
end ralg |
896797430fc4dea4269504d30f2c9022fec5e586 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/playground/pldi/intro.lean | f9249130ae635df3fbb041d9b59fbc2e7b08951b | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,871 | lean | #check "hello"
#check 1
#check fun (x : Nat) => x + 1
#eval (fun (x : Nat) => x + 1) 3
-- Recursive functions
def fact : Nat → Nat
| 0 => 1
| n+1 => (n+1) * fact n
#eval fact 4
#eval fact 20
-- Dot notation
#eval List.map (fun x => toString x) [1, 2, 3]
#check @toString
#eval [1, 2, 3].map fun x => toString x
def List.len1 {α} (xs : List α) : Nat :=
xs.length + 1
#eval [1, 2, 3].len1
-- Inductive datatypes
inductive Tree (α : Type)
| leaf : α → Tree
| node : Tree → Tree → Tree
namespace Tree
private def toStr {α} [HasToString α] : Tree α → String
| leaf a => toString a
| node left right => "(node " ++ toStr left ++ " " ++ toStr right ++ ")"
instance {α} [HasToString α] : HasToString (Tree α) := ⟨toStr⟩
end Tree
#eval toString (Tree.node (Tree.leaf 10) (Tree.leaf 20))
open Tree
#eval toString (node (leaf 10) (node (leaf 20) (leaf 30)))
-- Arrays
#eval #[1, 2, 3].map fun x => x+1
#eval #[1, 2, 3].set! 1 10
#eval #[1, 2, 3].push 4
-- Structures
structure Person :=
(name : String)
(age : Nat := 0)
instance : HasToString Person :=
⟨fun p => p.name ++ ":" ++ toString p.age⟩
#eval toString { name := "John", age := 30 : Person }
#eval toString { name := "Jack" : Person }
def incAge (p : Person) (n : Nat) : Person :=
{ p with age := p.age + n }
#eval toString $ incAge { name := "John", age := 30 } 2
-- IO
def tst (msg : String) : IO Unit := do
IO.println "hello world";
IO.println msg
#eval tst "foo"
-- Debugging helper functions
def Tree.map {α β} (f : α → β) : Tree α → Tree β
| leaf a => leaf (f a)
| node left right => node (Tree.map left) (Tree.map right)
#print dbgTrace
#eval
let n := node (leaf 10) (node (leaf 20) (leaf 30));
let n := n.map fun x => x + 1;
-- let n := n.map fun x => dbgTrace ("x: " ++ toString x) $ fun _ => x + 1;
toString n
|
ca83229f974bfd91aad3cb9afb879d217d404340 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/data/real/nnreal.lean | e117a196e249c1682fdef2cdf56b266567b66b85 | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 25,745 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
Nonnegative real numbers.
-/
import algebra.linear_ordered_comm_group_with_zero
import algebra.big_operators.ring
import data.real.basic
import data.indicator_function
noncomputable theory
open_locale classical big_operators
/-- Nonnegative real numbers. -/
def nnreal := {r : ℝ // 0 ≤ r}
localized "notation ` ℝ≥0 ` := nnreal" in nnreal
namespace nnreal
instance : has_coe ℝ≥0 ℝ := ⟨subtype.val⟩
/- Simp lemma to put back `n.val` into the normal form given by the coercion. -/
@[simp] lemma val_eq_coe (n : nnreal) : n.val = n := rfl
instance : can_lift ℝ nnreal :=
{ coe := coe,
cond := λ r, 0 ≤ r,
prf := λ x hx, ⟨⟨x, hx⟩, rfl⟩ }
protected lemma eq {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) → n = m := subtype.eq
protected lemma eq_iff {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) ↔ n = m :=
iff.intro nnreal.eq (congr_arg coe)
lemma ne_iff {x y : ℝ≥0} : (x : ℝ) ≠ (y : ℝ) ↔ x ≠ y :=
not_iff_not_of_iff $ nnreal.eq_iff
protected def of_real (r : ℝ) : ℝ≥0 := ⟨max r 0, le_max_right _ _⟩
lemma coe_of_real (r : ℝ) (hr : 0 ≤ r) : (nnreal.of_real r : ℝ) = r :=
max_eq_left hr
lemma le_coe_of_real (r : ℝ) : r ≤ nnreal.of_real r :=
le_max_left r 0
lemma coe_nonneg (r : nnreal) : (0 : ℝ) ≤ r := r.2
@[norm_cast]
theorem coe_mk (a : ℝ) (ha) : ((⟨a, ha⟩ : ℝ≥0) : ℝ) = a := rfl
instance : has_zero ℝ≥0 := ⟨⟨0, le_refl 0⟩⟩
instance : has_one ℝ≥0 := ⟨⟨1, zero_le_one⟩⟩
instance : has_add ℝ≥0 := ⟨λa b, ⟨a + b, add_nonneg a.2 b.2⟩⟩
instance : has_sub ℝ≥0 := ⟨λa b, nnreal.of_real (a - b)⟩
instance : has_mul ℝ≥0 := ⟨λa b, ⟨a * b, mul_nonneg a.2 b.2⟩⟩
instance : has_inv ℝ≥0 := ⟨λa, ⟨(a.1)⁻¹, inv_nonneg.2 a.2⟩⟩
instance : has_le ℝ≥0 := ⟨λ r s, (r:ℝ) ≤ s⟩
instance : has_bot ℝ≥0 := ⟨0⟩
instance : inhabited ℝ≥0 := ⟨0⟩
@[simp, norm_cast] protected lemma coe_eq {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) = r₂ ↔ r₁ = r₂ :=
subtype.ext_iff_val.symm
@[simp, norm_cast] protected lemma coe_zero : ((0 : ℝ≥0) : ℝ) = 0 := rfl
@[simp, norm_cast] protected lemma coe_one : ((1 : ℝ≥0) : ℝ) = 1 := rfl
@[simp, norm_cast] protected lemma coe_add (r₁ r₂ : ℝ≥0) : ((r₁ + r₂ : ℝ≥0) : ℝ) = r₁ + r₂ := rfl
@[simp, norm_cast] protected lemma coe_mul (r₁ r₂ : ℝ≥0) : ((r₁ * r₂ : ℝ≥0) : ℝ) = r₁ * r₂ := rfl
@[simp, norm_cast] protected lemma coe_inv (r : ℝ≥0) : ((r⁻¹ : ℝ≥0) : ℝ) = r⁻¹ := rfl
@[simp, norm_cast] protected lemma coe_bit0 (r : ℝ≥0) : ((bit0 r : ℝ≥0) : ℝ) = bit0 r := rfl
@[simp, norm_cast] protected lemma coe_bit1 (r : ℝ≥0) : ((bit1 r : ℝ≥0) : ℝ) = bit1 r := rfl
@[simp, norm_cast] protected lemma coe_sub {r₁ r₂ : ℝ≥0} (h : r₂ ≤ r₁) :
((r₁ - r₂ : ℝ≥0) : ℝ) = r₁ - r₂ :=
max_eq_left $ le_sub.2 $ by simp [show (r₂ : ℝ) ≤ r₁, from h]
-- TODO: setup semifield!
@[simp] protected lemma coe_eq_zero (r : ℝ≥0) : ↑r = (0 : ℝ) ↔ r = 0 := by norm_cast
lemma coe_ne_zero {r : ℝ≥0} : (r : ℝ) ≠ 0 ↔ r ≠ 0 := by norm_cast
instance : comm_semiring ℝ≥0 :=
begin
refine { zero := 0, add := (+), one := 1, mul := (*), ..};
{ intros;
apply nnreal.eq;
simp [mul_comm, mul_assoc, add_comm_monoid.add, left_distrib, right_distrib,
add_comm_monoid.zero, add_comm, add_left_comm] }
end
/-- Coercion `ℝ≥0 → ℝ` as a `ring_hom`. -/
def to_real_hom : ℝ≥0 →+* ℝ :=
⟨coe, nnreal.coe_one, nnreal.coe_mul, nnreal.coe_zero, nnreal.coe_add⟩
@[simp] lemma coe_to_real_hom : ⇑to_real_hom = coe := rfl
instance : comm_group_with_zero ℝ≥0 :=
{ exists_pair_ne := ⟨0, 1, assume h, zero_ne_one $ nnreal.eq_iff.2 h⟩,
inv_zero := nnreal.eq $ show (0⁻¹ : ℝ) = 0, from inv_zero,
mul_inv_cancel := assume x h, nnreal.eq $ mul_inv_cancel $ ne_iff.2 h,
.. (by apply_instance : has_inv ℝ≥0),
.. (_ : comm_semiring ℝ≥0),
.. (_ : semiring ℝ≥0) }
@[simp, norm_cast] lemma coe_indicator {α} (s : set α) (f : α → ℝ≥0) (a : α) :
((s.indicator f a : ℝ≥0) : ℝ) = s.indicator (λ x, f x) a :=
(to_real_hom : ℝ≥0 →+ ℝ).map_indicator _ _ _
@[simp, norm_cast] protected lemma coe_div (r₁ r₂ : ℝ≥0) : ((r₁ / r₂ : ℝ≥0) : ℝ) = r₁ / r₂ := rfl
@[norm_cast] lemma coe_pow (r : ℝ≥0) (n : ℕ) : ((r^n : ℝ≥0) : ℝ) = r^n :=
to_real_hom.map_pow r n
@[norm_cast] lemma coe_list_sum (l : list ℝ≥0) :
((l.sum : ℝ≥0) : ℝ) = (l.map coe).sum :=
to_real_hom.map_list_sum l
@[norm_cast] lemma coe_list_prod (l : list ℝ≥0) :
((l.prod : ℝ≥0) : ℝ) = (l.map coe).prod :=
to_real_hom.map_list_prod l
@[norm_cast] lemma coe_multiset_sum (s : multiset ℝ≥0) :
((s.sum : ℝ≥0) : ℝ) = (s.map coe).sum :=
to_real_hom.map_multiset_sum s
@[norm_cast] lemma coe_multiset_prod (s : multiset ℝ≥0) :
((s.prod : ℝ≥0) : ℝ) = (s.map coe).prod :=
to_real_hom.map_multiset_prod s
@[norm_cast] lemma coe_sum {α} {s : finset α} {f : α → ℝ≥0} :
↑(∑ a in s, f a) = ∑ a in s, (f a : ℝ) :=
to_real_hom.map_sum _ _
@[norm_cast] lemma coe_prod {α} {s : finset α} {f : α → ℝ≥0} :
↑(∏ a in s, f a) = ∏ a in s, (f a : ℝ) :=
to_real_hom.map_prod _ _
@[norm_cast] lemma nsmul_coe (r : ℝ≥0) (n : ℕ) : ↑(n •ℕ r) = n •ℕ (r:ℝ) :=
to_real_hom.to_add_monoid_hom.map_nsmul _ _
@[simp, norm_cast] protected lemma coe_nat_cast (n : ℕ) : (↑(↑n : ℝ≥0) : ℝ) = n :=
to_real_hom.map_nat_cast n
instance : decidable_linear_order ℝ≥0 :=
decidable_linear_order.lift (coe : ℝ≥0 → ℝ) subtype.val_injective
@[norm_cast] protected lemma coe_le_coe {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) ≤ r₂ ↔ r₁ ≤ r₂ := iff.rfl
@[norm_cast] protected lemma coe_lt_coe {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) < r₂ ↔ r₁ < r₂ := iff.rfl
protected lemma coe_pos {r : ℝ≥0} : (0 : ℝ) < r ↔ 0 < r := iff.rfl
protected lemma coe_mono : monotone (coe : ℝ≥0 → ℝ) := λ _ _, nnreal.coe_le_coe.2
protected lemma of_real_mono : monotone nnreal.of_real :=
λ x y h, max_le_max h (le_refl 0)
@[simp] lemma of_real_coe {r : ℝ≥0} : nnreal.of_real r = r :=
nnreal.eq $ max_eq_left r.2
/-- `nnreal.of_real` and `coe : ℝ≥0 → ℝ` form a Galois insertion. -/
protected def gi : galois_insertion nnreal.of_real coe :=
galois_insertion.monotone_intro nnreal.coe_mono nnreal.of_real_mono
le_coe_of_real (λ _, of_real_coe)
instance : order_bot ℝ≥0 :=
{ bot := ⊥, bot_le := assume ⟨a, h⟩, h, .. nnreal.decidable_linear_order }
instance : canonically_ordered_add_monoid ℝ≥0 :=
{ add_le_add_left := assume a b h c, @add_le_add_left ℝ _ a b h c,
lt_of_add_lt_add_left := assume a b c, @lt_of_add_lt_add_left ℝ _ a b c,
le_iff_exists_add := assume ⟨a, ha⟩ ⟨b, hb⟩,
iff.intro
(assume h : a ≤ b,
⟨⟨b - a, le_sub_iff_add_le.2 $ by simp [h]⟩,
nnreal.eq $ show b = a + (b - a), by rw [add_sub_cancel'_right]⟩)
(assume ⟨⟨c, hc⟩, eq⟩, eq.symm ▸ show a ≤ a + c, from (le_add_iff_nonneg_right a).2 hc),
..nnreal.comm_semiring,
..nnreal.order_bot,
..nnreal.decidable_linear_order }
instance : distrib_lattice ℝ≥0 := by apply_instance
instance : semilattice_inf_bot ℝ≥0 :=
{ .. nnreal.order_bot, .. nnreal.distrib_lattice }
instance : semilattice_sup_bot ℝ≥0 :=
{ .. nnreal.order_bot, .. nnreal.distrib_lattice }
instance : linear_ordered_semiring ℝ≥0 :=
{ add_left_cancel := assume a b c h, nnreal.eq $
@add_left_cancel ℝ _ a b c (nnreal.eq_iff.2 h),
add_right_cancel := assume a b c h, nnreal.eq $
@add_right_cancel ℝ _ a b c (nnreal.eq_iff.2 h),
le_of_add_le_add_left := assume a b c, @le_of_add_le_add_left ℝ _ a b c,
mul_lt_mul_of_pos_left := assume a b c, @mul_lt_mul_of_pos_left ℝ _ a b c,
mul_lt_mul_of_pos_right := assume a b c, @mul_lt_mul_of_pos_right ℝ _ a b c,
zero_lt_one := @zero_lt_one ℝ _,
.. nnreal.decidable_linear_order,
.. nnreal.canonically_ordered_add_monoid,
.. nnreal.comm_semiring }
instance : linear_ordered_comm_group_with_zero ℝ≥0 :=
{ mul_le_mul_left := assume a b h c, mul_le_mul (le_refl c) h (zero_le a) (zero_le c),
zero_le_one := zero_le 1,
.. nnreal.linear_ordered_semiring,
.. nnreal.comm_group_with_zero }
instance : canonically_ordered_comm_semiring ℝ≥0 :=
{ .. nnreal.canonically_ordered_add_monoid,
.. nnreal.comm_semiring,
.. (show no_zero_divisors ℝ≥0, by apply_instance),
.. nnreal.comm_group_with_zero }
instance : densely_ordered ℝ≥0 :=
⟨assume a b (h : (a : ℝ) < b), let ⟨c, hac, hcb⟩ := dense h in
⟨⟨c, le_trans a.property $ le_of_lt $ hac⟩, hac, hcb⟩⟩
instance : no_top_order ℝ≥0 :=
⟨assume a, let ⟨b, hb⟩ := no_top (a:ℝ) in ⟨⟨b, le_trans a.property $ le_of_lt $ hb⟩, hb⟩⟩
lemma bdd_above_coe {s : set ℝ≥0} : bdd_above ((coe : nnreal → ℝ) '' s) ↔ bdd_above s :=
iff.intro
(assume ⟨b, hb⟩, ⟨nnreal.of_real b, assume ⟨y, hy⟩ hys, show y ≤ max b 0, from
le_max_left_of_le $ hb $ set.mem_image_of_mem _ hys⟩)
(assume ⟨b, hb⟩, ⟨b, assume y ⟨x, hx, eq⟩, eq ▸ hb hx⟩)
lemma bdd_below_coe (s : set ℝ≥0) : bdd_below ((coe : nnreal → ℝ) '' s) :=
⟨0, assume r ⟨q, _, eq⟩, eq ▸ q.2⟩
instance : has_Sup ℝ≥0 :=
⟨λs, ⟨Sup ((coe : nnreal → ℝ) '' s),
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, set.image_empty, real.Sup_empty] },
rcases h with ⟨⟨b, hb⟩, hbs⟩,
by_cases h' : bdd_above s,
{ exact le_cSup_of_le (bdd_above_coe.2 h') (set.mem_image_of_mem _ hbs) hb },
{ rw [real.Sup_of_not_bdd_above], rwa [bdd_above_coe] }
end⟩⟩
instance : has_Inf ℝ≥0 :=
⟨λs, ⟨Inf ((coe : nnreal → ℝ) '' s),
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, set.image_empty, real.Inf_empty] },
exact le_cInf (h.image _) (assume r ⟨q, _, eq⟩, eq ▸ q.2)
end⟩⟩
lemma coe_Sup (s : set nnreal) : (↑(Sup s) : ℝ) = Sup ((coe : nnreal → ℝ) '' s) := rfl
lemma coe_Inf (s : set nnreal) : (↑(Inf s) : ℝ) = Inf ((coe : nnreal → ℝ) '' s) := rfl
instance : conditionally_complete_linear_order_bot ℝ≥0 :=
{ Sup := Sup,
Inf := Inf,
le_cSup := assume s a hs ha, le_cSup (bdd_above_coe.2 hs) (set.mem_image_of_mem _ ha),
cSup_le := assume s a hs h,show Sup ((coe : nnreal → ℝ) '' s) ≤ a, from
cSup_le (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h hb,
cInf_le := assume s a _ has, cInf_le (bdd_below_coe s) (set.mem_image_of_mem _ has),
le_cInf := assume s a hs h, show (↑a : ℝ) ≤ Inf ((coe : nnreal → ℝ) '' s), from
le_cInf (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h hb,
cSup_empty := nnreal.eq $ by simp [coe_Sup, real.Sup_empty]; refl,
decidable_le := begin assume x y, apply classical.dec end,
.. nnreal.linear_ordered_semiring, .. lattice_of_decidable_linear_order,
.. nnreal.order_bot }
instance : archimedean nnreal :=
⟨ assume x y pos_y,
let ⟨n, hr⟩ := archimedean.arch (x:ℝ) (pos_y : (0 : ℝ) < y) in
⟨n, show (x:ℝ) ≤ (n •ℕ y : nnreal), by simp [*, -nsmul_eq_mul, nsmul_coe]⟩ ⟩
lemma le_of_forall_epsilon_le {a b : nnreal} (h : ∀ε, 0 < ε → a ≤ b + ε) : a ≤ b :=
le_of_forall_le_of_dense $ assume x hxb,
begin
rcases le_iff_exists_add.1 (le_of_lt hxb) with ⟨ε, rfl⟩,
exact h _ ((lt_add_iff_pos_right b).1 hxb)
end
lemma lt_iff_exists_rat_btwn (a b : nnreal) :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ nnreal.of_real q < b) :=
iff.intro
(assume (h : (↑a:ℝ) < (↑b:ℝ)),
let ⟨q, haq, hqb⟩ := exists_rat_btwn h in
have 0 ≤ (q : ℝ), from le_trans a.2 $ le_of_lt haq,
⟨q, rat.cast_nonneg.1 this, by simp [coe_of_real _ this, nnreal.coe_lt_coe.symm, haq, hqb]⟩)
(assume ⟨q, _, haq, hqb⟩, lt_trans haq hqb)
lemma bot_eq_zero : (⊥ : nnreal) = 0 := rfl
lemma mul_sup (a b c : ℝ≥0) : a * (b ⊔ c) = (a * b) ⊔ (a * c) :=
begin
cases le_total b c with h h,
{ simp [sup_eq_max, max_eq_right h, max_eq_right (mul_le_mul_of_nonneg_left h (zero_le a))] },
{ simp [sup_eq_max, max_eq_left h, max_eq_left (mul_le_mul_of_nonneg_left h (zero_le a))] },
end
lemma mul_finset_sup {α} {f : α → ℝ≥0} {s : finset α} (r : ℝ≥0) :
r * s.sup f = s.sup (λa, r * f a) :=
begin
refine s.induction_on _ _,
{ simp [bot_eq_zero] },
{ assume a s has ih, simp [has, ih, mul_sup], }
end
@[simp, norm_cast] lemma coe_max (x y : nnreal) :
((max x y : nnreal) : ℝ) = max (x : ℝ) (y : ℝ) :=
by { delta max, split_ifs; refl }
@[simp, norm_cast] lemma coe_min (x y : nnreal) :
((min x y : nnreal) : ℝ) = min (x : ℝ) (y : ℝ) :=
by { delta min, split_ifs; refl }
section of_real
@[simp] lemma zero_le_coe {q : nnreal} : 0 ≤ (q : ℝ) := q.2
@[simp] lemma of_real_zero : nnreal.of_real 0 = 0 :=
by simp [nnreal.of_real]; refl
@[simp] lemma of_real_one : nnreal.of_real 1 = 1 :=
by simp [nnreal.of_real, max_eq_left (zero_le_one : (0 :ℝ) ≤ 1)]; refl
@[simp] lemma of_real_pos {r : ℝ} : 0 < nnreal.of_real r ↔ 0 < r :=
by simp [nnreal.of_real, nnreal.coe_lt_coe.symm, lt_irrefl]
@[simp] lemma of_real_eq_zero {r : ℝ} : nnreal.of_real r = 0 ↔ r ≤ 0 :=
by simpa [-of_real_pos] using (not_iff_not.2 (@of_real_pos r))
lemma of_real_of_nonpos {r : ℝ} : r ≤ 0 → nnreal.of_real r = 0 :=
of_real_eq_zero.2
@[simp] lemma of_real_le_of_real_iff {r p : ℝ} (hp : 0 ≤ p) :
nnreal.of_real r ≤ nnreal.of_real p ↔ r ≤ p :=
by simp [nnreal.coe_le_coe.symm, nnreal.of_real, hp]
@[simp] lemma of_real_lt_of_real_iff' {r p : ℝ} :
nnreal.of_real r < nnreal.of_real p ↔ r < p ∧ 0 < p :=
by simp [nnreal.coe_lt_coe.symm, nnreal.of_real, lt_irrefl]
lemma of_real_lt_of_real_iff {r p : ℝ} (h : 0 < p) :
nnreal.of_real r < nnreal.of_real p ↔ r < p :=
of_real_lt_of_real_iff'.trans (and_iff_left h)
lemma of_real_lt_of_real_iff_of_nonneg {r p : ℝ} (hr : 0 ≤ r) :
nnreal.of_real r < nnreal.of_real p ↔ r < p :=
of_real_lt_of_real_iff'.trans ⟨and.left, λ h, ⟨h, lt_of_le_of_lt hr h⟩⟩
@[simp] lemma of_real_add {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
nnreal.of_real (r + p) = nnreal.of_real r + nnreal.of_real p :=
nnreal.eq $ by simp [nnreal.of_real, hr, hp, add_nonneg]
lemma of_real_add_of_real {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
nnreal.of_real r + nnreal.of_real p = nnreal.of_real (r + p) :=
(of_real_add hr hp).symm
lemma of_real_le_of_real {r p : ℝ} (h : r ≤ p) : nnreal.of_real r ≤ nnreal.of_real p :=
nnreal.of_real_mono h
lemma of_real_add_le {r p : ℝ} : nnreal.of_real (r + p) ≤ nnreal.of_real r + nnreal.of_real p :=
nnreal.coe_le_coe.1 $ max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) nnreal.zero_le_coe
lemma of_real_le_iff_le_coe {r : ℝ} {p : nnreal} : nnreal.of_real r ≤ p ↔ r ≤ ↑p :=
nnreal.gi.gc r p
lemma le_of_real_iff_coe_le {r : nnreal} {p : ℝ} (hp : 0 ≤ p) : r ≤ nnreal.of_real p ↔ ↑r ≤ p :=
by rw [← nnreal.coe_le_coe, nnreal.coe_of_real p hp]
lemma of_real_lt_iff_lt_coe {r : ℝ} {p : nnreal} (ha : 0 ≤ r) : nnreal.of_real r < p ↔ r < ↑p :=
by rw [← nnreal.coe_lt_coe, nnreal.coe_of_real r ha]
lemma lt_of_real_iff_coe_lt {r : nnreal} {p : ℝ} : r < nnreal.of_real p ↔ ↑r < p :=
begin
cases le_total 0 p,
{ rw [← nnreal.coe_lt_coe, nnreal.coe_of_real p h] },
{ rw [of_real_eq_zero.2 h], split,
intro, have := not_lt_of_le (zero_le r), contradiction,
intro rp, have : ¬(p ≤ 0) := not_le_of_lt (lt_of_le_of_lt (coe_nonneg _) rp), contradiction }
end
end of_real
section mul
lemma mul_eq_mul_left {a b c : nnreal} (h : a ≠ 0) : (a * b = a * c ↔ b = c) :=
begin
rw [← nnreal.eq_iff, ← nnreal.eq_iff, nnreal.coe_mul, nnreal.coe_mul], split,
{ exact mul_left_cancel' (mt (@nnreal.eq_iff a 0).1 h) },
{ assume h, rw [h] }
end
lemma of_real_mul {p q : ℝ} (hp : 0 ≤ p) :
nnreal.of_real (p * q) = nnreal.of_real p * nnreal.of_real q :=
begin
cases le_total 0 q with hq hq,
{ apply nnreal.eq,
have := max_eq_left (mul_nonneg hp hq),
simpa [nnreal.of_real, hp, hq, max_eq_left] },
{ have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq,
rw [of_real_eq_zero.2 hq, of_real_eq_zero.2 hpq, mul_zero] }
end
@[field_simps] theorem mul_ne_zero' {a b : nnreal} (h₁ : a ≠ 0) (h₂ : b ≠ 0) : a * b ≠ 0 :=
mul_ne_zero h₁ h₂
end mul
section sub
lemma sub_def {r p : ℝ≥0} : r - p = nnreal.of_real (r - p) := rfl
lemma sub_eq_zero {r p : ℝ≥0} (h : r ≤ p) : r - p = 0 :=
nnreal.eq $ max_eq_right $ sub_le_iff_le_add.2 $ by simpa [nnreal.coe_le_coe] using h
@[simp] lemma sub_self {r : ℝ≥0} : r - r = 0 := sub_eq_zero $ le_refl r
@[simp] lemma sub_zero {r : ℝ≥0} : r - 0 = r :=
by rw [sub_def, nnreal.coe_zero, sub_zero, nnreal.of_real_coe]
lemma sub_pos {r p : ℝ≥0} : 0 < r - p ↔ p < r :=
of_real_pos.trans $ sub_pos.trans $ nnreal.coe_lt_coe
protected lemma sub_lt_self {r p : nnreal} : 0 < r → 0 < p → r - p < r :=
assume hr hp,
begin
cases le_total r p,
{ rwa [sub_eq_zero h] },
{ rw [← nnreal.coe_lt_coe, nnreal.coe_sub h], exact sub_lt_self _ hp }
end
@[simp] lemma sub_le_iff_le_add {r p q : nnreal} : r - p ≤ q ↔ r ≤ q + p :=
match le_total p r with
| or.inl h := by rw [← nnreal.coe_le_coe, ← nnreal.coe_le_coe, nnreal.coe_sub h, nnreal.coe_add,
sub_le_iff_le_add]
| or.inr h :=
have r ≤ p + q, from le_add_right h,
by simpa [nnreal.coe_le_coe, nnreal.coe_le_coe, sub_eq_zero h, add_comm]
end
@[simp] lemma sub_le_self {r p : ℝ≥0} : r - p ≤ r :=
sub_le_iff_le_add.2 $ le_add_right $ le_refl r
lemma add_sub_cancel {r p : nnreal} : (p + r) - r = p :=
nnreal.eq $ by rw [nnreal.coe_sub, nnreal.coe_add, add_sub_cancel]; exact le_add_left (le_refl _)
lemma add_sub_cancel' {r p : nnreal} : (r + p) - r = p :=
by rw [add_comm, add_sub_cancel]
@[simp] lemma sub_add_cancel_of_le {a b : nnreal} (h : b ≤ a) : (a - b) + b = a :=
nnreal.eq $ by rw [nnreal.coe_add, nnreal.coe_sub h, sub_add_cancel]
lemma sub_sub_cancel_of_le {r p : ℝ≥0} (h : r ≤ p) : p - (p - r) = r :=
by rw [nnreal.sub_def, nnreal.sub_def, nnreal.coe_of_real _ $ sub_nonneg.2 h,
sub_sub_cancel, nnreal.of_real_coe]
lemma lt_sub_iff_add_lt {p q r : nnreal} : p < q - r ↔ p + r < q :=
begin
split,
{ assume H,
have : (((q - r) : nnreal) : ℝ) = (q : ℝ) - (r : ℝ) :=
nnreal.coe_sub (le_of_lt (sub_pos.1 (lt_of_le_of_lt (zero_le _) H))),
rwa [← nnreal.coe_lt_coe, this, lt_sub_iff_add_lt, ← nnreal.coe_add] at H },
{ assume H,
have : r ≤ q := le_trans (le_add_left (le_refl _)) (le_of_lt H),
rwa [← nnreal.coe_lt_coe, nnreal.coe_sub this, lt_sub_iff_add_lt, ← nnreal.coe_add] }
end
end sub
section inv
lemma div_def {r p : nnreal} : r / p = r * p⁻¹ := rfl
lemma sum_div {ι} (s : finset ι) (f : ι → ℝ≥0) (b : ℝ≥0) :
(∑ i in s, f i) / b = ∑ i in s, (f i / b) :=
by simp only [nnreal.div_def, finset.sum_mul]
@[simp] lemma inv_zero : (0 : nnreal)⁻¹ = 0 := nnreal.eq inv_zero
@[simp] lemma inv_eq_zero {r : nnreal} : (r : nnreal)⁻¹ = 0 ↔ r = 0 :=
inv_eq_zero
@[simp] lemma inv_pos {r : nnreal} : 0 < r⁻¹ ↔ 0 < r :=
by simp [zero_lt_iff_ne_zero]
lemma div_pos {r p : ℝ≥0} (hr : 0 < r) (hp : 0 < p) : 0 < r / p :=
mul_pos hr (inv_pos.2 hp)
@[simp] lemma inv_one : (1:ℝ≥0)⁻¹ = 1 := nnreal.eq $ inv_one
@[simp] lemma div_one {r : ℝ≥0} : r / 1 = r := by rw [div_def, inv_one, mul_one]
protected lemma mul_inv {r p : ℝ≥0} : (r * p)⁻¹ = p⁻¹ * r⁻¹ := nnreal.eq $ mul_inv_rev' _ _
protected lemma inv_pow {r : ℝ≥0} {n : ℕ} : (r^n)⁻¹ = (r⁻¹)^n :=
nnreal.eq $ by { push_cast, exact (inv_pow' _ _).symm }
@[simp] lemma inv_mul_cancel {r : ℝ≥0} (h : r ≠ 0) : r⁻¹ * r = 1 :=
nnreal.eq $ inv_mul_cancel $ mt (@nnreal.eq_iff r 0).1 h
@[simp] lemma mul_inv_cancel {r : ℝ≥0} (h : r ≠ 0) : r * r⁻¹ = 1 :=
by rw [mul_comm, inv_mul_cancel h]
@[simp] lemma div_self {r : ℝ≥0} (h : r ≠ 0) : r / r = 1 :=
mul_inv_cancel h
lemma div_self_le (r : ℝ≥0) : r / r ≤ 1 :=
if h : r = 0 then by simp [h] else by rw [div_self h]
@[simp] lemma mul_div_cancel {r p : ℝ≥0} (h : p ≠ 0) : r * p / p = r :=
by rw [div_def, mul_assoc, mul_inv_cancel h, mul_one]
@[simp] lemma mul_div_cancel' {r p : ℝ≥0} (h : r ≠ 0) : r * (p / r) = p :=
by rw [mul_comm, div_mul_cancel _ h]
@[simp] lemma inv_inv {r : ℝ≥0} : r⁻¹⁻¹ = r := nnreal.eq (inv_inv' _)
@[simp] lemma inv_le {r p : ℝ≥0} (h : r ≠ 0) : r⁻¹ ≤ p ↔ 1 ≤ r * p :=
by rw [← mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h]
lemma inv_le_of_le_mul {r p : ℝ≥0} (h : 1 ≤ r * p) : r⁻¹ ≤ p :=
by by_cases r = 0; simp [*, inv_le]
@[simp] lemma le_inv_iff_mul_le {r p : ℝ≥0} (h : p ≠ 0) : (r ≤ p⁻¹ ↔ r * p ≤ 1) :=
by rw [← mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
@[simp] lemma lt_inv_iff_mul_lt {r p : ℝ≥0} (h : p ≠ 0) : (r < p⁻¹ ↔ r * p < 1) :=
by rw [← mul_lt_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
lemma mul_le_iff_le_inv {a b r : ℝ≥0} (hr : r ≠ 0) : r * a ≤ b ↔ a ≤ r⁻¹ * b :=
have 0 < r, from lt_of_le_of_ne (zero_le r) hr.symm,
by rw [← @mul_le_mul_left _ _ a _ r this, ← mul_assoc, mul_inv_cancel hr, one_mul]
lemma le_div_iff_mul_le {a b r : ℝ≥0} (hr : r ≠ 0) : a ≤ b / r ↔ a * r ≤ b :=
by rw [div_def, mul_comm, ← mul_le_iff_le_inv hr, mul_comm]
lemma div_le_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a / r ≤ b ↔ a ≤ b * r :=
@div_le_iff ℝ _ a r b $ zero_lt_iff_ne_zero.2 hr
lemma le_of_forall_lt_one_mul_lt {x y : ℝ≥0} (h : ∀a<1, a * x ≤ y) : x ≤ y :=
le_of_forall_ge_of_dense $ assume a ha,
have hx : x ≠ 0 := zero_lt_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha),
have hx' : x⁻¹ ≠ 0, by rwa [(≠), inv_eq_zero],
have a * x⁻¹ < 1, by rwa [← lt_inv_iff_mul_lt hx', inv_inv],
have (a * x⁻¹) * x ≤ y, from h _ this,
by rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this
lemma div_add_div_same (a b c : ℝ≥0) : a / c + b / c = (a + b) / c :=
eq.symm $ right_distrib a b (c⁻¹)
lemma half_pos {a : ℝ≥0} (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two
lemma add_halves (a : ℝ≥0) : a / 2 + a / 2 = a := nnreal.eq (add_halves a)
lemma half_lt_self {a : ℝ≥0} (h : a ≠ 0) : a / 2 < a :=
by rw [← nnreal.coe_lt_coe, nnreal.coe_div]; exact
half_lt_self (bot_lt_iff_ne_bot.2 h)
lemma two_inv_lt_one : (2⁻¹:ℝ≥0) < 1 :=
by simpa [div_def] using half_lt_self zero_ne_one.symm
lemma div_lt_iff {a b c : ℝ≥0} (hc : c ≠ 0) : b / c < a ↔ b < a * c :=
begin
rw [← nnreal.coe_lt_coe, ← nnreal.coe_lt_coe, nnreal.coe_div, nnreal.coe_mul],
exact div_lt_iff (zero_lt_iff_ne_zero.mpr hc)
end
lemma div_lt_one_of_lt {a b : ℝ≥0} (h : a < b) : a / b < 1 :=
begin
rwa [div_lt_iff, one_mul],
exact ne_of_gt (lt_of_le_of_lt (zero_le _) h)
end
@[field_simps] theorem div_pow {a b : ℝ≥0} (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n :=
div_pow _ _ _
@[field_simps] lemma mul_div_assoc' (a b c : ℝ≥0) : a * (b / c) = (a * b) / c :=
by rw [div_def, div_def, mul_assoc]
@[field_simps] lemma div_add_div (a : ℝ≥0) {b : ℝ≥0} (c : ℝ≥0) {d : ℝ≥0}
(hb : b ≠ 0) (hd : d ≠ 0) : a / b + c / d = (a * d + b * c) / (b * d) :=
begin
rw ← nnreal.eq_iff,
simp only [nnreal.coe_add, nnreal.coe_div, nnreal.coe_mul],
exact div_add_div _ _ (coe_ne_zero.2 hb) (coe_ne_zero.2 hd)
end
@[field_simps] lemma inv_eq_one_div (a : ℝ≥0) : a⁻¹ = 1/a :=
by rw [div_def, one_mul]
@[field_simps] lemma div_mul_eq_mul_div (a b c : ℝ≥0) : (a / b) * c = (a * c) / b :=
by { rw [div_def, div_def], ac_refl }
@[field_simps] lemma add_div' (a b c : ℝ≥0) (hc : c ≠ 0) :
b + a / c = (b * c + a) / c :=
by simpa using div_add_div b a one_ne_zero hc
@[field_simps] lemma div_add' (a b c : ℝ≥0) (hc : c ≠ 0) :
a / c + b = (a + b * c) / c :=
by rwa [add_comm, add_div', add_comm]
lemma one_div (a : ℝ≥0) : 1 / a = a⁻¹ :=
one_mul a⁻¹
lemma one_div_div (a b : ℝ≥0) : 1 / (a / b) = b / a :=
by { rw ← nnreal.eq_iff, simp [one_div_div] }
lemma div_eq_mul_one_div (a b : ℝ≥0) : a / b = a * (1 / b) :=
by rw [div_def, div_def, one_mul]
@[field_simps] lemma div_div_eq_mul_div (a b c : ℝ≥0) : a / (b / c) = (a * c) / b :=
by { rw ← nnreal.eq_iff, simp [div_div_eq_mul_div] }
@[field_simps] lemma div_div_eq_div_mul (a b c : ℝ≥0) : (a / b) / c = a / (b * c) :=
by { rw ← nnreal.eq_iff, simp [div_div_eq_div_mul] }
@[field_simps] lemma div_eq_div_iff {a b c d : ℝ≥0} (hb : b ≠ 0) (hd : d ≠ 0) :
a / b = c / d ↔ a * d = c * b :=
div_eq_div_iff hb hd
@[field_simps] lemma div_eq_iff {a b c : ℝ≥0} (hb : b ≠ 0) : a / b = c ↔ a = c * b :=
by simpa using @div_eq_div_iff a b c 1 hb one_ne_zero
@[field_simps] lemma eq_div_iff {a b c : ℝ≥0} (hb : b ≠ 0) : c = a / b ↔ c * b = a :=
by simpa using @div_eq_div_iff c 1 a b one_ne_zero hb
end inv
section pow
theorem pow_eq_zero {a : ℝ≥0} {n : ℕ} (h : a^n = 0) : a = 0 :=
begin
rw ← nnreal.eq_iff,
rw [← nnreal.eq_iff, coe_pow] at h,
exact pow_eq_zero h
end
@[field_simps] theorem pow_ne_zero {a : ℝ≥0} (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 :=
mt pow_eq_zero h
end pow
end nnreal
|
c528d8e2dc19f5d56e45906c66e3b4dda9d3daf1 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/data/real/ennreal.lean | 185e09e860cb9caf1594e686525fbee567cf344e | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 30,802 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
Extended non-negative reals
-/
import data.real.nnreal order.bounds data.set.intervals tactic.norm_num
noncomputable theory
open classical set lattice
local attribute [instance] prop_decidable
variables {α : Type*} {β : Type*}
/-- The extended nonnegative real numbers. This is usually denoted [0, ∞],
and is relevant as the codomain of a measure. -/
def ennreal := with_top nnreal
local notation `∞` := (⊤ : ennreal)
namespace ennreal
variables {a b c d : ennreal} {r p q : nnreal}
instance : canonically_ordered_comm_semiring ennreal := by unfold ennreal; apply_instance
instance : decidable_linear_order ennreal := by unfold ennreal; apply_instance
instance : complete_linear_order ennreal := by unfold ennreal; apply_instance
instance : inhabited ennreal := ⟨0⟩
instance : densely_ordered ennreal := with_top.densely_ordered
instance : has_coe nnreal ennreal := ⟨ option.some ⟩
lemma none_eq_top : (none : ennreal) = (⊤ : ennreal) := rfl
lemma some_eq_coe (a : nnreal) : (some a : ennreal) = (↑a : ennreal) := rfl
/-- `to_nnreal x` returns `x` if it is real, otherwise 0. -/
protected def to_nnreal : ennreal → nnreal
| (some r) := r
| none := 0
/-- `to_real x` returns `x` if it is real, `0` otherwise. -/
protected def to_real (a : ennreal) : real := coe (a.to_nnreal)
/-- `of_real x` returns `x` if it is nonnegative, `0` otherwise. -/
protected def of_real (r : real) : ennreal := coe (nnreal.of_real r)
@[simp] lemma to_nnreal_coe : (r : ennreal).to_nnreal = r := rfl
@[simp] lemma coe_to_nnreal : ∀{a:ennreal}, a ≠ ∞ → ↑(a.to_nnreal) = a
| (some r) h := rfl
| none h := (h rfl).elim
@[simp] lemma of_real_to_real {a : ennreal} (h : a ≠ ∞) : ennreal.of_real (a.to_real) = a :=
by simp [ennreal.to_real, ennreal.of_real, h]
@[simp] lemma to_real_of_real {r : real} (h : 0 ≤ r) : ennreal.to_real (ennreal.of_real r) = r :=
by simp [ennreal.to_real, ennreal.of_real, nnreal.coe_of_real _ h]
lemma coe_to_nnreal_le_self : ∀{a:ennreal}, ↑(a.to_nnreal) ≤ a
| (some r) := by rw [some_eq_coe, to_nnreal_coe]; exact le_refl _
| none := le_top
lemma coe_nnreal_eq (r : nnreal) : (r : ennreal) = ennreal.of_real r :=
by { rw [ennreal.of_real, nnreal.of_real], cases r with r h, congr, dsimp, rw max_eq_left h }
lemma of_real_eq_coe_nnreal {x : real} (h : x ≥ 0) :
ennreal.of_real x = @coe nnreal ennreal _ (⟨x, h⟩ : nnreal) :=
by { rw [coe_nnreal_eq], refl }
@[simp] lemma coe_zero : ↑(0 : nnreal) = (0 : ennreal) := rfl
@[simp] lemma coe_one : ↑(1 : nnreal) = (1 : ennreal) := rfl
@[simp] lemma to_real_nonneg {a : ennreal} : 0 ≤ a.to_real := by simp [ennreal.to_real]
@[simp] lemma top_to_nnreal : ∞.to_nnreal = 0 := rfl
@[simp] lemma top_to_real : ∞.to_real = 0 := rfl
@[simp] lemma zero_to_nnreal : (0 : ennreal).to_nnreal = 0 := rfl
@[simp] lemma zero_to_real : (0 : ennreal).to_real = 0 := rfl
@[simp] lemma of_real_zero : ennreal.of_real (0 : ℝ) = 0 :=
by simp [ennreal.of_real]; refl
@[simp] lemma of_real_one : ennreal.of_real (1 : ℝ) = (1 : ennreal) :=
by simp [ennreal.of_real]
lemma forall_ennreal {p : ennreal → Prop} : (∀a, p a) ↔ (∀r:nnreal, p r) ∧ p ∞ :=
⟨assume h, ⟨assume r, h _, h _⟩,
assume ⟨h₁, h₂⟩ a, match a with some r := h₁ _ | none := h₂ end⟩
lemma to_nnreal_eq_zero_iff (x : ennreal) : x.to_nnreal = 0 ↔ x = 0 ∨ x = ⊤ :=
⟨begin
cases x,
{ simp [none_eq_top] },
{ have A : some (0:nnreal) = (0:ennreal) := rfl,
simp [ennreal.to_nnreal, A] {contextual := tt} }
end,
by intro h; cases h; simp [h]⟩
lemma to_real_eq_zero_iff (x : ennreal) : x.to_real = 0 ↔ x = 0 ∨ x = ⊤ :=
by simp [ennreal.to_real, to_nnreal_eq_zero_iff]
@[simp] lemma coe_ne_top : (r : ennreal) ≠ ∞ := with_top.coe_ne_top
@[simp] lemma top_ne_coe : ∞ ≠ (r : ennreal) := with_top.top_ne_coe
@[simp] lemma of_real_ne_top {r : ℝ} : ennreal.of_real r ≠ ∞ := by simp [ennreal.of_real]
@[simp] lemma top_ne_of_real {r : ℝ} : ∞ ≠ ennreal.of_real r := by simp [ennreal.of_real]
@[simp] lemma zero_ne_top : 0 ≠ ∞ := coe_ne_top
@[simp] lemma top_ne_zero : ∞ ≠ 0 := top_ne_coe
@[simp] lemma one_ne_top : 1 ≠ ∞ := coe_ne_top
@[simp] lemma top_ne_one : ∞ ≠ 1 := top_ne_coe
@[simp] lemma coe_eq_coe : (↑r : ennreal) = ↑q ↔ r = q := with_top.coe_eq_coe
@[simp] lemma coe_le_coe : (↑r : ennreal) ≤ ↑q ↔ r ≤ q := with_top.coe_le_coe
@[simp] lemma coe_lt_coe : (↑r : ennreal) < ↑q ↔ r < q := with_top.coe_lt_coe
@[simp] lemma coe_eq_zero : (↑r : ennreal) = 0 ↔ r = 0 := coe_eq_coe
@[simp] lemma zero_eq_coe : 0 = (↑r : ennreal) ↔ 0 = r := coe_eq_coe
@[simp] lemma coe_eq_one : (↑r : ennreal) = 1 ↔ r = 1 := coe_eq_coe
@[simp] lemma one_eq_coe : 1 = (↑r : ennreal) ↔ 1 = r := coe_eq_coe
@[simp] lemma coe_nonneg : 0 ≤ (↑r : ennreal) ↔ 0 ≤ r := coe_le_coe
@[simp] lemma coe_pos : 0 < (↑r : ennreal) ↔ 0 < r := coe_lt_coe
@[simp] lemma coe_add : ↑(r + p) = (r + p : ennreal) := with_top.coe_add
@[simp] lemma coe_mul : ↑(r * p) = (r * p : ennreal) := with_top.coe_mul
@[simp] lemma coe_bit0 : (↑(bit0 r) : ennreal) = bit0 r := coe_add
@[simp] lemma coe_bit1 : (↑(bit1 r) : ennreal) = bit1 r := by simp [bit1]
@[simp] lemma add_top : a + ∞ = ∞ := with_top.add_top
@[simp] lemma top_add : ∞ + a = ∞ := with_top.top_add
instance : is_semiring_hom (coe : nnreal → ennreal) :=
by refine_struct {..}; simp
lemma add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := with_top.add_eq_top _ _
lemma add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := with_top.add_lt_top _ _
lemma to_nnreal_add {r₁ r₂ : ennreal} (h₁ : r₁ < ⊤) (h₂ : r₂ < ⊤) :
(r₁ + r₂).to_nnreal = r₁.to_nnreal + r₂.to_nnreal :=
begin
rw [← coe_eq_coe, coe_add, coe_to_nnreal, coe_to_nnreal, coe_to_nnreal];
apply @ne_top_of_lt ennreal _ _ ⊤,
exact h₂,
exact h₁,
exact add_lt_top.2 ⟨h₁, h₂⟩
end
/- rw has trouble with the generic lt_top_iff_ne_top and bot_lt_iff_ne_bot
(contrary to erw). This is solved with the next lemmas -/
protected lemma lt_top_iff_ne_top : a < ∞ ↔ a ≠ ∞ := lt_top_iff_ne_top
protected lemma bot_lt_iff_ne_bot : 0 < a ↔ a ≠ 0 := bot_lt_iff_ne_bot
lemma mul_top : a * ∞ = (if a = 0 then 0 else ∞) :=
begin split_ifs, { simp [h] }, { exact with_top.mul_top h } end
lemma top_mul : ∞ * a = (if a = 0 then 0 else ∞) :=
begin split_ifs, { simp [h] }, { exact with_top.top_mul h } end
@[simp] lemma top_mul_top : ∞ * ∞ = ∞ := with_top.top_mul_top
lemma mul_eq_top {a b : ennreal} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0) :=
with_top.mul_eq_top_iff
lemma mul_lt_top {a b : ennreal} : a < ⊤ → b < ⊤ → a * b < ⊤ :=
by simp [ennreal.lt_top_iff_ne_top, (≠), mul_eq_top] {contextual := tt}
@[simp] lemma coe_finset_sum {s : finset α} {f : α → nnreal} : ↑(s.sum f) = (s.sum (λa, f a) : ennreal) :=
(finset.sum_hom coe).symm
@[simp] lemma coe_finset_prod {s : finset α} {f : α → nnreal} : ↑(s.prod f) = (s.prod (λa, f a) : ennreal) :=
(finset.prod_hom coe).symm
@[simp] lemma bot_eq_zero : (⊥ : ennreal) = 0 := rfl
section order
@[simp] lemma coe_lt_top : coe r < ∞ := with_top.coe_lt_top r
@[simp] lemma not_top_le_coe : ¬ (⊤:ennreal) ≤ ↑r := with_top.not_top_le_coe r
@[simp] lemma zero_lt_coe_iff : 0 < (↑p : ennreal) ↔ 0 < p := coe_lt_coe
@[simp] lemma one_le_coe_iff : (1:ennreal) ≤ ↑r ↔ 1 ≤ r := coe_le_coe
@[simp] lemma coe_le_one_iff : ↑r ≤ (1:ennreal) ↔ r ≤ 1 := coe_le_coe
@[simp] lemma coe_lt_one_iff : (↑p : ennreal) < 1 ↔ p < 1 := coe_lt_coe
@[simp] lemma one_lt_zero_iff : 1 < (↑p : ennreal) ↔ 1 < p := coe_lt_coe
@[simp] lemma coe_nat (n : nat) : ((n : nnreal) : ennreal) = n := with_top.coe_nat n
@[simp] lemma nat_ne_top (n : nat) : (n : ennreal) ≠ ⊤ := with_top.nat_ne_top n
@[simp] lemma top_ne_nat (n : nat) : (⊤ : ennreal) ≠ n := with_top.top_ne_nat n
lemma le_coe_iff : a ≤ ↑r ↔ (∃p:nnreal, a = p ∧ p ≤ r) := with_top.le_coe_iff r a
lemma coe_le_iff : ↑r ≤ a ↔ (∀p:nnreal, a = p → r ≤ p) := with_top.coe_le_iff r a
lemma lt_iff_exists_coe : a < b ↔ (∃p:nnreal, a = p ∧ ↑p < b) := with_top.lt_iff_exists_coe a b
-- TODO: move to canonically ordered semiring ...
protected lemma zero_lt_one : 0 < (1 : ennreal) := zero_lt_coe_iff.mpr zero_lt_one
@[simp] lemma not_lt_zero : ¬ a < 0 := by simp
lemma add_lt_add_iff_left : a < ⊤ → (a + c < a + b ↔ c < b) :=
with_top.add_lt_add_iff_left
lemma add_lt_add_iff_right : a < ⊤ → (c + a < b + a ↔ c < b) :=
with_top.add_lt_add_iff_right
lemma lt_add_right (ha : a < ⊤) (hb : 0 < b) : a < a + b :=
by rwa [← add_lt_add_iff_left ha, add_zero] at hb
lemma le_of_forall_epsilon_le : ∀{a b : ennreal}, (∀ε:nnreal, 0 < ε → b < ∞ → a ≤ b + ε) → a ≤ b
| a none h := le_top
| none (some a) h :=
have (⊤:ennreal) ≤ ↑a + ↑(1:nnreal), from h 1 zero_lt_one coe_lt_top,
by rw [← coe_add] at this; exact (not_top_le_coe this).elim
| (some a) (some b) h :=
by simp only [none_eq_top, some_eq_coe, coe_add.symm, coe_le_coe, coe_lt_top, true_implies_iff] at *;
exact nnreal.le_of_forall_epsilon_le h
lemma lt_iff_exists_rat_btwn :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ (nnreal.of_real q:ennreal) < b) :=
⟨λ h,
begin
rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩,
rcases dense h with ⟨c, pc, cb⟩,
rcases lt_iff_exists_coe.1 cb with ⟨r, rfl, _⟩,
rcases (nnreal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟨q, hq0, pq, qr⟩,
exact ⟨q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩
end,
λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩
lemma lt_iff_exists_real_btwn :
a < b ↔ (∃r:ℝ, 0 ≤ r ∧ a < ennreal.of_real r ∧ (ennreal.of_real r:ennreal) < b) :=
⟨λ h, let ⟨q, q0, aq, qb⟩ := ennreal.lt_iff_exists_rat_btwn.1 h in
⟨q, rat.cast_nonneg.2 q0, aq, qb⟩,
λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩
protected lemma exists_nat_gt {r : ennreal} (h : r ≠ ⊤) : ∃n:ℕ, r < n :=
begin
rcases lt_iff_exists_coe.1 (lt_top_iff_ne_top.2 h) with ⟨r, rfl, hb⟩,
rcases exists_nat_gt r with ⟨n, hn⟩,
refine ⟨n, _⟩,
rwa [← ennreal.coe_nat, ennreal.coe_lt_coe],
end
lemma add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d :=
begin
rcases dense ac with ⟨a', aa', a'c⟩,
rcases lt_iff_exists_coe.1 aa' with ⟨aR, rfl, _⟩,
rcases lt_iff_exists_coe.1 a'c with ⟨a'R, rfl, _⟩,
rcases dense bd with ⟨b', bb', b'd⟩,
rcases lt_iff_exists_coe.1 bb' with ⟨bR, rfl, _⟩,
rcases lt_iff_exists_coe.1 b'd with ⟨b'R, rfl, _⟩,
have I : ↑aR + ↑bR < ↑a'R + ↑b'R :=
begin
rw [← coe_add, ← coe_add, coe_lt_coe],
apply add_lt_add (coe_lt_coe.1 aa') (coe_lt_coe.1 bb')
end,
have J : ↑a'R + ↑b'R ≤ c + d := add_le_add' (le_of_lt a'c) (le_of_lt b'd),
apply lt_of_lt_of_le I J
end
end order
section complete_lattice
lemma coe_Sup {s : set nnreal} : bdd_above s → (↑(Sup s) : ennreal) = (⨆a∈s, ↑a) := with_top.coe_Sup
lemma coe_Inf {s : set nnreal} : s ≠ ∅ → (↑(Inf s) : ennreal) = (⨅a∈s, ↑a) := with_top.coe_Inf
@[simp] lemma top_mem_upper_bounds {s : set ennreal} : ∞ ∈ upper_bounds s :=
assume x hx, le_top
lemma coe_mem_upper_bounds {s : set nnreal} :
↑r ∈ upper_bounds ((coe : nnreal → ennreal) '' s) ↔ r ∈ upper_bounds s :=
by simp [upper_bounds, ball_image_iff, -mem_image, *] {contextual := tt}
lemma infi_ennreal {α : Type*} [complete_lattice α] {f : ennreal → α} :
(⨅n, f n) = (⨅n:nnreal, f n) ⊓ f ⊤ :=
le_antisymm
(le_inf (le_infi $ assume i, infi_le _ _) (infi_le _ _))
(le_infi $ forall_ennreal.2 ⟨assume r, inf_le_left_of_le $ infi_le _ _, inf_le_right⟩)
end complete_lattice
section mul
lemma mul_eq_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b = a * c ↔ b = c) :=
begin
cases a; cases b; cases c;
simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm,
nnreal.mul_eq_mul_left] {contextual := tt},
end
lemma mul_le_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b ≤ a * c ↔ b ≤ c) :=
begin
cases a; cases b; cases c;
simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm] {contextual := tt},
assume h, exact mul_le_mul_left (zero_lt_iff_ne_zero.2 h)
end
lemma mul_eq_zero {a b : ennreal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
canonically_ordered_comm_semiring.mul_eq_zero_iff _ _
end mul
section sub
instance : has_sub ennreal := ⟨λa b, Inf {d | a ≤ d + b}⟩
lemma coe_sub : ↑(p - r) = (↑p:ennreal) - r :=
le_antisymm
(le_Inf $ assume b (hb : ↑p ≤ b + r), coe_le_iff.2 $
by rintros d rfl; rwa [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add] at hb)
(Inf_le $ show (↑p : ennreal) ≤ ↑(p - r) + ↑r,
by rw [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add])
@[simp] lemma top_sub_coe : ∞ - ↑r = ∞ :=
top_unique $ le_Inf $ by simp [add_eq_top]
@[simp] lemma sub_eq_zero_of_le (h : a ≤ b) : a - b = 0 :=
le_antisymm (Inf_le $ le_add_left h) (zero_le _)
@[simp] lemma sub_self : a - a = 0 := sub_eq_zero_of_le $ le_refl _
@[simp] lemma zero_sub : 0 - a = 0 :=
le_antisymm (Inf_le $ zero_le _) (zero_le _)
@[simp] lemma sub_infty : a - ∞ = 0 :=
le_antisymm (Inf_le $ by simp) (zero_le _)
lemma sub_le_sub (h₁ : a ≤ b) (h₂ : d ≤ c) : a - c ≤ b - d :=
Inf_le_Inf $ assume e (h : b ≤ e + d),
calc a ≤ b : h₁
... ≤ e + d : h
... ≤ e + c : add_le_add' (le_refl _) h₂
@[simp] lemma add_sub_self : ∀{a b : ennreal}, b < ∞ → (a + b) - b = a
| a none := by simp [none_eq_top]
| none (some b) := by simp [none_eq_top, some_eq_coe]
| (some a) (some b) :=
by simp [some_eq_coe]; rw [← coe_add, ← coe_sub, coe_eq_coe, nnreal.add_sub_cancel]
@[simp] lemma add_sub_self' (h : a < ∞) : (a + b) - a = b :=
by rw [add_comm, add_sub_self h]
lemma add_left_inj (h : a < ∞) : a + b = a + c ↔ b = c :=
⟨λ e, by simpa [h] using congr_arg (λ x, x - a) e, congr_arg _⟩
lemma add_right_inj (h : a < ∞) : b + a = c + a ↔ b = c :=
by rw [add_comm, add_comm c, add_left_inj h]
@[simp] lemma sub_add_cancel_of_le : ∀{a b : ennreal}, b ≤ a → (a - b) + b = a :=
begin
simp [forall_ennreal, le_coe_iff, -add_comm] {contextual := tt},
rintros r p x rfl h,
rw [← coe_sub, ← coe_add, nnreal.sub_add_cancel_of_le h]
end
@[simp] lemma add_sub_cancel_of_le (h : b ≤ a) : b + (a - b) = a :=
by rwa [add_comm, sub_add_cancel_of_le]
lemma sub_add_self_eq_max : (a - b) + b = max a b :=
match le_total a b with
| or.inl h := by simp [h, max_eq_right]
| or.inr h := by simp [h, max_eq_left]
end
@[simp] protected lemma sub_le_iff_le_add : a - b ≤ c ↔ a ≤ c + b :=
iff.intro
(assume h : a - b ≤ c,
calc a ≤ (a - b) + b : by rw [sub_add_self_eq_max]; exact le_max_left _ _
... ≤ c + b : add_le_add' h (le_refl _))
(assume h : a ≤ c + b,
calc a - b ≤ (c + b) - b : sub_le_sub h (le_refl _)
... ≤ c : Inf_le (le_refl (c + b)))
protected lemma sub_le_of_sub_le (h : a - b ≤ c) : a - c ≤ b :=
ennreal.sub_le_iff_le_add.2 $ by { rw add_comm, exact ennreal.sub_le_iff_le_add.1 h }
protected lemma sub_lt_sub_self : a ≠ ⊤ → a ≠ 0 → 0 < b → a - b < a :=
match a, b with
| none, _ := by { have := none_eq_top, assume h, contradiction }
| (some a), none := by {intros, simp only [none_eq_top, sub_infty, zero_lt_iff_ne_zero], assumption}
| (some a), (some b) :=
begin
simp only [some_eq_coe, coe_sub.symm, coe_pos, coe_eq_zero, coe_lt_coe, ne.def],
assume h₁ h₂, apply nnreal.sub_lt_self, exact zero_lt_iff_ne_zero.2 h₂
end
end
@[simp] lemma sub_eq_zero_iff_le : a - b = 0 ↔ a ≤ b :=
by simpa [-ennreal.sub_le_iff_le_add] using @ennreal.sub_le_iff_le_add a b 0
@[simp] lemma zero_lt_sub_iff_lt : 0 < a - b ↔ b < a :=
by simpa [ennreal.bot_lt_iff_ne_bot, -sub_eq_zero_iff_le] using not_iff_not.2 (@sub_eq_zero_iff_le a b)
lemma sub_le_self (a b : ennreal) : a - b ≤ a :=
ennreal.sub_le_iff_le_add.2 $ le_add_of_nonneg_right' $ zero_le _
@[simp] lemma sub_zero : a - 0 = a :=
eq.trans (add_zero (a - 0)).symm $ by simp
lemma sub_sub_cancel (h : a < ∞) (h2 : b ≤ a) : a - (a - b) = b :=
by rw [← add_right_inj (lt_of_le_of_lt (sub_le_self _ _) h),
sub_add_cancel_of_le (sub_le_self _ _), add_sub_cancel_of_le h2]
lemma sub_left_inj {a b c : ennreal} (ha : a < ⊤) (hb : b ≤ a) (hc : c ≤ a) :
a - b = a - c ↔ b = c :=
iff.intro
begin
assume h, have : a - (a - b) = a - (a - c), rw h,
rw [sub_sub_cancel ha hb, sub_sub_cancel ha hc] at this, exact this
end
(λ h, by rw h)
end sub
section interval
variables {x y z : ennreal} {ε ε₁ ε₂ : ennreal} {s : set ennreal}
protected lemma Ico_eq_Iio : (Ico 0 y) = (Iio y) :=
ext $ assume a, iff.intro
(assume ⟨_, hx⟩, hx)
(assume hx, ⟨zero_le _, hx⟩)
lemma mem_Iio_self_add : x ≠ ⊤ → 0 < ε → x ∈ Iio (x + ε) :=
assume xt ε0, lt_add_right (by rwa lt_top_iff_ne_top) ε0
lemma not_mem_Ioo_self_sub : x = 0 → x ∉ Ioo (x - ε) y :=
assume x0, by simp [x0]
lemma mem_Ioo_self_sub_add : x ≠ ⊤ → x ≠ 0 → 0 < ε₁ → 0 < ε₂ → x ∈ Ioo (x - ε₁) (x + ε₂) :=
assume xt x0 ε0 ε0',
⟨ennreal.sub_lt_sub_self xt x0 ε0, lt_add_right (by rwa [lt_top_iff_ne_top]) ε0'⟩
end interval
section bit
@[simp] lemma bit0_inj : bit0 a = bit0 b ↔ a = b :=
⟨λh, begin
rcases (lt_trichotomy a b) with h₁| h₂| h₃,
{ exact (absurd h (ne_of_lt (add_lt_add h₁ h₁))) },
{ exact h₂ },
{ exact (absurd h.symm (ne_of_lt (add_lt_add h₃ h₃))) }
end,
λh, congr_arg _ h⟩
@[simp] lemma bit0_eq_zero_iff : bit0 a = 0 ↔ a = 0 :=
by simpa only [bit0_zero] using @bit0_inj a 0
@[simp] lemma bit0_eq_top_iff : bit0 a = ∞ ↔ a = ∞ :=
by rw [bit0, add_eq_top, or_self]
@[simp] lemma bit1_inj : bit1 a = bit1 b ↔ a = b :=
⟨λh, begin
unfold bit1 at h,
rwa [add_right_inj, bit0_inj] at h,
simp [lt_top_iff_ne_top]
end,
λh, congr_arg _ h⟩
@[simp] lemma bit1_ne_zero : bit1 a ≠ 0 :=
by unfold bit1; simp
@[simp] lemma bit1_eq_one_iff : bit1 a = 1 ↔ a = 0 :=
by simpa only [bit1_zero] using @bit1_inj a 0
@[simp] lemma bit1_eq_top_iff : bit1 a = ∞ ↔ a = ∞ :=
by unfold bit1; rw add_eq_top; simp
end bit
section inv
instance : has_inv ennreal := ⟨λa, Inf {b | 1 ≤ a * b}⟩
instance : has_div ennreal := ⟨λa b, a * b⁻¹⟩
lemma div_def : a / b = a * b⁻¹ := rfl
@[simp] lemma inv_zero : (0 : ennreal)⁻¹ = ∞ :=
show Inf {b : ennreal | 1 ≤ 0 * b} = ∞, by simp; refl
@[simp] lemma inv_top : (∞ : ennreal)⁻¹ = 0 :=
bot_unique $ le_of_forall_le_of_dense $ λ a (h : a > 0), Inf_le $ by simp [*, ne_of_gt h, top_mul]
@[simp] lemma coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ennreal) = (↑r)⁻¹ :=
le_antisymm
(le_Inf $ assume b (hb : 1 ≤ ↑r * b), coe_le_iff.2 $
by rintros b rfl; rwa [← coe_mul, ← coe_one, coe_le_coe, ← nnreal.inv_le hr] at hb)
(Inf_le $ by simp; rw [← coe_mul, nnreal.mul_inv_cancel hr]; exact le_refl 1)
@[simp] lemma coe_div (hr : r ≠ 0) : (↑(p / r) : ennreal) = p / r :=
show ↑(p * r⁻¹) = ↑p * (↑r)⁻¹, by rw [coe_mul, coe_inv hr]
@[simp] lemma inv_inv : (a⁻¹)⁻¹ = a :=
by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe,
-coe_inv, (coe_inv _).symm] at *
@[simp] lemma inv_eq_top : a⁻¹ = ∞ ↔ a = 0 :=
by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe,
-coe_inv, (coe_inv _).symm] at *
lemma inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp
@[simp] lemma inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ :=
by rw [← inv_eq_top, inv_inv]
lemma inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp
lemma le_div_iff_mul_le : ∀{b}, b ≠ 0 → b ≠ ⊤ → (a ≤ c / b ↔ a * b ≤ c)
| none h0 ht := (ht rfl).elim
| (some r) h0 ht :=
begin
have hr : r ≠ 0, from mt coe_eq_coe.2 h0,
rw [← ennreal.mul_le_mul_left h0 ht],
suffices : ↑r * a ≤ (↑r * ↑r⁻¹) * c ↔ a * ↑r ≤ c,
{ simpa [some_eq_coe, div_def, hr, mul_left_comm, mul_comm, mul_assoc] },
rw [← coe_mul, nnreal.mul_inv_cancel hr, coe_one, one_mul, mul_comm]
end
lemma div_le_iff_le_mul (hb0 : b ≠ 0) (hbt : b ≠ ⊤) : a / b ≤ c ↔ a ≤ c * b :=
suffices a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹, by simpa [div_def],
(le_div_iff_mul_le (inv_ne_zero.2 hbt) (inv_ne_top.2 hb0)).symm
lemma inv_le_iff_le_mul : (b = ⊤ → a ≠ 0) → (a = ⊤ → b ≠ 0) → (a⁻¹ ≤ b ↔ 1 ≤ a * b) :=
begin
cases a; cases b; simp [none_eq_top, some_eq_coe, mul_top, top_mul] {contextual := tt},
by_cases a = 0; simp [*, -coe_mul, coe_mul.symm, -coe_inv, (coe_inv _).symm, nnreal.inv_le]
end
@[simp] lemma le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 :=
begin
cases b, { by_cases a = 0; simp [*, none_eq_top, mul_top] },
by_cases b = 0; simp [*, some_eq_coe, le_div_iff_mul_le],
suffices : a ≤ 1 / b ↔ a * b ≤ 1, { simpa [div_def, h] },
exact le_div_iff_mul_le (mt coe_eq_coe.1 h) coe_ne_top
end
lemma mul_inv_cancel : ∀{r : ennreal}, r ≠ 0 → r ≠ ⊤ → r * r⁻¹ = 1 :=
begin
refine forall_ennreal.2 ⟨λ r, _, _⟩; simp [-coe_inv, (coe_inv _).symm] {contextual := tt},
assume h, rw [← ennreal.coe_mul, nnreal.mul_inv_cancel h, coe_one]
end
lemma mul_le_if_le_inv {a b r : ennreal} (hr₀ : r ≠ 0) (hr₁ : r ≠ ⊤) : (r * a ≤ b ↔ a ≤ r⁻¹ * b) :=
by rw [← @ennreal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, mul_inv_cancel hr₀ hr₁, one_mul]
lemma le_of_forall_lt_one_mul_lt : ∀{x y : ennreal}, (∀a<1, a * x ≤ y) → x ≤ y :=
forall_ennreal.2 $ and.intro
(assume r, forall_ennreal.2 $ and.intro
(assume q h, coe_le_coe.2 $ nnreal.le_of_forall_lt_one_mul_lt $ assume a ha,
begin rw [← coe_le_coe, coe_mul], exact h _ (coe_lt_coe.2 ha) end)
(assume h, le_top))
(assume r hr,
have ((1 / 2 : nnreal) : ennreal) * ⊤ ≤ r :=
hr _ (coe_lt_coe.2 ((@nnreal.coe_lt (1/2) 1).2 one_half_lt_one)),
have ne : ((1 / 2 : nnreal) : ennreal) ≠ 0,
begin
rw [(≠), coe_eq_zero],
refine zero_lt_iff_ne_zero.1 _,
show 0 < (1 / 2 : ℝ),
exact div_pos zero_lt_one two_pos
end,
by rwa [mul_top, if_neg ne] at this)
lemma div_add_div_same {a b c : ennreal} : a / c + b / c = (a + b) / c :=
eq.symm $ right_distrib a b (c⁻¹)
lemma div_self {a : ennreal} (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 :=
have A : 1 ≤ a / a := by simp [le_div_iff_mul_le h0 hI, le_refl],
have B : a / a ≤ 1 := by simp [div_le_iff_le_mul h0 hI, le_refl],
le_antisymm B A
lemma add_halves (a : ennreal) : a / 2 + a / 2 = a :=
have ¬((2 : nnreal) : ennreal) = (0 : nnreal) := by rw [coe_eq_coe]; norm_num,
have A : (2:ennreal) * 2⁻¹ = 1 := by rw [←div_def, div_self]; [assumption, apply coe_ne_top],
calc
a / 2 + a / 2 = (a + a) / 2 : by rw div_add_div_same
... = (a * 1 + a * 1) / 2 : by rw mul_one
... = (a * (1 + 1)) / 2 : by rw left_distrib
... = (a * 2) / 2 : by rw one_add_one_eq_two
... = (a * 2) * 2⁻¹ : by rw div_def
... = a * (2 * 2⁻¹) : by rw mul_assoc
... = a * 1 : by rw A
... = a : by rw mul_one
@[simp] lemma div_zero_iff {a b : ennreal} : a / b = 0 ↔ a = 0 ∨ b = ⊤ :=
by simp [div_def, mul_eq_zero]
@[simp] lemma div_pos_iff {a b : ennreal} : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ⊤ :=
by simp [zero_lt_iff_ne_zero, not_or_distrib]
lemma half_pos {a : ennreal} (h : 0 < a) : 0 < a / 2 :=
by simp [ne_of_gt h]
lemma half_lt_self {a : ennreal} (hz : a ≠ 0) (ht : a ≠ ⊤) : a / 2 < a :=
begin
cases a,
{ cases ht none_eq_top },
{ simp [some_eq_coe] at hz,
simpa [-coe_lt_coe, coe_div two_ne_zero'] using
coe_lt_coe.2 (nnreal.half_lt_self hz) }
end
lemma exists_inv_nat_lt {a : ennreal} (h : a ≠ 0) :
∃n:ℕ, (n:ennreal)⁻¹ < a :=
begin
rcases dense (bot_lt_iff_ne_bot.2 h) with ⟨b, bz, ba⟩,
have bz' : b ≠ 0 := bot_lt_iff_ne_bot.1 bz,
have : b⁻¹ ≠ ⊤ := by simp [bz'],
rcases ennreal.exists_nat_gt this with ⟨n, bn⟩,
have I : ((n : ℕ) : ennreal)⁻¹ ≤ b := begin
rw [ennreal.inv_le_iff_le_mul, mul_comm, ← ennreal.inv_le_iff_le_mul],
exact le_of_lt bn,
simp only [h, ennreal.nat_ne_top, forall_prop_of_false, ne.def, not_false_iff],
exact λ_, ne_bot_of_gt bn,
exact λ_, ne_bot_of_gt bn,
exact λ_, bz'
end,
exact ⟨n, lt_of_le_of_lt I ba⟩
end
end inv
section real
lemma to_real_add (ha : a ≠ ⊤) (hb : b ≠ ⊤) : (a+b).to_real = a.to_real + b.to_real :=
begin
cases a,
{ simpa [none_eq_top] using ha },
cases b,
{ simpa [none_eq_top] using hb },
refl
end
lemma of_real_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ennreal.of_real (p + q) = ennreal.of_real p + ennreal.of_real q :=
by rw [ennreal.of_real, ennreal.of_real, ennreal.of_real, ← coe_add,
coe_eq_coe, nnreal.of_real_add hp hq]
@[simp] lemma to_real_le_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real ≤ b.to_real ↔ a ≤ b :=
begin
cases a,
{ simpa [none_eq_top] using ha },
cases b,
{ simpa [none_eq_top] using hb },
simp only [ennreal.to_real, nnreal.coe_le.symm, with_top.some_le_some],
refl
end
@[simp] lemma to_real_lt_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real < b.to_real ↔ a < b :=
begin
cases a,
{ simpa [none_eq_top] using ha },
cases b,
{ simpa [none_eq_top] using hb },
rw [with_top.some_lt_some],
refl
end
lemma of_real_le_of_real {p q : ℝ} (h : p ≤ q) : ennreal.of_real p ≤ ennreal.of_real q :=
by simp [ennreal.of_real, nnreal.of_real_le_of_real h]
@[simp] lemma of_real_le_of_real_iff {p q : ℝ} (h : 0 ≤ q) : ennreal.of_real p ≤ ennreal.of_real q ↔ p ≤ q :=
by rw [ennreal.of_real, ennreal.of_real, coe_le_coe, nnreal.of_real_le_of_real_iff h]
@[simp] lemma of_real_lt_of_real_iff {p q : ℝ} (h : 0 < q) : ennreal.of_real p < ennreal.of_real q ↔ p < q :=
by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, nnreal.of_real_lt_of_real_iff h]
@[simp] lemma of_real_pos {p : ℝ} : 0 < ennreal.of_real p ↔ 0 < p :=
by simp [ennreal.of_real]
@[simp] lemma of_real_eq_zero {p : ℝ} : ennreal.of_real p = 0 ↔ p ≤ 0 :=
by simp [ennreal.of_real]
lemma of_real_le_iff_le_to_real {a : ℝ} {b : ennreal} (hb : b ≠ ⊤) :
ennreal.of_real a ≤ b ↔ a ≤ ennreal.to_real b :=
begin
rcases b,
{ have := none_eq_top, contradiction },
{ have := nnreal.of_real_le_iff_le_coe,
simpa [ennreal.of_real, ennreal.to_real, some_eq_coe] }
end
lemma of_real_lt_iff_lt_to_real {a : ℝ} {b : ennreal} (ha : a ≥ 0) (hb : b ≠ ⊤) :
ennreal.of_real a < b ↔ a < ennreal.to_real b :=
begin
rcases b,
{ have := none_eq_top, contradiction },
{ have := nnreal.of_real_lt_iff_lt_coe ha,
simpa [ennreal.of_real, ennreal.to_real, some_eq_coe] }
end
lemma le_of_real_iff_to_real_le {a : ennreal} {b : ℝ} (ha : a ≠ ⊤) (hb : b ≥ 0) :
a ≤ ennreal.of_real b ↔ ennreal.to_real a ≤ b :=
begin
rcases a,
{ have := none_eq_top, contradiction },
{ have := nnreal.le_of_real_iff_coe_le hb,
simpa [ennreal.of_real, ennreal.to_real, some_eq_coe] }
end
lemma lt_of_real_iff_to_real_lt {a : ennreal} {b : ℝ} (ha : a ≠ ⊤) :
a < ennreal.of_real b ↔ ennreal.to_real a < b :=
begin
rcases a,
{ have := none_eq_top, contradiction },
{ have := nnreal.lt_of_real_iff_coe_lt,
simpa [ennreal.of_real, ennreal.to_real, some_eq_coe] }
end
lemma of_real_mul {p q : ℝ} (hp : 0 ≤ p) :
ennreal.of_real (p * q) = (ennreal.of_real p) * (ennreal.of_real q) :=
by { simp only [ennreal.of_real, coe_mul.symm, coe_eq_coe], exact nnreal.of_real_mul hp }
lemma to_real_of_real_mul (c : ℝ) (a : ennreal) (h : c ≥ 0) :
ennreal.to_real ((ennreal.of_real c) * a) = c * ennreal.to_real a :=
begin
cases a,
{ simp only [none_eq_top, ennreal.to_real, top_to_nnreal, nnreal.coe_zero, mul_zero, mul_top],
by_cases h' : c ≤ 0,
{ rw [if_pos], { simp }, { convert of_real_zero, exact le_antisymm h' h } },
{ rw [if_neg], refl, rw [of_real_eq_zero], assumption } },
{ simp only [ennreal.to_real, ennreal.to_nnreal],
simp only [some_eq_coe, ennreal.of_real, coe_mul.symm, to_nnreal_coe, nnreal.coe_mul],
congr, apply nnreal.coe_of_real, exact h }
end
end real
section infi
variables {ι : Sort*} {f g : ι → ennreal}
lemma infi_add : infi f + a = ⨅i, f i + a :=
le_antisymm
(le_infi $ assume i, add_le_add' (infi_le _ _) $ le_refl _)
(ennreal.sub_le_iff_le_add.1 $ le_infi $ assume i, ennreal.sub_le_iff_le_add.2 $ infi_le _ _)
lemma supr_sub : (⨆i, f i) - a = (⨆i, f i - a) :=
le_antisymm
(ennreal.sub_le_iff_le_add.2 $ supr_le $ assume i, ennreal.sub_le_iff_le_add.1 $ le_supr _ i)
(supr_le $ assume i, ennreal.sub_le_sub (le_supr _ _) (le_refl a))
lemma sub_infi : a - (⨅i, f i) = (⨆i, a - f i) :=
begin
refine (eq_of_forall_ge_iff $ λ c, _),
rw [ennreal.sub_le_iff_le_add, add_comm, infi_add],
simp [ennreal.sub_le_iff_le_add]
end
lemma Inf_add {s : set ennreal} : Inf s + a = ⨅b∈s, b + a :=
by simp [Inf_eq_infi, infi_add]
lemma add_infi {a : ennreal} : a + infi f = ⨅b, a + f b :=
by rw [add_comm, infi_add]; simp
lemma infi_add_infi (h : ∀i j, ∃k, f k + g k ≤ f i + g j) : infi f + infi g = (⨅a, f a + g a) :=
suffices (⨅a, f a + g a) ≤ infi f + infi g,
from le_antisymm (le_infi $ assume a, add_le_add' (infi_le _ _) (infi_le _ _)) this,
calc (⨅a, f a + g a) ≤ (⨅ a a', f a + g a') :
le_infi $ assume a, le_infi $ assume a',
let ⟨k, h⟩ := h a a' in infi_le_of_le k h
... ≤ infi f + infi g :
by simp [add_infi, infi_add, -add_comm, -le_infi_iff]; exact le_refl _
lemma infi_sum {f : ι → α → ennreal} {s : finset α} [nonempty ι]
(h : ∀(t : finset α) (i j : ι), ∃k, ∀a∈t, f k a ≤ f i a ∧ f k a ≤ f j a) :
(⨅i, s.sum (f i)) = s.sum (λa, ⨅i, f i a) :=
finset.induction_on s (by simp) $ assume a s ha ih,
have ∀ (i j : ι), ∃ (k : ι), f k a + s.sum (f k) ≤ f i a + s.sum (f j),
from assume i j,
let ⟨k, hk⟩ := h (insert a s) i j in
⟨k, add_le_add' (hk a (finset.mem_insert_self _ _)).left $ finset.sum_le_sum $
assume a ha, (hk _ $ finset.mem_insert_of_mem ha).right⟩,
by simp [ha, ih.symm, infi_add_infi this]
end infi
section supr
lemma supr_coe_nat : (⨆n:ℕ, (n : ennreal)) = ⊤ :=
(lattice.supr_eq_top _).2 $ assume b hb, ennreal.exists_nat_gt (lt_top_iff_ne_top.1 hb)
end supr
end ennreal
|
2fda9f22a2228f7eb1f4e18e368494a930f7b869 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Meta/AppBuilder.lean | d8e5c84e8dd2d068a96552a0546f4b888ea93b02 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 23,479 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Structure
import Lean.Util.Recognizers
import Lean.Meta.SynthInstance
import Lean.Meta.Check
import Lean.Meta.DecLevel
namespace Lean.Meta
/-- Return `id e` -/
def mkId (e : Expr) : MetaM Expr := do
let type ← inferType e
let u ← getLevel type
return mkApp2 (mkConst ``id [u]) type e
/--
Given `e` s.t. `inferType e` is definitionally equal to `expectedType`, return
term `@id expectedType e`. -/
def mkExpectedTypeHint (e : Expr) (expectedType : Expr) : MetaM Expr := do
let u ← getLevel expectedType
return mkApp2 (mkConst ``id [u]) expectedType e
/-- Return `a = b`. -/
def mkEq (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getLevel aType
return mkApp3 (mkConst ``Eq [u]) aType a b
/-- Return `HEq a b`. -/
def mkHEq (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let bType ← inferType b
let u ← getLevel aType
return mkApp4 (mkConst ``HEq [u]) aType a bType b
/--
If `a` and `b` have definitionally equal types, return `Eq a b`, otherwise return `HEq a b`.
-/
def mkEqHEq (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let bType ← inferType b
let u ← getLevel aType
if (← isDefEq aType bType) then
return mkApp3 (mkConst ``Eq [u]) aType a b
else
return mkApp4 (mkConst ``HEq [u]) aType a bType b
/-- Return a proof of `a = a`. -/
def mkEqRefl (a : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getLevel aType
return mkApp2 (mkConst ``Eq.refl [u]) aType a
/-- Return a proof of `HEq a a`. -/
def mkHEqRefl (a : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getLevel aType
return mkApp2 (mkConst ``HEq.refl [u]) aType a
/-- Given `hp : P` and `nhp : Not P` returns an instance of type `e`. -/
def mkAbsurd (e : Expr) (hp hnp : Expr) : MetaM Expr := do
let p ← inferType hp
let u ← getLevel e
return mkApp4 (mkConst ``absurd [u]) p e hp hnp
/-- Given `h : False`, return an instance of type `e`. -/
def mkFalseElim (e : Expr) (h : Expr) : MetaM Expr := do
let u ← getLevel e
return mkApp2 (mkConst ``False.elim [u]) e h
private def infer (h : Expr) : MetaM Expr := do
let hType ← inferType h
whnfD hType
private def hasTypeMsg (e type : Expr) : MessageData :=
m!"{indentExpr e}\nhas type{indentExpr type}"
private def throwAppBuilderException {α} (op : Name) (msg : MessageData) : MetaM α :=
throwError "AppBuilder for '{op}', {msg}"
/-- Given `h : a = b`, returns a proof of `b = a`. -/
def mkEqSymm (h : Expr) : MetaM Expr := do
if h.isAppOf ``Eq.refl then
return h
else
let hType ← infer h
match hType.eq? with
| some (α, a, b) =>
let u ← getLevel α
return mkApp4 (mkConst ``Eq.symm [u]) α a b h
| none => throwAppBuilderException ``Eq.symm ("equality proof expected" ++ hasTypeMsg h hType)
/-- Given `h₁ : a = b` and `h₂ : b = c` returns a proof of `a = c`. -/
def mkEqTrans (h₁ h₂ : Expr) : MetaM Expr := do
if h₁.isAppOf ``Eq.refl then
return h₂
else if h₂.isAppOf ``Eq.refl then
return h₁
else
let hType₁ ← infer h₁
let hType₂ ← infer h₂
match hType₁.eq?, hType₂.eq? with
| some (α, a, b), some (_, _, c) =>
let u ← getLevel α
return mkApp6 (mkConst ``Eq.trans [u]) α a b c h₁ h₂
| none, _ => throwAppBuilderException ``Eq.trans ("equality proof expected" ++ hasTypeMsg h₁ hType₁)
| _, none => throwAppBuilderException ``Eq.trans ("equality proof expected" ++ hasTypeMsg h₂ hType₂)
/-- Given `h : HEq a b`, returns a proof of `HEq b a`. -/
def mkHEqSymm (h : Expr) : MetaM Expr := do
if h.isAppOf ``HEq.refl then
return h
else
let hType ← infer h
match hType.heq? with
| some (α, a, β, b) =>
let u ← getLevel α
return mkApp5 (mkConst ``HEq.symm [u]) α β a b h
| none =>
throwAppBuilderException ``HEq.symm ("heterogeneous equality proof expected" ++ hasTypeMsg h hType)
/-- Given `h₁ : HEq a b`, `h₂ : HEq b c`, returns a proof of `HEq a c`. -/
def mkHEqTrans (h₁ h₂ : Expr) : MetaM Expr := do
if h₁.isAppOf ``HEq.refl then
return h₂
else if h₂.isAppOf ``HEq.refl then
return h₁
else
let hType₁ ← infer h₁
let hType₂ ← infer h₂
match hType₁.heq?, hType₂.heq? with
| some (α, a, β, b), some (_, _, γ, c) =>
let u ← getLevel α
return mkApp8 (mkConst ``HEq.trans [u]) α β γ a b c h₁ h₂
| none, _ => throwAppBuilderException ``HEq.trans ("heterogeneous equality proof expected" ++ hasTypeMsg h₁ hType₁)
| _, none => throwAppBuilderException ``HEq.trans ("heterogeneous equality proof expected" ++ hasTypeMsg h₂ hType₂)
/-- Given `h : Eq a b`, returns a proof of `HEq a b`. -/
def mkEqOfHEq (h : Expr) : MetaM Expr := do
let hType ← infer h
match hType.heq? with
| some (α, a, β, b) =>
unless (← isDefEq α β) do
throwAppBuilderException ``eq_of_heq m!"heterogeneous equality types are not definitionally equal{indentExpr α}\nis not definitionally equal to{indentExpr β}"
let u ← getLevel α
return mkApp4 (mkConst ``eq_of_heq [u]) α a b h
| _ =>
throwAppBuilderException ``HEq.trans m!"heterogeneous equality proof expected{indentExpr h}"
/-- Given `f : α → β` and `h : a = b`, returns a proof of `f a = f b`.-/
def mkCongrArg (f h : Expr) : MetaM Expr := do
if h.isAppOf ``Eq.refl then
mkEqRefl (mkApp f h.appArg!)
else
let hType ← infer h
let fType ← infer f
match fType.arrow?, hType.eq? with
| some (α, β), some (_, a, b) =>
let u ← getLevel α
let v ← getLevel β
return mkApp6 (mkConst ``congrArg [u, v]) α β a b f h
| none, _ => throwAppBuilderException ``congrArg ("non-dependent function expected" ++ hasTypeMsg f fType)
| _, none => throwAppBuilderException ``congrArg ("equality proof expected" ++ hasTypeMsg h hType)
/-- Given `h : f = g` and `a : α`, returns a proof of `f a = g a`.-/
def mkCongrFun (h a : Expr) : MetaM Expr := do
if h.isAppOf ``Eq.refl then
mkEqRefl (mkApp h.appArg! a)
else
let hType ← infer h
match hType.eq? with
| some (ρ, f, g) => do
let ρ ← whnfD ρ
match ρ with
| Expr.forallE n α β _ =>
let β' := Lean.mkLambda n BinderInfo.default α β
let u ← getLevel α
let v ← getLevel (mkApp β' a)
return mkApp6 (mkConst ``congrFun [u, v]) α β' f g h a
| _ => throwAppBuilderException ``congrFun ("equality proof between functions expected" ++ hasTypeMsg h hType)
| _ => throwAppBuilderException ``congrFun ("equality proof expected" ++ hasTypeMsg h hType)
/-- Given `h₁ : f = g` and `h₂ : a = b`, returns a proof of `f a = g b`. -/
def mkCongr (h₁ h₂ : Expr) : MetaM Expr := do
if h₁.isAppOf ``Eq.refl then
mkCongrArg h₁.appArg! h₂
else if h₂.isAppOf ``Eq.refl then
mkCongrFun h₁ h₂.appArg!
else
let hType₁ ← infer h₁
let hType₂ ← infer h₂
match hType₁.eq?, hType₂.eq? with
| some (ρ, f, g), some (α, a, b) =>
let ρ ← whnfD ρ
match ρ.arrow? with
| some (_, β) => do
let u ← getLevel α
let v ← getLevel β
return mkApp8 (mkConst ``congr [u, v]) α β f g a b h₁ h₂
| _ => throwAppBuilderException ``congr ("non-dependent function expected" ++ hasTypeMsg h₁ hType₁)
| none, _ => throwAppBuilderException ``congr ("equality proof expected" ++ hasTypeMsg h₁ hType₁)
| _, none => throwAppBuilderException ``congr ("equality proof expected" ++ hasTypeMsg h₂ hType₂)
private def mkAppMFinal (methodName : Name) (f : Expr) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do
instMVars.forM fun mvarId => do
let mvarDecl ← mvarId.getDecl
let mvarVal ← synthInstance mvarDecl.type
mvarId.assign mvarVal
let result ← instantiateMVars (mkAppN f args)
if (← hasAssignableMVar result) then throwAppBuilderException methodName ("result contains metavariables" ++ indentExpr result)
return result
private partial def mkAppMArgs (f : Expr) (fType : Expr) (xs : Array Expr) : MetaM Expr :=
let rec loop (type : Expr) (i : Nat) (j : Nat) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do
if i >= xs.size then
mkAppMFinal `mkAppM f args instMVars
else match type with
| Expr.forallE n d b bi =>
let d := d.instantiateRevRange j args.size args
match bi with
| BinderInfo.implicit =>
let mvar ← mkFreshExprMVar d MetavarKind.natural n
loop b i j (args.push mvar) instMVars
| BinderInfo.strictImplicit =>
let mvar ← mkFreshExprMVar d MetavarKind.natural n
loop b i j (args.push mvar) instMVars
| BinderInfo.instImplicit =>
let mvar ← mkFreshExprMVar d MetavarKind.synthetic n
loop b i j (args.push mvar) (instMVars.push mvar.mvarId!)
| _ =>
let x := xs[i]!
let xType ← inferType x
if (← isDefEq d xType) then
loop b (i+1) j (args.push x) instMVars
else
throwAppTypeMismatch (mkAppN f args) x
| type =>
let type := type.instantiateRevRange j args.size args
let type ← whnfD type
if type.isForall then
loop type i args.size args instMVars
else
throwAppBuilderException `mkAppM m!"too many explicit arguments provided to{indentExpr f}\narguments{indentD xs}"
loop fType 0 0 #[] #[]
private def mkFun (constName : Name) : MetaM (Expr × Expr) := do
let cinfo ← getConstInfo constName
let us ← cinfo.levelParams.mapM fun _ => mkFreshLevelMVar
let f := mkConst constName us
let fType ← instantiateTypeLevelParams cinfo us
return (f, fType)
private def withAppBuilderTrace [ToMessageData α] [ToMessageData β]
(f : α) (xs : β) (k : MetaM Expr) : MetaM Expr :=
let emoji | .ok .. => checkEmoji | .error .. => crossEmoji
withTraceNode `Meta.appBuilder (return m!"{emoji ·} f: {f}, xs: {xs}") do
try
let res ← k
trace[Meta.appBuilder.result] res
pure res
catch ex =>
trace[Meta.appBuilder.error] ex.toMessageData
throw ex
/--
Return the application `constName xs`.
It tries to fill the implicit arguments before the last element in `xs`.
Remark:
``mkAppM `arbitrary #[α]`` returns `@arbitrary.{u} α` without synthesizing
the implicit argument occurring after `α`.
Given a `x : (([Decidable p] → Bool) × Nat`, ``mkAppM `Prod.fst #[x]`` returns `@Prod.fst ([Decidable p] → Bool) Nat x`
-/
def mkAppM (constName : Name) (xs : Array Expr) : MetaM Expr := do
withAppBuilderTrace constName xs do withNewMCtxDepth do
let (f, fType) ← mkFun constName
mkAppMArgs f fType xs
/-- Similar to `mkAppM`, but takes an `Expr` instead of a constant name. -/
def mkAppM' (f : Expr) (xs : Array Expr) : MetaM Expr := do
let fType ← inferType f
withAppBuilderTrace f xs do withNewMCtxDepth do
mkAppMArgs f fType xs
private partial def mkAppOptMAux (f : Expr) (xs : Array (Option Expr)) : Nat → Array Expr → Nat → Array MVarId → Expr → MetaM Expr
| i, args, j, instMVars, Expr.forallE n d b bi => do
let d := d.instantiateRevRange j args.size args
if h : i < xs.size then
match xs.get ⟨i, h⟩ with
| none =>
match bi with
| BinderInfo.instImplicit => do
let mvar ← mkFreshExprMVar d MetavarKind.synthetic n
mkAppOptMAux f xs (i+1) (args.push mvar) j (instMVars.push mvar.mvarId!) b
| _ => do
let mvar ← mkFreshExprMVar d MetavarKind.natural n
mkAppOptMAux f xs (i+1) (args.push mvar) j instMVars b
| some x =>
let xType ← inferType x
if (← isDefEq d xType) then
mkAppOptMAux f xs (i+1) (args.push x) j instMVars b
else
throwAppTypeMismatch (mkAppN f args) x
else
mkAppMFinal `mkAppOptM f args instMVars
| i, args, j, instMVars, type => do
let type := type.instantiateRevRange j args.size args
let type ← whnfD type
if type.isForall then
mkAppOptMAux f xs i args args.size instMVars type
else if i == xs.size then
mkAppMFinal `mkAppOptM f args instMVars
else do
let xs : Array Expr := xs.foldl (fun r x? => match x? with | none => r | some x => r.push x) #[]
throwAppBuilderException `mkAppOptM ("too many arguments provided to" ++ indentExpr f ++ Format.line ++ "arguments" ++ xs)
/--
Similar to `mkAppM`, but it allows us to specify which arguments are provided explicitly using `Option` type.
Example:
Given `Pure.pure {m : Type u → Type v} [Pure m] {α : Type u} (a : α) : m α`,
```
mkAppOptM `Pure.pure #[m, none, none, a]
```
returns a `Pure.pure` application if the instance `Pure m` can be synthesized, and the universe match.
Note that,
```
mkAppM `Pure.pure #[a]
```
fails because the only explicit argument `(a : α)` is not sufficient for inferring the remaining arguments,
we would need the expected type. -/
def mkAppOptM (constName : Name) (xs : Array (Option Expr)) : MetaM Expr := do
withAppBuilderTrace constName xs do withNewMCtxDepth do
let (f, fType) ← mkFun constName
mkAppOptMAux f xs 0 #[] 0 #[] fType
/-- Similar to `mkAppOptM`, but takes an `Expr` instead of a constant name -/
def mkAppOptM' (f : Expr) (xs : Array (Option Expr)) : MetaM Expr := do
let fType ← inferType f
withAppBuilderTrace f xs do withNewMCtxDepth do
mkAppOptMAux f xs 0 #[] 0 #[] fType
def mkEqNDRec (motive h1 h2 : Expr) : MetaM Expr := do
if h2.isAppOf ``Eq.refl then
return h1
else
let h2Type ← infer h2
match h2Type.eq? with
| none => throwAppBuilderException ``Eq.ndrec ("equality proof expected" ++ hasTypeMsg h2 h2Type)
| some (α, a, b) =>
let u2 ← getLevel α
let motiveType ← infer motive
match motiveType with
| Expr.forallE _ _ (Expr.sort u1) _ =>
return mkAppN (mkConst ``Eq.ndrec [u1, u2]) #[α, a, motive, h1, b, h2]
| _ => throwAppBuilderException ``Eq.ndrec ("invalid motive" ++ indentExpr motive)
def mkEqRec (motive h1 h2 : Expr) : MetaM Expr := do
if h2.isAppOf ``Eq.refl then
return h1
else
let h2Type ← infer h2
match h2Type.eq? with
| none => throwAppBuilderException ``Eq.rec ("equality proof expected" ++ indentExpr h2)
| some (α, a, b) =>
let u2 ← getLevel α
let motiveType ← infer motive
match motiveType with
| Expr.forallE _ _ (Expr.forallE _ _ (Expr.sort u1) _) _ =>
return mkAppN (mkConst ``Eq.rec [u1, u2]) #[α, a, motive, h1, b, h2]
| _ =>
throwAppBuilderException ``Eq.rec ("invalid motive" ++ indentExpr motive)
def mkEqMP (eqProof pr : Expr) : MetaM Expr :=
mkAppM ``Eq.mp #[eqProof, pr]
def mkEqMPR (eqProof pr : Expr) : MetaM Expr :=
mkAppM ``Eq.mpr #[eqProof, pr]
def mkNoConfusion (target : Expr) (h : Expr) : MetaM Expr := do
let type ← inferType h
let type ← whnf type
match type.eq? with
| none => throwAppBuilderException `noConfusion ("equality expected" ++ hasTypeMsg h type)
| some (α, a, b) =>
let α ← whnfD α
matchConstInduct α.getAppFn (fun _ => throwAppBuilderException `noConfusion ("inductive type expected" ++ indentExpr α)) fun v us => do
let u ← getLevel target
return mkAppN (mkConst (Name.mkStr v.name "noConfusion") (u :: us)) (α.getAppArgs ++ #[target, a, b, h])
/-- Given a `monad` and `e : α`, makes `pure e`.-/
def mkPure (monad : Expr) (e : Expr) : MetaM Expr :=
mkAppOptM ``Pure.pure #[monad, none, none, e]
/--
`mkProjection s fieldName` return an expression for accessing field `fieldName` of the structure `s`.
Remark: `fieldName` may be a subfield of `s`. -/
partial def mkProjection (s : Expr) (fieldName : Name) : MetaM Expr := do
let type ← inferType s
let type ← whnf type
match type.getAppFn with
| Expr.const structName us =>
let env ← getEnv
unless isStructure env structName do
throwAppBuilderException `mkProjection ("structure expected" ++ hasTypeMsg s type)
match getProjFnForField? env structName fieldName with
| some projFn =>
let params := type.getAppArgs
return mkApp (mkAppN (mkConst projFn us) params) s
| none =>
let fields := getStructureFields env structName
let r? ← fields.findSomeM? fun fieldName' => do
match isSubobjectField? env structName fieldName' with
| none => pure none
| some _ =>
let parent ← mkProjection s fieldName'
(do let r ← mkProjection parent fieldName; return some r)
<|>
pure none
match r? with
| some r => pure r
| none => throwAppBuilderException `mkProjectionn ("invalid field name '" ++ toString fieldName ++ "' for" ++ hasTypeMsg s type)
| _ => throwAppBuilderException `mkProjectionn ("structure expected" ++ hasTypeMsg s type)
private def mkListLitAux (nil : Expr) (cons : Expr) : List Expr → Expr
| [] => nil
| x::xs => mkApp (mkApp cons x) (mkListLitAux nil cons xs)
def mkListLit (type : Expr) (xs : List Expr) : MetaM Expr := do
let u ← getDecLevel type
let nil := mkApp (mkConst ``List.nil [u]) type
match xs with
| [] => return nil
| _ =>
let cons := mkApp (mkConst ``List.cons [u]) type
return mkListLitAux nil cons xs
def mkArrayLit (type : Expr) (xs : List Expr) : MetaM Expr := do
let u ← getDecLevel type
let listLit ← mkListLit type xs
return mkApp (mkApp (mkConst ``List.toArray [u]) type) listLit
def mkSorry (type : Expr) (synthetic : Bool) : MetaM Expr := do
let u ← getLevel type
return mkApp2 (mkConst ``sorryAx [u]) type (toExpr synthetic)
/-- Return `Decidable.decide p` -/
def mkDecide (p : Expr) : MetaM Expr :=
mkAppOptM ``Decidable.decide #[p, none]
/-- Return a proof for `p : Prop` using `decide p` -/
def mkDecideProof (p : Expr) : MetaM Expr := do
let decP ← mkDecide p
let decEqTrue ← mkEq decP (mkConst ``Bool.true)
let h ← mkEqRefl (mkConst ``Bool.true)
let h ← mkExpectedTypeHint h decEqTrue
mkAppM ``of_decide_eq_true #[h]
/-- Return `a < b` -/
def mkLt (a b : Expr) : MetaM Expr :=
mkAppM ``LT.lt #[a, b]
/-- Return `a <= b` -/
def mkLe (a b : Expr) : MetaM Expr :=
mkAppM ``LE.le #[a, b]
/-- Return `Inhabited.default α` -/
def mkDefault (α : Expr) : MetaM Expr :=
mkAppOptM ``Inhabited.default #[α, none]
/-- Return `@Classical.ofNonempty α _` -/
def mkOfNonempty (α : Expr) : MetaM Expr := do
mkAppOptM ``Classical.ofNonempty #[α, none]
/-- Return `sorryAx type` -/
def mkSyntheticSorry (type : Expr) : MetaM Expr :=
return mkApp2 (mkConst ``sorryAx [← getLevel type]) type (mkConst ``Bool.true)
/-- Return `funext h` -/
def mkFunExt (h : Expr) : MetaM Expr :=
mkAppM ``funext #[h]
/-- Return `propext h` -/
def mkPropExt (h : Expr) : MetaM Expr :=
mkAppM ``propext #[h]
/-- Return `let_congr h₁ h₂` -/
def mkLetCongr (h₁ h₂ : Expr) : MetaM Expr :=
mkAppM ``let_congr #[h₁, h₂]
/-- Return `let_val_congr b h` -/
def mkLetValCongr (b h : Expr) : MetaM Expr :=
mkAppM ``let_val_congr #[b, h]
/-- Return `let_body_congr a h` -/
def mkLetBodyCongr (a h : Expr) : MetaM Expr :=
mkAppM ``let_body_congr #[a, h]
/-- Return `of_eq_true h` -/
def mkOfEqTrue (h : Expr) : MetaM Expr :=
mkAppM ``of_eq_true #[h]
/-- Return `eq_true h` -/
def mkEqTrue (h : Expr) : MetaM Expr :=
mkAppM ``eq_true #[h]
/--
Return `eq_false h`
`h` must have type definitionally equal to `¬ p` in the current
reducibility setting. -/
def mkEqFalse (h : Expr) : MetaM Expr :=
mkAppM ``eq_false #[h]
/--
Return `eq_false' h`
`h` must have type definitionally equal to `p → False` in the current
reducibility setting. -/
def mkEqFalse' (h : Expr) : MetaM Expr :=
mkAppM ``eq_false' #[h]
def mkImpCongr (h₁ h₂ : Expr) : MetaM Expr :=
mkAppM ``implies_congr #[h₁, h₂]
def mkImpCongrCtx (h₁ h₂ : Expr) : MetaM Expr :=
mkAppM ``implies_congr_ctx #[h₁, h₂]
def mkImpDepCongrCtx (h₁ h₂ : Expr) : MetaM Expr :=
mkAppM ``implies_dep_congr_ctx #[h₁, h₂]
def mkForallCongr (h : Expr) : MetaM Expr :=
mkAppM ``forall_congr #[h]
/-- Return instance for `[Monad m]` if there is one -/
def isMonad? (m : Expr) : MetaM (Option Expr) :=
try
let monadType ← mkAppM `Monad #[m]
let result ← trySynthInstance monadType
match result with
| LOption.some inst => pure inst
| _ => pure none
catch _ =>
pure none
/-- Return `(n : type)`, a numeric literal of type `type`. The method fails if we don't have an instance `OfNat type n` -/
def mkNumeral (type : Expr) (n : Nat) : MetaM Expr := do
let u ← getDecLevel type
let inst ← synthInstance (mkApp2 (mkConst ``OfNat [u]) type (mkRawNatLit n))
return mkApp3 (mkConst ``OfNat.ofNat [u]) type (mkRawNatLit n) inst
/--
Return `a op b`, where `op` has name `opName` and is implemented using the typeclass `className`.
This method assumes `a` and `b` have the same type, and typeclass `className` is heterogeneous.
Examples of supported clases: `HAdd`, `HSub`, `HMul`.
We use heterogeneous operators to ensure we have a uniform representation.
-/
private def mkBinaryOp (className : Name) (opName : Name) (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getDecLevel aType
let inst ← synthInstance (mkApp3 (mkConst className [u, u, u]) aType aType aType)
return mkApp6 (mkConst opName [u, u, u]) aType aType aType inst a b
/-- Return `a + b` using a heterogeneous `+`. This method assumes `a` and `b` have the same type. -/
def mkAdd (a b : Expr) : MetaM Expr := mkBinaryOp ``HAdd ``HAdd.hAdd a b
/-- Return `a - b` using a heterogeneous `-`. This method assumes `a` and `b` have the same type. -/
def mkSub (a b : Expr) : MetaM Expr := mkBinaryOp ``HSub ``HSub.hSub a b
/-- Return `a * b` using a heterogeneous `*`. This method assumes `a` and `b` have the same type. -/
def mkMul (a b : Expr) : MetaM Expr := mkBinaryOp ``HMul ``HMul.hMul a b
/--
Return `a r b`, where `r` has name `rName` and is implemented using the typeclass `className`.
This method assumes `a` and `b` have the same type.
Examples of supported clases: `LE` and `LT`.
We use heterogeneous operators to ensure we have a uniform representation.
-/
private def mkBinaryRel (className : Name) (rName : Name) (a b : Expr) : MetaM Expr := do
let aType ← inferType a
let u ← getDecLevel aType
let inst ← synthInstance (mkApp (mkConst className [u]) aType)
return mkApp4 (mkConst rName [u]) aType inst a b
/-- Return `a ≤ b`. This method assumes `a` and `b` have the same type. -/
def mkLE (a b : Expr) : MetaM Expr := mkBinaryRel ``LE ``LE.le a b
/-- Return `a < b`. This method assumes `a` and `b` have the same type. -/
def mkLT (a b : Expr) : MetaM Expr := mkBinaryRel ``LT ``LT.lt a b
builtin_initialize do
registerTraceClass `Meta.appBuilder
registerTraceClass `Meta.appBuilder.result (inherited := true)
registerTraceClass `Meta.appBuilder.error (inherited := true)
end Lean.Meta
|
5b168ab8335745078c532933d5ed1256362c0128 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/ptst.lean | af00782a25f020e07db3d7ed4e1e61d7e773271e | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 108 | lean | import data.nat logic data.prod
open prod nat
-- Test tuple notation
check ((3:nat), false, (1:num), true)
|
b1240acb8037dd3de0495dee4e57e364c6fcec6c | c777c32c8e484e195053731103c5e52af26a25d1 | /counterexamples/map_floor.lean | b1c262d6d780c1976627ae779deace871677b793 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 4,685 | lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import algebra.order.hom.ring
import data.polynomial.reverse
/-!
# Floors and ceils aren't preserved under ordered ring homomorphisms
Intuitively, if `f : α → β` is an ordered ring homomorphism, then floors and ceils should be
preserved by `f` because:
* `f` preserves the naturals/integers in `α` and `β` because it's a ring hom.
* `f` preserves what's between `n` and `n + 1` because it's monotone.
However, there is a catch. Potentially something whose floor was `n` could
get mapped to `n + 1`, and this has floor `n + 1`, not `n`. Note that this is at most an off by one
error.
This pathology disappears if you require `f` to be strictly monotone or `α` to be archimedean.
## The counterexample
Consider `ℤ[ε]` (`int_with_epsilons`), the integers with infinitesimals adjoined. This is a linearly
ordered commutative floor ring (`int_with_epsilons.linear_ordered_comm_ring`,
`int_with_epsilons.floor_ring`).
The map `f : ℤ[ε] → ℤ` that forgets about the epsilons (`int_with_epsilons.forget_epsilons`) is an
ordered ring homomorphism.
But it does not preserve floors (nor ceils) as `⌊-ε⌋ = -1` while `⌊f (-ε)⌋ = ⌊0⌋ = 0`
(`int_with_epsilons.forget_epsilons_floor_lt`, `int_with_epsilons.lt_forget_epsilons_ceil`).
-/
noncomputable theory
open function int polynomial
open_locale polynomial
/-- The integers with infinitesimals adjoined. -/
@[derive [comm_ring, nontrivial, inhabited]] def int_with_epsilon := ℤ[X]
local notation `ℤ[ε]` := int_with_epsilon
local notation `ε` := (X : ℤ[ε])
namespace int_with_epsilon
instance : linear_order ℤ[ε] := linear_order.lift' (to_lex ∘ coeff) coeff_injective
instance : ordered_add_comm_group ℤ[ε] :=
by refine (to_lex.injective.comp coeff_injective).ordered_add_comm_group _ _ _ _ _ _ _;
refl <|> intros; ext; simp [←nsmul_eq_mul, ←zsmul_eq_mul]
lemma pos_iff {p : ℤ[ε]} : 0 < p ↔ 0 < p.trailing_coeff :=
begin
rw trailing_coeff,
refine ⟨_, λ h,
⟨p.nat_trailing_degree, λ m hm, (coeff_eq_zero_of_lt_nat_trailing_degree hm).symm, h⟩⟩,
rintro ⟨n, hn⟩,
convert hn.2,
exact (nat_trailing_degree_le_of_ne_zero hn.2.ne').antisymm
(le_nat_trailing_degree (by { rintro rfl, cases hn.2.false }) $ λ m hm, (hn.1 _ hm).symm),
end
instance : linear_ordered_comm_ring ℤ[ε] :=
{ zero_le_one := or.inr ⟨0, by simp⟩,
mul_pos := λ p q, by { simp_rw [pos_iff, trailing_coeff_mul], exact mul_pos },
..int_with_epsilon.linear_order, ..int_with_epsilon.comm_ring,
..int_with_epsilon.ordered_add_comm_group, ..int_with_epsilon.nontrivial }
instance : floor_ring ℤ[ε] :=
floor_ring.of_floor _ (λ p, if (p.coeff 0 : ℤ[ε]) ≤ p then p.coeff 0 else p.coeff 0 - 1) $ λ p q,
begin
simp_rw [←not_lt, not_iff_not],
split,
{ split_ifs,
{ rintro ⟨_ | n, hn⟩,
{ refine (sub_one_lt _).trans _,
simpa using hn },
{ dsimp at hn,
simp [hn.1 _ n.zero_lt_succ] } },
{ exact λ h', cast_lt.1 ((not_lt.1 h).trans_lt h') } },
{ split_ifs,
{ exact λ h', h.trans_le (cast_le.2 $ sub_one_lt_iff.1 h') },
{ exact λ h', ⟨0, by simpa using h'⟩ } }
end
/-- The ordered ring homomorphisms from `ℤ[ε]` to `ℤ` that "forgets" the `ε`s. -/
def forget_epsilons : ℤ[ε] →+*o ℤ :=
{ to_fun := λ p, coeff p 0,
map_zero' := coeff_zero _,
map_one' := coeff_one_zero,
map_add' := λ _ _, coeff_add _ _ _,
map_mul' := mul_coeff_zero,
monotone' := monotone_iff_forall_lt.2 begin
rintro p q ⟨n, hn⟩,
cases n,
{ exact hn.2.le },
{ exact (hn.1 _ n.zero_lt_succ).le }
end }
@[simp] lemma forget_epsilons_apply (p : ℤ[ε]) : forget_epsilons p = coeff p 0 := rfl
/-- The floor of `n - ε` is `n - 1` but its image under `forget_epsilons` is `n`, whose floor is
itself. -/
lemma forget_epsilons_floor_lt (n : ℤ) :
forget_epsilons ⌊(n - ε : ℤ[ε])⌋ < ⌊forget_epsilons (n - ε)⌋ :=
begin
suffices : ⌊(n - ε : ℤ[ε])⌋ = n - 1,
{ simp [this] },
have : (0 : ℤ[ε]) < ε := ⟨1, by simp⟩,
exact (if_neg $ by simp [this]).trans (by simp),
end
/-- The ceil of `n + ε` is `n + 1` but its image under `forget_epsilons` is `n`, whose ceil is
itself. -/
lemma lt_forget_epsilons_ceil (n : ℤ) :
⌈forget_epsilons (n + ε)⌉ < forget_epsilons ⌈(n + ε : ℤ[ε])⌉ :=
begin
rw [←neg_lt_neg_iff, ←map_neg, ←cast_neg, ←floor_neg, ←floor_neg, ←map_neg, neg_add', ←cast_neg],
exact forget_epsilons_floor_lt _,
end
end int_with_epsilon
|
00d65f0db288b472bb6c6a1fbb04993ff54efc39 | e42ba0bcfa11e5be053e2ce1ce1f49f027680525 | /src/separation/heap/default.lean | 17635a7945fbcdc59980ccc62af81e98096f6ebd | [] | no_license | unitb/separation-logic | 8e17c5b466f86caa143265f4c04c78eec9d3c3b8 | bdde6fc8f16fd43932aea9827d6c63cadd91c2e8 | refs/heads/master | 1,540,936,751,653 | 1,535,050,181,000 | 1,535,056,425,000 | 109,461,809 | 6 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 93 | lean |
import separation.heap.basic
import separation.heap.lemmas
import separation.heap.instances
|
246a00f96e2d2e2b47ac0cdb20087275396c6354 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/data/equiv/local_equiv.lean | 03443468209606ef8cfe91243a4856b9ef243d3c | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 24,835 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import data.equiv.basic
/-!
# Local equivalences
This files defines equivalences between subsets of given types.
An element `e` of `local_equiv α β` is made of two maps `e.to_fun` and `e.inv_fun` respectively
from α to β and from β to α (just like equivs), which are inverse to each other on the subsets
`e.source` and `e.target` of respectively α and β.
They are designed in particular to define charts on manifolds.
The main functionality is `e.trans f`, which composes the two local equivalences by restricting
the source and target to the maximal set where the composition makes sense.
As for equivs, we register a coercion to functions and use it in our simp normal form: we write
`e x` and `e.symm y` instead of `e.to_fun x` and `e.inv_fun y`.
## Main definitions
`equiv.to_local_equiv`: associating a local equiv to an equiv, with source = target = univ
`local_equiv.symm` : the inverse of a local equiv
`local_equiv.trans` : the composition of two local equivs
`local_equiv.refl` : the identity local equiv
`local_equiv.of_set` : the identity on a set `s`
`eq_on_source` : equivalence relation describing the "right" notion of equality for local
equivs (see below in implementation notes)
## Implementation notes
There are at least three possible implementations of local equivalences:
* equivs on subtypes
* pairs of functions taking values in `option α` and `option β`, equal to none where the local
equivalence is not defined
* pairs of functions defined everywhere, keeping the source and target as additional data
Each of these implementations has pros and cons.
* When dealing with subtypes, one still need to define additional API for composition and
restriction of domains. Checking that one always belongs to the right subtype makes things very
tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for
instance).
* With option-valued functions, the composition is very neat (it is just the usual composition, and
the domain is restricted automatically). These are implemented in `pequiv.lean`. For manifolds,
where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of
overhead as one would need to extend all classes of smoothness to option-valued maps.
* The local_equiv version as explained above is easier to use for manifolds. The drawback is that
there is extra useless data (the values of `to_fun` and `inv_fun` outside of `source` and `target`).
In particular, the equality notion between local equivs is not "the right one", i.e., coinciding
source and target and equality there. Moreover, there are no local equivs in this sense between
an empty type and a nonempty type. Since empty types are not that useful, and since one almost never
needs to talk about equal local equivs, this is not an issue in practice.
Still, we introduce an equivalence relation `eq_on_source` that captures this right notion of
equality, and show that many properties are invariant under this equivalence relation.
-/
mk_simp_attribute mfld_simps "The simpset `mfld_simps` records several simp lemmas that are
especially useful in manifolds. It is a subset of the whole set of simp lemmas, but it makes it
possible to have quicker proofs (when used with `squeeze_simp` or `simp only`) while retaining
readability.
The typical use case is the following, in a file on manifolds:
If `simp [foo, bar]` is slow, replace it with `squeeze_simp [foo, bar] with mfld_simps` and paste
its output. The list of lemmas should be reasonable (contrary to the output of
`squeeze_simp [foo, bar]` which might contain tens of lemmas), and the outcome should be quick
enough.
"
-- register in the simpset `mfld_simps` several lemmas that are often useful when dealing
-- with manifolds
attribute [mfld_simps] id.def function.comp.left_id set.mem_set_of_eq set.image_eq_empty
set.univ_inter set.preimage_univ set.prod_mk_mem_set_prod_eq and_true set.mem_univ
set.mem_image_of_mem true_and set.mem_inter_eq set.mem_preimage function.comp_app
set.inter_subset_left set.mem_prod set.range_id and_self set.mem_range_self
eq_self_iff_true forall_const forall_true_iff set.inter_univ set.preimage_id function.comp.right_id
not_false_iff and_imp set.prod_inter_prod set.univ_prod_univ true_or or_true prod.map_mk
set.preimage_inter
namespace tactic.interactive
/-- A very basic tactic to show that sets showing up in manifolds coincide or are included in
one another. -/
meta def mfld_set_tac : tactic unit := do
goal ← tactic.target,
match goal with
| `(%%e₁ = %%e₂) :=
`[ext my_y,
split;
{ assume h_my_y,
try { simp only [*, -h_my_y] with mfld_simps at h_my_y },
simp only [*] with mfld_simps }]
| `(%%e₁ ⊆ %%e₂) :=
`[assume my_y h_my_y,
try { simp only [*, -h_my_y] with mfld_simps at h_my_y },
simp only [*] with mfld_simps]
| _ := tactic.fail "goal should be an equality or an inclusion"
end
end tactic.interactive
open function set
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- Local equivalence between subsets `source` and `target` of α and β respectively. The (global)
maps `to_fun : α → β` and `inv_fun : β → α` map `source` to `target` and conversely, and are inverse
to each other there. The values of `to_fun` outside of `source` and of `inv_fun` outside of `target`
are irrelevant. -/
@[nolint has_inhabited_instance]
structure local_equiv (α : Type*) (β : Type*) :=
(to_fun : α → β)
(inv_fun : β → α)
(source : set α)
(target : set β)
(map_source' : ∀{x}, x ∈ source → to_fun x ∈ target)
(map_target' : ∀{x}, x ∈ target → inv_fun x ∈ source)
(left_inv' : ∀{x}, x ∈ source → inv_fun (to_fun x) = x)
(right_inv' : ∀{x}, x ∈ target → to_fun (inv_fun x) = x)
/-- Associating a local_equiv to an equiv-/
def equiv.to_local_equiv (e : equiv α β) : local_equiv α β :=
{ to_fun := e.to_fun,
inv_fun := e.inv_fun,
source := univ,
target := univ,
map_source' := λx hx, mem_univ _,
map_target' := λy hy, mem_univ _,
left_inv' := λx hx, e.left_inv x,
right_inv' := λx hx, e.right_inv x }
namespace local_equiv
variables (e : local_equiv α β) (e' : local_equiv β γ)
/-- The inverse of a local equiv -/
protected def symm : local_equiv β α :=
{ to_fun := e.inv_fun,
inv_fun := e.to_fun,
source := e.target,
target := e.source,
map_source' := e.map_target',
map_target' := e.map_source',
left_inv' := e.right_inv',
right_inv' := e.left_inv' }
instance : has_coe_to_fun (local_equiv α β) := ⟨_, local_equiv.to_fun⟩
@[simp, mfld_simps] theorem coe_mk (f : α → β) (g s t ml mr il ir) :
(local_equiv.mk f g s t ml mr il ir : α → β) = f := rfl
@[simp, mfld_simps] theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) :
((local_equiv.mk f g s t ml mr il ir).symm : β → α) = g := rfl
@[simp, mfld_simps] lemma to_fun_as_coe : e.to_fun = e := rfl
@[simp, mfld_simps] lemma inv_fun_as_coe : e.inv_fun = e.symm := rfl
@[simp, mfld_simps] lemma map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target :=
e.map_source' h
protected lemma maps_to : maps_to e e.source e.target := λ _, e.map_source
@[simp, mfld_simps] lemma map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source :=
e.map_target' h
lemma symm_maps_to : maps_to e.symm e.target e.source := e.symm.maps_to
@[simp, mfld_simps] lemma left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x :=
e.left_inv' h
protected lemma left_inv_on : left_inv_on e.symm e e.source := λ _, e.left_inv
@[simp, mfld_simps] lemma right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x :=
e.right_inv' h
protected lemma right_inv_on : right_inv_on e.symm e e.target := λ _, e.right_inv
/-- Associating to a local_equiv an equiv between the source and the target -/
protected def to_equiv : equiv (e.source) (e.target) :=
{ to_fun := λ x, ⟨e x, e.map_source x.mem⟩,
inv_fun := λ y, ⟨e.symm y, e.map_target y.mem⟩,
left_inv := λ⟨x, hx⟩, subtype.eq $ e.left_inv hx,
right_inv := λ⟨y, hy⟩, subtype.eq $ e.right_inv hy }
@[simp, mfld_simps] lemma symm_source : e.symm.source = e.target := rfl
@[simp, mfld_simps] lemma symm_target : e.symm.target = e.source := rfl
@[simp, mfld_simps] lemma symm_symm : e.symm.symm = e := by { cases e, refl }
/-- A local equiv induces a bijection between its source and target -/
lemma bij_on_source : bij_on e e.source e.target :=
inv_on.bij_on ⟨e.left_inv_on, e.right_inv_on⟩ e.maps_to e.symm_maps_to
lemma image_eq_target_inter_inv_preimage {s : set α} (h : s ⊆ e.source) :
e '' s = e.target ∩ e.symm ⁻¹' s :=
begin
refine subset.antisymm (λx hx, _) (λx hx, _),
{ rcases (mem_image _ _ _).1 hx with ⟨y, ys, hy⟩,
rw ← hy,
split,
{ apply e.map_source,
exact h ys },
{ rwa [mem_preimage, e.left_inv (h ys)] } },
{ rw ← e.right_inv hx.1,
exact mem_image_of_mem _ hx.2 }
end
lemma image_inter_source_eq (s : set α) :
e '' (s ∩ e.source) = e.target ∩ e.symm ⁻¹' (s ∩ e.source) :=
e.image_eq_target_inter_inv_preimage (inter_subset_right _ _)
lemma image_inter_source_eq' (s : set α) :
e '' (s ∩ e.source) = e.target ∩ e.symm ⁻¹' s :=
begin
rw e.image_eq_target_inter_inv_preimage (inter_subset_right _ _),
ext x, split; { assume hx, simp at hx, simp [hx] }
end
lemma symm_image_eq_source_inter_preimage {s : set β} (h : s ⊆ e.target) :
e.symm '' s = e.source ∩ e ⁻¹' s :=
e.symm.image_eq_target_inter_inv_preimage h
lemma symm_image_inter_target_eq (s : set β) :
e.symm '' (s ∩ e.target) = e.source ∩ e ⁻¹' (s ∩ e.target) :=
e.symm.image_inter_source_eq _
lemma symm_image_inter_target_eq' (s : set β) :
e.symm '' (s ∩ e.target) = e.source ∩ e ⁻¹' s :=
e.symm.image_inter_source_eq' _
lemma source_inter_preimage_inv_preimage (s : set α) :
e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s :=
begin
ext x, split,
{ rintros ⟨hx, xs⟩,
simp only [mem_preimage, hx, e.left_inv, mem_preimage] at xs,
exact ⟨hx, xs⟩ },
{ rintros ⟨hx, xs⟩,
simp [hx, xs] }
end
lemma target_inter_inv_preimage_preimage (s : set β) :
e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s :=
e.symm.source_inter_preimage_inv_preimage _
lemma image_source_eq_target : e '' e.source = e.target :=
e.bij_on_source.image_eq
lemma source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target :=
λx hx, e.map_source hx
lemma inv_image_target_eq_source : e.symm '' e.target = e.source :=
e.symm.bij_on_source.image_eq
lemma target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source :=
λx hx, e.map_target hx
/-- Two local equivs that have the same `source`, same `to_fun` and same `inv_fun`, coincide. -/
@[ext]
protected lemma ext {e e' : local_equiv α β} (h : ∀x, e x = e' x)
(hsymm : ∀x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' :=
begin
have A : (e : α → β) = e', by { ext x, exact h x },
have B : (e.symm : β → α) = e'.symm, by { ext x, exact hsymm x },
have I : e '' e.source = e.target := e.image_source_eq_target,
have I' : e' '' e'.source = e'.target := e'.image_source_eq_target,
rw [A, hs, I'] at I,
cases e; cases e',
simp * at *
end
/-- Restricting a local equivalence to e.source ∩ s -/
protected def restr (s : set α) : local_equiv α β :=
{ to_fun := e,
inv_fun := e.symm,
source := e.source ∩ s,
target := e.target ∩ e.symm⁻¹' s,
map_source' := λx hx, begin
simp only with mfld_simps at hx,
simp only [hx] with mfld_simps,
end,
map_target' := λy hy, begin
simp only with mfld_simps at hy,
simp only [hy] with mfld_simps,
end,
left_inv' := λx hx, e.left_inv hx.1,
right_inv' := λy hy, e.right_inv hy.1 }
@[simp, mfld_simps] lemma restr_coe (s : set α) : (e.restr s : α → β) = e := rfl
@[simp, mfld_simps] lemma restr_coe_symm (s : set α) : ((e.restr s).symm : β → α) = e.symm := rfl
@[simp, mfld_simps] lemma restr_source (s : set α) : (e.restr s).source = e.source ∩ s := rfl
@[simp, mfld_simps] lemma restr_target (s : set α) : (e.restr s).target = e.target ∩ e.symm ⁻¹' s := rfl
lemma restr_eq_of_source_subset {e : local_equiv α β} {s : set α} (h : e.source ⊆ s) :
e.restr s = e :=
local_equiv.ext (λ_, rfl) (λ_, rfl) (by simp [inter_eq_self_of_subset_left h])
@[simp, mfld_simps] lemma restr_univ {e : local_equiv α β} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
/-- The identity local equiv -/
protected def refl (α : Type*) : local_equiv α α := (equiv.refl α).to_local_equiv
@[simp, mfld_simps] lemma refl_source : (local_equiv.refl α).source = univ := rfl
@[simp, mfld_simps] lemma refl_target : (local_equiv.refl α).target = univ := rfl
@[simp, mfld_simps] lemma refl_coe : (local_equiv.refl α : α → α) = id := rfl
@[simp, mfld_simps] lemma refl_symm : (local_equiv.refl α).symm = local_equiv.refl α := rfl
@[simp, mfld_simps] lemma refl_restr_source (s : set α) : ((local_equiv.refl α).restr s).source = s :=
by simp
@[simp, mfld_simps] lemma refl_restr_target (s : set α) : ((local_equiv.refl α).restr s).target = s :=
by { change univ ∩ id⁻¹' s = s, simp }
/-- The identity local equiv on a set `s` -/
def of_set (s : set α) : local_equiv α α :=
{ to_fun := id,
inv_fun := id,
source := s,
target := s,
map_source' := λx hx, hx,
map_target' := λx hx, hx,
left_inv' := λx hx, rfl,
right_inv' := λx hx, rfl }
@[simp, mfld_simps] lemma of_set_source (s : set α) : (local_equiv.of_set s).source = s := rfl
@[simp, mfld_simps] lemma of_set_target (s : set α) : (local_equiv.of_set s).target = s := rfl
@[simp, mfld_simps] lemma of_set_coe (s : set α) : (local_equiv.of_set s : α → α) = id := rfl
@[simp, mfld_simps] lemma of_set_symm (s : set α) : (local_equiv.of_set s).symm = local_equiv.of_set s := rfl
/-- Composing two local equivs if the target of the first coincides with the source of the
second. -/
protected def trans' (e' : local_equiv β γ) (h : e.target = e'.source) :
local_equiv α γ :=
{ to_fun := e' ∘ e,
inv_fun := e.symm ∘ e'.symm,
source := e.source,
target := e'.target,
map_source' := λx hx, by simp [h.symm, hx],
map_target' := λy hy, by simp [h, hy],
left_inv' := λx hx, by simp [hx, h.symm],
right_inv' := λy hy, by simp [hy, h] }
/-- Composing two local equivs, by restricting to the maximal domain where their composition
is well defined. -/
protected def trans : local_equiv α γ :=
local_equiv.trans' (e.symm.restr (e'.source)).symm (e'.restr (e.target)) (inter_comm _ _)
@[simp, mfld_simps] lemma coe_trans : (e.trans e' : α → γ) = e' ∘ e := rfl
@[simp, mfld_simps] lemma coe_trans_symm : ((e.trans e').symm : γ → α) = e.symm ∘ e'.symm := rfl
lemma trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm :=
by cases e; cases e'; refl
@[simp, mfld_simps] lemma trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source := rfl
lemma trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) :=
by mfld_set_tac
lemma trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) :=
by rw [e.trans_source', inter_comm e.target, e.symm_image_inter_target_eq]
lemma image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source :=
image_source_eq_target (local_equiv.symm (local_equiv.restr (local_equiv.symm e) (e'.source)))
@[simp, mfld_simps] lemma trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target := rfl
lemma trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) :=
trans_source' e'.symm e.symm
lemma trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) :=
trans_source'' e'.symm e.symm
lemma inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target :=
image_trans_source e'.symm e.symm
lemma trans_assoc (e'' : local_equiv γ δ) : (e.trans e').trans e'' = e.trans (e'.trans e'') :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source, @preimage_comp α β γ, inter_assoc])
@[simp, mfld_simps] lemma trans_refl : e.trans (local_equiv.refl β) = e :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source])
@[simp, mfld_simps] lemma refl_trans : (local_equiv.refl α).trans e = e :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source, preimage_id])
lemma trans_refl_restr (s : set β) :
e.trans ((local_equiv.refl β).restr s) = e.restr (e ⁻¹' s) :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [trans_source])
lemma trans_refl_restr' (s : set β) :
e.trans ((local_equiv.refl β).restr s) = e.restr (e.source ∩ e ⁻¹' s) :=
local_equiv.ext (λx, rfl) (λx, rfl) $ by { simp [trans_source], rw [← inter_assoc, inter_self] }
lemma restr_trans (s : set α) :
(e.restr s).trans e' = (e.trans e').restr s :=
local_equiv.ext (λx, rfl) (λx, rfl) $ by { simp [trans_source, inter_comm], rwa inter_assoc }
/-- `eq_on_source e e'` means that `e` and `e'` have the same source, and coincide there. Then `e`
and `e'` should really be considered the same local equiv. -/
def eq_on_source (e e' : local_equiv α β) : Prop :=
e.source = e'.source ∧ (e.source.eq_on e e')
/-- `eq_on_source` is an equivalence relation -/
instance eq_on_source_setoid : setoid (local_equiv α β) :=
{ r := eq_on_source,
iseqv := ⟨
λe, by simp [eq_on_source],
λe e' h, by { simp [eq_on_source, h.1.symm], exact λx hx, (h.2 hx).symm },
λe e' e'' h h', ⟨by rwa [← h'.1, ← h.1], λx hx, by { rw [← h'.2, h.2 hx], rwa ← h.1 }⟩⟩ }
lemma eq_on_source_refl : e ≈ e := setoid.refl _
/-- Two equivalent local equivs have the same source -/
lemma eq_on_source.source_eq {e e' : local_equiv α β} (h : e ≈ e') : e.source = e'.source :=
h.1
/-- Two equivalent local equivs coincide on the source -/
lemma eq_on_source.eq_on {e e' : local_equiv α β} (h : e ≈ e') : e.source.eq_on e e' :=
h.2
/-- Two equivalent local equivs have the same target -/
lemma eq_on_source.target_eq {e e' : local_equiv α β} (h : e ≈ e') : e.target = e'.target :=
by simp only [← image_source_eq_target, ← h.source_eq, h.2.image_eq]
/-- If two local equivs are equivalent, so are their inverses. -/
lemma eq_on_source.symm' {e e' : local_equiv α β} (h : e ≈ e') : e.symm ≈ e'.symm :=
begin
refine ⟨h.target_eq, eq_on_of_left_inv_on_of_right_inv_on e.left_inv_on _ _⟩;
simp only [symm_source, h.target_eq, h.source_eq, e'.symm_maps_to],
exact e'.right_inv_on.congr_right e'.symm_maps_to (h.source_eq ▸ h.eq_on.symm),
end
/-- Two equivalent local equivs have coinciding inverses on the target -/
lemma eq_on_source.symm_eq_on {e e' : local_equiv α β} (h : e ≈ e') :
eq_on e.symm e'.symm e.target :=
h.symm'.eq_on
/-- Composition of local equivs respects equivalence -/
lemma eq_on_source.trans' {e e' : local_equiv α β} {f f' : local_equiv β γ}
(he : e ≈ e') (hf : f ≈ f') : e.trans f ≈ e'.trans f' :=
begin
split,
{ rw [trans_source'', trans_source'', ← he.target_eq, ← hf.1],
exact (he.symm'.eq_on.mono $ inter_subset_left _ _).image_eq },
{ assume x hx,
rw trans_source at hx,
simp [(he.2 hx.1).symm, hf.2 hx.2] }
end
/-- Restriction of local equivs respects equivalence -/
lemma eq_on_source.restr {e e' : local_equiv α β} (he : e ≈ e') (s : set α) :
e.restr s ≈ e'.restr s :=
begin
split,
{ simp [he.1] },
{ assume x hx,
simp only [mem_inter_eq, restr_source] at hx,
exact he.2 hx.1 }
end
/-- Preimages are respected by equivalence -/
lemma eq_on_source.source_inter_preimage_eq {e e' : local_equiv α β} (he : e ≈ e') (s : set β) :
e.source ∩ e ⁻¹' s = e'.source ∩ e' ⁻¹' s :=
begin
ext x,
simp only [mem_inter_eq, mem_preimage],
split,
{ assume hx,
rwa [← he.2 hx.1, ← he.source_eq] },
{ assume hx,
rwa [← (setoid.symm he).2 hx.1, he.source_eq] }
end
/-- Composition of a local equiv and its inverse is equivalent to the restriction of the identity
to the source -/
lemma trans_self_symm :
e.trans e.symm ≈ local_equiv.of_set e.source :=
begin
have A : (e.trans e.symm).source = e.source, by mfld_set_tac,
refine ⟨by simp [A], λx hx, _⟩,
rw A at hx,
simp only [hx] with mfld_simps
end
/-- Composition of the inverse of a local equiv and this local equiv is equivalent to the
restriction of the identity to the target -/
lemma trans_symm_self :
e.symm.trans e ≈ local_equiv.of_set e.target :=
trans_self_symm (e.symm)
/-- Two equivalent local equivs are equal when the source and target are univ -/
lemma eq_of_eq_on_source_univ (e e' : local_equiv α β) (h : e ≈ e')
(s : e.source = univ) (t : e.target = univ) : e = e' :=
begin
apply local_equiv.ext (λx, _) (λx, _) h.1,
{ apply h.2,
rw s,
exact mem_univ _ },
{ apply h.symm'.2,
rw [symm_source, t],
exact mem_univ _ }
end
section prod
/-- The product of two local equivs, as a local equiv on the product. -/
def prod (e : local_equiv α β) (e' : local_equiv γ δ) : local_equiv (α × γ) (β × δ) :=
{ source := set.prod e.source e'.source,
target := set.prod e.target e'.target,
to_fun := λp, (e p.1, e' p.2),
inv_fun := λp, (e.symm p.1, e'.symm p.2),
map_source' := λp hp, by { simp at hp, simp [hp] },
map_target' := λp hp, by { simp at hp, simp [map_target, hp] },
left_inv' := λp hp, by { simp at hp, simp [hp] },
right_inv' := λp hp, by { simp at hp, simp [hp] } }
@[simp, mfld_simps] lemma prod_source (e : local_equiv α β) (e' : local_equiv γ δ) :
(e.prod e').source = set.prod e.source e'.source := rfl
@[simp, mfld_simps] lemma prod_target (e : local_equiv α β) (e' : local_equiv γ δ) :
(e.prod e').target = set.prod e.target e'.target := rfl
@[simp, mfld_simps] lemma prod_coe (e : local_equiv α β) (e' : local_equiv γ δ) :
((e.prod e') : α × γ → β × δ) = (λp, (e p.1, e' p.2)) := rfl
lemma prod_coe_symm (e : local_equiv α β) (e' : local_equiv γ δ) :
((e.prod e').symm : β × δ → α × γ) = (λp, (e.symm p.1, e'.symm p.2)) := rfl
@[simp, mfld_simps] lemma prod_symm (e : local_equiv α β) (e' : local_equiv γ δ) :
(e.prod e').symm = (e.symm.prod e'.symm) :=
by ext x; simp [prod_coe_symm]
@[simp, mfld_simps] lemma prod_trans {η : Type*} {ε : Type*}
(e : local_equiv α β) (f : local_equiv β γ) (e' : local_equiv δ η) (f' : local_equiv η ε) :
(e.prod e').trans (f.prod f') = (e.trans f).prod (e'.trans f') :=
by ext x; simp [ext_iff]; tauto
end prod
end local_equiv
namespace set
-- All arguments are explicit to avoid missing information in the pretty printer output
/-- A bijection between two sets `s : set α` and `t : set β` provides a local equivalence
between `α` and `β`. -/
@[simps] noncomputable def bij_on.to_local_equiv [nonempty α] (f : α → β) (s : set α) (t : set β)
(hf : bij_on f s t) :
local_equiv α β :=
{ to_fun := f,
inv_fun := inv_fun_on f s,
source := s,
target := t,
map_source' := hf.maps_to,
map_target' := hf.surj_on.maps_to_inv_fun_on,
left_inv' := hf.inv_on_inv_fun_on.1,
right_inv' := hf.inv_on_inv_fun_on.2 }
/-- A map injective on a subset of its domain provides a local equivalence. -/
@[simp, mfld_simps] noncomputable def inj_on.to_local_equiv [nonempty α] (f : α → β) (s : set α)
(hf : inj_on f s) :
local_equiv α β :=
hf.bij_on_image.to_local_equiv f s (f '' s)
end set
namespace equiv
/- equivs give rise to local_equiv. We set up simp lemmas to reduce most properties of the local
equiv to that of the equiv. -/
variables (e : equiv α β) (e' : equiv β γ)
@[simp, mfld_simps] lemma to_local_equiv_coe : (e.to_local_equiv : α → β) = e := rfl
@[simp, mfld_simps] lemma to_local_equiv_symm_coe : (e.to_local_equiv.symm : β → α) = e.symm := rfl
@[simp, mfld_simps] lemma to_local_equiv_source : e.to_local_equiv.source = univ := rfl
@[simp, mfld_simps] lemma to_local_equiv_target : e.to_local_equiv.target = univ := rfl
@[simp, mfld_simps] lemma refl_to_local_equiv : (equiv.refl α).to_local_equiv = local_equiv.refl α := rfl
@[simp, mfld_simps] lemma symm_to_local_equiv : e.symm.to_local_equiv = e.to_local_equiv.symm := rfl
@[simp, mfld_simps] lemma trans_to_local_equiv :
(e.trans e').to_local_equiv = e.to_local_equiv.trans e'.to_local_equiv :=
local_equiv.ext (λx, rfl) (λx, rfl) (by simp [local_equiv.trans_source, equiv.to_local_equiv])
end equiv
|
f9aec7abcc2a3ec7dd2beef8f599bb0271871608 | b2fe74b11b57d362c13326bc5651244f111fa6f4 | /src/algebra/group_power/lemmas.lean | f100e4b04bde79b64a2bcce4f670ce35f65537e5 | [
"Apache-2.0"
] | permissive | midfield/mathlib | c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7 | 775edc615ecec631d65b6180dbcc7bc26c3abc26 | refs/heads/master | 1,675,330,551,921 | 1,608,304,514,000 | 1,608,304,514,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 26,385 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
-/
import algebra.group_power.basic
import algebra.opposites
import data.list.basic
import data.int.cast
import data.equiv.basic
import data.equiv.mul_add
import deprecated.group
/-!
# Lemmas about power operations on monoids and groups
This file contains lemmas about `monoid.pow`, `group.pow`, `nsmul`, `gsmul`
which require additional imports besides those available in `.basic`.
-/
universes u v w x y z u₁ u₂
variables {M : Type u} {N : Type v} {G : Type w} {H : Type x} {A : Type y} {B : Type z}
{R : Type u₁} {S : Type u₂}
/-!
### (Additive) monoid
-/
section monoid
variables [monoid M] [monoid N] [add_monoid A] [add_monoid B]
@[simp] theorem nsmul_one [has_one A] : ∀ n : ℕ, n •ℕ (1 : A) = n :=
add_monoid_hom.eq_nat_cast
⟨λ n, n •ℕ (1 : A), zero_nsmul _, λ _ _, add_nsmul _ _ _⟩
(one_nsmul _)
@[simp, priority 500]
theorem list.prod_repeat (a : M) (n : ℕ) : (list.repeat a n).prod = a ^ n :=
begin
induction n with n ih,
{ refl },
{ rw [list.repeat_succ, list.prod_cons, ih], refl, }
end
@[simp, priority 500]
theorem list.sum_repeat : ∀ (a : A) (n : ℕ), (list.repeat a n).sum = n •ℕ a :=
@list.prod_repeat (multiplicative A) _
@[simp, norm_cast] lemma units.coe_pow (u : units M) (n : ℕ) : ((u ^ n : units M) : M) = u ^ n :=
(units.coe_hom M).map_pow u n
lemma is_unit_of_pow_eq_one (x : M) (n : ℕ) (hx : x ^ n = 1) (hn : 0 < n) :
is_unit x :=
begin
cases n, { exact (nat.not_lt_zero _ hn).elim },
refine ⟨⟨x, x ^ n, _, _⟩, rfl⟩,
{ rwa [pow_succ] at hx },
{ rwa [pow_succ'] at hx }
end
end monoid
theorem nat.nsmul_eq_mul (m n : ℕ) : m •ℕ n = m * n :=
by induction m with m ih; [rw [zero_nsmul, zero_mul],
rw [succ_nsmul', ih, nat.succ_mul]]
section group
variables [group G] [group H] [add_group A] [add_group B]
open int
local attribute [ematch] le_of_lt
open nat
theorem gsmul_one [has_one A] (n : ℤ) : n •ℤ (1 : A) = n :=
by cases n; simp
lemma gpow_add_one (a : G) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a
| (of_nat n) := by simp [← int.coe_nat_succ, pow_succ']
| -[1+0] := by simp [int.neg_succ_of_nat_eq]
| -[1+(n+1)] := by rw [int.neg_succ_of_nat_eq, gpow_neg, neg_add, neg_add_cancel_right, gpow_neg,
← int.coe_nat_succ, gpow_coe_nat, gpow_coe_nat, pow_succ _ (n + 1), mul_inv_rev,
inv_mul_cancel_right]
theorem add_one_gsmul : ∀ (a : A) (i : ℤ), (i + 1) •ℤ a = i •ℤ a + a :=
@gpow_add_one (multiplicative A) _
lemma gpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ :=
calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ : (mul_inv_cancel_right _ _).symm
... = a^n * a⁻¹ : by rw [← gpow_add_one, sub_add_cancel]
lemma gpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n :=
begin
induction n using int.induction_on with n ihn n ihn,
case hz : { simp },
{ simp only [← add_assoc, gpow_add_one, ihn, mul_assoc] },
{ rw [gpow_sub_one, ← mul_assoc, ← ihn, ← gpow_sub_one, add_sub_assoc] }
end
lemma mul_self_gpow (b : G) (m : ℤ) : b*b^m = b^(m+1) :=
by { conv_lhs {congr, rw ← gpow_one b }, rw [← gpow_add, add_comm] }
lemma mul_gpow_self (b : G) (m : ℤ) : b^m*b = b^(m+1) :=
by { conv_lhs {congr, skip, rw ← gpow_one b }, rw [← gpow_add, add_comm] }
theorem add_gsmul : ∀ (a : A) (i j : ℤ), (i + j) •ℤ a = i •ℤ a + j •ℤ a :=
@gpow_add (multiplicative A) _
lemma gpow_sub (a : G) (m n : ℤ) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ :=
by rw [sub_eq_add_neg, gpow_add, gpow_neg]
lemma sub_gsmul (m n : ℤ) (a : A) : (m - n) •ℤ a = m •ℤ a - n •ℤ a :=
by simpa only [sub_eq_add_neg] using @gpow_sub (multiplicative A) _ _ _ _
theorem gpow_one_add (a : G) (i : ℤ) : a ^ (1 + i) = a * a ^ i :=
by rw [gpow_add, gpow_one]
theorem one_add_gsmul : ∀ (a : A) (i : ℤ), (1 + i) •ℤ a = a + i •ℤ a :=
@gpow_one_add (multiplicative A) _
theorem gpow_mul_comm (a : G) (i j : ℤ) : a ^ i * a ^ j = a ^ j * a ^ i :=
by rw [← gpow_add, ← gpow_add, add_comm]
theorem gsmul_add_comm : ∀ (a : A) (i j), i •ℤ a + j •ℤ a = j •ℤ a + i •ℤ a :=
@gpow_mul_comm (multiplicative A) _
theorem gpow_mul (a : G) (m n : ℤ) : a ^ (m * n) = (a ^ m) ^ n :=
int.induction_on n (by simp) (λ n ihn, by simp [mul_add, gpow_add, ihn])
(λ n ihn, by simp only [mul_sub, gpow_sub, ihn, mul_one, gpow_one])
theorem gsmul_mul' : ∀ (a : A) (m n : ℤ), m * n •ℤ a = n •ℤ (m •ℤ a) :=
@gpow_mul (multiplicative A) _
theorem gpow_mul' (a : G) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m :=
by rw [mul_comm, gpow_mul]
theorem gsmul_mul (a : A) (m n : ℤ) : m * n •ℤ a = m •ℤ (n •ℤ a) :=
by rw [mul_comm, gsmul_mul']
theorem gpow_bit0 (a : G) (n : ℤ) : a ^ bit0 n = a ^ n * a ^ n := gpow_add _ _ _
theorem bit0_gsmul (a : A) (n : ℤ) : bit0 n •ℤ a = n •ℤ a + n •ℤ a := gpow_add _ _ _
theorem gpow_bit1 (a : G) (n : ℤ) : a ^ bit1 n = a ^ n * a ^ n * a :=
by rw [bit1, gpow_add, gpow_bit0, gpow_one]
theorem bit1_gsmul : ∀ (a : A) (n : ℤ), bit1 n •ℤ a = n •ℤ a + n •ℤ a + a :=
@gpow_bit1 (multiplicative A) _
@[simp] theorem monoid_hom.map_gpow (f : G →* H) (a : G) (n : ℤ) : f (a ^ n) = f a ^ n :=
by cases n; [exact f.map_pow _ _, exact (f.map_inv _).trans (congr_arg _ $ f.map_pow _ _)]
@[simp] theorem add_monoid_hom.map_gsmul (f : A →+ B) (a : A) (n : ℤ) : f (n •ℤ a) = n •ℤ f a :=
f.to_multiplicative.map_gpow a n
@[simp, norm_cast] lemma units.coe_gpow (u : units G) (n : ℤ) : ((u ^ n : units G) : G) = u ^ n :=
(units.coe_hom G).map_gpow u n
end group
section ordered_add_comm_group
variables [ordered_add_comm_group A]
/-! Lemmas about `gsmul` under ordering, placed here (rather than in `algebra.group_power.basic`
with their friends) because they require facts from `data.int.basic`-/
open int
lemma gsmul_pos {a : A} (ha : 0 < a) {k : ℤ} (hk : (0:ℤ) < k) : 0 < k •ℤ a :=
begin
lift k to ℕ using int.le_of_lt hk,
apply nsmul_pos ha,
exact coe_nat_pos.mp hk,
end
theorem gsmul_le_gsmul {a : A} {n m : ℤ} (ha : 0 ≤ a) (h : n ≤ m) : n •ℤ a ≤ m •ℤ a :=
calc n •ℤ a = n •ℤ a + 0 : (add_zero _).symm
... ≤ n •ℤ a + (m - n) •ℤ a : add_le_add_left (gsmul_nonneg ha (sub_nonneg.mpr h)) _
... = m •ℤ a : by { rw [← add_gsmul], simp }
theorem gsmul_lt_gsmul {a : A} {n m : ℤ} (ha : 0 < a) (h : n < m) : n •ℤ a < m •ℤ a :=
calc n •ℤ a = n •ℤ a + 0 : (add_zero _).symm
... < n •ℤ a + (m - n) •ℤ a : add_lt_add_left (gsmul_pos ha (sub_pos.mpr h)) _
... = m •ℤ a : by { rw [← add_gsmul], simp }
end ordered_add_comm_group
section linear_ordered_add_comm_group
variable [linear_ordered_add_comm_group A]
theorem gsmul_le_gsmul_iff {a : A} {n m : ℤ} (ha : 0 < a) : n •ℤ a ≤ m •ℤ a ↔ n ≤ m :=
begin
refine ⟨λ h, _, gsmul_le_gsmul $ le_of_lt ha⟩,
by_contra H,
exact lt_irrefl _ (lt_of_lt_of_le (gsmul_lt_gsmul ha (not_le.mp H)) h)
end
theorem gsmul_lt_gsmul_iff {a : A} {n m : ℤ} (ha : 0 < a) : n •ℤ a < m •ℤ a ↔ n < m :=
begin
refine ⟨λ h, _, gsmul_lt_gsmul ha⟩,
by_contra H,
exact lt_irrefl _ (lt_of_le_of_lt (gsmul_le_gsmul (le_of_lt ha) $ not_lt.mp H) h)
end
theorem nsmul_le_nsmul_iff {a : A} {n m : ℕ} (ha : 0 < a) : n •ℕ a ≤ m •ℕ a ↔ n ≤ m :=
begin
refine ⟨λ h, _, nsmul_le_nsmul $ le_of_lt ha⟩,
by_contra H,
exact lt_irrefl _ (lt_of_lt_of_le (nsmul_lt_nsmul ha (not_le.mp H)) h)
end
theorem nsmul_lt_nsmul_iff {a : A} {n m : ℕ} (ha : 0 < a) : n •ℕ a < m •ℕ a ↔ n < m :=
begin
refine ⟨λ h, _, nsmul_lt_nsmul ha⟩,
by_contra H,
exact lt_irrefl _ (lt_of_le_of_lt (nsmul_le_nsmul (le_of_lt ha) $ not_lt.mp H) h)
end
end linear_ordered_add_comm_group
@[simp] lemma with_bot.coe_nsmul [add_monoid A] (a : A) (n : ℕ) :
((nsmul n a : A) : with_bot A) = nsmul n a :=
add_monoid_hom.map_nsmul ⟨(coe : A → with_bot A), with_bot.coe_zero, with_bot.coe_add⟩ a n
theorem nsmul_eq_mul' [semiring R] (a : R) (n : ℕ) : n •ℕ a = a * n :=
by induction n with n ih; [rw [zero_nsmul, nat.cast_zero, mul_zero],
rw [succ_nsmul', ih, nat.cast_succ, mul_add, mul_one]]
@[simp] theorem nsmul_eq_mul [semiring R] (n : ℕ) (a : R) : n •ℕ a = n * a :=
by rw [nsmul_eq_mul', (n.cast_commute a).eq]
theorem mul_nsmul_left [semiring R] (a b : R) (n : ℕ) : n •ℕ (a * b) = a * (n •ℕ b) :=
by rw [nsmul_eq_mul', nsmul_eq_mul', mul_assoc]
theorem mul_nsmul_assoc [semiring R] (a b : R) (n : ℕ) : n •ℕ (a * b) = n •ℕ a * b :=
by rw [nsmul_eq_mul, nsmul_eq_mul, mul_assoc]
@[simp, norm_cast] theorem nat.cast_pow [semiring R] (n m : ℕ) : (↑(n ^ m) : R) = ↑n ^ m :=
by induction m with m ih; [exact nat.cast_one, rw [pow_succ', pow_succ', nat.cast_mul, ih]]
@[simp, norm_cast] theorem int.coe_nat_pow (n m : ℕ) : ((n ^ m : ℕ) : ℤ) = n ^ m :=
by induction m with m ih; [exact int.coe_nat_one, rw [pow_succ', pow_succ', int.coe_nat_mul, ih]]
theorem int.nat_abs_pow (n : ℤ) (k : ℕ) : int.nat_abs (n ^ k) = (int.nat_abs n) ^ k :=
by induction k with k ih; [refl, rw [pow_succ', int.nat_abs_mul, pow_succ', ih]]
-- The next four lemmas allow us to replace multiplication by a numeral with a `gsmul` expression.
-- They are used by the `noncomm_ring` tactic, to normalise expressions before passing to `abel`.
lemma bit0_mul [ring R] {n r : R} : bit0 n * r = gsmul 2 (n * r) :=
by { dsimp [bit0], rw [add_mul, add_gsmul, one_gsmul], }
lemma mul_bit0 [ring R] {n r : R} : r * bit0 n = gsmul 2 (r * n) :=
by { dsimp [bit0], rw [mul_add, add_gsmul, one_gsmul], }
lemma bit1_mul [ring R] {n r : R} : bit1 n * r = gsmul 2 (n * r) + r :=
by { dsimp [bit1], rw [add_mul, bit0_mul, one_mul], }
lemma mul_bit1 [ring R] {n r : R} : r * bit1 n = gsmul 2 (r * n) + r :=
by { dsimp [bit1], rw [mul_add, mul_bit0, mul_one], }
@[simp] theorem gsmul_eq_mul [ring R] (a : R) : ∀ n, n •ℤ a = n * a
| (n : ℕ) := nsmul_eq_mul _ _
| -[1+ n] := show -(_ •ℕ _)=-_*_, by rw [neg_mul_eq_neg_mul_symm, nsmul_eq_mul, nat.cast_succ]
theorem gsmul_eq_mul' [ring R] (a : R) (n : ℤ) : n •ℤ a = a * n :=
by rw [gsmul_eq_mul, (n.cast_commute a).eq]
theorem mul_gsmul_left [ring R] (a b : R) (n : ℤ) : n •ℤ (a * b) = a * (n •ℤ b) :=
by rw [gsmul_eq_mul', gsmul_eq_mul', mul_assoc]
theorem mul_gsmul_assoc [ring R] (a b : R) (n : ℤ) : n •ℤ (a * b) = n •ℤ a * b :=
by rw [gsmul_eq_mul, gsmul_eq_mul, mul_assoc]
@[simp]
lemma gsmul_int_int (a b : ℤ) : a •ℤ b = a * b := by simp [gsmul_eq_mul]
lemma gsmul_int_one (n : ℤ) : n •ℤ 1 = n := by simp
@[simp, norm_cast] theorem int.cast_pow [ring R] (n : ℤ) (m : ℕ) : (↑(n ^ m) : R) = ↑n ^ m :=
by induction m with m ih; [exact int.cast_one,
rw [pow_succ, pow_succ, int.cast_mul, ih]]
lemma neg_one_pow_eq_pow_mod_two [ring R] {n : ℕ} : (-1 : R) ^ n = (-1) ^ (n % 2) :=
by rw [← nat.mod_add_div n 2, pow_add, pow_mul]; simp [pow_two]
section ordered_semiring
variable [ordered_semiring R]
/-- Bernoulli's inequality. This version works for semirings but requires
an additional hypothesis `0 ≤ a * a`. -/
theorem one_add_mul_le_pow' {a : R} (Hsqr : 0 ≤ a * a) (H : 0 ≤ 1 + a) :
∀ (n : ℕ), 1 + n •ℕ a ≤ (1 + a) ^ n
| 0 := le_of_eq $ add_zero _
| (n+1) :=
calc 1 + (n + 1) •ℕ a ≤ (1 + a) * (1 + n •ℕ a) :
by simpa [succ_nsmul, mul_add, add_mul, mul_nsmul_left, add_comm, add_left_comm]
using nsmul_nonneg Hsqr n
... ≤ (1 + a)^(n+1) : mul_le_mul_of_nonneg_left (one_add_mul_le_pow' n) H
private lemma pow_lt_pow_of_lt_one_aux {a : R} (h : 0 < a) (ha : a < 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k + 1) < a ^ i
| 0 :=
begin
simp only [add_zero],
rw ←one_mul (a^i), exact mul_lt_mul ha (le_refl _) (pow_pos h _) zero_le_one
end
| (k+1) :=
begin
rw ←one_mul (a^i),
apply mul_lt_mul ha _ _ zero_le_one,
{ apply le_of_lt, apply pow_lt_pow_of_lt_one_aux },
{ show 0 < a ^ (i + (k + 1) + 0), apply pow_pos h }
end
private lemma pow_le_pow_of_le_one_aux {a : R} (h : 0 ≤ a) (ha : a ≤ 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k) ≤ a ^ i
| 0 := by simp
| (k+1) := by rw [←add_assoc, ←one_mul (a^i)];
exact mul_le_mul ha (pow_le_pow_of_le_one_aux _) (pow_nonneg h _) zero_le_one
lemma pow_lt_pow_of_lt_one {a : R} (h : 0 < a) (ha : a < 1)
{i j : ℕ} (hij : i < j) : a ^ j < a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_lt hij in
by rw hk; exact pow_lt_pow_of_lt_one_aux h ha _ _
lemma pow_lt_pow_iff_of_lt_one {a : R} {n m : ℕ} (hpos : 0 < a) (h : a < 1) :
a ^ m < a ^ n ↔ n < m :=
begin
have : strict_mono (λ (n : order_dual ℕ), a ^ (id n : ℕ)) := λ m n, pow_lt_pow_of_lt_one hpos h,
exact this.lt_iff_lt
end
lemma pow_le_pow_of_le_one {a : R} (h : 0 ≤ a) (ha : a ≤ 1)
{i j : ℕ} (hij : i ≤ j) : a ^ j ≤ a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_le hij in
by rw hk; exact pow_le_pow_of_le_one_aux h ha _ _
lemma pow_le_one {x : R} : ∀ (n : ℕ) (h0 : 0 ≤ x) (h1 : x ≤ 1), x ^ n ≤ 1
| 0 h0 h1 := le_refl (1 : R)
| (n+1) h0 h1 := mul_le_one h1 (pow_nonneg h0 _) (pow_le_one n h0 h1)
end ordered_semiring
/-- Bernoulli's inequality for `n : ℕ`, `-2 ≤ a`. -/
theorem one_add_mul_le_pow [linear_ordered_ring R] {a : R} (H : -2 ≤ a) :
∀ (n : ℕ), 1 + n •ℕ a ≤ (1 + a) ^ n
| 0 := le_of_eq $ add_zero _
| 1 := by simp
| (n+2) :=
have H' : 0 ≤ 2 + a,
from neg_le_iff_add_nonneg.1 H,
have 0 ≤ n •ℕ (a * a * (2 + a)) + a * a,
from add_nonneg (nsmul_nonneg (mul_nonneg (mul_self_nonneg a) H') n)
(mul_self_nonneg a),
calc 1 + (n + 2) •ℕ a ≤ 1 + (n + 2) •ℕ a + (n •ℕ (a * a * (2 + a)) + a * a) :
(le_add_iff_nonneg_right _).2 this
... = (1 + a) * (1 + a) * (1 + n •ℕ a) :
by { simp only [add_mul, mul_add, mul_two, mul_one, one_mul, succ_nsmul, nsmul_add,
mul_nsmul_assoc, (mul_nsmul_left _ _ _).symm],
ac_refl }
... ≤ (1 + a) * (1 + a) * (1 + a)^n :
mul_le_mul_of_nonneg_left (one_add_mul_le_pow n) (mul_self_nonneg (1 + a))
... = (1 + a)^(n + 2) : by simp only [pow_succ, mul_assoc]
/-- Bernoulli's inequality reformulated to estimate `a^n`. -/
theorem one_add_sub_mul_le_pow [linear_ordered_ring R]
{a : R} (H : -1 ≤ a) (n : ℕ) : 1 + n •ℕ (a - 1) ≤ a ^ n :=
have -2 ≤ a - 1, by { rw [bit0, neg_add, ← sub_eq_add_neg], exact sub_le_sub_right H 1 },
by simpa only [add_sub_cancel'_right] using one_add_mul_le_pow this n
namespace int
lemma units_pow_two (u : units ℤ) : u ^ 2 = 1 :=
(pow_two u).symm ▸ units_mul_self u
lemma units_pow_eq_pow_mod_two (u : units ℤ) (n : ℕ) : u ^ n = u ^ (n % 2) :=
by conv {to_lhs, rw ← nat.mod_add_div n 2}; rw [pow_add, pow_mul, units_pow_two, one_pow, mul_one]
@[simp] lemma nat_abs_pow_two (x : ℤ) : (x.nat_abs ^ 2 : ℤ) = x ^ 2 :=
by rw [pow_two, int.nat_abs_mul_self', pow_two]
lemma abs_le_self_pow_two (a : ℤ) : (int.nat_abs a : ℤ) ≤ a ^ 2 :=
by { rw [← int.nat_abs_pow_two a, pow_two], norm_cast, apply nat.le_mul_self }
lemma le_self_pow_two (b : ℤ) : b ≤ b ^ 2 := le_trans (le_nat_abs) (abs_le_self_pow_two _)
end int
variables (M G A)
/-- Monoid homomorphisms from `multiplicative ℕ` are defined by the image
of `multiplicative.of_add 1`. -/
def powers_hom [monoid M] : M ≃ (multiplicative ℕ →* M) :=
{ to_fun := λ x, ⟨λ n, x ^ n.to_add, pow_zero x, λ m n, pow_add x m n⟩,
inv_fun := λ f, f (multiplicative.of_add 1),
left_inv := pow_one,
right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_pow, ← of_add_nsmul] } }
/-- Monoid homomorphisms from `multiplicative ℤ` are defined by the image
of `multiplicative.of_add 1`. -/
def gpowers_hom [group G] : G ≃ (multiplicative ℤ →* G) :=
{ to_fun := λ x, ⟨λ n, x ^ n.to_add, gpow_zero x, λ m n, gpow_add x m n⟩,
inv_fun := λ f, f (multiplicative.of_add 1),
left_inv := gpow_one,
right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_gpow, ← of_add_gsmul ] } }
/-- Additive homomorphisms from `ℕ` are defined by the image of `1`. -/
def multiples_hom [add_monoid A] : A ≃ (ℕ →+ A) :=
{ to_fun := λ x, ⟨λ n, n •ℕ x, zero_nsmul x, λ m n, add_nsmul _ _ _⟩,
inv_fun := λ f, f 1,
left_inv := one_nsmul,
right_inv := λ f, add_monoid_hom.ext_nat $ one_nsmul (f 1) }
/-- Additive homomorphisms from `ℤ` are defined by the image of `1`. -/
def gmultiples_hom [add_group A] : A ≃ (ℤ →+ A) :=
{ to_fun := λ x, ⟨λ n, n •ℤ x, zero_gsmul x, λ m n, add_gsmul _ _ _⟩,
inv_fun := λ f, f 1,
left_inv := one_gsmul,
right_inv := λ f, add_monoid_hom.ext_int $ one_gsmul (f 1) }
variables {M G A}
@[simp] lemma powers_hom_apply [monoid M] (x : M) (n : multiplicative ℕ) :
powers_hom M x n = x ^ n.to_add := rfl
@[simp] lemma powers_hom_symm_apply [monoid M] (f : multiplicative ℕ →* M) :
(powers_hom M).symm f = f (multiplicative.of_add 1) := rfl
@[simp] lemma gpowers_hom_apply [group G] (x : G) (n : multiplicative ℤ) :
gpowers_hom G x n = x ^ n.to_add := rfl
@[simp] lemma gpowers_hom_symm_apply [group G] (f : multiplicative ℤ →* G) :
(gpowers_hom G).symm f = f (multiplicative.of_add 1) := rfl
@[simp] lemma multiples_hom_apply [add_monoid A] (x : A) (n : ℕ) :
multiples_hom A x n = n •ℕ x := rfl
@[simp] lemma multiples_hom_symm_apply [add_monoid A] (f : ℕ →+ A) :
(multiples_hom A).symm f = f 1 := rfl
@[simp] lemma gmultiples_hom_apply [add_group A] (x : A) (n : ℤ) :
gmultiples_hom A x n = n •ℤ x := rfl
@[simp] lemma gmultiples_hom_symm_apply [add_group A] (f : ℤ →+ A) :
(gmultiples_hom A).symm f = f 1 := rfl
lemma monoid_hom.apply_mnat [monoid M] (f : multiplicative ℕ →* M) (n : multiplicative ℕ) :
f n = (f (multiplicative.of_add 1)) ^ n.to_add :=
by rw [← powers_hom_symm_apply, ← powers_hom_apply, equiv.apply_symm_apply]
@[ext] lemma monoid_hom.ext_mnat [monoid M] ⦃f g : multiplicative ℕ →* M⦄
(h : f (multiplicative.of_add 1) = g (multiplicative.of_add 1)) : f = g :=
monoid_hom.ext $ λ n, by rw [f.apply_mnat, g.apply_mnat, h]
lemma monoid_hom.apply_mint [group M] (f : multiplicative ℤ →* M) (n : multiplicative ℤ) :
f n = (f (multiplicative.of_add 1)) ^ n.to_add :=
by rw [← gpowers_hom_symm_apply, ← gpowers_hom_apply, equiv.apply_symm_apply]
@[ext] lemma monoid_hom.ext_mint [group M] ⦃f g : multiplicative ℤ →* M⦄
(h : f (multiplicative.of_add 1) = g (multiplicative.of_add 1)) : f = g :=
monoid_hom.ext $ λ n, by rw [f.apply_mint, g.apply_mint, h]
lemma add_monoid_hom.apply_nat [add_monoid M] (f : ℕ →+ M) (n : ℕ) :
f n = n •ℕ (f 1) :=
by rw [← multiples_hom_symm_apply, ← multiples_hom_apply, equiv.apply_symm_apply]
/-! `add_monoid_hom.ext_nat` is defined in `data.nat.cast` -/
lemma add_monoid_hom.apply_int [add_group M] (f : ℤ →+ M) (n : ℤ) :
f n = n •ℤ (f 1) :=
by rw [← gmultiples_hom_symm_apply, ← gmultiples_hom_apply, equiv.apply_symm_apply]
/-! `add_monoid_hom.ext_int` is defined in `data.int.cast` -/
variables (M G A)
/-- If `M` is commutative, `powers_hom` is a multiplicative equivalence. -/
def powers_mul_hom [comm_monoid M] : M ≃* (multiplicative ℕ →* M) :=
{ map_mul' := λ a b, monoid_hom.ext $ by simp [mul_pow],
..powers_hom M}
/-- If `M` is commutative, `gpowers_hom` is a multiplicative equivalence. -/
def gpowers_mul_hom [comm_group G] : G ≃* (multiplicative ℤ →* G) :=
{ map_mul' := λ a b, monoid_hom.ext $ by simp [mul_gpow],
..gpowers_hom G}
/-- If `M` is commutative, `multiples_hom` is an additive equivalence. -/
def multiples_add_hom [add_comm_monoid A] : A ≃+ (ℕ →+ A) :=
{ map_add' := λ a b, add_monoid_hom.ext $ by simp [nsmul_add],
..multiples_hom A}
/-- If `M` is commutative, `gmultiples_hom` is an additive equivalence. -/
def gmultiples_add_hom [add_comm_group A] : A ≃+ (ℤ →+ A) :=
{ map_add' := λ a b, add_monoid_hom.ext $ by simp [gsmul_add],
..gmultiples_hom A}
variables {M G A}
@[simp] lemma powers_mul_hom_apply [comm_monoid M] (x : M) (n : multiplicative ℕ) :
powers_mul_hom M x n = x ^ n.to_add := rfl
@[simp] lemma powers_mul_hom_symm_apply [comm_monoid M] (f : multiplicative ℕ →* M) :
(powers_mul_hom M).symm f = f (multiplicative.of_add 1) := rfl
@[simp] lemma gpowers_mul_hom_apply [comm_group G] (x : G) (n : multiplicative ℤ) :
gpowers_mul_hom G x n = x ^ n.to_add := rfl
@[simp] lemma gpowers_mul_hom_symm_apply [comm_group G] (f : multiplicative ℤ →* G) :
(gpowers_mul_hom G).symm f = f (multiplicative.of_add 1) := rfl
@[simp] lemma multiples_add_hom_apply [add_comm_monoid A] (x : A) (n : ℕ) :
multiples_add_hom A x n = n •ℕ x := rfl
@[simp] lemma multiples_add_hom_symm_apply [add_comm_monoid A] (f : ℕ →+ A) :
(multiples_add_hom A).symm f = f 1 := rfl
@[simp] lemma gmultiples_add_hom_apply [add_comm_group A] (x : A) (n : ℤ) :
gmultiples_add_hom A x n = n •ℤ x := rfl
@[simp] lemma gmultiples_add_hom_symm_apply [add_comm_group A] (f : ℤ →+ A) :
(gmultiples_add_hom A).symm f = f 1 := rfl
/-!
### Commutativity (again)
Facts about `semiconj_by` and `commute` that require `gpow` or `gsmul`, or the fact that integer
multiplication equals semiring multiplication.
-/
namespace semiconj_by
section
variables [semiring R] {a x y : R}
@[simp] lemma cast_nat_mul_right (h : semiconj_by a x y) (n : ℕ) : semiconj_by a ((n : R) * x) (n * y) :=
semiconj_by.mul_right (nat.commute_cast _ _) h
@[simp] lemma cast_nat_mul_left (h : semiconj_by a x y) (n : ℕ) : semiconj_by ((n : R) * a) x y :=
semiconj_by.mul_left (nat.cast_commute _ _) h
@[simp] lemma cast_nat_mul_cast_nat_mul (h : semiconj_by a x y) (m n : ℕ) :
semiconj_by ((m : R) * a) (n * x) (n * y) :=
(h.cast_nat_mul_left m).cast_nat_mul_right n
end
variables [monoid M] [group G] [ring R]
@[simp] lemma units_gpow_right {a : M} {x y : units M} (h : semiconj_by a x y) :
∀ m : ℤ, semiconj_by a (↑(x^m)) (↑(y^m))
| (n : ℕ) := by simp only [gpow_coe_nat, units.coe_pow, h, pow_right]
| -[1+n] := by simp only [gpow_neg_succ_of_nat, units.coe_pow, units_inv_right, h, pow_right]
variables {a b x y x' y' : R}
@[simp] lemma cast_int_mul_right (h : semiconj_by a x y) (m : ℤ) :
semiconj_by a ((m : ℤ) * x) (m * y) :=
semiconj_by.mul_right (int.commute_cast _ _) h
@[simp] lemma cast_int_mul_left (h : semiconj_by a x y) (m : ℤ) : semiconj_by ((m : R) * a) x y :=
semiconj_by.mul_left (int.cast_commute _ _) h
@[simp] lemma cast_int_mul_cast_int_mul (h : semiconj_by a x y) (m n : ℤ) :
semiconj_by ((m : R) * a) (n * x) (n * y) :=
(h.cast_int_mul_left m).cast_int_mul_right n
end semiconj_by
namespace commute
section
variables [semiring R] {a b : R}
@[simp] theorem cast_nat_mul_right (h : commute a b) (n : ℕ) : commute a ((n : R) * b) :=
h.cast_nat_mul_right n
@[simp] theorem cast_nat_mul_left (h : commute a b) (n : ℕ) : commute ((n : R) * a) b :=
h.cast_nat_mul_left n
@[simp] theorem cast_nat_mul_cast_nat_mul (h : commute a b) (m n : ℕ) :
commute ((m : R) * a) (n * b) :=
h.cast_nat_mul_cast_nat_mul m n
@[simp] theorem self_cast_nat_mul (n : ℕ) : commute a (n * a) :=
(commute.refl a).cast_nat_mul_right n
@[simp] theorem cast_nat_mul_self (n : ℕ) : commute ((n : R) * a) a :=
(commute.refl a).cast_nat_mul_left n
@[simp] theorem self_cast_nat_mul_cast_nat_mul (m n : ℕ) : commute ((m : R) * a) (n * a) :=
(commute.refl a).cast_nat_mul_cast_nat_mul m n
end
variables [monoid M] [group G] [ring R]
@[simp] lemma units_gpow_right {a : M} {u : units M} (h : commute a u) (m : ℤ) :
commute a (↑(u^m)) :=
h.units_gpow_right m
@[simp] lemma units_gpow_left {u : units M} {a : M} (h : commute ↑u a) (m : ℤ) :
commute (↑(u^m)) a :=
(h.symm.units_gpow_right m).symm
variables {a b : R}
@[simp] lemma cast_int_mul_right (h : commute a b) (m : ℤ) : commute a (m * b) :=
h.cast_int_mul_right m
@[simp] lemma cast_int_mul_left (h : commute a b) (m : ℤ) : commute ((m : R) * a) b :=
h.cast_int_mul_left m
lemma cast_int_mul_cast_int_mul (h : commute a b) (m n : ℤ) : commute ((m : R) * a) (n * b) :=
h.cast_int_mul_cast_int_mul m n
variables (a) (m n : ℤ)
@[simp] theorem self_cast_int_mul : commute a (n * a) := (commute.refl a).cast_int_mul_right n
@[simp] theorem cast_int_mul_self : commute ((n : R) * a) a := (commute.refl a).cast_int_mul_left n
theorem self_cast_int_mul_cast_int_mul : commute ((m : R) * a) (n * a) :=
(commute.refl a).cast_int_mul_cast_int_mul m n
end commute
section multiplicative
open multiplicative
@[simp] lemma nat.to_add_pow (a : multiplicative ℕ) (b : ℕ) : to_add (a ^ b) = to_add a * b :=
begin
induction b with b ih,
{ erw [pow_zero, to_add_one, mul_zero] },
{ simp [*, pow_succ, add_comm, nat.mul_succ] }
end
@[simp] lemma nat.of_add_mul (a b : ℕ) : of_add (a * b) = of_add a ^ b :=
(nat.to_add_pow _ _).symm
@[simp] lemma int.to_add_pow (a : multiplicative ℤ) (b : ℕ) : to_add (a ^ b) = to_add a * b :=
by induction b; simp [*, mul_add, pow_succ, add_comm]
@[simp] lemma int.to_add_gpow (a : multiplicative ℤ) (b : ℤ) : to_add (a ^ b) = to_add a * b :=
int.induction_on b (by simp)
(by simp [gpow_add, mul_add] {contextual := tt})
(by simp [gpow_add, mul_add, sub_eq_add_neg] {contextual := tt})
@[simp] lemma int.of_add_mul (a b : ℤ) : of_add (a * b) = of_add a ^ b :=
(int.to_add_gpow _ _).symm
end multiplicative
namespace units
variables [monoid M]
lemma conj_pow (u : units M) (x : M) (n : ℕ) : (↑u * x * ↑(u⁻¹))^n = u * x^n * ↑(u⁻¹) :=
(divp_eq_iff_mul_eq.2 ((u.mk_semiconj_by x).pow_right n).eq.symm).symm
lemma conj_pow' (u : units M) (x : M) (n : ℕ) : (↑(u⁻¹) * x * u)^n = ↑(u⁻¹) * x^n * u:=
(u⁻¹).conj_pow x n
open opposite
/-- Moving to the opposite monoid commutes with taking powers. -/
@[simp] lemma op_pow (x : M) (n : ℕ) : op (x ^ n) = (op x) ^ n :=
begin
induction n with n h,
{ simp },
{ rw [pow_succ', op_mul, h, pow_succ] }
end
@[simp] lemma unop_pow (x : Mᵒᵖ) (n : ℕ) : unop (x ^ n) = (unop x) ^ n :=
begin
induction n with n h,
{ simp },
{ rw [pow_succ', unop_mul, h, pow_succ] }
end
end units
|
b345fb2952b541381bb8436141486a605d5af71a | e21db629d2e37a833531fdcb0b37ce4d71825408 | /src/parlang/lemmas_state.lean | 723baf5a5d01d57ea8a20b47a11431989c03b51f | [] | no_license | fischerman/GPU-transformation-verifier | 614a28cb4606a05a0eb27e8d4eab999f4f5ea60c | 75a5016f05382738ff93ce5859c4cfa47ccb63c1 | refs/heads/master | 1,586,985,789,300 | 1,579,290,514,000 | 1,579,290,514,000 | 165,031,073 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,679 | lean | import parlang.defs
import parlang.lemmas_active_map
import parlang.lemmas_thread_state
namespace parlang
namespace state
variables {n : ℕ} {σ : Type} {ι : Type} {τ : ι → Type} [decidable_eq ι]
-- we have to prove all four combinations (2 by contradiction and 2 because they match)
-- there must be at least one thread otherwise memory can be arbitrary
-- todo: do pattern matching to shorten proof?
lemma syncable_unique {s : state n σ τ} {m m'} (h₁ : syncable s m) (h₂ : syncable s m') (hl : 0 < n) : m = m' := begin
funext,
specialize h₁ x,
specialize h₂ x,
cases h₁,
case or.inl {
cases h₂,
case or.inl {
have i : fin n := ⟨0, hl⟩,
rw (h₁ i).right,
rw (h₂ i).right,
},
case or.inr {
cases h₂ with i h₂,
specialize h₁ i,
have : x ∈ (s.threads.nth i).stores := by apply h₂.left,
have : x ∉ (s.threads.nth i).stores := by apply h₁.left,
contradiction,
}
},
case or.inr {
cases h₁ with h₁l h₁,
cases h₁ with h₁_1 h₁,
cases h₁ with h₁_2 h₁_3,
cases h₂,
case or.inl {
specialize h₂ h₁l,
have : x ∉ (vector.nth (s.threads) h₁l).stores := by apply h₂.left,
contradiction,
},
case or.inr {
cases h₂ with h₂l h₂,
cases h₂ with h₂_1 h₂,
cases h₂ with h₂_2 h₂_3,
rw h₁_2,
rw h₂_2,
have hleq : h₁l = h₂l := begin
by_contra hlneq,
have : x ∉ thread_state.accesses (vector.nth (s.threads) h₁l) := begin
specialize h₂_3 h₁l,
apply h₂_3,
intro a,
apply hlneq,
exact eq.symm a,
end,
unfold thread_state.accesses at this,
have : x ∉ (vector.nth (s.threads) h₁l).stores := begin
apply set.union_no_mem_left this,
end,
contradiction,
end,
subst hleq,
}
}
end
theorem syncable_tlocal (s : state n σ τ) (m : memory τ) (ac : vector bool n) (tl : thread_state σ τ → σ) : s.syncable m ↔ (s.map_active_threads ac $ λts, { tlocal := tl ts, ..ts }).syncable m := begin
unfold syncable,
induction n,
case nat.zero {
split, {
intro h,
intro i,
left,
intro tid,
apply fin_zero_elim tid,
}, {
intros h i,
left,
intro tid,
apply fin_zero_elim tid,
}
},
case nat.succ : n ih {
split, {
intros h i,
specialize h i,
cases h,
{
left,
intro tid,
specialize h tid,
cases h,
split, {
sorry,
},
sorry
},
sorry,
},
sorry,
}
end
@[simp]
lemma compute_stores_state {s : state n σ τ} {ac : vector bool n} {tid} {f g} :
(vector.nth ((map_active_threads ac (thread_state.compute g ∘ f) s).threads) tid).stores = (vector.nth ((map_active_threads ac f s).threads) tid).stores := begin
unfold map_active_threads,
simp,
by_cases h : vector.nth ac tid = tt, {
simp [*, thread_state.compute],
}, {
simp at h,
simp [*, thread_state.compute],
}
end
@[simp]
lemma compute_loads_state {s : state n σ τ} {ac : vector bool n} {tid} {f g} :
(vector.nth ((map_active_threads ac (thread_state.compute g ∘ f) s).threads) tid).loads = (vector.nth ((map_active_threads ac f s).threads) tid).loads := begin
unfold map_active_threads,
simp,
by_cases h : vector.nth ac tid = tt, {
simp [*, thread_state.compute],
}, {
simp at h,
simp [*, thread_state.compute],
}
end
@[simp]
lemma compute_shared_state {s : state n σ τ} {ac : vector bool n} {tid} {f g} :
(vector.nth ((map_active_threads ac (thread_state.compute g ∘ f) s).threads) tid).shared = (vector.nth ((map_active_threads ac f s).threads) tid).shared := begin
unfold map_active_threads,
simp,
by_cases h : vector.nth ac tid = tt, {
simp [*, thread_state.compute],
}, {
simp at h,
simp [*, thread_state.compute],
}
end
@[simp]
lemma compute_access_state {s : state n σ τ} {ac : vector bool n} {tid} {f g} :
thread_state.accesses (vector.nth ((map_active_threads ac (thread_state.compute g ∘ f) s).threads) tid) = thread_state.accesses (vector.nth ((map_active_threads ac f s).threads) tid) := by simp [thread_state.accesses]
@[simp]
lemma syncable_remove_compute {s : state n σ τ} (ac : vector bool n) (f m g) : syncable (map_active_threads ac (thread_state.compute g ∘ f) s) m ↔ syncable (map_active_threads ac f s) m := begin
simp [syncable, compute_stores_state, compute_shared_state, compute_access_state],
end
lemma state_eq_per_thread {s u : state n σ τ} : (∀ i, s.threads.nth i = u.threads.nth i) → s = u := begin
intros hieq,
cases s,
cases u,
simp at *,
apply vector.eq_element_wise hieq,
end
lemma map_active_threads_nth_inac {s : state n σ τ} {ac : vector bool n} {f i} : ¬ ac.nth i → s.threads.nth i = (s.map_active_threads ac f).threads.nth i := begin
intro hnac,
unfold map_active_threads,
simp [hnac],
end
lemma map_active_threads_nth_ac {s : state n σ τ} {ac : vector bool n} {f i} : ac.nth i → (s.map_active_threads ac f).threads.nth i = f (s.threads.nth i) := begin
intro hac,
unfold map_active_threads,
simp [hac],
end
@[simp]
lemma map_map_active_threads {s : state n σ τ} {ac : vector bool n} {f g} : (s.map_active_threads ac f).map_active_threads ac g = s.map_active_threads ac (g ∘ f) := begin
simp [map_active_threads],
rw vector.map₂_map₂,
apply vector.eq_element_wise,
intro i,
simp,
by_cases h : vector.nth ac i = tt,
{ simp *, },
{ simp at h, simp *, },
end
lemma map_map_active_threads' {s : state n σ τ} {ac : vector bool n} (f g) : (s.map_active_threads ac f).map_active_threads ac g = s.map_active_threads ac (λ ts, g (f ts)) := begin
simp [map_active_threads],
apply vector.eq_element_wise,
intro,
simp,
by_cases h : vector.nth ac i = tt,
{ simp *, },
{ simp at h, simp *, },
end
lemma map_threads_all_threads_active {s : state n σ τ} {ac : vector bool n} {f} (h : all_threads_active ac) : s.map_threads f = s.map_active_threads ac f := begin
simp [map_active_threads, map_threads],
apply vector.eq_element_wise,
intro,
simp,
by_cases h' : vector.nth ac i = tt,
{ simp *, },
{
unfold all_threads_active list.all at h,
have : _ := all_threads_active_nth h i,
contradiction,
},
end
lemma map_active_threads_id (s : state n σ τ) (ac : vector bool n) : s = s.map_active_threads ac (thread_state.compute id) := begin
cases s,
simp [map_active_threads],
apply vector.eq_element_wise,
simp,
end
lemma map_active_threads_comm {s : state n σ τ} {ac₁ ac₂ : vector bool n} {f g} (h : ac_distinct ac₁ ac₂) :
(s.map_active_threads ac₁ f).map_active_threads ac₂ g = (s.map_active_threads ac₂ g).map_active_threads ac₁ f := begin
simp [map_active_threads],
apply vector.eq_element_wise,
intro i,
repeat { rw vector.nth_map₂},
cases h i,
{
simp[h_1],
by_cases vector.nth ac₂ i = tt,
{ rw h, },
{ simp at h, simp [h], }
}, {
simp[h_1],
by_cases vector.nth ac₁ i = tt,
{ rw h, },
{ simp at h, simp [h], }
}
end
lemma map_active_threads_no_thread_active (s : state n σ τ) (ac : vector bool n) (f)
(h : no_thread_active ac) :
s.map_active_threads ac f = s := begin
unfold map_active_threads,
cases s,
simp,
apply vector.eq_element_wise,
intro i,
simp,
by_cases h' : vector.nth ac i = tt,
{
have : _ := no_threads_active_nth h i,
contradiction,
}, {
rw eq_ff_eq_not_eq_tt at h',
simp *,
}
end
end state
end parlang |
bb7a5ddf983580e3bb4e99d1a5b503a311755aed | b7f22e51856f4989b970961f794f1c435f9b8f78 | /hott/algebra/homotopy_group.hlean | 98c06b11cc805a7f59ad0f85e1d8847d33d42bf2 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 10,381 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
homotopy groups of a pointed space
-/
import .trunc_group types.trunc .group_theory types.nat.hott
open nat eq pointed trunc is_trunc algebra group function equiv unit is_equiv nat
-- TODO: consistently make n an argument before A
namespace eq
definition homotopy_group [reducible] [constructor] (n : ℕ) (A : Type*) : Set* :=
ptrunc 0 (Ω[n] A)
notation `π[`:95 n:0 `]`:0 := homotopy_group n
definition group_homotopy_group [instance] [constructor] [reducible] (n : ℕ) (A : Type*)
: group (π[succ n] A) :=
trunc_group concat inverse idp con.assoc idp_con con_idp con.left_inv
definition group_homotopy_group2 [instance] (k : ℕ) (A : Type*) :
group (carrier (ptrunctype.to_pType (π[k + 1] A))) :=
group_homotopy_group k A
definition comm_group_homotopy_group [constructor] [reducible] (n : ℕ) (A : Type*)
: comm_group (π[succ (succ n)] A) :=
trunc_comm_group concat inverse idp con.assoc idp_con con_idp con.left_inv eckmann_hilton
local attribute comm_group_homotopy_group [instance]
definition ghomotopy_group [constructor] : Π(n : ℕ) [is_succ n] (A : Type*), Group
| (succ n) x A := Group.mk (π[succ n] A) _
definition cghomotopy_group [constructor] :
Π(n : ℕ) [is_at_least_two n] (A : Type*), CommGroup
| (succ (succ n)) x A := CommGroup.mk (π[succ (succ n)] A) _
definition fundamental_group [constructor] (A : Type*) : Group :=
ghomotopy_group 1 A
notation `πg[`:95 n:0 `]`:0 := ghomotopy_group n
notation `πag[`:95 n:0 `]`:0 := cghomotopy_group n
notation `π₁` := fundamental_group -- should this be notation for the group or pointed type?
definition tr_mul_tr {n : ℕ} {A : Type*} (p q : Ω[n + 1] A) :
tr p *[πg[n+1] A] tr q = tr (p ⬝ q) :=
by reflexivity
definition tr_mul_tr' {n : ℕ} {A : Type*} (p q : Ω[succ n] A)
: tr p *[π[succ n] A] tr q = tr (p ⬝ q) :=
idp
definition homotopy_group_pequiv [constructor] (n : ℕ) {A B : Type*} (H : A ≃* B)
: π[n] A ≃* π[n] B :=
ptrunc_pequiv_ptrunc 0 (loopn_pequiv_loopn n H)
definition homotopy_group_pequiv_loop_ptrunc [constructor] (k : ℕ) (A : Type*) :
π[k] A ≃* Ω[k] (ptrunc k A) :=
begin
refine !loopn_ptrunc_pequiv⁻¹ᵉ* ⬝e* _,
exact loopn_pequiv_loopn k (pequiv_of_eq begin rewrite [trunc_index.zero_add] end)
end
open trunc_index
definition homotopy_group_ptrunc_of_le [constructor] {k n : ℕ} (H : k ≤ n) (A : Type*) :
π[k] (ptrunc n A) ≃* π[k] A :=
calc
π[k] (ptrunc n A) ≃* Ω[k] (ptrunc k (ptrunc n A))
: homotopy_group_pequiv_loop_ptrunc k (ptrunc n A)
... ≃* Ω[k] (ptrunc k A)
: loopn_pequiv_loopn k (ptrunc_ptrunc_pequiv_left A (of_nat_le_of_nat H))
... ≃* π[k] A : (homotopy_group_pequiv_loop_ptrunc k A)⁻¹ᵉ*
definition homotopy_group_ptrunc [constructor] (k : ℕ) (A : Type*) :
π[k] (ptrunc k A) ≃* π[k] A :=
homotopy_group_ptrunc_of_le (le.refl k) A
theorem trivial_homotopy_of_is_set (A : Type*) [H : is_set A] (n : ℕ) : πg[n+1] A ≃g G0 :=
begin
apply trivial_group_of_is_contr,
apply is_trunc_trunc_of_is_trunc,
apply is_contr_loop_of_is_trunc,
apply is_trunc_succ_succ_of_is_set
end
definition homotopy_group_succ_out (A : Type*) (n : ℕ) : π[n + 1] A = π₁ (Ω[n] A) := idp
definition homotopy_group_succ_in (A : Type*) (n : ℕ) : π[n + 1] A ≃* π[n] (Ω A) :=
ptrunc_pequiv_ptrunc 0 (loopn_succ_in A n)
definition ghomotopy_group_succ_out (A : Type*) (n : ℕ) : πg[n + 1] A = π₁ (Ω[n] A) := idp
definition homotopy_group_succ_in_con {A : Type*} {n : ℕ} (g h : πg[n + 2] A) :
homotopy_group_succ_in A (succ n) (g * h) =
homotopy_group_succ_in A (succ n) g * homotopy_group_succ_in A (succ n) h :=
begin
induction g with p, induction h with q, esimp,
apply ap tr, apply loopn_succ_in_con
end
definition ghomotopy_group_succ_in (A : Type*) (n : ℕ) : πg[n + 2] A ≃g πg[n + 1] (Ω A) :=
begin
fapply isomorphism_of_equiv,
{ exact homotopy_group_succ_in A (succ n)},
{ exact homotopy_group_succ_in_con},
end
definition homotopy_group_functor [constructor] (n : ℕ) {A B : Type*} (f : A →* B)
: π[n] A →* π[n] B :=
ptrunc_functor 0 (apn n f)
notation `π→[`:95 n:0 `]`:0 := homotopy_group_functor n
definition homotopy_group_functor_phomotopy [constructor] (n : ℕ) {A B : Type*} {f g : A →* B}
(p : f ~* g) : π→[n] f ~* π→[n] g :=
ptrunc_functor_phomotopy 0 (apn_phomotopy n p)
definition homotopy_group_functor_compose [constructor] (n : ℕ) {A B C : Type*} (g : B →* C)
(f : A →* B) : π→[n] (g ∘* f) ~* π→[n] g ∘* π→[n] f :=
ptrunc_functor_phomotopy 0 !apn_pcompose ⬝* !ptrunc_functor_pcompose
definition is_equiv_homotopy_group_functor [constructor] (n : ℕ) {A B : Type*} (f : A →* B)
[is_equiv f] : is_equiv (π→[n] f) :=
@(is_equiv_trunc_functor 0 _) !is_equiv_apn
definition homotopy_group_functor_succ_phomotopy_in (n : ℕ) {A B : Type*} (f : A →* B) :
homotopy_group_succ_in B n ∘* π→[n + 1] f ~*
π→[n] (Ω→ f) ∘* homotopy_group_succ_in A n :=
begin
refine !ptrunc_functor_pcompose⁻¹* ⬝* _ ⬝* !ptrunc_functor_pcompose,
exact ptrunc_functor_phomotopy 0 (apn_succ_phomotopy_in n f)
end
definition is_equiv_homotopy_group_functor_ap1 (n : ℕ) {A B : Type*} (f : A →* B)
[is_equiv (π→[n + 1] f)] : is_equiv (π→[n] (Ω→ f)) :=
have is_equiv (homotopy_group_succ_in B n ∘* π→[n + 1] f),
from is_equiv_compose _ (π→[n + 1] f),
have is_equiv (π→[n] (Ω→ f) ∘ homotopy_group_succ_in A n),
from is_equiv.homotopy_closed _ (homotopy_group_functor_succ_phomotopy_in n f),
is_equiv.cancel_right (homotopy_group_succ_in A n) _
definition tinverse [constructor] {X : Type*} : π[1] X →* π[1] X :=
ptrunc_functor 0 pinverse
definition is_equiv_tinverse [constructor] (A : Type*) : is_equiv (@tinverse A) :=
by apply @is_equiv_trunc_functor; apply is_equiv_eq_inverse
definition ptrunc_functor_pinverse [constructor] {X : Type*}
: ptrunc_functor 0 (@pinverse X) ~* @tinverse X :=
begin
fapply phomotopy.mk,
{ reflexivity},
{ reflexivity}
end
definition homotopy_group_functor_mul [constructor] (n : ℕ) {A B : Type*} (g : A →* B)
(p q : πg[n+1] A) :
(π→[n + 1] g) (p *[πg[n+1] A] q) = (π→[n+1] g) p *[πg[n+1] B] (π→[n + 1] g) q :=
begin
unfold [ghomotopy_group, homotopy_group] at *,
refine @trunc.rec _ _ _ (λq, !is_trunc_eq) _ p, clear p, intro p,
refine @trunc.rec _ _ _ (λq, !is_trunc_eq) _ q, clear q, intro q,
apply ap tr, apply apn_con
end
definition homotopy_group_homomorphism [constructor] (n : ℕ) [H : is_succ n] {A B : Type*}
(f : A →* B) : πg[n] A →g πg[n] B :=
begin
induction H with n, fconstructor,
{ exact homotopy_group_functor (n+1) f},
{ apply homotopy_group_functor_mul}
end
notation `π→g[`:95 n:0 `]`:0 := homotopy_group_homomorphism n
definition homotopy_group_isomorphism_of_pequiv [constructor] (n : ℕ) {A B : Type*} (f : A ≃* B)
: πg[n+1] A ≃g πg[n+1] B :=
begin
apply isomorphism.mk (homotopy_group_homomorphism (succ n) f),
esimp, apply is_equiv_trunc_functor, apply is_equiv_apn,
end
definition homotopy_group_add (A : Type*) (n m : ℕ) :
πg[n+m+1] A ≃g πg[n+1] (Ω[m] A) :=
begin
revert A, induction m with m IH: intro A,
{ reflexivity},
{ esimp [loopn, nat.add], refine !ghomotopy_group_succ_in ⬝g _, refine !IH ⬝g _,
apply homotopy_group_isomorphism_of_pequiv,
exact !loopn_succ_in⁻¹ᵉ*}
end
theorem trivial_homotopy_add_of_is_set_loopn {A : Type*} {n : ℕ} (m : ℕ)
(H : is_set (Ω[n] A)) : πg[m+n+1] A ≃g G0 :=
!homotopy_group_add ⬝g !trivial_homotopy_of_is_set
theorem trivial_homotopy_le_of_is_set_loopn {A : Type*} {n : ℕ} (m : ℕ) (H1 : n ≤ m)
(H2 : is_set (Ω[n] A)) : πg[m+1] A ≃g G0 :=
obtain (k : ℕ) (p : n + k = m), from le.elim H1,
isomorphism_of_eq (ap (λx, πg[x+1] A) (p⁻¹ ⬝ add.comm n k)) ⬝g
trivial_homotopy_add_of_is_set_loopn k H2
definition homotopy_group_pequiv_loop_ptrunc_con {k : ℕ} {A : Type*} (p q : πg[k +1] A) :
homotopy_group_pequiv_loop_ptrunc (succ k) A (p * q) =
homotopy_group_pequiv_loop_ptrunc (succ k) A p ⬝
homotopy_group_pequiv_loop_ptrunc (succ k) A q :=
begin
refine _ ⬝ !loopn_pequiv_loopn_con,
exact ap (loopn_pequiv_loopn _ _) !loopn_ptrunc_pequiv_inv_con
end
definition homotopy_group_pequiv_loop_ptrunc_inv_con {k : ℕ} {A : Type*}
(p q : Ω[succ k] (ptrunc (succ k) A)) :
(homotopy_group_pequiv_loop_ptrunc (succ k) A)⁻¹ᵉ* (p ⬝ q) =
(homotopy_group_pequiv_loop_ptrunc (succ k) A)⁻¹ᵉ* p *
(homotopy_group_pequiv_loop_ptrunc (succ k) A)⁻¹ᵉ* q :=
inv_preserve_binary (homotopy_group_pequiv_loop_ptrunc (succ k) A) mul concat
(@homotopy_group_pequiv_loop_ptrunc_con k A) p q
definition ghomotopy_group_ptrunc [constructor] (k : ℕ) (A : Type*) :
πg[k+1] (ptrunc (k+1) A) ≃g πg[k+1] A :=
begin
fapply isomorphism_of_equiv,
{ exact homotopy_group_ptrunc (k+1) A},
{ intro g₁ g₂, esimp,
refine _ ⬝ !homotopy_group_pequiv_loop_ptrunc_inv_con,
apply ap ((homotopy_group_pequiv_loop_ptrunc (k+1) A)⁻¹ᵉ*),
refine _ ⬝ !loopn_pequiv_loopn_con ,
apply ap (loopn_pequiv_loopn (k+1) _),
apply homotopy_group_pequiv_loop_ptrunc_con}
end
/- some homomorphisms -/
-- definition is_homomorphism_cast_loopn_succ_eq_in {A : Type*} (n : ℕ) :
-- is_homomorphism (loopn_succ_in A (succ n) : πg[n+1+1] A → πg[n+1] (Ω A)) :=
-- begin
-- intro g h, induction g with g, induction h with h,
-- xrewrite [tr_mul_tr, - + fn_cast_eq_cast_fn _ (λn, tr), tr_mul_tr, ↑cast, -tr_compose,
-- loopn_succ_eq_in_concat, - + tr_compose],
-- end
definition is_homomorphism_inverse (A : Type*) (n : ℕ)
: is_homomorphism (λp, p⁻¹ : (πag[n+2] A) → (πag[n+2] A)) :=
begin
intro g h, exact ap inv (mul.comm g h) ⬝ mul_inv h g,
end
end eq
|
21ddd19722649711833d3ca2fcca6da4a6f78356 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/continuous_function/bounded.lean | ff0b98316870ddb371000fd818bdd915f59da165 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 61,375 | lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Mario Carneiro, Yury Kudryashov, Heather Macbeth
-/
import analysis.normed.order.lattice
import analysis.normed_space.operator_norm
import analysis.normed_space.star.basic
import data.real.sqrt
import topology.continuous_function.algebra
/-!
# Bounded continuous functions
The type of bounded continuous functions taking values in a metric space, with
the uniform distance.
-/
noncomputable theory
open_locale topological_space classical nnreal
open set filter metric function
universes u v w
variables {F : Type*} {α : Type u} {β : Type v} {γ : Type w}
/-- `α →ᵇ β` is the type of bounded continuous functions `α → β` from a topological space to a
metric space.
When possible, instead of parametrizing results over `(f : α →ᵇ β)`,
you should parametrize over `(F : Type*) [bounded_continuous_map_class F α β] (f : F)`.
When you extend this structure, make sure to extend `bounded_continuous_map_class`. -/
structure bounded_continuous_function (α : Type u) (β : Type v)
[topological_space α] [pseudo_metric_space β] extends continuous_map α β :
Type (max u v) :=
(map_bounded' : ∃ C, ∀ x y, dist (to_fun x) (to_fun y) ≤ C)
localized "infixr (name := bounded_continuous_function)
` →ᵇ `:25 := bounded_continuous_function" in bounded_continuous_function
section
set_option old_structure_cmd true
/-- `bounded_continuous_map_class F α β` states that `F` is a type of bounded continuous maps.
You should also extend this typeclass when you extend `bounded_continuous_function`. -/
class bounded_continuous_map_class (F α β : Type*) [topological_space α] [pseudo_metric_space β]
extends continuous_map_class F α β :=
(map_bounded (f : F) : ∃ C, ∀ x y, dist (f x) (f y) ≤ C)
end
export bounded_continuous_map_class (map_bounded)
namespace bounded_continuous_function
section basics
variables [topological_space α] [pseudo_metric_space β] [pseudo_metric_space γ]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
instance : bounded_continuous_map_class (α →ᵇ β) α β :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, by { obtain ⟨⟨_, _⟩, _⟩ := f, obtain ⟨⟨_, _⟩, _⟩ := g, congr' },
map_continuous := λ f, f.continuous_to_fun,
map_bounded := λ f, f.map_bounded' }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (α →ᵇ β) (λ _, α → β) := fun_like.has_coe_to_fun
instance [bounded_continuous_map_class F α β] : has_coe_t F (α →ᵇ β) :=
⟨λ f, { to_fun := f, continuous_to_fun := map_continuous f, map_bounded' := map_bounded f }⟩
@[simp] lemma coe_to_continuous_fun (f : α →ᵇ β) : (f.to_continuous_map : α → β) = f := rfl
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : α →ᵇ β) : α → β := h
initialize_simps_projections bounded_continuous_function (to_continuous_map_to_fun → apply)
protected lemma bounded (f : α →ᵇ β) : ∃C, ∀ x y : α, dist (f x) (f y) ≤ C := f.map_bounded'
protected lemma continuous (f : α →ᵇ β) : continuous f := f.to_continuous_map.continuous
@[ext] lemma ext (h : ∀ x, f x = g x) : f = g := fun_like.ext _ _ h
lemma bounded_range (f : α →ᵇ β) : bounded (range f) :=
bounded_range_iff.2 f.bounded
lemma bounded_image (f : α →ᵇ β) (s : set α) : bounded (f '' s) :=
f.bounded_range.mono $ image_subset_range _ _
lemma eq_of_empty [is_empty α] (f g : α →ᵇ β) : f = g :=
ext $ is_empty.elim ‹_›
/-- A continuous function with an explicit bound is a bounded continuous function. -/
def mk_of_bound (f : C(α, β)) (C : ℝ) (h : ∀ x y : α, dist (f x) (f y) ≤ C) : α →ᵇ β :=
⟨f, ⟨C, h⟩⟩
@[simp] lemma mk_of_bound_coe {f} {C} {h} : (mk_of_bound f C h : α → β) = (f : α → β) :=
rfl
/-- A continuous function on a compact space is automatically a bounded continuous function. -/
def mk_of_compact [compact_space α] (f : C(α, β)) : α →ᵇ β :=
⟨f, bounded_range_iff.1 (is_compact_range f.continuous).bounded⟩
@[simp] lemma mk_of_compact_apply [compact_space α] (f : C(α, β)) (a : α) :
mk_of_compact f a = f a :=
rfl
/-- If a function is bounded on a discrete space, it is automatically continuous,
and therefore gives rise to an element of the type of bounded continuous functions -/
@[simps] def mk_of_discrete [discrete_topology α] (f : α → β)
(C : ℝ) (h : ∀ x y : α, dist (f x) (f y) ≤ C) : α →ᵇ β :=
⟨⟨f, continuous_of_discrete_topology⟩, ⟨C, h⟩⟩
/-- The uniform distance between two bounded continuous functions -/
instance : has_dist (α →ᵇ β) :=
⟨λf g, Inf {C | 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C}⟩
lemma dist_eq : dist f g = Inf {C | 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C} := rfl
lemma dist_set_exists : ∃ C, 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C :=
begin
rcases f.bounded_range.union g.bounded_range with ⟨C, hC⟩,
refine ⟨max 0 C, le_max_left _ _, λ x, (hC _ _ _ _).trans (le_max_right _ _)⟩;
[left, right]; apply mem_range_self
end
/-- The pointwise distance is controlled by the distance between functions, by definition. -/
lemma dist_coe_le_dist (x : α) : dist (f x) (g x) ≤ dist f g :=
le_cInf dist_set_exists $ λb hb, hb.2 x
/- This lemma will be needed in the proof of the metric space instance, but it will become
useless afterwards as it will be superseded by the general result that the distance is nonnegative
in metric spaces. -/
private lemma dist_nonneg' : 0 ≤ dist f g :=
le_cInf dist_set_exists (λ C, and.left)
/-- The distance between two functions is controlled by the supremum of the pointwise distances -/
lemma dist_le (C0 : (0 : ℝ) ≤ C) : dist f g ≤ C ↔ ∀x:α, dist (f x) (g x) ≤ C :=
⟨λ h x, le_trans (dist_coe_le_dist x) h, λ H, cInf_le ⟨0, λ C, and.left⟩ ⟨C0, H⟩⟩
lemma dist_le_iff_of_nonempty [nonempty α] :
dist f g ≤ C ↔ ∀ x, dist (f x) (g x) ≤ C :=
⟨λ h x, le_trans (dist_coe_le_dist x) h,
λ w, (dist_le (le_trans dist_nonneg (w (nonempty.some ‹_›)))).mpr w⟩
lemma dist_lt_of_nonempty_compact [nonempty α] [compact_space α]
(w : ∀x:α, dist (f x) (g x) < C) : dist f g < C :=
begin
have c : continuous (λ x, dist (f x) (g x)), { continuity, },
obtain ⟨x, -, le⟩ :=
is_compact.exists_forall_ge is_compact_univ set.univ_nonempty (continuous.continuous_on c),
exact lt_of_le_of_lt (dist_le_iff_of_nonempty.mpr (λ y, le y trivial)) (w x),
end
lemma dist_lt_iff_of_compact [compact_space α] (C0 : (0 : ℝ) < C) :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
begin
fsplit,
{ intros w x,
exact lt_of_le_of_lt (dist_coe_le_dist x) w, },
{ by_cases h : nonempty α,
{ resetI,
exact dist_lt_of_nonempty_compact, },
{ rintro -,
convert C0,
apply le_antisymm _ dist_nonneg',
rw [dist_eq],
exact cInf_le ⟨0, λ C, and.left⟩ ⟨le_rfl, λ x, false.elim (h (nonempty.intro x))⟩, }, },
end
lemma dist_lt_iff_of_nonempty_compact [nonempty α] [compact_space α] :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
⟨λ w x, lt_of_le_of_lt (dist_coe_le_dist x) w, dist_lt_of_nonempty_compact⟩
/-- The type of bounded continuous functions, with the uniform distance, is a pseudometric space. -/
instance : pseudo_metric_space (α →ᵇ β) :=
{ dist_self := λ f, le_antisymm ((dist_le le_rfl).2 $ λ x, by simp) dist_nonneg',
dist_comm := λ f g, by simp [dist_eq, dist_comm],
dist_triangle := λ f g h,
(dist_le (add_nonneg dist_nonneg' dist_nonneg')).2 $ λ x,
le_trans (dist_triangle _ _ _) (add_le_add (dist_coe_le_dist _) (dist_coe_le_dist _)) }
/-- The type of bounded continuous functions, with the uniform distance, is a metric space. -/
instance {α β} [topological_space α] [metric_space β] : metric_space (α →ᵇ β) :=
{ eq_of_dist_eq_zero := λ f g hfg, by ext x; exact
eq_of_dist_eq_zero (le_antisymm (hfg ▸ dist_coe_le_dist _) dist_nonneg) }
lemma nndist_eq : nndist f g = Inf {C | ∀ x : α, nndist (f x) (g x) ≤ C} :=
subtype.ext $ dist_eq.trans $ begin
rw [nnreal.coe_Inf, nnreal.coe_image],
simp_rw [mem_set_of_eq, ←nnreal.coe_le_coe, subtype.coe_mk, exists_prop, coe_nndist],
end
lemma nndist_set_exists : ∃ C, ∀ x : α, nndist (f x) (g x) ≤ C :=
subtype.exists.mpr $ dist_set_exists.imp $ λ a ⟨ha, h⟩, ⟨ha, h⟩
lemma nndist_coe_le_nndist (x : α) : nndist (f x) (g x) ≤ nndist f g :=
dist_coe_le_dist x
/-- On an empty space, bounded continuous functions are at distance 0 -/
lemma dist_zero_of_empty [is_empty α] : dist f g = 0 :=
by rw [(ext is_empty_elim : f = g), dist_self]
lemma dist_eq_supr : dist f g = ⨆ x : α, dist (f x) (g x) :=
begin
casesI is_empty_or_nonempty α, { rw [supr_of_empty', real.Sup_empty, dist_zero_of_empty] },
refine (dist_le_iff_of_nonempty.mpr $ le_csupr _).antisymm (csupr_le dist_coe_le_dist),
exact dist_set_exists.imp (λ C hC, forall_range_iff.2 hC.2)
end
lemma nndist_eq_supr : nndist f g = ⨆ x : α, nndist (f x) (g x) :=
subtype.ext $ dist_eq_supr.trans $ by simp_rw [nnreal.coe_supr, coe_nndist]
lemma tendsto_iff_tendsto_uniformly {ι : Type*} {F : ι → (α →ᵇ β)} {f : α →ᵇ β} {l : filter ι} :
tendsto F l (𝓝 f) ↔ tendsto_uniformly (λ i, F i) f l :=
iff.intro
(λ h, tendsto_uniformly_iff.2
(λ ε ε0, (metric.tendsto_nhds.mp h ε ε0).mp (eventually_of_forall $
λ n hn x, lt_of_le_of_lt (dist_coe_le_dist x) (dist_comm (F n) f ▸ hn))))
(λ h, metric.tendsto_nhds.mpr $ λ ε ε_pos,
(h _ (dist_mem_uniformity $ half_pos ε_pos)).mp (eventually_of_forall $
λ n hn, lt_of_le_of_lt ((dist_le (half_pos ε_pos).le).mpr $
λ x, dist_comm (f x) (F n x) ▸ le_of_lt (hn x)) (half_lt_self ε_pos)))
variables (α) {β}
/-- Constant as a continuous bounded function. -/
@[simps {fully_applied := ff}] def const (b : β) : α →ᵇ β :=
⟨continuous_map.const α b, 0, by simp [le_rfl]⟩
variable {α}
lemma const_apply' (a : α) (b : β) : (const α b : α → β) a = b := rfl
/-- If the target space is inhabited, so is the space of bounded continuous functions -/
instance [inhabited β] : inhabited (α →ᵇ β) := ⟨const α default⟩
lemma lipschitz_evalx (x : α) : lipschitz_with 1 (λ f : α →ᵇ β, f x) :=
lipschitz_with.mk_one $ λ f g, dist_coe_le_dist x
theorem uniform_continuous_coe : @uniform_continuous (α →ᵇ β) (α → β) _ _ coe_fn :=
uniform_continuous_pi.2 $ λ x, (lipschitz_evalx x).uniform_continuous
lemma continuous_coe : continuous (λ (f : α →ᵇ β) x, f x) :=
uniform_continuous.continuous uniform_continuous_coe
/-- When `x` is fixed, `(f : α →ᵇ β) ↦ f x` is continuous -/
@[continuity] theorem continuous_eval_const {x : α} : continuous (λ f : α →ᵇ β, f x) :=
(continuous_apply x).comp continuous_coe
/-- The evaluation map is continuous, as a joint function of `u` and `x` -/
@[continuity] theorem continuous_eval : continuous (λ p : (α →ᵇ β) × α, p.1 p.2) :=
continuous_prod_of_continuous_lipschitz _ 1 (λ f, f.continuous) $ lipschitz_evalx
/-- Bounded continuous functions taking values in a complete space form a complete space. -/
instance [complete_space β] : complete_space (α →ᵇ β) :=
complete_of_cauchy_seq_tendsto $ λ (f : ℕ → α →ᵇ β) (hf : cauchy_seq f),
begin
/- We have to show that `f n` converges to a bounded continuous function.
For this, we prove pointwise convergence to define the limit, then check
it is a continuous bounded function, and then check the norm convergence. -/
rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩,
have f_bdd := λx n m N hn hm, le_trans (dist_coe_le_dist x) (b_bound n m N hn hm),
have fx_cau : ∀x, cauchy_seq (λn, f n x) :=
λx, cauchy_seq_iff_le_tendsto_0.2 ⟨b, b0, f_bdd x, b_lim⟩,
choose F hF using λx, cauchy_seq_tendsto_of_complete (fx_cau x),
/- F : α → β, hF : ∀ (x : α), tendsto (λ (n : ℕ), f n x) at_top (𝓝 (F x))
`F` is the desired limit function. Check that it is uniformly approximated by `f N` -/
have fF_bdd : ∀x N, dist (f N x) (F x) ≤ b N :=
λ x N, le_of_tendsto (tendsto_const_nhds.dist (hF x))
(filter.eventually_at_top.2 ⟨N, λn hn, f_bdd x N n N (le_refl N) hn⟩),
refine ⟨⟨⟨F, _⟩, _⟩, _⟩,
{ /- Check that `F` is continuous, as a uniform limit of continuous functions -/
have : tendsto_uniformly (λn x, f n x) F at_top,
{ refine metric.tendsto_uniformly_iff.2 (λ ε ε0, _),
refine ((tendsto_order.1 b_lim).2 ε ε0).mono (λ n hn x, _),
rw dist_comm,
exact lt_of_le_of_lt (fF_bdd x n) hn },
exact this.continuous (eventually_of_forall $ λ N, (f N).continuous) },
{ /- Check that `F` is bounded -/
rcases (f 0).bounded with ⟨C, hC⟩,
refine ⟨C + (b 0 + b 0), λ x y, _⟩,
calc dist (F x) (F y) ≤ dist (f 0 x) (f 0 y) + (dist (f 0 x) (F x) + dist (f 0 y) (F y)) :
dist_triangle4_left _ _ _ _
... ≤ C + (b 0 + b 0) : by mono* },
{ /- Check that `F` is close to `f N` in distance terms -/
refine tendsto_iff_dist_tendsto_zero.2 (squeeze_zero (λ _, dist_nonneg) _ b_lim),
exact λ N, (dist_le (b0 _)).2 (λx, fF_bdd x N) }
end
/-- Composition of a bounded continuous function and a continuous function. -/
@[simps { fully_applied := ff }]
def comp_continuous {δ : Type*} [topological_space δ] (f : α →ᵇ β) (g : C(δ, α)) : δ →ᵇ β :=
{ to_continuous_map := f.1.comp g,
map_bounded' := f.map_bounded'.imp (λ C hC x y, hC _ _) }
lemma lipschitz_comp_continuous {δ : Type*} [topological_space δ] (g : C(δ, α)) :
lipschitz_with 1 (λ f : α →ᵇ β, f.comp_continuous g) :=
lipschitz_with.mk_one $ λ f₁ f₂, (dist_le dist_nonneg).2 $ λ x, dist_coe_le_dist (g x)
lemma continuous_comp_continuous {δ : Type*} [topological_space δ] (g : C(δ, α)) :
continuous (λ f : α →ᵇ β, f.comp_continuous g) :=
(lipschitz_comp_continuous g).continuous
/-- Restrict a bounded continuous function to a set. -/
@[simps apply { fully_applied := ff }]
def restrict (f : α →ᵇ β) (s : set α) : s →ᵇ β :=
f.comp_continuous $ (continuous_map.id _).restrict s
/-- Composition (in the target) of a bounded continuous function with a Lipschitz map again
gives a bounded continuous function -/
def comp (G : β → γ) {C : ℝ≥0} (H : lipschitz_with C G)
(f : α →ᵇ β) : α →ᵇ γ :=
⟨⟨λx, G (f x), H.continuous.comp f.continuous⟩,
let ⟨D, hD⟩ := f.bounded in
⟨max C 0 * D, λ x y, calc
dist (G (f x)) (G (f y)) ≤ C * dist (f x) (f y) : H.dist_le_mul _ _
... ≤ max C 0 * dist (f x) (f y) : mul_le_mul_of_nonneg_right (le_max_left C 0) dist_nonneg
... ≤ max C 0 * D : mul_le_mul_of_nonneg_left (hD _ _) (le_max_right C 0)⟩⟩
/-- The composition operator (in the target) with a Lipschitz map is Lipschitz -/
lemma lipschitz_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) :
lipschitz_with C (comp G H : (α →ᵇ β) → α →ᵇ γ) :=
lipschitz_with.of_dist_le_mul $ λ f g,
(dist_le (mul_nonneg C.2 dist_nonneg)).2 $ λ x,
calc dist (G (f x)) (G (g x)) ≤ C * dist (f x) (g x) : H.dist_le_mul _ _
... ≤ C * dist f g : mul_le_mul_of_nonneg_left (dist_coe_le_dist _) C.2
/-- The composition operator (in the target) with a Lipschitz map is uniformly continuous -/
lemma uniform_continuous_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) :
uniform_continuous (comp G H : (α →ᵇ β) → α →ᵇ γ) :=
(lipschitz_comp H).uniform_continuous
/-- The composition operator (in the target) with a Lipschitz map is continuous -/
lemma continuous_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) :
continuous (comp G H : (α →ᵇ β) → α →ᵇ γ) :=
(lipschitz_comp H).continuous
/-- Restriction (in the target) of a bounded continuous function taking values in a subset -/
def cod_restrict (s : set β) (f : α →ᵇ β) (H : ∀x, f x ∈ s) : α →ᵇ s :=
⟨⟨s.cod_restrict f H, f.continuous.subtype_mk _⟩, f.bounded⟩
section extend
variables {δ : Type*} [topological_space δ] [discrete_topology δ]
/-- A version of `function.extend` for bounded continuous maps. We assume that the domain has
discrete topology, so we only need to verify boundedness. -/
def extend (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) : δ →ᵇ β :=
{ to_fun := extend f g h,
continuous_to_fun := continuous_of_discrete_topology,
map_bounded' :=
begin
rw [← bounded_range_iff, range_extend f.injective, metric.bounded_union],
exact ⟨g.bounded_range, h.bounded_image _⟩
end }
@[simp] lemma extend_apply (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) (x : α) :
extend f g h (f x) = g x :=
f.injective.extend_apply _ _ _
@[simp] lemma extend_comp (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) : extend f g h ∘ f = g :=
extend_comp f.injective _ _
lemma extend_apply' {f : α ↪ δ} {x : δ} (hx : x ∉ range f) (g : α →ᵇ β) (h : δ →ᵇ β) :
extend f g h x = h x :=
extend_apply' _ _ _ hx
lemma extend_of_empty [is_empty α] (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) :
extend f g h = h :=
fun_like.coe_injective $ function.extend_of_empty f g h
@[simp] lemma dist_extend_extend (f : α ↪ δ) (g₁ g₂ : α →ᵇ β) (h₁ h₂ : δ →ᵇ β) :
dist (g₁.extend f h₁) (g₂.extend f h₂) =
max (dist g₁ g₂) (dist (h₁.restrict (range f)ᶜ) (h₂.restrict (range f)ᶜ)) :=
begin
refine le_antisymm ((dist_le $ le_max_iff.2 $ or.inl dist_nonneg).2 $ λ x, _) (max_le _ _),
{ rcases em (∃ y, f y = x) with (⟨x, rfl⟩|hx),
{ simp only [extend_apply],
exact (dist_coe_le_dist x).trans (le_max_left _ _) },
{ simp only [extend_apply' hx],
lift x to ((range f)ᶜ : set δ) using hx,
calc dist (h₁ x) (h₂ x) = dist (h₁.restrict (range f)ᶜ x) (h₂.restrict (range f)ᶜ x) : rfl
... ≤ dist (h₁.restrict (range f)ᶜ) (h₂.restrict (range f)ᶜ) : dist_coe_le_dist x
... ≤ _ : le_max_right _ _ } },
{ refine (dist_le dist_nonneg).2 (λ x, _),
rw [← extend_apply f g₁ h₁, ← extend_apply f g₂ h₂],
exact dist_coe_le_dist _ },
{ refine (dist_le dist_nonneg).2 (λ x, _),
calc dist (h₁ x) (h₂ x) = dist (extend f g₁ h₁ x) (extend f g₂ h₂ x) :
by rw [extend_apply' x.coe_prop, extend_apply' x.coe_prop]
... ≤ _ : dist_coe_le_dist _ }
end
lemma isometry_extend (f : α ↪ δ) (h : δ →ᵇ β) :
isometry (λ g : α →ᵇ β, extend f g h) :=
isometry.of_dist_eq $ λ g₁ g₂, by simp [dist_nonneg]
end extend
end basics
section arzela_ascoli
variables [topological_space α] [compact_space α] [pseudo_metric_space β]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
/- Arzela-Ascoli theorem asserts that, on a compact space, a set of functions sharing
a common modulus of continuity and taking values in a compact set forms a compact
subset for the topology of uniform convergence. In this section, we prove this theorem
and several useful variations around it. -/
/-- First version, with pointwise equicontinuity and range in a compact space -/
theorem arzela_ascoli₁ [compact_space β]
(A : set (α →ᵇ β))
(closed : is_closed A)
(H : ∀ (x:α) (ε > 0), ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε) :
is_compact A :=
begin
refine is_compact_of_totally_bounded_is_closed _ closed,
refine totally_bounded_of_finite_discretization (λ ε ε0, _),
rcases exists_between ε0 with ⟨ε₁, ε₁0, εε₁⟩,
let ε₂ := ε₁/2/2,
/- We have to find a finite discretization of `u`, i.e., finite information
that is sufficient to reconstruct `u` up to ε. This information will be
provided by the values of `u` on a sufficiently dense set tα,
slightly translated to fit in a finite ε₂-dense set tβ in the image. Such
sets exist by compactness of the source and range. Then, to check that these
data determine the function up to ε, one uses the control on the modulus of
continuity to extend the closeness on tα to closeness everywhere. -/
have ε₂0 : ε₂ > 0 := half_pos (half_pos ε₁0),
have : ∀x:α, ∃U, x ∈ U ∧ is_open U ∧ ∀ (y z ∈ U) {f : α →ᵇ β},
f ∈ A → dist (f y) (f z) < ε₂ := λ x,
let ⟨U, nhdsU, hU⟩ := H x _ ε₂0,
⟨V, VU, openV, xV⟩ := _root_.mem_nhds_iff.1 nhdsU in
⟨V, xV, openV, λy hy z hz f hf, hU y (VU hy) z (VU hz) f hf⟩,
choose U hU using this,
/- For all x, the set hU x is an open set containing x on which the elements of A
fluctuate by at most ε₂.
We extract finitely many of these sets that cover the whole space, by compactness -/
rcases is_compact_univ.elim_finite_subcover_image
(λx _, (hU x).2.1) (λx hx, mem_bUnion (mem_univ _) (hU x).1)
with ⟨tα, _, ⟨_⟩, htα⟩,
/- tα : set α, htα : univ ⊆ ⋃x ∈ tα, U x -/
rcases @finite_cover_balls_of_compact β _ _ is_compact_univ _ ε₂0
with ⟨tβ, _, ⟨_⟩, htβ⟩, resetI,
/- tβ : set β, htβ : univ ⊆ ⋃y ∈ tβ, ball y ε₂ -/
/- Associate to every point `y` in the space a nearby point `F y` in tβ -/
choose F hF using λy, show ∃z∈tβ, dist y z < ε₂, by simpa using htβ (mem_univ y),
/- F : β → β, hF : ∀ (y : β), F y ∈ tβ ∧ dist y (F y) < ε₂ -/
/- Associate to every function a discrete approximation, mapping each point in `tα`
to a point in `tβ` close to its true image by the function. -/
refine ⟨tα → tβ, by apply_instance, λ f a, ⟨F (f a), (hF (f a)).1⟩, _⟩,
rintro ⟨f, hf⟩ ⟨g, hg⟩ f_eq_g,
/- If two functions have the same approximation, then they are within distance ε -/
refine lt_of_le_of_lt ((dist_le $ le_of_lt ε₁0).2 (λ x, _)) εε₁,
obtain ⟨x', x'tα, hx'⟩ : ∃x' ∈ tα, x ∈ U x' := mem_Union₂.1 (htα (mem_univ x)),
calc dist (f x) (g x)
≤ dist (f x) (f x') + dist (g x) (g x') + dist (f x') (g x') : dist_triangle4_right _ _ _ _
... ≤ ε₂ + ε₂ + ε₁/2 : le_of_lt (add_lt_add (add_lt_add _ _) _)
... = ε₁ : by rw [add_halves, add_halves],
{ exact (hU x').2.2 _ hx' _ ((hU x').1) hf },
{ exact (hU x').2.2 _ hx' _ ((hU x').1) hg },
{ have F_f_g : F (f x') = F (g x') :=
(congr_arg (λ f:tα → tβ, (f ⟨x', x'tα⟩ : β)) f_eq_g : _),
calc dist (f x') (g x')
≤ dist (f x') (F (f x')) + dist (g x') (F (f x')) : dist_triangle_right _ _ _
... = dist (f x') (F (f x')) + dist (g x') (F (g x')) : by rw F_f_g
... < ε₂ + ε₂ : add_lt_add (hF (f x')).2 (hF (g x')).2
... = ε₁/2 : add_halves _ }
end
/-- Second version, with pointwise equicontinuity and range in a compact subset -/
theorem arzela_ascoli₂
(s : set β) (hs : is_compact s)
(A : set (α →ᵇ β))
(closed : is_closed A)
(in_s : ∀(f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s)
(H : ∀(x:α) (ε > 0), ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε) :
is_compact A :=
/- This version is deduced from the previous one by restricting to the compact type in the target,
using compactness there and then lifting everything to the original space. -/
begin
have M : lipschitz_with 1 coe := lipschitz_with.subtype_coe s,
let F : (α →ᵇ s) → α →ᵇ β := comp coe M,
refine is_compact_of_is_closed_subset
((_ : is_compact (F ⁻¹' A)).image (continuous_comp M)) closed (λ f hf, _),
{ haveI : compact_space s := is_compact_iff_compact_space.1 hs,
refine arzela_ascoli₁ _ (continuous_iff_is_closed.1 (continuous_comp M) _ closed)
(λ x ε ε0, bex.imp_right (λ U U_nhds hU y hy z hz f hf, _) (H x ε ε0)),
calc dist (f y) (f z) = dist (F f y) (F f z) : rfl
... < ε : hU y hy z hz (F f) hf },
{ let g := cod_restrict s f (λx, in_s f x hf),
rw [show f = F g, by ext; refl] at hf ⊢,
exact ⟨g, hf, rfl⟩ }
end
/-- Third (main) version, with pointwise equicontinuity and range in a compact subset, but
without closedness. The closure is then compact -/
theorem arzela_ascoli [t2_space β]
(s : set β) (hs : is_compact s)
(A : set (α →ᵇ β))
(in_s : ∀(f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s)
(H : ∀(x:α) (ε > 0), ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε) :
is_compact (closure A) :=
/- This version is deduced from the previous one by checking that the closure of A, in
addition to being closed, still satisfies the properties of compact range and equicontinuity -/
arzela_ascoli₂ s hs (closure A) is_closed_closure
(λ f x hf, (mem_of_closed' hs.is_closed).2 $ λ ε ε0,
let ⟨g, gA, dist_fg⟩ := metric.mem_closure_iff.1 hf ε ε0 in
⟨g x, in_s g x gA, lt_of_le_of_lt (dist_coe_le_dist _) dist_fg⟩)
(λ x ε ε0, show ∃ U ∈ 𝓝 x,
∀ y z ∈ U, ∀ (f : α →ᵇ β), f ∈ closure A → dist (f y) (f z) < ε,
begin
refine bex.imp_right (λ U U_set hU y hy z hz f hf, _) (H x (ε/2) (half_pos ε0)),
rcases metric.mem_closure_iff.1 hf (ε/2/2) (half_pos (half_pos ε0)) with ⟨g, gA, dist_fg⟩,
replace dist_fg := λ x, lt_of_le_of_lt (dist_coe_le_dist x) dist_fg,
calc dist (f y) (f z) ≤ dist (f y) (g y) + dist (f z) (g z) + dist (g y) (g z) :
dist_triangle4_right _ _ _ _
... < ε/2/2 + ε/2/2 + ε/2 :
add_lt_add (add_lt_add (dist_fg y) (dist_fg z)) (hU y hy z hz g gA)
... = ε : by rw [add_halves, add_halves]
end)
/- To apply the previous theorems, one needs to check the equicontinuity. An important
instance is when the source space is a metric space, and there is a fixed modulus of continuity
for all the functions in the set A -/
lemma equicontinuous_of_continuity_modulus {α : Type u} [pseudo_metric_space α]
(b : ℝ → ℝ) (b_lim : tendsto b (𝓝 0) (𝓝 0))
(A : set (α →ᵇ β))
(H : ∀(x y:α) (f : α →ᵇ β), f ∈ A → dist (f x) (f y) ≤ b (dist x y))
(x:α) (ε : ℝ) (ε0 : 0 < ε) : ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε :=
begin
rcases tendsto_nhds_nhds.1 b_lim ε ε0 with ⟨δ, δ0, hδ⟩,
refine ⟨ball x (δ/2), ball_mem_nhds x (half_pos δ0), λ y hy z hz f hf, _⟩,
have : dist y z < δ := calc
dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _
... < δ/2 + δ/2 : add_lt_add hy hz
... = δ : add_halves _,
calc
dist (f y) (f z) ≤ b (dist y z) : H y z f hf
... ≤ |b (dist y z)| : le_abs_self _
... = dist (b (dist y z)) 0 : by simp [real.dist_eq]
... < ε : hδ (by simpa [real.dist_eq] using this),
end
end arzela_ascoli
section has_one
variables [topological_space α] [pseudo_metric_space β] [has_one β]
@[to_additive] instance : has_one (α →ᵇ β) := ⟨const α 1⟩
@[simp, to_additive] lemma coe_one : ((1 : α →ᵇ β) : α → β) = 1 := rfl
@[simp, to_additive]
lemma mk_of_compact_one [compact_space α] : mk_of_compact (1 : C(α, β)) = 1 := rfl
@[to_additive] lemma forall_coe_one_iff_one (f : α →ᵇ β) : (∀ x, f x = 1) ↔ f = 1 :=
(@fun_like.ext_iff _ _ _ _ f 1).symm
@[simp, to_additive] lemma one_comp_continuous [topological_space γ] (f : C(γ, α)) :
(1 : α →ᵇ β).comp_continuous f = 1 := rfl
end has_one
section has_lipschitz_add
/- In this section, if `β` is an `add_monoid` whose addition operation is Lipschitz, then we show
that the space of bounded continuous functions from `α` to `β` inherits a topological `add_monoid`
structure, by using pointwise operations and checking that they are compatible with the uniform
distance.
Implementation note: The material in this section could have been written for `has_lipschitz_mul`
and transported by `@[to_additive]`. We choose not to do this because this causes a few lemma
names (for example, `coe_mul`) to conflict with later lemma names for normed rings; this is only a
trivial inconvenience, but in any case there are no obvious applications of the multiplicative
version. -/
variables [topological_space α] [pseudo_metric_space β] [add_monoid β]
variables [has_lipschitz_add β]
variables (f g : α →ᵇ β) {x : α} {C : ℝ}
/-- The pointwise sum of two bounded continuous functions is again bounded continuous. -/
instance : has_add (α →ᵇ β) :=
{ add := λ f g,
bounded_continuous_function.mk_of_bound (f.to_continuous_map + g.to_continuous_map)
(↑(has_lipschitz_add.C β) * max (classical.some f.bounded) (classical.some g.bounded))
begin
intros x y,
refine le_trans (lipschitz_with_lipschitz_const_add ⟨f x, g x⟩ ⟨f y, g y⟩) _,
rw prod.dist_eq,
refine mul_le_mul_of_nonneg_left _ (has_lipschitz_add.C β).coe_nonneg,
apply max_le_max,
exact classical.some_spec f.bounded x y,
exact classical.some_spec g.bounded x y,
end }
@[simp] lemma coe_add : ⇑(f + g) = f + g := rfl
lemma add_apply : (f + g) x = f x + g x := rfl
@[simp] lemma mk_of_compact_add [compact_space α] (f g : C(α, β)) :
mk_of_compact (f + g) = mk_of_compact f + mk_of_compact g := rfl
lemma add_comp_continuous [topological_space γ] (h : C(γ, α)) :
(g + f).comp_continuous h = g.comp_continuous h + f.comp_continuous h := rfl
@[simp] lemma coe_nsmul_rec : ∀ n, ⇑(nsmul_rec n f) = n • f
| 0 := by rw [nsmul_rec, zero_smul, coe_zero]
| (n + 1) := by rw [nsmul_rec, succ_nsmul, coe_add, coe_nsmul_rec]
instance has_nat_scalar : has_smul ℕ (α →ᵇ β) :=
{ smul := λ n f,
{ to_continuous_map := n • f.to_continuous_map,
map_bounded' := by simpa [coe_nsmul_rec] using (nsmul_rec n f).map_bounded' } }
@[simp] lemma coe_nsmul (r : ℕ) (f : α →ᵇ β) : ⇑(r • f) = r • f := rfl
@[simp] lemma nsmul_apply (r : ℕ) (f : α →ᵇ β) (v : α) : (r • f) v = r • f v := rfl
instance : add_monoid (α →ᵇ β) :=
fun_like.coe_injective.add_monoid _ coe_zero coe_add (λ _ _, coe_nsmul _ _)
instance : has_lipschitz_add (α →ᵇ β) :=
{ lipschitz_add := ⟨has_lipschitz_add.C β, begin
have C_nonneg := (has_lipschitz_add.C β).coe_nonneg,
rw lipschitz_with_iff_dist_le_mul,
rintros ⟨f₁, g₁⟩ ⟨f₂, g₂⟩,
rw dist_le (mul_nonneg C_nonneg dist_nonneg),
intros x,
refine le_trans (lipschitz_with_lipschitz_const_add ⟨f₁ x, g₁ x⟩ ⟨f₂ x, g₂ x⟩) _,
refine mul_le_mul_of_nonneg_left _ C_nonneg,
apply max_le_max; exact dist_coe_le_dist x,
end⟩ }
/-- Coercion of a `normed_add_group_hom` is an `add_monoid_hom`. Similar to
`add_monoid_hom.coe_fn`. -/
@[simps] def coe_fn_add_hom : (α →ᵇ β) →+ (α → β) :=
{ to_fun := coe_fn, map_zero' := coe_zero, map_add' := coe_add }
variables (α β)
/-- The additive map forgetting that a bounded continuous function is bounded.
-/
@[simps] def to_continuous_map_add_hom : (α →ᵇ β) →+ C(α, β) :=
{ to_fun := to_continuous_map,
map_zero' := by { ext, simp, },
map_add' := by { intros, ext, simp, }, }
end has_lipschitz_add
section comm_has_lipschitz_add
variables [topological_space α] [pseudo_metric_space β] [add_comm_monoid β] [has_lipschitz_add β]
@[to_additive] instance : add_comm_monoid (α →ᵇ β) :=
{ add_comm := assume f g, by ext; simp [add_comm],
.. bounded_continuous_function.add_monoid }
open_locale big_operators
@[simp] lemma coe_sum {ι : Type*} (s : finset ι) (f : ι → (α →ᵇ β)) :
⇑(∑ i in s, f i) = (∑ i in s, (f i : α → β)) :=
(@coe_fn_add_hom α β _ _ _ _).map_sum f s
lemma sum_apply {ι : Type*} (s : finset ι) (f : ι → (α →ᵇ β)) (a : α) :
(∑ i in s, f i) a = (∑ i in s, f i a) :=
by simp
end comm_has_lipschitz_add
section normed_add_comm_group
/- In this section, if β is a normed group, then we show that the space of bounded
continuous functions from α to β inherits a normed group structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables [topological_space α] [seminormed_add_comm_group β]
variables (f g : α →ᵇ β) {x : α} {C : ℝ}
instance : has_norm (α →ᵇ β) := ⟨λu, dist u 0⟩
lemma norm_def : ‖f‖ = dist f 0 := rfl
/-- The norm of a bounded continuous function is the supremum of `‖f x‖`.
We use `Inf` to ensure that the definition works if `α` has no elements. -/
lemma norm_eq (f : α →ᵇ β) :
‖f‖ = Inf {C : ℝ | 0 ≤ C ∧ ∀ (x : α), ‖f x‖ ≤ C} :=
by simp [norm_def, bounded_continuous_function.dist_eq]
/-- When the domain is non-empty, we do not need the `0 ≤ C` condition in the formula for ‖f‖ as an
`Inf`. -/
lemma norm_eq_of_nonempty [h : nonempty α] : ‖f‖ = Inf {C : ℝ | ∀ (x : α), ‖f x‖ ≤ C} :=
begin
unfreezingI { obtain ⟨a⟩ := h, },
rw norm_eq,
congr,
ext,
simp only [and_iff_right_iff_imp],
exact λ h', le_trans (norm_nonneg (f a)) (h' a),
end
@[simp] lemma norm_eq_zero_of_empty [h : is_empty α] : ‖f‖ = 0 :=
dist_zero_of_empty
lemma norm_coe_le_norm (x : α) : ‖f x‖ ≤ ‖f‖ := calc
‖f x‖ = dist (f x) ((0 : α →ᵇ β) x) : by simp [dist_zero_right]
... ≤ ‖f‖ : dist_coe_le_dist _
lemma dist_le_two_norm' {f : γ → β} {C : ℝ} (hC : ∀ x, ‖f x‖ ≤ C) (x y : γ) :
dist (f x) (f y) ≤ 2 * C :=
calc dist (f x) (f y) ≤ ‖f x‖ + ‖f y‖ : dist_le_norm_add_norm _ _
... ≤ C + C : add_le_add (hC x) (hC y)
... = 2 * C : (two_mul _).symm
/-- Distance between the images of any two points is at most twice the norm of the function. -/
lemma dist_le_two_norm (x y : α) : dist (f x) (f y) ≤ 2 * ‖f‖ :=
dist_le_two_norm' f.norm_coe_le_norm x y
variable {f}
/-- The norm of a function is controlled by the supremum of the pointwise norms -/
lemma norm_le (C0 : (0 : ℝ) ≤ C) : ‖f‖ ≤ C ↔ ∀x:α, ‖f x‖ ≤ C :=
by simpa using @dist_le _ _ _ _ f 0 _ C0
lemma norm_le_of_nonempty [nonempty α]
{f : α →ᵇ β} {M : ℝ} : ‖f‖ ≤ M ↔ ∀ x, ‖f x‖ ≤ M :=
begin
simp_rw [norm_def, ←dist_zero_right],
exact dist_le_iff_of_nonempty,
end
lemma norm_lt_iff_of_compact [compact_space α]
{f : α →ᵇ β} {M : ℝ} (M0 : 0 < M) : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M :=
begin
simp_rw [norm_def, ←dist_zero_right],
exact dist_lt_iff_of_compact M0,
end
lemma norm_lt_iff_of_nonempty_compact [nonempty α] [compact_space α]
{f : α →ᵇ β} {M : ℝ} : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M :=
begin
simp_rw [norm_def, ←dist_zero_right],
exact dist_lt_iff_of_nonempty_compact,
end
variable (f)
/-- Norm of `const α b` is less than or equal to `‖b‖`. If `α` is nonempty,
then it is equal to `‖b‖`. -/
lemma norm_const_le (b : β) : ‖const α b‖ ≤ ‖b‖ :=
(norm_le (norm_nonneg b)).2 $ λ x, le_rfl
@[simp] lemma norm_const_eq [h : nonempty α] (b : β) : ‖const α b‖ = ‖b‖ :=
le_antisymm (norm_const_le b) $ h.elim $ λ x, (const α b).norm_coe_le_norm x
/-- Constructing a bounded continuous function from a uniformly bounded continuous
function taking values in a normed group. -/
def of_normed_add_comm_group {α : Type u} {β : Type v} [topological_space α]
[seminormed_add_comm_group β] (f : α → β) (Hf : continuous f) (C : ℝ) (H : ∀x, ‖f x‖ ≤ C) :
α →ᵇ β :=
⟨⟨λn, f n, Hf⟩, ⟨_, dist_le_two_norm' H⟩⟩
@[simp] lemma coe_of_normed_add_comm_group
{α : Type u} {β : Type v} [topological_space α] [seminormed_add_comm_group β]
(f : α → β) (Hf : continuous f) (C : ℝ) (H : ∀x, ‖f x‖ ≤ C) :
(of_normed_add_comm_group f Hf C H : α → β) = f := rfl
lemma norm_of_normed_add_comm_group_le {f : α → β} (hfc : continuous f) {C : ℝ} (hC : 0 ≤ C)
(hfC : ∀ x, ‖f x‖ ≤ C) : ‖of_normed_add_comm_group f hfc C hfC‖ ≤ C :=
(norm_le hC).2 hfC
/-- Constructing a bounded continuous function from a uniformly bounded
function on a discrete space, taking values in a normed group -/
def of_normed_add_comm_group_discrete {α : Type u} {β : Type v}
[topological_space α] [discrete_topology α] [seminormed_add_comm_group β]
(f : α → β) (C : ℝ) (H : ∀x, norm (f x) ≤ C) : α →ᵇ β :=
of_normed_add_comm_group f continuous_of_discrete_topology C H
@[simp] lemma coe_of_normed_add_comm_group_discrete {α : Type u} {β : Type v} [topological_space α]
[discrete_topology α] [seminormed_add_comm_group β] (f : α → β) (C : ℝ) (H : ∀x, ‖f x‖ ≤ C) :
(of_normed_add_comm_group_discrete f C H : α → β) = f := rfl
/-- Taking the pointwise norm of a bounded continuous function with values in a
`seminormed_add_comm_group` yields a bounded continuous function with values in ℝ. -/
def norm_comp : α →ᵇ ℝ :=
f.comp norm lipschitz_with_one_norm
@[simp] lemma coe_norm_comp : (f.norm_comp : α → ℝ) = norm ∘ f := rfl
@[simp] lemma norm_norm_comp : ‖f.norm_comp‖ = ‖f‖ :=
by simp only [norm_eq, coe_norm_comp, norm_norm]
lemma bdd_above_range_norm_comp : bdd_above $ set.range $ norm ∘ f :=
(real.bounded_iff_bdd_below_bdd_above.mp $ @bounded_range _ _ _ _ f.norm_comp).2
lemma norm_eq_supr_norm : ‖f‖ = ⨆ x : α, ‖f x‖ :=
by simp_rw [norm_def, dist_eq_supr, coe_zero, pi.zero_apply, dist_zero_right]
/-- If `‖(1 : β)‖ = 1`, then `‖(1 : α →ᵇ β)‖ = 1` if `α` is nonempty. -/
instance [nonempty α] [has_one β] [norm_one_class β] : norm_one_class (α →ᵇ β) :=
{ norm_one := by simp only [norm_eq_supr_norm, coe_one, pi.one_apply, norm_one, csupr_const] }
/-- The pointwise opposite of a bounded continuous function is again bounded continuous. -/
instance : has_neg (α →ᵇ β) :=
⟨λf, of_normed_add_comm_group (-f) f.continuous.neg ‖f‖ $ λ x,
trans_rel_right _ (norm_neg _) (f.norm_coe_le_norm x)⟩
/-- The pointwise difference of two bounded continuous functions is again bounded continuous. -/
instance : has_sub (α →ᵇ β) :=
⟨λf g, of_normed_add_comm_group (f - g) (f.continuous.sub g.continuous) (‖f‖ + ‖g‖) $ λ x,
by { simp only [sub_eq_add_neg],
exact le_trans (norm_add_le _ _) (add_le_add (f.norm_coe_le_norm x) $
trans_rel_right _ (norm_neg _) (g.norm_coe_le_norm x)) }⟩
@[simp] lemma coe_neg : ⇑(-f) = -f := rfl
lemma neg_apply : (-f) x = -f x := rfl
@[simp] lemma coe_sub : ⇑(f - g) = f - g := rfl
lemma sub_apply : (f - g) x = f x - g x := rfl
@[simp] lemma mk_of_compact_neg [compact_space α] (f : C(α, β)) :
mk_of_compact (-f) = -mk_of_compact f := rfl
@[simp] lemma mk_of_compact_sub [compact_space α] (f g : C(α, β)) :
mk_of_compact (f - g) = mk_of_compact f - mk_of_compact g := rfl
@[simp] lemma coe_zsmul_rec : ∀ z, ⇑(zsmul_rec z f) = z • f
| (int.of_nat n) := by rw [zsmul_rec, int.of_nat_eq_coe, coe_nsmul_rec, coe_nat_zsmul]
| -[1+ n] := by rw [zsmul_rec, zsmul_neg_succ_of_nat, coe_neg, coe_nsmul_rec]
instance has_int_scalar : has_smul ℤ (α →ᵇ β) :=
{ smul := λ n f,
{ to_continuous_map := n • f.to_continuous_map,
map_bounded' := by simpa using (zsmul_rec n f).map_bounded' } }
@[simp] lemma coe_zsmul (r : ℤ) (f : α →ᵇ β) : ⇑(r • f) = r • f := rfl
@[simp] lemma zsmul_apply (r : ℤ) (f : α →ᵇ β) (v : α) : (r • f) v = r • f v := rfl
instance : add_comm_group (α →ᵇ β) :=
fun_like.coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub (λ _ _, coe_nsmul _ _)
(λ _ _, coe_zsmul _ _)
instance : seminormed_add_comm_group (α →ᵇ β) :=
{ dist_eq := λ f g, by simp only [norm_eq, dist_eq, dist_eq_norm, sub_apply] }
instance {α β} [topological_space α] [normed_add_comm_group β] : normed_add_comm_group (α →ᵇ β) :=
{ ..bounded_continuous_function.seminormed_add_comm_group }
lemma nnnorm_def : ‖f‖₊ = nndist f 0 := rfl
lemma nnnorm_coe_le_nnnorm (x : α) : ‖f x‖₊ ≤ ‖f‖₊ := norm_coe_le_norm _ _
lemma nndist_le_two_nnnorm (x y : α) : nndist (f x) (f y) ≤ 2 * ‖f‖₊ := dist_le_two_norm _ _ _
/-- The nnnorm of a function is controlled by the supremum of the pointwise nnnorms -/
lemma nnnorm_le (C : ℝ≥0) : ‖f‖₊ ≤ C ↔ ∀x:α, ‖f x‖₊ ≤ C :=
norm_le C.prop
lemma nnnorm_const_le (b : β) : ‖const α b‖₊ ≤ ‖b‖₊ :=
norm_const_le _
@[simp] lemma nnnorm_const_eq [h : nonempty α] (b : β) : ‖const α b‖₊ = ‖b‖₊ :=
subtype.ext $ norm_const_eq _
lemma nnnorm_eq_supr_nnnorm : ‖f‖₊ = ⨆ x : α, ‖f x‖₊ :=
subtype.ext $ (norm_eq_supr_norm f).trans $ by simp_rw [nnreal.coe_supr, coe_nnnorm]
lemma abs_diff_coe_le_dist : ‖f x - g x‖ ≤ dist f g :=
by { rw dist_eq_norm, exact (f - g).norm_coe_le_norm x }
lemma coe_le_coe_add_dist {f g : α →ᵇ ℝ} : f x ≤ g x + dist f g :=
sub_le_iff_le_add'.1 $ (abs_le.1 $ @dist_coe_le_dist _ _ _ _ f g x).2
lemma norm_comp_continuous_le [topological_space γ] (f : α →ᵇ β) (g : C(γ, α)) :
‖f.comp_continuous g‖ ≤ ‖f‖ :=
((lipschitz_comp_continuous g).dist_le_mul f 0).trans $
by rw [nnreal.coe_one, one_mul, dist_zero_right]
end normed_add_comm_group
section has_bounded_smul
/-!
### `has_bounded_smul` (in particular, topological module) structure
In this section, if `β` is a metric space and a `𝕜`-module whose addition and scalar multiplication
are compatible with the metric structure, then we show that the space of bounded continuous
functions from `α` to `β` inherits a so-called `has_bounded_smul` structure (in particular, a
`has_continuous_mul` structure, which is the mathlib formulation of being a topological module), by
using pointwise operations and checking that they are compatible with the uniform distance. -/
variables {𝕜 : Type*} [pseudo_metric_space 𝕜] [topological_space α] [pseudo_metric_space β]
section has_smul
variables [has_zero 𝕜] [has_zero β] [has_smul 𝕜 β] [has_bounded_smul 𝕜 β]
instance : has_smul 𝕜 (α →ᵇ β) :=
{ smul := λ c f,
{ to_continuous_map := c • f.to_continuous_map,
map_bounded' := let ⟨b, hb⟩ := f.bounded in ⟨dist c 0 * b, λ x y, begin
refine (dist_smul_pair c (f x) (f y)).trans _,
refine mul_le_mul_of_nonneg_left _ dist_nonneg,
exact hb x y
end⟩ } }
@[simp] lemma coe_smul (c : 𝕜) (f : α →ᵇ β) : ⇑(c • f) = λ x, c • (f x) := rfl
lemma smul_apply (c : 𝕜) (f : α →ᵇ β) (x : α) : (c • f) x = c • f x := rfl
instance [has_smul 𝕜ᵐᵒᵖ β] [is_central_scalar 𝕜 β] : is_central_scalar 𝕜 (α →ᵇ β) :=
{ op_smul_eq_smul := λ _ _, ext $ λ _, op_smul_eq_smul _ _ }
instance : has_bounded_smul 𝕜 (α →ᵇ β) :=
{ dist_smul_pair' := λ c f₁ f₂, begin
rw dist_le (mul_nonneg dist_nonneg dist_nonneg),
intros x,
refine (dist_smul_pair c (f₁ x) (f₂ x)).trans _,
exact mul_le_mul_of_nonneg_left (dist_coe_le_dist x) dist_nonneg
end,
dist_pair_smul' := λ c₁ c₂ f, begin
rw dist_le (mul_nonneg dist_nonneg dist_nonneg),
intros x,
refine (dist_pair_smul c₁ c₂ (f x)).trans _,
convert mul_le_mul_of_nonneg_left (dist_coe_le_dist x) dist_nonneg,
simp
end }
end has_smul
section mul_action
variables [monoid_with_zero 𝕜] [has_zero β] [mul_action 𝕜 β] [has_bounded_smul 𝕜 β]
instance : mul_action 𝕜 (α →ᵇ β) := fun_like.coe_injective.mul_action _ coe_smul
end mul_action
section distrib_mul_action
variables [monoid_with_zero 𝕜] [add_monoid β] [distrib_mul_action 𝕜 β] [has_bounded_smul 𝕜 β]
variables [has_lipschitz_add β]
instance : distrib_mul_action 𝕜 (α →ᵇ β) :=
function.injective.distrib_mul_action ⟨_, coe_zero, coe_add⟩ fun_like.coe_injective coe_smul
end distrib_mul_action
section module
variables [semiring 𝕜] [add_comm_monoid β] [module 𝕜 β] [has_bounded_smul 𝕜 β]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
variables [has_lipschitz_add β]
instance : module 𝕜 (α →ᵇ β) :=
function.injective.module _ ⟨_, coe_zero, coe_add⟩ fun_like.coe_injective coe_smul
variables (𝕜)
/-- The evaluation at a point, as a continuous linear map from `α →ᵇ β` to `β`. -/
def eval_clm (x : α) : (α →ᵇ β) →L[𝕜] β :=
{ to_fun := λ f, f x,
map_add' := λ f g, add_apply _ _,
map_smul' := λ c f, smul_apply _ _ _ }
@[simp] lemma eval_clm_apply (x : α) (f : α →ᵇ β) :
eval_clm 𝕜 x f = f x := rfl
variables (α β)
/-- The linear map forgetting that a bounded continuous function is bounded. -/
@[simps]
def to_continuous_map_linear_map : (α →ᵇ β) →ₗ[𝕜] C(α, β) :=
{ to_fun := to_continuous_map,
map_smul' := λ f g, rfl,
map_add' := λ c f, rfl }
end module
end has_bounded_smul
section normed_space
/-!
### Normed space structure
In this section, if `β` is a normed space, then we show that the space of bounded
continuous functions from `α` to `β` inherits a normed space structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables {𝕜 : Type*}
variables [topological_space α] [seminormed_add_comm_group β]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
instance [normed_field 𝕜] [normed_space 𝕜 β] : normed_space 𝕜 (α →ᵇ β) := ⟨λ c f, begin
refine norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _,
exact (λ x, trans_rel_right _ (norm_smul _ _)
(mul_le_mul_of_nonneg_left (f.norm_coe_le_norm _) (norm_nonneg _))) end⟩
variables [nontrivially_normed_field 𝕜] [normed_space 𝕜 β]
variables [seminormed_add_comm_group γ] [normed_space 𝕜 γ]
variables (α)
-- TODO does this work in the `has_bounded_smul` setting, too?
/--
Postcomposition of bounded continuous functions into a normed module by a continuous linear map is
a continuous linear map.
Upgraded version of `continuous_linear_map.comp_left_continuous`, similar to
`linear_map.comp_left`. -/
protected def _root_.continuous_linear_map.comp_left_continuous_bounded (g : β →L[𝕜] γ) :
(α →ᵇ β) →L[𝕜] (α →ᵇ γ) :=
linear_map.mk_continuous
{ to_fun := λ f, of_normed_add_comm_group
(g ∘ f)
(g.continuous.comp f.continuous)
(‖g‖ * ‖f‖)
(λ x, (g.le_op_norm_of_le (f.norm_coe_le_norm x))),
map_add' := λ f g, by ext; simp,
map_smul' := λ c f, by ext; simp }
‖g‖
(λ f, norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg g) (norm_nonneg f)) _)
@[simp] lemma _root_.continuous_linear_map.comp_left_continuous_bounded_apply (g : β →L[𝕜] γ)
(f : α →ᵇ β) (x : α) :
(g.comp_left_continuous_bounded α f) x = g (f x) :=
rfl
end normed_space
section normed_ring
/-!
### Normed ring structure
In this section, if `R` is a normed ring, then we show that the space of bounded
continuous functions from `α` to `R` inherits a normed ring structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables [topological_space α] {R : Type*}
section non_unital
section semi_normed
variables [non_unital_semi_normed_ring R]
instance : has_mul (α →ᵇ R) :=
{ mul := λ f g, of_normed_add_comm_group (f * g) (f.continuous.mul g.continuous) (‖f‖ * ‖g‖) $ λ x,
le_trans (norm_mul_le (f x) (g x)) $
mul_le_mul (f.norm_coe_le_norm x) (g.norm_coe_le_norm x) (norm_nonneg _) (norm_nonneg _) }
@[simp] lemma coe_mul (f g : α →ᵇ R) : ⇑(f * g) = f * g := rfl
lemma mul_apply (f g : α →ᵇ R) (x : α) : (f * g) x = f x * g x := rfl
instance : non_unital_ring (α →ᵇ R) :=
fun_like.coe_injective.non_unital_ring _ coe_zero coe_add coe_mul coe_neg coe_sub
(λ _ _, coe_nsmul _ _) (λ _ _, coe_zsmul _ _)
instance : non_unital_semi_normed_ring (α →ᵇ R) :=
{ norm_mul := λ f g, norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _))
_,
.. bounded_continuous_function.seminormed_add_comm_group }
end semi_normed
instance [non_unital_normed_ring R] : non_unital_normed_ring (α →ᵇ R) :=
{ .. bounded_continuous_function.non_unital_semi_normed_ring,
.. bounded_continuous_function.normed_add_comm_group }
end non_unital
section semi_normed
variables [semi_normed_ring R]
@[simp] lemma coe_npow_rec (f : α →ᵇ R) : ∀ n, ⇑(npow_rec n f) = f ^ n
| 0 := by rw [npow_rec, pow_zero, coe_one]
| (n + 1) := by rw [npow_rec, pow_succ, coe_mul, coe_npow_rec]
instance has_nat_pow : has_pow (α →ᵇ R) ℕ :=
{ pow := λ f n,
{ to_continuous_map := f.to_continuous_map ^ n,
map_bounded' := by simpa [coe_npow_rec] using (npow_rec n f).map_bounded' } }
@[simp] lemma coe_pow (n : ℕ) (f : α →ᵇ R) : ⇑(f ^ n) = f ^ n := rfl
@[simp] lemma pow_apply (n : ℕ) (f : α →ᵇ R) (v : α) : (f ^ n) v = f v ^ n := rfl
instance : has_nat_cast (α →ᵇ R) :=
⟨λ n, bounded_continuous_function.const _ n⟩
@[simp, norm_cast] lemma coe_nat_cast (n : ℕ) : ((n : α →ᵇ R) : α → R) = n := rfl
instance : has_int_cast (α →ᵇ R) :=
⟨λ n, bounded_continuous_function.const _ n⟩
@[simp, norm_cast] lemma coe_int_cast (n : ℤ) : ((n : α →ᵇ R) : α → R) = n := rfl
instance : ring (α →ᵇ R) :=
fun_like.coe_injective.ring _ coe_zero coe_one coe_add coe_mul coe_neg coe_sub
(λ _ _, coe_nsmul _ _)
(λ _ _, coe_zsmul _ _)
(λ _ _, coe_pow _ _)
coe_nat_cast
coe_int_cast
instance : semi_normed_ring (α →ᵇ R) :=
{ ..bounded_continuous_function.non_unital_semi_normed_ring }
end semi_normed
instance [normed_ring R] : normed_ring (α →ᵇ R) :=
{ ..bounded_continuous_function.non_unital_normed_ring }
end normed_ring
section normed_comm_ring
/-!
### Normed commutative ring structure
In this section, if `R` is a normed commutative ring, then we show that the space of bounded
continuous functions from `α` to `R` inherits a normed commutative ring structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables [topological_space α] {R : Type*}
instance [semi_normed_comm_ring R] : comm_ring (α →ᵇ R) :=
{ mul_comm := λ f₁ f₂, ext $ λ x, mul_comm _ _,
.. bounded_continuous_function.ring }
instance [semi_normed_comm_ring R] : semi_normed_comm_ring (α →ᵇ R) :=
{ ..bounded_continuous_function.comm_ring, ..bounded_continuous_function.seminormed_add_comm_group }
instance [normed_comm_ring R] : normed_comm_ring (α →ᵇ R) :=
{ .. bounded_continuous_function.comm_ring, .. bounded_continuous_function.normed_add_comm_group }
end normed_comm_ring
section normed_algebra
/-!
### Normed algebra structure
In this section, if `γ` is a normed algebra, then we show that the space of bounded
continuous functions from `α` to `γ` inherits a normed algebra structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables {𝕜 : Type*} [normed_field 𝕜]
variables [topological_space α] [seminormed_add_comm_group β] [normed_space 𝕜 β]
variables [normed_ring γ] [normed_algebra 𝕜 γ]
variables {f g : α →ᵇ γ} {x : α} {c : 𝕜}
/-- `bounded_continuous_function.const` as a `ring_hom`. -/
def C : 𝕜 →+* (α →ᵇ γ) :=
{ to_fun := λ (c : 𝕜), const α ((algebra_map 𝕜 γ) c),
map_one' := ext $ λ x, (algebra_map 𝕜 γ).map_one,
map_mul' := λ c₁ c₂, ext $ λ x, (algebra_map 𝕜 γ).map_mul _ _,
map_zero' := ext $ λ x, (algebra_map 𝕜 γ).map_zero,
map_add' := λ c₁ c₂, ext $ λ x, (algebra_map 𝕜 γ).map_add _ _ }
instance : algebra 𝕜 (α →ᵇ γ) :=
{ to_ring_hom := C,
commutes' := λ c f, ext $ λ x, algebra.commutes' _ _,
smul_def' := λ c f, ext $ λ x, algebra.smul_def' _ _,
..bounded_continuous_function.module,
..bounded_continuous_function.ring }
@[simp] lemma algebra_map_apply (k : 𝕜) (a : α) :
algebra_map 𝕜 (α →ᵇ γ) k a = k • 1 :=
by { rw algebra.algebra_map_eq_smul_one, refl, }
instance : normed_algebra 𝕜 (α →ᵇ γ) :=
{ ..bounded_continuous_function.normed_space }
/-!
### Structure as normed module over scalar functions
If `β` is a normed `𝕜`-space, then we show that the space of bounded continuous
functions from `α` to `β` is naturally a module over the algebra of bounded continuous
functions from `α` to `𝕜`. -/
instance has_smul' : has_smul (α →ᵇ 𝕜) (α →ᵇ β) :=
⟨λ (f : α →ᵇ 𝕜) (g : α →ᵇ β), of_normed_add_comm_group (λ x, (f x) • (g x))
(f.continuous.smul g.continuous) (‖f‖ * ‖g‖) (λ x, calc
‖f x • g x‖ ≤ ‖f x‖ * ‖g x‖ : normed_space.norm_smul_le _ _
... ≤ ‖f‖ * ‖g‖ : mul_le_mul (f.norm_coe_le_norm _) (g.norm_coe_le_norm _) (norm_nonneg _)
(norm_nonneg _)) ⟩
instance module' : module (α →ᵇ 𝕜) (α →ᵇ β) :=
module.of_core $
{ smul := (•),
smul_add := λ c f₁ f₂, ext $ λ x, smul_add _ _ _,
add_smul := λ c₁ c₂ f, ext $ λ x, add_smul _ _ _,
mul_smul := λ c₁ c₂ f, ext $ λ x, mul_smul _ _ _,
one_smul := λ f, ext $ λ x, one_smul 𝕜 (f x) }
lemma norm_smul_le (f : α →ᵇ 𝕜) (g : α →ᵇ β) : ‖f • g‖ ≤ ‖f‖ * ‖g‖ :=
norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _
/- TODO: When `normed_module` has been added to `normed_space.basic`, the above facts
show that the space of bounded continuous functions from `α` to `β` is naturally a normed
module over the algebra of bounded continuous functions from `α` to `𝕜`. -/
end normed_algebra
lemma nnreal.upper_bound {α : Type*} [topological_space α]
(f : α →ᵇ ℝ≥0) (x : α) : f x ≤ nndist f 0 :=
begin
have key : nndist (f x) ((0 : α →ᵇ ℝ≥0) x) ≤ nndist f 0,
{ exact @dist_coe_le_dist α ℝ≥0 _ _ f 0 x, },
simp only [coe_zero, pi.zero_apply] at key,
rwa nnreal.nndist_zero_eq_val' (f x) at key,
end
/-!
### Star structures
In this section, if `β` is a normed ⋆-group, then so is the space of bounded
continuous functions from `α` to `β`, by using the star operation pointwise.
If `𝕜` is normed field and a ⋆-ring over which `β` is a normed algebra and a
star module, then the space of bounded continuous functions from `α` to `β`
is a star module.
If `β` is a ⋆-ring in addition to being a normed ⋆-group, then `α →ᵇ β`
inherits a ⋆-ring structure.
In summary, if `β` is a C⋆-algebra over `𝕜`, then so is `α →ᵇ β`; note that
completeness is guaranteed when `β` is complete (see
`bounded_continuous_function.complete`). -/
section normed_add_comm_group
variables {𝕜 : Type*} [normed_field 𝕜] [star_ring 𝕜] [topological_space α]
[seminormed_add_comm_group β] [star_add_monoid β] [normed_star_group β]
variables [normed_space 𝕜 β] [star_module 𝕜 β]
instance : star_add_monoid (α →ᵇ β) :=
{ star := λ f, f.comp star star_normed_add_group_hom.lipschitz,
star_involutive := λ f, ext $ λ x, star_star (f x),
star_add := λ f g, ext $ λ x, star_add (f x) (g x) }
/-- The right-hand side of this equality can be parsed `star ∘ ⇑f` because of the
instance `pi.has_star`. Upon inspecting the goal, one sees `⊢ ⇑(star f) = star ⇑f`.-/
@[simp] lemma coe_star (f : α →ᵇ β) : ⇑(star f) = star f := rfl
@[simp] lemma star_apply (f : α →ᵇ β) (x : α) : star f x = star (f x) := rfl
instance : normed_star_group (α →ᵇ β) :=
{ norm_star := λ f, by simp only [norm_eq, star_apply, norm_star] }
instance : star_module 𝕜 (α →ᵇ β) :=
{ star_smul := λ k f, ext $ λ x, star_smul k (f x) }
end normed_add_comm_group
section cstar_ring
variables [topological_space α]
variables [non_unital_normed_ring β] [star_ring β]
instance [normed_star_group β] : star_ring (α →ᵇ β) :=
{ star_mul := λ f g, ext $ λ x, star_mul (f x) (g x),
..bounded_continuous_function.star_add_monoid }
variable [cstar_ring β]
instance : cstar_ring (α →ᵇ β) :=
{ norm_star_mul_self :=
begin
intro f,
refine le_antisymm _ _,
{ rw [←sq, norm_le (sq_nonneg _)],
dsimp [star_apply],
intro x,
rw [cstar_ring.norm_star_mul_self, ←sq],
refine sq_le_sq' _ _,
{ linarith [norm_nonneg (f x), norm_nonneg f] },
{ exact norm_coe_le_norm f x }, },
{ rw [←sq, ←real.le_sqrt (norm_nonneg _) (norm_nonneg _), norm_le (real.sqrt_nonneg _)],
intro x,
rw [real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ←cstar_ring.norm_star_mul_self],
exact norm_coe_le_norm (star f * f) x }
end }
end cstar_ring
section normed_lattice_ordered_group
variables [topological_space α] [normed_lattice_add_comm_group β]
instance : partial_order (α →ᵇ β) := partial_order.lift (λ f, f.to_fun) (by tidy)
/--
Continuous normed lattice group valued functions form a meet-semilattice
-/
instance : semilattice_inf (α →ᵇ β) :=
{ inf := λ f g,
{ to_fun := λ t, f t ⊓ g t,
continuous_to_fun := f.continuous.inf g.continuous,
map_bounded' := begin
obtain ⟨C₁, hf⟩ := f.bounded,
obtain ⟨C₂, hg⟩ := g.bounded,
refine ⟨C₁ + C₂, λ x y, _⟩,
simp_rw normed_add_comm_group.dist_eq at hf hg ⊢,
exact (norm_inf_sub_inf_le_add_norm _ _ _ _).trans (add_le_add (hf _ _) (hg _ _)),
end },
inf_le_left := λ f g, continuous_map.le_def.mpr (λ _, inf_le_left),
inf_le_right := λ f g, continuous_map.le_def.mpr (λ _, inf_le_right),
le_inf := λ f g₁ g₂ w₁ w₂, continuous_map.le_def.mpr (λ _, le_inf (continuous_map.le_def.mp w₁ _)
(continuous_map.le_def.mp w₂ _)),
..bounded_continuous_function.partial_order }
instance : semilattice_sup (α →ᵇ β) :=
{ sup := λ f g,
{ to_fun := λ t, f t ⊔ g t,
continuous_to_fun := f.continuous.sup g.continuous,
map_bounded' := begin
obtain ⟨C₁, hf⟩ := f.bounded,
obtain ⟨C₂, hg⟩ := g.bounded,
refine ⟨C₁ + C₂, λ x y, _⟩,
simp_rw normed_add_comm_group.dist_eq at hf hg ⊢,
exact (norm_sup_sub_sup_le_add_norm _ _ _ _).trans (add_le_add (hf _ _) (hg _ _)),
end },
le_sup_left := λ f g, continuous_map.le_def.mpr (λ _, le_sup_left),
le_sup_right := λ f g, continuous_map.le_def.mpr (λ _, le_sup_right),
sup_le := λ f g₁ g₂ w₁ w₂, continuous_map.le_def.mpr (λ _, sup_le (continuous_map.le_def.mp w₁ _)
(continuous_map.le_def.mp w₂ _)),
..bounded_continuous_function.partial_order }
instance : lattice (α →ᵇ β) :=
{ .. bounded_continuous_function.semilattice_sup, .. bounded_continuous_function.semilattice_inf }
@[simp] lemma coe_fn_sup (f g : α →ᵇ β) : ⇑(f ⊔ g) = f ⊔ g := rfl
@[simp] lemma coe_fn_abs (f : α →ᵇ β) : ⇑|f| = |f| := rfl
instance : normed_lattice_add_comm_group (α →ᵇ β) :=
{ add_le_add_left := begin
intros f g h₁ h t,
simp only [coe_to_continuous_fun, pi.add_apply, add_le_add_iff_left, coe_add,
continuous_map.to_fun_eq_coe],
exact h₁ _,
end,
solid :=
begin
intros f g h,
have i1: ∀ t, ‖f t‖ ≤ ‖g t‖ := λ t, solid (h t),
rw norm_le (norm_nonneg _),
exact λ t, (i1 t).trans (norm_coe_le_norm g t),
end,
..bounded_continuous_function.lattice, ..bounded_continuous_function.seminormed_add_comm_group }
end normed_lattice_ordered_group
section nonnegative_part
variables [topological_space α]
/-- The nonnegative part of a bounded continuous `ℝ`-valued function as a bounded
continuous `ℝ≥0`-valued function. -/
def nnreal_part (f : α →ᵇ ℝ) : α →ᵇ ℝ≥0 :=
bounded_continuous_function.comp _
(show lipschitz_with 1 real.to_nnreal, from lipschitz_with_pos) f
@[simp] lemma nnreal_part_coe_fun_eq (f : α →ᵇ ℝ) : ⇑(f.nnreal_part) = real.to_nnreal ∘ ⇑f := rfl
/-- The absolute value of a bounded continuous `ℝ`-valued function as a bounded
continuous `ℝ≥0`-valued function. -/
def nnnorm (f : α →ᵇ ℝ) : α →ᵇ ℝ≥0 :=
bounded_continuous_function.comp _
(show lipschitz_with 1 (λ (x : ℝ), ‖x‖₊), from lipschitz_with_one_norm) f
@[simp] lemma nnnorm_coe_fun_eq (f : α →ᵇ ℝ) : ⇑(f.nnnorm) = has_nnnorm.nnnorm ∘ ⇑f := rfl
/-- Decompose a bounded continuous function to its positive and negative parts. -/
lemma self_eq_nnreal_part_sub_nnreal_part_neg (f : α →ᵇ ℝ) :
⇑f = coe ∘ f.nnreal_part - coe ∘ (-f).nnreal_part :=
by { funext x, dsimp, simp only [max_zero_sub_max_neg_zero_eq_self], }
/-- Express the absolute value of a bounded continuous function in terms of its
positive and negative parts. -/
lemma abs_self_eq_nnreal_part_add_nnreal_part_neg (f : α →ᵇ ℝ) :
abs ∘ ⇑f = coe ∘ f.nnreal_part + coe ∘ (-f).nnreal_part :=
by { funext x, dsimp, simp only [max_zero_add_max_neg_zero_eq_abs_self], }
end nonnegative_part
end bounded_continuous_function
|
9420b9355e4a8361c72b8af8a4e5f77389f182de | 3a7eb58cccd9e625ebf79689f8f0f244a20b6158 | /old/ArrayExtra.lean | d50a98859ac35891825cf38f1ccb5a1264294302 | [] | no_license | hermetique/lean4-raytracer | c1ea6336dbb44296af60ee8e416cc9c87d6827a9 | 092c9a6c4ee612786082b807491ccefaed961462 | refs/heads/master | 1,677,468,320,587 | 1,612,291,379,000 | 1,612,291,379,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,110 | lean | namespace Array
-- TODO add unsafe version
def foldlM₂ {m : Type _ → Type _} [Monad m] (f : γ → α → β → m γ) (init : γ) (as : Array α) (bs : Array β) (h' : as.size = bs.size) (start := 0) (stop := as.size) : m γ :=
let fold (stop : Nat) (h : stop ≤ as.size) :=
let rec loop (i : Nat) (j : Nat) (c : γ) : m γ := do
if hlt : j < stop then
match i with
| 0 => pure c
| i'+1 =>
loop i' (j+1) (← f c (as.get ⟨j, Nat.ltOfLtOfLe hlt h⟩) (bs.get ⟨j, by { rw ←h'; exact Nat.ltOfLtOfLe hlt h }⟩))
else
pure c
loop (stop - start) start init
if h : stop ≤ as.size then
fold stop h
else
fold as.size (Nat.leRefl _)
def mapM₂ {m : Type _ → Type _} [Monad m] (f : α → β → m γ) (as : Array α) (bs : Array β) (h : as.size = bs.size) : m (Array γ) :=
foldlM₂ (fun cs a b => do let c ← f a b; pure (cs.push c)) (mkEmpty as.size) as bs h
@[inline]
def map₂ (f : α → β → γ) (as : Array α) (bs : Array β) (h : as.size = bs.size): Array γ :=
Id.run <| mapM₂ f as bs h
end Array |
67423ed0b965ea27d6d9e6644af2546b31c5da6b | e61a235b8468b03aee0120bf26ec615c045005d2 | /stage0/src/Init/Lean/Meta/Tactic/Intro.lean | 973dba8368b8126d5953489062e252055a8c2213 | [
"Apache-2.0"
] | permissive | SCKelemen/lean4 | 140dc63a80539f7c61c8e43e1c174d8500ec3230 | e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc | refs/heads/master | 1,660,973,595,917 | 1,590,278,033,000 | 1,590,278,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,404 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Meta.Tactic.Util
namespace Lean
namespace Meta
@[specialize]
def introNCoreAux {σ} (mvarId : MVarId) (mkName : LocalContext → Name → σ → Name × σ)
: Nat → LocalContext → Array Expr → Nat → σ → Expr → MetaM (Array Expr × MVarId)
| 0, lctx, fvars, j, _, type =>
let type := type.instantiateRevRange j fvars.size fvars;
adaptReader (fun (ctx : Context) => { ctx with lctx := lctx }) $
withNewLocalInstances isClassExpensive fvars j $ do
tag ← getMVarTag mvarId;
let type := type.headBeta;
newMVar ← mkFreshExprSyntheticOpaqueMVar type tag;
lctx ← getLCtx;
newVal ← mkLambda fvars newMVar;
assignExprMVar mvarId newVal;
pure $ (fvars, newMVar.mvarId!)
| (i+1), lctx, fvars, j, s, Expr.letE n type val body _ => do
let type := type.instantiateRevRange j fvars.size fvars;
let type := type.headBeta;
let val := val.instantiateRevRange j fvars.size fvars;
fvarId ← mkFreshId;
let (n, s) := mkName lctx n s;
let lctx := lctx.mkLetDecl fvarId n type val;
let fvar := mkFVar fvarId;
let fvars := fvars.push fvar;
introNCoreAux i lctx fvars j s body
| (i+1), lctx, fvars, j, s, Expr.forallE n type body c => do
let type := type.instantiateRevRange j fvars.size fvars;
let type := type.headBeta;
fvarId ← mkFreshId;
let (n, s) := mkName lctx n s;
let lctx := lctx.mkLocalDecl fvarId n type c.binderInfo;
let fvar := mkFVar fvarId;
let fvars := fvars.push fvar;
introNCoreAux i lctx fvars j s body
| (i+1), lctx, fvars, j, s, type =>
let type := type.instantiateRevRange j fvars.size fvars;
adaptReader (fun (ctx : Context) => { ctx with lctx := lctx }) $
withNewLocalInstances isClassExpensive fvars j $ do
newType ← whnf type;
if newType.isForall then
introNCoreAux i lctx fvars fvars.size s newType
else
throwTacticEx `introN mvarId "insufficient number of binders"
@[specialize] def introNCore {σ} (mvarId : MVarId) (n : Nat) (mkName : LocalContext → Name → σ → Name × σ) (s : σ) : MetaM (Array FVarId × MVarId) :=
withMVarContext mvarId $ do
checkNotAssigned mvarId `introN;
mvarType ← getMVarType mvarId;
lctx ← getLCtx;
(fvars, mvarId) ← introNCoreAux mvarId mkName n lctx #[] 0 s mvarType;
pure (fvars.map Expr.fvarId!, mvarId)
def mkAuxName (useUnusedNames : Bool) (lctx : LocalContext) (defaultName : Name) : List Name → Name × List Name
| [] => (if useUnusedNames then lctx.getUnusedName defaultName else defaultName, [])
| n :: rest => (if n != "_" then n else if useUnusedNames then lctx.getUnusedName defaultName else defaultName, rest)
def introN (mvarId : MVarId) (n : Nat) (givenNames : List Name := []) (useUnusedNames := true) : MetaM (Array FVarId × MVarId) :=
introNCore mvarId n (mkAuxName useUnusedNames) givenNames
def intro (mvarId : MVarId) (name : Name) : MetaM (FVarId × MVarId) := do
(fvarIds, mvarId) ← introN mvarId 1 [name];
pure (fvarIds.get! 0, mvarId)
def intro1 (mvarId : MVarId) (useUnusedNames := true) : MetaM (FVarId × MVarId) := do
(fvarIds, mvarId) ← introN mvarId 1 [] useUnusedNames;
pure (fvarIds.get! 0, mvarId)
end Meta
end Lean
|
ef53cf02db69b581bbeef9ebf6bc0fb43aa88111 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/combinatorics/partition.lean | 40f4e5e8680937774316e4dbed0f7e2d04d195b7 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 4,453 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import combinatorics.composition
import data.nat.parity
import tactic.apply_fun
/-!
# Partitions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
A partition of a natural number `n` is a way of writing `n` as a sum of positive integers, where the
order does not matter: two sums that differ only in the order of their summands are considered the
same partition. This notion is closely related to that of a composition of `n`, but in a composition
of `n` the order does matter.
A summand of the partition is called a part.
## Main functions
* `p : partition n` is a structure, made of a multiset of integers which are all positive and
add up to `n`.
## Implementation details
The main motivation for this structure and its API is to show Euler's partition theorem, and
related results.
The representation of a partition as a multiset is very handy as multisets are very flexible and
already have a well-developed API.
## Tags
Partition
## References
<https://en.wikipedia.org/wiki/Partition_(number_theory)>
-/
variables {α : Type*}
open multiset
open_locale big_operators
namespace nat
/-- A partition of `n` is a multiset of positive integers summing to `n`. -/
@[ext, derive decidable_eq] structure partition (n : ℕ) :=
(parts : multiset ℕ)
(parts_pos : ∀ {i}, i ∈ parts → 0 < i)
(parts_sum : parts.sum = n)
namespace partition
/-- A composition induces a partition (just convert the list to a multiset). -/
def of_composition (n : ℕ) (c : composition n) : partition n :=
{ parts := c.blocks,
parts_pos := λ i hi, c.blocks_pos hi,
parts_sum := by rw [multiset.coe_sum, c.blocks_sum] }
lemma of_composition_surj {n : ℕ} : function.surjective (of_composition n) :=
begin
rintro ⟨b, hb₁, hb₂⟩,
rcases quotient.exists_rep b with ⟨b, rfl⟩,
refine ⟨⟨b, λ i hi, hb₁ hi, _⟩, partition.ext _ _ rfl⟩,
simpa using hb₂
end
/--
Given a multiset which sums to `n`, construct a partition of `n` with the same multiset, but
without the zeros.
-/
-- The argument `n` is kept explicit here since it is useful in tactic mode proofs to generate the
-- proof obligation `l.sum = n`.
def of_sums (n : ℕ) (l : multiset ℕ) (hl : l.sum = n) : partition n :=
{ parts := l.filter (≠ 0),
parts_pos := λ i hi, nat.pos_of_ne_zero $ by apply of_mem_filter hi,
parts_sum :=
begin
have lt : l.filter (= 0) + l.filter (≠ 0) = l := filter_add_not _ l,
apply_fun multiset.sum at lt,
have lz : (l.filter (= 0)).sum = 0,
{ rw multiset.sum_eq_zero_iff,
simp },
simpa [lz, hl] using lt,
end }
/-- A `multiset ℕ` induces a partition on its sum. -/
def of_multiset (l : multiset ℕ) : partition l.sum :=
of_sums _ l rfl
/-- The partition of exactly one part. -/
def indiscrete_partition (n : ℕ) : partition n :=
of_sums n {n} rfl
instance {n : ℕ} : inhabited (partition n) := ⟨indiscrete_partition n⟩
/--
The number of times a positive integer `i` appears in the partition `of_sums n l hl` is the same
as the number of times it appears in the multiset `l`.
(For `i = 0`, `partition.non_zero` combined with `multiset.count_eq_zero_of_not_mem` gives that
this is `0` instead.)
-/
lemma count_of_sums_of_ne_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) {i : ℕ} (hi : i ≠ 0) :
(of_sums n l hl).parts.count i = l.count i :=
count_filter_of_pos hi
lemma count_of_sums_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) :
(of_sums n l hl).parts.count 0 = 0 :=
count_filter_of_neg (λ h, h rfl)
/--
Show there are finitely many partitions by considering the surjection from compositions to
partitions.
-/
instance (n : ℕ) : fintype (partition n) :=
fintype.of_surjective (of_composition n) of_composition_surj
/-- The finset of those partitions in which every part is odd. -/
def odds (n : ℕ) : finset (partition n) :=
finset.univ.filter (λ c, ∀ i ∈ c.parts, ¬ even i)
/-- The finset of those partitions in which each part is used at most once. -/
def distincts (n : ℕ) : finset (partition n) :=
finset.univ.filter (λ c, c.parts.nodup)
/-- The finset of those partitions in which every part is odd and used at most once. -/
def odd_distincts (n : ℕ) : finset (partition n) := odds n ∩ distincts n
end partition
end nat
|
80a9349d61a661c9b92af2c4861b5a8b31d8285c | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /library/data/int/power.lean | abec75efc0fd9b6531cf031fc63d9bb14e98a9ac | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 775 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
The power function on the integers.
-/
import data.int.basic data.int.order data.int.div algebra.group_power data.nat.power
namespace int
definition int_has_pow_nat [reducible] [instance] [priority int.prio] : has_pow_nat int :=
has_pow_nat.mk has_pow_nat.pow_nat
/-
definition nmul (n : ℕ) (a : ℤ) : ℤ := algebra.nmul n a
infix [priority int.prio] ⬝ := nmul
definition imul (i : ℤ) (a : ℤ) : ℤ := algebra.imul i a
-/
open nat
theorem of_nat_pow (a n : ℕ) : of_nat (a^n) = (of_nat a)^n :=
begin
induction n with n ih,
apply eq.refl,
krewrite [pow_succ, pow_succ, of_nat_mul, ih]
end
end int
|
b3defe321bb519e1a7d98fef563990e34071142f | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /library/data/quotient/basic.lean | 8acb3bace35d62190df677da71313231a49e480f | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,884 | lean | /-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
An explicit treatment of quotients, without using Lean's built-in quotient types.
-/
import logic logic.cast algebra.relation data.prod
import logic.instances
import .util
open relation prod inhabited nonempty tactic eq.ops
open subtype relation.iff_ops
namespace quotient
/- definition and basics -/
-- TODO: make this a structure
definition is_quotient {A B : Type} (R : A → A → Prop) (abs : A → B) (rep : B → A) : Prop :=
(∀b, abs (rep b) = b) ∧
(∀b, R (rep b) (rep b)) ∧
(∀r s, R r s ↔ (R r r ∧ R s s ∧ abs r = abs s))
theorem intro {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(H1 : ∀b, abs (rep b) = b) (H2 : ∀b, R (rep b) (rep b))
(H3 : ∀r s, R r s ↔ (R r r ∧ R s s ∧ abs r = abs s)) : is_quotient R abs rep :=
and.intro H1 (and.intro H2 H3)
theorem and_absorb_left {a : Prop} (b : Prop) (Ha : a) : a ∧ b ↔ b :=
iff.intro (assume Hab, and.elim_right Hab) (assume Hb, and.intro Ha Hb)
theorem intro_refl {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(H1 : reflexive R) (H2 : ∀b, abs (rep b) = b)
(H3 : ∀r s, R r s ↔ abs r = abs s) : is_quotient R abs rep :=
intro
H2
(take b, H1 (rep b))
(take r s,
have H4 : R r s ↔ R s s ∧ abs r = abs s,
from
subst (symm (and_absorb_left _ (H1 s))) (H3 r s),
subst (symm (and_absorb_left _ (H1 r))) H4)
theorem abs_rep {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) (b : B) : abs (rep b) = b :=
and.elim_left Q b
theorem refl_rep {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) (b : B) : R (rep b) (rep b) :=
and.elim_left (and.elim_right Q) b
theorem R_iff {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) (r s : A) : R r s ↔ (R r r ∧ R s s ∧ abs r = abs s) :=
and.elim_right (and.elim_right Q) r s
theorem refl_left {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {r s : A} (H : R r s) : R r r :=
and.elim_left (iff.elim_left (R_iff Q r s) H)
theorem refl_right {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {r s : A} (H : R r s) : R s s :=
and.elim_left (and.elim_right (iff.elim_left (R_iff Q r s) H))
theorem eq_abs {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {r s : A} (H : R r s) : abs r = abs s :=
and.elim_right (and.elim_right (iff.elim_left (R_iff Q r s) H))
theorem R_intro {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {r s : A} (H1 : R r r) (H2 : R s s) (H3 : abs r = abs s) : R r s :=
iff.elim_right (R_iff Q r s) (and.intro H1 (and.intro H2 H3))
theorem R_intro_refl {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) (H1 : reflexive R) {r s : A} (H2 : abs r = abs s) : R r s :=
iff.elim_right (R_iff Q r s) (and.intro (H1 r) (and.intro (H1 s) H2))
theorem rep_eq {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {a b : B} (H : R (rep a) (rep b)) : a = b :=
calc
a = abs (rep a) : eq.symm (abs_rep Q a)
... = abs (rep b) : {eq_abs Q H}
... = b : abs_rep Q b
theorem R_rep_abs {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {a : A} (H : R a a) : R a (rep (abs a)) :=
have H3 : abs a = abs (rep (abs a)), from eq.symm (abs_rep Q (abs a)),
R_intro Q H (refl_rep Q (abs a)) H3
theorem quotient_imp_symm {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) : symmetric R :=
take a b : A,
assume H : R a b,
have Ha : R a a, from refl_left Q H,
have Hb : R b b, from refl_right Q H,
have Hab : abs b = abs a, from eq.symm (eq_abs Q H),
R_intro Q Hb Ha Hab
theorem quotient_imp_trans {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) : transitive R :=
take a b c : A,
assume Hab : R a b,
assume Hbc : R b c,
have Ha : R a a, from refl_left Q Hab,
have Hc : R c c, from refl_right Q Hbc,
have Hac : abs a = abs c, from eq.trans (eq_abs Q Hab) (eq_abs Q Hbc),
R_intro Q Ha Hc Hac
/- recursion -/
-- (maybe some are superfluous)
definition rec {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {C : B → Type} (f : forall (a : A), C (abs a)) (b : B) : C b :=
eq.rec_on (abs_rep Q b) (f (rep b))
theorem comp {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {C : B → Type} {f : forall (a : A), C (abs a)}
(H : forall (r s : A) (H' : R r s), eq.rec_on (eq_abs Q H') (f r) = f s)
{a : A} (Ha : R a a) : rec Q f (abs a) = f a :=
assert H2 : R a (rep (abs a)), from
R_rep_abs Q Ha,
assert Heq : abs (rep (abs a)) = abs a, from
abs_rep Q (abs a),
calc
rec Q f (abs a) = eq.rec_on Heq (f (rep (abs a))) : rfl
... = eq.rec_on Heq (eq.rec_on (Heq⁻¹) (f a)) : {(H _ _ H2)⁻¹}
... = f a : eq.rec_on_compose (eq_abs Q H2) _ _
definition rec_constant {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {C : Type} (f : A → C) (b : B) : C :=
f (rep b)
theorem comp_constant {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {C : Type} {f : A → C}
(H : forall (r s : A) (H' : R r s), f r = f s)
{a : A} (Ha : R a a) : rec_constant Q f (abs a) = f a :=
have H2 : R a (rep (abs a)), from R_rep_abs Q Ha,
calc
rec_constant Q f (abs a) = f (rep (abs a)) : rfl
... = f a : {(H _ _ H2)⁻¹}
definition rec_binary {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {C : Type} (f : A → A → C) (b c : B) : C :=
f (rep b) (rep c)
theorem comp_binary {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {C : Type} {f : A → A → C}
(H : forall (a a' b b' : A) (Ha : R a a') (Hb : R b b'), f a b = f a' b')
{a b : A} (Ha : R a a) (Hb : R b b) : rec_binary Q f (abs a) (abs b) = f a b :=
have H2 : R a (rep (abs a)), from R_rep_abs Q Ha,
have H3 : R b (rep (abs b)), from R_rep_abs Q Hb,
calc
rec_binary Q f (abs a) (abs b) = f (rep (abs a)) (rep (abs b)) : rfl
... = f a b : {(H _ _ _ _ H2 H3)⁻¹}
theorem comp_binary_refl {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) (Hrefl : reflexive R) {C : Type} {f : A → A → C}
(H : forall (a a' b b' : A) (Ha : R a a') (Hb : R b b'), f a b = f a' b')
(a b : A) : rec_binary Q f (abs a) (abs b) = f a b :=
comp_binary Q H (Hrefl a) (Hrefl b)
definition quotient_map {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) (f : A → A) (b : B) : B :=
abs (f (rep b))
theorem comp_quotient_map {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {f : A → A}
(H : forall (a a' : A) (Ha : R a a'), R (f a) (f a'))
{a : A} (Ha : R a a) : quotient_map Q f (abs a) = abs (f a) :=
have H2 : R a (rep (abs a)), from R_rep_abs Q Ha,
have H3 : R (f a) (f (rep (abs a))), from H _ _ H2,
have H4 : abs (f a) = abs (f (rep (abs a))), from eq_abs Q H3,
H4⁻¹
definition quotient_map_binary {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) (f : A → A → A) (b c : B) : B :=
abs (f (rep b) (rep c))
theorem comp_quotient_map_binary {A B : Type} {R : A → A → Prop} {abs : A → B} {rep : B → A}
(Q : is_quotient R abs rep) {f : A → A → A}
(H : forall (a a' b b' : A) (Ha : R a a') (Hb : R b b'), R (f a b) (f a' b'))
{a b : A} (Ha : R a a) (Hb : R b b) : quotient_map_binary Q f (abs a) (abs b) = abs (f a b) :=
have Ha2 : R a (rep (abs a)), from R_rep_abs Q Ha,
have Hb2 : R b (rep (abs b)), from R_rep_abs Q Hb,
have H2 : R (f a b) (f (rep (abs a)) (rep (abs b))), from H _ _ _ _ Ha2 Hb2,
(eq_abs Q H2)⁻¹
theorem comp_quotient_map_binary_refl {A B : Type} {R : A → A → Prop} (Hrefl : reflexive R)
{abs : A → B} {rep : B → A} (Q : is_quotient R abs rep) {f : A → A → A}
(H : forall (a a' b b' : A) (Ha : R a a') (Hb : R b b'), R (f a b) (f a' b'))
(a b : A) : quotient_map_binary Q f (abs a) (abs b) = abs (f a b) :=
comp_quotient_map_binary Q H (Hrefl a) (Hrefl b)
/- image -/
definition image {A B : Type} (f : A → B) := subtype (fun b, ∃a, f a = b)
theorem image_inhabited {A B : Type} (f : A → B) (H : inhabited A) : inhabited (image f) :=
inhabited.mk (tag (f (default A)) (exists.intro (default A) rfl))
theorem image_inhabited2 {A B : Type} (f : A → B) (a : A) : inhabited (image f) :=
image_inhabited f (inhabited.mk a)
definition fun_image {A B : Type} (f : A → B) (a : A) : image f :=
tag (f a) (exists.intro a rfl)
theorem fun_image_def {A B : Type} (f : A → B) (a : A) :
fun_image f a = tag (f a) (exists.intro a rfl) := rfl
theorem elt_of_fun_image {A B : Type} (f : A → B) (a : A) : elt_of (fun_image f a) = f a :=
by esimp
theorem image_elt_of {A B : Type} {f : A → B} (u : image f) : ∃a, f a = elt_of u :=
has_property u
theorem fun_image_surj {A B : Type} {f : A → B} (u : image f) : ∃a, fun_image f a = u :=
subtype.destruct u
(take (b : B) (H : ∃a, f a = b),
obtain a (H': f a = b), from H,
(exists.intro a (tag_eq H')))
theorem image_tag {A B : Type} {f : A → B} (u : image f) : ∃a H, tag (f a) H = u :=
obtain a (H : fun_image f a = u), from fun_image_surj u,
exists.intro a (exists.intro (exists.intro a rfl) H)
open eq.ops
theorem fun_image_eq {A B : Type} (f : A → B) (a a' : A)
: (f a = f a') ↔ (fun_image f a = fun_image f a') :=
iff.intro
(assume H : f a = f a', tag_eq H)
(assume H : fun_image f a = fun_image f a',
by injection H; assumption)
theorem idempotent_image_elt_of {A : Type} {f : A → A} (H : ∀a, f (f a) = f a) (u : image f)
: fun_image f (elt_of u) = u :=
obtain (a : A) (Ha : fun_image f a = u), from fun_image_surj u,
calc
fun_image f (elt_of u) = fun_image f (elt_of (fun_image f a)) : by rewrite Ha
... = fun_image f (f a) : {elt_of_fun_image f a}
... = fun_image f a : {iff.elim_left (fun_image_eq f (f a) a) (H a)}
... = u : Ha
theorem idempotent_image_fix {A : Type} {f : A → A} (H : ∀a, f (f a) = f a) (u : image f)
: f (elt_of u) = elt_of u :=
obtain (a : A) (Ha : f a = elt_of u), from image_elt_of u,
calc
f (elt_of u) = f (f a) : {Ha⁻¹}
... = f a : H a
... = elt_of u : Ha
/- construct quotient from representative map -/
theorem representative_map_idempotent {A : Type} {R : A → A → Prop} {f : A → A}
(H1 : ∀a, R a (f a)) (H2 : ∀a b, R a b ↔ R a a ∧ R b b ∧ f a = f b) (a : A) :
f (f a) = f a :=
(and.elim_right (and.elim_right (iff.elim_left (H2 a (f a)) (H1 a))))⁻¹
theorem representative_map_idempotent_equiv {A : Type} {R : A → A → Prop} {f : A → A}
(H1 : ∀a, R a (f a)) (H2 : ∀a b, R a b → f a = f b) (a : A) :
f (f a) = f a :=
(H2 a (f a) (H1 a))⁻¹
theorem representative_map_refl_rep {A : Type} {R : A → A → Prop} {f : A → A}
(H1 : ∀a, R a (f a)) (H2 : ∀a b, R a b ↔ R a a ∧ R b b ∧ f a = f b) (a : A) :
R (f a) (f a) :=
representative_map_idempotent H1 H2 a ▸ H1 (f a)
theorem representative_map_image_fix {A : Type} {R : A → A → Prop} {f : A → A}
(H1 : ∀a, R a (f a)) (H2 : ∀a a', R a a' ↔ R a a ∧ R a' a' ∧ f a = f a') (b : image f) :
f (elt_of b) = elt_of b :=
idempotent_image_fix (representative_map_idempotent H1 H2) b
theorem representative_map_to_quotient {A : Type} {R : A → A → Prop} {f : A → A}
(H1 : ∀a, R a (f a)) (H2 : ∀a a', R a a' ↔ R a a ∧ R a' a' ∧ f a = f a') :
is_quotient R (fun_image f) elt_of :=
let abs := fun_image f in
intro
(take u : image f,
obtain (a : A) (Ha : f a = elt_of u), from image_elt_of u,
have H : elt_of (abs (elt_of u)) = elt_of u, from
calc
elt_of (abs (elt_of u)) = f (elt_of u) : elt_of_fun_image _ _
... = f (f a) : {Ha⁻¹}
... = f a : representative_map_idempotent H1 H2 a
... = elt_of u : Ha,
show abs (elt_of u) = u, from subtype.eq H)
(take u : image f,
show R (elt_of u) (elt_of u), from
obtain (a : A) (Ha : f a = elt_of u), from image_elt_of u,
Ha ▸ (@representative_map_refl_rep A R f H1 H2 a))
(take a a',
subst (fun_image_eq f a a') (H2 a a'))
theorem representative_map_equiv_inj {A : Type} {R : A → A → Prop}
(equiv : is_equivalence R) {f : A → A}
(H1 : ∀a, R a (f a)) (H2 : ∀a b, R a b → f a = f b) {a b : A} (H3 : f a = f b) :
R a b :=
have symmR : relation.symmetric R, from rel_symm R,
have transR : relation.transitive R, from rel_trans R,
show R a b, from
have H2 : R a (f b), from H3 ▸ (H1 a),
have H3 : R (f b) b, from symmR (H1 b),
transR H2 H3
theorem representative_map_to_quotient_equiv {A : Type} {R : A → A → Prop}
(equiv : is_equivalence R) {f : A → A} (H1 : ∀a, R a (f a)) (H2 : ∀a b, R a b → f a = f b) :
@is_quotient A (image f) R (fun_image f) elt_of :=
representative_map_to_quotient
H1
(take a b,
have reflR : reflexive R, from rel_refl R,
have H3 : f a = f b → R a b, from representative_map_equiv_inj equiv H1 H2,
have H4 : R a b ↔ f a = f b, from iff.intro (H2 a b) H3,
have H5 : R a b ↔ R b b ∧ f a = f b,
from subst (symm (and_absorb_left _ (reflR b))) H4,
subst (symm (and_absorb_left _ (reflR a))) H5)
end quotient
|
531d5efa056bea3527dc87dbcb5125931d8468f0 | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/tactic/explode.lean | 931f2453e464c3b5cc99433c1e9de74d39382035 | [
"Apache-2.0"
] | permissive | fpvandoorn/mathlib | b21ab4068db079cbb8590b58fda9cc4bc1f35df4 | b3433a51ea8bc07c4159c1073838fc0ee9b8f227 | refs/heads/master | 1,624,791,089,608 | 1,556,715,231,000 | 1,556,715,231,000 | 165,722,980 | 5 | 0 | Apache-2.0 | 1,552,657,455,000 | 1,547,494,646,000 | Lean | UTF-8 | Lean | false | false | 5,253 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Displays a proof term in a line by line format somewhat akin to a Fitch style
proof or the Metamath proof style.
-/
import tactic.basic meta.coinductive_predicates
open expr tactic
namespace tactic
namespace explode
-- TODO(Mario): move back to list.basic
@[simp] def head' {α} : list α → option α
| [] := none
| (a :: l) := some a
inductive status | reg | intro | lam | sintro
meta structure entry :=
(expr : expr)
(line : nat)
(depth : nat)
(status : status)
(thm : string)
(deps : list nat)
meta def pad_right (l : list string) : list string :=
let n := l.foldl (λ r (s:string), max r s.length) 0 in
l.map $ λ s, nat.iterate (λ s, s.push ' ') (n - s.length) s
meta structure entries := mk' ::
(s : expr_map entry)
(l : list entry)
meta def entries.find (es : entries) (e : expr) := es.s.find e
meta def entries.size (es : entries) := es.s.size
meta def entries.add : entries → entry → entries
| es@⟨s, l⟩ e := if s.contains e.expr then es else ⟨s.insert e.expr e, e :: l⟩
meta def entries.head (es : entries) : option entry := head' es.l
meta instance : inhabited entries := ⟨⟨expr_map.mk _, []⟩⟩
meta def format_aux : list string → list string → list string → list entry → tactic format
| (line :: lines) (dep :: deps) (thm :: thms) (en :: es) := do
fmt ← do {
let margin := string.join (list.repeat " │" en.depth),
let margin := match en.status with
| status.sintro := " ├" ++ margin
| status.intro := " │" ++ margin ++ " ┌"
| status.reg := " │" ++ margin ++ ""
| status.lam := " │" ++ margin ++ ""
end,
p ← infer_type en.expr >>= pp,
let lhs := line ++ "│" ++ dep ++ "│ " ++ thm ++ margin ++ " ",
return $ format.of_string lhs ++ to_string p ++ format.line },
(++ fmt) <$> format_aux lines deps thms es
| _ _ _ _ := return format.nil
meta instance : has_to_tactic_format entries :=
⟨λ es : entries,
let lines := pad_right $ es.l.map (λ en, to_string en.line),
deps := pad_right $ es.l.map (λ en, string.intercalate "," (en.deps.map to_string)),
thms := pad_right $ es.l.map entry.thm in
format_aux lines deps thms es.l⟩
meta def append_dep (filter : expr → tactic unit)
(es : entries) (e : expr) (deps : list nat) : tactic (list nat) :=
do { ei ← es.find e,
filter ei.expr,
return (ei.line :: deps) }
<|> return deps
meta def may_be_proof (e : expr) : tactic bool :=
do expr.sort u ← infer_type e >>= infer_type,
return $ bnot u.nonzero
end explode
open explode
meta mutual def explode.core, explode.args (filter : expr → tactic unit)
with explode.core : expr → bool → nat → entries → tactic entries
| e@(lam n bi d b) si depth es := do
m ← mk_fresh_name,
let l := local_const m n bi d,
let b' := instantiate_var b l,
if si then
let en : entry := ⟨l, es.size, depth, status.sintro, to_string n, []⟩ in do
es' ← explode.core b' si depth (es.add en),
return $ es'.add ⟨e, es'.size, depth, status.lam, "∀I", [es.size, es'.size - 1]⟩
else do
let en : entry := ⟨l, es.size, depth, status.intro, to_string n, []⟩,
es' ← explode.core b' si (depth + 1) (es.add en),
deps' ← explode.append_dep filter es' b' [],
deps' ← explode.append_dep filter es' l deps',
return $ es'.add ⟨e, es'.size, depth, status.lam, "∀I", deps'⟩
| e@(macro _ l) si depth es := explode.core l.head si depth es
| e si depth es := filter e >>
match get_app_fn_args e with
| (const n _, args) :=
explode.args e args depth es (to_string n) []
| (fn, []) := do
p ← pp fn,
let en : entry := ⟨fn, es.size, depth, status.reg, to_string p, []⟩,
return (es.add en)
| (fn, args) := do
es' ← explode.core fn ff depth es,
deps ← explode.append_dep filter es' fn [],
explode.args e args depth es' "∀E" deps
end
with explode.args : expr → list expr → nat → entries → string → list nat → tactic entries
| e (arg :: args) depth es thm deps := do
es' ← explode.core arg ff depth es <|> return es,
deps' ← explode.append_dep filter es' arg deps,
explode.args e args depth es' thm deps'
| e [] depth es thm deps :=
return (es.add ⟨e, es.size, depth, status.reg, thm, deps.reverse⟩)
meta def explode_expr (e : expr) (hide_non_prop := tt) : tactic entries :=
let filter := if hide_non_prop then λ e, may_be_proof e >>= guardb else λ _, skip in
tactic.explode.core filter e tt 0 (default _)
meta def explode (n : name) : tactic unit :=
do const n _ ← resolve_name n | fail "cannot resolve name",
d ← get_decl n,
v ← match d with
| (declaration.defn _ _ _ v _ _) := return v
| (declaration.thm _ _ _ v) := return v.get
| _ := fail "not a definition"
end,
t ← pp d.type,
explode_expr v <* trace (to_fmt n ++ " : " ++ t) >>= trace
open interactive lean lean.parser interaction_monad.result
@[user_command]
meta def explode_cmd (_ : parse $ tk "#explode") : parser unit :=
do n ← ident,
explode n
.
-- #explode iff_true_intro
-- #explode nat.strong_rec_on
end tactic
|
ec8765b1948988014cb85b7c00e852cf0d3d95e1 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/theories/move.lean | dcb418e6e621fd9f1575df5501fff6a04896e337 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 21,174 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Temporary file; move in Lean3.
-/
import data.set algebra.order_bigops algebra.ordered_field
import data.finset data.list.sort
import data.real
-- move this to init.function
section
open function
postfix `^~` :std.prec.max_plus := swap
end
-- move to algebra
theorem eq_of_inv_mul_eq_one {A : Type} {a b : A} [group A] (H : b⁻¹ * a = 1) : a = b :=
have a⁻¹ * 1 = a⁻¹, by inst_simp,
by inst_simp
theorem lt_neg_self_of_neg {A : Type} {a : A} [ordered_comm_group A] (Ha : a < 0) : a < -a :=
calc
a < 0 : Ha
... = -0 : by rewrite neg_zero
... < -a : neg_lt_neg Ha
theorem lt_of_add_lt_of_nonneg_left {A : Type} {a b c : A} [ordered_comm_group A]
(H : a + b < c) (Hb : b ≥ 0) : a < c :=
calc
a < c - b : lt_sub_right_of_add_lt H
... ≤ c : sub_le_self _ Hb
theorem lt_of_add_lt_of_nonneg_right {A : Type} {a b c : A} [ordered_comm_group A]
(H : a + b < c) (Hb : a ≥ 0) : b < c :=
calc
b < c - a : lt_sub_left_of_add_lt H
... ≤ c : sub_le_self _ Hb
theorem lt_mul_of_div_lt_of_pos {A : Type} {a b c : A} [linear_ordered_field A]
(Hc : c > 0) (H : a / c < b) : a < b * c :=
calc
a = a / c * c : !div_mul_cancel (ne.symm (ne_of_lt Hc))
... < b * c : mul_lt_mul_of_pos_right H Hc
theorem add_sub_self {A : Type} [add_comm_group A] (a b : A) : a + b - a = b :=
by rewrite [add_sub_assoc, add.comm, sub_add_cancel]
-- move to init.quotient
namespace quot
open classical
variables {A : Type} [s : setoid A]
protected theorem exists_eq_mk (x : quot s) : ∃ a : A, x = ⟦a⟧ :=
quot.induction_on x (take a, exists.intro _ rfl)
protected noncomputable definition repr (x : quot s) : A := some (quot.exists_eq_mk x)
protected theorem mk_repr_eq (x : quot s) : ⟦ quot.repr x ⟧ = x :=
eq.symm (some_spec (quot.exists_eq_mk x))
open setoid
include s
protected theorem repr_mk_equiv (a : A) : quot.repr ⟦a⟧ ≈ a :=
quot.exact (by rewrite quot.mk_repr_eq)
end quot
-- move to data.set.basic
-- move to algebra.ring
theorem mul_two {A : Type} [semiring A] (a : A) : a * 2 = a + a :=
by rewrite [-one_add_one_eq_two, left_distrib, +mul_one]
theorem two_mul {A : Type} [semiring A] (a : A) : 2 * a = a + a :=
by rewrite [-one_add_one_eq_two, right_distrib, +one_mul]
-- move to data.set
namespace set
open function
lemma inter_eq_self_of_subset {X : Type} {s t : set X} (Hst : s ⊆ t) : s ∩ t = s :=
ext (take x, iff.intro
(assume H, !inter_subset_left H)
(assume H, and.intro H (Hst H)))
lemma inter_eq_self_of_subset_right {X : Type} {s t : set X} (Hst : t ⊆ s) : s ∩ t = t :=
by rewrite [inter_comm]; apply inter_eq_self_of_subset Hst
proposition diff_self_inter {X : Type} (s t : set X) : s \ (s ∩ t) = s \ t :=
by rewrite [*diff_eq, compl_inter, inter_distrib_left, inter_compl_self, empty_union]
proposition diff_eq_diff {X : Type} {s t u : set X} (H : s ∩ u = s ∩ t) :
s \ u = s \ t :=
by rewrite [-diff_self_inter, H, diff_self_inter]
-- classical
proposition inter_eq_inter_of_diff_eq_diff {X : Type} {s t u : set X} (H : s \ u = s \ t) :
s ∩ u = s ∩ t :=
by rewrite [-compl_compl u, -compl_compl t]; apply diff_eq_diff H
proposition compl_inter_eq_compl_inter {X : Type} {s t u : set X}
(H : u ∩ s = t ∩ s) :
-u ∩ s = -t ∩ s :=
by rewrite [*inter_comm _ s]; apply diff_eq_diff; rewrite [*inter_comm s, H]
proposition inter_eq_inter_of_compl_inter_eq_compl_inter {X : Type} {s t u : set X}
(H : -u ∩ s = -t ∩ s) :
u ∩ s = t ∩ s :=
begin
rewrite [*inter_comm _ s], apply inter_eq_inter_of_diff_eq_diff,
rewrite [*diff_eq, *inter_comm s, H]
end
proposition singleton_subset_of_mem {X : Type} {x : X} {s : set X} (xs : x ∈ s) : '{x} ⊆ s :=
take y, assume yx,
have y = x, from eq_of_mem_singleton yx,
by rewrite this; exact xs
proposition mem_of_singleton_subset {X : Type} {x : X} {s : set X} (xs : '{x} ⊆ s) : x ∈ s :=
xs !mem_singleton
proposition singleton_subset_iff {X : Type} (x : X) (s : set X) : '{x} ⊆ s ↔ x ∈ s :=
iff.intro mem_of_singleton_subset singleton_subset_of_mem
theorem singleton_subset {X : Type} {a : X} {s : set X} (H : a ∈ s) : '{a} ⊆ s :=
take b, suppose b ∈ '{a},
have b = a, from eq_of_mem_singleton this,
show b ∈ s, by rewrite this; assumption
lemma inter_eq_inter_left {X : Type} {s t u : set X} (H₁ : s ∩ t ⊆ u) (H₂ : s ∩ u ⊆ t) :
s ∩ t = s ∩ u :=
eq_of_subset_of_subset
(subset_inter (inter_subset_left _ _) H₁)
(subset_inter (inter_subset_left _ _) H₂)
lemma inter_eq_inter_right {X : Type} {s t u : set X} (H₁ : s ∩ t ⊆ u) (H₂ : u ∩ t ⊆ s) :
s ∩ t = u ∩ t :=
eq_of_subset_of_subset
(subset_inter H₁ (inter_subset_right _ _))
(subset_inter H₂ (inter_subset_right _ _))
proposition sUnion_subset {X : Type} {S : set (set X)} {t : set X} (H : ∀₀ u ∈ S, u ⊆ t) :
⋃₀ S ⊆ t :=
take x, assume Hx,
obtain u [uS xu], from Hx,
H uS xu
proposition subset_of_sUnion_subset {X : Type} {S : set (set X)} {t : set X}
(H : ⋃₀ S ⊆ t) {u : set X} (Hu : u ∈ S) : u ⊆ t :=
λ x xu, H (exists.intro u (and.intro Hu xu))
proposition preimage_Union {I X Y : Type} (f : X → Y) (u : I → set Y) :
f '- (⋃ i, u i) = ⋃ i, (f '- (u i)) :=
ext (take x, !iff.refl)
-- TODO: rename "injective" to "inj"
-- TODO: turn around equality in definition of image
-- TODO: use ∀₀ in definition of injective (and define notation for ∀₀ x y ∈ s, ...)
attribute [trans] subset.trans -- really? this was never declared? And all the variants...
proposition mem_set_of_iff {X : Type} (P : X → Prop) (a : X) : a ∈ { x : X | P x } ↔ P a :=
iff.refl _
proposition mem_set_of {X : Type} {P : X → Prop} {a : X} (Pa : P a) : a ∈ { x : X | P x } := Pa
proposition of_mem_set_of {X : Type} {P : X → Prop} {a : X} (H : a ∈ { x : X | P x }) : P a := H
proposition forallb_of_forall {X : Type} {P : X → Prop} (s : set X) (H : ∀ x, P x) :
∀₀ x ∈ s, P x :=
λ x xs, H x
proposition forall_of_forallb_univ {X : Type} {P : X → Prop} (H : ∀₀ x ∈ univ, P x) : ∀ x, P x :=
λ x, H trivial
proposition forallb_univ_iff_forall {X : Type} (P : X → Prop) : (∀₀ x ∈ univ, P x) ↔ ∀ x, P x :=
iff.intro forall_of_forallb_univ !forallb_of_forall
proposition forallb_of_subset {X : Type} {s t : set X} {P : X → Prop}
(ssubt : s ⊆ t) (Ht : ∀₀ x ∈ t, P x) : ∀₀ x ∈ s, P x :=
λ x xs, Ht (ssubt xs)
proposition forallb_of_forall₂ {X Y : Type} {P : X → Y → Prop} (s : set X) (t : set Y)
(H : ∀ x y, P x y) : ∀₀ x ∈ s, ∀₀ y ∈ t, P x y :=
λ x xs y yt, H x y
proposition forall_of_forallb_univ₂ {X Y : Type} {P : X → Y → Prop}
(H : ∀₀ x ∈ univ, ∀₀ y ∈ univ, P x y) : ∀ x y, P x y :=
λ x y, H trivial trivial
proposition forallb_univ_iff_forall₂ {X Y : Type} (P : X → Y → Prop) :
(∀₀ x ∈ univ, ∀₀ y ∈ univ, P x y) ↔ ∀ x y, P x y :=
iff.intro forall_of_forallb_univ₂ !forallb_of_forall₂
proposition forallb_of_subset₂ {X Y : Type} {s₁ t₁ : set X} {s₂ t₂ : set Y} {P : X → Y → Prop}
(ssubt₁ : s₁ ⊆ t₁) (ssubt₂ : s₂ ⊆ t₂) (Ht : ∀₀ x ∈ t₁, ∀₀ y ∈ t₂, P x y) :
∀₀ x ∈ s₁, ∀₀ y ∈ s₂, P x y :=
λ x xs y ys, Ht (ssubt₁ xs) (ssubt₂ ys)
theorem maps_to_univ {X Y : Type} (f : X → Y) (a : set X) : maps_to f a univ :=
take x, assume H, trivial
theorem surj_on_image {X Y : Type} (f : X → Y) (a : set X) : surj_on f a (f ' a) :=
λ y Hy, Hy
theorem image_eq_univ_of_surjective {X Y : Type} {f : X → Y} (H : surjective f) :
f ' univ = univ :=
ext (take y, iff.intro (λ H', trivial)
(λ H', obtain x xeq, from H y,
show y ∈ f ' univ, from mem_image trivial xeq))
proposition image_inter_subset {X Y : Type} (f : X → Y) (s t : set X) :
f ' (s ∩ t) ⊆ f ' s ∩ f ' t :=
take y, assume ymem,
obtain x [[xs xt] (xeq : f x = y)], from ymem,
show y ∈ f ' s ∩ f ' t,
begin
rewrite -xeq,
exact (and.intro (mem_image_of_mem f xs) (mem_image_of_mem f xt))
end
--proposition image_eq_of_maps_to_of_surj_on {X Y : Type} {f : X → Y} {s : set X} {t : set Y}
-- (H : maps_to f s t) (H' : surj_on f s t) :
-- f ' s = t :=
--eq_of_subset_of_subset (image_subset_of_maps_to H) H'
proposition surj_on_of_image_eq {X Y : Type} {f : X → Y} {s : set X} {t : set Y}
(H : f ' s = t) :
surj_on f s t :=
by rewrite [↑surj_on, H]; apply subset.refl
proposition surjective_induction {X Y : Type} {P : Y → Prop} {f : X → Y}
(surjf : surjective f) (H : ∀ x, P (f x)) :
∀ y, P y :=
take y,
obtain x (yeq : f x = y), from surjf y,
show P y, by rewrite -yeq; apply H x
proposition surjective_induction₂ {X Y : Type} {P : Y → Y → Prop} {f : X → Y}
(surjf : surjective f) (H : ∀ x₁ x₂, P (f x₁) (f x₂)) :
∀ y₁ y₂, P y₁ y₂ :=
take y₁ y₂,
obtain x₁ (y₁eq : f x₁ = y₁), from surjf y₁,
obtain x₂ (y₂eq : f x₂ = y₂), from surjf y₂,
show P y₁ y₂, by rewrite [-y₁eq, -y₂eq]; apply H x₁ x₂
proposition surj_on_univ_induction {X Y : Type} {P : Y → Prop} {f : X → Y} {s : set X}
(surjfs : surj_on f s univ) (H : ∀₀ x ∈ s, P (f x)) :
∀ y, P y :=
take y,
obtain x [xs (yeq : f x = y)], from surjfs trivial,
show P y, by rewrite -yeq; apply H xs
proposition surj_on_univ_induction₂ {X Y : Type} {P : Y → Y → Prop} {f : X → Y} {s : set X}
(surjfs : surj_on f s univ) (H : ∀₀ x₁ ∈ s, ∀₀ x₂ ∈ s, P (f x₁) (f x₂)) :
∀ y₁ y₂, P y₁ y₂ :=
take y₁ y₂,
obtain x₁ [x₁s (y₁eq : f x₁ = y₁)], from surjfs trivial,
obtain x₂ [x₂s (y₂eq : f x₂ = y₂)], from surjfs trivial,
show P y₁ y₂, by rewrite [-y₁eq, -y₂eq]; apply H x₁s x₂s
proposition surj_on_univ_of_surjective {X Y : Type} {f : X → Y} (s : set Y) (H : surjective f) :
surj_on f univ s :=
take y, assume ys,
obtain x yeq, from H y,
mem_image !mem_univ yeq
proposition mem_of_mem_image_of_injective {X Y : Type} {f : X → Y} {s : set X} {a : X}
(injf : injective f) (H : f a ∈ f ' s) :
a ∈ s :=
obtain b [bs faeq], from H,
have b = a, from injf faeq,
by rewrite -this; apply bs
proposition mem_of_mem_image_of_inj_on {X Y : Type} {f : X → Y} {s t : set X} {a : X} (Ha : a ∈ t)
(Hs : s ⊆ t) (injft : inj_on f t) (H : f a ∈ f ' s) :
a ∈ s :=
obtain b [bs faeq], from H,
have b = a, from injft (Hs bs) Ha faeq,
by rewrite -this; apply bs
proposition eq_singleton_of_forall_eq {A : Type} {s : set A} {x : A} (xs : x ∈ s) (H : ∀₀ y ∈ s, y = x) :
s = '{x} :=
ext (take y, iff.intro
(assume ys, mem_singleton_of_eq (H ys))
(assume yx, by rewrite (eq_of_mem_singleton yx); assumption))
proposition insert_subset {A : Type} {s t : set A} {a : A} (amem : a ∈ t) (ssubt : s ⊆ t) : insert a s ⊆ t :=
take x, assume xias,
or.elim (eq_or_mem_of_mem_insert xias)
(by simp)
(take H, ssubt H)
-- move to data.set.finite
lemma finite_sUnion {A : Type} {S : set (set A)} [H : finite S] :
(∀s, s ∈ S → finite s) → finite ⋃₀S :=
induction_on_finite S
(by intro H; rewrite sUnion_empty; apply finite_empty)
(take a s, assume fins anins ih h,
begin
rewrite sUnion_insert,
apply finite_union,
{apply h _ (mem_insert a s)},
apply ih (forall_of_forall_insert h)
end)
lemma subset_powerset_sUnion {A : Type} (S : set (set A)) : S ⊆ 𝒫 (⋃₀ S) :=
take u, suppose u ∈ S, show u ⊆ ⋃₀ S, from subset_sUnion_of_mem this
lemma finite_of_finite_sUnion {A : Type} (S : set (set A)) (H : finite ⋃₀S) : finite S :=
have finite (𝒫 (⋃₀ S)), from finite_powerset _,
show finite S, from finite_subset (subset_powerset_sUnion S)
section nat
open nat
proposition ne_empty_of_card_pos {A : Type} {s : set A} (H : card s > 0) : s ≠ ∅ :=
take H', begin rewrite [H' at H, card_empty at H], exact lt.irrefl 0 H end
lemma eq_of_card_eq_one {A : Type} {S : set A} (H : card S = 1) {x y : A} (Hx : x ∈ S) (Hy : y ∈ S) :
x = y :=
have finite S,
from classical.by_contradiction
(assume nfinS, begin rewrite (card_of_not_finite nfinS) at H, contradiction end),
classical.by_contradiction
(assume H0 : x ≠ y,
have H1 : '{x, y} ⊆ S, from insert_subset Hx (insert_subset Hy (empty_subset _)),
have x ∉ '{y}, from assume H, H0 (eq_of_mem_singleton H),
have 2 ≤ 1, from calc
2 = card '{x, y} : by rewrite [card_insert_of_not_mem this,
card_insert_of_not_mem (not_mem_empty _), card_empty]
... ≤ card S : card_le_card_of_subset H1
... = 1 : H,
show false, from dec_trivial this)
proposition eq_singleton_of_card_eq_one {A : Type} {s : set A} {x : A} (H : card s = 1) (xs : x ∈ s) :
s = '{x} :=
eq_singleton_of_forall_eq xs (take y, assume ys, eq.symm (eq_of_card_eq_one H xs ys))
proposition exists_eq_singleton_of_card_eq_one {A : Type} {s : set A} (H : card s = 1) : ∃ x, s = '{x} :=
have s ≠ ∅, from ne_empty_of_card_pos (by rewrite H; apply dec_trivial),
obtain (x : A) (xs : x ∈ s), from exists_mem_of_ne_empty this,
exists.intro x (eq_singleton_of_card_eq_one H xs)
end nat
-- move to data.set.classical_inverse (and rename file to "inverse")
theorem inv_fun_spec {X Y : Type} {f : X → Y} {a : set X} {dflt : X} {x : X} (xa : x ∈ a) :
f (inv_fun f a dflt (f x)) = f x :=
and.right (inv_fun_pos (exists.intro x (and.intro xa rfl)))
theorem inv_fun_spec' {X Y : Type} {f : X → Y} {a : set X} {dflt : X} {x : X} (xa : x ∈ a) :
inv_fun f a dflt (f x) ∈ a :=
and.left (inv_fun_pos (exists.intro x (and.intro xa rfl)))
-- TODO: move to data.set.filter
namespace filter
protected theorem le_iff {X : Type} (F₁ F₂ : filter X) : F₁ ≤ F₂ ↔ F₂ ⊆ F₁ := iff.refl _
-- TODO: change names of fields in filter
-- TODO: reorder hypotheses in eventually_of_le, and change "le" to "ge"
-- TODO: fix eventually_inf: implicit argument, and use implication
-- TODO: set: add spaces around ∀₀ x ∈ s and ∃₀ x ∈ s
theorem eventually_inf_left {X : Type} {P : X → Prop} {F₁ : filter X} (F₂ : filter X)
(H : eventually P F₁) : eventually P (inf F₁ F₂) :=
eventually_of_le H !inf_le_left
theorem eventually_inf_right {X : Type} {P : X → Prop} (F₁ : filter X) {F₂ : filter X}
(H : eventually P F₂) : eventually P (inf F₁ F₂) :=
eventually_of_le H !inf_le_right
theorem eventually_Inf {X : Type} {P : X → Prop} {S : set (filter X)} {F : filter X} (FS : F ∈ S)
(H : eventually P F) : eventually P (Inf S) :=
eventually_of_le H (Inf_le FS)
-- TODO: replace definition of Inf with this
definition Inf' {X : Type} (S : set (filter X)) : filter X :=
⦃ filter,
sets := { s | ∃ T : set (set X), finite T ∧ T ⊆ (⋃ F ∈ S, sets F) ∧ ⋂₀ T ⊆ s},
univ_mem_sets := abstract
have H : (⋂₀ ∅) ⊆ @univ X, by rewrite sInter_empty; apply subset.refl,
exists.intro ∅ (and.intro !finite_empty (and.intro (empty_subset _) H))
end,
inter_closed := abstract
take s t, assume Hs Ht,
obtain Ts finTs Tssub ITs, from Hs,
obtain Tt finTt Ttsub ITt, from Ht,
have H1 : finite (Ts ∪ Tt), proof finite_union Ts Tt qed,
have H2 : Ts ∪ Tt ⊆ (⋃ F ∈ S, sets F), from union_subset Tssub Ttsub,
have H3 : ⋂₀ (Ts ∪ Tt) ⊆ s ∩ t,
begin
rewrite sInter_union, apply subset_inter,
{exact subset.trans (inter_subset_left _ _) ITs},
exact subset.trans (inter_subset_right _ _) ITt
end,
exists.intro _ (and.intro H1 (and.intro H2 H3))
end,
is_mono := abstract
take s t ssubt Hs,
obtain T finT Tsub IT, from Hs,
exists.intro T (and.intro finT (and.intro Tsub (subset.trans IT ssubt)))
end
⦄
theorem sets_Inf' {A : Type} (S : set (filter A)) :
sets (Inf' S) = { s | ∃ T : set (set A), finite T ∧ T ⊆ (⋃ F ∈ S, sets F) ∧ ⋂₀ T ⊆ s} :=
rfl
theorem sInter_mem_of_finite {A : Type} {F : filter A} {T : set (set A)} (finT : finite T)
(Tsub : T ⊆ sets F) : ⋂₀ T ∈ sets F :=
begin
induction finT with a T finT aninT ih,
{rewrite sInter_empty, apply filter.univ_mem_sets},
rewrite sInter_insert, apply filter.inter_closed,
show a ∈ sets F, from Tsub (mem_insert a T),
show ⋂₀ T ∈ sets F, from ih (subset.trans (subset_insert _ _) Tsub)
end
theorem le_Inf' {A : Type} {F : filter A} {S : set (filter A)} (H : ∀₀ G ∈ S, F ≤ G) :
F ≤ Inf' S :=
filter.le_of_subset
(take s, suppose s ∈ sets (Inf' S),
obtain (T : set (set A)) finT (Tsub : T ⊆ (⋃ G ∈ S, sets G)) (IT : ⋂₀ T ⊆ s), from this,
have T ⊆ sets F, from subset.trans Tsub (bUnion_subset H),
have ⋂₀ T ∈ sets F, from sInter_mem_of_finite finT this,
show s ∈ sets F, from filter.is_mono _ IT this)
theorem Inf'_le {A : Type} {F : filter A} {S : set (filter A)} (FS : F ∈ S) :
Inf' S ≤ F :=
filter.le_of_subset
(take s, suppose s ∈ sets F,
have '{s} ⊆ ⋃ G ∈ S, sets G, from singleton_subset (mem_bUnion FS this),
exists.intro '{s} (and.intro _
(and.intro this (by rewrite sInter_singleton; apply subset.refl))))
theorem Inf_eq_Inf' {A : Type} (S : set (filter A)) : Inf S = Inf' S :=
le.antisymm (le_Inf' (λ F FS, Inf_le FS)) (le_Inf (λ F FS, Inf'_le FS))
theorem exists_eventually_of_eventually_Inf {A : Type} {P : A → Prop} {F : filter A}
{S : set (filter A)} (FS : F ∈ S) (H' : eventually P (Inf S))
(H : ∀₀ F₁ ∈ S, ∀₀ F₂ ∈ S, ∃₀ F ∈ S, F ≤ inf F₁ F₂) :
∃₀ F ∈ S, eventually P F :=
have P ∈ Inf' S, by rewrite -Inf_eq_Inf'; apply H',
have ∃ T : set (set A), finite T ∧ T ⊆ (⋃ F ∈ S, sets F) ∧ ⋂₀ T ⊆ P,
by rewrite sets_Inf' at this; exact this,
obtain T finT Tsub ITP, from this,
have ∃₀ F ∈ S, ⋂₀ T ∈ F,
begin
clear ITP,
induction finT with s T finT sninT ih,
{exact exists.intro F (and.intro FS (by rewrite sInter_empty; apply filter.univ_mem_sets))},
have ∃₀ F ∈ S, ⋂₀ T ∈ F, from ih (subset.trans (subset_insert _ _) Tsub),
cases this with F₁ H₁,
cases H₁ with F₁S ITF₁,
have s ∈ (⋃ F ∈ S, sets F), from Tsub !mem_insert,
cases this with F₂ H₂,
cases H₂ with F₂S sF₂,
cases H F₁S F₂S with F' HF',
cases HF' with F'S F'le,
existsi F', split, exact F'S,
show ⋂₀ insert s T ∈ sets F',
begin
rewrite sInter_insert, apply filter.inter_closed,
show s ∈ sets F', from filter.subset_of_le (le.trans F'le !inf_le_right) sF₂,
show ⋂₀ T ∈ sets F', from filter.subset_of_le (le.trans F'le !inf_le_left) ITF₁,
end
end,
obtain F FS IT, from this,
exists.intro F (and.intro FS (filter.is_mono _ ITP IT))
end filter
end set
-- move to data.finset
namespace finset
section
variables {A : Type} [decidable_linear_order A]
definition finset_to_list (s : finset A) : list A :=
quot.lift_on s
(take l, list.sort le (subtype.elt_of l))
(take a b, assume eqab, list.sort_eq_of_perm eqab)
proposition to_finset_finset_to_list (s : finset A) : to_finset (finset_to_list s) = s :=
quot.induction_on s
begin
intro l,
have H : list.nodup (list.sort le (subtype.elt_of l)),
from perm.nodup_of_perm_of_nodup (perm.symm !list.sort_perm) (subtype.has_property l),
rewrite [↑finset_to_list, -to_finset_eq_of_nodup H],
apply quot.sound,
apply list.sort_perm
end
proposition nodup_finset_to_list (s : finset A) : list.nodup (finset_to_list s) :=
quot.induction_on s
(take l, perm.nodup_of_perm_of_nodup (perm.symm !list.sort_perm) (subtype.has_property l))
proposition sorted_finset_to_list (s : finset A) : list.sorted le (finset_to_list s) :=
quot.induction_on s
(take l, list.sorted_of_strongly_sorted (list.strongly_sorted_sort _))
end
end finset
-- move to data.nat?
namespace nat
open finset
theorem succ_Max₀_not_mem (s : finset ℕ) : succ (Max₀ s) ∉ s :=
suppose succ (Max₀ s) ∈ s,
have succ (Max₀ s) ≤ Max₀ s, from le_Max₀ this,
show false, from not_succ_le_self this
end nat
-- move to real
namespace real
theorem lt_of_abs_lt {a b : ℝ} (Ha : abs a < b) : a < b :=
if Hnn : a ≥ 0 then
by rewrite [-abs_of_nonneg Hnn]; exact Ha
else
have Hlt : a < 0, from lt_of_not_ge Hnn,
have -a < b, by rewrite [-abs_of_neg Hlt]; exact Ha,
calc
a < -a : lt_neg_self_of_neg Hlt
... < b : this
end real
|
48f1079a509818a084b625ec34d469c69dc6fa05 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/tactic/solve_by_elim.lean | cf2bc2d565e275d3149b6a2dd32283f719cac8b1 | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 4,015 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Scott Morrison
-/
import tactic.core
namespace tactic
meta def mk_assumption_set (no_dflt : bool) (hs : list simp_arg_type) (attr : list name) : tactic (list expr) :=
do (hs, gex, hex, all_hyps) ← decode_simp_arg_list hs,
hs ← hs.mmap i_to_expr_for_apply,
l ← attr.mmap $ λ a, attribute.get_instances a,
let l := l.join,
m ← list.mmap mk_const l,
let hs := (hs ++ m).filter $ λ h, expr.const_name h ∉ gex,
hs ← if no_dflt then
return hs
else
do { congr_fun ← mk_const `congr_fun,
congr_arg ← mk_const `congr_arg,
return (congr_fun :: congr_arg :: hs) },
if ¬ no_dflt ∨ all_hyps then do
ctx ← local_context,
return $ hs.append (ctx.filter (λ h, h.local_uniq_name ∉ hex)) -- remove local exceptions
else return hs
meta def solve_by_elim_aux (discharger : tactic unit) (asms : tactic (list expr)) : ℕ → tactic unit
| 0 := done
| (n+1) := done <|>
(discharger >> solve_by_elim_aux n) <|>
(apply_assumption asms $ solve_by_elim_aux n)
meta structure by_elim_opt :=
(all_goals : bool := ff)
(discharger : tactic unit := done)
(assumptions : tactic (list expr) := local_context)
(max_rep : ℕ := 3)
meta def solve_by_elim (opt : by_elim_opt := { }) : tactic unit :=
do
tactic.fail_if_no_goals,
(if opt.all_goals then id else focus1) $
solve_by_elim_aux opt.discharger opt.assumptions opt.max_rep
open interactive lean.parser interactive.types
local postfix `?`:9001 := optional
namespace interactive
/--
`apply_assumption` looks for an assumption of the form `... → ∀ _, ... → head`
where `head` matches the current goal.
alternatively, when encountering an assumption of the form `sg₀ → ¬ sg₁`,
after the main approach failed, the goal is dismissed and `sg₀` and `sg₁`
are made into the new goal.
optional arguments:
- asms: list of rules to consider instead of the local constants
- tac: a tactic to run on each subgoals after applying an assumption; if
this tactic fails, the corresponding assumption will be rejected and
the next one will be attempted.
-/
meta def apply_assumption
(asms : tactic (list expr) := local_context)
(tac : tactic unit := return ()) : tactic unit :=
tactic.apply_assumption asms tac
/--
`solve_by_elim` calls `apply_assumption` on the main goal to find an assumption whose head matches
and then repeatedly calls `apply_assumption` on the generated subgoals until no subgoals remain,
performing at most `max_rep` recursive steps.
`solve_by_elim` discharges the current goal or fails
`solve_by_elim` performs back-tracking if `apply_assumption` chooses an unproductive assumption
By default, the assumptions passed to apply_assumption are the local context, `congr_fun` and
`congr_arg`.
`solve_by_elim [h₁, h₂, ..., hᵣ]` also applies the named lemmas.
`solve_by_elim with attr₁ ... attrᵣ also applied all lemmas tagged with the specified attributes.
`solve_by_elim only [h₁, h₂, ..., hᵣ]` does not include the local context, `congr_fun`, or `congr_arg`
unless they are explicitly included.
`solve_by_elim [-id]` removes a specified assumption.
`solve_by_elim*` tries to solve all goals together, using backtracking if a solution for one goal
makes other goals impossible.
optional arguments:
- discharger: a subsidiary tactic to try at each step (e.g. `cc` may be helpful)
- max_rep: number of attempts at discharging generated sub-goals
-/
meta def solve_by_elim (all_goals : parse $ (tk "*")?) (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list) (opt : by_elim_opt := { }) : tactic unit :=
do asms ← mk_assumption_set no_dflt hs attr_names,
tactic.solve_by_elim { all_goals := all_goals.is_some, assumptions := return asms, ..opt }
end interactive
end tactic
|
89f6bd4df742ada20139d25ea6d1c3b71a95a9dd | 54c9ed381c63410c9b6af3b0a1722c41152f037f | /Lib4/Examples/InfinitePrimes.lean | 5f4d72b81eda1a140a9231b18e872ea9ba458593 | [
"Apache-2.0"
] | permissive | dselsam/binport | 0233f1aa961a77c4fc96f0dccc780d958c5efc6c | aef374df0e169e2c3f1dc911de240c076315805c | refs/heads/master | 1,687,453,448,108 | 1,627,483,296,000 | 1,627,483,296,000 | 333,825,622 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 527 | lean | import Mathlib.data.nat.prime
open Mathlib Mathlib.nat
theorem exists_infinite_primes (n : Nat) : ∃ p, n ≤ p ∧ prime p :=
let p := min_fac (factorial n + 1)
have f1 : factorial n + 1 ≠ 1 := ne_of_gt $ succ_lt_succ $ factorial_pos _
have pp : prime p := min_fac_prime f1
have np : n ≤ p := le_of_not_ge λ h =>
have h₁ : p ∣ factorial n := dvd_factorial (min_fac_pos _) h
have h₂ : p ∣ 1 := (nat.dvd_add_iff_right h₁).2 (min_fac_dvd _)
pp.not_dvd_one h₂
Exists.intro p ⟨np, pp⟩
|
69767b654174f4192fc6d24cc1458327f6e19841 | b2fe74b11b57d362c13326bc5651244f111fa6f4 | /src/group_theory/submonoid/operations.lean | b3ce61276f29916929483cda8cb19522e65c2cc0 | [
"Apache-2.0"
] | permissive | midfield/mathlib | c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7 | 775edc615ecec631d65b6180dbcc7bc26c3abc26 | refs/heads/master | 1,675,330,551,921 | 1,608,304,514,000 | 1,608,304,514,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 22,631 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard,
Amelia Livingston, Yury Kudryashov
-/
import group_theory.submonoid.basic
import data.equiv.mul_add
import algebra.group.prod
import algebra.group.inj_surj
/-!
# Operations on `submonoid`s
In this file we define various operations on `submonoid`s and `monoid_hom`s.
## Main definitions
### Conversion between multiplicative and additive definitions
* `submonoid.to_add_submonoid`, `submonoid.of_add_submonoid`, `add_submonoid.to_submonoid`,
`add_submonoid.of_submonoid`: convert between multiplicative and additive submonoids of `M`,
`multiplicative M`, and `additive M`.
* `submonoid.add_submonoid_equiv`: equivalence between `submonoid M`
and `add_submonoid (additive M)`.
### (Commutative) monoid structure on a submonoid
* `submonoid.to_monoid`, `submonoid.to_comm_monoid`: a submonoid inherits a (commutative) monoid
structure.
### Operations on submonoids
* `submonoid.comap`: preimage of a submonoid under a monoid homomorphism as a submonoid of the
domain;
* `submonoid.map`: image of a submonoid under a monoid homomorphism as a submonoid of the codomain;
* `submonoid.prod`: product of two submonoids `s : submonoid M` and `t : submonoid N` as a submonoid
of `M × N`;
### Monoid homomorphisms between submonoid
* `submonoid.subtype`: embedding of a submonoid into the ambient monoid.
* `submonoid.inclusion`: given two submonoids `S`, `T` such that `S ≤ T`, `S.inclusion T` is the
inclusion of `S` into `T` as a monoid homomorphism;
* `mul_equiv.submonoid_congr`: converts a proof of `S = T` into a monoid isomorphism between `S`
and `T`.
* `submonoid.prod_equiv`: monoid isomorphism between `s.prod t` and `s × t`;
### Operations on `monoid_hom`s
* `monoid_hom.mrange`: range of a monoid homomorphism as a submonoid of the codomain;
* `monoid_hom.mrestrict`: restrict a monoid homomorphism to a submonoid;
* `monoid_hom.cod_mrestrict`: restrict the codomain of a monoid homomorphism to a submonoid;
* `monoid_hom.mrange_restrict`: restrict a monoid homomorphism to its range;
## Tags
submonoid, range, product, map, comap
-/
variables {M N P : Type*} [monoid M] [monoid N] [monoid P] (S : submonoid M)
/-!
### Conversion to/from `additive`/`multiplicative`
-/
/-- Map from submonoids of monoid `M` to `add_submonoid`s of `additive M`. -/
def submonoid.to_add_submonoid {M : Type*} [monoid M] (S : submonoid M) :
add_submonoid (additive M) :=
{ carrier := S.carrier,
zero_mem' := S.one_mem',
add_mem' := S.mul_mem' }
/-- Map from `add_submonoid`s of `additive M` to submonoids of `M`. -/
def submonoid.of_add_submonoid {M : Type*} [monoid M] (S : add_submonoid (additive M)) :
submonoid M :=
{ carrier := S.carrier,
one_mem' := S.zero_mem',
mul_mem' := S.add_mem' }
/-- Map from `add_submonoid`s of `add_monoid M` to submonoids of `multiplicative M`. -/
def add_submonoid.to_submonoid {M : Type*} [add_monoid M] (S : add_submonoid M) :
submonoid (multiplicative M) :=
{ carrier := S.carrier,
one_mem' := S.zero_mem',
mul_mem' := S.add_mem' }
/-- Map from submonoids of `multiplicative M` to `add_submonoid`s of `add_monoid M`. -/
def add_submonoid.of_submonoid {M : Type*} [add_monoid M] (S : submonoid (multiplicative M)) :
add_submonoid M :=
{ carrier := S.carrier,
zero_mem' := S.one_mem',
add_mem' := S.mul_mem' }
/-- Submonoids of monoid `M` are isomorphic to additive submonoids of `additive M`. -/
def submonoid.add_submonoid_equiv (M : Type*) [monoid M] :
submonoid M ≃ add_submonoid (additive M) :=
{ to_fun := submonoid.to_add_submonoid,
inv_fun := submonoid.of_add_submonoid,
left_inv := λ x, by cases x; refl,
right_inv := λ x, by cases x; refl }
namespace submonoid
open set
/-!
### `comap` and `map`
-/
/-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive "The preimage of an `add_submonoid` along an `add_monoid` homomorphism is an
`add_submonoid`."]
def comap (f : M →* N) (S : submonoid N) : submonoid M :=
{ carrier := (f ⁻¹' S),
one_mem' := show f 1 ∈ S, by rw f.map_one; exact S.one_mem,
mul_mem' := λ a b ha hb,
show f (a * b) ∈ S, by rw f.map_mul; exact S.mul_mem ha hb }
@[simp, to_additive]
lemma coe_comap (S : submonoid N) (f : M →* N) : (S.comap f : set M) = f ⁻¹' S := rfl
@[simp, to_additive]
lemma mem_comap {S : submonoid N} {f : M →* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := iff.rfl
@[to_additive]
lemma comap_comap (S : submonoid P) (g : N →* P) (f : M →* N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[to_additive, simp]
lemma comap_id (S : submonoid P) : S.comap (monoid_hom.id _) = S :=
ext (by simp)
/-- The image of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive "The image of an `add_submonoid` along an `add_monoid` homomorphism is
an `add_submonoid`."]
def map (f : M →* N) (S : submonoid M) : submonoid N :=
{ carrier := (f '' S),
one_mem' := ⟨1, S.one_mem, f.map_one⟩,
mul_mem' := begin rintros _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩, exact ⟨x * y, S.mul_mem hx hy,
by rw f.map_mul; refl⟩ end }
@[simp, to_additive]
lemma coe_map (f : M →* N) (S : submonoid M) :
(S.map f : set N) = f '' S := rfl
@[simp, to_additive]
lemma mem_map {f : M →* N} {S : submonoid M} {y : N} :
y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=
mem_image_iff_bex
@[to_additive]
lemma mem_map_of_mem (f : M →* N) (x : S) : f x ∈ S.map f :=
mem_image_of_mem f x.2
@[to_additive]
lemma map_map (g : N →* P) (f : M →* N) : (S.map f).map g = S.map (g.comp f) :=
ext' $ image_image _ _ _
@[to_additive]
lemma map_le_iff_le_comap {f : M →* N} {S : submonoid M} {T : submonoid N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
@[to_additive]
lemma gc_map_comap (f : M →* N) : galois_connection (map f) (comap f) :=
λ S T, map_le_iff_le_comap
@[to_additive]
lemma map_le_of_le_comap {T : submonoid N} {f : M →* N} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
@[to_additive]
lemma le_comap_of_map_le {T : submonoid N} {f : M →* N} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
@[to_additive]
lemma le_comap_map {f : M →* N} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
@[to_additive]
lemma map_comap_le {S : submonoid N} {f : M →* N} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
@[to_additive]
lemma monotone_map {f : M →* N} : monotone (map f) :=
(gc_map_comap f).monotone_l
@[to_additive]
lemma monotone_comap {f : M →* N} : monotone (comap f) :=
(gc_map_comap f).monotone_u
@[simp, to_additive]
lemma map_comap_map {f : M →* N} : ((S.map f).comap f).map f = S.map f :=
congr_fun ((gc_map_comap f).l_u_l_eq_l) _
@[simp, to_additive]
lemma comap_map_comap {S : submonoid N} {f : M →* N} : ((S.comap f).map f).comap f = S.comap f :=
congr_fun ((gc_map_comap f).u_l_u_eq_u) _
@[to_additive]
lemma map_sup (S T : submonoid M) (f : M →* N) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f).l_sup
@[to_additive]
lemma map_supr {ι : Sort*} (f : M →* N) (s : ι → submonoid M) :
(supr s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_supr
@[to_additive]
lemma comap_inf (S T : submonoid N) (f : M →* N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f).u_inf
@[to_additive]
lemma comap_infi {ι : Sort*} (f : M →* N) (s : ι → submonoid N) :
(infi s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_infi
@[simp, to_additive] lemma map_bot (f : M →* N) : (⊥ : submonoid M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp, to_additive] lemma comap_top (f : M →* N) : (⊤ : submonoid N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp, to_additive] lemma map_id (S : submonoid M) : S.map (monoid_hom.id M) = S :=
ext (λ x, ⟨λ ⟨_, h, rfl⟩, h, λ h, ⟨_, h, rfl⟩⟩)
section galois_coinsertion
variables {ι : Type*} {f : M →* N} (hf : function.injective f)
include hf
/-- `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. -/
def gci_map_comap : galois_coinsertion (map f) (comap f) :=
(gc_map_comap f).to_galois_coinsertion
(λ S x, by simp [mem_comap, mem_map, hf.eq_iff])
lemma comap_map_eq_of_injective (S : submonoid M) : (S.map f).comap f = S :=
(gci_map_comap hf).u_l_eq _
lemma comap_surjective_of_injective : function.surjective (comap f) :=
(gci_map_comap hf).u_surjective
lemma map_injective_of_injective : function.injective (map f) :=
(gci_map_comap hf).l_injective
lemma comap_inf_map_of_injective (S T : submonoid M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gci_map_comap hf).u_inf_l _ _
lemma comap_infi_map_of_injective (S : ι → submonoid M) : (⨅ i, (S i).map f).comap f = infi S :=
(gci_map_comap hf).u_infi_l _
lemma comap_sup_map_of_injective (S T : submonoid M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gci_map_comap hf).u_sup_l _ _
lemma comap_supr_map_of_injective (S : ι → submonoid M) : (⨆ i, (S i).map f).comap f = supr S :=
(gci_map_comap hf).u_supr_l _
lemma map_le_map_iff_of_injective {S T : submonoid M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gci_map_comap hf).l_le_l_iff
lemma map_strict_mono_of_injective : strict_mono (map f) :=
(gci_map_comap hf).strict_mono_l
end galois_coinsertion
section galois_insertion
variables {ι : Type*} {f : M →* N} (hf : function.surjective f)
include hf
/-- `map f` and `comap f` form a `galois_insertion` when `f` is surjective. -/
def gi_map_comap : galois_insertion (map f) (comap f) :=
(gc_map_comap f).to_galois_insertion
(λ S x h, let ⟨y, hy⟩ := hf x in mem_map.2 ⟨y, by simp [hy, h]⟩)
lemma map_comap_eq_of_surjective (S : submonoid N) : (S.comap f).map f = S :=
(gi_map_comap hf).l_u_eq _
lemma map_surjective_of_surjective : function.surjective (map f) :=
(gi_map_comap hf).l_surjective
lemma comap_injective_of_surjective : function.injective (comap f) :=
(gi_map_comap hf).u_injective
lemma map_inf_comap_of_surjective (S T : submonoid N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(gi_map_comap hf).l_inf_u _ _
lemma map_infi_comap_of_surjective (S : ι → submonoid N) : (⨅ i, (S i).comap f).map f = infi S :=
(gi_map_comap hf).l_infi_u _
lemma map_sup_comap_of_surjective (S T : submonoid N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(gi_map_comap hf).l_sup_u _ _
lemma map_supr_comap_of_surjective (S : ι → submonoid N) : (⨆ i, (S i).comap f).map f = supr S :=
(gi_map_comap hf).l_supr_u _
lemma comap_le_comap_iff_of_surjective {S T : submonoid N} : S.comap f ≤ T.comap f ↔ S ≤ T :=
(gi_map_comap hf).u_le_u_iff
lemma comap_strict_mono_of_surjective : strict_mono (comap f) :=
(gi_map_comap hf).strict_mono_u
end galois_insertion
/-- A submonoid of a monoid inherits a multiplication. -/
@[to_additive "An `add_submonoid` of an `add_monoid` inherits an addition."]
instance has_mul : has_mul S := ⟨λ a b, ⟨a.1 * b.1, S.mul_mem a.2 b.2⟩⟩
/-- A submonoid of a monoid inherits a 1. -/
@[to_additive "An `add_submonoid` of an `add_monoid` inherits a zero."]
instance has_one : has_one S := ⟨⟨_, S.one_mem⟩⟩
@[simp, to_additive] lemma coe_mul (x y : S) : (↑(x * y) : M) = ↑x * ↑y := rfl
@[simp, to_additive] lemma coe_one : ((1 : S) : M) = 1 := rfl
attribute [norm_cast] coe_mul coe_one
attribute [norm_cast] add_submonoid.coe_add add_submonoid.coe_zero
/-- A submonoid of a monoid inherits a monoid structure. -/
@[to_additive "An `add_submonoid` of an `add_monoid` inherits an `add_monoid`
structure."]
instance to_monoid {M : Type*} [monoid M] (S : submonoid M) : monoid S :=
S.coe_injective.monoid coe rfl (λ _ _, rfl)
/-- A submonoid of a `comm_monoid` is a `comm_monoid`. -/
@[to_additive "An `add_submonoid` of an `add_comm_monoid` is
an `add_comm_monoid`."]
instance to_comm_monoid {M} [comm_monoid M] (S : submonoid M) : comm_monoid S :=
S.coe_injective.comm_monoid coe rfl (λ _ _, rfl)
/-- The natural monoid hom from a submonoid of monoid `M` to `M`. -/
@[to_additive "The natural monoid hom from an `add_submonoid` of `add_monoid` `M` to `M`."]
def subtype : S →* M := ⟨coe, rfl, λ _ _, rfl⟩
@[simp, to_additive] theorem coe_subtype : ⇑S.subtype = coe := rfl
/-- An induction principle on elements of the type `submonoid.closure s`.
If `p` holds for `1` and all elements of `s`, and is preserved under multiplication, then `p`
holds for all elements of the closure of `s`.
The difference with `submonoid.closure_induction` is that this acts on the subtype.
-/
@[to_additive "An induction principle on elements of the type `add_submonoid.closure s`.
If `p` holds for `0` and all elements of `s`, and is preserved under addition, then `p`
holds for all elements of the closure of `s`.
The difference with `add_submonoid.closure_induction` is that this acts on the subtype."]
lemma closure_induction' (s : set M) {p : closure s → Prop}
(Hs : ∀ x (h : x ∈ s), p ⟨x, subset_closure h⟩)
(H1 : p 1)
(Hmul : ∀ x y, p x → p y → p (x * y))
(x : closure s) :
p x :=
subtype.rec_on x $ λ x hx, begin
refine exists.elim _ (λ (hx : x ∈ closure s) (hc : p ⟨x, hx⟩), hc),
exact closure_induction hx
(λ x hx, ⟨subset_closure hx, Hs x hx⟩)
⟨one_mem _, H1⟩
(λ x y hx hy, exists.elim hx $ λ hx' hx, exists.elim hy $ λ hy' hy,
⟨mul_mem _ hx' hy', Hmul _ _ hx hy⟩),
end
attribute [elab_as_eliminator] submonoid.closure_induction' add_submonoid.closure_induction'
/-- Given `submonoid`s `s`, `t` of monoids `M`, `N` respectively, `s × t` as a submonoid
of `M × N`. -/
@[to_additive prod "Given `add_submonoid`s `s`, `t` of `add_monoid`s `A`, `B` respectively, `s × t`
as an `add_submonoid` of `A × B`."]
def prod (s : submonoid M) (t : submonoid N) : submonoid (M × N) :=
{ carrier := (s : set M).prod t,
one_mem' := ⟨s.one_mem, t.one_mem⟩,
mul_mem' := λ p q hp hq, ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ }
@[to_additive coe_prod]
lemma coe_prod (s : submonoid M) (t : submonoid N) :
(s.prod t : set (M × N)) = (s : set M).prod (t : set N) :=
rfl
@[to_additive mem_prod]
lemma mem_prod {s : submonoid M} {t : submonoid N} {p : M × N} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl
@[to_additive prod_mono]
lemma prod_mono {s₁ s₂ : submonoid M} {t₁ t₂ : submonoid N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) :
s₁.prod t₁ ≤ s₂.prod t₂ :=
set.prod_mono hs ht
@[to_additive prod_top]
lemma prod_top (s : submonoid M) :
s.prod (⊤ : submonoid N) = s.comap (monoid_hom.fst M N) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_fst]
@[to_additive top_prod]
lemma top_prod (s : submonoid N) :
(⊤ : submonoid M).prod s = s.comap (monoid_hom.snd M N) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_snd]
@[simp, to_additive top_prod_top]
lemma top_prod_top : (⊤ : submonoid M).prod (⊤ : submonoid N) = ⊤ :=
(top_prod _).trans $ comap_top _
@[to_additive] lemma bot_prod_bot : (⊥ : submonoid M).prod (⊥ : submonoid N) = ⊥ :=
ext' $ by simp [coe_prod, prod.one_eq_mk]
/-- The product of submonoids is isomorphic to their product as monoids. -/
@[to_additive prod_equiv "The product of additive submonoids is isomorphic to their product
as additive monoids"]
def prod_equiv (s : submonoid M) (t : submonoid N) : s.prod t ≃* s × t :=
{ map_mul' := λ x y, rfl, .. equiv.set.prod ↑s ↑t }
open monoid_hom
@[to_additive]
lemma map_inl (s : submonoid M) : s.map (inl M N) = s.prod ⊥ :=
ext $ λ p, ⟨λ ⟨x, hx, hp⟩, hp ▸ ⟨hx, set.mem_singleton 1⟩,
λ ⟨hps, hp1⟩, ⟨p.1, hps, prod.ext rfl $ (set.eq_of_mem_singleton hp1).symm⟩⟩
@[to_additive]
lemma map_inr (s : submonoid N) : s.map (inr M N) = prod ⊥ s :=
ext $ λ p, ⟨λ ⟨x, hx, hp⟩, hp ▸ ⟨set.mem_singleton 1, hx⟩,
λ ⟨hp1, hps⟩, ⟨p.2, hps, prod.ext (set.eq_of_mem_singleton hp1).symm rfl⟩⟩
@[simp, to_additive prod_bot_sup_bot_prod]
lemma prod_bot_sup_bot_prod (s : submonoid M) (t : submonoid N) :
(s.prod ⊥) ⊔ (prod ⊥ t) = s.prod t :=
le_antisymm (sup_le (prod_mono (le_refl s) bot_le) (prod_mono bot_le (le_refl t))) $
assume p hp, prod.fst_mul_snd p ▸ mul_mem _
((le_sup_left : s.prod ⊥ ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨hp.1, set.mem_singleton 1⟩)
((le_sup_right : prod ⊥ t ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨set.mem_singleton 1, hp.2⟩)
end submonoid
namespace monoid_hom
open submonoid
/-- The range of a monoid homomorphism is a submonoid. -/
@[to_additive "The range of an `add_monoid_hom` is an `add_submonoid`."]
def mrange (f : M →* N) : submonoid N := (⊤ : submonoid M).map f
@[simp, to_additive] lemma coe_mrange (f : M →* N) :
(f.mrange : set N) = set.range f :=
set.image_univ
@[simp, to_additive] lemma mem_mrange {f : M →* N} {y : N} :
y ∈ f.mrange ↔ ∃ x, f x = y :=
by simp [mrange]
@[to_additive]
lemma map_mrange (g : N →* P) (f : M →* N) : f.mrange.map g = (g.comp f).mrange :=
(⊤ : submonoid M).map_map g f
@[to_additive]
lemma mrange_top_iff_surjective {N} [monoid N] {f : M →* N} :
f.mrange = (⊤ : submonoid N) ↔ function.surjective f :=
submonoid.ext'_iff.trans $ iff.trans (by rw [coe_mrange, coe_top]) set.range_iff_surjective
/-- The range of a surjective monoid hom is the whole of the codomain. -/
@[to_additive "The range of a surjective `add_monoid` hom is the whole of the codomain."]
lemma mrange_top_of_surjective {N} [monoid N] (f : M →* N) (hf : function.surjective f) :
f.mrange = (⊤ : submonoid N) :=
mrange_top_iff_surjective.2 hf
@[to_additive]
lemma mrange_eq_map (f : M →* N) : f.mrange = map f ⊤ := rfl
@[to_additive]
lemma mclosure_preimage_le (f : M →* N) (s : set N) :
closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 $ λ x hx, mem_coe.2 $ mem_comap.2 $ subset_closure hx
/-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated
by the image of the set. -/
@[to_additive "The image under an `add_monoid` hom of the `add_submonoid` generated by a set equals
the `add_submonoid` generated by the image of the set."]
lemma map_mclosure (f : M →* N) (s : set M) :
(closure s).map f = closure (f '' s) :=
le_antisymm
(map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _)
(mclosure_preimage_le _ _))
(closure_le.2 $ set.image_subset _ subset_closure)
/-- Restriction of a monoid hom to a submonoid of the domain. -/
@[to_additive "Restriction of an add_monoid hom to an `add_submonoid` of the domain."]
def mrestrict {N : Type*} [monoid N] (f : M →* N) (S : submonoid M) : S →* N := f.comp S.subtype
@[simp, to_additive]
lemma mrestrict_apply {N : Type*} [monoid N] (f : M →* N) (x : S) : f.mrestrict S x = f x := rfl
/-- Restriction of a monoid hom to a submonoid of the codomain. -/
@[to_additive "Restriction of an `add_monoid` hom to an `add_submonoid` of the codomain."]
def cod_mrestrict (f : M →* N) (S : submonoid N) (h : ∀ x, f x ∈ S) : M →* S :=
{ to_fun := λ n, ⟨f n, h n⟩,
map_one' := subtype.eq f.map_one,
map_mul' := λ x y, subtype.eq (f.map_mul x y) }
/-- Restriction of a monoid hom to its range interpreted as a submonoid. -/
@[to_additive "Restriction of an `add_monoid` hom to its range interpreted as a submonoid."]
def mrange_restrict {N} [monoid N] (f : M →* N) : M →* f.mrange :=
f.cod_mrestrict f.mrange $ λ x, ⟨x, submonoid.mem_top x, rfl⟩
@[simp, to_additive]
lemma coe_mrange_restrict {N} [monoid N] (f : M →* N) (x : M) :
(f.mrange_restrict x : N) = f x :=
rfl
end monoid_hom
namespace submonoid
open monoid_hom
@[to_additive]
lemma mrange_inl : (inl M N).mrange = prod ⊤ ⊥ := map_inl ⊤
@[to_additive]
lemma mrange_inr : (inr M N).mrange = prod ⊥ ⊤ := map_inr ⊤
@[to_additive]
lemma mrange_inl' : (inl M N).mrange = comap (snd M N) ⊥ := mrange_inl.trans (top_prod _)
@[to_additive]
lemma mrange_inr' : (inr M N).mrange = comap (fst M N) ⊥ := mrange_inr.trans (prod_top _)
@[simp, to_additive]
lemma mrange_fst : (fst M N).mrange = ⊤ :=
(fst M N).mrange_top_of_surjective $ @prod.fst_surjective _ _ ⟨1⟩
@[simp, to_additive]
lemma mrange_snd : (snd M N).mrange = ⊤ :=
(snd M N).mrange_top_of_surjective $ @prod.snd_surjective _ _ ⟨1⟩
@[simp, to_additive]
lemma mrange_inl_sup_mrange_inr : (inl M N).mrange ⊔ (inr M N).mrange = ⊤ :=
by simp only [mrange_inl, mrange_inr, prod_bot_sup_bot_prod, top_prod_top]
/-- The monoid hom associated to an inclusion of submonoids. -/
@[to_additive "The `add_monoid` hom associated to an inclusion of submonoids."]
def inclusion {S T : submonoid M} (h : S ≤ T) : S →* T :=
S.subtype.cod_mrestrict _ (λ x, h x.2)
@[simp, to_additive]
lemma range_subtype (s : submonoid M) : s.subtype.mrange = s :=
ext' $ (coe_mrange _).trans $ subtype.range_coe
@[to_additive] lemma eq_bot_iff_forall : S = ⊥ ↔ ∀ x ∈ S, x = (1 : M) :=
begin
split,
{ intros h x x_in,
rwa [h, mem_bot] at x_in },
{ intros h,
ext x,
rw mem_bot,
exact ⟨h x, by { rintros rfl, exact S.one_mem }⟩ },
end
@[to_additive] lemma nontrivial_iff_exists_ne_one (S : submonoid M) : nontrivial S ↔ ∃ x ∈ S, x ≠ (1:M) :=
begin
split,
{ introI h,
rcases exists_ne (1 : S) with ⟨⟨h, h_in⟩, h_ne⟩,
use [h, h_in],
intro hyp,
apply h_ne,
simpa [hyp] },
{ rintros ⟨x, x_in, hx⟩,
apply nontrivial_of_ne (⟨x, x_in⟩ : S) 1,
intro hyp,
apply hx,
simpa [has_one.one] using hyp },
end
/-- A submonoid is either the trivial submonoid or nontrivial. -/
@[to_additive] lemma bot_or_nontrivial (S : submonoid M) : S = ⊥ ∨ nontrivial S :=
begin
classical,
by_cases h : ∀ x ∈ S, x = (1 : M),
{ left,
exact S.eq_bot_iff_forall.mpr h },
{ right,
push_neg at h,
simpa [nontrivial_iff_exists_ne_one] using h },
end
/-- A submonoid is either the trivial submonoid or contains a nonzero element. -/
@[to_additive] lemma bot_or_exists_ne_one (S : submonoid M) : S = ⊥ ∨ ∃ x ∈ S, x ≠ (1:M) :=
begin
convert S.bot_or_nontrivial,
rw nontrivial_iff_exists_ne_one
end
end submonoid
namespace mul_equiv
variables {S} {T : submonoid M}
/-- Makes the identity isomorphism from a proof that two submonoids of a multiplicative
monoid are equal. -/
@[to_additive "Makes the identity additive isomorphism from a proof two
submonoids of an additive monoid are equal."]
def submonoid_congr (h : S = T) : S ≃* T :=
{ map_mul' := λ _ _, rfl, ..equiv.set_congr $ submonoid.ext'_iff.1 h }
end mul_equiv
|
3a9365214d5f505e2dcefe666ee64c542ddb2aa5 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/number_theory/pell.lean | 7214d5c01ef52639a779c4a5c250dbb2682f83de | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 37,144 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.nat.modeq
import data.zsqrtd.basic
import tactic.omega
namespace pell
open nat
section
parameters {a : ℕ} (a1 : 1 < a)
include a1
private def d := a*a - 1
@[simp] theorem d_pos : 0 < d :=
nat.sub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) dec_trivial dec_trivial : 1*1<a*a)
/-- The Pell sequences, defined together in mutual recursion. -/
-- TODO(lint): Fix double namespace issue
@[nolint dup_namespace] def pell : ℕ → ℕ × ℕ :=
λn, nat.rec_on n (1, 0) (λn xy, (xy.1*a + d*xy.2, xy.1 + xy.2*a))
/-- The Pell `x` sequence. -/
def xn (n : ℕ) : ℕ := (pell n).1
/-- The Pell `y` sequence. -/
def yn (n : ℕ) : ℕ := (pell n).2
@[simp] theorem pell_val (n : ℕ) : pell n = (xn n, yn n) :=
show pell n = ((pell n).1, (pell n).2), from match pell n with (a, b) := rfl end
@[simp] theorem xn_zero : xn 0 = 1 := rfl
@[simp] theorem yn_zero : yn 0 = 0 := rfl
@[simp] theorem xn_succ (n : ℕ) : xn (n+1) = xn n * a + d * yn n := rfl
@[simp] theorem yn_succ (n : ℕ) : yn (n+1) = xn n + yn n * a := rfl
@[simp] theorem xn_one : xn 1 = a := by simp
@[simp] theorem yn_one : yn 1 = 1 := by simp
def xz (n : ℕ) : ℤ := xn n
def yz (n : ℕ) : ℤ := yn n
def az : ℤ := a
theorem asq_pos : 0 < a*a :=
le_trans (le_of_lt a1) (by have := @nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa mul_one at this)
theorem dz_val : ↑d = az*az - 1 :=
have 1 ≤ a*a, from asq_pos,
show ↑(a*a - 1) = _, by rw int.coe_nat_sub this; refl
@[simp] theorem xz_succ (n : ℕ) : xz (n+1) = xz n * az + ↑d * yz n := rfl
@[simp] theorem yz_succ (n : ℕ) : yz (n+1) = xz n + yz n * az := rfl
/-- The Pell sequence can also be viewed as an element of `ℤ√d` -/
def pell_zd (n : ℕ) : ℤ√d := ⟨xn n, yn n⟩
@[simp] theorem pell_zd_re (n : ℕ) : (pell_zd n).re = xn n := rfl
@[simp] theorem pell_zd_im (n : ℕ) : (pell_zd n).im = yn n := rfl
/-- The property of being a solution to the Pell equation, expressed
as a property of elements of `ℤ√d`. -/
def is_pell : ℤ√d → Prop | ⟨x, y⟩ := x*x - d*y*y = 1
theorem is_pell_nat {x y : ℕ} : is_pell ⟨x, y⟩ ↔ x*x - d*y*y = 1 :=
⟨λh, int.coe_nat_inj (by rw int.coe_nat_sub (int.le_of_coe_nat_le_coe_nat $ int.le.intro_sub h); exact h),
λh, show ((x*x : ℕ) - (d*y*y:ℕ) : ℤ) = 1, by rw [← int.coe_nat_sub $ le_of_lt $ nat.lt_of_sub_eq_succ h, h]; refl⟩
theorem is_pell_norm : Π {b : ℤ√d}, is_pell b ↔ b * b.conj = 1
| ⟨x, y⟩ := by simp [zsqrtd.ext, is_pell, mul_comm]; ring
theorem is_pell_mul {b c : ℤ√d} (hb : is_pell b) (hc : is_pell c) : is_pell (b * c) :=
is_pell_norm.2 (by simp [mul_comm, mul_left_comm,
zsqrtd.conj_mul, pell.is_pell_norm.1 hb, pell.is_pell_norm.1 hc])
theorem is_pell_conj : ∀ {b : ℤ√d}, is_pell b ↔ is_pell b.conj | ⟨x, y⟩ :=
by simp [is_pell, zsqrtd.conj]
@[simp] theorem pell_zd_succ (n : ℕ) : pell_zd (n+1) = pell_zd n * ⟨a, 1⟩ :=
by simp [zsqrtd.ext]
theorem is_pell_one : is_pell ⟨a, 1⟩ :=
show az*az-d*1*1=1, by simp [dz_val]; ring
theorem is_pell_pell_zd : ∀ (n : ℕ), is_pell (pell_zd n)
| 0 := rfl
| (n+1) := let o := is_pell_one in by simp; exact pell.is_pell_mul (is_pell_pell_zd n) o
@[simp] theorem pell_eqz (n : ℕ) : xz n * xz n - d * yz n * yz n = 1 := is_pell_pell_zd n
@[simp] theorem pell_eq (n : ℕ) : xn n * xn n - d * yn n * yn n = 1 :=
let pn := pell_eqz n in
have h : (↑(xn n * xn n) : ℤ) - ↑(d * yn n * yn n) = 1,
by repeat {rw int.coe_nat_mul}; exact pn,
have hl : d * yn n * yn n ≤ xn n * xn n, from
int.le_of_coe_nat_le_coe_nat $ int.le.intro $ add_eq_of_eq_sub' $ eq.symm h,
int.coe_nat_inj (by rw int.coe_nat_sub hl; exact h)
instance dnsq : zsqrtd.nonsquare d := ⟨λn h,
have n*n + 1 = a*a, by rw ← h; exact nat.succ_pred_eq_of_pos (asq_pos a1),
have na : n < a, from nat.mul_self_lt_mul_self_iff.2 (by rw ← this; exact nat.lt_succ_self _),
have (n+1)*(n+1) ≤ n*n + 1, by rw this; exact nat.mul_self_le_mul_self na,
have n+n ≤ 0, from @nat.le_of_add_le_add_right (n*n + 1) _ _ (by ring at this ⊢; assumption),
ne_of_gt d_pos $ by rw nat.eq_zero_of_le_zero (le_trans (nat.le_add_left _ _) this) at h; exact h⟩
theorem xn_ge_a_pow : ∀ (n : ℕ), a^n ≤ xn n
| 0 := le_refl 1
| (n+1) := by simp [nat.pow_succ]; exact le_trans
(nat.mul_le_mul_right _ (xn_ge_a_pow n)) (nat.le_add_right _ _)
theorem n_lt_a_pow : ∀ (n : ℕ), n < a^n
| 0 := nat.le_refl 1
| (n+1) := begin have IH := n_lt_a_pow n,
have : a^n + a^n ≤ a^n * a,
{ rw ← mul_two, exact nat.mul_le_mul_left _ a1 },
simp [nat.pow_succ], refine lt_of_lt_of_le _ this,
exact add_lt_add_of_lt_of_le IH (lt_of_le_of_lt (nat.zero_le _) IH)
end
theorem n_lt_xn (n) : n < xn n :=
lt_of_lt_of_le (n_lt_a_pow n) (xn_ge_a_pow n)
theorem x_pos (n) : 0 < xn n :=
lt_of_le_of_lt (nat.zero_le n) (n_lt_xn n)
lemma eq_pell_lem : ∀n (b:ℤ√d), 1 ≤ b → is_pell b → b ≤ pell_zd n → ∃n, b = pell_zd n
| 0 b := λh1 hp hl, ⟨0, @zsqrtd.le_antisymm _ dnsq _ _ hl h1⟩
| (n+1) b := λh1 hp h,
have a1p : (0:ℤ√d) ≤ ⟨a, 1⟩, from trivial,
have am1p : (0:ℤ√d) ≤ ⟨a, -1⟩, from show (_:nat) ≤ _, by simp; exact nat.pred_le _,
have a1m : (⟨a, 1⟩ * ⟨a, -1⟩ : ℤ√d) = 1, from is_pell_norm.1 is_pell_one,
if ha : (⟨↑a, 1⟩ : ℤ√d) ≤ b then
let ⟨m, e⟩ := eq_pell_lem n (b * ⟨a, -1⟩)
(by rw ← a1m; exact mul_le_mul_of_nonneg_right ha am1p)
(is_pell_mul hp (is_pell_conj.1 is_pell_one))
(by have t := mul_le_mul_of_nonneg_right h am1p; rwa [pell_zd_succ, mul_assoc, a1m, mul_one] at t) in
⟨m+1, by rw [show b = b * ⟨a, -1⟩ * ⟨a, 1⟩, by rw [mul_assoc, eq.trans (mul_comm _ _) a1m]; simp, pell_zd_succ, e]⟩
else
suffices ¬1 < b, from ⟨0, show b = 1, from (or.resolve_left (lt_or_eq_of_le h1) this).symm⟩, λh1l,
by cases b with x y; exact
have bm : (_*⟨_,_⟩ :ℤ√(d a1)) = 1, from pell.is_pell_norm.1 hp,
have y0l : (0:ℤ√(d a1)) < ⟨x - x, y - -y⟩, from sub_lt_sub h1l $ λ(hn : (1:ℤ√(d a1)) ≤ ⟨x, -y⟩),
by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1); rw [bm, mul_one] at t; exact h1l t,
have yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩, from
show (⟨x, y⟩ - ⟨x, -y⟩ : ℤ√(d a1)) < ⟨a, 1⟩ - ⟨a, -1⟩, from
sub_lt_sub (by exact ha) $ λ(hn : (⟨x, -y⟩ : ℤ√(d a1)) ≤ ⟨a, -1⟩),
by have t := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p;
rw [bm, one_mul, mul_assoc, eq.trans (mul_comm _ _) a1m, mul_one] at t; exact ha t,
by simp at y0l; simp at yl2; exact
match y, y0l, (yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩) with
| 0, y0l, yl2 := y0l (le_refl 0)
| (y+1 : ℕ), y0l, yl2 := yl2 (zsqrtd.le_of_le_le (le_refl 0)
(let t := int.coe_nat_le_coe_nat_of_le (nat.succ_pos y) in add_le_add t t))
| -[1+y], y0l, yl2 := y0l trivial
end
theorem eq_pell_zd (b : ℤ√d) (b1 : 1 ≤ b) (hp : is_pell b) : ∃n, b = pell_zd n :=
let ⟨n, h⟩ := @zsqrtd.le_arch d b in
eq_pell_lem n b b1 hp $ zsqrtd.le_trans h $ by rw zsqrtd.coe_nat_val; exact
zsqrtd.le_of_le_le
(int.coe_nat_le_coe_nat_of_le $ le_of_lt $ n_lt_xn _ _) (int.coe_zero_le _)
theorem eq_pell {x y : ℕ} (hp : x*x - d*y*y = 1) : ∃n, x = xn n ∧ y = yn n :=
have (1:ℤ√d) ≤ ⟨x, y⟩, from match x, hp with
| 0, (hp : 0 - _ = 1) := by rw nat.zero_sub at hp; contradiction
| (x+1), hp := zsqrtd.le_of_le_le (int.coe_nat_le_coe_nat_of_le $ nat.succ_pos x) (int.coe_zero_le _)
end,
let ⟨m, e⟩ := eq_pell_zd ⟨x, y⟩ this (is_pell_nat.2 hp) in
⟨m, match x, y, e with ._, ._, rfl := ⟨rfl, rfl⟩ end⟩
theorem pell_zd_add (m) : ∀ n, pell_zd (m + n) = pell_zd m * pell_zd n
| 0 := (mul_one _).symm
| (n+1) := by rw[← add_assoc, pell_zd_succ, pell_zd_succ, pell_zd_add n, ← mul_assoc]
theorem xn_add (m n) : xn (m + n) = xn m * xn n + d * yn m * yn n :=
by injection (pell_zd_add _ m n) with h _;
repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem yn_add (m n) : yn (m + n) = xn m * yn n + yn m * xn n :=
by injection (pell_zd_add _ m n) with _ h;
repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem pell_zd_sub {m n} (h : n ≤ m) : pell_zd (m - n) = pell_zd m * (pell_zd n).conj :=
let t := pell_zd_add n (m - n) in
by rw [nat.add_sub_of_le h] at t;
rw [t, mul_comm (pell_zd _ n) _, mul_assoc, (is_pell_norm _).1 (is_pell_pell_zd _ _), mul_one]
theorem xz_sub {m n} (h : n ≤ m) : xz (m - n) = xz m * xz n - d * yz m * yz n :=
by injection (pell_zd_sub _ h) with h _; repeat {rw ← neg_mul_eq_mul_neg at h}; exact h
theorem yz_sub {m n} (h : n ≤ m) : yz (m - n) = xz n * yz m - xz m * yz n :=
by injection (pell_zd_sub a1 h) with _ h; repeat {rw ← neg_mul_eq_mul_neg at h}; rw [add_comm, mul_comm] at h; exact h
theorem xy_coprime (n) : (xn n).coprime (yn n) :=
nat.coprime_of_dvd' $ λk kx ky,
let p := pell_eq n in by rw ← p; exact
nat.dvd_sub (le_of_lt $ nat.lt_of_sub_eq_succ p)
(dvd_mul_of_dvd_right kx _) (dvd_mul_of_dvd_right ky _)
theorem y_increasing {m} : Π {n}, m < n → yn m < yn n
| 0 h := absurd h $ nat.not_lt_zero _
| (n+1) h :=
have yn m ≤ yn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(λhl, le_of_lt $ y_increasing hl) (λe, by rw e),
by simp; refine lt_of_le_of_lt _ (nat.lt_add_of_pos_left $ x_pos a1 n);
rw ← mul_one (yn a1 m);
exact mul_le_mul this (le_of_lt a1) (nat.zero_le _) (nat.zero_le _)
theorem x_increasing {m} : Π {n}, m < n → xn m < xn n
| 0 h := absurd h $ nat.not_lt_zero _
| (n+1) h :=
have xn m ≤ xn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(λhl, le_of_lt $ x_increasing hl) (λe, by rw e),
by simp; refine lt_of_lt_of_le (lt_of_le_of_lt this _) (nat.le_add_right _ _);
have t := nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n); rwa mul_one at t
theorem yn_ge_n : Π n, n ≤ yn n
| 0 := nat.zero_le _
| (n+1) := show n < yn (n+1), from lt_of_le_of_lt (yn_ge_n n) (y_increasing $ nat.lt_succ_self n)
theorem y_mul_dvd (n) : ∀k, yn n ∣ yn (n * k)
| 0 := dvd_zero _
| (k+1) := by rw [nat.mul_succ, yn_add]; exact
dvd_add (dvd_mul_left _ _) (dvd_mul_of_dvd_left (y_mul_dvd k) _)
theorem y_dvd_iff (m n) : yn m ∣ yn n ↔ m ∣ n :=
⟨λh, nat.dvd_of_mod_eq_zero $ (nat.eq_zero_or_pos _).resolve_right $ λhp,
have co : nat.coprime (yn m) (xn (m * (n / m))), from nat.coprime.symm $
(xy_coprime _).coprime_dvd_right (y_mul_dvd m (n / m)),
have m0 : 0 < m, from m.eq_zero_or_pos.resolve_left $
λe, by rw [e, nat.mod_zero] at hp; rw [e] at h; exact
have 0 < yn a1 n, from y_increasing _ hp,
ne_of_lt (y_increasing a1 hp) (eq_zero_of_zero_dvd h).symm,
by rw [← nat.mod_add_div n m, yn_add] at h; exact
not_le_of_gt (y_increasing _ $ nat.mod_lt n m0)
(nat.le_of_dvd (y_increasing _ hp) $ co.dvd_of_dvd_mul_right $
(nat.dvd_add_iff_right $ dvd_mul_of_dvd_right (y_mul_dvd _ _ _) _).2 h),
λ⟨k, e⟩, by rw e; apply y_mul_dvd⟩
theorem xy_modeq_yn (n) :
∀k, xn (n * k) ≡ (xn n)^k [MOD (yn n)^2]
∧ yn (n * k) ≡ k * (xn n)^(k-1) * yn n [MOD (yn n)^3]
| 0 := by constructor; simp
| (k+1) :=
let ⟨hx, hy⟩ := xy_modeq_yn k in
have L : xn (n * k) * xn n + d * yn (n * k) * yn n ≡ xn n^k * xn n + 0 [MOD yn n^2], from
modeq.modeq_add (modeq.modeq_mul_right _ hx) $ modeq.modeq_zero_iff.2 $
by rw nat.pow_succ; exact
mul_dvd_mul_right (dvd_mul_of_dvd_right (modeq.modeq_zero_iff.1 $
(hy.modeq_of_dvd_of_modeq $ by simp [nat.pow_succ]).trans $ modeq.modeq_zero_iff.2 $
by simp [-mul_comm, -mul_assoc]) _) _,
have R : xn (n * k) * yn n + yn (n * k) * xn n ≡
xn n^k * yn n + k * xn n^k * yn n [MOD yn n^3], from
modeq.modeq_add (by rw nat.pow_succ; exact modeq.modeq_mul_right' _ hx) $
have k * xn n^(k - 1) * yn n * xn n = k * xn n^k * yn n,
by clear _let_match; cases k with k; simp [nat.pow_succ, mul_comm, mul_left_comm],
by rw ← this; exact modeq.modeq_mul_right _ hy,
by rw [nat.add_sub_cancel, nat.mul_succ, xn_add, yn_add, nat.pow_succ (xn _ n),
nat.succ_mul, add_comm (k * xn _ n^k) (xn _ n^k), right_distrib];
exact ⟨L, R⟩
theorem ysq_dvd_yy (n) : yn n * yn n ∣ yn (n * yn n) :=
modeq.modeq_zero_iff.1 $
((xy_modeq_yn n (yn n)).right.modeq_of_dvd_of_modeq $ by simp [nat.pow_succ]).trans
(modeq.modeq_zero_iff.2 $ by simp [mul_dvd_mul_left, mul_assoc])
theorem dvd_of_ysq_dvd {n t} (h : yn n * yn n ∣ yn t) : yn n ∣ t :=
have nt : n ∣ t, from (y_dvd_iff n t).1 $ dvd_of_mul_left_dvd h,
n.eq_zero_or_pos.elim (λn0, by rw n0; rw n0 at nt; exact nt) $ λ(n0l : 0 < n),
let ⟨k, ke⟩ := nt in
have yn n ∣ k * (xn n)^(k-1), from
nat.dvd_of_mul_dvd_mul_right (y_increasing n0l) $ modeq.modeq_zero_iff.1 $
by have xm := (xy_modeq_yn a1 n k).right; rw ← ke at xm; exact
(xm.modeq_of_dvd_of_modeq $ by simp [nat.pow_succ]).symm.trans
(modeq.modeq_zero_iff.2 h),
by rw ke; exact dvd_mul_of_dvd_right
(((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _
theorem pell_zd_succ_succ (n) : pell_zd (n + 2) + pell_zd n = (2 * a : ℕ) * pell_zd (n + 1) :=
have (1:ℤ√d) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a),
by { rw zsqrtd.coe_nat_val, change (⟨_,_⟩:ℤ√(d a1))=⟨_,_⟩,
rw dz_val, change az a1 with a, rw zsqrtd.ext, dsimp, split; ring },
by simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (* pell_zd a1 n) this
theorem xy_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) ∧
yn (n + 2) + yn n = (2 * a) * yn (n + 1) := begin
have := pell_zd_succ_succ a1 n, unfold pell_zd at this,
rw [← int.cast_coe_nat, zsqrtd.smul_val] at this,
injection this with h₁ h₂,
split; apply int.coe_nat_inj; [simpa using h₁, simpa using h₂]
end
theorem xn_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) := (xy_succ_succ n).1
theorem yn_succ_succ (n) : yn (n + 2) + yn n = (2 * a) * yn (n + 1) := (xy_succ_succ n).2
theorem xz_succ_succ (n) : xz (n + 2) = (2 * a : ℕ) * xz (n + 1) - xz n :=
eq_sub_of_add_eq $ by delta xz; rw [← int.coe_nat_add, ← int.coe_nat_mul, xn_succ_succ]
theorem yz_succ_succ (n) : yz (n + 2) = (2 * a : ℕ) * yz (n + 1) - yz n :=
eq_sub_of_add_eq $ by delta yz; rw [← int.coe_nat_add, ← int.coe_nat_mul, yn_succ_succ]
theorem yn_modeq_a_sub_one : ∀ n, yn n ≡ n [MOD a-1]
| 0 := by simp
| 1 := by simp
| (n+2) := modeq.modeq_add_cancel_right (yn_modeq_a_sub_one n) $
have 2*(n+1) = n+2+n, by ring,
by rw [yn_succ_succ, ← this];
refine modeq.modeq_mul (modeq.modeq_mul_left 2 (_ : a ≡ 1 [MOD a-1])) (yn_modeq_a_sub_one (n+1));
exact (modeq.modeq_of_dvd $ by rw [int.coe_nat_sub $ le_of_lt a1]; apply dvd_refl).symm
theorem yn_modeq_two : ∀ n, yn n ≡ n [MOD 2]
| 0 := by simp
| 1 := by simp
| (n+2) := modeq.modeq_add_cancel_right (yn_modeq_two n) $
have 2*(n+1) = n+2+n, by ring,
by rw [yn_succ_succ, ← this];
refine modeq.modeq_mul _ (yn_modeq_two (n+1));
exact modeq.trans
(modeq.modeq_zero_iff.2 $ by simp)
(modeq.modeq_zero_iff.2 $ by simp).symm
lemma x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) :
(a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) =
y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring
theorem x_sub_y_dvd_pow (y : ℕ) :
∀ n, (2*a*y - y*y - 1 : ℤ) ∣ yz n * (a - y) + ↑(y^n) - xz n
| 0 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| 1 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| (n+2) :=
have (2*a*y - y*y - 1 : ℤ) ∣ ↑(y^(n + 2)) - ↑(2 * a) * ↑(y^(n + 1)) + ↑(y^n), from
⟨-↑(y^n), by simp [nat.pow_succ, mul_add, int.coe_nat_mul,
show ((2:ℕ):ℤ) = 2, from rfl, mul_comm, mul_left_comm]; ring ⟩,
by rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem a1 ↑(y^(n+2)) ↑(y^(n+1)) ↑(y^n)]; exact
dvd_sub (dvd_add this $ dvd_mul_of_dvd_right (x_sub_y_dvd_pow (n+1)) _) (x_sub_y_dvd_pow n)
theorem xn_modeq_x2n_add_lem (n j) : xn n ∣ d * yn n * (yn n * xn j) + xn j :=
have h1 : d * yn n * (yn n * xn j) + xn j = (d * yn n * yn n + 1) * xn j,
by simp [add_mul, mul_assoc],
have h2 : d * yn n * yn n + 1 = xn n * xn n, by apply int.coe_nat_inj;
repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul}; exact
add_eq_of_eq_sub' (eq.symm $ pell_eqz _ _),
by rw h2 at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _
theorem xn_modeq_x2n_add (n j) : xn (2 * n + j) + xn j ≡ 0 [MOD xn n] :=
by rw [two_mul, add_assoc, xn_add, add_assoc]; exact
show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_right (xn a1 n) (xn a1 (n + j))) $
by rw [yn_add, left_distrib, add_assoc]; exact
show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_of_dvd_right (dvd_mul_right _ _) _) $
modeq.modeq_zero_iff.2 $ xn_modeq_x2n_add_lem _ _ _
lemma xn_modeq_x2n_sub_lem {n j} (h : j ≤ n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] :=
have h1 : xz n ∣ ↑d * yz n * yz (n - j) + xz j, by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub]; exact
dvd_sub
(by delta xz; delta yz;
repeat {rw ← int.coe_nat_add <|> rw ← int.coe_nat_mul}; rw mul_comm (xn a1 j) (yn a1 n);
exact int.coe_nat_dvd.2 (xn_modeq_x2n_add_lem _ _ _))
(dvd_mul_of_dvd_right (dvd_mul_right _ _) _),
by rw [two_mul, nat.add_sub_assoc h, xn_add, add_assoc]; exact
show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_right _ _) $
modeq.modeq_zero_iff.2 $ int.coe_nat_dvd.1 $ by simpa [xz, yz] using h1
theorem xn_modeq_x2n_sub {n j} (h : j ≤ 2 * n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] :=
(le_total j n).elim xn_modeq_x2n_sub_lem
(λjn, have 2 * n - j + j ≤ n + j, by rw [nat.sub_add_cancel h, two_mul]; exact nat.add_le_add_left jn _,
let t := xn_modeq_x2n_sub_lem (nat.le_of_add_le_add_right this) in by rwa [nat.sub_sub_self h, add_comm] at t)
theorem xn_modeq_x4n_add (n j) : xn (4 * n + j) ≡ xn j [MOD xn n] :=
modeq.modeq_add_cancel_right (modeq.refl $ xn (2 * n + j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_add _ _ _).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, add_assoc]; apply xn_modeq_x2n_add
theorem xn_modeq_x4n_sub {n j} (h : j ≤ 2 * n) : xn (4 * n - j) ≡ xn j [MOD xn n] :=
have h' : j ≤ 2*n, from le_trans h (by rw nat.succ_mul; apply nat.le_add_left),
modeq.modeq_add_cancel_right (modeq.refl $ xn (2 * n - j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_sub _ h).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, nat.add_sub_assoc h']; apply xn_modeq_x2n_add
theorem eq_of_xn_modeq_lem1 {i n} : Π {j}, i < j → j < n → xn i % xn n < xn j % xn n
| 0 ij _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij jn :=
suffices xn j % xn n < xn (j + 1) % xn n, from
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(λh, lt_trans (eq_of_xn_modeq_lem1 h (le_of_lt jn)) this)
(λh, by rw h; exact this),
by rw [nat.mod_eq_of_lt (x_increasing _ (nat.lt_of_succ_lt jn)), nat.mod_eq_of_lt (x_increasing _ jn)];
exact x_increasing _ (nat.lt_succ_self _)
theorem eq_of_xn_modeq_lem2 {n} (h : 2 * xn n = xn (n + 1)) : a = 2 ∧ n = 0 :=
by rw [xn_succ, mul_comm] at h; exact
have n = 0, from n.eq_zero_or_pos.resolve_right $ λnp,
ne_of_lt (lt_of_le_of_lt (nat.mul_le_mul_left _ a1)
(nat.lt_add_of_pos_right $ mul_pos (d_pos a1) (y_increasing a1 np))) h,
by cases this; simp at h; exact ⟨h.symm, rfl⟩
theorem eq_of_xn_modeq_lem3 {i n} (npos : 0 < n) :
Π {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → xn i % xn n < xn j % xn n
| 0 ij _ _ _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij j2n jnn ntriv :=
have lem2 : ∀k > n, k ≤ 2*n → (↑(xn k % xn n) : ℤ) = xn n - xn (2 * n - k), from λk kn k2n,
let k2nl := lt_of_add_lt_add_right $ show 2*n-k+k < n+k, by
{rw nat.sub_add_cancel, rw two_mul; exact (add_lt_add_left kn n), exact k2n } in
have xle : xn (2 * n - k) ≤ xn n, from le_of_lt $ x_increasing k2nl,
suffices xn k % xn n = xn n - xn (2 * n - k), by rw [this, int.coe_nat_sub xle],
by {
rw ← nat.mod_eq_of_lt (nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k))),
apply modeq.modeq_add_cancel_right (modeq.refl (xn a1 (2 * n - k))),
rw [nat.sub_add_cancel xle],
have t := xn_modeq_x2n_sub_lem a1 (le_of_lt k2nl),
rw nat.sub_sub_self k2n at t,
exact t.trans (modeq.modeq_zero_iff.2 $ dvd_refl _).symm },
(lt_trichotomy j n).elim
(λ (jn : j < n), eq_of_xn_modeq_lem1 ij (lt_of_le_of_ne jn jnn)) $ λo, o.elim
(λ (jn : j = n), by {
cases jn,
apply int.lt_of_coe_nat_lt_coe_nat,
rw [lem2 (n+1) (nat.lt_succ_self _) j2n,
show 2 * n - (n + 1) = n - 1, by rw[two_mul, ← nat.sub_sub, nat.add_sub_cancel]],
refine lt_sub_left_of_add_lt (int.coe_nat_lt_coe_nat_of_lt _),
cases (lt_or_eq_of_le $ nat.le_of_succ_le_succ ij) with lin ein,
{ rw nat.mod_eq_of_lt (x_increasing _ lin),
have ll : xn a1 (n-1) + xn a1 (n-1) ≤ xn a1 n,
{ rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n-1+1), by rw [nat.sub_add_cancel npos], xn_succ],
exact le_trans (nat.mul_le_mul_left _ a1) (nat.le_add_right _ _) },
have npm : (n-1).succ = n := nat.succ_pred_eq_of_pos npos,
have il : i ≤ n - 1 := by apply nat.le_of_succ_le_succ; rw npm; exact lin,
cases lt_or_eq_of_le il with ill ile,
{ exact lt_of_lt_of_le (nat.add_lt_add_left (x_increasing a1 ill) _) ll },
{ rw ile,
apply lt_of_le_of_ne ll,
rw ← two_mul,
exact λe, ntriv $
let ⟨a2, s1⟩ := @eq_of_xn_modeq_lem2 _ a1 (n-1) (by rw[nat.sub_add_cancel npos]; exact e) in
have n1 : n = 1, from le_antisymm (nat.le_of_sub_eq_zero s1) npos,
by rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩ } },
{ rw [ein, nat.mod_self, add_zero],
exact x_increasing _ (nat.pred_lt $ ne_of_gt npos) } })
(λ (jn : j > n),
have lem1 : j ≠ n → xn j % xn n < xn (j + 1) % xn n → xn i % xn n < xn (j + 1) % xn n, from λjn s,
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(λh, lt_trans (eq_of_xn_modeq_lem3 h (le_of_lt j2n) jn $ λ⟨a1, n1, i0, j2⟩,
by rw [n1, j2] at j2n; exact absurd j2n dec_trivial) s)
(λh, by rw h; exact s),
lem1 (ne_of_gt jn) $ int.lt_of_coe_nat_lt_coe_nat $ by {
rw [lem2 j jn (le_of_lt j2n), lem2 (j+1) (nat.le_succ_of_le jn) j2n],
refine sub_lt_sub_left (int.coe_nat_lt_coe_nat_of_lt $ x_increasing _ _) _,
rw [nat.sub_succ],
exact nat.pred_lt (ne_of_gt $ nat.sub_pos_of_lt j2n) })
theorem eq_of_xn_modeq_le {i j n} (npos : 0 < n) (ij : i ≤ j) (j2n : j ≤ 2 * n) (h : xn i ≡ xn j [MOD xn n])
(ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j :=
(lt_or_eq_of_le ij).resolve_left $ λij',
if jn : j = n then by {
refine ne_of_gt _ h,
rw [jn, nat.mod_self],
have x0 : 0 < xn a1 0 % xn a1 n := by rw [nat.mod_eq_of_lt (x_increasing a1 npos)]; exact dec_trivial,
cases i with i, exact x0,
rw jn at ij',
exact lt_trans x0 (eq_of_xn_modeq_lem3 _ npos (nat.succ_pos _) (le_trans ij j2n) (ne_of_lt ij') $
λ⟨a1, n1, _, i2⟩, by rw [n1, i2] at ij'; exact absurd ij' dec_trivial)
} else ne_of_lt (eq_of_xn_modeq_lem3 npos ij' j2n jn ntriv) h
theorem eq_of_xn_modeq {i j n} (npos : 0 < n) (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n) (h : xn i ≡ xn j [MOD xn n])
(ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j :=
(le_total i j).elim
(λij, eq_of_xn_modeq_le npos ij j2n h $ λ⟨a2, n1, i0, j2⟩, (ntriv a2 n1).left i0 j2)
(λij, (eq_of_xn_modeq_le npos ij i2n h.symm $ λ⟨a2, n1, j0, i2⟩, (ntriv a2 n1).right i2 j0).symm)
theorem eq_of_xn_modeq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n) (h : xn j ≡ xn i [MOD xn n]) :
j = i ∨ j + i = 4 * n :=
have i2n : i ≤ 2*n, by apply le_trans hin; rw two_mul; apply nat.le_add_left,
have npos : 0 < n, from lt_of_lt_of_le ipos hin,
(le_or_gt j (2 * n)).imp
(λj2n : j ≤ 2 * n, eq_of_xn_modeq npos j2n i2n h $
λa2 n1, ⟨λj0 i2, by rw [n1, i2] at hin; exact absurd hin dec_trivial,
λj2 i0, ne_of_gt ipos i0⟩)
(λj2n : 2 * n < j, suffices i = 4*n - j, by rw [this, nat.add_sub_of_le j4n],
have j42n : 4*n - j ≤ 2*n, from @nat.le_of_add_le_add_right j _ _ $
by rw [nat.sub_add_cancel j4n, show 4*n = 2*n + 2*n, from right_distrib 2 2 n];
exact nat.add_le_add_left (le_of_lt j2n) _,
eq_of_xn_modeq npos i2n j42n
(h.symm.trans $ let t := xn_modeq_x4n_sub j42n in by rwa [nat.sub_sub_self j4n] at t)
(λa2 n1, ⟨λi0, absurd i0 (ne_of_gt ipos), λi2, by rw[n1, i2] at hin; exact absurd hin dec_trivial⟩))
theorem modeq_of_xn_modeq {i j n} (ipos : 0 < i) (hin : i ≤ n) (h : xn j ≡ xn i [MOD xn n]) :
j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] :=
let j' := j % (4 * n) in
have n4 : 0 < 4 * n, from mul_pos dec_trivial (lt_of_lt_of_le ipos hin),
have jl : j' < 4 * n, from nat.mod_lt _ n4,
have jj : j ≡ j' [MOD 4 * n], by delta modeq; rw nat.mod_eq_of_lt jl,
have ∀j q, xn (j + 4 * n * q) ≡ xn j [MOD xn n], begin
intros j q, induction q with q IH, { simp },
rw[nat.mul_succ, ← add_assoc, add_comm],
exact modeq.trans (xn_modeq_x4n_add _ _ _) IH
end,
or.imp
(λ(ji : j' = i), by rwa ← ji)
(λ(ji : j' + i = 4 * n), (modeq.modeq_add jj (modeq.refl _)).trans $
by rw ji; exact modeq.modeq_zero_iff.2 (dvd_refl _))
(eq_of_xn_modeq' ipos hin (le_of_lt jl) $
(modeq.symm (by rw ← nat.mod_add_div j (4*n); exact this j' _)).trans h)
end
theorem xy_modeq_of_modeq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) :
∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c]
| 0 := by constructor; refl
| 1 := by simp; exact ⟨h, modeq.refl 1⟩
| (n+2) := ⟨
modeq.modeq_add_cancel_right (xy_modeq_of_modeq n).left $
by rw [xn_succ_succ a1, xn_succ_succ b1]; exact
modeq.modeq_mul (modeq.modeq_mul_left _ h) (xy_modeq_of_modeq (n+1)).left,
modeq.modeq_add_cancel_right (xy_modeq_of_modeq n).right $
by rw [yn_succ_succ a1, yn_succ_succ b1]; exact
modeq.modeq_mul (modeq.modeq_mul_left _ h) (xy_modeq_of_modeq (n+1)).right⟩
theorem matiyasevic {a k x y} : (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔
1 < a ∧ k ≤ y ∧
(x = 1 ∧ y = 0 ∨
∃ (u v s t b : ℕ),
x * x - (a * a - 1) * y * y = 1 ∧
u * u - (a * a - 1) * v * v = 1 ∧
s * s - (b * b - 1) * t * t = 1 ∧
1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧
0 < v ∧ y * y ∣ v ∧
s ≡ x [MOD u] ∧
t ≡ k [MOD 4 * y]) :=
⟨λ⟨a1, hx, hy⟩, by rw [← hx, ← hy];
refine ⟨a1, (nat.eq_zero_or_pos k).elim
(λk0, by rw k0; exact ⟨le_refl _, or.inl ⟨rfl, rfl⟩⟩) (λkpos, _)⟩; exact
let x := xn a1 k, y := yn a1 k,
m := 2 * (k * y),
u := xn a1 m, v := yn a1 m in
have ky : k ≤ y, from yn_ge_n a1 k,
have yv : y * y ∣ v, from dvd_trans (ysq_dvd_yy a1 k) $
(y_dvd_iff _ _ _).2 $ dvd_mul_left _ _,
have uco : nat.coprime u (4 * y), from
have 2 ∣ v, from modeq.modeq_zero_iff.1 $ (yn_modeq_two _ _).trans $
modeq.modeq_zero_iff.2 (dvd_mul_right _ _),
have nat.coprime u 2, from
(xy_coprime a1 m).coprime_dvd_right this,
(this.mul_right this).mul_right $
(xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv),
let ⟨b, ba, bm1⟩ := modeq.chinese_remainder uco a 1 in
have m1 : 1 < m, from
have 0 < k * y, from mul_pos kpos (y_increasing a1 kpos),
nat.mul_le_mul_left 2 this,
have vp : 0 < v, from y_increasing a1 (lt_trans zero_lt_one m1),
have b1 : 1 < b, from
have xn a1 1 < u, from x_increasing a1 m1,
have a < u, by simp at this; exact this,
lt_of_lt_of_le a1 $ by delta modeq at ba;
rw nat.mod_eq_of_lt this at ba; rw ← ba; apply nat.mod_le,
let s := xn b1 k, t := yn b1 k in
have sx : s ≡ x [MOD u], from (xy_modeq_of_modeq b1 a1 ba k).left,
have tk : t ≡ k [MOD 4 * y], from
have 4 * y ∣ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1);
exact modeq.dvd_of_modeq bm1.symm,
modeq.modeq_of_dvd_of_modeq this $ yn_modeq_a_sub_one _ _,
⟨ky, or.inr ⟨u, v, s, t, b,
pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tk⟩⟩,
λ⟨a1, ky, o⟩, ⟨a1, match o with
| or.inl ⟨x1, y0⟩ := by rw y0 at ky; rw [nat.eq_zero_of_le_zero ky, x1, y0]; exact ⟨rfl, rfl⟩
| or.inr ⟨u, v, s, t, b, xy, uv, st, b1, rem⟩ :=
match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with
| ._, ._, ⟨i, rfl, rfl⟩, ._, ._, ⟨n, rfl, rfl⟩, ._, ._, ⟨j, rfl, rfl⟩,
⟨(bm1 : b ≡ 1 [MOD 4 * yn a1 i]),
(ba : b ≡ a [MOD xn a1 n]),
(vp : 0 < yn a1 n),
(yv : yn a1 i * yn a1 i ∣ yn a1 n),
(sx : xn b1 j ≡ xn a1 i [MOD xn a1 n]),
(tk : yn b1 j ≡ k [MOD 4 * yn a1 i])⟩,
(ky : k ≤ yn a1 i) :=
(nat.eq_zero_or_pos i).elim
(λi0, by simp [i0] at ky; rw [i0, ky]; exact ⟨rfl, rfl⟩) $ λipos,
suffices i = k, by rw this; exact ⟨rfl, rfl⟩,
by clear _x o rem xy uv st _match _match _fun_match; exact
have iln : i ≤ n, from le_of_not_gt $ λhin,
not_lt_of_ge (nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (y_increasing a1 hin),
have yd : 4 * yn a1 i ∣ 4 * n, from mul_dvd_mul_left _ $ dvd_of_ysq_dvd a1 yv,
have jk : j ≡ k [MOD 4 * yn a1 i], from
have 4 * yn a1 i ∣ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1); exact modeq.dvd_of_modeq bm1.symm,
(modeq.modeq_of_dvd_of_modeq this (yn_modeq_a_sub_one b1 _)).symm.trans tk,
have ki : k + i < 4 * yn a1 i, from
lt_of_le_of_lt (add_le_add ky (yn_ge_n a1 i)) $
by rw ← two_mul; exact nat.mul_lt_mul_of_pos_right dec_trivial (y_increasing a1 ipos),
have ji : j ≡ i [MOD 4 * n], from
have xn a1 j ≡ xn a1 i [MOD xn a1 n], from (xy_modeq_of_modeq b1 a1 ba j).left.symm.trans sx,
(modeq_of_xn_modeq a1 ipos iln this).resolve_right $ λ (ji : j + i ≡ 0 [MOD 4 * n]),
not_le_of_gt ki $ nat.le_of_dvd (lt_of_lt_of_le ipos $ nat.le_add_left _ _) $
modeq.modeq_zero_iff.1 $ (modeq.modeq_add jk.symm (modeq.refl i)).trans $
modeq.modeq_of_dvd_of_modeq yd ji,
by have : i % (4 * yn a1 i) = k % (4 * yn a1 i) :=
(modeq.modeq_of_dvd_of_modeq yd ji).symm.trans jk;
rwa [nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_left _ _) ki),
nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_right _ _) ki)] at this
end
end⟩⟩
lemma eq_pow_of_pell_lem {a y k} (a1 : 1 < a) (ypos : 0 < y) : 0 < k → y^k < a →
(↑(y^k) : ℤ) < 2*a*y - y*y - 1 :=
have y < a → a + (y*y + 1) ≤ 2*a*y, begin
intro ya, induction y with y IH, exact absurd ypos (lt_irrefl _),
cases nat.eq_zero_or_pos y with y0 ypos,
{ rw y0, simpa [two_mul], },
{ rw [nat.mul_succ, nat.mul_succ, nat.succ_mul y],
have : y + nat.succ y ≤ 2 * a,
{ change y + y < 2 * a, rw ← two_mul,
exact mul_lt_mul_of_pos_left (nat.lt_of_succ_lt ya) dec_trivial },
have := add_le_add (IH ypos (nat.lt_of_succ_lt ya)) this,
convert this using 1,
ring }
end, λk0 yak,
lt_of_lt_of_le (int.coe_nat_lt_coe_nat_of_lt yak) $
by rw sub_sub; apply le_sub_right_of_add_le;
apply int.coe_nat_le_coe_nat_of_le;
have y1 := nat.pow_le_pow_of_le_right ypos k0; simp at y1;
exact this (lt_of_le_of_lt y1 yak)
theorem eq_pow_of_pell {m n k} : (n^k = m ↔
k = 0 ∧ m = 1 ∨ 0 < k ∧
(n = 0 ∧ m = 0 ∨ 0 < n ∧
∃ (w a t z : ℕ) (a1 : 1 < a),
xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧
2 * a * n = t + (n * n + 1) ∧
m < t ∧ n ≤ w ∧ k ≤ w ∧
a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)) :=
⟨λe, by rw ← e;
refine (nat.eq_zero_or_pos k).elim
(λk0, by rw k0; exact or.inl ⟨rfl, rfl⟩)
(λkpos, or.inr ⟨kpos, _⟩);
refine (nat.eq_zero_or_pos n).elim
(λn0, by rw [n0, nat.zero_pow kpos]; exact or.inl ⟨rfl, rfl⟩)
(λnpos, or.inr ⟨npos, _⟩); exact
let w := _root_.max n k in
have nw : n ≤ w, from le_max_left _ _,
have kw : k ≤ w, from le_max_right _ _,
have wpos : 0 < w, from lt_of_lt_of_le npos nw,
have w1 : 1 < w + 1, from nat.succ_lt_succ wpos,
let a := xn w1 w in
have a1 : 1 < a, from x_increasing w1 wpos,
let x := xn a1 k, y := yn a1 k in
let ⟨z, ze⟩ := show w ∣ yn w1 w, from modeq.modeq_zero_iff.1 $
modeq.trans (yn_modeq_a_sub_one w1 w) (modeq.modeq_zero_iff.2 $ dvd_refl _) in
have nt : (↑(n^k) : ℤ) < 2 * a * n - n * n - 1, from
eq_pow_of_pell_lem a1 npos kpos $ calc
n^k ≤ n^w : nat.pow_le_pow_of_le_right npos kw
... < (w + 1)^w : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) wpos
... ≤ a : xn_ge_a_pow w1 w,
let ⟨t, te⟩ := int.eq_coe_of_zero_le $
le_trans (int.coe_zero_le _) $ le_of_lt nt in
have na : n ≤ a, from le_trans nw $ le_of_lt $ n_lt_xn w1 w,
have tm : x ≡ y * (a - n) + n^k [MOD t], begin
apply modeq.modeq_of_dvd,
rw [int.coe_nat_add, int.coe_nat_mul, int.coe_nat_sub na, ← te],
exact x_sub_y_dvd_pow a1 n k
end,
have ta : 2 * a * n = t + (n * n + 1), from int.coe_nat_inj $
by rw [int.coe_nat_add, ← te, sub_sub];
repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul};
rw [int.coe_nat_one, sub_add_cancel]; refl,
have mt : n^k < t, from int.lt_of_coe_nat_lt_coe_nat $
by rw ← te; exact nt,
have zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1,
by rw ← ze; exact pell_eq w1 w,
⟨w, a, t, z, a1, tm, ta, mt, nw, kw, zp⟩,
λo, match o with
| or.inl ⟨k0, m1⟩ := by rw [k0, m1]; refl
| or.inr ⟨kpos, or.inl ⟨n0, m0⟩⟩ := by rw [n0, m0, nat.zero_pow kpos]
| or.inr ⟨kpos, or.inr ⟨npos, w, a, t, z,
(a1 : 1 < a),
(tm : xn a1 k ≡ yn a1 k * (a - n) + m [MOD t]),
(ta : 2 * a * n = t + (n * n + 1)),
(mt : m < t),
(nw : n ≤ w),
(kw : k ≤ w),
(zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)⟩⟩ :=
have wpos : 0 < w, from lt_of_lt_of_le npos nw,
have w1 : 1 < w + 1, from nat.succ_lt_succ wpos,
let ⟨j, xj, yj⟩ := eq_pell w1 zp in
by clear _match o _let_match; exact
have jpos : 0 < j, from (nat.eq_zero_or_pos j).resolve_left $ λj0,
have a1 : a = 1, by rw j0 at xj; exact xj,
have 2 * n = t + (n * n + 1), by rw a1 at ta; exact ta,
have n1 : n = 1, from
have n * n < n * 2, by rw [mul_comm n 2, this]; apply nat.le_add_left,
have n ≤ 1, from nat.le_of_lt_succ $ lt_of_mul_lt_mul_left this (nat.zero_le _),
le_antisymm this npos,
by rw n1 at this;
rw ← @nat.add_right_cancel 0 2 t this at mt;
exact nat.not_lt_zero _ mt,
have wj : w ≤ j, from nat.le_of_dvd jpos $ modeq.modeq_zero_iff.1 $
(yn_modeq_a_sub_one w1 j).symm.trans $
modeq.modeq_zero_iff.2 ⟨z, yj.symm⟩,
have nt : (↑(n^k) : ℤ) < 2 * a * n - n * n - 1, from
eq_pow_of_pell_lem a1 npos kpos $ calc
n^k ≤ n^j : nat.pow_le_pow_of_le_right npos (le_trans kw wj)
... < (w + 1)^j : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) jpos
... ≤ xn w1 j : xn_ge_a_pow w1 j
... = a : xj.symm,
have na : n ≤ a, by rw xj; exact
le_trans (le_trans nw wj) (le_of_lt $ n_lt_xn _ _),
have te : (t : ℤ) = 2 * ↑a * ↑n - ↑n * ↑n - 1, by
rw sub_sub; apply eq_sub_of_add_eq; apply (int.coe_nat_eq_coe_nat_iff _ _).2;
exact ta.symm,
have xn a1 k ≡ yn a1 k * (a - n) + n^k [MOD t],
by have := x_sub_y_dvd_pow a1 n k;
rw [← te, ← int.coe_nat_sub na] at this; exact modeq.modeq_of_dvd this,
have n^k % t = m % t, from
modeq.modeq_add_cancel_left (modeq.refl _) (this.symm.trans tm),
by rw ← te at nt;
rwa [nat.mod_eq_of_lt (int.lt_of_coe_nat_lt_coe_nat nt), nat.mod_eq_of_lt mt] at this
end⟩
end pell
|
ef96602219b3ecfcce659b6dd8efea74e2a9763b | 367134ba5a65885e863bdc4507601606690974c1 | /src/topology/sheaves/forget.lean | 476998c4eb85923c6fdbc18bceb48bab2bbb8988 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 8,024 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import topology.sheaves.sheaf
import category_theory.limits.preserves.shapes.products
import category_theory.limits.types
/-!
# Checking the sheaf condition on the underlying presheaf of types.
If `G : C ⥤ D` is a functor which reflects isomorphisms and preserves limits
(we assume all limits exist in both `C` and `D`),
then checking the sheaf condition for a presheaf `F : presheaf C X`
is equivalent to checking the sheaf condition for `F ⋙ G`.
The important special case is when
`C` is a concrete category with a forgetful functor
that preserves limits and reflects isomorphisms.
Then to check the sheaf condition it suffices
to check it on the underlying sheaf of types.
## References
* https://stacks.math.columbia.edu/tag/0073
-/
noncomputable theory
open category_theory
open category_theory.limits
open topological_space
open opposite
namespace Top
namespace presheaf
namespace sheaf_condition
open sheaf_condition_equalizer_products
universes v u₁ u₂
variables {C : Type u₁} [category.{v} C] [has_limits C]
variables {D : Type u₂} [category.{v} D] [has_limits D]
variables (G : C ⥤ D) [preserves_limits G]
variables {X : Top.{v}} (F : presheaf C X)
variables {ι : Type v} (U : ι → opens X)
local attribute [reducible] diagram left_res right_res
/--
When `G` preserves limits, the sheaf condition diagram for `F` composed with `G` is
naturally isomorphic to the sheaf condition diagram for `F ⋙ G`.
-/
def diagram_comp_preserves_limits :
diagram F U ⋙ G ≅ diagram (F ⋙ G) U :=
begin
fapply nat_iso.of_components,
rintro ⟨j⟩,
exact (preserves_product.iso _ _),
exact (preserves_product.iso _ _),
rintros ⟨⟩ ⟨⟩ ⟨⟩,
{ ext, simp, dsimp, simp, }, -- non-terminal `simp`, but `squeeze_simp` fails
{ ext,
simp only [limit.lift_π, functor.comp_map, map_lift_pi_comparison, fan.mk_π_app,
preserves_product.iso_hom, parallel_pair_map_left, functor.map_comp,
category.assoc],
dsimp, simp, },
{ ext,
simp only [limit.lift_π, functor.comp_map, parallel_pair_map_right, fan.mk_π_app,
preserves_product.iso_hom, map_lift_pi_comparison, functor.map_comp,
category.assoc],
dsimp, simp, },
{ ext, simp, dsimp, simp, },
end
local attribute [reducible] res
/--
When `G` preserves limits, the image under `G` of the sheaf condition fork for `F`
is the sheaf condition fork for `F ⋙ G`,
postcomposed with the inverse of the natural isomorphism `diagram_comp_preserves_limits`.
-/
def map_cone_fork : G.map_cone (fork F U) ≅
(cones.postcompose (diagram_comp_preserves_limits G F U).inv).obj (fork (F ⋙ G) U) :=
cones.ext (iso.refl _) (λ j,
begin
dsimp, simp [diagram_comp_preserves_limits], cases j; dsimp,
{ rw iso.eq_comp_inv,
ext,
simp, dsimp, simp, },
{ rw iso.eq_comp_inv,
ext,
simp, -- non-terminal `simp`, but `squeeze_simp` fails
dsimp,
simp only [limit.lift_π, fan.mk_π_app, ←G.map_comp, limit.lift_π_assoc, fan.mk_π_app] }
end)
end sheaf_condition
universes v u₁ u₂
open sheaf_condition sheaf_condition_equalizer_products
variables {C : Type u₁} [category.{v} C] {D : Type u₂} [category.{v} D]
variables (G : C ⥤ D)
variables [reflects_isomorphisms G]
variables [has_limits C] [has_limits D] [preserves_limits G]
variables {X : Top.{v}} (F : presheaf C X)
/--
If `G : C ⥤ D` is a functor which reflects isomorphisms and preserves limits
(we assume all limits exist in both `C` and `D`),
then checking the sheaf condition for a presheaf `F : presheaf C X`
is equivalent to checking the sheaf condition for `F ⋙ G`.
The important special case is when
`C` is a concrete category with a forgetful functor
that preserves limits and reflects isomorphisms.
Then to check the sheaf condition it suffices to check it on the underlying sheaf of types.
Another useful example is the forgetful functor `TopCommRing ⥤ Top`.
See https://stacks.math.columbia.edu/tag/0073.
In fact we prove a stronger version with arbitrary complete target category.
-/
def sheaf_condition_equiv_sheaf_condition_comp :
sheaf_condition F ≃ sheaf_condition (F ⋙ G) :=
begin
apply equiv_of_subsingleton_of_subsingleton,
{ intros S ι U,
-- We have that the sheaf condition fork for `F` is a limit fork,
have t₁ := S U,
-- and since `G` preserves limits, the image under `G` of this fork is a limit fork too.
have t₂ := @preserves_limit.preserves _ _ _ _ _ _ _ G _ _ t₁,
-- As we established above, that image is just the sheaf condition fork
-- for `F ⋙ G` postcomposed with some natural isomorphism,
have t₃ := is_limit.of_iso_limit t₂ (map_cone_fork G F U),
-- and as postcomposing by a natural isomorphism preserves limit cones,
have t₄ := is_limit.postcompose_inv_equiv _ _ t₃,
-- we have our desired conclusion.
exact t₄, },
{ intros S ι U,
-- Let `f` be the universal morphism from `F.obj U` to the equalizer of the sheaf condition fork,
-- whatever it is. Our goal is to show that this is an isomorphism.
let f := equalizer.lift _ (w F U),
-- If we can do that,
suffices : is_iso (G.map f),
{ resetI,
-- we have that `f` itself is an isomorphism, since `G` reflects isomorphisms
haveI : is_iso f := is_iso_of_reflects_iso f G,
-- TODO package this up as a result elsewhere:
apply is_limit.of_iso_limit (limit.is_limit _),
apply iso.symm,
fapply cones.ext,
exact (as_iso f),
rintro ⟨_|_⟩; { dsimp [f], simp, }, },
{ -- Returning to the task of shwoing that `G.map f` is an isomorphism,
-- we note that `G.map f` is almost but not quite (see below) a morphism
-- from the sheaf condition cone for `F ⋙ G` to the
-- image under `G` of the equalizer cone for the sheaf condition diagram.
let c := fork (F ⋙ G) U,
have hc : is_limit c := S U,
let d := G.map_cone (equalizer.fork (left_res F U) (right_res F U)),
have hd : is_limit d := preserves_limit.preserves (limit.is_limit _),
-- Since both of these are limit cones
-- (`c` by our hypothesis `S`, and `d` because `G` preserves limits),
-- we hope to be able to conclude that `f` is an isomorphism.
-- We say "not quite" above because `c` and `d` don't quite have the same shape:
-- we need to postcompose by the natural isomorphism `diagram_comp_preserves_limits`
-- introduced above.
let d' := (cones.postcompose (diagram_comp_preserves_limits G F U).hom).obj d,
have hd' : is_limit d' :=
(is_limit.postcompose_hom_equiv (diagram_comp_preserves_limits G F U) d).symm hd,
-- Now everything works: we verify that `f` really is a morphism between these cones:
let f' : c ⟶ d' :=
fork.mk_hom (G.map f)
begin
dsimp only [c, d, d', f, diagram_comp_preserves_limits, res],
dunfold fork.ι,
ext1 j,
dsimp,
simp only [category.assoc, ←functor.map_comp_assoc, equalizer.lift_ι,
map_lift_pi_comparison_assoc],
dsimp [res], simp,
end,
-- conclude that it is an isomorphism,
-- just because it's a morphism between two limit cones.
haveI : is_iso f' := is_limit.hom_is_iso hc hd' f',
-- A cone morphism is an isomorphism exactly if the morphism between the cone points is,
-- so we're done!
exact { ..((cones.forget _).map_iso (as_iso f')) }, }, },
end
/-!
As an example, we now have everything we need to check the sheaf condition
for a presheaf of commutative rings, merely by checking the sheaf condition
for the underlying sheaf of types.
```
example (X : Top) (F : presheaf CommRing X) (h : sheaf_condition (F ⋙ (forget CommRing))) :
sheaf_condition F :=
(sheaf_condition_equiv_sheaf_condition_forget F).symm h
```
-/
end presheaf
end Top
|
5c146d2473ad284d47344cb2b2d59da83a183c9f | 78630e908e9624a892e24ebdd21260720d29cf55 | /src/logic_propositional/prop_08.lean | e4d87749ec19aa7d283efb036edb588af74a0b9b | [
"CC0-1.0"
] | permissive | tomasz-lisowski/lean-logic-examples | 84e612466776be0a16c23a0439ff8ef6114ddbe1 | 2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d | refs/heads/master | 1,683,334,199,431 | 1,621,938,305,000 | 1,621,938,305,000 | 365,041,573 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 178 | lean | namespace prop_08
variable P : Prop
theorem prop_8 : ¬ ¬ ¬ P → ¬ P :=
assume h1: ¬ ¬ ¬ P,
show ¬ P, from (classical.by_contradiction h1)
-- end namespace
end prop_08 |
9e068f91188b497edb336f130c68cce564631951 | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /library/data/fintype/function.lean | a0d5cf923fd702c8d760c8b169fdf33c5cd7f93a | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 18,672 | lean | /-
Copyright (c) 2015 Haitao Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Haitao Zhang
-/
import data
open nat function eq.ops
namespace list
-- this is in preparation for counting the number of finite functions
section list_of_lists
open prod
variable {A : Type}
definition cons_pair (pr : A × list A) := (pr1 pr) :: (pr2 pr)
definition cons_all_of (elts : list A) (ls : list (list A)) : list (list A) :=
map cons_pair (product elts ls)
lemma pair_of_cons {a} {l} {pr : A × list A} : cons_pair pr = a::l → pr = (a, l) :=
prod.destruct pr (λ p1 p2, assume Peq, list.no_confusion Peq (by intros; substvars))
lemma cons_pair_inj : injective (@cons_pair A) :=
take p1 p2, assume Pl,
prod.eq (list.no_confusion Pl (λ P1 P2, P1)) (list.no_confusion Pl (λ P1 P2, P2))
lemma nodup_of_cons_all {elts : list A} {ls : list (list A)}
: nodup elts → nodup ls → nodup (cons_all_of elts ls) :=
assume Pelts Pls,
nodup_map cons_pair_inj (nodup_product Pelts Pls)
lemma length_cons_all {elts : list A} {ls : list (list A)} :
length (cons_all_of elts ls) = length elts * length ls := calc
length (cons_all_of elts ls) = length (product elts ls) : length_map
... = length elts * length ls : length_product
variable [finA : fintype A]
include finA
definition all_lists_of_len : ∀ (n : nat), list (list A)
| 0 := [[]]
| (succ n) := cons_all_of (elements_of A) (all_lists_of_len n)
definition all_nodups_of_len [deceqA : decidable_eq A] (n : nat) : list (list A) :=
filter nodup (all_lists_of_len n)
lemma nodup_all_lists : ∀ {n : nat}, nodup (@all_lists_of_len A _ n)
| 0 := nodup_singleton []
| (succ n) := nodup_of_cons_all (fintype.unique A) nodup_all_lists
lemma nodup_all_nodups [deceqA : decidable_eq A] {n : nat} :
nodup (@all_nodups_of_len A _ _ n) :=
nodup_filter nodup nodup_all_lists
lemma mem_all_lists : ∀ {n : nat} {l : list A}, length l = n → l ∈ all_lists_of_len n
| 0 [] := assume P, mem_cons [] []
| 0 (a::l) := assume Peq, by contradiction
| (succ n) [] := assume Peq, by contradiction
| (succ n) (a::l) := assume Peq, begin
apply mem_map, apply mem_product,
exact fintype.complete a,
exact mem_all_lists (succ.inj Peq)
end
lemma mem_all_nodups [deceqA : decidable_eq A] (n : nat) (l : list A) :
length l = n → nodup l → l ∈ all_nodups_of_len n :=
assume Pl Pn, mem_filter_of_mem (mem_all_lists Pl) Pn
lemma nodup_mem_all_nodups [deceqA : decidable_eq A] {n : nat} ⦃l : list A⦄ :
l ∈ all_nodups_of_len n → nodup l :=
assume Pl, of_mem_filter Pl
lemma length_mem_all_lists : ∀ {n : nat} ⦃l : list A⦄,
l ∈ all_lists_of_len n → length l = n
| 0 [] := assume P, rfl
| 0 (a::l) := assume Pin, assert Peq : (a::l) = [], from mem_singleton Pin,
by contradiction
| (succ n) [] := assume Pin, obtain pr Pprin Ppr, from exists_of_mem_map Pin,
by contradiction
| (succ n) (a::l) := assume Pin, obtain pr Pprin Ppr, from exists_of_mem_map Pin,
assert Pl : l ∈ all_lists_of_len n,
from mem_of_mem_product_right ((pair_of_cons Ppr) ▸ Pprin),
by rewrite [length_cons, length_mem_all_lists Pl]
lemma length_mem_all_nodups [deceqA : decidable_eq A] {n : nat} ⦃l : list A⦄ :
l ∈ all_nodups_of_len n → length l = n :=
assume Pl, length_mem_all_lists (mem_of_mem_filter Pl)
open fintype
lemma length_all_lists : ∀ {n : nat}, length (@all_lists_of_len A _ n) = (card A) ^ n
| 0 := calc length [[]] = 1 : length_cons
| (succ n) := calc length _ = card A * length (all_lists_of_len n) : length_cons_all
... = card A * (card A ^ n) : length_all_lists
... = (card A ^ n) * card A : mul.comm
... = (card A) ^ (succ n) : pow_succ'
end list_of_lists
section kth
variable {A : Type}
definition kth : ∀ k (l : list A), k < length l → A
| k [] := begin rewrite length_nil, intro Pltz, exact absurd Pltz !not_lt_zero end
| 0 (a::l) := λ P, a
| (k+1) (a::l):= by rewrite length_cons; intro Plt; exact kth k l (lt_of_succ_lt_succ Plt)
lemma kth_zero_of_cons {a} (l : list A) (P : 0 < length (a::l)) : kth 0 (a::l) P = a :=
rfl
lemma kth_succ_of_cons {a} k (l : list A) (P : k+1 < length (a::l)) :
kth (succ k) (a::l) P = kth k l (lt_of_succ_lt_succ P) :=
rfl
lemma kth_mem : ∀ {k : nat} {l : list A} P, kth k l P ∈ l
| k [] := assume P, absurd P !not_lt_zero
| 0 (a::l) := assume P, by rewrite kth_zero_of_cons; apply mem_cons
| (succ k) (a::l) := assume P, by
rewrite [kth_succ_of_cons]; apply mem_cons_of_mem a; apply kth_mem
-- Leo provided the following proof.
lemma eq_of_kth_eq [deceqA : decidable_eq A]
: ∀ {l1 l2 : list A} (Pleq : length l1 = length l2),
(∀ (k : nat) (Plt1 : k < length l1) (Plt2 : k < length l2), kth k l1 Plt1 = kth k l2 Plt2) → l1 = l2
| [] [] h₁ h₂ := rfl
| (a₁::l₁) [] h₁ h₂ := by contradiction
| [] (a₂::l₂) h₁ h₂ := by contradiction
| (a₁::l₁) (a₂::l₂) h₁ h₂ :=
have ih₁ : length l₁ = length l₂, by injection h₁; eassumption,
have ih₂ : ∀ (k : nat) (plt₁ : k < length l₁) (plt₂ : k < length l₂), kth k l₁ plt₁ = kth k l₂ plt₂,
begin
intro k plt₁ plt₂,
have splt₁ : succ k < length l₁ + 1, from succ_le_succ plt₁,
have splt₂ : succ k < length l₂ + 1, from succ_le_succ plt₂,
have keq : kth (succ k) (a₁::l₁) splt₁ = kth (succ k) (a₂::l₂) splt₂, from h₂ (succ k) splt₁ splt₂,
rewrite *kth_succ_of_cons at keq,
exact keq
end,
assert ih : l₁ = l₂, from eq_of_kth_eq ih₁ ih₂,
assert k₁ : a₁ = a₂,
begin
have lt₁ : 0 < length (a₁::l₁), from !zero_lt_succ,
have lt₂ : 0 < length (a₂::l₂), from !zero_lt_succ,
have e₁ : kth 0 (a₁::l₁) lt₁ = kth 0 (a₂::l₂) lt₂, from h₂ 0 lt₁ lt₂,
rewrite *kth_zero_of_cons at e₁,
assumption
end,
by subst l₁; subst a₁
lemma kth_of_map {B : Type} {f : A → B} :
∀ {k : nat} {l : list A} Plt Pmlt, kth k (map f l) Pmlt = f (kth k l Plt)
| k [] := assume P, absurd P !not_lt_zero
| 0 (a::l) := assume Plt, by
rewrite [map_cons]; intro Pmlt; rewrite [kth_zero_of_cons]
| (succ k) (a::l) := assume P, begin
rewrite [map_cons], intro Pmlt, rewrite [*kth_succ_of_cons],
apply kth_of_map
end
lemma kth_find [deceqA : decidable_eq A] :
∀ {l : list A} {a} P, kth (find a l) l P = a
| [] := take a, assume P, absurd P !not_lt_zero
| (x::l) := take a, begin
assert Pd : decidable (a = x), {apply deceqA},
cases Pd with Pe Pne,
rewrite [find_cons_of_eq l Pe], intro P, rewrite [kth_zero_of_cons, Pe],
rewrite [find_cons_of_ne l Pne], intro P, rewrite [kth_succ_of_cons],
apply kth_find
end
lemma find_kth [deceqA : decidable_eq A] :
∀ {k : nat} {l : list A} P, find (kth k l P) l < length l
| k [] := assume P, absurd P !not_lt_zero
| 0 (a::l) := assume P, begin
rewrite [kth_zero_of_cons, find_cons_of_eq l rfl, length_cons],
exact !zero_lt_succ
end
| (succ k) (a::l) := assume P, begin
rewrite [kth_succ_of_cons],
assert Pd : decidable ((kth k l (lt_of_succ_lt_succ P)) = a),
{apply deceqA},
cases Pd with Pe Pne,
rewrite [find_cons_of_eq l Pe], apply zero_lt_succ,
rewrite [find_cons_of_ne l Pne], apply succ_lt_succ, apply find_kth
end
lemma find_kth_of_nodup [deceqA : decidable_eq A] :
∀ {k : nat} {l : list A} P, nodup l → find (kth k l P) l = k
| k [] := assume P, absurd P !not_lt_zero
| 0 (a::l) := assume Plt Pnodup,
by rewrite [kth_zero_of_cons, find_cons_of_eq l rfl]
| (succ k) (a::l) := assume Plt Pnodup, begin
rewrite [kth_succ_of_cons],
assert Pd : decidable ((kth k l (lt_of_succ_lt_succ Plt)) = a),
{apply deceqA},
cases Pd with Pe Pne,
assert Pin : a ∈ l, {rewrite -Pe, apply kth_mem},
exact absurd Pin (not_mem_of_nodup_cons Pnodup),
rewrite [find_cons_of_ne l Pne], apply congr (eq.refl succ),
apply find_kth_of_nodup (lt_of_succ_lt_succ Plt) (nodup_of_nodup_cons Pnodup)
end
end kth
end list
namespace fintype
open list
section found
variables {A B : Type}
variable [finA : fintype A]
include finA
lemma find_in_range [deceqB : decidable_eq B] {f : A → B} (b : B) :
∀ (l : list A) P, f (kth (find b (map f l)) l P) = b
| [] := assume P, begin exact absurd P !not_lt_zero end
| (a::l) := decidable.rec_on (deceqB b (f a))
(assume Peq, begin
rewrite [map_cons f a l, find_cons_of_eq _ Peq],
intro P, rewrite [kth_zero_of_cons], exact (Peq⁻¹)
end)
(assume Pne, begin
rewrite [map_cons f a l, find_cons_of_ne _ Pne],
intro P,
rewrite [kth_succ_of_cons (find b (map f l)) l P],
exact find_in_range l (lt_of_succ_lt_succ P)
end)
end found
section list_to_fun
variables {A B : Type}
variable [finA : fintype A]
include finA
definition fun_to_list (f : A → B) : list B := map f (elems A)
lemma length_map_of_fintype (f : A → B) : length (map f (elems A)) = card A :=
by apply length_map
variable [deceqA : decidable_eq A]
include deceqA
lemma fintype_find (a : A) : find a (elems A) < card A :=
find_lt_length (complete a)
definition list_to_fun (l : list B) (leq : length l = card A) : A → B :=
take x,
kth _ _ (leq⁻¹ ▸ fintype_find x)
definition all_funs [finB : fintype B] : list (A → B) :=
dmap (λ l, length l = card A) list_to_fun (all_lists_of_len (card A))
lemma list_to_fun_apply (l : list B) (leq : length l = card A) (a : A) :
∀ P, list_to_fun l leq a = kth (find a (elems A)) l P :=
assume P, rfl
variable [deceqB : decidable_eq B]
include deceqB
lemma fun_eq_list_to_fun_map (f : A → B) : ∀ P, f = list_to_fun (map f (elems A)) P :=
assume Pleq, funext (take a,
assert Plt : _, from Pleq⁻¹ ▸ find_lt_length (complete a), begin
rewrite [list_to_fun_apply _ Pleq a (Pleq⁻¹ ▸ find_lt_length (complete a))],
assert Pmlt : find a (elems A) < length (map f (elems A)),
{rewrite length_map, exact Plt},
rewrite [@kth_of_map A B f (find a (elems A)) (elems A) Plt _, kth_find]
end)
lemma list_eq_map_list_to_fun (l : list B) (leq : length l = card A)
: l = map (list_to_fun l leq) (elems A) :=
begin
apply eq_of_kth_eq, rewrite length_map, apply leq,
intro k Plt Plt2,
assert Plt1 : k < length (elems A), {apply leq ▸ Plt},
assert Plt3 : find (kth k (elems A) Plt1) (elems A) < length l,
{rewrite leq, apply find_kth},
rewrite [kth_of_map Plt1 Plt2, list_to_fun_apply l leq _ Plt3],
congruence,
rewrite [find_kth_of_nodup Plt1 (unique A)]
end
lemma fun_to_list_to_fun (f : A → B) : ∀ P, list_to_fun (fun_to_list f) P = f :=
assume P, (fun_eq_list_to_fun_map f P)⁻¹
lemma list_to_fun_to_list (l : list B) (leq : length l = card A) :
fun_to_list (list_to_fun l leq) = l
:= (list_eq_map_list_to_fun l leq)⁻¹
lemma dinj_list_to_fun : dinj (λ (l : list B), length l = card A) list_to_fun :=
take l1 l2 Pl1 Pl2 Peq,
by rewrite [list_eq_map_list_to_fun l1 Pl1, list_eq_map_list_to_fun l2 Pl2, Peq]
variable [finB : fintype B]
include finB
lemma nodup_all_funs : nodup (@all_funs A B _ _ _) :=
dmap_nodup_of_dinj dinj_list_to_fun nodup_all_lists
lemma all_funs_complete (f : A → B) : f ∈ all_funs :=
assert Plin : map f (elems A) ∈ all_lists_of_len (card A),
from mem_all_lists (by rewrite length_map),
assert Plfin : list_to_fun (map f (elems A)) (length_map_of_fintype f) ∈ all_funs,
from mem_dmap _ Plin,
begin rewrite [fun_eq_list_to_fun_map f (length_map_of_fintype f)], apply Plfin end
lemma all_funs_to_all_lists :
map fun_to_list (@all_funs A B _ _ _) = all_lists_of_len (card A) :=
map_dmap_of_inv_of_pos list_to_fun_to_list length_mem_all_lists
lemma length_all_funs : length (@all_funs A B _ _ _) = (card B) ^ (card A) := calc
length _ = length (map fun_to_list all_funs) : length_map
... = length (all_lists_of_len (card A)) : all_funs_to_all_lists
... = (card B) ^ (card A) : length_all_lists
definition fun_is_fintype [instance] : fintype (A → B) :=
fintype.mk all_funs nodup_all_funs all_funs_complete
lemma card_funs : card (A → B) = (card B) ^ (card A) := length_all_funs
end list_to_fun
section surj_inv
variables {A B : Type}
variable [finA : fintype A]
include finA
-- surj from fintype domain implies fintype range
lemma mem_map_of_surj {f : A → B} (surj : surjective f) : ∀ b, b ∈ map f (elems A) :=
take b, obtain a Peq, from surj b,
Peq ▸ mem_map f (complete a)
variable [deceqB : decidable_eq B]
include deceqB
lemma found_of_surj {f : A → B} (surj : surjective f) :
∀ b, let elts := elems A, k := find b (map f elts) in k < length elts :=
λ b, let elts := elems A, img := map f elts, k := find b img in
have Pin : b ∈ img, from mem_map_of_surj surj b,
assert Pfound : k < length img, from find_lt_length (mem_map_of_surj surj b),
length_map f elts ▸ Pfound
definition right_inv {f : A → B} (surj : surjective f) : B → A :=
λ b, let elts := elems A, k := find b (map f elts) in
kth k elts (found_of_surj surj b)
lemma right_inv_of_surj {f : A → B} (surj : surjective f) : f ∘ (right_inv surj) = id :=
funext (λ b, find_in_range b (elems A) (found_of_surj surj b))
end surj_inv
-- inj functions for equal card types are also surj and therefore bij
-- the right inv (since it is surj) is also the left inv
section inj
open finset
variables {A B : Type}
variable [finA : fintype A]
include finA
variable [deceqA : decidable_eq A]
include deceqA
lemma inj_of_card_image_eq [deceqB : decidable_eq B] {f : A → B} :
finset.card (image f univ) = card A → injective f :=
assume Peq, by
rewrite [set.injective_iff_inj_on_univ, -to_set_univ];
apply inj_on_of_card_image_eq Peq
variable [deceqB : decidable_eq B]
include deceqB
lemma nodup_of_inj {f : A → B} : injective f → nodup (map f (elems A)) :=
assume Pinj, nodup_map Pinj (unique A)
lemma inj_of_nodup {f : A → B} :
nodup (map f (elems A)) → injective f :=
assume Pnodup, inj_of_card_image_eq (calc
finset.card (image f univ) = finset.card (to_finset (map f (elems A))) : rfl
... = finset.card (to_finset_of_nodup (map f (elems A)) Pnodup) : {(to_finset_eq_of_nodup Pnodup)⁻¹}
... = length (map f (elems A)) : rfl
... = length (elems A) : length_map
... = card A : rfl)
variable [finB : fintype B]
include finB
lemma surj_of_inj_eq_card : card A = card B → ∀ {f : A → B}, injective f → surjective f :=
assume Peqcard, take f, assume Pinj,
decidable.rec_on decidable_forall_finite
(assume P : surjective f, P)
(assume Pnsurj : ¬surjective f,
obtain b Pne, from exists_not_of_not_forall Pnsurj,
assert Pall : ∀ a, f a ≠ b, from forall_not_of_not_exists Pne,
assert Pbnin : b ∉ image f univ, from λ Pin,
obtain a Pa, from exists_of_mem_image Pin, absurd (and.right Pa) (Pall a),
assert Puniv : finset.card (image f univ) = card A, from card_eq_card_image_of_inj Pinj,
assert Punivb : finset.card (image f univ) = card B, from eq.trans Puniv Peqcard,
assert P : image f univ = univ, from univ_of_card_eq_univ Punivb,
absurd (P⁻¹▸ mem_univ b) Pbnin)
end inj
section perm
definition all_injs (A : Type) [finA : fintype A] [deceqA : decidable_eq A] : list (A → A) :=
dmap (λ l, length l = card A) list_to_fun (all_nodups_of_len (card A))
variable {A : Type}
variable [finA : fintype A]
include finA
variable [deceqA : decidable_eq A]
include deceqA
lemma nodup_all_injs : nodup (all_injs A) :=
dmap_nodup_of_dinj dinj_list_to_fun nodup_all_nodups
lemma all_injs_complete {f : A → A} : injective f → f ∈ (all_injs A) :=
assume Pinj,
assert Plin : map f (elems A) ∈ all_nodups_of_len (card A),
from begin apply mem_all_nodups, apply length_map, apply nodup_of_inj Pinj end,
assert Plfin : list_to_fun (map f (elems A)) (length_map_of_fintype f) ∈ !all_injs,
from mem_dmap _ Plin,
begin rewrite [fun_eq_list_to_fun_map f (length_map_of_fintype f)], apply Plfin end
open finset
lemma univ_of_leq_univ_of_nodup {l : list A} (n : nodup l) (leq : length l = card A) :
to_finset_of_nodup l n = univ :=
univ_of_card_eq_univ (calc
finset.card (to_finset_of_nodup l n) = length l : rfl
... = card A : leq)
lemma inj_of_mem_all_injs {f : A → A} : f ∈ (all_injs A) → injective f :=
assume Pfin, obtain l Pex, from exists_of_mem_dmap Pfin,
obtain leq Pin Peq, from Pex,
assert Pmap : map f (elems A) = l, from Peq⁻¹ ▸ list_to_fun_to_list l leq,
begin apply inj_of_nodup, rewrite Pmap, apply nodup_mem_all_nodups Pin end
lemma perm_of_inj {f : A → A} : injective f → perm (map f (elems A)) (elems A) :=
assume Pinj,
assert P1 : univ = to_finset_of_nodup (elems A) (unique A), from rfl,
assert P2 : to_finset_of_nodup (map f (elems A)) (nodup_of_inj Pinj) = univ,
from univ_of_leq_univ_of_nodup _ !length_map,
quot.exact (P1 ▸ P2)
end perm
end fintype
|
81696c46eff73ba1436a7bd96a2fe96a32802e60 | ea5678cc400c34ff95b661fa26d15024e27ea8cd | /quotient_ring.lean | ec7b9903fa8b4ee1ca6ae70db17b0c86fe864e7b | [] | no_license | ChrisHughes24/leanstuff | dca0b5349c3ed893e8792ffbd98cbcadaff20411 | 9efa85f72efaccd1d540385952a6acc18fce8687 | refs/heads/master | 1,654,883,241,759 | 1,652,873,885,000 | 1,652,873,885,000 | 134,599,537 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,051 | lean | import ring_theory.ideals linear_algebra.quotient_module tactic.ring
open set function
universes u v w
variables {α : Type u} {β : Type v} [comm_ring α] [comm_ring β] {a b : α}
namespace is_ideal
lemma zero (S : set α) [is_ideal S] : (0 : α) ∈ S := is_submodule.zero_ α S
lemma add {S : set α} [is_ideal S] : a ∈ S → b ∈ S → a + b ∈ S := is_submodule.add_ α
lemma neg_iff {S : set α} [is_ideal S] : a ∈ S ↔ -a ∈ S := ⟨is_submodule.neg, λ h, neg_neg a ▸ is_submodule.neg h⟩
lemma sub {S : set α} [is_ideal S] : a ∈ S → b ∈ S → a - b ∈ S := is_submodule.sub
lemma mul_left {S : set α} [is_ideal S] : b ∈ S → a * b ∈ S := @is_submodule.smul α α _ _ _ _ a _
lemma mul_right {S : set α} [is_ideal S] : a ∈ S → a * b ∈ S := mul_comm b a ▸ mul_left
def quotient_rel (S : set α) [is_ideal S] := is_submodule.quotient_rel S
local attribute [instance] quotient_rel
def quotient (S : set α) [is_ideal S] := quotient (quotient_rel S)
instance (S : set α) [is_ideal S] : comm_ring (quotient S) :=
{ mul := λ a b, quotient.lift_on₂ a b (λ a b, ⟦a * b⟧)
(λ a₁ a₂ b₁ b₂ (h₁ : a₁ - b₁ ∈ S) (h₂ : a₂ - b₂ ∈ S),
quotient.sound
(show a₁ * a₂ - b₁ * b₂ ∈ S, from
have h : a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ =
a₁ * a₂ - b₁ * b₂, by ring,
h ▸ add (mul_left h₁) (mul_right h₂))),
mul_assoc := λ a b c, quotient.induction_on₃ a b c $
λ a b c, show ⟦_⟧ = ⟦_⟧, by rw mul_assoc,
mul_comm := λ a b, quotient.induction_on₂ a b $
λ a b, show ⟦_⟧ = ⟦_⟧, by rw mul_comm,
one := ⟦1⟧,
one_mul := λ a, quotient.induction_on a $
λ a, show ⟦_⟧ = ⟦_⟧, by rw one_mul,
mul_one := λ a, quotient.induction_on a $
λ a, show ⟦_⟧ = ⟦_⟧, by rw mul_one,
left_distrib := λ a b c, quotient.induction_on₃ a b c $
λ a b c, show ⟦_⟧ = ⟦_⟧, by rw mul_add,
right_distrib := λ a b c, quotient.induction_on₃ a b c $
λ a b c, show ⟦_⟧ = ⟦_⟧, by rw add_mul,
..is_submodule.quotient.add_comm_group S }
lemma is_proper_ideal_iff_one_not_mem {S : set α} [hS : is_ideal S] :
is_proper_ideal S ↔ (1 : α) ∉ S :=
⟨λ h h1, by exactI is_proper_ideal.ne_univ S
(eq_univ_iff_forall.2 (λ a, mul_one a ▸ mul_left h1)),
λ h, {ne_univ := mt eq_univ_iff_forall.1 (λ ha, h (ha _)), ..hS}⟩
lemma quotient_eq_zero_iff_mem {S : set α} [is_ideal S] : ⟦a⟧ = (0 : quotient S) ↔ a ∈ S :=
by conv {to_rhs, rw ← sub_zero a }; exact quotient.eq
instance (S : set α) [is_prime_ideal S] : integral_domain (quotient S) :=
{ zero_ne_one := ne.symm $ mt quotient_eq_zero_iff_mem.1
(is_proper_ideal_iff_one_not_mem.1 (by apply_instance)),
eq_zero_or_eq_zero_of_mul_eq_zero := λ a b,
quotient.induction_on₂ a b $ λ a b hab,
(is_prime_ideal.mem_or_mem_of_mul_mem
(quotient_eq_zero_iff_mem.1 hab)).elim
(or.inl ∘ quotient_eq_zero_iff_mem.2)
(or.inr ∘ quotient_eq_zero_iff_mem.2),
..is_ideal.comm_ring S }
instance (S : set α) : is_ideal (span S) :=
{ ..show is_submodule (span S), by apply_instance }
lemma exists_inv {S : set α} [is_maximal_ideal S] {a : quotient S} : a ≠ 0 →
∃ b : quotient S, a * b = 1 :=
quotient.induction_on a $ λ a ha,
classical.by_contradiction $ λ h,
have haS : a ∉ S := mt quotient_eq_zero_iff_mem.2 ha,
by haveI hS : is_proper_ideal (span (set.insert a S)) :=
is_proper_ideal_iff_one_not_mem.2
(mt mem_span_insert.1 $ λ ⟨b, hb⟩,
h ⟨-⟦b⟧, quotient.sound (show a * -b - 1 ∈ S,
from neg_iff.2 (begin
rw [neg_sub, mul_neg_eq_neg_mul_symm, sub_eq_add_neg, neg_neg, mul_comm],
rw span_eq_of_is_submodule (show is_submodule S, by apply_instance) at hb,
exact hb
end))⟩);
exact
have span (set.insert a S) = S :=
or.resolve_right (is_maximal_ideal.eq_or_univ_of_subset (span (set.insert a S))
(subset.trans (subset_insert _ _) subset_span)) (is_proper_ideal.ne_univ _),
haS (this ▸ subset_span (mem_insert _ _))
local attribute [instance] classical.prop_decidable
/-- quotient by maximal ideal is a field. A definition rather than an instance, since
it is noncomputable, and users may have a computable inverse in some applications-/
noncomputable def field (S : set α) [is_maximal_ideal S] : field (quotient S) :=
{ zero_ne_one := ne.symm $ mt quotient_eq_zero_iff_mem.1
(is_proper_ideal_iff_one_not_mem.1 (by apply_instance)),
inv := λ a, if ha : a = 0 then 0 else classical.some (exists_inv ha),
mul_inv_cancel := λ a (ha : a ≠ 0), show a * dite _ _ _ = _,
by rw dif_neg ha;
exact classical.some_spec (exists_inv ha),
inv_mul_cancel := λ a (ha : a ≠ 0), show dite _ _ _ * a = _,
by rw [mul_comm, dif_neg ha];
exact classical.some_spec (exists_inv ha),
..is_ideal.comm_ring S }
instance is_ring_hom_quotient_mk (S : set α) [is_ideal S] :
@is_ring_hom _ (quotient S) _ _ quotient.mk :=
by refine {..}; intros; refl
end is_ideal |
75313558fa2727bfa8d60d626950408fd3095fe6 | 1e3a43e8ba59c6fe1c66775b6e833e721eaf1675 | /src/data/option/basic.lean | 8b2b0c8e54e951aec9a86eb318d303a70ecf9afb | [
"Apache-2.0"
] | permissive | Sterrs/mathlib | ea6910847b8dfd18500486de9ab0ee35704a3f52 | d9327e433804004aa1dc65091bbe0de1e5a08c5e | refs/heads/master | 1,650,769,884,257 | 1,587,808,694,000 | 1,587,808,694,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,256 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import tactic.basic
namespace option
variables {α : Type*} {β : Type*} {γ : Type*}
lemma some_ne_none (x : α) : some x ≠ none := λ h, option.no_confusion h
@[simp] theorem get_mem : ∀ {o : option α} (h : is_some o), option.get h ∈ o
| (some a) _ := rfl
theorem get_of_mem {a : α} : ∀ {o : option α} (h : is_some o), a ∈ o → option.get h = a
| _ _ rfl := rfl
@[simp] lemma not_mem_none (a : α) : a ∉ (none : option α) :=
λ h, option.no_confusion h
@[simp] lemma some_get : ∀ {x : option α} (h : is_some x), some (option.get h) = x
| (some x) hx := rfl
@[simp] lemma get_some (x : α) (h : is_some (some x)) : option.get h = x := rfl
@[simp] lemma get_or_else_some (x y : α) : option.get_or_else (some x) y = x := rfl
theorem mem_unique {o : option α} {a b : α} (ha : a ∈ o) (hb : b ∈ o) : a = b :=
option.some.inj $ ha.symm.trans hb
theorem injective_some (α : Type*) : function.injective (@some α) :=
λ _ _, some_inj.mp
/-- `option.map f` is injective if `f` is injective. -/
theorem injective_map {f : α → β} (Hf : function.injective f) : function.injective (option.map f)
| none none H := rfl
| (some a₁) (some a₂) H := by rw Hf (option.some.inj H)
@[ext] theorem ext : ∀ {o₁ o₂ : option α}, (∀ a, a ∈ o₁ ↔ a ∈ o₂) → o₁ = o₂
| none none H := rfl
| (some a) o H := ((H _).1 rfl).symm
| o (some b) H := (H _).2 rfl
theorem eq_none_iff_forall_not_mem {o : option α} :
o = none ↔ (∀ a, a ∉ o) :=
⟨λ e a h, by rw e at h; cases h, λ h, ext $ by simpa⟩
@[simp] theorem none_bind {α β} (f : α → option β) : none >>= f = none := rfl
@[simp] theorem some_bind {α β} (a : α) (f : α → option β) : some a >>= f = f a := rfl
@[simp] theorem none_bind' (f : α → option β) : none.bind f = none := rfl
@[simp] theorem some_bind' (a : α) (f : α → option β) : (some a).bind f = f a := rfl
@[simp] theorem bind_some : ∀ x : option α, x >>= some = x :=
@bind_pure α option _ _
@[simp] theorem bind_eq_some {α β} {x : option α} {f : α → option β} {b : β} : x >>= f = some b ↔ ∃ a, x = some a ∧ f a = some b :=
by cases x; simp
@[simp] theorem bind_eq_some' {x : option α} {f : α → option β} {b : β} : x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b :=
by cases x; simp
@[simp] theorem bind_eq_none' {o : option α} {f : α → option β} :
o.bind f = none ↔ (∀ b a, a ∈ o → b ∉ f a) :=
by simp only [eq_none_iff_forall_not_mem, not_exists, not_and, mem_def, bind_eq_some']
@[simp] theorem bind_eq_none {α β} {o : option α} {f : α → option β} :
o >>= f = none ↔ (∀ b a, a ∈ o → b ∉ f a) :=
bind_eq_none'
lemma bind_comm {α β γ} {f : α → β → option γ} (a : option α) (b : option β) :
a.bind (λx, b.bind (f x)) = b.bind (λy, a.bind (λx, f x y)) :=
by cases a; cases b; refl
lemma bind_assoc (x : option α) (f : α → option β) (g : β → option γ) :
(x.bind f).bind g = x.bind (λ y, (f y).bind g) := by cases x; refl
@[simp] theorem map_none {α β} {f : α → β} : f <$> none = none := rfl
@[simp] theorem map_some {α β} {a : α} {f : α → β} : f <$> some a = some (f a) := rfl
@[simp] theorem map_none' {f : α → β} : option.map f none = none := rfl
@[simp] theorem map_some' {a : α} {f : α → β} : option.map f (some a) = some (f a) := rfl
@[simp] theorem map_eq_some {α β} {x : option α} {f : α → β} {b : β} : f <$> x = some b ↔ ∃ a, x = some a ∧ f a = b :=
by cases x; simp
@[simp] theorem map_eq_some' {x : option α} {f : α → β} {b : β} : x.map f = some b ↔ ∃ a, x = some a ∧ f a = b :=
by cases x; simp
@[simp] theorem map_id' : option.map (@id α) = id := map_id
@[simp] theorem seq_some {α β} {a : α} {f : α → β} : some f <*> some a = some (f a) := rfl
@[simp] theorem some_orelse' (a : α) (x : option α) : (some a).orelse x = some a := rfl
@[simp] theorem some_orelse (a : α) (x : option α) : (some a <|> x) = some a := rfl
@[simp] theorem none_orelse' (x : option α) : none.orelse x = x :=
by cases x; refl
@[simp] theorem none_orelse (x : option α) : (none <|> x) = x := none_orelse' x
@[simp] theorem orelse_none' (x : option α) : x.orelse none = x :=
by cases x; refl
@[simp] theorem orelse_none (x : option α) : (x <|> none) = x := orelse_none' x
@[simp] theorem is_some_none : @is_some α none = ff := rfl
@[simp] theorem is_some_some {a : α} : is_some (some a) = tt := rfl
theorem is_some_iff_exists {x : option α} : is_some x ↔ ∃ a, x = some a :=
by cases x; simp [is_some]; exact ⟨_, rfl⟩
@[simp] theorem is_none_none : @is_none α none = tt := rfl
@[simp] theorem is_none_some {a : α} : is_none (some a) = ff := rfl
@[simp] theorem not_is_some {a : option α} : is_some a = ff ↔ a.is_none = tt :=
by cases a; simp
lemma eq_some_iff_get_eq {o : option α} {a : α} :
o = some a ↔ ∃ h : o.is_some, option.get h = a :=
by cases o; simp
lemma not_is_some_iff_eq_none {o : option α} : ¬o.is_some ↔ o = none :=
by cases o; simp
lemma ne_none_iff_is_some {o : option α} : o ≠ none ↔ o.is_some :=
by cases o; simp
lemma bex_ne_none {p : option α → Prop} :
(∃ x ≠ none, p x) ↔ ∃ x, p (some x) :=
⟨λ ⟨x, hx, hp⟩, ⟨get $ ne_none_iff_is_some.1 hx, by rwa [some_get]⟩,
λ ⟨x, hx⟩, ⟨some x, some_ne_none x, hx⟩⟩
lemma ball_ne_none {p : option α → Prop} :
(∀ x ≠ none, p x) ↔ ∀ x, p (some x) :=
⟨λ h x, h (some x) (some_ne_none x),
λ h x hx, by simpa only [some_get] using h (get $ ne_none_iff_is_some.1 hx)⟩
theorem iget_mem [inhabited α] : ∀ {o : option α}, is_some o → o.iget ∈ o
| (some a) _ := rfl
theorem iget_of_mem [inhabited α] {a : α} : ∀ {o : option α}, a ∈ o → o.iget = a
| _ rfl := rfl
@[simp] theorem guard_eq_some {p : α → Prop} [decidable_pred p] {a b : α} :
guard p a = some b ↔ a = b ∧ p a :=
by by_cases p a; simp [option.guard, h]; intro; contradiction
@[simp] theorem guard_eq_some' {p : Prop} [decidable p] :
∀ u, _root_.guard p = some u ↔ p
| () := by by_cases p; simp [guard, h, pure]; intro; contradiction
theorem lift_or_get_choice {f : α → α → α} (h : ∀ a b, f a b = a ∨ f a b = b) :
∀ o₁ o₂, lift_or_get f o₁ o₂ = o₁ ∨ lift_or_get f o₁ o₂ = o₂
| none none := or.inl rfl
| (some a) none := or.inl rfl
| none (some b) := or.inr rfl
| (some a) (some b) := by simpa [lift_or_get] using h a b
@[simp] lemma lift_or_get_none_left {f} {b : option α} : lift_or_get f none b = b :=
by cases b; refl
@[simp] lemma lift_or_get_none_right {f} {a : option α} : lift_or_get f a none = a :=
by cases a; refl
@[simp] lemma lift_or_get_some_some {f} {a b : α} :
lift_or_get f (some a) (some b) = f a b := rfl
/-- given an element of `a : option α`, a default element `b : β` and a function `α → β`, apply this
function to `a` if it comes from `α`, and return `b` otherwise. -/
def cases_on' : option α → β → (α → β) → β
| none n s := n
| (some a) n s := s a
end option
|
aa776786c03060c5c6b3df295c86a0f105ee97cd | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/order_functions.lean | a074aede2ea5c65b1d1403bebed1ad2f64d3499d | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,821 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.order
import Mathlib.order.lattice
import Mathlib.PostPort
universes u v
namespace Mathlib
/-!
# `max` and `min`
This file proves basic properties about maxima and minima on a `linear_order`.
## Tags
min, max
-/
-- translate from lattices to linear orders (sup → max, inf → min)
@[simp] theorem le_min_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : c ≤ min a b ↔ c ≤ a ∧ c ≤ b :=
le_inf_iff
@[simp] theorem max_le_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : max a b ≤ c ↔ a ≤ c ∧ b ≤ c :=
sup_le_iff
theorem max_le_max {α : Type u} [linear_order α] {a : α} {b : α} {c : α} {d : α} : a ≤ c → b ≤ d → max a b ≤ max c d :=
sup_le_sup
theorem min_le_min {α : Type u} [linear_order α] {a : α} {b : α} {c : α} {d : α} : a ≤ c → b ≤ d → min a b ≤ min c d :=
inf_le_inf
theorem le_max_left_of_le {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : a ≤ b → a ≤ max b c :=
le_sup_left_of_le
theorem le_max_right_of_le {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : a ≤ c → a ≤ max b c :=
le_sup_right_of_le
theorem min_le_left_of_le {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : a ≤ c → min a b ≤ c :=
inf_le_left_of_le
theorem min_le_right_of_le {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : b ≤ c → min a b ≤ c :=
inf_le_right_of_le
theorem max_min_distrib_left {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : max a (min b c) = min (max a b) (max a c) :=
sup_inf_left
theorem max_min_distrib_right {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : max (min a b) c = min (max a c) (max b c) :=
sup_inf_right
theorem min_max_distrib_left {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : min a (max b c) = max (min a b) (min a c) :=
inf_sup_left
theorem min_max_distrib_right {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : min (max a b) c = max (min a c) (min b c) :=
inf_sup_right
theorem min_le_max {α : Type u} [linear_order α] {a : α} {b : α} : min a b ≤ max a b :=
le_trans (min_le_left a b) (le_max_left a b)
@[simp] theorem min_eq_left_iff {α : Type u} [linear_order α] {a : α} {b : α} : min a b = a ↔ a ≤ b :=
inf_eq_left
@[simp] theorem min_eq_right_iff {α : Type u} [linear_order α] {a : α} {b : α} : min a b = b ↔ b ≤ a :=
inf_eq_right
@[simp] theorem max_eq_left_iff {α : Type u} [linear_order α] {a : α} {b : α} : max a b = a ↔ b ≤ a :=
sup_eq_left
@[simp] theorem max_eq_right_iff {α : Type u} [linear_order α] {a : α} {b : α} : max a b = b ↔ a ≤ b :=
sup_eq_right
/-- An instance asserting that `max a a = a` -/
protected instance max_idem {α : Type u} [linear_order α] : is_idempotent α max :=
Mathlib.sup_is_idempotent
/-- An instance asserting that `min a a = a` -/
protected instance min_idem {α : Type u} [linear_order α] : is_idempotent α min :=
Mathlib.inf_is_idempotent
@[simp] theorem max_lt_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : max a b < c ↔ a < c ∧ b < c :=
sup_lt_iff
@[simp] theorem lt_min_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : a < min b c ↔ a < b ∧ a < c :=
lt_inf_iff
@[simp] theorem lt_max_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : a < max b c ↔ a < b ∨ a < c :=
lt_sup_iff
@[simp] theorem min_lt_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : min a b < c ↔ a < c ∨ b < c :=
lt_max_iff
@[simp] theorem min_le_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : min a b ≤ c ↔ a ≤ c ∨ b ≤ c :=
inf_le_iff
@[simp] theorem le_max_iff {α : Type u} [linear_order α] {a : α} {b : α} {c : α} : a ≤ max b c ↔ a ≤ b ∨ a ≤ c :=
min_le_iff
theorem max_lt_max {α : Type u} [linear_order α] {a : α} {b : α} {c : α} {d : α} (h₁ : a < c) (h₂ : b < d) : max a b < max c d := sorry
theorem min_lt_min {α : Type u} [linear_order α] {a : α} {b : α} {c : α} {d : α} (h₁ : a < c) (h₂ : b < d) : min a b < min c d :=
max_lt_max h₁ h₂
theorem min_right_comm {α : Type u} [linear_order α] (a : α) (b : α) (c : α) : min (min a b) c = min (min a c) b :=
right_comm min min_comm min_assoc a b c
theorem max.left_comm {α : Type u} [linear_order α] (a : α) (b : α) (c : α) : max a (max b c) = max b (max a c) :=
left_comm max max_comm max_assoc a b c
theorem max.right_comm {α : Type u} [linear_order α] (a : α) (b : α) (c : α) : max (max a b) c = max (max a c) b :=
right_comm max max_comm max_assoc a b c
theorem monotone.map_max {α : Type u} {β : Type v} [linear_order α] [linear_order β] {f : α → β} {a : α} {b : α} (hf : monotone f) : f (max a b) = max (f a) (f b) := sorry
theorem monotone.map_min {α : Type u} {β : Type v} [linear_order α] [linear_order β] {f : α → β} {a : α} {b : α} (hf : monotone f) : f (min a b) = min (f a) (f b) :=
monotone.map_max (monotone.order_dual hf)
theorem min_choice {α : Type u} [linear_order α] (a : α) (b : α) : min a b = a ∨ min a b = b := sorry
theorem max_choice {α : Type u} [linear_order α] (a : α) (b : α) : max a b = a ∨ max a b = b :=
min_choice a b
theorem le_of_max_le_left {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h : max a b ≤ c) : a ≤ c :=
le_trans (le_max_left a b) h
theorem le_of_max_le_right {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h : max a b ≤ c) : b ≤ c :=
le_trans (le_max_right a b) h
|
a3b9b0debcd7d00b20deac741f5056373baa7836 | 5ca7b1b12d14c4742e29366312ba2c2ef8201b21 | /src/game/world10/level16.lean | 36b2c65204112557ef333a99c0d69b507cb7af25 | [
"Apache-2.0"
] | permissive | MatthiasHu/natural_number_game | 2e464482ef3001863430b0336133b6697b275ba3 | 2d764f72669ae30861f6a1057fce0257f3e466c4 | refs/heads/master | 1,609,719,110,419 | 1,576,345,737,000 | 1,576,345,737,000 | 240,296,314 | 0 | 0 | Apache-2.0 | 1,581,608,357,000 | 1,581,608,356,000 | null | UTF-8 | Lean | false | false | 817 | lean | import game.world10.level15 -- hide
namespace mynat -- hide
/-
# Inequality world.
## Level 16: equivalence of two definitions of `<`
Now let's go the other way.
-/
/- Lemma :
For all naturals $a$ and $b$,
$$
\operatorname{succ}(a)\le b
\implies
a\le b\land\lnot(b\le a).$$
-/
lemma lt_aux_two (a b : mynat) : succ a ≤ b → a ≤ b ∧ ¬ (b ≤ a) :=
begin [nat_num_game]
intro h,
cases h with c hc,
split,
use succ c,
rw hc,
rw succ_add,
rw add_succ,
refl,
intro h,
cases h with d hd,
rw hc at hd,
rw succ_eq_add_one at hd,
have h : a + 1 + c + d = a + (c + d + 1),
ring,
rw h at hd,
symmetry at hd,
have h2 := eq_zero_of_add_right_eq_self _ _ hd,
rw ←succ_eq_add_one at h2,
exact succ_ne_zero _ h2,
end
/-
Now for the payoff.
-/
end mynat -- hide
|
fb89410e8a75067acc50aea977361ff31d01947b | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/quot.lean | 787c48bce1c5824610d0e0be1ad97a171eaacf93 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 21,077 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import logic.relator
/-!
# Quotient types
This module extends the core library's treatment of quotient types (`init.data.quot`).
## Tags
quotient
-/
variables {α : Sort*} {β : Sort*}
namespace setoid
lemma ext {α : Sort*} :
∀{s t : setoid α}, (∀a b, @setoid.r α s a b ↔ @setoid.r α t a b) → s = t
| ⟨r, _⟩ ⟨p, _⟩ eq :=
have r = p, from funext $ assume a, funext $ assume b, propext $ eq a b,
by subst this
end setoid
namespace quot
variables {ra : α → α → Prop} {rb : β → β → Prop} {φ : quot ra → quot rb → Sort*}
local notation `⟦`:max a `⟧` := quot.mk _ a
instance [inhabited α] : inhabited (quot ra) := ⟨⟦default _⟧⟩
/-- Recursion on two `quotient` arguments `a` and `b`, result type depends on `⟦a⟧` and `⟦b⟧`. -/
protected def hrec_on₂ (qa : quot ra) (qb : quot rb) (f : Π a b, φ ⟦a⟧ ⟦b⟧)
(ca : ∀ {b a₁ a₂}, ra a₁ a₂ → f a₁ b == f a₂ b)
(cb : ∀ {a b₁ b₂}, rb b₁ b₂ → f a b₁ == f a b₂) : φ qa qb :=
quot.hrec_on qa (λ a, quot.hrec_on qb (f a) (λ b₁ b₂ pb, cb pb)) $ λ a₁ a₂ pa,
quot.induction_on qb $ λ b,
calc @quot.hrec_on _ _ (φ _) ⟦b⟧ (f a₁) (@cb _)
== f a₁ b : by simp
... == f a₂ b : ca pa
... == @quot.hrec_on _ _ (φ _) ⟦b⟧ (f a₂) (@cb _) : by simp
/-- Map a function `f : α → β` such that `ra x y` implies `rb (f x) (f y)`
to a map `quot ra → quot rb`. -/
protected def map (f : α → β) (h : (ra ⇒ rb) f f) : quot ra → quot rb :=
quot.lift (λ x, ⟦f x⟧) $ assume x y (h₁ : ra x y), quot.sound $ h h₁
/-- If `ra` is a subrelation of `ra'`, then we have a natural map `quot ra → quot ra'`. -/
protected def map_right {ra' : α → α → Prop} (h : ∀a₁ a₂, ra a₁ a₂ → ra' a₁ a₂) :
quot ra → quot ra' :=
quot.map id h
/-- weaken the relation of a quotient -/
def factor {α : Type*} (r s : α → α → Prop) (h : ∀ x y, r x y → s x y) :
quot r → quot s :=
quot.lift (quot.mk s) (λ x y rxy, quot.sound (h x y rxy))
lemma factor_mk_eq {α : Type*} (r s : α → α → Prop) (h : ∀ x y, r x y → s x y) :
factor r s h ∘ quot.mk _ = quot.mk _ := rfl
variables {γ : Sort*} {r : α → α → Prop} {s : β → β → Prop}
/-- **Alias** of `quot.lift_beta`. -/
lemma lift_mk (f : α → γ) (h : ∀ a₁ a₂, r a₁ a₂ → f a₁ = f a₂) (a : α) :
quot.lift f h (quot.mk r a) = f a := quot.lift_beta f h a
@[simp]
lemma lift_on_mk (a : α) (f : α → γ) (h : ∀ a₁ a₂, r a₁ a₂ → f a₁ = f a₂) :
quot.lift_on (quot.mk r a) f h = f a := rfl
/-- Descends a function `f : α → β → γ` to quotients of `α` and `β`. -/
attribute [reducible, elab_as_eliminator]
protected def lift₂
(f : α → β → γ)
(hr : ∀ a b₁ b₂, s b₁ b₂ → f a b₁ = f a b₂)
(hs : ∀ a₁ a₂ b, r a₁ a₂ → f a₁ b = f a₂ b)
(q₁ : quot r) (q₂ : quot s) : γ :=
quot.lift (λ a, quot.lift (f a) (hr a))
(λ a₁ a₂ ha, funext (λ q, quot.induction_on q (λ b, hs a₁ a₂ b ha)))
q₁ q₂
@[simp]
lemma lift₂_mk (f : α → β → γ)
(hr : ∀ a b₁ b₂, s b₁ b₂ → f a b₁ = f a b₂)
(hs : ∀ a₁ a₂ b, r a₁ a₂ → f a₁ b = f a₂ b) (a : α) (b : β) :
quot.lift₂ f hr hs (quot.mk r a) (quot.mk s b) = f a b := rfl
/-- Descends a function `f : α → β → γ` to quotients of `α` and `β` and applies it. -/
attribute [reducible, elab_as_eliminator]
protected def lift_on₂ (p : quot r) (q : quot s) (f : α → β → γ)
(hr : ∀ a b₁ b₂, s b₁ b₂ → f a b₁ = f a b₂)
(hs : ∀ a₁ a₂ b, r a₁ a₂ → f a₁ b = f a₂ b) : γ := quot.lift₂ f hr hs p q
@[simp]
lemma lift_on₂_mk (a : α) (b : β) (f : α → β → γ)
(hr : ∀ a b₁ b₂, s b₁ b₂ → f a b₁ = f a b₂)
(hs : ∀ a₁ a₂ b, r a₁ a₂ → f a₁ b = f a₂ b) :
quot.lift_on₂ (quot.mk r a) (quot.mk s b) f hr hs = f a b := rfl
variables {t : γ → γ → Prop}
/-- Descends a function `f : α → β → γ` to quotients of `α` and `β` wih values in a quotient of
`γ`. -/
protected def map₂ (f : α → β → γ)
(hr : ∀ a b₁ b₂, s b₁ b₂ → t (f a b₁) (f a b₂))
(hs : ∀ a₁ a₂ b, r a₁ a₂ → t (f a₁ b) (f a₂ b))
(q₁ : quot r) (q₂ : quot s) : quot t :=
quot.lift₂ (λ a b, quot.mk t $ f a b) (λ a b₁ b₂ hb, quot.sound (hr a b₁ b₂ hb))
(λ a₁ a₂ b ha, quot.sound (hs a₁ a₂ b ha)) q₁ q₂
@[simp]
lemma map₂_mk (f : α → β → γ)
(hr : ∀ a b₁ b₂, s b₁ b₂ → t (f a b₁) (f a b₂))
(hs : ∀ a₁ a₂ b, r a₁ a₂ → t (f a₁ b) (f a₂ b))
(a : α) (b : β) : quot.map₂ f hr hs (quot.mk r a) (quot.mk s b) = quot.mk t (f a b) := rfl
attribute [elab_as_eliminator]
protected lemma induction_on₂
{δ : quot r → quot s → Prop} (q₁ : quot r) (q₂ : quot s)
(h : ∀ a b, δ (quot.mk r a) (quot.mk s b)) : δ q₁ q₂ :=
quot.ind (λ a₁, quot.ind (λ a₂, h a₁ a₂) q₂) q₁
attribute [elab_as_eliminator]
protected lemma induction_on₃
{δ : quot r → quot s → quot t → Prop} (q₁ : quot r) (q₂ : quot s) (q₃ : quot t)
(h : ∀ a b c, δ (quot.mk r a) (quot.mk s b) (quot.mk t c)) : δ q₁ q₂ q₃ :=
quot.ind (λ a₁, quot.ind (λ a₂, quot.ind (λ a₃, h a₁ a₂ a₃) q₃) q₂) q₁
end quot
namespace quotient
variables [sa : setoid α] [sb : setoid β]
variables {φ : quotient sa → quotient sb → Sort*}
instance [inhabited α] : inhabited (quotient sa) := ⟨⟦default _⟧⟩
/-- Induction on two `quotient` arguments `a` and `b`, result type depends on `⟦a⟧` and `⟦b⟧`. -/
protected def hrec_on₂ (qa : quotient sa) (qb : quotient sb) (f : Π a b, φ ⟦a⟧ ⟦b⟧)
(c : ∀ a₁ b₁ a₂ b₂, a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ == f a₂ b₂) : φ qa qb :=
quot.hrec_on₂ qa qb f
(λ _ _ _ p, c _ _ _ _ p (setoid.refl _))
(λ _ _ _ p, c _ _ _ _ (setoid.refl _) p)
/-- Map a function `f : α → β` that sends equivalent elements to equivalent elements
to a function `quotient sa → quotient sb`. Useful to define unary operations on quotients. -/
protected def map (f : α → β) (h : ((≈) ⇒ (≈)) f f) : quotient sa → quotient sb :=
quot.map f h
@[simp] lemma map_mk (f : α → β) (h : ((≈) ⇒ (≈)) f f) (x : α) :
quotient.map f h (⟦x⟧ : quotient sa) = (⟦f x⟧ : quotient sb) :=
rfl
variables {γ : Sort*} [sc : setoid γ]
/-- Map a function `f : α → β → γ` that sends equivalent elements to equivalent elements
to a function `f : quotient sa → quotient sb → quotient sc`.
Useful to define binary operations on quotients. -/
protected def map₂ (f : α → β → γ) (h : ((≈) ⇒ (≈) ⇒ (≈)) f f) :
quotient sa → quotient sb → quotient sc :=
quotient.lift₂ (λ x y, ⟦f x y⟧) (λ x₁ y₁ x₂ y₂ h₁ h₂, quot.sound $ h h₁ h₂)
end quotient
lemma quot.eq {α : Type*} {r : α → α → Prop} {x y : α} :
quot.mk r x = quot.mk r y ↔ eqv_gen r x y :=
⟨quot.exact r, quot.eqv_gen_sound⟩
@[simp] theorem quotient.eq [r : setoid α] {x y : α} : ⟦x⟧ = ⟦y⟧ ↔ x ≈ y :=
⟨quotient.exact, quotient.sound⟩
theorem forall_quotient_iff {α : Type*} [r : setoid α] {p : quotient r → Prop} :
(∀a:quotient r, p a) ↔ (∀a:α, p ⟦a⟧) :=
⟨assume h x, h _, assume h a, a.induction_on h⟩
@[simp] lemma quotient.lift_mk [s : setoid α] (f : α → β) (h : ∀ (a b : α), a ≈ b → f a = f b)
(x : α) :
quotient.lift f h (quotient.mk x) = f x := rfl
@[simp] lemma quotient.lift_on_mk [s : setoid α] (f : α → β) (h : ∀ (a b : α), a ≈ b → f a = f b)
(x : α) :
quotient.lift_on (quotient.mk x) f h = f x := rfl
@[simp] theorem quotient.lift_on₂_mk {α : Sort*} {β : Sort*} [setoid α] (f : α → α → β)
(h : ∀ (a₁ a₂ b₁ b₂ : α), a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ = f b₁ b₂) (x y : α) :
quotient.lift_on₂ (quotient.mk x) (quotient.mk y) f h = f x y := rfl
/-- `quot.mk r` is a surjective function. -/
lemma surjective_quot_mk (r : α → α → Prop) : function.surjective (quot.mk r) :=
quot.exists_rep
/-- `quotient.mk` is a surjective function. -/
lemma surjective_quotient_mk (α : Sort*) [s : setoid α] :
function.surjective (quotient.mk : α → quotient s) :=
quot.exists_rep
/-- Choose an element of the equivalence class using the axiom of choice.
Sound but noncomputable. -/
noncomputable def quot.out {r : α → α → Prop} (q : quot r) : α :=
classical.some (quot.exists_rep q)
/-- Unwrap the VM representation of a quotient to obtain an element of the equivalence class.
Computable but unsound. -/
meta def quot.unquot {r : α → α → Prop} : quot r → α := unchecked_cast
@[simp] theorem quot.out_eq {r : α → α → Prop} (q : quot r) : quot.mk r q.out = q :=
classical.some_spec (quot.exists_rep q)
/-- Choose an element of the equivalence class using the axiom of choice.
Sound but noncomputable. -/
noncomputable def quotient.out [s : setoid α] : quotient s → α := quot.out
@[simp] theorem quotient.out_eq [s : setoid α] (q : quotient s) : ⟦q.out⟧ = q := q.out_eq
theorem quotient.mk_out [s : setoid α] (a : α) : ⟦a⟧.out ≈ a :=
quotient.exact (quotient.out_eq _)
instance pi_setoid {ι : Sort*} {α : ι → Sort*} [∀ i, setoid (α i)] : setoid (Π i, α i) :=
{ r := λ a b, ∀ i, a i ≈ b i,
iseqv := ⟨
λ a i, setoid.refl _,
λ a b h i, setoid.symm (h _),
λ a b c h₁ h₂ i, setoid.trans (h₁ _) (h₂ _)⟩ }
/-- Given a function `f : Π i, quotient (S i)`, returns the class of functions `Π i, α i` sending
each `i` to an element of the class `f i`. -/
noncomputable def quotient.choice {ι : Type*} {α : ι → Type*} [S : Π i, setoid (α i)]
(f : Π i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) :=
⟦λ i, (f i).out⟧
theorem quotient.choice_eq {ι : Type*} {α : ι → Type*} [Π i, setoid (α i)]
(f : Π i, α i) : quotient.choice (λ i, ⟦f i⟧) = ⟦f⟧ :=
quotient.sound $ λ i, quotient.mk_out _
lemma nonempty_quotient_iff (s : setoid α) : nonempty (quotient s) ↔ nonempty α :=
⟨assume ⟨a⟩, quotient.induction_on a nonempty.intro, assume ⟨a⟩, ⟨⟦a⟧⟩⟩
/-- `trunc α` is the quotient of `α` by the always-true relation. This
is related to the propositional truncation in HoTT, and is similar
in effect to `nonempty α`, but unlike `nonempty α`, `trunc α` is data,
so the VM representation is the same as `α`, and so this can be used to
maintain computability. -/
def {u} trunc (α : Sort u) : Sort u := @quot α (λ _ _, true)
theorem true_equivalence : @equivalence α (λ _ _, true) :=
⟨λ _, trivial, λ _ _ _, trivial, λ _ _ _ _ _, trivial⟩
namespace trunc
/-- Constructor for `trunc α` -/
def mk (a : α) : trunc α := quot.mk _ a
instance [inhabited α] : inhabited (trunc α) := ⟨mk (default _)⟩
/-- Any constant function lifts to a function out of the truncation -/
def lift (f : α → β) (c : ∀ a b : α, f a = f b) : trunc α → β :=
quot.lift f (λ a b _, c a b)
theorem ind {β : trunc α → Prop} : (∀ a : α, β (mk a)) → ∀ q : trunc α, β q := quot.ind
protected theorem lift_mk (f : α → β) (c) (a : α) : lift f c (mk a) = f a := rfl
/-- Lift a constant function on `q : trunc α`. -/
@[reducible, elab_as_eliminator]
protected def lift_on (q : trunc α) (f : α → β)
(c : ∀ a b : α, f a = f b) : β := lift f c q
@[elab_as_eliminator]
protected theorem induction_on {β : trunc α → Prop} (q : trunc α)
(h : ∀ a, β (mk a)) : β q := ind h q
theorem exists_rep (q : trunc α) : ∃ a : α, mk a = q := quot.exists_rep q
attribute [elab_as_eliminator]
protected theorem induction_on₂ {C : trunc α → trunc β → Prop} (q₁ : trunc α) (q₂ : trunc β)
(h : ∀ a b, C (mk a) (mk b)) : C q₁ q₂ :=
trunc.induction_on q₁ $ λ a₁, trunc.induction_on q₂ (h a₁)
protected theorem eq (a b : trunc α) : a = b :=
trunc.induction_on₂ a b (λ x y, quot.sound trivial)
instance : subsingleton (trunc α) := ⟨trunc.eq⟩
/-- The `bind` operator for the `trunc` monad. -/
def bind (q : trunc α) (f : α → trunc β) : trunc β :=
trunc.lift_on q f (λ a b, trunc.eq _ _)
/-- A function `f : α → β` defines a function `map f : trunc α → trunc β`. -/
def map (f : α → β) (q : trunc α) : trunc β := bind q (trunc.mk ∘ f)
instance : monad trunc :=
{ pure := @trunc.mk,
bind := @trunc.bind }
instance : is_lawful_monad trunc :=
{ id_map := λ α q, trunc.eq _ _,
pure_bind := λ α β q f, rfl,
bind_assoc := λ α β γ x f g, trunc.eq _ _ }
variable {C : trunc α → Sort*}
/-- Recursion/induction principle for `trunc`. -/
@[reducible, elab_as_eliminator]
protected def rec
(f : Π a, C (mk a)) (h : ∀ (a b : α), (eq.rec (f a) (trunc.eq (mk a) (mk b)) : C (mk b)) = f b)
(q : trunc α) : C q :=
quot.rec f (λ a b _, h a b) q
/-- A version of `trunc.rec` taking `q : trunc α` as the first argument. -/
@[reducible, elab_as_eliminator]
protected def rec_on (q : trunc α) (f : Π a, C (mk a))
(h : ∀ (a b : α), (eq.rec (f a) (trunc.eq (mk a) (mk b)) : C (mk b)) = f b) : C q :=
trunc.rec f h q
/-- A version of `trunc.rec_on` assuming the codomain is a `subsingleton`. -/
@[reducible, elab_as_eliminator]
protected def rec_on_subsingleton
[∀ a, subsingleton (C (mk a))] (q : trunc α) (f : Π a, C (mk a)) : C q :=
trunc.rec f (λ a b, subsingleton.elim _ (f b)) q
/-- Noncomputably extract a representative of `trunc α` (using the axiom of choice). -/
noncomputable def out : trunc α → α := quot.out
@[simp] theorem out_eq (q : trunc α) : mk q.out = q := trunc.eq _ _
end trunc
theorem nonempty_of_trunc (q : trunc α) : nonempty α :=
let ⟨a, _⟩ := q.exists_rep in ⟨a⟩
namespace quotient
variables {γ : Sort*} {φ : Sort*}
{s₁ : setoid α} {s₂ : setoid β} {s₃ : setoid γ}
/- Versions of quotient definitions and lemmas ending in `'` use unification instead
of typeclass inference for inferring the `setoid` argument. This is useful when there are
several different quotient relations on a type, for example quotient groups, rings and modules -/
/-- A version of `quotient.mk` taking `{s : setoid α}` as an implicit argument instead of an
instance argument. -/
protected def mk' (a : α) : quotient s₁ := quot.mk s₁.1 a
/-- `quotient.mk'` is a surjective function. -/
lemma surjective_quotient_mk' : function.surjective (quotient.mk' : α → quotient s₁) :=
quot.exists_rep
/-- A version of `quotient.lift_on` taking `{s : setoid α}` as an implicit argument instead of an
instance argument. -/
@[elab_as_eliminator, reducible]
protected def lift_on' (q : quotient s₁) (f : α → φ)
(h : ∀ a b, @setoid.r α s₁ a b → f a = f b) : φ := quotient.lift_on q f h
@[simp]
protected lemma lift_on'_mk' (f : α → φ) (h) (x : α) :
quotient.lift_on' (@quotient.mk' _ s₁ x) f h = f x := rfl
/-- A version of `quotient.lift_on₂` taking `{s₁ : setoid α} {s₂ : setoid β}` as implicit arguments
instead of instance arguments. -/
@[elab_as_eliminator, reducible]
protected def lift_on₂' (q₁ : quotient s₁) (q₂ : quotient s₂) (f : α → β → γ)
(h : ∀ a₁ a₂ b₁ b₂, @setoid.r α s₁ a₁ b₁ → @setoid.r β s₂ a₂ b₂ → f a₁ a₂ = f b₁ b₂) : γ :=
quotient.lift_on₂ q₁ q₂ f h
@[simp]
protected lemma lift_on₂'_mk' (f : α → β → γ) (h) (a : α) (b : β) :
quotient.lift_on₂' (@quotient.mk' _ s₁ a) (@quotient.mk' _ s₂ b) f h = f a b := rfl
/-- A version of `quotient.ind` taking `{s : setoid α}` as an implicit argument instead of an
instance argument. -/
@[elab_as_eliminator]
protected lemma ind' {p : quotient s₁ → Prop}
(h : ∀ a, p (quotient.mk' a)) (q : quotient s₁) : p q :=
quotient.ind h q
/-- A version of `quotient.ind₂` taking `{s₁ : setoid α} {s₂ : setoid β}` as implicit arguments
instead of instance arguments. -/
@[elab_as_eliminator]
protected lemma ind₂' {p : quotient s₁ → quotient s₂ → Prop}
(h : ∀ a₁ a₂, p (quotient.mk' a₁) (quotient.mk' a₂))
(q₁ : quotient s₁) (q₂ : quotient s₂) : p q₁ q₂ :=
quotient.ind₂ h q₁ q₂
/-- A version of `quotient.induction_on` taking `{s : setoid α}` as an implicit argument instead
of an instance argument. -/
@[elab_as_eliminator]
protected lemma induction_on' {p : quotient s₁ → Prop} (q : quotient s₁)
(h : ∀ a, p (quotient.mk' a)) : p q := quotient.induction_on q h
/-- A version of `quotient.induction_on₂` taking `{s₁ : setoid α} {s₂ : setoid β}` as implicit
arguments instead of instance arguments. -/
@[elab_as_eliminator]
protected lemma induction_on₂' {p : quotient s₁ → quotient s₂ → Prop} (q₁ : quotient s₁)
(q₂ : quotient s₂) (h : ∀ a₁ a₂, p (quotient.mk' a₁) (quotient.mk' a₂)) : p q₁ q₂ :=
quotient.induction_on₂ q₁ q₂ h
/-- A version of `quotient.induction_on₃` taking `{s₁ : setoid α} {s₂ : setoid β} {s₃ : setoid γ}`
as implicit arguments instead of instance arguments. -/
@[elab_as_eliminator]
protected lemma induction_on₃' {p : quotient s₁ → quotient s₂ → quotient s₃ → Prop}
(q₁ : quotient s₁) (q₂ : quotient s₂) (q₃ : quotient s₃)
(h : ∀ a₁ a₂ a₃, p (quotient.mk' a₁) (quotient.mk' a₂) (quotient.mk' a₃)) : p q₁ q₂ q₃ :=
quotient.induction_on₃ q₁ q₂ q₃ h
/-- A version of `quotient.rec_on_subsingleton` taking `{s₁ : setoid α}` as an implicit argument
instead of an instance argument. -/
@[elab_as_eliminator]
protected def rec_on_subsingleton' {φ : quotient s₁ → Sort*}
[h : ∀ a, subsingleton (φ ⟦a⟧)] (q : quotient s₁) (f : Π a, φ (quotient.mk' a)) : φ q :=
quotient.rec_on_subsingleton q f
/-- Recursion on a `quotient` argument `a`, result type depends on `⟦a⟧`. -/
protected def hrec_on' {φ : quotient s₁ → Sort*} (qa : quotient s₁) (f : Π a, φ (quotient.mk' a))
(c : ∀ a₁ a₂, a₁ ≈ a₂ → f a₁ == f a₂) : φ qa :=
quot.hrec_on qa f c
@[simp] lemma hrec_on'_mk' {φ : quotient s₁ → Sort*} (f : Π a, φ (quotient.mk' a))
(c : ∀ a₁ a₂, a₁ ≈ a₂ → f a₁ == f a₂) (x : α) :
(quotient.mk' x).hrec_on' f c = f x :=
rfl
/-- Recursion on two `quotient` arguments `a` and `b`, result type depends on `⟦a⟧` and `⟦b⟧`. -/
protected def hrec_on₂' {φ : quotient s₁ → quotient s₂ → Sort*} (qa : quotient s₁)
(qb : quotient s₂) (f : ∀ a b, φ (quotient.mk' a) (quotient.mk' b))
(c : ∀ a₁ b₁ a₂ b₂, a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ == f a₂ b₂) : φ qa qb :=
quotient.hrec_on₂ qa qb f c
@[simp] lemma hrec_on₂'_mk' {φ : quotient s₁ → quotient s₂ → Sort*}
(f : ∀ a b, φ (quotient.mk' a) (quotient.mk' b))
(c : ∀ a₁ b₁ a₂ b₂, a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ == f a₂ b₂) (x : α) (qb : quotient s₂) :
(quotient.mk' x).hrec_on₂' qb f c = qb.hrec_on' (f x) (λ b₁ b₂, c _ _ _ _ (setoid.refl _)) :=
rfl
/-- Map a function `f : α → β` that sends equivalent elements to equivalent elements
to a function `quotient sa → quotient sb`. Useful to define unary operations on quotients. -/
protected def map' (f : α → β) (h : ((≈) ⇒ (≈)) f f) :
quotient s₁ → quotient s₂ :=
quot.map f h
@[simp] lemma map'_mk' (f : α → β) (h) (x : α) :
(quotient.mk' x : quotient s₁).map' f h = (quotient.mk' (f x) : quotient s₂) :=
rfl
/-- A version of `quotient.map₂` using curly braces and unification. -/
protected def map₂' (f : α → β → γ) (h : ((≈) ⇒ (≈) ⇒ (≈)) f f) :
quotient s₁ → quotient s₂ → quotient s₃ :=
quotient.map₂ f h
@[simp] lemma map₂'_mk' (f : α → β → γ) (h) (x : α) :
(quotient.mk' x : quotient s₁).map₂' f h =
(quotient.map' (f x) (h (setoid.refl x)) : quotient s₂ → quotient s₃) :=
rfl
lemma exact' {a b : α} :
(quotient.mk' a : quotient s₁) = quotient.mk' b → @setoid.r _ s₁ a b :=
quotient.exact
lemma sound' {a b : α} : @setoid.r _ s₁ a b → @quotient.mk' α s₁ a = quotient.mk' b :=
quotient.sound
@[simp]
protected lemma eq' {a b : α} : @quotient.mk' α s₁ a = quotient.mk' b ↔ @setoid.r _ s₁ a b :=
quotient.eq
/-- A version of `quotient.out` taking `{s₁ : setoid α}` as an implicit argument instead of an
instance argument. -/
noncomputable def out' (a : quotient s₁) : α := quotient.out a
@[simp] theorem out_eq' (q : quotient s₁) : quotient.mk' q.out' = q := q.out_eq
theorem mk_out' (a : α) : @setoid.r α s₁ (quotient.mk' a : quotient s₁).out' a :=
quotient.exact (quotient.out_eq _)
end quotient
|
e8067147c16d800e7b776c89262830d058d381ea | 7b89826c26634aa18c0110f1634f73027851edfe | /natural-number-game/src/world02/level04.lean | c618ca0df37efdb24859d3ca74a630d35f07ab9f | [
"MIT"
] | permissive | marcofavorito/leanings | b7642344d8c9012a1cec74a804c5884297880c4d | 581b83be66ff4f8dd946fb6a1bb045d2ddf91076 | refs/heads/master | 1,672,310,991,244 | 1,603,031,766,000 | 1,603,031,766,000 | 279,163,004 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 386 | lean | import mynat.definition -- Imports the natural numbers.
import mynat.add -- imports addition.
import world02.level01 -- hide
import world02.level03 -- hide
namespace mynat -- hide
lemma add_comm (a b : mynat) : a + b = b + a :=
begin [nat_num_game]
induction b with d hd,
rw add_zero,
rw zero_add,
refl,
rw add_succ,
rw succ_add,
rw hd,
refl,
end
end mynat -- hide
|
1c931250600e481d92b44520a7fb0ad2caa7899a | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/tactic/apply_fun.lean | 4cf382bd722ae5c724d462c46b42ff227eb1e08a | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 2,768 | lean | /-
Copyright (c) 2019 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Keeley Hoek, Patrick Massot
-/
import tactic.monotonicity
namespace tactic
/-- Apply the function `f` given by `e : pexpr` to the local hypothesis `hyp`, which must either be
of the form `a = b` or `a ≤ b`, replacing the type of `hyp` with `f a = f b` or `f a ≤ f b`. If
`hyp` names an inequality then a new goal `monotone f` is created, unless the name of a proof of
this fact is passed as the optional argument `mono_lem`, or the `mono` tactic can prove it.
-/
meta def apply_fun_to_hyp (e : pexpr) (mono_lem : option pexpr) (hyp : expr) : tactic unit :=
do {
t ← infer_type hyp,
prf ← match t with
| `(%%l = %%r) := do
ltp ← infer_type l,
mv ← mk_mvar,
to_expr ``(congr_arg (%%e : %%ltp → %%mv) %%hyp)
| `(%%l ≤ %%r) := do
Hmono ← match mono_lem with
| some mono_lem :=
tactic.i_to_expr mono_lem
| none := do
n ← get_unused_name `mono,
to_expr ``(monotone %%e) >>= assert n,
do { intro_lst [`x, `y, `h], `[dsimp, mono], skip } <|> swap,
get_local n
end,
to_expr ``(%%Hmono %%hyp)
| _ := fail ("failed to apply " ++ to_string e ++ " at " ++ to_string hyp.local_pp_name)
end,
clear hyp,
hyp ← note hyp.local_pp_name none prf,
-- let's try to force β-reduction at `h`
try $ tactic.dsimp_hyp hyp simp_lemmas.mk [] { eta := false, beta := true }
}
namespace interactive
setup_tactic_parser
/--
Apply a function to some local assumptions which are either equalities
or inequalities. For instance, if the context contains `h : a = b` and
some function `f` then `apply_fun f at h` turns `h` into
`h : f a = f b`. When the assumption is an inequality `h : a ≤ b`, a side
goal `monotone f` is created, unless this condition is provided using
`apply_fun f at h using P` where `P : monotone f`, or the `mono` tactic
can prove it.
Typical usage is:
```lean
open function
example (X Y Z : Type) (f : X → Y) (g : Y → Z) (H : injective $ g ∘ f) :
injective f :=
begin
intros x x' h,
apply_fun g at h,
exact H h
end
```
-/
meta def apply_fun (q : parse texpr) (locs : parse location) (lem : parse (tk "using" *> texpr)?)
: tactic unit :=
match locs with
| (loc.ns l) := l.mmap' $ option.mmap $ λ h, get_local h >>= apply_fun_to_hyp q lem
| wildcard := local_context >>= list.mmap' (apply_fun_to_hyp q lem)
end
add_tactic_doc
{ name := "apply_fun",
category := doc_category.tactic,
decl_names := [`tactic.interactive.apply_fun],
tags := ["context management"] }
end interactive
end tactic
|
d8ecb026e58976400721966bf87d5c6372f5735a | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/mv_polynomial/rename.lean | 20ac09ef287f92fb4d135b1dc0ebae15e1d8ee41 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 9,087 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import data.mv_polynomial.basic
/-!
# Renaming variables of polynomials
This file establishes the `rename` operation on multivariate polynomials,
which modifies the set of variables.
## Main declarations
* `mv_polynomial.rename`
* `mv_polynomial.rename_equiv`
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ α : Type*` (indexing the variables)
+ `R S : Type*` `[comm_semiring R]` `[comm_semiring S]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `mv_polynomial σ R` which mathematicians might call `X^s`
+ `r : R` elements of the coefficient ring
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : mv_polynomial σ α`
-/
noncomputable theory
open_locale classical big_operators
open set function finsupp add_monoid_algebra
open_locale big_operators
variables {σ τ α R S : Type*} [comm_semiring R] [comm_semiring S]
namespace mv_polynomial
section rename
/-- Rename all the variables in a multivariable polynomial. -/
def rename (f : σ → τ) : mv_polynomial σ R →ₐ[R] mv_polynomial τ R :=
aeval (X ∘ f)
@[simp] lemma rename_C (f : σ → τ) (r : R) : rename f (C r) = C r :=
eval₂_C _ _ _
@[simp] lemma rename_X (f : σ → τ) (i : σ) : rename f (X i : mv_polynomial σ R) = X (f i) :=
eval₂_X _ _ _
lemma map_rename (f : R →+* S) (g : σ → τ) (p : mv_polynomial σ R) :
map f (rename g p) = rename g (map f p) :=
mv_polynomial.induction_on p
(λ a, by simp only [map_C, rename_C])
(λ p q hp hq, by simp only [hp, hq, alg_hom.map_add, ring_hom.map_add])
(λ p n hp, by simp only [hp, rename_X, map_X, ring_hom.map_mul, alg_hom.map_mul])
@[simp] lemma rename_rename (f : σ → τ) (g : τ → α) (p : mv_polynomial σ R) :
rename g (rename f p) = rename (g ∘ f) p :=
show rename g (eval₂ C (X ∘ f) p) = _,
begin
simp only [rename, aeval_eq_eval₂_hom],
simp [eval₂_comp_left _ C (X ∘ f) p, (∘), eval₂_C, eval_X],
apply eval₂_hom_congr _ rfl rfl,
ext1, simp only [comp_app, ring_hom.coe_comp, eval₂_hom_C],
end
@[simp] lemma rename_id (p : mv_polynomial σ R) : rename id p = p :=
eval₂_eta p
lemma rename_monomial (f : σ → τ) (d : σ →₀ ℕ) (r : R) :
rename f (monomial d r) = monomial (d.map_domain f) r :=
begin
rw [rename, aeval_monomial, monomial_eq, finsupp.prod_map_domain_index],
{ refl },
{ exact assume n, pow_zero _ },
{ exact assume n i₁ i₂, pow_add _ _ _ }
end
lemma rename_eq (f : σ → τ) (p : mv_polynomial σ R) :
rename f p = finsupp.map_domain (finsupp.map_domain f) p :=
begin
simp only [rename, aeval_def, eval₂, finsupp.map_domain, ring_hom.coe_of],
congr' with s a : 2,
rw [← monomial, monomial_eq, finsupp.prod_sum_index],
congr' with n i : 2,
rw [finsupp.prod_single_index],
exact pow_zero _,
exact assume a, pow_zero _,
exact assume a b c, pow_add _ _ _
end
lemma rename_injective (f : σ → τ) (hf : function.injective f) :
function.injective (rename f : mv_polynomial σ R → mv_polynomial τ R) :=
have (rename f : mv_polynomial σ R → mv_polynomial τ R) =
finsupp.map_domain (finsupp.map_domain f) := funext (rename_eq f),
begin
rw this,
exact finsupp.map_domain_injective (finsupp.map_domain_injective hf)
end
section
variables (R)
/-- `mv_polynomial.rename e` is an equivalence when `e` is. -/
@[simps apply]
def rename_equiv (f : σ ≃ τ) : mv_polynomial σ R ≃ₐ[R] mv_polynomial τ R :=
{ to_fun := rename f,
inv_fun := rename f.symm,
left_inv := λ p, by rw [rename_rename, f.symm_comp_self, rename_id],
right_inv := λ p, by rw [rename_rename, f.self_comp_symm, rename_id],
..rename f}
@[simp] lemma rename_equiv_refl :
rename_equiv R (equiv.refl σ) = alg_equiv.refl :=
alg_equiv.ext rename_id
@[simp] lemma rename_equiv_symm (f : σ ≃ τ) :
(rename_equiv R f).symm = rename_equiv R f.symm := rfl
@[simp] lemma rename_equiv_trans (e : σ ≃ τ) (f : τ ≃ α):
(rename_equiv R e).trans (rename_equiv R f) = rename_equiv R (e.trans f) :=
alg_equiv.ext (rename_rename e f)
end
section
variables (f : R →+* S) (k : σ → τ) (g : τ → S) (p : mv_polynomial σ R)
lemma eval₂_rename : (rename k p).eval₂ f g = p.eval₂ f (g ∘ k) :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma eval₂_hom_rename : eval₂_hom f g (rename k p) = eval₂_hom f (g ∘ k) p :=
eval₂_rename _ _ _ _
lemma aeval_rename [algebra R S] : aeval g (rename k p) = aeval (g ∘ k) p :=
eval₂_hom_rename _ _ _ _
lemma rename_eval₂ (g : τ → mv_polynomial σ R) :
rename k (p.eval₂ C (g ∘ k)) = (rename k p).eval₂ C (rename k ∘ g) :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma rename_prodmk_eval₂ (j : τ) (g : σ → mv_polynomial σ R) :
rename (prod.mk j) (p.eval₂ C g) = p.eval₂ C (λ x, rename (prod.mk j) (g x)) :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma eval₂_rename_prodmk (g : σ × τ → S) (i : σ) (p : mv_polynomial τ R) :
(rename (prod.mk i) p).eval₂ f g = eval₂ f (λ j, g (i, j)) p :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma eval_rename_prodmk (g : σ × τ → R) (i : σ) (p : mv_polynomial τ R) :
eval g (rename (prod.mk i) p) = eval (λ j, g (i, j)) p :=
eval₂_rename_prodmk (ring_hom.id _) _ _ _
end
/-- Every polynomial is a polynomial in finitely many variables. -/
theorem exists_finset_rename (p : mv_polynomial σ R) :
∃ (s : finset σ) (q : mv_polynomial {x // x ∈ s} R), p = rename coe q :=
begin
apply induction_on p,
{ intro r, exact ⟨∅, C r, by rw rename_C⟩ },
{ rintro p q ⟨s, p, rfl⟩ ⟨t, q, rfl⟩,
refine ⟨s ∪ t, ⟨_, _⟩⟩,
{ refine rename (subtype.map id _) p + rename (subtype.map id _) q;
simp only [id.def, true_or, or_true, finset.mem_union, forall_true_iff] {contextual := tt}, },
{ simp only [rename_rename, alg_hom.map_add], refl, }, },
{ rintro p n ⟨s, p, rfl⟩,
refine ⟨insert n s, ⟨_, _⟩⟩,
{ refine rename (subtype.map id _) p * X ⟨n, s.mem_insert_self n⟩,
simp only [id.def, or_true, finset.mem_insert, forall_true_iff] {contextual := tt}, },
{ simp only [rename_rename, rename_X, subtype.coe_mk, alg_hom.map_mul], refl, }, },
end
/-- Every polynomial is a polynomial in finitely many variables. -/
theorem exists_fin_rename (p : mv_polynomial σ R) :
∃ (n : ℕ) (f : fin n → σ) (hf : injective f) (q : mv_polynomial (fin n) R), p = rename f q :=
begin
obtain ⟨s, q, rfl⟩ := exists_finset_rename p,
let n := fintype.card {x // x ∈ s},
let e := fintype.equiv_fin {x // x ∈ s},
refine ⟨n, coe ∘ e.symm, subtype.val_injective.comp e.symm.injective, rename e q, _⟩,
rw [← rename_rename, rename_rename e],
simp only [function.comp, equiv.symm_apply_apply, rename_rename]
end
end rename
lemma eval₂_cast_comp (f : σ → τ) (c : ℤ →+* R) (g : τ → R) (p : mv_polynomial σ ℤ) :
eval₂ c (g ∘ f) p = eval₂ c g (rename f p) :=
mv_polynomial.induction_on p
(λ n, by simp only [eval₂_C, rename_C])
(λ p q hp hq, by simp only [hp, hq, rename, eval₂_add, alg_hom.map_add])
(λ p n hp, by simp only [hp, rename, aeval_def, eval₂_X, eval₂_mul])
section coeff
@[simp]
lemma coeff_rename_map_domain (f : σ → τ) (hf : injective f) (φ : mv_polynomial σ R) (d : σ →₀ ℕ) :
(rename f φ).coeff (d.map_domain f) = φ.coeff d :=
begin
apply induction_on' φ,
{ intros u r,
rw [rename_monomial, coeff_monomial, coeff_monomial],
simp only [(finsupp.map_domain_injective hf).eq_iff],
split_ifs; refl, },
{ intros, simp only [*, alg_hom.map_add, coeff_add], }
end
lemma coeff_rename_eq_zero (f : σ → τ) (φ : mv_polynomial σ R) (d : τ →₀ ℕ)
(h : ∀ u : σ →₀ ℕ, u.map_domain f = d → φ.coeff u = 0) :
(rename f φ).coeff d = 0 :=
begin
rw [rename_eq, ← not_mem_support_iff],
intro H,
replace H := map_domain_support H,
rw [finset.mem_image] at H,
obtain ⟨u, hu, rfl⟩ := H,
specialize h u rfl,
simp at h hu,
contradiction
end
lemma coeff_rename_ne_zero (f : σ → τ) (φ : mv_polynomial σ R) (d : τ →₀ ℕ)
(h : (rename f φ).coeff d ≠ 0) :
∃ u : σ →₀ ℕ, u.map_domain f = d ∧ φ.coeff u ≠ 0 :=
by { contrapose! h, apply coeff_rename_eq_zero _ _ _ h }
@[simp] lemma constant_coeff_rename {τ : Type*} (f : σ → τ) (φ : mv_polynomial σ R) :
constant_coeff (rename f φ) = constant_coeff φ :=
begin
apply φ.induction_on,
{ intro a, simp only [constant_coeff_C, rename_C]},
{ intros p q hp hq, simp only [hp, hq, ring_hom.map_add, alg_hom.map_add] },
{ intros p n hp, simp only [hp, rename_X, constant_coeff_X, ring_hom.map_mul, alg_hom.map_mul] }
end
end coeff
end mv_polynomial
|
09c2044a87538b9cfb4de510d9c451babe0f1651 | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /hott/algebra/ring.hlean | 3657b2aa525d503910cc7700989275774d09ae33 | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 18,455 | hlean | /-
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
Structures with multiplicative and additive components, including semirings, rings, and fields.
The development is modeled after Isabelle's library.
-/
import algebra.binary algebra.group
open eq eq.ops algebra
set_option class.force_new true
variable {A : Type}
namespace algebra
/- auxiliary classes -/
structure distrib [class] (A : Type) extends has_mul A, has_add A :=
(left_distrib : Πa b c, mul a (add b c) = add (mul a b) (mul a c))
(right_distrib : Πa b c, mul (add a b) c = add (mul a c) (mul b c))
theorem left_distrib [s : distrib A] (a b c : A) : a * (b + c) = a * b + a * c :=
!distrib.left_distrib
theorem right_distrib [s: distrib A] (a b c : A) : (a + b) * c = a * c + b * c :=
!distrib.right_distrib
structure mul_zero_class [class] (A : Type) extends has_mul A, has_zero A :=
(zero_mul : Πa, mul zero a = zero)
(mul_zero : Πa, mul a zero = zero)
theorem zero_mul [s : mul_zero_class A] (a : A) : 0 * a = 0 := !mul_zero_class.zero_mul
theorem mul_zero [s : mul_zero_class A] (a : A) : a * 0 = 0 := !mul_zero_class.mul_zero
structure zero_ne_one_class [class] (A : Type) extends has_zero A, has_one A :=
(zero_ne_one : zero ≠ one)
theorem zero_ne_one [s: zero_ne_one_class A] : 0 ≠ (1:A) := @zero_ne_one_class.zero_ne_one A s
/- semiring -/
structure semiring [class] (A : Type) extends add_comm_monoid A, monoid A, distrib A,
mul_zero_class A
section semiring
variables [s : semiring A] (a b c : A)
include s
theorem one_add_one_eq_two : 1 + 1 = (2:A) :=
by unfold bit0
theorem ne_zero_of_mul_ne_zero_right {a b : A} (H : a * b ≠ 0) : a ≠ 0 :=
suppose a = 0,
have a * b = 0, from this⁻¹ ▸ zero_mul b,
H this
theorem ne_zero_of_mul_ne_zero_left {a b : A} (H : a * b ≠ 0) : b ≠ 0 :=
suppose b = 0,
have a * b = 0, from this⁻¹ ▸ mul_zero a,
H this
theorem distrib_three_right (a b c d : A) : (a + b + c) * d = a * d + b * d + c * d :=
by rewrite *right_distrib
end semiring
/- comm semiring -/
structure comm_semiring [class] (A : Type) extends semiring A, comm_monoid A
-- TODO: we could also define a cancelative comm_semiring, i.e. satisfying
-- c ≠ 0 → c * a = c * b → a = b.
section comm_semiring
variables [s : comm_semiring A] (a b c : A)
include s
protected definition algebra.dvd (a b : A) : Type := Σc, b = a * c
definition comm_semiring_has_dvd [reducible] [instance] [priority algebra.prio] : has_dvd A :=
has_dvd.mk algebra.dvd
theorem dvd.intro {a b c : A} (H : a * c = b) : a ∣ b :=
sigma.mk _ H⁻¹
theorem dvd_of_mul_right_eq {a b c : A} (H : a * c = b) : a ∣ b := dvd.intro H
theorem dvd.intro_left {a b c : A} (H : c * a = b) : a ∣ b :=
dvd.intro (!mul.comm ▸ H)
theorem dvd_of_mul_left_eq {a b c : A} (H : c * a = b) : a ∣ b := dvd.intro_left H
theorem exists_eq_mul_right_of_dvd {a b : A} (H : a ∣ b) : Σc, b = a * c := H
theorem dvd.elim {P : Type} {a b : A} (H₁ : a ∣ b) (H₂ : Πc, b = a * c → P) : P :=
sigma.rec_on H₁ H₂
theorem exists_eq_mul_left_of_dvd {a b : A} (H : a ∣ b) : Σc, b = c * a :=
dvd.elim H (take c, assume H1 : b = a * c, sigma.mk c (H1 ⬝ !mul.comm))
theorem dvd.elim_left {P : Type} {a b : A} (H₁ : a ∣ b) (H₂ : Πc, b = c * a → P) : P :=
sigma.rec_on (exists_eq_mul_left_of_dvd H₁) (take c, assume H₃ : b = c * a, H₂ c H₃)
theorem dvd.refl : a ∣ a := dvd.intro !mul_one
theorem dvd.trans {a b c : A} (H₁ : a ∣ b) (H₂ : b ∣ c) : a ∣ c :=
dvd.elim H₁
(take d, assume H₃ : b = a * d,
dvd.elim H₂
(take e, assume H₄ : c = b * e,
dvd.intro
(show a * (d * e) = c, by rewrite [-mul.assoc, -H₃, H₄])))
theorem eq_zero_of_zero_dvd {a : A} (H : 0 ∣ a) : a = 0 :=
dvd.elim H (take c, assume H' : a = 0 * c, H' ⬝ !zero_mul)
theorem dvd_zero : a ∣ 0 := dvd.intro !mul_zero
theorem one_dvd : 1 ∣ a := dvd.intro !one_mul
theorem dvd_mul_right : a ∣ a * b := dvd.intro rfl
theorem dvd_mul_left : a ∣ b * a := mul.comm a b ▸ dvd_mul_right a b
theorem dvd_mul_of_dvd_left {a b : A} (H : a ∣ b) (c : A) : a ∣ b * c :=
dvd.elim H
(take d,
suppose b = a * d,
dvd.intro
(show a * (d * c) = b * c, from by rewrite [-mul.assoc]; substvars))
theorem dvd_mul_of_dvd_right {a b : A} (H : a ∣ b) (c : A) : a ∣ c * b :=
!mul.comm ▸ (dvd_mul_of_dvd_left H _)
theorem mul_dvd_mul {a b c d : A} (dvd_ab : a ∣ b) (dvd_cd : c ∣ d) : a * c ∣ b * d :=
dvd.elim dvd_ab
(take e, suppose b = a * e,
dvd.elim dvd_cd
(take f, suppose d = c * f,
dvd.intro
(show a * c * (e * f) = b * d,
by rewrite [mul.assoc, {c*_}mul.left_comm, -mul.assoc]; substvars)))
theorem dvd_of_mul_right_dvd {a b c : A} (H : a * b ∣ c) : a ∣ c :=
dvd.elim H (take d, assume Habdc : c = a * b * d, dvd.intro (!mul.assoc⁻¹ ⬝ Habdc⁻¹))
theorem dvd_of_mul_left_dvd {a b c : A} (H : a * b ∣ c) : b ∣ c :=
dvd_of_mul_right_dvd (mul.comm a b ▸ H)
theorem dvd_add {a b c : A} (Hab : a ∣ b) (Hac : a ∣ c) : a ∣ b + c :=
dvd.elim Hab
(take d, suppose b = a * d,
dvd.elim Hac
(take e, suppose c = a * e,
dvd.intro (show a * (d + e) = b + c,
by rewrite [left_distrib]; substvars)))
end comm_semiring
/- ring -/
structure ring [class] (A : Type) extends add_comm_group A, monoid A, distrib A
theorem ring.mul_zero [s : ring A] (a : A) : a * 0 = 0 :=
have a * 0 + 0 = a * 0 + a * 0, from calc
a * 0 + 0 = a * 0 : by rewrite add_zero
... = a * (0 + 0) : by rewrite add_zero
... = a * 0 + a * 0 : by rewrite {a*_}ring.left_distrib,
show a * 0 = 0, from (add.left_cancel this)⁻¹
theorem ring.zero_mul [s : ring A] (a : A) : 0 * a = 0 :=
have 0 * a + 0 = 0 * a + 0 * a, from calc
0 * a + 0 = 0 * a : by rewrite add_zero
... = (0 + 0) * a : by rewrite add_zero
... = 0 * a + 0 * a : by rewrite {_*a}ring.right_distrib,
show 0 * a = 0, from (add.left_cancel this)⁻¹
definition ring.to_semiring [trans_instance] [reducible] [s : ring A] : semiring A :=
⦃ semiring, s,
mul_zero := ring.mul_zero,
zero_mul := ring.zero_mul ⦄
section
variables [s : ring A] (a b c d e : A)
include s
theorem neg_mul_eq_neg_mul : -(a * b) = -a * b :=
neg_eq_of_add_eq_zero
begin
rewrite [-right_distrib, add.right_inv, zero_mul]
end
theorem neg_mul_eq_mul_neg : -(a * b) = a * -b :=
neg_eq_of_add_eq_zero
begin
rewrite [-left_distrib, add.right_inv, mul_zero]
end
theorem neg_mul_eq_neg_mul_symm : - a * b = - (a * b) := inverse !neg_mul_eq_neg_mul
theorem mul_neg_eq_neg_mul_symm : a * - b = - (a * b) := inverse !neg_mul_eq_mul_neg
theorem neg_mul_neg : -a * -b = a * b :=
calc
-a * -b = -(a * -b) : by rewrite -neg_mul_eq_neg_mul
... = - -(a * b) : by rewrite -neg_mul_eq_mul_neg
... = a * b : by rewrite neg_neg
theorem neg_mul_comm : -a * b = a * -b := !neg_mul_eq_neg_mul⁻¹ ⬝ !neg_mul_eq_mul_neg
theorem neg_eq_neg_one_mul : -a = -1 * a :=
calc
-a = -(1 * a) : by rewrite one_mul
... = -1 * a : by rewrite neg_mul_eq_neg_mul
theorem mul_sub_left_distrib : a * (b - c) = a * b - a * c :=
calc
a * (b - c) = a * b + a * -c : left_distrib
... = a * b + - (a * c) : by rewrite -neg_mul_eq_mul_neg
... = a * b - a * c : rfl
theorem mul_sub_right_distrib : (a - b) * c = a * c - b * c :=
calc
(a - b) * c = a * c + -b * c : right_distrib
... = a * c + - (b * c) : by rewrite neg_mul_eq_neg_mul
... = a * c - b * c : rfl
-- TODO: can calc mode be improved to make this easier?
-- TODO: there is also the other direction. It will be easier when we
-- have the simplifier.
theorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d ↔ (a - b) * e + c = d :=
calc
a * e + c = b * e + d ↔ a * e + c = d + b * e : by rewrite {b*e+_}add.comm
... ↔ a * e + c - b * e = d : iff.symm !sub_eq_iff_eq_add
... ↔ a * e - b * e + c = d : by rewrite sub_add_eq_add_sub
... ↔ (a - b) * e + c = d : by rewrite mul_sub_right_distrib
theorem mul_add_eq_mul_add_of_sub_mul_add_eq : (a - b) * e + c = d → a * e + c = b * e + d :=
iff.mpr !mul_add_eq_mul_add_iff_sub_mul_add_eq
theorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d → (a - b) * e + c = d :=
iff.mp !mul_add_eq_mul_add_iff_sub_mul_add_eq
theorem mul_neg_one_eq_neg : a * (-1) = -a :=
have a + a * -1 = 0, from calc
a + a * -1 = a * 1 + a * -1 : mul_one
... = a * (1 + -1) : left_distrib
... = a * 0 : add.right_inv
... = 0 : mul_zero,
symm (neg_eq_of_add_eq_zero this)
theorem ne_zero_prod_ne_zero_of_mul_ne_zero {a b : A} (H : a * b ≠ 0) : a ≠ 0 × b ≠ 0 :=
have a ≠ 0, from
(suppose a = 0,
have a * b = 0, by rewrite [this, zero_mul],
absurd this H),
have b ≠ 0, from
(suppose b = 0,
have a * b = 0, by rewrite [this, mul_zero],
absurd this H),
prod.mk `a ≠ 0` `b ≠ 0`
end
structure comm_ring [class] (A : Type) extends ring A, comm_semigroup A
definition comm_ring.to_comm_semiring [trans_instance] [reducible] [s : comm_ring A] : comm_semiring A :=
⦃ comm_semiring, s,
mul_zero := mul_zero,
zero_mul := zero_mul ⦄
section
variables [s : comm_ring A] (a b c d e : A)
include s
theorem mul_self_sub_mul_self_eq : a * a - b * b = (a + b) * (a - b) :=
begin
krewrite [left_distrib, *right_distrib, add.assoc],
rewrite [-{b*a + _}add.assoc,
-*neg_mul_eq_mul_neg, {a*b}mul.comm, add.right_inv, zero_add]
end
theorem mul_self_sub_one_eq : a * a - 1 = (a + 1) * (a - 1) :=
by rewrite [-mul_self_sub_mul_self_eq, mul_one]
theorem dvd_neg_iff_dvd : (a ∣ -b) ↔ (a ∣ b) :=
iff.intro
(suppose a ∣ -b,
dvd.elim this
(take c, suppose -b = a * c,
dvd.intro
(show a * -c = b,
by rewrite [-neg_mul_eq_mul_neg, -this, neg_neg])))
(suppose a ∣ b,
dvd.elim this
(take c, suppose b = a * c,
dvd.intro
(show a * -c = -b,
by rewrite [-neg_mul_eq_mul_neg, -this])))
theorem dvd_neg_of_dvd : (a ∣ b) → (a ∣ -b) :=
iff.mpr !dvd_neg_iff_dvd
theorem dvd_of_dvd_neg : (a ∣ -b) → (a ∣ b) :=
iff.mp !dvd_neg_iff_dvd
theorem neg_dvd_iff_dvd : (-a ∣ b) ↔ (a ∣ b) :=
iff.intro
(suppose -a ∣ b,
dvd.elim this
(take c, suppose b = -a * c,
dvd.intro
(show a * -c = b, by rewrite [-neg_mul_comm, this])))
(suppose a ∣ b,
dvd.elim this
(take c, suppose b = a * c,
dvd.intro
(show -a * -c = b, by rewrite [neg_mul_neg, this])))
theorem neg_dvd_of_dvd : (a ∣ b) → (-a ∣ b) :=
iff.mpr !neg_dvd_iff_dvd
theorem dvd_of_neg_dvd : (-a ∣ b) → (a ∣ b) :=
iff.mp !neg_dvd_iff_dvd
theorem dvd_sub (H₁ : (a ∣ b)) (H₂ : (a ∣ c)) : (a ∣ b - c) :=
dvd_add H₁ (!dvd_neg_of_dvd H₂)
end
/- integral domains -/
structure no_zero_divisors [class] (A : Type) extends has_mul A, has_zero A :=
(eq_zero_sum_eq_zero_of_mul_eq_zero : Πa b, mul a b = zero → a = zero ⊎ b = zero)
definition eq_zero_sum_eq_zero_of_mul_eq_zero {A : Type} [s : no_zero_divisors A] {a b : A}
(H : a * b = 0) :
a = 0 ⊎ b = 0 := !no_zero_divisors.eq_zero_sum_eq_zero_of_mul_eq_zero H
structure integral_domain [class] (A : Type) extends comm_ring A, no_zero_divisors A,
zero_ne_one_class A
section
variables [s : integral_domain A] (a b c d e : A)
include s
theorem mul_ne_zero {a b : A} (H1 : a ≠ 0) (H2 : b ≠ 0) : a * b ≠ 0 :=
suppose a * b = 0,
sum.elim (eq_zero_sum_eq_zero_of_mul_eq_zero this) (assume H3, H1 H3) (assume H4, H2 H4)
theorem eq_of_mul_eq_mul_right {a b c : A} (Ha : a ≠ 0) (H : b * a = c * a) : b = c :=
have b * a - c * a = 0, from iff.mp !eq_iff_sub_eq_zero H,
have (b - c) * a = 0, using this, by rewrite [mul_sub_right_distrib, this],
have b - c = 0, from sum_resolve_left (eq_zero_sum_eq_zero_of_mul_eq_zero this) Ha,
iff.elim_right !eq_iff_sub_eq_zero this
theorem eq_of_mul_eq_mul_left {a b c : A} (Ha : a ≠ 0) (H : a * b = a * c) : b = c :=
have a * b - a * c = 0, from iff.mp !eq_iff_sub_eq_zero H,
have a * (b - c) = 0, using this, by rewrite [mul_sub_left_distrib, this],
have b - c = 0, from sum_resolve_right (eq_zero_sum_eq_zero_of_mul_eq_zero this) Ha,
iff.elim_right !eq_iff_sub_eq_zero this
-- TODO: do we want the iff versions?
theorem eq_zero_of_mul_eq_self_right {a b : A} (H₁ : b ≠ 1) (H₂ : a * b = a) : a = 0 :=
have b - 1 ≠ 0, from
suppose b - 1 = 0, H₁ (!zero_add ▸ eq_add_of_sub_eq this),
have a * b - a = 0, by rewrite H₂; apply sub_self,
have a * (b - 1) = 0, by+ rewrite [mul_sub_left_distrib, mul_one]; apply this,
show a = 0, from sum_resolve_left (eq_zero_sum_eq_zero_of_mul_eq_zero this) `b - 1 ≠ 0`
theorem eq_zero_of_mul_eq_self_left {a b : A} (H₁ : b ≠ 1) (H₂ : b * a = a) : a = 0 :=
eq_zero_of_mul_eq_self_right H₁ (!mul.comm ▸ H₂)
theorem mul_self_eq_mul_self_iff (a b : A) : a * a = b * b ↔ a = b ⊎ a = -b :=
iff.intro
(suppose a * a = b * b,
have (a - b) * (a + b) = 0,
by rewrite [mul.comm, -mul_self_sub_mul_self_eq, this, sub_self],
assert a - b = 0 ⊎ a + b = 0, from !eq_zero_sum_eq_zero_of_mul_eq_zero this,
sum.elim this
(suppose a - b = 0, sum.inl (eq_of_sub_eq_zero this))
(suppose a + b = 0, sum.inr (eq_neg_of_add_eq_zero this)))
(suppose a = b ⊎ a = -b, sum.elim this
(suppose a = b, by rewrite this)
(suppose a = -b, by rewrite [this, neg_mul_neg]))
theorem mul_self_eq_one_iff (a : A) : a * a = 1 ↔ a = 1 ⊎ a = -1 :=
assert a * a = 1 * 1 ↔ a = 1 ⊎ a = -1, from mul_self_eq_mul_self_iff a 1,
by rewrite mul_one at this; exact this
-- TODO: c - b * c → c = 0 ⊎ b = 1 and variants
theorem dvd_of_mul_dvd_mul_left {a b c : A} (Ha : a ≠ 0) (Hdvd : (a * b ∣ a * c)) : (b ∣ c) :=
dvd.elim Hdvd
(take d,
suppose a * c = a * b * d,
have b * d = c, from eq_of_mul_eq_mul_left Ha (mul.assoc a b d ▸ this⁻¹),
dvd.intro this)
theorem dvd_of_mul_dvd_mul_right {a b c : A} (Ha : a ≠ 0) (Hdvd : (b * a ∣ c * a)) : (b ∣ c) :=
dvd.elim Hdvd
(take d,
suppose c * a = b * a * d,
have b * d * a = c * a, from by rewrite [mul.right_comm, -this],
have b * d = c, from eq_of_mul_eq_mul_right Ha this,
dvd.intro this)
end
namespace norm_num
theorem mul_zero [s : mul_zero_class A] (a : A) : a * zero = zero :=
by rewrite [↑zero, mul_zero]
theorem zero_mul [s : mul_zero_class A] (a : A) : zero * a = zero :=
by rewrite [↑zero, zero_mul]
theorem mul_one [s : monoid A] (a : A) : a * one = a :=
by rewrite [↑one, mul_one]
theorem mul_bit0 [s : distrib A] (a b : A) : a * (bit0 b) = bit0 (a * b) :=
by rewrite [↑bit0, left_distrib]
theorem mul_bit0_helper [s : distrib A] (a b t : A) (H : a * b = t) : a * (bit0 b) = bit0 t :=
by rewrite -H; apply mul_bit0
theorem mul_bit1 [s : semiring A] (a b : A) : a * (bit1 b) = bit0 (a * b) + a :=
by rewrite [↑bit1, ↑bit0, +left_distrib, ↑one, mul_one]
theorem mul_bit1_helper [s : semiring A] (a b s t : A) (Hs : a * b = s) (Ht : bit0 s + a = t) :
a * (bit1 b) = t :=
begin rewrite [-Ht, -Hs, mul_bit1] end
theorem subst_into_prod [s : has_mul A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)
(prt : tl * tr = t) :
l * r = t :=
by rewrite [prl, prr, prt]
theorem mk_cong (op : A → A) (a b : A) (H : a = b) : op a = op b :=
by congruence; exact H
theorem mk_eq (a : A) : a = a := rfl
theorem neg_add_neg_eq_of_add_add_eq_zero [s : add_comm_group A] (a b c : A) (H : c + a + b = 0) :
-a + -b = c :=
begin
apply add_neg_eq_of_eq_add,
apply neg_eq_of_add_eq_zero,
rewrite [add.comm, add.assoc, add.comm b, -add.assoc, H]
end
theorem neg_add_neg_helper [s : add_comm_group A] (a b c : A) (H : a + b = c) : -a + -b = -c :=
begin apply iff.mp !neg_eq_neg_iff_eq, rewrite [neg_add, *neg_neg, H] end
theorem neg_add_pos_eq_of_eq_add [s : add_comm_group A] (a b c : A) (H : b = c + a) : -a + b = c :=
begin apply neg_add_eq_of_eq_add, rewrite add.comm, exact H end
theorem neg_add_pos_helper1 [s : add_comm_group A] (a b c : A) (H : b + c = a) : -a + b = -c :=
begin apply neg_add_eq_of_eq_add, apply eq_add_neg_of_add_eq H end
theorem neg_add_pos_helper2 [s : add_comm_group A] (a b c : A) (H : a + c = b) : -a + b = c :=
begin apply neg_add_eq_of_eq_add, rewrite H end
theorem pos_add_neg_helper [s : add_comm_group A] (a b c : A) (H : b + a = c) : a + b = c :=
by rewrite [add.comm, H]
theorem sub_eq_add_neg_helper [s : add_comm_group A] (t₁ t₂ e w₁ w₂: A) (H₁ : t₁ = w₁)
(H₂ : t₂ = w₂) (H : w₁ + -w₂ = e) : t₁ - t₂ = e :=
by rewrite [sub_eq_add_neg, H₁, H₂, H]
theorem pos_add_pos_helper [s : add_comm_group A] (a b c h₁ h₂ : A) (H₁ : a = h₁) (H₂ : b = h₂)
(H : h₁ + h₂ = c) : a + b = c :=
by rewrite [H₁, H₂, H]
theorem subst_into_subtr [s : add_group A] (l r t : A) (prt : l + -r = t) : l - r = t :=
by rewrite [sub_eq_add_neg, prt]
theorem neg_neg_helper [s : add_group A] (a b : A) (H : a = -b) : -a = b :=
by rewrite [H, neg_neg]
theorem neg_mul_neg_helper [s : ring A] (a b c : A) (H : a * b = c) : (-a) * (-b) = c :=
begin rewrite [neg_mul_neg, H] end
theorem neg_mul_pos_helper [s : ring A] (a b c : A) (H : a * b = c) : (-a) * b = -c :=
begin rewrite [-neg_mul_eq_neg_mul, H] end
theorem pos_mul_neg_helper [s : ring A] (a b c : A) (H : a * b = c) : a * (-b) = -c :=
begin rewrite [-neg_mul_comm, -neg_mul_eq_neg_mul, H] end
end norm_num
end algebra
open algebra
attribute [simp]
zero_mul mul_zero
at simplifier.unit
attribute [simp]
neg_mul_eq_neg_mul_symm mul_neg_eq_neg_mul_symm
at simplifier.neg
attribute [simp]
left_distrib right_distrib
at simplifier.distrib
|
116089febde480be02457d5a7266da5368dec741 | d7189ea2ef694124821b033e533f18905b5e87ef | /galois/data/binary_tree.lean | 6b81c2792f6f04d3e97aa487ca15b0ed69321912 | [
"Apache-2.0"
] | permissive | digama0/lean-protocol-support | eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59 | cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda | refs/heads/master | 1,625,421,450,627 | 1,506,035,462,000 | 1,506,035,462,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,299 | lean | -- author: Ben Sherman
import .lptree
galois.list
galois.list.filter_some
namespace binary_tree
universes u v
/-- Binary trees *with* internal nodes
(which differs from both `ptree` and `lptree`)
In this formulation, every binary tree has at least
one item of type A in it.
-/
inductive tree (A : Type) : Type
| leaf (item : A) : tree
| node (item : A) (l r : tree) : tree
namespace tree
def height {A : Type} : tree A → ℕ
| (leaf x) := 0
| (node x l r) := max (height l) (height r) + 1
end tree
/-- Pick the item at the root of the tree -/
def root {A} : tree A -> A
| (tree.node x _ _) := x
| (tree.leaf x) := x
/-- Combine a left and right subtree into a single tree
with some function that determines the root of the
new tree from the roots of the subtrees
-/
def combine {A} (f : A -> A -> A) (l r : tree A)
: tree A := tree.node (f (root l) (root r)) l r
lemma combine_height {A} (f : A → A → A) (l r : tree A)
: (combine f l r).height = max l.height r.height + 1
:= rfl
namespace tree
/-- Enumerate the leaves of a binary tree from right to left
-/
def leaves {A} : tree A -> list A
| (node x l r) := leaves r ++ leaves l
| (leaf x) := [x]
lemma leaves_combine {A} (f)
(x y : tree A)
: (combine f x y).leaves
= y.leaves ++ x.leaves :=
begin
induction x,
{ simp [combine, leaves] },
{ reflexivity }
end
end tree
def tree_leaves_option {A} : option (tree A) -> list A
| none := []
| (some t) := t.leaves
/-- Given a tree specified by a list of its left subtrees and
its rightmost subtree, enumerate its leaves from right to left
-/
def left_subtrees_leaves {A}
(f : A -> A -> A)
: list (tree A) -> tree A -> list A
| [] x := x.leaves
| (y :: ys) x := left_subtrees_leaves ys (combine f y x)
/-- Enumerate the leaves of a tree specified by a list of
left subtrees (with an empty rightmost subtree)
in reverse order
-/
def left_subtrees_leaves' {A}
: list (tree A) -> list A
| [] := []
| (t :: ts) := t.leaves ++ left_subtrees_leaves' ts
lemma left_subtrees_leaves_same {A}
(f : A -> A -> A) (ts : list (tree A))
: ∀ t : tree A,
left_subtrees_leaves f ts t = t.leaves ++ left_subtrees_leaves' ts
:=
begin
induction ts; intros,
{ simp [left_subtrees_leaves],
simp [left_subtrees_leaves']
},
{ simp [left_subtrees_leaves'],
simp [left_subtrees_leaves],
rw ih_1,
rw tree.leaves_combine,
rw list.append_assoc
}
end
def tree_mem {A} (t : tree A) : tree A -> Prop
| (tree.node i l r) := t = tree.node i l r ∨ tree_mem l ∨ tree_mem r
| (tree.leaf i) := t = tree.leaf i
/-- This inductive predicate holds of a binary tree
if all of its internal nodes can be compute by applying
`f` to the roots of its left and right subtrees
-/
inductive internal_nodes_ok {A} (f : A -> A -> A) : tree A -> Prop
| leaf : forall x : A, internal_nodes_ok (tree.leaf x)
| node : forall x l r, internal_nodes_ok l -> internal_nodes_ok r
-> x = f (root l) (root r) -> internal_nodes_ok (tree.node x l r)
lemma internal_nodes_ok_combine {A} (f : A -> A -> A)
(x y : tree A)
(Hx : internal_nodes_ok f x)
(Hy : internal_nodes_ok f y)
: internal_nodes_ok f (combine f x y) :=
begin
unfold combine,
constructor, assumption, assumption, reflexivity
end
end binary_tree
|
82c2e8c1be92276942af6ababaf815dc1f545d0a | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/analysis/special_functions/trigonometric/angle.lean | 155d7bb5463880b41724aeaf1aea523071e64209 | [
"Apache-2.0"
] | permissive | ramonfmir/mathlib | c5dc8b33155473fab97c38bd3aa6723dc289beaa | 14c52e990c17f5a00c0cc9e09847af16fabbed25 | refs/heads/master | 1,661,979,343,526 | 1,660,830,384,000 | 1,660,830,384,000 | 182,072,989 | 0 | 0 | null | 1,555,585,876,000 | 1,555,585,876,000 | null | UTF-8 | Lean | false | false | 12,816 | lean | /-
Copyright (c) 2019 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne
-/
import analysis.special_functions.trigonometric.basic
import algebra.char_zero.quotient
import data.sign
/-!
# The type of angles
In this file we define `real.angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas
about trigonometric functions and angles.
-/
open_locale real
noncomputable theory
namespace real
/-- The type of angles -/
@[derive [add_comm_group, topological_space, topological_add_group]]
def angle : Type :=
ℝ ⧸ (add_subgroup.zmultiples (2 * π))
namespace angle
instance : inhabited angle := ⟨0⟩
instance : has_coe ℝ angle := ⟨quotient_add_group.mk' _⟩
@[continuity] lemma continuous_coe : continuous (coe : ℝ → angle) :=
continuous_quotient_mk
/-- Coercion `ℝ → angle` as an additive homomorphism. -/
def coe_hom : ℝ →+ angle := quotient_add_group.mk' _
@[simp] lemma coe_coe_hom : (coe_hom : ℝ → angle) = coe := rfl
/-- An induction principle to deduce results for `angle` from those for `ℝ`, used with
`induction θ using real.angle.induction_on`. -/
@[elab_as_eliminator]
protected lemma induction_on {p : angle → Prop} (θ : angle) (h : ∀ x : ℝ, p x) : p θ :=
quotient.induction_on' θ h
@[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl
@[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl
@[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl
@[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) := rfl
lemma coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = (n • ↑x : angle) := rfl
lemma coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = (z • ↑x : angle) := rfl
@[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : ℝ) (n : ℕ) :
↑((n : ℝ) * x) = n • (↑x : angle) :=
by simpa only [nsmul_eq_mul] using coe_hom.map_nsmul x n
@[simp, norm_cast] lemma coe_int_mul_eq_zsmul (x : ℝ) (n : ℤ) :
↑((n : ℝ) * x : ℝ) = n • (↑x : angle) :=
by simpa only [zsmul_eq_mul] using coe_hom.map_zsmul x n
lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k :=
by simp only [quotient_add_group.eq, add_subgroup.zmultiples_eq_closure,
add_subgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
@[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) :=
angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, int.cast_one, mul_one]⟩
@[simp] lemma neg_coe_pi : -(π : angle) = π :=
begin
rw [←coe_neg, angle_eq_iff_two_pi_dvd_sub],
use -1,
simp [two_mul, sub_eq_add_neg]
end
lemma sub_coe_pi_eq_add_coe_pi (θ : angle) : θ - π = θ + π :=
by rw [sub_eq_add_neg, neg_coe_pi]
@[simp] lemma two_nsmul_coe_pi : (2 : ℕ) • (π : angle) = 0 :=
by simp [←coe_nat_mul_eq_nsmul]
@[simp] lemma two_zsmul_coe_pi : (2 : ℤ) • (π : angle) = 0 :=
by simp [←coe_int_mul_eq_zsmul]
@[simp] lemma coe_pi_add_coe_pi : (π : real.angle) + π = 0 :=
by rw [←two_nsmul, two_nsmul_coe_pi]
lemma zsmul_eq_iff {ψ θ : angle} {z : ℤ} (hz : z ≠ 0) :
z • ψ = z • θ ↔ (∃ k : fin z.nat_abs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ)) :=
quotient_add_group.zmultiples_zsmul_eq_zsmul_iff hz
lemma nsmul_eq_iff {ψ θ : angle} {n : ℕ} (hz : n ≠ 0) :
n • ψ = n • θ ↔ (∃ k : fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ)) :=
quotient_add_group.zmultiples_nsmul_eq_nsmul_iff hz
lemma two_zsmul_eq_iff {ψ θ : angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ (ψ = θ ∨ ψ = θ + π) :=
by rw [zsmul_eq_iff two_ne_zero, int.nat_abs_bit0, int.nat_abs_one,
fin.exists_fin_two, fin.coe_zero, fin.coe_one, zero_smul, add_zero, one_smul,
int.cast_two, mul_div_cancel_left (_ : ℝ) two_ne_zero]
lemma two_nsmul_eq_iff {ψ θ : angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ (ψ = θ ∨ ψ = θ + π) :=
by simp_rw [←coe_nat_zsmul, int.coe_nat_bit0, int.coe_nat_one, two_zsmul_eq_iff]
lemma two_nsmul_eq_zero_iff {θ : angle} : (2 : ℕ) • θ = 0 ↔ (θ = 0 ∨ θ = π) :=
by convert two_nsmul_eq_iff; simp
lemma two_nsmul_ne_zero_iff {θ : angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π :=
by rw [←not_or_distrib, ←two_nsmul_eq_zero_iff]
lemma two_zsmul_eq_zero_iff {θ : angle} : (2 : ℤ) • θ = 0 ↔ (θ = 0 ∨ θ = π) :=
by simp_rw [two_zsmul, ←two_nsmul, two_nsmul_eq_zero_iff]
lemma two_zsmul_ne_zero_iff {θ : angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π :=
by rw [←not_or_distrib, ←two_zsmul_eq_zero_iff]
lemma eq_neg_self_iff {θ : angle} : θ = -θ ↔ θ = 0 ∨ θ = π :=
by rw [←add_eq_zero_iff_eq_neg, ←two_nsmul, two_nsmul_eq_zero_iff]
lemma ne_neg_self_iff {θ : angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π :=
by rw [←not_or_distrib, ←eq_neg_self_iff.not]
lemma neg_eq_self_iff {θ : angle} : -θ = θ ↔ θ = 0 ∨ θ = π :=
by rw [eq_comm, eq_neg_self_iff]
lemma neg_ne_self_iff {θ : angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π :=
by rw [←not_or_distrib, ←neg_eq_self_iff.not]
theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} :
cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ :=
begin
split,
{ intro Hcos,
rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,
eq_false_intro two_ne_zero, false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos,
rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩,
{ right,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), ← sub_eq_iff_eq_add] at hn,
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc,
coe_int_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] },
{ left,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), eq_sub_iff_add_eq] at hn,
rw [← hn, coe_add, mul_assoc,
coe_int_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] },
apply_instance, },
{ rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero],
rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul] }
end
theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} :
sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π :=
begin
split,
{ intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin,
cases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h h,
{ left, rw [coe_sub, coe_sub] at h, exact sub_right_inj.1 h },
right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub,
sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h,
exact h.symm },
{ rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul],
have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add,
mul_assoc, mul_comm π _, ←mul_assoc] at H,
rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,
mul_zero] }
end
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ :=
begin
cases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc hc, { exact hc },
cases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs },
rw [eq_neg_iff_add_eq_zero, hs] at hc,
obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := quotient_add_group.left_rel_apply.mp (quotient.exact' hc),
rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul,
mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add,
← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add,
int.cast_inj] at hn,
have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn,
rw [add_comm, int.add_mul_mod_self] at this,
exact absurd this one_ne_zero
end
/-- The sine of a `real.angle`. -/
def sin (θ : angle) : ℝ := sin_periodic.lift θ
@[simp] lemma sin_coe (x : ℝ) : sin (x : angle) = real.sin x :=
rfl
@[continuity] lemma continuous_sin : continuous sin :=
real.continuous_sin.quotient_lift_on' _
/-- The cosine of a `real.angle`. -/
def cos (θ : angle) : ℝ := cos_periodic.lift θ
@[simp] lemma cos_coe (x : ℝ) : cos (x : angle) = real.cos x :=
rfl
@[continuity] lemma continuous_cos : continuous cos :=
real.continuous_cos.quotient_lift_on' _
lemma cos_eq_real_cos_iff_eq_or_eq_neg {θ : angle} {ψ : ℝ} : cos θ = real.cos ψ ↔ θ = ψ ∨ θ = -ψ :=
begin
induction θ using real.angle.induction_on,
exact cos_eq_iff_coe_eq_or_eq_neg
end
lemma cos_eq_iff_eq_or_eq_neg {θ ψ : angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ :=
begin
induction ψ using real.angle.induction_on,
exact cos_eq_real_cos_iff_eq_or_eq_neg
end
lemma sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : angle} {ψ : ℝ} :
sin θ = real.sin ψ ↔ θ = ψ ∨ θ + ψ = π :=
begin
induction θ using real.angle.induction_on,
exact sin_eq_iff_coe_eq_or_add_eq_pi
end
lemma sin_eq_iff_eq_or_add_eq_pi {θ ψ : angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π :=
begin
induction ψ using real.angle.induction_on,
exact sin_eq_real_sin_iff_eq_or_add_eq_pi
end
@[simp] lemma sin_zero : sin (0 : angle) = 0 :=
by rw [←coe_zero, sin_coe, real.sin_zero]
@[simp] lemma sin_coe_pi : sin (π : angle) = 0 :=
by rw [sin_coe, real.sin_pi]
lemma sin_eq_zero_iff {θ : angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π :=
begin
nth_rewrite 0 ←sin_zero,
rw sin_eq_iff_eq_or_add_eq_pi,
simp
end
lemma sin_ne_zero_iff {θ : angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π :=
by rw [←not_or_distrib, ←sin_eq_zero_iff]
@[simp] lemma sin_neg (θ : angle) : sin (-θ) = -sin θ :=
begin
induction θ using real.angle.induction_on,
exact real.sin_neg _
end
lemma sin_antiperiodic : function.antiperiodic sin (π : angle) :=
begin
intro θ,
induction θ using real.angle.induction_on,
exact real.sin_antiperiodic θ
end
@[simp] lemma sin_add_pi (θ : angle) : sin (θ + π) = -sin θ :=
sin_antiperiodic θ
@[simp] lemma sin_sub_pi (θ : angle) : sin (θ - π) = -sin θ :=
sin_antiperiodic.sub_eq θ
@[simp] lemma cos_zero : cos (0 : angle) = 1 :=
by rw [←coe_zero, cos_coe, real.cos_zero]
@[simp] lemma cos_coe_pi : cos (π : angle) = -1 :=
by rw [cos_coe, real.cos_pi]
@[simp] lemma cos_neg (θ : angle) : cos (-θ) = cos θ :=
begin
induction θ using real.angle.induction_on,
exact real.cos_neg _
end
lemma cos_antiperiodic : function.antiperiodic cos (π : angle) :=
begin
intro θ,
induction θ using real.angle.induction_on,
exact real.cos_antiperiodic θ
end
@[simp] lemma cos_add_pi (θ : angle) : cos (θ + π) = -cos θ :=
cos_antiperiodic θ
@[simp] lemma cos_sub_pi (θ : angle) : cos (θ - π) = -cos θ :=
cos_antiperiodic.sub_eq θ
/-- The sign of a `real.angle` is `0` if the angle is `0` or `π`, `1` if the angle is strictly
between `0` and `π` and `-1` is the angle is strictly between `-π` and `0`. It is defined as the
sign of the sine of the angle. -/
def sign (θ : angle) : sign_type := sign (sin θ)
@[simp] lemma sign_zero : (0 : angle).sign = 0 :=
by rw [sign, sin_zero, sign_zero]
@[simp] lemma sign_coe_pi : (π : angle).sign = 0 :=
by rw [sign, sin_coe_pi, _root_.sign_zero]
@[simp] lemma sign_neg (θ : angle) : (-θ).sign = - θ.sign :=
by simp_rw [sign, sin_neg, left.sign_neg]
lemma sign_antiperiodic : function.antiperiodic sign (π : angle) :=
λ θ, by rw [sign, sign, sin_add_pi, left.sign_neg]
@[simp] lemma sign_add_pi (θ : angle) : (θ + π).sign = -θ.sign :=
sign_antiperiodic θ
@[simp] lemma sign_pi_add (θ : angle) : ((π : angle) + θ).sign = -θ.sign :=
by rw [add_comm, sign_add_pi]
@[simp] lemma sign_sub_pi (θ : angle) : (θ - π).sign = -θ.sign :=
sign_antiperiodic.sub_eq θ
@[simp] lemma sign_pi_sub (θ : angle) : ((π : angle) - θ).sign = θ.sign :=
by simp [sign_antiperiodic.sub_eq']
lemma sign_eq_zero_iff {θ : angle} : θ.sign = 0 ↔ θ = 0 ∨ θ = π :=
by rw [sign, sign_eq_zero_iff, sin_eq_zero_iff]
lemma sign_ne_zero_iff {θ : angle} : θ.sign ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π :=
by rw [←not_or_distrib, ←sign_eq_zero_iff]
end angle
end real
|
eed2a0a7734e788cced3dcc31a14731143674645 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /leanpkg/leanpkg/manifest.lean | 2836532cb1ba9a8db581d8736b00a5c5e06ad01a | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 3,661 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Gabriel Ebner
-/
import leanpkg.toml leanpkg.lean_version system.io
namespace leanpkg
inductive source
| path (dir_name : string) : source
| git (url rev : string) : source
namespace source
def from_toml (v : toml.value) : option source :=
(do toml.value.str dir_name ← v.lookup "path" | none,
return $ path dir_name) <|>
(do toml.value.str url ← v.lookup "git" | none,
toml.value.str rev ← v.lookup "rev" | none,
return $ git url rev)
def to_toml : ∀ (s : source), toml.value
| (path dir_name) := toml.value.table [("path", toml.value.str dir_name)]
| (git url rev) :=
toml.value.table [("git", toml.value.str url), ("rev", toml.value.str rev)]
/- TODO(Leo): has_to_string -/
instance : has_repr source :=
⟨λ s, repr s.to_toml⟩
end source
structure dependency :=
(name : string) (src : source)
namespace dependency
/- TODO(Leo): has_to_string -/
instance : has_repr dependency :=
⟨λ d, d.name ++ " = " ++ repr d.src⟩
end dependency
structure manifest :=
(name : string) (version : string)
(lean_version : string := lean_version_string)
(timeout : option nat := none)
(path : option string := none)
(dependencies : list dependency := [])
namespace manifest
def effective_path (m : manifest) : list string :=
[match m.path with some p := p | none := "." end]
def from_toml (t : toml.value) : option manifest := do
pkg ← t.lookup "package",
toml.value.str n ← pkg.lookup "name" | none,
toml.value.str ver ← pkg.lookup "version" | none,
lean_ver ←
match pkg.lookup "lean_version" with
| some (toml.value.str lean_ver) := some lean_ver
| none := some lean_version_string
| _ := none
end,
tm ← match pkg.lookup "timeout" with
| some (toml.value.nat timeout) := some (some timeout)
| none := some none
| _ := none
end,
path ← match pkg.lookup "path" with
| some (toml.value.str path) := some (some path)
| none := some none
| _ := none
end,
toml.value.table deps ← t.lookup "dependencies" <|> some (toml.value.table []) | none,
deps ← deps.mmap (λ ⟨n, src⟩, do src ← source.from_toml src,
return $ dependency.mk n src),
return { name := n, version := ver, lean_version := lean_ver,
path := path, dependencies := deps, timeout := tm }
def to_toml (d : manifest) : toml.value :=
let pkg := [("name", toml.value.str d.name), ("version", toml.value.str d.version),
("lean_version", toml.value.str d.lean_version)],
pkg := match d.path with some p := pkg ++ [("path", toml.value.str p)] | none := pkg end,
pkg := match d.timeout with some t := pkg ++ [("timeout", toml.value.nat t)] | none := pkg end,
deps := toml.value.table $ d.dependencies.map $ λ dep, (dep.name, dep.src.to_toml) in
toml.value.table [("package", toml.value.table pkg), ("dependencies", deps)]
instance : has_repr manifest :=
⟨λ d, repr d.to_toml⟩
def from_string (s : string) : option manifest :=
match parser.run_string toml.File s with
| sum.inr toml := from_toml toml
| sum.inl _ := none
end
def from_file [io.interface] (fn : string) : io manifest := do
cnts ← io.fs.read_file fn,
toml ←
(match parser.run toml.File cnts with
| sum.inl err :=
io.fail $ "toml parse error in " ++ fn ++ "\n\n" ++ err
| sum.inr res := return res
end),
some manifest ← return (from_toml toml)
| io.fail ("cannot read manifest from " ++ fn ++ "\n\n" ++ repr toml),
return manifest
end manifest
def leanpkg_toml_fn := "leanpkg.toml"
end leanpkg
|
60a4656590364e3c276d490a73dd86243308dc81 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /src/Init/Data/UInt.lean | 17b45bbe6f102647194ea90ff141d7ed8ba2f5bd | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,792 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.Fin.Basic
import Init.System.Platform
open Nat
@[extern "lean_uint8_of_nat"]
def UInt8.ofNat (n : @& Nat) : UInt8 := ⟨Fin.ofNat n⟩
abbrev Nat.toUInt8 := UInt8.ofNat
@[extern "lean_uint8_to_nat"]
def UInt8.toNat (n : UInt8) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def UInt8.add (a b : UInt8) : UInt8 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt8.sub (a b : UInt8) : UInt8 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt8.mul (a b : UInt8) : UInt8 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt8.div (a b : UInt8) : UInt8 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt8.mod (a b : UInt8) : UInt8 := ⟨a.val % b.val⟩
@[extern "lean_uint8_modn"]
def UInt8.modn (a : UInt8) (n : @& Nat) : UInt8 := ⟨a.val %ₙ n⟩
@[extern c inline "#1 & #2"]
def UInt8.land (a b : UInt8) : UInt8 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt8.lor (a b : UInt8) : UInt8 := ⟨Fin.lor a.val b.val⟩
def UInt8.lt (a b : UInt8) : Prop := a.val < b.val
def UInt8.le (a b : UInt8) : Prop := a.val ≤ b.val
instance : OfNat UInt8 := ⟨UInt8.ofNat⟩
instance : Add UInt8 := ⟨UInt8.add⟩
instance : Sub UInt8 := ⟨UInt8.sub⟩
instance : Mul UInt8 := ⟨UInt8.mul⟩
instance : Mod UInt8 := ⟨UInt8.mod⟩
instance : ModN UInt8 := ⟨UInt8.modn⟩
instance : Div UInt8 := ⟨UInt8.div⟩
instance : HasLess UInt8 := ⟨UInt8.lt⟩
instance : HasLessEq UInt8 := ⟨UInt8.le⟩
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def UInt8.decLt (a b : UInt8) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def UInt8.decLe (a b : UInt8) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : UInt8) : Decidable (a < b) := UInt8.decLt a b
instance (a b : UInt8) : Decidable (a ≤ b) := UInt8.decLe a b
@[extern "lean_uint16_of_nat"]
def UInt16.ofNat (n : @& Nat) : UInt16 := ⟨Fin.ofNat n⟩
abbrev Nat.toUInt16 := UInt16.ofNat
@[extern "lean_uint16_to_nat"]
def UInt16.toNat (n : UInt16) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def UInt16.add (a b : UInt16) : UInt16 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt16.sub (a b : UInt16) : UInt16 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt16.mul (a b : UInt16) : UInt16 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt16.div (a b : UInt16) : UInt16 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt16.mod (a b : UInt16) : UInt16 := ⟨a.val % b.val⟩
@[extern "lean_uint16_modn"]
def UInt16.modn (a : UInt16) (n : @& Nat) : UInt16 := ⟨a.val %ₙ n⟩
@[extern c inline "#1 & #2"]
def UInt16.land (a b : UInt16) : UInt16 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt16.lor (a b : UInt16) : UInt16 := ⟨Fin.lor a.val b.val⟩
def UInt16.lt (a b : UInt16) : Prop := a.val < b.val
def UInt16.le (a b : UInt16) : Prop := a.val ≤ b.val
instance : OfNat UInt16 := ⟨UInt16.ofNat⟩
instance : Add UInt16 := ⟨UInt16.add⟩
instance : Sub UInt16 := ⟨UInt16.sub⟩
instance : Mul UInt16 := ⟨UInt16.mul⟩
instance : Mod UInt16 := ⟨UInt16.mod⟩
instance : ModN UInt16 := ⟨UInt16.modn⟩
instance : Div UInt16 := ⟨UInt16.div⟩
instance : HasLess UInt16 := ⟨UInt16.lt⟩
instance : HasLessEq UInt16 := ⟨UInt16.le⟩
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def UInt16.decLt (a b : UInt16) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def UInt16.decLe (a b : UInt16) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : UInt16) : Decidable (a < b) := UInt16.decLt a b
instance (a b : UInt16) : Decidable (a ≤ b) := UInt16.decLe a b
@[extern "lean_uint32_of_nat"]
def UInt32.ofNat (n : @& Nat) : UInt32 := ⟨Fin.ofNat n⟩
@[extern "lean_uint32_of_nat"]
def UInt32.ofNat' (n : Nat) (h : n < UInt32.size) : UInt32 := ⟨⟨n, h⟩⟩
abbrev Nat.toUInt32 := UInt32.ofNat
@[extern c inline "#1 + #2"]
def UInt32.add (a b : UInt32) : UInt32 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt32.sub (a b : UInt32) : UInt32 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt32.mul (a b : UInt32) : UInt32 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt32.div (a b : UInt32) : UInt32 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt32.mod (a b : UInt32) : UInt32 := ⟨a.val % b.val⟩
@[extern "lean_uint32_modn"]
def UInt32.modn (a : UInt32) (n : @& Nat) : UInt32 := ⟨a.val %ₙ n⟩
@[extern c inline "#1 & #2"]
def UInt32.land (a b : UInt32) : UInt32 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt32.lor (a b : UInt32) : UInt32 := ⟨Fin.lor a.val b.val⟩
@[extern c inline "((uint8_t)#1)"]
def UInt32.toUInt8 (a : UInt32) : UInt8 := a.toNat.toUInt8
@[extern c inline "((uint16_t)#1)"]
def UInt32.toUInt16 (a : UInt32) : UInt16 := a.toNat.toUInt16
@[extern c inline "((uint32_t)#1)"]
def UInt8.toUInt32 (a : UInt8) : UInt32 := a.toNat.toUInt32
instance : OfNat UInt32 := ⟨UInt32.ofNat⟩
instance : Add UInt32 := ⟨UInt32.add⟩
instance : Sub UInt32 := ⟨UInt32.sub⟩
instance : Mul UInt32 := ⟨UInt32.mul⟩
instance : Mod UInt32 := ⟨UInt32.mod⟩
instance : ModN UInt32 := ⟨UInt32.modn⟩
instance : Div UInt32 := ⟨UInt32.div⟩
@[extern c inline "#1 << #2"]
constant UInt32.shiftLeft (a b : UInt32) : UInt32
@[extern c inline "#1 >> #2"]
constant UInt32.shiftRight (a b : UInt32) : UInt32
@[extern "lean_uint64_of_nat"]
def UInt64.ofNat (n : @& Nat) : UInt64 := ⟨Fin.ofNat n⟩
abbrev Nat.toUInt64 := UInt64.ofNat
@[extern "lean_uint64_to_nat"]
def UInt64.toNat (n : UInt64) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def UInt64.add (a b : UInt64) : UInt64 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt64.sub (a b : UInt64) : UInt64 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt64.mul (a b : UInt64) : UInt64 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt64.div (a b : UInt64) : UInt64 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt64.mod (a b : UInt64) : UInt64 := ⟨a.val % b.val⟩
@[extern "lean_uint64_modn"]
def UInt64.modn (a : UInt64) (n : @& Nat) : UInt64 := ⟨a.val %ₙ n⟩
@[extern c inline "#1 & #2"]
def UInt64.land (a b : UInt64) : UInt64 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt64.lor (a b : UInt64) : UInt64 := ⟨Fin.lor a.val b.val⟩
def UInt64.lt (a b : UInt64) : Prop := a.val < b.val
def UInt64.le (a b : UInt64) : Prop := a.val ≤ b.val
@[extern c inline "((uint8_t)#1)"]
def UInt64.toUInt8 (a : UInt64) : UInt8 := a.toNat.toUInt8
@[extern c inline "((uint16_t)#1)"]
def UInt64.toUInt16 (a : UInt64) : UInt16 := a.toNat.toUInt16
@[extern c inline "((uint32_t)#1)"]
def UInt64.toUInt32 (a : UInt64) : UInt32 := a.toNat.toUInt32
@[extern c inline "((uint64_t)#1)"]
def UInt32.toUInt64 (a : UInt32) : UInt64 := a.toNat.toUInt64
-- TODO(Leo): give reference implementation for shiftLeft and shiftRight, and define them for other UInt types
@[extern c inline "#1 << #2"]
constant UInt64.shiftLeft (a b : UInt64) : UInt64
@[extern c inline "#1 >> #2"]
constant UInt64.shiftRight (a b : UInt64) : UInt64
instance : OfNat UInt64 := ⟨UInt64.ofNat⟩
instance : Add UInt64 := ⟨UInt64.add⟩
instance : Sub UInt64 := ⟨UInt64.sub⟩
instance : Mul UInt64 := ⟨UInt64.mul⟩
instance : Mod UInt64 := ⟨UInt64.mod⟩
instance : ModN UInt64 := ⟨UInt64.modn⟩
instance : Div UInt64 := ⟨UInt64.div⟩
instance : HasLess UInt64 := ⟨UInt64.lt⟩
instance : HasLessEq UInt64 := ⟨UInt64.le⟩
@[extern c inline "(uint64_t)#1"]
def Bool.toUInt64 (b : Bool) : UInt64 := if b then 1 else 0
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def UInt64.decLt (a b : UInt64) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def UInt64.decLe (a b : UInt64) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : UInt64) : Decidable (a < b) := UInt64.decLt a b
instance (a b : UInt64) : Decidable (a ≤ b) := UInt64.decLe a b
theorem usizeSzGt0 : USize.size > 0 :=
Nat.posPowOfPos System.Platform.numBits (Nat.zeroLtSucc _)
@[extern "lean_usize_of_nat"]
def USize.ofNat (n : @& Nat) : USize := ⟨Fin.ofNat' n usizeSzGt0⟩
abbrev Nat.toUSize := USize.ofNat
@[extern "lean_usize_to_nat"]
def USize.toNat (n : USize) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def USize.add (a b : USize) : USize := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def USize.sub (a b : USize) : USize := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def USize.mul (a b : USize) : USize := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def USize.div (a b : USize) : USize := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def USize.mod (a b : USize) : USize := ⟨a.val % b.val⟩
@[extern "lean_usize_modn"]
def USize.modn (a : USize) (n : @& Nat) : USize := ⟨a.val %ₙ n⟩
@[extern c inline "#1 & #2"]
def USize.land (a b : USize) : USize := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def USize.lor (a b : USize) : USize := ⟨Fin.lor a.val b.val⟩
@[extern c inline "#1"]
def UInt32.toUSize (a : UInt32) : USize := a.toNat.toUSize
@[extern c inline "((size_t)#1)"]
def UInt64.toUSize (a : UInt64) : USize := a.toNat.toUSize
@[extern c inline "(uint32_t)#1"]
def USize.toUInt32 (a : USize) : UInt32 := a.toNat.toUInt32
-- TODO(Leo): give reference implementation for shiftLeft and shiftRight, and define them for other UInt types
@[extern c inline "#1 << #2"]
constant USize.shiftLeft (a b : USize) : USize
@[extern c inline "#1 >> #2"]
constant USize.shiftRight (a b : USize) : USize
def USize.lt (a b : USize) : Prop := a.val < b.val
def USize.le (a b : USize) : Prop := a.val ≤ b.val
instance : OfNat USize := ⟨USize.ofNat⟩
instance : Add USize := ⟨USize.add⟩
instance : Sub USize := ⟨USize.sub⟩
instance : Mul USize := ⟨USize.mul⟩
instance : Mod USize := ⟨USize.mod⟩
instance : ModN USize := ⟨USize.modn⟩
instance : Div USize := ⟨USize.div⟩
instance : HasLess USize := ⟨USize.lt⟩
instance : HasLessEq USize := ⟨USize.le⟩
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def USize.decLt (a b : USize) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def USize.decLe (a b : USize) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : USize) : Decidable (a < b) := USize.decLt a b
instance (a b : USize) : Decidable (a ≤ b) := USize.decLe a b
theorem USize.modnLt {m : Nat} : ∀ (u : USize), m > 0 → USize.toNat (u %ₙ m) < m
| ⟨u⟩, h => Fin.modnLt u h
|
d21d4a79e791cb329fb5b65de4b73ccbf1d9cfd8 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/data/matrix/notation.lean | 70104f3d7c05fcce74f355015c75c5b653d52af2 | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 16,167 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
Notation for vectors and matrices
-/
import data.fintype.card
import data.matrix.basic
import tactic.fin_cases
/-!
# Matrix and vector notation
This file defines notation for vectors and matrices. Given `a b c d : α`,
the notation allows us to write `![a, b, c, d] : fin 4 → α`.
Nesting vectors gives a matrix, so `![![a, b], ![c, d]] : matrix (fin 2) (fin 2) α`.
This file includes `simp` lemmas for applying operations in
`data.matrix.basic` to values built out of this notation.
## Main definitions
* `vec_empty` is the empty vector (or `0` by `n` matrix) `![]`
* `vec_cons` prepends an entry to a vector, so `![a, b]` is `vec_cons a (vec_cons b vec_empty)`
## Implementation notes
The `simp` lemmas require that one of the arguments is of the form `vec_cons _ _`.
This ensures `simp` works with entries only when (some) entries are already given.
In other words, this notation will only appear in the output of `simp` if it
already appears in the input.
## Notations
The main new notation is `![a, b]`, which gets expanded to `vec_cons a (vec_cons b vec_empty)`.
-/
namespace matrix
universe u
variables {α : Type u}
open_locale matrix
section matrix_notation
/-- `![]` is the vector with no entries. -/
def vec_empty : fin 0 → α :=
fin_zero_elim
/-- `vec_cons h t` prepends an entry `h` to a vector `t`.
The inverse functions are `vec_head` and `vec_tail`.
The notation `![a, b, ...]` expands to `vec_cons a (vec_cons b ...)`.
-/
def vec_cons {n : ℕ} (h : α) (t : fin n → α) : fin n.succ → α :=
fin.cons h t
notation `![` l:(foldr `, ` (h t, vec_cons h t) vec_empty `]`) := l
/-- `vec_head v` gives the first entry of the vector `v` -/
def vec_head {n : ℕ} (v : fin n.succ → α) : α :=
v 0
/-- `vec_tail v` gives a vector consisting of all entries of `v` except the first -/
def vec_tail {n : ℕ} (v : fin n.succ → α) : fin n → α :=
v ∘ fin.succ
end matrix_notation
variables {m n o : ℕ} {m' n' o' : Type*} [fintype m'] [fintype n'] [fintype o']
lemma empty_eq (v : fin 0 → α) : v = ![] :=
by { ext i, fin_cases i }
section val
@[simp] lemma cons_val_zero (x : α) (u : fin m → α) : vec_cons x u 0 = x := rfl
lemma cons_val_zero' (h : 0 < m.succ) (x : α) (u : fin m → α) :
vec_cons x u ⟨0, h⟩ = x :=
rfl
@[simp] lemma cons_val_succ (x : α) (u : fin m → α) (i : fin m) :
vec_cons x u i.succ = u i :=
by simp [vec_cons]
@[simp] lemma cons_val_succ' {i : ℕ} (h : i.succ < m.succ) (x : α) (u : fin m → α) :
vec_cons x u ⟨i.succ, h⟩ = u ⟨i, nat.lt_of_succ_lt_succ h⟩ :=
by simp only [vec_cons, fin.cons, fin.cases_succ']
@[simp] lemma head_cons (x : α) (u : fin m → α) :
vec_head (vec_cons x u) = x :=
rfl
@[simp] lemma tail_cons (x : α) (u : fin m → α) :
vec_tail (vec_cons x u) = u :=
by { ext, simp [vec_tail] }
@[simp] lemma empty_val' {n' : Type*} (j : n') :
(λ i, (![] : fin 0 → n' → α) i j) = ![] :=
empty_eq _
@[simp] lemma cons_val' (v : n' → α) (B : matrix (fin m) n' α) (i j) :
vec_cons v B i j = vec_cons (v j) (λ i, B i j) i :=
by { refine fin.cases _ _ i; simp }
@[simp] lemma head_val' (B : matrix (fin m.succ) n' α) (j : n') :
vec_head (λ i, B i j) = vec_head B j := rfl
@[simp] lemma tail_val' (B : matrix (fin m.succ) n' α) (j : n') :
vec_tail (λ i, B i j) = λ i, vec_tail B i j :=
by { ext, simp [vec_tail] }
@[simp] lemma cons_head_tail (u : fin m.succ → α) :
vec_cons (vec_head u) (vec_tail u) = u :=
fin.cons_self_tail _
@[simp] lemma range_cons (x : α) (u : fin n → α) :
set.range (vec_cons x u) = {x} ∪ set.range u :=
set.ext $ λ y, by simp [fin.exists_fin_succ, eq_comm]
@[simp] lemma range_empty (u : fin 0 → α) : set.range u = ∅ :=
set.range_eq_empty.2 $ λ ⟨k⟩, k.elim0
/-- `![a, b, ...] 1` is equal to `b`.
The simplifier needs a special lemma for length `≥ 2`, in addition to
`cons_val_succ`, because `1 : fin 1 = 0 : fin 1`.
-/
@[simp] lemma cons_val_one (x : α) (u : fin m.succ → α) :
vec_cons x u 1 = vec_head u :=
cons_val_succ x u 0
@[simp] lemma cons_val_fin_one (x : α) (u : fin 0 → α) (i : fin 1) :
vec_cons x u i = x :=
by { fin_cases i, refl }
/-! ### Numeral (`bit0` and `bit1`) indices
The following definitions and `simp` lemmas are to allow any
numeral-indexed element of a vector given with matrix notation to
be extracted by `simp` (even when the numeral is larger than the
number of elements in the vector, which is taken modulo that number
of elements by virtue of the semantics of `bit0` and `bit1` and of
addition on `fin n`).
-/
@[simp] lemma empty_append (v : fin n → α) : fin.append (zero_add _).symm ![] v = v :=
by { ext, simp [fin.append] }
@[simp] lemma cons_append (ho : o + 1 = m + 1 + n) (x : α) (u : fin m → α) (v : fin n → α) :
fin.append ho (vec_cons x u) v =
vec_cons x (fin.append (by rwa [add_assoc, add_comm 1, ←add_assoc,
add_right_cancel_iff] at ho) u v) :=
begin
ext i,
simp_rw [fin.append],
split_ifs with h,
{ rcases i with ⟨⟨⟩ | i, hi⟩,
{ simp },
{ simp only [nat.succ_eq_add_one, add_lt_add_iff_right, fin.coe_mk] at h,
simp [h] } },
{ rcases i with ⟨⟨⟩ | i, hi⟩,
{ simpa using h },
{ rw [not_lt, fin.coe_mk, nat.succ_eq_add_one, add_le_add_iff_right] at h,
simp [h] } }
end
/-- `vec_alt0 v` gives a vector with half the length of `v`, with
only alternate elements (even-numbered). -/
def vec_alt0 (hm : m = n + n) (v : fin m → α) (k : fin n) : α :=
v ⟨(k : ℕ) + k, hm.symm ▸ add_lt_add k.property k.property⟩
/-- `vec_alt1 v` gives a vector with half the length of `v`, with
only alternate elements (odd-numbered). -/
def vec_alt1 (hm : m = n + n) (v : fin m → α) (k : fin n) : α :=
v ⟨(k : ℕ) + k + 1, hm.symm ▸ nat.add_succ_lt_add k.property k.property⟩
lemma vec_alt0_append (v : fin n → α) : vec_alt0 rfl (fin.append rfl v v) = v ∘ bit0 :=
begin
ext i,
simp_rw [function.comp, bit0, vec_alt0, fin.append],
split_ifs with h; congr,
{ rw fin.coe_mk at h,
simp only [fin.ext_iff, fin.coe_add, fin.coe_mk],
exact (nat.mod_eq_of_lt h).symm },
{ rw [fin.coe_mk, not_lt] at h,
simp only [fin.ext_iff, fin.coe_add, fin.coe_mk, nat.mod_eq_sub_mod h],
refine (nat.mod_eq_of_lt _).symm,
rw nat.sub_lt_left_iff_lt_add h,
exact add_lt_add i.property i.property }
end
lemma vec_alt1_append (v : fin (n + 1) → α) : vec_alt1 rfl (fin.append rfl v v) = v ∘ bit1 :=
begin
ext i,
simp_rw [function.comp, vec_alt1, fin.append],
cases n,
{ simp, congr },
{ split_ifs with h; simp_rw [bit1, bit0]; congr,
{ rw fin.coe_mk at h,
simp only [fin.ext_iff, fin.coe_add, fin.coe_mk],
rw nat.mod_eq_of_lt (nat.lt_of_succ_lt h),
exact (nat.mod_eq_of_lt h).symm },
{ rw [fin.coe_mk, not_lt] at h,
simp only [fin.ext_iff, fin.coe_add, fin.coe_mk, nat.mod_add_mod, fin.coe_one,
nat.mod_eq_sub_mod h],
refine (nat.mod_eq_of_lt _).symm,
rw nat.sub_lt_left_iff_lt_add h,
exact nat.add_succ_lt_add i.property i.property } }
end
@[simp] lemma cons_vec_bit0_eq_alt0 (x : α) (u : fin n → α) (i : fin (n + 1)) :
vec_cons x u (bit0 i) = vec_alt0 rfl (fin.append rfl (vec_cons x u) (vec_cons x u)) i :=
by rw vec_alt0_append
@[simp] lemma cons_vec_bit1_eq_alt1 (x : α) (u : fin n → α) (i : fin (n + 1)) :
vec_cons x u (bit1 i) = vec_alt1 rfl (fin.append rfl (vec_cons x u) (vec_cons x u)) i :=
by rw vec_alt1_append
@[simp] lemma cons_vec_alt0 (h : m + 1 + 1 = (n + 1) + (n + 1)) (x y : α) (u : fin m → α) :
vec_alt0 h (vec_cons x (vec_cons y u)) = vec_cons x (vec_alt0
(by rwa [add_assoc n, add_comm 1, ←add_assoc, ←add_assoc, add_right_cancel_iff,
add_right_cancel_iff] at h) u) :=
begin
ext i,
simp_rw [vec_alt0],
rcases i with ⟨⟨⟩ | i, hi⟩,
{ refl },
{ simp [vec_alt0, nat.succ_add] }
end
-- Although proved by simp, extracting element 8 of a five-element
-- vector does not work by simp unless this lemma is present.
@[simp] lemma empty_vec_alt0 (α) {h} : vec_alt0 h (![] : fin 0 → α) = ![] :=
by simp
@[simp] lemma cons_vec_alt1 (h : m + 1 + 1 = (n + 1) + (n + 1)) (x y : α) (u : fin m → α) :
vec_alt1 h (vec_cons x (vec_cons y u)) = vec_cons y (vec_alt1
(by rwa [add_assoc n, add_comm 1, ←add_assoc, ←add_assoc, add_right_cancel_iff,
add_right_cancel_iff] at h) u) :=
begin
ext i,
simp_rw [vec_alt1],
rcases i with ⟨⟨⟩ | i, hi⟩,
{ refl },
{ simp [vec_alt1, nat.succ_add] }
end
-- Although proved by simp, extracting element 9 of a five-element
-- vector does not work by simp unless this lemma is present.
@[simp] lemma empty_vec_alt1 (α) {h} : vec_alt1 h (![] : fin 0 → α) = ![] :=
by simp
end val
section dot_product
variables [add_comm_monoid α] [has_mul α]
@[simp] lemma dot_product_empty (v w : fin 0 → α) :
dot_product v w = 0 := finset.sum_empty
@[simp] lemma cons_dot_product (x : α) (v : fin n → α) (w : fin n.succ → α) :
dot_product (vec_cons x v) w = x * vec_head w + dot_product v (vec_tail w) :=
by simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail]
@[simp] lemma dot_product_cons (v : fin n.succ → α) (x : α) (w : fin n → α) :
dot_product v (vec_cons x w) = vec_head v * x + dot_product (vec_tail v) w :=
by simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail]
end dot_product
section col_row
@[simp] lemma col_empty (v : fin 0 → α) : col v = vec_empty :=
empty_eq _
@[simp] lemma col_cons (x : α) (u : fin m → α) :
col (vec_cons x u) = vec_cons (λ _, x) (col u) :=
by { ext i j, refine fin.cases _ _ i; simp [vec_head, vec_tail] }
@[simp] lemma row_empty : row (vec_empty : fin 0 → α) = λ _, vec_empty :=
by { ext, refl }
@[simp] lemma row_cons (x : α) (u : fin m → α) :
row (vec_cons x u) = λ _, vec_cons x u :=
by { ext, refl }
end col_row
section transpose
@[simp] lemma transpose_empty_rows (A : matrix m' (fin 0) α) : Aᵀ = ![] := empty_eq _
@[simp] lemma transpose_empty_cols : (![] : matrix (fin 0) m' α)ᵀ = λ i, ![] :=
funext (λ i, empty_eq _)
@[simp] lemma cons_transpose (v : n' → α) (A : matrix (fin m) n' α) :
(vec_cons v A)ᵀ = λ i, vec_cons (v i) (Aᵀ i) :=
by { ext i j, refine fin.cases _ _ j; simp }
@[simp] lemma head_transpose (A : matrix m' (fin n.succ) α) : vec_head (Aᵀ) = vec_head ∘ A :=
rfl
@[simp] lemma tail_transpose (A : matrix m' (fin n.succ) α) : vec_tail (Aᵀ) = (vec_tail ∘ A)ᵀ :=
by { ext i j, refl }
end transpose
section mul
variables [semiring α]
@[simp] lemma empty_mul (A : matrix (fin 0) n' α) (B : matrix n' o' α) :
A ⬝ B = ![] :=
empty_eq _
@[simp] lemma empty_mul_empty (A : matrix m' (fin 0) α) (B : matrix (fin 0) o' α) :
A ⬝ B = 0 :=
rfl
@[simp] lemma mul_empty (A : matrix m' n' α) (B : matrix n' (fin 0) α) :
A ⬝ B = λ _, ![] :=
funext (λ _, empty_eq _)
lemma mul_val_succ (A : matrix (fin m.succ) n' α) (B : matrix n' o' α) (i : fin m) (j : o') :
(A ⬝ B) i.succ j = (vec_tail A ⬝ B) i j := rfl
@[simp] lemma cons_mul (v : n' → α) (A : matrix (fin m) n' α) (B : matrix n' o' α) :
vec_cons v A ⬝ B = vec_cons (vec_mul v B) (A ⬝ B) :=
by { ext i j, refine fin.cases _ _ i, { refl }, simp [mul_val_succ] }
end mul
section vec_mul
variables [semiring α]
@[simp] lemma empty_vec_mul (v : fin 0 → α) (B : matrix (fin 0) o' α) :
vec_mul v B = 0 :=
rfl
@[simp] lemma vec_mul_empty (v : n' → α) (B : matrix n' (fin 0) α) :
vec_mul v B = ![] :=
empty_eq _
@[simp] lemma cons_vec_mul (x : α) (v : fin n → α) (B : matrix (fin n.succ) o' α) :
vec_mul (vec_cons x v) B = x • (vec_head B) + vec_mul v (vec_tail B) :=
by { ext i, simp [vec_mul] }
@[simp] lemma vec_mul_cons (v : fin n.succ → α) (w : o' → α) (B : matrix (fin n) o' α) :
vec_mul v (vec_cons w B) = vec_head v • w + vec_mul (vec_tail v) B :=
by { ext i, simp [vec_mul] }
end vec_mul
section mul_vec
variables [semiring α]
@[simp] lemma empty_mul_vec (A : matrix (fin 0) n' α) (v : n' → α) :
mul_vec A v = ![] :=
empty_eq _
@[simp] lemma mul_vec_empty (A : matrix m' (fin 0) α) (v : fin 0 → α) :
mul_vec A v = 0 :=
rfl
@[simp] lemma cons_mul_vec (v : n' → α) (A : fin m → n' → α) (w : n' → α) :
mul_vec (vec_cons v A) w = vec_cons (dot_product v w) (mul_vec A w) :=
by { ext i, refine fin.cases _ _ i; simp [mul_vec] }
@[simp] lemma mul_vec_cons {α} [comm_semiring α] (A : m' → (fin n.succ) → α) (x : α) (v : fin n → α) :
mul_vec A (vec_cons x v) = (x • vec_head ∘ A) + mul_vec (vec_tail ∘ A) v :=
by { ext i, simp [mul_vec, mul_comm] }
end mul_vec
section vec_mul_vec
variables [semiring α]
@[simp] lemma empty_vec_mul_vec (v : fin 0 → α) (w : n' → α) :
vec_mul_vec v w = ![] :=
empty_eq _
@[simp] lemma vec_mul_vec_empty (v : m' → α) (w : fin 0 → α) :
vec_mul_vec v w = λ _, ![] :=
funext (λ i, empty_eq _)
@[simp] lemma cons_vec_mul_vec (x : α) (v : fin m → α) (w : n' → α) :
vec_mul_vec (vec_cons x v) w = vec_cons (x • w) (vec_mul_vec v w) :=
by { ext i, refine fin.cases _ _ i; simp [vec_mul_vec] }
@[simp] lemma vec_mul_vec_cons (v : m' → α) (x : α) (w : fin n → α) :
vec_mul_vec v (vec_cons x w) = λ i, v i • vec_cons x w :=
by { ext i j, simp [vec_mul_vec]}
end vec_mul_vec
section smul
variables [semiring α]
@[simp] lemma smul_empty (x : α) (v : fin 0 → α) : x • v = ![] := empty_eq _
@[simp] lemma smul_mat_empty {m' : Type*} (x : α) (A : fin 0 → m' → α) : x • A = ![] := empty_eq _
@[simp] lemma smul_cons (x y : α) (v : fin n → α) :
x • vec_cons y v = vec_cons (x * y) (x • v) :=
by { ext i, refine fin.cases _ _ i; simp }
@[simp] lemma smul_mat_cons (x : α) (v : n' → α) (A : matrix (fin m) n' α) :
x • vec_cons v A = vec_cons (x • v) (x • A) :=
by { ext i, refine fin.cases _ _ i; simp }
end smul
section add
variables [has_add α]
@[simp] lemma empty_add_empty (v w : fin 0 → α) : v + w = ![] := empty_eq _
@[simp] lemma cons_add (x : α) (v : fin n → α) (w : fin n.succ → α) :
vec_cons x v + w = vec_cons (x + vec_head w) (v + vec_tail w) :=
by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }
@[simp] lemma add_cons (v : fin n.succ → α) (y : α) (w : fin n → α) :
v + vec_cons y w = vec_cons (vec_head v + y) (vec_tail v + w) :=
by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }
end add
section zero
variables [has_zero α]
@[simp] lemma zero_empty : (0 : fin 0 → α) = ![] :=
empty_eq _
@[simp] lemma cons_zero_zero : vec_cons (0 : α) (0 : fin n → α) = 0 :=
by { ext i j, refine fin.cases _ _ i, { refl }, simp }
@[simp] lemma head_zero : vec_head (0 : fin n.succ → α) = 0 := rfl
@[simp] lemma tail_zero : vec_tail (0 : fin n.succ → α) = 0 := rfl
@[simp] lemma cons_eq_zero_iff {v : fin n → α} {x : α} :
vec_cons x v = 0 ↔ x = 0 ∧ v = 0 :=
⟨ λ h, ⟨ congr_fun h 0, by { convert congr_arg vec_tail h, simp } ⟩,
λ ⟨hx, hv⟩, by simp [hx, hv] ⟩
open_locale classical
lemma cons_nonzero_iff {v : fin n → α} {x : α} :
vec_cons x v ≠ 0 ↔ (x ≠ 0 ∨ v ≠ 0) :=
⟨ λ h, not_and_distrib.mp (h ∘ cons_eq_zero_iff.mpr),
λ h, mt cons_eq_zero_iff.mp (not_and_distrib.mpr h) ⟩
end zero
section neg
variables [has_neg α]
@[simp] lemma neg_empty (v : fin 0 → α) : -v = ![] := empty_eq _
@[simp] lemma neg_cons (x : α) (v : fin n → α) :
-(vec_cons x v) = vec_cons (-x) (-v) :=
by { ext i, refine fin.cases _ _ i; simp }
end neg
section minor
@[simp] lemma minor_empty (A : matrix m' n' α) (row : fin 0 → m') (col : o' → n') :
minor A row col = ![] :=
empty_eq _
@[simp] lemma minor_cons_row (A : matrix m' n' α) (i : m') (row : fin m → m') (col : o' → n') :
minor A (vec_cons i row) col = vec_cons (λ j, A i (col j)) (minor A row col) :=
by { ext i j, refine fin.cases _ _ i; simp [minor] }
end minor
end matrix
|
2cd272437052e715cf05e7f843a6f37850c765d9 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/smul_with_zero.lean | 6a0c9db627f0368f4d10a92b15b2d8c75081a01b | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 7,014 | lean | /-
Copyright (c) 2021 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import algebra.group_power.basic
import algebra.ring.opposite
import group_theory.group_action.opposite
import group_theory.group_action.prod
/-!
# Introduce `smul_with_zero`
In analogy with the usual monoid action on a Type `M`, we introduce an action of a
`monoid_with_zero` on a Type with `0`.
In particular, for Types `R` and `M`, both containing `0`, we define `smul_with_zero R M` to
be the typeclass where the products `r • 0` and `0 • m` vanish for all `r : R` and all `m : M`.
Moreover, in the case in which `R` is a `monoid_with_zero`, we introduce the typeclass
`mul_action_with_zero R M`, mimicking group actions and having an absorbing `0` in `R`.
Thus, the action is required to be compatible with
* the unit of the monoid, acting as the identity;
* the zero of the monoid_with_zero, acting as zero;
* associativity of the monoid.
We also add an `instance`:
* any `monoid_with_zero` has a `mul_action_with_zero R R` acting on itself.
## Main declarations
* `smul_monoid_with_zero_hom`: Scalar multiplication bundled as a morphism of monoids with zero.
-/
variables {R R' M M' : Type*}
section has_zero
variables (R M)
/-- `smul_with_zero` is a class consisting of a Type `R` with `0 ∈ R` and a scalar multiplication
of `R` on a Type `M` with `0`, such that the equality `r • m = 0` holds if at least one among `r`
or `m` equals `0`. -/
class smul_with_zero [has_zero R] [has_zero M] extends smul_zero_class R M :=
(zero_smul : ∀ m : M, (0 : R) • m = 0)
instance mul_zero_class.to_smul_with_zero [mul_zero_class R] : smul_with_zero R R :=
{ smul := (*),
smul_zero := mul_zero,
zero_smul := zero_mul }
/-- Like `mul_zero_class.to_smul_with_zero`, but multiplies on the right. -/
instance mul_zero_class.to_opposite_smul_with_zero [mul_zero_class R] : smul_with_zero Rᵐᵒᵖ R :=
{ smul := (•),
smul_zero := λ r, zero_mul _,
zero_smul := mul_zero }
variables (R) {M} [has_zero R] [has_zero M] [smul_with_zero R M]
@[simp] lemma zero_smul (m : M) : (0 : R) • m = 0 := smul_with_zero.zero_smul m
variables {R M} [has_zero R'] [has_zero M'] [has_smul R M']
/-- Pullback a `smul_with_zero` structure along an injective zero-preserving homomorphism.
See note [reducible non-instances]. -/
@[reducible]
protected def function.injective.smul_with_zero
(f : zero_hom M' M) (hf : function.injective f) (smul : ∀ (a : R) b, f (a • b) = a • f b) :
smul_with_zero R M' :=
{ smul := (•),
zero_smul := λ a, hf $ by simp [smul],
smul_zero := λ a, hf $ by simp [smul]}
/-- Pushforward a `smul_with_zero` structure along a surjective zero-preserving homomorphism.
See note [reducible non-instances]. -/
@[reducible]
protected def function.surjective.smul_with_zero
(f : zero_hom M M') (hf : function.surjective f) (smul : ∀ (a : R) b, f (a • b) = a • f b) :
smul_with_zero R M' :=
{ smul := (•),
zero_smul := λ m, by { rcases hf m with ⟨x, rfl⟩, simp [←smul] },
smul_zero := λ c, by simp only [← f.map_zero, ← smul, smul_zero] }
variables (M)
/-- Compose a `smul_with_zero` with a `zero_hom`, with action `f r' • m` -/
def smul_with_zero.comp_hom (f : zero_hom R' R) : smul_with_zero R' M :=
{ smul := (•) ∘ f,
smul_zero := λ m, by simp,
zero_smul := λ m, by simp }
end has_zero
instance add_monoid.nat_smul_with_zero [add_monoid M] : smul_with_zero ℕ M :=
{ smul_zero := nsmul_zero,
zero_smul := zero_nsmul }
instance add_group.int_smul_with_zero [add_group M] : smul_with_zero ℤ M :=
{ smul_zero := zsmul_zero,
zero_smul := zero_zsmul }
section monoid_with_zero
variables [monoid_with_zero R] [monoid_with_zero R'] [has_zero M]
variables (R M)
/-- An action of a monoid with zero `R` on a Type `M`, also with `0`, extends `mul_action` and
is compatible with `0` (both in `R` and in `M`), with `1 ∈ R`, and with associativity of
multiplication on the monoid `M`. -/
class mul_action_with_zero extends mul_action R M :=
-- these fields are copied from `smul_with_zero`, as `extends` behaves poorly
(smul_zero : ∀ r : R, r • (0 : M) = 0)
(zero_smul : ∀ m : M, (0 : R) • m = 0)
@[priority 100] -- see Note [lower instance priority]
instance mul_action_with_zero.to_smul_with_zero [m : mul_action_with_zero R M] :
smul_with_zero R M :=
{..m}
/-- See also `semiring.to_module` -/
instance monoid_with_zero.to_mul_action_with_zero : mul_action_with_zero R R :=
{ ..mul_zero_class.to_smul_with_zero R,
..monoid.to_mul_action R }
/-- Like `monoid_with_zero.to_mul_action_with_zero`, but multiplies on the right. See also
`semiring.to_opposite_module` -/
instance monoid_with_zero.to_opposite_mul_action_with_zero : mul_action_with_zero Rᵐᵒᵖ R :=
{ ..mul_zero_class.to_opposite_smul_with_zero R,
..monoid.to_opposite_mul_action R }
variables {R M} [mul_action_with_zero R M] [has_zero M'] [has_smul R M']
/-- Pullback a `mul_action_with_zero` structure along an injective zero-preserving homomorphism.
See note [reducible non-instances]. -/
@[reducible]
protected def function.injective.mul_action_with_zero
(f : zero_hom M' M) (hf : function.injective f) (smul : ∀ (a : R) b, f (a • b) = a • f b) :
mul_action_with_zero R M' :=
{ ..hf.mul_action f smul, ..hf.smul_with_zero f smul }
/-- Pushforward a `mul_action_with_zero` structure along a surjective zero-preserving homomorphism.
See note [reducible non-instances]. -/
@[reducible]
protected def function.surjective.mul_action_with_zero
(f : zero_hom M M') (hf : function.surjective f) (smul : ∀ (a : R) b, f (a • b) = a • f b) :
mul_action_with_zero R M' :=
{ ..hf.mul_action f smul, ..hf.smul_with_zero f smul }
variables (M)
/-- Compose a `mul_action_with_zero` with a `monoid_with_zero_hom`, with action `f r' • m` -/
def mul_action_with_zero.comp_hom (f : R' →*₀ R) : mul_action_with_zero R' M :=
{ smul := (•) ∘ f,
mul_smul := λ r s m, by simp [mul_smul],
one_smul := λ m, by simp,
.. smul_with_zero.comp_hom M f.to_zero_hom}
end monoid_with_zero
section group_with_zero
variables {α β : Type*} [group_with_zero α] [group_with_zero β] [mul_action_with_zero α β]
lemma smul_inv₀ [smul_comm_class α β β] [is_scalar_tower α β β] (c : α) (x : β) :
(c • x)⁻¹ = c⁻¹ • x⁻¹ :=
begin
obtain rfl | hc := eq_or_ne c 0,
{ simp only [inv_zero, zero_smul] },
obtain rfl | hx := eq_or_ne x 0,
{ simp only [inv_zero, smul_zero] },
{ refine inv_eq_of_mul_eq_one_left _,
rw [smul_mul_smul, inv_mul_cancel hc, inv_mul_cancel hx, one_smul] }
end
end group_with_zero
/-- Scalar multiplication as a monoid homomorphism with zero. -/
@[simps]
def smul_monoid_with_zero_hom {α β : Type*} [monoid_with_zero α] [mul_zero_one_class β]
[mul_action_with_zero α β] [is_scalar_tower α β β] [smul_comm_class α β β] :
α × β →*₀ β :=
{ map_zero' := smul_zero _,
.. smul_monoid_hom }
|
d4eafd4ff3b2b21658b31e0196dd2abbd66fd326 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/deprecated/subgroup.lean | 41ef51b1b3059b5cc12fe942bf4185c5f57cbf53 | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 26,807 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mitchell Rowett, Scott Morrison, Johan Commelin, Mario Carneiro,
Michael Howes
-/
import group_theory.subgroup
import deprecated.submonoid
open set function
variables {G : Type*} {H : Type*} {A : Type*} {a a₁ a₂ b c: G}
section group
variables [group G] [add_group A]
/-- `s` is an additive subgroup: a set containing 0 and closed under addition and negation. -/
class is_add_subgroup (s : set A) extends is_add_submonoid s : Prop :=
(neg_mem {a} : a ∈ s → -a ∈ s)
/-- `s` is a subgroup: a set containing 1 and closed under multiplication and inverse. -/
@[to_additive]
class is_subgroup (s : set G) extends is_submonoid s : Prop :=
(inv_mem {a} : a ∈ s → a⁻¹ ∈ s)
@[to_additive]
lemma is_subgroup.div_mem {s : set G} [is_subgroup s] {x y : G} (hx : x ∈ s) (hy : y ∈ s) :
x / y ∈ s :=
by simpa only [div_eq_mul_inv] using is_submonoid.mul_mem hx (is_subgroup.inv_mem hy)
lemma additive.is_add_subgroup
(s : set G) [is_subgroup s] : @is_add_subgroup (additive G) _ s :=
@is_add_subgroup.mk (additive G) _ _ (additive.is_add_submonoid _)
(@is_subgroup.inv_mem _ _ _ _)
theorem additive.is_add_subgroup_iff
{s : set G} : @is_add_subgroup (additive G) _ s ↔ is_subgroup s :=
⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @is_subgroup.mk G _ _ ⟨h₁, @h₂⟩ @h₃,
λ h, by exactI additive.is_add_subgroup _⟩
lemma multiplicative.is_subgroup
(s : set A) [is_add_subgroup s] : @is_subgroup (multiplicative A) _ s :=
@is_subgroup.mk (multiplicative A) _ _ (multiplicative.is_submonoid _)
(@is_add_subgroup.neg_mem _ _ _ _)
theorem multiplicative.is_subgroup_iff
{s : set A} : @is_subgroup (multiplicative A) _ s ↔ is_add_subgroup s :=
⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @is_add_subgroup.mk A _ _ ⟨h₁, @h₂⟩ @h₃,
λ h, by exactI multiplicative.is_subgroup _⟩
/-- The group structure on a subgroup coerced to a type. -/
@[to_additive "The additive group structure on an additive subgroup coerced to a type."]
def subtype.group {s : set G} [is_subgroup s] : group s :=
{ inv := λ x, ⟨(x:G)⁻¹, is_subgroup.inv_mem x.2⟩,
mul_left_inv := λ x, subtype.eq $ mul_left_inv x.1,
div := λ x y, ⟨(x / y : G), is_subgroup.div_mem x.2 y.2⟩,
div_eq_mul_inv := λ x y, subtype.ext $ div_eq_mul_inv x.1 y.1,
.. subtype.monoid }
/-- The commutative group structure on a commutative subgroup coerced to a type. -/
@[to_additive "The additive commutative group structure
on a additive commutative subgroup coerced to a type."]
def subtype.comm_group {G : Type*} [comm_group G] {s : set G} [is_subgroup s] : comm_group s :=
{ .. subtype.group, .. subtype.comm_monoid }
section
local attribute [instance] subtype.group subtype.add_group
@[simp, norm_cast, to_additive]
lemma is_subgroup.coe_inv {s : set G} [is_subgroup s] (a : s) : ((a⁻¹ : s) : G) = a⁻¹ := rfl
attribute [norm_cast] is_add_subgroup.coe_neg
@[simp, norm_cast] lemma is_subgroup.coe_gpow {s : set G} [is_subgroup s] (a : s) (n : ℤ) :
((a ^ n : s) : G) = a ^ n :=
by induction n; simp [is_submonoid.coe_pow a]
@[simp, norm_cast] lemma is_add_subgroup.gsmul_coe {s : set A} [is_add_subgroup s] (a : s) (n : ℤ) :
((gsmul n a : s) : A) = gsmul n a :=
by induction n; simp [is_add_submonoid.smul_coe a]
attribute [to_additive gsmul_coe] is_subgroup.coe_gpow
end
@[to_additive of_add_neg]
theorem is_subgroup.of_div (s : set G)
(one_mem : (1:G) ∈ s) (div_mem : ∀{a b:G}, a ∈ s → b ∈ s → a * b⁻¹ ∈ s) :
is_subgroup s :=
have inv_mem : ∀a, a ∈ s → a⁻¹ ∈ s, from
assume a ha,
have 1 * a⁻¹ ∈ s, from div_mem one_mem ha,
by simpa,
{ inv_mem := inv_mem,
mul_mem := assume a b ha hb,
have a * b⁻¹⁻¹ ∈ s, from div_mem ha (inv_mem b hb),
by simpa,
one_mem := one_mem }
theorem is_add_subgroup.of_sub (s : set A)
(zero_mem : (0:A) ∈ s) (sub_mem : ∀{a b:A}, a ∈ s → b ∈ s → a - b ∈ s) :
is_add_subgroup s :=
is_add_subgroup.of_add_neg s zero_mem
(λ x y hx hy, by simpa only [sub_eq_add_neg] using sub_mem hx hy)
@[to_additive]
instance is_subgroup.inter (s₁ s₂ : set G) [is_subgroup s₁] [is_subgroup s₂] :
is_subgroup (s₁ ∩ s₂) :=
{ inv_mem := λ x hx, ⟨is_subgroup.inv_mem hx.1, is_subgroup.inv_mem hx.2⟩ }
@[to_additive]
instance is_subgroup.Inter {ι : Sort*} (s : ι → set G) [h : ∀ y : ι, is_subgroup (s y)] :
is_subgroup (set.Inter s) :=
{ inv_mem := λ x h, set.mem_Inter.2 $ λ y, is_subgroup.inv_mem (set.mem_Inter.1 h y) }
@[to_additive]
lemma is_subgroup_Union_of_directed {ι : Type*} [hι : nonempty ι]
(s : ι → set G) [∀ i, is_subgroup (s i)]
(directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) :
is_subgroup (⋃i, s i) :=
{ inv_mem := λ a ha,
let ⟨i, hi⟩ := set.mem_Union.1 ha in
set.mem_Union.2 ⟨i, is_subgroup.inv_mem hi⟩,
to_is_submonoid := is_submonoid_Union_of_directed s directed }
def gpowers (x : G) : set G := set.range ((^) x : ℤ → G)
def gmultiples (x : A) : set A := set.range (λ i, gsmul i x)
attribute [to_additive gmultiples] gpowers
instance gpowers.is_subgroup (x : G) : is_subgroup (gpowers x) :=
{ one_mem := ⟨(0:ℤ), by simp⟩,
mul_mem := assume x₁ x₂ ⟨i₁, h₁⟩ ⟨i₂, h₂⟩, ⟨i₁ + i₂, by simp [gpow_add, *]⟩,
inv_mem := assume x₀ ⟨i, h⟩, ⟨-i, by simp [h.symm]⟩ }
instance gmultiples.is_add_subgroup (x : A) : is_add_subgroup (gmultiples x) :=
multiplicative.is_subgroup_iff.1 $ gpowers.is_subgroup _
attribute [to_additive] gpowers.is_subgroup
lemma is_subgroup.gpow_mem {a : G} {s : set G} [is_subgroup s] (h : a ∈ s) : ∀{i:ℤ}, a ^ i ∈ s
| (n : ℕ) := is_submonoid.pow_mem h
| -[1+ n] := is_subgroup.inv_mem (is_submonoid.pow_mem h)
lemma is_add_subgroup.gsmul_mem {a : A} {s : set A} [is_add_subgroup s] :
a ∈ s → ∀{i:ℤ}, gsmul i a ∈ s :=
@is_subgroup.gpow_mem (multiplicative A) _ _ _ (multiplicative.is_subgroup _)
lemma gpowers_subset {a : G} {s : set G} [is_subgroup s] (h : a ∈ s) : gpowers a ⊆ s :=
λ x hx, match x, hx with _, ⟨i, rfl⟩ := is_subgroup.gpow_mem h end
lemma gmultiples_subset {a : A} {s : set A} [is_add_subgroup s] (h : a ∈ s) : gmultiples a ⊆ s :=
@gpowers_subset (multiplicative A) _ _ _ (multiplicative.is_subgroup _) h
attribute [to_additive gmultiples_subset] gpowers_subset
lemma mem_gpowers {a : G} : a ∈ gpowers a := ⟨1, by simp⟩
lemma mem_gmultiples {a : A} : a ∈ gmultiples a := ⟨1, by simp⟩
attribute [to_additive mem_gmultiples] mem_gpowers
end group
namespace is_subgroup
open is_submonoid
variables [group G] (s : set G) [is_subgroup s]
@[to_additive]
lemma inv_mem_iff : a⁻¹ ∈ s ↔ a ∈ s :=
⟨λ h, by simpa using inv_mem h, inv_mem⟩
@[to_additive]
lemma mul_mem_cancel_right (h : a ∈ s) : b * a ∈ s ↔ b ∈ s :=
⟨λ hba, by simpa using mul_mem hba (inv_mem h), λ hb, mul_mem hb h⟩
@[to_additive]
lemma mul_mem_cancel_left (h : a ∈ s) : a * b ∈ s ↔ b ∈ s :=
⟨λ hab, by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩
end is_subgroup
class normal_add_subgroup [add_group A] (s : set A) extends is_add_subgroup s : Prop :=
(normal : ∀ n ∈ s, ∀ g : A, g + n + -g ∈ s)
@[to_additive]
class normal_subgroup [group G] (s : set G) extends is_subgroup s : Prop :=
(normal : ∀ n ∈ s, ∀ g : G, g * n * g⁻¹ ∈ s)
@[to_additive]
lemma normal_subgroup_of_comm_group [comm_group G] (s : set G) [hs : is_subgroup s] :
normal_subgroup s :=
{ normal := λ n hn g, by rwa [mul_right_comm, mul_right_inv, one_mul],
..hs }
lemma additive.normal_add_subgroup [group G]
(s : set G) [normal_subgroup s] : @normal_add_subgroup (additive G) _ s :=
@normal_add_subgroup.mk (additive G) _ _
(@additive.is_add_subgroup G _ _ _)
(@normal_subgroup.normal _ _ _ _)
theorem additive.normal_add_subgroup_iff [group G]
{s : set G} : @normal_add_subgroup (additive G) _ s ↔ normal_subgroup s :=
⟨by rintro ⟨h₁, h₂⟩; exact
@normal_subgroup.mk G _ _ (additive.is_add_subgroup_iff.1 h₁) @h₂,
λ h, by exactI additive.normal_add_subgroup _⟩
lemma multiplicative.normal_subgroup [add_group A]
(s : set A) [normal_add_subgroup s] : @normal_subgroup (multiplicative A) _ s :=
@normal_subgroup.mk (multiplicative A) _ _
(@multiplicative.is_subgroup A _ _ _)
(@normal_add_subgroup.normal _ _ _ _)
theorem multiplicative.normal_subgroup_iff [add_group A]
{s : set A} : @normal_subgroup (multiplicative A) _ s ↔ normal_add_subgroup s :=
⟨by rintro ⟨h₁, h₂⟩; exact
@normal_add_subgroup.mk A _ _ (multiplicative.is_subgroup_iff.1 h₁) @h₂,
λ h, by exactI multiplicative.normal_subgroup _⟩
namespace is_subgroup
variable [group G]
-- Normal subgroup properties
@[to_additive]
lemma mem_norm_comm {s : set G} [normal_subgroup s] {a b : G} (hab : a * b ∈ s) : b * a ∈ s :=
have h : a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ s, from normal_subgroup.normal (a * b) hab a⁻¹,
by simp at h; exact h
@[to_additive]
lemma mem_norm_comm_iff {s : set G} [normal_subgroup s] {a b : G} : a * b ∈ s ↔ b * a ∈ s :=
⟨mem_norm_comm, mem_norm_comm⟩
/-- The trivial subgroup -/
@[to_additive]
def trivial (G : Type*) [group G] : set G := {1}
@[simp, to_additive]
lemma mem_trivial {g : G} : g ∈ trivial G ↔ g = 1 :=
mem_singleton_iff
@[to_additive]
instance trivial_normal : normal_subgroup (trivial G) :=
by refine {..}; simp [trivial] {contextual := tt}
@[to_additive]
lemma eq_trivial_iff {s : set G} [is_subgroup s] :
s = trivial G ↔ (∀ x ∈ s, x = (1 : G)) :=
by simp only [set.ext_iff, is_subgroup.mem_trivial];
exact ⟨λ h x, (h x).1, λ h x, ⟨h x, λ hx, hx.symm ▸ is_submonoid.one_mem⟩⟩
@[to_additive]
instance univ_subgroup : normal_subgroup (@univ G) :=
by refine {..}; simp
@[to_additive add_center]
def center (G : Type*) [group G] : set G := {z | ∀ g, g * z = z * g}
@[to_additive mem_add_center]
lemma mem_center {a : G} : a ∈ center G ↔ ∀g, g * a = a * g := iff.rfl
@[to_additive add_center_normal]
instance center_normal : normal_subgroup (center G) :=
{ one_mem := by simp [center],
mul_mem := assume a b ha hb g,
by rw [←mul_assoc, mem_center.2 ha g, mul_assoc, mem_center.2 hb g, ←mul_assoc],
inv_mem := assume a ha g,
calc
g * a⁻¹ = a⁻¹ * (g * a) * a⁻¹ : by simp [ha g]
... = a⁻¹ * g : by rw [←mul_assoc, mul_assoc]; simp,
normal := assume n ha g h,
calc
h * (g * n * g⁻¹) = h * n : by simp [ha g, mul_assoc]
... = g * g⁻¹ * n * h : by rw ha h; simp
... = g * n * g⁻¹ * h : by rw [mul_assoc g, ha g⁻¹, ←mul_assoc] }
@[to_additive add_normalizer]
def normalizer (s : set G) : set G :=
{g : G | ∀ n, n ∈ s ↔ g * n * g⁻¹ ∈ s}
@[to_additive]
instance normalizer_is_subgroup (s : set G) : is_subgroup (normalizer s) :=
{ one_mem := by simp [normalizer],
mul_mem := λ a b (ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s)
(hb : ∀ n, n ∈ s ↔ b * n * b⁻¹ ∈ s) n,
by rw [mul_inv_rev, ← mul_assoc, mul_assoc a, mul_assoc a, ← ha, ← hb],
inv_mem := λ a (ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s) n,
by rw [ha (a⁻¹ * n * a⁻¹⁻¹)];
simp [mul_assoc] }
@[to_additive subset_add_normalizer]
lemma subset_normalizer (s : set G) [is_subgroup s] : s ⊆ normalizer s :=
λ g hg n, by rw [is_subgroup.mul_mem_cancel_right _ ((is_subgroup.inv_mem_iff _).2 hg),
is_subgroup.mul_mem_cancel_left _ hg]
local attribute [instance] subtype.group
/-- Every subgroup is a normal subgroup of its normalizer -/
@[to_additive add_normal_in_add_normalizer]
instance normal_in_normalizer (s : set G) [is_subgroup s] :
normal_subgroup (subtype.val ⁻¹' s : set (normalizer s)) :=
{ one_mem := show (1 : G) ∈ s, from is_submonoid.one_mem,
mul_mem := λ a b ha hb, show (a * b : G) ∈ s, from is_submonoid.mul_mem ha hb,
inv_mem := λ a ha, show (a⁻¹ : G) ∈ s, from is_subgroup.inv_mem ha,
normal := λ a ha ⟨m, hm⟩, (hm a).1 ha }
end is_subgroup
-- Homomorphism subgroups
namespace is_group_hom
open is_submonoid is_subgroup
open is_mul_hom (map_mul)
@[to_additive]
def ker [group H] (f : G → H) : set G := preimage f (trivial H)
@[to_additive]
lemma mem_ker [group H] (f : G → H) {x : G} : x ∈ ker f ↔ f x = 1 :=
mem_trivial
variables [group G] [group H]
@[to_additive]
lemma one_ker_inv (f : G → H) [is_group_hom f] {a b : G} (h : f (a * b⁻¹) = 1) : f a = f b :=
begin
rw [map_mul f, map_inv f] at h,
rw [←inv_inv (f b), eq_inv_of_mul_eq_one h]
end
@[to_additive]
lemma one_ker_inv' (f : G → H) [is_group_hom f] {a b : G} (h : f (a⁻¹ * b) = 1) : f a = f b :=
begin
rw [map_mul f, map_inv f] at h,
apply inv_injective,
rw eq_inv_of_mul_eq_one h
end
@[to_additive]
lemma inv_ker_one (f : G → H) [is_group_hom f] {a b : G} (h : f a = f b) : f (a * b⁻¹) = 1 :=
have f a * (f b)⁻¹ = 1, by rw [h, mul_right_inv],
by rwa [←map_inv f, ←map_mul f] at this
@[to_additive]
lemma inv_ker_one' (f : G → H) [is_group_hom f] {a b : G} (h : f a = f b) : f (a⁻¹ * b) = 1 :=
have (f a)⁻¹ * f b = 1, by rw [h, mul_left_inv],
by rwa [←map_inv f, ←map_mul f] at this
@[to_additive]
lemma one_iff_ker_inv (f : G → H) [is_group_hom f] (a b : G) : f a = f b ↔ f (a * b⁻¹) = 1 :=
⟨inv_ker_one f, one_ker_inv f⟩
@[to_additive]
lemma one_iff_ker_inv' (f : G → H) [is_group_hom f] (a b : G) : f a = f b ↔ f (a⁻¹ * b) = 1 :=
⟨inv_ker_one' f, one_ker_inv' f⟩
@[to_additive]
lemma inv_iff_ker (f : G → H) [w : is_group_hom f] (a b : G) : f a = f b ↔ a * b⁻¹ ∈ ker f :=
by rw [mem_ker]; exact one_iff_ker_inv _ _ _
@[to_additive]
lemma inv_iff_ker' (f : G → H) [w : is_group_hom f] (a b : G) : f a = f b ↔ a⁻¹ * b ∈ ker f :=
by rw [mem_ker]; exact one_iff_ker_inv' _ _ _
@[to_additive]
instance image_subgroup (f : G → H) [is_group_hom f] (s : set G) [is_subgroup s] :
is_subgroup (f '' s) :=
{ mul_mem := assume a₁ a₂ ⟨b₁, hb₁, eq₁⟩ ⟨b₂, hb₂, eq₂⟩,
⟨b₁ * b₂, mul_mem hb₁ hb₂, by simp [eq₁, eq₂, map_mul f]⟩,
one_mem := ⟨1, one_mem, map_one f⟩,
inv_mem := assume a ⟨b, hb, eq⟩, ⟨b⁻¹, inv_mem hb, by rw map_inv f; simp *⟩ }
@[to_additive]
instance range_subgroup (f : G → H) [is_group_hom f] : is_subgroup (set.range f) :=
@set.image_univ _ _ f ▸ is_group_hom.image_subgroup f set.univ
local attribute [simp] one_mem inv_mem mul_mem normal_subgroup.normal
@[to_additive]
instance preimage (f : G → H) [is_group_hom f] (s : set H) [is_subgroup s] :
is_subgroup (f ⁻¹' s) :=
by refine {..}; simp [map_mul f, map_one f, map_inv f, @inv_mem H _ s] {contextual:=tt}
@[to_additive]
instance preimage_normal (f : G → H) [is_group_hom f] (s : set H) [normal_subgroup s] :
normal_subgroup (f ⁻¹' s) :=
⟨by simp [map_mul f, map_inv f] {contextual:=tt}⟩
@[to_additive]
instance normal_subgroup_ker (f : G → H) [is_group_hom f] : normal_subgroup (ker f) :=
is_group_hom.preimage_normal f (trivial H)
@[to_additive]
lemma injective_of_trivial_ker (f : G → H) [is_group_hom f] (h : ker f = trivial G) :
function.injective f :=
begin
intros a₁ a₂ hfa,
simp [ext_iff, ker, is_subgroup.trivial] at h,
have ha : a₁ * a₂⁻¹ = 1, by rw ←h; exact inv_ker_one f hfa,
rw [eq_inv_of_mul_eq_one ha, inv_inv a₂]
end
@[to_additive]
lemma trivial_ker_of_injective (f : G → H) [is_group_hom f] (h : function.injective f) :
ker f = trivial G :=
set.ext $ assume x, iff.intro
(assume hx,
suffices f x = f 1, by simpa using h this,
by simp [map_one f]; rwa [mem_ker] at hx)
(by simp [mem_ker, is_group_hom.map_one f] {contextual := tt})
@[to_additive]
lemma injective_iff_trivial_ker (f : G → H) [is_group_hom f] :
function.injective f ↔ ker f = trivial G :=
⟨trivial_ker_of_injective f, injective_of_trivial_ker f⟩
@[to_additive]
lemma trivial_ker_iff_eq_one (f : G → H) [is_group_hom f] :
ker f = trivial G ↔ ∀ x, f x = 1 → x = 1 :=
by rw set.ext_iff; simp [ker]; exact
⟨λ h x hx, (h x).1 hx, λ h x, ⟨h x, λ hx, by rw [hx, map_one f]⟩⟩
end is_group_hom
section
local attribute [instance] subtype.group
@[to_additive]
instance subtype_val.is_group_hom [group G] {s : set G} [is_subgroup s] :
is_group_hom (subtype.val : s → G) := { ..subtype_val.is_monoid_hom }
@[to_additive]
instance coe.is_group_hom [group G] {s : set G} [is_subgroup s] :
is_group_hom (coe : s → G) := { ..subtype_val.is_monoid_hom }
@[to_additive]
instance subtype_mk.is_group_hom [group G] [group H] {s : set G}
[is_subgroup s] (f : H → G) [is_group_hom f] (h : ∀ x, f x ∈ s) :
is_group_hom (λ x, (⟨f x, h x⟩ : s)) := { ..subtype_mk.is_monoid_hom f h }
@[to_additive]
instance set_inclusion.is_group_hom [group G] {s t : set G}
[is_subgroup s] [is_subgroup t] (h : s ⊆ t) : is_group_hom (set.inclusion h) :=
subtype_mk.is_group_hom _ _
end
section
local attribute [instance] subtype.monoid
/-- `subtype.val : set.range f → H` as a monoid homomorphism, when `f` is a monoid homomorphism. -/
@[to_additive "`subtype.val : set.range f → H` as an additive monoid homomorphism, when `f` is
an additive monoid homomorphism."]
def monoid_hom.range_subtype_val [monoid G] [monoid H] (f : G →* H) : (set.range f) →* H :=
monoid_hom.of subtype.val
/-- `set.range_factorization f : G → set.range f` as a monoid homomorphism, when `f` is a monoid
homomorphism. -/
@[to_additive "`set.range_factorization f : G → set.range f` as an additive monoid homomorphism,
when `f` is an additive monoid homomorphism."]
def monoid_hom.range_factorization [monoid G] [monoid H] (f : G →* H) : G →* (set.range f) :=
{ to_fun := set.range_factorization f,
map_one' := by { dsimp [set.range_factorization], simp, refl, },
map_mul' := by { intros, dsimp [set.range_factorization], simp, refl, } }
end
namespace add_group
variables [add_group A]
inductive in_closure (s : set A) : A → Prop
| basic {a : A} : a ∈ s → in_closure a
| zero : in_closure 0
| neg {a : A} : in_closure a → in_closure (-a)
| add {a b : A} : in_closure a → in_closure b → in_closure (a + b)
end add_group
namespace group
open is_submonoid is_subgroup
variables [group G] {s : set G}
@[to_additive]
inductive in_closure (s : set G) : G → Prop
| basic {a : G} : a ∈ s → in_closure a
| one : in_closure 1
| inv {a : G} : in_closure a → in_closure a⁻¹
| mul {a b : G} : in_closure a → in_closure b → in_closure (a * b)
/-- `group.closure s` is the subgroup closed over `s`, i.e. the smallest subgroup containg s. -/
@[to_additive]
def closure (s : set G) : set G := {a | in_closure s a }
@[to_additive]
lemma mem_closure {a : G} : a ∈ s → a ∈ closure s := in_closure.basic
@[to_additive]
instance closure.is_subgroup (s : set G) : is_subgroup (closure s) :=
{ one_mem := in_closure.one,
mul_mem := assume a b, in_closure.mul,
inv_mem := assume a, in_closure.inv }
@[to_additive]
theorem subset_closure {s : set G} : s ⊆ closure s := λ a, mem_closure
@[to_additive]
theorem closure_subset {s t : set G} [is_subgroup t] (h : s ⊆ t) : closure s ⊆ t :=
assume a ha, by induction ha; simp [h _, *, one_mem, mul_mem, inv_mem_iff]
@[to_additive]
lemma closure_subset_iff (s t : set G) [is_subgroup t] : closure s ⊆ t ↔ s ⊆ t :=
⟨assume h b ha, h (mem_closure ha), assume h b ha, closure_subset h ha⟩
@[to_additive]
theorem closure_mono {s t : set G} (h : s ⊆ t) : closure s ⊆ closure t :=
closure_subset $ set.subset.trans h subset_closure
@[simp, to_additive]
lemma closure_subgroup (s : set G) [is_subgroup s] : closure s = s :=
set.subset.antisymm (closure_subset $ set.subset.refl s) subset_closure
@[to_additive]
theorem exists_list_of_mem_closure {s : set G} {a : G} (h : a ∈ closure s) :
(∃l:list G, (∀x∈l, x ∈ s ∨ x⁻¹ ∈ s) ∧ l.prod = a) :=
in_closure.rec_on h
(λ x hxs, ⟨[x], list.forall_mem_singleton.2 $ or.inl hxs, one_mul _⟩)
⟨[], list.forall_mem_nil _, rfl⟩
(λ x _ ⟨L, HL1, HL2⟩, ⟨L.reverse.map has_inv.inv,
λ x hx, let ⟨y, hy1, hy2⟩ := list.exists_of_mem_map hx in
hy2 ▸ or.imp id (by rw [inv_inv]; exact id) (HL1 _ $ list.mem_reverse.1 hy1).symm,
HL2 ▸ list.rec_on L one_inv.symm (λ hd tl ih,
by rw [list.reverse_cons, list.map_append, list.prod_append, ih, list.map_singleton,
list.prod_cons, list.prod_nil, mul_one, list.prod_cons, mul_inv_rev])⟩)
(λ x y hx hy ⟨L1, HL1, HL2⟩ ⟨L2, HL3, HL4⟩, ⟨L1 ++ L2, list.forall_mem_append.2 ⟨HL1, HL3⟩,
by rw [list.prod_append, HL2, HL4]⟩)
@[to_additive]
lemma image_closure [group H] (f : G → H) [is_group_hom f] (s : set G) :
f '' closure s = closure (f '' s) :=
le_antisymm
begin
rintros _ ⟨x, hx, rfl⟩,
apply in_closure.rec_on hx; intros,
{ solve_by_elim [subset_closure, set.mem_image_of_mem] },
{ rw [is_monoid_hom.map_one f], apply is_submonoid.one_mem },
{ rw [is_group_hom.map_inv f], apply is_subgroup.inv_mem, assumption },
{ rw [is_monoid_hom.map_mul f], solve_by_elim [is_submonoid.mul_mem] }
end
(closure_subset $ set.image_subset _ subset_closure)
@[to_additive]
theorem mclosure_subset {s : set G} : monoid.closure s ⊆ closure s :=
monoid.closure_subset $ subset_closure
@[to_additive]
theorem mclosure_inv_subset {s : set G} : monoid.closure (has_inv.inv ⁻¹' s) ⊆ closure s :=
monoid.closure_subset $ λ x hx, inv_inv x ▸ (is_subgroup.inv_mem $ subset_closure hx)
@[to_additive]
theorem closure_eq_mclosure {s : set G} : closure s = monoid.closure (s ∪ has_inv.inv ⁻¹' s) :=
set.subset.antisymm
(@closure_subset _ _ _ (monoid.closure (s ∪ has_inv.inv ⁻¹' s))
{ inv_mem := λ x hx, monoid.in_closure.rec_on hx
(λ x hx, or.cases_on hx (λ hx, monoid.subset_closure $ or.inr $
show x⁻¹⁻¹ ∈ s, from (inv_inv x).symm ▸ hx)
(λ hx, monoid.subset_closure $ or.inl hx))
((@one_inv G _).symm ▸ is_submonoid.one_mem)
(λ x y hx hy ihx ihy, (mul_inv_rev x y).symm ▸ is_submonoid.mul_mem ihy ihx) }
(set.subset.trans (set.subset_union_left _ _) monoid.subset_closure))
(monoid.closure_subset $ set.union_subset subset_closure $
λ x hx, inv_inv x ▸ (is_subgroup.inv_mem $ subset_closure hx))
@[to_additive]
theorem mem_closure_union_iff {G : Type*} [comm_group G] {s t : set G} {x : G} :
x ∈ closure (s ∪ t) ↔ ∃ y ∈ closure s, ∃ z ∈ closure t, y * z = x :=
begin
simp only [closure_eq_mclosure, monoid.mem_closure_union_iff, exists_prop, preimage_union], split,
{ rintro ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, rfl⟩,
refine ⟨_, ⟨_, hys, _, hzs, rfl⟩, _, ⟨_, hyt, _, hzt, rfl⟩, _⟩,
rw [mul_assoc, mul_assoc, mul_left_comm zs] },
{ rintro ⟨_, ⟨ys, hys, zs, hzs, rfl⟩, _, ⟨yt, hyt, zt, hzt, rfl⟩, rfl⟩,
refine ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, _⟩,
rw [mul_assoc, mul_assoc, mul_left_comm yt] }
end
@[to_additive gmultiples_eq_closure]
theorem gpowers_eq_closure {a : G} : gpowers a = closure {a} :=
subset.antisymm
(gpowers_subset $ mem_closure $ by simp)
(closure_subset $ by simp [mem_gpowers])
end group
namespace is_subgroup
variable [group G]
@[to_additive]
lemma trivial_eq_closure : trivial G = group.closure ∅ :=
subset.antisymm
(by simp [set.subset_def, is_submonoid.one_mem])
(group.closure_subset $ by simp)
end is_subgroup
/-The normal closure of a set s is the subgroup closure of all the conjugates of
elements of s. It is the smallest normal subgroup containing s. -/
namespace group
variables {s : set G} [group G]
lemma conjugates_subset {t : set G} [normal_subgroup t] {a : G} (h : a ∈ t) : conjugates a ⊆ t :=
λ x ⟨c,w⟩,
begin
have H := normal_subgroup.normal a h c,
rwa ←w,
end
theorem conjugates_of_set_subset' {s t : set G} [normal_subgroup t] (h : s ⊆ t) :
conjugates_of_set s ⊆ t :=
set.bUnion_subset (λ x H, conjugates_subset (h H))
/-- The normal closure of a set s is the subgroup closure of all the conjugates of
elements of s. It is the smallest normal subgroup containing s. -/
def normal_closure (s : set G) : set G := closure (conjugates_of_set s)
theorem conjugates_of_set_subset_normal_closure : conjugates_of_set s ⊆ normal_closure s :=
subset_closure
theorem subset_normal_closure : s ⊆ normal_closure s :=
set.subset.trans subset_conjugates_of_set conjugates_of_set_subset_normal_closure
/-- The normal closure of a set is a subgroup. -/
instance normal_closure.is_subgroup (s : set G) : is_subgroup (normal_closure s) :=
closure.is_subgroup (conjugates_of_set s)
/-- The normal closure of s is a normal subgroup. -/
instance normal_closure.is_normal : normal_subgroup (normal_closure s) :=
⟨ λ n h g,
begin
induction h with x hx x hx ihx x y hx hy ihx ihy,
{exact (conjugates_of_set_subset_normal_closure (conj_mem_conjugates_of_set hx))},
{simpa using (normal_closure.is_subgroup s).one_mem},
{rw ←conj_inv,
exact (is_subgroup.inv_mem ihx)},
{rw ←conj_mul,
exact (is_submonoid.mul_mem ihx ihy)},
end ⟩
/-- The normal closure of s is the smallest normal subgroup containing s. -/
theorem normal_closure_subset {s t : set G} [normal_subgroup t] (h : s ⊆ t) :
normal_closure s ⊆ t :=
λ a w,
begin
induction w with x hx x hx ihx x y hx hy ihx ihy,
{exact (conjugates_of_set_subset' h $ hx)},
{exact is_submonoid.one_mem},
{exact is_subgroup.inv_mem ihx},
{exact is_submonoid.mul_mem ihx ihy}
end
lemma normal_closure_subset_iff {s t : set G} [normal_subgroup t] : s ⊆ t ↔ normal_closure s ⊆ t :=
⟨normal_closure_subset, set.subset.trans (subset_normal_closure)⟩
theorem normal_closure_mono {s t : set G} : s ⊆ t → normal_closure s ⊆ normal_closure t :=
λ h, normal_closure_subset (set.subset.trans h (subset_normal_closure))
end group
/-- Create a bundled subgroup from a set `s` and `[is_subgroup s]`. -/
@[to_additive "Create a bundled additive subgroup from a set `s` and `[is_add_subgroup s]`."]
def subgroup.of [group G] (s : set G) [h : is_subgroup s] : subgroup G :=
{ carrier := s,
one_mem' := h.1.1,
mul_mem' := h.1.2,
inv_mem' := h.2 }
@[to_additive]
instance subgroup.is_subgroup [group G] (K : subgroup G) : is_subgroup (K : set G) :=
{ one_mem := K.one_mem',
mul_mem := K.mul_mem',
inv_mem := K.inv_mem' }
@[to_additive]
instance subgroup.of_normal [group G] (s : set G) [h : is_subgroup s] [n : normal_subgroup s] :
subgroup.normal (subgroup.of s) :=
{ conj_mem := n.normal, }
|
4d45521a77db6d89469ad4d4f49533b736789e17 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/meta/rewrite_tactic_auto.lean | f33485a110bead6369f3e2b465e9153201b5c70b | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 485 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.meta.relation_tactics
import Mathlib.Lean3Lib.init.meta.occurrences
universes l
namespace Mathlib
namespace tactic
/-- Configuration options for the `rewrite` tactic. -/
structure rewrite_cfg extends apply_cfg where
symm : Bool
occs : occurrences
end Mathlib |
abd63168cb25d0df143293c3c3836329abc1ff92 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/big_operators/basic.lean | 8fa29297cd201c62486b80210777ada2960bd53e | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 43,128 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.finset.fold
import Mathlib.data.equiv.mul_add
import Mathlib.tactic.abel
import Mathlib.PostPort
universes u v w u_1
namespace Mathlib
/-!
# Big operators
In this file we define products and sums indexed by finite sets (specifically, `finset`).
## Notation
We introduce the following notation, localized in `big_operators`.
To enable the notation, use `open_locale big_operators`.
Let `s` be a `finset α`, and `f : α → β` a function.
* `∏ x in s, f x` is notation for `finset.prod s f` (assuming `β` is a `comm_monoid`)
* `∑ x in s, f x` is notation for `finset.sum s f` (assuming `β` is an `add_comm_monoid`)
* `∏ x, f x` is notation for `finset.prod finset.univ f`
(assuming `α` is a `fintype` and `β` is a `comm_monoid`)
* `∑ x, f x` is notation for `finset.sum finset.univ f`
(assuming `α` is a `fintype` and `β` is an `add_comm_monoid`)
-/
namespace finset
/--
`∏ x in s, f x` is the product of `f x`
as `x` ranges over the elements of the finite set `s`.
-/
protected def prod {α : Type u} {β : Type v} [comm_monoid β] (s : finset α) (f : α → β) : β :=
multiset.prod (multiset.map f (val s))
@[simp] theorem prod_mk {α : Type u} {β : Type v} [comm_monoid β] (s : multiset α) (hs : multiset.nodup s) (f : α → β) : finset.prod (mk s hs) f = multiset.prod (multiset.map f s) :=
rfl
end finset
/--
## Operator precedence of `∏` and `∑`
There is no established mathematical convention
for the operator precedence of big operators like `∏` and `∑`.
We will have to make a choice.
Online discussions, such as https://math.stackexchange.com/q/185538/30839
seem to suggest that `∏` and `∑` should have the same precedence,
and that this should be somewhere between `*` and `+`.
The latter have precedence levels `70` and `65` respectively,
and we therefore choose the level `67`.
In practice, this means that parentheses should be placed as follows:
```lean
∑ k in K, (a k + b k) = ∑ k in K, a k + ∑ k in K, b k →
∏ k in K, a k * b k = (∏ k in K, a k) * (∏ k in K, b k)
```
(Example taken from page 490 of Knuth's *Concrete Mathematics*.)
-/
namespace finset
theorem prod_eq_multiset_prod {α : Type u} {β : Type v} [comm_monoid β] (s : finset α) (f : α → β) : (finset.prod s fun (x : α) => f x) = multiset.prod (multiset.map f (val s)) :=
rfl
theorem prod_eq_fold {α : Type u} {β : Type v} [comm_monoid β] (s : finset α) (f : α → β) : (finset.prod s fun (x : α) => f x) = fold Mul.mul 1 f s :=
rfl
end finset
theorem monoid_hom.map_prod {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] [comm_monoid γ] (g : β →* γ) (f : α → β) (s : finset α) : coe_fn g (finset.prod s fun (x : α) => f x) = finset.prod s fun (x : α) => coe_fn g (f x) := sorry
theorem add_equiv.map_sum {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] [add_comm_monoid γ] (g : β ≃+ γ) (f : α → β) (s : finset α) : coe_fn g (finset.sum s fun (x : α) => f x) = finset.sum s fun (x : α) => coe_fn g (f x) :=
add_monoid_hom.map_sum (add_equiv.to_add_monoid_hom g) f s
theorem ring_hom.map_list_prod {β : Type v} {γ : Type w} [semiring β] [semiring γ] (f : β →+* γ) (l : List β) : coe_fn f (list.prod l) = list.prod (list.map (⇑f) l) :=
monoid_hom.map_list_prod (ring_hom.to_monoid_hom f) l
theorem ring_hom.map_list_sum {β : Type v} {γ : Type w} [semiring β] [semiring γ] (f : β →+* γ) (l : List β) : coe_fn f (list.sum l) = list.sum (list.map (⇑f) l) :=
add_monoid_hom.map_list_sum (ring_hom.to_add_monoid_hom f) l
theorem ring_hom.map_multiset_prod {β : Type v} {γ : Type w} [comm_semiring β] [comm_semiring γ] (f : β →+* γ) (s : multiset β) : coe_fn f (multiset.prod s) = multiset.prod (multiset.map (⇑f) s) :=
monoid_hom.map_multiset_prod (ring_hom.to_monoid_hom f) s
theorem ring_hom.map_multiset_sum {β : Type v} {γ : Type w} [semiring β] [semiring γ] (f : β →+* γ) (s : multiset β) : coe_fn f (multiset.sum s) = multiset.sum (multiset.map (⇑f) s) :=
add_monoid_hom.map_multiset_sum (ring_hom.to_add_monoid_hom f) s
theorem ring_hom.map_prod {α : Type u} {β : Type v} {γ : Type w} [comm_semiring β] [comm_semiring γ] (g : β →+* γ) (f : α → β) (s : finset α) : coe_fn g (finset.prod s fun (x : α) => f x) = finset.prod s fun (x : α) => coe_fn g (f x) :=
monoid_hom.map_prod (ring_hom.to_monoid_hom g) f s
theorem ring_hom.map_sum {α : Type u} {β : Type v} {γ : Type w} [semiring β] [semiring γ] (g : β →+* γ) (f : α → β) (s : finset α) : coe_fn g (finset.sum s fun (x : α) => f x) = finset.sum s fun (x : α) => coe_fn g (f x) :=
add_monoid_hom.map_sum (ring_hom.to_add_monoid_hom g) f s
theorem add_monoid_hom.coe_sum {α : Type u} {β : Type v} {γ : Type w} [add_monoid β] [add_comm_monoid γ] (f : α → β →+ γ) (s : finset α) : ⇑(finset.sum s fun (x : α) => f x) = finset.sum s fun (x : α) => ⇑(f x) :=
add_monoid_hom.map_sum (add_monoid_hom.coe_fn β γ) (fun (x : α) => f x) s
@[simp] theorem monoid_hom.finset_prod_apply {α : Type u} {β : Type v} {γ : Type w} [monoid β] [comm_monoid γ] (f : α → β →* γ) (s : finset α) (b : β) : coe_fn (finset.prod s fun (x : α) => f x) b = finset.prod s fun (x : α) => coe_fn (f x) b :=
monoid_hom.map_prod (coe_fn monoid_hom.eval b) (fun (x : α) => f x) s
namespace finset
@[simp] theorem sum_empty {β : Type v} [add_comm_monoid β] {α : Type u} {f : α → β} : (finset.sum ∅ fun (x : α) => f x) = 0 :=
rfl
@[simp] theorem prod_insert {α : Type u} {β : Type v} {s : finset α} {a : α} {f : α → β} [comm_monoid β] [DecidableEq α] : ¬a ∈ s → (finset.prod (insert a s) fun (x : α) => f x) = f a * finset.prod s fun (x : α) => f x :=
fold_insert
/--
The product of `f` over `insert a s` is the same as
the product over `s`, as long as `a` is in `s` or `f a = 1`.
-/
@[simp] theorem prod_insert_of_eq_one_if_not_mem {α : Type u} {β : Type v} {s : finset α} {a : α} {f : α → β} [comm_monoid β] [DecidableEq α] (h : ¬a ∈ s → f a = 1) : (finset.prod (insert a s) fun (x : α) => f x) = finset.prod s fun (x : α) => f x := sorry
/--
The product of `f` over `insert a s` is the same as the product over `s`, as long as `f a = 1`.
-/
@[simp] theorem prod_insert_one {α : Type u} {β : Type v} {s : finset α} {a : α} {f : α → β} [comm_monoid β] [DecidableEq α] (h : f a = 1) : (finset.prod (insert a s) fun (x : α) => f x) = finset.prod s fun (x : α) => f x :=
prod_insert_of_eq_one_if_not_mem fun (_x : ¬a ∈ s) => h
@[simp] theorem prod_singleton {α : Type u} {β : Type v} {a : α} {f : α → β} [comm_monoid β] : (finset.prod (singleton a) fun (x : α) => f x) = f a :=
Eq.trans fold_singleton (mul_one (f a))
theorem sum_pair {α : Type u} {β : Type v} {f : α → β} [add_comm_monoid β] [DecidableEq α] {a : α} {b : α} (h : a ≠ b) : (finset.sum (insert a (singleton b)) fun (x : α) => f x) = f a + f b := sorry
@[simp] theorem prod_const_one {α : Type u} {β : Type v} {s : finset α} [comm_monoid β] : (finset.prod s fun (x : α) => 1) = 1 := sorry
@[simp] theorem sum_const_zero {α : Type u} {β : Type u_1} {s : finset α} [add_comm_monoid β] : (finset.sum s fun (x : α) => 0) = 0 :=
prod_const_one
@[simp] theorem prod_image {α : Type u} {β : Type v} {γ : Type w} {f : α → β} [comm_monoid β] [DecidableEq α] {s : finset γ} {g : γ → α} : (∀ (x : γ), x ∈ s → ∀ (y : γ), y ∈ s → g x = g y → x = y) →
(finset.prod (image g s) fun (x : α) => f x) = finset.prod s fun (x : γ) => f (g x) :=
fold_image
@[simp] theorem prod_map {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] (s : finset α) (e : α ↪ γ) (f : γ → β) : (finset.prod (map e s) fun (x : γ) => f x) = finset.prod s fun (x : α) => f (coe_fn e x) := sorry
theorem prod_congr {α : Type u} {β : Type v} {s₁ : finset α} {s₂ : finset α} {f : α → β} {g : α → β} [comm_monoid β] (h : s₁ = s₂) : (∀ (x : α), x ∈ s₂ → f x = g x) → finset.prod s₁ f = finset.prod s₂ g :=
eq.mpr (id (Eq._oldrec (Eq.refl ((∀ (x : α), x ∈ s₂ → f x = g x) → finset.prod s₁ f = finset.prod s₂ g)) h)) fold_congr
theorem prod_union_inter {α : Type u} {β : Type v} {s₁ : finset α} {s₂ : finset α} {f : α → β} [comm_monoid β] [DecidableEq α] : ((finset.prod (s₁ ∪ s₂) fun (x : α) => f x) * finset.prod (s₁ ∩ s₂) fun (x : α) => f x) =
(finset.prod s₁ fun (x : α) => f x) * finset.prod s₂ fun (x : α) => f x :=
fold_union_inter
theorem sum_union {α : Type u} {β : Type v} {s₁ : finset α} {s₂ : finset α} {f : α → β} [add_comm_monoid β] [DecidableEq α] (h : disjoint s₁ s₂) : (finset.sum (s₁ ∪ s₂) fun (x : α) => f x) = (finset.sum s₁ fun (x : α) => f x) + finset.sum s₂ fun (x : α) => f x := sorry
theorem prod_sdiff {α : Type u} {β : Type v} {s₁ : finset α} {s₂ : finset α} {f : α → β} [comm_monoid β] [DecidableEq α] (h : s₁ ⊆ s₂) : ((finset.prod (s₂ \ s₁) fun (x : α) => f x) * finset.prod s₁ fun (x : α) => f x) = finset.prod s₂ fun (x : α) => f x := sorry
@[simp] theorem prod_sum_elim {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] [DecidableEq (α ⊕ γ)] (s : finset α) (t : finset γ) (f : α → β) (g : γ → β) : (finset.prod (map function.embedding.inl s ∪ map function.embedding.inr t) fun (x : α ⊕ γ) => sum.elim f g x) =
(finset.prod s fun (x : α) => f x) * finset.prod t fun (x : γ) => g x := sorry
theorem sum_bUnion {α : Type u} {β : Type v} {γ : Type w} {f : α → β} [add_comm_monoid β] [DecidableEq α] {s : finset γ} {t : γ → finset α} : (∀ (x : γ), x ∈ s → ∀ (y : γ), y ∈ s → x ≠ y → disjoint (t x) (t y)) →
(finset.sum (finset.bUnion s t) fun (x : α) => f x) = finset.sum s fun (x : γ) => finset.sum (t x) fun (x : α) => f x := sorry
theorem sum_product {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] {s : finset γ} {t : finset α} {f : γ × α → β} : (finset.sum (finset.product s t) fun (x : γ × α) => f x) =
finset.sum s fun (x : γ) => finset.sum t fun (y : α) => f (x, y) := sorry
/-- An uncurried version of `finset.prod_product`. -/
theorem sum_product' {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] {s : finset γ} {t : finset α} {f : γ → α → β} : (finset.sum (finset.product s t) fun (x : γ × α) => f (prod.fst x) (prod.snd x)) =
finset.sum s fun (x : γ) => finset.sum t fun (y : α) => f x y :=
sum_product
/-- Product over a sigma type equals the product of fiberwise products. For rewriting
in the reverse direction, use `finset.prod_sigma'`. -/
theorem prod_sigma {α : Type u} {β : Type v} [comm_monoid β] {σ : α → Type u_1} (s : finset α) (t : (a : α) → finset (σ a)) (f : sigma σ → β) : (finset.prod (finset.sigma s t) fun (x : sigma fun (a : α) => σ a) => f x) =
finset.prod s fun (a : α) => finset.prod (t a) fun (s : σ a) => f (sigma.mk a s) := sorry
theorem prod_sigma' {α : Type u} {β : Type v} [comm_monoid β] {σ : α → Type u_1} (s : finset α) (t : (a : α) → finset (σ a)) (f : (a : α) → σ a → β) : (finset.prod s fun (a : α) => finset.prod (t a) fun (s : σ a) => f a s) =
finset.prod (finset.sigma s t) fun (x : sigma fun (a : α) => σ a) => f (sigma.fst x) (sigma.snd x) :=
Eq.symm (prod_sigma s t fun (x : sigma fun (a : α) => σ a) => f (sigma.fst x) (sigma.snd x))
theorem prod_fiberwise_of_maps_to {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] [DecidableEq γ] {s : finset α} {t : finset γ} {g : α → γ} (h : ∀ (x : α), x ∈ s → g x ∈ t) (f : α → β) : (finset.prod t fun (y : γ) => finset.prod (filter (fun (x : α) => g x = y) s) fun (x : α) => f x) =
finset.prod s fun (x : α) => f x := sorry
theorem prod_image' {α : Type u} {β : Type v} {γ : Type w} {f : α → β} [comm_monoid β] [DecidableEq α] {s : finset γ} {g : γ → α} (h : γ → β) (eq : ∀ (c : γ), c ∈ s → f (g c) = finset.prod (filter (fun (c' : γ) => g c' = g c) s) fun (x : γ) => h x) : (finset.prod (image g s) fun (x : α) => f x) = finset.prod s fun (x : γ) => h x := sorry
theorem prod_mul_distrib {α : Type u} {β : Type v} {s : finset α} {f : α → β} {g : α → β} [comm_monoid β] : (finset.prod s fun (x : α) => f x * g x) = (finset.prod s fun (x : α) => f x) * finset.prod s fun (x : α) => g x := sorry
theorem sum_comm {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] {s : finset γ} {t : finset α} {f : γ → α → β} : (finset.sum s fun (x : γ) => finset.sum t fun (y : α) => f x y) =
finset.sum t fun (y : α) => finset.sum s fun (x : γ) => f x y := sorry
theorem sum_hom {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] [add_comm_monoid γ] (s : finset α) {f : α → β} (g : β → γ) [is_add_monoid_hom g] : (finset.sum s fun (x : α) => g (f x)) = g (finset.sum s fun (x : α) => f x) :=
Eq.symm (add_monoid_hom.map_sum (add_monoid_hom.of g) f s)
theorem sum_hom_rel {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] [add_comm_monoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : finset α} (h₁ : r 0 0) (h₂ : ∀ (a : α) (b : β) (c : γ), r b c → r (f a + b) (g a + c)) : r (finset.sum s fun (x : α) => f x) (finset.sum s fun (x : α) => g x) :=
id (multiset.sum_hom_rel (val s) h₁ h₂)
theorem prod_subset {α : Type u} {β : Type v} {s₁ : finset α} {s₂ : finset α} {f : α → β} [comm_monoid β] (h : s₁ ⊆ s₂) (hf : ∀ (x : α), x ∈ s₂ → ¬x ∈ s₁ → f x = 1) : (finset.prod s₁ fun (x : α) => f x) = finset.prod s₂ fun (x : α) => f x := sorry
theorem prod_filter_of_ne {α : Type u} {β : Type v} {s : finset α} {f : α → β} [comm_monoid β] {p : α → Prop} [decidable_pred p] (hp : ∀ (x : α), x ∈ s → f x ≠ 1 → p x) : (finset.prod (filter p s) fun (x : α) => f x) = finset.prod s fun (x : α) => f x := sorry
-- If we use `[decidable_eq β]` here, some rewrites fail because they find a wrong `decidable`
-- instance first; `{∀x, decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one`
theorem sum_filter_ne_zero {α : Type u} {β : Type v} {s : finset α} {f : α → β} [add_comm_monoid β] [(x : α) → Decidable (f x ≠ 0)] : (finset.sum (filter (fun (x : α) => f x ≠ 0) s) fun (x : α) => f x) = finset.sum s fun (x : α) => f x :=
sum_filter_of_ne fun (_x : α) (_x_1 : _x ∈ s) => id
theorem sum_filter {α : Type u} {β : Type v} {s : finset α} [add_comm_monoid β] (p : α → Prop) [decidable_pred p] (f : α → β) : (finset.sum (filter p s) fun (a : α) => f a) = finset.sum s fun (a : α) => ite (p a) (f a) 0 := sorry
theorem prod_eq_single {α : Type u} {β : Type v} [comm_monoid β] {s : finset α} {f : α → β} (a : α) (h₀ : ∀ (b : α), b ∈ s → b ≠ a → f b = 1) (h₁ : ¬a ∈ s → f a = 1) : (finset.prod s fun (x : α) => f x) = f a := sorry
theorem sum_attach {α : Type u} {β : Type v} {s : finset α} [add_comm_monoid β] {f : α → β} : (finset.sum (attach s) fun (x : Subtype fun (x : α) => x ∈ s) => f ↑x) = finset.sum s fun (x : α) => f x := sorry
/-- A product over `s.subtype p` equals one over `s.filter p`. -/
@[simp] theorem prod_subtype_eq_prod_filter {α : Type u} {β : Type v} {s : finset α} [comm_monoid β] (f : α → β) {p : α → Prop} [decidable_pred p] : (finset.prod (finset.subtype p s) fun (x : Subtype p) => f ↑x) = finset.prod (filter p s) fun (x : α) => f x := sorry
/-- If all elements of a `finset` satisfy the predicate `p`, a product
over `s.subtype p` equals that product over `s`. -/
theorem sum_subtype_of_mem {α : Type u} {β : Type v} {s : finset α} [add_comm_monoid β] (f : α → β) {p : α → Prop} [decidable_pred p] (h : ∀ (x : α), x ∈ s → p x) : (finset.sum (finset.subtype p s) fun (x : Subtype p) => f ↑x) = finset.sum s fun (x : α) => f x := sorry
/-- A product of a function over a `finset` in a subtype equals a
product in the main type of a function that agrees with the first
function on that `finset`. -/
theorem sum_subtype_map_embedding {α : Type u} {β : Type v} [add_comm_monoid β] {p : α → Prop} {s : finset (Subtype fun (x : α) => p x)} {f : (Subtype fun (x : α) => p x) → β} {g : α → β} (h : ∀ (x : Subtype fun (x : α) => p x), x ∈ s → g ↑x = f x) : (finset.sum (map (function.embedding.subtype fun (x : α) => p x) s) fun (x : α) => g x) =
finset.sum s fun (x : Subtype fun (x : α) => p x) => f x := sorry
theorem prod_eq_one {α : Type u} {β : Type v} [comm_monoid β] {f : α → β} {s : finset α} (h : ∀ (x : α), x ∈ s → f x = 1) : (finset.prod s fun (x : α) => f x) = 1 :=
Eq.trans (prod_congr rfl h) prod_const_one
theorem sum_apply_dite {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] {s : finset α} {p : α → Prop} {hp : decidable_pred p} (f : (x : α) → p x → γ) (g : (x : α) → ¬p x → γ) (h : γ → β) : (finset.sum s fun (x : α) => h (dite (p x) (fun (hx : p x) => f x hx) fun (hx : ¬p x) => g x hx)) =
(finset.sum (attach (filter p s))
fun (x : Subtype fun (x : α) => x ∈ filter p s) =>
h (f (subtype.val x) (and.right (iff.mp mem_filter (subtype.property x))))) +
finset.sum (attach (filter (fun (x : α) => ¬p x) s))
fun (x : Subtype fun (x : α) => x ∈ filter (fun (x : α) => ¬p x) s) =>
h (g (subtype.val x) (and.right (iff.mp mem_filter (subtype.property x)))) := sorry
theorem prod_apply_ite {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] {s : finset α} {p : α → Prop} {hp : decidable_pred p} (f : α → γ) (g : α → γ) (h : γ → β) : (finset.prod s fun (x : α) => h (ite (p x) (f x) (g x))) =
(finset.prod (filter p s) fun (x : α) => h (f x)) *
finset.prod (filter (fun (x : α) => ¬p x) s) fun (x : α) => h (g x) :=
trans (prod_apply_dite (fun (x : α) (hx : p x) => f x) (fun (x : α) (hx : ¬p x) => g x) h)
(congr_arg2 Mul.mul prod_attach prod_attach)
theorem sum_dite {α : Type u} {β : Type v} [add_comm_monoid β] {s : finset α} {p : α → Prop} {hp : decidable_pred p} (f : (x : α) → p x → β) (g : (x : α) → ¬p x → β) : (finset.sum s fun (x : α) => dite (p x) (fun (hx : p x) => f x hx) fun (hx : ¬p x) => g x hx) =
(finset.sum (attach (filter p s))
fun (x : Subtype fun (x : α) => x ∈ filter p s) =>
f (subtype.val x) (and.right (iff.mp mem_filter (subtype.property x)))) +
finset.sum (attach (filter (fun (x : α) => ¬p x) s))
fun (x : Subtype fun (x : α) => x ∈ filter (fun (x : α) => ¬p x) s) =>
g (subtype.val x) (and.right (iff.mp mem_filter (subtype.property x))) := sorry
theorem prod_ite {α : Type u} {β : Type v} [comm_monoid β] {s : finset α} {p : α → Prop} {hp : decidable_pred p} (f : α → β) (g : α → β) : (finset.prod s fun (x : α) => ite (p x) (f x) (g x)) =
(finset.prod (filter p s) fun (x : α) => f x) * finset.prod (filter (fun (x : α) => ¬p x) s) fun (x : α) => g x := sorry
theorem sum_extend_by_zero {α : Type u} {β : Type v} [add_comm_monoid β] [DecidableEq α] (s : finset α) (f : α → β) : (finset.sum s fun (i : α) => ite (i ∈ s) (f i) 0) = finset.sum s fun (i : α) => f i :=
sum_congr rfl fun (i : α) (hi : i ∈ s) => if_pos hi
@[simp] theorem sum_dite_eq {α : Type u} {β : Type v} [add_comm_monoid β] [DecidableEq α] (s : finset α) (a : α) (b : (x : α) → a = x → β) : (finset.sum s fun (x : α) => dite (a = x) (fun (h : a = x) => b x h) fun (h : ¬a = x) => 0) = ite (a ∈ s) (b a rfl) 0 := sorry
@[simp] theorem prod_dite_eq' {α : Type u} {β : Type v} [comm_monoid β] [DecidableEq α] (s : finset α) (a : α) (b : (x : α) → x = a → β) : (finset.prod s fun (x : α) => dite (x = a) (fun (h : x = a) => b x h) fun (h : ¬x = a) => 1) = ite (a ∈ s) (b a rfl) 1 := sorry
@[simp] theorem prod_ite_eq {α : Type u} {β : Type v} [comm_monoid β] [DecidableEq α] (s : finset α) (a : α) (b : α → β) : (finset.prod s fun (x : α) => ite (a = x) (b x) 1) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq s a fun (x : α) (_x : a = x) => b x
/--
When a product is taken over a conditional whose condition is an equality test on the index
and whose alternative is 1, then the product's value is either the term at that index or `1`.
The difference with `prod_ite_eq` is that the arguments to `eq` are swapped.
-/
@[simp] theorem sum_ite_eq' {α : Type u} {β : Type v} [add_comm_monoid β] [DecidableEq α] (s : finset α) (a : α) (b : α → β) : (finset.sum s fun (x : α) => ite (x = a) (b x) 0) = ite (a ∈ s) (b a) 0 :=
sum_dite_eq' s a fun (x : α) (_x : x = a) => b x
theorem prod_ite_index {α : Type u} {β : Type v} [comm_monoid β] (p : Prop) [Decidable p] (s : finset α) (t : finset α) (f : α → β) : (finset.prod (ite p s t) fun (x : α) => f x) =
ite p (finset.prod s fun (x : α) => f x) (finset.prod t fun (x : α) => f x) :=
apply_ite (fun (s : finset α) => finset.prod s fun (x : α) => f x) p s t
/--
Reorder a product.
The difference with `prod_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
-/
theorem prod_bij {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] {s : finset α} {t : finset γ} {f : α → β} {g : γ → β} (i : (a : α) → a ∈ s → γ) (hi : ∀ (a : α) (ha : a ∈ s), i a ha ∈ t) (h : ∀ (a : α) (ha : a ∈ s), f a = g (i a ha)) (i_inj : ∀ (a₁ a₂ : α) (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s), i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀ (b : γ), b ∈ t → ∃ (a : α), ∃ (ha : a ∈ s), b = i a ha) : (finset.prod s fun (x : α) => f x) = finset.prod t fun (x : γ) => g x :=
congr_arg multiset.prod (multiset.map_eq_map_of_bij_of_nodup f g (nodup s) (nodup t) i hi h i_inj i_surj)
/--
Reorder a product.
The difference with `prod_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
-/
theorem sum_bij' {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] {s : finset α} {t : finset γ} {f : α → β} {g : γ → β} (i : (a : α) → a ∈ s → γ) (hi : ∀ (a : α) (ha : a ∈ s), i a ha ∈ t) (h : ∀ (a : α) (ha : a ∈ s), f a = g (i a ha)) (j : (a : γ) → a ∈ t → α) (hj : ∀ (a : γ) (ha : a ∈ t), j a ha ∈ s) (left_inv : ∀ (a : α) (ha : a ∈ s), j (i a ha) (hi a ha) = a) (right_inv : ∀ (a : γ) (ha : a ∈ t), i (j a ha) (hj a ha) = a) : (finset.sum s fun (x : α) => f x) = finset.sum t fun (x : γ) => g x := sorry
theorem prod_bij_ne_one {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] {s : finset α} {t : finset γ} {f : α → β} {g : γ → β} (i : (a : α) → a ∈ s → f a ≠ 1 → γ) (hi : ∀ (a : α) (h₁ : a ∈ s) (h₂ : f a ≠ 1), i a h₁ h₂ ∈ t) (i_inj : ∀ (a₁ a₂ : α) (h₁₁ : a₁ ∈ s) (h₁₂ : f a₁ ≠ 1) (h₂₁ : a₂ ∈ s) (h₂₂ : f a₂ ≠ 1), i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂) (i_surj : ∀ (b : γ), b ∈ t → g b ≠ 1 → ∃ (a : α), ∃ (h₁ : a ∈ s), ∃ (h₂ : f a ≠ 1), b = i a h₁ h₂) (h : ∀ (a : α) (h₁ : a ∈ s) (h₂ : f a ≠ 1), f a = g (i a h₁ h₂)) : (finset.prod s fun (x : α) => f x) = finset.prod t fun (x : γ) => g x := sorry
theorem nonempty_of_sum_ne_zero {α : Type u} {β : Type v} {s : finset α} {f : α → β} [add_comm_monoid β] (h : (finset.sum s fun (x : α) => f x) ≠ 0) : finset.nonempty s :=
or.elim (eq_empty_or_nonempty s) (fun (H : s = ∅) => false.elim (h (Eq.symm H ▸ sum_empty))) id
theorem exists_ne_zero_of_sum_ne_zero {α : Type u} {β : Type v} {s : finset α} {f : α → β} [add_comm_monoid β] (h : (finset.sum s fun (x : α) => f x) ≠ 0) : ∃ (a : α), ∃ (H : a ∈ s), f a ≠ 0 := sorry
theorem sum_subset_zero_on_sdiff {α : Type u} {β : Type v} {s₁ : finset α} {s₂ : finset α} {f : α → β} {g : α → β} [add_comm_monoid β] [DecidableEq α] (h : s₁ ⊆ s₂) (hg : ∀ (x : α), x ∈ s₂ \ s₁ → g x = 0) (hfg : ∀ (x : α), x ∈ s₁ → f x = g x) : (finset.sum s₁ fun (i : α) => f i) = finset.sum s₂ fun (i : α) => g i := sorry
theorem sum_range_succ {β : Type u_1} [add_comm_monoid β] (f : ℕ → β) (n : ℕ) : (finset.sum (range (n + 1)) fun (x : ℕ) => f x) = f n + finset.sum (range n) fun (x : ℕ) => f x := sorry
theorem prod_range_succ {β : Type v} [comm_monoid β] (f : ℕ → β) (n : ℕ) : (finset.prod (range (n + 1)) fun (x : ℕ) => f x) = f n * finset.prod (range n) fun (x : ℕ) => f x := sorry
theorem prod_range_succ' {β : Type v} [comm_monoid β] (f : ℕ → β) (n : ℕ) : (finset.prod (range (n + 1)) fun (k : ℕ) => f k) = (finset.prod (range n) fun (k : ℕ) => f (k + 1)) * f 0 := sorry
theorem prod_range_zero {β : Type v} [comm_monoid β] (f : ℕ → β) : (finset.prod (range 0) fun (k : ℕ) => f k) = 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl ((finset.prod (range 0) fun (k : ℕ) => f k) = 1)) range_zero))
(eq.mpr (id (Eq._oldrec (Eq.refl ((finset.prod ∅ fun (k : ℕ) => f k) = 1)) prod_empty)) (Eq.refl 1))
theorem prod_range_one {β : Type v} [comm_monoid β] (f : ℕ → β) : (finset.prod (range 1) fun (k : ℕ) => f k) = f 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl ((finset.prod (range 1) fun (k : ℕ) => f k) = f 0)) range_one)) prod_singleton
theorem sum_range_one {δ : Type u_1} [add_comm_monoid δ] (f : ℕ → δ) : (finset.sum (range 1) fun (k : ℕ) => f k) = f 0 :=
prod_range_one f
theorem prod_multiset_map_count {α : Type u} [DecidableEq α] (s : multiset α) {M : Type u_1} [comm_monoid M] (f : α → M) : multiset.prod (multiset.map f s) = finset.prod (multiset.to_finset s) fun (m : α) => f m ^ multiset.count m s := sorry
theorem prod_multiset_count {α : Type u} [DecidableEq α] [comm_monoid α] (s : multiset α) : multiset.prod s = finset.prod (multiset.to_finset s) fun (m : α) => m ^ multiset.count m s := sorry
/--
To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors.
-/
theorem prod_induction {α : Type u} {s : finset α} {M : Type u_1} [comm_monoid M] (f : α → M) (p : M → Prop) (p_mul : ∀ (a b : M), p a → p b → p (a * b)) (p_one : p 1) (p_s : ∀ (x : α), x ∈ s → p (f x)) : p (finset.prod s fun (x : α) => f x) := sorry
/--
For any product along `{0, ..., n-1}` of a commutative-monoid-valued function, we can verify that
it's equal to a different function just by checking ratios of adjacent terms.
This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
theorem prod_range_induction {M : Type u_1} [comm_monoid M] (f : ℕ → M) (s : ℕ → M) (h0 : s 0 = 1) (h : ∀ (n : ℕ), s (n + 1) = s n * f n) (n : ℕ) : (finset.prod (range n) fun (k : ℕ) => f k) = s n := sorry
/--
For any sum along `{0, ..., n-1}` of a commutative-monoid-valued function,
we can verify that it's equal to a different function
just by checking differences of adjacent terms.
This is a discrete analogue
of the fundamental theorem of calculus.
-/
theorem sum_range_induction {M : Type u_1} [add_comm_monoid M] (f : ℕ → M) (s : ℕ → M) (h0 : s 0 = 0) (h : ∀ (n : ℕ), s (n + 1) = s n + f n) (n : ℕ) : (finset.sum (range n) fun (k : ℕ) => f k) = s n :=
prod_range_induction f s h0 h n
/-- A telescoping sum along `{0, ..., n-1}` of an additive commutative group valued function
reduces to the difference of the last and first terms.-/
theorem sum_range_sub {G : Type u_1} [add_comm_group G] (f : ℕ → G) (n : ℕ) : (finset.sum (range n) fun (i : ℕ) => f (i + 1) - f i) = f n - f 0 := sorry
theorem sum_range_sub' {G : Type u_1} [add_comm_group G] (f : ℕ → G) (n : ℕ) : (finset.sum (range n) fun (i : ℕ) => f i - f (i + 1)) = f 0 - f n := sorry
/-- A telescoping product along `{0, ..., n-1}` of a commutative group valued function
reduces to the ratio of the last and first factors.-/
theorem prod_range_div {M : Type u_1} [comm_group M] (f : ℕ → M) (n : ℕ) : (finset.prod (range n) fun (i : ℕ) => f (i + 1) * (f i⁻¹)) = f n * (f 0⁻¹) := sorry
theorem prod_range_div' {M : Type u_1} [comm_group M] (f : ℕ → M) (n : ℕ) : (finset.prod (range n) fun (i : ℕ) => f i * (f (i + 1)⁻¹)) = f 0 * (f n⁻¹) := sorry
/--
A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
reduces to the difference of the last and first terms
when the function we are summing is monotone.
-/
theorem sum_range_sub_of_monotone {f : ℕ → ℕ} (h : monotone f) (n : ℕ) : (finset.sum (range n) fun (i : ℕ) => f (i + 1) - f i) = f n - f 0 := sorry
@[simp] theorem prod_const {α : Type u} {β : Type v} {s : finset α} [comm_monoid β] (b : β) : (finset.prod s fun (x : α) => b) = b ^ card s := sorry
theorem pow_eq_prod_const {β : Type v} [comm_monoid β] (b : β) (n : ℕ) : b ^ n = finset.prod (range n) fun (k : ℕ) => b := sorry
theorem prod_pow {α : Type u} {β : Type v} [comm_monoid β] (s : finset α) (n : ℕ) (f : α → β) : (finset.prod s fun (x : α) => f x ^ n) = (finset.prod s fun (x : α) => f x) ^ n := sorry
-- `to_additive` fails on this lemma, so we prove it manually below
theorem prod_flip {β : Type v} [comm_monoid β] {n : ℕ} (f : ℕ → β) : (finset.prod (range (n + 1)) fun (r : ℕ) => f (n - r)) = finset.prod (range (n + 1)) fun (k : ℕ) => f k := sorry
theorem sum_involution {α : Type u} {β : Type v} [add_comm_monoid β] {s : finset α} {f : α → β} (g : (a : α) → a ∈ s → α) (h : ∀ (a : α) (ha : a ∈ s), f a + f (g a ha) = 0) (g_ne : ∀ (a : α) (ha : a ∈ s), f a ≠ 0 → g a ha ≠ a) (g_mem : ∀ (a : α) (ha : a ∈ s), g a ha ∈ s) (g_inv : ∀ (a : α) (ha : a ∈ s), g (g a ha) (g_mem a ha) = a) : (finset.sum s fun (x : α) => f x) = 0 := sorry
/-- The product of the composition of functions `f` and `g`, is the product
over `b ∈ s.image g` of `f b` to the power of the cardinality of the fibre of `b` -/
theorem prod_comp {α : Type u} {β : Type v} {γ : Type w} [comm_monoid β] [DecidableEq γ] {s : finset α} (f : γ → β) (g : α → γ) : (finset.prod s fun (a : α) => f (g a)) =
finset.prod (image g s) fun (b : γ) => f b ^ card (filter (fun (a : α) => g a = b) s) := sorry
theorem sum_piecewise {α : Type u} {β : Type v} [add_comm_monoid β] [DecidableEq α] (s : finset α) (t : finset α) (f : α → β) (g : α → β) : (finset.sum s fun (x : α) => piecewise t f g x) =
(finset.sum (s ∩ t) fun (x : α) => f x) + finset.sum (s \ t) fun (x : α) => g x := sorry
theorem sum_inter_add_sum_diff {α : Type u} {β : Type v} [add_comm_monoid β] [DecidableEq α] (s : finset α) (t : finset α) (f : α → β) : ((finset.sum (s ∩ t) fun (x : α) => f x) + finset.sum (s \ t) fun (x : α) => f x) = finset.sum s fun (x : α) => f x := sorry
theorem mul_prod_diff_singleton {α : Type u} {β : Type v} [comm_monoid β] [DecidableEq α] {s : finset α} {i : α} (h : i ∈ s) (f : α → β) : (f i * finset.prod (s \ singleton i) fun (x : α) => f x) = finset.prod s fun (x : α) => f x := sorry
/-- A product can be partitioned into a product of products, each equivalent under a setoid. -/
theorem sum_partition {α : Type u} {β : Type v} {s : finset α} {f : α → β} [add_comm_monoid β] (R : setoid α) [DecidableRel setoid.r] : (finset.sum s fun (x : α) => f x) =
finset.sum (image quotient.mk s)
fun (xbar : quotient R) => finset.sum (filter (fun (y : α) => quotient.mk y = xbar) s) fun (x : α) => f x := sorry
/-- If we can partition a product into subsets that cancel out, then the whole product cancels. -/
theorem prod_cancels_of_partition_cancels {α : Type u} {β : Type v} {s : finset α} {f : α → β} [comm_monoid β] (R : setoid α) [DecidableRel setoid.r] (h : ∀ (x : α), x ∈ s → (finset.prod (filter (fun (y : α) => y ≈ x) s) fun (a : α) => f a) = 1) : (finset.prod s fun (a : α) => f a) = 1 := sorry
theorem sum_update_of_not_mem {α : Type u} {β : Type v} [add_comm_monoid β] [DecidableEq α] {s : finset α} {i : α} (h : ¬i ∈ s) (f : α → β) (b : β) : (finset.sum s fun (x : α) => function.update f i b x) = finset.sum s fun (x : α) => f x := sorry
theorem prod_update_of_mem {α : Type u} {β : Type v} [comm_monoid β] [DecidableEq α] {s : finset α} {i : α} (h : i ∈ s) (f : α → β) (b : β) : (finset.prod s fun (x : α) => function.update f i b x) = b * finset.prod (s \ singleton i) fun (x : α) => f x := sorry
/-- If a product of a `finset` of size at most 1 has a given value, so
do the terms in that product. -/
theorem eq_of_card_le_one_of_prod_eq {α : Type u} {β : Type v} [comm_monoid β] {s : finset α} (hc : card s ≤ 1) {f : α → β} {b : β} (h : (finset.prod s fun (x : α) => f x) = b) (x : α) (H : x ∈ s) : f x = b := sorry
/-- If a sum of a `finset` of size at most 1 has a given value, so do
the terms in that sum. -/
theorem eq_of_card_le_one_of_sum_eq {α : Type u} {γ : Type w} [add_comm_monoid γ] {s : finset α} (hc : card s ≤ 1) {f : α → γ} {b : γ} (h : (finset.sum s fun (x : α) => f x) = b) (x : α) (H : x ∈ s) : f x = b := sorry
/-- If a function applied at a point is 1, a product is unchanged by
removing that point, if present, from a `finset`. -/
theorem prod_erase {α : Type u} {β : Type v} [comm_monoid β] [DecidableEq α] (s : finset α) {f : α → β} {a : α} (h : f a = 1) : (finset.prod (erase s a) fun (x : α) => f x) = finset.prod s fun (x : α) => f x := sorry
/-- If a product is 1 and the function is 1 except possibly at one
point, it is 1 everywhere on the `finset`. -/
theorem eq_one_of_prod_eq_one {α : Type u} {β : Type v} [comm_monoid β] {s : finset α} {f : α → β} {a : α} (hp : (finset.prod s fun (x : α) => f x) = 1) (h1 : ∀ (x : α), x ∈ s → x ≠ a → f x = 1) (x : α) (H : x ∈ s) : f x = 1 := sorry
theorem prod_pow_boole {α : Type u} {β : Type v} [comm_monoid β] [DecidableEq α] (s : finset α) (f : α → β) (a : α) : (finset.prod s fun (x : α) => f x ^ ite (a = x) 1 0) = ite (a ∈ s) (f a) 1 := sorry
/-- If `f = g = h` everywhere but at `i`, where `f i = g i + h i`, then the product of `f` over `s`
is the sum of the products of `g` and `h`. -/
theorem prod_add_prod_eq {α : Type u} {β : Type v} [comm_semiring β] {s : finset α} {i : α} {f : α → β} {g : α → β} {h : α → β} (hi : i ∈ s) (h1 : g i + h i = f i) (h2 : ∀ (j : α), j ∈ s → j ≠ i → g j = f j) (h3 : ∀ (j : α), j ∈ s → j ≠ i → h j = f j) : ((finset.prod s fun (i : α) => g i) + finset.prod s fun (i : α) => h i) = finset.prod s fun (i : α) => f i := sorry
theorem sum_update_of_mem {α : Type u} {β : Type v} [add_comm_monoid β] [DecidableEq α] {s : finset α} {i : α} (h : i ∈ s) (f : α → β) (b : β) : (finset.sum s fun (x : α) => function.update f i b x) = b + finset.sum (s \ singleton i) fun (x : α) => f x := sorry
theorem sum_nsmul {α : Type u} {β : Type v} [add_comm_monoid β] (s : finset α) (n : ℕ) (f : α → β) : (finset.sum s fun (x : α) => n •ℕ f x) = n •ℕ finset.sum s fun (x : α) => f x :=
prod_pow s n fun (x : α) => f x
@[simp] theorem sum_const {α : Type u} {β : Type v} {s : finset α} [add_comm_monoid β] (b : β) : (finset.sum s fun (x : α) => b) = card s •ℕ b :=
prod_const b
theorem card_eq_sum_ones {α : Type u} (s : finset α) : card s = finset.sum s fun (_x : α) => 1 := sorry
theorem sum_const_nat {α : Type u} {s : finset α} {m : ℕ} {f : α → ℕ} (h₁ : ∀ (x : α), x ∈ s → f x = m) : (finset.sum s fun (x : α) => f x) = card s * m := sorry
@[simp] theorem sum_boole {α : Type u} {β : Type v} {s : finset α} {p : α → Prop} [semiring β] {hp : decidable_pred p} : (finset.sum s fun (x : α) => ite (p x) 1 0) = ↑(card (filter p s)) := sorry
theorem sum_nat_cast {α : Type u} {β : Type v} [add_comm_monoid β] [HasOne β] (s : finset α) (f : α → ℕ) : ↑(finset.sum s fun (x : α) => f x) = finset.sum s fun (x : α) => ↑(f x) :=
add_monoid_hom.map_sum (nat.cast_add_monoid_hom β) f s
theorem sum_int_cast {α : Type u} {β : Type v} [add_comm_group β] [HasOne β] (s : finset α) (f : α → ℤ) : ↑(finset.sum s fun (x : α) => f x) = finset.sum s fun (x : α) => ↑(f x) :=
add_monoid_hom.map_sum (int.cast_add_hom β) f s
theorem sum_comp {α : Type u} {β : Type v} {γ : Type w} [add_comm_monoid β] [DecidableEq γ] {s : finset α} (f : γ → β) (g : α → γ) : (finset.sum s fun (a : α) => f (g a)) =
finset.sum (image g s) fun (b : γ) => card (filter (fun (a : α) => g a = b) s) •ℕ f b :=
prod_comp f fun (a : α) => g a
theorem sum_range_succ' {β : Type v} [add_comm_monoid β] (f : ℕ → β) (n : ℕ) : (finset.sum (range (n + 1)) fun (i : ℕ) => f i) = (finset.sum (range n) fun (i : ℕ) => f (i + 1)) + f 0 :=
prod_range_succ' fun (k : ℕ) => f k
theorem sum_flip {β : Type v} [add_comm_monoid β] {n : ℕ} (f : ℕ → β) : (finset.sum (range (n + 1)) fun (i : ℕ) => f (n - i)) = finset.sum (range (n + 1)) fun (i : ℕ) => f i :=
prod_flip f
/-- Moving to the opposite additive commutative monoid commutes with summing. -/
@[simp] theorem op_sum {α : Type u} {β : Type v} [add_comm_monoid β] {s : finset α} (f : α → β) : opposite.op (finset.sum s fun (x : α) => f x) = finset.sum s fun (x : α) => opposite.op (f x) :=
add_equiv.map_sum opposite.op_add_equiv (fun (x : α) => f x) s
@[simp] theorem unop_sum {α : Type u} {β : Type v} [add_comm_monoid β] {s : finset α} (f : α → (βᵒᵖ)) : opposite.unop (finset.sum s fun (x : α) => f x) = finset.sum s fun (x : α) => opposite.unop (f x) :=
add_equiv.map_sum (add_equiv.symm opposite.op_add_equiv) (fun (x : α) => f x) s
@[simp] theorem sum_neg_distrib {α : Type u} {β : Type v} {s : finset α} {f : α → β} [add_comm_group β] : (finset.sum s fun (x : α) => -f x) = -finset.sum s fun (x : α) => f x :=
sum_hom s Neg.neg
@[simp] theorem card_sigma {α : Type u} {σ : α → Type u_1} (s : finset α) (t : (a : α) → finset (σ a)) : card (finset.sigma s t) = finset.sum s fun (a : α) => card (t a) :=
multiset.card_sigma (val s) fun (a : α) => (fun (a : α) => val (t a)) a
theorem card_bUnion {α : Type u} {β : Type v} [DecidableEq β] {s : finset α} {t : α → finset β} (h : ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → x ≠ y → disjoint (t x) (t y)) : card (finset.bUnion s t) = finset.sum s fun (u : α) => card (t u) := sorry
theorem card_bUnion_le {α : Type u} {β : Type v} [DecidableEq β] {s : finset α} {t : α → finset β} : card (finset.bUnion s t) ≤ finset.sum s fun (a : α) => card (t a) := sorry
theorem card_eq_sum_card_fiberwise {α : Type u} {β : Type v} [DecidableEq β] {f : α → β} {s : finset α} {t : finset β} (H : ∀ (x : α), x ∈ s → f x ∈ t) : card s = finset.sum t fun (a : β) => card (filter (fun (x : α) => f x = a) s) := sorry
theorem card_eq_sum_card_image {α : Type u} {β : Type v} [DecidableEq β] (f : α → β) (s : finset α) : card s = finset.sum (image f s) fun (a : β) => card (filter (fun (x : α) => f x = a) s) :=
card_eq_sum_card_fiberwise fun (_x : α) => mem_image_of_mem fun (x : α) => f x
theorem gsmul_sum {α : Type u} {β : Type v} [add_comm_group β] {f : α → β} {s : finset α} (z : ℤ) : (z •ℤ finset.sum s fun (a : α) => f a) = finset.sum s fun (a : α) => z •ℤ f a :=
Eq.symm (sum_hom s (gsmul z))
@[simp] theorem sum_sub_distrib {α : Type u} {β : Type v} {s : finset α} {f : α → β} {g : α → β} [add_comm_group β] : (finset.sum s fun (x : α) => f x - g x) = (finset.sum s fun (x : α) => f x) - finset.sum s fun (x : α) => g x := sorry
theorem prod_eq_zero {α : Type u} {β : Type v} {s : finset α} {a : α} {f : α → β} [comm_monoid_with_zero β] (ha : a ∈ s) (h : f a = 0) : (finset.prod s fun (x : α) => f x) = 0 := sorry
theorem prod_boole {α : Type u} {β : Type v} [comm_monoid_with_zero β] {s : finset α} {p : α → Prop} [decidable_pred p] : (finset.prod s fun (i : α) => ite (p i) 1 0) = ite (∀ (i : α), i ∈ s → p i) 1 0 := sorry
theorem prod_eq_zero_iff {α : Type u} {β : Type v} {s : finset α} {f : α → β} [comm_monoid_with_zero β] [nontrivial β] [no_zero_divisors β] : (finset.prod s fun (x : α) => f x) = 0 ↔ ∃ (a : α), ∃ (H : a ∈ s), f a = 0 := sorry
theorem prod_ne_zero_iff {α : Type u} {β : Type v} {s : finset α} {f : α → β} [comm_monoid_with_zero β] [nontrivial β] [no_zero_divisors β] : (finset.prod s fun (x : α) => f x) ≠ 0 ↔ ∀ (a : α), a ∈ s → f a ≠ 0 := sorry
@[simp] theorem prod_inv_distrib' {α : Type u} {β : Type v} {s : finset α} {f : α → β} [comm_group_with_zero β] : (finset.prod s fun (x : α) => f x⁻¹) = ((finset.prod s fun (x : α) => f x)⁻¹) := sorry
end finset
namespace list
theorem prod_to_finset {α : Type u} {M : Type u_1} [DecidableEq α] [comm_monoid M] (f : α → M) {l : List α} (hl : nodup l) : finset.prod (to_finset l) f = prod (map f l) := sorry
end list
namespace multiset
@[simp] theorem to_finset_sum_count_eq {α : Type u} [DecidableEq α] (s : multiset α) : (finset.sum (to_finset s) fun (a : α) => count a s) = coe_fn card s := sorry
theorem count_sum' {α : Type u} {β : Type v} [DecidableEq α] {s : finset β} {a : α} {f : β → multiset α} : count a (finset.sum s fun (x : β) => f x) = finset.sum s fun (x : β) => count a (f x) := sorry
@[simp] theorem to_finset_sum_count_smul_eq {α : Type u} [DecidableEq α] (s : multiset α) : (finset.sum (to_finset s) fun (a : α) => count a s •ℕ (a ::ₘ 0)) = s := sorry
theorem exists_smul_of_dvd_count {α : Type u} [DecidableEq α] (s : multiset α) {k : ℕ} (h : ∀ (a : α), k ∣ count a s) : ∃ (u : multiset α), s = k •ℕ u := sorry
end multiset
@[simp] theorem nat.coe_prod {α : Type u} {R : Type u_1} [comm_semiring R] (f : α → ℕ) (s : finset α) : ↑(finset.prod s fun (i : α) => f i) = finset.prod s fun (i : α) => ↑(f i) :=
ring_hom.map_prod (nat.cast_ring_hom R) (fun (i : α) => f i) s
@[simp] theorem int.coe_prod {α : Type u} {R : Type u_1} [comm_ring R] (f : α → ℤ) (s : finset α) : ↑(finset.prod s fun (i : α) => f i) = finset.prod s fun (i : α) => ↑(f i) :=
ring_hom.map_prod (int.cast_ring_hom R) (fun (i : α) => f i) s
@[simp] theorem units.coe_prod {α : Type u} {M : Type u_1} [comm_monoid M] (f : α → units M) (s : finset α) : ↑(finset.prod s fun (i : α) => f i) = finset.prod s fun (i : α) => ↑(f i) :=
monoid_hom.map_prod (units.coe_hom M) (fun (i : α) => f i) s
|
56706514e4847064782e660e42acdb69cf4275f6 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/unfold_rec4.lean | 509c56cab6034af098097149112d9684b178dbf1 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 183 | lean | open nat
definition f [unfold 1] (n : ℕ) : ℕ :=
by induction n with n fn; exact zero; exact succ (succ fn)
example (n : ℕ) : f (succ (succ n)) = sorry :=
begin
unfold f,
end
|
490d3b00a2f7dd2ef0bb5797841c96e81d819e1b | 43390109ab88557e6090f3245c47479c123ee500 | /src/Euclid_old/tarski_1.lean | b7d4ec8050316dfbfb1593da1422290be8e2eb02 | [
"Apache-2.0"
] | permissive | Ja1941/xena-UROP-2018 | 41f0956519f94d56b8bf6834a8d39473f4923200 | b111fb87f343cf79eca3b886f99ee15c1dd9884b | refs/heads/master | 1,662,355,955,139 | 1,590,577,325,000 | 1,590,577,325,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 29,561 | lean | import euclid.axioms data.set tactic.interactive
open classical
namespace Euclidean_plane
variables {point : Type} [Euclidean_plane point]
local attribute [instance] prop_decidable
--Conclusions from the first 5 axioms
theorem eqd.refl (a b : point) : eqd a b a b :=
eqd_trans (eqd_refl b a) (eqd_refl b a)
theorem eqd.symm {a b c d : point} : eqd a b c d → eqd c d a b :=
λ h, eqd_trans h (eqd.refl a b)
theorem eqd.trans {a b c d e f: point} : eqd a b c d → eqd c d e f → eqd a b e f :=
assume h h1,
eqd_trans h.symm h1
theorem two4 {a b c d : point} : eqd a b c d → eqd b a c d := assume h, eqd_trans (eqd_refl a b) h
theorem two5 {a b c d : point} : eqd a b c d → eqd a b d c := assume h, eqd.trans h (eqd_refl c d)
theorem eqd.flip {a b c d : point} : eqd a b c d → eqd b a d c := assume h, two4 (two5 h)
instance point_setoid : setoid (point × point) :=
{ r := λ ⟨a,b⟩ ⟨c,d⟩, eqd a b c d,
iseqv := ⟨ λ ⟨a,b⟩, eqd.refl a b, λ ⟨a,b⟩ ⟨c,d⟩, eqd.symm, λ ⟨a,b⟩ ⟨c,d⟩ ⟨e,f⟩, eqd.trans⟩
}
definition distance_values (point : Type) [Euclidean_plane point] :=
quotient (@Euclidean_plane.point_setoid point _)
theorem refl_dist (a b : point) : (a,b) ≈ (b,a) := eqd_refl a b
theorem two7 {a b c d : point} : eqd a b c d → a ≠ b → c ≠ d :=
begin
intros h h1 h2,
subst d,
exact h1 (id_eqd h)
end
theorem two8 (a b : point) : eqd a a b b :=
let ⟨x, h⟩ := seg_cons a b b b in
have a = x, from id_eqd h.2,
by rw ←this at h; exact h.2
def afs (a b c d a' b' c' d' : point) : Prop := B a b c ∧ B a' b' c' ∧ eqd a b a' b'
∧ eqd b c b' c' ∧ eqd a d a' d' ∧ eqd b d b' d'
theorem afive_seg {a b c d a' b' c' d' : point} : afs a b c d a' b' c' d' →
a ≠ b → eqd c d c' d' :=
λ h h1, five_seg h1 h.1 h.2.1 h.2.2.1 h.2.2.2.1 h.2.2.2.2.1 h.2.2.2.2.2
theorem two11 {a b c a' b' c' : point} : B a b c → B a' b' c' → eqd a b a' b'
→ eqd b c b' c' → eqd a c a' c' :=
begin
intros,
have : afs a b c a a' b' c' a',
repeat {split}; try {assumption},
exact two8 _ _,
exact a_3.flip,
cases em (a = b),
have : eqd a' b' a a,
apply eqd.symm,
rw ←h at a_3,
assumption,
have : a' = b',
apply id_eqd,
assumption,
rw ←h at a_4,
rw ←this at a_4,
assumption,
apply eqd.flip,
apply afive_seg this,
assumption
end
theorem two12 (a b c q : point) : q ≠ a → ∃! x, B q a x ∧ eqd a x b c :=
begin
intro h,
cases seg_cons a b c q with x h1,
existsi x,
split,
assumption,
intros y hy,
cases h1 with h2 h3,
cases hy with h4 h5,
by_contradiction h_1,
have h6 : eqd a x a y,
exact eqd.trans h3 h5.symm,
have h7 : eqd q x q y,
apply two11 h2 h4,
exact eqd.refl _ _,
assumption,
have : afs q a x x q a x y,
repeat {split}; try {assumption},
exact eqd.refl _ _,
exact eqd.refl _ _,
have : eqd x x x y,
apply afive_seg this h,
have : x = y,
exact id_eqd this.symm,
have : y = x,
exact eq.symm this,
contradiction
end
-- Properties of B
theorem three1 (a b : point) : B a b b :=
begin
cases seg_cons b b b a with x h,
have : b = x,
exact id_eqd h.2,
rw ←this at h,
exact h.1
end
theorem B.symm {a b c : point} : B a b c → B c b a :=
begin
intro h,
cases pasch h (three1 b c) with x hx,
have : b = x,
exact bet_same hx.1,
rw ←this at hx,
exact hx.2
end
theorem three2 (a b c : point) : B a b c ↔ B c b a :=
begin
split,
exact B.symm,
intro h,
exact h.symm
end
theorem three3 (a b : point) : B a a b :=
begin
exact (three1 b a).symm
end
theorem three4 {a b c: point} : B a b c → B b a c → a = b :=
begin
intros h h1,
cases pasch h h1 with x hx,
have : a = x,
exact bet_same hx.2,
have : b = x,
exact bet_same hx.1,
simp *
end
theorem three5a {a b c d : point} : B a b d → B b c d → B a b c:=
begin
intros h h1,
cases pasch h h1 with x hx,
have : b = x,
exact bet_same hx.1,
rw ←this at hx,
exact hx.2.symm,
end
theorem three6a {a b c d : point} : B a b c → B a c d → B b c d :=
begin
intros h h1,
exact (three5a h1.symm h.symm).symm
end
theorem three7a {a b c d : point} : B a b c → B b c d → b ≠ c
→ B a c d :=
begin
intros h h1 h2,
cases seg_cons c c d a with x hx,
have : B b c x,
exact three6a h hx.1,
cases two12 c c d b h2 with y hy,
have : x = y,
apply hy.2,
split,
exact this, exact hx.2,
have : d = y,
apply hy.2,
split,
exact h1, exact eqd.refl c d,
have : x = d,
simp *,
rw this at hx,
exact hx.1
end
theorem three5b {a b c d : point} : B a b d → B b c d → B a c d :=
begin
intros h h1,
cases em (b = c),
rwa h_1 at h,
exact three7a (three5a h h1) h1 h_1
end
theorem three6b {a b c d : point} : B a b c → B a c d → B a b d :=
begin
intros h h1,
cases em (c = b),
rwa h_1 at h1,
exact (three7a (three6a h h1).symm h.symm h_1).symm
end
theorem three7b {a b c d : point} : B a b c → B b c d → b ≠ c
→ B a b d :=
begin
intros h h1 h2,
have h3 : B a c d,
exact three7a h h1 h2,
exact (three5b h3.symm h.symm).symm
end
theorem three13 : ∃ (x y : point), x ≠ y :=
begin
refine ⟨P1, P2, _⟩,
intro h,
apply (two_dim point).1,
rw h,
exact three3 P2 P3
end
theorem three14 (a b : point) : ∃ c, B a b c ∧ b ≠ c :=
let ⟨(x : point), y, hp⟩ := three13 in
begin
cases seg_cons b x y a with c h,
cases h with h1 h2,
have : b ≠ c,
intro hq,
have : eqd x y b b,
apply eqd.symm,
rwa ←hq at h2,
exact hp (id_eqd this) ,
constructor, exact ⟨h1, this⟩
end
theorem three17 {a b c a' b' p : point} : B a b c → B a' b' c
→ B a p a' → ∃ q, B p q c ∧ B b q b' :=
begin
intros h1 h2 h3,
cases pasch h3 h2.symm with x h4,
cases pasch h1.symm h4.2 with y h5,
have : B p y c,
exact three5b h4.1 h5.2,
constructor, exact ⟨this, h5.1⟩
end
-- cong + col
def ifs (a b c d a' b' c' d' : point) : Prop := B a b c ∧ B a' b' c' ∧ eqd a c a' c'
∧ eqd b c b' c' ∧ eqd a d a' d' ∧ eqd c d c' d'
theorem four2 {a b c d a' b' c' d' : point} : ifs a b c d a' b' c' d' → eqd b d b' d' :=
begin
intro h,
cases h with h h1,
cases h1 with h1 h2,
cases h2 with h2 h3,
cases h3 with h3 h4,
cases h4 with h4 h5,
cases em (a = c),
have : a' = c',
have : eqd c c a' c',
rwa h_1 at h2,
exact id_eqd this.symm,
have h6 : c = b,
apply bet_same,
rwa h_1 at h,
have h7 : b' = c',
have : eqd b b b' c',
rwa h6 at h3,
exact id_eqd this.symm,
rw [h6, ←h7] at h5,
exact h5,
cases three14 a c with e he,
cases seg_cons c' c e a' with e' he',
have : afs a c e d a' c' e' d',
repeat {split};
try{assumption},
exact he.1,
exact he'.1,
exact he'.2.symm,
have : eqd e d e' d',
exact afive_seg this h_1,
have : afs e c b d e' c' b' d',
repeat {split};
try{assumption},
exact (three6a h he.1).symm,
exact (three6a h1 he'.1).symm,
exact he'.2.symm.flip,
exact h3.flip,
exact afive_seg this he.2.symm
end
theorem four3 {a b c a' b' c' : point} : B a b c → B a' b' c' → eqd a c a' c'
→ eqd b c b' c' → eqd a b a' b' :=
begin
intros h h1 h2 h3,
have : ifs a b c a a' b' c' a',
repeat {split};
try{assumption},
exact two8 a a',
exact h2.flip,
exact (four2 this).flip
end
def cong (a b c a' b' c' : point) : Prop := eqd a b a' b' ∧ eqd b c b' c' ∧ eqd a c a' c'
@[simp] theorem cong.refl (a b c : point) : cong a b c a b c :=
begin
repeat {split};
exact eqd.refl _ _
end
theorem cong.symm {a b c a' b' c' : point} : cong a b c a' b' c' → cong a' b' c' a b c :=
begin
intro h,
split,
exact h.1.symm,
split,
exact h.2.1.symm,
exact h.2.2.symm
end
theorem cong.trans {a b c a' b' c' a'' b'' c'' : point} : cong a b c a' b' c' → cong a' b' c' a'' b'' c'' → cong a b c a'' b'' c'' :=
begin
intros h h1,
split,
exact eqd.trans h.1 h1.1,
split,
exact eqd.trans h.2.1 h1.2.1,
exact eqd.trans h.2.2 h1.2.2
end
lemma four4 {a b c a' b' c' : point} : cong a b c a' b' c' → cong a c b a' c' b' ∧ cong b a c b' a' c' ∧
cong b c a b' c' a' ∧ cong c a b c' a' b' ∧ cong c b a c' b' a' :=
λ h, ⟨⟨h.2.2, h.2.1.flip, h.1⟩, ⟨h.1.flip, h.2.2, h.2.1⟩, ⟨h.2.1, h.2.2.flip, h.1.flip⟩,
⟨h.2.2.flip, h.1, h.2.1.flip⟩, ⟨h.2.1.flip, h.1.flip, h.2.2.flip⟩⟩
theorem four5 {a b c a' c' : point} : B a b c → eqd a c a' c'
→ ∃ b', B a' b' c' ∧ cong a b c a' b' c' :=
begin
intros h h1,
cases three14 c' a' with d' hd,
cases seg_cons a' a b d' with b' hb,
cases seg_cons b' b c d' with c'' hc,
have h2 : B a' b' c'' ∧ B d' a' c'',
split,
exact three6a hb.1 hc.1,
exact three6b hb.1 hc.1,
have h3 : eqd a' c'' a c,
exact two11 h2.1 h hb.2 hc.2,
have h4 : c' = c'',
apply unique_of_exists_unique (two12 a' a c d' hd.2.symm),
split,
exact hd.1.symm,
exact h1.symm,
split,
exact h2.2,
exact h3,
rw ←h4 at *,
existsi b',
split,
exact h2.1,
unfold cong,
split,
apply four3 h h2.1,
exact h3.symm,
exact hc.2.symm,
split,
exact hc.2.symm,
exact h3.symm
end
theorem four6 {a b c a' b' c' : point} : B a b c → cong a b c a' b' c' → B a' b' c' :=
begin
intros h h1,
cases h1 with h1 h2,
cases h2 with h2 h3,
cases four5 h h3 with b'' hb,
cases hb with hb hb1,
cases hb1 with hb1 hb2,
cases hb2 with hb2 hb3,
have : ifs a' b'' c' b'' a' b'' c' b',
repeat {split};
try {assumption},
exact eqd.trans hb3.symm h3,
exact eqd.refl _ _,
exact eqd.trans hb1.symm h1,
have : eqd b'' c' b' c',
exact eqd.trans hb2.symm h2,
exact this.flip,
have : b'' = b',
have h4 : eqd b'' b'' b'' b',
exact four2 this,
exact id_eqd h4.symm,
rwa this at *
end
def col (a b c : point) : Prop := B a b c ∨ B b c a ∨ B c a b
theorem four11 {a b c : point} : col a b c → col a c b ∧ col b a c ∧ col b c a ∧ col c a b ∧ col c b a :=
begin
intro h,
cases h with h1 h2,
have : B c b a, exact h1.symm,
repeat {split}; unfold col;
simp *,
cases h2 with h2 h3,
have : B a c b, exact h2.symm,
repeat {split};unfold col;
simp *,
have : B b a c, exact h3.symm,
repeat {split};unfold col;
simp *
end
theorem four10 {a b c : point} : ¬col a b c → ¬col a c b ∧ ¬col b a c ∧ ¬col b c a ∧ ¬col c a b ∧ ¬col c b a :=
begin
intro h,
split,
intro h_1,
exact h (four11 h_1).1,
split,
intro h_1,
exact h (four11 h_1).2.1,
split,
intro h_1,
exact h (four11 h_1).2.2.2.1,
split,
intro h_1,
exact h (four11 h_1).2.2.1,
intro h_1,
exact h (four11 h_1).2.2.2.2
end
theorem four12 (a b : point) : col a a b :=
begin
unfold col,
left, exact three3 a b
end
theorem four13 {a b c a' b' c' : point} : col a b c → cong a b c a' b' c' → col a' b' c' :=
begin
intros h h1,
unfold col,
cases h,
have : B a' b' c', exact four6 h h1,
simp *,
cases h,
have : B b' c' a', exact four6 h (four4 h1).2.2.1,
simp *,
have : B c' a' b', exact four6 h (four4 h1).2.2.2.1,
simp *,
end
theorem four14 {a b c a' b' : point} : col a b c → eqd a b a' b' → ∃ c', cong a b c a' b' c' :=
begin
intros h1 h,
cases h1 with h1 h2,
cases seg_cons b' b c a' with c' hc,
existsi c',
unfold cong,
split,
exact h,
split,
exact hc.2.symm,
exact two11 h1 hc.1 h hc.2.symm,
cases h2 with h2 h3,
cases four5 h2 h.flip with c' hc,
constructor, exact (four4 hc.2).2.2.2.1,
cases seg_cons a' a c b' with c' hc,
existsi c',
unfold cong,
split,
exact h,
split,
exact two11 h3.symm hc.1 h.flip hc.2.symm,
exact hc.2.symm
end
def fs (a b c d a' b' c' d' : point) : Prop := col a b c ∧ cong a b c a' b' c' ∧
eqd a d a' d' ∧ eqd b d b' d'
theorem four16 {a b c d a' b' c' d' : point} : fs a b c d a' b' c' d' → a ≠ b → eqd c d c' d' :=
begin
intros h1 h,
cases h1 with h1 h2,
cases h2 with h2 h3,
cases h3 with h3 h4,
cases h1 with ha hbc,
exact five_seg h ha (four6 ha h2) h2.1 h2.2.1 h3 h4,
cases hbc with hb hc,
have : ifs b c a d b' c' a' d',
repeat {split};
try {assumption},
exact four6 hb (four4 h2).2.2.1,
exact h2.1.flip,
exact h2.2.2.flip,
exact four2 this,
rw three2 at hc,
have : cong b a c b' a' c',
unfold cong,
split,
exact h2.1.flip,
split,
exact h2.2.2,
exact h2.2.1,
exact five_seg h.symm hc (four6 hc this) h2.1.flip h2.2.2 h4 h3
end
theorem four17 {a b c p q : point} : a ≠ b → col a b c → eqd a p a q → eqd b p b q → eqd c p c q :=
begin
intros h h1 h2 h3,
have : fs a b c p a b c q,
unfold fs,
repeat {split}; try {assumption};
exact eqd.refl _ _,
exact four16 this h
end
theorem four18 {a b c c' : point} : a ≠ b → col a b c → eqd a c a c' → eqd b c b c' → c = c':=
begin
intros h h3 h1 h2,
have : eqd c c c c',
exact four17 h h3 h1 h2,
exact id_eqd this.symm
end
theorem four19 {a b c b' : point} : B a b c → eqd a b a b' → eqd b c b' c → b = b' :=
begin
intros h h1 h2,
cases em (a = c) with h3 h4,
rw ←h3 at *,
have : a = b, exact bet_same h,
rw this at *,
exact id_eqd h1.symm,
have : col a c b,
right, left,
exact h.symm,
exact four18 h4 this h1 h2.flip
end
-- Ordering collinear points & Comparing distances
theorem five1 {a b c d : point} : a ≠ b → B a b c → B a b d → B a c d ∨ B a d c :=
begin
intros h h1 h2,
cases em (c = d),
left, rw h_1 at *, exact three1 a d,
cases seg_cons d d c a with c' hc,
cases seg_cons c c d a with d' hd,
cases seg_cons c' c b d with b' ha,
cases seg_cons d' d b c with b'' hb,
have h_2 : d ≠ c',
intro h_2,
rw ←h_2 at hc,
have : c = d,
exact id_eqd hc.2.symm.flip,
contradiction,
have h_3 : d' ≠ c,
intro h_3,
rw h_3 at hd,
have : c = d,
exact id_eqd hd.2.symm,
contradiction,
have h3 : B b d c',
exact three6a h2 hc.1,
have h4 : eqd b c' b'' c,
exact two11 h3 hb.1.symm hb.2.symm.flip (eqd.trans hc.2 hd.2.symm.flip),
have h5 : B b c' b',
exact three7a h3 ha.1 h_2,
have h_4 : B b c d',
exact three6a h1 hd.1,
have h6 : B b'' c b,
exact three7a hb.1.symm h_4.symm h_3,
have h7 : eqd b b' b'' b,
exact two11 h5 h6 h4 ha.2,
have h_5 : B a b b',
have : B a d b',
exact three7b hc.1 ha.1 h_2,
exact three6b h2 this,
have h_6 : B a b b'',
have : B a c b'',
exact three7b hd.1 hb.1 h_3.symm,
exact three6b h1 this,
have h8 : b' = b'',
apply unique_of_exists_unique (two12 b b b' a h),
split,
exact h_5,
exact eqd.refl b b',
split,
exact h_6,
exact two4 h7.symm,
rw ←h8 at *,
have h9 : afs b c d' c' b' c' d c,
repeat {split}; try {assumption},
exact ha.1.symm,
exact ha.2.symm.flip,
exact eqd.trans hd.2 hc.2.symm.flip,
exact two5 (eqd.refl c c'),
cases em (b = c),
left,
rw ←h_7, exact h2,
have h10 : eqd c d c' d',
exact (afive_seg h9 h_7).symm.flip,
cases pasch hd.1.symm hc.1.symm with e he,
have h11 : ifs d e d' c d e d' c',
repeat {split}; try {assumption},
exact he.2,
exact he.2,
exact eqd.refl d d',
exact eqd.refl e d',
exact hc.2.symm,
exact eqd.trans hd.2.flip h10.flip,
have h12 : ifs c e c' d c e c' d',
repeat {split}; try {assumption},
exact he.1,
exact he.1,
exact eqd.refl c c',
exact eqd.refl e c',
exact hd.2.symm,
exact eqd.trans hc.2.flip h10,
have h_8 : eqd e c e c',
exact four2 h11,
have h_9 : eqd e d e d',
exact four2 h12,
cases em (c = c'),
rw ←h_10 at hc,
right, exact hc.1,
cases seg_cons c c d' c' with p hp,
cases seg_cons c c e d' with r hr,
cases seg_cons r r p p with q hq,
have h13 : afs d' c r p p c e d',
repeat {split},
exact hr.1,
exact three5a hp.1.symm he.1,
exact hp.2.symm.flip,
exact hr.2,
exact two4 (eqd.refl p d'),
exact hp.2,
have h_11 : eqd r p e d',
exact afive_seg h13 h_3,
have h_12 : eqd r q e d,
exact eqd.trans hq.2 (eqd.trans h_11 h_9.symm),
have h14 : afs d' e d c p r q c,
repeat {split},
exact he.2.symm,
exact hq.1,
exact h_11.symm.flip,
exact h_12.symm,
exact hp.2.symm.flip,
exact hr.2.symm.flip,
have h_13 : eqd d' d p q,
exact two11 he.2.symm hq.1 h_11.symm.flip h_12.symm,
cases em (d' = e),
rw ←h_14 at *,
have : d' = d,
exact id_eqd h_9,
rw this at *,
left, exact hd.1,
have h_15 : eqd c q c d,
exact (afive_seg h14 h_14).symm.flip,
have h15 : eqd c p c q,
exact eqd.trans hp.2 (eqd.trans hd.2 h_15.symm),
have h_16 : r ≠ c,
intro hrc,
rw hrc at *,
have : c = e,
exact id_eqd hr.2.symm,
rw ←this at *,
have : c = c',
exact id_eqd h_8.symm,
exact h_10 this,
have h16 : col r c d',
left, exact hr.1.symm,
have h_17 : eqd d' p d' q,
exact four17 h_16 h16 hq.2.symm h15,
have h17 : col c d' b,
right, right, exact h_4,
have h18 : col c d' b',
left, exact hb.1,
have h_18 : eqd b p b q,
exact four17 h_3.symm h17 h15 h_17,
have h_19 : eqd b' p b' q,
exact four17 h_3.symm h18 h15 h_17,
have h19 : col b b' c',
right, left, exact h5.symm,
have h_20 : b ≠ b',
intro hbb,
rw ←hbb at *,
have : b = c,
exact bet_same h6,
exact h_7 this,
have h_21 : eqd c' p c' q,
exact four17 h_20 h19 h_18 h_19,
have h20 : col c' c p,
left, exact hp.1,
have h_22 : eqd p p p q,
exact four17 (ne.symm h_10) h20 h_21 h15,
have h21 : p = q,
exact id_eqd h_22.symm,
rw h21 at *,
have : d' = d,
exact id_eqd h_13,
rw this at *,
left,
exact hd.1
end
theorem five2 {a b c d : point} : a ≠ b → B a b c → B a b d → B b c d ∨ B b d c :=
begin
intros h h1 h2,
cases five1 h h1 h2,
left,
exact three6a h1 h_1,
right,
exact three6a h2 h_1
end
theorem five3 {a b c d : point} : B a b d → B a c d → B a b c ∨ B a c b :=
begin
intros h h1,
cases three14 d a with p hp,
have h2 : B p a b,
exact three5a hp.1.symm h,
have h3 : B p a c,
exact three5a hp.1.symm h1,
cases five1 hp.2.symm h2 h3 with hb hc,
left,
exact three6a h2 hb,
right,
exact three6a h3 hc
end
theorem five4 {a b c d : point} : a ≠ b → col a b c → col a b d → col a c d :=
begin
intros h h1 h2,
cases h1,
cases h2,
cases five1 h h1 h2,
left,
assumption,
right, left,
exact h_1.symm,
cases h2,
right, left,
exact (three6b h2.symm h1).symm,
right, right,
exact three7b h2 h1 h,
cases h1,
cases h2,
left,
exact three6b h1.symm h2,
cases h2,
cases five3 h1.symm h2.symm,
left,
assumption,
right, left,
exact h_1.symm,
right, right,
exact three5a h2 h1.symm,
cases h2,
right, right,
exact (three7b h1 h2 h).symm,
cases h2,
right, right,
exact three6a h2 h1.symm,
cases five2 h.symm h1.symm h2.symm,
left,
assumption,
right, left,
exact h_1.symm
end
def distle (a b c d : point) : Prop := ∃ y, B c y d ∧ eqd a b c y
theorem five5 {a b c d : point} : distle a b c d ↔ ∃ x, B a b x ∧ eqd a x c d :=
begin
split,
intro h,
cases h with y hy,
have : col c y d,
left,
exact hy.1,
cases four14 this hy.2.symm with x hx,
constructor,
split,
exact four6 hy.1 hx,
exact hx.2.2.symm,
intro h,
cases h with x hx,
unfold distle,
have : col a x b,
right, left,
exact hx.1.symm,
cases four14 this hx.2 with y hy,
constructor,
split,
exact (four6 hx.1.symm (four4 hy).2.2.1).symm,
exact hy.2.2
end
theorem five6 {a b c d a' b' c' d' : point} : distle a b c d → eqd a b a' b' →
eqd c d c' d' → distle a' b' c' d' :=
begin
intros h h1 h2,
cases h with x hx,
cases four5 hx.1 h2 with y hy,
constructor,
split,
exact hy.1,
exact eqd.trans h1.symm (eqd.trans hx.2 hy.2.1)
end
theorem distle.refl (a b : point) : distle a b a b :=
begin
constructor,
split,
exact three1 a b,
exact eqd.refl a b
end
theorem distle.trans {a b c d e f : point} : distle a b c d → distle c d e f → distle a b e f :=
begin
intros h h1,
cases h with x hx,
cases h1 with y hy,
cases four5 hx.1 hy.2 with z hz,
constructor,
split,
exact three6b hz.1 hy.1,
exact eqd.trans hx.2 hz.2.1
end
theorem distle.flip {a b c d : point} : distle a b c d → distle b a d c :=
λ h, five6 h (two5 (eqd.refl a b)) (two5 (eqd.refl c d))
theorem five9 {a b c d : point} : distle a b c d → distle c d a b → eqd a b c d :=
begin
intros h h1,
cases h1 with x hx,
cases five5.mp h with z hz,
cases three14 b a with p hp,
cases hp with h1 h2,
rw three2 at h1,
cases em (a = b),
rw h_1 at *,
have : b = x,
exact bet_same hx.1,
rw this at *,
exact hx.2.symm,
have h2 : p ≠ a,
exact h2.symm,
have : x = z,
apply unique_of_exists_unique (two12 a c d p h2),
split,
exact three5a h1 hx.1,
exact hx.2.symm,
split,
exact three7b h1 hz.1 h_1,
exact hz.2,
rw this at *,
have : b = z,
exact three4 hx.1.symm hz.1.symm,
rw this at *,
exact hz.2
end
theorem five10 (a b c d : point) : distle a b c d ∨ distle c d a b :=
begin
cases three14 b a with p hp,
cases seg_cons a c d p with x hx,
cases five1 hp.2.symm hp.1.symm hx.1,
have : B a b x,
exact three6a hp.1.symm h,
left,
apply five5.mpr,
constructor,
split,
exact this,
exact hx.2,
have : B a x b,
exact three6a hx.1 h,
right,
constructor,
split,
exact this,
exact hx.2.symm
end
theorem five11 (a b c : point) : distle a a b c :=
begin
cases five10 a a b c with h,
assumption,
cases h with x hx,
have : a = x ,
exact bet_same hx.1,
rw this at *,
have : b = c,
exact id_eqd hx.2,
rw this at *,
existsi c,
split,
exact three1 c c,
exact hx.2.symm
end
theorem five12 {a b c : point} : col a b c → (B a b c ↔ distle a b a c ∧ distle b c a c) :=
begin
intro h,
split,
intro h1,
split,
constructor,
split,
exact h1,
exact eqd.refl a b,
have h2 : distle c b c a,
constructor,
split,
exact h1.symm,
exact eqd.refl c b,
apply five6 h2,
exact two5 (eqd.refl c b),
exact two5 (eqd.refl c a),
intro h1,
cases h1 with h1 h2,
cases h1 with x hx,
have : distle c b c a,
exact five6 h2 (two5 (eqd.refl b c)) (two5 (eqd.refl a c)),
cases this with y hy,
cases h with h,
assumption,
cases h with h3 h4,
rw three2 at h3,
cases three14 b a with p hp,
have : B p a c,
exact three5a hp.1.symm h3,
have : B p a x,
exact three5a this hx.1,
have : b = x,
apply unique_of_exists_unique (two12 a a b p hp.2.symm),
split,
exact hp.1.symm,
exact eqd.refl a b,
split,
exact this,
exact hx.2.symm,
rw ←this at *,
exact hx.1,
rw three2 at h4,
cases three14 b c with q hq,
have : B q c a,
exact three5a hq.1.symm h4.symm,
have : B q c y,
exact three5a this hy.1,
have : b = y,
apply unique_of_exists_unique (two12 c c b q hq.2.symm),
split,
exact hq.1.symm,
exact eqd.refl c b,
split,
exact this,
exact hy.2.symm,
rw ←this at *,
exact hy.1.symm
end
def distlt (a b c d : point) : Prop := distle a b c d ∧ ¬eqd a b c d
theorem five13 {a b c d : point} : distlt a b c d → ∃ y, B c y d ∧ eqd a b c y ∧ y ≠ d :=
begin
rintros ⟨h, h1⟩,
cases h with y hy,
refine ⟨y, hy.1, hy.2, _⟩,
intro h_1,
subst y,
exact h1 hy.2
end
theorem five14 {a b c d a' b' c' d' : point} : distlt a b c d → eqd a b a' b' →
eqd c d c' d' → distlt a' b' c' d' :=
λ h h1 h2, ⟨five6 h.1 h1 h2, λ h_1, h.2 (h1.trans (h_1.trans h2.symm))⟩
theorem distlt.trans {a b c d e f : point} : distlt a b c d → distlt c d e f → distlt a b e f :=
λ h h1, ⟨h.1.trans h1.1, λ h_1, h.2 (five9 h.1 (five6 h1.1 (eqd.refl c d) h_1.symm))⟩
theorem distlt.flip {a b c d : point} : distlt a b c d → distlt b a d c :=
λ h, ⟨h.1.flip, λ h_1, h.2 h_1.flip⟩
theorem five15 {a b c d : point} : distlt a b c d → distlt c d a b → false :=
λ h h1, (h.trans h1).2 (eqd.refl a b)
theorem dist_lt_or_eq_of_le {a b c d : point} : distle a b c d → distlt a b c d ∨ eqd a b c d :=
begin
intro h,
cases em (eqd a b c d),
exact or.inr h_1,
exact or.inl ⟨h, h_1⟩
end
theorem dist_lt_iff_not_le {a b c d : point} : distlt a b c d ↔ ¬distle c d a b :=
begin
split,
intros h h1,
exact h.2 (five9 h.1 h1),
intro h,
split,
have h1 := five10 a b c d,
simp [h] at h1,
exact h1,
intro h1,
exact h (five6 (distle.refl a b) h1 (eqd.refl a b))
end
theorem dist_le_iff_not_lt {a b c d : point} : distle a b c d ↔ ¬distlt c d a b :=
begin
split,
intros h h1,
exact dist_lt_iff_not_le.1 h1 h,
intro h,
by_contradiction h_1,
exact h (dist_lt_iff_not_le.2 h_1)
end
theorem dist_total (a b c d : point) : distlt a b c d ∨ eqd a b c d ∨ distlt c d a b :=
begin
cases em (distle a b c d),
cases dist_lt_or_eq_of_le h;
simp *,
simp [dist_lt_iff_not_le.2 h]
end
-- Rays and Lines
def sided (p a b : point) : Prop := a ≠ p ∧ b ≠ p ∧ (B p a b ∨ B p b a)
theorem six1 {a b p : point} : col a p b → B a p b ∨ sided p a b :=
begin
intro h,
cases em (B a p b),
exact or.inl h_1,
unfold col at h,
simp * at *,
rw [three2 b a p] at h,
refine ⟨_, _, h.symm⟩;
intro h_1;
subst p,
exact h_1 (three3 a b),
exact h_1 (three1 a b)
end
theorem six2 {a b c p : point} : a ≠ p → b ≠ p → c ≠ p → B a p c → (B b p c ↔ sided p a b) :=
begin
intros h h1 h2 h3,
split,
intro h4,
unfold sided; repeat {split}; try {assumption},
exact five2 h2 h3.symm h4.symm,
intro h4,
cases h4 with h h1,
cases h1 with h1 ha,
cases ha with ha hb,
exact three7a ha.symm h3 h,
exact three6a hb.symm h3
end
theorem six3 {a b p : point} : sided p a b ↔ a ≠ p ∧ b ≠ p ∧ ∃ c, c ≠ p ∧ B a p c ∧ B b p c :=
begin
split,
intro h,
cases h with h h1,
cases h1 with h1 h2,
split, exact h,
split, exact h1,
cases three14 a p with c hc,
constructor, split,
exact hc.2.symm,
split, exact hc.1,
cases h2,
exact three7a h2.symm hc.1 h,
exact three6a h2.symm hc.1,
intro h,
cases h with h h1,
cases h1 with h1 h2,
split, exact h,
split, exact h1,
cases h2 with c h2,
exact five2 h2.1 h2.2.1.symm h2.2.2.symm
end
theorem six4 {a b p : point} : sided p a b ↔ col a p b ∧ ¬B a p b :=
begin
split,
rintros ⟨h, h1, h2⟩,
cases h2 with ha hb,
split,
unfold col,
simp [ha.symm],
intro h2,
exact h (three4 h2 ha),
split,
unfold col,
simp [hb],
intro h2,
exact h1 (three4 h2.symm hb),
rintros ⟨h, h1⟩,
split,
intro h1,
subst p,
exact h1 (three3 a b),
split,
intro h1,
subst p,
exact h1 (three1 a b),
unfold col at h,
simp [h1] at h,
rw [three2 b a p] at h,
exact h.symm
end
theorem six5 {a p : point} : a ≠ p → sided p a a :=
begin
intro h,
apply six4.2,
split,
right, left,
exact three1 p a,
intro h1,
exact h (bet_same h1)
end
theorem six6 {a b c d : point} : B a b c → sided b c d → B a b d :=
begin
intros h h1,
cases h1.2.2,
exact three7b h h_1 h1.1.symm,
exact three5a h h_1
end
theorem six7 {a b p : point} : B p a b → a ≠ p → sided p a b :=
begin
intros h h1,
refine ⟨h1, _, or.inl h⟩,
intro h_1,
subst h_1,
exact h1.symm (bet_same h)
end
theorem sided.symm {a b p : point} : sided p a b → sided p b a :=
begin
intro h,
cases six3.1 h with h h1,
cases h1 with h1 h2,
cases h2 with c hc,
apply six3.2,
split, exact h1,
split, exact h,
constructor,
split,
exact hc.1,
split,
exact hc.2.2,
exact hc.2.1
end
theorem sided.trans {a b c p : point} : sided p a b → sided p b c → sided p a c :=
begin
intros h1 h,
cases six3.1 h1 with h1 h2,
cases h2 with h2 h3,
cases h3 with q hq,
have h3 : c ≠ p,
exact h.2.1,
have : B c p q,
exact (six2 h2 h3 hq.1 hq.2.2).2 h,
exact (six2 h1 h3 hq.1 hq.2.1).1 this
end
theorem six6a {a b c d : point} : sided a b c → B b d c → sided a b d :=
begin
intros h h1,
cases h.2.2,
exact six7 (three5a h_1 h1) h.1,
exact h.trans (six7 (three5a h_1 h1.symm) h.2.1)
end
theorem six7a {a b c p : point} : B p a b → sided p a c → sided p b c :=
begin
intros h h1,
apply sided.trans _ h1,
exact (six7 h h1.1).symm
end
theorem six8 {a b c p q : point} : sided b p a → sided b q c → B a b c → B p b q :=
begin
intros h h1 h2,
have h3 : B p b c,
cases h.2.2,
exact three6a h_1.symm h2,
exact three7a h_1.symm h2 h.2.1,
cases h1.2.2,
exact three5a h3 h_1,
exact three7b h3 h_1 h1.2.1.symm
end
def ray (p a : point) : set point := {x | sided p a x}
def hline (k : set point) : Prop := ∃ p a, a ≠ p ∧ k = ray p a
theorem six11 {a b c r : point} : r ≠ a → b ≠ c → ∃! x, sided a x r ∧ eqd a x b c :=
begin
intros h h1,
cases three14 r a with p hp,
cases seg_cons a b c p with x hx,
have h2 : x ≠ a,
intro ha,
rw ha at hx,
have : b = c,
exact id_eqd hx.2.symm,
contradiction,
have h3 : sided a x r,
split,
exact h2,
split,
exact h,
exact five2 hp.2.symm hx.1 hp.1.symm,
apply exists_unique.intro,
exact ⟨h3, hx.2⟩,
intros y hy,
have : B p a y,
exact ((six2 h2 hy.1.1 hp.2.symm hx.1.symm).2 (sided.trans h3 hy.1.symm)).symm,
apply unique_of_exists_unique (two12 a b c p hp.2.symm),
exact ⟨this, hy.2⟩,
exact hx
end
theorem six11a {p a b : point} : sided p a b → eqd p a p b → a = b :=
λ h h1, unique_of_exists_unique (six11 h.1 h.1.symm) ⟨(six5 h.1), eqd.refl p a⟩ ⟨h.symm, h1.symm⟩
theorem six12 {a b p : point} : sided p a b → (distle p a p b ↔ B p a b) :=
begin
intro h1,
have hp : sided p a b, exact h1,
split,
intro h,
cases h1 with h1 h2,
cases h2 with h2 h3,
cases h3,
exact h3,
have : col p b a,
left, exact h3,
have : distle p b p a,
exact ((five12 this).1 h3).1,
have : eqd p a p b,
exact five9 h this,
cases three14 a p with q hq,
have h4 : B q p b,
exact ((six2 h1 h2 hq.2.symm hq.1).2 hp).symm,
have : a = b,
apply unique_of_exists_unique (two12 p p a q hq.2.symm),
split,
exact hq.1.symm,
exact eqd.refl p a,
split,
exact h4,
exact this.symm,
rw this,
exact three1 p b,
intro h,
unfold distle,
existsi a,
split,
exact h,
exact eqd.refl p a
end
end Euclidean_plane |
c10418d9630be6d62a45d196e4a6ee96c5a108b9 | 17d3c61bf162bf88be633867ed4cb201378a8769 | /tests/lean/run/listex3.lean | 4e5035637283be24e50624160df4005cb758617e | [
"Apache-2.0"
] | permissive | u20024804/lean | 11def01468fb4796fb0da76015855adceac7e311 | d315e424ff17faf6fe096a0a1407b70193009726 | refs/heads/master | 1,611,388,567,561 | 1,485,836,506,000 | 1,485,836,625,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,386 | lean | universe variable u
constant in_tail {α : Type u} {a : α} (b : α) {l : list α} : a ∈ l → a ∈ b::l
constant in_head {α : Type u} (a : α) (l : list α) : a ∈ a::l
constant in_left {α : Type u} {a : α} {l : list α} (r : list α) : a ∈ l → a ∈ l ++ r
constant in_right {α : Type u} {a : α} (l : list α) {r : list α} : a ∈ r → a ∈ l ++ r
open expr tactic
declare_trace search_mem_list
meta def mk_mem_list_rec : unit → tactic unit
| u :=
when_tracing `search_mem_list (do t ← target, f ← pp t, trace (to_fmt "search " ++ f))
>> (assumption
<|>
(`[apply in_left] >> mk_mem_list_rec u)
<|>
(`[apply in_right] >> mk_mem_list_rec u)
<|>
(`[apply in_head])
<|>
(`[apply in_tail] >> mk_mem_list_rec u))
>> now
meta def mk_mem_list : tactic unit :=
solve1 (mk_mem_list_rec ())
set_option trace.search_mem_list true
example (a b c : nat) : a ∈ [b, c] ++ [b, a, b] :=
by mk_mem_list
example (a b c : nat) : a ∈ [b, c] ++ [b, a+0, b] :=
by mk_mem_list
example (a b c : nat) : a ∈ [b, c] ++ [b, c, c] ++ [b, a+0, b] :=
by mk_mem_list
example (a b c : nat) (l : list nat) : a ∈ l → a ∈ [b, c] ++ b::l :=
by tactic.intros >> mk_mem_list
example (a b c : nat) (l₁ l₂ : list nat) : a ∈ l₁ → a ∈ b::b::c::l₂ ++ b::c::l₁ ++ [c, c, b] :=
by tactic.intros >> mk_mem_list
|
406cf6bcba060e8ee4a678e452b4dd974d4feb8c | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /04_Quantifiers_and_Equality.org.8.lean | e9d4e2b59067555ad6783dbccd4e62a68cc95259 | [] | no_license | cjmazey/lean-tutorial | ba559a49f82aa6c5848b9bf17b7389bf7f4ba645 | 381f61c9fcac56d01d959ae0fa6e376f2c4e3b34 | refs/heads/master | 1,610,286,098,832 | 1,447,124,923,000 | 1,447,124,923,000 | 43,082,433 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 388 | lean | /- page 50 -/
import standard
variables (men : Type) (barber : men) (shaves : men → men → Prop)
example (H : ∀ x : men, shaves barber x ↔ ¬shaves x x) : false :=
have Hnsbb : ¬shaves barber barber,
from assume Hsbb : shaves barber barber,
iff.mp (H barber) Hsbb Hsbb,
have Hsbb : shaves barber barber,
from iff.mpr (H barber) Hnsbb,
absurd Hsbb Hnsbb
|
3a7e19ce2875a0ca731de5e02e361a09eede7a1d | 5d166a16ae129621cb54ca9dde86c275d7d2b483 | /library/init/meta/occurrences.lean | 2a8da2351492ebd53bef7fc6efebb1bb3a489ac5 | [
"Apache-2.0"
] | permissive | jcarlson23/lean | b00098763291397e0ac76b37a2dd96bc013bd247 | 8de88701247f54d325edd46c0eed57aeacb64baf | refs/heads/master | 1,611,571,813,719 | 1,497,020,963,000 | 1,497,021,515,000 | 93,882,536 | 1 | 0 | null | 1,497,029,896,000 | 1,497,029,896,000 | null | UTF-8 | Lean | false | false | 1,507 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic init.data.to_string init.meta.format
import init.meta.contradiction_tactic init.meta.constructor_tactic
import init.meta.relation_tactics init.meta.injection_tactic
/- We can specify the scope of application of some tactics using
the following type.
- all : all occurrences of a given term are considered.
- pos [1, 3] : only the first and third occurrences of a given
term are consiered.
- neg [2] : all but the second occurrence of a given term
are considered. -/
inductive occurrences
| all
| pos : list nat → occurrences
| neg : list nat → occurrences
open occurrences
def occurrences.contains : occurrences → nat → bool
| all p := tt
| (occurrences.pos ps) p := p ∈ ps
| (occurrences.neg ps) p := p ∉ ps
instance : inhabited occurrences :=
⟨all⟩
def occurrences_to_string : occurrences → string
| occurrences.all := "*"
| (occurrences.pos l) := to_string l
| (occurrences.neg l) := "-" ++ to_string l
instance : has_to_string occurrences :=
⟨occurrences_to_string⟩
meta def occurrences_to_format : occurrences → format
| occurrences.all := to_fmt "*"
| (occurrences.pos l) := to_fmt l
| (occurrences.neg l) := to_fmt "-" ++ to_fmt l
meta instance : has_to_format occurrences :=
⟨occurrences_to_format⟩
open decidable tactic
|
d64a6a3f58c131dc20938705a491c0d3ecdfe959 | 3aad12fe82645d2d3173fbedc2e5c2ba945a4d75 | /src/data/list/nursery.lean | 0acb2a390bfc7ddf0c86b1a8b3aaec2f66d4c0a2 | [] | no_license | seanpm2001/LeanProver-Community_MathLIB-Nursery | 4f88d539cb18d73a94af983092896b851e6640b5 | 0479b31fa5b4d39f41e89b8584c9f5bf5271e8ec | refs/heads/master | 1,688,730,786,645 | 1,572,070,026,000 | 1,572,070,026,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 279 | lean |
instance list.empty.decidable {α} : Π (xs : list α), decidable (xs = [])
| [] := is_true rfl
| (_ :: _) := is_false (by contradiction)
instance list.empty.decidable' {α} : Π (xs : list α), decidable ([] = xs)
| [] := is_true rfl
| (_ :: _) := is_false (by contradiction)
|
8f3fb7586d775daee61a72aeabf68852c4fbd862 | b70031c8e2c5337b91d7e70f1e0c5f528f7b0e77 | /src/topology/order.lean | 508df4b25c718ecfd89d9e091eaa1aeeeb927dd4 | [
"Apache-2.0"
] | permissive | molodiuc/mathlib | cae2ba3ef1601c1f42ca0b625c79b061b63fef5b | 98ebe5a6739fbe254f9ee9d401882d4388f91035 | refs/heads/master | 1,674,237,127,059 | 1,606,353,533,000 | 1,606,353,533,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,886 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import topology.tactic
/-!
# Ordering on topologies and (co)induced topologies
Topologies on a fixed type `α` are ordered, by reverse inclusion.
That is, for topologies `t₁` and `t₂` on `α`, we write `t₁ ≤ t₂`
if every set open in `t₂` is also open in `t₁`.
(One also calls `t₁` finer than `t₂`, and `t₂` coarser than `t₁`.)
Any function `f : α → β` induces
`induced f : topological_space β → topological_space α`
and `coinduced f : topological_space α → topological_space β`.
Continuity, the ordering on topologies and (co)induced topologies are
related as follows:
* The identity map (α, t₁) → (α, t₂) is continuous iff t₁ ≤ t₂.
* A map f : (α, t) → (β, u) is continuous
iff t ≤ induced f u (`continuous_iff_le_induced`)
iff coinduced f t ≤ u (`continuous_iff_coinduced_le`).
Topologies on α form a complete lattice, with ⊥ the discrete topology
and ⊤ the indiscrete topology.
For a function f : α → β, (coinduced f, induced f) is a Galois connection
between topologies on α and topologies on β.
## Implementation notes
There is a Galois insertion between topologies on α (with the inclusion ordering)
and all collections of sets in α. The complete lattice structure on topologies
on α is defined as the reverse of the one obtained via this Galois insertion.
## Tags
finer, coarser, induced topology, coinduced topology
-/
open set filter classical
open_locale classical topological_space filter
universes u v w
namespace topological_space
variables {α : Type u}
/-- The open sets of the least topology containing a collection of basic sets. -/
inductive generate_open (g : set (set α)) : set α → Prop
| basic : ∀s∈g, generate_open s
| univ : generate_open univ
| inter : ∀s t, generate_open s → generate_open t → generate_open (s ∩ t)
| sUnion : ∀k, (∀s∈k, generate_open s) → generate_open (⋃₀ k)
/-- The smallest topological space containing the collection `g` of basic sets -/
def generate_from (g : set (set α)) : topological_space α :=
{ is_open := generate_open g,
is_open_univ := generate_open.univ,
is_open_inter := generate_open.inter,
is_open_sUnion := generate_open.sUnion }
lemma nhds_generate_from {g : set (set α)} {a : α} :
@nhds α (generate_from g) a = (⨅s∈{s | a ∈ s ∧ s ∈ g}, 𝓟 s) :=
by rw nhds_def; exact le_antisymm
(infi_le_infi $ assume s, infi_le_infi_const $ assume ⟨as, sg⟩, ⟨as, generate_open.basic _ sg⟩)
(le_infi $ assume s, le_infi $ assume ⟨as, hs⟩,
begin
revert as, clear_, induction hs,
case generate_open.basic : s hs
{ exact assume as, infi_le_of_le s $ infi_le _ ⟨as, hs⟩ },
case generate_open.univ
{ rw [principal_univ],
exact assume _, le_top },
case generate_open.inter : s t hs' ht' hs ht
{ exact assume ⟨has, hat⟩, calc _ ≤ 𝓟 s ⊓ 𝓟 t : le_inf (hs has) (ht hat)
... = _ : inf_principal },
case generate_open.sUnion : k hk' hk
{ exact λ ⟨t, htk, hat⟩, calc _ ≤ 𝓟 t : hk t htk hat
... ≤ _ : le_principal_iff.2 $ subset_sUnion_of_mem htk }
end)
lemma tendsto_nhds_generate_from {β : Type*} {m : α → β} {f : filter α} {g : set (set β)} {b : β}
(h : ∀s∈g, b ∈ s → m ⁻¹' s ∈ f) : tendsto m f (@nhds β (generate_from g) b) :=
by rw [nhds_generate_from]; exact
(tendsto_infi.2 $ assume s, tendsto_infi.2 $ assume ⟨hbs, hsg⟩, tendsto_principal.2 $ h s hsg hbs)
/-- Construct a topology on α given the filter of neighborhoods of each point of α. -/
protected def mk_of_nhds (n : α → filter α) : topological_space α :=
{ is_open := λs, ∀a∈s, s ∈ n a,
is_open_univ := assume x h, univ_mem_sets,
is_open_inter := assume s t hs ht x ⟨hxs, hxt⟩, inter_mem_sets (hs x hxs) (ht x hxt),
is_open_sUnion := assume s hs a ⟨x, hx, hxa⟩, mem_sets_of_superset (hs x hx _ hxa) (set.subset_sUnion_of_mem hx) }
lemma nhds_mk_of_nhds (n : α → filter α) (a : α)
(h₀ : pure ≤ n) (h₁ : ∀{a s}, s ∈ n a → ∃ t ∈ n a, t ⊆ s ∧ ∀a' ∈ t, s ∈ n a') :
@nhds α (topological_space.mk_of_nhds n) a = n a :=
begin
letI := topological_space.mk_of_nhds n,
refine le_antisymm (assume s hs, _) (assume s hs, _),
{ have h₀ : {b | s ∈ n b} ⊆ s := assume b hb, mem_pure_sets.1 $ h₀ b hb,
have h₁ : {b | s ∈ n b} ∈ 𝓝 a,
{ refine mem_nhds_sets (assume b (hb : s ∈ n b), _) hs,
rcases h₁ hb with ⟨t, ht, hts, h⟩,
exact mem_sets_of_superset ht h },
exact mem_sets_of_superset h₁ h₀ },
{ rcases (@mem_nhds_sets_iff α (topological_space.mk_of_nhds n) _ _).1 hs with ⟨t, hts, ht, hat⟩,
exact (n a).sets_of_superset (ht _ hat) hts },
end
end topological_space
section lattice
variables {α : Type u} {β : Type v}
/-- The inclusion ordering on topologies on α. We use it to get a complete
lattice instance via the Galois insertion method, but the partial order
that we will eventually impose on `topological_space α` is the reverse one. -/
def tmp_order : partial_order (topological_space α) :=
{ le := λt s, t.is_open ≤ s.is_open,
le_antisymm := assume t s h₁ h₂, topological_space_eq $ le_antisymm h₁ h₂,
le_refl := assume t, le_refl t.is_open,
le_trans := assume a b c h₁ h₂, @le_trans _ _ a.is_open b.is_open c.is_open h₁ h₂ }
local attribute [instance] tmp_order
/- We'll later restate this lemma in terms of the correct order on `topological_space α`. -/
private lemma generate_from_le_iff_subset_is_open {g : set (set α)} {t : topological_space α} :
topological_space.generate_from g ≤ t ↔ g ⊆ {s | t.is_open s} :=
iff.intro
(assume ht s hs, ht _ $ topological_space.generate_open.basic s hs)
(assume hg s hs, hs.rec_on (assume v hv, hg hv)
t.is_open_univ (assume u v _ _, t.is_open_inter u v) (assume k _, t.is_open_sUnion k))
/-- If `s` equals the collection of open sets in the topology it generates,
then `s` defines a topology. -/
protected def mk_of_closure (s : set (set α))
(hs : {u | (topological_space.generate_from s).is_open u} = s) : topological_space α :=
{ is_open := λu, u ∈ s,
is_open_univ := hs ▸ topological_space.generate_open.univ,
is_open_inter := hs ▸ topological_space.generate_open.inter,
is_open_sUnion := hs ▸ topological_space.generate_open.sUnion }
lemma mk_of_closure_sets {s : set (set α)}
{hs : {u | (topological_space.generate_from s).is_open u} = s} :
mk_of_closure s hs = topological_space.generate_from s :=
topological_space_eq hs.symm
/-- The Galois insertion between `set (set α)` and `topological_space α` whose lower part
sends a collection of subsets of α to the topology they generate, and whose upper part
sends a topology to its collection of open subsets. -/
def gi_generate_from (α : Type*) :
galois_insertion topological_space.generate_from (λt:topological_space α, {s | t.is_open s}) :=
{ gc := assume g t, generate_from_le_iff_subset_is_open,
le_l_u := assume ts s hs, topological_space.generate_open.basic s hs,
choice := λg hg, mk_of_closure g
(subset.antisymm hg $ generate_from_le_iff_subset_is_open.1 $ le_refl _),
choice_eq := assume s hs, mk_of_closure_sets }
lemma generate_from_mono {α} {g₁ g₂ : set (set α)} (h : g₁ ⊆ g₂) :
topological_space.generate_from g₁ ≤ topological_space.generate_from g₂ :=
(gi_generate_from _).gc.monotone_l h
/-- The complete lattice of topological spaces, but built on the inclusion ordering. -/
def tmp_complete_lattice {α : Type u} : complete_lattice (topological_space α) :=
(gi_generate_from α).lift_complete_lattice
/-- The ordering on topologies on the type `α`.
`t ≤ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/
instance : partial_order (topological_space α) :=
{ le := λ t s, s.is_open ≤ t.is_open,
le_antisymm := assume t s h₁ h₂, topological_space_eq $ le_antisymm h₂ h₁,
le_refl := assume t, le_refl t.is_open,
le_trans := assume a b c h₁ h₂, le_trans h₂ h₁ }
lemma le_generate_from_iff_subset_is_open {g : set (set α)} {t : topological_space α} :
t ≤ topological_space.generate_from g ↔ g ⊆ {s | t.is_open s} :=
generate_from_le_iff_subset_is_open
/-- Topologies on `α` form a complete lattice, with `⊥` the discrete topology
and `⊤` the indiscrete topology. The infimum of a collection of topologies
is the topology generated by all their open sets, while the supremem is the
topology whose open sets are those sets open in every member of the collection. -/
instance : complete_lattice (topological_space α) :=
@order_dual.complete_lattice _ tmp_complete_lattice
/-- A topological space is discrete if every set is open, that is,
its topology equals the discrete topology `⊥`. -/
class discrete_topology (α : Type*) [t : topological_space α] : Prop :=
(eq_bot [] : t = ⊥)
@[simp] lemma is_open_discrete [topological_space α] [discrete_topology α] (s : set α) :
is_open s :=
(discrete_topology.eq_bot α).symm ▸ trivial
@[simp] lemma is_closed_discrete [topological_space α] [discrete_topology α] (s : set α) :
is_closed s :=
(discrete_topology.eq_bot α).symm ▸ trivial
lemma continuous_of_discrete_topology [topological_space α] [discrete_topology α]
[topological_space β] {f : α → β} : continuous f :=
continuous_def.2 $ λs hs, is_open_discrete _
lemma nhds_bot (α : Type*) : (@nhds α ⊥) = pure :=
begin
refine le_antisymm _ (@pure_le_nhds α ⊥),
assume a s hs,
exact @mem_nhds_sets α ⊥ a s trivial hs
end
lemma nhds_discrete (α : Type*) [topological_space α] [discrete_topology α] : (@nhds α _) = pure :=
(discrete_topology.eq_bot α).symm ▸ nhds_bot α
lemma le_of_nhds_le_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₁ x ≤ @nhds α t₂ x) :
t₁ ≤ t₂ :=
assume s, show @is_open α t₂ s → @is_open α t₁ s,
by { simp only [is_open_iff_nhds, le_principal_iff], exact assume hs a ha, h _ $ hs _ ha }
lemma eq_of_nhds_eq_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₁ x = @nhds α t₂ x) :
t₁ = t₂ :=
le_antisymm
(le_of_nhds_le_nhds $ assume x, le_of_eq $ h x)
(le_of_nhds_le_nhds $ assume x, le_of_eq $ (h x).symm)
lemma eq_bot_of_singletons_open {t : topological_space α} (h : ∀ x, t.is_open {x}) : t = ⊥ :=
bot_unique $ λ s hs, bUnion_of_singleton s ▸ is_open_bUnion (λ x _, h x)
end lattice
section galois_connection
variables {α : Type*} {β : Type*} {γ : Type*}
/-- Given `f : α → β` and a topology on `β`, the induced topology on `α` is the collection of
sets that are preimages of some open set in `β`. This is the coarsest topology that
makes `f` continuous. -/
def topological_space.induced {α : Type u} {β : Type v} (f : α → β) (t : topological_space β) :
topological_space α :=
{ is_open := λs, ∃s', t.is_open s' ∧ f ⁻¹' s' = s,
is_open_univ := ⟨univ, t.is_open_univ, preimage_univ⟩,
is_open_inter := by rintro s₁ s₂ ⟨s'₁, hs₁, rfl⟩ ⟨s'₂, hs₂, rfl⟩;
exact ⟨s'₁ ∩ s'₂, t.is_open_inter _ _ hs₁ hs₂, preimage_inter⟩,
is_open_sUnion := assume s h,
begin
simp only [classical.skolem] at h,
cases h with f hf,
apply exists.intro (⋃(x : set α) (h : x ∈ s), f x h),
simp only [sUnion_eq_bUnion, preimage_Union, (λx h, (hf x h).right)], refine ⟨_, rfl⟩,
exact (@is_open_Union β _ t _ $ assume i,
show is_open (⋃h, f i h), from @is_open_Union β _ t _ $ assume h, (hf i h).left)
end }
lemma is_open_induced_iff [t : topological_space β] {s : set α} {f : α → β} :
@is_open α (t.induced f) s ↔ (∃t, is_open t ∧ f ⁻¹' t = s) :=
iff.rfl
lemma is_closed_induced_iff [t : topological_space β] {s : set α} {f : α → β} :
@is_closed α (t.induced f) s ↔ (∃t, is_closed t ∧ s = f ⁻¹' t) :=
⟨assume ⟨t, ht, heq⟩, ⟨tᶜ, is_closed_compl_iff.2 ht,
by simp only [preimage_compl, heq, compl_compl]⟩,
assume ⟨t, ht, heq⟩, ⟨tᶜ, ht, by simp only [preimage_compl, heq.symm]⟩⟩
/-- Given `f : α → β` and a topology on `α`, the coinduced topology on `β` is defined
such that `s:set β` is open if the preimage of `s` is open. This is the finest topology that
makes `f` continuous. -/
def topological_space.coinduced {α : Type u} {β : Type v} (f : α → β) (t : topological_space α) :
topological_space β :=
{ is_open := λs, t.is_open (f ⁻¹' s),
is_open_univ := by rw preimage_univ; exact t.is_open_univ,
is_open_inter := assume s₁ s₂ h₁ h₂, by rw preimage_inter; exact t.is_open_inter _ _ h₁ h₂,
is_open_sUnion := assume s h, by rw [preimage_sUnion]; exact (@is_open_Union _ _ t _ $ assume i,
show is_open (⋃ (H : i ∈ s), f ⁻¹' i), from
@is_open_Union _ _ t _ $ assume hi, h i hi) }
lemma is_open_coinduced {t : topological_space α} {s : set β} {f : α → β} :
@is_open β (topological_space.coinduced f t) s ↔ is_open (f ⁻¹' s) :=
iff.rfl
variables {t t₁ t₂ : topological_space α} {t' : topological_space β} {f : α → β} {g : β → α}
lemma continuous.coinduced_le (h : @continuous α β t t' f) :
t.coinduced f ≤ t' :=
λ s hs, (continuous_def.1 h s hs : _)
lemma coinduced_le_iff_le_induced {f : α → β} {tα : topological_space α} {tβ : topological_space β} :
tα.coinduced f ≤ tβ ↔ tα ≤ tβ.induced f :=
iff.intro
(assume h s ⟨t, ht, hst⟩, hst ▸ h _ ht)
(assume h s hs, show tα.is_open (f ⁻¹' s), from h _ ⟨s, hs, rfl⟩)
lemma continuous.le_induced (h : @continuous α β t t' f) :
t ≤ t'.induced f :=
coinduced_le_iff_le_induced.1 h.coinduced_le
lemma gc_coinduced_induced (f : α → β) :
galois_connection (topological_space.coinduced f) (topological_space.induced f) :=
assume f g, coinduced_le_iff_le_induced
lemma induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g :=
(gc_coinduced_induced g).monotone_u h
lemma coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f :=
(gc_coinduced_induced f).monotone_l h
@[simp] lemma induced_top : (⊤ : topological_space α).induced g = ⊤ :=
(gc_coinduced_induced g).u_top
@[simp] lemma induced_inf : (t₁ ⊓ t₂).induced g = t₁.induced g ⊓ t₂.induced g :=
(gc_coinduced_induced g).u_inf
@[simp] lemma induced_infi {ι : Sort w} {t : ι → topological_space α} :
(⨅i, t i).induced g = (⨅i, (t i).induced g) :=
(gc_coinduced_induced g).u_infi
@[simp] lemma coinduced_bot : (⊥ : topological_space α).coinduced f = ⊥ :=
(gc_coinduced_induced f).l_bot
@[simp] lemma coinduced_sup : (t₁ ⊔ t₂).coinduced f = t₁.coinduced f ⊔ t₂.coinduced f :=
(gc_coinduced_induced f).l_sup
@[simp] lemma coinduced_supr {ι : Sort w} {t : ι → topological_space α} :
(⨆i, t i).coinduced f = (⨆i, (t i).coinduced f) :=
(gc_coinduced_induced f).l_supr
lemma induced_id [t : topological_space α] : t.induced id = t :=
topological_space_eq $ funext $ assume s, propext $
⟨assume ⟨s', hs, h⟩, h ▸ hs, assume hs, ⟨s, hs, rfl⟩⟩
lemma induced_compose [tγ : topological_space γ]
{f : α → β} {g : β → γ} : (tγ.induced g).induced f = tγ.induced (g ∘ f) :=
topological_space_eq $ funext $ assume s, propext $
⟨assume ⟨s', ⟨s, hs, h₂⟩, h₁⟩, h₁ ▸ h₂ ▸ ⟨s, hs, rfl⟩,
assume ⟨s, hs, h⟩, ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩
lemma coinduced_id [t : topological_space α] : t.coinduced id = t :=
topological_space_eq rfl
lemma coinduced_compose [tα : topological_space α]
{f : α → β} {g : β → γ} : (tα.coinduced f).coinduced g = tα.coinduced (g ∘ f) :=
topological_space_eq rfl
end galois_connection
/- constructions using the complete lattice structure -/
section constructions
open topological_space
variables {α : Type u} {β : Type v}
instance inhabited_topological_space {α : Type u} : inhabited (topological_space α) :=
⟨⊤⟩
@[priority 100]
instance subsingleton.unique_topological_space [subsingleton α] :
unique (topological_space α) :=
{ default := ⊥,
uniq := λ t, eq_bot_of_singletons_open $ λ x, subsingleton.set_cases
(@is_open_empty _ t) (@is_open_univ _ t) ({x} : set α) }
@[priority 100]
instance subsingleton.discrete_topology [t : topological_space α] [subsingleton α] :
discrete_topology α :=
⟨unique.eq_default t⟩
instance : topological_space empty := ⊥
instance : discrete_topology empty := ⟨rfl⟩
instance : topological_space pempty := ⊥
instance : discrete_topology pempty := ⟨rfl⟩
instance : topological_space unit := ⊥
instance : discrete_topology unit := ⟨rfl⟩
instance : topological_space bool := ⊥
instance : discrete_topology bool := ⟨rfl⟩
instance : topological_space ℕ := ⊥
instance : discrete_topology ℕ := ⟨rfl⟩
instance : topological_space ℤ := ⊥
instance : discrete_topology ℤ := ⟨rfl⟩
instance sierpinski_space : topological_space Prop :=
generate_from {{true}}
lemma le_generate_from {t : topological_space α} { g : set (set α) } (h : ∀s∈g, is_open s) :
t ≤ generate_from g :=
le_generate_from_iff_subset_is_open.2 h
lemma induced_generate_from_eq {α β} {b : set (set β)} {f : α → β} :
(generate_from b).induced f = topological_space.generate_from (preimage f '' b) :=
le_antisymm
(le_generate_from $ ball_image_iff.2 $ assume s hs, ⟨s, generate_open.basic _ hs, rfl⟩)
(coinduced_le_iff_le_induced.1 $ le_generate_from $ assume s hs,
generate_open.basic _ $ mem_image_of_mem _ hs)
/-- This construction is left adjoint to the operation sending a topology on `α`
to its neighborhood filter at a fixed point `a : α`. -/
protected def topological_space.nhds_adjoint (a : α) (f : filter α) : topological_space α :=
{ is_open := λs, a ∈ s → s ∈ f,
is_open_univ := assume s, univ_mem_sets,
is_open_inter := assume s t hs ht ⟨has, hat⟩, inter_mem_sets (hs has) (ht hat),
is_open_sUnion := assume k hk ⟨u, hu, hau⟩, mem_sets_of_superset (hk u hu hau) (subset_sUnion_of_mem hu) }
lemma gc_nhds (a : α) :
galois_connection (topological_space.nhds_adjoint a) (λt, @nhds α t a) :=
assume f t, by { rw le_nhds_iff, exact ⟨λ H s hs has, H _ has hs, λ H s has hs, H _ hs has⟩ }
lemma nhds_mono {t₁ t₂ : topological_space α} {a : α} (h : t₁ ≤ t₂) :
@nhds α t₁ a ≤ @nhds α t₂ a := (gc_nhds a).monotone_u h
lemma nhds_infi {ι : Sort*} {t : ι → topological_space α} {a : α} :
@nhds α (infi t) a = (⨅i, @nhds α (t i) a) := (gc_nhds a).u_infi
lemma nhds_Inf {s : set (topological_space α)} {a : α} :
@nhds α (Inf s) a = (⨅t∈s, @nhds α t a) := (gc_nhds a).u_Inf
lemma nhds_inf {t₁ t₂ : topological_space α} {a : α} :
@nhds α (t₁ ⊓ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a := (gc_nhds a).u_inf
lemma nhds_top {a : α} : @nhds α ⊤ a = ⊤ := (gc_nhds a).u_top
local notation `cont` := @continuous _ _
local notation `tspace` := topological_space
open topological_space
variables {γ : Type*} {f : α → β} {ι : Sort*}
lemma continuous_iff_coinduced_le {t₁ : tspace α} {t₂ : tspace β} :
cont t₁ t₂ f ↔ coinduced f t₁ ≤ t₂ :=
continuous_def.trans iff.rfl
lemma continuous_iff_le_induced {t₁ : tspace α} {t₂ : tspace β} :
cont t₁ t₂ f ↔ t₁ ≤ induced f t₂ :=
iff.trans continuous_iff_coinduced_le (gc_coinduced_induced f _ _)
theorem continuous_generated_from {t : tspace α} {b : set (set β)}
(h : ∀s∈b, is_open (f ⁻¹' s)) : cont t (generate_from b) f :=
continuous_iff_coinduced_le.2 $ le_generate_from h
lemma continuous_induced_dom {t : tspace β} : cont (induced f t) t f :=
by { rw continuous_def, assume s h, exact ⟨_, h, rfl⟩ }
lemma continuous_induced_rng {g : γ → α} {t₂ : tspace β} {t₁ : tspace γ}
(h : cont t₁ t₂ (f ∘ g)) : cont t₁ (induced f t₂) g :=
begin
rw continuous_def,
rintros s ⟨t, ht, s_eq⟩,
simpa [← s_eq] using continuous_def.1 h t ht,
end
lemma continuous_induced_rng' [topological_space α] [topological_space β] [topological_space γ]
{g : γ → α} (f : α → β) (H : ‹topological_space α› = ‹topological_space β›.induced f)
(h : continuous (f ∘ g)) : continuous g :=
H.symm ▸ continuous_induced_rng h
lemma continuous_coinduced_rng {t : tspace α} : cont t (coinduced f t) f :=
by { rw continuous_def, assume s h, exact h }
lemma continuous_coinduced_dom {g : β → γ} {t₁ : tspace α} {t₂ : tspace γ}
(h : cont t₁ t₂ (g ∘ f)) : cont (coinduced f t₁) t₂ g :=
begin
rw continuous_def at h ⊢,
assume s hs,
exact h _ hs
end
lemma continuous_le_dom {t₁ t₂ : tspace α} {t₃ : tspace β}
(h₁ : t₂ ≤ t₁) (h₂ : cont t₁ t₃ f) : cont t₂ t₃ f :=
begin
rw continuous_def at h₂ ⊢,
assume s h,
exact h₁ _ (h₂ s h)
end
lemma continuous_le_rng {t₁ : tspace α} {t₂ t₃ : tspace β}
(h₁ : t₂ ≤ t₃) (h₂ : cont t₁ t₂ f) : cont t₁ t₃ f :=
begin
rw continuous_def at h₂ ⊢,
assume s h,
exact h₂ s (h₁ s h)
end
lemma continuous_sup_dom {t₁ t₂ : tspace α} {t₃ : tspace β}
(h₁ : cont t₁ t₃ f) (h₂ : cont t₂ t₃ f) : cont (t₁ ⊔ t₂) t₃ f :=
begin
rw continuous_def at h₁ h₂ ⊢,
assume s h,
exact ⟨h₁ s h, h₂ s h⟩
end
lemma continuous_sup_rng_left {t₁ : tspace α} {t₃ t₂ : tspace β} :
cont t₁ t₂ f → cont t₁ (t₂ ⊔ t₃) f :=
continuous_le_rng le_sup_left
lemma continuous_sup_rng_right {t₁ : tspace α} {t₃ t₂ : tspace β} :
cont t₁ t₃ f → cont t₁ (t₂ ⊔ t₃) f :=
continuous_le_rng le_sup_right
lemma continuous_Sup_dom {t₁ : set (tspace α)} {t₂ : tspace β}
(h : ∀t∈t₁, cont t t₂ f) : cont (Sup t₁) t₂ f :=
continuous_iff_le_induced.2 $ Sup_le $ assume t ht, continuous_iff_le_induced.1 $ h t ht
lemma continuous_Sup_rng {t₁ : tspace α} {t₂ : set (tspace β)} {t : tspace β}
(h₁ : t ∈ t₂) (hf : cont t₁ t f) : cont t₁ (Sup t₂) f :=
continuous_iff_coinduced_le.2 $ le_Sup_of_le h₁ $ continuous_iff_coinduced_le.1 hf
lemma continuous_supr_dom {t₁ : ι → tspace α} {t₂ : tspace β}
(h : ∀i, cont (t₁ i) t₂ f) : cont (supr t₁) t₂ f :=
continuous_Sup_dom $ assume t ⟨i, (t_eq : t₁ i = t)⟩, t_eq ▸ h i
lemma continuous_supr_rng {t₁ : tspace α} {t₂ : ι → tspace β} {i : ι}
(h : cont t₁ (t₂ i) f) : cont t₁ (supr t₂) f :=
continuous_Sup_rng ⟨i, rfl⟩ h
lemma continuous_inf_rng {t₁ : tspace α} {t₂ t₃ : tspace β}
(h₁ : cont t₁ t₂ f) (h₂ : cont t₁ t₃ f) : cont t₁ (t₂ ⊓ t₃) f :=
continuous_iff_coinduced_le.2 $ le_inf
(continuous_iff_coinduced_le.1 h₁)
(continuous_iff_coinduced_le.1 h₂)
lemma continuous_inf_dom_left {t₁ t₂ : tspace α} {t₃ : tspace β} :
cont t₁ t₃ f → cont (t₁ ⊓ t₂) t₃ f :=
continuous_le_dom inf_le_left
lemma continuous_inf_dom_right {t₁ t₂ : tspace α} {t₃ : tspace β} :
cont t₂ t₃ f → cont (t₁ ⊓ t₂) t₃ f :=
continuous_le_dom inf_le_right
lemma continuous_Inf_dom {t₁ : set (tspace α)} {t₂ : tspace β} {t : tspace α} (h₁ : t ∈ t₁) :
cont t t₂ f → cont (Inf t₁) t₂ f :=
continuous_le_dom $ Inf_le h₁
lemma continuous_Inf_rng {t₁ : tspace α} {t₂ : set (tspace β)}
(h : ∀t∈t₂, cont t₁ t f) : cont t₁ (Inf t₂) f :=
continuous_iff_coinduced_le.2 $ le_Inf $ assume b hb, continuous_iff_coinduced_le.1 $ h b hb
lemma continuous_infi_dom {t₁ : ι → tspace α} {t₂ : tspace β} {i : ι} :
cont (t₁ i) t₂ f → cont (infi t₁) t₂ f :=
continuous_le_dom $ infi_le _ _
lemma continuous_infi_rng {t₁ : tspace α} {t₂ : ι → tspace β}
(h : ∀i, cont t₁ (t₂ i) f) : cont t₁ (infi t₂) f :=
continuous_iff_coinduced_le.2 $ le_infi $ assume i, continuous_iff_coinduced_le.1 $ h i
@[continuity] lemma continuous_bot {t : tspace β} : cont ⊥ t f :=
continuous_iff_le_induced.2 $ bot_le
@[continuity] lemma continuous_top {t : tspace α} : cont t ⊤ f :=
continuous_iff_coinduced_le.2 $ le_top
/- 𝓝 in the induced topology -/
theorem mem_nhds_induced [T : topological_space α] (f : β → α) (a : β) (s : set β) :
s ∈ @nhds β (topological_space.induced f T) a ↔ ∃ u ∈ 𝓝 (f a), f ⁻¹' u ⊆ s :=
begin
simp only [mem_nhds_sets_iff, is_open_induced_iff, exists_prop, set.mem_set_of_eq],
split,
{ rintros ⟨u, usub, ⟨v, openv, ueq⟩, au⟩,
exact ⟨v, ⟨v, set.subset.refl v, openv, by rwa ←ueq at au⟩, by rw ueq; exact usub⟩ },
rintros ⟨u, ⟨v, vsubu, openv, amem⟩, finvsub⟩,
exact ⟨f ⁻¹' v, set.subset.trans (set.preimage_mono vsubu) finvsub, ⟨⟨v, openv, rfl⟩, amem⟩⟩
end
theorem nhds_induced [T : topological_space α] (f : β → α) (a : β) :
@nhds β (topological_space.induced f T) a = comap f (𝓝 (f a)) :=
by { ext s, rw [mem_nhds_induced, mem_comap_sets] }
lemma induced_iff_nhds_eq [tα : topological_space α] [tβ : topological_space β] (f : β → α) :
tβ = tα.induced f ↔ ∀ b, 𝓝 b = comap f (𝓝 $ f b) :=
⟨λ h a, h.symm ▸ nhds_induced f a, λ h, eq_of_nhds_eq_nhds $ λ x, by rw [h, nhds_induced]⟩
theorem map_nhds_induced_of_surjective [T : topological_space α]
{f : β → α} (hf : function.surjective f) (a : β) :
map f (@nhds β (topological_space.induced f T) a) = 𝓝 (f a) :=
by rw [nhds_induced, map_comap_of_surjective hf]
end constructions
section induced
open topological_space
variables {α : Type*} {β : Type*}
variables [t : topological_space β] {f : α → β}
theorem is_open_induced_eq {s : set α} :
@is_open _ (induced f t) s ↔ s ∈ preimage f '' {s | is_open s} :=
iff.rfl
theorem is_open_induced {s : set β} (h : is_open s) : (induced f t).is_open (f ⁻¹' s) :=
⟨s, h, rfl⟩
lemma map_nhds_induced_eq {a : α} (h : range f ∈ 𝓝 (f a)) :
map f (@nhds α (induced f t) a) = 𝓝 (f a) :=
by rw [nhds_induced, filter.map_comap h]
lemma closure_induced [t : topological_space β] {f : α → β} {a : α} {s : set α}
(hf : ∀x y, f x = f y → x = y) :
a ∈ @closure α (topological_space.induced f t) s ↔ f a ∈ closure (f '' s) :=
have ne_bot (comap f (𝓝 (f a) ⊓ 𝓟 (f '' s))) ↔ ne_bot (𝓝 (f a) ⊓ 𝓟 (f '' s)),
from ⟨assume h₁ h₂, h₁ $ h₂.symm ▸ comap_bot,
assume h,
forall_sets_nonempty_iff_ne_bot.mp $
assume s₁ ⟨s₂, hs₂, (hs : f ⁻¹' s₂ ⊆ s₁)⟩,
have f '' s ∈ 𝓝 (f a) ⊓ 𝓟 (f '' s),
from mem_inf_sets_of_right $ by simp [subset.refl],
have s₂ ∩ f '' s ∈ 𝓝 (f a) ⊓ 𝓟 (f '' s),
from inter_mem_sets hs₂ this,
let ⟨b, hb₁, ⟨a, ha, ha₂⟩⟩ := h.nonempty_of_mem this in
⟨_, hs $ by rwa [←ha₂] at hb₁⟩⟩,
calc a ∈ @closure α (topological_space.induced f t) s
↔ (@nhds α (topological_space.induced f t) a) ⊓ 𝓟 s ≠ ⊥ : by rw [closure_eq_cluster_pts]; refl
... ↔ comap f (𝓝 (f a)) ⊓ 𝓟 (f ⁻¹' (f '' s)) ≠ ⊥ : by rw [nhds_induced, preimage_image_eq _ hf]
... ↔ comap f (𝓝 (f a) ⊓ 𝓟 (f '' s)) ≠ ⊥ : by rw [comap_inf, ←comap_principal]
... ↔ _ : by rwa [closure_eq_cluster_pts]
end induced
section sierpinski
variables {α : Type*} [topological_space α]
@[simp] lemma is_open_singleton_true : is_open ({true} : set Prop) :=
topological_space.generate_open.basic _ (by simp)
lemma continuous_Prop {p : α → Prop} : continuous p ↔ is_open {x | p x} :=
⟨assume h : continuous p,
have is_open (p ⁻¹' {true}),
from is_open_singleton_true.preimage h,
by simp [preimage, eq_true] at this; assumption,
assume h : is_open {x | p x},
continuous_generated_from $ assume s (hs : s ∈ {{true}}),
by simp at hs; simp [hs, preimage, eq_true, h]⟩
end sierpinski
section infi
variables {α : Type u} {ι : Type v} {t : ι → topological_space α}
lemma is_open_supr_iff {s : set α} : @is_open _ (⨆ i, t i) s ↔ ∀ i, @is_open _ (t i) s :=
begin
-- s defines a map from α to Prop, which is continuous iff s is open.
suffices : @continuous _ _ (⨆ i, t i) _ s ↔ ∀ i, @continuous _ _ (t i) _ s,
{ simpa only [continuous_Prop] using this },
simp only [continuous_iff_le_induced, supr_le_iff]
end
lemma is_closed_infi_iff {s : set α} : @is_closed _ (⨆ i, t i) s ↔ ∀ i, @is_closed _ (t i) s :=
is_open_supr_iff
end infi
|
9c6baa40c0504b07834dd65807fbbcae9c62954e | 076f5040b63237c6dd928c6401329ed5adcb0e44 | /assignments/hw6_prop_logic_and_satifiability.lean | 52a921cf74d8bbae8a7eeae27604866626ab2e6d | [] | no_license | kevinsullivan/uva-cs-dm-f19 | 0f123689cf6cb078f263950b18382a7086bf30be | 09a950752884bd7ade4be33e9e89a2c4b1927167 | refs/heads/master | 1,594,771,841,541 | 1,575,853,850,000 | 1,575,853,850,000 | 205,433,890 | 4 | 9 | null | 1,571,592,121,000 | 1,567,188,539,000 | Lean | UTF-8 | Lean | false | false | 6,495 | lean | namespace prop_logic
/-
This assignment has five problems. The first
is to extend our propositional logic syntax
and semantics to support the three additional
connectives, exclusive or (⊕), implies (which
we will write as ⇒), and if and only iff (↔).
We first give you the definitions developed
in class. You are to extend/modify them to
support expressions with the new connectives.
The remaining problems use this definition of
our language of expressions in propositional
logic.
-/
/-
1. Extend our syntax and semantics
for propositional logic to support
the xor, implies, and iff and only
iff connectives/operators.
A. Add support for the exclusive or
connective/operator. Define the symbol,
⊕, as an infix notation.
Here are specific steps to take for the
exclusive or connective, as an example.
1. Add new binary connective, xorOp
2. Add pXor as shorthand for binOpExp xorOp
3. Add ⊕ as an infix notation for pXor
4. Specify the interpretation of ⊕ to be bxor
5. Extend interpBinOp to handle the new case
Then add support for the implies connective,
using the symbol, ⇒, as an infix operator.
We can't use → because it's reserved by Lean
and cannot be overloaded. Lean does not have
a Boolean implies operator (analogous to bor),
so you will have to define one. Call it bimpl.
Finally add support for if and only iff. Use
the symbol ↔ as an infix notation. You will
have to define a Boolean function as Lean
does not provide one for iff. Call it biff.
Here is the code as developed in class.
Now review the step-by-step instructions,
and proceed to read and midify this logic
as required. We've bracketed areas where
new material will have to be added.
-/
/- *** SYNTAX *** -/
inductive var : Type
| mkVar : ℕ → var
inductive unOp : Type
| notOp
inductive binOp : Type
| andOp
| orOp
/-HW-/
-- add new binOps here
/-HW-/
inductive pExp : Type
| litExp : bool → pExp
| varExp : var → pExp
| unOpExp : unOp → pExp → pExp
| binOpExp : binOp → pExp → pExp → pExp
open var
open pExp
open unOp
open binOp
-- Shorthand notations
def pTrue := litExp tt
def pFalse := litExp ff
def pNot := unOpExp notOp
def pAnd := binOpExp andOp
def pOr := binOpExp orOp
/-HW-/
-- Add new operator application
-- shorthands here.
/-HW-/
-- conventional notation
notation e1 ∧ e2 := pAnd e1 e2
notation e1 ∨ e2 := pOr e1 e2
notation ¬ e := pNot e
/-HW-/
-- Add new notations here
/-HW-/
/-
*****************
*** SEMANTICS ***
*****************
-/
def interpUnOp : unOp → (bool → bool)
| notOp := bnot
/-HW-/
-- Add Boolean function definitions here
/-HW-/
def interpBinOp : binOp → (bool → bool → bool)
| andOp := band
| orOp := bor
/-HW-/
-- Add cases for new binOps here
/-HW-/
/- *** SEMANTICS *** -/
/-
Given a pExp and an interpretation
for the variables, compute and return
the Boolean value of the expression.
-/
def pEval : pExp → (var → bool) → bool
| (litExp b) i := b
| (varExp v) i := i v
| (unOpExp op e) i :=
(interpUnOp op) (pEval e i)
| (binOpExp op e1 e2) i :=
(interpBinOp op)
(pEval e1 i)
(pEval e2 i)
/-
Note: You are free to use pEval, if you
wish to, to check answers to some of the
questions below. It is not mandatory and
you will not be marked down for not doing
this.
-/
/-
#2. Define X, Y, and Z to be variable
expressions bound to a different variable
expression terms. Hint: Look at the
prop_logic_test.lean file to remind
yourself how we did this in class.
-/
def X : _ := _
def Y : _ := _
def Z : _ := _
/-
#3. Here are some English language
sentences that you are to re-express
in propositional logic. Here's one
example.
-/
/-
EXAMPLE:
Formalize the following proposition,
as a formula in propositional logic:
If it's raining then it's raining.
-/
-- Use R to represent "it's raining"
def R : pExp := varExp (mkVar 4)
-- Solution here
/-
Explanation: We first choose to represent
the smaller proposition, "it's raining",
by the variable expression, R. We then
formalize the overall natural language
expression, if R then R, as the formula,
R ⇒ R.
Note: R ⇒ R can be pronounced as any of:
- if R is true then R is true
- if R then R
- the truth of R implies the truth of R
- R implies R
The second and fourth pronounciations
are the two that we prefer to use.
-/
/-
For the remaining problems, use the
variables expressions, X, Y, and Z,
as already defined. Use parentheses
if needed to group sub-expressions.
-/
/-
A.
If it's raining and the streets are
wet then it's raining.
-/
def p2 : pExp := _
/-
B. If it's raining and the streets
are wet, then the streets are wet
and it's raining.
-/
def p3 := _
/-
C. If it's raining then if the
streets are wet then it's raining
and the streets are wet.
-/
def p4 := _
/-
D. If it's raining then it's
raining or the moon is made of
green cheese.
-/
def p5 :=
/-
E. If it's raining, then if it's
raining implies that the streets
are wet, then the streets are wet.
-/
def p6 := _
/-
#4. For each of the propositional
logic expressions below, write a truth
table and based on your result, state
whether the expression is unsatisfiable,
satisfiable but not valid, or valid.
Here's an example solution for the
expression, (X ∧ Y) ⇒ Y.
X Y X ∧ Y (X ∧ Y) ⇒ Y
- - ----- -----------
T T T T
T F F T
F T F T
F F F T
The proposition is valid.
-/
/-
A. After each "#check" give your
answer for the specified proposition.
That is, write a truth table in a
comment and then say whether given the
proposition is valid, satisfiable but
not valid, or unsatisifiable.
Note: This expression reqires that
you have properly specified ¬ and
⇒ as notations in our pExp language.
The errors indicated in many of the
following lines will go away once
you have these notations properly
defined.
-/
#check (X ⇒ Y) ⇒ (¬ X ⇒ ¬ Y)
/-
-- Answer here
-/
/-
B.
-/
#check ((X ⇒ Y) ∧ (Y ⇒ X)) ⇒ (X ⇒ Z)
/-
-- Answer here
-/
/-
C.
-/
#check pFalse ⇒ (X ∧ ¬ X)
/-
-- Answer here
-/
/-
D.
-/
#check pTrue ⇒ (X ∧ ¬ X)
-- Answer here
/-
E.
-/
#check (X ∨ Y) ∧ X ⇒ ¬ Y
-- Answer here
/-
#5.
A. Find and present an interpretation
that causes the following proposition
to be satisfied (to evaluate to true).
(X ∨ Y) ∧ (¬ Y ∨ Z)
Answer:
B. Count and state how many of the
possible interpretations satisfy the
formula.
Answer;
-/
end prop_logic
|
0b8310d6fe6ad3da812b89c43b8126fd1199ccf6 | acc85b4be2c618b11fc7cb3005521ae6858a8d07 | /data/nat/pairing.lean | aefa18eb8eb376090a1e3a41e6f2e45c12b5e4b7 | [
"Apache-2.0"
] | permissive | linpingchuan/mathlib | d49990b236574df2a45d9919ba43c923f693d341 | 5ad8020f67eb13896a41cc7691d072c9331b1f76 | refs/heads/master | 1,626,019,377,808 | 1,508,048,784,000 | 1,508,048,784,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,406 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
Elegant pairing function.
-/
import data.nat.sqrt
open prod decidable
namespace nat
def mkpair (a b : nat) : nat :=
if a < b then b*b + a else a*a + a + b
def unpair (n : nat) : nat × nat :=
let s := sqrt n in
if n - s*s < s then (n - s*s, s) else (s, n - s*s - s)
theorem mkpair_unpair (n : nat) : mkpair (unpair n).1 (unpair n).2 = n :=
let s := sqrt n in begin
dsimp [unpair], change sqrt n with s,
have sm : s * s + (n - s * s) = n := nat.add_sub_cancel' (sqrt_le _),
by_cases n - s * s < s with h; simp [h, mkpair],
{ exact sm },
{ have hl : n - s*s - s ≤ s :=
nat.sub_le_left_of_le_add (nat.sub_le_left_of_le_add $
by rw ← add_assoc; apply sqrt_le_add),
suffices : s * s + (s + (n - s * s - s)) = n, {simpa [not_lt_of_ge hl]},
rwa [nat.add_sub_cancel' (le_of_not_gt h)] }
end
theorem mkpair_unpair' {n a b} (H : unpair n = (a, b)) : mkpair a b = n :=
by simpa [H] using mkpair_unpair n
theorem unpair_mkpair (a b : nat) : unpair (mkpair a b) = (a, b) :=
begin
by_cases a < b; simp [h, mkpair],
{ show unpair (a + b * b) = (a, b),
have be : sqrt (a + b * b) = b,
{ rw [add_comm, sqrt_add_eq],
exact le_trans (le_of_lt h) (le_add_left _ _) },
simp [unpair, be, nat.add_sub_cancel, h] },
{ show unpair (a + (b + a * a)) = (a, b),
have ae : sqrt (a + (b + a * a)) = a,
{ rw [← add_assoc, add_comm, sqrt_add_eq],
exact add_le_add_left (le_of_not_gt h) _ },
have : a ≤ a + (b + a * a) - a * a,
{ rw nat.add_sub_assoc (nat.le_add_left _ _), apply nat.le_add_right },
simp [unpair, ae, not_lt_of_ge this],
show a + (b + a * a) - a * a - a = b,
rw [nat.add_sub_assoc (nat.le_add_left _ _),
nat.add_sub_cancel, nat.add_sub_cancel_left] }
end
theorem unpair_lt {n : nat} (n1 : n ≥ 1) : (unpair n).1 < n :=
let s := sqrt n in begin
simp [unpair], change sqrt n with s,
by_cases n - s * s < s with h; simp [h],
{ exact lt_of_lt_of_le h (sqrt_le_self _) },
{ simp at h,
have s0 : s > 0 := sqrt_pos.2 n1,
exact lt_of_le_of_lt h (nat.sub_lt_self n1 (mul_pos s0 s0)) }
end
theorem unpair_le : ∀ (n : nat), (unpair n).1 ≤ n
| 0 := dec_trivial
| (n+1) := le_of_lt (unpair_lt (nat.succ_pos _))
end nat
|
1895c8354ba0a6cd7178ec4cb7ac8c44be0d48fa | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /tests/lean/run/class2.lean | 9768fea993f38df9835d9f8ccb81e9babe2d3c9e | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 198 | lean | import logic data.prod data.num
open prod nonempty inhabited
theorem H {A B : Type} (H1 : inhabited A) : inhabited (Prop × A × (B → num))
:= _
reveal H
(*
print(get_env():find("H"):value())
*)
|
74f6ff87fa04ee3006811bce11e4323f6e7d7ed5 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/group/inj_surj.lean | 68f1acbe5576b0ae9d604ed368f3978389327f1e | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 28,896 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.group.defs
import logic.function.basic
import data.int.cast.basic
/-!
# Lifting algebraic data classes along injective/surjective maps
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file provides definitions that are meant to deal with
situations such as the following:
Suppose that `G` is a group, and `H` is a type endowed with
`has_one H`, `has_mul H`, and `has_inv H`.
Suppose furthermore, that `f : G → H` is a surjective map
that respects the multiplication, and the unit elements.
Then `H` satisfies the group axioms.
The relevant definition in this case is `function.surjective.group`.
Dually, there is also `function.injective.group`.
And there are versions for (additive) (commutative) semigroups/monoids.
-/
namespace function
/-!
### Injective
-/
namespace injective
variables {M₁ : Type*} {M₂ : Type*} [has_mul M₁]
/-- A type endowed with `*` is a semigroup,
if it admits an injective map that preserves `*` to a semigroup.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `+` is an additive semigroup,
if it admits an injective map that preserves `+` to an additive semigroup."]
protected def semigroup [semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
semigroup M₁ :=
{ mul_assoc := λ x y z, hf $ by erw [mul, mul, mul, mul, mul_assoc],
..‹has_mul M₁› }
/-- A type endowed with `*` is a commutative semigroup,
if it admits an injective map that preserves `*` to a commutative semigroup.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `+` is an additive commutative semigroup,
if it admits an injective map that preserves `+` to an additive commutative semigroup."]
protected def comm_semigroup [comm_semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
comm_semigroup M₁ :=
{ mul_comm := λ x y, hf $ by erw [mul, mul, mul_comm],
.. hf.semigroup f mul }
/-- A type endowed with `*` is a left cancel semigroup,
if it admits an injective map that preserves `*` to a left cancel semigroup.
See note [reducible non-instances]. -/
@[reducible, to_additive add_left_cancel_semigroup
"A type endowed with `+` is an additive left cancel semigroup,
if it admits an injective map that preserves `+` to an additive left cancel semigroup."]
protected def left_cancel_semigroup [left_cancel_semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
left_cancel_semigroup M₁ :=
{ mul := (*),
mul_left_cancel := λ x y z H, hf $ (mul_right_inj (f x)).1 $ by erw [← mul, ← mul, H]; refl,
.. hf.semigroup f mul }
/-- A type endowed with `*` is a right cancel semigroup,
if it admits an injective map that preserves `*` to a right cancel semigroup.
See note [reducible non-instances]. -/
@[reducible, to_additive add_right_cancel_semigroup
"A type endowed with `+` is an additive right cancel semigroup,
if it admits an injective map that preserves `+` to an additive right cancel semigroup."]
protected def right_cancel_semigroup [right_cancel_semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
right_cancel_semigroup M₁ :=
{ mul := (*),
mul_right_cancel := λ x y z H, hf $ (mul_left_inj (f y)).1 $ by erw [← mul, ← mul, H]; refl,
.. hf.semigroup f mul }
variables [has_one M₁]
/-- A type endowed with `1` and `*` is a mul_one_class,
if it admits an injective map that preserves `1` and `*` to a mul_one_class.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an add_zero_class,
if it admits an injective map that preserves `0` and `+` to an add_zero_class."]
protected def mul_one_class [mul_one_class M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
mul_one_class M₁ :=
{ one_mul := λ x, hf $ by erw [mul, one, one_mul],
mul_one := λ x, hf $ by erw [mul, one, mul_one],
..‹has_one M₁›, ..‹has_mul M₁› }
variables [has_pow M₁ ℕ]
/-- A type endowed with `1` and `*` is a monoid,
if it admits an injective map that preserves `1` and `*` to a monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive monoid,
if it admits an injective map that preserves `0` and `+` to an additive monoid.
This version takes a custom `nsmul` as a `[has_smul ℕ M₁]` argument."]
protected def monoid [monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
monoid M₁ :=
{ npow := λ n x, x ^ n,
npow_zero' := λ x, hf $ by erw [npow, one, pow_zero],
npow_succ' := λ n x, hf $ by erw [npow, pow_succ, mul, npow],
.. hf.semigroup f mul, .. hf.mul_one_class f one mul }
/-- A type endowed with `0`, `1` and `+` is an additive monoid with one,
if it admits an injective map that preserves `0`, `1` and `+` to an additive monoid with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_monoid_with_one {M₁}
[has_zero M₁] [has_one M₁] [has_add M₁] [has_smul ℕ M₁] [has_nat_cast M₁]
[add_monoid_with_one M₂] (f : M₁ → M₂) (hf : injective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) :
add_monoid_with_one M₁ :=
{ nat_cast := coe,
nat_cast_zero := hf (by erw [nat_cast, nat.cast_zero, zero]),
nat_cast_succ := λ n, hf (by erw [nat_cast, nat.cast_succ, add, one, nat_cast]),
one := 1, .. hf.add_monoid f zero add nsmul }
/-- A type endowed with `1` and `*` is a left cancel monoid,
if it admits an injective map that preserves `1` and `*` to a left cancel monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive add_left_cancel_monoid
"A type endowed with `0` and `+` is an additive left cancel monoid,
if it admits an injective map that preserves `0` and `+` to an additive left cancel monoid."]
protected def left_cancel_monoid [left_cancel_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
left_cancel_monoid M₁ :=
{ .. hf.left_cancel_semigroup f mul, .. hf.monoid f one mul npow }
/-- A type endowed with `1` and `*` is a right cancel monoid,
if it admits an injective map that preserves `1` and `*` to a right cancel monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive add_right_cancel_monoid
"A type endowed with `0` and `+` is an additive left cancel monoid,
if it admits an injective map that preserves `0` and `+` to an additive left cancel monoid."]
protected def right_cancel_monoid [right_cancel_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
right_cancel_monoid M₁ :=
{ .. hf.right_cancel_semigroup f mul, .. hf.monoid f one mul npow }
/-- A type endowed with `1` and `*` is a cancel monoid,
if it admits an injective map that preserves `1` and `*` to a cancel monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive add_cancel_monoid
"A type endowed with `0` and `+` is an additive left cancel monoid,
if it admits an injective map that preserves `0` and `+` to an additive left cancel monoid."]
protected def cancel_monoid [cancel_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
cancel_monoid M₁ :=
{ .. hf.left_cancel_monoid f one mul npow, .. hf.right_cancel_monoid f one mul npow }
/-- A type endowed with `1` and `*` is a commutative monoid,
if it admits an injective map that preserves `1` and `*` to a commutative monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive commutative monoid,
if it admits an injective map that preserves `0` and `+` to an additive commutative monoid."]
protected def comm_monoid [comm_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
comm_monoid M₁ :=
{ .. hf.comm_semigroup f mul, .. hf.monoid f one mul npow }
/-- A type endowed with `0`, `1` and `+` is an additive commutative monoid with one, if it admits an
injective map that preserves `0`, `1` and `+` to an additive commutative monoid with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_comm_monoid_with_one {M₁} [has_zero M₁] [has_one M₁] [has_add M₁] [has_smul ℕ M₁]
[has_nat_cast M₁] [add_comm_monoid_with_one M₂] (f : M₁ → M₂) (hf : injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (nsmul : ∀ x (n : ℕ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) :
add_comm_monoid_with_one M₁ :=
{ ..hf.add_monoid_with_one f zero one add nsmul nat_cast, ..hf.add_comm_monoid f zero add nsmul }
/-- A type endowed with `1` and `*` is a cancel commutative monoid,
if it admits an injective map that preserves `1` and `*` to a cancel commutative monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive add_cancel_comm_monoid
"A type endowed with `0` and `+` is an additive cancel commutative monoid,
if it admits an injective map that preserves `0` and `+` to an additive cancel commutative monoid."]
protected def cancel_comm_monoid [cancel_comm_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
cancel_comm_monoid M₁ :=
{ .. hf.left_cancel_semigroup f mul, .. hf.comm_monoid f one mul npow }
/-- A type has an involutive inversion if it admits a surjective map that preserves `⁻¹` to a type
which has an involutive inversion. -/
@[reducible, to_additive "A type has an involutive negation if it admits a surjective map that
preserves `⁻¹` to a type which has an involutive inversion."] --See note [reducible non-instances]
protected def has_involutive_inv {M₁ : Type*} [has_inv M₁][has_involutive_inv M₂]
(f : M₁ → M₂) (hf : injective f) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) :
has_involutive_inv M₁ :=
{ inv := has_inv.inv,
inv_inv := λ x, hf $ by rw [inv, inv, inv_inv] }
variables [has_inv M₁] [has_div M₁] [has_pow M₁ ℤ]
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `div_inv_monoid`
if it admits an injective map that preserves `1`, `*`, `⁻¹`, and `/` to a `div_inv_monoid`.
See note [reducible non-instances]. -/
@[reducible, to_additive sub_neg_monoid
"A type endowed with `0`, `+`, unary `-`, and binary `-` is a `sub_neg_monoid`
if it admits an injective map that preserves `0`, `+`, unary `-`, and binary `-` to
a `sub_neg_monoid`.
This version takes custom `nsmul` and `zsmul` as `[has_smul ℕ M₁]` and
`[has_smul ℤ M₁]` arguments."]
protected def div_inv_monoid [div_inv_monoid M₂]
(f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
div_inv_monoid M₁ :=
{ zpow := λ n x, x ^ n,
zpow_zero' := λ x, hf $ by erw [zpow, zpow_zero, one],
zpow_succ' := λ n x, hf $ by erw [zpow, mul, zpow_of_nat, pow_succ, zpow, zpow_of_nat],
zpow_neg' := λ n x, hf $ by erw [zpow, zpow_neg_succ_of_nat, inv, zpow, zpow_coe_nat],
div_eq_mul_inv := λ x y, hf $ by erw [div, mul, inv, div_eq_mul_inv],
.. hf.monoid f one mul npow, .. ‹has_inv M₁›, .. ‹has_div M₁› }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `division_monoid`
if it admits an injective map that preserves `1`, `*`, `⁻¹`, and `/` to a `division_monoid`. -/
@[reducible, to_additive
"A type endowed with `0`, `+`, unary `-`, and binary `-` is a `subtraction_monoid`
if it admits an injective map that preserves `0`, `+`, unary `-`, and binary `-` to
a `subtraction_monoid`.
This version takes custom `nsmul` and `zsmul` as `[has_smul ℕ M₁]` and
`[has_smul ℤ M₁]` arguments."] -- See note [reducible non-instances]
protected def division_monoid [division_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
division_monoid M₁ :=
{ mul_inv_rev := λ x y, hf $ by erw [inv, mul, mul_inv_rev, mul, inv, inv],
inv_eq_of_mul := λ x y h, hf $ by erw [inv, inv_eq_of_mul_eq_one_right (by erw [←mul, h, one])],
..hf.div_inv_monoid f one mul inv div npow zpow, ..hf.has_involutive_inv f inv }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `division_comm_monoid`
if it admits an injective map that preserves `1`, `*`, `⁻¹`, and `/` to a `division_comm_monoid`.
See note [reducible non-instances]. -/
@[reducible, to_additive subtraction_comm_monoid
"A type endowed with `0`, `+`, unary `-`, and binary `-` is a `subtraction_comm_monoid`
if it admits an injective map that preserves `0`, `+`, unary `-`, and binary `-` to
a `subtraction_comm_monoid`.
This version takes custom `nsmul` and `zsmul` as `[has_smul ℕ M₁]` and
`[has_smul ℤ M₁]` arguments."] -- See note [reducible non-instances]
protected def division_comm_monoid [division_comm_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
division_comm_monoid M₁ :=
{ ..hf.division_monoid f one mul inv div npow zpow, .. hf.comm_semigroup f mul }
/-- A type endowed with `1`, `*` and `⁻¹` is a group,
if it admits an injective map that preserves `1`, `*` and `⁻¹` to a group.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive group,
if it admits an injective map that preserves `0` and `+` to an additive group."]
protected def group [group M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
group M₁ :=
{ mul_left_inv := λ x, hf $ by erw [mul, inv, mul_left_inv, one],
.. hf.div_inv_monoid f one mul inv div npow zpow }
/-- A type endowed with `0`, `1` and `+` is an additive group with one,
if it admits an injective map that preserves `0`, `1` and `+` to an additive group with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_group_with_one {M₁} [has_zero M₁] [has_one M₁] [has_add M₁] [has_smul ℕ M₁]
[has_neg M₁] [has_sub M₁] [has_smul ℤ M₁] [has_nat_cast M₁] [has_int_cast M₁]
[add_group_with_one M₂] (f : M₁ → M₂) (hf : injective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x) (zsmul : ∀ x (n : ℤ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) (int_cast : ∀ n : ℤ, f n = n) :
add_group_with_one M₁ :=
{ int_cast := coe,
int_cast_of_nat := λ n, hf (by simp only [nat_cast, int_cast, int.cast_coe_nat]),
int_cast_neg_succ_of_nat :=
λ n, hf (by erw [int_cast, neg, nat_cast, int.cast_neg, int.cast_coe_nat]),
.. hf.add_group f zero add neg sub nsmul zsmul,
.. hf.add_monoid_with_one f zero one add nsmul nat_cast }
/-- A type endowed with `1`, `*` and `⁻¹` is a commutative group,
if it admits an injective map that preserves `1`, `*` and `⁻¹` to a commutative group.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive commutative group,
if it admits an injective map that preserves `0` and `+` to an additive commutative group."]
protected def comm_group [comm_group M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
comm_group M₁ :=
{ .. hf.comm_monoid f one mul npow, .. hf.group f one mul inv div npow zpow }
/-- A type endowed with `0`, `1` and `+` is an additive commutative group with one, if it admits an
injective map that preserves `0`, `1` and `+` to an additive commutative group with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_comm_group_with_one {M₁} [has_zero M₁] [has_one M₁] [has_add M₁] [has_smul ℕ M₁]
[has_neg M₁] [has_sub M₁] [has_smul ℤ M₁] [has_nat_cast M₁] [has_int_cast M₁]
[add_comm_group_with_one M₂] (f : M₁ → M₂) (hf : injective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x) (zsmul : ∀ x (n : ℤ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) (int_cast : ∀ n : ℤ, f n = n) :
add_comm_group_with_one M₁ :=
{ ..hf.add_group_with_one f zero one add neg sub nsmul zsmul nat_cast int_cast,
..hf.add_comm_monoid f zero add nsmul }
end injective
/-!
### Surjective
-/
namespace surjective
variables {M₁ : Type*} {M₂ : Type*} [has_mul M₂]
/-- A type endowed with `*` is a semigroup,
if it admits a surjective map that preserves `*` from a semigroup.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `+` is an additive semigroup,
if it admits a surjective map that preserves `+` from an additive semigroup."]
protected def semigroup [semigroup M₁] (f : M₁ → M₂) (hf : surjective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
semigroup M₂ :=
{ mul_assoc := hf.forall₃.2 $ λ x y z, by simp only [← mul, mul_assoc],
..‹has_mul M₂› }
/-- A type endowed with `*` is a commutative semigroup,
if it admits a surjective map that preserves `*` from a commutative semigroup.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `+` is an additive commutative semigroup,
if it admits a surjective map that preserves `+` from an additive commutative semigroup."]
protected def comm_semigroup [comm_semigroup M₁] (f : M₁ → M₂) (hf : surjective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
comm_semigroup M₂ :=
{ mul_comm := hf.forall₂.2 $ λ x y, by erw [← mul, ← mul, mul_comm],
.. hf.semigroup f mul }
variables [has_one M₂]
/-- A type endowed with `1` and `*` is a mul_one_class,
if it admits a surjective map that preserves `1` and `*` from a mul_one_class.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an add_zero_class,
if it admits a surjective map that preserves `0` and `+` to an add_zero_class."]
protected def mul_one_class [mul_one_class M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
mul_one_class M₂ :=
{ one_mul := hf.forall.2 $ λ x, by erw [← one, ← mul, one_mul],
mul_one := hf.forall.2 $ λ x, by erw [← one, ← mul, mul_one],
..‹has_one M₂›, ..‹has_mul M₂› }
variables [has_pow M₂ ℕ]
/-- A type endowed with `1` and `*` is a monoid,
if it admits a surjective map that preserves `1` and `*` to a monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive monoid,
if it admits a surjective map that preserves `0` and `+` to an additive monoid.
This version takes a custom `nsmul` as a `[has_smul ℕ M₂]` argument."]
protected def monoid [monoid M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
monoid M₂ :=
{ npow := λ n x, x ^ n,
npow_zero' := hf.forall.2 $ λ x, by erw [←npow, pow_zero, ←one],
npow_succ' := λ n, hf.forall.2 $ λ x, by erw [←npow, pow_succ, ←npow, ←mul],
.. hf.semigroup f mul, .. hf.mul_one_class f one mul }
/-- A type endowed with `0`, `1` and `+` is an additive monoid with one,
if it admits a surjective map that preserves `0`, `1` and `*` from an additive monoid with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_monoid_with_one
{M₂} [has_zero M₂] [has_one M₂] [has_add M₂] [has_smul ℕ M₂] [has_nat_cast M₂]
[add_monoid_with_one M₁] (f : M₁ → M₂) (hf : surjective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) :
add_monoid_with_one M₂ :=
{ nat_cast := coe,
nat_cast_zero := by { rw [← nat_cast, nat.cast_zero, zero], refl },
nat_cast_succ := λ n, by { rw [← nat_cast, nat.cast_succ, add, one, nat_cast], refl },
one := 1, .. hf.add_monoid f zero add nsmul }
/-- A type endowed with `1` and `*` is a commutative monoid,
if it admits a surjective map that preserves `1` and `*` from a commutative monoid.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive commutative monoid,
if it admits a surjective map that preserves `0` and `+` to an additive commutative monoid."]
protected def comm_monoid [comm_monoid M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
comm_monoid M₂ :=
{ .. hf.comm_semigroup f mul, .. hf.monoid f one mul npow }
/-- A type endowed with `0`, `1` and `+` is an additive monoid with one,
if it admits a surjective map that preserves `0`, `1` and `*` from an additive monoid with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_comm_monoid_with_one
{M₂} [has_zero M₂] [has_one M₂] [has_add M₂] [has_smul ℕ M₂] [has_nat_cast M₂]
[add_comm_monoid_with_one M₁] (f : M₁ → M₂) (hf : surjective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) :
add_comm_monoid_with_one M₂ :=
{ ..hf.add_monoid_with_one f zero one add nsmul nat_cast, ..hf.add_comm_monoid _ zero _ nsmul }
/-- A type has an involutive inversion if it admits a surjective map that preserves `⁻¹` to a type
which has an involutive inversion. -/
@[reducible, to_additive "A type has an involutive negation if it admits a surjective map that
preserves `⁻¹` to a type which has an involutive inversion."] --See note [reducible non-instances]
protected def has_involutive_inv {M₂ : Type*} [has_inv M₂] [has_involutive_inv M₁]
(f : M₁ → M₂) (hf : surjective f) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) :
has_involutive_inv M₂ :=
{ inv := has_inv.inv,
inv_inv := hf.forall.2 $ λ x, by erw [←inv, ←inv, inv_inv] }
variables [has_inv M₂] [has_div M₂] [has_pow M₂ ℤ]
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `div_inv_monoid`
if it admits a surjective map that preserves `1`, `*`, `⁻¹`, and `/` to a `div_inv_monoid`.
See note [reducible non-instances]. -/
@[reducible, to_additive sub_neg_monoid
"A type endowed with `0`, `+`, unary `-`, and binary `-` is a `sub_neg_monoid`
if it admits a surjective map that preserves `0`, `+`, unary `-`, and binary `-` to
a `sub_neg_monoid`."]
protected def div_inv_monoid [div_inv_monoid M₁]
(f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
div_inv_monoid M₂ :=
{ zpow := λ n x, x ^ n,
zpow_zero' := hf.forall.2 $ λ x, by erw [←zpow, zpow_zero, ←one],
zpow_succ' := λ n, hf.forall.2 $ λ x, by
erw [←zpow, ←zpow, zpow_of_nat, zpow_of_nat, pow_succ, ←mul],
zpow_neg' := λ n, hf.forall.2 $ λ x, by
erw [←zpow, ←zpow, zpow_neg_succ_of_nat, zpow_coe_nat, inv],
div_eq_mul_inv := hf.forall₂.2 $ λ x y, by erw [← inv, ← mul, ← div, div_eq_mul_inv],
.. hf.monoid f one mul npow, .. ‹has_div M₂›, .. ‹has_inv M₂› }
/-- A type endowed with `1`, `*` and `⁻¹` is a group,
if it admits a surjective map that preserves `1`, `*` and `⁻¹` to a group.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive group,
if it admits a surjective map that preserves `0` and `+` to an additive group."]
protected def group [group M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
group M₂ :=
{ mul_left_inv := hf.forall.2 $ λ x, by erw [← inv, ← mul, mul_left_inv, one]; refl,
.. hf.div_inv_monoid f one mul inv div npow zpow }
/-- A type endowed with `0`, `1`, `+` is an additive group with one,
if it admits a surjective map that preserves `0`, `1`, and `+` to an additive group with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_group_with_one
{M₂} [has_zero M₂] [has_one M₂] [has_add M₂] [has_neg M₂] [has_sub M₂]
[has_smul ℕ M₂] [has_smul ℤ M₂] [has_nat_cast M₂] [has_int_cast M₂]
[add_group_with_one M₁] (f : M₁ → M₂) (hf : surjective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x) (zsmul : ∀ x (n : ℤ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) (int_cast : ∀ n : ℤ, f n = n) :
add_group_with_one M₂ :=
{ int_cast := coe,
int_cast_of_nat := λ n, by rw [← int_cast, int.cast_coe_nat, nat_cast],
int_cast_neg_succ_of_nat := λ n,
by { rw [← int_cast, int.cast_neg, int.cast_coe_nat, neg, nat_cast], refl },
.. hf.add_monoid_with_one f zero one add nsmul nat_cast,
.. hf.add_group f zero add neg sub nsmul zsmul }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a commutative group,
if it admits a surjective map that preserves `1`, `*`, `⁻¹`, and `/` from a commutative group.
See note [reducible non-instances]. -/
@[reducible, to_additive
"A type endowed with `0` and `+` is an additive commutative group,
if it admits a surjective map that preserves `0` and `+` to an additive commutative group."]
protected def comm_group [comm_group M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n) :
comm_group M₂ :=
{ .. hf.comm_monoid f one mul npow, .. hf.group f one mul inv div npow zpow }
/-- A type endowed with `0`, `1`, `+` is an additive commutative group with one, if it admits a
surjective map that preserves `0`, `1`, and `+` to an additive commutative group with one.
See note [reducible non-instances]. -/
@[reducible]
protected def add_comm_group_with_one
{M₂} [has_zero M₂] [has_one M₂] [has_add M₂] [has_neg M₂] [has_sub M₂]
[has_smul ℕ M₂] [has_smul ℤ M₂] [has_nat_cast M₂] [has_int_cast M₂]
[add_comm_group_with_one M₁] (f : M₁ → M₂) (hf : surjective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x) (zsmul : ∀ x (n : ℤ), f (n • x) = n • f x)
(nat_cast : ∀ n : ℕ, f n = n) (int_cast : ∀ n : ℤ, f n = n) :
add_comm_group_with_one M₂ :=
{ ..hf.add_group_with_one f zero one add neg sub nsmul zsmul nat_cast int_cast,
..hf.add_comm_monoid _ zero add nsmul }
end surjective
end function
|
24c070b4ff63df858cc37f08215a3109d8fb9104 | 3ed5a65c1ab3ce5d1a094edce8fa3287980f197b | /src/herstein/ex2_3/Q_10.lean | 2ea8a7a4d9a991320108f6bf9b0fadeef0335ee0 | [] | no_license | group-study-group/herstein | 35d32e77158efa2cc303c84e1ee5e3bc80831137 | f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66 | refs/heads/master | 1,586,202,191,519 | 1,548,969,759,000 | 1,548,969,759,000 | 157,746,953 | 0 | 0 | null | 1,542,412,901,000 | 1,542,302,366,000 | Lean | UTF-8 | Lean | false | false | 335 | lean | import algebra.group
variable {G: Type*}
theorem Q_10 [group G]:
(∀ a: G, a⁻¹ = a) →
(∀ a b: G, a * b = b * a) :=
λ h a b, mul_left_cancel (mul_right_cancel $
calc a * (a * b) * b
= a * (a⁻¹ * b⁻¹) * b : by rw [h, h]
... = a * (b * a)⁻¹ * b : by rw [←mul_inv_rev]
... = a * (b * a) * b : by rw h )
|
db31530d4c4a598ad537d9cfa080eee36fd3b272 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/finset/powerset.lean | adeeb63e6f1c4a3519c26aae54bcd21332d533b4 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 12,530 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.finset.lattice
import data.multiset.powerset
/-!
# The powerset of a finset
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
namespace finset
open function multiset
variables {α : Type*} {s t : finset α}
/-! ### powerset -/
section powerset
/-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/
def powerset (s : finset α) : finset (finset α) :=
⟨s.1.powerset.pmap finset.mk $ λ t h, nodup_of_le (mem_powerset.1 h) s.nodup,
s.nodup.powerset.pmap $ λ a ha b hb, congr_arg finset.val⟩
@[simp] theorem mem_powerset {s t : finset α} : s ∈ powerset t ↔ s ⊆ t :=
by cases s; simp only [powerset, mem_mk, mem_pmap, mem_powerset, exists_prop, exists_eq_right];
rw ← val_le_iff
@[simp, norm_cast] lemma coe_powerset (s : finset α) :
(s.powerset : set (finset α)) = coe ⁻¹' (s : set α).powerset :=
by { ext, simp }
@[simp] theorem empty_mem_powerset (s : finset α) : ∅ ∈ powerset s :=
mem_powerset.2 (empty_subset _)
@[simp] lemma mem_powerset_self (s : finset α) : s ∈ powerset s := mem_powerset.2 subset.rfl
lemma powerset_nonempty (s : finset α) : s.powerset.nonempty := ⟨∅, empty_mem_powerset _⟩
@[simp] theorem powerset_mono {s t : finset α} : powerset s ⊆ powerset t ↔ s ⊆ t :=
⟨λ h, (mem_powerset.1 $ h $ mem_powerset_self _),
λ st u h, mem_powerset.2 $ subset.trans (mem_powerset.1 h) st⟩
lemma powerset_injective : injective (powerset : finset α → finset (finset α)) :=
injective_of_le_imp_le _ $ λ s t, powerset_mono.1
@[simp] lemma powerset_inj : powerset s = powerset t ↔ s = t := powerset_injective.eq_iff
@[simp] lemma powerset_empty : (∅ : finset α).powerset = {∅} := rfl
@[simp] lemma powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ :=
by rw [←powerset_empty, powerset_inj]
/-- **Number of Subsets of a Set** -/
@[simp] theorem card_powerset (s : finset α) :
card (powerset s) = 2 ^ card s :=
(card_pmap _ _ _).trans (card_powerset s.1)
lemma not_mem_of_mem_powerset_of_not_mem {s t : finset α} {a : α}
(ht : t ∈ s.powerset) (h : a ∉ s) : a ∉ t :=
by { apply mt _ h, apply mem_powerset.1 ht }
lemma powerset_insert [decidable_eq α] (s : finset α) (a : α) :
powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) :=
begin
ext t,
simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff],
by_cases h : a ∈ t,
{ split,
{ exact λH, or.inr ⟨_, H, insert_erase h⟩ },
{ intros H,
cases H,
{ exact subset.trans (erase_subset a t) H },
{ rcases H with ⟨u, hu⟩,
rw ← hu.2,
exact subset.trans (erase_insert_subset a u) hu.1 } } },
{ have : ¬ ∃ (u : finset α), u ⊆ s ∧ insert a u = t,
by simp [ne.symm (ne_insert_of_not_mem _ _ h)],
simp [finset.erase_eq_of_not_mem h, this] }
end
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidable_exists_of_decidable_subsets {s : finset α} {p : Π t ⊆ s, Prop}
[Π t (h : t ⊆ s), decidable (p t h)] : decidable (∃ t (h : t ⊆ s), p t h) :=
decidable_of_iff (∃ t (hs : t ∈ s.powerset), p t (mem_powerset.1 hs))
⟨(λ ⟨t, _, hp⟩, ⟨t, _, hp⟩), (λ ⟨t, hs, hp⟩, ⟨t, mem_powerset.2 hs, hp⟩)⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidable_forall_of_decidable_subsets {s : finset α} {p : Π t ⊆ s, Prop}
[Π t (h : t ⊆ s), decidable (p t h)] : decidable (∀ t (h : t ⊆ s), p t h) :=
decidable_of_iff (∀ t (h : t ∈ s.powerset), p t (mem_powerset.1 h))
⟨(λ h t hs, h t (mem_powerset.2 hs)), (λ h _ _, h _ _)⟩
/-- A version of `finset.decidable_exists_of_decidable_subsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_exists_of_decidable_subsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊆ s), decidable (p t)) : decidable (∃ t (h : t ⊆ s), p t) :=
@finset.decidable_exists_of_decidable_subsets _ _ _ hu
/-- A version of `finset.decidable_forall_of_decidable_subsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_forall_of_decidable_subsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊆ s), decidable (p t)) : decidable (∀ t (h : t ⊆ s), p t) :=
@finset.decidable_forall_of_decidable_subsets _ _ _ hu
end powerset
section ssubsets
variables [decidable_eq α]
/-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/
def ssubsets (s : finset α) : finset (finset α) :=
erase (powerset s) s
@[simp] lemma mem_ssubsets {s t : finset α} : t ∈ s.ssubsets ↔ t ⊂ s :=
by rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and.comm]
lemma empty_mem_ssubsets {s : finset α} (h : s.nonempty) : ∅ ∈ s.ssubsets :=
by { rw [mem_ssubsets, ssubset_iff_subset_ne], exact ⟨empty_subset s, h.ne_empty.symm⟩, }
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/
instance decidable_exists_of_decidable_ssubsets {s : finset α} {p : Π t ⊂ s, Prop}
[Π t (h : t ⊂ s), decidable (p t h)] : decidable (∃ t h, p t h) :=
decidable_of_iff (∃ t (hs : t ∈ s.ssubsets), p t (mem_ssubsets.1 hs))
⟨(λ ⟨t, _, hp⟩, ⟨t, _, hp⟩), (λ ⟨t, hs, hp⟩, ⟨t, mem_ssubsets.2 hs, hp⟩)⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/
instance decidable_forall_of_decidable_ssubsets {s : finset α} {p : Π t ⊂ s, Prop}
[Π t (h : t ⊂ s), decidable (p t h)] : decidable (∀ t h, p t h) :=
decidable_of_iff (∀ t (h : t ∈ s.ssubsets), p t (mem_ssubsets.1 h))
⟨(λ h t hs, h t (mem_ssubsets.2 hs)), (λ h _ _, h _ _)⟩
/-- A version of `finset.decidable_exists_of_decidable_ssubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_exists_of_decidable_ssubsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊂ s), decidable (p t)) : decidable (∃ t (h : t ⊂ s), p t) :=
@finset.decidable_exists_of_decidable_ssubsets _ _ _ _ hu
/-- A version of `finset.decidable_forall_of_decidable_ssubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidable_forall_of_decidable_ssubsets' {s : finset α} {p : finset α → Prop}
(hu : Π t (h : t ⊂ s), decidable (p t)) : decidable (∀ t (h : t ⊂ s), p t) :=
@finset.decidable_forall_of_decidable_ssubsets _ _ _ _ hu
end ssubsets
section powerset_len
/-- Given an integer `n` and a finset `s`, then `powerset_len n s` is the finset of subsets of `s`
of cardinality `n`. -/
def powerset_len (n : ℕ) (s : finset α) : finset (finset α) :=
⟨(s.1.powerset_len n).pmap finset.mk $ λ t h, nodup_of_le (mem_powerset_len.1 h).1 s.2,
s.2.powerset_len.pmap $ λ a ha b hb, congr_arg finset.val⟩
/-- **Formula for the Number of Combinations** -/
theorem mem_powerset_len {n} {s t : finset α} :
s ∈ powerset_len n t ↔ s ⊆ t ∧ card s = n :=
by cases s; simp [powerset_len, val_le_iff.symm]; refl
@[simp] theorem powerset_len_mono {n} {s t : finset α} (h : s ⊆ t) :
powerset_len n s ⊆ powerset_len n t :=
λ u h', mem_powerset_len.2 $
and.imp (λ h₂, subset.trans h₂ h) id (mem_powerset_len.1 h')
/-- **Formula for the Number of Combinations** -/
@[simp] theorem card_powerset_len (n : ℕ) (s : finset α) :
card (powerset_len n s) = nat.choose (card s) n :=
(card_pmap _ _ _).trans (card_powerset_len n s.1)
@[simp] lemma powerset_len_zero (s : finset α) : finset.powerset_len 0 s = {∅} :=
begin
ext, rw [mem_powerset_len, mem_singleton, card_eq_zero],
refine ⟨λ h, h.2, λ h, by { rw h, exact ⟨empty_subset s, rfl⟩ }⟩,
end
@[simp] theorem powerset_len_empty (n : ℕ) {s : finset α} (h : s.card < n) :
powerset_len n s = ∅ :=
finset.card_eq_zero.mp (by rw [card_powerset_len, nat.choose_eq_zero_of_lt h])
theorem powerset_len_eq_filter {n} {s : finset α} :
powerset_len n s = (powerset s).filter (λ x, x.card = n) :=
by { ext, simp [mem_powerset_len] }
lemma powerset_len_succ_insert [decidable_eq α] {x : α} {s : finset α} (h : x ∉ s) (n : ℕ) :
powerset_len n.succ (insert x s) = powerset_len n.succ s ∪ (powerset_len n s).image (insert x) :=
begin
rw [powerset_len_eq_filter, powerset_insert, filter_union, ←powerset_len_eq_filter],
congr,
rw [powerset_len_eq_filter, image_filter],
congr' 1,
ext t,
simp only [mem_powerset, mem_filter, function.comp_app, and.congr_right_iff],
intro ht,
have : x ∉ t := λ H, h (ht H),
simp [card_insert_of_not_mem this, nat.succ_inj']
end
lemma powerset_len_nonempty {n : ℕ} {s : finset α} (h : n ≤ s.card) :
(powerset_len n s).nonempty :=
begin
classical,
induction s using finset.induction_on with x s hx IH generalizing n,
{ rw [card_empty, le_zero_iff] at h,
rw [h, powerset_len_zero],
exact finset.singleton_nonempty _, },
{ cases n,
{ simp },
{ rw [card_insert_of_not_mem hx, nat.succ_le_succ_iff] at h,
rw powerset_len_succ_insert hx,
refine nonempty.mono _ ((IH h).image (insert x)),
convert (subset_union_right _ _) } }
end
@[simp] lemma powerset_len_self (s : finset α) :
powerset_len s.card s = {s} :=
begin
ext,
rw [mem_powerset_len, mem_singleton],
split,
{ exact λ ⟨hs, hc⟩, eq_of_subset_of_card_le hs hc.ge },
{ rintro rfl,
simp }
end
lemma pairwise_disjoint_powerset_len (s : finset α) :
_root_.pairwise (λ i j, disjoint (s.powerset_len i) (s.powerset_len j)) :=
λ i j hij, finset.disjoint_left.mpr $ λ x hi hj, hij $
(mem_powerset_len.mp hi).2.symm.trans (mem_powerset_len.mp hj).2
lemma powerset_card_disj_Union (s : finset α) :
finset.powerset s =
(range (s.card + 1)).disj_Union (λ i, powerset_len i s)
(s.pairwise_disjoint_powerset_len.set_pairwise _) :=
begin
refine ext (λ a, ⟨λ ha, _, λ ha, _ ⟩),
{ rw mem_disj_Union,
exact ⟨a.card, mem_range.mpr (nat.lt_succ_of_le (card_le_of_subset (mem_powerset.mp ha))),
mem_powerset_len.mpr ⟨mem_powerset.mp ha, rfl⟩⟩ },
{ rcases mem_disj_Union.mp ha with ⟨i, hi, ha⟩,
exact mem_powerset.mpr (mem_powerset_len.mp ha).1, }
end
lemma powerset_card_bUnion [decidable_eq (finset α)] (s : finset α) :
finset.powerset s = (range (s.card + 1)).bUnion (λ i, powerset_len i s) :=
by simpa only [disj_Union_eq_bUnion] using powerset_card_disj_Union s
lemma powerset_len_sup [decidable_eq α] (u : finset α) (n : ℕ) (hn : n < u.card) :
(powerset_len n.succ u).sup id = u :=
begin
apply le_antisymm,
{ simp_rw [finset.sup_le_iff, mem_powerset_len],
rintros x ⟨h, -⟩,
exact h },
{ rw [sup_eq_bUnion, le_iff_subset, subset_iff],
cases (nat.succ_le_of_lt hn).eq_or_lt with h' h',
{ simp [h'] },
{ intros x hx,
simp only [mem_bUnion, exists_prop, id.def],
obtain ⟨t, ht⟩ : ∃ t, t ∈ powerset_len n (u.erase x) := powerset_len_nonempty _,
{ refine ⟨insert x t, _, mem_insert_self _ _⟩,
rw [←insert_erase hx, powerset_len_succ_insert (not_mem_erase _ _)],
exact mem_union_right _ (mem_image_of_mem _ ht) },
{ rw [card_erase_of_mem hx],
exact nat.le_pred_of_lt hn, } } }
end
@[simp]
lemma powerset_len_card_add (s : finset α) {i : ℕ} (hi : 0 < i) :
s.powerset_len (s.card + i) = ∅ :=
finset.powerset_len_empty _ (lt_add_of_pos_right (finset.card s) hi)
@[simp] theorem map_val_val_powerset_len (s : finset α) (i : ℕ) :
(s.powerset_len i).val.map finset.val = s.1.powerset_len i :=
by simp [finset.powerset_len, map_pmap, pmap_eq_map, map_id']
theorem powerset_len_map {β : Type*} (f : α ↪ β) (n : ℕ) (s : finset α) :
powerset_len n (s.map f) = (powerset_len n s).map (map_embedding f).to_embedding :=
eq_of_veq $ multiset.map_injective (@eq_of_veq _) $
by simp_rw [map_val_val_powerset_len, map_val, multiset.map_map, function.comp,
rel_embedding.coe_fn_to_embedding, map_embedding_apply, map_val, ←multiset.map_map _ val,
map_val_val_powerset_len, multiset.powerset_len_map]
end powerset_len
end finset
|
948000f2f248142fb4fcd16d384f7b35da17a994 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/ring_theory/coprime/lemmas.lean | 454d672e59b7befe223d27dad83ff0850bdfe33c | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 8,093 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Ken Lee, Chris Hughes
-/
import algebra.big_operators.ring
import data.fintype.basic
import data.int.gcd
import ring_theory.coprime.basic
/-!
# Additional lemmas about elements of a ring satisfying `is_coprime`
These lemmas are in a separate file to the definition of `is_coprime` as they require more imports.
Notably, this includes lemmas about `finset.prod` as this requires importing big_operators, and
lemmas about `has_pow` since these are easiest to prove via `finset.prod`.
-/
universes u v
variables {R : Type u} {I : Type v} [comm_semiring R] {x y z : R} {s : I → R} {t : finset I}
open_locale big_operators
section
open_locale classical
theorem nat.is_coprime_iff_coprime {m n : ℕ} : is_coprime (m : ℤ) n ↔ nat.coprime m n :=
⟨λ ⟨a, b, H⟩, nat.eq_one_of_dvd_one $ int.coe_nat_dvd.1 $ by { rw [int.coe_nat_one, ← H],
exact dvd_add (dvd_mul_of_dvd_right (int.coe_nat_dvd.2 $ nat.gcd_dvd_left m n) _)
(dvd_mul_of_dvd_right (int.coe_nat_dvd.2 $ nat.gcd_dvd_right m n) _) },
λ H, ⟨nat.gcd_a m n, nat.gcd_b m n, by rw [mul_comm _ (m : ℤ), mul_comm _ (n : ℤ),
← nat.gcd_eq_gcd_ab, show _ = _, from H, int.coe_nat_one]⟩⟩
theorem is_coprime.prod_left : (∀ i ∈ t, is_coprime (s i) x) → is_coprime (∏ i in t, s i) x :=
finset.induction_on t (λ _, is_coprime_one_left) $ λ b t hbt ih H,
by { rw finset.prod_insert hbt, rw finset.forall_mem_insert at H, exact H.1.mul_left (ih H.2) }
theorem is_coprime.prod_right : (∀ i ∈ t, is_coprime x (s i)) → is_coprime x (∏ i in t, s i) :=
by simpa only [is_coprime_comm] using is_coprime.prod_left
theorem is_coprime.prod_left_iff : is_coprime (∏ i in t, s i) x ↔ ∀ i ∈ t, is_coprime (s i) x :=
finset.induction_on t (iff_of_true is_coprime_one_left $ λ _, false.elim) $ λ b t hbt ih,
by rw [finset.prod_insert hbt, is_coprime.mul_left_iff, ih, finset.forall_mem_insert]
theorem is_coprime.prod_right_iff : is_coprime x (∏ i in t, s i) ↔ ∀ i ∈ t, is_coprime x (s i) :=
by simpa only [is_coprime_comm] using is_coprime.prod_left_iff
theorem is_coprime.of_prod_left (H1 : is_coprime (∏ i in t, s i) x) (i : I) (hit : i ∈ t) :
is_coprime (s i) x :=
is_coprime.prod_left_iff.1 H1 i hit
theorem is_coprime.of_prod_right (H1 : is_coprime x (∏ i in t, s i)) (i : I) (hit : i ∈ t) :
is_coprime x (s i) :=
is_coprime.prod_right_iff.1 H1 i hit
theorem finset.prod_dvd_of_coprime :
∀ (Hs : (t : set I).pairwise (is_coprime on s)) (Hs1 : ∀ i ∈ t, s i ∣ z),
∏ x in t, s x ∣ z :=
finset.induction_on t (λ _ _, one_dvd z)
begin
intros a r har ih Hs Hs1,
rw finset.prod_insert har,
have aux1 : a ∈ (↑(insert a r) : set I) := finset.mem_insert_self a r,
refine (is_coprime.prod_right $ λ i hir, Hs aux1 (finset.mem_insert_of_mem hir)
$ by { rintro rfl, exact har hir }).mul_dvd
(Hs1 a aux1) (ih (Hs.mono _) $ λ i hi, Hs1 i $ finset.mem_insert_of_mem hi),
simp only [finset.coe_insert, set.subset_insert],
end
theorem fintype.prod_dvd_of_coprime [fintype I] (Hs : pairwise (is_coprime on s))
(Hs1 : ∀ i, s i ∣ z) : ∏ x, s x ∣ z :=
finset.prod_dvd_of_coprime (Hs.set_pairwise _) (λ i _, Hs1 i)
end
open finset
lemma exists_sum_eq_one_iff_pairwise_coprime [decidable_eq I] (h : t.nonempty) :
(∃ μ : I → R, ∑ i in t, μ i * ∏ j in t \ {i}, s j = 1) ↔ pairwise (is_coprime on λ i : t, s i) :=
begin
refine h.cons_induction _ _; clear' t h,
{ simp only [pairwise, sum_singleton, finset.sdiff_self, prod_empty, mul_one,
exists_apply_eq_apply, ne.def, true_iff],
rintro a ⟨i, hi⟩ ⟨j, hj⟩ h,
rw finset.mem_singleton at hi hj,
simpa [hi, hj] using h },
intros a t hat h ih,
rw pairwise_cons',
have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := λ x hx, by
{ rw [mem_sdiff, mem_singleton], exact ⟨mem_insert_self _ _, λ ha, hat (ha.symm.cases_on hx)⟩ },
split,
{ rintro ⟨μ, hμ⟩,
rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ,
refine ⟨ih.mp ⟨pi.single h.some (μ a * s h.some) + μ * λ _, s a, _⟩, λ b hb, _⟩,
{ rw [prod_eq_mul_prod_diff_singleton h.some_spec, ← mul_assoc,
← @if_pos _ _ h.some_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ,
rw [← hμ, sum_congr rfl], intros x hx, convert add_mul _ _ _ using 2,
{ by_cases hx : x = h.some,
{ rw [hx, pi.single_eq_same, pi.single_eq_same] },
{ rw [pi.single_eq_of_ne hx, pi.single_eq_of_ne hx, zero_mul] } },
{ convert (mul_assoc _ _ _).symm,
convert prod_eq_mul_prod_diff_singleton (mem x hx) _ using 3,
convert sdiff_sdiff_comm, rw [sdiff_singleton_eq_erase, erase_insert hat] } },
{ have : is_coprime (s b) (s a) :=
⟨μ a * ∏ i in t \ {b}, s i, ∑ i in t, μ i * ∏ j in t \ {i}, s j, _⟩,
{ exact ⟨this.symm, this⟩ },
rw [mul_assoc, ← prod_eq_prod_diff_singleton_mul hb, sum_mul, ← hμ, sum_congr rfl],
intros x hx, convert mul_assoc _ _ _,
convert prod_eq_prod_diff_singleton_mul (mem x hx) _ using 3,
convert sdiff_sdiff_comm, rw [sdiff_singleton_eq_erase, erase_insert hat] } },
{ rintro ⟨hs, Hb⟩, obtain ⟨μ, hμ⟩ := ih.mpr hs,
obtain ⟨u, v, huv⟩ := is_coprime.prod_left (λ b hb, (Hb b hb).right),
use λ i, if i = a then u else v * μ i,
have hμ' : ∑ i in t, v * ((μ i * ∏ j in t \ {i}, s j) * s a) = v * s a := by
rw [← mul_sum, ← sum_mul, hμ, one_mul],
rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat, if_pos rfl,
← huv, ← hμ', sum_congr rfl], intros x hx,
rw [mul_assoc, if_neg (λ ha : x = a, hat (ha.cases_on hx))],
convert mul_assoc _ _ _, convert (prod_eq_prod_diff_singleton_mul (mem x hx) _).symm using 3,
convert sdiff_sdiff_comm, rw [sdiff_singleton_eq_erase, erase_insert hat] }
end
lemma exists_sum_eq_one_iff_pairwise_coprime' [fintype I] [nonempty I] [decidable_eq I] :
(∃ μ : I → R, ∑ (i : I), μ i * ∏ j in {i}ᶜ, s j = 1) ↔ pairwise (is_coprime on s) :=
begin
convert exists_sum_eq_one_iff_pairwise_coprime finset.univ_nonempty using 1,
simp only [function.on_fun, pairwise_subtype_iff_pairwise_finset', coe_univ, set.pairwise_univ],
assumption
end
lemma pairwise_coprime_iff_coprime_prod [decidable_eq I] :
pairwise (is_coprime on λ i : t, s i) ↔ ∀ i ∈ t, is_coprime (s i) (∏ j in t \ {i}, (s j)) :=
begin
refine ⟨λ hp i hi, is_coprime.prod_right_iff.mpr (λ j hj, _), λ hp, _⟩,
{ rw [finset.mem_sdiff, finset.mem_singleton] at hj,
obtain ⟨hj, ji⟩ := hj,
exact hp ⟨i, hi⟩ ⟨j, hj⟩ (λ h, ji (congr_arg coe h).symm) },
{ rintro ⟨i, hi⟩ ⟨j, hj⟩ h,
apply is_coprime.prod_right_iff.mp (hp i hi),
exact finset.mem_sdiff.mpr ⟨hj, λ f, h $ subtype.ext (finset.mem_singleton.mp f).symm⟩ }
end
variables {m n : ℕ}
theorem is_coprime.pow_left (H : is_coprime x y) : is_coprime (x ^ m) y :=
by { rw [← finset.card_range m, ← finset.prod_const], exact is_coprime.prod_left (λ _ _, H) }
theorem is_coprime.pow_right (H : is_coprime x y) : is_coprime x (y ^ n) :=
by { rw [← finset.card_range n, ← finset.prod_const], exact is_coprime.prod_right (λ _ _, H) }
theorem is_coprime.pow (H : is_coprime x y) : is_coprime (x ^ m) (y ^ n) :=
H.pow_left.pow_right
theorem is_coprime.pow_left_iff (hm : 0 < m) : is_coprime (x ^ m) y ↔ is_coprime x y :=
begin
refine ⟨λ h, _, is_coprime.pow_left⟩,
rw [← finset.card_range m, ← finset.prod_const] at h,
exact h.of_prod_left 0 (finset.mem_range.mpr hm),
end
theorem is_coprime.pow_right_iff (hm : 0 < m) : is_coprime x (y ^ m) ↔ is_coprime x y :=
is_coprime_comm.trans $ (is_coprime.pow_left_iff hm).trans $ is_coprime_comm
theorem is_coprime.pow_iff (hm : 0 < m) (hn : 0 < n) :
is_coprime (x ^ m) (y ^ n) ↔ is_coprime x y :=
(is_coprime.pow_left_iff hm).trans $ is_coprime.pow_right_iff hn
|
19d7ff1cd21c930a1991b34635577041da6f1bdf | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/analysis/normed_space/ball_action.lean | 472cc334c00a8196aff2b2fc9d5c85d49dc4cb7e | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 7,892 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Heather Macbeth
-/
import analysis.normed.field.unit_ball
import analysis.normed_space.basic
/-!
# Multiplicative actions of/on balls and spheres
Let `E` be a normed vector space over a normed field `𝕜`. In this file we define the following
multiplicative actions.
- The closed unit ball in `𝕜` acts on open balls and closed balls centered at `0` in `E`.
- The unit sphere in `𝕜` acts on open balls, closed balls, and spheres centered at `0` in `E`.
-/
open metric set
variables {𝕜 𝕜' E : Type*} [normed_field 𝕜] [normed_field 𝕜']
[seminormed_add_comm_group E] [normed_space 𝕜 E] [normed_space 𝕜' E] {r : ℝ}
section closed_ball
instance mul_action_closed_ball_ball : mul_action (closed_ball (0 : 𝕜) 1) (ball (0 : E) r) :=
{ smul := λ c x, ⟨(c : 𝕜) • x, mem_ball_zero_iff.2 $
by simpa only [norm_smul, one_mul]
using mul_lt_mul' (mem_closed_ball_zero_iff.1 c.2) (mem_ball_zero_iff.1 x.2)
(norm_nonneg _) one_pos⟩,
one_smul := λ x, subtype.ext $ one_smul 𝕜 _,
mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ }
instance has_continuous_smul_closed_ball_ball :
has_continuous_smul (closed_ball (0 : 𝕜) 1) (ball (0 : E) r) :=
⟨(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _⟩
instance mul_action_closed_ball_closed_ball :
mul_action (closed_ball (0 : 𝕜) 1) (closed_ball (0 : E) r) :=
{ smul := λ c x, ⟨(c : 𝕜) • x, mem_closed_ball_zero_iff.2 $
by simpa only [norm_smul, one_mul]
using mul_le_mul (mem_closed_ball_zero_iff.1 c.2) (mem_closed_ball_zero_iff.1 x.2)
(norm_nonneg _) zero_le_one⟩,
one_smul := λ x, subtype.ext $ one_smul 𝕜 _,
mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ }
instance has_continuous_smul_closed_ball_closed_ball :
has_continuous_smul (closed_ball (0 : 𝕜) 1) (closed_ball (0 : E) r) :=
⟨(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _⟩
end closed_ball
section sphere
instance mul_action_sphere_ball : mul_action (sphere (0 : 𝕜) 1) (ball (0 : E) r) :=
{ smul := λ c x, inclusion sphere_subset_closed_ball c • x,
one_smul := λ x, subtype.ext $ one_smul _ _,
mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ }
instance has_continuous_smul_sphere_ball :
has_continuous_smul (sphere (0 : 𝕜) 1) (ball (0 : E) r) :=
⟨(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _⟩
instance mul_action_sphere_closed_ball : mul_action (sphere (0 : 𝕜) 1) (closed_ball (0 : E) r) :=
{ smul := λ c x, inclusion sphere_subset_closed_ball c • x,
one_smul := λ x, subtype.ext $ one_smul _ _,
mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ }
instance has_continuous_smul_sphere_closed_ball :
has_continuous_smul (sphere (0 : 𝕜) 1) (closed_ball (0 : E) r) :=
⟨(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _⟩
instance mul_action_sphere_sphere : mul_action (sphere (0 : 𝕜) 1) (sphere (0 : E) r) :=
{ smul := λ c x, ⟨(c : 𝕜) • x, mem_sphere_zero_iff_norm.2 $
by rw [norm_smul, mem_sphere_zero_iff_norm.1 c.coe_prop, mem_sphere_zero_iff_norm.1 x.coe_prop,
one_mul]⟩,
one_smul := λ x, subtype.ext $ one_smul _ _,
mul_smul := λ c₁ c₂ x, subtype.ext $ mul_smul _ _ _ }
instance has_continuous_smul_sphere_sphere :
has_continuous_smul (sphere (0 : 𝕜) 1) (sphere (0 : E) r) :=
⟨(continuous_subtype_val.fst'.smul continuous_subtype_val.snd').subtype_mk _⟩
end sphere
section is_scalar_tower
variables [normed_algebra 𝕜 𝕜'] [is_scalar_tower 𝕜 𝕜' E]
instance is_scalar_tower_closed_ball_closed_ball_closed_ball :
is_scalar_tower (closed_ball (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (closed_ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : E)⟩
instance is_scalar_tower_closed_ball_closed_ball_ball :
is_scalar_tower (closed_ball (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : E)⟩
instance is_scalar_tower_sphere_closed_ball_closed_ball :
is_scalar_tower (sphere (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (closed_ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : E)⟩
instance is_scalar_tower_sphere_closed_ball_ball :
is_scalar_tower (sphere (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : E)⟩
instance is_scalar_tower_sphere_sphere_closed_ball :
is_scalar_tower (sphere (0 : 𝕜) 1) (sphere (0 : 𝕜') 1) (closed_ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : E)⟩
instance is_scalar_tower_sphere_sphere_ball :
is_scalar_tower (sphere (0 : 𝕜) 1) (sphere (0 : 𝕜') 1) (ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : E)⟩
instance is_scalar_tower_sphere_sphere_sphere :
is_scalar_tower (sphere (0 : 𝕜) 1) (sphere (0 : 𝕜') 1) (sphere (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : E)⟩
instance is_scalar_tower_sphere_ball_ball :
is_scalar_tower (sphere (0 : 𝕜) 1) (ball (0 : 𝕜') 1) (ball (0 : 𝕜') 1) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : 𝕜')⟩
instance is_scalar_tower_closed_ball_ball_ball :
is_scalar_tower (closed_ball (0 : 𝕜) 1) (ball (0 : 𝕜') 1) (ball (0 : 𝕜') 1) :=
⟨λ a b c, subtype.ext $ smul_assoc (a : 𝕜) (b : 𝕜') (c : 𝕜')⟩
end is_scalar_tower
section smul_comm_class
variables [smul_comm_class 𝕜 𝕜' E]
instance smul_comm_class_closed_ball_closed_ball_closed_ball :
smul_comm_class (closed_ball (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (closed_ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : E)⟩
instance smul_comm_class_closed_ball_closed_ball_ball :
smul_comm_class (closed_ball (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : E)⟩
instance smul_comm_class_sphere_closed_ball_closed_ball :
smul_comm_class (sphere (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (closed_ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : E)⟩
instance smul_comm_class_sphere_closed_ball_ball :
smul_comm_class (sphere (0 : 𝕜) 1) (closed_ball (0 : 𝕜') 1) (ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : E)⟩
instance smul_comm_class_sphere_ball_ball [normed_algebra 𝕜 𝕜'] :
smul_comm_class (sphere (0 : 𝕜) 1) (ball (0 : 𝕜') 1) (ball (0 : 𝕜') 1) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : 𝕜')⟩
instance smul_comm_class_sphere_sphere_closed_ball :
smul_comm_class (sphere (0 : 𝕜) 1) (sphere (0 : 𝕜') 1) (closed_ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : E)⟩
instance smul_comm_class_sphere_sphere_ball :
smul_comm_class (sphere (0 : 𝕜) 1) (sphere (0 : 𝕜') 1) (ball (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : E)⟩
instance smul_comm_class_sphere_sphere_sphere :
smul_comm_class (sphere (0 : 𝕜) 1) (sphere (0 : 𝕜') 1) (sphere (0 : E) r) :=
⟨λ a b c, subtype.ext $ smul_comm (a : 𝕜) (b : 𝕜') (c : E)⟩
end smul_comm_class
variables (𝕜) [char_zero 𝕜]
lemma ne_neg_of_mem_sphere {r : ℝ} (hr : r ≠ 0) (x : sphere (0:E) r) : x ≠ - x :=
λ h, ne_zero_of_mem_sphere hr x ((self_eq_neg 𝕜 _).mp (by { conv_lhs {rw h}, simp }))
lemma ne_neg_of_mem_unit_sphere (x : sphere (0:E) 1) : x ≠ - x :=
ne_neg_of_mem_sphere 𝕜 one_ne_zero x
|
cbebd2d8e7348c19cc64667c59317917bb68ac27 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/category_theory/limits/shapes/wide_pullbacks.lean | 3c5202c0ff198a0195d61796f1cc2dc962740435 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 11,685 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.has_limits
import category_theory.thin
/-!
# Wide pullbacks
We define the category `wide_pullback_shape`, (resp. `wide_pushout_shape`) which is the category
obtained from a discrete category of type `J` by adjoining a terminal (resp. initial) element.
Limits of this shape are wide pullbacks (pushouts).
The convenience method `wide_cospan` (`wide_span`) constructs a functor from this category, hitting
the given morphisms.
We use `wide_pullback_shape` to define ordinary pullbacks (pushouts) by using `J := walking_pair`,
which allows easy proofs of some related lemmas.
Furthermore, wide pullbacks are used to show the existence of limits in the slice category.
Namely, if `C` has wide pullbacks then `C/B` has limits for any object `B` in `C`.
Typeclasses `has_wide_pullbacks` and `has_finite_wide_pullbacks` assert the existence of wide
pullbacks and finite wide pullbacks.
-/
universes v u
open category_theory category_theory.limits
namespace category_theory.limits
variable (J : Type v)
/-- A wide pullback shape for any type `J` can be written simply as `option J`. -/
@[derive inhabited]
def wide_pullback_shape := option J
/-- A wide pushout shape for any type `J` can be written simply as `option J`. -/
@[derive inhabited]
def wide_pushout_shape := option J
namespace wide_pullback_shape
variable {J}
/-- The type of arrows for the shape indexing a wide pullback. -/
@[derive decidable_eq]
inductive hom : wide_pullback_shape J → wide_pullback_shape J → Type v
| id : Π X, hom X X
| term : Π (j : J), hom (some j) none
attribute [nolint unused_arguments] hom.decidable_eq
instance struct : category_struct (wide_pullback_shape J) :=
{ hom := hom,
id := λ j, hom.id j,
comp := λ j₁ j₂ j₃ f g,
begin
cases f,
exact g,
cases g,
apply hom.term _
end }
instance hom.inhabited : inhabited (hom none none) := ⟨hom.id (none : wide_pullback_shape J)⟩
local attribute [tidy] tactic.case_bash
instance subsingleton_hom (j j' : wide_pullback_shape J) : subsingleton (j ⟶ j') :=
⟨by tidy⟩
instance category : small_category (wide_pullback_shape J) := thin_category
@[simp] lemma hom_id (X : wide_pullback_shape J) : hom.id X = 𝟙 X := rfl
variables {C : Type u} [category.{v} C]
/--
Construct a functor out of the wide pullback shape given a J-indexed collection of arrows to a
fixed object.
-/
@[simps]
def wide_cospan (B : C) (objs : J → C) (arrows : Π (j : J), objs j ⟶ B) :
wide_pullback_shape J ⥤ C :=
{ obj := λ j, option.cases_on j B objs,
map := λ X Y f,
begin
cases f with _ j,
{ apply (𝟙 _) },
{ exact arrows j }
end,
map_comp' := λ _ _ _ f g,
begin
cases f,
{ simpa },
cases g,
simp
end }
/-- Every diagram is naturally isomorphic (actually, equal) to a `wide_cospan` -/
def diagram_iso_wide_cospan (F : wide_pullback_shape J ⥤ C) :
F ≅ wide_cospan (F.obj none) (λ j, F.obj (some j)) (λ j, F.map (hom.term j)) :=
nat_iso.of_components (λ j, eq_to_iso $ by tidy) $ by tidy
/-- Construct a cone over a wide cospan. -/
@[simps]
def mk_cone {F : wide_pullback_shape J ⥤ C} {X : C}
(f : X ⟶ F.obj none) (π : Π j, X ⟶ F.obj (some j))
(w : ∀ j, π j ≫ F.map (hom.term j) = f) : cone F :=
{ X := X,
π :=
{ app := λ j, match j with
| none := f
| (some j) := π j
end,
naturality' := λ j j' f, by { cases j; cases j'; cases f; unfold_aux; dsimp; simp [w], }, } }
end wide_pullback_shape
namespace wide_pushout_shape
variable {J}
/-- The type of arrows for the shape indexing a wide psuhout. -/
@[derive decidable_eq]
inductive hom : wide_pushout_shape J → wide_pushout_shape J → Type v
| id : Π X, hom X X
| init : Π (j : J), hom none (some j)
attribute [nolint unused_arguments] hom.decidable_eq
instance struct : category_struct (wide_pushout_shape J) :=
{ hom := hom,
id := λ j, hom.id j,
comp := λ j₁ j₂ j₃ f g,
begin
cases f,
exact g,
cases g,
apply hom.init _
end }
instance hom.inhabited : inhabited (hom none none) := ⟨hom.id (none : wide_pushout_shape J)⟩
local attribute [tidy] tactic.case_bash
instance subsingleton_hom (j j' : wide_pushout_shape J) : subsingleton (j ⟶ j') :=
⟨by tidy⟩
instance category : small_category (wide_pushout_shape J) := thin_category
@[simp] lemma hom_id (X : wide_pushout_shape J) : hom.id X = 𝟙 X := rfl
variables {C : Type u} [category.{v} C]
/--
Construct a functor out of the wide pushout shape given a J-indexed collection of arrows from a
fixed object.
-/
@[simps]
def wide_span (B : C) (objs : J → C) (arrows : Π (j : J), B ⟶ objs j) : wide_pushout_shape J ⥤ C :=
{ obj := λ j, option.cases_on j B objs,
map := λ X Y f,
begin
cases f with _ j,
{ apply (𝟙 _) },
{ exact arrows j }
end,
map_comp' := by { rintros (_|_) (_|_) (_|_) (_|_) (_|_); simpa <|> simp } }
/-- Every diagram is naturally isomorphic (actually, equal) to a `wide_span` -/
def diagram_iso_wide_span (F : wide_pushout_shape J ⥤ C) :
F ≅ wide_span (F.obj none) (λ j, F.obj (some j)) (λ j, F.map (hom.init j)) :=
nat_iso.of_components (λ j, eq_to_iso $ by tidy) $ by tidy
/-- Construct a cocone over a wide span. -/
@[simps]
def mk_cocone {F : wide_pushout_shape J ⥤ C} {X : C}
(f : F.obj none ⟶ X) (ι : Π j, F.obj (some j) ⟶ X)
(w : ∀ j, F.map (hom.init j) ≫ ι j = f) : cocone F :=
{ X := X,
ι :=
{ app := λ j, match j with
| none := f
| (some j) := ι j
end,
naturality' := λ j j' f, by { cases j; cases j'; cases f; unfold_aux; dsimp; simp [w], }, } }
end wide_pushout_shape
variables (C : Type u) [category.{v} C]
/-- `has_wide_pullbacks` represents a choice of wide pullback for every collection of morphisms -/
abbreviation has_wide_pullbacks : Prop :=
Π (J : Type v), has_limits_of_shape (wide_pullback_shape J) C
/-- `has_wide_pushouts` represents a choice of wide pushout for every collection of morphisms -/
abbreviation has_wide_pushouts : Prop :=
Π (J : Type v), has_colimits_of_shape (wide_pushout_shape J) C
variables {C J}
/-- `has_wide_pullback B objs arrows` means that `wide_cospan B objs arrows` has a limit. -/
abbreviation has_wide_pullback (B : C) (objs : J → C)
(arrows : Π (j : J), objs j ⟶ B) : Prop :=
has_limit (wide_pullback_shape.wide_cospan B objs arrows)
/-- `has_wide_pushout B objs arrows` means that `wide_span B objs arrows` has a colimit. -/
abbreviation has_wide_pushout (B : C) (objs : J → C)
(arrows : Π (j : J), B ⟶ objs j) : Prop :=
has_colimit (wide_pushout_shape.wide_span B objs arrows)
/-- A choice of wide pullback. -/
noncomputable
abbreviation wide_pullback (B : C) (objs : J → C) (arrows : Π (j : J), objs j ⟶ B)
[has_wide_pullback B objs arrows] : C :=
limit (wide_pullback_shape.wide_cospan B objs arrows)
/-- A choice of wide pushout. -/
noncomputable
abbreviation wide_pushout (B : C) (objs : J → C) (arrows : Π (j : J), B ⟶ objs j)
[has_wide_pushout B objs arrows] : C :=
colimit (wide_pushout_shape.wide_span B objs arrows)
variable (C)
namespace wide_pullback
variables {C} {B : C} {objs : J → C} (arrows : Π (j : J), objs j ⟶ B)
variables [has_wide_pullback B objs arrows]
/-- The `j`-th projection from the pullback. -/
noncomputable
abbreviation π (j : J) : wide_pullback _ _ arrows ⟶ objs j :=
limit.π (wide_pullback_shape.wide_cospan _ _ _) (option.some j)
/-- The unique map to the base from the pullback. -/
noncomputable
abbreviation base : wide_pullback _ _ arrows ⟶ B :=
limit.π (wide_pullback_shape.wide_cospan _ _ _) option.none
@[simp, reassoc]
lemma π_arrow (j : J) : π arrows j ≫ arrows _ = base arrows :=
by apply limit.w (wide_pullback_shape.wide_cospan _ _ _) (wide_pullback_shape.hom.term j)
variables {arrows}
/-- Lift a collection of morphisms to a morphism to the pullback. -/
noncomputable
abbreviation lift {X : C} (f : X ⟶ B) (fs : Π (j : J), X ⟶ objs j)
(w : ∀ j, fs j ≫ arrows j = f) : X ⟶ wide_pullback _ _ arrows :=
limit.lift (wide_pullback_shape.wide_cospan _ _ _)
(wide_pullback_shape.mk_cone f fs $ by exact w)
variables (arrows)
variables {X : C} (f : X ⟶ B) (fs : Π (j : J), X ⟶ objs j)
(w : ∀ j, fs j ≫ arrows j = f)
@[simp, reassoc]
lemma lift_π (j : J) : lift f fs w ≫ π arrows j = fs _ :=
by { simp, refl }
@[simp, reassoc]
lemma lift_base : lift f fs w ≫ base arrows = f :=
by { simp, refl }
lemma eq_lift_of_comp_eq (g : X ⟶ wide_pullback _ _ arrows) :
(∀ j : J, g ≫ π arrows j = fs j) → g ≫ base arrows = f → g = lift f fs w :=
begin
intros h1 h2,
apply (limit.is_limit (wide_pullback_shape.wide_cospan B objs arrows)).uniq
(wide_pullback_shape.mk_cone f fs $ by exact w),
rintro (_|_),
{ apply h2 },
{ apply h1 }
end
lemma hom_eq_lift (g : X ⟶ wide_pullback _ _ arrows) :
g = lift (g ≫ base arrows) (λ j, g ≫ π arrows j) (by tidy) :=
begin
apply eq_lift_of_comp_eq,
tidy,
end
@[ext]
lemma hom_ext (g1 g2 : X ⟶ wide_pullback _ _ arrows) :
(∀ j : J, g1 ≫ π arrows j = g2 ≫ π arrows j) →
g1 ≫ base arrows = g2 ≫ base arrows → g1 = g2 :=
begin
intros h1 h2,
apply limit.hom_ext,
rintros (_|_),
{ apply h2 },
{ apply h1 },
end
end wide_pullback
namespace wide_pushout
variables {C} {B : C} {objs : J → C} (arrows : Π (j : J), B ⟶ objs j)
variables [has_wide_pushout B objs arrows]
/-- The `j`-th inclusion to the pushout. -/
noncomputable
abbreviation ι (j : J) : objs j ⟶ wide_pushout _ _ arrows :=
colimit.ι (wide_pushout_shape.wide_span _ _ _) (option.some j)
/-- The unique map from the head to the pushout. -/
noncomputable
abbreviation head : B ⟶ wide_pushout B objs arrows :=
colimit.ι (wide_pushout_shape.wide_span _ _ _) option.none
@[simp, reassoc]
lemma arrow_ι (j : J) : arrows j ≫ ι arrows j = head arrows :=
by apply colimit.w (wide_pushout_shape.wide_span _ _ _) (wide_pushout_shape.hom.init j)
variables {arrows}
/-- Descend a collection of morphisms to a morphism from the pushout. -/
noncomputable
abbreviation desc {X : C} (f : B ⟶ X) (fs : Π (j : J), objs j ⟶ X)
(w : ∀ j, arrows j ≫ fs j = f) : wide_pushout _ _ arrows ⟶ X :=
colimit.desc (wide_pushout_shape.wide_span B objs arrows)
(wide_pushout_shape.mk_cocone f fs $ by exact w)
variables (arrows)
variables {X : C} (f : B ⟶ X) (fs : Π (j : J), objs j ⟶ X)
(w : ∀ j, arrows j ≫ fs j = f)
@[simp, reassoc]
lemma ι_desc (j : J) : ι arrows j ≫ desc f fs w = fs _ :=
by { simp, refl }
@[simp, reassoc]
lemma head_desc : head arrows ≫ desc f fs w = f :=
by { simp, refl }
lemma eq_desc_of_comp_eq (g : wide_pushout _ _ arrows ⟶ X) :
(∀ j : J, ι arrows j ≫ g = fs j) → head arrows ≫ g = f → g = desc f fs w :=
begin
intros h1 h2,
apply (colimit.is_colimit (wide_pushout_shape.wide_span B objs arrows)).uniq
(wide_pushout_shape.mk_cocone f fs $ by exact w),
rintro (_|_),
{ apply h2 },
{ apply h1 }
end
lemma hom_eq_desc (g : wide_pushout _ _ arrows ⟶ X) :
g = desc (head arrows ≫ g) (λ j, ι arrows j ≫ g) (λ j, by { rw ← category.assoc, simp }) :=
begin
apply eq_desc_of_comp_eq,
tidy,
end
@[ext]
lemma hom_ext (g1 g2 : wide_pushout _ _ arrows ⟶ X) :
(∀ j : J, ι arrows j ≫ g1 = ι arrows j ≫ g2) →
head arrows ≫ g1 = head arrows ≫ g2 → g1 = g2 :=
begin
intros h1 h2,
apply colimit.hom_ext,
rintros (_|_),
{ apply h2 },
{ apply h1 },
end
end wide_pushout
end category_theory.limits
|
3f85ea8bd95e6f66993b651f045f61186d8e0da2 | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /stage0/src/Lean/Compiler/LCNF/Simp/FunDeclInfo.lean | b5285f938f8b82bc370bab5dcec03f4afee91930 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 4,274 | lean | /-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.LCNF.Simp.Basic
namespace Lean.Compiler.LCNF
namespace Simp
/--
Local function usage information used to decide whether it should be inlined or not.
The information is an approximation, but it is on the "safe" side. That is, if we tagged
a function with `.once`, then it is applied only once. A local function may be marked as
`.many`, but after simplifications the number of applications may reduce to 1. This is not
a big problem in practice because we run the simplifier multiple times, and this information
is recomputed from scratch at the beginning of each simplification step.
-/
inductive FunDeclInfo where
/--
Local function is applied once, and must be inlined.
-/
| once
/--
Local function is applied many times or occur as an argument of another function,
and will only be inlined if it is small.
-/
| many
/--
Function must be inlined.
-/
| mustInline
deriving Repr, Inhabited
/--
Local function declaration statistics.
-/
structure FunDeclInfoMap where
/--
Mapping from local function name to inlining information.
-/
map : HashMap FVarId FunDeclInfo := {}
deriving Inhabited
def FunDeclInfoMap.format (s : FunDeclInfoMap) : CompilerM Format := do
let mut result := Format.nil
for (fvarId, info) in s.map.toList do
let binderName ← getBinderName fvarId
result := result ++ "\n" ++ f!"{binderName} ↦ {repr info}"
return result
/--
Add new occurrence for the local function with binder name `key`.
-/
def FunDeclInfoMap.add (s : FunDeclInfoMap) (fvarId : FVarId) : FunDeclInfoMap :=
match s with
| { map } =>
match map.find? fvarId with
| some .once => { map := map.insert fvarId .many }
| none => { map := map.insert fvarId .once }
| _ => { map }
/--
Add new occurrence for the local function occurring as an argument for another function.
-/
def FunDeclInfoMap.addHo (s : FunDeclInfoMap) (fvarId : FVarId) : FunDeclInfoMap :=
match s with
| { map } =>
match map.find? fvarId with
| some .once | none => { map := map.insert fvarId .many }
| _ => { map }
/--
Add new occurrence for the local function with binder name `key`.
-/
def FunDeclInfoMap.addMustInline (s : FunDeclInfoMap) (fvarId : FVarId) : FunDeclInfoMap :=
match s with
| { map } => { map := map.insert fvarId .mustInline }
def FunDeclInfoMap.restore (s : FunDeclInfoMap) (fvarId : FVarId) (saved? : Option FunDeclInfo) : FunDeclInfoMap :=
match s, saved? with
| { map }, none => { map := map.erase fvarId }
| { map }, some saved => { map := map.insert fvarId saved }
/--
Traverse `code` and update function occurrence map.
This map is used to decide whether we inline local functions or not.
If `mustInline := true`, then all local function declarations occurring in
`code` are tagged as `.mustInline`.
Recall that we use `.mustInline` for local function declarations occurring in type class instances.
-/
partial def FunDeclInfoMap.update (s : FunDeclInfoMap) (code : Code) (mustInline := false) : CompilerM FunDeclInfoMap := do
let (_, s) ← go code |>.run s
return s
where
addArgOcc (e : Expr) : StateRefT FunDeclInfoMap CompilerM Unit := do
let some funDecl ← findFunDecl? e | return ()
modify fun s => s.addHo funDecl.fvarId
addOccs (e : Expr) : StateRefT FunDeclInfoMap CompilerM Unit := do
match e with
| .app f a => addArgOcc a; addOccs f
| .fvar _ =>
let some funDecl ← findFunDecl? e | return ()
modify fun s => s.add funDecl.fvarId
| _ => return ()
go (code : Code) : StateRefT FunDeclInfoMap CompilerM Unit := do
match code with
| .let decl k =>
addOccs decl.value
go k
| .fun decl k =>
if mustInline then
modify fun s => s.addMustInline decl.fvarId
go decl.value; go k
| .jp decl k => go decl.value; go k
| .cases c => c.alts.forM fun alt => go alt.getCode
| .jmp fvarId args =>
let funDecl ← getFunDecl fvarId
modify fun s => s.add funDecl.fvarId
args.forM addArgOcc
| .return .. | .unreach .. => return ()
end Simp
end Lean.Compiler.LCNF
|
aa40f4b6ddd96ca70fe1a65865eaf759bb13c5b9 | 41ebf3cb010344adfa84907b3304db00e02db0a6 | /uexp/src/uexp/rules/removeSemiJoinRight.lean | 787293a993ef97c9422a413b218b66928768b9a5 | [
"BSD-2-Clause"
] | permissive | ReinierKoops/Cosette | e061b2ba58b26f4eddf4cd052dcf7abd16dfe8fb | eb8dadd06ee05fe7b6b99de431dd7c4faef5cb29 | refs/heads/master | 1,686,483,953,198 | 1,624,293,498,000 | 1,624,293,498,000 | 378,997,885 | 0 | 0 | BSD-2-Clause | 1,624,293,485,000 | 1,624,293,484,000 | null | UTF-8 | Lean | false | false | 1,496 | lean | import ..sql
import ..tactics
import ..u_semiring
import ..extra_constants
import ..meta.ucongr
import ..meta.TDP
set_option profiler true
open Expr
open Proj
open Pred
open SQL
open tree
notation `int` := datatypes.int
theorem rule:
forall ( Γ scm_dept scm_emp: Schema) (rel_dept: relation scm_dept) (rel_emp: relation scm_emp) (dept_deptno : Column int scm_dept) (dept_name : Column int scm_dept) (emp_empno : Column int scm_emp) (emp_ename : Column int scm_emp) (emp_job : Column int scm_emp) (emp_mgr : Column int scm_emp) (emp_hiredate : Column int scm_emp) (emp_comm : Column int scm_emp) (emp_sal : Column int scm_emp) (emp_deptno : Column int scm_emp) (emp_slacker : Column int scm_emp),
denoteSQL ((SELECT1 (right⋅left⋅emp_ename) FROM1 (product (table rel_emp) (product (table rel_dept) (table rel_emp))) WHERE (and (equal (uvariable (right⋅left⋅emp_deptno)) (uvariable (right⋅right⋅left⋅dept_deptno))) (equal (uvariable (right⋅right⋅left⋅dept_deptno)) (uvariable (right⋅right⋅right⋅emp_deptno))))) :SQL Γ _)
=
denoteSQL ((SELECT1 (right⋅left⋅emp_ename) FROM1 (product (table rel_emp) (product (table rel_dept) (table rel_emp))) WHERE (and (equal (uvariable (right⋅left⋅emp_deptno)) (uvariable (right⋅right⋅left⋅dept_deptno))) (equal (uvariable (right⋅right⋅left⋅dept_deptno)) (uvariable (right⋅right⋅right⋅emp_deptno))))) :SQL Γ _) :=
begin
intros,
unfold_all_denotations,
funext,
try {simp},
try {TDP' ucongr},
end |
2492318677830189476991d11e56ac5283e23979 | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/function.hlean | b478fa9911276559f3ef91db5a5b74c34ea241f8 | [
"Apache-2.0"
] | permissive | fpvandoorn/lean2 | 5a430a153b570bf70dc8526d06f18fc000a60ad9 | 0889cf65b7b3cebfb8831b8731d89c2453dd1e9f | refs/heads/master | 1,592,036,508,364 | 1,545,093,958,000 | 1,545,093,958,000 | 75,436,854 | 0 | 0 | null | 1,480,718,780,000 | 1,480,718,780,000 | null | UTF-8 | Lean | false | false | 16,549 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Ported from Coq HoTT
Theorems about embeddings and surjections
-/
import hit.trunc types.equiv cubical.square types.nat
open equiv sigma sigma.ops eq trunc is_trunc pi is_equiv fiber prod pointed nat
variables {A B C : Type} (f f' : A → B) {b : B}
/- the image of a map is the (-1)-truncated fiber -/
definition image' [constructor] (f : A → B) (b : B) : Type := ∥ fiber f b ∥
definition is_prop_image' [instance] (f : A → B) (b : B) : is_prop (image' f b) := !is_trunc_trunc
definition image [constructor] (f : A → B) (b : B) : Prop := Prop.mk (image' f b) _
definition total_image {A B : Type} (f : A → B) : Type := sigma (image f)
/- properties of functions -/
definition is_embedding [class] (f : A → B) := Π(a a' : A), is_equiv (ap f : a = a' → f a = f a')
definition is_surjective [class] (f : A → B) := Π(b : B), image f b
definition is_split_surjective [class] (f : A → B) := Π(b : B), fiber f b
structure is_retraction [class] (f : A → B) :=
(sect : B → A)
(right_inverse : Π(b : B), f (sect b) = b)
structure is_section [class] (f : A → B) :=
(retr : B → A)
(left_inverse : Π(a : A), retr (f a) = a)
definition is_weakly_constant [class] (f : A → B) := Π(a a' : A), f a = f a'
structure is_constant [class] (f : A → B) :=
(pt : B)
(eq : Π(a : A), f a = pt)
definition merely_constant {A B : Type} (f : A → B) : Type :=
Σb, Πa, merely (f a = b)
structure is_conditionally_constant [class] (f : A → B) :=
(g : ∥A∥ → B)
(eq : Π(a : A), f a = g (tr a))
section image
protected definition image.mk [constructor] {f : A → B} {b : B} (a : A) (p : f a = b)
: image f b :=
tr (fiber.mk a p)
protected definition image.rec [unfold 8] [recursor 8] {f : A → B} {b : B} {P : image' f b → Type}
[H : Πv, is_prop (P v)] (H : Π(a : A) (p : f a = b), P (image.mk a p)) (v : image' f b) : P v :=
begin unfold [image'] at *, induction v with v, induction v with a p, exact H a p end
definition image.elim {A B : Type} {f : A → B} {C : Type} [is_prop C] {b : B}
(H : image f b) (H' : ∀ (a : A), f a = b → C) : C :=
begin
refine (trunc.elim _ H),
intro H'', cases H'' with a Ha, exact H' a Ha
end
definition image.equiv_exists {A B : Type} {f : A → B} {b : B} : image f b ≃ ∃ a, f a = b :=
trunc_equiv_trunc _ (fiber.sigma_char _ _)
definition image_pathover {f : A → B} {x y : B} (p : x = y) (u : image f x) (v : image f y) :
u =[p] v :=
!is_prop.elimo
definition total_image.rec [unfold 7]
{A B : Type} {f : A → B} {C : total_image f → Type} [H : Πx, is_prop (C x)]
(g : Πa, C ⟨f a, image.mk a idp⟩)
(x : total_image f) : C x :=
begin
induction x with b v,
refine @image.rec _ _ _ _ _ (λv, H ⟨b, v⟩) _ v,
intro a p,
induction p, exact g a
end
/- total_image.elim_set is in hit.prop_trunc to avoid dependency cycle -/
end image
namespace function
abbreviation sect [unfold 4] := @is_retraction.sect
abbreviation right_inverse [unfold 4] := @is_retraction.right_inverse
abbreviation retr [unfold 4] := @is_section.retr
abbreviation left_inverse [unfold 4] := @is_section.left_inverse
definition is_equiv_ap_of_embedding [instance] [H : is_embedding f] (a a' : A)
: is_equiv (ap f : a = a' → f a = f a') :=
H a a'
definition ap_inv_idp {a : A} {H : is_equiv (ap f : a = a → f a = f a)}
: (ap f)⁻¹ᶠ idp = idp :> a = a :=
!left_inv
variable {f}
definition is_injective_of_is_embedding [reducible] [H : is_embedding f] {a a' : A}
: f a = f a' → a = a' :=
(ap f)⁻¹
definition is_embedding_of_is_injective [HA : is_set A] [HB : is_set B]
(H : Π(a a' : A), f a = f a' → a = a') : is_embedding f :=
begin
intro a a',
fapply adjointify,
{exact (H a a')},
{intro p, apply is_set.elim},
{intro p, apply is_set.elim}
end
variable (f)
definition is_prop_is_embedding [instance] : is_prop (is_embedding f) :=
by unfold is_embedding; exact _
definition is_embedding_equiv_is_injective [HA : is_set A] [HB : is_set B]
: is_embedding f ≃ (Π(a a' : A), f a = f a' → a = a') :=
begin
fapply equiv.MK,
{ apply @is_injective_of_is_embedding},
{ apply is_embedding_of_is_injective},
{ intro H, apply is_prop.elim},
{ intro H, apply is_prop.elim, }
end
definition is_prop_fiber_of_is_embedding [H : is_embedding f] (b : B) :
is_prop (fiber f b) :=
begin
apply is_prop.mk, intro v w,
induction v with a p, induction w with a' q, induction q,
fapply fiber_eq,
{ esimp, apply is_injective_of_is_embedding p},
{ esimp [is_injective_of_is_embedding], symmetry, apply right_inv}
end
definition is_prop_fun_of_is_embedding [H : is_embedding f] : is_trunc_fun -1 f :=
is_prop_fiber_of_is_embedding f
definition is_embedding_of_is_prop_fun [constructor] [H : is_trunc_fun -1 f] : is_embedding f :=
begin
intro a a', fapply adjointify,
{ intro p, exact ap point (@is_prop.elim (fiber f (f a')) _ (fiber.mk a p) (fiber.mk a' idp))},
{ intro p, rewrite [-ap_compose], esimp, apply ap_con_eq (@point_eq _ _ f (f a'))},
{ intro p, induction p, apply ap (ap point), apply is_prop_elim_self}
end
variable {f}
definition is_surjective_rec_on {P : Type} (H : is_surjective f) (b : B) [Pt : is_prop P]
(IH : fiber f b → P) : P :=
trunc.rec_on (H b) IH
variable (f)
definition is_surjective_of_is_split_surjective [instance] [H : is_split_surjective f]
: is_surjective f :=
λb, tr (H b)
definition is_prop_is_surjective [instance] : is_prop (is_surjective f) :=
begin unfold is_surjective, exact _ end
definition is_surjective_cancel_right {A B C : Type} (g : B → C) (f : A → B)
[H : is_surjective (g ∘ f)] : is_surjective g :=
begin
intro c,
induction H c with a p,
exact tr (fiber.mk (f a) p)
end
definition is_contr_of_is_surjective (f : A → B) (H : is_surjective f) (HA : is_contr A)
(HB : is_set B) : is_contr B :=
is_contr.mk (f !center) begin intro b, induction H b, exact ap f !is_prop.elim ⬝ p end
definition is_surjective_of_is_contr [constructor] (f : A → B) (a : A) (H : is_contr B) :
is_surjective f :=
λb, image.mk a !eq_of_is_contr
definition is_weakly_constant_ap [instance] [H : is_weakly_constant f] (a a' : A) :
is_weakly_constant (ap f : a = a' → f a = f a') :=
take p q : a = a',
have Π{b c : A} {r : b = c}, (H a b)⁻¹ ⬝ H a c = ap f r, from
(λb c r, eq.rec_on r !con.left_inv),
this⁻¹ ⬝ this
definition is_constant_ap [unfold 4] [instance] [H : is_constant f] (a a' : A)
: is_constant (ap f : a = a' → f a = f a') :=
begin
induction H with b q,
fapply is_constant.mk,
{ exact q a ⬝ (q a')⁻¹},
{ intro p, induction p, exact !con.right_inv⁻¹}
end
definition is_contr_is_retraction [instance] [H : is_equiv f] : is_contr (is_retraction f) :=
begin
have H2 : (Σ(g : B → A), Πb, f (g b) = b) ≃ is_retraction f,
begin
fapply equiv.MK,
{intro x, induction x with g p, constructor, exact p},
{intro h, induction h, apply sigma.mk, assumption},
{intro h, induction h, reflexivity},
{intro x, induction x, reflexivity},
end,
apply is_trunc_equiv_closed, exact H2,
apply is_equiv.is_contr_right_inverse
end
definition is_contr_is_section [instance] [H : is_equiv f] : is_contr (is_section f) :=
begin
have H2 : (Σ(g : B → A), Πa, g (f a) = a) ≃ is_section f,
begin
fapply equiv.MK,
{intro x, induction x with g p, constructor, exact p},
{intro h, induction h, apply sigma.mk, assumption},
{intro h, induction h, reflexivity},
{intro x, induction x, reflexivity},
end,
apply is_trunc_equiv_closed, exact H2,
fapply is_trunc_equiv_closed,
{apply sigma_equiv_sigma_right, intro g, apply eq_equiv_homotopy},
fapply is_trunc_equiv_closed,
{apply fiber.sigma_char},
fapply is_contr_fiber_of_is_equiv,
exact to_is_equiv (arrow_equiv_arrow_left_rev A (equiv.mk f H)),
end
definition is_embedding_of_is_equiv [instance] [H : is_equiv f] : is_embedding f :=
λa a', _
definition is_equiv_of_is_surjective_of_is_embedding
[H : is_embedding f] [H' : is_surjective f] : is_equiv f :=
@is_equiv_of_is_contr_fun _ _ _
(λb, is_surjective_rec_on H' b
(λa, is_contr.mk a
(λa',
fiber_eq ((ap f)⁻¹ ((point_eq a) ⬝ (point_eq a')⁻¹))
(by rewrite (right_inv (ap f)); rewrite inv_con_cancel_right))))
definition is_split_surjective_of_is_retraction [H : is_retraction f] : is_split_surjective f :=
λb, fiber.mk (sect f b) (right_inverse f b)
definition is_constant_compose_point [constructor] [instance] (b : B)
: is_constant (f ∘ point : fiber f b → B) :=
is_constant.mk b (λv, by induction v with a p;exact p)
definition is_embedding_of_is_prop_fiber [H : Π(b : B), is_prop (fiber f b)] : is_embedding f :=
is_embedding_of_is_prop_fun _
definition is_retraction_of_is_equiv [instance] [H : is_equiv f] : is_retraction f :=
is_retraction.mk f⁻¹ (right_inv f)
definition is_section_of_is_equiv [instance] [H : is_equiv f] : is_section f :=
is_section.mk f⁻¹ (left_inv f)
definition is_equiv_of_is_section_of_is_retraction [H1 : is_retraction f] [H2 : is_section f]
: is_equiv f :=
let g := sect f in let h := retr f in
adjointify f
g
(right_inverse f)
(λa, calc
g (f a) = h (f (g (f a))) : left_inverse
... = h (f a) : right_inverse f
... = a : left_inverse)
section
local attribute is_equiv_of_is_section_of_is_retraction [instance] [priority 10000]
local attribute trunctype.struct [instance] [priority 1] -- remove after #842 is closed
variable (f)
definition is_prop_is_retraction_prod_is_section : is_prop (is_retraction f × is_section f) :=
begin
apply is_prop_of_imp_is_contr, intro H, induction H with H1 H2,
exact _,
end
end
definition is_retraction_trunc_functor [instance] (r : A → B) [H : is_retraction r]
(n : trunc_index) : is_retraction (trunc_functor n r) :=
is_retraction.mk
(trunc_functor n (sect r))
(λb,
((trunc_functor_compose n (sect r) r) b)⁻¹
⬝ trunc_homotopy n (right_inverse r) b
⬝ trunc_functor_id n B b)
-- Lemma 3.11.7
definition is_contr_retract (r : A → B) [H : is_retraction r] : is_contr A → is_contr B :=
begin
intro CA,
apply is_contr.mk (r (center A)),
intro b,
exact ap r (center_eq (is_retraction.sect r b)) ⬝ (is_retraction.right_inverse r b)
end
local attribute is_prop_is_retraction_prod_is_section [instance]
definition is_retraction_prod_is_section_equiv_is_equiv [constructor]
: (is_retraction f × is_section f) ≃ is_equiv f :=
begin
apply equiv_of_is_prop,
intro H, induction H, apply is_equiv_of_is_section_of_is_retraction,
intro H, split, repeat exact _
end
definition is_retraction_equiv_is_split_surjective :
is_retraction f ≃ is_split_surjective f :=
begin
fapply equiv.MK,
{ intro H, induction H with g p, intro b, constructor, exact p b},
{ intro H, constructor, intro b, exact point_eq (H b)},
{ intro H, esimp, apply eq_of_homotopy, intro b, esimp, induction H b, reflexivity},
{ intro H, induction H with g p, reflexivity},
end
definition is_embedding_compose (g : B → C) (f : A → B)
(H₁ : is_embedding g) (H₂ : is_embedding f) : is_embedding (g ∘ f) :=
begin
intros, apply is_equiv.homotopy_closed (ap g ∘ ap f),
{ symmetry, exact ap_compose g f },
{ exact is_equiv_compose _ _ _ _ }
end
definition is_surjective_compose (g : B → C) (f : A → B)
(H₁ : is_surjective g) (H₂ : is_surjective f) : is_surjective (g ∘ f) :=
begin
intro c, induction H₁ c with b p, induction H₂ b with a q,
exact image.mk a (ap g q ⬝ p)
end
definition is_split_surjective_compose (g : B → C) (f : A → B)
(H₁ : is_split_surjective g) (H₂ : is_split_surjective f) : is_split_surjective (g ∘ f) :=
begin
intro c, induction H₁ c with b p, induction H₂ b with a q,
exact fiber.mk a (ap g q ⬝ p)
end
definition is_injective_compose (g : B → C) (f : A → B)
(H₁ : Π⦃b b'⦄, g b = g b' → b = b') (H₂ : Π⦃a a'⦄, f a = f a' → a = a')
⦃a a' : A⦄ (p : g (f a) = g (f a')) : a = a' :=
H₂ (H₁ p)
definition is_embedding_pr1 [instance] [constructor] {A : Type} (B : A → Type) [H : Π a, is_prop (B a)]
: is_embedding (@pr1 A B) :=
λv v', to_is_equiv (sigma_eq_equiv v v' ⬝e sigma_equiv_of_is_contr_right _ _)
variables {f f'}
definition is_embedding_homotopy_closed (p : f ~ f') (H : is_embedding f) : is_embedding f' :=
begin
intro a a', fapply is_equiv_of_equiv_of_homotopy,
exact equiv.mk (ap f) _ ⬝e equiv_eq_closed_left _ (p a) ⬝e equiv_eq_closed_right _ (p a'),
intro q, esimp, exact (eq_bot_of_square (transpose (natural_square p q)))⁻¹
end
definition is_embedding_homotopy_closed_rev (p : f' ~ f) (H : is_embedding f) : is_embedding f' :=
is_embedding_homotopy_closed p⁻¹ʰᵗʸ H
definition is_surjective_homotopy_closed (p : f ~ f') (H : is_surjective f) : is_surjective f' :=
begin
intro b, induction H b with a q,
exact image.mk a ((p a)⁻¹ ⬝ q)
end
definition is_surjective_homotopy_closed_rev (p : f' ~ f) (H : is_surjective f) :
is_surjective f' :=
is_surjective_homotopy_closed p⁻¹ʰᵗʸ H
definition is_surjective_factor {g : B → C} (f : A → B) (h : A → C) (H : g ∘ f ~ h) :
is_surjective h → is_surjective g :=
begin
induction H using homotopy.rec_on_idp,
intro S,
intro c,
note p := S c,
induction p,
apply tr,
fapply fiber.mk,
exact f a,
exact p
end
definition is_equiv_ap1_gen_of_is_embedding {A B : Type} (f : A → B) [is_embedding f]
{a a' : A} {b b' : B} (q : f a = b) (q' : f a' = b') : is_equiv (ap1_gen f q q') :=
begin
induction q, induction q',
exact is_equiv.homotopy_closed _ (ap1_gen_idp_left f)⁻¹ʰᵗʸ _,
end
definition is_equiv_ap1_of_is_embedding {A B : Type*} (f : A →* B) [is_embedding f] :
is_equiv (Ω→ f) :=
is_equiv_ap1_gen_of_is_embedding f (respect_pt f) (respect_pt f)
definition loop_pequiv_loop_of_is_embedding [constructor] {A B : Type*} (f : A →* B)
[is_embedding f] : Ω A ≃* Ω B :=
pequiv_of_pmap (Ω→ f) (is_equiv_ap1_of_is_embedding f)
definition loopn_pequiv_loopn_of_is_embedding [constructor] (n : ℕ) [H : is_succ n]
{A B : Type*} (f : A →* B) [is_embedding f] : Ω[n] A ≃* Ω[n] B :=
begin
induction H with n,
exact !loopn_succ_in ⬝e*
loopn_pequiv_loopn n (loop_pequiv_loop_of_is_embedding f) ⬝e*
!loopn_succ_in⁻¹ᵉ*
end
definition is_contr_of_is_embedding (f : A → B) (H : is_embedding f) (HB : is_prop B)
(a₀ : A) : is_contr A :=
is_contr.mk a₀ (λa, is_injective_of_is_embedding (is_prop.elim (f a₀) (f a)))
definition is_embedding_of_square {A B C D : Type} {f : A → B} {g : C → D} (h : A ≃ C)
(k : B ≃ D) (s : k ∘ f ~ g ∘ h) (Hf : is_embedding f) : is_embedding g :=
begin
apply is_embedding_homotopy_closed, exact inv_homotopy_of_homotopy_pre _ _ _ s,
apply is_embedding_compose, apply is_embedding_compose,
apply is_embedding_of_is_equiv, exact Hf, apply is_embedding_of_is_equiv
end
definition is_embedding_of_square_rev {A B C D : Type} {f : A → B} {g : C → D} (h : A ≃ C)
(k : B ≃ D) (s : k ∘ f ~ g ∘ h) (Hg : is_embedding g) : is_embedding f :=
is_embedding_of_square h⁻¹ᵉ k⁻¹ᵉ s⁻¹ʰᵗʸᵛ Hg
definition is_embedding_factor [is_set A] [is_set B] (g : B → C) (h : A → C) (H : g ∘ f ~ h) :
is_embedding h → is_embedding f :=
begin
induction H using homotopy.rec_on_idp,
intro E,
fapply is_embedding_of_is_injective,
intro x y p,
fapply @is_injective_of_is_embedding _ _ _ E _ _ (ap g p)
end
/-
The definitions
is_surjective_of_is_equiv
is_equiv_equiv_is_embedding_times_is_surjective
are in types.trunc
See types.arrow_2 for retractions
-/
end function
|
e1b77c3c877117f66c57297734aa8de1585b6e20 | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/algebra/linear_recurrence.lean | b9aa2cc52b980ec1f88acfa390dd14d7f47b54f8 | [
"Apache-2.0"
] | permissive | hamdysalah1/mathlib | b915f86b2503feeae268de369f1b16932321f097 | 95454452f6b3569bf967d35aab8d852b1ddf8017 | refs/heads/master | 1,677,154,116,545 | 1,611,797,994,000 | 1,611,797,994,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,816 | lean | /-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import data.polynomial.ring_division
import linear_algebra.dimension
import algebra.polynomial.big_operators
/-!
# Linear recurrence
Informally, a "linear recurrence" is an assertion of the form
`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,
where `u` is a sequence, `d` is the *order* of the recurrence and the `a i`
are its *coefficients*.
In this file, we define the structure `linear_recurrence` so that
`linear_recurrence.mk d a` represents the above relation, and we call
a sequence `u` which verifies it a *solution* of the linear recurrence.
We prove a few basic lemmas about this concept, such as :
* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`
is a field)
* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`
between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two
solutions are equal if and only if their first `d` terms are equals.
* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,
which we call the *characteristic polynomial* of the recurrence
Of course, although we can inductively generate solutions (cf `mk_sol`), the
interesting part would be to determinate closed-forms for the solutions.
This is currently *not implemented*, as we are waiting for definition and
properties of eigenvalues and eigenvectors.
-/
noncomputable theory
open finset
open_locale big_operators
/-- A "linear recurrence relation" over a commutative semiring is given by its
order `n` and `n` coefficients. -/
structure linear_recurrence (α : Type*) [comm_semiring α] := (order : ℕ) (coeffs : fin order → α)
instance (α : Type*) [comm_semiring α] : inhabited (linear_recurrence α) :=
⟨⟨0, default _⟩⟩
namespace linear_recurrence
section comm_semiring
variables {α : Type*} [comm_semiring α] (E : linear_recurrence α)
/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have
`u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/
def is_solution (u : ℕ → α) :=
∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)
/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.
We will prove this is the only such solution. -/
def mk_sol (init : fin E.order → α) : ℕ → α
| n := if h : n < E.order then init ⟨n, h⟩ else
∑ k : fin E.order, have n - E.order + k < n, by have := k.is_lt; omega,
E.coeffs k * mk_sol (n - E.order + k)
/-- `E.mk_sol` indeed gives solutions to `E`. -/
lemma is_sol_mk_sol (init : fin E.order → α) : E.is_solution (E.mk_sol init) :=
λ n, by rw mk_sol; simp
/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/
lemma mk_sol_eq_init (init : fin E.order → α) : ∀ n : fin E.order, E.mk_sol init n = init n :=
λ n, by { rw mk_sol, simp only [n.is_lt, dif_pos, fin.mk_coe] }
/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,
then `∀ n, u n = E.mk_sol init n`. -/
lemma eq_mk_of_is_sol_of_eq_init {u : ℕ → α} {init : fin E.order → α}
(h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) :
∀ n, u n = E.mk_sol init n
| n := if h' : n < E.order
then by rw mk_sol; simp only [h', dif_pos]; exact_mod_cast heq ⟨n, h'⟩
else begin
rw [mk_sol, ← nat.sub_add_cancel (le_of_not_lt h'), h (n-E.order)],
simp [h'],
congr' with k,
exact have wf : n - E.order + k < n, by have := k.is_lt; omega,
by rw eq_mk_of_is_sol_of_eq_init
end
/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,
then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution
of `E` whose first `E.order` values are given by `init`. -/
lemma eq_mk_of_is_sol_of_eq_init' {u : ℕ → α} {init : fin E.order → α}
(h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) : u = E.mk_sol init :=
funext (E.eq_mk_of_is_sol_of_eq_init h heq)
/-- The space of solutions of `E`, as a `submodule` over `α` of the semimodule `ℕ → α`. -/
def sol_space : submodule α (ℕ → α) :=
{ carrier := {u | E.is_solution u},
zero_mem' := λ n, by simp,
add_mem' := λ u v hu hv n, by simp [mul_add, sum_add_distrib, hu n, hv n],
smul_mem' := λ a u hu n, by simp [hu n, mul_sum]; congr'; ext; ac_refl }
/-- Defining property of the solution space : `u` is a solution
iff it belongs to the solution space. -/
lemma is_sol_iff_mem_sol_space (u : ℕ → α) : E.is_solution u ↔ u ∈ E.sol_space :=
iff.rfl
/-- The function that maps a solution `u` of `E` to its first
`E.order` terms as a `linear_equiv`. -/
def to_init :
E.sol_space ≃ₗ[α] (fin E.order → α) :=
{ to_fun := λ u x, (u : ℕ → α) x,
map_add' := λ u v, by { ext, simp },
map_smul' := λ a u, by { ext, simp },
inv_fun := λ u, ⟨E.mk_sol u, E.is_sol_mk_sol u⟩,
left_inv := λ u, by ext n; symmetry; apply E.eq_mk_of_is_sol_of_eq_init u.2; intros k; refl,
right_inv := λ u, function.funext_iff.mpr (λ n, E.mk_sol_eq_init u n) }
/-- Two solutions are equal iff they are equal on `range E.order`. -/
lemma sol_eq_of_eq_init (u v : ℕ → α) (hu : E.is_solution u) (hv : E.is_solution v) :
u = v ↔ set.eq_on u v ↑(range E.order) :=
begin
refine iff.intro (λ h x hx, h ▸ rfl) _,
intro h,
set u' : ↥(E.sol_space) := ⟨u, hu⟩,
set v' : ↥(E.sol_space) := ⟨v, hv⟩,
change u'.val = v'.val,
suffices h' : u' = v', from h' ▸ rfl,
rw [← E.to_init.to_equiv.apply_eq_iff_eq, linear_equiv.coe_to_equiv],
ext x,
exact_mod_cast h (mem_range.mpr x.2)
end
/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,
where `n := E.order`. This operation is quite useful for determining closed-form
solutions of `E`. -/
/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,
where `n := E.order`. -/
def tuple_succ : (fin E.order → α) →ₗ[α] (fin E.order → α) :=
{ to_fun := λ X i, if h : (i : ℕ) + 1 < E.order then X ⟨i+1, h⟩ else (∑ i, E.coeffs i * X i),
map_add' := λ x y,
begin
ext i,
split_ifs ; simp [h, mul_add, sum_add_distrib],
end,
map_smul' := λ x y,
begin
ext i,
split_ifs ; simp [h, mul_sum],
exact sum_congr rfl (λ x _, by ac_refl),
end }
end comm_semiring
section field
variables {α : Type*} [field α] (E : linear_recurrence α)
/-- The dimension of `E.sol_space` is `E.order`. -/
lemma sol_space_dim : vector_space.dim α E.sol_space = E.order :=
@dim_fin_fun α _ E.order ▸ E.to_init.dim_eq
end field
section comm_ring
variables {α : Type*} [comm_ring α] (E : linear_recurrence α)
/-- The characteristic polynomial of `E` is
`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/
def char_poly : polynomial α :=
polynomial.monomial E.order 1 - (∑ i : fin E.order, polynomial.monomial i (E.coeffs i))
/-- The geometric sequence `q^n` is a solution of `E` iff
`q` is a root of `E`'s characteristic polynomial. -/
lemma geom_sol_iff_root_char_poly (q : α) : E.is_solution (λ n, q^n) ↔ E.char_poly.is_root q :=
begin
rw [char_poly, polynomial.is_root.def, polynomial.eval],
simp only [polynomial.eval₂_finset_sum, one_mul,
ring_hom.id_apply, polynomial.eval₂_monomial, polynomial.eval₂_sub],
split,
{ intro h,
simpa [sub_eq_zero_iff_eq] using h 0 },
{ intros h n,
simp only [pow_add, sub_eq_zero_iff_eq.mp h, mul_sum],
exact sum_congr rfl (λ _ _, by ring) }
end
end comm_ring
end linear_recurrence
|
725f80388ea22e791e77a83cdf68292571eb39df | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/268c.lean | 86db884ae5f355271e591e369765919f8e732e5a | [
"Apache-2.0"
] | permissive | leanprover-community/lean | 12b87f69d92e614daea8bcc9d4de9a9ace089d0e | cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0 | refs/heads/master | 1,687,508,156,644 | 1,684,951,104,000 | 1,684,951,104,000 | 169,960,991 | 457 | 107 | Apache-2.0 | 1,686,744,372,000 | 1,549,790,268,000 | C++ | UTF-8 | Lean | false | false | 230 | lean | def nat.case {α} (a b : α) (n : ℕ) : α := nat.cases_on n a (λ _, b)
variables (a b c : ℕ)
#check nat.case a b c -- a.case b c : ℕ
set_option pp.generalized_field_notation false
#check a.case b c -- nat.case b c a : ℕ
|
2e8658a3b7d0ae5138193e2393990d2afefb65b0 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/linear_algebra/unitary_group.lean | 65229d3aae0155a1b9930e893af3f86632055b61 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 6,390 | lean | /-
Copyright (c) 2021 Shing Tak Lam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
-/
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.matrix.to_lin
import data.complex.basic
/-!
# The Unitary Group
This file defines elements of the unitary group `unitary_group n α`, where `α` is a `star_ring`.
This consists of all `n` by `n` matrices with entries in `α` such that the star-transpose is its
inverse. In addition, we define the group structure on `unitary_group n α`, and the embedding into
the general linear group `general_linear_group α (n → α)`.
We also define the orthogonal group `orthogonal_group n β`, where `β` is a `comm_ring`.
## Main Definitions
* `matrix.unitary_group` is the type of matrices where the star-transpose is the inverse
* `matrix.unitary_group.group` is the group structure (under multiplication)
* `matrix.unitary_group.embedding_GL` is the embedding `unitary_group n α → GLₙ(α)`
* `matrix.orthogonal_group` is the type of matrices where the transpose is the inverse
## References
* https://en.wikipedia.org/wiki/Unitary_group
## Tags
matrix group, group, unitary group, orthogonal group
-/
universes u v
section
variables (M : Type v) [monoid M] [star_monoid M]
/--
In a `star_monoid M`, `unitary_submonoid M` is the submonoid consisting of all the elements of
`M` such that `star A * A = 1`.
-/
def unitary_submonoid : submonoid M :=
{ carrier := {A | star A * A = 1},
one_mem' := by simp,
mul_mem' := λ A B (hA : star A * A = 1) (hB : star B * B = 1), show star (A * B) * (A * B) = 1,
by rwa [star_mul, ←mul_assoc, mul_assoc _ _ A, hA, mul_one] }
end
namespace matrix
open linear_map
open_locale matrix
section
variables (n : Type u) [decidable_eq n] [fintype n]
variables (α : Type v) [comm_ring α] [star_ring α]
/--
`unitary_group n` is the group of `n` by `n` matrices where the star-transpose is the inverse.
-/
@[derive monoid]
def unitary_group : Type* := unitary_submonoid (matrix n n α)
end
variables {n : Type u} [decidable_eq n] [fintype n]
variables {α : Type v} [comm_ring α] [star_ring α]
namespace unitary_submonoid
lemma star_mem {A : matrix n n α} (h : A ∈ unitary_submonoid (matrix n n α)) :
star A ∈ unitary_submonoid (matrix n n α) :=
matrix.nonsing_inv_left_right _ _ $ (star_star A).symm ▸ h
@[simp]
lemma star_mem_iff {A : matrix n n α} :
star A ∈ unitary_submonoid (matrix n n α) ↔ A ∈ unitary_submonoid (matrix n n α) :=
⟨λ ha, star_star A ▸ star_mem ha, star_mem⟩
end unitary_submonoid
namespace unitary_group
instance coe_matrix : has_coe (unitary_group n α) (matrix n n α) := ⟨subtype.val⟩
instance coe_fun : has_coe_to_fun (unitary_group n α) :=
{ F := λ _, n → n → α,
coe := λ A, A.val }
/--
`to_lin' A` is matrix multiplication of vectors by `A`, as a linear map.
After the group structure on `unitary_group n` is defined,
we show in `to_linear_equiv` that this gives a linear equivalence.
-/
def to_lin' (A : unitary_group n α) := matrix.to_lin' A
lemma ext_iff (A B : unitary_group n α) : A = B ↔ ∀ i j, A i j = B i j :=
subtype.ext_iff_val.trans ⟨(λ h i j, congr_fun (congr_fun h i) j), matrix.ext⟩
@[ext] lemma ext (A B : unitary_group n α) : (∀ i j, A i j = B i j) → A = B :=
(unitary_group.ext_iff A B).mpr
instance : has_inv (unitary_group n α) :=
⟨λ A, ⟨star A.1, unitary_submonoid.star_mem_iff.mpr A.2⟩⟩
instance : star_monoid (unitary_group n α) :=
{ star := λ A, ⟨star A.1, unitary_submonoid.star_mem A.2⟩,
star_involutive := λ A, subtype.ext $ star_star A.1,
star_mul := λ A B, subtype.ext $ star_mul A.1 B.1 }
@[simp]
lemma star_mul_self (A : unitary_group n α) : star A ⬝ A = 1 := A.2
instance : inhabited (unitary_group n α) := ⟨1⟩
section coe_lemmas
variables (A B : unitary_group n α)
@[simp] lemma inv_val : ↑(A⁻¹) = (star A : matrix n n α) := rfl
@[simp] lemma inv_apply : ⇑(A⁻¹) = (star A : matrix n n α) := rfl
@[simp] lemma mul_val : ↑(A * B) = A ⬝ B := rfl
@[simp] lemma mul_apply : ⇑(A * B) = (A ⬝ B) := rfl
@[simp] lemma one_val : ↑(1 : unitary_group n α) = (1 : matrix n n α) := rfl
@[simp] lemma one_apply : ⇑(1 : unitary_group n α) = (1 : matrix n n α) := rfl
@[simp] lemma to_lin'_mul :
to_lin' (A * B) = (to_lin' A).comp (to_lin' B) :=
matrix.to_lin'_mul A B
@[simp] lemma to_lin'_one :
to_lin' (1 : unitary_group n α) = linear_map.id :=
matrix.to_lin'_one
end coe_lemmas
instance : group (unitary_group n α) :=
{ mul_left_inv := λ A, subtype.eq A.2,
..unitary_group.has_inv,
..unitary_group.monoid n α }
/-- `to_linear_equiv A` is matrix multiplication of vectors by `A`, as a linear equivalence. -/
def to_linear_equiv (A : unitary_group n α) : (n → α) ≃ₗ[α] (n → α) :=
{ inv_fun := A⁻¹.to_lin',
left_inv := λ x, calc
A⁻¹.to_lin'.comp A.to_lin' x
= (A⁻¹ * A).to_lin' x : by rw [←to_lin'_mul]
... = x : by rw [mul_left_inv, to_lin'_one, id_apply],
right_inv := λ x, calc
A.to_lin'.comp A⁻¹.to_lin' x
= (A * A⁻¹).to_lin' x : by rw [←to_lin'_mul]
... = x : by rw [mul_right_inv, to_lin'_one, id_apply],
..matrix.to_lin' A }
/-- `to_GL` is the map from the unitary group to the general linear group -/
def to_GL (A : unitary_group n α) : general_linear_group α (n → α) :=
general_linear_group.of_linear_equiv (to_linear_equiv A)
lemma coe_to_GL (A : unitary_group n α) :
↑(to_GL A) = A.to_lin' :=
rfl
@[simp]
lemma to_GL_one : to_GL (1 : unitary_group n α) = 1 :=
by { ext1 v i, rw [coe_to_GL, to_lin'_one], refl }
@[simp]
lemma to_GL_mul (A B : unitary_group n α) :
to_GL (A * B) = to_GL A * to_GL B :=
by { ext1 v i, rw [coe_to_GL, to_lin'_mul], refl }
/-- `unitary_group.embedding_GL` is the embedding from `unitary_group n α`
to `general_linear_group n α`. -/
def embedding_GL : unitary_group n α →* general_linear_group α (n → α) :=
⟨λ A, to_GL A, by simp, by simp⟩
end unitary_group
section orthogonal_group
variables (β : Type v) [comm_ring β]
local attribute [instance] star_ring_of_comm
/--
`orthogonal_group n` is the group of `n` by `n` matrices where the transpose is the inverse.
-/
abbreviation orthogonal_group := unitary_group n β
end orthogonal_group
end matrix
|
cd36eab4a3eae7da8881c738a31b69eb8e033905 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/algebra/ring/basic.lean | dd4bd806efa634dd1a0fda004b977364fd662f63 | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 35,780 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland
-/
import algebra.divisibility
import data.set.basic
/-!
# Properties and homomorphisms of semirings and rings
This file proves simple properties of semirings, rings and domains and their unit groups. It also
defines bundled homomorphisms of semirings and rings. As with monoid and groups, we use the same
structure `ring_hom a β`, a.k.a. `α →+* β`, for both homomorphism types.
The unbundled homomorphisms are defined in `deprecated/ring`. They are deprecated and the plan is to
slowly remove them from mathlib.
## Main definitions
ring_hom, nonzero, domain, integral_domain
## Notations
→+* for bundled ring homs (also use for semiring homs)
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `semiring_hom` -- the idea is that `ring_hom` is used.
The constructor for a `ring_hom` between semirings needs a proof of `map_zero`, `map_one` and
`map_add` as well as `map_mul`; a separate constructor `ring_hom.mk'` will construct ring homs
between rings from monoid homs given only a proof that addition is preserved.
Throughout the section on `ring_hom` implicit `{}` brackets are often used instead
of type class `[]` brackets. This is done when the instances can be inferred because they are
implicit arguments to the type `ring_hom`. When they can be inferred from the type it is faster
to use this method than to use type class inference.
## Tags
`ring_hom`, `semiring_hom`, `semiring`, `comm_semiring`, `ring`, `comm_ring`, `domain`,
`integral_domain`, `nonzero`, `units`
-/
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {R : Type x}
set_option old_structure_cmd true
open function
/-!
### `distrib` class
-/
/-- A typeclass stating that multiplication is left and right distributive
over addition. -/
@[protect_proj, ancestor has_mul has_add]
class distrib (R : Type*) extends has_mul R, has_add R :=
(left_distrib : ∀ a b c : R, a * (b + c) = (a * b) + (a * c))
(right_distrib : ∀ a b c : R, (a + b) * c = (a * c) + (b * c))
lemma left_distrib [distrib R] (a b c : R) : a * (b + c) = a * b + a * c :=
distrib.left_distrib a b c
alias left_distrib ← mul_add
lemma right_distrib [distrib R] (a b c : R) : (a + b) * c = a * c + b * c :=
distrib.right_distrib a b c
alias right_distrib ← add_mul
/-- Pullback a `distrib` instance along an injective function. -/
protected def function.injective.distrib {S} [has_mul R] [has_add R] [distrib S]
(f : R → S) (hf : injective f) (add : ∀ x y, f (x + y) = f x + f y)
(mul : ∀ x y, f (x * y) = f x * f y) :
distrib R :=
{ mul := (*),
add := (+),
left_distrib := λ x y z, hf $ by simp only [*, left_distrib],
right_distrib := λ x y z, hf $ by simp only [*, right_distrib] }
/-- Pushforward a `distrib` instance along a surjective function. -/
protected def function.surjective.distrib {S} [distrib R] [has_add S] [has_mul S]
(f : R → S) (hf : surjective f) (add : ∀ x y, f (x + y) = f x + f y)
(mul : ∀ x y, f (x * y) = f x * f y) :
distrib S :=
{ mul := (*),
add := (+),
left_distrib := hf.forall₃.2 $ λ x y z, by simp only [← add, ← mul, left_distrib],
right_distrib := hf.forall₃.2 $ λ x y z, by simp only [← add, ← mul, right_distrib] }
/-!
### Semirings
-/
@[protect_proj, ancestor add_comm_monoid monoid_with_zero distrib]
class semiring (α : Type u) extends add_comm_monoid α, monoid_with_zero α, distrib α
section semiring
variables [semiring α]
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.injective.semiring [has_zero β] [has_one β] [has_add β] [has_mul β]
(f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
semiring β :=
{ .. hf.monoid_with_zero f zero one mul, .. hf.add_comm_monoid f zero add,
.. hf.distrib f add mul }
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.surjective.semiring [has_zero β] [has_one β] [has_add β] [has_mul β]
(f : α → β) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
semiring β :=
{ .. hf.monoid_with_zero f zero one mul, .. hf.add_comm_monoid f zero add,
.. hf.distrib f add mul }
lemma one_add_one_eq_two : 1 + 1 = (2 : α) :=
by unfold bit0
theorem two_mul (n : α) : 2 * n = n + n :=
eq.trans (right_distrib 1 1 n) (by simp)
lemma distrib_three_right (a b c d : α) : (a + b + c) * d = a * d + b * d + c * d :=
by simp [right_distrib]
theorem mul_two (n : α) : n * 2 = n + n :=
(left_distrib n 1 1).trans (by simp)
theorem bit0_eq_two_mul (n : α) : bit0 n = 2 * n :=
(two_mul _).symm
@[to_additive] lemma mul_ite {α} [has_mul α] (P : Prop) [decidable P] (a b c : α) :
a * (if P then b else c) = if P then a * b else a * c :=
by split_ifs; refl
@[to_additive] lemma ite_mul {α} [has_mul α] (P : Prop) [decidable P] (a b c : α) :
(if P then a else b) * c = if P then a * c else b * c :=
by split_ifs; refl
-- We make `mul_ite` and `ite_mul` simp lemmas,
-- but not `add_ite` or `ite_add`.
-- The problem we're trying to avoid is dealing with
-- summations of the form `∑ x in s, (f x + ite P 1 0)`,
-- in which `add_ite` followed by `sum_ite` would needlessly slice up
-- the `f x` terms according to whether `P` holds at `x`.
-- There doesn't appear to be a corresponding difficulty so far with
-- `mul_ite` and `ite_mul`.
attribute [simp] mul_ite ite_mul
@[simp] lemma mul_boole {α} [semiring α] (P : Prop) [decidable P] (a : α) :
a * (if P then 1 else 0) = if P then a else 0 :=
by simp
@[simp] lemma boole_mul {α} [semiring α] (P : Prop) [decidable P] (a : α) :
(if P then 1 else 0) * a = if P then a else 0 :=
by simp
lemma ite_mul_zero_left {α : Type*} [mul_zero_class α] (P : Prop) [decidable P] (a b : α) :
ite P (a * b) 0 = ite P a 0 * b :=
by { by_cases h : P; simp [h], }
lemma ite_mul_zero_right {α : Type*} [mul_zero_class α] (P : Prop) [decidable P] (a b : α) :
ite P (a * b) 0 = a * ite P b 0 :=
by { by_cases h : P; simp [h], }
end semiring
namespace add_monoid_hom
/-- Left multiplication by an element of a (semi)ring is an `add_monoid_hom` -/
def mul_left {R : Type*} [semiring R] (r : R) : R →+ R :=
{ to_fun := (*) r,
map_zero' := mul_zero r,
map_add' := mul_add r }
@[simp] lemma coe_mul_left {R : Type*} [semiring R] (r : R) : ⇑(mul_left r) = (*) r := rfl
/-- Right multiplication by an element of a (semi)ring is an `add_monoid_hom` -/
def mul_right {R : Type*} [semiring R] (r : R) : R →+ R :=
{ to_fun := λ a, a * r,
map_zero' := zero_mul r,
map_add' := λ _ _, add_mul _ _ r }
@[simp] lemma mul_right_apply {R : Type*} [semiring R] (a r : R) :
(mul_right r : R → R) a = a * r := rfl
end add_monoid_hom
/-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too. -/
structure ring_hom (α : Type*) (β : Type*) [semiring α] [semiring β]
extends monoid_hom α β, add_monoid_hom α β
infixr ` →+* `:25 := ring_hom
instance {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} : has_coe_to_fun (α →+* β) :=
⟨_, ring_hom.to_fun⟩
instance {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} : has_coe (α →+* β) (α →* β) :=
⟨ring_hom.to_monoid_hom⟩
instance {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} : has_coe (α →+* β) (α →+ β) :=
⟨ring_hom.to_add_monoid_hom⟩
@[simp, norm_cast]
lemma coe_monoid_hom {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} (f : α →+* β) :
⇑(f : α →* β) = f := rfl
@[simp, norm_cast]
lemma coe_add_monoid_hom {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} (f : α →+* β) :
⇑(f : α →+ β) = f := rfl
namespace ring_hom
variables [rα : semiring α] [rβ : semiring β]
section
include rα rβ
@[simp]
lemma to_fun_eq_coe (f : α →+* β) : f.to_fun = f := rfl
@[simp] lemma coe_mk (f : α → β) (h₁ h₂ h₃ h₄) : ⇑(⟨f, h₁, h₂, h₃, h₄⟩ : α →+* β) = f := rfl
variables (f : α →+* β) {x y : α} {rα rβ}
theorem congr_fun {f g : α →+* β} (h : f = g) (x : α) : f x = g x :=
congr_arg (λ h : α →+* β, h x) h
theorem congr_arg (f : α →+* β) {x y : α} (h : x = y) : f x = f y :=
congr_arg (λ x : α, f x) h
theorem coe_inj ⦃f g : α →+* β⦄ (h : (f : α → β) = g) : f = g :=
by cases f; cases g; cases h; refl
@[ext] theorem ext ⦃f g : α →+* β⦄ (h : ∀ x, f x = g x) : f = g :=
coe_inj (funext h)
theorem ext_iff {f g : α →+* β} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, λ h, ext h⟩
theorem coe_add_monoid_hom_injective : function.injective (coe : (α →+* β) → (α →+ β)) :=
λ f g h, ext (λ x, add_monoid_hom.congr_fun h x)
theorem coe_monoid_hom_injective : function.injective (coe : (α →+* β) → (α →* β)) :=
λ f g h, ext (λ x, monoid_hom.congr_fun h x)
/-- Ring homomorphisms map zero to zero. -/
@[simp] lemma map_zero (f : α →+* β) : f 0 = 0 := f.map_zero'
/-- Ring homomorphisms map one to one. -/
@[simp] lemma map_one (f : α →+* β) : f 1 = 1 := f.map_one'
/-- Ring homomorphisms preserve addition. -/
@[simp] lemma map_add (f : α →+* β) (a b : α) : f (a + b) = f a + f b := f.map_add' a b
/-- Ring homomorphisms preserve multiplication. -/
@[simp] lemma map_mul (f : α →+* β) (a b : α) : f (a * b) = f a * f b := f.map_mul' a b
/-- Ring homomorphisms preserve `bit0`. -/
@[simp] lemma map_bit0 (f : α →+* β) (a : α) : f (bit0 a) = bit0 (f a) := map_add _ _ _
/-- Ring homomorphisms preserve `bit1`. -/
@[simp] lemma map_bit1 (f : α →+* β) (a : α) : f (bit1 a) = bit1 (f a) :=
by simp [bit1]
/-- `f : R →+* S` has a trivial codomain iff `f 1 = 0`. -/
lemma codomain_trivial_iff_map_one_eq_zero : (0 : β) = 1 ↔ f 1 = 0 :=
by rw [map_one, eq_comm]
/-- `f : R →+* S` has a trivial codomain iff it has a trivial range. -/
lemma codomain_trivial_iff_range_trivial : (0 : β) = 1 ↔ (∀ x, f x = 0) :=
f.codomain_trivial_iff_map_one_eq_zero.trans
⟨λ h x, by rw [←mul_one x, map_mul, h, mul_zero], λ h, h 1⟩
/-- `f : R →+* S` has a trivial codomain iff its range is `{0}`. -/
lemma codomain_trivial_iff_range_eq_singleton_zero : (0 : β) = 1 ↔ set.range f = {0} :=
f.codomain_trivial_iff_range_trivial.trans
⟨ λ h, set.ext (λ y, ⟨λ ⟨x, hx⟩, by simp [←hx, h x], λ hy, ⟨0, by simpa using hy.symm⟩⟩),
λ h x, set.mem_singleton_iff.mp (h ▸ set.mem_range_self x)⟩
/-- `f : R →+* S` doesn't map `1` to `0` if `S` is nontrivial -/
lemma map_one_ne_zero [nontrivial β] : f 1 ≠ 0 :=
mt f.codomain_trivial_iff_map_one_eq_zero.mpr zero_ne_one
/-- If there is a homomorphism `f : R →+* S` and `S` is nontrivial, then `R` is nontrivial. -/
lemma domain_nontrivial [nontrivial β] : nontrivial α :=
⟨⟨1, 0, mt (λ h, show f 1 = 0, by rw [h, map_zero]) f.map_one_ne_zero⟩⟩
lemma is_unit_map (f : α →+* β) {a : α} (h : is_unit a) : is_unit (f a) :=
h.map (f.to_monoid_hom)
end
/-- The identity ring homomorphism from a semiring to itself. -/
def id (α : Type*) [semiring α] : α →+* α :=
by refine {to_fun := id, ..}; intros; refl
include rα
@[simp] lemma id_apply (x : α) : ring_hom.id α x = x := rfl
variable {rγ : semiring γ}
include rβ rγ
/-- Composition of ring homomorphisms is a ring homomorphism. -/
def comp (hnp : β →+* γ) (hmn : α →+* β) : α →+* γ :=
{ to_fun := hnp ∘ hmn,
map_zero' := by simp,
map_one' := by simp,
map_add' := λ x y, by simp,
map_mul' := λ x y, by simp}
/-- Composition of semiring homomorphisms is associative. -/
lemma comp_assoc {δ} {rδ: semiring δ} (f : α →+* β) (g : β →+* γ) (h : γ →+* δ) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[simp] lemma coe_comp (hnp : β →+* γ) (hmn : α →+* β) : (hnp.comp hmn : α → γ) = hnp ∘ hmn := rfl
lemma comp_apply (hnp : β →+* γ) (hmn : α →+* β) (x : α) : (hnp.comp hmn : α → γ) x =
(hnp (hmn x)) := rfl
omit rγ
@[simp] lemma comp_id (f : α →+* β) : f.comp (id α) = f := ext $ λ x, rfl
@[simp] lemma id_comp (f : α →+* β) : (id β).comp f = f := ext $ λ x, rfl
omit rβ
instance : monoid (α →+* α) :=
{ one := id α,
mul := comp,
mul_one := comp_id,
one_mul := id_comp,
mul_assoc := λ f g h, comp_assoc _ _ _ }
lemma one_def : (1 : α →+* α) = id α := rfl
@[simp] lemma coe_one : ⇑(1 : α →+* α) = _root_.id := rfl
lemma mul_def (f g : α →+* α) : f * g = f.comp g := rfl
@[simp] lemma coe_mul (f g : α →+* α) : ⇑(f * g) = f ∘ g := rfl
include rβ rγ
lemma cancel_right {g₁ g₂ : β →+* γ} {f : α →+* β} (hf : surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, ring_hom.ext $ (forall_iff_forall_surj hf).1 (ext_iff.1 h), λ h, h ▸ rfl⟩
lemma cancel_left {g : β →+* γ} {f₁ f₂ : α →+* β} (hg : injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, ring_hom.ext $ λ x, hg $ by rw [← comp_apply, h, comp_apply], λ h, h ▸ rfl⟩
omit rα rβ rγ
end ring_hom
@[protect_proj, ancestor semiring comm_monoid]
class comm_semiring (α : Type u) extends semiring α, comm_monoid α
@[priority 100] -- see Note [lower instance priority]
instance comm_semiring.to_comm_monoid_with_zero [comm_semiring α] : comm_monoid_with_zero α :=
{ .. comm_semiring.to_comm_monoid α, .. comm_semiring.to_semiring α }
section comm_semiring
variables [comm_semiring α] [comm_semiring β] {a b c : α}
@[priority 100] -- see Note [lower instance priority]
instance comm_semiring.comm_monoid_with_zero : comm_monoid_with_zero α :=
{ .. (‹_› : comm_semiring α) }
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.injective.comm_semiring [has_zero γ] [has_one γ] [has_add γ] [has_mul γ]
(f : γ → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
comm_semiring γ :=
{ .. hf.semiring f zero one add mul, .. hf.comm_semigroup f mul }
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.surjective.comm_semiring [has_zero γ] [has_one γ] [has_add γ] [has_mul γ]
(f : α → γ) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
comm_semiring γ :=
{ .. hf.semiring f zero one add mul, .. hf.comm_semigroup f mul }
lemma add_mul_self_eq (a b : α) : (a + b) * (a + b) = a*a + 2*a*b + b*b :=
calc (a + b)*(a + b) = a*a + (1+1)*a*b + b*b : by simp [add_mul, mul_add, mul_comm, add_assoc]
... = a*a + 2*a*b + b*b : by rw one_add_one_eq_two
theorem dvd_add (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b + c :=
dvd.elim h₁ (λ d hd, dvd.elim h₂ (λ e he, dvd.intro (d + e) (by simp [left_distrib, hd, he])))
@[simp] theorem two_dvd_bit0 : 2 ∣ bit0 a := ⟨a, bit0_eq_two_mul _⟩
lemma ring_hom.map_dvd (f : α →+* β) {a b : α} : a ∣ b → f a ∣ f b :=
λ ⟨z, hz⟩, ⟨f z, by rw [hz, f.map_mul]⟩
end comm_semiring
/-!
### Rings
-/
@[protect_proj, ancestor add_comm_group monoid distrib]
class ring (α : Type u) extends add_comm_group α, monoid α, distrib α
section ring
variables [ring α] {a b c d e : α}
/- The instance from `ring` to `semiring` happens often in linear algebra, for which all the basic
definitions are given in terms of semirings, but many applications use rings or fields. We increase
a little bit its priority above 100 to try it quickly, but remaining below the default 1000 so that
more specific instances are tried first. -/
@[priority 200]
instance ring.to_semiring : semiring α :=
{ zero_mul := λ a, add_left_cancel $ show 0 * a + 0 * a = 0 * a + 0,
by rw [← add_mul, zero_add, add_zero],
mul_zero := λ a, add_left_cancel $ show a * 0 + a * 0 = a * 0 + 0,
by rw [← mul_add, add_zero, add_zero],
..‹ring α› }
/-- Pullback a `ring` instance along an injective function. -/
protected def function.injective.ring [has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β]
(f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) :
ring β :=
{ .. hf.add_comm_group f zero add neg, .. hf.monoid f one mul, .. hf.distrib f add mul }
/-- Pullback a `ring` instance along an injective function. -/
protected def function.surjective.ring [has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β]
(f : α → β) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) :
ring β :=
{ .. hf.add_comm_group f zero add neg, .. hf.monoid f one mul, .. hf.distrib f add mul }
lemma neg_mul_eq_neg_mul (a b : α) : -(a * b) = -a * b :=
neg_eq_of_add_eq_zero
begin rw [← right_distrib, add_right_neg, zero_mul] end
lemma neg_mul_eq_mul_neg (a b : α) : -(a * b) = a * -b :=
neg_eq_of_add_eq_zero
begin rw [← left_distrib, add_right_neg, mul_zero] end
@[simp] lemma neg_mul_eq_neg_mul_symm (a b : α) : - a * b = - (a * b) :=
eq.symm (neg_mul_eq_neg_mul a b)
@[simp] lemma mul_neg_eq_neg_mul_symm (a b : α) : a * - b = - (a * b) :=
eq.symm (neg_mul_eq_mul_neg a b)
lemma neg_mul_neg (a b : α) : -a * -b = a * b :=
by simp
lemma neg_mul_comm (a b : α) : -a * b = a * -b :=
by simp
theorem neg_eq_neg_one_mul (a : α) : -a = -1 * a :=
by simp
lemma mul_sub_left_distrib (a b c : α) : a * (b - c) = a * b - a * c :=
calc
a * (b - c) = a * b + a * -c : left_distrib a b (-c)
... = a * b - a * c : by simp [sub_eq_add_neg]
alias mul_sub_left_distrib ← mul_sub
lemma mul_sub_right_distrib (a b c : α) : (a - b) * c = a * c - b * c :=
calc
(a - b) * c = a * c + -b * c : right_distrib a (-b) c
... = a * c - b * c : by simp [sub_eq_add_neg]
alias mul_sub_right_distrib ← sub_mul
/-- An element of a ring multiplied by the additive inverse of one is the element's additive
inverse. -/
lemma mul_neg_one (a : α) : a * -1 = -a := by simp
/-- The additive inverse of one multiplied by an element of a ring is the element's additive
inverse. -/
lemma neg_one_mul (a : α) : -1 * a = -a := by simp
/-- An iff statement following from right distributivity in rings and the definition
of subtraction. -/
theorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d ↔ (a - b) * e + c = d :=
calc
a * e + c = b * e + d ↔ a * e + c = d + b * e : by simp [add_comm]
... ↔ a * e + c - b * e = d : iff.intro (λ h, begin rw h, simp end) (λ h,
begin rw ← h, simp end)
... ↔ (a - b) * e + c = d : begin simp [sub_mul, sub_add_eq_add_sub] end
/-- A simplification of one side of an equation exploiting right distributivity in rings
and the definition of subtraction. -/
theorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d → (a - b) * e + c = d :=
assume h,
calc
(a - b) * e + c = (a * e + c) - b * e : begin simp [sub_mul, sub_add_eq_add_sub] end
... = d : begin rw h, simp [@add_sub_cancel α] end
end ring
namespace units
variables [ring α] {a b : α}
/-- Each element of the group of units of a ring has an additive inverse. -/
instance : has_neg (units α) := ⟨λu, ⟨-↑u, -↑u⁻¹, by simp, by simp⟩ ⟩
/-- Representing an element of a ring's unit group as an element of the ring commutes with
mapping this element to its additive inverse. -/
@[simp, norm_cast] protected theorem coe_neg (u : units α) : (↑-u : α) = -u := rfl
@[simp, norm_cast] protected theorem coe_neg_one : ((-1 : units α) : α) = -1 := rfl
/-- Mapping an element of a ring's unit group to its inverse commutes with mapping this element
to its additive inverse. -/
@[simp] protected theorem neg_inv (u : units α) : (-u)⁻¹ = -u⁻¹ := rfl
/-- An element of a ring's unit group equals the additive inverse of its additive inverse. -/
@[simp] protected theorem neg_neg (u : units α) : - -u = u :=
units.ext $ neg_neg _
/-- Multiplication of elements of a ring's unit group commutes with mapping the first
argument to its additive inverse. -/
@[simp] protected theorem neg_mul (u₁ u₂ : units α) : -u₁ * u₂ = -(u₁ * u₂) :=
units.ext $ neg_mul_eq_neg_mul_symm _ _
/-- Multiplication of elements of a ring's unit group commutes with mapping the second argument
to its additive inverse. -/
@[simp] protected theorem mul_neg (u₁ u₂ : units α) : u₁ * -u₂ = -(u₁ * u₂) :=
units.ext $ (neg_mul_eq_mul_neg _ _).symm
/-- Multiplication of the additive inverses of two elements of a ring's unit group equals
multiplication of the two original elements. -/
@[simp] protected theorem neg_mul_neg (u₁ u₂ : units α) : -u₁ * -u₂ = u₁ * u₂ := by simp
/-- The additive inverse of an element of a ring's unit group equals the additive inverse of
one times the original element. -/
protected theorem neg_eq_neg_one_mul (u : units α) : -u = -1 * u := by simp
end units
namespace ring_hom
/-- Ring homomorphisms preserve additive inverse. -/
@[simp] theorem map_neg {α β} [ring α] [ring β] (f : α →+* β) (x : α) : f (-x) = -(f x) :=
(f : α →+ β).map_neg x
/-- Ring homomorphisms preserve subtraction. -/
@[simp] theorem map_sub {α β} [ring α] [ring β] (f : α →+* β) (x y : α) :
f (x - y) = (f x) - (f y) := (f : α →+ β).map_sub x y
/-- A ring homomorphism is injective iff its kernel is trivial. -/
theorem injective_iff {α β} [ring α] [semiring β] (f : α →+* β) :
function.injective f ↔ (∀ a, f a = 0 → a = 0) :=
(f : α →+ β).injective_iff
/-- Makes a ring homomorphism from a monoid homomorphism of rings which preserves addition. -/
def mk' {γ} [semiring α] [ring γ] (f : α →* γ) (map_add : ∀ a b : α, f (a + b) = f a + f b) :
α →+* γ :=
{ to_fun := f,
.. add_monoid_hom.mk' f map_add, .. f }
end ring_hom
@[protect_proj, ancestor ring comm_semigroup]
class comm_ring (α : Type u) extends ring α, comm_semigroup α
@[priority 100] -- see Note [lower instance priority]
instance comm_ring.to_comm_semiring [s : comm_ring α] : comm_semiring α :=
{ mul_zero := mul_zero, zero_mul := zero_mul, ..s }
section comm_ring
variables [comm_ring α] {a b c : α}
/-- Pullback a `ring` instance along an injective function. -/
protected def function.injective.comm_ring [has_zero β] [has_one β] [has_add β] [has_mul β]
[has_neg β] (f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) :
comm_ring β :=
{ .. hf.ring f zero one add mul neg, .. hf.comm_semigroup f mul }
/-- Pullback a `ring` instance along an injective function. -/
protected def function.surjective.comm_ring [has_zero β] [has_one β] [has_add β] [has_mul β]
[has_neg β] (f : α → β) (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) :
comm_ring β :=
{ .. hf.ring f zero one add mul neg, .. hf.comm_semigroup f mul }
local attribute [simp] add_assoc add_comm add_left_comm mul_comm
theorem dvd_neg_of_dvd (h : a ∣ b) : (a ∣ -b) :=
dvd.elim h
(assume c, assume : b = a * c,
dvd.intro (-c) (by simp [this]))
theorem dvd_of_dvd_neg (h : a ∣ -b) : (a ∣ b) :=
let t := dvd_neg_of_dvd h in by rwa neg_neg at t
theorem dvd_neg_iff_dvd (a b : α) : (a ∣ -b) ↔ (a ∣ b) :=
⟨dvd_of_dvd_neg, dvd_neg_of_dvd⟩
theorem neg_dvd_of_dvd (h : a ∣ b) : -a ∣ b :=
dvd.elim h
(assume c, assume : b = a * c,
dvd.intro (-c) (by simp [this]))
theorem dvd_of_neg_dvd (h : -a ∣ b) : a ∣ b :=
let t := neg_dvd_of_dvd h in by rwa neg_neg at t
theorem neg_dvd_iff_dvd (a b : α) : (-a ∣ b) ↔ (a ∣ b) :=
⟨dvd_of_neg_dvd, neg_dvd_of_dvd⟩
theorem dvd_sub (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b - c :=
dvd_add h₁ (dvd_neg_of_dvd h₂)
theorem dvd_add_iff_left (h : a ∣ c) : a ∣ b ↔ a ∣ b + c :=
⟨λh₂, dvd_add h₂ h, λH, by have t := dvd_sub H h; rwa add_sub_cancel at t⟩
theorem dvd_add_iff_right (h : a ∣ b) : a ∣ c ↔ a ∣ b + c :=
by rw add_comm; exact dvd_add_iff_left h
theorem two_dvd_bit1 : 2 ∣ bit1 a ↔ (2 : α) ∣ 1 := (dvd_add_iff_right (@two_dvd_bit0 _ _ a)).symm
/-- Representation of a difference of two squares in a commutative ring as a product. -/
theorem mul_self_sub_mul_self (a b : α) : a * a - b * b = (a + b) * (a - b) :=
by rw [add_mul, mul_sub, mul_sub, mul_comm a b, sub_add_sub_cancel]
lemma mul_self_sub_one (a : α) : a * a - 1 = (a + 1) * (a - 1) :=
by rw [← mul_self_sub_mul_self, mul_one]
/-- An element a of a commutative ring divides the additive inverse of an element b iff a
divides b. -/
@[simp] lemma dvd_neg (a b : α) : (a ∣ -b) ↔ (a ∣ b) :=
⟨dvd_of_dvd_neg, dvd_neg_of_dvd⟩
/-- The additive inverse of an element a of a commutative ring divides another element b iff a
divides b. -/
@[simp] lemma neg_dvd (a b : α) : (-a ∣ b) ↔ (a ∣ b) :=
⟨dvd_of_neg_dvd, neg_dvd_of_dvd⟩
/-- If an element a divides another element c in a commutative ring, a divides the sum of another
element b with c iff a divides b. -/
theorem dvd_add_left (h : a ∣ c) : a ∣ b + c ↔ a ∣ b :=
(dvd_add_iff_left h).symm
/-- If an element a divides another element b in a commutative ring, a divides the sum of b and
another element c iff a divides c. -/
theorem dvd_add_right (h : a ∣ b) : a ∣ b + c ↔ a ∣ c :=
(dvd_add_iff_right h).symm
/-- An element a divides the sum a + b if and only if a divides b.-/
@[simp] lemma dvd_add_self_left {a b : α} : a ∣ a + b ↔ a ∣ b :=
dvd_add_right (dvd_refl a)
/-- An element a divides the sum b + a if and only if a divides b.-/
@[simp] lemma dvd_add_self_right {a b : α} : a ∣ b + a ↔ a ∣ b :=
dvd_add_left (dvd_refl a)
/-- Vieta's formula for a quadratic equation, relating the coefficients of the polynomial with
its roots. This particular version states that if we have a root `x` of a monic quadratic
polynomial, then there is another root `y` such that `x + y` is negative the `a_1` coefficient
and `x * y` is the `a_0` coefficient. -/
lemma Vieta_formula_quadratic {b c x : α} (h : x * x - b * x + c = 0) :
∃ y : α, y * y - b * y + c = 0 ∧ x + y = b ∧ x * y = c :=
begin
have : c = -(x * x - b * x) := (neg_eq_of_add_eq_zero h).symm,
have : c = x * (b - x), by subst this; simp [mul_sub, mul_comm],
refine ⟨b - x, _, by simp, by rw this⟩,
rw [this, sub_add, ← sub_mul, sub_self]
end
lemma dvd_mul_sub_mul {k a b x y : α} (hab : k ∣ a - b) (hxy : k ∣ x - y) :
k ∣ a * x - b * y :=
begin
convert dvd_add (dvd_mul_of_dvd_right hxy a) (dvd_mul_of_dvd_left hab y),
rw [mul_sub_left_distrib, mul_sub_right_distrib],
simp only [sub_eq_add_neg, add_assoc, neg_add_cancel_left],
end
lemma dvd_iff_dvd_of_dvd_sub {a b c : α} (h : a ∣ (b - c)) : (a ∣ b ↔ a ∣ c) :=
begin
split,
{ intro h',
convert dvd_sub h' h,
exact eq.symm (sub_sub_self b c) },
{ intro h',
convert dvd_add h h',
exact eq_add_of_sub_eq rfl }
end
end comm_ring
lemma succ_ne_self [ring α] [nontrivial α] (a : α) : a + 1 ≠ a :=
λ h, one_ne_zero ((add_right_inj a).mp (by simp [h]))
lemma pred_ne_self [ring α] [nontrivial α] (a : α) : a - 1 ≠ a :=
λ h, one_ne_zero (neg_injective ((add_right_inj a).mp (by { convert h, simp })))
/-- A domain is a ring with no zero divisors, i.e. satisfying
the condition `a * b = 0 ↔ a = 0 ∨ b = 0`. Alternatively, a domain
is an integral domain without assuming commutativity of multiplication. -/
@[protect_proj] class domain (α : Type u) extends ring α, nontrivial α :=
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0)
section domain
variable [domain α]
@[priority 100] -- see Note [lower instance priority]
instance domain.to_no_zero_divisors : no_zero_divisors α :=
⟨domain.eq_zero_or_eq_zero_of_mul_eq_zero⟩
@[priority 100] -- see Note [lower instance priority]
instance domain.to_cancel_monoid_with_zero : cancel_monoid_with_zero α :=
{ mul_left_cancel_of_ne_zero := λ a b c ha,
by { rw [← sub_eq_zero, ← mul_sub], simp [ha, sub_eq_zero] },
mul_right_cancel_of_ne_zero := λ a b c hb,
by { rw [← sub_eq_zero, ← sub_mul], simp [hb, sub_eq_zero] },
.. (infer_instance : semiring α) }
/-- Pullback a `domain` instance along an injective function. -/
protected def function.injective.domain [has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β]
(f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) :
domain β :=
{ .. hf.ring f zero one add mul neg, .. pullback_nonzero f zero one,
.. hf.no_zero_divisors f zero mul }
end domain
/-!
### Integral domains
-/
@[protect_proj, ancestor comm_ring domain]
class integral_domain (α : Type u) extends comm_ring α, domain α
section integral_domain
variables [integral_domain α] {a b c d e : α}
@[priority 100] -- see Note [lower instance priority]
instance integral_domain.to_comm_cancel_monoid_with_zero : comm_cancel_monoid_with_zero α :=
{ ..comm_semiring.to_comm_monoid_with_zero, ..domain.to_cancel_monoid_with_zero }
/-- Pullback an `integral_domain` instance along an injective function. -/
protected def function.injective.integral_domain [has_zero β] [has_one β] [has_add β]
[has_mul β] [has_neg β] (f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) :
integral_domain β :=
{ .. hf.comm_ring f zero one add mul neg, .. hf.domain f zero one add mul neg }
lemma mul_self_eq_mul_self_iff {a b : α} : a * a = b * b ↔ a = b ∨ a = -b :=
by rw [← sub_eq_zero, mul_self_sub_mul_self, mul_eq_zero, or_comm, sub_eq_zero,
add_eq_zero_iff_eq_neg]
lemma mul_self_eq_one_iff {a : α} : a * a = 1 ↔ a = 1 ∨ a = -1 :=
by rw [← mul_self_eq_mul_self_iff, one_mul]
/-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or
one's additive inverse. -/
lemma units.inv_eq_self_iff (u : units α) : u⁻¹ = u ↔ u = 1 ∨ u = -1 :=
by { rw inv_eq_iff_mul_eq_one, simp only [units.ext_iff], push_cast, exact mul_self_eq_one_iff }
end integral_domain
namespace ring
variables [ring R]
open_locale classical
/-- Introduce a function `inverse` on a ring `R`, which sends `x` to `x⁻¹` if `x` is invertible and
to `0` otherwise. This definition is somewhat ad hoc, but one needs a fully (rather than partially)
defined inverse function for some purposes, including for calculus. -/
noncomputable def inverse : R → R :=
λ x, if h : is_unit x then (((classical.some h)⁻¹ : units R) : R) else 0
/-- By definition, if `x` is invertible then `inverse x = x⁻¹`. -/
@[simp] lemma inverse_unit (a : units R) : inverse (a : R) = (a⁻¹ : units R) :=
begin
simp [is_unit_unit, inverse],
exact units.inv_unique (classical.some_spec (is_unit_unit a)),
end
/-- By definition, if `x` is not invertible then `inverse x = 0`. -/
@[simp] lemma inverse_non_unit (x : R) (h : ¬(is_unit x)) : inverse x = 0 := dif_neg h
end ring
/-- A predicate to express that a ring is an integral domain.
This is mainly useful because such a predicate does not contain data,
and can therefore be easily transported along ring isomorphisms. -/
structure is_integral_domain (R : Type u) [ring R] extends nontrivial R : Prop :=
(mul_comm : ∀ (x y : R), x * y = y * x)
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ x y : R, x * y = 0 → x = 0 ∨ y = 0)
-- The linter does not recognize that is_integral_domain.to_nontrivial is a structure
-- projection, disable it
attribute [nolint def_lemma doc_blame] is_integral_domain.to_nontrivial
/-- Every integral domain satisfies the predicate for integral domains. -/
lemma integral_domain.to_is_integral_domain (R : Type u) [integral_domain R] :
is_integral_domain R :=
{ .. (‹_› : integral_domain R) }
/-- If a ring satisfies the predicate for integral domains,
then it can be endowed with an `integral_domain` instance
whose data is definitionally equal to the existing data. -/
def is_integral_domain.to_integral_domain (R : Type u) [ring R] (h : is_integral_domain R) :
integral_domain R :=
{ .. (‹_› : ring R), .. (‹_› : is_integral_domain R) }
namespace semiconj_by
@[simp] lemma add_right [distrib R] {a x y x' y' : R}
(h : semiconj_by a x y) (h' : semiconj_by a x' y') :
semiconj_by a (x + x') (y + y') :=
by simp only [semiconj_by, left_distrib, right_distrib, h.eq, h'.eq]
@[simp] lemma add_left [distrib R] {a b x y : R}
(ha : semiconj_by a x y) (hb : semiconj_by b x y) :
semiconj_by (a + b) x y :=
by simp only [semiconj_by, left_distrib, right_distrib, ha.eq, hb.eq]
variables [ring R] {a b x y x' y' : R}
lemma neg_right (h : semiconj_by a x y) : semiconj_by a (-x) (-y) :=
by simp only [semiconj_by, h.eq, neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm]
@[simp] lemma neg_right_iff : semiconj_by a (-x) (-y) ↔ semiconj_by a x y :=
⟨λ h, neg_neg x ▸ neg_neg y ▸ h.neg_right, semiconj_by.neg_right⟩
lemma neg_left (h : semiconj_by a x y) : semiconj_by (-a) x y :=
by simp only [semiconj_by, h.eq, neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm]
@[simp] lemma neg_left_iff : semiconj_by (-a) x y ↔ semiconj_by a x y :=
⟨λ h, neg_neg a ▸ h.neg_left, semiconj_by.neg_left⟩
@[simp] lemma neg_one_right (a : R) : semiconj_by a (-1) (-1) :=
(one_right a).neg_right
@[simp] lemma neg_one_left (x : R) : semiconj_by (-1) x x :=
(semiconj_by.one_left x).neg_left
@[simp] lemma sub_right (h : semiconj_by a x y) (h' : semiconj_by a x' y') :
semiconj_by a (x - x') (y - y') :=
h.add_right h'.neg_right
@[simp] lemma sub_left (ha : semiconj_by a x y) (hb : semiconj_by b x y) :
semiconj_by (a - b) x y :=
ha.add_left hb.neg_left
end semiconj_by
namespace commute
@[simp] theorem add_right [distrib R] {a b c : R} :
commute a b → commute a c → commute a (b + c) :=
semiconj_by.add_right
@[simp] theorem add_left [distrib R] {a b c : R} :
commute a c → commute b c → commute (a + b) c :=
semiconj_by.add_left
variables [ring R] {a b c : R}
theorem neg_right : commute a b → commute a (- b) := semiconj_by.neg_right
@[simp] theorem neg_right_iff : commute a (-b) ↔ commute a b := semiconj_by.neg_right_iff
theorem neg_left : commute a b → commute (- a) b := semiconj_by.neg_left
@[simp] theorem neg_left_iff : commute (-a) b ↔ commute a b := semiconj_by.neg_left_iff
@[simp] theorem neg_one_right (a : R) : commute a (-1) := semiconj_by.neg_one_right a
@[simp] theorem neg_one_left (a : R): commute (-1) a := semiconj_by.neg_one_left a
@[simp] theorem sub_right : commute a b → commute a c → commute a (b - c) := semiconj_by.sub_right
@[simp] theorem sub_left : commute a c → commute b c → commute (a - b) c := semiconj_by.sub_left
end commute
|
bf5f45ee67bf450ae8c3b1fc97c3ec3ba39578a7 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/irreducible.lean | 0862574732a1380f1fef7885cce82d691efe70d1 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 9,686 | lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.finset.lattice
import data.fintype.card
/-!
# Irreducible and prime elements in an order
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
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
* `sup_irred a`: Sup-irreducibility, `a` isn't minimal and `a = b ⊔ c → a = b ∨ a = c`
* `inf_irred a`: Inf-irreducibility, `a` isn't maximal and `a = b ⊓ c → a = b ∨ a = c`
* `sup_prime a`: Sup-primality, `a` isn't minimal and `a ≤ b ⊔ c → a ≤ b ∨ a ≤ c`
* `inf_irred a`: Inf-primality, `a` isn't maximal and `a ≥ b ⊓ c → a ≥ b ∨ a ≥ c`
* `exists_sup_irred_decomposition`/`exists_inf_irred_decomposition`: Decomposition into irreducibles
in a well-founded semilattice.
-/
open finset order_dual
variables {ι α : Type*}
/-! ### Irreducible and prime elements -/
section semilattice_sup
variables [semilattice_sup α] {a b c : α}
/-- A sup-irreducible element is a non-bottom element which isn't the supremum of anything smaller.
-/
def sup_irred (a : α) : Prop := ¬ is_min 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 sup_prime (a : α) : Prop := ¬ is_min a ∧ ∀ ⦃b c⦄, a ≤ b ⊔ c → a ≤ b ∨ a ≤ c
lemma sup_irred.not_is_min (ha : sup_irred a) : ¬ is_min a := ha.1
lemma sup_prime.not_is_min (ha : sup_prime a) : ¬ is_min a := ha.1
lemma is_min.not_sup_irred (ha : is_min a) : ¬ sup_irred a := λ h, h.1 ha
lemma is_min.not_sup_prime (ha : is_min a) : ¬ sup_prime a := λ h, h.1 ha
@[simp] lemma not_sup_irred : ¬ sup_irred a ↔ is_min a ∨ ∃ b c, b ⊔ c = a ∧ b < a ∧ c < a :=
begin
rw [sup_irred, not_and_distrib],
push_neg,
rw exists₂_congr,
simp [@eq_comm _ _ a] { contextual := tt },
end
@[simp] lemma not_sup_prime : ¬ sup_prime a ↔ is_min a ∨ ∃ b c, a ≤ b ⊔ c ∧ ¬ a ≤ b ∧ ¬ a ≤ c :=
by { rw [sup_prime, not_and_distrib], push_neg, refl }
protected lemma sup_prime.sup_irred : sup_prime a → sup_irred a :=
and.imp_right $ λ h b c ha, by simpa [←ha] using h ha.ge
lemma sup_prime.le_sup (ha : sup_prime a) : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c :=
⟨λ h, ha.2 h, λ h, h.elim le_sup_of_le_left le_sup_of_le_right⟩
variables [order_bot α] {s : finset ι} {f : ι → α}
@[simp] lemma not_sup_irred_bot : ¬ sup_irred (⊥ : α) := is_min_bot.not_sup_irred
@[simp] lemma not_sup_prime_bot : ¬ sup_prime (⊥ : α) := is_min_bot.not_sup_prime
lemma sup_irred.ne_bot (ha : sup_irred a) : a ≠ ⊥ := by { rintro rfl, exact not_sup_irred_bot ha }
lemma sup_prime.ne_bot (ha : sup_prime a) : a ≠ ⊥ := by { rintro rfl, exact not_sup_prime_bot ha }
lemma sup_irred.finset_sup_eq (ha : sup_irred a) (h : s.sup f = a) : ∃ i ∈ s, f i = a :=
begin
classical,
induction s using finset.induction with i s hi 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,
end
lemma sup_prime.le_finset_sup (ha : sup_prime a) : a ≤ s.sup f ↔ ∃ i ∈ s, a ≤ f i :=
begin
classical,
induction s using finset.induction with i s hi ih,
{ simp [ha.ne_bot] },
{ simp only [exists_prop, exists_mem_insert, sup_insert, ha.le_sup, ih] }
end
variables [well_founded_lt α]
/-- 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. -/
lemma exists_sup_irred_decomposition (a : α) :
∃ s : finset α, s.sup id = a ∧ ∀ ⦃b⦄, b ∈ s → sup_irred b :=
begin
classical,
apply well_founded_lt.induction a _,
clear a,
rintro a ih,
by_cases ha : sup_irred a,
{ exact ⟨{a}, by simp [ha]⟩ },
rw not_sup_irred 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
end semilattice_sup
section semilattice_inf
variables [semilattice_inf α] {a b c : α}
/-- An inf-irreducible element is a non-top element which isn't the infimum of anything bigger. -/
def inf_irred (a : α) : Prop := ¬ is_max 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 inf_prime (a : α) : Prop := ¬ is_max a ∧ ∀ ⦃b c⦄, b ⊓ c ≤ a → b ≤ a ∨ c ≤ a
@[simp] lemma is_max.not_inf_irred (ha : is_max a) : ¬ inf_irred a := λ h, h.1 ha
@[simp] lemma is_max.not_inf_prime (ha : is_max a) : ¬ inf_prime a := λ h, h.1 ha
@[simp] lemma not_inf_irred : ¬ inf_irred a ↔ is_max a ∨ ∃ b c, b ⊓ c = a ∧ a < b ∧ a < c :=
@not_sup_irred αᵒᵈ _ _
@[simp] lemma not_inf_prime : ¬ inf_prime a ↔ is_max a ∨ ∃ b c, b ⊓ c ≤ a ∧ ¬ b ≤ a ∧ ¬ c ≤ a :=
@not_sup_prime αᵒᵈ _ _
protected lemma inf_prime.inf_irred : inf_prime a → inf_irred a :=
and.imp_right $ λ h b c ha, by simpa [←ha] using h ha.le
lemma inf_prime.inf_le (ha : inf_prime a) : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a :=
⟨λ h, ha.2 h, λ h, h.elim inf_le_of_left_le inf_le_of_right_le⟩
variables [order_top α] {s : finset ι} {f : ι → α}
@[simp] lemma not_inf_irred_top : ¬ inf_irred (⊤ : α) := is_max_top.not_inf_irred
@[simp] lemma not_inf_prime_top : ¬ inf_prime (⊤ : α) := is_max_top.not_inf_prime
lemma inf_irred.ne_top (ha : inf_irred a) : a ≠ ⊤ := by { rintro rfl, exact not_inf_irred_top ha }
lemma inf_prime.ne_top (ha : inf_prime a) : a ≠ ⊤ := by { rintro rfl, exact not_inf_prime_top ha }
lemma inf_irred.finset_inf_eq : inf_irred a → s.inf f = a → ∃ i ∈ s, f i = a :=
@sup_irred.finset_sup_eq _ αᵒᵈ _ _ _ _ _
lemma inf_prime.finset_inf_le (ha : inf_prime a) : s.inf f ≤ a ↔ ∃ i ∈ s, f i ≤ a :=
@sup_prime.le_finset_sup _ αᵒᵈ _ _ _ _ _ ha
variables [well_founded_gt α]
/-- In a cowell-founded lattice, any element is the infimum of finitely many inf-irreducible
elements. This is the order-theoretic analogue of prime factorisation. -/
lemma exists_inf_irred_decomposition (a : α) :
∃ s : finset α, s.inf id = a ∧ ∀ ⦃b⦄, b ∈ s → inf_irred b :=
@exists_sup_irred_decomposition αᵒᵈ _ _ _ _
end semilattice_inf
section semilattice_sup
variables [semilattice_sup α]
@[simp] lemma inf_irred_to_dual {a : α} : inf_irred (to_dual a) ↔ sup_irred a := iff.rfl
@[simp] lemma inf_prime_to_dual {a : α} : inf_prime (to_dual a) ↔ sup_prime a := iff.rfl
@[simp] lemma sup_irred_of_dual {a : αᵒᵈ} : sup_irred (of_dual a) ↔ inf_irred a := iff.rfl
@[simp] lemma sup_prime_of_dual {a : αᵒᵈ} : sup_prime (of_dual a) ↔ inf_prime a := iff.rfl
alias inf_irred_to_dual ↔ _ sup_irred.dual
alias inf_prime_to_dual ↔ _ sup_prime.dual
alias sup_irred_of_dual ↔ _ inf_irred.of_dual
alias sup_prime_of_dual ↔ _ inf_prime.of_dual
end semilattice_sup
section semilattice_inf
variables [semilattice_inf α]
@[simp] lemma sup_irred_to_dual {a : α} : sup_irred (to_dual a) ↔ inf_irred a := iff.rfl
@[simp] lemma sup_prime_to_dual {a : α} : sup_prime (to_dual a) ↔ inf_prime a := iff.rfl
@[simp] lemma inf_irred_of_dual {a : αᵒᵈ} : inf_irred (of_dual a) ↔ sup_irred a := iff.rfl
@[simp] lemma inf_prime_of_dual {a : αᵒᵈ} : inf_prime (of_dual a) ↔ sup_prime a := iff.rfl
alias sup_irred_to_dual ↔ _ inf_irred.dual
alias sup_prime_to_dual ↔ _ inf_prime.dual
alias inf_irred_of_dual ↔ _ sup_irred.of_dual
alias inf_prime_of_dual ↔ _ sup_prime.of_dual
end semilattice_inf
section distrib_lattice
variables [distrib_lattice α] {a b c : α}
@[simp] lemma sup_prime_iff_sup_irred : sup_prime a ↔ sup_irred a :=
⟨sup_prime.sup_irred, and.imp_right $ λ h b c,
by { simp_rw [←inf_eq_left, inf_sup_left], exact @h _ _ }⟩
@[simp] lemma inf_prime_iff_inf_irred : inf_prime a ↔ inf_irred a :=
⟨inf_prime.inf_irred, and.imp_right $ λ h b c,
by { simp_rw [←sup_eq_left, sup_inf_left], exact @h _ _ }⟩
alias sup_prime_iff_sup_irred ↔ _ sup_irred.sup_prime
alias inf_prime_iff_inf_irred ↔ _ inf_irred.inf_prime
attribute [protected] sup_irred.sup_prime inf_irred.inf_prime
end distrib_lattice
section linear_order
variables [linear_order α] {a : α}
@[simp] lemma sup_prime_iff_not_is_min : sup_prime a ↔ ¬ is_min a := and_iff_left $ by simp
@[simp] lemma inf_prime_iff_not_is_max : inf_prime a ↔ ¬ is_max a := and_iff_left $ by simp
@[simp] lemma sup_irred_iff_not_is_min : sup_irred a ↔ ¬ is_min a :=
and_iff_left $ λ _ _, by simpa only [sup_eq_max, max_eq_iff] using or.imp and.left and.left
@[simp] lemma inf_irred_iff_not_is_max : inf_irred a ↔ ¬ is_max a :=
and_iff_left $ λ _ _, by simpa only [inf_eq_min, min_eq_iff] using or.imp and.left and.left
end linear_order
|
923e7f57d38ae0882e5e683756ceab4092bf4e12 | d1a52c3f208fa42c41df8278c3d280f075eb020c | /src/Lean/Util/CollectFVars.lean | c59a0b276f2f561486ef2f060a2d46112115d938 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 1,113 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Expr
namespace Lean.CollectFVars
structure State where
visitedExpr : ExprSet := {}
fvarSet : FVarIdSet := {}
deriving Inhabited
abbrev Visitor := State → State
mutual
partial def visit (e : Expr) : Visitor := fun s =>
if !e.hasFVar || s.visitedExpr.contains e then s
else main e { s with visitedExpr := s.visitedExpr.insert e }
partial def main : Expr → Visitor
| Expr.proj _ _ e _ => visit e
| Expr.forallE _ d b _ => visit b ∘ visit d
| Expr.lam _ d b _ => visit b ∘ visit d
| Expr.letE _ t v b _ => visit b ∘ visit v ∘ visit t
| Expr.app f a _ => visit a ∘ visit f
| Expr.mdata _ b _ => visit b
| Expr.fvar fvarId _ => fun s => { s with fvarSet := s.fvarSet.insert fvarId }
| _ => id
end
end CollectFVars
def collectFVars (s : CollectFVars.State) (e : Expr) : CollectFVars.State :=
CollectFVars.main e s
end Lean
|
c7d3879f26e585bad919fb5fffabd64be2963718 | 2bafba05c98c1107866b39609d15e849a4ca2bb8 | /src/week_8/Part_C_H1.lean | 613fb450b2839b944f4f2286f28b78c065868c10 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/formalising-mathematics | b54c83c94b5c315024ff09997fcd6b303892a749 | 7cf1d51c27e2038d2804561d63c74711924044a1 | refs/heads/master | 1,651,267,046,302 | 1,638,888,459,000 | 1,638,888,459,000 | 331,592,375 | 284 | 24 | Apache-2.0 | 1,669,593,705,000 | 1,611,224,849,000 | Lean | UTF-8 | Lean | false | false | 10,113 | lean | import week_8.Part_B_H0
import group_theory.quotient_group
/-
# A crash course in H¹(G,M)
We stick to the conventions that `G` is a group (or even
a monoid, we never use inversion) and that `M` is a `G`-module,
that is, an additive abelian group with a `G`-action.
A key concept here is that of a cocycle, or a twisted homomorphism.
These things were later renamed 1-cocycles when people realised that higher
cocycles existed; today whenever I say "cocycle" I mean 1-cocycle).
A cocycle is a function `f : G → M` satisfying the axiom
`∀ (g h : G), f (g * h) = f g + g • f h`. These things
naturally form an abelian group under pointwise addition
and negation, by which I mean "operate on the target":
`(f₁ + f₂) g = f₁ g + f₂ g`.
Let `Z1 G M` denote the abelian group of cocycles.
There is a subgroup `B1 G M` of coboundaries, consisting
of the functions `f` for which there exists `m : M`
such that `f g = g • m - m` (note that it is at this point where we
crucially use the fact that `M` is an abelian group and not just an abelian
monoid). One easily checks that all coboundaries are cocycles, and that
coboundaries are a subgroup (you will be doing this below). The
quotient group `H1 G M`, written `H¹(G,M)` by mathematicians, is the main
definition in this file. The first two theorems we shall prove about it here
are that it is functorial (i.e. a map `φ : M →+[G] N` gives
rise to a map `φ.H1_hom : H1 G M →+ H1 G N`), and exact in the
middle (i.e. if `0 → A → B → C → 0` is a short exact sequence
of `G`-modules then the sequence `H1 G A →+ H1 G B →+ H1 G C`
is exact).
Further work would be to verify "inf-res", otherwise known
as the beginning of the long exact
sequence of terms of low degree in the Hochschild-Serre
spectral sequence for group cohomology (i.e.
`0 → H¹(G/N, Aᴺ) → H¹(G, A) → H¹(N, A)` ) and of course one
could go on to define n-cocycles and n-coboundaries (please
get in touch if you're interested in doing this -- I have
ideas about how to set it all up) and to
construct the Hochschild-Serre spectral sequence itself.
I have no doubt that these kinds of results could be turned
into a research paper.
Let's start with a definition of `H1 G M`. First we need
to define cocycles and coboundaries.
-/
-- 1-cocycles as an additive subgroup of the group `Hom(G,M)`
-- a.k.a. `G → M` of functions from `G` to `M`, with group
-- law induced from `M`.
def Z1_subgroup (G M : Type)
[monoid G] [add_comm_group M] [distrib_mul_action G M] : add_subgroup (G → M) :=
{ carrier := { f : G → M | ∀ (g h : G), f (g * h) = f g + g • f h },
zero_mem' := begin
-- the zero map is a cocycle
sorry
end,
add_mem' := begin
sorry,
end,
neg_mem' := begin
sorry,
end }
-- Just like `H0 G M`, we promote this term to a type
structure Z1 (G M : Type)
[monoid G] [add_comm_group M] [distrib_mul_action G M] : Type :=
(to_fun : G → M)
(is_cocycle : ∀ (g h : G), to_fun (g * h) = to_fun g + g • to_fun h)
-- This is a definition so we need to make an API
namespace Z1
-- let G be a group (or a monoid) and let M be a G-module.
variables {G M : Type}
[monoid G] [add_comm_group M] [distrib_mul_action G M]
-- add a coercion from a cocycle to the function G → M
instance : has_coe_to_fun (Z1 G M) :=
{ F := λ _, G → M,
coe := to_fun }
@[simp] lemma coe_apply (to_fun : G → M)
(is_cocycle : ∀ (g h : G), to_fun (g * h) = to_fun g + g • to_fun h) (g : G) :
({ to_fun := to_fun, is_cocycle := is_cocycle } : Z1 G M) g = to_fun g := rfl
-- add a specification for the coercion
lemma spec (a : Z1 G M) : ∀ (g h : G), a (g * h) = a g + g • a h :=
-- this is the last time we'll see `a.is_cocycle`: we'll
-- use `a.spec` from now on because it applies to `⇑a` and not `a.to_fun`.
a.is_cocycle
-- add an extensionality lemma
@[ext] lemma ext (a b : Z1 G M) (h : ∀ g, a g = b g) : a = b :=
begin
cases a, cases b, simp, ext g, exact h g,
end
-- can you prove addition of two cocycles is a cocycle
def add (a b : Z1 G M) : Z1 G M :=
{ to_fun := λ g, a g + b g,
is_cocycle
:= begin
sorry,
end }
instance : has_add (Z1 G M) := ⟨add⟩
@[simp] lemma coe_add (a b : Z1 G M) (g : G) : (a + b) g = a g + b g := rfl
-- the zero cocycle is a cocycle
def zero : Z1 G M :=
{ to_fun := λ g, 0,
is_cocycle
:= begin
sorry,
end
}
instance : has_zero (Z1 G M) := ⟨zero⟩
@[simp] lemma coe_zero (g : G) : (0 : Z1 G M) g = 0 := rfl
-- negation of a cocycle is a cocycle
def neg (a : Z1 G M) : Z1 G M :=
{ to_fun := λ g, -(a g),
is_cocycle
:= begin
sorry
end
}
instance : has_neg (Z1 G M) := ⟨neg⟩
@[simp] lemma coe_neg (a : Z1 G M) (g : G) : (-a) g = -(a g) := rfl
def sub (a b : Z1 G M) : Z1 G M := a + -b
instance : has_sub (Z1 G M) := ⟨sub⟩
-- make the cocycles into a group
instance : add_comm_group (Z1 G M) :=
begin
refine_struct {
add := (+),
zero := (0 : Z1 G M),
neg := has_neg.neg,
sub := has_sub.sub,
-- ignore this, we have to fill in this proof for technical reasons
sub_eq_add_neg := λ _ _, rfl };
-- we now have five goals. Let's use the semicolon trick to work on
-- all of them at once. I'll show you what happens to the proof
-- of associativity, the others are the same mutatis mutandis
-- (but harder to see)
-- *TODO* could documentstring commutativity and remark that
-- they can see associativity using the cursor.
-- ⊢ ∀ (a b c : Z1 G M), a + b + c = a + (b + c)
intros;
-- ⊢ a + b + c = a + (b + c)
ext;
-- ⊢ ⇑(a + b + c) g = ⇑(a + (b + c)) g
simp;
-- ⊢ ⇑a g + ⇑b g + ⇑c g = ⇑a g + (⇑b g + ⇑c g)
abel
-- general additive abelian group tactic which solves
-- goals which are (absolute) identities in every abelian group.
-- Hypotheses are not looked at though. See Chris Hughes' forthcoming
-- Imperial MSc thesis for a new group theory tactic which is to `abel`
-- what `nlinarith` is to `ring`.
end
end Z1
namespace distrib_mul_action_hom
-- The Z1 construction is functorial in the module `M`. Let's construct
-- the relevant function, showing that if `φ : M →+[G] N` then
-- composition induces an additive group homomorphism `Z1 G M → Z1 G N`.
-- Just like `H0` we first define the auxiliary bare function,
-- and then beef it up to an abelian group homomorphism.
variables {G M N : Type} [monoid G]
[add_comm_group M] [distrib_mul_action G M]
[add_comm_group N] [distrib_mul_action G N]
def Z1_hom_underlying_function (φ : M →+[G] N) (f : Z1 G M) : Z1 G N :=
⟨λ g, φ (f g), begin
-- need to prove that this function obtained by composing the cocycle
-- f with the G-module homomorphism φ is also a cocycle.
sorry
end⟩
@[norm_cast]
lemma Z1_hom_underlying_function_coe_comp (φ : M →+[G] N) (f : Z1 G M) (g : G) :
(Z1_hom_underlying_function φ f g : N) = φ (f g) := rfl
def Z1 (φ : M →+[G] N) : Z1 G M →+ Z1 G N :=
-- to make a term of type `X →+ Y` (a group homomorphism) from a function
-- `f : X → Y` and
-- a proof that it preserves addition we use the following constructor:
add_monoid_hom.mk'
-- We now throw in the bare function
(Z1_hom_underlying_function φ)
-- (or could try direct definition:)
-- (λ f, ⟨λ g, φ (f g), begin
-- -- need to prove that this function obtained by composing the cocycle
-- -- f with the G-module homomorphism φ is also a cocycle.
-- intros g h,
-- rw ←φ.map_smul,
-- rw f.spec,
-- simp,
-- end⟩)
-- and now the proof that it preserves addition
begin
intros e f,
ext g,
simp [φ.Z1_hom_underlying_function_coe_comp],
end
-- it's a functor
variables {P : Type} [add_comm_group P] [distrib_mul_action G P]
def map_comp (φ: M →+[G] N) (ψ : N →+[G] P) (z : _root_.Z1 G M) :
(ψ.Z1) ((φ.Z1) z) = (ψ ∘ᵍ φ).Z1 z :=
begin
-- what do you think?
sorry
end
@[simp] lemma Z1_spec (φ : M →+[G] N) (a : _root_.Z1 G M) (g : G) :
φ.Z1 a g = φ (a g) := rfl
@[simp] lemma Z1_spec' (φ : M →+[G] N) (a : _root_.Z1 G M) (g : G) :
(φ.Z1 a : G → N) = ((φ : M → N) ∘ a) := rfl
end distrib_mul_action_hom
section cochain_map
variables (G M : Type) [monoid G] [add_comm_group M]
[distrib_mul_action G M]
def cochain_map : M →+ Z1 G M :=
{ to_fun := λ m, { to_fun := λ g, g • m - m, is_cocycle := begin
simp [mul_smul, smul_sub],
end},
map_zero' := begin
sorry
end,
map_add' := begin
sorry,
end }
@[simp] lemma cochain_map_apply (m : M) (g : G) :
cochain_map G M m g = g • m - m := rfl
end cochain_map
-- question : do we have cokernels? If A B are abelian groups and
-- `f : A → B` is a group hom, how do I make the type coker f`
-- Lean has inbuilt quotients of additive abelian groups by subgroups
-- so we just take the quotient by the range
@[derive add_comm_group]
def H1 (G M : Type) [monoid G] [add_comm_group M]
[distrib_mul_action G M] : Type :=
quotient_add_group.quotient ((cochain_map G M).range)
--quotient_add_group.quotient (B1 G M)
section quotient_stuff
variables {G M : Type} [monoid G] [add_comm_group M]
[distrib_mul_action G M]
def Z1.quotient : Z1 G M →+ H1 G M :=
quotient_add_group.mk' _
lemma ab_H1.ker_quotient : (Z1.quotient).ker = (cochain_map G M).range :=
quotient_add_group.ker_mk _
end quotient_stuff
namespace H1
variables {G M : Type} [monoid G] [add_comm_group M]
[distrib_mul_action G M]
@[elab_as_eliminator]
def induction_on {p : H1 G M → Prop}
(IH : ∀ z : Z1 G M, p (z.quotient)) (h : H1 G M) : p h :=
quot.induction_on h IH
end H1
/-
We have just defined `H1 G M` as a quotient group, and told Lean
to figure out (or "derive") the obvious abelian group structure
on it, which it did.
If you want to go any further, check out the `ideas` directory.
In there we show that if `φ : M →+[G] N` is a `G`-module
hom then `φ` induces a map `H1 G M → H1 G N`. To prove this we will
need to figure out how to define maps from and to quotient group structures.
Just like last week, this is simply a matter of learning the API for the
definition `quotient_add_group.quotient`.
-/ |
254acbfb29aee403951ad3b526eb6b0894892cab | 30b012bb72d640ec30c8fdd4c45fdfa67beb012c | /data/real/cau_seq_filter.lean | 702a7160d10622f130b749a2cd9ed9603dc0a6d2 | [
"Apache-2.0"
] | permissive | kckennylau/mathlib | 21fb810b701b10d6606d9002a4004f7672262e83 | 47b3477e20ffb5a06588dd3abb01fe0fe3205646 | refs/heads/master | 1,634,976,409,281 | 1,542,042,832,000 | 1,542,319,733,000 | 109,560,458 | 0 | 0 | Apache-2.0 | 1,542,369,208,000 | 1,509,867,494,000 | Lean | UTF-8 | Lean | false | false | 11,292 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Sébastien Gouëzel
Characterize completeness of metric spaces in terms of Cauchy sequences.
In particular, reconcile the filter notion of Cauchy-ness with the cau_seq notion on normed spaces.
-/
import analysis.topology.uniform_space analysis.normed_space data.real.cau_seq analysis.limits
import tactic.linarith
universes u v
open set filter classical
variable {β : Type v}
/-We show that a metric space in which all Cauchy sequences converge is complete, i.e., all
Cauchy filters converge. For this, we approximate any Cauchy filter by a Cauchy sequence,
taking advantage of the fact that there is a sequence tending to `0` in ℝ.-/
namespace sequentially_complete
section
variables [metric_space β] {f : filter β} (hf : cauchy f)
private lemma one_div_succ (n : ℕ) : 1 / ((n : ℝ) + 1) > 0 :=
one_div_pos_of_pos (by linarith using [show (↑n : ℝ) ≥ 0, from nat.cast_nonneg _])
def set_seq_of_cau_filter : ℕ → set β
| 0 := some ((cauchy_of_metric.1 hf).2 _ (one_div_succ 0))
| (n+1) := (set_seq_of_cau_filter n) ∩ some ((cauchy_of_metric.1 hf).2 _ (one_div_succ (n + 1)))
lemma set_seq_of_cau_filter_mem_sets : ∀ n, set_seq_of_cau_filter hf n ∈ f.sets
| 0 := some (some_spec ((cauchy_of_metric.1 hf).2 _ (one_div_succ 0)))
| (n+1) := inter_mem_sets (set_seq_of_cau_filter_mem_sets n)
(some (some_spec ((cauchy_of_metric.1 hf).2 _ (one_div_succ (n + 1)))))
lemma set_seq_of_cau_filter_inhabited (n : ℕ) : ∃ x, x ∈ set_seq_of_cau_filter hf n :=
inhabited_of_mem_sets (cauchy_of_metric.1 hf).1 (set_seq_of_cau_filter_mem_sets hf n)
lemma set_seq_of_cau_filter_spec : ∀ n, ∀ {x y},
x ∈ set_seq_of_cau_filter hf n → y ∈ set_seq_of_cau_filter hf n → dist x y < 1/((n : ℝ) + 1)
| 0 := some_spec (some_spec ((cauchy_of_metric.1 hf).2 _ (one_div_succ 0)))
| (n+1) := λ x y hx hy,
some_spec (some_spec ((cauchy_of_metric.1 hf).2 _ (one_div_succ (n+1)))) x y
(mem_of_mem_inter_right hx) (mem_of_mem_inter_right hy)
-- this must exist somewhere, no?
private lemma mono_of_mono_succ_aux {α} [partial_order α] (f : ℕ → α) (h : ∀ n, f (n+1) ≤ f n) (m : ℕ) :
∀ n, f (m + n) ≤ f m
| 0 := le_refl _
| (k+1) := le_trans (h _) (mono_of_mono_succ_aux _)
lemma mono_of_mono_succ {α} [partial_order α] (f : ℕ → α) (h : ∀ n, f (n+1) ≤ f n) {m n : ℕ}
(hmn : m ≤ n) : f n ≤ f m :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_le hmn in
by simpa [hk] using mono_of_mono_succ_aux f h m k
lemma set_seq_of_cau_filter_monotone' (n : ℕ) :
set_seq_of_cau_filter hf (n+1) ⊆ set_seq_of_cau_filter hf n :=
inter_subset_left _ _
lemma set_seq_of_cau_filter_monotone {n k : ℕ} (hle : n ≤ k) :
set_seq_of_cau_filter hf k ⊆ set_seq_of_cau_filter hf n :=
mono_of_mono_succ (set_seq_of_cau_filter hf) (set_seq_of_cau_filter_monotone' hf) hle
/--The approximating Cauchy sequence for the Cauchy filter `f`-/
noncomputable def seq_of_cau_filter (n : ℕ) : β :=
some (set_seq_of_cau_filter_inhabited hf n)
lemma seq_of_cau_filter_mem_set_seq (n : ℕ) : seq_of_cau_filter hf n ∈ set_seq_of_cau_filter hf n :=
some_spec (set_seq_of_cau_filter_inhabited hf n)
lemma seq_of_cau_filter_is_cauchy' {n k : ℕ} (hle : n ≤ k) :
dist (seq_of_cau_filter hf n) (seq_of_cau_filter hf k) < 1 / ((n : ℝ) + 1) :=
set_seq_of_cau_filter_spec hf _
(seq_of_cau_filter_mem_set_seq hf n)
(set_seq_of_cau_filter_monotone hf hle (seq_of_cau_filter_mem_set_seq hf k))
lemma cauchy_seq_of_dist_tendsto_0 {s : ℕ → β} {b : ℕ → ℝ} (h : ∀ {n k : ℕ}, n ≤ k → dist (s n) (s k) < b n)
(hb : tendsto b at_top (nhds 0)) : cauchy_seq s :=
begin
rw cauchy_seq_metric',
assume ε hε,
have hb : ∀ (i : set ℝ), (0:ℝ) ∈ i → is_open i → (∃ (a : ℕ), ∀ (c : ℕ), c ≥ a → b c ∈ i),
{ simpa [tendsto, nhds] using hb },
cases hb (ball 0 ε) (mem_ball_self hε) (is_open_ball) with N hN,
existsi N,
intros k hk,
rw [dist_comm],
apply lt.trans,
apply h hk,
have := hN _ (le_refl _),
have bnn : ∀ n, b n ≥ 0, from λ n, le_of_lt (lt_of_le_of_lt dist_nonneg (h (le_refl n))),
simpa [real.norm_eq_abs, abs_of_nonneg (bnn _)] using this
end
lemma tendsto_div : tendsto (λ n : ℕ, 1 / ((n : ℝ) + 1)) at_top (nhds 0) :=
suffices tendsto (λ n : ℕ, 1 / (↑(n + 1) : ℝ)) at_top (nhds 0), by simpa,
tendsto_comp_succ_at_top_iff.2 tendsto_one_div_at_top_nhds_0_nat
/--The approximating sequence is indeed Cauchy-/
lemma seq_of_cau_filter_is_cauchy :
cauchy_seq (seq_of_cau_filter hf) :=
cauchy_seq_of_dist_tendsto_0 (@seq_of_cau_filter_is_cauchy' _ _ _ hf) tendsto_div
/--
If the approximating Cauchy sequence is converging, to a limit `y`, then the
original Cauchy filter `f` is also converging, to the same limit.
Given `t1` in the filter `f` and `t2` a neighborhood of `y`, it suffices to show that `t1 ∩ t2` is nonempty.
Pick `ε` so that the ε-ball around `y` is contained in `t2`.
Pick `n` with `1/n < ε/2`, and `n2` such that `dist(seq n2, y) < ε/2`. Let `N = max(n, n2)`.
We defined `seq` by looking at a decreasing sequence of sets of `f` with shrinking radius.
The Nth one has radius `< 1/N < ε/2`. This set is in `f`, so we can find an element `x` that's
also in `t1`.
`dist(x, seq N) < ε/2` since `seq N` is in this set, and `dist (seq N, y) < ε/2`,
so `x` is in the ε-ball around `y`, and thus in `t2`.
-/
lemma le_nhds_cau_filter_lim {y : β} (H : tendsto (seq_of_cau_filter hf) at_top (nhds y)) :
f ≤ nhds y :=
begin
apply (le_nhds_iff_adhp_of_cauchy hf).2,
apply forall_sets_neq_empty_iff_neq_bot.1,
intros s hs,
simp at hs,
rcases hs with ⟨t1, ht1, t2, ht2, ht1t2⟩,
apply ne_empty_iff_exists_mem.2,
rcases mem_nhds_iff_metric.1 ht2 with ⟨ε, hε, ht2'⟩,
cases cauchy_of_metric.1 hf with hfb _,
have : ε / 2 > 0, from div_pos hε (by norm_num),
have : ∃ n : ℕ, 1 / (↑n + 1) < ε / 2, from exists_nat_one_div_lt this,
cases this with n hnε,
cases (tendsto_at_top_metric _).1 H _ this with n2 hn2,
let N := max n n2,
have hNε : 1 / (↑N+1) < ε / 2,
{ apply lt_of_le_of_lt _ hnε,
apply one_div_le_one_div_of_le,
{ exact add_pos_of_nonneg_of_pos (nat.cast_nonneg _) zero_lt_one },
{ apply add_le_add_right, simp [le_max_left] }},
have ht1sn : t1 ∩ set_seq_of_cau_filter hf N ∈ f.sets,
from inter_mem_sets ht1 (set_seq_of_cau_filter_mem_sets hf _),
have hts1n_ne : t1 ∩ set_seq_of_cau_filter hf N ≠ ∅,
from forall_sets_neq_empty_iff_neq_bot.2 hfb _ ht1sn,
cases exists_mem_of_ne_empty hts1n_ne with x hx,
have hdist1 := set_seq_of_cau_filter_spec hf _ hx.2 (seq_of_cau_filter_mem_set_seq hf N),
have hdist2 := hn2 N (le_max_right _ _),
replace hdist1 := lt_trans hdist1 hNε,
rw [dist_comm] at hdist2,
have hdist : dist x y < ε, from calc
dist x y ≤ dist x (seq_of_cau_filter hf N) + dist y (seq_of_cau_filter hf N) : dist_triangle_right _ _ _
... < ε/2 + ε/2 : add_lt_add hdist1 hdist2
... = ε : add_halves _,
have hxt2 : x ∈ t2, from ht2' hdist,
existsi x,
apply ht1t2,
exact mem_inter hx.left hxt2
end
end
end sequentially_complete
/--A metric space in which every Cauchy sequence converges is complete-/
theorem complete_of_cauchy_seq_tendsto {α : Type u} [metric_space α]
(H : ∀(u : ℕ → α), cauchy_seq u → ∃x, tendsto u at_top (nhds x)) :
complete_space α :=
⟨begin
/-Consider a Cauchy filter `f`-/
intros f hf,
/-Introduce a sequence `u` approximating the filter `f`-/
let u := sequentially_complete.seq_of_cau_filter hf,
/-It is Cauchy-/
have : cauchy_seq u := sequentially_complete.seq_of_cau_filter_is_cauchy hf,
/-Therefore, it converges by assumption. Let `x` be its limit-/
rcases H u this with ⟨x, hx⟩,
/-The original filter also converges to `x`-/
exact ⟨x, sequentially_complete.le_nhds_cau_filter_lim hf hx⟩
end⟩
section
/-Now, we will apply these results to `cau_seq`, i.e., "Cauchy sequences" defined by a multiplicative
absolute value on normed fields-/
lemma tendsto_limit [normed_ring β] [hn : is_absolute_value (norm : β → ℝ)]
(f : cau_seq β norm) [cau_seq.is_complete β norm] :
tendsto f at_top (nhds f.lim) :=
tendsto_nhds
begin
intros s lfs os,
suffices : ∃ (a : ℕ), ∀ (b : ℕ), b ≥ a → f b ∈ s, by simpa using this,
rcases is_open_metric.1 os _ lfs with ⟨ε, ⟨hε, hεs⟩⟩,
cases setoid.symm (cau_seq.equiv_lim f) _ hε with N hN,
existsi N,
intros b hb,
apply hεs,
dsimp [ball], rw [dist_comm, dist_eq_norm],
solve_by_elim
end
variables [normed_field β]
/-
This section shows that if we have a uniform space generated by an absolute value, topological
completeness and Cauchy sequence completeness coincide. The problem is that there isn't
a good notion of "uniform space generated by an absolute value", so right now this is
specific to norm. Furthermore, norm only instantiates is_absolute_value on normed_field.
This needs to be fixed, since it prevents showing that ℤ_[hp] is complete
-/
instance normed_field.is_absolute_value : is_absolute_value (norm : β → ℝ) :=
{ abv_nonneg := norm_nonneg,
abv_eq_zero := norm_eq_zero,
abv_add := norm_triangle,
abv_mul := normed_field.norm_mul }
lemma cauchy_of_filter_cauchy (f : ℕ → β) (hf : cauchy_seq f) :
is_cau_seq norm f :=
begin
cases cauchy_iff.1 hf with hf1 hf2,
intros ε hε,
rcases hf2 {x | dist x.1 x.2 < ε} (dist_mem_uniformity hε) with ⟨t, ⟨ht, htsub⟩⟩,
simp at ht, cases ht with N hN,
existsi N,
intros j hj,
rw ←dist_eq_norm,
apply @htsub (f j, f N),
apply set.mk_mem_prod; solve_by_elim [le_refl]
end
lemma filter_cauchy_of_cauchy (f : cau_seq β norm) : cauchy_seq f :=
begin
apply cauchy_iff.2,
split,
{ exact map_ne_bot at_top_ne_bot },
{ intros s hs,
rcases mem_uniformity_dist.1 hs with ⟨ε, ⟨hε, hεs⟩⟩,
cases cau_seq.cauchy₂ f hε with N hN,
existsi {n | n ≥ N}.image f,
simp, split,
{ existsi N, intros b hb, existsi b, simp [hb] },
{ rintros ⟨a, b⟩ ⟨⟨a', ⟨ha'1, ha'2⟩⟩, ⟨b', ⟨hb'1, hb'2⟩⟩⟩,
dsimp at ha'1 ha'2 hb'1 hb'2,
rw [←ha'2, ←hb'2],
apply hεs,
rw dist_eq_norm,
apply hN; assumption }},
{ apply_instance }
end
/--In a normed field, `cau_seq` coincides with the usual notion of Cauchy sequences-/
lemma cau_seq_iff_cauchy_seq {α : Type u} [normed_field α] {u : ℕ → α} :
is_cau_seq norm u ↔ cauchy_seq u :=
⟨λh, filter_cauchy_of_cauchy ⟨u, h⟩,
λh, cauchy_of_filter_cauchy u h⟩
/--A complete normed field is complete as a metric space, as Cauchy sequences converge by
assumption and this suffices to characterize completeness.-/
instance complete_space_of_cau_seq_complete [cau_seq.is_complete β norm] : complete_space β :=
begin
apply complete_of_cauchy_seq_tendsto,
assume u hu,
have C : is_cau_seq norm u := cau_seq_iff_cauchy_seq.2 hu,
existsi cau_seq.lim ⟨u, C⟩,
rw tendsto_at_top_metric,
assume ε εpos,
cases (cau_seq.equiv_lim ⟨u, C⟩) _ εpos with N hN,
existsi N,
simpa [dist_eq_norm] using hN
end
end
|
07cdd249145e9a34b0d8f409b0ab2c660c204244 | 618003631150032a5676f229d13a079ac875ff77 | /src/linear_algebra/sesquilinear_form.lean | eb2843db348599933a96bcc78d986c7b4c506d10 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 8,680 | lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Andreas Swerdlow
-/
import algebra.module
import ring_theory.maps
/-!
# Sesquilinear form
This file defines a sesquilinear form over a module. The definition requires a ring antiautomorphism
on the scalar ring, which comes from the file ring_theory.involution. Basic ideas such as
orthogonality are also introduced.
A sesquilinear form on an `R`-module `M`, is a function from `M × M` to `R, that is linear in the
first argument and antilinear in the second, with respect to an antiautomorphism on `R` (an
antiisomorphism from `R` to `R`).
## Notations
Given any term `S` of type `sesq_form`, due to a coercion, can use the notation `S x y` to
refer to the function field, ie. `S x y = S.sesq x y`.
## References
* <https://en.wikipedia.org/wiki/Sesquilinear_form#Over_arbitrary_rings>
## Tags
Sesquilinear form,
-/
open ring_anti_equiv
universes u v
/-- A sesquilinear form over a module -/
structure sesq_form (R : Type u) (M : Type v) [ring R] (I : ring_anti_equiv R R) [add_comm_group M]
[module R M] :=
(sesq : M → M → R)
(sesq_add_left : ∀ (x y z : M), sesq (x + y) z = sesq x z + sesq y z)
(sesq_smul_left : ∀ (a : R) (x y : M), sesq (a • x) y = a * (sesq x y))
(sesq_add_right : ∀ (x y z : M), sesq x (y + z) = sesq x y + sesq x z)
(sesq_smul_right : ∀ (a : R) (x y : M), sesq x (a • y) = (I a) * (sesq x y))
namespace sesq_form
section general_ring
variables {R : Type u} {M : Type v} [ring R] [add_comm_group M] [module R M]
{I : ring_anti_equiv R R} {S : sesq_form R M I}
instance : has_coe_to_fun (sesq_form R M I) :=
⟨_, λ S, S.sesq⟩
lemma add_left (x y z : M) : S (x + y) z = S x z + S y z := sesq_add_left S x y z
lemma smul_left (a : R) (x y : M) : S (a • x) y = a * (S x y) := sesq_smul_left S a x y
lemma add_right (x y z : M) : S x (y + z) = S x y + S x z := sesq_add_right S x y z
lemma smul_right (a : R) (x y : M) : S x (a • y) = (I a) * (S x y) := sesq_smul_right S a x y
lemma zero_left (x : M) :
S 0 x = 0 := by {rw [←@zero_smul R _ _ _ _ (0 : M), smul_left, zero_mul]}
lemma zero_right (x : M) :
S x 0 = 0 := by rw [←@zero_smul _ _ _ _ _ (0 : M), smul_right, map_zero, ring.zero_mul]
lemma neg_left (x y : M) :
S (-x) y = -(S x y) := by rw [←@neg_one_smul R _ _, smul_left, neg_one_mul]
lemma neg_right (x y : M) :
S x (-y) = -(S x y) := by rw [←@neg_one_smul R _ _, smul_right, map_neg_one, neg_one_mul]
lemma sub_left (x y z : M) :
S (x - y) z = S x z - S y z := by rw [sub_eq_add_neg, add_left, neg_left]; refl
lemma sub_right (x y z : M) :
S x (y - z) = S x y - S x z := by rw [sub_eq_add_neg, add_right, neg_right]; refl
variable {D : sesq_form R M I}
@[ext] lemma ext (H : ∀ (x y : M), S x y = D x y) : S = D :=
by {cases S, cases D, congr, funext, exact H _ _}
instance : add_comm_group (sesq_form R M I) :=
{ add := λ S D, { sesq := λ x y, S x y + D x y,
sesq_add_left := λ x y z, by {rw add_left, rw add_left, ac_refl},
sesq_smul_left := λ a x y, by {rw [smul_left, smul_left, mul_add]},
sesq_add_right := λ x y z, by {rw add_right, rw add_right, ac_refl},
sesq_smul_right := λ a x y, by {rw [smul_right, smul_right, mul_add]} },
add_assoc := by {intros, ext,
unfold coe_fn has_coe_to_fun.coe sesq coe_fn has_coe_to_fun.coe sesq, rw add_assoc},
zero := { sesq := λ x y, 0,
sesq_add_left := λ x y z, (add_zero 0).symm,
sesq_smul_left := λ a x y, (mul_zero a).symm,
sesq_add_right := λ x y z, (zero_add 0).symm,
sesq_smul_right := λ a x y, (mul_zero (I a)).symm },
zero_add := by {intros, ext, unfold coe_fn has_coe_to_fun.coe sesq, rw zero_add},
add_zero := by {intros, ext, unfold coe_fn has_coe_to_fun.coe sesq, rw add_zero},
neg := λ S, { sesq := λ x y, - (S.1 x y),
sesq_add_left := λ x y z, by rw [sesq_add_left, neg_add],
sesq_smul_left := λ a x y, by rw [sesq_smul_left, mul_neg_eq_neg_mul_symm],
sesq_add_right := λ x y z, by rw [sesq_add_right, neg_add],
sesq_smul_right := λ a x y, by rw [sesq_smul_right, mul_neg_eq_neg_mul_symm] },
add_left_neg := by {intros, ext, unfold coe_fn has_coe_to_fun.coe sesq, rw neg_add_self},
add_comm := by {intros, ext, unfold coe_fn has_coe_to_fun.coe sesq, rw add_comm} }
instance : inhabited (sesq_form R M I) := ⟨0⟩
/-- The proposition that two elements of a sesquilinear form space are orthogonal -/
def is_ortho (S : sesq_form R M I) (x y : M) : Prop :=
S x y = 0
lemma ortho_zero (x : M) :
is_ortho S (0 : M) x := zero_left x
end general_ring
section comm_ring
variables {R : Type*} [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
{J : ring_anti_equiv R R} (F : sesq_form R M J) (f : M → M)
instance to_module : module R (sesq_form R M J) :=
{ smul := λ c S,
{ sesq := λ x y, c * S x y,
sesq_add_left := λ x y z, by {unfold coe_fn has_coe_to_fun.coe sesq,
rw [sesq_add_left, left_distrib]},
sesq_smul_left := λ a x y, by {unfold coe_fn has_coe_to_fun.coe sesq,
rw [sesq_smul_left, ←mul_assoc, mul_comm c, mul_assoc]},
sesq_add_right := λ x y z, by {unfold coe_fn has_coe_to_fun.coe sesq,
rw [sesq_add_right, left_distrib]},
sesq_smul_right := λ a x y, by {unfold coe_fn has_coe_to_fun.coe sesq,
rw [sesq_smul_right, ←mul_assoc, mul_comm c, mul_assoc], refl} },
smul_add := λ c S D, by {ext, unfold coe_fn has_coe_to_fun.coe sesq, rw left_distrib},
add_smul := λ c S D, by {ext, unfold coe_fn has_coe_to_fun.coe sesq, rw right_distrib},
mul_smul := λ a c D, by {ext, unfold coe_fn has_coe_to_fun.coe sesq, rw mul_assoc},
one_smul := λ S, by {ext, unfold coe_fn has_coe_to_fun.coe sesq, rw one_mul},
zero_smul := λ S, by {ext, unfold coe_fn has_coe_to_fun.coe sesq, rw zero_mul},
smul_zero := λ S, by {ext, unfold coe_fn has_coe_to_fun.coe sesq, rw mul_zero} }
end comm_ring
section domain
variables {R : Type*} [domain R]
{M : Type v} [add_comm_group M] [module R M]
{K : ring_anti_equiv R R} {G : sesq_form R M K}
theorem ortho_smul_left {x y : M} {a : R} (ha : a ≠ 0) :
(is_ortho G x y) ↔ (is_ortho G (a • x) y) :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_left, H, ring.mul_zero] },
{ rw [smul_left, mul_eq_zero] at H,
cases H,
{ trivial },
{ exact H }}
end
theorem ortho_smul_right {x y : M} {a : R} (ha : a ≠ 0) :
(is_ortho G x y) ↔ (is_ortho G x (a • y)) :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_right, H, ring.mul_zero] },
{ rw [smul_right, mul_eq_zero] at H,
cases H,
{ rw map_zero_iff at H, trivial },
{ exact H }}
end
end domain
end sesq_form
namespace refl_sesq_form
open refl_sesq_form sesq_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {I : ring_anti_equiv R R}
{S : sesq_form R M I}
/-- The proposition that a sesquilinear form is reflexive -/
def is_refl (S : sesq_form R M I) : Prop := ∀ (x y : M), S x y = 0 → S y x = 0
variable (H : is_refl S)
lemma eq_zero : ∀ {x y : M}, S x y = 0 → S y x = 0 := λ x y, H x y
lemma ortho_sym {x y : M} :
is_ortho S x y ↔ is_ortho S y x := ⟨eq_zero H, eq_zero H⟩
end refl_sesq_form
namespace sym_sesq_form
open sym_sesq_form sesq_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {I : ring_anti_equiv R R}
{S : sesq_form R M I}
/-- The proposition that a sesquilinear form is symmetric -/
def is_sym (S : sesq_form R M I) : Prop := ∀ (x y : M), I (S x y) = S y x
variable (H : is_sym S)
include H
lemma sym (x y : M) : I (S x y) = S y x := H x y
lemma is_refl : refl_sesq_form.is_refl S := λ x y H1, by rw [←H, map_zero_iff, H1]
lemma ortho_sym {x y : M} :
is_ortho S x y ↔ is_ortho S y x := refl_sesq_form.ortho_sym (is_refl H)
end sym_sesq_form
namespace alt_sesq_form
open alt_sesq_form sesq_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {I : ring_anti_equiv R R}
{S : sesq_form R M I}
/-- The proposition that a sesquilinear form is alternating -/
def is_alt (S : sesq_form R M I) : Prop := ∀ (x : M), S x x = 0
variable (H : is_alt S)
include H
lemma self_eq_zero (x : M) : S x x = 0 := H x
lemma neg (x y : M) :
- S x y = S y x :=
begin
have H1 : S (x + y) (x + y) = 0,
{ exact self_eq_zero H (x + y) },
rw [add_left, add_right, add_right,
self_eq_zero H, self_eq_zero H, ring.zero_add,
ring.add_zero, add_eq_zero_iff_neg_eq] at H1,
exact H1,
end
end alt_sesq_form
|
3b4b39cbbe71eb8491bec7238fd9f0e0904e1c9a | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/data/set/intervals/disjoint.lean | 07d45554249213033de3403315e1fe30bc2368e9 | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 1,391 | lean | /-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yury Kudryashov
-/
import data.set.intervals.basic data.set.lattice
/-! # Extra lemmas about intervals
This file contains lemmas about intervals that cannot be included into `data.set.intervals.basic`
because this would create an `import` cycle. Namely, lemmas in this file can use definitions
from `data.set.lattice`, including `disjoint`.
-/
universe u
variables {α : Type u}
open lattice
namespace set
section decidable_linear_order
variables [decidable_linear_order α] {a₁ a₂ b₁ b₂ : α}
lemma Ico_disjoint_Ico : disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ :=
by simp only [set.disjoint_iff, subset_empty_iff, Ico_inter_Ico, Ico_eq_empty_iff,
inf_eq_min, sup_eq_max]
/-- If two half-open intervals are disjoint and the endpoint of one lies in the other,
then it must be equal to the endpoint of the other. -/
lemma eq_of_Ico_disjoint {x₁ x₂ y₁ y₂ : α}
(h : disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂) (h2 : x₂ ∈ Ico y₁ y₂) :
y₁ = x₂ :=
begin
rw [Ico_disjoint_Ico, min_eq_left (le_of_lt h2.2), le_max_iff] at h,
apply le_antisymm h2.1,
exact h.elim (λ h, absurd hx (not_lt_of_le h)) id
end
end decidable_linear_order
end set
|
e5c03f0dc0e8380bdd39252e0013cb32216476e8 | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /tests/lean/run/lean3_zulip_issues_1.lean | 422a068b5cb418f768fd6f50d52e4a2076f52c5f | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 1,317 | lean | example : Prop := ∀ n, (n:Nat) + n = n.succ
example : Prop := ∀ n, n.succ = (n:Nat) + n
example : Prop := ∀ n, (n:Nat) + n.succ = n
example : Prop := ∀ n, n.succ + (n:Nat) = n
example : Prop := ∀ n, (n.succ:Nat) + n = n
example : Prop := ∀ n, (n:Nat).succ + n = n
def fib: Nat → Nat
| 0 => 0
| 1 => 1
| n + 2 => fib n + fib (n + 1)
theorem fib50Eq : fib 50 = 12586269025 :=
rfl
inductive type : Type
| A : type
| B : type
inductive val : type → Type
| cA : val type.A
| cB : val type.B
inductive wrap : Type
| val : ∀ {t : type}, (val t) → wrap
def f : wrap → Nat
| wrap.val val.cA => 1
| _ => 1
example (a : Nat) : True := by
have ∀ n, n ≥ 0 → a ≤ a from fun _ _ => Nat.leRefl ..
exact True.intro
example (ᾰ : Nat) : True := by
have ∀ n, n ≥ 0 → ᾰ ≤ ᾰ from fun _ _ => Nat.leRefl ..
exact True.intro
inductive Vec.{u} (α : Type u) : Nat → Type u
| nil : Vec α 0
| cons : α → {n : Nat} → Vec α n → Vec α (Nat.succ n) -- TODO: investigate why +1 doesn't work here
constant Vars : Type
structure Lang :=
(funcs : Nat → Type)
(consts : Type)
inductive Term (L : Lang) : Type
| const_term : L.consts → Term L
| var_term : Vars → Term L
| func_term (n : Nat) (f : L.funcs n) (v : Vec (Term L) n) : Term L
|
2fc2b47b621465c0bfc67511024effbf9fcc8985 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/analysis/convex/exposed.lean | 5a08c049de69624d41d5fb937790a55b2138f985 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 9,328 | lean | /-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import analysis.convex.extreme
import analysis.convex.function
import analysis.normed_space.ordered
/-!
# Exposed sets
This file defines exposed sets and exposed points for sets in a real vector space.
An exposed subset of `A` is a subset of `A` that is the set of all maximal points of a functional
(a continuous linear map `E → 𝕜`) over `A`. By convention, `∅` is an exposed subset of all sets.
This allows for better functioriality of the definition (the intersection of two exposed subsets is
exposed, faces of a polytope form a bounded lattice).
This is an analytic notion of "being on the side of". It is stronger than being extreme (see
`is_exposed.is_extreme`), but weaker (for exposed points) than being a vertex.
An exposed set of `A` is sometimes called a "face of `A`", but we decided to reserve this
terminology to the more specific notion of a face of a polytope (sometimes hopefully soon out
on mathlib!).
## Main declarations
* `is_exposed 𝕜 A B`: States that `B` is an exposed set of `A` (in the literature, `A` is often
implicit).
* `is_exposed.is_extreme`: An exposed set is also extreme.
## References
See chapter 8 of [Barry Simon, *Convexity*][simon2011]
## TODO
Define intrinsic frontier/interior and prove the lemmas related to exposed sets and points.
Generalise to Locally Convex Topological Vector Spaces™
More not-yet-PRed stuff is available on the branch `sperner_again`.
-/
open_locale classical affine big_operators
open set
variables (𝕜 : Type*) {E : Type*} [normed_linear_ordered_field 𝕜] [normed_group E]
[normed_space 𝕜 E] {l : E →L[𝕜] 𝕜} {A B C : set E} {X : finset E} {x : E}
/-- A set `B` is exposed with respect to `A` iff it maximizes some functional over `A` (and contains
all points maximizing it). Written `is_exposed 𝕜 A B`. -/
def is_exposed (A B : set E) : Prop :=
B.nonempty → ∃ l : E →L[𝕜] 𝕜, B = {x ∈ A | ∀ y ∈ A, l y ≤ l x}
variables {𝕜}
/-- A useful way to build exposed sets from intersecting `A` with halfspaces (modelled by an
inequality with a functional). -/
def continuous_linear_map.to_exposed (l : E →L[𝕜] 𝕜) (A : set E) : set E :=
{x ∈ A | ∀ y ∈ A, l y ≤ l x}
lemma continuous_linear_map.to_exposed.is_exposed : is_exposed 𝕜 A (l.to_exposed A) := λ h, ⟨l, rfl⟩
lemma is_exposed_empty : is_exposed 𝕜 A ∅ :=
λ ⟨x, hx⟩, by { exfalso, exact hx }
namespace is_exposed
protected lemma subset (hAB : is_exposed 𝕜 A B) : B ⊆ A :=
begin
rintro x hx,
obtain ⟨_, rfl⟩ := hAB ⟨x, hx⟩,
exact hx.1,
end
@[refl] protected lemma refl (A : set E) : is_exposed 𝕜 A A :=
λ ⟨w, hw⟩, ⟨0, subset.antisymm (λ x hx, ⟨hx, λ y hy, by exact le_refl 0⟩) (λ x hx, hx.1)⟩
protected lemma antisymm (hB : is_exposed 𝕜 A B) (hA : is_exposed 𝕜 B A) :
A = B :=
hA.subset.antisymm hB.subset
/- `is_exposed` is *not* transitive: Consider a (topologically) open cube with vertices
`A₀₀₀, ..., A₁₁₁` and add to it the triangle `A₀₀₀A₀₀₁A₀₁₀`. Then `A₀₀₁A₀₁₀` is an exposed subset
of `A₀₀₀A₀₀₁A₀₁₀` which is an exposed subset of the cube, but `A₀₀₁A₀₁₀` is not itself an exposed
subset of the cube. -/
protected lemma mono (hC : is_exposed 𝕜 A C) (hBA : B ⊆ A) (hCB : C ⊆ B) :
is_exposed 𝕜 B C :=
begin
rintro ⟨w, hw⟩,
obtain ⟨l, rfl⟩ := hC ⟨w, hw⟩,
exact ⟨l, subset.antisymm (λ x hx, ⟨hCB hx, λ y hy, hx.2 y (hBA hy)⟩)
(λ x hx, ⟨hBA hx.1, λ y hy, (hw.2 y hy).trans (hx.2 w (hCB hw))⟩)⟩,
end
/-- If `B` is an exposed subset of `A`, then `B` is the intersection of `A` with some closed
halfspace. The converse is *not* true. It would require that the corresponding open halfspace
doesn't intersect `A`. -/
lemma eq_inter_halfspace (hAB : is_exposed 𝕜 A B) :
∃ l : E →L[𝕜] 𝕜, ∃ a, B = {x ∈ A | a ≤ l x} :=
begin
obtain hB | hB := B.eq_empty_or_nonempty,
{ refine ⟨0, 1, _⟩,
rw [hB, eq_comm, eq_empty_iff_forall_not_mem],
rintro x ⟨-, h⟩,
rw continuous_linear_map.zero_apply at h,
linarith },
obtain ⟨l, rfl⟩ := hAB hB,
obtain ⟨w, hw⟩ := hB,
exact ⟨l, l w, subset.antisymm (λ x hx, ⟨hx.1, hx.2 w hw.1⟩)
(λ x hx, ⟨hx.1, λ y hy, (hw.2 y hy).trans hx.2⟩)⟩,
end
protected lemma inter (hB : is_exposed 𝕜 A B) (hC : is_exposed 𝕜 A C) :
is_exposed 𝕜 A (B ∩ C) :=
begin
rintro ⟨w, hwB, hwC⟩,
obtain ⟨l₁, rfl⟩ := hB ⟨w, hwB⟩,
obtain ⟨l₂, rfl⟩ := hC ⟨w, hwC⟩,
refine ⟨l₁ + l₂, subset.antisymm _ _⟩,
{ rintro x ⟨⟨hxA, hxB⟩, ⟨-, hxC⟩⟩,
exact ⟨hxA, λ z hz, add_le_add (hxB z hz) (hxC z hz)⟩ },
rintro x ⟨hxA, hx⟩,
refine ⟨⟨hxA, λ y hy, _⟩, hxA, λ y hy, _⟩,
{ exact (add_le_add_iff_right (l₂ x)).1 ((add_le_add (hwB.2 y hy) (hwC.2 x hxA)).trans
(hx w hwB.1)) },
{ exact (add_le_add_iff_left (l₁ x)).1 (le_trans (add_le_add (hwB.2 x hxA) (hwC.2 y hy))
(hx w hwB.1)) }
end
lemma sInter {F : finset (set E)} (hF : F.nonempty)
(hAF : ∀ B ∈ F, is_exposed 𝕜 A B) :
is_exposed 𝕜 A (⋂₀ F) :=
begin
revert hF F,
refine finset.induction _ _,
{ rintro h,
exfalso,
exact empty_not_nonempty h },
rintro C F _ hF _ hCF,
rw [finset.coe_insert, sInter_insert],
obtain rfl | hFnemp := F.eq_empty_or_nonempty,
{ rw [finset.coe_empty, sInter_empty, inter_univ],
exact hCF C (finset.mem_singleton_self C) },
exact (hCF C (finset.mem_insert_self C F)).inter (hF hFnemp (λ B hB,
hCF B(finset.mem_insert_of_mem hB))),
end
lemma inter_left (hC : is_exposed 𝕜 A C) (hCB : C ⊆ B) :
is_exposed 𝕜 (A ∩ B) C :=
begin
rintro ⟨w, hw⟩,
obtain ⟨l, rfl⟩ := hC ⟨w, hw⟩,
exact ⟨l, subset.antisymm (λ x hx, ⟨⟨hx.1, hCB hx⟩, λ y hy, hx.2 y hy.1⟩)
(λ x ⟨⟨hxC, _⟩, hx⟩, ⟨hxC, λ y hy, (hw.2 y hy).trans (hx w ⟨hC.subset hw, hCB hw⟩)⟩)⟩,
end
lemma inter_right (hC : is_exposed 𝕜 B C) (hCA : C ⊆ A) :
is_exposed 𝕜 (A ∩ B) C :=
begin
rw inter_comm,
exact hC.inter_left hCA,
end
protected lemma is_extreme (hAB : is_exposed 𝕜 A B) :
is_extreme 𝕜 A B :=
begin
refine ⟨hAB.subset, λ x₁ hx₁A x₂ hx₂A x hxB hx, _⟩,
obtain ⟨l, rfl⟩ := hAB ⟨x, hxB⟩,
have hl : convex_on 𝕜 univ l := l.to_linear_map.convex_on convex_univ,
have hlx₁ := hxB.2 x₁ hx₁A,
have hlx₂ := hxB.2 x₂ hx₂A,
refine ⟨⟨hx₁A, λ y hy, _⟩, ⟨hx₂A, λ y hy, _⟩⟩,
{ rw hlx₁.antisymm (hl.le_left_of_right_le (mem_univ _) (mem_univ _) hx hlx₂),
exact hxB.2 y hy },
{ rw hlx₂.antisymm (hl.le_right_of_left_le (mem_univ _) (mem_univ _) hx hlx₁),
exact hxB.2 y hy }
end
protected lemma convex (hAB : is_exposed 𝕜 A B) (hA : convex 𝕜 A) :
convex 𝕜 B :=
begin
obtain rfl | hB := B.eq_empty_or_nonempty,
{ exact convex_empty },
obtain ⟨l, rfl⟩ := hAB hB,
exact λ x₁ x₂ hx₁ hx₂ a b ha hb hab, ⟨hA hx₁.1 hx₂.1 ha hb hab, λ y hy,
((l.to_linear_map.concave_on convex_univ).convex_ge _
⟨mem_univ _, hx₁.2 y hy⟩ ⟨mem_univ _, hx₂.2 y hy⟩ ha hb hab).2⟩,
end
protected lemma is_closed [order_closed_topology 𝕜] (hAB : is_exposed 𝕜 A B) (hA : is_closed A) :
is_closed B :=
begin
obtain ⟨l, a, rfl⟩ := hAB.eq_inter_halfspace,
exact hA.is_closed_le continuous_on_const l.continuous.continuous_on,
end
protected lemma is_compact [order_closed_topology 𝕜] (hAB : is_exposed 𝕜 A B) (hA : is_compact A) :
is_compact B :=
compact_of_is_closed_subset hA (hAB.is_closed hA.is_closed) hAB.subset
end is_exposed
variables (𝕜)
/-- A point is exposed with respect to `A` iff there exists an hyperplane whose intersection with
`A` is exactly that point. -/
def set.exposed_points (A : set E) :
set E :=
{x ∈ A | ∃ l : E →L[𝕜] 𝕜, ∀ y ∈ A, l y ≤ l x ∧ (l x ≤ l y → y = x)}
variables {𝕜}
lemma exposed_point_def :
x ∈ A.exposed_points 𝕜 ↔ x ∈ A ∧ ∃ l : E →L[𝕜] 𝕜, ∀ y ∈ A, l y ≤ l x ∧ (l x ≤ l y → y = x) :=
iff.rfl
lemma exposed_points_subset :
A.exposed_points 𝕜 ⊆ A :=
λ x hx, hx.1
@[simp] lemma exposed_points_empty :
(∅ : set E).exposed_points 𝕜 = ∅ :=
subset_empty_iff.1 exposed_points_subset
/-- Exposed points exactly correspond to exposed singletons. -/
lemma mem_exposed_points_iff_exposed_singleton :
x ∈ A.exposed_points 𝕜 ↔ is_exposed 𝕜 A {x} :=
begin
use λ ⟨hxA, l, hl⟩ h, ⟨l, eq.symm $ eq_singleton_iff_unique_mem.2 ⟨⟨hxA, λ y hy, (hl y hy).1⟩,
λ z hz, (hl z hz.1).2 (hz.2 x hxA)⟩⟩,
rintro h,
obtain ⟨l, hl⟩ := h ⟨x, mem_singleton _⟩,
rw [eq_comm, eq_singleton_iff_unique_mem] at hl,
exact ⟨hl.1.1, l, λ y hy, ⟨hl.1.2 y hy, λ hxy, hl.2 y ⟨hy, λ z hz, (hl.1.2 z hz).trans hxy⟩⟩⟩,
end
lemma exposed_points_subset_extreme_points :
A.exposed_points 𝕜 ⊆ A.extreme_points 𝕜 :=
λ x hx, mem_extreme_points_iff_extreme_singleton.2
(mem_exposed_points_iff_exposed_singleton.1 hx).is_extreme
|
0db76e9f1b69211920f621957bd4fe771f9428be | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/succ_pred/basic.lean | 6f0151b672335f05d6ee27b5eb1a534368c7c4cb | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 42,518 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import order.complete_lattice
import order.cover
import order.iterate
/-!
# Successor and predecessor
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is
the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples
include `ℕ`, `ℤ`, `ℕ+`, `fin n`, but also `enat`, the lexicographic order of a successor/predecessor
order...
## Typeclasses
* `succ_order`: Order equipped with a sensible successor function.
* `pred_order`: Order equipped with a sensible predecessor function.
* `is_succ_archimedean`: `succ_order` where `succ` iterated to an element gives all the greater
ones.
* `is_pred_archimedean`: `pred_order` where `pred` iterated to an element gives all the smaller
ones.
## Implementation notes
Maximal elements don't have a sensible successor. Thus the naïve typeclass
```lean
class naive_succ_order (α : Type*) [preorder α] :=
(succ : α → α)
(succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b)
(lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b)
```
can't apply to an `order_top` because plugging in `a = b = ⊤` into either of `succ_le_iff` and
`lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`).
The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a`
for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of
`max_of_succ_le`).
The stricter condition of every element having a sensible successor can be obtained through the
combination of `succ_order α` and `no_max_order α`.
## TODO
Is `galois_connection pred succ` always true? If not, we should introduce
```lean
class succ_pred_order (α : Type*) [preorder α] extends succ_order α, pred_order α :=
(pred_succ_gc : galois_connection (pred : α → α) succ)
```
`covby` should help here.
-/
open function order_dual set
variables {α : Type*}
/-- Order equipped with a sensible successor function. -/
@[ext] class succ_order (α : Type*) [preorder α] :=
(succ : α → α)
(le_succ : ∀ a, a ≤ succ a)
(max_of_succ_le {a} : succ a ≤ a → is_max a)
(succ_le_of_lt {a b} : a < b → succ a ≤ b)
(le_of_lt_succ {a b} : a < succ b → a ≤ b)
/-- Order equipped with a sensible predecessor function. -/
@[ext] class pred_order (α : Type*) [preorder α] :=
(pred : α → α)
(pred_le : ∀ a, pred a ≤ a)
(min_of_le_pred {a} : a ≤ pred a → is_min a)
(le_pred_of_lt {a b} : a < b → a ≤ pred b)
(le_of_pred_lt {a b} : pred a < b → a ≤ b)
instance [preorder α] [succ_order α] : pred_order αᵒᵈ :=
{ pred := to_dual ∘ succ_order.succ ∘ of_dual,
pred_le := succ_order.le_succ,
min_of_le_pred := λ _, succ_order.max_of_succ_le,
le_pred_of_lt := λ a b h, succ_order.succ_le_of_lt h,
le_of_pred_lt := λ a b, succ_order.le_of_lt_succ }
instance [preorder α] [pred_order α] : succ_order αᵒᵈ :=
{ succ := to_dual ∘ pred_order.pred ∘ of_dual,
le_succ := pred_order.pred_le,
max_of_succ_le := λ _, pred_order.min_of_le_pred,
succ_le_of_lt := λ a b h, pred_order.le_pred_of_lt h,
le_of_lt_succ := λ a b, pred_order.le_of_pred_lt }
section preorder
variables [preorder α]
/-- A constructor for `succ_order α` usable when `α` has no maximal element. -/
def succ_order.of_succ_le_iff_of_le_lt_succ (succ : α → α)
(hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (hle_of_lt_succ : ∀ {a b}, a < succ b → a ≤ b) :
succ_order α :=
{ succ := succ,
le_succ := λ a, (hsucc_le_iff.1 le_rfl).le,
max_of_succ_le := λ a ha, (lt_irrefl a $ hsucc_le_iff.1 ha).elim,
succ_le_of_lt := λ a b, hsucc_le_iff.2,
le_of_lt_succ := λ a b, hle_of_lt_succ }
/-- A constructor for `pred_order α` usable when `α` has no minimal element. -/
def pred_order.of_le_pred_iff_of_pred_le_pred (pred : α → α)
(hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) (hle_of_pred_lt : ∀ {a b}, pred a < b → a ≤ b) :
pred_order α :=
{ pred := pred,
pred_le := λ a, (hle_pred_iff.1 le_rfl).le,
min_of_le_pred := λ a ha, (lt_irrefl a $ hle_pred_iff.1 ha).elim,
le_pred_of_lt := λ a b, hle_pred_iff.2,
le_of_pred_lt := λ a b, hle_of_pred_lt }
end preorder
section linear_order
variables [linear_order α]
/-- A constructor for `succ_order α` for `α` a linear order. -/
@[simps] def succ_order.of_core (succ : α → α) (hn : ∀ {a}, ¬ is_max a → ∀ b, a < b ↔ succ a ≤ b)
(hm : ∀ a, is_max a → succ a = a) : succ_order α :=
{ succ := succ,
succ_le_of_lt := λ a b, classical.by_cases (λ h hab, (hm a h).symm ▸ hab.le) (λ h, (hn h b).mp),
le_succ := λ a, classical.by_cases (λ h, (hm a h).symm.le)
(λ h, le_of_lt $ by simpa using (hn h a).not),
le_of_lt_succ := λ a b hab, classical.by_cases (λ h, hm b h ▸ hab.le)
(λ h, by simpa [hab] using (hn h a).not),
max_of_succ_le := λ a, not_imp_not.mp $ λ h, by simpa using (hn h a).not }
/-- A constructor for `pred_order α` for `α` a linear order. -/
@[simps] def pred_order.of_core {α} [linear_order α] (pred : α → α)
(hn : ∀ {a}, ¬ is_min a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, is_min a → pred a = a) :
pred_order α :=
{ pred := pred,
le_pred_of_lt := λ a b, classical.by_cases (λ h hab, (hm b h).symm ▸ hab.le) (λ h, (hn h a).mpr),
pred_le := λ a, classical.by_cases (λ h, (hm a h).le)
(λ h, le_of_lt $ by simpa using (hn h a).not),
le_of_pred_lt := λ a b hab, classical.by_cases (λ h, hm a h ▸ hab.le)
(λ h, by simpa [hab] using (hn h b).not),
min_of_le_pred := λ a, not_imp_not.mp $ λ h, by simpa using (hn h a).not }
/-- A constructor for `succ_order α` usable when `α` is a linear order with no maximal element. -/
def succ_order.of_succ_le_iff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) :
succ_order α :=
{ succ := succ,
le_succ := λ a, (hsucc_le_iff.1 le_rfl).le,
max_of_succ_le := λ a ha, (lt_irrefl a $ hsucc_le_iff.1 ha).elim,
succ_le_of_lt := λ a b, hsucc_le_iff.2,
le_of_lt_succ := λ a b h, le_of_not_lt ((not_congr hsucc_le_iff).1 h.not_le) }
/-- A constructor for `pred_order α` usable when `α` is a linear order with no minimal element. -/
def pred_order.of_le_pred_iff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) :
pred_order α :=
{ pred := pred,
pred_le := λ a, (hle_pred_iff.1 le_rfl).le,
min_of_le_pred := λ a ha, (lt_irrefl a $ hle_pred_iff.1 ha).elim,
le_pred_of_lt := λ a b, hle_pred_iff.2,
le_of_pred_lt := λ a b h, le_of_not_lt ((not_congr hle_pred_iff).1 h.not_le) }
end linear_order
/-! ### Successor order -/
namespace order
section preorder
variables [preorder α] [succ_order α] {a b : α}
/-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater
than `a`. If `a` is maximal, then `succ a = a`. -/
def succ : α → α := succ_order.succ
lemma le_succ : ∀ a : α, a ≤ succ a := succ_order.le_succ
lemma max_of_succ_le {a : α} : succ a ≤ a → is_max a := succ_order.max_of_succ_le
lemma succ_le_of_lt {a b : α} : a < b → succ a ≤ b := succ_order.succ_le_of_lt
lemma le_of_lt_succ {a b : α} : a < succ b → a ≤ b := succ_order.le_of_lt_succ
@[simp] lemma succ_le_iff_is_max : succ a ≤ a ↔ is_max a := ⟨max_of_succ_le, λ h, h $ le_succ _⟩
@[simp] lemma lt_succ_iff_not_is_max : a < succ a ↔ ¬ is_max a :=
⟨not_is_max_of_lt, λ ha, (le_succ a).lt_of_not_le $ λ h, ha $ max_of_succ_le h⟩
alias lt_succ_iff_not_is_max ↔ _ lt_succ_of_not_is_max
lemma wcovby_succ (a : α) : a ⩿ succ a :=
⟨le_succ a, λ b hb, (succ_le_of_lt hb).not_lt⟩
lemma covby_succ_of_not_is_max (h : ¬ is_max a) : a ⋖ succ a :=
(wcovby_succ a).covby_of_lt $ lt_succ_of_not_is_max h
lemma lt_succ_iff_of_not_is_max (ha : ¬ is_max a) : b < succ a ↔ b ≤ a :=
⟨le_of_lt_succ, λ h, h.trans_lt $ lt_succ_of_not_is_max ha⟩
lemma succ_le_iff_of_not_is_max (ha : ¬ is_max a) : succ a ≤ b ↔ a < b :=
⟨(lt_succ_of_not_is_max ha).trans_le, succ_le_of_lt⟩
lemma succ_lt_succ_iff_of_not_is_max (ha : ¬ is_max a) (hb : ¬ is_max b) :
succ a < succ b ↔ a < b :=
by rw [lt_succ_iff_of_not_is_max hb, succ_le_iff_of_not_is_max ha]
lemma succ_le_succ_iff_of_not_is_max (ha : ¬ is_max a) (hb : ¬ is_max b) :
succ a ≤ succ b ↔ a ≤ b :=
by rw [succ_le_iff_of_not_is_max ha, lt_succ_iff_of_not_is_max hb]
@[simp, mono] lemma succ_le_succ (h : a ≤ b) : succ a ≤ succ b :=
begin
by_cases hb : is_max b,
{ by_cases hba : b ≤ a,
{ exact (hb $ hba.trans $ le_succ _).trans (le_succ _) },
{ exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le $ le_succ b) } },
{ rwa [succ_le_iff_of_not_is_max (λ ha, hb $ ha.mono h), lt_succ_iff_of_not_is_max hb] }
end
lemma succ_mono : monotone (succ : α → α) := λ a b, succ_le_succ
lemma le_succ_iterate (k : ℕ) (x : α) : x ≤ (succ^[k] x) :=
begin
conv_lhs { rw (by simp only [function.iterate_id, id.def] : x = (id^[k] x)) },
exact monotone.le_iterate_of_le succ_mono le_succ k x,
end
lemma is_max_iterate_succ_of_eq_of_lt {n m : ℕ}
(h_eq : (succ^[n] a) = (succ^[m] a)) (h_lt : n < m) :
is_max (succ^[n] a) :=
begin
refine max_of_succ_le (le_trans _ h_eq.symm.le),
have : succ (succ^[n] a) = (succ^[n + 1] a), by rw function.iterate_succ',
rw this,
have h_le : n + 1 ≤ m := nat.succ_le_of_lt h_lt,
exact monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le,
end
lemma is_max_iterate_succ_of_eq_of_ne {n m : ℕ}
(h_eq : (succ^[n] a) = (succ^[m] a)) (h_ne : n ≠ m) :
is_max (succ^[n] a) :=
begin
cases le_total n m,
{ exact is_max_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne), },
{ rw h_eq,
exact is_max_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm), },
end
lemma Iio_succ_of_not_is_max (ha : ¬ is_max a) : Iio (succ a) = Iic a :=
set.ext $ λ x, lt_succ_iff_of_not_is_max ha
lemma Ici_succ_of_not_is_max (ha : ¬ is_max a) : Ici (succ a) = Ioi a :=
set.ext $ λ x, succ_le_iff_of_not_is_max ha
lemma Ico_succ_right_of_not_is_max (hb : ¬ is_max b) : Ico a (succ b) = Icc a b :=
by rw [←Ici_inter_Iio, Iio_succ_of_not_is_max hb, Ici_inter_Iic]
lemma Ioo_succ_right_of_not_is_max (hb : ¬ is_max b) : Ioo a (succ b) = Ioc a b :=
by rw [←Ioi_inter_Iio, Iio_succ_of_not_is_max hb, Ioi_inter_Iic]
lemma Icc_succ_left_of_not_is_max (ha : ¬ is_max a) : Icc (succ a) b = Ioc a b :=
by rw [←Ici_inter_Iic, Ici_succ_of_not_is_max ha, Ioi_inter_Iic]
lemma Ico_succ_left_of_not_is_max (ha : ¬ is_max a) : Ico (succ a) b = Ioo a b :=
by rw [←Ici_inter_Iio, Ici_succ_of_not_is_max ha, Ioi_inter_Iio]
section no_max_order
variables [no_max_order α]
lemma lt_succ (a : α) : a < succ a := lt_succ_of_not_is_max $ not_is_max a
@[simp] lemma lt_succ_iff : a < succ b ↔ a ≤ b := lt_succ_iff_of_not_is_max $ not_is_max b
@[simp] lemma succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_is_max $ not_is_max a
lemma succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp
lemma succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp
alias succ_le_succ_iff ↔ le_of_succ_le_succ _
alias succ_lt_succ_iff ↔ lt_of_succ_lt_succ succ_lt_succ
lemma succ_strict_mono : strict_mono (succ : α → α) := λ a b, succ_lt_succ
lemma covby_succ (a : α) : a ⋖ succ a := covby_succ_of_not_is_max $ not_is_max a
@[simp] lemma Iio_succ (a : α) : Iio (succ a) = Iic a := Iio_succ_of_not_is_max $ not_is_max _
@[simp] lemma Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_is_max $ not_is_max _
@[simp] lemma Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b :=
Ico_succ_right_of_not_is_max $ not_is_max _
@[simp] lemma Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b :=
Ioo_succ_right_of_not_is_max $ not_is_max _
@[simp] lemma Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b :=
Icc_succ_left_of_not_is_max $ not_is_max _
@[simp] lemma Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b :=
Ico_succ_left_of_not_is_max $ not_is_max _
end no_max_order
end preorder
section partial_order
variables [partial_order α] [succ_order α] {a b : α}
@[simp] lemma succ_eq_iff_is_max : succ a = a ↔ is_max a :=
⟨λ h, max_of_succ_le h.le, λ h, h.eq_of_ge $ le_succ _⟩
alias succ_eq_iff_is_max ↔ _ _root_.is_max.succ_eq
lemma succ_eq_succ_iff_of_not_is_max (ha : ¬ is_max a) (hb : ¬ is_max b) :
succ a = succ b ↔ a = b :=
by rw [eq_iff_le_not_lt, eq_iff_le_not_lt,
succ_le_succ_iff_of_not_is_max ha hb, succ_lt_succ_iff_of_not_is_max ha hb]
lemma le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a :=
begin
refine ⟨λ h, or_iff_not_imp_left.2 $ λ hba : b ≠ a,
h.2.antisymm (succ_le_of_lt $ h.1.lt_of_ne $ hba.symm), _⟩,
rintro (rfl | rfl),
{ exact ⟨le_rfl, le_succ b⟩ },
{ exact ⟨le_succ a, le_rfl⟩ }
end
lemma _root_.covby.succ_eq (h : a ⋖ b) : succ a = b :=
(succ_le_of_lt h.lt).eq_of_not_lt $ λ h', h.2 (lt_succ_of_not_is_max h.lt.not_is_max) h'
lemma _root_.wcovby.le_succ (h : a ⩿ b) : b ≤ succ a :=
begin
obtain h | rfl := h.covby_or_eq,
{ exact h.succ_eq.ge },
{ exact le_succ _ }
end
lemma le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b :=
begin
by_cases hb : is_max b,
{ rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] },
{ rw [←lt_succ_iff_of_not_is_max hb, le_iff_eq_or_lt] }
end
lemma lt_succ_iff_eq_or_lt_of_not_is_max (hb : ¬ is_max b) : a < succ b ↔ a = b ∨ a < b :=
(lt_succ_iff_of_not_is_max hb).trans le_iff_eq_or_lt
lemma Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) := ext $ λ _, le_succ_iff_eq_or_le
lemma Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) :=
by simp_rw [←Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)]
lemma Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) :=
by simp_rw [←Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)]
lemma Iio_succ_eq_insert_of_not_is_max (h : ¬is_max a) : Iio (succ a) = insert a (Iio a) :=
ext $ λ _, lt_succ_iff_eq_or_lt_of_not_is_max h
lemma Ico_succ_right_eq_insert_of_not_is_max (h₁ : a ≤ b) (h₂ : ¬is_max b) :
Ico a (succ b) = insert b (Ico a b) :=
by simp_rw [←Iio_inter_Ici, Iio_succ_eq_insert_of_not_is_max h₂, insert_inter_of_mem (mem_Ici.2 h₁)]
lemma Ioo_succ_right_eq_insert_of_not_is_max (h₁ : a < b) (h₂ : ¬is_max b) :
Ioo a (succ b) = insert b (Ioo a b) :=
by simp_rw [←Iio_inter_Ioi, Iio_succ_eq_insert_of_not_is_max h₂, insert_inter_of_mem (mem_Ioi.2 h₁)]
section no_max_order
variables [no_max_order α]
@[simp] lemma succ_eq_succ_iff : succ a = succ b ↔ a = b :=
succ_eq_succ_iff_of_not_is_max (not_is_max a) (not_is_max b)
lemma succ_injective : injective (succ : α → α) := λ a b, succ_eq_succ_iff.1
lemma succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b := succ_injective.ne_iff
alias succ_ne_succ_iff ↔ _ succ_ne_succ
lemma lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b := lt_succ_iff.trans le_iff_eq_or_lt
lemma succ_eq_iff_covby : succ a = b ↔ a ⋖ b :=
⟨by { rintro rfl, exact covby_succ _ }, covby.succ_eq⟩
lemma Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) :=
Iio_succ_eq_insert_of_not_is_max $ not_is_max a
lemma Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) :=
Ico_succ_right_eq_insert_of_not_is_max h $ not_is_max b
lemma Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) :=
Ioo_succ_right_eq_insert_of_not_is_max h $ not_is_max b
end no_max_order
section order_top
variables [order_top α]
@[simp] lemma succ_top : succ (⊤ : α) = ⊤ := is_max_top.succ_eq
@[simp] lemma succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_is_max.trans is_max_iff_eq_top
@[simp] lemma lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ :=
lt_succ_iff_not_is_max.trans not_is_max_iff_ne_top
end order_top
section order_bot
variable [order_bot α]
@[simp] lemma lt_succ_bot_iff [no_max_order α] : a < succ ⊥ ↔ a = ⊥ :=
by rw [lt_succ_iff, le_bot_iff]
lemma le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ :=
by rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm]
variable [nontrivial α]
lemma bot_lt_succ (a : α) : ⊥ < succ a :=
(lt_succ_of_not_is_max not_is_max_bot).trans_le $ succ_mono bot_le
lemma succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne'
end order_bot
end partial_order
/-- There is at most one way to define the successors in a `partial_order`. -/
instance [partial_order α] : subsingleton (succ_order α) :=
⟨begin
introsI h₀ h₁,
ext a,
by_cases ha : is_max a,
{ exact (@is_max.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm },
{ exact @covby.succ_eq _ _ h₀ _ _ (covby_succ_of_not_is_max ha) }
end⟩
section complete_lattice
variables [complete_lattice α] [succ_order α]
lemma succ_eq_infi (a : α) : succ a = ⨅ b (h : a < b), b :=
begin
refine le_antisymm (le_infi (λ b, le_infi succ_le_of_lt)) _,
obtain rfl | ha := eq_or_ne a ⊤,
{ rw succ_top,
exact le_top },
exact infi₂_le _ (lt_succ_iff_ne_top.2 ha),
end
end complete_lattice
/-! ### Predecessor order -/
section preorder
variables [preorder α] [pred_order α] {a b : α}
/-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less
than `a`. If `a` is minimal, then `pred a = a`. -/
def pred : α → α := pred_order.pred
lemma pred_le : ∀ a : α, pred a ≤ a := pred_order.pred_le
lemma min_of_le_pred {a : α} : a ≤ pred a → is_min a := pred_order.min_of_le_pred
lemma le_pred_of_lt {a b : α} : a < b → a ≤ pred b := pred_order.le_pred_of_lt
lemma le_of_pred_lt {a b : α} : pred a < b → a ≤ b := pred_order.le_of_pred_lt
@[simp] lemma le_pred_iff_is_min : a ≤ pred a ↔ is_min a := ⟨min_of_le_pred, λ h, h $ pred_le _⟩
@[simp] lemma pred_lt_iff_not_is_min : pred a < a ↔ ¬ is_min a :=
⟨not_is_min_of_lt, λ ha, (pred_le a).lt_of_not_le $ λ h, ha $ min_of_le_pred h⟩
alias pred_lt_iff_not_is_min ↔ _ pred_lt_of_not_is_min
lemma pred_wcovby (a : α) : pred a ⩿ a :=
⟨pred_le a, λ b hb, (le_of_pred_lt hb).not_lt⟩
lemma pred_covby_of_not_is_min (h : ¬ is_min a) : pred a ⋖ a :=
(pred_wcovby a).covby_of_lt $ pred_lt_of_not_is_min h
lemma pred_lt_iff_of_not_is_min (ha : ¬ is_min a) : pred a < b ↔ a ≤ b :=
⟨le_of_pred_lt, (pred_lt_of_not_is_min ha).trans_le⟩
lemma le_pred_iff_of_not_is_min (ha : ¬ is_min a) : b ≤ pred a ↔ b < a :=
⟨λ h, h.trans_lt $ pred_lt_of_not_is_min ha, le_pred_of_lt⟩
@[simp, mono] lemma pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b := succ_le_succ h.dual
lemma pred_mono : monotone (pred : α → α) := λ a b, pred_le_pred
lemma pred_iterate_le (k : ℕ) (x : α) : (pred^[k] x) ≤ x :=
begin
conv_rhs { rw (by simp only [function.iterate_id, id.def] : x = (id^[k] x)) },
exact monotone.iterate_le_of_le pred_mono pred_le k x,
end
lemma is_min_iterate_pred_of_eq_of_lt {n m : ℕ}
(h_eq : (pred^[n] a) = (pred^[m] a)) (h_lt : n < m) :
is_min (pred^[n] a) :=
@is_max_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt
lemma is_min_iterate_pred_of_eq_of_ne {n m : ℕ}
(h_eq : (pred^[n] a) = (pred^[m] a)) (h_ne : n ≠ m) :
is_min (pred^[n] a) :=
@is_max_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne
lemma Ioi_pred_of_not_is_min (ha : ¬ is_min a) : Ioi (pred a) = Ici a :=
set.ext $ λ x, pred_lt_iff_of_not_is_min ha
lemma Iic_pred_of_not_is_min (ha : ¬ is_min a) : Iic (pred a) = Iio a :=
set.ext $ λ x, le_pred_iff_of_not_is_min ha
lemma Ioc_pred_left_of_not_is_min (ha : ¬ is_min a) : Ioc (pred a) b = Icc a b :=
by rw [←Ioi_inter_Iic, Ioi_pred_of_not_is_min ha, Ici_inter_Iic]
lemma Ioo_pred_left_of_not_is_min (ha : ¬ is_min a) : Ioo (pred a) b = Ico a b :=
by rw [←Ioi_inter_Iio, Ioi_pred_of_not_is_min ha, Ici_inter_Iio]
lemma Icc_pred_right_of_not_is_min (ha : ¬ is_min b) : Icc a (pred b) = Ico a b :=
by rw [←Ici_inter_Iic, Iic_pred_of_not_is_min ha, Ici_inter_Iio]
lemma Ioc_pred_right_of_not_is_min (ha : ¬ is_min b) : Ioc a (pred b) = Ioo a b :=
by rw [←Ioi_inter_Iic, Iic_pred_of_not_is_min ha, Ioi_inter_Iio]
section no_min_order
variables [no_min_order α]
lemma pred_lt (a : α) : pred a < a := pred_lt_of_not_is_min $ not_is_min a
@[simp] lemma pred_lt_iff : pred a < b ↔ a ≤ b := pred_lt_iff_of_not_is_min $ not_is_min a
@[simp] lemma le_pred_iff : a ≤ pred b ↔ a < b := le_pred_iff_of_not_is_min $ not_is_min b
lemma pred_le_pred_iff : pred a ≤ pred b ↔ a ≤ b := by simp
lemma pred_lt_pred_iff : pred a < pred b ↔ a < b := by simp
alias pred_le_pred_iff ↔ le_of_pred_le_pred _
alias pred_lt_pred_iff ↔ lt_of_pred_lt_pred pred_lt_pred
lemma pred_strict_mono : strict_mono (pred : α → α) := λ a b, pred_lt_pred
lemma pred_covby (a : α) : pred a ⋖ a := pred_covby_of_not_is_min $ not_is_min a
@[simp] lemma Ioi_pred (a : α) : Ioi (pred a) = Ici a := Ioi_pred_of_not_is_min $ not_is_min a
@[simp] lemma Iic_pred (a : α) : Iic (pred a) = Iio a := Iic_pred_of_not_is_min $ not_is_min a
@[simp] lemma Ioc_pred_left (a b : α) : Ioc (pred a) b = Icc a b :=
Ioc_pred_left_of_not_is_min $ not_is_min _
@[simp] lemma Ioo_pred_left (a b : α) : Ioo (pred a) b = Ico a b :=
Ioo_pred_left_of_not_is_min $ not_is_min _
@[simp] lemma Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b :=
Icc_pred_right_of_not_is_min $ not_is_min _
@[simp] lemma Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b :=
Ioc_pred_right_of_not_is_min $ not_is_min _
end no_min_order
end preorder
section partial_order
variables [partial_order α] [pred_order α] {a b : α}
@[simp] lemma pred_eq_iff_is_min : pred a = a ↔ is_min a :=
⟨λ h, min_of_le_pred h.ge, λ h, h.eq_of_le $ pred_le _⟩
alias pred_eq_iff_is_min ↔ _ _root_.is_min.pred_eq
lemma pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a :=
begin
refine ⟨λ h, or_iff_not_imp_left.2 $ λ hba : b ≠ a,
(le_pred_of_lt $ h.2.lt_of_ne hba).antisymm h.1, _⟩,
rintro (rfl | rfl),
{ exact ⟨pred_le b, le_rfl⟩ },
{ exact ⟨le_rfl, pred_le a⟩ }
end
lemma _root_.covby.pred_eq {a b : α} (h : a ⋖ b) : pred b = a :=
(le_pred_of_lt h.lt).eq_of_not_gt $ λ h', h.2 h' $ pred_lt_of_not_is_min h.lt.not_is_min
lemma _root_.wcovby.pred_le (h : a ⩿ b) : pred b ≤ a :=
begin
obtain h | rfl := h.covby_or_eq,
{ exact h.pred_eq.le },
{ exact pred_le _ }
end
lemma pred_le_iff_eq_or_le : pred a ≤ b ↔ b = pred a ∨ a ≤ b :=
begin
by_cases ha : is_min a,
{ rw [ha.pred_eq, or_iff_right_of_imp ge_of_eq] },
{ rw [←pred_lt_iff_of_not_is_min ha, le_iff_eq_or_lt, eq_comm] }
end
lemma pred_lt_iff_eq_or_lt_of_not_is_min (ha : ¬ is_min a) : pred a < b ↔ a = b ∨ a < b :=
(pred_lt_iff_of_not_is_min ha).trans le_iff_eq_or_lt
lemma Ici_pred (a : α) : Ici (pred a) = insert (pred a) (Ici a) := ext $ λ _, pred_le_iff_eq_or_le
lemma Ioi_pred_eq_insert_of_not_is_min (ha : ¬ is_min a) :
Ioi (pred a) = insert a (Ioi a) :=
begin
ext x, simp only [insert, mem_set_of, @eq_comm _ x a],
exact pred_lt_iff_eq_or_lt_of_not_is_min ha
end
lemma Icc_pred_left (h : pred a ≤ b) : Icc (pred a) b = insert (pred a) (Icc a b) :=
by simp_rw [←Ici_inter_Iic, Ici_pred, insert_inter_of_mem (mem_Iic.2 h)]
lemma Ico_pred_left (h : pred a < b) : Ico (pred a) b = insert (pred a) (Ico a b) :=
by simp_rw [←Ici_inter_Iio, Ici_pred, insert_inter_of_mem (mem_Iio.2 h)]
section no_min_order
variables [no_min_order α]
@[simp] lemma pred_eq_pred_iff : pred a = pred b ↔ a = b :=
by simp_rw [eq_iff_le_not_lt, pred_le_pred_iff, pred_lt_pred_iff]
lemma pred_injective : injective (pred : α → α) := λ a b, pred_eq_pred_iff.1
lemma pred_ne_pred_iff : pred a ≠ pred b ↔ a ≠ b := pred_injective.ne_iff
alias pred_ne_pred_iff ↔ _ pred_ne_pred
lemma pred_lt_iff_eq_or_lt : pred a < b ↔ a = b ∨ a < b := pred_lt_iff.trans le_iff_eq_or_lt
lemma pred_eq_iff_covby : pred b = a ↔ a ⋖ b :=
⟨by { rintro rfl, exact pred_covby _ }, covby.pred_eq⟩
lemma Ioi_pred_eq_insert (a : α) : Ioi (pred a) = insert a (Ioi a) :=
ext $ λ _, pred_lt_iff_eq_or_lt.trans $ or_congr_left' eq_comm
lemma Ico_pred_right_eq_insert (h : a ≤ b) : Ioc (pred a) b = insert a (Ioc a b) :=
by simp_rw [←Ioi_inter_Iic, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iic.2 h)]
lemma Ioo_pred_right_eq_insert (h : a < b) : Ioo (pred a) b = insert a (Ioo a b) :=
by simp_rw [←Ioi_inter_Iio, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iio.2 h)]
end no_min_order
section order_bot
variables [order_bot α]
@[simp] lemma pred_bot : pred (⊥ : α) = ⊥ := is_min_bot.pred_eq
@[simp] lemma le_pred_iff_eq_bot : a ≤ pred a ↔ a = ⊥ := @succ_le_iff_eq_top αᵒᵈ _ _ _ _
@[simp] lemma pred_lt_iff_ne_bot : pred a < a ↔ a ≠ ⊥ := @lt_succ_iff_ne_top αᵒᵈ _ _ _ _
end order_bot
section order_top
variable [order_top α]
@[simp] lemma pred_top_lt_iff [no_min_order α] : pred ⊤ < a ↔ a = ⊤ :=
@lt_succ_bot_iff αᵒᵈ _ _ _ _ _
lemma pred_top_le_iff : pred ⊤ ≤ a ↔ a = ⊤ ∨ a = pred ⊤ := @le_succ_bot_iff αᵒᵈ _ _ _ _
variable [nontrivial α]
lemma pred_lt_top (a : α) : pred a < ⊤ :=
(pred_mono le_top).trans_lt $ pred_lt_of_not_is_min not_is_min_top
lemma pred_ne_top (a : α) : pred a ≠ ⊤ := (pred_lt_top a).ne
end order_top
end partial_order
/-- There is at most one way to define the predecessors in a `partial_order`. -/
instance [partial_order α] : subsingleton (pred_order α) :=
⟨begin
introsI h₀ h₁,
ext a,
by_cases ha : is_min a,
{ exact (@is_min.pred_eq _ _ h₀ _ ha).trans ha.pred_eq.symm },
{ exact @covby.pred_eq _ _ h₀ _ _ (pred_covby_of_not_is_min ha) }
end⟩
section complete_lattice
variables [complete_lattice α] [pred_order α]
lemma pred_eq_supr (a : α) : pred a = ⨆ b (h : b < a), b :=
begin
refine le_antisymm _ (supr_le (λ b, supr_le le_pred_of_lt)),
obtain rfl | ha := eq_or_ne a ⊥,
{ rw pred_bot,
exact bot_le },
{ exact @le_supr₂ _ _ (λ b, b < a) _ (λ a _, a) (pred a) (pred_lt_iff_ne_bot.2 ha) }
end
end complete_lattice
/-! ### Successor-predecessor orders -/
section succ_pred_order
variables [partial_order α] [succ_order α] [pred_order α] {a b : α}
@[simp] lemma succ_pred_of_not_is_min (h : ¬ is_min a) : succ (pred a) = a :=
(pred_covby_of_not_is_min h).succ_eq
@[simp] lemma pred_succ_of_not_is_max (h : ¬ is_max a) : pred (succ a) = a :=
(covby_succ_of_not_is_max h).pred_eq
@[simp] lemma succ_pred [no_min_order α] (a : α) : succ (pred a) = a := (pred_covby _).succ_eq
@[simp] lemma pred_succ [no_max_order α] (a : α) : pred (succ a) = a := (covby_succ _).pred_eq
lemma pred_succ_iterate_of_not_is_max (i : α) (n : ℕ) (hin : ¬ is_max (succ^[n-1] i)) :
pred^[n] (succ^[n] i) = i :=
begin
induction n with n hn,
{ simp only [function.iterate_zero, id.def], },
rw [nat.succ_sub_succ_eq_sub, nat.sub_zero] at hin,
have h_not_max : ¬ is_max (succ^[n - 1] i),
{ cases n,
{ simpa using hin, },
rw [nat.succ_sub_succ_eq_sub, nat.sub_zero] at hn ⊢,
have h_sub_le : (succ^[n] i) ≤ (succ^[n.succ] i),
{ rw function.iterate_succ',
exact le_succ _, },
refine λ h_max, hin (λ j hj, _),
have hj_le : j ≤ (succ^[n] i) := h_max (h_sub_le.trans hj),
exact hj_le.trans h_sub_le, },
rw [function.iterate_succ, function.iterate_succ'],
simp only [function.comp_app],
rw pred_succ_of_not_is_max hin,
exact hn h_not_max,
end
lemma succ_pred_iterate_of_not_is_min (i : α) (n : ℕ) (hin : ¬ is_min (pred^[n-1] i)) :
succ^[n] (pred^[n] i) = i :=
@pred_succ_iterate_of_not_is_max αᵒᵈ _ _ _ i n hin
end succ_pred_order
end order
open order
/-! ### `with_bot`, `with_top`
Adding a greatest/least element to a `succ_order` or to a `pred_order`.
As far as successors and predecessors are concerned, there are four ways to add a bottom or top
element to an order:
* Adding a `⊤` to an `order_top`: Preserves `succ` and `pred`.
* Adding a `⊤` to a `no_max_order`: Preserves `succ`. Never preserves `pred`.
* Adding a `⊥` to an `order_bot`: Preserves `succ` and `pred`.
* Adding a `⊥` to a `no_min_order`: Preserves `pred`. Never preserves `succ`.
where "preserves `(succ/pred)`" means
`(succ/pred)_order α → (succ/pred)_order ((with_top/with_bot) α)`.
-/
namespace with_top
/-! #### Adding a `⊤` to an `order_top` -/
section succ
variables [decidable_eq α] [partial_order α] [order_top α] [succ_order α]
instance : succ_order (with_top α) :=
{ succ := λ a, match a with
| ⊤ := ⊤
| (some a) := ite (a = ⊤) ⊤ (some (succ a))
end,
le_succ := λ a, begin
cases a,
{ exact le_top },
change _ ≤ ite _ _ _,
split_ifs,
{ exact le_top },
{ exact some_le_some.2 (le_succ a) }
end,
max_of_succ_le := λ a ha, begin
cases a,
{ exact is_max_top },
change ite _ _ _ ≤ _ at ha,
split_ifs at ha with ha',
{ exact (not_top_le_coe _ ha).elim },
{ rw [some_le_some, succ_le_iff_eq_top] at ha,
exact (ha' ha).elim }
end,
succ_le_of_lt := λ a b h, begin
cases b,
{ exact le_top },
cases a,
{ exact (not_top_lt h).elim },
rw some_lt_some at h,
change ite _ _ _ ≤ _,
split_ifs with ha,
{ rw ha at h,
exact (not_top_lt h).elim },
{ exact some_le_some.2 (succ_le_of_lt h) }
end,
le_of_lt_succ := λ a b h, begin
cases a,
{ exact (not_top_lt h).elim },
cases b,
{ exact le_top },
change _ < ite _ _ _ at h,
rw some_le_some,
split_ifs at h with hb,
{ rw hb,
exact le_top },
{ exact le_of_lt_succ (some_lt_some.1 h) }
end }
@[simp] lemma succ_coe_top : succ ↑(⊤ : α) = (⊤ : with_top α) := dif_pos rfl
lemma succ_coe_of_ne_top {a : α} (h : a ≠ ⊤) : succ (↑a : with_top α) = ↑(succ a) :=
dif_neg h
end succ
section pred
variables [preorder α] [order_top α] [pred_order α]
instance : pred_order (with_top α) :=
{ pred := λ a, match a with
| ⊤ := some ⊤
| (some a) := some (pred a)
end,
pred_le := λ a, match a with
| ⊤ := le_top
| (some a) := some_le_some.2 (pred_le a)
end,
min_of_le_pred := λ a ha, begin
cases a,
{ exact ((coe_lt_top (⊤ : α)).not_le ha).elim },
{ exact (min_of_le_pred $ some_le_some.1 ha).with_top }
end,
le_pred_of_lt := λ a b h, begin
cases a,
{ exact ((le_top).not_lt h).elim },
cases b,
{ exact some_le_some.2 le_top },
exact some_le_some.2 (le_pred_of_lt $ some_lt_some.1 h),
end,
le_of_pred_lt := λ a b h, begin
cases b,
{ exact le_top },
cases a,
{ exact (not_top_lt $ some_lt_some.1 h).elim },
{ exact some_le_some.2 (le_of_pred_lt $ some_lt_some.1 h) }
end }
@[simp] lemma pred_top : pred (⊤ : with_top α) = ↑(⊤ : α) := rfl
@[simp] lemma pred_coe (a : α) : pred (↑a : with_top α) = ↑(pred a) := rfl
@[simp] lemma pred_untop : ∀ (a : with_top α) (ha : a ≠ ⊤),
pred (a.untop ha) = (pred a).untop (by induction a using with_top.rec_top_coe; simp)
| ⊤ ha := (ha rfl).elim
| (a : α) ha := rfl
end pred
/-! #### Adding a `⊤` to a `no_max_order` -/
section succ
variables [preorder α] [no_max_order α] [succ_order α]
instance succ_order_of_no_max_order : succ_order (with_top α) :=
{ succ := λ a, match a with
| ⊤ := ⊤
| (some a) := some (succ a)
end,
le_succ := λ a, begin
cases a,
{ exact le_top },
{ exact some_le_some.2 (le_succ a) }
end,
max_of_succ_le := λ a ha, begin
cases a,
{ exact is_max_top },
{ exact (not_is_max _ $ max_of_succ_le $ some_le_some.1 ha).elim }
end,
succ_le_of_lt := λ a b h, begin
cases a,
{ exact (not_top_lt h).elim },
cases b,
{ exact le_top},
{ exact some_le_some.2 (succ_le_of_lt $ some_lt_some.1 h) }
end,
le_of_lt_succ := λ a b h, begin
cases a,
{ exact (not_top_lt h).elim },
cases b,
{ exact le_top },
{ exact some_le_some.2 (le_of_lt_succ $ some_lt_some.1 h) }
end }
@[simp] lemma succ_coe (a : α) : succ (↑a : with_top α) = ↑(succ a) := rfl
end succ
section pred
variables [preorder α] [no_max_order α]
instance [hα : nonempty α] : is_empty (pred_order (with_top α)) :=
⟨begin
introI,
cases h : pred (⊤ : with_top α) with a ha,
{ exact hα.elim (λ a, (min_of_le_pred h.ge).not_lt $ coe_lt_top a) },
{ obtain ⟨c, hc⟩ := exists_gt a,
rw [←some_lt_some, ←h] at hc,
exact (le_of_pred_lt hc).not_lt (some_lt_none _) }
end⟩
end pred
end with_top
namespace with_bot
/-! #### Adding a `⊥` to an `order_bot` -/
section succ
variables [preorder α] [order_bot α] [succ_order α]
instance : succ_order (with_bot α) :=
{ succ := λ a, match a with
| ⊥ := some ⊥
| (some a) := some (succ a)
end,
le_succ := λ a, match a with
| ⊥ := bot_le
| (some a) := some_le_some.2 (le_succ a)
end,
max_of_succ_le := λ a ha, begin
cases a,
{ exact ((none_lt_some (⊥ : α)).not_le ha).elim },
{ exact (max_of_succ_le $ some_le_some.1 ha).with_bot }
end,
succ_le_of_lt := λ a b h, begin
cases b,
{ exact (not_lt_bot h).elim },
cases a,
{ exact some_le_some.2 bot_le },
{ exact some_le_some.2 (succ_le_of_lt $ some_lt_some.1 h) }
end,
le_of_lt_succ := λ a b h, begin
cases a,
{ exact bot_le },
cases b,
{ exact (not_lt_bot $ some_lt_some.1 h).elim },
{ exact some_le_some.2 (le_of_lt_succ $ some_lt_some.1 h) }
end }
@[simp] lemma succ_bot : succ (⊥ : with_bot α) = ↑(⊥ : α) := rfl
@[simp] lemma succ_coe (a : α) : succ (↑a : with_bot α) = ↑(succ a) := rfl
@[simp] lemma succ_unbot : ∀ (a : with_bot α) (ha : a ≠ ⊥),
succ (a.unbot ha) = (succ a).unbot (by induction a using with_bot.rec_bot_coe; simp)
| ⊥ ha := (ha rfl).elim
| (a : α) ha := rfl
end succ
section pred
variables [decidable_eq α] [partial_order α] [order_bot α] [pred_order α]
instance : pred_order (with_bot α) :=
{ pred := λ a, match a with
| ⊥ := ⊥
| (some a) := ite (a = ⊥) ⊥ (some (pred a))
end,
pred_le := λ a, begin
cases a,
{ exact bot_le },
change ite _ _ _ ≤ _,
split_ifs,
{ exact bot_le },
{ exact some_le_some.2 (pred_le a) }
end,
min_of_le_pred := λ a ha, begin
cases a,
{ exact is_min_bot },
change _ ≤ ite _ _ _ at ha,
split_ifs at ha with ha',
{ exact (not_coe_le_bot _ ha).elim },
{ rw [some_le_some, le_pred_iff_eq_bot] at ha,
exact (ha' ha).elim }
end,
le_pred_of_lt := λ a b h, begin
cases a,
{ exact bot_le },
cases b,
{ exact (not_lt_bot h).elim },
rw some_lt_some at h,
change _ ≤ ite _ _ _,
split_ifs with hb,
{ rw hb at h,
exact (not_lt_bot h).elim },
{ exact some_le_some.2 (le_pred_of_lt h) }
end,
le_of_pred_lt := λ a b h, begin
cases b,
{ exact (not_lt_bot h).elim },
cases a,
{ exact bot_le },
change ite _ _ _ < _ at h,
rw some_le_some,
split_ifs at h with ha,
{ rw ha,
exact bot_le },
{ exact le_of_pred_lt (some_lt_some.1 h) }
end }
@[simp] lemma pred_coe_bot : pred ↑(⊥ : α) = (⊥ : with_bot α) := dif_pos rfl
lemma pred_coe_of_ne_bot {a : α} (h : a ≠ ⊥) : pred (↑a : with_bot α) = ↑(pred a) :=
dif_neg h
end pred
/-! #### Adding a `⊥` to a `no_min_order` -/
section succ
variables [preorder α] [no_min_order α]
instance [hα : nonempty α] : is_empty (succ_order (with_bot α)) :=
⟨begin
introI,
cases h : succ (⊥ : with_bot α) with a ha,
{ exact hα.elim (λ a, (max_of_succ_le h.le).not_lt $ bot_lt_coe a) },
{ obtain ⟨c, hc⟩ := exists_lt a,
rw [←some_lt_some, ←h] at hc,
exact (le_of_lt_succ hc).not_lt (none_lt_some _) }
end⟩
end succ
section pred
variables [preorder α] [no_min_order α] [pred_order α]
instance pred_order_of_no_min_order : pred_order (with_bot α) :=
{ pred := λ a, match a with
| ⊥ := ⊥
| (some a) := some (pred a)
end,
pred_le := λ a, begin
cases a,
{ exact bot_le },
{ exact some_le_some.2 (pred_le a) }
end,
min_of_le_pred := λ a ha, begin
cases a,
{ exact is_min_bot },
{ exact (not_is_min _ $ min_of_le_pred $ some_le_some.1 ha).elim }
end,
le_pred_of_lt := λ a b h, begin
cases b,
{ exact (not_lt_bot h).elim },
cases a,
{ exact bot_le },
{ exact some_le_some.2 (le_pred_of_lt $ some_lt_some.1 h) }
end,
le_of_pred_lt := λ a b h, begin
cases b,
{ exact (not_lt_bot h).elim },
cases a,
{ exact bot_le },
{ exact some_le_some.2 (le_of_pred_lt $ some_lt_some.1 h) }
end }
@[simp] lemma pred_coe (a : α) : pred (↑a : with_bot α) = ↑(pred a) := rfl
end pred
end with_bot
/-! ### Archimedeanness -/
/-- A `succ_order` is succ-archimedean if one can go from any two comparable elements by iterating
`succ` -/
class is_succ_archimedean (α : Type*) [preorder α] [succ_order α] : Prop :=
(exists_succ_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, succ^[n] a = b)
/-- A `pred_order` is pred-archimedean if one can go from any two comparable elements by iterating
`pred` -/
class is_pred_archimedean (α : Type*) [preorder α] [pred_order α] : Prop :=
(exists_pred_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, pred^[n] b = a)
export is_succ_archimedean (exists_succ_iterate_of_le)
export is_pred_archimedean (exists_pred_iterate_of_le)
section preorder
variables [preorder α]
section succ_order
variables [succ_order α] [is_succ_archimedean α] {a b : α}
instance : is_pred_archimedean αᵒᵈ := ⟨λ a b h, by convert exists_succ_iterate_of_le h.of_dual⟩
lemma has_le.le.exists_succ_iterate (h : a ≤ b) : ∃ n, succ^[n] a = b :=
exists_succ_iterate_of_le h
lemma exists_succ_iterate_iff_le : (∃ n, succ^[n] a = b) ↔ a ≤ b :=
begin
refine ⟨_, exists_succ_iterate_of_le⟩,
rintro ⟨n, rfl⟩,
exact id_le_iterate_of_id_le le_succ n a,
end
/-- Induction principle on a type with a `succ_order` for all elements above a given element `m`. -/
@[elab_as_eliminator] lemma succ.rec {P : α → Prop} {m : α}
(h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (succ n)) ⦃n : α⦄ (hmn : m ≤ n) : P n :=
begin
obtain ⟨n, rfl⟩ := hmn.exists_succ_iterate, clear hmn,
induction n with n ih,
{ exact h0 },
{ rw [function.iterate_succ_apply'], exact h1 _ (id_le_iterate_of_id_le le_succ n m) ih }
end
lemma succ.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) {a b : α} (h : a ≤ b) :
p a ↔ p b :=
begin
obtain ⟨n, rfl⟩ := h.exists_succ_iterate,
exact iterate.rec (λ b, p a ↔ p b) (λ c hc, hc.trans (hsucc _)) iff.rfl n,
end
end succ_order
section pred_order
variables [pred_order α] [is_pred_archimedean α] {a b : α}
instance : is_succ_archimedean αᵒᵈ := ⟨λ a b h, by convert exists_pred_iterate_of_le h.of_dual⟩
lemma has_le.le.exists_pred_iterate (h : a ≤ b) : ∃ n, pred^[n] b = a :=
exists_pred_iterate_of_le h
lemma exists_pred_iterate_iff_le : (∃ n, pred^[n] b = a) ↔ a ≤ b :=
@exists_succ_iterate_iff_le αᵒᵈ _ _ _ _ _
/-- Induction principle on a type with a `pred_order` for all elements below a given element `m`. -/
@[elab_as_eliminator] lemma pred.rec {P : α → Prop} {m : α}
(h0 : P m) (h1 : ∀ n, n ≤ m → P n → P (pred n)) ⦃n : α⦄ (hmn : n ≤ m) : P n :=
@succ.rec αᵒᵈ _ _ _ _ _ h0 h1 _ hmn
lemma pred.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) {a b : α} (h : a ≤ b) :
p a ↔ p b :=
(@succ.rec_iff αᵒᵈ _ _ _ _ hsucc _ _ h).symm
end pred_order
end preorder
section linear_order
variables [linear_order α]
section succ_order
variables [succ_order α] [is_succ_archimedean α] {a b : α}
lemma exists_succ_iterate_or : (∃ n, succ^[n] a = b) ∨ ∃ n, succ^[n] b = a :=
(le_total a b).imp exists_succ_iterate_of_le exists_succ_iterate_of_le
lemma succ.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) (a b : α) : p a ↔ p b :=
(le_total a b).elim (succ.rec_iff hsucc) (λ h, (succ.rec_iff hsucc h).symm)
end succ_order
section pred_order
variables [pred_order α] [is_pred_archimedean α] {a b : α}
lemma exists_pred_iterate_or : (∃ n, pred^[n] b = a) ∨ ∃ n, pred^[n] a = b :=
(le_total a b).imp exists_pred_iterate_of_le exists_pred_iterate_of_le
lemma pred.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) (a b : α) : p a ↔ p b :=
(le_total a b).elim (pred.rec_iff hsucc) (λ h, (pred.rec_iff hsucc h).symm)
end pred_order
end linear_order
section is_well_order
variables [linear_order α]
@[priority 100]
instance is_well_order.to_is_pred_archimedean [h : is_well_order α (<)] [pred_order α] :
is_pred_archimedean α :=
⟨λ a, begin
refine well_founded.fix h.wf (λ b ih hab, _),
replace hab := hab.eq_or_lt,
rcases hab with rfl | hab,
{ exact ⟨0, rfl⟩ },
cases le_or_lt b (pred b) with hb hb,
{ cases (min_of_le_pred hb).not_lt hab },
obtain ⟨k, hk⟩ := ih (pred b) hb (le_pred_of_lt hab),
refine ⟨k + 1, _⟩,
rw [iterate_add_apply, iterate_one, hk],
end⟩
@[priority 100]
instance is_well_order.to_is_succ_archimedean [h : is_well_order α (>)] [succ_order α] :
is_succ_archimedean α :=
by convert @order_dual.is_succ_archimedean αᵒᵈ _ _ _
end is_well_order
section order_bot
variables [preorder α] [order_bot α] [succ_order α] [is_succ_archimedean α]
lemma succ.rec_bot (p : α → Prop) (hbot : p ⊥) (hsucc : ∀ a, p a → p (succ a)) (a : α) : p a :=
succ.rec hbot (λ x _ h, hsucc x h) (bot_le : ⊥ ≤ a)
end order_bot
section order_top
variables [preorder α] [order_top α] [pred_order α] [is_pred_archimedean α]
lemma pred.rec_top (p : α → Prop) (htop : p ⊤) (hpred : ∀ a, p a → p (pred a)) (a : α) : p a :=
pred.rec htop (λ x _ h, hpred x h) (le_top : a ≤ ⊤)
end order_top
|
35fed2fa3d5310de3bb7b06a775e47b18aea47f0 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/normed/group/pointwise.lean | 33a11f7bf38a9ae6b5372f0a838bc5ae802c7e85 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 3,170 | lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.normed.group.basic
import topology.metric_space.hausdorff_distance
/-!
# Properties of pointwise addition of sets in normed groups.
We explore the relationships between pointwise addition of sets in normed groups, and the norm.
Notably, we show that the sum of bounded sets remain bounded.
-/
open metric set
open_locale pointwise topological_space
section semi_normed_group
variables {E : Type*} [semi_normed_group E]
lemma bounded_iff_exists_norm_le {s : set E} :
bounded s ↔ ∃ R, ∀ x ∈ s, ∥x∥ ≤ R :=
by simp [subset_def, bounded_iff_subset_ball (0 : E)]
alias bounded_iff_exists_norm_le ↔ metric.bounded.exists_norm_le _
lemma metric.bounded.exists_pos_norm_le {s : set E} (hs : metric.bounded s) :
∃ R > 0, ∀ x ∈ s, ∥x∥ ≤ R :=
begin
obtain ⟨R₀, hR₀⟩ := hs.exists_norm_le,
refine ⟨max R₀ 1, _, _⟩,
{ exact (by norm_num : (0:ℝ) < 1).trans_le (le_max_right R₀ 1) },
intros x hx,
exact (hR₀ x hx).trans (le_max_left _ _),
end
lemma metric.bounded.add
{s t : set E} (hs : bounded s) (ht : bounded t) :
bounded (s + t) :=
begin
obtain ⟨Rs, hRs⟩ : ∃ (R : ℝ), ∀ x ∈ s, ∥x∥ ≤ R := hs.exists_norm_le,
obtain ⟨Rt, hRt⟩ : ∃ (R : ℝ), ∀ x ∈ t, ∥x∥ ≤ R := ht.exists_norm_le,
refine (bounded_iff_exists_norm_le).2 ⟨Rs + Rt, _⟩,
rintros z ⟨x, y, hx, hy, rfl⟩,
calc ∥x + y∥ ≤ ∥x∥ + ∥y∥ : norm_add_le _ _
... ≤ Rs + Rt : add_le_add (hRs x hx) (hRt y hy)
end
@[simp] lemma singleton_add_ball (x y : E) (r : ℝ) :
{x} + ball y r = ball (x + y) r :=
by simp only [preimage_add_ball, image_add_left, singleton_add, sub_neg_eq_add, add_comm y x]
@[simp] lemma ball_add_singleton (x y : E) (r : ℝ) :
ball x r + {y} = ball (x + y) r :=
by simp [add_comm _ {y}, add_comm y]
lemma singleton_add_ball_zero (x : E) (r : ℝ) :
{x} + ball 0 r = ball x r :=
by simp
lemma ball_zero_add_singleton (x : E) (r : ℝ) :
ball 0 r + {x} = ball x r :=
by simp
@[simp] lemma singleton_add_closed_ball (x y : E) (r : ℝ) :
{x} + closed_ball y r = closed_ball (x + y) r :=
by simp only [add_comm y x, preimage_add_closed_ball, image_add_left, singleton_add, sub_neg_eq_add]
@[simp] lemma closed_ball_add_singleton (x y : E) (r : ℝ) :
closed_ball x r + {y} = closed_ball (x + y) r :=
by simp [add_comm _ {y}, add_comm y]
lemma singleton_add_closed_ball_zero (x : E) (r : ℝ) :
{x} + closed_ball 0 r = closed_ball x r :=
by simp
lemma closed_ball_zero_add_singleton (x : E) (r : ℝ) :
closed_ball 0 r + {x} = closed_ball x r :=
by simp
lemma is_compact.cthickening_eq_add_closed_ball
{s : set E} (hs : is_compact s) {r : ℝ} (hr : 0 ≤ r) :
cthickening r s = s + closed_ball 0 r :=
begin
rw hs.cthickening_eq_bUnion_closed_ball hr,
ext x,
simp only [mem_add, dist_eq_norm, exists_prop, mem_Union, mem_closed_ball,
exists_and_distrib_left, mem_closed_ball_zero_iff, ← eq_sub_iff_add_eq', exists_eq_right],
end
end semi_normed_group
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.