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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5364b16a95b9cd2da4c4577bde4ae99448af0a77
|
f20db13587f4dd28a4b1fbd31953afd491691fa0
|
/library/system/io.lean
|
d8bab91544b772a3e57a46f8ee4b06430f421ae8
|
[
"Apache-2.0"
] |
permissive
|
AHartNtkn/lean
|
9a971edfc6857c63edcbf96bea6841b9a84cf916
|
0d83a74b26541421fc1aa33044c35b03759710ed
|
refs/heads/master
| 1,620,592,591,236
| 1,516,749,881,000
| 1,516,749,881,000
| 118,697,288
| 1
| 0
| null | 1,516,759,470,000
| 1,516,759,470,000
| null |
UTF-8
|
Lean
| false
| false
| 5,866
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Nelson, Jared Roesch and Leonardo de Moura
-/
import system.io_interface
/- The following constants have a builtin implementation -/
constant io_core : Type β Type β Type
@[instance] constant monad_io_impl : monad_io io_core
@[instance] constant monad_io_terminal_impl : monad_io_terminal io_core
@[instance] constant monad_io_file_system_impl : monad_io_file_system io_core
@[instance] constant monad_io_environment_impl : monad_io_environment io_core
@[instance] constant monad_io_process_impl : monad_io_process io_core
instance io_core_is_monad (e : Type) : monad (io_core e) :=
monad_io_is_monad io_core e
instance io_core_is_monad_fail : monad_fail (io_core io.error) :=
monad_io_is_monad_fail io_core
instance io_core_is_alternative : alternative (io_core io.error) :=
monad_io_is_alternative io_core
@[reducible] def io (Ξ± : Type) :=
io_core io.error Ξ±
namespace io
/- Remark: the following definitions can be generalized and defined for any (m : Type -> Type -> Type)
that implements the required type classes. However, the generalized versions are very inconvenient to use,
(example: `#eval io.put_str "hello world"` does not work because we don't have enough information to infer `m`.).
-/
def iterate {e Ξ±} (a : Ξ±) (f : Ξ± β io_core e (option Ξ±)) : io_core e Ξ± :=
monad_io.iterate e Ξ± a f
def forever {e} (a : io_core e unit) : io_core e unit :=
iterate () $ Ξ» _, a >> return (some ())
-- TODO(Leo): delete after we merge #1881
def catch {eβ eβ Ξ±} (a : io_core eβ Ξ±) (b : eβ β io_core eβ Ξ±) : io_core eβ Ξ± :=
monad_io.catch eβ eβ Ξ± a b
def finally {Ξ± e} (a : io_core e Ξ±) (cleanup : io_core e unit) : io_core e Ξ± := do
res β catch (sum.inr <$> a) (return β sum.inl),
cleanup,
match res with
| sum.inr res := return res
| sum.inl error := monad_io.fail _ _ _ error
end
protected def fail {Ξ± : Type} (s : string) : io Ξ± :=
monad_io.fail io_core _ _ (io.error.other s)
def put_str : string β io unit :=
monad_io_terminal.put_str io_core
def put_str_ln (s : string) : io unit :=
put_str s >> put_str "\n"
def get_line : io string :=
monad_io_terminal.get_line io_core
def cmdline_args : io (list string) :=
return (monad_io_terminal.cmdline_args io_core)
def print {Ξ±} [has_to_string Ξ±] (s : Ξ±) : io unit :=
put_str β to_string $ s
def print_ln {Ξ±} [has_to_string Ξ±] (s : Ξ±) : io unit :=
print s >> put_str "\n"
def handle : Type :=
monad_io.handle io_core
def mk_file_handle (s : string) (m : mode) (bin : bool := ff) : io handle :=
monad_io_file_system.mk_file_handle io_core s m bin
def stdin : io handle :=
monad_io_file_system.stdin io_core
def stderr : io handle :=
monad_io_file_system.stderr io_core
def stdout : io handle :=
monad_io_file_system.stdout io_core
namespace env
def get (env_var : string) : io (option string) :=
monad_io_environment.get_env io_core env_var
/-- get the current working directory -/
def get_cwd : io string :=
monad_io_environment.get_cwd io_core
/-- set the current working directory -/
def set_cwd (cwd : string) : io unit :=
monad_io_environment.set_cwd io_core cwd
end env
namespace fs
def is_eof : handle β io bool :=
monad_io_file_system.is_eof
def flush : handle β io unit :=
monad_io_file_system.flush
def close : handle β io unit :=
monad_io_file_system.close
def read : handle β nat β io char_buffer :=
monad_io_file_system.read
def write : handle β char_buffer β io unit :=
monad_io_file_system.write
def get_char (h : handle) : io char :=
do b β read h 1,
if h : b.size = 1 then return $ b.read β¨0, h.symm βΈ zero_lt_oneβ©
else io.fail "get_char failed"
def get_line : handle β io char_buffer :=
monad_io_file_system.get_line
def put_char (h : handle) (c : char) : io unit :=
write h (mk_buffer.push_back c)
def put_str (h : handle) (s : string) : io unit :=
write h (mk_buffer.append_string s)
def put_str_ln (h : handle) (s : string) : io unit :=
put_str h s >> put_str h "\n"
def read_to_end (h : handle) : io char_buffer :=
iterate mk_buffer $ Ξ» r,
do done β is_eof h,
if done
then return none
else do
c β read h 1024,
return $ some (r ++ c)
def read_file (s : string) (bin := ff) : io char_buffer :=
do h β mk_file_handle s io.mode.read bin,
read_to_end h
end fs
namespace proc
def child : Type :=
monad_io_process.child io_core
def child.stdin : child β handle :=
monad_io_process.stdin
def child.stdout : child β handle :=
monad_io_process.stdout
def child.stderr : child β handle :=
monad_io_process.stderr
def spawn (p : io.process.spawn_args) : io child :=
monad_io_process.spawn io_core p
def wait (c : child) : io nat :=
monad_io_process.wait c
end proc
end io
meta constant format.print_using : format β options β io unit
meta definition format.print (fmt : format) : io unit :=
format.print_using fmt options.mk
meta definition pp_using {Ξ± : Type} [has_to_format Ξ±] (a : Ξ±) (o : options) : io unit :=
format.print_using (to_fmt a) o
meta definition pp {Ξ± : Type} [has_to_format Ξ±] (a : Ξ±) : io unit :=
format.print (to_fmt a)
/-- Run the external process specified by `args`.
The process will run to completion with its output captured by a pipe, and
read into `string` which is then returned. -/
def io.cmd (args : io.process.spawn_args) : io string :=
do child β io.proc.spawn { stdout := io.process.stdio.piped, ..args },
buf β io.fs.read_to_end child.stdout,
exitv β io.proc.wait child,
when (exitv β 0) $ io.fail $ "process exited with status " ++ repr exitv,
return buf.to_string
/-- Lift a monadic `io` action into the `tactic` monad. -/
meta constant tactic.run_io {Ξ± : Type} : io Ξ± β tactic Ξ±
|
e4523dd61df08cfee802fa48bb36d5e5947d1e2d
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/data/finset/lattice.lean
|
dec7cb992bdec0a4b27074eac7a80df0f96ba4a3
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 59,974
|
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.fold
import data.finset.option
import data.finset.prod
import data.multiset.lattice
import order.complete_lattice
/-!
# Lattice operations on finsets
-/
variables {Ξ± Ξ² Ξ³ ΞΉ : Type*}
namespace finset
open multiset order_dual
/-! ### sup -/
section sup
-- TODO: define with just `[has_bot Ξ±]` where some lemmas hold without requiring `[order_bot Ξ±]`
variables [semilattice_sup Ξ±] [order_bot Ξ±]
/-- Supremum of a finite set: `sup {a, b, c} f = f a β f b β f c` -/
def sup (s : finset Ξ²) (f : Ξ² β Ξ±) : Ξ± := s.fold (β) β₯ f
variables {s sβ sβ : finset Ξ²} {f g : Ξ² β Ξ±}
lemma sup_def : s.sup f = (s.1.map f).sup := rfl
@[simp] lemma sup_empty : (β
: finset Ξ²).sup f = β₯ :=
fold_empty
@[simp] lemma sup_cons {b : Ξ²} (h : b β s) : (cons b s h).sup f = f b β s.sup f :=
fold_cons h
@[simp] lemma sup_insert [decidable_eq Ξ²] {b : Ξ²} : (insert b s : finset Ξ²).sup f = f b β s.sup f :=
fold_insert_idem
lemma sup_image [decidable_eq Ξ²] (s : finset Ξ³) (f : Ξ³ β Ξ²) (g : Ξ² β Ξ±) :
(s.image f).sup g = s.sup (g β f) :=
fold_image_idem
@[simp] lemma sup_map (s : finset Ξ³) (f : Ξ³ βͺ Ξ²) (g : Ξ² β Ξ±) :
(s.map f).sup g = s.sup (g β f) :=
fold_map
@[simp] lemma sup_singleton {b : Ξ²} : ({b} : finset Ξ²).sup f = f b :=
sup_singleton
lemma sup_union [decidable_eq Ξ²] : (sβ βͺ sβ).sup f = sβ.sup f β sβ.sup f :=
finset.induction_on sβ (by rw [empty_union, sup_empty, bot_sup_eq]) $ Ξ» a s has ih,
by rw [insert_union, sup_insert, sup_insert, ih, sup_assoc]
lemma sup_sup : s.sup (f β g) = s.sup f β s.sup g :=
begin
refine finset.cons_induction_on s _ (Ξ» b t _ h, _),
{ rw [sup_empty, sup_empty, sup_empty, bot_sup_eq] },
{ rw [sup_cons, sup_cons, sup_cons, h],
exact sup_sup_sup_comm _ _ _ _ }
end
theorem sup_congr {f g : Ξ² β Ξ±} (hs : sβ = sβ) (hfg : βaβsβ, f a = g a) : sβ.sup f = sβ.sup g :=
by subst hs; exact finset.fold_congr hfg
@[simp] protected lemma sup_le_iff {a : Ξ±} : s.sup f β€ a β (βb β s, f b β€ a) :=
begin
apply iff.trans multiset.sup_le,
simp only [multiset.mem_map, and_imp, exists_imp_distrib],
exact β¨Ξ» k b hb, k _ _ hb rfl, Ξ» k a' b hb h, h βΈ k _ hbβ©,
end
@[simp] lemma sup_bUnion [decidable_eq Ξ²] (s : finset Ξ³) (t : Ξ³ β finset Ξ²) :
(s.bUnion t).sup f = s.sup (Ξ» x, (t x).sup f) :=
eq_of_forall_ge_iff $ Ξ» c, by simp [@forall_swap _ Ξ²]
lemma sup_const {s : finset Ξ²} (h : s.nonempty) (c : Ξ±) : s.sup (Ξ» _, c) = c :=
eq_of_forall_ge_iff $ Ξ» b, finset.sup_le_iff.trans h.forall_const
@[simp] lemma sup_bot (s : finset Ξ²) : s.sup (Ξ» _, β₯) = (β₯ : Ξ±) :=
begin
obtain rfl | hs := s.eq_empty_or_nonempty,
{ exact sup_empty },
{ exact sup_const hs _ }
end
lemma sup_ite (p : Ξ² β Prop) [decidable_pred p] :
s.sup (Ξ» i, ite (p i) (f i) (g i)) =
(s.filter p).sup f β (s.filter (Ξ» i, Β¬ p i)).sup g :=
fold_ite _
lemma sup_le {a : Ξ±} : (βb β s, f b β€ a) β s.sup f β€ a :=
finset.sup_le_iff.2
lemma le_sup {b : Ξ²} (hb : b β s) : f b β€ s.sup f :=
finset.sup_le_iff.1 le_rfl _ hb
lemma sup_mono_fun {g : Ξ² β Ξ±} (h : βbβs, f b β€ g b) : s.sup f β€ s.sup g :=
sup_le (Ξ» b hb, le_trans (h b hb) (le_sup hb))
lemma sup_mono (h : sβ β sβ) : sβ.sup f β€ sβ.sup f :=
sup_le $ assume b hb, le_sup (h hb)
lemma sup_comm (s : finset Ξ²) (t : finset Ξ³) (f : Ξ² β Ξ³ β Ξ±) :
s.sup (Ξ» b, t.sup (f b)) = t.sup (Ξ» c, s.sup (Ξ» b, f b c)) :=
begin
refine eq_of_forall_ge_iff (Ξ» a, _),
simp_rw finset.sup_le_iff,
exact β¨Ξ» h c hc b hb, h b hb c hc, Ξ» h b hb c hc, h c hc b hbβ©,
end
@[simp] lemma sup_attach (s : finset Ξ²) (f : Ξ² β Ξ±) : s.attach.sup (Ξ» x, f x) = s.sup f :=
(s.attach.sup_map (function.embedding.subtype _) f).symm.trans $ congr_arg _ attach_map_val
/-- See also `finset.product_bUnion`. -/
lemma sup_product_left (s : finset Ξ²) (t : finset Ξ³) (f : Ξ² Γ Ξ³ β Ξ±) :
(s ΓΛ’ t).sup f = s.sup (Ξ» i, t.sup $ Ξ» i', f β¨i, i'β©) :=
begin
refine le_antisymm _ (sup_le (Ξ» i hi, sup_le $ Ξ» i' hi', le_sup $ mem_product.2 β¨hi, hi'β©)),
refine sup_le _,
rintro β¨i, i'β© hi,
rw mem_product at hi,
refine le_trans _ (le_sup hi.1),
convert le_sup hi.2,
end
lemma sup_product_right (s : finset Ξ²) (t : finset Ξ³) (f : Ξ² Γ Ξ³ β Ξ±) :
(s ΓΛ’ t).sup f = t.sup (Ξ» i', s.sup $ Ξ» i, f β¨i, i'β©) :=
by rw [sup_product_left, sup_comm]
@[simp] lemma sup_erase_bot [decidable_eq Ξ±] (s : finset Ξ±) : (s.erase β₯).sup id = s.sup id :=
begin
refine (sup_mono (s.erase_subset _)).antisymm (finset.sup_le_iff.2 $ Ξ» a ha, _),
obtain rfl | ha' := eq_or_ne a β₯,
{ exact bot_le },
{ exact le_sup (mem_erase.2 β¨ha', haβ©) }
end
lemma sup_sdiff_right {Ξ± Ξ² : Type*} [generalized_boolean_algebra Ξ±] (s : finset Ξ²) (f : Ξ² β Ξ±)
(a : Ξ±) :
s.sup (Ξ» b, f b \ a) = s.sup f \ a :=
begin
refine finset.cons_induction_on s _ (Ξ» b t _ h, _),
{ rw [sup_empty, sup_empty, bot_sdiff] },
{ rw [sup_cons, sup_cons, h, sup_sdiff] }
end
lemma comp_sup_eq_sup_comp [semilattice_sup Ξ³] [order_bot Ξ³] {s : finset Ξ²}
{f : Ξ² β Ξ±} (g : Ξ± β Ξ³) (g_sup : β x y, g (x β y) = g x β g y) (bot : g β₯ = β₯) :
g (s.sup f) = s.sup (g β f) :=
finset.cons_induction_on s bot (Ξ» c t hc ih, by rw [sup_cons, sup_cons, g_sup, ih])
/-- Computing `sup` in a subtype (closed under `sup`) is the same as computing it in `Ξ±`. -/
lemma sup_coe {P : Ξ± β Prop}
{Pbot : P β₯} {Psup : β{{x y}}, P x β P y β P (x β y)}
(t : finset Ξ²) (f : Ξ² β {x : Ξ± // P x}) :
(@sup _ _ (subtype.semilattice_sup Psup) (subtype.order_bot Pbot) t f : Ξ±) = t.sup (Ξ» x, f x) :=
by { rw [comp_sup_eq_sup_comp coe]; intros; refl }
@[simp] lemma sup_to_finset {Ξ± Ξ²} [decidable_eq Ξ²]
(s : finset Ξ±) (f : Ξ± β multiset Ξ²) :
(s.sup f).to_finset = s.sup (Ξ» x, (f x).to_finset) :=
comp_sup_eq_sup_comp multiset.to_finset to_finset_union rfl
lemma _root_.list.foldr_sup_eq_sup_to_finset [decidable_eq Ξ±] (l : list Ξ±) :
l.foldr (β) β₯ = l.to_finset.sup id :=
begin
rw [βcoe_fold_r, βmultiset.fold_dedup_idem, sup_def, βlist.to_finset_coe, to_finset_val,
multiset.map_id],
refl
end
theorem subset_range_sup_succ (s : finset β) : s β range (s.sup id).succ :=
Ξ» n hn, mem_range.2 $ nat.lt_succ_of_le $ le_sup hn
theorem exists_nat_subset_range (s : finset β) : βn : β, s β range n :=
β¨_, s.subset_range_sup_succβ©
lemma sup_induction {p : Ξ± β Prop} (hb : p β₯) (hp : β aβ, p aβ β β aβ, p aβ β p (aβ β aβ))
(hs : β b β s, p (f b)) : p (s.sup f) :=
begin
induction s using finset.cons_induction with c s hc ih,
{ exact hb, },
{ rw sup_cons,
apply hp,
{ exact hs c (mem_cons.2 (or.inl rfl)), },
{ exact ih (Ξ» b h, hs b (mem_cons.2 (or.inr h))), }, },
end
lemma sup_le_of_le_directed {Ξ± : Type*} [semilattice_sup Ξ±] [order_bot Ξ±] (s : set Ξ±)
(hs : s.nonempty) (hdir : directed_on (β€) s) (t : finset Ξ±) :
(β x β t, β y β s, x β€ y) β β x, x β s β§ t.sup id β€ x :=
begin
classical,
apply finset.induction_on t,
{ simpa only [forall_prop_of_true, and_true, forall_prop_of_false, bot_le, not_false_iff,
sup_empty, forall_true_iff, not_mem_empty], },
{ intros a r har ih h,
have incs : βr β β(insert a r), by { rw finset.coe_subset, apply finset.subset_insert, },
-- x β s is above the sup of r
obtain β¨x, β¨hxs, hsx_supβ©β© := ih (Ξ» x hx, h x $ incs hx),
-- y β s is above a
obtain β¨y, hys, hayβ© := h a (finset.mem_insert_self a r),
-- z β s is above x and y
obtain β¨z, hzs, β¨hxz, hyzβ©β© := hdir x hxs y hys,
use [z, hzs],
rw [sup_insert, id.def, sup_le_iff],
exact β¨le_trans hay hyz, le_trans hsx_sup hxzβ©, },
end
-- If we acquire sublattices
-- the hypotheses should be reformulated as `s : subsemilattice_sup_bot`
lemma sup_mem
(s : set Ξ±) (wβ : β₯ β s) (wβ : β x y β s, x β y β s)
{ΞΉ : Type*} (t : finset ΞΉ) (p : ΞΉ β Ξ±) (h : β i β t, p i β s) :
t.sup p β s :=
@sup_induction _ _ _ _ _ _ (β s) wβ wβ h
@[simp]
lemma sup_eq_bot_iff (f : Ξ² β Ξ±)
(S : finset Ξ²) : S.sup f = β₯ β β s β S, f s = β₯ :=
begin
classical,
induction S using finset.induction with a S haS hi;
simp [*],
end
end sup
lemma sup_eq_supr [complete_lattice Ξ²] (s : finset Ξ±) (f : Ξ± β Ξ²) : s.sup f = (β¨aβs, f a) :=
le_antisymm
(finset.sup_le $ assume a ha, le_supr_of_le a $ le_supr _ ha)
(supr_le $ assume a, supr_le $ assume ha, le_sup ha)
lemma sup_id_eq_Sup [complete_lattice Ξ±] (s : finset Ξ±) : s.sup id = Sup s :=
by simp [Sup_eq_supr, sup_eq_supr]
lemma sup_id_set_eq_sUnion (s : finset (set Ξ±)) : s.sup id = ββ(βs) :=
sup_id_eq_Sup _
@[simp] lemma sup_set_eq_bUnion (s : finset Ξ±) (f : Ξ± β set Ξ²) : s.sup f = β x β s, f x :=
sup_eq_supr _ _
lemma sup_eq_Sup_image [complete_lattice Ξ²] (s : finset Ξ±) (f : Ξ± β Ξ²) : s.sup f = Sup (f '' s) :=
begin
classical,
rw [βfinset.coe_image, βsup_id_eq_Sup, sup_image, function.comp.left_id],
end
/-! ### inf -/
section inf
-- TODO: define with just `[has_top Ξ±]` where some lemmas hold without requiring `[order_top Ξ±]`
variables [semilattice_inf Ξ±] [order_top Ξ±]
/-- Infimum of a finite set: `inf {a, b, c} f = f a β f b β f c` -/
def inf (s : finset Ξ²) (f : Ξ² β Ξ±) : Ξ± := s.fold (β) β€ f
variables {s sβ sβ : finset Ξ²} {f g : Ξ² β Ξ±}
lemma inf_def : s.inf f = (s.1.map f).inf := rfl
@[simp] lemma inf_empty : (β
: finset Ξ²).inf f = β€ :=
fold_empty
@[simp] lemma inf_cons {b : Ξ²} (h : b β s) : (cons b s h).inf f = f b β s.inf f :=
@sup_cons Ξ±α΅α΅ _ _ _ _ _ _ h
@[simp] lemma inf_insert [decidable_eq Ξ²] {b : Ξ²} : (insert b s : finset Ξ²).inf f = f b β s.inf f :=
fold_insert_idem
lemma inf_image [decidable_eq Ξ²] (s : finset Ξ³) (f : Ξ³ β Ξ²) (g : Ξ² β Ξ±) :
(s.image f).inf g = s.inf (g β f) :=
fold_image_idem
@[simp] lemma inf_map (s : finset Ξ³) (f : Ξ³ βͺ Ξ²) (g : Ξ² β Ξ±) :
(s.map f).inf g = s.inf (g β f) :=
fold_map
@[simp] lemma inf_singleton {b : Ξ²} : ({b} : finset Ξ²).inf f = f b :=
inf_singleton
lemma inf_union [decidable_eq Ξ²] : (sβ βͺ sβ).inf f = sβ.inf f β sβ.inf f :=
@sup_union Ξ±α΅α΅ _ _ _ _ _ _ _
lemma inf_inf : s.inf (f β g) = s.inf f β s.inf g :=
@sup_sup Ξ±α΅α΅ _ _ _ _ _ _
theorem inf_congr {f g : Ξ² β Ξ±} (hs : sβ = sβ) (hfg : βaβsβ, f a = g a) : sβ.inf f = sβ.inf g :=
by subst hs; exact finset.fold_congr hfg
@[simp] lemma inf_bUnion [decidable_eq Ξ²] (s : finset Ξ³) (t : Ξ³ β finset Ξ²) :
(s.bUnion t).inf f = s.inf (Ξ» x, (t x).inf f) :=
@sup_bUnion Ξ±α΅α΅ _ _ _ _ _ _ _ _
lemma inf_const {s : finset Ξ²} (h : s.nonempty) (c : Ξ±) : s.inf (Ξ» _, c) = c :=
@sup_const Ξ±α΅α΅ _ _ _ _ h _
@[simp] lemma inf_top (s : finset Ξ²) : s.inf (Ξ» _, β€) = (β€ : Ξ±) := @sup_bot Ξ±α΅α΅ _ _ _ _
lemma le_inf_iff {a : Ξ±} : a β€ s.inf f β β b β s, a β€ f b :=
@finset.sup_le_iff Ξ±α΅α΅ _ _ _ _ _ _
lemma inf_le {b : Ξ²} (hb : b β s) : s.inf f β€ f b :=
le_inf_iff.1 le_rfl _ hb
lemma le_inf {a : Ξ±} : (βb β s, a β€ f b) β a β€ s.inf f :=
le_inf_iff.2
lemma inf_mono_fun {g : Ξ² β Ξ±} (h : βbβs, f b β€ g b) : s.inf f β€ s.inf g :=
le_inf (Ξ» b hb, le_trans (inf_le hb) (h b hb))
lemma inf_mono (h : sβ β sβ) : sβ.inf f β€ sβ.inf f :=
le_inf $ assume b hb, inf_le (h hb)
lemma inf_attach (s : finset Ξ²) (f : Ξ² β Ξ±) : s.attach.inf (Ξ» x, f x) = s.inf f :=
@sup_attach Ξ±α΅α΅ _ _ _ _ _
lemma inf_comm (s : finset Ξ²) (t : finset Ξ³) (f : Ξ² β Ξ³ β Ξ±) :
s.inf (Ξ» b, t.inf (f b)) = t.inf (Ξ» c, s.inf (Ξ» b, f b c)) :=
@sup_comm Ξ±α΅α΅ _ _ _ _ _ _ _
lemma inf_product_left (s : finset Ξ²) (t : finset Ξ³) (f : Ξ² Γ Ξ³ β Ξ±) :
(s ΓΛ’ t).inf f = s.inf (Ξ» i, t.inf $ Ξ» i', f β¨i, i'β©) :=
@sup_product_left Ξ±α΅α΅ _ _ _ _ _ _ _
lemma inf_product_right (s : finset Ξ²) (t : finset Ξ³) (f : Ξ² Γ Ξ³ β Ξ±) :
(s ΓΛ’ t).inf f = t.inf (Ξ» i', s.inf $ Ξ» i, f β¨i, i'β©) :=
@sup_product_right Ξ±α΅α΅ _ _ _ _ _ _ _
@[simp] lemma inf_erase_top [decidable_eq Ξ±] (s : finset Ξ±) : (s.erase β€).inf id = s.inf id :=
@sup_erase_bot Ξ±α΅α΅ _ _ _ _
lemma sup_sdiff_left {Ξ± Ξ² : Type*} [boolean_algebra Ξ±] (s : finset Ξ²) (f : Ξ² β Ξ±) (a : Ξ±) :
s.sup (Ξ» b, a \ f b) = a \ s.inf f :=
begin
refine finset.cons_induction_on s _ (Ξ» b t _ h, _),
{ rw [sup_empty, inf_empty, sdiff_top] },
{ rw [sup_cons, inf_cons, h, sdiff_inf] }
end
lemma inf_sdiff_left {Ξ± Ξ² : Type*} [boolean_algebra Ξ±] {s : finset Ξ²} (hs : s.nonempty) (f : Ξ² β Ξ±)
(a : Ξ±) :
s.inf (Ξ» b, a \ f b) = a \ s.sup f :=
begin
induction hs using finset.nonempty.cons_induction with b b t _ _ h,
{ rw [sup_singleton, inf_singleton] },
{ rw [sup_cons, inf_cons, h, sdiff_sup] }
end
lemma inf_sdiff_right {Ξ± Ξ² : Type*} [boolean_algebra Ξ±] {s : finset Ξ²} (hs : s.nonempty) (f : Ξ² β Ξ±)
(a : Ξ±) :
s.inf (Ξ» b, f b \ a) = s.inf f \ a :=
begin
induction hs using finset.nonempty.cons_induction with b b t _ _ h,
{ rw [inf_singleton, inf_singleton] },
{ rw [inf_cons, inf_cons, h, inf_sdiff] }
end
lemma comp_inf_eq_inf_comp [semilattice_inf Ξ³] [order_top Ξ³] {s : finset Ξ²}
{f : Ξ² β Ξ±} (g : Ξ± β Ξ³) (g_inf : β x y, g (x β y) = g x β g y) (top : g β€ = β€) :
g (s.inf f) = s.inf (g β f) :=
@comp_sup_eq_sup_comp Ξ±α΅α΅ _ Ξ³α΅α΅ _ _ _ _ _ _ _ g_inf top
/-- Computing `inf` in a subtype (closed under `inf`) is the same as computing it in `Ξ±`. -/
lemma inf_coe {P : Ξ± β Prop}
{Ptop : P β€} {Pinf : β{{x y}}, P x β P y β P (x β y)}
(t : finset Ξ²) (f : Ξ² β {x : Ξ± // P x}) :
(@inf _ _ (subtype.semilattice_inf Pinf) (subtype.order_top Ptop) t f : Ξ±) = t.inf (Ξ» x, f x) :=
@sup_coe Ξ±α΅α΅ _ _ _ _ Ptop Pinf t f
lemma _root_.list.foldr_inf_eq_inf_to_finset [decidable_eq Ξ±] (l : list Ξ±) :
l.foldr (β) β€ = l.to_finset.inf id :=
begin
rw [βcoe_fold_r, βmultiset.fold_dedup_idem, inf_def, βlist.to_finset_coe, to_finset_val,
multiset.map_id],
refl
end
lemma inf_induction {p : Ξ± β Prop} (ht : p β€) (hp : β aβ, p aβ β β aβ, p aβ β p (aβ β aβ))
(hs : β b β s, p (f b)) : p (s.inf f) :=
@sup_induction Ξ±α΅α΅ _ _ _ _ _ _ ht hp hs
lemma inf_mem
(s : set Ξ±) (wβ : β€ β s) (wβ : β x y β s, x β y β s)
{ΞΉ : Type*} (t : finset ΞΉ) (p : ΞΉ β Ξ±) (h : β i β t, p i β s) :
t.inf p β s :=
@inf_induction _ _ _ _ _ _ (β s) wβ wβ h
@[simp]
lemma inf_eq_top_iff (f : Ξ² β Ξ±)
(S : finset Ξ²) : S.inf f = β€ β β s β S, f s = β€ :=
@finset.sup_eq_bot_iff Ξ±α΅α΅ _ _ _ _ _
end inf
@[simp] lemma to_dual_sup [semilattice_sup Ξ±] [order_bot Ξ±] (s : finset Ξ²) (f : Ξ² β Ξ±) :
to_dual (s.sup f) = s.inf (to_dual β f) := rfl
@[simp] lemma to_dual_inf [semilattice_inf Ξ±] [order_top Ξ±] (s : finset Ξ²) (f : Ξ² β Ξ±) :
to_dual (s.inf f) = s.sup (to_dual β f) := rfl
@[simp] lemma of_dual_sup [semilattice_inf Ξ±] [order_top Ξ±] (s : finset Ξ²) (f : Ξ² β Ξ±α΅α΅) :
of_dual (s.sup f) = s.inf (of_dual β f) := rfl
@[simp] lemma of_dual_inf [semilattice_sup Ξ±] [order_bot Ξ±] (s : finset Ξ²) (f : Ξ² β Ξ±α΅α΅) :
of_dual (s.inf f) = s.sup (of_dual β f) := rfl
section distrib_lattice
variables [distrib_lattice Ξ±]
section order_bot
variables [order_bot Ξ±] {s : finset Ξ²} {f : Ξ² β Ξ±} {a : Ξ±}
lemma sup_inf_distrib_left (s : finset ΞΉ) (f : ΞΉ β Ξ±) (a : Ξ±) :
a β s.sup f = s.sup (Ξ» i, a β f i) :=
begin
induction s using finset.cons_induction with i s hi h,
{ simp_rw [finset.sup_empty, inf_bot_eq] },
{ rw [sup_cons, sup_cons, inf_sup_left, h] }
end
lemma sup_inf_distrib_right (s : finset ΞΉ) (f : ΞΉ β Ξ±) (a : Ξ±) :
s.sup f β a = s.sup (Ξ» i, f i β a) :=
by { rw [_root_.inf_comm, s.sup_inf_distrib_left], simp_rw _root_.inf_comm }
lemma disjoint_sup_right : disjoint a (s.sup f) β β i β s, disjoint a (f i) :=
by simp only [disjoint_iff, sup_inf_distrib_left, sup_eq_bot_iff]
lemma disjoint_sup_left : disjoint (s.sup f) a β β i β s, disjoint (f i) a :=
by simp only [disjoint_iff, sup_inf_distrib_right, sup_eq_bot_iff]
end order_bot
section order_top
variables [order_top Ξ±]
lemma inf_sup_distrib_left (s : finset ΞΉ) (f : ΞΉ β Ξ±) (a : Ξ±) :
a β s.inf f = s.inf (Ξ» i, a β f i) :=
@sup_inf_distrib_left Ξ±α΅α΅ _ _ _ _ _ _
lemma inf_sup_distrib_right (s : finset ΞΉ) (f : ΞΉ β Ξ±) (a : Ξ±) :
s.inf f β a = s.inf (Ξ» i, f i β a) :=
@sup_inf_distrib_right Ξ±α΅α΅ _ _ _ _ _ _
end order_top
end distrib_lattice
section linear_order
variables [linear_order Ξ±]
section order_bot
variables [order_bot Ξ±] {s : finset ΞΉ} {f : ΞΉ β Ξ±} {a : Ξ±}
lemma comp_sup_eq_sup_comp_of_is_total [semilattice_sup Ξ²] [order_bot Ξ²] (g : Ξ± β Ξ²)
(mono_g : monotone g) (bot : g β₯ = β₯) : g (s.sup f) = s.sup (g β f) :=
comp_sup_eq_sup_comp g mono_g.map_sup bot
@[simp] protected lemma le_sup_iff (ha : β₯ < a) : a β€ s.sup f β β b β s, a β€ f b :=
β¨finset.cons_induction_on s (Ξ» h, absurd h (not_le_of_lt ha))
(Ξ» c t hc ih, by simpa using @or.rec _ _ (β b, (b = c β¨ b β t) β§ a β€ f b)
(Ξ» h, β¨c, or.inl rfl, hβ©) (Ξ» h, let β¨b, hb, hleβ© := ih h in β¨b, or.inr hb, hleβ©)),
(Ξ» β¨b, hb, hleβ©, trans hle (le_sup hb))β©
@[simp] protected lemma lt_sup_iff : a < s.sup f β β b β s, a < f b :=
β¨finset.cons_induction_on s (Ξ» h, absurd h not_lt_bot)
(Ξ» c t hc ih, by simpa using @or.rec _ _ (β b, (b = c β¨ b β t) β§ a < f b)
(Ξ» h, β¨c, or.inl rfl, hβ©) (Ξ» h, let β¨b, hb, hltβ© := ih h in β¨b, or.inr hb, hltβ©)),
(Ξ» β¨b, hb, hltβ©, lt_of_lt_of_le hlt (le_sup hb))β©
@[simp] protected lemma sup_lt_iff (ha : β₯ < a) : s.sup f < a β β b β s, f b < a :=
β¨(Ξ» hs b hb, lt_of_le_of_lt (le_sup hb) hs), finset.cons_induction_on s (Ξ» _, ha)
(Ξ» c t hc, by simpa only [sup_cons, sup_lt_iff, mem_cons, forall_eq_or_imp] using and.imp_right)β©
end order_bot
section order_top
variables [order_top Ξ±] {s : finset ΞΉ} {f : ΞΉ β Ξ±} {a : Ξ±}
lemma comp_inf_eq_inf_comp_of_is_total [semilattice_inf Ξ²] [order_top Ξ²] (g : Ξ± β Ξ²)
(mono_g : monotone g) (top : g β€ = β€) : g (s.inf f) = s.inf (g β f) :=
comp_inf_eq_inf_comp g mono_g.map_inf top
@[simp] protected lemma inf_le_iff (ha : a < β€) : s.inf f β€ a β β b β s, f b β€ a :=
@finset.le_sup_iff Ξ±α΅α΅ _ _ _ _ _ _ ha
@[simp] protected lemma inf_lt_iff : s.inf f < a β β b β s, f b < a :=
@finset.lt_sup_iff Ξ±α΅α΅ _ _ _ _ _ _
@[simp] protected lemma lt_inf_iff (ha : a < β€) : a < s.inf f β β b β s, a < f b :=
@finset.sup_lt_iff Ξ±α΅α΅ _ _ _ _ _ _ ha
end order_top
end linear_order
lemma inf_eq_infi [complete_lattice Ξ²] (s : finset Ξ±) (f : Ξ± β Ξ²) : s.inf f = β¨
a β s, f a :=
@sup_eq_supr _ Ξ²α΅α΅ _ _ _
lemma inf_id_eq_Inf [complete_lattice Ξ±] (s : finset Ξ±) : s.inf id = Inf s := @sup_id_eq_Sup Ξ±α΅α΅ _ _
lemma inf_id_set_eq_sInter (s : finset (set Ξ±)) : s.inf id = ββ(βs) :=
inf_id_eq_Inf _
@[simp] lemma inf_set_eq_bInter (s : finset Ξ±) (f : Ξ± β set Ξ²) : s.inf f = β x β s, f x :=
inf_eq_infi _ _
lemma inf_eq_Inf_image [complete_lattice Ξ²] (s : finset Ξ±) (f : Ξ± β Ξ²) : s.inf f = Inf (f '' s) :=
@sup_eq_Sup_image _ Ξ²α΅α΅ _ _ _
section sup'
variables [semilattice_sup Ξ±]
lemma sup_of_mem {s : finset Ξ²} (f : Ξ² β Ξ±) {b : Ξ²} (h : b β s) :
β (a : Ξ±), s.sup (coe β f : Ξ² β with_bot Ξ±) = βa :=
Exists.imp (Ξ» a, Exists.fst) (@le_sup (with_bot Ξ±) _ _ _ _ _ _ h (f b) rfl)
/-- Given nonempty finset `s` then `s.sup' H f` is the supremum of its image under `f` in (possibly
unbounded) join-semilattice `Ξ±`, where `H` is a proof of nonemptiness. If `Ξ±` has a bottom element
you may instead use `finset.sup` which does not require `s` nonempty. -/
def sup' (s : finset Ξ²) (H : s.nonempty) (f : Ξ² β Ξ±) : Ξ± :=
with_bot.unbot (s.sup (coe β f)) (by simpa using H)
variables {s : finset Ξ²} (H : s.nonempty) (f : Ξ² β Ξ±)
@[simp] lemma coe_sup' : ((s.sup' H f : Ξ±) : with_bot Ξ±) = s.sup (coe β f) :=
by rw [sup', with_bot.coe_unbot]
@[simp] lemma sup'_cons {b : Ξ²} {hb : b β s} {h : (cons b s hb).nonempty} :
(cons b s hb).sup' h f = f b β s.sup' H f :=
by { rw βwith_bot.coe_eq_coe, simp only [coe_sup', sup_cons, with_bot.coe_sup], }
@[simp] lemma sup'_insert [decidable_eq Ξ²] {b : Ξ²} {h : (insert b s).nonempty} :
(insert b s).sup' h f = f b β s.sup' H f :=
by { rw βwith_bot.coe_eq_coe, simp only [coe_sup', sup_insert, with_bot.coe_sup], }
@[simp] lemma sup'_singleton {b : Ξ²} {h : ({b} : finset Ξ²).nonempty} :
({b} : finset Ξ²).sup' h f = f b := rfl
lemma sup'_le {a : Ξ±} (hs : β b β s, f b β€ a) : s.sup' H f β€ a :=
by { rw [βwith_bot.coe_le_coe, coe_sup'], exact sup_le (Ξ» b h, with_bot.coe_le_coe.2 $ hs b h), }
lemma le_sup' {b : Ξ²} (h : b β s) : f b β€ s.sup' β¨b, hβ© f :=
by { rw [βwith_bot.coe_le_coe, coe_sup'], exact le_sup h, }
@[simp] lemma sup'_const (a : Ξ±) : s.sup' H (Ξ» b, a) = a :=
begin
apply le_antisymm,
{ apply sup'_le, intros, exact le_rfl, },
{ apply le_sup' (Ξ» b, a) H.some_spec, }
end
@[simp] lemma sup'_le_iff {a : Ξ±} : s.sup' H f β€ a β β b β s, f b β€ a :=
iff.intro (Ξ» h b hb, trans (le_sup' f hb) h) (sup'_le H f)
lemma sup'_bUnion [decidable_eq Ξ²] {s : finset Ξ³} (Hs : s.nonempty) {t : Ξ³ β finset Ξ²}
(Ht : β b, (t b).nonempty) :
(s.bUnion t).sup' (Hs.bUnion (Ξ» b _, Ht b)) f = s.sup' Hs (Ξ» b, (t b).sup' (Ht b) f) :=
eq_of_forall_ge_iff $ Ξ» c, by simp [@forall_swap _ Ξ²]
lemma comp_sup'_eq_sup'_comp [semilattice_sup Ξ³] {s : finset Ξ²} (H : s.nonempty)
{f : Ξ² β Ξ±} (g : Ξ± β Ξ³) (g_sup : β x y, g (x β y) = g x β g y) :
g (s.sup' H f) = s.sup' H (g β f) :=
begin
rw [βwith_bot.coe_eq_coe, coe_sup'],
let g' := with_bot.map g,
show g' β(s.sup' H f) = s.sup (Ξ» a, g' β(f a)),
rw coe_sup',
refine comp_sup_eq_sup_comp g' _ rfl,
intros fβ fβ,
induction fβ using with_bot.rec_bot_coe,
{ rw [bot_sup_eq], exact bot_sup_eq.symm, },
{ induction fβ using with_bot.rec_bot_coe,
{ refl },
{ exact congr_arg coe (g_sup fβ fβ) } }
end
lemma sup'_induction {p : Ξ± β Prop} (hp : β aβ, p aβ β β aβ, p aβ β p (aβ β aβ))
(hs : β b β s, p (f b)) : p (s.sup' H f) :=
begin
show @with_bot.rec_bot_coe Ξ± (Ξ» _, Prop) true p β(s.sup' H f),
rw coe_sup',
refine sup_induction trivial _ hs,
rintro (_|aβ) hβ aβ hβ,
{ rw [with_bot.none_eq_bot, bot_sup_eq], exact hβ },
cases aβ,
exacts [hβ, hp aβ hβ aβ hβ]
end
lemma sup'_mem
(s : set Ξ±) (w : β x y β s, x β y β s)
{ΞΉ : Type*} (t : finset ΞΉ) (H : t.nonempty) (p : ΞΉ β Ξ±) (h : β i β t, p i β s) :
t.sup' H p β s := sup'_induction H p w h
@[congr] lemma sup'_congr {t : finset Ξ²} {f g : Ξ² β Ξ±} (hβ : s = t) (hβ : β x β s, f x = g x) :
s.sup' H f = t.sup' (hβ βΈ H) g :=
begin
subst s,
refine eq_of_forall_ge_iff (Ξ» c, _),
simp only [sup'_le_iff, hβ] { contextual := tt }
end
@[simp] lemma sup'_map {s : finset Ξ³} {f : Ξ³ βͺ Ξ²} (g : Ξ² β Ξ±) (hs : (s.map f).nonempty)
(hs': s.nonempty := finset.map_nonempty.mp hs) :
(s.map f).sup' hs g = s.sup' hs' (g β f) :=
by rw [βwith_bot.coe_eq_coe, coe_sup', sup_map, coe_sup']
end sup'
section inf'
variables [semilattice_inf Ξ±]
lemma inf_of_mem {s : finset Ξ²} (f : Ξ² β Ξ±) {b : Ξ²} (h : b β s) :
β (a : Ξ±), s.inf (coe β f : Ξ² β with_top Ξ±) = βa :=
@sup_of_mem Ξ±α΅α΅ _ _ _ f _ h
/-- Given nonempty finset `s` then `s.inf' H f` is the infimum of its image under `f` in (possibly
unbounded) meet-semilattice `Ξ±`, where `H` is a proof of nonemptiness. If `Ξ±` has a top element you
may instead use `finset.inf` which does not require `s` nonempty. -/
def inf' (s : finset Ξ²) (H : s.nonempty) (f : Ξ² β Ξ±) : Ξ± :=
with_top.untop (s.inf (coe β f)) (by simpa using H)
variables {s : finset Ξ²} (H : s.nonempty) (f : Ξ² β Ξ±) {a : Ξ±} {b : Ξ²}
@[simp] lemma coe_inf' : ((s.inf' H f : Ξ±) : with_top Ξ±) = s.inf (coe β f) :=
@coe_sup' Ξ±α΅α΅ _ _ _ H f
@[simp] lemma inf'_cons {b : Ξ²} {hb : b β s} {h : (cons b s hb).nonempty} :
(cons b s hb).inf' h f = f b β s.inf' H f :=
@sup'_cons Ξ±α΅α΅ _ _ _ H f _ _ h
@[simp] lemma inf'_insert [decidable_eq Ξ²] {b : Ξ²} {h : (insert b s).nonempty} :
(insert b s).inf' h f = f b β s.inf' H f :=
@sup'_insert Ξ±α΅α΅ _ _ _ H f _ _ h
@[simp] lemma inf'_singleton {b : Ξ²} {h : ({b} : finset Ξ²).nonempty} :
({b} : finset Ξ²).inf' h f = f b := rfl
lemma le_inf' (hs : β b β s, a β€ f b) : a β€ s.inf' H f := @sup'_le Ξ±α΅α΅ _ _ _ H f _ hs
lemma inf'_le (h : b β s) : s.inf' β¨b, hβ© f β€ f b := @le_sup' Ξ±α΅α΅ _ _ _ f _ h
@[simp] lemma inf'_const (a : Ξ±) : s.inf' H (Ξ» b, a) = a := @sup'_const Ξ±α΅α΅ _ _ _ H _
@[simp] lemma le_inf'_iff : a β€ s.inf' H f β β b β s, a β€ f b := @sup'_le_iff Ξ±α΅α΅ _ _ _ H f _
lemma inf'_bUnion [decidable_eq Ξ²] {s : finset Ξ³} (Hs : s.nonempty) {t : Ξ³ β finset Ξ²}
(Ht : β b, (t b).nonempty) :
(s.bUnion t).inf' (Hs.bUnion (Ξ» b _, Ht b)) f = s.inf' Hs (Ξ» b, (t b).inf' (Ht b) f) :=
@sup'_bUnion Ξ±α΅α΅ _ _ _ _ _ _ Hs _ Ht
lemma comp_inf'_eq_inf'_comp [semilattice_inf Ξ³] {s : finset Ξ²} (H : s.nonempty)
{f : Ξ² β Ξ±} (g : Ξ± β Ξ³) (g_inf : β x y, g (x β y) = g x β g y) :
g (s.inf' H f) = s.inf' H (g β f) :=
@comp_sup'_eq_sup'_comp Ξ±α΅α΅ _ Ξ³α΅α΅ _ _ _ H f g g_inf
lemma inf'_induction {p : Ξ± β Prop} (hp : β aβ, p aβ β β aβ, p aβ β p (aβ β aβ))
(hs : β b β s, p (f b)) : p (s.inf' H f) :=
@sup'_induction Ξ±α΅α΅ _ _ _ H f _ hp hs
lemma inf'_mem (s : set Ξ±) (w : β x y β s, x β y β s)
{ΞΉ : Type*} (t : finset ΞΉ) (H : t.nonempty) (p : ΞΉ β Ξ±) (h : β i β t, p i β s) :
t.inf' H p β s := inf'_induction H p w h
@[congr] lemma inf'_congr {t : finset Ξ²} {f g : Ξ² β Ξ±} (hβ : s = t) (hβ : β x β s, f x = g x) :
s.inf' H f = t.inf' (hβ βΈ H) g :=
@sup'_congr Ξ±α΅α΅ _ _ _ H _ _ _ hβ hβ
@[simp] lemma inf'_map {s : finset Ξ³} {f : Ξ³ βͺ Ξ²} (g : Ξ² β Ξ±) (hs : (s.map f).nonempty)
(hs': s.nonempty := finset.map_nonempty.mp hs) :
(s.map f).inf' hs g = s.inf' hs' (g β f) :=
@sup'_map Ξ±α΅α΅ _ _ _ _ _ _ hs hs'
end inf'
section sup
variables [semilattice_sup Ξ±] [order_bot Ξ±]
lemma sup'_eq_sup {s : finset Ξ²} (H : s.nonempty) (f : Ξ² β Ξ±) : s.sup' H f = s.sup f :=
le_antisymm (sup'_le H f (Ξ» b, le_sup)) (sup_le (Ξ» b, le_sup' f))
lemma sup_closed_of_sup_closed {s : set Ξ±} (t : finset Ξ±) (htne : t.nonempty) (h_subset : βt β s)
(h : β a b β s, a β b β s) : t.sup id β s :=
sup'_eq_sup htne id βΈ sup'_induction _ _ h h_subset
lemma coe_sup_of_nonempty {s : finset Ξ²} (h : s.nonempty) (f : Ξ² β Ξ±) :
(β(s.sup f) : with_bot Ξ±) = s.sup (coe β f) :=
by simp only [βsup'_eq_sup h, coe_sup' h]
end sup
section inf
variables [semilattice_inf Ξ±] [order_top Ξ±]
lemma inf'_eq_inf {s : finset Ξ²} (H : s.nonempty) (f : Ξ² β Ξ±) : s.inf' H f = s.inf f :=
@sup'_eq_sup Ξ±α΅α΅ _ _ _ _ H f
lemma inf_closed_of_inf_closed {s : set Ξ±} (t : finset Ξ±) (htne : t.nonempty) (h_subset : βt β s)
(h : β a b β s, a β b β s) : t.inf id β s :=
@sup_closed_of_sup_closed Ξ±α΅α΅ _ _ _ t htne h_subset h
lemma coe_inf_of_nonempty {s : finset Ξ²} (h : s.nonempty) (f : Ξ² β Ξ±):
(β(s.inf f) : with_top Ξ±) = s.inf (Ξ» i, f i) :=
@coe_sup_of_nonempty Ξ±α΅α΅ _ _ _ _ h f
end inf
section sup
variables {C : Ξ² β Type*} [Ξ (b : Ξ²), semilattice_sup (C b)] [Ξ (b : Ξ²), order_bot (C b)]
@[simp]
protected lemma sup_apply (s : finset Ξ±) (f : Ξ± β Ξ (b : Ξ²), C b) (b : Ξ²) :
s.sup f b = s.sup (Ξ» a, f a b) :=
comp_sup_eq_sup_comp (Ξ» x : Ξ b : Ξ², C b, x b) (Ξ» i j, rfl) rfl
end sup
section inf
variables {C : Ξ² β Type*} [Ξ (b : Ξ²), semilattice_inf (C b)] [Ξ (b : Ξ²), order_top (C b)]
@[simp]
protected lemma inf_apply (s : finset Ξ±) (f : Ξ± β Ξ (b : Ξ²), C b) (b : Ξ²) :
s.inf f b = s.inf (Ξ» a, f a b) :=
@finset.sup_apply _ _ (Ξ» b, (C b)α΅α΅) _ _ s f b
end inf
section sup'
variables {C : Ξ² β Type*} [Ξ (b : Ξ²), semilattice_sup (C b)]
@[simp]
protected lemma sup'_apply {s : finset Ξ±} (H : s.nonempty) (f : Ξ± β Ξ (b : Ξ²), C b) (b : Ξ²) :
s.sup' H f b = s.sup' H (Ξ» a, f a b) :=
comp_sup'_eq_sup'_comp H (Ξ» x : Ξ b : Ξ², C b, x b) (Ξ» i j, rfl)
end sup'
section inf'
variables {C : Ξ² β Type*} [Ξ (b : Ξ²), semilattice_inf (C b)]
@[simp]
protected lemma inf'_apply {s : finset Ξ±} (H : s.nonempty) (f : Ξ± β Ξ (b : Ξ²), C b) (b : Ξ²) :
s.inf' H f b = s.inf' H (Ξ» a, f a b) :=
@finset.sup'_apply _ _ (Ξ» b, (C b)α΅α΅) _ _ H f b
end inf'
@[simp] lemma to_dual_sup' [semilattice_sup Ξ±] {s : finset ΞΉ} (hs : s.nonempty) (f : ΞΉ β Ξ±) :
to_dual (s.sup' hs f) = s.inf' hs (to_dual β f) := rfl
@[simp] lemma to_dual_inf' [semilattice_inf Ξ±] {s : finset ΞΉ} (hs : s.nonempty) (f : ΞΉ β Ξ±) :
to_dual (s.inf' hs f) = s.sup' hs (to_dual β f) := rfl
@[simp] lemma of_dual_sup' [semilattice_inf Ξ±] {s : finset ΞΉ} (hs : s.nonempty) (f : ΞΉ β Ξ±α΅α΅) :
of_dual (s.sup' hs f) = s.inf' hs (of_dual β f) := rfl
@[simp] lemma of_dual_inf' [semilattice_sup Ξ±] {s : finset ΞΉ} (hs : s.nonempty) (f : ΞΉ β Ξ±α΅α΅) :
of_dual (s.inf' hs f) = s.sup' hs (of_dual β f) := rfl
section linear_order
variables [linear_order Ξ±] {s : finset ΞΉ} (H : s.nonempty) {f : ΞΉ β Ξ±} {a : Ξ±}
@[simp] lemma le_sup'_iff : a β€ s.sup' H f β β b β s, a β€ f b :=
begin
rw [βwith_bot.coe_le_coe, coe_sup', finset.le_sup_iff (with_bot.bot_lt_coe a)],
exact bex_congr (Ξ» b hb, with_bot.coe_le_coe),
end
@[simp] lemma lt_sup'_iff : a < s.sup' H f β β b β s, a < f b :=
begin
rw [βwith_bot.coe_lt_coe, coe_sup', finset.lt_sup_iff],
exact bex_congr (Ξ» b hb, with_bot.coe_lt_coe),
end
@[simp] lemma sup'_lt_iff : s.sup' H f < a β β i β s, f i < a :=
begin
rw [βwith_bot.coe_lt_coe, coe_sup', finset.sup_lt_iff (with_bot.bot_lt_coe a)],
exact ball_congr (Ξ» b hb, with_bot.coe_lt_coe),
end
@[simp] lemma inf'_le_iff : s.inf' H f β€ a β β i β s, f i β€ a := @le_sup'_iff Ξ±α΅α΅ _ _ _ H f _
@[simp] lemma inf'_lt_iff : s.inf' H f < a β β i β s, f i < a := @lt_sup'_iff Ξ±α΅α΅ _ _ _ H f _
@[simp] lemma lt_inf'_iff : a < s.inf' H f β β i β s, a < f i := @sup'_lt_iff Ξ±α΅α΅ _ _ _ H f _
lemma exists_mem_eq_sup' (f : ΞΉ β Ξ±) : β i, i β s β§ s.sup' H f = f i :=
begin
refine H.cons_induction (Ξ» c, _) (Ξ» c s hc hs ih, _),
{ exact β¨c, mem_singleton_self c, rflβ©, },
{ rcases ih with β¨b, hb, h'β©,
rw [sup'_cons hs, h'],
cases total_of (β€) (f b) (f c) with h h,
{ exact β¨c, mem_cons.2 (or.inl rfl), sup_eq_left.2 hβ©, },
{ exact β¨b, mem_cons.2 (or.inr hb), sup_eq_right.2 hβ©, }, },
end
lemma exists_mem_eq_inf' (f : ΞΉ β Ξ±) : β i, i β s β§ s.inf' H f = f i :=
@exists_mem_eq_sup' Ξ±α΅α΅ _ _ _ H f
lemma exists_mem_eq_sup [order_bot Ξ±] (s : finset ΞΉ) (h : s.nonempty) (f : ΞΉ β Ξ±) :
β i, i β s β§ s.sup f = f i :=
sup'_eq_sup h f βΈ exists_mem_eq_sup' h f
lemma exists_mem_eq_inf [order_top Ξ±] (s : finset ΞΉ) (h : s.nonempty) (f : ΞΉ β Ξ±) :
β i, i β s β§ s.inf f = f i :=
@exists_mem_eq_sup Ξ±α΅α΅ _ _ _ _ h f
end linear_order
/-! ### max and min of finite sets -/
section max_min
variables [linear_order Ξ±]
/-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty,
and `β₯` otherwise. It belongs to `with_bot Ξ±`. If you want to get an element of `Ξ±`, see
`s.max'`. -/
protected def max (s : finset Ξ±) : with_bot Ξ± :=
sup s coe
lemma max_eq_sup_coe {s : finset Ξ±} : s.max = s.sup coe := rfl
theorem max_eq_sup_with_bot (s : finset Ξ±) :
s.max = sup s coe := rfl
@[simp] theorem max_empty : (β
: finset Ξ±).max = β₯ := rfl
@[simp] theorem max_insert {a : Ξ±} {s : finset Ξ±} :
(insert a s).max = max a s.max := fold_insert_idem
@[simp] theorem max_singleton {a : Ξ±} : finset.max {a} = (a : with_bot Ξ±) :=
by { rw [β insert_emptyc_eq], exact max_insert }
theorem max_of_mem {s : finset Ξ±} {a : Ξ±} (h : a β s) : β (b : Ξ±), s.max = b :=
(@le_sup (with_bot Ξ±) _ _ _ _ _ _ h _ rfl).imp $ Ξ» b, Exists.fst
theorem max_of_nonempty {s : finset Ξ±} (h : s.nonempty) : β (a : Ξ±), s.max = a :=
let β¨a, haβ© := h in max_of_mem ha
theorem max_eq_bot {s : finset Ξ±} : s.max = β₯ β s = β
:=
β¨Ξ» h, s.eq_empty_or_nonempty.elim id
(Ξ» H, let β¨a, haβ© := max_of_nonempty H in by rw h at ha; cases ha),
Ξ» h, h.symm βΈ max_emptyβ©
theorem mem_of_max {s : finset Ξ±} : β {a : Ξ±}, s.max = a β a β s :=
finset.induction_on s (Ξ» _ H, by cases H)
(Ξ» b s _ (ih : β {a : Ξ±}, s.max = a β a β s) a (h : (insert b s).max = a),
begin
by_cases p : b = a,
{ induction p, exact mem_insert_self b s },
{ cases max_choice βb s.max with q q;
rw [max_insert, q] at h,
{ cases h, cases p rfl },
{ exact mem_insert_of_mem (ih h) } }
end)
lemma coe_le_max_of_mem {a : Ξ±} {s : finset Ξ±} (as : a β s) : βa β€ s.max :=
le_sup as
lemma not_mem_of_max_lt_coe {a : Ξ±} {s : finset Ξ±} (h : s.max < a) : a β s :=
mt coe_le_max_of_mem h.not_le
theorem le_max_of_mem {s : finset Ξ±} {a b : Ξ±} (hβ : a β s) (hβ : s.max = b) : a β€ b :=
with_bot.coe_le_coe.mp $ (coe_le_max_of_mem hβ).trans hβ.le
theorem not_mem_of_max_lt {s : finset Ξ±} {a b : Ξ±} (hβ : b < a) (hβ : s.max = βb) : a β s :=
finset.not_mem_of_max_lt_coe $ hβ.trans_lt $ with_bot.coe_lt_coe.mpr hβ
lemma max_mono {s t : finset Ξ±} (st : s β t) : s.max β€ t.max :=
sup_mono st
lemma max_le {M : with_bot Ξ±} {s : finset Ξ±} (st : β a : Ξ±, a β s β (a : with_bot Ξ±) β€ M) :
s.max β€ M :=
sup_le st
/-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty,
and `β€` otherwise. It belongs to `with_top Ξ±`. If you want to get an element of `Ξ±`, see
`s.min'`. -/
protected def min (s : finset Ξ±) : with_top Ξ± :=
inf s coe
theorem min_eq_inf_with_top (s : finset Ξ±) :
s.min = inf s coe := rfl
@[simp] theorem min_empty : (β
: finset Ξ±).min = β€ := rfl
@[simp] theorem min_insert {a : Ξ±} {s : finset Ξ±} :
(insert a s).min = min βa s.min :=
fold_insert_idem
@[simp] theorem min_singleton {a : Ξ±} : finset.min {a} = (a : with_top Ξ±) :=
by { rw β insert_emptyc_eq, exact min_insert }
theorem min_of_mem {s : finset Ξ±} {a : Ξ±} (h : a β s) : β b : Ξ±, s.min = b :=
(@inf_le (with_top Ξ±) _ _ _ _ _ _ h _ rfl).imp $ Ξ» b, Exists.fst
theorem min_of_nonempty {s : finset Ξ±} (h : s.nonempty) : β a : Ξ±, s.min = a :=
let β¨a, haβ© := h in min_of_mem ha
theorem min_eq_top {s : finset Ξ±} : s.min = β€ β s = β
:=
β¨Ξ» h, s.eq_empty_or_nonempty.elim id
(Ξ» H, let β¨a, haβ© := min_of_nonempty H in by rw h at ha; cases ha),
Ξ» h, h.symm βΈ min_emptyβ©
theorem mem_of_min {s : finset Ξ±} : β {a : Ξ±}, s.min = a β a β s := @mem_of_max Ξ±α΅α΅ _ s
lemma min_le_coe_of_mem {a : Ξ±} {s : finset Ξ±} (as : a β s) : s.min β€ a :=
inf_le as
lemma not_mem_of_coe_lt_min {a : Ξ±} {s : finset Ξ±} (h : βa < s.min) : a β s :=
mt min_le_coe_of_mem h.not_le
theorem min_le_of_mem {s : finset Ξ±} {a b : Ξ±} (hβ : b β s) (hβ : s.min = a) : a β€ b :=
with_top.coe_le_coe.mp $ hβ.ge.trans (min_le_coe_of_mem hβ)
theorem not_mem_of_lt_min {s : finset Ξ±} {a b : Ξ±} (hβ : a < b) (hβ : s.min = βb) : a β s :=
finset.not_mem_of_coe_lt_min $ ( with_top.coe_lt_coe.mpr hβ).trans_eq hβ.symm
lemma min_mono {s t : finset Ξ±} (st : s β t) : t.min β€ s.min :=
inf_mono st
lemma le_min {m : with_top Ξ±} {s : finset Ξ±} (st : β a : Ξ±, a β s β m β€ a) :
m β€ s.min :=
le_inf st
/-- Given a nonempty finset `s` in a linear order `Ξ± `, then `s.min' h` is its minimum, as an
element of `Ξ±`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`,
taking values in `with_top Ξ±`. -/
def min' (s : finset Ξ±) (H : s.nonempty) : Ξ± :=
inf' s H id
/-- Given a nonempty finset `s` in a linear order `Ξ± `, then `s.max' h` is its maximum, as an
element of `Ξ±`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`,
taking values in `with_bot Ξ±`. -/
def max' (s : finset Ξ±) (H : s.nonempty) : Ξ± :=
sup' s H id
variables (s : finset Ξ±) (H : s.nonempty) {x : Ξ±}
theorem min'_mem : s.min' H β s := mem_of_min $ by simp [min', finset.min]
theorem min'_le (x) (H2 : x β s) : s.min' β¨x, H2β© β€ x :=
min_le_of_mem H2 (with_top.coe_untop _ _).symm
theorem le_min' (x) (H2 : β y β s, x β€ y) : x β€ s.min' H := H2 _ $ min'_mem _ _
theorem is_least_min' : is_least βs (s.min' H) := β¨min'_mem _ _, min'_le _β©
@[simp] lemma le_min'_iff {x} : x β€ s.min' H β β y β s, x β€ y :=
le_is_glb_iff (is_least_min' s H).is_glb
/-- `{a}.min' _` is `a`. -/
@[simp] lemma min'_singleton (a : Ξ±) :
({a} : finset Ξ±).min' (singleton_nonempty _) = a :=
by simp [min']
theorem max'_mem : s.max' H β s := mem_of_max $ by simp [max', finset.max]
theorem le_max' (x) (H2 : x β s) : x β€ s.max' β¨x, H2β© :=
le_max_of_mem H2 (with_bot.coe_unbot _ _).symm
theorem max'_le (x) (H2 : β y β s, y β€ x) : s.max' H β€ x := H2 _ $ max'_mem _ _
theorem is_greatest_max' : is_greatest βs (s.max' H) := β¨max'_mem _ _, le_max' _β©
@[simp] lemma max'_le_iff {x} : s.max' H β€ x β β y β s, y β€ x :=
is_lub_le_iff (is_greatest_max' s H).is_lub
@[simp] lemma max'_lt_iff {x} : s.max' H < x β β y β s, y < x :=
β¨Ξ» Hlt y hy, (s.le_max' y hy).trans_lt Hlt, Ξ» H, H _ $ s.max'_mem _β©
@[simp] lemma lt_min'_iff : x < s.min' H β β y β s, x < y := @max'_lt_iff Ξ±α΅α΅ _ _ H _
lemma max'_eq_sup' : s.max' H = s.sup' H id :=
eq_of_forall_ge_iff $ Ξ» a, (max'_le_iff _ _).trans (sup'_le_iff _ _).symm
lemma min'_eq_inf' : s.min' H = s.inf' H id := @max'_eq_sup' Ξ±α΅α΅ _ s H
/-- `{a}.max' _` is `a`. -/
@[simp] lemma max'_singleton (a : Ξ±) :
({a} : finset Ξ±).max' (singleton_nonempty _) = a :=
by simp [max']
theorem min'_lt_max' {i j} (H1 : i β s) (H2 : j β s) (H3 : i β j) :
s.min' β¨i, H1β© < s.max' β¨i, H1β© :=
is_glb_lt_is_lub_of_ne (s.is_least_min' _).is_glb (s.is_greatest_max' _).is_lub H1 H2 H3
/--
If there's more than 1 element, the min' is less than the max'. An alternate version of
`min'_lt_max'` which is sometimes more convenient.
-/
lemma min'_lt_max'_of_card (hβ : 1 < card s) :
s.min' (finset.card_pos.mp $ lt_trans zero_lt_one hβ) <
s.max' (finset.card_pos.mp $ lt_trans zero_lt_one hβ) :=
begin
rcases one_lt_card.1 hβ with β¨a, ha, b, hb, habβ©,
exact s.min'_lt_max' ha hb hab
end
lemma map_of_dual_min (s : finset Ξ±α΅α΅) : s.min.map of_dual = (s.image of_dual).max :=
by { rw [max_eq_sup_with_bot, sup_image], exact congr_fun option.map_id _ }
lemma map_of_dual_max (s : finset Ξ±α΅α΅) : s.max.map of_dual = (s.image of_dual).min :=
by { rw [min_eq_inf_with_top, inf_image], exact congr_fun option.map_id _ }
lemma map_to_dual_min (s : finset Ξ±) : s.min.map to_dual = (s.image to_dual).max :=
by { rw [max_eq_sup_with_bot, sup_image], exact congr_fun option.map_id _ }
lemma map_to_dual_max (s : finset Ξ±) : s.max.map to_dual = (s.image to_dual).min :=
by { rw [min_eq_inf_with_top, inf_image], exact congr_fun option.map_id _ }
lemma of_dual_min' {s : finset Ξ±α΅α΅} (hs : s.nonempty) :
of_dual (min' s hs) = max' (s.image of_dual) (hs.image _) :=
by { convert rfl, exact image_id }
lemma of_dual_max' {s : finset Ξ±α΅α΅} (hs : s.nonempty) :
of_dual (max' s hs) = min' (s.image of_dual) (hs.image _) :=
by { convert rfl, exact image_id }
lemma to_dual_min' {s : finset Ξ±} (hs : s.nonempty) :
to_dual (min' s hs) = max' (s.image to_dual) (hs.image _) :=
by { convert rfl, exact image_id }
lemma to_dual_max' {s : finset Ξ±} (hs : s.nonempty) :
to_dual (max' s hs) = min' (s.image to_dual) (hs.image _) :=
by { convert rfl, exact image_id }
lemma max'_subset {s t : finset Ξ±} (H : s.nonempty) (hst : s β t) :
s.max' H β€ t.max' (H.mono hst) :=
le_max' _ _ (hst (s.max'_mem H))
lemma min'_subset {s t : finset Ξ±} (H : s.nonempty) (hst : s β t) :
t.min' (H.mono hst) β€ s.min' H :=
min'_le _ _ (hst (s.min'_mem H))
lemma max'_insert (a : Ξ±) (s : finset Ξ±) (H : s.nonempty) :
(insert a s).max' (s.insert_nonempty a) = max (s.max' H) a :=
(is_greatest_max' _ _).unique $
by { rw [coe_insert, max_comm], exact (is_greatest_max' _ _).insert _ }
lemma min'_insert (a : Ξ±) (s : finset Ξ±) (H : s.nonempty) :
(insert a s).min' (s.insert_nonempty a) = min (s.min' H) a :=
(is_least_min' _ _).unique $
by { rw [coe_insert, min_comm], exact (is_least_min' _ _).insert _ }
lemma lt_max'_of_mem_erase_max' [decidable_eq Ξ±] {a : Ξ±} (ha : a β s.erase (s.max' H)) :
a < s.max' H :=
lt_of_le_of_ne (le_max' _ _ (mem_of_mem_erase ha)) $ ne_of_mem_of_not_mem ha $ not_mem_erase _ _
lemma min'_lt_of_mem_erase_min' [decidable_eq Ξ±] {a : Ξ±} (ha : a β s.erase (s.min' H)) :
s.min' H < a :=
@lt_max'_of_mem_erase_max' Ξ±α΅α΅ _ s H _ a ha
@[simp] lemma max'_image [linear_order Ξ²]
{f : Ξ± β Ξ²} (hf : monotone f) (s : finset Ξ±) (h : (s.image f).nonempty) :
(s.image f).max' h = f (s.max' ((nonempty.image_iff f).mp h)) :=
begin
refine le_antisymm (max'_le _ _ _ (Ξ» y hy, _))
(le_max' _ _ (mem_image.mpr β¨_, max'_mem _ _, rflβ©)),
obtain β¨x, hx, rflβ© := mem_image.mp hy,
exact hf (le_max' _ _ hx)
end
@[simp] lemma min'_image [linear_order Ξ²]
{f : Ξ± β Ξ²} (hf : monotone f) (s : finset Ξ±) (h : (s.image f).nonempty) :
(s.image f).min' h = f (s.min' ((nonempty.image_iff f).mp h)) :=
begin
convert @max'_image Ξ±α΅α΅ Ξ²α΅α΅ _ _ (Ξ» a : Ξ±α΅α΅, to_dual (f (of_dual a))) (by simpa) _ _; convert h,
rw nonempty.image_iff,
end
lemma coe_max' {s : finset Ξ±} (hs : s.nonempty) : β(s.max' hs) = s.max := coe_sup' hs id
lemma coe_min' {s : finset Ξ±} (hs : s.nonempty) : β(s.min' hs) = s.min := coe_inf' hs id
lemma max'_erase_ne_self {s : finset Ξ±} (s0 : (s.erase x).nonempty) :
(s.erase x).max' s0 β x :=
ne_of_mem_erase (max'_mem _ s0)
lemma min'_erase_ne_self {s : finset Ξ±} (s0 : (s.erase x).nonempty) :
(s.erase x).min' s0 β x :=
ne_of_mem_erase (min'_mem _ s0)
lemma max_erase_ne_self {s : finset Ξ±} : (s.erase x).max β x :=
begin
by_cases s0 : (s.erase x).nonempty,
{ refine ne_of_eq_of_ne (coe_max' s0).symm _,
exact with_bot.coe_eq_coe.not.mpr (max'_erase_ne_self _) },
{ rw [not_nonempty_iff_eq_empty.mp s0, max_empty],
exact with_bot.bot_ne_coe }
end
lemma min_erase_ne_self {s : finset Ξ±} : (s.erase x).min β x :=
by convert @max_erase_ne_self Ξ±α΅α΅ _ _ _
/-- Induction principle for `finset`s in a linearly ordered type: a predicate is true on all
`s : finset Ξ±` provided that:
* it is true on the empty `finset`,
* for every `s : finset Ξ±` and an element `a` strictly greater than all elements of `s`, `p s`
implies `p (insert a s)`. -/
@[elab_as_eliminator]
lemma induction_on_max [decidable_eq Ξ±] {p : finset Ξ± β Prop} (s : finset Ξ±) (h0 : p β
)
(step : β a s, (β x β s, x < a) β p s β p (insert a s)) : p s :=
begin
induction s using finset.strong_induction_on with s ihs,
rcases s.eq_empty_or_nonempty with rfl|hne,
{ exact h0 },
{ have H : s.max' hne β s, from max'_mem s hne,
rw β insert_erase H,
exact step _ _ (Ξ» x, s.lt_max'_of_mem_erase_max' hne) (ihs _ $ erase_ssubset H) }
end
/-- Induction principle for `finset`s in a linearly ordered type: a predicate is true on all
`s : finset Ξ±` provided that:
* it is true on the empty `finset`,
* for every `s : finset Ξ±` and an element `a` strictly less than all elements of `s`, `p s`
implies `p (insert a s)`. -/
@[elab_as_eliminator]
lemma induction_on_min [decidable_eq Ξ±] {p : finset Ξ± β Prop} (s : finset Ξ±) (h0 : p β
)
(step : β a s, (β x β s, a < x) β p s β p (insert a s)) : p s :=
@induction_on_max Ξ±α΅α΅ _ _ _ s h0 step
end max_min
section max_min_induction_value
variables [linear_order Ξ±] [linear_order Ξ²]
/-- Induction principle for `finset`s in any type from which a given function `f` maps to a linearly
ordered type : a predicate is true on all `s : finset Ξ±` provided that:
* it is true on the empty `finset`,
* for every `s : finset Ξ±` and an element `a` such that for elements of `s` denoted by `x` we have
`f x β€ f a`, `p s` implies `p (insert a s)`. -/
@[elab_as_eliminator]
lemma induction_on_max_value [decidable_eq ΞΉ] (f : ΞΉ β Ξ±)
{p : finset ΞΉ β Prop} (s : finset ΞΉ) (h0 : p β
)
(step : β a s, a β s β (β x β s, f x β€ f a) β p s β p (insert a s)) : p s :=
begin
induction s using finset.strong_induction_on with s ihs,
rcases (s.image f).eq_empty_or_nonempty with hne|hne,
{ simp only [image_eq_empty] at hne,
simp only [hne, h0] },
{ have H : (s.image f).max' hne β (s.image f), from max'_mem (s.image f) hne,
simp only [mem_image, exists_prop] at H,
rcases H with β¨a, has, hfaβ©,
rw β insert_erase has,
refine step _ _ (not_mem_erase a s) (Ξ» x hx, _) (ihs _ $ erase_ssubset has),
rw hfa,
exact le_max' _ _ (mem_image_of_mem _ $ mem_of_mem_erase hx) }
end
/-- Induction principle for `finset`s in any type from which a given function `f` maps to a linearly
ordered type : a predicate is true on all `s : finset Ξ±` provided that:
* it is true on the empty `finset`,
* for every `s : finset Ξ±` and an element `a` such that for elements of `s` denoted by `x` we have
`f a β€ f x`, `p s` implies `p (insert a s)`. -/
@[elab_as_eliminator]
lemma induction_on_min_value [decidable_eq ΞΉ] (f : ΞΉ β Ξ±)
{p : finset ΞΉ β Prop} (s : finset ΞΉ) (h0 : p β
)
(step : β a s, a β s β (β x β s, f a β€ f x) β p s β p (insert a s)) : p s :=
@induction_on_max_value Ξ±α΅α΅ ΞΉ _ _ _ _ s h0 step
end max_min_induction_value
section exists_max_min
variables [linear_order Ξ±]
lemma exists_max_image (s : finset Ξ²) (f : Ξ² β Ξ±) (h : s.nonempty) :
β x β s, β x' β s, f x' β€ f x :=
begin
cases max_of_nonempty (h.image f) with y hy,
rcases mem_image.mp (mem_of_max hy) with β¨x, hx, rflβ©,
exact β¨x, hx, Ξ» x' hx', le_max_of_mem (mem_image_of_mem f hx') hyβ©,
end
lemma exists_min_image (s : finset Ξ²) (f : Ξ² β Ξ±) (h : s.nonempty) :
β x β s, β x' β s, f x β€ f x' :=
@exists_max_image Ξ±α΅α΅ Ξ² _ s f h
end exists_max_min
end finset
namespace multiset
lemma map_finset_sup [decidable_eq Ξ±] [decidable_eq Ξ²]
(s : finset Ξ³) (f : Ξ³ β multiset Ξ²) (g : Ξ² β Ξ±) (hg : function.injective g) :
map g (s.sup f) = s.sup (map g β f) :=
finset.comp_sup_eq_sup_comp _ (Ξ» _ _, map_union hg) (map_zero _)
lemma count_finset_sup [decidable_eq Ξ²] (s : finset Ξ±) (f : Ξ± β multiset Ξ²) (b : Ξ²) :
count b (s.sup f) = s.sup (Ξ»a, count b (f a)) :=
begin
letI := classical.dec_eq Ξ±,
refine s.induction _ _,
{ exact count_zero _ },
{ assume i s his ih,
rw [finset.sup_insert, sup_eq_union, count_union, finset.sup_insert, ih],
refl }
end
lemma mem_sup {Ξ± Ξ²} [decidable_eq Ξ²] {s : finset Ξ±} {f : Ξ± β multiset Ξ²}
{x : Ξ²} : x β s.sup f β β v β s, x β f v :=
begin
classical,
apply s.induction_on,
{ simp },
{ intros a s has hxs,
rw [finset.sup_insert, multiset.sup_eq_union, multiset.mem_union],
split,
{ intro hxi,
cases hxi with hf hf,
{ refine β¨a, _, hfβ©,
simp only [true_or, eq_self_iff_true, finset.mem_insert] },
{ rcases hxs.mp hf with β¨v, hv, hfvβ©,
refine β¨v, _, hfvβ©,
simp only [hv, or_true, finset.mem_insert] } },
{ rintros β¨v, hv, hfvβ©,
rw [finset.mem_insert] at hv,
rcases hv with rfl | hv,
{ exact or.inl hfv },
{ refine or.inr (hxs.mpr β¨v, hv, hfvβ©) } } },
end
end multiset
namespace finset
lemma mem_sup {Ξ± Ξ²} [decidable_eq Ξ²] {s : finset Ξ±} {f : Ξ± β finset Ξ²}
{x : Ξ²} : x β s.sup f β β v β s, x β f v :=
begin
change _ β β v β s, x β (f v).val,
rw [βmultiset.mem_sup, βmultiset.mem_to_finset, sup_to_finset],
simp_rw [val_to_finset],
end
lemma sup_eq_bUnion {Ξ± Ξ²} [decidable_eq Ξ²] (s : finset Ξ±) (t : Ξ± β finset Ξ²) :
s.sup t = s.bUnion t :=
by { ext, rw [mem_sup, mem_bUnion], }
@[simp] lemma sup_singleton'' [decidable_eq Ξ±] (s : finset Ξ²) (f : Ξ² β Ξ±) :
s.sup (Ξ» b, {f b}) = s.image f :=
by { ext a, rw [mem_sup, mem_image], simp only [mem_singleton, eq_comm] }
@[simp] lemma sup_singleton' [decidable_eq Ξ±] (s : finset Ξ±) : s.sup singleton = s :=
(s.sup_singleton'' _).trans image_id
end finset
section lattice
variables {ΞΉ' : Sort*} [complete_lattice Ξ±]
/-- Supremum of `s i`, `i : ΞΉ`, is equal to the supremum over `t : finset ΞΉ` of suprema
`β¨ i β t, s i`. This version assumes `ΞΉ` is a `Type*`. See `supr_eq_supr_finset'` for a version
that works for `ΞΉ : Sort*`. -/
lemma supr_eq_supr_finset (s : ΞΉ β Ξ±) :
(β¨i, s i) = (β¨t:finset ΞΉ, β¨iβt, s i) :=
begin
classical,
exact le_antisymm
(supr_le $ assume b, le_supr_of_le {b} $ le_supr_of_le b $ le_supr_of_le
(by simp) $ le_rfl)
(supr_le $ assume t, supr_le $ assume b, supr_le $ assume hb, le_supr _ _)
end
/-- Supremum of `s i`, `i : ΞΉ`, is equal to the supremum over `t : finset ΞΉ` of suprema
`β¨ i β t, s i`. This version works for `ΞΉ : Sort*`. See `supr_eq_supr_finset` for a version
that assumes `ΞΉ : Type*` but has no `plift`s. -/
lemma supr_eq_supr_finset' (s : ΞΉ' β Ξ±) :
(β¨i, s i) = (β¨t:finset (plift ΞΉ'), β¨iβt, s (plift.down i)) :=
by rw [β supr_eq_supr_finset, β equiv.plift.surjective.supr_comp]; refl
/-- Infimum of `s i`, `i : ΞΉ`, is equal to the infimum over `t : finset ΞΉ` of infima
`β¨
i β t, s i`. This version assumes `ΞΉ` is a `Type*`. See `infi_eq_infi_finset'` for a version
that works for `ΞΉ : Sort*`. -/
lemma infi_eq_infi_finset (s : ΞΉ β Ξ±) : (β¨
i, s i) = β¨
(t : finset ΞΉ) (i β t), s i :=
@supr_eq_supr_finset Ξ±α΅α΅ _ _ _
/-- Infimum of `s i`, `i : ΞΉ`, is equal to the infimum over `t : finset ΞΉ` of infima
`β¨
i β t, s i`. This version works for `ΞΉ : Sort*`. See `infi_eq_infi_finset` for a version
that assumes `ΞΉ : Type*` but has no `plift`s. -/
lemma infi_eq_infi_finset' (s : ΞΉ' β Ξ±) :
(β¨
i, s i) = (β¨
t:finset (plift ΞΉ'), β¨
iβt, s (plift.down i)) :=
@supr_eq_supr_finset' Ξ±α΅α΅ _ _ _
end lattice
namespace set
variables {ΞΉ' : Sort*}
/-- Union of an indexed family of sets `s : ΞΉ β set Ξ±` is equal to the union of the unions
of finite subfamilies. This version assumes `ΞΉ : Type*`. See also `Union_eq_Union_finset'` for
a version that works for `ΞΉ : Sort*`. -/
lemma Union_eq_Union_finset (s : ΞΉ β set Ξ±) :
(βi, s i) = (βt:finset ΞΉ, βiβt, s i) :=
supr_eq_supr_finset s
/-- Union of an indexed family of sets `s : ΞΉ β set Ξ±` is equal to the union of the unions
of finite subfamilies. This version works for `ΞΉ : Sort*`. See also `Union_eq_Union_finset` for
a version that assumes `ΞΉ : Type*` but avoids `plift`s in the right hand side. -/
lemma Union_eq_Union_finset' (s : ΞΉ' β set Ξ±) :
(βi, s i) = (βt:finset (plift ΞΉ'), βiβt, s (plift.down i)) :=
supr_eq_supr_finset' s
/-- Intersection of an indexed family of sets `s : ΞΉ β set Ξ±` is equal to the intersection of the
intersections of finite subfamilies. This version assumes `ΞΉ : Type*`. See also
`Inter_eq_Inter_finset'` for a version that works for `ΞΉ : Sort*`. -/
lemma Inter_eq_Inter_finset (s : ΞΉ β set Ξ±) :
(βi, s i) = (βt:finset ΞΉ, βiβt, s i) :=
infi_eq_infi_finset s
/-- Intersection of an indexed family of sets `s : ΞΉ β set Ξ±` is equal to the intersection of the
intersections of finite subfamilies. This version works for `ΞΉ : Sort*`. See also
`Inter_eq_Inter_finset` for a version that assumes `ΞΉ : Type*` but avoids `plift`s in the right
hand side. -/
lemma Inter_eq_Inter_finset' (s : ΞΉ' β set Ξ±) :
(βi, s i) = (βt:finset (plift ΞΉ'), βiβt, s (plift.down i)) :=
infi_eq_infi_finset' s
end set
namespace finset
/-! ### Interaction with ordered algebra structures -/
lemma sup_mul_le_mul_sup_of_nonneg [linear_ordered_semiring Ξ±] [order_bot Ξ±]
{a b : ΞΉ β Ξ±} (s : finset ΞΉ) (ha : β i β s, 0 β€ a i) (hb : β i β s, 0 β€ b i) :
s.sup (a * b) β€ s.sup a * s.sup b :=
finset.sup_le $ Ξ» i hi, mul_le_mul (le_sup hi) (le_sup hi) (hb _ hi) ((ha _ hi).trans $ le_sup hi)
lemma mul_inf_le_inf_mul_of_nonneg [linear_ordered_semiring Ξ±] [order_top Ξ±]
{a b : ΞΉ β Ξ±} (s : finset ΞΉ) (ha : β i β s, 0 β€ a i) (hb : β i β s, 0 β€ b i) :
s.inf a * s.inf b β€ s.inf (a * b) :=
finset.le_inf $ Ξ» i hi, mul_le_mul (inf_le hi) (inf_le hi) (finset.le_inf hb) (ha i hi)
lemma sup'_mul_le_mul_sup'_of_nonneg [linear_ordered_semiring Ξ±]
{a b : ΞΉ β Ξ±} (s : finset ΞΉ) (H : s.nonempty) (ha : β i β s, 0 β€ a i) (hb : β i β s, 0 β€ b i) :
s.sup' H (a * b) β€ s.sup' H a * s.sup' H b :=
sup'_le _ _ $ Ξ» i hi,
mul_le_mul (le_sup' _ hi) (le_sup' _ hi) (hb _ hi) ((ha _ hi).trans $ le_sup' _ hi)
lemma inf'_mul_le_mul_inf'_of_nonneg [linear_ordered_semiring Ξ±]
{a b : ΞΉ β Ξ±} (s : finset ΞΉ) (H : s.nonempty) (ha : β i β s, 0 β€ a i) (hb : β i β s, 0 β€ b i) :
s.inf' H a * s.inf' H b β€ s.inf' H (a * b) :=
le_inf' _ _ $ Ξ» i hi, mul_le_mul (inf'_le _ hi) (inf'_le _ hi) (le_inf' _ _ hb) (ha _ hi)
open function
/-! ### Interaction with big lattice/set operations -/
section lattice
lemma supr_coe [has_Sup Ξ²] (f : Ξ± β Ξ²) (s : finset Ξ±) :
(β¨ x β (βs : set Ξ±), f x) = β¨ x β s, f x :=
rfl
lemma infi_coe [has_Inf Ξ²] (f : Ξ± β Ξ²) (s : finset Ξ±) :
(β¨
x β (βs : set Ξ±), f x) = β¨
x β s, f x :=
rfl
variables [complete_lattice Ξ²]
theorem supr_singleton (a : Ξ±) (s : Ξ± β Ξ²) : (β¨ x β ({a} : finset Ξ±), s x) = s a :=
by simp
theorem infi_singleton (a : Ξ±) (s : Ξ± β Ξ²) : (β¨
x β ({a} : finset Ξ±), s x) = s a :=
by simp
lemma supr_option_to_finset (o : option Ξ±) (f : Ξ± β Ξ²) :
(β¨ x β o.to_finset, f x) = β¨ x β o, f x :=
by simp
lemma infi_option_to_finset (o : option Ξ±) (f : Ξ± β Ξ²) : (β¨
x β o.to_finset, f x) = β¨
x β o, f x :=
@supr_option_to_finset _ Ξ²α΅α΅ _ _ _
variables [decidable_eq Ξ±]
theorem supr_union {f : Ξ± β Ξ²} {s t : finset Ξ±} :
(β¨ x β s βͺ t, f x) = (β¨xβs, f x) β (β¨xβt, f x) :=
by simp [supr_or, supr_sup_eq]
theorem infi_union {f : Ξ± β Ξ²} {s t : finset Ξ±} :
(β¨
x β s βͺ t, f x) = (β¨
x β s, f x) β (β¨
x β t, f x) :=
@supr_union Ξ± Ξ²α΅α΅ _ _ _ _ _
lemma supr_insert (a : Ξ±) (s : finset Ξ±) (t : Ξ± β Ξ²) :
(β¨ x β insert a s, t x) = t a β (β¨ x β s, t x) :=
by { rw insert_eq, simp only [supr_union, finset.supr_singleton] }
lemma infi_insert (a : Ξ±) (s : finset Ξ±) (t : Ξ± β Ξ²) :
(β¨
x β insert a s, t x) = t a β (β¨
x β s, t x) :=
@supr_insert Ξ± Ξ²α΅α΅ _ _ _ _ _
lemma supr_finset_image {f : Ξ³ β Ξ±} {g : Ξ± β Ξ²} {s : finset Ξ³} :
(β¨ x β s.image f, g x) = (β¨ y β s, g (f y)) :=
by rw [β supr_coe, coe_image, supr_image, supr_coe]
lemma sup_finset_image {Ξ² Ξ³ : Type*} [semilattice_sup Ξ²] [order_bot Ξ²]
(f : Ξ³ β Ξ±) (g : Ξ± β Ξ²) (s : finset Ξ³) :
(s.image f).sup g = s.sup (g β f) :=
begin
classical,
induction s using finset.induction_on with a s' ha ih; simp *
end
lemma infi_finset_image {f : Ξ³ β Ξ±} {g : Ξ± β Ξ²} {s : finset Ξ³} :
(β¨
x β s.image f, g x) = (β¨
y β s, g (f y)) :=
by rw [β infi_coe, coe_image, infi_image, infi_coe]
lemma supr_insert_update {x : Ξ±} {t : finset Ξ±} (f : Ξ± β Ξ²) {s : Ξ²} (hx : x β t) :
(β¨ (i β insert x t), function.update f x s i) = (s β β¨ (i β t), f i) :=
begin
simp only [finset.supr_insert, update_same],
rcongr i hi, apply update_noteq, rintro rfl, exact hx hi
end
lemma infi_insert_update {x : Ξ±} {t : finset Ξ±} (f : Ξ± β Ξ²) {s : Ξ²} (hx : x β t) :
(β¨
(i β insert x t), update f x s i) = (s β β¨
(i β t), f i) :=
@supr_insert_update Ξ± Ξ²α΅α΅ _ _ _ _ f _ hx
lemma supr_bUnion (s : finset Ξ³) (t : Ξ³ β finset Ξ±) (f : Ξ± β Ξ²) :
(β¨ y β s.bUnion t, f y) = β¨ (x β s) (y β t x), f y :=
by simp [@supr_comm _ Ξ±, supr_and]
lemma infi_bUnion (s : finset Ξ³) (t : Ξ³ β finset Ξ±) (f : Ξ± β Ξ²) :
(β¨
y β s.bUnion t, f y) = β¨
(x β s) (y β t x), f y :=
@supr_bUnion _ Ξ²α΅α΅ _ _ _ _ _ _
end lattice
theorem set_bUnion_coe (s : finset Ξ±) (t : Ξ± β set Ξ²) :
(β x β (βs : set Ξ±), t x) = β x β s, t x :=
rfl
theorem set_bInter_coe (s : finset Ξ±) (t : Ξ± β set Ξ²) :
(β x β (βs : set Ξ±), t x) = β x β s, t x :=
rfl
theorem set_bUnion_singleton (a : Ξ±) (s : Ξ± β set Ξ²) :
(β x β ({a} : finset Ξ±), s x) = s a :=
supr_singleton a s
theorem set_bInter_singleton (a : Ξ±) (s : Ξ± β set Ξ²) :
(β x β ({a} : finset Ξ±), s x) = s a :=
infi_singleton a s
@[simp] lemma set_bUnion_preimage_singleton (f : Ξ± β Ξ²) (s : finset Ξ²) :
(β y β s, f β»ΒΉ' {y}) = f β»ΒΉ' s :=
set.bUnion_preimage_singleton f s
lemma set_bUnion_option_to_finset (o : option Ξ±) (f : Ξ± β set Ξ²) :
(β x β o.to_finset, f x) = β x β o, f x :=
supr_option_to_finset o f
lemma set_bInter_option_to_finset (o : option Ξ±) (f : Ξ± β set Ξ²) :
(β x β o.to_finset, f x) = β x β o, f x :=
infi_option_to_finset o f
lemma subset_set_bUnion_of_mem {s : finset Ξ±} {f : Ξ± β set Ξ²} {x : Ξ±} (h : x β s) :
f x β β (y β s), f y :=
show f x β€ (β¨ y β s, f y), from le_supr_of_le x $ le_supr _ h
variables [decidable_eq Ξ±]
lemma set_bUnion_union (s t : finset Ξ±) (u : Ξ± β set Ξ²) :
(β x β s βͺ t, u x) = (β x β s, u x) βͺ (β x β t, u x) :=
supr_union
lemma set_bInter_inter (s t : finset Ξ±) (u : Ξ± β set Ξ²) :
(β x β s βͺ t, u x) = (β x β s, u x) β© (β x β t, u x) :=
infi_union
lemma set_bUnion_insert (a : Ξ±) (s : finset Ξ±) (t : Ξ± β set Ξ²) :
(β x β insert a s, t x) = t a βͺ (β x β s, t x) :=
supr_insert a s t
lemma set_bInter_insert (a : Ξ±) (s : finset Ξ±) (t : Ξ± β set Ξ²) :
(β x β insert a s, t x) = t a β© (β x β s, t x) :=
infi_insert a s t
lemma set_bUnion_finset_image {f : Ξ³ β Ξ±} {g : Ξ± β set Ξ²} {s : finset Ξ³} :
(βx β s.image f, g x) = (βy β s, g (f y)) :=
supr_finset_image
lemma set_bInter_finset_image {f : Ξ³ β Ξ±} {g : Ξ± β set Ξ²} {s : finset Ξ³} :
(β x β s.image f, g x) = (β y β s, g (f y)) :=
infi_finset_image
lemma set_bUnion_insert_update {x : Ξ±} {t : finset Ξ±} (f : Ξ± β set Ξ²) {s : set Ξ²} (hx : x β t) :
(β (i β insert x t), @update _ _ _ f x s i) = (s βͺ β (i β t), f i) :=
supr_insert_update f hx
lemma set_bInter_insert_update {x : Ξ±} {t : finset Ξ±} (f : Ξ± β set Ξ²) {s : set Ξ²} (hx : x β t) :
(β (i β insert x t), @update _ _ _ f x s i) = (s β© β (i β t), f i) :=
infi_insert_update f hx
lemma set_bUnion_bUnion (s : finset Ξ³) (t : Ξ³ β finset Ξ±) (f : Ξ± β set Ξ²) :
(β y β s.bUnion t, f y) = β (x β s) (y β t x), f y :=
supr_bUnion s t f
lemma set_bInter_bUnion (s : finset Ξ³) (t : Ξ³ β finset Ξ±) (f : Ξ± β set Ξ²) :
(β y β s.bUnion t, f y) = β (x β s) (y β t x), f y :=
infi_bUnion s t f
end finset
|
ed12aaefca2400b4264263150401a4ea869de9e8
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/src/Lean/Meta/WHNF.lean
|
5cb4a335819db8da3d4a60523d3e9e46b74ab5a4
|
[
"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
| 36,599
|
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.ToExpr
import Lean.AuxRecursor
import Lean.ProjFns
import Lean.Structure
import Lean.Util.Recognizers
import Lean.Meta.Basic
import Lean.Meta.GetConst
import Lean.Meta.FunInfo
import Lean.Meta.Match.MatcherInfo
import Lean.Meta.Match.MatchPatternAttr
namespace Lean.Meta
-- ===========================
/-! # Smart unfolding support -/
-- ===========================
/--
Forward declaration. It is defined in the module `src/Lean/Elab/PreDefinition/Structural/Eqns.lean`.
It is possible to avoid this hack if we move `Structural.EqnInfo` and `Structural.eqnInfoExt`
to this module.
-/
@[extern "lean_get_structural_rec_arg_pos"]
opaque getStructuralRecArgPos? (declName : Name) : CoreM (Option Nat)
def smartUnfoldingSuffix := "_sunfold"
@[inline] def mkSmartUnfoldingNameFor (declName : Name) : Name :=
Name.mkStr declName smartUnfoldingSuffix
def hasSmartUnfoldingDecl (env : Environment) (declName : Name) : Bool :=
env.contains (mkSmartUnfoldingNameFor declName)
register_builtin_option smartUnfolding : Bool := {
defValue := true
descr := "when computing weak head normal form, use auxiliary definition created for functions defined by structural recursion"
}
/-- Add auxiliary annotation to indicate the `match`-expression `e` must be reduced when performing smart unfolding. -/
def markSmartUnfoldingMatch (e : Expr) : Expr :=
mkAnnotation `sunfoldMatch e
def smartUnfoldingMatch? (e : Expr) : Option Expr :=
annotation? `sunfoldMatch e
/-- Add auxiliary annotation to indicate expression `e` (a `match` alternative rhs) was successfully reduced by smart unfolding. -/
def markSmartUnfoldingMatchAlt (e : Expr) : Expr :=
mkAnnotation `sunfoldMatchAlt e
def smartUnfoldingMatchAlt? (e : Expr) : Option Expr :=
annotation? `sunfoldMatchAlt e
-- ===========================
/-! # Helper methods -/
-- ===========================
def isAuxDef (constName : Name) : MetaM Bool := do
let env β getEnv
return isAuxRecursor env constName || isNoConfusion env constName
@[inline] private def matchConstAux {Ξ±} (e : Expr) (failK : Unit β MetaM Ξ±) (k : ConstantInfo β List Level β MetaM Ξ±) : MetaM Ξ± :=
match e with
| Expr.const name lvls => do
let (some cinfo) β getConst? name | failK ()
k cinfo lvls
| _ => failK ()
-- ===========================
/-! # Helper functions for reducing recursors -/
-- ===========================
private def getFirstCtor (d : Name) : MetaM (Option Name) := do
let some (ConstantInfo.inductInfo { ctors := ctor::_, ..}) β getConstNoEx? d | pure none
return some ctor
private def mkNullaryCtor (type : Expr) (nparams : Nat) : MetaM (Option Expr) := do
match type.getAppFn with
| Expr.const d lvls =>
let (some ctor) β getFirstCtor d | pure none
return mkAppN (mkConst ctor lvls) (type.getAppArgs.shrink nparams)
| _ =>
return none
private def getRecRuleFor (recVal : RecursorVal) (major : Expr) : Option RecursorRule :=
match major.getAppFn with
| Expr.const fn _ => recVal.rules.find? fun r => r.ctor == fn
| _ => none
private def toCtorWhenK (recVal : RecursorVal) (major : Expr) : MetaM Expr := do
let majorType β inferType major
let majorType β instantiateMVars (β whnf majorType)
let majorTypeI := majorType.getAppFn
if !majorTypeI.isConstOf recVal.getInduct then
return major
else if majorType.hasExprMVar && majorType.getAppArgs[recVal.numParams:].any Expr.hasExprMVar then
return major
else do
let (some newCtorApp) β mkNullaryCtor majorType recVal.numParams | pure major
let newType β inferType newCtorApp
/- TODO: check whether changing reducibility to default hurts performance here.
We do that to make sure auxiliary `Eq.rec` introduced by the `match`-compiler
are reduced even when `TransparencyMode.reducible` (like in `simp`).
We use `withNewMCtxDepth` to make sure metavariables at `majorType` are not assigned.
For example, given `major : Eq ?x y`, we don't want to apply K by assigning `?x := y`.
-/
if (β withAtLeastTransparency TransparencyMode.default <| withNewMCtxDepth <| isDefEq majorType newType) then
return newCtorApp
else
return major
/--
Create the `i`th projection `major`. It tries to use the auto-generated projection functions if available. Otherwise falls back
to `Expr.proj`.
-/
def mkProjFn (ctorVal : ConstructorVal) (us : List Level) (params : Array Expr) (i : Nat) (major : Expr) : CoreM Expr := do
match getStructureInfo? (β getEnv) ctorVal.induct with
| none => return mkProj ctorVal.induct i major
| some info => match info.getProjFn? i with
| none => return mkProj ctorVal.induct i major
| some projFn => return mkApp (mkAppN (mkConst projFn us) params) major
/--
If `major` is not a constructor application, and its type is a structure `C ...`, then return `C.mk major.1 ... major.n`
\pre `inductName` is `C`.
If `Meta.Config.etaStruct` is `false` or the condition above does not hold, this method just returns `major`. -/
private def toCtorWhenStructure (inductName : Name) (major : Expr) : MetaM Expr := do
unless (β useEtaStruct inductName) do
return major
let env β getEnv
if !isStructureLike env inductName then
return major
else if let some _ := major.isConstructorApp? env then
return major
else
let majorType β inferType major
let majorType β instantiateMVars (β whnf majorType)
let majorTypeI := majorType.getAppFn
if !majorTypeI.isConstOf inductName then
return major
match majorType.getAppFn with
| Expr.const d us =>
if (β whnfD (β inferType majorType)) == mkSort levelZero then
return major -- We do not perform eta for propositions, see implementation in the kernel
else
let some ctorName β getFirstCtor d | pure major
let ctorInfo β getConstInfoCtor ctorName
let params := majorType.getAppArgs.shrink ctorInfo.numParams
let mut result := mkAppN (mkConst ctorName us) params
for i in [:ctorInfo.numFields] do
result := mkApp result (β mkProjFn ctorInfo us params i major)
return result
| _ => return major
/-- Auxiliary function for reducing recursor applications. -/
private def reduceRec (recVal : RecursorVal) (recLvls : List Level) (recArgs : Array Expr) (failK : Unit β MetaM Ξ±) (successK : Expr β MetaM Ξ±) : MetaM Ξ± :=
let majorIdx := recVal.getMajorIdx
if h : majorIdx < recArgs.size then do
let major := recArgs.get β¨majorIdx, hβ©
let mut major β whnf major
if recVal.k then
major β toCtorWhenK recVal major
major := major.toCtorIfLit
major β toCtorWhenStructure recVal.getInduct major
match getRecRuleFor recVal major with
| some rule =>
let majorArgs := major.getAppArgs
if recLvls.length != recVal.levelParams.length then
failK ()
else
let rhs := rule.rhs.instantiateLevelParams recVal.levelParams recLvls
-- Apply parameters, motives and minor premises from recursor application.
let rhs := mkAppRange rhs 0 (recVal.numParams+recVal.numMotives+recVal.numMinors) recArgs
/- The number of parameters in the constructor is not necessarily
equal to the number of parameters in the recursor when we have
nested inductive types. -/
let nparams := majorArgs.size - rule.nfields
let rhs := mkAppRange rhs nparams majorArgs.size majorArgs
let rhs := mkAppRange rhs (majorIdx + 1) recArgs.size recArgs
successK rhs
| none => failK ()
else
failK ()
-- ===========================
/-! # Helper functions for reducing Quot.lift and Quot.ind -/
-- ===========================
/-- Auxiliary function for reducing `Quot.lift` and `Quot.ind` applications. -/
private def reduceQuotRec (recVal : QuotVal) (recLvls : List Level) (recArgs : Array Expr) (failK : Unit β MetaM Ξ±) (successK : Expr β MetaM Ξ±) : MetaM Ξ± :=
let process (majorPos argPos : Nat) : MetaM Ξ± :=
if h : majorPos < recArgs.size then do
let major := recArgs.get β¨majorPos, hβ©
let major β whnf major
match major with
| Expr.app (Expr.app (Expr.app (Expr.const majorFn _) _) _) majorArg => do
let some (ConstantInfo.quotInfo { kind := QuotKind.ctor, .. }) β getConstNoEx? majorFn | failK ()
let f := recArgs[argPos]!
let r := mkApp f majorArg
let recArity := majorPos + 1
successK <| mkAppRange r recArity recArgs.size recArgs
| _ => failK ()
else
failK ()
match recVal.kind with
| QuotKind.lift => process 5 3
| QuotKind.ind => process 4 3
| _ => failK ()
-- ===========================
/-! # Helper function for extracting "stuck term" -/
-- ===========================
mutual
private partial def isRecStuck? (recVal : RecursorVal) (recArgs : Array Expr) : MetaM (Option MVarId) :=
if recVal.k then
-- TODO: improve this case
return none
else do
let majorIdx := recVal.getMajorIdx
if h : majorIdx < recArgs.size then do
let major := recArgs.get β¨majorIdx, hβ©
let major β whnf major
getStuckMVar? major
else
return none
private partial def isQuotRecStuck? (recVal : QuotVal) (recArgs : Array Expr) : MetaM (Option MVarId) :=
let process? (majorPos : Nat) : MetaM (Option MVarId) :=
if h : majorPos < recArgs.size then do
let major := recArgs.get β¨majorPos, hβ©
let major β whnf major
getStuckMVar? major
else
return none
match recVal.kind with
| QuotKind.lift => process? 5
| QuotKind.ind => process? 4
| _ => return none
/-- Return `some (Expr.mvar mvarId)` if metavariable `mvarId` is blocking reduction. -/
partial def getStuckMVar? (e : Expr) : MetaM (Option MVarId) := do
match e with
| .mdata _ e => getStuckMVar? e
| .proj _ _ e => getStuckMVar? (β whnf e)
| .mvar .. =>
let e β instantiateMVars e
match e with
| .mvar mvarId => return some mvarId
| _ => getStuckMVar? e
| .app f .. =>
let f := f.getAppFn
match f with
| .mvar .. =>
let e β instantiateMVars e
match e.getAppFn with
| .mvar mvarId => return some mvarId
| _ => getStuckMVar? e
| .const fName _ =>
match (β getConstNoEx? fName) with
| some <| .recInfo recVal => isRecStuck? recVal e.getAppArgs
| some <| .quotInfo recVal => isQuotRecStuck? recVal e.getAppArgs
| _ =>
unless e.hasExprMVar do return none
-- Projection function support
let some projInfo β getProjectionFnInfo? fName | return none
-- This branch is relevant if `e` is a type class projection that is stuck because the instance has not been synthesized yet.
unless projInfo.fromClass do return none
let args := e.getAppArgs
-- First check whether `e`s instance is stuck.
if let some major := args.get? projInfo.numParams then
if let some mvarId β getStuckMVar? major then
return mvarId
/-
Then, recurse on the explicit arguments
We want to detect the stuck instance in terms such as
`HAdd.hAdd Nat Nat Nat (instHAdd Nat instAddNat) n (OfNat.ofNat Nat 2 ?m)`
See issue https://github.com/leanprover/lean4/issues/1408 for an example where this is needed.
-/
let info β getFunInfo f
for pinfo in info.paramInfo, arg in args do
if pinfo.isExplicit then
if let some mvarId β getStuckMVar? arg then
return some mvarId
return none
| .proj _ _ e => getStuckMVar? (β whnf e)
| _ => return none
| _ => return none
end
-- ===========================
/-! # Weak Head Normal Form auxiliary combinators -/
-- ===========================
/-- Auxiliary combinator for handling easy WHNF cases. It takes a function for handling the "hard" cases as an argument -/
@[specialize] partial def whnfEasyCases (e : Expr) (k : Expr β MetaM Expr) : MetaM Expr := do
match e with
| .forallE .. => return e
| .lam .. => return e
| .sort .. => return e
| .lit .. => return e
| .bvar .. => unreachable!
| .letE .. => k e
| .const .. => k e
| .app .. => k e
| .proj .. => k e
| .mdata _ e => whnfEasyCases e k
| .fvar fvarId =>
let decl β fvarId.getDecl
match decl with
| .cdecl .. => return e
| .ldecl (value := v) (nonDep := nonDep) .. =>
let cfg β getConfig
if nonDep && !cfg.zetaNonDep then
return e
else
if cfg.trackZeta then
modify fun s => { s with zetaFVarIds := s.zetaFVarIds.insert fvarId }
whnfEasyCases v k
| .mvar mvarId =>
match (β getExprMVarAssignment? mvarId) with
| some v => whnfEasyCases v k
| none => return e
@[specialize] private def deltaDefinition (c : ConstantInfo) (lvls : List Level)
(failK : Unit β MetaM Ξ±) (successK : Expr β MetaM Ξ±) : MetaM Ξ± := do
if c.levelParams.length != lvls.length then
failK ()
else
successK (β instantiateValueLevelParams c lvls)
@[specialize] private def deltaBetaDefinition (c : ConstantInfo) (lvls : List Level) (revArgs : Array Expr)
(failK : Unit β MetaM Ξ±) (successK : Expr β MetaM Ξ±) (preserveMData := false) : MetaM Ξ± := do
if c.levelParams.length != lvls.length then
failK ()
else
let val β instantiateValueLevelParams c lvls
let val := val.betaRev revArgs (preserveMData := preserveMData)
successK val
inductive ReduceMatcherResult where
| reduced (val : Expr)
| stuck (val : Expr)
| notMatcher
| partialApp
/--
The "match" compiler uses `if-then-else` expressions and other auxiliary declarations to compile match-expressions such as
```
match v with
| 'a' => 1
| 'b' => 2
| _ => 3
```
because it is more efficient than using `casesOn` recursors.
The method `reduceMatcher?` fails if these auxiliary definitions (e.g., `ite`) cannot be unfolded in the current
transparency setting. This is problematic because tactics such as `simp` use `TransparencyMode.reducible`, and
most users assume that expressions such as
```
match 0 with
| 0 => 1
| 100 => 2
| _ => 3
```
should reduce in any transparency mode.
Thus, we define a custom `canUnfoldAtMatcher` predicate for `whnfMatcher`.
This solution is not very modular because modications at the `match` compiler require changes here.
We claim this is defensible because it is reducing the auxiliary declaration defined by the `match` compiler.
Alternative solution: tactics that use `TransparencyMode.reducible` should rely on the equations we generated for match-expressions.
This solution is also not perfect because the match-expression above will not reduce during type checking when we are not using
`TransparencyMode.default` or `TransparencyMode.all`.
-/
def canUnfoldAtMatcher (cfg : Config) (info : ConstantInfo) : CoreM Bool := do
match cfg.transparency with
| TransparencyMode.all => return true
| TransparencyMode.default => return true
| _ =>
if (β isReducible info.name) || isGlobalInstance (β getEnv) info.name then
return true
else if hasMatchPatternAttribute (β getEnv) info.name then
return true
else
return info.name == ``ite
|| info.name == ``dite
|| info.name == ``decEq
|| info.name == ``Nat.decEq
|| info.name == ``Char.ofNat || info.name == ``Char.ofNatAux
|| info.name == ``String.decEq || info.name == ``List.hasDecEq
|| info.name == ``Fin.ofNat
|| info.name == ``UInt8.ofNat || info.name == ``UInt8.decEq
|| info.name == ``UInt16.ofNat || info.name == ``UInt16.decEq
|| info.name == ``UInt32.ofNat || info.name == ``UInt32.decEq
|| info.name == ``UInt64.ofNat || info.name == ``UInt64.decEq
/- Remark: we need to unfold the following two definitions because they are used for `Fin`, and
lazy unfolding at `isDefEq` does not unfold projections. -/
|| info.name == ``HMod.hMod || info.name == ``Mod.mod
private def whnfMatcher (e : Expr) : MetaM Expr := do
/- When reducing `match` expressions, if the reducibility setting is at `TransparencyMode.reducible`,
we increase it to `TransparencyMode.instance`. We use the `TransparencyMode.reducible` in many places (e.g., `simp`),
and this setting prevents us from reducing `match` expressions where the discriminants are terms such as `OfNat.ofNat Ξ± n inst`.
For example, `simp [Int.div]` will not unfold the application `Int.div 2 1` occuring in the target.
TODO: consider other solutions; investigate whether the solution above produces counterintuitive behavior. -/
let mut transparency β getTransparency
if transparency == TransparencyMode.reducible then
transparency := TransparencyMode.instances
withTransparency transparency <| withReader (fun ctx => { ctx with canUnfold? := canUnfoldAtMatcher }) do
whnf e
def reduceMatcher? (e : Expr) : MetaM ReduceMatcherResult := do
match e.getAppFn with
| Expr.const declName declLevels =>
let some info β getMatcherInfo? declName
| return ReduceMatcherResult.notMatcher
let args := e.getAppArgs
let prefixSz := info.numParams + 1 + info.numDiscrs
if args.size < prefixSz + info.numAlts then
return ReduceMatcherResult.partialApp
else
let constInfo β getConstInfo declName
let f β instantiateValueLevelParams constInfo declLevels
let auxApp := mkAppN f args[0:prefixSz]
let auxAppType β inferType auxApp
forallBoundedTelescope auxAppType info.numAlts fun hs _ => do
let auxApp β whnfMatcher (mkAppN auxApp hs)
let auxAppFn := auxApp.getAppFn
let mut i := prefixSz
for h in hs do
if auxAppFn == h then
let result := mkAppN args[i]! auxApp.getAppArgs
let result := mkAppN result args[prefixSz + info.numAlts:args.size]
return ReduceMatcherResult.reduced result.headBeta
i := i + 1
return ReduceMatcherResult.stuck auxApp
| _ => pure ReduceMatcherResult.notMatcher
private def projectCore? (e : Expr) (i : Nat) : MetaM (Option Expr) := do
let e := e.toCtorIfLit
matchConstCtor e.getAppFn (fun _ => pure none) fun ctorVal _ =>
let numArgs := e.getAppNumArgs
let idx := ctorVal.numParams + i
if idx < numArgs then
return some (e.getArg! idx)
else
return none
def project? (e : Expr) (i : Nat) : MetaM (Option Expr) := do
projectCore? (β whnf e) i
/-- Reduce kernel projection `Expr.proj ..` expression. -/
def reduceProj? (e : Expr) : MetaM (Option Expr) := do
match e with
| Expr.proj _ i c => project? c i
| _ => return none
/--
Auxiliary method for reducing terms of the form `?m t_1 ... t_n` where `?m` is delayed assigned.
Recall that we can only expand a delayed assignment when all holes/metavariables in the assigned value have been "filled".
-/
private def whnfDelayedAssigned? (f' : Expr) (e : Expr) : MetaM (Option Expr) := do
if f'.isMVar then
match (β getDelayedMVarAssignment? f'.mvarId!) with
| none => return none
| some { fvars, mvarIdPending } =>
let args := e.getAppArgs
if fvars.size > args.size then
-- Insufficient number of argument to expand delayed assignment
return none
else
let newVal β instantiateMVars (mkMVar mvarIdPending)
if newVal.hasExprMVar then
-- Delayed assignment still contains metavariables
return none
else
let newVal := newVal.abstract fvars
let result := newVal.instantiateRevRange 0 fvars.size args
return mkAppRange result fvars.size args.size args
else
return none
/--
Apply beta-reduction, zeta-reduction (i.e., unfold let local-decls), iota-reduction,
expand let-expressions, expand assigned meta-variables.
The parameter `deltaAtProj` controls how to reduce projections `s.i`. If `deltaAtProj == true`,
then delta reduction is used to reduce `s` (i.e., `whnf` is used), otherwise `whnfCore`.
We only set this flag to `false` when implementing `isDefEq`.
-/
partial def whnfCore (e : Expr) (deltaAtProj : Bool := true) : MetaM Expr :=
go e
where
go (e : Expr) : MetaM Expr :=
whnfEasyCases e fun e => do
trace[Meta.whnf] e
match e with
| Expr.const .. => pure e
| Expr.letE _ _ v b _ => go <| b.instantiate1 v
| Expr.app f .. =>
let f := f.getAppFn
let f' β go f
if f'.isLambda then
let revArgs := e.getAppRevArgs
go <| f'.betaRev revArgs
else if let some eNew β whnfDelayedAssigned? f' e then
go eNew
else
let e := if f == f' then e else e.updateFn f'
match (β reduceMatcher? e) with
| ReduceMatcherResult.reduced eNew => go eNew
| ReduceMatcherResult.partialApp => pure e
| ReduceMatcherResult.stuck _ => pure e
| ReduceMatcherResult.notMatcher =>
matchConstAux f' (fun _ => return e) fun cinfo lvls =>
match cinfo with
| ConstantInfo.recInfo rec => reduceRec rec lvls e.getAppArgs (fun _ => return e) go
| ConstantInfo.quotInfo rec => reduceQuotRec rec lvls e.getAppArgs (fun _ => return e) go
| c@(ConstantInfo.defnInfo _) => do
if (β isAuxDef c.name) then
deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => return e) go
else
return e
| _ => return e
| Expr.proj _ i c =>
let c β if deltaAtProj then whnf c else whnfCore c
match (β projectCore? c i) with
| some e => go e
| none => return e
| _ => unreachable!
/--
Recall that `_sunfold` auxiliary definitions contains the markers: `markSmartUnfoldingMatch` (*) and `markSmartUnfoldingMatchAlt` (**).
For example, consider the following definition
```
def r (i j : Nat) : Nat :=
i +
match j with
| Nat.zero => 1
| Nat.succ j =>
i + match j with
| Nat.zero => 2
| Nat.succ j => r i j
```
produces the following `_sunfold` auxiliary definition with the markers
```
def r._sunfold (i j : Nat) : Nat :=
i +
(*) match j with
| Nat.zero => (**) 1
| Nat.succ j =>
i + (*) match j with
| Nat.zero => (**) 2
| Nat.succ j => (**) r i j
```
`match` expressions marked with `markSmartUnfoldingMatch` (*) must be reduced, otherwise the resulting term is not definitionally
equal to the given expression. The recursion may be interrupted as soon as the annotation `markSmartUnfoldingAlt` (**) is reached.
For example, the term `r i j.succ.succ` reduces to the definitionally equal term `i + i * r i j`
-/
partial def smartUnfoldingReduce? (e : Expr) : MetaM (Option Expr) :=
go e |>.run
where
go (e : Expr) : OptionT MetaM Expr := do
match e with
| Expr.letE n t v b _ => withLetDecl n t (β go v) fun x => do mkLetFVars #[x] (β go (b.instantiate1 x))
| Expr.lam .. => lambdaTelescope e fun xs b => do mkLambdaFVars xs (β go b)
| Expr.app f a .. => return mkApp (β go f) (β go a)
| Expr.proj _ _ s => return e.updateProj! (β go s)
| Expr.mdata _ b =>
if let some m := smartUnfoldingMatch? e then
goMatch m
else
return e.updateMData! (β go b)
| _ => return e
goMatch (e : Expr) : OptionT MetaM Expr := do
match (β reduceMatcher? e) with
| ReduceMatcherResult.reduced e =>
if let some alt := smartUnfoldingMatchAlt? e then
return alt
else
go e
| ReduceMatcherResult.stuck e' =>
let mvarId β getStuckMVar? e'
/- Try to "unstuck" by resolving pending TC problems -/
if (β Meta.synthPending mvarId) then
goMatch e
else
failure
| _ => failure
mutual
/--
Auxiliary method for unfolding a class projection.
-/
partial def unfoldProjInst? (e : Expr) : MetaM (Option Expr) := do
match e.getAppFn with
| Expr.const declName .. =>
match (β getProjectionFnInfo? declName) with
| some { fromClass := true, .. } =>
match (β withDefault <| unfoldDefinition? e) with
| none => return none
| some e =>
match (β withReducibleAndInstances <| reduceProj? e.getAppFn) with
| none => return none
| some r => return mkAppN r e.getAppArgs |>.headBeta
| _ => return none
| _ => return none
/--
Auxiliary method for unfolding a class projection. when transparency is set to `TransparencyMode.instances`.
Recall that class instance projections are not marked with `[reducible]` because we want them to be
in "reducible canonical form".
-/
partial def unfoldProjInstWhenIntances? (e : Expr) : MetaM (Option Expr) := do
if (β getTransparency) != TransparencyMode.instances then
return none
else
unfoldProjInst? e
/-- Unfold definition using "smart unfolding" if possible. -/
partial def unfoldDefinition? (e : Expr) : MetaM (Option Expr) :=
match e with
| Expr.app f _ =>
matchConstAux f.getAppFn (fun _ => unfoldProjInstWhenIntances? e) fun fInfo fLvls => do
if fInfo.levelParams.length != fLvls.length then
return none
else
let unfoldDefault (_ : Unit) : MetaM (Option Expr) :=
if fInfo.hasValue then
deltaBetaDefinition fInfo fLvls e.getAppRevArgs (fun _ => pure none) (fun e => pure (some e))
else
return none
if smartUnfolding.get (β getOptions) then
match ((β getEnv).find? (mkSmartUnfoldingNameFor fInfo.name)) with
| some fAuxInfo@(ConstantInfo.defnInfo _) =>
-- We use `preserveMData := true` to make sure the smart unfolding annotation are not erased in an over-application.
deltaBetaDefinition fAuxInfo fLvls e.getAppRevArgs (preserveMData := true) (fun _ => pure none) fun eβ => do
let some r β smartUnfoldingReduce? eβ | return none
/-
If `smartUnfoldingReduce?` succeeds, we should still check whether the argument the
structural recursion is recursing on reduces to a constructor.
This extra check is necessary in definitions (see issue #1081) such as
```
inductive Vector (Ξ± : Type u) : Nat β Type u where
| nil : Vector Ξ± 0
| cons : Ξ± β Vector Ξ± n β Vector Ξ± (n+1)
def Vector.insert (a: Ξ±) (i : Fin (n+1)) (xs : Vector Ξ± n) : Vector Ξ± (n+1) :=
match i, xs with
| β¨0, _β©, xs => cons a xs
| β¨i+1, hβ©, cons x xs => cons x (xs.insert a β¨i, Nat.lt_of_succ_lt_succ hβ©)
```
The structural recursion is being performed using the vector `xs`. That is, we used `Vector.brecOn` to define
`Vector.insert`. Thus, an application `xs.insert a β¨0, hβ©` is **not** definitionally equal to
`Vector.cons a xs` because `xs` is not a constructor application (the `Vector.brecOn` application is blocked).
Remark 1: performing structural recursion on `Fin (n+1)` is not an option here because it is a `Subtype` and
and the repacking in recursive applications confuses the structural recursion module.
Remark 2: the match expression reduces reduces to `cons a xs` when the discriminants are `β¨0, hβ©` and `xs`.
Remark 3: this check is unnecessary in most cases, but we don't need dependent elimination to trigger the issue fixed by this extra check. Here is another example that triggers the issue fixed by this check.
```
def f : Nat β Nat β Nat
| 0, y => y
| x+1, y+1 => f (x-2) y
| x+1, 0 => 0
theorem ex : f 0 y = y := rfl
```
Remark 4: the `return some r` in the following `let` is not a typo. Binport generated .olean files do not
store the position of recursive arguments for definitions using structural recursion.
Thus, we should keep `return some r` until Mathlib has been ported to Lean 3.
Note that the `Vector` example above does not even work in Lean 3.
-/
let some recArgPos β getStructuralRecArgPos? fInfo.name | return some r
let numArgs := e.getAppNumArgs
if recArgPos >= numArgs then return none
let recArg := e.getArg! recArgPos numArgs
if !(β whnfMatcher recArg).isConstructorApp (β getEnv) then return none
return some r
| _ =>
if (β getMatcherInfo? fInfo.name).isSome then
-- Recall that `whnfCore` tries to reduce "matcher" applications.
return none
else
unfoldDefault ()
else
unfoldDefault ()
| Expr.const declName lvls => do
if smartUnfolding.get (β getOptions) && (β getEnv).contains (mkSmartUnfoldingNameFor declName) then
return none
else
let (some (cinfo@(ConstantInfo.defnInfo _))) β getConstNoEx? declName | pure none
deltaDefinition cinfo lvls
(fun _ => pure none)
(fun e => pure (some e))
| _ => return none
end
def unfoldDefinition (e : Expr) : MetaM Expr := do
let some e β unfoldDefinition? e | throwError "failed to unfold definition{indentExpr e}"
return e
@[specialize] partial def whnfHeadPred (e : Expr) (pred : Expr β MetaM Bool) : MetaM Expr :=
whnfEasyCases e fun e => do
let e β whnfCore e
if (β pred e) then
match (β unfoldDefinition? e) with
| some e => whnfHeadPred e pred
| none => return e
else
return e
def whnfUntil (e : Expr) (declName : Name) : MetaM (Option Expr) := do
let e β whnfHeadPred e (fun e => return !e.isAppOf declName)
if e.isAppOf declName then
return e
else
return none
/-- Try to reduce matcher/recursor/quot applications. We say they are all "morally" recursor applications. -/
def reduceRecMatcher? (e : Expr) : MetaM (Option Expr) := do
if !e.isApp then
return none
else match (β reduceMatcher? e) with
| ReduceMatcherResult.reduced e => return e
| _ => matchConstAux e.getAppFn (fun _ => pure none) fun cinfo lvls => do
match cinfo with
| ConstantInfo.recInfo Β«recΒ» => reduceRec Β«recΒ» lvls e.getAppArgs (fun _ => pure none) (fun e => pure (some e))
| ConstantInfo.quotInfo Β«recΒ» => reduceQuotRec Β«recΒ» lvls e.getAppArgs (fun _ => pure none) (fun e => pure (some e))
| c@(ConstantInfo.defnInfo _) =>
if (β isAuxDef c.name) then
deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => pure none) (fun e => pure (some e))
else
return none
| _ => return none
unsafe def reduceBoolNativeUnsafe (constName : Name) : MetaM Bool := evalConstCheck Bool `Bool constName
unsafe def reduceNatNativeUnsafe (constName : Name) : MetaM Nat := evalConstCheck Nat `Nat constName
@[implementedBy reduceBoolNativeUnsafe] opaque reduceBoolNative (constName : Name) : MetaM Bool
@[implementedBy reduceNatNativeUnsafe] opaque reduceNatNative (constName : Name) : MetaM Nat
def reduceNative? (e : Expr) : MetaM (Option Expr) :=
match e with
| Expr.app (Expr.const fName _) (Expr.const argName _) =>
if fName == ``Lean.reduceBool then do
return toExpr (β reduceBoolNative argName)
else if fName == ``Lean.reduceNat then do
return toExpr (β reduceNatNative argName)
else
return none
| _ =>
return none
@[inline] def withNatValue {Ξ±} (a : Expr) (k : Nat β MetaM (Option Ξ±)) : MetaM (Option Ξ±) := do
let a β whnf a
match a with
| Expr.const `Nat.zero _ => k 0
| Expr.lit (Literal.natVal v) => k v
| _ => return none
def reduceUnaryNatOp (f : Nat β Nat) (a : Expr) : MetaM (Option Expr) :=
withNatValue a fun a =>
return mkRawNatLit <| f a
def reduceBinNatOp (f : Nat β Nat β Nat) (a b : Expr) : MetaM (Option Expr) :=
withNatValue a fun a =>
withNatValue b fun b => do
trace[Meta.isDefEq.whnf.reduceBinOp] "{a} op {b}"
return mkRawNatLit <| f a b
def reduceBinNatPred (f : Nat β Nat β Bool) (a b : Expr) : MetaM (Option Expr) := do
withNatValue a fun a =>
withNatValue b fun b =>
return toExpr <| f a b
def reduceNat? (e : Expr) : MetaM (Option Expr) :=
if e.hasFVar || e.hasMVar then
return none
else match e with
| Expr.app (Expr.const fn _) a =>
if fn == ``Nat.succ then
reduceUnaryNatOp Nat.succ a
else
return none
| Expr.app (Expr.app (Expr.const fn _) a1) a2 =>
if fn == ``Nat.add then reduceBinNatOp Nat.add a1 a2
else if fn == ``Nat.sub then reduceBinNatOp Nat.sub a1 a2
else if fn == ``Nat.mul then reduceBinNatOp Nat.mul a1 a2
else if fn == ``Nat.div then reduceBinNatOp Nat.div a1 a2
else if fn == ``Nat.mod then reduceBinNatOp Nat.mod a1 a2
else if fn == ``Nat.beq then reduceBinNatPred Nat.beq a1 a2
else if fn == ``Nat.ble then reduceBinNatPred Nat.ble a1 a2
else return none
| _ =>
return none
@[inline] private def useWHNFCache (e : Expr) : MetaM Bool := do
-- We cache only closed terms without expr metavars.
-- Potential refinement: cache if `e` is not stuck at a metavariable
if e.hasFVar || e.hasExprMVar || (β read).canUnfold?.isSome then
return false
else
match (β getConfig).transparency with
| TransparencyMode.default => return true
| TransparencyMode.all => return true
| _ => return false
@[inline] private def cached? (useCache : Bool) (e : Expr) : MetaM (Option Expr) := do
if useCache then
match (β getConfig).transparency with
| TransparencyMode.default => return (β get).cache.whnfDefault.find? e
| TransparencyMode.all => return (β get).cache.whnfAll.find? e
| _ => unreachable!
else
return none
private def cache (useCache : Bool) (e r : Expr) : MetaM Expr := do
if useCache then
match (β getConfig).transparency with
| TransparencyMode.default => modify fun s => { s with cache.whnfDefault := s.cache.whnfDefault.insert e r }
| TransparencyMode.all => modify fun s => { s with cache.whnfAll := s.cache.whnfAll.insert e r }
| _ => unreachable!
return r
@[export lean_whnf]
partial def whnfImp (e : Expr) : MetaM Expr :=
withIncRecDepth <| whnfEasyCases e fun e => do
checkMaxHeartbeats "whnf"
let useCache β useWHNFCache e
match (β cached? useCache e) with
| some e' => pure e'
| none =>
let e' β whnfCore e
match (β reduceNat? e') with
| some v => cache useCache e v
| none =>
match (β reduceNative? e') with
| some v => cache useCache e v
| none =>
match (β unfoldDefinition? e') with
| some e => whnfImp e
| none => cache useCache e e'
/-- If `e` is a projection function that satisfies `p`, then reduce it -/
def reduceProjOf? (e : Expr) (p : Name β Bool) : MetaM (Option Expr) := do
if !e.isApp then
pure none
else match e.getAppFn with
| Expr.const name .. => do
let env β getEnv
match env.getProjectionStructureName? name with
| some structName =>
if p structName then
Meta.unfoldDefinition? e
else
pure none
| none => pure none
| _ => pure none
builtin_initialize
registerTraceClass `Meta.whnf
registerTraceClass `Meta.isDefEq.whnf.reduceBinOp
end Lean.Meta
|
290f7e0cdaed6e1de517cc979d0e01ffd276b626
|
b70031c8e2c5337b91d7e70f1e0c5f528f7b0e77
|
/src/data/matrix/char_p.lean
|
a68b50a620dafaec545dc5b87407c86a300c18ed
|
[
"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
| 580
|
lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import data.matrix.basic
import algebra.char_p
/-!
# Matrices in prime characteristic
-/
open matrix
variables {n : Type*} [fintype n] {R : Type*} [ring R]
instance matrix.char_p [decidable_eq n] [nonempty n] (p : β) [char_p R p] :
char_p (matrix n n R) p :=
β¨begin
intro k,
rw [β char_p.cast_eq_zero_iff R p k, β nat.cast_zero, β (scalar n).map_nat_cast],
convert scalar_inj, {simp}, {assumption}
endβ©
|
476bcdd4338d10146daee29cfeb193bc82c3dec8
|
36938939954e91f23dec66a02728db08a7acfcf9
|
/lean/deps/galois_stdlib/src/galois/algebra/ordered_group.lean
|
d6c8c9d6c0da94c0c1291f877d6146aaf3940574
|
[
"Apache-2.0"
] |
permissive
|
pnwamk/reopt-vcg
|
f8b56dd0279392a5e1c6aee721be8138e6b558d3
|
c9f9f185fbefc25c36c4b506bbc85fd1a03c3b6d
|
refs/heads/master
| 1,631,145,017,772
| 1,593,549,019,000
| 1,593,549,143,000
| 254,191,418
| 0
| 0
| null | 1,586,377,077,000
| 1,586,377,077,000
| null |
UTF-8
|
Lean
| false
| false
| 1,066
|
lean
|
namespace galois
section ordered_cancel_comm_monoid
universe u
variable {Ξ± : Type u}
variables [ordered_cancel_comm_monoid Ξ±] {a b c : Ξ±}
@[simp] lemma add_le_add_iff_left (a : Ξ±) {b c : Ξ±} : a + b β€ a + c β b β€ c :=
β¨le_of_add_le_add_left, Ξ» h, add_le_add_left h _β©
@[simp] lemma add_le_add_iff_right (c : Ξ±) : a + c β€ b + c β a β€ b :=
add_comm c a βΈ add_comm c b βΈ add_le_add_iff_left c
@[simp] lemma add_lt_add_iff_left (a : Ξ±) {b c : Ξ±} : a + b < a + c β b < c :=
β¨lt_of_add_lt_add_left, Ξ» h, add_lt_add_left h _β©
@[simp] lemma add_lt_add_iff_right (c : Ξ±) : a + c < b + c β a < b :=
add_comm c a βΈ add_comm c b βΈ add_lt_add_iff_left c
@[simp] lemma le_add_iff_nonneg_right (a : Ξ±) {b : Ξ±} : a β€ a + b β 0 β€ b :=
have a + 0 β€ a + b β 0 β€ b, from add_le_add_iff_left a,
by rwa add_zero at this
@[simp] lemma lt_add_iff_pos_right (a : Ξ±) {b : Ξ±} : a < a + b β 0 < b :=
have a + 0 < a + b β 0 < b, from add_lt_add_iff_left a,
by rwa add_zero at this
end ordered_cancel_comm_monoid
end galois
|
38c123af41a1f5116085e4a2434ea210ae78327b
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/interactive/hole4.lean
|
23b32790f6481d5d4dfd0a95bd07c4892f012629
|
[
"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
| 78
|
lean
|
def x : nat β nat :=
{! Ξ» a, _ !}
--^ "command": "hole", "action": "Use"
|
46c8f382cabc33d50343d3f3252313ada3050945
|
ea4aee6b11f86433e69bb5e50d0259e056d0ae61
|
/src/tidy/loop_detection.lean
|
fbdc72c2f18f498dd7a36266d9279655a2d45499
|
[] |
no_license
|
timjb/lean-tidy
|
e18feff0b7f0aad08c614fb4d34aaf527bf21e20
|
e767e259bf76c69edfd4ab8af1b76e6f1ed67f48
|
refs/heads/master
| 1,624,861,693,182
| 1,504,411,006,000
| 1,504,411,006,000
| 103,740,824
| 0
| 0
| null | 1,505,553,968,000
| 1,505,553,968,000
| null |
UTF-8
|
Lean
| false
| false
| 3,205
|
lean
|
-- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import .tactic_states
import .hash_target
open tactic
universe variables u v
structure loop_detection_state :=
( allowed_collisions : nat )
( past_goals : list string )
meta def unreachable {Ξ± : Sort u} : Ξ± := undefined_core "unreachable"
meta def detect_looping
{ Ο Ξ± : Type }
[ underlying_tactic_state Ο ]
( t : interaction_monad (Ο Γ loop_detection_state) Ξ± )
( allowed_collisions : nat := 0 )
: interaction_monad Ο Ξ± :=
Ξ» s, match (hash_target s) with
| result.success hash s' := (t (s, β¨ allowed_collisions, [ hash ] β© )).map(Ξ» s'', s''.1)
| result.exception pos msg s' := unreachable
end
meta def instrument_for_loop_detection { Ο Ξ± : Type } [uts : underlying_tactic_state Ο] ( t : interaction_monad Ο Ξ± ) : interaction_monad (Ο Γ loop_detection_state) Ξ± :=
Ξ» (s : Ο Γ loop_detection_state),
match t s.1 with
| result.success a s' := match (hash_target (@underlying_tactic_state.to_tactic_state _ uts s')) with -- FIXME why doesn't the coercion work? why can't Lean find uts itself?
| result.success hash s'' := if s.2.past_goals.mem hash then
if s.2.allowed_collisions > 0 then
result.success a (s', β¨ s.2.allowed_collisions - 1, s.2.past_goals β© )
else
match (@tactic.fail Ξ± string _ ("detected looping" /-++ "\n" ++ s.2.past_goals.to_string ++ "\n" ++ hash-/)) s'' with -- FIXME this duplicates code above
| result.success a s''' := unreachable
| result.exception pos msg s''' := result.exception pos msg (s', s.2)
end
else
result.success a (s', β¨ s.2.allowed_collisions, hash :: s.2.past_goals β© )
| _ := unreachable
end
| result.exception msg pos s' := result.exception msg pos (s', s.2)
end
meta instance lift_to_loop_detection_tactic : tactic_lift loop_detection_state :=
β¨ Ξ» { Ο Ξ± : Type } [uts : underlying_tactic_state Ο], @instrument_for_loop_detection Ο Ξ± uts β©
meta def interactive_simp := `[simp]
lemma looping_test_1 (a : empty): 1 = 1 :=
begin
success_if_fail { detect_looping $ skip },
success_if_fail { detect_looping $ skip >> skip },
refl
end
lemma looping_test_2 (a : empty): 1 = 1 :=
begin
detect_looping $ interactive_simp
end
|
0955069b6bbffb45b2129cac895062dbd39bfc23
|
82e44445c70db0f03e30d7be725775f122d72f3e
|
/src/analysis/normed_space/multilinear.lean
|
4524c1722d310e44626380910a9fa92751edacc9
|
[
"Apache-2.0"
] |
permissive
|
stjordanis/mathlib
|
51e286d19140e3788ef2c470bc7b953e4991f0c9
|
2568d41bca08f5d6bf39d915434c8447e21f42ee
|
refs/heads/master
| 1,631,748,053,501
| 1,627,938,886,000
| 1,627,938,886,000
| 228,728,358
| 0
| 0
|
Apache-2.0
| 1,576,630,588,000
| 1,576,630,587,000
| null |
UTF-8
|
Lean
| false
| false
| 73,395
|
lean
|
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import analysis.normed_space.operator_norm
import topology.algebra.multilinear
/-!
# Operator norm on the space of continuous multilinear maps
When `f` is a continuous multilinear map in finitely many variables, we define its norm `β₯fβ₯` as the
smallest number such that `β₯f mβ₯ β€ β₯fβ₯ * β i, β₯m iβ₯` for all `m`.
We show that it is indeed a norm, and prove its basic properties.
## Main results
Let `f` be a multilinear map in finitely many variables.
* `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0`
with `β₯f mβ₯ β€ C * β i, β₯m iβ₯` for all `m`.
* `continuous_of_bound`, conversely, asserts that this bound implies continuity.
* `mk_continuous` constructs the associated continuous multilinear map.
Let `f` be a continuous multilinear map in finitely many variables.
* `β₯fβ₯` is its norm, i.e., the smallest number such that `β₯f mβ₯ β€ β₯fβ₯ * β i, β₯m iβ₯` for
all `m`.
* `le_op_norm f m` asserts the fundamental inequality `β₯f mβ₯ β€ β₯fβ₯ * β i, β₯m iβ₯`.
* `norm_image_sub_le f mβ mβ` gives a control of the difference `f mβ - f mβ` in terms of
`β₯fβ₯` and `β₯mβ - mββ₯`.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
continuous multilinear function `f` in `n+1` variables into a continuous linear function taking
values in continuous multilinear functions in `n` variables, and also into a continuous multilinear
function in `n` variables taking values in continuous linear functions. These operations are called
`f.curry_left` and `f.curry_right` respectively (with inverses `f.uncurry_left` and
`f.uncurry_right`). They induce continuous linear equivalences between spaces of
continuous multilinear functions in `n+1` variables and spaces of continuous linear functions into
continuous multilinear functions in `n` variables (resp. continuous multilinear functions in `n`
variables taking values in continuous linear functions), called respectively
`continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`.
## Implementation notes
We mostly follow the API (and the proofs) of `operator_norm.lean`, with the additional complexity
that we should deal with multilinear maps in several variables. The currying/uncurrying
constructions are based on those in `multilinear.lean`.
From the mathematical point of view, all the results follow from the results on operator norm in
one variable, by applying them to one variable after the other through currying. However, this
is only well defined when there is an order on the variables (for instance on `fin n`) although
the final result is independent of the order. While everything could be done following this
approach, it turns out that direct proofs are easier and more efficient.
-/
noncomputable theory
open_locale classical big_operators nnreal
open finset metric
local attribute [instance, priority 1001]
add_comm_group.to_add_comm_monoid normed_group.to_add_comm_group normed_space.to_module
-- hack to speed up simp when dealing with complicated types
local attribute [-instance] unique.subsingleton pi.subsingleton
/-!
### Type variables
We use the following type variables in this file:
* `π` : a `nondiscrete_normed_field`;
* `ΞΉ`, `ΞΉ'` : finite index types with decidable equality;
* `E`, `Eβ` : families of normed vector spaces over `π` indexed by `i : ΞΉ`;
* `E'` : a family of normed vector spaces over `π` indexed by `i' : ΞΉ'`;
* `Ei` : a family of normed vector spaces over `π` indexed by `i : fin (nat.succ n)`;
* `G`, `G'` : normed vector spaces over `π`.
-/
universes u v v' wE wEβ wE' wEi wG wG'
variables {π : Type u} {ΞΉ : Type v} {ΞΉ' : Type v'} {n : β}
{E : ΞΉ β Type wE} {Eβ : ΞΉ β Type wEβ} {E' : ΞΉ' β Type wE'} {Ei : fin n.succ β Type wEi}
{G : Type wG} {G' : Type wG'}
[decidable_eq ΞΉ] [fintype ΞΉ] [decidable_eq ΞΉ'] [fintype ΞΉ'] [nondiscrete_normed_field π]
[Ξ i, normed_group (E i)] [Ξ i, normed_space π (E i)]
[Ξ i, normed_group (Eβ i)] [Ξ i, normed_space π (Eβ i)]
[Ξ i, normed_group (E' i)] [Ξ i, normed_space π (E' i)]
[Ξ i, normed_group (Ei i)] [Ξ i, normed_space π (Ei i)]
[normed_group G] [normed_space π G] [normed_group G'] [normed_space π G']
/-!
### Continuity properties of multilinear maps
We relate continuity of multilinear maps to the inequality `β₯f mβ₯ β€ C * β i, β₯m iβ₯`, in
both directions. Along the way, we prove useful bounds on the difference `β₯f mβ - f mββ₯`.
-/
namespace multilinear_map
variable (f : multilinear_map π E G)
/-- If a multilinear map in finitely many variables on normed spaces satisfies the inequality
`β₯f mβ₯ β€ C * β i, β₯m iβ₯` on a shell `Ξ΅ i / β₯c iβ₯ < β₯m iβ₯ < Ξ΅ i` for some positive numbers `Ξ΅ i`
and elements `c i : π`, `1 < β₯c iβ₯`, then it satisfies this inequality for all `m`. -/
lemma bound_of_shell {Ξ΅ : ΞΉ β β} {C : β} (hΞ΅ : β i, 0 < Ξ΅ i) {c : ΞΉ β π} (hc : β i, 1 < β₯c iβ₯)
(hf : β m : Ξ i, E i, (β i, Ξ΅ i / β₯c iβ₯ β€ β₯m iβ₯) β (β i, β₯m iβ₯ < Ξ΅ i) β β₯f mβ₯ β€ C * β i, β₯m iβ₯)
(m : Ξ i, E i) : β₯f mβ₯ β€ C * β i, β₯m iβ₯ :=
begin
rcases em (β i, m i = 0) with β¨i, hiβ©|hm; [skip, push_neg at hm],
{ simp [f.map_coord_zero i hi, prod_eq_zero (mem_univ i), hi] },
choose Ξ΄ hΞ΄0 hΞ΄m_lt hle_Ξ΄m hΞ΄inv using Ξ» i, rescale_to_shell (hc i) (hΞ΅ i) (hm i),
have hΞ΄0 : 0 < β i, β₯Ξ΄ iβ₯, from prod_pos (Ξ» i _, norm_pos_iff.2 (hΞ΄0 i)),
simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hΞ΄0]
using hf (Ξ» i, Ξ΄ i β’ m i) hle_Ξ΄m hΞ΄m_lt,
end
/-- If a multilinear map in finitely many variables on normed spaces is continuous, then it
satisfies the inequality `β₯f mβ₯ β€ C * β i, β₯m iβ₯`, for some `C` which can be chosen to be
positive. -/
theorem exists_bound_of_continuous (hf : continuous f) :
β (C : β), 0 < C β§ (β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) :=
begin
by_cases hΞΉ : nonempty ΞΉ, swap,
{ refine β¨β₯f 0β₯ + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, Ξ» m, _β©,
obtain rfl : m = 0, from funext (Ξ» i, (hΞΉ β¨iβ©).elim),
simp [univ_eq_empty.2 hΞΉ, zero_le_one] },
resetI,
obtain β¨Ξ΅ : β, Ξ΅0 : 0 < Ξ΅, hΞ΅ : β m : Ξ i, E i, β₯m - 0β₯ < Ξ΅ β β₯f m - f 0β₯ < 1β© :=
normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one,
simp only [sub_zero, f.map_zero] at hΞ΅,
rcases normed_field.exists_one_lt_norm π with β¨c, hcβ©,
have : 0 < (β₯cβ₯ / Ξ΅) ^ fintype.card ΞΉ, from pow_pos (div_pos (zero_lt_one.trans hc) Ξ΅0) _,
refine β¨_, this, _β©,
refine f.bound_of_shell (Ξ» _, Ξ΅0) (Ξ» _, hc) (Ξ» m hcm hm, _),
refine (hΞ΅ m ((pi_norm_lt_iff Ξ΅0).2 hm)).le.trans _,
rw [β div_le_iff' this, one_div, β inv_pow', inv_div, fintype.card, β prod_const],
exact prod_le_prod (Ξ» _ _, div_nonneg Ξ΅0.le (norm_nonneg _)) (Ξ» i _, hcm i)
end
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f mβ - f mβ`
using the multilinearity. Here, we give a precise but hard to use version. See
`norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads
`β₯f m - f m'β₯ β€
C * β₯m 1 - m' 1β₯ * max β₯m 2β₯ β₯m' 2β₯ * max β₯m 3β₯ β₯m' 3β₯ * ... * max β₯m nβ₯ β₯m' nβ₯ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
lemma norm_image_sub_le_of_bound' {C : β} (hC : 0 β€ C)
(H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) (mβ mβ : Ξ i, E i) :
β₯f mβ - f mββ₯ β€
C * β i, β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯ :=
begin
have A : β(s : finset ΞΉ), β₯f mβ - f (s.piecewise mβ mβ)β₯
β€ C * β i in s, β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯,
{ refine finset.induction (by simp) _,
assume i s his Hrec,
have I : β₯f (s.piecewise mβ mβ) - f ((insert i s).piecewise mβ mβ)β₯
β€ C * β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯,
{ have A : ((insert i s).piecewise mβ mβ)
= function.update (s.piecewise mβ mβ) i (mβ i) := s.piecewise_insert _ _ _,
have B : s.piecewise mβ mβ = function.update (s.piecewise mβ mβ) i (mβ i),
{ ext j,
by_cases h : j = i,
{ rw h, simp [his] },
{ simp [h] } },
rw [B, A, β f.map_sub],
apply le_trans (H _) (mul_le_mul_of_nonneg_left _ hC),
refine prod_le_prod (Ξ»j hj, norm_nonneg _) (Ξ»j hj, _),
by_cases h : j = i,
{ rw h, simp },
{ by_cases h' : j β s;
simp [h', h, le_refl] } },
calc β₯f mβ - f ((insert i s).piecewise mβ mβ)β₯ β€
β₯f mβ - f (s.piecewise mβ mβ)β₯ + β₯f (s.piecewise mβ mβ) - f ((insert i s).piecewise mβ mβ)β₯ :
by { rw [β dist_eq_norm, β dist_eq_norm, β dist_eq_norm], exact dist_triangle _ _ _ }
... β€ (C * β i in s, β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯)
+ C * β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯ :
add_le_add Hrec I
... = C * β i in insert i s, β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯ :
by simp [his, add_comm, left_distrib] },
convert A univ,
simp
end
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f mβ - f mβ`
using the multilinearity. Here, we give a usable but not very precise version. See
`norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is
`β₯f m - f m'β₯ β€ C * card ΞΉ * β₯m - m'β₯ * (max β₯mβ₯ β₯m'β₯) ^ (card ΞΉ - 1)`. -/
lemma norm_image_sub_le_of_bound {C : β} (hC : 0 β€ C)
(H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) (mβ mβ : Ξ i, E i) :
β₯f mβ - f mββ₯ β€ C * (fintype.card ΞΉ) * (max β₯mββ₯ β₯mββ₯) ^ (fintype.card ΞΉ - 1) * β₯mβ - mββ₯ :=
begin
have A : β (i : ΞΉ), β j, (if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯)
β€ β₯mβ - mββ₯ * (max β₯mββ₯ β₯mββ₯) ^ (fintype.card ΞΉ - 1),
{ assume i,
calc β j, (if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯)
β€ β j : ΞΉ, function.update (Ξ» j, max β₯mββ₯ β₯mββ₯) i (β₯mβ - mββ₯) j :
begin
apply prod_le_prod,
{ assume j hj, by_cases h : j = i; simp [h, norm_nonneg] },
{ assume j hj,
by_cases h : j = i,
{ rw h, simp, exact norm_le_pi_norm (mβ - mβ) i },
{ simp [h, max_le_max, norm_le_pi_norm] } }
end
... = β₯mβ - mββ₯ * (max β₯mββ₯ β₯mββ₯) ^ (fintype.card ΞΉ - 1) :
by { rw prod_update_of_mem (finset.mem_univ _), simp [card_univ_diff] } },
calc
β₯f mβ - f mββ₯
β€ C * β i, β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯ :
f.norm_image_sub_le_of_bound' hC H mβ mβ
... β€ C * β i, β₯mβ - mββ₯ * (max β₯mββ₯ β₯mββ₯) ^ (fintype.card ΞΉ - 1) :
mul_le_mul_of_nonneg_left (sum_le_sum (Ξ»i hi, A i)) hC
... = C * (fintype.card ΞΉ) * (max β₯mββ₯ β₯mββ₯) ^ (fintype.card ΞΉ - 1) * β₯mβ - mββ₯ :
by { rw [sum_const, card_univ, nsmul_eq_mul], ring }
end
/-- If a multilinear map satisfies an inequality `β₯f mβ₯ β€ C * β i, β₯m iβ₯`, then it is
continuous. -/
theorem continuous_of_bound (C : β) (H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) :
continuous f :=
begin
let D := max C 1,
have D_pos : 0 β€ D := le_trans zero_le_one (le_max_right _ _),
replace H : β m, β₯f mβ₯ β€ D * β i, β₯m iβ₯,
{ assume m,
apply le_trans (H m) (mul_le_mul_of_nonneg_right (le_max_left _ _) _),
exact prod_nonneg (Ξ»(i : ΞΉ) hi, norm_nonneg (m i)) },
refine continuous_iff_continuous_at.2 (Ξ»m, _),
refine continuous_at_of_locally_lipschitz zero_lt_one
(D * (fintype.card ΞΉ) * (β₯mβ₯ + 1) ^ (fintype.card ΞΉ - 1)) (Ξ»m' h', _),
rw [dist_eq_norm, dist_eq_norm],
have : 0 β€ (max β₯m'β₯ β₯mβ₯), by simp,
have : (max β₯m'β₯ β₯mβ₯) β€ β₯mβ₯ + 1,
by simp [zero_le_one, norm_le_of_mem_closed_ball (le_of_lt h'), -add_comm],
calc
β₯f m' - f mβ₯
β€ D * (fintype.card ΞΉ) * (max β₯m'β₯ β₯mβ₯) ^ (fintype.card ΞΉ - 1) * β₯m' - mβ₯ :
f.norm_image_sub_le_of_bound D_pos H m' m
... β€ D * (fintype.card ΞΉ) * (β₯mβ₯ + 1) ^ (fintype.card ΞΉ - 1) * β₯m' - mβ₯ :
by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul_of_nonneg_left, mul_nonneg,
norm_nonneg, nat.cast_nonneg, pow_le_pow_of_le_left]
end
/-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness
condition. -/
def mk_continuous (C : β) (H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) :
continuous_multilinear_map π E G :=
{ cont := f.continuous_of_bound C H, ..f }
@[simp] lemma coe_mk_continuous (C : β) (H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) :
β(f.mk_continuous C H) = f :=
rfl
/-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on
the other coordinates, then the resulting restricted function satisfies an inequality
`β₯f.restr vβ₯ β€ C * β₯zβ₯^(n-k) * Ξ β₯v iβ₯` if the original function satisfies `β₯f vβ₯ β€ C * Ξ β₯v iβ₯`. -/
lemma restr_norm_le {k n : β} (f : (multilinear_map π (Ξ» i : fin n, G) G' : _))
(s : finset (fin n)) (hk : s.card = k) (z : G) {C : β}
(H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) (v : fin k β G) :
β₯f.restr s hk z vβ₯ β€ C * β₯zβ₯ ^ (n - k) * β i, β₯v iβ₯ :=
begin
rw [mul_right_comm, mul_assoc],
convert H _ using 2,
simp only [apply_dite norm, fintype.prod_dite, prod_const (β₯zβ₯), finset.card_univ,
fintype.card_of_subtype sαΆ (Ξ» x, mem_compl), card_compl, fintype.card_fin, hk, mk_coe,
β (s.order_iso_of_fin hk).symm.bijective.prod_comp (Ξ» x, β₯v xβ₯)],
refl
end
end multilinear_map
/-!
### Continuous multilinear maps
We define the norm `β₯fβ₯` of a continuous multilinear map `f` in finitely many variables as the
smallest number such that `β₯f mβ₯ β€ β₯fβ₯ * β i, β₯m iβ₯` for all `m`. We show that this
defines a normed space structure on `continuous_multilinear_map π E G`.
-/
namespace continuous_multilinear_map
variables (c : π) (f g : continuous_multilinear_map π E G) (m : Ξ i, E i)
theorem bound : β (C : β), 0 < C β§ (β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) :=
f.to_multilinear_map.exists_bound_of_continuous f.2
open real
/-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/
def op_norm := Inf {c | 0 β€ (c : β) β§ β m, β₯f mβ₯ β€ c * β i, β₯m iβ₯}
instance has_op_norm : has_norm (continuous_multilinear_map π E G) := β¨op_normβ©
lemma norm_def : β₯fβ₯ = Inf {c | 0 β€ (c : β) β§ β m, β₯f mβ₯ β€ c * β i, β₯m iβ₯} := rfl
-- So that invocations of `real.Inf_le` make sense: we show that the set of
-- bounds is nonempty and bounded below.
lemma bounds_nonempty {f : continuous_multilinear_map π E G} :
β c, c β {c | 0 β€ c β§ β m, β₯f mβ₯ β€ c * β i, β₯m iβ₯} :=
let β¨M, hMp, hMbβ© := f.bound in β¨M, le_of_lt hMp, hMbβ©
lemma bounds_bdd_below {f : continuous_multilinear_map π E G} :
bdd_below {c | 0 β€ c β§ β m, β₯f mβ₯ β€ c * β i, β₯m iβ₯} :=
β¨0, Ξ» _ β¨hn, _β©, hnβ©
lemma op_norm_nonneg : 0 β€ β₯fβ₯ :=
lb_le_Inf _ bounds_nonempty (Ξ» _ β¨hx, _β©, hx)
/-- The fundamental property of the operator norm of a continuous multilinear map:
`β₯f mβ₯` is bounded by `β₯fβ₯` times the product of the `β₯m iβ₯`. -/
theorem le_op_norm : β₯f mβ₯ β€ β₯fβ₯ * β i, β₯m iβ₯ :=
begin
have A : 0 β€ β i, β₯m iβ₯ := prod_nonneg (Ξ»j hj, norm_nonneg _),
cases A.eq_or_lt with h hlt,
{ rcases prod_eq_zero_iff.1 h.symm with β¨i, _, hiβ©,
rw norm_eq_zero at hi,
have : f m = 0 := f.map_coord_zero i hi,
rw [this, norm_zero],
exact mul_nonneg (op_norm_nonneg f) A },
{ rw [β div_le_iff hlt],
apply (le_Inf _ bounds_nonempty bounds_bdd_below).2,
rintro c β¨_, hcβ©, rw [div_le_iff hlt], apply hc }
end
theorem le_of_op_norm_le {C : β} (h : β₯fβ₯ β€ C) : β₯f mβ₯ β€ C * β i, β₯m iβ₯ :=
(f.le_op_norm m).trans $ mul_le_mul_of_nonneg_right h (prod_nonneg $ Ξ» i _, norm_nonneg (m i))
lemma ratio_le_op_norm : β₯f mβ₯ / β i, β₯m iβ₯ β€ β₯fβ₯ :=
div_le_of_nonneg_of_le_mul (prod_nonneg $ Ξ» i _, norm_nonneg _) (op_norm_nonneg _) (f.le_op_norm m)
/-- The image of the unit ball under a continuous multilinear map is bounded. -/
lemma unit_le_op_norm (h : β₯mβ₯ β€ 1) : β₯f mβ₯ β€ β₯fβ₯ :=
calc
β₯f mβ₯ β€ β₯fβ₯ * β i, β₯m iβ₯ : f.le_op_norm m
... β€ β₯fβ₯ * β i : ΞΉ, 1 :
mul_le_mul_of_nonneg_left (prod_le_prod (Ξ»i hi, norm_nonneg _)
(Ξ»i hi, le_trans (norm_le_pi_norm _ _) h)) (op_norm_nonneg f)
... = β₯fβ₯ : by simp
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
lemma op_norm_le_bound {M : β} (hMp: 0 β€ M) (hM : β m, β₯f mβ₯ β€ M * β i, β₯m iβ₯) :
β₯fβ₯ β€ M :=
Inf_le _ bounds_bdd_below β¨hMp, hMβ©
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : β₯f + gβ₯ β€ β₯fβ₯ + β₯gβ₯ :=
Inf_le _ bounds_bdd_below
β¨add_nonneg (op_norm_nonneg _) (op_norm_nonneg _), Ξ» x, by { rw add_mul,
exact norm_add_le_of_le (le_op_norm _ _) (le_op_norm _ _) }β©
/-- A continuous linear map is zero iff its norm vanishes. -/
theorem op_norm_zero_iff : β₯fβ₯ = 0 β f = 0 :=
begin
split,
{ assume h,
ext m,
simpa [h] using f.le_op_norm m },
{ rintro rfl,
apply le_antisymm (op_norm_le_bound 0 le_rfl (Ξ»m, _)) (op_norm_nonneg _),
simp }
end
variables {π' : Type*} [nondiscrete_normed_field π'] [normed_algebra π' π]
[normed_space π' G] [is_scalar_tower π' π G]
lemma op_norm_smul_le (c : π') : β₯c β’ fβ₯ β€ β₯cβ₯ * β₯fβ₯ :=
(c β’ f).op_norm_le_bound
(mul_nonneg (norm_nonneg _) (op_norm_nonneg _))
begin
intro m,
erw [norm_smul, mul_assoc],
exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _)
end
lemma op_norm_neg : β₯-fβ₯ = β₯fβ₯ := by { rw norm_def, apply congr_arg, ext, simp }
/-- Continuous multilinear maps themselves form a normed space with respect to
the operator norm. -/
instance to_normed_group : normed_group (continuous_multilinear_map π E G) :=
normed_group.of_core _ β¨op_norm_zero_iff, op_norm_add_le, op_norm_negβ©
instance to_normed_space : normed_space π' (continuous_multilinear_map π E G) :=
β¨Ξ» c f, f.op_norm_smul_le cβ©
theorem le_op_norm_mul_prod_of_le {b : ΞΉ β β} (hm : β i, β₯m iβ₯ β€ b i) : β₯f mβ₯ β€ β₯fβ₯ * β i, b i :=
(f.le_op_norm m).trans $ mul_le_mul_of_nonneg_left
(prod_le_prod (Ξ» _ _, norm_nonneg _) (Ξ» i _, hm i)) (norm_nonneg f)
theorem le_op_norm_mul_pow_card_of_le {b : β} (hm : β i, β₯m iβ₯ β€ b) :
β₯f mβ₯ β€ β₯fβ₯ * b ^ fintype.card ΞΉ :=
by simpa only [prod_const] using f.le_op_norm_mul_prod_of_le m hm
theorem le_op_norm_mul_pow_of_le {Ei : fin n β Type*} [Ξ i, normed_group (Ei i)]
[Ξ i, normed_space π (Ei i)] (f : continuous_multilinear_map π Ei G) (m : Ξ i, Ei i)
{b : β} (hm : β₯mβ₯ β€ b) :
β₯f mβ₯ β€ β₯fβ₯ * b ^ n :=
by simpa only [fintype.card_fin]
using f.le_op_norm_mul_pow_card_of_le m (Ξ» i, (norm_le_pi_norm m i).trans hm)
/-- The fundamental property of the operator norm of a continuous multilinear map:
`β₯f mβ₯` is bounded by `β₯fβ₯` times the product of the `β₯m iβ₯`, `nnnorm` version. -/
theorem le_op_nnnorm : nnnorm (f m) β€ nnnorm f * β i, nnnorm (m i) :=
nnreal.coe_le_coe.1 $ by { push_cast, exact f.le_op_norm m }
theorem le_of_op_nnnorm_le {C : ββ₯0} (h : nnnorm f β€ C) : nnnorm (f m) β€ C * β i, nnnorm (m i) :=
(f.le_op_nnnorm m).trans $ mul_le_mul' h le_rfl
lemma op_norm_prod (f : continuous_multilinear_map π E G) (g : continuous_multilinear_map π E G') :
β₯f.prod gβ₯ = max (β₯fβ₯) (β₯gβ₯) :=
le_antisymm
(op_norm_le_bound _ (norm_nonneg (f, g)) (Ξ» m,
have H : 0 β€ β i, β₯m iβ₯, from prod_nonneg $ Ξ» _ _, norm_nonneg _,
by simpa only [prod_apply, prod.norm_def, max_mul_of_nonneg, H]
using max_le_max (f.le_op_norm m) (g.le_op_norm m))) $
max_le
(f.op_norm_le_bound (norm_nonneg _) $ Ξ» m, (le_max_left _ _).trans ((f.prod g).le_op_norm _))
(g.op_norm_le_bound (norm_nonneg _) $ Ξ» m, (le_max_right _ _).trans ((f.prod g).le_op_norm _))
lemma norm_pi {ΞΉ' : Type v'} [fintype ΞΉ'] {E' : ΞΉ' β Type wE'} [Ξ i', normed_group (E' i')]
[Ξ i', normed_space π (E' i')] (f : Ξ i', continuous_multilinear_map π E (E' i')) :
β₯pi fβ₯ = β₯fβ₯ :=
begin
apply le_antisymm,
{ refine (op_norm_le_bound _ (norm_nonneg f) (Ξ» m, _)),
dsimp,
rw pi_norm_le_iff,
exacts [Ξ» i, (f i).le_of_op_norm_le m (norm_le_pi_norm f i),
mul_nonneg (norm_nonneg f) (prod_nonneg $ Ξ» _ _, norm_nonneg _)] },
{ refine (pi_norm_le_iff (norm_nonneg _)).2 (Ξ» i, _),
refine (op_norm_le_bound _ (norm_nonneg _) (Ξ» m, _)),
refine le_trans _ ((pi f).le_op_norm m),
convert norm_le_pi_norm (Ξ» j, f j m) i }
end
section
variables (π E E' G G')
/-- `continuous_multilinear_map.prod` as a `linear_isometry_equiv`. -/
def prodL :
(continuous_multilinear_map π E G) Γ (continuous_multilinear_map π E G') ββα΅’[π]
continuous_multilinear_map π E (G Γ G') :=
{ to_fun := Ξ» f, f.1.prod f.2,
inv_fun := Ξ» f, ((continuous_linear_map.fst π G G').comp_continuous_multilinear_map f,
(continuous_linear_map.snd π G G').comp_continuous_multilinear_map f),
map_add' := Ξ» f g, rfl,
map_smul' := Ξ» c f, rfl,
left_inv := Ξ» f, by ext; refl,
right_inv := Ξ» f, by ext; refl,
norm_map' := Ξ» f, op_norm_prod f.1 f.2 }
/-- `continuous_multilinear_map.pi` as a `linear_isometry_equiv`. -/
def piβα΅’ {ΞΉ' : Type v'} [fintype ΞΉ'] {E' : ΞΉ' β Type wE'} [Ξ i', normed_group (E' i')]
[Ξ i', normed_space π (E' i')] :
@linear_isometry_equiv π (Ξ i', continuous_multilinear_map π E (E' i'))
(continuous_multilinear_map π E (Ξ i, E' i)) _ _ _
(@pi.module ΞΉ' _ π _ _ (Ξ» i', infer_instance)) _ :=
{ to_linear_equiv :=
-- note: `pi_linear_equiv` does not unify correctly here, presumably due to issues with dependent
-- typeclass arguments.
{ map_add' := Ξ» f g, rfl,
map_smul' := Ξ» c f, rfl,
.. pi_equiv, },
norm_map' := norm_pi }
end
section restrict_scalars
variables [Ξ i, normed_space π' (E i)] [β i, is_scalar_tower π' π (E i)]
@[simp] lemma norm_restrict_scalars : β₯f.restrict_scalars π'β₯ = β₯fβ₯ :=
by simp only [norm_def, coe_restrict_scalars]
variable (π')
/-- `continuous_multilinear_map.restrict_scalars` as a `continuous_multilinear_map`. -/
def restrict_scalars_linear :
continuous_multilinear_map π E G βL[π'] continuous_multilinear_map π' E G :=
linear_map.mk_continuous
{ to_fun := restrict_scalars π',
map_add' := Ξ» mβ mβ, rfl,
map_smul' := Ξ» c m, rfl } 1 $ Ξ» f, by simp
variable {π'}
lemma continuous_restrict_scalars :
continuous (restrict_scalars π' : continuous_multilinear_map π E G β
continuous_multilinear_map π' E G) :=
(restrict_scalars_linear π').continuous
end restrict_scalars
/-- The difference `f mβ - f mβ` is controlled in terms of `β₯fβ₯` and `β₯mβ - mββ₯`, precise version.
For a less precise but more usable version, see `norm_image_sub_le`. The bound reads
`β₯f m - f m'β₯ β€
β₯fβ₯ * β₯m 1 - m' 1β₯ * max β₯m 2β₯ β₯m' 2β₯ * max β₯m 3β₯ β₯m' 3β₯ * ... * max β₯m nβ₯ β₯m' nβ₯ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`.-/
lemma norm_image_sub_le' (mβ mβ : Ξ i, E i) :
β₯f mβ - f mββ₯ β€
β₯fβ₯ * β i, β j, if j = i then β₯mβ i - mβ iβ₯ else max β₯mβ jβ₯ β₯mβ jβ₯ :=
f.to_multilinear_map.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_op_norm _ _
/-- The difference `f mβ - f mβ` is controlled in terms of `β₯fβ₯` and `β₯mβ - mββ₯`, less precise
version. For a more precise but less usable version, see `norm_image_sub_le'`.
The bound is `β₯f m - f m'β₯ β€ β₯fβ₯ * card ΞΉ * β₯m - m'β₯ * (max β₯mβ₯ β₯m'β₯) ^ (card ΞΉ - 1)`.-/
lemma norm_image_sub_le (mβ mβ : Ξ i, E i) :
β₯f mβ - f mββ₯ β€ β₯fβ₯ * (fintype.card ΞΉ) * (max β₯mββ₯ β₯mββ₯) ^ (fintype.card ΞΉ - 1) * β₯mβ - mββ₯ :=
f.to_multilinear_map.norm_image_sub_le_of_bound (norm_nonneg _) f.le_op_norm _ _
/-- Applying a multilinear map to a vector is continuous in both coordinates. -/
lemma continuous_eval :
continuous (Ξ» p : continuous_multilinear_map π E G Γ Ξ i, E i, p.1 p.2) :=
begin
apply continuous_iff_continuous_at.2 (Ξ»p, _),
apply continuous_at_of_locally_lipschitz zero_lt_one
((β₯pβ₯ + 1) * (fintype.card ΞΉ) * (β₯pβ₯ + 1) ^ (fintype.card ΞΉ - 1) + β i, β₯p.2 iβ₯)
(Ξ»q hq, _),
have : 0 β€ (max β₯q.2β₯ β₯p.2β₯), by simp,
have : 0 β€ β₯pβ₯ + 1, by simp [le_trans zero_le_one],
have A : β₯qβ₯ β€ β₯pβ₯ + 1 := norm_le_of_mem_closed_ball (le_of_lt hq),
have : (max β₯q.2β₯ β₯p.2β₯) β€ β₯pβ₯ + 1 :=
le_trans (max_le_max (norm_snd_le q) (norm_snd_le p)) (by simp [A, -add_comm, zero_le_one]),
have : β (i : ΞΉ), i β univ β 0 β€ β₯p.2 iβ₯ := Ξ» i hi, norm_nonneg _,
calc dist (q.1 q.2) (p.1 p.2)
β€ dist (q.1 q.2) (q.1 p.2) + dist (q.1 p.2) (p.1 p.2) : dist_triangle _ _ _
... = β₯q.1 q.2 - q.1 p.2β₯ + β₯q.1 p.2 - p.1 p.2β₯ : by rw [dist_eq_norm, dist_eq_norm]
... β€ β₯q.1β₯ * (fintype.card ΞΉ) * (max β₯q.2β₯ β₯p.2β₯) ^ (fintype.card ΞΉ - 1) * β₯q.2 - p.2β₯
+ β₯q.1 - p.1β₯ * β i, β₯p.2 iβ₯ :
add_le_add (norm_image_sub_le _ _ _) ((q.1 - p.1).le_op_norm p.2)
... β€ (β₯pβ₯ + 1) * (fintype.card ΞΉ) * (β₯pβ₯ + 1) ^ (fintype.card ΞΉ - 1) * β₯q - pβ₯
+ β₯q - pβ₯ * β i, β₯p.2 iβ₯ :
by apply_rules [add_le_add, mul_le_mul, le_refl, le_trans (norm_fst_le q) A, nat.cast_nonneg,
mul_nonneg, pow_le_pow_of_le_left, pow_nonneg, norm_snd_le (q - p), norm_nonneg,
norm_fst_le (q - p), prod_nonneg]
... = ((β₯pβ₯ + 1) * (fintype.card ΞΉ) * (β₯pβ₯ + 1) ^ (fintype.card ΞΉ - 1)
+ (β i, β₯p.2 iβ₯)) * dist q p : by { rw dist_eq_norm, ring }
end
lemma continuous_eval_left (m : Ξ i, E i) :
continuous (Ξ» p : continuous_multilinear_map π E G, p m) :=
continuous_eval.comp (continuous_id.prod_mk continuous_const)
lemma has_sum_eval
{Ξ± : Type*} {p : Ξ± β continuous_multilinear_map π E G} {q : continuous_multilinear_map π E G}
(h : has_sum p q) (m : Ξ i, E i) : has_sum (Ξ» a, p a m) (q m) :=
begin
dsimp [has_sum] at h β’,
convert ((continuous_eval_left m).tendsto _).comp h,
ext s,
simp
end
lemma tsum_eval {Ξ± : Type*} {p : Ξ± β continuous_multilinear_map π E G} (hp : summable p)
(m : Ξ i, E i) : (β' a, p a) m = β' a, p a m :=
(has_sum_eval hp.has_sum m).tsum_eq.symm
open_locale topological_space
open filter
/-- If the target space is complete, the space of continuous multilinear maps with its norm is also
complete. The proof is essentially the same as for the space of continuous linear maps (modulo the
addition of `finset.prod` where needed. The duplication could be avoided by deducing the linear
case from the multilinear case via a currying isomorphism. However, this would mess up imports,
and it is more satisfactory to have the simplest case as a standalone proof. -/
instance [complete_space G] : complete_space (continuous_multilinear_map π E G) :=
begin
have nonneg : β (v : Ξ i, E i), 0 β€ β i, β₯v iβ₯ :=
Ξ» v, finset.prod_nonneg (Ξ» i hi, norm_nonneg _),
-- We show that every Cauchy sequence converges.
refine metric.complete_of_cauchy_seq_tendsto (Ξ» f hf, _),
-- We now expand out the definition of a Cauchy sequence,
rcases cauchy_seq_iff_le_tendsto_0.1 hf with β¨b, b0, b_bound, b_limβ©,
-- and establish that the evaluation at any point `v : Ξ i, E i` is Cauchy.
have cau : β v, cauchy_seq (Ξ» n, f n v),
{ assume v,
apply cauchy_seq_iff_le_tendsto_0.2 β¨Ξ» n, b n * β i, β₯v iβ₯, Ξ» n, _, _, _β©,
{ exact mul_nonneg (b0 n) (nonneg v) },
{ assume n m N hn hm,
rw dist_eq_norm,
apply le_trans ((f n - f m).le_op_norm v) _,
exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (nonneg v) },
{ simpa using b_lim.mul tendsto_const_nhds } },
-- We assemble the limits points of those Cauchy sequences
-- (which exist as `G` is complete)
-- into a function which we call `F`.
choose F hF using Ξ»v, cauchy_seq_tendsto_of_complete (cau v),
-- Next, we show that this `F` is multilinear,
let Fmult : multilinear_map π E G :=
{ to_fun := F,
map_add' := Ξ» v i x y, begin
have A := hF (function.update v i (x + y)),
have B := (hF (function.update v i x)).add (hF (function.update v i y)),
simp at A B,
exact tendsto_nhds_unique A B
end,
map_smul' := Ξ» v i c x, begin
have A := hF (function.update v i (c β’ x)),
have B := filter.tendsto.smul (@tendsto_const_nhds _ β _ c _) (hF (function.update v i x)),
simp at A B,
exact tendsto_nhds_unique A B
end },
-- and that `F` has norm at most `(b 0 + β₯f 0β₯)`.
have Fnorm : β v, β₯F vβ₯ β€ (b 0 + β₯f 0β₯) * β i, β₯v iβ₯,
{ assume v,
have A : β n, β₯f n vβ₯ β€ (b 0 + β₯f 0β₯) * β i, β₯v iβ₯,
{ assume n,
apply le_trans ((f n).le_op_norm _) _,
apply mul_le_mul_of_nonneg_right _ (nonneg v),
calc β₯f nβ₯ = β₯(f n - f 0) + f 0β₯ : by { congr' 1, abel }
... β€ β₯f n - f 0β₯ + β₯f 0β₯ : norm_add_le _ _
... β€ b 0 + β₯f 0β₯ : begin
apply add_le_add_right,
simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _)
end },
exact le_of_tendsto (hF v).norm (eventually_of_forall A) },
-- Thus `F` is continuous, and we propose that as the limit point of our original Cauchy sequence.
let Fcont := Fmult.mk_continuous _ Fnorm,
use Fcont,
-- Our last task is to establish convergence to `F` in norm.
have : β n, β₯f n - Fcontβ₯ β€ b n,
{ assume n,
apply op_norm_le_bound _ (b0 n) (Ξ» v, _),
have A : βαΆ m in at_top, β₯(f n - f m) vβ₯ β€ b n * β i, β₯v iβ₯,
{ refine eventually_at_top.2 β¨n, Ξ» m hm, _β©,
apply le_trans ((f n - f m).le_op_norm _) _,
exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (nonneg v) },
have B : tendsto (Ξ» m, β₯(f n - f m) vβ₯) at_top (π (β₯(f n - Fcont) vβ₯)) :=
tendsto.norm (tendsto_const_nhds.sub (hF v)),
exact le_of_tendsto B A },
erw tendsto_iff_norm_tendsto_zero,
exact squeeze_zero (Ξ» n, norm_nonneg _) this b_lim,
end
end continuous_multilinear_map
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mk_continuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
lemma multilinear_map.mk_continuous_norm_le (f : multilinear_map π E G) {C : β} (hC : 0 β€ C)
(H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) : β₯f.mk_continuous C Hβ₯ β€ C :=
continuous_multilinear_map.op_norm_le_bound _ hC (Ξ»m, H m)
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mk_continuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
lemma multilinear_map.mk_continuous_norm_le' (f : multilinear_map π E G) {C : β}
(H : β m, β₯f mβ₯ β€ C * β i, β₯m iβ₯) : β₯f.mk_continuous C Hβ₯ β€ max C 0 :=
continuous_multilinear_map.op_norm_le_bound _ (le_max_right _ _) $
Ξ» m, (H m).trans $ mul_le_mul_of_nonneg_right (le_max_left _ _)
(prod_nonneg $ Ξ» _ _, norm_nonneg _)
namespace continuous_multilinear_map
/-- Given a continuous multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset
`s` of `k` of these variables, one gets a new continuous multilinear map on `fin k` by varying
these variables, and fixing the other ones equal to a given value `z`. It is denoted by
`f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit
identification between `fin k` and `s` that we use is the canonical (increasing) bijection. -/
def restr {k n : β} (f : (G [Γn]βL[π] G' : _))
(s : finset (fin n)) (hk : s.card = k) (z : G) : G [Γk]βL[π] G' :=
(f.to_multilinear_map.restr s hk z).mk_continuous
(β₯fβ₯ * β₯zβ₯^(n-k)) $ Ξ» v, multilinear_map.restr_norm_le _ _ _ _ f.le_op_norm _
lemma norm_restr {k n : β} (f : G [Γn]βL[π] G') (s : finset (fin n)) (hk : s.card = k) (z : G) :
β₯f.restr s hk zβ₯ β€ β₯fβ₯ * β₯zβ₯ ^ (n - k) :=
begin
apply multilinear_map.mk_continuous_norm_le,
exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _)
end
section
variables (π ΞΉ) (A : Type*) [normed_comm_ring A] [normed_algebra π A]
/-- The continuous multilinear map on `A^ΞΉ`, where `A` is a normed commutative algebra
over `π`, associating to `m` the product of all the `m i`.
See also `continuous_multilinear_map.mk_pi_algebra_fin`. -/
protected def mk_pi_algebra : continuous_multilinear_map π (Ξ» i : ΞΉ, A) A :=
@multilinear_map.mk_continuous π ΞΉ (Ξ» i : ΞΉ, A) A _ _ _ _ _ _ _
(multilinear_map.mk_pi_algebra π ΞΉ A) (if nonempty ΞΉ then 1 else β₯(1 : A)β₯) $
begin
intro m,
by_cases hΞΉ : nonempty ΞΉ,
{ resetI, simp [hΞΉ, norm_prod_le' univ univ_nonempty] },
{ simp [eq_empty_of_not_nonempty hΞΉ univ, hΞΉ] }
end
variables {A π ΞΉ}
@[simp] lemma mk_pi_algebra_apply (m : ΞΉ β A) :
continuous_multilinear_map.mk_pi_algebra π ΞΉ A m = β i, m i :=
rfl
lemma norm_mk_pi_algebra_le [nonempty ΞΉ] :
β₯continuous_multilinear_map.mk_pi_algebra π ΞΉ Aβ₯ β€ 1 :=
calc β₯continuous_multilinear_map.mk_pi_algebra π ΞΉ Aβ₯ β€ if nonempty ΞΉ then 1 else β₯(1 : A)β₯ :
multilinear_map.mk_continuous_norm_le _ (by split_ifs; simp [zero_le_one]) _
... = _ : if_pos βΉ_βΊ
lemma norm_mk_pi_algebra_of_empty [is_empty ΞΉ] :
β₯continuous_multilinear_map.mk_pi_algebra π ΞΉ Aβ₯ = β₯(1 : A)β₯ :=
begin
apply le_antisymm,
calc β₯continuous_multilinear_map.mk_pi_algebra π ΞΉ Aβ₯ β€ if nonempty ΞΉ then 1 else β₯(1 : A)β₯ :
multilinear_map.mk_continuous_norm_le _ (by split_ifs; simp [zero_le_one]) _
... = β₯(1 : A)β₯ : if_neg (not_nonempty_iff.mpr βΉ_βΊ),
convert ratio_le_op_norm _ (Ξ» _, (1 : A)),
simp [eq_empty_of_is_empty (univ : finset ΞΉ)],
end
@[simp] lemma norm_mk_pi_algebra [norm_one_class A] :
β₯continuous_multilinear_map.mk_pi_algebra π ΞΉ Aβ₯ = 1 :=
begin
casesI is_empty_or_nonempty ΞΉ,
{ simp [norm_mk_pi_algebra_of_empty] },
{ refine le_antisymm norm_mk_pi_algebra_le _,
convert ratio_le_op_norm _ (Ξ» _, 1); [skip, apply_instance],
simp },
end
end
section
variables (π n) (A : Type*) [normed_ring A] [normed_algebra π A]
/-- The continuous multilinear map on `A^n`, where `A` is a normed algebra over `π`, associating to
`m` the product of all the `m i`.
See also: `multilinear_map.mk_pi_algebra`. -/
protected def mk_pi_algebra_fin : continuous_multilinear_map π (Ξ» i : fin n, A) A :=
@multilinear_map.mk_continuous π (fin n) (Ξ» i : fin n, A) A _ _ _ _ _ _ _
(multilinear_map.mk_pi_algebra_fin π n A) (nat.cases_on n β₯(1 : A)β₯ (Ξ» _, 1)) $
begin
intro m,
cases n,
{ simp },
{ have : @list.of_fn A n.succ m β [] := by simp,
simpa [β fin.prod_of_fn] using list.norm_prod_le' this }
end
variables {A π n}
@[simp] lemma mk_pi_algebra_fin_apply (m : fin n β A) :
continuous_multilinear_map.mk_pi_algebra_fin π n A m = (list.of_fn m).prod :=
rfl
lemma norm_mk_pi_algebra_fin_succ_le :
β₯continuous_multilinear_map.mk_pi_algebra_fin π n.succ Aβ₯ β€ 1 :=
multilinear_map.mk_continuous_norm_le _ zero_le_one _
lemma norm_mk_pi_algebra_fin_le_of_pos (hn : 0 < n) :
β₯continuous_multilinear_map.mk_pi_algebra_fin π n Aβ₯ β€ 1 :=
by cases n; [exact hn.false.elim, exact norm_mk_pi_algebra_fin_succ_le]
lemma norm_mk_pi_algebra_fin_zero :
β₯continuous_multilinear_map.mk_pi_algebra_fin π 0 Aβ₯ = β₯(1 : A)β₯ :=
begin
refine le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _) _,
convert ratio_le_op_norm _ (Ξ» _, 1); [simp, apply_instance]
end
@[simp] lemma norm_mk_pi_algebra_fin [norm_one_class A] :
β₯continuous_multilinear_map.mk_pi_algebra_fin π n Aβ₯ = 1 :=
begin
cases n,
{ simp [norm_mk_pi_algebra_fin_zero] },
{ refine le_antisymm norm_mk_pi_algebra_fin_succ_le _,
convert ratio_le_op_norm _ (Ξ» _, 1); [skip, apply_instance],
simp }
end
end
variables (π ΞΉ)
/-- The canonical continuous multilinear map on `π^ΞΉ`, associating to `m` the product of all the
`m i` (multiplied by a fixed reference element `z` in the target module) -/
protected def mk_pi_field (z : G) : continuous_multilinear_map π (Ξ»(i : ΞΉ), π) G :=
@multilinear_map.mk_continuous π ΞΉ (Ξ»(i : ΞΉ), π) G _ _ _ _ _ _ _
(multilinear_map.mk_pi_ring π ΞΉ z) (β₯zβ₯)
(Ξ» m, by simp only [multilinear_map.mk_pi_ring_apply, norm_smul, normed_field.norm_prod,
mul_comm])
variables {π ΞΉ}
@[simp] lemma mk_pi_field_apply (z : G) (m : ΞΉ β π) :
(continuous_multilinear_map.mk_pi_field π ΞΉ z : (ΞΉ β π) β G) m = (β i, m i) β’ z := rfl
lemma mk_pi_field_apply_one_eq_self (f : continuous_multilinear_map π (Ξ»(i : ΞΉ), π) G) :
continuous_multilinear_map.mk_pi_field π ΞΉ (f (Ξ»i, 1)) = f :=
to_multilinear_map_inj f.to_multilinear_map.mk_pi_ring_apply_one_eq_self
variables (π ΞΉ G)
/-- Continuous multilinear maps on `π^n` with values in `G` are in bijection with `G`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a linear equivalence in
`continuous_multilinear_map.pi_field_equiv_aux`. The continuous linear equivalence is
`continuous_multilinear_map.pi_field_equiv`. -/
protected def pi_field_equiv_aux : G ββ[π] (continuous_multilinear_map π (Ξ»(i : ΞΉ), π) G) :=
{ to_fun := Ξ» z, continuous_multilinear_map.mk_pi_field π ΞΉ z,
inv_fun := Ξ» f, f (Ξ»i, 1),
map_add' := Ξ» z z', by { ext m, simp [smul_add] },
map_smul' := Ξ» c z, by { ext m, simp [smul_smul, mul_comm] },
left_inv := Ξ» z, by simp,
right_inv := Ξ» f, f.mk_pi_field_apply_one_eq_self }
/-- Continuous multilinear maps on `π^n` with values in `G` are in bijection with `G`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a continuous linear equivalence in
`continuous_multilinear_map.pi_field_equiv`. -/
protected def pi_field_equiv : G βL[π] (continuous_multilinear_map π (Ξ»(i : ΞΉ), π) G) :=
{ continuous_to_fun := begin
refine (continuous_multilinear_map.pi_field_equiv_aux π ΞΉ G).to_linear_map.continuous_of_bound
(1 : β) (Ξ»z, _),
rw one_mul,
change β₯continuous_multilinear_map.mk_pi_field π ΞΉ zβ₯ β€ β₯zβ₯,
exact multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _
end,
continuous_inv_fun := begin
refine
(continuous_multilinear_map.pi_field_equiv_aux π ΞΉ G).symm.to_linear_map.continuous_of_bound
(1 : β) (Ξ»f, _),
rw one_mul,
change β₯f (Ξ»i, 1)β₯ β€ β₯fβ₯,
apply @continuous_multilinear_map.unit_le_op_norm π ΞΉ (Ξ» (i : ΞΉ), π) G _ _ _ _ _ _ _ f,
simp [pi_norm_le_iff zero_le_one, le_refl]
end,
.. continuous_multilinear_map.pi_field_equiv_aux π ΞΉ G }
end continuous_multilinear_map
namespace continuous_linear_map
lemma norm_comp_continuous_multilinear_map_le (g : G βL[π] G')
(f : continuous_multilinear_map π E G) :
β₯g.comp_continuous_multilinear_map fβ₯ β€ β₯gβ₯ * β₯fβ₯ :=
continuous_multilinear_map.op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) $ Ξ» m,
calc β₯g (f m)β₯ β€ β₯gβ₯ * (β₯fβ₯ * β i, β₯m iβ₯) : g.le_op_norm_of_le $ f.le_op_norm _
... = _ : (mul_assoc _ _ _).symm
/-- `continuous_linear_map.comp_continuous_multilinear_map` as a bundled continuous bilinear map. -/
def comp_continuous_multilinear_mapL :
(G βL[π] G') βL[π] continuous_multilinear_map π E G βL[π] continuous_multilinear_map π E G' :=
linear_map.mk_continuousβ
(linear_map.mkβ π comp_continuous_multilinear_map (Ξ» fβ fβ g, rfl) (Ξ» c f g, rfl)
(Ξ» f gβ gβ, by { ext1, apply f.map_add }) (Ξ» c f g, by { ext1, simp }))
1 $ Ξ» f g, by { rw one_mul, exact f.norm_comp_continuous_multilinear_map_le g }
/-- Flip arguments in `f : G βL[π] continuous_multilinear_map π E G'` to get
`continuous_multilinear_map π E (G βL[π] G')` -/
def flip_multilinear (f : G βL[π] continuous_multilinear_map π E G') :
continuous_multilinear_map π E (G βL[π] G') :=
multilinear_map.mk_continuous
{ to_fun := Ξ» m, linear_map.mk_continuous
{ to_fun := Ξ» x, f x m,
map_add' := Ξ» x y, by simp only [map_add, continuous_multilinear_map.add_apply],
map_smul' := Ξ» c x, by simp only [continuous_multilinear_map.smul_apply, map_smul]}
(β₯fβ₯ * β i, β₯m iβ₯) $ Ξ» x,
by { rw mul_right_comm, exact (f x).le_of_op_norm_le _ (f.le_op_norm x) },
map_add' := Ξ» m i x y,
by { ext1, simp only [add_apply, continuous_multilinear_map.map_add, linear_map.coe_mk,
linear_map.mk_continuous_apply]},
map_smul' := Ξ» m i c x,
by { ext1, simp only [coe_smul', continuous_multilinear_map.map_smul, linear_map.coe_mk,
linear_map.mk_continuous_apply, pi.smul_apply]} }
β₯fβ₯ $ Ξ» m,
linear_map.mk_continuous_norm_le _
(mul_nonneg (norm_nonneg f) (prod_nonneg $ Ξ» i hi, norm_nonneg (m i))) _
end continuous_linear_map
open continuous_multilinear_map
namespace multilinear_map
/-- Given a map `f : G ββ[π] multilinear_map π E G'` and an estimate
`H : β x m, β₯f x mβ₯ β€ C * β₯xβ₯ * β i, β₯m iβ₯`, construct a continuous linear
map from `G` to `continuous_multilinear_map π E G'`.
In order to lift, e.g., a map `f : (multilinear_map π E G) ββ[π] multilinear_map π E' G'`
to a map `(continuous_multilinear_map π E G) βL[π] continuous_multilinear_map π E' G'`,
one can apply this construction to `f.comp continuous_multilinear_map.to_multilinear_map_linear`
which is a linear map from `continuous_multilinear_map π E G` to `multilinear_map π E' G'`. -/
def mk_continuous_linear (f : G ββ[π] multilinear_map π E G') (C : β)
(H : β x m, β₯f x mβ₯ β€ C * β₯xβ₯ * β i, β₯m iβ₯) :
G βL[π] continuous_multilinear_map π E G' :=
linear_map.mk_continuous
{ to_fun := Ξ» x, (f x).mk_continuous (C * β₯xβ₯) $ H x,
map_add' := Ξ» x y, by { ext1, simp },
map_smul' := Ξ» c x, by { ext1, simp } }
(max C 0) $ Ξ» x, ((f x).mk_continuous_norm_le' _).trans_eq $
by rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul]
lemma mk_continuous_linear_norm_le' (f : G ββ[π] multilinear_map π E G') (C : β)
(H : β x m, β₯f x mβ₯ β€ C * β₯xβ₯ * β i, β₯m iβ₯) :
β₯mk_continuous_linear f C Hβ₯ β€ max C 0 :=
begin
dunfold mk_continuous_linear,
exact linear_map.mk_continuous_norm_le _ (le_max_right _ _) _
end
lemma mk_continuous_linear_norm_le (f : G ββ[π] multilinear_map π E G') {C : β} (hC : 0 β€ C)
(H : β x m, β₯f x mβ₯ β€ C * β₯xβ₯ * β i, β₯m iβ₯) :
β₯mk_continuous_linear f C Hβ₯ β€ C :=
(mk_continuous_linear_norm_le' f C H).trans_eq (max_eq_left hC)
/-- Given a map `f : multilinear_map π E (multilinear_map π E' G)` and an estimate
`H : β m m', β₯f m m'β₯ β€ C * β i, β₯m iβ₯ * β i, β₯m' iβ₯`, upgrade all `multilinear_map`s in the type to
`continuous_multilinear_map`s. -/
def mk_continuous_multilinear (f : multilinear_map π E (multilinear_map π E' G)) (C : β)
(H : β mβ mβ, β₯f mβ mββ₯ β€ C * (β i, β₯mβ iβ₯) * β i, β₯mβ iβ₯) :
continuous_multilinear_map π E (continuous_multilinear_map π E' G) :=
mk_continuous
{ to_fun := Ξ» m, mk_continuous (f m) (C * β i, β₯m iβ₯) $ H m,
map_add' := Ξ» m i x y, by { ext1, simp },
map_smul' := Ξ» m i c x, by { ext1, simp } }
(max C 0) $ Ξ» m, ((f m).mk_continuous_norm_le' _).trans_eq $
by { rw [max_mul_of_nonneg, zero_mul], exact prod_nonneg (Ξ» _ _, norm_nonneg _) }
@[simp] lemma mk_continuous_multilinear_apply (f : multilinear_map π E (multilinear_map π E' G))
{C : β} (H : β mβ mβ, β₯f mβ mββ₯ β€ C * (β i, β₯mβ iβ₯) * β i, β₯mβ iβ₯) (m : Ξ i, E i) :
β(mk_continuous_multilinear f C H m) = f m :=
rfl
lemma mk_continuous_multilinear_norm_le' (f : multilinear_map π E (multilinear_map π E' G)) (C : β)
(H : β mβ mβ, β₯f mβ mββ₯ β€ C * (β i, β₯mβ iβ₯) * β i, β₯mβ iβ₯) :
β₯mk_continuous_multilinear f C Hβ₯ β€ max C 0 :=
begin
dunfold mk_continuous_multilinear,
exact mk_continuous_norm_le _ (le_max_right _ _) _
end
lemma mk_continuous_multilinear_norm_le (f : multilinear_map π E (multilinear_map π E' G)) {C : β}
(hC : 0 β€ C) (H : β mβ mβ, β₯f mβ mββ₯ β€ C * (β i, β₯mβ iβ₯) * β i, β₯mβ iβ₯) :
β₯mk_continuous_multilinear f C Hβ₯ β€ C :=
(mk_continuous_multilinear_norm_le' f C H).trans_eq (max_eq_left hC)
end multilinear_map
namespace continuous_multilinear_map
lemma norm_comp_continuous_linear_le (g : continuous_multilinear_map π Eβ G)
(f : Ξ i, E i βL[π] Eβ i) :
β₯g.comp_continuous_linear_map fβ₯ β€ β₯gβ₯ * β i, β₯f iβ₯ :=
op_norm_le_bound _ (mul_nonneg (norm_nonneg _) $ prod_nonneg $ Ξ» i hi, norm_nonneg _) $ Ξ» m,
calc β₯g (Ξ» i, f i (m i))β₯ β€ β₯gβ₯ * β i, β₯f i (m i)β₯ : g.le_op_norm _
... β€ β₯gβ₯ * β i, (β₯f iβ₯ * β₯m iβ₯) :
mul_le_mul_of_nonneg_left
(prod_le_prod (Ξ» _ _, norm_nonneg _) (Ξ» i hi, (f i).le_op_norm (m i))) (norm_nonneg g)
... = (β₯gβ₯ * β i, β₯f iβ₯) * β i, β₯m iβ₯ : by rw [prod_mul_distrib, mul_assoc]
/-- `continuous_multilinear_map.comp_continuous_linear_map` as a bundled continuous linear map.
This implementation fixes `f : Ξ i, E i βL[π] Eβ i`.
TODO: Actually, the map is multilinear in `f` but an attempt to formalize this failed because of
issues with class instances. -/
def comp_continuous_linear_mapL (f : Ξ i, E i βL[π] Eβ i) :
continuous_multilinear_map π Eβ G βL[π] continuous_multilinear_map π E G :=
linear_map.mk_continuous
{ to_fun := Ξ» g, g.comp_continuous_linear_map f,
map_add' := Ξ» gβ gβ, rfl,
map_smul' := Ξ» c g, rfl }
(β i, β₯f iβ₯) $ Ξ» g, (norm_comp_continuous_linear_le _ _).trans_eq (mul_comm _ _)
@[simp] lemma comp_continuous_linear_mapL_apply (g : continuous_multilinear_map π Eβ G)
(f : Ξ i, E i βL[π] Eβ i) :
comp_continuous_linear_mapL f g = g.comp_continuous_linear_map f :=
rfl
lemma norm_comp_continuous_linear_mapL_le (f : Ξ i, E i βL[π] Eβ i) :
β₯@comp_continuous_linear_mapL π ΞΉ E Eβ G _ _ _ _ _ _ _ _ _ fβ₯ β€ (β i, β₯f iβ₯) :=
linear_map.mk_continuous_norm_le _ (prod_nonneg $ Ξ» i _, norm_nonneg _) _
end continuous_multilinear_map
section currying
/-!
### Currying
We associate to a continuous multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two
curried functions, named `f.curry_left` (which is a continuous linear map on `E 0` taking values
in continuous multilinear maps in `n` variables) and `f.curry_right` (which is a continuous
multilinear map in `n` variables taking values in continuous linear maps on `E (last n)`).
The inverse operations are called `uncurry_left` and `uncurry_right`.
We also register continuous linear equiv versions of these correspondences, in
`continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`.
-/
open fin function
lemma continuous_linear_map.norm_map_tail_le
(f : Ei 0 βL[π] (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.succ) G)) (m : Ξ i, Ei i) :
β₯f (m 0) (tail m)β₯ β€ β₯fβ₯ * β i, β₯m iβ₯ :=
calc
β₯f (m 0) (tail m)β₯ β€ β₯f (m 0)β₯ * β i, β₯(tail m) iβ₯ : (f (m 0)).le_op_norm _
... β€ (β₯fβ₯ * β₯m 0β₯) * β i, β₯(tail m) iβ₯ :
mul_le_mul_of_nonneg_right (f.le_op_norm _) (prod_nonneg (Ξ»i hi, norm_nonneg _))
... = β₯fβ₯ * (β₯m 0β₯ * β i, β₯(tail m) iβ₯) : by ring
... = β₯fβ₯ * β i, β₯m iβ₯ : by { rw prod_univ_succ, refl }
lemma continuous_multilinear_map.norm_map_init_le
(f : continuous_multilinear_map π (Ξ»(i : fin n), Ei i.cast_succ) (Ei (last n) βL[π] G))
(m : Ξ i, Ei i) :
β₯f (init m) (m (last n))β₯ β€ β₯fβ₯ * β i, β₯m iβ₯ :=
calc
β₯f (init m) (m (last n))β₯ β€ β₯f (init m)β₯ * β₯m (last n)β₯ : (f (init m)).le_op_norm _
... β€ (β₯fβ₯ * (β i, β₯(init m) iβ₯)) * β₯m (last n)β₯ :
mul_le_mul_of_nonneg_right (f.le_op_norm _) (norm_nonneg _)
... = β₯fβ₯ * ((β i, β₯(init m) iβ₯) * β₯m (last n)β₯) : mul_assoc _ _ _
... = β₯fβ₯ * β i, β₯m iβ₯ : by { rw prod_univ_cast_succ, refl }
lemma continuous_multilinear_map.norm_map_cons_le
(f : continuous_multilinear_map π Ei G) (x : Ei 0) (m : Ξ (i : fin n), Ei i.succ) :
β₯f (cons x m)β₯ β€ β₯fβ₯ * β₯xβ₯ * β i, β₯m iβ₯ :=
calc
β₯f (cons x m)β₯ β€ β₯fβ₯ * β i, β₯cons x m iβ₯ : f.le_op_norm _
... = (β₯fβ₯ * β₯xβ₯) * β i, β₯m iβ₯ : by { rw prod_univ_succ, simp [mul_assoc] }
lemma continuous_multilinear_map.norm_map_snoc_le
(f : continuous_multilinear_map π Ei G) (m : Ξ (i : fin n), Ei i.cast_succ) (x : Ei (last n)) :
β₯f (snoc m x)β₯ β€ β₯fβ₯ * (β i, β₯m iβ₯) * β₯xβ₯ :=
calc
β₯f (snoc m x)β₯ β€ β₯fβ₯ * β i, β₯snoc m x iβ₯ : f.le_op_norm _
... = β₯fβ₯ * (β i, β₯m iβ₯) * β₯xβ₯ : by { rw prod_univ_cast_succ, simp [mul_assoc] }
/-! #### Left currying -/
/-- Given a continuous linear map `f` from `E 0` to continuous multilinear maps on `n` variables,
construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m β¦ f (m 0) (tail m)`-/
def continuous_linear_map.uncurry_left
(f : Ei 0 βL[π] (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.succ) G)) :
continuous_multilinear_map π Ei G :=
(@linear_map.uncurry_left π n Ei G _ _ _ _ _
(continuous_multilinear_map.to_multilinear_map_linear.comp f.to_linear_map)).mk_continuous
(β₯fβ₯) (Ξ»m, continuous_linear_map.norm_map_tail_le f m)
@[simp] lemma continuous_linear_map.uncurry_left_apply
(f : Ei 0 βL[π] (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.succ) G)) (m : Ξ i, Ei i) :
f.uncurry_left m = f (m 0) (tail m) := rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the first variable to obtain
a continuous linear map into continuous multilinear maps in `n` variables, given by
`x β¦ (m β¦ f (cons x m))`. -/
def continuous_multilinear_map.curry_left
(f : continuous_multilinear_map π Ei G) :
Ei 0 βL[π] (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.succ) G) :=
linear_map.mk_continuous
{ -- define a linear map into `n` continuous multilinear maps from an `n+1` continuous multilinear
-- map
to_fun := Ξ»x, (f.to_multilinear_map.curry_left x).mk_continuous
(β₯fβ₯ * β₯xβ₯) (f.norm_map_cons_le x),
map_add' := Ξ»x y, by { ext m, exact f.cons_add m x y },
map_smul' := Ξ»c x, by { ext m, exact f.cons_smul m c x } }
-- then register its continuity thanks to its boundedness properties.
(β₯fβ₯) (Ξ»x, multilinear_map.mk_continuous_norm_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _)
@[simp] lemma continuous_multilinear_map.curry_left_apply
(f : continuous_multilinear_map π Ei G) (x : Ei 0) (m : Ξ (i : fin n), Ei i.succ) :
f.curry_left x m = f (cons x m) := rfl
@[simp] lemma continuous_linear_map.curry_uncurry_left
(f : Ei 0 βL[π] (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.succ) G)) :
f.uncurry_left.curry_left = f :=
begin
ext m x,
simp only [tail_cons, continuous_linear_map.uncurry_left_apply,
continuous_multilinear_map.curry_left_apply],
rw cons_zero
end
@[simp] lemma continuous_multilinear_map.uncurry_curry_left
(f : continuous_multilinear_map π Ei G) : f.curry_left.uncurry_left = f :=
continuous_multilinear_map.to_multilinear_map_inj $ f.to_multilinear_map.uncurry_curry_left
variables (π Ei G)
/-- The space of continuous multilinear maps on `Ξ (i : fin (n+1)), E i` is canonically isomorphic to
the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on
`Ξ (i : fin n), E i.succ `, by separating the first variable. We register this isomorphism in
`continuous_multilinear_curry_left_equiv π E Eβ`. The algebraic version (without topology) is given
in `multilinear_curry_left_equiv π E Eβ`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of linear isometric equivs. -/
def continuous_multilinear_curry_left_equiv :
(Ei 0 βL[π] (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.succ) G)) ββα΅’[π]
(continuous_multilinear_map π Ei G) :=
linear_isometry_equiv.of_bounds
{ to_fun := continuous_linear_map.uncurry_left,
map_add' := Ξ»fβ fβ, by { ext m, refl },
map_smul' := Ξ»c f, by { ext m, refl },
inv_fun := continuous_multilinear_map.curry_left,
left_inv := continuous_linear_map.curry_uncurry_left,
right_inv := continuous_multilinear_map.uncurry_curry_left }
(Ξ» f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
(Ξ» f, linear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
variables {π Ei G}
@[simp] lemma continuous_multilinear_curry_left_equiv_apply
(f : Ei 0 βL[π] (continuous_multilinear_map π (Ξ» i : fin n, Ei i.succ) G)) (v : Ξ i, Ei i) :
continuous_multilinear_curry_left_equiv π Ei G f v = f (v 0) (tail v) := rfl
@[simp] lemma continuous_multilinear_curry_left_equiv_symm_apply
(f : continuous_multilinear_map π Ei G) (x : Ei 0) (v : Ξ i : fin n, Ei i.succ) :
(continuous_multilinear_curry_left_equiv π Ei G).symm f x v = f (cons x v) := rfl
@[simp] lemma continuous_multilinear_map.curry_left_norm
(f : continuous_multilinear_map π Ei G) : β₯f.curry_leftβ₯ = β₯fβ₯ :=
(continuous_multilinear_curry_left_equiv π Ei G).symm.norm_map f
@[simp] lemma continuous_linear_map.uncurry_left_norm
(f : Ei 0 βL[π] (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.succ) G)) :
β₯f.uncurry_leftβ₯ = β₯fβ₯ :=
(continuous_multilinear_curry_left_equiv π Ei G).norm_map f
/-! #### Right currying -/
/-- Given a continuous linear map `f` from continuous multilinear maps on `n` variables to
continuous linear maps on `E 0`, construct the corresponding continuous multilinear map on `n+1`
variables obtained by concatenating the variables, given by `m β¦ f (init m) (m (last n))`. -/
def continuous_multilinear_map.uncurry_right
(f : continuous_multilinear_map π (Ξ» i : fin n, Ei i.cast_succ) (Ei (last n) βL[π] G)) :
continuous_multilinear_map π Ei G :=
let f' : multilinear_map π (Ξ»(i : fin n), Ei i.cast_succ) (Ei (last n) ββ[π] G) :=
{ to_fun := Ξ» m, (f m).to_linear_map,
map_add' := Ξ» m i x y, by simp,
map_smul' := Ξ» m i c x, by simp } in
(@multilinear_map.uncurry_right π n Ei G _ _ _ _ _ f').mk_continuous
(β₯fβ₯) (Ξ»m, f.norm_map_init_le m)
@[simp] lemma continuous_multilinear_map.uncurry_right_apply
(f : continuous_multilinear_map π (Ξ»(i : fin n), Ei i.cast_succ) (Ei (last n) βL[π] G))
(m : Ξ i, Ei i) :
f.uncurry_right m = f (init m) (m (last n)) := rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the last variable to obtain
a continuous multilinear map in `n` variables into continuous linear maps, given by
`m β¦ (x β¦ f (snoc m x))`. -/
def continuous_multilinear_map.curry_right
(f : continuous_multilinear_map π Ei G) :
continuous_multilinear_map π (Ξ» i : fin n, Ei i.cast_succ) (Ei (last n) βL[π] G) :=
let f' : multilinear_map π (Ξ»(i : fin n), Ei i.cast_succ) (Ei (last n) βL[π] G) :=
{ to_fun := Ξ»m, (f.to_multilinear_map.curry_right m).mk_continuous
(β₯fβ₯ * β i, β₯m iβ₯) $ Ξ»x, f.norm_map_snoc_le m x,
map_add' := Ξ» m i x y, by { simp, refl },
map_smul' := Ξ» m i c x, by { simp, refl } } in
f'.mk_continuous (β₯fβ₯) (Ξ»m, linear_map.mk_continuous_norm_le _
(mul_nonneg (norm_nonneg _) (prod_nonneg (Ξ»j hj, norm_nonneg _))) _)
@[simp] lemma continuous_multilinear_map.curry_right_apply
(f : continuous_multilinear_map π Ei G) (m : Ξ i : fin n, Ei i.cast_succ) (x : Ei (last n)) :
f.curry_right m x = f (snoc m x) := rfl
@[simp] lemma continuous_multilinear_map.curry_uncurry_right
(f : continuous_multilinear_map π (Ξ» i : fin n, Ei i.cast_succ) (Ei (last n) βL[π] G)) :
f.uncurry_right.curry_right = f :=
begin
ext m x,
simp only [snoc_last, continuous_multilinear_map.curry_right_apply,
continuous_multilinear_map.uncurry_right_apply],
rw init_snoc
end
@[simp] lemma continuous_multilinear_map.uncurry_curry_right
(f : continuous_multilinear_map π Ei G) : f.curry_right.uncurry_right = f :=
by { ext m, simp }
variables (π Ei G)
/--
The space of continuous multilinear maps on `Ξ (i : fin (n+1)), Ei i` is canonically isomorphic to
the space of continuous multilinear maps on `Ξ (i : fin n), Ei i.cast_succ` with values in the space
of continuous linear maps on `Ei (last n)`, by separating the last variable. We register this
isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv π Ei G`.
The algebraic version (without topology) is given in `multilinear_curry_right_equiv π Ei G`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear isometric equivs.
-/
def continuous_multilinear_curry_right_equiv :
(continuous_multilinear_map π (Ξ»(i : fin n), Ei i.cast_succ) (Ei (last n) βL[π] G)) ββα΅’[π]
(continuous_multilinear_map π Ei G) :=
linear_isometry_equiv.of_bounds
{ to_fun := continuous_multilinear_map.uncurry_right,
map_add' := Ξ»fβ fβ, by { ext m, refl },
map_smul' := Ξ»c f, by { ext m, refl },
inv_fun := continuous_multilinear_map.curry_right,
left_inv := continuous_multilinear_map.curry_uncurry_right,
right_inv := continuous_multilinear_map.uncurry_curry_right }
(Ξ» f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
(Ξ» f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
variables (n G')
/-- The space of continuous multilinear maps on `Ξ (i : fin (n+1)), G` is canonically isomorphic to
the space of continuous multilinear maps on `Ξ (i : fin n), G` with values in the space
of continuous linear maps on `G`, by separating the last variable. We register this
isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv' π n G G'`.
For a version allowing dependent types, see `continuous_multilinear_curry_right_equiv`. When there
are no dependent types, use the primed version as it helps Lean a lot for unification.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear isometric equivs. -/
def continuous_multilinear_curry_right_equiv' :
(G [Γn]βL[π] (G βL[π] G')) ββα΅’[π] (G [Γn.succ]βL[π] G') :=
continuous_multilinear_curry_right_equiv π (Ξ» (i : fin n.succ), G) G'
variables {n π G Ei G'}
@[simp] lemma continuous_multilinear_curry_right_equiv_apply
(f : (continuous_multilinear_map π (Ξ»(i : fin n), Ei i.cast_succ) (Ei (last n) βL[π] G)))
(v : Ξ i, Ei i) :
(continuous_multilinear_curry_right_equiv π Ei G) f v = f (init v) (v (last n)) := rfl
@[simp] lemma continuous_multilinear_curry_right_equiv_symm_apply
(f : continuous_multilinear_map π Ei G)
(v : Ξ (i : fin n), Ei i.cast_succ) (x : Ei (last n)) :
(continuous_multilinear_curry_right_equiv π Ei G).symm f v x = f (snoc v x) := rfl
@[simp] lemma continuous_multilinear_curry_right_equiv_apply'
(f : G [Γn]βL[π] (G βL[π] G')) (v : Ξ (i : fin n.succ), G) :
continuous_multilinear_curry_right_equiv' π n G G' f v = f (init v) (v (last n)) := rfl
@[simp] lemma continuous_multilinear_curry_right_equiv_symm_apply'
(f : G [Γn.succ]βL[π] G') (v : Ξ (i : fin n), G) (x : G) :
(continuous_multilinear_curry_right_equiv' π n G G').symm f v x = f (snoc v x) := rfl
@[simp] lemma continuous_multilinear_map.curry_right_norm
(f : continuous_multilinear_map π Ei G) : β₯f.curry_rightβ₯ = β₯fβ₯ :=
(continuous_multilinear_curry_right_equiv π Ei G).symm.norm_map f
@[simp] lemma continuous_multilinear_map.uncurry_right_norm
(f : continuous_multilinear_map π (Ξ» i : fin n, Ei i.cast_succ) (Ei (last n) βL[π] G)) :
β₯f.uncurry_rightβ₯ = β₯fβ₯ :=
(continuous_multilinear_curry_right_equiv π Ei G).norm_map f
/-!
#### Currying with `0` variables
The space of multilinear maps with `0` variables is trivial: such a multilinear map is just an
arbitrary constant (note that multilinear maps in `0` variables need not map `0` to `0`!).
Therefore, the space of continuous multilinear maps on `(fin 0) β G` with values in `Eβ` is
isomorphic (and even isometric) to `Eβ`. As this is the zeroth step in the construction of iterated
derivatives, we register this isomorphism. -/
section
local attribute [instance] unique.subsingleton
variables {π G G'}
/-- Associating to a continuous multilinear map in `0` variables the unique value it takes. -/
def continuous_multilinear_map.uncurry0
(f : continuous_multilinear_map π (Ξ» (i : fin 0), G) G') : G' := f 0
variables (π G)
/-- Associating to an element `x` of a vector space `Eβ` the continuous multilinear map in `0`
variables taking the (unique) value `x` -/
def continuous_multilinear_map.curry0 (x : G') : G [Γ0]βL[π] G' :=
{ to_fun := Ξ»m, x,
map_add' := Ξ» m i, fin.elim0 i,
map_smul' := Ξ» m i, fin.elim0 i,
cont := continuous_const }
variable {G}
@[simp] lemma continuous_multilinear_map.curry0_apply (x : G') (m : (fin 0) β G) :
continuous_multilinear_map.curry0 π G x m = x := rfl
variable {π}
@[simp] lemma continuous_multilinear_map.uncurry0_apply (f : G [Γ0]βL[π] G') :
f.uncurry0 = f 0 := rfl
@[simp] lemma continuous_multilinear_map.apply_zero_curry0 (f : G [Γ0]βL[π] G') {x : fin 0 β G} :
continuous_multilinear_map.curry0 π G (f x) = f :=
by { ext m, simp [(subsingleton.elim _ _ : x = m)] }
lemma continuous_multilinear_map.uncurry0_curry0 (f : G [Γ0]βL[π] G') :
continuous_multilinear_map.curry0 π G (f.uncurry0) = f :=
by simp
variables (π G)
@[simp] lemma continuous_multilinear_map.curry0_uncurry0 (x : G') :
(continuous_multilinear_map.curry0 π G x).uncurry0 = x := rfl
@[simp] lemma continuous_multilinear_map.curry0_norm (x : G') :
β₯continuous_multilinear_map.curry0 π G xβ₯ = β₯xβ₯ :=
begin
apply le_antisymm,
{ exact continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (Ξ»m, by simp) },
{ simpa using (continuous_multilinear_map.curry0 π G x).le_op_norm 0 }
end
variables {π G}
@[simp] lemma continuous_multilinear_map.fin0_apply_norm (f : G [Γ0]βL[π] G') {x : fin 0 β G} :
β₯f xβ₯ = β₯fβ₯ :=
begin
have : x = 0 := subsingleton.elim _ _, subst this,
refine le_antisymm (by simpa using f.le_op_norm 0) _,
have : β₯continuous_multilinear_map.curry0 π G (f.uncurry0)β₯ β€ β₯f.uncurry0β₯ :=
continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (Ξ»m,
by simp [-continuous_multilinear_map.apply_zero_curry0]),
simpa
end
lemma continuous_multilinear_map.uncurry0_norm (f : G [Γ0]βL[π] G') : β₯f.uncurry0β₯ = β₯fβ₯ :=
by simp
variables (π G G')
/-- The continuous linear isomorphism between elements of a normed space, and continuous multilinear
maps in `0` variables with values in this normed space.
The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full
framework of linear isometric equivs. -/
def continuous_multilinear_curry_fin0 : (G [Γ0]βL[π] G') ββα΅’[π] G' :=
{ to_fun := Ξ»f, continuous_multilinear_map.uncurry0 f,
inv_fun := Ξ»f, continuous_multilinear_map.curry0 π G f,
map_add' := Ξ»f g, rfl,
map_smul' := Ξ»c f, rfl,
left_inv := continuous_multilinear_map.uncurry0_curry0,
right_inv := continuous_multilinear_map.curry0_uncurry0 π G,
norm_map' := continuous_multilinear_map.uncurry0_norm }
variables {π G G'}
@[simp] lemma continuous_multilinear_curry_fin0_apply (f : G [Γ0]βL[π] G') :
continuous_multilinear_curry_fin0 π G G' f = f 0 := rfl
@[simp] lemma continuous_multilinear_curry_fin0_symm_apply (x : G') (v : (fin 0) β G) :
(continuous_multilinear_curry_fin0 π G G').symm x v = x := rfl
end
/-! #### With 1 variable -/
variables (π G G')
/-- Continuous multilinear maps from `G^1` to `G'` are isomorphic with continuous linear maps from
`G` to `G'`. -/
def continuous_multilinear_curry_fin1 : (G [Γ1]βL[π] G') ββα΅’[π] (G βL[π] G') :=
(continuous_multilinear_curry_right_equiv π (Ξ» (i : fin 1), G) G').symm.trans
(continuous_multilinear_curry_fin0 π G (G βL[π] G'))
variables {π G G'}
@[simp] lemma continuous_multilinear_curry_fin1_apply (f : G [Γ1]βL[π] G') (x : G) :
continuous_multilinear_curry_fin1 π G G' f x = f (fin.snoc 0 x) := rfl
@[simp] lemma continuous_multilinear_curry_fin1_symm_apply
(f : G βL[π] G') (v : (fin 1) β G) :
(continuous_multilinear_curry_fin1 π G G').symm f v = f (v 0) := rfl
namespace continuous_multilinear_map
variables (π G G')
/-- An equivalence of the index set defines a linear isometric equivalence between the spaces
of multilinear maps. -/
def dom_dom_congr (Ο : ΞΉ β ΞΉ') :
continuous_multilinear_map π (Ξ» _ : ΞΉ, G) G' ββα΅’[π]
continuous_multilinear_map π (Ξ» _ : ΞΉ', G) G' :=
linear_isometry_equiv.of_bounds
{ to_fun := Ξ» f, (multilinear_map.dom_dom_congr Ο f.to_multilinear_map).mk_continuous β₯fβ₯ $
Ξ» m, (f.le_op_norm (Ξ» i, m (Ο i))).trans_eq $ by rw [β Ο.prod_comp],
inv_fun := Ξ» f, (multilinear_map.dom_dom_congr Ο.symm f.to_multilinear_map).mk_continuous β₯fβ₯ $
Ξ» m, (f.le_op_norm (Ξ» i, m (Ο.symm i))).trans_eq $ by rw [β Ο.symm.prod_comp],
left_inv := Ξ» f, ext $ Ξ» m, congr_arg f $ by simp only [Ο.symm_apply_apply],
right_inv := Ξ» f, ext $ Ξ» m, congr_arg f $ by simp only [Ο.apply_symm_apply],
map_add' := Ξ» f g, rfl,
map_smul' := Ξ» c f, rfl }
(Ξ» f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
(Ξ» f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
variables {π G G'}
section
variable [decidable_eq (ΞΉ β ΞΉ')]
/-- A continuous multilinear map with variables indexed by `ΞΉ β ΞΉ'` defines a continuous multilinear
map with variables indexed by `ΞΉ` taking values in the space of continuous multilinear maps with
variables indexed by `ΞΉ'`. -/
def curry_sum (f : continuous_multilinear_map π (Ξ» x : ΞΉ β ΞΉ', G) G') :
continuous_multilinear_map π (Ξ» x : ΞΉ, G) (continuous_multilinear_map π (Ξ» x : ΞΉ', G) G') :=
multilinear_map.mk_continuous_multilinear (multilinear_map.curry_sum f.to_multilinear_map) (β₯fβ₯) $
Ξ» m m', by simpa [fintype.prod_sum_type, mul_assoc] using f.le_op_norm (sum.elim m m')
@[simp] lemma curry_sum_apply (f : continuous_multilinear_map π (Ξ» x : ΞΉ β ΞΉ', G) G')
(m : ΞΉ β G) (m' : ΞΉ' β G) :
f.curry_sum m m' = f (sum.elim m m') :=
rfl
/-- A continuous multilinear map with variables indexed by `ΞΉ` taking values in the space of
continuous multilinear maps with variables indexed by `ΞΉ'` defines a continuous multilinear map with
variables indexed by `ΞΉ β ΞΉ'`. -/
def uncurry_sum
(f : continuous_multilinear_map π (Ξ» x : ΞΉ, G) (continuous_multilinear_map π (Ξ» x : ΞΉ', G) G')) :
continuous_multilinear_map π (Ξ» x : ΞΉ β ΞΉ', G) G' :=
multilinear_map.mk_continuous
(to_multilinear_map_linear.comp_multilinear_map f.to_multilinear_map).uncurry_sum (β₯fβ₯) $ Ξ» m,
by simpa [fintype.prod_sum_type, mul_assoc]
using (f (m β sum.inl)).le_of_op_norm_le (m β sum.inr) (f.le_op_norm _)
@[simp] lemma uncurry_sum_apply
(f : continuous_multilinear_map π (Ξ» x : ΞΉ, G) (continuous_multilinear_map π (Ξ» x : ΞΉ', G) G'))
(m : ΞΉ β ΞΉ' β G) :
f.uncurry_sum m = f (m β sum.inl) (m β sum.inr) :=
rfl
variables (π ΞΉ ΞΉ' G G')
/-- Linear isometric equivalence between the space of continuous multilinear maps with variables
indexed by `ΞΉ β ΞΉ'` and the space of continuous multilinear maps with variables indexed by `ΞΉ`
taking values in the space of continuous multilinear maps with variables indexed by `ΞΉ'`.
The forward and inverse functions are `continuous_multilinear_map.curry_sum`
and `continuous_multilinear_map.uncurry_sum`. Use this definition only if you need
some properties of `linear_isometry_equiv`. -/
def curry_sum_equiv : continuous_multilinear_map π (Ξ» x : ΞΉ β ΞΉ', G) G' ββα΅’[π]
continuous_multilinear_map π (Ξ» x : ΞΉ, G) (continuous_multilinear_map π (Ξ» x : ΞΉ', G) G') :=
linear_isometry_equiv.of_bounds
{ to_fun := curry_sum,
inv_fun := uncurry_sum,
map_add' := Ξ» f g, by { ext, refl },
map_smul' := Ξ» c f, by { ext, refl },
left_inv := Ξ» f, by { ext m, exact congr_arg f (sum.elim_comp_inl_inr m) },
right_inv := Ξ» f, by { ext mβ mβ, change f _ _ = f _ _,
rw [sum.elim_comp_inl, sum.elim_comp_inr] } }
(Ξ» f, multilinear_map.mk_continuous_multilinear_norm_le _ (norm_nonneg f) _)
(Ξ» f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
end
section
variables (π G G') {k l : β} {s : finset (fin n)}
/-- If `s : finset (fin n)` is a finite set of cardinality `k` and its complement has cardinality
`l`, then the space of continuous multilinear maps `G [Γn]βL[π] G'` of `n` variables is isomorphic
to the space of continuous multilinear maps `G [Γk]βL[π] G [Γl]βL[π] G'` of `k` variables taking
values in the space of continuous multilinear maps of `l` variables. -/
def curry_fin_finset {k l n : β} {s : finset (fin n)}
(hk : s.card = k) (hl : sαΆ.card = l) :
(G [Γn]βL[π] G') ββα΅’[π] (G [Γk]βL[π] G [Γl]βL[π] G') :=
(dom_dom_congr π G G' (fin_sum_equiv_of_finset hk hl).symm).trans
(curry_sum_equiv π (fin k) (fin l) G G')
variables {π G G'}
@[simp] lemma curry_fin_finset_apply (hk : s.card = k) (hl : sαΆ.card = l)
(f : G [Γn]βL[π] G') (mk : fin k β G) (ml : fin l β G) :
curry_fin_finset π G G' hk hl f mk ml =
f (Ξ» i, sum.elim mk ml ((fin_sum_equiv_of_finset hk hl).symm i)) :=
rfl
@[simp] lemma curry_fin_finset_symm_apply (hk : s.card = k) (hl : sαΆ.card = l)
(f : G [Γk]βL[π] G [Γl]βL[π] G') (m : fin n β G) :
(curry_fin_finset π G G' hk hl).symm f m =
f (Ξ» i, m $ fin_sum_equiv_of_finset hk hl (sum.inl i))
(Ξ» i, m $ fin_sum_equiv_of_finset hk hl (sum.inr i)) :=
rfl
@[simp] lemma curry_fin_finset_symm_apply_piecewise_const (hk : s.card = k) (hl : sαΆ.card = l)
(f : G [Γk]βL[π] G [Γl]βL[π] G') (x y : G) :
(curry_fin_finset π G G' hk hl).symm f (s.piecewise (Ξ» _, x) (Ξ» _, y)) = f (Ξ» _, x) (Ξ» _, y) :=
multilinear_map.curry_fin_finset_symm_apply_piecewise_const hk hl _ x y
@[simp] lemma curry_fin_finset_symm_apply_const (hk : s.card = k) (hl : sαΆ.card = l)
(f : G [Γk]βL[π] G [Γl]βL[π] G') (x : G) :
(curry_fin_finset π G G' hk hl).symm f (Ξ» _, x) = f (Ξ» _, x) (Ξ» _, x) :=
rfl
@[simp] lemma curry_fin_finset_apply_const (hk : s.card = k) (hl : sαΆ.card = l)
(f : G [Γn]βL[π] G') (x y : G) :
curry_fin_finset π G G' hk hl f (Ξ» _, x) (Ξ» _, y) = f (s.piecewise (Ξ» _, x) (Ξ» _, y)) :=
begin
refine (curry_fin_finset_symm_apply_piecewise_const hk hl _ _ _).symm.trans _, -- `rw` fails
rw linear_isometry_equiv.symm_apply_apply
end
end
end continuous_multilinear_map
end currying
|
2a5ccfe6f5cd7c6a0042d9fdb708aa5170810a41
|
d9ed0fce1c218297bcba93e046cb4e79c83c3af8
|
/library/tools/super/clause.lean
|
bb59c37d47d177a4e3d8345be702987fd1dadfad
|
[
"Apache-2.0"
] |
permissive
|
leodemoura/lean_clone
|
005c63aa892a6492f2d4741ee3c2cb07a6be9d7f
|
cc077554b584d39bab55c360bc12a6fe7957afe6
|
refs/heads/master
| 1,610,506,475,484
| 1,482,348,354,000
| 1,482,348,543,000
| 77,091,586
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 8,974
|
lean
|
/-
Copyright (c) 2016 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import init.meta.tactic .utils .trim
open expr list tactic monad decidable
namespace super
meta def is_local_not (local_false : expr) (e : expr) : option expr :=
match e with
| (pi _ _ a b) := if b = local_false then some a else none
| _ := if local_false = false_ then is_not e else none
end
meta structure clause :=
(num_quants : β)
(num_lits : β)
(proof : expr)
(type : expr)
(local_false : expr)
namespace clause
private meta def tactic_format (c : clause) : tactic format := do
prf_fmt : format β pp (proof c),
type_fmt β pp (type c),
loc_fls_fmt β pp c^.local_false,
return $ prf_fmt ++ to_fmt " : " ++ type_fmt ++ to_fmt " (" ++
to_fmt (num_quants c) ++ to_fmt " quants, "
++ to_fmt (num_lits c) ++ to_fmt " lits)"
meta instance : has_to_tactic_format clause := β¨tactic_formatβ©
meta def num_binders (c : clause) : β := num_quants c + num_lits c
meta def inst (c : clause) (e : expr) : clause :=
(if num_quants c > 0
then mk (num_quants c - 1) (num_lits c)
else mk 0 (num_lits c - 1))
(app (proof c) e) (instantiate_var (binding_body (type c)) e) c^.local_false
meta def instn (c : clause) (es : list expr) : clause :=
foldr (Ξ»e c', inst c' e) c es
meta def open_const (c : clause) : tactic (clause Γ expr) := do
n β mk_fresh_name,
b β return $ local_const n (binding_name (type c)) (binding_info (type c)) (binding_domain (type c)),
return (inst c b, b)
meta def open_meta (c : clause) : tactic (clause Γ expr) := do
b β mk_meta_var (binding_domain (type c)),
return (inst c b, b)
meta def close_const (c : clause) (e : expr) : clause :=
match e with
| local_const uniq pp info t :=
let abst_type' := abstract_local (type c) (local_uniq_name e) in
let type' := pi pp binder_info.default t (abstract_local (type c) uniq) in
let abs_prf := abstract_local (proof c) uniq in
let proof' := lambdas [e] c^.proof in
if num_quants c > 0 β¨ has_var abst_type' then
{ c with num_quants := c^.num_quants + 1, proof := proof', type := type' }
else
{ c with num_lits := c^.num_lits + 1, proof := proof', type := type' }
| _ := β¨0, 0, default expr, default expr, default exprβ©
end
meta def open_constn : clause β β β tactic (clause Γ list expr)
| c 0 := return (c, nil)
| c (n+1) := do
(c', b) β open_const c,
(c'', bs) β open_constn c' n,
return (c'', b::bs)
meta def open_metan : clause β β β tactic (clause Γ list expr)
| c 0 := return (c, nil)
| c (n+1) := do
(c', b) β open_meta c,
(c'', bs) β open_metan c' n,
return (c'', b::bs)
meta def close_constn : clause β list expr β clause
| c [] := c
| c (b::bs') := close_const (close_constn c bs') b
set_option eqn_compiler.max_steps 500
private meta def parse_clause (local_false : expr) : expr β expr β tactic clause
| proof (pi n bi d b) := do
lc_n β mk_fresh_name,
lc β return $ local_const lc_n n bi d,
c β parse_clause (app proof lc) (instantiate_var b lc),
return $ c^.close_const $ local_const lc_n n binder_info.default d
| proof (app (const ``not []) formula) := parse_clause proof (formula^.imp false_)
| proof type :=
if type = local_false then do
return { num_quants := 0, num_lits := 0, proof := proof, type := type, local_false := local_false }
else do
univ β infer_univ type,
not_type β return $ imp type local_false,
parse_clause (lam `H binder_info.default not_type $ app (mk_var 0) proof) (imp not_type local_false)
meta def of_proof_and_type (local_false proof type : expr) : tactic clause :=
parse_clause local_false proof type
meta def of_proof (local_false proof : expr) : tactic clause := do
type β infer_type proof,
of_proof_and_type local_false proof type
meta def of_classical_proof (proof : expr) : tactic clause :=
of_proof false_ proof
meta def inst_mvars (c : clause) : tactic clause := do
proof' β instantiate_mvars (proof c),
type' β instantiate_mvars (type c),
return { c with proof := proof', type := type' }
meta inductive literal
| left : expr β literal
| right : expr β literal
namespace literal
meta instance : decidable_eq literal := by mk_dec_eq_instance
meta def formula : literal β expr
| (left f) := f
| (right f) := f
meta def is_neg : literal β bool
| (left _) := tt
| (right _) := ff
meta def is_pos (l : literal) : bool := bnot l^.is_neg
meta def to_formula (l : literal) : tactic expr :=
if is_neg l then mk_mapp ``not [some (formula l)]
else return (formula l)
meta def type_str : literal β string
| (literal.left _) := "left"
| (literal.right _) := "right"
meta instance : has_to_tactic_format literal :=
β¨Ξ»l, do
pp_f β pp l^.formula,
return $ to_fmt l^.type_str ++ " (" ++ pp_f ++ ")"β©
end literal
private meta def get_binding_body : expr β β β expr
| e 0 := e
| e (i+1) := get_binding_body e^.binding_body i
meta def get_binder (e : expr) (i : nat) :=
binding_domain (get_binding_body e i)
meta def validate (c : clause) : tactic unit := do
concl β return $ get_binding_body c^.type c^.num_binders,
unify concl c^.local_false
<|> (do pp_concl β pp concl, pp_lf β pp c^.local_false,
fail $ to_fmt "wrong local false: " ++ pp_concl ++ " =!= " ++ pp_lf),
type' β infer_type c^.proof,
unify c^.type type' <|> (do pp_ty β pp c^.type, pp_ty' β pp type',
fail (to_fmt "wrong type: " ++ pp_ty ++ " =!= " ++ pp_ty'))
meta def get_lit (c : clause) (i : nat) : literal :=
let bind := get_binder (type c) (num_quants c + i) in
match is_local_not c^.local_false bind with
| some formula := literal.right formula
| none := literal.left bind
end
meta def lits_where (c : clause) (p : literal β bool) : list nat :=
list.filter (Ξ»l, p (get_lit c l)) (range (num_lits c))
meta def get_lits (c : clause) : list literal :=
list.map (get_lit c) (range c^.num_lits)
meta def is_maximal (gt : expr β expr β bool) (c : clause) (i : nat) : bool :=
list.empty (list.filter (Ξ»j, gt (get_lit c j)^.formula (get_lit c i)^.formula) (range c^.num_lits))
meta def normalize (c : clause) : tactic clause := do
opened β open_constn c (num_binders c),
lconsts_in_types β return $ contained_lconsts_list (list.map local_type opened.2),
quants' β return $ list.filter (Ξ»lc, rb_map.contains lconsts_in_types (local_uniq_name lc))
opened.2,
lits' β return $ list.filter (Ξ»lc, Β¬rb_map.contains lconsts_in_types (local_uniq_name lc))
opened.2,
return $ close_constn opened.1 (quants' ++ lits')
meta def whnf_head_lit (c : clause) : tactic clause := do
atom' β whnf $ literal.formula $ get_lit c 0,
return $
if literal.is_neg (get_lit c 0) then
{ c with type := imp atom' (binding_body c^.type) }
else
{ c with type := imp (app (const ``not []) atom') c^.type^.binding_body }
end clause
meta def unify_lit (l1 l2 : clause.literal) : tactic unit :=
if clause.literal.is_pos l1 = clause.literal.is_pos l2 then
unify_core transparency.none (clause.literal.formula l1) (clause.literal.formula l2)
else
fail "cannot unify literals"
-- FIXME: this is most definitely broken with meta-variables that were already in the goal
meta def sort_and_constify_metas : list expr β tactic (list expr)
| exprs_with_metas := do
inst_exprs β mapm instantiate_mvars exprs_with_metas,
metas β return $ inst_exprs >>= get_metas,
match list.filter (Ξ»m, Β¬has_meta_var (get_meta_type m)) metas with
| [] :=
if metas^.empty then
return []
else do
for' metas (Ξ»m, do trace (expr.to_string m), t β infer_type m, trace (expr.to_string t)),
fail "could not sort metas"
| ((mvar n t) :: _) := do
t' β infer_type (mvar n t),
uniq β mk_fresh_name,
c β return (local_const uniq uniq binder_info.default t'),
unify c (mvar n t),
rest β sort_and_constify_metas metas,
return (rest ++ [c])
| _ := failed
end
namespace clause
meta def meta_closure (metas : list expr) (qf : clause) : tactic clause := do
bs β sort_and_constify_metas metas,
qf' β clause.inst_mvars qf,
clause.inst_mvars $ clause.close_constn qf' bs
private meta def distinct' (local_false : expr) : list expr β expr β clause
| [] proof := β¨ 0, 0, proof, local_false, local_false β©
| (h::hs) proof :=
let (dups, rest) := partition (Ξ»h' : expr, h^.local_type = h'^.local_type) hs,
proof_wo_dups := foldl (Ξ»proof (h' : expr),
instantiate_var (abstract_local proof h'^.local_uniq_name) h)
proof dups in
(distinct' rest proof_wo_dups)^.close_const h
meta def distinct (c : clause) : tactic clause := do
(qf, vs) β c^.open_constn c^.num_quants,
(fls, hs) β qf^.open_constn qf^.num_lits,
return $ (distinct' c^.local_false hs fls^.proof)^.close_constn vs
end clause
end super
|
4c963c646cbc2a9a60eedb45a05ee364b9ef5170
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/set/basic.lean
|
9ac1590fab6494efde0783f36d01b6e6db9f4dd0
|
[
"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
| 77,683
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import order.symm_diff
import logic.function.iterate
/-!
# Basic properties of sets
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type `X` are thus defined as `set X := X β Prop`. Note that this function need not
be decidable. The definition is in the core library.
This file provides some basic definitions related to sets and functions not present in the core
library, as well as extra lemmas for functions in the core library (empty set, univ, union,
intersection, insert, singleton, set-theoretic difference, complement, and powerset).
Note that a set is a term, not a type. There is a coercion from `set Ξ±` to `Type*` sending
`s` to the corresponding subtype `β₯s`.
See also the file `set_theory/zfc.lean`, which contains an encoding of ZFC set theory in Lean.
## Main definitions
Notation used here:
- `f : Ξ± β Ξ²` is a function,
- `s : set Ξ±` and `sβ sβ : set Ξ±` are subsets of `Ξ±`
- `t : set Ξ²` is a subset of `Ξ²`.
Definitions in the file:
* `nonempty s : Prop` : the predicate `s β β
`. Note that this is the preferred way to express the
fact that `s` has an element (see the Implementation Notes).
* `subsingleton s : Prop` : the predicate saying that `s` has at most one element.
* `nontrivial s : Prop` : the predicate saying that `s` has at least two distinct elements.
* `inclusion sβ sβ : β₯sβ β β₯sβ` : the map `β₯sβ β β₯sβ` induced by an inclusion `sβ β sβ`.
## Notation
* `sαΆ` for the complement of `s`
## Implementation notes
* `s.nonempty` is to be preferred to `s β β
` or `β x, x β s`. It has the advantage that
the `s.nonempty` dot notation can be used.
* For `s : set Ξ±`, do not use `subtype s`. Instead use `β₯s` or `(s : Type*)` or `s`.
## Tags
set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset
-/
/-! ### Set coercion to a type -/
open function
universes u v w x
namespace set
variables {Ξ± : Type*} {s t : set Ξ±}
instance : has_le (set Ξ±) := β¨Ξ» s t, β β¦xβ¦, x β s β x β tβ©
instance : has_subset (set Ξ±) := β¨(β€)β©
instance {Ξ± : Type*} : boolean_algebra (set Ξ±) :=
{ sup := Ξ» s t, {x | x β s β¨ x β t},
le := (β€),
lt := Ξ» s t, s β t β§ Β¬t β s,
inf := Ξ» s t, {x | x β s β§ x β t},
bot := β
,
compl := Ξ» s, {x | x β s},
top := univ,
sdiff := Ξ» s t, {x | x β s β§ x β t},
.. (infer_instance : boolean_algebra (Ξ± β Prop)) }
instance : has_ssubset (set Ξ±) := β¨(<)β©
instance : has_union (set Ξ±) := β¨(β)β©
instance : has_inter (set Ξ±) := β¨(β)β©
@[simp] lemma top_eq_univ : (β€ : set Ξ±) = univ := rfl
@[simp] lemma bot_eq_empty : (β₯ : set Ξ±) = β
:= rfl
@[simp] lemma sup_eq_union : ((β) : set Ξ± β set Ξ± β set Ξ±) = (βͺ) := rfl
@[simp] lemma inf_eq_inter : ((β) : set Ξ± β set Ξ± β set Ξ±) = (β©) := rfl
@[simp] lemma le_eq_subset : ((β€) : set Ξ± β set Ξ± β Prop) = (β) := rfl
@[simp] lemma lt_eq_ssubset : ((<) : set Ξ± β set Ξ± β Prop) = (β) := rfl
lemma le_iff_subset : s β€ t β s β t := iff.rfl
lemma lt_iff_ssubset : s < t β s β t := iff.rfl
alias le_iff_subset β _root_.has_le.le.subset _root_.has_subset.subset.le
alias lt_iff_ssubset β _root_.has_lt.lt.ssubset _root_.has_ssubset.ssubset.lt
/-- Coercion from a set to the corresponding subtype. -/
instance {Ξ± : Type u} : has_coe_to_sort (set Ξ±) (Type u) := β¨Ξ» s, {x // x β s}β©
instance pi_set_coe.can_lift (ΞΉ : Type u) (Ξ± : Ξ i : ΞΉ, Type v) [ne : Ξ i, nonempty (Ξ± i)]
(s : set ΞΉ) :
can_lift (Ξ i : s, Ξ± i) (Ξ i, Ξ± i) (Ξ» f i, f i) (Ξ» _, true) :=
pi_subtype.can_lift ΞΉ Ξ± s
instance pi_set_coe.can_lift' (ΞΉ : Type u) (Ξ± : Type v) [ne : nonempty Ξ±] (s : set ΞΉ) :
can_lift (s β Ξ±) (ΞΉ β Ξ±) (Ξ» f i, f i) (Ξ» _, true) :=
pi_set_coe.can_lift ΞΉ (Ξ» _, Ξ±) s
end set
section set_coe
variables {Ξ± : Type u}
theorem set.coe_eq_subtype (s : set Ξ±) : β₯s = {x // x β s} := rfl
@[simp] theorem set.coe_set_of (p : Ξ± β Prop) : β₯{x | p x} = {x // p x} := rfl
@[simp] theorem set_coe.forall {s : set Ξ±} {p : s β Prop} :
(β x : s, p x) β (β x (h : x β s), p β¨x, hβ©) :=
subtype.forall
@[simp] theorem set_coe.exists {s : set Ξ±} {p : s β Prop} :
(β x : s, p x) β (β x (h : x β s), p β¨x, hβ©) :=
subtype.exists
theorem set_coe.exists' {s : set Ξ±} {p : Ξ x, x β s β Prop} :
(β x (h : x β s), p x h) β (β x : s, p x x.2) :=
(@set_coe.exists _ _ $ Ξ» x, p x.1 x.2).symm
theorem set_coe.forall' {s : set Ξ±} {p : Ξ x, x β s β Prop} :
(β x (h : x β s), p x h) β (β x : s, p x x.2) :=
(@set_coe.forall _ _ $ Ξ» x, p x.1 x.2).symm
@[simp] theorem set_coe_cast : β {s t : set Ξ±} (H' : s = t) (H : β₯s = β₯t) (x : s),
cast H x = β¨x.1, H' βΈ x.2β©
| s _ rfl _ β¨x, hβ© := rfl
theorem set_coe.ext {s : set Ξ±} {a b : s} : (βa : Ξ±) = βb β a = b :=
subtype.eq
theorem set_coe.ext_iff {s : set Ξ±} {a b : s} : (βa : Ξ±) = βb β a = b :=
iff.intro set_coe.ext (assume h, h βΈ rfl)
end set_coe
/-- See also `subtype.prop` -/
lemma subtype.mem {Ξ± : Type*} {s : set Ξ±} (p : s) : (p : Ξ±) β s := p.prop
/-- Duplicate of `eq.subset'`, which currently has elaboration problems. -/
lemma eq.subset {Ξ±} {s t : set Ξ±} : s = t β s β t := eq.subset'
namespace set
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {ΞΉ : Sort x} {a b : Ξ±} {s sβ sβ t tβ tβ u : set Ξ±}
instance : inhabited (set Ξ±) := β¨β
β©
@[ext]
theorem ext {a b : set Ξ±} (h : β x, x β a β x β b) : a = b :=
funext (assume x, propext (h x))
theorem ext_iff {s t : set Ξ±} : s = t β β x, x β s β x β t :=
β¨Ξ» h x, by rw h, extβ©
@[trans] theorem mem_of_mem_of_subset {x : Ξ±} {s t : set Ξ±} (hx : x β s) (h : s β t) : x β t := h hx
lemma forall_in_swap {p : Ξ± β Ξ² β Prop} :
(β (a β s) b, p a b) β β b (a β s), p a b :=
by tauto
/-! ### Lemmas about `mem` and `set_of` -/
lemma mem_set_of {a : Ξ±} {p : Ξ± β Prop} : a β {x | p x} β p a := iff.rfl
/-- If `h : a β {x | p x}` then `h.out : p x`. These are definitionally equal, but this can
nevertheless be useful for various reasons, e.g. to apply further projection notation or in an
argument to `simp`. -/
lemma _root_.has_mem.mem.out {p : Ξ± β Prop} {a : Ξ±} (h : a β {x | p x}) : p a := h
theorem nmem_set_of_iff {a : Ξ±} {p : Ξ± β Prop} : a β {x | p x} β Β¬ p a := iff.rfl
@[simp] theorem set_of_mem_eq {s : set Ξ±} : {x | x β s} = s := rfl
theorem set_of_set {s : set Ξ±} : set_of s = s := rfl
lemma set_of_app_iff {p : Ξ± β Prop} {x : Ξ±} : {x | p x} x β p x := iff.rfl
theorem mem_def {a : Ξ±} {s : set Ξ±} : a β s β s a := iff.rfl
lemma set_of_bijective : bijective (set_of : (Ξ± β Prop) β set Ξ±) := bijective_id
@[simp] theorem set_of_subset_set_of {p q : Ξ± β Prop} :
{a | p a} β {a | q a} β (βa, p a β q a) := iff.rfl
lemma set_of_and {p q : Ξ± β Prop} : {a | p a β§ q a} = {a | p a} β© {a | q a} := rfl
lemma set_of_or {p q : Ξ± β Prop} : {a | p a β¨ q a} = {a | p a} βͺ {a | q a} := rfl
/-! ### Subset and strict subset relations -/
instance : is_refl (set Ξ±) (β) := has_le.le.is_refl
instance : is_trans (set Ξ±) (β) := has_le.le.is_trans
instance : is_antisymm (set Ξ±) (β) := has_le.le.is_antisymm
instance : is_irrefl (set Ξ±) (β) := has_lt.lt.is_irrefl
instance : is_trans (set Ξ±) (β) := has_lt.lt.is_trans
instance : is_asymm (set Ξ±) (β) := has_lt.lt.is_asymm
instance : is_nonstrict_strict_order (set Ξ±) (β) (β) := β¨Ξ» _ _, iff.rflβ©
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
lemma subset_def : (s β t) = β x, x β s β x β t := rfl
lemma ssubset_def : s β t = (s β t β§ Β¬ t β s) := rfl
@[refl] theorem subset.refl (a : set Ξ±) : a β a := assume x, id
theorem subset.rfl {s : set Ξ±} : s β s := subset.refl s
@[trans] theorem subset.trans {a b c : set Ξ±} (ab : a β b) (bc : b β c) : a β c := Ξ» x h, bc $ ab h
@[trans] theorem mem_of_eq_of_mem {x y : Ξ±} {s : set Ξ±} (hx : x = y) (h : y β s) : x β s :=
hx.symm βΈ h
theorem subset.antisymm {a b : set Ξ±} (hβ : a β b) (hβ : b β a) : a = b :=
set.ext $ Ξ» x, β¨@hβ _, @hβ _β©
theorem subset.antisymm_iff {a b : set Ξ±} : a = b β a β b β§ b β a :=
β¨Ξ» e, β¨e.subset, e.symm.subsetβ©, Ξ» β¨hβ, hββ©, subset.antisymm hβ hββ©
-- an alternative name
theorem eq_of_subset_of_subset {a b : set Ξ±} : a β b β b β a β a = b := subset.antisymm
theorem mem_of_subset_of_mem {sβ sβ : set Ξ±} {a : Ξ±} (h : sβ β sβ) : a β sβ β a β sβ := @h _
theorem not_mem_subset (h : s β t) : a β t β a β s :=
mt $ mem_of_subset_of_mem h
theorem not_subset : (Β¬ s β t) β βa β s, a β t := by simp only [subset_def, not_forall]
/-! ### Definition of strict subsets `s β t` and basic properties. -/
protected theorem eq_or_ssubset_of_subset (h : s β t) : s = t β¨ s β t :=
eq_or_lt_of_le h
lemma exists_of_ssubset {s t : set Ξ±} (h : s β t) : (βxβt, x β s) :=
not_subset.1 h.2
protected lemma ssubset_iff_subset_ne {s t : set Ξ±} : s β t β s β t β§ s β t :=
@lt_iff_le_and_ne (set Ξ±) _ s t
lemma ssubset_iff_of_subset {s t : set Ξ±} (h : s β t) : s β t β β x β t, x β s :=
β¨exists_of_ssubset, Ξ» β¨x, hxt, hxsβ©, β¨h, Ξ» h, hxs $ h hxtβ©β©
protected lemma ssubset_of_ssubset_of_subset {sβ sβ sβ : set Ξ±} (hsβsβ : sβ β sβ)
(hsβsβ : sβ β sβ) :
sβ β sβ :=
β¨subset.trans hsβsβ.1 hsβsβ, Ξ» hsβsβ, hsβsβ.2 (subset.trans hsβsβ hsβsβ)β©
protected lemma ssubset_of_subset_of_ssubset {sβ sβ sβ : set Ξ±} (hsβsβ : sβ β sβ)
(hsβsβ : sβ β sβ) :
sβ β sβ :=
β¨subset.trans hsβsβ hsβsβ.1, Ξ» hsβsβ, hsβsβ.2 (subset.trans hsβsβ hsβsβ)β©
theorem not_mem_empty (x : Ξ±) : Β¬ (x β (β
: set Ξ±)) := id
@[simp] theorem not_not_mem : Β¬ (a β s) β a β s := not_not
/-! ### Non-empty sets -/
/-- The property `s.nonempty` expresses the fact that the set `s` is not empty. It should be used
in theorem assumptions instead of `β x, x β s` or `s β β
` as it gives access to a nice API thanks
to the dot notation. -/
protected def nonempty (s : set Ξ±) : Prop := β x, x β s
@[simp] lemma nonempty_coe_sort {s : set Ξ±} : nonempty β₯s β s.nonempty := nonempty_subtype
alias nonempty_coe_sort β _ nonempty.coe_sort
lemma nonempty_def : s.nonempty β β x, x β s := iff.rfl
lemma nonempty_of_mem {x} (h : x β s) : s.nonempty := β¨x, hβ©
theorem nonempty.not_subset_empty : s.nonempty β Β¬(s β β
)
| β¨x, hxβ© hs := hs hx
/-- Extract a witness from `s.nonempty`. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the `classical.choice` axiom. -/
protected noncomputable def nonempty.some (h : s.nonempty) : Ξ± := classical.some h
protected lemma nonempty.some_mem (h : s.nonempty) : h.some β s := classical.some_spec h
lemma nonempty.mono (ht : s β t) (hs : s.nonempty) : t.nonempty := hs.imp ht
lemma nonempty_of_not_subset (h : Β¬s β t) : (s \ t).nonempty :=
let β¨x, xs, xtβ© := not_subset.1 h in β¨x, xs, xtβ©
lemma nonempty_of_ssubset (ht : s β t) : (t \ s).nonempty :=
nonempty_of_not_subset ht.2
lemma nonempty.of_diff (h : (s \ t).nonempty) : s.nonempty := h.imp $ Ξ» _, and.left
lemma nonempty_of_ssubset' (ht : s β t) : t.nonempty := (nonempty_of_ssubset ht).of_diff
lemma nonempty.inl (hs : s.nonempty) : (s βͺ t).nonempty := hs.imp $ Ξ» _, or.inl
lemma nonempty.inr (ht : t.nonempty) : (s βͺ t).nonempty := ht.imp $ Ξ» _, or.inr
@[simp] lemma union_nonempty : (s βͺ t).nonempty β s.nonempty β¨ t.nonempty := exists_or_distrib
lemma nonempty.left (h : (s β© t).nonempty) : s.nonempty := h.imp $ Ξ» _, and.left
lemma nonempty.right (h : (s β© t).nonempty) : t.nonempty := h.imp $ Ξ» _, and.right
lemma inter_nonempty : (s β© t).nonempty β β x, x β s β§ x β t := iff.rfl
lemma inter_nonempty_iff_exists_left : (s β© t).nonempty β β x β s, x β t :=
by simp_rw [inter_nonempty, exists_prop]
lemma inter_nonempty_iff_exists_right : (s β© t).nonempty β β x β t, x β s :=
by simp_rw [inter_nonempty, exists_prop, and_comm]
lemma nonempty_iff_univ_nonempty : nonempty Ξ± β (univ : set Ξ±).nonempty :=
β¨Ξ» β¨xβ©, β¨x, trivialβ©, Ξ» β¨x, _β©, β¨xβ©β©
@[simp] lemma univ_nonempty : β [h : nonempty Ξ±], (univ : set Ξ±).nonempty
| β¨xβ© := β¨x, trivialβ©
lemma nonempty.to_subtype : s.nonempty β nonempty s := nonempty_subtype.2
lemma nonempty.to_type : s.nonempty β nonempty Ξ± := Ξ» β¨x, hxβ©, β¨xβ©
instance [nonempty Ξ±] : nonempty (set.univ : set Ξ±) := set.univ_nonempty.to_subtype
lemma nonempty_of_nonempty_subtype [nonempty s] : s.nonempty :=
nonempty_subtype.mp βΉ_βΊ
/-! ### Lemmas about the empty set -/
theorem empty_def : (β
: set Ξ±) = {x | false} := rfl
@[simp] theorem mem_empty_iff_false (x : Ξ±) : x β (β
: set Ξ±) β false := iff.rfl
@[simp] theorem set_of_false : {a : Ξ± | false} = β
:= rfl
@[simp] theorem empty_subset (s : set Ξ±) : β
β s.
theorem subset_empty_iff {s : set Ξ±} : s β β
β s = β
:=
(subset.antisymm_iff.trans $ and_iff_left (empty_subset _)).symm
theorem eq_empty_iff_forall_not_mem {s : set Ξ±} : s = β
β β x, x β s := subset_empty_iff.symm
lemma eq_empty_of_forall_not_mem (h : β x, x β s) : s = β
:= subset_empty_iff.1 h
theorem eq_empty_of_subset_empty {s : set Ξ±} : s β β
β s = β
:= subset_empty_iff.1
theorem eq_empty_of_is_empty [is_empty Ξ±] (s : set Ξ±) : s = β
:=
eq_empty_of_subset_empty $ Ξ» x hx, is_empty_elim x
/-- There is exactly one set of a type that is empty. -/
instance unique_empty [is_empty Ξ±] : unique (set Ξ±) :=
{ default := β
, uniq := eq_empty_of_is_empty }
/-- See also `set.nonempty_iff_ne_empty`. -/
lemma not_nonempty_iff_eq_empty {s : set Ξ±} : Β¬s.nonempty β s = β
:=
by simp only [set.nonempty, eq_empty_iff_forall_not_mem, not_exists]
/-- See also `set.not_nonempty_iff_eq_empty`. -/
lemma nonempty_iff_ne_empty : s.nonempty β s β β
:= not_nonempty_iff_eq_empty.not_right
alias nonempty_iff_ne_empty β nonempty.ne_empty _
@[simp] lemma not_nonempty_empty : Β¬(β
: set Ξ±).nonempty := Ξ» β¨x, hxβ©, hx
@[simp] lemma is_empty_coe_sort {s : set Ξ±} : is_empty β₯s β s = β
:=
not_iff_not.1 $ by simpa using nonempty_iff_ne_empty
lemma eq_empty_or_nonempty (s : set Ξ±) : s = β
β¨ s.nonempty :=
or_iff_not_imp_left.2 nonempty_iff_ne_empty.2
theorem subset_eq_empty {s t : set Ξ±} (h : t β s) (e : s = β
) : t = β
:=
subset_empty_iff.1 $ e βΈ h
theorem ball_empty_iff {p : Ξ± β Prop} : (β x β (β
: set Ξ±), p x) β true :=
iff_true_intro $ Ξ» x, false.elim
instance (Ξ± : Type u) : is_empty.{u+1} (β
: set Ξ±) :=
β¨Ξ» x, x.2β©
@[simp] lemma empty_ssubset : β
β s β s.nonempty :=
(@bot_lt_iff_ne_bot (set Ξ±) _ _ _).trans nonempty_iff_ne_empty.symm
alias empty_ssubset β _ nonempty.empty_ssubset
/-!
### Universal set.
In Lean `@univ Ξ±` (or `univ : set Ξ±`) is the set that contains all elements of type `Ξ±`.
Mathematically it is the same as `Ξ±` but it has a different type.
-/
@[simp] theorem set_of_true : {x : Ξ± | true} = univ := rfl
@[simp, mfld_simps] theorem mem_univ (x : Ξ±) : x β @univ Ξ± := trivial
@[simp] lemma univ_eq_empty_iff : (univ : set Ξ±) = β
β is_empty Ξ± :=
eq_empty_iff_forall_not_mem.trans β¨Ξ» H, β¨Ξ» x, H x trivialβ©, Ξ» H x _, @is_empty.false Ξ± H xβ©
theorem empty_ne_univ [nonempty Ξ±] : (β
: set Ξ±) β univ :=
Ξ» e, not_is_empty_of_nonempty Ξ± $ univ_eq_empty_iff.1 e.symm
@[simp] theorem subset_univ (s : set Ξ±) : s β univ := Ξ» x H, trivial
theorem univ_subset_iff {s : set Ξ±} : univ β s β s = univ := @top_le_iff _ _ _ s
alias univ_subset_iff β eq_univ_of_univ_subset _
theorem eq_univ_iff_forall {s : set Ξ±} : s = univ β β x, x β s :=
univ_subset_iff.symm.trans $ forall_congr $ Ξ» x, imp_iff_right trivial
theorem eq_univ_of_forall {s : set Ξ±} : (β x, x β s) β s = univ := eq_univ_iff_forall.2
lemma nonempty.eq_univ [subsingleton Ξ±] : s.nonempty β s = univ :=
by { rintro β¨x, hxβ©, refine eq_univ_of_forall (Ξ» y, by rwa subsingleton.elim y x) }
lemma eq_univ_of_subset {s t : set Ξ±} (h : s β t) (hs : s = univ) : t = univ :=
eq_univ_of_univ_subset $ hs βΈ h
lemma exists_mem_of_nonempty (Ξ±) : β [nonempty Ξ±], βx:Ξ±, x β (univ : set Ξ±)
| β¨xβ© := β¨x, trivialβ©
lemma ne_univ_iff_exists_not_mem {Ξ± : Type*} (s : set Ξ±) : s β univ β β a, a β s :=
by rw [βnot_forall, βeq_univ_iff_forall]
lemma not_subset_iff_exists_mem_not_mem {Ξ± : Type*} {s t : set Ξ±} :
Β¬ s β t β β x, x β s β§ x β t :=
by simp [subset_def]
lemma univ_unique [unique Ξ±] : @set.univ Ξ± = {default} :=
set.ext $ Ξ» x, iff_of_true trivial $ subsingleton.elim x default
lemma ssubset_univ_iff : s β univ β s β univ := lt_top_iff_ne_top
instance nontrivial_of_nonempty [nonempty Ξ±] : nontrivial (set Ξ±) := β¨β¨β
, univ, empty_ne_univβ©β©
/-! ### Lemmas about union -/
theorem union_def {sβ sβ : set Ξ±} : sβ βͺ sβ = {a | a β sβ β¨ a β sβ} := rfl
theorem mem_union_left {x : Ξ±} {a : set Ξ±} (b : set Ξ±) : x β a β x β a βͺ b := or.inl
theorem mem_union_right {x : Ξ±} {b : set Ξ±} (a : set Ξ±) : x β b β x β a βͺ b := or.inr
theorem mem_or_mem_of_mem_union {x : Ξ±} {a b : set Ξ±} (H : x β a βͺ b) : x β a β¨ x β b := H
theorem mem_union.elim {x : Ξ±} {a b : set Ξ±} {P : Prop}
(Hβ : x β a βͺ b) (Hβ : x β a β P) (Hβ : x β b β P) : P :=
or.elim Hβ Hβ Hβ
@[simp] theorem mem_union (x : Ξ±) (a b : set Ξ±) : x β a βͺ b β (x β a β¨ x β b) := iff.rfl
@[simp] theorem union_self (a : set Ξ±) : a βͺ a = a := ext $ Ξ» x, or_self _
@[simp] theorem union_empty (a : set Ξ±) : a βͺ β
= a := ext $ Ξ» x, or_false _
@[simp] theorem empty_union (a : set Ξ±) : β
βͺ a = a := ext $ Ξ» x, false_or _
theorem union_comm (a b : set Ξ±) : a βͺ b = b βͺ a := ext $ Ξ» x, or.comm
theorem union_assoc (a b c : set Ξ±) : (a βͺ b) βͺ c = a βͺ (b βͺ c) := ext $ Ξ» x, or.assoc
instance union_is_assoc : is_associative (set Ξ±) (βͺ) := β¨union_assocβ©
instance union_is_comm : is_commutative (set Ξ±) (βͺ) := β¨union_commβ©
theorem union_left_comm (sβ sβ sβ : set Ξ±) : sβ βͺ (sβ βͺ sβ) = sβ βͺ (sβ βͺ sβ) :=
ext $ Ξ» x, or.left_comm
theorem union_right_comm (sβ sβ sβ : set Ξ±) : (sβ βͺ sβ) βͺ sβ = (sβ βͺ sβ) βͺ sβ :=
ext $ Ξ» x, or.right_comm
@[simp] theorem union_eq_left_iff_subset {s t : set Ξ±} : s βͺ t = s β t β s :=
sup_eq_left
@[simp] theorem union_eq_right_iff_subset {s t : set Ξ±} : s βͺ t = t β s β t :=
sup_eq_right
theorem union_eq_self_of_subset_left {s t : set Ξ±} (h : s β t) : s βͺ t = t :=
union_eq_right_iff_subset.mpr h
theorem union_eq_self_of_subset_right {s t : set Ξ±} (h : t β s) : s βͺ t = s :=
union_eq_left_iff_subset.mpr h
@[simp] theorem subset_union_left (s t : set Ξ±) : s β s βͺ t := Ξ» x, or.inl
@[simp] theorem subset_union_right (s t : set Ξ±) : t β s βͺ t := Ξ» x, or.inr
theorem union_subset {s t r : set Ξ±} (sr : s β r) (tr : t β r) : s βͺ t β r :=
Ξ» x, or.rec (@sr _) (@tr _)
@[simp] theorem union_subset_iff {s t u : set Ξ±} : s βͺ t β u β s β u β§ t β u :=
(forall_congr (by exact Ξ» x, or_imp_distrib)).trans forall_and_distrib
theorem union_subset_union {sβ sβ tβ tβ : set Ξ±}
(hβ : sβ β sβ) (hβ : tβ β tβ) : sβ βͺ tβ β sβ βͺ tβ := Ξ» x, or.imp (@hβ _) (@hβ _)
theorem union_subset_union_left {sβ sβ : set Ξ±} (t) (h : sβ β sβ) : sβ βͺ t β sβ βͺ t :=
union_subset_union h subset.rfl
theorem union_subset_union_right (s) {tβ tβ : set Ξ±} (h : tβ β tβ) : s βͺ tβ β s βͺ tβ :=
union_subset_union subset.rfl h
lemma subset_union_of_subset_left {s t : set Ξ±} (h : s β t) (u : set Ξ±) : s β t βͺ u :=
subset.trans h (subset_union_left t u)
lemma subset_union_of_subset_right {s u : set Ξ±} (h : s β u) (t : set Ξ±) : s β t βͺ u :=
subset.trans h (subset_union_right t u)
lemma union_congr_left (ht : t β s βͺ u) (hu : u β s βͺ t) : s βͺ t = s β u := sup_congr_left ht hu
lemma union_congr_right (hs : s β t βͺ u) (ht : t β s βͺ u) : s βͺ u = t βͺ u := sup_congr_right hs ht
lemma union_eq_union_iff_left : s βͺ t = s βͺ u β t β s βͺ u β§ u β s βͺ t := sup_eq_sup_iff_left
lemma union_eq_union_iff_right : s βͺ u = t βͺ u β s β t βͺ u β§ t β s βͺ u := sup_eq_sup_iff_right
@[simp] theorem union_empty_iff {s t : set Ξ±} : s βͺ t = β
β s = β
β§ t = β
:=
by simp only [β subset_empty_iff]; exact union_subset_iff
@[simp] lemma union_univ {s : set Ξ±} : s βͺ univ = univ := sup_top_eq
@[simp] lemma univ_union {s : set Ξ±} : univ βͺ s = univ := top_sup_eq
/-! ### Lemmas about intersection -/
theorem inter_def {sβ sβ : set Ξ±} : sβ β© sβ = {a | a β sβ β§ a β sβ} := rfl
@[simp, mfld_simps]
theorem mem_inter_iff (x : Ξ±) (a b : set Ξ±) : x β a β© b β (x β a β§ x β b) := iff.rfl
theorem mem_inter {x : Ξ±} {a b : set Ξ±} (ha : x β a) (hb : x β b) : x β a β© b := β¨ha, hbβ©
theorem mem_of_mem_inter_left {x : Ξ±} {a b : set Ξ±} (h : x β a β© b) : x β a := h.left
theorem mem_of_mem_inter_right {x : Ξ±} {a b : set Ξ±} (h : x β a β© b) : x β b := h.right
@[simp] theorem inter_self (a : set Ξ±) : a β© a = a := ext $ Ξ» x, and_self _
@[simp] theorem inter_empty (a : set Ξ±) : a β© β
= β
:= ext $ Ξ» x, and_false _
@[simp] theorem empty_inter (a : set Ξ±) : β
β© a = β
:= ext $ Ξ» x, false_and _
theorem inter_comm (a b : set Ξ±) : a β© b = b β© a := ext $ Ξ» x, and.comm
theorem inter_assoc (a b c : set Ξ±) : (a β© b) β© c = a β© (b β© c) := ext $ Ξ» x, and.assoc
instance inter_is_assoc : is_associative (set Ξ±) (β©) := β¨inter_assocβ©
instance inter_is_comm : is_commutative (set Ξ±) (β©) := β¨inter_commβ©
theorem inter_left_comm (sβ sβ sβ : set Ξ±) : sβ β© (sβ β© sβ) = sβ β© (sβ β© sβ) :=
ext $ Ξ» x, and.left_comm
theorem inter_right_comm (sβ sβ sβ : set Ξ±) : (sβ β© sβ) β© sβ = (sβ β© sβ) β© sβ :=
ext $ Ξ» x, and.right_comm
@[simp, mfld_simps] theorem inter_subset_left (s t : set Ξ±) : s β© t β s := Ξ» x, and.left
@[simp] theorem inter_subset_right (s t : set Ξ±) : s β© t β t := Ξ» x, and.right
theorem subset_inter {s t r : set Ξ±} (rs : r β s) (rt : r β t) : r β s β© t := Ξ» x h, β¨rs h, rt hβ©
@[simp] theorem subset_inter_iff {s t r : set Ξ±} : r β s β© t β r β s β§ r β t :=
(forall_congr (by exact Ξ» x, imp_and_distrib)).trans forall_and_distrib
@[simp] theorem inter_eq_left_iff_subset {s t : set Ξ±} : s β© t = s β s β t :=
inf_eq_left
@[simp] theorem inter_eq_right_iff_subset {s t : set Ξ±} : s β© t = t β t β s :=
inf_eq_right
theorem inter_eq_self_of_subset_left {s t : set Ξ±} : s β t β s β© t = s :=
inter_eq_left_iff_subset.mpr
theorem inter_eq_self_of_subset_right {s t : set Ξ±} : t β s β s β© t = t :=
inter_eq_right_iff_subset.mpr
lemma inter_congr_left (ht : s β© u β t) (hu : s β© t β u) : s β© t = s β© u := inf_congr_left ht hu
lemma inter_congr_right (hs : t β© u β s) (ht : s β© u β t) : s β© u = t β© u := inf_congr_right hs ht
lemma inter_eq_inter_iff_left : s β© t = s β© u β s β© u β t β§ s β© t β u := inf_eq_inf_iff_left
lemma inter_eq_inter_iff_right : s β© u = t β© u β t β© u β s β§ s β© u β t := inf_eq_inf_iff_right
@[simp, mfld_simps] theorem inter_univ (a : set Ξ±) : a β© univ = a := inf_top_eq
@[simp, mfld_simps] theorem univ_inter (a : set Ξ±) : univ β© a = a := top_inf_eq
theorem inter_subset_inter {sβ sβ tβ tβ : set Ξ±}
(hβ : sβ β tβ) (hβ : sβ β tβ) : sβ β© sβ β tβ β© tβ := Ξ» x, and.imp (@hβ _) (@hβ _)
theorem inter_subset_inter_left {s t : set Ξ±} (u : set Ξ±) (H : s β t) : s β© u β t β© u :=
inter_subset_inter H subset.rfl
theorem inter_subset_inter_right {s t : set Ξ±} (u : set Ξ±) (H : s β t) : u β© s β u β© t :=
inter_subset_inter subset.rfl H
theorem union_inter_cancel_left {s t : set Ξ±} : (s βͺ t) β© s = s :=
inter_eq_self_of_subset_right $ subset_union_left _ _
theorem union_inter_cancel_right {s t : set Ξ±} : (s βͺ t) β© t = t :=
inter_eq_self_of_subset_right $ subset_union_right _ _
lemma inter_set_of_eq_sep (s : set Ξ±) (p : Ξ± β Prop) : s β© {a | p a} = {a β s | p a} := rfl
lemma set_of_inter_eq_sep (p : Ξ± β Prop) (s : set Ξ±) : {a | p a} β© s = {a β s | p a} :=
inter_comm _ _
/-! ### Distributivity laws -/
theorem inter_distrib_left (s t u : set Ξ±) : s β© (t βͺ u) = (s β© t) βͺ (s β© u) :=
inf_sup_left
theorem inter_union_distrib_left {s t u : set Ξ±} : s β© (t βͺ u) = (s β© t) βͺ (s β© u) :=
inf_sup_left
theorem inter_distrib_right (s t u : set Ξ±) : (s βͺ t) β© u = (s β© u) βͺ (t β© u) :=
inf_sup_right
theorem union_inter_distrib_right {s t u : set Ξ±} : (s βͺ t) β© u = (s β© u) βͺ (t β© u) :=
inf_sup_right
theorem union_distrib_left (s t u : set Ξ±) : s βͺ (t β© u) = (s βͺ t) β© (s βͺ u) :=
sup_inf_left
theorem union_inter_distrib_left {s t u : set Ξ±} : s βͺ (t β© u) = (s βͺ t) β© (s βͺ u) :=
sup_inf_left
theorem union_distrib_right (s t u : set Ξ±) : (s β© t) βͺ u = (s βͺ u) β© (t βͺ u) :=
sup_inf_right
theorem inter_union_distrib_right {s t u : set Ξ±} : (s β© t) βͺ u = (s βͺ u) β© (t βͺ u) :=
sup_inf_right
lemma union_union_distrib_left (s t u : set Ξ±) : s βͺ (t βͺ u) = (s βͺ t) βͺ (s βͺ u) :=
sup_sup_distrib_left _ _ _
lemma union_union_distrib_right (s t u : set Ξ±) : (s βͺ t) βͺ u = (s βͺ u) βͺ (t βͺ u) :=
sup_sup_distrib_right _ _ _
lemma inter_inter_distrib_left (s t u : set Ξ±) : s β© (t β© u) = (s β© t) β© (s β© u) :=
inf_inf_distrib_left _ _ _
lemma inter_inter_distrib_right (s t u : set Ξ±) : (s β© t) β© u = (s β© u) β© (t β© u) :=
inf_inf_distrib_right _ _ _
lemma union_union_union_comm (s t u v : set Ξ±) : (s βͺ t) βͺ (u βͺ v) = (s βͺ u) βͺ (t βͺ v) :=
sup_sup_sup_comm _ _ _ _
lemma inter_inter_inter_comm (s t u v : set Ξ±) : (s β© t) β© (u β© v) = (s β© u) β© (t β© v) :=
inf_inf_inf_comm _ _ _ _
/-!
### Lemmas about `insert`
`insert Ξ± s` is the set `{Ξ±} βͺ s`.
-/
theorem insert_def (x : Ξ±) (s : set Ξ±) : insert x s = { y | y = x β¨ y β s } := rfl
@[simp] theorem subset_insert (x : Ξ±) (s : set Ξ±) : s β insert x s := Ξ» y, or.inr
theorem mem_insert (x : Ξ±) (s : set Ξ±) : x β insert x s := or.inl rfl
theorem mem_insert_of_mem {x : Ξ±} {s : set Ξ±} (y : Ξ±) : x β s β x β insert y s := or.inr
theorem eq_or_mem_of_mem_insert {x a : Ξ±} {s : set Ξ±} : x β insert a s β x = a β¨ x β s := id
lemma mem_of_mem_insert_of_ne : b β insert a s β b β a β b β s := or.resolve_left
lemma eq_of_not_mem_of_mem_insert : b β insert a s β b β s β b = a := or.resolve_right
@[simp] theorem mem_insert_iff {x a : Ξ±} {s : set Ξ±} : x β insert a s β x = a β¨ x β s := iff.rfl
@[simp] theorem insert_eq_of_mem {a : Ξ±} {s : set Ξ±} (h : a β s) : insert a s = s :=
ext $ Ξ» x, or_iff_right_of_imp $ Ξ» e, e.symm βΈ h
lemma ne_insert_of_not_mem {s : set Ξ±} (t : set Ξ±) {a : Ξ±} : a β s β s β insert a t :=
mt $ Ξ» e, e.symm βΈ mem_insert _ _
@[simp] lemma insert_eq_self : insert a s = s β a β s := β¨Ξ» h, h βΈ mem_insert _ _, insert_eq_of_memβ©
lemma insert_ne_self : insert a s β s β a β s := insert_eq_self.not
theorem insert_subset : insert a s β t β (a β t β§ s β t) :=
by simp only [subset_def, or_imp_distrib, forall_and_distrib, forall_eq, mem_insert_iff]
theorem insert_subset_insert (h : s β t) : insert a s β insert a t := Ξ» x, or.imp_right (@h _)
theorem insert_subset_insert_iff (ha : a β s) : insert a s β insert a t β s β t :=
begin
refine β¨Ξ» h x hx, _, insert_subset_insertβ©,
rcases h (subset_insert _ _ hx) with (rfl|hxt),
exacts [(ha hx).elim, hxt]
end
theorem subset_insert_iff_of_not_mem (ha : a β s) : s β insert a t β s β t :=
forallβ_congr $ Ξ» b hb, or_iff_right $ ne_of_mem_of_not_mem hb ha
theorem ssubset_iff_insert {s t : set Ξ±} : s β t β β a β s, insert a s β t :=
begin
simp only [insert_subset, exists_and_distrib_right, ssubset_def, not_subset],
simp only [exists_prop, and_comm]
end
theorem ssubset_insert {s : set Ξ±} {a : Ξ±} (h : a β s) : s β insert a s :=
ssubset_iff_insert.2 β¨a, h, subset.rflβ©
theorem insert_comm (a b : Ξ±) (s : set Ξ±) : insert a (insert b s) = insert b (insert a s) :=
ext $ Ξ» x, or.left_comm
@[simp] lemma insert_idem (a : Ξ±) (s : set Ξ±) : insert a (insert a s) = insert a s :=
insert_eq_of_mem $ mem_insert _ _
theorem insert_union : insert a s βͺ t = insert a (s βͺ t) := ext $ Ξ» x, or.assoc
@[simp] theorem union_insert : s βͺ insert a t = insert a (s βͺ t) := ext $ Ξ» x, or.left_comm
@[simp] theorem insert_nonempty (a : Ξ±) (s : set Ξ±) : (insert a s).nonempty := β¨a, mem_insert a sβ©
instance (a : Ξ±) (s : set Ξ±) : nonempty (insert a s : set Ξ±) := (insert_nonempty a s).to_subtype
lemma insert_inter_distrib (a : Ξ±) (s t : set Ξ±) : insert a (s β© t) = insert a s β© insert a t :=
ext $ Ξ» y, or_and_distrib_left
lemma insert_union_distrib (a : Ξ±) (s t : set Ξ±) : insert a (s βͺ t) = insert a s βͺ insert a t :=
ext $ Ξ» _, or_or_distrib_left _ _ _
lemma insert_inj (ha : a β s) : insert a s = insert b s β a = b :=
β¨Ξ» h, eq_of_not_mem_of_mem_insert (h.subst $ mem_insert a s) ha, congr_arg _β©
-- useful in proofs by induction
theorem forall_of_forall_insert {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±}
(H : β x, x β insert a s β P x) (x) (h : x β s) : P x := H _ (or.inr h)
theorem forall_insert_of_forall {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±}
(H : β x, x β s β P x) (ha : P a) (x) (h : x β insert a s) : P x :=
h.elim (Ξ» e, e.symm βΈ ha) (H _)
theorem bex_insert_iff {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} :
(β x β insert a s, P x) β P a β¨ (β x β s, P x) :=
bex_or_left_distrib.trans $ or_congr_left' bex_eq_left
theorem ball_insert_iff {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} :
(β x β insert a s, P x) β P a β§ (βx β s, P x) :=
ball_or_left_distrib.trans $ and_congr_left' forall_eq
/-! ### Lemmas about singletons -/
theorem singleton_def (a : Ξ±) : ({a} : set Ξ±) = insert a β
:= (insert_emptyc_eq _).symm
@[simp] theorem mem_singleton_iff {a b : Ξ±} : a β ({b} : set Ξ±) β a = b := iff.rfl
@[simp] lemma set_of_eq_eq_singleton {a : Ξ±} : {n | n = a} = {a} := rfl
@[simp] lemma set_of_eq_eq_singleton' {a : Ξ±} : {x | a = x} = {a} := ext $ Ξ» x, eq_comm
-- TODO: again, annotation needed
@[simp] theorem mem_singleton (a : Ξ±) : a β ({a} : set Ξ±) := @rfl _ _
theorem eq_of_mem_singleton {x y : Ξ±} (h : x β ({y} : set Ξ±)) : x = y := h
@[simp] theorem singleton_eq_singleton_iff {x y : Ξ±} : {x} = ({y} : set Ξ±) β x = y :=
ext_iff.trans eq_iff_eq_cancel_left
lemma singleton_injective : injective (singleton : Ξ± β set Ξ±) :=
Ξ» _ _, singleton_eq_singleton_iff.mp
theorem mem_singleton_of_eq {x y : Ξ±} (H : x = y) : x β ({y} : set Ξ±) := H
theorem insert_eq (x : Ξ±) (s : set Ξ±) : insert x s = ({x} : set Ξ±) βͺ s := rfl
@[simp] theorem singleton_nonempty (a : Ξ±) : ({a} : set Ξ±).nonempty :=
β¨a, rflβ©
@[simp] lemma singleton_ne_empty (a : Ξ±) : ({a} : set Ξ±) β β
:= (singleton_nonempty _).ne_empty
@[simp] lemma empty_ssubset_singleton : (β
: set Ξ±) β {a} := (singleton_nonempty _).empty_ssubset
@[simp] theorem singleton_subset_iff {a : Ξ±} {s : set Ξ±} : {a} β s β a β s := forall_eq
lemma singleton_subset_singleton : ({a} : set Ξ±) β {b} β a = b := by simp
theorem set_compr_eq_eq_singleton {a : Ξ±} : {b | b = a} = {a} := rfl
@[simp] theorem singleton_union : {a} βͺ s = insert a s := rfl
@[simp] theorem union_singleton : s βͺ {a} = insert a s := union_comm _ _
@[simp] theorem singleton_inter_nonempty : ({a} β© s).nonempty β a β s :=
by simp only [set.nonempty, mem_inter_iff, mem_singleton_iff, exists_eq_left]
@[simp] theorem inter_singleton_nonempty : (s β© {a}).nonempty β a β s :=
by rw [inter_comm, singleton_inter_nonempty]
@[simp] theorem singleton_inter_eq_empty : {a} β© s = β
β a β s :=
not_nonempty_iff_eq_empty.symm.trans singleton_inter_nonempty.not
@[simp] theorem inter_singleton_eq_empty : s β© {a} = β
β a β s :=
by rw [inter_comm, singleton_inter_eq_empty]
lemma nmem_singleton_empty {s : set Ξ±} : s β ({β
} : set (set Ξ±)) β s.nonempty :=
nonempty_iff_ne_empty.symm
instance unique_singleton (a : Ξ±) : unique β₯({a} : set Ξ±) :=
β¨β¨β¨a, mem_singleton aβ©β©, Ξ» β¨x, hβ©, subtype.eq hβ©
lemma eq_singleton_iff_unique_mem : s = {a} β a β s β§ β x β s, x = a :=
subset.antisymm_iff.trans $ and.comm.trans $ and_congr_left' singleton_subset_iff
lemma eq_singleton_iff_nonempty_unique_mem : s = {a} β s.nonempty β§ β x β s, x = a :=
eq_singleton_iff_unique_mem.trans $ and_congr_left $ Ξ» H, β¨Ξ» h', β¨_, h'β©, Ξ» β¨x, hβ©, H x h βΈ hβ©
-- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS.
@[simp] lemma default_coe_singleton (x : Ξ±) : (default : ({x} : set Ξ±)) = β¨x, rflβ© := rfl
/-! ### Lemmas about pairs -/
@[simp] theorem pair_eq_singleton (a : Ξ±) : ({a, a} : set Ξ±) = {a} := union_self _
theorem pair_comm (a b : Ξ±) : ({a, b} : set Ξ±) = {b, a} := union_comm _ _
lemma pair_eq_pair_iff {x y z w : Ξ±} :
({x, y} : set Ξ±) = {z, w} β x = z β§ y = w β¨ x = w β§ y = z :=
begin
simp only [set.subset.antisymm_iff, set.insert_subset, set.mem_insert_iff, set.mem_singleton_iff,
set.singleton_subset_iff],
split,
{ tauto! },
{ rintro (β¨rfl,rflβ©|β¨rfl,rflβ©); simp }
end
/-! ### Lemmas about sets defined as `{x β s | p x}`. -/
section sep
variables {p q : Ξ± β Prop} {x : Ξ±}
theorem mem_sep (xs : x β s) (px : p x) : x β {x β s | p x} := β¨xs, pxβ©
@[simp] theorem sep_mem_eq : {x β s | x β t} = s β© t := rfl
@[simp] theorem mem_sep_iff : x β {x β s | p x} β x β s β§ p x := iff.rfl
theorem sep_ext_iff : {x β s | p x} = {x β s | q x} β β x β s, (p x β q x) :=
by simp_rw [ext_iff, mem_sep_iff, and.congr_right_iff]
theorem sep_eq_of_subset (h : s β t) : {x β t | x β s} = s :=
inter_eq_self_of_subset_right h
@[simp] theorem sep_subset (s : set Ξ±) (p : Ξ± β Prop) : {x β s | p x} β s := Ξ» x, and.left
@[simp] lemma sep_eq_self_iff_mem_true : {x β s | p x} = s β β x β s, p x :=
by simp_rw [ext_iff, mem_sep_iff, and_iff_left_iff_imp]
@[simp] lemma sep_eq_empty_iff_mem_false : {x β s | p x} = β
β β x β s, Β¬ p x :=
by simp_rw [ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false, not_and]
@[simp] lemma sep_true : {x β s | true} = s := inter_univ s
@[simp] lemma sep_false : {x β s | false} = β
:= inter_empty s
@[simp] lemma sep_empty (p : Ξ± β Prop) : {x β (β
: set Ξ±) | p x} = β
:= empty_inter p
@[simp] lemma sep_univ : {x β (univ : set Ξ±) | p x} = {x | p x} := univ_inter p
@[simp] lemma sep_union : {x β s βͺ t | p x} = {x β s | p x} βͺ {x β t | p x} :=
union_inter_distrib_right
@[simp] lemma sep_inter : {x β s β© t | p x} = {x β s | p x} β© {x β t | p x} :=
inter_inter_distrib_right s t p
@[simp] lemma sep_and : {x β s | p x β§ q x} = {x β s | p x} β© {x β s | q x} :=
inter_inter_distrib_left s p q
@[simp] lemma sep_or : {x β s | p x β¨ q x} = {x β s | p x} βͺ {x β s | q x} :=
inter_union_distrib_left
@[simp] lemma sep_set_of : {x β {y | p y} | q x} = {x | p x β§ q x} := rfl
end sep
@[simp] lemma subset_singleton_iff {Ξ± : Type*} {s : set Ξ±} {x : Ξ±} : s β {x} β β y β s, y = x :=
iff.rfl
lemma subset_singleton_iff_eq {s : set Ξ±} {x : Ξ±} : s β {x} β s = β
β¨ s = {x} :=
begin
obtain (rfl | hs) := s.eq_empty_or_nonempty,
use β¨Ξ» _, or.inl rfl, Ξ» _, empty_subset _β©,
simp [eq_singleton_iff_nonempty_unique_mem, hs, hs.ne_empty],
end
lemma nonempty.subset_singleton_iff (h : s.nonempty) : s β {a} β s = {a} :=
subset_singleton_iff_eq.trans $ or_iff_right h.ne_empty
lemma ssubset_singleton_iff {s : set Ξ±} {x : Ξ±} : s β {x} β s = β
:=
begin
rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_distrib_right, and_not_self, or_false,
and_iff_left_iff_imp],
exact Ξ» h, ne_of_eq_of_ne h (singleton_ne_empty _).symm,
end
lemma eq_empty_of_ssubset_singleton {s : set Ξ±} {x : Ξ±} (hs : s β {x}) : s = β
:=
ssubset_singleton_iff.1 hs
/-! ### Disjointness -/
protected theorem disjoint_iff : disjoint s t β s β© t β β
:= disjoint_iff_inf_le
theorem disjoint_iff_inter_eq_empty : disjoint s t β s β© t = β
:=
disjoint_iff
lemma _root_.disjoint.inter_eq : disjoint s t β s β© t = β
:= disjoint.eq_bot
lemma disjoint_left : disjoint s t β β β¦aβ¦, a β s β a β t :=
disjoint_iff_inf_le.trans $ forall_congr $ Ξ» _, not_and
lemma disjoint_right : disjoint s t β β β¦aβ¦, a β t β a β s := by rw [disjoint.comm, disjoint_left]
lemma not_disjoint_iff : Β¬disjoint s t β β x, x β s β§ x β t :=
set.disjoint_iff.not.trans $ not_forall.trans $ exists_congr $ Ξ» x, not_not
lemma not_disjoint_iff_nonempty_inter : Β¬disjoint s t β (s β© t).nonempty := not_disjoint_iff
alias not_disjoint_iff_nonempty_inter β _ nonempty.not_disjoint
lemma disjoint_or_nonempty_inter (s t : set Ξ±) : disjoint s t β¨ (s β© t).nonempty :=
(em _).imp_right not_disjoint_iff_nonempty_inter.mp
lemma disjoint_iff_forall_ne : disjoint s t β β (x β s) (y β t), x β y :=
by simp only [ne.def, disjoint_left, @imp_not_comm _ (_ = _), forall_eq']
lemma _root_.disjoint.ne_of_mem (h : disjoint s t) {x y} (hx : x β s) (hy : y β t) : x β y :=
disjoint_iff_forall_ne.mp h x hx y hy
lemma disjoint_of_subset_left (hs : sβ β sβ) (h : disjoint sβ t) : disjoint sβ t := h.mono_left hs
lemma disjoint_of_subset_right (ht : tβ β tβ) (h : disjoint s tβ) : disjoint s tβ := h.mono_right ht
lemma disjoint_of_subset (hs : sβ β sβ) (ht : tβ β tβ) (h : disjoint sβ tβ) : disjoint sβ tβ :=
h.mono hs ht
@[simp] lemma disjoint_union_left : disjoint (s βͺ t) u β disjoint s u β§ disjoint t u :=
disjoint_sup_left
@[simp] lemma disjoint_union_right : disjoint s (t βͺ u) β disjoint s t β§ disjoint s u :=
disjoint_sup_right
@[simp] lemma disjoint_empty (s : set Ξ±) : disjoint s β
:= disjoint_bot_right
@[simp] lemma empty_disjoint (s : set Ξ±) : disjoint β
s := disjoint_bot_left
@[simp] lemma univ_disjoint : disjoint univ s β s = β
:= top_disjoint
@[simp] lemma disjoint_univ : disjoint s univ β s = β
:= disjoint_top
lemma disjoint_sdiff_left : disjoint (t \ s) s := disjoint_sdiff_self_left
lemma disjoint_sdiff_right : disjoint s (t \ s) := disjoint_sdiff_self_right
lemma diff_union_diff_cancel (hts : t β s) (hut : u β t) : s \ t βͺ t \ u = s \ u :=
sdiff_sup_sdiff_cancel hts hut
lemma diff_diff_eq_sdiff_union (h : u β s) : s \ (t \ u) = s \ t βͺ u := sdiff_sdiff_eq_sdiff_sup h
@[simp] lemma disjoint_singleton_left : disjoint {a} s β a β s :=
by simp [set.disjoint_iff, subset_def]; exact iff.rfl
@[simp] lemma disjoint_singleton_right : disjoint s {a} β a β s :=
disjoint.comm.trans disjoint_singleton_left
@[simp] lemma disjoint_singleton : disjoint ({a} : set Ξ±) {b} β a β b :=
by rw [disjoint_singleton_left, mem_singleton_iff]
lemma subset_diff : s β t \ u β s β t β§ disjoint s u := le_iff_subset.symm.trans le_sdiff
lemma inter_diff_distrib_left (s t u : set Ξ±) : s β© (t \ u) = (s β© t) \ (s β© u) :=
inf_sdiff_distrib_left _ _ _
lemma inter_diff_distrib_right (s t u : set Ξ±) : s \ t β© u = (s β© u) \ (t β© u) :=
inf_sdiff_distrib_right _ _ _
/-! ### Lemmas about complement -/
lemma compl_def (s : set Ξ±) : sαΆ = {x | x β s} := rfl
theorem mem_compl {s : set Ξ±} {x : Ξ±} (h : x β s) : x β sαΆ := h
lemma compl_set_of {Ξ±} (p : Ξ± β Prop) : {a | p a}αΆ = { a | Β¬ p a } := rfl
theorem not_mem_of_mem_compl {s : set Ξ±} {x : Ξ±} (h : x β sαΆ) : x β s := h
@[simp] theorem mem_compl_iff (s : set Ξ±) (x : Ξ±) : x β sαΆ β (x β s) := iff.rfl
lemma not_mem_compl_iff {x : Ξ±} : x β sαΆ β x β s := not_not
@[simp] theorem inter_compl_self (s : set Ξ±) : s β© sαΆ = β
:= inf_compl_eq_bot
@[simp] theorem compl_inter_self (s : set Ξ±) : sαΆ β© s = β
:= compl_inf_eq_bot
@[simp] theorem compl_empty : (β
: set Ξ±)αΆ = univ := compl_bot
@[simp] theorem compl_union (s t : set Ξ±) : (s βͺ t)αΆ = sαΆ β© tαΆ := compl_sup
theorem compl_inter (s t : set Ξ±) : (s β© t)αΆ = sαΆ βͺ tαΆ := compl_inf
@[simp] theorem compl_univ : (univ : set Ξ±)αΆ = β
:= compl_top
@[simp] lemma compl_empty_iff {s : set Ξ±} : sαΆ = β
β s = univ := compl_eq_bot
@[simp] lemma compl_univ_iff {s : set Ξ±} : sαΆ = univ β s = β
:= compl_eq_top
lemma compl_ne_univ : sαΆ β univ β s.nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm
lemma nonempty_compl : sαΆ.nonempty β s β univ := (ne_univ_iff_exists_not_mem s).symm
lemma mem_compl_singleton_iff {a x : Ξ±} : x β ({a} : set Ξ±)αΆ β x β a := iff.rfl
lemma compl_singleton_eq (a : Ξ±) : ({a} : set Ξ±)αΆ = {x | x β a} := rfl
@[simp] lemma compl_ne_eq_singleton (a : Ξ±) : ({x | x β a} : set Ξ±)αΆ = {a} := compl_compl _
theorem union_eq_compl_compl_inter_compl (s t : set Ξ±) : s βͺ t = (sαΆ β© tαΆ)αΆ :=
ext $ Ξ» x, or_iff_not_and_not
theorem inter_eq_compl_compl_union_compl (s t : set Ξ±) : s β© t = (sαΆ βͺ tαΆ)αΆ :=
ext $ Ξ» x, and_iff_not_or_not
@[simp] theorem union_compl_self (s : set Ξ±) : s βͺ sαΆ = univ := eq_univ_iff_forall.2 $ Ξ» x, em _
@[simp] theorem compl_union_self (s : set Ξ±) : sαΆ βͺ s = univ := by rw [union_comm, union_compl_self]
lemma compl_subset_comm : sαΆ β t β tαΆ β s := @compl_le_iff_compl_le _ s _ _
lemma subset_compl_comm : s β tαΆ β t β sαΆ := @le_compl_iff_le_compl _ _ _ t
@[simp] lemma compl_subset_compl : sαΆ β tαΆ β t β s := @compl_le_compl_iff_le (set Ξ±) _ _ _
lemma subset_compl_iff_disjoint_left : s β tαΆ β disjoint t s :=
@le_compl_iff_disjoint_left (set Ξ±) _ _ _
lemma subset_compl_iff_disjoint_right : s β tαΆ β disjoint s t :=
@le_compl_iff_disjoint_right (set Ξ±) _ _ _
lemma disjoint_compl_left_iff_subset : disjoint sαΆ t β t β s := disjoint_compl_left_iff
lemma disjoint_compl_right_iff_subset : disjoint s tαΆ β s β t := disjoint_compl_right_iff
alias subset_compl_iff_disjoint_right β _ _root_.disjoint.subset_compl_right
alias subset_compl_iff_disjoint_left β _ _root_.disjoint.subset_compl_left
alias disjoint_compl_left_iff_subset β _ _root_.has_subset.subset.disjoint_compl_left
alias disjoint_compl_right_iff_subset β _ _root_.has_subset.subset.disjoint_compl_right
theorem subset_union_compl_iff_inter_subset {s t u : set Ξ±} : s β t βͺ uαΆ β s β© u β t :=
(@is_compl_compl _ u _).le_sup_right_iff_inf_left_le
theorem compl_subset_iff_union {s t : set Ξ±} : sαΆ β t β s βͺ t = univ :=
iff.symm $ eq_univ_iff_forall.trans $ forall_congr $ Ξ» a, or_iff_not_imp_left
@[simp] lemma subset_compl_singleton_iff {a : Ξ±} {s : set Ξ±} : s β {a}αΆ β a β s :=
subset_compl_comm.trans singleton_subset_iff
theorem inter_subset (a b c : set Ξ±) : a β© b β c β a β bαΆ βͺ c :=
forall_congr $ Ξ» x, and_imp.trans $ imp_congr_right $ Ξ» _, imp_iff_not_or
lemma inter_compl_nonempty_iff {s t : set Ξ±} : (s β© tαΆ).nonempty β Β¬ s β t :=
(not_subset.trans $ exists_congr $ by exact Ξ» x, by simp [mem_compl]).symm
/-! ### Lemmas about set difference -/
theorem diff_eq (s t : set Ξ±) : s \ t = s β© tαΆ := rfl
@[simp] theorem mem_diff {s t : set Ξ±} (x : Ξ±) : x β s \ t β x β s β§ x β t := iff.rfl
theorem mem_diff_of_mem {s t : set Ξ±} {x : Ξ±} (h1 : x β s) (h2 : x β t) : x β s \ t :=
β¨h1, h2β©
lemma not_mem_diff_of_mem {s t : set Ξ±} {x : Ξ±} (hx : x β t) : x β s \ t :=
Ξ» h, h.2 hx
theorem mem_of_mem_diff {s t : set Ξ±} {x : Ξ±} (h : x β s \ t) : x β s :=
h.left
theorem not_mem_of_mem_diff {s t : set Ξ±} {x : Ξ±} (h : x β s \ t) : x β t :=
h.right
theorem diff_eq_compl_inter {s t : set Ξ±} : s \ t = tαΆ β© s :=
by rw [diff_eq, inter_comm]
theorem nonempty_diff {s t : set Ξ±} : (s \ t).nonempty β Β¬ (s β t) := inter_compl_nonempty_iff
theorem diff_subset (s t : set Ξ±) : s \ t β s := show s \ t β€ s, from sdiff_le
theorem union_diff_cancel' {s t u : set Ξ±} (hβ : s β t) (hβ : t β u) : t βͺ (u \ s) = u :=
sup_sdiff_cancel' hβ hβ
theorem union_diff_cancel {s t : set Ξ±} (h : s β t) : s βͺ (t \ s) = t :=
sup_sdiff_cancel_right h
theorem union_diff_cancel_left {s t : set Ξ±} (h : s β© t β β
) : (s βͺ t) \ s = t :=
disjoint.sup_sdiff_cancel_left $ disjoint_iff_inf_le.2 h
theorem union_diff_cancel_right {s t : set Ξ±} (h : s β© t β β
) : (s βͺ t) \ t = s :=
disjoint.sup_sdiff_cancel_right $ disjoint_iff_inf_le.2 h
@[simp] theorem union_diff_left {s t : set Ξ±} : (s βͺ t) \ s = t \ s :=
sup_sdiff_left_self
@[simp] theorem union_diff_right {s t : set Ξ±} : (s βͺ t) \ t = s \ t :=
sup_sdiff_right_self
theorem union_diff_distrib {s t u : set Ξ±} : (s βͺ t) \ u = s \ u βͺ t \ u :=
sup_sdiff
theorem inter_diff_assoc (a b c : set Ξ±) : (a β© b) \ c = a β© (b \ c) :=
inf_sdiff_assoc
@[simp] theorem inter_diff_self (a b : set Ξ±) : a β© (b \ a) = β
:=
inf_sdiff_self_right
@[simp] theorem inter_union_diff (s t : set Ξ±) : (s β© t) βͺ (s \ t) = s :=
sup_inf_sdiff s t
@[simp] lemma diff_union_inter (s t : set Ξ±) : (s \ t) βͺ (s β© t) = s :=
by { rw union_comm, exact sup_inf_sdiff _ _ }
@[simp] theorem inter_union_compl (s t : set Ξ±) : (s β© t) βͺ (s β© tαΆ) = s := inter_union_diff _ _
theorem diff_subset_diff {sβ sβ tβ tβ : set Ξ±} : sβ β sβ β tβ β tβ β sβ \ tβ β sβ \ tβ :=
show sβ β€ sβ β tβ β€ tβ β sβ \ tβ β€ sβ \ tβ, from sdiff_le_sdiff
theorem diff_subset_diff_left {sβ sβ t : set Ξ±} (h : sβ β sβ) : sβ \ t β sβ \ t :=
sdiff_le_sdiff_right βΉsβ β€ sββΊ
theorem diff_subset_diff_right {s t u : set Ξ±} (h : t β u) : s \ u β s \ t :=
sdiff_le_sdiff_left βΉt β€ uβΊ
theorem compl_eq_univ_diff (s : set Ξ±) : sαΆ = univ \ s :=
top_sdiff.symm
@[simp] lemma empty_diff (s : set Ξ±) : (β
\ s : set Ξ±) = β
:=
bot_sdiff
theorem diff_eq_empty {s t : set Ξ±} : s \ t = β
β s β t :=
sdiff_eq_bot_iff
@[simp] theorem diff_empty {s : set Ξ±} : s \ β
= s :=
sdiff_bot
@[simp] lemma diff_univ (s : set Ξ±) : s \ univ = β
:= diff_eq_empty.2 (subset_univ s)
theorem diff_diff {u : set Ξ±} : s \ t \ u = s \ (t βͺ u) :=
sdiff_sdiff_left
-- the following statement contains parentheses to help the reader
lemma diff_diff_comm {s t u : set Ξ±} : (s \ t) \ u = (s \ u) \ t :=
sdiff_sdiff_comm
lemma diff_subset_iff {s t u : set Ξ±} : s \ t β u β s β t βͺ u :=
show s \ t β€ u β s β€ t βͺ u, from sdiff_le_iff
lemma subset_diff_union (s t : set Ξ±) : s β (s \ t) βͺ t :=
show s β€ (s \ t) βͺ t, from le_sdiff_sup
lemma diff_union_of_subset {s t : set Ξ±} (h : t β s) :
(s \ t) βͺ t = s :=
subset.antisymm (union_subset (diff_subset _ _) h) (subset_diff_union _ _)
@[simp] lemma diff_singleton_subset_iff {x : Ξ±} {s t : set Ξ±} : s \ {x} β t β s β insert x t :=
by { rw [βunion_singleton, union_comm], apply diff_subset_iff }
lemma subset_diff_singleton {x : Ξ±} {s t : set Ξ±} (h : s β t) (hx : x β s) : s β t \ {x} :=
subset_inter h $ subset_compl_comm.1 $ singleton_subset_iff.2 hx
lemma subset_insert_diff_singleton (x : Ξ±) (s : set Ξ±) : s β insert x (s \ {x}) :=
by rw [βdiff_singleton_subset_iff]
lemma diff_subset_comm {s t u : set Ξ±} : s \ t β u β s \ u β t :=
show s \ t β€ u β s \ u β€ t, from sdiff_le_comm
lemma diff_inter {s t u : set Ξ±} : s \ (t β© u) = (s \ t) βͺ (s \ u) :=
sdiff_inf
lemma diff_inter_diff {s t u : set Ξ±} : s \ t β© (s \ u) = s \ (t βͺ u) :=
sdiff_sup.symm
lemma diff_compl : s \ tαΆ = s β© t := sdiff_compl
lemma diff_diff_right {s t u : set Ξ±} : s \ (t \ u) = (s \ t) βͺ (s β© u) :=
sdiff_sdiff_right'
@[simp] theorem insert_diff_of_mem (s) (h : a β t) : insert a s \ t = s \ t :=
by { ext, split; simp [or_imp_distrib, h] {contextual := tt} }
theorem insert_diff_of_not_mem (s) (h : a β t) : insert a s \ t = insert a (s \ t) :=
begin
classical,
ext x,
by_cases h' : x β t,
{ have : x β a,
{ assume H,
rw H at h',
exact h h' },
simp [h, h', this] },
{ simp [h, h'] }
end
lemma insert_diff_self_of_not_mem {a : Ξ±} {s : set Ξ±} (h : a β s) :
insert a s \ {a} = s :=
by { ext, simp [and_iff_left_of_imp (Ξ» hx : x β s, show x β a, from Ξ» hxa, h $ hxa βΈ hx)] }
@[simp] lemma insert_diff_eq_singleton {a : Ξ±} {s : set Ξ±} (h : a β s) :
insert a s \ s = {a} :=
begin
ext,
rw [set.mem_diff, set.mem_insert_iff, set.mem_singleton_iff, or_and_distrib_right,
and_not_self, or_false, and_iff_left_iff_imp],
rintro rfl,
exact h,
end
lemma inter_insert_of_mem (h : a β s) : s β© insert a t = insert a (s β© t) :=
by rw [insert_inter_distrib, insert_eq_of_mem h]
lemma insert_inter_of_mem (h : a β t) : insert a s β© t = insert a (s β© t) :=
by rw [insert_inter_distrib, insert_eq_of_mem h]
lemma inter_insert_of_not_mem (h : a β s) : s β© insert a t = s β© t :=
ext $ Ξ» x, and_congr_right $ Ξ» hx, or_iff_right $ ne_of_mem_of_not_mem hx h
lemma insert_inter_of_not_mem (h : a β t) : insert a s β© t = s β© t :=
ext $ Ξ» x, and_congr_left $ Ξ» hx, or_iff_right $ ne_of_mem_of_not_mem hx h
@[simp] lemma union_diff_self {s t : set Ξ±} : s βͺ (t \ s) = s βͺ t := sup_sdiff_self _ _
@[simp] lemma diff_union_self {s t : set Ξ±} : (s \ t) βͺ t = s βͺ t := sdiff_sup_self _ _
@[simp] theorem diff_inter_self {a b : set Ξ±} : (b \ a) β© a = β
:=
inf_sdiff_self_left
@[simp] theorem diff_inter_self_eq_diff {s t : set Ξ±} : s \ (t β© s) = s \ t :=
sdiff_inf_self_right _ _
@[simp] theorem diff_self_inter {s t : set Ξ±} : s \ (s β© t) = s \ t := sdiff_inf_self_left _ _
@[simp] theorem diff_singleton_eq_self {a : Ξ±} {s : set Ξ±} (h : a β s) : s \ {a} = s :=
sdiff_eq_self_iff_disjoint.2 $ by simp [h]
@[simp] lemma diff_singleton_ssubset {s : set Ξ±} {a : Ξ±} : s \ {a} β s β a β s :=
sdiff_le.lt_iff_ne.trans $ sdiff_eq_left.not.trans $ by simp
@[simp] theorem insert_diff_singleton {a : Ξ±} {s : set Ξ±} :
insert a (s \ {a}) = insert a s :=
by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union]
lemma insert_diff_singleton_comm (hab : a β b) (s : set Ξ±) :
insert a (s \ {b}) = insert a s \ {b} :=
by simp_rw [βunion_singleton, union_diff_distrib,
diff_singleton_eq_self (mem_singleton_iff.not.2 hab.symm)]
@[simp] lemma diff_self {s : set Ξ±} : s \ s = β
:= sdiff_self
lemma diff_diff_right_self (s t : set Ξ±) : s \ (s \ t) = s β© t := sdiff_sdiff_right_self
lemma diff_diff_cancel_left {s t : set Ξ±} (h : s β t) : t \ (t \ s) = s :=
sdiff_sdiff_eq_self h
lemma mem_diff_singleton {x y : Ξ±} {s : set Ξ±} : x β s \ {y} β (x β s β§ x β y) :=
iff.rfl
lemma mem_diff_singleton_empty {t : set (set Ξ±)} : s β t \ {β
} β s β t β§ s.nonempty :=
mem_diff_singleton.trans $ and_congr_right' nonempty_iff_ne_empty.symm
lemma union_eq_diff_union_diff_union_inter (s t : set Ξ±) :
s βͺ t = (s \ t) βͺ (t \ s) βͺ (s β© t) :=
sup_eq_sdiff_sup_sdiff_sup_inf
/-! ### Symmetric difference -/
lemma mem_symm_diff : a β s β t β a β s β§ a β t β¨ a β t β§ a β s := iff.rfl
protected lemma symm_diff_def (s t : set Ξ±) : s β t = s \ t βͺ t \ s := rfl
lemma symm_diff_subset_union : s β t β s βͺ t := @symm_diff_le_sup (set Ξ±) _ _ _
@[simp] lemma symm_diff_eq_empty : s β t = β
β s = t := symm_diff_eq_bot
@[simp] lemma symm_diff_nonempty : (s β t).nonempty β s β t :=
nonempty_iff_ne_empty.trans symm_diff_eq_empty.not
lemma inter_symm_diff_distrib_left (s t u : set Ξ±) : s β© t β u = (s β© t) β (s β© u) :=
inf_symm_diff_distrib_left _ _ _
lemma inter_symm_diff_distrib_right (s t u : set Ξ±) : s β t β© u = (s β© u) β (t β© u) :=
inf_symm_diff_distrib_right _ _ _
lemma subset_symm_diff_union_symm_diff_left (h : disjoint s t) : u β s β u βͺ t β u :=
h.le_symm_diff_sup_symm_diff_left
lemma subset_symm_diff_union_symm_diff_right (h : disjoint t u) : s β s β t βͺ s β u :=
h.le_symm_diff_sup_symm_diff_right
/-! ### Powerset -/
/-- `π« s = set.powerset s` is the set of all subsets of `s`. -/
def powerset (s : set Ξ±) : set (set Ξ±) := {t | t β s}
prefix `π«`:100 := powerset
theorem mem_powerset {x s : set Ξ±} (h : x β s) : x β π« s := h
theorem subset_of_mem_powerset {x s : set Ξ±} (h : x β π« s) : x β s := h
@[simp] theorem mem_powerset_iff (x s : set Ξ±) : x β π« s β x β s := iff.rfl
theorem powerset_inter (s t : set Ξ±) : π« (s β© t) = π« s β© π« t :=
ext $ Ξ» u, subset_inter_iff
@[simp] theorem powerset_mono : π« s β π« t β s β t :=
β¨Ξ» h, h (subset.refl s), Ξ» h u hu, subset.trans hu hβ©
theorem monotone_powerset : monotone (powerset : set Ξ± β set (set Ξ±)) :=
Ξ» s t, powerset_mono.2
@[simp] theorem powerset_nonempty : (π« s).nonempty :=
β¨β
, empty_subset sβ©
@[simp] theorem powerset_empty : π« (β
: set Ξ±) = {β
} :=
ext $ Ξ» s, subset_empty_iff
@[simp] theorem powerset_univ : π« (univ : set Ξ±) = univ :=
eq_univ_of_forall subset_univ
/-- The powerset of a singleton contains only `β
` and the singleton itself. -/
theorem powerset_singleton (x : Ξ±) : π« ({x} : set Ξ±) = {β
, {x}} :=
by { ext y, rw [mem_powerset_iff, subset_singleton_iff_eq, mem_insert_iff, mem_singleton_iff] }
/-! ### Sets defined as an if-then-else -/
lemma mem_dite_univ_right (p : Prop) [decidable p] (t : p β set Ξ±) (x : Ξ±) :
(x β if h : p then t h else univ) β (β h : p, x β t h) :=
by split_ifs; simp [h]
@[simp] lemma mem_ite_univ_right (p : Prop) [decidable p] (t : set Ξ±) (x : Ξ±) :
x β ite p t set.univ β (p β x β t) :=
mem_dite_univ_right p (Ξ» _, t) x
lemma mem_dite_univ_left (p : Prop) [decidable p] (t : Β¬ p β set Ξ±) (x : Ξ±) :
(x β if h : p then univ else t h) β (β h : Β¬ p, x β t h) :=
by split_ifs; simp [h]
@[simp] lemma mem_ite_univ_left (p : Prop) [decidable p] (t : set Ξ±) (x : Ξ±) :
x β ite p set.univ t β (Β¬ p β x β t) :=
mem_dite_univ_left p (Ξ» _, t) x
lemma mem_dite_empty_right (p : Prop) [decidable p] (t : p β set Ξ±) (x : Ξ±) :
(x β if h : p then t h else β
) β (β h : p, x β t h) :=
by split_ifs; simp [h]
@[simp] lemma mem_ite_empty_right (p : Prop) [decidable p] (t : set Ξ±) (x : Ξ±) :
x β ite p t β
β p β§ x β t :=
by split_ifs; simp [h]
lemma mem_dite_empty_left (p : Prop) [decidable p] (t : Β¬ p β set Ξ±) (x : Ξ±) :
(x β if h : p then β
else t h) β (β h : Β¬ p, x β t h) :=
by split_ifs; simp [h]
@[simp] lemma mem_ite_empty_left (p : Prop) [decidable p] (t : set Ξ±) (x : Ξ±) :
x β ite p β
t β Β¬ p β§ x β t :=
by split_ifs; simp [h]
/-! ### If-then-else for sets -/
/-- `ite` for sets: `set.ite t s s' β© t = s β© t`, `set.ite t s s' β© tαΆ = s' β© tαΆ`.
Defined as `s β© t βͺ s' \ t`. -/
protected def ite (t s s' : set Ξ±) : set Ξ± := s β© t βͺ s' \ t
@[simp] lemma ite_inter_self (t s s' : set Ξ±) : t.ite s s' β© t = s β© t :=
by rw [set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty]
@[simp] lemma ite_compl (t s s' : set Ξ±) : tαΆ.ite s s' = t.ite s' s :=
by rw [set.ite, set.ite, diff_compl, union_comm, diff_eq]
@[simp] lemma ite_inter_compl_self (t s s' : set Ξ±) : t.ite s s' β© tαΆ = s' β© tαΆ :=
by rw [β ite_compl, ite_inter_self]
@[simp] lemma ite_diff_self (t s s' : set Ξ±) : t.ite s s' \ t = s' \ t :=
ite_inter_compl_self t s s'
@[simp] lemma ite_same (t s : set Ξ±) : t.ite s s = s := inter_union_diff _ _
@[simp] lemma ite_left (s t : set Ξ±) : s.ite s t = s βͺ t := by simp [set.ite]
@[simp] lemma ite_right (s t : set Ξ±) : s.ite t s = t β© s := by simp [set.ite]
@[simp] lemma ite_empty (s s' : set Ξ±) : set.ite β
s s' = s' :=
by simp [set.ite]
@[simp] lemma ite_univ (s s' : set Ξ±) : set.ite univ s s' = s :=
by simp [set.ite]
@[simp] lemma ite_empty_left (t s : set Ξ±) : t.ite β
s = s \ t :=
by simp [set.ite]
@[simp] lemma ite_empty_right (t s : set Ξ±) : t.ite s β
= s β© t :=
by simp [set.ite]
lemma ite_mono (t : set Ξ±) {sβ sβ' sβ sβ' : set Ξ±} (h : sβ β sβ) (h' : sβ' β sβ') :
t.ite sβ sβ' β t.ite sβ sβ' :=
union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')
lemma ite_subset_union (t s s' : set Ξ±) : t.ite s s' β s βͺ s' :=
union_subset_union (inter_subset_left _ _) (diff_subset _ _)
lemma inter_subset_ite (t s s' : set Ξ±) : s β© s' β t.ite s s' :=
ite_same t (s β© s') βΈ ite_mono _ (inter_subset_left _ _) (inter_subset_right _ _)
lemma ite_inter_inter (t sβ sβ sβ' sβ' : set Ξ±) :
t.ite (sβ β© sβ) (sβ' β© sβ') = t.ite sβ sβ' β© t.ite sβ sβ' :=
by { ext x, simp only [set.ite, set.mem_inter_iff, set.mem_diff, set.mem_union], itauto }
lemma ite_inter (t sβ sβ s : set Ξ±) :
t.ite (sβ β© s) (sβ β© s) = t.ite sβ sβ β© s :=
by rw [ite_inter_inter, ite_same]
lemma ite_inter_of_inter_eq (t : set Ξ±) {sβ sβ s : set Ξ±} (h : sβ β© s = sβ β© s) :
t.ite sβ sβ β© s = sβ β© s :=
by rw [β ite_inter, β h, ite_same]
lemma subset_ite {t s s' u : set Ξ±} : u β t.ite s s' β u β© t β s β§ u \ t β s' :=
begin
simp only [subset_def, β forall_and_distrib],
refine forall_congr (Ξ» x, _),
by_cases hx : x β t; simp [*, set.ite]
end
/-! ### Subsingleton -/
/-- A set `s` is a `subsingleton` if it has at most one element. -/
protected def subsingleton (s : set Ξ±) : Prop :=
β β¦xβ¦ (hx : x β s) β¦yβ¦ (hy : y β s), x = y
lemma subsingleton.anti (ht : t.subsingleton) (hst : s β t) : s.subsingleton :=
Ξ» x hx y hy, ht (hst hx) (hst hy)
lemma subsingleton.eq_singleton_of_mem (hs : s.subsingleton) {x:Ξ±} (hx : x β s) : s = {x} :=
ext $ Ξ» y, β¨Ξ» hy, (hs hx hy) βΈ mem_singleton _, Ξ» hy, (eq_of_mem_singleton hy).symm βΈ hxβ©
@[simp] lemma subsingleton_empty : (β
: set Ξ±).subsingleton := Ξ» x, false.elim
@[simp] lemma subsingleton_singleton {a} : ({a} : set Ξ±).subsingleton :=
Ξ» x hx y hy, (eq_of_mem_singleton hx).symm βΈ (eq_of_mem_singleton hy).symm βΈ rfl
lemma subsingleton_of_subset_singleton (h : s β {a}) : s.subsingleton :=
subsingleton_singleton.anti h
lemma subsingleton_of_forall_eq (a : Ξ±) (h : β b β s, b = a) : s.subsingleton :=
Ξ» b hb c hc, (h _ hb).trans (h _ hc).symm
lemma subsingleton_iff_singleton {x} (hx : x β s) : s.subsingleton β s = {x} :=
β¨Ξ» h, h.eq_singleton_of_mem hx, Ξ» h,h.symm βΈ subsingleton_singletonβ©
lemma subsingleton.eq_empty_or_singleton (hs : s.subsingleton) :
s = β
β¨ β x, s = {x} :=
s.eq_empty_or_nonempty.elim or.inl (Ξ» β¨x, hxβ©, or.inr β¨x, hs.eq_singleton_of_mem hxβ©)
lemma subsingleton.induction_on {p : set Ξ± β Prop} (hs : s.subsingleton) (he : p β
)
(hβ : β x, p {x}) : p s :=
by { rcases hs.eq_empty_or_singleton with rfl|β¨x, rflβ©, exacts [he, hβ _] }
lemma subsingleton_univ [subsingleton Ξ±] : (univ : set Ξ±).subsingleton :=
Ξ» x hx y hy, subsingleton.elim x y
lemma subsingleton_of_univ_subsingleton (h : (univ : set Ξ±).subsingleton) : subsingleton Ξ± :=
β¨Ξ» a b, h (mem_univ a) (mem_univ b)β©
@[simp] lemma subsingleton_univ_iff : (univ : set Ξ±).subsingleton β subsingleton Ξ± :=
β¨subsingleton_of_univ_subsingleton, Ξ» h, @subsingleton_univ _ hβ©
lemma subsingleton_of_subsingleton [subsingleton Ξ±] {s : set Ξ±} : set.subsingleton s :=
subsingleton_univ.anti (subset_univ s)
lemma subsingleton_is_top (Ξ± : Type*) [partial_order Ξ±] : set.subsingleton {x : Ξ± | is_top x} :=
Ξ» x hx y hy, hx.is_max.eq_of_le (hy x)
lemma subsingleton_is_bot (Ξ± : Type*) [partial_order Ξ±] : set.subsingleton {x : Ξ± | is_bot x} :=
Ξ» x hx y hy, hx.is_min.eq_of_ge (hy x)
lemma exists_eq_singleton_iff_nonempty_subsingleton :
(β a : Ξ±, s = {a}) β s.nonempty β§ s.subsingleton :=
begin
refine β¨_, Ξ» h, _β©,
{ rintros β¨a, rflβ©,
exact β¨singleton_nonempty a, subsingleton_singletonβ© },
{ exact h.2.eq_empty_or_singleton.resolve_left h.1.ne_empty },
end
/-- `s`, coerced to a type, is a subsingleton type if and only if `s` is a subsingleton set. -/
@[simp, norm_cast] lemma subsingleton_coe (s : set Ξ±) : subsingleton s β s.subsingleton :=
begin
split,
{ refine Ξ» h, (Ξ» a ha b hb, _),
exact set_coe.ext_iff.2 (@subsingleton.elim s h β¨a, haβ© β¨b, hbβ©) },
{ exact Ξ» h, subsingleton.intro (Ξ» a b, set_coe.ext (h a.property b.property)) }
end
lemma subsingleton.coe_sort {s : set Ξ±} : s.subsingleton β subsingleton s := s.subsingleton_coe.2
/-- The `coe_sort` of a set `s` in a subsingleton type is a subsingleton.
For the corresponding result for `subtype`, see `subtype.subsingleton`. -/
instance subsingleton_coe_of_subsingleton [subsingleton Ξ±] {s : set Ξ±} : subsingleton s :=
by { rw [s.subsingleton_coe], exact subsingleton_of_subsingleton }
/-! ### Nontrivial -/
/-- A set `s` is `nontrivial` if it has at least two distinct elements. -/
protected def nontrivial (s : set Ξ±) : Prop := β x y β s, x β y
lemma nontrivial_of_mem_mem_ne {x y} (hx : x β s) (hy : y β s) (hxy : x β y) : s.nontrivial :=
β¨x, hx, y, hy, hxyβ©
/-- Extract witnesses from s.nontrivial. This function might be used instead of case analysis on the
argument. Note that it makes a proof depend on the classical.choice axiom. -/
protected noncomputable def nontrivial.some (hs : s.nontrivial) : Ξ± Γ Ξ± :=
(hs.some, hs.some_spec.some_spec.some)
protected lemma nontrivial.some_fst_mem (hs : s.nontrivial) : hs.some.fst β s := hs.some_spec.some
protected lemma nontrivial.some_snd_mem (hs : s.nontrivial) : hs.some.snd β s :=
hs.some_spec.some_spec.some_spec.some
protected lemma nontrivial.some_fst_ne_some_snd (hs : s.nontrivial) : hs.some.fst β hs.some.snd :=
hs.some_spec.some_spec.some_spec.some_spec
lemma nontrivial.mono (hs : s.nontrivial) (hst : s β t) : t.nontrivial :=
let β¨x, hx, y, hy, hxyβ© := hs in β¨x, hst hx, y, hst hy, hxyβ©
lemma nontrivial_pair {x y} (hxy : x β y) : ({x, y} : set Ξ±).nontrivial :=
β¨x, mem_insert _ _, y, mem_insert_of_mem _ (mem_singleton _), hxyβ©
lemma nontrivial_of_pair_subset {x y} (hxy : x β y) (h : {x, y} β s) : s.nontrivial :=
(nontrivial_pair hxy).mono h
lemma nontrivial.pair_subset (hs : s.nontrivial) : β x y (hab : x β y), {x, y} β s :=
let β¨x, hx, y, hy, hxyβ© := hs in β¨x, y, hxy, insert_subset.2 β¨hx, (singleton_subset_iff.2 hy)β©β©
lemma nontrivial_iff_pair_subset : s.nontrivial β β x y (hxy : x β y), {x, y} β s :=
β¨nontrivial.pair_subset, Ξ» H, let β¨x, y, hxy, hβ© := H in nontrivial_of_pair_subset hxy hβ©
lemma nontrivial_of_exists_ne {x} (hx : x β s) (h : β y β s, y β x) : s.nontrivial :=
let β¨y, hy, hyxβ© := h in β¨y, hy, x, hx, hyxβ©
lemma nontrivial.exists_ne (hs : s.nontrivial) (z) : β x β s, x β z :=
begin
by_contra H, push_neg at H,
rcases hs with β¨x, hx, y, hy, hxyβ©,
rw [H x hx, H y hy] at hxy,
exact hxy rfl
end
lemma nontrivial_iff_exists_ne {x} (hx : x β s) : s.nontrivial β β y β s, y β x :=
β¨Ξ» H, H.exists_ne _, nontrivial_of_exists_ne hxβ©
lemma nontrivial_of_lt [preorder Ξ±] {x y} (hx : x β s) (hy : y β s) (hxy : x < y) : s.nontrivial :=
β¨x, hx, y, hy, ne_of_lt hxyβ©
lemma nontrivial_of_exists_lt [preorder Ξ±] (H : β x y β s, x < y) : s.nontrivial :=
let β¨x, hx, y, hy, hxyβ© := H in nontrivial_of_lt hx hy hxy
lemma nontrivial.exists_lt [linear_order Ξ±] (hs : s.nontrivial) : β x y β s, x < y :=
let β¨x, hx, y, hy, hxyβ© := hs in
or.elim (lt_or_gt_of_ne hxy) (Ξ» H, β¨x, hx, y, hy, Hβ©) (Ξ» H, β¨y, hy, x, hx, Hβ©)
lemma nontrivial_iff_exists_lt [linear_order Ξ±] : s.nontrivial β β x y β s, x < y :=
β¨nontrivial.exists_lt, nontrivial_of_exists_ltβ©
protected lemma nontrivial.nonempty (hs : s.nontrivial) : s.nonempty :=
let β¨x, hx, _β© := hs in β¨x, hxβ©
protected lemma nontrivial.ne_empty (hs : s.nontrivial) : s β β
:= hs.nonempty.ne_empty
lemma nontrivial.not_subset_empty (hs : s.nontrivial) : Β¬ s β β
:= hs.nonempty.not_subset_empty
@[simp] lemma not_nontrivial_empty : Β¬ (β
: set Ξ±).nontrivial := Ξ» h, h.ne_empty rfl
@[simp] lemma not_nontrivial_singleton {x} : Β¬ ({x} : set Ξ±).nontrivial :=
Ξ» H, begin
rw nontrivial_iff_exists_ne (mem_singleton x) at H,
exact let β¨y, hy, hyaβ© := H in hya (mem_singleton_iff.1 hy)
end
lemma nontrivial.ne_singleton {x} (hs : s.nontrivial) : s β {x} :=
Ξ» H, by { rw H at hs, exact not_nontrivial_singleton hs }
lemma nontrivial.not_subset_singleton {x} (hs : s.nontrivial) : Β¬ s β {x} :=
(not_congr subset_singleton_iff_eq).2 (not_or hs.ne_empty hs.ne_singleton)
lemma nontrivial_univ [nontrivial Ξ±] : (univ : set Ξ±).nontrivial :=
let β¨x, y, hxyβ© := exists_pair_ne Ξ± in β¨x, mem_univ _, y, mem_univ _, hxyβ©
lemma nontrivial_of_univ_nontrivial (h : (univ : set Ξ±).nontrivial) : nontrivial Ξ± :=
let β¨x, _, y, _, hxyβ© := h in β¨β¨x, y, hxyβ©β©
@[simp] lemma nontrivial_univ_iff : (univ : set Ξ±).nontrivial β nontrivial Ξ± :=
β¨nontrivial_of_univ_nontrivial, Ξ» h, @nontrivial_univ _ hβ©
lemma nontrivial_of_nontrivial (hs : s.nontrivial) : nontrivial Ξ± :=
let β¨x, _, y, _, hxyβ© := hs in β¨β¨x, y, hxyβ©β©
/-- `s`, coerced to a type, is a nontrivial type if and only if `s` is a nontrivial set. -/
@[simp, norm_cast] lemma nontrivial_coe_sort {s : set Ξ±} : nontrivial s β s.nontrivial :=
by simp_rw [β nontrivial_univ_iff, set.nontrivial, mem_univ,
exists_true_left, set_coe.exists, subtype.mk_eq_mk]
alias nontrivial_coe_sort β _ nontrivial.coe_sort
/-- A type with a set `s` whose `coe_sort` is a nontrivial type is nontrivial.
For the corresponding result for `subtype`, see `subtype.nontrivial_iff_exists_ne`. -/
lemma nontrivial_of_nontrivial_coe (hs : nontrivial s) : nontrivial Ξ± :=
nontrivial_of_nontrivial $ nontrivial_coe_sort.1 hs
theorem nontrivial_mono {Ξ± : Type*} {s t : set Ξ±} (hst : s β t) (hs : nontrivial s) :
nontrivial t := nontrivial.coe_sort $ (nontrivial_coe_sort.1 hs).mono hst
@[simp] lemma not_subsingleton_iff : Β¬ s.subsingleton β s.nontrivial :=
by simp_rw [set.subsingleton, set.nontrivial, not_forall]
@[simp] lemma not_nontrivial_iff : Β¬ s.nontrivial β s.subsingleton :=
iff.not_left not_subsingleton_iff.symm
alias not_nontrivial_iff β _ subsingleton.not_nontrivial
alias not_subsingleton_iff β _ nontrivial.not_subsingleton
protected lemma subsingleton_or_nontrivial (s : set Ξ±) : s.subsingleton β¨ s.nontrivial :=
by simp [or_iff_not_imp_right]
lemma eq_singleton_or_nontrivial (ha : a β s) : s = {a} β¨ s.nontrivial :=
by { rw βsubsingleton_iff_singleton ha, exact s.subsingleton_or_nontrivial }
lemma nontrivial_iff_ne_singleton (ha : a β s) : s.nontrivial β s β {a} :=
β¨nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_leftβ©
lemma nonempty.exists_eq_singleton_or_nontrivial : s.nonempty β (β a, s = {a}) β¨ s.nontrivial :=
Ξ» β¨a, haβ©, (eq_singleton_or_nontrivial ha).imp_left $ exists.intro a
theorem univ_eq_true_false : univ = ({true, false} : set Prop) :=
eq.symm $ eq_univ_of_forall $ classical.cases (by simp) (by simp)
section preorder
variables [preorder Ξ±] [preorder Ξ²] {f : Ξ± β Ξ²}
lemma monotone_on_iff_monotone : monotone_on f s β monotone (Ξ» a : s, f a) :=
by simp [monotone, monotone_on]
lemma antitone_on_iff_antitone : antitone_on f s β antitone (Ξ» a : s, f a) :=
by simp [antitone, antitone_on]
lemma strict_mono_on_iff_strict_mono : strict_mono_on f s β strict_mono (Ξ» a : s, f a) :=
by simp [strict_mono, strict_mono_on]
lemma strict_anti_on_iff_strict_anti : strict_anti_on f s β strict_anti (Ξ» a : s, f a) :=
by simp [strict_anti, strict_anti_on]
variables (f)
/-! ### Monotonicity on singletons -/
protected lemma subsingleton.monotone_on (h : s.subsingleton) :
monotone_on f s :=
Ξ» a ha b hb _, (congr_arg _ (h ha hb)).le
protected lemma subsingleton.antitone_on (h : s.subsingleton) :
antitone_on f s :=
Ξ» a ha b hb _, (congr_arg _ (h hb ha)).le
protected lemma subsingleton.strict_mono_on (h : s.subsingleton) :
strict_mono_on f s :=
Ξ» a ha b hb hlt, (hlt.ne (h ha hb)).elim
protected lemma subsingleton.strict_anti_on (h : s.subsingleton) :
strict_anti_on f s :=
Ξ» a ha b hb hlt, (hlt.ne (h ha hb)).elim
@[simp] lemma monotone_on_singleton : monotone_on f {a} :=
subsingleton_singleton.monotone_on f
@[simp] lemma antitone_on_singleton : antitone_on f {a} :=
subsingleton_singleton.antitone_on f
@[simp] lemma strict_mono_on_singleton : strict_mono_on f {a} :=
subsingleton_singleton.strict_mono_on f
@[simp] lemma strict_anti_on_singleton : strict_anti_on f {a} :=
subsingleton_singleton.strict_anti_on f
end preorder
section linear_order
variables [linear_order Ξ±] [linear_order Ξ²] {f : Ξ± β Ξ²}
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_on_not_antitone_on_iff_exists_le_le :
Β¬ monotone_on f s β§ Β¬ antitone_on f s β β a b c β s, a β€ b β§ b β€ c β§
(f a < f b β§ f c < f b β¨ f b < f a β§ f b < f c) :=
by simp [monotone_on_iff_monotone, antitone_on_iff_antitone, and_assoc, exists_and_distrib_left,
not_monotone_not_antitone_iff_exists_le_le, @and.left_comm (_ β s)]
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_on_not_antitone_on_iff_exists_lt_lt :
Β¬ monotone_on f s β§ Β¬ antitone_on f s β β a b c β s, a < b β§ b < c β§
(f a < f b β§ f c < f b β¨ f b < f a β§ f b < f c) :=
by simp [monotone_on_iff_monotone, antitone_on_iff_antitone, and_assoc, exists_and_distrib_left,
not_monotone_not_antitone_iff_exists_lt_lt, @and.left_comm (_ β s)]
end linear_order
end set
open set
namespace function
variables {ΞΉ : Sort*} {Ξ± : Type*} {Ξ² : Type*} {f : Ξ± β Ξ²}
lemma injective.nonempty_apply_iff {f : set Ξ± β set Ξ²} (hf : injective f)
(h2 : f β
= β
) {s : set Ξ±} : (f s).nonempty β s.nonempty :=
by rw [nonempty_iff_ne_empty, β h2, nonempty_iff_ne_empty, hf.ne_iff]
end function
open function
namespace set
/-! ### Lemmas about `inclusion`, the injection of subtypes induced by `β` -/
section inclusion
variables {Ξ± : Type*} {s t u : set Ξ±}
/-- `inclusion` is the "identity" function between two subsets `s` and `t`, where `s β t` -/
def inclusion (h : s β t) : s β t :=
Ξ» x : s, (β¨x, h x.2β© : t)
@[simp] lemma inclusion_self (x : s) : inclusion subset.rfl x = x := by { cases x, refl }
lemma inclusion_eq_id (h : s β s) : inclusion h = id := funext inclusion_self
@[simp] lemma inclusion_mk {h : s β t} (a : Ξ±) (ha : a β s) : inclusion h β¨a, haβ© = β¨a, h haβ© := rfl
lemma inclusion_right (h : s β t) (x : t) (m : (x : Ξ±) β s) : inclusion h β¨x, mβ© = x :=
by { cases x, refl }
@[simp] lemma inclusion_inclusion (hst : s β t) (htu : t β u) (x : s) :
inclusion htu (inclusion hst x) = inclusion (hst.trans htu) x :=
by { cases x, refl }
@[simp] lemma inclusion_comp_inclusion {Ξ±} {s t u : set Ξ±} (hst : s β t) (htu : t β u) :
inclusion htu β inclusion hst = inclusion (hst.trans htu) :=
funext (inclusion_inclusion hst htu)
@[simp] lemma coe_inclusion (h : s β t) (x : s) : (inclusion h x : Ξ±) = (x : Ξ±) := rfl
lemma inclusion_injective (h : s β t) : injective (inclusion h)
| β¨_, _β© β¨_, _β© := subtype.ext_iff_val.2 β subtype.ext_iff_val.1
lemma eq_of_inclusion_surjective {s t : set Ξ±} {h : s β t}
(h_surj : function.surjective (inclusion h)) : s = t :=
begin
refine set.subset.antisymm h (Ξ» x hx, _),
obtain β¨y, hyβ© := h_surj β¨x, hxβ©,
exact mem_of_eq_of_mem (congr_arg coe hy).symm y.prop,
end
end inclusion
end set
namespace subsingleton
variables {Ξ± : Type*} [subsingleton Ξ±]
lemma eq_univ_of_nonempty {s : set Ξ±} : s.nonempty β s = univ :=
Ξ» β¨x, hxβ©, eq_univ_of_forall $ Ξ» y, subsingleton.elim x y βΈ hx
@[elab_as_eliminator]
lemma set_cases {p : set Ξ± β Prop} (h0 : p β
) (h1 : p univ) (s) : p s :=
s.eq_empty_or_nonempty.elim (Ξ» h, h.symm βΈ h0) $ Ξ» h, (eq_univ_of_nonempty h).symm βΈ h1
lemma mem_iff_nonempty {Ξ± : Type*} [subsingleton Ξ±] {s : set Ξ±} {x : Ξ±} :
x β s β s.nonempty :=
β¨Ξ» hx, β¨x, hxβ©, Ξ» β¨y, hyβ©, subsingleton.elim y x βΈ hyβ©
end subsingleton
/-! ### Decidability instances for sets -/
namespace set
variables {Ξ± : Type u} (s t : set Ξ±) (a : Ξ±)
instance decidable_sdiff [decidable (a β s)] [decidable (a β t)] : decidable (a β s \ t) :=
(by apply_instance : decidable (a β s β§ a β t))
instance decidable_inter [decidable (a β s)] [decidable (a β t)] : decidable (a β s β© t) :=
(by apply_instance : decidable (a β s β§ a β t))
instance decidable_union [decidable (a β s)] [decidable (a β t)] : decidable (a β s βͺ t) :=
(by apply_instance : decidable (a β s β¨ a β t))
instance decidable_compl [decidable (a β s)] : decidable (a β sαΆ) :=
(by apply_instance : decidable (a β s))
instance decidable_emptyset : decidable_pred (β (β
: set Ξ±)) :=
Ξ» _, decidable.is_false (by simp)
instance decidable_univ : decidable_pred (β (set.univ : set Ξ±)) :=
Ξ» _, decidable.is_true (by simp)
instance decidable_set_of (p : Ξ± β Prop) [decidable (p a)] : decidable (a β {a | p a}) :=
by assumption
end set
/-! ### Monotone lemmas for sets -/
section monotone
variables {Ξ± Ξ² : Type*}
theorem monotone.inter [preorder Ξ²] {f g : Ξ² β set Ξ±}
(hf : monotone f) (hg : monotone g) : monotone (Ξ» x, f x β© g x) :=
hf.inf hg
theorem monotone_on.inter [preorder Ξ²] {f g : Ξ² β set Ξ±} {s : set Ξ²}
(hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (Ξ» x, f x β© g x) s :=
hf.inf hg
theorem antitone.inter [preorder Ξ²] {f g : Ξ² β set Ξ±}
(hf : antitone f) (hg : antitone g) : antitone (Ξ» x, f x β© g x) :=
hf.inf hg
theorem antitone_on.inter [preorder Ξ²] {f g : Ξ² β set Ξ±} {s : set Ξ²}
(hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (Ξ» x, f x β© g x) s :=
hf.inf hg
theorem monotone.union [preorder Ξ²] {f g : Ξ² β set Ξ±}
(hf : monotone f) (hg : monotone g) : monotone (Ξ» x, f x βͺ g x) :=
hf.sup hg
theorem monotone_on.union [preorder Ξ²] {f g : Ξ² β set Ξ±} {s : set Ξ²}
(hf : monotone_on f s) (hg : monotone_on g s) : monotone_on (Ξ» x, f x βͺ g x) s :=
hf.sup hg
theorem antitone.union [preorder Ξ²] {f g : Ξ² β set Ξ±}
(hf : antitone f) (hg : antitone g) : antitone (Ξ» x, f x βͺ g x) :=
hf.sup hg
theorem antitone_on.union [preorder Ξ²] {f g : Ξ² β set Ξ±} {s : set Ξ²}
(hf : antitone_on f s) (hg : antitone_on g s) : antitone_on (Ξ» x, f x βͺ g x) s :=
hf.sup hg
namespace set
theorem monotone_set_of [preorder Ξ±] {p : Ξ± β Ξ² β Prop}
(hp : β b, monotone (Ξ» a, p a b)) : monotone (Ξ» a, {b | p a b}) :=
Ξ» a a' h b, hp b h
theorem antitone_set_of [preorder Ξ±] {p : Ξ± β Ξ² β Prop}
(hp : β b, antitone (Ξ» a, p a b)) : antitone (Ξ» a, {b | p a b}) :=
Ξ» a a' h b, hp b h
/-- Quantifying over a set is antitone in the set -/
lemma antitone_bforall {P : Ξ± β Prop} : antitone (Ξ» s : set Ξ±, β x β s, P x) :=
Ξ» s t hst h x hx, h x $ hst hx
end set
end monotone
/-! ### Disjoint sets -/
variables {Ξ± Ξ² : Type*} {s t u : set Ξ±} {f : Ξ± β Ξ²}
namespace disjoint
theorem union_left (hs : disjoint s u) (ht : disjoint t u) : disjoint (s βͺ t) u :=
hs.sup_left ht
theorem union_right (ht : disjoint s t) (hu : disjoint s u) : disjoint s (t βͺ u) :=
ht.sup_right hu
lemma inter_left (u : set Ξ±) (h : disjoint s t) : disjoint (s β© u) t :=
h.inf_left u
lemma inter_left' (u : set Ξ±) (h : disjoint s t) : disjoint (u β© s) t :=
h.inf_left' _
lemma inter_right (u : set Ξ±) (h : disjoint s t) : disjoint s (t β© u) :=
h.inf_right _
lemma inter_right' (u : set Ξ±) (h : disjoint s t) : disjoint s (u β© t) :=
h.inf_right' _
lemma subset_left_of_subset_union (h : s β t βͺ u) (hac : disjoint s u) : s β t :=
hac.left_le_of_le_sup_right h
lemma subset_right_of_subset_union (h : s β t βͺ u) (hab : disjoint s t) : s β u :=
hab.left_le_of_le_sup_left h
end disjoint
|
345c1c8f375eb6c1fcfe3689be463fdadbbedc58
|
9a0192b31a07f48502dacee8122e0b8beda7b110
|
/lista3.lean
|
a327007e92d06cedba14648f57e8f43c758e9964
|
[] |
no_license
|
ana-/Lean
|
8a5b9f2e13685bd43efd72c6665401c0851157cb
|
4527da83de947fa1df368b2f9bcf322a4d14e121
|
refs/heads/master
| 1,593,588,619,552
| 1,565,196,720,000
| 1,565,196,720,000
| 201,090,102
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,274
|
lean
|
/- Lista 3 do EAD
QuestΓ£o 2-
Um crime Γ© cometido por uma e somente uma pessoa e hΓ‘ quatro suspeitos: Paulo, Rodrigo, Henrique e Felipe.
Interrogados eles fazem as seguintes declaraΓ§Γ΅es:
Felipe: Rodrigo mente quando diz que eu nΓ£o sou inocente.
Paulo: Rodrigo nΓ£o Γ© inocente.
Henrique: Eu sou inocente.
Rodrigo: Felipe nΓ£o Γ© inocente.
Represente em lΓ³gica proposicional as sentenΓ§as acima. Com base nestas sentenΓ§as lΓ³gicas, mostre que se o
inspetor usar Tableaux irΓ‘ concluir que se o Henrique for culpado entΓ£o somente Felipe fala a verdade. Mostre o
Tableaux que suporta a conclusΓ£o do inspetor.
P : paulo
F : felipe
H : henrique
R : rodrigo
c: x Γ© culpado
v: x fal2a a verdade
constant P : U β U
constant R : U β Prop
constant H : U β Prop
constant F : U β Prop
-/
--resposta
variable U : Type
variable C : U
variable V : U
variables P R H F: U β Prop
#check ((P C β¨ R C β¨ H C β¨ F C ) β§ (P C β (Β¬ R C β§ Β¬ H C β§ Β¬ F C)) β§ (R C β (Β¬ P C β§ Β¬ H C β§ Β¬ F C)) β§ (H C β (Β¬ R C β§ Β¬ P C β§ Β¬ F C)) β§ (F C β (Β¬ R C β§ Β¬ H C β§ Β¬ P C)) β§ (H V β (F C β Β¬ R V)) β§ (P V β R C ) β§ (H V β Β¬ H C) β§ (R V β F C)) β (H C β (F V β§ Β¬ P V β§ Β¬ H V β§ Β¬ R V))
|
34fe36571e0d55daa3974c473e25c117e4ed86d0
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/Lean3Lib/data/buffer.lean
|
4ff10660110e19d89182cd0ccd37935f191fd75e
|
[] |
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
| 4,671
|
lean
|
/-
Copyright (c) 2017 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.default
universes u w u_1
namespace Mathlib
def buffer (Ξ± : Type u) :=
sigma fun (n : β) => array n Ξ±
def mk_buffer {Ξ± : Type u} : buffer Ξ± :=
sigma.mk 0 (d_array.mk fun (i : fin 0) => fin.elim0 i)
def array.to_buffer {Ξ± : Type u} {n : β} (a : array n Ξ±) : buffer Ξ± :=
sigma.mk n a
namespace buffer
def nil {Ξ± : Type u} : buffer Ξ± :=
mk_buffer
def size {Ξ± : Type u} (b : buffer Ξ±) : β :=
sigma.fst b
def to_array {Ξ± : Type u} (b : buffer Ξ±) : array (size b) Ξ± :=
sigma.snd b
def push_back {Ξ± : Type u} : buffer Ξ± β Ξ± β buffer Ξ± :=
sorry
def pop_back {Ξ± : Type u} : buffer Ξ± β buffer Ξ± :=
sorry
def read {Ξ± : Type u} (b : buffer Ξ±) : fin (size b) β Ξ± :=
sorry
def write {Ξ± : Type u} (b : buffer Ξ±) : fin (size b) β Ξ± β buffer Ξ± :=
sorry
def read' {Ξ± : Type u} [Inhabited Ξ±] : buffer Ξ± β β β Ξ± :=
sorry
def write' {Ξ± : Type u} : buffer Ξ± β β β Ξ± β buffer Ξ± :=
sorry
theorem read_eq_read' {Ξ± : Type u} [Inhabited Ξ±] (b : buffer Ξ±) (i : β) (h : i < size b) : read b { val := i, property := h } = read' b i := sorry
theorem write_eq_write' {Ξ± : Type u} (b : buffer Ξ±) (i : β) (h : i < size b) (v : Ξ±) : write b { val := i, property := h } v = write' b i v := sorry
def to_list {Ξ± : Type u} (b : buffer Ξ±) : List Ξ± :=
array.to_list (to_array b)
protected def to_string (b : buffer char) : string :=
list.as_string (array.to_list (to_array b))
def append_list {Ξ± : Type u} : buffer Ξ± β List Ξ± β buffer Ξ± :=
sorry
def append_string (b : buffer char) (s : string) : buffer char :=
append_list b (string.to_list s)
theorem lt_aux_1 {a : β} {b : β} {c : β} (h : a + c < b) : a < b :=
lt_of_le_of_lt (nat.le_add_right a c) h
theorem lt_aux_2 {n : β} (h : n > 0) : n - 1 < n :=
(fun (hβ : 1 > 0) => nat.sub_lt h hβ) (of_as_true trivial)
theorem lt_aux_3 {n : β} {i : β} (h : i + 1 < n) : n - bit0 1 - i < n := sorry
def append_array {Ξ± : Type u} {n : β} (nz : n > 0) : buffer Ξ± β array n Ξ± β (i : β) β i < n β buffer Ξ± :=
sorry
protected def append {Ξ± : Type u} : buffer Ξ± β buffer Ξ± β buffer Ξ± :=
sorry
def iterate {Ξ± : Type u} {Ξ² : Type w} (b : buffer Ξ±) : Ξ² β (fin (size b) β Ξ± β Ξ² β Ξ²) β Ξ² :=
sorry
def foreach {Ξ± : Type u} (b : buffer Ξ±) : (fin (size b) β Ξ± β Ξ±) β buffer Ξ± :=
sorry
/-- Monadically map a function over the buffer. -/
def mmap {Ξ± : Type u} {Ξ² : Type w} {m : Type w β Type u_1} [Monad m] (b : buffer Ξ±) (f : Ξ± β m Ξ²) : m (buffer Ξ²) :=
do
let b' β array.mmap (sigma.snd b) f
return (array.to_buffer b')
/-- Map a function over the buffer. -/
def map {Ξ± : Type u} {Ξ² : Type w} : buffer Ξ± β (Ξ± β Ξ²) β buffer Ξ² :=
sorry
def foldl {Ξ± : Type u} {Ξ² : Type w} : buffer Ξ± β Ξ² β (Ξ± β Ξ² β Ξ²) β Ξ² :=
sorry
def rev_iterate {Ξ± : Type u} {Ξ² : Type w} (b : buffer Ξ±) : Ξ² β (fin (size b) β Ξ± β Ξ² β Ξ²) β Ξ² :=
sorry
def take {Ξ± : Type u} (b : buffer Ξ±) (n : β) : buffer Ξ± :=
dite (n β€ size b) (fun (h : n β€ size b) => sigma.mk n (array.take (to_array b) n h)) fun (h : Β¬n β€ size b) => b
def take_right {Ξ± : Type u} (b : buffer Ξ±) (n : β) : buffer Ξ± :=
dite (n β€ size b) (fun (h : n β€ size b) => sigma.mk n (array.take_right (to_array b) n h)) fun (h : Β¬n β€ size b) => b
def drop {Ξ± : Type u} (b : buffer Ξ±) (n : β) : buffer Ξ± :=
dite (n β€ size b) (fun (h : n β€ size b) => sigma.mk (size b - n) (array.drop (to_array b) n h))
fun (h : Β¬n β€ size b) => b
def reverse {Ξ± : Type u} (b : buffer Ξ±) : buffer Ξ± :=
sigma.mk (size b) (array.reverse (to_array b))
protected def mem {Ξ± : Type u} (v : Ξ±) (a : buffer Ξ±) :=
β (i : fin (size a)), read a i = v
protected instance has_mem {Ξ± : Type u} : has_mem Ξ± (buffer Ξ±) :=
has_mem.mk buffer.mem
protected instance has_append {Ξ± : Type u} : Append (buffer Ξ±) :=
{ append := buffer.append }
protected instance has_repr {Ξ± : Type u} [has_repr Ξ±] : has_repr (buffer Ξ±) :=
has_repr.mk (repr β to_list)
end buffer
def list.to_buffer {Ξ± : Type u} (l : List Ξ±) : buffer Ξ± :=
buffer.append_list mk_buffer l
def char_buffer :=
buffer char
/-- Convert a format object into a character buffer with the provided
formatting options. -/
def string.to_char_buffer (s : string) : char_buffer :=
buffer.append_string buffer.nil s
|
d7fc17535ce035acdcd9ab0806992afb29248aef
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/blast11.lean
|
08b1da392d0cbdb0162daa7c8eb61816b8a5e1a2
|
[
"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
| 227
|
lean
|
import data.nat
open algebra nat
definition lemma1 (a b : nat) : a + b + 0 = b + a :=
by simp
print lemma1
definition lemma2 (a b c : nat) : a + b + 0 + c + a + a + b = 0 + 0 + c + a + b + a + a + b :=
by simp
print lemma2
|
7710a6669d21a8278665bef924728b209e3eaa27
|
e151e9053bfd6d71740066474fc500a087837323
|
/src/hott/init/meta/intro.lean
|
f7c04abd415998192e2343ca2e9196579f865814
|
[
"Apache-2.0"
] |
permissive
|
daniel-carranza/hott3
|
15bac2d90589dbb952ef15e74b2837722491963d
|
913811e8a1371d3a5751d7d32ff9dec8aa6815d9
|
refs/heads/master
| 1,610,091,349,670
| 1,596,222,336,000
| 1,596,222,336,000
| 241,957,822
| 0
| 0
|
Apache-2.0
| 1,582,222,839,000
| 1,582,222,838,000
| null |
UTF-8
|
Lean
| false
| false
| 650
|
lean
|
/-
Copyright (c) 2017 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
open expr tactic
local postfix `?`:9001 := optional
namespace tactic.interactive
open interactive interactive.types lean.parser lean
/--
A version of `intro` which will never insert `id_locked` in the proof term.
The `intro` tactic will add `id_locked` to the proof term if the goal is not a Pi or a let (but reduces to one).
See issue lean#1260.
-/
meta def hintro : parse ident_? β tactic unit
| none := intro_core `_ >> skip
| (some h) := intro_core h >> skip
end tactic.interactive
|
51cdb4c4a501888e9c778dfe49a3fd7c341a866b
|
4a092885406df4e441e9bb9065d9405dacb94cd8
|
/src/for_mathlib/logic.lean
|
866543797b9fdba4b1b724f93e5b052fa9b75104
|
[
"Apache-2.0"
] |
permissive
|
semorrison/lean-perfectoid-spaces
|
78c1572cedbfae9c3e460d8aaf91de38616904d8
|
bb4311dff45791170bcb1b6a983e2591bee88a19
|
refs/heads/master
| 1,588,841,765,494
| 1,554,805,620,000
| 1,554,805,620,000
| 180,353,546
| 0
| 1
| null | 1,554,809,880,000
| 1,554,809,880,000
| null |
UTF-8
|
Lean
| false
| false
| 246
|
lean
|
import logic.basic
theorem forall_iff_forall_surj {Ξ± Ξ² : Type*} {f : Ξ± β Ξ²} (h : function.surjective f) {P : Ξ² β Prop} :
(β a, P (f a)) β β b, P b:=
β¨Ξ» ha b, by cases h b with a hab; rw βhab; exact ha a, Ξ» hb a, hb $ f aβ©
|
81958e8500b16dd5d41ccb3808db9084d98ea5f1
|
69d4931b605e11ca61881fc4f66db50a0a875e39
|
/src/algebra/algebra/subalgebra.lean
|
8c2714d9716cfdaf6f36ccc3cc5057cb57eed53e
|
[
"Apache-2.0"
] |
permissive
|
abentkamp/mathlib
|
d9a75d291ec09f4637b0f30cc3880ffb07549ee5
|
5360e476391508e092b5a1e5210bd0ed22dc0755
|
refs/heads/master
| 1,682,382,954,948
| 1,622,106,077,000
| 1,622,106,077,000
| 149,285,665
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 27,183
|
lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import algebra.algebra.operations
/-!
# Subalgebras over Commutative Semiring
In this file we define `subalgebra`s and the usual operations on them (`map`, `comap`).
More lemmas about `adjoin` can be found in `ring_theory.adjoin`.
-/
universes u v w
open_locale tensor_product big_operators
set_option old_structure_cmd true
/-- A subalgebra is a sub(semi)ring that includes the range of `algebra_map`. -/
structure subalgebra (R : Type u) (A : Type v)
[comm_semiring R] [semiring A] [algebra R A] extends subsemiring A : Type v :=
(algebra_map_mem' : β r, algebra_map R A r β carrier)
(zero_mem' := (algebra_map R A).map_zero βΈ algebra_map_mem' 0)
(one_mem' := (algebra_map R A).map_one βΈ algebra_map_mem' 1)
/-- Reinterpret a `subalgebra` as a `subsemiring`. -/
add_decl_doc subalgebra.to_subsemiring
namespace subalgebra
variables {R : Type u} {A : Type v} {B : Type w}
variables [comm_semiring R] [semiring A] [algebra R A] [semiring B] [algebra R B]
include R
instance : set_like (subalgebra R A) A :=
β¨subalgebra.carrier, Ξ» p q h, by cases p; cases q; congr'β©
@[simp]
lemma mem_carrier {s : subalgebra R A} {x : A} : x β s.carrier β x β s := iff.rfl
@[ext] theorem ext {S T : subalgebra R A} (h : β x : A, x β S β x β T) : S = T := set_like.ext h
/-- Copy of a submodule with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (S : subalgebra R A) (s : set A) (hs : s = βS) : subalgebra R A :=
{ carrier := s,
add_mem' := hs.symm βΈ S.add_mem',
mul_mem' := hs.symm βΈ S.mul_mem',
algebra_map_mem' := hs.symm βΈ S.algebra_map_mem' }
variables (S : subalgebra R A)
theorem algebra_map_mem (r : R) : algebra_map R A r β S :=
S.algebra_map_mem' r
theorem srange_le : (algebra_map R A).srange β€ S.to_subsemiring :=
Ξ» x β¨r, hrβ©, hr βΈ S.algebra_map_mem r
theorem range_subset : set.range (algebra_map R A) β S :=
Ξ» x β¨r, hrβ©, hr βΈ S.algebra_map_mem r
theorem range_le : set.range (algebra_map R A) β€ S :=
S.range_subset
theorem one_mem : (1 : A) β S :=
S.to_subsemiring.one_mem
theorem mul_mem {x y : A} (hx : x β S) (hy : y β S) : x * y β S :=
S.to_subsemiring.mul_mem hx hy
theorem smul_mem {x : A} (hx : x β S) (r : R) : r β’ x β S :=
(algebra.smul_def r x).symm βΈ S.mul_mem (S.algebra_map_mem r) hx
theorem pow_mem {x : A} (hx : x β S) (n : β) : x ^ n β S :=
S.to_subsemiring.pow_mem hx n
theorem zero_mem : (0 : A) β S :=
S.to_subsemiring.zero_mem
theorem add_mem {x y : A} (hx : x β S) (hy : y β S) : x + y β S :=
S.to_subsemiring.add_mem hx hy
theorem neg_mem {R : Type u} {A : Type v} [comm_ring R] [ring A]
[algebra R A] (S : subalgebra R A) {x : A} (hx : x β S) : -x β S :=
neg_one_smul R x βΈ S.smul_mem hx _
theorem sub_mem {R : Type u} {A : Type v} [comm_ring R] [ring A]
[algebra R A] (S : subalgebra R A) {x y : A} (hx : x β S) (hy : y β S) : x - y β S :=
by simpa only [sub_eq_add_neg] using S.add_mem hx (S.neg_mem hy)
theorem nsmul_mem {x : A} (hx : x β S) (n : β) : n β’ x β S :=
S.to_subsemiring.nsmul_mem hx n
theorem gsmul_mem {R : Type u} {A : Type v} [comm_ring R] [ring A]
[algebra R A] (S : subalgebra R A) {x : A} (hx : x β S) : β (n : β€), n β’ x β S
| (n : β) := by { rw [gsmul_coe_nat], exact S.nsmul_mem hx n }
| -[1+ n] := by { rw [gsmul_neg_succ_of_nat], exact S.neg_mem (S.nsmul_mem hx _) }
theorem coe_nat_mem (n : β) : (n : A) β S :=
S.to_subsemiring.coe_nat_mem n
theorem coe_int_mem {R : Type u} {A : Type v} [comm_ring R] [ring A]
[algebra R A] (S : subalgebra R A) (n : β€) : (n : A) β S :=
int.cases_on n (Ξ» i, S.coe_nat_mem i) (Ξ» i, S.neg_mem $ S.coe_nat_mem $ i + 1)
theorem list_prod_mem {L : list A} (h : β x β L, x β S) : L.prod β S :=
S.to_subsemiring.list_prod_mem h
theorem list_sum_mem {L : list A} (h : β x β L, x β S) : L.sum β S :=
S.to_subsemiring.list_sum_mem h
theorem multiset_prod_mem {R : Type u} {A : Type v} [comm_semiring R] [comm_semiring A]
[algebra R A] (S : subalgebra R A) {m : multiset A} (h : β x β m, x β S) : m.prod β S :=
S.to_subsemiring.multiset_prod_mem m h
theorem multiset_sum_mem {m : multiset A} (h : β x β m, x β S) : m.sum β S :=
S.to_subsemiring.multiset_sum_mem m h
theorem prod_mem {R : Type u} {A : Type v} [comm_semiring R] [comm_semiring A]
[algebra R A] (S : subalgebra R A) {ΞΉ : Type w} {t : finset ΞΉ} {f : ΞΉ β A}
(h : β x β t, f x β S) : β x in t, f x β S :=
S.to_subsemiring.prod_mem h
theorem sum_mem {ΞΉ : Type w} {t : finset ΞΉ} {f : ΞΉ β A}
(h : β x β t, f x β S) : β x in t, f x β S :=
S.to_subsemiring.sum_mem h
instance {R : Type u} {A : Type v} [comm_semiring R] [semiring A] [algebra R A]
(S : subalgebra R A) : is_add_submonoid (S : set A) :=
{ zero_mem := S.zero_mem,
add_mem := Ξ» _ _, S.add_mem }
instance {R : Type u} {A : Type v} [comm_semiring R] [semiring A] [algebra R A]
(S : subalgebra R A) : is_submonoid (S : set A) :=
{ one_mem := S.one_mem,
mul_mem := Ξ» _ _, S.mul_mem }
/-- A subalgebra over a ring is also a `subring`. -/
def to_subring {R : Type u} {A : Type v} [comm_ring R] [ring A] [algebra R A] (S : subalgebra R A) :
subring A :=
{ neg_mem' := Ξ» _, S.neg_mem,
.. S.to_subsemiring }
instance {R : Type u} {A : Type v} [comm_ring R] [ring A] [algebra R A] (S : subalgebra R A) :
is_subring (S : set A) :=
{ neg_mem := Ξ» _, S.neg_mem }
instance : inhabited S := β¨(0 : S.to_subsemiring)β©
section
/-! `subalgebra`s inherit structure from their `subsemiring` / `semiring` coercions. -/
instance to_semiring {R A}
[comm_semiring R] [semiring A] [algebra R A] (S : subalgebra R A) :
semiring S := S.to_subsemiring.to_semiring
instance to_comm_semiring {R A}
[comm_semiring R] [comm_semiring A] [algebra R A] (S : subalgebra R A) :
comm_semiring S := S.to_subsemiring.to_comm_semiring
instance to_ring {R A}
[comm_ring R] [ring A] [algebra R A] (S : subalgebra R A) :
ring S := S.to_subring.to_ring
instance to_comm_ring {R A}
[comm_ring R] [comm_ring A] [algebra R A] (S : subalgebra R A) :
comm_ring S := S.to_subring.to_comm_ring
instance to_ordered_semiring {R A}
[comm_semiring R] [ordered_semiring A] [algebra R A] (S : subalgebra R A) :
ordered_semiring S := S.to_subsemiring.to_ordered_semiring
instance to_ordered_comm_semiring {R A}
[comm_semiring R] [ordered_comm_semiring A] [algebra R A] (S : subalgebra R A) :
ordered_comm_semiring S := S.to_subsemiring.to_ordered_comm_semiring
instance to_ordered_ring {R A}
[comm_ring R] [ordered_ring A] [algebra R A] (S : subalgebra R A) :
ordered_ring S := S.to_subring.to_ordered_ring
instance to_ordered_comm_ring {R A}
[comm_ring R] [ordered_comm_ring A] [algebra R A] (S : subalgebra R A) :
ordered_comm_ring S := S.to_subring.to_ordered_comm_ring
instance to_linear_ordered_semiring {R A}
[comm_semiring R] [linear_ordered_semiring A] [algebra R A] (S : subalgebra R A) :
linear_ordered_semiring S := S.to_subsemiring.to_linear_ordered_semiring
/-! There is no `linear_ordered_comm_semiring`. -/
instance to_linear_ordered_ring {R A}
[comm_ring R] [linear_ordered_ring A] [algebra R A] (S : subalgebra R A) :
linear_ordered_ring S := S.to_subring.to_linear_ordered_ring
instance to_linear_ordered_comm_ring {R A}
[comm_ring R] [linear_ordered_comm_ring A] [algebra R A] (S : subalgebra R A) :
linear_ordered_comm_ring S := S.to_subring.to_linear_ordered_comm_ring
end
instance algebra : algebra R S :=
{ smul := Ξ» (c:R) x, β¨c β’ x.1, S.smul_mem x.2 cβ©,
commutes' := Ξ» c x, subtype.eq $ algebra.commutes _ _,
smul_def' := Ξ» c x, subtype.eq $ algebra.smul_def _ _,
.. (algebra_map R A).cod_srestrict S.to_subsemiring $ Ξ» x, S.range_le β¨x, rflβ© }
instance to_algebra {R A B : Type*} [comm_semiring R] [comm_semiring A] [semiring B]
[algebra R A] [algebra A B] (Aβ : subalgebra R A) : algebra Aβ B :=
algebra.of_subsemiring Aβ.to_subsemiring
instance nontrivial [nontrivial A] : nontrivial S :=
S.to_subsemiring.nontrivial
instance no_zero_smul_divisors_bot [no_zero_smul_divisors R A] : no_zero_smul_divisors R S :=
β¨Ξ» c x h,
have c = 0 β¨ (x : A) = 0,
from eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg coe h),
this.imp_right (@subtype.ext_iff _ _ x 0).mprβ©
@[simp, norm_cast] lemma coe_add (x y : S) : (β(x + y) : A) = βx + βy := rfl
@[simp, norm_cast] lemma coe_mul (x y : S) : (β(x * y) : A) = βx * βy := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : S) : A) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : S) : A) = 1 := rfl
@[simp, norm_cast] lemma coe_neg {R : Type u} {A : Type v} [comm_ring R] [ring A] [algebra R A]
{S : subalgebra R A} (x : S) : (β(-x) : A) = -βx := rfl
@[simp, norm_cast] lemma coe_sub {R : Type u} {A : Type v} [comm_ring R] [ring A] [algebra R A]
{S : subalgebra R A} (x y : S) : (β(x - y) : A) = βx - βy := rfl
@[simp, norm_cast] lemma coe_smul (r : R) (x : S) : (β(r β’ x) : A) = r β’ βx := rfl
@[simp, norm_cast] lemma coe_algebra_map (r : R) : β(algebra_map R S r) = algebra_map R A r :=
rfl
@[simp, norm_cast] lemma coe_pow (x : S) (n : β) : (β(x^n) : A) = (βx)^n :=
begin
induction n with n ih,
{ simp, },
{ simp [pow_succ, ih], },
end
@[simp, norm_cast] lemma coe_eq_zero {x : S} : (x : A) = 0 β x = 0 :=
(subtype.ext_iff.symm : (x : A) = (0 : S) β x = 0)
@[simp, norm_cast] lemma coe_eq_one {x : S} : (x : A) = 1 β x = 1 :=
(subtype.ext_iff.symm : (x : A) = (1 : S) β x = 1)
-- todo: standardize on the names these morphisms
-- compare with submodule.subtype
/-- Embedding of a subalgebra into the algebra. -/
def val : S ββ[R] A :=
by refine_struct { to_fun := (coe : S β A) }; intros; refl
@[simp] lemma coe_val : (S.val : S β A) = coe := rfl
lemma val_apply (x : S) : S.val x = (x : A) := rfl
/-- Convert a `subalgebra` to `submodule` -/
def to_submodule : submodule R A :=
{ carrier := S,
zero_mem' := (0:S).2,
add_mem' := Ξ» x y hx hy, (β¨x, hxβ© + β¨y, hyβ© : S).2,
smul_mem' := Ξ» c x hx, (algebra.smul_def c x).symm βΈ
(β¨algebra_map R A c, S.range_le β¨c, rflβ©β© * β¨x, hxβ©:S).2 }
instance to_submodule.is_subring {R : Type u} {A : Type v} [comm_ring R] [ring A] [algebra R A]
(S : subalgebra R A) : is_subring (S.to_submodule : set A) := S.is_subring
@[simp] lemma mem_to_submodule {x} : x β S.to_submodule β x β S := iff.rfl
theorem to_submodule_injective :
function.injective (to_submodule : subalgebra R A β submodule R A) :=
Ξ» S T h, ext $ Ξ» x, by rw [β mem_to_submodule, β mem_to_submodule, h]
theorem to_submodule_inj {S U : subalgebra R A} : S.to_submodule = U.to_submodule β S = U :=
to_submodule_injective.eq_iff
/-- As submodules, subalgebras are idempotent. -/
@[simp] theorem mul_self : S.to_submodule * S.to_submodule = S.to_submodule :=
begin
apply le_antisymm,
{ rw submodule.mul_le,
intros y hy z hz,
exact mul_mem S hy hz },
{ intros x hx1,
rw β mul_one x,
exact submodule.mul_mem_mul hx1 (one_mem S) }
end
/-- Linear equivalence between `S : submodule R A` and `S`. Though these types are equal,
we define it as a `linear_equiv` to avoid type equalities. -/
def to_submodule_equiv (S : subalgebra R A) : S.to_submodule ββ[R] S :=
linear_equiv.of_eq _ _ rfl
/-- Reinterpret an `S`-subalgebra as an `R`-subalgebra in `comap R S A`. -/
def comap {R : Type u} {S : Type v} {A : Type w}
[comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A]
(iSB : subalgebra S A) : subalgebra R (algebra.comap R S A) :=
{ algebra_map_mem' := Ξ» r, iSB.algebra_map_mem (algebra_map R S r),
.. iSB }
/-- If `S` is an `R`-subalgebra of `A` and `T` is an `S`-subalgebra of `A`,
then `T` is an `R`-subalgebra of `A`. -/
def under {R : Type u} {A : Type v} [comm_semiring R] [comm_semiring A]
{i : algebra R A} (S : subalgebra R A)
(T : subalgebra S A) : subalgebra R A :=
{ algebra_map_mem' := Ξ» r, T.algebra_map_mem β¨algebra_map R A r, S.algebra_map_mem rβ©,
.. T }
/-- Transport a subalgebra via an algebra homomorphism. -/
def map (S : subalgebra R A) (f : A ββ[R] B) : subalgebra R B :=
{ algebra_map_mem' := Ξ» r, f.commutes r βΈ set.mem_image_of_mem _ (S.algebra_map_mem r),
.. S.to_subsemiring.map (f : A β+* B) }
lemma map_mono {Sβ Sβ : subalgebra R A} {f : A ββ[R] B} :
Sβ β€ Sβ β Sβ.map f β€ Sβ.map f :=
set.image_subset f
lemma map_injective {Sβ Sβ : subalgebra R A} (f : A ββ[R] B)
(hf : function.injective f) (ih : Sβ.map f = Sβ.map f) : Sβ = Sβ :=
ext $ set.ext_iff.1 $ set.image_injective.2 hf $ set.ext $ set_like.ext_iff.mp ih
lemma mem_map {S : subalgebra R A} {f : A ββ[R] B} {y : B} :
y β map S f β β x β S, f x = y :=
subsemiring.mem_map
/-- Preimage of a subalgebra under an algebra homomorphism. -/
def comap' (S : subalgebra R B) (f : A ββ[R] B) : subalgebra R A :=
{ algebra_map_mem' := Ξ» r, show f (algebra_map R A r) β S,
from (f.commutes r).symm βΈ S.algebra_map_mem r,
.. S.to_subsemiring.comap (f : A β+* B) }
theorem map_le {S : subalgebra R A} {f : A ββ[R] B} {U : subalgebra R B} :
map S f β€ U β S β€ comap' U f :=
set.image_subset_iff
@[simp] lemma mem_comap (S : subalgebra R B) (f : A ββ[R] B) (x : A) :
x β S.comap' f β f x β S :=
iff.rfl
@[simp, norm_cast] lemma coe_comap (S : subalgebra R B) (f : A ββ[R] B) :
(S.comap' f : set A) = f β»ΒΉ' (S : set B) :=
by { ext, simp, }
instance no_zero_divisors {R A : Type*} [comm_ring R] [semiring A] [no_zero_divisors A]
[algebra R A] (S : subalgebra R A) : no_zero_divisors S :=
S.to_subsemiring.no_zero_divisors
instance no_zero_smul_divisors_top {R A : Type*} [comm_semiring R] [comm_semiring A] [algebra R A]
[no_zero_divisors A] (S : subalgebra R A) : no_zero_smul_divisors S A :=
β¨Ξ» c x h,
have (c : A) = 0 β¨ x = 0,
from eq_zero_or_eq_zero_of_mul_eq_zero h,
this.imp_left (@subtype.ext_iff _ _ c 0).mprβ©
instance integral_domain {R A : Type*} [comm_ring R] [integral_domain A] [algebra R A]
(S : subalgebra R A) : integral_domain S :=
@subring.domain A _ S _
end subalgebra
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w}
variables [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
variables (Ο : A ββ[R] B)
/-- Range of an `alg_hom` as a subalgebra. -/
protected def range (Ο : A ββ[R] B) : subalgebra R B :=
{ algebra_map_mem' := Ξ» r, β¨algebra_map R A r, Ο.commutes rβ©,
.. Ο.to_ring_hom.srange }
@[simp] lemma mem_range (Ο : A ββ[R] B) {y : B} :
y β Ο.range β β x, Ο x = y := ring_hom.mem_srange
theorem mem_range_self (Ο : A ββ[R] B) (x : A) : Ο x β Ο.range := Ο.mem_range.2 β¨x, rflβ©
@[simp] lemma coe_range (Ο : A ββ[R] B) : (Ο.range : set B) = set.range Ο :=
by { ext, rw [set_like.mem_coe, mem_range], refl }
/-- Restrict the codomain of an algebra homomorphism. -/
def cod_restrict (f : A ββ[R] B) (S : subalgebra R B) (hf : β x, f x β S) : A ββ[R] S :=
{ commutes' := Ξ» r, subtype.eq $ f.commutes r,
.. ring_hom.cod_srestrict (f : A β+* B) S.to_subsemiring hf }
@[simp] lemma val_comp_cod_restrict (f : A ββ[R] B) (S : subalgebra R B) (hf : β x, f x β S) :
S.val.comp (f.cod_restrict S hf) = f :=
alg_hom.ext $ Ξ» _, rfl
@[simp] lemma coe_cod_restrict (f : A ββ[R] B) (S : subalgebra R B) (hf : β x, f x β S) (x : A) :
β(f.cod_restrict S hf x) = f x := rfl
theorem injective_cod_restrict (f : A ββ[R] B) (S : subalgebra R B) (hf : β x, f x β S) :
function.injective (f.cod_restrict S hf) β function.injective f :=
β¨Ξ» H x y hxy, H $ subtype.eq hxy, Ξ» H x y hxy, H (congr_arg subtype.val hxy : _)β©
/-- Restrict the codomain of a alg_hom `f` to `f.range`.
This is the bundled version of `set.range_factorization`. -/
@[reducible] def range_restrict (f : A ββ[R] B) : A ββ[R] f.range :=
f.cod_restrict f.range f.mem_range_self
/-- The equalizer of two R-algebra homomorphisms -/
def equalizer (Ο Ο : A ββ[R] B) : subalgebra R A :=
{ carrier := {a | Ο a = Ο a},
add_mem' := Ξ» x y hx hy, by
{ change Ο x = Ο x at hx,
change Ο y = Ο y at hy,
change Ο (x + y) = Ο (x + y),
rw [alg_hom.map_add, alg_hom.map_add, hx, hy] },
mul_mem' := Ξ» x y hx hy, by
{ change Ο x = Ο x at hx,
change Ο y = Ο y at hy,
change Ο (x * y) = Ο (x * y),
rw [alg_hom.map_mul, alg_hom.map_mul, hx, hy] },
algebra_map_mem' := Ξ» x, by
{ change Ο (algebra_map R A x) = Ο (algebra_map R A x),
rw [alg_hom.commutes, alg_hom.commutes] } }
@[simp] lemma mem_equalizer (Ο Ο : A ββ[R] B) (x : A) :
x β Ο.equalizer Ο β Ο x = Ο x := iff.rfl
end alg_hom
namespace alg_equiv
variables {R : Type u} {A : Type v} {B : Type w}
variables [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
/-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range.
This is a computable alternative to `alg_equiv.of_injective`. -/
def of_left_inverse
{g : B β A} {f : A ββ[R] B} (h : function.left_inverse g f) :
A ββ[R] f.range :=
{ to_fun := f.range_restrict,
inv_fun := g β f.range.val,
left_inv := h,
right_inv := Ξ» x, subtype.ext $
let β¨x', hx'β© := f.mem_range.mp x.prop in
show f (g x) = x, by rw [βhx', h x'],
..f.range_restrict }
@[simp] lemma of_left_inverse_apply
{g : B β A} {f : A ββ[R] B} (h : function.left_inverse g f) (x : A) :
β(of_left_inverse h x) = f x := rfl
@[simp] lemma of_left_inverse_symm_apply
{g : B β A} {f : A ββ[R] B} (h : function.left_inverse g f) (x : f.range) :
(of_left_inverse h).symm x = g x := rfl
/-- Restrict an injective algebra homomorphism to an algebra isomorphism -/
noncomputable def of_injective (f : A ββ[R] B) (hf : function.injective f) :
A ββ[R] f.range :=
of_left_inverse (classical.some_spec hf.has_left_inverse)
@[simp] lemma of_injective_apply (f : A ββ[R] B) (hf : function.injective f) (x : A) :
β(of_injective f hf x) = f x := rfl
/-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/
noncomputable def of_injective_field {E F : Type*} [division_ring E] [semiring F]
[nontrivial F] [algebra R E] [algebra R F] (f : E ββ[R] F) : E ββ[R] f.range :=
of_injective f f.to_ring_hom.injective
end alg_equiv
namespace algebra
variables (R : Type u) {A : Type v} {B : Type w}
variables [comm_semiring R] [semiring A] [algebra R A] [semiring B] [algebra R B]
/-- The minimal subalgebra that includes `s`. -/
def adjoin (s : set A) : subalgebra R A :=
{ algebra_map_mem' := Ξ» r, subsemiring.subset_closure $ or.inl β¨r, rflβ©,
.. subsemiring.closure (set.range (algebra_map R A) βͺ s) }
variables {R}
protected lemma gc : galois_connection (adjoin R : set A β subalgebra R A) coe :=
Ξ» s S, β¨Ξ» H, le_trans (le_trans (set.subset_union_right _ _) subsemiring.subset_closure) H,
Ξ» H, show subsemiring.closure (set.range (algebra_map R A) βͺ s) β€ S.to_subsemiring,
from subsemiring.closure_le.2 $ set.union_subset S.range_subset Hβ©
/-- Galois insertion between `adjoin` and `coe`. -/
protected def gi : galois_insertion (adjoin R : set A β subalgebra R A) coe :=
{ choice := Ξ» s hs, adjoin R s,
gc := algebra.gc,
le_l_u := Ξ» S, (algebra.gc (S : set A) (adjoin R S)).1 $ le_refl _,
choice_eq := Ξ» _ _, rfl }
instance : complete_lattice (subalgebra R A) :=
galois_insertion.lift_complete_lattice algebra.gi
instance : inhabited (subalgebra R A) := β¨β₯β©
theorem mem_bot {x : A} : x β (β₯ : subalgebra R A) β x β set.range (algebra_map R A) :=
suffices (of_id R A).range = (β₯ : subalgebra R A),
by { rw [β this, βset_like.mem_coe, alg_hom.coe_range], refl },
le_bot_iff.mp (Ξ» x hx, subalgebra.range_le _ ((of_id R A).coe_range βΈ hx))
theorem to_submodule_bot : (β₯ : subalgebra R A).to_submodule = R β 1 :=
by { ext x, simp [mem_bot, -set.singleton_one, submodule.mem_span_singleton, algebra.smul_def] }
@[simp] theorem mem_top {x : A} : x β (β€ : subalgebra R A) :=
subsemiring.subset_closure $ or.inr trivial
@[simp] theorem top_to_submodule : (β€ : subalgebra R A).to_submodule = β€ :=
submodule.ext $ Ξ» x, iff_of_true mem_top trivial
@[simp] theorem top_to_subsemiring : (β€ : subalgebra R A).to_subsemiring = β€ :=
subsemiring.ext $ Ξ» x, iff_of_true mem_top trivial
@[simp] theorem coe_bot : ((β₯ : subalgebra R A) : set A) = set.range (algebra_map R A) :=
by simp [set.ext_iff, algebra.mem_bot]
theorem eq_top_iff {S : subalgebra R A} :
S = β€ β β x : A, x β S :=
β¨Ξ» h x, by rw h; exact mem_top, Ξ» h, by ext x; exact β¨Ξ» _, mem_top, Ξ» _, h xβ©β©
@[simp] theorem map_top (f : A ββ[R] B) : subalgebra.map (β€ : subalgebra R A) f = f.range :=
subalgebra.ext $ Ξ» x,
β¨Ξ» β¨y, _, hyβ©, β¨y, hyβ©, Ξ» β¨y, hyβ©, β¨y, algebra.mem_top, hyβ©β©
@[simp] theorem map_bot (f : A ββ[R] B) : subalgebra.map (β₯ : subalgebra R A) f = β₯ :=
eq_bot_iff.2 $ Ξ» x β¨y, hy, hfyβ©, let β¨r, hrβ© := mem_bot.1 hy in subalgebra.range_le _
β¨r, by rwa [β f.commutes, hr]β©
@[simp] theorem comap_top (f : A ββ[R] B) : subalgebra.comap' (β€ : subalgebra R B) f = β€ :=
eq_top_iff.2 $ Ξ» x, mem_top
/-- `alg_hom` to `β€ : subalgebra R A`. -/
def to_top : A ββ[R] (β€ : subalgebra R A) :=
by refine_struct { to_fun := Ξ» x, (β¨x, mem_topβ© : (β€ : subalgebra R A)) }; intros; refl
theorem surjective_algebra_map_iff :
function.surjective (algebra_map R A) β (β€ : subalgebra R A) = β₯ :=
β¨Ξ» h, eq_bot_iff.2 $ Ξ» y _, let β¨x, hxβ© := h y in hx βΈ subalgebra.algebra_map_mem _ _,
Ξ» h y, algebra.mem_bot.1 $ eq_bot_iff.1 h (algebra.mem_top : y β _)β©
theorem bijective_algebra_map_iff {R A : Type*} [field R] [semiring A] [nontrivial A]
[algebra R A] :
function.bijective (algebra_map R A) β (β€ : subalgebra R A) = β₯ :=
β¨Ξ» h, surjective_algebra_map_iff.1 h.2,
Ξ» h, β¨(algebra_map R A).injective, surjective_algebra_map_iff.2 hβ©β©
/-- The bottom subalgebra is isomorphic to the base ring. -/
noncomputable def bot_equiv_of_injective (h : function.injective (algebra_map R A)) :
(β₯ : subalgebra R A) ββ[R] R :=
alg_equiv.symm $ alg_equiv.of_bijective (algebra.of_id R _)
β¨Ξ» x y hxy, h (congr_arg subtype.val hxy : _),
Ξ» β¨y, hyβ©, let β¨x, hxβ© := algebra.mem_bot.1 hy in β¨x, subtype.eq hxβ©β©
/-- The bottom subalgebra is isomorphic to the field. -/
noncomputable def bot_equiv (F R : Type*) [field F] [semiring R] [nontrivial R] [algebra F R] :
(β₯ : subalgebra F R) ββ[F] F :=
bot_equiv_of_injective (ring_hom.injective _)
/-- The top subalgebra is isomorphic to the field. -/
noncomputable def top_equiv : (β€ : subalgebra R A) ββ[R] A :=
(alg_equiv.of_bijective to_top β¨Ξ» _ _, subtype.mk.inj,
Ξ» x, β¨x.val, by { ext, refl }β©β© : A ββ[R] (β€ : subalgebra R A)).symm
end algebra
namespace subalgebra
open algebra
variables {R : Type u} {A : Type v} {B : Type w}
variables [comm_semiring R] [semiring A] [algebra R A] [semiring B] [algebra R B]
variables (S : subalgebra R A)
-- TODO[gh-6025]: make this an instance once safe to do so
lemma subsingleton_of_subsingleton [subsingleton A] : subsingleton (subalgebra R A) :=
β¨Ξ» B C, ext (Ξ» x, by { simp only [subsingleton.elim x 0, zero_mem] })β©
-- TODO[gh-6025]: make this an instance once safe to do so
lemma alg_hom.subsingleton [subsingleton (subalgebra R A)] : subsingleton (A ββ[R] B) :=
β¨Ξ» f g, alg_hom.ext $ Ξ» a,
have a β (β₯ : subalgebra R A) := subsingleton.elim (β€ : subalgebra R A) β₯ βΈ mem_top,
let β¨x, hxβ© := set.mem_range.mp (mem_bot.mp this) in
hx βΈ (f.commutes _).trans (g.commutes _).symmβ©
-- TODO[gh-6025]: make this an instance once safe to do so
lemma alg_equiv.subsingleton_left [subsingleton (subalgebra R A)] : subsingleton (A ββ[R] B) :=
begin
haveI : subsingleton (A ββ[R] B) := alg_hom.subsingleton,
exact β¨Ξ» f g, alg_equiv.ext
(Ξ» x, alg_hom.ext_iff.mp (subsingleton.elim f.to_alg_hom g.to_alg_hom) x)β©,
end
-- TODO[gh-6025]: make this an instance once safe to do so
lemma alg_equiv.subsingleton_right [subsingleton (subalgebra R B)] : subsingleton (A ββ[R] B) :=
begin
haveI : subsingleton (B ββ[R] A) := alg_equiv.subsingleton_left,
exact β¨Ξ» f g, eq.trans (alg_equiv.symm_symm _).symm
(by rw [subsingleton.elim f.symm g.symm, alg_equiv.symm_symm])β©
end
lemma range_val : S.val.range = S :=
ext $ set.ext_iff.1 $ S.val.coe_range.trans subtype.range_val
instance : unique (subalgebra R R) :=
{ uniq :=
begin
intro S,
refine le_antisymm (Ξ» r hr, _) bot_le,
simp only [set.mem_range, mem_bot, id.map_eq_self, exists_apply_eq_apply, default],
end
.. algebra.subalgebra.inhabited }
/-- Two subalgebras that are equal are also equivalent as algebras.
This is the `subalgebra` version of `linear_equiv.of_eq` and `equiv.set.of_eq`. -/
@[simps apply]
def equiv_of_eq (S T : subalgebra R A) (h : S = T) : S ββ[R] T :=
{ to_fun := Ξ» x, β¨x, h βΈ x.2β©,
inv_fun := Ξ» x, β¨x, h.symm βΈ x.2β©,
map_mul' := Ξ» _ _, rfl,
commutes' := Ξ» _, rfl,
.. linear_equiv.of_eq _ _ (congr_arg to_submodule h) }
@[simp] lemma equiv_of_eq_symm (S T : subalgebra R A) (h : S = T) :
(equiv_of_eq S T h).symm = equiv_of_eq T S h.symm :=
rfl
@[simp] lemma equiv_of_eq_rfl (S : subalgebra R A) :
equiv_of_eq S S rfl = alg_equiv.refl :=
by { ext, refl }
@[simp] lemma equiv_of_eq_trans (S T U : subalgebra R A) (hST : S = T) (hTU : T = U) :
(equiv_of_eq S T hST).trans (equiv_of_eq T U hTU) = equiv_of_eq S U (trans hST hTU) :=
rfl
end subalgebra
section nat
variables {R : Type*} [semiring R]
/-- A subsemiring is a `β`-subalgebra. -/
def subalgebra_of_subsemiring (S : subsemiring R) : subalgebra β R :=
{ algebra_map_mem' := Ξ» i, S.coe_nat_mem i,
.. S }
@[simp] lemma mem_subalgebra_of_subsemiring {x : R} {S : subsemiring R} :
x β subalgebra_of_subsemiring S β x β S :=
iff.rfl
end nat
section int
variables {R : Type*} [ring R]
/-- A subring is a `β€`-subalgebra. -/
def subalgebra_of_subring (S : subring R) : subalgebra β€ R :=
{ algebra_map_mem' := Ξ» i, int.induction_on i S.zero_mem
(Ξ» i ih, S.add_mem ih S.one_mem)
(Ξ» i ih, show ((-i - 1 : β€) : R) β S, by { rw [int.cast_sub, int.cast_one],
exact S.sub_mem ih S.one_mem }),
.. S }
/-- A subset closed under the ring operations is a `β€`-subalgebra. -/
def subalgebra_of_is_subring (S : set R) [is_subring S] : subalgebra β€ R :=
subalgebra_of_subring S.to_subring
variables {S : Type*} [semiring S]
@[simp] lemma mem_subalgebra_of_subring {x : R} {S : subring R} :
x β subalgebra_of_subring S β x β S :=
iff.rfl
@[simp] lemma mem_subalgebra_of_is_subring {x : R} {S : set R} [is_subring S] :
x β subalgebra_of_is_subring S β x β S :=
iff.rfl
end int
|
ba6bc41d34b207af35797f742419d501f155df0d
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/ring_theory/localization.lean
|
7495e71da36fce6c37b782db1759daa988b739a4
|
[
"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
| 112,297
|
lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston
-/
import data.equiv.ring
import group_theory.monoid_localization
import ring_theory.algebraic
import ring_theory.ideal.local_ring
import ring_theory.ideal.quotient
import ring_theory.integral_closure
import ring_theory.non_zero_divisors
import group_theory.submonoid.inverses
import tactic.ring_exp
/-!
# Localizations of commutative rings
We characterize the localization of a commutative ring `R` at a submonoid `M` up to
isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a
ring homomorphism `f : R β+* S` satisfying 3 properties:
1. For all `y β M`, `f y` is a unit;
2. For all `z : S`, there exists `(x, y) : R Γ M` such that `z * f y = f x`;
3. For all `x, y : R`, `f x = f y` iff there exists `c β M` such that `x * c = y * c`.
In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras
and `M, T` be submonoids of `R` and `P` respectively, e.g.:
```
variables (R S P Q : Type*) [comm_ring R] [comm_ring S] [comm_ring P] [comm_ring Q]
variables [algebra R S] [algebra P Q] (M : submonoid R) (T : submonoid P)
```
## Main definitions
* `is_localization (M : submonoid R) (S : Type*)` is a typeclass expressing that `S` is a
localization of `R` at `M`, i.e. the canonical map `algebra_map R S : R β+* S` is a
localization map (satisfying the above properties).
* `is_localization.mk' S` is a surjection sending `(x, y) : R Γ M` to `f x * (f y)β»ΒΉ`
* `is_localization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R`
which maps elements of `M` to invertible elements of the codomain.
* `is_localization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements
of `M` to elements of `T`
* `is_localization.ring_equiv_of_ring_equiv`: if `R` and `P` are isomorphic by an isomorphism
sending `M` to `T`, then `S` and `Q` are isomorphic
* `is_localization.alg_equiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q`
are isomorphic as `R`-algebras
* `is_localization.is_integer` is a predicate stating that `x : S` is in the image of `R`
* `is_localization.away (x : R) S` expresses that `S` is a localization away from `x`, as an
abbreviation of `is_localization (submonoid.powers x) S`
* `is_localization.at_prime (I : ideal R) [is_prime I] (S : Type*)` expresses that `S` is a
localization at (the complement of) a prime ideal `I`, as an abbreviation of
`is_localization I.prime_compl S`
* `is_fraction_ring R K` expresses that `K` is a field of fractions of `R`, as an abbreviation of
`is_localization (non_zero_divisors R) K`
## Main results
* `localization M S`, a construction of the localization as a quotient type, defined in
`group_theory.monoid_localization`, has `comm_ring`, `algebra R` and `is_localization M`
instances if `R` is a ring. `localization.away`, `localization.at_prime` and `fraction_ring`
are abbreviations for `localization`s and have their corresponding `is_localization` instances
* `is_localization.at_prime.local_ring`: a theorem (not an instance) stating a localization at the
complement of a prime ideal is a local ring
* `is_fraction_ring.field`: a definition (not an instance) stating the localization of an integral
domain `R` at `R \ {0}` is a field
* `rat.is_fraction_ring` is an instance stating `β` is the field of fractions of `β€`
## Implementation notes
In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one
structure with an isomorphic one; one way around this is to isolate a predicate characterizing
a structure up to isomorphism, and reason about things that satisfy the predicate.
A previous version of this file used a fully bundled type of ring localization maps,
then used a type synonym `f.codomain` for `f : localization_map M S` to instantiate the
`R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already
defined on `S`. By making `is_localization` a predicate on the `algebra_map R S`,
we can ensure the localization map commutes nicely with other `algebra_map`s.
To prove most lemmas about a localization map `algebra_map R S` in this file we invoke the
corresponding proof for the underlying `comm_monoid` localization map
`is_localization.to_localization_map M S`, which can be found in `group_theory.monoid_localization`
and the namespace `submonoid.localization_map`.
To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas.
These show the quotient map `mk : R β M β localization M` equals the surjection
`localization_map.mk'` induced by the map `algebra_map : R β+* localization M`.
The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file,
which are about the `localization_map.mk'` induced by any localization map.
The proof that "a `comm_ring` `K` which is the localization of an integral domain `R` at `R \ {0}`
is a field" is a `def` rather than an `instance`, so if you want to reason about a field of
fractions `K`, assume `[field K]` instead of just `[comm_ring K]`.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
variables {R : Type*} [comm_ring R] (M : submonoid R) (S : Type*) [comm_ring S]
variables [algebra R S] {P : Type*} [comm_ring P]
open function
open_locale big_operators
/-- The typeclass `is_localization (M : submodule R) S` where `S` is an `R`-algebra
expresses that `S` is isomorphic to the localization of `R` at `M`. -/
class is_localization : Prop :=
(map_units [] : β y : M, is_unit (algebra_map R S y))
(surj [] : β z : S, β x : R Γ M, z * algebra_map R S x.2 = algebra_map R S x.1)
(eq_iff_exists [] : β {x y}, algebra_map R S x = algebra_map R S y β β c : M, x * c = y * c)
variables {M S}
namespace is_localization
section is_localization
variables [is_localization M S]
section
variables (M)
lemma of_le (N : submonoid R) (hβ : M β€ N)
(hβ : β r β N, is_unit (algebra_map R S r)) : is_localization N S :=
{ map_units := Ξ» r, hβ r r.2,
surj := Ξ» s, by { obtain β¨β¨x, y, hyβ©, Hβ© := is_localization.surj M s, exact β¨β¨x, y, hβ hyβ©, Hβ© },
eq_iff_exists := Ξ» x y, begin
split,
{ rw is_localization.eq_iff_exists M,
rintro β¨c, hcβ©,
exact β¨β¨c, hβ c.2β©, hcβ© },
{ rintro β¨c, hβ©,
simpa only [set_like.coe_mk, map_mul, (hβ c c.2).mul_left_inj] using
congr_arg (algebra_map R S) h }
end }
variables (S)
/-- `is_localization.to_localization_map M S` shows `S` is the monoid localization of `R` at `M`. -/
@[simps]
def to_localization_map : submonoid.localization_map M S :=
{ to_fun := algebra_map R S,
map_units' := is_localization.map_units _,
surj' := is_localization.surj _,
eq_iff_exists' := Ξ» _ _, is_localization.eq_iff_exists _ _,
.. algebra_map R S }
@[simp]
lemma to_localization_map_to_map :
(to_localization_map M S).to_map = (algebra_map R S : R β* S) := rfl
lemma to_localization_map_to_map_apply (x) :
(to_localization_map M S).to_map x = algebra_map R S x := rfl
end
section
variables (R)
-- TODO: define a subalgebra of `is_integer`s
/-- Given `a : S`, `S` a localization of `R`, `is_integer R a` iff `a` is in the image of
the localization map from `R` to `S`. -/
def is_integer (a : S) : Prop := a β (algebra_map R S).range
end
lemma is_integer_zero : is_integer R (0 : S) := subring.zero_mem _
lemma is_integer_one : is_integer R (1 : S) := subring.one_mem _
lemma is_integer_add {a b : S} (ha : is_integer R a) (hb : is_integer R b) :
is_integer R (a + b) :=
subring.add_mem _ ha hb
lemma is_integer_mul {a b : S} (ha : is_integer R a) (hb : is_integer R b) :
is_integer R (a * b) :=
subring.mul_mem _ ha hb
lemma is_integer_smul {a : R} {b : S} (hb : is_integer R b) :
is_integer R (a β’ b) :=
begin
rcases hb with β¨b', hbβ©,
use a * b',
rw [βhb, (algebra_map R S).map_mul, algebra.smul_def]
end
variables (M)
/-- Each element `a : S` has an `M`-multiple which is an integer.
This version multiplies `a` on the right, matching the argument order in `localization_map.surj`.
-/
lemma exists_integer_multiple' (a : S) :
β (b : M), is_integer R (a * algebra_map R S b) :=
let β¨β¨num, denomβ©, hβ© := is_localization.surj _ a in β¨denom, set.mem_range.mpr β¨num, h.symmβ©β©
/-- Each element `a : S` has an `M`-multiple which is an integer.
This version multiplies `a` on the left, matching the argument order in the `has_scalar` instance.
-/
lemma exists_integer_multiple (a : S) :
β (b : M), is_integer R ((b : R) β’ a) :=
by { simp_rw [algebra.smul_def, mul_comm _ a], apply exists_integer_multiple' }
/-- Given a localization map `f : M β* N`, a section function sending `z : N` to some
`(x, y) : M Γ S` such that `f x * (f y)β»ΒΉ = z`. -/
noncomputable def sec (z : S) : R Γ M :=
classical.some $ is_localization.surj _ z
@[simp] lemma to_localization_map_sec : (to_localization_map M S).sec = sec M := rfl
/-- Given `z : S`, `is_localization.sec M z` is defined to be a pair `(x, y) : R Γ M` such
that `z * f y = f x` (so this lemma is true by definition). -/
lemma sec_spec (z : S) :
z * algebra_map R S (is_localization.sec M z).2 =
algebra_map R S (is_localization.sec M z).1 :=
classical.some_spec $ is_localization.surj _ z
/-- Given `z : S`, `is_localization.sec M z` is defined to be a pair `(x, y) : R Γ M` such
that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/
lemma sec_spec' (z : S) :
algebra_map R S (is_localization.sec M z).1 =
algebra_map R S (is_localization.sec M z).2 * z :=
by rw [mul_comm, sec_spec]
open_locale big_operators
/-- We can clear the denominators of a `finset`-indexed family of fractions. -/
lemma exist_integer_multiples {ΞΉ : Type*} (s : finset ΞΉ) (f : ΞΉ β S) :
β (b : M), β i β s, is_localization.is_integer R ((b : R) β’ f i) :=
begin
haveI := classical.prop_decidable,
refine β¨β i in s, (sec M (f i)).2, Ξ» i hi, β¨_, _β©β©,
{ exact (β j in s.erase i, (sec M (f j)).2) * (sec M (f i)).1 },
rw [ring_hom.map_mul, sec_spec', βmul_assoc, β(algebra_map R S).map_mul, β algebra.smul_def],
congr' 2,
refine trans _ ((submonoid.subtype M).map_prod _ _).symm,
rw [mul_comm, βfinset.prod_insert (s.not_mem_erase i), finset.insert_erase hi],
refl
end
/-- We can clear the denominators of a `fintype`-indexed family of fractions. -/
lemma exist_integer_multiples_of_fintype {ΞΉ : Type*} [fintype ΞΉ] (f : ΞΉ β S) :
β (b : M), β i, is_localization.is_integer R ((b : R) β’ f i) :=
begin
obtain β¨b, hbβ© := exist_integer_multiples M finset.univ f,
exact β¨b, Ξ» i, hb i (finset.mem_univ _)β©
end
/-- We can clear the denominators of a finite set of fractions. -/
lemma exist_integer_multiples_of_finset (s : finset S) :
β (b : M), β a β s, is_integer R ((b : R) β’ a) :=
exist_integer_multiples M s id
/-- A choice of a common multiple of the denominators of a `finset`-indexed family of fractions. -/
noncomputable
def common_denom {ΞΉ : Type*} (s : finset ΞΉ) (f : ΞΉ β S) : M :=
(exist_integer_multiples M s f).some
/-- The numerator of a fraction after clearing the denominators
of a `finset`-indexed family of fractions. -/
noncomputable
def integer_multiple {ΞΉ : Type*} (s : finset ΞΉ) (f : ΞΉ β S) (i : s) : R :=
((exist_integer_multiples M s f).some_spec i i.prop).some
@[simp]
lemma map_integer_multiple {ΞΉ : Type*} (s : finset ΞΉ) (f : ΞΉ β S) (i : s) :
algebra_map R S (integer_multiple M s f i) = common_denom M s f β’ f i :=
((exist_integer_multiples M s f).some_spec _ i.prop).some_spec
/-- A choice of a common multiple of the denominators of a finite set of fractions. -/
noncomputable
def common_denom_of_finset (s : finset S) : M :=
common_denom M s id
/-- The finset of numerators after clearing the denominators of a finite set of fractions. -/
noncomputable
def finset_integer_multiple [decidable_eq R] (s : finset S) : finset R :=
s.attach.image (Ξ» t, integer_multiple M s id t)
open_locale pointwise
lemma finset_integer_multiple_image [decidable_eq R] (s : finset S) :
algebra_map R S '' (finset_integer_multiple M s) =
common_denom_of_finset M s β’ s :=
begin
delta finset_integer_multiple common_denom,
rw finset.coe_image,
ext,
split,
{ rintro β¨_, β¨x, -, rflβ©, rflβ©,
rw map_integer_multiple,
exact set.mem_image_of_mem _ x.prop },
{ rintro β¨x, hx, rflβ©,
exact β¨_, β¨β¨x, hxβ©, s.mem_attach _, rflβ©, map_integer_multiple M s id _β© }
end
variables {R M}
lemma map_right_cancel {x y} {c : M} (h : algebra_map R S (c * x) = algebra_map R S (c * y)) :
algebra_map R S x = algebra_map R S y :=
(to_localization_map M S).map_right_cancel h
lemma map_left_cancel {x y} {c : M} (h : algebra_map R S (x * c) = algebra_map R S (y * c)) :
algebra_map R S x = algebra_map R S y :=
(to_localization_map M S).map_left_cancel h
lemma eq_zero_of_fst_eq_zero {z x} {y : M}
(h : z * algebra_map R S y = algebra_map R S x) (hx : x = 0) : z = 0 :=
by { rw [hx, (algebra_map R S).map_zero] at h,
exact (is_unit.mul_left_eq_zero (is_localization.map_units S y)).1 h}
variables (M S)
lemma map_eq_zero_iff (r : R) :
algebra_map R S r = 0 β β m : M, r * m = 0 :=
begin
split,
intro h,
{ obtain β¨m, hmβ© := (is_localization.eq_iff_exists M S).mp
((algebra_map R S).map_zero.trans h.symm),
exact β¨m, by simpa using hm.symmβ© },
{ rintro β¨m, hmβ©,
rw [β (is_localization.map_units S m).mul_left_inj, zero_mul, β ring_hom.map_mul, hm,
ring_hom.map_zero] }
end
variables {M}
/-- `is_localization.mk' S` is the surjection sending `(x, y) : R Γ M` to
`f x * (f y)β»ΒΉ`. -/
noncomputable def mk' (x : R) (y : M) : S :=
(to_localization_map M S).mk' x y
@[simp] lemma mk'_sec (z : S) :
mk' S (is_localization.sec M z).1 (is_localization.sec M z).2 = z :=
(to_localization_map M S).mk'_sec _
lemma mk'_mul (xβ xβ : R) (yβ yβ : M) :
mk' S (xβ * xβ) (yβ * yβ) = mk' S xβ yβ * mk' S xβ yβ :=
(to_localization_map M S).mk'_mul _ _ _ _
lemma mk'_one (x) : mk' S x (1 : M) = algebra_map R S x :=
(to_localization_map M S).mk'_one _
@[simp]
lemma mk'_spec (x) (y : M) :
mk' S x y * algebra_map R S y = algebra_map R S x :=
(to_localization_map M S).mk'_spec _ _
@[simp]
lemma mk'_spec' (x) (y : M) :
algebra_map R S y * mk' S x y = algebra_map R S x :=
(to_localization_map M S).mk'_spec' _ _
@[simp]
lemma mk'_spec_mk (x) (y : R) (hy : y β M) :
mk' S x β¨y, hyβ© * algebra_map R S y = algebra_map R S x :=
mk'_spec S x β¨y, hyβ©
@[simp]
lemma mk'_spec'_mk (x) (y : R) (hy : y β M) :
algebra_map R S y * mk' S x β¨y, hyβ© = algebra_map R S x :=
mk'_spec' S x β¨y, hyβ©
variables {S}
theorem eq_mk'_iff_mul_eq {x} {y : M} {z} :
z = mk' S x y β z * algebra_map R S y = algebra_map R S x :=
(to_localization_map M S).eq_mk'_iff_mul_eq
theorem mk'_eq_iff_eq_mul {x} {y : M} {z} :
mk' S x y = z β algebra_map R S x = z * algebra_map R S y :=
(to_localization_map M S).mk'_eq_iff_eq_mul
variables (M)
lemma mk'_surjective (z : S) : β x (y : M), mk' S x y = z :=
let β¨r, hrβ© := is_localization.surj _ z in β¨r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symmβ©
variables {M}
lemma mk'_eq_iff_eq {xβ xβ} {yβ yβ : M} :
mk' S xβ yβ = mk' S xβ yβ β algebra_map R S (xβ * yβ) = algebra_map R S (xβ * yβ) :=
(to_localization_map M S).mk'_eq_iff_eq
lemma mk'_mem_iff {x} {y : M} {I : ideal S} : mk' S x y β I β algebra_map R S x β I :=
begin
split;
intro h,
{ rw [β mk'_spec S x y, mul_comm],
exact I.mul_mem_left ((algebra_map R S) y) h },
{ rw β mk'_spec S x y at h,
obtain β¨b, hbβ© := is_unit_iff_exists_inv.1 (map_units S y),
have := I.mul_mem_left b h,
rwa [mul_comm, mul_assoc, hb, mul_one] at this }
end
protected lemma eq {aβ bβ} {aβ bβ : M} :
mk' S aβ aβ = mk' S bβ bβ β β c : M, aβ * bβ * c = bβ * aβ * c :=
(to_localization_map M S).eq
lemma mk'_eq_zero_iff (x : R) (s : M) :
mk' S x s = 0 β β (m : M), x * m = 0 :=
by rw [β (map_units S s).mul_left_inj, mk'_spec, zero_mul, map_eq_zero_iff M]
section ext
variables [algebra R P] [is_localization M P]
lemma eq_iff_eq {x y} :
algebra_map R S x = algebra_map R S y β algebra_map R P x = algebra_map R P y :=
(to_localization_map M S).eq_iff_eq (to_localization_map M P)
lemma mk'_eq_iff_mk'_eq {xβ xβ}
{yβ yβ : M} : mk' S xβ yβ = mk' S xβ yβ β mk' P xβ yβ = mk' P xβ yβ :=
(to_localization_map M S).mk'_eq_iff_mk'_eq (to_localization_map M P)
lemma mk'_eq_of_eq {aβ bβ : R} {aβ bβ : M} (H : bβ * aβ = aβ * bβ) :
mk' S aβ aβ = mk' S bβ bβ :=
(to_localization_map M S).mk'_eq_of_eq H
variables (S)
@[simp] lemma mk'_self {x : R} (hx : x β M) : mk' S x β¨x, hxβ© = 1 :=
(to_localization_map M S).mk'_self _ hx
@[simp] lemma mk'_self' {x : M} : mk' S (x : R) x = 1 :=
(to_localization_map M S).mk'_self' _
lemma mk'_self'' {x : M} : mk' S x.1 x = 1 :=
mk'_self' _
end ext
lemma mul_mk'_eq_mk'_of_mul (x y : R) (z : M) :
(algebra_map R S) x * mk' S y z = mk' S (x * y) z :=
(to_localization_map M S).mul_mk'_eq_mk'_of_mul _ _ _
lemma mk'_eq_mul_mk'_one (x : R) (y : M) :
mk' S x y = (algebra_map R S) x * mk' S 1 y :=
((to_localization_map M S).mul_mk'_one_eq_mk' _ _).symm
@[simp] lemma mk'_mul_cancel_left (x : R) (y : M) :
mk' S (y * x : R) y = (algebra_map R S) x :=
(to_localization_map M S).mk'_mul_cancel_left _ _
lemma mk'_mul_cancel_right (x : R) (y : M) :
mk' S (x * y) y = (algebra_map R S) x :=
(to_localization_map M S).mk'_mul_cancel_right _ _
@[simp] lemma mk'_mul_mk'_eq_one (x y : M) :
mk' S (x : R) y * mk' S (y : R) x = 1 :=
by rw [βmk'_mul, mul_comm]; exact mk'_self _ _
lemma mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x β M) :
mk' S x y * mk' S (y : R) β¨x, hβ© = 1 :=
mk'_mul_mk'_eq_one β¨x, hβ© _
section
variables (M)
lemma is_unit_comp (j : S β+* P) (y : M) :
is_unit (j.comp (algebra_map R S) y) :=
(to_localization_map M S).is_unit_comp j.to_monoid_hom _
end
/-- Given a localization map `f : R β+* S` for a submonoid `M β R` and a map of `comm_ring`s
`g : R β+* P` such that `g(M) β units P`, `f x = f y β g x = g y` for all `x y : R`. -/
lemma eq_of_eq {g : R β+* P} (hg : β y : M, is_unit (g y)) {x y}
(h : (algebra_map R S) x = (algebra_map R S) y) :
g x = g y :=
@submonoid.localization_map.eq_of_eq _ _ _ _ _ _ _
(to_localization_map M S) g.to_monoid_hom hg _ _ h
lemma mk'_add (xβ xβ : R) (yβ yβ : M) :
mk' S (xβ * yβ + xβ * yβ) (yβ * yβ) = mk' S xβ yβ + mk' S xβ yβ :=
mk'_eq_iff_eq_mul.2 $ eq.symm
begin
rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, βeq_sub_iff_add_eq, mk'_eq_iff_eq_mul,
mul_comm _ ((algebra_map R S) _), mul_sub, eq_sub_iff_add_eq, βeq_sub_iff_add_eq', βmul_assoc,
β(algebra_map R S).map_mul, mul_mk'_eq_mk'_of_mul, mk'_eq_iff_eq_mul],
simp only [(algebra_map R S).map_add, submonoid.coe_mul, (algebra_map R S).map_mul],
ring_exp,
end
/-- Given a localization map `f : R β+* S` for a submonoid `M β R` and a map of `comm_ring`s
`g : R β+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from
`S` to `P` sending `z : S` to `g x * (g y)β»ΒΉ`, where `(x, y) : R Γ M` are such that
`z = f x * (f y)β»ΒΉ`. -/
noncomputable def lift {g : R β+* P} (hg : β y : M, is_unit (g y)) : S β+* P :=
ring_hom.mk' (@submonoid.localization_map.lift _ _ _ _ _ _ _
(to_localization_map M S) g.to_monoid_hom hg) $
begin
intros x y,
rw [(to_localization_map M S).lift_spec, mul_comm, add_mul, βsub_eq_iff_eq_add, eq_comm,
(to_localization_map M S).lift_spec_mul, mul_comm _ (_ - _), sub_mul, eq_sub_iff_add_eq',
βeq_sub_iff_add_eq, mul_assoc, (to_localization_map M S).lift_spec_mul],
show g _ * (g _ * g _) = g _ * (g _ * g _ - g _ * g _),
simp only [β g.map_sub, β g.map_mul, to_localization_map_sec],
apply eq_of_eq hg,
rw [(algebra_map R S).map_mul, sec_spec', mul_sub, (algebra_map R S).map_sub],
simp only [ring_hom.map_mul, sec_spec'],
ring,
assumption
end
variables {g : R β+* P} (hg : β y : M, is_unit (g y))
/-- Given a localization map `f : R β+* S` for a submonoid `M β R` and a map of `comm_ring`s
`g : R β* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from
`S` to `P` maps `f x * (f y)β»ΒΉ` to `g x * (g y)β»ΒΉ` for all `x : R, y β M`. -/
lemma lift_mk' (x y) :
lift hg (mk' S x y) = g x * β(is_unit.lift_right (g.to_monoid_hom.mrestrict M) hg y)β»ΒΉ :=
(to_localization_map M S).lift_mk' _ _ _
lemma lift_mk'_spec (x v) (y : M) :
lift hg (mk' S x y) = v β g x = g y * v :=
(to_localization_map M S).lift_mk'_spec _ _ _ _
@[simp] lemma lift_eq (x : R) :
lift hg ((algebra_map R S) x) = g x :=
(to_localization_map M S).lift_eq _ _
lemma lift_eq_iff {x y : R Γ M} :
lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) β g (x.1 * y.2) = g (y.1 * x.2) :=
(to_localization_map M S).lift_eq_iff _
@[simp] lemma lift_comp : (lift hg).comp (algebra_map R S) = g :=
ring_hom.ext $ monoid_hom.ext_iff.1 $ (to_localization_map M S).lift_comp _
@[simp] lemma lift_of_comp (j : S β+* P) :
lift (is_unit_comp M j) = j :=
ring_hom.ext $ monoid_hom.ext_iff.1 $ (to_localization_map M S).lift_of_comp j.to_monoid_hom
variables (M)
/-- See note [partially-applied ext lemmas] -/
lemma monoid_hom_ext β¦j k : S β* Pβ¦
(h : j.comp (algebra_map R S : R β* S) = k.comp (algebra_map R S)) : j = k :=
submonoid.localization_map.epic_of_localization_map (to_localization_map M S) $
monoid_hom.congr_fun h
/-- See note [partially-applied ext lemmas] -/
lemma ring_hom_ext β¦j k : S β+* Pβ¦
(h : j.comp (algebra_map R S) = k.comp (algebra_map R S)) : j = k :=
ring_hom.coe_monoid_hom_injective $ monoid_hom_ext M $ monoid_hom.ext $ ring_hom.congr_fun h
/-- To show `j` and `k` agree on the whole localization, it suffices to show they agree
on the image of the base ring, if they preserve `1` and `*`. -/
protected lemma ext (j k : S β P) (hj1 : j 1 = 1) (hk1 : k 1 = 1)
(hjm : β a b, j (a * b) = j a * j b) (hkm : β a b, k (a * b) = k a * k b)
(h : β a, j (algebra_map R S a) = k (algebra_map R S a)) : j = k :=
monoid_hom.mk.inj (monoid_hom_ext M $ monoid_hom.ext h : (β¨j, hj1, hjmβ© : S β* P) = β¨k, hk1, hkmβ©)
variables {M}
lemma lift_unique {j : S β+* P}
(hj : β x, j ((algebra_map R S) x) = g x) : lift hg = j :=
ring_hom.ext $ monoid_hom.ext_iff.1 $ @submonoid.localization_map.lift_unique
_ _ _ _ _ _ _ (to_localization_map M S) g.to_monoid_hom hg j.to_monoid_hom hj
@[simp] lemma lift_id (x) : lift (map_units S : β y : M, is_unit _) x = x :=
(to_localization_map M S).lift_id _
lemma lift_surjective_iff :
surjective (lift hg : S β P) β β v : P, β x : R Γ M, v * g x.2 = g x.1 :=
(to_localization_map M S).lift_surjective_iff hg
lemma lift_injective_iff :
injective (lift hg : S β P) β β x y, algebra_map R S x = algebra_map R S y β g x = g y :=
(to_localization_map M S).lift_injective_iff hg
section map
variables {T : submonoid P} {Q : Type*} [comm_ring Q] (hy : M β€ T.comap g)
variables [algebra P Q] [is_localization T Q]
section
variables (Q)
/-- Map a homomorphism `g : R β+* P` to `S β+* Q`, where `S` and `Q` are
localizations of `R` and `P` at `M` and `T` respectively,
such that `g(M) β T`.
We send `z : S` to `algebra_map P Q (g x) * (algebra_map P Q (g y))β»ΒΉ`, where
`(x, y) : R Γ M` are such that `z = f x * (f y)β»ΒΉ`. -/
noncomputable def map (g : R β+* P) (hy : M β€ T.comap g) : S β+* Q :=
@lift R _ M _ _ _ _ _ _ ((algebra_map P Q).comp g) (Ξ» y, map_units _ β¨g y, hy y.2β©)
end
lemma map_eq (x) :
map Q g hy ((algebra_map R S) x) = algebra_map P Q (g x) :=
lift_eq (Ξ» y, map_units _ β¨g y, hy y.2β©) x
@[simp] lemma map_comp :
(map Q g hy).comp (algebra_map R S) = (algebra_map P Q).comp g :=
lift_comp $ Ξ» y, map_units _ β¨g y, hy y.2β©
lemma map_mk' (x) (y : M) :
map Q g hy (mk' S x y) = mk' Q (g x) β¨g y, hy y.2β© :=
@submonoid.localization_map.map_mk' _ _ _ _ _ _ _ (to_localization_map M S)
g.to_monoid_hom _ (Ξ» y, hy y.2) _ _ (to_localization_map T Q) _ _
@[simp] lemma map_id (z : S) (h : M β€ M.comap (ring_hom.id R) := le_refl M) :
map S (ring_hom.id _) h z = z :=
lift_id _
lemma map_unique (j : S β+* Q)
(hj : β x : R, j (algebra_map R S x) = algebra_map P Q (g x)) : map Q g hy = j :=
lift_unique (Ξ» y, map_units _ β¨g y, hy y.2β©) hj
/-- If `comm_ring` homs `g : R β+* P, l : P β+* A` induce maps of localizations, the composition
of the induced maps equals the map of localizations induced by `l β g`. -/
lemma map_comp_map {A : Type*} [comm_ring A] {U : submonoid A} {W} [comm_ring W]
[algebra A W] [is_localization U W] {l : P β+* A} (hl : T β€ U.comap l) :
(map W l hl).comp (map Q g hy : S β+* _) = map W (l.comp g) (Ξ» x hx, hl (hy hx)) :=
ring_hom.ext $ Ξ» x, @submonoid.localization_map.map_map _ _ _ _ _ P _ (to_localization_map M S) g _
_ _ _ _ _ _ _ _ _ (to_localization_map U W) l _ x
/-- If `comm_ring` homs `g : R β+* P, l : P β+* A` induce maps of localizations, the composition
of the induced maps equals the map of localizations induced by `l β g`. -/
lemma map_map {A : Type*} [comm_ring A] {U : submonoid A} {W} [comm_ring W]
[algebra A W] [is_localization U W] {l : P β+* A} (hl : T β€ U.comap l) (x : S) :
map W l hl (map Q g hy x) = map W (l.comp g) (Ξ» x hx, hl (hy hx)) x :=
by rw βmap_comp_map hy hl; refl
section
variables (S Q)
/-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M, T` respectively, an
isomorphism `j : R β+* P` such that `j(M) = T` induces an isomorphism of localizations
`S β+* Q`. -/
@[simps]
noncomputable def ring_equiv_of_ring_equiv (h : R β+* P) (H : M.map h.to_monoid_hom = T) :
S β+* Q :=
have H' : T.map h.symm.to_monoid_hom = M,
by { rw [β M.map_id, β H, submonoid.map_map], congr, ext, apply h.symm_apply_apply },
{ to_fun := map Q (h : R β+* P) (M.le_comap_of_map_le (le_of_eq H)),
inv_fun := map S (h.symm : P β+* R) (T.le_comap_of_map_le (le_of_eq H')),
left_inv := Ξ» x, by { rw [map_map, map_unique _ (ring_hom.id _), ring_hom.id_apply],
intro x, convert congr_arg (algebra_map R S) (h.symm_apply_apply x).symm },
right_inv := Ξ» x, by { rw [map_map, map_unique _ (ring_hom.id _), ring_hom.id_apply],
intro x, convert congr_arg (algebra_map P Q) (h.apply_symm_apply x).symm },
.. map Q (h : R β+* P) _ }
end
lemma ring_equiv_of_ring_equiv_eq_map {j : R β+* P} (H : M.map j.to_monoid_hom = T) :
(ring_equiv_of_ring_equiv S Q j H : S β+* Q) =
map Q (j : R β+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl
@[simp] lemma ring_equiv_of_ring_equiv_eq {j : R β+* P} (H : M.map j.to_monoid_hom = T) (x) :
ring_equiv_of_ring_equiv S Q j H ((algebra_map R S) x) = algebra_map P Q (j x) :=
map_eq _ _
lemma ring_equiv_of_ring_equiv_mk' {j : R β+* P} (H : M.map j.to_monoid_hom = T) (x : R) (y : M) :
ring_equiv_of_ring_equiv S Q j H (mk' S x y) =
mk' Q (j x) β¨j y, show j y β T, from H βΈ set.mem_image_of_mem j y.2β© :=
map_mk' _ _ _
end map
section alg_equiv
variables {Q : Type*} [comm_ring Q] [algebra R Q] [is_localization M Q]
section
variables (M S Q)
/-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively,
there is an isomorphism of localizations `S ββ[R] Q`. -/
@[simps]
noncomputable def alg_equiv : S ββ[R] Q :=
{ commutes' := ring_equiv_of_ring_equiv_eq _,
.. ring_equiv_of_ring_equiv S Q (ring_equiv.refl R) M.map_id }
end
@[simp]
lemma alg_equiv_mk' (x : R) (y : M) : alg_equiv M S Q (mk' S x y) = mk' Q x y:=
map_mk' _ _ _
@[simp]
lemma alg_equiv_symm_mk' (x : R) (y : M) : (alg_equiv M S Q).symm (mk' Q x y) = mk' S x y:=
map_mk' _ _ _
end alg_equiv
end is_localization
section
variables (M)
lemma is_localization_of_alg_equiv [algebra R P] [is_localization M S] (h : S ββ[R] P) :
is_localization M P :=
begin
constructor,
{ intro y,
convert (is_localization.map_units S y).map h.to_alg_hom.to_ring_hom.to_monoid_hom,
exact (h.commutes y).symm },
{ intro y,
obtain β¨β¨x, sβ©, eβ© := is_localization.surj M (h.symm y),
apply_fun h at e,
simp only [h.map_mul, h.apply_symm_apply, h.commutes] at e,
exact β¨β¨x, sβ©, eβ© },
{ intros x y,
rw [β h.symm.to_equiv.injective.eq_iff, β is_localization.eq_iff_exists M S,
β h.symm.commutes, β h.symm.commutes],
refl }
end
lemma is_localization_iff_of_alg_equiv [algebra R P] (h : S ββ[R] P) :
is_localization M S β is_localization M P :=
β¨Ξ» _, by exactI is_localization_of_alg_equiv M h,
Ξ» _, by exactI is_localization_of_alg_equiv M h.symmβ©
lemma is_localization_iff_of_ring_equiv (h : S β+* P) :
is_localization M S β
@@is_localization _ M P _ (h.to_ring_hom.comp $ algebra_map R S).to_algebra :=
begin
letI := (h.to_ring_hom.comp $ algebra_map R S).to_algebra,
exact is_localization_iff_of_alg_equiv M { commutes' := Ξ» _, rfl, ..h },
end
variable (S)
lemma is_localization_of_base_ring_equiv [is_localization M S] (h : R β+* P) :
@@is_localization _ (M.map h.to_monoid_hom) S _
((algebra_map R S).comp h.symm.to_ring_hom).to_algebra :=
begin
constructor,
{ rintros β¨_, β¨y, hy, rflβ©β©,
convert is_localization.map_units S β¨y, hyβ©,
dsimp only [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply],
exact congr_arg _ (h.symm_apply_apply _) },
{ intro y,
obtain β¨β¨x, sβ©, eβ© := is_localization.surj M y,
refine β¨β¨h x, _, _, s.prop, rflβ©, _β©,
dsimp only [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply] at β’ e,
convert e; exact h.symm_apply_apply _ },
{ intros x y,
rw [ring_hom.algebra_map_to_algebra, ring_hom.comp_apply, ring_hom.comp_apply,
is_localization.eq_iff_exists M S],
simp_rw β h.to_equiv.apply_eq_iff_eq,
change (β (c : M), h (h.symm x * c) = h (h.symm y * c)) β _,
simp only [ring_equiv.apply_symm_apply, ring_equiv.map_mul],
exact β¨Ξ» β¨c, eβ©, β¨β¨_, _, c.prop, rflβ©, eβ©, Ξ» β¨β¨_, c, h, eββ©, eββ©, β¨β¨_, hβ©, eβ.symm βΈ eββ©β© }
end
lemma is_localization_iff_of_base_ring_equiv (h : R β+* P) :
is_localization M S β @@is_localization _ (M.map h.to_monoid_hom) S _
((algebra_map R S).comp h.symm.to_ring_hom).to_algebra :=
begin
refine β¨Ξ» _, by exactI is_localization_of_base_ring_equiv _ _ h, _β©,
letI := ((algebra_map R S).comp h.symm.to_ring_hom).to_algebra,
intro H,
convert @@is_localization_of_base_ring_equiv _ _ _ _ _ _ H h.symm,
{ erw [submonoid.map_equiv_eq_comap_symm, submonoid.comap_map_eq_of_injective],
exact h.to_equiv.injective },
rw [ring_hom.algebra_map_to_algebra, ring_hom.comp_assoc],
simp only [ring_hom.comp_id, ring_equiv.symm_symm, ring_equiv.symm_to_ring_hom_comp_to_ring_hom],
apply algebra.algebra_ext,
intro r,
rw ring_hom.algebra_map_to_algebra
end
end
section away
variables (x : R)
/-- Given `x : R`, the typeclass `is_localization.away x S` states that `S` is
isomorphic to the localization of `R` at the submonoid generated by `x`. -/
abbreviation away (S : Type*) [comm_ring S] [algebra R S] :=
is_localization (submonoid.powers x) S
namespace away
variables [is_localization.away x S]
/-- Given `x : R` and a localization map `F : R β+* S` away from `x`, `inv_self` is `(F x)β»ΒΉ`. -/
noncomputable def inv_self : S :=
mk' S (1 : R) β¨x, submonoid.mem_powers _β©
variables {g : R β+* P}
/-- Given `x : R`, a localization map `F : R β+* S` away from `x`, and a map of `comm_ring`s
`g : R β+* P` such that `g x` is invertible, the homomorphism induced from `S` to `P` sending
`z : S` to `g y * (g x)β»βΏ`, where `y : R, n : β` are such that `z = F y * (F x)β»βΏ`. -/
noncomputable def lift (hg : is_unit (g x)) : S β+* P :=
is_localization.lift $ Ξ» (y : submonoid.powers x), show is_unit (g y.1),
begin
obtain β¨n, hnβ© := y.2,
rw [βhn, g.map_pow],
exact is_unit.map (pow_monoid_hom n) hg,
end
@[simp] lemma away_map.lift_eq (hg : is_unit (g x)) (a : R) :
lift x hg ((algebra_map R S) a) = g a := lift_eq _ _
@[simp] lemma away_map.lift_comp (hg : is_unit (g x)) :
(lift x hg).comp (algebra_map R S) = g := lift_comp _
/-- Given `x y : R` and localizations `S`, `P` away from `x` and `x * y`
respectively, the homomorphism induced from `S` to `P`. -/
noncomputable def away_to_away_right (y : R) [algebra R P] [is_localization.away (x * y) P] :
S β+* P :=
lift x $ show is_unit ((algebra_map R P) x), from
is_unit_of_mul_eq_one ((algebra_map R P) x) (mk' P y β¨x * y, submonoid.mem_powers _β©) $
by rw [mul_mk'_eq_mk'_of_mul, mk'_self]
variables (S) (Q : Type*) [comm_ring Q] [algebra P Q]
/-- Given a map `f : R β+* S` and an element `r : R`, we may construct a map `Rα΅£ β+* Sα΅£`. -/
noncomputable
def map (f : R β+* P) (r : R) [is_localization.away r S]
[is_localization.away (f r) Q] : S β+* Q :=
is_localization.map Q f
(show submonoid.powers r β€ (submonoid.powers (f r)).comap f,
by { rintros x β¨n, rflβ©, use n, simp })
end away
end away
section inv_submonoid
variables (M S)
/-- The submonoid of `S = Mβ»ΒΉR` consisting of `{ 1 / x | x β M }`. -/
def inv_submonoid : submonoid S := (M.map (algebra_map R S : R β* S)).left_inv
variable [is_localization M S]
lemma submonoid_map_le_is_unit : M.map (algebra_map R S : R β* S) β€ is_unit.submonoid S :=
by { rintros _ β¨a, ha, rflβ©, exact is_localization.map_units S β¨_, haβ© }
/-- There is an equivalence of monoids between the image of `M` and `inv_submonoid`. -/
noncomputable
abbreviation equiv_inv_submonoid : M.map (algebra_map R S : R β* S) β* inv_submonoid M S :=
((M.map (algebra_map R S : R β* S)).left_inv_equiv (submonoid_map_le_is_unit M S)).symm
/-- There is a canonical map from `M` to `inv_submonoid` sending `x` to `1 / x`. -/
noncomputable
def to_inv_submonoid : M β* inv_submonoid M S :=
(equiv_inv_submonoid M S).to_monoid_hom.comp ((algebra_map R S : R β* S).submonoid_map M)
lemma to_inv_submonoid_surjective : function.surjective (to_inv_submonoid M S) :=
function.surjective.comp (equiv.surjective _) (monoid_hom.submonoid_map_surjective _ _)
@[simp]
lemma to_inv_submonoid_mul (m : M) : (to_inv_submonoid M S m : S) * (algebra_map R S m) = 1 :=
submonoid.left_inv_equiv_symm_mul _ _ _
@[simp]
lemma mul_to_inv_submonoid (m : M) : (algebra_map R S m) * (to_inv_submonoid M S m : S) = 1 :=
submonoid.mul_left_inv_equiv_symm _ _ β¨_, _β©
@[simp]
lemma smul_to_inv_submonoid (m : M) : m β’ (to_inv_submonoid M S m : S) = 1 :=
by { convert mul_to_inv_submonoid M S m, rw β algebra.smul_def, refl }
variables {S}
lemma surj' (z : S) : β (r : R) (m : M), z = r β’ to_inv_submonoid M S m :=
begin
rcases is_localization.surj M z with β¨β¨r, mβ©, e : z * _ = algebra_map R S rβ©,
refine β¨r, m, _β©,
rw [algebra.smul_def, β e, mul_assoc],
simp,
end
lemma to_inv_submonoid_eq_mk' (x : M) :
(to_inv_submonoid M S x : S) = mk' S 1 x :=
by { rw β (is_localization.map_units S x).mul_left_inj, simp }
lemma mem_inv_submonoid_iff_exists_mk' (x : S) :
x β inv_submonoid M S β β m : M, mk' S 1 m = x :=
begin
simp_rw β to_inv_submonoid_eq_mk',
exact β¨Ξ» h, β¨_, congr_arg subtype.val (to_inv_submonoid_surjective M S β¨x, hβ©).some_specβ©,
Ξ» h, h.some_spec βΈ (to_inv_submonoid M S h.some).propβ©
end
variables (S)
lemma span_inv_submonoid : submodule.span R (inv_submonoid M S : set S) = β€ :=
begin
rw eq_top_iff,
rintros x -,
rcases is_localization.surj' M x with β¨r, m, rflβ©,
exact submodule.smul_mem _ _ (submodule.subset_span (to_inv_submonoid M S m).prop),
end
lemma finite_type_of_monoid_fg [monoid.fg M] : algebra.finite_type R S :=
begin
have := monoid.fg_of_surjective _ (to_inv_submonoid_surjective M S),
rw monoid.fg_iff_submonoid_fg at this,
rcases this with β¨s, hsβ©,
refine β¨β¨s, _β©β©,
rw eq_top_iff,
rintro x -,
change x β ((algebra.adjoin R _ : subalgebra R S).to_submodule : set S),
rw [algebra.adjoin_eq_span, hs, span_inv_submonoid],
trivial
end
end inv_submonoid
variables (M S)
include M
lemma non_zero_divisors_le_comap [is_localization M S] :
non_zero_divisors R β€ (non_zero_divisors S).comap (algebra_map R S) :=
begin
rintros a ha b (e : b * algebra_map R S a = 0),
obtain β¨x, s, rflβ© := mk'_surjective M b,
rw [β @mk'_one R _ M, β mk'_mul, β (algebra_map R S).map_zero, β @mk'_one R _ M,
is_localization.eq] at e,
obtain β¨c, eβ© := e,
rw [zero_mul, zero_mul, submonoid.coe_one, mul_one, mul_comm x a, mul_assoc, mul_comm] at e,
rw mk'_eq_zero_iff,
exact β¨c, ha _ eβ©
end
lemma map_non_zero_divisors_le [is_localization M S] :
(non_zero_divisors R).map (algebra_map R S).to_monoid_hom β€ non_zero_divisors S :=
submonoid.map_le_iff_le_comap.mpr (non_zero_divisors_le_comap M S)
end is_localization
namespace localization
open is_localization
/-! ### Constructing a localization at a given submonoid -/
variables {M}
section
instance [subsingleton R] : subsingleton (localization M) :=
β¨Ξ» a b, by { induction a, induction b, congr, refl, refl }β©
/-- Addition in a ring localization is defined as `β¨a, bβ© + β¨c, dβ© = β¨b * c + d * a, b * dβ©`.
Should not be confused with `add_localization.add`, which is defined as
`β¨a, bβ© + β¨c, dβ© = β¨a + c, b + dβ©`.
-/
@[irreducible] protected def add (z w : localization M) : localization M :=
localization.lift_onβ z w
(Ξ» a b c d, mk ((b : R) * c + d * a) (b * d)) $
Ξ» a a' b b' c c' d d' h1 h2, mk_eq_mk_iff.2
begin
rw r_eq_r' at h1 h2 β’,
cases h1 with tβ
htβ
,
cases h2 with tβ htβ,
use tβ * tβ
,
calc ((b : R) * c + d * a) * (b' * d') * (tβ * tβ
) =
(c * d' * tβ) * (b * b' * tβ
) + (a * b' * tβ
) * (d * d' * tβ) : by ring
... = (b' * c' + d' * a') * (b * d) * (tβ * tβ
) : by rw [htβ, htβ
]; ring
end
instance : has_add (localization M) := β¨localization.addβ©
lemma add_mk (a b c d) : (mk a b : localization M) + mk c d = mk (b * c + d * a) (b * d) :=
by { unfold has_add.add localization.add, apply lift_onβ_mk }
lemma add_mk_self (a b c) : (mk a b : localization M) + mk c b = mk (a + c) b :=
begin
rw [add_mk, mk_eq_mk_iff, r_eq_r'],
refine (r' M).symm β¨1, _β©,
simp only [submonoid.coe_one, submonoid.coe_mul],
ring
end
/-- Negation in a ring localization is defined as `-β¨a, bβ© = β¨-a, bβ©`. -/
@[irreducible] protected def neg (z : localization M) : localization M :=
localization.lift_on z (Ξ» a b, mk (-a) b) $
Ξ» a b c d h, mk_eq_mk_iff.2
begin
rw r_eq_r' at h β’,
cases h with t ht,
use t,
rw [neg_mul_eq_neg_mul_symm, neg_mul_eq_neg_mul_symm, ht],
ring_nf,
end
instance : has_neg (localization M) := β¨localization.negβ©
lemma neg_mk (a b) : -(mk a b : localization M) = mk (-a) b :=
by { unfold has_neg.neg localization.neg, apply lift_on_mk }
/-- The zero element in a ring localization is defined as `β¨0, 1β©`.
Should not be confused with `add_localization.zero` which is `β¨0, 0β©`. -/
@[irreducible] protected def zero : localization M :=
mk 0 1
instance : has_zero (localization M) := β¨localization.zeroβ©
lemma mk_zero (b) : (mk 0 b : localization M) = 0 :=
calc mk 0 b = mk 0 1 : mk_eq_mk_iff.mpr (r_of_eq (by simp))
... = 0 : by unfold has_zero.zero localization.zero
lemma lift_on_zero {p : Type*} (f : β (a : R) (b : M), p) (H) : lift_on 0 f H = f 0 1 :=
by rw [β mk_zero 1, lift_on_mk]
private meta def tac := `[
{ intros,
simp only [add_mk, localization.mk_mul, neg_mk, β mk_zero 1],
refine mk_eq_mk_iff.mpr (r_of_eq _),
simp only [submonoid.coe_mul, prod.fst_mul, prod.snd_mul],
ring }]
instance : comm_ring (localization M) :=
{ zero := 0,
one := 1,
add := (+),
mul := (*),
npow := localization.npow _,
nsmul := (β’),
nsmul_zero' := Ξ» x, localization.induction_on x
(Ξ» x, by simp only [smul_mk, zero_nsmul, mk_zero]),
nsmul_succ' := Ξ» n x, localization.induction_on x
(Ξ» x, by simp only [smul_mk, succ_nsmul, add_mk_self]),
zsmul := (β’),
zsmul_zero' := Ξ» x, localization.induction_on x
(Ξ» x, by simp only [smul_mk, zero_zsmul, mk_zero]),
zsmul_succ' := Ξ» n x, localization.induction_on x
(Ξ» x, by simp [smul_mk, add_mk_self, -mk_eq_monoid_of_mk', add_comm (n : β€) 1, add_smul]),
zsmul_neg' := Ξ» n x, localization.induction_on x
(Ξ» x, by { rw [smul_mk, smul_mk, neg_mk, β neg_smul], refl }),
add_assoc := Ξ» m n k, localization.induction_onβ m n k (by tac),
zero_add := Ξ» y, localization.induction_on y (by tac),
add_zero := Ξ» y, localization.induction_on y (by tac),
neg := has_neg.neg,
sub := Ξ» x y, x + -y,
sub_eq_add_neg := Ξ» x y, rfl,
add_left_neg := Ξ» y, by exact localization.induction_on y (by tac),
add_comm := Ξ» y z, localization.induction_onβ z y (by tac),
left_distrib := Ξ» m n k, localization.induction_onβ m n k (by tac),
right_distrib := Ξ» m n k, localization.induction_onβ m n k (by tac),
..localization.comm_monoid M }
instance {S : Type*} [monoid S] [distrib_mul_action S R] [is_scalar_tower S R R] :
distrib_mul_action S (localization M) :=
{ smul_zero := Ξ» s, by simp only [βlocalization.mk_zero 1, localization.smul_mk, smul_zero],
smul_add := Ξ» s x y, localization.induction_onβ x y $
prod.rec $ by exact Ξ» rβ xβ, prod.rec $ by exact Ξ» rβ xβ,
by simp only [localization.smul_mk, localization.add_mk, smul_add, mul_comm _ (s β’ _),
mul_comm _ rβ, mul_comm _ rβ, smul_mul_assoc] }
instance {S : Type*} [semiring S] [mul_semiring_action S R] [is_scalar_tower S R R] :
mul_semiring_action S (localization M) :=
{ ..localization.mul_distrib_mul_action }
instance {S : Type*} [semiring S] [module S R] [is_scalar_tower S R R] :
module S (localization M) :=
{ zero_smul := localization.ind $ prod.rec $
by { intros, simp only [localization.smul_mk, zero_smul, mk_zero] },
add_smul := Ξ» sβ sβ, localization.ind $ prod.rec $
by { intros, simp only [localization.smul_mk, add_smul, add_mk_self] },
..localization.distrib_mul_action }
instance {S : Type*} [comm_semiring S] [algebra S R] : algebra S (localization M) :=
{ to_ring_hom :=
ring_hom.comp
{ to_fun := (monoid_of M).to_map,
map_zero' := by rw [β mk_zero (1 : M), mk_one_eq_monoid_of_mk],
map_add' := Ξ» x y,
by simp only [β mk_one_eq_monoid_of_mk, add_mk, submonoid.coe_one, one_mul, add_comm],
.. localization.monoid_of M } (algebra_map S R),
smul_def' := Ξ» s, localization.ind $ prod.rec $ begin
intros r x,
dsimp,
simp only [βmk_one_eq_monoid_of_mk, mk_mul, localization.smul_mk, one_mul, algebra.smul_def],
end,
commutes' := Ξ» s, localization.ind $ prod.rec $ begin
intros r x,
dsimp,
simp only [βmk_one_eq_monoid_of_mk, mk_mul, localization.smul_mk, one_mul, mul_one,
algebra.commutes],
end }
instance : is_localization M (localization M) :=
{ map_units := (localization.monoid_of M).map_units,
surj := (localization.monoid_of M).surj,
eq_iff_exists := Ξ» _ _, (localization.monoid_of M).eq_iff_exists }
end
@[simp] lemma to_localization_map_eq_monoid_of :
to_localization_map M (localization M) = monoid_of M := rfl
lemma monoid_of_eq_algebra_map (x) :
(monoid_of M).to_map x = algebra_map R (localization M) x :=
rfl
lemma mk_one_eq_algebra_map (x) : mk x 1 = algebra_map R (localization M) x := rfl
lemma mk_eq_mk'_apply (x y) : mk x y = is_localization.mk' (localization M) x y :=
by rw [mk_eq_monoid_of_mk'_apply, mk', to_localization_map_eq_monoid_of]
@[simp] lemma mk_eq_mk' : (mk : R β M β localization M) = is_localization.mk' (localization M) :=
mk_eq_monoid_of_mk'
variables [is_localization M S]
section
variables (M S)
/-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/
@[simps]
noncomputable def alg_equiv : localization M ββ[R] S :=
is_localization.alg_equiv M _ _
end
@[simp] lemma alg_equiv_mk' (x : R) (y : M) :
alg_equiv M S (mk' (localization M) x y) = mk' S x y :=
alg_equiv_mk' _ _
@[simp] lemma alg_equiv_symm_mk' (x : R) (y : M) :
(alg_equiv M S).symm (mk' S x y) = mk' (localization M) x y :=
alg_equiv_symm_mk' _ _
lemma alg_equiv_mk (x y) :
alg_equiv M S (mk x y) = mk' S x y :=
by rw [mk_eq_mk', alg_equiv_mk']
lemma alg_equiv_symm_mk (x : R) (y : M) :
(alg_equiv M S).symm (mk' S x y) = mk x y :=
by rw [mk_eq_mk', alg_equiv_symm_mk']
/-- Given a map `f : R β+* S` and an element `r : R`, such that `f r` is invertible,
we may construct a map `Rα΅£ β+* S`. -/
noncomputable
abbreviation away_lift (f : R β+* P) (r : R) (hr : is_unit (f r)) :
localization.away r β+* P :=
is_localization.away.lift r hr
/-- Given a map `f : R β+* S` and an element `r : R`, we may construct a map `Rα΅£ β+* Sα΅£`. -/
noncomputable
abbreviation away_map (f : R β+* P) (r : R) :
localization.away r β+* localization.away (f r) :=
is_localization.away.map _ _ f r
end localization
variables {M}
section at_prime
variables (I : ideal R) [hp : I.is_prime]
include hp
namespace ideal
/-- The complement of a prime ideal `I β R` is a submonoid of `R`. -/
def prime_compl :
submonoid R :=
{ carrier := (IαΆ : set R),
one_mem' := by convert I.ne_top_iff_one.1 hp.1; refl,
mul_mem' := Ξ» x y hnx hny hxy, or.cases_on (hp.mem_or_mem hxy) hnx hny }
end ideal
variables (S)
/-- Given a prime ideal `P`, the typeclass `is_localization.at_prime S P` states that `S` is
isomorphic to the localization of `R` at the complement of `P`. -/
protected abbreviation is_localization.at_prime := is_localization I.prime_compl S
/-- Given a prime ideal `P`, `localization.at_prime S P` is a localization of
`R` at the complement of `P`, as a quotient type. -/
protected abbreviation localization.at_prime := localization I.prime_compl
namespace is_localization
theorem at_prime.local_ring [is_localization.at_prime S I] : local_ring S :=
local_of_nonunits_ideal
(Ξ» hze, begin
rw [β(algebra_map R S).map_one, β(algebra_map R S).map_zero] at hze,
obtain β¨t, htβ© := (eq_iff_exists I.prime_compl S).1 hze,
exact ((show (t : R) β I, from t.2) (have htz : (t : R) = 0, by simpa using ht.symm,
htz.symm βΈ I.zero_mem))
end)
(begin
intros x hx y hy hu,
cases is_unit_iff_exists_inv.1 hu with z hxyz,
have : β {r : R} {s : I.prime_compl}, mk' S r s β nonunits S β r β I, from
Ξ» (r : R) (s : I.prime_compl), not_imp_comm.1
(Ξ» nr, is_unit_iff_exists_inv.2 β¨mk' S βs (β¨r, nrβ© : I.prime_compl),
mk'_mul_mk'_eq_one' _ _ nrβ©),
rcases mk'_surjective I.prime_compl x with β¨rx, sx, hrxβ©,
rcases mk'_surjective I.prime_compl y with β¨ry, sy, hryβ©,
rcases mk'_surjective I.prime_compl z with β¨rz, sz, hrzβ©,
rw [βhrx, βhry, βhrz, βmk'_add, βmk'_mul,
βmk'_self S I.prime_compl.one_mem] at hxyz,
rw βhrx at hx, rw βhry at hy,
obtain β¨t, htβ© := is_localization.eq.1 hxyz,
simp only [mul_one, one_mul, submonoid.coe_mul, subtype.coe_mk] at ht,
rw [βsub_eq_zero, βsub_mul] at ht,
have hr := (hp.mem_or_mem_of_mul_eq_zero ht).resolve_right t.2,
rw sub_eq_add_neg at hr,
have := I.neg_mem_iff.1 ((ideal.add_mem_iff_right _ _).1 hr),
{ exact not_or (mt hp.mem_or_mem (not_or sx.2 sy.2)) sz.2 (hp.mem_or_mem this)},
{ exact I.mul_mem_right _ (I.add_mem (I.mul_mem_right _ (this hx))
(I.mul_mem_right _ (this hy)))}
end)
end is_localization
namespace localization
/-- The localization of `R` at the complement of a prime ideal is a local ring. -/
instance at_prime.local_ring : local_ring (localization I.prime_compl) :=
is_localization.at_prime.local_ring (localization I.prime_compl) I
end localization
end at_prime
namespace is_localization
variables [is_localization M S]
section ideals
variables (M) (S)
include M
/-- Explicit characterization of the ideal given by `ideal.map (algebra_map R S) I`.
In practice, this ideal differs only in that the carrier set is defined explicitly.
This definition is only meant to be used in proving `mem_map_to_map_iff`,
and any proof that needs to refer to the explicit carrier set should use that theorem. -/
private def map_ideal (I : ideal R) : ideal S :=
{ carrier := { z : S | β x : I Γ M, z * algebra_map R S x.2 = algebra_map R S x.1},
zero_mem' := β¨β¨0, 1β©, by simpβ©,
add_mem' := begin
rintros a b β¨a', haβ© β¨b', hbβ©,
use β¨a'.2 * b'.1 + b'.2 * a'.1, I.add_mem (I.mul_mem_left _ b'.1.2) (I.mul_mem_left _ a'.1.2)β©,
use a'.2 * b'.2,
simp only [ring_hom.map_add, submodule.coe_mk, submonoid.coe_mul, ring_hom.map_mul],
rw [add_mul, β mul_assoc a, ha, mul_comm (algebra_map R S a'.2) (algebra_map R S b'.2),
β mul_assoc b, hb],
ring
end,
smul_mem' := begin
rintros c x β¨x', hxβ©,
obtain β¨c', hcβ© := is_localization.surj M c,
use β¨c'.1 * x'.1, I.mul_mem_left c'.1 x'.1.2β©,
use c'.2 * x'.2,
simp only [βhx, βhc, smul_eq_mul, submodule.coe_mk, submonoid.coe_mul, ring_hom.map_mul],
ring
end }
theorem mem_map_algebra_map_iff {I : ideal R} {z} :
z β ideal.map (algebra_map R S) I β β x : I Γ M, z * algebra_map R S x.2 = algebra_map R S x.1 :=
begin
split,
{ change _ β z β map_ideal M S I,
refine Ξ» h, ideal.mem_Inf.1 h (Ξ» z hz, _),
obtain β¨y, hyβ© := hz,
use β¨β¨β¨y, hy.leftβ©, 1β©, by simp [hy.right]β© },
{ rintros β¨β¨a, sβ©, hβ©,
rw [β ideal.unit_mul_mem_iff_mem _ (map_units S s), mul_comm],
exact h.symm βΈ ideal.mem_map_of_mem _ a.2 }
end
theorem map_comap (J : ideal S) :
ideal.map (algebra_map R S) (ideal.comap (algebra_map R S) J) = J :=
le_antisymm (ideal.map_le_iff_le_comap.2 le_rfl) $ Ξ» x hJ,
begin
obtain β¨r, s, hxβ© := mk'_surjective M x,
rw βhx at β’ hJ,
exact ideal.mul_mem_right _ _ (ideal.mem_map_of_mem _ (show (algebra_map R S) r β J, from
mk'_spec S r s βΈ J.mul_mem_right ((algebra_map R S) s) hJ)),
end
theorem comap_map_of_is_prime_disjoint (I : ideal R) (hI : I.is_prime)
(hM : disjoint (M : set R) I) :
ideal.comap (algebra_map R S) (ideal.map (algebra_map R S) I) = I :=
begin
refine le_antisymm (Ξ» a ha, _) ideal.le_comap_map,
rw [ideal.mem_comap, mem_map_algebra_map_iff M S] at ha,
obtain β¨β¨b, sβ©, hβ© := ha,
have : (algebra_map R S) (a * βs - b) = 0 := by simpa [sub_eq_zero] using h,
rw [β (algebra_map R S).map_zero, eq_iff_exists M S] at this,
obtain β¨c, hcβ© := this,
have : a * s β I,
{ rw zero_mul at hc,
let this : (a * βs - βb) * βc β I := hc.symm βΈ I.zero_mem,
cases hI.mem_or_mem this with h1 h2,
{ simpa using I.add_mem h1 b.2 },
{ exfalso,
refine hM β¨c.2, h2β© } },
cases hI.mem_or_mem this with h1 h2,
{ exact h1 },
{ exfalso,
refine hM β¨s.2, h2β© }
end
/-- If `S` is the localization of `R` at a submonoid, the ordering of ideals of `S` is
embedded in the ordering of ideals of `R`. -/
def order_embedding : ideal S βͺo ideal R :=
{ to_fun := Ξ» J, ideal.comap (algebra_map R S) J,
inj' := function.left_inverse.injective (map_comap M S),
map_rel_iff' := Ξ» Jβ Jβ, β¨Ξ» hJ, (map_comap M S) Jβ βΈ (map_comap M S) Jβ βΈ ideal.map_mono hJ,
ideal.comap_monoβ© }
/-- If `R` is a ring, then prime ideals in the localization at `M`
correspond to prime ideals in the original ring `R` that are disjoint from `M`.
This lemma gives the particular case for an ideal and its comap,
see `le_rel_iso_of_prime` for the more general relation isomorphism -/
lemma is_prime_iff_is_prime_disjoint (J : ideal S) :
J.is_prime β (ideal.comap (algebra_map R S) J).is_prime β§
disjoint (M : set R) β(ideal.comap (algebra_map R S) J) :=
begin
split,
{ refine Ξ» h, β¨β¨_, _β©, Ξ» m hm,
h.ne_top (ideal.eq_top_of_is_unit_mem _ hm.2 (map_units S β¨m, hm.leftβ©))β©,
{ refine Ξ» hJ, h.ne_top _,
rw [eq_top_iff, β (order_embedding M S).le_iff_le],
exact le_of_eq hJ.symm },
{ intros x y hxy,
rw [ideal.mem_comap, ring_hom.map_mul] at hxy,
exact h.mem_or_mem hxy } },
{ refine Ξ» h, β¨Ξ» hJ, h.left.ne_top (eq_top_iff.2 _), _β©,
{ rwa [eq_top_iff, β (order_embedding M S).le_iff_le] at hJ },
{ intros x y hxy,
obtain β¨a, s, haβ© := mk'_surjective M x,
obtain β¨b, t, hbβ© := mk'_surjective M y,
have : mk' S (a * b) (s * t) β J := by rwa [mk'_mul, ha, hb],
rw [mk'_mem_iff, β ideal.mem_comap] at this,
replace this := h.left.mem_or_mem this,
rw [ideal.mem_comap, ideal.mem_comap] at this,
rwa [β ha, β hb, mk'_mem_iff, mk'_mem_iff] } }
end
/-- If `R` is a ring, then prime ideals in the localization at `M`
correspond to prime ideals in the original ring `R` that are disjoint from `M`.
This lemma gives the particular case for an ideal and its map,
see `le_rel_iso_of_prime` for the more general relation isomorphism, and the reverse implication -/
lemma is_prime_of_is_prime_disjoint (I : ideal R) (hp : I.is_prime)
(hd : disjoint (M : set R) βI) : (ideal.map (algebra_map R S) I).is_prime :=
begin
rw [is_prime_iff_is_prime_disjoint M S, comap_map_of_is_prime_disjoint M S I hp hd],
exact β¨hp, hdβ©
end
/-- If `R` is a ring, then prime ideals in the localization at `M`
correspond to prime ideals in the original ring `R` that are disjoint from `M` -/
def order_iso_of_prime :
{p : ideal S // p.is_prime} βo {p : ideal R // p.is_prime β§ disjoint (M : set R) βp} :=
{ to_fun := Ξ» p, β¨ideal.comap (algebra_map R S) p.1,
(is_prime_iff_is_prime_disjoint M S p.1).1 p.2β©,
inv_fun := Ξ» p, β¨ideal.map (algebra_map R S) p.1,
is_prime_of_is_prime_disjoint M S p.1 p.2.1 p.2.2β©,
left_inv := Ξ» J, subtype.eq (map_comap M S J),
right_inv := Ξ» I, subtype.eq (comap_map_of_is_prime_disjoint M S I.1 I.2.1 I.2.2),
map_rel_iff' := Ξ» I I', β¨Ξ» h, (show I.val β€ I'.val,
from (map_comap M S I.val) βΈ (map_comap M S I'.val) βΈ (ideal.map_mono h)), Ξ» h x hx, h hxβ© }
/-- `quotient_map` applied to maximal ideals of a localization is `surjective`.
The quotient by a maximal ideal is a field, so inverses to elements already exist,
and the localization necessarily maps the equivalence class of the inverse in the localization -/
lemma surjective_quotient_map_of_maximal_of_localization {I : ideal S} [I.is_prime] {J : ideal R}
{H : J β€ I.comap (algebra_map R S)} (hI : (I.comap (algebra_map R S)).is_maximal) :
function.surjective (I.quotient_map (algebra_map R S) H) :=
begin
intro s,
obtain β¨s, rflβ© := ideal.quotient.mk_surjective s,
obtain β¨r, β¨m, hmβ©, rflβ© := mk'_surjective M s,
by_cases hM : (ideal.quotient.mk (I.comap (algebra_map R S))) m = 0,
{ have : I = β€,
{ rw ideal.eq_top_iff_one,
rw [ideal.quotient.eq_zero_iff_mem, ideal.mem_comap] at hM,
convert I.mul_mem_right (mk' S (1 : R) β¨m, hmβ©) hM,
rw [β mk'_eq_mul_mk'_one, mk'_self] },
exact β¨0, eq_comm.1 (by simp [ideal.quotient.eq_zero_iff_mem, this])β© },
{ rw ideal.quotient.maximal_ideal_iff_is_field_quotient at hI,
obtain β¨n, hnβ© := hI.3 hM,
obtain β¨rn, rflβ© := ideal.quotient.mk_surjective n,
refine β¨(ideal.quotient.mk J) (r * rn), _β©,
-- The rest of the proof is essentially just algebraic manipulations to prove the equality
rw β ring_hom.map_mul at hn,
replace hn := congr_arg (ideal.quotient_map I (algebra_map R S) le_rfl) hn,
simp only [ring_hom.map_one, ideal.quotient_map_mk, ring_hom.map_mul] at hn,
rw [ideal.quotient_map_mk, β sub_eq_zero, β ring_hom.map_sub,
ideal.quotient.eq_zero_iff_mem, β ideal.quotient.eq_zero_iff_mem, ring_hom.map_sub,
sub_eq_zero, mk'_eq_mul_mk'_one],
simp only [mul_eq_mul_left_iff, ring_hom.map_mul],
exact or.inl (mul_left_cancelβ (Ξ» hn, hM (ideal.quotient.eq_zero_iff_mem.2
(ideal.mem_comap.2 (ideal.quotient.eq_zero_iff_mem.1 hn)))) (trans hn
(by rw [β ring_hom.map_mul, β mk'_eq_mul_mk'_one, mk'_self, ring_hom.map_one]))) }
end
end ideals
section at_units
variables (R) (S) (M)
/-- The localization at a module of units is isomorphic to the ring -/
noncomputable
def at_units (H : β x : M, is_unit (x : R)) : R ββ[R] S :=
begin
refine alg_equiv.of_bijective (algebra.of_id R S) β¨_, _β©,
{ intros x y hxy,
obtain β¨c, eqβ© := (is_localization.eq_iff_exists M S).mp hxy,
obtain β¨u, huβ© := H c,
rwa [β hu, units.mul_left_inj] at eq },
{ intros y,
obtain β¨β¨x, sβ©, eqβ© := is_localization.surj M y,
obtain β¨u, huβ© := H s,
use x * u.inv,
dsimp only [algebra.of_id, ring_hom.to_fun_eq_coe, alg_hom.coe_mk],
rw [ring_hom.map_mul, β eq, β hu, mul_assoc, β ring_hom.map_mul],
simp }
end
/-- The localization away from a unit is isomorphic to the ring -/
noncomputable
def at_unit (x : R) (e : is_unit x) [is_localization.away x S] : R ββ[R] S :=
begin
apply at_units R (submonoid.powers x),
rintros β¨xn, n, hxnβ©,
obtain β¨u, huβ© := e,
rw is_unit_iff_exists_inv,
use u.inv ^ n,
simp[β hxn, β hu, β mul_pow]
end
/-- The localization at one is isomorphic to the ring. -/
noncomputable
def at_one [is_localization.away (1 : R) S] : R ββ[R] S :=
@at_unit R _ S _ _ (1 : R) is_unit_one _
end at_units
section localization_localization
variable (M)
variables (N : submonoid S) (T : Type*) [comm_ring T] [algebra R T]
section
variables [algebra S T] [is_scalar_tower R S T]
/--
Localizing wrt `M β R` and then wrt `N β S = Mβ»ΒΉR` is equal to the localization of `R` wrt this
module. See `localization_localization_is_localization`.
-/
-- This should only be defined when `S` is the localization `Mβ»ΒΉR`, hence the nolint.
@[nolint unused_arguments]
def localization_localization_submodule : submonoid R :=
(N β M.map (algebra_map R S)).comap (algebra_map R S)
variables {M N}
@[simp]
lemma mem_localization_localization_submodule {x : R} :
x β localization_localization_submodule M N β
β (y : N) (z : M), algebra_map R S x = y * algebra_map R S z :=
begin
rw [localization_localization_submodule, submonoid.mem_comap, submonoid.mem_sup],
split,
{ rintros β¨y, hy, _, β¨z, hz, rflβ©, eβ©, exact β¨β¨y, hyβ©, β¨z, hzβ© ,e.symmβ© },
{ rintros β¨y, z, eβ©, exact β¨y, y.prop, _, β¨z, z.prop, rflβ©, e.symmβ© }
end
variables (M N)
lemma localization_localization_map_units [is_localization N T]
(y : localization_localization_submodule M N) : is_unit (algebra_map R T y) :=
begin
obtain β¨y', z, eqβ© := mem_localization_localization_submodule.mp y.prop,
rw [is_scalar_tower.algebra_map_apply R S T, eq, ring_hom.map_mul, is_unit.mul_iff],
exact β¨is_localization.map_units T y',
(is_localization.map_units _ z).map (algebra_map S T : S β* T)β©,
end
lemma localization_localization_surj [is_localization N T] (x : T) :
β (y : R Γ localization_localization_submodule M N),
x * (algebra_map R T y.2) = algebra_map R T y.1 :=
begin
rcases is_localization.surj N x with β¨β¨y, sβ©, eqββ©, -- x = y / s
rcases is_localization.surj M y with β¨β¨z, tβ©, eqββ©, -- y = z / t
rcases is_localization.surj M (s : S) with β¨β¨z', t'β©, eqββ©, -- s = z' / t'
dsimp only at eqβ eqβ eqβ,
use z * t', use z' * t, -- x = y / s = (z * t') / (z' * t)
{ rw mem_localization_localization_submodule,
refine β¨s, t * t', _β©,
rw [ring_hom.map_mul, β eqβ, mul_assoc, β ring_hom.map_mul, mul_comm t, submonoid.coe_mul] },
{ simp only [subtype.coe_mk, ring_hom.map_mul, is_scalar_tower.algebra_map_apply R S T,
β eqβ, β eqβ, β eqβ],
ring },
end
lemma localization_localization_eq_iff_exists [is_localization N T] (x y : R) :
algebra_map R T x = algebra_map R T y β
β (c : localization_localization_submodule M N), x * c = y * c :=
begin
rw [is_scalar_tower.algebra_map_apply R S T, is_scalar_tower.algebra_map_apply R S T,
is_localization.eq_iff_exists N T],
split,
{ rintros β¨z, eqββ©,
rcases is_localization.surj M (z : S) with β¨β¨z', sβ©, eqββ©,
dsimp only at eqβ,
obtain β¨c, eqβ : x * z' * β c = y * z' * β cβ© := (is_localization.eq_iff_exists M S).mp _,
swap, { rw [ring_hom.map_mul, ring_hom.map_mul, β eqβ, β mul_assoc, β mul_assoc, β eqβ] },
use z' * c,
{ rw mem_localization_localization_submodule,
refine β¨z, s * c, _β©,
rw [ring_hom.map_mul, β eqβ, mul_assoc, β ring_hom.map_mul, submonoid.coe_mul] },
{ simpa only [mul_assoc] using eqβ } },
{ rintro β¨β¨c, hcβ©, eqβ : x * c = y * cβ©,
rw mem_localization_localization_submodule at hc,
rcases hc with β¨zβ, z, eqββ©,
use zβ,
refine (is_localization.map_units S z).mul_left_inj.mp _,
rw [mul_assoc, mul_assoc, β eqβ, β ring_hom.map_mul, β ring_hom.map_mul, eqβ] }
end
/--
Given submodules `M β R` and `N β S = Mβ»ΒΉR`, with `f : R β+* S` the localization map, we have
`N β»ΒΉ S = T = (fβ»ΒΉ (N β’ f(M))) β»ΒΉ R`. I.e., the localization of a localization is a localization.
-/
lemma localization_localization_is_localization [is_localization N T] :
is_localization (localization_localization_submodule M N) T :=
{ map_units := localization_localization_map_units M N T,
surj := localization_localization_surj M N T,
eq_iff_exists := localization_localization_eq_iff_exists M N T }
include M
/--
Given submodules `M β R` and `N β S = Mβ»ΒΉR`, with `f : R β+* S` the localization map, if
`N` contains all the units of `S`, then `N β»ΒΉ S = T = (fβ»ΒΉ N) β»ΒΉ R`. I.e., the localization of a
localization is a localization.
-/
lemma localization_localization_is_localization_of_has_all_units
[is_localization N T] (H : β (x : S), is_unit x β x β N) :
is_localization (N.comap (algebra_map R S).to_monoid_hom) T :=
begin
convert localization_localization_is_localization M N T,
symmetry,
rw sup_eq_left,
rintros _ β¨x, hx, rflβ©,
exact H _ (is_localization.map_units _ β¨x, hxβ©),
end
/--
Given a submodule `M β R` and a prime ideal `p` of `S = Mβ»ΒΉR`, with `f : R β+* S` the localization
map, then `T = Sβ` is the localization of `R` at `fβ»ΒΉ(p)`.
-/
lemma is_localization_is_localization_at_prime_is_localization (p : ideal S) [Hp : p.is_prime]
[is_localization.at_prime T p] :
is_localization.at_prime T (p.comap (algebra_map R S)) :=
begin
apply localization_localization_is_localization_of_has_all_units M p.prime_compl T,
intros x hx hx',
exact (Hp.1 : Β¬ _) (p.eq_top_of_is_unit_mem hx' hx),
end
instance (p : ideal (localization M)) [p.is_prime] : algebra R (localization.at_prime p) :=
localization.algebra
instance (p : ideal (localization M)) [p.is_prime] :
is_scalar_tower R (localization M) (localization.at_prime p) :=
is_scalar_tower.of_algebra_map_eq' rfl
instance localization_localization_at_prime_is_localization (p : ideal (localization M))
[p.is_prime] : is_localization.at_prime (localization.at_prime p) (p.comap (algebra_map R _)) :=
is_localization_is_localization_at_prime_is_localization M _ _
/--
Given a submodule `M β R` and a prime ideal `p` of `Mβ»ΒΉR`, with `f : R β+* S` the localization
map, then `(Mβ»ΒΉR)β` is isomorphic (as an `R`-algebra) to the localization of `R` at `fβ»ΒΉ(p)`.
-/
noncomputable
def localization_localization_at_prime_iso_localization (p : ideal (localization M)) [p.is_prime] :
localization.at_prime (p.comap (algebra_map R _)) ββ[R] localization.at_prime p :=
is_localization.alg_equiv (p.comap (algebra_map R _)).prime_compl _ _
end
variables (S)
/-- Given submonoids `M β€ N` of `R`, this is the canonical algebra structure
of `Mβ»ΒΉS` acting on `Nβ»ΒΉS`. -/
noncomputable
def localization_algebra_of_submonoid_le
(M N : submonoid R) (h : M β€ N) [is_localization M S] [is_localization N T] :
algebra S T :=
(is_localization.lift (Ξ» y, (map_units T β¨βy, h y.propβ© : _)) : S β+* T).to_algebra
/-- If `M β€ N` are submonoids of `R`, then the natural map `Mβ»ΒΉS β+* Nβ»ΒΉS` commutes with the
localization maps -/
lemma localization_is_scalar_tower_of_submonoid_le
(M N : submonoid R) (h : M β€ N) [is_localization M S] [is_localization N T] :
@@is_scalar_tower R S T _ (localization_algebra_of_submonoid_le S T M N h).to_has_scalar _ :=
begin
letI := localization_algebra_of_submonoid_le S T M N h,
exact is_scalar_tower.of_algebra_map_eq' (is_localization.lift_comp _).symm
end
noncomputable
instance (x : ideal R) [H : x.is_prime] [is_domain R] :
algebra (localization.at_prime x) (localization (non_zero_divisors R)) :=
localization_algebra_of_submonoid_le _ _ x.prime_compl (non_zero_divisors R)
(by { intros a ha, rw mem_non_zero_divisors_iff_ne_zero, exact Ξ» h, ha (h.symm βΈ x.zero_mem) })
/-- If `M β€ N` are submonoids of `R`, then `Nβ»ΒΉS` is also the localization of `Mβ»ΒΉS` at `N`. -/
lemma is_localization_of_submonoid_le
(M N : submonoid R) (h : M β€ N) [is_localization M S] [is_localization N T]
[algebra S T] [is_scalar_tower R S T] :
is_localization (N.map (algebra_map R S).to_monoid_hom) T :=
{ map_units := begin
rintro β¨_, β¨y, hy, rflβ©β©,
convert is_localization.map_units T β¨y, hyβ©,
exact (is_scalar_tower.algebra_map_apply _ _ _ _).symm
end,
surj := Ξ» y, begin
obtain β¨β¨x, sβ©, eβ© := is_localization.surj N y,
refine β¨β¨algebra_map _ _ x, _, _, s.prop, rflβ©, _β©,
simpa [β is_scalar_tower.algebra_map_apply] using e
end,
eq_iff_exists := Ξ» xβ xβ, begin
obtain β¨β¨yβ, sββ©, eββ© := is_localization.surj M xβ,
obtain β¨β¨yβ, sββ©, eββ© := is_localization.surj M xβ,
refine iff.trans _ (set.exists_image_iff (algebra_map R S) N (Ξ» c, xβ * c = xβ * c)).symm,
dsimp only at eβ eβ β’,
suffices : algebra_map R T (yβ * sβ) = algebra_map R T (yβ * sβ) β
β (a : N), algebra_map R S (a * (yβ * sβ)) = algebra_map R S (a * (yβ * sβ)),
{ have hβ := (is_localization.map_units T β¨_, h sβ.propβ©).mul_left_inj,
have hβ := (is_localization.map_units T β¨_, h sβ.propβ©).mul_left_inj,
simp only [is_scalar_tower.algebra_map_apply R S T, subtype.coe_mk] at hβ hβ,
simp only [is_scalar_tower.algebra_map_apply R S T, map_mul, β eβ, β eβ, β mul_assoc,
mul_right_comm _ (algebra_map R S sβ),
mul_right_comm _ (algebra_map S T (algebra_map R S sβ)),
(is_localization.map_units S sβ).mul_left_inj,
(is_localization.map_units S sβ).mul_left_inj] at this,
rw [hβ, hβ] at this,
simpa only [mul_comm] using this },
simp_rw [is_localization.eq_iff_exists N T, is_localization.eq_iff_exists M S],
split,
{ rintro β¨a, eβ©, exact β¨a, 1, by { convert e using 1; simp; ring }β© },
{ rintro β¨a, b, eβ©, exact β¨a * (β¨_, h b.propβ© : N), by { convert e using 1; simp; ring }β© }
end }
/-- If `M β€ N` are submonoids of `R` such that `β x : N, β m : R, m * x β M`, then the
localization at `N` is equal to the localizaton of `M`. -/
lemma is_localization_of_is_exists_mul_mem (M N : submonoid R) [is_localization M S] (h : M β€ N)
(h' : β x : N, β m : R, m * x β M) : is_localization N S :=
{ map_units := Ξ» y, begin
obtain β¨m, hmβ© := h' y,
have := is_localization.map_units S β¨_, hmβ©,
erw map_mul at this,
exact (is_unit.mul_iff.mp this).2
end,
surj := Ξ» z, by { obtain β¨β¨y, sβ©, eβ© := is_localization.surj M z, exact β¨β¨y, _, h s.propβ©, eβ© },
eq_iff_exists := Ξ» xβ xβ, begin
rw is_localization.eq_iff_exists M,
refine β¨Ξ» β¨x, hxβ©, β¨β¨_, h x.propβ©, hxβ©, _β©,
rintros β¨x, hβ©,
obtain β¨m, hmβ© := h' x,
refine β¨β¨_, hmβ©, _β©,
simp [mul_comm m, β mul_assoc, h]
end }
end localization_localization
variables (S)
/-- Map from ideals of `R` to submodules of `S` induced by `f`. -/
-- This was previously a `has_coe` instance, but if `S = R` then this will loop.
-- It could be a `has_coe_t` instance, but we keep it explicit here to avoid slowing down
-- the rest of the library.
def coe_submodule (I : ideal R) : submodule R S := submodule.map (algebra.linear_map R S) I
lemma mem_coe_submodule (I : ideal R) {x : S} :
x β coe_submodule S I β β y : R, y β I β§ algebra_map R S y = x :=
iff.rfl
lemma coe_submodule_mono {I J : ideal R} (h : I β€ J) :
coe_submodule S I β€ coe_submodule S J :=
submodule.map_mono h
@[simp] lemma coe_submodule_bot : coe_submodule S (β₯ : ideal R) = β₯ :=
by rw [coe_submodule, submodule.map_bot]
@[simp] lemma coe_submodule_top : coe_submodule S (β€ : ideal R) = 1 :=
by rw [coe_submodule, submodule.map_top, submodule.one_eq_range]
@[simp] lemma coe_submodule_sup (I J : ideal R) :
coe_submodule S (I β J) = coe_submodule S I β coe_submodule S J :=
submodule.map_sup _ _ _
@[simp] lemma coe_submodule_mul (I J : ideal R) :
coe_submodule S (I * J) = coe_submodule S I * coe_submodule S J :=
submodule.map_mul _ _ (algebra.of_id R S)
lemma coe_submodule_fg
(hS : function.injective (algebra_map R S)) (I : ideal R) :
submodule.fg (coe_submodule S I) β submodule.fg I :=
β¨submodule.fg_of_fg_map _ (linear_map.ker_eq_bot.mpr hS), submodule.fg.map _β©
@[simp]
lemma coe_submodule_span (s : set R) :
coe_submodule S (ideal.span s) = submodule.span R ((algebra_map R S) '' s) :=
by { rw [is_localization.coe_submodule, ideal.span, submodule.map_span], refl }
@[simp]
lemma coe_submodule_span_singleton (x : R) :
coe_submodule S (ideal.span {x}) = submodule.span R {(algebra_map R S) x} :=
by rw [coe_submodule_span, set.image_singleton]
variables {g : R β+* P}
variables {T : submonoid P} (hy : M β€ T.comap g) {Q : Type*} [comm_ring Q]
variables [algebra P Q] [is_localization T Q]
lemma map_smul (x : S) (z : R) :
map Q g hy (z β’ x : S) = g z β’ map Q g hy x :=
by rw [algebra.smul_def, algebra.smul_def, ring_hom.map_mul, map_eq]
section
include M
lemma is_noetherian_ring (h : is_noetherian_ring R) : is_noetherian_ring S :=
begin
rw [is_noetherian_ring_iff, is_noetherian_iff_well_founded] at h β’,
exact order_embedding.well_founded ((is_localization.order_embedding M S).dual) h
end
end
section integer_normalization
open polynomial
open_locale classical
variables (M) {S}
/-- `coeff_integer_normalization p` gives the coefficients of the polynomial
`integer_normalization p` -/
noncomputable def coeff_integer_normalization (p : polynomial S) (i : β) : R :=
if hi : i β p.support
then classical.some (classical.some_spec
(exist_integer_multiples_of_finset M (p.support.image p.coeff))
(p.coeff i)
(finset.mem_image.mpr β¨i, hi, rflβ©))
else 0
lemma coeff_integer_normalization_of_not_mem_support (p : polynomial S) (i : β)
(h : coeff p i = 0) : coeff_integer_normalization M p i = 0 :=
by simp only [coeff_integer_normalization, h, mem_support_iff, eq_self_iff_true, not_true,
ne.def, dif_neg, not_false_iff]
lemma coeff_integer_normalization_mem_support (p : polynomial S) (i : β)
(h : coeff_integer_normalization M p i β 0) : i β p.support :=
begin
contrapose h,
rw [ne.def, not_not, coeff_integer_normalization, dif_neg h]
end
/-- `integer_normalization g` normalizes `g` to have integer coefficients
by clearing the denominators -/
noncomputable def integer_normalization (p : polynomial S) :
polynomial R :=
β i in p.support, monomial i (coeff_integer_normalization M p i)
@[simp]
lemma integer_normalization_coeff (p : polynomial S) (i : β) :
(integer_normalization M p).coeff i = coeff_integer_normalization M p i :=
by simp [integer_normalization, coeff_monomial, coeff_integer_normalization_of_not_mem_support]
{contextual := tt}
lemma integer_normalization_spec (p : polynomial S) :
β (b : M), β i,
algebra_map R S ((integer_normalization M p).coeff i) = (b : R) β’ p.coeff i :=
begin
use classical.some (exist_integer_multiples_of_finset M (p.support.image p.coeff)),
intro i,
rw [integer_normalization_coeff, coeff_integer_normalization],
split_ifs with hi,
{ exact classical.some_spec (classical.some_spec
(exist_integer_multiples_of_finset M (p.support.image p.coeff))
(p.coeff i)
(finset.mem_image.mpr β¨i, hi, rflβ©)) },
{ convert (smul_zero _).symm,
{ apply ring_hom.map_zero },
{ exact not_mem_support_iff.mp hi } }
end
lemma integer_normalization_map_to_map (p : polynomial S) :
β (b : M), (integer_normalization M p).map (algebra_map R S) = (b : R) β’ p :=
let β¨b, hbβ© := integer_normalization_spec M p in
β¨b, polynomial.ext (Ξ» i, by { rw [coeff_map, coeff_smul], exact hb i })β©
variables {R' : Type*} [comm_ring R']
lemma integer_normalization_evalβ_eq_zero (g : S β+* R') (p : polynomial S)
{x : R'} (hx : evalβ g x p = 0) :
evalβ (g.comp (algebra_map R S)) x (integer_normalization M p) = 0 :=
let β¨b, hbβ© := integer_normalization_map_to_map M p in
trans (evalβ_map (algebra_map R S) g x).symm
(by rw [hb, β is_scalar_tower.algebra_map_smul S (b : R) p, evalβ_smul, hx, mul_zero])
lemma integer_normalization_aeval_eq_zero [algebra R R'] [algebra S R'] [is_scalar_tower R S R']
(p : polynomial S) {x : R'} (hx : aeval x p = 0) :
aeval x (integer_normalization M p) = 0 :=
by rw [aeval_def, is_scalar_tower.algebra_map_eq R S R',
integer_normalization_evalβ_eq_zero _ _ _ hx]
end integer_normalization
variables {R M} (S) {K : Type*}
lemma to_map_eq_zero_iff {x : R} (hM : M β€ non_zero_divisors R) :
algebra_map R S x = 0 β x = 0 :=
begin
rw β (algebra_map R S).map_zero,
split; intro h,
{ cases (eq_iff_exists M S).mp h with c hc,
rw zero_mul at hc,
exact hM c.2 x hc },
{ rw h },
end
protected lemma injective (hM : M β€ non_zero_divisors R) :
injective (algebra_map R S) :=
begin
rw ring_hom.injective_iff (algebra_map R S),
intros a ha,
rwa to_map_eq_zero_iff S hM at ha
end
protected lemma to_map_ne_zero_of_mem_non_zero_divisors [nontrivial R]
(hM : M β€ non_zero_divisors R) {x : R} (hx : x β non_zero_divisors R) : algebra_map R S x β 0 :=
show (algebra_map R S).to_monoid_with_zero_hom x β 0,
from map_ne_zero_of_mem_non_zero_divisors (algebra_map R S) (is_localization.injective S hM) hx
variables (S Q M)
/-- Injectivity of a map descends to the map induced on localizations. -/
lemma map_injective_of_injective
(hg : function.injective g) [is_localization (M.map g : submonoid P) Q]
(hM : (M.map g : submonoid P) β€ non_zero_divisors P) :
function.injective (map Q g M.le_comap_map : S β Q) :=
begin
rintros x y hxy,
obtain β¨a, b, rflβ© := mk'_surjective M x,
obtain β¨c, d, rflβ© := mk'_surjective M y,
rw [map_mk' _ a b, map_mk' _ c d, mk'_eq_iff_eq] at hxy,
refine mk'_eq_iff_eq.2 (congr_arg (algebra_map _ _) (hg _)),
convert is_localization.injective _ hM hxy; simp,
end
variables {S Q M}
@[mono]
lemma coe_submodule_le_coe_submodule (h : M β€ non_zero_divisors R)
{I J : ideal R} :
coe_submodule S I β€ coe_submodule S J β I β€ J :=
submodule.map_le_map_iff_of_injective (is_localization.injective _ h) _ _
@[mono]
lemma coe_submodule_strict_mono (h : M β€ non_zero_divisors R) :
strict_mono (coe_submodule S : ideal R β submodule R S) :=
strict_mono_of_le_iff_le (Ξ» _ _, (coe_submodule_le_coe_submodule h).symm)
variables (S) {Q M}
lemma coe_submodule_injective (h : M β€ non_zero_divisors R) :
function.injective (coe_submodule S : ideal R β submodule R S) :=
injective_of_le_imp_le _ (Ξ» _ _, (coe_submodule_le_coe_submodule h).mp)
lemma coe_submodule_is_principal {I : ideal R} (h : M β€ non_zero_divisors R) :
(coe_submodule S I).is_principal β I.is_principal :=
begin
split; unfreezingI { rintros β¨β¨x, hxβ©β© },
{ have x_mem : x β coe_submodule S I := hx.symm βΈ submodule.mem_span_singleton_self x,
obtain β¨x, x_mem, rflβ© := (mem_coe_submodule _ _).mp x_mem,
refine β¨β¨x, coe_submodule_injective S h _β©β©,
rw [ideal.submodule_span_eq, hx, coe_submodule_span_singleton] },
{ refine β¨β¨algebra_map R S x, _β©β©,
rw [hx, ideal.submodule_span_eq, coe_submodule_span_singleton] }
end
variables {A : Type*} [comm_ring A] [is_domain A]
/-- A `comm_ring` `S` which is the localization of an integral domain `R` at a subset of
non-zero elements is an integral domain.
See note [reducible non-instances]. -/
@[reducible]
theorem is_domain_of_le_non_zero_divisors
[algebra A S] {M : submonoid A} [is_localization M S]
(hM : M β€ non_zero_divisors A) : is_domain S :=
{ eq_zero_or_eq_zero_of_mul_eq_zero :=
begin
intros z w h,
cases surj M z with x hx,
cases surj M w with y hy,
have : z * w * algebra_map A S y.2 * algebra_map A S x.2 =
algebra_map A S x.1 * algebra_map A S y.1,
by rw [mul_assoc z, hy, βhx]; ac_refl,
rw [h, zero_mul, zero_mul, β (algebra_map A S).map_mul] at this,
cases eq_zero_or_eq_zero_of_mul_eq_zero ((to_map_eq_zero_iff S hM).mp this.symm) with H H,
{ exact or.inl (eq_zero_of_fst_eq_zero hx H) },
{ exact or.inr (eq_zero_of_fst_eq_zero hy H) },
end,
exists_pair_ne := β¨(algebra_map A S) 0, (algebra_map A S) 1,
Ξ» h, zero_ne_one (is_localization.injective S hM h)β©, }
/-- The localization at of an integral domain to a set of non-zero elements is an integral domain.
See note [reducible non-instances]. -/
@[reducible]
theorem is_domain_localization {M : submonoid A} (hM : M β€ non_zero_divisors A) :
is_domain (localization M) :=
is_domain_of_le_non_zero_divisors _ hM
/--
The localization of an integral domain at the complement of a prime ideal is an integral domain.
-/
instance is_domain_of_local_at_prime {P : ideal A} (hp : P.is_prime) :
is_domain (localization.at_prime P) :=
is_domain_localization (le_non_zero_divisors_of_no_zero_divisors
(not_not_intro P.zero_mem))
namespace at_prime
variables (I : ideal R) [hI : I.is_prime] [is_localization.at_prime S I]
include hI
lemma is_unit_to_map_iff (x : R) :
is_unit ((algebra_map R S) x) β x β I.prime_compl :=
β¨Ξ» h hx, (is_prime_of_is_prime_disjoint I.prime_compl S I hI disjoint_compl_left).ne_top $
(ideal.map (algebra_map R S) I).eq_top_of_is_unit_mem (ideal.mem_map_of_mem _ hx) h,
Ξ» h, map_units S β¨x, hβ©β©
-- Can't use typeclasses to infer the `local_ring` instance, so use an `opt_param` instead
-- (since `local_ring` is a `Prop`, there should be no unification issues.)
lemma to_map_mem_maximal_iff (x : R) (h : _root_.local_ring S := local_ring S I) :
algebra_map R S x β local_ring.maximal_ideal S β x β I :=
not_iff_not.mp $ by
simpa only [@local_ring.mem_maximal_ideal S, mem_nonunits_iff, not_not]
using is_unit_to_map_iff S I x
lemma is_unit_mk'_iff (x : R) (y : I.prime_compl) :
is_unit (mk' S x y) β x β I.prime_compl :=
β¨Ξ» h hx, mk'_mem_iff.mpr ((to_map_mem_maximal_iff S I x).mpr hx) h,
Ξ» h, is_unit_iff_exists_inv.mpr β¨mk' S βy β¨x, hβ©, mk'_mul_mk'_eq_one β¨x, hβ© yβ©β©
lemma mk'_mem_maximal_iff (x : R) (y : I.prime_compl) (h : _root_.local_ring S := local_ring S I) :
mk' S x y β local_ring.maximal_ideal S β x β I :=
not_iff_not.mp $ by
simpa only [@local_ring.mem_maximal_ideal S, mem_nonunits_iff, not_not]
using is_unit_mk'_iff S I x y
end at_prime
end is_localization
namespace localization
open is_localization
local attribute [instance] classical.prop_decidable
variables (I : ideal R) [hI : I.is_prime]
include hI
variables {I}
/-- The unique maximal ideal of the localization at `I.prime_compl` lies over the ideal `I`. -/
lemma at_prime.comap_maximal_ideal :
ideal.comap (algebra_map R (localization.at_prime I))
(local_ring.maximal_ideal (localization I.prime_compl)) = I :=
ideal.ext $ Ξ» x, by
simpa only [ideal.mem_comap] using at_prime.to_map_mem_maximal_iff _ I x
/-- The image of `I` in the localization at `I.prime_compl` is a maximal ideal, and in particular
it is the unique maximal ideal given by the local ring structure `at_prime.local_ring` -/
lemma at_prime.map_eq_maximal_ideal :
ideal.map (algebra_map R (localization.at_prime I)) I =
(local_ring.maximal_ideal (localization I.prime_compl)) :=
begin
convert congr_arg (ideal.map _) at_prime.comap_maximal_ideal.symm,
rw map_comap I.prime_compl
end
lemma le_comap_prime_compl_iff {J : ideal P} [hJ : J.is_prime] {f : R β+* P} :
I.prime_compl β€ J.prime_compl.comap f β J.comap f β€ I :=
β¨Ξ» h x hx, by { contrapose! hx, exact h hx },
Ξ» h x hx hfxJ, hx (h hfxJ)β©
variables (I)
/--
For a ring hom `f : R β+* S` and a prime ideal `J` in `S`, the induced ring hom from the
localization of `R` at `J.comap f` to the localization of `S` at `J`.
To make this definition more flexible, we allow any ideal `I` of `R` as input, together with a proof
that `I = J.comap f`. This can be useful when `I` is not definitionally equal to `J.comap f`.
-/
noncomputable def local_ring_hom (J : ideal P) [hJ : J.is_prime] (f : R β+* P)
(hIJ : I = J.comap f) :
localization.at_prime I β+* localization.at_prime J :=
is_localization.map (localization.at_prime J) f (le_comap_prime_compl_iff.mpr (ge_of_eq hIJ))
lemma local_ring_hom_to_map (J : ideal P) [hJ : J.is_prime] (f : R β+* P)
(hIJ : I = J.comap f) (x : R) :
local_ring_hom I J f hIJ (algebra_map _ _ x) = algebra_map _ _ (f x) :=
map_eq _ _
lemma local_ring_hom_mk' (J : ideal P) [hJ : J.is_prime] (f : R β+* P)
(hIJ : I = J.comap f) (x : R) (y : I.prime_compl) :
local_ring_hom I J f hIJ (is_localization.mk' _ x y) =
is_localization.mk' (localization.at_prime J) (f x)
(β¨f y, le_comap_prime_compl_iff.mpr (ge_of_eq hIJ) y.2β© : J.prime_compl) :=
map_mk' _ _ _
instance is_local_ring_hom_local_ring_hom (J : ideal P) [hJ : J.is_prime] (f : R β+* P)
(hIJ : I = J.comap f) :
is_local_ring_hom (local_ring_hom I J f hIJ) :=
is_local_ring_hom.mk $ Ξ» x hx,
begin
rcases is_localization.mk'_surjective I.prime_compl x with β¨r, s, rflβ©,
rw local_ring_hom_mk' at hx,
rw at_prime.is_unit_mk'_iff at hx β’,
exact Ξ» hr, hx ((set_like.ext_iff.mp hIJ r).mp hr),
end
lemma local_ring_hom_unique (J : ideal P) [hJ : J.is_prime] (f : R β+* P)
(hIJ : I = J.comap f) {j : localization.at_prime I β+* localization.at_prime J}
(hj : β x : R, j (algebra_map _ _ x) = algebra_map _ _ (f x)) :
local_ring_hom I J f hIJ = j :=
map_unique _ _ hj
@[simp] lemma local_ring_hom_id :
local_ring_hom I I (ring_hom.id R) (ideal.comap_id I).symm = ring_hom.id _ :=
local_ring_hom_unique _ _ _ _ (Ξ» x, rfl)
@[simp] lemma local_ring_hom_comp {S : Type*} [comm_ring S]
(J : ideal S) [hJ : J.is_prime] (K : ideal P) [hK : K.is_prime]
(f : R β+* S) (hIJ : I = J.comap f) (g : S β+* P) (hJK : J = K.comap g) :
local_ring_hom I K (g.comp f) (by rw [hIJ, hJK, ideal.comap_comap f g]) =
(local_ring_hom J K g hJK).comp (local_ring_hom I J f hIJ) :=
local_ring_hom_unique _ _ _ _
(Ξ» r, by simp only [function.comp_app, ring_hom.coe_comp, local_ring_hom_to_map])
end localization
open is_localization
/-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/
lemma localization_map_bijective_of_field
{R Rβ : Type*} [comm_ring R] [is_domain R] [comm_ring Rβ]
{M : submonoid R} (hM : (0 : R) β M) (hR : is_field R)
[algebra R Rβ] [is_localization M Rβ] : function.bijective (algebra_map R Rβ) :=
begin
refine β¨is_localization.injective _ (le_non_zero_divisors_of_no_zero_divisors hM), Ξ» x, _β©,
obtain β¨r, β¨m, hmβ©, rflβ© := mk'_surjective M x,
obtain β¨n, hnβ© := hR.mul_inv_cancel (Ξ» hm0, hM (hm0 βΈ hm) : m β 0),
exact β¨r * n,
by erw [eq_mk'_iff_mul_eq, β ring_hom.map_mul, mul_assoc, mul_comm n, hn, mul_one]β©
end
variables (R) {A : Type*} [comm_ring A] [is_domain A]
variables (K : Type*)
/-- `is_fraction_ring R K` states `K` is the field of fractions of an integral domain `R`. -/
-- TODO: should this extend `algebra` instead of assuming it?
abbreviation is_fraction_ring [comm_ring K] [algebra R K] := is_localization (non_zero_divisors R) K
/-- The cast from `int` to `rat` as a `fraction_ring`. -/
instance rat.is_fraction_ring : is_fraction_ring β€ β :=
{ map_units :=
begin
rintro β¨x, hxβ©,
rw mem_non_zero_divisors_iff_ne_zero at hx,
simpa only [ring_hom.eq_int_cast, is_unit_iff_ne_zero, int.cast_eq_zero,
ne.def, subtype.coe_mk] using hx,
end,
surj :=
begin
rintro β¨n, d, hd, hβ©,
refine β¨β¨n, β¨d, _β©β©, rat.mul_denom_eq_numβ©,
rwa [mem_non_zero_divisors_iff_ne_zero, int.coe_nat_ne_zero_iff_pos]
end,
eq_iff_exists :=
begin
intros x y,
rw [ring_hom.eq_int_cast, ring_hom.eq_int_cast, int.cast_inj],
refine β¨by { rintro rfl, use 1 }, _β©,
rintro β¨β¨c, hcβ©, hβ©,
apply int.eq_of_mul_eq_mul_right _ h,
rwa mem_non_zero_divisors_iff_ne_zero at hc,
end }
namespace is_fraction_ring
variables {R K}
section comm_ring
variables [comm_ring K] [algebra R K] [is_fraction_ring R K] [algebra A K] [is_fraction_ring A K]
lemma to_map_eq_zero_iff {x : R} :
algebra_map R K x = 0 β x = 0 :=
to_map_eq_zero_iff _ (le_of_eq rfl)
variables (R K)
protected theorem injective : function.injective (algebra_map R K) :=
is_localization.injective _ (le_of_eq rfl)
variables {R K}
@[simp, mono]
lemma coe_submodule_le_coe_submodule
{I J : ideal R} : coe_submodule K I β€ coe_submodule K J β I β€ J :=
is_localization.coe_submodule_le_coe_submodule le_rfl
@[mono]
lemma coe_submodule_strict_mono :
strict_mono (coe_submodule K : ideal R β submodule R K) :=
strict_mono_of_le_iff_le (Ξ» _ _, coe_submodule_le_coe_submodule.symm)
@[priority 100] instance [no_zero_divisors K] : no_zero_smul_divisors R K :=
no_zero_smul_divisors.of_algebra_map_injective $ is_fraction_ring.injective R K
variables (R K)
lemma coe_submodule_injective :
function.injective (coe_submodule K : ideal R β submodule R K) :=
injective_of_le_imp_le _ (Ξ» _ _, (coe_submodule_le_coe_submodule).mp)
@[simp]
lemma coe_submodule_is_principal {I : ideal R} :
(coe_submodule K I).is_principal β I.is_principal :=
is_localization.coe_submodule_is_principal _ le_rfl
variables {R K}
protected lemma to_map_ne_zero_of_mem_non_zero_divisors [nontrivial R]
{x : R} (hx : x β non_zero_divisors R) : algebra_map R K x β 0 :=
is_localization.to_map_ne_zero_of_mem_non_zero_divisors _ le_rfl hx
variables (A)
/-- A `comm_ring` `K` which is the localization of an integral domain `R` at `R - {0}` is an
integral domain. -/
protected theorem is_domain : is_domain K :=
is_domain_of_le_non_zero_divisors K (le_refl (non_zero_divisors A))
local attribute [instance] classical.dec_eq
/-- The inverse of an element in the field of fractions of an integral domain. -/
@[irreducible]
protected noncomputable def inv (z : K) : K :=
if h : z = 0 then 0 else
mk' K β(sec (non_zero_divisors A) z).2
β¨(sec _ z).1,
mem_non_zero_divisors_iff_ne_zero.2 $ Ξ» h0, h $
eq_zero_of_fst_eq_zero (sec_spec (non_zero_divisors A) z) h0β©
local attribute [semireducible] is_fraction_ring.inv
protected lemma mul_inv_cancel (x : K) (hx : x β 0) :
x * is_fraction_ring.inv A x = 1 :=
show x * dite _ _ _ = 1, by rw [dif_neg hx,
βis_unit.mul_left_inj (map_units K β¨(sec _ x).1, mem_non_zero_divisors_iff_ne_zero.2 $
Ξ» h0, hx $ eq_zero_of_fst_eq_zero (sec_spec (non_zero_divisors A) x) h0β©),
one_mul, mul_assoc, mk'_spec, βeq_mk'_iff_mul_eq]; exact (mk'_sec _ x).symm
/-- A `comm_ring` `K` which is the localization of an integral domain `R` at `R - {0}` is a field.
See note [reducible non-instances]. -/
@[reducible]
noncomputable def to_field : field K :=
{ inv := is_fraction_ring.inv A,
mul_inv_cancel := is_fraction_ring.mul_inv_cancel A,
inv_zero := dif_pos rfl,
.. is_fraction_ring.is_domain A,
.. show comm_ring K, by apply_instance }
end comm_ring
variables {B : Type*} [comm_ring B] [is_domain B] [field K] {L : Type*} [field L]
[algebra A K] [is_fraction_ring A K] {g : A β+* L}
lemma mk'_mk_eq_div {r s} (hs : s β non_zero_divisors A) :
mk' K r β¨s, hsβ© = algebra_map A K r / algebra_map A K s :=
mk'_eq_iff_eq_mul.2 $ (div_mul_cancel (algebra_map A K r)
(is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors hs)).symm
@[simp] lemma mk'_eq_div {r} (s : non_zero_divisors A) :
mk' K r s = algebra_map A K r / algebra_map A K s :=
mk'_mk_eq_div s.2
lemma div_surjective (z : K) : β (x y : A) (hy : y β non_zero_divisors A),
algebra_map _ _ x / algebra_map _ _ y = z :=
let β¨x, β¨y, hyβ©, hβ© := mk'_surjective (non_zero_divisors A) z
in β¨x, y, hy, by rwa mk'_eq_div at hβ©
lemma is_unit_map_of_injective (hg : function.injective g)
(y : non_zero_divisors A) : is_unit (g y) :=
is_unit.mk0 (g y) $ show g.to_monoid_with_zero_hom y β 0,
from map_ne_zero_of_mem_non_zero_divisors g hg y.2
/-- Given an integral domain `A` with field of fractions `K`,
and an injective ring hom `g : A β+* L` where `L` is a field, we get a
field hom sending `z : K` to `g x * (g y)β»ΒΉ`, where `(x, y) : A Γ (non_zero_divisors A)` are
such that `z = f x * (f y)β»ΒΉ`. -/
noncomputable def lift (hg : injective g) : K β+* L :=
lift $ Ξ» (y : non_zero_divisors A), is_unit_map_of_injective hg y
/-- Given an integral domain `A` with field of fractions `K`,
and an injective ring hom `g : A β+* L` where `L` is a field,
the field hom induced from `K` to `L` maps `x` to `g x` for all
`x : A`. -/
@[simp] lemma lift_algebra_map (hg : injective g) (x) :
lift hg (algebra_map A K x) = g x :=
lift_eq _ _
/-- Given an integral domain `A` with field of fractions `K`,
and an injective ring hom `g : A β+* L` where `L` is a field,
field hom induced from `K` to `L` maps `f x / f y` to `g x / g y` for all
`x : A, y β non_zero_divisors A`. -/
lemma lift_mk' (hg : injective g) (x) (y : non_zero_divisors A) :
lift hg (mk' K x y) = g x / g y :=
by simp only [mk'_eq_div, ring_hom.map_div, lift_algebra_map]
/-- Given integral domains `A, B` with fields of fractions `K`, `L`
and an injective ring hom `j : A β+* B`, we get a field hom
sending `z : K` to `g (j x) * (g (j y))β»ΒΉ`, where `(x, y) : A Γ (non_zero_divisors A)` are
such that `z = f x * (f y)β»ΒΉ`. -/
noncomputable def map {A B K L : Type*} [comm_ring A] [comm_ring B] [is_domain B]
[comm_ring K] [algebra A K] [is_fraction_ring A K] [comm_ring L] [algebra B L]
[is_fraction_ring B L] {j : A β+* B} (hj : injective j) :
K β+* L :=
map L j (show non_zero_divisors A β€ (non_zero_divisors B).comap j,
from non_zero_divisors_le_comap_non_zero_divisors_of_injective j hj)
/-- Given integral domains `A, B` and localization maps to their fields of fractions
`f : A β+* K, g : B β+* L`, an isomorphism `j : A β+* B` induces an isomorphism of
fields of fractions `K β+* L`. -/
noncomputable def field_equiv_of_ring_equiv [algebra B L] [is_fraction_ring B L] (h : A β+* B) :
K β+* L :=
ring_equiv_of_ring_equiv K L h
begin
ext b,
show b β h.to_equiv '' _ β _,
erw [h.to_equiv.image_eq_preimage, set.preimage, set.mem_set_of_eq,
mem_non_zero_divisors_iff_ne_zero, mem_non_zero_divisors_iff_ne_zero],
exact h.symm.map_ne_zero_iff
end
lemma integer_normalization_eq_zero_iff {p : polynomial K} :
integer_normalization (non_zero_divisors A) p = 0 β p = 0 :=
begin
refine (polynomial.ext_iff.trans (polynomial.ext_iff.trans _).symm),
obtain β¨β¨b, nonzeroβ©, hbβ© := integer_normalization_spec _ p,
split; intros h i,
{ apply to_map_eq_zero_iff.mp,
rw [hb i, h i],
apply smul_zero,
assumption },
{ have hi := h i,
rw [polynomial.coeff_zero, β @to_map_eq_zero_iff A _ K, hb i, algebra.smul_def] at hi,
apply or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hi),
intro h,
apply mem_non_zero_divisors_iff_ne_zero.mp nonzero,
exact to_map_eq_zero_iff.mp h }
end
section
variables (A K) (C : Type*)
variables [comm_ring C]
/-- An element of a ring is algebraic over the ring `A` iff it is algebraic
over the field of fractions of `A`.
-/
lemma is_algebraic_iff [algebra A C] [algebra K C] [is_scalar_tower A K C] {x : C} :
is_algebraic A x β is_algebraic K x :=
begin
split; rintros β¨p, hp, pxβ©,
{ refine β¨p.map (algebra_map A K), Ξ» h, hp (polynomial.ext (Ξ» i, _)), _β©,
{ have : algebra_map A K (p.coeff i) = 0 := trans (polynomial.coeff_map _ _).symm (by simp [h]),
exact to_map_eq_zero_iff.mp this },
{ rwa is_scalar_tower.aeval_apply _ K at px } },
{ exact β¨integer_normalization _ p,
mt integer_normalization_eq_zero_iff.mp hp,
integer_normalization_aeval_eq_zero _ p pxβ© },
end
variables {A K C}
/-- A ring is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`.
-/
lemma comap_is_algebraic_iff [algebra A C] [algebra K C] [is_scalar_tower A K C] :
algebra.is_algebraic A C β algebra.is_algebraic K C :=
β¨Ξ» h x, (is_algebraic_iff A K C).mp (h x), Ξ» h x, (is_algebraic_iff A K C).mpr (h x)β©
end
section num_denom
variables (A) [unique_factorization_monoid A]
lemma exists_reduced_fraction (x : K) :
β (a : A) (b : non_zero_divisors A),
(β {d}, d β£ a β d β£ b β is_unit d) β§ mk' K a b = x :=
begin
obtain β¨β¨b, b_nonzeroβ©, a, habβ© := exists_integer_multiple (non_zero_divisors A) x,
obtain β¨a', b', c', no_factor, rfl, rflβ© :=
unique_factorization_monoid.exists_reduced_factors' a b
(mem_non_zero_divisors_iff_ne_zero.mp b_nonzero),
obtain β¨c'_nonzero, b'_nonzeroβ© := mul_mem_non_zero_divisors.mp b_nonzero,
refine β¨a', β¨b', b'_nonzeroβ©, @no_factor, _β©,
refine mul_left_cancelβ
(is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors b_nonzero) _,
simp only [subtype.coe_mk, ring_hom.map_mul, algebra.smul_def] at *,
erw [βhab, mul_assoc, mk'_spec' _ a' β¨b', b'_nonzeroβ©],
end
/-- `f.num x` is the numerator of `x : f.codomain` as a reduced fraction. -/
noncomputable def num (x : K) : A :=
classical.some (exists_reduced_fraction A x)
/-- `f.num x` is the denominator of `x : f.codomain` as a reduced fraction. -/
noncomputable def denom (x : K) : non_zero_divisors A :=
classical.some (classical.some_spec (exists_reduced_fraction A x))
lemma num_denom_reduced (x : K) :
β {d}, d β£ num A x β d β£ denom A x β is_unit d :=
(classical.some_spec (classical.some_spec (exists_reduced_fraction A x))).1
@[simp] lemma mk'_num_denom (x : K) : mk' K (num A x) (denom A x) = x :=
(classical.some_spec (classical.some_spec (exists_reduced_fraction A x))).2
variables {A}
lemma num_mul_denom_eq_num_iff_eq {x y : K} :
x * algebra_map A K (denom A y) = algebra_map A K (num A y) β x = y :=
β¨Ξ» h, by simpa only [mk'_num_denom] using eq_mk'_iff_mul_eq.mpr h,
Ξ» h, eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_denom])β©
lemma num_mul_denom_eq_num_iff_eq' {x y : K} :
y * algebra_map A K (denom A x) = algebra_map A K (num A x) β x = y :=
β¨Ξ» h, by simpa only [eq_comm, mk'_num_denom] using eq_mk'_iff_mul_eq.mpr h,
Ξ» h, eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_denom])β©
lemma num_mul_denom_eq_num_mul_denom_iff_eq {x y : K} :
num A y * denom A x = num A x * denom A y β x = y :=
β¨Ξ» h, by simpa only [mk'_num_denom] using mk'_eq_of_eq h,
Ξ» h, by rw hβ©
lemma eq_zero_of_num_eq_zero {x : K} (h : num A x = 0) : x = 0 :=
num_mul_denom_eq_num_iff_eq'.mp (by rw [zero_mul, h, ring_hom.map_zero])
lemma is_integer_of_is_unit_denom {x : K} (h : is_unit (denom A x : A)) : is_integer A x :=
begin
cases h with d hd,
have d_ne_zero : algebra_map A K (denom A x) β 0 :=
is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors (denom A x).2,
use βdβ»ΒΉ * num A x,
refine trans _ (mk'_num_denom A x),
rw [ring_hom.map_mul, ring_hom.map_units_inv, hd],
apply mul_left_cancelβ d_ne_zero,
rw [βmul_assoc, mul_inv_cancel d_ne_zero, one_mul, mk'_spec']
end
lemma is_unit_denom_of_num_eq_zero {x : K} (h : num A x = 0) : is_unit (denom A x : A) :=
num_denom_reduced A x (h.symm βΈ dvd_zero _) dvd_rfl
end num_denom
variables (S)
lemma is_fraction_ring_iff_of_base_ring_equiv (h : R β+* P) :
is_fraction_ring R S β
@@is_fraction_ring P _ S _ ((algebra_map R S).comp h.symm.to_ring_hom).to_algebra :=
begin
delta is_fraction_ring,
convert is_localization_iff_of_base_ring_equiv _ _ h,
ext x,
erw submonoid.map_equiv_eq_comap_symm,
simp only [mul_equiv.coe_to_monoid_hom,
ring_equiv.to_mul_equiv_eq_coe, submonoid.mem_comap],
split,
{ rintros hx z (hz : z * h.symm x = 0),
rw β h.map_eq_zero_iff,
apply hx,
simpa only [h.map_zero, h.apply_symm_apply, h.map_mul] using congr_arg h hz },
{ rintros (hx : h.symm x β _) z hz,
rw β h.symm.map_eq_zero_iff,
apply hx,
rw [β h.symm.map_mul, hz, h.symm.map_zero] }
end
variable (M)
lemma is_fraction_ring_of_is_localization (S T : Type*) [comm_ring S] [comm_ring T]
[algebra R S] [algebra R T] [algebra S T] [is_scalar_tower R S T]
[is_localization M S] [is_fraction_ring R T] (hM : M β€ non_zero_divisors R) :
is_fraction_ring S T :=
begin
have := is_localization_of_submonoid_le S T M (non_zero_divisors R) _,
refine @@is_localization_of_is_exists_mul_mem _ _ _ _ _ _ this _ _,
{ exact map_non_zero_divisors_le M S },
{ rintro β¨x, hxβ©,
obtain β¨β¨y, sβ©, eβ© := is_localization.surj M x,
use algebra_map R S s,
rw [mul_comm, subtype.coe_mk, e],
refine set.mem_image_of_mem (algebra_map R S) _,
intros z hz,
apply is_localization.injective S hM,
rw map_zero,
apply hx,
rw [β (map_units S s).mul_left_inj, mul_assoc, e, β map_mul, hz, map_zero, zero_mul] },
{ exact hM }
end
protected
lemma nontrivial (R S : Type*) [comm_ring R] [nontrivial R] [comm_ring S] [algebra R S]
[is_fraction_ring R S] : nontrivial S :=
begin
apply nontrivial_of_ne,
intro h,
apply @zero_ne_one R,
exact is_localization.injective S (le_of_eq rfl)
(((algebra_map R S).map_zero.trans h).trans (algebra_map R S).map_one.symm),
end
lemma is_fraction_ring_of_is_domain_of_is_localization [is_domain R] (S T : Type*)
[comm_ring S] [comm_ring T] [algebra R S] [algebra R T] [algebra S T]
[is_scalar_tower R S T] [is_localization M S] [is_fraction_ring R T] : is_fraction_ring S T :=
begin
haveI := is_fraction_ring.nontrivial R T,
haveI := (algebra_map S T).domain_nontrivial,
apply is_fraction_ring_of_is_localization M S T,
intros x hx,
rw mem_non_zero_divisors_iff_ne_zero,
intro hx',
apply @zero_ne_one S,
rw [β (algebra_map R S).map_one, β @mk'_one R _ M, @comm _ eq, mk'_eq_zero_iff],
exact β¨β¨_, hxβ©, (one_mul x).symm βΈ hx'β©,
end
end is_fraction_ring
section algebra
section is_integral
variables {R S} {Rβ Sβ : Type*} [comm_ring Rβ] [comm_ring Sβ]
variables [algebra R Rβ] [is_localization M Rβ]
variables [algebra S Sβ] [is_localization (algebra.algebra_map_submonoid S M) Sβ]
section
variables (S M)
/-- Definition of the natural algebra induced by the localization of an algebra.
Given an algebra `R β S`, a submonoid `R` of `M`, and a localization `Rβ` for `M`,
let `Sβ` be the localization of `S` to the image of `M` under `algebra_map R S`.
Then this is the natural algebra structure on `Rβ β Sβ`, such that the entire square commutes,
where `localization_map.map_comp` gives the commutativity of the underlying maps -/
noncomputable def localization_algebra : algebra Rβ Sβ :=
(map Sβ (algebra_map R S)
(show _ β€ (algebra.algebra_map_submonoid S M).comap _, from M.le_comap_map)
: Rβ β+* Sβ).to_algebra
end
lemma algebra_map_mk' (r : R) (m : M) :
(@algebra_map Rβ Sβ _ _ (localization_algebra M S)) (mk' Rβ r m) =
mk' Sβ (algebra_map R S r) β¨algebra_map R S m, algebra.mem_algebra_map_submonoid_of_mem mβ© :=
map_mk' _ _ _
variables (Rβ Sβ)
/-- Injectivity of the underlying `algebra_map` descends to the algebra induced by localization. -/
lemma localization_algebra_injective (hRS : function.injective (algebra_map R S))
(hM : algebra.algebra_map_submonoid S M β€ non_zero_divisors S) :
function.injective (@algebra_map Rβ Sβ _ _ (localization_algebra M S)) :=
is_localization.map_injective_of_injective M Rβ Sβ hRS hM
variables {Rβ Sβ}
open polynomial
lemma ring_hom.is_integral_elem_localization_at_leading_coeff
{R S : Type*} [comm_ring R] [comm_ring S] (f : R β+* S)
(x : S) (p : polynomial R) (hf : p.evalβ f x = 0) (M : submonoid R)
(hM : p.leading_coeff β M) {Rβ Sβ : Type*} [comm_ring Rβ] [comm_ring Sβ]
[algebra R Rβ] [is_localization M Rβ]
[algebra S Sβ] [is_localization (M.map f : submonoid S) Sβ] :
(map Sβ f M.le_comap_map : Rβ β+* _).is_integral_elem (algebra_map S Sβ x) :=
begin
by_cases triv : (1 : Rβ) = 0,
{ exact β¨0, β¨trans leading_coeff_zero triv.symm, evalβ_zero _ _β©β© },
haveI : nontrivial Rβ := nontrivial_of_ne 1 0 triv,
obtain β¨b, hbβ© := is_unit_iff_exists_inv.mp
(map_units Rβ β¨p.leading_coeff, hMβ©),
refine β¨(p.map (algebra_map R Rβ)) * C b, β¨_, _β©β©,
{ refine monic_mul_C_of_leading_coeff_mul_eq_one _,
rwa leading_coeff_map_of_leading_coeff_ne_zero (algebra_map R Rβ),
refine Ξ» hfp, zero_ne_one (trans (zero_mul b).symm (hfp βΈ hb) : (0 : Rβ) = 1) },
{ refine evalβ_mul_eq_zero_of_left _ _ _ _,
erw [evalβ_map, is_localization.map_comp, β hom_evalβ _ f (algebra_map S Sβ) x],
exact trans (congr_arg (algebra_map S Sβ) hf) (ring_hom.map_zero _) }
end
/-- Given a particular witness to an element being algebraic over an algebra `R β S`,
We can localize to a submonoid containing the leading coefficient to make it integral.
Explicitly, the map between the localizations will be an integral ring morphism -/
theorem is_integral_localization_at_leading_coeff {x : S} (p : polynomial R)
(hp : aeval x p = 0) (hM : p.leading_coeff β M) :
(map Sβ (algebra_map R S)
(show _ β€ (algebra.algebra_map_submonoid S M).comap _, from M.le_comap_map)
: Rβ β+* _).is_integral_elem (algebra_map S Sβ x) :=
(algebra_map R S).is_integral_elem_localization_at_leading_coeff x p hp M hM
/-- If `R β S` is an integral extension, `M` is a submonoid of `R`,
`Rβ` is the localization of `R` at `M`,
and `Sβ` is the localization of `S` at the image of `M` under the extension map,
then the induced map `Rβ β Sβ` is also an integral extension -/
theorem is_integral_localization (H : algebra.is_integral R S) :
(map Sβ (algebra_map R S)
(show _ β€ (algebra.algebra_map_submonoid S M).comap _, from M.le_comap_map)
: Rβ β+* _).is_integral :=
begin
intro x,
obtain β¨β¨s, β¨u, huβ©β©, hxβ© := surj (algebra.algebra_map_submonoid S M) x,
obtain β¨v, hvβ© := hu,
obtain β¨v', hv'β© := is_unit_iff_exists_inv'.1 (map_units Rβ β¨v, hv.1β©),
refine @is_integral_of_is_integral_mul_unit Rβ _ _ _
(localization_algebra M S) x (algebra_map S Sβ u) v' _ _,
{ replace hv' := congr_arg (@algebra_map Rβ Sβ _ _ (localization_algebra M S)) hv',
rw [ring_hom.map_mul, ring_hom.map_one, β ring_hom.comp_apply _ (algebra_map R Rβ)] at hv',
erw is_localization.map_comp at hv',
exact hv.2 βΈ hv' },
{ obtain β¨p, hpβ© := H s,
exact hx.symm βΈ is_integral_localization_at_leading_coeff p hp.2 (hp.1.symm βΈ M.one_mem) }
end
lemma is_integral_localization' {R S : Type*} [comm_ring R] [comm_ring S]
{f : R β+* S} (hf : f.is_integral) (M : submonoid R) :
(map (localization (M.map (f : R β* S))) f M.le_comap_map : localization M β+* _).is_integral :=
@is_integral_localization R _ M S _ f.to_algebra _ _ _ _ _ _ _ _ hf
end is_integral
namespace is_integral_closure
variables (A) {L : Type*} [field K] [field L] [algebra A K] [algebra A L] [is_fraction_ring A K]
variables (C : Type*) [comm_ring C] [is_domain C] [algebra C L] [is_integral_closure C A L]
variables [algebra A C] [is_scalar_tower A C L]
open algebra
/-- If the field `L` is an algebraic extension of the integral domain `A`,
the integral closure `C` of `A` in `L` has fraction field `L`. -/
lemma is_fraction_ring_of_algebraic (alg : is_algebraic A L)
(inj : β x, algebra_map A L x = 0 β x = 0) :
is_fraction_ring C L :=
{ map_units := Ξ» β¨y, hyβ©,
is_unit.mk0 _ (show algebra_map C L y β 0, from Ξ» h, mem_non_zero_divisors_iff_ne_zero.mp hy
((algebra_map C L).injective_iff.mp (algebra_map_injective C A L) _ h)),
surj := Ξ» z, let β¨x, y, hy, hxyβ© := exists_integral_multiple (alg z) inj in
β¨β¨mk' C (x : L) x.2, algebra_map _ _ y,
mem_non_zero_divisors_iff_ne_zero.mpr (Ξ» h, hy (inj _
(by rw [is_scalar_tower.algebra_map_apply A C L, h, ring_hom.map_zero])))β©,
by rw [set_like.coe_mk, algebra_map_mk', β is_scalar_tower.algebra_map_apply A C L, hxy]β©,
eq_iff_exists := Ξ» x y, β¨Ξ» h, β¨1, by simpa using algebra_map_injective C A L hβ©, Ξ» β¨c, hcβ©,
congr_arg (algebra_map _ L) (mul_right_cancelβ (mem_non_zero_divisors_iff_ne_zero.mp c.2) hc)β© }
variables (K L)
/-- If the field `L` is a finite extension of the fraction field of the integral domain `A`,
the integral closure `C` of `A` in `L` has fraction field `L`. -/
lemma is_fraction_ring_of_finite_extension [algebra K L] [is_scalar_tower A K L]
[finite_dimensional K L] : is_fraction_ring C L :=
is_fraction_ring_of_algebraic A C
(is_fraction_ring.comap_is_algebraic_iff.mpr (is_algebraic_of_finite K L))
(Ξ» x hx, is_fraction_ring.to_map_eq_zero_iff.mp ((algebra_map K L).map_eq_zero.mp $
(is_scalar_tower.algebra_map_apply _ _ _ _).symm.trans hx))
end is_integral_closure
namespace integral_closure
variables {L : Type*} [field K] [field L] [algebra A K] [is_fraction_ring A K]
open algebra
/-- If the field `L` is an algebraic extension of the integral domain `A`,
the integral closure of `A` in `L` has fraction field `L`. -/
lemma is_fraction_ring_of_algebraic [algebra A L] (alg : is_algebraic A L)
(inj : β x, algebra_map A L x = 0 β x = 0) :
is_fraction_ring (integral_closure A L) L :=
is_integral_closure.is_fraction_ring_of_algebraic A (integral_closure A L) alg inj
variables (K L)
/-- If the field `L` is a finite extension of the fraction field of the integral domain `A`,
the integral closure of `A` in `L` has fraction field `L`. -/
lemma is_fraction_ring_of_finite_extension [algebra A L] [algebra K L]
[is_scalar_tower A K L] [finite_dimensional K L] :
is_fraction_ring (integral_closure A L) L :=
is_integral_closure.is_fraction_ring_of_finite_extension A K L (integral_closure A L)
end integral_closure
end algebra
variables (R A)
/-- The fraction ring of a commutative ring `R` as a quotient type.
We instantiate this definition as generally as possible, and assume that the
commutative ring `R` is an integral domain only when this is needed for proving.
-/
@[reducible] def fraction_ring := localization (non_zero_divisors R)
namespace fraction_ring
instance [subsingleton R] : subsingleton (fraction_ring R) :=
localization.subsingleton
instance [nontrivial R] : nontrivial (fraction_ring R) :=
β¨β¨(algebra_map R _) 0, (algebra_map _ _) 1,
Ξ» H, zero_ne_one (is_localization.injective _ le_rfl H)β©β©
variables {A}
noncomputable instance : field (fraction_ring A) :=
{ add := (+),
mul := (*),
neg := has_neg.neg,
sub := has_sub.sub,
one := 1,
zero := 0,
nsmul := add_monoid.nsmul,
zsmul := sub_neg_monoid.zsmul,
npow := localization.npow _,
.. localization.comm_ring,
.. is_fraction_ring.to_field A }
@[simp] lemma mk_eq_div {r s} : (localization.mk r s : fraction_ring A) =
(algebra_map _ _ r / algebra_map A _ s : fraction_ring A) :=
by rw [localization.mk_eq_mk', is_fraction_ring.mk'_eq_div]
noncomputable instance [is_domain R] [field K] [algebra R K] [no_zero_smul_divisors R K] :
algebra (fraction_ring R) K :=
ring_hom.to_algebra (is_fraction_ring.lift (no_zero_smul_divisors.algebra_map_injective R _))
instance [is_domain R] [field K] [algebra R K] [no_zero_smul_divisors R K] :
is_scalar_tower R (fraction_ring R) K :=
is_scalar_tower.of_algebra_map_eq (Ξ» x, (is_fraction_ring.lift_algebra_map _ x).symm)
variables (A)
/-- Given an integral domain `A` and a localization map to a field of fractions
`f : A β+* K`, we get an `A`-isomorphism between the field of fractions of `A` as a quotient
type and `K`. -/
noncomputable def alg_equiv (K : Type*) [field K] [algebra A K] [is_fraction_ring A K] :
fraction_ring A ββ[A] K :=
localization.alg_equiv (non_zero_divisors A) K
instance [algebra R A] [no_zero_smul_divisors R A] : no_zero_smul_divisors R (fraction_ring A) :=
no_zero_smul_divisors.of_algebra_map_injective
begin
rw [is_scalar_tower.algebra_map_eq R A],
exact function.injective.comp
(no_zero_smul_divisors.algebra_map_injective _ _)
(no_zero_smul_divisors.algebra_map_injective _ _)
end
end fraction_ring
namespace is_fraction_ring
variables (R S K)
/-- `S` is algebraic over `R` iff a fraction ring of `S` is algebraic over `R` -/
lemma is_algebraic_iff' [field K] [is_domain R] [is_domain S] [algebra R K] [algebra S K]
[no_zero_smul_divisors R K] [is_fraction_ring S K] [is_scalar_tower R S K] :
algebra.is_algebraic R S β algebra.is_algebraic R K :=
begin
simp only [algebra.is_algebraic],
split,
{ intros h x,
rw [is_fraction_ring.is_algebraic_iff R (fraction_ring R) K, is_algebraic_iff_is_integral],
obtain β¨(a : S), b, ha, rflβ© := @div_surjective S _ _ _ _ _ _ x,
obtain β¨f, hfβ, hfββ© := h b,
rw [div_eq_mul_inv],
refine is_integral_mul _ _,
{ rw [β is_algebraic_iff_is_integral],
refine _root_.is_algebraic_of_larger_base_of_injective
(no_zero_smul_divisors.algebra_map_injective R (fraction_ring R)) _,
exact is_algebraic_algebra_map_of_is_algebraic (h a) },
{ rw [β is_algebraic_iff_is_integral],
use (f.map (algebra_map R (fraction_ring R))).reverse,
split,
{ rwa [ne.def, polynomial.reverse_eq_zero, β polynomial.degree_eq_bot,
polynomial.degree_map_eq_of_injective
(no_zero_smul_divisors.algebra_map_injective R (fraction_ring R)),
polynomial.degree_eq_bot]},
{ haveI : invertible (algebra_map S K b),
from is_unit.invertible (is_unit_of_mem_non_zero_divisors
(mem_non_zero_divisors_iff_ne_zero.2
(Ξ» h, non_zero_divisors.ne_zero ha
((ring_hom.injective_iff (algebra_map S K)).1
(no_zero_smul_divisors.algebra_map_injective _ _) b h)))),
rw [polynomial.aeval_def, β inv_of_eq_inv, polynomial.evalβ_reverse_eq_zero_iff,
polynomial.evalβ_map, β is_scalar_tower.algebra_map_eq, β polynomial.aeval_def,
β is_scalar_tower.algebra_map_aeval, hfβ, ring_hom.map_zero] } } },
{ intros h x,
obtain β¨f, hfβ, hfββ© := h (algebra_map S K x),
use [f, hfβ],
rw [β is_scalar_tower.algebra_map_aeval] at hfβ,
exact (algebra_map S K).injective_iff.1
(no_zero_smul_divisors.algebra_map_injective _ _) _ hfβ }
end
end is_fraction_ring
|
c8ff6f4c645211a839b984a6381b0c5a9fd1351e
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/simp6.lean
|
313cf358ed5a0fa3cf7ad05600b2a4578579fe3a
|
[
"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
| 153
|
lean
|
variables a b : Nat
rewrite_set simple
add_rewrite Nat::add_comm eq_id : simple
(*
local t = parse_lean("a + b = b + a")
print(simplify(t, 'simple'))
*)
|
24ed611acfd7b85ba351fe74d57eac7cea7f902f
|
7afc29faca4febb6e5005c20aa4aa5c3df5cf35c
|
/src/height.lean
|
134ef45337d4e7f5243e6884fa40ce61b4463925
|
[
"MIT"
] |
permissive
|
Piwry/Proof-of-Surreal
|
ad2883027e275050b43a578c5513ae3fe350515b
|
6b92baf2382ac23dd0d700f5c958aa910ad4b754
|
refs/heads/master
| 1,670,521,185,736
| 1,599,657,591,000
| 1,599,657,591,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,442
|
lean
|
import data.list tactic defs single
@[simp]
lemma height_ge1 : β t : bintree, height t β₯ 1 :=
begin
intros t,
destruct t,
repeat {
try {intros t H}, try {intros H}, rewrite H, repeat { unfold height }, omega
}
end
@[simp]
lemma height_ne0 : β t : bintree, Β¬(height t = 0) :=
begin
intros t contra,
have ht : height t β₯ 1 := by simp,
rewrite contra at ht, cases ht
end
@[simp]
lemma height_nle0 : β t : bintree, Β¬(height t β€ 0) :=
begin
intros t contra,
have ht : height t = 0, omega,
eapply height_ne0, assumption
end
meta def pos_height : tactic unit :=
do
tactic.exfalso,
tactic.try (
do tactic.eapplyc `height_ne0,
tactic.assumption
),
tactic.try (
do tactic.eapplyc `height_nle0,
tactic.assumption
)
lemma height_le1_single : β t : bintree, height t β€ 1 β t = β :=
begin
intros t h1,
have h2 : height t β₯ 1, simp,
have ht : height t = 1, omega,
cases t,
trivial,
repeat {
unfold height at ht, have ht' : height t = 0, omega,
pos_height,
},
begin
unfold height at ht, have ht' : max (height t_a) (height t_a_1) = 0, omega,
have ht'' : height t_a β€ max (height t_a) (height t_a_1), apply le_max_left,
rewrite ht' at ht'',
pos_height,
end
end
lemma grow_height : β t' t : bintree, (t β£ t') β height t β€ height t' :=
begin
intros t', induction t',
begin -- single
intros, unfold height,
rewrite (single_grow _ a), unfold height
end,
begin -- left
intros t h1,
cases t,
begin unfold height, apply ge.le, omega, end,
begin
unfold height,
have h2 : (t β£ t'_a), cases h1, repeat {assumption},
simp, apply t'_ih, assumption
end,
repeat {cases h1},
end,
begin -- right
intros t h1,
cases t,
begin unfold height, apply ge.le, omega, end,
cases h1,
begin
unfold height,
have h2 : (t β£ t'_a), cases h1, repeat {assumption},
simp, apply t'_ih, assumption
end,
cases h1
end,
begin -- full
intros t h1,
cases t,
begin unfold height, omega end,
cases h1,
cases h1,
begin
unfold height, cases h1,
have h3 : height t_a β€ height t'_a, apply t'_ih_a, assumption,
have h3' : height t_a_1 β€ height t'_a_1, apply t'_ih_a_1, assumption,
have h4 : max (height t_a) (height t_a_1) β€ max (height t'_a) (height t'_a_1), apply max_le_max, repeat {assumption},
omega
end
end
end
lemma iso_height : β t t' : bintree, (t = t') β height t = height t' :=
begin
intros, rewrite a
end
lemma height_neq_niso : β t t' : bintree, height t β height t' β t β t' :=
begin
intros, intro contra, apply a, rewrite contra
end
@[simp]
def height_bound : list bintree β β
| [] := 1
| (t :: l) := max (height t) (height_bound l)
lemma height_bound_correct : β l t, t β l β height t β€ height_bound l :=
begin
intros l t h,
induction l,
begin cases h end,
begin
unfold height_bound,
cases h,
begin rewrite h, apply le_max_left end,
begin
eapply le_trans,
apply l_ih, assumption,
apply le_max_right
end
end
end
lemma height_bound_ge1 : β l, height_bound l β₯ 1 :=
begin
intros l,
induction l,
unfold height_bound, omega,
unfold height_bound, eapply ge_trans,
begin apply has_le.le.ge, apply le_max_right end,
begin assumption end
end
|
c3400153fd25782bd745af86146e56686faa2902
|
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
|
/tests/lean/run/structInst3.lean
|
a54ab755d1be879031a479e73015928c8ce4bf14
|
[
"Apache-2.0"
] |
permissive
|
walterhu1015/lean4
|
b2c71b688975177402758924eaa513475ed6ce72
|
2214d81e84646a905d0b20b032c89caf89c737ad
|
refs/heads/master
| 1,671,342,096,906
| 1,599,695,985,000
| 1,599,695,985,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 463
|
lean
|
universes u
namespace Ex1
structure A (Ξ± : Type u) :=
(x : Ξ±) (f : Ξ± β Ξ± := Ξ» x => x)
structure B (Ξ± : Type u) extends A Ξ± :=
(y : Ξ± := f (f x)) (g : Ξ± β Ξ± β Ξ± := Ξ» x y => f x)
structure C (Ξ± : Type u) extends B Ξ± :=
(z : Ξ± := g x y) (x := f z)
end Ex1
new_frontend
open Ex1
def c1 : C Nat := { x := 1 }
#check { c1 with z := 2 }
def c2 : C (Nat Γ Nat) := { z := (1, 1) }
#check { c2 with x.fst := 2 }
#check { c2 with x.1 := 3 }
|
665f867f9ba3257853d59ada431d731f939c6dfd
|
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
|
/src/order/rel_classes.lean
|
e7b871d694bbb6a9216b5800f442884165646da9
|
[
"Apache-2.0"
] |
permissive
|
dupuisf/mathlib
|
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
|
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
|
refs/heads/master
| 1,669,494,854,016
| 1,595,692,409,000
| 1,595,692,409,000
| 272,046,630
| 0
| 0
|
Apache-2.0
| 1,592,066,143,000
| 1,592,066,142,000
| null |
UTF-8
|
Lean
| false
| false
| 16,850
|
lean
|
/-
Copyright (c) 2020 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro, Yury G. Kudryashov
-/
import data.set.basic
/-!
# Unbundled relation classes
In this file we prove some properties of `is_*` classes defined in `init.algebra.classes`. The main
difference between these classes and the usual order classes (`preorder` etc) is that usual classes
extend `has_le` and/or `has_lt` while these classes take a relation as an explicit argument.
-/
universes u v
variables {Ξ± : Type u} {Ξ² : Type v} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
open function
theorem is_refl.swap (r) [is_refl Ξ± r] : is_refl Ξ± (swap r) := β¨refl_of rβ©
theorem is_irrefl.swap (r) [is_irrefl Ξ± r] : is_irrefl Ξ± (swap r) := β¨irrefl_of rβ©
theorem is_trans.swap (r) [is_trans Ξ± r] : is_trans Ξ± (swap r) :=
β¨Ξ» a b c hβ hβ, trans_of r hβ hββ©
theorem is_antisymm.swap (r) [is_antisymm Ξ± r] : is_antisymm Ξ± (swap r) :=
β¨Ξ» a b hβ hβ, antisymm hβ hββ©
theorem is_asymm.swap (r) [is_asymm Ξ± r] : is_asymm Ξ± (swap r) :=
β¨Ξ» a b hβ hβ, asymm_of r hβ hββ©
theorem is_total.swap (r) [is_total Ξ± r] : is_total Ξ± (swap r) :=
β¨Ξ» a b, (total_of r a b).swapβ©
theorem is_trichotomous.swap (r) [is_trichotomous Ξ± r] : is_trichotomous Ξ± (swap r) :=
β¨Ξ» a b, by simpa [swap, or.comm, or.left_comm] using trichotomous_of r a bβ©
theorem is_preorder.swap (r) [is_preorder Ξ± r] : is_preorder Ξ± (swap r) :=
{..@is_refl.swap Ξ± r _, ..@is_trans.swap Ξ± r _}
theorem is_strict_order.swap (r) [is_strict_order Ξ± r] : is_strict_order Ξ± (swap r) :=
{..@is_irrefl.swap Ξ± r _, ..@is_trans.swap Ξ± r _}
theorem is_partial_order.swap (r) [is_partial_order Ξ± r] : is_partial_order Ξ± (swap r) :=
{..@is_preorder.swap Ξ± r _, ..@is_antisymm.swap Ξ± r _}
theorem is_total_preorder.swap (r) [is_total_preorder Ξ± r] : is_total_preorder Ξ± (swap r) :=
{..@is_preorder.swap Ξ± r _, ..@is_total.swap Ξ± r _}
theorem is_linear_order.swap (r) [is_linear_order Ξ± r] : is_linear_order Ξ± (swap r) :=
{..@is_partial_order.swap Ξ± r _, ..@is_total.swap Ξ± r _}
protected theorem is_asymm.is_antisymm (r) [is_asymm Ξ± r] : is_antisymm Ξ± r :=
β¨Ξ» x y hβ hβ, (asymm hβ hβ).elimβ©
protected theorem is_asymm.is_irrefl [is_asymm Ξ± r] : is_irrefl Ξ± r :=
β¨Ξ» a h, asymm h hβ©
/- Convert algebraic structure style to explicit relation style typeclasses -/
instance [preorder Ξ±] : is_refl Ξ± (β€) := β¨le_reflβ©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_refl Ξ± (β₯) := is_refl.swap _
instance [preorder Ξ±] : is_trans Ξ± (β€) := β¨@le_trans _ _β©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_trans Ξ± (β₯) := is_trans.swap _
instance [preorder Ξ±] : is_preorder Ξ± (β€) := {}
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_preorder Ξ± (β₯) := {}
instance [preorder Ξ±] : is_irrefl Ξ± (<) := β¨lt_irreflβ©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_irrefl Ξ± (>) := is_irrefl.swap _
instance [preorder Ξ±] : is_trans Ξ± (<) := β¨@lt_trans _ _β©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_trans Ξ± (>) := is_trans.swap _
instance [preorder Ξ±] : is_asymm Ξ± (<) := β¨@lt_asymm _ _β©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_asymm Ξ± (>) := is_asymm.swap _
instance [preorder Ξ±] : is_antisymm Ξ± (<) := is_asymm.is_antisymm _
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_antisymm Ξ± (>) := is_asymm.is_antisymm _
instance [preorder Ξ±] : is_strict_order Ξ± (<) := {}
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [preorder Ξ±] : is_strict_order Ξ± (>) := {}
instance preorder.is_total_preorder [preorder Ξ±] [is_total Ξ± (β€)] : is_total_preorder Ξ± (β€) := {}
instance [partial_order Ξ±] : is_antisymm Ξ± (β€) := β¨@le_antisymm _ _β©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [partial_order Ξ±] : is_antisymm Ξ± (β₯) := is_antisymm.swap _
instance [partial_order Ξ±] : is_partial_order Ξ± (β€) := {}
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [partial_order Ξ±] : is_partial_order Ξ± (β₯) := {}
instance [linear_order Ξ±] : is_total Ξ± (β€) := β¨le_totalβ©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [linear_order Ξ±] : is_total Ξ± (β₯) := is_total.swap _
instance linear_order.is_total_preorder [linear_order Ξ±] : is_total_preorder Ξ± (β€) :=
by apply_instance
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [linear_order Ξ±] : is_total_preorder Ξ± (β₯) := {}
instance [linear_order Ξ±] : is_linear_order Ξ± (β€) := {}
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [linear_order Ξ±] : is_linear_order Ξ± (β₯) := {}
instance [linear_order Ξ±] : is_trichotomous Ξ± (<) := β¨lt_trichotomyβ©
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance [linear_order Ξ±] : is_trichotomous Ξ± (>) := is_trichotomous.swap _
lemma trans_trichotomous_left [is_trans Ξ± r] [is_trichotomous Ξ± r] {a b c : Ξ±} :
Β¬r b a β r b c β r a c :=
begin
intros hβ hβ, rcases trichotomous_of r a b with hβ|hβ|hβ,
exact trans hβ hβ, rw hβ, exact hβ, exfalso, exact hβ hβ
end
lemma trans_trichotomous_right [is_trans Ξ± r] [is_trichotomous Ξ± r] {a b c : Ξ±} :
r a b β Β¬r c b β r a c :=
begin
intros hβ hβ, rcases trichotomous_of r b c with hβ|hβ|hβ,
exact trans hβ hβ, rw βhβ, exact hβ, exfalso, exact hβ hβ
end
/-- Construct a partial order from a `is_strict_order` relation -/
def partial_order_of_SO (r) [is_strict_order Ξ± r] : partial_order Ξ± :=
{ le := Ξ» x y, x = y β¨ r x y,
lt := r,
le_refl := Ξ» x, or.inl rfl,
le_trans := Ξ» x y z hβ hβ,
match y, z, hβ, hβ with
| _, _, or.inl rfl, hβ := hβ
| _, _, hβ, or.inl rfl := hβ
| _, _, or.inr hβ, or.inr hβ := or.inr (trans hβ hβ)
end,
le_antisymm := Ξ» x y hβ hβ,
match y, hβ, hβ with
| _, or.inl rfl, hβ := rfl
| _, hβ, or.inl rfl := rfl
| _, or.inr hβ, or.inr hβ := (asymm hβ hβ).elim
end,
lt_iff_le_not_le := Ξ» x y,
β¨Ξ» h, β¨or.inr h, not_or
(Ξ» e, by rw e at h; exact irrefl _ h)
(asymm h)β©,
Ξ» β¨hβ, hββ©, hβ.resolve_left (Ξ» e, hβ $ e βΈ or.inl rfl)β© }
section prio
set_option default_priority 100 -- see Note [default priority]
/-- This is basically the same as `is_strict_total_order`, but that definition is
in Type (probably by mistake) and also has redundant assumptions. -/
@[algebra] class is_strict_total_order' (Ξ± : Type u) (lt : Ξ± β Ξ± β Prop)
extends is_trichotomous Ξ± lt, is_strict_order Ξ± lt : Prop.
end prio
/-- Construct a linear order from a `is_strict_total_order'` relation -/
def linear_order_of_STO' (r) [is_strict_total_order' Ξ± r] : linear_order Ξ± :=
{ le_total := Ξ» x y,
match y, trichotomous_of r x y with
| y, or.inl h := or.inl (or.inr h)
| _, or.inr (or.inl rfl) := or.inl (or.inl rfl)
| _, or.inr (or.inr h) := or.inr (or.inr h)
end,
..partial_order_of_SO r }
/-- Construct a decidable linear order from a `is_strict_total_order'` relation -/
def decidable_linear_order_of_STO' (r) [is_strict_total_order' Ξ± r] [decidable_rel r] :
decidable_linear_order Ξ± :=
by letI LO := linear_order_of_STO' r; exact
{ decidable_le := Ξ» x y, decidable_of_iff (Β¬ r y x) (@not_lt _ _ y x),
..LO }
theorem is_strict_total_order'.swap (r) [is_strict_total_order' Ξ± r] :
is_strict_total_order' Ξ± (swap r) :=
{..is_trichotomous.swap r, ..is_strict_order.swap r}
instance [linear_order Ξ±] : is_strict_total_order' Ξ± (<) := {}
/-- A connected order is one satisfying the condition `a < c β a < b β¨ b < c`.
This is recognizable as an intuitionistic substitute for `a β€ b β¨ b β€ a` on
the constructive reals, and is also known as negative transitivity,
since the contrapositive asserts transitivity of the relation `Β¬ a < b`. -/
@[algebra] class is_order_connected (Ξ± : Type u) (lt : Ξ± β Ξ± β Prop) : Prop :=
(conn : β a b c, lt a c β lt a b β¨ lt b c)
theorem is_order_connected.neg_trans {r : Ξ± β Ξ± β Prop} [is_order_connected Ξ± r]
{a b c} (hβ : Β¬ r a b) (hβ : Β¬ r b c) : Β¬ r a c :=
mt (is_order_connected.conn a b c) $ by simp [hβ, hβ]
theorem is_strict_weak_order_of_is_order_connected [is_asymm Ξ± r]
[is_order_connected Ξ± r] : is_strict_weak_order Ξ± r :=
{ trans := Ξ» a b c hβ hβ, (is_order_connected.conn _ c _ hβ).resolve_right (asymm hβ),
incomp_trans := Ξ» a b c β¨hβ, hββ© β¨hβ, hββ©,
β¨is_order_connected.neg_trans hβ hβ, is_order_connected.neg_trans hβ hββ©,
..@is_asymm.is_irrefl Ξ± r _ }
@[priority 100] -- see Note [lower instance priority]
instance is_order_connected_of_is_strict_total_order'
[is_strict_total_order' Ξ± r] : is_order_connected Ξ± r :=
β¨Ξ» a b c h, (trichotomous _ _).imp_right (Ξ» o,
o.elim (Ξ» e, e βΈ h) (Ξ» h', trans h' h))β©
@[priority 100] -- see Note [lower instance priority]
instance is_strict_total_order_of_is_strict_total_order'
[is_strict_total_order' Ξ± r] : is_strict_total_order Ξ± r :=
{..is_strict_weak_order_of_is_order_connected}
instance [linear_order Ξ±] : is_strict_total_order Ξ± (<) := by apply_instance
instance [linear_order Ξ±] : is_order_connected Ξ± (<) := by apply_instance
instance [linear_order Ξ±] : is_incomp_trans Ξ± (<) := by apply_instance
instance [linear_order Ξ±] : is_strict_weak_order Ξ± (<) := by apply_instance
/-- An extensional relation is one in which an element is determined by its set
of predecessors. It is named for the `x β y` relation in set theory, whose
extensionality is one of the first axioms of ZFC. -/
@[algebra] class is_extensional (Ξ± : Type u) (r : Ξ± β Ξ± β Prop) : Prop :=
(ext : β a b, (β x, r x a β r x b) β a = b)
@[priority 100] -- see Note [lower instance priority]
instance is_extensional_of_is_strict_total_order'
[is_strict_total_order' Ξ± r] : is_extensional Ξ± r :=
β¨Ξ» a b H, ((@trichotomous _ r _ a b)
.resolve_left $ mt (H _).2 (irrefl a))
.resolve_right $ mt (H _).1 (irrefl b)β©
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A well order is a well-founded linear order. -/
@[algebra] class is_well_order (Ξ± : Type u) (r : Ξ± β Ξ± β Prop)
extends is_strict_total_order' Ξ± r : Prop :=
(wf : well_founded r)
end prio
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_strict_total_order {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_strict_total_order Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_extensional {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_extensional Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_trichotomous {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_trichotomous Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_trans {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_trans Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_irrefl {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_irrefl Ξ± r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_asymm {Ξ±} (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
is_asymm Ξ± r := by apply_instance
/-- Construct a decidable linear order from a well-founded linear order. -/
noncomputable def is_well_order.decidable_linear_order (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r] :
decidable_linear_order Ξ± :=
by { haveI := linear_order_of_STO' r, exact classical.DLO Ξ± }
instance empty_relation.is_well_order [subsingleton Ξ±] : is_well_order Ξ± empty_relation :=
{ trichotomous := Ξ» a b, or.inr $ or.inl $ subsingleton.elim _ _,
irrefl := Ξ» a, id,
trans := Ξ» a b c, false.elim,
wf := β¨Ξ» a, β¨_, Ξ» y, false.elimβ©β© }
instance nat.lt.is_well_order : is_well_order β (<) := β¨nat.lt_wfβ©
instance sum.lex.is_well_order [is_well_order Ξ± r] [is_well_order Ξ² s] :
is_well_order (Ξ± β Ξ²) (sum.lex r s) :=
{ trichotomous := Ξ» a b, by cases a; cases b; simp; apply trichotomous,
irrefl := Ξ» a, by cases a; simp; apply irrefl,
trans := Ξ» a b c, by cases a; cases b; simp; cases c; simp; apply trans,
wf := sum.lex_wf is_well_order.wf is_well_order.wf }
instance prod.lex.is_well_order [is_well_order Ξ± r] [is_well_order Ξ² s] :
is_well_order (Ξ± Γ Ξ²) (prod.lex r s) :=
{ trichotomous := Ξ» β¨aβ, aββ© β¨bβ, bββ©,
match @trichotomous _ r _ aβ bβ with
| or.inl hβ := or.inl $ prod.lex.left _ _ hβ
| or.inr (or.inr hβ) := or.inr $ or.inr $ prod.lex.left _ _ hβ
| or.inr (or.inl e) := e βΈ match @trichotomous _ s _ aβ bβ with
| or.inl h := or.inl $ prod.lex.right _ h
| or.inr (or.inr h) := or.inr $ or.inr $ prod.lex.right _ h
| or.inr (or.inl e) := e βΈ or.inr $ or.inl rfl
end
end,
irrefl := Ξ» β¨aβ, aββ© h, by cases h with _ _ _ _ h _ _ _ h;
[exact irrefl _ h, exact irrefl _ h],
trans := Ξ» a b c hβ hβ, begin
cases hβ with aβ aβ bβ bβ ab aβ bβ bβ ab;
cases hβ with _ _ cβ cβ bc _ _ cβ bc,
{ exact prod.lex.left _ _ (trans ab bc) },
{ exact prod.lex.left _ _ ab },
{ exact prod.lex.left _ _ bc },
{ exact prod.lex.right _ (trans ab bc) }
end,
wf := prod.lex_wf is_well_order.wf is_well_order.wf }
/-- An unbounded or cofinal set -/
def unbounded (r : Ξ± β Ξ± β Prop) (s : set Ξ±) : Prop := β a, β b β s, Β¬ r b a
/-- A bounded or final set -/
def bounded (r : Ξ± β Ξ± β Prop) (s : set Ξ±) : Prop := βa, β b β s, r b a
@[simp] lemma not_bounded_iff {r : Ξ± β Ξ± β Prop} (s : set Ξ±) : Β¬bounded r s β unbounded r s :=
begin
classical,
simp only [bounded, unbounded, not_forall, not_exists, exists_prop, not_and, not_not]
end
@[simp] lemma not_unbounded_iff {r : Ξ± β Ξ± β Prop} (s : set Ξ±) : Β¬unbounded r s β bounded r s :=
by { classical, rw [not_iff_comm, not_bounded_iff] }
namespace well_founded
/-- If `r` is a well-founded relation, then any nonempty set has a minimal element
with respect to `r`. -/
theorem has_min {Ξ±} {r : Ξ± β Ξ± β Prop} (H : well_founded r)
(s : set Ξ±) : s.nonempty β β a β s, β x β s, Β¬ r x a
| β¨a, haβ© := (acc.rec_on (H.apply a) $ Ξ» x _ IH, classical.not_imp_not.1 $ Ξ» hne hx, hne $
β¨x, hx, Ξ» y hy hyx, hne $ IH y hyx hyβ©) ha
/-- A minimal element of a nonempty set in a well-founded order -/
noncomputable def min {Ξ±} {r : Ξ± β Ξ± β Prop} (H : well_founded r)
(p : set Ξ±) (h : p.nonempty) : Ξ± :=
classical.some (H.has_min p h)
theorem min_mem {Ξ±} {r : Ξ± β Ξ± β Prop} (H : well_founded r)
(p : set Ξ±) (h : p.nonempty) : H.min p h β p :=
let β¨h, _β© := classical.some_spec (H.has_min p h) in h
theorem not_lt_min {Ξ±} {r : Ξ± β Ξ± β Prop} (H : well_founded r)
(p : set Ξ±) (h : p.nonempty) {x} (xp : x β p) : Β¬ r x (H.min p h) :=
let β¨_, h'β© := classical.some_spec (H.has_min p h) in h' _ xp
open set
/-- The supremum of a bounded, well-founded order -/
protected noncomputable def sup {Ξ±} {r : Ξ± β Ξ± β Prop} (wf : well_founded r) (s : set Ξ±)
(h : bounded r s) : Ξ± :=
wf.min { x | βa β s, r a x } h
protected lemma lt_sup {Ξ±} {r : Ξ± β Ξ± β Prop} (wf : well_founded r) {s : set Ξ±} (h : bounded r s)
{x} (hx : x β s) : r x (wf.sup s h) :=
min_mem wf { x | βa β s, r a x } h x hx
section
open_locale classical
/-- A successor of an element `x` in a well-founded order is a minimal element `y` such that
`x < y` if one exists. Otherwise it is `x` itself. -/
protected noncomputable def succ {Ξ±} {r : Ξ± β Ξ± β Prop} (wf : well_founded r) (x : Ξ±) : Ξ± :=
if h : βy, r x y then wf.min { y | r x y } h else x
protected lemma lt_succ {Ξ±} {r : Ξ± β Ξ± β Prop} (wf : well_founded r) {x : Ξ±} (h : βy, r x y) :
r x (wf.succ x) :=
by { rw [well_founded.succ, dif_pos h], apply min_mem }
end
protected lemma lt_succ_iff {Ξ±} {r : Ξ± β Ξ± β Prop} [wo : is_well_order Ξ± r] {x : Ξ±} (h : βy, r x y)
(y : Ξ±) : r y (wo.wf.succ x) β r y x β¨ y = x :=
begin
split,
{ intro h', have : Β¬r x y,
{ intro hy, rw [well_founded.succ, dif_pos] at h',
exact wo.wf.not_lt_min _ h hy h' },
rcases trichotomous_of r x y with hy | hy | hy,
exfalso, exact this hy,
right, exact hy.symm,
left, exact hy },
rintro (hy | rfl), exact trans hy (wo.wf.lt_succ h), exact wo.wf.lt_succ h
end
end well_founded
|
a6208e2cfd1485c7d85baee3311b95c605381d97
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/category_theory/limits/shapes/kernels.lean
|
e42686a2f39202ede24ece822a35cd41f9b30683
|
[
"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
| 27,036
|
lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Markus Himmel
-/
import category_theory.limits.shapes.zero
/-!
# Kernels and cokernels
In a category with zero morphisms, the kernel of a morphism `f : X βΆ Y` is the equalizer of `f`
and `0 : X βΆ Y`. (Similarly the cokernel is the coequalizer.)
The basic definitions are
* `kernel : (X βΆ Y) β C`
* `kernel.ΞΉ : kernel f βΆ X`
* `kernel.condition : kernel.ΞΉ f β« f = 0` and
* `kernel.lift (k : W βΆ X) (h : k β« f = 0) : W βΆ kernel f` (as well as the dual versions)
## Main statements
Besides the definition and lifts, we prove
* `kernel.ΞΉ_zero_is_iso`: a kernel map of a zero morphism is an isomorphism
* `kernel.eq_zero_of_epi_kernel`: if `kernel.ΞΉ f` is an epimorphism, then `f = 0`
* `kernel.of_mono`: the kernel of a monomorphism is the zero object
* `kernel.lift_mono`: the lift of a monomorphism `k : W βΆ X` such that `k β« f = 0`
is still a monomorphism
* `kernel.is_limit_cone_zero_cone`: if our category has a zero object, then the map from the zero
obect is a kernel map of any monomorphism
* `kernel.ΞΉ_of_zero`: `kernel.ΞΉ (0 : X βΆ Y)` is an isomorphism
and the corresponding dual statements.
## Future work
* TODO: connect this with existing working in the group theory and ring theory libraries.
## Implementation notes
As with the other special shapes in the limits library, all the definitions here are given as
`abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about
general limits can be used.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
universes v u u'
open category_theory
open category_theory.limits.walking_parallel_pair
namespace category_theory.limits
variables {C : Type u} [category.{v} C]
variables [has_zero_morphisms C]
/-- A morphism `f` has a kernel if the functor `parallel_pair f 0` has a limit. -/
abbreviation has_kernel {X Y : C} (f : X βΆ Y) : Type (max u v) := has_limit (parallel_pair f 0)
/-- A morphism `f` has a cokernel if the functor `parallel_pair f 0` has a colimit. -/
abbreviation has_cokernel {X Y : C} (f : X βΆ Y) : Type (max u v) := has_colimit (parallel_pair f 0)
variables {X Y : C} (f : X βΆ Y)
section
/-- A kernel fork is just a fork where the second morphism is a zero morphism. -/
abbreviation kernel_fork := fork f 0
variables {f}
@[simp, reassoc] lemma kernel_fork.condition (s : kernel_fork f) : fork.ΞΉ s β« f = 0 :=
by erw [fork.condition, has_zero_morphisms.comp_zero]
@[simp] lemma kernel_fork.app_one (s : kernel_fork f) : s.Ο.app one = 0 :=
by rw [βfork.app_zero_left, kernel_fork.condition]
/-- A morphism `ΞΉ` satisfying `ΞΉ β« f = 0` determines a kernel fork over `f`. -/
abbreviation kernel_fork.of_ΞΉ {Z : C} (ΞΉ : Z βΆ X) (w : ΞΉ β« f = 0) : kernel_fork f :=
fork.of_ΞΉ ΞΉ $ by rw [w, has_zero_morphisms.comp_zero]
@[simp] lemma kernel_fork.ΞΉ_of_ΞΉ {X Y P : C} (f : X βΆ Y) (ΞΉ : P βΆ X) (w : ΞΉ β« f = 0) :
fork.ΞΉ (kernel_fork.of_ΞΉ ΞΉ w) = ΞΉ := rfl
section
local attribute [tidy] tactic.case_bash
/-- Every kernel fork `s` is isomorphic (actually, equal) to `fork.of_ΞΉ (fork.ΞΉ s) _`. -/
def iso_of_ΞΉ (s : fork f 0) : s β
fork.of_ΞΉ (fork.ΞΉ s) (fork.condition s) :=
cones.ext (iso.refl _) $ by tidy
/-- If `ΞΉ = ΞΉ'`, then `fork.of_ΞΉ ΞΉ _` and `fork.of_ΞΉ ΞΉ' _` are isomorphic. -/
def of_ΞΉ_congr {P : C} {ΞΉ ΞΉ' : P βΆ X} {w : ΞΉ β« f = 0} (h : ΞΉ = ΞΉ') :
kernel_fork.of_ΞΉ ΞΉ w β
kernel_fork.of_ΞΉ ΞΉ' (by rw [βh, w]) :=
cones.ext (iso.refl _) $ by tidy
/-- If `F` is an equivalence, then applying `F` to a diagram indexing a (co)kernel of `f` yields
the diagram indexing the (co)kernel of `F.map f`. -/
def comp_nat_iso {D : Type u'} [category.{v} D] [has_zero_morphisms D] (F : C β₯€ D)
[is_equivalence F] : parallel_pair f 0 β F β
parallel_pair (F.map f) 0 :=
nat_iso.of_components (Ξ» j, match j with
| zero := iso.refl _
| one := iso.refl _
end) $ by tidy
end
/-- If `s` is a limit kernel fork and `k : W βΆ X` satisfies ``k β« f = 0`, then there is some
`l : W βΆ s.X` such that `l β« fork.ΞΉ s = k`. -/
def kernel_fork.is_limit.lift' {s : kernel_fork f} (hs : is_limit s) {W : C} (k : W βΆ X)
(h : k β« f = 0) : {l : W βΆ s.X // l β« fork.ΞΉ s = k} :=
β¨hs.lift $ kernel_fork.of_ΞΉ _ h, hs.fac _ _β©
/-- This is a slightly more convenient method to verify that a kernel fork is a limit cone. It
only asks for a proof of facts that carry any mathematical content -/
def is_limit_aux (t : kernel_fork f)
(lift : Ξ (s : kernel_fork f), s.X βΆ t.X)
(fac : β (s : kernel_fork f), lift s β« t.ΞΉ = s.ΞΉ)
(uniq : β (s : kernel_fork f) (m : s.X βΆ t.X) (w : m β« t.ΞΉ = s.ΞΉ), m = lift s) :
is_limit t :=
{ lift := lift,
fac' := Ξ» s j, by { cases j, { exact fac s, }, { simp, }, },
uniq' := Ξ» s m w, uniq s m (w limits.walking_parallel_pair.zero), }
/--
This is a more convenient formulation to show that a `kernel_fork` constructed using
`kernel_fork.of_ΞΉ` is a limit cone.
-/
def is_limit.of_ΞΉ {W : C} (g : W βΆ X) (eq : g β« f = 0)
(lift : Ξ {W' : C} (g' : W' βΆ X) (eq' : g' β« f = 0), W' βΆ W)
(fac : β {W' : C} (g' : W' βΆ X) (eq' : g' β« f = 0), lift g' eq' β« g = g')
(uniq : β {W' : C} (g' : W' βΆ X) (eq' : g' β« f = 0) (m : W' βΆ W) (w : m β« g = g'), m = lift g' eq') :
is_limit (kernel_fork.of_ΞΉ g eq) :=
is_limit_aux _ (Ξ» s, lift s.ΞΉ s.condition) (Ξ» s, fac s.ΞΉ s.condition) (Ξ» s, uniq s.ΞΉ s.condition)
end
section
variables [has_kernel f]
/-- The kernel of a morphism, expressed as the equalizer with the 0 morphism. -/
abbreviation kernel : C := equalizer f 0
/-- The map from `kernel f` into the source of `f`. -/
abbreviation kernel.ΞΉ : kernel f βΆ X := equalizer.ΞΉ f 0
@[simp, reassoc] lemma kernel.condition : kernel.ΞΉ f β« f = 0 :=
kernel_fork.condition _
/-- Given any morphism `k : W βΆ X` satisfying `k β« f = 0`, `k` factors through `kernel.ΞΉ f`
via `kernel.lift : W βΆ kernel f`. -/
abbreviation kernel.lift {W : C} (k : W βΆ X) (h : k β« f = 0) : W βΆ kernel f :=
limit.lift (parallel_pair f 0) (kernel_fork.of_ΞΉ k h)
@[simp, reassoc]
lemma kernel.lift_ΞΉ {W : C} (k : W βΆ X) (h : k β« f = 0) : kernel.lift f k h β« kernel.ΞΉ f = k :=
limit.lift_Ο _ _
@[simp]
lemma kernel.lift_zero {W : C} {h} : kernel.lift f (0 : W βΆ X) h = 0 :=
by { ext, simp, }
instance kernel.lift_mono {W : C} (k : W βΆ X) (h : k β« f = 0) [mono k] : mono (kernel.lift f k h) :=
β¨Ξ» Z g g' w,
begin
replace w := w =β« kernel.ΞΉ f,
simp only [category.assoc, kernel.lift_ΞΉ] at w,
exact (cancel_mono k).1 w,
endβ©
/-- Any morphism `k : W βΆ X` satisfying `k β« f = 0` induces a morphism `l : W βΆ kernel f` such that
`l β« kernel.ΞΉ f = k`. -/
def kernel.lift' {W : C} (k : W βΆ X) (h : k β« f = 0) : {l : W βΆ kernel f // l β« kernel.ΞΉ f = k} :=
β¨kernel.lift f k h, kernel.lift_ΞΉ _ _ _β©
/-- Every kernel of the zero morphism is an isomorphism -/
instance kernel.ΞΉ_zero_is_iso [has_kernel (0 : X βΆ Y)] :
is_iso (kernel.ΞΉ (0 : X βΆ Y)) :=
equalizer.ΞΉ_of_self _
lemma eq_zero_of_epi_kernel [epi (kernel.ΞΉ f)] : f = 0 :=
(cancel_epi (kernel.ΞΉ f)).1 (by simp)
/-- The kernel of a zero morphism is isomorphic to the source. -/
def kernel_zero_iso_source [has_kernel (0 : X βΆ Y)] : kernel (0 : X βΆ Y) β
X :=
equalizer.iso_source_of_self 0
@[simp] lemma kernel_zero_iso_source_hom [has_kernel (0 : X βΆ Y)] :
kernel_zero_iso_source.hom = kernel.ΞΉ (0 : X βΆ Y) := rfl
@[simp] lemma kernel_zero_iso_source_inv [has_kernel (0 : X βΆ Y)] :
kernel_zero_iso_source.inv = kernel.lift (0 : X βΆ Y) (π X) (by simp) := rfl
/-- If two morphisms are known to be equal, then their kernels are isomorphic. -/
def kernel_iso_of_eq {f g : X βΆ Y} [has_kernel f] [has_kernel g] (h : f = g) :
kernel f β
kernel g :=
has_limit.iso_of_nat_iso (by simp[h])
@[simp]
lemma kernel_iso_of_eq_refl {h : f = f} : kernel_iso_of_eq h = iso.refl (kernel f) :=
by { ext, simp [kernel_iso_of_eq], }
@[simp]
lemma kernel_iso_of_eq_trans {f g h : X βΆ Y} [has_kernel f] [has_kernel g] [has_kernel h]
(wβ : f = g) (wβ : g = h) :
kernel_iso_of_eq wβ βͺβ« kernel_iso_of_eq wβ = kernel_iso_of_eq (wβ.trans wβ) :=
by { unfreezingI { induction wβ, induction wβ, }, ext, simp [kernel_iso_of_eq], }
variables {f}
lemma kernel_not_epi_of_nonzero (w : f β 0) : Β¬epi (kernel.ΞΉ f) :=
Ξ» I, by exactI w (eq_zero_of_epi_kernel f)
lemma kernel_not_iso_of_nonzero (w : f β 0) : (is_iso (kernel.ΞΉ f)) β false :=
Ξ» I, kernel_not_epi_of_nonzero w $ by { resetI, apply_instance }
/--
When `g` is an isomorphism, the kernel of `f β« g` is isomorphic to the kernel of `f`.
-/
@[simps]
def kernel_comp_is_iso {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_kernel (f β« g)] [has_kernel f] [is_iso g] :
kernel (f β« g) β
kernel f :=
{ hom := kernel.lift _ (kernel.ΞΉ _) (by { rw [βcancel_mono g], simp, }),
inv := kernel.lift _ (kernel.ΞΉ _) (by simp), }
lemma kernel_comp_is_iso_hom_comp_kernel_ΞΉ {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_kernel (f β« g)] [has_kernel f] [is_iso g] :
(kernel_comp_is_iso f g).hom β« kernel.ΞΉ f = kernel.ΞΉ (f β« g) :=
by simp
lemma kernel_comp_is_iso_inv_comp_kernel_ΞΉ {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_kernel (f β« g)] [has_kernel f] [is_iso g] :
(kernel_comp_is_iso f g).inv β« kernel.ΞΉ (f β« g) = kernel.ΞΉ f :=
by simp
/--
When `f` is an isomorphism, the kernel of `f β« g` is isomorphic to the kernel of `g`.
-/
@[simps]
def kernel_is_iso_comp {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_kernel (f β« g)] [is_iso f] [has_kernel g] :
kernel (f β« g) β
kernel g :=
{ hom := kernel.lift _ (kernel.ΞΉ _ β« f) (by simp),
inv := kernel.lift _ (kernel.ΞΉ _ β« inv f) (by simp), }
lemma kernel_is_iso_comp_hom_comp_kernel_ΞΉ {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_kernel (f β« g)] [is_iso f] [has_kernel g] :
(kernel_is_iso_comp f g).hom β« kernel.ΞΉ g = kernel.ΞΉ (f β« g) β« f :=
by simp
lemma kernel_is_iso_comp_inv_comp_kernel_ΞΉ {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_kernel (f β« g)] [is_iso f] [has_kernel g] :
(kernel_is_iso_comp f g).inv β« kernel.ΞΉ (f β« g) = kernel.ΞΉ g β« (inv f) :=
by simp
end
section has_zero_object
variables [has_zero_object C]
local attribute [instance] has_zero_object.has_zero
/-- The morphism from the zero object determines a cone on a kernel diagram -/
def kernel.zero_cone : cone (parallel_pair f 0) :=
{ X := 0,
Ο := { app := Ξ» j, 0 }}
/-- The map from the zero object is a kernel of a monomorphism -/
def kernel.is_limit_cone_zero_cone [mono f] : is_limit (kernel.zero_cone f) :=
fork.is_limit.mk _ (Ξ» s, 0)
(Ξ» s, by { erw has_zero_morphisms.zero_comp,
convert (zero_of_comp_mono f _).symm,
exact kernel_fork.condition _ })
(Ξ» _ _ _, zero_of_to_zero _)
/-- The kernel of a monomorphism is isomorphic to the zero object -/
def kernel.of_mono [has_kernel f] [mono f] : kernel f β
0 :=
functor.map_iso (cones.forget _) $ is_limit.unique_up_to_iso
(limit.is_limit (parallel_pair f 0)) (kernel.is_limit_cone_zero_cone f)
/-- The kernel morphism of a monomorphism is a zero morphism -/
lemma kernel.ΞΉ_of_mono [has_kernel f] [mono f] : kernel.ΞΉ f = 0 :=
zero_of_source_iso_zero _ (kernel.of_mono f)
end has_zero_object
section transport
/-- If `i` is an isomorphism such that `l β« i.hom = f`, then any kernel of `f` is a kernel of `l`.-/
def is_kernel.of_comp_iso {Z : C} (l : X βΆ Z) (i : Z β
Y) (h : l β« i.hom = f)
{s : kernel_fork f} (hs : is_limit s) : is_limit (kernel_fork.of_ΞΉ (fork.ΞΉ s) $
show fork.ΞΉ s β« l = 0, by simp [βi.comp_inv_eq.2 h.symm]) :=
fork.is_limit.mk _
(Ξ» s, hs.lift $ kernel_fork.of_ΞΉ (fork.ΞΉ s) $ by simp [βh])
(Ξ» s, by simp)
(Ξ» s m h, by { apply fork.is_limit.hom_ext hs, simpa using h walking_parallel_pair.zero })
/-- If `i` is an isomorphism such that `l β« i.hom = f`, then the kernel of `f` is a kernel of `l`.-/
def kernel.of_comp_iso [has_kernel f]
{Z : C} (l : X βΆ Z) (i : Z β
Y) (h : l β« i.hom = f) :
is_limit (kernel_fork.of_ΞΉ (kernel.ΞΉ f) $
show kernel.ΞΉ f β« l = 0, by simp [βi.comp_inv_eq.2 h.symm]) :=
is_kernel.of_comp_iso f l i h $ limit.is_limit _
/-- If `s` is any limit kernel cone over `f` and if `i` is an isomorphism such that
`i.hom β« s.ΞΉ = l`, then `l` is a kernel of `f`. -/
def is_kernel.iso_kernel {Z : C} (l : Z βΆ X) {s : kernel_fork f} (hs : is_limit s)
(i : Z β
s.X) (h : i.hom β« fork.ΞΉ s = l) : is_limit (kernel_fork.of_ΞΉ l $
show l β« f = 0, by simp [βh]) :=
is_limit.of_iso_limit hs $ cones.ext i.symm $ Ξ» j,
by { cases j, { exact (iso.eq_inv_comp i).2 h }, { simp } }
/-- If `i` is an isomorphism such that `i.hom β« kernel.ΞΉ f = l`, then `l` is a kernel of `f`. -/
def kernel.iso_kernel [has_kernel f]
{Z : C} (l : Z βΆ X) (i : Z β
kernel f) (h : i.hom β« kernel.ΞΉ f = l) :
is_limit (kernel_fork.of_ΞΉ l $ by simp [βh]) :=
is_kernel.iso_kernel f l (limit.is_limit _) i h
end transport
section
variables (X Y)
/-- The kernel morphism of a zero morphism is an isomorphism -/
def kernel.ΞΉ_of_zero [has_kernel (0 : X βΆ Y)] : is_iso (kernel.ΞΉ (0 : X βΆ Y)) :=
equalizer.ΞΉ_of_self _
end
section
/-- A cokernel cofork is just a cofork where the second morphism is a zero morphism. -/
abbreviation cokernel_cofork := cofork f 0
variables {f}
@[simp, reassoc] lemma cokernel_cofork.condition (s : cokernel_cofork f) : f β« cofork.Ο s = 0 :=
by rw [cofork.condition, has_zero_morphisms.zero_comp]
@[simp] lemma cokernel_cofork.app_zero (s : cokernel_cofork f) : s.ΞΉ.app zero = 0 :=
by rw [βcofork.left_app_one, cokernel_cofork.condition]
/-- A morphism `Ο` satisfying `f β« Ο = 0` determines a cokernel cofork on `f`. -/
abbreviation cokernel_cofork.of_Ο {Z : C} (Ο : Y βΆ Z) (w : f β« Ο = 0) : cokernel_cofork f :=
cofork.of_Ο Ο $ by rw [w, has_zero_morphisms.zero_comp]
@[simp] lemma cokernel_cofork.Ο_of_Ο {X Y P : C} (f : X βΆ Y) (Ο : Y βΆ P) (w : f β« Ο = 0) :
cofork.Ο (cokernel_cofork.of_Ο Ο w) = Ο := rfl
/-- Every cokernel cofork `s` is isomorphic (actually, equal) to `cofork.of_Ο (cofork.Ο s) _`. -/
def iso_of_Ο (s : cofork f 0) : s β
cofork.of_Ο (cofork.Ο s) (cofork.condition s) :=
cocones.ext (iso.refl _) $ Ξ» j, by cases j; tidy
/-- If `Ο = Ο'`, then `cokernel_cofork.of_Ο Ο _` and `cokernel_cofork.of_Ο Ο' _` are isomorphic. -/
def of_Ο_congr {P : C} {Ο Ο' : Y βΆ P} {w : f β« Ο = 0} (h : Ο = Ο') :
cokernel_cofork.of_Ο Ο w β
cokernel_cofork.of_Ο Ο' (by rw [βh, w]) :=
cocones.ext (iso.refl _) $ Ξ» j, by cases j; tidy
/-- If `s` is a colimit cokernel cofork, then every `k : Y βΆ W` satisfying `f β« k = 0` induces
`l : s.X βΆ W` such that `cofork.Ο s β« l = k`. -/
def cokernel_cofork.is_colimit.desc' {s : cokernel_cofork f} (hs : is_colimit s) {W : C} (k : Y βΆ W)
(h : f β« k = 0) : {l : s.X βΆ W // cofork.Ο s β« l = k} :=
β¨hs.desc $ cokernel_cofork.of_Ο _ h, hs.fac _ _β©
/--
This is a slightly more convenient method to verify that a cokernel cofork is a colimit cocone.
It only asks for a proof of facts that carry any mathematical content -/
def is_colimit_aux (t : cokernel_cofork f)
(desc : Ξ (s : cokernel_cofork f), t.X βΆ s.X)
(fac : β (s : cokernel_cofork f), t.Ο β« desc s = s.Ο)
(uniq : β (s : cokernel_cofork f) (m : t.X βΆ s.X) (w : t.Ο β« m = s.Ο), m = desc s) :
is_colimit t :=
{ desc := desc,
fac' := Ξ» s j, by { cases j, { simp, }, { exact fac s, }, },
uniq' := Ξ» s m w, uniq s m (w limits.walking_parallel_pair.one), }
/--
This is a more convenient formulation to show that a `cokernel_cofork` constructed using
`cokernel_cofork.of_Ο` is a limit cone.
-/
def is_colimit.of_Ο {Z : C} (g : Y βΆ Z) (eq : f β« g = 0)
(desc : Ξ {Z' : C} (g' : Y βΆ Z') (eq' : f β« g' = 0), Z βΆ Z')
(fac : β {Z' : C} (g' : Y βΆ Z') (eq' : f β« g' = 0), g β« desc g' eq' = g')
(uniq : β {Z' : C} (g' : Y βΆ Z') (eq' : f β« g' = 0) (m : Z βΆ Z') (w : g β« m = g'), m = desc g' eq') :
is_colimit (cokernel_cofork.of_Ο g eq) :=
is_colimit_aux _ (Ξ» s, desc s.Ο s.condition) (Ξ» s, fac s.Ο s.condition) (Ξ» s, uniq s.Ο s.condition)
end
section
variables [has_cokernel f]
/-- The cokernel of a morphism, expressed as the coequalizer with the 0 morphism. -/
abbreviation cokernel : C := coequalizer f 0
/-- The map from the target of `f` to `cokernel f`. -/
abbreviation cokernel.Ο : Y βΆ cokernel f := coequalizer.Ο f 0
@[simp, reassoc] lemma cokernel.condition : f β« cokernel.Ο f = 0 :=
cokernel_cofork.condition _
/-- Given any morphism `k : Y βΆ W` such that `f β« k = 0`, `k` factors through `cokernel.Ο f`
via `cokernel.desc : cokernel f βΆ W`. -/
abbreviation cokernel.desc {W : C} (k : Y βΆ W) (h : f β« k = 0) : cokernel f βΆ W :=
colimit.desc (parallel_pair f 0) (cokernel_cofork.of_Ο k h)
@[simp, reassoc]
lemma cokernel.Ο_desc {W : C} (k : Y βΆ W) (h : f β« k = 0) :
cokernel.Ο f β« cokernel.desc f k h = k :=
colimit.ΞΉ_desc _ _
@[simp]
lemma cokernel.desc_zero {W : C} {h} : cokernel.desc f (0 : Y βΆ W) h = 0 :=
by { ext, simp, }
instance cokernel.desc_epi {W : C} (k : Y βΆ W) (h : f β« k = 0) [epi k] : epi (cokernel.desc f k h) :=
β¨Ξ» Z g g' w,
begin
replace w := cokernel.Ο f β«= w,
simp only [cokernel.Ο_desc_assoc] at w,
exact (cancel_epi k).1 w,
endβ©
/-- Any morphism `k : Y βΆ W` satisfying `f β« k = 0` induces `l : cokernel f βΆ W` such that
`cokernel.Ο f β« l = k`. -/
def cokernel.desc' {W : C} (k : Y βΆ W) (h : f β« k = 0) :
{l : cokernel f βΆ W // cokernel.Ο f β« l = k} :=
β¨cokernel.desc f k h, cokernel.Ο_desc _ _ _β©
/-- The cokernel of the zero morphism is an isomorphism -/
instance cokernel.Ο_zero_is_iso [has_colimit (parallel_pair (0 : X βΆ Y) 0)] :
is_iso (cokernel.Ο (0 : X βΆ Y)) :=
coequalizer.Ο_of_self _
lemma eq_zero_of_mono_cokernel [mono (cokernel.Ο f)] : f = 0 :=
(cancel_mono (cokernel.Ο f)).1 (by simp)
/-- The cokernel of a zero morphism is isomorphic to the target. -/
def cokernel_zero_iso_target [has_cokernel (0 : X βΆ Y)] : cokernel (0 : X βΆ Y) β
Y :=
coequalizer.iso_target_of_self 0
@[simp] lemma cokernel_zero_iso_target_hom [has_cokernel (0 : X βΆ Y)] :
cokernel_zero_iso_target.hom = cokernel.desc (0 : X βΆ Y) (π Y) (by simp) := rfl
@[simp] lemma cokernel_zero_iso_target_inv [has_cokernel (0 : X βΆ Y)] :
cokernel_zero_iso_target.inv = cokernel.Ο (0 : X βΆ Y) := rfl
/-- If two morphisms are known to be equal, then their cokernels are isomorphic. -/
def cokernel_iso_of_eq {f g : X βΆ Y} [has_cokernel f] [has_cokernel g] (h : f = g) :
cokernel f β
cokernel g :=
has_colimit.iso_of_nat_iso (by simp[h])
@[simp]
lemma cokernel_iso_of_eq_refl {h : f = f} : cokernel_iso_of_eq h = iso.refl (cokernel f) :=
by { ext, simp [cokernel_iso_of_eq], }
@[simp]
lemma cokernel_iso_of_eq_trans {f g h : X βΆ Y} [has_cokernel f] [has_cokernel g] [has_cokernel h]
(wβ : f = g) (wβ : g = h) :
cokernel_iso_of_eq wβ βͺβ« cokernel_iso_of_eq wβ = cokernel_iso_of_eq (wβ.trans wβ) :=
by { unfreezingI { induction wβ, induction wβ, }, ext, simp [cokernel_iso_of_eq], }
variables {f}
lemma cokernel_not_mono_of_nonzero (w : f β 0) : Β¬mono (cokernel.Ο f) :=
Ξ» I, by exactI w (eq_zero_of_mono_cokernel f)
lemma cokernel_not_iso_of_nonzero (w : f β 0) : (is_iso (cokernel.Ο f)) β false :=
Ξ» I, cokernel_not_mono_of_nonzero w $ by { resetI, apply_instance }
/--
When `g` is an isomorphism, the cokernel of `f β« g` is isomorphic to the cokernel of `f`.
-/
@[simps]
def cokernel_comp_is_iso {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_cokernel (f β« g)] [has_cokernel f] [is_iso g] :
cokernel (f β« g) β
cokernel f :=
{ hom := cokernel.desc _ (inv g β« cokernel.Ο f) (by simp),
inv := cokernel.desc _ (g β« cokernel.Ο (f β« g)) (by rw [βcategory.assoc, cokernel.condition]), }
lemma cokernel_Ο_comp_cokernel_comp_is_iso_hom {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_cokernel (f β« g)] [has_cokernel f] [is_iso g] :
cokernel.Ο (f β« g) β« (cokernel_comp_is_iso f g).hom = inv g β« cokernel.Ο f :=
by simp
lemma cokernel_Ο_comp_cokernel_comp_is_iso_inv {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_cokernel (f β« g)] [has_cokernel f] [is_iso g] :
cokernel.Ο f β« (cokernel_comp_is_iso f g).inv = g β« cokernel.Ο (f β« g) :=
by simp
/--
When `f` is an isomorphism, the cokernel of `f β« g` is isomorphic to the cokernel of `g`.
-/
@[simps]
def cokernel_is_iso_comp {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_cokernel (f β« g)] [is_iso f] [has_cokernel g] :
cokernel (f β« g) β
cokernel g :=
{ hom := cokernel.desc _ (cokernel.Ο g) (by simp),
inv := cokernel.desc _ (cokernel.Ο (f β« g)) (by { rw [βcancel_epi f, βcategory.assoc], simp, }), }
lemma cokernel_Ο_comp_cokernel_is_iso_comp_hom {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_cokernel (f β« g)] [is_iso f] [has_cokernel g] :
cokernel.Ο (f β« g) β« (cokernel_is_iso_comp f g).hom = cokernel.Ο g :=
by simp
lemma cokernel_Ο_comp_cokernel_is_iso_comp_inv {X Y Z : C} (f : X βΆ Y) (g : Y βΆ Z)
[has_cokernel (f β« g)] [is_iso f] [has_cokernel g] :
cokernel.Ο g β« (cokernel_is_iso_comp f g).inv = cokernel.Ο (f β« g) :=
by simp
end
section has_zero_object
variables [has_zero_object C]
local attribute [instance] has_zero_object.has_zero
/-- The morphism to the zero object determines a cocone on a cokernel diagram -/
def cokernel.zero_cocone : cocone (parallel_pair f 0) :=
{ X := 0,
ΞΉ := { app := Ξ» j, 0 } }
/-- The morphism to the zero object is a cokernel of an epimorphism -/
def cokernel.is_colimit_cocone_zero_cocone [epi f] : is_colimit (cokernel.zero_cocone f) :=
cofork.is_colimit.mk _ (Ξ» s, 0)
(Ξ» s, by { erw has_zero_morphisms.zero_comp,
convert (zero_of_epi_comp f _).symm,
exact cokernel_cofork.condition _ })
(Ξ» _ _ _, zero_of_from_zero _)
/-- The cokernel of an epimorphism is isomorphic to the zero object -/
def cokernel.of_epi [has_cokernel f] [epi f] : cokernel f β
0 :=
functor.map_iso (cocones.forget _) $ is_colimit.unique_up_to_iso
(colimit.is_colimit (parallel_pair f 0)) (cokernel.is_colimit_cocone_zero_cocone f)
/-- The cokernel morphism of an epimorphism is a zero morphism -/
lemma cokernel.Ο_of_epi [has_cokernel f] [epi f] : cokernel.Ο f = 0 :=
zero_of_target_iso_zero _ (cokernel.of_epi f)
end has_zero_object
section has_image
/--
The cokernel of the image inclusion of a morphism `f` is isomorphic to the cokernel of `f`.
(This result requires that the factorisation through the image is an epimorphism.
This holds in any category with equalizers.)
-/
@[simps]
def cokernel_image_ΞΉ {X Y : C} (f : X βΆ Y)
[has_image f] [has_cokernel (image.ΞΉ f)] [has_cokernel f] [epi (factor_thru_image f)] :
cokernel (image.ΞΉ f) β
cokernel f :=
{ hom := cokernel.desc _ (cokernel.Ο f)
begin
have w := cokernel.condition f,
conv at w { to_lhs, congr, rw βimage.fac f, },
rw [βhas_zero_morphisms.comp_zero (limits.factor_thru_image f), category.assoc, cancel_epi] at w,
exact w,
end,
inv := cokernel.desc _ (cokernel.Ο _)
begin
conv { to_lhs, congr, rw βimage.fac f, },
rw [category.assoc, cokernel.condition, has_zero_morphisms.comp_zero],
end, }
end has_image
section
variables (X Y)
/-- The cokernel of a zero morphism is an isomorphism -/
def cokernel.Ο_of_zero [has_cokernel (0 : X βΆ Y)] :
is_iso (cokernel.Ο (0 : X βΆ Y)) :=
coequalizer.Ο_of_self _
end
section has_zero_object
variables [has_zero_object C]
local attribute [instance] has_zero_object.has_zero
/-- The kernel of the cokernel of an epimorphism is an isomorphism -/
instance kernel.of_cokernel_of_epi [has_cokernel f]
[has_kernel (cokernel.Ο f)] [epi f] : is_iso (kernel.ΞΉ (cokernel.Ο f)) :=
equalizer.ΞΉ_of_eq $ cokernel.Ο_of_epi f
/-- The cokernel of the kernel of a monomorphism is an isomorphism -/
instance cokernel.of_kernel_of_mono [has_kernel f]
[has_cokernel (kernel.ΞΉ f)] [mono f] : is_iso (cokernel.Ο (kernel.ΞΉ f)) :=
coequalizer.Ο_of_eq $ kernel.ΞΉ_of_mono f
end has_zero_object
section transport
/-- If `i` is an isomorphism such that `i.hom β« l = f`, then any cokernel of `f` is a cokernel of
`l`. -/
def is_cokernel.of_iso_comp {Z : C} (l : Z βΆ Y) (i : X β
Z) (h : i.hom β« l = f)
{s : cokernel_cofork f} (hs : is_colimit s) : is_colimit (cokernel_cofork.of_Ο (cofork.Ο s) $
show l β« cofork.Ο s = 0, by simp [i.eq_inv_comp.2 h]) :=
cofork.is_colimit.mk _
(Ξ» s, hs.desc $ cokernel_cofork.of_Ο (cofork.Ο s) $ by simp [βh])
(Ξ» s, by simp)
(Ξ» s m h, by { apply cofork.is_colimit.hom_ext hs, simpa using h walking_parallel_pair.one })
/-- If `i` is an isomorphism such that `i.hom β« l = f`, then the cokernel of `f` is a cokernel of
`l`. -/
def cokernel.of_iso_comp [has_cokernel f]
{Z : C} (l : Z βΆ Y) (i : X β
Z) (h : i.hom β« l = f) :
is_colimit (cokernel_cofork.of_Ο (cokernel.Ο f) $
show l β« cokernel.Ο f = 0, by simp [i.eq_inv_comp.2 h]) :=
is_cokernel.of_iso_comp f l i h $ colimit.is_colimit _
/-- If `s` is any colimit cokernel cocone over `f` and `i` is an isomorphism such that
`s.Ο β« i.hom = l`, then `l` is a cokernel of `f`. -/
def is_cokernel.cokernel_iso {Z : C} (l : Y βΆ Z) {s : cokernel_cofork f} (hs : is_colimit s)
(i : s.X β
Z) (h : cofork.Ο s β« i.hom = l) : is_colimit (cokernel_cofork.of_Ο l $
show f β« l = 0, by simp [βh]) :=
is_colimit.of_iso_colimit hs $ cocones.ext i $ Ξ» j, by { cases j, { simp }, { exact h } }
/-- If `i` is an isomorphism such that `cokernel.Ο f β« i.hom = l`, then `l` is a cokernel of `f`. -/
def cokernel.cokernel_iso [has_cokernel f]
{Z : C} (l : Y βΆ Z) (i : cokernel f β
Z) (h : cokernel.Ο f β« i.hom = l) :
is_colimit (cokernel_cofork.of_Ο l $ by simp [βh]) :=
is_cokernel.cokernel_iso f l (colimit.is_colimit _) i h
end transport
end category_theory.limits
namespace category_theory.limits
variables (C : Type u) [category.{v} C]
variables [has_zero_morphisms C]
/-- `has_kernels` represents a choice of kernel for every morphism -/
class has_kernels :=
(has_limit : Ξ {X Y : C} (f : X βΆ Y), has_kernel f)
/-- `has_cokernels` represents a choice of cokernel for every morphism -/
class has_cokernels :=
(has_colimit : Ξ {X Y : C} (f : X βΆ Y), has_cokernel f)
attribute [instance, priority 100] has_kernels.has_limit has_cokernels.has_colimit
@[priority 100]
instance has_kernels_of_has_equalizers [has_equalizers C] : has_kernels C :=
{ has_limit := infer_instance }
@[priority 100]
instance has_cokernels_of_has_coequalizers [has_coequalizers C] : has_cokernels C :=
{ has_colimit := infer_instance }
end category_theory.limits
|
dc99dfd4a6e3add6677c2223bbdacea0d15e3bbc
|
42610cc2e5db9c90269470365e6056df0122eaa0
|
/hott/types/pointed.hlean
|
28a98cec1d89e1f3eec3ec44bb874af9db3ffbc7
|
[
"Apache-2.0"
] |
permissive
|
tomsib2001/lean
|
2ab59bfaebd24a62109f800dcf4a7139ebd73858
|
eb639a7d53fb40175bea5c8da86b51d14bb91f76
|
refs/heads/master
| 1,586,128,387,740
| 1,468,968,950,000
| 1,468,968,950,000
| 61,027,234
| 0
| 0
| null | 1,465,813,585,000
| 1,465,813,585,000
| null |
UTF-8
|
Lean
| false
| false
| 28,372
|
hlean
|
/-
Copyright (c) 2014-2016 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
The basic definitions are in init.pointed
-/
import .equiv .nat.basic
open is_trunc eq prod sigma nat equiv option is_equiv bool unit algebra sigma.ops sum
namespace pointed
variables {A B : Type}
definition pointed_loop [instance] [constructor] (a : A) : pointed (a = a) :=
pointed.mk idp
definition pointed_fun_closed [constructor] (f : A β B) [H : pointed A] : pointed B :=
pointed.mk (f pt)
definition ploop_space [reducible] [constructor] (A : Type*) : Type* :=
pointed.mk' (point A = point A)
definition iterated_ploop_space [reducible] : β β Type* β Type*
| iterated_ploop_space 0 X := X
| iterated_ploop_space (n+1) X := ploop_space (iterated_ploop_space n X)
notation `Ξ©` := ploop_space
notation `Ξ©[`:95 n:0 `] `:0 A:95 := iterated_ploop_space n A
definition is_trunc_loop [instance] [priority 1100] (A : Type*)
(n : βββ) [H : is_trunc (n.+1) A] : is_trunc n (Ξ© A) :=
!is_trunc_eq
definition iterated_ploop_space_zero [unfold_full] (A : Type*)
: Ξ©[0] A = A := rfl
definition iterated_ploop_space_succ [unfold_full] (k : β) (A : Type*)
: Ξ©[succ k] A = Ξ© Ξ©[k] A := rfl
definition rfln [constructor] [reducible] {n : β} {A : Type*} : Ξ©[n] A := pt
definition refln [constructor] [reducible] (n : β) (A : Type*) : Ξ©[n] A := pt
definition refln_eq_refl [unfold_full] (A : Type*) (n : β) : rfln = rfl :> Ξ©[succ n] A := rfl
definition iterated_loop_space [unfold 3] (A : Type) [H : pointed A] (n : β) : Type :=
Ξ©[n] (pointed.mk' A)
definition loop_mul {k : β} {A : Type*} (mul : A β A β A) : Ξ©[k] A β Ξ©[k] A β Ξ©[k] A :=
begin cases k with k, exact mul, exact concat end
definition pType_eq {A B : Type*} (f : A β B) (p : f pt = pt) : A = B :=
begin
cases A with A a, cases B with B b, esimp at *,
fapply apd011 @pType.mk,
{ apply ua f},
{ rewrite [cast_ua,p]},
end
definition pType_eq_elim {A B : Type*} (p : A = B :> Type*)
: Ξ£(p : carrier A = carrier B :> Type), Point A =[p] Point B :=
by induction p; exact β¨idp, idpoβ©
protected definition pType.sigma_char.{u} : pType.{u} β Ξ£(X : Type.{u}), X :=
begin
fapply equiv.MK,
{ intro x, induction x with X x, exact β¨X, xβ©},
{ intro x, induction x with X x, exact pointed.MK X x},
{ intro x, induction x with X x, reflexivity},
{ intro x, induction x with X x, reflexivity},
end
definition add_point [constructor] (A : Type) : Type* :=
pointed.Mk (none : option A)
postfix `β`:(max+1) := add_point
-- the inclusion A β Aβ is called "some", the extra point "pt" or "none" ("@none A")
end pointed
namespace pointed
/- truncated pointed types -/
definition ptrunctype_eq {n : βββ} {A B : n-Type*}
(p : A = B :> Type) (q : Point A =[p] Point B) : A = B :=
begin
induction A with A HA a, induction B with B HB b, esimp at *,
induction q, esimp,
refine ap010 (ptrunctype.mk A) _ a,
exact !is_prop.elim
end
definition ptrunctype_eq_of_pType_eq {n : βββ} {A B : n-Type*} (p : A = B :> Type*)
: A = B :=
begin
cases pType_eq_elim p with q r,
exact ptrunctype_eq q r
end
definition is_trunc_ptrunctype [instance] {n : βββ} (A : n-Type*) : is_trunc n A :=
trunctype.struct A
/- properties of iterated loop space -/
variable (A : Type*)
definition loop_space_succ_eq_in (n : β) : Ξ©[succ n] A = Ξ©[n] (Ξ© A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact ap ploop_space IH}
end
definition loop_space_add (n m : β) : Ξ©[n] (Ξ©[m] A) = Ξ©[m+n] (A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact ap ploop_space IH}
end
definition loop_space_succ_eq_out (n : β) : Ξ©[succ n] A = Ξ©(Ξ©[n] A) :=
idp
variable {A}
/- the equality [loop_space_succ_eq_in] preserves concatenation -/
theorem loop_space_succ_eq_in_concat {n : β} (p q : Ξ©[succ (succ n)] A) :
transport carrier (ap ploop_space (loop_space_succ_eq_in A n)) (p β¬ q)
= transport carrier (ap ploop_space (loop_space_succ_eq_in A n)) p
β¬ transport carrier (ap ploop_space (loop_space_succ_eq_in A n)) q :=
begin
rewrite [-+tr_compose, βfunction.compose],
rewrite [+@transport_eq_FlFr_D _ _ _ _ Point Point, +con.assoc], apply whisker_left,
rewrite [-+con.assoc], apply whisker_right, rewrite [con_inv_cancel_right, βΈ*, -ap_con]
end
definition loop_space_loop_irrel (p : point A = point A) : Ξ©(pointed.Mk p) = Ξ©[2] A :=
begin
intros, fapply pType_eq,
{ esimp, transitivity _,
apply eq_equiv_fn_eq_of_equiv (equiv_eq_closed_right _ pβ»ΒΉ),
esimp, apply eq_equiv_eq_closed, apply con.right_inv, apply con.right_inv},
{ esimp, apply con.left_inv}
end
definition iterated_loop_space_loop_irrel (n : β) (p : point A = point A)
: Ξ©[succ n](pointed.Mk p) = Ξ©[succ (succ n)] A :> pType :=
calc
Ξ©[succ n](pointed.Mk p) = Ξ©[n](Ξ© (pointed.Mk p)) : loop_space_succ_eq_in
... = Ξ©[n] (Ξ©[2] A) : loop_space_loop_irrel
... = Ξ©[2+n] A : loop_space_add
... = Ξ©[n+2] A : by rewrite [algebra.add.comm]
end pointed open pointed
namespace pointed
variables {A B C D : Type*} {f g h : A β* B}
/- categorical properties of pointed maps -/
definition pmap_of_map [constructor] {A B : Type} (f : A β B) (a : A) :
pointed.MK A a β* pointed.MK B (f a) :=
pmap.mk f idp
definition pid [constructor] [refl] (A : Type*) : A β* A :=
pmap.mk id idp
definition pcompose [constructor] [trans] (g : B β* C) (f : A β* B) : A β* C :=
pmap.mk (Ξ»a, g (f a)) (ap g (respect_pt f) β¬ respect_pt g)
infixr ` β* `:60 := pcompose
definition passoc (h : C β* D) (g : B β* C) (f : A β* B) : (h β* g) β* f ~* h β* (g β* f) :=
begin
fconstructor, intro a, reflexivity,
cases A, cases B, cases C, cases D, cases f with f pf, cases g with g pg, cases h with h ph,
esimp at *,
induction pf, induction pg, induction ph, reflexivity
end
definition pid_comp [constructor] (f : A β* B) : pid B β* f ~* f :=
begin
fconstructor,
{ intro a, reflexivity},
{ reflexivity}
end
definition comp_pid [constructor] (f : A β* B) : f β* pid A ~* f :=
begin
fconstructor,
{ intro a, reflexivity},
{ reflexivity}
end
/- equivalences and equalities -/
definition pmap_eq (r : Ξ a, f a = g a) (s : respect_pt f = (r pt) β¬ respect_pt g) : f = g :=
begin
cases f with f p, cases g with g q,
esimp at *,
fapply apo011 pmap.mk,
{ exact eq_of_homotopy r},
{ apply concato_eq, apply pathover_eq_Fl, apply inv_con_eq_of_eq_con,
rewrite [ap_eq_ap10,βap10,apd10_eq_of_homotopy,s]}
end
definition pmap_equiv_left (A : Type) (B : Type*) : Aβ β* B β (A β B) :=
begin
fapply equiv.MK,
{ intro f a, cases f with f p, exact f (some a)},
{ intro f, fconstructor,
intro a, cases a, exact pt, exact f a,
reflexivity},
{ intro f, reflexivity},
{ intro f, cases f with f p, esimp, fapply pmap_eq,
{ intro a, cases a; all_goals (esimp at *), exact pβ»ΒΉ},
{ esimp, exact !con.left_invβ»ΒΉ}},
end
definition pmap_equiv_right (A : Type*) (B : Type)
: (Ξ£(b : B), A β* (pointed.Mk b)) β (A β B) :=
begin
fapply equiv.MK,
{ intro u a, exact pmap.to_fun u.2 a},
{ intro f, refine β¨f pt, _β©, fapply pmap.mk,
intro a, esimp, exact f a,
reflexivity},
{ intro f, reflexivity},
{ intro u, cases u with b f, cases f with f p, esimp at *, induction p,
reflexivity}
end
definition pmap_bool_equiv (B : Type*) : (pbool β* B) β B :=
begin
fapply equiv.MK,
{ intro f, cases f with f p, exact f tt},
{ intro b, fconstructor,
intro u, cases u, exact pt, exact b,
reflexivity},
{ intro b, reflexivity},
{ intro f, cases f with f p, esimp, fapply pmap_eq,
{ intro a, cases a; all_goals (esimp at *), exact pβ»ΒΉ},
{ esimp, exact !con.left_invβ»ΒΉ}},
end
-- The constant pointed map between any two types
definition pconst [constructor] (A B : Type*) : A β* B :=
pmap.mk (Ξ» a, Point B) idp
-- the pointed type of pointed maps
definition ppmap [constructor] (A B : Type*) : Type* :=
pType.mk (A β* B) (pconst A B)
/- instances of pointed maps -/
definition pcast [constructor] {A B : Type*} (p : A = B) : A β* B :=
pmap.mk (cast (ap pType.carrier p)) (by induction p; reflexivity)
definition pinverse [constructor] {X : Type*} : Ξ© X β* Ξ© X :=
pmap.mk eq.inverse idp
definition ap1 [constructor] (f : A β* B) : Ξ© A β* Ξ© B :=
begin
fconstructor,
{ intro p, exact !respect_ptβ»ΒΉ β¬ ap f p β¬ !respect_pt},
{ esimp, apply con.left_inv}
end
definition apn (n : β) (f : A β* B) : Ξ©[n] A β* Ξ©[n] B :=
begin
induction n with n IH,
{ exact f},
{ esimp [iterated_ploop_space], exact ap1 IH}
end
prefix `Ξ©β`:(max+5) := ap1
notation `Ξ©β[`:95 n:0 `] `:0 f:95 := apn n f
/- categorical properties of pointed homotopies -/
protected definition phomotopy.refl [constructor] [refl] (f : A β* B) : f ~* f :=
begin
fconstructor,
{ intro a, exact idp},
{ apply idp_con}
end
protected definition phomotopy.rfl [constructor] {f : A β* B} : f ~* f :=
phomotopy.refl f
protected definition phomotopy.trans [constructor] [trans] (p : f ~* g) (q : g ~* h)
: f ~* h :=
phomotopy.mk (Ξ»a, p a β¬ q a)
abstract begin
induction f, induction g, induction p with p p', induction q with q q', esimp at *,
induction p', induction q', esimp, apply con.assoc
end end
protected definition phomotopy.symm [constructor] [symm] (p : f ~* g) : g ~* f :=
phomotopy.mk (Ξ»a, (p a)β»ΒΉ)
abstract begin
induction f, induction p with p p', esimp at *,
induction p', esimp, apply inv_con_cancel_left
end end
infix ` β¬* `:75 := phomotopy.trans
postfix `β»ΒΉ*`:(max+1) := phomotopy.symm
/- properties about the given pointed maps -/
definition is_equiv_ap1 (f : A β* B) [is_equiv f] : is_equiv (ap1 f) :=
begin
induction B with B b, induction f with f pf, esimp at *, cases pf, esimp,
apply is_equiv.homotopy_closed (ap f),
intro p, exact !idp_conβ»ΒΉ
end
definition is_equiv_apn (n : β) (f : A β* B) [H : is_equiv f]
: is_equiv (apn n f) :=
begin
induction n with n IH,
{ exact H},
{ exact is_equiv_ap1 (apn n f)}
end
definition is_equiv_pcast [instance] {A B : Type*} (p : A = B) : is_equiv (pcast p) :=
!is_equiv_cast
definition ap1_id [constructor] {A : Type*} : ap1 (pid A) ~* pid (Ξ© A) :=
begin
fapply phomotopy.mk,
{ intro p, esimp, refine !idp_con β¬ !ap_id},
{ reflexivity}
end
definition ap1_pinverse {A : Type*} : ap1 (@pinverse A) ~* @pinverse (Ξ© A) :=
begin
fapply phomotopy.mk,
{ intro p, esimp, refine !idp_con β¬ _, exact !inv_eq_inv2β»ΒΉ },
{ reflexivity}
end
definition ap1_compose (g : B β* C) (f : A β* B) : ap1 (g β* f) ~* ap1 g β* ap1 f :=
begin
induction B, induction C, induction g with g pg, induction f with f pf, esimp at *,
induction pg, induction pf,
fconstructor,
{ intro p, esimp, apply whisker_left, exact ap_compose g f p β¬ ap (ap g) !idp_conβ»ΒΉ},
{ reflexivity}
end
definition ap1_compose_pinverse (f : A β* B) : ap1 f β* pinverse ~* pinverse β* ap1 f :=
begin
fconstructor,
{ intro p, esimp, refine !con.assoc β¬ _ β¬ !con_invβ»ΒΉ, apply whisker_left,
refine whisker_right !ap_inv _ β¬ _ β¬ !con_invβ»ΒΉ, apply whisker_left,
exact !inv_invβ»ΒΉ},
{ induction B with B b, induction f with f pf, esimp at *, induction pf, reflexivity},
end
theorem ap1_con (f : A β* B) (p q : Ξ© A) : ap1 f (p β¬ q) = ap1 f p β¬ ap1 f q :=
begin
rewrite [βΈ*,ap_con, +con.assoc, con_inv_cancel_left], repeat apply whisker_left
end
theorem ap1_inv (f : A β* B) (p : Ξ© A) : ap1 f pβ»ΒΉ = (ap1 f p)β»ΒΉ :=
begin
rewrite [βΈ*,ap_inv, +con_inv, inv_inv, +con.assoc], repeat apply whisker_left
end
definition pcast_ap_loop_space {A B : Type*} (p : A = B)
: pcast (ap ploop_space p) ~* Ξ©β (pcast p) :=
begin
induction p, exact !ap1_idβ»ΒΉ*
end
definition pinverse_con [constructor] {X : Type*} (p q : Ξ© X)
: pinverse (p β¬ q) = pinverse q β¬ pinverse p :=
!con_inv
definition pinverse_inv [constructor] {X : Type*} (p : Ξ© X)
: pinverse pβ»ΒΉ = (pinverse p)β»ΒΉ :=
idp
definition pcast_idp [constructor] {A : Type*} : pcast (idpath A) ~* pid A :=
by reflexivity
definition apn_zero [unfold_full] (f : A β* B) : Ξ©β[0] f = f := idp
definition apn_succ [unfold_full] (n : β) (f : A β* B) : Ξ©β[n + 1] f = Ξ©β (Ξ©β[n] f) := idp
/- more on pointed homotopies -/
definition phomotopy_of_eq [constructor] {A B : Type*} {f g : A β* B} (p : f = g) : f ~* g :=
phomotopy.mk (ap010 pmap.to_fun p) begin induction p, apply idp_con end
definition pconcat_eq [constructor] {A B : Type*} {f g h : A β* B} (p : f ~* g) (q : g = h)
: f ~* h :=
p β¬* phomotopy_of_eq q
definition eq_pconcat [constructor] {A B : Type*} {f g h : A β* B} (p : f = g) (q : g ~* h)
: f ~* h :=
phomotopy_of_eq p β¬* q
infix ` β¬*p `:75 := pconcat_eq
infix ` β¬p* `:75 := eq_pconcat
definition pwhisker_left [constructor] (h : B β* C) (p : f ~* g) : h β* f ~* h β* g :=
phomotopy.mk (Ξ»a, ap h (p a))
abstract begin
induction A, induction B, induction C,
induction f with f pf, induction g with g pg, induction h with h ph,
induction p with p p', esimp at *, induction ph, induction pg, induction p', reflexivity
end end
definition pwhisker_right [constructor] (h : C β* A) (p : f ~* g) : f β* h ~* g β* h :=
phomotopy.mk (Ξ»a, p (h a))
abstract begin
induction A, induction B, induction C,
induction f with f pf, induction g with g pg, induction h with h ph,
induction p with p p', esimp at *, induction ph, induction pg, induction p', esimp,
exact !idp_conβ»ΒΉ
end end
definition pconcat2 [constructor] {A B C : Type*} {h i : B β* C} {f g : A β* B}
(q : h ~* i) (p : f ~* g) : h β* f ~* i β* g :=
pwhisker_left _ p β¬* pwhisker_right _ q
definition eq_of_phomotopy (p : f ~* g) : f = g :=
begin
fapply pmap_eq,
{ intro a, exact p a},
{ exact !to_homotopy_ptβ»ΒΉ}
end
/-
In general we need function extensionality for pap,
but for particular F we can do it without function extensionality.
-/
definition pap (F : (A β* B) β (C β* D)) {f g : A β* B} (p : f ~* g) : F f ~* F g :=
phomotopy.mk (ap010 F (eq_of_phomotopy p)) begin cases eq_of_phomotopy p, apply idp_con end
definition ap1_phomotopy {f g : A β* B} (p : f ~* g)
: ap1 f ~* ap1 g :=
begin
induction p with p q, induction f with f pf, induction g with g pg, induction B with B b,
esimp at *, induction q, induction pg,
fapply phomotopy.mk,
{ intro l, esimp, refine _ β¬ !idp_conβ»ΒΉ, refine !con.assoc β¬ _, apply inv_con_eq_of_eq_con,
apply ap_con_eq_con_ap},
{ unfold [ap_con_eq_con_ap], generalize p (Point A), generalize g (Point A), intro b q,
induction q, reflexivity}
end
definition apn_phomotopy {f g : A β* B} (n : β) (p : f ~* g) : apn n f ~* apn n g :=
begin
induction n with n IH,
{ exact p},
{ exact ap1_phomotopy IH}
end
definition apn_compose (n : β) (g : B β* C) (f : A β* B) : apn n (g β* f) ~* apn n g β* apn n f :=
begin
induction n with n IH,
{ reflexivity},
{ refine ap1_phomotopy IH β¬* _, apply ap1_compose}
end
definition apn_pid [constructor] {A : Type*} (n : β) : apn n (pid A) ~* pid (Ξ©[n] A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact ap1_phomotopy IH β¬* ap1_id}
end
theorem apn_con (n : β) (f : A β* B) (p q : Ξ©[n+1] A)
: apn (n+1) f (p β¬ q) = apn (n+1) f p β¬ apn (n+1) f q :=
by rewrite [+apn_succ, ap1_con]
theorem apn_inv (n : β) (f : A β* B) (p : Ξ©[n+1] A) : apn (n+1) f pβ»ΒΉ = (apn (n+1) f p)β»ΒΉ :=
by rewrite [+apn_succ, ap1_inv]
definition pinverse_pinverse (A : Type*) : pinverse β* pinverse ~* pid (Ξ© A) :=
begin
fapply phomotopy.mk,
{ apply inv_inv},
{ reflexivity}
end
definition pcast_loop_space [constructor] {A B : Type*} (p : A = B) :
pcast (ap Ξ© p) ~* ap1 (pcast p) :=
begin
fapply phomotopy.mk,
{ intro a, induction p, esimp, exact (!idp_con β¬ !ap_id)β»ΒΉ},
{ induction p, reflexivity}
end
definition apn_succ_phomotopy_in (n : β) (f : A β* B) :
pcast (loop_space_succ_eq_in B n) β* Ξ©β[n + 1] f ~*
Ξ©β[n] (Ξ©β f) β* pcast (loop_space_succ_eq_in A n) :=
begin
induction n with n IH,
{ reflexivity},
{ refine pwhisker_right _ (pcast_loop_space (loop_space_succ_eq_in B n)) β¬* _,
refine _ β¬* pwhisker_left _ (pcast_loop_space (loop_space_succ_eq_in A n))β»ΒΉ*,
refine (ap1_compose _ (Ξ©β[n + 1] f))β»ΒΉ* β¬* _ β¬* ap1_compose (Ξ©β[n] (Ξ©β f)) _,
exact ap1_phomotopy IH}
end
definition ap1_pmap_of_map [constructor] {A B : Type} (f : A β B) (a : A) :
ap1 (pmap_of_map f a) ~* pmap_of_map (ap f) (idpath a) :=
begin
fapply phomotopy.mk,
{ intro a, esimp, apply idp_con},
{ reflexivity}
end
definition pmap_of_eq_pt [constructor] {A : Type} {a a' : A} (p : a = a') :
pointed.MK A a β* pointed.MK A a' :=
pmap.mk id p
/- pointed equivalences -/
definition pequiv_of_pmap [constructor] (f : A β* B) (H : is_equiv f) : A β* B :=
pequiv.mk f _ (respect_pt f)
definition pequiv_of_equiv [constructor] (f : A β B) (H : f pt = pt) : A β* B :=
pequiv.mk f _ H
protected definition pequiv.MK [constructor] (f : A β* B) (g : B β A)
(gf : Ξ a, g (f a) = a) (fg : Ξ b, f (g b) = b) : A β* B :=
pequiv.mk f (adjointify f g fg gf) (respect_pt f)
definition equiv_of_pequiv [constructor] (f : A β* B) : A β B :=
equiv.mk f _
definition to_pinv [constructor] (f : A β* B) : B β* A :=
pmap.mk fβ»ΒΉ ((ap fβ»ΒΉ (respect_pt f))β»ΒΉ β¬ left_inv f pt)
definition to_pmap_pequiv_of_pmap {A B : Type*} (f : A β* B) (H : is_equiv f)
: pequiv.to_pmap (pequiv_of_pmap f H) = f :=
by cases f; reflexivity
/-
A version of pequiv.MK with stronger conditions.
The advantage of defining a pointed equivalence with this definition is that there is a
pointed homotopy between the inverse of the resulting equivalence and the given pointed map g.
This is not the case when using `pequiv.MK` (if g is a pointed map),
that will only give an ordinary homotopy.
-/
protected definition pequiv.MK2 [constructor] (f : A β* B) (g : B β* A)
(gf : g β* f ~* !pid) (fg : f β* g ~* !pid) : A β* B :=
pequiv.MK f g gf fg
definition to_pmap_pequiv_MK2 [constructor] (f : A β* B) (g : B β* A)
(gf : g β* f ~* !pid) (fg : f β* g ~* !pid) : pequiv.MK2 f g gf fg ~* f :=
phomotopy.mk (Ξ»b, idp) !idp_con
definition to_pinv_pequiv_MK2 [constructor] (f : A β* B) (g : B β* A)
(gf : g β* f ~* !pid) (fg : f β* g ~* !pid) : to_pinv (pequiv.MK2 f g gf fg) ~* g :=
phomotopy.mk (Ξ»b, idp)
abstract [irreducible] begin
esimp, unfold [adjointify_left_inv'],
note H := to_homotopy_pt gf, note H2 := to_homotopy_pt fg,
note H3 := eq_top_of_square (natural_square_tr (to_homotopy fg) (respect_pt f)),
rewrite [βΈ* at *, H, H3, H2, ap_id, - +con.assoc, ap_compose' f g, con_inv,
- ap_inv, - +ap_con g],
apply whisker_right, apply ap02 g,
rewrite [ap_con, - + con.assoc, +ap_inv, +inv_con_cancel_right, con.left_inv],
end end
definition pua {A B : Type*} (f : A β* B) : A = B :=
pType_eq (equiv_of_pequiv f) !respect_pt
protected definition pequiv.refl [refl] [constructor] (A : Type*) : A β* A :=
pequiv_of_pmap !pid !is_equiv_id
protected definition pequiv.rfl [constructor] : A β* A :=
pequiv.refl A
protected definition pequiv.symm [symm] (f : A β* B) : B β* A :=
pequiv_of_pmap (to_pinv f) !is_equiv_inv
protected definition pequiv.trans [trans] (f : A β* B) (g : B β* C) : A β* C :=
pequiv_of_pmap (g β* f) !is_equiv_compose
postfix `β»ΒΉα΅*`:(max + 1) := pequiv.symm
infix ` β¬e* `:75 := pequiv.trans
definition to_pmap_pequiv_trans {A B C : Type*} (f : A β* B) (g : B β* C)
: pequiv.to_pmap (f β¬e* g) = g β* f :=
!to_pmap_pequiv_of_pmap
definition pequiv_change_fun [constructor] (f : A β* B) (f' : A β* B) (Heq : f ~ f') : A β* B :=
pequiv_of_pmap f' (is_equiv.homotopy_closed f Heq)
definition pequiv_change_inv [constructor] (f : A β* B) (f' : B β* A) (Heq : to_pinv f ~ f')
: A β* B :=
pequiv.MK f f' (to_left_inv (equiv_change_inv f Heq)) (to_right_inv (equiv_change_inv f Heq))
definition pequiv_rect' (f : A β* B) (P : A β B β Type)
(g : Ξ b, P (fβ»ΒΉ b) b) (a : A) : P a (f a) :=
left_inv f a βΈ g (f a)
definition pequiv_of_eq [constructor] {A B : Type*} (p : A = B) : A β* B :=
pequiv_of_pmap (pcast p) !is_equiv_tr
definition peconcat_eq {A B C : Type*} (p : A β* B) (q : B = C) : A β* C :=
p β¬e* pequiv_of_eq q
definition eq_peconcat {A B C : Type*} (p : A = B) (q : B β* C) : A β* C :=
pequiv_of_eq p β¬e* q
definition eq_of_pequiv {A B : Type*} (p : A β* B) : A = B :=
pType_eq (equiv_of_pequiv p) !respect_pt
definition peap {A B : Type*} (F : Type* β Type*) (p : A β* B) : F A β* F B :=
pequiv_of_pmap (pcast (ap F (eq_of_pequiv p))) begin cases eq_of_pequiv p, apply is_equiv_id end
definition pequiv_eq {p q : A β* B} (H : p = q :> (A β* B)) : p = q :=
begin
cases p with f Hf, cases q with g Hg, esimp at *,
exact apd011 pequiv_of_pmap H !is_prop.elim
end
infix ` β¬e*p `:75 := peconcat_eq
infix ` β¬pe* `:75 := eq_peconcat
local attribute pequiv.symm [constructor]
definition pleft_inv (f : A β* B) : fβ»ΒΉα΅* β* f ~* pid A :=
phomotopy.mk (left_inv f)
abstract begin
esimp, symmetry, apply con_inv_cancel_left
end end
definition pright_inv (f : A β* B) : f β* fβ»ΒΉα΅* ~* pid B :=
phomotopy.mk (right_inv f)
abstract begin
induction f with f H p, esimp,
rewrite [ap_con, +ap_inv, -adj f, -ap_compose],
note q := natural_square (right_inv f) p,
rewrite [ap_id at q],
apply eq_bot_of_square,
exact transpose q
end end
definition pcancel_left (f : B β* C) {g h : A β* B} (p : f β* g ~* f β* h) : g ~* h :=
begin
refine _β»ΒΉ* β¬* pwhisker_left fβ»ΒΉα΅* p β¬* _:
refine !passocβ»ΒΉ* β¬* _:
refine pwhisker_right _ (pleft_inv f) β¬* _:
apply pid_comp
end
definition pcancel_right (f : A β* B) {g h : B β* C} (p : g β* f ~* h β* f) : g ~* h :=
begin
refine _β»ΒΉ* β¬* pwhisker_right fβ»ΒΉα΅* p β¬* _:
refine !passoc β¬* _:
refine pwhisker_left _ (pright_inv f) β¬* _:
apply comp_pid
end
definition phomotopy_pinv_right_of_phomotopy {f : A β* B} {g : B β* C} {h : A β* C}
(p : g β* f ~* h) : g ~* h β* fβ»ΒΉα΅* :=
begin
refine _ β¬* pwhisker_right _ p, symmetry,
refine !passoc β¬* _,
refine pwhisker_left _ (pright_inv f) β¬* _,
apply comp_pid
end
definition phomotopy_of_pinv_right_phomotopy {f : B β* A} {g : B β* C} {h : A β* C}
(p : g β* fβ»ΒΉα΅* ~* h) : g ~* h β* f :=
begin
refine _ β¬* pwhisker_right _ p, symmetry,
refine !passoc β¬* _,
refine pwhisker_left _ (pleft_inv f) β¬* _,
apply comp_pid
end
definition pinv_right_phomotopy_of_phomotopy {f : A β* B} {g : B β* C} {h : A β* C}
(p : h ~* g β* f) : h β* fβ»ΒΉα΅* ~* g :=
(phomotopy_pinv_right_of_phomotopy pβ»ΒΉ*)β»ΒΉ*
definition phomotopy_of_phomotopy_pinv_right {f : B β* A} {g : B β* C} {h : A β* C}
(p : h ~* g β* fβ»ΒΉα΅*) : h β* f ~* g :=
(phomotopy_of_pinv_right_phomotopy pβ»ΒΉ*)β»ΒΉ*
definition phomotopy_pinv_left_of_phomotopy {f : B β* C} {g : A β* B} {h : A β* C}
(p : f β* g ~* h) : g ~* fβ»ΒΉα΅* β* h :=
begin
refine _ β¬* pwhisker_left _ p, symmetry,
refine !passocβ»ΒΉ* β¬* _,
refine pwhisker_right _ (pleft_inv f) β¬* _,
apply pid_comp
end
definition phomotopy_of_pinv_left_phomotopy {f : C β* B} {g : A β* B} {h : A β* C}
(p : fβ»ΒΉα΅* β* g ~* h) : g ~* f β* h :=
begin
refine _ β¬* pwhisker_left _ p, symmetry,
refine !passocβ»ΒΉ* β¬* _,
refine pwhisker_right _ (pright_inv f) β¬* _,
apply pid_comp
end
definition pinv_left_phomotopy_of_phomotopy {f : B β* C} {g : A β* B} {h : A β* C}
(p : h ~* f β* g) : fβ»ΒΉα΅* β* h ~* g :=
(phomotopy_pinv_left_of_phomotopy pβ»ΒΉ*)β»ΒΉ*
definition phomotopy_of_phomotopy_pinv_left {f : C β* B} {g : A β* B} {h : A β* C}
(p : h ~* fβ»ΒΉα΅* β* g) : f β* h ~* g :=
(phomotopy_of_pinv_left_phomotopy pβ»ΒΉ*)β»ΒΉ*
/- pointed equivalences between particular pointed types -/
definition loopn_pequiv_loopn [constructor] (n : β) (f : A β* B) : Ξ©[n] A β* Ξ©[n] B :=
pequiv.MK2 (apn n f) (apn n fβ»ΒΉα΅*)
abstract begin
induction n with n IH,
{ apply pleft_inv},
{ replace nat.succ n with n + 1,
rewrite [+apn_succ],
refine !ap1_composeβ»ΒΉ* β¬* _,
refine ap1_phomotopy IH β¬* _,
apply ap1_id}
end end
abstract begin
induction n with n IH,
{ apply pright_inv},
{ replace nat.succ n with n + 1,
rewrite [+apn_succ],
refine !ap1_composeβ»ΒΉ* β¬* _,
refine ap1_phomotopy IH β¬* _,
apply ap1_id}
end end
definition loop_pequiv_loop [constructor] (f : A β* B) : Ξ© A β* Ξ© B :=
loopn_pequiv_loopn 1 f
definition to_pmap_loopn_pequiv_loopn [constructor] (n : β) (f : A β* B)
: loopn_pequiv_loopn n f ~* apn n f :=
!to_pmap_pequiv_MK2
definition to_pinv_loopn_pequiv_loopn [constructor] (n : β) (f : A β* B)
: (loopn_pequiv_loopn n f)β»ΒΉα΅* ~* apn n fβ»ΒΉα΅* :=
!to_pinv_pequiv_MK2
definition loopn_pequiv_loopn_con (n : β) (f : A β* B) (p q : Ξ©[n+1] A)
: loopn_pequiv_loopn (n+1) f (p β¬ q) =
loopn_pequiv_loopn (n+1) f p β¬ loopn_pequiv_loopn (n+1) f q :=
ap1_con (loopn_pequiv_loopn n f) p q
definition loop_pequiv_loop_con {A B : Type*} (f : A β* B) (p q : Ξ© A)
: loop_pequiv_loop f (p β¬ q) = loop_pequiv_loop f p β¬ loop_pequiv_loop f q :=
loopn_pequiv_loopn_con 0 f p q
definition loopn_pequiv_loopn_rfl (n : β) (A : Type*) :
loopn_pequiv_loopn n (pequiv.refl A) = pequiv.refl (Ξ©[n] A) :=
begin
apply pequiv_eq, apply eq_of_phomotopy,
exact !to_pmap_loopn_pequiv_loopn β¬* apn_pid n,
end
definition loop_pequiv_loop_rfl (A : Type*) :
loop_pequiv_loop (pequiv.refl A) = pequiv.refl (Ξ© A) :=
loopn_pequiv_loopn_rfl 1 A
definition pmap_functor [constructor] {A A' B B' : Type*} (f : A' β* A) (g : B β* B') :
ppmap A B β* ppmap A' B' :=
pmap.mk (Ξ»h, g β* h β* f)
abstract begin
fapply pmap_eq,
{ esimp, intro a, exact respect_pt g},
{ rewrite [βΈ*, ap_constant], apply idp_con}
end end
definition pequiv_pinverse (A : Type*) : Ξ© A β* Ξ© A :=
pequiv_of_pmap pinverse !is_equiv_eq_inverse
definition pequiv_of_eq_pt [constructor] {A : Type} {a a' : A} (p : a = a') :
pointed.MK A a β* pointed.MK A a' :=
pequiv_of_pmap (pmap_of_eq_pt p) !is_equiv_id
/- -- TODO
definition pmap_pequiv_pmap {A A' B B' : Type*} (f : A β* A') (g : B β* B') :
ppmap A B β* ppmap A' B' :=
pequiv.MK (pmap_functor fβ»ΒΉα΅* g) (pmap_functor f gβ»ΒΉα΅*)
abstract begin
intro a, esimp, apply pmap_eq,
{ esimp, },
{ }
end end
abstract begin
end end
-/
end pointed
|
57099fcc91a6f6076f556ff1d96575ab91453a83
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/tactic/zify.lean
|
e92e06714a34f01801131599984a0232c61d8fb6
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 5,432
|
lean
|
/-
Copyright (c) 2020 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import data.int.cast -- used by clients
import data.int.char_zero
import tactic.norm_cast
/-!
# A tactic to shift `β` goals to `β€`
It is often easier to work in `β€`, where subtraction is well behaved, than in `β` where it isn't.
`zify` is a tactic that casts goals and hypotheses about natural numbers to ones about integers.
It makes use of `push_cast`, part of the `norm_cast` family, to simplify these goals.
## Implementation notes
`zify` is extensible, using the attribute `@[zify]` to label lemmas used for moving propositions
from `β` to `β€`.
`zify` lemmas should have the form `β aβ ... aβ : β, Pz (aβ : β€) ... (aβ : β€) β Pn aβ ... aβ`.
For example, `int.coe_nat_le_coe_nat_iff : β (m n : β), βm β€ βn β m β€ n` is a `zify` lemma.
`zify` is very nearly just `simp only with zify push_cast`. There are a few minor differences:
* `zify` lemmas are used in the opposite order of the standard simp form.
E.g. we will rewrite with `int.coe_nat_le_coe_nat_iff` from right to left.
* `zify` should fail if no `zify` lemma applies (i.e. it was unable to shift any proposition to β€).
However, once this succeeds, it does not necessarily need to rewrite with any `push_cast` rules.
-/
open tactic
namespace zify
/--
The `zify` attribute is used by the `zify` tactic. It applies to lemmas that shift propositions
between `nat` and `int`.
`zify` lemmas should have the form `β aβ ... aβ : β, Pz (aβ : β€) ... (aβ : β€) β Pn aβ ... aβ`.
For example, `int.coe_nat_le_coe_nat_iff : β (m n : β), βm β€ βn β m β€ n` is a `zify` lemma.
-/
@[user_attribute]
meta def zify_attr : user_attribute simp_lemmas unit :=
{ name := `zify,
descr := "Used to tag lemmas for use in the `zify` tactic",
cache_cfg :=
{ mk_cache :=
Ξ» ns, mmap (Ξ» n, do c β mk_const n, return (c, tt)) ns >>= simp_lemmas.mk.append_with_symm,
dependencies := [] } }
/--
Given an expression `e`, `lift_to_z e` looks for subterms of `e` that are propositions "about"
natural numbers and change them to propositions about integers.
Returns an expression `e'` and a proof that `e = e'`.
Includes `ge_iff_le` and `gt_iff_lt` in the simp set. These can't be tagged with `zify` as we
want to use them in the "forward", not "backward", direction.
-/
meta def lift_to_z (e : expr) : tactic (expr Γ expr) :=
do sl β zify_attr.get_cache,
sl β sl.add_simp `ge_iff_le, sl β sl.add_simp `gt_iff_lt,
(e', prf, _) β simplify sl [] e,
return (e', prf)
attribute [zify] int.coe_nat_le_coe_nat_iff int.coe_nat_lt_coe_nat_iff int.coe_nat_eq_coe_nat_iff
end zify
@[zify] lemma int.coe_nat_ne_coe_nat_iff (a b : β) : (a : β€) β b β a β b :=
by simp
/--
`zify extra_lems e` is used to shift propositions in `e` from `β` to `β€`.
This is often useful since `β€` has well-behaved subtraction.
The list of extra lemmas is used in the `push_cast` step.
Returns an expression `e'` and a proof that `e = e'`.-/
meta def tactic.zify (extra_lems : list simp_arg_type) : expr β tactic (expr Γ expr) := Ξ» z,
do (z1, p1) β zify.lift_to_z z <|> fail "failed to find an applicable zify lemma",
(z2, p2) β norm_cast.derive_push_cast extra_lems z1,
prod.mk z2 <$> mk_eq_trans p1 p2
/--
A variant of `tactic.zify` that takes `h`, a proof of a proposition about natural numbers,
and returns a proof of the zified version of that propositon.
-/
meta def tactic.zify_proof (extra_lems : list simp_arg_type) (h : expr) : tactic expr :=
do (_, pf) β infer_type h >>= tactic.zify extra_lems,
mk_eq_mp pf h
section
setup_tactic_parser
/--
The `zify` tactic is used to shift propositions from `β` to `β€`.
This is often useful since `β€` has well-behaved subtraction.
```lean
example (a b c x y z : β) (h : Β¬ x*y*z < 0) : c < a + 3*b :=
begin
zify,
zify at h,
/-
h : Β¬βx * βy * βz < 0
β’ βc < βa + 3 * βb
-/
end
```
`zify` can be given extra lemmas to use in simplification. This is especially useful in the
presence of nat subtraction: passing `β€` arguments will allow `push_cast` to do more work.
```
example (a b c : β) (h : a - b < c) (hab : b β€ a) : false :=
begin
zify [hab] at h,
/- h : βa - βb < βc -/
end
```
`zify` makes use of the `@[zify]` attribute to move propositions,
and the `push_cast` tactic to simplify the `β€`-valued expressions.
`zify` is in some sense dual to the `lift` tactic. `lift (z : β€) to β` will change the type of an
integer `z` (in the supertype) to `β` (the subtype), given a proof that `z β₯ 0`;
propositions concerning `z` will still be over `β€`. `zify` changes propositions about `β` (the
subtype) to propositions about `β€` (the supertype), without changing the type of any variable.
-/
meta def tactic.interactive.zify (sl : parse simp_arg_list) (l : parse location) : tactic unit :=
do locs β l.get_locals,
replace_at (tactic.zify sl) locs l.include_goal >>= guardb
end
add_tactic_doc
{ name := "zify",
category := doc_category.attr,
decl_names := [`zify.zify_attr],
tags := ["coercions", "transport"] }
add_tactic_doc
{ name := "zify",
category := doc_category.tactic,
decl_names := [`tactic.interactive.zify],
tags := ["coercions", "transport"] }
|
6ef6d2e24cae6a80d4c9ddc09cadf865da0ba847
|
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
|
/src/Lean/Compiler/Specialize.lean
|
e5b4a9fc09de1e93087ccce66a9f3a90af750a74
|
[
"Apache-2.0"
] |
permissive
|
walterhu1015/lean4
|
b2c71b688975177402758924eaa513475ed6ce72
|
2214d81e84646a905d0b20b032c89caf89c737ad
|
refs/heads/master
| 1,671,342,096,906
| 1,599,695,985,000
| 1,599,695,985,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,454
|
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.Attributes
import Lean.Compiler.Util
namespace Lean
namespace Compiler
inductive SpecializeAttributeKind
| specialize | nospecialize
namespace SpecializeAttributeKind
instance : Inhabited SpecializeAttributeKind := β¨SpecializeAttributeKind.specializeβ©
protected def beq : SpecializeAttributeKind β SpecializeAttributeKind β Bool
| specialize, specialize => true
| nospecialize, nospecialize => true
| _, _ => false
instance : HasBeq SpecializeAttributeKind := β¨SpecializeAttributeKind.beqβ©
end SpecializeAttributeKind
def mkSpecializeAttrs : IO (EnumAttributes SpecializeAttributeKind) :=
registerEnumAttributes `specializeAttrs
[(`specialize, "mark definition to always be inlined", SpecializeAttributeKind.specialize),
(`nospecialize, "mark definition to never be inlined", SpecializeAttributeKind.nospecialize) ]
/- TODO: fix the following hack.
We need to use the following hack because the equation compiler generates auxiliary
definitions that are compiled before we even finish the elaboration of the current command.
So, if the current command is a `@[specialize] def foo ...`, we must set the attribute `[specialize]`
before we start elaboration, otherwise when we compile the auxiliary definitions we will not be
able to test whether `@[specialize]` has been set or not.
In the new equation compiler we should pass all attributes and allow it to apply them to auxiliary definitions.
In the current implementation, we workaround this issue by using functions such as `hasSpecializeAttrAux`.
-/
(fun declName _ => pure ())
AttributeApplicationTime.beforeElaboration
@[init mkSpecializeAttrs]
constant specializeAttrs : EnumAttributes SpecializeAttributeKind := arbitrary _
private partial def hasSpecializeAttrAux (env : Environment) (kind : SpecializeAttributeKind) : Name β Bool
| n => match specializeAttrs.getValue env n with
| some k => kind == k
| none => if n.isInternal then hasSpecializeAttrAux n.getPrefix else false
@[export lean_has_specialize_attribute]
def hasSpecializeAttribute (env : Environment) (n : Name) : Bool :=
hasSpecializeAttrAux env SpecializeAttributeKind.specialize n
@[export lean_has_nospecialize_attribute]
def hasNospecializeAttribute (env : Environment) (n : Name) : Bool :=
hasSpecializeAttrAux env SpecializeAttributeKind.nospecialize n
inductive SpecArgKind
| fixed
| fixedNeutral -- computationally neutral
| fixedHO -- higher order
| fixedInst -- type class instance
| other
structure SpecInfo :=
(mutualDecls : List Name) (argKinds : SpecArgKind)
structure SpecState :=
(specInfo : SMap Name SpecInfo := {})
(cache : SMap Expr Name := {})
inductive SpecEntry
| info (name : Name) (info : SpecInfo)
| cache (key : Expr) (fn : Name)
namespace SpecState
instance : Inhabited SpecState := β¨{}β©
def addEntry (s : SpecState) (e : SpecEntry) : SpecState :=
match e with
| SpecEntry.info name info => { s with specInfo := s.specInfo.insert name info }
| SpecEntry.cache key fn => { s with cache := s.cache.insert key fn }
def switch : SpecState β SpecState
| β¨mβ, mββ© => β¨mβ.switch, mβ.switchβ©
end SpecState
def mkSpecExtension : IO (SimplePersistentEnvExtension SpecEntry SpecState) :=
registerSimplePersistentEnvExtension {
name := `specialize,
addEntryFn := SpecState.addEntry,
addImportedFn := fun es => (mkStateFromImportedEntries SpecState.addEntry {} es).switch
}
@[init mkSpecExtension]
constant specExtension : SimplePersistentEnvExtension SpecEntry SpecState := arbitrary _
@[export lean_add_specialization_info]
def addSpecializationInfo (env : Environment) (fn : Name) (info : SpecInfo) : Environment :=
specExtension.addEntry env (SpecEntry.info fn info)
@[export lean_get_specialization_info]
def getSpecializationInfo (env : Environment) (fn : Name) : Option SpecInfo :=
(specExtension.getState env).specInfo.find? fn
@[export lean_cache_specialization]
def cacheSpecialization (env : Environment) (e : Expr) (fn : Name) : Environment :=
specExtension.addEntry env (SpecEntry.cache e fn)
@[export lean_get_cached_specialization]
def getCachedSpecialization (env : Environment) (e : Expr) : Option Name :=
(specExtension.getState env).cache.find? e
end Compiler
end Lean
|
2fb3d0aacf826e4091620065b154976549cd429c
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/tactic10.lean
|
a9c45d834e625dee983ad2e59f15cf6c45103af8
|
[
"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
| 521
|
lean
|
(* import("tactic.lua") *)
definition f(a : Bool) : Bool := not a.
definition g(a b : Bool) : Bool := a \/ b.
theorem T1 (a b : Bool) : (g a b) β (f b) β a := _.
unfold_all
disj_hyp
exact
absurd
done.
(*
simple_tac = Repeat(unfold_tac()) .. Repeat(OrElse(conj_hyp_tac(), assumption_tac(), absurd_tac(), conj_hyp_tac(), disj_hyp_tac()))
*)
definition h(a b : Bool) : Bool := g a b.
theorem T2 (a b : Bool) : (h a b) β (f b) β a := _.
simple_tac
done.
print environment 1.
|
82650ca56c9fd355961681cd6b85a5d9a098c35e
|
bb31430994044506fa42fd667e2d556327e18dfe
|
/src/topology/algebra/module/finite_dimension.lean
|
fece5d836a471e5919a0e292cc5bc90242a20df0
|
[
"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
| 20,296
|
lean
|
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Anatole Dedecker
-/
import analysis.locally_convex.balanced_core_hull
import topology.algebra.module.determinant
/-!
# Finite dimensional topological vector spaces over complete fields
Let `π` be a complete nontrivially normed field, and `E` a topological vector space (TVS) over
`π` (i.e we have `[add_comm_group E] [module π E] [topological_space E] [topological_add_group E]`
and `[has_continuous_smul π E]`).
If `E` is finite dimensional and Hausdorff, then all linear maps from `E` to any other TVS are
continuous.
When `E` is a normed space, this gets us the equivalence of norms in finite dimension.
## Main results :
* `linear_map.continuous_iff_is_closed_ker` : a linear form is continuous if and only if its kernel
is closed.
* `linear_map.continuous_of_finite_dimensional` : a linear map on a finite-dimensional Hausdorff
space over a complete field is continuous.
## TODO
Generalize more of `analysis/normed_space/finite_dimension` to general TVSs.
## Implementation detail
The main result from which everything follows is the fact that, if `ΞΎ : ΞΉ β E` is a finite basis,
then `ΞΎ.equiv_fun : E ββ (ΞΉ β π)` is continuous. However, for technical reasons, it is easier to
prove this when `ΞΉ` and `E` live ine the same universe. So we start by doing that as a private
lemma, then we deduce `linear_map.continuous_of_finite_dimensional` from it, and then the general
result follows as `continuous_equiv_fun_basis`.
-/
universes u v w x
noncomputable theory
open set finite_dimensional topological_space filter
open_locale big_operators
section semiring
variables {ΞΉ π F : Type*} [finite ΞΉ] [semiring π] [topological_space π]
[add_comm_monoid F] [module π F] [topological_space F]
[has_continuous_add F] [has_continuous_smul π F]
/-- A linear map on `ΞΉ β π` (where `ΞΉ` is finite) is continuous -/
lemma linear_map.continuous_on_pi (f : (ΞΉ β π) ββ[π] F) : continuous f :=
begin
casesI nonempty_fintype ΞΉ,
classical,
-- for the proof, write `f` in the standard basis, and use that each coordinate is a continuous
-- function.
have : (f : (ΞΉ β π) β F) =
(Ξ»x, β i : ΞΉ, x i β’ (f (Ξ» j, if i = j then 1 else 0))),
by { ext x, exact f.pi_apply_eq_sum_univ x },
rw this,
refine continuous_finset_sum _ (Ξ»i hi, _),
exact (continuous_apply i).smul continuous_const
end
end semiring
section field
variables {π E F : Type*} [field π] [topological_space π] [add_comm_group E] [module π E]
[topological_space E] [add_comm_group F] [module π F] [topological_space F]
[topological_add_group F] [has_continuous_smul π F]
/-- The space of continuous linear maps between finite-dimensional spaces is finite-dimensional. -/
instance [finite_dimensional π E] [finite_dimensional π F] :
finite_dimensional π (E βL[π] F) :=
finite_dimensional.of_injective
(continuous_linear_map.coe_lm π : (E βL[π] F) ββ[π] (E ββ[π] F))
continuous_linear_map.coe_injective
end field
section normed_field
variables {π : Type u} [hnorm : nontrivially_normed_field π]
{E : Type v} [add_comm_group E] [module π E] [topological_space E]
[topological_add_group E] [has_continuous_smul π E]
{F : Type w} [add_comm_group F] [module π F] [topological_space F]
[topological_add_group F] [has_continuous_smul π F]
{F' : Type x} [add_comm_group F'] [module π F'] [topological_space F']
[topological_add_group F'] [has_continuous_smul π F']
include hnorm
/-- If `π` is a nontrivially normed field, any T2 topology on `π` which makes it a topological
vector space over itself (with the norm topology) is *equal* to the norm topology. -/
lemma unique_topology_of_t2 {t : topological_space π}
(hβ : @topological_add_group π t _)
(hβ : @has_continuous_smul π π _ hnorm.to_uniform_space.to_topological_space t)
(hβ : @t2_space π t) :
t = hnorm.to_uniform_space.to_topological_space :=
begin
-- Let `π£β` denote the topology on `π` induced by the norm, and `π£` be any T2 vector
-- topology on `π`. To show that `π£β = π£`, it suffices to show that they have the same
-- neighborhoods of 0.
refine topological_add_group.ext hβ infer_instance (le_antisymm _ _),
{ -- To show `π£ β€ π£β`, we have to show that closed balls are `π£`-neighborhoods of 0.
rw metric.nhds_basis_closed_ball.ge_iff,
-- Let `Ξ΅ > 0`. Since `π` is nontrivially normed, we have `0 < βΞΎββ < Ξ΅` for some `ΞΎβ : π`.
intros Ξ΅ hΞ΅,
rcases normed_field.exists_norm_lt π hΞ΅ with β¨ΞΎβ, hΞΎβ, hΞΎβΞ΅β©,
-- Since `ΞΎβ β 0` and `π£` is T2, we know that `{ΞΎβ}αΆ` is a `π£`-neighborhood of 0.
have : {ΞΎβ}αΆ β @nhds π t 0 :=
is_open.mem_nhds is_open_compl_singleton (ne.symm $ norm_ne_zero_iff.mp hΞΎβ.ne.symm),
-- Thus, its balanced core `π` is too. Let's show that the closed ball of radius `Ξ΅` contains
-- `π`, which will imply that the closed ball is indeed a `π£`-neighborhood of 0.
have : balanced_core π {ΞΎβ}αΆ β @nhds π t 0 := balanced_core_mem_nhds_zero this,
refine mem_of_superset this (Ξ» ΞΎ hΞΎ, _),
-- Let `ΞΎ β π`. We want to show `βΞΎβ < Ξ΅`. If `ΞΎ = 0`, this is trivial.
by_cases hΞΎ0 : ΞΎ = 0,
{ rw hΞΎ0,
exact metric.mem_closed_ball_self hΞ΅.le },
{ rw [mem_closed_ball_zero_iff],
-- Now suppose `ΞΎ β 0`. By contradiction, let's assume `Ξ΅ < βΞΎβ`, and show that
-- `ΞΎβ β π β {ΞΎβ}αΆ`, which is a contradiction.
by_contra' h,
suffices : (ΞΎβ * ΞΎβ»ΒΉ) β’ ΞΎ β balanced_core π {ΞΎβ}αΆ,
{ rw [smul_eq_mul π, mul_assoc, inv_mul_cancel hΞΎ0, mul_one] at this,
exact not_mem_compl_iff.mpr (mem_singleton ΞΎβ) ((balanced_core_subset _) this) },
-- For that, we use that `π` is balanced : since `βΞΎββ < Ξ΅ < βΞΎβ`, we have `βΞΎβ / ΞΎβ β€ 1`,
-- hence `ΞΎβ = (ΞΎβ / ΞΎ) β’ ΞΎ β π` because `ΞΎ β π`.
refine (balanced_core_balanced _).smul_mem _ hΞΎ,
rw [norm_mul, norm_inv, mul_inv_le_iff (norm_pos_iff.mpr hΞΎ0), mul_one],
exact (hΞΎβΞ΅.trans h).le } },
{ -- Finally, to show `π£β β€ π£`, we simply argue that `id = (Ξ» x, x β’ 1)` is continuous from
-- `(π, π£β)` to `(π, π£)` because `(β’) : (π, π£β) Γ (π, π£) β (π, π£)` is continuous.
calc (@nhds π hnorm.to_uniform_space.to_topological_space 0)
= map id (@nhds π hnorm.to_uniform_space.to_topological_space 0) : map_id.symm
... = map (Ξ» x, id x β’ 1) (@nhds π hnorm.to_uniform_space.to_topological_space 0) :
by conv_rhs {congr, funext, rw [smul_eq_mul, mul_one]}; refl
... β€ (@nhds π t ((0 : π) β’ 1)) :
@tendsto.smul_const _ _ _ hnorm.to_uniform_space.to_topological_space t _ _ _ _ _
tendsto_id (1 : π)
... = (@nhds π t 0) : by rw zero_smul }
end
/-- Any linear form on a topological vector space over a nontrivially normed field is continuous if
its kernel is closed. -/
lemma linear_map.continuous_of_is_closed_ker (l : E ββ[π] π) (hl : is_closed (l.ker : set E)) :
continuous l :=
begin
-- `l` is either constant or surjective. If it is constant, the result is trivial.
by_cases H : finrank π l.range = 0,
{ rw [finrank_eq_zero, linear_map.range_eq_bot] at H,
rw H,
exact continuous_zero },
{ -- In the case where `l` is surjective, we factor it as `Ο : (E β§Έ l.ker) ββ[π] π`. Note that
-- `E β§Έ l.ker` is T2 since `l.ker` is closed.
have : finrank π l.range = 1,
from le_antisymm (finrank_self π βΈ l.range.finrank_le) (zero_lt_iff.mpr H),
have hi : function.injective (l.ker.liftq l (le_refl _)),
{ rw [β linear_map.ker_eq_bot],
exact submodule.ker_liftq_eq_bot _ _ _ (le_refl _) },
have hs : function.surjective (l.ker.liftq l (le_refl _)),
{ rw [β linear_map.range_eq_top, submodule.range_liftq],
exact eq_top_of_finrank_eq ((finrank_self π).symm βΈ this) },
let Ο : (E β§Έ l.ker) ββ[π] π := linear_equiv.of_bijective (l.ker.liftq l (le_refl _)) β¨hi, hsβ©,
have hlΟ : (l : E β π) = Ο β l.ker.mkq,
by ext; refl,
-- Since the quotient map `E ββ[π] (E β§Έ l.ker)` is continuous, the continuity of `l` will follow
-- form the continuity of `Ο`.
suffices : continuous Ο.to_equiv,
{ rw hlΟ,
exact this.comp continuous_quot_mk },
-- The pullback by `Ο.symm` of the quotient topology is a T2 topology on `π`, because `Ο.symm`
-- is injective. Since `Ο.symm` is linear, it is also a vector space topology.
-- Hence, we know that it is equal to the topology induced by the norm.
have : induced Ο.to_equiv.symm infer_instance = hnorm.to_uniform_space.to_topological_space,
{ refine unique_topology_of_t2 (topological_add_group_induced Ο.symm.to_linear_map)
(has_continuous_smul_induced Ο.symm.to_linear_map) _,
rw t2_space_iff,
exact Ξ» x y hxy, @separated_by_continuous _ _ (induced _ _) _ _ _
continuous_induced_dom _ _ (Ο.to_equiv.symm.injective.ne hxy) },
-- Finally, the pullback by `Ο.symm` is exactly the pushforward by `Ο`, so we have to prove
-- that `Ο` is continuous when `π` is endowed with the pushforward by `Ο` of the quotient
-- topology, which is trivial by definition of the pushforward.
rw [this.symm, equiv.induced_symm],
exact continuous_coinduced_rng }
end
/-- Any linear form on a topological vector space over a nontrivially normed field is continuous if
and only if its kernel is closed. -/
lemma linear_map.continuous_iff_is_closed_ker (l : E ββ[π] π) :
continuous l β is_closed (l.ker : set E) :=
β¨Ξ» h, is_closed_singleton.preimage h, l.continuous_of_is_closed_kerβ©
/-- Over a nontrivially normed field, any linear form which is nonzero on a nonempty open set is
automatically continuous. -/
lemma linear_map.continuous_of_nonzero_on_open (l : E ββ[π] π) (s : set E) (hsβ : is_open s)
(hsβ : s.nonempty) (hsβ : β x β s, l x β 0) : continuous l :=
begin
refine l.continuous_of_is_closed_ker (l.is_closed_or_dense_ker.resolve_right $ Ξ» hl, _),
rcases hsβ with β¨x, hxβ©,
have : x β interior (l.ker : set E)αΆ,
{ rw mem_interior_iff_mem_nhds,
exact mem_of_superset (hsβ.mem_nhds hx) hsβ },
rwa hl.interior_compl at this
end
variables [complete_space π]
/-- This version imposes `ΞΉ` and `E` to live in the same universe, so you should instead use
`continuous_equiv_fun_basis` which gives the same result without universe restrictions. -/
private lemma continuous_equiv_fun_basis_aux [ht2 : t2_space E] {ΞΉ : Type v} [fintype ΞΉ]
(ΞΎ : basis ΞΉ π E) : continuous ΞΎ.equiv_fun :=
begin
letI : uniform_space E := topological_add_group.to_uniform_space E,
letI : uniform_add_group E := topological_add_comm_group_is_uniform,
letI : separated_space E := separated_iff_t2.mpr ht2,
unfreezingI { induction hn : fintype.card ΞΉ with n IH generalizing ΞΉ E },
{ rw fintype.card_eq_zero_iff at hn,
exact continuous_of_const (Ξ» x y, funext hn.elim) },
{ haveI : finite_dimensional π E := of_fintype_basis ΞΎ,
-- first step: thanks to the induction hypothesis, any n-dimensional subspace is equivalent
-- to a standard space of dimension n, hence it is complete and therefore closed.
have Hβ : βs : submodule π E, finrank π s = n β is_closed (s : set E),
{ assume s s_dim,
letI : uniform_add_group s := s.to_add_subgroup.uniform_add_group,
let b := basis.of_vector_space π s,
have U : uniform_embedding b.equiv_fun.symm.to_equiv,
{ have : fintype.card (basis.of_vector_space_index π s) = n,
by { rw β s_dim, exact (finrank_eq_card_basis b).symm },
have : continuous b.equiv_fun := IH b this,
exact b.equiv_fun.symm.uniform_embedding b.equiv_fun.symm.to_linear_map.continuous_on_pi
this },
have : is_complete (s : set E),
from complete_space_coe_iff_is_complete.1 ((complete_space_congr U).1 (by apply_instance)),
exact this.is_closed },
-- second step: any linear form is continuous, as its kernel is closed by the first step
have Hβ : βf : E ββ[π] π, continuous f,
{ assume f,
by_cases H : finrank π f.range = 0,
{ rw [finrank_eq_zero, linear_map.range_eq_bot] at H,
rw H,
exact continuous_zero },
{ have : finrank π f.ker = n,
{ have Z := f.finrank_range_add_finrank_ker,
rw [finrank_eq_card_basis ΞΎ, hn] at Z,
have : finrank π f.range = 1,
from le_antisymm (finrank_self π βΈ f.range.finrank_le) (zero_lt_iff.mpr H),
rw [this, add_comm, nat.add_one] at Z,
exact nat.succ.inj Z },
have : is_closed (f.ker : set E),
from Hβ _ this,
exact linear_map.continuous_of_is_closed_ker f this } },
rw continuous_pi_iff,
intros i,
change continuous (ΞΎ.coord i),
exact Hβ (ΞΎ.coord i) },
end
/-- Any linear map on a finite dimensional space over a complete field is continuous. -/
theorem linear_map.continuous_of_finite_dimensional [t2_space E] [finite_dimensional π E]
(f : E ββ[π] F') :
continuous f :=
begin
-- for the proof, go to a model vector space `b β π` thanks to `continuous_equiv_fun_basis`, and
-- argue that all linear maps there are continuous.
let b := basis.of_vector_space π E,
have A : continuous b.equiv_fun :=
continuous_equiv_fun_basis_aux b,
have B : continuous (f.comp (b.equiv_fun.symm : (basis.of_vector_space_index π E β π) ββ[π] E)) :=
linear_map.continuous_on_pi _,
have : continuous ((f.comp (b.equiv_fun.symm : (basis.of_vector_space_index π E β π) ββ[π] E))
β b.equiv_fun) := B.comp A,
convert this,
ext x,
dsimp,
rw [basis.equiv_fun_symm_apply, basis.sum_repr]
end
instance linear_map.continuous_linear_map_class_of_finite_dimensional
[t2_space E] [finite_dimensional π E] :
continuous_linear_map_class (E ββ[π] F') π E F' :=
{ map_continuous := Ξ» f, f.continuous_of_finite_dimensional,
..linear_map.semilinear_map_class }
/-- In finite dimensions over a non-discrete complete normed field, the canonical identification
(in terms of a basis) with `π^n` (endowed with the product topology) is continuous.
This is the key fact wich makes all linear maps from a T2 finite dimensional TVS over such a field
continuous (see `linear_map.continuous_of_finite_dimensional`), which in turn implies that all
norms are equivalent in finite dimensions. -/
theorem continuous_equiv_fun_basis [t2_space E] {ΞΉ : Type*} [fintype ΞΉ] (ΞΎ : basis ΞΉ π E) :
continuous ΞΎ.equiv_fun :=
begin
haveI : finite_dimensional π E := of_fintype_basis ΞΎ,
exact ΞΎ.equiv_fun.to_linear_map.continuous_of_finite_dimensional
end
namespace linear_map
variables [t2_space E] [finite_dimensional π E]
/-- The continuous linear map induced by a linear map on a finite dimensional space -/
def to_continuous_linear_map : (E ββ[π] F') ββ[π] E βL[π] F' :=
{ to_fun := Ξ» f, β¨f, f.continuous_of_finite_dimensionalβ©,
inv_fun := coe,
map_add' := Ξ» f g, rfl,
map_smul' := Ξ» c f, rfl,
left_inv := Ξ» f, rfl,
right_inv := Ξ» f, continuous_linear_map.coe_injective rfl }
@[simp] lemma coe_to_continuous_linear_map' (f : E ββ[π] F') :
βf.to_continuous_linear_map = f := rfl
@[simp] lemma coe_to_continuous_linear_map (f : E ββ[π] F') :
(f.to_continuous_linear_map : E ββ[π] F') = f := rfl
@[simp] lemma coe_to_continuous_linear_map_symm :
β(to_continuous_linear_map : (E ββ[π] F') ββ[π] E βL[π] F').symm = coe := rfl
@[simp] lemma det_to_continuous_linear_map (f : E ββ[π] E) :
f.to_continuous_linear_map.det = f.det :=
rfl
@[simp] lemma ker_to_continuous_linear_map (f : E ββ[π] F') :
ker f.to_continuous_linear_map = ker f :=
rfl
@[simp] lemma range_to_continuous_linear_map (f : E ββ[π] F') :
range f.to_continuous_linear_map = range f :=
rfl
/-- A surjective linear map `f` with finite dimensional codomain is an open map. -/
lemma is_open_map_of_finite_dimensional (f : F ββ[π] E) (hf : function.surjective f) :
is_open_map f :=
begin
rcases f.exists_right_inverse_of_surjective (linear_map.range_eq_top.2 hf) with β¨g, hgβ©,
refine is_open_map.of_sections (Ξ» x, β¨Ξ» y, g (y - f x) + x, _, _, Ξ» y, _β©),
{ exact ((g.continuous_of_finite_dimensional.comp $ continuous_id.sub continuous_const).add
continuous_const).continuous_at },
{ rw [sub_self, map_zero, zero_add] },
{ simp only [map_sub, map_add, β comp_apply f g, hg, id_apply, sub_add_cancel] }
end
instance can_lift_continuous_linear_map : can_lift (E ββ[π] F) (E βL[π] F) coe (Ξ» _, true) :=
β¨Ξ» f _, β¨f.to_continuous_linear_map, rflβ©β©
end linear_map
namespace linear_equiv
variables [t2_space E] [t2_space F] [finite_dimensional π E]
/-- The continuous linear equivalence induced by a linear equivalence on a finite dimensional
space. -/
def to_continuous_linear_equiv (e : E ββ[π] F) : E βL[π] F :=
{ continuous_to_fun := e.to_linear_map.continuous_of_finite_dimensional,
continuous_inv_fun := begin
haveI : finite_dimensional π F := e.finite_dimensional,
exact e.symm.to_linear_map.continuous_of_finite_dimensional
end,
..e }
@[simp] lemma coe_to_continuous_linear_equiv (e : E ββ[π] F) :
(e.to_continuous_linear_equiv : E ββ[π] F) = e := rfl
@[simp] lemma coe_to_continuous_linear_equiv' (e : E ββ[π] F) :
(e.to_continuous_linear_equiv : E β F) = e := rfl
@[simp] lemma coe_to_continuous_linear_equiv_symm (e : E ββ[π] F) :
(e.to_continuous_linear_equiv.symm : F ββ[π] E) = e.symm := rfl
@[simp] lemma coe_to_continuous_linear_equiv_symm' (e : E ββ[π] F) :
(e.to_continuous_linear_equiv.symm : F β E) = e.symm := rfl
@[simp] lemma to_linear_equiv_to_continuous_linear_equiv (e : E ββ[π] F) :
e.to_continuous_linear_equiv.to_linear_equiv = e :=
by { ext x, refl }
@[simp] lemma to_linear_equiv_to_continuous_linear_equiv_symm (e : E ββ[π] F) :
e.to_continuous_linear_equiv.symm.to_linear_equiv = e.symm :=
by { ext x, refl }
instance can_lift_continuous_linear_equiv :
can_lift (E ββ[π] F) (E βL[π] F) continuous_linear_equiv.to_linear_equiv (Ξ» _, true) :=
β¨Ξ» f _, β¨_, f.to_linear_equiv_to_continuous_linear_equivβ©β©
end linear_equiv
namespace continuous_linear_map
variables [t2_space E] [finite_dimensional π E]
/-- Builds a continuous linear equivalence from a continuous linear map on a finite-dimensional
vector space whose determinant is nonzero. -/
def to_continuous_linear_equiv_of_det_ne_zero
(f : E βL[π] E) (hf : f.det β 0) : E βL[π] E :=
((f : E ββ[π] E).equiv_of_det_ne_zero hf).to_continuous_linear_equiv
@[simp] lemma coe_to_continuous_linear_equiv_of_det_ne_zero (f : E βL[π] E) (hf : f.det β 0) :
(f.to_continuous_linear_equiv_of_det_ne_zero hf : E βL[π] E) = f :=
by { ext x, refl }
@[simp] lemma to_continuous_linear_equiv_of_det_ne_zero_apply
(f : E βL[π] E) (hf : f.det β 0) (x : E) :
f.to_continuous_linear_equiv_of_det_ne_zero hf x = f x :=
rfl
lemma _root_.matrix.to_lin_fin_two_prod_to_continuous_linear_map (a b c d : π) :
(matrix.to_lin (basis.fin_two_prod π) (basis.fin_two_prod π)
!![a, b; c, d]).to_continuous_linear_map =
(a β’ continuous_linear_map.fst π π π + b β’ continuous_linear_map.snd π π π).prod
(c β’ continuous_linear_map.fst π π π + d β’ continuous_linear_map.snd π π π) :=
continuous_linear_map.ext $ matrix.to_lin_fin_two_prod_apply _ _ _ _
end continuous_linear_map
end normed_field
|
4b33a0f457e2395ad129d6593bbec96ff03a1b7d
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/analysis/analytic/linear.lean
|
e0c124303f8446b65494e61d2e8c5706d10ddd31
|
[
"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,277
|
lean
|
/-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import analysis.analytic.basic
/-!
# Linear functions are analytic
In this file we prove that a `continuous_linear_map` defines an analytic function with
the formal power series `f x = f a + f (x - a)`.
-/
variables {π : Type*} [nontrivially_normed_field π]
{E : Type*} [normed_add_comm_group E] [normed_space π E]
{F : Type*} [normed_add_comm_group F] [normed_space π F]
{G : Type*} [normed_add_comm_group G] [normed_space π G]
open_locale topology classical big_operators nnreal ennreal
open set filter asymptotics
noncomputable theory
namespace continuous_linear_map
/-- Formal power series of a continuous linear map `f : E βL[π] F` at `x : E`:
`f y = f x + f (y - x)`. -/
@[simp] def fpower_series (f : E βL[π] F) (x : E) : formal_multilinear_series π E F
| 0 := continuous_multilinear_map.curry0 π _ (f x)
| 1 := (continuous_multilinear_curry_fin1 π E F).symm f
| _ := 0
@[simp] lemma fpower_series_apply_add_two (f : E βL[π] F) (x : E) (n : β) :
f.fpower_series x (n + 2) = 0 := rfl
@[simp] lemma fpower_series_radius (f : E βL[π] F) (x : E) : (f.fpower_series x).radius = β :=
(f.fpower_series x).radius_eq_top_of_forall_image_add_eq_zero 2 $ Ξ» n, rfl
protected theorem has_fpower_series_on_ball (f : E βL[π] F) (x : E) :
has_fpower_series_on_ball f (f.fpower_series x) x β :=
{ r_le := by simp,
r_pos := ennreal.coe_lt_top,
has_sum := Ξ» y _, (has_sum_nat_add_iff' 2).1 $
by simp [finset.sum_range_succ, β sub_sub, has_sum_zero] }
protected theorem has_fpower_series_at (f : E βL[π] F) (x : E) :
has_fpower_series_at f (f.fpower_series x) x :=
β¨β, f.has_fpower_series_on_ball xβ©
protected theorem analytic_at (f : E βL[π] F) (x : E) : analytic_at π f x :=
(f.has_fpower_series_at x).analytic_at
/-- Reinterpret a bilinear map `f : E βL[π] F βL[π] G` as a multilinear map
`(E Γ F) [Γ2]βL[π] G`. This multilinear map is the second term in the formal
multilinear series expansion of `uncurry f`. It is given by
`f.uncurry_bilinear ![(x, y), (x', y')] = f x y'`. -/
def uncurry_bilinear (f : E βL[π] F βL[π] G) : (E Γ F) [Γ2]βL[π] G :=
@continuous_linear_map.uncurry_left π 1 (Ξ» _, E Γ F) G _ _ _ _ _ $
(β(continuous_multilinear_curry_fin1 π (E Γ F) G).symm : (E Γ F βL[π] G) βL[π] _).comp $
f.bilinear_comp (fst _ _ _) (snd _ _ _)
@[simp] lemma uncurry_bilinear_apply (f : E βL[π] F βL[π] G) (m : fin 2 β E Γ F) :
f.uncurry_bilinear m = f (m 0).1 (m 1).2 :=
rfl
/-- Formal multilinear series expansion of a bilinear function `f : E βL[π] F βL[π] G`. -/
@[simp] def fpower_series_bilinear (f : E βL[π] F βL[π] G) (x : E Γ F) :
formal_multilinear_series π (E Γ F) G
| 0 := continuous_multilinear_map.curry0 π _ (f x.1 x.2)
| 1 := (continuous_multilinear_curry_fin1 π (E Γ F) G).symm (f.derivβ x)
| 2 := f.uncurry_bilinear
| _ := 0
@[simp] lemma fpower_series_bilinear_radius (f : E βL[π] F βL[π] G) (x : E Γ F) :
(f.fpower_series_bilinear x).radius = β :=
(f.fpower_series_bilinear x).radius_eq_top_of_forall_image_add_eq_zero 3 $ Ξ» n, rfl
protected theorem has_fpower_series_on_ball_bilinear (f : E βL[π] F βL[π] G) (x : E Γ F) :
has_fpower_series_on_ball (Ξ» x : E Γ F, f x.1 x.2) (f.fpower_series_bilinear x) x β :=
{ r_le := by simp,
r_pos := ennreal.coe_lt_top,
has_sum := Ξ» y _, (has_sum_nat_add_iff' 3).1 $
begin
simp only [finset.sum_range_succ, finset.sum_range_one, prod.fst_add, prod.snd_add,
f.map_add_add],
dsimp, simp only [add_comm, sub_self, has_sum_zero]
end }
protected theorem has_fpower_series_at_bilinear (f : E βL[π] F βL[π] G) (x : E Γ F) :
has_fpower_series_at (Ξ» x : E Γ F, f x.1 x.2) (f.fpower_series_bilinear x) x :=
β¨β, f.has_fpower_series_on_ball_bilinear xβ©
protected theorem analytic_at_bilinear (f : E βL[π] F βL[π] G) (x : E Γ F) :
analytic_at π (Ξ» x : E Γ F, f x.1 x.2) x :=
(f.has_fpower_series_at_bilinear x).analytic_at
end continuous_linear_map
|
63a8e72a43babeb0b59e1d5723414aba86adce3d
|
618003631150032a5676f229d13a079ac875ff77
|
/src/computability/tm_to_partrec.lean
|
5657d261a0bd8eb7215584187d130f2c4266eb72
|
[
"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
| 64,312
|
lean
|
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import computability.halting
import computability.turing_machine
import data.num.lemmas
/-!
# Modelling partial recursive functions using Turing machines
This file defines a simplified basis for partial recursive functions, and a `turing.TM2` model
Turing machine for evaluating these functions. This amounts to a constructive proof that every
`partrec` function can be evaluated by a Turing machine.
## Main definitions
* `to_partrec.code`: a simplified basis for partial recursive functions, valued in
`list β β. list β`.
* `to_partrec.code.eval`: semantics for a `to_partrec.code` program
* `partrec_to_TM2.tr`: A TM2 turing machine which can evaluate `code` programs
-/
open function (update)
open relation
namespace turing
/-!
## A simplified basis for partrec
This section constructs the type `code`, which is a data type of programs with `list β` input and
output, with enough expressivity to write any partial recursive function. The primitives are:
* `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`.
* `succ` returns the successor of the head of the input, defaulting to zero if there is no head:
* `succ [] = [1]`
* `succ (n :: v) = [n + 1]`
* `tail` returns the tail of the input
* `tail [] = []`
* `tail (n :: v) = v`
* `cons f fs` calls `f` and `fs` on the input and conses the results:
* `cons f fs v = (f v).head :: fs v`
* `comp f g` calls `f` on the output of `g`:
* `comp f g v = f (g v)`
* `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or
a successor (similar to `nat.cases_on`).
* `case f g [] = f []`
* `case f g (0 :: v) = f v`
* `case f g (n+1 :: v) = g (n :: v)`
* `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f`
again or finish:
* `fix f v = []` if `f v = []`
* `fix f v = w` if `f v = 0 :: w`
* `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded)
This basis is convenient because it is closer to the Turing machine model - the key operations are
splitting and merging of lists of unknown length, while the messy `n`-ary composition operation
from the traditional basis for partial recursive functions is absent - but it retains a
compositional semantics. The first step in transitioning to Turing machines is to make a sequential
evaluator for this basis, which we take up in the next section.
-/
namespace to_partrec
/-- The type of codes for primitive recursive functions. Unlike `nat.partrec.code`, this uses a set
of operations on `list β`. See `code.eval` for a description of the behavior of the primitives. -/
@[derive inhabited]
inductive code
| zero'
| succ
| tail
| cons : code β code β code
| comp : code β code β code
| case : code β code β code
| fix : code β code
/-- The semantics of the `code` primitives, as partial functions `list β β. list β`. By convention
we functions that return a single result return a singleton `[n]`, or in some cases `n :: v` where
`v` will be ignored by a subsequent function.
* `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`.
* `succ` returns the successor of the head of the input, defaulting to zero if there is no head:
* `succ [] = [1]`
* `succ (n :: v) = [n + 1]`
* `tail` returns the tail of the input
* `tail [] = []`
* `tail (n :: v) = v`
* `cons f fs` calls `f` and `fs` on the input and conses the results:
* `cons f fs v = (f v).head :: fs v`
* `comp f g` calls `f` on the output of `g`:
* `comp f g v = f (g v)`
* `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or
a successor (similar to `nat.cases_on`).
* `case f g [] = f []`
* `case f g (0 :: v) = f v`
* `case f g (n+1 :: v) = g (n :: v)`
* `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f`
again or finish:
* `fix f v = []` if `f v = []`
* `fix f v = w` if `f v = 0 :: w`
* `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded)
-/
@[simp] def code.eval : code β list β β. list β
| code.zero' := Ξ» v, pure (0 :: v)
| code.succ := Ξ» v, pure [v.head.succ]
| code.tail := Ξ» v, pure v.tail
| (code.cons f fs) := Ξ» v, do n β code.eval f v, ns β code.eval fs v, pure (n.head :: ns)
| (code.comp f g) := Ξ» v, g.eval v >>= f.eval
| (code.case f g) := Ξ» v, v.head.elim (f.eval v.tail) (Ξ» y _, g.eval (y :: v.tail))
| (code.fix f) := pfun.fix $ Ξ» v, (f.eval v).map $ Ξ» v,
if v.head = 0 then sum.inl v.tail else sum.inr v.tail
namespace code
/-- `nil` is the constant nil function: `nil v = []`. -/
def nil : code := tail.comp succ
@[simp] theorem nil_eval (v) : nil.eval v = pure [] := by simp [nil]
/-- `id` is the identity function: `id v = v`. -/
def id : code := tail.comp zero'
@[simp] theorem id_eval (v) : id.eval v = pure v := by simp [id]
/-- `head` gets the head of the input list: `head [] = [0]`, `head (n :: v) = [n]`. -/
def head : code := cons id nil
@[simp] theorem head_eval (v) : head.eval v = pure [v.head] := by simp [head]
/-- `zero` is the constant zero function: `zero v = [0]`. -/
def zero : code := cons zero' nil
@[simp] theorem zero_eval (v) : zero.eval v = pure [0] := by simp [zero]
/-- `pred` returns the predecessor of the head of the input:
`pred [] = [0]`, `pred (0 :: v) = [0]`, `pred (n+1 :: v) = [n]`. -/
def pred : code := case zero head
@[simp] theorem pred_eval (v) : pred.eval v = pure [v.head.pred] :=
by simp [pred]; cases v.head; simp
/-- `rfind f` performs the function of the `rfind` primitive of partial recursive functions.
`rfind f v` returns the smallest `n` such that `(f (n :: v)).head = 0`.
It is implemented as:
rfind f v = pred (fix (Ξ» (n::v), f (n::v) :: n+1 :: v) (0 :: v))
The idea is that the initial state is `0 :: v`, and the `fix` keeps `n :: v` as its internal state;
it calls `f (n :: v)` as the exit test and `n+1 :: v` as the next state. At the end we get
`n+1 :: v` where `n` is the desired output, and `pred (n+1 :: v) = [n]` returns the result.
-/
def rfind (f : code) : code := comp pred $ comp (fix $ cons f $ cons succ tail) zero'
/-- `prec f g` implements the `prec` (primitive recursion) operation of partial recursive
functions. `prec f g` evaluates as:
* `prec f g [] = [f []]`
* `prec f g (0 :: v) = [f v]`
* `prec f g (n+1 :: v) = [g (n :: prec f g (n :: v) :: v)]`
It is implemented as:
G (a :: b :: IH :: v) = (b :: a+1 :: b-1 :: g (a :: IH :: v) :: v)
F (0 :: f_v :: v) = (f_v :: v)
F (n+1 :: f_v :: v) = (fix G (0 :: n :: f_v :: v)).tail.tail
prec f g (a :: v) = [(F (a :: f v :: v)).head]
Because `fix` always evaluates its body at least once, we must special case the `0` case to avoid
calling `g` more times than necessary (which could be bad if `g` diverges). If the input is
`0 :: v`, then `F (0 :: f v :: v) = (f v :: v)` so we return `[f v]`. If the input is `n+1 :: v`,
we evaluate the function from the bottom up, with initial state `0 :: n :: f v :: v`. The first
number counts up, providing arguments for the applications to `g`, while the second number counts
down, providing the exit condition (this is the initial `b` in the return value of `G`, which is
stripped by `fix`). After the `fix` is complete, the final state is `n :: 0 :: res :: v` where
`res` is the desired result, and the rest reduces this to `[res]`. -/
def prec (f g : code) : code :=
let G := cons tail $ cons succ $ cons (comp pred tail) $
cons (comp g $ cons id $ comp tail tail) $ comp tail $ comp tail tail in
let F := case id $ comp (comp (comp tail tail) (fix G)) zero' in
cons (comp F (cons head $ cons (comp f tail) tail)) nil
local attribute [-simp] roption.bind_eq_bind roption.map_eq_map roption.pure_eq_some
theorem exists_code.comp {m n} {f : vector β n β. β} {g : fin n β vector β m β. β}
(hf : β c : code, β v : vector β n, c.eval v.1 = pure <$> f v)
(hg : β i, β c : code, β v : vector β m, c.eval v.1 = pure <$> g i v) :
β c : code, β v : vector β m, c.eval v.1 = pure <$> (vector.m_of_fn (Ξ» i, g i v) >>= f) :=
begin
suffices : β c : code, β v : vector β m,
c.eval v.1 = subtype.val <$> vector.m_of_fn (Ξ» i, g i v),
{ obtain β¨cf, hfβ© := hf, obtain β¨cg, hgβ© := this,
exact β¨cf.comp cg, Ξ» v, by simp [hg, hf, map_bind, seq_bind_eq, (β)]; reflβ© },
clear hf f, induction n with n IH,
{ exact β¨nil, Ξ» v, by simp [vector.m_of_fn]; reflβ© },
{ obtain β¨cg, hgββ© := hg 0, obtain β¨cl, hlβ© := IH (Ξ» i, hg i.succ),
exact β¨cons cg cl, Ξ» v, by simp [vector.m_of_fn, hgβ, map_bind,
seq_bind_eq, bind_assoc, (β), hl]; reflβ© },
end
theorem exists_code {n} {f : vector β n β. β} (hf : nat.partrec' f) :
β c : code, β v : vector β n, c.eval v.1 = pure <$> f v :=
begin
induction hf with n f hf,
induction hf,
case prim zero { exact β¨zero', Ξ» β¨[], _β©, rflβ© },
case prim succ { exact β¨succ, Ξ» β¨[v], _β©, rflβ© },
case prim nth : n i {
refine fin.succ_rec (Ξ» n, _) (Ξ» n i IH, _) i,
{ exact β¨head, Ξ» β¨list.cons a as, _β©, by simp; reflβ© },
{ obtain β¨c, hβ© := IH,
exact β¨c.comp tail, Ξ» v, by simpa [β vector.nth_tail] using h v.tailβ© } },
case prim comp : m n f g hf hg IHf IHg {
simpa [roption.bind_eq_bind] using exists_code.comp IHf IHg },
case prim prec : n f g hf hg IHf IHg {
obtain β¨cf, hfβ© := IHf, obtain β¨cg, hgβ© := IHg,
simp only [roption.map_eq_map, roption.map_some, pfun.coe_val] at hf hg,
refine β¨prec cf cg, Ξ» v, _β©, rw β v.cons_head_tail,
specialize hf v.tail, replace hg := Ξ» a b, hg (a :: b :: v.tail),
simp only [vector.cons_val, vector.tail_val] at hf hg,
simp only [roption.map_eq_map, roption.map_some, vector.cons_val,
vector.cons_tail, vector.cons_head, pfun.coe_val, vector.tail_val],
simp only [β roption.pure_eq_some] at hf hg β’,
induction v.head with n IH; simp [prec, hf, bind_assoc, β roption.map_eq_map,
β bind_pure_comp_eq_map, show β x, pure x = [x], from Ξ» _, rfl],
suffices : β a b, a + b = n β
(n.succ :: 0 :: g (n :: nat.elim (f v.tail) (Ξ» y IH, g (y::IH::v.tail)) n :: v.tail)
:: v.val.tail : list β) β
pfun.fix (Ξ» v : list β, do
x β cg.eval (v.head :: v.tail.tail),
pure $ if v.tail.head = 0
then sum.inl (v.head.succ :: v.tail.head.pred :: x.head :: v.tail.tail.tail : list β)
else sum.inr (v.head.succ :: v.tail.head.pred :: x.head :: v.tail.tail.tail))
(a :: b :: nat.elim (f v.tail) (Ξ» y IH, g (y::IH::v.tail)) a :: v.val.tail),
{ rw (_ : pfun.fix _ _ = pure _), swap, exact roption.eq_some_iff.2 (this 0 n (zero_add n)),
simp only [list.head, pure_bind, list.tail_cons] },
intros a b e, induction b with b IH generalizing a e,
{ refine pfun.mem_fix_iff.2 (or.inl $ roption.eq_some_iff.1 _),
simp only [hg, β e, pure_bind, list.tail_cons], refl },
{ refine pfun.mem_fix_iff.2 (or.inr β¨_, _, IH (a+1) (by rwa add_right_comm)β©),
simp only [hg, eval, pure_bind, nat.elim_succ, list.tail],
exact roption.mem_some_iff.2 rfl } },
case comp : m n f g hf hg IHf IHg { exact exists_code.comp IHf IHg },
case rfind : n f hf IHf {
obtain β¨cf, hfβ© := IHf, refine β¨rfind cf, Ξ» v, _β©,
replace hf := Ξ» a, hf (a :: v),
simp only [roption.map_eq_map, roption.map_some, vector.cons_val, pfun.coe_val,
show β x, pure x = [x], from Ξ» _, rfl] at hf β’,
refine roption.ext (Ξ» x, _),
simp only [rfind, roption.bind_eq_bind, roption.pure_eq_some, roption.map_eq_map,
roption.bind_some, exists_prop, eval, list.head, pred_eval, roption.map_some,
bool.ff_eq_to_bool_iff, roption.mem_bind_iff, list.length,
roption.mem_map_iff, nat.mem_rfind, list.tail, bool.tt_eq_to_bool_iff,
roption.mem_some_iff, roption.map_bind],
split,
{ rintro β¨v', h1, rflβ©,
suffices : β (vβ : list β), v' β pfun.fix
(Ξ» v, (cf.eval v).bind $ Ξ» y, roption.some $ if y.head = 0 then
sum.inl (v.head.succ :: v.tail) else sum.inr (v.head.succ :: v.tail)) vβ β
β n, vβ = n :: v.val β (β m < n, Β¬f (m :: v) = 0) β
(β (a : β), (f (a :: v) = 0 β§ β {m : β}, m < a β Β¬f (m :: v) = 0) β§ [a] = [v'.head.pred]),
{ exact this _ h1 0 rfl (by rintro _ β¨β©) },
clear h1, intros vβ h1,
refine pfun.fix_induction h1 (Ξ» vβ h2 IH, _), clear h1,
rintro n rfl hm,
have := pfun.mem_fix_iff.1 h2,
simp only [hf, roption.bind_some] at this,
split_ifs at this,
{ simp only [list.head, exists_false, or_false, roption.mem_some_iff,
list.tail_cons, false_and] at this,
subst this, exact β¨_, β¨h, hmβ©, rflβ© },
{ simp only [list.head, exists_eq_left, roption.mem_some_iff,
list.tail_cons, false_or] at this,
refine IH _ this (by simp [hf, h]) _ rfl (Ξ» m h', _),
obtain h|rfl := nat.lt_succ_iff_lt_or_eq.1 h', exacts [hm _ h, h] } },
{ rintro β¨n, β¨hn, hmβ©, rflβ©, refine β¨n.succ :: v.1, _, rflβ©,
have : (n.succ :: v.1 : list β) β pfun.fix
(Ξ» v, (cf.eval v).bind $ Ξ» y, roption.some $ if y.head = 0 then
sum.inl (v.head.succ :: v.tail) else sum.inr (v.head.succ :: v.tail)) (n :: v.val) :=
pfun.mem_fix_iff.2 (or.inl (by simp [hf, hn])),
generalize_hyp : (n.succ :: v.1 : list β) = w at this β’, clear hn,
induction n with n IH, {exact this},
refine IH (Ξ» m h', hm (nat.lt_succ_of_lt h')) (pfun.mem_fix_iff.2 (or.inr β¨_, _, thisβ©)),
simp only [hf, hm n.lt_succ_self, roption.bind_some, list.head, eq_self_iff_true,
if_false, roption.mem_some_iff, and_self, list.tail_cons] } }
end
end code
/-!
## From compositional semantics to sequential semantics
Our initial sequential model is designed to be as similar as possible to the compositional
semantics in terms of its primitives, but it is a sequential semantics, meaning that rather than
defining an `eval c : list β β. list β` function for each program, defined by recursion on
programs, we have a type `cfg` with a step function `step : cfg β option cfg` that provides a
deterministic evaluation order. In order to do this, we introduce the notion of a *continuation*,
which can be viewed as a `code` with a hole in it where evaluation is currently taking place.
Continuations can be assigned a `list β β. list β` semantics as well, with the interpretation
being that given a `list β` result returned from the code in the hole, the remainder of the
program will evaluate to a `list β` final value.
The continuations are:
* `halt`: the empty continuation: the hole is the whole program, whatever is returned is the
final result. In our notation this is just `_`.
* `consβ fs v k`: evaluating the first part of a `cons`, that is `k (_ :: fs v)`, where `k` is the
outer continuation.
* `consβ ns k`: evaluating the second part of a `cons`: `k (ns.head :: _)`. (Technically we don't
need to hold on to all of `ns` here since we are already committed to taking the head, but this
is more regular.)
* `comp f k`: evaluating the first part of a composition: `k (f _)`.
* `fix f k`: waiting for the result of `f` in a `fix f` expression:
`k (if _.head = 0 then _.tail else fix f (_.tail))`
The type `cfg` of evaluation states is:
* `ret k v`: we have received a result, and are now evaluating the continuation `k` with result
`v`; that is, `k v` where `k` is ready to evaluate.
* `halt v`: we are done and the result is `v`.
The main theorem of this section is that for each code `c`, the state `step_normal c halt v` steps
to `v'` in finitely many steps if and only if `code.eval c v = some v'`.
-/
/-- The type of continuations, built up during evaluation of a `code` expression. -/
@[derive inhabited]
inductive cont
| halt
| consβ : code β list β β cont β cont
| consβ : list β β cont β cont
| comp : code β cont β cont
| fix : code β cont β cont
/-- The semantics of a continuation. -/
def cont.eval : cont β list β β. list β
| cont.halt := pure
| (cont.consβ fs as k) := Ξ» v, do ns β code.eval fs as, cont.eval k (v.head :: ns)
| (cont.consβ ns k) := Ξ» v, cont.eval k (ns.head :: v)
| (cont.comp f k) := Ξ» v, code.eval f v >>= cont.eval k
| (cont.fix f k) := Ξ» v, if v.head = 0 then k.eval v.tail else f.fix.eval v.tail >>= k.eval
/-- The semantics of a continuation. -/
@[derive inhabited]
inductive cfg
| halt : list β β cfg
| ret : cont β list β β cfg
/-- Evaluating `c : code` in a continuation `k : cont` and input `v : list β`. This goes by
recursion on `c`, building an augmented continuation and a value to pass to it.
* `zero' v = 0 :: v` evaluates immediately, so we return it to the parent continuation
* `succ v = [v.head.succ]` evaluates immediately, so we return it to the parent continuation
* `tail v = v.tail` evaluates immediately, so we return it to the parent continuation
* `cons f fs v = (f v).head :: fs v` requires two sub-evaluations, so we evaluate
`f v` in the continuation `k (_.head :: fs v)` (called `cont.consβ fs v k`)
* `comp f g v = f (g v)` requires two sub-evaluations, so we evaluate
`g v` in the continuation `k (f _)` (called `cont.comp f k`)
* `case f g v = v.head.cases_on (f v.tail) (Ξ» n, g (n :: v.tail))` has the information needed to
evaluate the case statement, so we do that and transition to either `f v` or `g (n :: v.tail)`.
* `fix f v = let v' := f v in if v'.head = 0 then k v'.tail else fix f v'.tail`
needs to first evaluate `f v`, so we do that and leave the rest for the continuation (called
`cont.fix f k`)
-/
def step_normal : code β cont β list β β cfg
| code.zero' k v := cfg.ret k (0 :: v)
| code.succ k v := cfg.ret k [v.head.succ]
| code.tail k v := cfg.ret k v.tail
| (code.cons f fs) k v := step_normal f (cont.consβ fs v k) v
| (code.comp f g) k v := step_normal g (cont.comp f k) v
| (code.case f g) k v :=
v.head.elim (step_normal f k v.tail) (Ξ» y _, step_normal g k (y :: v.tail))
| (code.fix f) k v := step_normal f (cont.fix f k) v
/-- Evaluating a continuation `k : cont` on input `v : list β`. This is the second part of
evaluation, when we receive results from continuations built by `step_normal`.
* `cont.halt v = v`, so we are done and transition to the `cfg.halt v` state
* `cont.consβ fs as k v = k (v.head :: fs as)`, so we evaluate `fs as` now with the continuation
`k (v.head :: _)` (called `consβ v k`).
* `cont.consβ ns k v = k (ns.head :: v)`, where we now have everything we need to evaluate
`ns.head :: v`, so we return it to `k`.
* `cont.comp f k v = k (f v)`, so we call `f v` with `k` as the continuation.
* `cont.fix f k v = k (if v.head = 0 then k v.tail else fix f v.tail)`, where `v` is a value,
so we evaluate the if statement and either call `k` with `v.tail`, or call `fix f v` with `k` as
the continuation (which immediately calls `f` with `cont.fix f k` as the continuation).
-/
def step_ret : cont β list β β cfg
| cont.halt v := cfg.halt v
| (cont.consβ fs as k) v := step_normal fs (cont.consβ v k) as
| (cont.consβ ns k) v := step_ret k (ns.head :: v)
| (cont.comp f k) v := step_normal f k v
| (cont.fix f k) v := if v.head = 0 then step_ret k v.tail else
step_normal f (cont.fix f k) v.tail
/-- If we are not done (in `cfg.halt` state), then we must be still stuck on a continuation, so
this main loop calls `step_ret` with the new continuation. The overall `step` function transitions
from one `cfg` to another, only halting at the `cfg.halt` state. -/
def step : cfg β option cfg
| (cfg.halt _) := none
| (cfg.ret k v) := some (step_ret k v)
/-- In order to extract a compositional semantics from the sequential execution behavior of
configurations, we observe that continuations have a monoid structure, with `cont.halt` as the unit
and `cont.then` as the multiplication. `cont.then kβ kβ` runs `kβ` until it halts, and then takes
the result of `kβ` and passes it to `kβ`.
We will not prove it is associative (although it is), but we are instead interested in the
associativity law `kβ (eval c kβ) = eval c (kβ.then kβ)`. This holds at both the sequential and
compositional levels, and allows us to express running a machine without the ambient continuation
and relate it to the original machine's evaluation steps. In the literature this is usually
where one uses Turing machines embedded inside other Turing machines, but this approach allows us
to avoid changing the ambient type `cfg` in the middle of the recursion.
-/
def cont.then : cont β cont β cont
| cont.halt k' := k'
| (cont.consβ fs as k) k' := cont.consβ fs as (k.then k')
| (cont.consβ ns k) k' := cont.consβ ns (k.then k')
| (cont.comp f k) k' := cont.comp f (k.then k')
| (cont.fix f k) k' := cont.fix f (k.then k')
theorem cont.then_eval {k k' : cont} {v} : (k.then k').eval v = k.eval v >>= k'.eval :=
begin
induction k generalizing v; simp only [cont.eval, cont.then, bind_assoc, pure_bind, *],
{ simp only [β k_ih] },
{ split_ifs; [refl, simp only [β k_ih, bind_assoc]] }
end
/-- The `then k` function is a "configuration homomorphism". Its operation on states is to append
`k` to the continuation of a `cfg.ret` state, and to run `k` on `v` if we are in the `cfg.halt v`
state. -/
def cfg.then : cfg β cont β cfg
| (cfg.halt v) k' := step_ret k' v
| (cfg.ret k v) k' := cfg.ret (k.then k') v
/-- The `step_normal` function respects the `then k'` homomorphism. Note that this is an exact
equality, not a simulation; the original and embedded machines move in lock-step until the
embedded machine reaches the halt state. -/
theorem step_normal_then (c) (k k' : cont) (v) :
step_normal c (k.then k') v = (step_normal c k v).then k' :=
begin
induction c generalizing k v;
simp only [cont.then, step_normal, cfg.then, *] {constructor_eq := ff},
{ rw [β c_ih_a, cont.then] },
{ rw [β c_ih_a_1, cont.then] },
{ cases v.head; simp only [nat.elim] },
{ rw [β c_ih, cont.then] },
end
/-- The `step_ret` function respects the `then k'` homomorphism. Note that this is an exact
equality, not a simulation; the original and embedded machines move in lock-step until the
embedded machine reaches the halt state. -/
theorem step_ret_then {k k' : cont} {v} :
step_ret (k.then k') v = (step_ret k v).then k' :=
begin
induction k generalizing v;
simp only [cont.then, step_ret, cfg.then, *],
{ rw β step_normal_then, refl },
{ rw β step_normal_then },
{ split_ifs, {rw β k_ih}, {rw β step_normal_then, refl} },
end
/-- This is a temporary definition, because we will prove in `code_is_ok` that it always holds.
It asserts that `c` is semantically correct; that is, for any `k` and `v`,
`eval (step_normal c k v) = eval (cfg.ret k (code.eval c v))`, as an equality of partial values
(so one diverges iff the other does).
In particular, we can let `k = cont.halt`, and then this asserts that `step_normal c cont.halt v`
evaluates to `cfg.halt (code.eval c v)`. -/
def code.ok (c : code) :=
β k v, eval step (step_normal c k v) = code.eval c v >>= Ξ» v, eval step (cfg.ret k v)
theorem code.ok.zero {c} (h : code.ok c) {v} :
eval step (step_normal c cont.halt v) = cfg.halt <$> code.eval c v :=
begin
rw [h, β bind_pure_comp_eq_map], congr, funext v,
exact roption.eq_some_iff.2 (mem_eval.2 β¨refl_trans_gen.single rfl, rflβ©),
end
theorem step_normal.is_ret (c k v) : β k' v', step_normal c k v = cfg.ret k' v' :=
begin
induction c generalizing k v,
iterate 3 { exact β¨_, _, rflβ© },
case cons : f fs IHf IHfs { apply IHf },
case comp : f g IHf IHg { apply IHg },
case case : f g IHf IHg {
rw step_normal, cases v.head; simp only [nat.elim]; [apply IHf, apply IHg] },
case fix : f IHf { apply IHf },
end
theorem cont_eval_fix {f k v} (fok : code.ok f) :
eval step (step_normal f (cont.fix f k) v) = f.fix.eval v >>= Ξ» v, eval step (cfg.ret k v) :=
begin
refine roption.ext (Ξ» x, _),
simp only [roption.bind_eq_bind, roption.mem_bind_iff],
split,
{ suffices :
β c, x β eval step c β
β v c', c = cfg.then c' (cont.fix f k) β reaches step (step_normal f cont.halt v) c' β
β vβ β f.eval v,
β vβ β (if list.head vβ = 0 then pure vβ.tail else f.fix.eval vβ.tail),
x β eval step (cfg.ret k vβ),
{ intro h,
obtain β¨vβ, hvβ, vβ, hvβ, hββ© :=
this _ h _ _ (step_normal_then _ cont.halt _ _) refl_trans_gen.refl,
refine β¨vβ, pfun.mem_fix_iff.2 _, hββ©,
simp only [roption.eq_some_iff.2 hvβ, roption.map_some],
split_ifs at hvβ β’,
{ rw roption.mem_some_iff.1 hvβ, exact or.inl (roption.mem_some _) },
{ exact or.inr β¨_, roption.mem_some _, hvββ© } },
refine Ξ» c he, eval_induction he (Ξ» y h IH, _),
rintro v (β¨v'β© | β¨k',v'β©) rfl hr; rw cfg.then at h IH,
{ have := mem_eval.2 β¨hr, rflβ©,
rw [fok, roption.bind_eq_bind, roption.mem_bind_iff] at this,
obtain β¨v'', hβ, hββ© := this,
rw reaches_eval at hβ, swap, exact refl_trans_gen.single rfl,
cases roption.mem_unique hβ (mem_eval.2 β¨refl_trans_gen.refl, rflβ©),
refine β¨v', hβ, _β©, rw [step_ret] at h,
revert h, by_cases he : v'.head = 0; simp only [exists_prop, if_pos, if_false, he]; intro h,
{ refine β¨_, roption.mem_some _, _β©,
rw reaches_eval, exact h, exact refl_trans_gen.single rfl },
{ obtain β¨kβ, vβ, eββ© := step_normal.is_ret f cont.halt v'.tail,
have eβ := step_normal_then f cont.halt (cont.fix f k) v'.tail,
rw [eβ, cont.then, cfg.then] at eβ,
obtain β¨vβ, hvβ, vβ, hvβ, hββ© :=
IH (step_ret (kβ.then (cont.fix f k)) vβ) _ _ v'.tail _ step_ret_then _,
{ refine β¨_, pfun.mem_fix_iff.2 _, hββ©,
simp only [roption.eq_some_iff.2 hvβ, roption.map_some, roption.mem_some_iff],
split_ifs at hvβ β’; [exact or.inl (roption.mem_some_iff.1 hvβ),
exact or.inr β¨_, rfl, hvββ©] },
{ rwa [β @reaches_eval _ _ (cfg.ret (kβ.then (cont.fix f k)) vβ), β eβ],
exact refl_trans_gen.single rfl },
{ rw [step_ret, if_neg he, eβ], refl },
{ apply refl_trans_gen.single, rw eβ, exact rfl } } },
{ rw reaches_eval at h, swap, exact refl_trans_gen.single rfl,
exact IH _ h rfl _ _ step_ret_then (refl_trans_gen.tail hr rfl) } },
{ rintro β¨v', he, hrβ©,
rw reaches_eval at hr, swap, exact refl_trans_gen.single rfl,
refine pfun.fix_induction he (Ξ» v (he : v' β f.fix.eval v) IH, _),
rw [fok, roption.bind_eq_bind, roption.mem_bind_iff],
obtain he | β¨v'', heβ', heβ'β© := pfun.mem_fix_iff.1 he,
{ obtain β¨v', heβ, heββ© := (roption.mem_map_iff _).1 he, split_ifs at heβ; cases heβ,
refine β¨_, heβ, _β©,
rw reaches_eval, swap, exact refl_trans_gen.single rfl,
rwa [step_ret, if_pos h] },
{ obtain β¨vβ, heβ, heββ© := (roption.mem_map_iff _).1 heβ', split_ifs at heβ; cases heβ,
clear heβ heβ', change _ β f.fix.eval _ at heβ',
refine β¨_, heβ, _β©,
rw reaches_eval, swap, exact refl_trans_gen.single rfl,
rwa [step_ret, if_neg h],
exact IH vβ.tail heβ' ((roption.mem_map_iff _).2 β¨_, heβ, if_neg hβ©) } }
end
theorem code_is_ok (c) : code.ok c :=
begin
induction c; intros k v; rw step_normal,
iterate 3 { simp only [code.eval, pure_bind] },
case cons : f fs IHf IHfs {
rw [code.eval, IHf],
simp only [bind_assoc, cont.eval, pure_bind], congr, funext v,
rw [reaches_eval], swap, exact refl_trans_gen.single rfl,
rw [step_ret, IHfs], congr, funext v',
refine eq.trans _ (eq.symm _);
try {exact reaches_eval (refl_trans_gen.single rfl)} },
case comp : f g IHf IHg {
rw [code.eval, IHg],
simp only [bind_assoc, cont.eval, pure_bind], congr, funext v,
rw [reaches_eval], swap, exact refl_trans_gen.single rfl,
rw [step_ret, IHf] },
case case : f g IHf IHg {
simp only [code.eval], cases v.head; simp only [nat.elim, code.eval];
[apply IHf, apply IHg] },
case fix : f IHf { rw cont_eval_fix IHf },
end
theorem step_normal_eval (c v) : eval step (step_normal c cont.halt v) = cfg.halt <$> c.eval v :=
(code_is_ok c).zero
theorem step_ret_eval {k v} : eval step (step_ret k v) = cfg.halt <$> k.eval v :=
begin
induction k generalizing v,
case halt : {
simp only [mem_eval, cont.eval, map_pure],
exact roption.eq_some_iff.2 (mem_eval.2 β¨refl_trans_gen.refl, rflβ©) },
case consβ : fs as k IH {
rw [cont.eval, step_ret, code_is_ok],
simp only [β bind_pure_comp_eq_map, bind_assoc], congr, funext v',
rw [reaches_eval], swap, exact refl_trans_gen.single rfl,
rw [step_ret, IH, bind_pure_comp_eq_map] },
case consβ : ns k IH { rw [cont.eval, step_ret], exact IH },
case comp : f k IH {
rw [cont.eval, step_ret, code_is_ok],
simp only [β bind_pure_comp_eq_map, bind_assoc], congr, funext v',
rw [reaches_eval], swap, exact refl_trans_gen.single rfl,
rw [IH, bind_pure_comp_eq_map] },
case fix : f k IH {
rw [cont.eval, step_ret], simp only [bind_pure_comp_eq_map],
split_ifs, { exact IH },
simp only [β bind_pure_comp_eq_map, bind_assoc, cont_eval_fix (code_is_ok _)],
congr, funext, rw [bind_pure_comp_eq_map, β IH],
exact reaches_eval (refl_trans_gen.single rfl) },
end
end to_partrec
/-!
## Simulating sequentialized partial recursive functions in TM2
At this point we have a sequential model of partial recursive functions: the `cfg` type and
`step : cfg β option cfg` function from the previous section. The key feature of this model is that
it does a finite amount of computation (in fact, an amount which is statically bounded by the size
of the program) between each step, and no individual step can diverge (unlike the compositional
semantics, where every sub-part of the computation is potentially divergent). So we can utilize the
same techniques as in the other TM simulations in `computability.turing_machine` to prove that
each step corresponds to a finite number of steps in a lower level model. (We don't prove it here,
but in anticipation of the complexity class P, the simulation is actually polynomial-time as well.)
The target model is `turing.TM2`, which has a fixed finite set of stacks, a bit of local storage,
with programs selected from a potentially infinite (but finitely accessible) set of program
positions, or labels `Ξ`, each of which executes a finite sequence of basic stack commands.
For this program we will need four stacks, each on an alphabet `Ξ'` like so:
inductive Ξ' | Cons | cons | bit0 | bit1
We represent a number as a bit sequence, lists of numbers by putting `cons` after each element, and
lists of lists of natural numbers by putting `Cons` after each list. For example:
0 ~> []
1 ~> [bit1]
6 ~> [bit0, bit1, bit1]
[1, 2] ~> [bit1, cons, bit0, bit1, cons]
[[], [1, 2]] ~> [Cons, bit1, cons, bit0, bit1, cons, Cons]
The four stacks are `main`, `rev`, `aux`, `stack`. In normal mode, `main` contains the input to the
current program (a `list β`) and `stack` contains data (a `list (list β)`) associated to the
current continuation, and in `ret` mode `main` contains the value that is being passed to the
continuation and `stack` contains the data for the continuation. The `rev` and `aux` stacks are
usually empty; `rev` is used to store reversed data when e.g. moving a value from one stack to
another, while `aux` is used as a temporary for a `main`/`stack` swap that happens during `consβ`
evaluation.
The only local store we need is `option Ξ'`, which stores the result of the last pop
operation. (Most of our working data are natural numbers, which are too large to fit in the local
store.)
The continuations from the previous section are data-carrying, containing all the values that have
been computed and are awaiting other arguments. In order to have only a finite number of
continuations appear in the program so that they can be used in machine states, we separate the
data part (anything with type `list β`) from the `cont` type, producing a `cont'` type that lacks
this information. The data is kept on the `stack` stack.
Because we want to have subroutines for e.g. moving an entire stack to another place, we use an
infinite inductive type `Ξ'` so that we can execute a program and then return to do something else
without having to define too many different kinds of intermediate states. (We must nevertheless
prove that only finitely many labels are accessible.) The labels are:
* `move p kβ kβ q`: move elements from stack `kβ` to `kβ` while `p` holds of the value being moved.
The last element, that fails `p`, is placed in neither stack but left in the local store.
At the end of the operation, `kβ` will have the elements of `kβ` in reverse order. Then do `q`.
* `clear p k q`: delete elements from stack `k` until `p` is true. Like `move`, the last element is
left in the local storage. Then do `q`.
* `copy q`: Move all elements from `rev` to both `main` and `stack` (in reverse order),
then do `q`. That is, it takes `(a, b, c, d)` to `(b.reverse ++ a, [], c, b.reverse ++ d)`.
* `push k f q`: push `f s`, where `s` is the local store, to stack `k`, then do `q`. This is a
duplicate of the `push` instruction that is part of the TM2 model, but by having a subroutine
just for this purpose we can build up programs to execute inside a `goto` statement, where we
have the flexibility to be general recursive.
* `read (f : option Ξ' β Ξ')`: go to state `f s` where `s` is the local store. Again this is only
here for convenience.
* `succ q`: perform a successor operation. Assuming `[n]` is encoded on `main` before,
`[n+1]` will be on main after. This implements successor for binary natural numbers.
* `pred qβ qβ`: perform a predecessor operation or `case` statement. If `[]` is encoded on
`main` before, then we transition to `qβ` with `[]` on main; if `(0 :: v)` is on `main` before
then `v` will be on `main` after and we transition to `qβ`; and if `(n+1 :: v)` is on `main`
before then `n :: v` will be on `main` after and we transition to `qβ`.
* `ret k`: call continuation `k`. Each continuation has its own interpretation of the data in
`stack` and sets up the data for the next continuation.
* `ret (consβ fs k)`: `v :: k_data` on `stack` and `ns` on `main`, and the next step expects
`v` on `main` and `ns :: k_data` on `stack`. So we have to do a little dance here with six
reverse-moves using the `aux` stack to perform a three-point swap, each of which involves two
reversals.
* `ret (consβ k)`: `ns :: k_data` is on `stack` and `v` is on `main`, and we have to put
`ns.head :: v` on `main` and `k_data` on `stack`. This is done using the `head` subroutine.
* `ret (fix f k)`: This stores no data, so we just check if `main` starts with `0` and
if so, remove it and call `k`, otherwise `clear` the first value and call `f`.
* `ret halt`: the stack is empty, and `main` has the output. Do nothing and halt.
In addition to these basic states, we define some additional subroutines that are used in the
above:
* `push'`, `peek'`, `pop'` are special versions of the builtins that use the local store to supply
inputs and outputs.
* `unrev`: special case `move ff rev main` to move everything from `rev` back to `main`. Used as a
cleanup operation in several functions.
* `move_excl p kβ kβ q`: same as `move` but pushes the last value read back onto the source stack.
* `moveβ p kβ kβ q`: double `move`, so that the result comes out in the right order at the target
stack. Implemented as `move_excl p k rev; move ff rev kβ`. Assumes that neither `kβ` nor `kβ` is
`rev` and `rev` is initially empty.
* `head k q`: get the first natural number from stack `k` and reverse-move it to `rev`, then clear
the rest of the list at `k` and then `unrev` to reverse-move the head value to `main`. This is
used with `k = main` to implement regular `head`, i.e. if `v` is on `main` before then `[v.head]`
will be on `main` after; and also with `k = stack` for the `cons` operation, which has `v` on
`main` and `ns :: k_data` on `stack`, and results in `k_data` on `stack` and `ns.head :: v` on
`main`.
* `tr_normal` is the main entry point, defining states that perform a given `code` computation.
It mostly just dispatches to functions written above.
The main theorem of this section is `tr_eval`, which asserts that for each that for each code `c`,
the state `init c v` steps to `halt v'` in finitely many steps if and only if
`code.eval c v = some v'`.
-/
namespace partrec_to_TM2
section
open to_partrec
/-- The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `β` values
as lists of binary digits, `cons` is used to separate `list β` values, and `Cons` is used to
separate `list (list β)` values. See the section documentation. -/
@[derive [decidable_eq, inhabited]]
inductive Ξ' | Cons | cons | bit0 | bit1
/-- The four stacks used by the program. `main` is used to store the input value in `tr_normal`
mode and the output value in `Ξ'.ret` mode, while `stack` is used to keep all the data for the
continuations. `rev` is used to store reversed lists when transferring values between stacks, and
`aux` is only used once in `consβ`. See the section documentation. -/
@[derive [decidable_eq, inhabited]]
inductive K' | main | rev | aux | stack
open K'
/-- Continuations as in `to_partrec.cont` but with the data removed. This is done because we want
the set of all continuations in the program to be finite (so that it can ultimately be encoded into
the finite state machine of a Turing machine), but a continuation can handle a potentially infinite
number of data values during execution. -/
@[derive inhabited]
inductive cont'
| halt
| consβ : code β cont' β cont'
| consβ : cont' β cont'
| comp : code β cont' β cont'
| fix : code β cont' β cont'
/-- The set of program positions. We make extensive use of inductive types here to let us describe
"subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where
`q` is another label. In order to prevent this from resulting in an infinite number of distinct
accessible states, we are careful to be non-recursive (although loops are okay). See the section
documentation for a description of all the programs. -/
inductive Ξ'
| move (p : Ξ' β bool) (kβ kβ : K') (q : Ξ')
| clear (p : Ξ' β bool) (k : K') (q : Ξ')
| copy (q : Ξ')
| push (k : K') (s : option Ξ' β option Ξ') (q : Ξ')
| read (f : option Ξ' β Ξ')
| succ (q : Ξ')
| pred (qβ qβ : Ξ')
| ret (k : cont')
instance : inhabited Ξ' := β¨Ξ'.ret cont'.haltβ©
/-- The type of TM2 statements used by this machine. -/
@[derive inhabited]
def stmt' := TM2.stmt (Ξ» _:K', Ξ') Ξ' (option Ξ')
/-- The type of TM2 configurations used by this machine. -/
@[derive inhabited]
def cfg' := TM2.cfg (Ξ» _:K', Ξ') Ξ' (option Ξ')
open TM2.stmt
/-- A predicate that detects the end of a natural number, either `Ξ'.cons` or `Ξ'.Cons` (or
implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`. -/
def nat_end : Ξ' β bool
| Ξ'.Cons := tt
| Ξ'.cons := tt
| _ := ff
/-- Pop a value from the stack and place the result in local store. -/
@[simp] def pop' (k : K') : stmt' β stmt' := pop k (Ξ» x v, v)
/-- Peek a value from the stack and place the result in local store. -/
@[simp] def peek' (k : K') : stmt' β stmt' := peek k (Ξ» x v, v)
/-- Push the value in the local store to the given stack. -/
@[simp] def push' (k : K') : stmt' β stmt' := push k (Ξ» x, x.iget)
/-- Move everything from the `rev` stack to the `main` stack (reversed). -/
def unrev := Ξ'.move (Ξ» _, ff) rev main
/-- Move elements from `kβ` to `kβ` while `p` holds, with the last element being left on `kβ`. -/
def move_excl (p kβ kβ q) :=
Ξ'.move p kβ kβ $ Ξ'.push kβ id q
/-- Move elements from `kβ` to `kβ` without reversion, by performing a double move via the `rev`
stack. -/
def moveβ (p kβ kβ q) := move_excl p kβ rev $ Ξ'.move (Ξ» _, ff) rev kβ q
/-- Assuming `tr_list v` is on the front of stack `k`, remove it, and push `v.head` onto `main`.
See the section documentation. -/
def head (k : K') (q : Ξ') : Ξ' :=
Ξ'.move nat_end k rev $
Ξ'.push rev (Ξ» _, some Ξ'.cons) $
Ξ'.read $ Ξ» s,
(if s = some Ξ'.Cons then id else Ξ'.clear (Ξ» x, x = Ξ'.Cons) k) $
unrev q
/-- The program that evaluates code `c` with continuation `k`. This expects an initial state where
`tr_list v` is on `main`, `tr_cont_stack k` is on `stack`, and `aux` and `rev` are empty.
See the section documentation for details. -/
@[simp] def tr_normal : code β cont' β Ξ'
| code.zero' k := Ξ'.push main (Ξ» _, some Ξ'.cons) $ Ξ'.ret k
| code.succ k := head main $ Ξ'.succ $ Ξ'.ret k
| code.tail k := Ξ'.clear nat_end main $ Ξ'.ret k
| (code.cons f fs) k :=
Ξ'.push stack (Ξ» _, some Ξ'.Cons) $
Ξ'.move (Ξ» _, ff) main rev $ Ξ'.copy $
tr_normal f (cont'.consβ fs k)
| (code.comp f g) k := tr_normal g (cont'.comp f k)
| (code.case f g) k := Ξ'.pred (tr_normal f k) (tr_normal g k)
| (code.fix f) k := tr_normal f (cont'.fix f k)
/-- The main program. See the section documentation for details. -/
@[simp] def tr : Ξ' β stmt'
| (Ξ'.move p kβ kβ q) :=
pop' kβ $ branch (Ξ» s, s.elim tt p)
( goto $ Ξ» _, q )
( push' kβ $ goto $ Ξ» _, Ξ'.move p kβ kβ q )
| (Ξ'.push k f q) :=
branch (Ξ» s, (f s).is_some)
( push k (Ξ» s, (f s).iget) $ goto $ Ξ» _, q )
( goto $ Ξ» _, q )
| (Ξ'.read q) := goto q
| (Ξ'.clear p k q) :=
pop' k $ branch (Ξ» s, s.elim tt p)
( goto $ Ξ» _, q )
( goto $ Ξ» _, Ξ'.clear p k q )
| (Ξ'.copy q) :=
pop' rev $ branch option.is_some
( push' main $ push' stack $ goto $ Ξ» _, Ξ'.copy q )
( goto $ Ξ» _, q )
| (Ξ'.succ q) :=
pop' main $ branch (Ξ» s, s = some Ξ'.bit1)
( push rev (Ξ» _, Ξ'.bit0) $
goto $ Ξ» _, Ξ'.succ q ) $
branch (Ξ» s, s = some Ξ'.cons)
( push main (Ξ» _, Ξ'.cons) $
push main (Ξ» _, Ξ'.bit1) $
goto $ Ξ» _, unrev q )
( push main (Ξ» _, Ξ'.bit1) $
goto $ Ξ» _, unrev q )
| (Ξ'.pred qβ qβ) :=
pop' main $ branch (Ξ» s, s = some Ξ'.bit0)
( push rev (Ξ» _, Ξ'.bit1) $
goto $ Ξ» _, Ξ'.pred qβ qβ ) $
branch (Ξ» s, nat_end s.iget)
( goto $ Ξ» _, qβ )
( peek' main $ branch (Ξ» s, nat_end s.iget)
( goto $ Ξ» _, unrev qβ )
( push rev (Ξ» _, Ξ'.bit0) $
goto $ Ξ» _, unrev qβ ) )
| (Ξ'.ret (cont'.consβ fs k)) := goto $ Ξ» _,
moveβ (Ξ» _, ff) main aux $
moveβ (Ξ» s, s = Ξ'.Cons) stack main $
moveβ (Ξ» _, ff) aux stack $
tr_normal fs (cont'.consβ k)
| (Ξ'.ret (cont'.consβ k)) := goto $ Ξ» _, head stack $ Ξ'.ret k
| (Ξ'.ret (cont'.comp f k)) := goto $ Ξ» _, tr_normal f k
| (Ξ'.ret (cont'.fix f k)) :=
pop' main $ goto $ Ξ» s,
cond (nat_end s.iget) (Ξ'.ret k) $
Ξ'.clear nat_end main $ tr_normal f (cont'.fix f k)
| (Ξ'.ret cont'.halt) := load (Ξ» _, none) $ halt
/-- Translating a `cont` continuation to a `cont'` continuation simply entails dropping all the
data. This data is instead encoded in `tr_cont_stack` in the configuration. -/
def tr_cont : cont β cont'
| cont.halt := cont'.halt
| (cont.consβ c _ k) := cont'.consβ c (tr_cont k)
| (cont.consβ _ k) := cont'.consβ (tr_cont k)
| (cont.comp c k) := cont'.comp c (tr_cont k)
| (cont.fix c k) := cont'.fix c (tr_cont k)
/-- We use `pos_num` to define the translation of binary natural numbers. A natural number is
represented as a little-endian list of `bit0` and `bit1` elements:
1 = [bit1]
2 = [bit0, bit1]
3 = [bit1, bit1]
4 = [bit0, bit0, bit1]
In particular, this representation guarantees no trailing `bit0`'s at the end of the list. -/
def tr_pos_num : pos_num β list Ξ'
| pos_num.one := [Ξ'.bit1]
| (pos_num.bit0 n) := Ξ'.bit0 :: tr_pos_num n
| (pos_num.bit1 n) := Ξ'.bit1 :: tr_pos_num n
/-- We use `num` to define the translation of binary natural numbers. Positive numbers are
translated using `tr_pos_num`, and `tr_num 0 = []`. So there are never any trailing `bit0`'s in
a translated `num`.
0 = []
1 = [bit1]
2 = [bit0, bit1]
3 = [bit1, bit1]
4 = [bit0, bit0, bit1]
-/
def tr_num : num β list Ξ'
| num.zero := []
| (num.pos n) := tr_pos_num n
/-- Because we use binary encoding, we define `tr_nat` in terms of `tr_num`, using `num`, which are
binary natural numbers. (We could also use `nat.binary_rec_on`, but `num` and `pos_num` make for
easy inductions.) -/
def tr_nat (n : β) : list Ξ' := tr_num n
@[simp] theorem tr_nat_zero : tr_nat 0 = [] := rfl
/-- Lists are translated with a `cons` after each encoded number.
For example:
[] = []
[0] = [cons]
[1] = [bit1, cons]
[6, 0] = [bit0, bit1, bit1, cons, cons]
-/
@[simp] def tr_list : list β β list Ξ'
| [] := []
| (n :: ns) := tr_nat n ++ Ξ'.cons :: tr_list ns
/-- Lists of lists are translated with a `Cons` after each encoded list.
For example:
[] = []
[[]] = [Cons]
[[], []] = [Cons, Cons]
[[0]] = [cons, Cons]
[[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, Cons, cons, Cons]
-/
@[simp] def tr_llist : list (list β) β list Ξ'
| [] := []
| (l :: ls) := tr_list l ++ Ξ'.Cons :: tr_llist ls
/-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack
using `tr_llist`. -/
@[simp] def cont_stack : cont β list (list β)
| cont.halt := []
| (cont.consβ _ ns k) := ns :: cont_stack k
| (cont.consβ ns k) := ns :: cont_stack k
| (cont.comp _ k) := cont_stack k
| (cont.fix _ k) := cont_stack k
/-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack
using `tr_llist`. -/
def tr_cont_stack (k : cont) := tr_llist (cont_stack k)
/-- This is the nondependent eliminator for `K'`, but we use it specifically here in order to
represent the stack data as four lists rather than as a function `K' β list Ξ'`, because this makes
rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated
after an `update` to one of the components. -/
@[simp] def K'.elim (a b c d : list Ξ') : K' β list Ξ'
| K'.main := a
| K'.rev := b
| K'.aux := c
| K'.stack := d
@[simp] theorem K'.elim_update_main {a b c d a'} :
update (K'.elim a b c d) main a' = K'.elim a' b c d := by funext x; cases x; refl
@[simp] theorem K'.elim_update_rev {a b c d b'} :
update (K'.elim a b c d) rev b' = K'.elim a b' c d := by funext x; cases x; refl
@[simp] theorem K'.elim_update_aux {a b c d c'} :
update (K'.elim a b c d) aux c' = K'.elim a b c' d := by funext x; cases x; refl
@[simp] theorem K'.elim_update_stack {a b c d d'} :
update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x; refl
/-- The halting state corresponding to a `list β` output value. -/
def halt (v : list β) : cfg' := β¨none, none, K'.elim (tr_list v) [] [] []β©
/-- The `cfg` states map to `cfg'` states almost one to one, except that in normal operation the
local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly
clear it in the halt state so that there is exactly one configuration corresponding to output `v`.
-/
def tr_cfg : cfg β cfg' β Prop
| (cfg.ret k v) c' := β s, c' =
β¨some (Ξ'.ret (tr_cont k)), s, K'.elim (tr_list v) [] [] (tr_cont_stack k)β©
| (cfg.halt v) c' := c' = halt v
/-- This could be a general list definition, but it is also somewhat specialized to this
application. `split_at_pred p L` will search `L` for the first element satisfying `p`.
If it is found, say `L = lβ ++ a :: lβ` where `a` satisfies `p` but `lβ` does not, then it returns
`(lβ, some a, lβ)`. Otherwise, if there is no such element, it returns `(L, none, [])`. -/
def split_at_pred {Ξ±} (p : Ξ± β bool) : list Ξ± β list Ξ± Γ option Ξ± Γ list Ξ±
| [] := ([], none, [])
| (a :: as) := cond (p a) ([], some a, as) $
let β¨lβ, o, lββ© := split_at_pred as in β¨a :: lβ, o, lββ©
theorem split_at_pred_eq {Ξ±} (p : Ξ± β bool) : β L lβ o lβ,
(β x β lβ, p x = ff) β
option.elim o (L = lβ β§ lβ = []) (Ξ» a, p a = tt β§ L = lβ ++ a :: lβ) β
split_at_pred p L = (lβ, o, lβ)
| [] _ none _ _ β¨rfl, rflβ© := rfl
| [] lβ (some o) lβ hβ β¨hβ, hββ© := by simp at hβ; contradiction
| (a :: L) lβ o lβ hβ hβ := begin
rw [split_at_pred],
have IH := split_at_pred_eq L,
cases o,
{ cases lβ with a' lβ; rcases hβ with β¨β¨β©, rflβ©,
rw [hβ a (or.inl rfl), cond, IH L none [] _ β¨rfl, rflβ©], refl,
exact Ξ» x h, hβ x (or.inr h) },
{ cases lβ with a' lβ; rcases hβ with β¨hβ, β¨β©β©, {rw [hβ, cond]},
rw [hβ a (or.inl rfl), cond, IH lβ (some o) lβ _ β¨hβ, _β©]; try {refl},
exact Ξ» x h, hβ x (or.inr h) },
end
theorem split_at_pred_ff {Ξ±} (L : list Ξ±) : split_at_pred (Ξ» _, ff) L = (L, none, []) :=
split_at_pred_eq _ _ _ _ _ (Ξ» _ _, rfl) β¨rfl, rflβ©
theorem move_ok {p kβ kβ q s Lβ o Lβ} {S : K' β list Ξ'}
(hβ : kβ β kβ) (e : split_at_pred p (S kβ) = (Lβ, o, Lβ)) :
reachesβ (TM2.step tr)
β¨some (Ξ'.move p kβ kβ q), s, Sβ©
β¨some q, o, update (update S kβ Lβ) kβ (Lβ.reverse_core (S kβ))β© :=
begin
induction Lβ with a Lβ IH generalizing S s,
{ rw [(_ : [].reverse_core _ = _), function.update_eq_self],
swap, { rw function.update_noteq hβ.symm, refl },
refine trans_gen.head' rfl _,
simp, cases S kβ with a Sk, {cases e, refl},
simp [split_at_pred] at e β’,
cases p a; simp at e β’,
{ revert e, rcases split_at_pred p Sk with β¨_, _, _β©, rintro β¨β© },
{ simp only [e] } },
{ refine trans_gen.head rfl _, simp,
cases eβ : S kβ with a' Sk; rw [eβ, split_at_pred] at e, {cases e},
cases eβ : p a'; simp only [eβ, cond] at e, swap, {cases e},
rcases eβ : split_at_pred p Sk with β¨_, _, _β©, rw [eβ, split_at_pred] at e, cases e,
simp [eβ],
convert @IH (update (update S kβ Sk) kβ (a :: S kβ)) _ _ using 2;
simp [function.update_noteq, hβ, hβ.symm, eβ, list.reverse_core],
simp [function.update_comm hβ.symm] }
end
theorem unrev_ok {q s} {S : K' β list Ξ'} :
reachesβ (TM2.step tr) β¨some (unrev q), s, Sβ©
β¨some q, none, update (update S rev []) main (list.reverse_core (S rev) (S main))β© :=
move_ok dec_trivial $ split_at_pred_ff _
theorem moveβ_ok {p kβ kβ q s Lβ o Lβ} {S : K' β list Ξ'}
(hβ : kβ β rev β§ kβ β rev β§ kβ β kβ) (hβ : S rev = [])
(e : split_at_pred p (S kβ) = (Lβ, o, Lβ)) :
reachesβ (TM2.step tr)
β¨some (moveβ p kβ kβ q), s, Sβ©
β¨some q, none, update (update S kβ (o.elim id list.cons Lβ)) kβ (Lβ ++ S kβ)β© :=
begin
refine (move_ok hβ.1 e).trans (trans_gen.head rfl _),
cases o; simp only [option.elim, tr, id.def],
{ convert move_ok hβ.2.1.symm (split_at_pred_ff _) using 2,
simp only [function.update_comm hβ.1, function.update_idem],
rw show update S rev [] = S, by rw [β hβ, function.update_eq_self],
simp only [function.update_noteq hβ.2.2.symm, function.update_noteq hβ.2.1,
function.update_noteq hβ.1.symm, list.reverse_core_eq, hβ,
function.update_same, list.append_nil, list.reverse_reverse] },
{ convert move_ok hβ.2.1.symm (split_at_pred_ff _) using 2,
simp only [hβ, function.update_comm hβ.1,
list.reverse_core_eq, function.update_same, list.append_nil, function.update_idem],
rw show update S rev [] = S, by rw [β hβ, function.update_eq_self],
simp only [function.update_noteq hβ.1.symm,
function.update_noteq hβ.2.2.symm, function.update_noteq hβ.2.1,
function.update_same, list.reverse_reverse] },
end
theorem clear_ok {p k q s Lβ o Lβ} {S : K' β list Ξ'}
(e : split_at_pred p (S k) = (Lβ, o, Lβ)) :
reachesβ (TM2.step tr) β¨some (Ξ'.clear p k q), s, Sβ© β¨some q, o, update S k Lββ© :=
begin
induction Lβ with a Lβ IH generalizing S s,
{ refine trans_gen.head' rfl _,
simp, cases S k with a Sk, {cases e, refl},
simp [split_at_pred] at e β’,
cases p a; simp at e β’,
{ revert e, rcases split_at_pred p Sk with β¨_, _, _β©, rintro β¨β© },
{ simp only [e] } },
{ refine trans_gen.head rfl _, simp,
cases eβ : S k with a' Sk; rw [eβ, split_at_pred] at e, {cases e},
cases eβ : p a'; simp only [eβ, cond] at e, swap, {cases e},
rcases eβ : split_at_pred p Sk with β¨_, _, _β©, rw [eβ, split_at_pred] at e, cases e,
simp [eβ],
convert @IH (update S k Sk) _ _ using 2; simp [eβ] }
end
theorem copy_ok (q s a b c d) :
reachesβ (TM2.step tr)
β¨some (Ξ'.copy q), s, K'.elim a b c dβ©
β¨some q, none, K'.elim (list.reverse_core b a) [] c (list.reverse_core b d)β© :=
begin
induction b with x b IH generalizing a d s,
{ refine trans_gen.single _, simp, refl },
refine trans_gen.head rfl _, simp, exact IH _ _ _,
end
theorem tr_pos_num_nat_end : β n (x β tr_pos_num n), nat_end x = ff
| pos_num.one _ (or.inl rfl) := rfl
| (pos_num.bit0 n) _ (or.inl rfl) := rfl
| (pos_num.bit0 n) _ (or.inr h) := tr_pos_num_nat_end n _ h
| (pos_num.bit1 n) _ (or.inl rfl) := rfl
| (pos_num.bit1 n) _ (or.inr h) := tr_pos_num_nat_end n _ h
theorem tr_num_nat_end : β n (x β tr_num n), nat_end x = ff
| (num.pos n) x h := tr_pos_num_nat_end n x h
theorem tr_nat_nat_end (n) : β x β tr_nat n, nat_end x = ff := tr_num_nat_end _
theorem tr_list_ne_Cons : β l (x β tr_list l), x β Ξ'.Cons
| (a :: l) x h := begin
simp [tr_list] at h,
obtain h | rfl | h := h,
{ rintro rfl, cases tr_nat_nat_end _ _ h },
{ rintro β¨β© },
{ exact tr_list_ne_Cons l _ h }
end
theorem head_main_ok {q s L} {c d : list Ξ'} :
reachesβ (TM2.step tr)
β¨some (head main q), s, K'.elim (tr_list L) [] c dβ©
β¨some q, none, K'.elim (tr_list [L.head]) [] c dβ© :=
begin
let o : option Ξ' := list.cases_on L none (Ξ» _ _, some Ξ'.cons),
refine (move_ok dec_trivial
(split_at_pred_eq _ _ (tr_nat L.head) o (tr_list L.tail) (tr_nat_nat_end _) _)).trans
(trans_gen.head rfl (trans_gen.head rfl _)),
{ cases L; exact β¨rfl, rflβ© },
simp [show o β some Ξ'.Cons, by cases L; rintro β¨β©],
refine (clear_ok (split_at_pred_eq _ _ _ none [] _ β¨rfl, rflβ©)).trans _,
{ exact Ξ» x h, (to_bool_ff (tr_list_ne_Cons _ _ h)) },
convert unrev_ok, simp [list.reverse_core_eq],
end
theorem head_stack_ok {q s Lβ Lβ Lβ} :
reachesβ (TM2.step tr)
β¨some (head stack q), s, K'.elim (tr_list Lβ) [] [] (tr_list Lβ ++ Ξ'.Cons :: Lβ)β©
β¨some q, none, K'.elim (tr_list (Lβ.head :: Lβ)) [] [] Lββ© :=
begin
cases Lβ with a Lβ,
{ refine trans_gen.trans (move_ok dec_trivial
(split_at_pred_eq _ _ [] (some Ξ'.Cons) Lβ (by rintro _ β¨β©) β¨rfl, rflβ©))
(trans_gen.head rfl (trans_gen.head rfl _)),
convert unrev_ok, simp, refl },
{ refine trans_gen.trans (move_ok dec_trivial
(split_at_pred_eq _ _ (tr_nat a) (some Ξ'.cons)
(tr_list Lβ ++ Ξ'.Cons :: Lβ) (tr_nat_nat_end _) β¨rfl, by simpβ©))
(trans_gen.head rfl (trans_gen.head rfl _)),
simp,
refine trans_gen.trans (clear_ok
(split_at_pred_eq _ _ (tr_list Lβ) (some Ξ'.Cons) Lβ
(Ξ» x h, (to_bool_ff (tr_list_ne_Cons _ _ h))) β¨rfl, by simpβ©)) _,
convert unrev_ok, simp [list.reverse_core_eq] },
end
theorem succ_ok {q s n} {c d : list Ξ'} :
reachesβ (TM2.step tr)
β¨some (Ξ'.succ q), s, K'.elim (tr_list [n]) [] c dβ©
β¨some q, none, K'.elim (tr_list [n.succ]) [] c dβ© :=
begin
simp [tr_nat, num.add_one],
cases (n:num),
{ refine trans_gen.head rfl _, simp,
rw if_neg, swap, rintro β¨β©, rw if_pos, swap, refl,
convert unrev_ok, simp, refl },
simp [num.succ, tr_num, num.succ'],
suffices : β lβ,
β lβ' lβ' s', list.reverse_core lβ (tr_pos_num a.succ) = list.reverse_core lβ' lβ' β§
reachesβ (TM2.step tr)
β¨some q.succ, s, K'.elim (tr_pos_num a ++ [Ξ'.cons]) lβ c dβ©
β¨some (unrev q), s', K'.elim (lβ' ++ [Ξ'.cons]) lβ' c dβ©,
{ obtain β¨lβ', lβ', s', e, hβ© := this [], simp [list.reverse_core] at e,
refine h.trans _, convert unrev_ok using 2, simp [e, list.reverse_core_eq] },
induction a with m IH m IH generalizing s; intro lβ,
{ refine β¨Ξ'.bit0 :: lβ, [Ξ'.bit1], some Ξ'.cons, rfl, trans_gen.head rfl (trans_gen.single _)β©,
simp [tr_pos_num] },
{ obtain β¨lβ', lβ', s', e, hβ© := IH (Ξ'.bit0 :: lβ),
refine β¨lβ', lβ', s', e, trans_gen.head _ hβ©, swap,
simp [pos_num.succ, tr_pos_num] },
{ refine β¨lβ, _, some Ξ'.bit0, rfl, trans_gen.single _β©, simp, refl },
end
theorem pred_ok (qβ qβ s v) (c d : list Ξ') :
β s', reachesβ (TM2.step tr)
β¨some (Ξ'.pred qβ qβ), s, K'.elim (tr_list v) [] c dβ©
(v.head.elim
β¨some qβ, s', K'.elim (tr_list v.tail) [] c dβ©
(Ξ» n _, β¨some qβ, s', K'.elim (tr_list (n :: v.tail)) [] c dβ©)) :=
begin
rcases v with _|β¨_|n, vβ©,
{ refine β¨none, trans_gen.single _β©, simp, refl },
{ refine β¨some Ξ'.cons, trans_gen.single _β©, simp, refl },
refine β¨none, _β©, simp [tr_nat, num.add_one, num.succ, tr_num],
cases (n:num),
{ simp [tr_pos_num, tr_num, show num.zero.succ' = pos_num.one, from rfl],
refine trans_gen.head rfl _, convert unrev_ok, simp, refl },
simp [tr_num, num.succ'],
suffices : β lβ,
β lβ' lβ' s', list.reverse_core lβ (tr_pos_num a) = list.reverse_core lβ' lβ' β§
reachesβ (TM2.step tr)
β¨some (qβ.pred qβ), s, K'.elim (tr_pos_num a.succ ++ Ξ'.cons :: tr_list v) lβ c dβ©
β¨some (unrev qβ), s', K'.elim (lβ' ++ Ξ'.cons :: tr_list v) lβ' c dβ©,
{ obtain β¨lβ', lβ', s', e, hβ© := this [], simp [list.reverse_core] at e,
refine h.trans _, convert unrev_ok using 2, simp [e, list.reverse_core_eq] },
induction a with m IH m IH generalizing s; intro lβ,
{ refine β¨Ξ'.bit1 :: lβ, [], some Ξ'.cons, rfl, trans_gen.head rfl (trans_gen.single _)β©,
simp [tr_pos_num, show pos_num.one.succ = pos_num.one.bit0, from rfl], refl },
{ obtain β¨lβ', lβ', s', e, hβ© := IH (some Ξ'.bit0) (Ξ'.bit1 :: lβ),
refine β¨lβ', lβ', s', e, trans_gen.head _ hβ©, simp, refl },
{ obtain β¨a, l, e, hβ© : β a l, tr_pos_num m = a :: l β§ nat_end a = ff,
{ cases m; refine β¨_, _, rfl, rflβ© },
refine β¨Ξ'.bit0 :: lβ, _, some a, rfl, trans_gen.single _β©,
simp [tr_pos_num, pos_num.succ, e, h, nat_end,
show some Ξ'.bit1 β some Ξ'.bit0, from dec_trivial] },
end
theorem tr_normal_respects (c k v s) : β bβ, tr_cfg (step_normal c k v) bβ β§
reachesβ (TM2.step tr)
β¨some (tr_normal c (tr_cont k)), s, K'.elim (tr_list v) [] [] (tr_cont_stack k)β© bβ :=
begin
induction c generalizing k v s,
case zero' : { refine β¨_, β¨s, rflβ©, trans_gen.single _β©, simp },
case succ : { refine β¨_, β¨none, rflβ©, head_main_ok.trans succ_okβ© },
case tail : {
let o : option Ξ' := list.cases_on v none (Ξ» _ _, some Ξ'.cons),
refine β¨_, β¨o, rflβ©, _β©, convert clear_ok _, simp, swap,
refine split_at_pred_eq _ _ (tr_nat v.head) _ _ (tr_nat_nat_end _) _,
cases v; exact β¨rfl, rflβ© },
case cons : f fs IHf IHfs {
obtain β¨c, hβ, hββ© := IHf (cont.consβ fs v k) v none,
refine β¨c, hβ, trans_gen.head rfl $ (move_ok dec_trivial (split_at_pred_ff _)).trans _β©,
simp [step_normal],
refine (copy_ok _ none [] (tr_list v).reverse _ _).trans _,
convert hβ using 2,
simp [list.reverse_core_eq, tr_cont_stack] },
case comp : f g IHf IHg { exact IHg (cont.comp f k) v s },
case case : f g IHf IHg {
rw step_normal,
obtain β¨s', hβ© := pred_ok _ _ s v _ _,
cases v.head with n,
{ obtain β¨c, hβ, hββ© := IHf k _ s', exact β¨_, hβ, h.trans hββ© },
{ obtain β¨c, hβ, hββ© := IHg k _ s', exact β¨_, hβ, h.trans hββ© } },
case fix : f IH { apply IH }
end
theorem tr_ret_respects (k v s) : β bβ, tr_cfg (step_ret k v) bβ β§
reachesβ (TM2.step tr)
β¨some (Ξ'.ret (tr_cont k)), s, K'.elim (tr_list v) [] [] (tr_cont_stack k)β© bβ :=
begin
induction k generalizing v s,
case halt : { exact β¨_, rfl, trans_gen.single rflβ© },
case consβ : fs as k IH {
obtain β¨s', hβ, hββ© := tr_normal_respects fs (cont.consβ v k) as none,
refine β¨s', hβ, trans_gen.head rfl _β©, simp,
refine (moveβ_ok dec_trivial _ (split_at_pred_ff _)).trans _, {refl}, simp,
refine (moveβ_ok dec_trivial _ _).trans _, swap 4, {refl},
swap 4, {exact (split_at_pred_eq _ _ _ (some Ξ'.Cons) _
(Ξ» x h, to_bool_ff (tr_list_ne_Cons _ _ h)) β¨rfl, rflβ©)},
refine (moveβ_ok dec_trivial _ (split_at_pred_ff _)).trans _, {refl}, simp,
exact hβ },
case consβ : ns k IH {
obtain β¨c, hβ, hββ© := IH (ns.head :: v) none,
exact β¨c, hβ, trans_gen.head rfl $ head_stack_ok.trans hββ© },
case comp : f k IH {
obtain β¨s', hβ, hββ© := tr_normal_respects f k v s,
exact β¨_, hβ, trans_gen.head rfl hββ© },
case fix : f k IH {
rw [step_ret],
have : if v.head = 0
then nat_end (tr_list v).head'.iget = tt β§ (tr_list v).tail = tr_list v.tail
else nat_end (tr_list v).head'.iget = ff β§
(tr_list v).tail = (tr_nat v.head).tail ++ Ξ'.cons :: tr_list v.tail,
{ cases v with n, {exact β¨rfl, rflβ©}, cases n, {exact β¨rfl, rflβ©},
rw [tr_list, list.head, tr_nat, nat.cast_succ, num.add_one, num.succ, list.tail],
cases (n:num).succ'; exact β¨rfl, rflβ© },
by_cases v.head = 0; simp [h] at this β’,
{ obtain β¨c, hβ, hββ© := IH v.tail (tr_list v).head',
refine β¨c, hβ, trans_gen.head rfl _β©,
simp [tr_cont, tr_cont_stack, this], exact hβ },
{ obtain β¨s', hβ, hββ© := tr_normal_respects f (cont.fix f k) v.tail (some Ξ'.cons),
refine β¨_, hβ, trans_gen.head rfl $ trans_gen.trans _ hββ©,
swap 3, simp [tr_cont, this.1],
convert clear_ok (split_at_pred_eq _ _ (tr_nat v.head).tail (some Ξ'.cons) _ _ _) using 2,
{ simp },
{ exact Ξ» x h, tr_nat_nat_end _ _ (list.tail_subset _ h) },
{ exact β¨rfl, this.2β© } } },
end
theorem tr_respects : respects step (TM2.step tr) tr_cfg
| (cfg.ret k v) _ β¨s, rflβ© := tr_ret_respects _ _ _
| (cfg.halt v) _ rfl := rfl
/-- The initial state, evaluating function `c` on input `v`. -/
def init (c : code) (v : list β) : cfg' :=
β¨some (tr_normal c cont'.halt), none, K'.elim (tr_list v) [] [] []β©
theorem tr_init (c v) : β b, tr_cfg (step_normal c cont.halt v) b β§
reachesβ (TM2.step tr) (init c v) b := tr_normal_respects _ _ _ _
theorem tr_eval (c v) : eval (TM2.step tr) (init c v) = halt <$> code.eval c v :=
begin
obtain β¨i, hβ, hββ© := tr_init c v,
refine roption.ext (Ξ» x, _),
rw [reaches_eval hβ.to_refl], simp,
refine β¨Ξ» h, _, _β©,
{ obtain β¨c, hcβ, hcββ© := tr_eval_rev tr_respects hβ h,
simp [step_normal_eval] at hcβ,
obtain β¨v', hv, rflβ© := hcβ,
exact β¨_, hv, hcβ.symmβ© },
{ rintro β¨v', hv, rflβ©,
have := tr_eval tr_respects hβ,
simp [step_normal_eval] at this,
obtain β¨_, β¨β©, hβ© := this _ hv rfl,
exact h }
end
end
end partrec_to_TM2
end turing
|
266accc46d45213f151fe047895c4c8351f6e70b
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/field_theory/separable_auto.lean
|
b231d62fca2e061139aedf23c2bf5561a2c3774a
|
[] |
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
| 17,294
|
lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.polynomial.big_operators
import Mathlib.field_theory.minpoly
import Mathlib.field_theory.splitting_field
import Mathlib.field_theory.tower
import Mathlib.algebra.squarefree
import Mathlib.PostPort
universes u u_1 v u_2 u_3
namespace Mathlib
/-!
# Separable polynomials
We define a polynomial to be separable if it is coprime with its derivative. We prove basic
properties about separable polynomials here.
## Main definitions
* `polynomial.separable f`: a polynomial `f` is separable iff it is coprime with its derivative.
* `polynomial.expand R p f`: expand the polynomial `f` with coefficients in a
commutative semiring `R` by a factor of p, so `expand R p (β aβ xβΏ)` is `β aβ xβΏα΅`.
* `polynomial.contract p f`: the opposite of `expand`, so it sends `β aβ xβΏα΅` to `β aβ xβΏ`.
-/
namespace polynomial
/-- A polynomial is separable iff it is coprime with its derivative. -/
def separable {R : Type u} [comm_semiring R] (f : polynomial R) :=
is_coprime f (coe_fn derivative f)
theorem separable_def {R : Type u} [comm_semiring R] (f : polynomial R) :
separable f β is_coprime f (coe_fn derivative f) :=
iff.rfl
theorem separable_def' {R : Type u} [comm_semiring R] (f : polynomial R) :
separable f β β (a : polynomial R), β (b : polynomial R), a * f + b * coe_fn derivative f = 1 :=
iff.rfl
theorem separable_one {R : Type u} [comm_semiring R] : separable 1 := is_coprime_one_left
theorem separable_X_add_C {R : Type u} [comm_semiring R] (a : R) : separable (X + coe_fn C a) :=
sorry
theorem separable_X {R : Type u} [comm_semiring R] : separable X :=
eq.mpr (id (Eq._oldrec (Eq.refl (separable X)) (propext (separable_def X))))
(eq.mpr (id (Eq._oldrec (Eq.refl (is_coprime X (coe_fn derivative X))) derivative_X))
is_coprime_one_right)
theorem separable_C {R : Type u} [comm_semiring R] (r : R) : separable (coe_fn C r) β is_unit r :=
sorry
theorem separable.of_mul_left {R : Type u} [comm_semiring R] {f : polynomial R} {g : polynomial R}
(h : separable (f * g)) : separable f :=
sorry
theorem separable.of_mul_right {R : Type u} [comm_semiring R] {f : polynomial R} {g : polynomial R}
(h : separable (f * g)) : separable g :=
separable.of_mul_left (eq.mp (Eq._oldrec (Eq.refl (separable (f * g))) (mul_comm f g)) h)
theorem separable.of_dvd {R : Type u} [comm_semiring R] {f : polynomial R} {g : polynomial R}
(hf : separable f) (hfg : g β£ f) : separable g :=
Exists.dcases_on hfg
fun (f' : polynomial R) (hfg_h : f = g * f') =>
Eq._oldrec (fun (hf : separable (g * f')) => separable.of_mul_left hf) (Eq.symm hfg_h) hf
theorem separable_gcd_left {F : Type u_1} [field F] {f : polynomial F} (hf : separable f)
(g : polynomial F) : separable (euclidean_domain.gcd f g) :=
separable.of_dvd hf (euclidean_domain.gcd_dvd_left f g)
theorem separable_gcd_right {F : Type u_1} [field F] {g : polynomial F} (f : polynomial F)
(hg : separable g) : separable (euclidean_domain.gcd f g) :=
separable.of_dvd hg (euclidean_domain.gcd_dvd_right f g)
theorem separable.is_coprime {R : Type u} [comm_semiring R] {f : polynomial R} {g : polynomial R}
(h : separable (f * g)) : is_coprime f g :=
sorry
theorem separable.of_pow' {R : Type u} [comm_semiring R] {f : polynomial R} {n : β}
(h : separable (f ^ n)) : is_unit f β¨ separable f β§ n = 1 β¨ n = 0 :=
sorry
theorem separable.of_pow {R : Type u} [comm_semiring R] {f : polynomial R} (hf : Β¬is_unit f) {n : β}
(hn : n β 0) (hfs : separable (f ^ n)) : separable f β§ n = 1 :=
or.resolve_right (or.resolve_left (separable.of_pow' hfs) hf) hn
theorem separable.map {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S]
{p : polynomial R} (h : separable p) {f : R β+* S} : separable (map f p) :=
sorry
/-- Expand the polynomial by a factor of p, so `β aβ xβΏ` becomes `β aβ xβΏα΅`. -/
def expand (R : Type u) [comm_semiring R] (p : β) : alg_hom R (polynomial R) (polynomial R) :=
alg_hom.mk (ring_hom.to_fun (evalβ_ring_hom C (X ^ p))) sorry sorry sorry sorry sorry
theorem coe_expand (R : Type u) [comm_semiring R] (p : β) : β(expand R p) = evalβ C (X ^ p) := rfl
theorem expand_eq_sum {R : Type u} [comm_semiring R] (p : β) {f : polynomial R} :
coe_fn (expand R p) f = finsupp.sum f fun (e : β) (a : R) => coe_fn C a * (X ^ p) ^ e :=
id (Eq.refl (finsupp.sum f fun (e : β) (a : R) => coe_fn C a * (X ^ p) ^ e))
@[simp] theorem expand_C {R : Type u} [comm_semiring R] (p : β) (r : R) :
coe_fn (expand R p) (coe_fn C r) = coe_fn C r :=
evalβ_C C (X ^ p)
@[simp] theorem expand_X {R : Type u} [comm_semiring R] (p : β) : coe_fn (expand R p) X = X ^ p :=
evalβ_X C (X ^ p)
@[simp] theorem expand_monomial {R : Type u} [comm_semiring R] (p : β) (q : β) (r : R) :
coe_fn (expand R p) (coe_fn (monomial q) r) = coe_fn (monomial (q * p)) r :=
sorry
theorem expand_expand {R : Type u} [comm_semiring R] (p : β) (q : β) (f : polynomial R) :
coe_fn (expand R p) (coe_fn (expand R q) f) = coe_fn (expand R (p * q)) f :=
sorry
theorem expand_mul {R : Type u} [comm_semiring R] (p : β) (q : β) (f : polynomial R) :
coe_fn (expand R (p * q)) f = coe_fn (expand R p) (coe_fn (expand R q) f) :=
Eq.symm (expand_expand p q f)
@[simp] theorem expand_one {R : Type u} [comm_semiring R] (f : polynomial R) :
coe_fn (expand R 1) f = f :=
sorry
theorem expand_pow {R : Type u} [comm_semiring R] (p : β) (q : β) (f : polynomial R) :
coe_fn (expand R (p ^ q)) f = nat.iterate (β(expand R p)) q f :=
sorry
theorem derivative_expand {R : Type u} [comm_semiring R] (p : β) (f : polynomial R) :
coe_fn derivative (coe_fn (expand R p) f) =
coe_fn (expand R p) (coe_fn derivative f) * (βp * X ^ (p - 1)) :=
sorry
theorem coeff_expand {R : Type u} [comm_semiring R] {p : β} (hp : 0 < p) (f : polynomial R)
(n : β) : coeff (coe_fn (expand R p) f) n = ite (p β£ n) (coeff f (n / p)) 0 :=
sorry
@[simp] theorem coeff_expand_mul {R : Type u} [comm_semiring R] {p : β} (hp : 0 < p)
(f : polynomial R) (n : β) : coeff (coe_fn (expand R p) f) (n * p) = coeff f n :=
sorry
@[simp] theorem coeff_expand_mul' {R : Type u} [comm_semiring R] {p : β} (hp : 0 < p)
(f : polynomial R) (n : β) : coeff (coe_fn (expand R p) f) (p * n) = coeff f n :=
eq.mpr
(id (Eq._oldrec (Eq.refl (coeff (coe_fn (expand R p) f) (p * n) = coeff f n)) (mul_comm p n)))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (coeff (coe_fn (expand R p) f) (n * p) = coeff f n))
(coeff_expand_mul hp f n)))
(Eq.refl (coeff f n)))
theorem expand_eq_map_domain {R : Type u} [comm_semiring R] (p : β) (f : polynomial R) :
coe_fn (expand R p) f = finsupp.map_domain (fun (_x : β) => _x * p) f :=
sorry
theorem expand_inj {R : Type u} [comm_semiring R] {p : β} (hp : 0 < p) {f : polynomial R}
{g : polynomial R} : coe_fn (expand R p) f = coe_fn (expand R p) g β f = g :=
sorry
theorem expand_eq_zero {R : Type u} [comm_semiring R] {p : β} (hp : 0 < p) {f : polynomial R} :
coe_fn (expand R p) f = 0 β f = 0 :=
sorry
theorem expand_eq_C {R : Type u} [comm_semiring R] {p : β} (hp : 0 < p) {f : polynomial R} {r : R} :
coe_fn (expand R p) f = coe_fn C r β f = coe_fn C r :=
sorry
theorem nat_degree_expand {R : Type u} [comm_semiring R] (p : β) (f : polynomial R) :
nat_degree (coe_fn (expand R p) f) = nat_degree f * p :=
sorry
theorem map_expand {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] {p : β}
(hp : 0 < p) {f : R β+* S} {q : polynomial R} :
map f (coe_fn (expand R p) q) = coe_fn (expand S p) (map f q) :=
sorry
theorem separable_X_sub_C {R : Type u} [comm_ring R] {x : R} : separable (X - coe_fn C x) := sorry
theorem separable.mul {R : Type u} [comm_ring R] {f : polynomial R} {g : polynomial R}
(hf : separable f) (hg : separable g) (h : is_coprime f g) : separable (f * g) :=
sorry
theorem separable_prod' {R : Type u} [comm_ring R] {ΞΉ : Type u_1} {f : ΞΉ β polynomial R}
{s : finset ΞΉ} :
(β (x : ΞΉ), x β s β β (y : ΞΉ), y β s β x β y β is_coprime (f x) (f y)) β
(β (x : ΞΉ), x β s β separable (f x)) β separable (finset.prod s fun (x : ΞΉ) => f x) :=
sorry
theorem separable_prod {R : Type u} [comm_ring R] {ΞΉ : Type u_1} [fintype ΞΉ] {f : ΞΉ β polynomial R}
(h1 : pairwise (is_coprime on f)) (h2 : β (x : ΞΉ), separable (f x)) :
separable (finset.prod finset.univ fun (x : ΞΉ) => f x) :=
separable_prod'
(fun (x : ΞΉ) (hx : x β finset.univ) (y : ΞΉ) (hy : y β finset.univ) (hxy : x β y) => h1 x y hxy)
fun (x : ΞΉ) (hx : x β finset.univ) => h2 x
theorem separable.inj_of_prod_X_sub_C {R : Type u} [comm_ring R] [nontrivial R] {ΞΉ : Type u_1}
{f : ΞΉ β R} {s : finset ΞΉ} (hfs : separable (finset.prod s fun (i : ΞΉ) => X - coe_fn C (f i)))
{x : ΞΉ} {y : ΞΉ} (hx : x β s) (hy : y β s) (hfxy : f x = f y) : x = y :=
sorry
theorem separable.injective_of_prod_X_sub_C {R : Type u} [comm_ring R] [nontrivial R] {ΞΉ : Type u_1}
[fintype ΞΉ] {f : ΞΉ β R}
(hfs : separable (finset.prod finset.univ fun (i : ΞΉ) => X - coe_fn C (f i))) :
function.injective f :=
fun (x y : ΞΉ) (hfxy : f x = f y) =>
separable.inj_of_prod_X_sub_C hfs (finset.mem_univ x) (finset.mem_univ y) hfxy
theorem is_unit_of_self_mul_dvd_separable {R : Type u} [comm_ring R] {p : polynomial R}
{q : polynomial R} (hp : separable p) (hq : q * q β£ p) : is_unit q :=
sorry
theorem is_local_ring_hom_expand (R : Type u) [integral_domain R] {p : β} (hp : 0 < p) :
is_local_ring_hom β(expand R p) :=
sorry
theorem separable_iff_derivative_ne_zero {F : Type u} [field F] {f : polynomial F}
(hf : irreducible f) : separable f β coe_fn derivative f β 0 :=
sorry
theorem separable_map {F : Type u} [field F] {K : Type v} [field K] (f : F β+* K)
{p : polynomial F} : separable (map f p) β separable p :=
sorry
/-- The opposite of `expand`: sends `β aβ xβΏα΅` to `β aβ xβΏ`. -/
def contract {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)] (f : polynomial F) :
polynomial F :=
finsupp.mk (finset.preimage (finsupp.support f) (fun (_x : β) => _x * p) sorry)
(fun (n : β) => coeff f (n * p)) sorry
theorem coeff_contract {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)] (f : polynomial F)
(n : β) : coeff (contract p f) n = coeff f (n * p) :=
rfl
theorem of_irreducible_expand {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)]
{f : polynomial F} (hf : irreducible (coe_fn (expand F p) f)) : irreducible f :=
of_irreducible_map (β(expand F p)) hf
theorem of_irreducible_expand_pow {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)]
{f : polynomial F} {n : β} : irreducible (coe_fn (expand F (p ^ n)) f) β irreducible f :=
sorry
theorem expand_char {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)] [HF : char_p F p]
(f : polynomial F) : map (frobenius F p) (coe_fn (expand F p) f) = f ^ p :=
sorry
theorem map_expand_pow_char {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)]
[HF : char_p F p] (f : polynomial F) (n : β) :
map (frobenius F p ^ n) (coe_fn (expand F (p ^ n)) f) = f ^ p ^ n :=
sorry
theorem expand_contract {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)] [HF : char_p F p]
{f : polynomial F} (hf : coe_fn derivative f = 0) : coe_fn (expand F p) (contract p f) = f :=
sorry
theorem separable_or {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)] [HF : char_p F p]
{f : polynomial F} (hf : irreducible f) :
separable f β¨ Β¬separable f β§ β (g : polynomial F), irreducible g β§ coe_fn (expand F p) g = f :=
sorry
theorem exists_separable_of_irreducible {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)]
[HF : char_p F p] {f : polynomial F} (hf : irreducible f) (hf0 : f β 0) :
β (n : β), β (g : polynomial F), separable g β§ coe_fn (expand F (p ^ n)) g = f :=
sorry
theorem is_unit_or_eq_zero_of_separable_expand {F : Type u} [field F] (p : β)
[hp : fact (nat.prime p)] [HF : char_p F p] {f : polynomial F} (n : β)
(hf : separable (coe_fn (expand F (p ^ n)) f)) : is_unit f β¨ n = 0 :=
sorry
theorem unique_separable_of_irreducible {F : Type u} [field F] (p : β) [hp : fact (nat.prime p)]
[HF : char_p F p] {f : polynomial F} (hf : irreducible f) (hf0 : f β 0) (nβ : β)
(gβ : polynomial F) (hgβ : separable gβ) (hgfβ : coe_fn (expand F (p ^ nβ)) gβ = f) (nβ : β)
(gβ : polynomial F) (hgβ : separable gβ) (hgfβ : coe_fn (expand F (p ^ nβ)) gβ = f) :
nβ = nβ β§ gβ = gβ :=
sorry
theorem separable_prod_X_sub_C_iff' {F : Type u} [field F] {ΞΉ : Type u_1} {f : ΞΉ β F}
{s : finset ΞΉ} :
separable (finset.prod s fun (i : ΞΉ) => X - coe_fn C (f i)) β
β (x : ΞΉ), x β s β β (y : ΞΉ), y β s β f x = f y β x = y :=
sorry
theorem separable_prod_X_sub_C_iff {F : Type u} [field F] {ΞΉ : Type u_1} [fintype ΞΉ] {f : ΞΉ β F} :
separable (finset.prod finset.univ fun (i : ΞΉ) => X - coe_fn C (f i)) β function.injective f :=
sorry
theorem not_unit_X_sub_C {F : Type u} [field F] (a : F) : Β¬is_unit (X - coe_fn C a) := sorry
theorem nodup_of_separable_prod {F : Type u} [field F] {s : multiset F}
(hs : separable (multiset.prod (multiset.map (fun (a : F) => X - coe_fn C a) s))) :
multiset.nodup s :=
sorry
theorem multiplicity_le_one_of_separable {F : Type u} [field F] {p : polynomial F}
{q : polynomial F} (hq : Β¬is_unit q) (hsep : separable p) : multiplicity q p β€ 1 :=
sorry
theorem separable.squarefree {F : Type u} [field F] {p : polynomial F} (hsep : separable p) :
squarefree p :=
sorry
/--If `n β 0` in `F`, then ` X ^ n - a` is separable for any `a β 0`. -/
theorem separable_X_pow_sub_C {F : Type u} [field F] {n : β} (a : F) (hn : βn β 0) (ha : a β 0) :
separable (X ^ n - coe_fn C a) :=
sorry
/--If `n β 0` in `F`, then ` X ^ n - a` is squarefree for any `a β 0`. -/
theorem squarefree_X_pow_sub_C {F : Type u} [field F] {n : β} (a : F) (hn : βn β 0) (ha : a β 0) :
squarefree (X ^ n - coe_fn C a) :=
separable.squarefree (separable_X_pow_sub_C a hn ha)
theorem root_multiplicity_le_one_of_separable {F : Type u} [field F] {p : polynomial F} (hp : p β 0)
(hsep : separable p) (x : F) : root_multiplicity x p β€ 1 :=
sorry
theorem count_roots_le_one {F : Type u} [field F] {p : polynomial F} (hsep : separable p) (x : F) :
multiset.count x (roots p) β€ 1 :=
sorry
theorem nodup_roots {F : Type u} [field F] {p : polynomial F} (hsep : separable p) :
multiset.nodup (roots p) :=
iff.mpr multiset.nodup_iff_count_le_one (count_roots_le_one hsep)
theorem eq_X_sub_C_of_separable_of_root_eq {F : Type u} [field F] {K : Type v} [field K]
{i : F β+* K} {x : F} {h : polynomial F} (h_ne_zero : h β 0) (h_sep : separable h)
(h_root : eval x h = 0) (h_splits : splits i h)
(h_roots : β (y : K), y β roots (map i h) β y = coe_fn i x) :
h = coe_fn C (leading_coeff h) * (X - coe_fn C x) :=
sorry
end polynomial
theorem irreducible.separable {F : Type u} [field F] [char_zero F] {f : polynomial F}
(hf : irreducible f) : polynomial.separable f :=
sorry
-- TODO: refactor to allow transcendental extensions?
-- See: https://en.wikipedia.org/wiki/Separable_extension#Separability_of_transcendental_extensions
/-- Typeclass for separable field extension: `K` is a separable field extension of `F` iff
the minimal polynomial of every `x : K` is separable. -/
def is_separable (F : Type u_1) (K : Type u_2) [field F] [field K] [algebra F K] :=
β (x : K), is_integral F x β§ polynomial.separable (minpoly F x)
protected instance is_separable_self (F : Type u_1) [field F] : is_separable F F :=
fun (x : F) =>
{ left := is_integral_algebra_map,
right :=
eq.mpr
(id (Eq._oldrec (Eq.refl (polynomial.separable (minpoly F x))) (minpoly.eq_X_sub_C' x)))
polynomial.separable_X_sub_C }
theorem is_separable_tower_top_of_is_separable (F : Type u_1) (K : Type u_2) (E : Type u_3)
[field F] [field K] [field E] [algebra F K] [algebra F E] [algebra K E] [is_scalar_tower F K E]
[h : is_separable F E] : is_separable K E :=
sorry
theorem is_separable_tower_bot_of_is_separable (F : Type u_1) (K : Type u_2) (E : Type u_3)
[field F] [field K] [field E] [algebra F K] [algebra F E] [algebra K E] [is_scalar_tower F K E]
[h : is_separable F E] : is_separable F K :=
sorry
theorem is_separable.of_alg_hom (F : Type u_1) {E : Type u_3} [field F] [field E] [algebra F E]
(E' : Type u_2) [field E'] [algebra F E'] (f : alg_hom F E E') [is_separable F E'] :
is_separable F E :=
let _inst : algebra E E' := ring_hom.to_algebra (alg_hom.to_ring_hom f);
is_separable_tower_bot_of_is_separable F E E'
end Mathlib
|
58d4e07b12b308bf6f1e34eebbbae95047936197
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/order/category/NonemptyFinLinOrd.lean
|
a9187c8796b332ec3728bb75171f053eda58bf95
|
[
"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
| 2,298
|
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 data.fin.basic
import data.fintype.sort
import order.category.LinearOrder
/-! # Nonempty finite linear orders
Nonempty finite linear orders form the index category for simplicial objects.
-/
universes u v
open category_theory
/-- A typeclass for nonempty finite linear orders. -/
class nonempty_fin_lin_ord (Ξ± : Type*) extends fintype Ξ±, linear_order Ξ± :=
(nonempty : nonempty Ξ± . tactic.apply_instance)
attribute [instance] nonempty_fin_lin_ord.nonempty
@[priority 100]
instance nonempty_fin_lin_ord.order_bot (Ξ± : Type*) [nonempty_fin_lin_ord Ξ±] : order_bot Ξ± :=
{ bot := finset.min' finset.univ β¨classical.arbitrary Ξ±, by simpβ©,
bot_le := Ξ» a, finset.min'_le _ a (by simp) }
@[priority 100]
instance nonempty_fin_lin_ord.order_top (Ξ± : Type*) [nonempty_fin_lin_ord Ξ±] : order_top Ξ± :=
{ top := finset.max' finset.univ β¨classical.arbitrary Ξ±, by simpβ©,
le_top := Ξ» a, finset.le_max' _ a (by simp) }
instance punit.nonempty_fin_lin_ord : nonempty_fin_lin_ord punit :=
{ .. punit.linear_ordered_cancel_add_comm_monoid,
.. punit.fintype }
instance fin.nonempty_fin_lin_ord (n : β) : nonempty_fin_lin_ord (fin (n+1)) :=
{ .. fin.fintype _,
.. fin.linear_order }
instance ulift.nonempty_fin_lin_ord (Ξ± : Type u) [nonempty_fin_lin_ord Ξ±] :
nonempty_fin_lin_ord (ulift.{v} Ξ±) :=
{ nonempty := β¨ulift.up β₯β©,
.. linear_order.lift equiv.ulift (equiv.injective _),
.. ulift.fintype _ }
/-- The category of nonempty finite linear orders. -/
def NonemptyFinLinOrd := bundled nonempty_fin_lin_ord
namespace NonemptyFinLinOrd
instance : bundled_hom.parent_projection @nonempty_fin_lin_ord.to_linear_order := β¨β©
attribute [derive [large_category, concrete_category]] NonemptyFinLinOrd
instance : has_coe_to_sort NonemptyFinLinOrd Type* := bundled.has_coe_to_sort
/-- Construct a bundled NonemptyFinLinOrd from the underlying type and typeclass. -/
def of (Ξ± : Type*) [nonempty_fin_lin_ord Ξ±] : NonemptyFinLinOrd := bundled.of Ξ±
instance : inhabited NonemptyFinLinOrd := β¨of punitβ©
instance (Ξ± : NonemptyFinLinOrd) : nonempty_fin_lin_ord Ξ± := Ξ±.str
end NonemptyFinLinOrd
|
062297247b9963a9fcb37e4c34c899b4d67d27d1
|
07c6143268cfb72beccd1cc35735d424ebcb187b
|
/src/data/padics/padic_numbers.lean
|
8be6f79ecb63d27bf1922675e397ff7c7e7ca842
|
[
"Apache-2.0"
] |
permissive
|
khoek/mathlib
|
bc49a842910af13a3c372748310e86467d1dc766
|
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
|
refs/heads/master
| 1,588,232,063,837
| 1,587,304,803,000
| 1,587,304,803,000
| 176,688,517
| 0
| 0
|
Apache-2.0
| 1,553,070,585,000
| 1,553,070,585,000
| null |
UTF-8
|
Lean
| false
| false
| 32,563
|
lean
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import data.real.cau_seq_completion
import data.padics.padic_norm algebra.archimedean analysis.normed_space.basic
import tactic.norm_cast
/-!
# p-adic numbers
This file defines the p-adic numbers (rationals) β_p as the completion of β with respect to the
p-adic norm. We show that the p-adic norm on β extends to β_p, that β is embedded in β_p, and that
β_p is Cauchy complete.
## Important definitions
* `padic` : the type of p-adic numbers
* `padic_norm_e` : the rational valued p-adic norm on β_p
## Notation
We introduce the notation β_[p] for the p-adic numbers.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking (prime p) as a type class argument.
We use the same concrete Cauchy sequence construction that is used to construct β. β_p inherits a
field structure from this construction. The extension of the norm on β to β_p is *not* analogous to
extending the absolute value to β, and hence the proof that β_p is complete is different from the
proof that β is complete.
A small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence
indices in the proof that the norm extends.
`padic_norm_e` is the rational-valued p-adic norm on β_p. To instantiate β_p as a normed field, we
must cast this into a β-valued norm. The β-valued norm, using notation β₯ β₯ from normed spaces, is
the canonical representation of this norm.
Coercions from β to β_p are set up to work with the `norm_cast` tactic.
## References
* [F. Q. GouΓͺva, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion
-/
noncomputable theory
open_locale classical
open nat multiplicity padic_norm cau_seq cau_seq.completion metric
/-- The type of Cauchy sequences of rationals with respect to the p-adic norm. -/
@[reducible] def padic_seq (p : β) [p.prime] := cau_seq _ (padic_norm p)
namespace padic_seq
section
variables {p : β} [nat.prime p]
/-- The p-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually
constant. -/
lemma stationary {f : cau_seq β (padic_norm p)} (hf : Β¬ f β 0) :
β N, β m n, N β€ m β N β€ n β padic_norm p (f n) = padic_norm p (f m) :=
have β Ξ΅ > 0, β N1, β j β₯ N1, Ξ΅ β€ padic_norm p (f j),
from cau_seq.abv_pos_of_not_lim_zero $ not_lim_zero_of_not_congr_zero hf,
let β¨Ξ΅, hΞ΅, N1, hN1β© := this,
β¨N2, hN2β© := cau_seq.cauchyβ f hΞ΅ in
β¨ max N1 N2,
Ξ» n m hn hm,
have padic_norm p (f n - f m) < Ξ΅, from hN2 _ _ (max_le_iff.1 hn).2 (max_le_iff.1 hm).2,
have padic_norm p (f n - f m) < padic_norm p (f n),
from lt_of_lt_of_le this $ hN1 _ (max_le_iff.1 hn).1,
have padic_norm p (f n - f m) < max (padic_norm p (f n)) (padic_norm p (f m)),
from lt_max_iff.2 (or.inl this),
begin
by_contradiction hne,
rw βpadic_norm.neg p (f m) at hne,
have hnam := add_eq_max_of_ne p hne,
rw [padic_norm.neg, max_comm] at hnam,
rw [βhnam, sub_eq_add_neg, add_comm] at this,
apply _root_.lt_irrefl _ this
end β©
/-- For all n β₯ stationary_point f hf, the p-adic norm of f n is the same. -/
def stationary_point {f : padic_seq p} (hf : Β¬ f β 0) : β :=
classical.some $ stationary hf
lemma stationary_point_spec {f : padic_seq p} (hf : Β¬ f β 0) :
β {m n}, m β₯ stationary_point hf β n β₯ stationary_point hf β
padic_norm p (f n) = padic_norm p (f m) :=
classical.some_spec $ stationary hf
/-- Since the norm of the entries of a Cauchy sequence is eventually stationary, we can lift the norm
to sequences. -/
def norm (f : padic_seq p) : β :=
if hf : f β 0 then 0 else padic_norm p (f (stationary_point hf))
lemma norm_zero_iff (f : padic_seq p) : f.norm = 0 β f β 0 :=
begin
constructor,
{ intro h,
by_contradiction hf,
unfold norm at h, split_ifs at h,
apply hf,
intros Ξ΅ hΞ΅,
existsi stationary_point hf,
intros j hj,
have heq := stationary_point_spec hf (le_refl _) hj,
simpa [h, heq] },
{ intro h,
simp [norm, h] }
end
end
section embedding
open cau_seq
variables {p : β} [nat.prime p]
lemma equiv_zero_of_val_eq_of_equiv_zero {f g : padic_seq p}
(h : β k, padic_norm p (f k) = padic_norm p (g k)) (hf : f β 0) : g β 0 :=
Ξ» Ξ΅ hΞ΅, let β¨i, hiβ© := hf _ hΞ΅ in
β¨i, Ξ» j hj, by simpa [h] using hi _ hjβ©
lemma norm_nonzero_of_not_equiv_zero {f : padic_seq p} (hf : Β¬ f β 0) :
f.norm β 0 :=
hf β f.norm_zero_iff.1
lemma norm_eq_norm_app_of_nonzero {f : padic_seq p} (hf : Β¬ f β 0) :
β k, f.norm = padic_norm p k β§ k β 0 :=
have heq : f.norm = padic_norm p (f $ stationary_point hf), by simp [norm, hf],
β¨f $ stationary_point hf, heq,
Ξ» h, norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)β©
lemma not_lim_zero_const_of_nonzero {q : β} (hq : q β 0) : Β¬ lim_zero (const (padic_norm p) q) :=
Ξ» h', hq $ const_lim_zero.1 h'
lemma not_equiv_zero_const_of_nonzero {q : β} (hq : q β 0) : Β¬ (const (padic_norm p) q) β 0 :=
Ξ» h : lim_zero (const (padic_norm p) q - 0), not_lim_zero_const_of_nonzero hq $ by simpa using h
lemma norm_nonneg (f : padic_seq p) : f.norm β₯ 0 :=
if hf : f β 0 then by simp [hf, norm]
else by simp [norm, hf, padic_norm.nonneg]
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_left_left {f : padic_seq p} (hf : Β¬ f β 0) (v2 v3 : β) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max (stationary_point hf) (max v2 v3))) :=
let i := max (stationary_point hf) (max v2 v3) in
begin
apply stationary_point_spec hf,
{ apply le_max_left },
{ apply le_refl }
end
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_left {f : padic_seq p} (hf : Β¬ f β 0) (v1 v3 : β) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max v1 (max (stationary_point hf) v3))) :=
let i := max v1 (max (stationary_point hf) v3) in
begin
apply stationary_point_spec hf,
{ apply le_trans,
{ apply le_max_left _ v3 },
{ apply le_max_right } },
{ apply le_refl }
end
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_right {f : padic_seq p} (hf : Β¬ f β 0) (v1 v2 : β) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max v1 (max v2 (stationary_point hf)))) :=
let i := max v1 (max v2 (stationary_point hf)) in
begin
apply stationary_point_spec hf,
{ apply le_trans,
{ apply le_max_right v2 },
{ apply le_max_right } },
{ apply le_refl }
end
end embedding
end padic_seq
section
open padic_seq
private meta def index_simp_core (hh hf hg : expr)
(at_ : interactive.loc := interactive.loc.ns [none]) : tactic unit :=
do [v1, v2, v3] β [hh, hf, hg].mmap
(Ξ» n, tactic.mk_app ``stationary_point [n] <|> return n),
e1 β tactic.mk_app ``lift_index_left_left [hh, v2, v3] <|> return `(true),
e2 β tactic.mk_app ``lift_index_left [hf, v1, v3] <|> return `(true),
e3 β tactic.mk_app ``lift_index_right [hg, v1, v2] <|> return `(true),
sl β [e1, e2, e3].mfoldl (Ξ» s e, simp_lemmas.add s e) simp_lemmas.mk,
when at_.include_goal (tactic.simp_target sl),
hs β at_.get_locals, hs.mmap' (tactic.simp_hyp sl [])
/--
This is a special-purpose tactic that lifts padic_norm (f (stationary_point f)) to
padic_norm (f (max _ _ _)).
-/
meta def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)
(at_ : interactive.parse interactive.types.location) : tactic unit :=
do [h, f, g] β l.mmap tactic.i_to_expr,
index_simp_core h f g at_
end
namespace padic_seq
section embedding
open cau_seq
variables {p : β} [hp : nat.prime p]
include hp
lemma norm_mul (f g : padic_seq p) : (f * g).norm = f.norm * g.norm :=
if hf : f β 0 then
have hg : f * g β 0, from mul_equiv_zero' _ hf,
by simp [hf, hg, norm]
else if hg : g β 0 then
have hf : f * g β 0, from mul_equiv_zero _ hg,
by simp [hf, hg, norm]
else
have hfg : Β¬ f * g β 0, by apply mul_not_equiv_zero; assumption,
begin
unfold norm,
split_ifs,
padic_index_simp [hfg, hf, hg],
apply padic_norm.mul
end
lemma eq_zero_iff_equiv_zero (f : padic_seq p) : mk f = 0 β f β 0 :=
mk_eq
lemma ne_zero_iff_nequiv_zero (f : padic_seq p) : mk f β 0 β Β¬ f β 0 :=
not_iff_not.2 (eq_zero_iff_equiv_zero _)
lemma norm_const (q : β) : norm (const (padic_norm p) q) = padic_norm p q :=
if hq : q = 0 then
have (const (padic_norm p) q) β 0,
by simp [hq]; apply setoid.refl (const (padic_norm p) 0),
by subst hq; simp [norm, this]
else
have Β¬ (const (padic_norm p) q) β 0, from not_equiv_zero_const_of_nonzero hq,
by simp [norm, this]
lemma norm_image (a : padic_seq p) (ha : Β¬ a β 0) :
(β (n : β€), a.norm = βp ^ (-n)) :=
let β¨k, hk, hk'β© := norm_eq_norm_app_of_nonzero ha in
by simpa [hk] using padic_norm.image p hk'
lemma norm_one : norm (1 : padic_seq p) = 1 :=
have h1 : Β¬ (1 : padic_seq p) β 0, from one_not_equiv_zero _,
by simp [h1, norm, hp.one_lt]
private lemma norm_eq_of_equiv_aux {f g : padic_seq p} (hf : Β¬ f β 0) (hg : Β¬ g β 0) (hfg : f β g)
(h : padic_norm p (f (stationary_point hf)) β padic_norm p (g (stationary_point hg)))
(hgt : padic_norm p (f (stationary_point hf)) > padic_norm p (g (stationary_point hg))) :
false :=
begin
have hpn : padic_norm p (f (stationary_point hf)) - padic_norm p (g (stationary_point hg)) > 0,
from sub_pos_of_lt hgt,
cases hfg _ hpn with N hN,
let i := max N (max (stationary_point hf) (stationary_point hg)),
have hi : i β₯ N, from le_max_left _ _,
have hN' := hN _ hi,
padic_index_simp [N, hf, hg] at hN' h hgt,
have hpne : padic_norm p (f i) β padic_norm p (-(g i)),
by rwa [ βpadic_norm.neg p (g i)] at h,
let hpnem := add_eq_max_of_ne p hpne,
have hpeq : padic_norm p ((f - g) i) = max (padic_norm p (f i)) (padic_norm p (g i)),
{ rwa padic_norm.neg at hpnem },
rw [hpeq, max_eq_left_of_lt hgt] at hN',
have : padic_norm p (f i) < padic_norm p (f i),
{ apply lt_of_lt_of_le hN', apply sub_le_self, apply padic_norm.nonneg },
exact lt_irrefl _ this
end
private lemma norm_eq_of_equiv {f g : padic_seq p} (hf : Β¬ f β 0) (hg : Β¬ g β 0) (hfg : f β g) :
padic_norm p (f (stationary_point hf)) = padic_norm p (g (stationary_point hg)) :=
begin
by_contradiction h,
cases (decidable.em (padic_norm p (f (stationary_point hf)) >
padic_norm p (g (stationary_point hg))))
with hgt hngt,
{ exact norm_eq_of_equiv_aux hf hg hfg h hgt },
{ apply norm_eq_of_equiv_aux hg hf (setoid.symm hfg) (ne.symm h),
apply lt_of_le_of_ne,
apply le_of_not_gt hngt,
apply h }
end
theorem norm_equiv {f g : padic_seq p} (hfg : f β g) : f.norm = g.norm :=
if hf : f β 0 then
have hg : g β 0, from setoid.trans (setoid.symm hfg) hf,
by simp [norm, hf, hg]
else have hg : Β¬ g β 0, from hf β setoid.trans hfg,
by unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg
private lemma norm_nonarchimedean_aux {f g : padic_seq p}
(hfg : Β¬ f + g β 0) (hf : Β¬ f β 0) (hg : Β¬ g β 0) : (f + g).norm β€ max (f.norm) (g.norm) :=
begin
unfold norm, split_ifs,
padic_index_simp [hfg, hf, hg],
apply padic_norm.nonarchimedean
end
theorem norm_nonarchimedean (f g : padic_seq p) : (f + g).norm β€ max (f.norm) (g.norm) :=
if hfg : f + g β 0 then
have 0 β€ max (f.norm) (g.norm), from le_max_left_of_le (norm_nonneg _),
by simpa [hfg, norm]
else if hf : f β 0 then
have hfg' : f + g β g,
{ change lim_zero (f - 0) at hf,
show lim_zero (f + g - g), by simpa using hf },
have hcfg : (f + g).norm = g.norm, from norm_equiv hfg',
have hcl : f.norm = 0, from (norm_zero_iff f).2 hf,
have max (f.norm) (g.norm) = g.norm,
by rw hcl; exact max_eq_right (norm_nonneg _),
by rw [this, hcfg]
else if hg : g β 0 then
have hfg' : f + g β f,
{ change lim_zero (g - 0) at hg,
show lim_zero (f + g - f), by simpa [add_sub_cancel'] using hg },
have hcfg : (f + g).norm = f.norm, from norm_equiv hfg',
have hcl : g.norm = 0, from (norm_zero_iff g).2 hg,
have max (f.norm) (g.norm) = f.norm,
by rw hcl; exact max_eq_left (norm_nonneg _),
by rw [this, hcfg]
else norm_nonarchimedean_aux hfg hf hg
lemma norm_eq {f g : padic_seq p} (h : β k, padic_norm p (f k) = padic_norm p (g k)) :
f.norm = g.norm :=
if hf : f β 0 then
have hg : g β 0, from equiv_zero_of_val_eq_of_equiv_zero h hf,
by simp [hf, hg, norm]
else
have hg : Β¬ g β 0, from Ξ» hg, hf $ equiv_zero_of_val_eq_of_equiv_zero (by simp [h]) hg,
begin
simp [hg, hf, norm],
let i := max (stationary_point hf) (stationary_point hg),
have hpf : padic_norm p (f (stationary_point hf)) = padic_norm p (f i),
{ apply stationary_point_spec, apply le_max_left, apply le_refl },
have hpg : padic_norm p (g (stationary_point hg)) = padic_norm p (g i),
{ apply stationary_point_spec, apply le_max_right, apply le_refl },
rw [hpf, hpg, h]
end
lemma norm_neg (a : padic_seq p) : (-a).norm = a.norm :=
norm_eq $ by simp
lemma norm_eq_of_add_equiv_zero {f g : padic_seq p} (h : f + g β 0) : f.norm = g.norm :=
have lim_zero (f + g - 0), from h,
have f β -g, from show lim_zero (f - (-g)), by simpa,
have f.norm = (-g).norm, from norm_equiv this,
by simpa [norm_neg] using this
lemma add_eq_max_of_ne {f g : padic_seq p} (hfgne : f.norm β g.norm) :
(f + g).norm = max f.norm g.norm :=
have hfg : Β¬f + g β 0, from mt norm_eq_of_add_equiv_zero hfgne,
if hf : f β 0 then
have lim_zero (f - 0), from hf,
have f + g β g, from show lim_zero ((f + g) - g), by simpa,
have h1 : (f+g).norm = g.norm, from norm_equiv this,
have h2 : f.norm = 0, from (norm_zero_iff _).2 hf,
by rw [h1, h2]; rw max_eq_right (norm_nonneg _)
else if hg : g β 0 then
have lim_zero (g - 0), from hg,
have f + g β f, from show lim_zero ((f + g) - f), by rw [add_sub_cancel']; simpa,
have h1 : (f+g).norm = f.norm, from norm_equiv this,
have h2 : g.norm = 0, from (norm_zero_iff _).2 hg,
by rw [h1, h2]; rw max_eq_left (norm_nonneg _)
else
begin
unfold norm at β’ hfgne, split_ifs at β’ hfgne,
padic_index_simp [hfg, hf, hg] at β’ hfgne,
apply padic_norm.add_eq_max_of_ne,
simpa [hf, hg, norm] using hfgne
end
end embedding
end padic_seq
/-- The p-adic numbers `Q_[p]` are the Cauchy completion of `β` with respect to the p-adic norm. -/
def padic (p : β) [nat.prime p] := @cau_seq.completion.Cauchy _ _ _ _ (padic_norm p) _
notation `β_[` p `]` := padic p
namespace padic
section completion
variables {p : β} [nat.prime p]
/-- The discrete field structure on β_p is inherited from the Cauchy completion construction. -/
instance field : field (β_[p]) :=
cau_seq.completion.field
instance : inhabited β_[p] := β¨0β©
-- short circuits
instance : has_zero β_[p] := by apply_instance
instance : has_one β_[p] := by apply_instance
instance : has_add β_[p] := by apply_instance
instance : has_mul β_[p] := by apply_instance
instance : has_sub β_[p] := by apply_instance
instance : has_neg β_[p] := by apply_instance
instance : has_div β_[p] := by apply_instance
instance : add_comm_group β_[p] := by apply_instance
instance : comm_ring β_[p] := by apply_instance
/-- Builds the equivalence class of a Cauchy sequence of rationals. -/
def mk : padic_seq p β β_[p] := quotient.mk
end completion
section completion
variables (p : β) [nat.prime p]
lemma mk_eq {f g : padic_seq p} : mk f = mk g β f β g := quotient.eq
/-- Embeds the rational numbers in the p-adic numbers. -/
def of_rat : β β β_[p] := cau_seq.completion.of_rat
@[simp] lemma of_rat_add : β (x y : β), of_rat p (x + y) = of_rat p x + of_rat p y :=
cau_seq.completion.of_rat_add
@[simp] lemma of_rat_neg : β (x : β), of_rat p (-x) = -of_rat p x :=
cau_seq.completion.of_rat_neg
@[simp] lemma of_rat_mul : β (x y : β), of_rat p (x * y) = of_rat p x * of_rat p y :=
cau_seq.completion.of_rat_mul
@[simp] lemma of_rat_sub : β (x y : β), of_rat p (x - y) = of_rat p x - of_rat p y :=
cau_seq.completion.of_rat_sub
@[simp] lemma of_rat_div : β (x y : β), of_rat p (x / y) = of_rat p x / of_rat p y :=
cau_seq.completion.of_rat_div
@[simp] lemma of_rat_one : of_rat p 1 = 1 := rfl
@[simp] lemma of_rat_zero : of_rat p 0 = 0 := rfl
@[simp] lemma cast_eq_of_rat_of_nat (n : β) : (βn : β_[p]) = of_rat p n :=
begin
induction n with n ih,
{ refl },
{ simpa using ih }
end
-- without short circuits, this needs an increase of class.instance_max_depth
@[simp] lemma cast_eq_of_rat_of_int (n : β€) : βn = of_rat p n :=
by induction n; simp
lemma cast_eq_of_rat : β (q : β), (βq : β_[p]) = of_rat p q
| β¨n, d, h1, h2β© :=
show βn / βd = _, from
have (β¨n, d, h1, h2β© : β) = rat.mk n d, from rat.num_denom',
by simp [this, rat.mk_eq_div, of_rat_div]
@[norm_cast] lemma coe_add : β {x y : β}, (β(x + y) : β_[p]) = βx + βy := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_neg : β {x : β}, (β(-x) : β_[p]) = -βx := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_mul : β {x y : β}, (β(x * y) : β_[p]) = βx * βy := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_sub : β {x y : β}, (β(x - y) : β_[p]) = βx - βy := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_div : β {x y : β}, (β(x / y) : β_[p]) = βx / βy := by simp [cast_eq_of_rat]
@[norm_cast] lemma coe_one : (β1 : β_[p]) = 1 := rfl
@[norm_cast] lemma coe_zero : (β0 : β_[p]) = 0 := rfl
lemma const_equiv {q r : β} : const (padic_norm p) q β const (padic_norm p) r β q = r :=
β¨ Ξ» heq : lim_zero (const (padic_norm p) (q - r)),
eq_of_sub_eq_zero $ const_lim_zero.1 heq,
Ξ» heq, by rw heq; apply setoid.refl _ β©
lemma of_rat_eq {q r : β} : of_rat p q = of_rat p r β q = r :=
β¨(const_equiv p).1 β quotient.eq.1, Ξ» h, by rw hβ©
@[norm_cast] lemma coe_inj {q r : β} : (βq : β_[p]) = βr β q = r :=
by simp [cast_eq_of_rat, of_rat_eq]
instance : char_zero β_[p] :=
β¨Ξ» m n, by { rw β rat.cast_coe_nat, norm_cast, exact id }β©
end completion
end padic
/-- The rational-valued p-adic norm on β_p is lifted from the norm on Cauchy sequences. The
canonical form of this function is the normed space instance, with notation `β₯ β₯`. -/
def padic_norm_e {p : β} [hp : nat.prime p] : β_[p] β β :=
quotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _
namespace padic_norm_e
section embedding
open padic_seq
variables {p : β} [nat.prime p]
lemma defn (f : padic_seq p) {Ξ΅ : β} (hΞ΅ : Ξ΅ > 0) : β N, β i β₯ N, padic_norm_e (β¦fβ§ - f i) < Ξ΅ :=
begin
simp only [padic.cast_eq_of_rat],
change β N, β i β₯ N, (f - const _ (f i)).norm < Ξ΅,
by_contradiction h,
cases cauchyβ f hΞ΅ with N hN,
have : β N, β i β₯ N, (f - const _ (f i)).norm β₯ Ξ΅,
by simpa [not_forall] using h,
rcases this N with β¨i, hi, hgeβ©,
have hne : Β¬ (f - const (padic_norm p) (f i)) β 0,
{ intro h, unfold padic_seq.norm at hge; split_ifs at hge, exact not_lt_of_ge hge hΞ΅ },
unfold padic_seq.norm at hge; split_ifs at hge,
apply not_le_of_gt _ hge,
cases decidable.em ((stationary_point hne) β₯ N) with hgen hngen,
{ apply hN; assumption },
{ have := stationary_point_spec hne (le_refl _) (le_of_not_le hngen),
rw βthis,
apply hN,
apply le_refl, assumption }
end
protected lemma nonneg (q : β_[p]) : padic_norm_e q β₯ 0 :=
quotient.induction_on q $ norm_nonneg
lemma zero_def : (0 : β_[p]) = β¦0β§ := rfl
lemma zero_iff (q : β_[p]) : padic_norm_e q = 0 β q = 0 :=
quotient.induction_on q $
by simpa only [zero_def, quotient.eq] using norm_zero_iff
@[simp] protected lemma zero : padic_norm_e (0 : β_[p]) = 0 :=
(zero_iff _).2 rfl
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`β₯ β₯`). -/
@[simp] protected lemma one' : padic_norm_e (1 : β_[p]) = 1 :=
norm_one
@[simp] protected lemma neg (q : β_[p]) : padic_norm_e (-q) = padic_norm_e q :=
quotient.induction_on q $ norm_neg
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`β₯ β₯`). -/
theorem nonarchimedean' (q r : β_[p]) :
padic_norm_e (q + r) β€ max (padic_norm_e q) (padic_norm_e r) :=
quotient.induction_onβ q r $ norm_nonarchimedean
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`β₯ β₯`). -/
theorem add_eq_max_of_ne' {q r : β_[p]} :
padic_norm_e q β padic_norm_e r β padic_norm_e (q + r) = max (padic_norm_e q) (padic_norm_e r) :=
quotient.induction_onβ q r $ Ξ» _ _, padic_seq.add_eq_max_of_ne
lemma triangle_ineq (x y z : β_[p]) :
padic_norm_e (x - z) β€ padic_norm_e (x - y) + padic_norm_e (y - z) :=
calc padic_norm_e (x - z) = padic_norm_e ((x - y) + (y - z)) : by rw sub_add_sub_cancel
... β€ max (padic_norm_e (x - y)) (padic_norm_e (y - z)) : padic_norm_e.nonarchimedean' _ _
... β€ padic_norm_e (x - y) + padic_norm_e (y - z) :
max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)
protected lemma add (q r : β_[p]) : padic_norm_e (q + r) β€ (padic_norm_e q) + (padic_norm_e r) :=
calc
padic_norm_e (q + r) β€ max (padic_norm_e q) (padic_norm_e r) : nonarchimedean' _ _
... β€ (padic_norm_e q) + (padic_norm_e r) :
max_le_add_of_nonneg (padic_norm_e.nonneg _) (padic_norm_e.nonneg _)
protected lemma mul' (q r : β_[p]) : padic_norm_e (q * r) = (padic_norm_e q) * (padic_norm_e r) :=
quotient.induction_onβ q r $ norm_mul
instance : is_absolute_value (@padic_norm_e p _) :=
{ abv_nonneg := padic_norm_e.nonneg,
abv_eq_zero := zero_iff,
abv_add := padic_norm_e.add,
abv_mul := padic_norm_e.mul' }
@[simp] lemma eq_padic_norm' (q : β) : padic_norm_e (padic.of_rat p q) = padic_norm p q :=
norm_const _
protected theorem image' {q : β_[p]} : q β 0 β β n : β€, padic_norm_e q = p ^ (-n) :=
quotient.induction_on q $ Ξ» f hf,
have Β¬ f β 0, from (ne_zero_iff_nequiv_zero f).1 hf,
norm_image f this
lemma sub_rev (q r : β_[p]) : padic_norm_e (q - r) = padic_norm_e (r - q) :=
by rw β(padic_norm_e.neg); simp
end embedding
end padic_norm_e
namespace padic
section complete
open padic_seq padic
theorem rat_dense' {p : β} [nat.prime p] (q : β_[p]) {Ξ΅ : β} (hΞ΅ : Ξ΅ > 0) :
β r : β, padic_norm_e (q - r) < Ξ΅ :=
quotient.induction_on q $ Ξ» q',
have β N, β m n β₯ N, padic_norm p (q' m - q' n) < Ξ΅, from cauchyβ _ hΞ΅,
let β¨N, hNβ© := this in
β¨q' N,
begin
simp only [padic.cast_eq_of_rat],
change padic_seq.norm (q' - const _ (q' N)) < Ξ΅,
cases decidable.em ((q' - const (padic_norm p) (q' N)) β 0) with heq hne',
{ simpa only [heq, padic_seq.norm, dif_pos] },
{ simp only [padic_seq.norm, dif_neg hne'],
change padic_norm p (q' _ - q' _) < Ξ΅,
have := stationary_point_spec hne',
cases decidable.em (N β₯ stationary_point hne') with hle hle,
{ have := eq.symm (this (le_refl _) hle),
simp at this, simpa [this] },
{ apply hN,
apply le_of_lt, apply lt_of_not_ge, apply hle, apply le_refl }}
endβ©
variables {p : β} [nat.prime p] (f : cau_seq _ (@padic_norm_e p _))
open classical
private lemma div_nat_pos (n : β) : (1 / ((n + 1): β)) > 0 :=
div_pos zero_lt_one (by exact_mod_cast succ_pos _)
def lim_seq : β β β := Ξ» n, classical.some (rat_dense' (f n) (div_nat_pos n))
lemma exi_rat_seq_conv {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) :
β N, β i β₯ N, padic_norm_e (f i - ((lim_seq f) i : β_[p])) < Ξ΅ :=
begin
refine (exists_nat_gt (1/Ξ΅)).imp (Ξ» N hN i hi, _),
have h := classical.some_spec (rat_dense' (f i) (div_nat_pos i)),
refine lt_of_lt_of_le h (div_le_of_le_mul (by exact_mod_cast succ_pos _) _),
rw right_distrib,
apply le_add_of_le_of_nonneg,
{ exact le_mul_of_div_le hΞ΅ (le_trans (le_of_lt hN) (by exact_mod_cast hi)) },
{ apply le_of_lt, simpa }
end
lemma exi_rat_seq_conv_cauchy : is_cau_seq (padic_norm p) (lim_seq f) :=
assume Ξ΅ hΞ΅,
have hΞ΅3 : Ξ΅ / 3 > 0, from div_pos hΞ΅ (by norm_num),
let β¨N, hNβ© := exi_rat_seq_conv f hΞ΅3,
β¨N2, hN2β© := f.cauchyβ hΞ΅3 in
begin
existsi max N N2,
intros j hj,
suffices : padic_norm_e ((β(lim_seq f j) - f (max N N2)) + (f (max N N2) - lim_seq f (max N N2))) < Ξ΅,
{ ring at this β’,
rw [β padic_norm_e.eq_padic_norm', β padic.cast_eq_of_rat],
exact_mod_cast this },
{ apply lt_of_le_of_lt,
{ apply padic_norm_e.add },
{ have : (3 : β) β 0, by norm_num,
have : Ξ΅ = Ξ΅ / 3 + Ξ΅ / 3 + Ξ΅ / 3,
{ apply eq_of_mul_eq_mul_left this, simp [left_distrib, mul_div_cancel' _ this ], ring },
rw this,
apply add_lt_add,
{ suffices : padic_norm_e ((β(lim_seq f j) - f j) + (f j - f (max N N2))) < Ξ΅ / 3 + Ξ΅ / 3,
by simpa [sub_eq_add_neg],
apply lt_of_le_of_lt,
{ apply padic_norm_e.add },
{ apply add_lt_add,
{ rw [padic_norm_e.sub_rev],
apply_mod_cast hN,
exact le_of_max_le_left hj },
{ apply hN2,
exact le_of_max_le_right hj,
apply le_max_right }}},
{ apply_mod_cast hN,
apply le_max_left }}}
end
private def lim' : padic_seq p := β¨_, exi_rat_seq_conv_cauchy fβ©
private def lim : β_[p] := β¦lim' fβ§
theorem complete' : β q : β_[p], β Ξ΅ > 0, β N, β i β₯ N, padic_norm_e (q - f i) < Ξ΅ :=
β¨ lim f,
Ξ» Ξ΅ hΞ΅,
let β¨N, hNβ© := exi_rat_seq_conv f (show Ξ΅ / 2 > 0, from div_pos hΞ΅ (by norm_num)),
β¨N2, hN2β© := padic_norm_e.defn (lim' f) (show Ξ΅ / 2 > 0, from div_pos hΞ΅ (by norm_num)) in
begin
existsi max N N2,
intros i hi,
suffices : padic_norm_e ((lim f - lim' f i) + (lim' f i - f i)) < Ξ΅,
{ ring at this; exact this },
{ apply lt_of_le_of_lt,
{ apply padic_norm_e.add },
{ have : Ξ΅ = Ξ΅ / 2 + Ξ΅ / 2, by rw β(add_self_div_two Ξ΅); simp,
rw this,
apply add_lt_add,
{ apply hN2, exact le_of_max_le_right hi },
{ rw_mod_cast [padic_norm_e.sub_rev],
apply hN,
exact le_of_max_le_left hi }}}
end β©
end complete
section normed_space
variables (p : β) [nat.prime p]
instance : has_dist β_[p] := β¨Ξ» x y, padic_norm_e (x - y)β©
instance : metric_space β_[p] :=
{ dist_self := by simp [dist],
dist_comm := Ξ» x y, by unfold dist; rw βpadic_norm_e.neg (x - y); simp,
dist_triangle :=
begin
intros, unfold dist,
exact_mod_cast padic_norm_e.triangle_ineq _ _ _,
end,
eq_of_dist_eq_zero :=
begin
unfold dist, intros _ _ h,
apply eq_of_sub_eq_zero,
apply (padic_norm_e.zero_iff _).1,
exact_mod_cast h
end }
instance : has_norm β_[p] := β¨Ξ» x, padic_norm_e xβ©
instance : normed_field β_[p] :=
{ dist_eq := Ξ» _ _, rfl,
norm_mul' := by simp [has_norm.norm, padic_norm_e.mul'] }
instance : is_absolute_value (Ξ» a : β_[p], β₯aβ₯) :=
{ abv_nonneg := norm_nonneg,
abv_eq_zero := Ξ» _, norm_eq_zero,
abv_add := norm_add_le,
abv_mul := by simp [has_norm.norm, padic_norm_e.mul'] }
theorem rat_dense {p : β} {hp : p.prime} (q : β_[p]) {Ξ΅ : β} (hΞ΅ : Ξ΅ > 0) :
β r : β, β₯q - rβ₯ < Ξ΅ :=
let β¨Ξ΅', hΞ΅'l, hΞ΅'rβ© := exists_rat_btwn hΞ΅,
β¨r, hrβ© := rat_dense' q (by simpa using hΞ΅'l) in
β¨r, lt.trans (by simpa [has_norm.norm] using hr) hΞ΅'rβ©
end normed_space
end padic
namespace padic_norm_e
section normed_space
variables {p : β} [hp : p.prime]
include hp
@[simp] protected lemma mul (q r : β_[p]) : β₯q * rβ₯ = β₯qβ₯ * β₯rβ₯ :=
by simp [has_norm.norm, padic_norm_e.mul']
protected lemma is_norm (q : β_[p]) : β(padic_norm_e q) = β₯qβ₯ := rfl
theorem nonarchimedean (q r : β_[p]) : β₯q + rβ₯ β€ max (β₯qβ₯) (β₯rβ₯) :=
begin
unfold has_norm.norm,
exact_mod_cast nonarchimedean' _ _
end
theorem add_eq_max_of_ne {q r : β_[p]} (h : β₯qβ₯ β β₯rβ₯) : β₯q+rβ₯ = max (β₯qβ₯) (β₯rβ₯) :=
begin
unfold has_norm.norm,
apply_mod_cast add_eq_max_of_ne',
intro h',
apply h,
unfold has_norm.norm,
exact_mod_cast h'
end
@[simp] lemma eq_padic_norm (q : β) : β₯(βq : β_[p])β₯ = padic_norm p q :=
begin
unfold has_norm.norm,
rw [β padic_norm_e.eq_padic_norm', β padic.cast_eq_of_rat]
end
instance : nondiscrete_normed_field β_[p] :=
{ non_trivial := β¨padic.of_rat p (pβ»ΒΉ), begin
have h0 : p β 0 := ne_of_gt (hp.pos),
have h1 : 1 < p := hp.one_lt,
rw [β padic.cast_eq_of_rat, eq_padic_norm],
simp only [padic_norm, inv_eq_zero],
simp only [if_neg] {discharger := `[exact_mod_cast h0]},
norm_cast,
simp only [padic_val_rat.inv] {discharger := `[exact_mod_cast h0]},
rw [neg_neg, padic_val_rat.padic_val_rat_self h1],
erw _root_.pow_one,
exact_mod_cast h1,
endβ© }
protected theorem image {q : β_[p]} : q β 0 β β n : β€, β₯qβ₯ = β((βp : β) ^ (-n)) :=
quotient.induction_on q $ Ξ» f hf,
have Β¬ f β 0, from (padic_seq.ne_zero_iff_nequiv_zero f).1 hf,
let β¨n, hnβ© := padic_seq.norm_image f this in
β¨n, congr_arg coe hnβ©
protected lemma is_rat (q : β_[p]) : β q' : β, β₯qβ₯ = βq' :=
if h : q = 0 then β¨0, by simp [h]β©
else let β¨n, hnβ© := padic_norm_e.image h in β¨_, hnβ©
def rat_norm (q : β_[p]) : β := classical.some (padic_norm_e.is_rat q)
lemma eq_rat_norm (q : β_[p]) : β₯qβ₯ = rat_norm q := classical.some_spec (padic_norm_e.is_rat q)
theorem norm_rat_le_one : β {q : β} (hq : Β¬ p β£ q.denom), β₯(q : β_[p])β₯ β€ 1
| β¨n, d, hn, hdβ© := Ξ» hq : Β¬ p β£ d,
if hnz : n = 0 then
have (β¨n, d, hn, hdβ© : β) = 0,
from rat.zero_iff_num_zero.mpr hnz,
by norm_num [this]
else
begin
have hnz' : {rat . num := n, denom := d, pos := hn, cop := hd} β 0, from mt rat.zero_iff_num_zero.1 hnz,
rw [padic_norm_e.eq_padic_norm],
norm_cast,
rw [padic_norm.eq_fpow_of_nonzero p hnz', padic_val_rat_def p hnz'],
have h : (multiplicity p d).get _ = 0, by simp [multiplicity_eq_zero_of_not_dvd, hq],
simp only [], norm_cast,
rw_mod_cast [h, sub_zero],
apply fpow_le_one_of_nonpos,
{ exact_mod_cast le_of_lt hp.one_lt, },
{ apply neg_nonpos_of_nonneg, norm_cast, simp, }
end
lemma eq_of_norm_add_lt_right {p : β} {hp : p.prime} {z1 z2 : β_[p]}
(h : β₯z1 + z2β₯ < β₯z2β₯) : β₯z1β₯ = β₯z2β₯ :=
by_contradiction $ Ξ» hne,
not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_right) h
lemma eq_of_norm_add_lt_left {p : β} {hp : p.prime} {z1 z2 : β_[p]}
(h : β₯z1 + z2β₯ < β₯z1β₯) : β₯z1β₯ = β₯z2β₯ :=
by_contradiction $ Ξ» hne,
not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_left) h
end normed_space
end padic_norm_e
namespace padic
variables {p : β} [nat.prime p]
set_option eqn_compiler.zeta true
instance complete : cau_seq.is_complete β_[p] norm :=
begin
split, intro f,
have cau_seq_norm_e : is_cau_seq padic_norm_e f,
{ intros Ξ΅ hΞ΅,
let h := is_cau f Ξ΅ (by exact_mod_cast hΞ΅),
unfold norm at h,
apply_mod_cast h },
cases padic.complete' β¨f, cau_seq_norm_eβ© with q hq,
existsi q,
intros Ξ΅ hΞ΅,
cases exists_rat_btwn hΞ΅ with Ξ΅' hΞ΅',
norm_cast at hΞ΅',
cases hq Ξ΅' hΞ΅'.1 with N hN, existsi N,
intros i hi, let h := hN i hi,
unfold norm,
rw_mod_cast [cau_seq.sub_apply, padic_norm_e.sub_rev],
refine lt.trans _ hΞ΅'.2,
exact_mod_cast hN i hi
end
lemma padic_norm_e_lim_le {f : cau_seq β_[p] norm} {a : β} (ha : a > 0)
(hf : β i, β₯f iβ₯ β€ a) : β₯f.limβ₯ β€ a :=
let β¨N, hNβ© := setoid.symm (cau_seq.equiv_lim f) _ ha in
calc β₯f.limβ₯ = β₯f.lim - f N + f Nβ₯ : by simp
... β€ max (β₯f.lim - f Nβ₯) (β₯f Nβ₯) : padic_norm_e.nonarchimedean _ _
... β€ a : max_le (le_of_lt (hN _ (le_refl _))) (hf _)
end padic
|
21f998ee795d380c50a78f776f87df58d8695ed1
|
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
|
/tests/lean/mvar_fvar.lean
|
0f7a2dc08e9b2cbdfb038bd01ac9a377143652b2
|
[
"Apache-2.0"
] |
permissive
|
WojciechKarpiel/lean4
|
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
|
f6e1314fa08293dea66a329e05b6c196a0189163
|
refs/heads/master
| 1,686,633,402,214
| 1,625,821,189,000
| 1,625,821,258,000
| 384,640,886
| 0
| 0
|
Apache-2.0
| 1,625,903,617,000
| 1,625,903,026,000
| null |
UTF-8
|
Lean
| false
| false
| 275
|
lean
|
import Lean
open Lean
#eval (mkFVar `a).hasFVar
#eval (mkApp (mkConst `foo) (mkFVar `a)).hasFVar
#eval (mkApp (mkConst `foo) (mkConst `a)).hasFVar
#eval (mkMVar `a).hasMVar
#eval (mkApp (mkConst `foo) (mkMVar `a)).hasMVar
#eval (mkApp (mkConst `foo) (mkConst `a)).hasMVar
|
44d606278900424e69734374ee4240dc50c68cc3
|
ad3e8f15221a986da27c99f371922c0b3f5792b6
|
/src/week05/solutions/e01_matroids.lean
|
cf128164eaacb9ecb4494c65caa49786b18f5ac0
|
[] |
no_license
|
VArtem/lean-itmo
|
a0e1424c8cc4c2de2ac85ab6fd4a12d80e9b85f1
|
dc44cd06f9f5b984d051831b3aaa7364e64c2dc4
|
refs/heads/main
| 1,683,761,214,467
| 1,622,821,295,000
| 1,622,821,295,000
| 357,236,048
| 12
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 14,629
|
lean
|
import data.finset
import data.fintype.basic
import tactic
import week05.solutions.e00_intro
open finset
structure matroid (Ξ± : Type*) [fintype Ξ±] [decidable_eq Ξ±] :=
(ind : set (finset Ξ±))
(ind_empty : ind β
)
(ind_subset : β β¦A Bβ¦, A β B β ind B β ind A)
(ind_exchange : β (A B : finset Ξ±), ind A β ind B β A.card < B.card β
(β (c β B), (c β A) β§ ind (insert c A)))
namespace matroid
attribute [simp] matroid.ind_empty
variables {Ξ± : Type} [fintype Ξ±] [decidable_eq Ξ±] {A B X : finset Ξ±} {m : matroid Ξ±}
-- ΠΠΎΠΏΡΠΎΠ±ΡΠΉΡΠ΅ Π΄ΠΎΠΊΠ°Π·Π°ΡΡ Π² term mode
lemma dep_superset {A B} : A β B β Β¬m.ind A β Β¬m.ind B := Ξ» h hA hB, hA (m.ind_subset h hB)
-- ΠΠ°Π·ΠΎΠΉ ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²Π° A Π½Π°Π·ΡΠ²Π°Π΅ΡΡΡ Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎΠ΅ ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²ΠΎ B, ΡΡΠΎ B β A, ΠΈ Π΄Π»Ρ Π»ΡΠ±ΠΎΠ³ΠΎ x β A \ B, B βͺ {x} Π·Π°Π²ΠΈΡΠΈΠΌΠΎ
-- x β A \ B - Π½Π΅ΡΠ΄ΠΎΠ±Π½ΠΎΠ΅ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅, ΠΏΠΎΡΠΎΠΌΡ ΡΡΠΎ Π²Π΅Π·Π΄Π΅ ΠΏΡΠΈΠ΄Π΅ΡΡΡ ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΡΠ²Π°ΡΡ mem_sdiff
-- ΠΠ½Π°Π»ΠΎΠ³ΠΈΡΠ½ΠΎ, Π΄Π»Ρ Π²ΡΡΠ°Π²ΠΊΠΈ x Π² B Π΅ΡΡΡ `insert x B`
def base_of (m : matroid Ξ±) (X A : finset Ξ±) := A β X β§ m.ind A β§ β x β X, x β A β Β¬m.ind (insert x A)
lemma base_of_ind : m.base_of X A β m.ind A := Ξ» h, h.2.1
lemma base_of_subset : m.base_of X A β A β X := Ξ» h, h.1
lemma base_of_dep_of_insert {x} : m.base_of X A β x β X β x β A β Β¬m.ind (insert x A) := Ξ» h hX hA, h.2.2 x hX hA
-- ΠΠ°Π·Π° ΠΌΠ°ΡΡΠΎΠΈΠ΄Π° - Π°Π½Π°Π»ΠΎΠ³ΠΈΡΠ½ΠΎ, Π½ΠΎ Π±Π΅Π· ΠΎΠ³ΡΠ°Π½ΠΈΡΠ΅Π½ΠΈΡ Π½Π° ΠΏΠΎΠ΄ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²ΠΎ
def base (m : matroid Ξ±) (B : finset Ξ±) := m.ind B β§ β x β B, Β¬m.ind (insert x B)
lemma base_ind : m.base A β m.ind A := Ξ» h, h.1
@[simp] lemma base_of_univ_iff_base {A : finset Ξ±} : m.base_of univ A β m.base A :=
β¨Ξ» β¨_, h_ind, h_insβ©, β¨h_ind, Ξ» x hx, h_ins x (mem_univ _) hxβ©,
Ξ» β¨h_ind, h_insβ©, β¨subset_univ A, h_ind, Ξ» x _ hx, h_ins x hxβ©β©
-- Π‘Π΅ΠΊΡΠΈΡ Ρ Π΄ΠΎΠΊΠ°Π·Π°ΡΠ΅Π»ΡΡΡΠ²Π°ΠΌΠΈ ΠΏΡΠΎ `base_of`
section base_of
-- A Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎ ΡΠΎΠ³Π΄Π° ΠΈ ΡΠΎΠ»ΡΠΊΠΎ ΡΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° A - Π±Π°Π·Π° A
lemma ind_iff_base_of_self : m.ind A β m.base_of A A :=
begin
refine β¨Ξ» Aind, _, base_of_indβ©,
refine β¨subset.refl _, Aind, Ξ» x hx hnx, absurd hx hnxβ©,
end
-- ΠΡΠ΅ Π±Π°Π·Ρ ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²Π° ΡΠ°Π²Π½ΠΎΠΌΠΎΡΠ½Ρ
-- ΠΡΠΏΠΎΠΌΠ½ΠΈΡΠ΅/ΠΏΠΎΠ΄ΡΠΌΠ°ΠΉΡΠ΅ ΠΏΡΠΎ ΠΌΠ°ΡΠ΅ΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΎΠ΅ Π΄ΠΎΠΊΠ°Π·Π°ΡΠ΅Π»ΡΡΡΠ²ΠΎ
lemma base_of_card_eq (hA : m.base_of X A) (hB : m.base_of X B) : A.card = B.card :=
begin
by_contradiction hne,
wlog h : A.card < B.card := lt_or_gt_of_ne hne using [A B, B A],
obtain β¨w, wB, wA, winsertβ© := m.ind_exchange _ _ (base_of_ind hA) (base_of_ind hB) h,
refine base_of_dep_of_insert hA (base_of_subset hB wB) wA winsert,
end
-- ΠΡΠ±ΠΎΠ΅ Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎΠ΅ ΠΏΠΎΠ΄ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²ΠΎ X ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΡΡΡΠΎΠΈΡΡ Π΄ΠΎ Π±Π°Π·Ρ X
-- `by_contradiction` Π΄ΠΎΠΊΠ°Π·ΡΠ²Π°Π΅Ρ ΡΠ΅Π»Ρ ΠΎΡ ΠΏΡΠΎΡΠΈΠ²Π½ΠΎΠ³ΠΎ
-- `push_neg` ΠΏΡΠΎΡΠ°Π»ΠΊΠΈΠ²Π°Π΅Ρ ΠΎΡΡΠΈΡΠ°Π½ΠΈΡ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎ Π²Π½ΡΡΡΡ ΡΡΠ²Π΅ΡΠΆΠ΄Π΅Π½ΠΈΡ ΠΈΠ»ΠΈ ΡΠ΅Π»ΠΈ
-- Π’Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ ΠΏΠΎΠΌΠΎΡΡ `nat.le_induction`
#check @nat.le_induction
lemma exists_base_of_superset_of_ind : A β X β m.ind A β β B, A β B β§ m.base_of X B :=
begin
intros hAX hA,
by_contradiction,
push_neg at h,
suffices ind_unbounded : β k β₯ A.card, β B, A β B β§ B β X β§ m.ind B β§ B.card = k, {
replace hAX := card_le_of_subset hAX,
rcases ind_unbounded (X.card + 1) (by linarith) with β¨B, -, hBX, -, Bcardβ©,
replace hBX := card_le_of_subset hBX,
linarith,
},
apply nat.le_induction, {
use [A, subset.refl A, hAX, hA],
}, {
rintro n Acard β¨B, hAB, hBX, Bind, rflβ©,
specialize h B hAB,
rw base_of at h,
push_neg at h,
rcases h hBX Bind with β¨w, wX, wB, w_insertβ©,
use [insert w B],
use [subset.trans hAB (subset_insert _ _)],
use [insert_subset.2 β¨wX, hBXβ©],
use [w_insert, card_insert_of_not_mem wB],
}
end
-- Π£ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΏΠΎΠ΄ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²Π° X ΡΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ Π±Π°Π·Π°
theorem exists_base_of (m : matroid Ξ±) (X : finset Ξ±): β A, m.base_of X A :=
begin
obtain β¨B, _, Bbaseβ© := exists_base_of_superset_of_ind (empty_subset X) m.ind_empty,
exact β¨B, Bbaseβ©,
end
-- ΠΠΎΡΠ½ΠΎΡΡΡ Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎΠ³ΠΎ ΠΏΠΎΠ΄ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²Π° A β X Π½Π΅ Π±ΠΎΠ»ΡΡΠ΅ ΠΌΠΎΡΠ½ΠΎΡΡΠΈ Π±Π°Π·Ρ X
lemma ind_card_le_base_of_card : A β X β m.ind A β m.base_of X B β A.card β€ B.card :=
begin
intros hAX Aind Bbase,
obtain β¨T, hAT, Tbaseβ© := exists_base_of_superset_of_ind hAX Aind,
rw base_of_card_eq Bbase Tbase,
exact card_le_of_subset hAT,
end
end base_of
-- Π’Π΅ΠΎΡΠ΅ΠΌΠ° ΠΎ Π±Π°Π·Π°Ρ
ΠΌΠ°ΡΡΠΎΠΈΠ΄Π°
section base
lemma base_eq_card (hA : m.base A) (hB : m.base B) : A.card = B.card :=
by {rw [βbase_of_univ_iff_base] at *, exact base_of_card_eq hA hB}
lemma ind_subset_base (hA : m.ind A) : β B, A β B β§ m.base B :=
begin
obtain β¨B, hAB, h_baseβ© := exists_base_of_superset_of_ind (subset_univ A) hA,
rw base_of_univ_iff_base at h_base,
use [B, hAB, h_base],
end
theorem exists_base : β A, m.base A :=
begin
obtain β¨B, _, Bbaseβ© := ind_subset_base m.ind_empty,
exact β¨B, Bbaseβ©,
end
theorem base_not_subset {A B} : m.base A β m.base B β A β B β A = B :=
begin
rintro Abase Bbase h_subset,
exact eq_of_subset_of_card_le h_subset (ge_of_eq $ base_eq_card Abase Bbase),
end
lemma ind_and_card_eq_card_base_iff_base {A B} (Abase : m.base A) : (m.ind B β§ A.card = B.card) β m.base B :=
begin
split, {
rintro β¨Bind, Acardβ©,
use Bind,
intros x xB h_insert_ind,
obtain β¨C, Bsubset, Cbaseβ© := ind_subset_base h_insert_ind,
replace Bsubset := card_le_of_subset Bsubset,
rw [base_eq_card Abase Cbase] at Acard,
rw card_insert_of_not_mem xB at Bsubset,
linarith,
}, {
intro Bbase,
exact β¨base_ind Bbase, base_eq_card Abase Bbaseβ©,
}
end
-- ΠΠΎΡΠΈΡΠ°ΠΉΡΠ΅ ΠΏΡΠΎ ΡΠ°ΠΊΡΠΈΠΊΡ `finish`: https://leanprover-community.github.io/mathlib_docs/tactics.html#finish%20/%20clarify%20/%20safe
theorem base_exchange {A B} : m.base A β m.base B β β x β A \ B, β b β (B \ A), m.base (insert b (A.erase x)) :=
begin
intros Abase Bbase x xA,
rcases m.ind_exchange (A.erase x) B _ Bbase.1 _ with β¨c, cB, cA, cinsertβ©,
{
use c,
rw mem_sdiff at β’ xA,
use [cB],
{
finish,
}, {
apply (ind_and_card_eq_card_base_iff_base Abase).1,
use cinsert,
rw [card_insert_of_not_mem cA, card_erase_of_mem' xA.1],
},
}, {
exact m.ind_subset (erase_subset _ _) (base_ind Abase),
}, {
rw mem_sdiff at xA,
rw [β base_eq_card Abase Bbase, card_erase_of_mem xA.1],
exact nat.pred_lt (card_ne_zero_of_mem xA.1),
},
end
end base
-- Π¦ΠΈΠΊΠ» ΠΌΠ°ΡΡΠΎΠΈΠ΄Π° ΡΡΠΎ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ΅ ΠΏΠΎ Π²ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΠ΅ ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²ΠΎ
def circuit (m : matroid Ξ±) (A : finset Ξ±) := Β¬ m.ind A β§ β x β A, m.ind (A.erase x)
section circuit
theorem not_circuit : Β¬ m.circuit β
:= Ξ» β¨empty_dep, _β©, empty_dep m.ind_empty
lemma circuit_ssubset : m.circuit A β B β A β m.ind B :=
begin
rintro β¨Anind, Aeraseβ© Bsubset,
rw ssubset_iff at Bsubset,
rcases Bsubset with β¨x, xB, x_insertβ©,
rw insert_subset at x_insert,
cases x_insert with xA h_subset,
apply m.ind_subset _ (Aerase x xA),
rw β erase_eq_of_not_mem xB,
exact erase_subset_erase x h_subset,
end
theorem circuit_not_subset {A B} : m.circuit A β m.circuit B β A β B β A = B :=
begin
rintro Acirc Bcirc h_subset,
cases @lt_or_eq_of_le _ _ A B h_subset, {
exfalso,
exact Acirc.1 (circuit_ssubset Bcirc h),
}, {
exact h,
}
end
-- Π§ΡΠΎΠ±Ρ Π΄ΠΎΠΊΠ°Π·Π°ΡΡ ΡΡΡ Π»Π΅ΠΌΠΌΡ ΠΎΡ ΠΏΡΠΎΡΠΈΠ²Π½ΠΎΠ³ΠΎ, Π½ΡΠΆΠ½ΠΎ Π΄ΠΎΠΊΠ°Π·Π°ΡΡ ΡΡΠ²Π΅ΡΠΆΠ΄Π΅Π½ΠΈΠ΅ Π²ΠΈΠ΄Π°
-- "ΠΡΠ»ΠΈ A Π·Π°Π²ΠΈΡΠΈΠΌΠΎ ΠΈ Ρ Π½Π΅Π³ΠΎ Π½Π΅Ρ ΠΏΠΎΠ΄ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²-ΡΠΈΠΊΠ»ΠΎΠ²,
-- ΡΠΎ Π΄Π»Ρ Π²ΡΠ΅Ρ
k ΠΎΡ 0 Π΄ΠΎ |A| ΡΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΠ΅ ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΠ° k"
-- ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ Ρ ΡΠ΅ΠΊΠΎΠΌΠ΅Π½Π΄ΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΠΈΠ½Π΄ΡΠΊΡΠΈΡ ΠΏΠΎ ΡΠ±ΡΠ²Π°Π½ΠΈΡ k
-- Π mathlib ΡΡΠΎ nat.decreasing_induction
lemma ind_iff_no_circuit_subset (A) : m.ind A β β C β A, Β¬m.circuit C :=
begin
split, {
intros Aind C hCA Ccirc,
refine dep_superset hCA (Ccirc.1) Aind,
}, {
intros h,
by_contradiction Aind,
suffices subsets_dep : β k β€ A.card, β B β A, B.card = k β§ Β¬ m.ind B, {
obtain β¨B, Bsub, Bcard, Bdepβ© := subsets_dep 0 (zero_le _),
apply Bdep,
convert m.ind_empty,
rwa card_eq_zero at Bcard,
},
intros k k_le_card,
refine nat.decreasing_induction _ k_le_card _, {
rintro n β¨B, hBA, Bcard, Bdepβ©,
specialize h B hBA,
rw circuit at h,
push_neg at h,
obtain β¨x, xAB, h_dep_eraseβ© := h Bdep,
refine β¨B.erase x, subset.trans (erase_subset _ _) hBA, _, h_dep_eraseβ©,
rw β card_erase_of_mem' xAB at Bcard,
exact add_right_cancel Bcard,
}, {
use [A, subset.refl _, rfl],
}
}
end
lemma dep_iff_contains_circuit (A) : Β¬ m.ind A β β C β A, m.circuit C :=
begin
convert (not_congr $ ind_iff_no_circuit_subset A),
simp,
end
end circuit
-- ΠΡΡΡ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠΏΠΎΡΠΎΠ±ΠΎΠ² ΠΎΠΏΡΠ΅Π΄Π΅Π»ΠΈΡΡ ΡΠ°Π½Π³ΠΎΠ²ΡΡ ΡΡΠ½ΠΊΡΠΈΡ Π² ΠΌΠ°ΡΡΠΎΠΈΠ΄Π΅
-- Π― Π²ΡΠ±ΡΠ°Π» ΡΠ»Π΅Π΄ΡΡΡΠΈΠΉ: Π²ΠΎΠ·ΡΠΌΠ΅ΠΌ Π²ΡΠ΅ Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΡΠ΅ ΠΏΠΎΠ΄ΠΌΠ½ΠΎΠΆΠ΅ΡΡΠ²Π° A ΠΈ Π²ΠΎΠ·ΡΠΌΠ΅ΠΌ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΡ ΠΌΠΎΡΠ½ΠΎΡΡΡ ΡΡΠ΅Π΄ΠΈ Π½ΠΈΡ
-- ΠΠ»Ρ ΡΠ°ΠΊΠΎΠ³ΠΎ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΡ Π½ΡΠΆΠ½ΠΎ, ΡΡΠΎΠ±Ρ ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° Π½Π° Π½Π΅Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΡ Π² ΠΌΠ°ΡΡΠΎΠΈΠ΄Π΅ Π±ΡΠ»Π° ΡΠ°Π·ΡΠ΅ΡΠΈΠΌΠΎΠΉ
variable [decidable_pred m.ind]
def rank (m : matroid Ξ±) [decidable_pred m.ind] (A : finset Ξ±) : β := sup (filter m.ind (powerset A)) card
section rank
@[simp] lemma rank_def : rank m A = sup (filter m.ind (powerset A)) card := rfl
@[simp] lemma rank_empty : rank m β
= 0 :=
begin
rw rank,
simp only [card_empty, filter_true_of_mem, ind_empty, forall_eq, powerset_empty, sup_singleton, mem_singleton],
end
-- ΠΡΠ»ΠΈ B - Π±Π°Π·Π° A, ΡΠΎ ΡΠ°Π½Π³ Π ΡΠ°Π²Π΅Π½ ΠΌΠΎΡΠ½ΠΎΡΡΠΈ B
-- ΠΠ΅ΠΌΠΌΡ ΠΏΡΠΎ `sup` Π·Π΄Π΅ΡΡ ΠΏΠΎΠ»Π΅Π·Π½Ρ: `finset.sup_le` ΠΈ `le_sup`
lemma rank_eq_base_of_card (Bbase : m.base_of A B) : rank m A = B.card :=
begin
rw rank_def,
apply nat.le_antisymm, {
apply finset.sup_le,
intros C hC,
rw [mem_filter, mem_powerset] at hC,
exact ind_card_le_base_of_card hC.1 hC.2 Bbase,
}, {
apply le_sup,
rw [mem_filter, mem_powerset],
exact β¨base_of_subset Bbase, base_of_ind Bbaseβ©,
}
end
lemma rank_exists_base_of (m : matroid Ξ±) [decidable_pred m.ind] (A : finset Ξ±) :
β (B : finset Ξ±), m.rank A = B.card β§ m.base_of A B :=
begin
obtain β¨B, Bbaseβ© := exists_base_of m A,
refine β¨B, rank_eq_base_of_card Bbase, Bbaseβ©,
end
theorem rank_le_card : rank m A β€ A.card :=
begin
obtain β¨bA, bAcard, bAbaseβ© := rank_exists_base_of m A,
rw bAcard,
exact card_le_of_subset bAbase.1,
end
@[simp] lemma rank_le_of_subset (hAB : A β B) : rank m A β€ rank m B :=
begin
obtain β¨bA, bAbaseβ© := exists_base_of m A,
obtain β¨bB, bBbaseβ© := exists_base_of m B,
rw rank_eq_base_of_card bAbase,
rw rank_eq_base_of_card bBbase,
refine ind_card_le_base_of_card (subset.trans bAbase.1 hAB) bAbase.2.1 bBbase,
end
@[simp] lemma rank_ind : rank m A = A.card β m.ind A :=
begin
split, {
intro h_card,
obtain β¨B, Bcard, Bbaseβ© := rank_exists_base_of m A,
rw h_card at Bcard,
suffices h_eq : A = B, {
subst h_eq,
exact Bbase.2.1,
},
symmetry,
exact eq_of_subset_of_card_le Bbase.1 (le_of_eq Bcard),
}, {
intro Aind,
rw [ind_iff_base_of_self] at Aind,
rw rank_eq_base_of_card Aind,
}
end
lemma not_mem_sdiff_iff {x : Ξ±} {A B : finset Ξ±} : x β A \ B β x β A β¨ x β B :=
begin
rw not_iff_comm,
push_neg,
simp only [mem_sdiff, iff_self],
end
lemma card_sdiff_β€ {A B : finset Ξ±} (hAB : A β B) : ((B \ A).card : β€) = (B.card : β€) - A.card :=
begin
suffices h : (B \ A).card + A.card = B.card, {
linarith,
},
rw [card_sdiff hAB, nat.sub_add_cancel (card_le_of_subset hAB)],
end
-- Π‘Π»ΠΎΠΆΠ½ΡΠΉ ΡΠΈΠ½Π°Π»ΡΠ½ΡΠΉ Π±ΠΎΡΡ!
-- http://neerc.ifmo.ru/wiki/index.php?title=%D0%A0%D0%B0%D0%BD%D0%B3%D0%BE%D0%B2%D0%B0%D1%8F_%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F,_%D0%BF%D0%BE%D0%BB%D1%83%D0%BC%D0%BE%D0%B4%D1%83%D0%BB%D1%8F%D1%80%D0%BD%D0%BE%D1%81%D1%82%D1%8C
theorem rank_submodular : m.rank (A β© B) + m.rank (A βͺ B) β€ m.rank A + m.rank B :=
begin
obtain β¨bInter, bInter_baseβ© := exists_base_of m (A β© B),
have rankInter := rank_eq_base_of_card bInter_base,
obtain β¨bA, bA_sub, bA_baseβ© := exists_base_of_superset_of_ind (subset.trans bInter_base.1 (inter_subset_left _ _)) (bInter_base.2.1),
have rankA := rank_eq_base_of_card bA_base,
obtain β¨bUnion, bUnion_sub, bUnion_baseβ© :=
exists_base_of_superset_of_ind (subset.trans bA_base.1 (subset_union_left A B)) bA_base.2.1,
have rankUnion := rank_eq_base_of_card bUnion_base,
obtain β¨bB, bB_baseβ© := exists_base_of m B,
have rankB := rank_eq_base_of_card bB_base,
have indB_sub : (bUnion \ (bA \ bInter)) β B := by {
intros x hx,
rw [mem_sdiff, not_mem_sdiff_iff] at hx,
rcases hx with β¨xBunion, xA | xInterβ©, {
have xAB := bUnion_base.1 xBunion,
cases (mem_union.1 xAB), {
exfalso,
have h_insert_dep := bA_base.2.2 _ h xA,
refine h_insert_dep (m.ind_subset _ (bUnion_base.2.1)),
rw β insert_eq_of_mem xBunion,
refine insert_subset_insert x bUnion_sub,
}, {
exact h,
}
}, {
exact mem_of_mem_inter_right (bInter_base.1 xInter),
},
},
have indB_ind : m.ind (bUnion \ (bA \ bInter)) := m.ind_subset (sdiff_subset _ _) bUnion_base.2.1,
have indB_card_le := ind_card_le_base_of_card indB_sub indB_ind bB_base,
have indB_card : (bUnion \ (bA \ bInter)).card + bA.card = bUnion.card + bInter.card := by {
zify,
rw card_sdiff_β€ (subset.trans (sdiff_subset bA bInter) bUnion_sub),
rw card_sdiff_β€ bA_sub,
ring,
},
rw [rankInter, rankA, rankUnion, rankB],
linarith,
end
end rank
end matroid
|
014208cb96a653d15f6f56cab50a14701be9f62e
|
a46270e2f76a375564f3b3e9c1bf7b635edc1f2c
|
/3-5.lean
|
1b8085565b5d34dbebd20a440430f08ac7cff467
|
[
"CC0-1.0"
] |
permissive
|
wudcscheme/lean-exercise
|
88ea2506714eac343de2a294d1132ee8ee6d3a20
|
5b23b9be3d361fff5e981d5be3a0a1175504b9f6
|
refs/heads/master
| 1,678,958,930,293
| 1,583,197,205,000
| 1,583,197,205,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 195
|
lean
|
open classical
variable p: Prop
#check em p
theorem dne {p: Prop} (h: Β¬ Β¬ p) : p :=
(em p).elim
(assume hp: p, hp)
(assume hnp: Β¬ p, absurd hnp h)
#check by_cases
|
ed3354917836e6f26d711abf9abb94a58e0f2684
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/data/sum/order.lean
|
fa415e8e8a7f4c698d62ce79a44e224e45f6688b
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 24,237
|
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.hom.basic
/-!
# Orders on a sum type
This file defines the disjoint sum and the linear (aka lexicographic) sum of two orders and provides
relation instances for `sum.lift_rel` and `sum.lex`.
We declare the disjoint sum of orders as the default set of instances. The linear order goes on a
type synonym.
## Main declarations
* `sum.has_le`, `sum.has_lt`: Disjoint sum of orders.
* `sum.lex.has_le`, `sum.lex.has_lt`: Lexicographic/linear sum of orders.
## Notation
* `Ξ± ββ Ξ²`: The linear sum of `Ξ±` and `Ξ²`.
-/
variables {Ξ± Ξ² Ξ³ Ξ΄ : Type*}
namespace sum
/-! ### Unbundled relation classes -/
section lift_rel
variables (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop)
@[refl] lemma lift_rel.refl [is_refl Ξ± r] [is_refl Ξ² s] : β x, lift_rel r s x x
| (inl a) := lift_rel.inl (refl _)
| (inr a) := lift_rel.inr (refl _)
instance [is_refl Ξ± r] [is_refl Ξ² s] : is_refl (Ξ± β Ξ²) (lift_rel r s) := β¨lift_rel.refl _ _β©
instance [is_irrefl Ξ± r] [is_irrefl Ξ² s] : is_irrefl (Ξ± β Ξ²) (lift_rel r s) :=
β¨by { rintro _ (β¨a, _, hβ© | β¨a, _, hβ©); exact irrefl _ h }β©
@[trans] lemma lift_rel.trans [is_trans Ξ± r] [is_trans Ξ² s] :
β {a b c}, lift_rel r s a b β lift_rel r s b c β lift_rel r s a c
| _ _ _ (lift_rel.inl hab) (lift_rel.inl hbc) := lift_rel.inl $ trans hab hbc
| _ _ _ (lift_rel.inr hab) (lift_rel.inr hbc) := lift_rel.inr $ trans hab hbc
instance [is_trans Ξ± r] [is_trans Ξ² s] : is_trans (Ξ± β Ξ²) (lift_rel r s) :=
β¨Ξ» _ _ _, lift_rel.trans _ _β©
instance [is_antisymm Ξ± r] [is_antisymm Ξ² s] : is_antisymm (Ξ± β Ξ²) (lift_rel r s) :=
β¨by { rintro _ _ (β¨a, b, habβ© | β¨a, b, habβ©) (β¨_, _, hbaβ© | β¨_, _, hbaβ©); rw antisymm hab hba }β©
end lift_rel
section lex
variables (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop)
instance [is_refl Ξ± r] [is_refl Ξ² s] : is_refl (Ξ± β Ξ²) (lex r s) :=
β¨by { rintro (a | a), exacts [lex.inl (refl _), lex.inr (refl _)] }β©
instance [is_irrefl Ξ± r] [is_irrefl Ξ² s] : is_irrefl (Ξ± β Ξ²) (lex r s) :=
β¨by { rintro _ (β¨a, _, hβ© | β¨a, _, hβ©); exact irrefl _ h }β©
instance [is_trans Ξ± r] [is_trans Ξ² s] : is_trans (Ξ± β Ξ²) (lex r s) :=
β¨by { rintro _ _ _ (β¨a, b, habβ© | β¨a, b, habβ©) (β¨_, c, hbcβ© | β¨_, c, hbcβ©),
exacts [lex.inl (trans hab hbc), lex.sep _ _, lex.inr (trans hab hbc), lex.sep _ _] }β©
instance [is_antisymm Ξ± r] [is_antisymm Ξ² s] : is_antisymm (Ξ± β Ξ²) (lex r s) :=
β¨by { rintro _ _ (β¨a, b, habβ© | β¨a, b, habβ©) (β¨_, _, hbaβ© | β¨_, _, hbaβ©); rw antisymm hab hba }β©
instance [is_total Ξ± r] [is_total Ξ² s] : is_total (Ξ± β Ξ²) (lex r s) :=
β¨Ξ» a b, match a, b with
| inl a, inl b := (total_of r a b).imp lex.inl lex.inl
| inl a, inr b := or.inl (lex.sep _ _)
| inr a, inl b := or.inr (lex.sep _ _)
| inr a, inr b := (total_of s a b).imp lex.inr lex.inr
endβ©
instance [is_trichotomous Ξ± r] [is_trichotomous Ξ² s] : is_trichotomous (Ξ± β Ξ²) (lex r s) :=
β¨Ξ» a b, match a, b with
| inl a, inl b := (trichotomous_of r a b).imp3 lex.inl (congr_arg _) lex.inl
| inl a, inr b := or.inl (lex.sep _ _)
| inr a, inl b := or.inr (or.inr $ lex.sep _ _)
| inr a, inr b := (trichotomous_of s a b).imp3 lex.inr (congr_arg _) lex.inr
endβ©
instance [is_well_order Ξ± r] [is_well_order Ξ² s] : is_well_order (Ξ± β Ξ²) (sum.lex r s) :=
{ wf := sum.lex_wf is_well_founded.wf is_well_founded.wf }
end lex
/-! ### Disjoint sum of two orders -/
section disjoint
instance [has_le Ξ±] [has_le Ξ²] : has_le (Ξ± β Ξ²) := β¨lift_rel (β€) (β€)β©
instance [has_lt Ξ±] [has_lt Ξ²] : has_lt (Ξ± β Ξ²) := β¨lift_rel (<) (<)β©
lemma le_def [has_le Ξ±] [has_le Ξ²] {a b : Ξ± β Ξ²} : a β€ b β lift_rel (β€) (β€) a b := iff.rfl
lemma lt_def [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ± β Ξ²} : a < b β lift_rel (<) (<) a b := iff.rfl
@[simp] lemma inl_le_inl_iff [has_le Ξ±] [has_le Ξ²] {a b : Ξ±} : (inl a : Ξ± β Ξ²) β€ inl b β a β€ b :=
lift_rel_inl_inl
@[simp] lemma inr_le_inr_iff [has_le Ξ±] [has_le Ξ²] {a b : Ξ²} : (inr a : Ξ± β Ξ²) β€ inr b β a β€ b :=
lift_rel_inr_inr
@[simp] lemma inl_lt_inl_iff [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ±} : (inl a : Ξ± β Ξ²) < inl b β a < b :=
lift_rel_inl_inl
@[simp] lemma inr_lt_inr_iff [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ²} : (inr a : Ξ± β Ξ²) < inr b β a < b :=
lift_rel_inr_inr
@[simp] lemma not_inl_le_inr [has_le Ξ±] [has_le Ξ²] {a : Ξ±} {b : Ξ²} : Β¬ inl b β€ inr a :=
not_lift_rel_inl_inr
@[simp] lemma not_inl_lt_inr [has_lt Ξ±] [has_lt Ξ²] {a : Ξ±} {b : Ξ²} : Β¬ inl b < inr a :=
not_lift_rel_inl_inr
@[simp] lemma not_inr_le_inl [has_le Ξ±] [has_le Ξ²] {a : Ξ±} {b : Ξ²} : Β¬ inr b β€ inl a :=
not_lift_rel_inr_inl
@[simp] lemma not_inr_lt_inl [has_lt Ξ±] [has_lt Ξ²] {a : Ξ±} {b : Ξ²} : Β¬ inr b < inl a :=
not_lift_rel_inr_inl
section preorder
variables [preorder Ξ±] [preorder Ξ²]
instance : preorder (Ξ± β Ξ²) :=
{ le_refl := Ξ» _, refl _,
le_trans := Ξ» _ _ _, trans,
lt_iff_le_not_le := Ξ» a b, begin
refine β¨Ξ» hab, β¨hab.mono (Ξ» _ _, le_of_lt) (Ξ» _ _, le_of_lt), _β©, _β©,
{ rintro (β¨b, a, hbaβ© | β¨b, a, hbaβ©),
{ exact hba.not_lt (inl_lt_inl_iff.1 hab) },
{ exact hba.not_lt (inr_lt_inr_iff.1 hab) } },
{ rintro β¨β¨a, b, habβ© | β¨a, b, habβ©, hbaβ©,
{ exact lift_rel.inl (hab.lt_of_not_le $ Ξ» h, hba $ lift_rel.inl h) },
{ exact lift_rel.inr (hab.lt_of_not_le $ Ξ» h, hba $ lift_rel.inr h) } }
end,
.. sum.has_le, .. sum.has_lt }
lemma inl_mono : monotone (inl : Ξ± β Ξ± β Ξ²) := Ξ» a b, lift_rel.inl
lemma inr_mono : monotone (inr : Ξ² β Ξ± β Ξ²) := Ξ» a b, lift_rel.inr
lemma inl_strict_mono : strict_mono (inl : Ξ± β Ξ± β Ξ²) := Ξ» a b, lift_rel.inl
lemma inr_strict_mono : strict_mono (inr : Ξ² β Ξ± β Ξ²) := Ξ» a b, lift_rel.inr
end preorder
instance [partial_order Ξ±] [partial_order Ξ²] : partial_order (Ξ± β Ξ²) :=
{ le_antisymm := Ξ» _ _, antisymm,
.. sum.preorder }
instance no_min_order [has_lt Ξ±] [has_lt Ξ²] [no_min_order Ξ±] [no_min_order Ξ²] :
no_min_order (Ξ± β Ξ²) :=
β¨Ξ» a, match a with
| inl a := let β¨b, hβ© := exists_lt a in β¨inl b, inl_lt_inl_iff.2 hβ©
| inr a := let β¨b, hβ© := exists_lt a in β¨inr b, inr_lt_inr_iff.2 hβ©
endβ©
instance no_max_order [has_lt Ξ±] [has_lt Ξ²] [no_max_order Ξ±] [no_max_order Ξ²] :
no_max_order (Ξ± β Ξ²) :=
β¨Ξ» a, match a with
| inl a := let β¨b, hβ© := exists_gt a in β¨inl b, inl_lt_inl_iff.2 hβ©
| inr a := let β¨b, hβ© := exists_gt a in β¨inr b, inr_lt_inr_iff.2 hβ©
endβ©
@[simp] lemma no_min_order_iff [has_lt Ξ±] [has_lt Ξ²] :
no_min_order (Ξ± β Ξ²) β no_min_order Ξ± β§ no_min_order Ξ² :=
β¨Ξ» _, by exactI β¨β¨Ξ» a, begin
obtain β¨b | b, hβ© := exists_lt (inl a : Ξ± β Ξ²),
{ exact β¨b, inl_lt_inl_iff.1 hβ© },
{ exact (not_inr_lt_inl h).elim }
endβ©, β¨Ξ» a, begin
obtain β¨b | b, hβ© := exists_lt (inr a : Ξ± β Ξ²),
{ exact (not_inl_lt_inr h).elim },
{ exact β¨b, inr_lt_inr_iff.1 hβ© }
endβ©β©, Ξ» h, @sum.no_min_order _ _ _ _ h.1 h.2β©
@[simp] lemma no_max_order_iff [has_lt Ξ±] [has_lt Ξ²] :
no_max_order (Ξ± β Ξ²) β no_max_order Ξ± β§ no_max_order Ξ² :=
β¨Ξ» _, by exactI β¨β¨Ξ» a, begin
obtain β¨b | b, hβ© := exists_gt (inl a : Ξ± β Ξ²),
{ exact β¨b, inl_lt_inl_iff.1 hβ© },
{ exact (not_inl_lt_inr h).elim }
endβ©, β¨Ξ» a, begin
obtain β¨b | b, hβ© := exists_gt (inr a : Ξ± β Ξ²),
{ exact (not_inr_lt_inl h).elim },
{ exact β¨b, inr_lt_inr_iff.1 hβ© }
endβ©β©, Ξ» h, @sum.no_max_order _ _ _ _ h.1 h.2β©
instance densely_ordered [has_lt Ξ±] [has_lt Ξ²] [densely_ordered Ξ±] [densely_ordered Ξ²] :
densely_ordered (Ξ± β Ξ²) :=
β¨Ξ» a b h, match a, b, h with
| inl a, inl b, lift_rel.inl h := let β¨c, ha, hbβ© := exists_between h in
β¨to_lex (inl c), lift_rel.inl ha, lift_rel.inl hbβ©
| inr a, inr b, lift_rel.inr h := let β¨c, ha, hbβ© := exists_between h in
β¨to_lex (inr c), lift_rel.inr ha, lift_rel.inr hbβ©
endβ©
@[simp] lemma densely_ordered_iff [has_lt Ξ±] [has_lt Ξ²] :
densely_ordered (Ξ± β Ξ²) β densely_ordered Ξ± β§ densely_ordered Ξ² :=
β¨Ξ» _, by exactI β¨β¨Ξ» a b h, begin
obtain β¨c | c, ha, hbβ© := @exists_between (Ξ± β Ξ²) _ _ _ _ (inl_lt_inl_iff.2 h),
{ exact β¨c, inl_lt_inl_iff.1 ha, inl_lt_inl_iff.1 hbβ© },
{ exact (not_inl_lt_inr ha).elim }
endβ©, β¨Ξ» a b h, begin
obtain β¨c | c, ha, hbβ© := @exists_between (Ξ± β Ξ²) _ _ _ _ (inr_lt_inr_iff.2 h),
{ exact (not_inl_lt_inr hb).elim },
{ exact β¨c, inr_lt_inr_iff.1 ha, inr_lt_inr_iff.1 hbβ© }
endβ©β©, Ξ» h, @sum.densely_ordered _ _ _ _ h.1 h.2β©
@[simp] lemma swap_le_swap_iff [has_le Ξ±] [has_le Ξ²] {a b : Ξ± β Ξ²} : a.swap β€ b.swap β a β€ b :=
lift_rel_swap_iff
@[simp] lemma swap_lt_swap_iff [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ± β Ξ²} : a.swap < b.swap β a < b :=
lift_rel_swap_iff
end disjoint
/-! ### Linear sum of two orders -/
namespace lex
notation Ξ± ` ββ `:30 Ξ²:29 := _root_.lex (Ξ± β Ξ²)
--TODO: Can we make `inlβ`, `inrβ` `local notation`?
/-- Lexicographical `sum.inl`. Only used for pattern matching. -/
@[pattern] abbreviation _root_.sum.inlβ (x : Ξ±) : Ξ± ββ Ξ² := to_lex (sum.inl x)
/-- Lexicographical `sum.inr`. Only used for pattern matching. -/
@[pattern] abbreviation _root_.sum.inrβ (x : Ξ²) : Ξ± ββ Ξ² := to_lex (sum.inr x)
/-- The linear/lexicographical `β€` on a sum. -/
instance has_le [has_le Ξ±] [has_le Ξ²] : has_le (Ξ± ββ Ξ²) := β¨lex (β€) (β€)β©
/-- The linear/lexicographical `<` on a sum. -/
instance has_lt [has_lt Ξ±] [has_lt Ξ²] : has_lt (Ξ± ββ Ξ²) := β¨lex (<) (<)β©
@[simp] lemma to_lex_le_to_lex [has_le Ξ±] [has_le Ξ²] {a b : Ξ± β Ξ²} :
to_lex a β€ to_lex b β lex (β€) (β€) a b := iff.rfl
@[simp] lemma to_lex_lt_to_lex [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ± β Ξ²} :
to_lex a < to_lex b β lex (<) (<) a b := iff.rfl
lemma le_def [has_le Ξ±] [has_le Ξ²] {a b : Ξ± ββ Ξ²} : a β€ b β lex (β€) (β€) (of_lex a) (of_lex b) :=
iff.rfl
lemma lt_def [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ± ββ Ξ²} : a < b β lex (<) (<) (of_lex a) (of_lex b) :=
iff.rfl
@[simp] lemma inl_le_inl_iff [has_le Ξ±] [has_le Ξ²] {a b : Ξ±} :
to_lex (inl a : Ξ± β Ξ²) β€ to_lex (inl b) β a β€ b :=
lex_inl_inl
@[simp] lemma inr_le_inr_iff [has_le Ξ±] [has_le Ξ²] {a b : Ξ²} :
to_lex (inr a : Ξ± β Ξ²) β€ to_lex (inr b) β a β€ b :=
lex_inr_inr
@[simp] lemma inl_lt_inl_iff [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ±} :
to_lex (inl a : Ξ± β Ξ²) < to_lex (inl b) β a < b :=
lex_inl_inl
@[simp] lemma inr_lt_inr_iff [has_lt Ξ±] [has_lt Ξ²] {a b : Ξ²} :
to_lex (inr a : Ξ± ββ Ξ²) < to_lex (inr b) β a < b :=
lex_inr_inr
@[simp] lemma inl_le_inr [has_le Ξ±] [has_le Ξ²] (a : Ξ±) (b : Ξ²) : to_lex (inl a) β€ to_lex (inr b) :=
lex.sep _ _
@[simp] lemma inl_lt_inr [has_lt Ξ±] [has_lt Ξ²] (a : Ξ±) (b : Ξ²) : to_lex (inl a) < to_lex (inr b) :=
lex.sep _ _
@[simp] lemma not_inr_le_inl [has_le Ξ±] [has_le Ξ²] {a : Ξ±} {b : Ξ²} :
Β¬ to_lex (inr b) β€ to_lex (inl a) :=
lex_inr_inl
@[simp] lemma not_inr_lt_inl [has_lt Ξ±] [has_lt Ξ²] {a : Ξ±} {b : Ξ²} :
Β¬ to_lex (inr b) < to_lex (inl a) :=
lex_inr_inl
section preorder
variables [preorder Ξ±] [preorder Ξ²]
instance preorder : preorder (Ξ± ββ Ξ²) :=
{ le_refl := refl_of (lex (β€) (β€)),
le_trans := Ξ» _ _ _, trans_of (lex (β€) (β€)),
lt_iff_le_not_le := Ξ» a b, begin
refine β¨Ξ» hab, β¨hab.mono (Ξ» _ _, le_of_lt) (Ξ» _ _, le_of_lt), _β©, _β©,
{ rintro (β¨b, a, hbaβ© | β¨b, a, hbaβ© | β¨b, aβ©),
{ exact hba.not_lt (inl_lt_inl_iff.1 hab) },
{ exact hba.not_lt (inr_lt_inr_iff.1 hab) },
{ exact not_inr_lt_inl hab } },
{ rintro β¨β¨a, b, habβ© | β¨a, b, habβ© | β¨a, bβ©, hbaβ©,
{ exact lex.inl (hab.lt_of_not_le $ Ξ» h, hba $ lex.inl h) },
{ exact lex.inr (hab.lt_of_not_le $ Ξ» h, hba $ lex.inr h) },
{ exact lex.sep _ _} }
end,
.. lex.has_le, .. lex.has_lt }
lemma to_lex_mono : monotone (@to_lex (Ξ± β Ξ²)) := Ξ» a b h, h.lex
lemma to_lex_strict_mono : strict_mono (@to_lex (Ξ± β Ξ²)) := Ξ» a b h, h.lex
lemma inl_mono : monotone (to_lex β inl : Ξ± β Ξ± ββ Ξ²) := to_lex_mono.comp inl_mono
lemma inr_mono : monotone (to_lex β inr : Ξ² β Ξ± ββ Ξ²) := to_lex_mono.comp inr_mono
lemma inl_strict_mono : strict_mono (to_lex β inl : Ξ± β Ξ± ββ Ξ²) :=
to_lex_strict_mono.comp inl_strict_mono
lemma inr_strict_mono : strict_mono (to_lex β inr : Ξ² β Ξ± ββ Ξ²) :=
to_lex_strict_mono.comp inr_strict_mono
end preorder
instance partial_order [partial_order Ξ±] [partial_order Ξ²] : partial_order (Ξ± ββ Ξ²) :=
{ le_antisymm := Ξ» _ _, antisymm_of (lex (β€) (β€)),
.. lex.preorder }
instance linear_order [linear_order Ξ±] [linear_order Ξ²] : linear_order (Ξ± ββ Ξ²) :=
{ le_total := total_of (lex (β€) (β€)),
decidable_le := lex.decidable_rel,
decidable_eq := sum.decidable_eq _ _,
.. lex.partial_order }
/-- The lexicographical bottom of a sum is the bottom of the left component. -/
instance order_bot [has_le Ξ±] [order_bot Ξ±] [has_le Ξ²] : order_bot (Ξ± ββ Ξ²) :=
{ bot := inl β₯,
bot_le := begin
rintro (a | b),
{ exact lex.inl bot_le },
{ exact lex.sep _ _ }
end }
@[simp] lemma inl_bot [has_le Ξ±] [order_bot Ξ±] [has_le Ξ²]: to_lex (inl β₯ : Ξ± β Ξ²) = β₯ := rfl
/-- The lexicographical top of a sum is the top of the right component. -/
instance order_top [has_le Ξ±] [has_le Ξ²] [order_top Ξ²] : order_top (Ξ± ββ Ξ²) :=
{ top := inr β€,
le_top := begin
rintro (a | b),
{ exact lex.sep _ _ },
{ exact lex.inr le_top }
end }
@[simp] lemma inr_top [has_le Ξ±] [has_le Ξ²] [order_top Ξ²] : to_lex (inr β€ : Ξ± β Ξ²) = β€ := rfl
instance bounded_order [has_le Ξ±] [has_le Ξ²] [order_bot Ξ±] [order_top Ξ²] :
bounded_order (Ξ± ββ Ξ²) :=
{ .. lex.order_bot, .. lex.order_top }
instance no_min_order [has_lt Ξ±] [has_lt Ξ²] [no_min_order Ξ±] [no_min_order Ξ²] :
no_min_order (Ξ± ββ Ξ²) :=
β¨Ξ» a, match a with
| inl a := let β¨b, hβ© := exists_lt a in β¨to_lex (inl b), inl_lt_inl_iff.2 hβ©
| inr a := let β¨b, hβ© := exists_lt a in β¨to_lex (inr b), inr_lt_inr_iff.2 hβ©
endβ©
instance no_max_order [has_lt Ξ±] [has_lt Ξ²] [no_max_order Ξ±] [no_max_order Ξ²] :
no_max_order (Ξ± ββ Ξ²) :=
β¨Ξ» a, match a with
| inl a := let β¨b, hβ© := exists_gt a in β¨to_lex (inl b), inl_lt_inl_iff.2 hβ©
| inr a := let β¨b, hβ© := exists_gt a in β¨to_lex (inr b), inr_lt_inr_iff.2 hβ©
endβ©
instance no_min_order_of_nonempty [has_lt Ξ±] [has_lt Ξ²] [no_min_order Ξ±] [nonempty Ξ±] :
no_min_order (Ξ± ββ Ξ²) :=
β¨Ξ» a, match a with
| inl a := let β¨b, hβ© := exists_lt a in β¨to_lex (inl b), inl_lt_inl_iff.2 hβ©
| inr a := β¨to_lex (inl $ classical.arbitrary Ξ±), inl_lt_inr _ _β©
endβ©
instance no_max_order_of_nonempty [has_lt Ξ±] [has_lt Ξ²] [no_max_order Ξ²] [nonempty Ξ²] :
no_max_order (Ξ± ββ Ξ²) :=
β¨Ξ» a, match a with
| inl a := β¨to_lex (inr $ classical.arbitrary Ξ²), inl_lt_inr _ _β©
| inr a := let β¨b, hβ© := exists_gt a in β¨to_lex (inr b), inr_lt_inr_iff.2 hβ©
endβ©
instance densely_ordered_of_no_max_order [has_lt Ξ±] [has_lt Ξ²] [densely_ordered Ξ±]
[densely_ordered Ξ²] [no_max_order Ξ±] :
densely_ordered (Ξ± ββ Ξ²) :=
β¨Ξ» a b h, match a, b, h with
| inl a, inl b, lex.inl h := let β¨c, ha, hbβ© := exists_between h in
β¨to_lex (inl c), inl_lt_inl_iff.2 ha, inl_lt_inl_iff.2 hbβ©
| inl a, inr b, lex.sep _ _ := let β¨c, hβ© := exists_gt a in
β¨to_lex (inl c), inl_lt_inl_iff.2 h, inl_lt_inr _ _β©
| inr a, inr b, lex.inr h := let β¨c, ha, hbβ© := exists_between h in
β¨to_lex (inr c), inr_lt_inr_iff.2 ha, inr_lt_inr_iff.2 hbβ©
endβ©
instance densely_ordered_of_no_min_order [has_lt Ξ±] [has_lt Ξ²] [densely_ordered Ξ±]
[densely_ordered Ξ²] [no_min_order Ξ²] :
densely_ordered (Ξ± ββ Ξ²) :=
β¨Ξ» a b h, match a, b, h with
| inl a, inl b, lex.inl h := let β¨c, ha, hbβ© := exists_between h in
β¨to_lex (inl c), inl_lt_inl_iff.2 ha, inl_lt_inl_iff.2 hbβ©
| inl a, inr b, lex.sep _ _ := let β¨c, hβ© := exists_lt b in
β¨to_lex (inr c), inl_lt_inr _ _, inr_lt_inr_iff.2 hβ©
| inr a, inr b, lex.inr h := let β¨c, ha, hbβ© := exists_between h in
β¨to_lex (inr c), inr_lt_inr_iff.2 ha, inr_lt_inr_iff.2 hbβ©
endβ©
end lex
end sum
/-! ### Order isomorphisms -/
open order_dual sum
namespace order_iso
variables [has_le Ξ±] [has_le Ξ²] [has_le Ξ³] (a : Ξ±) (b : Ξ²) (c : Ξ³)
/-- `equiv.sum_comm` promoted to an order isomorphism. -/
@[simps apply] def sum_comm (Ξ± Ξ² : Type*) [has_le Ξ±] [has_le Ξ²] : Ξ± β Ξ² βo Ξ² β Ξ± :=
{ map_rel_iff' := Ξ» a b, swap_le_swap_iff,
..equiv.sum_comm Ξ± Ξ² }
@[simp] lemma sum_comm_symm (Ξ± Ξ² : Type*) [has_le Ξ±] [has_le Ξ²] :
(order_iso.sum_comm Ξ± Ξ²).symm = order_iso.sum_comm Ξ² Ξ± := rfl
/-- `equiv.sum_assoc` promoted to an order isomorphism. -/
def sum_assoc (Ξ± Ξ² Ξ³ : Type*) [has_le Ξ±] [has_le Ξ²] [has_le Ξ³] : (Ξ± β Ξ²) β Ξ³ βo Ξ± β Ξ² β Ξ³ :=
{ map_rel_iff' := by { rintro ((a | a) | a) ((b | b) | b); simp },
..equiv.sum_assoc Ξ± Ξ² Ξ³ }
@[simp] lemma sum_assoc_apply_inl_inl : sum_assoc Ξ± Ξ² Ξ³ (inl (inl a)) = inl a := rfl
@[simp] lemma sum_assoc_apply_inl_inr : sum_assoc Ξ± Ξ² Ξ³ (inl (inr b)) = inr (inl b) := rfl
@[simp] lemma sum_assoc_apply_inr : sum_assoc Ξ± Ξ² Ξ³ (inr c) = inr (inr c) := rfl
@[simp] lemma sum_assoc_symm_apply_inl : (sum_assoc Ξ± Ξ² Ξ³).symm (inl a) = inl (inl a) := rfl
@[simp] lemma sum_assoc_symm_apply_inr_inl : (sum_assoc Ξ± Ξ² Ξ³).symm (inr (inl b)) = inl (inr b) :=
rfl
@[simp] lemma sum_assoc_symm_apply_inr_inr : (sum_assoc Ξ± Ξ² Ξ³).symm (inr (inr c)) = inr c := rfl
/-- `order_dual` is distributive over `β` up to an order isomorphism. -/
def sum_dual_distrib (Ξ± Ξ² : Type*) [has_le Ξ±] [has_le Ξ²] : (Ξ± β Ξ²)α΅α΅ βo Ξ±α΅α΅ β Ξ²α΅α΅ :=
{ map_rel_iff' := begin
rintro (a | a) (b | b),
{ change inl (to_dual a) β€ inl (to_dual b) β to_dual (inl a) β€ to_dual (inl b),
simp only [to_dual_le_to_dual, inl_le_inl_iff] },
{ exact iff_of_false not_inl_le_inr not_inr_le_inl },
{ exact iff_of_false not_inr_le_inl not_inl_le_inr },
{ change inr (to_dual a) β€ inr (to_dual b) β to_dual (inr a) β€ to_dual (inr b),
simp only [to_dual_le_to_dual, inr_le_inr_iff] }
end,
..equiv.refl _ }
@[simp] lemma sum_dual_distrib_inl :
sum_dual_distrib Ξ± Ξ² (to_dual (inl a)) = inl (to_dual a) := rfl
@[simp] lemma sum_dual_distrib_inr :
sum_dual_distrib Ξ± Ξ² (to_dual (inr b)) = inr (to_dual b) := rfl
@[simp] lemma sum_dual_distrib_symm_inl :
(sum_dual_distrib Ξ± Ξ²).symm (inl (to_dual a)) = to_dual (inl a) := rfl
@[simp] lemma sum_dual_distrib_symm_inr :
(sum_dual_distrib Ξ± Ξ²).symm (inr (to_dual b)) = to_dual (inr b) := rfl
/-- `equiv.sum_assoc` promoted to an order isomorphism. -/
def sum_lex_assoc (Ξ± Ξ² Ξ³ : Type*) [has_le Ξ±] [has_le Ξ²] [has_le Ξ³] : (Ξ± ββ Ξ²) ββ Ξ³ βo Ξ± ββ Ξ² ββ Ξ³ :=
{ map_rel_iff' := Ξ» a b, β¨Ξ» h, match a, b, h with
| inlβ (inlβ a), inlβ (inlβ b), lex.inl h := lex.inl $ lex.inl h
| inlβ (inlβ a), inlβ (inrβ b), lex.sep _ _ := lex.inl $ lex.sep _ _
| inlβ (inlβ a), inrβ b, lex.sep _ _ := lex.sep _ _
| inlβ (inrβ a), inlβ (inrβ b), lex.inr (lex.inl h) := lex.inl $ lex.inr h
| inlβ (inrβ a), inrβ b, lex.inr (lex.sep _ _) := lex.sep _ _
| inrβ a, inrβ b, lex.inr (lex.inr h) := lex.inr h
end, Ξ» h, match a, b, h with
| inlβ (inlβ a), inlβ (inlβ b), lex.inl (lex.inl h) := lex.inl h
| inlβ (inlβ a), inlβ (inrβ b), lex.inl (lex.sep _ _) := lex.sep _ _
| inlβ (inlβ a), inrβ b, lex.sep _ _ := lex.sep _ _
| inlβ (inrβ a), inlβ (inrβ b), lex.inl (lex.inr h) := lex.inr $ lex.inl h
| inlβ (inrβ a), inrβ b, lex.sep _ _ := lex.inr $ lex.sep _ _
| inrβ a, inrβ b, lex.inr h := lex.inr $ lex.inr h
endβ©,
..equiv.sum_assoc Ξ± Ξ² Ξ³ }
@[simp] lemma sum_lex_assoc_apply_inl_inl :
sum_lex_assoc Ξ± Ξ² Ξ³ (to_lex $ inl $ to_lex $ inl a) = to_lex (inl a) := rfl
@[simp] lemma sum_lex_assoc_apply_inl_inr :
sum_lex_assoc Ξ± Ξ² Ξ³ (to_lex $ inl $ to_lex $ inr b) = to_lex (inr $ to_lex $ inl b) := rfl
@[simp] lemma sum_lex_assoc_apply_inr :
sum_lex_assoc Ξ± Ξ² Ξ³ (to_lex $ inr c) = to_lex (inr $ to_lex $ inr c) := rfl
@[simp] lemma sum_lex_assoc_symm_apply_inl :
(sum_lex_assoc Ξ± Ξ² Ξ³).symm (inl a) = inl (inl a) := rfl
@[simp] lemma sum_lex_assoc_symm_apply_inr_inl :
(sum_lex_assoc Ξ± Ξ² Ξ³).symm (inr (inl b)) = inl (inr b) := rfl
@[simp] lemma sum_lex_assoc_symm_apply_inr_inr :
(sum_lex_assoc Ξ± Ξ² Ξ³).symm (inr (inr c)) = inr c := rfl
/-- `order_dual` is antidistributive over `ββ` up to an order isomorphism. -/
def sum_lex_dual_antidistrib (Ξ± Ξ² : Type*) [has_le Ξ±] [has_le Ξ²] : (Ξ± ββ Ξ²)α΅α΅ βo Ξ²α΅α΅ ββ Ξ±α΅α΅ :=
{ map_rel_iff' := begin
rintro (a | a) (b | b), simp,
{ change to_lex (inr $ to_dual a) β€ to_lex (inr $ to_dual b) β
to_dual (to_lex $ inl a) β€ to_dual (to_lex $ inl b),
simp only [to_dual_le_to_dual, lex.inl_le_inl_iff, lex.inr_le_inr_iff] },
{ exact iff_of_false lex.not_inr_le_inl lex.not_inr_le_inl },
{ exact iff_of_true (lex.inl_le_inr _ _) (lex.inl_le_inr _ _) },
{ change to_lex (inl $ to_dual a) β€ to_lex (inl $ to_dual b) β
to_dual (to_lex $ inr a) β€ to_dual (to_lex $ inr b),
simp only [to_dual_le_to_dual, lex.inl_le_inl_iff, lex.inr_le_inr_iff] }
end,
..equiv.sum_comm Ξ± Ξ² }
@[simp] lemma sum_lex_dual_antidistrib_inl :
sum_lex_dual_antidistrib Ξ± Ξ² (to_dual (inl a)) = inr (to_dual a) := rfl
@[simp] lemma sum_lex_dual_antidistrib_inr :
sum_lex_dual_antidistrib Ξ± Ξ² (to_dual (inr b)) = inl (to_dual b) := rfl
@[simp] lemma sum_lex_dual_antidistrib_symm_inl :
(sum_lex_dual_antidistrib Ξ± Ξ²).symm (inl (to_dual b)) = to_dual (inr b) := rfl
@[simp] lemma sum_lex_dual_antidistrib_symm_inr :
(sum_lex_dual_antidistrib Ξ± Ξ²).symm (inr (to_dual a)) = to_dual (inl a) := rfl
end order_iso
variable [has_le Ξ±]
namespace with_bot
/-- `with_bot Ξ±` is order-isomorphic to `punit ββ Ξ±`, by sending `β₯` to `punit.star` and `βa` to
`a`. -/
def order_iso_punit_sum_lex : with_bot Ξ± βo punit ββ Ξ± :=
β¨(equiv.option_equiv_sum_punit Ξ±).trans $ (equiv.sum_comm _ _).trans to_lex,
by rintro (a | _) (b | _); simp; exact not_coe_le_bot _β©
@[simp] lemma order_iso_punit_sum_lex_bot :
@order_iso_punit_sum_lex Ξ± _ β₯ = to_lex (inl punit.star) := rfl
@[simp] lemma order_iso_punit_sum_lex_coe (a : Ξ±) :
order_iso_punit_sum_lex (βa) = to_lex (inr a) := rfl
@[simp] lemma order_iso_punit_sum_lex_symm_inl (x : punit) :
(@order_iso_punit_sum_lex Ξ± _).symm (to_lex $ inl x) = β₯ := rfl
@[simp] lemma order_iso_punit_sum_lex_symm_inr (a : Ξ±) :
order_iso_punit_sum_lex.symm (to_lex $ inr a) = a := rfl
end with_bot
namespace with_top
/-- `with_top Ξ±` is order-isomorphic to `Ξ± ββ punit`, by sending `β€` to `punit.star` and `βa` to
`a`. -/
def order_iso_sum_lex_punit : with_top Ξ± βo Ξ± ββ punit :=
β¨(equiv.option_equiv_sum_punit Ξ±).trans to_lex,
by rintro (a | _) (b | _); simp; exact not_top_le_coe _β©
@[simp] lemma order_iso_sum_lex_punit_top :
@order_iso_sum_lex_punit Ξ± _ β€ = to_lex (inr punit.star) := rfl
@[simp] lemma order_iso_sum_lex_punit_coe (a : Ξ±) :
order_iso_sum_lex_punit (βa) = to_lex (inl a) := rfl
@[simp] lemma order_iso_sum_lex_punit_symm_inr (x : punit) :
(@order_iso_sum_lex_punit Ξ± _).symm (to_lex $ inr x) = β€ := rfl
@[simp] lemma order_iso_sum_lex_punit_symm_inl (a : Ξ±) :
order_iso_sum_lex_punit.symm (to_lex $ inl a) = a := rfl
end with_top
|
58c826af0d58c248a7daee15075bca28b89cb4e9
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/geometry/manifold/algebra/lie_group.lean
|
7866fc867b9a0f1065f3206f9e46d6e0cd533adf
|
[
"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
| 6,113
|
lean
|
/-
Copyright Β© 2020 NicolΓ² Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: NicolΓ² Cavalleri
-/
import geometry.manifold.algebra.monoid
/-!
# Lie groups
A Lie group is a group that is also a smooth manifold, in which the group operations of
multiplication and inversion are smooth maps. Smoothness of the group multiplication means that
multiplication is a smooth mapping of the product manifold `G` Γ `G` into `G`.
Note that, since a manifold here is not second-countable and Hausdorff a Lie group here is not
guaranteed to be second-countable (even though it can be proved it is Hausdorff). Note also that Lie
groups here are not necessarily finite dimensional.
## Main definitions and statements
* `lie_add_group I G` : a Lie additive group where `G` is a manifold on the model with corners `I`.
* `lie_group I G` : a Lie multiplicative group where `G` is a manifold on the model with
corners `I`.
* `normed_space_lie_add_group` : a normed vector space over a nontrivially normed field
is an additive Lie group.
## Implementation notes
A priori, a Lie group here is a manifold with corners.
The definition of Lie group cannot require `I : model_with_corners π E E` with the same space as the
model space and as the model vector space, as one might hope, beause in the product situation,
the model space is `model_prod E E'` and the model vector space is `E Γ E'`, which are not the same,
so the definition does not apply. Hence the definition should be more general, allowing
`I : model_with_corners π E H`.
-/
noncomputable theory
open_locale manifold
/-- A Lie (additive) group is a group and a smooth manifold at the same time in which
the addition and negation operations are smooth. -/
-- See note [Design choices about smooth algebraic structures]
@[ancestor has_smooth_add]
class lie_add_group {π : Type*} [nontrivially_normed_field π]
{H : Type*} [topological_space H]
{E : Type*} [normed_add_comm_group E] [normed_space π E] (I : model_with_corners π E H)
(G : Type*) [add_group G] [topological_space G] [charted_space H G]
extends has_smooth_add I G : Prop :=
(smooth_neg : smooth I I (Ξ» a:G, -a))
/-- A Lie group is a group and a smooth manifold at the same time in which
the multiplication and inverse operations are smooth. -/
-- See note [Design choices about smooth algebraic structures]
@[ancestor has_smooth_mul, to_additive]
class lie_group {π : Type*} [nontrivially_normed_field π]
{H : Type*} [topological_space H]
{E : Type*} [normed_add_comm_group E] [normed_space π E] (I : model_with_corners π E H)
(G : Type*) [group G] [topological_space G] [charted_space H G]
extends has_smooth_mul I G : Prop :=
(smooth_inv : smooth I I (Ξ» a:G, aβ»ΒΉ))
section lie_group
variables {π : Type*} [nontrivially_normed_field π]
{H : Type*} [topological_space H]
{E : Type*} [normed_add_comm_group E] [normed_space π E] {I : model_with_corners π E H}
{F : Type*} [normed_add_comm_group F] [normed_space π F] {J : model_with_corners π F F}
{G : Type*} [topological_space G] [charted_space H G] [group G] [lie_group I G]
{E' : Type*} [normed_add_comm_group E'] [normed_space π E']
{H' : Type*} [topological_space H'] {I' : model_with_corners π E' H'}
{M : Type*} [topological_space M] [charted_space H' M]
{E'' : Type*} [normed_add_comm_group E''] [normed_space π E'']
{H'' : Type*} [topological_space H''] {I'' : model_with_corners π E'' H''}
{M' : Type*} [topological_space M'] [charted_space H'' M']
section
variable (I)
@[to_additive]
lemma smooth_inv : smooth I I (Ξ» x : G, xβ»ΒΉ) :=
lie_group.smooth_inv
/-- A Lie group is a topological group. This is not an instance for technical reasons,
see note [Design choices about smooth algebraic structures]. -/
@[to_additive
"An additive Lie group is an additive topological group. This is not an instance for technical
reasons, see note [Design choices about smooth algebraic structures]."]
lemma topological_group_of_lie_group : topological_group G :=
{ continuous_inv := (smooth_inv I).continuous,
.. has_continuous_mul_of_smooth I }
end
@[to_additive]
lemma smooth.inv {f : M β G}
(hf : smooth I' I f) : smooth I' I (Ξ»x, (f x)β»ΒΉ) :=
(smooth_inv I).comp hf
@[to_additive]
lemma smooth_on.inv {f : M β G} {s : set M}
(hf : smooth_on I' I f s) : smooth_on I' I (Ξ»x, (f x)β»ΒΉ) s :=
(smooth_inv I).comp_smooth_on hf
@[to_additive]
lemma smooth.div {f g : M β G}
(hf : smooth I' I f) (hg : smooth I' I g) : smooth I' I (f / g) :=
by { rw div_eq_mul_inv, exact ((smooth_mul I).comp (hf.prod_mk hg.inv) : _), }
@[to_additive]
lemma smooth_on.div {f g : M β G} {s : set M}
(hf : smooth_on I' I f s) (hg : smooth_on I' I g s) : smooth_on I' I (f / g) s :=
by { rw div_eq_mul_inv, exact ((smooth_mul I).comp_smooth_on (hf.prod_mk hg.inv) : _), }
end lie_group
section prod_lie_group
/- Instance of product group -/
@[to_additive]
instance {π : Type*} [nontrivially_normed_field π] {H : Type*} [topological_space H]
{E : Type*} [normed_add_comm_group E] [normed_space π E] {I : model_with_corners π E H}
{G : Type*} [topological_space G] [charted_space H G] [group G] [lie_group I G]
{E' : Type*} [normed_add_comm_group E'] [normed_space π E']
{H' : Type*} [topological_space H'] {I' : model_with_corners π E' H'}
{G' : Type*} [topological_space G'] [charted_space H' G']
[group G'] [lie_group I' G'] :
lie_group (I.prod I') (GΓG') :=
{ smooth_inv := smooth_fst.inv.prod_mk smooth_snd.inv,
..has_smooth_mul.prod _ _ _ _ }
end prod_lie_group
/-! ### Normed spaces are Lie groups -/
instance normed_space_lie_add_group {π : Type*} [nontrivially_normed_field π]
{E : Type*} [normed_add_comm_group E] [normed_space π E] :
lie_add_group (π(π, E)) E :=
{ smooth_add := smooth_iff.2 β¨continuous_add, Ξ» x y, cont_diff_add.cont_diff_onβ©,
smooth_neg := smooth_iff.2 β¨continuous_neg, Ξ» x y, cont_diff_neg.cont_diff_onβ©,
.. model_space_smooth }
|
97cf17eae67f121bcae7f6eb0ad9a898b0a38ed3
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/measure_theory/function/simple_func_dense_lp.lean
|
93bf695847081f29e547c10a9b30aebc9252b61a
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 41,507
|
lean
|
/-
Copyright (c) 2022 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth
-/
import measure_theory.function.l1_space
import measure_theory.function.simple_func_dense
/-!
# Density of simple functions
Show that each `Lα΅` Borel measurable function can be approximated in `Lα΅` norm
by a sequence of simple functions.
## Main definitions
* `measure_theory.Lp.simple_func`, the type of `Lp` simple functions
* `coe_to_Lp`, the embedding of `Lp.simple_func E p ΞΌ` into `Lp E p ΞΌ`
## Main results
* `tendsto_approx_on_univ_Lp` (Lα΅ convergence): If `E` is a `normed_add_comm_group` and `f` is
measurable and `mem_βp` (for `p < β`), then the simple functions
`simple_func.approx_on f hf s 0 hβ n` may be considered as elements of `Lp E p ΞΌ`, and they tend
in Lα΅ to `f`.
* `Lp.simple_func.dense_embedding`: the embedding `coe_to_Lp` of the `Lp` simple functions into
`Lp` is dense.
* `Lp.simple_func.induction`, `Lp.induction`, `mem_βp.induction`, `integrable.induction`: to prove
a predicate for all elements of one of these classes of functions, it suffices to check that it
behaves correctly on simple functions.
## TODO
For `E` finite-dimensional, simple functions `Ξ± ββ E` are dense in L^β -- prove this.
## Notations
* `Ξ± ββ Ξ²` (local notation): the type of simple functions `Ξ± β Ξ²`.
* `Ξ± βββ[ΞΌ] E`: the type of `L1` simple functions `Ξ± β Ξ²`.
-/
noncomputable theory
open set function filter topological_space ennreal emetric finset
open_locale classical topological_space ennreal measure_theory big_operators
variables {Ξ± Ξ² ΞΉ E F π : Type*}
namespace measure_theory
local infixr ` ββ `:25 := simple_func
namespace simple_func
/-! ### Lp approximation by simple functions -/
section Lp
variables [measurable_space Ξ²] [measurable_space E] [normed_add_comm_group E]
[normed_add_comm_group F] {q : β} {p : ββ₯0β}
lemma nnnorm_approx_on_le [opens_measurable_space E] {f : Ξ² β E} (hf : measurable f)
{s : set E} {yβ : E} (hβ : yβ β s) [separable_space s] (x : Ξ²) (n : β) :
β₯approx_on f hf s yβ hβ n x - f xβ₯β β€ β₯f x - yββ₯β :=
begin
have := edist_approx_on_le hf hβ x n,
rw edist_comm yβ at this,
simp only [edist_nndist, nndist_eq_nnnorm] at this,
exact_mod_cast this
end
lemma norm_approx_on_yβ_le [opens_measurable_space E] {f : Ξ² β E} (hf : measurable f)
{s : set E} {yβ : E} (hβ : yβ β s) [separable_space s] (x : Ξ²) (n : β) :
β₯approx_on f hf s yβ hβ n x - yββ₯ β€ β₯f x - yββ₯ + β₯f x - yββ₯ :=
begin
have := edist_approx_on_y0_le hf hβ x n,
repeat { rw [edist_comm yβ, edist_eq_coe_nnnorm_sub] at this },
exact_mod_cast this,
end
lemma norm_approx_on_zero_le [opens_measurable_space E] {f : Ξ² β E} (hf : measurable f)
{s : set E} (hβ : (0 : E) β s) [separable_space s] (x : Ξ²) (n : β) :
β₯approx_on f hf s 0 hβ n xβ₯ β€ β₯f xβ₯ + β₯f xβ₯ :=
begin
have := edist_approx_on_y0_le hf hβ x n,
simp [edist_comm (0 : E), edist_eq_coe_nnnorm] at this,
exact_mod_cast this,
end
lemma tendsto_approx_on_Lp_snorm [opens_measurable_space E]
{f : Ξ² β E} (hf : measurable f) {s : set E} {yβ : E} (hβ : yβ β s) [separable_space s]
(hp_ne_top : p β β) {ΞΌ : measure Ξ²} (hΞΌ : βα΅ x βΞΌ, f x β closure s)
(hi : snorm (Ξ» x, f x - yβ) p ΞΌ < β) :
tendsto (Ξ» n, snorm (approx_on f hf s yβ hβ n - f) p ΞΌ) at_top (π 0) :=
begin
by_cases hp_zero : p = 0,
{ simpa only [hp_zero, snorm_exponent_zero] using tendsto_const_nhds },
have hp : 0 < p.to_real := to_real_pos hp_zero hp_ne_top,
suffices : tendsto (Ξ» n, β«β» x, β₯approx_on f hf s yβ hβ n x - f xβ₯β ^ p.to_real βΞΌ) at_top (π 0),
{ simp only [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_ne_top],
convert continuous_rpow_const.continuous_at.tendsto.comp this;
simp [_root_.inv_pos.mpr hp] },
-- We simply check the conditions of the Dominated Convergence Theorem:
-- (1) The function "`p`-th power of distance between `f` and the approximation" is measurable
have hF_meas : β n, measurable (Ξ» x, (β₯approx_on f hf s yβ hβ n x - f xβ₯β : ββ₯0β) ^ p.to_real),
{ simpa only [β edist_eq_coe_nnnorm_sub] using
Ξ» n, (approx_on f hf s yβ hβ n).measurable_bind (Ξ» y x, (edist y (f x)) ^ p.to_real)
(Ξ» y, (measurable_edist_right.comp hf).pow_const p.to_real) },
-- (2) The functions "`p`-th power of distance between `f` and the approximation" are uniformly
-- bounded, at any given point, by `Ξ» x, β₯f x - yββ₯ ^ p.to_real`
have h_bound : β n, (Ξ» x, (β₯approx_on f hf s yβ hβ n x - f xβ₯β : ββ₯0β) ^ p.to_real)
β€α΅[ΞΌ] (Ξ» x, β₯f x - yββ₯β ^ p.to_real),
{ exact Ξ» n, eventually_of_forall
(Ξ» x, rpow_le_rpow (coe_mono (nnnorm_approx_on_le hf hβ x n)) to_real_nonneg) },
-- (3) The bounding function `Ξ» x, β₯f x - yββ₯ ^ p.to_real` has finite integral
have h_fin : β«β» (a : Ξ²), β₯f a - yββ₯β ^ p.to_real βΞΌ β β€,
from (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_ne_top hi).ne,
-- (4) The functions "`p`-th power of distance between `f` and the approximation" tend pointwise
-- to zero
have h_lim : βα΅ (a : Ξ²) βΞΌ,
tendsto (Ξ» n, (β₯approx_on f hf s yβ hβ n a - f aβ₯β : ββ₯0β) ^ p.to_real) at_top (π 0),
{ filter_upwards [hΞΌ] with a ha,
have : tendsto (Ξ» n, (approx_on f hf s yβ hβ n) a - f a) at_top (π (f a - f a)),
{ exact (tendsto_approx_on hf hβ ha).sub tendsto_const_nhds },
convert continuous_rpow_const.continuous_at.tendsto.comp (tendsto_coe.mpr this.nnnorm),
simp [zero_rpow_of_pos hp] },
-- Then we apply the Dominated Convergence Theorem
simpa using tendsto_lintegral_of_dominated_convergence _ hF_meas h_bound h_fin h_lim,
end
lemma mem_βp_approx_on [borel_space E]
{f : Ξ² β E} {ΞΌ : measure Ξ²} (fmeas : measurable f) (hf : mem_βp f p ΞΌ) {s : set E} {yβ : E}
(hβ : yβ β s) [separable_space s] (hiβ : mem_βp (Ξ» x, yβ) p ΞΌ) (n : β) :
mem_βp (approx_on f fmeas s yβ hβ n) p ΞΌ :=
begin
refine β¨(approx_on f fmeas s yβ hβ n).ae_strongly_measurable, _β©,
suffices : snorm (Ξ» x, approx_on f fmeas s yβ hβ n x - yβ) p ΞΌ < β€,
{ have : mem_βp (Ξ» x, approx_on f fmeas s yβ hβ n x - yβ) p ΞΌ :=
β¨(approx_on f fmeas s yβ hβ n - const Ξ² yβ).ae_strongly_measurable, thisβ©,
convert snorm_add_lt_top this hiβ,
ext x,
simp },
have hf' : mem_βp (Ξ» x, β₯f x - yββ₯) p ΞΌ,
{ have h_meas : measurable (Ξ» x, β₯f x - yββ₯),
{ simp only [β dist_eq_norm],
exact (continuous_id.dist continuous_const).measurable.comp fmeas },
refine β¨h_meas.ae_measurable.ae_strongly_measurable, _β©,
rw snorm_norm,
convert snorm_add_lt_top hf hiβ.neg,
ext x,
simp [sub_eq_add_neg] },
have : βα΅ x βΞΌ, β₯approx_on f fmeas s yβ hβ n x - yββ₯ β€ β₯(β₯f x - yββ₯ + β₯f x - yββ₯)β₯,
{ refine eventually_of_forall _,
intros x,
convert norm_approx_on_yβ_le fmeas hβ x n,
rw [real.norm_eq_abs, abs_of_nonneg],
exact add_nonneg (norm_nonneg _) (norm_nonneg _) },
calc snorm (Ξ» x, approx_on f fmeas s yβ hβ n x - yβ) p ΞΌ
β€ snorm (Ξ» x, β₯f x - yββ₯ + β₯f x - yββ₯) p ΞΌ : snorm_mono_ae this
... < β€ : snorm_add_lt_top hf' hf',
end
lemma tendsto_approx_on_range_Lp_snorm [borel_space E]
{f : Ξ² β E} (hp_ne_top : p β β) {ΞΌ : measure Ξ²} (fmeas : measurable f)
[separable_space (range f βͺ {0} : set E)]
(hf : snorm f p ΞΌ < β) :
tendsto (Ξ» n, snorm (approx_on f fmeas (range f βͺ {0}) 0 (by simp) n - f) p ΞΌ) at_top (π 0) :=
begin
refine tendsto_approx_on_Lp_snorm fmeas _ hp_ne_top _ _,
{ apply eventually_of_forall,
assume x,
apply subset_closure,
simp },
{ simpa using hf }
end
lemma mem_βp_approx_on_range [borel_space E]
{f : Ξ² β E} {ΞΌ : measure Ξ²} (fmeas : measurable f) [separable_space (range f βͺ {0} : set E)]
(hf : mem_βp f p ΞΌ) (n : β) :
mem_βp (approx_on f fmeas (range f βͺ {0}) 0 (by simp) n) p ΞΌ :=
mem_βp_approx_on fmeas hf (by simp) zero_mem_βp n
lemma tendsto_approx_on_range_Lp [borel_space E]
{f : Ξ² β E} [hp : fact (1 β€ p)] (hp_ne_top : p β β) {ΞΌ : measure Ξ²} (fmeas : measurable f)
[separable_space (range f βͺ {0} : set E)] (hf : mem_βp f p ΞΌ) :
tendsto (Ξ» n, (mem_βp_approx_on_range fmeas hf n).to_Lp
(approx_on f fmeas (range f βͺ {0}) 0 (by simp) n))
at_top (π (hf.to_Lp f)) :=
by simpa only [Lp.tendsto_Lp_iff_tendsto_βp'']
using tendsto_approx_on_range_Lp_snorm hp_ne_top fmeas hf.2
end Lp
/-! ### L1 approximation by simple functions -/
section integrable
variables [measurable_space Ξ²]
variables [measurable_space E] [normed_add_comm_group E]
lemma tendsto_approx_on_L1_nnnorm [opens_measurable_space E]
{f : Ξ² β E} (hf : measurable f) {s : set E} {yβ : E} (hβ : yβ β s) [separable_space s]
{ΞΌ : measure Ξ²} (hΞΌ : βα΅ x βΞΌ, f x β closure s) (hi : has_finite_integral (Ξ» x, f x - yβ) ΞΌ) :
tendsto (Ξ» n, β«β» x, β₯approx_on f hf s yβ hβ n x - f xβ₯β βΞΌ) at_top (π 0) :=
by simpa [snorm_one_eq_lintegral_nnnorm] using tendsto_approx_on_Lp_snorm hf hβ one_ne_top hΞΌ
(by simpa [snorm_one_eq_lintegral_nnnorm] using hi)
lemma integrable_approx_on [borel_space E]
{f : Ξ² β E} {ΞΌ : measure Ξ²} (fmeas : measurable f) (hf : integrable f ΞΌ)
{s : set E} {yβ : E} (hβ : yβ β s)
[separable_space s] (hiβ : integrable (Ξ» x, yβ) ΞΌ) (n : β) :
integrable (approx_on f fmeas s yβ hβ n) ΞΌ :=
begin
rw β mem_βp_one_iff_integrable at hf hiβ β’,
exact mem_βp_approx_on fmeas hf hβ hiβ n,
end
lemma tendsto_approx_on_range_L1_nnnorm [opens_measurable_space E]
{f : Ξ² β E} {ΞΌ : measure Ξ²} [separable_space (range f βͺ {0} : set E)]
(fmeas : measurable f) (hf : integrable f ΞΌ) :
tendsto (Ξ» n, β«β» x, β₯approx_on f fmeas (range f βͺ {0}) 0 (by simp) n x - f xβ₯β βΞΌ)
at_top (π 0) :=
begin
apply tendsto_approx_on_L1_nnnorm fmeas,
{ apply eventually_of_forall,
assume x,
apply subset_closure,
simp },
{ simpa using hf.2 }
end
lemma integrable_approx_on_range [borel_space E]
{f : Ξ² β E} {ΞΌ : measure Ξ²} (fmeas : measurable f)
[separable_space (range f βͺ {0} : set E)] (hf : integrable f ΞΌ) (n : β) :
integrable (approx_on f fmeas (range f βͺ {0}) 0 (by simp) n) ΞΌ :=
integrable_approx_on fmeas hf _ (integrable_zero _ _ _) n
end integrable
section simple_func_properties
variables [measurable_space Ξ±]
variables [normed_add_comm_group E] [normed_add_comm_group F]
variables {ΞΌ : measure Ξ±} {p : ββ₯0β}
/-!
### Properties of simple functions in `Lp` spaces
A simple function `f : Ξ± ββ E` into a normed group `E` verifies, for a measure `ΞΌ`:
- `mem_βp f 0 ΞΌ` and `mem_βp f β ΞΌ`, since `f` is a.e.-measurable and bounded,
- for `0 < p < β`,
`mem_βp f p ΞΌ β integrable f ΞΌ β f.fin_meas_supp ΞΌ β β y β 0, ΞΌ (f β»ΒΉ' {y}) < β`.
-/
lemma exists_forall_norm_le (f : Ξ± ββ F) : β C, β x, β₯f xβ₯ β€ C :=
exists_forall_le (f.map (Ξ» x, β₯xβ₯))
lemma mem_βp_zero (f : Ξ± ββ E) (ΞΌ : measure Ξ±) : mem_βp f 0 ΞΌ :=
mem_βp_zero_iff_ae_strongly_measurable.mpr f.ae_strongly_measurable
lemma mem_βp_top (f : Ξ± ββ E) (ΞΌ : measure Ξ±) : mem_βp f β ΞΌ :=
let β¨C, hfCβ© := f.exists_forall_norm_le in
mem_βp_top_of_bound f.ae_strongly_measurable C $ eventually_of_forall hfC
protected lemma snorm'_eq {p : β} (f : Ξ± ββ F) (ΞΌ : measure Ξ±) :
snorm' f p ΞΌ = (β y in f.range, (β₯yβ₯β : ββ₯0β) ^ p * ΞΌ (f β»ΒΉ' {y})) ^ (1/p) :=
have h_map : (Ξ» a, (β₯f aβ₯β : ββ₯0β) ^ p) = f.map (Ξ» a : F, (β₯aβ₯β : ββ₯0β) ^ p), by simp,
by rw [snorm', h_map, lintegral_eq_lintegral, map_lintegral]
lemma measure_preimage_lt_top_of_mem_βp (hp_pos : p β 0) (hp_ne_top : p β β) (f : Ξ± ββ E)
(hf : mem_βp f p ΞΌ) (y : E) (hy_ne : y β 0) :
ΞΌ (f β»ΒΉ' {y}) < β :=
begin
have hp_pos_real : 0 < p.to_real, from ennreal.to_real_pos hp_pos hp_ne_top,
have hf_snorm := mem_βp.snorm_lt_top hf,
rw [snorm_eq_snorm' hp_pos hp_ne_top, f.snorm'_eq,
β @ennreal.lt_rpow_one_div_iff _ _ (1 / p.to_real) (by simp [hp_pos_real]),
@ennreal.top_rpow_of_pos (1 / (1 / p.to_real)) (by simp [hp_pos_real]),
ennreal.sum_lt_top_iff] at hf_snorm,
by_cases hyf : y β f.range,
swap,
{ suffices h_empty : f β»ΒΉ' {y} = β
,
by { rw [h_empty, measure_empty], exact ennreal.coe_lt_top, },
ext1 x,
rw [set.mem_preimage, set.mem_singleton_iff, mem_empty_eq, iff_false],
refine Ξ» hxy, hyf _,
rw [mem_range, set.mem_range],
exact β¨x, hxyβ©, },
specialize hf_snorm y hyf,
rw ennreal.mul_lt_top_iff at hf_snorm,
cases hf_snorm,
{ exact hf_snorm.2, },
cases hf_snorm,
{ refine absurd _ hy_ne,
simpa [hp_pos_real] using hf_snorm, },
{ simp [hf_snorm], },
end
lemma mem_βp_of_finite_measure_preimage (p : ββ₯0β) {f : Ξ± ββ E} (hf : β y β 0, ΞΌ (f β»ΒΉ' {y}) < β) :
mem_βp f p ΞΌ :=
begin
by_cases hp0 : p = 0,
{ rw [hp0, mem_βp_zero_iff_ae_strongly_measurable], exact f.ae_strongly_measurable, },
by_cases hp_top : p = β,
{ rw hp_top, exact mem_βp_top f ΞΌ, },
refine β¨f.ae_strongly_measurable, _β©,
rw [snorm_eq_snorm' hp0 hp_top, f.snorm'_eq],
refine ennreal.rpow_lt_top_of_nonneg (by simp) (ennreal.sum_lt_top_iff.mpr (Ξ» y hy, _)).ne,
by_cases hy0 : y = 0,
{ simp [hy0, ennreal.to_real_pos hp0 hp_top], },
{ refine ennreal.mul_lt_top _ (hf y hy0).ne,
exact (ennreal.rpow_lt_top_of_nonneg ennreal.to_real_nonneg ennreal.coe_ne_top).ne },
end
lemma mem_βp_iff {f : Ξ± ββ E} (hp_pos : p β 0) (hp_ne_top : p β β) :
mem_βp f p ΞΌ β β y β 0, ΞΌ (f β»ΒΉ' {y}) < β :=
β¨Ξ» h, measure_preimage_lt_top_of_mem_βp hp_pos hp_ne_top f h,
Ξ» h, mem_βp_of_finite_measure_preimage p hβ©
lemma integrable_iff {f : Ξ± ββ E} : integrable f ΞΌ β β y β 0, ΞΌ (f β»ΒΉ' {y}) < β :=
mem_βp_one_iff_integrable.symm.trans $ mem_βp_iff ennreal.zero_lt_one.ne' ennreal.coe_ne_top
lemma mem_βp_iff_integrable {f : Ξ± ββ E} (hp_pos : p β 0) (hp_ne_top : p β β) :
mem_βp f p ΞΌ β integrable f ΞΌ :=
(mem_βp_iff hp_pos hp_ne_top).trans integrable_iff.symm
lemma mem_βp_iff_fin_meas_supp {f : Ξ± ββ E} (hp_pos : p β 0) (hp_ne_top : p β β) :
mem_βp f p ΞΌ β f.fin_meas_supp ΞΌ :=
(mem_βp_iff hp_pos hp_ne_top).trans fin_meas_supp_iff.symm
lemma integrable_iff_fin_meas_supp {f : Ξ± ββ E} : integrable f ΞΌ β f.fin_meas_supp ΞΌ :=
integrable_iff.trans fin_meas_supp_iff.symm
lemma fin_meas_supp.integrable {f : Ξ± ββ E} (h : f.fin_meas_supp ΞΌ) : integrable f ΞΌ :=
integrable_iff_fin_meas_supp.2 h
lemma integrable_pair {f : Ξ± ββ E} {g : Ξ± ββ F} :
integrable f ΞΌ β integrable g ΞΌ β integrable (pair f g) ΞΌ :=
by simpa only [integrable_iff_fin_meas_supp] using fin_meas_supp.pair
lemma mem_βp_of_is_finite_measure (f : Ξ± ββ E) (p : ββ₯0β) (ΞΌ : measure Ξ±) [is_finite_measure ΞΌ] :
mem_βp f p ΞΌ :=
let β¨C, hfCβ© := f.exists_forall_norm_le in
mem_βp.of_bound f.ae_strongly_measurable C $ eventually_of_forall hfC
lemma integrable_of_is_finite_measure [is_finite_measure ΞΌ] (f : Ξ± ββ E) : integrable f ΞΌ :=
mem_βp_one_iff_integrable.mp (f.mem_βp_of_is_finite_measure 1 ΞΌ)
lemma measure_preimage_lt_top_of_integrable (f : Ξ± ββ E) (hf : integrable f ΞΌ) {x : E}
(hx : x β 0) :
ΞΌ (f β»ΒΉ' {x}) < β :=
integrable_iff.mp hf x hx
lemma measure_support_lt_top [has_zero Ξ²] (f : Ξ± ββ Ξ²) (hf : β y β 0, ΞΌ (f β»ΒΉ' {y}) < β) :
ΞΌ (support f) < β :=
begin
rw support_eq,
refine (measure_bUnion_finset_le _ _).trans_lt (ennreal.sum_lt_top_iff.mpr (Ξ» y hy, _)),
rw finset.mem_filter at hy,
exact hf y hy.2,
end
lemma measure_support_lt_top_of_mem_βp (f : Ξ± ββ E) (hf : mem_βp f p ΞΌ) (hp_ne_zero : p β 0)
(hp_ne_top : p β β) :
ΞΌ (support f) < β :=
f.measure_support_lt_top ((mem_βp_iff hp_ne_zero hp_ne_top).mp hf)
lemma measure_support_lt_top_of_integrable (f : Ξ± ββ E) (hf : integrable f ΞΌ) :
ΞΌ (support f) < β :=
f.measure_support_lt_top (integrable_iff.mp hf)
lemma measure_lt_top_of_mem_βp_indicator (hp_pos : p β 0) (hp_ne_top : p β β) {c : E} (hc : c β 0)
{s : set Ξ±} (hs : measurable_set s)
(hcs : mem_βp ((const Ξ± c).piecewise s hs (const Ξ± 0)) p ΞΌ) :
ΞΌ s < β€ :=
begin
have : function.support (const Ξ± c) = set.univ := function.support_const hc,
simpa only [mem_βp_iff_fin_meas_supp hp_pos hp_ne_top, fin_meas_supp_iff_support,
support_indicator, set.inter_univ, this] using hcs
end
end simple_func_properties
end simple_func
/-! Construction of the space of `Lp` simple functions, and its dense embedding into `Lp`. -/
namespace Lp
open ae_eq_fun
variables [measurable_space Ξ±] [normed_add_comm_group E] [normed_add_comm_group F] (p : ββ₯0β)
(ΞΌ : measure Ξ±)
variables (E)
/-- `Lp.simple_func` is a subspace of Lp consisting of equivalence classes of an integrable simple
function. -/
def simple_func : add_subgroup (Lp E p ΞΌ) :=
{ carrier := {f : Lp E p ΞΌ |
β (s : Ξ± ββ E), (ae_eq_fun.mk s s.ae_strongly_measurable : Ξ± ββ[ΞΌ] E) = f},
zero_mem' := β¨0, rflβ©,
add_mem' := Ξ» f g β¨s, hsβ© β¨t, htβ©, β¨s + t,
by simp only [βhs, βht, ae_eq_fun.mk_add_mk, add_subgroup.coe_add, ae_eq_fun.mk_eq_mk,
simple_func.coe_add]β©,
neg_mem' := Ξ» f β¨s, hsβ©, β¨-s,
by simp only [βhs, ae_eq_fun.neg_mk, simple_func.coe_neg, ae_eq_fun.mk_eq_mk,
add_subgroup.coe_neg]β© }
variables {E p ΞΌ}
namespace simple_func
section instances
/-! Simple functions in Lp space form a `normed_space`. -/
@[norm_cast] lemma coe_coe (f : Lp.simple_func E p ΞΌ) : β(f : Lp E p ΞΌ) = f := rfl
protected lemma eq' {f g : Lp.simple_func E p ΞΌ} : (f : Ξ± ββ[ΞΌ] E) = (g : Ξ± ββ[ΞΌ] E) β f = g :=
subtype.eq β subtype.eq
/-! Implementation note: If `Lp.simple_func E p ΞΌ` were defined as a `π`-submodule of `Lp E p ΞΌ`,
then the next few lemmas, putting a normed `π`-group structure on `Lp.simple_func E p ΞΌ`, would be
unnecessary. But instead, `Lp.simple_func E p ΞΌ` is defined as an `add_subgroup` of `Lp E p ΞΌ`,
which does not permit this (but has the advantage of working when `E` itself is a normed group,
i.e. has no scalar action). -/
variables [normed_field π] [normed_space π E]
/-- If `E` is a normed space, `Lp.simple_func E p ΞΌ` is a `has_smul`. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def has_smul : has_smul π (Lp.simple_func E p ΞΌ) := β¨Ξ» k f, β¨k β’ f,
begin
rcases f with β¨f, β¨s, hsβ©β©,
use k β’ s,
apply eq.trans (ae_eq_fun.smul_mk k s s.ae_strongly_measurable).symm _,
rw hs,
refl,
end β©β©
local attribute [instance] simple_func.has_smul
@[simp, norm_cast] lemma coe_smul (c : π) (f : Lp.simple_func E p ΞΌ) :
((c β’ f : Lp.simple_func E p ΞΌ) : Lp E p ΞΌ) = c β’ (f : Lp E p ΞΌ) := rfl
/-- If `E` is a normed space, `Lp.simple_func E p ΞΌ` is a module. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def module : module π (Lp.simple_func E p ΞΌ) :=
{ one_smul := Ξ»f, by { ext1, exact one_smul _ _ },
mul_smul := Ξ»x y f, by { ext1, exact mul_smul _ _ _ },
smul_add := Ξ»x f g, by { ext1, exact smul_add _ _ _ },
smul_zero := Ξ»x, by { ext1, exact smul_zero _ },
add_smul := Ξ»x y f, by { ext1, exact add_smul _ _ _ },
zero_smul := Ξ»f, by { ext1, exact zero_smul _ _ } }
local attribute [instance] simple_func.module
/-- If `E` is a normed space, `Lp.simple_func E p ΞΌ` is a normed space. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def normed_space [fact (1 β€ p)] : normed_space π (Lp.simple_func E p ΞΌ) :=
β¨ Ξ»c f, by { rw [add_subgroup.coe_norm, add_subgroup.coe_norm, coe_smul, norm_smul] } β©
end instances
local attribute [instance] simple_func.module simple_func.normed_space
section to_Lp
/-- Construct the equivalence class `[f]` of a simple function `f` satisfying `mem_βp`. -/
@[reducible] def to_Lp (f : Ξ± ββ E) (hf : mem_βp f p ΞΌ) : (Lp.simple_func E p ΞΌ) :=
β¨hf.to_Lp f, β¨f, rflβ©β©
lemma to_Lp_eq_to_Lp (f : Ξ± ββ E) (hf : mem_βp f p ΞΌ) :
(to_Lp f hf : Lp E p ΞΌ) = hf.to_Lp f := rfl
lemma to_Lp_eq_mk (f : Ξ± ββ E) (hf : mem_βp f p ΞΌ) :
(to_Lp f hf : Ξ± ββ[ΞΌ] E) = ae_eq_fun.mk f f.ae_strongly_measurable := rfl
lemma to_Lp_zero : to_Lp (0 : Ξ± ββ E) zero_mem_βp = (0 : Lp.simple_func E p ΞΌ) := rfl
lemma to_Lp_add (f g : Ξ± ββ E) (hf : mem_βp f p ΞΌ) (hg : mem_βp g p ΞΌ) :
to_Lp (f + g) (hf.add hg) = to_Lp f hf + to_Lp g hg := rfl
lemma to_Lp_neg (f : Ξ± ββ E) (hf : mem_βp f p ΞΌ) :
to_Lp (-f) hf.neg = -to_Lp f hf := rfl
lemma to_Lp_sub (f g : Ξ± ββ E) (hf : mem_βp f p ΞΌ) (hg : mem_βp g p ΞΌ) :
to_Lp (f - g) (hf.sub hg) = to_Lp f hf - to_Lp g hg :=
by { simp only [sub_eq_add_neg, β to_Lp_neg, β to_Lp_add], refl }
variables [normed_field π] [normed_space π E]
lemma to_Lp_smul (f : Ξ± ββ E) (hf : mem_βp f p ΞΌ) (c : π) :
to_Lp (c β’ f) (hf.const_smul c) = c β’ to_Lp f hf := rfl
lemma norm_to_Lp [fact (1 β€ p)] (f : Ξ± ββ E) (hf : mem_βp f p ΞΌ) :
β₯to_Lp f hfβ₯ = ennreal.to_real (snorm f p ΞΌ) :=
norm_to_Lp f hf
end to_Lp
section to_simple_func
/-- Find a representative of a `Lp.simple_func`. -/
def to_simple_func (f : Lp.simple_func E p ΞΌ) : Ξ± ββ E := classical.some f.2
/-- `(to_simple_func f)` is measurable. -/
@[measurability]
protected lemma measurable [measurable_space E] (f : Lp.simple_func E p ΞΌ) :
measurable (to_simple_func f) :=
(to_simple_func f).measurable
protected lemma strongly_measurable (f : Lp.simple_func E p ΞΌ) :
strongly_measurable (to_simple_func f) :=
(to_simple_func f).strongly_measurable
@[measurability]
protected lemma ae_measurable [measurable_space E] (f : Lp.simple_func E p ΞΌ) :
ae_measurable (to_simple_func f) ΞΌ :=
(simple_func.measurable f).ae_measurable
protected lemma ae_strongly_measurable (f : Lp.simple_func E p ΞΌ) :
ae_strongly_measurable (to_simple_func f) ΞΌ :=
(simple_func.strongly_measurable f).ae_strongly_measurable
lemma to_simple_func_eq_to_fun (f : Lp.simple_func E p ΞΌ) : to_simple_func f =α΅[ΞΌ] f :=
show β(to_simple_func f) =α΅[ΞΌ] β(f : Ξ± ββ[ΞΌ] E),
begin
convert (ae_eq_fun.coe_fn_mk (to_simple_func f) (to_simple_func f).ae_strongly_measurable).symm
using 2,
exact (classical.some_spec f.2).symm,
end
/-- `to_simple_func f` satisfies the predicate `mem_βp`. -/
protected lemma mem_βp (f : Lp.simple_func E p ΞΌ) : mem_βp (to_simple_func f) p ΞΌ :=
mem_βp.ae_eq (to_simple_func_eq_to_fun f).symm $ mem_Lp_iff_mem_βp.mp (f : Lp E p ΞΌ).2
lemma to_Lp_to_simple_func (f : Lp.simple_func E p ΞΌ) :
to_Lp (to_simple_func f) (simple_func.mem_βp f) = f :=
simple_func.eq' (classical.some_spec f.2)
lemma to_simple_func_to_Lp (f : Ξ± ββ E) (hfi : mem_βp f p ΞΌ) :
to_simple_func (to_Lp f hfi) =α΅[ΞΌ] f :=
by { rw β ae_eq_fun.mk_eq_mk, exact classical.some_spec (to_Lp f hfi).2 }
variables (E ΞΌ)
lemma zero_to_simple_func : to_simple_func (0 : Lp.simple_func E p ΞΌ) =α΅[ΞΌ] 0 :=
begin
filter_upwards [to_simple_func_eq_to_fun (0 : Lp.simple_func E p ΞΌ), Lp.coe_fn_zero E 1 ΞΌ]
with _ hβ _,
rwa hβ,
end
variables {E ΞΌ}
lemma add_to_simple_func (f g : Lp.simple_func E p ΞΌ) :
to_simple_func (f + g) =α΅[ΞΌ] to_simple_func f + to_simple_func g :=
begin
filter_upwards [to_simple_func_eq_to_fun (f + g), to_simple_func_eq_to_fun f,
to_simple_func_eq_to_fun g, Lp.coe_fn_add (f : Lp E p ΞΌ) g] with _,
simp only [β coe_coe, add_subgroup.coe_add, pi.add_apply],
iterate 4 { assume h, rw h, },
end
lemma neg_to_simple_func (f : Lp.simple_func E p ΞΌ) :
to_simple_func (-f) =α΅[ΞΌ] - to_simple_func f :=
begin
filter_upwards [to_simple_func_eq_to_fun (-f), to_simple_func_eq_to_fun f,
Lp.coe_fn_neg (f : Lp E p ΞΌ)] with _,
simp only [pi.neg_apply, add_subgroup.coe_neg, β coe_coe],
repeat { assume h, rw h, },
end
lemma sub_to_simple_func (f g : Lp.simple_func E p ΞΌ) :
to_simple_func (f - g) =α΅[ΞΌ] to_simple_func f - to_simple_func g :=
begin
filter_upwards [to_simple_func_eq_to_fun (f - g), to_simple_func_eq_to_fun f,
to_simple_func_eq_to_fun g, Lp.coe_fn_sub (f : Lp E p ΞΌ) g] with _,
simp only [add_subgroup.coe_sub, pi.sub_apply, β coe_coe],
repeat { assume h, rw h, },
end
variables [normed_field π] [normed_space π E]
lemma smul_to_simple_func (k : π) (f : Lp.simple_func E p ΞΌ) :
to_simple_func (k β’ f) =α΅[ΞΌ] k β’ to_simple_func f :=
begin
filter_upwards [to_simple_func_eq_to_fun (k β’ f), to_simple_func_eq_to_fun f,
Lp.coe_fn_smul k (f : Lp E p ΞΌ)] with _,
simp only [pi.smul_apply, coe_smul, β coe_coe],
repeat { assume h, rw h, },
end
lemma norm_to_simple_func [fact (1 β€ p)] (f : Lp.simple_func E p ΞΌ) :
β₯fβ₯ = ennreal.to_real (snorm (to_simple_func f) p ΞΌ) :=
by simpa [to_Lp_to_simple_func] using norm_to_Lp (to_simple_func f) (simple_func.mem_βp f)
end to_simple_func
section induction
variables (p)
/-- The characteristic function of a finite-measure measurable set `s`, as an `Lp` simple function.
-/
def indicator_const {s : set Ξ±} (hs : measurable_set s) (hΞΌs : ΞΌ s β β) (c : E) :
Lp.simple_func E p ΞΌ :=
to_Lp ((simple_func.const _ c).piecewise s hs (simple_func.const _ 0))
(mem_βp_indicator_const p hs c (or.inr hΞΌs))
variables {p}
@[simp] lemma coe_indicator_const {s : set Ξ±} (hs : measurable_set s) (hΞΌs : ΞΌ s β β) (c : E) :
(β(indicator_const p hs hΞΌs c) : Lp E p ΞΌ) = indicator_const_Lp p hs hΞΌs c :=
rfl
lemma to_simple_func_indicator_const {s : set Ξ±} (hs : measurable_set s) (hΞΌs : ΞΌ s β β) (c : E) :
to_simple_func (indicator_const p hs hΞΌs c)
=α΅[ΞΌ] (simple_func.const _ c).piecewise s hs (simple_func.const _ 0) :=
Lp.simple_func.to_simple_func_to_Lp _ _
/-- To prove something for an arbitrary `Lp` simple function, with `0 < p < β`, it suffices to show
that the property holds for (multiples of) characteristic functions of finite-measure measurable
sets and is closed under addition (of functions with disjoint support). -/
@[elab_as_eliminator]
protected lemma induction (hp_pos : p β 0) (hp_ne_top : p β β) {P : Lp.simple_func E p ΞΌ β Prop}
(h_ind : β (c : E) {s : set Ξ±} (hs : measurable_set s) (hΞΌs : ΞΌ s < β),
P (Lp.simple_func.indicator_const p hs hΞΌs.ne c))
(h_add : β β¦f g : Ξ± ββ Eβ¦, β hf : mem_βp f p ΞΌ, β hg : mem_βp g p ΞΌ,
disjoint (support f) (support g) β P (Lp.simple_func.to_Lp f hf)
β P (Lp.simple_func.to_Lp g hg) β P (Lp.simple_func.to_Lp f hf + Lp.simple_func.to_Lp g hg))
(f : Lp.simple_func E p ΞΌ) : P f :=
begin
suffices : β f : Ξ± ββ E, β hf : mem_βp f p ΞΌ, P (to_Lp f hf),
{ rw β to_Lp_to_simple_func f,
apply this }, clear f,
refine simple_func.induction _ _,
{ intros c s hs hf,
by_cases hc : c = 0,
{ convert h_ind 0 measurable_set.empty (by simp) using 1,
ext1,
simp [hc] },
exact h_ind c hs (simple_func.measure_lt_top_of_mem_βp_indicator hp_pos hp_ne_top hc hs hf) },
{ intros f g hfg hf hg hfg',
obtain β¨hf', hg'β© : mem_βp f p ΞΌ β§ mem_βp g p ΞΌ,
{ exact (mem_βp_add_of_disjoint hfg f.strongly_measurable g.strongly_measurable).mp hfg' },
exact h_add hf' hg' hfg (hf hf') (hg hg') },
end
end induction
section coe_to_Lp
variables [fact (1 β€ p)]
protected lemma uniform_continuous :
uniform_continuous (coe : (Lp.simple_func E p ΞΌ) β (Lp E p ΞΌ)) :=
uniform_continuous_comap
protected lemma uniform_embedding :
uniform_embedding (coe : (Lp.simple_func E p ΞΌ) β (Lp E p ΞΌ)) :=
uniform_embedding_comap subtype.val_injective
protected lemma uniform_inducing : uniform_inducing (coe : (Lp.simple_func E p ΞΌ) β (Lp E p ΞΌ)) :=
simple_func.uniform_embedding.to_uniform_inducing
protected lemma dense_embedding (hp_ne_top : p β β) :
dense_embedding (coe : (Lp.simple_func E p ΞΌ) β (Lp E p ΞΌ)) :=
begin
borelize E,
apply simple_func.uniform_embedding.dense_embedding,
assume f,
rw mem_closure_iff_seq_limit,
have hfi' : mem_βp f p ΞΌ := Lp.mem_βp f,
haveI : separable_space (range f βͺ {0} : set E) :=
(Lp.strongly_measurable f).separable_space_range_union_singleton,
refine β¨Ξ» n, β(to_Lp (simple_func.approx_on f (Lp.strongly_measurable f).measurable
(range f βͺ {0}) 0 (by simp) n)
(simple_func.mem_βp_approx_on_range (Lp.strongly_measurable f).measurable hfi' n)),
Ξ» n, mem_range_self _, _β©,
convert simple_func.tendsto_approx_on_range_Lp hp_ne_top (Lp.strongly_measurable f).measurable
hfi',
rw to_Lp_coe_fn f (Lp.mem_βp f)
end
protected lemma dense_inducing (hp_ne_top : p β β) :
dense_inducing (coe : (Lp.simple_func E p ΞΌ) β (Lp E p ΞΌ)) :=
(simple_func.dense_embedding hp_ne_top).to_dense_inducing
protected lemma dense_range (hp_ne_top : p β β) :
dense_range (coe : (Lp.simple_func E p ΞΌ) β (Lp E p ΞΌ)) :=
(simple_func.dense_inducing hp_ne_top).dense
variables [normed_field π] [normed_space π E]
variables (Ξ± E π)
/-- The embedding of Lp simple functions into Lp functions, as a continuous linear map. -/
def coe_to_Lp : (Lp.simple_func E p ΞΌ) βL[π] (Lp E p ΞΌ) :=
{ map_smul' := Ξ»k f, rfl,
cont := Lp.simple_func.uniform_continuous.continuous,
.. add_subgroup.subtype (Lp.simple_func E p ΞΌ) }
variables {Ξ± E π}
end coe_to_Lp
section order
variables {G : Type*} [normed_lattice_add_comm_group G]
lemma coe_fn_le (f g : Lp.simple_func G p ΞΌ) : f β€α΅[ΞΌ] g β f β€ g :=
by rw [β subtype.coe_le_coe, β Lp.coe_fn_le, coe_fn_coe_base', coe_fn_coe_base' g]
instance : covariant_class (Lp.simple_func G p ΞΌ) (Lp.simple_func G p ΞΌ) (+) (β€) :=
begin
refine β¨Ξ» f gβ gβ hgββ, _β©,
rw β Lp.simple_func.coe_fn_le at hgββ β’,
have h_add_1 : β(f + gβ) =α΅[ΞΌ] f + gβ, from Lp.coe_fn_add _ _,
have h_add_2 : β(f + gβ) =α΅[ΞΌ] f + gβ, from Lp.coe_fn_add _ _,
filter_upwards [h_add_1, h_add_2, hgββ] with _ h1 h2 h3,
rw [h1, h2, pi.add_apply, pi.add_apply],
exact add_le_add le_rfl h3,
end
variables (p ΞΌ G)
lemma coe_fn_zero : (0 : Lp.simple_func G p ΞΌ) =α΅[ΞΌ] (0 : Ξ± β G) := Lp.coe_fn_zero _ _ _
variables{p ΞΌ G}
lemma coe_fn_nonneg (f : Lp.simple_func G p ΞΌ) : 0 β€α΅[ΞΌ] f β 0 β€ f :=
begin
rw β Lp.simple_func.coe_fn_le,
have h0 : (0 : Lp.simple_func G p ΞΌ) =α΅[ΞΌ] (0 : Ξ± β G), from Lp.simple_func.coe_fn_zero p ΞΌ G,
split; intro h; filter_upwards [h, h0] with _ _ h2,
{ rwa h2, },
{ rwa β h2, },
end
lemma exists_simple_func_nonneg_ae_eq {f : Lp.simple_func G p ΞΌ} (hf : 0 β€ f) :
β f' : Ξ± ββ G, 0 β€ f' β§ f =α΅[ΞΌ] f' :=
begin
rw β Lp.simple_func.coe_fn_nonneg at hf,
have hf_ae : 0 β€α΅[ΞΌ] (simple_func.to_simple_func f),
by { filter_upwards [to_simple_func_eq_to_fun f, hf] with _ h1 _, rwa h1 },
let s := (to_measurable ΞΌ {x | Β¬ 0 β€ simple_func.to_simple_func f x})αΆ,
have hs_zero : ΞΌ sαΆ = 0,
by { rw [compl_compl, measure_to_measurable], rwa [eventually_le, ae_iff] at hf_ae, },
have hfs_nonneg : β x β s, 0 β€ simple_func.to_simple_func f x,
{ intros x hxs,
rw mem_compl_iff at hxs,
have hx' : x β {a : Ξ± | Β¬0 β€ simple_func.to_simple_func f a},
from Ξ» h, hxs (subset_to_measurable ΞΌ _ h),
rwa [set.nmem_set_of_eq, not_not] at hx', },
let f' := simple_func.piecewise s (measurable_set_to_measurable ΞΌ _).compl
(simple_func.to_simple_func f) (simple_func.const Ξ± (0 : G)),
refine β¨f', Ξ» x, _, _β©,
{ rw simple_func.piecewise_apply,
by_cases hxs : x β s,
{ simp only [hxs, hfs_nonneg x hxs, if_true, pi.zero_apply, simple_func.coe_zero], },
{ simp only [hxs, simple_func.const_zero, if_false], }, },
{ rw simple_func.coe_piecewise,
have : s =α΅[ΞΌ] univ,
{ rw ae_eq_set,
simp only [true_and, measure_empty, eq_self_iff_true, diff_univ, β compl_eq_univ_diff],
exact hs_zero, },
refine eventually_eq.trans (to_simple_func_eq_to_fun f).symm _,
refine eventually_eq.trans _ (piecewise_ae_eq_of_ae_eq_set this.symm),
simp only [simple_func.const_zero, indicator_univ, piecewise_eq_indicator,
simple_func.coe_zero], },
end
variables (p ΞΌ G)
/-- Coercion from nonnegative simple functions of Lp to nonnegative functions of Lp. -/
def coe_simple_func_nonneg_to_Lp_nonneg :
{g : Lp.simple_func G p ΞΌ // 0 β€ g} β {g : Lp G p ΞΌ // 0 β€ g} :=
Ξ» g, β¨g, g.2β©
lemma dense_range_coe_simple_func_nonneg_to_Lp_nonneg [hp : fact (1 β€ p)] (hp_ne_top : p β β) :
dense_range (coe_simple_func_nonneg_to_Lp_nonneg p ΞΌ G) :=
begin
borelize G,
assume g,
rw mem_closure_iff_seq_limit,
have hg_mem_βp : mem_βp g p ΞΌ := Lp.mem_βp g,
have zero_mem : (0 : G) β (range g βͺ {0} : set G) β© {y | 0 β€ y}, by simp only [union_singleton,
mem_inter_eq, mem_insert_iff, eq_self_iff_true, true_or, mem_set_of_eq, le_refl, and_self],
haveI : separable_space (((range g βͺ {0}) β© {y | 0 β€ y}) : set G),
{ apply is_separable.separable_space,
apply is_separable.mono _ (set.inter_subset_left _ _),
exact (Lp.strongly_measurable (g : Lp G p ΞΌ)).is_separable_range.union
(finite_singleton _).is_separable },
have g_meas : measurable g := (Lp.strongly_measurable (g : Lp G p ΞΌ)).measurable,
let x := Ξ» n, simple_func.approx_on g g_meas ((range g βͺ {0}) β© {y | 0 β€ y}) 0 zero_mem n,
have hx_nonneg : β n, 0 β€ x n,
{ assume n a,
change x n a β {y : G | 0 β€ y},
have A : (range g βͺ {0} : set G) β© {y | 0 β€ y} β {y | 0 β€ y} := inter_subset_right _ _,
apply A,
exact simple_func.approx_on_mem g_meas _ n a },
have hx_mem_βp : β n, mem_βp (x n) p ΞΌ,
from simple_func.mem_βp_approx_on _ hg_mem_βp _ β¨ae_strongly_measurable_const, by simpβ©,
have h_to_Lp := Ξ» n, mem_βp.coe_fn_to_Lp (hx_mem_βp n),
have hx_nonneg_Lp : β n, 0 β€ to_Lp (x n) (hx_mem_βp n),
{ intro n,
rw [β Lp.simple_func.coe_fn_le, coe_fn_coe_base' (simple_func.to_Lp (x n) _),
Lp.simple_func.to_Lp_eq_to_Lp],
have h0 := Lp.simple_func.coe_fn_zero p ΞΌ G,
filter_upwards [Lp.simple_func.coe_fn_zero p ΞΌ G, h_to_Lp n] with a ha0 ha_to_Lp,
rw [ha0, ha_to_Lp],
exact hx_nonneg n a, },
have hx_tendsto : tendsto (Ξ» (n : β), snorm (x n - g) p ΞΌ) at_top (π 0),
{ apply simple_func.tendsto_approx_on_Lp_snorm g_meas zero_mem hp_ne_top,
{ have hg_nonneg : 0 β€α΅[ΞΌ] g, from (Lp.coe_fn_nonneg _).mpr g.2,
refine hg_nonneg.mono (Ξ» a ha, subset_closure _),
simpa using ha, },
{ simp_rw sub_zero, exact hg_mem_βp.snorm_lt_top, }, },
refine β¨Ξ» n, (coe_simple_func_nonneg_to_Lp_nonneg p ΞΌ G) β¨to_Lp (x n) (hx_mem_βp n),
hx_nonneg_Lp nβ©, Ξ» n, mem_range_self _, _β©,
suffices : tendsto (Ξ» (n : β), β(to_Lp (x n) (hx_mem_βp n))) at_top (π (g : Lp G p ΞΌ)),
{ rw tendsto_iff_dist_tendsto_zero at this β’,
simp_rw subtype.dist_eq,
convert this, },
rw Lp.tendsto_Lp_iff_tendsto_βp',
convert hx_tendsto,
refine funext (Ξ» n, snorm_congr_ae (eventually_eq.sub _ _)),
{ rw Lp.simple_func.to_Lp_eq_to_Lp,
exact h_to_Lp n, },
{ rw β coe_fn_coe_base, },
end
variables {p ΞΌ G}
end order
end simple_func
end Lp
variables [measurable_space Ξ±] [normed_add_comm_group E] {f : Ξ± β E} {p : ββ₯0β} {ΞΌ : measure Ξ±}
/-- To prove something for an arbitrary `Lp` function in a second countable Borel normed group, it
suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in `Lp` for which the property holds is closed.
-/
@[elab_as_eliminator]
lemma Lp.induction [_i : fact (1 β€ p)] (hp_ne_top : p β β) (P : Lp E p ΞΌ β Prop)
(h_ind : β (c : E) {s : set Ξ±} (hs : measurable_set s) (hΞΌs : ΞΌ s < β),
P (Lp.simple_func.indicator_const p hs hΞΌs.ne c))
(h_add : β β¦f gβ¦, β hf : mem_βp f p ΞΌ, β hg : mem_βp g p ΞΌ, disjoint (support f) (support g) β
P (hf.to_Lp f) β P (hg.to_Lp g) β P ((hf.to_Lp f) + (hg.to_Lp g)))
(h_closed : is_closed {f : Lp E p ΞΌ | P f}) :
β f : Lp E p ΞΌ, P f :=
begin
refine Ξ» f, (Lp.simple_func.dense_range hp_ne_top).induction_on f h_closed _,
refine Lp.simple_func.induction (lt_of_lt_of_le ennreal.zero_lt_one _i.elim).ne' hp_ne_top _ _,
{ exact Ξ» c s, h_ind c },
{ exact Ξ» f g hf hg, h_add hf hg },
end
/-- To prove something for an arbitrary `mem_βp` function in a second countable
Borel normed group, it suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in the `Lα΅` space for which the property holds is closed.
* the property is closed under the almost-everywhere equal relation.
It is possible to make the hypotheses in the induction steps a bit stronger, and such conditions
can be added once we need them (for example in `h_add` it is only necessary to consider the sum of
a simple function with a multiple of a characteristic function and that the intersection
of their images is a subset of `{0}`).
-/
@[elab_as_eliminator]
lemma mem_βp.induction [_i : fact (1 β€ p)] (hp_ne_top : p β β) (P : (Ξ± β E) β Prop)
(h_ind : β (c : E) β¦sβ¦, measurable_set s β ΞΌ s < β β P (s.indicator (Ξ» _, c)))
(h_add : β β¦f g : Ξ± β Eβ¦, disjoint (support f) (support g) β mem_βp f p ΞΌ β mem_βp g p ΞΌ β
P f β P g β P (f + g))
(h_closed : is_closed {f : Lp E p ΞΌ | P f} )
(h_ae : β β¦f gβ¦, f =α΅[ΞΌ] g β mem_βp f p ΞΌ β P f β P g) :
β β¦f : Ξ± β Eβ¦ (hf : mem_βp f p ΞΌ), P f :=
begin
have : β (f : simple_func Ξ± E), mem_βp f p ΞΌ β P f,
{ refine simple_func.induction _ _,
{ intros c s hs h,
by_cases hc : c = 0,
{ subst hc, convert h_ind 0 measurable_set.empty (by simp) using 1, ext, simp [const] },
have hp_pos : p β 0 := (lt_of_lt_of_le ennreal.zero_lt_one _i.elim).ne',
exact h_ind c hs (simple_func.measure_lt_top_of_mem_βp_indicator hp_pos hp_ne_top hc hs h) },
{ intros f g hfg hf hg int_fg,
rw [simple_func.coe_add,
mem_βp_add_of_disjoint hfg f.strongly_measurable g.strongly_measurable] at int_fg,
refine h_add hfg int_fg.1 int_fg.2 (hf int_fg.1) (hg int_fg.2) } },
have : β (f : Lp.simple_func E p ΞΌ), P f,
{ intro f,
exact h_ae (Lp.simple_func.to_simple_func_eq_to_fun f) (Lp.simple_func.mem_βp f)
(this (Lp.simple_func.to_simple_func f) (Lp.simple_func.mem_βp f)) },
have : β (f : Lp E p ΞΌ), P f :=
Ξ» f, (Lp.simple_func.dense_range hp_ne_top).induction_on f h_closed this,
exact Ξ» f hf, h_ae hf.coe_fn_to_Lp (Lp.mem_βp _) (this (hf.to_Lp f)),
end
section integrable
notation Ξ± ` βββ[`:25 ΞΌ `] ` E := @measure_theory.Lp.simple_func Ξ± E _ _ 1 ΞΌ
lemma L1.simple_func.to_Lp_one_eq_to_L1 (f : Ξ± ββ E) (hf : integrable f ΞΌ) :
(Lp.simple_func.to_Lp f (mem_βp_one_iff_integrable.2 hf) : Ξ± ββ[ΞΌ] E) = hf.to_L1 f :=
rfl
protected lemma L1.simple_func.integrable (f : Ξ± βββ[ΞΌ] E) :
integrable (Lp.simple_func.to_simple_func f) ΞΌ :=
by { rw β mem_βp_one_iff_integrable, exact (Lp.simple_func.mem_βp f) }
/-- To prove something for an arbitrary integrable function in a normed group,
it suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in the `LΒΉ` space for which the property holds is closed.
* the property is closed under the almost-everywhere equal relation.
It is possible to make the hypotheses in the induction steps a bit stronger, and such conditions
can be added once we need them (for example in `h_add` it is only necessary to consider the sum of
a simple function with a multiple of a characteristic function and that the intersection
of their images is a subset of `{0}`).
-/
@[elab_as_eliminator]
lemma integrable.induction (P : (Ξ± β E) β Prop)
(h_ind : β (c : E) β¦sβ¦, measurable_set s β ΞΌ s < β β P (s.indicator (Ξ» _, c)))
(h_add : β β¦f g : Ξ± β Eβ¦, disjoint (support f) (support g) β integrable f ΞΌ β integrable g ΞΌ β
P f β P g β P (f + g))
(h_closed : is_closed {f : Ξ± ββ[ΞΌ] E | P f} )
(h_ae : β β¦f gβ¦, f =α΅[ΞΌ] g β integrable f ΞΌ β P f β P g) :
β β¦f : Ξ± β Eβ¦ (hf : integrable f ΞΌ), P f :=
begin
simp only [β mem_βp_one_iff_integrable] at *,
exact mem_βp.induction one_ne_top P h_ind h_add h_closed h_ae
end
end integrable
end measure_theory
|
8f75fb9127c54e0b23f4f7942ef1bc16626abe9a
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/pi/algebra.lean
|
367eb56bcbbca68c9436ecc7cf6298fd70374279
|
[
"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,049
|
lean
|
/-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot, Eric Wieser
-/
import tactic.split_ifs
import tactic.simpa
import tactic.congr
import algebra.group.to_additive
import data.prod
import logic.unique
/-!
# Instances and theorems on pi types
This file provides basic definitions and notation instances for Pi types.
Instances of more sophisticated classes are defined in `pi.lean` files elsewhere.
-/
open function
universes u vβ vβ vβ
variable {I : Type u} -- The indexing type
variables {Ξ± Ξ² Ξ³ : Type*}
-- The families of types already equipped with instances
variables {f : I β Type vβ} {g : I β Type vβ} {h : I β Type vβ}
variables (x y : Ξ i, f i) (i : I)
namespace pi
/-! `1`, `0`, `+`, `*`, `-`, `β»ΒΉ`, and `/` are defined pointwise. -/
@[to_additive] instance has_one [β i, has_one $ f i] :
has_one (Ξ i : I, f i) :=
β¨Ξ» _, 1β©
@[simp, to_additive] lemma one_apply [β i, has_one $ f i] : (1 : Ξ i, f i) i = 1 := rfl
@[to_additive] lemma one_def [Ξ i, has_one $ f i] : (1 : Ξ i, f i) = Ξ» i, 1 := rfl
@[simp, to_additive] lemma const_one [has_one Ξ²] : const Ξ± (1 : Ξ²) = 1 := rfl
@[simp, to_additive] lemma one_comp [has_one Ξ³] (x : Ξ± β Ξ²) : (1 : Ξ² β Ξ³) β x = 1 := rfl
@[simp, to_additive] lemma comp_one [has_one Ξ²] (x : Ξ² β Ξ³) : x β 1 = const Ξ± (x 1) := rfl
@[to_additive]
instance has_mul [β i, has_mul $ f i] :
has_mul (Ξ i : I, f i) :=
β¨Ξ» f g i, f i * g iβ©
@[simp, to_additive] lemma mul_apply [β i, has_mul $ f i] : (x * y) i = x i * y i := rfl
@[to_additive] lemma mul_def [Ξ i, has_mul $ f i] : x * y = Ξ» i, x i * y i := rfl
@[simp, to_additive] lemma const_mul [has_mul Ξ²] (a b : Ξ²) :
const Ξ± a * const Ξ± b = const Ξ± (a * b) := rfl
@[to_additive] lemma mul_comp [has_mul Ξ³] (x y : Ξ² β Ξ³) (z : Ξ± β Ξ²) :
(x * y) β z = x β z * y β z := rfl
@[simp] lemma bit0_apply [Ξ i, has_add $ f i] : (bit0 x) i = bit0 (x i) := rfl
@[simp] lemma bit1_apply [Ξ i, has_add $ f i] [Ξ i, has_one $ f i] : (bit1 x) i = bit1 (x i) := rfl
@[to_additive] instance has_inv [β i, has_inv $ f i] :
has_inv (Ξ i : I, f i) :=
β¨Ξ» f i, (f i)β»ΒΉβ©
@[simp, to_additive] lemma inv_apply [β i, has_inv $ f i] : xβ»ΒΉ i = (x i)β»ΒΉ := rfl
@[to_additive] lemma inv_def [Ξ i, has_inv $ f i] : xβ»ΒΉ = Ξ» i, (x i)β»ΒΉ := rfl
@[to_additive] lemma const_inv [has_inv Ξ²] (a : Ξ²) : (const Ξ± a)β»ΒΉ = const Ξ± aβ»ΒΉ := rfl
@[to_additive] lemma inv_comp [has_inv Ξ³] (x : Ξ² β Ξ³) (y : Ξ± β Ξ²) : xβ»ΒΉ β y = (x β y)β»ΒΉ := rfl
@[to_additive] instance has_div [Ξ i, has_div $ f i] :
has_div (Ξ i : I, f i) :=
β¨Ξ» f g i, f i / g iβ©
@[simp, to_additive] lemma div_apply [Ξ i, has_div $ f i] : (x / y) i = x i / y i := rfl
@[to_additive] lemma div_def [Ξ i, has_div $ f i] : x / y = Ξ» i, x i / y i := rfl
@[to_additive] lemma div_comp [has_div Ξ³] (x y : Ξ² β Ξ³) (z : Ξ± β Ξ²) :
(x / y) β z = x β z / y β z := rfl
@[simp, to_additive] lemma const_div [has_div Ξ²] (a b : Ξ²) :
const Ξ± a / const Ξ± b = const Ξ± (a / b) := rfl
section
variables [decidable_eq I]
variables [Ξ i, has_one (f i)] [Ξ i, has_one (g i)] [Ξ i, has_one (h i)]
/-- The function supported at `i`, with value `x` there, and `1` elsewhere. -/
@[to_additive pi.single "The function supported at `i`, with value `x` there, and `0` elsewhere." ]
def mul_single (i : I) (x : f i) : Ξ i, f i :=
function.update 1 i x
@[simp, to_additive]
lemma mul_single_eq_same (i : I) (x : f i) : mul_single i x i = x :=
function.update_same i x _
@[simp, to_additive]
lemma mul_single_eq_of_ne {i i' : I} (h : i' β i) (x : f i) : mul_single i x i' = 1 :=
function.update_noteq h x _
/-- Abbreviation for `mul_single_eq_of_ne h.symm`, for ease of use by `simp`. -/
@[simp, to_additive "Abbreviation for `single_eq_of_ne h.symm`, for ease of
use by `simp`."]
lemma mul_single_eq_of_ne' {i i' : I} (h : i β i') (x : f i) : mul_single i x i' = 1 :=
mul_single_eq_of_ne h.symm x
@[simp, to_additive]
lemma mul_single_one (i : I) : mul_single i (1 : f i) = 1 :=
function.update_eq_self _ _
/-- On non-dependent functions, `pi.mul_single` can be expressed as an `ite` -/
@[to_additive "On non-dependent functions, `pi.single` can be expressed as an `ite`"]
lemma mul_single_apply {Ξ² : Sort*} [has_one Ξ²] (i : I) (x : Ξ²) (i' : I) :
mul_single i x i' = if i' = i then x else 1 :=
function.update_apply 1 i x i'
/-- On non-dependent functions, `pi.mul_single` is symmetric in the two indices. -/
@[to_additive "On non-dependent functions, `pi.single` is symmetric in the two
indices."]
lemma mul_single_comm {Ξ² : Sort*} [has_one Ξ²] (i : I) (x : Ξ²) (i' : I) :
mul_single i x i' = mul_single i' x i :=
by simp [mul_single_apply, eq_comm]
@[to_additive]
lemma apply_mul_single (f' : Ξ i, f i β g i) (hf' : β i, f' i 1 = 1) (i : I) (x : f i) (j : I):
f' j (mul_single i x j) = mul_single i (f' i x) j :=
by simpa only [pi.one_apply, hf', mul_single] using function.apply_update f' 1 i x j
@[to_additive apply_singleβ]
lemma apply_mul_singleβ (f' : Ξ i, f i β g i β h i) (hf' : β i, f' i 1 1 = 1)
(i : I) (x : f i) (y : g i) (j : I):
f' j (mul_single i x j) (mul_single i y j) = mul_single i (f' i x y) j :=
begin
by_cases h : j = i,
{ subst h, simp only [mul_single_eq_same] },
{ simp only [mul_single_eq_of_ne h, hf'] },
end
@[to_additive]
lemma mul_single_op {g : I β Type*} [Ξ i, has_one (g i)] (op : Ξ i, f i β g i) (h : β i, op i 1 = 1)
(i : I) (x : f i) :
mul_single i (op i x) = Ξ» j, op j (mul_single i x j) :=
eq.symm $ funext $ apply_mul_single op h i x
@[to_additive]
lemma mul_single_opβ {gβ gβ : I β Type*} [Ξ i, has_one (gβ i)] [Ξ i, has_one (gβ i)]
(op : Ξ i, gβ i β gβ i β f i) (h : β i, op i 1 1 = 1) (i : I) (xβ : gβ i) (xβ : gβ i) :
mul_single i (op i xβ xβ) = Ξ» j, op j (mul_single i xβ j) (mul_single i xβ j) :=
eq.symm $ funext $ apply_mul_singleβ op h i xβ xβ
variables (f)
@[to_additive]
lemma mul_single_injective (i : I) : function.injective (mul_single i : f i β Ξ i, f i) :=
function.update_injective _ i
@[simp, to_additive]
lemma mul_single_inj (i : I) {x y : f i} : mul_single i x = mul_single i y β x = y :=
(pi.mul_single_injective _ _).eq_iff
end
/-- The mapping into a product type built from maps into each component. -/
@[simp] protected def prod (f' : Ξ i, f i) (g' : Ξ i, g i) (i : I) : f i Γ g i := (f' i, g' i)
@[simp] lemma prod_fst_snd : pi.prod (prod.fst : Ξ± Γ Ξ² β Ξ±) (prod.snd : Ξ± Γ Ξ² β Ξ²) = id :=
funext $ Ξ» _, prod.mk.eta
@[simp] lemma prod_snd_fst : pi.prod (prod.snd : Ξ± Γ Ξ² β Ξ²) (prod.fst : Ξ± Γ Ξ² β Ξ±) = prod.swap :=
rfl
end pi
namespace function
section extend
@[to_additive]
lemma extend_one [has_one Ξ³] (f : Ξ± β Ξ²) :
function.extend f (1 : Ξ± β Ξ³) (1 : Ξ² β Ξ³) = 1 :=
funext $ Ξ» _, by apply if_t_t _ _
@[to_additive]
lemma extend_mul [has_mul Ξ³] (f : Ξ± β Ξ²) (gβ gβ : Ξ± β Ξ³) (eβ eβ : Ξ² β Ξ³) :
function.extend f (gβ * gβ) (eβ * eβ) = function.extend f gβ eβ * function.extend f gβ eβ :=
funext $ Ξ» _, by convert (apply_dite2 (*) _ _ _ _ _).symm
@[to_additive]
lemma extend_inv [has_inv Ξ³] (f : Ξ± β Ξ²) (g : Ξ± β Ξ³) (e : Ξ² β Ξ³) :
function.extend f (gβ»ΒΉ) (eβ»ΒΉ) = (function.extend f g e)β»ΒΉ :=
funext $ Ξ» _, by convert (apply_dite has_inv.inv _ _ _).symm
@[to_additive]
lemma extend_div [has_div Ξ³] (f : Ξ± β Ξ²) (gβ gβ : Ξ± β Ξ³) (eβ eβ : Ξ² β Ξ³) :
function.extend f (gβ / gβ) (eβ / eβ) = function.extend f gβ eβ / function.extend f gβ eβ :=
funext $ Ξ» _, by convert (apply_dite2 (/) _ _ _ _ _).symm
end extend
lemma surjective_pi_map {F : Ξ i, f i β g i} (hF : β i, surjective (F i)) :
surjective (Ξ» x : Ξ i, f i, Ξ» i, F i (x i)) :=
Ξ» y, β¨Ξ» i, (hF i (y i)).some, funext $ Ξ» i, (hF i (y i)).some_specβ©
lemma injective_pi_map {F : Ξ i, f i β g i} (hF : β i, injective (F i)) :
injective (Ξ» x : Ξ i, f i, Ξ» i, F i (x i)) :=
Ξ» x y h, funext $ Ξ» i, hF i $ (congr_fun h i : _)
lemma bijective_pi_map {F : Ξ i, f i β g i} (hF : β i, bijective (F i)) :
bijective (Ξ» x : Ξ i, f i, Ξ» i, F i (x i)) :=
β¨injective_pi_map (Ξ» i, (hF i).injective), surjective_pi_map (Ξ» i, (hF i).surjective)β©
end function
/-- If the one function is surjective, the codomain is trivial. -/
@[to_additive "If the zero function is surjective, the codomain is trivial."]
def unique_of_surjective_one (Ξ± : Type*) {Ξ² : Type*} [has_one Ξ²]
(h : function.surjective (1 : Ξ± β Ξ²)) : unique Ξ² :=
h.unique_of_surjective_const Ξ± (1 : Ξ²)
@[to_additive subsingleton.pi_single_eq]
lemma subsingleton.pi_mul_single_eq {Ξ± : Type*} [decidable_eq I] [subsingleton I] [has_one Ξ±]
(i : I) (x : Ξ±) :
pi.mul_single i x = Ξ» _, x :=
funext $ Ξ» j, by rw [subsingleton.elim j i, pi.mul_single_eq_same]
|
19d441405d3f29be064726cf305bd9f48352be7a
|
1dd482be3f611941db7801003235dc84147ec60a
|
/src/data/finset.lean
|
880287d86b0bb5805afc1e3a65648923030529d7
|
[
"Apache-2.0"
] |
permissive
|
sanderdahmen/mathlib
|
479039302bd66434bb5672c2a4cecf8d69981458
|
8f0eae75cd2d8b7a083cf935666fcce4565df076
|
refs/heads/master
| 1,587,491,322,775
| 1,549,672,060,000
| 1,549,672,060,000
| 169,748,224
| 0
| 0
|
Apache-2.0
| 1,549,636,694,000
| 1,549,636,694,000
| null |
UTF-8
|
Lean
| false
| false
| 78,118
|
lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
Finite sets.
-/
import logic.embedding order.boolean_algebra algebra.order_functions
data.multiset data.sigma.basic data.set.lattice
open multiset subtype nat lattice
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*}
/-- `finset Ξ±` is the type of finite sets of elements of `Ξ±`. It is implemented
as a multiset (a list up to permutation) which has no duplicate elements. -/
structure finset (Ξ± : Type*) :=
(val : multiset Ξ±)
(nodup : nodup val)
namespace finset
theorem eq_of_veq : β {s t : finset Ξ±}, s.1 = t.1 β s = t
| β¨s, _β© β¨t, _β© rfl := rfl
@[simp] theorem val_inj {s t : finset Ξ±} : s.1 = t.1 β s = t :=
β¨eq_of_veq, congr_arg _β©
@[simp] theorem erase_dup_eq_self [decidable_eq Ξ±] (s : finset Ξ±) : erase_dup s.1 = s.1 :=
erase_dup_eq_self.2 s.2
instance has_decidable_eq [decidable_eq Ξ±] : decidable_eq (finset Ξ±)
| sβ sβ := decidable_of_iff _ val_inj
/- membership -/
instance : has_mem Ξ± (finset Ξ±) := β¨Ξ» a s, a β s.1β©
theorem mem_def {a : Ξ±} {s : finset Ξ±} : a β s β a β s.1 := iff.rfl
@[simp] theorem mem_mk {a : Ξ±} {s nd} : a β @finset.mk Ξ± s nd β a β s := iff.rfl
instance decidable_mem [h : decidable_eq Ξ±] (a : Ξ±) (s : finset Ξ±) : decidable (a β s) :=
multiset.decidable_mem _ _
/- set coercion -/
/-- Convert a finset to a set in the natural way. -/
def to_set (s : finset Ξ±) : set Ξ± := {x | x β s}
instance : has_lift (finset Ξ±) (set Ξ±) := β¨to_setβ©
@[simp] lemma mem_coe {a : Ξ±} {s : finset Ξ±} : a β (βs : set Ξ±) β a β s := iff.rfl
@[simp] lemma set_of_mem {Ξ±} {s : finset Ξ±} : {a | a β s} = βs := rfl
/- extensionality -/
theorem ext {sβ sβ : finset Ξ±} : sβ = sβ β β a, a β sβ β a β sβ :=
val_inj.symm.trans $ nodup_ext sβ.2 sβ.2
@[extensionality]
theorem ext' {sβ sβ : finset Ξ±} : (β a, a β sβ β a β sβ) β sβ = sβ :=
ext.2
@[simp] theorem coe_inj {sβ sβ : finset Ξ±} : (βsβ : set Ξ±) = βsβ β sβ = sβ :=
(set.ext_iff _ _).trans ext.symm
/- subset -/
instance : has_subset (finset Ξ±) := β¨Ξ» sβ sβ, β β¦aβ¦, a β sβ β a β sββ©
theorem subset_def {sβ sβ : finset Ξ±} : sβ β sβ β sβ.1 β sβ.1 := iff.rfl
@[simp] theorem subset.refl (s : finset Ξ±) : s β s := subset.refl _
theorem subset.trans {sβ sβ sβ : finset Ξ±} : sβ β sβ β sβ β sβ β sβ β sβ := subset.trans
theorem mem_of_subset {sβ sβ : finset Ξ±} {a : Ξ±} : sβ β sβ β a β sβ β a β sβ := mem_of_subset
theorem subset.antisymm {sβ sβ : finset Ξ±} (Hβ : sβ β sβ) (Hβ : sβ β sβ) : sβ = sβ :=
ext.2 $ Ξ» a, β¨@Hβ a, @Hβ aβ©
theorem subset_iff {sβ sβ : finset Ξ±} : sβ β sβ β β β¦xβ¦, x β sβ β x β sβ := iff.rfl
@[simp] theorem coe_subset {sβ sβ : finset Ξ±} :
(βsβ : set Ξ±) β βsβ β sβ β sβ := iff.rfl
@[simp] theorem val_le_iff {sβ sβ : finset Ξ±} : sβ.1 β€ sβ.1 β sβ β sβ := le_iff_subset sβ.2
instance : has_ssubset (finset Ξ±) := β¨Ξ»a b, a β b β§ Β¬ b β aβ©
instance : partial_order (finset Ξ±) :=
{ le := (β),
lt := (β),
le_refl := subset.refl,
le_trans := @subset.trans _,
le_antisymm := @subset.antisymm _ }
theorem subset.antisymm_iff {sβ sβ : finset Ξ±} : sβ = sβ β sβ β sβ β§ sβ β sβ :=
le_antisymm_iff
@[simp] theorem le_iff_subset {sβ sβ : finset Ξ±} : sβ β€ sβ β sβ β sβ := iff.rfl
@[simp] theorem lt_iff_ssubset {sβ sβ : finset Ξ±} : sβ < sβ β sβ β sβ := iff.rfl
@[simp] lemma coe_ssubset {sβ sβ : finset Ξ±} : (βsβ : set Ξ±) β βsβ β sβ β sβ :=
show (βsβ : set Ξ±) β βsβ β sβ β sβ β§ Β¬sβ β sβ,
by simp only [set.ssubset_iff_subset_not_subset, finset.coe_subset]
@[simp] theorem val_lt_iff {sβ sβ : finset Ξ±} : sβ.1 < sβ.1 β sβ β sβ :=
and_congr val_le_iff $ not_congr val_le_iff
/- empty -/
protected def empty : finset Ξ± := β¨0, nodup_zeroβ©
instance : has_emptyc (finset Ξ±) := β¨finset.emptyβ©
instance : inhabited (finset Ξ±) := β¨β
β©
@[simp] theorem empty_val : (β
: finset Ξ±).1 = 0 := rfl
@[simp] theorem not_mem_empty (a : Ξ±) : a β (β
: finset Ξ±) := id
@[simp] theorem ne_empty_of_mem {a : Ξ±} {s : finset Ξ±} (h : a β s) : s β β
| e := not_mem_empty a $ e βΈ h
@[simp] theorem empty_subset (s : finset Ξ±) : β
β s := zero_subset _
theorem eq_empty_of_forall_not_mem {s : finset Ξ±} (H : βx, x β s) : s = β
:=
eq_of_veq (eq_zero_of_forall_not_mem H)
lemma eq_empty_iff_forall_not_mem {s : finset Ξ±} : s = β
β β x, x β s :=
β¨by rintro rfl x; exact id, Ξ» h, eq_empty_of_forall_not_mem hβ©
@[simp] theorem val_eq_zero {s : finset Ξ±} : s.1 = 0 β s = β
:= @val_inj _ s β
theorem subset_empty {s : finset Ξ±} : s β β
β s = β
:= subset_zero.trans val_eq_zero
theorem exists_mem_of_ne_empty {s : finset Ξ±} (h : s β β
) : β a : Ξ±, a β s :=
exists_mem_of_ne_zero (mt val_eq_zero.1 h)
@[simp] lemma coe_empty : β(β
: finset Ξ±) = (β
: set Ξ±) := rfl
/-- `singleton a` is the set `{a}` containing `a` and nothing else. -/
def singleton (a : Ξ±) : finset Ξ± := β¨_, nodup_singleton aβ©
local prefix `ΞΉ`:90 := singleton
@[simp] theorem singleton_val (a : Ξ±) : (ΞΉ a).1 = a :: 0 := rfl
@[simp] theorem mem_singleton {a b : Ξ±} : b β ΞΉ a β b = a := mem_singleton
theorem not_mem_singleton {a b : Ξ±} : a β ΞΉ b β a β b := not_iff_not_of_iff mem_singleton
theorem mem_singleton_self (a : Ξ±) : a β ΞΉ a := or.inl rfl
theorem singleton_inj {a b : Ξ±} : ΞΉ a = ΞΉ b β a = b :=
β¨Ξ» h, mem_singleton.1 (h βΈ mem_singleton_self _), congr_arg _β©
@[simp] theorem singleton_ne_empty (a : Ξ±) : ΞΉ a β β
:= ne_empty_of_mem (mem_singleton_self _)
@[simp] lemma coe_singleton (a : Ξ±) : β(ΞΉ a) = ({a} : set Ξ±) := rfl
/- insert -/
section decidable_eq
variables [decidable_eq Ξ±]
/-- `insert a s` is the set `{a} βͺ s` containing `a` and the elements of `s`. -/
instance : has_insert Ξ± (finset Ξ±) := β¨Ξ» a s, β¨_, nodup_ndinsert a s.2β©β©
@[simp] theorem has_insert_eq_insert (a : Ξ±) (s : finset Ξ±) : has_insert.insert a s = insert a s := rfl
theorem insert_def (a : Ξ±) (s : finset Ξ±) : insert a s = β¨_, nodup_ndinsert a s.2β© := rfl
@[simp] theorem insert_val (a : Ξ±) (s : finset Ξ±) : (insert a s).1 = ndinsert a s.1 := rfl
theorem insert_val' (a : Ξ±) (s : finset Ξ±) : (insert a s).1 = erase_dup (a :: s.1) :=
by rw [erase_dup_cons, erase_dup_eq_self]; refl
theorem insert_val_of_not_mem {a : Ξ±} {s : finset Ξ±} (h : a β s) : (insert a s).1 = a :: s.1 :=
by rw [insert_val, ndinsert_of_not_mem h]
@[simp] theorem mem_insert {a b : Ξ±} {s : finset Ξ±} : a β insert b s β a = b β¨ a β s := mem_ndinsert
theorem mem_insert_self (a : Ξ±) (s : finset Ξ±) : a β insert a s := mem_ndinsert_self a s.1
theorem mem_insert_of_mem {a b : Ξ±} {s : finset Ξ±} (h : a β s) : a β insert b s := mem_ndinsert_of_mem h
theorem mem_of_mem_insert_of_ne {a b : Ξ±} {s : finset Ξ±} (h : b β insert a s) : b β a β b β s :=
(mem_insert.1 h).resolve_left
@[simp] lemma coe_insert (a : Ξ±) (s : finset Ξ±) : β(insert a s) = (insert a βs : set Ξ±) :=
set.ext $ Ξ» x, by simp only [mem_coe, mem_insert, set.mem_insert_iff]
@[simp] theorem insert_eq_of_mem {a : Ξ±} {s : finset Ξ±} (h : a β s) : insert a s = s :=
eq_of_veq $ ndinsert_of_mem h
theorem insert.comm (a b : Ξ±) (s : finset Ξ±) : insert a (insert b s) = insert b (insert a s) :=
ext.2 $ Ξ» x, by simp only [finset.mem_insert, or.left_comm]
@[simp] theorem insert_idem (a : Ξ±) (s : finset Ξ±) : insert a (insert a s) = insert a s :=
ext.2 $ Ξ» x, by simp only [finset.mem_insert, or.assoc.symm, or_self]
@[simp] theorem insert_ne_empty (a : Ξ±) (s : finset Ξ±) : insert a s β β
:=
ne_empty_of_mem (mem_insert_self a s)
theorem insert_subset {a : Ξ±} {s t : finset Ξ±} : insert a s β t β a β t β§ s β t :=
by simp only [subset_iff, mem_insert, forall_eq, or_imp_distrib, forall_and_distrib]
theorem subset_insert [h : decidable_eq Ξ±] (a : Ξ±) (s : finset Ξ±) : s β insert a s :=
Ξ» b, mem_insert_of_mem
theorem insert_subset_insert (a : Ξ±) {s t : finset Ξ±} (h : s β t) : insert a s β insert a t :=
insert_subset.2 β¨mem_insert_self _ _, subset.trans h (subset_insert _ _)β©
lemma ssubset_iff {s t : finset Ξ±} : s β t β (βa, a β s β§ insert a s β t) :=
iff.intro
(assume β¨hβ, hββ©,
have βa β t, a β s, by simpa only [finset.subset_iff, classical.not_forall] using hβ,
let β¨a, hat, hasβ© := this in β¨a, has, insert_subset.mpr β¨hat, hββ©β©)
(assume β¨a, hat, hasβ©,
let β¨hβ, hββ© := insert_subset.mp has in
β¨hβ, assume h, hat $ h hββ©)
lemma ssubset_insert {s : finset Ξ±} {a : Ξ±} (h : a β s) : s β insert a s :=
ssubset_iff.mpr β¨a, h, subset.refl _β©
@[recursor 6] protected theorem induction {Ξ± : Type*} {p : finset Ξ± β Prop} [decidable_eq Ξ±]
(hβ : p β
) (hβ : β β¦a : Ξ±β¦ {s : finset Ξ±}, a β s β p s β p (insert a s)) : β s, p s
| β¨s, ndβ© := multiset.induction_on s (Ξ» _, hβ) (Ξ» a s IH nd, begin
cases nodup_cons.1 nd with m nd',
rw [β (eq_of_veq _ : insert a (finset.mk s _) = β¨a::s, ndβ©)],
{ exact hβ (by exact m) (IH nd') },
{ rw [insert_val, ndinsert_of_not_mem m] }
end) nd
@[elab_as_eliminator] protected theorem induction_on {Ξ± : Type*} {p : finset Ξ± β Prop} [decidable_eq Ξ±]
(s : finset Ξ±) (hβ : p β
) (hβ : β β¦a : Ξ±β¦ {s : finset Ξ±}, a β s β p s β p (insert a s)) : p s :=
finset.induction hβ hβ s
@[simp] theorem singleton_eq_singleton (a : Ξ±) : _root_.singleton a = ΞΉ a := rfl
@[simp] theorem insert_empty_eq_singleton (a : Ξ±) : {a} = ΞΉ a := rfl
@[simp] theorem insert_singleton_self_eq (a : Ξ±) : ({a, a} : finset Ξ±) = ΞΉ a :=
insert_eq_of_mem $ mem_singleton_self _
/- union -/
/-- `s βͺ t` is the set such that `a β s βͺ t` iff `a β s` or `a β t`. -/
instance : has_union (finset Ξ±) := β¨Ξ» sβ sβ, β¨_, nodup_ndunion sβ.1 sβ.2β©β©
theorem union_val_nd (sβ sβ : finset Ξ±) : (sβ βͺ sβ).1 = ndunion sβ.1 sβ.1 := rfl
@[simp] theorem union_val (sβ sβ : finset Ξ±) : (sβ βͺ sβ).1 = sβ.1 βͺ sβ.1 :=
ndunion_eq_union sβ.2
@[simp] theorem mem_union {a : Ξ±} {sβ sβ : finset Ξ±} : a β sβ βͺ sβ β a β sβ β¨ a β sβ := mem_ndunion
theorem mem_union_left {a : Ξ±} {sβ : finset Ξ±} (sβ : finset Ξ±) (h : a β sβ) : a β sβ βͺ sβ := mem_union.2 $ or.inl h
theorem mem_union_right {a : Ξ±} {sβ : finset Ξ±} (sβ : finset Ξ±) (h : a β sβ) : a β sβ βͺ sβ := mem_union.2 $ or.inr h
theorem not_mem_union {a : Ξ±} {sβ sβ : finset Ξ±} : a β sβ βͺ sβ β a β sβ β§ a β sβ :=
by rw [mem_union, not_or_distrib]
@[simp] lemma coe_union (sβ sβ : finset Ξ±) : β(sβ βͺ sβ) = (βsβ βͺ βsβ : set Ξ±) := set.ext $ Ξ» x, mem_union
theorem union_subset {sβ sβ sβ : finset Ξ±} (hβ : sβ β sβ) (hβ : sβ β sβ) : sβ βͺ sβ β sβ :=
val_le_iff.1 (ndunion_le.2 β¨hβ, val_le_iff.2 hββ©)
theorem subset_union_left (sβ sβ : finset Ξ±) : sβ β sβ βͺ sβ := Ξ» x, mem_union_left _
theorem subset_union_right (sβ sβ : finset Ξ±) : sβ β sβ βͺ sβ := Ξ» x, mem_union_right _
@[simp] theorem union_comm (sβ sβ : finset Ξ±) : sβ βͺ sβ = sβ βͺ sβ :=
ext.2 $ Ξ» x, by simp only [mem_union, or_comm]
instance : is_commutative (finset Ξ±) (βͺ) := β¨union_commβ©
@[simp] theorem union_assoc (sβ sβ sβ : finset Ξ±) : (sβ βͺ sβ) βͺ sβ = sβ βͺ (sβ βͺ sβ) :=
ext.2 $ Ξ» x, by simp only [mem_union, or_assoc]
instance : is_associative (finset Ξ±) (βͺ) := β¨union_assocβ©
@[simp] theorem union_idempotent (s : finset Ξ±) : s βͺ s = s :=
ext.2 $ Ξ» _, mem_union.trans $ or_self _
instance : is_idempotent (finset Ξ±) (βͺ) := β¨union_idempotentβ©
theorem union_left_comm (sβ sβ sβ : finset Ξ±) : sβ βͺ (sβ βͺ sβ) = sβ βͺ (sβ βͺ sβ) :=
ext.2 $ Ξ» _, by simp only [mem_union, or.left_comm]
theorem union_right_comm (sβ sβ sβ : finset Ξ±) : (sβ βͺ sβ) βͺ sβ = (sβ βͺ sβ) βͺ sβ :=
ext.2 $ Ξ» x, by simp only [mem_union, or_assoc, or_comm (x β sβ)]
@[simp] theorem union_self (s : finset Ξ±) : s βͺ s = s := union_idempotent s
@[simp] theorem union_empty (s : finset Ξ±) : s βͺ β
= s :=
ext.2 $ Ξ» x, mem_union.trans $ or_false _
@[simp] theorem empty_union (s : finset Ξ±) : β
βͺ s = s :=
ext.2 $ Ξ» x, mem_union.trans $ false_or _
theorem insert_eq (a : Ξ±) (s : finset Ξ±) : insert a s = {a} βͺ s := rfl
@[simp] theorem insert_union (a : Ξ±) (s t : finset Ξ±) : insert a s βͺ t = insert a (s βͺ t) :=
by simp only [insert_eq, union_assoc]
@[simp] theorem union_insert (a : Ξ±) (s t : finset Ξ±) : s βͺ insert a t = insert a (s βͺ t) :=
by simp only [insert_eq, union_left_comm]
theorem insert_union_distrib (a : Ξ±) (s t : finset Ξ±) : insert a (s βͺ t) = insert a s βͺ insert a t :=
by simp only [insert_union, union_insert, insert_idem]
/- inter -/
/-- `s β© t` is the set such that `a β s β© t` iff `a β s` and `a β t`. -/
instance : has_inter (finset Ξ±) := β¨Ξ» sβ sβ, β¨_, nodup_ndinter sβ.1 sβ.2β©β©
theorem inter_val_nd (sβ sβ : finset Ξ±) : (sβ β© sβ).1 = ndinter sβ.1 sβ.1 := rfl
@[simp] theorem inter_val (sβ sβ : finset Ξ±) : (sβ β© sβ).1 = sβ.1 β© sβ.1 :=
ndinter_eq_inter sβ.2
@[simp] theorem mem_inter {a : Ξ±} {sβ sβ : finset Ξ±} : a β sβ β© sβ β a β sβ β§ a β sβ := mem_ndinter
theorem mem_of_mem_inter_left {a : Ξ±} {sβ sβ : finset Ξ±} (h : a β sβ β© sβ) : a β sβ := (mem_inter.1 h).1
theorem mem_of_mem_inter_right {a : Ξ±} {sβ sβ : finset Ξ±} (h : a β sβ β© sβ) : a β sβ := (mem_inter.1 h).2
theorem mem_inter_of_mem {a : Ξ±} {sβ sβ : finset Ξ±} : a β sβ β a β sβ β a β sβ β© sβ :=
and_imp.1 mem_inter.2
theorem inter_subset_left (sβ sβ : finset Ξ±) : sβ β© sβ β sβ := Ξ» a, mem_of_mem_inter_left
theorem inter_subset_right (sβ sβ : finset Ξ±) : sβ β© sβ β sβ := Ξ» a, mem_of_mem_inter_right
theorem subset_inter {sβ sβ sβ : finset Ξ±} : sβ β sβ β sβ β sβ β sβ β sβ β© sβ :=
by simp only [subset_iff, mem_inter] {contextual:=tt}; intros; split; trivial
@[simp] lemma coe_inter (sβ sβ : finset Ξ±) : β(sβ β© sβ) = (βsβ β© βsβ : set Ξ±) := set.ext $ Ξ» _, mem_inter
@[simp] theorem inter_comm (sβ sβ : finset Ξ±) : sβ β© sβ = sβ β© sβ :=
ext.2 $ Ξ» _, by simp only [mem_inter, and_comm]
@[simp] theorem inter_assoc (sβ sβ sβ : finset Ξ±) : (sβ β© sβ) β© sβ = sβ β© (sβ β© sβ) :=
ext.2 $ Ξ» _, by simp only [mem_inter, and_assoc]
@[simp] theorem inter_left_comm (sβ sβ sβ : finset Ξ±) : sβ β© (sβ β© sβ) = sβ β© (sβ β© sβ) :=
ext.2 $ Ξ» _, by simp only [mem_inter, and.left_comm]
@[simp] theorem inter_right_comm (sβ sβ sβ : finset Ξ±) : (sβ β© sβ) β© sβ = (sβ β© sβ) β© sβ :=
ext.2 $ Ξ» _, by simp only [mem_inter, and.right_comm]
@[simp] theorem inter_self (s : finset Ξ±) : s β© s = s :=
ext.2 $ Ξ» _, mem_inter.trans $ and_self _
@[simp] theorem inter_empty (s : finset Ξ±) : s β© β
= β
:=
ext.2 $ Ξ» _, mem_inter.trans $ and_false _
@[simp] theorem empty_inter (s : finset Ξ±) : β
β© s = β
:=
ext.2 $ Ξ» _, mem_inter.trans $ false_and _
@[simp] theorem insert_inter_of_mem {sβ sβ : finset Ξ±} {a : Ξ±} (h : a β sβ) :
insert a sβ β© sβ = insert a (sβ β© sβ) :=
ext.2 $ Ξ» x, have x = a β¨ x β sβ β x β sβ, from or_iff_right_of_imp $ by rintro rfl; exact h,
by simp only [mem_inter, mem_insert, or_and_distrib_left, this]
@[simp] theorem inter_insert_of_mem {sβ sβ : finset Ξ±} {a : Ξ±} (h : a β sβ) :
sβ β© insert a sβ = insert a (sβ β© sβ) :=
by rw [inter_comm, insert_inter_of_mem h, inter_comm]
@[simp] theorem insert_inter_of_not_mem {sβ sβ : finset Ξ±} {a : Ξ±} (h : a β sβ) :
insert a sβ β© sβ = sβ β© sβ :=
ext.2 $ Ξ» x, have Β¬ (x = a β§ x β sβ), by rintro β¨rfl, Hβ©; exact h H,
by simp only [mem_inter, mem_insert, or_and_distrib_right, this, false_or]
@[simp] theorem inter_insert_of_not_mem {sβ sβ : finset Ξ±} {a : Ξ±} (h : a β sβ) :
sβ β© insert a sβ = sβ β© sβ :=
by rw [inter_comm, insert_inter_of_not_mem h, inter_comm]
@[simp] theorem singleton_inter_of_mem {a : Ξ±} {s : finset Ξ±} (H : a β s) : ΞΉ a β© s = ΞΉ a :=
show insert a β
β© s = insert a β
, by rw [insert_inter_of_mem H, empty_inter]
@[simp] theorem singleton_inter_of_not_mem {a : Ξ±} {s : finset Ξ±} (H : a β s) : ΞΉ a β© s = β
:=
eq_empty_of_forall_not_mem $ by simp only [mem_inter, mem_singleton]; rintro x β¨rfl, hβ©; exact H h
@[simp] theorem inter_singleton_of_mem {a : Ξ±} {s : finset Ξ±} (h : a β s) : s β© ΞΉ a = ΞΉ a :=
by rw [inter_comm, singleton_inter_of_mem h]
@[simp] theorem inter_singleton_of_not_mem {a : Ξ±} {s : finset Ξ±} (h : a β s) : s β© ΞΉ a = β
:=
by rw [inter_comm, singleton_inter_of_not_mem h]
/- lattice laws -/
instance : lattice (finset Ξ±) :=
{ sup := (βͺ),
sup_le := assume a b c, union_subset,
le_sup_left := subset_union_left,
le_sup_right := subset_union_right,
inf := (β©),
le_inf := assume a b c, subset_inter,
inf_le_left := inter_subset_left,
inf_le_right := inter_subset_right,
..finset.partial_order }
@[simp] theorem sup_eq_union (s t : finset Ξ±) : s β t = s βͺ t := rfl
@[simp] theorem inf_eq_inter (s t : finset Ξ±) : s β t = s β© t := rfl
instance : semilattice_inf_bot (finset Ξ±) :=
{ bot := β
, bot_le := empty_subset, ..finset.lattice.lattice }
instance {Ξ± : Type*} [decidable_eq Ξ±] : semilattice_sup_bot (finset Ξ±) :=
{ ..finset.lattice.semilattice_inf_bot, ..finset.lattice.lattice }
instance : distrib_lattice (finset Ξ±) :=
{ le_sup_inf := assume a b c, show (a βͺ b) β© (a βͺ c) β a βͺ b β© c,
by simp only [subset_iff, mem_inter, mem_union, and_imp, or_imp_distrib] {contextual:=tt};
simp only [true_or, imp_true_iff, true_and, or_true],
..finset.lattice.lattice }
theorem inter_distrib_left (s t u : finset Ξ±) : s β© (t βͺ u) = (s β© t) βͺ (s β© u) := inf_sup_left
theorem inter_distrib_right (s t u : finset Ξ±) : (s βͺ t) β© u = (s β© u) βͺ (t β© u) := inf_sup_right
theorem union_distrib_left (s t u : finset Ξ±) : s βͺ (t β© u) = (s βͺ t) β© (s βͺ u) := sup_inf_left
theorem union_distrib_right (s t u : finset Ξ±) : (s β© t) βͺ u = (s βͺ u) β© (t βͺ u) := sup_inf_right
/- erase -/
/-- `erase s a` is the set `s - {a}`, that is, the elements of `s` which are
not equal to `a`. -/
def erase (s : finset Ξ±) (a : Ξ±) : finset Ξ± := β¨_, nodup_erase_of_nodup a s.2β©
@[simp] theorem erase_val (s : finset Ξ±) (a : Ξ±) : (erase s a).1 = s.1.erase a := rfl
@[simp] theorem mem_erase {a b : Ξ±} {s : finset Ξ±} : a β erase s b β a β b β§ a β s :=
mem_erase_iff_of_nodup s.2
theorem not_mem_erase (a : Ξ±) (s : finset Ξ±) : a β erase s a := mem_erase_of_nodup s.2
@[simp] theorem erase_empty (a : Ξ±) : erase β
a = β
:= rfl
theorem ne_of_mem_erase {a b : Ξ±} {s : finset Ξ±} : b β erase s a β b β a :=
by simp only [mem_erase]; exact and.left
theorem mem_of_mem_erase {a b : Ξ±} {s : finset Ξ±} : b β erase s a β b β s := mem_of_mem_erase
theorem mem_erase_of_ne_of_mem {a b : Ξ±} {s : finset Ξ±} : a β b β a β s β a β erase s b :=
by simp only [mem_erase]; exact and.intro
theorem erase_insert {a : Ξ±} {s : finset Ξ±} (h : a β s) : erase (insert a s) a = s :=
ext.2 $ assume x, by simp only [mem_erase, mem_insert, and_or_distrib_left, not_and_self, false_or];
apply and_iff_right_of_imp; rintro H rfl; exact h H
theorem insert_erase {a : Ξ±} {s : finset Ξ±} (h : a β s) : insert a (erase s a) = s :=
ext.2 $ assume x, by simp only [mem_insert, mem_erase, or_and_distrib_left, dec_em, true_and];
apply or_iff_right_of_imp; rintro rfl; exact h
theorem erase_subset_erase (a : Ξ±) {s t : finset Ξ±} (h : s β t) : erase s a β erase t a :=
val_le_iff.1 $ erase_le_erase _ $ val_le_iff.2 h
theorem erase_subset (a : Ξ±) (s : finset Ξ±) : erase s a β s := erase_subset _ _
@[simp] lemma coe_erase (a : Ξ±) (s : finset Ξ±) : β(erase s a) = (βs \ {a} : set Ξ±) :=
set.ext $ Ξ» _, mem_erase.trans $ by rw [and_comm, set.mem_diff, set.mem_singleton_iff]; refl
lemma erase_ssubset {a : Ξ±} {s : finset Ξ±} (h : a β s) : s.erase a β s :=
calc s.erase a β insert a (s.erase a) : ssubset_insert $ not_mem_erase _ _
... = _ : insert_erase h
theorem erase_eq_of_not_mem {a : Ξ±} {s : finset Ξ±} (h : a β s) : erase s a = s :=
eq_of_veq $ erase_of_not_mem h
theorem subset_insert_iff {a : Ξ±} {s t : finset Ξ±} : s β insert a t β erase s a β t :=
by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp];
exact forall_congr (Ξ» x, forall_swap)
theorem erase_insert_subset (a : Ξ±) (s : finset Ξ±) : erase (insert a s) a β s :=
subset_insert_iff.1 $ subset.refl _
theorem insert_erase_subset (a : Ξ±) (s : finset Ξ±) : s β insert a (erase s a) :=
subset_insert_iff.2 $ subset.refl _
/- sdiff -/
/-- `s \ t` is the set consisting of the elements of `s` that are not in `t`. -/
instance : has_sdiff (finset Ξ±) := β¨Ξ»sβ sβ, β¨sβ.1 - sβ.1, nodup_of_le (sub_le_self _ _) sβ.2β©β©
@[simp] theorem mem_sdiff {a : Ξ±} {sβ sβ : finset Ξ±} :
a β sβ \ sβ β a β sβ β§ a β sβ := mem_sub_of_nodup sβ.2
@[simp] theorem sdiff_union_of_subset {sβ sβ : finset Ξ±} (h : sβ β sβ) : (sβ \ sβ) βͺ sβ = sβ :=
ext.2 $ Ξ» a, by simpa only [mem_sdiff, mem_union, or_comm,
or_and_distrib_left, dec_em, and_true] using or_iff_right_of_imp (@h a)
@[simp] theorem union_sdiff_of_subset {sβ sβ : finset Ξ±} (h : sβ β sβ) : sβ βͺ (sβ \ sβ) = sβ :=
(union_comm _ _).trans (sdiff_union_of_subset h)
@[simp] theorem inter_sdiff_self (sβ sβ : finset Ξ±) : sβ β© (sβ \ sβ) = β
:=
eq_empty_of_forall_not_mem $
by simp only [mem_inter, mem_sdiff]; rintro x β¨h, _, hnβ©; exact hn h
@[simp] theorem sdiff_inter_self (sβ sβ : finset Ξ±) : (sβ \ sβ) β© sβ = β
:=
(inter_comm _ _).trans (inter_sdiff_self _ _)
theorem sdiff_subset_sdiff {sβ sβ tβ tβ : finset Ξ±} (hβ : tβ β tβ) (hβ : sβ β sβ) : tβ \ sβ β tβ \ sβ :=
by simpa only [subset_iff, mem_sdiff, and_imp] using Ξ» a mβ mβ, and.intro (hβ mβ) (mt (@hβ _) mβ)
@[simp] lemma coe_sdiff (sβ sβ : finset Ξ±) : β(sβ \ sβ) = (βsβ \ βsβ : set Ξ±) :=
set.ext $ Ξ» _, mem_sdiff
end decidable_eq
/- attach -/
/-- `attach s` takes the elements of `s` and forms a new set of elements of the
subtype `{x // x β s}`. -/
def attach (s : finset Ξ±) : finset {x // x β s} := β¨attach s.1, nodup_attach.2 s.2β©
@[simp] theorem attach_val (s : finset Ξ±) : s.attach.1 = s.1.attach := rfl
@[simp] theorem mem_attach (s : finset Ξ±) : β x, x β s.attach := mem_attach _
@[simp] theorem attach_empty : attach (β
: finset Ξ±) = β
:= rfl
section decidable_pi_exists
variables {s : finset Ξ±}
instance decidable_dforall_finset {p : Ξ aβs, Prop} [hp : βa (h : a β s), decidable (p a h)] :
decidable (βa (h : a β s), p a h) :=
multiset.decidable_dforall_multiset
/-- decidable equality for functions whose domain is bounded by finsets -/
instance decidable_eq_pi_finset {Ξ² : Ξ± β Type*} [h : βa, decidable_eq (Ξ² a)] :
decidable_eq (Ξ aβs, Ξ² a) :=
multiset.decidable_eq_pi_multiset
instance decidable_dexists_finset {p : Ξ aβs, Prop} [hp : βa (h : a β s), decidable (p a h)] :
decidable (βa (h : a β s), p a h) :=
multiset.decidable_dexists_multiset
end decidable_pi_exists
/- filter -/
section filter
variables {p q : Ξ± β Prop} [decidable_pred p] [decidable_pred q]
/-- `filter p s` is the set of elements of `s` that satisfy `p`. -/
def filter (p : Ξ± β Prop) [decidable_pred p] (s : finset Ξ±) : finset Ξ± :=
β¨_, nodup_filter p s.2β©
@[simp] theorem filter_val (s : finset Ξ±) : (filter p s).1 = s.1.filter p := rfl
@[simp] theorem mem_filter {s : finset Ξ±} {a : Ξ±} : a β s.filter p β a β s β§ p a := mem_filter
@[simp] theorem filter_subset (s : finset Ξ±) : s.filter p β s := filter_subset _
theorem filter_filter (s : finset Ξ±) :
(s.filter p).filter q = s.filter (Ξ»a, p a β§ q a) :=
ext.2 $ assume a, by simp only [mem_filter, and_comm, and.left_comm]
@[simp] lemma filter_true {s : finset Ξ±} [h : decidable_pred (Ξ» _, true)] :
@finset.filter Ξ± (Ξ» _, true) h s = s :=
by ext; simp
@[simp] theorem filter_false {h} (s : finset Ξ±) : @filter Ξ± (Ξ»a, false) h s = β
:=
ext.2 $ assume a, by simp only [mem_filter, and_false]; refl
lemma filter_congr {s : finset Ξ±} (H : β x β s, p x β q x) : filter p s = filter q s :=
eq_of_veq $ filter_congr H
variable [decidable_eq Ξ±]
theorem filter_union (sβ sβ : finset Ξ±) :
(sβ βͺ sβ).filter p = sβ.filter p βͺ sβ.filter p :=
ext.2 $ Ξ» _, by simp only [mem_filter, mem_union, or_and_distrib_right]
theorem filter_or (s : finset Ξ±) : s.filter (Ξ» a, p a β¨ q a) = s.filter p βͺ s.filter q :=
ext.2 $ Ξ» _, by simp only [mem_filter, mem_union, and_or_distrib_left]
theorem filter_and (s : finset Ξ±) : s.filter (Ξ» a, p a β§ q a) = s.filter p β© s.filter q :=
ext.2 $ Ξ» _, by simp only [mem_filter, mem_inter, and_comm, and.left_comm, and_self]
theorem filter_not (s : finset Ξ±) : s.filter (Ξ» a, Β¬ p a) = s \ s.filter p :=
ext.2 $ by simpa only [mem_filter, mem_sdiff, and_comm, not_and] using Ξ» a, and_congr_right $
Ξ» h : a β s, (imp_iff_right h).symm.trans imp_not_comm
theorem sdiff_eq_filter (sβ sβ : finset Ξ±) :
sβ \ sβ = filter (β sβ) sβ := ext.2 $ Ξ» _, by simp only [mem_sdiff, mem_filter]
theorem filter_union_filter_neg_eq (s : finset Ξ±) : s.filter p βͺ s.filter (Ξ»a, Β¬ p a) = s :=
by simp only [filter_not, union_sdiff_of_subset (filter_subset s)]
theorem filter_inter_filter_neg_eq (s : finset Ξ±) : s.filter p β© s.filter (Ξ»a, Β¬ p a) = β
:=
by simp only [filter_not, inter_sdiff_self]
@[simp] lemma coe_filter (s : finset Ξ±) : β(s.filter p) = ({x β βs | p x} : set Ξ±) :=
set.ext $ Ξ» _, mem_filter
end filter
/- range -/
section range
variables {n m l : β}
/-- `range n` is the set of natural numbers less than `n`. -/
def range (n : β) : finset β := β¨_, nodup_range nβ©
@[simp] theorem range_val (n : β) : (range n).1 = multiset.range n := rfl
@[simp] theorem mem_range : m β range n β m < n := mem_range
@[simp] theorem range_zero : range 0 = β
:= rfl
@[simp] theorem range_one : range 1 = {0} := rfl
theorem range_succ : range (succ n) = insert n (range n) :=
eq_of_veq $ (range_succ n).trans $ (ndinsert_of_not_mem not_mem_range_self).symm
theorem range_add_one : range (n + 1) = insert n (range n) :=
range_succ
@[simp] theorem not_mem_range_self : n β range n := not_mem_range_self
@[simp] theorem range_subset {n m} : range n β range m β n β€ m := range_subset
theorem exists_nat_subset_range (s : finset β) : βn : β, s β range n :=
finset.induction_on s β¨0, empty_subset _β© $ Ξ» a s ha β¨n, hnβ©,
β¨max (a + 1) n, insert_subset.2
β¨by simpa only [mem_range] using le_max_left (a+1) n,
subset.trans hn (by simpa only [range_subset] using le_max_right (a+1) n)β©β©
end range
/- useful rules for calculations with quantifiers -/
theorem exists_mem_empty_iff (p : Ξ± β Prop) : (β x, x β (β
: finset Ξ±) β§ p x) β false :=
by simp only [not_mem_empty, false_and, exists_false]
theorem exists_mem_insert [d : decidable_eq Ξ±]
(a : Ξ±) (s : finset Ξ±) (p : Ξ± β Prop) :
(β x, x β insert a s β§ p x) β p a β¨ (β x, x β s β§ p x) :=
by simp only [mem_insert, or_and_distrib_right, exists_or_distrib, exists_eq_left]
theorem forall_mem_empty_iff (p : Ξ± β Prop) : (β x, x β (β
: finset Ξ±) β p x) β true :=
iff_true_intro $ Ξ» _, false.elim
theorem forall_mem_insert [d : decidable_eq Ξ±]
(a : Ξ±) (s : finset Ξ±) (p : Ξ± β Prop) :
(β x, x β insert a s β p x) β p a β§ (β x, x β s β p x) :=
by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq]
end finset
namespace option
/-- Construct an empty or singleton finset from an `option` -/
def to_finset (o : option Ξ±) : finset Ξ± :=
match o with
| none := β
| some a := finset.singleton a
end
@[simp] theorem to_finset_none : none.to_finset = (β
: finset Ξ±) := rfl
@[simp] theorem to_finset_some {a : Ξ±} : (some a).to_finset = finset.singleton a := rfl
@[simp] theorem mem_to_finset {a : Ξ±} {o : option Ξ±} : a β o.to_finset β a β o :=
by cases o; simp only [to_finset, finset.mem_singleton, option.mem_def, eq_comm]; refl
end option
/- erase_dup on list and multiset -/
namespace multiset
variable [decidable_eq Ξ±]
/-- `to_finset s` removes duplicates from the multiset `s` to produce a finset. -/
def to_finset (s : multiset Ξ±) : finset Ξ± := β¨_, nodup_erase_dup sβ©
@[simp] theorem to_finset_val (s : multiset Ξ±) : s.to_finset.1 = s.erase_dup := rfl
theorem to_finset_eq {s : multiset Ξ±} (n : nodup s) : finset.mk s n = s.to_finset :=
finset.val_inj.1 (erase_dup_eq_self.2 n).symm
@[simp] theorem mem_to_finset {a : Ξ±} {s : multiset Ξ±} : a β s.to_finset β a β s :=
mem_erase_dup
@[simp] lemma to_finset_zero :
to_finset (0 : multiset Ξ±) = β
:=
rfl
@[simp] lemma to_finset_cons (a : Ξ±) (s : multiset Ξ±) :
to_finset (a :: s) = insert a (to_finset s) :=
finset.eq_of_veq erase_dup_cons
@[simp] lemma to_finset_add (s t : multiset Ξ±) :
to_finset (s + t) = to_finset s βͺ to_finset t :=
finset.ext' $ by simp
end multiset
namespace list
variable [decidable_eq Ξ±]
/-- `to_finset l` removes duplicates from the list `l` to produce a finset. -/
def to_finset (l : list Ξ±) : finset Ξ± := multiset.to_finset l
@[simp] theorem to_finset_val (l : list Ξ±) : l.to_finset.1 = (l.erase_dup : multiset Ξ±) := rfl
theorem to_finset_eq {l : list Ξ±} (n : nodup l) : @finset.mk Ξ± l n = l.to_finset :=
multiset.to_finset_eq n
@[simp] theorem mem_to_finset {a : Ξ±} {l : list Ξ±} : a β l.to_finset β a β l :=
mem_erase_dup
@[simp] theorem to_finset_nil : to_finset (@nil Ξ±) = β
:=
rfl
@[simp] theorem to_finset_cons {a : Ξ±} {l : list Ξ±} : to_finset (a :: l) = insert a (to_finset l) :=
finset.eq_of_veq $ by by_cases h : a β l; simp [finset.insert_val', multiset.erase_dup_cons, h]
end list
namespace finset
section map
open function
def map (f : Ξ± βͺ Ξ²) (s : finset Ξ±) : finset Ξ² :=
β¨s.1.map f, nodup_map f.2 s.2β©
@[simp] theorem map_val (f : Ξ± βͺ Ξ²) (s : finset Ξ±) : (map f s).1 = s.1.map f := rfl
@[simp] theorem map_empty (f : Ξ± βͺ Ξ²) (s : finset Ξ±) : (β
: finset Ξ±).map f = β
:= rfl
variables {f : Ξ± βͺ Ξ²} {s : finset Ξ±}
@[simp] theorem mem_map {b : Ξ²} : b β s.map f β β a β s, f a = b :=
mem_map.trans $ by simp only [exists_prop]; refl
theorem mem_map' (f : Ξ± βͺ Ξ²) {a} {s : finset Ξ±} : f a β s.map f β a β s :=
mem_map_of_inj f.2
@[simp] theorem mem_map_of_mem (f : Ξ± βͺ Ξ²) {a} {s : finset Ξ±} : a β s β f a β s.map f :=
(mem_map' _).2
theorem map_to_finset [decidable_eq Ξ±] [decidable_eq Ξ²] {s : multiset Ξ±} :
s.to_finset.map f = (s.map f).to_finset :=
ext.2 $ Ξ» _, by simp only [mem_map, multiset.mem_map, exists_prop, multiset.mem_to_finset]
theorem map_refl : s.map (embedding.refl _) = s :=
ext.2 $ Ξ» _, by simpa only [mem_map, exists_prop] using exists_eq_right
theorem map_map {g : Ξ² βͺ Ξ³} : (s.map f).map g = s.map (f.trans g) :=
eq_of_veq $ by simp only [map_val, multiset.map_map]; refl
theorem map_subset_map {sβ sβ : finset Ξ±} : sβ.map f β sβ.map f β sβ β sβ :=
β¨Ξ» h x xs, (mem_map' _).1 $ h $ (mem_map' f).2 xs,
Ξ» h, by simp [subset_def, map_subset_map h]β©
theorem map_inj {sβ sβ : finset Ξ±} : sβ.map f = sβ.map f β sβ = sβ :=
by simp only [subset.antisymm_iff, map_subset_map]
def map_embedding (f : Ξ± βͺ Ξ²) : finset Ξ± βͺ finset Ξ² := β¨map f, Ξ» sβ sβ, map_inj.1β©
@[simp] theorem map_embedding_apply : map_embedding f s = map f s := rfl
theorem map_filter {p : Ξ² β Prop} [decidable_pred p] :
(s.map f).filter p = (s.filter (p β f)).map f :=
ext.2 $ Ξ» b, by simp only [mem_filter, mem_map, exists_prop, and_assoc]; exact
β¨by rintro β¨β¨x, h1, rflβ©, h2β©; exact β¨x, h1, h2, rflβ©,
by rintro β¨x, h1, h2, rflβ©; exact β¨β¨x, h1, rflβ©, h2β©β©
theorem map_union [decidable_eq Ξ±] [decidable_eq Ξ²]
{f : Ξ± βͺ Ξ²} (sβ sβ : finset Ξ±) : (sβ βͺ sβ).map f = sβ.map f βͺ sβ.map f :=
ext.2 $ Ξ» _, by simp only [mem_map, mem_union, exists_prop, or_and_distrib_right, exists_or_distrib]
theorem map_inter [decidable_eq Ξ±] [decidable_eq Ξ²]
{f : Ξ± βͺ Ξ²} (sβ sβ : finset Ξ±) : (sβ β© sβ).map f = sβ.map f β© sβ.map f :=
ext.2 $ Ξ» b, by simp only [mem_map, mem_inter, exists_prop]; exact
β¨by rintro β¨a, β¨mβ, mββ©, rflβ©; exact β¨β¨a, mβ, rflβ©, β¨a, mβ, rflβ©β©,
by rintro β¨β¨a, mβ, eβ©, β¨a', mβ, rflβ©β©; cases f.2 e; exact β¨_, β¨mβ, mββ©, rflβ©β©
@[simp] theorem map_singleton (f : Ξ± βͺ Ξ²) (a : Ξ±) : (singleton a).map f = singleton (f a) :=
ext.2 $ Ξ» _, by simp only [mem_map, mem_singleton, exists_prop, exists_eq_left]; exact eq_comm
@[simp] theorem map_insert [decidable_eq Ξ±] [decidable_eq Ξ²]
(f : Ξ± βͺ Ξ²) (a : Ξ±) (s : finset Ξ±) :
(insert a s).map f = insert (f a) (s.map f) :=
by simp only [insert_eq, insert_empty_eq_singleton, map_union, map_singleton]
@[simp] theorem map_eq_empty : s.map f = β
β s = β
:=
β¨Ξ» h, eq_empty_of_forall_not_mem $
Ξ» a m, ne_empty_of_mem (mem_map_of_mem _ m) h, Ξ» e, e.symm βΈ rflβ©
lemma attach_map_val {s : finset Ξ±} : s.attach.map (embedding.subtype _) = s :=
eq_of_veq $ by rw [map_val, attach_val]; exact attach_map_val _
end map
section image
variables [decidable_eq Ξ²]
/-- `image f s` is the forward image of `s` under `f`. -/
def image (f : Ξ± β Ξ²) (s : finset Ξ±) : finset Ξ² := (s.1.map f).to_finset
@[simp] theorem image_val (f : Ξ± β Ξ²) (s : finset Ξ±) : (image f s).1 = (s.1.map f).erase_dup := rfl
@[simp] theorem image_empty (f : Ξ± β Ξ²) : (β
: finset Ξ±).image f = β
:= rfl
variables {f : Ξ± β Ξ²} {s : finset Ξ±}
@[simp] theorem mem_image {b : Ξ²} : b β s.image f β β a β s, f a = b :=
by simp only [mem_def, image_val, mem_erase_dup, multiset.mem_map, exists_prop]
@[simp] theorem mem_image_of_mem (f : Ξ± β Ξ²) {a} {s : finset Ξ±} (h : a β s) : f a β s.image f :=
mem_image.2 β¨_, h, rflβ©
@[simp] lemma coe_image {f : Ξ± β Ξ²} : β(s.image f) = f '' βs :=
set.ext $ Ξ» _, mem_image.trans $ by simp only [exists_prop]; refl
theorem image_to_finset [decidable_eq Ξ±] {s : multiset Ξ±} : s.to_finset.image f = (s.map f).to_finset :=
ext.2 $ Ξ» _, by simp only [mem_image, multiset.mem_to_finset, exists_prop, multiset.mem_map]
@[simp] theorem image_val_of_inj_on (H : βxβs, βyβs, f x = f y β x = y) : (image f s).1 = s.1.map f :=
multiset.erase_dup_eq_self.2 (nodup_map_on H s.2)
theorem image_id [decidable_eq Ξ±] : s.image id = s :=
ext.2 $ Ξ» _, by simp only [mem_image, exists_prop, id, exists_eq_right]
theorem image_image [decidable_eq Ξ³] {g : Ξ² β Ξ³} : (s.image f).image g = s.image (g β f) :=
eq_of_veq $ by simp only [image_val, erase_dup_map_erase_dup_eq, multiset.map_map]
theorem image_subset_image {sβ sβ : finset Ξ±} (h : sβ β sβ) : sβ.image f β sβ.image f :=
by simp only [subset_def, image_val, subset_erase_dup', erase_dup_subset', multiset.map_subset_map h]
theorem image_filter {p : Ξ² β Prop} [decidable_pred p] :
(s.image f).filter p = (s.filter (p β f)).image f :=
ext.2 $ Ξ» b, by simp only [mem_filter, mem_image, exists_prop]; exact
β¨by rintro β¨β¨x, h1, rflβ©, h2β©; exact β¨x, β¨h1, h2β©, rflβ©,
by rintro β¨x, β¨h1, h2β©, rflβ©; exact β¨β¨x, h1, rflβ©, h2β©β©
theorem image_union [decidable_eq Ξ±] {f : Ξ± β Ξ²} (sβ sβ : finset Ξ±) : (sβ βͺ sβ).image f = sβ.image f βͺ sβ.image f :=
ext.2 $ Ξ» _, by simp only [mem_image, mem_union, exists_prop, or_and_distrib_right, exists_or_distrib]
theorem image_inter [decidable_eq Ξ±] (sβ sβ : finset Ξ±) (hf : βx y, f x = f y β x = y) : (sβ β© sβ).image f = sβ.image f β© sβ.image f :=
ext.2 $ by simp only [mem_image, exists_prop, mem_inter]; exact Ξ» b,
β¨Ξ» β¨a, β¨mβ, mββ©, eβ©, β¨β¨a, mβ, eβ©, β¨a, mβ, eβ©β©,
Ξ» β¨β¨a, mβ, eββ©, β¨a', mβ, eββ©β©, β¨a, β¨mβ, hf _ _ (eβ.trans eβ.symm) βΈ mββ©, eββ©β©.
@[simp] theorem image_singleton [decidable_eq Ξ±] (f : Ξ± β Ξ²) (a : Ξ±) : (singleton a).image f = singleton (f a) :=
ext.2 $ Ξ» x, by simpa only [mem_image, exists_prop, mem_singleton, exists_eq_left] using eq_comm
@[simp] theorem image_insert [decidable_eq Ξ±] (f : Ξ± β Ξ²) (a : Ξ±) (s : finset Ξ±) :
(insert a s).image f = insert (f a) (s.image f) :=
by simp only [insert_eq, insert_empty_eq_singleton, image_singleton, image_union]
@[simp] theorem image_eq_empty : s.image f = β
β s = β
:=
β¨Ξ» h, eq_empty_of_forall_not_mem $
Ξ» a m, ne_empty_of_mem (mem_image_of_mem _ m) h, Ξ» e, e.symm βΈ rflβ©
lemma attach_image_val [decidable_eq Ξ±] {s : finset Ξ±} : s.attach.image subtype.val = s :=
eq_of_veq $ by rw [image_val, attach_val, multiset.attach_map_val, erase_dup_eq_self]
@[simp] lemma attach_insert [decidable_eq Ξ±] {a : Ξ±} {s : finset Ξ±} :
attach (insert a s) = insert (β¨a, mem_insert_self a sβ© : {x // x β insert a s})
((attach s).image (Ξ»x, β¨x.1, mem_insert_of_mem x.2β©)) :=
ext.2 $ Ξ» β¨x, hxβ©, β¨or.cases_on (mem_insert.1 hx)
(assume h : x = a, Ξ» _, mem_insert.2 $ or.inl $ subtype.eq h)
(assume h : x β s, Ξ» _, mem_insert_of_mem $ mem_image.2 $ β¨β¨x, hβ©, mem_attach _ _, subtype.eq rflβ©),
Ξ» _, finset.mem_attach _ _β©
theorem map_eq_image (f : Ξ± βͺ Ξ²) (s : finset Ξ±) : s.map f = s.image f :=
eq_of_veq $ (multiset.erase_dup_eq_self.2 (s.map f).2).symm
lemma image_const [decidable_eq Ξ²] {s : finset Ξ±} (h : s β β
) (b : Ξ²) : s.image (Ξ»a, b) = singleton b :=
ext.2 $ assume b', by simp only [mem_image, exists_prop, exists_and_distrib_right,
exists_mem_of_ne_empty h, true_and, mem_singleton, eq_comm]
protected def subtype {Ξ±} (p : Ξ± β Prop) [decidable_pred p] (s : finset Ξ±) : finset (subtype p) :=
(s.filter p).attach.map β¨Ξ» x, β¨x.1, (finset.mem_filter.1 x.2).2β©,
Ξ» x y H, subtype.eq $ subtype.mk.inj Hβ©
@[simp] lemma mem_subtype {p : Ξ± β Prop} [decidable_pred p] {s : finset Ξ±} :
β{a : subtype p}, a β s.subtype p β a.val β s
| β¨a, haβ© := by simp [finset.subtype, ha]
end image
/- card -/
section card
/-- `card s` is the cardinality (number of elements) of `s`. -/
def card (s : finset Ξ±) : nat := s.1.card
theorem card_def (s : finset Ξ±) : s.card = s.1.card := rfl
@[simp] theorem card_empty : card (β
: finset Ξ±) = 0 := rfl
@[simp] theorem card_eq_zero {s : finset Ξ±} : card s = 0 β s = β
:=
card_eq_zero.trans val_eq_zero
theorem card_pos {s : finset Ξ±} : 0 < card s β s β β
:=
pos_iff_ne_zero.trans $ not_congr card_eq_zero
theorem card_eq_one {s : finset Ξ±} : s.card = 1 β β a, s = finset.singleton a :=
by cases s; simp [multiset.card_eq_one, finset.singleton, finset.card]
@[simp] theorem card_insert_of_not_mem [decidable_eq Ξ±]
{a : Ξ±} {s : finset Ξ±} (h : a β s) : card (insert a s) = card s + 1 :=
by simpa only [card_cons, card, insert_val] using
congr_arg multiset.card (ndinsert_of_not_mem h)
theorem card_insert_le [decidable_eq Ξ±] (a : Ξ±) (s : finset Ξ±) : card (insert a s) β€ card s + 1 :=
by by_cases a β s; [{rw [insert_eq_of_mem h], apply nat.le_add_right},
rw [card_insert_of_not_mem h]]
@[simp] theorem card_singleton (a : Ξ±) : card (singleton a) = 1 := card_singleton _
theorem card_erase_of_mem [decidable_eq Ξ±] {a : Ξ±} {s : finset Ξ±} : a β s β card (erase s a) = pred (card s) := card_erase_of_mem
@[simp] theorem card_range (n : β) : card (range n) = n := card_range n
@[simp] theorem card_attach {s : finset Ξ±} : card (attach s) = card s := multiset.card_attach
theorem card_image_of_inj_on [decidable_eq Ξ²] {f : Ξ± β Ξ²} {s : finset Ξ±}
(H : βxβs, βyβs, f x = f y β x = y) : card (image f s) = card s :=
by simp only [card, image_val_of_inj_on H, card_map]
theorem card_image_of_injective [decidable_eq Ξ²] {f : Ξ± β Ξ²} (s : finset Ξ±)
(H : function.injective f) : card (image f s) = card s :=
card_image_of_inj_on $ Ξ» x _ y _ h, H h
lemma card_eq_of_bijective [decidable_eq Ξ±] {s : finset Ξ±} {n : β}
(f : βi, i < n β Ξ±)
(hf : βaβs, βi, βh:i<n, f i h = a) (hf' : βi (h : i < n), f i h β s)
(f_inj : βi j (hi : i < n) (hj : j < n), f i hi = f j hj β i = j) :
card s = n :=
have β (a : Ξ±), a β s β βi (hi : i β range n), f i (mem_range.1 hi) = a,
from assume a, β¨assume ha, let β¨i, hi, eqβ© := hf a ha in β¨i, mem_range.2 hi, eqβ©,
assume β¨i, hi, eqβ©, eq βΈ hf' i (mem_range.1 hi)β©,
have s = ((range n).attach.image $ Ξ»i, f i.1 (mem_range.1 i.2)),
by simpa only [ext, mem_image, exists_prop, subtype.exists, mem_attach, true_and],
calc card s = card ((range n).attach.image $ Ξ»i, f i.1 (mem_range.1 i.2)) :
by rw [this]
... = card ((range n).attach) :
card_image_of_injective _ $ assume β¨i, hiβ© β¨j, hjβ© eq,
subtype.eq $ f_inj i j (mem_range.1 hi) (mem_range.1 hj) eq
... = card (range n) : card_attach
... = n : card_range n
lemma card_eq_succ [decidable_eq Ξ±] {s : finset Ξ±} {a : Ξ±} {n : β} :
s.card = n + 1 β (βa t, a β t β§ insert a t = s β§ card t = n) :=
iff.intro
(assume eq,
have card s > 0, from eq.symm βΈ nat.zero_lt_succ _,
let β¨a, hasβ© := finset.exists_mem_of_ne_empty $ card_pos.mp this in
β¨a, s.erase a, s.not_mem_erase a, insert_erase has, by simp only [eq, card_erase_of_mem has, pred_succ]β©)
(assume β¨a, t, hat, s_eq, n_eqβ©, s_eq βΈ n_eq βΈ card_insert_of_not_mem hat)
theorem card_le_of_subset {s t : finset Ξ±} : s β t β card s β€ card t :=
multiset.card_le_of_le β val_le_iff.mpr
theorem eq_of_subset_of_card_le {s t : finset Ξ±} (h : s β t) (hβ : card t β€ card s) : s = t :=
eq_of_veq $ multiset.eq_of_le_of_card_le (val_le_iff.mpr h) hβ
lemma card_lt_card [decidable_eq Ξ±] {s t : finset Ξ±} (h : s β t) : s.card < t.card :=
card_lt_of_lt (val_lt_iff.2 h)
lemma card_le_card_of_inj_on [decidable_eq Ξ±] [decidable_eq Ξ²] {s : finset Ξ±} {t : finset Ξ²}
(f : Ξ± β Ξ²) (hf : βaβs, f a β t) (f_inj : βaββs, βaββs, f aβ = f aβ β aβ = aβ) :
card s β€ card t :=
calc card s = card (s.image f) : by rw [card_image_of_inj_on f_inj]
... β€ card t : card_le_of_subset $
assume x hx, match x, finset.mem_image.1 hx with _, β¨a, ha, rflβ© := hf a ha end
lemma card_le_of_inj_on [decidable_eq Ξ±] {n} {s : finset Ξ±}
(f : β β Ξ±) (hf : βi<n, f i β s) (f_inj : βi j, i<n β j<n β f i = f j β i = j) : n β€ card s :=
calc n = card (range n) : (card_range n).symm
... β€ card s : card_le_card_of_inj_on f
(by simpa only [mem_range])
(by simp only [mem_range]; exact assume aβ hβ aβ hβ, f_inj aβ aβ hβ hβ)
@[elab_as_eliminator] lemma strong_induction_on {p : finset Ξ± β Sort*} :
β (s : finset Ξ±), (βs, (βt β s, p t) β p s) β p s
| β¨s, ndβ© ih := multiset.strong_induction_on s
(Ξ» s IH nd, ih β¨s, ndβ© (Ξ» β¨t, nd'β© ss, IH t (val_lt_iff.2 ss) nd')) nd
@[elab_as_eliminator] lemma case_strong_induction_on [decidable_eq Ξ±] {p : finset Ξ± β Prop}
(s : finset Ξ±) (hβ : p β
) (hβ : β a s, a β s β (βt β s, p t) β p (insert a s)) : p s :=
finset.strong_induction_on s $ Ξ» s,
finset.induction_on s (Ξ» _, hβ) $ Ξ» a s n _ ih, hβ a s n $
Ξ» t ss, ih _ (lt_of_le_of_lt ss (ssubset_insert n) : t < _)
lemma card_congr {s : finset Ξ±} {t : finset Ξ²} (f : Ξ a β s, Ξ²)
(hβ : β a ha, f a ha β t) (hβ : β a b ha hb, f a ha = f b hb β a = b)
(hβ : β b β t, β a ha, f a ha = b) : s.card = t.card :=
by haveI := classical.prop_decidable; exact
calc s.card = s.attach.card : card_attach.symm
... = (s.attach.image (Ξ» (a : {a // a β s}), f a.1 a.2)).card :
eq.symm (card_image_of_injective _ (Ξ» a b h, subtype.eq (hβ _ _ _ _ h)))
... = t.card : congr_arg card (finset.ext.2 $ Ξ» b,
β¨Ξ» h, let β¨a, haβ, haββ© := mem_image.1 h in haβ βΈ hβ _ _,
Ξ» h, let β¨a, haβ, haββ© := hβ b h in mem_image.2 β¨β¨a, haββ©, by simp [haβ]β©β©)
lemma card_union_add_card_inter [decidable_eq Ξ±] (s t : finset Ξ±) :
(s βͺ t).card + (s β© t).card = s.card + t.card :=
finset.induction_on t (by simp) (Ξ» a, by by_cases a β s; simp * {contextual := tt})
lemma card_union_le [decidable_eq Ξ±] (s t : finset Ξ±) :
(s βͺ t).card β€ s.card + t.card :=
card_union_add_card_inter s t βΈ le_add_right _ _
lemma surj_on_of_inj_on_of_card_le {s : finset Ξ±} {t : finset Ξ²}
(f : Ξ a β s, Ξ²) (hf : β a ha, f a ha β t)
(hinj : β aβ aβ haβ haβ, f aβ haβ = f aβ haβ β aβ = aβ)
(hst : card t β€ card s) :
(β b β t, β a ha, b = f a ha) :=
by haveI := classical.dec_eq Ξ²; exact
Ξ» b hb,
have h : card (image (Ξ» (a : {a // a β s}), f (a.val) a.2) (attach s)) = card s,
from @card_attach _ s βΈ card_image_of_injective _
(Ξ» β¨aβ, haββ© β¨aβ, haββ© h, subtype.eq $ hinj _ _ _ _ h),
have hβ : image (Ξ» a : {a // a β s}, f a.1 a.2) s.attach = t :=
eq_of_subset_of_card_le (Ξ» b h, let β¨a, haβ, haββ© := mem_image.1 h in
haβ βΈ hf _ _) (by simp [hst, h]),
begin
rw β hβ at hb,
rcases mem_image.1 hb with β¨a, haβ, haββ©,
exact β¨a, a.2, haβ.symmβ©,
end
end card
section bind
variables [decidable_eq Ξ²] {s : finset Ξ±} {t : Ξ± β finset Ξ²}
/-- `bind s t` is the union of `t x` over `x β s` -/
protected def bind (s : finset Ξ±) (t : Ξ± β finset Ξ²) : finset Ξ² := (s.1.bind (Ξ» a, (t a).1)).to_finset
@[simp] theorem bind_val (s : finset Ξ±) (t : Ξ± β finset Ξ²) :
(s.bind t).1 = (s.1.bind (Ξ» a, (t a).1)).erase_dup := rfl
@[simp] theorem bind_empty : finset.bind β
t = β
:= rfl
@[simp] theorem mem_bind {b : Ξ²} : b β s.bind t β βaβs, b β t a :=
by simp only [mem_def, bind_val, mem_erase_dup, mem_bind, exists_prop]
@[simp] theorem bind_insert [decidable_eq Ξ±] {a : Ξ±} : (insert a s).bind t = t a βͺ s.bind t :=
ext.2 $ Ξ» x, by simp only [mem_bind, exists_prop, mem_union, mem_insert,
or_and_distrib_right, exists_or_distrib, exists_eq_left]
-- ext.2 $ Ξ» x, by simp [or_and_distrib_right, exists_or_distrib]
@[simp] lemma singleton_bind [decidable_eq Ξ±] {a : Ξ±} : (singleton a).bind t = t a :=
show (insert a β
: finset Ξ±).bind t = t a, from bind_insert.trans $ union_empty _
theorem image_bind [decidable_eq Ξ³] {f : Ξ± β Ξ²} {s : finset Ξ±} {t : Ξ² β finset Ξ³} :
(s.image f).bind t = s.bind (Ξ»a, t (f a)) :=
by haveI := classical.dec_eq Ξ±; exact
finset.induction_on s rfl (Ξ» a s has ih,
by simp only [image_insert, bind_insert, ih])
theorem bind_image [decidable_eq Ξ³] {s : finset Ξ±} {t : Ξ± β finset Ξ²} {f : Ξ² β Ξ³} :
(s.bind t).image f = s.bind (Ξ»a, (t a).image f) :=
by haveI := classical.dec_eq Ξ±; exact
finset.induction_on s rfl (Ξ» a s has ih,
by simp only [bind_insert, image_union, ih])
theorem bind_to_finset [decidable_eq Ξ±] (s : multiset Ξ±) (t : Ξ± β multiset Ξ²) :
(s.bind t).to_finset = s.to_finset.bind (Ξ»a, (t a).to_finset) :=
ext.2 $ Ξ» x, by simp only [multiset.mem_to_finset, mem_bind, multiset.mem_bind, exists_prop]
lemma bind_mono {tβ tβ : Ξ± β finset Ξ²} (h : βaβs, tβ a β tβ a) : s.bind tβ β s.bind tβ :=
have βb a, a β s β b β tβ a β (β (a : Ξ±), a β s β§ b β tβ a),
from assume b a ha hb, β¨a, ha, finset.mem_of_subset (h a ha) hbβ©,
by simpa only [subset_iff, mem_bind, exists_imp_distrib, and_imp, exists_prop]
lemma bind_singleton {f : Ξ± β Ξ²} : s.bind (Ξ»a, {f a}) = s.image f :=
ext.2 $ Ξ» x, by simp only [mem_bind, mem_image, insert_empty_eq_singleton, mem_singleton, eq_comm]
lemma image_bind_filter_eq [decidable_eq Ξ±] (s : finset Ξ²) (g : Ξ² β Ξ±) :
(s.image g).bind (Ξ»a, s.filter $ (Ξ»c, g c = a)) = s :=
begin
ext b,
simp,
split,
{ rintros β¨a, β¨b', _, _β©, hb, _β©, exact hb },
{ rintros hb, exact β¨g b, β¨b, hb, rflβ©, hb, rflβ© }
end
end bind
section prod
variables {s : finset Ξ±} {t : finset Ξ²}
/-- `product s t` is the set of pairs `(a, b)` such that `a β s` and `b β t`. -/
protected def product (s : finset Ξ±) (t : finset Ξ²) : finset (Ξ± Γ Ξ²) := β¨_, nodup_product s.2 t.2β©
@[simp] theorem product_val : (s.product t).1 = s.1.product t.1 := rfl
@[simp] theorem mem_product {p : Ξ± Γ Ξ²} : p β s.product t β p.1 β s β§ p.2 β t := mem_product
theorem product_eq_bind [decidable_eq Ξ±] [decidable_eq Ξ²] (s : finset Ξ±) (t : finset Ξ²) :
s.product t = s.bind (Ξ»a, t.image $ Ξ»b, (a, b)) :=
ext.2 $ Ξ» β¨x, yβ©, by simp only [mem_product, mem_bind, mem_image, exists_prop, prod.mk.inj_iff,
and.left_comm, exists_and_distrib_left, exists_eq_right, exists_eq_left]
@[simp] theorem card_product (s : finset Ξ±) (t : finset Ξ²) : card (s.product t) = card s * card t :=
multiset.card_product _ _
end prod
section sigma
variables {Ο : Ξ± β Type*} {s : finset Ξ±} {t : Ξ a, finset (Ο a)}
/-- `sigma s t` is the set of dependent pairs `β¨a, bβ©` such that `a β s` and `b β t a`. -/
protected def sigma (s : finset Ξ±) (t : Ξ a, finset (Ο a)) : finset (Ξ£a, Ο a) :=
β¨_, nodup_sigma s.2 (Ξ» a, (t a).2)β©
@[simp] theorem mem_sigma {p : sigma Ο} : p β s.sigma t β p.1 β s β§ p.2 β t (p.1) := mem_sigma
theorem sigma_mono {sβ sβ : finset Ξ±} {tβ tβ : Ξ a, finset (Ο a)}
(H1 : sβ β sβ) (H2 : βa, tβ a β tβ a) : sβ.sigma tβ β sβ.sigma tβ :=
Ξ» β¨x, sxβ© H, let β¨H3, H4β© := mem_sigma.1 H in mem_sigma.2 β¨H1 H3, H2 x H4β©
theorem sigma_eq_bind [decidable_eq Ξ±] [βa, decidable_eq (Ο a)] (s : finset Ξ±) (t : Ξ a, finset (Ο a)) :
s.sigma t = s.bind (Ξ»a, (t a).image $ Ξ»b, β¨a, bβ©) :=
ext.2 $ Ξ» β¨x, yβ©, by simp only [mem_sigma, mem_bind, mem_image, exists_prop,
and.left_comm, exists_and_distrib_left, exists_eq_left, heq_iff_eq, exists_eq_right]
end sigma
section pi
variables {Ξ΄ : Ξ± β Type*} [decidable_eq Ξ±]
def pi (s : finset Ξ±) (t : Ξ a, finset (Ξ΄ a)) : finset (Ξ aβs, Ξ΄ a) :=
β¨s.1.pi (Ξ» a, (t a).1), nodup_pi s.2 (Ξ» a _, (t a).2)β©
@[simp] lemma pi_val (s : finset Ξ±) (t : Ξ a, finset (Ξ΄ a)) :
(s.pi t).1 = s.1.pi (Ξ» a, (t a).1) := rfl
@[simp] lemma mem_pi {s : finset Ξ±} {t : Ξ a, finset (Ξ΄ a)} {f : Ξ aβs, Ξ΄ a} :
f β s.pi t β (βa (h : a β s), f a h β t a) :=
mem_pi _ _ _
def pi.empty (Ξ² : Ξ± β Sort*) [decidable_eq Ξ±] (a : Ξ±) (h : a β (β
: finset Ξ±)) : Ξ² a :=
multiset.pi.empty Ξ² a h
def pi.cons (s : finset Ξ±) (a : Ξ±) (b : Ξ΄ a) (f : Ξ a, a β s β Ξ΄ a) (a' : Ξ±) (h : a' β insert a s) : Ξ΄ a' :=
multiset.pi.cons s.1 a b f _ (multiset.mem_cons.2 $ mem_insert.symm.2 h)
@[simp] lemma pi.cons_same (s : finset Ξ±) (a : Ξ±) (b : Ξ΄ a) (f : Ξ a, a β s β Ξ΄ a) (h : a β insert a s) :
pi.cons s a b f a h = b :=
multiset.pi.cons_same _
lemma pi.cons_ne {s : finset Ξ±} {a a' : Ξ±} {b : Ξ΄ a} {f : Ξ a, a β s β Ξ΄ a} {h : a' β insert a s} (ha : a β a') :
pi.cons s a b f a' h = f a' ((mem_insert.1 h).resolve_left ha.symm) :=
multiset.pi.cons_ne _ _
lemma injective_pi_cons {a : Ξ±} {b : Ξ΄ a} {s : finset Ξ±} (hs : a β s) :
function.injective (pi.cons s a b) :=
assume eβ eβ eq,
@multiset.injective_pi_cons Ξ± _ Ξ΄ a b s.1 hs _ _ $
funext $ assume e, funext $ assume h,
have pi.cons s a b eβ e (by simpa only [mem_cons, mem_insert] using h) = pi.cons s a b eβ e (by simpa only [mem_cons, mem_insert] using h),
by rw [eq],
this
@[simp] lemma pi_empty {t : Ξ a:Ξ±, finset (Ξ΄ a)} :
pi (β
: finset Ξ±) t = singleton (pi.empty Ξ΄) := rfl
@[simp] lemma pi_insert [βa, decidable_eq (Ξ΄ a)]
{s : finset Ξ±} {t : Ξ a:Ξ±, finset (Ξ΄ a)} {a : Ξ±} (ha : a β s) :
pi (insert a s) t = (t a).bind (Ξ»b, (pi s t).image (pi.cons s a b)) :=
begin
apply eq_of_veq,
rw β multiset.erase_dup_eq_self.2 (pi (insert a s) t).2,
refine (Ξ» s' (h : s' = a :: s.1), (_ : erase_dup (multiset.pi s' (Ξ» a, (t a).1)) =
erase_dup ((t a).1.bind $ Ξ» b,
erase_dup $ (multiset.pi s.1 (Ξ» (a : Ξ±), (t a).val)).map $
Ξ» f a' h', multiset.pi.cons s.1 a b f a' (h βΈ h')))) _ (insert_val_of_not_mem ha),
subst s', rw pi_cons,
congr, funext b,
rw multiset.erase_dup_eq_self.2,
exact multiset.nodup_map (multiset.injective_pi_cons ha) (pi s t).2,
end
end pi
section powerset
def powerset (s : finset Ξ±) : finset (finset Ξ±) :=
β¨s.1.powerset.pmap finset.mk
(Ξ» t h, nodup_of_le (mem_powerset.1 h) s.2),
nodup_pmap (Ξ» a ha b hb, congr_arg finset.val)
(nodup_powerset.2 s.2)β©
@[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] theorem empty_mem_powerset (s : finset Ξ±) : β
β powerset s :=
mem_powerset.2 (empty_subset _)
@[simp] theorem mem_powerset_self (s : finset Ξ±) : s β powerset s :=
mem_powerset.2 (subset.refl _)
@[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β©
@[simp] theorem card_powerset (s : finset Ξ±) :
card (powerset s) = 2 ^ card s :=
(card_pmap _ _ _).trans (card_powerset s.1)
end powerset
section fold
variables (op : Ξ² β Ξ² β Ξ²) [hc : is_commutative Ξ² op] [ha : is_associative Ξ² op]
local notation a * b := op a b
include hc ha
/-- `fold op b f s` folds the commutative associative operation `op` over the
`f`-image of `s`, i.e. `fold (+) b f {1,2,3} = `f 1 + f 2 + f 3 + b`. -/
def fold (b : Ξ²) (f : Ξ± β Ξ²) (s : finset Ξ±) : Ξ² := (s.1.map f).fold op b
variables {op} {f : Ξ± β Ξ²} {b : Ξ²} {s : finset Ξ±} {a : Ξ±}
@[simp] theorem fold_empty : (β
: finset Ξ±).fold op b f = b := rfl
@[simp] theorem fold_insert [decidable_eq Ξ±] (h : a β s) : (insert a s).fold op b f = f a * s.fold op b f :=
by unfold fold; rw [insert_val, ndinsert_of_not_mem h, map_cons, fold_cons_left]
@[simp] theorem fold_singleton : (singleton a).fold op b f = f a * b := rfl
@[simp] theorem fold_image [decidable_eq Ξ±] {g : Ξ³ β Ξ±} {s : finset Ξ³}
(H : β (x β s) (y β s), g x = g y β x = y) : (s.image g).fold op b f = s.fold op b (f β g) :=
by simp only [fold, image_val_of_inj_on H, multiset.map_map]
@[congr] theorem fold_congr {g : Ξ± β Ξ²} (H : β x β s, f x = g x) : s.fold op b f = s.fold op b g :=
by rw [fold, fold, map_congr H]
theorem fold_op_distrib {f g : Ξ± β Ξ²} {bβ bβ : Ξ²} :
s.fold op (bβ * bβ) (Ξ»x, f x * g x) = s.fold op bβ f * s.fold op bβ g :=
by simp only [fold, fold_distrib]
theorem fold_hom {op' : Ξ³ β Ξ³ β Ξ³} [is_commutative Ξ³ op'] [is_associative Ξ³ op']
{m : Ξ² β Ξ³} (hm : βx y, m (op x y) = op' (m x) (m y)) :
s.fold op' (m b) (Ξ»x, m (f x)) = m (s.fold op b f) :=
by rw [fold, fold, β fold_hom op hm, multiset.map_map]
theorem fold_union_inter [decidable_eq Ξ±] {sβ sβ : finset Ξ±} {bβ bβ : Ξ²} :
(sβ βͺ sβ).fold op bβ f * (sβ β© sβ).fold op bβ f = sβ.fold op bβ f * sβ.fold op bβ f :=
by unfold fold; rw [β fold_add op, β map_add, union_val,
inter_val, union_add_inter, map_add, hc.comm, fold_add]
@[simp] theorem fold_insert_idem [decidable_eq Ξ±] [hi : is_idempotent Ξ² op] :
(insert a s).fold op b f = f a * s.fold op b f :=
by haveI := classical.prop_decidable;
rw [fold, insert_val', β fold_erase_dup_idem op, erase_dup_map_erase_dup_eq,
fold_erase_dup_idem op]; simp only [map_cons, fold_cons_left, fold]
end fold
section sup
variables [semilattice_sup_bot Ξ±]
/-- Supremum of a finite set: `sup {a, b, c} f = f a β f b β f c` -/
def sup (s : finset Ξ²) (f : Ξ² β Ξ±) : Ξ± := s.fold (β) β₯ f
variables {s sβ sβ : finset Ξ²} {f : Ξ² β Ξ±}
lemma sup_val : s.sup f = (s.1.map f).sup := rfl
@[simp] lemma sup_empty : (β
: finset Ξ²).sup f = β₯ :=
fold_empty
@[simp] lemma sup_insert [decidable_eq Ξ²] {b : Ξ²} : (insert b s : finset Ξ²).sup f = f b β s.sup f :=
fold_insert_idem
@[simp] lemma sup_singleton [decidable_eq Ξ²] {b : Ξ²} : ({b} : finset Ξ²).sup f = f b :=
calc _ = f b β (β
:finset Ξ²).sup f : sup_insert
... = f b : sup_bot_eq
lemma sup_union [decidable_eq Ξ²] : (sβ βͺ sβ).sup f = sβ.sup f β sβ.sup f :=
finset.induction_on sβ (by rw [empty_union, sup_empty, bot_sup_eq]) $ Ξ» a s has ih,
by rw [insert_union, sup_insert, sup_insert, ih, sup_assoc]
theorem sup_congr {f g : Ξ² β Ξ±} (hs : sβ = sβ) (hfg : βaβsβ, f a = g a) : sβ.sup f = sβ.sup g :=
by subst hs; exact finset.fold_congr hfg
lemma sup_mono_fun {g : Ξ² β Ξ±} : (βbβs, f b β€ g b) β s.sup f β€ s.sup g :=
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (Ξ» _, le_refl _) (Ξ» a s has ih H,
by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H;
simp only [sup_insert]; exact sup_le_sup H.1 (ih H.2))
lemma le_sup {b : Ξ²} (hb : b β s) : f b β€ s.sup f :=
by letI := classical.dec_eq Ξ²; from
calc f b β€ f b β s.sup f : le_sup_left
... = (insert b s).sup f : sup_insert.symm
... = s.sup f : by rw [insert_eq_of_mem hb]
lemma sup_le {a : Ξ±} : (βb β s, f b β€ a) β s.sup f β€ a :=
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (Ξ» _, bot_le) (Ξ» n s hns ih H,
by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H;
simp only [sup_insert]; exact sup_le H.1 (ih H.2))
lemma sup_le_iff {a : Ξ±} : s.sup f β€ a β (βb β s, f b β€ a) :=
iff.intro (assume h b hb, le_trans (le_sup hb) h) sup_le
lemma sup_mono (h : sβ β sβ) : sβ.sup f β€ sβ.sup f :=
sup_le $ assume b hb, le_sup (h hb)
lemma sup_lt [is_total Ξ± (β€)] {a : Ξ±} : (β₯ < a) β (βb β s, f b < a) β s.sup f < a :=
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (by simp) (by simp {contextual := tt})
lemma comp_sup_eq_sup_comp [is_total Ξ± (β€)] {Ξ³ : Type} [semilattice_sup_bot Ξ³]
(g : Ξ± β Ξ³) (mono_g : monotone g) (bot : g β₯ = β₯) : g (s.sup f) = s.sup (g β f) :=
have A : βx y, g (x β y) = g x β g y :=
begin
assume x y,
cases (is_total.total (β€) x y) with h,
{ simp [sup_of_le_right h, sup_of_le_right (mono_g h)] },
{ simp [sup_of_le_left h, sup_of_le_left (mono_g h)] }
end,
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (by simp [bot]) (by simp [A] {contextual := tt})
end sup
lemma sup_eq_supr [complete_lattice Ξ²] (s : finset Ξ±) (f : Ξ± β Ξ²) : s.sup f = (β¨aβs, f a) :=
le_antisymm
(finset.sup_le $ assume a ha, le_supr_of_le a $ le_supr _ ha)
(supr_le $ assume a, supr_le $ assume ha, le_sup ha)
section inf
variables [semilattice_inf_top Ξ±]
/-- Infimum of a finite set: `inf {a, b, c} f = f a β f b β f c` -/
def inf (s : finset Ξ²) (f : Ξ² β Ξ±) : Ξ± := s.fold (β) β€ f
variables {s sβ sβ : finset Ξ²} {f : Ξ² β Ξ±}
lemma inf_val : s.inf f = (s.1.map f).inf := rfl
@[simp] lemma inf_empty : (β
: finset Ξ²).inf f = β€ :=
fold_empty
@[simp] lemma inf_insert [decidable_eq Ξ²] {b : Ξ²} : (insert b s : finset Ξ²).inf f = f b β s.inf f :=
fold_insert_idem
@[simp] lemma inf_singleton [decidable_eq Ξ²] {b : Ξ²} : ({b} : finset Ξ²).inf f = f b :=
calc _ = f b β (β
:finset Ξ²).inf f : inf_insert
... = f b : inf_top_eq
lemma inf_union [decidable_eq Ξ²] : (sβ βͺ sβ).inf f = sβ.inf f β sβ.inf f :=
finset.induction_on sβ (by rw [empty_union, inf_empty, top_inf_eq]) $ Ξ» a s has ih,
by rw [insert_union, inf_insert, inf_insert, ih, inf_assoc]
theorem inf_congr {f g : Ξ² β Ξ±} (hs : sβ = sβ) (hfg : βaβsβ, f a = g a) : sβ.inf f = sβ.inf g :=
by subst hs; exact finset.fold_congr hfg
lemma inf_mono_fun {g : Ξ² β Ξ±} : (βbβs, f b β€ g b) β s.inf f β€ s.inf g :=
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (Ξ» _, le_refl _) (Ξ» a s has ih H,
by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H;
simp only [inf_insert]; exact inf_le_inf H.1 (ih H.2))
lemma inf_le {b : Ξ²} (hb : b β s) : s.inf f β€ f b :=
by letI := classical.dec_eq Ξ²; from
calc f b β₯ f b β s.inf f : inf_le_left
... = (insert b s).inf f : inf_insert.symm
... = s.inf f : by rw [insert_eq_of_mem hb]
lemma le_inf {a : Ξ±} : (βb β s, a β€ f b) β a β€ s.inf f :=
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (Ξ» _, le_top) (Ξ» n s hns ih H,
by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H;
simp only [inf_insert]; exact le_inf H.1 (ih H.2))
lemma le_inf_iff {a : Ξ±} : a β€ s.inf f β (βb β s, a β€ f b) :=
iff.intro (assume h b hb, le_trans h (inf_le hb)) le_inf
lemma inf_mono (h : sβ β sβ) : sβ.inf f β€ sβ.inf f :=
le_inf $ assume b hb, inf_le (h hb)
lemma lt_inf [is_total Ξ± (β€)] {a : Ξ±} : (a < β€) β (βb β s, a < f b) β a < s.inf f :=
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (by simp) (by simp {contextual := tt})
lemma comp_inf_eq_inf_comp [is_total Ξ± (β€)] {Ξ³ : Type} [semilattice_inf_top Ξ³]
(g : Ξ± β Ξ³) (mono_g : monotone g) (top : g β€ = β€) : g (s.inf f) = s.inf (g β f) :=
have A : βx y, g (x β y) = g x β g y :=
begin
assume x y,
cases (is_total.total (β€) x y) with h,
{ simp [inf_of_le_left h, inf_of_le_left (mono_g h)] },
{ simp [inf_of_le_right h, inf_of_le_right (mono_g h)] }
end,
by letI := classical.dec_eq Ξ²; from
finset.induction_on s (by simp [top]) (by simp [A] {contextual := tt})
end inf
lemma inf_eq_infi [complete_lattice Ξ²] (s : finset Ξ±) (f : Ξ± β Ξ²) : s.inf f = (β¨
aβs, f a) :=
le_antisymm
(le_infi $ assume a, le_infi $ assume ha, inf_le ha)
(finset.le_inf $ assume a ha, infi_le_of_le a $ infi_le _ ha)
/- max and min of finite sets -/
section max_min
variables [decidable_linear_order Ξ±]
protected def max : finset Ξ± β option Ξ± :=
fold (option.lift_or_get max) none some
theorem max_eq_sup_with_bot (s : finset Ξ±) :
s.max = @sup (with_bot Ξ±) Ξ± _ s some := rfl
@[simp] theorem max_empty : (β
: finset Ξ±).max = none := rfl
@[simp] theorem max_insert {a : Ξ±} {s : finset Ξ±} :
(insert a s).max = option.lift_or_get max (some a) s.max := fold_insert_idem
@[simp] theorem max_singleton {a : Ξ±} : finset.max {a} = some a := max_insert
@[simp] theorem max_singleton' {a : Ξ±} : finset.max (singleton a) = some a := max_singleton
theorem max_of_mem {s : finset Ξ±} {a : Ξ±} (h : a β s) : β b, b β s.max :=
(@le_sup (with_bot Ξ±) _ _ _ _ _ h _ rfl).imp $ Ξ» b, Exists.fst
theorem max_of_ne_empty {s : finset Ξ±} (h : s β β
) : β a, a β s.max :=
let β¨a, haβ© := exists_mem_of_ne_empty h in max_of_mem ha
theorem max_eq_none {s : finset Ξ±} : s.max = none β s = β
:=
β¨Ξ» h, by_contradiction $
Ξ» hs, let β¨a, haβ© := max_of_ne_empty hs in by rw [h] at ha; cases ha,
Ξ» h, h.symm βΈ max_emptyβ©
theorem mem_of_max {s : finset Ξ±} : β {a : Ξ±}, a β s.max β a β s :=
finset.induction_on s (Ξ» _ H, by cases H)
(Ξ» b s _ (ih : β {a}, a β s.max β a β s) a (h : a β (insert b s).max),
begin
by_cases p : b = a,
{ induction p, exact mem_insert_self b s },
{ cases option.lift_or_get_choice max_choice (some b) s.max with q q;
rw [max_insert, q] at h,
{ cases h, cases p rfl },
{ exact mem_insert_of_mem (ih h) } }
end)
theorem le_max_of_mem {s : finset Ξ±} {a b : Ξ±} (hβ : a β s) (hβ : b β s.max) : a β€ b :=
by rcases @le_sup (with_bot Ξ±) _ _ _ _ _ hβ _ rfl with β¨b', hb, abβ©;
cases hβ.symm.trans hb; assumption
protected def min : finset Ξ± β option Ξ± :=
fold (option.lift_or_get min) none some
theorem min_eq_inf_with_top (s : finset Ξ±) :
s.min = @inf (with_top Ξ±) Ξ± _ s some := rfl
@[simp] theorem min_empty : (β
: finset Ξ±).min = none := rfl
@[simp] theorem min_insert {a : Ξ±} {s : finset Ξ±} :
(insert a s).min = option.lift_or_get min (some a) s.min :=
fold_insert_idem
@[simp] theorem min_singleton {a : Ξ±} : finset.min {a} = some a := min_insert
theorem min_of_mem {s : finset Ξ±} {a : Ξ±} (h : a β s) : β b, b β s.min :=
(@inf_le (with_top Ξ±) _ _ _ _ _ h _ rfl).imp $ Ξ» b, Exists.fst
theorem min_of_ne_empty {s : finset Ξ±} (h : s β β
) : β a, a β s.min :=
let β¨a, haβ© := exists_mem_of_ne_empty h in min_of_mem ha
theorem min_eq_none {s : finset Ξ±} : s.min = none β s = β
:=
β¨Ξ» h, by_contradiction $
Ξ» hs, let β¨a, haβ© := min_of_ne_empty hs in by rw [h] at ha; cases ha,
Ξ» h, h.symm βΈ min_emptyβ©
theorem mem_of_min {s : finset Ξ±} : β {a : Ξ±}, a β s.min β a β s :=
finset.induction_on s (Ξ» _ H, by cases H) $
Ξ» b s _ (ih : β {a}, a β s.min β a β s) a (h : a β (insert b s).min),
begin
by_cases p : b = a,
{ induction p, exact mem_insert_self b s },
{ cases option.lift_or_get_choice min_choice (some b) s.min with q q;
rw [min_insert, q] at h,
{ cases h, cases p rfl },
{ exact mem_insert_of_mem (ih h) } }
end
theorem le_min_of_mem {s : finset Ξ±} {a b : Ξ±} (hβ : b β s) (hβ : a β s.min) : a β€ b :=
by rcases @inf_le (with_top Ξ±) _ _ _ _ _ hβ _ rfl with β¨b', hb, abβ©;
cases hβ.symm.trans hb; assumption
end max_min
section sort
variables (r : Ξ± β Ξ± β Prop) [decidable_rel r]
[is_trans Ξ± r] [is_antisymm Ξ± r] [is_total Ξ± r]
/-- `sort s` constructs a sorted list from the unordered set `s`.
(Uses merge sort algorithm.) -/
def sort (s : finset Ξ±) : list Ξ± := sort r s.1
@[simp] theorem sort_sorted (s : finset Ξ±) : list.sorted r (sort r s) :=
sort_sorted _ _
@[simp] theorem sort_eq (s : finset Ξ±) : β(sort r s) = s.1 :=
sort_eq _ _
@[simp] theorem sort_nodup (s : finset Ξ±) : (sort r s).nodup :=
(by rw sort_eq; exact s.2 : @multiset.nodup Ξ± (sort r s))
@[simp] theorem sort_to_finset [decidable_eq Ξ±] (s : finset Ξ±) : (sort r s).to_finset = s :=
list.to_finset_eq (sort_nodup r s) βΈ eq_of_veq (sort_eq r s)
@[simp] theorem mem_sort {s : finset Ξ±} {a : Ξ±} : a β sort r s β a β s :=
multiset.mem_sort _
end sort
section disjoint
variable [decidable_eq Ξ±]
theorem disjoint_left {s t : finset Ξ±} : disjoint s t β β {a}, a β s β a β t :=
by simp only [_root_.disjoint, inf_eq_inter, le_iff_subset, subset_iff, mem_inter, not_and, and_imp]; refl
theorem disjoint_val {s t : finset Ξ±} : disjoint s t β s.1.disjoint t.1 :=
disjoint_left
theorem disjoint_iff_inter_eq_empty {s t : finset Ξ±} : disjoint s t β s β© t = β
:=
disjoint_iff
theorem disjoint_right {s t : finset Ξ±} : disjoint s t β β {a}, a β t β a β s :=
by rw [disjoint.comm, disjoint_left]
theorem disjoint_iff_ne {s t : finset Ξ±} : disjoint s t β β a β s, β b β t, a β b :=
by simp only [disjoint_left, imp_not_comm, forall_eq']
theorem disjoint_of_subset_left {s t u : finset Ξ±} (h : s β u) (d : disjoint u t) : disjoint s t :=
disjoint_left.2 (Ξ» x mβ, (disjoint_left.1 d) (h mβ))
theorem disjoint_of_subset_right {s t u : finset Ξ±} (h : t β u) (d : disjoint s u) : disjoint s t :=
disjoint_right.2 (Ξ» x mβ, (disjoint_right.1 d) (h mβ))
@[simp] theorem disjoint_empty_left (s : finset Ξ±) : disjoint β
s := disjoint_bot_left
@[simp] theorem disjoint_empty_right (s : finset Ξ±) : disjoint s β
:= disjoint_bot_right
@[simp] theorem singleton_disjoint {s : finset Ξ±} {a : Ξ±} : disjoint (singleton a) s β a β s :=
by simp only [disjoint_left, mem_singleton, forall_eq]
@[simp] theorem disjoint_singleton {s : finset Ξ±} {a : Ξ±} : disjoint s (singleton a) β a β s :=
disjoint.comm.trans singleton_disjoint
@[simp] theorem disjoint_insert_left {a : Ξ±} {s t : finset Ξ±} :
disjoint (insert a s) t β a β t β§ disjoint s t :=
by simp only [disjoint_left, mem_insert, or_imp_distrib, forall_and_distrib, forall_eq]
@[simp] theorem disjoint_insert_right {a : Ξ±} {s t : finset Ξ±} :
disjoint s (insert a t) β a β s β§ disjoint s t :=
disjoint.comm.trans $ by rw [disjoint_insert_left, disjoint.comm]
@[simp] theorem disjoint_union_left {s t u : finset Ξ±} :
disjoint (s βͺ t) u β disjoint s u β§ disjoint t u :=
by simp only [disjoint_left, mem_union, or_imp_distrib, forall_and_distrib]
@[simp] theorem disjoint_union_right {s t u : finset Ξ±} :
disjoint s (t βͺ u) β disjoint s t β§ disjoint s u :=
by simp only [disjoint_right, mem_union, or_imp_distrib, forall_and_distrib]
@[simp] theorem card_disjoint_union {s t : finset Ξ±} :
disjoint s t β card (s βͺ t) = card s + card t :=
finset.induction_on s (Ξ» _, by simp only [empty_union, card_empty, zero_add]) $ Ξ» a s ha ih H,
have h1 : a β s βͺ t, from Ξ» h, or.elim (mem_union.1 h) ha (disjoint_insert_left.1 H).1,
by rw [insert_union, card_insert_of_not_mem h1, card_insert_of_not_mem ha, ih (disjoint_insert_left.1 H).2, add_right_comm]
end disjoint
theorem sort_sorted_lt [decidable_linear_order Ξ±] (s : finset Ξ±) :
list.sorted (<) (sort (β€) s) :=
(sort_sorted _ _).impβ (@lt_of_le_of_ne _ _) (sort_nodup _ _)
instance [has_repr Ξ±] : has_repr (finset Ξ±) := β¨Ξ» s, repr s.1β©
def attach_fin (s : finset β) {n : β} (h : β m β s, m < n) : finset (fin n) :=
β¨s.1.pmap (Ξ» a ha, β¨a, haβ©) h, multiset.nodup_pmap (Ξ» _ _ _ _, fin.mk.inj) s.2β©
@[simp] lemma mem_attach_fin {n : β} {s : finset β} (h : β m β s, m < n) {a : fin n} :
a β s.attach_fin h β a.1 β s :=
β¨Ξ» h, let β¨b, hbβ, hbββ© := multiset.mem_pmap.1 h in hbβ βΈ hbβ,
Ξ» h, multiset.mem_pmap.2 β¨a.1, h, fin.eta _ _β©β©
@[simp] lemma card_attach_fin {n : β} (s : finset β) (h : β m β s, m < n) :
(s.attach_fin h).card = s.card := multiset.card_pmap _ _ _
section choose
variables (p : Ξ± β Prop) [decidable_pred p] (l : finset Ξ±)
def choose_x (hp : (β! a, a β l β§ p a)) : { a // a β l β§ p a } :=
multiset.choose_x p l.val hp
def choose (hp : β! a, a β l β§ p a) : Ξ± := choose_x p l hp
lemma choose_spec (hp : β! a, a β l β§ p a) : choose p l hp β l β§ p (choose p l hp) :=
(choose_x p l hp).property
lemma choose_mem (hp : β! a, a β l β§ p a) : choose p l hp β l := (choose_spec _ _ _).1
lemma choose_property (hp : β! a, a β l β§ p a) : p (choose p l hp) := (choose_spec _ _ _).2
end choose
theorem lt_wf {Ξ±} [decidable_eq Ξ±] : well_founded (@has_lt.lt (finset Ξ±) _) :=
have H : subrelation (@has_lt.lt (finset Ξ±) _)
(inv_image (<) card),
from Ξ» x y hxy, card_lt_card hxy,
subrelation.wf H $ inv_image.wf _ $ nat.lt_wf
section decidable_linear_order
variables {Ξ±} [decidable_linear_order Ξ±]
def min' (S : finset Ξ±) (H : S β β
) : Ξ± :=
@option.get _ S.min $
let β¨k, hkβ© := exists_mem_of_ne_empty H in
let β¨b, hbβ© := min_of_mem hk in by simp at hb; simp [hb]
def max' (S : finset Ξ±) (H : S β β
) : Ξ± :=
@option.get _ S.max $
let β¨k, hkβ© := exists_mem_of_ne_empty H in
let β¨b, hbβ© := max_of_mem hk in by simp at hb; simp [hb]
variables (S : finset Ξ±) (H : S β β
)
theorem min'_mem : S.min' H β S := mem_of_min $ by simp [min']
theorem min'_le (x) (H2 : x β S) : S.min' H β€ x := le_min_of_mem H2 $ option.get_mem _
theorem le_min' (x) (H2 : β y β S, x β€ y) : x β€ S.min' H := H2 _ $ min'_mem _ _
theorem max'_mem : S.max' H β S := mem_of_max $ by simp [max']
theorem le_max' (x) (H2 : x β S) : x β€ S.max' H := le_max_of_mem H2 $ option.get_mem _
theorem max'_le (x) (H2 : β y β S, y β€ x) : S.max' H β€ x := H2 _ $ max'_mem _ _
theorem min'_lt_max' {i j} (H1 : i β S) (H2 : j β S) (H3 : i β j) : S.min' H < S.max' H :=
begin
rcases lt_trichotomy i j with H4 | H4 | H4,
{ have H5 := min'_le S H i H1,
have H6 := le_max' S H j H2,
apply lt_of_le_of_lt H5,
apply lt_of_lt_of_le H4 H6 },
{ cc },
{ have H5 := min'_le S H j H2,
have H6 := le_max' S H i H1,
apply lt_of_le_of_lt H5,
apply lt_of_lt_of_le H4 H6 }
end
end decidable_linear_order
/- Ico (a closed openinterval) -/
variables {n m l : β}
/-- `Ico n m` is the set of natural numbers `n β€ k < m`. -/
def Ico (n m : β) : finset β := β¨_, Ico.nodup n mβ©
namespace Ico
@[simp] theorem val (n m : β) : (Ico n m).1 = multiset.Ico n m := rfl
@[simp] theorem to_finset (n m : β) : (multiset.Ico n m).to_finset = Ico n m :=
(multiset.to_finset_eq _).symm
theorem map_add (n m k : β) : (Ico n m).image ((+) k) = Ico (n + k) (m + k) :=
by simp [image, multiset.Ico.map_add]
theorem zero_bot (n : β) : Ico 0 n = range n :=
eq_of_veq $ multiset.Ico.zero_bot _
@[simp] theorem card (n m : β) : (Ico n m).card = m - n :=
multiset.Ico.card _ _
@[simp] theorem mem {n m l : β} : l β Ico n m β n β€ l β§ l < m :=
multiset.Ico.mem
theorem eq_empty_of_le {n m : β} (h : m β€ n) : Ico n m = β
:=
eq_of_veq $ multiset.Ico.eq_zero_of_le h
@[simp] theorem self_eq_empty {n : β} : Ico n n = β
:=
eq_empty_of_le $ le_refl n
@[simp] theorem eq_empty_iff {n m : β} : Ico n m = β
β m β€ n :=
iff.trans val_eq_zero.symm multiset.Ico.eq_zero_iff
lemma union_consecutive {n m l : β} (hnm : n β€ m) (hml : m β€ l) :
Ico n m βͺ Ico m l = Ico n l :=
by rw [β to_finset, β to_finset, β multiset.to_finset_add,
multiset.Ico.add_consecutive hnm hml, to_finset]
@[simp] theorem succ_singleton {n : β} : Ico n (n+1) = {n} :=
eq_of_veq $ multiset.Ico.succ_singleton
theorem succ_top {n m : β} (h : n β€ m) : Ico n (m + 1) = insert m (Ico n m) :=
by rw [β to_finset, multiset.Ico.succ_top h, multiset.to_finset_cons, to_finset]
theorem eq_cons {n m : β} (h : n < m) : Ico n m = insert n (Ico (n + 1) m) :=
by rw [β to_finset, multiset.Ico.eq_cons h, multiset.to_finset_cons, to_finset]
theorem pred_singleton {m : β} (h : m > 0) : Ico (m - 1) m = {m - 1} :=
eq_of_veq $ multiset.Ico.pred_singleton h
@[simp] theorem not_mem_top {n m : β} : m β Ico n m :=
multiset.Ico.not_mem_top
lemma filter_lt_of_top_le {n m l : β} (hml : m β€ l) : (Ico n m).filter (Ξ» x, x < l) = Ico n m :=
eq_of_veq $ multiset.Ico.filter_lt_of_top_le hml
lemma filter_lt_of_le_bot {n m l : β} (hln : l β€ n) : (Ico n m).filter (Ξ» x, x < l) = β
:=
eq_of_veq $ multiset.Ico.filter_lt_of_le_bot hln
lemma filter_lt_of_ge {n m l : β} (hlm : l β€ m) : (Ico n m).filter (Ξ» x, x < l) = Ico n l :=
eq_of_veq $ multiset.Ico.filter_lt_of_ge hlm
@[simp] lemma filter_lt (n m l : β) : (Ico n m).filter (Ξ» x, x < l) = Ico n (min m l) :=
eq_of_veq $ multiset.Ico.filter_lt n m l
lemma filter_ge_of_le_bot {n m l : β} (hln : l β€ n) : (Ico n m).filter (Ξ» x, x β₯ l) = Ico n m :=
eq_of_veq $ multiset.Ico.filter_ge_of_le_bot hln
lemma filter_ge_of_top_le {n m l : β} (hml : m β€ l) : (Ico n m).filter (Ξ» x, x β₯ l) = β
:=
eq_of_veq $ multiset.Ico.filter_ge_of_top_le hml
lemma filter_ge_of_ge {n m l : β} (hnl : n β€ l) : (Ico n m).filter (Ξ» x, x β₯ l) = Ico l m :=
eq_of_veq $ multiset.Ico.filter_ge_of_ge hnl
@[simp] lemma filter_ge (n m l : β) : (Ico n m).filter (Ξ» x, x β₯ l) = Ico (max n l) m :=
eq_of_veq $ multiset.Ico.filter_ge n m l
@[simp] lemma diff_left (l n m : β) : (Ico n m) \ (Ico n l) = Ico (max n l) m :=
by ext k; by_cases n β€ k; simp [h, and_comm]
@[simp] lemma diff_right (l n m : β) : (Ico n m) \ (Ico l m) = Ico n (min m l) :=
have βk, (k < m β§ (l β€ k β m β€ k)) β (k < m β§ k < l) :=
assume k, and_congr_right $ assume hk, by rw [β not_imp_not]; simp [hk],
by ext k; by_cases n β€ k; simp [h, this]
end Ico
end finset
namespace list
variable [decidable_eq Ξ±]
theorem to_finset_card_of_nodup {l : list Ξ±} (h : l.nodup) : l.to_finset.card = l.length :=
congr_arg card $ (@multiset.erase_dup_eq_self Ξ± _ l).2 h
end list
namespace lattice
variables {ΞΉ : Sort*} [complete_lattice Ξ±] [decidable_eq ΞΉ]
lemma supr_eq_supr_finset (s : ΞΉ β Ξ±) : (β¨i, s i) = (β¨t:finset (plift ΞΉ), β¨iβt, s (plift.down i)) :=
le_antisymm
(supr_le $ assume b, le_supr_of_le {plift.up b} $ le_supr_of_le (plift.up b) $ le_supr_of_le
(by simp) $ le_refl _)
(supr_le $ assume t, supr_le $ assume b, supr_le $ assume hb, le_supr _ _)
lemma infi_eq_infi_finset (s : ΞΉ β Ξ±) : (β¨
i, s i) = (β¨
t:finset (plift ΞΉ), β¨
iβt, s (plift.down i)) :=
le_antisymm
(le_infi $ assume t, le_infi $ assume b, le_infi $ assume hb, infi_le _ _)
(le_infi $ assume b, infi_le_of_le {plift.up b} $ infi_le_of_le (plift.up b) $ infi_le_of_le
(by simp) $ le_refl _)
end lattice
namespace set
variables {ΞΉ : Sort*} [decidable_eq ΞΉ]
lemma Union_eq_Union_finset (s : ΞΉ β set Ξ±) :
(βi, s i) = (βt:finset (plift ΞΉ), βiβt, s (plift.down i)) :=
lattice.supr_eq_supr_finset s
lemma Inter_eq_Inter_finset (s : ΞΉ β set Ξ±) :
(βi, s i) = (βt:finset (plift ΞΉ), βiβt, s (plift.down i)) :=
lattice.infi_eq_infi_finset s
end set
|
12e4f45739a311f288a382c954c7137ff046517b
|
d1a52c3f208fa42c41df8278c3d280f075eb020c
|
/src/Init/Data/Nat/Log2.lean
|
2148bd433cb7143f22a52e04a88c9b8b90ff6824
|
[
"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
| 816
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
prelude
import Init.NotationExtra
namespace Nat
private theorem log2_terminates : β n, n β₯ 2 β n / 2 < n
| 2, _ => by decide
| 3, _ => by decide
| n+4, _ => by
rw [div_eq, if_pos]
refine succ_lt_succ (Nat.lt_trans ?_ (lt_succ_self _))
exact log2_terminates (n+2) (succ_lt_succ (zero_lt_succ _))
exact β¨by decide, succ_lt_succ (zero_lt_succ _)β©
/--
Computes `βmax 0 (logβ n)β`.
`log2 0 = log2 1 = 0`, `log2 2 = 1`, ..., `log2 (2^i) = i`, etc.
-/
@[extern "lean_nat_log2"]
def log2 (n : @& Nat) : Nat :=
if h : n β₯ 2 then log2 (n / 2) + 1 else 0
termination_by measure id
decreasing_by exact log2_terminates _ h
|
e40179ff127ceb1e7a18b17bf12f9b7599323873
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/data/prod_auto.lean
|
92a58768188e12ffb9ab1abf511dcd43486e4d4d
|
[] |
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
| 7,934
|
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.tactic.basic
import Mathlib.PostPort
universes u_1 u_2 u_3 u_4 u_5 u_6
namespace Mathlib
/-!
# Extra facts about `prod`
This file defines `prod.swap : Ξ± Γ Ξ² β Ξ² Γ Ξ±` and proves various simple lemmas about `prod`.
-/
@[simp] theorem prod_map {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} (f : Ξ± β Ξ³)
(g : Ξ² β Ξ΄) (p : Ξ± Γ Ξ²) : prod.map f g p = (f (prod.fst p), g (prod.snd p)) :=
rfl
namespace prod
@[simp] theorem forall {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ² β Prop} :
(β (x : Ξ± Γ Ξ²), p x) β β (a : Ξ±) (b : Ξ²), p (a, b) :=
sorry
@[simp] theorem exists {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ² β Prop} :
(β (x : Ξ± Γ Ξ²), p x) β β (a : Ξ±), β (b : Ξ²), p (a, b) :=
sorry
theorem forall' {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± β Ξ² β Prop} :
(β (x : Ξ± Γ Ξ²), p (fst x) (snd x)) β β (a : Ξ±) (b : Ξ²), p a b :=
forall
theorem exists' {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± β Ξ² β Prop} :
(β (x : Ξ± Γ Ξ²), p (fst x) (snd x)) β β (a : Ξ±), β (b : Ξ²), p a b :=
exists
@[simp] theorem map_mk {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} (f : Ξ± β Ξ³)
(g : Ξ² β Ξ΄) (a : Ξ±) (b : Ξ²) : map f g (a, b) = (f a, g b) :=
rfl
theorem map_fst {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} (f : Ξ± β Ξ³) (g : Ξ² β Ξ΄)
(p : Ξ± Γ Ξ²) : fst (map f g p) = f (fst p) :=
rfl
theorem map_snd {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} (f : Ξ± β Ξ³) (g : Ξ² β Ξ΄)
(p : Ξ± Γ Ξ²) : snd (map f g p) = g (snd p) :=
rfl
theorem map_fst' {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} (f : Ξ± β Ξ³)
(g : Ξ² β Ξ΄) : fst β map f g = f β fst :=
funext (map_fst f g)
theorem map_snd' {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} (f : Ξ± β Ξ³)
(g : Ξ² β Ξ΄) : snd β map f g = g β snd :=
funext (map_snd f g)
/--
Composing a `prod.map` with another `prod.map` is equal to
a single `prod.map` of composed functions.
-/
theorem map_comp_map {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} {Ξ΅ : Type u_5}
{ΞΆ : Type u_6} (f : Ξ± β Ξ²) (f' : Ξ³ β Ξ΄) (g : Ξ² β Ξ΅) (g' : Ξ΄ β ΞΆ) :
map g g' β map f f' = map (g β f) (g' β f') :=
rfl
/--
Composing a `prod.map` with another `prod.map` is equal to
a single `prod.map` of composed functions, fully applied.
-/
theorem map_map {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} {Ξ΅ : Type u_5}
{ΞΆ : Type u_6} (f : Ξ± β Ξ²) (f' : Ξ³ β Ξ΄) (g : Ξ² β Ξ΅) (g' : Ξ΄ β ΞΆ) (x : Ξ± Γ Ξ³) :
map g g' (map f f' x) = map (g β f) (g' β f') x :=
rfl
@[simp] theorem mk.inj_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {aβ : Ξ±} {aβ : Ξ±} {bβ : Ξ²} {bβ : Ξ²} :
(aβ, bβ) = (aβ, bβ) β aβ = aβ β§ bβ = bβ :=
sorry
theorem mk.inj_left {Ξ± : Type u_1} {Ξ² : Type u_2} (a : Ξ±) : function.injective (Prod.mk a) := sorry
theorem mk.inj_right {Ξ± : Type u_1} {Ξ² : Type u_2} (b : Ξ²) :
function.injective fun (a : Ξ±) => (a, b) :=
sorry
theorem ext_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} {q : Ξ± Γ Ξ²} :
p = q β fst p = fst q β§ snd p = snd q :=
sorry
theorem ext {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} {q : Ξ± Γ Ξ²} (hβ : fst p = fst q)
(hβ : snd p = snd q) : p = q :=
iff.mpr ext_iff { left := hβ, right := hβ }
theorem map_def {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4} {f : Ξ± β Ξ³}
{g : Ξ² β Ξ΄} : map f g = fun (p : Ξ± Γ Ξ²) => (f (fst p), g (snd p)) :=
funext fun (p : Ξ± Γ Ξ²) => ext (map_fst f g p) (map_snd f g p)
theorem id_prod {Ξ± : Type u_1} : (fun (p : Ξ± Γ Ξ±) => (fst p, snd p)) = id := sorry
theorem fst_surjective {Ξ± : Type u_1} {Ξ² : Type u_2} [h : Nonempty Ξ²] : function.surjective fst :=
fun (x : Ξ±) => nonempty.elim h fun (y : Ξ²) => Exists.intro (x, y) rfl
theorem snd_surjective {Ξ± : Type u_1} {Ξ² : Type u_2} [h : Nonempty Ξ±] : function.surjective snd :=
fun (y : Ξ²) => nonempty.elim h fun (x : Ξ±) => Exists.intro (x, y) rfl
theorem fst_injective {Ξ± : Type u_1} {Ξ² : Type u_2} [subsingleton Ξ²] : function.injective fst :=
fun (x y : Ξ± Γ Ξ²) (h : fst x = fst y) => ext h (subsingleton.elim (snd x) (snd y))
theorem snd_injective {Ξ± : Type u_1} {Ξ² : Type u_2} [subsingleton Ξ±] : function.injective snd :=
fun (x y : Ξ± Γ Ξ²) (h : snd x = snd y) => ext (subsingleton.elim (fst x) (fst y)) h
/-- Swap the factors of a product. `swap (a, b) = (b, a)` -/
def swap {Ξ± : Type u_1} {Ξ² : Type u_2} : Ξ± Γ Ξ² β Ξ² Γ Ξ± := fun (p : Ξ± Γ Ξ²) => (snd p, fst p)
@[simp] theorem swap_swap {Ξ± : Type u_1} {Ξ² : Type u_2} (x : Ξ± Γ Ξ²) : swap (swap x) = x :=
cases_on x
fun (x_fst : Ξ±) (x_snd : Ξ²) =>
idRhs (swap (swap (x_fst, x_snd)) = swap (swap (x_fst, x_snd))) rfl
@[simp] theorem fst_swap {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} : fst (swap p) = snd p := rfl
@[simp] theorem snd_swap {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} : snd (swap p) = fst p := rfl
@[simp] theorem swap_prod_mk {Ξ± : Type u_1} {Ξ² : Type u_2} {a : Ξ±} {b : Ξ²} : swap (a, b) = (b, a) :=
rfl
@[simp] theorem swap_swap_eq {Ξ± : Type u_1} {Ξ² : Type u_2} : swap β swap = id := funext swap_swap
@[simp] theorem swap_left_inverse {Ξ± : Type u_1} {Ξ² : Type u_2} : function.left_inverse swap swap :=
swap_swap
@[simp] theorem swap_right_inverse {Ξ± : Type u_1} {Ξ² : Type u_2} :
function.right_inverse swap swap :=
swap_swap
theorem swap_injective {Ξ± : Type u_1} {Ξ² : Type u_2} : function.injective swap :=
function.left_inverse.injective swap_left_inverse
theorem swap_surjective {Ξ± : Type u_1} {Ξ² : Type u_2} : function.surjective swap :=
function.left_inverse.surjective swap_left_inverse
theorem swap_bijective {Ξ± : Type u_1} {Ξ² : Type u_2} : function.bijective swap :=
{ left := swap_injective, right := swap_surjective }
@[simp] theorem swap_inj {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} {q : Ξ± Γ Ξ²} :
swap p = swap q β p = q :=
function.injective.eq_iff swap_injective
theorem eq_iff_fst_eq_snd_eq {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} {q : Ξ± Γ Ξ²} :
p = q β fst p = fst q β§ snd p = snd q :=
sorry
theorem fst_eq_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} {x : Ξ±} : fst p = x β p = (x, snd p) :=
sorry
theorem snd_eq_iff {Ξ± : Type u_1} {Ξ² : Type u_2} {p : Ξ± Γ Ξ²} {x : Ξ²} : snd p = x β p = (fst p, x) :=
sorry
theorem lex_def {Ξ± : Type u_1} {Ξ² : Type u_2} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) {p : Ξ± Γ Ξ²}
{q : Ξ± Γ Ξ²} : lex r s p q β r (fst p) (fst q) β¨ fst p = fst q β§ s (snd p) (snd q) :=
sorry
protected instance lex.decidable {Ξ± : Type u_1} {Ξ² : Type u_2} [DecidableEq Ξ±] (r : Ξ± β Ξ± β Prop)
(s : Ξ² β Ξ² β Prop) [DecidableRel r] [DecidableRel s] : DecidableRel (lex r s) :=
fun (p q : Ξ± Γ Ξ²) => decidable_of_decidable_of_iff or.decidable sorry
end prod
theorem function.injective.prod_map {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4}
{f : Ξ± β Ξ³} {g : Ξ² β Ξ΄} (hf : function.injective f) (hg : function.injective g) :
function.injective (prod.map f g) :=
fun (x y : Ξ± Γ Ξ²) (h : prod.map f g x = prod.map f g y) =>
prod.ext (hf (and.left (iff.mp prod.ext_iff h))) (hg (and.right (iff.mp prod.ext_iff h)))
theorem function.surjective.prod_map {Ξ± : Type u_1} {Ξ² : Type u_2} {Ξ³ : Type u_3} {Ξ΄ : Type u_4}
{f : Ξ± β Ξ³} {g : Ξ² β Ξ΄} (hf : function.surjective f) (hg : function.surjective g) :
function.surjective (prod.map f g) :=
sorry
end Mathlib
|
e1b04afedda3c338b28249a0382d4d685d4618e4
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/test/qpf.lean
|
f3a358092fb2e89dc79dba3dd31eaea9d311d94c
|
[
"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
| 6,161
|
lean
|
import data.qpf.univariate.basic
import control.bifunctor
universes u
variables {F : Type u β Type u} [functor F]
namespace qpf
section box
variables (F)
/-- apply a functor to a set of values. taken from
[Basil FΓΌrer, Andreas Lochbihler, Joshua Schneider, Dmitriy Traytel *Quotients of Bounded Natural Functors*][fuerer-lochbihler-schneider-traytel2020]
henceforth referred to as the QBNF paper
-/
def box {Ξ±} (A : set Ξ±) : set (F Ξ±) :=
{ x | β Ξ² (f g : Ξ± β Ξ²), (β a β A, f a = g a) β f <$> x = g <$> x }
variables {F}
/--
Alternate notion of support set based on `box`.
Taken from the QBNF paper
-/
def supp' {Ξ±} (x : F Ξ±) : set Ξ± :=
β A β { A : set Ξ± | x β box F A}, A
/--
Alternate notion of predicate lifting based on `box`.
Taken from the QBNF paper
-/
def liftp' {Ξ±} (x : F Ξ±) (p : Ξ± β Prop) : Prop :=
β a β supp' x, p a
end box
end qpf
namespace ex
/-- polynomial functor isomorph to `Ξ± Γ _` for some `Ξ±` -/
def prod.pfunctor (Ξ± : Type) : pfunctor :=
β¨ Ξ±, Ξ» _, unit β©
instance {Ξ±} : qpf (prod Ξ±) :=
{ P := prod.pfunctor Ξ±,
abs := Ξ» Ξ² β¨a,fβ©, (a, f ()),
repr := Ξ» Ξ² β¨x,yβ©, β¨x, Ξ» _, yβ©,
abs_repr := Ξ» Ξ² β¨x,yβ©, rfl,
abs_map := Ξ» Ξ² Ξ³ f β¨a,gβ©, rfl }
/-- example relation for products -/
def foo.R (Ξ± : Type) (x y : bool Γ Ξ±) : Prop :=
x.1 = y.1 β§ (x.1 β x.2 = y.2)
lemma equivalence_foo.R (Ξ±) : equivalence (foo.R Ξ±) :=
begin
refine β¨_,_,_β©,
{ intro, exact β¨rfl,Ξ» _, rflβ© },
{ intros x y h, refine β¨h.1.symm, Ξ» _, (h.2 _).symmβ©,
rwa h.1 },
{ rintros x y z β¨ha,ha'β© β¨hb,hb'β©,
refine β¨ha.trans hb, Ξ» hh, _β©,
refine (ha' hh).trans (hb' _),
rwa β ha }
end
/-- example of a qpf -/
def foo (Ξ± : Type) :=
quot $ foo.R Ξ±
instance {Ξ±} [inhabited Ξ±] : inhabited (foo Ξ±) := β¨ quot.mk _ (default _) β©
/-- functor operation of `foo` -/
def foo.map {Ξ± Ξ²} (f : Ξ± β Ξ²) (x : foo Ξ±) : foo Ξ² :=
quot.lift_on x (Ξ» x : bool Γ Ξ±, quot.mk (foo.R Ξ²) $ f <$> x)
(Ξ» β¨aβ,aββ© β¨bβ,bββ© h, quot.sound β¨h.1,Ξ» h', show f aβ = f bβ, from congr_arg f (h.2 h')β©)
instance : functor foo :=
{ map := @foo.map }
@[simp]
lemma foo.map_mk {Ξ± Ξ² : Type} (f : Ξ± β Ξ²) (x : bool Γ Ξ±) :
(f <$> quot.mk _ x : foo Ξ²) = quot.mk _ (f <$> x) :=
by simp [(<$>),foo.map]
noncomputable instance qpf.foo : qpf foo :=
@qpf.quotient_qpf (prod bool) _ ex.prod.qpf foo _ (Ξ» Ξ±, quot.mk _) (Ξ» Ξ±, quot.out)
(by simp)
(by intros; simp)
/-- constructor for `foo` -/
def foo.mk {Ξ±} (b : bool) (x : Ξ±) : foo Ξ± := quot.mk _ (b, x)
@[simp]
lemma foo.map_mk' {Ξ± Ξ² : Type} (f : Ξ± β Ξ²) (b : bool) (x : Ξ±) :
f <$> foo.mk b x = foo.mk b (f x) :=
by simp only [foo.mk, foo.map_mk]; refl
@[simp]
lemma foo.map_tt {Ξ± : Type} (x y : Ξ±) :
foo.mk tt x = foo.mk tt y β x = y :=
by simp [foo.mk]; split; intro h; [replace h := quot.exact _ h, rw h];
rw (equivalence_foo.R _).eqv_gen_iff at h;
exact h.2 rfl
/-- consequence of original definition of `supp`. If there exists more than
one value of type `Ξ±`, then the support of `foo.mk ff x` is empty -/
lemma supp_mk_ffβ {Ξ±} (x y : Ξ±) (h : Β¬ x = y) : functor.supp (foo.mk ff x) = {} :=
begin
dsimp [functor.supp], ext z, simp, -- split; intro h,
classical, by_cases x = z,
{ use (Ξ» a, Β¬ z = a), subst z,
dsimp [functor.liftp],
simp, refine β¨foo.mk ff β¨y,hβ©,_β©,
simp, apply quot.sound, simp [foo.R] },
{ use (Ξ» a, x = a),
dsimp [functor.liftp],
simp [h], use foo.mk ff β¨x,rflβ©,
simp }
end
/-- consequence of original definition of `supp`. If there exists only
one value of type `Ξ±`, then the support of `foo.mk ff x` contains that value -/
lemma supp_mk_ffβ {Ξ±} (x : Ξ±) (h : β z, x = z) : functor.supp (foo.mk ff x) = {x} :=
begin
dsimp [functor.supp], ext y, simp, split; intro h',
{ apply @h' (= x), dsimp [functor.liftp],
use foo.mk ff β¨x,rflβ©, refl },
{ introv hp, simp [functor.liftp] at hp,
rcases hp with β¨β¨z,z',hzβ©,hpβ©,
simp at hp, convert hz,
rw [h'], apply h },
end
/--
Such a QPF is not uniform
-/
lemma foo_not_uniform : Β¬ @qpf.is_uniform foo _ qpf.foo :=
begin
simp only [qpf.is_uniform, foo, qpf.foo, set.image_univ, not_forall, not_imp],
existsi [bool,ff,ff,Ξ» a : unit, tt,Ξ» a : unit, ff], split,
{ apply quot.sound, simp [foo.R, qpf.abs, prod.qpf._match_1] },
{ simp! only [set.range, set.ext_iff],
simp only [not_exists, false_iff, bool.forall_bool, eq_self_iff_true, exists_false, not_true,
and_self, set.mem_set_of_eq, iff_false],
exact Ξ» h, h () }
end
/-- intuitive consequence of original definition of `supp`. -/
lemma supp_mk_tt {Ξ±} (x : Ξ±) : functor.supp (foo.mk tt x) = {x} :=
begin
dsimp [functor.supp], ext y, simp, split; intro h',
{ apply @h' (= x), dsimp [functor.liftp],
use foo.mk tt β¨x,rflβ©, refl },
{ introv hp, simp [functor.liftp] at hp,
rcases hp with β¨β¨z,z',hzβ©,hpβ©,
simp at hp, replace hp := quot.exact _ hp,
rw (equivalence_foo.R _).eqv_gen_iff at hp,
rcases hp with β¨β¨β©,hpβ©, subst y,
replace hp := hp rfl, cases hp,
exact hz }
end
/-- simple consequence of the definition of `supp` from the QBNF paper -/
lemma supp_mk_ff' {Ξ±} (x : Ξ±) : qpf.supp' (foo.mk ff x) = {} :=
begin
dsimp [qpf.supp'], ext, simp, dsimp [qpf.box],
use β
, simp [foo.mk], intros, apply quot.sound,
dsimp [foo.R], split, refl, rintro β¨ β©
end
/-- simple consequence of the definition of `supp` from the QBNF paper -/
lemma supp_mk_tt' {Ξ±} (x : Ξ±) : qpf.supp' (foo.mk tt x) = {x} :=
begin
dsimp [qpf.supp'], ext, simp, dsimp [qpf.box], split; intro h,
{ specialize h {x} _,
{ clear h, introv hfg, simp, rw hfg, simp },
{ simp at h, assumption }, },
{ introv hfg, subst x_1, classical,
let f : Ξ± β Ξ± β bool := Ξ» x, if x β i then sum.inl x else sum.inr tt,
let g : Ξ± β Ξ± β bool := Ξ» x, if x β i then sum.inl x else sum.inr ff,
specialize hfg _ f g _,
{ intros, simp [*,f,g,if_pos] },
{ simp [f,g] at hfg, split_ifs at hfg,
assumption, cases hfg } }
end
end ex
|
19a65c7bf9896f3ca3367f11ca960a116d0ff449
|
8b9f17008684d796c8022dab552e42f0cb6fb347
|
/hott/algebra/precategory/constructions.hlean
|
67f76c39abf693963a941615ee46ea0b00364ba3
|
[
"Apache-2.0"
] |
permissive
|
chubbymaggie/lean
|
0d06ae25f9dd396306fb02190e89422ea94afd7b
|
d2c7b5c31928c98f545b16420d37842c43b4ae9a
|
refs/heads/master
| 1,611,313,622,901
| 1,430,266,839,000
| 1,430,267,083,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 9,929
|
hlean
|
/-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: algebra.precategory.constructions
Authors: Floris van Doorn, Jakob von Raumer
This file contains basic constructions on precategories, including common precategories
-/
import .nat_trans
import types.prod types.sigma types.pi
open eq prod eq eq.ops equiv is_trunc
namespace category
namespace opposite
definition opposite [reducible] {ob : Type} (C : precategory ob) : precategory ob :=
precategory.mk (Ξ» a b, hom b a)
(Ξ» a b, !homH)
(Ξ» a b c f g, g β f)
(Ξ» a, id)
(Ξ» a b c d f g h, !assocβ»ΒΉ)
(Ξ» a b f, !id_right)
(Ξ» a b f, !id_left)
definition Opposite [reducible] (C : Precategory) : Precategory := precategory.Mk (opposite C)
infixr `βop`:60 := @comp _ (opposite _) _ _ _
variables {C : Precategory} {a b c : C}
set_option apply.class_instance false -- disable class instance resolution in the apply tactic
definition compose_op {f : hom a b} {g : hom b c} : f βop g = g β f := idp
-- TODO: Decide whether just to use funext for this theorem or
-- take the trick they use in Coq-HoTT, and introduce a further
-- axiom in the definition of precategories that provides thee
-- symmetric associativity proof.
definition opposite_opposite' {ob : Type} (C : precategory ob) : opposite (opposite C) = C :=
begin
apply (precategory.rec_on C), intros [hom', homH', comp', ID', assoc', id_left', id_right'],
apply (ap (Ξ»assoc'', precategory.mk hom' @homH' comp' ID' assoc'' id_left' id_right')),
repeat (apply eq_of_homotopy ; intros ),
apply ap,
apply (@is_hset.elim), apply !homH',
end
definition opposite_opposite : Opposite (Opposite C) = C :=
(ap (Precategory.mk C) (opposite_opposite' C)) β¬ !Precategory.eta
end opposite
-- Note: Discrete precategory doesn't really make sense in HoTT,
-- We'll define a discrete _category_ later.
/-section
open decidable unit empty
variables {A : Type} [H : decidable_eq A]
include H
definition set_hom (a b : A) := decidable.rec_on (H a b) (Ξ»h, unit) (Ξ»h, empty)
theorem set_hom_subsingleton [instance] (a b : A) : subsingleton (set_hom a b) := _
definition set_compose {a b c : A} (g : set_hom b c) (f : set_hom a b) : set_hom a c :=
decidable.rec_on
(H b c)
(Ξ» Hbc g, decidable.rec_on
(H a b)
(Ξ» Hab f, rec_on_true (trans Hab Hbc) β)
(Ξ»h f, empty.rec _ f) f)
(Ξ»h (g : empty), empty.rec _ g) g
omit H
definition discrete_precategory (A : Type) [H : decidable_eq A] : precategory A :=
mk (Ξ»a b, set_hom a b)
(Ξ» a b c g f, set_compose g f)
(Ξ» a, decidable.rec_on_true rfl β)
(Ξ» a b c d h g f, @subsingleton.elim (set_hom a d) _ _ _)
(Ξ» a b f, @subsingleton.elim (set_hom a b) _ _ _)
(Ξ» a b f, @subsingleton.elim (set_hom a b) _ _ _)
definition Discrete_category (A : Type) [H : decidable_eq A] := Mk (discrete_category A)
end
section
open unit bool
definition category_one := discrete_category unit
definition Category_one := Mk category_one
definition category_two := discrete_category bool
definition Category_two := Mk category_two
end-/
namespace product
section
open prod is_trunc
definition precategory_prod [reducible] {obC obD : Type} (C : precategory obC) (D : precategory obD)
: precategory (obC Γ obD) :=
precategory.mk (Ξ» a b, hom (pr1 a) (pr1 b) Γ hom (pr2 a) (pr2 b))
(Ξ» a b, !is_trunc_prod)
(Ξ» a b c g f, (pr1 g β pr1 f , pr2 g β pr2 f))
(Ξ» a, (id, id))
(Ξ» a b c d h g f, pair_eq !assoc !assoc )
(Ξ» a b f, prod_eq !id_left !id_left )
(Ξ» a b f, prod_eq !id_right !id_right)
definition Precategory_prod [reducible] (C D : Precategory) : Precategory :=
precategory.Mk (precategory_prod C D)
end
end product
namespace ops
--notation 1 := Category_one
--notation 2 := Category_two
postfix `α΅α΅`:max := opposite.Opposite
infixr `Γc`:30 := product.Precategory_prod
--instance [persistent] type_category category_one
-- category_two product.prod_category
end ops
open ops
namespace opposite
open ops functor
definition opposite_functor [reducible] {C D : Precategory} (F : C β D) : Cα΅α΅ β Dα΅α΅ :=
begin
apply (@functor.mk (Cα΅α΅) (Dα΅α΅)),
intro a, apply (respect_id F),
intros, apply (@respect_comp C D)
end
end opposite
namespace product
section
open ops functor
definition prod_functor [reducible] {C C' D D' : Precategory} (F : C β D) (G : C' β D') : C Γc C' β D Γc D' :=
functor.mk (Ξ» a, pair (F (pr1 a)) (G (pr2 a)))
(Ξ» a b f, pair (F (pr1 f)) (G (pr2 f)))
(Ξ» a, pair_eq !respect_id !respect_id)
(Ξ» a b c g f, pair_eq !respect_comp !respect_comp)
end
end product
definition precategory_hset [reducible] : precategory hset :=
precategory.mk (Ξ»x y : hset, x β y)
_
(Ξ»x y z g f a, g (f a))
(Ξ»x a, a)
(Ξ»x y z w h g f, eq_of_homotopy (Ξ»a, idp))
(Ξ»x y f, eq_of_homotopy (Ξ»a, idp))
(Ξ»x y f, eq_of_homotopy (Ξ»a, idp))
definition Precategory_hset [reducible] : Precategory :=
Precategory.mk hset precategory_hset
section
open iso functor nat_trans
definition precategory_functor [instance] [reducible] (D C : Precategory)
: precategory (functor C D) :=
precategory.mk (Ξ»a b, nat_trans a b)
(Ξ» a b, @is_hset_nat_trans C D a b)
(Ξ» a b c g f, nat_trans.compose g f)
(Ξ» a, nat_trans.id)
(Ξ» a b c d h g f, !nat_trans.assoc)
(Ξ» a b f, !nat_trans.id_left)
(Ξ» a b f, !nat_trans.id_right)
definition Precategory_functor [reducible] (D C : Precategory) : Precategory :=
precategory.Mk (precategory_functor D C)
end
namespace ops
infixr `^c`:35 := Precategory_functor
end ops
section
open iso functor nat_trans
/- we prove that if a natural transformation is pointwise an to_fun, then it is an to_fun -/
variables {C D : Precategory} {F G : C β D} (Ξ· : F βΉ G) [iso : Ξ (a : C), is_iso (Ξ· a)]
include iso
definition nat_trans_inverse : G βΉ F :=
nat_trans.mk
(Ξ»c, (Ξ· c)β»ΒΉ)
(Ξ»c d f,
begin
apply comp_inverse_eq_of_eq_comp,
apply concat, rotate_left 1, apply assoc,
apply eq_inverse_comp_of_comp_eq,
apply inverse,
apply naturality,
end)
definition nat_trans_left_inverse : nat_trans_inverse Ξ· βn Ξ· = nat_trans.id :=
begin
fapply (apD011 nat_trans.mk),
apply eq_of_homotopy, intro c, apply left_inverse,
apply eq_of_homotopy, intros, apply eq_of_homotopy, intros, apply eq_of_homotopy, intros,
apply is_hset.elim
end
definition nat_trans_right_inverse : Ξ· βn nat_trans_inverse Ξ· = nat_trans.id :=
begin
fapply (apD011 nat_trans.mk),
apply eq_of_homotopy, intro c, apply right_inverse,
apply eq_of_homotopy, intros, apply eq_of_homotopy, intros, apply eq_of_homotopy, intros,
apply is_hset.elim
end
definition is_iso_nat_trans : is_iso Ξ· :=
is_iso.mk (nat_trans_left_inverse Ξ·) (nat_trans_right_inverse Ξ·)
omit iso
-- local attribute is_iso_nat_trans [instance]
-- definition functor_iso_functor (H : Ξ (a : C), F a β
G a) : F β
G := -- is this true?
-- iso.mk _
end
section
open iso functor category.ops nat_trans iso.iso
/- and conversely, if a natural transformation is an iso, it is componentwise an iso -/
variables {C D : Precategory} {F G : D ^c C} (Ξ· : hom F G) [isoΞ· : is_iso Ξ·] (c : C)
include isoΞ·
definition componentwise_is_iso : is_iso (Ξ· c) :=
@is_iso.mk _ _ _ _ _ (natural_map Ξ·β»ΒΉ c) (ap010 natural_map ( left_inverse Ξ·) c)
(ap010 natural_map (right_inverse Ξ·) c)
local attribute componentwise_is_iso [instance]
definition natural_map_inverse : natural_map Ξ·β»ΒΉ c = (Ξ· c)β»ΒΉ := idp
definition naturality_iso {c c' : C} (f : c βΆ c') : G f = Ξ· c' β F f β (Ξ· c)β»ΒΉ :=
calc
G f = (G f β Ξ· c) β (Ξ· c)β»ΒΉ : comp_inverse_cancel_right
... = (Ξ· c' β F f) β (Ξ· c)β»ΒΉ : {naturality Ξ· f}
... = Ξ· c' β F f β (Ξ· c)β»ΒΉ : assoc
definition naturality_iso' {c c' : C} (f : c βΆ c') : (Ξ· c')β»ΒΉ β G f β Ξ· c = F f :=
calc
(Ξ· c')β»ΒΉ β G f β Ξ· c = (Ξ· c')β»ΒΉ β Ξ· c' β F f : {naturality Ξ· f}
... = F f : inverse_comp_cancel_left
omit isoΞ·
definition componentwise_iso (Ξ· : F β
G) (c : C) : F c β
G c :=
@iso.mk _ _ _ _ (natural_map (to_hom Ξ·) c)
(@componentwise_is_iso _ _ _ _ (to_hom Ξ·) (struct Ξ·) c)
definition componentwise_iso_id (c : C) : componentwise_iso (iso.refl F) c = iso.refl (F c) :=
iso.eq_mk (idpath id)
definition componentwise_iso_iso_of_eq (p : F = G) (c : C)
: componentwise_iso (iso_of_eq p) c = iso_of_eq (ap010 to_fun_ob p c) :=
eq.rec_on p !componentwise_iso_id
definition natural_map_hom_of_eq (p : F = G) (c : C)
: natural_map (hom_of_eq p) c = hom_of_eq (ap010 to_fun_ob p c) :=
eq.rec_on p idp
definition natural_map_inv_of_eq (p : F = G) (c : C)
: natural_map (inv_of_eq p) c = hom_of_eq (ap010 to_fun_ob p c)β»ΒΉ :=
eq.rec_on p idp
end
namespace ops
infixr `Γf`:30 := product.prod_functor
infixr `α΅α΅αΆ `:(max+1) := opposite.opposite_functor
end ops
end category
|
8fd8182a23a56c984070d4ce261d032b315fe865
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/category_theory/monoidal/functor.lean
|
748ac9776ba92dab8f6af966e0b715cd3cbf2c1b
|
[
"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
| 14,068
|
lean
|
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta
-/
import category_theory.monoidal.category
import category_theory.adjunction.basic
/-!
# (Lax) monoidal functors
A lax monoidal functor `F` between monoidal categories `C` and `D`
is a functor between the underlying categories equipped with morphisms
* `Ξ΅ : π_ D βΆ F.obj (π_ C)` (called the unit morphism)
* `ΞΌ X Y : (F.obj X) β (F.obj Y) βΆ F.obj (X β Y)` (called the tensorator, or strength).
satisfying various axioms.
A monoidal functor is a lax monoidal functor for which `Ξ΅` and `ΞΌ` are isomorphisms.
We show that the composition of (lax) monoidal functors gives a (lax) monoidal functor.
See also `category_theory.monoidal.functorial` for a typeclass decorating an object-level
function with the additional data of a monoidal functor.
This is useful when stating that a pre-existing functor is monoidal.
See `category_theory.monoidal.natural_transformation` for monoidal natural transformations.
We show in `category_theory.monoidal.Mon_` that lax monoidal functors take monoid objects
to monoid objects.
## Future work
* Oplax monoidal functors.
## References
See https://stacks.math.columbia.edu/tag/0FFL.
-/
open category_theory
universes vβ vβ vβ uβ uβ uβ
open category_theory.category
open category_theory.functor
namespace category_theory
section
open monoidal_category
variables (C : Type uβ) [category.{vβ} C] [monoidal_category.{vβ} C]
(D : Type uβ) [category.{vβ} D] [monoidal_category.{vβ} D]
/-- A lax monoidal functor is a functor `F : C β₯€ D` between monoidal categories,
equipped with morphisms `Ξ΅ : π _D βΆ F.obj (π_ C)` and `ΞΌ X Y : F.obj X β F.obj Y βΆ F.obj (X β Y)`,
satisfying the appropriate coherences. -/
-- The direction of `left_unitality` and `right_unitality` as simp lemmas may look strange:
-- remember the rule of thumb that component indices of natural transformations
-- "weigh more" than structural maps.
-- (However by this argument `associativity` is currently stated backwards!)
structure lax_monoidal_functor extends C β₯€ D :=
-- unit morphism
(Ξ΅ : π_ D βΆ obj (π_ C))
-- tensorator
(ΞΌ : Ξ X Y : C, (obj X) β (obj Y) βΆ obj (X β Y))
(ΞΌ_natural' : β {X Y X' Y' : C}
(f : X βΆ Y) (g : X' βΆ Y'),
((map f) β (map g)) β« ΞΌ Y Y' = ΞΌ X X' β« map (f β g)
. obviously)
-- associativity of the tensorator
(associativity' : β (X Y Z : C),
(ΞΌ X Y β π (obj Z)) β« ΞΌ (X β Y) Z β« map (Ξ±_ X Y Z).hom
= (Ξ±_ (obj X) (obj Y) (obj Z)).hom β« (π (obj X) β ΞΌ Y Z) β« ΞΌ X (Y β Z)
. obviously)
-- unitality
(left_unitality' : β X : C,
(Ξ»_ (obj X)).hom
= (Ξ΅ β π (obj X)) β« ΞΌ (π_ C) X β« map (Ξ»_ X).hom
. obviously)
(right_unitality' : β X : C,
(Ο_ (obj X)).hom
= (π (obj X) β Ξ΅) β« ΞΌ X (π_ C) β« map (Ο_ X).hom
. obviously)
restate_axiom lax_monoidal_functor.ΞΌ_natural'
attribute [simp, reassoc] lax_monoidal_functor.ΞΌ_natural
restate_axiom lax_monoidal_functor.left_unitality'
attribute [simp] lax_monoidal_functor.left_unitality
restate_axiom lax_monoidal_functor.right_unitality'
attribute [simp] lax_monoidal_functor.right_unitality
restate_axiom lax_monoidal_functor.associativity'
attribute [simp, reassoc] lax_monoidal_functor.associativity
-- When `rewrite_search` lands, add @[search] attributes to
-- lax_monoidal_functor.ΞΌ_natural lax_monoidal_functor.left_unitality
-- lax_monoidal_functor.right_unitality lax_monoidal_functor.associativity
section
variables {C D}
@[simp, reassoc]
lemma lax_monoidal_functor.left_unitality_inv (F : lax_monoidal_functor C D) (X : C) :
(Ξ»_ (F.obj X)).inv β« (F.Ξ΅ β π (F.obj X)) β« F.ΞΌ (π_ C) X = F.map (Ξ»_ X).inv :=
begin
rw [iso.inv_comp_eq, F.left_unitality, category.assoc, category.assoc,
βF.to_functor.map_comp, iso.hom_inv_id, F.to_functor.map_id, comp_id],
end
@[simp, reassoc]
lemma lax_monoidal_functor.right_unitality_inv (F : lax_monoidal_functor C D) (X : C) :
(Ο_ (F.obj X)).inv β« (π (F.obj X) β F.Ξ΅) β« F.ΞΌ X (π_ C) = F.map (Ο_ X).inv :=
begin
rw [iso.inv_comp_eq, F.right_unitality, category.assoc, category.assoc,
βF.to_functor.map_comp, iso.hom_inv_id, F.to_functor.map_id, comp_id],
end
@[simp, reassoc]
lemma lax_monoidal_functor.associativity_inv (F : lax_monoidal_functor C D) (X Y Z : C) :
(π (F.obj X) β F.ΞΌ Y Z) β« F.ΞΌ X (Y β Z) β« F.map (Ξ±_ X Y Z).inv =
(Ξ±_ (F.obj X) (F.obj Y) (F.obj Z)).inv β« (F.ΞΌ X Y β π (F.obj Z)) β« F.ΞΌ (X β Y) Z :=
begin
rw [iso.eq_inv_comp, βF.associativity_assoc,
βF.to_functor.map_comp, iso.hom_inv_id, F.to_functor.map_id, comp_id],
end
end
/--
A monoidal functor is a lax monoidal functor for which the tensorator and unitor as isomorphisms.
See https://stacks.math.columbia.edu/tag/0FFL.
-/
structure monoidal_functor
extends lax_monoidal_functor.{vβ vβ} C D :=
(Ξ΅_is_iso : is_iso Ξ΅ . tactic.apply_instance)
(ΞΌ_is_iso : Ξ X Y : C, is_iso (ΞΌ X Y) . tactic.apply_instance)
attribute [instance] monoidal_functor.Ξ΅_is_iso monoidal_functor.ΞΌ_is_iso
variables {C D}
/--
The unit morphism of a (strong) monoidal functor as an isomorphism.
-/
noncomputable
def monoidal_functor.Ξ΅_iso (F : monoidal_functor.{vβ vβ} C D) :
tensor_unit D β
F.obj (tensor_unit C) :=
as_iso F.Ξ΅
/--
The tensorator of a (strong) monoidal functor as an isomorphism.
-/
noncomputable
def monoidal_functor.ΞΌ_iso (F : monoidal_functor.{vβ vβ} C D) (X Y : C) :
(F.obj X) β (F.obj Y) β
F.obj (X β Y) :=
as_iso (F.ΞΌ X Y)
end
open monoidal_category
namespace lax_monoidal_functor
variables (C : Type uβ) [category.{vβ} C] [monoidal_category.{vβ} C]
/-- The identity lax monoidal functor. -/
@[simps] def id : lax_monoidal_functor.{vβ vβ} C C :=
{ Ξ΅ := π _,
ΞΌ := Ξ» X Y, π _,
.. π C }
instance : inhabited (lax_monoidal_functor C C) := β¨id Cβ©
end lax_monoidal_functor
namespace monoidal_functor
section
variables {C : Type uβ} [category.{vβ} C] [monoidal_category.{vβ} C]
variables {D : Type uβ} [category.{vβ} D] [monoidal_category.{vβ} D]
lemma map_tensor (F : monoidal_functor.{vβ vβ} C D) {X Y X' Y' : C} (f : X βΆ Y) (g : X' βΆ Y') :
F.map (f β g) = inv (F.ΞΌ X X') β« ((F.map f) β (F.map g)) β« F.ΞΌ Y Y' :=
by simp
lemma map_left_unitor (F : monoidal_functor.{vβ vβ} C D) (X : C) :
F.map (Ξ»_ X).hom = inv (F.ΞΌ (π_ C) X) β« (inv F.Ξ΅ β π (F.obj X)) β« (Ξ»_ (F.obj X)).hom :=
begin
simp only [lax_monoidal_functor.left_unitality],
slice_rhs 2 3 { rw βcomp_tensor_id, simp, },
simp,
end
lemma map_right_unitor (F : monoidal_functor.{vβ vβ} C D) (X : C) :
F.map (Ο_ X).hom = inv (F.ΞΌ X (π_ C)) β« (π (F.obj X) β inv F.Ξ΅) β« (Ο_ (F.obj X)).hom :=
begin
simp only [lax_monoidal_functor.right_unitality],
slice_rhs 2 3 { rw βid_tensor_comp, simp, },
simp,
end
/-- The tensorator as a natural isomorphism. -/
noncomputable
def ΞΌ_nat_iso (F : monoidal_functor.{vβ vβ} C D) :
(functor.prod F.to_functor F.to_functor) β (tensor D) β
(tensor C) β F.to_functor :=
nat_iso.of_components
(by { intros, apply F.ΞΌ_iso })
(by { intros, apply F.to_lax_monoidal_functor.ΞΌ_natural })
end
section
variables (C : Type uβ) [category.{vβ} C] [monoidal_category.{vβ} C]
/-- The identity monoidal functor. -/
@[simps] def id : monoidal_functor.{vβ vβ} C C :=
{ Ξ΅ := π _,
ΞΌ := Ξ» X Y, π _,
.. π C }
instance : inhabited (monoidal_functor C C) := β¨id Cβ©
end
end monoidal_functor
variables {C : Type uβ} [category.{vβ} C] [monoidal_category.{vβ} C]
variables {D : Type uβ} [category.{vβ} D] [monoidal_category.{vβ} D]
variables {E : Type uβ} [category.{vβ} E] [monoidal_category.{vβ} E]
namespace lax_monoidal_functor
variables (F : lax_monoidal_functor.{vβ vβ} C D) (G : lax_monoidal_functor.{vβ vβ} D E)
-- The proofs here are horrendous; rewrite_search helps a lot.
/-- The composition of two lax monoidal functors is again lax monoidal. -/
@[simps] def comp : lax_monoidal_functor.{vβ vβ} C E :=
{ Ξ΅ := G.Ξ΅ β« (G.map F.Ξ΅),
ΞΌ := Ξ» X Y, G.ΞΌ (F.obj X) (F.obj Y) β« G.map (F.ΞΌ X Y),
ΞΌ_natural' := Ξ» _ _ _ _ f g,
begin
simp only [functor.comp_map, assoc],
rw [βcategory.assoc, lax_monoidal_functor.ΞΌ_natural, category.assoc, βmap_comp, βmap_comp,
βlax_monoidal_functor.ΞΌ_natural]
end,
associativity' := Ξ» X Y Z,
begin
dsimp,
rw id_tensor_comp,
slice_rhs 3 4 { rw [β G.to_functor.map_id, G.ΞΌ_natural], },
slice_rhs 1 3 { rw βG.associativity, },
rw comp_tensor_id,
slice_lhs 2 3 { rw [β G.to_functor.map_id, G.ΞΌ_natural], },
rw [category.assoc, category.assoc, category.assoc, category.assoc, category.assoc,
βG.to_functor.map_comp, βG.to_functor.map_comp, βG.to_functor.map_comp,
βG.to_functor.map_comp, F.associativity],
end,
left_unitality' := Ξ» X,
begin
dsimp,
rw [G.left_unitality, comp_tensor_id, category.assoc, category.assoc],
apply congr_arg,
rw [F.left_unitality, map_comp, βnat_trans.id_app, βcategory.assoc,
βlax_monoidal_functor.ΞΌ_natural, nat_trans.id_app, map_id, βcategory.assoc, map_comp],
end,
right_unitality' := Ξ» X,
begin
dsimp,
rw [G.right_unitality, id_tensor_comp, category.assoc, category.assoc],
apply congr_arg,
rw [F.right_unitality, map_comp, βnat_trans.id_app, βcategory.assoc,
βlax_monoidal_functor.ΞΌ_natural, nat_trans.id_app, map_id, βcategory.assoc, map_comp],
end,
.. (F.to_functor) β (G.to_functor) }.
infixr ` ββ `:80 := comp
end lax_monoidal_functor
namespace monoidal_functor
variables (F : monoidal_functor.{vβ vβ} C D) (G : monoidal_functor.{vβ vβ} D E)
/-- The composition of two monoidal functors is again monoidal. -/
@[simps]
def comp : monoidal_functor.{vβ vβ} C E :=
{ Ξ΅_is_iso := by { dsimp, apply_instance },
ΞΌ_is_iso := by { dsimp, apply_instance },
.. (F.to_lax_monoidal_functor).comp (G.to_lax_monoidal_functor) }.
infixr ` ββ `:80 := comp -- We overload notation; potentially dangerous, but it seems to work.
end monoidal_functor
/--
If we have a right adjoint functor `G` to a monoidal functor `F`, then `G` has a lax monoidal
structure as well.
-/
@[simps]
noncomputable
def monoidal_adjoint (F : monoidal_functor C D) {G : D β₯€ C} (h : F.to_functor β£ G) :
lax_monoidal_functor D C :=
{ to_functor := G,
Ξ΅ := h.hom_equiv _ _ (inv F.Ξ΅),
ΞΌ := Ξ» X Y,
h.hom_equiv _ (X β Y) (inv (F.ΞΌ (G.obj X) (G.obj Y)) β« (h.counit.app X β h.counit.app Y)),
ΞΌ_natural' := Ξ» X Y X' Y' f g,
begin
rw [βh.hom_equiv_naturality_left, βh.hom_equiv_naturality_right, equiv.apply_eq_iff_eq, assoc,
is_iso.eq_inv_comp, βF.to_lax_monoidal_functor.ΞΌ_natural_assoc, is_iso.hom_inv_id_assoc,
βtensor_comp, adjunction.counit_naturality, adjunction.counit_naturality, tensor_comp],
end,
associativity' := Ξ» X Y Z,
begin
rw [βh.hom_equiv_naturality_right, βh.hom_equiv_naturality_left, βh.hom_equiv_naturality_left,
βh.hom_equiv_naturality_left, equiv.apply_eq_iff_eq,
β cancel_epi (F.to_lax_monoidal_functor.ΞΌ (G.obj X β G.obj Y) (G.obj Z)),
β cancel_epi (F.to_lax_monoidal_functor.ΞΌ (G.obj X) (G.obj Y) β π (F.obj (G.obj Z))),
F.to_lax_monoidal_functor.associativity_assoc (G.obj X) (G.obj Y) (G.obj Z),
βF.to_lax_monoidal_functor.ΞΌ_natural_assoc, assoc, is_iso.hom_inv_id_assoc,
βF.to_lax_monoidal_functor.ΞΌ_natural_assoc, is_iso.hom_inv_id_assoc, βtensor_comp,
βtensor_comp, id_comp, functor.map_id, functor.map_id, id_comp, βtensor_comp_assoc,
βtensor_comp_assoc, id_comp, id_comp, h.hom_equiv_unit, h.hom_equiv_unit, functor.map_comp,
assoc, assoc, h.counit_naturality, h.left_triangle_components_assoc, is_iso.hom_inv_id_assoc,
functor.map_comp, assoc, h.counit_naturality, h.left_triangle_components_assoc,
is_iso.hom_inv_id_assoc],
exact associator_naturality (h.counit.app X) (h.counit.app Y) (h.counit.app Z),
end,
left_unitality' := Ξ» X,
begin
rw [βh.hom_equiv_naturality_right, βh.hom_equiv_naturality_left, βequiv.symm_apply_eq,
h.hom_equiv_counit, F.map_left_unitor, h.hom_equiv_unit, assoc, assoc, assoc, F.map_tensor,
assoc, assoc, is_iso.hom_inv_id_assoc, βtensor_comp_assoc, functor.map_id, id_comp,
functor.map_comp, assoc, h.counit_naturality, h.left_triangle_components_assoc,
βleft_unitor_naturality, βtensor_comp_assoc, id_comp, comp_id],
end,
right_unitality' := Ξ» X,
begin
rw [βh.hom_equiv_naturality_right, βh.hom_equiv_naturality_left, βequiv.symm_apply_eq,
h.hom_equiv_counit, F.map_right_unitor, assoc, assoc, βright_unitor_naturality,
βtensor_comp_assoc, comp_id, id_comp, h.hom_equiv_unit, F.map_tensor, assoc, assoc, assoc,
is_iso.hom_inv_id_assoc, functor.map_comp, functor.map_id, βtensor_comp_assoc, assoc,
h.counit_naturality, h.left_triangle_components_assoc, id_comp],
end }.
/-- If a monoidal functor `F` is an equivalence of categories then its inverse is also monoidal. -/
noncomputable
def monoidal_inverse (F : monoidal_functor C D) [is_equivalence F.to_functor] :
monoidal_functor D C :=
{ to_lax_monoidal_functor := monoidal_adjoint F (as_equivalence _).to_adjunction,
Ξ΅_is_iso := by { dsimp [equivalence.to_adjunction], apply_instance },
ΞΌ_is_iso := Ξ» X Y, by { dsimp [equivalence.to_adjunction], apply_instance } }
@[simp]
lemma monoidal_inverse_to_functor (F : monoidal_functor C D) [is_equivalence F.to_functor] :
(monoidal_inverse F).to_functor = F.to_functor.inv := rfl
end category_theory
|
c3e1cfbfbb1b39f28f5fd7808bb21d125d4c8e1f
|
f618aea02cb4104ad34ecf3b9713065cc0d06103
|
/src/field_theory/perfect_closure.lean
|
41dcfb2cd31b60ee262410ca856a5be77ff691bc
|
[
"Apache-2.0"
] |
permissive
|
joehendrix/mathlib
|
84b6603f6be88a7e4d62f5b1b0cbb523bb82b9a5
|
c15eab34ad754f9ecd738525cb8b5a870e834ddc
|
refs/heads/master
| 1,589,606,591,630
| 1,555,946,393,000
| 1,555,946,393,000
| 182,813,854
| 0
| 0
| null | 1,555,946,309,000
| 1,555,946,308,000
| null |
UTF-8
|
Lean
| false
| false
| 17,289
|
lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Kenny Lau
The perfect closure of a field.
-/
import algebra.char_p
local attribute [instance, priority 0] nat.cast_coe
local attribute [instance, priority 0] int.cast_coe
universes u v
/-- A perfect field is a field of characteristic p that has p-th root. -/
class perfect_field (Ξ± : Type u) [field Ξ±] (p : β) [char_p Ξ± p] : Type u :=
(pth_root : Ξ± β Ξ±)
(frobenius_pth_root : β x, frobenius Ξ± p (pth_root x) = x)
theorem frobenius_pth_root (Ξ± : Type u) [field Ξ±] (p : β) [char_p Ξ± p] [perfect_field Ξ± p] (x : Ξ±) :
frobenius Ξ± p (perfect_field.pth_root p x) = x :=
perfect_field.frobenius_pth_root p x
theorem pth_root_frobenius (Ξ± : Type u) [field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] [perfect_field Ξ± p] (x : Ξ±) :
perfect_field.pth_root p (frobenius Ξ± p x) = x :=
frobenius_inj Ξ± p _ _ (by rw frobenius_pth_root)
instance pth_root.is_ring_hom (Ξ± : Type u) [field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] [perfect_field Ξ± p] :
is_ring_hom (@perfect_field.pth_root Ξ± _ p _ _) :=
{ map_one := frobenius_inj Ξ± p _ _ (by rw [frobenius_pth_root, frobenius_one]),
map_mul := Ξ» x y, frobenius_inj Ξ± p _ _ (by simp only [frobenius_pth_root, frobenius_mul]),
map_add := Ξ» x y, frobenius_inj Ξ± p _ _ (by simp only [frobenius_pth_root, frobenius_add]) }
theorem is_ring_hom.pth_root {Ξ± : Type u} [field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] [perfect_field Ξ± p]
{Ξ² : Type v} [field Ξ²] [char_p Ξ² p] [perfect_field Ξ² p] (f : Ξ± β Ξ²) [is_ring_hom f] {x : Ξ±} :
f (perfect_field.pth_root p x) = perfect_field.pth_root p (f x) :=
frobenius_inj Ξ² p _ _ (by rw [β is_monoid_hom.map_frobenius f, frobenius_pth_root, frobenius_pth_root])
inductive perfect_closure.r (Ξ± : Type u) [monoid Ξ±] (p : β) : (β Γ Ξ±) β (β Γ Ξ±) β Prop
| intro : β n x, perfect_closure.r (n, x) (n+1, frobenius Ξ± p x)
run_cmd tactic.mk_iff_of_inductive_prop `perfect_closure.r `perfect_closure.r_iff
/-- The perfect closure is the smallest extension that makes frobenius surjective. -/
def perfect_closure (Ξ± : Type u) [monoid Ξ±] (p : β) : Type u :=
quot (perfect_closure.r Ξ± p)
namespace perfect_closure
variables (Ξ± : Type u)
private lemma mul_aux_left [comm_monoid Ξ±] (p : β) (x1 x2 y : β Γ Ξ±) (H : r Ξ± p x1 x2) :
quot.mk (r Ξ± p) (x1.1 + y.1, ((frobenius Ξ± p)^[y.1] x1.2) * ((frobenius Ξ± p)^[x1.1] y.2)) =
quot.mk (r Ξ± p) (x2.1 + y.1, ((frobenius Ξ± p)^[y.1] x2.2) * ((frobenius Ξ± p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro _ n x := quot.sound $ by rw [β nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', β frobenius_mul, nat.succ_add]; apply r.intro
end
private lemma mul_aux_right [comm_monoid Ξ±] (p : β) (x y1 y2 : β Γ Ξ±) (H : r Ξ± p y1 y2) :
quot.mk (r Ξ± p) (x.1 + y1.1, ((frobenius Ξ± p)^[y1.1] x.2) * ((frobenius Ξ± p)^[x.1] y1.2)) =
quot.mk (r Ξ± p) (x.1 + y2.1, ((frobenius Ξ± p)^[y2.1] x.2) * ((frobenius Ξ± p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro _ n y := quot.sound $ by rw [β nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', β frobenius_mul]; apply r.intro
end
instance [comm_monoid Ξ±] (p : β) : has_mul (perfect_closure Ξ± p) :=
β¨quot.lift (Ξ» x:βΓΞ±, quot.lift (Ξ» y:βΓΞ±, quot.mk (r Ξ± p)
(x.1 + y.1, ((frobenius Ξ± p)^[y.1] x.2) * ((frobenius Ξ± p)^[x.1] y.2))) (mul_aux_right Ξ± p x))
(Ξ» x1 x2 (H : r Ξ± p x1 x2), funext $ Ξ» e, quot.induction_on e $ Ξ» y,
mul_aux_left Ξ± p x1 x2 y H)β©
instance [comm_monoid Ξ±] (p : β) : comm_monoid (perfect_closure Ξ± p) :=
{ mul_assoc := Ξ» e f g, quot.induction_on e $ Ξ» β¨m, xβ©, quot.induction_on f $ Ξ» β¨n, yβ©,
quot.induction_on g $ Ξ» β¨s, zβ©, congr_arg (quot.mk _) $
by simp only [add_assoc, mul_assoc, nat.iterateβ (frobenius_mul _ _),
(nat.iterate_add _ _ _ _).symm, add_comm, add_left_comm],
one := quot.mk _ (0, 1),
one_mul := Ξ» e, quot.induction_on e (Ξ» β¨n, xβ©, congr_arg (quot.mk _) $
by simp only [nat.iterateβ (frobenius_one _ _), nat.iterate_zero, one_mul, zero_add]),
mul_one := Ξ» e, quot.induction_on e (Ξ» β¨n, xβ©, congr_arg (quot.mk _) $
by simp only [nat.iterateβ (frobenius_one _ _), nat.iterate_zero, mul_one, add_zero]),
mul_comm := Ξ» e f, quot.induction_on e (Ξ» β¨m, xβ©, quot.induction_on f (Ξ» β¨n, yβ©,
congr_arg (quot.mk _) $ by simp only [add_comm, mul_comm])),
.. (infer_instance : has_mul (perfect_closure Ξ± p)) }
private lemma add_aux_left [comm_ring Ξ±] (p : β) (hp : nat.prime p) [char_p Ξ± p]
(x1 x2 y : β Γ Ξ±) (H : r Ξ± p x1 x2) :
quot.mk (r Ξ± p) (x1.1 + y.1, ((frobenius Ξ± p)^[y.1] x1.2) + ((frobenius Ξ± p)^[x1.1] y.2)) =
quot.mk (r Ξ± p) (x2.1 + y.1, ((frobenius Ξ± p)^[y.1] x2.2) + ((frobenius Ξ± p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro _ n x := quot.sound $ by rw [β nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', β frobenius_add, nat.succ_add]; apply r.intro
end
private lemma add_aux_right [comm_ring Ξ±] (p : β) (hp : nat.prime p) [char_p Ξ± p]
(x y1 y2 : β Γ Ξ±) (H : r Ξ± p y1 y2) :
quot.mk (r Ξ± p) (x.1 + y1.1, ((frobenius Ξ± p)^[y1.1] x.2) + ((frobenius Ξ± p)^[x.1] y1.2)) =
quot.mk (r Ξ± p) (x.1 + y2.1, ((frobenius Ξ± p)^[y2.1] x.2) + ((frobenius Ξ± p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro _ n y := quot.sound $ by rw [β nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', β frobenius_add]; apply r.intro
end
instance [comm_ring Ξ±] (p : β) [hp : nat.prime p] [char_p Ξ± p] : has_add (perfect_closure Ξ± p) :=
β¨quot.lift (Ξ» x:βΓΞ±, quot.lift (Ξ» y:βΓΞ±, quot.mk (r Ξ± p)
(x.1 + y.1, ((frobenius Ξ± p)^[y.1] x.2) + ((frobenius Ξ± p)^[x.1] y.2))) (add_aux_right Ξ± p hp x))
(Ξ» x1 x2 (H : r Ξ± p x1 x2), funext $ Ξ» e, quot.induction_on e $ Ξ» y,
add_aux_left Ξ± p hp x1 x2 y H)β©
instance [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] : has_neg (perfect_closure Ξ± p) :=
β¨quot.lift (Ξ» x:βΓΞ±, quot.mk (r Ξ± p) (x.1, -x.2)) (Ξ» x y (H : r Ξ± p x y), match x, y, H with
| _, _, r.intro _ n x := quot.sound $ by rw β frobenius_neg; apply r.intro
end)β©
theorem mk_zero [comm_ring Ξ±] (p : β) [nat.prime p] (n : β) : quot.mk (r Ξ± p) (n, 0) = quot.mk (r Ξ± p) (0, 0) :=
by induction n with n ih; [refl, rw β ih]; symmetry; apply quot.sound;
have := r.intro p n (0:Ξ±); rwa [frobenius_zero Ξ± p] at this
theorem r.sound [monoid Ξ±] (p m n : β) (x y : Ξ±) (H : frobenius Ξ± p^[m] x = y) :
quot.mk (r Ξ± p) (n, x) = quot.mk (r Ξ± p) (m + n, y) :=
by subst H; induction m with m ih; [simp only [zero_add, nat.iterate_zero],
rw [ih, nat.succ_add, nat.iterate_succ']]; apply quot.sound; apply r.intro
instance [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] : comm_ring (perfect_closure Ξ± p) :=
{ add_assoc := Ξ» e f g, quot.induction_on e $ Ξ» β¨m, xβ©, quot.induction_on f $ Ξ» β¨n, yβ©,
quot.induction_on g $ Ξ» β¨s, zβ©, congr_arg (quot.mk _) $
by simp only [add_assoc, nat.iterateβ (frobenius_add Ξ± p),
(nat.iterate_add _ _ _ _).symm, add_comm, add_left_comm],
zero := quot.mk _ (0, 0),
zero_add := Ξ» e, quot.induction_on e (Ξ» β¨n, xβ©, congr_arg (quot.mk _) $
by simp only [nat.iterateβ (frobenius_zero Ξ± p), nat.iterate_zero, zero_add]),
add_zero := Ξ» e, quot.induction_on e (Ξ» β¨n, xβ©, congr_arg (quot.mk _) $
by simp only [nat.iterateβ (frobenius_zero Ξ± p), nat.iterate_zero, add_zero]),
add_left_neg := Ξ» e, quot.induction_on e (Ξ» β¨n, xβ©, show quot.mk _ _ = _,
by simp only [nat.iterateβ (frobenius_neg Ξ± p), add_left_neg, mk_zero]; refl),
add_comm := Ξ» e f, quot.induction_on e (Ξ» β¨m, xβ©, quot.induction_on f (Ξ» β¨n, yβ©,
congr_arg (quot.mk _) $ by simp only [add_comm])),
left_distrib := Ξ» e f g, quot.induction_on e $ Ξ» β¨m, xβ©, quot.induction_on f $ Ξ» β¨n, yβ©,
quot.induction_on g $ Ξ» β¨s, zβ©, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm, add_left_comm]; apply r.sound;
simp only [nat.iterateβ (frobenius_mul Ξ± p), nat.iterateβ (frobenius_add Ξ± p),
(nat.iterate_add _ _ _ _).symm, mul_add, add_comm, add_left_comm],
right_distrib := Ξ» e f g, quot.induction_on e $ Ξ» β¨m, xβ©, quot.induction_on f $ Ξ» β¨n, yβ©,
quot.induction_on g $ Ξ» β¨s, zβ©, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm _ s, add_left_comm _ s]; apply r.sound;
simp only [nat.iterateβ (frobenius_mul Ξ± p), nat.iterateβ (frobenius_add Ξ± p),
(nat.iterate_add _ _ _ _).symm, add_mul, add_comm, add_left_comm],
.. (infer_instance : has_add (perfect_closure Ξ± p)),
.. (infer_instance : has_neg (perfect_closure Ξ± p)),
.. (infer_instance : comm_monoid (perfect_closure Ξ± p)) }
instance [discrete_field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] : has_inv (perfect_closure Ξ± p) :=
β¨quot.lift (Ξ» x:βΓΞ±, quot.mk (r Ξ± p) (x.1, x.2β»ΒΉ)) (Ξ» x y (H : r Ξ± p x y), match x, y, H with
| _, _, r.intro _ n x := quot.sound $ by simp only [frobenius]; rw inv_pow'; apply r.intro
end)β©
theorem eq_iff' [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p]
(x y : β Γ Ξ±) : quot.mk (r Ξ± p) x = quot.mk (r Ξ± p) y β
β z, (frobenius Ξ± p^[y.1 + z] x.2) = (frobenius Ξ± p^[x.1 + z] y.2) :=
begin
split,
{ intro H,
replace H := quot.exact _ H,
induction H,
case eqv_gen.rel : x y H
{ cases H with n x, exact β¨0, rflβ© },
case eqv_gen.refl : H
{ exact β¨0, rflβ© },
case eqv_gen.symm : x y H ih
{ cases ih with w ih, exact β¨w, ih.symmβ© },
case eqv_gen.trans : x y z H1 H2 ih1 ih2
{ cases ih1 with z1 ih1,
cases ih2 with z2 ih2,
existsi z2+(y.1+z1),
rw [β add_assoc, nat.iterate_add, ih1],
rw [β nat.iterate_add, add_comm, nat.iterate_add, ih2],
rw [β nat.iterate_add],
simp only [add_comm, add_left_comm] } },
intro H,
cases x with m x,
cases y with n y,
cases H with z H, dsimp only at H,
rw [r.sound Ξ± p (n+z) m x _ rfl, r.sound Ξ± p (m+z) n y _ rfl, H],
rw [add_assoc, add_comm, add_comm z]
end
theorem eq_iff [integral_domain Ξ±] (p : β) [nat.prime p] [char_p Ξ± p]
(x y : β Γ Ξ±) : quot.mk (r Ξ± p) x = quot.mk (r Ξ± p) y β
(frobenius Ξ± p^[y.1] x.2) = (frobenius Ξ± p^[x.1] y.2) :=
(eq_iff' Ξ± p x y).trans β¨Ξ» β¨z, Hβ©, nat.iterate_inj (frobenius_inj Ξ± p) z _ _ $
by simpa only [add_comm, nat.iterate_add] using H,
Ξ» H, β¨0, Hβ©β©
instance [discrete_field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] : discrete_field (perfect_closure Ξ± p) :=
{ zero_ne_one := Ξ» H, zero_ne_one ((eq_iff _ _ _ _).1 H),
mul_inv_cancel := Ξ» e, quot.induction_on e $ Ξ» β¨m, xβ© H,
have _ := mt (eq_iff _ _ _ _).2 H, (eq_iff _ _ _ _).2
(by simp only [nat.iterateβ (frobenius_one _ _), nat.iterateβ (frobenius_zero Ξ± p),
nat.iterate_zero, (nat.iterateβ (frobenius_mul Ξ± p)).symm] at this β’;
rw [mul_inv_cancel this, nat.iterateβ (frobenius_one _ _)]),
inv_mul_cancel := Ξ» e, quot.induction_on e $ Ξ» β¨m, xβ© H,
have _ := mt (eq_iff _ _ _ _).2 H, (eq_iff _ _ _ _).2
(by simp only [nat.iterateβ (frobenius_one _ _), nat.iterateβ (frobenius_zero Ξ± p),
nat.iterate_zero, (nat.iterateβ (frobenius_mul Ξ± p)).symm] at this β’;
rw [inv_mul_cancel this, nat.iterateβ (frobenius_one _ _)]),
has_decidable_eq := Ξ» e f, quot.rec_on_subsingleton e $ Ξ» β¨m, xβ©,
quot.rec_on_subsingleton f $ Ξ» β¨n, yβ©,
decidable_of_iff' _ (eq_iff Ξ± p _ _),
inv_zero := congr_arg (quot.mk (r Ξ± p)) (by rw [inv_zero]),
.. (infer_instance : has_inv (perfect_closure Ξ± p)),
.. (infer_instance : comm_ring (perfect_closure Ξ± p)) }
theorem frobenius_mk [comm_monoid Ξ±] (p : β) (x : β Γ Ξ±) :
frobenius (perfect_closure Ξ± p) p (quot.mk (r Ξ± p) x) = quot.mk _ (x.1, x.2^p) :=
begin
unfold frobenius, cases x with n x, dsimp only,
suffices : β p':β, (quot.mk (r Ξ± p) (n, x) ^ p' : perfect_closure Ξ± p) = quot.mk (r Ξ± p) (n, x ^ p'),
{ apply this },
intro p, induction p with p ih,
case nat.zero { apply r.sound, rw [nat.iterateβ (frobenius_one _ _), pow_zero] },
case nat.succ {
rw [pow_succ, ih],
symmetry,
apply r.sound,
simp only [pow_succ, nat.iterateβ (frobenius_mul _ _)]
}
end
def frobenius_equiv [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] :
perfect_closure Ξ± p β perfect_closure Ξ± p :=
{ to_fun := frobenius (perfect_closure Ξ± p) p,
inv_fun := Ξ» e, quot.lift_on e (Ξ» x, quot.mk (r Ξ± p) (x.1 + 1, x.2)) (Ξ» x y H,
match x, y, H with
| _, _, r.intro _ n x := quot.sound (r.intro _ _ _)
end),
left_inv := Ξ» e, quot.induction_on e (Ξ» β¨m, xβ©, by rw frobenius_mk;
symmetry; apply quot.sound; apply r.intro),
right_inv := Ξ» e, quot.induction_on e (Ξ» β¨m, xβ©, by rw frobenius_mk;
symmetry; apply quot.sound; apply r.intro) }
theorem frobenius_equiv_apply [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] {x : perfect_closure Ξ± p} :
frobenius_equiv Ξ± p x = frobenius _ p x :=
rfl
theorem nat_cast [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] (n x : β) :
(x : perfect_closure Ξ± p) = quot.mk (r Ξ± p) (n, x) :=
begin
induction n with n ih,
{ induction x with x ih, {refl},
rw [nat.cast_succ, nat.cast_succ, ih], refl },
rw ih, apply quot.sound,
conv {congr, skip, skip, rw β frobenius_nat_cast Ξ± p x},
apply r.intro
end
theorem int_cast [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] (x : β€) :
(x : perfect_closure Ξ± p) = quot.mk (r Ξ± p) (0, x) :=
by induction x; simp only [int.cast_of_nat, int.cast_neg_succ_of_nat, nat_cast Ξ± p 0]; refl
theorem nat_cast_eq_iff [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] (x y : β) :
(x : perfect_closure Ξ± p) = y β (x : Ξ±) = y :=
begin
split; intro H,
{ rw [nat_cast Ξ± p 0, nat_cast Ξ± p 0, eq_iff'] at H,
cases H with z H,
simpa only [zero_add, nat.iterateβ (frobenius_nat_cast Ξ± p _)] using H },
rw [nat_cast Ξ± p 0, nat_cast Ξ± p 0, H]
end
instance [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] : char_p (perfect_closure Ξ± p) p :=
begin
constructor, intro x, rw β char_p.cast_eq_zero_iff Ξ±,
rw [β nat.cast_zero, nat_cast_eq_iff, nat.cast_zero]
end
instance [discrete_field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] : perfect_field (perfect_closure Ξ± p) p :=
{ pth_root := (frobenius_equiv Ξ± p).symm,
frobenius_pth_root := (frobenius_equiv Ξ± p).apply_symm_apply }
def of [monoid Ξ±] (p : β) (x : Ξ±) : perfect_closure Ξ± p :=
quot.mk _ (0, x)
instance [comm_ring Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] : is_ring_hom (of Ξ± p) :=
{ map_one := rfl,
map_mul := Ξ» x y, rfl,
map_add := Ξ» x y, rfl }
theorem eq_pth_root [discrete_field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p] (m : β) (x : Ξ±) :
quot.mk (r Ξ± p) (m, x) = (perfect_field.pth_root p^[m] (of Ξ± p x) : perfect_closure Ξ± p) :=
begin
unfold of,
induction m with m ih, {refl},
rw [nat.iterate_succ', β ih]; refl
end
def UMP [discrete_field Ξ±] (p : β) [nat.prime p] [char_p Ξ± p]
(Ξ² : Type v) [discrete_field Ξ²] [char_p Ξ² p] [perfect_field Ξ² p] :
{ f : Ξ± β Ξ² // is_ring_hom f } β { f : perfect_closure Ξ± p β Ξ² // is_ring_hom f } :=
{ to_fun := Ξ» f, β¨Ξ» e, quot.lift_on e (Ξ» x, perfect_field.pth_root p^[x.1] (f.1 x.2))
(Ξ» x y H, match x, y, H with | _, _, r.intro _ n x := by letI := f.2;
simp only [is_monoid_hom.map_frobenius f.1, nat.iterate_succ, pth_root_frobenius]
end),
show f.1 1 = 1, from f.2.1,
Ξ» j k, quot.induction_on j $ Ξ» β¨m, xβ©, quot.induction_on k $ Ξ» β¨n, yβ©,
show (perfect_field.pth_root p^[_] _) = (perfect_field.pth_root p^[_] _) * (perfect_field.pth_root p^[_] _),
by letI := f.2; simp only [is_ring_hom.map_mul f.1, (nat.iterateβ (Ξ» x, (is_monoid_hom.map_frobenius f.1 p x).symm)).symm,
@nat.iterateβ Ξ² _ (*) (Ξ» x y, is_ring_hom.map_mul (perfect_field.pth_root p))];
rw [nat.iterate_add, nat.iterate_cancel (pth_root_frobenius Ξ² p),
add_comm, nat.iterate_add, nat.iterate_cancel (pth_root_frobenius Ξ² p)],
Ξ» j k, quot.induction_on j $ Ξ» β¨m, xβ©, quot.induction_on k $ Ξ» β¨n, yβ©,
show (perfect_field.pth_root p^[_] _) = (perfect_field.pth_root p^[_] _) + (perfect_field.pth_root p^[_] _),
by letI := f.2; simp only [is_ring_hom.map_add f.1, (nat.iterateβ (Ξ» x, (is_monoid_hom.map_frobenius f.1 p x).symm)).symm,
@nat.iterateβ Ξ² _ (+) (Ξ» x y, is_ring_hom.map_add (perfect_field.pth_root p))];
rw [nat.iterate_add, nat.iterate_cancel (pth_root_frobenius Ξ² p),
add_comm m, nat.iterate_add, nat.iterate_cancel (pth_root_frobenius Ξ² p)]β©,
inv_fun := Ξ» f, β¨f.1 β of Ξ± p, @@is_ring_hom.comp _ _ _ _ _ _ f.2β©,
left_inv := Ξ» β¨f, hfβ©, subtype.eq rfl,
right_inv := Ξ» β¨f, hfβ©, subtype.eq $ funext $ Ξ» i, quot.induction_on i $ Ξ» β¨m, xβ©,
show perfect_field.pth_root p^[m] (f _) = f _,
by resetI; rw [eq_pth_root, @nat.iterateβ _ _ _ _ f (Ξ» x:perfect_closure Ξ± p, (is_ring_hom.pth_root p f).symm)] }
end perfect_closure
|
7b569996cf1295d315994f0aa27dcb279ee7fba1
|
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
|
/library/init/function.lean
|
1110039d03b497dfe5531af75c00c5f615f03d6f
|
[
"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
| 5,635
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura, Jeremy Avigad, Haitao Zhang
General operations on functions.
-/
prelude
import init.prod init.funext init.logic
namespace function
variables {A : Type} {B : Type} {C : Type} {D : Type} {E : Type}
definition compose [reducible] [unfold_full] (f : B β C) (g : A β B) : A β C :=
Ξ»x, f (g x)
definition compose_right [reducible] [unfold_full] (f : B β B β B) (g : A β B) : B β A β B :=
Ξ» b a, f b (g a)
definition compose_left [reducible] [unfold_full] (f : B β B β B) (g : A β B) : A β B β B :=
Ξ» a b, f (g a) b
definition on_fun [reducible] [unfold_full] (f : B β B β C) (g : A β B) : A β A β C :=
Ξ»x y, f (g x) (g y)
definition combine [reducible] [unfold_full] (f : A β B β C) (op : C β D β E) (g : A β B β D)
: A β B β E :=
Ξ»x y, op (f x y) (g x y)
definition const [reducible] [unfold_full] (B : Type) (a : A) : B β A :=
Ξ»x, a
definition dcompose [reducible] [unfold_full] {B : A β Type} {C : Ξ {x : A}, B x β Type}
(f : Ξ {x : A} (y : B x), C y) (g : Ξ x, B x) : Ξ x, C (g x) :=
Ξ»x, f (g x)
definition swap [reducible] [unfold_full] {C : A β B β Type} (f : Ξ x y, C x y) : Ξ y x, C x y :=
Ξ»y x, f x y
definition app [reducible] {B : A β Type} (f : Ξ x, B x) (x : A) : B x :=
f x
definition curry [reducible] [unfold_full] : (A Γ B β C) β A β B β C :=
Ξ» f a b, f (a, b)
definition uncurry [reducible] [unfold 5] : (A β B β C) β (A Γ B β C) :=
Ξ» f p, match p with (a, b) := f a b end
theorem curry_uncurry (f : A β B β C) : curry (uncurry f) = f :=
rfl
theorem uncurry_curry (f : A Γ B β C) : uncurry (curry f) = f :=
funext (Ξ» p, match p with (a, b) := rfl end)
infixr ` β ` := compose
infixr ` β' `:60 := dcompose
infixl ` on `:1 := on_fun
infixr ` $ `:1 := app
notation f ` -[` op `]- ` g := combine f op g
lemma left_id (f : A β B) : id β f = f := rfl
lemma right_id (f : A β B) : f β id = f := rfl
theorem compose.assoc (f : C β D) (g : B β C) (h : A β B) : (f β g) β h = f β (g β h) := rfl
theorem compose.left_id (f : A β B) : id β f = f := rfl
theorem compose.right_id (f : A β B) : f β id = f := rfl
theorem compose_const_right (f : B β C) (b : B) : f β (const A b) = const A (f b) := rfl
definition injective [reducible] (f : A β B) : Prop := β β¦aβ aββ¦, f aβ = f aβ β aβ = aβ
theorem injective_compose {g : B β C} {f : A β B} (Hg : injective g) (Hf : injective f) :
injective (g β f) :=
take aβ aβ, assume Heq, Hf (Hg Heq)
definition surjective [reducible] (f : A β B) : Prop := β b, β a, f a = b
theorem surjective_compose {g : B β C} {f : A β B} (Hg : surjective g) (Hf : surjective f) :
surjective (g β f) :=
take c,
obtain b (Hb : g b = c), from Hg c,
obtain a (Ha : f a = b), from Hf b,
exists.intro a (eq.trans (congr_arg g Ha) Hb)
definition bijective (f : A β B) := injective f β§ surjective f
theorem bijective_compose {g : B β C} {f : A β B} (Hg : bijective g) (Hf : bijective f) :
bijective (g β f) :=
obtain Hginj Hgsurj, from Hg,
obtain Hfinj Hfsurj, from Hf,
and.intro (injective_compose Hginj Hfinj) (surjective_compose Hgsurj Hfsurj)
-- g is a left inverse to f
definition left_inverse (g : B β A) (f : A β B) : Prop := βx, g (f x) = x
definition id_of_left_inverse {g : B β A} {f : A β B} : left_inverse g f β g β f = id :=
assume h, funext h
definition has_left_inverse (f : A β B) : Prop := β finv : B β A, left_inverse finv f
-- g is a right inverse to f
definition right_inverse (g : B β A) (f : A β B) : Prop := left_inverse f g
definition id_of_right_inverse {g : B β A} {f : A β B} : right_inverse g f β f β g = id :=
assume h, funext h
definition has_right_inverse (f : A β B) : Prop := β finv : B β A, right_inverse finv f
theorem injective_of_left_inverse {g : B β A} {f : A β B} : left_inverse g f β injective f :=
assume h, take a b, assume faeqfb,
calc a = g (f a) : by rewrite h
... = g (f b) : faeqfb
... = b : by rewrite h
theorem injective_of_has_left_inverse {f : A β B} : has_left_inverse f β injective f :=
assume h, obtain (finv : B β A) (inv : left_inverse finv f), from h,
injective_of_left_inverse inv
theorem right_inverse_of_injective_of_left_inverse {f : A β B} {g : B β A}
(injf : injective f) (lfg : left_inverse f g) :
right_inverse f g :=
take x,
have H : f (g (f x)) = f x, from lfg (f x),
injf H
theorem surjective_of_has_right_inverse {f : A β B} : has_right_inverse f β surjective f :=
assume h, take b,
obtain (finv : B β A) (inv : right_inverse finv f), from h,
let a : A := finv b in
have h : f a = b, from calc
f a = (f β finv) b : rfl
... = id b : by rewrite inv
... = b : rfl,
exists.intro a h
theorem left_inverse_of_surjective_of_right_inverse {f : A β B} {g : B β A}
(surjf : surjective f) (rfg : right_inverse f g) :
left_inverse f g :=
take y,
obtain x (Hx : f x = y), from surjf y,
calc
f (g y) = f (g (f x)) : Hx
... = f x : rfg
... = y : Hx
theorem injective_id : injective (@id A) := take aβ aβ H, H
theorem surjective_id : surjective (@id A) := take a, exists.intro a rfl
theorem bijective_id : bijective (@id A) := and.intro injective_id surjective_id
end function
-- copy reducible annotations to top-level
export [reducible] [unfold] function
|
b989b0d663df1b806cf3340e73299a1907223c7a
|
19cc34575500ee2e3d4586c15544632aa07a8e66
|
/src/data/sum.lean
|
3a4647bd42eb10df5dd3cb25f0d10d090eca805f
|
[
"Apache-2.0"
] |
permissive
|
LibertasSpZ/mathlib
|
b9fcd46625eb940611adb5e719a4b554138dade6
|
33f7870a49d7cc06d2f3036e22543e6ec5046e68
|
refs/heads/master
| 1,672,066,539,347
| 1,602,429,158,000
| 1,602,429,158,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,155
|
lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury G. Kudryashov
-/
/-!
# More theorems about the sum type
-/
universes u v w x
variables {Ξ± : Type u} {Ξ±' : Type w} {Ξ² : Type v} {Ξ²' : Type x}
open sum
/-- Check if a sum is `inl` and if so, retrieve its contents. -/
@[simp] def sum.get_left {Ξ± Ξ²} : Ξ± β Ξ² β option Ξ±
| (inl a) := some a
| (inr _) := none
/-- Check if a sum is `inr` and if so, retrieve its contents. -/
@[simp] def sum.get_right {Ξ± Ξ²} : Ξ± β Ξ² β option Ξ²
| (inr b) := some b
| (inl _) := none
/-- Check if a sum is `inl`. -/
@[simp] def sum.is_left {Ξ± Ξ²} : Ξ± β Ξ² β bool
| (inl _) := tt
| (inr _) := ff
/-- Check if a sum is `inr`. -/
@[simp] def sum.is_right {Ξ± Ξ²} : Ξ± β Ξ² β bool
| (inl _) := ff
| (inr _) := tt
attribute [derive decidable_eq] sum
@[simp] theorem sum.forall {p : Ξ± β Ξ² β Prop} : (β x, p x) β (β a, p (inl a)) β§ (β b, p (inr b)) :=
β¨Ξ» h, β¨Ξ» a, h _, Ξ» b, h _β©, Ξ» β¨hβ, hββ©, sum.rec hβ hββ©
@[simp] theorem sum.exists {p : Ξ± β Ξ² β Prop} : (β x, p x) β (β a, p (inl a)) β¨ β b, p (inr b) :=
β¨Ξ» h, match h with
| β¨inl a, hβ© := or.inl β¨a, hβ©
| β¨inr b, hβ© := or.inr β¨b, hβ©
end, Ξ» h, match h with
| or.inl β¨a, hβ© := β¨inl a, hβ©
| or.inr β¨b, hβ© := β¨inr b, hβ©
endβ©
namespace sum
/-- Map `Ξ± β Ξ²` to `Ξ±' β Ξ²'` sending `Ξ±` to `Ξ±'` and `Ξ²` to `Ξ²'`. -/
protected def map (f : Ξ± β Ξ±') (g : Ξ² β Ξ²') : Ξ± β Ξ² β Ξ±' β Ξ²'
| (sum.inl x) := sum.inl (f x)
| (sum.inr x) := sum.inr (g x)
@[simp] lemma map_inl (f : Ξ± β Ξ±') (g : Ξ² β Ξ²') (x : Ξ±) : (inl x).map f g = inl (f x) := rfl
@[simp] lemma map_inr (f : Ξ± β Ξ±') (g : Ξ² β Ξ²') (x : Ξ²) : (inr x).map f g = inr (g x) := rfl
@[simp] lemma map_map {Ξ±'' Ξ²''} (f' : Ξ±' β Ξ±'') (g' : Ξ²' β Ξ²'') (f : Ξ± β Ξ±') (g : Ξ² β Ξ²') :
β x : Ξ± β Ξ², (x.map f g).map f' g' = x.map (f' β f) (g' β g)
| (inl a) := rfl
| (inr b) := rfl
@[simp] lemma map_comp_map {Ξ±'' Ξ²''} (f' : Ξ±' β Ξ±'') (g' : Ξ²' β Ξ²'') (f : Ξ± β Ξ±') (g : Ξ² β Ξ²') :
(sum.map f' g') β (sum.map f g) = sum.map (f' β f) (g' β g) :=
funext $ map_map f' g' f g
@[simp] lemma map_id_id (Ξ± Ξ²) : sum.map (@id Ξ±) (@id Ξ²) = id :=
funext $ Ξ» x, sum.rec_on x (Ξ» _, rfl) (Ξ» _, rfl)
theorem inl.inj_iff {a b} : (inl a : Ξ± β Ξ²) = inl b β a = b :=
β¨inl.inj, congr_arg _β©
theorem inr.inj_iff {a b} : (inr a : Ξ± β Ξ²) = inr b β a = b :=
β¨inr.inj, congr_arg _β©
theorem inl_ne_inr {a : Ξ±} {b : Ξ²} : inl a β inr b.
theorem inr_ne_inl {a : Ξ±} {b : Ξ²} : inr b β inl a.
/-- Define a function on `Ξ± β Ξ²` by giving separate definitions on `Ξ±` and `Ξ²`. -/
protected def elim {Ξ± Ξ² Ξ³ : Sort*} (f : Ξ± β Ξ³) (g : Ξ² β Ξ³) : Ξ± β Ξ² β Ξ³ := Ξ» x, sum.rec_on x f g
@[simp] lemma elim_inl {Ξ± Ξ² Ξ³ : Sort*} (f : Ξ± β Ξ³) (g : Ξ² β Ξ³) (x : Ξ±) :
sum.elim f g (inl x) = f x := rfl
@[simp] lemma elim_inr {Ξ± Ξ² Ξ³ : Sort*} (f : Ξ± β Ξ³) (g : Ξ² β Ξ³) (x : Ξ²) :
sum.elim f g (inr x) = g x := rfl
lemma elim_injective {Ξ± Ξ² Ξ³ : Sort*} {f : Ξ± β Ξ³} {g : Ξ² β Ξ³}
(hf : function.injective f) (hg : function.injective g)
(hfg : β a b, f a β g b) : function.injective (sum.elim f g) :=
Ξ» x y, sum.rec_on x
(sum.rec_on y (Ξ» x y hxy, by rw hf hxy) (Ξ» x y hxy, false.elim $ hfg _ _ hxy))
(sum.rec_on y (Ξ» x y hxy, false.elim $ hfg x y hxy.symm) (Ξ» x y hxy, by rw hg hxy))
section
variables (ra : Ξ± β Ξ± β Prop) (rb : Ξ² β Ξ² β Prop)
/-- Lexicographic order for sum. Sort all the `inl a` before the `inr b`,
otherwise use the respective order on `Ξ±` or `Ξ²`. -/
inductive lex : Ξ± β Ξ² β Ξ± β Ξ² β Prop
| inl {aβ aβ} (h : ra aβ aβ) : lex (inl aβ) (inl aβ)
| inr {bβ bβ} (h : rb bβ bβ) : lex (inr bβ) (inr bβ)
| sep (a b) : lex (inl a) (inr b)
variables {ra rb}
@[simp] theorem lex_inl_inl {aβ aβ} : lex ra rb (inl aβ) (inl aβ) β ra aβ aβ :=
β¨Ξ» h, by cases h; assumption, lex.inlβ©
@[simp] theorem lex_inr_inr {bβ bβ} : lex ra rb (inr bβ) (inr bβ) β rb bβ bβ :=
β¨Ξ» h, by cases h; assumption, lex.inrβ©
@[simp] theorem lex_inr_inl {b a} : Β¬ lex ra rb (inr b) (inl a) :=
Ξ» h, by cases h
attribute [simp] lex.sep
theorem lex_acc_inl {a} (aca : acc ra a) : acc (lex ra rb) (inl a) :=
begin
induction aca with a H IH,
constructor, intros y h,
cases h with a' _ h',
exact IH _ h'
end
theorem lex_acc_inr (aca : β a, acc (lex ra rb) (inl a)) {b} (acb : acc rb b) : acc (lex ra rb) (inr b) :=
begin
induction acb with b H IH,
constructor, intros y h,
cases h with _ _ _ b' _ h' a,
{ exact IH _ h' },
{ exact aca _ }
end
theorem lex_wf (ha : well_founded ra) (hb : well_founded rb) : well_founded (lex ra rb) :=
have aca : β a, acc (lex ra rb) (inl a), from Ξ» a, lex_acc_inl (ha.apply a),
β¨Ξ» x, sum.rec_on x aca (Ξ» b, lex_acc_inr aca (hb.apply b))β©
end
/-- Swap the factors of a sum type -/
@[simp] def swap : Ξ± β Ξ² β Ξ² β Ξ±
| (inl a) := inr a
| (inr b) := inl b
@[simp] lemma swap_swap (x : Ξ± β Ξ²) : swap (swap x) = x :=
by cases x; refl
@[simp] lemma swap_swap_eq : swap β swap = @id (Ξ± β Ξ²) :=
funext $ swap_swap
@[simp] lemma swap_left_inverse : function.left_inverse (@swap Ξ± Ξ²) swap :=
swap_swap
@[simp] lemma swap_right_inverse : function.right_inverse (@swap Ξ± Ξ²) swap :=
swap_swap
end sum
namespace function
open sum
lemma injective.sum_map {f : Ξ± β Ξ²} {g : Ξ±' β Ξ²'} (hf : injective f) (hg : injective g) :
injective (sum.map f g)
| (inl x) (inl y) h := congr_arg inl $ hf $ inl.inj h
| (inr x) (inr y) h := congr_arg inr $ hg $ inr.inj h
lemma surjective.sum_map {f : Ξ± β Ξ²} {g : Ξ±' β Ξ²'} (hf : surjective f) (hg : surjective g) :
surjective (sum.map f g)
| (inl y) := let β¨x, hxβ© := hf y in β¨inl x, congr_arg inl hxβ©
| (inr y) := let β¨x, hxβ© := hg y in β¨inr x, congr_arg inr hxβ©
end function
|
f55deb223e30288db8b19a6342e85a3ee05ad8dc
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/1021.lean
|
055522620b089ce3bfb9c0382470105bb95c1a1e
|
[
"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
| 108
|
lean
|
import Lean
open Lean Meta
#eval show MetaM _ from do
findDeclarationRanges? `Lean.Elab.Term.expandAssert
|
be00e6df180d440032b06b265edd3bb461ee30bc
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/wlog_auto.lean
|
407cd736987b1b122cfeb085135d29d2f1b1a119
|
[] |
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
| 2,471
|
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
Without loss of generality tactic.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.list.perm
import Mathlib.PostPort
namespace Mathlib
namespace tactic
namespace interactive
/-- Without loss of generality: reduces to one goal under variables permutations.
Given a goal of the form `g xs`, a predicate `p` over a set of variables, as well as variable
permutations `xs_i`. Then `wlog` produces goals of the form
The case goal, i.e. the permutation `xs_i` covers all possible cases:
`β’ p xs_0 β¨ β― β¨ p xs_n`
The main goal, i.e. the goal reduced to `xs_0`:
`(h : p xs_0) β’ g xs_0`
The invariant goals, i.e. `g` is invariant under `xs_i`:
`(h : p xs_i) (this : g xs_0) β’ gs xs_i`
Either the permutation is provided, or a proof of the disjunction is provided to compute the
permutation. The disjunction need to be in assoc normal form, e.g. `pβ β¨ (pβ β¨ pβ)`. In many cases
the invariant goals can be solved by AC rewriting using `cc` etc.
Example:
On a state `(n m : β) β’ p n m` the tactic `wlog h : n β€ m using [n m, m n]` produces the following
states:
`(n m : β) β’ n β€ m β¨ m β€ n`
`(n m : β) (h : n β€ m) β’ p n m`
`(n m : β) (h : m β€ n) (this : p n m) β’ p m n`
`wlog` supports different calling conventions. The name `h` is used to give a name to the introduced
case hypothesis. If the name is avoided, the default will be `case`.
(1) `wlog : p xs0 using [xs0, β¦, xsn]`
Results in the case goal `p xs0 β¨ β― β¨ ps xsn`, the main goal `(case : p xs0) β’ g xs0` and the
invariance goals `(case : p xsi) (this : g xs0) β’ g xsi`.
(2) `wlog : p xs0 := r using xs0`
The expression `r` is a proof of the shape `p xs0 β¨ β― β¨ p xsi`, it is also used to compute the
variable permutations.
(3) `wlog := r using xs0`
The expression `r` is a proof of the shape `p xs0 β¨ β― β¨ p xsi`, it is also used to compute the
variable permutations. This is not as stable as (2), for example `p` cannot be a disjunction.
(4) `wlog : R x y using x y` and `wlog : R x y`
Produces the case `R x y β¨ R y x`. If `R` is β€, then the disjunction discharged using linearity.
If `using x y` is avoided then `x` and `y` are the last two variables appearing in the
expression `R x y`. -/
end Mathlib
|
a92853e2bf9cccd52607ab7c832c66ee66a08953
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/field_theory/separable.lean
|
4a09fb62f4fac72dc65244afc27d3eb7dc3a1941
|
[
"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
| 21,044
|
lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.squarefree
import data.polynomial.expand
import data.polynomial.splits
import field_theory.minpoly
import ring_theory.power_basis
/-!
# Separable polynomials
We define a polynomial to be separable if it is coprime with its derivative. We prove basic
properties about separable polynomials here.
## Main definitions
* `polynomial.separable f`: a polynomial `f` is separable iff it is coprime with its derivative.
-/
universes u v w
open_locale classical big_operators polynomial
open finset
namespace polynomial
section comm_semiring
variables {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S]
/-- A polynomial is separable iff it is coprime with its derivative. -/
def separable (f : R[X]) : Prop :=
is_coprime f f.derivative
lemma separable_def (f : R[X]) :
f.separable β is_coprime f f.derivative :=
iff.rfl
lemma separable_def' (f : R[X]) :
f.separable β β a b : R[X], a * f + b * f.derivative = 1 :=
iff.rfl
lemma not_separable_zero [nontrivial R] : Β¬ separable (0 : R[X]) :=
begin
rintro β¨x, y, hβ©,
simpa only [derivative_zero, mul_zero, add_zero, zero_ne_one] using h,
end
lemma separable_one : (1 : R[X]).separable :=
is_coprime_one_left
@[nontriviality] lemma separable_of_subsingleton [subsingleton R] (f : R[X]) :
f.separable := by simp [separable]
lemma separable_X_add_C (a : R) : (X + C a).separable :=
by { rw [separable_def, derivative_add, derivative_X, derivative_C, add_zero],
exact is_coprime_one_right }
lemma separable_X : (X : R[X]).separable :=
by { rw [separable_def, derivative_X], exact is_coprime_one_right }
lemma separable_C (r : R) : (C r).separable β is_unit r :=
by rw [separable_def, derivative_C, is_coprime_zero_right, is_unit_C]
lemma separable.of_mul_left {f g : R[X]} (h : (f * g).separable) : f.separable :=
begin
have := h.of_mul_left_left, rw derivative_mul at this,
exact is_coprime.of_mul_right_left (is_coprime.of_add_mul_left_right this)
end
lemma separable.of_mul_right {f g : R[X]} (h : (f * g).separable) : g.separable :=
by { rw mul_comm at h, exact h.of_mul_left }
lemma separable.of_dvd {f g : R[X]} (hf : f.separable) (hfg : g β£ f) : g.separable :=
by { rcases hfg with β¨f', rflβ©, exact separable.of_mul_left hf }
lemma separable_gcd_left {F : Type*} [field F] {f : F[X]}
(hf : f.separable) (g : F[X]) : (euclidean_domain.gcd f g).separable :=
separable.of_dvd hf (euclidean_domain.gcd_dvd_left f g)
lemma separable_gcd_right {F : Type*} [field F] {g : F[X]}
(f : F[X]) (hg : g.separable) : (euclidean_domain.gcd f g).separable :=
separable.of_dvd hg (euclidean_domain.gcd_dvd_right f g)
lemma separable.is_coprime {f g : R[X]} (h : (f * g).separable) : is_coprime f g :=
begin
have := h.of_mul_left_left, rw derivative_mul at this,
exact is_coprime.of_mul_right_right (is_coprime.of_add_mul_left_right this)
end
theorem separable.of_pow' {f : R[X]} :
β {n : β} (h : (f ^ n).separable), is_unit f β¨ (f.separable β§ n = 1) β¨ n = 0
| 0 := Ξ» h, or.inr $ or.inr rfl
| 1 := Ξ» h, or.inr $ or.inl β¨pow_one f βΈ h, rflβ©
| (n+2) := Ξ» h, by { rw [pow_succ, pow_succ] at h,
exact or.inl (is_coprime_self.1 h.is_coprime.of_mul_right_left) }
theorem separable.of_pow {f : R[X]} (hf : Β¬is_unit f) {n : β} (hn : n β 0)
(hfs : (f ^ n).separable) : f.separable β§ n = 1 :=
(hfs.of_pow'.resolve_left hf).resolve_right hn
theorem separable.map {p : R[X]} (h : p.separable) {f : R β+* S} : (p.map f).separable :=
let β¨a, b, Hβ© := h in β¨a.map f, b.map f,
by rw [derivative_map, β polynomial.map_mul, β polynomial.map_mul, β polynomial.map_add, H,
polynomial.map_one]β©
variables (p q : β)
lemma is_unit_of_self_mul_dvd_separable {p q : R[X]}
(hp : p.separable) (hq : q * q β£ p) : is_unit q :=
begin
obtain β¨p, rflβ© := hq,
apply is_coprime_self.mp,
have : is_coprime (q * (q * p)) (q * (q.derivative * p + q.derivative * p + q * p.derivative)),
{ simp only [β mul_assoc, mul_add],
convert hp,
rw [derivative_mul, derivative_mul],
ring },
exact is_coprime.of_mul_right_left (is_coprime.of_mul_left_left this)
end
lemma multiplicity_le_one_of_separable {p q : R[X]} (hq : Β¬ is_unit q)
(hsep : separable p) : multiplicity q p β€ 1 :=
begin
contrapose! hq,
apply is_unit_of_self_mul_dvd_separable hsep,
rw β sq,
apply multiplicity.pow_dvd_of_le_multiplicity,
simpa only [nat.cast_one, nat.cast_bit0] using part_enat.add_one_le_of_lt hq
end
lemma separable.squarefree {p : R[X]} (hsep : separable p) : squarefree p :=
begin
rw multiplicity.squarefree_iff_multiplicity_le_one p,
intro f,
by_cases hunit : is_unit f,
{ exact or.inr hunit },
exact or.inl (multiplicity_le_one_of_separable hunit hsep)
end
end comm_semiring
section comm_ring
variables {R : Type u} [comm_ring R]
lemma separable_X_sub_C {x : R} : separable (X - C x) :=
by simpa only [sub_eq_add_neg, C_neg] using separable_X_add_C (-x)
lemma separable.mul {f g : R[X]} (hf : f.separable) (hg : g.separable)
(h : is_coprime f g) : (f * g).separable :=
by { rw [separable_def, derivative_mul], exact ((hf.mul_right h).add_mul_left_right _).mul_left
((h.symm.mul_right hg).mul_add_right_right _) }
lemma separable_prod' {ΞΉ : Sort*} {f : ΞΉ β R[X]} {s : finset ΞΉ} :
(βxβs, βyβs, x β y β is_coprime (f x) (f y)) β (βxβs, (f x).separable) β
(β x in s, f x).separable :=
finset.induction_on s (Ξ» _ _, separable_one) $ Ξ» a s has ih h1 h2, begin
simp_rw [finset.forall_mem_insert, forall_and_distrib] at h1 h2, rw prod_insert has,
exact h2.1.mul (ih h1.2.2 h2.2) (is_coprime.prod_right $ Ξ» i his, h1.1.2 i his $
ne.symm $ ne_of_mem_of_not_mem his has)
end
lemma separable_prod {ΞΉ : Sort*} [fintype ΞΉ] {f : ΞΉ β R[X]}
(h1 : pairwise (is_coprime on f)) (h2 : β x, (f x).separable) : (β x, f x).separable :=
separable_prod' (Ξ» x hx y hy hxy, h1 hxy) (Ξ» x hx, h2 x)
lemma separable.inj_of_prod_X_sub_C [nontrivial R] {ΞΉ : Sort*} {f : ΞΉ β R} {s : finset ΞΉ}
(hfs : (β i in s, (X - C (f i))).separable)
{x y : ΞΉ} (hx : x β s) (hy : y β s) (hfxy : f x = f y) : x = y :=
begin
by_contra hxy,
rw [β insert_erase hx, prod_insert (not_mem_erase _ _),
β insert_erase (mem_erase_of_ne_of_mem (ne.symm hxy) hy),
prod_insert (not_mem_erase _ _), β mul_assoc, hfxy, β sq] at hfs,
cases (hfs.of_mul_left.of_pow (by exact not_is_unit_X_sub_C _) two_ne_zero).2
end
lemma separable.injective_of_prod_X_sub_C [nontrivial R] {ΞΉ : Sort*} [fintype ΞΉ] {f : ΞΉ β R}
(hfs : (β i, (X - C (f i))).separable) : function.injective f :=
Ξ» x y hfxy, hfs.inj_of_prod_X_sub_C (mem_univ _) (mem_univ _) hfxy
lemma nodup_of_separable_prod [nontrivial R] {s : multiset R}
(hs : separable (multiset.map (Ξ» a, X - C a) s).prod) : s.nodup :=
begin
rw multiset.nodup_iff_ne_cons_cons,
rintros a t rfl,
refine not_is_unit_X_sub_C a (is_unit_of_self_mul_dvd_separable hs _),
simpa only [multiset.map_cons, multiset.prod_cons] using mul_dvd_mul_left _ (dvd_mul_right _ _)
end
/--If `is_unit n` in a `comm_ring R`, then `X ^ n - u` is separable for any unit `u`. -/
lemma separable_X_pow_sub_C_unit {n : β} (u : RΛ£) (hn : is_unit (n : R)) :
separable (X ^ n - C (u : R)) :=
begin
nontriviality R,
rcases n.eq_zero_or_pos with rfl | hpos,
{ simpa using hn },
apply (separable_def' (X ^ n - C (u : R))).2,
obtain β¨n', hn'β© := hn.exists_left_inv,
refine β¨-C βuβ»ΒΉ, C βuβ»ΒΉ * C n' * X, _β©,
rw [derivative_sub, derivative_C, sub_zero, derivative_pow X n, derivative_X, mul_one],
calc - C βuβ»ΒΉ * (X ^ n - C βu) + C βuβ»ΒΉ * C n' * X * (βn * X ^ (n - 1))
= C (βuβ»ΒΉ * β u) - C βuβ»ΒΉ * X^n + C β u β»ΒΉ * C (n' * βn) * (X * X ^ (n - 1)) :
by { simp only [C.map_mul, C_eq_nat_cast], ring }
... = 1 : by simp only [units.inv_mul, hn', C.map_one, mul_one, β pow_succ,
nat.sub_add_cancel (show 1 β€ n, from hpos), sub_add_cancel]
end
lemma root_multiplicity_le_one_of_separable [nontrivial R] {p : R[X]}
(hsep : separable p) (x : R) : root_multiplicity x p β€ 1 :=
begin
by_cases hp : p = 0,
{ simp [hp], },
rw [root_multiplicity_eq_multiplicity, dif_neg hp, β part_enat.coe_le_coe, part_enat.coe_get,
nat.cast_one],
exact multiplicity_le_one_of_separable (not_is_unit_X_sub_C _) hsep
end
end comm_ring
section is_domain
variables {R : Type u} [comm_ring R] [is_domain R]
lemma count_roots_le_one {p : R[X]} (hsep : separable p) (x : R) :
p.roots.count x β€ 1 :=
begin
rw count_roots p,
exact root_multiplicity_le_one_of_separable hsep x
end
lemma nodup_roots {p : R[X]} (hsep : separable p) : p.roots.nodup :=
multiset.nodup_iff_count_le_one.mpr (count_roots_le_one hsep)
end is_domain
section field
variables {F : Type u} [field F] {K : Type v} [field K]
theorem separable_iff_derivative_ne_zero {f : F[X]} (hf : irreducible f) :
f.separable β f.derivative β 0 :=
β¨Ξ» h1 h2, hf.not_unit $ is_coprime_zero_right.1 $ h2 βΈ h1,
Ξ» h, euclidean_domain.is_coprime_of_dvd (mt and.right h) $ Ξ» g hg1 hg2 β¨p, hg3β© hg4,
let β¨u, huβ© := (hf.is_unit_or_is_unit hg3).resolve_left hg1 in
have f β£ f.derivative, by { conv_lhs { rw [hg3, β hu] }, rwa units.mul_right_dvd },
not_lt_of_le (nat_degree_le_of_dvd this h) $
nat_degree_derivative_lt $ mt derivative_of_nat_degree_zero hβ©
theorem separable_map (f : F β+* K) {p : F[X]} : (p.map f).separable β p.separable :=
by simp_rw [separable_def, derivative_map, is_coprime_map]
lemma separable_prod_X_sub_C_iff' {ΞΉ : Sort*} {f : ΞΉ β F} {s : finset ΞΉ} :
(β i in s, (X - C (f i))).separable β (β (x β s) (y β s), f x = f y β x = y) :=
β¨Ξ» hfs x hx y hy hfxy, hfs.inj_of_prod_X_sub_C hx hy hfxy,
Ξ» H, by { rw β prod_attach, exact separable_prod' (Ξ» x hx y hy hxy,
@pairwise_coprime_X_sub_C _ _ { x // x β s } (Ξ» x, f x)
(Ξ» x y hxy, subtype.eq $ H x.1 x.2 y.1 y.2 hxy) _ _ hxy)
(Ξ» _ _, separable_X_sub_C) }β©
lemma separable_prod_X_sub_C_iff {ΞΉ : Sort*} [fintype ΞΉ] {f : ΞΉ β F} :
(β i, (X - C (f i))).separable β function.injective f :=
separable_prod_X_sub_C_iff'.trans $ by simp_rw [mem_univ, true_implies_iff, function.injective]
section char_p
variables (p : β) [HF : char_p F p]
include HF
theorem separable_or {f : F[X]} (hf : irreducible f) : f.separable β¨
Β¬f.separable β§ β g : F[X], irreducible g β§ expand F p g = f :=
if H : f.derivative = 0 then
begin
unfreezingI { rcases p.eq_zero_or_pos with rfl | hp },
{ haveI := char_p.char_p_to_char_zero F,
have := nat_degree_eq_zero_of_derivative_eq_zero H,
have := (nat_degree_pos_iff_degree_pos.mpr $ degree_pos_of_irreducible hf).ne',
contradiction },
haveI := is_local_ring_hom_expand F hp,
exact or.inr
β¨by rw [separable_iff_derivative_ne_zero hf, not_not, H],
contract p f,
of_irreducible_map β(expand F p) (by rwa β expand_contract p H hp.ne' at hf),
expand_contract p H hp.ne'β©
end
else or.inl $ (separable_iff_derivative_ne_zero hf).2 H
theorem exists_separable_of_irreducible {f : F[X]} (hf : irreducible f) (hp : p β 0) :
β (n : β) (g : F[X]), g.separable β§ expand F (p ^ n) g = f :=
begin
replace hp : p.prime := (char_p.char_is_prime_or_zero F p).resolve_right hp,
unfreezingI
{ induction hn : f.nat_degree using nat.strong_induction_on with N ih generalizing f },
rcases separable_or p hf with h | β¨h1, g, hg, hgfβ©,
{ refine β¨0, f, h, _β©, rw [pow_zero, expand_one] },
{ cases N with N,
{ rw [nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff] at hn,
rw [hn, separable_C, is_unit_iff_ne_zero, not_not] at h1,
have hf0 : f β 0 := hf.ne_zero,
rw [h1, C_0] at hn, exact absurd hn hf0 },
have hg1 : g.nat_degree * p = N.succ,
{ rwa [β nat_degree_expand, hgf] },
have hg2 : g.nat_degree β 0,
{ intro this, rw [this, zero_mul] at hg1, cases hg1 },
have hg3 : g.nat_degree < N.succ,
{ rw [β mul_one g.nat_degree, β hg1],
exact nat.mul_lt_mul_of_pos_left hp.one_lt hg2.bot_lt },
rcases ih _ hg3 hg rfl with β¨n, g, hg4, rflβ©, refine β¨n+1, g, hg4, _β©,
rw [β hgf, expand_expand, pow_succ] }
end
theorem is_unit_or_eq_zero_of_separable_expand {f : F[X]} (n : β) (hp : 0 < p)
(hf : (expand F (p ^ n) f).separable) : is_unit f β¨ n = 0 :=
begin
rw or_iff_not_imp_right,
rintro hn : n β 0,
have hf2 : (expand F (p ^ n) f).derivative = 0,
{ rw [derivative_expand, nat.cast_pow, char_p.cast_eq_zero,
zero_pow hn.bot_lt, zero_mul, mul_zero] },
rw [separable_def, hf2, is_coprime_zero_right, is_unit_iff] at hf,
rcases hf with β¨r, hr, hrfβ©,
rw [eq_comm, expand_eq_C (pow_pos hp _)] at hrf,
rwa [hrf, is_unit_C]
end
theorem unique_separable_of_irreducible {f : F[X]} (hf : irreducible f) (hp : 0 < p)
(nβ : β) (gβ : F[X]) (hgβ : gβ.separable) (hgfβ : expand F (p ^ nβ) gβ = f)
(nβ : β) (gβ : F[X]) (hgβ : gβ.separable) (hgfβ : expand F (p ^ nβ) gβ = f) :
nβ = nβ β§ gβ = gβ :=
begin
revert gβ gβ,
wlog hn : nβ β€ nβ := le_total nβ nβ using [nβ nβ, nβ nβ],
have hf0 : f β 0 := hf.ne_zero,
unfreezingI { intros, rw le_iff_exists_add at hn, rcases hn with β¨k, rflβ©,
rw [β hgfβ, pow_add, expand_mul, expand_inj (pow_pos hp nβ)] at hgfβ, subst hgfβ,
subst hgfβ,
rcases is_unit_or_eq_zero_of_separable_expand p k hp hgβ with h | rfl,
{ rw is_unit_iff at h, rcases h with β¨r, hr, rflβ©,
simp_rw expand_C at hf, exact absurd (is_unit_C.2 hr) hf.1 },
{ rw [add_zero, pow_zero, expand_one], split; refl } },
obtain β¨hn, hgβ© := this gβ gβ hgβ hgfβ hgβ hgfβ,
exact β¨hn.symm, hg.symmβ©
end
end char_p
/--If `n β 0` in `F`, then ` X ^ n - a` is separable for any `a β 0`. -/
lemma separable_X_pow_sub_C {n : β} (a : F) (hn : (n : F) β 0) (ha : a β 0) :
separable (X ^ n - C a) :=
separable_X_pow_sub_C_unit (units.mk0 a ha) (is_unit.mk0 n hn)
-- this can possibly be strengthened to making `separable_X_pow_sub_C_unit` a
-- bi-implication, but it is nontrivial!
/-- In a field `F`, `X ^ n - 1` is separable iff `βn β 0`. -/
lemma X_pow_sub_one_separable_iff {n : β} :
(X ^ n - 1 : F[X]).separable β (n : F) β 0 :=
begin
refine β¨_, Ξ» h, separable_X_pow_sub_C_unit 1 (is_unit.mk0 βn h)β©,
rw [separable_def', derivative_sub, derivative_X_pow, derivative_one, sub_zero],
-- Suppose `(n : F) = 0`, then the derivative is `0`, so `X ^ n - 1` is a unit, contradiction.
rintro (h : is_coprime _ _) hn',
rw [β C_eq_nat_cast, hn', C.map_zero, zero_mul, is_coprime_zero_right] at h,
have := not_is_unit_X_pow_sub_one F n,
contradiction
end
section splits
lemma card_root_set_eq_nat_degree [algebra F K] {p : F[X]} (hsep : p.separable)
(hsplit : splits (algebra_map F K) p) : fintype.card (p.root_set K) = p.nat_degree :=
begin
simp_rw [root_set_def, finset.coe_sort_coe, fintype.card_coe],
rw [multiset.to_finset_card_of_nodup, βnat_degree_eq_card_roots hsplit],
exact nodup_roots hsep.map,
end
variable {i : F β+* K}
lemma eq_X_sub_C_of_separable_of_root_eq {x : F} {h : F[X]}
(h_sep : h.separable) (h_root : h.eval x = 0) (h_splits : splits i h)
(h_roots : β y β (h.map i).roots, y = i x) : h = (C (leading_coeff h)) * (X - C x) :=
begin
have h_ne_zero : h β 0 := by { rintro rfl, exact not_separable_zero h_sep },
apply polynomial.eq_X_sub_C_of_splits_of_single_root i h_splits,
apply finset.mk.inj,
{ change _ = {i x},
rw finset.eq_singleton_iff_unique_mem,
split,
{ apply finset.mem_mk.mpr,
rw mem_roots (show h.map i β 0, by exact map_ne_zero h_ne_zero),
rw [is_root.def,βevalβ_eq_eval_map,evalβ_hom,h_root],
exact ring_hom.map_zero i },
{ exact h_roots } },
{ exact nodup_roots (separable.map h_sep) },
end
lemma exists_finset_of_splits
(i : F β+* K) {f : F[X]} (sep : separable f) (sp : splits i f) :
β (s : finset K), f.map i = C (i f.leading_coeff) * (s.prod (Ξ» a : K, X - C a)) :=
begin
obtain β¨s, hβ© := (splits_iff_exists_multiset _).1 sp,
use s.to_finset,
rw [h, finset.prod_eq_multiset_prod, βmultiset.to_finset_eq],
apply nodup_of_separable_prod,
apply separable.of_mul_right,
rw βh,
exact sep.map,
end
end splits
theorem _root_.irreducible.separable [char_zero F] {f : F[X]}
(hf : irreducible f) : f.separable :=
begin
rw [separable_iff_derivative_ne_zero hf, ne, β degree_eq_bot, degree_derivative_eq],
{ rintro β¨β© },
rw [pos_iff_ne_zero, ne, nat_degree_eq_zero_iff_degree_le_zero, degree_le_zero_iff],
refine Ξ» hf1, hf.not_unit _,
rw [hf1, is_unit_C, is_unit_iff_ne_zero],
intro hf2,
rw [hf2, C_0] at hf1,
exact absurd hf1 hf.ne_zero
end
end field
end polynomial
open polynomial
section comm_ring
variables (F K : Type*) [comm_ring F] [ring K] [algebra F K]
-- TODO: refactor to allow transcendental extensions?
-- See: https://en.wikipedia.org/wiki/Separable_extension#Separability_of_transcendental_extensions
-- Note that right now a Galois extension (class `is_galois`) is defined to be an extension which
-- is separable and normal, so if the definition of separable changes here at some point
-- to allow non-algebraic extensions, then the definition of `is_galois` must also be changed.
/-- Typeclass for separable field extension: `K` is a separable field extension of `F` iff
the minimal polynomial of every `x : K` is separable.
We define this for general (commutative) rings and only assume `F` and `K` are fields if this
is needed for a proof.
-/
class is_separable : Prop :=
(is_integral' (x : K) : is_integral F x)
(separable' (x : K) : (minpoly F x).separable)
variables (F) {K}
theorem is_separable.is_integral [is_separable F K] :
β x : K, is_integral F x := is_separable.is_integral'
theorem is_separable.separable [is_separable F K] :
β x : K, (minpoly F x).separable := is_separable.separable'
variables {F K}
theorem is_separable_iff : is_separable F K β β x : K, is_integral F x β§ (minpoly F x).separable :=
β¨Ξ» h x, β¨@@is_separable.is_integral F _ _ _ h x, @@is_separable.separable F _ _ _ h xβ©,
Ξ» h, β¨Ξ» x, (h x).1, Ξ» x, (h x).2β©β©
end comm_ring
instance is_separable_self (F : Type*) [field F] : is_separable F F :=
β¨Ξ» x, is_integral_algebra_map, Ξ» x, by { rw minpoly.eq_X_sub_C', exact separable_X_sub_C }β©
/-- A finite field extension in characteristic 0 is separable. -/
@[priority 100] -- See note [lower instance priority]
instance is_separable.of_finite (F K : Type*) [field F] [field K] [algebra F K]
[finite_dimensional F K] [char_zero F] : is_separable F K :=
have β (x : K), is_integral F x,
from Ξ» x, algebra.is_integral_of_finite _ _ _,
β¨this, Ξ» x, (minpoly.irreducible (this x)).separableβ©
section is_separable_tower
variables (F K E : Type*) [field F] [field K] [field E] [algebra F K] [algebra F E]
[algebra K E] [is_scalar_tower F K E]
lemma is_separable_tower_top_of_is_separable [is_separable F E] : is_separable K E :=
β¨Ξ» x, is_integral_of_is_scalar_tower (is_separable.is_integral F x),
Ξ» x, (is_separable.separable F x).map.of_dvd (minpoly.dvd_map_of_is_scalar_tower _ _ _)β©
lemma is_separable_tower_bot_of_is_separable [h : is_separable F E] : is_separable F K :=
is_separable_iff.2 $ Ξ» x, begin
refine (is_separable_iff.1 h (algebra_map K E x)).imp
is_integral_tower_bot_of_is_integral_field (Ξ» hs, _),
obtain β¨q, hqβ© := minpoly.dvd F x
((aeval_algebra_map_eq_zero_iff _ _ _).mp (minpoly.aeval F ((algebra_map K E) x))),
rw hq at hs,
exact hs.of_mul_left
end
variables {E}
lemma is_separable.of_alg_hom (E' : Type*) [field E'] [algebra F E']
(f : E ββ[F] E') [is_separable F E'] : is_separable F E :=
begin
letI : algebra E E' := ring_hom.to_algebra f.to_ring_hom,
haveI : is_scalar_tower F E E' := is_scalar_tower.of_algebra_map_eq (Ξ» x, (f.commutes x).symm),
exact is_separable_tower_bot_of_is_separable F E E',
end
end is_separable_tower
section card_alg_hom
variables {R S T : Type*} [comm_ring S]
variables {K L F : Type*} [field K] [field L] [field F]
variables [algebra K S] [algebra K L]
lemma alg_hom.card_of_power_basis (pb : power_basis K S) (h_sep : (minpoly K pb.gen).separable)
(h_splits : (minpoly K pb.gen).splits (algebra_map K L)) :
@fintype.card (S ββ[K] L) (power_basis.alg_hom.fintype pb) = pb.dim :=
begin
let s := ((minpoly K pb.gen).map (algebra_map K L)).roots.to_finset,
have H := Ξ» x, multiset.mem_to_finset,
rw [fintype.card_congr pb.lift_equiv', fintype.card_of_subtype s H,
β pb.nat_degree_minpoly, nat_degree_eq_card_roots h_splits, multiset.to_finset_card_of_nodup],
exact nodup_roots ((separable_map (algebra_map K L)).mpr h_sep)
end
end card_alg_hom
|
4c45501e894f454950fc6f3917199ba0b41aee9b
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/archive/100-theorems-list/73_ascending_descending_sequences.lean
|
41e92aff0d128067a309900dd5c94922fcfa28bd
|
[
"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
| 8,063
|
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 tactic.basic
import data.fintype.basic
/-!
# ErdΕsβSzekeres theorem
This file proves Theorem 73 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/), also
known as the ErdΕsβSzekeres theorem: given a sequence of more than `r * s` distinct
values, there is an increasing sequence of length longer than `r` or a decreasing sequence of length
longer than `s`.
We use the proof outlined at
https://en.wikipedia.org/wiki/Erdos-Szekeres_theorem#Pigeonhole_principle.
## Tags
sequences, increasing, decreasing, Ramsey, Erdos-Szekeres, ErdΕsβSzekeres, ErdΕs-Szekeres
-/
variables {Ξ± : Type*} [linear_order Ξ±] {Ξ² : Type*}
open function finset
open_locale classical
/--
**ErdΕsβSzekeres Theorem**: Given a sequence of more than `r * s` distinct values, there is an
increasing sequence of length longer than `r` or a decreasing sequence of length longer than `s`.
Proof idea:
We label each value in the sequence with two numbers specifying the longest increasing
subsequence ending there, and the longest decreasing subsequence ending there.
We then show the pair of labels must be unique. Now if there is no increasing sequence longer than
`r` and no decreasing sequence longer than `s`, then there are at most `r * s` possible labels,
which is a contradiction if there are more than `r * s` elements.
-/
theorem erdos_szekeres {r s n : β} {f : fin n β Ξ±} (hn : r * s < n) (hf : injective f) :
(β (t : finset (fin n)), r < t.card β§ strict_mono_on f βt) β¨
(β (t : finset (fin n)), s < t.card β§ strict_anti_on f βt) :=
begin
-- Given an index `i`, produce the set of increasing (resp., decreasing) subsequences which ends
-- at `i`.
let inc_sequences_ending_in : fin n β finset (finset (fin n)) :=
Ξ» i, univ.powerset.filter (Ξ» t, finset.max t = i β§ strict_mono_on f βt),
let dec_sequences_ending_in : fin n β finset (finset (fin n)) :=
Ξ» i, univ.powerset.filter (Ξ» t, finset.max t = i β§ strict_anti_on f βt),
-- The singleton sequence is in both of the above collections.
-- (This is useful to show that the maximum length subsequence is at least 1, and that the set
-- of subsequences is nonempty.)
have inc_i : β i, {i} β inc_sequences_ending_in i := Ξ» i, by simp [strict_mono_on],
have dec_i : β i, {i} β dec_sequences_ending_in i := Ξ» i, by simp [strict_anti_on],
-- Define the pair of labels: at index `i`, the pair is the maximum length of an increasing
-- subsequence ending at `i`, paired with the maximum length of a decreasing subsequence ending
-- at `i`.
-- We call these labels `(a_i, b_i)`.
let ab : fin n β β Γ β,
{ intro i,
apply (max' ((inc_sequences_ending_in i).image card) (nonempty.image β¨{i}, inc_i iβ© _),
max' ((dec_sequences_ending_in i).image card) (nonempty.image β¨{i}, dec_i iβ© _)) },
-- It now suffices to show that one of the labels is 'big' somewhere. In particular, if the
-- first in the pair is more than `r` somewhere, then we have an increasing subsequence in our
-- set, and if the second is more than `s` somewhere, then we have a decreasing subsequence.
suffices : β i, r < (ab i).1 β¨ s < (ab i).2,
{ obtain β¨i, hiβ© := this,
apply or.imp _ _ hi,
work_on_goal 1 { have : (ab i).1 β _ := max'_mem _ _ },
work_on_goal 2 { have : (ab i).2 β _ := max'_mem _ _ },
all_goals
{ intro hi,
rw mem_image at this,
obtain β¨t, htβ, htββ© := this,
refine β¨t, by rwa htβ, _β©,
rw mem_filter at htβ,
apply htβ.2.2 } },
-- Show first that the pair of labels is unique.
have : injective ab,
{ apply injective_of_lt_imp_ne,
intros i j k q,
injection q with qβ qβ,
-- We have two cases: `f i < f j` or `f j < f i`.
-- In the former we'll show `a_i < a_j`, and in the latter we'll show `b_i < b_j`.
cases lt_or_gt_of_ne (Ξ» _, ne_of_lt βΉi < jβΊ (hf βΉf i = f jβΊ)),
work_on_goal 1 { apply ne_of_lt _ qβ, have : (ab i).1 β _ := max'_mem _ _ },
work_on_goal 2 { apply ne_of_lt _ qβ, have : (ab i).2 β _ := max'_mem _ _ },
all_goals
{ -- Reduce to showing there is a subsequence of length `a_i + 1` which ends at `j`.
rw nat.lt_iff_add_one_le,
apply le_max',
rw mem_image at this β’,
-- In particular we take the subsequence `t` of length `a_i` which ends at `i`, by definition
-- of `a_i`
rcases this with β¨t, htβ, htββ©,
rw mem_filter at htβ,
-- Ensure `t` ends at `i`.
have : t.max = i,
simp [htβ.2.1],
-- Now our new subsequence is given by adding `j` at the end of `t`.
refine β¨insert j t, _, _β©,
-- First make sure it's valid, i.e., that this subsequence ends at `j` and is increasing
{ rw mem_filter,
refine β¨_, _, _β©,
{ rw mem_powerset, apply subset_univ },
-- It ends at `j` since `i < j`.
{ convert max_insert,
rw [htβ.2.1, max_eq_left],
apply with_bot.coe_le_coe.mpr (le_of_lt βΉi < jβΊ) },
-- To show it's increasing (i.e., `f` is monotone increasing on `t.insert j`), we do cases
-- on what the possibilities could be - either in `t` or equals `j`.
simp only [strict_mono_on, strict_anti_on, coe_insert, set.mem_insert_iff,
mem_coe],
-- Most of the cases are just bashes.
rintros x β¨rfl | _β© y β¨rfl | _β© _,
{ apply (irrefl _ βΉj < jβΊ).elim },
{ exfalso,
apply not_le_of_lt (trans βΉi < jβΊ βΉj < yβΊ) (le_max_of_mem βΉy β tβΊ βΉt.max = iβΊ) },
{ apply lt_of_le_of_lt _ βΉf i < f jβΊ <|> apply lt_of_lt_of_le βΉf j < f iβΊ _,
rcases lt_or_eq_of_le (le_max_of_mem βΉx β tβΊ βΉt.max = iβΊ) with _ | rfl,
{ apply le_of_lt (htβ.2.2 βΉx β tβΊ (mem_of_max βΉt.max = iβΊ) βΉx < iβΊ) },
{ refl } },
{ apply htβ.2.2 βΉx β tβΊ βΉy β tβΊ βΉx < yβΊ } },
-- Finally show that this new subsequence is one longer than the old one.
{ rw [card_insert_of_not_mem, htβ],
intro _,
apply not_le_of_lt βΉi < jβΊ (le_max_of_mem βΉj β tβΊ βΉt.max = iβΊ) } } },
-- Finished both goals!
-- Now that we have uniqueness of each label, it remains to do some counting to finish off.
-- Suppose all the labels are small.
by_contra q,
push_neg at q,
-- Then the labels `(a_i, b_i)` all fit in the following set: `{ (x,y) | 1 β€ x β€ r, 1 β€ y β€ s }`
let ran : finset (β Γ β) := (range r).image nat.succ ΓΛ’ (range s).image nat.succ,
-- which we prove here.
have : image ab univ β ran,
-- First some logical shuffling
{ rintro β¨xβ, xββ©,
simp only [mem_image, exists_prop, mem_range, mem_univ, mem_product, true_and, prod.mk.inj_iff],
rintros β¨i, rfl, rflβ©,
specialize q i,
-- Show `1 β€ a_i` and `1 β€ b_i`, which is easy from the fact that `{i}` is a increasing and
-- decreasing subsequence which we did right near the top.
have z : 1 β€ (ab i).1 β§ 1 β€ (ab i).2,
{ split;
{ apply le_max',
rw mem_image,
refine β¨{i}, by solve_by_elim, card_singleton iβ© } },
refine β¨_, _β©,
-- Need to get `a_i β€ r`, here phrased as: there is some `a < r` with `a+1 = a_i`.
{ refine β¨(ab i).1 - 1, _, nat.succ_pred_eq_of_pos z.1β©,
rw tsub_lt_iff_right z.1,
apply nat.lt_succ_of_le q.1 },
{ refine β¨(ab i).2 - 1, _, nat.succ_pred_eq_of_pos z.2β©,
rw tsub_lt_iff_right z.2,
apply nat.lt_succ_of_le q.2 } },
-- To get our contradiction, it suffices to prove `n β€ r * s`
apply not_le_of_lt hn,
-- Which follows from considering the cardinalities of the subset above, since `ab` is injective.
simpa [nat.succ_injective, card_image_of_injective, βΉinjective abβΊ] using card_le_of_subset this,
end
|
d4c549fedd7e88eabf31c0229bc778f2d5097691
|
b2fe74b11b57d362c13326bc5651244f111fa6f4
|
/src/analysis/mean_inequalities.lean
|
892eccfde7d33daf735e00a54bb4f08899b00aa3
|
[
"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
| 47,315
|
lean
|
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne
-/
import analysis.convex.specific_functions
import analysis.special_functions.pow
import data.real.conjugate_exponents
import tactic.nth_rewrite
import measure_theory.integration
/-!
# Mean value inequalities
In this file we prove several inequalities, including AM-GM inequality, Young's inequality,
HΓΆlder inequality, and Minkowski inequality.
## Main theorems
### AM-GM inequality:
The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal
to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$
are two non-negative vectors and $\sum_{i\in s} w_i=1$, then
$$
\prod_{i\in s} z_i^{w_i} β€ \sum_{i\in s} w_iz_i.
$$
The classical version is a special case of this inequality for $w_i=\frac{1}{n}$.
We prove a few versions of this inequality. Each of the following lemmas comes in two versions:
a version for real-valued non-negative functions is in the `real` namespace, and a version for
`nnreal`-valued functions is in the `nnreal` namespace.
- `geom_mean_le_arith_mean_weighted` : weighted version for functions on `finset`s;
- `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers;
- `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers;
- `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers.
### Generalized mean inequality
The inequality says that for two non-negative vectors $w$ and $z$ with $\sum_{i\in s} w_i=1$
and $p β€ q$ we have
$$
\sqrt[p]{\sum_{i\in s} w_i z_i^p} β€ \sqrt[q]{\sum_{i\in s} w_i z_i^q}.
$$
Currently we only prove this inequality for $p=1$. As in the rest of `mathlib`, we provide
different theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents
(`fpow_arith_mean_le_arith_mean_fpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and
`arith_mean_le_rpow_mean`). In the first two cases we prove
$$
\left(\sum_{i\in s} w_i z_i\right)^n β€ \sum_{i\in s} w_i z_i^n
$$
in order to avoid using real exponents. For real exponents we prove both this and standard versions.
### Young's inequality
Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that
$\frac{1}{p}+\frac{1}{q}=1$ we have
$$
ab β€ \frac{a^p}{p} + \frac{b^q}{q}.
$$
This inequality is a special case of the AM-GM inequality. It can be used to prove HΓΆlder's
inequality (see below) but we use a different proof.
### HΓΆlder's inequality
The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers
such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is
less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the
second vector:
$$
\sum_{i\in s} a_ib_i β€ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}.
$$
We give versions of this result in `real`, `nnreal` and `ennreal`.
There are at least two short proofs of this inequality. In one proof we prenormalize both vectors,
then apply Young's inequality to each $a_ib_i$. We use a different proof deducing this inequality
from the generalized mean inequality for well-chosen vectors and weights.
HΓΆlder's inequality for the Lebesgue integral of ennreal and nnreal functions: we prove
`β« (f * g) βΞΌ β€ (β« f^p βΞΌ) ^ (1/p) * (β« g^q βΞΌ) ^ (1/q)` for `p`, `q` conjugate real exponents
and `Ξ±β(e)nnreal` functions in two cases,
* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ennreal functions,
* `nnreal.lintegral_mul_le_Lp_mul_Lq` : nnreal functions.
### Minkowski's inequality
The inequality says that for `p β₯ 1` the function
$$
\|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p}
$$
satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$.
We give versions of this result in `real`, `nnreal` and `ennreal`.
We deduce this inequality from HΓΆlder's inequality. Namely, HΓΆlder inequality implies that $\|a\|_p$
is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now
Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is
less than or equal to the sum of the maximum values of the summands.
Minkowski's inequality for the Lebesgue integral of measurable functions with `ennreal` values:
we prove `(β« (f + g)^p βΞΌ) ^ (1/p) β€ (β« f^p βΞΌ) ^ (1/p) + (β« g^p βΞΌ) ^ (1/p)` for `1 β€ p`.
## TODO
- each inequality `A β€ B` should come with a theorem `A = B β _`; one of the ways to prove them
is to define `strict_convex_on` functions.
- generalized mean inequality with any `p β€ q`, including negative numbers;
- prove that the power mean tends to the geometric mean as the exponent tends to zero.
- prove integral versions of these inequalities.
-/
universes u v
open finset
open_locale classical nnreal big_operators
noncomputable theory
variables {ΞΉ : Type u} (s : finset ΞΉ)
namespace real
/-- AM-GM inequality: the geometric mean is less than or equal to the arithmetic mean, weighted version
for real-valued nonnegative functions. -/
theorem geom_mean_le_arith_mean_weighted (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i in s, w i = 1) (hz : β i β s, 0 β€ z i) :
(β i in s, (z i) ^ (w i)) β€ β i in s, w i * z i :=
begin
-- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative.
by_cases A : β i β s, z i = 0 β§ w i β 0,
{ rcases A with β¨i, his, hzi, hwiβ©,
rw [prod_eq_zero his],
{ exact sum_nonneg (Ξ» j hj, mul_nonneg (hw j hj) (hz j hj)) },
{ rw hzi, exact zero_rpow hwi } },
-- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality
-- for `exp` and numbers `log (z i)` with weights `w i`.
{ simp only [not_exists, not_and, ne.def, not_not] at A,
have := convex_on_exp.map_sum_le hw hw' (Ξ» i _, set.mem_univ $ log (z i)),
simp only [exp_sum, (β), smul_eq_mul, mul_comm (w _) (log _)] at this,
convert this using 1; [apply prod_congr rfl, apply sum_congr rfl]; intros i hi,
{ cases eq_or_lt_of_le (hz i hi) with hz hz,
{ simp [A i hi hz.symm] },
{ exact rpow_def_of_pos hz _ } },
{ cases eq_or_lt_of_le (hz i hi) with hz hz,
{ simp [A i hi hz.symm] },
{ rw [exp_log hz] } } }
end
theorem pow_arith_mean_le_arith_mean_pow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i in s, w i = 1) (hz : β i β s, 0 β€ z i) (n : β) :
(β i in s, w i * z i) ^ n β€ β i in s, (w i * z i ^ n) :=
(convex_on_pow n).map_sum_le hw hw' hz
theorem pow_arith_mean_le_arith_mean_pow_of_even (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i in s, w i = 1) {n : β} (hn : even n) :
(β i in s, w i * z i) ^ n β€ β i in s, (w i * z i ^ n) :=
(convex_on_pow_of_even hn).map_sum_le hw hw' (Ξ» _ _, trivial)
theorem fpow_arith_mean_le_arith_mean_fpow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i in s, w i = 1) (hz : β i β s, 0 < z i) (m : β€) :
(β i in s, w i * z i) ^ m β€ β i in s, (w i * z i ^ m) :=
(convex_on_fpow m).map_sum_le hw hw' hz
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i in s, w i = 1) (hz : β i β s, 0 β€ z i) {p : β} (hp : 1 β€ p) :
(β i in s, w i * z i) ^ p β€ β i in s, (w i * z i ^ p) :=
(convex_on_rpow hp).map_sum_le hw hw' hz
theorem arith_mean_le_rpow_mean (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i in s, w i = 1) (hz : β i β s, 0 β€ z i) {p : β} (hp : 1 β€ p) :
β i in s, w i * z i β€ (β i in s, (w i * z i ^ p)) ^ (1 / p) :=
begin
have : 0 < p := lt_of_lt_of_le zero_lt_one hp,
rw [β rpow_le_rpow_iff _ _ this, β rpow_mul, one_div_mul_cancel (ne_of_gt this), rpow_one],
exact rpow_arith_mean_le_arith_mean_rpow s w z hw hw' hz hp,
all_goals { apply_rules [sum_nonneg, rpow_nonneg_of_nonneg],
intros i hi,
apply_rules [mul_nonneg, rpow_nonneg_of_nonneg, hw i hi, hz i hi] },
end
end real
namespace nnreal
/-- The geometric mean is less than or equal to the arithmetic mean, weighted version
for `nnreal`-valued functions. -/
theorem geom_mean_le_arith_mean_weighted (w z : ΞΉ β ββ₯0) (hw' : β i in s, w i = 1) :
(β i in s, (z i) ^ (w i:β)) β€ β i in s, w i * z i :=
by exact_mod_cast real.geom_mean_le_arith_mean_weighted _ _ _ (Ξ» i _, (w i).coe_nonneg)
(by assumption_mod_cast) (Ξ» i _, (z i).coe_nonneg)
/-- The geometric mean is less than or equal to the arithmetic mean, weighted version
for two `nnreal` numbers. -/
theorem geom_mean_le_arith_mean2_weighted (wβ wβ pβ pβ : ββ₯0) :
wβ + wβ = 1 β pβ ^ (wβ:β) * pβ ^ (wβ:β) β€ wβ * pβ + wβ * pβ :=
by simpa only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero,
fin.cons_succ, fin.cons_zero, add_zero, mul_one]
using geom_mean_le_arith_mean_weighted (univ : finset (fin 2))
(fin.cons wβ $ fin.cons wβ fin_zero_elim) (fin.cons pβ $ fin.cons pβ $ fin_zero_elim)
theorem geom_mean_le_arith_mean3_weighted (wβ wβ wβ pβ pβ pβ : ββ₯0) :
wβ + wβ + wβ = 1 β pβ ^ (wβ:β) * pβ ^ (wβ:β) * pβ ^ (wβ:β) β€ wβ * pβ + wβ * pβ + wβ * pβ :=
by simpa only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero,
fin.cons_succ, fin.cons_zero, add_zero, mul_one, β add_assoc, mul_assoc]
using geom_mean_le_arith_mean_weighted (univ : finset (fin 3))
(fin.cons wβ $ fin.cons wβ $ fin.cons wβ fin_zero_elim)
(fin.cons pβ $ fin.cons pβ $ fin.cons pβ fin_zero_elim)
theorem geom_mean_le_arith_mean4_weighted (wβ wβ wβ wβ pβ pβ pβ pβ : ββ₯0) :
wβ + wβ + wβ + wβ = 1 β pβ ^ (wβ:β) * pβ ^ (wβ:β) * pβ ^ (wβ:β)* pβ ^ (wβ:β) β€
wβ * pβ + wβ * pβ + wβ * pβ + wβ * pβ :=
by simpa only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero,
fin.cons_succ, fin.cons_zero, add_zero, mul_one, β add_assoc, mul_assoc]
using geom_mean_le_arith_mean_weighted (univ : finset (fin 4))
(fin.cons wβ $ fin.cons wβ $ fin.cons wβ $ fin.cons wβ fin_zero_elim)
(fin.cons pβ $ fin.cons pβ $ fin.cons pβ $ fin.cons pβ fin_zero_elim)
/-- Weighted generalized mean inequality, version sums over finite sets, with `ββ₯0`-valued
functions and natural exponent. -/
theorem pow_arith_mean_le_arith_mean_pow (w z : ΞΉ β ββ₯0) (hw' : β i in s, w i = 1) (n : β) :
(β i in s, w i * z i) ^ n β€ β i in s, (w i * z i ^ n) :=
by exact_mod_cast real.pow_arith_mean_le_arith_mean_pow s _ _ (Ξ» i _, (w i).coe_nonneg)
(by exact_mod_cast hw') (Ξ» i _, (z i).coe_nonneg) n
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ββ₯0`-valued
functions and real exponents. -/
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β ββ₯0) (hw' : β i in s, w i = 1) {p : β}
(hp : 1 β€ p) :
(β i in s, w i * z i) ^ p β€ β i in s, (w i * z i ^ p) :=
by exact_mod_cast real.rpow_arith_mean_le_arith_mean_rpow s _ _ (Ξ» i _, (w i).coe_nonneg)
(by exact_mod_cast hw') (Ξ» i _, (z i).coe_nonneg) hp
/-- Weighted generalized mean inequality, version for two elements of `ββ₯0` and real exponents. -/
theorem rpow_arith_mean_le_arith_mean2_rpow (wβ wβ zβ zβ : ββ₯0) (hw' : wβ + wβ = 1) {p : β}
(hp : 1 β€ p) :
(wβ * zβ + wβ * zβ) ^ p β€ wβ * zβ ^ p + wβ * zβ ^ p :=
begin
have h := rpow_arith_mean_le_arith_mean_rpow (univ : finset (fin 2))
(fin.cons wβ $ fin.cons wβ fin_zero_elim) (fin.cons zβ $ fin.cons zβ $ fin_zero_elim) _ hp,
{ simpa [fin.sum_univ_succ, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero] using h, },
{ simp [hw', fin.sum_univ_succ, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero], },
end
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ββ₯0`-valued
functions and real exponents. -/
theorem arith_mean_le_rpow_mean (w z : ΞΉ β ββ₯0) (hw' : β i in s, w i = 1) {p : β}
(hp : 1 β€ p) :
β i in s, w i * z i β€ (β i in s, (w i * z i ^ p)) ^ (1 / p) :=
by exact_mod_cast real.arith_mean_le_rpow_mean s _ _ (Ξ» i _, (w i).coe_nonneg)
(by exact_mod_cast hw') (Ξ» i _, (z i).coe_nonneg) hp
end nnreal
namespace ennreal
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ennreal`-valued
functions and real exponents. -/
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β ennreal) (hw' : β i in s, w i = 1) {p : β}
(hp : 1 β€ p) :
(β i in s, w i * z i) ^ p β€ β i in s, (w i * z i ^ p) :=
begin
have hp_pos : 0 < p, from lt_of_lt_of_le zero_lt_one hp,
have hp_nonneg : 0 β€ p, from le_of_lt hp_pos,
have hp_not_nonpos : Β¬ p β€ 0, by simp [hp_pos],
have hp_not_neg : Β¬ p < 0, by simp [hp_nonneg],
have h_top_iff_rpow_top : β (i : ΞΉ) (hi : i β s), w i * z i = β€ β w i * (z i) ^ p = β€,
by simp [hp_pos, hp_nonneg, hp_not_nonpos, hp_not_neg],
refine le_of_top_imp_top_of_to_nnreal_le _ _,
{ -- first, prove `(β i in s, w i * z i) ^ p = β€ β β i in s, (w i * z i ^ p) = β€`
rw [rpow_eq_top_iff, sum_eq_top_iff, sum_eq_top_iff],
intro h,
simp only [and_false, hp_not_neg, false_or] at h,
rcases h.left with β¨a, H, haβ©,
use [a, H],
rwa βh_top_iff_rpow_top a H, },
{ -- second, suppose both `(β i in s, w i * z i) ^ p β β€` and `β i in s, (w i * z i ^ p) β β€`,
-- and prove `((β i in s, w i * z i) ^ p).to_nnreal β€ (β i in s, (w i * z i ^ p)).to_nnreal`,
-- by using `nnreal.rpow_arith_mean_le_arith_mean_rpow`.
intros h_top_rpow_sum _,
-- show hypotheses needed to put the `.to_nnreal` inside the sums.
have h_top : β (a : ΞΉ), a β s β w a * z a < β€,
{ have h_top_sum : β (i : ΞΉ) in s, w i * z i < β€,
{ by_contra h,
rw [lt_top_iff_ne_top, not_not] at h,
rw [h, top_rpow_of_pos hp_pos] at h_top_rpow_sum,
exact h_top_rpow_sum rfl, },
rwa sum_lt_top_iff at h_top_sum, },
have h_top_rpow : β (a : ΞΉ), a β s β w a * z a ^ p < β€,
{ intros i hi,
specialize h_top i hi,
rw lt_top_iff_ne_top at h_top β’,
rwa [ne.def, βh_top_iff_rpow_top i hi], },
-- put the `.to_nnreal` inside the sums.
simp_rw [to_nnreal_sum h_top_rpow, βto_nnreal_rpow, to_nnreal_sum h_top, to_nnreal_mul,
βto_nnreal_rpow],
-- use corresponding nnreal result
refine nnreal.rpow_arith_mean_le_arith_mean_rpow s (Ξ» i, (w i).to_nnreal) (Ξ» i, (z i).to_nnreal)
_ hp,
-- verify the hypothesis `β i in s, (w i).to_nnreal = 1`, using `β i in s, w i = 1` .
have h_sum_nnreal : (β i in s, w i) = β(β i in s, (w i).to_nnreal),
{ have hw_top : β i in s, w i < β€, by { rw hw', exact one_lt_top, },
rw βto_nnreal_sum,
{ rw coe_to_nnreal,
rwa βlt_top_iff_ne_top, },
{ rwa sum_lt_top_iff at hw_top, }, },
rwa [βcoe_eq_coe, βh_sum_nnreal], },
end
/-- Weighted generalized mean inequality, version for two elements of `ennreal` and real
exponents. -/
theorem rpow_arith_mean_le_arith_mean2_rpow (wβ wβ zβ zβ : ennreal) (hw' : wβ + wβ = 1) {p : β}
(hp : 1 β€ p) :
(wβ * zβ + wβ * zβ) ^ p β€ wβ * zβ ^ p + wβ * zβ ^ p :=
begin
have h := rpow_arith_mean_le_arith_mean_rpow (univ : finset (fin 2))
(fin.cons wβ $ fin.cons wβ fin_zero_elim) (fin.cons zβ $ fin.cons zβ $ fin_zero_elim) _ hp,
{ simpa [fin.sum_univ_succ, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero] using h, },
{ simp [hw', fin.sum_univ_succ, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero], },
end
end ennreal
namespace real
theorem geom_mean_le_arith_mean2_weighted {wβ wβ pβ pβ : β} (hwβ : 0 β€ wβ) (hwβ : 0 β€ wβ)
(hpβ : 0 β€ pβ) (hpβ : 0 β€ pβ) (hw : wβ + wβ = 1) :
pβ ^ wβ * pβ ^ wβ β€ wβ * pβ + wβ * pβ :=
nnreal.geom_mean_le_arith_mean2_weighted β¨wβ, hwββ© β¨wβ, hwββ© β¨pβ, hpββ© β¨pβ, hpββ© $
nnreal.coe_eq.1 $ by assumption
theorem geom_mean_le_arith_mean3_weighted {wβ wβ wβ pβ pβ pβ : β} (hwβ : 0 β€ wβ) (hwβ : 0 β€ wβ)
(hwβ : 0 β€ wβ) (hpβ : 0 β€ pβ) (hpβ : 0 β€ pβ) (hpβ : 0 β€ pβ) (hw : wβ + wβ + wβ = 1) :
pβ ^ wβ * pβ ^ wβ * pβ ^ wβ β€ wβ * pβ + wβ * pβ + wβ * pβ :=
nnreal.geom_mean_le_arith_mean3_weighted β¨wβ, hwββ© β¨wβ, hwββ© β¨wβ, hwββ© β¨pβ, hpββ© β¨pβ, hpββ© β¨pβ, hpββ© $
nnreal.coe_eq.1 $ by assumption
theorem geom_mean_le_arith_mean4_weighted {wβ wβ wβ wβ pβ pβ pβ pβ : β} (hwβ : 0 β€ wβ)
(hwβ : 0 β€ wβ) (hwβ : 0 β€ wβ) (hwβ : 0 β€ wβ) (hpβ : 0 β€ pβ) (hpβ : 0 β€ pβ) (hpβ : 0 β€ pβ)
(hpβ : 0 β€ pβ) (hw : wβ + wβ + wβ + wβ = 1) :
pβ ^ wβ * pβ ^ wβ * pβ ^ wβ * pβ ^ wβ β€ wβ * pβ + wβ * pβ + wβ * pβ + wβ * pβ :=
nnreal.geom_mean_le_arith_mean4_weighted β¨wβ, hwββ© β¨wβ, hwββ© β¨wβ, hwββ© β¨wβ, hwββ©
β¨pβ, hpββ© β¨pβ, hpββ© β¨pβ, hpββ© β¨pβ, hpββ© $ nnreal.coe_eq.1 $ by assumption
/-- Young's inequality, a version for nonnegative real numbers. -/
theorem young_inequality_of_nonneg {a b p q : β} (ha : 0 β€ a) (hb : 0 β€ b)
(hpq : p.is_conjugate_exponent q) :
a * b β€ a^p / p + b^q / q :=
by simpa [β rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, div_eq_inv_mul]
using geom_mean_le_arith_mean2_weighted hpq.one_div_nonneg hpq.symm.one_div_nonneg
(rpow_nonneg_of_nonneg ha p) (rpow_nonneg_of_nonneg hb q) hpq.inv_add_inv_conj
/-- Young's inequality, a version for arbitrary real numbers. -/
theorem young_inequality (a b : β) {p q : β} (hpq : p.is_conjugate_exponent q) :
a * b β€ (abs a)^p / p + (abs b)^q / q :=
calc a * b β€ abs (a * b) : le_abs_self (a * b)
... = abs a * abs b : abs_mul a b
... β€ (abs a)^p / p + (abs b)^q / q :
real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq
end real
namespace nnreal
/-- Young's inequality, `ββ₯0` version. We use `{p q : ββ₯0}` in order to avoid constructing
witnesses of `0 β€ p` and `0 β€ q` for the denominators. -/
theorem young_inequality (a b : ββ₯0) {p q : ββ₯0} (hp : 1 < p) (hpq : 1 / p + 1 / q = 1) :
a * b β€ a^(p:β) / p + b^(q:β) / q :=
real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg β¨hp, nnreal.coe_eq.2 hpqβ©
/-- Young's inequality, `ββ₯0` version with real conjugate exponents. -/
theorem young_inequality_real (a b : ββ₯0) {p q : β} (hpq : p.is_conjugate_exponent q) :
a * b β€ a ^ p / nnreal.of_real p + b ^ q / nnreal.of_real q :=
begin
nth_rewrite 0 βcoe_of_real p hpq.nonneg,
nth_rewrite 0 βcoe_of_real q hpq.symm.nonneg,
exact young_inequality a b hpq.one_lt_nnreal hpq.inv_add_inv_conj_nnreal,
end
/-- HΓΆlder inequality: the scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,
with `ββ₯0`-valued functions. -/
theorem inner_le_Lp_mul_Lq (f g : ΞΉ β ββ₯0) {p q : β}
(hpq : p.is_conjugate_exponent q) :
β i in s, f i * g i β€ (β i in s, (f i) ^ p) ^ (1 / p) * (β i in s, (g i) ^ q) ^ (1 / q) :=
begin
-- Let `G=β₯gβ₯_q` be the `L_q`-norm of `g`.
set G := (β i in s, (g i) ^ q) ^ (1 / q),
have hGq : G ^ q = β i in s, (g i) ^ q,
{ rw [β rpow_mul, one_div_mul_cancel hpq.symm.ne_zero, rpow_one], },
-- First consider the trivial case `β₯gβ₯_q=0`
by_cases hG : G = 0,
{ rw [hG, sum_eq_zero, mul_zero],
intros i hi,
simp only [rpow_eq_zero_iff, sum_eq_zero_iff] at hG,
simp [(hG.1 i hi).1] },
{ -- Move power from right to left
rw [β div_le_iff hG, sum_div],
-- Now the inequality follows from the weighted generalized mean inequality
-- with weights `w_i` and numbers `z_i` given by the following formulas.
set w : ΞΉ β ββ₯0 := Ξ» i, (g i) ^ q / G ^ q,
set z : ΞΉ β ββ₯0 := Ξ» i, f i * (G / g i) ^ (q / p),
-- Show that the sum of weights equals one
have A : β i in s, w i = 1,
{ rw [β sum_div, hGq, div_self],
simpa [rpow_eq_zero_iff, hpq.symm.ne_zero] using hG },
-- LHS of the goal equals LHS of the weighted generalized mean inequality
calc (β i in s, f i * g i / G) = (β i in s, w i * z i) :
begin
refine sum_congr rfl (Ξ» i hi, _),
have : q - q / p = 1, by field_simp [hpq.ne_zero, hpq.symm.mul_eq_add],
dsimp only [w, z],
rw [β div_rpow, mul_left_comm, mul_div_assoc, β @inv_div _ _ _ G, inv_rpow,
β div_eq_mul_inv, β rpow_sub']; simp [this]
end
-- Apply the generalized mean inequality
... β€ (β i in s, w i * (z i) ^ p) ^ (1 / p) :
nnreal.arith_mean_le_rpow_mean s w z A (le_of_lt hpq.one_lt)
-- Simplify the right hand side. Terms with `g i β 0` are equal to `(f i) ^ p`,
-- the others are zeros.
... β€ (β i in s, (f i) ^ p) ^ (1 / p) :
begin
refine rpow_le_rpow (sum_le_sum (Ξ» i hi, _)) hpq.one_div_nonneg,
dsimp only [w, z],
rw [mul_rpow, mul_left_comm, β rpow_mul _ _ p, div_mul_cancel _ hpq.ne_zero, div_rpow,
div_mul_div, mul_comm (G ^ q), mul_div_mul_right],
{ nth_rewrite 1 [β mul_one ((f i) ^ p)],
exact canonically_ordered_semiring.mul_le_mul (le_refl _) (div_self_le _) },
{ simpa [hpq.symm.ne_zero] using hG }
end }
end
/-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product
`β i in s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/
theorem is_greatest_Lp (f : ΞΉ β ββ₯0) {p q : β} (hpq : p.is_conjugate_exponent q) :
is_greatest ((Ξ» g : ΞΉ β ββ₯0, β i in s, f i * g i) ''
{g | β i in s, (g i)^q β€ 1}) ((β i in s, (f i)^p) ^ (1 / p)) :=
begin
split,
{ use Ξ» i, ((f i) ^ p / f i / (β i in s, (f i) ^ p) ^ (1 / q)),
by_cases hf : β i in s, (f i)^p = 0,
{ simp [hf, hpq.ne_zero, hpq.symm.ne_zero] },
{ have A : p + q - q β 0, by simp [hpq.ne_zero],
have B : β y : ββ₯0, y * y^p / y = y^p,
{ refine Ξ» y, mul_div_cancel_left_of_imp (Ξ» h, _),
simpa [h, hpq.ne_zero] },
simp only [set.mem_set_of_eq, div_rpow, β sum_div, β rpow_mul,
div_mul_cancel _ hpq.symm.ne_zero, rpow_one, div_le_iff hf, one_mul, hpq.mul_eq_add,
β rpow_sub' _ A, _root_.add_sub_cancel, le_refl, true_and, β mul_div_assoc, B],
rw [div_eq_iff, β rpow_add hf, hpq.inv_add_inv_conj, rpow_one],
simpa [hpq.symm.ne_zero] using hf } },
{ rintros _ β¨g, hg, rflβ©,
apply le_trans (inner_le_Lp_mul_Lq s f g hpq),
simpa only [mul_one] using canonically_ordered_semiring.mul_le_mul (le_refl _)
(nnreal.rpow_le_one hg (le_of_lt hpq.symm.one_div_pos)) }
end
/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal
to the sum of the `L_p`-seminorms of the summands. A version for `nnreal`-valued functions. -/
theorem Lp_add_le (f g : ΞΉ β ββ₯0) {p : β} (hp : 1 β€ p) :
(β i in s, (f i + g i) ^ p) ^ (1 / p) β€
(β i in s, (f i) ^ p) ^ (1 / p) + (β i in s, (g i) ^ p) ^ (1 / p) :=
begin
-- The result is trivial when `p = 1`, so we can assume `1 < p`.
rcases eq_or_lt_of_le hp with rfl|hp, { simp [finset.sum_add_distrib] },
have hpq := real.is_conjugate_exponent_conjugate_exponent hp,
have := is_greatest_Lp s (f + g) hpq,
simp only [pi.add_apply, add_mul, sum_add_distrib] at this,
rcases this.1 with β¨Ο, hΟ, Hβ©,
rw β H,
exact add_le_add ((is_greatest_Lp s f hpq).2 β¨Ο, hΟ, rflβ©)
((is_greatest_Lp s g hpq).2 β¨Ο, hΟ, rflβ©)
end
end nnreal
namespace real
variables (f g : ΞΉ β β) {p q : β}
/-- HΓΆlder inequality: the scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,
with real-valued functions. -/
theorem inner_le_Lp_mul_Lq (hpq : is_conjugate_exponent p q) :
β i in s, f i * g i β€ (β i in s, (abs $ f i)^p) ^ (1 / p) * (β i in s, (abs $ g i)^q) ^ (1 / q) :=
begin
have := nnreal.coe_le_coe.2 (nnreal.inner_le_Lp_mul_Lq s (Ξ» i, β¨_, abs_nonneg (f i)β©)
(Ξ» i, β¨_, abs_nonneg (g i)β©) hpq),
push_cast at this,
refine le_trans (sum_le_sum $ Ξ» i hi, _) this,
simp only [β abs_mul, le_abs_self]
end
/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal
to the sum of the `L_p`-seminorms of the summands. A version for `real`-valued functions. -/
theorem Lp_add_le (hp : 1 β€ p) :
(β i in s, (abs $ f i + g i) ^ p) ^ (1 / p) β€
(β i in s, (abs $ f i) ^ p) ^ (1 / p) + (β i in s, (abs $ g i) ^ p) ^ (1 / p) :=
begin
have := nnreal.coe_le_coe.2 (nnreal.Lp_add_le s (Ξ» i, β¨_, abs_nonneg (f i)β©)
(Ξ» i, β¨_, abs_nonneg (g i)β©) hp),
push_cast at this,
refine le_trans (rpow_le_rpow _ (sum_le_sum $ Ξ» i hi, _) _) this;
simp [sum_nonneg, rpow_nonneg_of_nonneg, abs_nonneg, le_trans zero_le_one hp, abs_add,
rpow_le_rpow]
end
variables {f g}
/-- HΓΆlder inequality: the scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,
with real-valued nonnegative functions. -/
theorem inner_le_Lp_mul_Lq_of_nonneg (hpq : is_conjugate_exponent p q)
(hf : β i β s, 0 β€ f i) (hg : β i β s, 0 β€ g i) :
β i in s, f i * g i β€ (β i in s, (f i)^p) ^ (1 / p) * (β i in s, (g i)^q) ^ (1 / q) :=
by convert inner_le_Lp_mul_Lq s f g hpq using 3; apply sum_congr rfl; intros i hi;
simp only [abs_of_nonneg, hf i hi, hg i hi]
/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal
to the sum of the `L_p`-seminorms of the summands. A version for `real`-valued nonnegative
functions. -/
theorem Lp_add_le_of_nonneg (hp : 1 β€ p) (hf : β i β s, 0 β€ f i) (hg : β i β s, 0 β€ g i) :
(β i in s, (f i + g i) ^ p) ^ (1 / p) β€
(β i in s, (f i) ^ p) ^ (1 / p) + (β i in s, (g i) ^ p) ^ (1 / p) :=
by convert Lp_add_le s f g hp using 2 ; [skip, congr' 1, congr' 1];
apply sum_congr rfl; intros i hi; simp only [abs_of_nonneg, hf i hi, hg i hi, add_nonneg]
end real
namespace ennreal
/-- Young's inequality, `ennreal` version with real conjugate exponents. -/
theorem young_inequality (a b : ennreal) {p q : β} (hpq : p.is_conjugate_exponent q) :
a * b β€ a ^ p / ennreal.of_real p + b ^ q / ennreal.of_real q :=
begin
by_cases h : a = β€ β¨ b = β€,
{ refine le_trans le_top (le_of_eq _),
repeat {rw ennreal.div_def},
cases h; rw h; simp [h, hpq.pos, hpq.symm.pos], },
push_neg at h, -- if a β β€ and b β β€, use the nnreal version: nnreal.young_inequality_real
rw [βcoe_to_nnreal h.left, βcoe_to_nnreal h.right, βcoe_mul,
coe_rpow_of_nonneg _ hpq.nonneg, coe_rpow_of_nonneg _ hpq.symm.nonneg, ennreal.of_real,
ennreal.of_real, β@coe_div (nnreal.of_real p) _ (by simp [hpq.pos]),
β@coe_div (nnreal.of_real q) _ (by simp [hpq.symm.pos]), βcoe_add, coe_le_coe],
exact nnreal.young_inequality_real a.to_nnreal b.to_nnreal hpq,
end
variables (f g : ΞΉ β ennreal) {p q : β}
/-- HΓΆlder inequality: the scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,
with `ennreal`-valued functions. -/
theorem inner_le_Lp_mul_Lq (hpq : p.is_conjugate_exponent q) :
(β i in s, f i * g i) β€ (β i in s, (f i)^p) ^ (1/p) * (β i in s, (g i)^q) ^ (1/q) :=
begin
by_cases H : (β i in s, (f i)^p) ^ (1/p) = 0 β¨ (β i in s, (g i)^q) ^ (1/q) = 0,
{ replace H : (β i β s, f i = 0) β¨ (β i β s, g i = 0),
by simpa [ennreal.rpow_eq_zero_iff, hpq.pos, hpq.symm.pos, asymm hpq.pos, asymm hpq.symm.pos,
sum_eq_zero_iff_of_nonneg] using H,
have : β i β s, f i * g i = 0 := Ξ» i hi, by cases H; simp [H i hi],
have : (β i in s, f i * g i) = (β i in s, 0) := sum_congr rfl this,
simp [this] },
push_neg at H,
by_cases H' : (β i in s, (f i)^p) ^ (1/p) = β€ β¨ (β i in s, (g i)^q) ^ (1/q) = β€,
{ cases H'; simp [H', -one_div, H] },
replace H' : (β i β s, f i β β€) β§ (β i β s, g i β β€),
by simpa [ennreal.rpow_eq_top_iff, asymm hpq.pos, asymm hpq.symm.pos, hpq.pos, hpq.symm.pos,
ennreal.sum_eq_top_iff, not_or_distrib] using H',
have := ennreal.coe_le_coe.2 (@nnreal.inner_le_Lp_mul_Lq _ s (Ξ» i, ennreal.to_nnreal (f i))
(Ξ» i, ennreal.to_nnreal (g i)) _ _ hpq),
simp [β ennreal.coe_rpow_of_nonneg, le_of_lt (hpq.pos), le_of_lt (hpq.one_div_pos),
le_of_lt (hpq.symm.pos), le_of_lt (hpq.symm.one_div_pos)] at this,
convert this using 1;
[skip, congr' 2];
[skip, skip, simp, skip, simp];
{ apply finset.sum_congr rfl (Ξ» i hi, _), simp [H'.1 i hi, H'.2 i hi, -with_zero.coe_mul,
with_top.coe_mul.symm] },
end
/-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal
to the sum of the `L_p`-seminorms of the summands. A version for `ennreal` valued nonnegative
functions. -/
theorem Lp_add_le (hp : 1 β€ p) :
(β i in s, (f i + g i) ^ p)^(1/p) β€ (β i in s, (f i)^p) ^ (1/p) + (β i in s, (g i)^p) ^ (1/p) :=
begin
by_cases H' : (β i in s, (f i)^p) ^ (1/p) = β€ β¨ (β i in s, (g i)^p) ^ (1/p) = β€,
{ cases H'; simp [H', -one_div] },
have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp,
replace H' : (β i β s, f i β β€) β§ (β i β s, g i β β€),
by simpa [ennreal.rpow_eq_top_iff, asymm pos, pos, ennreal.sum_eq_top_iff,
not_or_distrib] using H',
have := ennreal.coe_le_coe.2 (@nnreal.Lp_add_le _ s (Ξ» i, ennreal.to_nnreal (f i))
(Ξ» i, ennreal.to_nnreal (g i)) _ hp),
push_cast [β ennreal.coe_rpow_of_nonneg, le_of_lt (pos), le_of_lt (one_div_pos.2 pos)] at this,
convert this using 2;
[skip, congr' 1, congr' 1];
{ apply finset.sum_congr rfl (Ξ» i hi, _), simp [H'.1 i hi, H'.2 i hi] }
end
end ennreal
section lintegral
/-!
### HΓΆlder's inequality for the Lebesgue integral of ennreal and nnreal functions
We prove `β« (f * g) βΞΌ β€ (β« f^p βΞΌ) ^ (1/p) * (β« g^q βΞΌ) ^ (1/q)` for `p`, `q`
conjugate real exponents and `Ξ±β(e)nnreal` functions in several cases, the first two being useful
only to prove the more general results:
* `ennreal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ennreal functions for which the
integrals on the right are equal to 1,
* `ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ennreal functions for which the
integrals on the right are neither β€ nor 0,
* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ennreal functions,
* `nnreal.lintegral_mul_le_Lp_mul_Lq` : nnreal functions.
-/
open measure_theory
variables {Ξ± : Type*} [measurable_space Ξ±] {ΞΌ : measure Ξ±}
namespace ennreal
lemma lintegral_mul_le_one_of_lintegral_rpow_eq_one {p q : β} (hpq : p.is_conjugate_exponent q)
{f g : Ξ± β ennreal} (hf : measurable f) (hg : measurable g)
(hf_norm : β«β» a, (f a)^p βΞΌ = 1) (hg_norm : β«β» a, (g a)^q βΞΌ = 1) :
β«β» a, (f * g) a βΞΌ β€ 1 :=
begin
calc β«β» (a : Ξ±), ((f * g) a) βΞΌ
β€ β«β» (a : Ξ±), ((f a)^p / ennreal.of_real p + (g a)^q / ennreal.of_real q) βΞΌ :
lintegral_mono (Ξ» a, young_inequality (f a) (g a) hpq)
... = 1 :
begin
simp_rw [div_def],
rw lintegral_add,
{ rw [lintegral_mul_const _ hf.ennreal_rpow_const, lintegral_mul_const _ hg.ennreal_rpow_const,
hf_norm, hg_norm, βennreal.div_def, βennreal.div_def, hpq.inv_add_inv_conj_ennreal], },
{ exact hf.ennreal_rpow_const.ennreal_mul measurable_const, },
{ exact hg.ennreal_rpow_const.ennreal_mul measurable_const, },
end
end
/-- Function multiplied by the inverse of its p-seminorm `(β«β» f^p βΞΌ) ^ 1/p`-/
def fun_mul_inv_snorm (f : Ξ± β ennreal) (p : β) (ΞΌ : measure Ξ±) : Ξ± β ennreal :=
Ξ» a, (f a) * ((β«β» c, (f c) ^ p βΞΌ) ^ (1 / p))β»ΒΉ
lemma fun_eq_fun_mul_inv_snorm_mul_snorm {p : β} (f : Ξ± β ennreal)
(hf_nonzero : β«β» a, (f a) ^ p βΞΌ β 0) (hf_top : β«β» a, (f a) ^ p βΞΌ β β€) {a : Ξ±} :
f a = (fun_mul_inv_snorm f p ΞΌ a) * (β«β» c, (f c)^p βΞΌ)^(1/p) :=
by simp [fun_mul_inv_snorm, mul_assoc, inv_mul_cancel, hf_nonzero, hf_top]
lemma fun_mul_inv_snorm_rpow {p : β} (hp0 : 0 < p) {f : Ξ± β ennreal} {a : Ξ±} :
(fun_mul_inv_snorm f p ΞΌ a) ^ p = (f a)^p * (β«β» c, (f c) ^ p βΞΌ)β»ΒΉ :=
begin
rw [fun_mul_inv_snorm, mul_rpow_of_nonneg _ _ (le_of_lt hp0)],
suffices h_inv_rpow : ((β«β» (c : Ξ±), f c ^ p βΞΌ) ^ (1 / p))β»ΒΉ ^ p = (β«β» (c : Ξ±), f c ^ p βΞΌ)β»ΒΉ,
by rw h_inv_rpow,
rw [inv_rpow_of_pos hp0, βrpow_mul, div_eq_mul_inv, one_mul,
_root_.inv_mul_cancel (ne_of_lt hp0).symm, rpow_one],
end
lemma lintegral_rpow_fun_mul_inv_snorm_eq_one {p : β} (hp0_lt : 0 < p) {f : Ξ± β ennreal}
(hf : measurable f) (hf_nonzero : β«β» a, (f a)^p βΞΌ β 0) (hf_top : β«β» a, (f a)^p βΞΌ β β€) :
β«β» c, (fun_mul_inv_snorm f p ΞΌ c)^p βΞΌ = 1 :=
begin
simp_rw fun_mul_inv_snorm_rpow hp0_lt,
rw [lintegral_mul_const _ hf.ennreal_rpow_const, mul_inv_cancel hf_nonzero hf_top],
end
/-- HΓΆlder's inequality in case of finite non-zero integrals -/
lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {p q : β} (hpq : p.is_conjugate_exponent q)
{f g : Ξ± β ennreal} (hf : measurable f) (hg : measurable g)
(hf_nontop : β«β» a, (f a)^p βΞΌ β β€) (hg_nontop : β«β» a, (g a)^q βΞΌ β β€)
(hf_nonzero : β«β» a, (f a)^p βΞΌ β 0) (hg_nonzero : β«β» a, (g a)^q βΞΌ β 0) :
β«β» a, (f * g) a βΞΌ β€ (β«β» a, (f a)^p βΞΌ)^(1/p) * (β«β» a, (g a)^q βΞΌ)^(1/q) :=
begin
let npf := (β«β» (c : Ξ±), (f c) ^ p βΞΌ) ^ (1/p),
let nqg := (β«β» (c : Ξ±), (g c) ^ q βΞΌ) ^ (1/q),
calc β«β» (a : Ξ±), (f * g) a βΞΌ
= β«β» (a : Ξ±), ((fun_mul_inv_snorm f p ΞΌ * fun_mul_inv_snorm g q ΞΌ) a)
* (npf * nqg) βΞΌ :
begin
refine lintegral_congr (Ξ» a, _),
rw [pi.mul_apply, fun_eq_fun_mul_inv_snorm_mul_snorm f hf_nonzero hf_nontop,
fun_eq_fun_mul_inv_snorm_mul_snorm g hg_nonzero hg_nontop, pi.mul_apply],
ring,
end
... β€ npf * nqg :
begin
rw lintegral_mul_const' (npf * nqg) _ (by simp [hf_nontop, hg_nontop, hf_nonzero, hg_nonzero]),
nth_rewrite 1 βone_mul (npf * nqg),
refine mul_le_mul _ (le_refl (npf * nqg)),
have hf1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.pos hf hf_nonzero hf_nontop,
have hg1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.symm.pos hg hg_nonzero hg_nontop,
exact lintegral_mul_le_one_of_lintegral_rpow_eq_one hpq (hf.ennreal_mul measurable_const)
(hg.ennreal_mul measurable_const) hf1 hg1,
end
end
lemma ae_eq_zero_of_lintegral_rpow_eq_zero {p : β} (hp0_lt : 0 < p) {f : Ξ± β ennreal}
(hf : measurable f) (hf_zero : β«β» a, (f a)^p βΞΌ = 0) :
f =α΅[ΞΌ] 0 :=
begin
rw lintegral_eq_zero_iff hf.ennreal_rpow_const at hf_zero,
refine filter.eventually.mp hf_zero (filter.eventually_of_forall (Ξ» x, _)),
dsimp only,
rw [pi.zero_apply, rpow_eq_zero_iff],
intro hx,
cases hx,
{ exact hx.left, },
{ exfalso,
linarith, },
end
lemma lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {p : β} (hp0_lt : 0 < p)
{f g : Ξ± β ennreal} (hf : measurable f) (hf_zero : β«β» a, (f a)^p βΞΌ = 0) :
β«β» a, (f * g) a βΞΌ = 0 :=
begin
rw β@lintegral_zero_fun Ξ± _ ΞΌ,
refine lintegral_congr_ae _,
suffices h_mul_zero : f * g =α΅[ΞΌ] 0 * g , by rwa zero_mul at h_mul_zero,
have hf_eq_zero : f =α΅[ΞΌ] 0, from ae_eq_zero_of_lintegral_rpow_eq_zero hp0_lt hf hf_zero,
exact filter.eventually_eq.mul hf_eq_zero (ae_eq_refl g),
end
lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {p q : β} (hp0_lt : 0 < p) (hq0 : 0 β€ q)
{f g : Ξ± β ennreal} (hf_top : β«β» a, (f a)^p βΞΌ = β€) (hg_nonzero : β«β» a, (g a)^q βΞΌ β 0) :
β«β» a, (f * g) a βΞΌ β€ (β«β» a, (f a)^p βΞΌ) ^ (1/p) * (β«β» a, (g a)^q βΞΌ) ^ (1/q) :=
begin
refine le_trans le_top (le_of_eq _),
have hp0_inv_lt : 0 < 1/p, by simp [hp0_lt],
rw [hf_top, ennreal.top_rpow_of_pos hp0_inv_lt],
simp [hq0, hg_nonzero],
end
/-- HΓΆlder's inequality for functions `Ξ± β ennreal`. The integral of the product of two functions
is bounded by the product of their `βp` and `βq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem lintegral_mul_le_Lp_mul_Lq (ΞΌ : measure Ξ±) {p q : β} (hpq : p.is_conjugate_exponent q)
{f g : Ξ± β ennreal} (hf : measurable f) (hg : measurable g) :
β«β» a, (f * g) a βΞΌ β€ (β«β» a, (f a)^p βΞΌ) ^ (1/p) * (β«β» a, (g a)^q βΞΌ) ^ (1/q) :=
begin
by_cases hf_zero : β«β» a, (f a) ^ p βΞΌ = 0,
{ refine le_trans (le_of_eq _) (zero_le _),
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.pos hf hf_zero, },
by_cases hg_zero : β«β» a, (g a) ^ q βΞΌ = 0,
{ refine le_trans (le_of_eq _) (zero_le _),
rw mul_comm,
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.symm.pos hg hg_zero, },
by_cases hf_top : β«β» a, (f a) ^ p βΞΌ = β€,
{ exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.pos hpq.symm.nonneg hf_top hg_zero, },
by_cases hg_top : β«β» a, (g a) ^ q βΞΌ = β€,
{ rw [mul_comm, mul_comm ((β«β» (a : Ξ±), (f a) ^ p βΞΌ) ^ (1 / p))],
exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.symm.pos hpq.nonneg hg_top hf_zero, },
-- non-β€ non-zero case
exact ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top hpq hf hg hf_top hg_top hf_zero
hg_zero,
end
lemma lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top {p : β}
{f g : Ξ± β ennreal} (hf : measurable f) (hf_top : β«β» a, (f a) ^ p βΞΌ < β€)
(hg : measurable g) (hg_top : β«β» a, (g a) ^ p βΞΌ < β€) (hp1 : 1 β€ p) :
β«β» a, ((f + g) a) ^ p βΞΌ < β€ :=
begin
have hp0_lt : 0 < p, from lt_of_lt_of_le zero_lt_one hp1,
have hp0 : 0 β€ p, from le_of_lt hp0_lt,
calc β«β» (a : Ξ±), (f a + g a) ^ p βΞΌ
β€ β«β» a, ((2:ennreal)^(p-1) * (f a) ^ p + (2:ennreal)^(p-1) * (g a) ^ p) β ΞΌ :
begin
refine lintegral_mono (Ξ» a, _),
dsimp only,
have h_zero_lt_half_rpow : (0 : ennreal) < (1 / 2) ^ p,
{ rw [βennreal.zero_rpow_of_pos hp0_lt],
exact ennreal.rpow_lt_rpow (by simp [zero_lt_one]) hp0_lt, },
have h_rw : (1 / 2) ^ p * (2:ennreal) ^ (p - 1) = 1 / 2,
{ rw [sub_eq_add_neg, ennreal.rpow_add _ _ ennreal.two_ne_zero ennreal.coe_ne_top,
βmul_assoc, βennreal.mul_rpow_of_nonneg _ _ hp0, ennreal.div_def, one_mul,
ennreal.inv_mul_cancel ennreal.two_ne_zero ennreal.coe_ne_top, ennreal.one_rpow,
one_mul, ennreal.rpow_neg_one], },
rw βennreal.mul_le_mul_left (ne_of_lt h_zero_lt_half_rpow).symm _,
{ rw [mul_add, β mul_assoc, β mul_assoc, h_rw, βennreal.mul_rpow_of_nonneg _ _ hp0, mul_add],
refine ennreal.rpow_arith_mean_le_arith_mean2_rpow (1/2 : ennreal) (1/2 : ennreal)
(f a) (g a) _ hp1,
rw [ennreal.div_add_div_same, one_add_one_eq_two,
ennreal.div_self ennreal.two_ne_zero ennreal.coe_ne_top], },
{ rw βennreal.lt_top_iff_ne_top,
refine ennreal.rpow_lt_top_of_nonneg hp0 _,
rw [ennreal.div_def, one_mul, ennreal.inv_ne_top],
exact ennreal.two_ne_zero, },
end
... < β€ :
begin
rw [lintegral_add, lintegral_const_mul _ hf.ennreal_rpow_const,
lintegral_const_mul _ hg.ennreal_rpow_const, ennreal.add_lt_top],
{ have h_two : (2 : ennreal) ^ (p - 1) < β€,
from ennreal.rpow_lt_top_of_nonneg (by simp [hp1]) ennreal.coe_ne_top,
repeat {rw ennreal.mul_lt_top_iff},
simp [hf_top, hg_top, h_two], },
{ exact (ennreal.continuous_const_mul (by simp)).measurable.comp hf.ennreal_rpow_const, },
{ exact (ennreal.continuous_const_mul (by simp)).measurable.comp hg.ennreal_rpow_const },
end
end
lemma lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow {p q : β}
(hpq : p.is_conjugate_exponent q) {f g : Ξ± β ennreal} (hf : measurable f) (hg : measurable g)
(hf_top : β«β» a, (f a) ^ p βΞΌ β β€) :
β«β» a, (f a) * (g a) ^ (p - 1) βΞΌ β€ (β«β» a, (f a)^p βΞΌ) ^ (1/p) * (β«β» a, (g a)^p βΞΌ) ^ (1/q) :=
begin
refine le_trans (ennreal.lintegral_mul_le_Lp_mul_Lq ΞΌ hpq hf hg.ennreal_rpow_const) _,
by_cases hf_zero_rpow : (β«β» (a : Ξ±), (f a) ^ p βΞΌ) ^ (1 / p) = 0,
{ rw [hf_zero_rpow, zero_mul],
exact zero_le _, },
have hf_top_rpow : (β«β» (a : Ξ±), (f a) ^ p βΞΌ) ^ (1 / p) β β€,
{ by_contra h,
push_neg at h,
refine hf_top _,
have hp_not_neg : Β¬ p < 0, by simp [hpq.nonneg],
simpa [hpq.pos, hp_not_neg] using h, },
refine (ennreal.mul_le_mul_left hf_zero_rpow hf_top_rpow).mpr (le_of_eq _),
congr,
ext1 a,
rw [βennreal.rpow_mul, hpq.sub_one_mul_conj],
end
lemma lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add {p q : β}
(hpq : p.is_conjugate_exponent q) {f g : Ξ± β ennreal} (hf : measurable f)
(hf_top : β«β» a, (f a) ^ p βΞΌ β β€) (hg : measurable g) (hg_top : β«β» a, (g a) ^ p βΞΌ β β€) :
β«β» a, ((f + g) a)^p β ΞΌ
β€ ((β«β» a, (f a)^p βΞΌ) ^ (1/p) + (β«β» a, (g a)^p βΞΌ) ^ (1/p))
* (β«β» a, (f a + g a)^p βΞΌ) ^ (1/q) :=
begin
calc β«β» a, ((f+g) a) ^ p βΞΌ β€ β«β» a, ((f + g) a) * ((f + g) a) ^ (p - 1) βΞΌ :
begin
refine lintegral_mono (Ξ» a, _),
dsimp only,
by_cases h_zero : (f + g) a = 0,
{ rw [h_zero, ennreal.zero_rpow_of_pos hpq.pos],
exact zero_le _, },
by_cases h_top : (f + g) a = β€,
{ rw [h_top, ennreal.top_rpow_of_pos hpq.sub_one_pos, ennreal.top_mul_top],
exact le_top, },
refine le_of_eq _,
nth_rewrite 1 βennreal.rpow_one ((f + g) a),
rw [βennreal.rpow_add _ _ h_zero h_top, add_sub_cancel'_right],
end
... = β«β» (a : Ξ±), f a * (f + g) a ^ (p - 1) βΞΌ + β«β» (a : Ξ±), g a * (f + g) a ^ (p - 1) βΞΌ :
begin
have h_add_m : measurable (Ξ» (a : Ξ±), ((f + g) a) ^ (p-1)), from (hf.add hg).ennreal_rpow_const,
have h_add_apply : β«β» (a : Ξ±), (f + g) a * (f + g) a ^ (p - 1) βΞΌ
= β«β» (a : Ξ±), (f a + g a) * (f + g) a ^ (p - 1) βΞΌ,
from rfl,
simp_rw [h_add_apply, add_mul],
rw lintegral_add (hf.ennreal_mul h_add_m) (hg.ennreal_mul h_add_m),
end
... β€ ((β«β» a, (f a)^p βΞΌ) ^ (1/p) + (β«β» a, (g a)^p βΞΌ) ^ (1/p))
* (β«β» a, (f a + g a)^p βΞΌ) ^ (1/q) :
begin
rw add_mul,
exact add_le_add
(lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hf (hf.add hg) hf_top)
(lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hg (hf.add hg) hg_top),
end
end
private lemma lintegral_Lp_add_le_aux {p q : β}
(hpq : p.is_conjugate_exponent q) {f g : Ξ± β ennreal} (hf : measurable f)
(hf_top : β«β» a, (f a) ^ p βΞΌ β β€) (hg : measurable g) (hg_top : β«β» a, (g a) ^ p βΞΌ β β€)
(h_add_zero : β«β» a, ((f+g) a) ^ p β ΞΌ β 0) (h_add_top : β«β» a, ((f+g) a) ^ p β ΞΌ β β€) :
(β«β» a, ((f + g) a)^p β ΞΌ) ^ (1/p) β€ (β«β» a, (f a)^p βΞΌ) ^ (1/p) + (β«β» a, (g a)^p βΞΌ) ^ (1/p) :=
begin
have hp_not_nonpos : Β¬ p β€ 0, by simp [hpq.pos],
have htop_rpow : (β«β» a, ((f+g) a) ^ p βΞΌ)^(1/p) β β€,
{ by_contra h,
push_neg at h,
exact h_add_top (@ennreal.rpow_eq_top_of_nonneg _ (1/p) (by simp [hpq.nonneg]) h), },
have h0_rpow : (β«β» a, ((f+g) a) ^ p β ΞΌ) ^ (1/p) β 0,
by simp [h_add_zero, h_add_top, hpq.nonneg, hp_not_nonpos, -pi.add_apply],
suffices h : 1 β€ (β«β» (a : Ξ±), ((f+g) a)^p βΞΌ) ^ -(1/p)
* ((β«β» (a : Ξ±), (f a)^p βΞΌ) ^ (1/p) + (β«β» (a : Ξ±), (g a)^p βΞΌ) ^ (1/p)),
by rwa [βmul_le_mul_left h0_rpow htop_rpow, βmul_assoc, βrpow_add _ _ h_add_zero h_add_top,
βsub_eq_add_neg, _root_.sub_self, rpow_zero, one_mul, mul_one] at h,
have h : β«β» (a : Ξ±), ((f+g) a)^p βΞΌ
β€ ((β«β» (a : Ξ±), (f a)^p βΞΌ) ^ (1/p) + (β«β» (a : Ξ±), (g a)^p βΞΌ) ^ (1/p))
* (β«β» (a : Ξ±), ((f+g) a)^p βΞΌ) ^ (1/q),
from lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add hpq hf hf_top hg hg_top,
have h_one_div_q : 1/q = 1 - 1/p, by { nth_rewrite 1 βhpq.inv_add_inv_conj, ring, },
simp_rw [h_one_div_q, sub_eq_add_neg 1 (1/p), ennreal.rpow_add _ _ h_add_zero h_add_top,
rpow_one] at h,
nth_rewrite 1 mul_comm at h,
nth_rewrite 0 βone_mul (β«β» (a : Ξ±), ((f+g) a) ^ p βΞΌ) at h,
rwa [βmul_assoc, ennreal.mul_le_mul_right h_add_zero h_add_top, mul_comm] at h,
end
/-- Minkowski's inequality for functions `Ξ± β ennreal`: the `βp` seminorm of the sum of two
functions is bounded by the sum of their `βp` seminorms. -/
theorem lintegral_Lp_add_le {p : β} {f g : Ξ± β ennreal}
(hf : measurable f) (hg : measurable g) (hp1 : 1 β€ p) :
(β«β» a, ((f + g) a)^p β ΞΌ) ^ (1/p) β€ (β«β» a, (f a)^p βΞΌ) ^ (1/p) + (β«β» a, (g a)^p βΞΌ) ^ (1/p) :=
begin
have hp_pos : 0 < p, from lt_of_lt_of_le zero_lt_one hp1,
by_cases hf_top : β«β» a, (f a) ^ p βΞΌ = β€,
{ simp [hf_top, hp_pos], },
by_cases hg_top : β«β» a, (g a) ^ p βΞΌ = β€,
{ simp [hg_top, hp_pos], },
by_cases h1 : p = 1,
{ refine le_of_eq _,
simp_rw [h1, one_div_one, ennreal.rpow_one],
exact lintegral_add hf hg, },
have hp1_lt : 1 < p, by { refine lt_of_le_of_ne hp1 _, symmetry, exact h1, },
have hpq := real.is_conjugate_exponent_conjugate_exponent hp1_lt,
by_cases h0 : β«β» a, ((f+g) a) ^ p β ΞΌ = 0,
{ rw [h0, @ennreal.zero_rpow_of_pos (1/p) (by simp [lt_of_lt_of_le zero_lt_one hp1])],
exact zero_le _, },
have htop : β«β» a, ((f+g) a) ^ p β ΞΌ β β€,
{ rw βne.def at hf_top hg_top,
rw βennreal.lt_top_iff_ne_top at hf_top hg_top β’,
exact lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top hf hf_top hg hg_top hp1, },
exact lintegral_Lp_add_le_aux hpq hf hf_top hg hg_top h0 htop,
end
end ennreal
/-- HΓΆlder's inequality for functions `Ξ± β ββ₯0`. The integral of the product of two functions
is bounded by the product of their `βp` and `βq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem nnreal.lintegral_mul_le_Lp_mul_Lq {p q : β} (hpq : p.is_conjugate_exponent q)
{f g : Ξ± β ββ₯0} (hf : measurable f) (hg : measurable g) :
β«β» a, (f * g) a βΞΌ β€ (β«β» a, (f a)^p βΞΌ)^(1/p) * (β«β» a, (g a)^q βΞΌ)^(1/q) :=
begin
simp_rw [pi.mul_apply, ennreal.coe_mul],
exact ennreal.lintegral_mul_le_Lp_mul_Lq ΞΌ hpq hf.ennreal_coe hg.ennreal_coe,
end
end lintegral
|
7df24fc41e858568046835f7a47511a8e8880852
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/find.lean
|
057dd4b3da4a4829b253787d4015ea144f4f36f9
|
[
"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
| 48
|
lean
|
import find.
find "^.ongr"
find "foo"
find "(ab"
|
f6b94d8dc9116dc4c24b8124f4d49971625e5d6c
|
2eab05920d6eeb06665e1a6df77b3157354316ad
|
/src/linear_algebra/prod.lean
|
d833f33a69a4fb619ee163366505e04927b78c5a
|
[
"Apache-2.0"
] |
permissive
|
ayush1801/mathlib
|
78949b9f789f488148142221606bf15c02b960d2
|
ce164e28f262acbb3de6281b3b03660a9f744e3c
|
refs/heads/master
| 1,692,886,907,941
| 1,635,270,866,000
| 1,635,270,866,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 25,510
|
lean
|
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser
-/
import linear_algebra.basic
import order.partial_sups
/-! ### Products of modules
This file defines constructors for linear maps whose domains or codomains are products.
It contains theorems relating these to each other, as well as to `submodule.prod`, `submodule.map`,
`submodule.comap`, `linear_map.range`, and `linear_map.ker`.
## Main definitions
- products in the domain:
- `linear_map.fst`
- `linear_map.snd`
- `linear_map.coprod`
- `linear_map.prod_ext`
- products in the codomain:
- `linear_map.inl`
- `linear_map.inr`
- `linear_map.prod`
- products in both domain and codomain:
- `linear_map.prod_map`
- `linear_equiv.prod_map`
- `linear_equiv.skew_prod`
-/
universes u v w x y z u' v' w' y'
variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {Mβ : Type w} {Vβ : Type w'}
variables {Mβ : Type y} {Vβ : Type y'} {Mβ : Type z} {ΞΉ : Type x}
section prod
namespace linear_map
variables (S : Type*) [semiring R] [semiring S]
variables [add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
variables [module R M] [module R Mβ] [module R Mβ] [module R Mβ]
variables (f : M ββ[R] Mβ)
section
variables (R M Mβ)
/-- The first projection of a product is a linear map. -/
def fst : M Γ Mβ ββ[R] M := { to_fun := prod.fst, map_add' := Ξ» x y, rfl, map_smul' := Ξ» x y, rfl }
/-- The second projection of a product is a linear map. -/
def snd : M Γ Mβ ββ[R] Mβ := { to_fun := prod.snd, map_add' := Ξ» x y, rfl, map_smul' := Ξ» x y, rfl }
end
@[simp] theorem fst_apply (x : M Γ Mβ) : fst R M Mβ x = x.1 := rfl
@[simp] theorem snd_apply (x : M Γ Mβ) : snd R M Mβ x = x.2 := rfl
theorem fst_surjective : function.surjective (fst R M Mβ) := Ξ» x, β¨(x, 0), rflβ©
theorem snd_surjective : function.surjective (snd R M Mβ) := Ξ» x, β¨(0, x), rflβ©
/-- The prod of two linear maps is a linear map. -/
@[simps] def prod (f : M ββ[R] Mβ) (g : M ββ[R] Mβ) : (M ββ[R] Mβ Γ Mβ) :=
{ to_fun := Ξ» x, (f x, g x),
map_add' := Ξ» x y, by simp only [prod.mk_add_mk, map_add],
map_smul' := Ξ» c x, by simp only [prod.smul_mk, map_smul, ring_hom.id_apply] }
@[simp] theorem fst_prod (f : M ββ[R] Mβ) (g : M ββ[R] Mβ) :
(fst R Mβ Mβ).comp (prod f g) = f := by ext; refl
@[simp] theorem snd_prod (f : M ββ[R] Mβ) (g : M ββ[R] Mβ) :
(snd R Mβ Mβ).comp (prod f g) = g := by ext; refl
@[simp] theorem pair_fst_snd : prod (fst R M Mβ) (snd R M Mβ) = linear_map.id :=
by ext; refl
/-- Taking the product of two maps with the same domain is equivalent to taking the product of
their codomains.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps] def prod_equiv
[module S Mβ] [module S Mβ] [smul_comm_class R S Mβ] [smul_comm_class R S Mβ] :
((M ββ[R] Mβ) Γ (M ββ[R] Mβ)) ββ[S] (M ββ[R] Mβ Γ Mβ) :=
{ to_fun := Ξ» f, f.1.prod f.2,
inv_fun := Ξ» f, ((fst _ _ _).comp f, (snd _ _ _).comp f),
left_inv := Ξ» f, by ext; refl,
right_inv := Ξ» f, by ext; refl,
map_add' := Ξ» a b, rfl,
map_smul' := Ξ» r a, rfl }
section
variables (R M Mβ)
/-- The left injection into a product is a linear map. -/
def inl : M ββ[R] M Γ Mβ := prod linear_map.id 0
/-- The right injection into a product is a linear map. -/
def inr : Mβ ββ[R] M Γ Mβ := prod 0 linear_map.id
theorem range_inl : range (inl R M Mβ) = ker (snd R M Mβ) :=
begin
ext x,
simp only [mem_ker, mem_range],
split,
{ rintros β¨y, rflβ©, refl },
{ intro h, exact β¨x.fst, prod.ext rfl h.symmβ© }
end
theorem ker_snd : ker (snd R M Mβ) = range (inl R M Mβ) :=
eq.symm $ range_inl R M Mβ
theorem range_inr : range (inr R M Mβ) = ker (fst R M Mβ) :=
begin
ext x,
simp only [mem_ker, mem_range],
split,
{ rintros β¨y, rflβ©, refl },
{ intro h, exact β¨x.snd, prod.ext h.symm rflβ© }
end
theorem ker_fst : ker (fst R M Mβ) = range (inr R M Mβ) :=
eq.symm $ range_inr R M Mβ
end
@[simp] theorem coe_inl : (inl R M Mβ : M β M Γ Mβ) = Ξ» x, (x, 0) := rfl
theorem inl_apply (x : M) : inl R M Mβ x = (x, 0) := rfl
@[simp] theorem coe_inr : (inr R M Mβ : Mβ β M Γ Mβ) = prod.mk 0 := rfl
theorem inr_apply (x : Mβ) : inr R M Mβ x = (0, x) := rfl
theorem inl_eq_prod : inl R M Mβ = prod linear_map.id 0 := rfl
theorem inr_eq_prod : inr R M Mβ = prod 0 linear_map.id := rfl
theorem inl_injective : function.injective (inl R M Mβ) :=
Ξ» _, by simp
theorem inr_injective : function.injective (inr R M Mβ) :=
Ξ» _, by simp
/-- The coprod function `Ξ» x : M Γ Mβ, f.1 x.1 + f.2 x.2` is a linear map. -/
def coprod (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) : M Γ Mβ ββ[R] Mβ :=
f.comp (fst _ _ _) + g.comp (snd _ _ _)
@[simp] theorem coprod_apply (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) (x : M Γ Mβ) :
coprod f g x = f x.1 + g x.2 := rfl
@[simp] theorem coprod_inl (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
(coprod f g).comp (inl R M Mβ) = f :=
by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply]
@[simp] theorem coprod_inr (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
(coprod f g).comp (inr R M Mβ) = g :=
by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply]
@[simp] theorem coprod_inl_inr : coprod (inl R M Mβ) (inr R M Mβ) = linear_map.id :=
by ext; simp only [prod.mk_add_mk, add_zero, id_apply, coprod_apply,
inl_apply, inr_apply, zero_add]
theorem comp_coprod (f : Mβ ββ[R] Mβ) (gβ : M ββ[R] Mβ) (gβ : Mβ ββ[R] Mβ) :
f.comp (gβ.coprod gβ) = (f.comp gβ).coprod (f.comp gβ) :=
ext $ Ξ» x, f.map_add (gβ x.1) (gβ x.2)
theorem fst_eq_coprod : fst R M Mβ = coprod linear_map.id 0 := by ext; simp
theorem snd_eq_coprod : snd R M Mβ = coprod 0 linear_map.id := by ext; simp
@[simp] theorem coprod_comp_prod (f : Mβ ββ[R] Mβ) (g : Mβ ββ[R] Mβ)
(f' : M ββ[R] Mβ) (g' : M ββ[R] Mβ) :
(f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' :=
rfl
@[simp]
lemma coprod_map_prod (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) (S : submodule R M)
(S' : submodule R Mβ) :
(submodule.prod S S').map (linear_map.coprod f g) = S.map f β S'.map g :=
set_like.coe_injective $ begin
simp only [linear_map.coprod_apply, submodule.coe_sup, submodule.map_coe],
rw [βset.image2_add, set.image2_image_left, set.image2_image_right],
exact set.image_prod (Ξ» m mβ, f m + g mβ),
end
/-- Taking the product of two maps with the same codomain is equivalent to taking the product of
their domains.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps] def coprod_equiv [module S Mβ] [smul_comm_class R S Mβ] :
((M ββ[R] Mβ) Γ (Mβ ββ[R] Mβ)) ββ[S] (M Γ Mβ ββ[R] Mβ) :=
{ to_fun := Ξ» f, f.1.coprod f.2,
inv_fun := Ξ» f, (f.comp (inl _ _ _), f.comp (inr _ _ _)),
left_inv := Ξ» f, by simp only [prod.mk.eta, coprod_inl, coprod_inr],
right_inv := Ξ» f, by simp only [βcomp_coprod, comp_id, coprod_inl_inr],
map_add' := Ξ» a b,
by { ext, simp only [prod.snd_add, add_apply, coprod_apply, prod.fst_add], ac_refl },
map_smul' := Ξ» r a,
by { dsimp, ext, simp only [smul_add, smul_apply, prod.smul_snd, prod.smul_fst,
coprod_apply] } }
theorem prod_ext_iff {f g : M Γ Mβ ββ[R] Mβ} :
f = g β f.comp (inl _ _ _) = g.comp (inl _ _ _) β§ f.comp (inr _ _ _) = g.comp (inr _ _ _) :=
(coprod_equiv β).symm.injective.eq_iff.symm.trans prod.ext_iff
/--
Split equality of linear maps from a product into linear maps over each component, to allow `ext`
to apply lemmas specific to `M ββ Mβ` and `Mβ ββ Mβ`.
See note [partially-applied ext lemmas]. -/
@[ext] theorem prod_ext {f g : M Γ Mβ ββ[R] Mβ}
(hl : f.comp (inl _ _ _) = g.comp (inl _ _ _))
(hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) :
f = g :=
prod_ext_iff.2 β¨hl, hrβ©
/-- `prod.map` of two linear maps. -/
def prod_map (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) : (M Γ Mβ) ββ[R] (Mβ Γ Mβ) :=
(f.comp (fst R M Mβ)).prod (g.comp (snd R M Mβ))
@[simp] theorem prod_map_apply (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) (x) :
f.prod_map g x = (f x.1, g x.2) := rfl
lemma prod_map_comap_prod (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) (S : submodule R Mβ)
(S' : submodule R Mβ) :
(submodule.prod S S').comap (linear_map.prod_map f g) = (S.comap f).prod (S'.comap g) :=
set_like.coe_injective $ set.preimage_prod_map_prod f g _ _
lemma ker_prod_map (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
(linear_map.prod_map f g).ker = submodule.prod f.ker g.ker :=
begin
dsimp only [ker],
rw [βprod_map_comap_prod, submodule.prod_bot],
end
section map_mul
variables {A : Type*} [non_unital_non_assoc_semiring A] [module R A]
variables {B : Type*} [non_unital_non_assoc_semiring B] [module R B]
lemma inl_map_mul (aβ aβ : A) : linear_map.inl R A B (aβ * aβ) =
linear_map.inl R A B aβ * linear_map.inl R A B aβ :=
prod.ext rfl (by simp)
lemma inr_map_mul (bβ bβ : B) : linear_map.inr R A B (bβ * bβ) =
linear_map.inr R A B bβ * linear_map.inr R A B bβ :=
prod.ext (by simp) rfl
end map_mul
end linear_map
end prod
namespace linear_map
open submodule
variables [semiring R]
[add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
[module R M] [module R Mβ] [module R Mβ] [module R Mβ]
lemma range_coprod (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
(f.coprod g).range = f.range β g.range :=
submodule.ext $ Ξ» x, by simp [mem_sup]
lemma is_compl_range_inl_inr : is_compl (inl R M Mβ).range (inr R M Mβ).range :=
begin
split,
{ rintros β¨_, _β© β¨β¨x, hxβ©, β¨y, hyβ©β©,
simp only [prod.ext_iff, inl_apply, inr_apply, mem_bot] at hx hy β’,
exact β¨hy.1.symm, hx.2.symmβ© },
{ rintros β¨x, yβ© -,
simp only [mem_sup, mem_range, exists_prop],
refine β¨(x, 0), β¨x, rflβ©, (0, y), β¨y, rflβ©, _β©,
simp }
end
lemma sup_range_inl_inr : (inl R M Mβ).range β (inr R M Mβ).range = β€ :=
is_compl_range_inl_inr.sup_eq_top
lemma disjoint_inl_inr : disjoint (inl R M Mβ).range (inr R M Mβ).range :=
by simp [disjoint_def, @eq_comm M 0, @eq_comm Mβ 0] {contextual := tt}; intros; refl
theorem map_coprod_prod (f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ)
(p : submodule R M) (q : submodule R Mβ) :
map (coprod f g) (p.prod q) = map f p β map g q :=
begin
refine le_antisymm _ (sup_le (map_le_iff_le_comap.2 _) (map_le_iff_le_comap.2 _)),
{ rw set_like.le_def, rintro _ β¨x, β¨hβ, hββ©, rflβ©,
exact mem_sup.2 β¨_, β¨_, hβ, rflβ©, _, β¨_, hβ, rflβ©, rflβ© },
{ exact Ξ» x hx, β¨(x, 0), by simp [hx]β© },
{ exact Ξ» x hx, β¨(0, x), by simp [hx]β© }
end
theorem comap_prod_prod (f : M ββ[R] Mβ) (g : M ββ[R] Mβ)
(p : submodule R Mβ) (q : submodule R Mβ) :
comap (prod f g) (p.prod q) = comap f p β comap g q :=
submodule.ext $ Ξ» x, iff.rfl
theorem prod_eq_inf_comap (p : submodule R M) (q : submodule R Mβ) :
p.prod q = p.comap (linear_map.fst R M Mβ) β q.comap (linear_map.snd R M Mβ) :=
submodule.ext $ Ξ» x, iff.rfl
theorem prod_eq_sup_map (p : submodule R M) (q : submodule R Mβ) :
p.prod q = p.map (linear_map.inl R M Mβ) β q.map (linear_map.inr R M Mβ) :=
by rw [β map_coprod_prod, coprod_inl_inr, map_id]
lemma span_inl_union_inr {s : set M} {t : set Mβ} :
span R (inl R M Mβ '' s βͺ inr R M Mβ '' t) = (span R s).prod (span R t) :=
by rw [span_union, prod_eq_sup_map, β span_image, β span_image]
@[simp] lemma ker_prod (f : M ββ[R] Mβ) (g : M ββ[R] Mβ) :
ker (prod f g) = ker f β ker g :=
by rw [ker, β prod_bot, comap_prod_prod]; refl
lemma range_prod_le (f : M ββ[R] Mβ) (g : M ββ[R] Mβ) :
range (prod f g) β€ (range f).prod (range g) :=
begin
simp only [set_like.le_def, prod_apply, mem_range, set_like.mem_coe, mem_prod,
exists_imp_distrib],
rintro _ x rfl,
exact β¨β¨x, rflβ©, β¨x, rflβ©β©
end
lemma ker_prod_ker_le_ker_coprod {Mβ : Type*} [add_comm_group Mβ] [module R Mβ]
{Mβ : Type*} [add_comm_group Mβ] [module R Mβ]
(f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
(ker f).prod (ker g) β€ ker (f.coprod g) :=
by { rintros β¨y, zβ©, simp {contextual := tt} }
lemma ker_coprod_of_disjoint_range {Mβ : Type*} [add_comm_group Mβ] [module R Mβ]
{Mβ : Type*} [add_comm_group Mβ] [module R Mβ]
(f : M ββ[R] Mβ) (g : Mβ ββ[R] Mβ) (hd : disjoint f.range g.range) :
ker (f.coprod g) = (ker f).prod (ker g) :=
begin
apply le_antisymm _ (ker_prod_ker_le_ker_coprod f g),
rintros β¨y, zβ© h,
simp only [mem_ker, mem_prod, coprod_apply] at h β’,
have : f y β f.range β g.range,
{ simp only [true_and, mem_range, mem_inf, exists_apply_eq_apply],
use -z,
rwa [eq_comm, map_neg, β sub_eq_zero, sub_neg_eq_add] },
rw [hd.eq_bot, mem_bot] at this,
rw [this] at h,
simpa [this] using h,
end
end linear_map
namespace submodule
open linear_map
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid Mβ]
variables [module R M] [module R Mβ]
lemma sup_eq_range (p q : submodule R M) : p β q = (p.subtype.coprod q.subtype).range :=
submodule.ext $ Ξ» x, by simp [submodule.mem_sup, set_like.exists]
variables (p : submodule R M) (q : submodule R Mβ)
@[simp] theorem map_inl : p.map (inl R M Mβ) = prod p β₯ :=
by { ext β¨x, yβ©, simp only [and.left_comm, eq_comm, mem_map, prod.mk.inj_iff, inl_apply, mem_bot,
exists_eq_left', mem_prod] }
@[simp] theorem map_inr : q.map (inr R M Mβ) = prod β₯ q :=
by ext β¨x, yβ©; simp [and.left_comm, eq_comm]
@[simp] theorem comap_fst : p.comap (fst R M Mβ) = prod p β€ :=
by ext β¨x, yβ©; simp
@[simp] theorem comap_snd : q.comap (snd R M Mβ) = prod β€ q :=
by ext β¨x, yβ©; simp
@[simp] theorem prod_comap_inl : (prod p q).comap (inl R M Mβ) = p := by ext; simp
@[simp] theorem prod_comap_inr : (prod p q).comap (inr R M Mβ) = q := by ext; simp
@[simp] theorem prod_map_fst : (prod p q).map (fst R M Mβ) = p :=
by ext x; simp [(β¨0, zero_mem _β© : β x, x β q)]
@[simp] theorem prod_map_snd : (prod p q).map (snd R M Mβ) = q :=
by ext x; simp [(β¨0, zero_mem _β© : β x, x β p)]
@[simp] theorem ker_inl : (inl R M Mβ).ker = β₯ :=
by rw [ker, β prod_bot, prod_comap_inl]
@[simp] theorem ker_inr : (inr R M Mβ).ker = β₯ :=
by rw [ker, β prod_bot, prod_comap_inr]
@[simp] theorem range_fst : (fst R M Mβ).range = β€ :=
by rw [range_eq_map, β prod_top, prod_map_fst]
@[simp] theorem range_snd : (snd R M Mβ).range = β€ :=
by rw [range_eq_map, β prod_top, prod_map_snd]
variables (R M Mβ)
/-- `M` as a submodule of `M Γ N`. -/
def fst : submodule R (M Γ Mβ) := (β₯ : submodule R Mβ).comap (linear_map.snd R M Mβ)
/-- `M` as a submodule of `M Γ N` is isomorphic to `M`. -/
@[simps] def fst_equiv : submodule.fst R M Mβ ββ[R] M :=
{ to_fun := Ξ» x, x.1.1,
inv_fun := Ξ» m, β¨β¨m, 0β©, by tidyβ©,
map_add' := by simp,
map_smul' := by simp,
left_inv := by tidy,
right_inv := by tidy, }
lemma fst_map_fst : (submodule.fst R M Mβ).map (linear_map.fst R M Mβ) = β€ :=
by tidy
lemma fst_map_snd : (submodule.fst R M Mβ).map (linear_map.snd R M Mβ) = β₯ :=
by { tidy, exact 0, }
/-- `N` as a submodule of `M Γ N`. -/
def snd : submodule R (M Γ Mβ) := (β₯ : submodule R M).comap (linear_map.fst R M Mβ)
/-- `N` as a submodule of `M Γ N` is isomorphic to `N`. -/
@[simps] def snd_equiv : submodule.snd R M Mβ ββ[R] Mβ :=
{ to_fun := Ξ» x, x.1.2,
inv_fun := Ξ» n, β¨β¨0, nβ©, by tidyβ©,
map_add' := by simp,
map_smul' := by simp,
left_inv := by tidy,
right_inv := by tidy, }
lemma snd_map_fst : (submodule.snd R M Mβ).map (linear_map.fst R M Mβ) = β₯ :=
by { tidy, exact 0, }
lemma snd_map_snd : (submodule.snd R M Mβ).map (linear_map.snd R M Mβ) = β€ :=
by tidy
lemma fst_sup_snd : submodule.fst R M Mβ β submodule.snd R M Mβ = β€ :=
begin
rw eq_top_iff,
rintro β¨m, nβ© -,
rw [show (m, n) = (m, 0) + (0, n), by simp],
apply submodule.add_mem (submodule.fst R M Mβ β submodule.snd R M Mβ),
{ exact submodule.mem_sup_left (submodule.mem_comap.mpr (by simp)), },
{ exact submodule.mem_sup_right (submodule.mem_comap.mpr (by simp)), },
end
lemma fst_inf_snd : submodule.fst R M Mβ β submodule.snd R M Mβ = β₯ := by tidy
end submodule
namespace linear_equiv
section
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_monoid Mβ]
variables {module_M : module R M} {module_Mβ : module R Mβ}
variables {module_Mβ : module R Mβ} {module_Mβ : module R Mβ}
variables (eβ : M ββ[R] Mβ) (eβ : Mβ ββ[R] Mβ)
/-- Product of linear equivalences; the maps come from `equiv.prod_congr`. -/
protected def prod :
(M Γ Mβ) ββ[R] (Mβ Γ Mβ) :=
{ map_add' := Ξ» x y, prod.ext (eβ.map_add _ _) (eβ.map_add _ _),
map_smul' := Ξ» c x, prod.ext (eβ.map_smulββ c _) (eβ.map_smulββ c _),
.. equiv.prod_congr eβ.to_equiv eβ.to_equiv }
lemma prod_symm : (eβ.prod eβ).symm = eβ.symm.prod eβ.symm := rfl
@[simp] lemma prod_apply (p) :
eβ.prod eβ p = (eβ p.1, eβ p.2) := rfl
@[simp, norm_cast] lemma coe_prod :
(eβ.prod eβ : (M Γ Mβ) ββ[R] (Mβ Γ Mβ)) = (eβ : M ββ[R] Mβ).prod_map (eβ : Mβ ββ[R] Mβ) := rfl
end
section
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_group Mβ]
variables {module_M : module R M} {module_Mβ : module R Mβ}
variables {module_Mβ : module R Mβ} {module_Mβ : module R Mβ}
variables (eβ : M ββ[R] Mβ) (eβ : Mβ ββ[R] Mβ)
/-- Equivalence given by a block lower diagonal matrix. `eβ` and `eβ` are diagonal square blocks,
and `f` is a rectangular block below the diagonal. -/
protected def skew_prod (f : M ββ[R] Mβ) :
(M Γ Mβ) ββ[R] Mβ Γ Mβ :=
{ inv_fun := Ξ» p : Mβ Γ Mβ, (eβ.symm p.1, eβ.symm (p.2 - f (eβ.symm p.1))),
left_inv := Ξ» p, by simp,
right_inv := Ξ» p, by simp,
.. ((eβ : M ββ[R] Mβ).comp (linear_map.fst R M Mβ)).prod
((eβ : Mβ ββ[R] Mβ).comp (linear_map.snd R M Mβ) +
f.comp (linear_map.fst R M Mβ)) }
@[simp] lemma skew_prod_apply (f : M ββ[R] Mβ) (x) :
eβ.skew_prod eβ f x = (eβ x.1, eβ x.2 + f x.1) := rfl
@[simp] lemma skew_prod_symm_apply (f : M ββ[R] Mβ) (x) :
(eβ.skew_prod eβ f).symm x = (eβ.symm x.1, eβ.symm (x.2 - f (eβ.symm x.1))) := rfl
end
end linear_equiv
namespace linear_map
open submodule
variables [ring R]
variables [add_comm_group M] [add_comm_group Mβ] [add_comm_group Mβ]
variables [module R M] [module R Mβ] [module R Mβ]
/-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of
`prod f g` is equal to the product of `range f` and `range g`. -/
lemma range_prod_eq {f : M ββ[R] Mβ} {g : M ββ[R] Mβ} (h : ker f β ker g = β€) :
range (prod f g) = (range f).prod (range g) :=
begin
refine le_antisymm (f.range_prod_le g) _,
simp only [set_like.le_def, prod_apply, mem_range, set_like.mem_coe, mem_prod, exists_imp_distrib,
and_imp, prod.forall],
rintros _ _ x rfl y rfl,
simp only [prod.mk.inj_iff, β sub_mem_ker_iff],
have : y - x β ker f β ker g, { simp only [h, mem_top] },
rcases mem_sup.1 this with β¨x', hx', y', hy', Hβ©,
refine β¨x' + x, _, _β©,
{ rwa add_sub_cancel },
{ rwa [β eq_sub_iff_add_eq.1 H, add_sub_add_right_eq_sub, β neg_mem_iff, neg_sub,
add_sub_cancel'] }
end
end linear_map
namespace linear_map
/-!
## Tunnels and tailings
Some preliminary work for establishing the strong rank condition for noetherian rings.
Given a morphism `f : M Γ N ββ[R] M` which is `i : injective f`,
we can find an infinite decreasing `tunnel f i n` of copies of `M` inside `M`,
and sitting beside these, an infinite sequence of copies of `N`.
We picturesquely name these as `tailing f i n` for each individual copy of `N`,
and `tailings f i n` for the supremum of the first `n+1` copies:
they are the pieces left behind, sitting inside the tunnel.
By construction, each `tailing f i (n+1)` is disjoint from `tailings f i n`;
later, when we assume `M` is noetherian, this implies that `N` must be trivial,
and establishes the strong rank condition for any left-noetherian ring.
-/
section tunnel
-- (This doesn't work over a semiring: we need to use that `submodule R M` is a modular lattice,
-- which requires cancellation.)
variables [ring R]
variables {N : Type*} [add_comm_group M] [module R M] [add_comm_group N] [module R N]
open function
/-- An auxiliary construction for `tunnel`.
The composition of `f`, followed by the isomorphism back to `K`,
followed by the inclusion of this submodule back into `M`. -/
def tunnel_aux (f : M Γ N ββ[R] M) (KΟ : Ξ£ K : submodule R M, K ββ[R] M) :
M Γ N ββ[R] M :=
(KΟ.1.subtype.comp KΟ.2.symm.to_linear_map).comp f
lemma tunnel_aux_injective
(f : M Γ N ββ[R] M) (i : injective f) (KΟ : Ξ£ K : submodule R M, K ββ[R] M) :
injective (tunnel_aux f KΟ) :=
(subtype.val_injective.comp KΟ.2.symm.injective).comp i
noncomputable theory
/-- Auxiliary definition for `tunnel`. -/
-- Even though we have `noncomputable theory`,
-- we get an error without another `noncomputable` here.
noncomputable def tunnel' (f : M Γ N ββ[R] M) (i : injective f) :
β β Ξ£ (K : submodule R M), K ββ[R] M
| 0 := β¨β€, linear_equiv.of_top β€ rflβ©
| (n+1) :=
β¨(submodule.fst R M N).map (tunnel_aux f (tunnel' n)),
((submodule.fst R M N).equiv_map_of_injective _ (tunnel_aux_injective f i (tunnel' n))).symm.trans
(submodule.fst_equiv R M N)β©
/--
Give an injective map `f : M Γ N ββ[R] M` we can find a nested sequence of submodules
all isomorphic to `M`.
-/
def tunnel (f : M Γ N ββ[R] M) (i : injective f) : β ββ order_dual (submodule R M) :=
β¨Ξ» n, (tunnel' f i n).1, monotone_nat_of_le_succ (Ξ» n, begin
dsimp [tunnel', tunnel_aux],
rw [submodule.map_comp, submodule.map_comp],
apply submodule.map_subtype_le,
end)β©
/--
Give an injective map `f : M Γ N ββ[R] M` we can find a sequence of submodules
all isomorphic to `N`.
-/
def tailing (f : M Γ N ββ[R] M) (i : injective f) (n : β) : submodule R M :=
(submodule.snd R M N).map (tunnel_aux f (tunnel' f i n))
/-- Each `tailing f i n` is a copy of `N`. -/
def tailing_linear_equiv (f : M Γ N ββ[R] M) (i : injective f) (n : β) : tailing f i n ββ[R] N :=
((submodule.snd R M N).equiv_map_of_injective _
(tunnel_aux_injective f i (tunnel' f i n))).symm.trans (submodule.snd_equiv R M N)
lemma tailing_le_tunnel (f : M Γ N ββ[R] M) (i : injective f) (n : β) :
tailing f i n β€ tunnel f i n :=
begin
dsimp [tailing, tunnel_aux],
rw [submodule.map_comp, submodule.map_comp],
apply submodule.map_subtype_le,
end
lemma tailing_disjoint_tunnel_succ (f : M Γ N ββ[R] M) (i : injective f) (n : β) :
disjoint (tailing f i n) (tunnel f i (n+1)) :=
begin
rw disjoint_iff,
dsimp [tailing, tunnel, tunnel'],
rw [submodule.map_inf_eq_map_inf_comap,
submodule.comap_map_eq_of_injective (tunnel_aux_injective _ i _), inf_comm,
submodule.fst_inf_snd, submodule.map_bot],
end
lemma tailing_sup_tunnel_succ_le_tunnel (f : M Γ N ββ[R] M) (i : injective f) (n : β) :
tailing f i n β tunnel f i (n+1) β€ tunnel f i n :=
begin
dsimp [tailing, tunnel, tunnel', tunnel_aux],
rw [βsubmodule.map_sup, sup_comm, submodule.fst_sup_snd, submodule.map_comp, submodule.map_comp],
apply submodule.map_subtype_le,
end
/-- The supremum of all the copies of `N` found inside the tunnel. -/
def tailings (f : M Γ N ββ[R] M) (i : injective f) : β β submodule R M :=
partial_sups (tailing f i)
@[simp] lemma tailings_zero (f : M Γ N ββ[R] M) (i : injective f) :
tailings f i 0 = tailing f i 0 :=
by simp [tailings]
@[simp] lemma tailings_succ (f : M Γ N ββ[R] M) (i : injective f) (n : β) :
tailings f i (n+1) = tailings f i n β tailing f i (n+1) :=
by simp [tailings]
lemma tailings_disjoint_tunnel (f : M Γ N ββ[R] M) (i : injective f) (n : β) :
disjoint (tailings f i n) (tunnel f i (n+1)) :=
begin
induction n with n ih,
{ simp only [tailings_zero],
apply tailing_disjoint_tunnel_succ, },
{ simp only [tailings_succ],
refine disjoint.disjoint_sup_left_of_disjoint_sup_right _ _,
apply tailing_disjoint_tunnel_succ,
apply disjoint.mono_right _ ih,
apply tailing_sup_tunnel_succ_le_tunnel, },
end
lemma tailings_disjoint_tailing (f : M Γ N ββ[R] M) (i : injective f) (n : β) :
disjoint (tailings f i n) (tailing f i (n+1)) :=
disjoint.mono_right (tailing_le_tunnel f i _) (tailings_disjoint_tunnel f i _)
end tunnel
end linear_map
|
5fcfc4c0bf6e8b3076980259b7f6b43ef5a31e80
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/seclvl.lean
|
feabe3d4a847af2e8e6cfc7db3079f9f076b39bd
|
[
"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
| 317
|
lean
|
import logic
section
variables (A B C : Type)
definition foo := A β B
check foo A B
check foo B C
check foo A A
end
constants A B C : Type
check foo A B
check foo B C
check foo A A
section
variables (A B C : Type)
definition foo2 := A β B
check foo2 A B
check foo2 B C
check foo2 A A
end
|
86ec78b4b0772d7a5da45f10503eb803e2fbbba1
|
097294e9b80f0d9893ac160b9c7219aa135b51b9
|
/instructor/identifiers/2020-01-23-notes-001.lean
|
49ba7d2edeab87121251c972208e118d13dc4fcd
|
[] |
no_license
|
AbigailCastro17/CS2102-Discrete-Math
|
cf296251be9418ce90206f5e66bde9163e21abf9
|
d741e4d2d6a9b2e0c8380e51706218b8f608cee4
|
refs/heads/main
| 1,682,891,087,358
| 1,621,401,341,000
| 1,621,401,341,000
| 368,749,959
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 681
|
lean
|
def x := 1 + 2
#print x
#eval x
/-
Identifiers, bindings, types
-/
def b' : bool := (tt : bool)
def b'' := tt
-- type inference
def s' : string := "I love logic!"
def n' : β := 1
/-
Functions and their application
-/
#eval band tt tt
#eval tt && tt
#eval nat.add 3 4
#eval string.append "Hello, " "Logic!"
#eval "Hello, " ++ "Logic!"
#check band
/-
Types
-/
/-
Every term has exactly one type
A type defines a set of terms
These sets are disjoint
-/
#check 0
#check "Hello"
#check tt
#check prod.mk 2 "Hi!"
#check true -- a proposition
#check bool
#check string
#check β
#check Type 0
#check Type 1
#check Prop
#check Sort 0
#check Sort 1
#check Sort 2
|
6d576fed00dc5eb6fcbd2a1da86ac01b0cc758de
|
968e2f50b755d3048175f176376eff7139e9df70
|
/examples/pred_logic/unnamed_308.lean
|
694f8674be2ea4f7788f1e3913158c57df0a1f0b
|
[] |
no_license
|
gihanmarasingha/mth1001_sphinx
|
190a003269ba5e54717b448302a27ca26e31d491
|
05126586cbf5786e521be1ea2ef5b4ba3c44e74a
|
refs/heads/master
| 1,672,913,933,677
| 1,604,516,583,000
| 1,604,516,583,000
| 309,245,750
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 107
|
lean
|
variables (U : Type*) (P : U β Prop) (u : U)
-- BEGIN
example (h : β x, P x) : P u :=
by apply h
-- END
|
73f67c9dcf3a3402d62be6702471698c9863bf31
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/topology/sheaves/sheaf.lean
|
46ce853717d8601fc81f7453b0be2ca4877e7e85
|
[
"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,316
|
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.presheaf
import category_theory.sites.sheaf
import category_theory.sites.spaces
/-!
# Sheaves
We define sheaves on a topological space, with values in an arbitrary category.
A presheaf on a topological space `X` is a sheaf presicely when it is a sheaf under the
grothendieck topology on `opens X`, which expands out to say: For each open cover `{ Uα΅’ }` of
`U`, and a family of compatible functions `A βΆ F(Uα΅’)` for an `A : X`, there exists an unique
gluing `A βΆ F(U)` compatible with the restriction.
See the docstring of `Top.presheaf.is_sheaf` for an explanation on the design descisions and a list
of equivalent conditions.
We provide the instance `category (sheaf C X)` as the full subcategory of presheaves,
and the fully faithful functor `sheaf.forget : sheaf C X β₯€ presheaf C X`.
-/
universes w v u
noncomputable theory
open category_theory
open category_theory.limits
open topological_space
open opposite
open topological_space.opens
namespace Top
variables {C : Type u} [category.{v} C]
variables {X : Top.{w}} (F : presheaf C X) {ΞΉ : Type v} (U : ΞΉ β opens X)
namespace presheaf
/--
The sheaf condition has several different equivalent formulations.
The official definition chosen here is in terms of grothendieck topologies so that the results on
sites could be applied here easily, and this condition does not require additional constraints on
the value category.
The equivalent formulations of the sheaf condition on `presheaf C X` are as follows :
1. `Top.presheaf.is_sheaf`: (the official definition)
It is a sheaf with respect to the grothendieck topology on `opens X`, which is to say:
For each open cover `{ Uα΅’ }` of `U`, and a family of compatible functions `A βΆ F(Uα΅’)` for an
`A : X`, there exists an unique gluing `A βΆ F(U)` compatible with the restriction.
2. `Top.presheaf.is_sheaf_equalizer_products`: (requires `C` to have all products)
For each open cover `{ Uα΅’ }` of `U`, `F(U) βΆ β F(Uα΅’)` is the equalizer of the two morphisms
`β F(Uα΅’) βΆ β F(Uα΅’ β© Uβ±Ό)`.
See `Top.presheaf.is_sheaf_iff_is_sheaf_equalizer_products`.
3. `Top.presheaf.is_sheaf_opens_le_cover`:
For each open cover `{ Uα΅’ }` of `U`, `F(U)` is the limit of the diagram consisting of arrows
`F(Vβ) βΆ F(Vβ)` for every pair of open sets `Vβ β Vβ` that are contained in some `Uα΅’`.
See `Top.presheaf.is_sheaf_iff_is_sheaf_opens_le_cover`.
4. `Top.presheaf.is_sheaf_pairwise_intersections`:
For each open cover `{ Uα΅’ }` of `U`, `F(U)` is the limit of the diagram consisting of arrows
from `F(Uα΅’)` and `F(Uβ±Ό)` to `F(Uα΅’ β© Uβ±Ό)` for each pair `(i, j)`.
See `Top.presheaf.is_sheaf_iff_is_sheaf_pairwise_intersections`.
The following requires `C` to be concrete and complete, and `forget C` to reflect isomorphisms and
preserve limits. This applies to most "algebraic" categories, e.g. groups, abelian groups and rings.
5. `Top.presheaf.is_sheaf_unique_gluing`:
(requires `C` to be concrete and complete; `forget C` to reflect isomorphisms and preserve limits)
For each open cover `{ Uα΅’ }` of `U`, and a compatible family of elements `x : F(Uα΅’)`, there exists
a unique gluing `x : F(U)` that restricts to the given elements.
See `Top.presheaf.is_sheaf_iff_is_sheaf_unique_gluing`.
6. The underlying sheaf of types is a sheaf.
See `Top.presheaf.is_sheaf_iff_is_sheaf_comp` and
`category_theory.presheaf.is_sheaf_iff_is_sheaf_forget`.
-/
def is_sheaf (F : presheaf.{w v u} C X) : Prop :=
presheaf.is_sheaf (opens.grothendieck_topology X) F
/--
The presheaf valued in `unit` over any topological space is a sheaf.
-/
lemma is_sheaf_unit (F : presheaf (category_theory.discrete unit) X) : F.is_sheaf :=
Ξ» x U S hS x hx, β¨eq_to_hom (subsingleton.elim _ _), by tidy, by tidyβ©
lemma is_sheaf_iso_iff {F G : presheaf C X} (Ξ± : F β
G) : F.is_sheaf β G.is_sheaf :=
presheaf.is_sheaf_of_iso_iff Ξ±
/--
Transfer the sheaf condition across an isomorphism of presheaves.
-/
lemma is_sheaf_of_iso {F G : presheaf C X} (Ξ± : F β
G) (h : F.is_sheaf) : G.is_sheaf :=
(is_sheaf_iso_iff Ξ±).1 h
end presheaf
variables (C X)
/--
A `sheaf C X` is a presheaf of objects from `C` over a (bundled) topological space `X`,
satisfying the sheaf condition.
-/
@[derive category]
def sheaf : Type (max u v w) := Sheaf (opens.grothendieck_topology X) C
variables {C X}
/-- The underlying presheaf of a sheaf -/
abbreviation sheaf.presheaf (F : X.sheaf C) : Top.presheaf C X := F.1
variables (C X)
-- Let's construct a trivial example, to keep the inhabited linter happy.
instance sheaf_inhabited : inhabited (sheaf (category_theory.discrete punit) X) :=
β¨β¨functor.star _, presheaf.is_sheaf_unit _β©β©
namespace sheaf
/--
The forgetful functor from sheaves to presheaves.
-/
@[derive [full, faithful]]
def forget : Top.sheaf C X β₯€ Top.presheaf C X :=
Sheaf_to_presheaf _ _
-- Note: These can be proved by simp.
lemma id_app (F : sheaf C X) (t) : (π F : F βΆ F).1.app t = π _ := rfl
lemma comp_app {F G H : sheaf C X} (f : F βΆ G) (g : G βΆ H) (t) :
(f β« g).1.app t = f.1.app t β« g.1.app t := rfl
end sheaf
end Top
|
7ebf0e939f999282529ac837e57287e9ebe170f5
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/def8.lean
|
f0998699f5c7bdc07d849e8b4ff608008cefef50
|
[
"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
| 936
|
lean
|
def g : List Nat β List Nat β Nat
| [], y::ys => y
| [], ys => 0
| x1::x2::xs, ys => g xs ys
| x::xs, y::ys => g xs ys + y
| x::xs, [] => g xs []
universe u v
inductive Imf {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β Ξ²) : Ξ² β Type (max u v)
| mk : (a : Ξ±) β Imf f (f a)
def h {Ξ± Ξ²} {f : Ξ± β Ξ²} : {b : Ξ²} β Imf f b β Ξ±
| _, Imf.mk a => a
theorem ex1 {Ξ± Ξ²} (f : Ξ± β Ξ²) (a : Ξ±) : h (Imf.mk (f := f) a) = a :=
rfl
def vβ : Imf Nat.succ 1 :=
Imf.mk 0
def vβ : Imf (fun x => 1 + x) 1 :=
Imf.mk 0
theorem ex2 : h vβ = 0 :=
rfl
theorem ex3 : h vβ = 0 :=
rfl
theorem ex4 {Ξ±} : {a b : Ξ±} β a = b β b = a
| _, _, rfl => rfl
theorem ex5 {Ξ±} : {a b : Ξ±} β a = b β b = a
| a, .(a), rfl => rfl
theorem ex6 {Ξ±} : {a b : Ξ±} β a = b β b = a
| a, .(a), Eq.refl .(a) => rfl
theorem ex7 {Ξ±} : {a b : Ξ±} β a = b β b = a
| .(a), a, Eq.refl .(a) => rfl
|
9112b75a22dd0c7580e4797fc667b00eb0d0c5f4
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/group_theory/submonoid/membership.lean
|
68a205b93926c093cc948fa2c7f85fea653fcc88
|
[
"Apache-2.0"
] |
permissive
|
waynemunro/mathlib
|
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
|
065a70810b5480d584033f7bbf8e0409480c2118
|
refs/heads/master
| 1,693,417,182,397
| 1,634,644,781,000
| 1,634,644,781,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 14,624
|
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.operations
import algebra.big_operators.basic
import algebra.free_monoid
import algebra.pointwise
/-!
# Submonoids: membership criteria
In this file we prove various facts about membership in a submonoid:
* `list_prod_mem`, `multiset_prod_mem`, `prod_mem`: if each element of a collection belongs
to a multiplicative submonoid, then so does their product;
* `list_sum_mem`, `multiset_sum_mem`, `sum_mem`: if each element of a collection belongs
to an additive submonoid, then so does their sum;
* `pow_mem`, `nsmul_mem`: if `x β S` where `S` is a multiplicative (resp., additive) submonoid and
`n` is a natural number, then `x^n` (resp., `n β’ x`) belongs to `S`;
* `mem_supr_of_directed`, `coe_supr_of_directed`, `mem_Sup_of_directed_on`,
`coe_Sup_of_directed_on`: the supremum of a directed collection of submonoid is their union.
* `sup_eq_range`, `mem_sup`: supremum of two submonoids `S`, `T` of a commutative monoid is the set
of products;
* `closure_singleton_eq`, `mem_closure_singleton`: the multiplicative (resp., additive) closure
of `{x}` consists of powers (resp., natural multiples) of `x`.
## Tags
submonoid, submonoids
-/
open_locale big_operators pointwise
variables {M : Type*}
variables {A : Type*}
namespace submonoid
section assoc
variables [monoid M] (S : submonoid M)
@[simp, norm_cast, to_additive coe_nsmul] theorem coe_pow (x : S) (n : β) :
β(x ^ n) = (x ^ n : M) :=
S.subtype.map_pow x n
@[simp, norm_cast, to_additive] theorem coe_list_prod (l : list S) :
(l.prod : M) = (l.map coe).prod :=
S.subtype.map_list_prod l
@[simp, norm_cast, to_additive] theorem coe_multiset_prod {M} [comm_monoid M] (S : submonoid M)
(m : multiset S) : (m.prod : M) = (m.map coe).prod :=
S.subtype.map_multiset_prod m
@[simp, norm_cast, to_additive] theorem coe_finset_prod {ΞΉ M} [comm_monoid M] (S : submonoid M)
(f : ΞΉ β S) (s : finset ΞΉ) :
β(β i in s, f i) = (β i in s, f i : M) :=
S.subtype.map_prod f s
/-- Product of a list of elements in a submonoid is in the submonoid. -/
@[to_additive "Sum of a list of elements in an `add_submonoid` is in the `add_submonoid`."]
lemma list_prod_mem {l : list M} (hl : β x β l, x β S) : l.prod β S :=
by { lift l to list S using hl, rw β coe_list_prod, exact l.prod.coe_prop }
/-- Product of a multiset of elements in a submonoid of a `comm_monoid` is in the submonoid. -/
@[to_additive "Sum of a multiset of elements in an `add_submonoid` of an `add_comm_monoid` is
in the `add_submonoid`."]
lemma multiset_prod_mem {M} [comm_monoid M] (S : submonoid M) (m : multiset M)
(hm : β a β m, a β S) : m.prod β S :=
by { lift m to multiset S using hm, rw β coe_multiset_prod, exact m.prod.coe_prop }
/-- Product of elements of a submonoid of a `comm_monoid` indexed by a `finset` is in the
submonoid. -/
@[to_additive "Sum of elements in an `add_submonoid` of an `add_comm_monoid` indexed by a `finset`
is in the `add_submonoid`."]
lemma prod_mem {M : Type*} [comm_monoid M] (S : submonoid M)
{ΞΉ : Type*} {t : finset ΞΉ} {f : ΞΉ β M} (h : βc β t, f c β S) :
β c in t, f c β S :=
S.multiset_prod_mem (t.1.map f) $ Ξ» x hx, let β¨i, hi, hixβ© := multiset.mem_map.1 hx in hix βΈ h i hi
@[to_additive nsmul_mem] lemma pow_mem {x : M} (hx : x β S) (n : β) : x ^ n β S :=
by simpa only [coe_pow] using ((β¨x, hxβ© : S) ^ n).coe_prop
end assoc
section non_assoc
variables [mul_one_class M] (S : submonoid M)
open set
@[to_additive]
lemma mem_supr_of_directed {ΞΉ} [hΞΉ : nonempty ΞΉ] {S : ΞΉ β submonoid M} (hS : directed (β€) S)
{x : M} :
x β (β¨ i, S i) β β i, x β S i :=
begin
refine β¨_, Ξ» β¨i, hiβ©, (set_like.le_def.1 $ le_supr S i) hiβ©,
suffices : x β closure (β i, (S i : set M)) β β i, x β S i,
by simpa only [closure_Union, closure_eq (S _)] using this,
refine (Ξ» hx, closure_induction hx (Ξ» _, mem_Union.1) _ _),
{ exact hΞΉ.elim (Ξ» i, β¨i, (S i).one_memβ©) },
{ rintros x y β¨i, hiβ© β¨j, hjβ©,
rcases hS i j with β¨k, hki, hkjβ©,
exact β¨k, (S k).mul_mem (hki hi) (hkj hj)β© }
end
@[to_additive]
lemma coe_supr_of_directed {ΞΉ} [nonempty ΞΉ] {S : ΞΉ β submonoid M} (hS : directed (β€) S) :
((β¨ i, S i : submonoid M) : set M) = β i, β(S i) :=
set.ext $ Ξ» x, by simp [mem_supr_of_directed hS]
@[to_additive]
lemma mem_Sup_of_directed_on {S : set (submonoid M)} (Sne : S.nonempty)
(hS : directed_on (β€) S) {x : M} :
x β Sup S β β s β S, x β s :=
begin
haveI : nonempty S := Sne.to_subtype,
simp only [Sup_eq_supr', mem_supr_of_directed hS.directed_coe, set_coe.exists, subtype.coe_mk]
end
@[to_additive]
lemma coe_Sup_of_directed_on {S : set (submonoid M)} (Sne : S.nonempty) (hS : directed_on (β€) S) :
(β(Sup S) : set M) = β s β S, βs :=
set.ext $ Ξ» x, by simp [mem_Sup_of_directed_on Sne hS]
@[to_additive]
lemma mem_sup_left {S T : submonoid M} : β {x : M}, x β S β x β S β T :=
show S β€ S β T, from le_sup_left
@[to_additive]
lemma mem_sup_right {S T : submonoid M} : β {x : M}, x β T β x β S β T :=
show T β€ S β T, from le_sup_right
@[to_additive]
lemma mem_supr_of_mem {ΞΉ : Type*} {S : ΞΉ β submonoid M} (i : ΞΉ) :
β {x : M}, x β S i β x β supr S :=
show S i β€ supr S, from le_supr _ _
@[to_additive]
lemma mem_Sup_of_mem {S : set (submonoid M)} {s : submonoid M}
(hs : s β S) : β {x : M}, x β s β x β Sup S :=
show s β€ Sup S, from le_Sup hs
end non_assoc
end submonoid
namespace free_monoid
variables {Ξ± : Type*}
open submonoid
@[to_additive]
theorem closure_range_of : closure (set.range $ @of Ξ±) = β€ :=
eq_top_iff.2 $ Ξ» x hx, free_monoid.rec_on x (one_mem _) $ Ξ» x xs hxs,
mul_mem _ (subset_closure $ set.mem_range_self _) hxs
end free_monoid
namespace submonoid
variables [monoid M]
open monoid_hom
lemma closure_singleton_eq (x : M) : closure ({x} : set M) = (powers_hom M x).mrange :=
closure_eq_of_le (set.singleton_subset_iff.2 β¨multiplicative.of_add 1, pow_one xβ©) $
Ξ» x β¨n, hnβ©, hn βΈ pow_mem _ (subset_closure $ set.mem_singleton _) _
/-- The submonoid generated by an element of a monoid equals the set of natural number powers of
the element. -/
lemma mem_closure_singleton {x y : M} : y β closure ({x} : set M) β β n:β, x^n=y :=
by rw [closure_singleton_eq, mem_mrange]; refl
lemma mem_closure_singleton_self {y : M} : y β closure ({y} : set M) :=
mem_closure_singleton.2 β¨1, pow_one yβ©
lemma closure_singleton_one : closure ({1} : set M) = β₯ :=
by simp [eq_bot_iff_forall, mem_closure_singleton]
@[to_additive]
lemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift (coe : s β M)).mrange :=
by rw [mrange_eq_map, β free_monoid.closure_range_of, map_mclosure, β set.range_comp,
free_monoid.lift_comp_of, subtype.range_coe]
@[to_additive]
lemma exists_list_of_mem_closure {s : set M} {x : M} (hx : x β closure s) :
β (l : list M) (hl : β y β l, y β s), l.prod = x :=
begin
rw [closure_eq_mrange, mem_mrange] at hx,
rcases hx with β¨l, hxβ©,
exact β¨list.map coe l, Ξ» y hy, let β¨z, hz, hyβ© := list.mem_map.1 hy in hy βΈ z.2, hxβ©
end
/-- The submonoid generated by an element. -/
def powers (n : M) : submonoid M :=
submonoid.copy (powers_hom M n).mrange (set.range ((^) n : β β M)) $
set.ext (Ξ» n, exists_congr $ Ξ» i, by simp; refl)
@[simp] lemma mem_powers (n : M) : n β powers n := β¨1, pow_one _β©
lemma mem_powers_iff (x z : M) : x β powers z β β n : β, z ^ n = x := iff.rfl
lemma powers_eq_closure (n : M) : powers n = closure {n} :=
by { ext, exact mem_closure_singleton.symm }
lemma powers_subset {n : M} {P : submonoid M} (h : n β P) : powers n β€ P :=
Ξ» x hx, match x, hx with _, β¨i, rflβ© := P.pow_mem h i end
/-- Exponentiation map from natural numbers to powers. -/
def pow (n : M) (m : β) : powers n := β¨n ^ m, m, rflβ©
/-- Logarithms from powers to natural numbers. -/
def log [decidable_eq M] {n : M} (p : powers n) : β :=
nat.find $ (mem_powers_iff p.val n).mp p.prop
@[simp] theorem pow_log_eq_self [decidable_eq M] {n : M} (p : powers n) : pow n (log p) = p :=
subtype.ext $ nat.find_spec p.prop
lemma pow_right_injective_iff_pow_injective {n : M} :
function.injective (Ξ» m : β, n ^ m) β function.injective (pow n) :=
subtype.coe_injective.of_comp_iff (pow n)
theorem log_pow_eq_self [decidable_eq M] {n : M} (h : function.injective (Ξ» m : β, n ^ m)) (m : β) :
log (pow n m) = m :=
pow_right_injective_iff_pow_injective.mp h $ pow_log_eq_self _
theorem log_pow_int_eq_self {x : β€} (h : 1 < x.nat_abs) (m : β) : log (pow x m) = m :=
log_pow_eq_self (int.pow_right_injective h) _
end submonoid
namespace submonoid
variables {N : Type*} [comm_monoid N]
open monoid_hom
@[to_additive]
lemma sup_eq_range (s t : submonoid N) : s β t = (s.subtype.coprod t.subtype).mrange :=
by rw [mrange_eq_map, β mrange_inl_sup_mrange_inr, map_sup, map_mrange, coprod_comp_inl,
map_mrange, coprod_comp_inr, range_subtype, range_subtype]
@[to_additive]
lemma mem_sup {s t : submonoid N} {x : N} :
x β s β t β β (y β s) (z β t), y * z = x :=
by simp only [sup_eq_range, mem_mrange, coprod_apply, prod.exists, set_like.exists,
coe_subtype, subtype.coe_mk]
end submonoid
namespace add_submonoid
variables [add_monoid A]
open set
lemma closure_singleton_eq (x : A) : closure ({x} : set A) = (multiples_hom A x).mrange :=
closure_eq_of_le (set.singleton_subset_iff.2 β¨1, one_nsmul xβ©) $
Ξ» x β¨n, hnβ©, hn βΈ nsmul_mem _ (subset_closure $ set.mem_singleton _) _
/-- The `add_submonoid` generated by an element of an `add_monoid` equals the set of
natural number multiples of the element. -/
lemma mem_closure_singleton {x y : A} :
y β closure ({x} : set A) β β n:β, n β’ x = y :=
by rw [closure_singleton_eq, add_monoid_hom.mem_mrange]; refl
lemma closure_singleton_zero : closure ({0} : set A) = β₯ :=
by simp [eq_bot_iff_forall, mem_closure_singleton, nsmul_zero]
/-- The additive submonoid generated by an element. -/
def multiples (x : A) : add_submonoid A :=
add_submonoid.copy (multiples_hom A x).mrange (set.range (Ξ» i, nsmul i x : β β A)) $
set.ext (Ξ» n, exists_congr $ Ξ» i, by simp; refl)
@[simp] lemma mem_multiples (x : A) : x β multiples x := β¨1, one_nsmul _β©
lemma mem_multiples_iff (x z : A) : x β multiples z β β n : β, n β’ z = x := iff.rfl
lemma multiples_eq_closure (x : A) : multiples x = closure {x} :=
by { ext, exact mem_closure_singleton.symm }
lemma multiples_subset {x : A} {P : add_submonoid A} (h : x β P) : multiples x β€ P :=
Ξ» x hx, match x, hx with _, β¨i, rflβ© := P.nsmul_mem h i end
attribute [to_additive add_submonoid.multiples] submonoid.powers
attribute [to_additive add_submonoid.mem_multiples] submonoid.mem_powers
attribute [to_additive add_submonoid.mem_multiples_iff] submonoid.mem_powers_iff
attribute [to_additive add_submonoid.multiples_eq_closure] submonoid.powers_eq_closure
attribute [to_additive add_submonoid.multiples_subset] submonoid.powers_subset
end add_submonoid
/-! Lemmas about additive closures of `submonoid`. -/
namespace submonoid
variables {R : Type*} [non_assoc_semiring R] (S : submonoid R) {a b : R}
/-- The product of an element of the additive closure of a multiplicative submonoid `M`
and an element of `M` is contained in the additive closure of `M`. -/
lemma mul_right_mem_add_closure
(ha : a β add_submonoid.closure (S : set R)) (hb : b β S) :
a * b β add_submonoid.closure (S : set R) :=
begin
revert b,
refine add_submonoid.closure_induction ha _ _ _; clear ha a,
{ exact Ξ» r hr b hb, add_submonoid.mem_closure.mpr (Ξ» y hy, hy (S.mul_mem hr hb)) },
{ exact Ξ» b hb, by simp only [zero_mul, (add_submonoid.closure (S : set R)).zero_mem] },
{ simp_rw add_mul,
exact Ξ» r s hr hs b hb, (add_submonoid.closure (S : set R)).add_mem (hr hb) (hs hb) }
end
/-- The product of two elements of the additive closure of a submonoid `M` is an element of the
additive closure of `M`. -/
lemma mul_mem_add_closure
(ha : a β add_submonoid.closure (S : set R)) (hb : b β add_submonoid.closure (S : set R)) :
a * b β add_submonoid.closure (S : set R) :=
begin
revert a,
refine add_submonoid.closure_induction hb _ _ _; clear hb b,
{ exact Ξ» r hr b hb, S.mul_right_mem_add_closure hb hr },
{ exact Ξ» b hb, by simp only [mul_zero, (add_submonoid.closure (S : set R)).zero_mem] },
{ simp_rw mul_add,
exact Ξ» r s hr hs b hb, (add_submonoid.closure (S : set R)).add_mem (hr hb) (hs hb) }
end
/-- The product of an element of `S` and an element of the additive closure of a multiplicative
submonoid `S` is contained in the additive closure of `S`. -/
lemma mul_left_mem_add_closure (ha : a β S) (hb : b β add_submonoid.closure (S : set R)) :
a * b β add_submonoid.closure (S : set R) :=
S.mul_mem_add_closure (add_submonoid.mem_closure.mpr (Ξ» sT hT, hT ha)) hb
@[to_additive]
lemma mem_closure_inv {G : Type*} [group G] (S : set G) (x : G) :
x β submonoid.closure Sβ»ΒΉ β xβ»ΒΉ β submonoid.closure S :=
begin
suffices : β (S : set G) (x : G), x β submonoid.closure Sβ»ΒΉ β xβ»ΒΉ β submonoid.closure S,
{ refine β¨this S x, _β©,
have := this Sβ»ΒΉ xβ»ΒΉ,
rw [inv_inv, set.inv_inv] at this,
exact this, },
intros S x hx,
refine submonoid.closure_induction hx (Ξ» x hx, _) _ (Ξ» x y hx hy, _),
{ exact submonoid.subset_closure (set.mem_inv.mp hx), },
{ rw one_inv,
exact submonoid.one_mem _ },
{ rw mul_inv_rev x y,
exact submonoid.mul_mem _ hy hx },
end
end submonoid
section mul_add
lemma of_mul_image_powers_eq_multiples_of_mul [monoid M] {x : M} :
additive.of_mul '' ((submonoid.powers x) : set M) = add_submonoid.multiples (additive.of_mul x) :=
begin
ext,
split,
{ rintros β¨y, β¨n, hy1β©, hy2β©,
use n,
simpa [β of_mul_pow, hy1] },
{ rintros β¨n, hnβ©,
refine β¨x ^ n, β¨n, rflβ©, _β©,
rwa of_mul_pow }
end
lemma of_add_image_multiples_eq_powers_of_add [add_monoid A] {x : A} :
multiplicative.of_add '' ((add_submonoid.multiples x) : set A) =
submonoid.powers (multiplicative.of_add x) :=
begin
symmetry,
rw equiv.eq_image_iff_symm_image_eq,
exact of_mul_image_powers_eq_multiples_of_mul,
end
end mul_add
|
a05eba68112adf5df959dcecbdc362f67355a87e
|
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
|
/stage0/src/Lean/Data/Lsp/Capabilities.lean
|
396675ffe0b19c71d29768361088cfcc2deeb20d
|
[
"Apache-2.0"
] |
permissive
|
banksonian/lean4
|
3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc
|
78da6b3aa2840693eea354a41e89fc5b212a5011
|
refs/heads/master
| 1,673,703,624,165
| 1,605,123,551,000
| 1,605,123,551,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 931
|
lean
|
/-
Copyright (c) 2020 Marc Huisinga. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Marc Huisinga, Wojciech Nawrocki
-/
import Lean.Data.JsonRpc
import Lean.Data.Lsp.TextSync
/-! Minimal LSP servers/clients do not have to implement a lot
of functionality. Most useful additional behaviour is instead
opted into via capabilities. -/
namespace Lean
namespace Lsp
open Json
-- TODO: right now we ignore the client's capabilities
inductive ClientCapabilities | mk
instance : FromJson ClientCapabilities :=
β¨fun j => ClientCapabilities.mkβ©
-- TODO largely unimplemented
structure ServerCapabilities :=
(textDocumentSync? : Option TextDocumentSyncOptions := none)
(hoverProvider : Bool := false)
instance : ToJson ServerCapabilities := β¨fun o => mkObj $
opt "textDocumentSync" o.textDocumentSync? ++
[β¨"hoverProvider", o.hoverProviderβ©]β©
end Lsp
end Lean
|
1d41d050eeec5bf4319faa121a678596734ed2a0
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/ring_theory/witt_vector/identities.lean
|
2347d9edc4d82fb9f05cdd0312073cc2e6d7c9c5
|
[
"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
| 1,901
|
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 ring_theory.witt_vector.frobenius
import ring_theory.witt_vector.verschiebung
import ring_theory.witt_vector.mul_p
/-!
## Identities between operations on the ring of Witt vectors
In this file we derive common identities between the Frobenius and Verschiebung operators.
## Main declarations
* `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p`
* `verschiebung_mul_frobenius`: the βprojection formulaβ: `V(x * F y) = V x * y`
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace witt_vector
variables {p : β} {R : Type*} [fact p.prime] [comm_ring R]
local notation `π` := witt_vector p -- type as `\bbW`
noncomputable theory
/-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/
lemma frobenius_verschiebung (x : π R) :
frobenius (verschiebung x) = x * p :=
by { ghost_calc x, ghost_simp [mul_comm] }
/-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `zmod p`. -/
lemma verschiebung_zmod (x : π (zmod p)) :
verschiebung x = x * p :=
by rw [β frobenius_verschiebung, frobenius_zmodp]
lemma coeff_p_pow [char_p R p] (i : β) : (p ^ i : π R).coeff i = 1 :=
begin
induction i with i h,
{ simp only [one_coeff_zero, ne.def, pow_zero] },
{ rw [pow_succ', β frobenius_verschiebung, coeff_frobenius_char_p,
verschiebung_coeff_succ, h, one_pow], }
end
/-- The βprojection formulaβ for Frobenius and Verschiebung. -/
lemma verschiebung_mul_frobenius (x y : π R) :
verschiebung (x * frobenius y) = verschiebung x * y :=
by { ghost_calc x y, rintro β¨β©; ghost_simp [mul_assoc] }
end witt_vector
|
f70ac0cd855b9a987c4c23b34f5468cf16c6914a
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/order/filter/n_ary.lean
|
4c06a1c9c27134581343fccc6775681158dbb151
|
[
"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
| 18,121
|
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 order.filter.prod
/-!
# N-ary maps of filter
This file defines the binary and ternary maps of filters. This is mostly useful to define pointwise
operations on filters.
## Main declarations
* `filter.mapβ`: Binary map of filters.
* `filter.mapβ`: Ternary map of filters.
## Notes
This file is very similar to the n-ary section of `data.set.basic`, to `data.finset.n_ary` and to
`data.option.n_ary`. Please keep them in sync.
-/
open function set
open_locale filter
namespace filter
variables {Ξ± Ξ±' Ξ² Ξ²' Ξ³ Ξ³' Ξ΄ Ξ΄' Ξ΅ Ξ΅' : Type*} {m : Ξ± β Ξ² β Ξ³} {f fβ fβ : filter Ξ±}
{g gβ gβ : filter Ξ²} {h hβ hβ : filter Ξ³} {s sβ sβ : set Ξ±} {t tβ tβ : set Ξ²} {u : set Ξ³}
{v : set Ξ΄} {a : Ξ±} {b : Ξ²} {c : Ξ³}
/-- The image of a binary function `m : Ξ± β Ξ² β Ξ³` as a function `filter Ξ± β filter Ξ² β filter Ξ³`.
Mathematically this should be thought of as the image of the corresponding function `Ξ± Γ Ξ² β Ξ³`. -/
def mapβ (m : Ξ± β Ξ² β Ξ³) (f : filter Ξ±) (g : filter Ξ²) : filter Ξ³ :=
{ sets := {s | β u v, u β f β§ v β g β§ image2 m u v β s},
univ_sets := β¨univ, univ, univ_sets _, univ_sets _, subset_univ _β©,
sets_of_superset := Ξ» s t hs hst,
Existsβ.imp (Ξ» u v, and.imp_right $ and.imp_right $ Ξ» h, subset.trans h hst) hs,
inter_sets := Ξ» s t,
begin
simp only [exists_prop, mem_set_of_eq, subset_inter_iff],
rintro β¨sβ, sβ, hsβ, hsβ, hsβ© β¨tβ, tβ, htβ, htβ, htβ©,
exact β¨sβ β© tβ, sβ β© tβ, inter_sets f hsβ htβ, inter_sets g hsβ htβ,
(image2_subset (inter_subset_left _ _) $ inter_subset_left _ _).trans hs,
(image2_subset (inter_subset_right _ _) $ inter_subset_right _ _).trans htβ©,
end }
@[simp] lemma mem_mapβ_iff : u β mapβ m f g β β s t, s β f β§ t β g β§ image2 m s t β u := iff.rfl
lemma image2_mem_mapβ (hs : s β f) (ht : t β g) : image2 m s t β mapβ m f g :=
β¨_, _, hs, ht, subset.rflβ©
lemma map_prod_eq_mapβ (m : Ξ± β Ξ² β Ξ³) (f : filter Ξ±) (g : filter Ξ²) :
filter.map (Ξ» p : Ξ± Γ Ξ², m p.1 p.2) (f ΓαΆ g) = mapβ m f g :=
begin
ext s,
split,
{ intro hmem,
rw filter.mem_map_iff_exists_image at hmem,
obtain β¨s', hs', hsubβ© := hmem,
rw filter.mem_prod_iff at hs',
obtain β¨t, ht, t', ht', hsub'β© := hs',
refine β¨t, t', ht, ht', _β©,
rw β set.image_prod,
exact subset_trans (set.image_subset (Ξ» (p : Ξ± Γ Ξ²), m p.fst p.snd) hsub') hsub },
{ intro hmem,
rw mem_mapβ_iff at hmem,
obtain β¨t, t', ht, ht', hsubβ© := hmem,
rw β set.image_prod at hsub,
rw filter.mem_map_iff_exists_image,
exact β¨t ΓΛ’ t', filter.prod_mem_prod ht ht', hsubβ© },
end
lemma map_prod_eq_mapβ' (m : Ξ± Γ Ξ² β Ξ³) (f : filter Ξ±) (g : filter Ξ²) :
filter.map m (f ΓαΆ g) = mapβ (Ξ» a b, m (a, b)) f g :=
by { refine eq.trans _ (map_prod_eq_mapβ (curry m) f g), ext, simp }
@[simp] lemma mapβ_mk_eq_prod (f : filter Ξ±) (g : filter Ξ²) : mapβ prod.mk f g = f ΓαΆ g :=
by ext; simp [mem_prod_iff]
-- lemma image2_mem_mapβ_iff (hm : injective2 m) : image2 m s t β mapβ m f g β s β f β§ t β g :=
-- β¨by { rintro β¨u, v, hu, hv, hβ©, rw image2_subset_image2_iff hm at h,
-- exact β¨mem_of_superset hu h.1, mem_of_superset hv h.2β© }, Ξ» h, image2_mem_mapβ h.1 h.2β©
lemma mapβ_mono (hf : fβ β€ fβ) (hg : gβ β€ gβ) : mapβ m fβ gβ β€ mapβ m fβ gβ :=
Ξ» _ β¨s, t, hs, ht, hstβ©, β¨s, t, hf hs, hg ht, hstβ©
lemma mapβ_mono_left (h : gβ β€ gβ) : mapβ m f gβ β€ mapβ m f gβ := mapβ_mono subset.rfl h
lemma mapβ_mono_right (h : fβ β€ fβ) : mapβ m fβ g β€ mapβ m fβ g := mapβ_mono h subset.rfl
@[simp] lemma le_mapβ_iff {h : filter Ξ³} :
h β€ mapβ m f g β β β¦sβ¦, s β f β β β¦tβ¦, t β g β image2 m s t β h :=
β¨Ξ» H s hs t ht, H $ image2_mem_mapβ hs ht, Ξ» H u β¨s, t, hs, ht, huβ©, mem_of_superset (H hs ht) huβ©
@[simp] lemma mapβ_bot_left : mapβ m β₯ g = β₯ :=
empty_mem_iff_bot.1 β¨β
, univ, trivial, univ_mem, (image2_empty_left).subsetβ©
@[simp] lemma mapβ_bot_right : mapβ m f β₯ = β₯ :=
empty_mem_iff_bot.1 β¨univ, β
, univ_mem, trivial, (image2_empty_right).subsetβ©
@[simp] lemma mapβ_eq_bot_iff : mapβ m f g = β₯ β f = β₯ β¨ g = β₯ :=
begin
simp only [βempty_mem_iff_bot, mem_mapβ_iff, subset_empty_iff, image2_eq_empty_iff],
split,
{ rintro β¨s, t, hs, ht, rfl | rflβ©,
{ exact or.inl hs },
{ exact or.inr ht } },
{ rintro (h | h),
{ exact β¨_, _, h, univ_mem, or.inl rflβ© },
{ exact β¨_, _, univ_mem, h, or.inr rflβ© } }
end
@[simp] lemma mapβ_ne_bot_iff : (mapβ m f g).ne_bot β f.ne_bot β§ g.ne_bot :=
by { simp_rw ne_bot_iff, exact mapβ_eq_bot_iff.not.trans not_or_distrib }
lemma ne_bot.mapβ (hf : f.ne_bot) (hg : g.ne_bot) : (mapβ m f g).ne_bot :=
mapβ_ne_bot_iff.2 β¨hf, hgβ©
lemma ne_bot.of_mapβ_left (h : (mapβ m f g).ne_bot) : f.ne_bot := (mapβ_ne_bot_iff.1 h).1
lemma ne_bot.of_mapβ_right (h : (mapβ m f g).ne_bot) : g.ne_bot := (mapβ_ne_bot_iff.1 h).2
lemma mapβ_sup_left : mapβ m (fβ β fβ) g = mapβ m fβ g β mapβ m fβ g :=
begin
ext u,
split,
{ rintro β¨s, t, β¨hβ, hββ©, ht, huβ©,
exact β¨mem_of_superset (image2_mem_mapβ hβ ht) hu,
mem_of_superset (image2_mem_mapβ hβ ht) huβ© },
{ rintro β¨β¨sβ, tβ, hsβ, htβ, huββ©, sβ, tβ, hsβ, htβ, huββ©,
refine β¨sβ βͺ sβ, tβ β© tβ, union_mem_sup hsβ hsβ, inter_mem htβ htβ, _β©,
rw image2_union_left,
exact union_subset ((image2_subset_left $ inter_subset_left _ _).trans huβ)
((image2_subset_left $ inter_subset_right _ _).trans huβ) }
end
lemma mapβ_sup_right : mapβ m f (gβ β gβ) = mapβ m f gβ β mapβ m f gβ :=
begin
ext u,
split,
{ rintro β¨s, t, hs, β¨hβ, hββ©, huβ©,
exact β¨mem_of_superset (image2_mem_mapβ hs hβ) hu,
mem_of_superset (image2_mem_mapβ hs hβ) huβ© },
{ rintro β¨β¨sβ, tβ, hsβ, htβ, huββ©, sβ, tβ, hsβ, htβ, huββ©,
refine β¨sβ β© sβ, tβ βͺ tβ, inter_mem hsβ hsβ, union_mem_sup htβ htβ, _β©,
rw image2_union_right,
exact union_subset ((image2_subset_right $ inter_subset_left _ _).trans huβ)
((image2_subset_right $ inter_subset_right _ _).trans huβ) }
end
lemma mapβ_inf_subset_left : mapβ m (fβ β fβ) g β€ mapβ m fβ g β mapβ m fβ g :=
le_inf (mapβ_mono_right inf_le_left) (mapβ_mono_right inf_le_right)
lemma mapβ_inf_subset_right : mapβ m f (gβ β gβ) β€ mapβ m f gβ β mapβ m f gβ :=
le_inf (mapβ_mono_left inf_le_left) (mapβ_mono_left inf_le_right)
@[simp] lemma mapβ_pure_left : mapβ m (pure a) g = g.map (Ξ» b, m a b) :=
filter.ext $ Ξ» u, β¨Ξ» β¨s, t, hs, ht, huβ©,
mem_of_superset (image_mem_map ht) ((image_subset_image2_right $ mem_pure.1 hs).trans hu),
Ξ» h, β¨{a}, _, singleton_mem_pure, h, by rw [image2_singleton_left, image_subset_iff]β©β©
@[simp] lemma mapβ_pure_right : mapβ m f (pure b) = f.map (Ξ» a, m a b) :=
filter.ext $ Ξ» u, β¨Ξ» β¨s, t, hs, ht, huβ©,
mem_of_superset (image_mem_map hs) ((image_subset_image2_left $ mem_pure.1 ht).trans hu),
Ξ» h, β¨_, {b}, h, singleton_mem_pure, by rw [image2_singleton_right, image_subset_iff]β©β©
lemma mapβ_pure : mapβ m (pure a) (pure b) = pure (m a b) := by rw [mapβ_pure_right, map_pure]
lemma mapβ_swap (m : Ξ± β Ξ² β Ξ³) (f : filter Ξ±) (g : filter Ξ²) :
mapβ m f g = mapβ (Ξ» a b, m b a) g f :=
by { ext u, split; rintro β¨s, t, hs, ht, huβ©; refine β¨t, s, ht, hs, by rwa image2_swapβ© }
@[simp] lemma mapβ_left (h : g.ne_bot) : mapβ (Ξ» x y, x) f g = f :=
begin
ext u,
refine β¨_, Ξ» hu, β¨_, _, hu, univ_mem, (image2_left $ h.nonempty_of_mem univ_mem).subsetβ©β©,
rintro β¨s, t, hs, ht, huβ©,
rw image2_left (h.nonempty_of_mem ht) at hu,
exact mem_of_superset hs hu,
end
@[simp] lemma mapβ_right (h : f.ne_bot) : mapβ (Ξ» x y, y) f g = g := by rw [mapβ_swap, mapβ_left h]
/-- The image of a ternary function `m : Ξ± β Ξ² β Ξ³ β Ξ΄` as a function
`filter Ξ± β filter Ξ² β filter Ξ³ β filter Ξ΄`. Mathematically this should be thought of as the image
of the corresponding function `Ξ± Γ Ξ² Γ Ξ³ β Ξ΄`. -/
def mapβ (m : Ξ± β Ξ² β Ξ³ β Ξ΄) (f : filter Ξ±) (g : filter Ξ²) (h : filter Ξ³) : filter Ξ΄ :=
{ sets := {s | β u v w, u β f β§ v β g β§ w β h β§ image3 m u v w β s},
univ_sets := β¨univ, univ, univ, univ_sets _, univ_sets _, univ_sets _, subset_univ _β©,
sets_of_superset := Ξ» s t hs hst, Existsβ.imp
(Ξ» u v w, and.imp_right $ and.imp_right $ and.imp_right $ Ξ» h, subset.trans h hst) hs,
inter_sets := Ξ» s t,
begin
simp only [exists_prop, mem_set_of_eq, subset_inter_iff],
rintro β¨sβ, sβ, sβ, hsβ, hsβ, hsβ, hsβ© β¨tβ, tβ, tβ, htβ, htβ, htβ, htβ©,
exact β¨sβ β© tβ, sβ β© tβ, sβ β© tβ, inter_mem hsβ htβ, inter_mem hsβ htβ, inter_mem hsβ htβ,
(image3_mono (inter_subset_left _ _) (inter_subset_left _ _) $ inter_subset_left _ _).trans
hs,
(image3_mono (inter_subset_right _ _) (inter_subset_right _ _) $ inter_subset_right _ _).trans
htβ©,
end }
lemma mapβ_mapβ_left (m : Ξ΄ β Ξ³ β Ξ΅) (n : Ξ± β Ξ² β Ξ΄) :
mapβ m (mapβ n f g) h = mapβ (Ξ» a b c, m (n a b) c) f g h :=
begin
ext w,
split,
{ rintro β¨s, t, β¨u, v, hu, hv, hsβ©, ht, hwβ©,
refine β¨u, v, t, hu, hv, ht, _β©,
rw βimage2_image2_left,
exact (image2_subset_right hs).trans hw },
{ rintro β¨s, t, u, hs, ht, hu, hwβ©,
exact β¨_, u, image2_mem_mapβ hs ht, hu, by rwa image2_image2_leftβ© }
end
lemma mapβ_mapβ_right (m : Ξ± β Ξ΄ β Ξ΅) (n : Ξ² β Ξ³ β Ξ΄) :
mapβ m f (mapβ n g h) = mapβ (Ξ» a b c, m a (n b c)) f g h :=
begin
ext w,
split,
{ rintro β¨s, t, hs, β¨u, v, hu, hv, htβ©, hwβ©,
refine β¨s, u, v, hs, hu, hv, _β©,
rw βimage2_image2_right,
exact (image2_subset_left ht).trans hw },
{ rintro β¨s, t, u, hs, ht, hu, hwβ©,
exact β¨s, _, hs, image2_mem_mapβ ht hu, by rwa image2_image2_rightβ© }
end
lemma map_mapβ (m : Ξ± β Ξ² β Ξ³) (n : Ξ³ β Ξ΄) : (mapβ m f g).map n = mapβ (Ξ» a b, n (m a b)) f g :=
filter.ext $ Ξ» u, existsβ_congr $ Ξ» s t, by rw [βimage_subset_iff, image_image2]
lemma mapβ_map_left (m : Ξ³ β Ξ² β Ξ΄) (n : Ξ± β Ξ³) :
mapβ m (f.map n) g = mapβ (Ξ» a b, m (n a) b) f g :=
begin
ext u,
split,
{ rintro β¨s, t, hs, ht, huβ©,
refine β¨_, t, hs, ht, _β©,
rw βimage2_image_left,
exact (image2_subset_right $ image_preimage_subset _ _).trans hu },
{ rintro β¨s, t, hs, ht, huβ©,
exact β¨_, t, image_mem_map hs, ht, by rwa image2_image_leftβ© }
end
lemma mapβ_map_right (m : Ξ± β Ξ³ β Ξ΄) (n : Ξ² β Ξ³) :
mapβ m f (g.map n) = mapβ (Ξ» a b, m a (n b)) f g :=
by rw [mapβ_swap, mapβ_map_left, mapβ_swap]
@[simp] lemma mapβ_curry (m : Ξ± Γ Ξ² β Ξ³) (f : filter Ξ±) (g : filter Ξ²) :
mapβ (curry m) f g = (f ΓαΆ g).map m :=
by { classical, rw [βmapβ_mk_eq_prod, map_mapβ, curry] }
@[simp] lemma map_uncurry_prod (m : Ξ± β Ξ² β Ξ³) (f : filter Ξ±) (g : filter Ξ²) :
(f ΓαΆ g).map (uncurry m) = mapβ m f g := by rw [βmapβ_curry, curry_uncurry]
/-!
### Algebraic replacement rules
A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations
to the associativity, commutativity, distributivity, ... of `filter.mapβ` of those operations.
The proof pattern is `mapβ_lemma operation_lemma`. For example, `mapβ_comm mul_comm` proves that
`mapβ (*) f g = mapβ (*) g f` in a `comm_semigroup`.
-/
lemma mapβ_assoc {m : Ξ΄ β Ξ³ β Ξ΅} {n : Ξ± β Ξ² β Ξ΄} {m' : Ξ± β Ξ΅' β Ξ΅} {n' : Ξ² β Ξ³ β Ξ΅'}
{h : filter Ξ³} (h_assoc : β a b c, m (n a b) c = m' a (n' b c)) :
mapβ m (mapβ n f g) h = mapβ m' f (mapβ n' g h) :=
by simp only [mapβ_mapβ_left, mapβ_mapβ_right, h_assoc]
lemma mapβ_comm {n : Ξ² β Ξ± β Ξ³} (h_comm : β a b, m a b = n b a) : mapβ m f g = mapβ n g f :=
(mapβ_swap _ _ _).trans $ by simp_rw h_comm
lemma mapβ_left_comm {m : Ξ± β Ξ΄ β Ξ΅} {n : Ξ² β Ξ³ β Ξ΄} {m' : Ξ± β Ξ³ β Ξ΄'} {n' : Ξ² β Ξ΄' β Ξ΅}
(h_left_comm : β a b c, m a (n b c) = n' b (m' a c)) :
mapβ m f (mapβ n g h) = mapβ n' g (mapβ m' f h) :=
by { rw [mapβ_swap m', mapβ_swap m], exact mapβ_assoc (Ξ» _ _ _, h_left_comm _ _ _) }
lemma mapβ_right_comm {m : Ξ΄ β Ξ³ β Ξ΅} {n : Ξ± β Ξ² β Ξ΄} {m' : Ξ± β Ξ³ β Ξ΄'} {n' : Ξ΄' β Ξ² β Ξ΅}
(h_right_comm : β a b c, m (n a b) c = n' (m' a c) b) :
mapβ m (mapβ n f g) h = mapβ n' (mapβ m' f h) g :=
by { rw [mapβ_swap n, mapβ_swap n'], exact mapβ_assoc (Ξ» _ _ _, h_right_comm _ _ _) }
lemma map_mapβ_distrib {n : Ξ³ β Ξ΄} {m' : Ξ±' β Ξ²' β Ξ΄} {nβ : Ξ± β Ξ±'} {nβ : Ξ² β Ξ²'}
(h_distrib : β a b, n (m a b) = m' (nβ a) (nβ b)) :
(mapβ m f g).map n = mapβ m' (f.map nβ) (g.map nβ) :=
by simp_rw [map_mapβ, mapβ_map_left, mapβ_map_right, h_distrib]
/-- Symmetric statement to `filter.mapβ_map_left_comm`. -/
lemma map_mapβ_distrib_left {n : Ξ³ β Ξ΄} {m' : Ξ±' β Ξ² β Ξ΄} {n' : Ξ± β Ξ±'}
(h_distrib : β a b, n (m a b) = m' (n' a) b) :
(mapβ m f g).map n = mapβ m' (f.map n') g :=
map_mapβ_distrib h_distrib
/-- Symmetric statement to `filter.map_mapβ_right_comm`. -/
lemma map_mapβ_distrib_right {n : Ξ³ β Ξ΄} {m' : Ξ± β Ξ²' β Ξ΄} {n' : Ξ² β Ξ²'}
(h_distrib : β a b, n (m a b) = m' a (n' b)) :
(mapβ m f g).map n = mapβ m' f (g.map n') :=
map_mapβ_distrib h_distrib
/-- Symmetric statement to `filter.map_mapβ_distrib_left`. -/
lemma mapβ_map_left_comm {m : Ξ±' β Ξ² β Ξ³} {n : Ξ± β Ξ±'} {m' : Ξ± β Ξ² β Ξ΄} {n' : Ξ΄ β Ξ³}
(h_left_comm : β a b, m (n a) b = n' (m' a b)) :
mapβ m (f.map n) g = (mapβ m' f g).map n' :=
(map_mapβ_distrib_left $ Ξ» a b, (h_left_comm a b).symm).symm
/-- Symmetric statement to `filter.map_mapβ_distrib_right`. -/
lemma map_mapβ_right_comm {m : Ξ± β Ξ²' β Ξ³} {n : Ξ² β Ξ²'} {m' : Ξ± β Ξ² β Ξ΄} {n' : Ξ΄ β Ξ³}
(h_right_comm : β a b, m a (n b) = n' (m' a b)) :
mapβ m f (g.map n) = (mapβ m' f g).map n' :=
(map_mapβ_distrib_right $ Ξ» a b, (h_right_comm a b).symm).symm
/-- The other direction does not hold because of the `f`-`f` cross terms on the RHS. -/
lemma mapβ_distrib_le_left {m : Ξ± β Ξ΄ β Ξ΅} {n : Ξ² β Ξ³ β Ξ΄} {mβ : Ξ± β Ξ² β Ξ²'} {mβ : Ξ± β Ξ³ β Ξ³'}
{n' : Ξ²' β Ξ³' β Ξ΅} (h_distrib : β a b c, m a (n b c) = n' (mβ a b) (mβ a c)) :
mapβ m f (mapβ n g h) β€ mapβ n' (mapβ mβ f g) (mapβ mβ f h) :=
begin
rintro s β¨tβ, tβ, β¨uβ, v, huβ, hv, htββ©, β¨uβ, w, huβ, hw, htββ©, hsβ©,
refine β¨uβ β© uβ, _, inter_mem huβ huβ, image2_mem_mapβ hv hw, _β©,
refine (image2_distrib_subset_left h_distrib).trans ((image2_subset _ _).trans hs),
{ exact (image2_subset_right $ inter_subset_left _ _).trans htβ },
{ exact (image2_subset_right $ inter_subset_right _ _).trans htβ }
end
/-- The other direction does not hold because of the `h`-`h` cross terms on the RHS. -/
lemma mapβ_distrib_le_right {m : Ξ΄ β Ξ³ β Ξ΅} {n : Ξ± β Ξ² β Ξ΄} {mβ : Ξ± β Ξ³ β Ξ±'}
{mβ : Ξ² β Ξ³ β Ξ²'} {n' : Ξ±' β Ξ²' β Ξ΅} (h_distrib : β a b c, m (n a b) c = n' (mβ a c) (mβ b c)) :
mapβ m (mapβ n f g) h β€ mapβ n' (mapβ mβ f h) (mapβ mβ g h) :=
begin
rintro s β¨tβ, tβ, β¨u, wβ, hu, hwβ, htββ©, β¨v, wβ, hv, hwβ, htββ©, hsβ©,
refine β¨_, wβ β© wβ, image2_mem_mapβ hu hv, inter_mem hwβ hwβ, _β©,
refine (image2_distrib_subset_right h_distrib).trans ((image2_subset _ _).trans hs),
{ exact (image2_subset_left $ inter_subset_left _ _).trans htβ },
{ exact (image2_subset_left $ inter_subset_right _ _).trans htβ }
end
lemma map_mapβ_antidistrib {n : Ξ³ β Ξ΄} {m' : Ξ²' β Ξ±' β Ξ΄} {nβ : Ξ² β Ξ²'} {nβ : Ξ± β Ξ±'}
(h_antidistrib : β a b, n (m a b) = m' (nβ b) (nβ a)) :
(mapβ m f g).map n = mapβ m' (g.map nβ) (f.map nβ) :=
by { rw mapβ_swap m, exact map_mapβ_distrib (Ξ» _ _, h_antidistrib _ _) }
/-- Symmetric statement to `filter.mapβ_map_left_anticomm`. -/
lemma map_mapβ_antidistrib_left {n : Ξ³ β Ξ΄} {m' : Ξ²' β Ξ± β Ξ΄} {n' : Ξ² β Ξ²'}
(h_antidistrib : β a b, n (m a b) = m' (n' b) a) :
(mapβ m f g).map n = mapβ m' (g.map n') f :=
map_mapβ_antidistrib h_antidistrib
/-- Symmetric statement to `filter.map_mapβ_right_anticomm`. -/
lemma map_mapβ_antidistrib_right {n : Ξ³ β Ξ΄} {m' : Ξ² β Ξ±' β Ξ΄} {n' : Ξ± β Ξ±'}
(h_antidistrib : β a b, n (m a b) = m' b (n' a)) :
(mapβ m f g).map n = mapβ m' g (f.map n') :=
map_mapβ_antidistrib h_antidistrib
/-- Symmetric statement to `filter.map_mapβ_antidistrib_left`. -/
lemma mapβ_map_left_anticomm {m : Ξ±' β Ξ² β Ξ³} {n : Ξ± β Ξ±'} {m' : Ξ² β Ξ± β Ξ΄} {n' : Ξ΄ β Ξ³}
(h_left_anticomm : β a b, m (n a) b = n' (m' b a)) :
mapβ m (f.map n) g = (mapβ m' g f).map n' :=
(map_mapβ_antidistrib_left $ Ξ» a b, (h_left_anticomm b a).symm).symm
/-- Symmetric statement to `filter.map_mapβ_antidistrib_right`. -/
lemma map_mapβ_right_anticomm {m : Ξ± β Ξ²' β Ξ³} {n : Ξ² β Ξ²'} {m' : Ξ² β Ξ± β Ξ΄} {n' : Ξ΄ β Ξ³}
(h_right_anticomm : β a b, m a (n b) = n' (m' b a)) :
mapβ m f (g.map n) = (mapβ m' g f).map n' :=
(map_mapβ_antidistrib_right $ Ξ» a b, (h_right_anticomm b a).symm).symm
end filter
|
21adfc14a8bf998c136ea0d0c81592f8e5ba44ff
|
22e97a5d648fc451e25a06c668dc03ac7ed7bc25
|
/src/measure_theory/simple_func_dense.lean
|
e56cce3f712ea686c692a375adb39a2bf5d4524c
|
[
"Apache-2.0"
] |
permissive
|
keeferrowan/mathlib
|
f2818da875dbc7780830d09bd4c526b0764a4e50
|
aad2dfc40e8e6a7e258287a7c1580318e865817e
|
refs/heads/master
| 1,661,736,426,952
| 1,590,438,032,000
| 1,590,438,032,000
| 266,892,663
| 0
| 0
|
Apache-2.0
| 1,590,445,835,000
| 1,590,445,835,000
| null |
UTF-8
|
Lean
| false
| false
| 14,920
|
lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import measure_theory.l1_space
/-!
# Density of simple functions
Show that each Borel measurable function can be approximated,
both pointwise and in `LΒΉ` norm, by a sequence of simple functions.
-/
noncomputable theory
open set filter topological_space
open_locale classical topological_space
universes u v
variables {Ξ± : Type u} {Ξ² : Type v} {ΞΉ : Type*}
namespace measure_theory
open ennreal nat metric
variables [measure_space Ξ±] [normed_group Ξ²] [second_countable_topology Ξ²]
[measurable_space Ξ²] [borel_space Ξ²]
local infixr ` ββ `:25 := simple_func
-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`
-- It should be broken in a sequence of more manageable pieces.
lemma simple_func_sequence_tendsto {f : Ξ± β Ξ²} (hf : measurable f) :
β (F : β β (Ξ± ββ Ξ²)), β x : Ξ±, tendsto (Ξ» n, F n x) at_top (π (f x)) β§
β n, β₯F n xβ₯ β€ β₯f xβ₯ + β₯f xβ₯ :=
-- enumerate a countable dense subset {e k} of Ξ²
let β¨D, β¨D_countable, D_denseβ©β© := @separable_space.exists_countable_closure_eq_univ Ξ² _ _ in
let e := enumerate_countable D_countable 0 in
let E := range e in
have E_dense : closure E = univ :=
dense_of_subset_dense (subset_range_enumerate D_countable 0) D_dense,
let A' (N k : β) : set Ξ± :=
f β»ΒΉ' (metric.ball (e k) (1 / (N+1 : β)) \ metric.ball 0 (1 / (N+1 : β))) in
let A N := disjointed (A' N) in
have is_measurable_A' : β {N k}, is_measurable (A' N k) :=
Ξ» N k, hf.preimage $ is_measurable.inter is_measurable_ball $ is_measurable.compl is_measurable_ball,
have is_measurable_A : β {N k}, is_measurable (A N k) :=
Ξ» N, is_measurable.disjointed $ Ξ» k, is_measurable_A',
have A_subset_A' : β {N k x}, x β A N k β x β A' N k := Ξ» N k, inter_subset_left _ _,
have dist_ek_fx' : β {x N k}, x β A' N k β (dist (e k) (f x) < 1 / (N+1 : β)) :=
Ξ» x N k, by { rw [dist_comm], simpa using (Ξ» a b, a) },
have dist_ek_fx : β {x N k}, x β A N k β (dist (e k) (f x) < 1 / (N+1 : β)) :=
Ξ» x N k h, dist_ek_fx' (A_subset_A' h),
have norm_fx' : β {x N k}, x β A' N k β (1 / (N+1 : β)) β€ β₯f xβ₯ := Ξ» x N k, by simp [ball_0_eq],
have norm_fx : β {x N k}, x β A N k β (1 / (N+1 : β)) β€ β₯f xβ₯ := Ξ» x N k h, norm_fx' (A_subset_A' h),
-- construct the desired sequence of simple functions
let M N x := nat.find_greatest (Ξ» M, x β β k β€ N, (A M k)) N in
let k N x := nat.find_greatest (Ξ» k, x β A (M N x) k) N in
let F N x := if x β β M β€ N, β k β€ N, A M k then e (k N x) else 0 in
-- prove properties of the construction above
have k_unique : β {M k k' x}, x β A M k β§ x β A M k' β k = k' := Ξ» M k k' x h,
begin
by_contradiction k_ne_k',
have NE : (A M k β© A M k').nonempty, from β¨x, hβ©,
have E : A M k β© A M k' = β
:= disjoint_disjointed' k k' k_ne_k',
exact NE.ne_empty E,
end,
have x_mem_Union_k : β {N x}, (x β β M β€ N, β k β€ N, A M k) β x β β k β€ N, A (M N x) k :=
Ξ» N x h,
@nat.find_greatest_spec (Ξ» M, x β β k β€ N, (A M k)) _ N (
let β¨M, hMβ© := mem_Union.1 (h) in
let β¨hMβ, hMββ© := mem_Union.1 hM in
β¨M, β¨hMβ, hMββ©β©),
have x_mem_A : β {N x}, (x β β M β€ N, β k β€ N, A M k) β x β A (M N x) (k N x) :=
Ξ» N x h,
@nat.find_greatest_spec (Ξ» k, x β A (M N x) k) _ N (
let β¨k, hkβ© := mem_Union.1 (x_mem_Union_k h) in
let β¨hkβ, hkββ© := mem_Union.1 hk in
β¨k, β¨hkβ, hkββ©β©),
have x_mem_A' : β {N x}, (x β β M β€ N, β k β€ N, A M k) β x β A' (M N x) (k N x) :=
Ξ» N x h, mem_of_subset_of_mem (inter_subset_left _ _) (x_mem_A h),
-- prove that for all N, (F N) has finite range
have F_finite : β {N}, finite (range (F N)) :=
begin
assume N, apply finite_range_ite,
{ rw range_comp, apply finite_image, exact finite_range_find_greatest },
{ exact finite_range_const }
end,
-- prove that for all N, (F N) is a measurable function
have F_measurable : β {N}, measurable (F N) :=
begin
assume N, refine measurable.if _ _ measurable_const,
-- show `is_measurable {a : Ξ± | a β β (M : β) (H : M β€ N) (k : β) (H : k β€ N), A M k}`
{ rw set_of_mem_eq, simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable_A] },
-- show `measurable (Ξ» (x : Ξ±), e (k N x))`
apply measurable.comp measurable_from_nat, apply measurable_find_greatest,
assume k' k'_le_N, by_cases k'_eq_0 : k' = 0,
-- if k' = 0
have : {x | k N x = 0} = (-β (M : β) (H : M β€ N) (k : β) (H : k β€ N), A M k) βͺ
(β (m β€ N), A m 0 - β m' (hmm' : m < m') (hm'N : m' β€ N) (k β€ N), A m' k),
{ ext, split,
{ rw [mem_set_of_eq, mem_union_eq, or_iff_not_imp_left, mem_compl_eq, not_not_mem],
assume k_eq_0 x_mem,
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff],
refine β¨M N x, β¨nat.find_greatest_le, β¨by { rw β k_eq_0, exact x_mem_A x_mem} , _β©β©β©,
assume m hMm hmN k k_le_N,
have := nat.find_greatest_is_greatest _ m β¨hMm, hmNβ©,
{ simp only [not_exists, exists_prop, mem_Union, not_and] at this, exact this k k_le_N },
{ exact β¨M N x, β¨nat.find_greatest_le, x_mem_Union_k x_memβ©β© } },
{ simp only [mem_set_of_eq, mem_union_eq, mem_compl_eq],
by_cases x_mem : (x β β (M : β) (H : M β€ N) (k : β) (H : k β€ N), A M k),
{ intro, apply find_greatest_eq_zero, assume k k_le_N hx,
have : x β β (M : β) (H : M β€ N) (k : β) (H : k β€ N), A M k,
{ simp only [mem_Union], use [M N x, nat.find_greatest_le, k, k_le_N, hx] },
contradiction },
{ rw not_not_mem at x_mem, assume h, cases h, contradiction,
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff] at h,
rcases h with β¨m, β¨m_le_N, β¨hx, hmβ©β©β©,
by_cases m_lt_M : m < M N x,
{ have := hm (M N x) m_lt_M nat.find_greatest_le (k N x) nat.find_greatest_le,
have := x_mem_A x_mem,
contradiction },
rw not_lt at m_lt_M, by_cases m_gt_M : m > M N x,
{ have := nat.find_greatest_is_greatest _ m β¨m_gt_M, m_le_Nβ©,
{ have : x β β k β€ N, A m k,
{ exact mem_bUnion (nat.zero_le N) hx },
contradiction },
{ exact β¨m, m_le_N, mem_bUnion (nat.zero_le _) hxβ© } },
rw not_lt at m_gt_M, have M_eq_m := le_antisymm m_lt_M m_gt_M,
rw β k'_eq_0, exact k_unique β¨x_mem_A x_mem, by { rw [k'_eq_0, M_eq_m], exact hx }β© } } },
-- end of `have`
rw [k'_eq_0, this], apply is_measurable.union,
{ apply is_measurable.compl,
simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable_A] },
{ simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable.diff, is_measurable_A] },
-- if k' β 0
have : {x | k N x = k'} = β(m β€ N), A m k' - βm' (hmm' : m < m') (hm'N : m' β€ N) (k β€ N), A m' k,
{ ext, split,
{ rw [mem_set_of_eq],
assume k_eq_k',
have x_mem : x β β (M : β) (H : M β€ N) (k : β) (H : k β€ N), A M k,
{ have := find_greatest_of_ne_zero k_eq_k' k'_eq_0,
simp only [mem_Union], use [M N x, nat.find_greatest_le, k', k'_le_N, this] },
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff],
refine β¨M N x, β¨nat.find_greatest_le, β¨by { rw β k_eq_k', exact x_mem_A x_mem} , _β©β©β©,
assume m hMm hmN k k_le_N,
have := nat.find_greatest_is_greatest _ m β¨hMm, hmNβ©,
{ simp only [not_exists, exists_prop, mem_Union, not_and] at this, exact this k k_le_N },
exact β¨M N x, β¨nat.find_greatest_le, x_mem_Union_k x_memβ©β© },
{ simp only [mem_set_of_eq, mem_union_eq, mem_compl_eq], assume h,
have x_mem : x β β (M : β) (H : M β€ N) (k : β) (H : k β€ N), A M k,
{ simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff] at h,
rcases h with β¨m, hm, hx, _β©,
simp only [mem_Union], use [m, hm, k', k'_le_N, hx] },
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff] at h,
rcases h with β¨m, β¨m_le_N, β¨hx, hmβ©β©β©,
by_cases m_lt_M : m < M N x,
{ have := hm (M N x) m_lt_M nat.find_greatest_le (k N x) nat.find_greatest_le,
have := x_mem_A x_mem,
contradiction },
rw not_lt at m_lt_M, by_cases m_gt_M : m > M N x,
{ have := nat.find_greatest_is_greatest _ m β¨m_gt_M, m_le_Nβ©,
have : x β β k β€ N, A m k := mem_bUnion k'_le_N hx,
contradiction,
{ simp only [mem_Union], use [m, m_le_N, k', k'_le_N, hx] }},
rw not_lt at m_gt_M, have M_eq_m := le_antisymm m_lt_M m_gt_M,
exact k_unique β¨x_mem_A x_mem, by { rw M_eq_m, exact hx }β© } },
-- end of `have`
rw this, simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable.diff, is_measurable_A]
end,
-- start of proof
β¨Ξ» N, β¨F N, Ξ» x, measurable.preimage F_measurable is_measurable_singleton, F_finiteβ©,
-- The pointwise convergence part of the theorem
Ξ» x, β¨metric.tendsto_at_top.2 $ Ξ» Ξ΅ hΞ΅, classical.by_cases
--first case : f x = 0
( assume fx_eq_0 : f x = 0,
have x_not_mem_A' : β {M k}, x β A' M k := Ξ» M k,
begin
simp only [mem_preimage, fx_eq_0, metric.mem_ball, one_div_eq_inv, norm_zero,
not_and, not_lt, add_comm, not_le, dist_zero_right, mem_diff],
assume h, rw add_comm, exact inv_pos_of_nat
end,
have x_not_mem_A : β {M k}, x β A M k :=
by { assume M k h, have := disjointed_subset h, exact absurd this x_not_mem_A' },
have F_eq_0 : β {N}, F N x = 0 := Ξ» N, by simp [F, if_neg, mem_Union, x_not_mem_A],
-- end of `have`
β¨0, Ξ» n hn, show dist (F n x) (f x) < Ξ΅, by {rw [fx_eq_0, F_eq_0, dist_self], exact hΞ΅}β© )
--second case : f x β 0
( assume fx_ne_0 : f x β 0,
let β¨Nβ, hNβ© := exists_nat_one_div_lt (lt_min (norm_pos_iff.2 fx_ne_0) hΞ΅) in
have norm_fx_gt : _ := (lt_min_iff.1 hN).1,
have Ξ΅_gt : _ := (lt_min_iff.1 hN).2,
have x_mem_Union_k_Nβ : x β β k, A Nβ k :=
let β¨k, hkβ© := mem_closure_range_iff_nat.1 (by { rw E_dense, exact mem_univ (f x) }) Nβ in
begin
rw [Union_disjointed, mem_Union], use k,
rw [mem_preimage], simp, rw [β one_div_eq_inv],
exact β¨hk, le_of_lt norm_fx_gtβ©
end,
let β¨kβ, x_mem_Aβ© := mem_Union.1 x_mem_Union_k_Nβ in
let n := max Nβ kβ in
have x_mem_Union_Union : β {N} (hN : n β€ N), x β β M β€ N, β k β€ N, A M k := assume N hN,
mem_Union.2
β¨Nβ, mem_Union.2
β¨le_trans (le_max_left _ _) hN, mem_Union.2
β¨kβ, mem_Union.2 β¨le_trans (le_max_right _ _) hN, x_mem_Aβ©β©β©β©,
have FN_eq : β {N} (hN : n β€ N), F N x = e (k N x) := assume N hN, if_pos $ x_mem_Union_Union hN,
-- start of proof
β¨n, assume N hN,
have Nβ_le_N : Nβ β€ N := le_trans (le_max_left _ _) hN,
have kβ_le_N : kβ β€ N := le_trans (le_max_right _ _) hN,
show dist (F N x) (f x) < Ξ΅, from
calc
dist (F N x) (f x) = dist (e (k N x)) (f x) : by rw FN_eq hN
... < 1 / ((M N x : β) + 1) :
begin
have := x_mem_A' (x_mem_Union_Union hN),
rw [mem_preimage, mem_diff, metric.mem_ball, dist_comm] at this, exact this.1
end
... β€ 1 / ((Nβ : β) + 1) :
@one_div_le_one_div_of_le _ _ ((Nβ : β) + 1) ((M N x : β) + 1) (nat.cast_add_one_pos Nβ)
(add_le_add_right (nat.cast_le.2 (nat.le_find_greatest Nβ_le_N (mem_bUnion kβ_le_N x_mem_A))) 1)
... < Ξ΅ : Ξ΅_gt β© ),
-- second part of the theorem
assume N, show β₯F N xβ₯ β€ β₯f xβ₯ + β₯f xβ₯, from
classical.by_cases
( assume h : x β β M β€ N, β k β€ N, A M k,
calc
β₯F N xβ₯ = dist (F N x) 0 : by simp
... = dist (e (k N x)) 0 : begin simp only [F], rw if_pos h end
... β€ dist (e (k N x)) (f x) + dist (f x) 0 : dist_triangle _ _ _
... = dist (e (k N x)) (f x) + β₯f xβ₯ : by simp
... β€ 1 / ((M N x : β) + 1) + β₯f xβ₯ :
le_of_lt $ add_lt_add_right (dist_ek_fx (x_mem_A h)) _
... β€ β₯f xβ₯ + β₯f xβ₯ : add_le_add_right (norm_fx (x_mem_A h) ) _)
( assume h : x β β M β€ N, β k β€ N, A M k,
have F_eq_0 : F N x = 0 := if_neg h,
by { simp only [F_eq_0, norm_zero], exact add_nonneg (norm_nonneg _) (norm_nonneg _) } )β©β©
lemma simple_func_sequence_tendsto' {f : Ξ± β Ξ²} (hfm : measurable f)
(hfi : integrable f) : β (F : β β (Ξ± ββ Ξ²)), (βn, integrable (F n)) β§
tendsto (Ξ» n, β«β» x, nndist (F n x) (f x)) at_top (π 0) :=
let β¨F, hFβ© := simple_func_sequence_tendsto hfm in
let G : β β Ξ± β ennreal := Ξ»n x, nndist (F n x) (f x) in
let g : Ξ± β ennreal := Ξ»x, nnnorm (f x) + nnnorm (f x) + nnnorm (f x) in
have hF_meas : β n, measurable (G n) := Ξ» n, measurable.comp measurable_coe $
(F n).measurable.nndist hfm,
have hg_meas : measurable g := measurable.comp measurable_coe $ measurable.add
(measurable.add hfm.nnnorm hfm.nnnorm) hfm.nnnorm,
have h_bound : β n, ββ x, G n x β€ g x := Ξ» n, all_ae_of_all $ Ξ» x, coe_le_coe.2 $
calc
nndist (F n x) (f x) β€ nndist (F n x) 0 + nndist 0 (f x) : nndist_triangle _ _ _
... = nnnorm (F n x) + nnnorm (f x) : by simp [nndist_eq_nnnorm]
... β€ nnnorm (f x) + nnnorm (f x) + nnnorm (f x) :
by { simp [nnreal.coe_le_coe.symm, (hF x).2, add_comm] },
have h_finite : lintegral g < β€ :=
calc
(β«β» x, nnnorm (f x) + nnnorm (f x) + nnnorm (f x)) =
(β«β» x, nnnorm (f x)) + (β«β» x, nnnorm (f x)) + (β«β» x, nnnorm (f x)) :
by { rw [lintegral_add, lintegral_nnnorm_add],
exacts [hfm, hfm, hfm.ennnorm.add hfm.ennnorm, hfm.ennnorm] }
... < β€ : by { simp only [and_self, add_lt_top], exact hfi},
have h_lim : ββ x, tendsto (Ξ» n, G n x) at_top (π 0) := all_ae_of_all $ Ξ» x,
begin
apply (@tendsto_coe β at_top (Ξ» n, nndist (F n x) (f x)) 0).2,
apply (@nnreal.tendsto_coe β at_top (Ξ» n, nndist (F n x) (f x)) 0).1,
apply tendsto_iff_dist_tendsto_zero.1 (hF x).1
end,
begin
use F, split,
{ assume n, exact
calc
(β«β» a, nnnorm (F n a)) β€ β«β» a, nnnorm (f a) + nnnorm (f a) :
lintegral_mono
(by { assume a, simp only [coe_add.symm, coe_le_coe], exact (hF a).2 n })
... = (β«β» a, nnnorm (f a)) + (β«β» a, nnnorm (f a)) :
lintegral_nnnorm_add hfm hfm
... < β€ : by simp only [add_lt_top, and_self]; exact hfi },
convert @tendsto_lintegral_of_dominated_convergence _ _ G (Ξ» a, 0) g
hF_meas h_bound h_finite h_lim,
simp only [lintegral_zero]
end
end measure_theory
|
c0228a74275c43b3f16a5602a70f1710f212279a
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/number_theory/padics/ring_homs.lean
|
c5e60e21d58708ea74f23e97a2471562e9e045b0
|
[
"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
| 24,407
|
lean
|
/-
Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import data.zmod.basic
import number_theory.padics.padic_integers
/-!
# Relating `β€_[p]` to `zmod (p ^ n)`
In this file we establish connections between the `p`-adic integers $\mathbb{Z}_p$
and the integers modulo powers of `p`, $\mathbb{Z}/p^n\mathbb{Z}$.
## Main declarations
We show that $\mathbb{Z}_p$ has a ring hom to $\mathbb{Z}/p^n\mathbb{Z}$ for each `n`.
The case for `n = 1` is handled separately, since it is used in the general construction
and we may want to use it without the `^1` getting in the way.
* `padic_int.to_zmod`: ring hom to `zmod p`
* `padic_int.to_zmod_pow`: ring hom to `zmod (p^n)`
* `padic_int.ker_to_zmod` / `padic_int.ker_to_zmod_pow`: the kernels of these maps are the ideals
generated by `p^n`
We also establish the universal property of $\mathbb{Z}_p$ as a projective limit.
Given a family of compatible ring homs $f_k : R \to \mathbb{Z}/p^n\mathbb{Z}$,
there is a unique limit $R \to \mathbb{Z}_p$.
* `padic_int.lift`: the limit function
* `padic_int.lift_spec` / `padic_int.lift_unique`: the universal property
## Implementation notes
The ring hom constructions go through an auxiliary constructor `padic_int.to_zmod_hom`,
which removes some boilerplate code.
-/
noncomputable theory
open_locale classical
open nat local_ring padic
namespace padic_int
variables {p : β} [hp_prime : fact (p.prime)]
include hp_prime
section ring_homs
/-! ### Ring homomorphisms to `zmod p` and `zmod (p ^ n)` -/
variables (p) (r : β)
omit hp_prime
/--
`mod_part p r` is an integer that satisfies
`β₯(r - mod_part p r : β_[p])β₯ < 1` when `β₯(r : β_[p])β₯ β€ 1`,
see `padic_int.norm_sub_mod_part`.
It is the unique non-negative integer that is `< p` with this property.
(Note that this definition assumes `r : β`.
See `padic_int.zmod_repr` for a version that takes values in `β`
and works for arbitrary `x : β€_[p]`.) -/
def mod_part : β€ :=
(r.num * gcd_a r.denom p) % p
include hp_prime
variable {p}
lemma mod_part_lt_p : mod_part p r < p :=
begin
convert int.mod_lt _ _,
{ simp },
{ exact_mod_cast hp_prime.1.ne_zero }
end
lemma mod_part_nonneg : 0 β€ mod_part p r :=
int.mod_nonneg _ $ by exact_mod_cast hp_prime.1.ne_zero
lemma is_unit_denom (r : β) (h : β₯(r : β_[p])β₯ β€ 1) : is_unit (r.denom : β€_[p]) :=
begin
rw is_unit_iff,
apply le_antisymm (r.denom : β€_[p]).2,
rw [β not_lt, val_eq_coe, coe_coe],
intro norm_denom_lt,
have hr : β₯(r * r.denom : β_[p])β₯ = β₯(r.num : β_[p])β₯,
{ rw_mod_cast @rat.mul_denom_eq_num r, refl, },
rw padic_norm_e.mul at hr,
have key : β₯(r.num : β_[p])β₯ < 1,
{ calc _ = _ : hr.symm
... < 1 * 1 : mul_lt_mul' h norm_denom_lt (norm_nonneg _) zero_lt_one
... = 1 : mul_one 1 },
have : βp β£ r.num β§ (p : β€) β£ r.denom,
{ simp only [β norm_int_lt_one_iff_dvd, β padic_norm_e_of_padic_int],
norm_cast, exact β¨key, norm_denom_ltβ© },
apply hp_prime.1.not_dvd_one,
rwa [β r.cop.gcd_eq_one, nat.dvd_gcd_iff, β int.coe_nat_dvd_left, β int.coe_nat_dvd],
end
lemma norm_sub_mod_part_aux (r : β) (h : β₯(r : β_[p])β₯ β€ 1) :
βp β£ r.num - r.num * r.denom.gcd_a p % p * β(r.denom) :=
begin
rw β zmod.int_coe_zmod_eq_zero_iff_dvd,
simp only [int.cast_coe_nat, zmod.nat_cast_mod, int.cast_mul, int.cast_sub],
have := congr_arg (coe : β€ β zmod p) (gcd_eq_gcd_ab r.denom p),
simp only [int.cast_coe_nat, add_zero, int.cast_add, zmod.nat_cast_self, int.cast_mul, zero_mul]
at this,
push_cast,
rw [mul_right_comm, mul_assoc, βthis],
suffices rdcp : r.denom.coprime p,
{ rw rdcp.gcd_eq_one, simp only [mul_one, cast_one, sub_self], },
apply coprime.symm,
apply (coprime_or_dvd_of_prime hp_prime.1 _).resolve_right,
rw [β int.coe_nat_dvd, β norm_int_lt_one_iff_dvd, not_lt],
apply ge_of_eq,
rw β is_unit_iff,
exact is_unit_denom r h,
end
lemma norm_sub_mod_part (h : β₯(r : β_[p])β₯ β€ 1) : β₯(β¨r,hβ© - mod_part p r : β€_[p])β₯ < 1 :=
begin
let n := mod_part p r,
rw [norm_lt_one_iff_dvd, β (is_unit_denom r h).dvd_mul_right],
suffices : βp β£ r.num - n * r.denom,
{ convert (int.cast_ring_hom β€_[p]).map_dvd this,
simp only [sub_mul, int.cast_coe_nat, ring_hom.eq_int_cast, int.cast_mul,
sub_left_inj, int.cast_sub],
apply subtype.coe_injective,
simp only [coe_mul, subtype.coe_mk, coe_coe],
rw_mod_cast @rat.mul_denom_eq_num r, refl },
exact norm_sub_mod_part_aux r h
end
lemma exists_mem_range_of_norm_rat_le_one (h : β₯(r : β_[p])β₯ β€ 1) :
β n : β€, 0 β€ n β§ n < p β§ β₯(β¨r,hβ© - n : β€_[p])β₯ < 1 :=
β¨mod_part p r, mod_part_nonneg _, mod_part_lt_p _, norm_sub_mod_part _ hβ©
lemma zmod_congr_of_sub_mem_span_aux (n : β) (x : β€_[p]) (a b : β€)
(ha : x - a β (ideal.span {p ^ n} : ideal β€_[p]))
(hb : x - b β (ideal.span {p ^ n} : ideal β€_[p])) :
(a : zmod (p ^ n)) = b :=
begin
rw [ideal.mem_span_singleton] at ha hb,
rw [β sub_eq_zero, β int.cast_sub,
zmod.int_coe_zmod_eq_zero_iff_dvd, int.coe_nat_pow],
rw [β dvd_neg, neg_sub] at ha,
have := dvd_add ha hb,
rwa [sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left,
β sub_eq_add_neg, β int.cast_sub, pow_p_dvd_int_iff] at this,
end
lemma zmod_congr_of_sub_mem_span (n : β) (x : β€_[p]) (a b : β)
(ha : x - a β (ideal.span {p ^ n} : ideal β€_[p]))
(hb : x - b β (ideal.span {p ^ n} : ideal β€_[p])) :
(a : zmod (p ^ n)) = b :=
zmod_congr_of_sub_mem_span_aux n x a b ha hb
lemma zmod_congr_of_sub_mem_max_ideal (x : β€_[p]) (m n : β)
(hm : x - m β maximal_ideal β€_[p]) (hn : x - n β maximal_ideal β€_[p]) :
(m : zmod p) = n :=
begin
rw maximal_ideal_eq_span_p at hm hn,
have := zmod_congr_of_sub_mem_span_aux 1 x m n,
simp only [pow_one] at this,
specialize this hm hn,
apply_fun zmod.cast_hom (show p β£ p ^ 1, by rw pow_one) (zmod p) at this,
simpa only [ring_hom.map_int_cast],
end
variable (x : β€_[p])
lemma exists_mem_range : β n : β, n < p β§ (x - n β maximal_ideal β€_[p]) :=
begin
simp only [maximal_ideal_eq_span_p, ideal.mem_span_singleton, β norm_lt_one_iff_dvd],
obtain β¨r, hrβ© := rat_dense (x : β_[p]) zero_lt_one,
have H : β₯(r : β_[p])β₯ β€ 1,
{ rw norm_sub_rev at hr,
calc _ = β₯(r : β_[p]) - x + xβ₯ : by ring_nf
... β€ _ : padic_norm_e.nonarchimedean _ _
... β€ _ : max_le (le_of_lt hr) x.2 },
obtain β¨n, hzn, hnp, hnβ© := exists_mem_range_of_norm_rat_le_one r H,
lift n to β using hzn,
use n,
split, {exact_mod_cast hnp},
simp only [norm_def, coe_sub, subtype.coe_mk, coe_coe] at hn β’,
rw show (x - n : β_[p]) = (x - r) + (r - n), by ring,
apply lt_of_le_of_lt (padic_norm_e.nonarchimedean _ _),
apply max_lt hr,
simpa using hn
end
/--
`zmod_repr x` is the unique natural number smaller than `p`
satisfying `β₯(x - zmod_repr x : β€_[p])β₯ < 1`.
-/
def zmod_repr : β :=
classical.some (exists_mem_range x)
lemma zmod_repr_spec : zmod_repr x < p β§ (x - zmod_repr x β maximal_ideal β€_[p]) :=
classical.some_spec (exists_mem_range x)
lemma zmod_repr_lt_p : zmod_repr x < p := (zmod_repr_spec _).1
lemma sub_zmod_repr_mem : (x - zmod_repr x β maximal_ideal β€_[p]) := (zmod_repr_spec _).2
/--
`to_zmod_hom` is an auxiliary constructor for creating ring homs from `β€_[p]` to `zmod v`.
-/
def to_zmod_hom (v : β) (f : β€_[p] β β) (f_spec : β x, x - f x β (ideal.span {v} : ideal β€_[p]))
(f_congr : β (x : β€_[p]) (a b : β),
x - a β (ideal.span {v} : ideal β€_[p]) β x - b β (ideal.span {v} : ideal β€_[p]) β
(a : zmod v) = b) :
β€_[p] β+* zmod v :=
{ to_fun := Ξ» x, f x,
map_zero' :=
begin
rw [f_congr (0 : β€_[p]) _ 0, cast_zero],
{ exact f_spec _ },
{ simp only [sub_zero, cast_zero, submodule.zero_mem], }
end,
map_one' :=
begin
rw [f_congr (1 : β€_[p]) _ 1, cast_one],
{ exact f_spec _ },
{ simp only [sub_self, cast_one, submodule.zero_mem], }
end,
map_add' :=
begin
intros x y,
rw [f_congr (x + y) _ (f x + f y), cast_add],
{ exact f_spec _ },
{ convert ideal.add_mem _ (f_spec x) (f_spec y),
rw cast_add,
ring, }
end,
map_mul' :=
begin
intros x y,
rw [f_congr (x * y) _ (f x * f y), cast_mul],
{ exact f_spec _ },
{ let I : ideal β€_[p] := ideal.span {v},
convert I.add_mem (I.mul_mem_left x (f_spec y)) (I.mul_mem_right (f y) (f_spec x)),
rw cast_mul,
ring, }
end, }
/--
`to_zmod` is a ring hom from `β€_[p]` to `zmod p`,
with the equality `to_zmod x = (zmod_repr x : zmod p)`.
-/
def to_zmod : β€_[p] β+* zmod p :=
to_zmod_hom p zmod_repr
(by { rw βmaximal_ideal_eq_span_p, exact sub_zmod_repr_mem })
(by { rw βmaximal_ideal_eq_span_p, exact zmod_congr_of_sub_mem_max_ideal } )
/--
`z - (to_zmod z : β€_[p])` is contained in the maximal ideal of `β€_[p]`, for every `z : β€_[p]`.
The coercion from `zmod p` to `β€_[p]` is `zmod.has_coe_t`,
which coerces `zmod p` into artibrary rings.
This is unfortunate, but a consequence of the fact that we allow `zmod p`
to coerce to rings of arbitrary characteristic, instead of only rings of characteristic `p`.
This coercion is only a ring homomorphism if it coerces into a ring whose characteristic divides
`p`. While this is not the case here we can still make use of the coercion.
-/
lemma to_zmod_spec (z : β€_[p]) : z - (to_zmod z : β€_[p]) β maximal_ideal β€_[p] :=
begin
convert sub_zmod_repr_mem z using 2,
dsimp [to_zmod, to_zmod_hom],
unfreezingI { rcases (exists_eq_add_of_lt (hp_prime.1.pos)) with β¨p', rflβ© },
change β(zmod.val _) = _,
simp only [zmod.val_nat_cast, add_zero, add_def, nat.cast_inj, zero_add],
apply mod_eq_of_lt,
simpa only [zero_add] using zmod_repr_lt_p z,
end
lemma ker_to_zmod : (to_zmod : β€_[p] β+* zmod p).ker = maximal_ideal β€_[p] :=
begin
ext x,
rw ring_hom.mem_ker,
split,
{ intro h,
simpa only [h, zmod.cast_zero, sub_zero] using to_zmod_spec x, },
{ intro h,
rw β sub_zero x at h,
dsimp [to_zmod, to_zmod_hom],
convert zmod_congr_of_sub_mem_max_ideal x _ 0 _ h,
apply sub_zmod_repr_mem, }
end
/-- `appr n x` gives a value `v : β` such that `x` and `βv : β€_p` are congruent mod `p^n`.
See `appr_spec`. -/
noncomputable def appr : β€_[p] β β β β
| x 0 := 0
| x (n+1) :=
let y := x - appr x n in
if hy : y = 0 then
appr x n
else
let u := unit_coeff hy in
appr x n + p ^ n * (to_zmod ((u : β€_[p]) * (p ^ (y.valuation - n).nat_abs))).val
lemma appr_lt (x : β€_[p]) (n : β) : x.appr n < p ^ n :=
begin
induction n with n ih generalizing x,
{ simp only [appr, succ_pos', pow_zero], },
simp only [appr, map_nat_cast, zmod.nat_cast_self, ring_hom.map_pow, int.nat_abs,
ring_hom.map_mul],
have hp : p ^ n < p ^ (n + 1),
{ apply pow_lt_pow hp_prime.1.one_lt (lt_add_one n) },
split_ifs with h,
{ apply lt_trans (ih _) hp, },
{ calc _ < p ^ n + p ^ n * (p - 1) : _
... = p ^ (n + 1) : _,
{ apply add_lt_add_of_lt_of_le (ih _),
apply nat.mul_le_mul_left,
apply le_pred_of_lt,
apply zmod.val_lt },
{ rw [mul_tsub, mul_one, β pow_succ'],
apply add_tsub_cancel_of_le (le_of_lt hp) } }
end
lemma appr_mono (x : β€_[p]) : monotone x.appr :=
begin
apply monotone_nat_of_le_succ,
intro n,
dsimp [appr],
split_ifs, { refl, },
apply nat.le_add_right,
end
lemma dvd_appr_sub_appr (x : β€_[p]) (m n : β) (h : m β€ n) :
p ^ m β£ x.appr n - x.appr m :=
begin
obtain β¨k, rflβ© := nat.exists_eq_add_of_le h, clear h,
induction k with k ih,
{ simp only [add_zero, tsub_self, dvd_zero], },
rw [nat.succ_eq_add_one, β add_assoc],
dsimp [appr],
split_ifs with h,
{ exact ih },
rw [add_comm, add_tsub_assoc_of_le (appr_mono _ (nat.le_add_right m k))],
apply dvd_add _ ih,
apply dvd_mul_of_dvd_left,
apply pow_dvd_pow _ (nat.le_add_right m k),
end
lemma appr_spec (n : β) : β (x : β€_[p]), x - appr x n β (ideal.span {p^n} : ideal β€_[p]) :=
begin
simp only [ideal.mem_span_singleton],
induction n with n ih,
{ simp only [is_unit_one, is_unit.dvd, pow_zero, forall_true_iff], },
intro x,
dsimp only [appr],
split_ifs with h,
{ rw h, apply dvd_zero },
push_cast, rw sub_add_eq_sub_sub,
obtain β¨c, hcβ© := ih x,
simp only [map_nat_cast, zmod.nat_cast_self, ring_hom.map_pow, ring_hom.map_mul,
zmod.nat_cast_val],
have hc' : c β 0,
{ rintro rfl, simp only [mul_zero] at hc, contradiction },
conv_rhs { congr, simp only [hc], },
rw show (x - β(appr x n)).valuation = (βp ^ n * c).valuation,
{ rw hc },
rw [valuation_p_pow_mul _ _ hc', add_sub_cancel', pow_succ', β mul_sub],
apply mul_dvd_mul_left,
obtain hc0 | hc0 := c.valuation.nat_abs.eq_zero_or_pos,
{ simp only [hc0, mul_one, pow_zero],
rw [mul_comm, unit_coeff_spec h] at hc,
suffices : c = unit_coeff h,
{ rw [β this, β ideal.mem_span_singleton, β maximal_ideal_eq_span_p],
apply to_zmod_spec },
obtain β¨c, rflβ© : is_unit c, -- TODO: write a can_lift instance for units
{ rw int.nat_abs_eq_zero at hc0,
rw [is_unit_iff, norm_eq_pow_val hc', hc0, neg_zero, zpow_zero], },
rw discrete_valuation_ring.unit_mul_pow_congr_unit _ _ _ _ _ hc,
exact irreducible_p },
{ rw zero_pow hc0,
simp only [sub_zero, zmod.cast_zero, mul_zero],
rw unit_coeff_spec hc',
exact (dvd_pow_self (p : β€_[p]) hc0.ne').mul_left _, },
end
attribute [irreducible] appr
/-- A ring hom from `β€_[p]` to `zmod (p^n)`, with underlying function `padic_int.appr n`. -/
def to_zmod_pow (n : β) : β€_[p] β+* zmod (p ^ n) :=
to_zmod_hom (p^n) (Ξ» x, appr x n)
(by { intros, convert appr_spec n _ using 1, simp })
(by { intros x a b ha hb,
apply zmod_congr_of_sub_mem_span n x a b,
{ simpa using ha },
{ simpa using hb } })
lemma ker_to_zmod_pow (n : β) : (to_zmod_pow n : β€_[p] β+* zmod (p ^ n)).ker = ideal.span {p ^ n} :=
begin
ext x,
rw ring_hom.mem_ker,
split,
{ intro h,
suffices : x.appr n = 0,
{ convert appr_spec n x, simp only [this, sub_zero, cast_zero], },
dsimp [to_zmod_pow, to_zmod_hom] at h,
rw zmod.nat_coe_zmod_eq_zero_iff_dvd at h,
apply eq_zero_of_dvd_of_lt h (appr_lt _ _), },
{ intro h,
rw β sub_zero x at h,
dsimp [to_zmod_pow, to_zmod_hom],
rw [zmod_congr_of_sub_mem_span n x _ 0 _ h, cast_zero],
apply appr_spec, }
end
@[simp] lemma zmod_cast_comp_to_zmod_pow (m n : β) (h : m β€ n) :
(zmod.cast_hom (pow_dvd_pow p h) (zmod (p ^ m))).comp (to_zmod_pow n) = to_zmod_pow m :=
begin
apply zmod.ring_hom_eq_of_ker_eq,
ext x,
rw [ring_hom.mem_ker, ring_hom.mem_ker],
simp only [function.comp_app, zmod.cast_hom_apply, ring_hom.coe_comp],
simp only [to_zmod_pow, to_zmod_hom, ring_hom.coe_mk],
rw [zmod.cast_nat_cast (pow_dvd_pow p h),
zmod_congr_of_sub_mem_span m (x.appr n) (x.appr n) (x.appr m)],
{ rw [sub_self], apply ideal.zero_mem _, },
{ rw ideal.mem_span_singleton,
rcases dvd_appr_sub_appr x m n h with β¨c, hcβ©,
use c,
rw [β nat.cast_sub (appr_mono _ h), hc, nat.cast_mul, nat.cast_pow], },
{ apply_instance }
end
@[simp] lemma cast_to_zmod_pow (m n : β) (h : m β€ n) (x : β€_[p]) :
β(to_zmod_pow n x) = to_zmod_pow m x :=
by { rw β zmod_cast_comp_to_zmod_pow _ _ h, refl }
lemma dense_range_nat_cast :
dense_range (nat.cast : β β β€_[p]) :=
begin
intro x,
rw metric.mem_closure_range_iff,
intros Ξ΅ hΞ΅,
obtain β¨n, hnβ© := exists_pow_neg_lt p hΞ΅,
use (x.appr n),
rw dist_eq_norm,
apply lt_of_le_of_lt _ hn,
rw norm_le_pow_iff_mem_span_pow,
apply appr_spec,
end
lemma dense_range_int_cast :
dense_range (int.cast : β€ β β€_[p]) :=
begin
intro x,
apply dense_range_nat_cast.induction_on x,
{ exact is_closed_closure, },
{ intro a,
change (a.cast : β€_[p]) with (a : β€).cast,
apply subset_closure,
exact set.mem_range_self _ }
end
end ring_homs
section lift
/-! ### Universal property as projective limit -/
open cau_seq padic_seq
variables {R : Type*} [non_assoc_semiring R] (f : Ξ k : β, R β+* zmod (p^k))
(f_compat : β k1 k2 (hk : k1 β€ k2), (zmod.cast_hom (pow_dvd_pow p hk) _).comp (f k2) = f k1)
omit hp_prime
/--
Given a family of ring homs `f : Ξ n : β, R β+* zmod (p ^ n)`,
`nth_hom f r` is an integer-valued sequence
whose `n`th value is the unique integer `k` such that `0 β€ k < p ^ n`
and `f n r = (k : zmod (p ^ n))`.
-/
def nth_hom (r : R) : β β β€ :=
Ξ» n, (f n r : zmod (p^n)).val
@[simp] lemma nth_hom_zero : nth_hom f 0 = 0 :=
by simp [nth_hom]; refl
variable {f}
include hp_prime
include f_compat
lemma pow_dvd_nth_hom_sub (r : R) (i j : β) (h : i β€ j) :
βp ^ i β£ nth_hom f r j - nth_hom f r i :=
begin
specialize f_compat i j h,
rw [β int.coe_nat_pow, β zmod.int_coe_zmod_eq_zero_iff_dvd,
int.cast_sub],
dsimp [nth_hom],
rw [β f_compat, ring_hom.comp_apply],
have : fact (p ^ i > 0) := β¨pow_pos hp_prime.1.pos _β©,
have : fact (p ^ j > 0) := β¨pow_pos hp_prime.1.pos _β©,
unfreezingI { simp only [zmod.cast_id, zmod.cast_hom_apply, sub_self, zmod.nat_cast_val], },
end
lemma is_cau_seq_nth_hom (r : R): is_cau_seq (padic_norm p) (Ξ» n, nth_hom f r n) :=
begin
intros Ξ΅ hΞ΅,
obtain β¨k, hkβ© : β k : β, (p ^ - (β(k : β) : β€) : β) < Ξ΅ := exists_pow_neg_lt_rat p hΞ΅,
use k,
intros j hj,
refine lt_of_le_of_lt _ hk,
norm_cast,
rw β padic_norm.dvd_iff_norm_le,
exact_mod_cast pow_dvd_nth_hom_sub f_compat r k j hj
end
/--
`nth_hom_seq f_compat r` bundles `padic_int.nth_hom f r`
as a Cauchy sequence of rationals with respect to the `p`-adic norm.
The `n`th value of the sequence is `((f n r).val : β)`.
-/
def nth_hom_seq (r : R) : padic_seq p := β¨Ξ» n, nth_hom f r n, is_cau_seq_nth_hom f_compat rβ©
lemma nth_hom_seq_one : nth_hom_seq f_compat 1 β 1 :=
begin
intros Ξ΅ hΞ΅,
change _ < _ at hΞ΅,
use 1,
intros j hj,
haveI : fact (1 < p^j) := β¨nat.one_lt_pow _ _ (by linarith) hp_prime.1.one_ltβ©,
simp [nth_hom_seq, nth_hom, zmod.val_one, hΞ΅],
end
lemma nth_hom_seq_add (r s : R) :
nth_hom_seq f_compat (r + s) β nth_hom_seq f_compat r + nth_hom_seq f_compat s :=
begin
intros Ξ΅ hΞ΅,
obtain β¨n, hnβ© := exists_pow_neg_lt_rat p hΞ΅,
use n,
intros j hj,
dsimp [nth_hom_seq],
apply lt_of_le_of_lt _ hn,
rw [β int.cast_add, β int.cast_sub, β padic_norm.dvd_iff_norm_le,
β zmod.int_coe_zmod_eq_zero_iff_dvd],
dsimp [nth_hom],
have : fact (p ^ n > 0) := β¨pow_pos hp_prime.1.pos _β©,
have : fact (p ^ j > 0) := β¨pow_pos hp_prime.1.pos _β©,
unfreezingI
{ simp only [int.cast_coe_nat, int.cast_add, ring_hom.map_add, int.cast_sub, zmod.nat_cast_val] },
rw [zmod.cast_add (show p ^ n β£ p ^ j, from _), sub_self],
{ apply_instance },
{ apply pow_dvd_pow, linarith only [hj] },
end
lemma nth_hom_seq_mul (r s : R) :
nth_hom_seq f_compat (r * s) β nth_hom_seq f_compat r * nth_hom_seq f_compat s :=
begin
intros Ξ΅ hΞ΅,
obtain β¨n, hnβ© := exists_pow_neg_lt_rat p hΞ΅,
use n,
intros j hj,
dsimp [nth_hom_seq],
apply lt_of_le_of_lt _ hn,
rw [β int.cast_mul, β int.cast_sub, β padic_norm.dvd_iff_norm_le,
β zmod.int_coe_zmod_eq_zero_iff_dvd],
dsimp [nth_hom],
have : fact (p ^ n > 0) := β¨pow_pos hp_prime.1.pos _β©,
have : fact (p ^ j > 0) := β¨pow_pos hp_prime.1.pos _β©,
unfreezingI
{ simp only [int.cast_coe_nat, int.cast_mul, int.cast_sub, ring_hom.map_mul, zmod.nat_cast_val] },
rw [zmod.cast_mul (show p ^ n β£ p ^ j, from _), sub_self],
{ apply_instance },
{ apply pow_dvd_pow, linarith only [hj] },
end
/--
`lim_nth_hom f_compat r` is the limit of a sequence `f` of compatible ring homs `R β+* zmod (p^k)`.
This is itself a ring hom: see `padic_int.lift`.
-/
def lim_nth_hom (r : R) : β€_[p] :=
of_int_seq (nth_hom f r) (is_cau_seq_nth_hom f_compat r)
lemma lim_nth_hom_spec (r : R) :
β Ξ΅ : β, 0 < Ξ΅ β β N : β, β n β₯ N, β₯lim_nth_hom f_compat r - nth_hom f r nβ₯ < Ξ΅ :=
begin
intros Ξ΅ hΞ΅,
obtain β¨Ξ΅', hΞ΅'0, hΞ΅'β© : β v : β, (0 : β) < v β§ βv < Ξ΅ := exists_rat_btwn hΞ΅,
norm_cast at hΞ΅'0,
obtain β¨N, hNβ© := padic_norm_e.defn (nth_hom_seq f_compat r) hΞ΅'0,
use N,
intros n hn,
apply lt_trans _ hΞ΅',
change β(padic_norm_e _) < _,
norm_cast,
convert hN _ hn,
simp [nth_hom, lim_nth_hom, nth_hom_seq, of_int_seq],
end
lemma lim_nth_hom_zero : lim_nth_hom f_compat 0 = 0 :=
by simp [lim_nth_hom]; refl
lemma lim_nth_hom_one : lim_nth_hom f_compat 1 = 1 :=
subtype.ext $ quot.sound $ nth_hom_seq_one _
lemma lim_nth_hom_add (r s : R) :
lim_nth_hom f_compat (r + s) = lim_nth_hom f_compat r + lim_nth_hom f_compat s :=
subtype.ext $ quot.sound $ nth_hom_seq_add _ _ _
lemma lim_nth_hom_mul (r s : R) :
lim_nth_hom f_compat (r * s) = lim_nth_hom f_compat r * lim_nth_hom f_compat s :=
subtype.ext $ quot.sound $ nth_hom_seq_mul _ _ _
-- TODO: generalize this to arbitrary complete discrete valuation rings
/--
`lift f_compat` is the limit of a sequence `f` of compatible ring homs `R β+* zmod (p^k)`,
with the equality `lift f_compat r = padic_int.lim_nth_hom f_compat r`.
-/
def lift : R β+* β€_[p] :=
{ to_fun := lim_nth_hom f_compat,
map_one' := lim_nth_hom_one f_compat,
map_mul' := lim_nth_hom_mul f_compat,
map_zero' := lim_nth_hom_zero f_compat,
map_add' := lim_nth_hom_add f_compat }
omit f_compat
lemma lift_sub_val_mem_span (r : R) (n : β) :
(lift f_compat r - (f n r).val) β (ideal.span {βp ^ n} : ideal β€_[p]) :=
begin
obtain β¨k, hkβ© := lim_nth_hom_spec f_compat r _
(show (0 : β) < p ^ (-n : β€), from nat.zpow_pos_of_pos hp_prime.1.pos _),
have := le_of_lt (hk (max n k) (le_max_right _ _)),
rw norm_le_pow_iff_mem_span_pow at this,
dsimp [lift],
rw sub_eq_sub_add_sub (lim_nth_hom f_compat r) _ β(nth_hom f r (max n k)),
apply ideal.add_mem _ _ this,
rw [ideal.mem_span_singleton],
simpa only [ring_hom.eq_int_cast, ring_hom.map_pow, int.cast_sub] using
(int.cast_ring_hom β€_[p]).map_dvd
(pow_dvd_nth_hom_sub f_compat r n (max n k) (le_max_left _ _)),
end
/--
One part of the universal property of `β€_[p]` as a projective limit.
See also `padic_int.lift_unique`.
-/
lemma lift_spec (n : β) : (to_zmod_pow n).comp (lift f_compat) = f n :=
begin
ext r,
haveI : fact (0 < p ^ n) := β¨pow_pos hp_prime.1.pos nβ©,
rw [ring_hom.comp_apply, β zmod.nat_cast_zmod_val (f n r), β map_nat_cast $ to_zmod_pow n,
β sub_eq_zero, β ring_hom.map_sub, β ring_hom.mem_ker, ker_to_zmod_pow],
apply lift_sub_val_mem_span,
end
/--
One part of the universal property of `β€_[p]` as a projective limit.
See also `padic_int.lift_spec`.
-/
lemma lift_unique (g : R β+* β€_[p]) (hg : β n, (to_zmod_pow n).comp g = f n) :
lift f_compat = g :=
begin
ext1 r,
apply eq_of_forall_dist_le,
intros Ξ΅ hΞ΅,
obtain β¨n, hnβ© := exists_pow_neg_lt p hΞ΅,
apply le_trans _ (le_of_lt hn),
rw [dist_eq_norm, norm_le_pow_iff_mem_span_pow, β ker_to_zmod_pow, ring_hom.mem_ker,
ring_hom.map_sub, β ring_hom.comp_apply, β ring_hom.comp_apply, lift_spec, hg, sub_self],
end
@[simp] lemma lift_self (z : β€_[p]) : @lift p _ β€_[p] _ to_zmod_pow
zmod_cast_comp_to_zmod_pow z = z :=
begin
show _ = ring_hom.id _ z,
rw @lift_unique p _ β€_[p] _ _ zmod_cast_comp_to_zmod_pow (ring_hom.id β€_[p]),
intro, rw ring_hom.comp_id,
end
end lift
lemma ext_of_to_zmod_pow {x y : β€_[p]} :
(β n, to_zmod_pow n x = to_zmod_pow n y) β x = y :=
begin
split,
{ intro h,
rw [β lift_self x, β lift_self y],
simp [lift, lim_nth_hom, nth_hom, h] },
{ rintro rfl _, refl }
end
lemma to_zmod_pow_eq_iff_ext {R : Type*} [non_assoc_semiring R] {g g' : R β+* β€_[p]} :
(β n, (to_zmod_pow n).comp g = (to_zmod_pow n).comp g') β g = g' :=
begin
split,
{ intro hg,
ext x : 1,
apply ext_of_to_zmod_pow.mp,
intro n,
show (to_zmod_pow n).comp g x = (to_zmod_pow n).comp g' x,
rw hg n },
{ rintro rfl _, refl }
end
end padic_int
|
d7cca1c4f8b6a58f4f5e64e17550d5a89b5403ee
|
a45212b1526d532e6e83c44ddca6a05795113ddc
|
/src/tactic/library_search.lean
|
d59a66fddebd556bc1295bd2a88a314dff1690c5
|
[
"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
| 4,653
|
lean
|
-- Copyright (c) 2019 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import tactic.basic
import data.list.defs
/-
A basic `library_search` tactic.
-/
namespace tactic
open native
namespace library_search
meta def head_symbol : expr β name
| (expr.pi _ _ _ t) := head_symbol t
| (expr.app f _) := head_symbol f
| (expr.const n _) :=
-- TODO this is a hack; if you suspect more cases here would help, please report them
match n with
| `gt := `has_lt.lt
| `ge := `has_le.le
| _ := n
end
| _ := `_
inductive head_symbol_match
| ex | mp | mpr | both
open head_symbol_match
def head_symbol_match.to_string : head_symbol_match β string
| ex := "exact"
| mp := "iff.mp"
| mpr := "iff.mpr"
| both := "iff.mp and iff.mpr"
meta def unfold_head_symbol : name β list name
| `false := [`not, `false]
| n := [n]
meta def match_head_symbol (hs : name) : expr β option head_symbol_match
| (expr.pi _ _ _ t) := match_head_symbol t
| `(%%a β %%b) := if `iff = hs then some ex else
match (match_head_symbol a, match_head_symbol b) with
| (some ex, some ex) :=
some both
| (some ex, _) := some mpr
| (_, some ex) := some mp
| _ := none
end
| (expr.app f _) := match_head_symbol f
| (expr.const n _) := if list.mem hs (unfold_head_symbol n) then some ex else none
| _ := none
meta structure decl_data :=
(d : declaration)
(n : name)
(m : head_symbol_match)
(l : β) -- cached length of name
-- We used to check here for private declarations, or declarations with certain suffixes.
-- It turns out `apply` is so fast, it's better to just try them all.
meta def process_declaration (hs : name) (d : declaration) : option decl_data :=
let n := d.to_name in
if Β¬ d.is_trusted β¨ n.is_internal then
none
else
(Ξ» m, β¨d, n, m, n.lengthβ©) <$> match_head_symbol hs d.type
/-- Retrieve all library definitions with a given head symbol. -/
meta def library_defs (hs : name) : tactic (list decl_data) :=
do env β get_env,
return $ env.decl_filter_map (process_declaration hs)
meta def apply_and_solve (e : expr) :=
apply e >> (done <|> solve_by_elim { all_goals := tt })
meta def apply_declaration (d : decl_data) : tactic unit :=
do e β mk_const d.n,
let t := d.d.type,
match d.m with
| ex := apply_and_solve e
| mp :=
do l β iff_mp_core e t,
apply_and_solve l
| mpr :=
do l β iff_mpr_core e t,
apply_and_solve l
| both :=
do l β iff_mp_core e t,
apply_and_solve l <|>
do l β iff_mpr_core e t,
apply_and_solve l
end
end library_search
open library_search
open library_search.head_symbol_match
declare_trace silence_library_search -- Turn off `exact ...` trace message
declare_trace library_search -- Trace a list of all relevant lemmas
meta def library_search : tactic string :=
do [g] β get_goals | fail "`library_search` should be called with exactly one goal",
t β infer_type g,
-- Collect all definitions with the correct head symbol
defs β library_defs (head_symbol t),
-- Sort by length; people like short proofs
let defs := defs.qsort(Ξ» dβ dβ, dβ.l β€ dβ.l),
when (is_trace_enabled_for `library_search) $ (do
trace format!"Found {defs.length} relevant lemmas:",
trace $ defs.map (Ξ» β¨d, n, m, lβ©, (n, m.to_string))),
-- Try `apply` followed by `solve_by_elim`, for each definition.
defs.mfirst apply_declaration,
-- If something worked, prepare a string to print.
p β instantiate_mvars g >>= head_beta >>= pp,
let r := format!"exact {p}",
when (Β¬ is_trace_enabled_for `silence_library_search) $ tactic.trace r,
return $ to_string r
namespace interactive
/--
`library_search` attempts to apply every definition in the library whose head symbol
matches the goal, and then discharge any new goals using `solve_by_elim`.
If it succeeds, it prints a trace message `exact ...` which can replace the invocation
of `library_search`.
-/
meta def library_search := tactic.library_search
end interactive
@[hole_command] meta def library_search_hole_cmd : hole_command :=
{ name := "library_search",
descr := "Use `library_search` to complete the goal.",
action := Ξ» _, do
script β library_search,
-- Is there a better API for dropping the 'exact ' prefix on this string?
return [((script.mk_iterator.remove 6).to_string, "by library_search")] }
end tactic
|
f07de0c29b27ff6e4bb792d736b3f49a95c1195c
|
f00cc9c04d77f9621aa57d1406d35c522c3ff82c
|
/library/init/meta/interactive.lean
|
ab798efe33bf0a63704c5c2babe6a42de5478bcf
|
[
"Apache-2.0"
] |
permissive
|
shonfeder/lean
|
444c66a74676d74fb3ef682d88cd0f5c1bf928a5
|
24d5a1592d80cefe86552d96410c51bb07e6d411
|
refs/heads/master
| 1,619,338,440,905
| 1,512,842,340,000
| 1,512,842,340,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 58,593
|
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.meta.tactic init.meta.rewrite_tactic init.meta.simp_tactic
import init.meta.smt.congruence_closure init.category.combinators
import init.meta.interactive_base init.meta.derive init.meta.match_tactic
open lean
open lean.parser
local postfix `?`:9001 := optional
local postfix *:9001 := many
namespace tactic
/- allows metavars -/
meta def i_to_expr (q : pexpr) : tactic expr :=
to_expr q tt
/- allow metavars and no subgoals -/
meta def i_to_expr_no_subgoals (q : pexpr) : tactic expr :=
to_expr q tt ff
/- doesn't allows metavars -/
meta def i_to_expr_strict (q : pexpr) : tactic expr :=
to_expr q ff
/- Auxiliary version of i_to_expr for apply-like tactics.
This is a workaround for comment
https://github.com/leanprover/lean/issues/1342#issuecomment-307912291
at issue #1342.
In interactive mode, given a tactic
apply f
we want the apply tactic to create all metavariables. The following
definition will return `@f` for `f`. That is, it will **not** create
metavariables for implicit arguments.
Before we added `i_to_expr_for_apply`, the tactic
apply le_antisymm
would first elaborate `le_antisymm`, and create
@le_antisymm ?m_1 ?m_2 ?m_3 ?m_4
The type class resolution problem
?m_2 : weak_order ?m_1
by the elaborator since ?m_1 is not assigned yet, and the problem is
discarded.
Then, we would invoke `apply_core`, which would create two
new metavariables for the explicit arguments, and try to unify the resulting
type with the current target. After the unification,
the metavariables ?m_1, ?m_3 and ?m_4 are assigned, but we lost
the information about the pending type class resolution problem.
With `i_to_expr_for_apply`, `le_antisymm` is elaborate into `@le_antisymm`,
the apply_core tactic creates all metavariables, and solves the ones that
can be solved by type class resolution.
Another possible fix: we modify the elaborator to return pending
type class resolution problems, and store them in the tactic_state.
-/
meta def i_to_expr_for_apply (q : pexpr) : tactic expr :=
let aux (n : name) : tactic expr := do
p β resolve_name n,
match p with
| (expr.const c []) := do r β mk_const c, save_type_info r q, return r
| _ := i_to_expr p
end
in match q with
| (expr.const c []) := aux c
| (expr.local_const c _ _ _) := aux c
| _ := i_to_expr q
end
namespace interactive
open interactive interactive.types expr
/--
itactic: parse a nested "interactive" tactic. That is, parse
`{` tactic `}`
-/
meta def itactic : Type :=
tactic unit
/--
If the current goal is a Pi/forall `β x : t, u` (resp. `let x := t in u`) then `intro` puts `x : t` (resp. `x := t`) in the local context. The new subgoal target is `u`.
If the goal is an arrow `t β u`, then it puts `h : t` in the local context and the new goal target is `u`.
If the goal is neither a Pi/forall nor begins with a let binder, the tactic `intro` applies the tactic `whnf` until an introduction can be applied or the goal is not head reducible. In the latter case, the tactic fails.
-/
meta def intro : parse ident_? β tactic unit
| none := intro1 >> skip
| (some h) := tactic.intro h >> skip
/--
Similar to `intro` tactic. The tactic `intros` will keep introducing new hypotheses until the goal target is not a Pi/forall or let binder.
The variant `intros hβ ... hβ` introduces `n` new hypotheses using the given identifiers to name them.
-/
meta def intros : parse ident_* β tactic unit
| [] := tactic.intros >> skip
| hs := intro_lst hs >> skip
/--
The tactic `introv` allows the user to automatically introduce the variables of a theorem and explicitly name the hypotheses involved. The given names are used to name non-dependent hypotheses.
Examples:
```
example : β a b : nat, a = b β b = a :=
begin
introv h,
exact h.symm
end
```
The state after `introv h` is
```
a b : β,
h : a = b
β’ b = a
```
```
example : β a b : nat, a = b β β c, b = c β a = c :=
begin
introv hβ hβ,
exact hβ.trans hβ
end
```
The state after `introv hβ hβ` is
```
a b : β,
hβ : a = b,
c : β,
hβ : b = c
β’ a = c
```
-/
meta def introv (ns : parse ident_*) : tactic unit :=
tactic.introv ns >> return ()
/--
The tactic `rename hβ hβ` renames hypothesis `hβ` to `hβ` in the current local context.
-/
meta def rename : parse ident β parse ident β tactic unit :=
tactic.rename
/--
The `apply` tactic tries to match the current goal against the conclusion of the type of term. The argument term should be a term well-formed in the local context of the main goal. If it succeeds, then the tactic returns as many subgoals as the number of premises that have not been fixed by type inference or type class resolution. Non-dependent premises are added before dependent ones.
The `apply` tactic uses higher-order pattern matching, type class resolution, and first-order unification with dependent types.
-/
meta def apply (q : parse texpr) : tactic unit :=
i_to_expr_for_apply q >>= tactic.apply
/--
Similar to the `apply` tactic, but does not reorder goals.
-/
meta def fapply (q : parse texpr) : tactic unit :=
i_to_expr_for_apply q >>= tactic.fapply
/--
Similar to the `apply` tactic, but only creates subgoals for non-dependent premises that have not been fixed by type inference or type class resolution.
-/
meta def eapply (q : parse texpr) : tactic unit :=
i_to_expr_for_apply q >>= tactic.eapply
/--
Similar to the `apply` tactic, but allows the user to provide a `apply_cfg` configuration object.
-/
meta def apply_with (q : parse parser.pexpr) (cfg : apply_cfg) : tactic unit :=
do e β i_to_expr_for_apply q, tactic.apply e cfg
/--
This tactic tries to close the main goal `... β’ t` by generating a term of type `t` using type class resolution.
-/
meta def apply_instance : tactic unit :=
tactic.apply_instance
/--
This tactic behaves like `exact`, but with a big difference: the user can put underscores `_` in the expression as placeholders for holes that need to be filled, and `refine` will generate as many subgoals as there are holes.
Note that some holes may be implicit. The type of each hole must either be synthesized by the system or declared by an explicit type ascription like `(_ : nat β Prop)`.
-/
meta def refine (q : parse texpr) : tactic unit :=
tactic.refine q
/--
This tactic looks in the local context for a hypothesis whose type is equal to the goal target. If it finds one, it uses it to prove the goal, and otherwise it fails.
-/
meta def assumption : tactic unit :=
tactic.assumption
/-- Try to apply `assumption` to all goals. -/
meta def assumption' : tactic unit :=
tactic.any_goals tactic.assumption
private meta def change_core (e : expr) : option expr β tactic unit
| none := tactic.change e
| (some h) :=
do num_reverted : β β revert h,
expr.pi n bi d b β target,
tactic.change $ expr.pi n bi e b,
intron num_reverted
/--
`change u` replaces the target `t` of the main goal to `u` provided that `t` is well formed with respect to the local context of the main goal and `t` and `u` are definitionally equal.
`change u at h` will change a local hypothesis to `u`.
`change t with u at h1 h2 ...` will replace `t` with `u` in all the supplied hypotheses (or `*`), or in the goal if no `at` clause is specified, provided that `t` and `u` are definitionally equal.
-/
meta def change (q : parse texpr) : parse (tk "with" *> texpr)? β parse location β tactic unit
| none (loc.ns [none]) := do e β i_to_expr q, change_core e none
| none (loc.ns [some h]) := do eq β i_to_expr q, eh β get_local h, change_core eq (some eh)
| none _ := fail "change-at does not support multiple locations"
| (some w) l :=
do u β mk_meta_univ,
ty β mk_meta_var (sort u),
eq β i_to_expr ``(%%q : %%ty),
ew β i_to_expr ``(%%w : %%ty),
let repl := Ξ»e : expr, e.replace (Ξ» a n, if a = eq then some ew else none),
l.try_apply
(Ξ»h, do e β infer_type h, change_core (repl e) (some h))
(do g β target, change_core (repl g) none)
/--
This tactic provides an exact proof term to solve the main goal. If `t` is the goal and `p` is a term of type `u` then `exact p` succeeds if and only if `t` and `u` can be unified.
-/
meta def exact (q : parse texpr) : tactic unit :=
do tgt : expr β target,
i_to_expr_strict ``(%%q : %%tgt) >>= tactic.exact
/--
Like `exact`, but takes a list of terms and checks that all goals are discharged after the tactic.
-/
meta def exacts : parse pexpr_list_or_texpr β tactic unit
| [] := done
| (t :: ts) := exact t >> exacts ts
/--
A synonym for `exact` that allows writing `have/suffices/show ..., from ...` in tactic mode.
-/
meta def Β«fromΒ» := exact
/--
`revert hβ ... hβ` applies to any goal with hypotheses `hβ` ... `hβ`. It moves the hypotheses and their dependencies to the target of the goal. This tactic is the inverse of `intro`.
-/
meta def revert (ids : parse ident*) : tactic unit :=
do hs β mmap tactic.get_local ids, revert_lst hs, skip
private meta def resolve_name' (n : name) : tactic expr :=
do {
p β resolve_name n,
match p with
| expr.const n _ := mk_const n -- create metavars for universe levels
| _ := i_to_expr p
end
}
/- Version of to_expr that tries to bypass the elaborator if `p` is just a constant or local constant.
This is not an optimization, by skipping the elaborator we make sure that no unwanted resolution is used.
Example: the elaborator will force any unassigned ?A that must have be an instance of (has_one ?A) to nat.
Remark: another benefit is that auxiliary temporary metavariables do not appear in error messages. -/
meta def to_expr' (p : pexpr) : tactic expr :=
match p with
| (const c []) := do new_e β resolve_name' c, save_type_info new_e p, return new_e
| (local_const c _ _ _) := do new_e β resolve_name' c, save_type_info new_e p, return new_e
| _ := i_to_expr p
end
@[derive has_reflect]
meta structure rw_rule :=
(pos : pos)
(symm : bool)
(rule : pexpr)
meta def get_rule_eqn_lemmas (r : rw_rule) : tactic (list name) :=
let aux (n : name) : tactic (list name) := do {
p β resolve_name n,
-- unpack local refs
let e := p.erase_annotations.get_app_fn.erase_annotations,
match e with
| const n _ := get_eqn_lemmas_for tt n
| _ := return []
end } <|> return [] in
match r.rule with
| const n _ := aux n
| local_const n _ _ _ := aux n
| _ := return []
end
private meta def rw_goal (cfg : rewrite_cfg) (rs : list rw_rule) : tactic unit :=
rs.mmap' $ Ξ» r, do
save_info r.pos,
eq_lemmas β get_rule_eqn_lemmas r,
orelse'
(do e β to_expr' r.rule, rewrite_target e {symm := r.symm, ..cfg})
(eq_lemmas.mfirst $ Ξ» n, do e β mk_const n, rewrite_target e {symm := r.symm, ..cfg})
(eq_lemmas.empty)
private meta def uses_hyp (e : expr) (h : expr) : bool :=
e.fold ff $ Ξ» t _ r, r || to_bool (t = h)
private meta def rw_hyp (cfg : rewrite_cfg) : list rw_rule β expr β tactic unit
| [] hyp := skip
| (r::rs) hyp := do
save_info r.pos,
eq_lemmas β get_rule_eqn_lemmas r,
orelse'
(do e β to_expr' r.rule, when (not (uses_hyp e hyp)) $ rewrite_hyp e hyp {symm := r.symm, ..cfg} >>= rw_hyp rs)
(eq_lemmas.mfirst $ Ξ» n, do e β mk_const n, rewrite_hyp e hyp {symm := r.symm, ..cfg} >>= rw_hyp rs)
(eq_lemmas.empty)
meta def rw_rule_p (ep : parser pexpr) : parser rw_rule :=
rw_rule.mk <$> cur_pos <*> (option.is_some <$> (with_desc "β" (tk "β" <|> tk "<-"))?) <*> ep
@[derive has_reflect]
meta structure rw_rules_t :=
(rules : list rw_rule)
(end_pos : option pos)
-- accepts the same content as `pexpr_list_or_texpr`, but with correct goal info pos annotations
meta def rw_rules : parser rw_rules_t :=
(tk "[" *>
rw_rules_t.mk <$> sep_by (skip_info (tk ",")) (set_goal_info_pos $ rw_rule_p (parser.pexpr 0))
<*> (some <$> cur_pos <* set_goal_info_pos (tk "]")))
<|> rw_rules_t.mk <$> (list.ret <$> rw_rule_p texpr) <*> return none
private meta def rw_core (rs : parse rw_rules) (loca : parse location) (cfg : rewrite_cfg) : tactic unit :=
match loca with
| loc.wildcard := loca.try_apply (rw_hyp cfg rs.rules) (rw_goal cfg rs.rules)
| _ := loca.apply (rw_hyp cfg rs.rules) (rw_goal cfg rs.rules)
end >> try (reflexivity reducible)
>> (returnopt rs.end_pos >>= save_info <|> skip)
/--
`rewrite e` applies identity `e` as a rewrite rule to the target of the main goal. If `e` is preceded by left arrow (`β` or `<-`), the rewrite is applied in the reverse direction. If `e` is a defined constant, then the equational lemmas associated with `e` are used. This provides a convenient way to unfold `e`.
`rewrite [eβ, ..., eβ]` applies the given rules sequentially.
`rewrite e at l` rewrites `e` at location(s) `l`, where `l` is either `*` or a list of hypotheses in the local context. In the latter case, a turnstile `β’` or `|-` can also be used, to signify the target of the goal.
-/
meta def rewrite (q : parse rw_rules) (l : parse location) (cfg : rewrite_cfg := {}) : tactic unit :=
rw_core q l cfg
/--
An abbreviation for `rewrite`.
-/
meta def rw (q : parse rw_rules) (l : parse location) (cfg : rewrite_cfg := {}) : tactic unit :=
rw_core q l cfg
/--
`rewrite` followed by `assumption`.
-/
meta def rwa (q : parse rw_rules) (l : parse location) (cfg : rewrite_cfg := {}) : tactic unit :=
rewrite q l cfg >> try assumption
/--
A variant of `rewrite` that uses the unifier more aggressively, unfolding semireducible definitions.
-/
meta def erewrite (q : parse rw_rules) (l : parse location) (cfg : rewrite_cfg := {md := semireducible}) : tactic unit :=
rw_core q l cfg
/--
An abbreviation for `erewrite`.
-/
meta def erw (q : parse rw_rules) (l : parse location) (cfg : rewrite_cfg := {md := semireducible}) : tactic unit :=
rw_core q l cfg
private meta def get_type_name (e : expr) : tactic name :=
do e_type β infer_type e >>= whnf,
(const I ls) β return $ get_app_fn e_type,
return I
private meta def generalize_arg_p_aux : pexpr β parser (pexpr Γ name)
| (app (app (macro _ [const `eq _ ]) h) (local_const x _ _ _)) := pure (h, x)
| _ := fail "parse error"
private meta def generalize_arg_p : parser (pexpr Γ name) :=
with_desc "expr = id" $ parser.pexpr 0 >>= generalize_arg_p_aux
/--
`generalize : e = x` replaces all occurrences of `e` in the target with a new hypothesis `x` of the same type.
`generalize h : e = x` in addition registers the hypothesis `h : e = x`.
-/
meta def generalize (h : parse ident?) (_ : parse $ tk ":") (p : parse generalize_arg_p) : tactic unit :=
do let (p, x) := p,
e β i_to_expr p,
some h β pure h | tactic.generalize e x >> intro1 >> skip,
tgt β target,
-- if generalizing fails, fall back to not replacing anything
tgt' β do {
β¨tgt', _β© β solve_aux tgt (tactic.generalize e x >> target),
to_expr ``(Ξ x, %%e = x β %%(tgt'.binding_body.lift_vars 0 1))
} <|> to_expr ``(Ξ x, %%e = x β %%tgt),
t β assert h tgt',
swap,
exact ``(%%t %%e rfl),
intro x,
intro h
meta def cases_arg_p : parser (option name Γ pexpr) :=
with_desc "(id :)? expr" $ do
t β texpr,
match t with
| (local_const x _ _ _) :=
(tk ":" *> do t β texpr, pure (some x, t)) <|> pure (none, t)
| _ := pure (none, t)
end
precedence `generalizing` : 0
/--
Assuming `x` is a variable in the local context with an inductive type, `induction x` applies induction on `x` to the main goal, producing one goal for each constructor of the inductive type, in which the target is replaced by a general instance of that constructor and an inductive hypothesis is added for each recursive argument to the constructor. If the type of an element in the local context depends on `x`, that element is reverted and reintroduced afterward, so that the inductive hypothesis incorporates that hypothesis as well.
For example, given `n : nat` and a goal with a hypothesis `h : P n` and target `Q n`, `induction n` produces one goal with hypothesis `h : P 0` and target `Q 0`, and one goal with hypotheses `h : P (nat.succ a)` and `ihβ : P a β Q a` and target `Q (nat.succ a)`. Here the names `a` and `ihβ` ire chosen automatically.
`induction e`, where `e` is an expression instead of a variable, generalizes `e` in the goal, and then performs induction on the resulting variable.
`induction e with yβ ... yβ`, where `e` is a variable or an expression, specifies that the sequence of names `yβ ... yβ` should be used for the arguments to the constructors and inductive hypotheses, including implicit arguments. If the list does not include enough names for all of the arguments, additional names are generated automatically. If too many names are given, the extra ones are ignored. Underscores can be used in the list, in which case the corresponding names are generated automatically. Note that for long sequences of names, the `case` tactic provides a more convenient naming mechanism.
`induction e using r` allows the user to specify the principle of induction that should be used. Here `r` should be a theorem whose result type must be of the form `C t`, where `C` is a bound variable and `t` is a (possibly empty) sequence of bound variables
`induction e generalizing zβ ... zβ`, where `zβ ... zβ` are variables in the local context, generalizes over `zβ ... zβ` before applying the induction but then introduces them in each goal. In other words, the net effect is that each inductive hypothesis is generalized.
`induction h : t` will introduce an equality of the form `h : t = C x y`, asserting that the input term is equal to the current constructor case, to the context.
-/
meta def induction (hp : parse cases_arg_p) (rec_name : parse using_ident) (ids : parse with_ident_list)
(revert : parse $ (tk "generalizing" *> ident*)?) : tactic unit :=
do
-- process `h : t` case
e β match hp with
| (some h, p) := do
x β mk_fresh_name,
generalize h () (p, x),
get_local x
| (none, p) := i_to_expr p
end,
-- generalize major premise
e β if e.is_local_constant then pure e
else tactic.generalize e >> intro1,
-- generalize major premise args
(e, newvars, locals) β do {
none β pure rec_name | pure (e, [], []),
t β infer_type e,
t β whnf_ginductive t,
const n _ β pure t.get_app_fn | pure (e, [], []),
env β get_env,
tt β pure $ env.is_inductive n | pure (e, [], []),
let (locals, nonlocals) := (t.get_app_args.drop $ env.inductive_num_params n).partition
(Ξ» arg : expr, arg.is_local_constant),
_ :: _ β pure nonlocals | pure (e, [], []),
n β tactic.revert e,
newvars β nonlocals.mmap $ Ξ» arg, do {
n β revert_kdeps arg,
tactic.generalize arg,
h β intro1,
intron n,
-- now try to clear hypotheses that may have been abstracted away
let locals := arg.fold [] (Ξ» e _ acc, if e.is_local_constant then e::acc else acc),
locals.mmap' (try β clear),
pure h
},
intron (n-1),
e β intro1,
pure (e, newvars, locals)
},
-- revert `generalizing` params
n β mmap tactic.get_local (revert.get_or_else []) >>= revert_lst,
tactic.induction e ids rec_name,
all_goals $ do {
intron n,
clear_lst (newvars.map local_pp_name),
(e::locals).mmap' (try β clear) }
private meta def find_case (goals : list expr) (ty : name) (idx : nat) (num_indices : nat) : option expr β expr β option (expr Γ expr)
| case e := if e.has_meta_var then match e with
| (mvar _ _ _) :=
do case β case,
guard $ e β goals,
pure (case, e)
| (app _ _) :=
let idx :=
match e.get_app_fn with
| const (name.mk_string rec ty') _ :=
guard (ty' = ty) >>
match mk_simple_name rec with
| `drec := some idx | `rec := some idx
-- indices + major premise
| `dcases_on := some (idx + num_indices + 1) | `cases_on := some (idx + num_indices + 1)
| _ := none
end
| _ := none
end in
match idx with
| none := list.foldl (<|>) (find_case case e.get_app_fn) $ e.get_app_args.map (find_case case)
| some idx :=
let args := e.get_app_args in
do arg β args.nth idx,
args.enum.foldl
(Ξ» acc β¨i, argβ©, match acc with
| some _ := acc
| _ := if i β idx then find_case none arg else none
end)
-- start recursion with likely case
(find_case (some arg) arg)
end
| (lam _ _ _ e) := find_case case e
| (macro n args) := list.foldl (<|>) none $ args.map (find_case case)
| _ := none
end else none
private meta def rename_lams : expr β list name β tactic unit
| (lam n _ _ e) (n'::ns) := (rename n n' >> rename_lams e ns) <|> rename_lams e (n'::ns)
| _ _ := skip
/--
Focuses on the `induction`/`cases` subgoal corresponding to the given introduction rule, optionally renaming introduced locals.
```
example (n : β) : n = n :=
begin
induction n,
case nat.zero { reflexivity },
case nat.succ a ih { reflexivity }
end
```
-/
meta def case (ctor : parse ident) (ids : parse ident_*) (tac : itactic) : tactic unit :=
do r β result,
env β get_env,
ctor β resolve_constant ctor
<|> fail ("'" ++ to_string ctor ++ "' is not a constructor"),
ty β (env.inductive_type_of ctor).to_monad
<|> fail ("'" ++ to_string ctor ++ "' is not a constructor"),
let ctors := env.constructors_of ty,
let idx := env.inductive_num_params ty + /- motive -/ 1 +
list.index_of ctor ctors,
gs β get_goals,
(case, g) β (find_case gs ty idx (env.inductive_num_indices ty) none r ).to_monad
<|> fail "could not find open goal of given case",
set_goals $ g :: gs.filter (β g),
rename_lams case ids,
solve1 tac
/--
Apply `t` to main goal, and revert any new hypothesis in the generated goals.
This tactic is useful for writing robust proof scripts that are not sensitive
to the name generation strategy used by `t`.
```
example (n : β) : n = n :=
begin
guard_names { induction n },
{ reflexivity },
{ intros n' ih, reflexivity }
end
```
-/
meta def guard_names : itactic β tactic unit :=
tactic.guard_names
/--
Assuming `x` is a variable in the local context with an inductive type, `destruct x` splits the main goal, producing one goal for each constructor of the inductive type, in which `x` is assumed to be a general instance of that constructor. In contrast to `cases`, the local context is unchanged, i.e. no elements are reverted or introduced.
For example, given `n : nat` and a goal with a hypothesis `h : P n` and target `Q n`, `destruct n` produces one goal with target `n = 0 β Q n`, and one goal with target `β (a : β), (Ξ» (w : β), n = w β Q n) (nat.succ a)`. Here the name `a` is chosen automatically.
-/
meta def destruct (p : parse texpr) : tactic unit :=
i_to_expr p >>= tactic.destruct
/--
Assuming `x` is a variable in the local context with an inductive type, `cases x` splits the main goal, producing one goal for each constructor of the inductive type, in which the target is replaced by a general instance of that constructor. If the type of an element in the local context depends on `x`, that element is reverted and reintroduced afterward, so that the case split affects that hypothesis as well.
For example, given `n : nat` and a goal with a hypothesis `h : P n` and target `Q n`, `cases n` produces one goal with hypothesis `h : P 0` and target `Q 0`, and one goal with hypothesis `h : P (nat.succ a)` and target `Q (nat.succ a)`. Here the name `a` is chosen automatically.
`cases e`, where `e` is an expression instead of a variable, generalizes `e` in the goal, and then cases on the resulting variable.
`cases e with yβ ... yβ`, where `e` is a variable or an expression, specifies that the sequence of names `yβ ... yβ` should be used for the arguments to the constructors, including implicit arguments. If the list does not include enough names for all of the arguments, additional names are generated automatically. If too many names are given, the extra ones are ignored. Underscores can be used in the list, in which case the corresponding names are generated automatically.
`cases h : e`, where `e` is a variable or an expression, performs cases on `e` as above, but also adds a hypothesis `h : e = ...` to each hypothesis, where `...` is the constructor instance for that particular case.
-/
meta def cases : parse cases_arg_p β parse with_ident_list β tactic unit
| (none, p) ids := do
e β i_to_expr p,
tactic.cases e ids
| (some h, p) ids := do
x β mk_fresh_name,
generalize h () (p, x),
hx β get_local x,
tactic.cases hx ids
private meta def find_matching_hyp (ps : list pattern) : tactic expr :=
any_hyp $ Ξ» h, do
type β infer_type h,
ps.mfirst $ Ξ» p, do
match_pattern p type,
return h
/--
`cases_matching p` applies the `cases` tactic to a hypothesis `h : type` if `type` matches the pattern `p`.
`cases_matching [p_1, ..., p_n]` applies the `cases` tactic to a hypothesis `h : type` if `type` matches one of the given patterns.
`cases_matching* p` more efficient and compact version of `focus1 { repeat { cases_matching p } }`. It is more efficient because the pattern is compiled once.
Example: The following tactic destructs all conjunctions and disjunctions in the current goal.
```
cases_matching* [_ β¨ _, _ β§ _]
```
-/
meta def cases_matching (rec : parse $ (tk "*")?) (ps : parse pexpr_list_or_texpr) : tactic unit :=
do ps β ps.mmap pexpr_to_pattern,
if rec.is_none
then find_matching_hyp ps >>= tactic.cases
else tactic.focus1 $ tactic.repeat $ find_matching_hyp ps >>= tactic.cases
/-- Shorthand for `cases_matching` -/
meta def casesm (rec : parse $ (tk "*")?) (ps : parse pexpr_list_or_texpr) : tactic unit :=
cases_matching rec ps
private meta def try_cases_for_types (type_names : list name) (at_most_one : bool) : tactic unit :=
any_hyp $ Ξ» h, do
I β expr.get_app_fn <$> (infer_type h >>= head_beta),
guard I.is_constant,
guard (I.const_name β type_names),
tactic.focus1 (tactic.cases h >> if at_most_one then do n β num_goals, guard (n <= 1) else skip)
/--
`cases_type I` applies the `cases` tactic to a hypothesis `h : (I ...)`
`cases_type I_1 ... I_n` applies the `cases` tactic to a hypothesis `h : (I_1 ...)` or ... or `h : (I_n ...)`
`cases_type* I` is shorthand for `focus1 { repeat { cases_type I } }`
`cases_type! I` only applies `cases` if the number of resulting subgoals is <= 1.
Example: The following tactic destructs all conjunctions and disjunctions in the current goal.
```
cases_type* or and
```
-/
meta def cases_type (one : parse $ (tk "!")?) (rec : parse $ (tk "*")?) (type_names : parse ident*) : tactic unit :=
do type_names β type_names.mmap resolve_constant,
if rec.is_none
then try_cases_for_types type_names (bnot one.is_none)
else tactic.focus1 $ tactic.repeat $ try_cases_for_types type_names (bnot one.is_none)
/--
Tries to solve the current goal using a canonical proof of `true`, or the `reflexivity` tactic, or the `contradiction` tactic.
-/
meta def trivial : tactic unit :=
tactic.triv <|> tactic.reflexivity <|> tactic.contradiction <|> fail "trivial tactic failed"
/--
Closes the main goal using `sorry`.
-/
meta def admit : tactic unit := tactic.admit
/--
The contradiction tactic attempts to find in the current local context a hypothesis that is equivalent to an empty inductive type (e.g. `false`), a hypothesis of the form `c_1 ... = c_2 ...` where `c_1` and `c_2` are distinct constructors, or two contradictory hypotheses.
-/
meta def contradiction : tactic unit :=
tactic.contradiction
/--
`iterate { t }` repeatedly applies tactic `t` until `t` fails. `iterate { t }` always succeeds.
`iterate n { t }` applies `t` `n` times.
-/
meta def iterate (n : parse small_nat?) (t : itactic) : tactic unit :=
match n with
| none := tactic.iterate t
| some n := iterate_exactly n t
end
/--
`repeat { t }` applies `t` to each goal. If the application succeeds,
the tactic is applied recursively to all the generated subgoals until it eventually fails.
The recursion stops in a subgoal when the tactic has failed to make progress.
The tactic `repeat { t }` never fails.
-/
meta def repeat : itactic β tactic unit :=
tactic.repeat
/--
`try { t }` tries to apply tactic `t`, but succeeds whether or not `t` succeeds.
-/
meta def try : itactic β tactic unit :=
tactic.try
/--
A do-nothing tactic that always succeeds.
-/
meta def skip : tactic unit :=
tactic.skip
/--
`solve1 { t }` applies the tactic `t` to the main goal and fails if it is not solved.
-/
meta def solve1 : itactic β tactic unit :=
tactic.solve1
/--
`abstract id { t }` tries to use tactic `t` to solve the main goal. If it succeeds, it abstracts the goal as an independent definition or theorem with name `id`. If `id` is omitted, a name is generated automatically.
-/
meta def abstract (id : parse ident?) (tac : itactic) : tactic unit :=
tactic.abstract tac id
/--
`all_goals { t }` applies the tactic `t` to every goal, and succeeds if each application succeeds.
-/
meta def all_goals : itactic β tactic unit :=
tactic.all_goals
/--
`any_goals { t }` applies the tactic `t` to every goal, and succeeds if at least one application succeeds.
-/
meta def any_goals : itactic β tactic unit :=
tactic.any_goals
/--
`focus { t }` temporarily hides all goals other than the first, applies `t`, and then restores the other goals. It fails if there are no goals.
-/
meta def focus (tac : itactic) : tactic unit :=
tactic.focus1 tac
private meta def assume_core (n : name) (ty : pexpr) :=
do t β target,
when (not $ t.is_pi β¨ t.is_let) whnf_target,
t β target,
when (not $ t.is_pi β¨ t.is_let) $
fail "assume tactic failed, Pi/let expression expected",
ty β i_to_expr ty,
unify ty t.binding_domain,
intro_core n >> skip
/--
Assuming the target of the goal is a Pi or a let, `assume h : t` unifies the type of the binder with `t` and introduces it with name `h`, just like `intro h`. If `h` is absent, the tactic uses the name `this`. If `t` is omitted, it will be inferred.
`assume (hβ : tβ) ... (hβ : tβ)` introduces multiple hypotheses. Any of the types may be omitted, but the names must be present.
-/
meta def Β«assumeΒ» : parse (sum.inl <$> (tk ":" *> texpr) <|> sum.inr <$> parse_binders tac_rbp) β tactic unit
| (sum.inl ty) := assume_core `this ty
| (sum.inr binders) :=
binders.mmap' $ Ξ» b, assume_core b.local_pp_name b.local_type
/--
`have h : t := p` adds the hypothesis `h : t` to the current goal if `p` a term of type `t`. If `t` is omitted, it will be inferred.
`have h : t` adds the hypothesis `h : t` to the current goal and opens a new subgoal with target `t`. The new subgoal becomes the main goal. If `t` is omitted, it will be replaced by a fresh metavariable.
If `h` is omitted, the name `this` is used.
-/
meta def Β«haveΒ» (h : parse ident?) (qβ : parse (tk ":" *> texpr)?) (qβ : parse $ (tk ":=" *> texpr)?) : tactic unit :=
let h := h.get_or_else `this in
match qβ, qβ with
| some e, some p := do
t β i_to_expr e,
v β i_to_expr ``(%%p : %%t),
tactic.assertv h t v
| none, some p := do
p β i_to_expr p,
tactic.note h none p
| some e, none := i_to_expr e >>= tactic.assert h
| none, none := do
u β mk_meta_univ,
e β mk_meta_var (sort u),
tactic.assert h e
end >> skip
/--
`let h : t := p` adds the hypothesis `h : t := p` to the current goal if `p` a term of type `t`. If `t` is omitted, it will be inferred.
`let h : t` adds the hypothesis `h : t := ?M` to the current goal and opens a new subgoal `?M : t`. The new subgoal becomes the main goal. If `t` is omitted, it will be replaced by a fresh metavariable.
If `h` is omitted, the name `this` is used.
-/
meta def Β«letΒ» (h : parse ident?) (qβ : parse (tk ":" *> texpr)?) (qβ : parse $ (tk ":=" *> texpr)?) : tactic unit :=
let h := h.get_or_else `this in
match qβ, qβ with
| some e, some p := do
t β i_to_expr e,
v β i_to_expr ``(%%p : %%t),
tactic.definev h t v
| none, some p := do
p β i_to_expr p,
tactic.pose h none p
| some e, none := i_to_expr e >>= tactic.define h
| none, none := do
u β mk_meta_univ,
e β mk_meta_var (sort u),
tactic.define h e
end >> skip
/--
`suffices h : t` is the same as `have h : t, tactic.swap`. In other words, it adds the hypothesis `h : t` to the current goal and opens a new subgoal with target `t`.
-/
meta def Β«sufficesΒ» (h : parse ident?) (t : parse (tk ":" *> texpr)?) : tactic unit :=
Β«haveΒ» h t none >> tactic.swap
/--
This tactic displays the current state in the tracing buffer.
-/
meta def trace_state : tactic unit :=
tactic.trace_state
/--
`trace a` displays `a` in the tracing buffer.
-/
meta def trace {Ξ± : Type} [has_to_tactic_format Ξ±] (a : Ξ±) : tactic unit :=
tactic.trace a
/--
`existsi e` will instantiate an existential quantifier in the target with `e` and leave the instantiated body as the new target. More generally, it applies to any inductive type with one constructor and at least two arguments, applying the constructor with `e` as the first argument and leaving the remaining arguments as goals.
`existsi [eβ, ..., eβ]` iteratively does the same for each expression in the list.
-/
meta def existsi : parse pexpr_list_or_texpr β tactic unit
| [] := return ()
| (p::ps) := i_to_expr p >>= tactic.existsi >> existsi ps
/--
This tactic applies to a goal such that its conclusion is an inductive type (say `I`). It tries to apply each constructor of `I` until it succeeds.
-/
meta def constructor : tactic unit :=
tactic.constructor
/--
Similar to `constructor`, but only non-dependent premises are added as new goals.
-/
meta def econstructor : tactic unit :=
tactic.econstructor
/--
Applies the first constructor when the type of the target is an inductive data type with two constructors.
-/
meta def left : tactic unit :=
tactic.left
/--
Applies the second constructor when the type of the target is an inductive data type with two constructors.
-/
meta def right : tactic unit :=
tactic.right
/--
Applies the constructor when the type of the target is an inductive data type with one constructor.
-/
meta def split : tactic unit :=
tactic.split
private meta def constructor_matching_aux (ps : list pattern) : tactic unit :=
do t β target, ps.mfirst (Ξ» p, match_pattern p t), constructor
meta def constructor_matching (rec : parse $ (tk "*")?) (ps : parse pexpr_list_or_texpr) : tactic unit :=
do ps β ps.mmap pexpr_to_pattern,
if rec.is_none then constructor_matching_aux ps
else tactic.focus1 $ tactic.repeat $ constructor_matching_aux ps
/--
Replaces the target of the main goal by `false`.
-/
meta def exfalso : tactic unit :=
tactic.exfalso
/--
The `injection` tactic is based on the fact that constructors of inductive data types are injections. That means that if `c` is a constructor of an inductive datatype, and if `(c tβ)` and `(c tβ)` are two terms that are equal then `tβ` and `tβ` are equal too.
If `q` is a proof of a statement of conclusion `tβ = tβ`, then injection applies injectivity to derive the equality of all arguments of `tβ` and `tβ` placed in the same positions. For example, from `(a::b) = (c::d)` we derive `a=c` and `b=d`. To use this tactic `tβ` and `tβ` should be constructor applications of the same constructor.
Given `h : a::b = c::d`, the tactic `injection h` adds two new hypothesis with types `a = c` and `b = d` to the main goal. The tactic `injection h with hβ hβ` uses the names `hβ` and `hβ` to name the new hypotheses.
-/
meta def injection (q : parse texpr) (hs : parse with_ident_list) : tactic unit :=
do e β i_to_expr q, tactic.injection_with e hs, try assumption
/--
`injections with hβ ... hβ` iteratively applies `injection` to hypotheses using the names `hβ ... hβ`.
-/
meta def injections (hs : parse with_ident_list) : tactic unit :=
do tactic.injections_with hs, try assumption
end interactive
meta structure simp_config_ext extends simp_config :=
(discharger : tactic unit := failed)
section mk_simp_set
open expr interactive.types
@[derive has_reflect]
meta inductive simp_arg_type : Type
| all_hyps : simp_arg_type
| except : name β simp_arg_type
| expr : pexpr β simp_arg_type
meta def simp_arg : parser simp_arg_type :=
(tk "*" *> return simp_arg_type.all_hyps) <|> (tk "-" *> simp_arg_type.except <$> ident) <|> (simp_arg_type.expr <$> texpr)
meta def simp_arg_list : parser (list simp_arg_type) :=
(tk "*" *> return [simp_arg_type.all_hyps]) <|> list_of simp_arg <|> return []
private meta def resolve_exception_ids (all_hyps : bool) : list name β list name β list name β tactic (list name Γ list name)
| [] gex hex := return (gex.reverse, hex.reverse)
| (id::ids) gex hex := do
p β resolve_name id,
let e := p.erase_annotations.get_app_fn.erase_annotations,
match e with
| const n _ := resolve_exception_ids ids (n::gex) hex
| local_const n _ _ _ := when (not all_hyps) (fail $ sformat! "invalid local exception {id}, '*' was not used") >>
resolve_exception_ids ids gex (n::hex)
| _ := fail $ sformat! "invalid exception {id}, unknown identifier"
end
/- Return (hs, gex, hex, all) -/
meta def decode_simp_arg_list (hs : list simp_arg_type) : tactic $ list pexpr Γ list name Γ list name Γ bool :=
do
let (hs, ex, all) := hs.foldl
(Ξ» r h,
match r, h with
| (es, ex, all), simp_arg_type.all_hyps := (es, ex, tt)
| (es, ex, all), simp_arg_type.except id := (es, id::ex, all)
| (es, ex, all), simp_arg_type.expr e := (e::es, ex, all)
end)
([], [], ff),
(gex, hex) β resolve_exception_ids all ex [] [],
return (hs.reverse, gex, hex, all)
private meta def add_simps : simp_lemmas β list name β tactic simp_lemmas
| s [] := return s
| s (n::ns) := do s' β s.add_simp n, add_simps s' ns
private meta def report_invalid_simp_lemma {Ξ± : Type} (n : name): tactic Ξ± :=
fail format!"invalid simplification lemma '{n}' (use command 'set_option trace.simp_lemmas true' for more details)"
private meta def check_no_overload (p : pexpr) : tactic unit :=
when p.is_choice_macro $
match p with
| macro _ ps :=
fail $ to_fmt "ambiguous overload, possible interpretations" ++
format.join (ps.map (Ξ» p, (to_fmt p).indent 4))
| _ := failed
end
private meta def simp_lemmas.resolve_and_add (s : simp_lemmas) (u : list name) (n : name) (ref : pexpr) : tactic (simp_lemmas Γ list name) :=
do
p β resolve_name n,
check_no_overload p,
-- unpack local refs
let e := p.erase_annotations.get_app_fn.erase_annotations,
match e with
| const n _ :=
(do b β is_valid_simp_lemma_cnst n, guard b, save_const_type_info n ref, s β s.add_simp n, return (s, u))
<|>
(do eqns β get_eqn_lemmas_for tt n, guard (eqns.length > 0), save_const_type_info n ref, s β add_simps s eqns, return (s, u))
<|>
(do env β get_env, guard (env.is_projection n).is_some, return (s, n::u))
<|>
report_invalid_simp_lemma n
| _ :=
(do e β i_to_expr_no_subgoals p, b β is_valid_simp_lemma e, guard b, try (save_type_info e ref), s β s.add e, return (s, u))
<|>
report_invalid_simp_lemma n
end
private meta def simp_lemmas.add_pexpr (s : simp_lemmas) (u : list name) (p : pexpr) : tactic (simp_lemmas Γ list name) :=
match p with
| (const c []) := simp_lemmas.resolve_and_add s u c p
| (local_const c _ _ _) := simp_lemmas.resolve_and_add s u c p
| _ := do new_e β i_to_expr_no_subgoals p, s β s.add new_e, return (s, u)
end
private meta def simp_lemmas.append_pexprs : simp_lemmas β list name β list pexpr β tactic (simp_lemmas Γ list name)
| s u [] := return (s, u)
| s u (l::ls) := do (s, u) β simp_lemmas.add_pexpr s u l, simp_lemmas.append_pexprs s u ls
meta def mk_simp_set_core (no_dflt : bool) (attr_names : list name) (hs : list simp_arg_type) (at_star : bool)
: tactic (bool Γ simp_lemmas Γ list name) :=
do (hs, gex, hex, all_hyps) β decode_simp_arg_list hs,
when (all_hyps β§ at_star β§ not hex.empty) $ fail "A tactic of the form `simp [*, -h] at *` is currently not supported",
s β join_user_simp_lemmas no_dflt attr_names,
(s, u) β simp_lemmas.append_pexprs s [] hs,
s β if not at_star β§ all_hyps then do
ctx β collect_ctx_simps,
let ctx := ctx.filter (Ξ» h, h.local_uniq_name β hex), -- remove local exceptions
s.append ctx
else return s,
-- add equational lemmas, if any
gex β gex.mmap (Ξ» n, list.cons n <$> get_eqn_lemmas_for tt n),
return (all_hyps, simp_lemmas.erase s $ gex.join, u)
meta def mk_simp_set (no_dflt : bool) (attr_names : list name) (hs : list simp_arg_type) : tactic (simp_lemmas Γ list name) :=
prod.snd <$> (mk_simp_set_core no_dflt attr_names hs ff)
end mk_simp_set
namespace interactive
open interactive interactive.types expr
meta def simp_core_aux (cfg : simp_config) (discharger : tactic unit) (s : simp_lemmas) (u : list name) (hs : list expr) (tgt : bool) : tactic unit :=
do to_remove β hs.mfilter $ Ξ» h, do {
h_type β infer_type h,
(do (new_h_type, pr) β simplify s u h_type cfg `eq discharger,
assert h.local_pp_name new_h_type,
mk_eq_mp pr h >>= tactic.exact >> return tt)
<|>
(return ff) },
goal_simplified β if tgt then (simp_target s u cfg discharger >> return tt) <|> (return ff) else return ff,
guard (cfg.fail_if_unchanged = ff β¨ to_remove.length > 0 β¨ goal_simplified) <|> fail "simplify tactic failed to simplify",
to_remove.mmap' (Ξ» h, try (clear h))
meta def simp_core (cfg : simp_config) (discharger : tactic unit)
(no_dflt : bool) (hs : list simp_arg_type) (attr_names : list name)
(locat : loc) : tactic unit :=
match locat with
| loc.wildcard := do (all_hyps, s, u) β mk_simp_set_core no_dflt attr_names hs tt,
if all_hyps then tactic.simp_all s u cfg discharger
else do hyps β non_dep_prop_hyps, simp_core_aux cfg discharger s u hyps tt
| _ := do (s, u) β mk_simp_set no_dflt attr_names hs,
ns β locat.get_locals,
simp_core_aux cfg discharger s u ns locat.include_goal
end
>> try tactic.triv >> try (tactic.reflexivity reducible)
/--
The `simp` tactic uses lemmas and hypotheses to simplify the main goal target or non-dependent hypotheses. It has many variants.
`simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`.
`simp [hβ hβ ... hβ]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and the given `hα΅’`'s, where the `hα΅’`'s are expressions. If an `hα΅’` is a defined constant `f`, then the equational lemmas associated with `f` are used. This provides a convenient way to unfold `f`.
`simp [*]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and all hypotheses.
`simp *` is a shorthand for `simp [*]`.
`simp only [hβ hβ ... hβ]` is like `simp [hβ hβ ... hβ]` but does not use `[simp]` lemmas
`simp [-id_1, ... -id_n]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]`, but removes the ones named `idα΅’`.
`simp at hβ hβ ... hβ` simplifies the non-dependent hypotheses `hβ : Tβ` ... `hβ : Tβ`. The tactic fails if the target or another hypothesis depends on one of them. The token `β’` or `|-` can be added to the list to include the target.
`simp at *` simplifies all the hypotheses and the target.
`simp * at *` simplifies target and all (non-dependent propositional) hypotheses using the other hypotheses.
`simp with attrβ ... attrβ` simplifies the main goal target using the lemmas tagged with any of the attributes `[attrβ]`, ..., `[attrβ]` or `[simp]`.
-/
meta def simp (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list)
(locat : parse location) (cfg : simp_config_ext := {}) : tactic unit :=
simp_core cfg.to_simp_config cfg.discharger no_dflt hs attr_names locat
/--
Just construct the simp set and trace it. Used for debugging.
-/
meta def trace_simp_set (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list) : tactic unit :=
do (s, _) β mk_simp_set no_dflt attr_names hs,
s.pp >>= trace
/--
`simp_intros hβ hβ ... hβ` is similar to `intros hβ hβ ... hβ` except that each hypothesis is simplified as it is introduced, and each introduced hypothesis is used to simplify later ones and the final target.
As with `simp`, a list of simplification lemmas can be provided. The modifiers `only` and `with` behave as with `simp`.
-/
meta def simp_intros (ids : parse ident_*) (no_dflt : parse only_flag) (hs : parse simp_arg_list) (attr_names : parse with_ident_list)
(cfg : simp_intros_config := {}) : tactic unit :=
do (s, u) β mk_simp_set no_dflt attr_names hs,
when (Β¬u.empty) (fail (sformat! "simp_intros tactic does not support {u}")),
tactic.simp_intros s u ids cfg,
try triv >> try (reflexivity reducible)
private meta def to_simp_arg_list (es : list pexpr) : list simp_arg_type :=
es.map simp_arg_type.expr
/--
`dsimp` is similar to `simp`, except that it only uses definitional equalities.
-/
meta def dsimp (no_dflt : parse only_flag) (es : parse simp_arg_list) (attr_names : parse with_ident_list)
(l : parse location) (cfg : dsimp_config := {}) : tactic unit :=
do (s, u) β mk_simp_set no_dflt attr_names es,
match l with
| loc.wildcard := do ls β local_context, n β revert_lst ls, dsimp_target s u cfg, intron n
| _ := l.apply (Ξ» h, dsimp_hyp h s u cfg) (dsimp_target s u cfg)
end
/--
This tactic applies to a goal whose target has the form `t ~ u` where `~` is a reflexive relation, that is, a relation which has a reflexivity lemma tagged with the attribute `[refl]`. The tactic checks whether `t` and `u` are definitionally equal and then solves the goal.
-/
meta def reflexivity : tactic unit :=
tactic.reflexivity
/--
Shorter name for the tactic `reflexivity`.
-/
meta def refl : tactic unit :=
tactic.reflexivity
/--
This tactic applies to a goal whose target has the form `t ~ u` where `~` is a symmetric relation, that is, a relation which has a symmetry lemma tagged with the attribute `[symm]`. It replaces the target with `u ~ t`.
-/
meta def symmetry : tactic unit :=
tactic.symmetry
/--
This tactic applies to a goal whose target has the form `t ~ u` where `~` is a transitive relation, that is, a relation which has a transitivity lemma tagged with the attribute `[trans]`.
`transitivity s` replaces the goal with the two subgoals `t ~ s` and `s ~ u`. If `s` is omitted, then a metavariable is used instead.
-/
meta def transitivity (q : parse texpr?) : tactic unit :=
tactic.transitivity >> match q with
| none := skip
| some q :=
do (r, lhs, rhs) β target_lhs_rhs,
i_to_expr q >>= unify rhs
end
/--
Proves a goal with target `s = t` when `s` and `t` are equal up to the associativity and commutativity of their binary operations.
-/
meta def ac_reflexivity : tactic unit :=
tactic.ac_refl
/--
An abbreviation for `ac_reflexivity`.
-/
meta def ac_refl : tactic unit :=
tactic.ac_refl
/--
Tries to prove the main goal using congruence closure.
-/
meta def cc : tactic unit :=
tactic.cc
/--
Given hypothesis `h : x = t` or `h : t = x`, where `x` is a local constant, `subst h` substitutes `x` by `t` everywhere in the main goal and then clears `h`.
-/
meta def subst (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.subst >> try (tactic.reflexivity reducible)
/--
`clear hβ ... hβ` tries to clear each hypothesis `hα΅’` from the local context.
-/
meta def clear : parse ident* β tactic unit :=
tactic.clear_lst
private meta def to_qualified_name_core : name β list name β tactic name
| n [] := fail $ "unknown declaration '" ++ to_string n ++ "'"
| n (ns::nss) := do
curr β return $ ns ++ n,
env β get_env,
if env.contains curr then return curr
else to_qualified_name_core n nss
private meta def to_qualified_name (n : name) : tactic name :=
do env β get_env,
if env.contains n then return n
else do
ns β open_namespaces,
to_qualified_name_core n ns
private meta def to_qualified_names : list name β tactic (list name)
| [] := return []
| (c::cs) := do new_c β to_qualified_name c, new_cs β to_qualified_names cs, return (new_c::new_cs)
/--
Similar to `unfold`, but only uses definitional equalities.
-/
meta def dunfold (cs : parse ident*) (l : parse location) (cfg : dunfold_config := {}) : tactic unit :=
match l with
| (loc.wildcard) := do ls β tactic.local_context,
n β revert_lst ls,
new_cs β to_qualified_names cs,
dunfold_target new_cs cfg,
intron n
| _ := do new_cs β to_qualified_names cs, l.apply (Ξ» h, dunfold_hyp cs h cfg) (dunfold_target new_cs cfg)
end
private meta def delta_hyps : list name β list name β tactic unit
| cs [] := skip
| cs (h::hs) := get_local h >>= delta_hyp cs >> delta_hyps cs hs
/--
Similar to `dunfold`, but performs a raw delta reduction, rather than using an equation associated with the defined constants.
-/
meta def delta : parse ident* β parse location β tactic unit
| cs (loc.wildcard) := do ls β tactic.local_context,
n β revert_lst ls,
new_cs β to_qualified_names cs,
delta_target new_cs,
intron n
| cs l := do new_cs β to_qualified_names cs, l.apply (delta_hyp new_cs) (delta_target new_cs)
private meta def unfold_projs_hyps (cfg : unfold_proj_config := {}) (hs : list name) : tactic bool :=
hs.mfoldl (Ξ» r h, do h β get_local h, (unfold_projs_hyp h cfg >> return tt) <|> return r) ff
/--
This tactic unfolds all structure projections.
-/
meta def unfold_projs (l : parse location) (cfg : unfold_proj_config := {}) : tactic unit :=
match l with
| loc.wildcard := do ls β local_context,
bβ β unfold_projs_hyps cfg (ls.map expr.local_pp_name),
bβ β (tactic.unfold_projs_target cfg >> return tt) <|> return ff,
when (not bβ β§ not bβ) (fail "unfold_projs failed to simplify")
| _ :=
l.try_apply (Ξ» h, unfold_projs_hyp h cfg)
(tactic.unfold_projs_target cfg) <|> fail "unfold_projs failed to simplify"
end
end interactive
meta def ids_to_simp_arg_list (tac_name : name) (cs : list name) : tactic (list simp_arg_type) :=
cs.mmap $ Ξ» c, do
n β resolve_name c,
hs β get_eqn_lemmas_for ff n.const_name,
env β get_env,
let p := env.is_projection n.const_name,
when (hs.empty β§ p.is_none) (fail (sformat! "{tac_name} tactic failed, {c} does not have equational lemmas nor is a projection")),
return $ simp_arg_type.expr (expr.const c [])
structure unfold_config extends simp_config :=
(zeta := ff)
(proj := ff)
(eta := ff)
(canonize_instances := ff)
namespace interactive
open interactive interactive.types expr
/--
Given defined constants `eβ ... eβ`, `unfold eβ ... eβ` iteratively unfolds all occurrences in the target of the main goal, using equational lemmas associated with the definitions.
As with `simp`, the `at` modifier can be used to specify locations for the unfolding.
-/
meta def unfold (cs : parse ident*) (locat : parse location) (cfg : unfold_config := {}) : tactic unit :=
do es β ids_to_simp_arg_list "unfold" cs,
let no_dflt := tt,
simp_core cfg.to_simp_config failed no_dflt es [] locat
/--
Similar to `unfold`, but does not iterate the unfolding.
-/
meta def unfold1 (cs : parse ident*) (locat : parse location) (cfg : unfold_config := {single_pass := tt}) : tactic unit :=
unfold cs locat cfg
/--
If the target of the main goal is an `opt_param`, assigns the default value.
-/
meta def apply_opt_param : tactic unit :=
tactic.apply_opt_param
/--
If the target of the main goal is an `auto_param`, executes the associated tactic.
-/
meta def apply_auto_param : tactic unit :=
tactic.apply_auto_param
/--
Fails if the given tactic succeeds.
-/
meta def fail_if_success (tac : itactic) : tactic unit :=
tactic.fail_if_success tac
/--
Succeeds if the given tactic fails.
-/
meta def success_if_fail (tac : itactic) : tactic unit :=
tactic.success_if_fail tac
meta def guard_expr_eq (t : expr) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do e β to_expr p, guard (alpha_eqv t e)
/--
`guard_target t` fails if the target of the main goal is not `t`.
We use this tactic for writing tests.
-/
meta def guard_target (p : parse texpr) : tactic unit :=
do t β target, guard_expr_eq t p
/--
`guard_hyp h := t` fails if the hypothesis `h` does not have type `t`.
We use this tactic for writing tests.
-/
meta def guard_hyp (n : parse ident) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do h β get_local n >>= infer_type, guard_expr_eq h p
/--
`match_target t` fails if target does not match pattern `t`.
-/
meta def match_target (t : parse texpr) (m := reducible) : tactic unit :=
tactic.match_target t m >> skip
/--
`by_cases p with h` splits the main goal into two cases, assuming `h : p` in the first branch, and `h : Β¬ p` in the second branch.
This tactic requires that `p` is decidable. To ensure that all propositions are decidable via classical reasoning, use `local attribute classical.prop_decidable [instance]`.
-/
meta def by_cases (q : parse texpr) (n : parse (tk "with" *> ident)?): tactic unit :=
do p β tactic.to_expr_strict q,
tactic.by_cases p (n.get_or_else `h)
/--
Apply function extensionality and introduce new hypotheses.
The tactic `funext` will keep applying new the `funext` lemma until the goal target is not reducible to
```
|- ((fun x, ...) = (fun x, ...))
```
The variant `funext hβ ... hβ` applies `funext` `n` times, and uses the given identifiers to name the new hypotheses.
-/
meta def funext : parse ident_* β tactic unit
| [] := tactic.funext >> skip
| hs := funext_lst hs >> skip
/--
If the target of the main goal is a proposition `p`, `by_contradiction h` reduces the goal to proving `false` using the additional hypothesis `h : Β¬ p`. If `h` is omitted, a name is generated automatically.
This tactic requires that `p` is decidable. To ensure that all propositions are decidable via classical reasoning, use `local attribute classical.prop_decidable [instance]`.
-/
meta def by_contradiction (n : parse ident?) : tactic unit :=
tactic.by_contradiction n >> return ()
/--
An abbreviation for `by_contradiction`.
-/
meta def by_contra (n : parse ident?) : tactic unit :=
tactic.by_contradiction n >> return ()
/--
Type check the given expression, and trace its type.
-/
meta def type_check (p : parse texpr) : tactic unit :=
do e β to_expr p, tactic.type_check e, infer_type e >>= trace
/--
Fail if there are unsolved goals.
-/
meta def done : tactic unit :=
tactic.done
private meta def show_aux (p : pexpr) : list expr β list expr β tactic unit
| [] r := fail "show tactic failed"
| (g::gs) r := do
do {set_goals [g], g_ty β target, ty β i_to_expr p, unify g_ty ty, set_goals (g :: r.reverse ++ gs), tactic.change ty}
<|>
show_aux gs (g::r)
/--
`show t` finds the first goal whose target unifies with `t`. It makes that the main goal, performs the unification, and replaces the target with the unified version of `t`.
-/
meta def Β«showΒ» (q : parse texpr) : tactic unit :=
do gs β get_goals,
show_aux q gs []
/--
The tactic `specialize h aβ ... aβ` works on local hypothesis `h`. The premises of this hypothesis, either universal quantifications or non-dependent implications, are instantiated by concrete terms coming either from arguments `aβ` ... `aβ`. The tactic adds a new hypothesis with the same name `h := h aβ ... aβ` and tries to clear the previous one.
-/
meta def specialize (p : parse texpr) : tactic unit :=
do e β i_to_expr p,
let h := expr.get_app_fn e,
if h.is_local_constant
then tactic.note h.local_pp_name none e >> try (tactic.clear h)
else tactic.fail "specialize requires a term of the form `h x_1 .. x_n` where `h` appears in the local context"
end interactive
end tactic
section add_interactive
open tactic
/- See add_interactive -/
private meta def add_interactive_aux (new_namespace : name) : list name β command
| [] := return ()
| (n::ns) := do
env β get_env,
d_name β resolve_constant n,
(declaration.defn _ ls ty val hints trusted) β env.get d_name,
(name.mk_string h _) β return d_name,
let new_name := `tactic.interactive <.> h,
add_decl (declaration.defn new_name ls ty (expr.const d_name (ls.map level.param)) hints trusted),
add_interactive_aux ns
/--
Copy a list of meta definitions in the current namespace to tactic.interactive.
This command is useful when we want to update tactic.interactive without closing the current namespace.
-/
meta def add_interactive (ns : list name) (p : name := `tactic.interactive) : command :=
add_interactive_aux p ns
meta def has_dup : tactic bool :=
do ctx β local_context,
let p : name_set Γ bool :=
ctx.foldl (Ξ» β¨s, rβ© h,
if r then (s, r)
else if s.contains h.local_pp_name then (s, tt)
else (s.insert h.local_pp_name, ff))
(mk_name_set, ff),
return p.2
/--
Renames hypotheses with the same name.
-/
meta def dedup : tactic unit :=
mwhen has_dup $ do
ctx β local_context,
n β revert_lst ctx,
intron n
end add_interactive
|
069fb1aa0da86d8ecd5e781fc6550a21c40d2ad9
|
d5ff69c5608a867046609101d89910f1257aaf8c
|
/src/2020/problem_sheets/sheet2.lean
|
aabfe9e9a44c0f3df7d53e3a05650178b53212b3
|
[] |
no_license
|
jiaminglimjm/M40001_lean
|
c299ff574a22d3a636a2b9720dc9b5e853a3bab0
|
c8bd8922f37f3e10e2d448f226798ebd0a2af232
|
refs/heads/master
| 1,672,312,761,737
| 1,603,095,035,000
| 1,603,095,035,000
| 304,831,347
| 0
| 0
| null | 1,603,094,893,000
| 1,602,922,986,000
| null |
UTF-8
|
Lean
| false
| false
| 3,097
|
lean
|
/- Math40001 : Introduction to university mathematics.
Problem Sheet 2, October 2020.
This is a Lean file. It can be read with the Lean theorem prover.
You can work on this file online via the link at
https://github.com/ImperialCollegeLondon/M40001_lean/blob/master/README.md
or you can install Lean and its maths library following the
instructions at
https://leanprover-community.github.io/get_started.html
and then just clone the project onto your own computer
with `leanproject get ImperialCollegeLondon/M40001_lean`.
There are advantages to installing Lean on your own computer
(for example it's faster), but it's more hassle than
just using it online.
In the below, delete "sorry" and replace it with some
tactics which prove the result.
-/
import data.real.basic -- need real numbers for Q5
-- Q1 prove that β© is symmetric
lemma question1 (Ξ± : Type) (X Y : set Ξ±) : X β© Y = Y β© X :=
begin
sorry
end
-- question 2 defs
def A := {x : β | x ^ 2 < 3}
def B := {x : β | β n : β€, x = n β§ x ^ 2 < 3}
def C := {x : β | x ^ 3 < 3}
-- Change _true to _false and put a Β¬ in front
-- of the goal if you think it's false.
-- e.g. if you think 2c is false then don't
-- try to prove it's true, try proving
-- lemma question2c_false : Β¬ (A β C) := ...
-- Some of these are tricky for Lean beginners.
lemma question2a_true : (1 : β)/2 β A β© B :=
begin
sorry
end
lemma question2b_true : (1 : β)/2 β A βͺ B :=
begin
sorry
end
lemma question2c_true : A β C :=
begin
sorry
end
lemma question2d_true : B β C :=
begin
sorry
end
lemma question2e_true : C β A βͺ B :=
begin
sorry
end
lemma question2f_true : (A β© B) βͺ C = (A βͺ B) β© C :=
begin
sorry
end
-- Q3 set-up
variables (X Y : Type)
variable (P : X β Prop)
variable (Q : X β Prop)
variable (R : X β Y β Prop)
-- for Q3 you're going to have to change the right hand
-- side of the β in the statement
-- of the lemma to the answer you think is correct.
lemma question3a : Β¬ (β x : X, P x β§ Β¬ Q x) β true := -- change `true`!
begin
sorry
end
lemma question3b : Β¬ (β x : X, (Β¬ P x) β§ Q x) β true := -- change `true`!
begin
sorry
end
lemma question3c : Β¬ (β x : X, β y : Y, R x y) β true := -- change `true`!
begin
sorry
end
example (f : β β β) (x : β) :
Β¬ (β Ξ΅ : β, Ξ΅ > 0 β β Ξ΄ : β, Ξ΄ > 0 β β y : β, abs (y - x) < Ξ΄ β abs (f y -f x) < Ξ΅ )
β -- change next line to what you think the answer is
true :=
begin
sorry
end
-- change _true to _false in 4a, 4b if you think the opposite is true
-- and stick a `Β¬` in front of it
lemma question4a_true : β x : β, β y : β, x + y = 2 :=
begin
sorry
end
lemma question4b_true : β y : β, β x : β, x + y = 2 :=
begin
sorry
end
-- similarly for Q5 -- change _true to _false and add in a negation if you
-- want to prove that the proposition in the question is false.
lemma question5a_true : β x β (β
: set β), 2 + 2 = 5 :=
begin
sorry
end
lemma question5b_true : β x β (β
: set β), 2 + 2 = 5 :=
begin
sorry
end
|
05f309ce1e1b37f67a4b449765d38468b7e1b077
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/data/pnat/xgcd.lean
|
f58589a851047d2d12f54c5ed18a0ceb7958cebe
|
[
"Apache-2.0"
] |
permissive
|
waynemunro/mathlib
|
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
|
065a70810b5480d584033f7bbf8e0409480c2118
|
refs/heads/master
| 1,693,417,182,397
| 1,634,644,781,000
| 1,634,644,781,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 13,637
|
lean
|
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
-/
import tactic.ring
import data.pnat.prime
/-!
# Euclidean algorithm for β
This file sets up a version of the Euclidean algorithm that only works with natural numbers.
Given `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold:
* `a = (w + x) d`
* `b = (y + z) d`
* `w * z = x * y + 1`
`d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime.
This story is closely related to the structure of SLβ(β) (as a free monoid on two generators) and
the theory of continued fractions.
## Main declarations
* `xgcd_type`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp`
`zp`, `ap`, `bp` are the variables getting changed through the algorithm.
* `is_special`: States `wp * zp = x * y + 1`
* `is_reduced`: States `ap = a β§ bp = b`
## Notes
See `nat.xgcd` for a very similar algorithm allowing values in `β€`.
-/
open nat
namespace pnat
/-- A term of xgcd_type is a system of six naturals. They should
be thought of as representing the matrix
[[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]
together with the vector [a, b] = [ap + 1, bp + 1].
-/
@[derive inhabited]
structure xgcd_type :=
(wp x y zp ap bp : β)
namespace xgcd_type
variable (u : xgcd_type)
instance : has_sizeof xgcd_type := β¨Ξ» u, u.bpβ©
/-- The has_repr instance converts terms to strings in a way that
reflects the matrix/vector interpretation as above. -/
instance : has_repr xgcd_type :=
β¨Ξ» u, "[[[" ++ (repr (u.wp + 1)) ++ ", " ++ (repr u.x) ++
"], [" ++ (repr u.y) ++ ", " ++ (repr (u.zp + 1)) ++ "]], [" ++
(repr (u.ap + 1)) ++ ", " ++ (repr (u.bp + 1)) ++ "]]"β©
def mk' (w : β+) (x : β) (y : β) (z : β+) (a : β+) (b : β+) : xgcd_type :=
mk w.val.pred x y z.val.pred a.val.pred b.val.pred
def w : β+ := succ_pnat u.wp
def z : β+ := succ_pnat u.zp
def a : β+ := succ_pnat u.ap
def b : β+ := succ_pnat u.bp
def r : β := (u.ap + 1) % (u.bp + 1)
def q : β := (u.ap + 1) / (u.bp + 1)
def qp : β := u.q - 1
/-- The map v gives the product of the matrix
[[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]]
and the vector [a, b] = [ap + 1, bp + 1]. The map
vp gives [sp, tp] such that v = [sp + 1, tp + 1].
-/
def vp : β Γ β :=
β¨ u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp,
u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp β©
def v : β Γ β := β¨u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.bβ©
def succβ (t : β Γ β) : β Γ β := β¨t.1.succ, t.2.succβ©
theorem v_eq_succ_vp : u.v = succβ u.vp :=
by { ext; dsimp [v, vp, w, z, a, b, succβ];
repeat { rw [nat.succ_eq_add_one] }; ring }
/-- is_special holds if the matrix has determinant one. -/
def is_special : Prop := u.wp + u.zp + u.wp * u.zp = u.x * u.y
def is_special' : Prop := u.w * u.z = succ_pnat (u.x * u.y)
theorem is_special_iff : u.is_special β u.is_special' :=
begin
dsimp [is_special, is_special'],
split; intro h,
{ apply eq, dsimp [w, z, succ_pnat], rw [β h],
repeat { rw [nat.succ_eq_add_one] }, ring },
{ apply nat.succ.inj,
replace h := congr_arg (coe : β+ β β) h,
rw [mul_coe, w, z] at h,
repeat { rw [succ_pnat_coe, nat.succ_eq_add_one] at h },
repeat { rw [nat.succ_eq_add_one] }, rw [β h], ring }
end
/-- is_reduced holds if the two entries in the vector are the
same. The reduction algorithm will produce a system with this
property, whose product vector is the same as for the original
system. -/
def is_reduced : Prop := u.ap = u.bp
def is_reduced' : Prop := u.a = u.b
theorem is_reduced_iff : u.is_reduced β u.is_reduced' :=
β¨ congr_arg succ_pnat, succ_pnat_inj β©
def flip : xgcd_type :=
{ wp := u.zp, x := u.y, y := u.x, zp := u.wp, ap := u.bp, bp := u.ap }
@[simp] theorem flip_w : (flip u).w = u.z := rfl
@[simp] theorem flip_x : (flip u).x = u.y := rfl
@[simp] theorem flip_y : (flip u).y = u.x := rfl
@[simp] theorem flip_z : (flip u).z = u.w := rfl
@[simp] theorem flip_a : (flip u).a = u.b := rfl
@[simp] theorem flip_b : (flip u).b = u.a := rfl
theorem flip_is_reduced : (flip u).is_reduced β u.is_reduced :=
by { dsimp [is_reduced, flip], split; intro h; exact h.symm }
theorem flip_is_special : (flip u).is_special β u.is_special :=
by { dsimp [is_special, flip], rw[mul_comm u.x, mul_comm u.zp, add_comm u.zp] }
theorem flip_v : (flip u).v = (u.v).swap :=
by { dsimp [v], ext, { simp only, ring }, { simp only, ring } }
/-- Properties of division with remainder for a / b. -/
theorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 :=
nat.mod_add_div (u.ap + 1) (u.bp + 1)
theorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 :=
begin
by_cases hq : u.q = 0,
{ let h := u.rq_eq, rw [hr, hq, mul_zero, add_zero] at h, cases h },
{ exact (nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero hq)).symm }
end
/-- The following function provides the starting point for
our algorithm. We will apply an iterative reduction process
to it, which will produce a system satisfying is_reduced.
The gcd can be read off from this final system.
-/
def start (a b : β+) : xgcd_type := β¨0, 0, 0, 0, a - 1, b - 1β©
theorem start_is_special (a b : β+) : (start a b).is_special :=
by { dsimp [start, is_special], refl }
theorem start_v (a b : β+) : (start a b).v = β¨a, bβ© :=
begin
dsimp [start, v, xgcd_type.a, xgcd_type.b, w, z],
rw [one_mul, one_mul, zero_mul, zero_mul, zero_add, add_zero],
rw [β nat.pred_eq_sub_one, β nat.pred_eq_sub_one],
rw [nat.succ_pred_eq_of_pos a.pos, nat.succ_pred_eq_of_pos b.pos]
end
def finish : xgcd_type :=
xgcd_type.mk u.wp ((u.wp + 1) * u.qp + u.x) u.y (u.y * u.qp + u.zp) u.bp u.bp
theorem finish_is_reduced : u.finish.is_reduced :=
by { dsimp [is_reduced], refl }
theorem finish_is_special (hs : u.is_special) : u.finish.is_special :=
begin
dsimp [is_special, finish] at hs β’,
rw [add_mul _ _ u.y, add_comm _ (u.x * u.y), β hs],
ring
end
theorem finish_v (hr : u.r = 0) : u.finish.v = u.v :=
begin
let ha : u.r + u.b * u.q = u.a := u.rq_eq,
rw [hr, zero_add] at ha,
ext,
{ change (u.wp + 1) * u.b + ((u.wp + 1) * u.qp + u.x) * u.b = u.w * u.a + u.x * u.b,
have : u.wp + 1 = u.w := rfl, rw [this, β ha, u.qp_eq hr], ring },
{ change u.y * u.b + (u.y * u.qp + u.z) * u.b = u.y * u.a + u.z * u.b,
rw [β ha, u.qp_eq hr], ring }
end
/-- This is the main reduction step, which is used when u.r β 0, or
equivalently b does not divide a. -/
def step : xgcd_type :=
xgcd_type.mk (u.y * u.q + u.zp) u.y ((u.wp + 1) * u.q + u.x) u.wp u.bp (u.r - 1)
/-- We will apply the above step recursively. The following result
is used to ensure that the process terminates. -/
theorem step_wf (hr : u.r β 0) : sizeof u.step < sizeof u :=
begin
change u.r - 1 < u.bp,
have hβ : (u.r - 1) + 1 = u.r := nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero hr),
have hβ : u.r < u.bp + 1 := nat.mod_lt (u.ap + 1) u.bp.succ_pos,
rw[β hβ] at hβ,
exact lt_of_succ_lt_succ hβ,
end
theorem step_is_special (hs : u.is_special) : u.step.is_special :=
begin
dsimp [is_special, step] at hs β’,
rw [mul_add, mul_comm u.y u.x, β hs],
ring
end
/-- The reduction step does not change the product vector. -/
theorem step_v (hr : u.r β 0) : u.step.v = (u.v).swap :=
begin
let ha : u.r + u.b * u.q = u.a := u.rq_eq,
let hr : (u.r - 1) + 1 = u.r :=
(add_comm _ 1).trans (nat.add_sub_of_le (nat.pos_of_ne_zero hr)),
ext,
{ change ((u.y * u.q + u.z) * u.b + u.y * (u.r - 1 + 1) : β) = u.y * u.a + u.z * u.b,
rw [β ha, hr], ring },
{ change ((u.w * u.q + u.x) * u.b + u.w * (u.r - 1 + 1) : β) = u.w * u.a + u.x * u.b,
rw [β ha, hr], ring }
end
/-- We can now define the full reduction function, which applies
step as long as possible, and then applies finish. Note that the
"have" statement puts a fact in the local context, and the
equation compiler uses this fact to help construct the full
definition in terms of well-founded recursion. The same fact
needs to be introduced in all the inductive proofs of properties
given below. -/
def reduce : xgcd_type β xgcd_type
| u := dite (u.r = 0)
(Ξ» h, u.finish)
(Ξ» h, have sizeof u.step < sizeof u, from u.step_wf h,
flip (reduce u.step))
theorem reduce_a {u : xgcd_type} (h : u.r = 0) :
u.reduce = u.finish := by { rw [reduce], simp only, rw [if_pos h] }
theorem reduce_b {u : xgcd_type} (h : u.r β 0) :
u.reduce = u.step.reduce.flip := by { rw [reduce], simp only, rw [if_neg h, step] }
theorem reduce_reduced : β (u : xgcd_type), u.reduce.is_reduced
| u := dite (u.r = 0) (Ξ» h, by { rw [reduce_a h], exact u.finish_is_reduced })
(Ξ» h, have sizeof u.step < sizeof u, from u.step_wf h,
by { rw [reduce_b h, flip_is_reduced], apply reduce_reduced })
theorem reduce_reduced' (u : xgcd_type) : u.reduce.is_reduced' :=
(is_reduced_iff _).mp u.reduce_reduced
theorem reduce_special : β (u : xgcd_type), u.is_special β u.reduce.is_special
| u := dite (u.r = 0)
(Ξ» h hs, by { rw [reduce_a h], exact u.finish_is_special hs })
(Ξ» h hs, have sizeof u.step < sizeof u, from u.step_wf h,
by { rw [reduce_b h],
exact (flip_is_special _).mpr (reduce_special _ (u.step_is_special hs)) })
theorem reduce_special' (u : xgcd_type) (hs : u.is_special) : u.reduce.is_special' :=
(is_special_iff _).mp (u.reduce_special hs)
theorem reduce_v : β (u : xgcd_type), u.reduce.v = u.v
| u := dite (u.r = 0)
(Ξ» h, by {rw[reduce_a h, finish_v u h]})
(Ξ» h, have sizeof u.step < sizeof u, from u.step_wf h,
by { rw[reduce_b h, flip_v, reduce_v (step u), step_v u h, prod.swap_swap] })
end xgcd_type
section gcd
variables (a b : β+)
def xgcd : xgcd_type := (xgcd_type.start a b).reduce
def gcd_d : β+ := (xgcd a b).a
def gcd_w : β+ := (xgcd a b).w
def gcd_x : β := (xgcd a b).x
def gcd_y : β := (xgcd a b).y
def gcd_z : β+ := (xgcd a b).z
def gcd_a' : β+ := succ_pnat ((xgcd a b).wp + (xgcd a b).x)
def gcd_b' : β+ := succ_pnat ((xgcd a b).y + (xgcd a b).zp)
theorem gcd_a'_coe : ((gcd_a' a b) : β) = (gcd_w a b) + (gcd_x a b) :=
by { dsimp [gcd_a', gcd_x, gcd_w, xgcd_type.w],
rw [nat.succ_eq_add_one, nat.succ_eq_add_one, add_right_comm] }
theorem gcd_b'_coe : ((gcd_b' a b) : β) = (gcd_y a b) + (gcd_z a b) :=
by { dsimp [gcd_b', gcd_y, gcd_z, xgcd_type.z],
rw [nat.succ_eq_add_one, nat.succ_eq_add_one, add_assoc] }
theorem gcd_props :
let d := gcd_d a b,
w := gcd_w a b, x := gcd_x a b, y := gcd_y a b, z := gcd_z a b,
a' := gcd_a' a b, b' := gcd_b' a b in
(w * z = succ_pnat (x * y) β§
(a = a' * d) β§ (b = b' * d) β§
z * a' = succ_pnat (x * b') β§ w * b' = succ_pnat (y * a') β§
(z * a : β) = x * b + d β§ (w * b : β) = y * a + d
) :=
begin
intros,
let u := (xgcd_type.start a b),
let ur := u.reduce,
have ha : d = ur.a := rfl,
have hb : d = ur.b := u.reduce_reduced',
have ha' : (a' : β) = w + x := gcd_a'_coe a b,
have hb' : (b' : β) = y + z := gcd_b'_coe a b,
have hdet : w * z = succ_pnat (x * y) := u.reduce_special' rfl,
split, exact hdet,
have hdet' : ((w * z) : β) = x * y + 1 :=
by { rw [β mul_coe, hdet, succ_pnat_coe] },
have huv : u.v = β¨a, bβ© := (xgcd_type.start_v a b),
let hv : prod.mk (w * d + x * ur.b : β) (y * d + z * ur.b : β) = β¨a, bβ© :=
u.reduce_v.trans (xgcd_type.start_v a b),
rw [β hb, β add_mul, β add_mul, β ha', β hb'] at hv,
have ha'' : (a : β) = a' * d := (congr_arg prod.fst hv).symm,
have hb'' : (b : β) = b' * d := (congr_arg prod.snd hv).symm,
split, exact eq ha'', split, exact eq hb'',
have hza' : (z * a' : β) = x * b' + 1,
by { rw [ha', hb', mul_add, mul_add, mul_comm (z : β), hdet'], ring },
have hwb' : (w * b' : β) = y * a' + 1,
by { rw [ha', hb', mul_add, mul_add, hdet'], ring },
split,
{ apply eq, rw [succ_pnat_coe, nat.succ_eq_add_one, mul_coe, hza'] },
split,
{ apply eq, rw [succ_pnat_coe, nat.succ_eq_add_one, mul_coe, hwb'] },
rw [ha'', hb''], repeat { rw [β mul_assoc] }, rw [hza', hwb'],
split; ring,
end
theorem gcd_eq : gcd_d a b = gcd a b :=
begin
rcases gcd_props a b with β¨hβ, hβ, hβ, hβ, hβ, hβ
, hββ©,
apply dvd_antisymm,
{ apply dvd_gcd,
exact dvd.intro (gcd_a' a b) (hβ.trans (mul_comm _ _)).symm,
exact dvd.intro (gcd_b' a b) (hβ.trans (mul_comm _ _)).symm},
{ have hβ : (gcd a b : β) β£ (gcd_z a b) * a :=
(nat.gcd_dvd_left a b).trans (dvd_mul_left _ _),
have hβ : (gcd a b : β) β£ (gcd_x a b) * b :=
(nat.gcd_dvd_right a b).trans (dvd_mul_left _ _),
rw[hβ
] at hβ, rw dvd_iff,
exact (nat.dvd_add_iff_right hβ).mpr hβ,}
end
theorem gcd_det_eq :
(gcd_w a b) * (gcd_z a b) = succ_pnat ((gcd_x a b) * (gcd_y a b)) :=
(gcd_props a b).1
theorem gcd_a_eq : a = (gcd_a' a b) * (gcd a b) :=
(gcd_eq a b) βΈ (gcd_props a b).2.1
theorem gcd_b_eq : b = (gcd_b' a b) * (gcd a b) :=
(gcd_eq a b) βΈ (gcd_props a b).2.2.1
theorem gcd_rel_left' :
(gcd_z a b) * (gcd_a' a b) = succ_pnat ((gcd_x a b) * (gcd_b' a b)) :=
(gcd_props a b).2.2.2.1
theorem gcd_rel_right' :
(gcd_w a b) * (gcd_b' a b) = succ_pnat ((gcd_y a b) * (gcd_a' a b)) :=
(gcd_props a b).2.2.2.2.1
theorem gcd_rel_left :
((gcd_z a b) * a : β) = (gcd_x a b) * b + (gcd a b) :=
(gcd_eq a b) βΈ (gcd_props a b).2.2.2.2.2.1
theorem gcd_rel_right :
((gcd_w a b) * b : β) = (gcd_y a b) * a + (gcd a b) :=
(gcd_eq a b) βΈ (gcd_props a b).2.2.2.2.2.2
end gcd
end pnat
|
412e0b9859edbbbae127f248a9c84a4f963d5534
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/algebra/group/units_auto.lean
|
8efb60fa5b5994c7c1267c8f6371ed14d9d4ac03
|
[] |
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
| 15,104
|
lean
|
/-
Copyright (c) 2017 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johannes HΓΆlzl, Chris Hughes, Jens Wagemaker
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.group.basic
import Mathlib.logic.nontrivial
import Mathlib.PostPort
universes u l u_1
namespace Mathlib
/-!
# Units (i.e., invertible elements) of a multiplicative monoid
-/
/-- Units of a monoid, bundled version. An element of a `monoid` is a unit if it has a two-sided
inverse. This version bundles the inverse element so that it can be computed. For a predicate
see `is_unit`. -/
structure units (Ξ± : Type u) [monoid Ξ±] where
val : Ξ±
inv : Ξ±
val_inv : val * inv = 1
inv_val : inv * val = 1
/-- Units of an add_monoid, bundled version. An element of an add_monoid is a unit if it has a
two-sided additive inverse. This version bundles the inverse element so that it can be
computed. For a predicate see `is_add_unit`. -/
structure add_units (Ξ± : Type u) [add_monoid Ξ±] where
val : Ξ±
neg : Ξ±
val_neg : val + neg = 0
neg_val : neg + val = 0
namespace units
protected instance Mathlib.add_units.has_coe {Ξ± : Type u} [add_monoid Ξ±] :
has_coe (add_units Ξ±) Ξ± :=
has_coe.mk add_units.val
@[simp] theorem Mathlib.add_units.coe_mk {Ξ± : Type u} [add_monoid Ξ±] (a : Ξ±) (b : Ξ±)
(hβ : a + b = 0) (hβ : b + a = 0) : β(add_units.mk a b hβ hβ) = a :=
rfl
theorem ext {Ξ± : Type u} [monoid Ξ±] : function.injective coe := sorry
theorem Mathlib.add_units.eq_iff {Ξ± : Type u} [add_monoid Ξ±] {a : add_units Ξ±} {b : add_units Ξ±} :
βa = βb β a = b :=
function.injective.eq_iff add_units.ext
theorem Mathlib.add_units.ext_iff {Ξ± : Type u} [add_monoid Ξ±] {a : add_units Ξ±} {b : add_units Ξ±} :
a = b β βa = βb :=
iff.symm add_units.eq_iff
protected instance Mathlib.add_units.decidable_eq {Ξ± : Type u} [add_monoid Ξ±] [DecidableEq Ξ±] :
DecidableEq (add_units Ξ±) :=
fun (a b : add_units Ξ±) => decidable_of_iff' (βa = βb) add_units.ext_iff
@[simp] theorem mk_coe {Ξ± : Type u} [monoid Ξ±] (u : units Ξ±) (y : Ξ±) (hβ : βu * y = 1)
(hβ : y * βu = 1) : mk (βu) y hβ hβ = u :=
ext rfl
/-- Units of a monoid form a group. -/
protected instance group {Ξ± : Type u} [monoid Ξ±] : group (units Ξ±) :=
group.mk (fun (uβ uβ : units Ξ±) => mk (val uβ * val uβ) (inv uβ * inv uβ) sorry sorry) sorry
(mk 1 1 sorry sorry) sorry sorry
(fun (u : units Ξ±) => mk (inv u) (val u) (inv_val u) (val_inv u))
(div_inv_monoid.div._default
(fun (uβ uβ : units Ξ±) => mk (val uβ * val uβ) (inv uβ * inv uβ) sorry sorry) sorry
(mk 1 1 sorry sorry) sorry sorry
fun (u : units Ξ±) => mk (inv u) (val u) (inv_val u) (val_inv u))
sorry
@[simp] theorem Mathlib.add_units.coe_add {Ξ± : Type u} [add_monoid Ξ±] (a : add_units Ξ±)
(b : add_units Ξ±) : β(a + b) = βa + βb :=
rfl
@[simp] theorem coe_one {Ξ± : Type u} [monoid Ξ±] : β1 = 1 := rfl
@[simp] theorem Mathlib.add_units.coe_eq_zero {Ξ± : Type u} [add_monoid Ξ±] {a : add_units Ξ±} :
βa = 0 β a = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (βa = 0 β a = 0)) (Eq.symm add_units.coe_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (βa = β0 β a = 0)) (propext add_units.eq_iff)))
(iff.refl (a = 0)))
@[simp] theorem inv_mk {Ξ± : Type u} [monoid Ξ±] (x : Ξ±) (y : Ξ±) (hβ : x * y = 1) (hβ : y * x = 1) :
mk x y hβ hββ»ΒΉ = mk y x hβ hβ :=
rfl
theorem val_coe {Ξ± : Type u} [monoid Ξ±] (a : units Ξ±) : βa = val a := rfl
theorem coe_inv {Ξ± : Type u} [monoid Ξ±] (a : units Ξ±) : β(aβ»ΒΉ) = inv a := rfl
@[simp] theorem inv_mul {Ξ± : Type u} [monoid Ξ±] (a : units Ξ±) : β(aβ»ΒΉ) * βa = 1 := inv_val a
@[simp] theorem Mathlib.add_units.add_neg {Ξ± : Type u} [add_monoid Ξ±] (a : add_units Ξ±) :
βa + β(-a) = 0 :=
add_units.val_neg a
theorem inv_mul_of_eq {Ξ± : Type u} [monoid Ξ±] {u : units Ξ±} {a : Ξ±} (h : βu = a) : β(uβ»ΒΉ) * a = 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl (β(uβ»ΒΉ) * a = 1)) (Eq.symm h)))
(eq.mpr (id (Eq._oldrec (Eq.refl (β(uβ»ΒΉ) * βu = 1)) (inv_mul u))) (Eq.refl 1))
theorem Mathlib.add_units.add_neg_of_eq {Ξ± : Type u} [add_monoid Ξ±] {u : add_units Ξ±} {a : Ξ±}
(h : βu = a) : a + β(-u) = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + β(-u) = 0)) (Eq.symm h)))
(eq.mpr (id (Eq._oldrec (Eq.refl (βu + β(-u) = 0)) (add_units.add_neg u))) (Eq.refl 0))
@[simp] theorem mul_inv_cancel_left {Ξ± : Type u} [monoid Ξ±] (a : units Ξ±) (b : Ξ±) :
βa * (β(aβ»ΒΉ) * b) = b :=
eq.mpr (id (Eq._oldrec (Eq.refl (βa * (β(aβ»ΒΉ) * b) = b)) (Eq.symm (mul_assoc (βa) (β(aβ»ΒΉ)) b))))
(eq.mpr (id (Eq._oldrec (Eq.refl (βa * β(aβ»ΒΉ) * b = b)) (mul_inv a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (1 * b = b)) (one_mul b))) (Eq.refl b)))
@[simp] theorem Mathlib.add_units.neg_add_cancel_left {Ξ± : Type u} [add_monoid Ξ±] (a : add_units Ξ±)
(b : Ξ±) : β(-a) + (βa + b) = b :=
eq.mpr (id (Eq._oldrec (Eq.refl (β(-a) + (βa + b) = b)) (Eq.symm (add_assoc (β(-a)) (βa) b))))
(eq.mpr (id (Eq._oldrec (Eq.refl (β(-a) + βa + b = b)) (add_units.neg_add a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (0 + b = b)) (zero_add b))) (Eq.refl b)))
@[simp] theorem mul_inv_cancel_right {Ξ± : Type u} [monoid Ξ±] (a : Ξ±) (b : units Ξ±) :
a * βb * β(bβ»ΒΉ) = a :=
eq.mpr (id (Eq._oldrec (Eq.refl (a * βb * β(bβ»ΒΉ) = a)) (mul_assoc a βb β(bβ»ΒΉ))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * (βb * β(bβ»ΒΉ)) = a)) (mul_inv b)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * 1 = a)) (mul_one a))) (Eq.refl a)))
@[simp] theorem Mathlib.add_units.neg_add_cancel_right {Ξ± : Type u} [add_monoid Ξ±] (a : Ξ±)
(b : add_units Ξ±) : a + β(-b) + βb = a :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + β(-b) + βb = a)) (add_assoc a β(-b) βb)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + (β(-b) + βb) = a)) (add_units.neg_add b)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 = a)) (add_zero a))) (Eq.refl a)))
protected instance Mathlib.add_units.inhabited {Ξ± : Type u} [add_monoid Ξ±] :
Inhabited (add_units Ξ±) :=
{ default := 0 }
protected instance comm_group {Ξ± : Type u_1} [comm_monoid Ξ±] : comm_group (units Ξ±) :=
comm_group.mk group.mul sorry group.one sorry sorry group.inv group.div sorry sorry
protected instance Mathlib.add_units.has_repr {Ξ± : Type u} [add_monoid Ξ±] [has_repr Ξ±] :
has_repr (add_units Ξ±) :=
has_repr.mk (repr β add_units.val)
@[simp] theorem Mathlib.add_units.add_right_inj {Ξ± : Type u} [add_monoid Ξ±] (a : add_units Ξ±)
{b : Ξ±} {c : Ξ±} : βa + b = βa + c β b = c :=
sorry
@[simp] theorem Mathlib.add_units.add_left_inj {Ξ± : Type u} [add_monoid Ξ±] (a : add_units Ξ±) {b : Ξ±}
{c : Ξ±} : b + βa = c + βa β b = c :=
sorry
theorem Mathlib.add_units.eq_add_neg_iff_add_eq {Ξ± : Type u} [add_monoid Ξ±] {c : add_units Ξ±}
{a : Ξ±} {b : Ξ±} : a = b + β(-c) β a + βc = b :=
sorry
theorem eq_inv_mul_iff_mul_eq {Ξ± : Type u} [monoid Ξ±] (b : units Ξ±) {a : Ξ±} {c : Ξ±} :
a = β(bβ»ΒΉ) * c β βb * a = c :=
sorry
theorem inv_mul_eq_iff_eq_mul {Ξ± : Type u} [monoid Ξ±] (a : units Ξ±) {b : Ξ±} {c : Ξ±} :
β(aβ»ΒΉ) * b = c β b = βa * c :=
sorry
theorem mul_inv_eq_iff_eq_mul {Ξ± : Type u} [monoid Ξ±] (b : units Ξ±) {a : Ξ±} {c : Ξ±} :
a * β(bβ»ΒΉ) = c β a = c * βb :=
sorry
theorem inv_eq_of_mul_eq_one {Ξ± : Type u} [monoid Ξ±] {u : units Ξ±} {a : Ξ±} (h : βu * a = 1) :
β(uβ»ΒΉ) = a :=
sorry
theorem inv_unique {Ξ± : Type u} [monoid Ξ±] {uβ : units Ξ±} {uβ : units Ξ±} (h : βuβ = βuβ) :
β(uββ»ΒΉ) = β(uββ»ΒΉ) :=
(fun (this : βuβ * β(uββ»ΒΉ) = 1) => inv_eq_of_mul_eq_one this)
(eq.mpr (id (Eq._oldrec (Eq.refl (βuβ * β(uββ»ΒΉ) = 1)) h))
(eq.mpr (id (Eq._oldrec (Eq.refl (βuβ * β(uββ»ΒΉ) = 1)) (mul_inv uβ))) (Eq.refl 1)))
end units
/-- For `a, b` in a `comm_monoid` such that `a * b = 1`, makes a unit out of `a`. -/
def add_units.mk_of_add_eq_zero {Ξ± : Type u} [add_comm_monoid Ξ±] (a : Ξ±) (b : Ξ±) (hab : a + b = 0) :
add_units Ξ± :=
add_units.mk a b hab sorry
@[simp] theorem units.coe_mk_of_mul_eq_one {Ξ± : Type u} [comm_monoid Ξ±] {a : Ξ±} {b : Ξ±}
(h : a * b = 1) : β(units.mk_of_mul_eq_one a b h) = a :=
rfl
/-- Partial division. It is defined when the
second argument is invertible, and unlike the division operator
in `division_ring` it is not totalized at zero. -/
def divp {Ξ± : Type u} [monoid Ξ±] (a : Ξ±) (u : units Ξ±) : Ξ± := a * β(uβ»ΒΉ)
infixl:70 " /β " => Mathlib.divp
@[simp] theorem divp_self {Ξ± : Type u} [monoid Ξ±] (u : units Ξ±) : βu /β u = 1 := units.mul_inv u
@[simp] theorem divp_one {Ξ± : Type u} [monoid Ξ±] (a : Ξ±) : a /β 1 = a := mul_one a
theorem divp_assoc {Ξ± : Type u} [monoid Ξ±] (a : Ξ±) (b : Ξ±) (u : units Ξ±) :
a * b /β u = a * (b /β u) :=
mul_assoc a b β(uβ»ΒΉ)
@[simp] theorem divp_inv {Ξ± : Type u} [monoid Ξ±] {a : Ξ±} (u : units Ξ±) : a /β (uβ»ΒΉ) = a * βu := rfl
@[simp] theorem divp_mul_cancel {Ξ± : Type u} [monoid Ξ±] (a : Ξ±) (u : units Ξ±) : a /β u * βu = a :=
Eq.trans (mul_assoc a β(uβ»ΒΉ) βu)
(eq.mpr (id (Eq._oldrec (Eq.refl (a * (β(uβ»ΒΉ) * βu) = a)) (units.inv_mul u)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * 1 = a)) (mul_one a))) (Eq.refl a)))
@[simp] theorem mul_divp_cancel {Ξ± : Type u} [monoid Ξ±] (a : Ξ±) (u : units Ξ±) : a * βu /β u = a :=
Eq.trans (mul_assoc a βu β(uβ»ΒΉ))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * (βu * β(uβ»ΒΉ)) = a)) (units.mul_inv u)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * 1 = a)) (mul_one a))) (Eq.refl a)))
@[simp] theorem divp_left_inj {Ξ± : Type u} [monoid Ξ±] (u : units Ξ±) {a : Ξ±} {b : Ξ±} :
a /β u = b /β u β a = b :=
units.mul_left_inj (uβ»ΒΉ)
theorem divp_divp_eq_divp_mul {Ξ± : Type u} [monoid Ξ±] (x : Ξ±) (uβ : units Ξ±) (uβ : units Ξ±) :
x /β uβ /β uβ = x /β (uβ * uβ) :=
sorry
theorem divp_eq_iff_mul_eq {Ξ± : Type u} [monoid Ξ±] {x : Ξ±} {u : units Ξ±} {y : Ξ±} :
x /β u = y β y * βu = x :=
iff.trans (iff.symm (units.mul_left_inj u))
(eq.mpr (id (Eq._oldrec (Eq.refl (x /β u * βu = y * βu β y * βu = x)) (divp_mul_cancel x u)))
{ mp := Eq.symm, mpr := Eq.symm })
theorem divp_eq_one_iff_eq {Ξ± : Type u} [monoid Ξ±] {a : Ξ±} {u : units Ξ±} : a /β u = 1 β a = βu :=
iff.trans (iff.symm (units.mul_left_inj u))
(eq.mpr (id (Eq._oldrec (Eq.refl (a /β u * βu = 1 * βu β a = βu)) (divp_mul_cancel a u)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a = 1 * βu β a = βu)) (one_mul βu))) (iff.refl (a = βu))))
@[simp] theorem one_divp {Ξ± : Type u} [monoid Ξ±] (u : units Ξ±) : 1 /β u = β(uβ»ΒΉ) := one_mul β(uβ»ΒΉ)
theorem divp_eq_divp_iff {Ξ± : Type u} [comm_monoid Ξ±] {x : Ξ±} {y : Ξ±} {ux : units Ξ±}
{uy : units Ξ±} : x /β ux = y /β uy β x * βuy = y * βux :=
sorry
theorem divp_mul_divp {Ξ± : Type u} [comm_monoid Ξ±] (x : Ξ±) (y : Ξ±) (ux : units Ξ±) (uy : units Ξ±) :
x /β ux * (y /β uy) = x * y /β (ux * uy) :=
sorry
/-!
# `is_unit` predicate
In this file we define the `is_unit` predicate on a `monoid`, and
prove a few basic properties. For the bundled version see `units`. See
also `prime`, `associated`, and `irreducible` in `algebra/associated`.
-/
/-- An element `a : M` of a monoid is a unit if it has a two-sided inverse.
The actual definition says that `a` is equal to some `u : units M`, where
`units M` is a bundled version of `is_unit`. -/
def is_unit {M : Type u_1} [monoid M] (a : M) := β (u : units M), βu = a
theorem is_unit_of_subsingleton {M : Type u_1} [monoid M] [subsingleton M] (a : M) : is_unit a :=
Exists.intro (units.mk a a (subsingleton.elim (a * a) 1) (subsingleton.elim (a * a) 1)) rfl
@[simp] theorem is_unit_unit {M : Type u_1} [monoid M] (u : units M) : is_unit βu :=
Exists.intro u rfl
@[simp] theorem is_add_unit_zero {M : Type u_1} [add_monoid M] : is_add_unit 0 := Exists.intro 0 rfl
theorem is_add_unit_of_add_eq_zero {M : Type u_1} [add_comm_monoid M] (a : M) (b : M)
(h : a + b = 0) : is_add_unit a :=
Exists.intro (add_units.mk_of_add_eq_zero a b h) rfl
theorem is_add_unit_iff_exists_neg {M : Type u_1} [add_comm_monoid M] {a : M} :
is_add_unit a β β (b : M), a + b = 0 :=
sorry
theorem is_add_unit_iff_exists_neg' {M : Type u_1} [add_comm_monoid M] {a : M} :
is_add_unit a β β (b : M), b + a = 0 :=
sorry
/-- Multiplication by a `u : units M` doesn't affect `is_unit`. -/
@[simp] theorem units.is_unit_mul_units {M : Type u_1} [monoid M] (a : M) (u : units M) :
is_unit (a * βu) β is_unit a :=
sorry
theorem is_unit.mul {M : Type u_1} [monoid M] {x : M} {y : M} :
is_unit x β is_unit y β is_unit (x * y) :=
sorry
theorem is_add_unit_of_add_is_add_unit_left {M : Type u_1} [add_comm_monoid M] {x : M} {y : M}
(hu : is_add_unit (x + y)) : is_add_unit x :=
sorry
theorem is_unit_of_mul_is_unit_right {M : Type u_1} [comm_monoid M] {x : M} {y : M}
(hu : is_unit (x * y)) : is_unit y :=
is_unit_of_mul_is_unit_left
(eq.mpr (id (Eq._oldrec (Eq.refl (is_unit (y * x))) (mul_comm y x))) hu)
theorem is_unit.mul_right_inj {M : Type u_1} [monoid M] {a : M} {b : M} {c : M} (ha : is_unit a) :
a * b = a * c β b = c :=
sorry
theorem is_unit.mul_left_inj {M : Type u_1} [monoid M] {a : M} {b : M} {c : M} (ha : is_unit a) :
b * a = c * a β b = c :=
sorry
/-- The element of the group of units, corresponding to an element of a monoid which is a unit. -/
def is_unit.unit {M : Type u_1} [monoid M] {a : M} (h : is_unit a) : units M := classical.some h
theorem is_unit.unit_spec {M : Type u_1} [monoid M] {a : M} (h : is_unit a) :
β(is_unit.unit h) = a :=
classical.some_spec h
/-- Constructs a `group` structure on a `monoid` consisting only of units. -/
def group_of_is_unit {M : Type u_1} [hM : monoid M] (h : β (a : M), is_unit a) : group M :=
group.mk monoid.mul monoid.mul_assoc monoid.one monoid.one_mul monoid.mul_one
(fun (a : M) => β(is_unit.unit (h a)β»ΒΉ))
(div_inv_monoid.div._default monoid.mul monoid.mul_assoc monoid.one monoid.one_mul
monoid.mul_one fun (a : M) => β(is_unit.unit (h a)β»ΒΉ))
sorry
/-- Constructs a `comm_group` structure on a `comm_monoid` consisting only of units. -/
def comm_group_of_is_unit {M : Type u_1} [hM : comm_monoid M] (h : β (a : M), is_unit a) :
comm_group M :=
comm_group.mk comm_monoid.mul comm_monoid.mul_assoc comm_monoid.one comm_monoid.one_mul
comm_monoid.mul_one (fun (a : M) => β(is_unit.unit (h a)β»ΒΉ))
(group.div._default comm_monoid.mul comm_monoid.mul_assoc comm_monoid.one comm_monoid.one_mul
comm_monoid.mul_one fun (a : M) => β(is_unit.unit (h a)β»ΒΉ))
sorry comm_monoid.mul_comm
end Mathlib
|
bfe79bbe9b506af5da37c4da8b7a666df0cbf8bf
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/measure_theory/measurable_space.lean
|
60e479ef9cf97e7a9e63eb1af664962b960247be
|
[
"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
| 68,527
|
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 data.prod.tprod
import group_theory.coset
import logic.equiv.fin
import measure_theory.measurable_space_def
import order.filter.small_sets
import order.liminf_limsup
import measure_theory.tactic
/-!
# Measurable spaces and measurable functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file provides properties of measurable spaces and the functions and isomorphisms
between them. The definition of a measurable space is in `measure_theory.measurable_space_def`.
A measurable space is a set equipped with a Ο-algebra, a collection of
subsets closed under complementation and countable union. A function
between measurable spaces is measurable if the preimage of each
measurable subset is measurable.
Ο-algebras on a fixed set `Ξ±` form a complete lattice. Here we order
Ο-algebras by writing `mβ β€ mβ` if every set which is `mβ`-measurable is
also `mβ`-measurable (that is, `mβ` is a subset of `mβ`). In particular, any
collection of subsets of `Ξ±` generates a smallest Ο-algebra which
contains all of them. A function `f : Ξ± β Ξ²` induces a Galois connection
between the lattices of Ο-algebras on `Ξ±` and `Ξ²`.
A measurable equivalence between measurable spaces is an equivalence
which respects the Ο-algebras, that is, for which both directions of
the equivalence are measurable functions.
We say that a filter `f` is measurably generated if every set `s β f` includes a measurable
set `t β f`. This property is useful, e.g., to extract a measurable witness of `filter.eventually`.
## Notation
* We write `Ξ± βα΅ Ξ²` for measurable equivalences between the measurable spaces `Ξ±` and `Ξ²`.
This should not be confused with `ββ` which is used for diffeomorphisms between manifolds.
## Implementation notes
Measurability of a function `f : Ξ± β Ξ²` between measurable spaces is
defined in terms of the Galois connection induced by f.
## References
* <https://en.wikipedia.org/wiki/Measurable_space>
* <https://en.wikipedia.org/wiki/Sigma-algebra>
* <https://en.wikipedia.org/wiki/Dynkin_system>
## Tags
measurable space, Ο-algebra, measurable function, measurable equivalence, dynkin system,
Ο-Ξ» theorem, Ο-system
-/
open set encodable function equiv
open_locale filter measure_theory
variables {Ξ± Ξ² Ξ³ Ξ΄ Ξ΄' : Type*} {ΞΉ : Sort*} {s t u : set Ξ±}
namespace measurable_space
section functors
variables {m mβ mβ : measurable_space Ξ±} {m' : measurable_space Ξ²} {f : Ξ± β Ξ²} {g : Ξ² β Ξ±}
/-- The forward image of a measurable space under a function. `map f m` contains the sets
`s : set Ξ²` whose preimage under `f` is measurable. -/
protected def map (f : Ξ± β Ξ²) (m : measurable_space Ξ±) : measurable_space Ξ² :=
{ measurable_set' := Ξ» s, measurable_set[m] $ f β»ΒΉ' s,
measurable_set_empty := m.measurable_set_empty,
measurable_set_compl := assume s hs, m.measurable_set_compl _ hs,
measurable_set_Union := assume f hf, by { rw preimage_Union, exact m.measurable_set_Union _ hf }}
@[simp] lemma map_id : m.map id = m :=
measurable_space.ext $ assume s, iff.rfl
@[simp] lemma map_comp {f : Ξ± β Ξ²} {g : Ξ² β Ξ³} : (m.map f).map g = m.map (g β f) :=
measurable_space.ext $ assume s, iff.rfl
/-- The reverse image of a measurable space under a function. `comap f m` contains the sets
`s : set Ξ±` such that `s` is the `f`-preimage of a measurable set in `Ξ²`. -/
protected def comap (f : Ξ± β Ξ²) (m : measurable_space Ξ²) : measurable_space Ξ± :=
{ measurable_set' := Ξ» s, βs', measurable_set[m] s' β§ f β»ΒΉ' s' = s,
measurable_set_empty := β¨β
, m.measurable_set_empty, rflβ©,
measurable_set_compl := assume s β¨s', hβ, hββ©, β¨s'αΆ, m.measurable_set_compl _ hβ, hβ βΈ rflβ©,
measurable_set_Union := assume s hs,
let β¨s', hs'β© := classical.axiom_of_choice hs in
β¨β i, s' i, m.measurable_set_Union _ (Ξ» i, (hs' i).left), by simp [hs'] β© }
lemma comap_eq_generate_from (m : measurable_space Ξ²) (f : Ξ± β Ξ²) :
m.comap f = generate_from {t | β s, measurable_set s β§ f β»ΒΉ' s = t} :=
by convert generate_from_measurable_set.symm
@[simp] lemma comap_id : m.comap id = m :=
measurable_space.ext $ assume s, β¨assume β¨s', hs', hβ©, h βΈ hs', assume h, β¨s, h, rflβ©β©
@[simp] lemma comap_comp {f : Ξ² β Ξ±} {g : Ξ³ β Ξ²} : (m.comap f).comap g = m.comap (f β g) :=
measurable_space.ext $ assume s,
β¨assume β¨t, β¨u, h, huβ©, htβ©, β¨u, h, ht βΈ hu βΈ rflβ©, assume β¨t, h, htβ©, β¨f β»ΒΉ' t, β¨_, h, rflβ©, htβ©β©
lemma comap_le_iff_le_map {f : Ξ± β Ξ²} : m'.comap f β€ m β m' β€ m.map f :=
β¨assume h s hs, h _ β¨_, hs, rflβ©, assume h s β¨t, ht, heqβ©, heq βΈ h _ htβ©
lemma gc_comap_map (f : Ξ± β Ξ²) :
galois_connection (measurable_space.comap f) (measurable_space.map f) :=
assume f g, comap_le_iff_le_map
lemma map_mono (h : mβ β€ mβ) : mβ.map f β€ mβ.map f := (gc_comap_map f).monotone_u h
lemma monotone_map : monotone (measurable_space.map f) := assume a b h, map_mono h
lemma comap_mono (h : mβ β€ mβ) : mβ.comap g β€ mβ.comap g := (gc_comap_map g).monotone_l h
lemma monotone_comap : monotone (measurable_space.comap g) := assume a b h, comap_mono h
@[simp] lemma comap_bot : (β₯ : measurable_space Ξ±).comap g = β₯ := (gc_comap_map g).l_bot
@[simp] lemma comap_sup : (mβ β mβ).comap g = mβ.comap g β mβ.comap g := (gc_comap_map g).l_sup
@[simp] lemma comap_supr {m : ΞΉ β measurable_space Ξ±} : (β¨i, m i).comap g = (β¨i, (m i).comap g) :=
(gc_comap_map g).l_supr
@[simp] lemma map_top : (β€ : measurable_space Ξ±).map f = β€ := (gc_comap_map f).u_top
@[simp] lemma map_inf : (mβ β mβ).map f = mβ.map f β mβ.map f := (gc_comap_map f).u_inf
@[simp] lemma map_infi {m : ΞΉ β measurable_space Ξ±} : (β¨
i, m i).map f = (β¨
i, (m i).map f) :=
(gc_comap_map f).u_infi
lemma comap_map_le : (m.map f).comap f β€ m := (gc_comap_map f).l_u_le _
lemma le_map_comap : m β€ (m.comap g).map g := (gc_comap_map g).le_u_l _
end functors
lemma comap_generate_from {f : Ξ± β Ξ²} {s : set (set Ξ²)} :
(generate_from s).comap f = generate_from (preimage f '' s) :=
le_antisymm
(comap_le_iff_le_map.2 $ generate_from_le $ assume t hts,
generate_measurable.basic _ $ mem_image_of_mem _ $ hts)
(generate_from_le $ assume t β¨u, hu, eqβ©, eq βΈ β¨u, generate_measurable.basic _ hu, rflβ©)
end measurable_space
section measurable_functions
open measurable_space
lemma measurable_iff_le_map {mβ : measurable_space Ξ±} {mβ : measurable_space Ξ²} {f : Ξ± β Ξ²} :
measurable f β mβ β€ mβ.map f :=
iff.rfl
alias measurable_iff_le_map β measurable.le_map measurable.of_le_map
lemma measurable_iff_comap_le {mβ : measurable_space Ξ±} {mβ : measurable_space Ξ²} {f : Ξ± β Ξ²} :
measurable f β mβ.comap f β€ mβ :=
comap_le_iff_le_map.symm
alias measurable_iff_comap_le β measurable.comap_le measurable.of_comap_le
lemma comap_measurable {m : measurable_space Ξ²} (f : Ξ± β Ξ²) :
measurable[m.comap f] f :=
Ξ» s hs, β¨s, hs, rflβ©
lemma measurable.mono {ma ma' : measurable_space Ξ±} {mb mb' : measurable_space Ξ²} {f : Ξ± β Ξ²}
(hf : @measurable Ξ± Ξ² ma mb f) (ha : ma β€ ma') (hb : mb' β€ mb) :
@measurable Ξ± Ξ² ma' mb' f :=
Ξ» t ht, ha _ $ hf $ hb _ ht
@[measurability]
lemma measurable_from_top [measurable_space Ξ²] {f : Ξ± β Ξ²} : measurable[β€] f :=
Ξ» s hs, trivial
lemma measurable_generate_from [measurable_space Ξ±] {s : set (set Ξ²)} {f : Ξ± β Ξ²}
(h : β t β s, measurable_set (f β»ΒΉ' t)) : @measurable _ _ _ (generate_from s) f :=
measurable.of_le_map $ generate_from_le h
variables {f g : Ξ± β Ξ²}
section typeclass_measurable_space
variables [measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³]
@[nontriviality, measurability]
lemma subsingleton.measurable [subsingleton Ξ±] : measurable f :=
Ξ» s hs, @subsingleton.measurable_set Ξ± _ _ _
@[nontriviality, measurability]
lemma measurable_of_subsingleton_codomain [subsingleton Ξ²] (f : Ξ± β Ξ²) :
measurable f :=
Ξ» s hs, subsingleton.set_cases measurable_set.empty measurable_set.univ s
@[to_additive]
lemma measurable_one [has_one Ξ±] : measurable (1 : Ξ² β Ξ±) := @measurable_const _ _ _ _ 1
lemma measurable_of_empty [is_empty Ξ±] (f : Ξ± β Ξ²) : measurable f :=
subsingleton.measurable
lemma measurable_of_empty_codomain [is_empty Ξ²] (f : Ξ± β Ξ²) : measurable f :=
by { haveI := function.is_empty f, exact measurable_of_empty f }
/-- A version of `measurable_const` that assumes `f x = f y` for all `x, y`. This version works
for functions between empty types. -/
lemma measurable_const' {f : Ξ² β Ξ±} (hf : β x y, f x = f y) : measurable f :=
begin
casesI is_empty_or_nonempty Ξ²,
{ exact measurable_of_empty f },
{ convert measurable_const, exact funext (Ξ» x, hf x h.some) }
end
@[measurability] lemma measurable_nat_cast [has_nat_cast Ξ±] (n : β) : measurable (n : Ξ² β Ξ±) :=
@measurable_const Ξ± _ _ _ n
@[measurability] lemma measurable_int_cast [has_int_cast Ξ±] (n : β€) : measurable (n : Ξ² β Ξ±) :=
@measurable_const Ξ± _ _ _ n
lemma measurable_of_finite [finite Ξ±] [measurable_singleton_class Ξ±] (f : Ξ± β Ξ²) : measurable f :=
Ξ» s hs, (f β»ΒΉ' s).to_finite.measurable_set
lemma measurable_of_countable [countable Ξ±] [measurable_singleton_class Ξ±] (f : Ξ± β Ξ²) :
measurable f :=
Ξ» s hs, (f β»ΒΉ' s).to_countable.measurable_set
end typeclass_measurable_space
variables {m : measurable_space Ξ±}
include m
@[measurability] lemma measurable.iterate {f : Ξ± β Ξ±} (hf : measurable f) : β n, measurable (f^[n])
| 0 := measurable_id
| (n+1) := (measurable.iterate n).comp hf
variables {mΞ² : measurable_space Ξ²}
include mΞ²
@[measurability]
lemma measurable_set_preimage {t : set Ξ²} (hf : measurable f) (ht : measurable_set t) :
measurable_set (f β»ΒΉ' t) :=
hf ht
@[measurability]
lemma measurable.piecewise {_ : decidable_pred (β s)} (hs : measurable_set s)
(hf : measurable f) (hg : measurable g) :
measurable (piecewise s f g) :=
begin
intros t ht,
rw piecewise_preimage,
exact hs.ite (hf ht) (hg ht)
end
/-- this is slightly different from `measurable.piecewise`. It can be used to show
`measurable (ite (x=0) 0 1)` by
`exact measurable.ite (measurable_set_singleton 0) measurable_const measurable_const`,
but replacing `measurable.ite` by `measurable.piecewise` in that example proof does not work. -/
lemma measurable.ite {p : Ξ± β Prop} {_ : decidable_pred p}
(hp : measurable_set {a : Ξ± | p a}) (hf : measurable f) (hg : measurable g) :
measurable (Ξ» x, ite (p x) (f x) (g x)) :=
measurable.piecewise hp hf hg
@[measurability]
lemma measurable.indicator [has_zero Ξ²] (hf : measurable f) (hs : measurable_set s) :
measurable (s.indicator f) :=
hf.piecewise hs measurable_const
@[measurability, to_additive] lemma measurable_set_mul_support [has_one Ξ²]
[measurable_singleton_class Ξ²] (hf : measurable f) :
measurable_set (mul_support f) :=
hf (measurable_set_singleton 1).compl
/-- If a function coincides with a measurable function outside of a countable set, it is
measurable. -/
lemma measurable.measurable_of_countable_ne [measurable_singleton_class Ξ±]
(hf : measurable f) (h : set.countable {x | f x β g x}) : measurable g :=
begin
assume t ht,
have : g β»ΒΉ' t = (g β»ΒΉ' t β© {x | f x = g x}αΆ) βͺ (g β»ΒΉ' t β© {x | f x = g x}),
by simp [β inter_union_distrib_left],
rw this,
apply measurable_set.union (h.mono (inter_subset_right _ _)).measurable_set,
have : g β»ΒΉ' t β© {x : Ξ± | f x = g x} = f β»ΒΉ' t β© {x : Ξ± | f x = g x},
by { ext x, simp {contextual := tt} },
rw this,
exact (hf ht).inter h.measurable_set.of_compl,
end
end measurable_functions
section constructions
instance : measurable_space empty := β€
instance : measurable_space punit := β€ -- this also works for `unit`
instance : measurable_space bool := β€
instance : measurable_space β := β€
instance : measurable_space β€ := β€
instance : measurable_space β := β€
instance : measurable_singleton_class empty := β¨Ξ» _, trivialβ©
instance : measurable_singleton_class punit := β¨Ξ» _, trivialβ©
instance : measurable_singleton_class bool := β¨Ξ» _, trivialβ©
instance : measurable_singleton_class β := β¨Ξ» _, trivialβ©
instance : measurable_singleton_class β€ := β¨Ξ» _, trivialβ©
instance : measurable_singleton_class β := β¨Ξ» _, trivialβ©
lemma measurable_to_countable [measurable_space Ξ±] [countable Ξ±] [measurable_space Ξ²] {f : Ξ² β Ξ±}
(h : β y, measurable_set (f β»ΒΉ' {f y})) :
measurable f :=
begin
assume s hs,
rw [β bUnion_preimage_singleton],
refine measurable_set.Union (Ξ» y, measurable_set.Union $ Ξ» hy, _),
by_cases hyf : y β range f,
{ rcases hyf with β¨y, rflβ©,
apply h },
{ simp only [preimage_singleton_eq_empty.2 hyf, measurable_set.empty] }
end
lemma measurable_to_countable' [measurable_space Ξ±] [countable Ξ±] [measurable_space Ξ²] {f : Ξ² β Ξ±}
(h : β x, measurable_set (f β»ΒΉ' {x})) : measurable f :=
measurable_to_countable (Ξ» y, h (f y))
@[measurability] lemma measurable_unit [measurable_space Ξ±] (f : unit β Ξ±) : measurable f :=
measurable_from_top
section nat
variables [measurable_space Ξ±]
@[measurability] lemma measurable_from_nat {f : β β Ξ±} : measurable f :=
measurable_from_top
lemma measurable_to_nat {f : Ξ± β β} : (β y, measurable_set (f β»ΒΉ' {f y})) β measurable f :=
measurable_to_countable
lemma measurable_to_bool {f : Ξ± β bool} (h : measurable_set (fβ»ΒΉ' {tt})) : measurable f :=
begin
apply measurable_to_countable',
rintros (-|-),
{ convert h.compl,
rw [β preimage_compl, bool.compl_singleton, bool.bnot_tt] },
exact h,
end
lemma measurable_find_greatest' {p : Ξ± β β β Prop} [β x, decidable_pred (p x)]
{N : β} (hN : β k β€ N, measurable_set {x | nat.find_greatest (p x) N = k}) :
measurable (Ξ» x, nat.find_greatest (p x) N) :=
measurable_to_nat $ Ξ» x, hN _ N.find_greatest_le
lemma measurable_find_greatest {p : Ξ± β β β Prop} [β x, decidable_pred (p x)]
{N} (hN : β k β€ N, measurable_set {x | p x k}) :
measurable (Ξ» x, nat.find_greatest (p x) N) :=
begin
refine measurable_find_greatest' (Ξ» k hk, _),
simp only [nat.find_greatest_eq_iff, set_of_and, set_of_forall, β compl_set_of],
repeat { apply_rules [measurable_set.inter, measurable_set.const, measurable_set.Inter,
measurable_set.compl, hN]; try { intros } }
end
lemma measurable_find {p : Ξ± β β β Prop} [β x, decidable_pred (p x)]
(hp : β x, β N, p x N) (hm : β k, measurable_set {x | p x k}) :
measurable (Ξ» x, nat.find (hp x)) :=
begin
refine measurable_to_nat (Ξ» x, _),
rw [preimage_find_eq_disjointed],
exact measurable_set.disjointed hm _
end
end nat
section quotient
variables [measurable_space Ξ±] [measurable_space Ξ²]
instance {Ξ±} {r : Ξ± β Ξ± β Prop} [m : measurable_space Ξ±] : measurable_space (quot r) :=
m.map (quot.mk r)
instance {Ξ±} {s : setoid Ξ±} [m : measurable_space Ξ±] : measurable_space (quotient s) :=
m.map quotient.mk'
@[to_additive]
instance _root_.quotient_group.measurable_space {G} [group G] [measurable_space G]
(S : subgroup G) : measurable_space (G β§Έ S) :=
quotient.measurable_space
lemma measurable_set_quotient {s : setoid Ξ±} {t : set (quotient s)} :
measurable_set t β measurable_set (quotient.mk' β»ΒΉ' t) :=
iff.rfl
lemma measurable_from_quotient {s : setoid Ξ±} {f : quotient s β Ξ²} :
measurable f β measurable (f β quotient.mk') :=
iff.rfl
@[measurability] lemma measurable_quotient_mk [s : setoid Ξ±] :
measurable (quotient.mk : Ξ± β quotient s) :=
Ξ» s, id
@[measurability] lemma measurable_quotient_mk' {s : setoid Ξ±} :
measurable (quotient.mk' : Ξ± β quotient s) :=
Ξ» s, id
@[measurability] lemma measurable_quot_mk {r : Ξ± β Ξ± β Prop} :
measurable (quot.mk r) :=
Ξ» s, id
@[to_additive] lemma quotient_group.measurable_coe {G} [group G] [measurable_space G]
{S : subgroup G} : measurable (coe : G β G β§Έ S) :=
measurable_quotient_mk'
attribute [measurability] quotient_group.measurable_coe quotient_add_group.measurable_coe
@[to_additive] lemma quotient_group.measurable_from_quotient {G} [group G] [measurable_space G]
{S : subgroup G} {f : G β§Έ S β Ξ±} :
measurable f β measurable (f β (coe : G β G β§Έ S)) :=
measurable_from_quotient
end quotient
section subtype
instance {Ξ±} {p : Ξ± β Prop} [m : measurable_space Ξ±] : measurable_space (subtype p) :=
m.comap (coe : _ β Ξ±)
section
variables [measurable_space Ξ±]
@[measurability] lemma measurable_subtype_coe {p : Ξ± β Prop} : measurable (coe : subtype p β Ξ±) :=
measurable_space.le_map_comap
instance {p : Ξ± β Prop} [measurable_singleton_class Ξ±] : measurable_singleton_class (subtype p) :=
{ measurable_set_singleton := Ξ» x,
begin
have : measurable_set {(x : Ξ±)} := measurable_set_singleton _,
convert @measurable_subtype_coe Ξ± _ p _ this,
ext y,
simp [subtype.ext_iff],
end }
end
variables {m : measurable_space Ξ±} {mΞ² : measurable_space Ξ²}
include m
lemma measurable_set.subtype_image {s : set Ξ±} {t : set s}
(hs : measurable_set s) : measurable_set t β measurable_set ((coe : s β Ξ±) '' t)
| β¨u, (hu : measurable_set u), (eq : coe β»ΒΉ' u = t)β© :=
begin
rw [β eq, subtype.image_preimage_coe],
exact hu.inter hs
end
include mΞ²
@[measurability] lemma measurable.subtype_coe {p : Ξ² β Prop} {f : Ξ± β subtype p}
(hf : measurable f) :
measurable (Ξ» a : Ξ±, (f a : Ξ²)) :=
measurable_subtype_coe.comp hf
@[measurability]
lemma measurable.subtype_mk {p : Ξ² β Prop} {f : Ξ± β Ξ²} (hf : measurable f) {h : β x, p (f x)} :
measurable (Ξ» x, (β¨f x, h xβ© : subtype p)) :=
Ξ» t β¨s, hsβ©, hs.2 βΈ by simp only [β preimage_comp, (β), subtype.coe_mk, hf hs.1]
lemma measurable_of_measurable_union_cover
{f : Ξ± β Ξ²} (s t : set Ξ±) (hs : measurable_set s) (ht : measurable_set t) (h : univ β s βͺ t)
(hc : measurable (Ξ» a : s, f a)) (hd : measurable (Ξ» a : t, f a)) :
measurable f :=
begin
intros u hu,
convert (hs.subtype_image (hc hu)).union (ht.subtype_image (hd hu)),
change f β»ΒΉ' u = coe '' (coe β»ΒΉ' (f β»ΒΉ' u) : set s) βͺ coe '' (coe β»ΒΉ' (f β»ΒΉ' u) : set t),
rw [image_preimage_eq_inter_range, image_preimage_eq_inter_range, subtype.range_coe,
subtype.range_coe, β inter_distrib_left, univ_subset_iff.1 h, inter_univ],
end
lemma measurable_of_restrict_of_restrict_compl {f : Ξ± β Ξ²} {s : set Ξ±}
(hs : measurable_set s) (hβ : measurable (s.restrict f)) (hβ : measurable (sαΆ.restrict f)) :
measurable f :=
measurable_of_measurable_union_cover s sαΆ hs hs.compl (union_compl_self s).ge hβ hβ
lemma measurable.dite [β x, decidable (x β s)] {f : s β Ξ²} (hf : measurable f)
{g : sαΆ β Ξ²} (hg : measurable g) (hs : measurable_set s) :
measurable (Ξ» x, if hx : x β s then f β¨x, hxβ© else g β¨x, hxβ©) :=
measurable_of_restrict_of_restrict_compl hs (by simpa) (by simpa)
lemma measurable_of_measurable_on_compl_finite [measurable_singleton_class Ξ±]
{f : Ξ± β Ξ²} (s : set Ξ±) (hs : s.finite) (hf : measurable (sαΆ.restrict f)) :
measurable f :=
begin
letI : fintype s := finite.fintype hs,
exact measurable_of_restrict_of_restrict_compl hs.measurable_set
(measurable_of_finite _) hf
end
lemma measurable_of_measurable_on_compl_singleton [measurable_singleton_class Ξ±]
{f : Ξ± β Ξ²} (a : Ξ±) (hf : measurable ({x | x β a}.restrict f)) :
measurable f :=
measurable_of_measurable_on_compl_finite {a} (finite_singleton a) hf
end subtype
section prod
/-- A `measurable_space` structure on the product of two measurable spaces. -/
def measurable_space.prod {Ξ± Ξ²} (mβ : measurable_space Ξ±) (mβ : measurable_space Ξ²) :
measurable_space (Ξ± Γ Ξ²) :=
mβ.comap prod.fst β mβ.comap prod.snd
instance {Ξ± Ξ²} [mβ : measurable_space Ξ±] [mβ : measurable_space Ξ²] : measurable_space (Ξ± Γ Ξ²) :=
mβ.prod mβ
@[measurability] lemma measurable_fst {ma : measurable_space Ξ±} {mb : measurable_space Ξ²} :
measurable (prod.fst : Ξ± Γ Ξ² β Ξ±) :=
measurable.of_comap_le le_sup_left
@[measurability] lemma measurable_snd {ma : measurable_space Ξ±} {mb : measurable_space Ξ²} :
measurable (prod.snd : Ξ± Γ Ξ² β Ξ²) :=
measurable.of_comap_le le_sup_right
variables {m : measurable_space Ξ±} {mΞ² : measurable_space Ξ²} {mΞ³ : measurable_space Ξ³}
include m mΞ² mΞ³
lemma measurable.fst {f : Ξ± β Ξ² Γ Ξ³} (hf : measurable f) :
measurable (Ξ» a : Ξ±, (f a).1) :=
measurable_fst.comp hf
lemma measurable.snd {f : Ξ± β Ξ² Γ Ξ³} (hf : measurable f) :
measurable (Ξ» a : Ξ±, (f a).2) :=
measurable_snd.comp hf
@[measurability] lemma measurable.prod {f : Ξ± β Ξ² Γ Ξ³}
(hfβ : measurable (Ξ» a, (f a).1)) (hfβ : measurable (Ξ» a, (f a).2)) : measurable f :=
measurable.of_le_map $ sup_le
(by { rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp], exact hfβ })
(by { rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp], exact hfβ })
lemma measurable.prod_mk {Ξ² Ξ³} {mΞ² : measurable_space Ξ²}
{mΞ³ : measurable_space Ξ³} {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} (hf : measurable f) (hg : measurable g) :
measurable (Ξ» a : Ξ±, (f a, g a)) :=
measurable.prod hf hg
lemma measurable.prod_map [measurable_space Ξ΄] {f : Ξ± β Ξ²} {g : Ξ³ β Ξ΄} (hf : measurable f)
(hg : measurable g) : measurable (prod.map f g) :=
(hf.comp measurable_fst).prod_mk (hg.comp measurable_snd)
omit mΞ³
lemma measurable_prod_mk_left {x : Ξ±} : measurable (@prod.mk _ Ξ² x) :=
measurable_const.prod_mk measurable_id
lemma measurable_prod_mk_right {y : Ξ²} : measurable (Ξ» x : Ξ±, (x, y)) :=
measurable_id.prod_mk measurable_const
include mΞ³
lemma measurable.of_uncurry_left {f : Ξ± β Ξ² β Ξ³} (hf : measurable (uncurry f)) {x : Ξ±} :
measurable (f x) :=
hf.comp measurable_prod_mk_left
lemma measurable.of_uncurry_right {f : Ξ± β Ξ² β Ξ³} (hf : measurable (uncurry f)) {y : Ξ²} :
measurable (Ξ» x, f x y) :=
hf.comp measurable_prod_mk_right
lemma measurable_prod {f : Ξ± β Ξ² Γ Ξ³} : measurable f β
measurable (Ξ» a, (f a).1) β§ measurable (Ξ» a, (f a).2) :=
β¨Ξ» hf, β¨measurable_fst.comp hf, measurable_snd.comp hfβ©, Ξ» h, measurable.prod h.1 h.2β©
omit mΞ³
@[measurability] lemma measurable_swap :
measurable (prod.swap : Ξ± Γ Ξ² β Ξ² Γ Ξ±) :=
measurable.prod measurable_snd measurable_fst
lemma measurable_swap_iff {mΞ³ : measurable_space Ξ³} {f : Ξ± Γ Ξ² β Ξ³} :
measurable (f β prod.swap) β measurable f :=
β¨Ξ» hf, by { convert hf.comp measurable_swap, ext β¨x, yβ©, refl }, Ξ» hf, hf.comp measurable_swapβ©
@[measurability]
lemma measurable_set.prod {s : set Ξ±} {t : set Ξ²} (hs : measurable_set s) (ht : measurable_set t) :
measurable_set (s ΓΛ’ t) :=
measurable_set.inter (measurable_fst hs) (measurable_snd ht)
lemma measurable_set_prod_of_nonempty {s : set Ξ±} {t : set Ξ²} (h : (s ΓΛ’ t).nonempty) :
measurable_set (s ΓΛ’ t) β measurable_set s β§ measurable_set t :=
begin
rcases h with β¨β¨x, yβ©, hx, hyβ©,
refine β¨Ξ» hst, _, Ξ» h, h.1.prod h.2β©,
have : measurable_set ((Ξ» x, (x, y)) β»ΒΉ' s ΓΛ’ t) := measurable_prod_mk_right hst,
have : measurable_set (prod.mk x β»ΒΉ' s ΓΛ’ t) := measurable_prod_mk_left hst,
simp * at *
end
lemma measurable_set_prod {s : set Ξ±} {t : set Ξ²} :
measurable_set (s ΓΛ’ t) β (measurable_set s β§ measurable_set t) β¨ s = β
β¨ t = β
:=
begin
cases (s ΓΛ’ t).eq_empty_or_nonempty with h h,
{ simp [h, prod_eq_empty_iff.mp h] },
{ simp [βnot_nonempty_iff_eq_empty, prod_nonempty_iff.mp h, measurable_set_prod_of_nonempty h] }
end
lemma measurable_set_swap_iff {s : set (Ξ± Γ Ξ²)} :
measurable_set (prod.swap β»ΒΉ' s) β measurable_set s :=
β¨Ξ» hs, by { convert measurable_swap hs, ext β¨x, yβ©, refl }, Ξ» hs, measurable_swap hsβ©
instance [measurable_singleton_class Ξ±] [measurable_singleton_class Ξ²] :
measurable_singleton_class (Ξ± Γ Ξ²) :=
β¨Ξ» β¨a, bβ©, @singleton_prod_singleton _ _ a b βΈ
(measurable_set_singleton a).prod (measurable_set_singleton b)β©
lemma measurable_from_prod_countable [countable Ξ²] [measurable_singleton_class Ξ²]
{mΞ³ : measurable_space Ξ³} {f : Ξ± Γ Ξ² β Ξ³} (hf : β y, measurable (Ξ» x, f (x, y))) :
measurable f :=
begin
intros s hs,
have : f β»ΒΉ' s = β y, ((Ξ» x, f (x, y)) β»ΒΉ' s) ΓΛ’ ({y} : set Ξ²),
{ ext1 β¨x, yβ©,
simp [and_assoc, and.left_comm] },
rw this,
exact measurable_set.Union (Ξ» y, (hf y hs).prod (measurable_set_singleton y))
end
/-- A piecewise function on countably many pieces is measurable if all the data is measurable. -/
@[measurability]
lemma measurable.find {m : measurable_space Ξ±}
{f : β β Ξ± β Ξ²} {p : β β Ξ± β Prop} [β n, decidable_pred (p n)]
(hf : β n, measurable (f n)) (hp : β n, measurable_set {x | p n x}) (h : β x, β n, p n x) :
measurable (Ξ» x, f (nat.find (h x)) x) :=
begin
have : measurable (Ξ» (p : Ξ± Γ β), f p.2 p.1) := measurable_from_prod_countable (Ξ» n, hf n),
exact this.comp (measurable.prod_mk measurable_id (measurable_find h hp)),
end
/-- Given countably many disjoint measurable sets `t n` and countably many measurable
functions `g n`, one can construct a measurable function that coincides with `g n` on `t n`. -/
lemma exists_measurable_piecewise_nat {m : measurable_space Ξ±} (t : β β set Ξ²)
(t_meas : β n, measurable_set (t n)) (t_disj : pairwise (disjoint on t))
(g : β β Ξ² β Ξ±) (hg : β n, measurable (g n)) :
β f : Ξ² β Ξ±, measurable f β§ (β n x, x β t n β f x = g n x) :=
begin
classical,
let p : β β Ξ² β Prop := Ξ» n x, x β t n βͺ (β k, t k)αΆ,
have M : β n, measurable_set {x | p n x} :=
Ξ» n, (t_meas n).union (measurable_set.compl (measurable_set.Union t_meas)),
have P : β x, β n, p n x,
{ assume x,
by_cases H : β (i : β), x β t i,
{ exact β¨0, or.inr (by simpa only [mem_Inter, compl_Union] using H)β© },
{ simp only [not_forall, not_not_mem] at H,
rcases H with β¨n, hnβ©,
exact β¨n, or.inl hnβ© } },
refine β¨Ξ» x, g (nat.find (P x)) x, measurable.find hg M P, _β©,
assume n x hx,
have : x β t (nat.find (P x)),
{ have B : x β t (nat.find (P x)) βͺ (β k, t k)αΆ := nat.find_spec (P x),
have B' : (β (i : β), x β t i) β false,
{ simp only [iff_false, not_forall, not_not_mem], exact β¨n, hxβ© },
simpa only [B', mem_union, mem_Inter, or_false, compl_Union, mem_compl_iff] using B },
congr,
by_contra h,
exact (t_disj (ne.symm h)).le_bot β¨hx, thisβ©
end
end prod
section pi
variables {Ο : Ξ΄ β Type*} [measurable_space Ξ±]
instance measurable_space.pi [m : Ξ a, measurable_space (Ο a)] : measurable_space (Ξ a, Ο a) :=
β¨ a, (m a).comap (Ξ» b, b a)
variables [Ξ a, measurable_space (Ο a)] [measurable_space Ξ³]
lemma measurable_pi_iff {g : Ξ± β Ξ a, Ο a} :
measurable g β β a, measurable (Ξ» x, g x a) :=
by simp_rw [measurable_iff_comap_le, measurable_space.pi, measurable_space.comap_supr,
measurable_space.comap_comp, function.comp, supr_le_iff]
@[measurability]
lemma measurable_pi_apply (a : Ξ΄) : measurable (Ξ» f : Ξ a, Ο a, f a) :=
measurable.of_comap_le $ le_supr _ a
@[measurability]
lemma measurable.eval {a : Ξ΄} {g : Ξ± β Ξ a, Ο a}
(hg : measurable g) : measurable (Ξ» x, g x a) :=
(measurable_pi_apply a).comp hg
@[measurability]
lemma measurable_pi_lambda (f : Ξ± β Ξ a, Ο a) (hf : β a, measurable (Ξ» c, f c a)) :
measurable f :=
measurable_pi_iff.mpr hf
/-- The function `update f a : Ο a β Ξ a, Ο a` is always measurable.
This doesn't require `f` to be measurable.
This should not be confused with the statement that `update f a x` is measurable. -/
@[measurability]
lemma measurable_update (f : Ξ (a : Ξ΄), Ο a) {a : Ξ΄} [decidable_eq Ξ΄] : measurable (update f a) :=
begin
apply measurable_pi_lambda,
intro x, by_cases hx : x = a,
{ cases hx, convert measurable_id, ext, simp },
simp_rw [update_noteq hx], apply measurable_const,
end
/- Even though we cannot use projection notation, we still keep a dot to be consistent with similar
lemmas, like `measurable_set.prod`. -/
@[measurability]
lemma measurable_set.pi {s : set Ξ΄} {t : Ξ i : Ξ΄, set (Ο i)} (hs : s.countable)
(ht : β i β s, measurable_set (t i)) :
measurable_set (s.pi t) :=
by { rw [pi_def], exact measurable_set.bInter hs (Ξ» i hi, measurable_pi_apply _ (ht i hi)) }
lemma measurable_set.univ_pi [countable Ξ΄] {t : Ξ i : Ξ΄, set (Ο i)}
(ht : β i, measurable_set (t i)) : measurable_set (pi univ t) :=
measurable_set.pi (to_countable _) (Ξ» i _, ht i)
lemma measurable_set_pi_of_nonempty
{s : set Ξ΄} {t : Ξ i, set (Ο i)} (hs : s.countable)
(h : (pi s t).nonempty) : measurable_set (pi s t) β β i β s, measurable_set (t i) :=
begin
classical,
rcases h with β¨f, hfβ©, refine β¨Ξ» hst i hi, _, measurable_set.pi hsβ©,
convert measurable_update f hst, rw [update_preimage_pi hi], exact Ξ» j hj _, hf j hj
end
lemma measurable_set_pi {s : set Ξ΄} {t : Ξ i, set (Ο i)} (hs : s.countable) :
measurable_set (pi s t) β (β i β s, measurable_set (t i)) β¨ pi s t = β
:=
begin
cases (pi s t).eq_empty_or_nonempty with h h,
{ simp [h] },
{ simp [measurable_set_pi_of_nonempty hs, h, β not_nonempty_iff_eq_empty] }
end
instance [countable Ξ΄] [Ξ a, measurable_singleton_class (Ο a)] :
measurable_singleton_class (Ξ a, Ο a) :=
β¨Ξ» f, univ_pi_singleton f βΈ measurable_set.univ_pi (Ξ» t, measurable_set_singleton (f t))β©
variable (Ο)
@[measurability]
lemma measurable_pi_equiv_pi_subtype_prod_symm (p : Ξ΄ β Prop) [decidable_pred p] :
measurable (equiv.pi_equiv_pi_subtype_prod p Ο).symm :=
begin
apply measurable_pi_iff.2 (Ξ» j, _),
by_cases hj : p j,
{ simp only [hj, dif_pos, equiv.pi_equiv_pi_subtype_prod_symm_apply],
have : measurable (Ξ» (f : (Ξ (i : {x // p x}), Ο βi)), f β¨j, hjβ©) :=
measurable_pi_apply β¨j, hjβ©,
exact measurable.comp this measurable_fst },
{ simp only [hj, equiv.pi_equiv_pi_subtype_prod_symm_apply, dif_neg, not_false_iff],
have : measurable (Ξ» (f : (Ξ (i : {x // Β¬ p x}), Ο βi)), f β¨j, hjβ©) :=
measurable_pi_apply β¨j, hjβ©,
exact measurable.comp this measurable_snd }
end
@[measurability]
lemma measurable_pi_equiv_pi_subtype_prod (p : Ξ΄ β Prop) [decidable_pred p] :
measurable (equiv.pi_equiv_pi_subtype_prod p Ο) :=
begin
refine measurable_prod.2 _,
split;
{ apply measurable_pi_iff.2 (Ξ» j, _),
simp only [pi_equiv_pi_subtype_prod_apply, measurable_pi_apply] }
end
end pi
instance tprod.measurable_space (Ο : Ξ΄ β Type*) [β x, measurable_space (Ο x)] :
β (l : list Ξ΄), measurable_space (list.tprod Ο l)
| [] := punit.measurable_space
| (i :: is) := @prod.measurable_space _ _ _ (tprod.measurable_space is)
section tprod
open list
variables {Ο : Ξ΄ β Type*} [β x, measurable_space (Ο x)]
lemma measurable_tprod_mk (l : list Ξ΄) : measurable (@tprod.mk Ξ΄ Ο l) :=
begin
induction l with i l ih,
{ exact measurable_const },
{ exact (measurable_pi_apply i).prod_mk ih }
end
lemma measurable_tprod_elim [decidable_eq Ξ΄] : β {l : list Ξ΄} {i : Ξ΄} (hi : i β l),
measurable (Ξ» (v : tprod Ο l), v.elim hi)
| (i :: is) j hj := begin
by_cases hji : j = i,
{ subst hji, simp [measurable_fst] },
{ rw [funext $ tprod.elim_of_ne _ hji],
exact (measurable_tprod_elim (hj.resolve_left hji)).comp measurable_snd }
end
lemma measurable_tprod_elim' [decidable_eq Ξ΄] {l : list Ξ΄} (h : β i, i β l) :
measurable (tprod.elim' h : tprod Ο l β Ξ i, Ο i) :=
measurable_pi_lambda _ (Ξ» i, measurable_tprod_elim (h i))
lemma measurable_set.tprod (l : list Ξ΄) {s : β i, set (Ο i)} (hs : β i, measurable_set (s i)) :
measurable_set (set.tprod l s) :=
by { induction l with i l ih, exact measurable_set.univ, exact (hs i).prod ih }
end tprod
instance {Ξ± Ξ²} [mβ : measurable_space Ξ±] [mβ : measurable_space Ξ²] : measurable_space (Ξ± β Ξ²) :=
mβ.map sum.inl β mβ.map sum.inr
section sum
@[measurability] lemma measurable_inl [measurable_space Ξ±] [measurable_space Ξ²] :
measurable (@sum.inl Ξ± Ξ²) :=
measurable.of_le_map inf_le_left
@[measurability] lemma measurable_inr [measurable_space Ξ±] [measurable_space Ξ²] :
measurable (@sum.inr Ξ± Ξ²) :=
measurable.of_le_map inf_le_right
variables {m : measurable_space Ξ±} {mΞ² : measurable_space Ξ²}
include m mΞ²
lemma measurable_sum {mΞ³ : measurable_space Ξ³} {f : Ξ± β Ξ² β Ξ³}
(hl : measurable (f β sum.inl)) (hr : measurable (f β sum.inr)) : measurable f :=
measurable.of_comap_le $ le_inf
(measurable_space.comap_le_iff_le_map.2 $ hl)
(measurable_space.comap_le_iff_le_map.2 $ hr)
@[measurability]
lemma measurable.sum_elim {mΞ³ : measurable_space Ξ³} {f : Ξ± β Ξ³} {g : Ξ² β Ξ³}
(hf : measurable f) (hg : measurable g) :
measurable (sum.elim f g) :=
measurable_sum hf hg
lemma measurable_set.inl_image {s : set Ξ±} (hs : measurable_set s) :
measurable_set (sum.inl '' s : set (Ξ± β Ξ²)) :=
β¨show measurable_set (sum.inl β»ΒΉ' _), by { rwa [preimage_image_eq], exact (Ξ» a b, sum.inl.inj) },
have sum.inr β»ΒΉ' (sum.inl '' s : set (Ξ± β Ξ²)) = β
:=
eq_empty_of_subset_empty $ assume x β¨y, hy, eqβ©, by contradiction,
show measurable_set (sum.inr β»ΒΉ' _), by { rw [this], exact measurable_set.empty }β©
lemma measurable_set_inr_image {s : set Ξ²} (hs : measurable_set s) :
measurable_set (sum.inr '' s : set (Ξ± β Ξ²)) :=
β¨ have sum.inl β»ΒΉ' (sum.inr '' s : set (Ξ± β Ξ²)) = β
:=
eq_empty_of_subset_empty $ assume x β¨y, hy, eqβ©, by contradiction,
show measurable_set (sum.inl β»ΒΉ' _), by { rw [this], exact measurable_set.empty },
show measurable_set (sum.inr β»ΒΉ' _), by { rwa [preimage_image_eq], exact Ξ» a b, sum.inr.inj }β©
omit m
lemma measurable_set_range_inl [measurable_space Ξ±] :
measurable_set (range sum.inl : set (Ξ± β Ξ²)) :=
by { rw [β image_univ], exact measurable_set.univ.inl_image }
lemma measurable_set_range_inr [measurable_space Ξ±] :
measurable_set (range sum.inr : set (Ξ± β Ξ²)) :=
by { rw [β image_univ], exact measurable_set_inr_image measurable_set.univ }
end sum
instance {Ξ±} {Ξ² : Ξ± β Type*} [m : Ξ a, measurable_space (Ξ² a)] : measurable_space (sigma Ξ²) :=
β¨
a, (m a).map (sigma.mk a)
end constructions
/-- A map `f : Ξ± β Ξ²` is called a *measurable embedding* if it is injective, measurable, and sends
measurable sets to measurable sets. The latter assumption can be replaced with β`f` has measurable
inverse `g : range f β Ξ±`β, see `measurable_embedding.measurable_range_splitting`,
`measurable_embedding.of_measurable_inverse_range`, and
`measurable_embedding.of_measurable_inverse`.
One more interpretation: `f` is a measurable embedding if it defines a measurable equivalence to its
range and the range is a measurable set. One implication is formalized as
`measurable_embedding.equiv_range`; the other one follows from
`measurable_equiv.measurable_embedding`, `measurable_embedding.subtype_coe`, and
`measurable_embedding.comp`. -/
@[protect_proj]
structure measurable_embedding {Ξ± Ξ² : Type*} [measurable_space Ξ±] [measurable_space Ξ²] (f : Ξ± β Ξ²) :
Prop :=
(injective : injective f)
(measurable : measurable f)
(measurable_set_image' : β β¦sβ¦, measurable_set s β measurable_set (f '' s))
namespace measurable_embedding
variables {mΞ± : measurable_space Ξ±} [measurable_space Ξ²] [measurable_space Ξ³]
{f : Ξ± β Ξ²} {g : Ξ² β Ξ³}
include mΞ±
lemma measurable_set_image (hf : measurable_embedding f) {s : set Ξ±} :
measurable_set (f '' s) β measurable_set s :=
β¨Ξ» h, by simpa only [hf.injective.preimage_image] using hf.measurable h,
Ξ» h, hf.measurable_set_image' hβ©
lemma id : measurable_embedding (id : Ξ± β Ξ±) :=
β¨injective_id, measurable_id, Ξ» s hs, by rwa image_idβ©
lemma comp (hg : measurable_embedding g) (hf : measurable_embedding f) :
measurable_embedding (g β f) :=
β¨hg.injective.comp hf.injective, hg.measurable.comp hf.measurable,
Ξ» s hs, by rwa [β image_image, hg.measurable_set_image, hf.measurable_set_image]β©
lemma subtype_coe {s : set Ξ±} (hs : measurable_set s) : measurable_embedding (coe : s β Ξ±) :=
{ injective := subtype.coe_injective,
measurable := measurable_subtype_coe,
measurable_set_image' := Ξ» _, measurable_set.subtype_image hs }
lemma measurable_set_range (hf : measurable_embedding f) : measurable_set (range f) :=
by { rw β image_univ, exact hf.measurable_set_image' measurable_set.univ }
lemma measurable_set_preimage (hf : measurable_embedding f) {s : set Ξ²} :
measurable_set (f β»ΒΉ' s) β measurable_set (s β© range f) :=
by rw [β image_preimage_eq_inter_range, hf.measurable_set_image]
lemma measurable_range_splitting (hf : measurable_embedding f) :
measurable (range_splitting f) :=
Ξ» s hs, by rwa [preimage_range_splitting hf.injective,
β (subtype_coe hf.measurable_set_range).measurable_set_image, β image_comp,
coe_comp_range_factorization, hf.measurable_set_image]
lemma measurable_extend (hf : measurable_embedding f) {g : Ξ± β Ξ³} {g' : Ξ² β Ξ³}
(hg : measurable g) (hg' : measurable g') :
measurable (extend f g g') :=
begin
refine measurable_of_restrict_of_restrict_compl hf.measurable_set_range _ _,
{ rw restrict_extend_range,
simpa only [range_splitting] using hg.comp hf.measurable_range_splitting },
{ rw restrict_extend_compl_range, exact hg'.comp measurable_subtype_coe }
end
lemma exists_measurable_extend (hf : measurable_embedding f) {g : Ξ± β Ξ³} (hg : measurable g)
(hne : Ξ² β nonempty Ξ³) :
β g' : Ξ² β Ξ³, measurable g' β§ g' β f = g :=
β¨extend f g (Ξ» x, classical.choice (hne x)),
hf.measurable_extend hg (measurable_const' $ Ξ» _ _, rfl),
funext $ Ξ» x, hf.injective.extend_apply _ _ _β©
lemma measurable_comp_iff (hg : measurable_embedding g) : measurable (g β f) β measurable f :=
begin
refine β¨Ξ» H, _, hg.measurable.compβ©,
suffices : measurable ((range_splitting g β range_factorization g) β f),
by rwa [(right_inverse_range_splitting hg.injective).comp_eq_id] at this,
exact hg.measurable_range_splitting.comp H.subtype_mk
end
end measurable_embedding
lemma measurable_set.exists_measurable_proj {m : measurable_space Ξ±} {s : set Ξ±}
(hs : measurable_set s) (hne : s.nonempty) : β f : Ξ± β s, measurable f β§ β x : s, f x = x :=
let β¨f, hfm, hfβ© := (measurable_embedding.subtype_coe hs).exists_measurable_extend
measurable_id (Ξ» _, hne.to_subtype)
in β¨f, hfm, congr_fun hfβ©
/-- Equivalences between measurable spaces. Main application is the simplification of measurability
statements along measurable equivalences. -/
structure measurable_equiv (Ξ± Ξ² : Type*) [measurable_space Ξ±] [measurable_space Ξ²] extends Ξ± β Ξ² :=
(measurable_to_fun : measurable to_equiv)
(measurable_inv_fun : measurable to_equiv.symm)
infix ` βα΅ `:25 := measurable_equiv
namespace measurable_equiv
variables (Ξ± Ξ²) [measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³] [measurable_space Ξ΄]
instance : has_coe_to_fun (Ξ± βα΅ Ξ²) (Ξ» _, Ξ± β Ξ²) := β¨Ξ» e, e.to_funβ©
variables {Ξ± Ξ²}
@[simp] lemma coe_to_equiv (e : Ξ± βα΅ Ξ²) : (e.to_equiv : Ξ± β Ξ²) = e := rfl
@[measurability]
protected lemma measurable (e : Ξ± βα΅ Ξ²) : measurable (e : Ξ± β Ξ²) :=
e.measurable_to_fun
@[simp] lemma coe_mk (e : Ξ± β Ξ²) (h1 : measurable e) (h2 : measurable e.symm) :
((β¨e, h1, h2β© : Ξ± βα΅ Ξ²) : Ξ± β Ξ²) = e := rfl
/-- Any measurable space is equivalent to itself. -/
def refl (Ξ± : Type*) [measurable_space Ξ±] : Ξ± βα΅ Ξ± :=
{ to_equiv := equiv.refl Ξ±,
measurable_to_fun := measurable_id, measurable_inv_fun := measurable_id }
instance : inhabited (Ξ± βα΅ Ξ±) := β¨refl Ξ±β©
/-- The composition of equivalences between measurable spaces. -/
def trans (ab : Ξ± βα΅ Ξ²) (bc : Ξ² βα΅ Ξ³) :
Ξ± βα΅ Ξ³ :=
{ to_equiv := ab.to_equiv.trans bc.to_equiv,
measurable_to_fun := bc.measurable_to_fun.comp ab.measurable_to_fun,
measurable_inv_fun := ab.measurable_inv_fun.comp bc.measurable_inv_fun }
/-- The inverse of an equivalence between measurable spaces. -/
def symm (ab : Ξ± βα΅ Ξ²) : Ξ² βα΅ Ξ± :=
{ to_equiv := ab.to_equiv.symm,
measurable_to_fun := ab.measurable_inv_fun,
measurable_inv_fun := ab.measurable_to_fun }
@[simp] lemma coe_to_equiv_symm (e : Ξ± βα΅ Ξ²) : (e.to_equiv.symm : Ξ² β Ξ±) = e.symm := rfl
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : Ξ± βα΅ Ξ²) : Ξ± β Ξ² := h
/-- See Note [custom simps projection] -/
def simps.symm_apply (h : Ξ± βα΅ Ξ²) : Ξ² β Ξ± := h.symm
initialize_simps_projections measurable_equiv
(to_equiv_to_fun β apply, to_equiv_inv_fun β symm_apply)
lemma to_equiv_injective : injective (to_equiv : (Ξ± βα΅ Ξ²) β (Ξ± β Ξ²)) :=
by { rintro β¨eβ, _, _β© β¨eβ, _, _β© (rfl : eβ = eβ), refl }
@[ext] lemma ext {eβ eβ : Ξ± βα΅ Ξ²} (h : (eβ : Ξ± β Ξ²) = eβ) : eβ = eβ :=
to_equiv_injective $ equiv.coe_fn_injective h
@[simp] lemma symm_mk (e : Ξ± β Ξ²) (h1 : measurable e) (h2 : measurable e.symm) :
(β¨e, h1, h2β© : Ξ± βα΅ Ξ²).symm = β¨e.symm, h2, h1β© := rfl
attribute [simps apply to_equiv] trans refl
@[simp] lemma symm_refl (Ξ± : Type*) [measurable_space Ξ±] : (refl Ξ±).symm = refl Ξ± := rfl
@[simp] theorem symm_comp_self (e : Ξ± βα΅ Ξ²) : e.symm β e = id := funext e.left_inv
@[simp] theorem self_comp_symm (e : Ξ± βα΅ Ξ²) : e β e.symm = id := funext e.right_inv
@[simp] theorem apply_symm_apply (e : Ξ± βα΅ Ξ²) (y : Ξ²) : e (e.symm y) = y := e.right_inv y
@[simp] theorem symm_apply_apply (e : Ξ± βα΅ Ξ²) (x : Ξ±) : e.symm (e x) = x := e.left_inv x
@[simp] theorem symm_trans_self (e : Ξ± βα΅ Ξ²) : e.symm.trans e = refl Ξ² :=
ext e.self_comp_symm
@[simp] theorem self_trans_symm (e : Ξ± βα΅ Ξ²) : e.trans e.symm = refl Ξ± :=
ext e.symm_comp_self
protected theorem surjective (e : Ξ± βα΅ Ξ²) : surjective e := e.to_equiv.surjective
protected theorem bijective (e : Ξ± βα΅ Ξ²) : bijective e := e.to_equiv.bijective
protected theorem injective (e : Ξ± βα΅ Ξ²) : injective e := e.to_equiv.injective
@[simp] theorem symm_preimage_preimage (e : Ξ± βα΅ Ξ²) (s : set Ξ²) : e.symm β»ΒΉ' (e β»ΒΉ' s) = s :=
e.to_equiv.symm_preimage_preimage s
theorem image_eq_preimage (e : Ξ± βα΅ Ξ²) (s : set Ξ±) : e '' s = e.symm β»ΒΉ' s :=
e.to_equiv.image_eq_preimage s
@[simp] theorem measurable_set_preimage (e : Ξ± βα΅ Ξ²) {s : set Ξ²} :
measurable_set (e β»ΒΉ' s) β measurable_set s :=
β¨Ξ» h, by simpa only [symm_preimage_preimage] using e.symm.measurable h, Ξ» h, e.measurable hβ©
@[simp] theorem measurable_set_image (e : Ξ± βα΅ Ξ²) {s : set Ξ±} :
measurable_set (e '' s) β measurable_set s :=
by rw [image_eq_preimage, measurable_set_preimage]
/-- A measurable equivalence is a measurable embedding. -/
protected lemma measurable_embedding (e : Ξ± βα΅ Ξ²) : measurable_embedding e :=
{ injective := e.injective,
measurable := e.measurable,
measurable_set_image' := Ξ» s, e.measurable_set_image.2 }
/-- Equal measurable spaces are equivalent. -/
protected def cast {Ξ± Ξ²} [iβ : measurable_space Ξ±] [iβ : measurable_space Ξ²]
(h : Ξ± = Ξ²) (hi : iβ == iβ) : Ξ± βα΅ Ξ² :=
{ to_equiv := equiv.cast h,
measurable_to_fun := by { substI h, substI hi, exact measurable_id },
measurable_inv_fun := by { substI h, substI hi, exact measurable_id }}
protected lemma measurable_comp_iff {f : Ξ² β Ξ³} (e : Ξ± βα΅ Ξ²) :
measurable (f β e) β measurable f :=
iff.intro
(assume hfe,
have measurable (f β (e.symm.trans e).to_equiv) := hfe.comp e.symm.measurable,
by rwa [coe_to_equiv, symm_trans_self] at this)
(Ξ» h, h.comp e.measurable)
/-- Any two types with unique elements are measurably equivalent. -/
def of_unique_of_unique (Ξ± Ξ² : Type*) [measurable_space Ξ±] [measurable_space Ξ²]
[unique Ξ±] [unique Ξ²] : Ξ± βα΅ Ξ² :=
{ to_equiv := equiv_of_unique Ξ± Ξ²,
measurable_to_fun := subsingleton.measurable,
measurable_inv_fun := subsingleton.measurable }
/-- Products of equivalent measurable spaces are equivalent. -/
def prod_congr (ab : Ξ± βα΅ Ξ²) (cd : Ξ³ βα΅ Ξ΄) : Ξ± Γ Ξ³ βα΅ Ξ² Γ Ξ΄ :=
{ to_equiv := prod_congr ab.to_equiv cd.to_equiv,
measurable_to_fun := (ab.measurable_to_fun.comp measurable_id.fst).prod_mk
(cd.measurable_to_fun.comp measurable_id.snd),
measurable_inv_fun := (ab.measurable_inv_fun.comp measurable_id.fst).prod_mk
(cd.measurable_inv_fun.comp measurable_id.snd) }
/-- Products of measurable spaces are symmetric. -/
def prod_comm : Ξ± Γ Ξ² βα΅ Ξ² Γ Ξ± :=
{ to_equiv := prod_comm Ξ± Ξ²,
measurable_to_fun := measurable_id.snd.prod_mk measurable_id.fst,
measurable_inv_fun := measurable_id.snd.prod_mk measurable_id.fst }
/-- Products of measurable spaces are associative. -/
def prod_assoc : (Ξ± Γ Ξ²) Γ Ξ³ βα΅ Ξ± Γ (Ξ² Γ Ξ³) :=
{ to_equiv := prod_assoc Ξ± Ξ² Ξ³,
measurable_to_fun := measurable_fst.fst.prod_mk $ measurable_fst.snd.prod_mk measurable_snd,
measurable_inv_fun := (measurable_fst.prod_mk measurable_snd.fst).prod_mk measurable_snd.snd }
/-- Sums of measurable spaces are symmetric. -/
def sum_congr (ab : Ξ± βα΅ Ξ²) (cd : Ξ³ βα΅ Ξ΄) : Ξ± β Ξ³ βα΅ Ξ² β Ξ΄ :=
{ to_equiv := sum_congr ab.to_equiv cd.to_equiv,
measurable_to_fun :=
begin
cases ab with ab' abm, cases ab', cases cd with cd' cdm, cases cd',
refine measurable_sum (measurable_inl.comp abm) (measurable_inr.comp cdm)
end,
measurable_inv_fun :=
begin
cases ab with ab' _ abm, cases ab', cases cd with cd' _ cdm, cases cd',
refine measurable_sum (measurable_inl.comp abm) (measurable_inr.comp cdm)
end }
/-- `s ΓΛ’ t β (s Γ t)` as measurable spaces. -/
def set.prod (s : set Ξ±) (t : set Ξ²) : β₯(s ΓΛ’ t) βα΅ s Γ t :=
{ to_equiv := equiv.set.prod s t,
measurable_to_fun := measurable_id.subtype_coe.fst.subtype_mk.prod_mk
measurable_id.subtype_coe.snd.subtype_mk,
measurable_inv_fun := measurable.subtype_mk $ measurable_id.fst.subtype_coe.prod_mk
measurable_id.snd.subtype_coe }
/-- `univ Ξ± β Ξ±` as measurable spaces. -/
def set.univ (Ξ± : Type*) [measurable_space Ξ±] : (univ : set Ξ±) βα΅ Ξ± :=
{ to_equiv := equiv.set.univ Ξ±,
measurable_to_fun := measurable_id.subtype_coe,
measurable_inv_fun := measurable_id.subtype_mk }
/-- `{a} β unit` as measurable spaces. -/
def set.singleton (a : Ξ±) : ({a} : set Ξ±) βα΅ unit :=
{ to_equiv := equiv.set.singleton a,
measurable_to_fun := measurable_const,
measurable_inv_fun := measurable_const }
/-- `Ξ±` is equivalent to its image in `Ξ± β Ξ²` as measurable spaces. -/
def set.range_inl : (range sum.inl : set (Ξ± β Ξ²)) βα΅ Ξ± :=
{ to_fun := Ξ» ab, match ab with
| β¨sum.inl a, _β© := a
| β¨sum.inr b, pβ© := have false, by { cases p, contradiction }, this.elim
end,
inv_fun := Ξ» a, β¨sum.inl a, a, rflβ©,
left_inv := by { rintro β¨ab, a, rflβ©, refl },
right_inv := assume a, rfl,
measurable_to_fun := assume s (hs : measurable_set s),
begin
refine β¨_, hs.inl_image, set.ext _β©,
rintros β¨ab, a, rflβ©,
simp [set.range_inl._match_1]
end,
measurable_inv_fun := measurable.subtype_mk measurable_inl }
/-- `Ξ²` is equivalent to its image in `Ξ± β Ξ²` as measurable spaces. -/
def set.range_inr : (range sum.inr : set (Ξ± β Ξ²)) βα΅ Ξ² :=
{ to_fun := Ξ» ab, match ab with
| β¨sum.inr b, _β© := b
| β¨sum.inl a, pβ© := have false, by { cases p, contradiction }, this.elim
end,
inv_fun := Ξ» b, β¨sum.inr b, b, rflβ©,
left_inv := by { rintro β¨ab, b, rflβ©, refl },
right_inv := assume b, rfl,
measurable_to_fun := assume s (hs : measurable_set s),
begin
refine β¨_, measurable_set_inr_image hs, set.ext _β©,
rintros β¨ab, b, rflβ©,
simp [set.range_inr._match_1]
end,
measurable_inv_fun := measurable.subtype_mk measurable_inr }
/-- Products distribute over sums (on the right) as measurable spaces. -/
def sum_prod_distrib (Ξ± Ξ² Ξ³) [measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³] :
(Ξ± β Ξ²) Γ Ξ³ βα΅ (Ξ± Γ Ξ³) β (Ξ² Γ Ξ³) :=
{ to_equiv := sum_prod_distrib Ξ± Ξ² Ξ³,
measurable_to_fun :=
begin
refine measurable_of_measurable_union_cover
(range sum.inl ΓΛ’ (univ : set Ξ³))
(range sum.inr ΓΛ’ (univ : set Ξ³))
(measurable_set_range_inl.prod measurable_set.univ)
(measurable_set_range_inr.prod measurable_set.univ)
(by { rintro β¨a|b, cβ©; simp [set.prod_eq] })
_
_,
{ refine (set.prod (range sum.inl) univ).symm.measurable_comp_iff.1 _,
refine (prod_congr set.range_inl (set.univ _)).symm.measurable_comp_iff.1 _,
dsimp [(β)],
convert measurable_inl,
ext β¨a, cβ©, refl },
{ refine (set.prod (range sum.inr) univ).symm.measurable_comp_iff.1 _,
refine (prod_congr set.range_inr (set.univ _)).symm.measurable_comp_iff.1 _,
dsimp [(β)],
convert measurable_inr,
ext β¨b, cβ©, refl }
end,
measurable_inv_fun :=
measurable_sum
((measurable_inl.comp measurable_fst).prod_mk measurable_snd)
((measurable_inr.comp measurable_fst).prod_mk measurable_snd) }
/-- Products distribute over sums (on the left) as measurable spaces. -/
def prod_sum_distrib (Ξ± Ξ² Ξ³) [measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³] :
Ξ± Γ (Ξ² β Ξ³) βα΅ (Ξ± Γ Ξ²) β (Ξ± Γ Ξ³) :=
prod_comm.trans $ (sum_prod_distrib _ _ _).trans $ sum_congr prod_comm prod_comm
/-- Products distribute over sums as measurable spaces. -/
def sum_prod_sum (Ξ± Ξ² Ξ³ Ξ΄)
[measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³] [measurable_space Ξ΄] :
(Ξ± β Ξ²) Γ (Ξ³ β Ξ΄) βα΅ ((Ξ± Γ Ξ³) β (Ξ± Γ Ξ΄)) β ((Ξ² Γ Ξ³) β (Ξ² Γ Ξ΄)) :=
(sum_prod_distrib _ _ _).trans $ sum_congr (prod_sum_distrib _ _ _) (prod_sum_distrib _ _ _)
variables {Ο Ο' : Ξ΄' β Type*} [β x, measurable_space (Ο x)] [β x, measurable_space (Ο' x)]
/-- A family of measurable equivalences `Ξ a, Ξ²β a βα΅ Ξ²β a` generates a measurable equivalence
between `Ξ a, Ξ²β a` and `Ξ a, Ξ²β a`. -/
def Pi_congr_right (e : Ξ a, Ο a βα΅ Ο' a) : (Ξ a, Ο a) βα΅ (Ξ a, Ο' a) :=
{ to_equiv := Pi_congr_right (Ξ» a, (e a).to_equiv),
measurable_to_fun :=
measurable_pi_lambda _ (Ξ» i, (e i).measurable_to_fun.comp (measurable_pi_apply i)),
measurable_inv_fun :=
measurable_pi_lambda _ (Ξ» i, (e i).measurable_inv_fun.comp (measurable_pi_apply i)) }
/-- Pi-types are measurably equivalent to iterated products. -/
@[simps {fully_applied := ff}]
def pi_measurable_equiv_tprod [decidable_eq Ξ΄']
{l : list Ξ΄'} (hnd : l.nodup) (h : β i, i β l) :
(Ξ i, Ο i) βα΅ list.tprod Ο l :=
{ to_equiv := list.tprod.pi_equiv_tprod hnd h,
measurable_to_fun := measurable_tprod_mk l,
measurable_inv_fun := measurable_tprod_elim' h }
/-- If `Ξ±` has a unique term, then the type of function `Ξ± β Ξ²` is measurably equivalent to `Ξ²`. -/
@[simps {fully_applied := ff}] def fun_unique (Ξ± Ξ² : Type*) [unique Ξ±] [measurable_space Ξ²] :
(Ξ± β Ξ²) βα΅ Ξ² :=
{ to_equiv := equiv.fun_unique Ξ± Ξ²,
measurable_to_fun := measurable_pi_apply _,
measurable_inv_fun := measurable_pi_iff.2 $ Ξ» b, measurable_id }
/-- The space `Ξ i : fin 2, Ξ± i` is measurably equivalent to `Ξ± 0 Γ Ξ± 1`. -/
@[simps {fully_applied := ff}] def pi_fin_two (Ξ± : fin 2 β Type*) [β i, measurable_space (Ξ± i)] :
(Ξ i, Ξ± i) βα΅ Ξ± 0 Γ Ξ± 1 :=
{ to_equiv := pi_fin_two_equiv Ξ±,
measurable_to_fun := measurable.prod (measurable_pi_apply _) (measurable_pi_apply _),
measurable_inv_fun := measurable_pi_iff.2 $
fin.forall_fin_two.2 β¨measurable_fst, measurable_sndβ© }
/-- The space `fin 2 β Ξ±` is measurably equivalent to `Ξ± Γ Ξ±`. -/
@[simps {fully_applied := ff}] def fin_two_arrow : (fin 2 β Ξ±) βα΅ Ξ± Γ Ξ± := pi_fin_two (Ξ» _, Ξ±)
/-- Measurable equivalence between `Ξ j : fin (n + 1), Ξ± j` and
`Ξ± i Γ Ξ j : fin n, Ξ± (fin.succ_above i j)`. -/
@[simps {fully_applied := ff}]
def pi_fin_succ_above_equiv {n : β} (Ξ± : fin (n + 1) β Type*) [Ξ i, measurable_space (Ξ± i)]
(i : fin (n + 1)) :
(Ξ j, Ξ± j) βα΅ Ξ± i Γ (Ξ j, Ξ± (i.succ_above j)) :=
{ to_equiv := pi_fin_succ_above_equiv Ξ± i,
measurable_to_fun := (measurable_pi_apply i).prod_mk $ measurable_pi_iff.2 $
Ξ» j, measurable_pi_apply _,
measurable_inv_fun := by simp [measurable_pi_iff, i.forall_iff_succ_above, measurable_fst,
(measurable_pi_apply _).comp measurable_snd] }
variable (Ο)
/-- Measurable equivalence between (dependent) functions on a type and pairs of functions on
`{i // p i}` and `{i // Β¬p i}`. See also `equiv.pi_equiv_pi_subtype_prod`. -/
@[simps {fully_applied := ff}]
def pi_equiv_pi_subtype_prod (p : Ξ΄' β Prop) [decidable_pred p] :
(Ξ i, Ο i) βα΅ ((Ξ i : subtype p, Ο i) Γ (Ξ i : {i // Β¬p i}, Ο i)) :=
{ to_equiv := pi_equiv_pi_subtype_prod p Ο,
measurable_to_fun := measurable_pi_equiv_pi_subtype_prod Ο p,
measurable_inv_fun := measurable_pi_equiv_pi_subtype_prod_symm Ο p }
/-- If `s` is a measurable set in a measurable space, that space is equivalent
to the sum of `s` and `sαΆ`.-/
def sum_compl {s : set Ξ±} [decidable_pred s] (hs : measurable_set s) : s β (sαΆ : set Ξ±) βα΅ Ξ± :=
{ to_equiv := sum_compl s,
measurable_to_fun := by {apply measurable.sum_elim; exact measurable_subtype_coe},
measurable_inv_fun := measurable.dite measurable_inl measurable_inr hs }
end measurable_equiv
namespace measurable_embedding
variables [measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³] {f : Ξ± β Ξ²} {g : Ξ² β Ξ±}
/-- A set is equivalent to its image under a function `f` as measurable spaces,
if `f` is a measurable embedding -/
noncomputable def equiv_image (s : set Ξ±) (hf : measurable_embedding f) :
s βα΅ (f '' s) :=
{ to_equiv := equiv.set.image f s hf.injective,
measurable_to_fun := (hf.measurable.comp measurable_id.subtype_coe).subtype_mk,
measurable_inv_fun :=
begin
rintro t β¨u, hu, rflβ©, simp [preimage_preimage, set.image_symm_preimage hf.injective],
exact measurable_subtype_coe (hf.measurable_set_image' hu)
end }
/-- The domain of `f` is equivalent to its range as measurable spaces,
if `f` is a measurable embedding -/
noncomputable def equiv_range (hf : measurable_embedding f) : Ξ± βα΅ (range f) :=
(measurable_equiv.set.univ _).symm.trans $
(hf.equiv_image univ).trans $
measurable_equiv.cast (by rw image_univ) (by rw image_univ)
lemma of_measurable_inverse_on_range {g : range f β Ξ±} (hfβ : measurable f)
(hfβ : measurable_set (range f)) (hg : measurable g)
(H : left_inverse g (range_factorization f)) : measurable_embedding f :=
begin
set e : Ξ± βα΅ range f :=
β¨β¨range_factorization f, g, H, H.right_inverse_of_surjective surjective_onto_rangeβ©,
hfβ.subtype_mk, hgβ©,
exact (measurable_embedding.subtype_coe hfβ).comp e.measurable_embedding
end
lemma of_measurable_inverse (hfβ : measurable f)
(hfβ : measurable_set (range f)) (hg : measurable g)
(H : left_inverse g f) : measurable_embedding f :=
of_measurable_inverse_on_range hfβ hfβ (hg.comp measurable_subtype_coe) H
open_locale classical
/-- The **`measurable SchrΓΆder-Bernstein Theorem**: Given measurable embeddings
`Ξ± β Ξ²` and `Ξ² β Ξ±`, we can find a measurable equivalence `Ξ± βα΅ Ξ²`.-/
noncomputable
def schroeder_bernstein {f : Ξ± β Ξ²} {g : Ξ² β Ξ±}
(hf : measurable_embedding f)(hg : measurable_embedding g) : Ξ± βα΅ Ξ² :=
begin
let F : set Ξ± β set Ξ± := Ξ» A, (g '' (f '' A)αΆ)αΆ,
-- We follow the proof of the usual SB theorem in mathlib,
-- the crux of which is finding a fixed point of this F.
-- However, we must find this fixed point manually instead of invoking Knaster-Tarski
-- in order to make sure it is measurable.
suffices : Ξ£' A : set Ξ±, measurable_set A β§ F A = A,
{ rcases this with β¨A, Ameas, Afpβ©,
let B := f '' A,
have Bmeas : measurable_set B := hf.measurable_set_image' Ameas,
refine (measurable_equiv.sum_compl Ameas).symm.trans
(measurable_equiv.trans _ (measurable_equiv.sum_compl Bmeas)),
apply measurable_equiv.sum_congr (hf.equiv_image _),
have : AαΆ = g '' BαΆ,
{ apply compl_injective,
rw β Afp,
simp, },
rw this,
exact (hg.equiv_image _).symm, },
have Fmono : β {A B}, A β B β F A β F B := Ξ» A B hAB,
compl_subset_compl.mpr $ set.image_subset _ $
compl_subset_compl.mpr $ set.image_subset _ hAB,
let X : β β set Ξ± := Ξ» n, F^[n] univ,
refine β¨Inter X, _, _β©,
{ apply measurable_set.Inter,
intros n,
induction n with n ih,
{ exact measurable_set.univ },
rw [function.iterate_succ', function.comp_apply],
exact (hg.measurable_set_image' (hf.measurable_set_image' ih).compl).compl, },
apply subset_antisymm,
{ apply subset_Inter,
intros n,
cases n,
{ exact subset_univ _ },
rw [function.iterate_succ', function.comp_apply],
exact Fmono (Inter_subset _ _ ), },
rintros x hx β¨y, hy, rflβ©,
rw mem_Inter at hx,
apply hy,
rw (inj_on_of_injective hf.injective _).image_Inter_eq,
swap, { apply_instance },
rw mem_Inter,
intro n,
specialize hx n.succ,
rw [function.iterate_succ', function.comp_apply] at hx,
by_contradiction h,
apply hx,
exact β¨y, h, rflβ©,
end
end measurable_embedding
section countably_generated
namespace measurable_space
variable (Ξ±)
/-- We say a measurable space is countably generated
if can be generated by a countable set of sets.-/
class countably_generated [m : measurable_space Ξ±] : Prop :=
(is_countably_generated : β b : set (set Ξ±), b.countable β§ m = generate_from b)
open_locale classical
/-- If a measurable space is countably generated, it admits a measurable injection
into the Cantor space `β β bool` (equipped with the product sigma algebra). -/
theorem measurable_injection_nat_bool_of_countably_generated
[measurable_space Ξ±] [h : countably_generated Ξ±] [measurable_singleton_class Ξ±] :
β f : Ξ± β (β β bool), measurable f β§ function.injective f :=
begin
obtain β¨b, bct, hbβ© := h.is_countably_generated,
obtain β¨e, heβ© := set.countable.exists_eq_range (bct.insert β
) (insert_nonempty _ _),
rw [β generate_from_insert_empty, he] at hb,
refine β¨Ξ» x n, to_bool (x β e n), _, _β©,
{ rw measurable_pi_iff,
intro n,
apply measurable_to_bool,
simp only [preimage, mem_singleton_iff, to_bool_iff, set_of_mem_eq],
rw hb,
apply measurable_set_generate_from,
use n, },
intros x y hxy,
have : β s : set Ξ±, measurable_set s β (x β s β y β s) := Ξ» s, by
{ rw hb,
apply generate_from_induction,
{ rintros - β¨n, rflβ©,
rw β bool.to_bool_eq,
rw funext_iff at hxy,
exact hxy n },
{ tauto },
{ intro t,
tauto },
intros t ht,
simp_rw [mem_Union, ht], },
specialize this {y} measurable_set_eq,
simpa only [mem_singleton, iff_true],
end
end measurable_space
end countably_generated
namespace filter
variables [measurable_space Ξ±]
/-- A filter `f` is measurably generates if each `s β f` includes a measurable `t β f`. -/
class is_measurably_generated (f : filter Ξ±) : Prop :=
(exists_measurable_subset : β β¦sβ¦, s β f β β t β f, measurable_set t β§ t β s)
instance is_measurably_generated_bot : is_measurably_generated (β₯ : filter Ξ±) :=
β¨Ξ» _ _, β¨β
, mem_bot, measurable_set.empty, empty_subset _β©β©
instance is_measurably_generated_top : is_measurably_generated (β€ : filter Ξ±) :=
β¨Ξ» s hs, β¨univ, univ_mem, measurable_set.univ, Ξ» x _, hs xβ©β©
lemma eventually.exists_measurable_mem {f : filter Ξ±} [is_measurably_generated f]
{p : Ξ± β Prop} (h : βαΆ x in f, p x) :
β s β f, measurable_set s β§ β x β s, p x :=
is_measurably_generated.exists_measurable_subset h
lemma eventually.exists_measurable_mem_of_small_sets {f : filter Ξ±} [is_measurably_generated f]
{p : set Ξ± β Prop} (h : βαΆ s in f.small_sets, p s) :
β s β f, measurable_set s β§ p s :=
let β¨s, hsf, hsβ© := eventually_small_sets.1 h,
β¨t, htf, htm, htsβ© := is_measurably_generated.exists_measurable_subset hsf
in β¨t, htf, htm, hs t htsβ©
instance inf_is_measurably_generated (f g : filter Ξ±) [is_measurably_generated f]
[is_measurably_generated g] :
is_measurably_generated (f β g) :=
begin
refine β¨_β©,
rintros t β¨sf, hsf, sg, hsg, rflβ©,
rcases is_measurably_generated.exists_measurable_subset hsf with β¨s'f, hs'f, hmf, hs'sfβ©,
rcases is_measurably_generated.exists_measurable_subset hsg with β¨s'g, hs'g, hmg, hs'sgβ©,
refine β¨s'f β© s'g, inter_mem_inf hs'f hs'g, hmf.inter hmg, _β©,
exact inter_subset_inter hs'sf hs'sg
end
lemma principal_is_measurably_generated_iff {s : set Ξ±} :
is_measurably_generated (π s) β measurable_set s :=
begin
refine β¨_, Ξ» hs, β¨Ξ» t ht, β¨s, mem_principal_self s, hs, htβ©β©β©,
rintros β¨hsβ©,
rcases hs (mem_principal_self s) with β¨t, ht, htm, htsβ©,
have : t = s := subset.antisymm hts ht,
rwa β this
end
alias principal_is_measurably_generated_iff β
_ _root_.measurable_set.principal_is_measurably_generated
instance infi_is_measurably_generated {f : ΞΉ β filter Ξ±} [β i, is_measurably_generated (f i)] :
is_measurably_generated (β¨
i, f i) :=
begin
refine β¨Ξ» s hs, _β©,
rw [β equiv.plift.surjective.infi_comp, mem_infi] at hs,
rcases hs with β¨t, ht, β¨V, hVf, rflβ©β©,
choose U hUf hU using Ξ» i, is_measurably_generated.exists_measurable_subset (hVf i),
refine β¨β i : t, U i, _, _, _β©,
{ rw [β equiv.plift.surjective.infi_comp, mem_infi],
refine β¨t, ht, U, hUf, rflβ© },
{ haveI := ht.countable.to_encodable,
exact measurable_set.Inter (Ξ» i, (hU i).1) },
{ exact Inter_mono (Ξ» i, (hU i).2) }
end
end filter
/-- We say that a collection of sets is countably spanning if a countable subset spans the
whole type. This is a useful condition in various parts of measure theory. For example, it is
a needed condition to show that the product of two collections generate the product sigma algebra,
see `generate_from_prod_eq`. -/
def is_countably_spanning (C : set (set Ξ±)) : Prop :=
β (s : β β set Ξ±), (β n, s n β C) β§ (β n, s n) = univ
lemma is_countably_spanning_measurable_set [measurable_space Ξ±] :
is_countably_spanning {s : set Ξ± | measurable_set s} :=
β¨Ξ» _, univ, Ξ» _, measurable_set.univ, Union_const _β©
namespace measurable_set
/-!
### Typeclasses on `subtype measurable_set`
-/
variables [measurable_space Ξ±]
instance : has_mem Ξ± (subtype (measurable_set : set Ξ± β Prop)) :=
β¨Ξ» a s, a β (s : set Ξ±)β©
@[simp] lemma mem_coe (a : Ξ±) (s : subtype (measurable_set : set Ξ± β Prop)) :
a β (s : set Ξ±) β a β s := iff.rfl
instance : has_emptyc (subtype (measurable_set : set Ξ± β Prop)) :=
β¨β¨β
, measurable_set.emptyβ©β©
@[simp] lemma coe_empty : β(β
: subtype (measurable_set : set Ξ± β Prop)) = (β
: set Ξ±) := rfl
instance [measurable_singleton_class Ξ±] : has_insert Ξ± (subtype (measurable_set : set Ξ± β Prop)) :=
β¨Ξ» a s, β¨has_insert.insert a s, s.prop.insert aβ©β©
@[simp] lemma coe_insert [measurable_singleton_class Ξ±] (a : Ξ±)
(s : subtype (measurable_set : set Ξ± β Prop)) :
β(has_insert.insert a s) = (has_insert.insert a s : set Ξ±) := rfl
instance : has_compl (subtype (measurable_set : set Ξ± β Prop)) :=
β¨Ξ» x, β¨xαΆ, x.prop.complβ©β©
@[simp] lemma coe_compl (s : subtype (measurable_set : set Ξ± β Prop)) : β(sαΆ) = (sαΆ : set Ξ±) := rfl
instance : has_union (subtype (measurable_set : set Ξ± β Prop)) :=
β¨Ξ» x y, β¨x βͺ y, x.prop.union y.propβ©β©
@[simp] lemma coe_union (s t : subtype (measurable_set : set Ξ± β Prop)) :
β(s βͺ t) = (s βͺ t : set Ξ±) := rfl
instance : has_inter (subtype (measurable_set : set Ξ± β Prop)) :=
β¨Ξ» x y, β¨x β© y, x.prop.inter y.propβ©β©
@[simp] lemma coe_inter (s t : subtype (measurable_set : set Ξ± β Prop)) :
β(s β© t) = (s β© t : set Ξ±) := rfl
instance : has_sdiff (subtype (measurable_set : set Ξ± β Prop)) :=
β¨Ξ» x y, β¨x \ y, x.prop.diff y.propβ©β©
@[simp] lemma coe_sdiff (s t : subtype (measurable_set : set Ξ± β Prop)) :
β(s \ t) = (s \ t : set Ξ±) := rfl
instance : has_bot (subtype (measurable_set : set Ξ± β Prop)) :=
β¨β¨β₯, measurable_set.emptyβ©β©
@[simp] lemma coe_bot : β(β₯ : subtype (measurable_set : set Ξ± β Prop)) = (β₯ : set Ξ±) := rfl
instance : has_top (subtype (measurable_set : set Ξ± β Prop)) :=
β¨β¨β€, measurable_set.univβ©β©
@[simp] lemma coe_top : β(β€ : subtype (measurable_set : set Ξ± β Prop)) = (β€ : set Ξ±) := rfl
instance : partial_order (subtype (measurable_set : set Ξ± β Prop)) :=
partial_order.lift _ subtype.coe_injective
instance : distrib_lattice (subtype (measurable_set : set Ξ± β Prop)) :=
{ sup := (βͺ),
le_sup_left := Ξ» a b, show (a : set Ξ±) β€ a β b, from le_sup_left,
le_sup_right := Ξ» a b, show (b : set Ξ±) β€ a β b, from le_sup_right,
sup_le := Ξ» a b c ha hb, show (a β b : set Ξ±) β€ c, from sup_le ha hb,
inf := (β©),
inf_le_left := Ξ» a b, show (a β b : set Ξ±) β€ a, from inf_le_left,
inf_le_right := Ξ» a b, show (a β b : set Ξ±) β€ b, from inf_le_right,
le_inf := Ξ» a b c ha hb, show (a : set Ξ±) β€ b β c, from le_inf ha hb,
le_sup_inf := Ξ» x y z, show ((x β y) β (x β z) : set Ξ±) β€ x β y β z, from le_sup_inf,
.. measurable_set.subtype.partial_order }
instance : bounded_order (subtype (measurable_set : set Ξ± β Prop)) :=
{ top := β€,
le_top := Ξ» a, show (a : set Ξ±) β€ β€, from le_top,
bot := β₯,
bot_le := Ξ» a, show (β₯ : set Ξ±) β€ a, from bot_le }
instance : boolean_algebra (subtype (measurable_set : set Ξ± β Prop)) :=
{ sdiff := (\),
compl := has_compl.compl,
inf_compl_le_bot := Ξ» a, boolean_algebra.inf_compl_le_bot (a : set Ξ±),
top_le_sup_compl := Ξ» a, boolean_algebra.top_le_sup_compl (a : set Ξ±),
sdiff_eq := Ξ» a b, subtype.eq $ sdiff_eq,
.. measurable_set.subtype.bounded_order,
.. measurable_set.subtype.distrib_lattice }
@[measurability] lemma measurable_set_blimsup {s : β β set Ξ±} {p : β β Prop}
(h : β n, p n β measurable_set (s n)) :
measurable_set $ filter.blimsup s filter.at_top p :=
begin
simp only [filter.blimsup_eq_infi_bsupr_of_nat, supr_eq_Union, infi_eq_Inter],
exact measurable_set.Inter
(Ξ» n, measurable_set.Union (Ξ» m, measurable_set.Union $ Ξ» hm, h m hm.1)),
end
@[measurability] lemma measurable_set_bliminf {s : β β set Ξ±} {p : β β Prop}
(h : β n, p n β measurable_set (s n)) :
measurable_set $ filter.bliminf s filter.at_top p :=
begin
simp only [filter.bliminf_eq_supr_binfi_of_nat, infi_eq_Inter, supr_eq_Union],
exact measurable_set.Union
(Ξ» n, measurable_set.Inter (Ξ» m, measurable_set.Inter $ Ξ» hm, h m hm.1)),
end
@[measurability] lemma measurable_set_limsup {s : β β set Ξ±} (hs : β n, measurable_set $ s n) :
measurable_set $ filter.limsup s filter.at_top :=
begin
convert measurable_set_blimsup (Ξ» n h, hs n : β n, true β measurable_set (s n)),
simp,
end
@[measurability] lemma measurable_set_liminf {s : β β set Ξ±} (hs : β n, measurable_set $ s n) :
measurable_set $ filter.liminf s filter.at_top :=
begin
convert measurable_set_bliminf (Ξ» n h, hs n : β n, true β measurable_set (s n)),
simp,
end
end measurable_set
|
682b1cc32d458a9389d0a68130b6d999f0cc9df2
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/polynomial/algebra_map.lean
|
e91fee5d30a3ae933478f7ca888bfad3038a4c20
|
[
"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
| 13,840
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes HΓΆlzl, Scott Morrison, Jens Wagemaker
-/
import ring_theory.adjoin.basic
import data.polynomial.eval
/-!
# Theory of univariate polynomials
We show that `polynomial A` is an R-algebra when `A` is an R-algebra.
We promote `evalβ` to an algebra hom in `aeval`.
-/
noncomputable theory
open finset
open_locale big_operators polynomial
namespace polynomial
universes u v w z
variables {R : Type u} {S : Type v} {T : Type w} {A : Type z} {A' B' : Type*} {a b : R} {n : β}
variables [comm_semiring A'] [semiring B']
section comm_semiring
variables [comm_semiring R] {p q r : R[X]}
variables [semiring A] [algebra R A]
/-- Note that this instance also provides `algebra R R[X]`. -/
instance algebra_of_algebra : algebra R (polynomial A) :=
{ smul_def' := Ξ» r p, to_finsupp_injective $ begin
dsimp only [ring_hom.to_fun_eq_coe, ring_hom.comp_apply],
rw [to_finsupp_smul, to_finsupp_mul, to_finsupp_C],
exact algebra.smul_def' _ _,
end,
commutes' := Ξ» r p, to_finsupp_injective $ begin
dsimp only [ring_hom.to_fun_eq_coe, ring_hom.comp_apply],
simp_rw [to_finsupp_mul, to_finsupp_C],
convert algebra.commutes' r p.to_finsupp,
end,
to_ring_hom := C.comp (algebra_map R A) }
lemma algebra_map_apply (r : R) :
algebra_map R (polynomial A) r = C (algebra_map R A r) :=
rfl
@[simp] lemma to_finsupp_algebra_map (r : R) :
(algebra_map R (polynomial A) r).to_finsupp = algebra_map R _ r :=
show to_finsupp (C (algebra_map _ _ r)) = _, by { rw to_finsupp_C, refl }
lemma of_finsupp_algebra_map (r : R) :
(β¨algebra_map R _ rβ© : A[X]) = algebra_map R (polynomial A) r :=
to_finsupp_injective (to_finsupp_algebra_map _).symm
/--
When we have `[comm_semiring R]`, the function `C` is the same as `algebra_map R R[X]`.
(But note that `C` is defined when `R` is not necessarily commutative, in which case
`algebra_map` is not available.)
-/
lemma C_eq_algebra_map (r : R) :
C r = algebra_map R R[X] r :=
rfl
variables {R}
/--
Extensionality lemma for algebra maps out of `polynomial A'` over a smaller base ring than `A'`
-/
@[ext] lemma alg_hom_ext' [algebra R A'] [algebra R B']
{f g : A'[X] ββ[R] B'}
(hβ : f.comp (is_scalar_tower.to_alg_hom R A' (polynomial A')) =
g.comp (is_scalar_tower.to_alg_hom R A' (polynomial A')))
(hβ : f X = g X) : f = g :=
alg_hom.coe_ring_hom_injective (polynomial.ring_hom_ext'
(congr_arg alg_hom.to_ring_hom hβ) hβ)
variable (R)
/-- Algebra isomorphism between `polynomial R` and `add_monoid_algebra R β`. This is just an
implementation detail, but it can be useful to transfer results from `finsupp` to polynomials. -/
@[simps]
def to_finsupp_iso_alg : R[X] ββ[R] add_monoid_algebra R β :=
{ commutes' := Ξ» r,
begin
dsimp,
exact to_finsupp_algebra_map _,
end,
..to_finsupp_iso R }
variable {R}
instance [nontrivial A] : nontrivial (subalgebra R (polynomial A)) :=
β¨β¨β₯, β€, begin
rw [ne.def, set_like.ext_iff, not_forall],
refine β¨X, _β©,
simp only [algebra.mem_bot, not_exists, set.mem_range, iff_true, algebra.mem_top,
algebra_map_apply, not_forall],
intro x,
rw [ext_iff, not_forall],
refine β¨1, _β©,
simp [coeff_C],
endβ©β©
@[simp]
lemma alg_hom_evalβ_algebra_map
{R A B : Type*} [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
(p : R[X]) (f : A ββ[R] B) (a : A) :
f (evalβ (algebra_map R A) a p) = evalβ (algebra_map R B) (f a) p :=
begin
dsimp [evalβ, sum],
simp only [f.map_sum, f.map_mul, f.map_pow, ring_hom.eq_int_cast, ring_hom.map_int_cast,
alg_hom.commutes],
end
@[simp]
lemma evalβ_algebra_map_X {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
(p : R[X]) (f : R[X] ββ[R] A) :
evalβ (algebra_map R A) (f X) p = f p :=
begin
conv_rhs { rw [βpolynomial.sum_C_mul_X_eq p], },
dsimp [evalβ, sum],
simp only [f.map_sum, f.map_mul, f.map_pow, ring_hom.eq_int_cast, ring_hom.map_int_cast],
simp [polynomial.C_eq_algebra_map],
end
-- these used to be about `algebra_map β€ R`, but now the simp-normal form is `int.cast_ring_hom R`.
@[simp]
lemma ring_hom_evalβ_cast_int_ring_hom {R S : Type*} [ring R] [ring S]
(p : β€[X]) (f : R β+* S) (r : R) :
f (evalβ (int.cast_ring_hom R) r p) = evalβ (int.cast_ring_hom S) (f r) p :=
alg_hom_evalβ_algebra_map p f.to_int_alg_hom r
@[simp]
lemma evalβ_int_cast_ring_hom_X {R : Type*} [ring R] (p : β€[X]) (f : β€[X] β+* R) :
evalβ (int.cast_ring_hom R) (f X) p = f p :=
evalβ_algebra_map_X p f.to_int_alg_hom
end comm_semiring
section aeval
variables [comm_semiring R] {p q : R[X]}
variables [semiring A] [algebra R A]
variables {B : Type*} [semiring B] [algebra R B]
variables (x : A)
/-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is
the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`.
This is a stronger variant of the linear map `polynomial.leval`. -/
def aeval : R[X] ββ[R] A :=
{ commutes' := Ξ» r, evalβ_C _ _,
..evalβ_ring_hom' (algebra_map R A) x (Ξ» a, algebra.commutes _ _) }
variables {R A}
@[simp] lemma adjoin_X : algebra.adjoin R ({X} : set R[X]) = β€ :=
begin
refine top_unique (Ξ» p hp, _),
set S := algebra.adjoin R ({X} : set R[X]),
rw [β sum_monomial_eq p], simp only [monomial_eq_smul_X, sum],
exact S.sum_mem (Ξ» n hn, S.smul_mem (S.pow_mem (algebra.subset_adjoin rfl) _) _)
end
@[ext] lemma alg_hom_ext {f g : R[X] ββ[R] A} (h : f X = g X) : f = g :=
alg_hom.ext_of_adjoin_eq_top adjoin_X $ Ξ» p hp, (set.mem_singleton_iff.1 hp).symm βΈ h
theorem aeval_def (p : R[X]) : aeval x p = evalβ (algebra_map R A) x p := rfl
@[simp] lemma aeval_zero : aeval x (0 : R[X]) = 0 :=
alg_hom.map_zero (aeval x)
@[simp] lemma aeval_X : aeval x (X : R[X]) = x := evalβ_X _ x
@[simp] lemma aeval_C (r : R) : aeval x (C r) = algebra_map R A r := evalβ_C _ x
@[simp] lemma aeval_monomial {n : β} {r : R} : aeval x (monomial n r) = (algebra_map _ _ r) * x^n :=
evalβ_monomial _ _
@[simp] lemma aeval_X_pow {n : β} : aeval x ((X : R[X])^n) = x^n :=
evalβ_X_pow _ _
@[simp] lemma aeval_add : aeval x (p + q) = aeval x p + aeval x q :=
alg_hom.map_add _ _ _
@[simp] lemma aeval_one : aeval x (1 : R[X]) = 1 :=
alg_hom.map_one _
@[simp] lemma aeval_bit0 : aeval x (bit0 p) = bit0 (aeval x p) :=
alg_hom.map_bit0 _ _
@[simp] lemma aeval_bit1 : aeval x (bit1 p) = bit1 (aeval x p) :=
alg_hom.map_bit1 _ _
@[simp] lemma aeval_nat_cast (n : β) : aeval x (n : R[X]) = n :=
map_nat_cast _ _
lemma aeval_mul : aeval x (p * q) = aeval x p * aeval x q :=
alg_hom.map_mul _ _ _
lemma aeval_comp {A : Type*} [comm_semiring A] [algebra R A] (x : A) :
aeval x (p.comp q) = (aeval (aeval x q) p) :=
evalβ_comp (algebra_map R A)
@[simp] lemma aeval_map {A : Type*} [comm_semiring A] [algebra R A] [algebra A B]
[is_scalar_tower R A B] (b : B) (p : R[X]) :
aeval b (p.map (algebra_map R A)) = aeval b p :=
by rw [aeval_def, evalβ_map, βis_scalar_tower.algebra_map_eq, βaeval_def]
theorem aeval_alg_hom (f : A ββ[R] B) (x : A) : aeval (f x) = f.comp (aeval x) :=
alg_hom_ext $ by simp only [aeval_X, alg_hom.comp_apply]
@[simp] theorem aeval_X_left : aeval (X : R[X]) = alg_hom.id R R[X] :=
alg_hom_ext $ aeval_X X
theorem eval_unique (Ο : R[X] ββ[R] A) (p) :
Ο p = evalβ (algebra_map R A) (Ο X) p :=
by rw [β aeval_def, aeval_alg_hom, aeval_X_left, alg_hom.comp_id]
theorem aeval_alg_hom_apply (f : A ββ[R] B) (x : A) (p : R[X]) :
aeval (f x) p = f (aeval x p) :=
alg_hom.ext_iff.1 (aeval_alg_hom f x) p
theorem aeval_alg_equiv (f : A ββ[R] B) (x : A) : aeval (f x) = (f : A ββ[R] B).comp (aeval x) :=
aeval_alg_hom (f : A ββ[R] B) x
theorem aeval_alg_equiv_apply (f : A ββ[R] B) (x : A) (p : R[X]) :
aeval (f x) p = f (aeval x p) :=
aeval_alg_hom_apply (f : A ββ[R] B) x p
lemma aeval_algebra_map_apply (x : R) (p : R[X]) :
aeval (algebra_map R A x) p = algebra_map R A (p.eval x) :=
aeval_alg_hom_apply (algebra.of_id R A) x p
@[simp] lemma coe_aeval_eq_eval (r : R) :
(aeval r : R[X] β R) = eval r := rfl
@[simp] lemma aeval_fn_apply {X : Type*} (g : R[X]) (f : X β R) (x : X) :
((aeval f) g) x = aeval (f x) g :=
(aeval_alg_hom_apply (pi.eval_alg_hom _ _ x) f g).symm
@[norm_cast] lemma aeval_subalgebra_coe
(g : R[X]) {A : Type*} [semiring A] [algebra R A] (s : subalgebra R A) (f : s) :
(aeval f g : A) = aeval (f : A) g :=
(aeval_alg_hom_apply s.val f g).symm
lemma coeff_zero_eq_aeval_zero (p : R[X]) : p.coeff 0 = aeval 0 p :=
by simp [coeff_zero_eq_eval_zero]
lemma coeff_zero_eq_aeval_zero' (p : R[X]) :
algebra_map R A (p.coeff 0) = aeval (0 : A) p :=
by simp [aeval_def]
variable (R)
theorem _root_.algebra.adjoin_singleton_eq_range_aeval (x : A) :
algebra.adjoin R {x} = (polynomial.aeval x).range :=
by rw [β algebra.map_top, β adjoin_X, alg_hom.map_adjoin, set.image_singleton, aeval_X]
variable {R}
section comm_semiring
variables [comm_semiring S] {f : R β+* S}
lemma aeval_eq_sum_range [algebra R S] {p : R[X]} (x : S) :
aeval x p = β i in finset.range (p.nat_degree + 1), p.coeff i β’ x ^ i :=
by { simp_rw algebra.smul_def, exact evalβ_eq_sum_range (algebra_map R S) x }
lemma aeval_eq_sum_range' [algebra R S] {p : R[X]} {n : β} (hn : p.nat_degree < n) (x : S) :
aeval x p = β i in finset.range n, p.coeff i β’ x ^ i :=
by { simp_rw algebra.smul_def, exact evalβ_eq_sum_range' (algebra_map R S) hn x }
lemma is_root_of_evalβ_map_eq_zero
(hf : function.injective f) {r : R} : evalβ f (f r) p = 0 β p.is_root r :=
begin
intro h,
apply hf,
rw [βevalβ_hom, h, f.map_zero],
end
lemma is_root_of_aeval_algebra_map_eq_zero [algebra R S] {p : R[X]}
(inj : function.injective (algebra_map R S))
{r : R} (hr : aeval (algebra_map R S r) p = 0) : p.is_root r :=
is_root_of_evalβ_map_eq_zero inj hr
section aeval_tower
variables [algebra S R] [algebra S A'] [algebra S B']
/-- Version of `aeval` for defining algebra homs out of `polynomial R` over a smaller base ring
than `R`. -/
def aeval_tower (f : R ββ[S] A') (x : A') : R[X] ββ[S] A' :=
{ commutes' := Ξ» r, by simp [algebra_map_apply],
..evalβ_ring_hom βf x }
variables (g : R ββ[S] A') (y : A')
@[simp] lemma aeval_tower_X : aeval_tower g y X = y := evalβ_X _ _
@[simp] lemma aeval_tower_C (x : R) : aeval_tower g y (C x) = g x := evalβ_C _ _
@[simp] lemma aeval_tower_comp_C : ((aeval_tower g y : R[X] β+* A').comp C) = g :=
ring_hom.ext $ aeval_tower_C _ _
@[simp] lemma aeval_tower_algebra_map (x : R) :
aeval_tower g y (algebra_map R R[X] x) = g x := evalβ_C _ _
@[simp] lemma aeval_tower_comp_algebra_map :
(aeval_tower g y : R[X] β+* A').comp (algebra_map R R[X]) = g :=
aeval_tower_comp_C _ _
lemma aeval_tower_to_alg_hom (x : R) :
aeval_tower g y (is_scalar_tower.to_alg_hom S R R[X] x) = g x :=
aeval_tower_algebra_map _ _ _
@[simp] lemma aeval_tower_comp_to_alg_hom :
(aeval_tower g y).comp (is_scalar_tower.to_alg_hom S R R[X]) = g :=
alg_hom.coe_ring_hom_injective $ aeval_tower_comp_algebra_map _ _
@[simp] lemma aeval_tower_id : aeval_tower (alg_hom.id S S) = aeval :=
by { ext, simp only [eval_X, aeval_tower_X, coe_aeval_eq_eval], }
@[simp] lemma aeval_tower_of_id : aeval_tower (algebra.of_id S A') = aeval :=
by { ext, simp only [aeval_X, aeval_tower_X], }
end aeval_tower
end comm_semiring
section comm_ring
variables [comm_ring S] {f : R β+* S}
lemma dvd_term_of_dvd_eval_of_dvd_terms {z p : S} {f : S[X]} (i : β)
(dvd_eval : p β£ f.eval z) (dvd_terms : β (j β i), p β£ f.coeff j * z ^ j) :
p β£ f.coeff i * z ^ i :=
begin
by_cases hi : i β f.support,
{ rw [eval, evalβ, sum] at dvd_eval,
rw [βfinset.insert_erase hi, finset.sum_insert (finset.not_mem_erase _ _)] at dvd_eval,
refine (dvd_add_left _).mp dvd_eval,
apply finset.dvd_sum,
intros j hj,
exact dvd_terms j (finset.ne_of_mem_erase hj) },
{ convert dvd_zero p,
rw not_mem_support_iff at hi,
simp [hi] }
end
lemma dvd_term_of_is_root_of_dvd_terms {r p : S} {f : S[X]} (i : β)
(hr : f.is_root r) (h : β (j β i), p β£ f.coeff j * r ^ j) : p β£ f.coeff i * r ^ i :=
dvd_term_of_dvd_eval_of_dvd_terms i (eq.symm hr βΈ dvd_zero p) h
end comm_ring
end aeval
section ring
variables [ring R]
/--
The evaluation map is not generally multiplicative when the coefficient ring is noncommutative,
but nevertheless any polynomial of the form `p * (X - monomial 0 r)` is sent to zero
when evaluated at `r`.
This is the key step in our proof of the Cayley-Hamilton theorem.
-/
lemma eval_mul_X_sub_C {p : R[X]} (r : R) :
(p * (X - C r)).eval r = 0 :=
begin
simp only [eval, evalβ, ring_hom.id_apply],
have bound := calc
(p * (X - C r)).nat_degree
β€ p.nat_degree + (X - C r).nat_degree : nat_degree_mul_le
... β€ p.nat_degree + 1 : add_le_add_left nat_degree_X_sub_C_le _
... < p.nat_degree + 2 : lt_add_one _,
rw sum_over_range' _ _ (p.nat_degree + 2) bound,
swap,
{ simp, },
rw sum_range_succ',
conv_lhs
{ congr, apply_congr, skip,
rw [coeff_mul_X_sub_C, sub_mul, mul_assoc, βpow_succ], },
simp [sum_range_sub', coeff_monomial],
end
theorem not_is_unit_X_sub_C [nontrivial R] (r : R) : Β¬ is_unit (X - C r) :=
Ξ» β¨β¨_, g, hfg, hgfβ©, rflβ©, @zero_ne_one R _ _ $ by erw [β eval_mul_X_sub_C, hgf, eval_one]
end ring
lemma aeval_endomorphism {M : Type*}
[comm_ring R] [add_comm_group M] [module R M]
(f : M ββ[R] M) (v : M) (p : R[X]) :
aeval f p v = p.sum (Ξ» n b, b β’ (f ^ n) v) :=
begin
rw [aeval_def, evalβ],
exact (linear_map.applyβ v).map_sum,
end
end polynomial
|
a992fb386c73e565d2a1b0f3d231ea6b5e6fd7c2
|
a45212b1526d532e6e83c44ddca6a05795113ddc
|
/src/data/pnat.lean
|
e04b522cb61b13e005f7c2918d14cd028923e352
|
[
"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
| 2,424
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import tactic.basic
/-- `β+` is the type of positive natural numbers. It is defined as a subtype,
and the VM representation of `β+` is the same as `β` because the proof
is not stored. -/
def pnat := {n : β // n > 0}
notation `β+` := pnat
instance coe_pnat_nat : has_coe β+ β := β¨subtype.valβ©
namespace nat
/-- Convert a natural number to a positive natural number. The
positivity assumption is inferred by `dec_trivial`. -/
def to_pnat (n : β) (h : n > 0 . tactic.exact_dec_trivial) : β+ := β¨n, hβ©
/-- Write a successor as an element of `β+`. -/
def succ_pnat (n : β) : β+ := β¨succ n, succ_pos nβ©
@[simp] theorem succ_pnat_coe (n : β) : (succ_pnat n : β) = succ n := rfl
/-- Convert a natural number to a pnat. `n+1` is mapped to itself,
and `0` becomes `1`. -/
def to_pnat' (n : β) : β+ := succ_pnat (pred n)
end nat
namespace pnat
open nat
@[simp] theorem pos (n : β+) : (n : β) > 0 := n.2
theorem eq {m n : β+} : (m : β) = n β m = n := subtype.eq
@[simp] theorem mk_coe (n h) : ((β¨n, hβ© : β+) : β) = n := rfl
instance : has_add β+ := β¨Ξ» m n, β¨m + n, add_pos m.2 n.2β©β©
@[simp] theorem add_coe (m n : β+) : ((m + n : β+) : β) = m + n := rfl
@[simp] theorem ne_zero (n : β+) : (n : β) β 0 := ne_of_gt n.2
@[simp] theorem to_pnat'_coe {n : β} : n > 0 β (n.to_pnat' : β) = n := succ_pred_eq_of_pos
@[simp] theorem coe_to_pnat' (n : β+) : (n : β).to_pnat' = n := eq (to_pnat'_coe n.pos)
instance : comm_monoid β+ :=
{ mul := Ξ» m n, β¨m.1 * n.1, mul_pos m.2 n.2β©,
mul_assoc := Ξ» a b c, subtype.eq (mul_assoc _ _ _),
one := succ_pnat 0,
one_mul := Ξ» a, subtype.eq (one_mul _),
mul_one := Ξ» a, subtype.eq (mul_one _),
mul_comm := Ξ» a b, subtype.eq (mul_comm _ _) }
@[simp] theorem one_coe : ((1 : β+) : β) = 1 := rfl
@[simp] theorem mul_coe (m n : β+) : ((m * n : β+) : β) = m * n := rfl
/-- The power of a pnat and a nat is a pnat. -/
def pow (m : β+) (n : β) : β+ :=
β¨m ^ n, nat.pos_pow_of_pos _ m.posβ©
instance : has_pow β+ β := β¨powβ©
@[simp] theorem pow_coe (m : β+) (n : β) : (β(m ^ n) : β) = m ^ n := rfl
instance : has_repr β+ := β¨Ξ» n, repr n.1β©
end pnat
|
b352787f96494602a0c4e8a3ffa5f0991c3612bd
|
969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb
|
/src/algebra/continued_fractions/computation/approximations.lean
|
9bb14add6fb38dca5b3ac34df2f7dae255da61a7
|
[
"Apache-2.0"
] |
permissive
|
SAAluthwela/mathlib
|
62044349d72dd63983a8500214736aa7779634d3
|
83a4b8b990907291421de54a78988c024dc8a552
|
refs/heads/master
| 1,679,433,873,417
| 1,615,998,031,000
| 1,615,998,031,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 29,862
|
lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import algebra.continued_fractions.computation.correctness_terminating
import data.nat.fib
import tactic.solve_by_elim
/-!
# Approximations for Continued Fraction Computations (`generalized_continued_fraction.of`)
## Summary
This file contains useful approximations for the values involved in the continued fractions
computation `generalized_continued_fraction.of`. In particular, we derive the so-called
*determinant formula* for `generalized_continued_fraction.of`:
`Aβ * Bβββ - Bβ * Aβββ = (-1)^(n + 1)`.
Moreover, we derive some upper bounds for the error term when computing a continued fraction up a
given position, i.e. bounds for the term
`|v - (generalized_continued_fraction.of v).convergents n|`. The derived bounds will show us that
the error term indeed gets smaller. As a corollary, we will be able to show that
`(generalized_continued_fraction.of v).convergents` converges to `v` in
`algebra.continued_fractions.computation.approximation_corollaries`.
## Main Theorems
- `generalized_continued_fraction.of_part_num_eq_one`: shows that all partial numerators `aα΅’` are
equal to one.
- `generalized_continued_fraction.exists_int_eq_of_part_denom`: shows that all partial denominators
`bα΅’` correspond to an integer.
- `generalized_continued_fraction.one_le_of_nth_part_denom`: shows that `1 β€ bα΅’`.
- `generalized_continued_fraction.succ_nth_fib_le_of_nth_denom`: shows that the `n`th denominator
`Bβ` is greater than or equal to the `n + 1`th fibonacci number `nat.fib (n + 1)`.
- `generalized_continued_fraction.le_of_succ_nth_denom`: shows that `bβ * Bβ β€ Bβββ`, where `bβ` is
the `n`th partial denominator of the continued fraction.
- `generalized_continued_fraction.abs_sub_convergents_le`: shows that
`|v - Aβ / Bβ| β€ 1 / (Bβ * Bβββ)`, where `Aβ` is the nth partial numerator.
## References
- [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction]
- https://en.wikipedia.org/wiki/Generalized_continued_fraction#The_determinant_formula
-/
namespace generalized_continued_fraction
open generalized_continued_fraction as gcf
variables {K : Type*} {v : K} {n : β} [linear_ordered_field K] [floor_ring K]
namespace int_fract_pair
/-!
We begin with some lemmas about the stream of `int_fract_pair`s, which presumably are not
of great interest for the end user.
-/
/-- Shows that the fractional parts of the stream are in `[0,1)`. -/
lemma nth_stream_fr_nonneg_lt_one {ifp_n : int_fract_pair K}
(nth_stream_eq : int_fract_pair.stream v n = some ifp_n) :
0 β€ ifp_n.fr β§ ifp_n.fr < 1 :=
begin
cases n,
case nat.zero
{ have : int_fract_pair.of v = ifp_n, by injection nth_stream_eq,
simp [fract_lt_one, fract_nonneg, int_fract_pair.of, this.symm] },
case nat.succ
{ rcases (succ_nth_stream_eq_some_iff.elim_left nth_stream_eq) with β¨_, _, _, ifp_of_eq_ifp_nβ©,
simp [fract_lt_one, fract_nonneg, int_fract_pair.of, ifp_of_eq_ifp_n.symm] }
end
/-- Shows that the fractional parts of the stream are nonnegative. -/
lemma nth_stream_fr_nonneg {ifp_n : int_fract_pair K}
(nth_stream_eq : int_fract_pair.stream v n = some ifp_n) :
0 β€ ifp_n.fr :=
(nth_stream_fr_nonneg_lt_one nth_stream_eq).left
/-- Shows that the fractional parts of the stream are smaller than one. -/
lemma nth_stream_fr_lt_one {ifp_n : int_fract_pair K}
(nth_stream_eq : int_fract_pair.stream v n = some ifp_n) :
ifp_n.fr < 1 :=
(nth_stream_fr_nonneg_lt_one nth_stream_eq).right
/-- Shows that the integer parts of the stream are at least one. -/
lemma one_le_succ_nth_stream_b {ifp_succ_n : int_fract_pair K}
(succ_nth_stream_eq : int_fract_pair.stream v (n + 1) = some ifp_succ_n) :
1 β€ ifp_succ_n.b :=
begin
obtain β¨ifp_n, nth_stream_eq, stream_nth_fr_ne_zero, β¨-β©β© :
β ifp_n, int_fract_pair.stream v n = some ifp_n β§ ifp_n.fr β 0
β§ int_fract_pair.of ifp_n.frβ»ΒΉ = ifp_succ_n, from
succ_nth_stream_eq_some_iff.elim_left succ_nth_stream_eq,
suffices : 1 β€ ifp_n.frβ»ΒΉ, { rw_mod_cast [le_floor], assumption },
suffices : ifp_n.fr β€ 1,
{ have h : 0 < ifp_n.fr, from
lt_of_le_of_ne (nth_stream_fr_nonneg nth_stream_eq) stream_nth_fr_ne_zero.symm,
apply one_le_inv h this },
simp only [le_of_lt (nth_stream_fr_lt_one nth_stream_eq)]
end
/--
Shows that the `n + 1`th integer part `bβββ` of the stream is smaller or equal than the inverse of
the `n`th fractional part `frβ` of the stream.
This result is straight-forward as `bβββ` is defined as the floor of `1 / frβ`
-/
lemma succ_nth_stream_b_le_nth_stream_fr_inv {ifp_n ifp_succ_n : int_fract_pair K}
(nth_stream_eq : int_fract_pair.stream v n = some ifp_n)
(succ_nth_stream_eq : int_fract_pair.stream v (n + 1) = some ifp_succ_n) :
(ifp_succ_n.b : K) β€ ifp_n.frβ»ΒΉ :=
begin
suffices : (βifp_n.frβ»ΒΉβ : K) β€ ifp_n.frβ»ΒΉ,
{ cases ifp_n with _ ifp_n_fr,
have : ifp_n_fr β 0,
{ intro h, simpa [h, int_fract_pair.stream, nth_stream_eq] using succ_nth_stream_eq },
have : int_fract_pair.of ifp_n_frβ»ΒΉ = ifp_succ_n,
{ simpa [this, int_fract_pair.stream, nth_stream_eq, option.coe_def] using succ_nth_stream_eq },
rwa βthis },
exact (floor_le ifp_n.frβ»ΒΉ)
end
end int_fract_pair
/-!
Next we translate above results about the stream of `int_fract_pair`s to the computed continued
fraction `generalized_continued_fraction.of`.
-/
/-- Shows that the integer parts of the continued fraction are at least one. -/
lemma of_one_le_nth_part_denom {b : K}
(nth_part_denom_eq : (gcf.of v).partial_denominators.nth n = some b) :
1 β€ b :=
begin
obtain β¨gp_n, nth_s_eq, β¨-β©β© : β gp_n, (gcf.of v).s.nth n = some gp_n β§ gp_n.b = b, from
exists_s_b_of_part_denom nth_part_denom_eq,
obtain β¨ifp_n, succ_nth_stream_eq, ifp_n_b_eq_gp_n_bβ© :
β ifp, int_fract_pair.stream v (n + 1) = some ifp β§ (ifp.b : K) = gp_n.b, from
int_fract_pair.exists_succ_nth_stream_of_gcf_of_nth_eq_some nth_s_eq,
rw [βifp_n_b_eq_gp_n_b],
exact_mod_cast (int_fract_pair.one_le_succ_nth_stream_b succ_nth_stream_eq)
end
/--
Shows that the partial numerators `aα΅’` of the continued fraction are equal to one and the partial
denominators `bα΅’` correspond to integers.
-/
lemma of_part_num_eq_one_and_exists_int_part_denom_eq {gp : gcf.pair K}
(nth_s_eq : (gcf.of v).s.nth n = some gp) :
gp.a = 1 β§ β (z : β€), gp.b = (z : K) :=
begin
obtain β¨ifp, stream_succ_nth_eq, -β© :
β ifp, int_fract_pair.stream v (n + 1) = some ifp β§ _,
from int_fract_pair.exists_succ_nth_stream_of_gcf_of_nth_eq_some nth_s_eq,
have : gp = β¨1, ifp.bβ©, by
{ have : (gcf.of v).s.nth n = some β¨1, ifp.bβ©, from
nth_of_eq_some_of_succ_nth_int_fract_pair_stream stream_succ_nth_eq,
have : some gp = some β¨1, ifp.bβ©, by rwa nth_s_eq at this,
injection this },
finish
end
/-- Shows that the partial numerators `aα΅’` are equal to one. -/
lemma of_part_num_eq_one {a : K} (nth_part_num_eq : (gcf.of v).partial_numerators.nth n = some a) :
a = 1 :=
begin
obtain β¨gp, nth_s_eq, gp_a_eq_a_nβ© : β gp, (gcf.of v).s.nth n = some gp β§ gp.a = a, from
exists_s_a_of_part_num nth_part_num_eq,
have : gp.a = 1, from (of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).left,
rwa gp_a_eq_a_n at this
end
/-- Shows that the partial denominators `bα΅’` correspond to an integer. -/
lemma exists_int_eq_of_part_denom {b : K}
(nth_part_denom_eq : (gcf.of v).partial_denominators.nth n = some b) :
β (z : β€), b = (z : K) :=
begin
obtain β¨gp, nth_s_eq, gp_b_eq_b_nβ© : β gp, (gcf.of v).s.nth n = some gp β§ gp.b = b, from
exists_s_b_of_part_denom nth_part_denom_eq,
have : β (z : β€), gp.b = (z : K), from
(of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).right,
rwa gp_b_eq_b_n at this
end
/-!
One of our next goals is to show that `bβ * Bβ β€ Bβββ`. For this, we first show that the partial
denominators `Bβ` are bounded from below by the fibonacci sequence `nat.fib`. This then implies that
`0 β€ Bβ` and hence `Bβββ = bβββ * Bβββ + Bβ β₯ bβββ * Bβββ + 0 = bβββ * Bβββ`.
-/
-- open `nat` as we will make use of fibonacci numbers.
open nat
lemma fib_le_of_continuants_aux_b : (n β€ 1 β¨ Β¬(gcf.of v).terminated_at (n - 2)) β
(fib n : K) β€ ((gcf.of v).continuants_aux n).b :=
nat.strong_induction_on n
begin
clear n,
assume n IH hyp,
rcases n with _|_|n,
{ simp [fib_succ_succ, continuants_aux] }, -- case n = 0
{ simp [fib_succ_succ, continuants_aux] }, -- case n = 1
{ let g := gcf.of v, -- case 2 β€ n
have : Β¬(n + 2 β€ 1), by linarith,
have not_terminated_at_n : Β¬g.terminated_at n, from or.resolve_left hyp this,
obtain β¨gp, s_ppred_nth_eqβ© : β gp, g.s.nth n = some gp, from
option.ne_none_iff_exists'.mp not_terminated_at_n,
set pconts := g.continuants_aux (n + 1) with pconts_eq,
set ppconts := g.continuants_aux n with ppconts_eq,
-- use the recurrence of continuants_aux
suffices : (fib n : K) + fib (n + 1) β€ gp.a * ppconts.b + gp.b * pconts.b, by
simpa [fib_succ_succ, add_comm,
(continuants_aux_recurrence s_ppred_nth_eq ppconts_eq pconts_eq)],
-- make use of the fact that gp.a = 1
suffices : (fib n : K) + fib (n + 1) β€ ppconts.b + gp.b * pconts.b, by
simpa [(of_part_num_eq_one $ part_num_eq_s_a s_ppred_nth_eq)],
have not_terminated_at_pred_n : Β¬g.terminated_at (n - 1), from
mt (terminated_stable $ nat.sub_le n 1) not_terminated_at_n,
have not_terminated_at_ppred_n : Β¬terminated_at g (n - 2), from
mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n,
-- use the IH to get the inequalities for `pconts` and `ppconts`
have : (fib (n + 1) : K) β€ pconts.b, from
IH _ (nat.lt.base $ n + 1) (or.inr not_terminated_at_pred_n),
have ppred_nth_fib_le_ppconts_B : (fib n : K) β€ ppconts.b, from
IH n (lt_trans (nat.lt.base n) $ nat.lt.base $ n + 1) (or.inr not_terminated_at_ppred_n),
suffices : (fib (n + 1) : K) β€ gp.b * pconts.b,
solve_by_elim [add_le_add ppred_nth_fib_le_ppconts_B],
-- finally use the fact that 1 β€ gp.b to solve the goal
suffices : 1 * (fib (n + 1) : K) β€ gp.b * pconts.b, by rwa [one_mul] at this,
have one_le_gp_b : (1 : K) β€ gp.b, from
of_one_le_nth_part_denom (part_denom_eq_s_b s_ppred_nth_eq),
have : (0 : K) β€ fib (n + 1), by exact_mod_cast (fib (n + 1)).zero_le,
have : (0 : K) β€ gp.b, from le_trans zero_le_one one_le_gp_b,
mono }
end
/-- Shows that the `n`th denominator is greater than or equal to the `n + 1`th fibonacci number,
that is `nat.fib (n + 1) β€ Bβ`. -/
lemma succ_nth_fib_le_of_nth_denom (hyp: n = 0 β¨ Β¬(gcf.of v).terminated_at (n - 1)) :
(fib (n + 1) : K) β€ (gcf.of v).denominators n :=
begin
rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux],
have : (n + 1) β€ 1 β¨ Β¬(gcf.of v).terminated_at (n - 1), by
{ cases n,
case nat.zero : { exact (or.inl $ le_refl 1) },
case nat.succ : { exact or.inr (or.resolve_left hyp n.succ_ne_zero) } },
exact (fib_le_of_continuants_aux_b this)
end
/-! As a simple consequence, we can now derive that all denominators are nonnegative. -/
lemma zero_le_of_continuants_aux_b : 0 β€ ((gcf.of v).continuants_aux n).b :=
begin
let g := gcf.of v,
induction n with n IH,
case nat.zero: { refl },
case nat.succ:
{ cases (decidable.em $ g.terminated_at (n - 1)) with terminated not_terminated,
{ cases n, -- terminating case
{ simp [zero_le_one] },
{ have : g.continuants_aux (n + 2) = g.continuants_aux (n + 1), from
continuants_aux_stable_step_of_terminated terminated,
simp only [this, IH] } },
{ calc -- non-terminating case
(0 : K) β€ fib (n + 1) : by exact_mod_cast (n + 1).fib.zero_le
... β€ ((gcf.of v).continuants_aux (n + 1)).b : fib_le_of_continuants_aux_b
(or.inr not_terminated) } }
end
/-- Shows that all denominators are nonnegative. -/
lemma zero_le_of_denom : 0 β€ (gcf.of v).denominators n :=
by { rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux], exact zero_le_of_continuants_aux_b }
lemma le_of_succ_succ_nth_continuants_aux_b {b : K}
(nth_part_denom_eq : (gcf.of v).partial_denominators.nth n = some b) :
b * ((gcf.of v).continuants_aux $ n + 1).b β€ ((gcf.of v).continuants_aux $ n + 2).b :=
begin
set g := gcf.of v with g_eq,
obtain β¨gp_n, nth_s_eq, gpnb_eq_bβ© : β gp_n, g.s.nth n = some gp_n β§ gp_n.b = b, from
exists_s_b_of_part_denom nth_part_denom_eq,
let conts := g.continuants_aux (n + 2),
set pconts := g.continuants_aux (n + 1) with pconts_eq,
set ppconts := g.continuants_aux n with ppconts_eq,
-- use the recurrence of continuants_aux and the fact that gp_n.a = 1
suffices : gp_n.b * pconts.b β€ ppconts.b + gp_n.b * pconts.b, by
{ have : gp_n.a = 1, from of_part_num_eq_one (part_num_eq_s_a nth_s_eq),
finish [gcf.continuants_aux_recurrence nth_s_eq ppconts_eq pconts_eq] },
have : 0 β€ ppconts.b, from zero_le_of_continuants_aux_b,
solve_by_elim [le_add_of_nonneg_of_le, le_refl]
end
/-- Shows that `bβ * Bβ β€ Bβββ`, where `bβ` is the `n`th partial denominator and `Bβββ` and `Bβ` are
the `n + 1`th and `n`th denominator of the continued fraction. -/
theorem le_of_succ_nth_denom {b : K}
(nth_part_denom_eq : (gcf.of v).partial_denominators.nth n = some b) :
b * (gcf.of v).denominators n β€ (gcf.of v).denominators (n + 1) :=
begin
rw [denom_eq_conts_b, nth_cont_eq_succ_nth_cont_aux],
exact (le_of_succ_succ_nth_continuants_aux_b nth_part_denom_eq)
end
/-- Shows that the sequence of denominators is monotonically increasing, that is `Bβ β€ Bβββ`. -/
theorem of_denom_mono : (gcf.of v).denominators n β€ (gcf.of v).denominators (n + 1) :=
begin
let g := gcf.of v,
cases (decidable.em $ g.partial_denominators.terminated_at n) with terminated not_terminated,
{ have : g.partial_denominators.nth n = none, by rwa seq.terminated_at at terminated,
have : g.terminated_at n, from
terminated_at_iff_part_denom_none.elim_right (by rwa seq.terminated_at at terminated),
have : g.denominators (n + 1) = g.denominators n, from
denominators_stable_of_terminated n.le_succ this,
rw this },
{ obtain β¨b, nth_part_denom_eqβ© : β b, g.partial_denominators.nth n = some b, from
option.ne_none_iff_exists'.mp not_terminated,
have : 1 β€ b, from of_one_le_nth_part_denom nth_part_denom_eq,
calc g.denominators n
β€ b * g.denominators n : by simpa using (mul_le_mul_of_nonneg_right this zero_le_of_denom)
... β€ g.denominators (n + 1) : le_of_succ_nth_denom nth_part_denom_eq }
end
section determinant
/-!
### Determinant Formula
Next we prove the so-called *determinant formula* for `generalized_continued_fraction.of`:
`Aβ * Bβββ - Bβ * Aβββ = (-1)^(n + 1)`.
-/
lemma determinant_aux (hyp: n = 0 β¨ Β¬(gcf.of v).terminated_at (n - 1)) :
((gcf.of v).continuants_aux n).a * ((gcf.of v).continuants_aux (n + 1)).b
- ((gcf.of v).continuants_aux n).b * ((gcf.of v).continuants_aux (n + 1)).a
= (-1)^n :=
begin
induction n with n IH,
case nat.zero { simp [continuants_aux] },
case nat.succ
{ -- set up some shorthand notation
let g := gcf.of v,
let conts := continuants_aux g (n + 2),
set pred_conts := continuants_aux g (n + 1) with pred_conts_eq,
set ppred_conts := continuants_aux g n with ppred_conts_eq,
let pA := pred_conts.a,
let pB := pred_conts.b,
let ppA := ppred_conts.a,
let ppB := ppred_conts.b,
-- let's change the goal to something more readable
change pA * conts.b - pB * conts.a = (-1)^(n + 1),
have not_terminated_at_n : Β¬terminated_at g n, from or.resolve_left hyp n.succ_ne_zero,
obtain β¨gp, s_nth_eqβ© : β gp, g.s.nth n = some gp, from
option.ne_none_iff_exists'.elim_left not_terminated_at_n,
-- unfold the recurrence relation for `conts` once and simplify to derive the following
suffices : pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1)^(n + 1), by
{ simp only [conts, (continuants_aux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq)],
have gp_a_eq_one : gp.a = 1, from of_part_num_eq_one (part_num_eq_s_a s_nth_eq),
rw [gp_a_eq_one, this.symm],
ring },
suffices : pA * ppB - pB * ppA = (-1)^(n + 1), calc
pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA)
= pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA : by ring
... = pA * ppB - pB * ppA : by ring
... = (-1)^(n + 1) : by assumption,
suffices : ppA * pB - ppB * pA = (-1)^n, by
{ have pow_succ_n : (-1 : K)^(n + 1) = (-1) * (-1)^n, from pow_succ (-1) n,
rw [pow_succ_n, βthis],
ring },
exact (IH $ or.inr $ mt (terminated_stable $ n.sub_le 1) not_terminated_at_n) }
end
/-- The determinant formula `Aβ * Bβββ - Bβ * Aβββ = (-1)^(n + 1)` -/
lemma determinant (not_terminated_at_n : Β¬(gcf.of v).terminated_at n) :
(gcf.of v).numerators n * (gcf.of v).denominators (n + 1)
- (gcf.of v).denominators n * (gcf.of v).numerators (n + 1)
= (-1)^(n + 1) :=
(determinant_aux $ or.inr $ not_terminated_at_n)
end determinant
section error_term
/-!
### Approximation of Error Term
Next we derive some approximations for the error term when computing a continued fraction up a given
position, i.e. bounds for the term `|v - (generalized_continued_fraction.of v).convergents n|`.
-/
/-- This lemma follows from the finite correctness proof, the determinant equality, and
by simplifying the difference. -/
lemma sub_convergents_eq {ifp : int_fract_pair K}
(stream_nth_eq : int_fract_pair.stream v n = some ifp) :
let g := gcf.of v in
let B := (g.continuants_aux (n + 1)).b in
let pB := (g.continuants_aux n).b in
v - g.convergents n = if ifp.fr = 0 then 0 else (-1)^n / (B * (ifp.frβ»ΒΉ * B + pB)) :=
begin
-- set up some shorthand notation
let g := gcf.of v,
let conts := g.continuants_aux (n + 1),
let pred_conts := g.continuants_aux n,
have g_finite_correctness : v = gcf.comp_exact_value pred_conts conts ifp.fr, from
comp_exact_value_correctness_of_stream_eq_some stream_nth_eq,
cases decidable.em (ifp.fr = 0) with ifp_fr_eq_zero ifp_fr_ne_zero,
{ suffices : v - g.convergents n = 0, by simpa [ifp_fr_eq_zero],
replace g_finite_correctness : v = g.convergents n, by
simpa [gcf.comp_exact_value, ifp_fr_eq_zero] using g_finite_correctness,
exact (sub_eq_zero.elim_right g_finite_correctness) },
{ -- more shorthand notation
let A := conts.a,
let B := conts.b,
let pA := pred_conts.a,
let pB := pred_conts.b,
-- first, let's simplify the goal as `ifp.fr β 0`
suffices : v - A / B = (-1)^n / (B * (ifp.frβ»ΒΉ * B + pB)), by simpa [ifp_fr_ne_zero],
-- now we can unfold `g.comp_exact_value` to derive the following equality for `v`
replace g_finite_correctness : v = (pA + ifp.frβ»ΒΉ * A) / (pB + ifp.frβ»ΒΉ * B), by
simpa [gcf.comp_exact_value, ifp_fr_ne_zero, next_continuants, next_numerator,
next_denominator, add_comm] using g_finite_correctness,
-- let's rewrite this equality for `v` in our goal
suffices : (pA + ifp.frβ»ΒΉ * A) / (pB + ifp.frβ»ΒΉ * B) - A / B
= (-1)^n / (B * (ifp.frβ»ΒΉ * B + pB)), by rwa g_finite_correctness,
-- To continue, we need use the determinant equality. So let's derive the needed hypothesis.
have n_eq_zero_or_not_terminated_at_pred_n : n = 0 β¨ Β¬g.terminated_at (n - 1), by
{ cases n with n',
{ simp },
{ have : int_fract_pair.stream v (n' + 1) β none, by simp [stream_nth_eq],
have : Β¬g.terminated_at n', from
(not_iff_not_of_iff of_terminated_at_n_iff_succ_nth_int_fract_pair_stream_eq_none)
.elim_right this,
exact (or.inr this) } },
have determinant_eq : pA * B - pB * A = (-1)^n, from
determinant_aux n_eq_zero_or_not_terminated_at_pred_n,
-- now all we got to do is to rewrite this equality in our goal and re-arrange terms;
-- however, for this, we first have to derive quite a few tedious inequalities.
have pB_ineq : (fib n : K) β€ pB, by
{ have : n β€ 1 β¨ Β¬g.terminated_at (n - 2), by
{ cases n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n,
{ simp [n_eq_zero] },
{ exact (or.inr $ mt (terminated_stable (n - 1).pred_le) not_terminated_at_pred_n) } },
exact (fib_le_of_continuants_aux_b this) },
have B_ineq : (fib (n + 1) : K) β€ B, by
{ have : n + 1 β€ 1 β¨ Β¬g.terminated_at (n + 1 - 2), by
{ cases n_eq_zero_or_not_terminated_at_pred_n with n_eq_zero not_terminated_at_pred_n,
{ simp [n_eq_zero, le_refl] },
{ exact (or.inr not_terminated_at_pred_n) } },
exact (fib_le_of_continuants_aux_b this) },
have zero_lt_B : 0 < B,
{ have : 1 β€ B, from
le_trans
(by exact_mod_cast fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm)) B_ineq,
exact (lt_of_lt_of_le zero_lt_one this) },
have zero_ne_B : 0 β B, from ne_of_lt zero_lt_B,
have : 0 β pB + ifp.frβ»ΒΉ * B, by
{ have : (0 : K) β€ fib n, by exact_mod_cast (fib n).zero_le,
-- 0 β€ fib n β€ pB
have zero_le_pB : 0 β€ pB, from le_trans this pB_ineq,
have : 0 < ifp.frβ»ΒΉ, by
{ suffices : 0 < ifp.fr, by rwa inv_pos,
have : 0 β€ ifp.fr, from int_fract_pair.nth_stream_fr_nonneg stream_nth_eq,
change ifp.fr β 0 at ifp_fr_ne_zero,
exact lt_of_le_of_ne this ifp_fr_ne_zero.symm },
have : 0 < ifp.frβ»ΒΉ * B, from mul_pos this zero_lt_B,
have : 0 < pB + ifp.frβ»ΒΉ * B, from add_pos_of_nonneg_of_pos zero_le_pB this,
exact (ne_of_lt this) },
-- finally, let's do the rewriting
calc
(pA + ifp.frβ»ΒΉ * A) / (pB + ifp.frβ»ΒΉ * B) - A / B
= ((pA + ifp.frβ»ΒΉ * A) * B - (pB + ifp.frβ»ΒΉ * B) * A)
/ ((pB + ifp.frβ»ΒΉ * B) * B) : by rw (div_sub_div _ _
this.symm zero_ne_B.symm)
... = (pA * B + ifp.frβ»ΒΉ * A * B - (pB * A + ifp.frβ»ΒΉ * B * A))
/ _ : by repeat { rw [add_mul] }
... = (pA * B - pB * A) / ((pB + ifp.frβ»ΒΉ * B) * B) : by ring
... = (-1)^n / ((pB + ifp.frβ»ΒΉ * B) * B) : by rw determinant_eq
... = (-1)^n / (B * (ifp.frβ»ΒΉ * B + pB)) : by ac_refl }
end
local notation `|` x `|` := abs x
/-- Shows that `|v - Aβ / Bβ| β€ 1 / (Bβ * Bβββ)` -/
theorem abs_sub_convergents_le (not_terminated_at_n : Β¬(gcf.of v).terminated_at n) :
|v - (gcf.of v).convergents n|
β€ 1 / (((gcf.of v).denominators n) * ((gcf.of v).denominators $ n + 1)) :=
begin
-- shorthand notation
let g := gcf.of v,
let nextConts := g.continuants_aux (n + 2),
set conts := continuants_aux g (n + 1) with conts_eq,
set pred_conts := continuants_aux g n with pred_conts_eq,
-- change the goal to something more readable
change |v - convergents g n| β€ 1 / (conts.b * nextConts.b),
obtain β¨gp, s_nth_eqβ© : β gp, g.s.nth n = some gp, from
option.ne_none_iff_exists'.elim_left not_terminated_at_n,
have gp_a_eq_one : gp.a = 1, from of_part_num_eq_one (part_num_eq_s_a s_nth_eq),
-- unfold the recurrence relation for `nextConts.b`
have nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b, by
simp [nextConts, (continuants_aux_recurrence s_nth_eq pred_conts_eq conts_eq), gp_a_eq_one,
pred_conts_eq.symm, conts_eq.symm, add_comm],
let denom := conts.b * (pred_conts.b + gp.b * conts.b),
suffices : |v - g.convergents n| β€ 1 / denom, by { rw [nextConts_b_eq], congr' 1 },
obtain β¨ifp_succ_n, succ_nth_stream_eq, ifp_succ_n_b_eq_gp_bβ© :
β ifp_succ_n, int_fract_pair.stream v (n + 1)
= some ifp_succ_n β§ (ifp_succ_n.b : K) = gp.b, from
int_fract_pair.exists_succ_nth_stream_of_gcf_of_nth_eq_some s_nth_eq,
obtain β¨ifp_n, stream_nth_eq, stream_nth_fr_ne_zero, if_of_eq_ifp_succ_nβ© :
β ifp_n, int_fract_pair.stream v n = some ifp_n β§ ifp_n.fr β 0
β§ int_fract_pair.of ifp_n.frβ»ΒΉ = ifp_succ_n, from
int_fract_pair.succ_nth_stream_eq_some_iff.elim_left succ_nth_stream_eq,
let denom' := conts.b * (pred_conts.b + ifp_n.frβ»ΒΉ * conts.b),
-- now we can use `sub_convergents_eq` to simplify our goal
suffices : |(-1)^n / denom'| β€ 1 / denom, by
{ have : v - g.convergents n = (-1)^n / denom', by
{ -- apply `sub_convergens_eq` and simplify the result
have tmp, from sub_convergents_eq stream_nth_eq,
delta at tmp,
simp only [stream_nth_fr_ne_zero, conts_eq.symm, pred_conts_eq.symm] at tmp,
rw tmp,
simp only [denom'],
ring,
ac_refl },
rwa this },
-- derive some tedious inequalities that we need to rewrite our goal
have nextConts_b_ineq : (fib (n + 2) : K) β€ (pred_conts.b + gp.b * conts.b), by
{ have : (fib (n + 2) : K) β€ nextConts.b, from
fib_le_of_continuants_aux_b (or.inr not_terminated_at_n),
rwa [nextConts_b_eq] at this },
have conts_b_ineq : (fib (n + 1) : K) β€ conts.b, by
{ have : Β¬g.terminated_at (n - 1), from mt (terminated_stable n.pred_le) not_terminated_at_n,
exact (fib_le_of_continuants_aux_b $ or.inr this) },
have zero_lt_conts_b : 0 < conts.b, by
{ have : (0 : K) < fib (n + 1), by
exact_mod_cast (fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm)),
exact (lt_of_lt_of_le this conts_b_ineq) },
-- `denom'` is positive, so we can remove `|β¬|` from our goal
suffices : 1 / denom' β€ 1 / denom, by
{ have : |(-1)^n / denom'| = 1 / denom', by
{ suffices : 1 / |denom'| = 1 / denom', by rwa [abs_div, (abs_neg_one_pow n)],
have : 0 < denom', by
{ have : 0 β€ pred_conts.b, by
{ have : (fib n : K) β€ pred_conts.b, by
{ have : Β¬g.terminated_at (n - 2), from
mt (terminated_stable (n.sub_le 2)) not_terminated_at_n,
exact (fib_le_of_continuants_aux_b $ or.inr this) },
exact le_trans (by exact_mod_cast (fib n).zero_le) this },
have : 0 < ifp_n.frβ»ΒΉ, by
{ have zero_le_ifp_n_fract : 0 β€ ifp_n.fr, from
int_fract_pair.nth_stream_fr_nonneg stream_nth_eq,
exact inv_pos.elim_right
(lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm) },
any_goals { repeat { apply mul_pos <|> apply add_pos_of_nonneg_of_pos } }; assumption },
rwa (abs_of_pos this) },
rwa this },
suffices : 0 < denom β§ denom β€ denom', from
div_le_div_of_le_left zero_le_one this.left this.right,
split,
{ have : 0 < pred_conts.b + gp.b * conts.b, from
lt_of_lt_of_le
(by exact_mod_cast (fib_pos (lt_of_le_of_ne n.succ.succ.zero_le n.succ.succ_ne_zero.symm)))
nextConts_b_ineq,
solve_by_elim [mul_pos] },
{ -- we can cancel multiplication by `conts.b` and addition with `pred_conts.b`
suffices : gp.b * conts.b β€ ifp_n.frβ»ΒΉ * conts.b, from
((mul_le_mul_left zero_lt_conts_b).elim_right $
(add_le_add_iff_left pred_conts.b).elim_right this),
suffices : (ifp_succ_n.b : K) * conts.b β€ ifp_n.frβ»ΒΉ * conts.b, by rwa [βifp_succ_n_b_eq_gp_b],
have : (ifp_succ_n.b : K) β€ ifp_n.frβ»ΒΉ, from
int_fract_pair.succ_nth_stream_b_le_nth_stream_fr_inv stream_nth_eq succ_nth_stream_eq,
have : 0 β€ conts.b, from le_of_lt zero_lt_conts_b,
mono }
end
/--
Shows that `|v - Aβ / Bβ| β€ 1 / (bβ * Bβ * Bβ)`. This bound is worse than the one shown in
`gcf.abs_sub_convergents_le`, but sometimes it is easier to apply and sufficient for one's use case.
-/
lemma abs_sub_convergents_le' {b : K}
(nth_part_denom_eq : (gcf.of v).partial_denominators.nth n = some b) :
|v - (gcf.of v).convergents n|
β€ 1 / (b * ((gcf.of v).denominators n) * ((gcf.of v).denominators n)) :=
begin
let g := gcf.of v,
let B := g.denominators n,
let nB := g.denominators (n + 1),
have not_terminated_at_n : Β¬g.terminated_at n, by
{ have : g.partial_denominators.nth n β none, by simp [nth_part_denom_eq],
exact (not_iff_not_of_iff terminated_at_iff_part_denom_none).elim_right this },
suffices : 1 / (B * nB) β€ (1 : K) / (b * B * B), by
{ have : |v - g.convergents n| β€ 1 / (B * nB), from abs_sub_convergents_le not_terminated_at_n,
transitivity;
assumption },
-- derive some inequalities needed to show the claim
have zero_lt_B : 0 < B, by
{ have : (fib (n + 1) : K) β€ B, from
succ_nth_fib_le_of_nth_denom (or.inr $
mt (terminated_stable n.pred_le) not_terminated_at_n),
exact (lt_of_lt_of_le
(by exact_mod_cast (fib_pos (lt_of_le_of_ne n.succ.zero_le n.succ_ne_zero.symm))) this) },
have denoms_ineq : b * B * B β€ B * nB, by
{ have : b * B β€ nB, from le_of_succ_nth_denom nth_part_denom_eq,
rwa [(mul_comm B nB), (mul_le_mul_right zero_lt_B)] },
have : (0 : K) < b * B * B, by
{ have : 0 < b, from lt_of_lt_of_le zero_lt_one (of_one_le_nth_part_denom nth_part_denom_eq),
any_goals { repeat { apply mul_pos } }; assumption },
exact (div_le_div_of_le_left zero_le_one this denoms_ineq)
end
end error_term
end generalized_continued_fraction
|
524d15bc5610df413b8fffccf2ceb5361b78c198
|
bb31430994044506fa42fd667e2d556327e18dfe
|
/src/combinatorics/simple_graph/subgraph.lean
|
e1a67790ddd9b413fea1e3709beec8e58685ad1b
|
[
"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
| 34,531
|
lean
|
/-
Copyright (c) 2021 Hunter Monroe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hunter Monroe, Kyle Miller, Alena Gusakov
-/
import combinatorics.simple_graph.basic
/-!
# Subgraphs of a simple graph
A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the
endpoints of each edge are present in the vertex subset. The edge subset is formalized as a
sub-relation of the adjacency relation of the simple graph.
## Main definitions
* `subgraph G` is the type of subgraphs of a `G : simple_graph`
* `subgraph.neighbor_set`, `subgraph.incidence_set`, and `subgraph.degree` are like their
`simple_graph` counterparts, but they refer to vertices from `G` to avoid subtype coercions.
* `subgraph.coe` is the coercion from a `G' : subgraph G` to a `simple_graph G'.verts`.
(This cannot be a `has_coe` instance since the destination type depends on `G'`.)
* `subgraph.is_spanning` for whether a subgraph is a spanning subgraph and
`subgraph.is_induced` for whether a subgraph is an induced subgraph.
* Instances for `lattice (subgraph G)` and `bounded_order (subgraph G)`.
* `simple_graph.to_subgraph`: If a `simple_graph` is a subgraph of another, then you can turn it
into a member of the larger graph's `simple_graph.subgraph` type.
* Graph homomorphisms from a subgraph to a graph (`subgraph.map_top`) and between subgraphs
(`subgraph.map`).
## Implementation notes
* Recall that subgraphs are not determined by their vertex sets, so `set_like` does not apply to
this kind of subobject.
## Todo
* Images of graph homomorphisms as subgraphs.
-/
universes u v
namespace simple_graph
/-- A subgraph of a `simple_graph` is a subset of vertices along with a restriction of the adjacency
relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice.
Thinking of `V β V β Prop` as `set (V Γ V)`, a set of darts (i.e., half-edges), then
`subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/
@[ext]
structure subgraph {V : Type u} (G : simple_graph V) :=
(verts : set V)
(adj : V β V β Prop)
(adj_sub : β {v w : V}, adj v w β G.adj v w)
(edge_vert : β {v w : V}, adj v w β v β verts)
(symm : symmetric adj . obviously)
variables {V : Type u} {W : Type v}
/-- The one-vertex subgraph. -/
@[simps]
protected def singleton_subgraph (G : simple_graph V) (v : V) : G.subgraph :=
{ verts := {v},
adj := β₯,
adj_sub := by simp [-set.bot_eq_empty],
edge_vert := by simp [-set.bot_eq_empty] }
/-- The one-edge subgraph. -/
@[simps]
def subgraph_of_adj (G : simple_graph V) {v w : V} (hvw : G.adj v w) : G.subgraph :=
{ verts := {v, w},
adj := Ξ» a b, β¦(v, w)β§ = β¦(a, b)β§,
adj_sub := Ξ» a b h, by { rw [β G.mem_edge_set, β h], exact hvw },
edge_vert := Ξ» a b h, by { apply_fun (Ξ» e, a β e) at h, simpa using h } }
namespace subgraph
variables {G : simple_graph V}
protected lemma loopless (G' : subgraph G) : irreflexive G'.adj :=
Ξ» v h, G.loopless v (G'.adj_sub h)
lemma adj_comm (G' : subgraph G) (v w : V) : G'.adj v w β G'.adj w v :=
β¨Ξ» x, G'.symm x, Ξ» x, G'.symm xβ©
@[symm] lemma adj_symm (G' : subgraph G) {u v : V} (h : G'.adj u v) : G'.adj v u := G'.symm h
protected lemma adj.symm {G' : subgraph G} {u v : V} (h : G'.adj u v) : G'.adj v u := G'.symm h
protected lemma adj.adj_sub {H : G.subgraph} {u v : V} (h : H.adj u v) : G.adj u v := H.adj_sub h
protected lemma adj.fst_mem {H : G.subgraph} {u v : V} (h : H.adj u v) : u β H.verts :=
H.edge_vert h
protected lemma adj.snd_mem {H : G.subgraph} {u v : V} (h : H.adj u v) : v β H.verts :=
h.symm.fst_mem
protected lemma adj.ne {H : G.subgraph} {u v : V} (h : H.adj u v) : u β v := h.adj_sub.ne
/-- Coercion from `G' : subgraph G` to a `simple_graph β₯G'.verts`. -/
@[simps] protected def coe (G' : subgraph G) : simple_graph G'.verts :=
{ adj := Ξ» v w, G'.adj v w,
symm := Ξ» v w h, G'.symm h,
loopless := Ξ» v h, loopless G v (G'.adj_sub h) }
@[simp] lemma coe_adj_sub (G' : subgraph G) (u v : G'.verts) (h : G'.coe.adj u v) : G.adj u v :=
G'.adj_sub h
/- Given `h : H.adj u v`, then `h.coe : H.coe.adj β¨u, _β© β¨v, _β©`. -/
protected lemma adj.coe {H : G.subgraph} {u v : V} (h : H.adj u v) :
H.coe.adj β¨u, H.edge_vert hβ© β¨v, H.edge_vert h.symmβ© := h
/-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/
def is_spanning (G' : subgraph G) : Prop := β (v : V), v β G'.verts
lemma is_spanning_iff {G' : subgraph G} : G'.is_spanning β G'.verts = set.univ :=
set.eq_univ_iff_forall.symm
/-- Coercion from `subgraph G` to `simple_graph V`. If `G'` is a spanning
subgraph, then `G'.spanning_coe` yields an isomorphic graph.
In general, this adds in all vertices from `V` as isolated vertices. -/
@[simps] protected def spanning_coe (G' : subgraph G) : simple_graph V :=
{ adj := G'.adj,
symm := G'.symm,
loopless := Ξ» v hv, G.loopless v (G'.adj_sub hv) }
@[simp] lemma adj.of_spanning_coe {G' : subgraph G} {u v : G'.verts}
(h : G'.spanning_coe.adj u v) : G.adj u v := G'.adj_sub h
/-- `spanning_coe` is equivalent to `coe` for a subgraph that `is_spanning`. -/
@[simps] def spanning_coe_equiv_coe_of_spanning (G' : subgraph G) (h : G'.is_spanning) :
G'.spanning_coe βg G'.coe :=
{ to_fun := Ξ» v, β¨v, h vβ©,
inv_fun := Ξ» v, v,
left_inv := Ξ» v, rfl,
right_inv := Ξ» β¨v, hvβ©, rfl,
map_rel_iff' := Ξ» v w, iff.rfl }
/-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if
they are adjacent in `G`. -/
def is_induced (G' : subgraph G) : Prop :=
β {v w : V}, v β G'.verts β w β G'.verts β G.adj v w β G'.adj v w
/-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/
def support (H : subgraph G) : set V := rel.dom H.adj
lemma mem_support (H : subgraph G) {v : V} : v β H.support β β w, H.adj v w := iff.rfl
lemma support_subset_verts (H : subgraph G) : H.support β H.verts := Ξ» v β¨w, hβ©, H.edge_vert h
/-- `G'.neighbor_set v` is the set of vertices adjacent to `v` in `G'`. -/
def neighbor_set (G' : subgraph G) (v : V) : set V := set_of (G'.adj v)
lemma neighbor_set_subset (G' : subgraph G) (v : V) : G'.neighbor_set v β G.neighbor_set v :=
Ξ» w h, G'.adj_sub h
lemma neighbor_set_subset_verts (G' : subgraph G) (v : V) : G'.neighbor_set v β G'.verts :=
Ξ» _ h, G'.edge_vert (adj_symm G' h)
@[simp] lemma mem_neighbor_set (G' : subgraph G) (v w : V) : w β G'.neighbor_set v β G'.adj v w :=
iff.rfl
/-- A subgraph as a graph has equivalent neighbor sets. -/
def coe_neighbor_set_equiv {G' : subgraph G} (v : G'.verts) :
G'.coe.neighbor_set v β G'.neighbor_set v :=
{ to_fun := Ξ» w, β¨w, by { obtain β¨w', hw'β© := w, simpa using hw' }β©,
inv_fun := Ξ» w, β¨β¨w, G'.edge_vert (G'.adj_symm w.2)β©, by simpa using w.2β©,
left_inv := Ξ» w, by simp,
right_inv := Ξ» w, by simp }
/-- The edge set of `G'` consists of a subset of edges of `G`. -/
def edge_set (G' : subgraph G) : set (sym2 V) := sym2.from_rel G'.symm
lemma edge_set_subset (G' : subgraph G) : G'.edge_set β G.edge_set :=
Ξ» e, quotient.ind (Ξ» e h, G'.adj_sub h) e
@[simp]
lemma mem_edge_set {G' : subgraph G} {v w : V} : β¦(v, w)β§ β G'.edge_set β G'.adj v w := iff.rfl
lemma mem_verts_if_mem_edge {G' : subgraph G} {e : sym2 V} {v : V}
(he : e β G'.edge_set) (hv : v β e) : v β G'.verts :=
begin
refine quotient.ind (Ξ» e he hv, _) e he hv,
cases e with v w,
simp only [mem_edge_set] at he,
cases sym2.mem_iff.mp hv with h h; subst h,
{ exact G'.edge_vert he, },
{ exact G'.edge_vert (G'.symm he), },
end
/-- The `incidence_set` is the set of edges incident to a given vertex. -/
def incidence_set (G' : subgraph G) (v : V) : set (sym2 V) := {e β G'.edge_set | v β e}
lemma incidence_set_subset_incidence_set (G' : subgraph G) (v : V) :
G'.incidence_set v β G.incidence_set v :=
Ξ» e h, β¨G'.edge_set_subset h.1, h.2β©
lemma incidence_set_subset (G' : subgraph G) (v : V) : G'.incidence_set v β G'.edge_set :=
Ξ» _ h, h.1
/-- Give a vertex as an element of the subgraph's vertex type. -/
@[reducible]
def vert (G' : subgraph G) (v : V) (h : v β G'.verts) : G'.verts := β¨v, hβ©
/--
Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities.
See Note [range copy pattern].
-/
def copy (G' : subgraph G)
(V'' : set V) (hV : V'' = G'.verts)
(adj' : V β V β Prop) (hadj : adj' = G'.adj) :
subgraph G :=
{ verts := V'',
adj := adj',
adj_sub := Ξ» _ _, hadj.symm βΈ G'.adj_sub,
edge_vert := Ξ» _ _, hV.symm βΈ hadj.symm βΈ G'.edge_vert,
symm := hadj.symm βΈ G'.symm }
lemma copy_eq (G' : subgraph G)
(V'' : set V) (hV : V'' = G'.verts)
(adj' : V β V β Prop) (hadj : adj' = G'.adj) :
G'.copy V'' hV adj' hadj = G' :=
subgraph.ext _ _ hV hadj
/-- The union of two subgraphs. -/
def union (x y : subgraph G) : subgraph G :=
{ verts := x.verts βͺ y.verts,
adj := x.adj β y.adj,
adj_sub := Ξ» v w h, or.cases_on h (Ξ» h, x.adj_sub h) (Ξ» h, y.adj_sub h),
edge_vert := Ξ» v w h, or.cases_on h (Ξ» h, or.inl (x.edge_vert h)) (Ξ» h, or.inr (y.edge_vert h)),
symm := Ξ» v w h, by rwa [pi.sup_apply, pi.sup_apply, x.adj_comm, y.adj_comm] }
/-- The intersection of two subgraphs. -/
def inter (x y : subgraph G) : subgraph G :=
{ verts := x.verts β© y.verts,
adj := x.adj β y.adj,
adj_sub := Ξ» v w h, x.adj_sub h.1,
edge_vert := Ξ» v w h, β¨x.edge_vert h.1, y.edge_vert h.2β©,
symm := Ξ» v w h, by rwa [pi.inf_apply, pi.inf_apply, x.adj_comm, y.adj_comm] }
/-- The `top` subgraph is `G` as a subgraph of itself. -/
def top : subgraph G :=
{ verts := set.univ,
adj := G.adj,
adj_sub := Ξ» v w h, h,
edge_vert := Ξ» v w h, set.mem_univ v,
symm := G.symm }
/-- The `bot` subgraph is the subgraph with no vertices or edges. -/
def bot : subgraph G :=
{ verts := β
,
adj := β₯,
adj_sub := Ξ» v w h, false.rec _ h,
edge_vert := Ξ» v w h, false.rec _ h,
symm := Ξ» u v h, h }
/-- The relation that one subgraph is a subgraph of another. -/
def is_subgraph (x y : subgraph G) : Prop := x.verts β y.verts β§ β β¦v w : Vβ¦, x.adj v w β y.adj v w
instance : lattice (subgraph G) :=
{ le := is_subgraph,
sup := union,
inf := inter,
le_refl := Ξ» x, β¨rfl.subset, Ξ» _ _ h, hβ©,
le_trans := Ξ» x y z hxy hyz, β¨hxy.1.trans hyz.1, Ξ» _ _ h, hyz.2 (hxy.2 h)β©,
le_antisymm := begin
intros x y hxy hyx,
ext1 v,
exact set.subset.antisymm hxy.1 hyx.1,
ext v w,
exact iff.intro (Ξ» h, hxy.2 h) (Ξ» h, hyx.2 h),
end,
sup_le := Ξ» x y z hxy hyz,
β¨set.union_subset hxy.1 hyz.1,
(Ξ» v w h, h.cases_on (Ξ» h, hxy.2 h) (Ξ» h, hyz.2 h))β©,
le_sup_left := Ξ» x y, β¨set.subset_union_left x.verts y.verts, (Ξ» v w h, or.inl h)β©,
le_sup_right := Ξ» x y, β¨set.subset_union_right x.verts y.verts, (Ξ» v w h, or.inr h)β©,
le_inf := Ξ» x y z hxy hyz, β¨set.subset_inter hxy.1 hyz.1, (Ξ» v w h, β¨hxy.2 h, hyz.2 hβ©)β©,
inf_le_left := Ξ» x y, β¨set.inter_subset_left x.verts y.verts, (Ξ» v w h, h.1)β©,
inf_le_right := Ξ» x y, β¨set.inter_subset_right x.verts y.verts, (Ξ» v w h, h.2)β© }
instance : bounded_order (subgraph G) :=
{ top := top,
bot := bot,
le_top := Ξ» x, β¨set.subset_univ _, (Ξ» v w h, x.adj_sub h)β©,
bot_le := Ξ» x, β¨set.empty_subset _, (Ξ» v w h, false.rec _ h)β© }
@[simps] instance subgraph_inhabited : inhabited (subgraph G) := β¨β₯β©
-- TODO simp lemmas for the other lattice operations on subgraphs
@[simp] lemma top_verts : (β€ : subgraph G).verts = set.univ := rfl
@[simp] lemma top_adj_iff {v w : V} : (β€ : subgraph G).adj v w β G.adj v w := iff.rfl
@[simp] lemma bot_verts : (β₯ : subgraph G).verts = β
:= rfl
@[simp] lemma not_bot_adj {v w : V} : Β¬(β₯ : subgraph G).adj v w := not_false
@[simp] lemma inf_adj {Hβ Hβ : subgraph G} {v w : V} :
(Hβ β Hβ).adj v w β Hβ.adj v w β§ Hβ.adj v w := iff.rfl
@[simp] lemma sup_adj {Hβ Hβ : subgraph G} {v w : V} :
(Hβ β Hβ).adj v w β Hβ.adj v w β¨ Hβ.adj v w := iff.rfl
@[simp] lemma verts_sup {H H' : G.subgraph} : (H β H').verts = H.verts βͺ H'.verts := rfl
@[simp] lemma verts_inf {H H' : G.subgraph} : (H β H').verts = H.verts β© H'.verts := rfl
lemma neighbor_set_sup {H H' : G.subgraph} (v : V) :
(H β H').neighbor_set v = H.neighbor_set v βͺ H'.neighbor_set v :=
by { ext w, simp }
lemma neighbor_set_inf {H H' : G.subgraph} (v : V) :
(H β H').neighbor_set v = H.neighbor_set v β© H'.neighbor_set v :=
by { ext w, simp }
@[simp] lemma edge_set_top : (β€ : subgraph G).edge_set = G.edge_set := rfl
@[simp] lemma edge_set_bot : (β₯ : subgraph G).edge_set = β
:=
set.ext $ sym2.ind (by simp)
@[simp] lemma edge_set_inf {Hβ Hβ : subgraph G} : (Hβ β Hβ).edge_set = Hβ.edge_set β© Hβ.edge_set :=
set.ext $ sym2.ind (by simp)
@[simp] lemma edge_set_sup {Hβ Hβ : subgraph G} : (Hβ β Hβ).edge_set = Hβ.edge_set βͺ Hβ.edge_set :=
set.ext $ sym2.ind (by simp)
@[simp] lemma spanning_coe_top : (β€ : subgraph G).spanning_coe = G :=
by { ext, refl }
@[simp] lemma spanning_coe_bot : (β₯ : subgraph G).spanning_coe = β₯ := rfl
/-- Turn a subgraph of a `simple_graph` into a member of its subgraph type. -/
@[simps] def _root_.simple_graph.to_subgraph (H : simple_graph V) (h : H β€ G) : G.subgraph :=
{ verts := set.univ,
adj := H.adj,
adj_sub := h,
edge_vert := Ξ» v w h, set.mem_univ v,
symm := H.symm }
lemma support_mono {H H' : subgraph G} (h : H β€ H') : H.support β H'.support :=
rel.dom_mono h.2
lemma _root_.simple_graph.to_subgraph.is_spanning (H : simple_graph V) (h : H β€ G) :
(H.to_subgraph h).is_spanning := set.mem_univ
lemma spanning_coe_le_of_le {H H' : subgraph G} (h : H β€ H') :
H.spanning_coe β€ H'.spanning_coe := h.2
/-- The top of the `subgraph G` lattice is equivalent to the graph itself. -/
def top_equiv : (β€ : subgraph G).coe βg G :=
{ to_fun := Ξ» v, βv,
inv_fun := Ξ» v, β¨v, trivialβ©,
left_inv := Ξ» β¨v, _β©, rfl,
right_inv := Ξ» v, rfl,
map_rel_iff' := Ξ» a b, iff.rfl }
/-- The bottom of the `subgraph G` lattice is equivalent to the empty graph on the empty
vertex type. -/
def bot_equiv : (β₯ : subgraph G).coe βg (β₯ : simple_graph empty) :=
{ to_fun := Ξ» v, v.property.elim,
inv_fun := Ξ» v, v.elim,
left_inv := Ξ» β¨_, hβ©, h.elim,
right_inv := Ξ» v, v.elim,
map_rel_iff' := Ξ» a b, iff.rfl }
lemma edge_set_mono {Hβ Hβ : subgraph G} (h : Hβ β€ Hβ) : Hβ.edge_set β€ Hβ.edge_set :=
Ξ» e, sym2.ind h.2 e
lemma _root_.disjoint.edge_set {Hβ Hβ : subgraph G}
(h : disjoint Hβ Hβ) : disjoint Hβ.edge_set Hβ.edge_set :=
disjoint_iff_inf_le.mpr $ by simpa using edge_set_mono h.le_bot
/-- Graph homomorphisms induce a covariant function on subgraphs. -/
@[simps]
protected def map {G' : simple_graph W} (f : G βg G') (H : G.subgraph) : G'.subgraph :=
{ verts := f '' H.verts,
adj := relation.map H.adj f f,
adj_sub := by { rintro _ _ β¨u, v, h, rfl, rflβ©, exact f.map_rel (H.adj_sub h) },
edge_vert := by { rintro _ _ β¨u, v, h, rfl, rflβ©, exact set.mem_image_of_mem _ (H.edge_vert h) },
symm := by { rintro _ _ β¨u, v, h, rfl, rflβ©, exact β¨v, u, H.symm h, rfl, rflβ© } }
lemma map_monotone {G' : simple_graph W} (f : G βg G') : monotone (subgraph.map f) :=
begin
intros H H' h,
split,
{ intro,
simp only [map_verts, set.mem_image, forall_exists_index, and_imp],
rintro v hv rfl,
exact β¨_, h.1 hv, rflβ© },
{ rintros _ _ β¨u, v, ha, rfl, rflβ©,
exact β¨_, _, h.2 ha, rfl, rflβ© }
end
lemma map_sup {G : simple_graph V} {G' : simple_graph W} (f : G βg G')
{H H' : G.subgraph} :
(H β H').map f = H.map f β H'.map f :=
begin
ext1,
{ simp only [set.image_union, map_verts, verts_sup]},
{ ext,
simp only [relation.map, map_adj, sup_adj],
split,
{ rintro β¨a, b, h|h, rfl, rflβ©,
{ exact or.inl β¨_, _, h, rfl, rflβ© },
{ exact or.inr β¨_, _, h, rfl, rflβ© } },
{ rintro (β¨a, b, h, rfl, rflβ©|β¨a, b, h, rfl, rflβ©),
{ exact β¨_, _, or.inl h, rfl, rflβ© },
{ exact β¨_, _, or.inr h, rfl, rflβ© } } },
end
/-- Graph homomorphisms induce a contravariant function on subgraphs. -/
@[simps]
protected def comap {G' : simple_graph W} (f : G βg G') (H : G'.subgraph) : G.subgraph :=
{ verts := f β»ΒΉ' H.verts,
adj := Ξ» u v, G.adj u v β§ H.adj (f u) (f v),
adj_sub := by { rintros v w β¨ga, haβ©, exact ga },
edge_vert := by { rintros v w β¨ga, haβ©, simp [H.edge_vert ha] } }
lemma comap_monotone {G' : simple_graph W} (f : G βg G') : monotone (subgraph.comap f) :=
begin
intros H H' h,
split,
{ intro,
simp only [comap_verts, set.mem_preimage],
apply h.1, },
{ intros v w,
simp only [comap_adj, and_imp, true_and] { contextual := tt },
intro,
apply h.2, }
end
lemma map_le_iff_le_comap {G' : simple_graph W} (f : G βg G') (H : G.subgraph) (H' : G'.subgraph) :
H.map f β€ H' β H β€ H'.comap f :=
begin
refine β¨Ξ» h, β¨Ξ» v hv, _, Ξ» v w hvw, _β©, Ξ» h, β¨Ξ» v, _, Ξ» v w, _β©β©,
{ simp only [comap_verts, set.mem_preimage],
exact h.1 β¨v, hv, rflβ©, },
{ simp only [H.adj_sub hvw, comap_adj, true_and],
exact h.2 β¨v, w, hvw, rfl, rflβ©, },
{ simp only [map_verts, set.mem_image, forall_exists_index, and_imp],
rintro w hw rfl,
exact h.1 hw, },
{ simp only [relation.map, map_adj, forall_exists_index, and_imp],
rintros u u' hu rfl rfl,
have := h.2 hu,
simp only [comap_adj] at this,
exact this.2, }
end
/-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of
the subgraphs as graphs. -/
@[simps]
def inclusion {x y : subgraph G} (h : x β€ y) : x.coe βg y.coe :=
{ to_fun := Ξ» v, β¨βv, and.left h v.propertyβ©,
map_rel' := Ξ» v w hvw, h.2 hvw }
lemma inclusion.injective {x y : subgraph G} (h : x β€ y) : function.injective (inclusion h) :=
Ξ» v w h, by { simp only [inclusion, rel_hom.coe_fn_mk, subtype.mk_eq_mk] at h, exact subtype.ext h }
/-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/
@[simps]
protected def hom (x : subgraph G) : x.coe βg G :=
{ to_fun := Ξ» v, v,
map_rel' := Ξ» v w hvw, x.adj_sub hvw }
lemma hom.injective {x : subgraph G} : function.injective x.hom :=
Ξ» v w h, subtype.ext h
/-- There is an induced injective homomorphism of a subgraph of `G` as
a spanning subgraph into `G`. -/
@[simps] def spanning_hom (x : subgraph G) : x.spanning_coe βg G :=
{ to_fun := id,
map_rel' := Ξ» v w hvw, x.adj_sub hvw }
lemma spanning_hom.injective {x : subgraph G} : function.injective x.spanning_hom :=
Ξ» v w h, h
lemma neighbor_set_subset_of_subgraph {x y : subgraph G} (h : x β€ y) (v : V) :
x.neighbor_set v β y.neighbor_set v :=
Ξ» w h', h.2 h'
instance neighbor_set.decidable_pred (G' : subgraph G) [h : decidable_rel G'.adj] (v : V) :
decidable_pred (β G'.neighbor_set v) := h v
/-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/
instance finite_at {G' : subgraph G} (v : G'.verts) [decidable_rel G'.adj]
[fintype (G.neighbor_set v)] : fintype (G'.neighbor_set v) :=
set.fintype_subset (G.neighbor_set v) (G'.neighbor_set_subset v)
/-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph.
This is not an instance because `G''` cannot be inferred. -/
def finite_at_of_subgraph {G' G'' : subgraph G} [decidable_rel G'.adj]
(h : G' β€ G'') (v : G'.verts) [hf : fintype (G''.neighbor_set v)] :
fintype (G'.neighbor_set v) :=
set.fintype_subset (G''.neighbor_set v) (neighbor_set_subset_of_subgraph h v)
instance (G' : subgraph G) [fintype G'.verts]
(v : V) [decidable_pred (β G'.neighbor_set v)] : fintype (G'.neighbor_set v) :=
set.fintype_subset G'.verts (neighbor_set_subset_verts G' v)
instance coe_finite_at {G' : subgraph G} (v : G'.verts) [fintype (G'.neighbor_set v)] :
fintype (G'.coe.neighbor_set v) :=
fintype.of_equiv _ (coe_neighbor_set_equiv v).symm
lemma is_spanning.card_verts [fintype V] {G' : subgraph G} [fintype G'.verts]
(h : G'.is_spanning) : G'.verts.to_finset.card = fintype.card V :=
by { rw is_spanning_iff at h, simpa [h] }
/-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/
def degree (G' : subgraph G) (v : V) [fintype (G'.neighbor_set v)] : β :=
fintype.card (G'.neighbor_set v)
lemma finset_card_neighbor_set_eq_degree {G' : subgraph G} {v : V} [fintype (G'.neighbor_set v)] :
(G'.neighbor_set v).to_finset.card = G'.degree v := by rw [degree, set.to_finset_card]
lemma degree_le (G' : subgraph G) (v : V)
[fintype (G'.neighbor_set v)] [fintype (G.neighbor_set v)] :
G'.degree v β€ G.degree v :=
begin
rw βcard_neighbor_set_eq_degree,
exact set.card_le_of_subset (G'.neighbor_set_subset v),
end
lemma degree_le' (G' G'' : subgraph G) (h : G' β€ G'') (v : V)
[fintype (G'.neighbor_set v)] [fintype (G''.neighbor_set v)] :
G'.degree v β€ G''.degree v :=
set.card_le_of_subset (neighbor_set_subset_of_subgraph h v)
@[simp] lemma coe_degree (G' : subgraph G) (v : G'.verts)
[fintype (G'.coe.neighbor_set v)] [fintype (G'.neighbor_set v)] :
G'.coe.degree v = G'.degree v :=
begin
rw βcard_neighbor_set_eq_degree,
exact fintype.card_congr (coe_neighbor_set_equiv v),
end
@[simp] lemma degree_spanning_coe {G' : G.subgraph} (v : V) [fintype (G'.neighbor_set v)]
[fintype (G'.spanning_coe.neighbor_set v)] :
G'.spanning_coe.degree v = G'.degree v :=
by { rw [β card_neighbor_set_eq_degree, subgraph.degree], congr }
lemma degree_eq_one_iff_unique_adj {G' : subgraph G} {v : V} [fintype (G'.neighbor_set v)] :
G'.degree v = 1 β β! (w : V), G'.adj v w :=
begin
rw [β finset_card_neighbor_set_eq_degree, finset.card_eq_one, finset.singleton_iff_unique_mem],
simp only [set.mem_to_finset, mem_neighbor_set],
end
end subgraph
section mk_properties
/-! ### Properties of `singleton_subgraph` and `subgraph_of_adj` -/
variables {G : simple_graph V} {G' : simple_graph W}
instance nonempty_singleton_subgraph_verts (v : V) : nonempty (G.singleton_subgraph v).verts :=
β¨β¨v, set.mem_singleton vβ©β©
@[simp] lemma singleton_subgraph_le_iff (v : V) (H : G.subgraph) :
G.singleton_subgraph v β€ H β v β H.verts :=
begin
refine β¨Ξ» h, h.1 (set.mem_singleton v), _β©,
intro h,
split,
{ simp [h] },
{ simp [-set.bot_eq_empty] }
end
@[simp] lemma map_singleton_subgraph (f : G βg G') {v : V} :
subgraph.map f (G.singleton_subgraph v) = G'.singleton_subgraph (f v) :=
by ext; simp only [relation.map, subgraph.map_adj, singleton_subgraph_adj, pi.bot_apply,
exists_and_distrib_left, and_iff_left_iff_imp, is_empty.forall_iff, subgraph.map_verts,
singleton_subgraph_verts, set.image_singleton]
@[simp] lemma neighbor_set_singleton_subgraph (v w : V) :
(G.singleton_subgraph v).neighbor_set w = β
:=
by { ext u, refl }
@[simp] lemma edge_set_singleton_subgraph (v : V) :
(G.singleton_subgraph v).edge_set = β
:=
sym2.from_rel_bot
lemma eq_singleton_subgraph_iff_verts_eq (H : G.subgraph) {v : V} :
H = G.singleton_subgraph v β H.verts = {v} :=
begin
refine β¨Ξ» h, by simp [h], Ξ» h, _β©,
ext,
{ rw [h, singleton_subgraph_verts] },
{ simp only [Prop.bot_eq_false, singleton_subgraph_adj, pi.bot_apply, iff_false],
intro ha,
have ha1 := ha.fst_mem,
have ha2 := ha.snd_mem,
rw [h, set.mem_singleton_iff] at ha1 ha2,
subst_vars,
exact ha.ne rfl },
end
instance nonempty_subgraph_of_adj_verts {v w : V} (hvw : G.adj v w) :
nonempty (G.subgraph_of_adj hvw).verts := β¨β¨v, by simpβ©β©
@[simp] lemma edge_set_subgraph_of_adj {v w : V} (hvw : G.adj v w) :
(G.subgraph_of_adj hvw).edge_set = {β¦(v, w)β§} :=
begin
ext e,
refine e.ind _,
simp only [eq_comm, set.mem_singleton_iff, subgraph.mem_edge_set, subgraph_of_adj_adj,
iff_self, forall_2_true_iff],
end
lemma subgraph_of_adj_symm {v w : V} (hvw : G.adj v w) :
G.subgraph_of_adj hvw.symm = G.subgraph_of_adj hvw :=
by ext; simp [or_comm, and_comm]
@[simp] lemma map_subgraph_of_adj (f : G βg G')
{v w : V} (hvw : G.adj v w) :
subgraph.map f (G.subgraph_of_adj hvw) = G'.subgraph_of_adj (f.map_adj hvw) :=
begin
ext,
{ simp only [subgraph.map_verts, subgraph_of_adj_verts, set.mem_image,
set.mem_insert_iff, set.mem_singleton_iff],
split,
{ rintro β¨u, rfl|rfl, rflβ©; simp },
{ rintro (rfl|rfl),
{ use v, simp },
{ use w, simp } } },
{ simp only [relation.map, subgraph.map_adj, subgraph_of_adj_adj, quotient.eq, sym2.rel_iff],
split,
{ rintro β¨a, b, (β¨rfl,rflβ©|β¨rfl,rflβ©), rfl, rflβ©; simp },
{ rintro (β¨rfl,rflβ©|β¨rfl,rflβ©),
{ use [v, w], simp },
{ use [w, v], simp } } }
end
lemma neighbor_set_subgraph_of_adj_subset {u v w : V} (hvw : G.adj v w) :
(G.subgraph_of_adj hvw).neighbor_set u β {v, w} :=
(G.subgraph_of_adj hvw).neighbor_set_subset_verts _
@[simp] lemma neighbor_set_fst_subgraph_of_adj {v w : V} (hvw : G.adj v w) :
(G.subgraph_of_adj hvw).neighbor_set v = {w} :=
begin
ext u,
suffices : w = u β u = w, by simpa [hvw.ne.symm] using this,
rw eq_comm,
end
@[simp] lemma neighbor_set_snd_subgraph_of_adj {v w : V} (hvw : G.adj v w) :
(G.subgraph_of_adj hvw).neighbor_set w = {v} :=
begin
rw subgraph_of_adj_symm hvw.symm,
exact neighbor_set_fst_subgraph_of_adj hvw.symm,
end
@[simp] lemma neighbor_set_subgraph_of_adj_of_ne_of_ne {u v w : V} (hvw : G.adj v w)
(hv : u β v) (hw : u β w) :
(G.subgraph_of_adj hvw).neighbor_set u = β
:=
by { ext, simp [hv.symm, hw.symm] }
lemma neighbor_set_subgraph_of_adj [decidable_eq V] {u v w : V} (hvw : G.adj v w) :
(G.subgraph_of_adj hvw).neighbor_set u =
(if u = v then {w} else β
) βͺ (if u = w then {v} else β
) :=
by split_ifs; subst_vars; simp [*]
lemma singleton_subgraph_fst_le_subgraph_of_adj {u v : V} {h : G.adj u v} :
G.singleton_subgraph u β€ G.subgraph_of_adj h :=
by split; simp [-set.bot_eq_empty]
lemma singleton_subgraph_snd_le_subgraph_of_adj {u v : V} {h : G.adj u v} :
G.singleton_subgraph v β€ G.subgraph_of_adj h :=
by split; simp [-set.bot_eq_empty]
end mk_properties
namespace subgraph
variables {G : simple_graph V}
/-! ### Subgraphs of subgraphs -/
/-- Given a subgraph of a subgraph of `G`, construct a subgraph of `G`. -/
@[reducible]
protected def coe_subgraph {G' : G.subgraph} : G'.coe.subgraph β G.subgraph := subgraph.map G'.hom
/-- Given a subgraph of `G`, restrict it to being a subgraph of another subgraph `G'` by
taking the portion of `G` that intersects `G'`. -/
@[reducible]
protected def restrict {G' : G.subgraph} : G.subgraph β G'.coe.subgraph := subgraph.comap G'.hom
lemma restrict_coe_subgraph {G' : G.subgraph} (G'' : G'.coe.subgraph) :
G''.coe_subgraph.restrict = G'' :=
begin
ext,
{ simp },
{ simp only [relation.map, comap_adj, coe_adj, subtype.coe_prop, hom_apply, map_adj,
set_coe.exists, subtype.coe_mk, exists_and_distrib_right, exists_eq_right_right,
subtype.coe_eta, exists_true_left, exists_eq_right, and_iff_right_iff_imp],
apply G''.adj_sub, }
end
lemma coe_subgraph_injective (G' : G.subgraph) :
function.injective (subgraph.coe_subgraph : G'.coe.subgraph β G.subgraph) :=
function.left_inverse.injective restrict_coe_subgraph
/-! ### Edge deletion -/
/-- Given a subgraph `G'` and a set of vertex pairs, remove all of the corresponding edges
from its edge set, if present.
See also: `simple_graph.delete_edges`. -/
def delete_edges (G' : G.subgraph) (s : set (sym2 V)) : G.subgraph :=
{ verts := G'.verts,
adj := G'.adj \ sym2.to_rel s,
adj_sub := Ξ» a b h', G'.adj_sub h'.1,
edge_vert := Ξ» a b h', G'.edge_vert h'.1,
symm := Ξ» a b, by simp [G'.adj_comm, sym2.eq_swap] }
section delete_edges
variables {G' : G.subgraph} (s : set (sym2 V))
@[simp] lemma delete_edges_verts : (G'.delete_edges s).verts = G'.verts := rfl
@[simp] lemma delete_edges_adj (v w : V) :
(G'.delete_edges s).adj v w β G'.adj v w β§ Β¬ β¦(v, w)β§ β s := iff.rfl
@[simp] lemma delete_edges_delete_edges (s s' : set (sym2 V)) :
(G'.delete_edges s).delete_edges s' = G'.delete_edges (s βͺ s') :=
by ext; simp [and_assoc, not_or_distrib]
@[simp] lemma delete_edges_empty_eq : G'.delete_edges β
= G' :=
by ext; simp
@[simp] lemma delete_edges_spanning_coe_eq :
G'.spanning_coe.delete_edges s = (G'.delete_edges s).spanning_coe :=
by { ext, simp }
lemma delete_edges_coe_eq (s : set (sym2 G'.verts)) :
G'.coe.delete_edges s = (G'.delete_edges (sym2.map coe '' s)).coe :=
begin
ext β¨v, hvβ© β¨w, hwβ©,
simp only [simple_graph.delete_edges_adj, coe_adj, subtype.coe_mk, delete_edges_adj,
set.mem_image, not_exists, not_and, and.congr_right_iff],
intro h,
split,
{ intros hs,
refine sym2.ind _,
rintro β¨v', hv'β© β¨w', hw'β©,
simp only [sym2.map_pair_eq, subtype.coe_mk, quotient.eq],
contrapose!,
rintro (_ | _); simpa [sym2.eq_swap], },
{ intros h' hs,
exact h' _ hs rfl, },
end
lemma coe_delete_edges_eq (s : set (sym2 V)) :
(G'.delete_edges s).coe = G'.coe.delete_edges (sym2.map coe β»ΒΉ' s) :=
by { ext β¨v, hvβ© β¨w, hwβ©, simp }
lemma delete_edges_le : G'.delete_edges s β€ G' :=
by split; simp { contextual := tt }
lemma delete_edges_le_of_le {s s' : set (sym2 V)} (h : s β s') :
G'.delete_edges s' β€ G'.delete_edges s :=
begin
split;
simp only [delete_edges_verts, delete_edges_adj, true_and, and_imp] {contextual := tt},
exact Ξ» v w hvw hs' hs, hs' (h hs),
end
@[simp] lemma delete_edges_inter_edge_set_left_eq :
G'.delete_edges (G'.edge_set β© s) = G'.delete_edges s :=
by ext; simp [imp_false] { contextual := tt }
@[simp] lemma delete_edges_inter_edge_set_right_eq :
G'.delete_edges (s β© G'.edge_set) = G'.delete_edges s :=
by ext; simp [imp_false] { contextual := tt }
lemma coe_delete_edges_le :
(G'.delete_edges s).coe β€ (G'.coe : simple_graph G'.verts) :=
Ξ» v w, by simp { contextual := tt }
lemma spanning_coe_delete_edges_le (G' : G.subgraph) (s : set (sym2 V)) :
(G'.delete_edges s).spanning_coe β€ G'.spanning_coe :=
spanning_coe_le_of_le (delete_edges_le s)
end delete_edges
/-! ### Induced subgraphs -/
/- Given a subgraph, we can change its vertex set while removing any invalid edges, which
gives induced subgraphs. See also `simple_graph.induce` for the `simple_graph` version, which,
unlike for subgraphs, results in a graph with a different vertex type. -/
/-- The induced subgraph of a subgraph. The expectation is that `s β G'.verts` for the usual
notion of an induced subgraph, but, in general, `s` is taken to be the new vertex set and edges
are induced from the subgraph `G'`. -/
@[simps]
def induce (G' : G.subgraph) (s : set V) : G.subgraph :=
{ verts := s,
adj := Ξ» u v, u β s β§ v β s β§ G'.adj u v,
adj_sub := Ξ» u v, by { rintro β¨-, -, haβ©, exact G'.adj_sub ha },
edge_vert := Ξ» u v, by { rintro β¨h, -, -β©, exact h } }
lemma _root_.simple_graph.induce_eq_coe_induce_top (s : set V) :
G.induce s = ((β€ : G.subgraph).induce s).coe :=
by { ext v w, simp }
section induce
variables {G' G'' : G.subgraph} {s s' : set V}
lemma induce_mono (hg : G' β€ G'') (hs : s β s') : G'.induce s β€ G''.induce s' :=
begin
split,
{ simp [hs], },
{ simp only [induce_adj, true_and, and_imp] { contextual := tt },
intros v w hv hw ha,
exact β¨hs hv, hs hw, hg.2 haβ©, },
end
@[mono]
lemma induce_mono_left (hg : G' β€ G'') : G'.induce s β€ G''.induce s := induce_mono hg (by refl)
@[mono]
lemma induce_mono_right (hs : s β s') : G'.induce s β€ G'.induce s' := induce_mono (by refl) hs
@[simp] lemma induce_empty : G'.induce β
= β₯ :=
by ext; simp
@[simp] lemma induce_self_verts : G'.induce G'.verts = G' :=
begin
ext,
{ simp },
{ split;
simp only [induce_adj, implies_true_iff, and_true] {contextual := tt},
exact Ξ» ha, β¨G'.edge_vert ha, G'.edge_vert ha.symmβ© }
end
lemma singleton_subgraph_eq_induce {v : V} :
G.singleton_subgraph v = (β€ : G.subgraph).induce {v} :=
by ext; simp [-set.bot_eq_empty, Prop.bot_eq_false] { contextual := tt }
lemma subgraph_of_adj_eq_induce {v w : V} (hvw : G.adj v w) :
G.subgraph_of_adj hvw = (β€ : G.subgraph).induce {v, w} :=
begin
ext,
{ simp },
{ split,
{ intro h,
simp only [subgraph_of_adj_adj, quotient.eq, sym2.rel_iff] at h,
obtain β¨rfl, rflβ©|β¨rfl, rflβ© := h; simp [hvw, hvw.symm], },
{ intro h,
simp only [induce_adj, set.mem_insert_iff, set.mem_singleton_iff, top_adj_iff] at h,
obtain β¨rfl|rfl, rfl|rfl, haβ© := h;
exact (ha.ne rfl).elim <|> simp } }
end
end induce
/-- Given a subgraph and a set of vertices, delete all the vertices from the subgraph,
if present. Any edges indicent to the deleted vertices are deleted as well. -/
@[reducible] def delete_verts (G' : G.subgraph) (s : set V) : G.subgraph := G'.induce (G'.verts \ s)
section delete_verts
variables {G' : G.subgraph} {s : set V}
lemma delete_verts_verts : (G'.delete_verts s).verts = G'.verts \ s := rfl
lemma delete_verts_adj {u v : V} :
(G'.delete_verts s).adj u v β
u β G'.verts β§ Β¬ u β s β§ v β G'.verts β§ Β¬ v β s β§ G'.adj u v :=
by simp [and_assoc]
@[simp] lemma delete_verts_delete_verts (s s' : set V) :
(G'.delete_verts s).delete_verts s' = G'.delete_verts (s βͺ s') :=
by ext; simp [not_or_distrib, and_assoc] { contextual := tt }
@[simp] lemma delete_verts_empty : G'.delete_verts β
= G' :=
by simp [delete_verts]
lemma delete_verts_le : G'.delete_verts s β€ G' :=
by split; simp [set.diff_subset]
@[mono]
lemma delete_verts_mono {G' G'' : G.subgraph} (h : G' β€ G'') :
G'.delete_verts s β€ G''.delete_verts s :=
induce_mono h (set.diff_subset_diff_left h.1)
@[mono]
lemma delete_verts_anti {s s' : set V} (h : s β s') :
G'.delete_verts s' β€ G'.delete_verts s :=
induce_mono (le_refl _) (set.diff_subset_diff_right h)
@[simp] lemma delete_verts_inter_verts_left_eq :
G'.delete_verts (G'.verts β© s) = G'.delete_verts s :=
by ext; simp [imp_false] { contextual := tt }
@[simp] lemma delete_verts_inter_verts_set_right_eq :
G'.delete_verts (s β© G'.verts) = G'.delete_verts s :=
by ext; simp [imp_false] { contextual := tt }
end delete_verts
end subgraph
end simple_graph
|
1335a26c9fa571af0d82c2731ab75c044f0789a4
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/measure_theory/measure/vector_measure.lean
|
af04f6d6049671c340f8ba00066f21843ccdf6fc
|
[
"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
| 49,770
|
lean
|
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import measure_theory.measure.measure_space
import analysis.complex.basic
/-!
# Vector valued measures
This file defines vector valued measures, which are Ο-additive functions from a set to a add monoid
`M` such that it maps the empty set and non-measurable sets to zero. In the case
that `M = β`, we called the vector measure a signed measure and write `signed_measure Ξ±`.
Similarly, when `M = β`, we call the measure a complex measure and write `complex_measure Ξ±`.
## Main definitions
* `measure_theory.vector_measure` is a vector valued, Ο-additive function that maps the empty
and non-measurable set to zero.
* `measure_theory.vector_measure.map` is the pushforward of a vector measure along a function.
* `measure_theory.vector_measure.restrict` is the restriction of a vector measure on some set.
## Notation
* `v β€[i] w` means that the vector measure `v` restricted on the set `i` is less than or equal
to the vector measure `w` restricted on `i`, i.e. `v.restrict i β€ w.restrict i`.
## Implementation notes
We require all non-measurable sets to be mapped to zero in order for the extensionality lemma
to only compare the underlying functions for measurable sets.
We use `has_sum` instead of `tsum` in the definition of vector measures in comparison to `measure`
since this provides summablity.
## Tags
vector measure, signed measure, complex measure
-/
noncomputable theory
open_locale classical big_operators nnreal ennreal measure_theory
namespace measure_theory
variables {Ξ± Ξ² : Type*} {m : measurable_space Ξ±}
/-- A vector measure on a measurable space `Ξ±` is a Ο-additive `M`-valued function (for some `M`
an add monoid) such that the empty set and non-measurable sets are mapped to zero. -/
structure vector_measure (Ξ± : Type*) [measurable_space Ξ±]
(M : Type*) [add_comm_monoid M] [topological_space M] :=
(measure_of' : set Ξ± β M)
(empty' : measure_of' β
= 0)
(not_measurable' β¦i : set Ξ±β¦ : Β¬ measurable_set i β measure_of' i = 0)
(m_Union' β¦f : β β set Ξ±β¦ :
(β i, measurable_set (f i)) β pairwise (disjoint on f) β
has_sum (Ξ» i, measure_of' (f i)) (measure_of' (β i, f i)))
/-- A `signed_measure` is a `β`-vector measure. -/
abbreviation signed_measure (Ξ± : Type*) [measurable_space Ξ±] := vector_measure Ξ± β
/-- A `complex_measure` is a `β`-vector_measure. -/
abbreviation complex_measure (Ξ± : Type*) [measurable_space Ξ±] := vector_measure Ξ± β
open set measure_theory
namespace vector_measure
section
variables {M : Type*} [add_comm_monoid M] [topological_space M]
include m
instance : has_coe_to_fun (vector_measure Ξ± M) (Ξ» _, set Ξ± β M) :=
β¨vector_measure.measure_of'β©
initialize_simps_projections vector_measure (measure_of' β apply)
@[simp]
lemma measure_of_eq_coe (v : vector_measure Ξ± M) : v.measure_of' = v := rfl
@[simp]
lemma empty (v : vector_measure Ξ± M) : v β
= 0 := v.empty'
lemma not_measurable (v : vector_measure Ξ± M)
{i : set Ξ±} (hi : Β¬ measurable_set i) : v i = 0 := v.not_measurable' hi
lemma m_Union (v : vector_measure Ξ± M) {f : β β set Ξ±}
(hfβ : β i, measurable_set (f i)) (hfβ : pairwise (disjoint on f)) :
has_sum (Ξ» i, v (f i)) (v (β i, f i)) :=
v.m_Union' hfβ hfβ
lemma of_disjoint_Union_nat [t2_space M] (v : vector_measure Ξ± M) {f : β β set Ξ±}
(hfβ : β i, measurable_set (f i)) (hfβ : pairwise (disjoint on f)) :
v (β i, f i) = β' i, v (f i) :=
(v.m_Union hfβ hfβ).tsum_eq.symm
lemma coe_injective : @function.injective (vector_measure Ξ± M) (set Ξ± β M) coe_fn :=
Ξ» v w h, by { cases v, cases w, congr' }
lemma ext_iff' (v w : vector_measure Ξ± M) :
v = w β β i : set Ξ±, v i = w i :=
by rw [β coe_injective.eq_iff, function.funext_iff]
lemma ext_iff (v w : vector_measure Ξ± M) :
v = w β β i : set Ξ±, measurable_set i β v i = w i :=
begin
split,
{ rintro rfl _ _, refl },
{ rw ext_iff',
intros h i,
by_cases hi : measurable_set i,
{ exact h i hi },
{ simp_rw [not_measurable _ hi] } }
end
@[ext] lemma ext {s t : vector_measure Ξ± M}
(h : β i : set Ξ±, measurable_set i β s i = t i) : s = t :=
(ext_iff s t).2 h
variables [t2_space M] {v : vector_measure Ξ± M} {f : β β set Ξ±}
lemma has_sum_of_disjoint_Union [encodable Ξ²] {f : Ξ² β set Ξ±}
(hfβ : β i, measurable_set (f i)) (hfβ : pairwise (disjoint on f)) :
has_sum (Ξ» i, v (f i)) (v (β i, f i)) :=
begin
set g := Ξ» i : β, β (b : Ξ²) (H : b β encodable.decodeβ Ξ² i), f b with hg,
have hgβ : β i, measurable_set (g i),
{ exact Ξ» _, measurable_set.Union (Ξ» b, measurable_set.Union_Prop $ Ξ» _, hfβ b) },
have hgβ : pairwise (disjoint on g),
{ exact encodable.Union_decodeβ_disjoint_on hfβ },
have := v.of_disjoint_Union_nat hgβ hgβ,
rw [hg, encodable.Union_decodeβ] at this,
have hgβ : (Ξ» (i : Ξ²), v (f i)) = (Ξ» i, v (g (encodable.encode i))),
{ ext, rw hg, simp only,
congr, ext y, simp only [exists_prop, mem_Union, option.mem_def],
split,
{ intro hy,
refine β¨x, (encodable.decodeβ_is_partial_inv _ _).2 rfl, hyβ© },
{ rintro β¨b, hbβ, hbββ©,
rw (encodable.decodeβ_is_partial_inv _ _) at hbβ,
rwa β encodable.encode_injective hbβ } },
rw [summable.has_sum_iff, this, β tsum_Union_decodeβ],
{ exact v.empty },
{ rw hgβ, change summable ((Ξ» i, v (g i)) β encodable.encode),
rw function.injective.summable_iff encodable.encode_injective,
{ exact (v.m_Union hgβ hgβ).summable },
{ intros x hx,
convert v.empty,
simp only [Union_eq_empty, option.mem_def, not_exists, mem_range] at β’ hx,
intros i hi,
exact false.elim ((hx i) ((encodable.decodeβ_is_partial_inv _ _).1 hi)) } }
end
lemma of_disjoint_Union [encodable Ξ²] {f : Ξ² β set Ξ±}
(hfβ : β i, measurable_set (f i)) (hfβ : pairwise (disjoint on f)) :
v (β i, f i) = β' i, v (f i) :=
(has_sum_of_disjoint_Union hfβ hfβ).tsum_eq.symm
lemma of_union {A B : set Ξ±}
(h : disjoint A B) (hA : measurable_set A) (hB : measurable_set B) :
v (A βͺ B) = v A + v B :=
begin
rw [union_eq_Union, of_disjoint_Union, tsum_fintype, fintype.sum_bool, cond, cond],
exacts [Ξ» b, bool.cases_on b hB hA, pairwise_disjoint_on_bool.2 h]
end
lemma of_add_of_diff {A B : set Ξ±} (hA : measurable_set A) (hB : measurable_set B)
(h : A β B) : v A + v (B \ A) = v B :=
begin
rw [β of_union disjoint_diff hA (hB.diff hA), union_diff_cancel h],
apply_instance,
end
lemma of_diff {M : Type*} [add_comm_group M]
[topological_space M] [t2_space M] {v : vector_measure Ξ± M}
{A B : set Ξ±} (hA : measurable_set A) (hB : measurable_set B)
(h : A β B) : v (B \ A) = v B - (v A) :=
begin
rw [β of_add_of_diff hA hB h, add_sub_cancel'],
apply_instance,
end
lemma of_diff_of_diff_eq_zero {A B : set Ξ±}
(hA : measurable_set A) (hB : measurable_set B) (h' : v (B \ A) = 0) :
v (A \ B) + v B = v A :=
begin
symmetry,
calc v A = v (A \ B βͺ A β© B) : by simp only [set.diff_union_inter]
... = v (A \ B) + v (A β© B) :
by { rw of_union,
{ rw disjoint.comm,
exact set.disjoint_of_subset_left (A.inter_subset_right B) set.disjoint_diff },
{ exact hA.diff hB },
{ exact hA.inter hB } }
... = v (A \ B) + v (A β© B βͺ B \ A) :
by { rw [of_union, h', add_zero],
{ exact set.disjoint_of_subset_left (A.inter_subset_left B) set.disjoint_diff },
{ exact hA.inter hB },
{ exact hB.diff hA } }
... = v (A \ B) + v B :
by { rw [set.union_comm, set.inter_comm, set.diff_union_inter] }
end
lemma of_Union_nonneg {M : Type*} [topological_space M]
[ordered_add_comm_monoid M] [order_closed_topology M]
{v : vector_measure Ξ± M} (hfβ : β i, measurable_set (f i))
(hfβ : pairwise (disjoint on f)) (hfβ : β i, 0 β€ v (f i)) :
0 β€ v (β i, f i) :=
(v.of_disjoint_Union_nat hfβ hfβ).symm βΈ tsum_nonneg hfβ
lemma of_Union_nonpos {M : Type*} [topological_space M]
[ordered_add_comm_monoid M] [order_closed_topology M]
{v : vector_measure Ξ± M} (hfβ : β i, measurable_set (f i))
(hfβ : pairwise (disjoint on f)) (hfβ : β i, v (f i) β€ 0) :
v (β i, f i) β€ 0 :=
(v.of_disjoint_Union_nat hfβ hfβ).symm βΈ tsum_nonpos hfβ
lemma of_nonneg_disjoint_union_eq_zero {s : signed_measure Ξ±} {A B : set Ξ±}
(h : disjoint A B) (hAβ : measurable_set A) (hBβ : measurable_set B)
(hAβ : 0 β€ s A) (hBβ : 0 β€ s B)
(hAB : s (A βͺ B) = 0) : s A = 0 :=
begin
rw of_union h hAβ hBβ at hAB,
linarith,
apply_instance,
end
lemma of_nonpos_disjoint_union_eq_zero {s : signed_measure Ξ±} {A B : set Ξ±}
(h : disjoint A B) (hAβ : measurable_set A) (hBβ : measurable_set B)
(hAβ : s A β€ 0) (hBβ : s B β€ 0)
(hAB : s (A βͺ B) = 0) : s A = 0 :=
begin
rw of_union h hAβ hBβ at hAB,
linarith,
apply_instance,
end
end
section add_comm_monoid
variables {M : Type*} [add_comm_monoid M] [topological_space M]
include m
instance : has_zero (vector_measure Ξ± M) :=
β¨β¨0, rfl, Ξ» _ _, rfl, Ξ» _ _ _, has_sum_zeroβ©β©
instance : inhabited (vector_measure Ξ± M) := β¨0β©
@[simp] lemma coe_zero : β(0 : vector_measure Ξ± M) = 0 := rfl
lemma zero_apply (i : set Ξ±) : (0 : vector_measure Ξ± M) i = 0 := rfl
variables [has_continuous_add M]
/-- The sum of two vector measure is a vector measure. -/
def add (v w : vector_measure Ξ± M) : vector_measure Ξ± M :=
{ measure_of' := v + w,
empty' := by simp,
not_measurable' := Ξ» _ hi,
by simp [v.not_measurable hi, w.not_measurable hi],
m_Union' := Ξ» f hfβ hfβ,
has_sum.add (v.m_Union hfβ hfβ) (w.m_Union hfβ hfβ) }
instance : has_add (vector_measure Ξ± M) := β¨addβ©
@[simp] lemma coe_add (v w : vector_measure Ξ± M) : β(v + w) = v + w := rfl
lemma add_apply (v w : vector_measure Ξ± M) (i : set Ξ±) :(v + w) i = v i + w i := rfl
instance : add_comm_monoid (vector_measure Ξ± M) :=
function.injective.add_comm_monoid _ coe_injective coe_zero coe_add
/-- `coe_fn` is an `add_monoid_hom`. -/
@[simps]
def coe_fn_add_monoid_hom : vector_measure Ξ± M β+ (set Ξ± β M) :=
{ to_fun := coe_fn, map_zero' := coe_zero, map_add' := coe_add }
end add_comm_monoid
section add_comm_group
variables {M : Type*} [add_comm_group M] [topological_space M] [topological_add_group M]
include m
/-- The negative of a vector measure is a vector measure. -/
def neg (v : vector_measure Ξ± M) : vector_measure Ξ± M :=
{ measure_of' := -v,
empty' := by simp,
not_measurable' := Ξ» _ hi, by simp [v.not_measurable hi],
m_Union' := Ξ» f hfβ hfβ, has_sum.neg $ v.m_Union hfβ hfβ }
instance : has_neg (vector_measure Ξ± M) := β¨negβ©
@[simp] lemma coe_neg (v : vector_measure Ξ± M) : β(-v) = - v := rfl
lemma neg_apply (v : vector_measure Ξ± M) (i : set Ξ±) :(-v) i = - v i := rfl
/-- The difference of two vector measure is a vector measure. -/
def sub (v w : vector_measure Ξ± M) : vector_measure Ξ± M :=
{ measure_of' := v - w,
empty' := by simp,
not_measurable' := Ξ» _ hi,
by simp [v.not_measurable hi, w.not_measurable hi],
m_Union' := Ξ» f hfβ hfβ,
has_sum.sub (v.m_Union hfβ hfβ)
(w.m_Union hfβ hfβ) }
instance : has_sub (vector_measure Ξ± M) := β¨subβ©
@[simp] lemma coe_sub (v w : vector_measure Ξ± M) : β(v - w) = v - w := rfl
lemma sub_apply (v w : vector_measure Ξ± M) (i : set Ξ±) : (v - w) i = v i - w i := rfl
instance : add_comm_group (vector_measure Ξ± M) :=
function.injective.add_comm_group _ coe_injective coe_zero coe_add coe_neg coe_sub
end add_comm_group
section distrib_mul_action
variables {M : Type*} [add_comm_monoid M] [topological_space M]
variables {R : Type*} [semiring R] [distrib_mul_action R M]
variables [topological_space R] [has_continuous_smul R M]
include m
/-- Given a real number `r` and a signed measure `s`, `smul r s` is the signed
measure corresponding to the function `r β’ s`. -/
def smul (r : R) (v : vector_measure Ξ± M) : vector_measure Ξ± M :=
{ measure_of' := r β’ v,
empty' := by rw [pi.smul_apply, empty, smul_zero],
not_measurable' := Ξ» _ hi, by rw [pi.smul_apply, v.not_measurable hi, smul_zero],
m_Union' := Ξ» _ hfβ hfβ, has_sum.const_smul (v.m_Union hfβ hfβ) }
instance : has_scalar R (vector_measure Ξ± M) := β¨smulβ©
@[simp] lemma coe_smul (r : R) (v : vector_measure Ξ± M) : β(r β’ v) = r β’ v := rfl
lemma smul_apply (r : R) (v : vector_measure Ξ± M) (i : set Ξ±) :
(r β’ v) i = r β’ v i := rfl
instance [has_continuous_add M] : distrib_mul_action R (vector_measure Ξ± M) :=
function.injective.distrib_mul_action coe_fn_add_monoid_hom coe_injective coe_smul
end distrib_mul_action
section module
variables {M : Type*} [add_comm_monoid M] [topological_space M]
variables {R : Type*} [semiring R] [module R M]
variables [topological_space R] [has_continuous_smul R M]
include m
instance [has_continuous_add M] : module R (vector_measure Ξ± M) :=
function.injective.module R coe_fn_add_monoid_hom coe_injective coe_smul
end module
end vector_measure
namespace measure
include m
/-- A finite measure coerced into a real function is a signed measure. -/
@[simps]
def to_signed_measure (ΞΌ : measure Ξ±) [hΞΌ : is_finite_measure ΞΌ] : signed_measure Ξ± :=
{ measure_of' := Ξ» i : set Ξ±, if measurable_set i then (ΞΌ.measure_of i).to_real else 0,
empty' := by simp [ΞΌ.empty],
not_measurable' := Ξ» _ hi, if_neg hi,
m_Union' :=
begin
intros _ hfβ hfβ,
rw [ΞΌ.m_Union hfβ hfβ, ennreal.tsum_to_real_eq, if_pos (measurable_set.Union hfβ),
summable.has_sum_iff],
{ congr, ext n, rw if_pos (hfβ n) },
{ refine @summable_of_nonneg_of_le _ (ennreal.to_real β ΞΌ β f) _ _ _ _,
{ intro, split_ifs,
exacts [ennreal.to_real_nonneg, le_rfl] },
{ intro, split_ifs,
exacts [le_rfl, ennreal.to_real_nonneg] },
exact summable_measure_to_real hfβ hfβ },
{ intros a ha,
apply ne_of_lt hΞΌ.measure_univ_lt_top,
rw [eq_top_iff, β ha, outer_measure.measure_of_eq_coe, coe_to_outer_measure],
exact measure_mono (set.subset_univ _) }
end }
lemma to_signed_measure_apply_measurable {ΞΌ : measure Ξ±} [is_finite_measure ΞΌ]
{i : set Ξ±} (hi : measurable_set i) :
ΞΌ.to_signed_measure i = (ΞΌ i).to_real :=
if_pos hi
-- Without this lemma, `singular_part_neg` in `measure_theory.decomposition.lebesgue` is
-- extremely slow
lemma to_signed_measure_congr {ΞΌ Ξ½ : measure Ξ±} [is_finite_measure ΞΌ] [is_finite_measure Ξ½]
(h : ΞΌ = Ξ½) : ΞΌ.to_signed_measure = Ξ½.to_signed_measure :=
by { congr, exact h }
lemma to_signed_measure_eq_to_signed_measure_iff
{ΞΌ Ξ½ : measure Ξ±} [is_finite_measure ΞΌ] [is_finite_measure Ξ½] :
ΞΌ.to_signed_measure = Ξ½.to_signed_measure β ΞΌ = Ξ½ :=
begin
refine β¨Ξ» h, _, Ξ» h, _β©,
{ ext1 i hi,
have : ΞΌ.to_signed_measure i = Ξ½.to_signed_measure i,
{ rw h },
rwa [to_signed_measure_apply_measurable hi, to_signed_measure_apply_measurable hi,
ennreal.to_real_eq_to_real] at this;
{ exact measure_ne_top _ _ } },
{ congr, assumption }
end
@[simp] lemma to_signed_measure_zero :
(0 : measure Ξ±).to_signed_measure = 0 :=
by { ext i hi, simp }
@[simp] lemma to_signed_measure_add (ΞΌ Ξ½ : measure Ξ±) [is_finite_measure ΞΌ] [is_finite_measure Ξ½] :
(ΞΌ + Ξ½).to_signed_measure = ΞΌ.to_signed_measure + Ξ½.to_signed_measure :=
begin
ext i hi,
rw [to_signed_measure_apply_measurable hi, add_apply,
ennreal.to_real_add (ne_of_lt (measure_lt_top _ _ )) (ne_of_lt (measure_lt_top _ _)),
vector_measure.add_apply, to_signed_measure_apply_measurable hi,
to_signed_measure_apply_measurable hi],
all_goals { apply_instance }
end
@[simp] lemma to_signed_measure_smul (ΞΌ : measure Ξ±) [is_finite_measure ΞΌ] (r : ββ₯0) :
(r β’ ΞΌ).to_signed_measure = r β’ ΞΌ.to_signed_measure :=
begin
ext i hi,
rw [to_signed_measure_apply_measurable hi, vector_measure.smul_apply,
to_signed_measure_apply_measurable hi, coe_nnreal_smul, pi.smul_apply,
ennreal.to_real_smul],
end
/-- A measure is a vector measure over `ββ₯0β`. -/
@[simps]
def to_ennreal_vector_measure (ΞΌ : measure Ξ±) : vector_measure Ξ± ββ₯0β :=
{ measure_of' := Ξ» i : set Ξ±, if measurable_set i then ΞΌ i else 0,
empty' := by simp [ΞΌ.empty],
not_measurable' := Ξ» _ hi, if_neg hi,
m_Union' := Ξ» _ hfβ hfβ,
begin
rw summable.has_sum_iff ennreal.summable,
{ rw [if_pos (measurable_set.Union hfβ), measure_theory.measure_Union hfβ hfβ],
exact tsum_congr (Ξ» n, if_pos (hfβ n)) },
end }
lemma to_ennreal_vector_measure_apply_measurable
{ΞΌ : measure Ξ±} {i : set Ξ±} (hi : measurable_set i) :
ΞΌ.to_ennreal_vector_measure i = ΞΌ i :=
if_pos hi
@[simp] lemma to_ennreal_vector_measure_zero :
(0 : measure Ξ±).to_ennreal_vector_measure = 0 :=
by { ext i hi, simp }
@[simp] lemma to_ennreal_vector_measure_add (ΞΌ Ξ½ : measure Ξ±) :
(ΞΌ + Ξ½).to_ennreal_vector_measure = ΞΌ.to_ennreal_vector_measure + Ξ½.to_ennreal_vector_measure :=
begin
refine measure_theory.vector_measure.ext (Ξ» i hi, _),
rw [to_ennreal_vector_measure_apply_measurable hi, add_apply, vector_measure.add_apply,
to_ennreal_vector_measure_apply_measurable hi, to_ennreal_vector_measure_apply_measurable hi]
end
lemma to_signed_measure_sub_apply {ΞΌ Ξ½ : measure Ξ±} [is_finite_measure ΞΌ] [is_finite_measure Ξ½]
{i : set Ξ±} (hi : measurable_set i) :
(ΞΌ.to_signed_measure - Ξ½.to_signed_measure) i = (ΞΌ i).to_real - (Ξ½ i).to_real :=
begin
rw [vector_measure.sub_apply, to_signed_measure_apply_measurable hi,
measure.to_signed_measure_apply_measurable hi, sub_eq_add_neg]
end
end measure
namespace vector_measure
open measure
section
/-- A vector measure over `ββ₯0β` is a measure. -/
def ennreal_to_measure {m : measurable_space Ξ±} (v : vector_measure Ξ± ββ₯0β) : measure Ξ± :=
of_measurable (Ξ» s _, v s) v.empty (Ξ» f hfβ hfβ, v.of_disjoint_Union_nat hfβ hfβ)
lemma ennreal_to_measure_apply {m : measurable_space Ξ±} {v : vector_measure Ξ± ββ₯0β}
{s : set Ξ±} (hs : measurable_set s) : ennreal_to_measure v s = v s :=
by rw [ennreal_to_measure, of_measurable_apply _ hs]
/-- The equiv between `vector_measure Ξ± ββ₯0β` and `measure Ξ±` formed by
`measure_theory.vector_measure.ennreal_to_measure` and
`measure_theory.measure.to_ennreal_vector_measure`. -/
@[simps] def equiv_measure [measurable_space Ξ±] : vector_measure Ξ± ββ₯0β β measure Ξ± :=
{ to_fun := ennreal_to_measure,
inv_fun := to_ennreal_vector_measure,
left_inv := Ξ» _, ext (Ξ» s hs,
by rw [to_ennreal_vector_measure_apply_measurable hs, ennreal_to_measure_apply hs]),
right_inv := Ξ» _, measure.ext (Ξ» s hs,
by rw [ennreal_to_measure_apply hs, to_ennreal_vector_measure_apply_measurable hs]) }
end
section
variables [measurable_space Ξ±] [measurable_space Ξ²]
variables {M : Type*} [add_comm_monoid M] [topological_space M]
variables (v : vector_measure Ξ± M)
/-- The pushforward of a vector measure along a function. -/
def map (v : vector_measure Ξ± M) (f : Ξ± β Ξ²) :
vector_measure Ξ² M :=
if hf : measurable f then
{ measure_of' := Ξ» s, if measurable_set s then v (f β»ΒΉ' s) else 0,
empty' := by simp,
not_measurable' := Ξ» i hi, if_neg hi,
m_Union' :=
begin
intros g hgβ hgβ,
convert v.m_Union (Ξ» i, hf (hgβ i)) (Ξ» i j hij x hx, hgβ i j hij hx),
{ ext i, rw if_pos (hgβ i) },
{ rw [preimage_Union, if_pos (measurable_set.Union hgβ)] }
end } else 0
lemma map_not_measurable {f : Ξ± β Ξ²} (hf : Β¬ measurable f) : v.map f = 0 :=
dif_neg hf
lemma map_apply {f : Ξ± β Ξ²} (hf : measurable f) {s : set Ξ²} (hs : measurable_set s) :
v.map f s = v (f β»ΒΉ' s) :=
by { rw [map, dif_pos hf], exact if_pos hs }
@[simp] lemma map_id : v.map id = v :=
ext (Ξ» i hi, by rw [map_apply v measurable_id hi, preimage_id])
@[simp] lemma map_zero (f : Ξ± β Ξ²) : (0 : vector_measure Ξ± M).map f = 0 :=
begin
by_cases hf : measurable f,
{ ext i hi,
rw [map_apply _ hf hi, zero_apply, zero_apply] },
{ exact dif_neg hf }
end
section
variables {N : Type*} [add_comm_monoid N] [topological_space N]
/-- Given a vector measure `v` on `M` and a continuous add_monoid_hom `f : M β N`, `f β v` is a
vector measure on `N`. -/
def map_range (v : vector_measure Ξ± M) (f : M β+ N) (hf : continuous f) : vector_measure Ξ± N :=
{ measure_of' := Ξ» s, f (v s),
empty' := by rw [empty, add_monoid_hom.map_zero],
not_measurable' := Ξ» i hi, by rw [not_measurable v hi, add_monoid_hom.map_zero],
m_Union' := Ξ» g hgβ hgβ, has_sum.map (v.m_Union hgβ hgβ) f hf }
@[simp] lemma map_range_apply {f : M β+ N} (hf : continuous f) {s : set Ξ±} :
v.map_range f hf s = f (v s) :=
rfl
@[simp] lemma map_range_id :
v.map_range (add_monoid_hom.id M) continuous_id = v :=
by { ext, refl }
@[simp] lemma map_range_zero {f : M β+ N} (hf : continuous f) :
map_range (0 : vector_measure Ξ± M) f hf = 0 :=
by { ext, simp }
section has_continuous_add
variables [has_continuous_add M] [has_continuous_add N]
@[simp] lemma map_range_add {v w : vector_measure Ξ± M} {f : M β+ N} (hf : continuous f) :
(v + w).map_range f hf = v.map_range f hf + w.map_range f hf :=
by { ext, simp }
/-- Given a continuous add_monoid_hom `f : M β N`, `map_range_hom` is the add_monoid_hom mapping the
vector measure `v` on `M` to the vector measure `f β v` on `N`. -/
def map_range_hom (f : M β+ N) (hf : continuous f) : vector_measure Ξ± M β+ vector_measure Ξ± N :=
{ to_fun := Ξ» v, v.map_range f hf,
map_zero' := map_range_zero hf,
map_add' := Ξ» _ _, map_range_add hf }
end has_continuous_add
section module
variables {R : Type*} [semiring R] [module R M] [module R N]
variables [topological_space R] [has_continuous_add M] [has_continuous_add N]
[has_continuous_smul R M] [has_continuous_smul R N]
/-- Given a continuous linear map `f : M β N`, `map_rangeβ` is the linear map mapping the
vector measure `v` on `M` to the vector measure `f β v` on `N`. -/
def map_rangeβ (f : M ββ[R] N) (hf : continuous f) : vector_measure Ξ± M ββ[R] vector_measure Ξ± N :=
{ to_fun := Ξ» v, v.map_range f.to_add_monoid_hom hf,
map_add' := Ξ» _ _, map_range_add hf,
map_smul' := by { intros, ext, simp } }
end module
end
/-- The restriction of a vector measure on some set. -/
def restrict (v : vector_measure Ξ± M) (i : set Ξ±) :
vector_measure Ξ± M :=
if hi : measurable_set i then
{ measure_of' := Ξ» s, if measurable_set s then v (s β© i) else 0,
empty' := by simp,
not_measurable' := Ξ» i hi, if_neg hi,
m_Union' :=
begin
intros f hfβ hfβ,
convert v.m_Union (Ξ» n, (hfβ n).inter hi)
(hfβ.mono $ Ξ» i j, disjoint.mono inf_le_left inf_le_left),
{ ext n, rw if_pos (hfβ n) },
{ rw [Union_inter, if_pos (measurable_set.Union hfβ)] }
end } else 0
lemma restrict_not_measurable {i : set Ξ±} (hi : Β¬ measurable_set i) :
v.restrict i = 0 :=
dif_neg hi
lemma restrict_apply {i : set Ξ±} (hi : measurable_set i)
{j : set Ξ±} (hj : measurable_set j) : v.restrict i j = v (j β© i) :=
by { rw [restrict, dif_pos hi], exact if_pos hj }
lemma restrict_eq_self {i : set Ξ±} (hi : measurable_set i)
{j : set Ξ±} (hj : measurable_set j) (hij : j β i) : v.restrict i j = v j :=
by rw [restrict_apply v hi hj, inter_eq_left_iff_subset.2 hij]
@[simp] lemma restrict_empty : v.restrict β
= 0 :=
ext (Ξ» i hi, by rw [restrict_apply v measurable_set.empty hi, inter_empty, v.empty, zero_apply])
@[simp] lemma restrict_univ : v.restrict univ = v :=
ext (Ξ» i hi, by rw [restrict_apply v measurable_set.univ hi, inter_univ])
@[simp] lemma restrict_zero {i : set Ξ±} :
(0 : vector_measure Ξ± M).restrict i = 0 :=
begin
by_cases hi : measurable_set i,
{ ext j hj, rw [restrict_apply 0 hi hj], refl },
{ exact dif_neg hi }
end
section has_continuous_add
variables [has_continuous_add M]
lemma map_add (v w : vector_measure Ξ± M) (f : Ξ± β Ξ²) :
(v + w).map f = v.map f + w.map f :=
begin
by_cases hf : measurable f,
{ ext i hi,
simp [map_apply _ hf hi] },
{ simp [map, dif_neg hf] }
end
/-- `vector_measure.map` as an additive monoid homomorphism. -/
@[simps] def map_gm (f : Ξ± β Ξ²) : vector_measure Ξ± M β+ vector_measure Ξ² M :=
{ to_fun := Ξ» v, v.map f,
map_zero' := map_zero f,
map_add' := Ξ» _ _, map_add _ _ f }
lemma restrict_add (v w : vector_measure Ξ± M) (i : set Ξ±) :
(v + w).restrict i = v.restrict i + w.restrict i :=
begin
by_cases hi : measurable_set i,
{ ext j hj,
simp [restrict_apply _ hi hj] },
{ simp [restrict_not_measurable _ hi] }
end
/--`vector_measure.restrict` as an additive monoid homomorphism. -/
@[simps] def restrict_gm (i : set Ξ±) : vector_measure Ξ± M β+ vector_measure Ξ± M :=
{ to_fun := Ξ» v, v.restrict i,
map_zero' := restrict_zero,
map_add' := Ξ» _ _, restrict_add _ _ i }
end has_continuous_add
end
section
variables [measurable_space Ξ²]
variables {M : Type*} [add_comm_monoid M] [topological_space M]
variables {R : Type*} [semiring R] [distrib_mul_action R M]
variables [topological_space R] [has_continuous_smul R M]
include m
@[simp] lemma map_smul {v : vector_measure Ξ± M} {f : Ξ± β Ξ²} (c : R) :
(c β’ v).map f = c β’ v.map f :=
begin
by_cases hf : measurable f,
{ ext i hi,
simp [map_apply _ hf hi] },
{ simp only [map, dif_neg hf],
-- `smul_zero` does not work since we do not require `has_continuous_add`
ext i hi, simp }
end
@[simp] lemma restrict_smul {v :vector_measure Ξ± M} {i : set Ξ±} (c : R) :
(c β’ v).restrict i = c β’ v.restrict i :=
begin
by_cases hi : measurable_set i,
{ ext j hj,
simp [restrict_apply _ hi hj] },
{ simp only [restrict_not_measurable _ hi],
-- `smul_zero` does not work since we do not require `has_continuous_add`
ext j hj, simp }
end
end
section
variables [measurable_space Ξ²]
variables {M : Type*} [add_comm_monoid M] [topological_space M]
variables {R : Type*} [semiring R] [module R M]
variables [topological_space R] [has_continuous_smul R M] [has_continuous_add M]
include m
/-- `vector_measure.map` as a linear map. -/
@[simps] def mapβ (f : Ξ± β Ξ²) : vector_measure Ξ± M ββ[R] vector_measure Ξ² M :=
{ to_fun := Ξ» v, v.map f,
map_add' := Ξ» _ _, map_add _ _ f,
map_smul' := Ξ» _ _, map_smul _ }
/-- `vector_measure.restrict` as an additive monoid homomorphism. -/
@[simps] def restrictβ (i : set Ξ±) : vector_measure Ξ± M ββ[R] vector_measure Ξ± M :=
{ to_fun := Ξ» v, v.restrict i,
map_add' := Ξ» _ _, restrict_add _ _ i,
map_smul' := Ξ» _ _, restrict_smul _ }
end
section
variables {M : Type*} [topological_space M] [add_comm_monoid M] [partial_order M]
include m
/-- Vector measures over a partially ordered monoid is partially ordered.
This definition is consistent with `measure.partial_order`. -/
instance : partial_order (vector_measure Ξ± M) :=
{ le := Ξ» v w, β i, measurable_set i β v i β€ w i,
le_refl := Ξ» v i hi, le_rfl,
le_trans := Ξ» u v w hβ hβ i hi, le_trans (hβ i hi) (hβ i hi),
le_antisymm := Ξ» v w hβ hβ, ext (Ξ» i hi, le_antisymm (hβ i hi) (hβ i hi)) }
variables {u v w : vector_measure Ξ± M}
lemma le_iff : v β€ w β β i, measurable_set i β v i β€ w i :=
iff.rfl
lemma le_iff' : v β€ w β β i, v i β€ w i :=
begin
refine β¨Ξ» h i, _, Ξ» h i hi, h iβ©,
by_cases hi : measurable_set i,
{ exact h i hi },
{ rw [v.not_measurable hi, w.not_measurable hi] }
end
end
localized "notation v ` β€[`:50 i:50 `] `:0 w:50 :=
measure_theory.vector_measure.restrict v i β€ measure_theory.vector_measure.restrict w i"
in measure_theory
section
variables {M : Type*} [topological_space M] [add_comm_monoid M] [partial_order M]
variables (v w : vector_measure Ξ± M)
lemma restrict_le_restrict_iff {i : set Ξ±} (hi : measurable_set i) :
v β€[i] w β β β¦jβ¦, measurable_set j β j β i β v j β€ w j :=
β¨Ξ» h j hjβ hjβ, (restrict_eq_self v hi hjβ hjβ) βΈ (restrict_eq_self w hi hjβ hjβ) βΈ h j hjβ,
Ξ» h, le_iff.1 (Ξ» j hj, (restrict_apply v hi hj).symm βΈ (restrict_apply w hi hj).symm βΈ
h (hj.inter hi) (set.inter_subset_right j i))β©
lemma subset_le_of_restrict_le_restrict {i : set Ξ±}
(hi : measurable_set i) (hiβ : v β€[i] w) {j : set Ξ±} (hj : j β i) :
v j β€ w j :=
begin
by_cases hjβ : measurable_set j,
{ exact (restrict_le_restrict_iff _ _ hi).1 hiβ hjβ hj },
{ rw [v.not_measurable hjβ, w.not_measurable hjβ] },
end
lemma restrict_le_restrict_of_subset_le {i : set Ξ±}
(h : β β¦jβ¦, measurable_set j β j β i β v j β€ w j) : v β€[i] w :=
begin
by_cases hi : measurable_set i,
{ exact (restrict_le_restrict_iff _ _ hi).2 h },
{ rw [restrict_not_measurable v hi, restrict_not_measurable w hi],
exact le_rfl },
end
lemma restrict_le_restrict_subset {i j : set Ξ±}
(hiβ : measurable_set i) (hiβ : v β€[i] w) (hij : j β i) : v β€[j] w :=
restrict_le_restrict_of_subset_le v w (Ξ» k hkβ hkβ,
subset_le_of_restrict_le_restrict v w hiβ hiβ (set.subset.trans hkβ hij))
lemma le_restrict_empty : v β€[β
] w :=
begin
intros j hj,
rw [restrict_empty, restrict_empty]
end
lemma le_restrict_univ_iff_le : v β€[univ] w β v β€ w :=
begin
split,
{ intros h s hs,
have := h s hs,
rwa [restrict_apply _ measurable_set.univ hs, inter_univ,
restrict_apply _ measurable_set.univ hs, inter_univ] at this },
{ intros h s hs,
rw [restrict_apply _ measurable_set.univ hs, inter_univ,
restrict_apply _ measurable_set.univ hs, inter_univ],
exact h s hs }
end
end
section
variables {M : Type*} [topological_space M] [ordered_add_comm_group M] [topological_add_group M]
variables (v w : vector_measure Ξ± M)
lemma neg_le_neg {i : set Ξ±} (hi : measurable_set i) (h : v β€[i] w) : -w β€[i] -v :=
begin
intros j hjβ,
rw [restrict_apply _ hi hjβ, restrict_apply _ hi hjβ, neg_apply, neg_apply],
refine neg_le_neg _,
rw [β restrict_apply _ hi hjβ, β restrict_apply _ hi hjβ],
exact h j hjβ,
end
@[simp]
lemma neg_le_neg_iff {i : set Ξ±} (hi : measurable_set i) : -w β€[i] -v β v β€[i] w :=
β¨Ξ» h, neg_neg v βΈ neg_neg w βΈ neg_le_neg _ _ hi h, Ξ» h, neg_le_neg _ _ hi hβ©
end
section
variables {M : Type*} [topological_space M] [ordered_add_comm_monoid M] [order_closed_topology M]
variables (v w : vector_measure Ξ± M) {i j : set Ξ±}
lemma restrict_le_restrict_Union {f : β β set Ξ±}
(hfβ : β n, measurable_set (f n)) (hfβ : β n, v β€[f n] w) :
v β€[β n, f n] w :=
begin
refine restrict_le_restrict_of_subset_le v w (Ξ» a haβ haβ, _),
have haβ : (β n, a β© disjointed f n) = a,
{ rwa [β inter_Union, Union_disjointed, inter_eq_left_iff_subset] },
have haβ : pairwise (disjoint on (Ξ» n, a β© disjointed f n)),
{ exact (disjoint_disjointed _).mono (Ξ» i j, disjoint.mono inf_le_right inf_le_right) },
rw [β haβ, v.of_disjoint_Union_nat _ haβ, w.of_disjoint_Union_nat _ haβ],
refine tsum_le_tsum (Ξ» n, (restrict_le_restrict_iff v w (hfβ n)).1 (hfβ n) _ _) _ _,
{ exact (haβ.inter (measurable_set.disjointed hfβ n)) },
{ exact set.subset.trans (set.inter_subset_right _ _) (disjointed_subset _ _) },
{ refine (v.m_Union (Ξ» n, _) _).summable,
{ exact haβ.inter (measurable_set.disjointed hfβ n) },
{ exact (disjoint_disjointed _).mono (Ξ» i j, disjoint.mono inf_le_right inf_le_right) } },
{ refine (w.m_Union (Ξ» n, _) _).summable,
{ exact haβ.inter (measurable_set.disjointed hfβ n) },
{ exact (disjoint_disjointed _).mono (Ξ» i j, disjoint.mono inf_le_right inf_le_right) } },
{ intro n, exact (haβ.inter (measurable_set.disjointed hfβ n)) },
{ exact Ξ» n, haβ.inter (measurable_set.disjointed hfβ n) }
end
lemma restrict_le_restrict_encodable_Union [encodable Ξ²] {f : Ξ² β set Ξ±}
(hfβ : β b, measurable_set (f b)) (hfβ : β b, v β€[f b] w) :
v β€[β b, f b] w :=
begin
rw β encodable.Union_decodeβ,
refine restrict_le_restrict_Union v w _ _,
{ intro n, measurability },
{ intro n,
cases encodable.decodeβ Ξ² n with b,
{ simp },
{ simp [hfβ b] } }
end
lemma restrict_le_restrict_union
(hiβ : measurable_set i) (hiβ : v β€[i] w)
(hjβ : measurable_set j) (hjβ : v β€[j] w) :
v β€[i βͺ j] w :=
begin
rw union_eq_Union,
refine restrict_le_restrict_encodable_Union v w _ _,
{ measurability },
{ rintro (_ | _); simpa }
end
end
section
variables {M : Type*} [topological_space M] [ordered_add_comm_monoid M]
variables (v w : vector_measure Ξ± M) {i j : set Ξ±}
lemma nonneg_of_zero_le_restrict (hiβ : 0 β€[i] v) :
0 β€ v i :=
begin
by_cases hiβ : measurable_set i,
{ exact (restrict_le_restrict_iff _ _ hiβ).1 hiβ hiβ set.subset.rfl },
{ rw v.not_measurable hiβ },
end
lemma nonpos_of_restrict_le_zero (hiβ : v β€[i] 0) :
v i β€ 0 :=
begin
by_cases hiβ : measurable_set i,
{ exact (restrict_le_restrict_iff _ _ hiβ).1 hiβ hiβ set.subset.rfl },
{ rw v.not_measurable hiβ }
end
lemma zero_le_restrict_not_measurable (hi : Β¬ measurable_set i) :
0 β€[i] v :=
begin
rw [restrict_zero, restrict_not_measurable _ hi],
exact le_rfl,
end
lemma restrict_le_zero_of_not_measurable (hi : Β¬ measurable_set i) :
v β€[i] 0 :=
begin
rw [restrict_zero, restrict_not_measurable _ hi],
exact le_rfl,
end
lemma measurable_of_not_zero_le_restrict (hi : Β¬ 0 β€[i] v) : measurable_set i :=
not.imp_symm (zero_le_restrict_not_measurable _) hi
lemma measurable_of_not_restrict_le_zero (hi : Β¬ v β€[i] 0) : measurable_set i :=
not.imp_symm (restrict_le_zero_of_not_measurable _) hi
lemma zero_le_restrict_subset (hiβ : measurable_set i) (hij : j β i) (hiβ : 0 β€[i] v):
0 β€[j] v :=
restrict_le_restrict_of_subset_le _ _
(Ξ» k hkβ hkβ, (restrict_le_restrict_iff _ _ hiβ).1 hiβ hkβ (set.subset.trans hkβ hij))
lemma restrict_le_zero_subset (hiβ : measurable_set i) (hij : j β i) (hiβ : v β€[i] 0):
v β€[j] 0 :=
restrict_le_restrict_of_subset_le _ _
(Ξ» k hkβ hkβ, (restrict_le_restrict_iff _ _ hiβ).1 hiβ hkβ (set.subset.trans hkβ hij))
end
section
variables {M : Type*} [topological_space M] [linear_ordered_add_comm_monoid M]
variables (v w : vector_measure Ξ± M) {i j : set Ξ±}
include m
lemma exists_pos_measure_of_not_restrict_le_zero (hi : Β¬ v β€[i] 0) :
β j : set Ξ±, measurable_set j β§ j β i β§ 0 < v j :=
begin
have hiβ : measurable_set i := measurable_of_not_restrict_le_zero _ hi,
rw [restrict_le_restrict_iff _ _ hiβ] at hi,
push_neg at hi,
obtain β¨j, hjβ, hjβ, hjβ© := hi,
exact β¨j, hjβ, hjβ, hjβ©,
end
end
section
variables {M : Type*} [topological_space M] [add_comm_monoid M] [partial_order M]
[covariant_class M M (+) (β€)] [has_continuous_add M]
include m
instance covariant_add_le :
covariant_class (vector_measure Ξ± M) (vector_measure Ξ± M) (+) (β€) :=
β¨Ξ» u v w h i hi, add_le_add_left (h i hi) _β©
end
section
variables {L M N : Type*}
variables [add_comm_monoid L] [topological_space L] [add_comm_monoid M] [topological_space M]
[add_comm_monoid N] [topological_space N]
include m
/-- A vector measure `v` is absolutely continuous with respect to a measure `ΞΌ` if for all sets
`s`, `ΞΌ s = 0`, we have `v s = 0`. -/
def absolutely_continuous (v : vector_measure Ξ± M) (w : vector_measure Ξ± N) :=
β β¦s : set Ξ±β¦, w s = 0 β v s = 0
localized "infix ` βͺα΅₯ `:50 := measure_theory.vector_measure.absolutely_continuous"
in measure_theory
open_locale measure_theory
namespace absolutely_continuous
variables {v : vector_measure Ξ± M} {w : vector_measure Ξ± N}
lemma mk (h : β β¦s : set Ξ±β¦, measurable_set s β w s = 0 β v s = 0) : v βͺα΅₯ w :=
begin
intros s hs,
by_cases hmeas : measurable_set s,
{ exact h hmeas hs },
{ exact not_measurable v hmeas }
end
lemma eq {w : vector_measure Ξ± M} (h : v = w) : v βͺα΅₯ w :=
Ξ» s hs, h.symm βΈ hs
@[refl] lemma refl (v : vector_measure Ξ± M) : v βͺα΅₯ v :=
eq rfl
@[trans] lemma trans {u : vector_measure Ξ± L} (huv : u βͺα΅₯ v) (hvw : v βͺα΅₯ w) : u βͺα΅₯ w :=
Ξ» _ hs, huv $ hvw hs
lemma zero (v : vector_measure Ξ± N) : (0 : vector_measure Ξ± M) βͺα΅₯ v :=
Ξ» s _, vector_measure.zero_apply s
lemma neg_left {M : Type*} [add_comm_group M] [topological_space M] [topological_add_group M]
{v : vector_measure Ξ± M} {w : vector_measure Ξ± N} (h : v βͺα΅₯ w) : -v βͺα΅₯ w :=
Ξ» s hs, by { rw [neg_apply, h hs, neg_zero] }
lemma neg_right {N : Type*} [add_comm_group N] [topological_space N] [topological_add_group N]
{v : vector_measure Ξ± M} {w : vector_measure Ξ± N} (h : v βͺα΅₯ w) : v βͺα΅₯ -w :=
begin
intros s hs,
rw [neg_apply, neg_eq_zero] at hs,
exact h hs
end
lemma add [has_continuous_add M] {vβ vβ : vector_measure Ξ± M} {w : vector_measure Ξ± N}
(hvβ : vβ βͺα΅₯ w) (hvβ : vβ βͺα΅₯ w) : vβ + vβ βͺα΅₯ w :=
Ξ» s hs, by { rw [add_apply, hvβ hs, hvβ hs, zero_add] }
lemma sub {M : Type*} [add_comm_group M] [topological_space M] [topological_add_group M]
{vβ vβ : vector_measure Ξ± M} {w : vector_measure Ξ± N} (hvβ : vβ βͺα΅₯ w) (hvβ : vβ βͺα΅₯ w) :
vβ - vβ βͺα΅₯ w :=
Ξ» s hs, by { rw [sub_apply, hvβ hs, hvβ hs, zero_sub, neg_zero] }
lemma smul {R : Type*} [semiring R] [distrib_mul_action R M]
[topological_space R] [has_continuous_smul R M]
{r : R} {v : vector_measure Ξ± M} {w : vector_measure Ξ± N} (h : v βͺα΅₯ w) :
r β’ v βͺα΅₯ w :=
Ξ» s hs, by { rw [smul_apply, h hs, smul_zero] }
lemma map [measure_space Ξ²] (h : v βͺα΅₯ w) (f : Ξ± β Ξ²) :
v.map f βͺα΅₯ w.map f :=
begin
by_cases hf : measurable f,
{ refine mk (Ξ» s hs hws, _),
rw map_apply _ hf hs at hws β’,
exact h hws },
{ intros s hs,
rw [map_not_measurable v hf, zero_apply] }
end
lemma ennreal_to_measure {ΞΌ : vector_measure Ξ± ββ₯0β} :
(β β¦s : set Ξ±β¦, ΞΌ.ennreal_to_measure s = 0 β v s = 0) β v βͺα΅₯ ΞΌ :=
begin
split; intro h,
{ refine mk (Ξ» s hmeas hs, h _),
rw [β hs, ennreal_to_measure_apply hmeas] },
{ intros s hs,
by_cases hmeas : measurable_set s,
{ rw ennreal_to_measure_apply hmeas at hs,
exact h hs },
{ exact not_measurable v hmeas } },
end
end absolutely_continuous
/-- Two vector measures `v` and `w` are said to be mutually singular if there exists a measurable
set `s`, such that for all `t β s`, `v t = 0` and for all `t β sαΆ`, `w t = 0`.
We note that we do not require the measurability of `t` in the definition since this makes it easier
to use. This is equivalent to the definition which requires measurability. To prove
`mutually_singular` with the measurability condition, use
`measure_theory.vector_measure.mutually_singular.mk`. -/
def mutually_singular (v : vector_measure Ξ± M) (w : vector_measure Ξ± N) : Prop :=
β (s : set Ξ±), measurable_set s β§ (β t β s, v t = 0) β§ (β t β sαΆ, w t = 0)
localized "infix ` β₯α΅₯ `:60 := measure_theory.vector_measure.mutually_singular" in measure_theory
namespace mutually_singular
variables {v vβ vβ : vector_measure Ξ± M} {w wβ wβ : vector_measure Ξ± N}
lemma mk (s : set Ξ±) (hs : measurable_set s)
(hβ : β t β s, measurable_set t β v t = 0)
(hβ : β t β sαΆ, measurable_set t β w t = 0) : v β₯α΅₯ w :=
begin
refine β¨s, hs, Ξ» t hst, _, Ξ» t hst, _β©;
by_cases ht : measurable_set t,
{ exact hβ t hst ht },
{ exact not_measurable v ht },
{ exact hβ t hst ht },
{ exact not_measurable w ht }
end
lemma symm (h : v β₯α΅₯ w) : w β₯α΅₯ v :=
let β¨s, hmeas, hsβ, hsββ© := h in
β¨sαΆ, hmeas.compl, hsβ, Ξ» t ht, hsβ _ (compl_compl s βΈ ht : t β s)β©
lemma zero_right : v β₯α΅₯ (0 : vector_measure Ξ± N) :=
β¨β
, measurable_set.empty, Ξ» t ht, (subset_empty_iff.1 ht).symm βΈ v.empty, Ξ» _ _, zero_apply _β©
lemma zero_left : (0 : vector_measure Ξ± M) β₯α΅₯ w :=
zero_right.symm
lemma add_left [t2_space N] [has_continuous_add M] (hβ : vβ β₯α΅₯ w) (hβ : vβ β₯α΅₯ w) : vβ + vβ β₯α΅₯ w :=
begin
obtain β¨u, hmu, huβ, huββ© := hβ,
obtain β¨v, hmv, hvβ, hvββ© := hβ,
refine mk (u β© v) (hmu.inter hmv) (Ξ» t ht hmt, _) (Ξ» t ht hmt, _),
{ rw [add_apply, huβ _ (subset_inter_iff.1 ht).1, hvβ _ (subset_inter_iff.1 ht).2, zero_add] },
{ rw compl_inter at ht,
rw [(_ : t = (uαΆ β© t) βͺ (vαΆ \ uαΆ β© t)),
of_union _ (hmu.compl.inter hmt) ((hmv.compl.diff hmu.compl).inter hmt),
huβ, hvβ, add_zero],
{ exact subset.trans (inter_subset_left _ _) (diff_subset _ _) },
{ exact inter_subset_left _ _ },
{ apply_instance },
{ exact disjoint.mono (inter_subset_left _ _) (inter_subset_left _ _) disjoint_diff },
{ apply subset.antisymm;
intros x hx,
{ by_cases hxu' : x β uαΆ,
{ exact or.inl β¨hxu', hxβ© },
rcases ht hx with (hxu | hxv),
exacts [false.elim (hxu' hxu), or.inr β¨β¨hxv, hxu'β©, hxβ©] },
{ rcases hx; exact hx.2 } } },
end
lemma add_right [t2_space M] [has_continuous_add N] (hβ : v β₯α΅₯ wβ) (hβ : v β₯α΅₯ wβ) : v β₯α΅₯ wβ + wβ :=
(add_left hβ.symm hβ.symm).symm
lemma smul_right {R : Type*} [semiring R] [distrib_mul_action R N] [topological_space R]
[has_continuous_smul R N] (r : R) (h : v β₯α΅₯ w) : v β₯α΅₯ r β’ w :=
let β¨s, hmeas, hsβ, hsββ© := h in
β¨s, hmeas, hsβ, Ξ» t ht, by simp only [coe_smul, pi.smul_apply, hsβ t ht, smul_zero]β©
lemma smul_left {R : Type*} [semiring R] [distrib_mul_action R M] [topological_space R]
[has_continuous_smul R M] (r : R) (h : v β₯α΅₯ w) : r β’ v β₯α΅₯ w :=
(smul_right r h.symm).symm
lemma neg_left {M : Type*} [add_comm_group M] [topological_space M] [topological_add_group M]
{v : vector_measure Ξ± M} {w : vector_measure Ξ± N} (h : v β₯α΅₯ w) : -v β₯α΅₯ w :=
begin
obtain β¨u, hmu, huβ, huββ© := h,
refine β¨u, hmu, Ξ» s hs, _, huββ©,
rw [neg_apply v s, neg_eq_zero],
exact huβ s hs
end
lemma neg_right {N : Type*} [add_comm_group N] [topological_space N] [topological_add_group N]
{v : vector_measure Ξ± M} {w : vector_measure Ξ± N} (h : v β₯α΅₯ w) : v β₯α΅₯ -w :=
h.symm.neg_left.symm
@[simp]
lemma neg_left_iff {M : Type*} [add_comm_group M] [topological_space M] [topological_add_group M]
{v : vector_measure Ξ± M} {w : vector_measure Ξ± N} :
-v β₯α΅₯ w β v β₯α΅₯ w :=
β¨Ξ» h, neg_neg v βΈ h.neg_left, neg_leftβ©
@[simp]
lemma neg_right_iff {N : Type*} [add_comm_group N] [topological_space N] [topological_add_group N]
{v : vector_measure Ξ± M} {w : vector_measure Ξ± N} :
v β₯α΅₯ -w β v β₯α΅₯ w :=
β¨Ξ» h, neg_neg w βΈ h.neg_right, neg_rightβ©
end mutually_singular
section trim
omit m
/-- Restriction of a vector measure onto a sub-Ο-algebra. -/
@[simps] def trim {m n : measurable_space Ξ±} (v : vector_measure Ξ± M) (hle : m β€ n) :
@vector_measure Ξ± m M _ _ :=
{ measure_of' := Ξ» i, if measurable_set[m] i then v i else 0,
empty' := by rw [if_pos measurable_set.empty, v.empty],
not_measurable' := Ξ» i hi, by rw if_neg hi,
m_Union' := Ξ» f hfβ hfβ,
begin
have hfβ' : β k, measurable_set[n] (f k) := Ξ» k, hle _ (hfβ k),
convert v.m_Union hfβ' hfβ,
{ ext n, rw if_pos (hfβ n) },
{ rw if_pos (@measurable_set.Union _ _ m _ _ hfβ) }
end }
variables {n : measurable_space Ξ±} {v : vector_measure Ξ± M}
lemma trim_eq_self : v.trim le_rfl = v :=
begin
ext1 i hi,
exact if_pos hi,
end
@[simp] lemma zero_trim (hle : m β€ n) :
(0 : vector_measure Ξ± M).trim hle = 0 :=
begin
ext1 i hi,
exact if_pos hi,
end
lemma trim_measurable_set_eq (hle : m β€ n) {i : set Ξ±} (hi : measurable_set[m] i) :
v.trim hle i = v i :=
if_pos hi
lemma restrict_trim (hle : m β€ n) {i : set Ξ±} (hi : measurable_set[m] i) :
@vector_measure.restrict Ξ± m M _ _ (v.trim hle) i = (v.restrict i).trim hle :=
begin
ext j hj,
rw [restrict_apply, trim_measurable_set_eq hle hj, restrict_apply, trim_measurable_set_eq],
all_goals { measurability }
end
end trim
end
end vector_measure
namespace signed_measure
open vector_measure
open_locale measure_theory
include m
/-- The underlying function for `signed_measure.to_measure_of_zero_le`. -/
def to_measure_of_zero_le' (s : signed_measure Ξ±) (i : set Ξ±) (hi : 0 β€[i] s)
(j : set Ξ±) (hj : measurable_set j) : ββ₯0β :=
@coe ββ₯0 ββ₯0β _ β¨s.restrict i j, le_trans (by simp) (hi j hj)β©
/-- Given a signed measure `s` and a positive measurable set `i`, `to_measure_of_zero_le`
provides the measure, mapping measurable sets `j` to `s (i β© j)`. -/
def to_measure_of_zero_le (s : signed_measure Ξ±) (i : set Ξ±)
(hiβ : measurable_set i) (hiβ : 0 β€[i] s) : measure Ξ± :=
measure.of_measurable (s.to_measure_of_zero_le' i hiβ)
(by { simp_rw [to_measure_of_zero_le', s.restrict_apply hiβ measurable_set.empty,
set.empty_inter i, s.empty], refl })
begin
intros f hfβ hfβ,
have hβ : β n, measurable_set (i β© f n) := Ξ» n, hiβ.inter (hfβ n),
have hβ : pairwise (disjoint on Ξ» (n : β), i β© f n),
{ rintro n m hnm x β¨β¨_, hxββ©, _, hxββ©,
exact hfβ n m hnm β¨hxβ, hxββ© },
simp only [to_measure_of_zero_le', s.restrict_apply hiβ (measurable_set.Union hfβ),
set.inter_comm, set.inter_Union, s.of_disjoint_Union_nat hβ hβ,
ennreal.some_eq_coe, id.def],
have h : β n, 0 β€ s (i β© f n) :=
Ξ» n, s.nonneg_of_zero_le_restrict
(s.zero_le_restrict_subset hiβ (inter_subset_left _ _) hiβ),
rw [nnreal.coe_tsum_of_nonneg h, ennreal.coe_tsum],
{ refine tsum_congr (Ξ» n, _),
simp_rw [s.restrict_apply hiβ (hfβ n), set.inter_comm] },
{ exact (nnreal.summable_coe_of_nonneg h).2 (s.m_Union hβ hβ).summable }
end
variables (s : signed_measure Ξ±) {i j : set Ξ±}
lemma to_measure_of_zero_le_apply (hi : 0 β€[i] s)
(hiβ : measurable_set i) (hjβ : measurable_set j) :
s.to_measure_of_zero_le i hiβ hi j =
@coe ββ₯0 ββ₯0β _ β¨s (i β© j), nonneg_of_zero_le_restrict s
(zero_le_restrict_subset s hiβ (set.inter_subset_left _ _) hi)β© :=
by simp_rw [to_measure_of_zero_le, measure.of_measurable_apply _ hjβ, to_measure_of_zero_le',
s.restrict_apply hiβ hjβ, set.inter_comm]
/-- Given a signed measure `s` and a negative measurable set `i`, `to_measure_of_le_zero`
provides the measure, mapping measurable sets `j` to `-s (i β© j)`. -/
def to_measure_of_le_zero (s : signed_measure Ξ±) (i : set Ξ±) (hiβ : measurable_set i)
(hiβ : s β€[i] 0) : measure Ξ± :=
to_measure_of_zero_le (-s) i hiβ $ (@neg_zero (vector_measure Ξ± β) _) βΈ neg_le_neg _ _ hiβ hiβ
lemma to_measure_of_le_zero_apply (hi : s β€[i] 0)
(hiβ : measurable_set i) (hjβ : measurable_set j) :
s.to_measure_of_le_zero i hiβ hi j =
@coe ββ₯0 ββ₯0β _ β¨-s (i β© j), neg_apply s (i β© j) βΈ nonneg_of_zero_le_restrict _
(zero_le_restrict_subset _ hiβ (set.inter_subset_left _ _)
((@neg_zero (vector_measure Ξ± β) _) βΈ neg_le_neg _ _ hiβ hi))β© :=
begin
erw [to_measure_of_zero_le_apply],
{ simp },
{ assumption },
end
/-- `signed_measure.to_measure_of_zero_le` is a finite measure. -/
instance to_measure_of_zero_le_finite (hi : 0 β€[i] s) (hiβ : measurable_set i) :
is_finite_measure (s.to_measure_of_zero_le i hiβ hi) :=
{ measure_univ_lt_top :=
begin
rw [to_measure_of_zero_le_apply s hi hiβ measurable_set.univ],
exact ennreal.coe_lt_top,
end }
/-- `signed_measure.to_measure_of_le_zero` is a finite measure. -/
instance to_measure_of_le_zero_finite (hi : s β€[i] 0) (hiβ : measurable_set i) :
is_finite_measure (s.to_measure_of_le_zero i hiβ hi) :=
{ measure_univ_lt_top :=
begin
rw [to_measure_of_le_zero_apply s hi hiβ measurable_set.univ],
exact ennreal.coe_lt_top,
end }
lemma to_measure_of_zero_le_to_signed_measure (hs : 0 β€[univ] s) :
(s.to_measure_of_zero_le univ measurable_set.univ hs).to_signed_measure = s :=
begin
ext i hi,
simp [measure.to_signed_measure_apply_measurable hi, to_measure_of_zero_le_apply _ _ _ hi],
end
lemma to_measure_of_le_zero_to_signed_measure (hs : s β€[univ] 0) :
(s.to_measure_of_le_zero univ measurable_set.univ hs).to_signed_measure = -s :=
begin
ext i hi,
simp [measure.to_signed_measure_apply_measurable hi, to_measure_of_le_zero_apply _ _ _ hi],
end
end signed_measure
namespace measure
open vector_measure
variables (ΞΌ : measure Ξ±) [is_finite_measure ΞΌ]
lemma zero_le_to_signed_measure : 0 β€ ΞΌ.to_signed_measure :=
begin
rw β le_restrict_univ_iff_le,
refine restrict_le_restrict_of_subset_le _ _ (Ξ» j hjβ _, _),
simp only [measure.to_signed_measure_apply_measurable hjβ, coe_zero, pi.zero_apply,
ennreal.to_real_nonneg, vector_measure.coe_zero]
end
lemma to_signed_measure_to_measure_of_zero_le :
ΞΌ.to_signed_measure.to_measure_of_zero_le univ measurable_set.univ
((le_restrict_univ_iff_le _ _).2 (zero_le_to_signed_measure ΞΌ)) = ΞΌ :=
begin
refine measure.ext (Ξ» i hi, _),
lift ΞΌ i to ββ₯0 using (measure_lt_top _ _).ne with m hm,
simp [signed_measure.to_measure_of_zero_le_apply _ _ _ hi,
measure.to_signed_measure_apply_measurable hi, β hm],
end
end measure
end measure_theory
|
9bba5a965b7d937a1fa6154e797b8a90325a3f19
|
2d787ac9a5ab28a7d164cd13cee8a3cdc1e4680a
|
/src/my_exercises/07_first_negations.lean
|
5f3d4f77acc2de30b299c0701946640f8ee5041c
|
[
"Apache-2.0"
] |
permissive
|
paulzfm/lean3-tutorials
|
8c113ec2c9494d401c8a877f094db93e5a631fd6
|
f41baf1c62c251976ec8dd9ccae9e85ec4c4d336
|
refs/heads/master
| 1,679,267,488,532
| 1,614,782,461,000
| 1,614,782,461,000
| 344,157,026
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 8,402
|
lean
|
import tuto_lib
import data.int.parity
/-
Negations, proof by contradiction and contraposition.
This file introduces the logical rules and tactics related to negation:
exfalso, by_contradiction, contrapose, by_cases and push_neg.
There is a special statement denoted by `false` which, by definition,
has no proof.
So `false` implies everything. Indeed `false β P` means any proof of
`false` could be turned into a proof of P.
This fact is known by its latin name
"ex falso quod libet" (from false follows whatever you want).
Hence Lean's tactic to invoke this is called `exfalso`.
-/
example : false β 0 = 1 :=
begin
intro h,
exfalso,
exact h,
end
/-
The preceding example suggests that this definition of `false` isn't very useful.
But actually it allows us to define the negation of a statement P as
"P implies false" that we can read as "if P were true, we would get
a contradiction". Lean denotes this by `Β¬ P`.
One can prove that (Β¬ P) β (P β false). But in practice we directly
use the definition of `Β¬ P`.
-/
example {x : β} : Β¬ x < x :=
begin
intro hyp,
rw lt_iff_le_and_ne at hyp,
cases hyp with hyp_inf hyp_non,
clear hyp_inf, -- we won't use that one, so let's discard it
change x = x β false at hyp_non, -- Lean doesn't need this psychological line
apply hyp_non,
refl,
end
open int
-- 0045
example (n : β€) (h_even : even n) (h_not_even : Β¬ even n) : 0 = 1 :=
begin
exfalso,
apply h_not_even,
exact h_even,
end
-- 0046
example (P Q : Prop) (hβ : P β¨ Q) (hβ : Β¬ (P β§ Q)) : Β¬ P β Q :=
begin
split,
{ intros notP, cases hβ with hP hQ,
{ exfalso, apply notP, exact hP, },
{ exact hQ, }
},
{ intros hQ hP, apply hβ, exact β¨hP, hQβ©, }
end
/-
The definition of negation easily implies that, for every statement P,
P β Β¬ Β¬ P
The excluded middle axiom, which asserts P β¨ Β¬ P allows us to
prove the converse implication.
Together those two implications form the principle of double negation elimination.
not_not {P : Prop} : (Β¬ Β¬ P) β P
The implication `Β¬ Β¬ P β P` is the basis for proofs by contradiction:
in order to prove P, it suffices to prove ¬¬ P, ie `Β¬ P β false`.
Of course there is no need to keep explaining all this. The tactic
`by_contradiction Hyp` will transform any goal P into `false` and
add Hyp : Β¬ P to the local context.
Let's return to a proof from the 5th file: uniqueness of limits for a sequence.
This cannot be proved without using some version of the excluded middle
axiom. We used it secretely in
eq_of_abs_sub_le_all (x y : β) : (β Ξ΅ > 0, |x - y| β€ Ξ΅) β x = y
(we'll prove a variation on this lemma below).
In the proof below, we also take the opportunity to introduce the `let` tactic
which creates a local definition. If needed, it can be unfolded using `dsimp` which
takes a list of definitions to unfold. For instance after using `let Nβ := max N N'`,
you could write `dsimp [Nβ] at h` to replace `Nβ` by its definition in some
local assumption `h`.
-/
example (u : β β β) (l l' : β) : seq_limit u l β seq_limit u l' β l = l' :=
begin
intros hl hl',
by_contradiction H,
change l β l' at H, -- Lean does not need this line
have ineg : |l-l'| > 0,
exact abs_pos.mpr (sub_ne_zero_of_ne H), -- details about that line are not important
cases hl ( |l-l'|/4 ) (by linarith) with N hN,
cases hl' ( |l-l'|/4 ) (by linarith) with N' hN',
let Nβ := max N N',
specialize hN Nβ (le_max_left _ _),
specialize hN' Nβ (le_max_right _ _),
have clef : |l-l'| < |l-l'|,
calc
|l - l'| = |(l-u Nβ) + (u Nβ -l')| : by ring
... β€ |l - u Nβ| + |u Nβ - l'| : by apply abs_add
... = |u Nβ - l| + |u Nβ - l'| : by rw abs_sub
... < |l-l'| : by linarith,
linarith, -- linarith can also find simple numerical contradictions
end
/-
Another incarnation of the excluded middle axiom is the principle of
contraposition: in order to prove P β Q, it suffices to prove
non Q β non P.
-/
-- Using a proof by contradiction, let's prove the contraposition principle
-- 0047
example (P Q : Prop) (h : Β¬ Q β Β¬ P) : P β Q :=
begin
intros hP,
by_contradiction hnot,
specialize h hnot,
apply h,
exact hP,
end
/-
Again Lean doesn't need this principle explained to it. We can use the
`contrapose` tactic.
-/
example (P Q : Prop) (h : Β¬ Q β Β¬ P) : P β Q :=
begin
contrapose,
exact h,
end
/-
In the next exercise, we'll use
odd n : β k, n = 2*k + 1
int.odd_iff_not_even {n : β€} : odd n β Β¬ even n
-/
-- 0048
example (n : β€) : even (n^2) β even n :=
begin
split,
{ contrapose,
intro h,
rw β int.odd_iff_not_even at *,
cases h with k hk,
use (2*k^2+2*k),
rw hk, ring, },
{ rintros β¨k, rflβ©,
use (2*k^2), ring, }
end
/-
As a last step on our law of the excluded middle tour, let's notice that, especially
in pure logic exercises, it can sometimes be useful to use the
excluded middle axiom in its original form:
classical.em : β P, P β¨ Β¬ P
Instead of applying this lemma and then using the `cases` tactic, we
have the shortcut
by_cases h : P,
combining both steps to create two proof branches: one assuming
h : P, and the other assuming h : Β¬ P
For instance, let's prove a reformulation of this implication relation,
which is sometimes used as a definition in other logical foundations,
especially those based on truth tables (hence very strongly using
excluded middle from the very beginning).
-/
variables (P Q : Prop)
example : (P β Q) β (Β¬ P β¨ Q) :=
begin
split,
{ intro h,
by_cases hP : P,
{ right,
exact h hP },
{ left,
exact hP } },
{ intros h hP,
cases h with hnP hQ,
{ exfalso,
exact hnP hP },
{ exact hQ } },
end
-- 0049
example : Β¬ (P β§ Q) β Β¬ P β¨ Β¬ Q :=
begin
split,
{ intro h,
by_cases hP : P,
{ right, intros hQ, apply h, exact β¨hP, hQβ©, },
{ left, exact hP, }
},
{ rintros h β¨hP, hQβ©,
cases h with h h,
{ apply h, exact hP, },
{ apply h, exact hQ, }
}
end
/-
It is crucial to understand negation of quantifiers.
Let's do it by hand for a little while.
In the first exercise, only the definition of negation is needed.
-/
-- 0050
example (n : β€) : Β¬ (β k, n = 2*k) β β k, n β 2*k :=
begin
split,
{ intros h k hn, apply h, use k, exact hn, },
{ rintros h β¨k, rflβ©, apply h k, refl, }
end
/-
Contrary to negation of the existential quantifier, negation of the
universal quantifier requires excluded middle for the first implication.
In order to prove this, we can use either
* a double proof by contradiction
* a contraposition, not_not : (Β¬ Β¬ P) β P) and a proof by contradiction.
-/
def even_fun (f : β β β) := β x, f (-x) = f x
-- 0051
example (f : β β β) : Β¬ even_fun f β β x, f (-x) β f x :=
begin
split,
{ contrapose,
intro h,
rw not_not,
intro x,
by_contradiction H,
apply h,
use x,
},
{ rintro β¨x, hxβ© h,
apply hx,
apply h,
}
end
/-
Of course we can't keep repeating the above proofs, especially the second one.
So we use the `push_neg` tactic.
-/
example : Β¬ even_fun (Ξ» x, 2*x) :=
begin
unfold even_fun, -- Here unfolding is important because push_neg won't do it.
push_neg,
use 42,
linarith,
end
-- 0052
example (f : β β β) : Β¬ even_fun f β β x, f (-x) β f x :=
begin
unfold even_fun,
push_neg,
end
def bounded_above (f : β β β) := β M, β x, f x β€ M
example : Β¬ bounded_above (Ξ» x, x) :=
begin
unfold bounded_above,
push_neg,
intro M,
use M + 1,
linarith,
end
-- Let's contrapose
-- 0053
example (x : β) : (β Ξ΅ > 0, x β€ Ξ΅) β x β€ 0 :=
begin
contrapose,
push_neg,
intro h,
use x/2,
split; linarith,
end
/-
The "contrapose, push_neg" combo is so common that we can abreviate it to
`contrapose!`
Let's use this trick, together with:
eq_or_lt_of_le : a β€ b β a = b β¨ a < b
-/
-- 0054
example (f : β β β) : (β x y, x < y β f x < f y) β (β x y, (x β€ y β f x β€ f y)) :=
begin
split,
{ intros h x y, split,
{ intros hle, cases eq_or_lt_of_le hle with heq hlt,
{ rw heq, },
{ linarith [h _ _ hlt], }
},
contrapose!, apply h,
},
{ intros h x y, contrapose!, rw β h, intro hle, exact hle, }
end
|
94d46ac23b3f2d5077a5924409cfa004f7729d21
|
206422fb9edabf63def0ed2aa3f489150fb09ccb
|
/src/topology/uniform_space/basic.lean
|
54bb214d53294812a87176e1ad5153348f025e21
|
[
"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
| 71,039
|
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, Patrick Massot
-/
import order.filter.lift
import topology.separation
/-!
# Uniform spaces
Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly
generalize to uniform spaces, e.g.
* uniform continuity (in this file)
* completeness (in `cauchy.lean`)
* extension of uniform continuous functions to complete spaces (in `uniform_embedding.lean`)
* totally bounded sets (in `cauchy.lean`)
* totally bounded complete sets are compact (in `cauchy.lean`)
A uniform structure on a type `X` is a filter `π€ X` on `X Γ X` satisfying some conditions
which makes it reasonable to say that `βαΆ (p : X Γ X) in π€ X, ...` means
"for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages
of `X`. The two main examples are:
* If `X` is a metric space, `V β π€ X β β Ξ΅ > 0, { p | dist p.1 p.2 < Ξ΅ } β V`
* If `G` is an additive topological group, `V β π€ G β β U β π (0 : G), {p | p.2 - p.1 β U} β V`
Those examples are generalizations in two different directions of the elementary example where
`X = β` and `V β π€ β β β Ξ΅ > 0, { p | |p.2 - p.1| < Ξ΅ } β V` which features both the topological
group structure on `β` and its metric space structure.
Each uniform structure on `X` induces a topology on `X` characterized by
> `nhds_eq_comap_uniformity : β {x : X}, π x = comap (prod.mk x) (π€ X)`
where `prod.mk x : X β X Γ X := (Ξ» y, (x, y))` is the partial evaluation of the product
constructor.
The dictionary with metric spaces includes:
* an upper bound for `dist x y` translates into `(x, y) β V` for some `V β π€ X`
* a ball `ball x r` roughly corresponds to `uniform_space.ball x V := {y | (x, y) β V}`
for some `V β π€ X`, but the later is more general (it includes in
particular both open and closed balls for suitable `V`).
In particular we have:
`is_open_iff_ball_subset {s : set X} : is_open s β β x β s, β V β π€ X, ball x V β s`
The triangle inequality is abstracted to a statement involving the composition of relations in `X`.
First note that the triangle inequality in a metric space is equivalent to
`β (x y z : X) (r r' : β), dist x y β€ r β dist y z β€ r' β dist x z β€ r + r'`.
Then, for any `V` and `W` with type `set (X Γ X)`, the composition `V β W : set (X Γ X)` is
defined as `{ p : X Γ X | β z, (p.1, z) β V β§ (z, p.2) β W }`.
In the metric space case, if `V = { p | dist p.1 p.2 β€ r }` and `W = { p | dist p.1 p.2 β€ r' }`
then the triangle inequality, as reformulated above, says `V β W` is contained in
`{p | dist p.1 p.2 β€ r + r'}` which is the entourage associated to the radius `r + r'`.
In general we have `mem_ball_comp (h : y β ball x V) (h' : z β ball y W) : z β ball x (V β W)`.
Note that this discussion does not depend on any axiom imposed on the uniformity filter,
it is simply captured by the definition of composition.
The uniform space axioms ask the filter `π€ X` to satisfy the following:
* every `V β π€ X` contains the diagonal `id_rel = { p | p.1 = p.2 }`. This abstracts the fact
that `dist x x β€ r` for every non-negative radius `r` in the metric space case and also that
`x - x` belongs to every neighborhood of zero in the topological group case.
* `V β π€ X β prod.swap '' V β π€ X`. This is tightly related the fact that `dist x y = dist y x`
in a metric space, and to continuity of negation in the topological group case.
* `β V β π€ X, β W β π€ X, W β W β V`. In the metric space case, it corresponds
to cutting the radius of a ball in half and applying the triangle inequality.
In the topological group case, it comes from continuity of addition at `(0, 0)`.
These three axioms are stated more abstractly in the definition below, in terms of
operations on filters, without directly manipulating entourages.
##Β Main definitions
* `uniform_space X` is a uniform space structure on a type `X`
* `uniform_continuous f` is a predicate saying a function `f : Ξ± β Ξ²` between uniform spaces
is uniformly continuous : `β r β π€ Ξ², βαΆ (x : Ξ± Γ Ξ±) in π€ Ξ±, (f x.1, f x.2) β r`
In this file we also define a complete lattice structure on the type `uniform_space X`
of uniform structures on `X`, as well as the pullback (`uniform_space.comap`) of uniform structures
coming from the pullback of filters.
Like distance functions, uniform structures cannot be pushed forward in general.
## Notations
Localized in `uniformity`, we have the notation `π€ X` for the uniformity on a uniform space `X`,
and `β` for composition of relations, seen as terms with type `set (X Γ X)`.
## Implementation notes
There is already a theory of relations in `data/rel.lean` where the main definition is
`def rel (Ξ± Ξ² : Type*) := Ξ± β Ξ² β Prop`.
The relations used in the current file involve only one type, but this is not the reason why
we don't reuse `data/rel.lean`. We use `set (Ξ± Γ Ξ±)`
instead of `rel Ξ± Ξ±` because we really need sets to use the filter library, and elements
of filters on `Ξ± Γ Ξ±` have type `set (Ξ± Γ Ξ±)`.
The structure `uniform_space X` bundles a uniform structure on `X`, a topology on `X` and
an assumption saying those are compatible. This may not seem mathematically reasonable at first,
but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance]
below.
## References
The formalization uses the books:
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
But it makes a more systematic use of the filter library.
-/
open set filter classical
open_locale classical topological_space filter
set_option eqn_compiler.zeta true
universes u
/-!
### Relations, seen as `set (Ξ± Γ Ξ±)`
-/
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*} {ΞΉ : Sort*}
/-- The identity relation, or the graph of the identity function -/
def id_rel {Ξ± : Type*} := {p : Ξ± Γ Ξ± | p.1 = p.2}
@[simp] theorem mem_id_rel {a b : Ξ±} : (a, b) β @id_rel Ξ± β a = b := iff.rfl
@[simp] theorem id_rel_subset {s : set (Ξ± Γ Ξ±)} : id_rel β s β β a, (a, a) β s :=
by simp [subset_def]; exact forall_congr (Ξ» a, by simp)
/-- The composition of relations -/
def comp_rel {Ξ± : Type u} (rβ rβ : set (Ξ±ΓΞ±)) := {p : Ξ± Γ Ξ± | βz:Ξ±, (p.1, z) β rβ β§ (z, p.2) β rβ}
localized "infix ` β `:55 := comp_rel" in uniformity
@[simp] theorem mem_comp_rel {rβ rβ : set (Ξ±ΓΞ±)}
{x y : Ξ±} : (x, y) β rβ β rβ β β z, (x, z) β rβ β§ (z, y) β rβ := iff.rfl
@[simp] theorem swap_id_rel : prod.swap '' id_rel = @id_rel Ξ± :=
set.ext $ assume β¨a, bβ©, by simp [image_swap_eq_preimage_swap]; exact eq_comm
theorem monotone_comp_rel [preorder Ξ²] {f g : Ξ² β set (Ξ±ΓΞ±)}
(hf : monotone f) (hg : monotone g) : monotone (Ξ»x, (f x) β (g x)) :=
assume a b h p β¨z, hβ, hββ©, β¨z, hf h hβ, hg h hββ©
@[mono]
lemma comp_rel_mono {f g h k: set (Ξ±ΓΞ±)} (hβ : f β h) (hβ : g β k) : f β g β h β k :=
Ξ» β¨x, yβ© β¨z, h, h'β©, β¨z, hβ h, hβ h'β©
lemma prod_mk_mem_comp_rel {a b c : Ξ±} {s t : set (Ξ±ΓΞ±)} (hβ : (a, c) β s) (hβ : (c, b) β t) :
(a, b) β s β t :=
β¨c, hβ, hββ©
@[simp] lemma id_comp_rel {r : set (Ξ±ΓΞ±)} : id_rel β r = r :=
set.ext $ assume β¨a, bβ©, by simp
lemma comp_rel_assoc {r s t : set (Ξ±ΓΞ±)} :
(r β s) β t = r β (s β t) :=
by ext p; cases p; simp only [mem_comp_rel]; tauto
lemma subset_comp_self {Ξ± : Type*} {s : set (Ξ± Γ Ξ±)} (h : id_rel β s) : s β s β s :=
Ξ» β¨x, yβ© xy_in, β¨x, h (by rw mem_id_rel), xy_inβ©
/-- The relation is invariant under swapping factors. -/
def symmetric_rel (V : set (Ξ± Γ Ξ±)) : Prop := prod.swap β»ΒΉ' V = V
/-- The maximal symmetric relation contained in a given relation. -/
def symmetrize_rel (V : set (Ξ± Γ Ξ±)) : set (Ξ± Γ Ξ±) := V β© prod.swap β»ΒΉ' V
lemma symmetric_symmetrize_rel (V : set (Ξ± Γ Ξ±)) : symmetric_rel (symmetrize_rel V) :=
by simp [symmetric_rel, symmetrize_rel, preimage_inter, inter_comm, β preimage_comp]
lemma symmetrize_rel_subset_self (V : set (Ξ± Γ Ξ±)) : symmetrize_rel V β V :=
sep_subset _ _
@[mono]
lemma symmetrize_mono {V W: set (Ξ± Γ Ξ±)} (h : V β W) : symmetrize_rel V β symmetrize_rel W :=
inter_subset_inter h $ preimage_mono h
lemma symmetric_rel_inter {U V : set (Ξ± Γ Ξ±)} (hU : symmetric_rel U) (hV : symmetric_rel V) :
symmetric_rel (U β© V) :=
begin
unfold symmetric_rel at *,
rw [preimage_inter, hU, hV],
end
/-- This core description of a uniform space is outside of the type class hierarchy. It is useful
for constructions of uniform spaces, when the topology is derived from the uniform space. -/
structure uniform_space.core (Ξ± : Type u) :=
(uniformity : filter (Ξ± Γ Ξ±))
(refl : π id_rel β€ uniformity)
(symm : tendsto prod.swap uniformity uniformity)
(comp : uniformity.lift' (Ξ»s, s β s) β€ uniformity)
/-- An alternative constructor for `uniform_space.core`. This version unfolds various
`filter`-related definitions. -/
def uniform_space.core.mk' {Ξ± : Type u} (U : filter (Ξ± Γ Ξ±))
(refl : β (r β U) x, (x, x) β r)
(symm : β r β U, prod.swap β»ΒΉ' r β U)
(comp : β r β U, β t β U, t β t β r) : uniform_space.core Ξ± :=
β¨U, Ξ» r ru, id_rel_subset.2 (refl _ ru), symm,
begin
intros r ru,
rw [mem_lift'_sets],
exact comp _ ru,
apply monotone_comp_rel; exact monotone_id,
endβ©
/-- A uniform space generates a topological space -/
def uniform_space.core.to_topological_space {Ξ± : Type u} (u : uniform_space.core Ξ±) :
topological_space Ξ± :=
{ is_open := Ξ»s, βxβs, { p : Ξ± Γ Ξ± | p.1 = x β p.2 β s } β u.uniformity,
is_open_univ := by simp; intro; exact univ_mem_sets,
is_open_inter :=
assume s t hs ht x β¨xs, xtβ©, by filter_upwards [hs x xs, ht x xt]; simp {contextual := tt},
is_open_sUnion :=
assume s hs x β¨t, ts, xtβ©, by filter_upwards [hs t ts x xt] assume p ph h, β¨t, ts, ph hβ© }
lemma uniform_space.core_eq :
β{uβ uβ : uniform_space.core Ξ±}, uβ.uniformity = uβ.uniformity β uβ = uβ
| β¨uβ, _, _, _β© β¨uβ, _, _, _β© h := by { congr, exact h }
/-- Suppose that one can put two mathematical structures on a type, a rich one `R` and a poor one
`P`, and that one can deduce the poor structure from the rich structure through a map `F` (called a
forgetful functor) (think `R = metric_space` and `P = topological_space`). A possible
implementation would be to have a type class `rich` containing a field `R`, a type class `poor`
containing a field `P`, and an instance from `rich` to `poor`. However, this creates diamond
problems, and a better approach is to let `rich` extend `poor` and have a field saying that
`F R = P`.
To illustrate this, consider the pair `metric_space` / `topological_space`. Consider the topology
on a product of two metric spaces. With the first approach, it could be obtained by going first from
each metric space to its topology, and then taking the product topology. But it could also be
obtained by considering the product metric space (with its sup distance) and then the topology
coming from this distance. These would be the same topology, but not definitionally, which means
that from the point of view of Lean's kernel, there would be two different `topological_space`
instances on the product. This is not compatible with the way instances are designed and used:
there should be at most one instance of a kind on each type. This approach has created an instance
diamond that does not commute definitionally.
The second approach solves this issue. Now, a metric space contains both a distance, a topology, and
a proof that the topology coincides with the one coming from the distance. When one defines the
product of two metric spaces, one uses the sup distance and the product topology, and one has to
give the proof that the sup distance induces the product topology. Following both sides of the
instance diamond then gives rise (definitionally) to the product topology on the product space.
Another approach would be to have the rich type class take the poor type class as an instance
parameter. It would solve the diamond problem, but it would lead to a blow up of the number
of type classes one would need to declare to work with complicated classes, say a real inner
product space, and would create exponential complexity when working with products of
such complicated spaces, that are avoided by bundling things carefully as above.
Note that this description of this specific case of the product of metric spaces is oversimplified
compared to mathlib, as there is an intermediate typeclass between `metric_space` and
`topological_space` called `uniform_space`. The above scheme is used at both levels, embedding a
topology in the uniform space structure, and a uniform structure in the metric space structure.
Note also that, when `P` is a proposition, there is no such issue as any two proofs of `P` are
definitionally equivalent in Lean.
To avoid boilerplate, there are some designs that can automatically fill the poor fields when
creating a rich structure if one doesn't want to do something special about them. For instance,
in the definition of metric spaces, default tactics fill the uniform space fields if they are
not given explicitly. One can also have a helper function creating the rich structure from a
structure with less fields, where the helper function fills the remaining fields. See for instance
`uniform_space.of_core` or `real_inner_product.of_core`.
For more details on this question, called the forgetful inheritance pattern, see [Competing
inheritance paths in dependent type theory: a case study in functional
analysis](https://hal.inria.fr/hal-02463336).
-/
library_note "forgetful inheritance"
/-- A uniform space is a generalization of the "uniform" topological aspects of a
metric space. It consists of a filter on `Ξ± Γ Ξ±` called the "uniformity", which
satisfies properties analogous to the reflexivity, symmetry, and triangle properties
of a metric.
A metric space has a natural uniformity, and a uniform space has a natural topology.
A topological group also has a natural uniformity, even when it is not metrizable. -/
class uniform_space (Ξ± : Type u) extends topological_space Ξ±, uniform_space.core Ξ± :=
(is_open_uniformity : βs, is_open s β (βxβs, { p : Ξ± Γ Ξ± | p.1 = x β p.2 β s } β uniformity))
/-- Alternative constructor for `uniform_space Ξ±` when a topology is already given. -/
@[pattern] def uniform_space.mk' {Ξ±} (t : topological_space Ξ±)
(c : uniform_space.core Ξ±)
(is_open_uniformity : βs:set Ξ±, t.is_open s β
(βxβs, { p : Ξ± Γ Ξ± | p.1 = x β p.2 β s } β c.uniformity)) :
uniform_space Ξ± := β¨c, is_open_uniformityβ©
/-- Construct a `uniform_space` from a `uniform_space.core`. -/
def uniform_space.of_core {Ξ± : Type u} (u : uniform_space.core Ξ±) : uniform_space Ξ± :=
{ to_core := u,
to_topological_space := u.to_topological_space,
is_open_uniformity := assume a, iff.rfl }
/-- Construct a `uniform_space` from a `u : uniform_space.core` and a `topological_space` structure
that is equal to `u.to_topological_space`. -/
def uniform_space.of_core_eq {Ξ± : Type u} (u : uniform_space.core Ξ±) (t : topological_space Ξ±)
(h : t = u.to_topological_space) : uniform_space Ξ± :=
{ to_core := u,
to_topological_space := t,
is_open_uniformity := assume a, h.symm βΈ iff.rfl }
lemma uniform_space.to_core_to_topological_space (u : uniform_space Ξ±) :
u.to_core.to_topological_space = u.to_topological_space :=
topological_space_eq $ funext $ assume s,
by rw [uniform_space.core.to_topological_space, uniform_space.is_open_uniformity]
@[ext]
lemma uniform_space_eq : β{uβ uβ : uniform_space Ξ±}, uβ.uniformity = uβ.uniformity β uβ = uβ
| (uniform_space.mk' tβ uβ oβ) (uniform_space.mk' tβ uβ oβ) h :=
have uβ = uβ, from uniform_space.core_eq h,
have tβ = tβ, from topological_space_eq $ funext $ assume s, by rw [oβ, oβ]; simp [this],
by simp [*]
lemma uniform_space.of_core_eq_to_core
(u : uniform_space Ξ±) (t : topological_space Ξ±) (h : t = u.to_core.to_topological_space) :
uniform_space.of_core_eq u.to_core t h = u :=
uniform_space_eq rfl
section uniform_space
variables [uniform_space Ξ±]
/-- The uniformity is a filter on Ξ± Γ Ξ± (inferred from an ambient uniform space
structure on Ξ±). -/
def uniformity (Ξ± : Type u) [uniform_space Ξ±] : filter (Ξ± Γ Ξ±) :=
(@uniform_space.to_core Ξ± _).uniformity
localized "notation `π€` := uniformity" in uniformity
lemma is_open_uniformity {s : set Ξ±} :
is_open s β (βxβs, { p : Ξ± Γ Ξ± | p.1 = x β p.2 β s } β π€ Ξ±) :=
uniform_space.is_open_uniformity s
lemma refl_le_uniformity : π id_rel β€ π€ Ξ± :=
(@uniform_space.to_core Ξ± _).refl
lemma refl_mem_uniformity {x : Ξ±} {s : set (Ξ± Γ Ξ±)} (h : s β π€ Ξ±) :
(x, x) β s :=
refl_le_uniformity h rfl
lemma symm_le_uniformity : map (@prod.swap Ξ± Ξ±) (π€ _) β€ (π€ _) :=
(@uniform_space.to_core Ξ± _).symm
lemma comp_le_uniformity : (π€ Ξ±).lift' (Ξ»s:set (Ξ±ΓΞ±), s β s) β€ π€ Ξ± :=
(@uniform_space.to_core Ξ± _).comp
lemma tendsto_swap_uniformity : tendsto (@prod.swap Ξ± Ξ±) (π€ Ξ±) (π€ Ξ±) :=
symm_le_uniformity
lemma comp_mem_uniformity_sets {s : set (Ξ± Γ Ξ±)} (hs : s β π€ Ξ±) :
β t β π€ Ξ±, t β t β s :=
have s β (π€ Ξ±).lift' (Ξ»t:set (Ξ±ΓΞ±), t β t),
from comp_le_uniformity hs,
(mem_lift'_sets $ monotone_comp_rel monotone_id monotone_id).mp this
/-- Relation `Ξ» f g, tendsto (Ξ» x, (f x, g x)) l (π€ Ξ±)` is transitive. -/
lemma filter.tendsto.uniformity_trans {l : filter Ξ²} {fβ fβ fβ : Ξ² β Ξ±}
(hββ : tendsto (Ξ» x, (fβ x, fβ x)) l (π€ Ξ±)) (hββ : tendsto (Ξ» x, (fβ x, fβ x)) l (π€ Ξ±)) :
tendsto (Ξ» x, (fβ x, fβ x)) l (π€ Ξ±) :=
begin
refine le_trans (le_lift' $ Ξ» s hs, mem_map.2 _) comp_le_uniformity,
filter_upwards [hββ hs, hββ hs],
exact Ξ» x hxββ hxββ, β¨_, hxββ, hxβββ©
end
/-- Relation `Ξ» f g, tendsto (Ξ» x, (f x, g x)) l (π€ Ξ±)` is symmetric -/
lemma filter.tendsto.uniformity_symm {l : filter Ξ²} {f : Ξ² β Ξ± Γ Ξ±}
(h : tendsto f l (π€ Ξ±)) :
tendsto (Ξ» x, ((f x).2, (f x).1)) l (π€ Ξ±) :=
tendsto_swap_uniformity.comp h
/-- Relation `Ξ» f g, tendsto (Ξ» x, (f x, g x)) l (π€ Ξ±)` is reflexive. -/
lemma tendsto_diag_uniformity (f : Ξ² β Ξ±) (l : filter Ξ²) :
tendsto (Ξ» x, (f x, f x)) l (π€ Ξ±) :=
assume s hs, mem_map.2 $ univ_mem_sets' $ Ξ» x, refl_mem_uniformity hs
lemma tendsto_const_uniformity {a : Ξ±} {f : filter Ξ²} : tendsto (Ξ» _, (a, a)) f (π€ Ξ±) :=
tendsto_diag_uniformity (Ξ» _, a) f
lemma symm_of_uniformity {s : set (Ξ± Γ Ξ±)} (hs : s β π€ Ξ±) :
β t β π€ Ξ±, (βa b, (a, b) β t β (b, a) β t) β§ t β s :=
have preimage prod.swap s β π€ Ξ±, from symm_le_uniformity hs,
β¨s β© preimage prod.swap s, inter_mem_sets hs this, Ξ» a b β¨hβ, hββ©, β¨hβ, hββ©, inter_subset_left _ _β©
lemma comp_symm_of_uniformity {s : set (Ξ± Γ Ξ±)} (hs : s β π€ Ξ±) :
β t β π€ Ξ±, (β{a b}, (a, b) β t β (b, a) β t) β§ t β t β s :=
let β¨t, htβ, htββ© := comp_mem_uniformity_sets hs in
let β¨t', ht', ht'β, ht'ββ© := symm_of_uniformity htβ in
β¨t', ht', ht'β, subset.trans (monotone_comp_rel monotone_id monotone_id ht'β) htββ©
lemma uniformity_le_symm : π€ Ξ± β€ (@prod.swap Ξ± Ξ±) <$> π€ Ξ± :=
by rw [map_swap_eq_comap_swap];
from map_le_iff_le_comap.1 tendsto_swap_uniformity
lemma uniformity_eq_symm : π€ Ξ± = (@prod.swap Ξ± Ξ±) <$> π€ Ξ± :=
le_antisymm uniformity_le_symm symm_le_uniformity
lemma symmetrize_mem_uniformity {V : set (Ξ± Γ Ξ±)} (h : V β π€ Ξ±) : symmetrize_rel V β π€ Ξ± :=
begin
apply (π€ Ξ±).inter_sets h,
rw [β image_swap_eq_preimage_swap, uniformity_eq_symm],
exact image_mem_map h,
end
theorem uniformity_lift_le_swap {g : set (Ξ±ΓΞ±) β filter Ξ²} {f : filter Ξ²} (hg : monotone g)
(h : (π€ Ξ±).lift (Ξ»s, g (preimage prod.swap s)) β€ f) : (π€ Ξ±).lift g β€ f :=
calc (π€ Ξ±).lift g β€ (filter.map (@prod.swap Ξ± Ξ±) $ π€ Ξ±).lift g :
lift_mono uniformity_le_symm (le_refl _)
... β€ _ :
by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h
lemma uniformity_lift_le_comp {f : set (Ξ±ΓΞ±) β filter Ξ²} (h : monotone f) :
(π€ Ξ±).lift (Ξ»s, f (s β s)) β€ (π€ Ξ±).lift f :=
calc (π€ Ξ±).lift (Ξ»s, f (s β s)) =
((π€ Ξ±).lift' (Ξ»s:set (Ξ±ΓΞ±), s β s)).lift f :
begin
rw [lift_lift'_assoc],
exact monotone_comp_rel monotone_id monotone_id,
exact h
end
... β€ (π€ Ξ±).lift f : lift_mono comp_le_uniformity (le_refl _)
lemma comp_le_uniformity3 :
(π€ Ξ±).lift' (Ξ»s:set (Ξ±ΓΞ±), s β (s β s)) β€ (π€ Ξ±) :=
calc (π€ Ξ±).lift' (Ξ»d, d β (d β d)) =
(π€ Ξ±).lift (Ξ»s, (π€ Ξ±).lift' (Ξ»t:set(Ξ±ΓΞ±), s β (t β t))) :
begin
rw [lift_lift'_same_eq_lift'],
exact (assume x, monotone_comp_rel monotone_const $ monotone_comp_rel monotone_id monotone_id),
exact (assume x, monotone_comp_rel monotone_id monotone_const),
end
... β€ (π€ Ξ±).lift (Ξ»s, (π€ Ξ±).lift' (Ξ»t:set(Ξ±ΓΞ±), s β t)) :
lift_mono' $ assume s hs, @uniformity_lift_le_comp Ξ± _ _ (π β (β) s) $
monotone_principal.comp (monotone_comp_rel monotone_const monotone_id)
... = (π€ Ξ±).lift' (Ξ»s:set(Ξ±ΓΞ±), s β s) :
lift_lift'_same_eq_lift'
(assume s, monotone_comp_rel monotone_const monotone_id)
(assume s, monotone_comp_rel monotone_id monotone_const)
... β€ (π€ Ξ±) : comp_le_uniformity
lemma comp_symm_mem_uniformity_sets {s : set (Ξ± Γ Ξ±)} (hs : s β π€ Ξ±) :
β t β π€ Ξ±, symmetric_rel t β§ t β t β s :=
begin
obtain β¨w, w_in, w_subβ© : β w β π€ Ξ±, w β w β s := comp_mem_uniformity_sets hs,
use [symmetrize_rel w, symmetrize_mem_uniformity w_in, symmetric_symmetrize_rel w],
have : symmetrize_rel w β w := symmetrize_rel_subset_self w,
calc symmetrize_rel w β symmetrize_rel w β w β w : by mono
... β s : w_sub,
end
lemma subset_comp_self_of_mem_uniformity {s : set (Ξ± Γ Ξ±)} (h : s β π€ Ξ±) : s β s β s :=
subset_comp_self (refl_le_uniformity h)
lemma comp_comp_symm_mem_uniformity_sets {s : set (Ξ± Γ Ξ±)} (hs : s β π€ Ξ±) :
β t β π€ Ξ±, symmetric_rel t β§ t β t β t β s :=
begin
rcases comp_symm_mem_uniformity_sets hs with β¨w, w_in, w_symm, w_subβ©,
rcases comp_symm_mem_uniformity_sets w_in with β¨t, t_in, t_symm, t_subβ©,
use [t, t_in, t_symm],
have : t β t β t := subset_comp_self_of_mem_uniformity t_in,
calc
t β t β t β w β t : by mono
... β w β (t β t) : by mono
... β w β w : by mono
... β s : w_sub,
end
/-!
###Β Balls in uniform spaces
-/
/-- The ball around `(x : Ξ²)` with respect to `(V : set (Ξ² Γ Ξ²))`. Intended to be
used for `V β π€ Ξ²`, but this is not needed for the definition. Recovers the
notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/
def uniform_space.ball (x : Ξ²) (V : set (Ξ² Γ Ξ²)) : set Ξ² := (prod.mk x) β»ΒΉ' V
open uniform_space (ball)
lemma uniform_space.mem_ball_self (x : Ξ±) {V : set (Ξ± Γ Ξ±)} (hV : V β π€ Ξ±) :
x β ball x V :=
refl_mem_uniformity hV
/-- The triangle inequality for `uniform_space.ball` -/
lemma mem_ball_comp {V W : set (Ξ² Γ Ξ²)} {x y z} (h : y β ball x V) (h' : z β ball y W) :
z β ball x (V β W) :=
prod_mk_mem_comp_rel h h'
lemma ball_subset_of_comp_subset {V W : set (Ξ² Γ Ξ²)} {x y} (h : x β ball y W) (h' : W β W β V) :
ball x W β ball y V :=
Ξ» z z_in, h' (mem_ball_comp h z_in)
lemma ball_mono {V W : set (Ξ² Γ Ξ²)} (h : V β W) (x : Ξ²) : ball x V β ball x W :=
by tauto
lemma mem_ball_symmetry {V : set (Ξ² Γ Ξ²)} (hV : symmetric_rel V) {x y} :
x β ball y V β y β ball x V :=
show (x, y) β prod.swap β»ΒΉ' V β (x, y) β V, by { unfold symmetric_rel at hV, rw hV }
lemma ball_eq_of_symmetry {V : set (Ξ² Γ Ξ²)} (hV : symmetric_rel V) {x} :
ball x V = {y | (y, x) β V} :=
by { ext y, rw mem_ball_symmetry hV, exact iff.rfl }
lemma mem_comp_of_mem_ball {V W : set (Ξ² Γ Ξ²)} {x y z : Ξ²} (hV : symmetric_rel V)
(hx : x β ball z V) (hy : y β ball z W) : (x, y) β V β W :=
begin
rw mem_ball_symmetry hV at hx,
exact β¨z, hx, hyβ©
end
lemma uniform_space.is_open_ball (x : Ξ±) {V : set (Ξ± Γ Ξ±)} (hV : is_open V) :
is_open (ball x V) :=
hV.preimage $ continuous_const.prod_mk continuous_id
lemma mem_comp_comp {V W M : set (Ξ² Γ Ξ²)} (hW' : symmetric_rel W) {p : Ξ² Γ Ξ²} :
p β V β M β W β ((ball p.1 V).prod (ball p.2 W) β© M).nonempty :=
begin
cases p with x y,
split,
{ rintros β¨z, β¨w, hpw, hwzβ©, hzyβ©,
exact β¨(w, z), β¨hpw, by rwa mem_ball_symmetry hW'β©, hwzβ©, },
{ rintro β¨β¨w, zβ©, β¨w_in, z_inβ©, hwzβ©,
rwa mem_ball_symmetry hW' at z_in,
use [z, w] ; tauto },
end
/-!
### Neighborhoods in uniform spaces
-/
lemma mem_nhds_uniformity_iff_right {x : Ξ±} {s : set Ξ±} :
s β π x β {p : Ξ± Γ Ξ± | p.1 = x β p.2 β s} β π€ Ξ± :=
β¨ begin
simp only [mem_nhds_sets_iff, is_open_uniformity, and_imp, exists_imp_distrib],
exact assume t ts ht xt, by filter_upwards [ht x xt] assume β¨x', yβ© h eq, ts $ h eq
end,
assume hs,
mem_nhds_sets_iff.mpr β¨{x | {p : Ξ± Γ Ξ± | p.1 = x β p.2 β s} β π€ Ξ±},
assume x' hx', refl_mem_uniformity hx' rfl,
is_open_uniformity.mpr $ assume x' hx',
let β¨t, ht, trβ© := comp_mem_uniformity_sets hx' in
by filter_upwards [ht] assume β¨a, bβ© hp' (hax' : a = x'),
by filter_upwards [ht] assume β¨a, b'β© hp'' (hab : a = b),
have hp : (x', b) β t, from hax' βΈ hp',
have (b, b') β t, from hab βΈ hp'',
have (x', b') β t β t, from β¨b, hp, thisβ©,
show b' β s,
from tr this rfl,
hsβ©β©
lemma mem_nhds_uniformity_iff_left {x : Ξ±} {s : set Ξ±} :
s β π x β {p : Ξ± Γ Ξ± | p.2 = x β p.1 β s} β π€ Ξ± :=
by { rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right], refl }
lemma nhds_eq_comap_uniformity_aux {Ξ± : Type u} {x : Ξ±} {s : set Ξ±} {F : filter (Ξ± Γ Ξ±)} :
{p : Ξ± Γ Ξ± | p.fst = x β p.snd β s} β F β s β comap (prod.mk x) F :=
by rw mem_comap_sets ; from iff.intro
(assume hs, β¨_, hs, assume x hx, hx rflβ©)
(assume β¨t, h, htβ©, F.sets_of_superset h $
assume β¨pβ, pββ© hp (h : pβ = x), ht $ by simp [h.symm, hp])
lemma nhds_eq_comap_uniformity {x : Ξ±} : π x = (π€ Ξ±).comap (prod.mk x) :=
by { ext s, rw [mem_nhds_uniformity_iff_right], exact nhds_eq_comap_uniformity_aux }
lemma is_open_iff_ball_subset {s : set Ξ±} : is_open s β β x β s, β V β π€ Ξ±, ball x V β s :=
begin
simp_rw [is_open_iff_mem_nhds, nhds_eq_comap_uniformity],
exact iff.rfl,
end
lemma nhds_basis_uniformity' {p : Ξ² β Prop} {s : Ξ² β set (Ξ± Γ Ξ±)} (h : (π€ Ξ±).has_basis p s)
{x : Ξ±} :
(π x).has_basis p (Ξ» i, ball x (s i)) :=
by { rw [nhds_eq_comap_uniformity], exact h.comap (prod.mk x) }
lemma nhds_basis_uniformity {p : Ξ² β Prop} {s : Ξ² β set (Ξ± Γ Ξ±)} (h : (π€ Ξ±).has_basis p s) {x : Ξ±} :
(π x).has_basis p (Ξ» i, {y | (y, x) β s i}) :=
begin
replace h := h.comap prod.swap,
rw [β map_swap_eq_comap_swap, β uniformity_eq_symm] at h,
exact nhds_basis_uniformity' h
end
lemma uniform_space.mem_nhds_iff {x : Ξ±} {s : set Ξ±} : s β π x β β V β π€ Ξ±, ball x V β s :=
begin
rw [nhds_eq_comap_uniformity, mem_comap_sets],
exact iff.rfl,
end
lemma uniform_space.ball_mem_nhds (x : Ξ±) β¦V : set (Ξ± Γ Ξ±)β¦ (V_in : V β π€ Ξ±) : ball x V β π x :=
begin
rw uniform_space.mem_nhds_iff,
exact β¨V, V_in, subset.refl _β©
end
lemma uniform_space.mem_nhds_iff_symm {x : Ξ±} {s : set Ξ±} :
s β π x β β V β π€ Ξ±, symmetric_rel V β§ ball x V β s :=
begin
rw uniform_space.mem_nhds_iff,
split,
{ rintros β¨V, V_in, V_subβ©,
use [symmetrize_rel V, symmetrize_mem_uniformity V_in, symmetric_symmetrize_rel V],
exact subset.trans (ball_mono (symmetrize_rel_subset_self V) x) V_sub },
{ rintros β¨V, V_in, V_symm, V_subβ©,
exact β¨V, V_in, V_subβ© }
end
lemma uniform_space.has_basis_nhds (x : Ξ±) :
has_basis (π x) (Ξ» s : set (Ξ± Γ Ξ±), s β π€ Ξ± β§ symmetric_rel s) (Ξ» s, ball x s) :=
β¨Ξ» t, by simp [uniform_space.mem_nhds_iff_symm, and_assoc]β©
open uniform_space
lemma uniform_space.has_basis_nhds_prod (x y : Ξ±) :
has_basis (π (x, y)) (Ξ» s, s β π€ Ξ± β§ symmetric_rel s) $ Ξ» s, (ball x s).prod (ball y s) :=
begin
rw nhds_prod_eq,
apply (has_basis_nhds x).prod' (has_basis_nhds y),
rintro U V β¨U_in, U_symmβ© β¨V_in, V_symmβ©,
exact β¨U β© V, β¨(π€ Ξ±).inter_sets U_in V_in, symmetric_rel_inter U_symm V_symmβ©,
ball_mono (inter_subset_left U V) x, ball_mono (inter_subset_right U V) yβ©,
end
lemma nhds_eq_uniformity {x : Ξ±} : π x = (π€ Ξ±).lift' (ball x) :=
(nhds_basis_uniformity' (π€ Ξ±).basis_sets).eq_binfi
lemma mem_nhds_left (x : Ξ±) {s : set (Ξ±ΓΞ±)} (h : s β π€ Ξ±) :
{y : Ξ± | (x, y) β s} β π x :=
ball_mem_nhds x h
lemma mem_nhds_right (y : Ξ±) {s : set (Ξ±ΓΞ±)} (h : s β π€ Ξ±) :
{x : Ξ± | (x, y) β s} β π y :=
mem_nhds_left _ (symm_le_uniformity h)
lemma tendsto_right_nhds_uniformity {a : Ξ±} : tendsto (Ξ»a', (a', a)) (π a) (π€ Ξ±) :=
assume s, mem_nhds_right a
lemma tendsto_left_nhds_uniformity {a : Ξ±} : tendsto (Ξ»a', (a, a')) (π a) (π€ Ξ±) :=
assume s, mem_nhds_left a
lemma lift_nhds_left {x : Ξ±} {g : set Ξ± β filter Ξ²} (hg : monotone g) :
(π x).lift g = (π€ Ξ±).lift (Ξ»s:set (Ξ±ΓΞ±), g {y | (x, y) β s}) :=
eq.trans
begin
rw [nhds_eq_uniformity],
exact (filter.lift_assoc $ monotone_principal.comp $ monotone_preimage.comp monotone_preimage )
end
(congr_arg _ $ funext $ assume s, filter.lift_principal hg)
lemma lift_nhds_right {x : Ξ±} {g : set Ξ± β filter Ξ²} (hg : monotone g) :
(π x).lift g = (π€ Ξ±).lift (Ξ»s:set (Ξ±ΓΞ±), g {y | (y, x) β s}) :=
calc (π x).lift g = (π€ Ξ±).lift (Ξ»s:set (Ξ±ΓΞ±), g {y | (x, y) β s}) : lift_nhds_left hg
... = ((@prod.swap Ξ± Ξ±) <$> (π€ Ξ±)).lift (Ξ»s:set (Ξ±ΓΞ±), g {y | (x, y) β s}) :
by rw [βuniformity_eq_symm]
... = (π€ Ξ±).lift (Ξ»s:set (Ξ±ΓΞ±), g {y | (x, y) β image prod.swap s}) :
map_lift_eq2 $ hg.comp monotone_preimage
... = _ : by simp [image_swap_eq_preimage_swap]
lemma nhds_nhds_eq_uniformity_uniformity_prod {a b : Ξ±} :
π a ΓαΆ π b =
(π€ Ξ±).lift (Ξ»s:set (Ξ±ΓΞ±), (π€ Ξ±).lift' (Ξ»t:set (Ξ±ΓΞ±),
set.prod {y : Ξ± | (y, a) β s} {y : Ξ± | (b, y) β t})) :=
begin
rw [prod_def],
show (π a).lift (Ξ»s:set Ξ±, (π b).lift (Ξ»t:set Ξ±, π (set.prod s t))) = _,
rw [lift_nhds_right],
apply congr_arg, funext s,
rw [lift_nhds_left],
refl,
exact monotone_principal.comp (monotone_prod monotone_const monotone_id),
exact (monotone_lift' monotone_const $ monotone_lam $
assume x, monotone_prod monotone_id monotone_const)
end
lemma nhds_eq_uniformity_prod {a b : Ξ±} :
π (a, b) =
(π€ Ξ±).lift' (Ξ»s:set (Ξ±ΓΞ±), set.prod {y : Ξ± | (y, a) β s} {y : Ξ± | (b, y) β s}) :=
begin
rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'],
{ intro s, exact monotone_prod monotone_const monotone_preimage },
{ intro t, exact monotone_prod monotone_preimage monotone_const }
end
lemma nhdset_of_mem_uniformity {d : set (Ξ±ΓΞ±)} (s : set (Ξ±ΓΞ±)) (hd : d β π€ Ξ±) :
β(t : set (Ξ±ΓΞ±)), is_open t β§ s β t β§ t β {p | βx y, (p.1, x) β d β§ (x, y) β s β§ (y, p.2) β d} :=
let cl_d := {p:Ξ±ΓΞ± | βx y, (p.1, x) β d β§ (x, y) β s β§ (y, p.2) β d} in
have βp β s, βt β cl_d, is_open t β§ p β t, from
assume β¨x, yβ© hp, mem_nhds_sets_iff.mp $
show cl_d β π (x, y),
begin
rw [nhds_eq_uniformity_prod, mem_lift'_sets],
exact β¨d, hd, assume β¨a, bβ© β¨ha, hbβ©, β¨x, y, ha, hp, hbβ©β©,
exact monotone_prod monotone_preimage monotone_preimage
end,
have βt:(Ξ (p:Ξ±ΓΞ±) (h:p β s), set (Ξ±ΓΞ±)),
βp, βh:p β s, t p h β cl_d β§ is_open (t p h) β§ p β t p h,
by simp [classical.skolem] at this; simp; assumption,
match this with
| β¨t, htβ© :=
β¨(β p:Ξ±ΓΞ±, β h : p β s, t p h : set (Ξ±ΓΞ±)),
is_open_Union $ assume (p:Ξ±ΓΞ±), is_open_Union $ assume hp, (ht p hp).right.left,
assume β¨a, bβ© hp, begin simp; exact β¨a, b, hp, (ht (a,b) hp).right.rightβ© end,
Union_subset $ assume p, Union_subset $ assume hp, (ht p hp).leftβ©
end
/-- Entourages are neighborhoods of the diagonal. -/
lemma nhds_le_uniformity (x : Ξ±) : π (x, x) β€ π€ Ξ± :=
begin
intros V V_in,
rcases comp_symm_mem_uniformity_sets V_in with β¨w, w_in, w_symm, w_subβ©,
have : (ball x w).prod (ball x w) β π (x, x),
{ rw nhds_prod_eq,
exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) },
apply mem_sets_of_superset this,
rintros β¨u, vβ© β¨u_in, v_inβ©,
exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in)
end
/-- Entourages are neighborhoods of the diagonal. -/
lemma supr_nhds_le_uniformity : (β¨ x : Ξ±, π (x, x)) β€ π€ Ξ± :=
supr_le nhds_le_uniformity
/-!
### Closure and interior in uniform spaces
-/
lemma closure_eq_uniformity (s : set $ Ξ± Γ Ξ±) :
closure s = β V β {V | V β π€ Ξ± β§ symmetric_rel V}, V β s β V :=
begin
ext β¨x, yβ©,
simp_rw [mem_closure_iff_nhds_basis (uniform_space.has_basis_nhds_prod x y),
mem_Inter, mem_set_of_eq],
apply forall_congr,
intro V,
apply forall_congr,
rintros β¨V_in, V_symmβ©,
simp_rw [mem_comp_comp V_symm, inter_comm, exists_prop],
exact iff.rfl,
end
lemma uniformity_has_basis_closed : has_basis (π€ Ξ±) (Ξ» V : set (Ξ± Γ Ξ±), V β π€ Ξ± β§ is_closed V) id :=
begin
rw filter.has_basis_self,
intro t,
split,
{ intro h,
rcases comp_comp_symm_mem_uniformity_sets h with β¨w, w_in, w_symm, rβ©,
refine β¨closure w, _, is_closed_closure, _β©,
apply mem_sets_of_superset w_in subset_closure,
refine subset.trans _ r,
rw closure_eq_uniformity,
apply Inter_subset_of_subset,
apply Inter_subset,
exact β¨w_in, w_symmβ© },
{ rintros β¨r, r_in, r_closed, r_subβ©,
exact mem_sets_of_superset r_in r_sub, }
end
/-- Closed entourages form a basis of the uniformity filter. -/
lemma uniformity_has_basis_closure : has_basis (π€ Ξ±) (Ξ» V : set (Ξ± Γ Ξ±), V β π€ Ξ±) closure :=
β¨begin
intro t,
rw uniformity_has_basis_closed.mem_iff,
split,
{ rintros β¨r, β¨r_in, r_closedβ©, r_subβ©,
use [r, r_in],
convert r_sub,
rw r_closed.closure_eq,
refl },
{ rintros β¨r, r_in, r_subβ©,
exact β¨closure r, β¨mem_sets_of_superset r_in subset_closure, is_closed_closureβ©, r_subβ© }
endβ©
lemma closure_eq_inter_uniformity {t : set (Ξ±ΓΞ±)} :
closure t = (β d β π€ Ξ±, d β (t β d)) :=
set.ext $ assume β¨a, bβ©,
calc (a, b) β closure t β (π (a, b) β π t β β₯) : mem_closure_iff_cluster_pt
... β (((@prod.swap Ξ± Ξ±) <$> π€ Ξ±).lift'
(Ξ» (s : set (Ξ± Γ Ξ±)), set.prod {x : Ξ± | (x, a) β s} {y : Ξ± | (b, y) β s}) β π t β β₯) :
by rw [βuniformity_eq_symm, nhds_eq_uniformity_prod]
... β ((map (@prod.swap Ξ± Ξ±) (π€ Ξ±)).lift'
(Ξ» (s : set (Ξ± Γ Ξ±)), set.prod {x : Ξ± | (x, a) β s} {y : Ξ± | (b, y) β s}) β π t β β₯) :
by refl
... β ((π€ Ξ±).lift'
(Ξ» (s : set (Ξ± Γ Ξ±)), set.prod {y : Ξ± | (a, y) β s} {x : Ξ± | (x, b) β s}) β π t β β₯) :
begin
rw [map_lift'_eq2],
simp [image_swap_eq_preimage_swap, function.comp],
exact monotone_prod monotone_preimage monotone_preimage
end
... β (βs β π€ Ξ±, (set.prod {y : Ξ± | (a, y) β s} {x : Ξ± | (x, b) β s} β© t).nonempty) :
begin
rw [lift'_inf_principal_eq, β ne_bot, lift'_ne_bot_iff],
exact monotone_inter (monotone_prod monotone_preimage monotone_preimage) monotone_const
end
... β (β s β π€ Ξ±, (a, b) β s β (t β s)) :
forall_congr $ assume s, forall_congr $ assume hs,
β¨assume β¨β¨x, yβ©, β¨β¨hx, hyβ©, hxytβ©β©, β¨x, hx, y, hxyt, hyβ©,
assume β¨x, hx, y, hxyt, hyβ©, β¨β¨x, yβ©, β¨β¨hx, hyβ©, hxytβ©β©β©
... β _ : by simp
lemma uniformity_eq_uniformity_closure : π€ Ξ± = (π€ Ξ±).lift' closure :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, by simp; filter_upwards [hs] subset_closure)
(calc (π€ Ξ±).lift' closure β€ (π€ Ξ±).lift' (Ξ»d, d β (d β d)) :
lift'_mono' (by intros s hs; rw [closure_eq_inter_uniformity]; exact bInter_subset_of_mem hs)
... β€ (π€ Ξ±) : comp_le_uniformity3)
lemma uniformity_eq_uniformity_interior : π€ Ξ± = (π€ Ξ±).lift' interior :=
le_antisymm
(le_infi $ assume d, le_infi $ assume hd,
let β¨s, hs, hs_compβ© := (mem_lift'_sets $
monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp
(comp_le_uniformity3 hd) in
let β¨t, ht, hst, ht_compβ© := nhdset_of_mem_uniformity s hs in
have s β interior d, from
calc s β t : hst
... β interior d : (subset_interior_iff_subset_of_open ht).mpr $
Ξ» x (hx : x β t), let β¨x, y, hβ, hβ, hββ© := ht_comp hx in hs_comp β¨x, hβ, y, hβ, hββ©,
have interior d β π€ Ξ±, by filter_upwards [hs] this,
by simp [this])
(assume s hs, ((π€ Ξ±).lift' interior).sets_of_superset (mem_lift' hs) interior_subset)
lemma interior_mem_uniformity {s : set (Ξ± Γ Ξ±)} (hs : s β π€ Ξ±) :
interior s β π€ Ξ± :=
by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs
lemma mem_uniformity_is_closed {s : set (Ξ±ΓΞ±)} (h : s β π€ Ξ±) :
βt β π€ Ξ±, is_closed t β§ t β s :=
let β¨t, β¨ht_mem, htcβ©, htsβ© := uniformity_has_basis_closed.mem_iff.1 h in
β¨t, ht_mem, htc, htsβ©
/-- The uniform neighborhoods of all points of a dense set cover the whole space. -/
lemma dense.bUnion_uniformity_ball {s : set Ξ±} {U : set (Ξ± Γ Ξ±)} (hs : dense s) (hU : U β π€ Ξ±) :
(β x β s, ball x U) = univ :=
begin
refine bUnion_eq_univ_iff.2 (Ξ» y, _),
rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with β¨x, hxs, hxy : (x, y) β Uβ©,
exact β¨x, hxs, hxyβ©
end
/-!
### Uniformity bases
-/
/-- Open elements of `π€ Ξ±` form a basis of `π€ Ξ±`. -/
lemma uniformity_has_basis_open : has_basis (π€ Ξ±) (Ξ» V : set (Ξ± Γ Ξ±), V β π€ Ξ± β§ is_open V) id :=
has_basis_self.2 $ Ξ» s,
β¨Ξ» hs, β¨interior s, interior_mem_uniformity hs, is_open_interior, interior_subsetβ©,
Ξ» β¨t, htU, hto, htsβ©, mem_sets_of_superset htU htsβ©
lemma filter.has_basis.mem_uniformity_iff {p : Ξ² β Prop} {s : Ξ² β set (Ξ±ΓΞ±)}
(h : (π€ Ξ±).has_basis p s) {t : set (Ξ± Γ Ξ±)} :
t β π€ Ξ± β β i (hi : p i), β a b, (a, b) β s i β (a, b) β t :=
h.mem_iff.trans $ by simp only [prod.forall, subset_def]
/-- Symmetric entourages form a basis of `π€ Ξ±` -/
lemma uniform_space.has_basis_symmetric :
(π€ Ξ±).has_basis (Ξ» s : set (Ξ± Γ Ξ±), s β π€ Ξ± β§ symmetric_rel s) id :=
has_basis_self.2 $ Ξ» t,
β¨Ξ» t_in, β¨symmetrize_rel t, symmetrize_mem_uniformity t_in, symmetric_symmetrize_rel t,
symmetrize_rel_subset_self tβ©, Ξ» β¨s, s_in, _, hstβ©, mem_sets_of_superset s_in hstβ©
/-- Open elements `s : set (Ξ± Γ Ξ±)` of `π€ Ξ±` such that `(x, y) β s β (y, x) β s` form a basis
of `π€ Ξ±`. -/
lemma uniformity_has_basis_open_symmetric :
has_basis (π€ Ξ±) (Ξ» V : set (Ξ± Γ Ξ±), V β π€ Ξ± β§ is_open V β§ symmetric_rel V) id :=
begin
simp only [β and_assoc],
refine uniformity_has_basis_open.restrict (Ξ» s hs, β¨symmetrize_rel s, _β©),
exact β¨β¨symmetrize_mem_uniformity hs.1, is_open_inter hs.2 (hs.2.preimage continuous_swap)β©,
symmetric_symmetrize_rel s, symmetrize_rel_subset_self sβ©
end
lemma uniform_space.has_seq_basis (h : is_countably_generated $ π€ Ξ±) :
β V : β β set (Ξ± Γ Ξ±), has_antimono_basis (π€ Ξ±) (Ξ» _, true) V β§ β n, symmetric_rel (V n) :=
let β¨U, hsym, hbasisβ© := h.exists_antimono_subbasis uniform_space.has_basis_symmetric
in β¨U, hbasis, Ξ» n, (hsym n).2β©
/-! ### Uniform continuity -/
/-- A function `f : Ξ± β Ξ²` is *uniformly continuous* if `(f x, f y)` tends to the diagonal
as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then
`f x` is close to `f y` no matter where `x` and `y` are located in `Ξ±`. -/
def uniform_continuous [uniform_space Ξ²] (f : Ξ± β Ξ²) :=
tendsto (Ξ»x:Ξ±ΓΞ±, (f x.1, f x.2)) (π€ Ξ±) (π€ Ξ²)
/-- A function `f : Ξ± β Ξ²` is *uniformly continuous* on `s : set Ξ±` if `(f x, f y)` tends to
the diagonal as `(x, y)` tends to the diagonal while remaining in `s.prod s`.
In other words, if `x` is sufficiently close to `y`, then `f x` is close to
`f y` no matter where `x` and `y` are located in `s`.-/
def uniform_continuous_on [uniform_space Ξ²] (f : Ξ± β Ξ²) (s : set Ξ±) : Prop :=
tendsto (Ξ» x : Ξ± Γ Ξ±, (f x.1, f x.2)) (π€ Ξ± β principal (s.prod s)) (π€ Ξ²)
theorem uniform_continuous_def [uniform_space Ξ²] {f : Ξ± β Ξ²} :
uniform_continuous f β β r β π€ Ξ², { x : Ξ± Γ Ξ± | (f x.1, f x.2) β r} β π€ Ξ± :=
iff.rfl
theorem uniform_continuous_iff_eventually [uniform_space Ξ²] {f : Ξ± β Ξ²} :
uniform_continuous f β β r β π€ Ξ², βαΆ (x : Ξ± Γ Ξ±) in π€ Ξ±, (f x.1, f x.2) β r :=
iff.rfl
lemma uniform_continuous_of_const [uniform_space Ξ²] {c : Ξ± β Ξ²} (h : βa b, c a = c b) :
uniform_continuous c :=
have (Ξ» (x : Ξ± Γ Ξ±), (c (x.fst), c (x.snd))) β»ΒΉ' id_rel = univ, from
eq_univ_iff_forall.2 $ assume β¨a, bβ©, h a b,
le_trans (map_le_iff_le_comap.2 $ by simp [comap_principal, this, univ_mem_sets]) refl_le_uniformity
lemma uniform_continuous_id : uniform_continuous (@id Ξ±) :=
by simp [uniform_continuous]; exact tendsto_id
lemma uniform_continuous_const [uniform_space Ξ²] {b : Ξ²} : uniform_continuous (Ξ»a:Ξ±, b) :=
uniform_continuous_of_const $ Ξ» _ _, rfl
lemma uniform_continuous.comp [uniform_space Ξ²] [uniform_space Ξ³] {g : Ξ² β Ξ³} {f : Ξ± β Ξ²}
(hg : uniform_continuous g) (hf : uniform_continuous f) : uniform_continuous (g β f) :=
hg.comp hf
lemma filter.has_basis.uniform_continuous_iff [uniform_space Ξ²] {p : Ξ³ β Prop} {s : Ξ³ β set (Ξ±ΓΞ±)}
(ha : (π€ Ξ±).has_basis p s) {q : Ξ΄ β Prop} {t : Ξ΄ β set (Ξ²ΓΞ²)} (hb : (π€ Ξ²).has_basis q t)
{f : Ξ± β Ξ²} :
uniform_continuous f β β i (hi : q i), β j (hj : p j), β x y, (x, y) β s j β (f x, f y) β t i :=
(ha.tendsto_iff hb).trans $ by simp only [prod.forall]
lemma filter.has_basis.uniform_continuous_on_iff [uniform_space Ξ²] {p : Ξ³ β Prop}
{s : Ξ³ β set (Ξ±ΓΞ±)} (ha : (π€ Ξ±).has_basis p s) {q : Ξ΄ β Prop} {t : Ξ΄ β set (Ξ²ΓΞ²)}
(hb : (π€ Ξ²).has_basis q t) {f : Ξ± β Ξ²} {S : set Ξ±} :
uniform_continuous_on f S β
β i (hi : q i), β j (hj : p j), β x y β S, (x, y) β s j β (f x, f y) β t i :=
((ha.inf_principal (S.prod S)).tendsto_iff hb).trans $ by finish [prod.forall]
end uniform_space
open_locale uniformity
section constructions
instance : partial_order (uniform_space Ξ±) :=
{ le := Ξ»t s, t.uniformity β€ s.uniformity,
le_antisymm := assume t s hβ hβ, uniform_space_eq $ le_antisymm hβ hβ,
le_refl := assume t, le_refl _,
le_trans := assume a b c hβ hβ, le_trans hβ hβ }
instance : has_Inf (uniform_space Ξ±) :=
β¨assume s, uniform_space.of_core {
uniformity := (β¨
uβs, @uniformity Ξ± u),
refl := le_infi $ assume u, le_infi $ assume hu, u.refl,
symm := le_infi $ assume u, le_infi $ assume hu,
le_trans (map_mono $ infi_le_of_le _ $ infi_le _ hu) u.symm,
comp := le_infi $ assume u, le_infi $ assume hu,
le_trans (lift'_mono (infi_le_of_le _ $ infi_le _ hu) $ le_refl _) u.comp }β©
private lemma Inf_le {tt : set (uniform_space Ξ±)} {t : uniform_space Ξ±} (h : t β tt) :
Inf tt β€ t :=
show (β¨
uβtt, @uniformity Ξ± u) β€ t.uniformity,
from infi_le_of_le t $ infi_le _ h
private lemma le_Inf {tt : set (uniform_space Ξ±)} {t : uniform_space Ξ±} (h : βt'βtt, t β€ t') :
t β€ Inf tt :=
show t.uniformity β€ (β¨
uβtt, @uniformity Ξ± u),
from le_infi $ assume t', le_infi $ assume ht', h t' ht'
instance : has_top (uniform_space Ξ±) :=
β¨uniform_space.of_core { uniformity := β€, refl := le_top, symm := le_top, comp := le_top }β©
instance : has_bot (uniform_space Ξ±) :=
β¨{ to_topological_space := β₯,
uniformity := π id_rel,
refl := le_refl _,
symm := by simp [tendsto]; apply subset.refl,
comp :=
begin
rw [lift'_principal], {simp},
exact monotone_comp_rel monotone_id monotone_id
end,
is_open_uniformity :=
assume s, by simp [is_open_fold, subset_def, id_rel] {contextual := tt } } β©
instance : complete_lattice (uniform_space Ξ±) :=
{ sup := Ξ»a b, Inf {x | a β€ x β§ b β€ x},
le_sup_left := Ξ» a b, le_Inf (Ξ» _ β¨h, _β©, h),
le_sup_right := Ξ» a b, le_Inf (Ξ» _ β¨_, hβ©, h),
sup_le := Ξ» a b c hβ hβ, Inf_le β¨hβ, hββ©,
inf := Ξ» a b, Inf {a, b},
le_inf := Ξ» a b c hβ hβ, le_Inf (Ξ» u h,
by { cases h, exact h.symm βΈ hβ, exact (mem_singleton_iff.1 h).symm βΈ hβ }),
inf_le_left := Ξ» a b, Inf_le (by simp),
inf_le_right := Ξ» a b, Inf_le (by simp),
top := β€,
le_top := Ξ» a, show a.uniformity β€ β€, from le_top,
bot := β₯,
bot_le := Ξ» u, u.refl,
Sup := Ξ» tt, Inf {t | β t' β tt, t' β€ t},
le_Sup := Ξ» s u h, le_Inf (Ξ» u' h', h' u h),
Sup_le := Ξ» s u h, Inf_le h,
Inf := Inf,
le_Inf := Ξ» s a hs, le_Inf hs,
Inf_le := Ξ» s a ha, Inf_le ha,
..uniform_space.partial_order }
lemma infi_uniformity {ΞΉ : Sort*} {u : ΞΉ β uniform_space Ξ±} :
(infi u).uniformity = (β¨
i, (u i).uniformity) :=
show (β¨
a (h : βi:ΞΉ, u i = a), a.uniformity) = _, from
le_antisymm
(le_infi $ assume i, infi_le_of_le (u i) $ infi_le _ β¨i, rflβ©)
(le_infi $ assume a, le_infi $ assume β¨i, (ha : u i = a)β©, ha βΈ infi_le _ _)
lemma inf_uniformity {u v : uniform_space Ξ±} :
(u β v).uniformity = u.uniformity β v.uniformity :=
have (u β v) = (β¨
i (h : i = u β¨ i = v), i), by simp [infi_or, infi_inf_eq],
calc (u β v).uniformity = ((β¨
i (h : i = u β¨ i = v), i) : uniform_space Ξ±).uniformity : by rw [this]
... = _ : by simp [infi_uniformity, infi_or, infi_inf_eq]
instance inhabited_uniform_space : inhabited (uniform_space Ξ±) := β¨β₯β©
instance inhabited_uniform_space_core : inhabited (uniform_space.core Ξ±) :=
β¨@uniform_space.to_core _ (default _)β©
/-- Given `f : Ξ± β Ξ²` and a uniformity `u` on `Ξ²`, the inverse image of `u` under `f`
is the inverse image in the filter sense of the induced function `Ξ± Γ Ξ± β Ξ² Γ Ξ²`. -/
def uniform_space.comap (f : Ξ± β Ξ²) (u : uniform_space Ξ²) : uniform_space Ξ± :=
{ uniformity := u.uniformity.comap (Ξ»p:Ξ±ΓΞ±, (f p.1, f p.2)),
to_topological_space := u.to_topological_space.induced f,
refl := le_trans (by simp; exact assume β¨a, bβ© (h : a = b), h βΈ rfl) (comap_mono u.refl),
symm := by simp [tendsto_comap_iff, prod.swap, (β)];
exact tendsto_swap_uniformity.comp tendsto_comap,
comp := le_trans
begin
rw [comap_lift'_eq, comap_lift'_eq2],
exact (lift'_mono' $ assume s hs β¨aβ, aββ© β¨x, hβ, hββ©, β¨f x, hβ, hββ©),
repeat { exact monotone_comp_rel monotone_id monotone_id }
end
(comap_mono u.comp),
is_open_uniformity := Ξ» s, begin
change (@is_open Ξ± (u.to_topological_space.induced f) s β _),
simp [is_open_iff_nhds, nhds_induced, mem_nhds_uniformity_iff_right, filter.comap, and_comm],
refine ball_congr (Ξ» x hx, β¨_, _β©),
{ rintro β¨t, hts, htβ©, refine β¨_, ht, _β©,
rintro β¨xβ, xββ© h rfl, exact hts (h rfl) },
{ rintro β¨t, ht, htsβ©,
exact β¨{y | (f x, y) β t}, Ξ» y hy, @hts (x, y) hy rfl,
mem_nhds_uniformity_iff_right.1 $ mem_nhds_left _ htβ© }
end }
lemma uniformity_comap [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β Ξ²}
(h : βΉuniform_space Ξ±βΊ = uniform_space.comap f βΉuniform_space Ξ²βΊ) :
π€ Ξ± = comap (prod.map f f) (π€ Ξ²) :=
by { rw h, refl }
lemma uniform_space_comap_id {Ξ± : Type*} : uniform_space.comap (id : Ξ± β Ξ±) = id :=
by ext u ; dsimp [uniform_space.comap] ; rw [prod.id_prod, filter.comap_id]
lemma uniform_space.comap_comap {Ξ± Ξ² Ξ³} [uΞ³ : uniform_space Ξ³] {f : Ξ± β Ξ²} {g : Ξ² β Ξ³} :
uniform_space.comap (g β f) uΞ³ = uniform_space.comap f (uniform_space.comap g uΞ³) :=
by ext ; dsimp [uniform_space.comap] ; rw filter.comap_comap
lemma uniform_continuous_iff {Ξ± Ξ²} [uΞ± : uniform_space Ξ±] [uΞ² : uniform_space Ξ²] {f : Ξ± β Ξ²} :
uniform_continuous f β uΞ± β€ uΞ².comap f :=
filter.map_le_iff_le_comap
lemma uniform_continuous_comap {f : Ξ± β Ξ²} [u : uniform_space Ξ²] :
@uniform_continuous Ξ± Ξ² (uniform_space.comap f u) u f :=
tendsto_comap
theorem to_topological_space_comap {f : Ξ± β Ξ²} {u : uniform_space Ξ²} :
@uniform_space.to_topological_space _ (uniform_space.comap f u) =
topological_space.induced f (@uniform_space.to_topological_space Ξ² u) := rfl
lemma uniform_continuous_comap' {f : Ξ³ β Ξ²} {g : Ξ± β Ξ³} [v : uniform_space Ξ²] [u : uniform_space Ξ±]
(h : uniform_continuous (f β g)) : @uniform_continuous Ξ± Ξ³ u (uniform_space.comap f v) g :=
tendsto_comap_iff.2 h
lemma to_topological_space_mono {uβ uβ : uniform_space Ξ±} (h : uβ β€ uβ) :
@uniform_space.to_topological_space _ uβ β€ @uniform_space.to_topological_space _ uβ :=
le_of_nhds_le_nhds $ assume a,
by rw [@nhds_eq_uniformity Ξ± uβ a, @nhds_eq_uniformity Ξ± uβ a]; exact (lift'_mono h $ le_refl _)
lemma uniform_continuous.continuous [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β Ξ²}
(hf : uniform_continuous f) : continuous f :=
continuous_iff_le_induced.mpr $ to_topological_space_mono $ uniform_continuous_iff.1 hf
lemma to_topological_space_bot : @uniform_space.to_topological_space Ξ± β₯ = β₯ := rfl
lemma to_topological_space_top : @uniform_space.to_topological_space Ξ± β€ = β€ :=
top_unique $ assume s hs, s.eq_empty_or_nonempty.elim
(assume : s = β
, this.symm βΈ @is_open_empty _ β€)
(assume β¨x, hxβ©,
have s = univ, from top_unique $ assume y hy, hs x hx (x, y) rfl,
this.symm βΈ @is_open_univ _ β€)
lemma to_topological_space_infi {ΞΉ : Sort*} {u : ΞΉ β uniform_space Ξ±} :
(infi u).to_topological_space = β¨
i, (u i).to_topological_space :=
begin
by_cases h : nonempty ΞΉ,
{ resetI,
refine (eq_of_nhds_eq_nhds $ assume a, _),
rw [nhds_infi, nhds_eq_uniformity],
change (infi u).uniformity.lift' (preimage $ prod.mk a) = _,
rw [infi_uniformity, lift'_infi],
{ simp only [nhds_eq_uniformity], refl },
{ exact assume a b, rfl } },
{ rw [infi_of_empty h, infi_of_empty h, to_topological_space_top] }
end
lemma to_topological_space_Inf {s : set (uniform_space Ξ±)} :
(Inf s).to_topological_space = (β¨
iβs, @uniform_space.to_topological_space Ξ± i) :=
begin
rw [Inf_eq_infi],
simp only [β to_topological_space_infi],
end
lemma to_topological_space_inf {u v : uniform_space Ξ±} :
(u β v).to_topological_space = u.to_topological_space β v.to_topological_space :=
by rw [to_topological_space_Inf, infi_pair]
instance : uniform_space empty := β₯
instance : uniform_space unit := β₯
instance : uniform_space bool := β₯
instance : uniform_space β := β₯
instance : uniform_space β€ := β₯
instance {p : Ξ± β Prop} [t : uniform_space Ξ±] : uniform_space (subtype p) :=
uniform_space.comap subtype.val t
lemma uniformity_subtype {p : Ξ± β Prop} [t : uniform_space Ξ±] :
π€ (subtype p) = comap (Ξ»q:subtype p Γ subtype p, (q.1.1, q.2.1)) (π€ Ξ±) :=
rfl
lemma uniform_continuous_subtype_val {p : Ξ± β Prop} [uniform_space Ξ±] :
uniform_continuous (subtype.val : {a : Ξ± // p a} β Ξ±) :=
uniform_continuous_comap
lemma uniform_continuous_subtype_mk {p : Ξ± β Prop} [uniform_space Ξ±] [uniform_space Ξ²]
{f : Ξ² β Ξ±} (hf : uniform_continuous f) (h : βx, p (f x)) :
uniform_continuous (Ξ»x, β¨f x, h xβ© : Ξ² β subtype p) :=
uniform_continuous_comap' hf
lemma uniform_continuous_on_iff_restrict [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β Ξ²}
{s : set Ξ±} :
uniform_continuous_on f s β uniform_continuous (s.restrict f) :=
begin
unfold uniform_continuous_on set.restrict uniform_continuous tendsto,
rw [show (Ξ» x : s Γ s, (f x.1, f x.2)) = prod.map f f β coe, by ext x; cases x; refl,
uniformity_comap rfl,
show prod.map subtype.val subtype.val = (coe : s Γ s β Ξ± Γ Ξ±), by ext x; cases x; refl],
conv in (map _ (comap _ _)) { rw β filter.map_map },
rw subtype_coe_map_comap_prod, refl,
end
lemma tendsto_of_uniform_continuous_subtype
[uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±}
(hf : uniform_continuous (Ξ»x:s, f x.val)) (ha : s β π a) :
tendsto f (π a) (π (f a)) :=
by rw [(@map_nhds_subtype_coe_eq Ξ± _ s a (mem_of_nhds ha) ha).symm]; exact
tendsto_map' (continuous_iff_continuous_at.mp hf.continuous _)
lemma uniform_continuous_on.continuous_on [uniform_space Ξ±] [uniform_space Ξ²] {f : Ξ± β Ξ²}
{s : set Ξ±} (h : uniform_continuous_on f s) : continuous_on f s :=
begin
rw uniform_continuous_on_iff_restrict at h,
rw continuous_on_iff_continuous_restrict,
exact h.continuous
end
section prod
/- a similar product space is possible on the function space (uniformity of pointwise convergence),
but we want to have the uniformity of uniform convergence on function spaces -/
instance [uβ : uniform_space Ξ±] [uβ : uniform_space Ξ²] : uniform_space (Ξ± Γ Ξ²) :=
uniform_space.of_core_eq
(uβ.comap prod.fst β uβ.comap prod.snd).to_core
prod.topological_space
(calc prod.topological_space = (uβ.comap prod.fst β uβ.comap prod.snd).to_topological_space :
by rw [to_topological_space_inf, to_topological_space_comap, to_topological_space_comap]; refl
... = _ : by rw [uniform_space.to_core_to_topological_space])
theorem uniformity_prod [uniform_space Ξ±] [uniform_space Ξ²] : π€ (Ξ± Γ Ξ²) =
(π€ Ξ±).comap (Ξ»p:(Ξ± Γ Ξ²) Γ Ξ± Γ Ξ², (p.1.1, p.2.1)) β
(π€ Ξ²).comap (Ξ»p:(Ξ± Γ Ξ²) Γ Ξ± Γ Ξ², (p.1.2, p.2.2)) :=
inf_uniformity
lemma uniformity_prod_eq_prod [uniform_space Ξ±] [uniform_space Ξ²] :
π€ (Ξ±ΓΞ²) =
map (Ξ»p:(Ξ±ΓΞ±)Γ(Ξ²ΓΞ²), ((p.1.1, p.2.1), (p.1.2, p.2.2))) (π€ Ξ± ΓαΆ π€ Ξ²) :=
have map (Ξ»p:(Ξ±ΓΞ±)Γ(Ξ²ΓΞ²), ((p.1.1, p.2.1), (p.1.2, p.2.2))) =
comap (Ξ»p:(Ξ±ΓΞ²)Γ(Ξ±ΓΞ²), ((p.1.1, p.2.1), (p.1.2, p.2.2))),
from funext $ assume f, map_eq_comap_of_inverse
(funext $ assume β¨β¨_, _β©, β¨_, _β©β©, rfl) (funext $ assume β¨β¨_, _β©, β¨_, _β©β©, rfl),
by rw [this, uniformity_prod, filter.prod, comap_inf, comap_comap, comap_comap]
lemma mem_map_sets_iff' {Ξ± : Type*} {Ξ² : Type*} {f : filter Ξ±} {m : Ξ± β Ξ²} {t : set Ξ²} :
t β (map m f).sets β (βsβf, m '' s β t) :=
mem_map_sets_iff
lemma mem_uniformity_of_uniform_continuous_invariant [uniform_space Ξ±] {s:set (Ξ±ΓΞ±)} {f : Ξ± β Ξ± β Ξ±}
(hf : uniform_continuous (Ξ»p:Ξ±ΓΞ±, f p.1 p.2)) (hs : s β π€ Ξ±) :
βuβπ€ Ξ±, βa b c, (a, b) β u β (f a c, f b c) β s :=
begin
rw [uniform_continuous, uniformity_prod_eq_prod, tendsto_map'_iff, (β)] at hf,
rcases mem_map_sets_iff'.1 (hf hs) with β¨t, ht, htsβ©, clear hf,
rcases mem_prod_iff.1 ht with β¨u, hu, v, hv, huvtβ©, clear ht,
refine β¨u, hu, assume a b c hab, hts $ (mem_image _ _ _).2 β¨β¨β¨a, bβ©, β¨c, cβ©β©, huvt β¨_, _β©, _β©β©,
exact hab,
exact refl_mem_uniformity hv,
refl
end
lemma mem_uniform_prod [tβ : uniform_space Ξ±] [tβ : uniform_space Ξ²] {a : set (Ξ± Γ Ξ±)}
{b : set (Ξ² Γ Ξ²)} (ha : a β π€ Ξ±) (hb : b β π€ Ξ²) :
{p:(Ξ±ΓΞ²)Γ(Ξ±ΓΞ²) | (p.1.1, p.2.1) β a β§ (p.1.2, p.2.2) β b } β (@uniformity (Ξ± Γ Ξ²) _) :=
by rw [uniformity_prod]; exact inter_mem_inf_sets (preimage_mem_comap ha) (preimage_mem_comap hb)
lemma tendsto_prod_uniformity_fst [uniform_space Ξ±] [uniform_space Ξ²] :
tendsto (Ξ»p:(Ξ±ΓΞ²)Γ(Ξ±ΓΞ²), (p.1.1, p.2.1)) (π€ (Ξ± Γ Ξ²)) (π€ Ξ±) :=
le_trans (map_mono (@inf_le_left (uniform_space (Ξ±ΓΞ²)) _ _ _)) map_comap_le
lemma tendsto_prod_uniformity_snd [uniform_space Ξ±] [uniform_space Ξ²] :
tendsto (Ξ»p:(Ξ±ΓΞ²)Γ(Ξ±ΓΞ²), (p.1.2, p.2.2)) (π€ (Ξ± Γ Ξ²)) (π€ Ξ²) :=
le_trans (map_mono (@inf_le_right (uniform_space (Ξ±ΓΞ²)) _ _ _)) map_comap_le
lemma uniform_continuous_fst [uniform_space Ξ±] [uniform_space Ξ²] :
uniform_continuous (Ξ»p:Ξ±ΓΞ², p.1) :=
tendsto_prod_uniformity_fst
lemma uniform_continuous_snd [uniform_space Ξ±] [uniform_space Ξ²] :
uniform_continuous (Ξ»p:Ξ±ΓΞ², p.2) :=
tendsto_prod_uniformity_snd
variables [uniform_space Ξ±] [uniform_space Ξ²] [uniform_space Ξ³]
lemma uniform_continuous.prod_mk
{fβ : Ξ± β Ξ²} {fβ : Ξ± β Ξ³} (hβ : uniform_continuous fβ) (hβ : uniform_continuous fβ) :
uniform_continuous (Ξ»a, (fβ a, fβ a)) :=
by rw [uniform_continuous, uniformity_prod]; exact
tendsto_inf.2 β¨tendsto_comap_iff.2 hβ, tendsto_comap_iff.2 hββ©
lemma uniform_continuous.prod_mk_left {f : Ξ± Γ Ξ² β Ξ³} (h : uniform_continuous f) (b) :
uniform_continuous (Ξ» a, f (a,b)) :=
h.comp (uniform_continuous_id.prod_mk uniform_continuous_const)
lemma uniform_continuous.prod_mk_right {f : Ξ± Γ Ξ² β Ξ³} (h : uniform_continuous f) (a) :
uniform_continuous (Ξ» b, f (a,b)) :=
h.comp (uniform_continuous_const.prod_mk uniform_continuous_id)
lemma uniform_continuous.prod_map [uniform_space Ξ΄] {f : Ξ± β Ξ³} {g : Ξ² β Ξ΄}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (prod.map f g) :=
(hf.comp uniform_continuous_fst).prod_mk (hg.comp uniform_continuous_snd)
lemma to_topological_space_prod {Ξ±} {Ξ²} [u : uniform_space Ξ±] [v : uniform_space Ξ²] :
@uniform_space.to_topological_space (Ξ± Γ Ξ²) prod.uniform_space =
@prod.topological_space Ξ± Ξ² u.to_topological_space v.to_topological_space := rfl
end prod
section
open uniform_space function
variables {Ξ΄' : Type*} [uniform_space Ξ±] [uniform_space Ξ²] [uniform_space Ξ³] [uniform_space Ξ΄]
[uniform_space Ξ΄']
local notation f `ββ` g := function.bicompr f g
/-- Uniform continuity for functions of two variables. -/
def uniform_continuousβ (f : Ξ± β Ξ² β Ξ³) := uniform_continuous (uncurry f)
lemma uniform_continuousβ_def (f : Ξ± β Ξ² β Ξ³) :
uniform_continuousβ f β uniform_continuous (uncurry f) := iff.rfl
lemma uniform_continuousβ.uniform_continuous {f : Ξ± β Ξ² β Ξ³} (h : uniform_continuousβ f) :
uniform_continuous (uncurry f) := h
lemma uniform_continuousβ_curry (f : Ξ± Γ Ξ² β Ξ³) :
uniform_continuousβ (function.curry f) β uniform_continuous f :=
by rw [uniform_continuousβ, uncurry_curry]
lemma uniform_continuousβ.comp {f : Ξ± β Ξ² β Ξ³} {g : Ξ³ β Ξ΄}
(hg : uniform_continuous g) (hf : uniform_continuousβ f) :
uniform_continuousβ (g ββ f) :=
hg.comp hf
lemma uniform_continuousβ.bicompl {f : Ξ± β Ξ² β Ξ³} {ga : Ξ΄ β Ξ±} {gb : Ξ΄' β Ξ²}
(hf : uniform_continuousβ f) (hga : uniform_continuous ga) (hgb : uniform_continuous gb) :
uniform_continuousβ (bicompl f ga gb) :=
hf.uniform_continuous.comp (hga.prod_map hgb)
end
lemma to_topological_space_subtype [u : uniform_space Ξ±] {p : Ξ± β Prop} :
@uniform_space.to_topological_space (subtype p) subtype.uniform_space =
@subtype.topological_space Ξ± p u.to_topological_space := rfl
section sum
variables [uniform_space Ξ±] [uniform_space Ξ²]
open sum
/-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained
by taking independently an entourage of the diagonal in the first part, and an entourage of
the diagonal in the second part. -/
def uniform_space.core.sum : uniform_space.core (Ξ± β Ξ²) :=
uniform_space.core.mk'
(map (Ξ» p : Ξ± Γ Ξ±, (inl p.1, inl p.2)) (π€ Ξ±) β map (Ξ» p : Ξ² Γ Ξ², (inr p.1, inr p.2)) (π€ Ξ²))
(Ξ» r β¨Hβ, Hββ© x, by cases x; [apply refl_mem_uniformity Hβ, apply refl_mem_uniformity Hβ])
(Ξ» r β¨Hβ, Hββ©, β¨symm_le_uniformity Hβ, symm_le_uniformity Hββ©)
(Ξ» r β¨HrΞ±, HrΞ²β©, begin
rcases comp_mem_uniformity_sets HrΞ± with β¨tΞ±, htΞ±, HtΞ±β©,
rcases comp_mem_uniformity_sets HrΞ² with β¨tΞ², htΞ², HtΞ²β©,
refine β¨_,
β¨mem_map_sets_iff.2 β¨tΞ±, htΞ±, subset_union_left _ _β©,
mem_map_sets_iff.2 β¨tΞ², htΞ², subset_union_right _ _β©β©, _β©,
rintros β¨_, _β© β¨z, β¨β¨a, bβ©, hab, β¨β©β© | β¨β¨a, bβ©, hab, β¨β©β©,
β¨β¨_, cβ©, hbc, β¨β©β© | β¨β¨_, cβ©, hbc, β¨β©β©β©,
{ have A : (a, c) β tΞ± β tΞ± := β¨b, hab, hbcβ©,
exact HtΞ± A },
{ have A : (a, c) β tΞ² β tΞ² := β¨b, hab, hbcβ©,
exact HtΞ² A }
end)
/-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage
of the diagonal. -/
lemma union_mem_uniformity_sum
{a : set (Ξ± Γ Ξ±)} (ha : a β π€ Ξ±) {b : set (Ξ² Γ Ξ²)} (hb : b β π€ Ξ²) :
((Ξ» p : (Ξ± Γ Ξ±), (inl p.1, inl p.2)) '' a βͺ (Ξ» p : (Ξ² Γ Ξ²), (inr p.1, inr p.2)) '' b) β
(@uniform_space.core.sum Ξ± Ξ² _ _).uniformity :=
β¨mem_map_sets_iff.2 β¨_, ha, subset_union_left _ _β©,
mem_map_sets_iff.2 β¨_, hb, subset_union_right _ _β©β©
/- To prove that the topology defined by the uniform structure on the disjoint union coincides with
the disjoint union topology, we need two lemmas saying that open sets can be characterized by
the uniform structure -/
lemma uniformity_sum_of_open_aux {s : set (Ξ± β Ξ²)} (hs : is_open s) {x : Ξ± β Ξ²} (xs : x β s) :
{ p : ((Ξ± β Ξ²) Γ (Ξ± β Ξ²)) | p.1 = x β p.2 β s } β (@uniform_space.core.sum Ξ± Ξ² _ _).uniformity :=
begin
cases x,
{ refine mem_sets_of_superset
(union_mem_uniformity_sum (mem_nhds_uniformity_iff_right.1 (mem_nhds_sets hs.1 xs))
univ_mem_sets)
(union_subset _ _);
rintro _ β¨β¨_, bβ©, h, β¨β©β© β¨β©,
exact h rfl },
{ refine mem_sets_of_superset
(union_mem_uniformity_sum univ_mem_sets (mem_nhds_uniformity_iff_right.1
(mem_nhds_sets hs.2 xs)))
(union_subset _ _);
rintro _ β¨β¨a, _β©, h, β¨β©β© β¨β©,
exact h rfl },
end
lemma open_of_uniformity_sum_aux {s : set (Ξ± β Ξ²)}
(hs : βx β s, { p : ((Ξ± β Ξ²) Γ (Ξ± β Ξ²)) | p.1 = x β p.2 β s } β
(@uniform_space.core.sum Ξ± Ξ² _ _).uniformity) :
is_open s :=
begin
split,
{ refine (@is_open_iff_mem_nhds Ξ± _ _).2 (Ξ» a ha, mem_nhds_uniformity_iff_right.2 _),
rcases mem_map_sets_iff.1 (hs _ ha).1 with β¨t, ht, stβ©,
refine mem_sets_of_superset ht _,
rintro p pt rfl, exact st β¨_, pt, rflβ© rfl },
{ refine (@is_open_iff_mem_nhds Ξ² _ _).2 (Ξ» b hb, mem_nhds_uniformity_iff_right.2 _),
rcases mem_map_sets_iff.1 (hs _ hb).2 with β¨t, ht, stβ©,
refine mem_sets_of_superset ht _,
rintro p pt rfl, exact st β¨_, pt, rflβ© rfl }
end
/- We can now define the uniform structure on the disjoint union -/
instance sum.uniform_space : uniform_space (Ξ± β Ξ²) :=
{ to_core := uniform_space.core.sum,
is_open_uniformity := Ξ» s, β¨uniformity_sum_of_open_aux, open_of_uniformity_sum_auxβ© }
lemma sum.uniformity : π€ (Ξ± β Ξ²) =
map (Ξ» p : Ξ± Γ Ξ±, (inl p.1, inl p.2)) (π€ Ξ±) β
map (Ξ» p : Ξ² Γ Ξ², (inr p.1, inr p.2)) (π€ Ξ²) := rfl
end sum
end constructions
-- For a version of the Lebesgue number lemma assuming only a sequentially compact space,
-- see topology/sequences.lean
/-- Let `c : ΞΉ β set Ξ±` be an open cover of a compact set `s`. Then there exists an entourage
`n` such that for each `x β s` its `n`-neighborhood is contained in some `c i`. -/
lemma lebesgue_number_lemma {Ξ± : Type u} [uniform_space Ξ±] {s : set Ξ±} {ΞΉ} {c : ΞΉ β set Ξ±}
(hs : is_compact s) (hcβ : β i, is_open (c i)) (hcβ : s β β i, c i) :
β n β π€ Ξ±, β x β s, β i, {y | (x, y) β n} β c i :=
begin
let u := Ξ» n, {x | β i (m β π€ Ξ±), {y | (x, y) β m β n} β c i},
have huβ : β n β π€ Ξ±, is_open (u n),
{ refine Ξ» n hn, is_open_uniformity.2 _,
rintro x β¨i, m, hm, hβ©,
rcases comp_mem_uniformity_sets hm with β¨m', hm', mm'β©,
apply (π€ Ξ±).sets_of_superset hm',
rintros β¨x, yβ© hp rfl,
refine β¨i, m', hm', Ξ» z hz, h (monotone_comp_rel monotone_id monotone_const mm' _)β©,
dsimp at hz β’, rw comp_rel_assoc,
exact β¨y, hp, hzβ© },
have huβ : s β β n β π€ Ξ±, u n,
{ intros x hx,
rcases mem_Union.1 (hcβ hx) with β¨i, hβ©,
rcases comp_mem_uniformity_sets (is_open_uniformity.1 (hcβ i) x h) with β¨m', hm', mm'β©,
exact mem_bUnion hm' β¨i, _, hm', Ξ» y hy, mm' hy rflβ© },
rcases hs.elim_finite_subcover_image huβ huβ with β¨b, bu, b_fin, b_coverβ©,
refine β¨_, (bInter_mem_sets b_fin).2 bu, Ξ» x hx, _β©,
rcases mem_bUnion_iff.1 (b_cover hx) with β¨n, bn, i, m, hm, hβ©,
refine β¨i, Ξ» y hy, h _β©,
exact prod_mk_mem_comp_rel (refl_mem_uniformity hm) (bInter_subset_of_mem bn hy)
end
/-- Let `c : set (set Ξ±)` be an open cover of a compact set `s`. Then there exists an entourage
`n` such that for each `x β s` its `n`-neighborhood is contained in some `t β c`. -/
lemma lebesgue_number_lemma_sUnion {Ξ± : Type u} [uniform_space Ξ±] {s : set Ξ±} {c : set (set Ξ±)}
(hs : is_compact s) (hcβ : β t β c, is_open t) (hcβ : s β ββ c) :
β n β π€ Ξ±, β x β s, β t β c, β y, (x, y) β n β y β t :=
by rw sUnion_eq_Union at hcβ;
simpa using lebesgue_number_lemma hs (by simpa) hcβ
/-!
### Expressing continuity properties in uniform spaces
We reformulate the various continuity properties of functions taking values in a uniform space
in terms of the uniformity in the target. Since the same lemmas (essentially with the same names)
also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or
the edistance in the target), we put them in a namespace `uniform` here.
In the metric and emetric space setting, there are also similar lemmas where one assumes that
both the source and the target are metric spaces, reformulating things in terms of the distance
on both sides. These lemmas are generally written without primes, and the versions where only
the target is a metric space is primed. We follow the same convention here, thus giving lemmas
with primes.
-/
namespace uniform
variables [uniform_space Ξ±]
theorem tendsto_nhds_right {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±} :
tendsto u f (π a) β tendsto (Ξ» x, (a, u x)) f (π€ Ξ±) :=
β¨Ξ» H, tendsto_left_nhds_uniformity.comp H,
Ξ» H s hs, by simpa [mem_of_nhds hs] using H (mem_nhds_uniformity_iff_right.1 hs)β©
theorem tendsto_nhds_left {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±} :
tendsto u f (π a) β tendsto (Ξ» x, (u x, a)) f (π€ Ξ±) :=
β¨Ξ» H, tendsto_right_nhds_uniformity.comp H,
Ξ» H s hs, by simpa [mem_of_nhds hs] using H (mem_nhds_uniformity_iff_left.1 hs)β©
theorem continuous_at_iff'_right [topological_space Ξ²] {f : Ξ² β Ξ±} {b : Ξ²} :
continuous_at f b β tendsto (Ξ» x, (f b, f x)) (π b) (π€ Ξ±) :=
by rw [continuous_at, tendsto_nhds_right]
theorem continuous_at_iff'_left [topological_space Ξ²] {f : Ξ² β Ξ±} {b : Ξ²} :
continuous_at f b β tendsto (Ξ» x, (f x, f b)) (π b) (π€ Ξ±) :=
by rw [continuous_at, tendsto_nhds_left]
theorem continuous_at_iff_prod [topological_space Ξ²] {f : Ξ² β Ξ±} {b : Ξ²} :
continuous_at f b β tendsto (Ξ» x : Ξ² Γ Ξ², (f x.1, f x.2)) (π (b, b)) (π€ Ξ±) :=
β¨Ξ» H, le_trans (H.prod_map' H) (nhds_le_uniformity _),
Ξ» H, continuous_at_iff'_left.2 $ H.comp $ tendsto_id.prod_mk_nhds tendsto_const_nhdsβ©
theorem continuous_within_at_iff'_right [topological_space Ξ²] {f : Ξ² β Ξ±} {b : Ξ²} {s : set Ξ²} :
continuous_within_at f s b β tendsto (Ξ» x, (f b, f x)) (π[s] b) (π€ Ξ±) :=
by rw [continuous_within_at, tendsto_nhds_right]
theorem continuous_within_at_iff'_left [topological_space Ξ²] {f : Ξ² β Ξ±} {b : Ξ²} {s : set Ξ²} :
continuous_within_at f s b β tendsto (Ξ» x, (f x, f b)) (π[s] b) (π€ Ξ±) :=
by rw [continuous_within_at, tendsto_nhds_left]
theorem continuous_on_iff'_right [topological_space Ξ²] {f : Ξ² β Ξ±} {s : set Ξ²} :
continuous_on f s β β b β s, tendsto (Ξ» x, (f b, f x)) (π[s] b) (π€ Ξ±) :=
by simp [continuous_on, continuous_within_at_iff'_right]
theorem continuous_on_iff'_left [topological_space Ξ²] {f : Ξ² β Ξ±} {s : set Ξ²} :
continuous_on f s β β b β s, tendsto (Ξ» x, (f x, f b)) (π[s] b) (π€ Ξ±) :=
by simp [continuous_on, continuous_within_at_iff'_left]
theorem continuous_iff'_right [topological_space Ξ²] {f : Ξ² β Ξ±} :
continuous f β β b, tendsto (Ξ» x, (f b, f x)) (π b) (π€ Ξ±) :=
continuous_iff_continuous_at.trans $ forall_congr $ Ξ» b, tendsto_nhds_right
theorem continuous_iff'_left [topological_space Ξ²] {f : Ξ² β Ξ±} :
continuous f β β b, tendsto (Ξ» x, (f x, f b)) (π b) (π€ Ξ±) :=
continuous_iff_continuous_at.trans $ forall_congr $ Ξ» b, tendsto_nhds_left
end uniform
lemma filter.tendsto.congr_uniformity {Ξ± Ξ²} [uniform_space Ξ²] {f g : Ξ± β Ξ²} {l : filter Ξ±} {b : Ξ²}
(hf : tendsto f l (π b)) (hg : tendsto (Ξ» x, (f x, g x)) l (π€ Ξ²)) :
tendsto g l (π b) :=
uniform.tendsto_nhds_right.2 $ (uniform.tendsto_nhds_right.1 hf).uniformity_trans hg
lemma uniform.tendsto_congr {Ξ± Ξ²} [uniform_space Ξ²] {f g : Ξ± β Ξ²} {l : filter Ξ±} {b : Ξ²}
(hfg : tendsto (Ξ» x, (f x, g x)) l (π€ Ξ²)) :
tendsto f l (π b) β tendsto g l (π b) :=
β¨Ξ» h, h.congr_uniformity hfg, Ξ» h, h.congr_uniformity hfg.uniformity_symmβ©
|
90c30e7dfc5c3b1729fb9fe1896efbde9712c0d6
|
367134ba5a65885e863bdc4507601606690974c1
|
/archive/100-theorems-list/83_friendship_graphs.lean
|
36fcc870f2daaa7177f1892142659d4fcd8dd438
|
[
"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
| 13,831
|
lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Aaron Anderson, Jalex Stark, Kyle Miller.
-/
import combinatorics.simple_graph.adj_matrix
import linear_algebra.char_poly.coeff
import data.int.modeq
import data.zmod.basic
import tactic.interval_cases
/-!
# The Friendship Theorem
## Definitions and Statement
- A `friendship` graph is one in which any two distinct vertices have exactly one neighbor in common
- A `politician`, at least in the context of this problem, is a vertex in a graph which is adjacent
to every other vertex.
- The friendship theorem (ErdΕs, RΓ©nyi, SΓ³s 1966) states that every finite friendship graph has a
politician.
## Proof outline
The proof revolves around the theory of adjacency matrices, although some steps could equivalently
be phrased in terms of counting walks.
- Assume `G` is a finite friendship graph.
- First we show that any two nonadjacent vertices have the same degree
- Assume for contradiction that `G` does not have a politician.
- Conclude from the last two points that `G` is `d`-regular for some `d : β`.
- Show that `G` has `d ^ 2 - d + 1` vertices.
- By casework, show that if `d = 0, 1, 2`, then `G` has a politician.
- If `3 β€ d`, let `p` be a prime factor of `d - 1`.
- If `A` is the adjacency matrix of `G` with entries in `β€/pβ€`, we show that `A ^ p` has trace `1`.
- This gives a contradiction, as `A` has trace `0`, and thus `A ^ p` has trace `0`.
## References
- [P. ErdΕs, A. RΓ©nyi, V. SΓ³s, *On A Problem of Graph Theory*][erdosrenyisos]
- [C. Huneke, *The Friendship Theorem*][huneke2002]
-/
open_locale classical big_operators
noncomputable theory
open finset simple_graph matrix
universes u v
variables {V : Type u} {R : Type v} [semiring R]
section friendship_def
variables (G : simple_graph V)
/--
This property of a graph is the hypothesis of the friendship theorem:
every pair of nonadjacent vertices has exactly one common friend,
a vertex to which both are adjacent.
-/
def friendship [fintype V] : Prop := β β¦v w : Vβ¦, v β w β fintype.card (G.common_neighbors v w) = 1
/--
A politician is a vertex that is adjacent to all other vertices.
-/
def exists_politician : Prop := β (v : V), β (w : V), v β w β G.adj v w
end friendship_def
variables [fintype V] {G : simple_graph V} {d : β} (hG : friendship G)
include hG
namespace friendship
variables (R)
/-- One characterization of a friendship graph is that there is exactly one walk of length 2
between distinct vertices. These walks are counted in off-diagonal entries of the square of
the adjacency matrix, so for a friendship graph, those entries are all 1. -/
theorem adj_matrix_sq_of_ne {v w : V} (hvw : v β w) :
((G.adj_matrix R) ^ 2) v w = 1 :=
begin
rw [pow_two, β nat.cast_one, β hG hvw],
simp [common_neighbors, neighbor_finset_eq_filter, finset.filter_filter, finset.filter_inter,
and_comm],
end
/-- This calculation amounts to counting the number of length 3 walks between nonadjacent vertices.
We use it to show that nonadjacent vertices have equal degrees. -/
lemma adj_matrix_pow_three_of_not_adj {v w : V} (non_adj : Β¬ G.adj v w) :
((G.adj_matrix R) ^ 3) v w = degree G v :=
begin
rw [pow_succ, mul_eq_mul, adj_matrix_mul_apply, degree, card_eq_sum_ones, sum_nat_cast],
apply sum_congr rfl,
intros x hx,
rw [adj_matrix_sq_of_ne _ hG, nat.cast_one],
rintro β¨rflβ©,
rw mem_neighbor_finset at hx,
exact non_adj hx,
end
variable {R}
/-- As `v` and `w` not being adjacent implies
`degree G v = ((G.adj_matrix R) ^ 3) v w` and `degree G w = ((G.adj_matrix R) ^ 3) v w`,
the degrees are equal if `((G.adj_matrix R) ^ 3) v w = ((G.adj_matrix R) ^ 3) w v`
This is true as the adjacency matrix is symmetric. -/
lemma degree_eq_of_not_adj {v w : V} (hvw : Β¬ G.adj v w) :
degree G v = degree G w :=
begin
rw [β nat.cast_id (G.degree v), β nat.cast_id (G.degree w),
β adj_matrix_pow_three_of_not_adj β hG hvw,
β adj_matrix_pow_three_of_not_adj β hG (Ξ» h, hvw (G.sym h))],
conv_lhs {rw β transpose_adj_matrix},
simp only [pow_succ, pow_two, mul_eq_mul, β transpose_mul, transpose_apply],
simp only [β mul_eq_mul, mul_assoc],
end
/-- Let `A` be the adjacency matrix of a graph `G`.
If `G` is a friendship graph, then all of the off-diagonal entries of `A^2` are 1.
If `G` is `d`-regular, then all of the diagonal entries of `A^2` are `d`.
Putting these together determines `A^2` exactly for a `d`-regular friendship graph. -/
theorem adj_matrix_sq_of_regular (hd : G.is_regular_of_degree d) :
((G.adj_matrix R) ^ 2) = Ξ» v w, if v = w then d else 1 :=
begin
ext v w, by_cases h : v = w,
{ rw [h, pow_two, mul_eq_mul, adj_matrix_mul_self_apply_self, hd], simp, },
{ rw [adj_matrix_sq_of_ne R hG h, if_neg h], },
end
lemma adj_matrix_sq_mod_p_of_regular {p : β} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) :
(G.adj_matrix (zmod p)) ^ 2 = Ξ» _ _, 1 :=
by simp [adj_matrix_sq_of_regular hG hd, dmod]
section nonempty
variable [nonempty V]
/-- If `G` is a friendship graph without a politician (a vertex adjacent to all others), then
it is regular. We have shown that nonadjacent vertices of a friendship graph have the same degree,
and if there isn't a politician, we can show this for adjacent vertices by finding a vertex
neither is adjacent to, and then using transitivity. -/
theorem is_regular_of_not_exists_politician (hG' : Β¬exists_politician G) :
β (d : β), G.is_regular_of_degree d :=
begin
have v := classical.arbitrary V,
use G.degree v,
intro x,
by_cases hvx : G.adj v x, swap, { exact (degree_eq_of_not_adj hG hvx).symm, },
dunfold exists_politician at hG',
push_neg at hG',
rcases hG' v with β¨w, hvw', hvwβ©,
rcases hG' x with β¨y, hxy', hxyβ©,
by_cases hxw : G.adj x w,
swap, { rw degree_eq_of_not_adj hG hvw, exact degree_eq_of_not_adj hG hxw },
rw degree_eq_of_not_adj hG hxy,
by_cases hvy : G.adj v y,
swap, { exact (degree_eq_of_not_adj hG hvy).symm },
rw degree_eq_of_not_adj hG hvw,
apply degree_eq_of_not_adj hG,
intro hcontra,
rcases finset.card_eq_one.mp (hG hvw') with β¨β¨a, haβ©, hβ©,
have key : β {x}, x β G.common_neighbors v w β x = a,
{ intros x hx,
have h' := mem_univ (subtype.mk x hx),
rw [h, mem_singleton] at h',
injection h', },
apply hxy',
rw [key ((mem_common_neighbors G).mpr β¨hvx, G.sym hxwβ©),
key ((mem_common_neighbors G).mpr β¨hvy, G.sym hcontraβ©)],
end
/-- Let `A` be the adjacency matrix of a `d`-regular friendship graph, and let `v` be a vector
all of whose components are `1`. Then `v` is an eigenvector of `A ^ 2`, and we can compute
the eigenvalue to be `d * d`, or as `d + (fintype.card V - 1)`, so those quantities must be equal.
This essentially means that the graph has `d ^ 2 - d + 1` vertices. -/
lemma card_of_regular (hd : G.is_regular_of_degree d) :
d + (fintype.card V - 1) = d * d :=
begin
have v := classical.arbitrary V,
transitivity ((G.adj_matrix β) ^ 2).mul_vec (Ξ» _, 1) v,
{ rw [adj_matrix_sq_of_regular hG hd, mul_vec, dot_product, β insert_erase (mem_univ v)],
simp only [sum_insert, mul_one, if_true, nat.cast_id, eq_self_iff_true,
mem_erase, not_true, ne.def, not_false_iff, add_right_inj, false_and],
rw [finset.sum_const_nat, card_erase_of_mem (mem_univ v), mul_one], { refl },
intros x hx, simp [(ne_of_mem_erase hx).symm], },
{ rw [pow_two, mul_eq_mul, β mul_vec_mul_vec],
simp [adj_matrix_mul_vec_const_apply_of_regular hd, neighbor_finset,
card_neighbor_set_eq_degree, hd v], }
end
/-- The size of a `d`-regular friendship graph is `1 mod (d-1)`, and thus `1 mod p` for a
factor `p β£ d-1`. -/
lemma card_mod_p_of_regular {p : β} (dmod : (d : zmod p) = 1) (hd : G.is_regular_of_degree d) :
(fintype.card V : zmod p) = 1 :=
begin
have hpos : 0 < fintype.card V := fintype.card_pos_iff.mpr infer_instance,
rw [β nat.succ_pred_eq_of_pos hpos, nat.succ_eq_add_one, nat.pred_eq_sub_one],
simp only [add_left_eq_self, nat.cast_add, nat.cast_one],
have h := congr_arg (Ξ» n, (βn : zmod p)) (card_of_regular hG hd),
revert h, simp [dmod],
end
end nonempty
omit hG
lemma adj_matrix_sq_mul_const_one_of_regular (hd : G.is_regular_of_degree d) :
(G.adj_matrix R) * (Ξ» _ _, 1) = Ξ» _ _, d :=
by { ext x, simp [β hd x, degree] }
lemma adj_matrix_mul_const_one_mod_p_of_regular {p : β} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) :
(G.adj_matrix (zmod p)) * (Ξ» _ _, 1) = Ξ» _ _, 1 :=
by rw [adj_matrix_sq_mul_const_one_of_regular hd, dmod]
include hG
/-- Modulo a factor of `d-1`, the square and all higher powers of the adjacency matrix
of a `d`-regular friendship graph reduce to the matrix whose entries are all 1. -/
lemma adj_matrix_pow_mod_p_of_regular {p : β} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) {k : β} (hk : 2 β€ k) :
(G.adj_matrix (zmod p)) ^ k = Ξ» _ _, 1 :=
begin
iterate 2 {cases k with k, { exfalso, linarith, }, },
induction k with k hind,
{ exact adj_matrix_sq_mod_p_of_regular hG dmod hd, },
have h2 : 2 β€ k.succ.succ := by omega,
rw [pow_succ, hind h2],
exact adj_matrix_mul_const_one_mod_p_of_regular dmod hd,
end
variable [nonempty V]
/-- This is the main proof. Assuming that `3 β€ d`, we take `p` to be a prime factor of `d-1`.
Then the `p`th power of the adjacency matrix of a `d`-regular friendship graph must have trace 1
mod `p`, but we can also show that the trace must be the `p`th power of the trace of the original
adjacency matrix, which is 0, a contradiction.
-/
lemma false_of_three_le_degree (hd : G.is_regular_of_degree d) (h : 3 β€ d) : false :=
begin
-- get a prime factor of d - 1
let p : β := (d - 1).min_fac,
have p_dvd_d_pred := (zmod.nat_coe_zmod_eq_zero_iff_dvd _ _).mpr (d - 1).min_fac_dvd,
have dpos : 0 < d := by linarith,
have d_cast : β(d - 1) = (d : β€) - 1 := by norm_cast,
haveI : fact p.prime := nat.min_fac_prime (by linarith),
have hp2 : 2 β€ p, { apply nat.prime.two_le, assumption },
have dmod : (d : zmod p) = 1,
{ rw [β nat.succ_pred_eq_of_pos dpos, nat.succ_eq_add_one, nat.pred_eq_sub_one],
simp only [add_left_eq_self, nat.cast_add, nat.cast_one],
exact p_dvd_d_pred, },
have Vmod := card_mod_p_of_regular hG dmod hd,
-- now we reduce to a trace calculation
have := zmod.trace_pow_card (G.adj_matrix (zmod p)),
contrapose! this, clear this,
-- the trace is 0 mod p when computed one way
rw [trace_adj_matrix, zero_pow],
swap, { apply nat.prime.pos, assumption, },
-- but the trace is 1 mod p when computed the other way
rw adj_matrix_pow_mod_p_of_regular hG dmod hd hp2,
dunfold fintype.card at Vmod,
simp only [matrix.trace, diag_apply, mul_one, nsmul_eq_mul, linear_map.coe_mk, sum_const],
rw [Vmod, β nat.cast_one, zmod.nat_coe_zmod_eq_zero_iff_dvd, nat.dvd_one,
nat.min_fac_eq_one_iff],
linarith,
end
/-- If `d β€ 1`, a `d`-regular friendship graph has at most one vertex, which is
trivially a politician. -/
lemma exists_politician_of_degree_le_one (hd : G.is_regular_of_degree d) (hd1 : d β€ 1) :
exists_politician G :=
begin
have sq : d * d = d := by { interval_cases d; norm_num },
have h := card_of_regular hG hd,
rw sq at h,
have : fintype.card V β€ 1,
{ cases fintype.card V with n,
{ exact zero_le _, },
{ have : n = 0,
{ rw [nat.succ_sub_succ_eq_sub, nat.sub_zero] at h,
linarith },
subst n, } },
use classical.arbitrary V,
intros w h, exfalso,
apply h,
apply fintype.card_le_one_iff.mp this,
end
/-- If `d = 2`, a `d`-regular friendship graph has 3 vertices, so it must be complete graph,
and all the vertices are politicians. -/
lemma neighbor_finset_eq_of_degree_eq_two (hd : G.is_regular_of_degree 2) (v : V) :
G.neighbor_finset v = finset.univ.erase v :=
begin
apply finset.eq_of_subset_of_card_le,
{ rw finset.subset_iff,
intro x,
rw [mem_neighbor_finset, finset.mem_erase],
exact Ξ» h, β¨(G.ne_of_adj h).symm, finset.mem_univ _β© },
convert_to 2 β€ _,
{ convert_to _ = fintype.card V - 1,
{ have hfr:= card_of_regular hG hd,
linarith },
{ exact finset.card_erase_of_mem (finset.mem_univ _), }, },
{ dsimp [is_regular_of_degree, degree] at hd,
rw hd, }
end
lemma exists_politician_of_degree_eq_two (hd : G.is_regular_of_degree 2) :
exists_politician G :=
begin
have v := classical.arbitrary V,
use v,
intros w hvw,
rw [β mem_neighbor_finset, neighbor_finset_eq_of_degree_eq_two hG hd v, finset.mem_erase],
exact β¨hvw.symm, finset.mem_univ _β©,
end
lemma exists_politician_of_degree_le_two (hd : G.is_regular_of_degree d) (h : d β€ 2) :
exists_politician G :=
begin
interval_cases d,
iterate 2 { apply exists_politician_of_degree_le_one hG hd, norm_num },
{ exact exists_politician_of_degree_eq_two hG hd },
end
end friendship
/-- We wish to show that a friendship graph has a politician (a vertex adjacent to all others).
We proceed by contradiction, and assume the graph has no politician.
We have already proven that a friendship graph with no politician is `d`-regular for some `d`,
and now we do casework on `d`.
If the degree is at most 2, we observe by casework that it has a politician anyway.
If the degree is at least 3, the graph cannot exist. -/
theorem friendship_theorem [nonempty V] : exists_politician G :=
begin
by_contradiction npG,
rcases hG.is_regular_of_not_exists_politician npG with β¨d, dregβ©,
have h : d β€ 2 β¨ 3 β€ d := by omega,
cases h with dle2 dge3,
{ exact npG (hG.exists_politician_of_degree_le_two dreg dle2) },
{ exact hG.false_of_three_le_degree dreg dge3 },
end
|
d46889f34deaf585f9dd6a7e393b8aa1c59a05e7
|
b561a44b48979a98df50ade0789a21c79ee31288
|
/src/Lean/Elab/Inductive.lean
|
13b80894dc96cc9b5130a0cd97d5ce77e4f91974
|
[
"Apache-2.0"
] |
permissive
|
3401ijk/lean4
|
97659c475ebd33a034fed515cb83a85f75ccfb06
|
a5b1b8de4f4b038ff752b9e607b721f15a9a4351
|
refs/heads/master
| 1,693,933,007,651
| 1,636,424,845,000
| 1,636,424,845,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 25,028
|
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.Util.ReplaceLevel
import Lean.Util.ReplaceExpr
import Lean.Util.CollectLevelParams
import Lean.Meta.Constructions
import Lean.Meta.CollectFVars
import Lean.Meta.SizeOf
import Lean.Meta.Injective
import Lean.Meta.IndPredBelow
import Lean.Elab.Command
import Lean.Elab.DefView
import Lean.Elab.DeclUtil
import Lean.Elab.Deriving.Basic
namespace Lean.Elab.Command
open Meta
builtin_initialize
registerTraceClass `Elab.inductive
def checkValidInductiveModifier [Monad m] [MonadError m] (modifiers : Modifiers) : m Unit := do
if modifiers.isNoncomputable then
throwError "invalid use of 'noncomputable' in inductive declaration"
if modifiers.isPartial then
throwError "invalid use of 'partial' in inductive declaration"
unless modifiers.attrs.size == 0 || (modifiers.attrs.size == 1 && modifiers.attrs[0].name == `class) do
throwError "invalid use of attributes in inductive declaration"
def checkValidCtorModifier [Monad m] [MonadError m] (modifiers : Modifiers) : m Unit := do
if modifiers.isNoncomputable then
throwError "invalid use of 'noncomputable' in constructor declaration"
if modifiers.isPartial then
throwError "invalid use of 'partial' in constructor declaration"
if modifiers.isUnsafe then
throwError "invalid use of 'unsafe' in constructor declaration"
if modifiers.attrs.size != 0 then
throwError "invalid use of attributes in constructor declaration"
structure CtorView where
ref : Syntax
modifiers : Modifiers
inferMod : Bool -- true if `{}` is used in the constructor declaration
declName : Name
binders : Syntax
type? : Option Syntax
deriving Inhabited
structure InductiveView where
ref : Syntax
modifiers : Modifiers
shortDeclName : Name
declName : Name
levelNames : List Name
binders : Syntax
type? : Option Syntax
ctors : Array CtorView
derivingClasses : Array DerivingClassView
deriving Inhabited
structure ElabHeaderResult where
view : InductiveView
lctx : LocalContext
localInsts : LocalInstances
params : Array Expr
type : Expr
deriving Inhabited
private partial def elabHeaderAux (views : Array InductiveView) (i : Nat) (acc : Array ElabHeaderResult) : TermElabM (Array ElabHeaderResult) := do
if h : i < views.size then
let view := views.get β¨i, hβ©
let acc β Term.withAutoBoundImplicit <| Term.elabBinders view.binders.getArgs fun params => do
match view.type? with
| none =>
let u β mkFreshLevelMVar
let type := mkSort u
Term.synthesizeSyntheticMVarsNoPostponing
let params β Term.addAutoBoundImplicits params
pure <| acc.push { lctx := (β getLCtx), localInsts := (β getLocalInstances), params := params, type := type, view := view }
| some typeStx =>
let type β Term.elabType typeStx
unless (β isTypeFormerType type) do
throwErrorAt typeStx "invalid inductive type, resultant type is not a sort"
Term.synthesizeSyntheticMVarsNoPostponing
let params β Term.addAutoBoundImplicits params
pure <| acc.push { lctx := (β getLCtx), localInsts := (β getLocalInstances), params := params, type := type, view := view }
elabHeaderAux views (i+1) acc
else
pure acc
private def checkNumParams (rs : Array ElabHeaderResult) : TermElabM Nat := do
let numParams := rs[0].params.size
for r in rs do
unless r.params.size == numParams do
throwErrorAt r.view.ref "invalid inductive type, number of parameters mismatch in mutually inductive datatypes"
pure numParams
private def checkUnsafe (rs : Array ElabHeaderResult) : TermElabM Unit := do
let isUnsafe := rs[0].view.modifiers.isUnsafe
for r in rs do
unless r.view.modifiers.isUnsafe == isUnsafe do
throwErrorAt r.view.ref "invalid inductive type, cannot mix unsafe and safe declarations in a mutually inductive datatypes"
private def checkLevelNames (views : Array InductiveView) : TermElabM Unit := do
if views.size > 1 then
let levelNames := views[0].levelNames
for view in views do
unless view.levelNames == levelNames do
throwErrorAt view.ref "invalid inductive type, universe parameters mismatch in mutually inductive datatypes"
private def mkTypeFor (r : ElabHeaderResult) : TermElabM Expr := do
withLCtx r.lctx r.localInsts do
mkForallFVars r.params r.type
private def throwUnexpectedInductiveType {Ξ±} : TermElabM Ξ± :=
throwError "unexpected inductive resulting type"
private def eqvFirstTypeResult (firstType type : Expr) : MetaM Bool :=
forallTelescopeReducing firstType fun _ firstTypeResult => isDefEq firstTypeResult type
-- Auxiliary function for checking whether the types in mutually inductive declaration are compatible.
private partial def checkParamsAndResultType (type firstType : Expr) (numParams : Nat) : TermElabM Unit := do
try
forallTelescopeCompatible type firstType numParams fun _ type firstType =>
forallTelescopeReducing type fun _ type =>
forallTelescopeReducing firstType fun _ firstType => do
let type β whnfD type
match type with
| Expr.sort .. =>
unless (β isDefEq firstType type) do
throwError "resulting universe mismatch, given{indentExpr type}\nexpected type{indentExpr firstType}"
| _ =>
throwError "unexpected inductive resulting type"
catch
| Exception.error ref msg => throw (Exception.error ref m!"invalid mutually inductive types, {msg}")
| ex => throw ex
-- Auxiliary function for checking whether the types in mutually inductive declaration are compatible.
private def checkHeader (r : ElabHeaderResult) (numParams : Nat) (firstType? : Option Expr) : TermElabM Expr := do
let type β mkTypeFor r
match firstType? with
| none => pure type
| some firstType =>
withRef r.view.ref $ checkParamsAndResultType type firstType numParams
pure firstType
-- Auxiliary function for checking whether the types in mutually inductive declaration are compatible.
private partial def checkHeaders (rs : Array ElabHeaderResult) (numParams : Nat) (i : Nat) (firstType? : Option Expr) : TermElabM Unit := do
if i < rs.size then
let type β checkHeader rs[i] numParams firstType?
checkHeaders rs numParams (i+1) type
private def elabHeader (views : Array InductiveView) : TermElabM (Array ElabHeaderResult) := do
let rs β elabHeaderAux views 0 #[]
if rs.size > 1 then
checkUnsafe rs
let numParams β checkNumParams rs
checkHeaders rs numParams 0 none
return rs
/- Create a local declaration for each inductive type in `rs`, and execute `x params indFVars`, where `params` are the inductive type parameters and
`indFVars` are the new local declarations.
We use the local context/instances and parameters of rs[0].
Note that this method is executed after we executed `checkHeaders` and established all
parameters are compatible. -/
private partial def withInductiveLocalDecls {Ξ±} (rs : Array ElabHeaderResult) (x : Array Expr β Array Expr β TermElabM Ξ±) : TermElabM Ξ± := do
let namesAndTypes β rs.mapM fun r => do
let type β mkTypeFor r
pure (r.view.shortDeclName, type)
let r0 := rs[0]
let params := r0.params
withLCtx r0.lctx r0.localInsts $ withRef r0.view.ref do
let rec loop (i : Nat) (indFVars : Array Expr) := do
if h : i < namesAndTypes.size then
let (id, type) := namesAndTypes.get β¨i, hβ©
withLocalDeclD id type fun indFVar => loop (i+1) (indFVars.push indFVar)
else
x params indFVars
loop 0 #[]
private def isInductiveFamily (numParams : Nat) (indFVar : Expr) : TermElabM Bool := do
let indFVarType β inferType indFVar
forallTelescopeReducing indFVarType fun xs _ =>
return xs.size > numParams
/-
Elaborate constructor types.
Remark: we check whether the resulting type is correct, and the parameter occurrences are consistent, but
we currently do not check for:
- Positivity (it is a rare failure, and the kernel already checks for it).
- Universe constraints (the kernel checks for it).
-/
private def elabCtors (indFVars : Array Expr) (indFVar : Expr) (params : Array Expr) (r : ElabHeaderResult) : TermElabM (List Constructor) := withRef r.view.ref do
let indFamily β isInductiveFamily params.size indFVar
r.view.ctors.toList.mapM fun ctorView =>
Term.withAutoBoundImplicit <| Term.elabBinders ctorView.binders.getArgs fun ctorParams =>
withRef ctorView.ref do
let rec elabCtorType (k : Expr β TermElabM Constructor) : TermElabM Constructor := do
match ctorView.type? with
| none =>
if indFamily then
throwError "constructor resulting type must be specified in inductive family declaration"
k <| mkAppN indFVar params
| some ctorType =>
let type β Term.elabType ctorType
Term.synthesizeSyntheticMVars (mayPostpone := true)
let type β instantiateMVars type
let type β checkParamOccs type
forallTelescopeReducing type fun _ resultingType => do
unless resultingType.getAppFn == indFVar do
throwError "unexpected constructor resulting type{indentExpr resultingType}"
unless (β isType resultingType) do
throwError "unexpected constructor resulting type, type expected{indentExpr resultingType}"
k type
elabCtorType fun type => do
Term.synthesizeSyntheticMVarsNoPostponing
let ctorParams β Term.addAutoBoundImplicits ctorParams
let type β mkForallFVars ctorParams type
let type β mkForallFVars params type
return { name := ctorView.declName, type := type }
where
checkParamOccs (ctorType : Expr) : MetaM Expr :=
let visit (e : Expr) : MetaM TransformStep := do
let f := e.getAppFn
if indFVars.contains f then
let mut args := e.getAppArgs
unless args.size β₯ params.size do
throwError "unexpected inductive type occurrence{indentExpr e}"
for i in [:params.size] do
let param := params[i]
let arg := args[i]
unless (β isDefEq param arg) do
throwError "inductive datatype parameter mismatch{indentExpr arg}\nexpected{indentExpr param}"
args := args.set! i param
return TransformStep.done (mkAppN f args)
else
return TransformStep.visit e
transform ctorType (pre := visit)
/- Convert universe metavariables occurring in the `indTypes` into new parameters.
Remark: if the resulting inductive datatype has universe metavariables, we will fix it later using
`inferResultingUniverse`. -/
private def levelMVarToParamAux (indTypes : List InductiveType) : StateRefT Nat TermElabM (List InductiveType) :=
indTypes.mapM fun indType => do
let type β Term.levelMVarToParam' indType.type
let ctors β indType.ctors.mapM fun ctor => do
let ctorType β Term.levelMVarToParam' ctor.type
pure { ctor with type := ctorType }
pure { indType with ctors := ctors, type := type }
private def levelMVarToParam (indTypes : List InductiveType) : TermElabM (List InductiveType) :=
(levelMVarToParamAux indTypes).run' 1
private def getResultingUniverse : List InductiveType β TermElabM Level
| [] => throwError "unexpected empty inductive declaration"
| indType :: _ => forallTelescopeReducing indType.type fun _ r => do
let r β whnfD r
match r with
| Expr.sort u _ => pure u
| _ => throwError "unexpected inductive type resulting type{indentExpr r}"
def tmpIndParam := mkLevelParam `_tmp_ind_univ_param
/--
Return true if `u` is of the form `?m + k`.
Return false if `u` does not contain universe metavariables.
Throw exception otherwise. -/
def shouldInferResultUniverse (u : Level) : TermElabM Bool := do
let u β instantiateLevelMVars u
if u.hasMVar then
match u.getLevelOffset with
| Level.mvar mvarId _ => do
Term.assignLevelMVar mvarId tmpIndParam
pure true
| _ =>
throwError "cannot infer resulting universe level of inductive datatype, given level contains metavariables {mkSort u}, provide universe explicitly"
else
pure false
/-
Auxiliary function for `updateResultingUniverse`
`accLevelAtCtor u r rOffset us` add `u` components to `us` if they are not already there and it is different from the resulting universe level `r+rOffset`.
If `u` is a `max`, then its components are recursively processed.
If `u` is a `succ` and `rOffset > 0`, we process the `u`s child using `rOffset-1`.
This method is used to infer the resulting universe level of an inductive datatype. -/
def accLevelAtCtor : Level β Level β Nat β Array Level β TermElabM (Array Level)
| Level.max u v _, r, rOffset, us => do let us β accLevelAtCtor u r rOffset us; accLevelAtCtor v r rOffset us
| Level.imax u v _, r, rOffset, us => do let us β accLevelAtCtor u r rOffset us; accLevelAtCtor v r rOffset us
| Level.zero _, _, _, us => pure us
| Level.succ u _, r, rOffset+1, us => accLevelAtCtor u r rOffset us
| u, r, rOffset, us =>
if rOffset == 0 && u == r then pure us
else if r.occurs u then throwError "failed to compute resulting universe level of inductive datatype, provide universe explicitly"
else if rOffset > 0 then throwError "failed to compute resulting universe level of inductive datatype, provide universe explicitly"
else if us.contains u then pure us
else pure (us.push u)
/- Auxiliary function for `updateResultingUniverse` -/
private partial def collectUniversesFromCtorTypeAux (r : Level) (rOffset : Nat) : Nat β Expr β Array Level β TermElabM (Array Level)
| 0, Expr.forallE n d b c, us => do
let u β getLevel d
let u β instantiateLevelMVars u
let us β accLevelAtCtor u r rOffset us
withLocalDecl n c.binderInfo d fun x =>
let e := b.instantiate1 x
collectUniversesFromCtorTypeAux r rOffset 0 e us
| i+1, Expr.forallE n d b c, us => do
withLocalDecl n c.binderInfo d fun x =>
let e := b.instantiate1 x
collectUniversesFromCtorTypeAux r rOffset i e us
| _, _, us => pure us
/- Auxiliary function for `updateResultingUniverse` -/
private partial def collectUniversesFromCtorType
(r : Level) (rOffset : Nat) (ctorType : Expr) (numParams : Nat) (us : Array Level) : TermElabM (Array Level) :=
collectUniversesFromCtorTypeAux r rOffset numParams ctorType us
/- Auxiliary function for `updateResultingUniverse` -/
private partial def collectUniverses (r : Level) (rOffset : Nat) (numParams : Nat) (indTypes : List InductiveType) : TermElabM (Array Level) := do
let mut us := #[]
for indType in indTypes do
for ctor in indType.ctors do
us β collectUniversesFromCtorType r rOffset ctor.type numParams us
return us
def mkResultUniverse (us : Array Level) (rOffset : Nat) : Level :=
if us.isEmpty && rOffset == 0 then
levelOne
else
let r := Level.mkNaryMax us.toList
if rOffset == 0 && !r.isZero && !r.isNeverZero then
(mkLevelMax r levelOne).normalize
else
r.normalize
private def updateResultingUniverse (numParams : Nat) (indTypes : List InductiveType) : TermElabM (List InductiveType) := do
let r β getResultingUniverse indTypes
let rOffset : Nat := r.getOffset
let r : Level := r.getLevelOffset
unless r.isParam do
throwError "failed to compute resulting universe level of inductive datatype, provide universe explicitly"
let us β collectUniverses r rOffset numParams indTypes
trace[Elab.inductive] "updateResultingUniverse us: {us}, r: {r}, rOffset: {rOffset}"
let rNew := mkResultUniverse us rOffset
let updateLevel (e : Expr) : Expr := e.replaceLevel fun u => if u == tmpIndParam then some rNew else none
return indTypes.map fun indType =>
let type := updateLevel indType.type;
let ctors := indType.ctors.map fun ctor => { ctor with type := updateLevel ctor.type };
{ indType with type := type, ctors := ctors }
register_builtin_option bootstrap.inductiveCheckResultingUniverse : Bool := {
defValue := true,
group := "bootstrap",
descr := "by default the `inductive/structure commands report an error if the resulting universe is not zero, but may be zero for some universe parameters. Reason: unless this type is a subsingleton, it is hardly what the user wants since it can only eliminate into `Prop`. In the `Init` package, we define subsingletons, and we use this option to disable the check. This option may be deleted in the future after we improve the validator"
}
def checkResultingUniverse (u : Level) : TermElabM Unit := do
if bootstrap.inductiveCheckResultingUniverse.get (β getOptions) then
let u β instantiateLevelMVars u
if !u.isZero && !u.isNeverZero then
throwError "invalid universe polymorphic type, the resultant universe is not Prop (i.e., 0), but it may be Prop for some parameter values (solution: use 'u+1' or 'max 1 u'{indentD u}"
private def checkResultingUniverses (indTypes : List InductiveType) : TermElabM Unit := do
checkResultingUniverse (β getResultingUniverse indTypes)
private def collectUsed (indTypes : List InductiveType) : StateRefT CollectFVars.State MetaM Unit := do
indTypes.forM fun indType => do
Meta.collectUsedFVars indType.type
indType.ctors.forM fun ctor =>
Meta.collectUsedFVars ctor.type
private def removeUnused (vars : Array Expr) (indTypes : List InductiveType) : TermElabM (LocalContext Γ LocalInstances Γ Array Expr) := do
let (_, used) β (collectUsed indTypes).run {}
Meta.removeUnused vars used
private def withUsed {Ξ±} (vars : Array Expr) (indTypes : List InductiveType) (k : Array Expr β TermElabM Ξ±) : TermElabM Ξ± := do
let (lctx, localInsts, vars) β removeUnused vars indTypes
withLCtx lctx localInsts $ k vars
private def updateParams (vars : Array Expr) (indTypes : List InductiveType) : TermElabM (List InductiveType) :=
indTypes.mapM fun indType => do
let type β mkForallFVars vars indType.type
let ctors β indType.ctors.mapM fun ctor => do
let ctorType β mkForallFVars vars ctor.type
pure { ctor with type := ctorType }
pure { indType with type := type, ctors := ctors }
private def collectLevelParamsInInductive (indTypes : List InductiveType) : Array Name := do
let mut usedParams : CollectLevelParams.State := {}
for indType in indTypes do
usedParams := collectLevelParams usedParams indType.type
for ctor in indType.ctors do
usedParams := collectLevelParams usedParams ctor.type
return usedParams.params
private def mkIndFVar2Const (views : Array InductiveView) (indFVars : Array Expr) (levelNames : List Name) : ExprMap Expr := do
let levelParams := levelNames.map mkLevelParam;
let mut m : ExprMap Expr := {}
for i in [:views.size] do
let view := views[i]
let indFVar := indFVars[i]
m := m.insert indFVar (mkConst view.declName levelParams)
return m
/- Remark: `numVars <= numParams`. `numVars` is the number of context `variables` used in the inductive declaration,
and `numParams` is `numVars` + number of explicit parameters provided in the declaration. -/
private def replaceIndFVarsWithConsts (views : Array InductiveView) (indFVars : Array Expr) (levelNames : List Name)
(numVars : Nat) (numParams : Nat) (indTypes : List InductiveType) : TermElabM (List InductiveType) :=
let indFVar2Const := mkIndFVar2Const views indFVars levelNames
indTypes.mapM fun indType => do
let ctors β indType.ctors.mapM fun ctor => do
let type β forallBoundedTelescope ctor.type numParams fun params type => do
let type := type.replace fun e =>
if !e.isFVar then
none
else match indFVar2Const.find? e with
| none => none
| some c => mkAppN c (params.extract 0 numVars)
mkForallFVars params type
pure { ctor with type := type }
pure { indType with ctors := ctors }
abbrev Ctor2InferMod := Std.HashMap Name Bool
private def mkCtor2InferMod (views : Array InductiveView) : Ctor2InferMod := do
let mut m := {}
for view in views do
for ctorView in view.ctors do
m := m.insert ctorView.declName ctorView.inferMod
return m
private def applyInferMod (views : Array InductiveView) (numParams : Nat) (indTypes : List InductiveType) : List InductiveType :=
let ctor2InferMod := mkCtor2InferMod views
indTypes.map fun indType =>
let ctors := indType.ctors.map fun ctor =>
let inferMod := ctor2InferMod.find! ctor.name -- true if `{}` was used
let ctorType := ctor.type.inferImplicit numParams !inferMod
{ ctor with type := ctorType }
{ indType with ctors := ctors }
private def mkAuxConstructions (views : Array InductiveView) : TermElabM Unit := do
let env β getEnv
let hasEq := env.contains ``Eq
let hasHEq := env.contains ``HEq
let hasUnit := env.contains ``PUnit
let hasProd := env.contains ``Prod
for view in views do
let n := view.declName
mkRecOn n
if hasUnit then mkCasesOn n
if hasUnit && hasEq && hasHEq then mkNoConfusion n
if hasUnit && hasProd then mkBelow n
if hasUnit && hasProd then mkIBelow n
for view in views do
let n := view.declName;
if hasUnit && hasProd then mkBRecOn n
if hasUnit && hasProd then mkBInductionOn n
private def mkInductiveDecl (vars : Array Expr) (views : Array InductiveView) : TermElabM Unit := do
let view0 := views[0]
let scopeLevelNames β Term.getLevelNames
checkLevelNames views
let allUserLevelNames := view0.levelNames
let isUnsafe := view0.modifiers.isUnsafe
withRef view0.ref <| Term.withLevelNames allUserLevelNames do
let rs β elabHeader views
withInductiveLocalDecls rs fun params indFVars => do
let numExplicitParams := params.size
let mut indTypesArray := #[]
for i in [:views.size] do
let indFVar := indFVars[i]
let r := rs[i]
let type β mkForallFVars params r.type
let ctors β elabCtors indFVars indFVar params r
indTypesArray := indTypesArray.push { name := r.view.declName, type := type, ctors := ctors : InductiveType }
let indTypes := indTypesArray.toList
Term.synthesizeSyntheticMVarsNoPostponing
let u β getResultingUniverse indTypes
let inferLevel β shouldInferResultUniverse u
withUsed vars indTypes fun vars => do
let numVars := vars.size
let numParams := numVars + numExplicitParams
let indTypes β updateParams vars indTypes
let indTypes β levelMVarToParam indTypes
let indTypes β if inferLevel then updateResultingUniverse numParams indTypes else checkResultingUniverses indTypes; pure indTypes
let usedLevelNames := collectLevelParamsInInductive indTypes
match sortDeclLevelParams scopeLevelNames allUserLevelNames usedLevelNames with
| Except.error msg => throwError msg
| Except.ok levelParams => do
let indTypes β replaceIndFVarsWithConsts views indFVars levelParams numVars numParams indTypes
let indTypes := applyInferMod views numParams indTypes
trace[Meta.debug] "levelParams: {levelParams}"
let decl := Declaration.inductDecl levelParams numParams indTypes isUnsafe
Term.ensureNoUnassignedMVars decl
addDecl decl
mkAuxConstructions views
-- We need to invoke `applyAttributes` because `class` is implemented as an attribute.
for view in views do
Term.applyAttributesAt view.declName view.modifiers.attrs AttributeApplicationTime.afterTypeChecking
private def applyDerivingHandlers (views : Array InductiveView) : CommandElabM Unit := do
let mut processed : NameSet := {}
for view in views do
for classView in view.derivingClasses do
let className := classView.className
unless processed.contains className do
processed := processed.insert className
let mut declNames := #[]
for view in views do
if view.derivingClasses.any fun classView => classView.className == className then
declNames := declNames.push view.declName
classView.applyHandlers declNames
def elabInductiveViews (views : Array InductiveView) : CommandElabM Unit := do
let view0 := views[0]
let ref := view0.ref
runTermElabM view0.declName fun vars => withRef ref do
mkInductiveDecl vars views
mkSizeOfInstances view0.declName
Lean.Meta.IndPredBelow.mkBelow view0.declName
for view in views do
mkInjectiveTheorems view.declName
applyDerivingHandlers views
end Lean.Elab.Command
|
efb905f34dc79b15533d1b15836734bf42037967
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/linear_algebra/free_module/basic.lean
|
15a86b4839cb24d9ed9582f8e3b92a2f155fdb55
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 6,319
|
lean
|
/-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import linear_algebra.direct_sum.finsupp
import logic.small
import linear_algebra.std_basis
import linear_algebra.finsupp_vector_space
/-!
# Free modules
We introduce a class `module.free R M`, for `R` a `semiring` and `M` an `R`-module and we provide
several basic instances for this class.
Use `finsupp.total_id_surjective` to prove that any module is the quotient of a free module.
## Main definition
* `module.free R M` : the class of free `R`-modules.
-/
universes u v w z
variables {ΞΉ : Type*} (R : Type u) (M : Type v) (N : Type z)
open_locale tensor_product direct_sum big_operators
section basic
variables [semiring R] [add_comm_monoid M] [module R M]
/-- `module.free R M` is the statement that the `R`-module `M` is free.-/
class module.free : Prop :=
(exists_basis [] : nonempty (Ξ£ (I : Type v), basis I R M))
/- If `M` fits in universe `w`, then freeness is equivalent to existence of a basis in that
universe.
Note that if `M` does not fit in `w`, the reverse direction of this implication is still true as
`module.free.of_basis`. -/
lemma module.free_def [small.{w} M] : module.free R M β β (I : Type w), nonempty (basis I R M) :=
β¨ Ξ» h, β¨shrink (set.range h.exists_basis.some.2),
β¨(basis.reindex_range h.exists_basis.some.2).reindex (equiv_shrink _)β©β©,
Ξ» h, β¨(nonempty_sigma.2 h).map $ Ξ» β¨i, bβ©, β¨set.range b, b.reindex_rangeβ©β©β©
lemma module.free_iff_set : module.free R M β β (S : set M), nonempty (basis S R M) :=
β¨Ξ» h, β¨set.range h.exists_basis.some.2, β¨basis.reindex_range h.exists_basis.some.2β©β©,
Ξ» β¨S, hSβ©, β¨nonempty_sigma.2 β¨S, hSβ©β©β©
variables {R M}
lemma module.free.of_basis {ΞΉ : Type w} (b : basis ΞΉ R M) : module.free R M :=
(module.free_def R M).2 β¨set.range b, β¨b.reindex_rangeβ©β©
end basic
namespace module.free
section semiring
variables (R M) [semiring R] [add_comm_monoid M] [module R M] [module.free R M]
variables [add_comm_monoid N] [module R N]
/-- If `module.free R M` then `choose_basis_index R M` is the `ΞΉ` which indexes the basis
`ΞΉ β M`. -/
@[nolint has_nonempty_instance] def choose_basis_index := (exists_basis R M).some.1
/-- If `module.free R M` then `choose_basis : ΞΉ β M` is the basis.
Here `ΞΉ = choose_basis_index R M`. -/
noncomputable def choose_basis : basis (choose_basis_index R M) R M := (exists_basis R M).some.2
/-- The isomorphism `M ββ[R] (choose_basis_index R M ββ R)`. -/
noncomputable def repr : M ββ[R] (choose_basis_index R M ββ R) := (choose_basis R M).repr
/-- The universal property of free modules: giving a functon `(choose_basis_index R M) β N`, for `N`
an `R`-module, is the same as giving an `R`-linear map `M ββ[R] N`.
This definition is parameterized over an extra `semiring S`,
such that `smul_comm_class R S M'` holds.
If `R` is commutative, you can set `S := R`; if `R` is not commutative,
you can recover an `add_equiv` by setting `S := β`.
See library note [bundled maps over different rings]. -/
noncomputable def constr {S : Type z} [semiring S] [module S N] [smul_comm_class R S N] :
((choose_basis_index R M) β N) ββ[S] M ββ[R] N := basis.constr (choose_basis R M) S
@[priority 100]
instance no_zero_smul_divisors [no_zero_divisors R] : no_zero_smul_divisors R M :=
let β¨β¨_, bβ©β© := exists_basis R M in b.no_zero_smul_divisors
variables {R M N}
lemma of_equiv (e : M ββ[R] N) : module.free R N :=
of_basis $ (choose_basis R M).map e
/-- A variation of `of_equiv`: the assumption `module.free R P` here is explicit rather than an
instance. -/
lemma of_equiv' {P : Type v} [add_comm_monoid P] [module R P] (h : module.free R P)
(e : P ββ[R] N) : module.free R N :=
of_equiv e
variables (R M N)
/-- The module structure provided by `semiring.to_module` is free. -/
instance self : module.free R R := of_basis (basis.singleton unit R)
instance prod [module.free R N] : module.free R (M Γ N) :=
of_basis $ (choose_basis R M).prod (choose_basis R N)
/-- The product of finitely many free modules is free. -/
instance pi (M : ΞΉ β Type*) [finite ΞΉ] [Ξ (i : ΞΉ), add_comm_monoid (M i)]
[Ξ (i : ΞΉ), module R (M i)] [Ξ (i : ΞΉ), module.free R (M i)] : module.free R (Ξ i, M i) :=
let β¨_β© := nonempty_fintype ΞΉ in by exactI (of_basis $ pi.basis $ Ξ» i, choose_basis R (M i))
/-- The module of finite matrices is free. -/
instance matrix {m n : Type*} [finite m] [finite n] : module.free R (matrix m n M) :=
module.free.pi R _
variables (ΞΉ)
/-- The product of finitely many free modules is free (non-dependent version to help with typeclass
search). -/
instance function [finite ΞΉ] : module.free R (ΞΉ β M) := free.pi _ _
instance finsupp : module.free R (ΞΉ ββ M) :=
of_basis (finsupp.basis $ Ξ» i, choose_basis R M)
variables {ΞΉ}
@[priority 100]
instance of_subsingleton [subsingleton N] : module.free R N :=
of_basis (basis.empty N : basis pempty R N)
@[priority 100]
instance of_subsingleton' [subsingleton R] : module.free R N :=
by letI := module.subsingleton R N; exact module.free.of_subsingleton R N
instance dfinsupp {ΞΉ : Type*} (M : ΞΉ β Type*) [Ξ (i : ΞΉ), add_comm_monoid (M i)]
[Ξ (i : ΞΉ), module R (M i)] [Ξ (i : ΞΉ), module.free R (M i)] : module.free R (Ξ β i, M i) :=
of_basis $ dfinsupp.basis $ Ξ» i, choose_basis R (M i)
instance direct_sum {ΞΉ : Type*} (M : ΞΉ β Type*) [Ξ (i : ΞΉ), add_comm_monoid (M i)]
[Ξ (i : ΞΉ), module R (M i)] [Ξ (i : ΞΉ), module.free R (M i)] : module.free R (β¨ i, M i) :=
module.free.dfinsupp R M
end semiring
section comm_ring
variables [comm_ring R] [add_comm_group M] [module R M] [module.free R M]
variables [add_comm_group N] [module R N] [module.free R N]
instance tensor : module.free R (M β[R] N) :=
of_equiv' (of_equiv' (free.finsupp _ R _) (finsupp_tensor_finsupp' R _ _).symm)
(tensor_product.congr (choose_basis R M).repr (choose_basis R N).repr).symm
end comm_ring
section division_ring
variables [division_ring R] [add_comm_group M] [module R M]
@[priority 100]
instance of_division_ring : module.free R M :=
of_basis (basis.of_vector_space R M)
end division_ring
end module.free
|
2d369c9f33249cba06b25643deb95c2bcc5497fd
|
6afa22d5eee6e9a56b6a2f1210eca8f7a1067466
|
/library/init/meta/widget/interactive_expr.lean
|
65d289dd26a0cc7ff7d487c82edde45a90dd3051
|
[
"Apache-2.0"
] |
permissive
|
giordano/lean
|
72a1fabfeb2f1ccfd38673e2719a719cd6ffbb40
|
56f8877f1efa22215aca0b82f1c0ce2ff975b9c3
|
refs/heads/master
| 1,663,091,511,168
| 1,590,688,082,000
| 1,590,688,082,000
| 268,183,678
| 0
| 0
|
Apache-2.0
| 1,590,885,425,000
| 1,590,885,424,000
| null |
UTF-8
|
Lean
| false
| false
| 7,074
|
lean
|
/-
Copyright (c) E.W.Ayers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: E.W.Ayers
-/
prelude
import init.meta.widget.basic
import init.meta.widget.tactic_component
import init.meta.tagged_format
import init.data.punit
meta def subexpr := (expr Γ expr.address)
namespace widget
open tagged_format
open html attr
namespace interactive_expression
/-- eformat but without any of the formatting stuff like highlighting, groups etc. -/
meta inductive sf : Type
| tag_expr : expr.address β expr β sf β sf
| compose : sf β sf β sf
| of_string : string β sf
private meta def to_simple : eformat β sf
| (tag β¨ea,eβ© m) := sf.tag_expr ea e $ to_simple m
| (group m) := to_simple m
| (nest i m) := to_simple m
| (highlight i m) := to_simple m
| (of_format f) := sf.of_string $ format.to_string f
| (compose x y) := sf.compose (to_simple x) (to_simple y)
private meta def sf.flatten : sf β sf
| (sf.tag_expr e ea m) := (sf.tag_expr e ea $ sf.flatten m)
| (sf.compose x y) :=
match (sf.flatten x), (sf.flatten y) with
| (sf.of_string sx), (sf.of_string sy) := sf.of_string (sx ++ sy)
| (sf.of_string sx), (sf.compose (sf.of_string sy) z) := sf.compose (sf.of_string (sx ++ sy)) z
| (sf.compose x (sf.of_string sy)), (sf.of_string sz) := sf.compose x (sf.of_string (sy ++ sz))
| (sf.compose x (sf.of_string sy1)), (sf.compose (sf.of_string sy2) z) := sf.compose x (sf.compose (sf.of_string (sy1 ++ sy2)) z)
| x, y := sf.compose x y
end
| (sf.of_string s) := sf.of_string s
meta inductive action (Ξ³ : Type)
| on_mouse_enter : subexpr β action
| on_mouse_leave_all : action
| on_click : subexpr β action
| on_tooltip_action : Ξ³ β action
| on_close_tooltip : action
meta def view {Ξ³} (tooltip_component : tc subexpr (action Ξ³)) (click_address : option expr.address) (select_address : option expr.address) :
subexpr β sf β tactic (list (html (action Ξ³)))
| β¨ce, current_addressβ© (sf.tag_expr ea e m) := do
let new_address := current_address ++ ea,
let select_attrs : list (attr (action Ξ³)) := if some new_address = select_address then [className "highlight"] else [],
click_attrs : list (attr (action Ξ³)) β
if some new_address = click_address then do
content β tc.to_html tooltip_component (e, new_address),
pure [tooltip $ h "div" [] [
h "button" [cn "fr pointer ba br3", on_click (Ξ» _, action.on_close_tooltip)] ["x"],
content
]]
else pure [],
let as := [className "expr-boundary", key (ea)] ++ select_attrs ++ click_attrs,
inner β view (e,new_address) m,
pure [h "span" as inner]
| ca (sf.compose x y) := pure (++) <*> view ca x <*> view ca y
| ca (sf.of_string s) := pure
[h "span" [
on_mouse_enter (Ξ» _, action.on_mouse_enter ca),
on_click (Ξ» _, action.on_click ca),
key s
] [html.of_string s]]
/-- Make an interactive expression. -/
meta def mk {Ξ³} (tooltip : tc subexpr Ξ³) : tc expr Ξ³ :=
let tooltip_comp :=
component.with_props_eq (Ξ» (x y : tactic_state Γ expr Γ expr.address), x.2.2 = y.2.2)
$ component.map_action (action.on_tooltip_action) tooltip in
tc.mk_simple
(action Ξ³)
(option subexpr Γ option subexpr)
(Ξ» e, pure $ (none, none))
(Ξ» e β¨ca, saβ© act, pure $
match act with
| (action.on_mouse_enter β¨e, eaβ©) := ((ca, some (e, ea)), none)
| (action.on_mouse_leave_all) := ((ca, none), none)
| (action.on_click β¨e, eaβ©) := if some (e,ea) = ca then ((none, sa), none) else ((some (e, ea), sa), none)
| (action.on_tooltip_action g) := ((none, sa), some g)
| (action.on_close_tooltip) := ((none, sa), none)
end
)
(Ξ» e β¨ca, saβ©, do
ts β tactic.read,
let m : sf := sf.flatten $ to_simple $ tactic_state.pp_tagged ts e,
let m : sf := sf.tag_expr [] e m, -- [hack] in pp.cpp I forgot to add an expr-boundary for the root expression.
v β view tooltip_comp (prod.snd <$> ca) (prod.snd <$> sa) β¨e, []β© m,
pure $
[ h "span" [
className "expr",
key e.hash,
on_mouse_leave (Ξ» _, action.on_mouse_leave_all) ] $ v
]
)
/-- Render the implicit arguments for an expression in fancy, little pills. -/
meta def implicit_arg_list (tooltip : tc subexpr empty) (e : expr) : tactic $ html empty := do
fn β (mk tooltip) $ expr.get_app_fn e,
args β list.mmap (mk tooltip) $ expr.get_app_args e,
pure $ h "div" []
( (h "span" [className "bg-blue br3 ma1 ph2 white"] [fn]) ::
list.map (Ξ» a, h "span" [className "bg-gray br3 ma1 ph2 white"] [a]) args
)
meta def type_tooltip : tc subexpr empty :=
tc.stateless (Ξ» β¨e,eaβ©, do
y β tactic.infer_type e,
y_comp β mk type_tooltip y,
implicit_args β implicit_arg_list type_tooltip e,
pure [
h "div" [] [
h "div" [] [y_comp],
h "hr" [] [],
implicit_args
]
]
)
end interactive_expression
meta def html.of_name {Ξ± : Type} : name β html Ξ±
| n := html.of_string $ name.to_string n
open tactic
meta def show_type_component : tc expr empty :=
tc.stateless (Ξ» x, do
y β infer_type x,
y_comp β interactive_expression.mk interactive_expression.type_tooltip $ y,
pure y_comp
)
meta def tactic_view_component {Ξ³} (local_c : tc expr Ξ³) (target_c : tc expr Ξ³) : tc unit Ξ³ :=
tc.stateless $ Ξ» _, do
gs β get_goals,
hs : list (html Ξ³) β gs.mmap (Ξ» g, do
ts β read,
gn β pp g,
set_goals [g],
lcs β local_context,
lchs : list (html Ξ³) β lcs.mmap (Ξ» lc, do
pn β pure $ expr.local_pp_name lc,
lh : html Ξ³ β local_c lc,
pure
$ h "tr" [key $ to_string $ expr.local_uniq_name lc] [
h "td" [cn "goal-hyp b"] [html.of_name pn],
h "td" [] [html.of_string " : "],
h "td" [] [lh]
]
),
t_comp β target_c g,
(expr.mvar u_n pp_n y) β pure g,
pure $ h "table" [key $ expr.hash g, className "font-code"] [
h "tbody" [] $ lchs ++ [
h "tr" [key u_n, className "bt"] [
h "td" [] [] ,
h "td" [cn "goal-vdash b"] [html.of_string " β’ "],
h "td" [] [t_comp]
]]
]
),
set_goals gs,
goal_message : string β pure $ if gs.length = 0 then "goals accomplished" else if gs.length = 1 then "1 goal" else (to_string gs.length) ++ " goals",
goal_message : html Ξ³ β pure $ h "strong" [cn "goal-goals"] [goal_message],
pure $ [h "ul" [className "list pl0"]
$ list.map_with_index (Ξ» i x,
let border_cn := if i < hs.length then "ba bl-0 bt-0 br-0 b--dotted b--black-30" else "" in
h "li" [className $ "lh-copy mv3 " ++ border_cn] [x])
$ (goal_message :: hs)]
meta def tactic_render : tc unit string :=
component.ignore_action $ tactic_view_component show_type_component show_type_component
meta def tactic_state_widget : component tactic_state string :=
tc.to_component tactic_render
end widget
|
3fe88d7f8b11ea767f6b45cd58560e53247a27f7
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/algebra/order/nonneg.lean
|
7838dd352b18bc6054af21c61c352a7bc2fa151d
|
[
"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
| 12,333
|
lean
|
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import algebra.order.archimedean
import algebra.order.sub
import algebra.order.with_zero
import order.lattice_intervals
import order.conditionally_complete_lattice
/-!
# The type of nonnegative elements
This file defines instances and prove some properties about the nonnegative elements
`{x : Ξ± // 0 β€ x}` of an arbitrary type `Ξ±`.
Currently we only state instances and states some `simp`/`norm_cast` lemmas.
When `Ξ±` is `β`, this will give us some properties about `ββ₯0`.
## Main declarations
* `{x : Ξ± // 0 β€ x}` is a `canonically_linear_ordered_add_monoid` if `Ξ±` is a `linear_ordered_ring`.
* `{x : Ξ± // 0 β€ x}` is a `linear_ordered_comm_group_with_zero` if `Ξ±` is a `linear_ordered_field`.
## Implementation Notes
Instead of `{x : Ξ± // 0 β€ x}` we could also use `set.Ici (0 : Ξ±)`, which is definitionally equal.
However, using the explicit subtype has a big advantage: when writing and element explicitly
with a proof of nonnegativity as `β¨x, hxβ©`, the `hx` is expected to have type `0 β€ x`. If we would
use `Ici 0`, then the type is expected to be `x β Ici 0`. Although these types are definitionally
equal, this often confuses the elaborator. Similar problems arise when doing cases on an element.
The disadvantage is that we have to duplicate some instances about `set.Ici` to this subtype.
-/
open set
variables {Ξ± : Type*}
namespace nonneg
/-- This instance uses data fields from `subtype.partial_order` to help type-class inference.
The `set.Ici` data fields are definitionally equal, but that requires unfolding semireducible
definitions, so type-class inference won't see this. -/
instance order_bot [preorder Ξ±] {a : Ξ±} : order_bot {x : Ξ± // a β€ x} :=
{ ..set.Ici.order_bot }
lemma bot_eq [preorder Ξ±] {a : Ξ±} : (β₯ : {x : Ξ± // a β€ x}) = β¨a, le_rflβ© := rfl
instance no_top_order [partial_order Ξ±] [no_top_order Ξ±] {a : Ξ±} : no_top_order {x : Ξ± // a β€ x} :=
set.Ici.no_top_order
/-- This instance uses data fields from `subtype.partial_order` to help type-class inference.
The `set.Ici` data fields are definitionally equal, but that requires unfolding semireducible
definitions, so type-class inference won't see this. -/
instance semilattice_inf_bot [semilattice_inf Ξ±] {a : Ξ±} : semilattice_inf_bot {x : Ξ± // a β€ x} :=
{ ..nonneg.order_bot, ..set.Ici.semilattice_inf_bot }
instance densely_ordered [preorder Ξ±] [densely_ordered Ξ±] {a : Ξ±} :
densely_ordered {x : Ξ± // a β€ x} :=
show densely_ordered (Ici a), from set.densely_ordered
/-- If `Sup β
β€ a` then `{x : Ξ± // a β€ x}` is a `conditionally_complete_linear_order_bot`.
This instance uses data fields from `subtype.linear_order` to help type-class inference.
The `set.Ici` data fields are definitionally equal, but that requires unfolding semireducible
definitions, so type-class inference won't see this. -/
@[reducible]
protected noncomputable def conditionally_complete_linear_order_bot
[conditionally_complete_linear_order Ξ±] {a : Ξ±} (h : Sup β
β€ a) :
conditionally_complete_linear_order_bot {x : Ξ± // a β€ x} :=
{ cSup_empty := (function.funext_iff.1
(@subset_Sup_def Ξ± (set.Ici a) _ β¨β¨a, le_rflβ©β©) β
).trans $ subtype.eq $
by { rw bot_eq, cases h.lt_or_eq with h2 h2, { simp [h2.not_le] }, simp [h2] },
..nonneg.order_bot,
..(by apply_instance : linear_order {x : Ξ± // a β€ x}),
.. @ord_connected_subset_conditionally_complete_linear_order Ξ± (set.Ici a) _ β¨β¨a, le_rflβ©β© _ }
instance inhabited [preorder Ξ±] {a : Ξ±} : inhabited {x : Ξ± // a β€ x} :=
β¨β¨a, le_rflβ©β©
instance has_zero [has_zero Ξ±] [preorder Ξ±] : has_zero {x : Ξ± // 0 β€ x} :=
β¨β¨0, le_rflβ©β©
@[simp, norm_cast]
protected lemma coe_zero [has_zero Ξ±] [preorder Ξ±] : ((0 : {x : Ξ± // 0 β€ x}) : Ξ±) = 0 := rfl
@[simp] lemma mk_eq_zero [has_zero Ξ±] [preorder Ξ±] {x : Ξ±} (hx : 0 β€ x) :
(β¨x, hxβ© : {x : Ξ± // 0 β€ x}) = 0 β x = 0 :=
subtype.ext_iff
instance has_add [add_zero_class Ξ±] [preorder Ξ±] [covariant_class Ξ± Ξ± (+) (β€)] :
has_add {x : Ξ± // 0 β€ x} :=
β¨Ξ» x y, β¨x + y, add_nonneg x.2 y.2β©β©
@[simp] lemma mk_add_mk [add_zero_class Ξ±] [preorder Ξ±] [covariant_class Ξ± Ξ± (+) (β€)] {x y : Ξ±}
(hx : 0 β€ x) (hy : 0 β€ y) : (β¨x, hxβ© : {x : Ξ± // 0 β€ x}) + β¨y, hyβ© = β¨x + y, add_nonneg hx hyβ© :=
rfl
@[simp, norm_cast]
protected lemma coe_add [add_zero_class Ξ±] [preorder Ξ±] [covariant_class Ξ± Ξ± (+) (β€)]
(a b : {x : Ξ± // 0 β€ x}) : ((a + b : {x : Ξ± // 0 β€ x}) : Ξ±) = a + b := rfl
instance ordered_add_comm_monoid [ordered_add_comm_monoid Ξ±] :
ordered_add_comm_monoid {x : Ξ± // 0 β€ x} :=
subtype.coe_injective.ordered_add_comm_monoid (coe : {x : Ξ± // 0 β€ x} β Ξ±) rfl (Ξ» x y, rfl)
instance linear_ordered_add_comm_monoid [linear_ordered_add_comm_monoid Ξ±] :
linear_ordered_add_comm_monoid {x : Ξ± // 0 β€ x} :=
subtype.coe_injective.linear_ordered_add_comm_monoid (coe : {x : Ξ± // 0 β€ x} β Ξ±) rfl (Ξ» x y, rfl)
instance ordered_cancel_add_comm_monoid [ordered_cancel_add_comm_monoid Ξ±] :
ordered_cancel_add_comm_monoid {x : Ξ± // 0 β€ x} :=
subtype.coe_injective.ordered_cancel_add_comm_monoid (coe : {x : Ξ± // 0 β€ x} β Ξ±) rfl (Ξ» x y, rfl)
instance linear_ordered_cancel_add_comm_monoid [linear_ordered_cancel_add_comm_monoid Ξ±] :
linear_ordered_cancel_add_comm_monoid {x : Ξ± // 0 β€ x} :=
subtype.coe_injective.linear_ordered_cancel_add_comm_monoid
(coe : {x : Ξ± // 0 β€ x} β Ξ±) rfl (Ξ» x y, rfl)
/-- Coercion `{x : Ξ± // 0 β€ x} β Ξ±` as a `add_monoid_hom`. -/
def coe_add_monoid_hom [ordered_add_comm_monoid Ξ±] : {x : Ξ± // 0 β€ x} β+ Ξ± :=
β¨coe, nonneg.coe_zero, nonneg.coe_addβ©
@[norm_cast]
lemma nsmul_coe [ordered_add_comm_monoid Ξ±] (n : β) (r : {x : Ξ± // 0 β€ x}) :
β(n β’ r) = n β’ (r : Ξ±) :=
nonneg.coe_add_monoid_hom.map_nsmul _ _
instance archimedean [ordered_add_comm_monoid Ξ±] [archimedean Ξ±] : archimedean {x : Ξ± // 0 β€ x} :=
β¨ assume x y pos_y,
let β¨n, hrβ© := archimedean.arch (x : Ξ±) (pos_y : (0 : Ξ±) < y) in
β¨n, show (x : Ξ±) β€ (n β’ y : {x : Ξ± // 0 β€ x}), by simp [*, -nsmul_eq_mul, nsmul_coe]β© β©
instance has_one [ordered_semiring Ξ±] : has_one {x : Ξ± // 0 β€ x} :=
{ one := β¨1, zero_le_oneβ© }
@[simp, norm_cast]
protected lemma coe_one [ordered_semiring Ξ±] : ((1 : {x : Ξ± // 0 β€ x}) : Ξ±) = 1 := rfl
@[simp] lemma mk_eq_one [ordered_semiring Ξ±] {x : Ξ±} (hx : 0 β€ x) :
(β¨x, hxβ© : {x : Ξ± // 0 β€ x}) = 1 β x = 1 :=
subtype.ext_iff
instance has_mul [ordered_semiring Ξ±] : has_mul {x : Ξ± // 0 β€ x} :=
{ mul := Ξ» x y, β¨x * y, mul_nonneg x.2 y.2β© }
@[simp, norm_cast]
protected lemma coe_mul [ordered_semiring Ξ±] (a b : {x : Ξ± // 0 β€ x}) :
((a * b : {x : Ξ± // 0 β€ x}) : Ξ±) = a * b := rfl
@[simp] lemma mk_mul_mk [ordered_semiring Ξ±] {x y : Ξ±} (hx : 0 β€ x) (hy : 0 β€ y) :
(β¨x, hxβ© : {x : Ξ± // 0 β€ x}) * β¨y, hyβ© = β¨x * y, mul_nonneg hx hyβ© :=
rfl
instance ordered_semiring [ordered_semiring Ξ±] : ordered_semiring {x : Ξ± // 0 β€ x} :=
subtype.coe_injective.ordered_semiring
(coe : {x : Ξ± // 0 β€ x} β Ξ±) rfl rfl (Ξ» x y, rfl) (Ξ» x y, rfl)
instance ordered_comm_semiring [ordered_comm_semiring Ξ±] : ordered_comm_semiring {x : Ξ± // 0 β€ x} :=
subtype.coe_injective.ordered_comm_semiring
(coe : {x : Ξ± // 0 β€ x} β Ξ±) rfl rfl (Ξ» x y, rfl) (Ξ» x y, rfl)
-- These prevent noncomputable instances being found, as it does not require `linear_order` which
-- is frequently non-computable.
instance monoid_with_zero [ordered_semiring Ξ±] : monoid_with_zero {x : Ξ± // 0 β€ x} :=
by apply_instance
instance comm_monoid_with_zero [ordered_comm_semiring Ξ±] : comm_monoid_with_zero {x : Ξ± // 0 β€ x} :=
by apply_instance
instance nontrivial [linear_ordered_semiring Ξ±] : nontrivial {x : Ξ± // 0 β€ x} :=
β¨ β¨0, 1, Ξ» h, zero_ne_one (congr_arg subtype.val h)β© β©
instance linear_ordered_semiring [linear_ordered_semiring Ξ±] :
linear_ordered_semiring {x : Ξ± // 0 β€ x} :=
subtype.coe_injective.linear_ordered_semiring
(coe : {x : Ξ± // 0 β€ x} β Ξ±) rfl rfl (Ξ» x y, rfl) (Ξ» x y, rfl)
instance linear_ordered_comm_monoid_with_zero [linear_ordered_comm_ring Ξ±] :
linear_ordered_comm_monoid_with_zero {x : Ξ± // 0 β€ x} :=
{ mul_le_mul_left := Ξ» a b h c, mul_le_mul_of_nonneg_left h c.2,
..nonneg.linear_ordered_semiring,
..nonneg.ordered_comm_semiring }
/-- Coercion `{x : Ξ± // 0 β€ x} β Ξ±` as a `ring_hom`. -/
def coe_ring_hom [ordered_semiring Ξ±] : {x : Ξ± // 0 β€ x} β+* Ξ± :=
β¨coe, nonneg.coe_one, nonneg.coe_mul, nonneg.coe_zero, nonneg.coe_addβ©
instance has_inv [linear_ordered_field Ξ±] : has_inv {x : Ξ± // 0 β€ x} :=
{ inv := Ξ» x, β¨xβ»ΒΉ, inv_nonneg.mpr x.2β© }
@[simp, norm_cast]
protected lemma coe_inv [linear_ordered_field Ξ±] (a : {x : Ξ± // 0 β€ x}) :
((aβ»ΒΉ : {x : Ξ± // 0 β€ x}) : Ξ±) = aβ»ΒΉ := rfl
@[simp] lemma inv_mk [linear_ordered_field Ξ±] {x : Ξ±} (hx : 0 β€ x) :
(β¨x, hxβ© : {x : Ξ± // 0 β€ x})β»ΒΉ = β¨xβ»ΒΉ, inv_nonneg.mpr hxβ© :=
rfl
instance linear_ordered_comm_group_with_zero [linear_ordered_field Ξ±] :
linear_ordered_comm_group_with_zero {x : Ξ± // 0 β€ x} :=
{ inv_zero := by { ext, exact inv_zero },
mul_inv_cancel := by { intros a ha, ext, refine mul_inv_cancel (mt (Ξ» h, _) ha), ext, exact h },
..nonneg.nontrivial,
..nonneg.has_inv,
..nonneg.linear_ordered_comm_monoid_with_zero }
instance has_div [linear_ordered_field Ξ±] : has_div {x : Ξ± // 0 β€ x} :=
{ div := Ξ» x y, β¨x / y, div_nonneg x.2 y.2β© }
@[simp, norm_cast]
protected lemma coe_div [linear_ordered_field Ξ±] (a b : {x : Ξ± // 0 β€ x}) :
((a / b : {x : Ξ± // 0 β€ x}) : Ξ±) = a / b := rfl
@[simp] lemma mk_div_mk [linear_ordered_field Ξ±] {x y : Ξ±} (hx : 0 β€ x) (hy : 0 β€ y) :
(β¨x, hxβ© : {x : Ξ± // 0 β€ x}) / β¨y, hyβ© = β¨x / y, div_nonneg hx hyβ© :=
rfl
instance canonically_ordered_add_monoid [ordered_ring Ξ±] :
canonically_ordered_add_monoid {x : Ξ± // 0 β€ x} :=
{ le_iff_exists_add := Ξ» β¨a, haβ© β¨b, hbβ©,
by simpa only [mk_add_mk, subtype.exists, subtype.mk_eq_mk] using le_iff_exists_nonneg_add a b,
..nonneg.ordered_add_comm_monoid,
..nonneg.order_bot }
instance canonically_ordered_comm_semiring [ordered_comm_ring Ξ±] [no_zero_divisors Ξ±] :
canonically_ordered_comm_semiring {x : Ξ± // 0 β€ x} :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := by { rintro β¨a, haβ© β¨b, hbβ©, simp },
..nonneg.canonically_ordered_add_monoid,
..nonneg.ordered_comm_semiring }
instance canonically_linear_ordered_add_monoid [linear_ordered_ring Ξ±] :
canonically_linear_ordered_add_monoid {x : Ξ± // 0 β€ x} :=
{ ..subtype.linear_order _, ..nonneg.canonically_ordered_add_monoid }
section linear_order
variables [has_zero Ξ±] [linear_order Ξ±]
/-- The function `a β¦ max a 0` of type `Ξ± β {x : Ξ± // 0 β€ x}`. -/
def to_nonneg (a : Ξ±) : {x : Ξ± // 0 β€ x} :=
β¨max a 0, le_max_right _ _β©
@[simp]
lemma coe_to_nonneg {a : Ξ±} : (to_nonneg a : Ξ±) = max a 0 := rfl
@[simp]
lemma to_nonneg_of_nonneg {a : Ξ±} (h : 0 β€ a) : to_nonneg a = β¨a, hβ© :=
by simp [to_nonneg, h]
@[simp]
lemma to_nonneg_coe {a : {x : Ξ± // 0 β€ x}} : to_nonneg (a : Ξ±) = a :=
by { cases a with a ha, exact to_nonneg_of_nonneg ha }
@[simp]
lemma to_nonneg_le {a : Ξ±} {b : {x : Ξ± // 0 β€ x}} : to_nonneg a β€ b β a β€ b :=
by { cases b with b hb, simp [to_nonneg, hb] }
@[simp]
lemma to_nonneg_lt {a : {x : Ξ± // 0 β€ x}} {b : Ξ±} : a < to_nonneg b β βa < b :=
by { cases a with a ha, simp [to_nonneg, ha.not_lt] }
instance has_sub [has_sub Ξ±] : has_sub {x : Ξ± // 0 β€ x} :=
β¨Ξ» x y, to_nonneg (x - y)β©
@[simp] lemma mk_sub_mk [has_sub Ξ±] {x y : Ξ±}
(hx : 0 β€ x) (hy : 0 β€ y) : (β¨x, hxβ© : {x : Ξ± // 0 β€ x}) - β¨y, hyβ© = to_nonneg (x - y) :=
rfl
end linear_order
instance has_ordered_sub [linear_ordered_ring Ξ±] : has_ordered_sub {x : Ξ± // 0 β€ x} :=
β¨by { rintro β¨a, haβ© β¨b, hbβ© β¨c, hcβ©, simp only [sub_le_iff_le_add, subtype.mk_le_mk, mk_sub_mk,
mk_add_mk, to_nonneg_le, subtype.coe_mk]}β©
end nonneg
|
e6fd6e31825adb425b4b9c885aab800ca1b99ddf
|
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
|
/src/data/real/irrational.lean
|
f97077b2d096317683cff5a18903bd333ede06dc
|
[
"Apache-2.0"
] |
permissive
|
dupuisf/mathlib
|
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
|
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
|
refs/heads/master
| 1,669,494,854,016
| 1,595,692,409,000
| 1,595,692,409,000
| 272,046,630
| 0
| 0
|
Apache-2.0
| 1,592,066,143,000
| 1,592,066,142,000
| null |
UTF-8
|
Lean
| false
| false
| 8,255
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Yury Kudryashov.
-/
import data.real.basic
import data.rat.sqrt
import algebra.gcd_domain
import ring_theory.multiplicity
/-!
# Irrational real numbers
In this file we define a predicate `irrational` on `β`, prove that the `n`-th root of an integer
number is irrational if it is not integer, and that `sqrt q` is irrational if and only if
`rat.sqrt q * rat.sqrt q β q β§ 0 β€ q`.
We also provide dot-style constructors like `irrational.add_rat`, `irrational.rat_sub` etc.
-/
open rat real multiplicity
/-- A real number is irrational if it is not equal to any rational number. -/
def irrational (x : β) := x β set.range (coe : β β β)
/-!
### Irrationality of roots of integer and rational numbers
-/
/-- If `x^n`, `n > 0`, is integer and is not the `n`-th power of an integer, then
`x` is irrational. -/
theorem irrational_nrt_of_notint_nrt {x : β} (n : β) (m : β€)
(hxr : x ^ n = m) (hv : Β¬ β y : β€, x = y) (hnpos : 0 < n) :
irrational x :=
begin
rintros β¨β¨N, D, P, Cβ©, rflβ©,
rw [β cast_pow] at hxr,
have c1 : ((D : β€) : β) β 0,
{ rw [int.cast_ne_zero, int.coe_nat_ne_zero], exact ne_of_gt P },
have c2 : ((D : β€) : β) ^ n β 0 := pow_ne_zero _ c1,
rw [num_denom', cast_pow, cast_mk, div_pow, div_eq_iff_mul_eq c2,
β int.cast_pow, β int.cast_pow, β int.cast_mul, int.cast_inj] at hxr,
have hdivn : βD ^ n β£ N ^ n := dvd.intro_left m hxr,
rw [β int.dvd_nat_abs, β int.coe_nat_pow, int.coe_nat_dvd, int.nat_abs_pow,
nat.pow_dvd_pow_iff hnpos] at hdivn,
have hD : D = 1 := by rw [β nat.gcd_eq_right hdivn, C.gcd_eq_one],
subst D,
refine hv β¨N, _β©,
rw [num_denom', int.coe_nat_one, mk_eq_div, int.cast_one, div_one, cast_coe_int]
end
/-- If `x^n = m` is an integer and `n` does not divide the `multiplicity p m`, then `x`
is irrational. -/
theorem irrational_nrt_of_n_not_dvd_multiplicity {x : β} (n : β) {m : β€} (hm : m β 0) (p : β)
[hp : fact p.prime] (hxr : x ^ n = m)
(hv : (multiplicity (p : β€) m).get (finite_int_iff.2 β¨hp.ne_one, hmβ©) % n β 0) :
irrational x :=
begin
rcases nat.eq_zero_or_pos n with rfl | hnpos,
{ rw [eq_comm, pow_zero, β int.cast_one, int.cast_inj] at hxr,
simpa [hxr, multiplicity.one_right (mt is_unit_iff_dvd_one.1
(mt int.coe_nat_dvd.1 hp.not_dvd_one)), nat.zero_mod] using hv },
refine irrational_nrt_of_notint_nrt _ _ hxr _ hnpos,
rintro β¨y, rflβ©,
rw [β int.cast_pow, int.cast_inj] at hxr, subst m,
have : y β 0, { rintro rfl, rw zero_pow hnpos at hm, exact hm rfl },
erw [multiplicity.pow' (nat.prime_iff_prime_int.1 hp)
(finite_int_iff.2 β¨hp.ne_one, thisβ©), nat.mul_mod_right] at hv,
exact hv rfl
end
theorem irrational_sqrt_of_multiplicity_odd (m : β€) (hm : 0 < m)
(p : β) [hp : fact p.prime]
(Hpv : (multiplicity (p : β€) m).get (finite_int_iff.2 β¨hp.ne_one, (ne_of_lt hm).symmβ©) % 2 = 1) :
irrational (sqrt m) :=
@irrational_nrt_of_n_not_dvd_multiplicity _ 2 _ (ne.symm (ne_of_lt hm)) p hp
(sqr_sqrt (int.cast_nonneg.2 $ le_of_lt hm))
(by rw Hpv; exact one_ne_zero)
theorem nat.prime.irrational_sqrt {p : β} (hp : nat.prime p) : irrational (sqrt p) :=
@irrational_sqrt_of_multiplicity_odd p (int.coe_nat_pos.2 hp.pos) p hp $
by simp [multiplicity_self (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.not_dvd_one) : _)];
refl
theorem irrational_sqrt_two : irrational (sqrt 2) :=
by simpa using nat.prime_two.irrational_sqrt
theorem irrational_sqrt_rat_iff (q : β) : irrational (sqrt q) β
rat.sqrt q * rat.sqrt q β q β§ 0 β€ q :=
if H1 : rat.sqrt q * rat.sqrt q = q
then iff_of_false (not_not_intro β¨rat.sqrt q,
by rw [β H1, cast_mul, sqrt_mul_self (cast_nonneg.2 $ rat.sqrt_nonneg q),
sqrt_eq, abs_of_nonneg (rat.sqrt_nonneg q)]β©) (Ξ» h, h.1 H1)
else if H2 : 0 β€ q
then iff_of_true (Ξ» β¨r, hrβ©, H1 $ (exists_mul_self _).1 β¨r,
by rwa [eq_comm, sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), β cast_mul, cast_inj] at hr;
rw [β hr]; exact real.sqrt_nonneg _β©) β¨H1, H2β©
else iff_of_false (not_not_intro β¨0,
by rw cast_zero; exact (sqrt_eq_zero_of_nonpos (rat.cast_nonpos.2 $ le_of_not_le H2)).symmβ©)
(Ξ» h, H2 h.2)
instance (q : β) : decidable (irrational (sqrt q)) :=
decidable_of_iff' _ (irrational_sqrt_rat_iff q)
/-!
### Adding/subtracting/multiplying by rational numbers
-/
lemma rat.not_irrational (q : β) : Β¬irrational q := Ξ» h, h β¨q, rflβ©
namespace irrational
variables (q : β) {x y : β}
open_locale classical
theorem add_cases : irrational (x + y) β irrational x β¨ irrational y :=
begin
delta irrational,
contrapose!,
rintros β¨β¨rx, rflβ©, β¨ry, rflβ©β©,
exact β¨rx + ry, cast_add rx ryβ©
end
theorem of_rat_add (h : irrational (q + x)) : irrational x :=
h.add_cases.elim (Ξ» h, absurd h q.not_irrational) id
theorem rat_add (h : irrational x) : irrational (q + x) :=
of_rat_add (-q) $ by rwa [cast_neg, neg_add_cancel_left]
theorem of_add_rat : irrational (x + q) β irrational x :=
add_comm βq x βΈ of_rat_add q
theorem add_rat (h : irrational x) : irrational (x + q) :=
add_comm βq x βΈ h.rat_add q
theorem of_neg (h : irrational (-x)) : irrational x :=
Ξ» β¨q, hxβ©, h β¨-q, by rw [cast_neg, hx]β©
protected theorem neg (h : irrational x) : irrational (-x) :=
of_neg $ by rwa neg_neg
theorem sub_rat (h : irrational x) : irrational (x - q) :=
by simpa only [cast_neg] using h.add_rat (-q)
theorem rat_sub (h : irrational x) : irrational (q - x) :=
h.neg.rat_add q
theorem of_sub_rat (h : irrational (x - q)) : irrational x :=
of_add_rat (-q) $ by simpa only [cast_neg]
theorem of_rat_sub (h : irrational (q - x)) : irrational x :=
(h.of_rat_add _).of_neg
theorem mul_cases : irrational (x * y) β irrational x β¨ irrational y :=
begin
delta irrational,
contrapose!,
rintros β¨β¨rx, rflβ©, β¨ry, rflβ©β©,
exact β¨rx * ry, cast_mul rx ryβ©
end
theorem of_mul_rat (h : irrational (x * q)) : irrational x :=
h.mul_cases.elim id (Ξ» h, absurd h q.not_irrational)
theorem mul_rat (h : irrational x) {q : β} (hq : q β 0) : irrational (x * q) :=
of_mul_rat qβ»ΒΉ $ by rwa [mul_assoc, β cast_mul, mul_inv_cancel hq, cast_one, mul_one]
theorem of_rat_mul : irrational (q * x) β irrational x :=
mul_comm x q βΈ of_mul_rat q
theorem rat_mul (h : irrational x) {q : β} (hq : q β 0) : irrational (q * x) :=
mul_comm x q βΈ h.mul_rat hq
theorem of_mul_self (h : irrational (x * x)) : irrational x :=
h.mul_cases.elim id id
theorem of_inv (h : irrational xβ»ΒΉ) : irrational x :=
Ξ» β¨q, hqβ©, h $ hq βΈ β¨qβ»ΒΉ, q.cast_invβ©
protected theorem inv (h : irrational x) : irrational xβ»ΒΉ :=
of_inv $ by rwa inv_inv'
theorem div_cases (h : irrational (x / y)) : irrational x β¨ irrational y :=
h.mul_cases.imp id of_inv
theorem of_rat_div (h : irrational (q / x)) : irrational x :=
(h.of_rat_mul q).of_inv
theorem of_one_div (h : irrational (1 / x)) : irrational x :=
of_rat_div 1 $ by rwa [cast_one]
theorem of_pow : β n : β, irrational (x^n) β irrational x
| 0 := Ξ» h, (h β¨1, cast_oneβ©).elim
| (n+1) := Ξ» h, h.mul_cases.elim id (of_pow n)
theorem of_fpow : β m : β€, irrational (x^m) β irrational x
| (n:β) := of_pow n
| -[1+n] := Ξ» h, by { rw fpow_neg_succ_of_nat at h, exact h.of_inv.of_pow _ }
end irrational
section
variables {q : β} {x : β}
open irrational
@[simp] theorem irrational_rat_add_iff : irrational (q + x) β irrational x :=
β¨of_rat_add q, rat_add qβ©
@[simp] theorem irrational_add_rat_iff : irrational (x + q) β irrational x :=
β¨of_add_rat q, add_rat qβ©
@[simp] theorem irrational_rat_sub_iff : irrational (q - x) β irrational x :=
β¨of_rat_sub q, rat_sub qβ©
@[simp] theorem irrational_sub_rat_iff : irrational (x - q) β irrational x :=
β¨of_sub_rat q, sub_rat qβ©
@[simp] theorem irrational_neg_iff : irrational (-x) β irrational x :=
β¨of_neg, irrational.negβ©
@[simp] theorem irrational_inv_iff : irrational xβ»ΒΉ β irrational x :=
β¨of_inv, irrational.invβ©
end
|
db9e8f30f001336fb2b79805544fd390fae260fe
|
5e3548e65f2c037cb94cd5524c90c623fbd6d46a
|
/src_icannos_totilas/groupes/cpge_groupe_3_a.lean
|
cef54c1c24ab71cfe93f7f56547224753942d3f3
|
[] |
no_license
|
ahayat16/lean_exos
|
d4f08c30adb601a06511a71b5ffb4d22d12ef77f
|
682f2552d5b04a8c8eb9e4ab15f875a91b03845c
|
refs/heads/main
| 1,693,101,073,585
| 1,636,479,336,000
| 1,636,479,336,000
| 415,000,441
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 214
|
lean
|
import data.complex.basic
import algebra.field
theorem cpge_group_3_a {G1 : Type*} [group G1] {G2 : Type*} [group G2]
(H : (subgroup G1)) (f : (G1 β* G2) ) : is_subgroup (f '' H) := sorry
|
a0e8fe100217862a13e9984f306d6d232289a105
|
367134ba5a65885e863bdc4507601606690974c1
|
/src/category_theory/limits/opposites.lean
|
981f62eb307d5cfd7972f1098c81a8920725ac6b
|
[
"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
| 4,507
|
lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Floris van Doorn
-/
import category_theory.limits.shapes.products
import category_theory.discrete_category
universes v u
noncomputable theory
open category_theory
open category_theory.functor
open opposite
namespace category_theory.limits
variables {C : Type u} [category.{v} C]
variables {J : Type v} [small_category J]
variable (F : J β₯€ Cα΅α΅)
/--
If `F.left_op : Jα΅α΅ β₯€ C` has a colimit, we can construct a limit for `F : J β₯€ Cα΅α΅`.
-/
lemma has_limit_of_has_colimit_left_op [has_colimit F.left_op] : has_limit F :=
has_limit.mk
{ cone := cone_of_cocone_left_op (colimit.cocone F.left_op),
is_limit :=
{ lift := Ξ» s, (colimit.desc F.left_op (cocone_left_op_of_cone s)).op,
fac' := Ξ» s j,
begin
rw [cone_of_cocone_left_op_Ο_app, colimit.cocone_ΞΉ, βop_comp,
colimit.ΞΉ_desc, cocone_left_op_of_cone_ΞΉ_app, has_hom.hom.op_unop],
refl, end,
uniq' := Ξ» s m w,
begin
-- It's a pity we can't do this automatically.
-- Usually something like this would work by limit.hom_ext,
-- but the opposites get in the way of this firing.
have u := (colimit.is_colimit F.left_op).uniq (cocone_left_op_of_cone s) (m.unop),
convert congr_arg (Ξ» f : _ βΆ _, f.op) (u _), clear u,
intro j,
rw [cocone_left_op_of_cone_ΞΉ_app, colimit.cocone_ΞΉ],
convert congr_arg (Ξ» f : _ βΆ _, f.unop) (w (unop j)), clear w,
rw [cone_of_cocone_left_op_Ο_app, colimit.cocone_ΞΉ, has_hom.hom.unop_op],
refl,
end } }
/--
If `C` has colimits of shape `Jα΅α΅`, we can construct limits in `Cα΅α΅` of shape `J`.
-/
lemma has_limits_of_shape_op_of_has_colimits_of_shape [has_colimits_of_shape Jα΅α΅ C] :
has_limits_of_shape J Cα΅α΅ :=
{ has_limit := Ξ» F, has_limit_of_has_colimit_left_op F }
local attribute [instance] has_limits_of_shape_op_of_has_colimits_of_shape
/--
If `C` has colimits, we can construct limits for `Cα΅α΅`.
-/
lemma has_limits_op_of_has_colimits [has_colimits C] : has_limits Cα΅α΅ :=
{ has_limits_of_shape := Ξ» J π₯, by { resetI, apply_instance } }
/--
If `F.left_op : Jα΅α΅ β₯€ C` has a limit, we can construct a colimit for `F : J β₯€ Cα΅α΅`.
-/
lemma has_colimit_of_has_limit_left_op [has_limit F.left_op] : has_colimit F :=
has_colimit.mk
{ cocone := cocone_of_cone_left_op (limit.cone F.left_op),
is_colimit :=
{ desc := Ξ» s, (limit.lift F.left_op (cone_left_op_of_cocone s)).op,
fac' := Ξ» s j,
begin
rw [cocone_of_cone_left_op_ΞΉ_app, limit.cone_Ο, βop_comp,
limit.lift_Ο, cone_left_op_of_cocone_Ο_app, has_hom.hom.op_unop],
refl, end,
uniq' := Ξ» s m w,
begin
have u := (limit.is_limit F.left_op).uniq (cone_left_op_of_cocone s) (m.unop),
convert congr_arg (Ξ» f : _ βΆ _, f.op) (u _), clear u,
intro j,
rw [cone_left_op_of_cocone_Ο_app, limit.cone_Ο],
convert congr_arg (Ξ» f : _ βΆ _, f.unop) (w (unop j)), clear w,
rw [cocone_of_cone_left_op_ΞΉ_app, limit.cone_Ο, has_hom.hom.unop_op],
refl,
end } }
/--
If `C` has colimits of shape `Jα΅α΅`, we can construct limits in `Cα΅α΅` of shape `J`.
-/
lemma has_colimits_of_shape_op_of_has_limits_of_shape [has_limits_of_shape Jα΅α΅ C] :
has_colimits_of_shape J Cα΅α΅ :=
{ has_colimit := Ξ» F, has_colimit_of_has_limit_left_op F }
local attribute [instance] has_colimits_of_shape_op_of_has_limits_of_shape
/--
If `C` has limits, we can construct colimits for `Cα΅α΅`.
-/
lemma has_colimits_op_of_has_limits [has_limits C] : has_colimits Cα΅α΅ :=
{ has_colimits_of_shape := Ξ» J π₯, by { resetI, apply_instance } }
variables (X : Type v)
/--
If `C` has products indexed by `X`, then `Cα΅α΅` has coproducts indexed by `X`.
-/
lemma has_coproducts_opposite [has_products_of_shape X C] :
has_coproducts_of_shape X Cα΅α΅ :=
begin
haveI : has_limits_of_shape (discrete X)α΅α΅ C :=
has_limits_of_shape_of_equivalence (discrete.opposite X).symm,
apply_instance
end
/--
If `C` has coproducts indexed by `X`, then `Cα΅α΅` has products indexed by `X`.
-/
lemma has_products_opposite [has_coproducts_of_shape X C] :
has_products_of_shape X Cα΅α΅ :=
begin
haveI : has_colimits_of_shape (discrete X)α΅α΅ C :=
has_colimits_of_shape_of_equivalence (discrete.opposite X).symm,
apply_instance
end
end category_theory.limits
|
929b6faa834192c6fbda585b8585015b30fecaa3
|
4fa161becb8ce7378a709f5992a594764699e268
|
/src/category_theory/limits/limits.lean
|
f75d4673222f4d13c1164a17911d8987d14effc3
|
[
"Apache-2.0"
] |
permissive
|
laughinggas/mathlib
|
e4aa4565ae34e46e834434284cb26bd9d67bc373
|
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
|
refs/heads/master
| 1,669,496,232,688
| 1,592,831,995,000
| 1,592,831,995,000
| 274,155,979
| 0
| 0
|
Apache-2.0
| 1,592,835,190,000
| 1,592,835,189,000
| null |
UTF-8
|
Lean
| false
| false
| 43,221
|
lean
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn
-/
import category_theory.limits.cones
import category_theory.adjunction.basic
open category_theory category_theory.category category_theory.functor opposite
namespace category_theory.limits
universes v u u' u'' w -- declare the `v`'s first; see `category_theory.category` for an explanation
-- See the notes at the top of cones.lean, explaining why we can't allow `J : Prop` here.
variables {J K : Type v} [small_category J] [small_category K]
variables {C : Type u} [category.{v} C]
variables {F : J β₯€ C}
/-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique
cone morphism to `t`. -/
@[nolint has_inhabited_instance]
structure is_limit (t : cone F) :=
(lift : Ξ (s : cone F), s.X βΆ t.X)
(fac' : β (s : cone F) (j : J), lift s β« t.Ο.app j = s.Ο.app j . obviously)
(uniq' : β (s : cone F) (m : s.X βΆ t.X) (w : β j : J, m β« t.Ο.app j = s.Ο.app j),
m = lift s . obviously)
restate_axiom is_limit.fac'
attribute [simp, reassoc] is_limit.fac
restate_axiom is_limit.uniq'
namespace is_limit
instance subsingleton {t : cone F} : subsingleton (is_limit t) :=
β¨by intros P Q; cases P; cases Q; congr; ext; solve_by_elimβ©
/- Repackaging the definition in terms of cone morphisms. -/
/-- The universal morphism from any other cone to a limit cone. -/
def lift_cone_morphism {t : cone F} (h : is_limit t) (s : cone F) : s βΆ t :=
{ hom := h.lift s }
lemma uniq_cone_morphism {s t : cone F} (h : is_limit t) {f f' : s βΆ t} :
f = f' :=
have β {g : s βΆ t}, g = h.lift_cone_morphism s, by intro g; ext; exact h.uniq _ _ g.w,
this.trans this.symm
/--
Alternative constructor for `is_limit`,
providing a morphism of cones rather than a morphism between the cone points
and separately the factorisation condition.
-/
def mk_cone_morphism {t : cone F}
(lift : Ξ (s : cone F), s βΆ t)
(uniq' : β (s : cone F) (m : s βΆ t), m = lift s) : is_limit t :=
{ lift := Ξ» s, (lift s).hom,
uniq' := Ξ» s m w,
have cone_morphism.mk m w = lift s, by apply uniq',
congr_arg cone_morphism.hom this }
/-- Limit cones on `F` are unique up to isomorphism. -/
def unique_up_to_iso {s t : cone F} (P : is_limit s) (Q : is_limit t) : s β
t :=
{ hom := Q.lift_cone_morphism s,
inv := P.lift_cone_morphism t,
hom_inv_id' := P.uniq_cone_morphism,
inv_hom_id' := Q.uniq_cone_morphism }
/-- Limits of `F` are unique up to isomorphism. -/
-- We may later want to prove the coherence of these isomorphisms.
def cone_point_unique_up_to_iso {s t : cone F} (P : is_limit s) (Q : is_limit t) : s.X β
t.X :=
(cones.forget F).map_iso (unique_up_to_iso P Q)
/-- Transport evidence that a cone is a limit cone across an isomorphism of cones. -/
def of_iso_limit {r t : cone F} (P : is_limit r) (i : r β
t) : is_limit t :=
is_limit.mk_cone_morphism
(Ξ» s, P.lift_cone_morphism s β« i.hom)
(Ξ» s m, by rw βi.comp_inv_eq; apply P.uniq_cone_morphism)
variables {t : cone F}
lemma hom_lift (h : is_limit t) {W : C} (m : W βΆ t.X) :
m = h.lift { X := W, Ο := { app := Ξ» b, m β« t.Ο.app b } } :=
h.uniq { X := W, Ο := { app := Ξ» b, m β« t.Ο.app b } } m (Ξ» b, rfl)
/-- Two morphisms into a limit are equal if their compositions with
each cone morphism are equal. -/
lemma hom_ext (h : is_limit t) {W : C} {f f' : W βΆ t.X}
(w : β j, f β« t.Ο.app j = f' β« t.Ο.app j) : f = f' :=
by rw [h.hom_lift f, h.hom_lift f']; congr; exact funext w
/-- The universal property of a limit cone: a map `W βΆ X` is the same as
a cone on `F` with vertex `W`. -/
def hom_iso (h : is_limit t) (W : C) : (W βΆ t.X) β
((const J).obj W βΆ F) :=
{ hom := Ξ» f, (t.extend f).Ο,
inv := Ξ» Ο, h.lift { X := W, Ο := Ο },
hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl }
@[simp] lemma hom_iso_hom (h : is_limit t) {W : C} (f : W βΆ t.X) :
(is_limit.hom_iso h W).hom f = (t.extend f).Ο := rfl
/-- The limit of `F` represents the functor taking `W` to
the set of cones on `F` with vertex `W`. -/
def nat_iso (h : is_limit t) : yoneda.obj t.X β
F.cones :=
nat_iso.of_components (Ξ» W, is_limit.hom_iso h (unop W)) (by tidy).
/--
Another, more explicit, formulation of the universal property of a limit cone.
See also `hom_iso`.
-/
def hom_iso' (h : is_limit t) (W : C) :
((W βΆ t.X) : Type v) β
{ p : Ξ j, W βΆ F.obj j // β {j j'} (f : j βΆ j'), p j β« F.map f = p j' } :=
h.hom_iso W βͺβ«
{ hom := Ξ» Ο,
β¨Ξ» j, Ο.app j, Ξ» j j' f,
by convert β(Ο.naturality f).symm; apply id_compβ©,
inv := Ξ» p,
{ app := Ξ» j, p.1 j,
naturality' := Ξ» j j' f, begin dsimp, rw [id_comp], exact (p.2 f).symm end } }
/-- If G : C β D is a faithful functor which sends t to a limit cone,
then it suffices to check that the induced maps for the image of t
can be lifted to maps of C. -/
def of_faithful {t : cone F} {D : Type u'} [category.{v} D] (G : C β₯€ D) [faithful G]
(ht : is_limit (G.map_cone t)) (lift : Ξ (s : cone F), s.X βΆ t.X)
(h : β s, G.map (lift s) = ht.lift (G.map_cone s)) : is_limit t :=
{ lift := lift,
fac' := Ξ» s j, by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac,
uniq' := Ξ» s m w, begin
apply G.map_injective, rw h,
refine ht.uniq (G.map_cone s) _ (Ξ» j, _),
convert βcongr_arg (Ξ» f, G.map f) (w j),
apply G.map_comp
end }
/--
If `F` and `G` are naturally isomorphic, then `F.map_cone c` being a limit implies
`G.map_cone c` is also a limit.
-/
def map_cone_equiv {D : Type u'} [category.{v} D] {K : J β₯€ C} {F G : C β₯€ D} (h : F β
G) {c : cone K}
(t : is_limit (F.map_cone c)) : is_limit (G.map_cone c) :=
{ lift := Ξ» s, t.lift ((cones.postcompose (iso_whisker_left K h).inv).obj s) β« h.hom.app c.X,
fac' := Ξ» s j,
begin
slice_lhs 2 3 {erw β h.hom.naturality (c.Ο.app j)},
slice_lhs 1 2 {erw t.fac ((cones.postcompose (iso_whisker_left K h).inv).obj s) j},
dsimp,
slice_lhs 2 3 {rw nat_iso.inv_hom_id_app},
rw category.comp_id,
end,
uniq' := Ξ» s m J,
begin
rw β cancel_mono (h.inv.app c.X),
apply t.hom_ext,
intro j,
dsimp,
slice_lhs 2 3 {erw β h.inv.naturality (c.Ο.app j)},
slice_lhs 1 2 {erw J j},
conv_rhs {congr, rw [category.assoc, nat_iso.hom_inv_id_app, comp_id]},
apply (t.fac ((cones.postcompose (iso_whisker_left K h).inv).obj s) j).symm
end }
/--
A cone is a limit cone exactly if
there is a unique cone morphism from any other cone.
-/
def iso_unique_cone_morphism {t : cone F} :
is_limit t β
Ξ s, unique (s βΆ t) :=
{ hom := Ξ» h s,
{ default := h.lift_cone_morphism s,
uniq := Ξ» _, h.uniq_cone_morphism },
inv := Ξ» h,
{ lift := Ξ» s, (h s).default.hom,
uniq' := Ξ» s f w, congr_arg cone_morphism.hom ((h s).uniq β¨f, wβ©) } }
/--
Given two functors which have equivalent categories of cones, we can transport a limiting cone across
the equivalence.
-/
def of_cone_equiv {D : Type u'} [category.{v} D] {G : K β₯€ D}
(h : cone G β₯€ cone F) [is_right_adjoint h] {c : cone G} (t : is_limit c) :
is_limit (h.obj c) :=
mk_cone_morphism
(Ξ» s, (adjunction.of_right_adjoint h).hom_equiv s c (t.lift_cone_morphism _))
(Ξ» s m, (adjunction.eq_hom_equiv_apply _ _ _).2 t.uniq_cone_morphism )
namespace of_nat_iso
variables {X : C} (h : yoneda.obj X β
F.cones)
/-- If `F.cones` is represented by `X`, each morphism `f : Y βΆ X` gives a cone with cone point `Y`. -/
def cone_of_hom {Y : C} (f : Y βΆ X) : cone F :=
{ X := Y, Ο := h.hom.app (op Y) f }
/-- If `F.cones` is represented by `X`, each cone `s` gives a morphism `s.X βΆ X`. -/
def hom_of_cone (s : cone F) : s.X βΆ X := h.inv.app (op s.X) s.Ο
@[simp] lemma cone_of_hom_of_cone (s : cone F) : cone_of_hom h (hom_of_cone h s) = s :=
begin
dsimp [cone_of_hom, hom_of_cone], cases s, congr, dsimp,
exact congr_fun (congr_fun (congr_arg nat_trans.app h.inv_hom_id) (op s_X)) s_Ο,
end
@[simp] lemma hom_of_cone_of_hom {Y : C} (f : Y βΆ X) : hom_of_cone h (cone_of_hom h f) = f :=
congr_fun (congr_fun (congr_arg nat_trans.app h.hom_inv_id) (op Y)) f
/-- If `F.cones` is represented by `X`, the cone corresponding to the identity morphism on `X`
will be a limit cone. -/
def limit_cone : cone F :=
cone_of_hom h (π X)
/-- If `F.cones` is represented by `X`, the cone corresponding to a morphism `f : Y βΆ X` is
the limit cone extended by `f`. -/
lemma cone_of_hom_fac {Y : C} (f : Y βΆ X) :
cone_of_hom h f = (limit_cone h).extend f :=
begin
dsimp [cone_of_hom, limit_cone, cone.extend],
congr,
ext j,
have t := congr_fun (h.hom.naturality f.op) (π X),
dsimp at t,
simp only [comp_id] at t,
rw congr_fun (congr_arg nat_trans.app t) j,
refl,
end
/-- If `F.cones` is represented by `X`, any cone is the extension of the limit cone by the
corresponding morphism. -/
lemma cone_fac (s : cone F) : (limit_cone h).extend (hom_of_cone h s) = s :=
begin
rw βcone_of_hom_of_cone h s,
conv_lhs { simp only [hom_of_cone_of_hom] },
apply (cone_of_hom_fac _ _).symm,
end
end of_nat_iso
section
open of_nat_iso
/--
If `F.cones` is representable, then the cone corresponding to the identity morphism on
the representing object is a limit cone.
-/
def of_nat_iso {X : C} (h : yoneda.obj X β
F.cones) :
is_limit (limit_cone h) :=
{ lift := Ξ» s, hom_of_cone h s,
fac' := Ξ» s j,
begin
have h := cone_fac h s,
cases s,
injection h with hβ hβ,
simp only [heq_iff_eq] at hβ,
conv_rhs { rw β hβ }, refl,
end,
uniq' := Ξ» s m w,
begin
rw βhom_of_cone_of_hom h m,
congr,
rw cone_of_hom_fac,
dsimp, cases s, congr,
ext j, exact w j,
end }
end
end is_limit
/-- A cocone `t` on `F` is a colimit cocone if each cocone on `F` admits a unique
cocone morphism from `t`. -/
@[nolint has_inhabited_instance]
structure is_colimit (t : cocone F) :=
(desc : Ξ (s : cocone F), t.X βΆ s.X)
(fac' : β (s : cocone F) (j : J), t.ΞΉ.app j β« desc s = s.ΞΉ.app j . obviously)
(uniq' : β (s : cocone F) (m : t.X βΆ s.X) (w : β j : J, t.ΞΉ.app j β« m = s.ΞΉ.app j),
m = desc s . obviously)
restate_axiom is_colimit.fac'
attribute [simp] is_colimit.fac
restate_axiom is_colimit.uniq'
namespace is_colimit
instance subsingleton {t : cocone F} : subsingleton (is_colimit t) :=
β¨by intros P Q; cases P; cases Q; congr; ext; solve_by_elimβ©
/- Repackaging the definition in terms of cone morphisms. -/
/-- The universal morphism from a colimit cocone to any other cone. -/
def desc_cocone_morphism {t : cocone F} (h : is_colimit t) (s : cocone F) : t βΆ s :=
{ hom := h.desc s }
lemma uniq_cocone_morphism {s t : cocone F} (h : is_colimit t) {f f' : t βΆ s} :
f = f' :=
have β {g : t βΆ s}, g = h.desc_cocone_morphism s, by intro g; ext; exact h.uniq _ _ g.w,
this.trans this.symm
/--
Alternative constructor for `is_colimit`,
providing a morphism of cocones rather than a morphism between the cocone points
and separately the factorisation condition.
-/
def mk_cocone_morphism {t : cocone F}
(desc : Ξ (s : cocone F), t βΆ s)
(uniq' : β (s : cocone F) (m : t βΆ s), m = desc s) : is_colimit t :=
{ desc := Ξ» s, (desc s).hom,
uniq' := Ξ» s m w,
have cocone_morphism.mk m w = desc s, by apply uniq',
congr_arg cocone_morphism.hom this }
/-- Limit cones on `F` are unique up to isomorphism. -/
def unique_up_to_iso {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : s β
t :=
{ hom := P.desc_cocone_morphism t,
inv := Q.desc_cocone_morphism s,
hom_inv_id' := P.uniq_cocone_morphism,
inv_hom_id' := Q.uniq_cocone_morphism }
/-- Colimits of `F` are unique up to isomorphism. -/
-- We may later want to prove the coherence of these isomorphisms.
def cocone_point_unique_up_to_iso {s t : cocone F} (P : is_colimit s) (Q : is_colimit t) : s.X β
t.X :=
(cocones.forget F).map_iso (unique_up_to_iso P Q)
/-- Transport evidence that a cocone is a colimit cocone across an isomorphism of cocones. -/
def of_iso_colimit {r t : cocone F} (P : is_colimit r) (i : r β
t) : is_colimit t :=
is_colimit.mk_cocone_morphism
(Ξ» s, i.inv β« P.desc_cocone_morphism s)
(Ξ» s m, by rw i.eq_inv_comp; apply P.uniq_cocone_morphism)
variables {t : cocone F}
lemma hom_desc (h : is_colimit t) {W : C} (m : t.X βΆ W) :
m = h.desc { X := W, ΞΉ := { app := Ξ» b, t.ΞΉ.app b β« m,
naturality' := by intros; erw [βassoc, t.ΞΉ.naturality, comp_id, comp_id] } } :=
h.uniq { X := W, ΞΉ := { app := Ξ» b, t.ΞΉ.app b β« m, naturality' := _ } } m (Ξ» b, rfl)
/-- Two morphisms out of a colimit are equal if their compositions with
each cocone morphism are equal. -/
lemma hom_ext (h : is_colimit t) {W : C} {f f' : t.X βΆ W}
(w : β j, t.ΞΉ.app j β« f = t.ΞΉ.app j β« f') : f = f' :=
by rw [h.hom_desc f, h.hom_desc f']; congr; exact funext w
/-- The universal property of a colimit cocone: a map `X βΆ W` is the same as
a cocone on `F` with vertex `W`. -/
def hom_iso (h : is_colimit t) (W : C) : (t.X βΆ W) β
(F βΆ (const J).obj W) :=
{ hom := Ξ» f, (t.extend f).ΞΉ,
inv := Ξ» ΞΉ, h.desc { X := W, ΞΉ := ΞΉ },
hom_inv_id' := by ext f; apply h.hom_ext; intro j; simp; dsimp; refl }
@[simp] lemma hom_iso_hom (h : is_colimit t) {W : C} (f : t.X βΆ W) :
(is_colimit.hom_iso h W).hom f = (t.extend f).ΞΉ := rfl
/-- The colimit of `F` represents the functor taking `W` to
the set of cocones on `F` with vertex `W`. -/
def nat_iso (h : is_colimit t) : coyoneda.obj (op t.X) β
F.cocones :=
nat_iso.of_components (is_colimit.hom_iso h) (by intros; ext; dsimp; rw βassoc; refl)
/--
Another, more explicit, formulation of the universal property of a colimit cocone.
See also `hom_iso`.
-/
def hom_iso' (h : is_colimit t) (W : C) :
((t.X βΆ W) : Type v) β
{ p : Ξ j, F.obj j βΆ W // β {j j' : J} (f : j βΆ j'), F.map f β« p j' = p j } :=
h.hom_iso W βͺβ«
{ hom := Ξ» ΞΉ,
β¨Ξ» j, ΞΉ.app j, Ξ» j j' f,
by convert β(ΞΉ.naturality f); apply comp_idβ©,
inv := Ξ» p,
{ app := Ξ» j, p.1 j,
naturality' := Ξ» j j' f, begin dsimp, rw [comp_id], exact (p.2 f) end } }
/-- If G : C β D is a faithful functor which sends t to a colimit cocone,
then it suffices to check that the induced maps for the image of t
can be lifted to maps of C. -/
def of_faithful {t : cocone F} {D : Type u'} [category.{v} D] (G : C β₯€ D) [faithful G]
(ht : is_colimit (G.map_cocone t)) (desc : Ξ (s : cocone F), t.X βΆ s.X)
(h : β s, G.map (desc s) = ht.desc (G.map_cocone s)) : is_colimit t :=
{ desc := desc,
fac' := Ξ» s j, by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac,
uniq' := Ξ» s m w, begin
apply G.map_injective, rw h,
refine ht.uniq (G.map_cocone s) _ (Ξ» j, _),
convert βcongr_arg (Ξ» f, G.map f) (w j),
apply G.map_comp
end }
/--
A cocone is a colimit cocone exactly if
there is a unique cocone morphism from any other cocone.
-/
def iso_unique_cocone_morphism {t : cocone F} :
is_colimit t β
Ξ s, unique (t βΆ s) :=
{ hom := Ξ» h s,
{ default := h.desc_cocone_morphism s,
uniq := Ξ» _, h.uniq_cocone_morphism },
inv := Ξ» h,
{ desc := Ξ» s, (h s).default.hom,
uniq' := Ξ» s f w, congr_arg cocone_morphism.hom ((h s).uniq β¨f, wβ©) } }
/--
Given two functors which have equivalent categories of cocones, we can transport a limiting cocone
across the equivalence.
-/
def of_cocone_equiv {D : Type u'} [category.{v} D] {G : K β₯€ D}
(h : cocone G β₯€ cocone F) [is_left_adjoint h] {c : cocone G} (t : is_colimit c) :
is_colimit (h.obj c) :=
mk_cocone_morphism
(Ξ» s, ((adjunction.of_left_adjoint h).hom_equiv c s).symm (t.desc_cocone_morphism _))
(Ξ» s m, (adjunction.hom_equiv_apply_eq _ _ _).1 t.uniq_cocone_morphism)
namespace of_nat_iso
variables {X : C} (h : coyoneda.obj (op X) β
F.cocones)
/-- If `F.cocones` is corepresented by `X`, each morphism `f : X βΆ Y` gives a cocone with cone point `Y`. -/
def cocone_of_hom {Y : C} (f : X βΆ Y) : cocone F :=
{ X := Y, ΞΉ := h.hom.app Y f }
/-- If `F.cocones` is corepresented by `X`, each cocone `s` gives a morphism `X βΆ s.X`. -/
def hom_of_cocone (s : cocone F) : X βΆ s.X := h.inv.app s.X s.ΞΉ
@[simp] lemma cocone_of_hom_of_cocone (s : cocone F) : cocone_of_hom h (hom_of_cocone h s) = s :=
begin
dsimp [cocone_of_hom, hom_of_cocone], cases s, congr, dsimp,
exact congr_fun (congr_fun (congr_arg nat_trans.app h.inv_hom_id) s_X) s_ΞΉ,
end
@[simp] lemma hom_of_cocone_of_hom {Y : C} (f : X βΆ Y) : hom_of_cocone h (cocone_of_hom h f) = f :=
congr_fun (congr_fun (congr_arg nat_trans.app h.hom_inv_id) Y) f
/-- If `F.cocones` is corepresented by `X`, the cocone corresponding to the identity morphism on `X`
will be a colimit cocone. -/
def colimit_cocone : cocone F :=
cocone_of_hom h (π X)
/-- If `F.cocones` is corepresented by `X`, the cocone corresponding to a morphism `f : Y βΆ X` is
the colimit cocone extended by `f`. -/
lemma cocone_of_hom_fac {Y : C} (f : X βΆ Y) :
cocone_of_hom h f = (colimit_cocone h).extend f :=
begin
dsimp [cocone_of_hom, colimit_cocone, cocone.extend],
congr,
ext j,
have t := congr_fun (h.hom.naturality f) (π X),
dsimp at t,
simp only [id_comp] at t,
rw congr_fun (congr_arg nat_trans.app t) j,
refl,
end
/-- If `F.cocones` is corepresented by `X`, any cocone is the extension of the colimit cocone by the
corresponding morphism. -/
lemma cocone_fac (s : cocone F) : (colimit_cocone h).extend (hom_of_cocone h s) = s :=
begin
rw βcocone_of_hom_of_cocone h s,
conv_lhs { simp only [hom_of_cocone_of_hom] },
apply (cocone_of_hom_fac _ _).symm,
end
end of_nat_iso
section
open of_nat_iso
/--
If `F.cocones` is corepresentable, then the cocone corresponding to the identity morphism on
the representing object is a colimit cocone.
-/
def of_nat_iso {X : C} (h : coyoneda.obj (op X) β
F.cocones) :
is_colimit (colimit_cocone h) :=
{ desc := Ξ» s, hom_of_cocone h s,
fac' := Ξ» s j,
begin
have h := cocone_fac h s,
cases s,
injection h with hβ hβ,
simp only [heq_iff_eq] at hβ,
conv_rhs { rw β hβ }, refl,
end,
uniq' := Ξ» s m w,
begin
rw βhom_of_cocone_of_hom h m,
congr,
rw cocone_of_hom_fac,
dsimp, cases s, congr,
ext j, exact w j,
end }
end
end is_colimit
section limit
/-- `has_limit F` represents a particular chosen limit of the diagram `F`. -/
class has_limit (F : J β₯€ C) :=
(cone : cone F)
(is_limit : is_limit cone)
variables (J C)
/-- `C` has limits of shape `J` if we have chosen a particular limit of
every functor `F : J β₯€ C`. -/
class has_limits_of_shape :=
(has_limit : Ξ F : J β₯€ C, has_limit F)
/-- `C` has all (small) limits if it has limits of every shape. -/
class has_limits :=
(has_limits_of_shape : Ξ (J : Type v) [π₯ : small_category J], has_limits_of_shape J C)
variables {J C}
@[priority 100] -- see Note [lower instance priority]
instance has_limit_of_has_limits_of_shape
{J : Type v} [small_category J] [H : has_limits_of_shape J C] (F : J β₯€ C) : has_limit F :=
has_limits_of_shape.has_limit F
@[priority 100] -- see Note [lower instance priority]
instance has_limits_of_shape_of_has_limits
{J : Type v} [small_category J] [H : has_limits.{v} C] : has_limits_of_shape J C :=
has_limits.has_limits_of_shape J
/- Interface to the `has_limit` class. -/
/-- The chosen limit cone of a functor. -/
def limit.cone (F : J β₯€ C) [has_limit F] : cone F := has_limit.cone
/-- The chosen limit object of a functor. -/
def limit (F : J β₯€ C) [has_limit F] := (limit.cone F).X
/-- The projection from the chosen limit object to a value of the functor. -/
def limit.Ο (F : J β₯€ C) [has_limit F] (j : J) : limit F βΆ F.obj j :=
(limit.cone F).Ο.app j
@[simp] lemma limit.cone_Ο {F : J β₯€ C} [has_limit F] (j : J) :
(limit.cone F).Ο.app j = limit.Ο _ j := rfl
@[simp] lemma limit.w (F : J β₯€ C) [has_limit F] {j j' : J} (f : j βΆ j') :
limit.Ο F j β« F.map f = limit.Ο F j' := (limit.cone F).w f
/-- Evidence that the chosen cone is a limit cone. -/
def limit.is_limit (F : J β₯€ C) [has_limit F] : is_limit (limit.cone F) :=
has_limit.is_limit.{v}
/-- The morphism from the cone point of any other cone to the chosen limit object. -/
def limit.lift (F : J β₯€ C) [has_limit F] (c : cone F) : c.X βΆ limit F :=
(limit.is_limit F).lift c
@[simp] lemma limit.is_limit_lift {F : J β₯€ C} [has_limit F] (c : cone F) :
(limit.is_limit F).lift c = limit.lift F c := rfl
@[simp, reassoc] lemma limit.lift_Ο {F : J β₯€ C} [has_limit F] (c : cone F) (j : J) :
limit.lift F c β« limit.Ο F j = c.Ο.app j :=
is_limit.fac _ c j
/-- The cone morphism from any cone to the chosen limit cone. -/
def limit.cone_morphism {F : J β₯€ C} [has_limit F] (c : cone F) :
c βΆ (limit.cone F) :=
(limit.is_limit F).lift_cone_morphism c
@[simp] lemma limit.cone_morphism_hom {F : J β₯€ C} [has_limit F] (c : cone F) :
(limit.cone_morphism c).hom = limit.lift F c := rfl
lemma limit.cone_morphism_Ο {F : J β₯€ C} [has_limit F] (c : cone F) (j : J) :
(limit.cone_morphism c).hom β« limit.Ο F j = c.Ο.app j :=
by simp
@[ext] lemma limit.hom_ext {F : J β₯€ C} [has_limit F] {X : C} {f f' : X βΆ limit F}
(w : β j, f β« limit.Ο F j = f' β« limit.Ο F j) : f = f' :=
(limit.is_limit F).hom_ext w
/--
The isomorphism (in `Type`) between
morphisms from a specified object `W` to the limit object,
and cones with cone point `W`.
-/
def limit.hom_iso (F : J β₯€ C) [has_limit F] (W : C) : (W βΆ limit F) β
(F.cones.obj (op W)) :=
(limit.is_limit F).hom_iso W
@[simp] lemma limit.hom_iso_hom (F : J β₯€ C) [has_limit F] {W : C} (f : W βΆ limit F) :
(limit.hom_iso F W).hom f = (const J).map f β« (limit.cone F).Ο :=
(limit.is_limit F).hom_iso_hom f
/--
The isomorphism (in `Type`) between
morphisms from a specified object `W` to the limit object,
and an explicit componentwise description of cones with cone point `W`.
-/
def limit.hom_iso' (F : J β₯€ C) [has_limit F] (W : C) :
((W βΆ limit F) : Type v) β
{ p : Ξ j, W βΆ F.obj j // β {j j' : J} (f : j βΆ j'), p j β« F.map f = p j' } :=
(limit.is_limit F).hom_iso' W
lemma limit.lift_extend {F : J β₯€ C} [has_limit F] (c : cone F) {X : C} (f : X βΆ c.X) :
limit.lift F (c.extend f) = f β« limit.lift F c :=
by obviously
/--
If we've chosen a limit for a functor `F`,
we can transport that choice across a natural isomorphism.
-/
def has_limit_of_iso {F G : J β₯€ C} [has_limit F] (Ξ± : F β
G) : has_limit G :=
{ cone := (cones.postcompose Ξ±.hom).obj (limit.cone F),
is_limit :=
{ lift := Ξ» s, limit.lift F ((cones.postcompose Ξ±.inv).obj s),
fac' := Ξ» s j,
begin
rw [cones.postcompose_obj_Ο, nat_trans.comp_app, limit.cone_Ο, βcategory.assoc, limit.lift_Ο],
simp
end,
uniq' := Ξ» s m w,
begin
apply limit.hom_ext, intro j,
rw [limit.lift_Ο, cones.postcompose_obj_Ο, nat_trans.comp_app, βnat_iso.app_inv, iso.eq_comp_inv],
simpa using w j
end } }
/-- If a functor `G` has the same collection of cones as a functor `F`
which has a limit, then `G` also has a limit. -/
-- See the construction of limits from products and equalizers
-- for an example usage.
def has_limit.of_cones_iso {J K : Type v} [small_category J] [small_category K] (F : J β₯€ C) (G : K β₯€ C)
(h : F.cones β
G.cones) [has_limit F] : has_limit G :=
β¨_, is_limit.of_nat_iso ((is_limit.nat_iso (limit.is_limit F)) βͺβ« h)β©
section pre
variables (F) [has_limit F] (E : K β₯€ J) [has_limit (E β F)]
/--
The canonical morphism
from the chosen limit of `F`
to the chosen limit of `E β F`.
-/
def limit.pre : limit F βΆ limit (E β F) :=
limit.lift (E β F)
{ X := limit F,
Ο := { app := Ξ» k, limit.Ο F (E.obj k) } }
@[simp] lemma limit.pre_Ο (k : K) : limit.pre F E β« limit.Ο (E β F) k = limit.Ο F (E.obj k) :=
by erw is_limit.fac
@[simp] lemma limit.lift_pre (c : cone F) :
limit.lift F c β« limit.pre F E = limit.lift (E β F) (c.whisker E) :=
by ext; simp
variables {L : Type v} [small_category L]
variables (D : L β₯€ K) [has_limit (D β E β F)]
@[simp] lemma limit.pre_pre : limit.pre F E β« limit.pre (E β F) D = limit.pre F (D β E) :=
by ext j; erw [assoc, limit.pre_Ο, limit.pre_Ο, limit.pre_Ο]; refl
end pre
section post
variables {D : Type u'} [category.{v} D]
variables (F) [has_limit F] (G : C β₯€ D) [has_limit (F β G)]
/--
The canonical morphism
from `G` applied to the chosen limit of `F`
to the chosen limit of `F β G`.
-/
def limit.post : G.obj (limit F) βΆ limit (F β G) :=
limit.lift (F β G)
{ X := G.obj (limit F),
Ο :=
{ app := Ξ» j, G.map (limit.Ο F j),
naturality' :=
by intros j j' f; erw [βG.map_comp, limits.cone.w, id_comp]; refl } }
@[simp] lemma limit.post_Ο (j : J) : limit.post F G β« limit.Ο (F β G) j = G.map (limit.Ο F j) :=
by erw is_limit.fac
@[simp] lemma limit.lift_post (c : cone F) :
G.map (limit.lift F c) β« limit.post F G = limit.lift (F β G) (G.map_cone c) :=
by ext; rw [assoc, limit.post_Ο, βG.map_comp, limit.lift_Ο, limit.lift_Ο]; refl
@[simp] lemma limit.post_post
{E : Type u''} [category.{v} E] (H : D β₯€ E) [has_limit ((F β G) β H)] :
/- H G (limit F) βΆ H (limit (F β G)) βΆ limit ((F β G) β H) equals -/
/- H G (limit F) βΆ limit (F β (G β H)) -/
H.map (limit.post F G) β« limit.post (F β G) H = limit.post F (G β H) :=
by ext; erw [assoc, limit.post_Ο, βH.map_comp, limit.post_Ο, limit.post_Ο]; refl
end post
lemma limit.pre_post {D : Type u'} [category.{v} D]
(E : K β₯€ J) (F : J β₯€ C) (G : C β₯€ D)
[has_limit F] [has_limit (E β F)] [has_limit (F β G)] [has_limit ((E β F) β G)] :
/- G (limit F) βΆ G (limit (E β F)) βΆ limit ((E β F) β G) vs -/
/- G (limit F) βΆ limit F β G βΆ limit (E β (F β G)) or -/
G.map (limit.pre F E) β« limit.post (E β F) G = limit.post F G β« limit.pre (F β G) E :=
by ext; erw [assoc, limit.post_Ο, βG.map_comp, limit.pre_Ο, assoc, limit.pre_Ο, limit.post_Ο]; refl
open category_theory.equivalence
instance has_limit_equivalence_comp (e : K β J) [has_limit F] : has_limit (e.functor β F) :=
{ cone := cone.whisker e.functor (limit.cone F),
is_limit :=
let e' := cones.postcompose (e.inv_fun_id_assoc F).hom in
{ lift := Ξ» s, limit.lift F (e'.obj (cone.whisker e.inverse s)),
fac' := Ξ» s j,
begin
dsimp, rw [limit.lift_Ο], dsimp [e'],
erw [inv_fun_id_assoc_hom_app, counit_functor, βs.Ο.naturality, id_comp]
end,
uniq' := Ξ» s m w,
begin
apply limit.hom_ext, intro j,
erw [limit.lift_Ο, βlimit.w F (e.counit_iso.hom.app j)],
slice_lhs 1 2 { erw [w (e.inverse.obj j)] }, simp
end } }
local attribute [elab_simple] inv_fun_id_assoc -- not entirely sure why this is needed
/--
If a `E β F` has a chosen limit, and `E` is an equivalence, we can construct a chosen limit of `F`.
-/
def has_limit_of_equivalence_comp (e : K β J) [has_limit (e.functor β F)] : has_limit F :=
begin
haveI : has_limit (e.inverse β e.functor β F) := limits.has_limit_equivalence_comp e.symm,
apply has_limit_of_iso (e.inv_fun_id_assoc F),
end
-- `has_limit_comp_equivalence` and `has_limit_of_comp_equivalence`
-- are proved in `category_theory/adjunction/limits.lean`.
section lim_functor
variables [has_limits_of_shape J C]
/-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/
def lim : (J β₯€ C) β₯€ C :=
{ obj := Ξ» F, limit F,
map := Ξ» F G Ξ±, limit.lift G
{ X := limit F,
Ο :=
{ app := Ξ» j, limit.Ο F j β« Ξ±.app j,
naturality' := Ξ» j j' f,
by erw [id_comp, assoc, βΞ±.naturality, βassoc, limit.w] } },
map_comp' := Ξ» F G H Ξ± Ξ²,
by ext; erw [assoc, is_limit.fac, is_limit.fac, βassoc, is_limit.fac, assoc]; refl }
variables {F} {G : J β₯€ C} (Ξ± : F βΆ G)
@[simp, reassoc] lemma limit.map_Ο (j : J) : lim.map Ξ± β« limit.Ο G j = limit.Ο F j β« Ξ±.app j :=
by apply is_limit.fac
@[simp] lemma limit.lift_map (c : cone F) :
limit.lift F c β« lim.map Ξ± = limit.lift G ((cones.postcompose Ξ±).obj c) :=
by ext; rw [assoc, limit.map_Ο, βassoc, limit.lift_Ο, limit.lift_Ο]; refl
lemma limit.map_pre [has_limits_of_shape K C] (E : K β₯€ J) :
lim.map Ξ± β« limit.pre G E = limit.pre F E β« lim.map (whisker_left E Ξ±) :=
by ext; rw [assoc, limit.pre_Ο, limit.map_Ο, assoc, limit.map_Ο, βassoc, limit.pre_Ο]; refl
lemma limit.map_pre' [has_limits_of_shape.{v} K C]
(F : J β₯€ C) {Eβ Eβ : K β₯€ J} (Ξ± : Eβ βΆ Eβ) :
limit.pre F Eβ = limit.pre F Eβ β« lim.map (whisker_right Ξ± F) :=
by ext1; simp [β category.assoc]
lemma limit.id_pre (F : J β₯€ C) :
limit.pre F (π _) = lim.map (functor.left_unitor F).inv := by tidy
lemma limit.map_post {D : Type u'} [category.{v} D] [has_limits_of_shape J D] (H : C β₯€ D) :
/- H (limit F) βΆ H (limit G) βΆ limit (G β H) vs
H (limit F) βΆ limit (F β H) βΆ limit (G β H) -/
H.map (lim.map Ξ±) β« limit.post G H = limit.post F H β« lim.map (whisker_right Ξ± H) :=
begin
ext,
rw [assoc, limit.post_Ο, βH.map_comp, limit.map_Ο, H.map_comp],
rw [assoc, limit.map_Ο, βassoc, limit.post_Ο],
refl
end
/--
The isomorphism between
morphisms from `W` to the cone point of the limit cone for `F`
and cones over `F` with cone point `W`
is natural in `F`.
-/
def lim_yoneda : lim β yoneda β
category_theory.cones J C :=
nat_iso.of_components (Ξ» F, nat_iso.of_components (Ξ» W, limit.hom_iso F (unop W)) (by tidy))
(by tidy)
end lim_functor
/--
We can transport chosen limits of shape `J` along an equivalence `J β J'`.
-/
def has_limits_of_shape_of_equivalence {J' : Type v} [small_category J']
(e : J β J') [has_limits_of_shape J C] : has_limits_of_shape J' C :=
by { constructor, intro F, apply has_limit_of_equivalence_comp e, apply_instance }
end limit
section colimit
/-- `has_colimit F` represents a particular chosen colimit of the diagram `F`. -/
class has_colimit (F : J β₯€ C) :=
(cocone : cocone F)
(is_colimit : is_colimit cocone)
variables (J C)
/-- `C` has colimits of shape `J` if we have chosen a particular colimit of
every functor `F : J β₯€ C`. -/
class has_colimits_of_shape :=
(has_colimit : Ξ F : J β₯€ C, has_colimit F)
/-- `C` has all (small) colimits if it has colimits of every shape. -/
class has_colimits :=
(has_colimits_of_shape : Ξ (J : Type v) [π₯ : small_category J], has_colimits_of_shape J C)
variables {J C}
@[priority 100] -- see Note [lower instance priority]
instance has_colimit_of_has_colimits_of_shape
{J : Type v} [small_category J] [H : has_colimits_of_shape J C] (F : J β₯€ C) : has_colimit F :=
has_colimits_of_shape.has_colimit F
@[priority 100] -- see Note [lower instance priority]
instance has_colimits_of_shape_of_has_colimits
{J : Type v} [small_category J] [H : has_colimits.{v} C] : has_colimits_of_shape J C :=
has_colimits.has_colimits_of_shape J
/- Interface to the `has_colimit` class. -/
/-- The chosen colimit cocone of a functor. -/
def colimit.cocone (F : J β₯€ C) [has_colimit F] : cocone F := has_colimit.cocone
/-- The chosen colimit object of a functor. -/
def colimit (F : J β₯€ C) [has_colimit F] := (colimit.cocone F).X
/-- The coprojection from a value of the functor to the chosen colimit object. -/
def colimit.ΞΉ (F : J β₯€ C) [has_colimit F] (j : J) : F.obj j βΆ colimit F :=
(colimit.cocone F).ΞΉ.app j
@[simp] lemma colimit.cocone_ΞΉ {F : J β₯€ C} [has_colimit F] (j : J) :
(colimit.cocone F).ΞΉ.app j = colimit.ΞΉ _ j := rfl
@[simp] lemma colimit.w (F : J β₯€ C) [has_colimit F] {j j' : J} (f : j βΆ j') :
F.map f β« colimit.ΞΉ F j' = colimit.ΞΉ F j := (colimit.cocone F).w f
/-- Evidence that the chosen cocone is a colimit cocone. -/
def colimit.is_colimit (F : J β₯€ C) [has_colimit F] : is_colimit (colimit.cocone F) :=
has_colimit.is_colimit.{v}
/-- The morphism from the chosen colimit object to the cone point of any other cocone. -/
def colimit.desc (F : J β₯€ C) [has_colimit F] (c : cocone F) : colimit F βΆ c.X :=
(colimit.is_colimit F).desc c
@[simp] lemma colimit.is_colimit_desc {F : J β₯€ C} [has_colimit F] (c : cocone F) :
(colimit.is_colimit F).desc c = colimit.desc F c := rfl
/--
We have lots of lemmas describing how to simplify `colimit.ΞΉ F j β« _`,
and combined with `colimit.ext` we rely on these lemmas for many calculations.
However, since `category.assoc` is a `@[simp]` lemma, often expressions are
right associated, and it's hard to apply these lemmas about `colimit.ΞΉ`.
We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism.
(see `tactic/reassoc_axiom.lean`)
-/
@[simp, reassoc] lemma colimit.ΞΉ_desc {F : J β₯€ C} [has_colimit F] (c : cocone F) (j : J) :
colimit.ΞΉ F j β« colimit.desc F c = c.ΞΉ.app j :=
is_colimit.fac _ c j
/-- The cocone morphism from the chosen colimit cocone to any cocone. -/
def colimit.cocone_morphism {F : J β₯€ C} [has_colimit F] (c : cocone F) :
(colimit.cocone F) βΆ c :=
(colimit.is_colimit F).desc_cocone_morphism c
@[simp] lemma colimit.cocone_morphism_hom {F : J β₯€ C} [has_colimit F] (c : cocone F) :
(colimit.cocone_morphism c).hom = colimit.desc F c := rfl
lemma colimit.ΞΉ_cocone_morphism {F : J β₯€ C} [has_colimit F] (c : cocone F) (j : J) :
colimit.ΞΉ F j β« (colimit.cocone_morphism c).hom = c.ΞΉ.app j :=
by simp
@[ext] lemma colimit.hom_ext {F : J β₯€ C} [has_colimit F] {X : C} {f f' : colimit F βΆ X}
(w : β j, colimit.ΞΉ F j β« f = colimit.ΞΉ F j β« f') : f = f' :=
(colimit.is_colimit F).hom_ext w
/--
The isomorphism (in `Type`) between
morphisms from the colimit object to a specified object `W`,
and cocones with cone point `W`.
-/
def colimit.hom_iso (F : J β₯€ C) [has_colimit F] (W : C) : (colimit F βΆ W) β
(F.cocones.obj W) :=
(colimit.is_colimit F).hom_iso W
@[simp] lemma colimit.hom_iso_hom (F : J β₯€ C) [has_colimit F] {W : C} (f : colimit F βΆ W) :
(colimit.hom_iso F W).hom f = (colimit.cocone F).ΞΉ β« (const J).map f :=
(colimit.is_colimit F).hom_iso_hom f
/--
The isomorphism (in `Type`) between
morphisms from the colimit object to a specified object `W`,
and an explicit componentwise description of cocones with cone point `W`.
-/
def colimit.hom_iso' (F : J β₯€ C) [has_colimit F] (W : C) :
((colimit F βΆ W) : Type v) β
{ p : Ξ j, F.obj j βΆ W // β {j j'} (f : j βΆ j'), F.map f β« p j' = p j } :=
(colimit.is_colimit F).hom_iso' W
lemma colimit.desc_extend (F : J β₯€ C) [has_colimit F] (c : cocone F) {X : C} (f : c.X βΆ X) :
colimit.desc F (c.extend f) = colimit.desc F c β« f :=
begin
ext1, rw [βcategory.assoc], simp
end
/--
If we've chosen a colimit for a functor `F`,
we can transport that choice across a natural isomorphism.
-/
-- This has the isomorphism pointing in the opposite direction than in `has_limit_of_iso`.
-- This is intentional; it seems to help with elaboration.
def has_colimit_of_iso {F G : J β₯€ C} [has_colimit F] (Ξ± : G β
F) : has_colimit G :=
{ cocone := (cocones.precompose Ξ±.hom).obj (colimit.cocone F),
is_colimit :=
{ desc := Ξ» s, colimit.desc F ((cocones.precompose Ξ±.inv).obj s),
fac' := Ξ» s j,
begin
rw [cocones.precompose_obj_ΞΉ, nat_trans.comp_app, colimit.cocone_ΞΉ],
rw [category.assoc, colimit.ΞΉ_desc, βnat_iso.app_hom, βiso.eq_inv_comp], refl
end,
uniq' := Ξ» s m w,
begin
apply colimit.hom_ext, intro j,
rw [colimit.ΞΉ_desc, cocones.precompose_obj_ΞΉ, nat_trans.comp_app, βnat_iso.app_inv,
iso.eq_inv_comp],
simpa using w j
end } }
/-- If a functor `G` has the same collection of cocones as a functor `F`
which has a colimit, then `G` also has a colimit. -/
def has_colimit.of_cocones_iso {J K : Type v} [small_category J] [small_category K] (F : J β₯€ C) (G : K β₯€ C)
(h : F.cocones β
G.cocones) [has_colimit F] : has_colimit G :=
β¨_, is_colimit.of_nat_iso ((is_colimit.nat_iso (colimit.is_colimit F)) βͺβ« h)β©
section pre
variables (F) [has_colimit F] (E : K β₯€ J) [has_colimit (E β F)]
/--
The canonical morphism
from the chosen colimit of `E β F`
to the chosen colimit of `F`.
-/
def colimit.pre : colimit (E β F) βΆ colimit F :=
colimit.desc (E β F)
{ X := colimit F,
ΞΉ := { app := Ξ» k, colimit.ΞΉ F (E.obj k) } }
@[simp, reassoc] lemma colimit.ΞΉ_pre (k : K) : colimit.ΞΉ (E β F) k β« colimit.pre F E = colimit.ΞΉ F (E.obj k) :=
by erw is_colimit.fac
@[simp] lemma colimit.pre_desc (c : cocone F) :
colimit.pre F E β« colimit.desc F c = colimit.desc (E β F) (c.whisker E) :=
by ext; rw [βassoc, colimit.ΞΉ_pre]; simp
variables {L : Type v} [small_category L]
variables (D : L β₯€ K) [has_colimit (D β E β F)]
@[simp] lemma colimit.pre_pre : colimit.pre (E β F) D β« colimit.pre F E = colimit.pre F (D β E) :=
begin
ext j,
rw [βassoc, colimit.ΞΉ_pre, colimit.ΞΉ_pre],
letI : has_colimit ((D β E) β F) := show has_colimit (D β E β F), by apply_instance,
exact (colimit.ΞΉ_pre F (D β E) j).symm
end
end pre
section post
variables {D : Type u'} [category.{v} D]
variables (F) [has_colimit F] (G : C β₯€ D) [has_colimit (F β G)]
/--
The canonical morphism
from `G` applied to the chosen colimit of `F β G`
to `G` applied to the chosen colimit of `F`.
-/
def colimit.post : colimit (F β G) βΆ G.obj (colimit F) :=
colimit.desc (F β G)
{ X := G.obj (colimit F),
ΞΉ :=
{ app := Ξ» j, G.map (colimit.ΞΉ F j),
naturality' :=
by intros j j' f; erw [βG.map_comp, limits.cocone.w, comp_id]; refl } }
@[simp, reassoc] lemma colimit.ΞΉ_post (j : J) : colimit.ΞΉ (F β G) j β« colimit.post F G = G.map (colimit.ΞΉ F j) :=
by erw is_colimit.fac
@[simp] lemma colimit.post_desc (c : cocone F) :
colimit.post F G β« G.map (colimit.desc F c) = colimit.desc (F β G) (G.map_cocone c) :=
by ext; rw [βassoc, colimit.ΞΉ_post, βG.map_comp, colimit.ΞΉ_desc, colimit.ΞΉ_desc]; refl
@[simp] lemma colimit.post_post
{E : Type u''} [category.{v} E] (H : D β₯€ E) [has_colimit ((F β G) β H)] :
/- H G (colimit F) βΆ H (colimit (F β G)) βΆ colimit ((F β G) β H) equals -/
/- H G (colimit F) βΆ colimit (F β (G β H)) -/
colimit.post (F β G) H β« H.map (colimit.post F G) = colimit.post F (G β H) :=
begin
ext,
rw [βassoc, colimit.ΞΉ_post, βH.map_comp, colimit.ΞΉ_post],
exact (colimit.ΞΉ_post F (G β H) j).symm
end
end post
lemma colimit.pre_post {D : Type u'} [category.{v} D]
(E : K β₯€ J) (F : J β₯€ C) (G : C β₯€ D)
[has_colimit F] [has_colimit (E β F)] [has_colimit (F β G)] [has_colimit ((E β F) β G)] :
/- G (colimit F) βΆ G (colimit (E β F)) βΆ colimit ((E β F) β G) vs -/
/- G (colimit F) βΆ colimit F β G βΆ colimit (E β (F β G)) or -/
colimit.post (E β F) G β« G.map (colimit.pre F E) = colimit.pre (F β G) E β« colimit.post F G :=
begin
ext,
rw [βassoc, colimit.ΞΉ_post, βG.map_comp, colimit.ΞΉ_pre, βassoc],
letI : has_colimit (E β F β G) := show has_colimit ((E β F) β G), by apply_instance,
erw [colimit.ΞΉ_pre (F β G) E j, colimit.ΞΉ_post]
end
open category_theory.equivalence
instance has_colimit_equivalence_comp (e : K β J) [has_colimit F] : has_colimit (e.functor β F) :=
{ cocone := cocone.whisker e.functor (colimit.cocone F),
is_colimit := let e' := cocones.precompose (e.inv_fun_id_assoc F).inv in
{ desc := Ξ» s, colimit.desc F (e'.obj (cocone.whisker e.inverse s)),
fac' := Ξ» s j,
begin
dsimp, rw [colimit.ΞΉ_desc], dsimp [e'],
erw [inv_fun_id_assoc_inv_app, βfunctor_unit, s.ΞΉ.naturality, comp_id], refl
end,
uniq' := Ξ» s m w,
begin
apply colimit.hom_ext, intro j,
erw [colimit.ΞΉ_desc],
have := w (e.inverse.obj j), simp at this, erw [βcolimit.w F (e.counit_iso.hom.app j)] at this,
erw [assoc, βiso.eq_inv_comp (F.map_iso $ e.counit_iso.app j)] at this, erw [this], simp
end } }
/--
If a `E β F` has a chosen colimit, and `E` is an equivalence, we can construct a chosen colimit of `F`.
-/
def has_colimit_of_equivalence_comp (e : K β J) [has_colimit (e.functor β F)] : has_colimit F :=
begin
haveI : has_colimit (e.inverse β e.functor β F) := limits.has_colimit_equivalence_comp e.symm,
apply has_colimit_of_iso (e.inv_fun_id_assoc F).symm,
end
section colim_functor
variables [has_colimits_of_shape J C]
/-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/
def colim : (J β₯€ C) β₯€ C :=
{ obj := Ξ» F, colimit F,
map := Ξ» F G Ξ±, colimit.desc F
{ X := colimit G,
ΞΉ :=
{ app := Ξ» j, Ξ±.app j β« colimit.ΞΉ G j,
naturality' := Ξ» j j' f,
by erw [comp_id, βassoc, Ξ±.naturality, assoc, colimit.w] } },
map_comp' := Ξ» F G H Ξ± Ξ²,
by ext; erw [βassoc, is_colimit.fac, is_colimit.fac, assoc, is_colimit.fac, βassoc]; refl }
variables {F} {G : J β₯€ C} (Ξ± : F βΆ G)
@[simp, reassoc] lemma colimit.ΞΉ_map (j : J) : colimit.ΞΉ F j β« colim.map Ξ± = Ξ±.app j β« colimit.ΞΉ G j :=
by apply is_colimit.fac
@[simp] lemma colimit.map_desc (c : cocone G) :
colim.map Ξ± β« colimit.desc G c = colimit.desc F ((cocones.precompose Ξ±).obj c) :=
by ext; rw [βassoc, colimit.ΞΉ_map, assoc, colimit.ΞΉ_desc, colimit.ΞΉ_desc]; refl
lemma colimit.pre_map [has_colimits_of_shape K C] (E : K β₯€ J) :
colimit.pre F E β« colim.map Ξ± = colim.map (whisker_left E Ξ±) β« colimit.pre G E :=
by ext; rw [βassoc, colimit.ΞΉ_pre, colimit.ΞΉ_map, βassoc, colimit.ΞΉ_map, assoc, colimit.ΞΉ_pre]; refl
lemma colimit.pre_map' [has_colimits_of_shape.{v} K C]
(F : J β₯€ C) {Eβ Eβ : K β₯€ J} (Ξ± : Eβ βΆ Eβ) :
colimit.pre F Eβ = colim.map (whisker_right Ξ± F) β« colimit.pre F Eβ :=
by ext1; simp [β category.assoc]
lemma colimit.pre_id (F : J β₯€ C) :
colimit.pre F (π _) = colim.map (functor.left_unitor F).hom := by tidy
lemma colimit.map_post {D : Type u'} [category.{v} D] [has_colimits_of_shape J D] (H : C β₯€ D) :
/- H (colimit F) βΆ H (colimit G) βΆ colimit (G β H) vs
H (colimit F) βΆ colimit (F β H) βΆ colimit (G β H) -/
colimit.post F H β« H.map (colim.map Ξ±) = colim.map (whisker_right Ξ± H) β« colimit.post G H:=
begin
ext,
rw [βassoc, colimit.ΞΉ_post, βH.map_comp, colimit.ΞΉ_map, H.map_comp],
rw [βassoc, colimit.ΞΉ_map, assoc, colimit.ΞΉ_post],
refl
end
/--
The isomorphism between
morphisms from the cone point of the chosen colimit cocone for `F` to `W`
and cocones over `F` with cone point `W`
is natural in `F`.
-/
def colim_coyoneda : colim.op β coyoneda β
category_theory.cocones J C :=
nat_iso.of_components (Ξ» F, nat_iso.of_components (colimit.hom_iso (unop F)) (by tidy))
(by tidy)
end colim_functor
/--
We can transport chosen colimits of shape `J` along an equivalence `J β J'`.
-/
def has_colimits_of_shape_of_equivalence {J' : Type v} [small_category J']
(e : J β J') [has_colimits_of_shape J C] : has_colimits_of_shape J' C :=
by { constructor, intro F, apply has_colimit_of_equivalence_comp e, apply_instance }
end colimit
end category_theory.limits
|
522e5559039a71269677fee2dda89df4322a8bbd
|
556aeb81a103e9e0ac4e1fe0ce1bc6e6161c3c5e
|
/src/starkware/cairo/lean/semantics/soundness/hoare.lean
|
86e8502f7f9851b32720ad018e0454c0521ef5e2
|
[
"Apache-2.0"
] |
permissive
|
starkware-libs/formal-proofs
|
d6b731604461bf99e6ba820e68acca62a21709e8
|
f5fa4ba6a471357fd171175183203d0b437f6527
|
refs/heads/master
| 1,691,085,444,753
| 1,690,507,386,000
| 1,690,507,386,000
| 410,476,629
| 32
| 9
|
Apache-2.0
| 1,690,506,773,000
| 1,632,639,790,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 31,969
|
lean
|
/-
Definitions and tactics for reasoning about the one-step effects of each assembly instruction.
-/
import starkware.cairo.lean.semantics.util
import starkware.cairo.lean.semantics.soundness.assembly
import starkware.cairo.lean.semantics.air_encoding.instruction
section main
@[class] def char_ge_2_63 (F : Type*) [field F] : Prop := ring_char F β₯ 2^63
variables {F : Type*} [field F]
/-
Reasoning about contents of memory.
-/
def mem_at (mem : F β F) : list F β F β Prop
| [] _ := true
| (v :: l) pc := mem pc = v β§ mem_at l (pc + 1)
/-
The halting instruction is a relative jump to the same spot. In general, we don't prove that a
program will halt, but, rather, that *if* it halts it has the desired behavior. This is o.k.
because the STARK can certify that the computation has, in fact, halted.
To take a step forward, however, we need to verify that the current instruction is not a halting
instruction. The following lemmas help with do that efficiently.
-/
def jmp_rel_instr : instr := 'jmp_rel[ 'op1[imm] ]
section instr
variables (op0 : op0_spec) (op1 : op1_spec) (res : res_spec) (dst : dst_spec) (ap_update : bool)
lemma assert_eq_ne_jmp_rel :
(assert_eq_instr op0 res dst ap_update).to_instruction β jmp_rel_instr.to_instruction :=
begin
intro h,
have := congr_arg instruction.opcode_assert_eq h,
contradiction
end
lemma call_ne_jmp_rel (call_abs : bool) :
(call_instr call_abs res).to_instruction β jmp_rel_instr.to_instruction :=
begin
intro h,
have := congr_arg instruction.opcode_call h,
contradiction
end
lemma ret_ne_jmp_rel : ret_instr.to_instruction β jmp_rel_instr.to_instruction :=
begin
intro h,
have := congr_arg instruction.opcode_ret h,
contradiction
end
lemma advance_ap_ne_jmp_rel :
(advance_ap_instr op0 res).to_instruction β jmp_rel_instr.to_instruction :=
begin
intro h,
have := congr_arg instruction.ap_add h,
contradiction
end
lemma jnz_ne_jmp_rel :
(jnz_instr op0 op1 dst ap_update).to_instruction β jmp_rel_instr.to_instruction :=
begin
intro h,
have := congr_arg instruction.pc_jnz h,
contradiction
end
/-- Can be used unless the jump has an immediate argument, in which case instead we have to
check that the immediate argument is not 0. -/
lemma jump_ne_jmp_rel (jump_abs : bool) (h : res.to_op1.op1_imm = ff) :
(jump_instr jump_abs op0 res ap_update).to_instruction β jmp_rel_instr.to_instruction :=
begin
intro h',
have := congr_arg instruction.op1_imm h',
dsimp [jump_instr] at this,
rw h at this,
contradiction
end
end instr
/-
The definition of a halting execution trace and supporting lemmas.
-/
section halting
variable [decidable_eq F]
variable mem : F β F
variables s t : register_state F
def is_halting_state := mem s.pc = jmp_rel_instr.to_nat β§ mem (s.pc + 1) = 0
lemma not_is_halting_state_iff {mem : F β F} {s : register_state F} :
Β¬ is_halting_state mem s β mem s.pc β jmp_rel_instr.to_nat β¨ mem (s.pc + 1) β 0 :=
decidable.not_and_distrib
def is_halting_trace {n : β} (exec : fin (n + 1) β register_state F) : Prop :=
(β i : fin n, next_state mem (exec i.cast_succ) (exec i.succ)) β§
is_halting_state mem (exec (fin.last n))
theorem eq_succ_of_not_halting_state_0 {mem : F β F} {n : β}
{exec : fin (n + 1) β register_state F}
(h : is_halting_trace mem exec)
(h' : Β¬ is_halting_state mem (exec 0)) :
β m : β, n = m.succ :=
begin
apply nat.exists_eq_succ_of_ne_zero,
rintro rfl,
exact h' h.2
end
theorem is_halting_trace_step {mem : F β F} {n : β} {exec : fin (n.succ + 1) β register_state F}
(h : is_halting_trace mem exec)
(h' : Β¬ is_halting_state mem (exec 0)) :
is_halting_trace mem (Ξ» i, exec i.succ) :=
begin
split,
{ intro i, convert h.1 i.succ, rw [fin.cast_succ_fin_succ] },
exact h.2
end
theorem is_halting_trace_remainder {m n : β} {exec : fin (m + n + 1) β register_state F}
(h : is_halting_trace mem exec) :
is_halting_trace mem (Ξ» j : fin (n + 1), exec (fin.cast_offset' m j)) :=
begin
rcases h with β¨h1, h2, h3β©,
rw is_halting_trace,
refine β¨_, h2, h3β©,
intro i,
convert h1 (fin.cast_offset m i),
rw [fin.cast_offset', fin.succ_cast_offset]
end
end halting
/-
The `ensures` predicate, and a bounded version.
-/
section ensures
variable [decidable_eq F]
/--
Given `mem` and start state `s`, any halting trace `exec` with `exec 0 = s` eventually reaches a
state `t` in `i` steps such that for some `k β€ i`, `P k (exec i)`. We use the bound on `k` to
ensure a final claim about the range of values that have been range checked.
-/
def ensures (mem : F β F) (s : register_state F) (P : β β register_state F β Prop) : Prop :=
β n : β, β exec : fin (n+1) β register_state F,
is_halting_trace mem exec β exec 0 = s β β i : fin (n + 1), β k β€ i, P k (exec i)
/-- for use with code blocks that end with a return -/
@[reducible] def ensures_ret (mem : F β F) (s : register_state F)
(P : β β register_state F β Prop) :
Prop :=
ensures mem s (Ξ» k t, t.pc = mem (s.fp - 1) β§ t.fp = mem (s.fp - 2) β§ P k t)
def ensuresb (bound : β) (mem : F β F) (s : register_state F) (P : β β register_state F β Prop) :
Prop :=
β n : β, n < bound β β exec : fin (n+1) β register_state F,
is_halting_trace mem exec β exec 0 = s β β i : fin (n + 1), β k β€ i, P k (exec i)
theorem ensures_of_ensuresb {mem : F β F} {s : register_state F}
{P : β β register_state F β Prop}
(h : β bound, ensuresb bound mem s P) :
ensures mem s P :=
Ξ» n, h (n + 1) _ (nat.lt_succ_self n)
@[reducible] def ensuresb_ret (bound : β) (mem : F β F) (s : register_state F)
(P : β β register_state F β Prop) :
Prop :=
ensuresb bound mem s (Ξ» k t, t.pc = mem (s.fp - 1) β§ t.fp = mem (s.fp - 2) β§ P k t)
theorem ensures_ret_of_ensuresb_ret {mem : F β F} {s : register_state F}
{P : β β register_state F β Prop}
(h : β bound, ensuresb_ret bound mem s P) :
ensures_ret mem s P :=
Ξ» n, h (n + 1) _ (nat.lt_succ_self n)
/-- Takes a step and augments `k` by 1. -/
theorem ensuresb_step {bound : β}
{mem : F β F} {s t : register_state F} {P : β β register_state F β Prop}
{Q : Prop}
(h0 : Β¬ is_halting_state mem s)
(h1 : β t', next_state mem s t' β t' = t β§ Q)
(h : Q β ensuresb bound mem t (Ξ» k t', P (k + 1) t')) :
ensuresb (bound + 1) mem s P :=
begin
rintros nβ nβle exec h2 rfl,
rcases eq_succ_of_not_halting_state_0 h2 h0 with β¨n, rflβ©,
rcases h (h1 _ (h2.1 0)).2 n (nat.le_of_succ_le_succ nβle) (Ξ» i, exec i.succ)
(is_halting_trace_step h2 h0) (h1 _ (h2.1 0)).1 with β¨i, k, hik, h4β©,
use [i.succ, k.succ], split,
{ exact fin.succ_le_succ_iff.mpr hik },
convert h4, simp
end
/- used to add a + 1 if necessary -/
theorem ensuresb_succ {bound : β}
{mem : F β F} {s : register_state F} {P : β β register_state F β Prop}
(h : ensuresb (bound + 1) mem s P) :
ensuresb bound mem s P :=
Ξ» n nlt, h _ (nlt.trans $nat.lt_succ_self _)
theorem ensuresb_test {bound : β}
{mem : F β F} {s : register_state F} {P : β β register_state F β Prop}
(h : ensuresb (bound + 1) mem s P) : ensuresb (bound + 1) mem s P := h
theorem ensuresb_trans {bound : β}
{mem : F β F} {s : register_state F} {P Q : β β register_state F β Prop}
(h0 : ensures mem s P)
(h1 : β k t, P k t β ensuresb bound mem t (Ξ» k', Q (k + k'))) :
ensuresb bound mem s Q :=
begin
rintros n nlt exec h2 h3,
rcases h0 _ _ h2 h3 with β¨i, k, hik1, hik2β©,
rcases fin.exists_eq_add i with β¨m, j, hm, rflβ©,
have : exec (fin.cast_offset' m 0) = exec i,
{ congr, ext, exact hm },
rcases h1 _ _ hik2 _ (lt_of_le_of_lt (nat.le_add_left _ _) nlt) _
(is_halting_trace_remainder mem h2) this with β¨i', k', hi'k', h4β©,
dsimp at h4,
have : βk + j + 1 β€ m + j + 1,
{ apply nat.succ_le_succ, apply nat.add_le_add_right, nth_rewrite_rhs 0 hm, exact hik1 },
use [fin.cast_offset' m i', fin.cast_le this (fin.cast_offset' k k')],
split,
{ rw fin.le_iff_coe_le_coe,
simp [fin.cast_offset', fin.cast_offset],
nth_rewrite_rhs 0 hm,
rw fin.le_iff_coe_le_coe at hik1 hi'k',
apply add_le_add hik1 hi'k' },
exact h4
end
theorem ensuresb_rec_trans {bound : β}
{mem : F β F} {s : register_state F} {P Q : β β register_state F β Prop}
(h0 : ensuresb bound mem s P)
(h1 : β k t, P k t β ensuresb bound mem t (Ξ» k', Q (k + k'))) :
ensuresb bound mem s Q :=
begin
rintros n nlt exec h2 h3,
rcases h0 _ nlt _ h2 h3 with β¨i, k, hik1, hik2β©,
rcases fin.exists_eq_add i with β¨m, j, hm, rflβ©,
have : exec (fin.cast_offset' m 0) = exec i,
{ congr, ext, exact hm },
rcases h1 _ _ hik2 _ (lt_of_le_of_lt (nat.le_add_left _ _) nlt) _
(is_halting_trace_remainder mem h2) this with β¨i', k', hi'k', h4β©,
dsimp at h4,
have : βk + j + 1 β€ m + j + 1,
{ apply nat.succ_le_succ, apply nat.add_le_add_right, nth_rewrite_rhs 0 hm, exact hik1 },
use [fin.cast_offset' m i', fin.cast_le this (fin.cast_offset' k k')],
split,
{ rw fin.le_iff_coe_le_coe,
simp [fin.cast_offset', fin.cast_offset],
nth_rewrite_rhs 0 hm,
rw fin.le_iff_coe_le_coe at hik1 hi'k',
apply add_le_add hik1 hi'k' },
exact h4
end
theorem ensuresb_id {bound : β} {mem : F β F} {s : register_state F}
{P : β β register_state F β Prop} (h : P 0 s) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec hexec hexec0,
use [0, 0, le_refl _],
rwa hexec0
end
theorem ensuresb_rec {mem : F β F}
(P : register_state F β F β β β register_state F β Prop)
(Haux : F β register_state F β Prop)
(s : register_state F) (arg : F) (hHaux : Haux arg s)
(hind : β bound, (β (arg : F) (s: register_state F),
Haux arg s β ensuresb bound mem s (P s arg)) β
(β {arg : F}, β {s: register_state F},
Haux arg s β ensuresb (bound + 1) mem s (P s arg))) :
ensures mem s (P s arg) :=
begin
have : β bound, (β {arg : F}, β {s: register_state F},
Haux arg s β ensuresb bound mem s (P s arg)),
{ intro bound,
induction bound with bound ih,
{ intros _ _ _ n nlt, exact absurd nlt (nat.not_lt_zero _)},
apply hind, exact @ih },
apply ensures_of_ensuresb (Ξ» bound, this bound hHaux)
end
-- for handling blocks
theorem ensuresb_ret_trans {bound : β}
{mem : F β F} {s : register_state F} {P Q : β β register_state F β Prop}
(h0 : ensuresb_ret bound mem s P)
(h1 : β k t, P k t β Q k t) :
ensuresb_ret bound mem s Q :=
begin
rintros n nlt exec h2 h3,
rcases h0 _ nlt _ h2 h3 with β¨i, k, hik1, hik2, hik3, hik4β©,
use [i, k, hik1, hik2, hik3, h1 _ _ hik4]
end
end ensures
/-
Characterize next state transitions.
-/
section next_state
variable [decidable_eq F]
lemma instruction.next_state_iff_of_eq [char_ge : char_ge_2_63 F] {i : instruction}
{mem : F β F} {s t : register_state F} (h : mem s.pc = i.to_nat) :
next_state mem s t β i.next_state mem s t :=
begin
rw [next_state], split,
{ rintros β¨i', i'eq, i'next_stateβ©,
have : i = i' := inst_unique char_ge _ _ (h.symm.trans i'eq),
rwa this },
intro h', use [i, h, h']
end
variable {mem : F β F}
variable {s : register_state F}
variable {P : β β register_state F β Prop}
theorem assert_eq_ensuresb' [char_ge : char_ge_2_63 F] {bound : β}
{op0 : op0_spec} {res : res_spec} {dst : dst_spec} {ap_update : bool}
(h : mem s.pc = (assert_eq_instr op0 res dst ap_update).to_nat)
(h' : compute_dst mem s dst = compute_res mem s op0 res β
ensuresb bound mem β¨bump_pc s res.to_op1.op1_imm, bump_ap s ap_update, s.fpβ©
(Ξ» k t, P (k + 1) t)) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec,
have h1 : Β¬ is_halting_state mem s,
{ rw not_is_halting_state_iff, left, rw h,
intro h0,
exact assert_eq_ne_jmp_rel _ _ _ _ (inst_unique char_ge _ _ h0) },
have h2 : β t, next_state mem s t β
t = β¨bump_pc s res.to_op1.op1_imm, bump_ap s ap_update, s.fpβ© β§
compute_dst mem s dst = compute_res mem s op0 res,
{ intros t ht,
rw [instruction.next_state_iff_of_eq h, βinstr.next_state, next_state_assert_eq] at ht,
simp [ht],
ext; simp [ht] },
apply ensuresb_step h1 h2 h' _ nlt
end
theorem jump_ensuresb [char_ge : char_ge_2_63 F] {bound}
{op0 : op0_spec} {res : res_spec} {ap_update : bool} {jump_abs : bool}
(h : mem s.pc = (jump_instr jump_abs op0 res ap_update).to_nat)
(h_aux : res.to_op1.op1_imm = ff)
(h' : ensuresb bound mem β¨jump_pc s jump_abs (compute_res mem s op0 res),
bump_ap s ap_update, s.fpβ© (Ξ» k t, P (k + 1) t)) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec,
have h1 : Β¬ is_halting_state mem s,
{ rw not_is_halting_state_iff, left, rw h,
intro h0,
exact jump_ne_jmp_rel _ _ _ _ h_aux (inst_unique char_ge _ _ h0) },
have h2 : β t, next_state mem s t β
t = β¨jump_pc s jump_abs (compute_res mem s op0 res), bump_ap s ap_update, s.fpβ© β§ true,
{ intros t ht,
rw [instruction.next_state_iff_of_eq h, βinstr.next_state, next_state_jump] at ht,
split, ext; simp [ht], trivial },
apply ensuresb_step h1 h2 (Ξ» _, h') _ nlt
end
def checked_int_nz (x : β€) (h0 : abs x β 0) (h1 : abs x < 2^63) := x
lemma checked_int_nz_eq (x : β€) (h0 : abs x β 0) (h1 : abs x < 2^63) :
checked_int_nz x h0 h1 = x := rfl
meta def abs_lt_tac : tactic unit :=
`[ { rw abs_of_nonneg, norm_num, norm_num } <|> { rw abs_of_nonpos, norm_num, norm_num } ]
notation `'[#nz` x `]` := checked_int_nz x (by norm_num) (by abs_lt_tac)
theorem jump_ensuresb' [char_ge : char_ge_2_63 F] {bound : β}
{op0 : op0_spec} {res : res_spec} {ap_update : bool} {jump_abs : bool}
(h : mem s.pc = (jump_instr jump_abs op0 res ap_update).to_nat)
{x : β€} {h0 : abs x β 0} {h1 : abs x < 2^63}
(h_aux : mem (s.pc + 1) = checked_int_nz x h0 h1)
(h' : ensuresb bound mem β¨jump_pc s jump_abs (compute_res mem s op0 res),
bump_ap s ap_update, s.fpβ© (Ξ» k t, P (k + 1) t)) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec,
have h1 : Β¬ is_halting_state mem s,
{ rw [not_is_halting_state_iff, h_aux], right,
apply int.cast_ne_zero_of_abs_lt_char h0,
apply lt_of_lt_of_le h1,
change ((2^ 63 : β) : β€) β€ _,
rw int.coe_nat_le_coe_nat_iff,
apply char_ge },
have h2 : β t, next_state mem s t β
t = β¨jump_pc s jump_abs (compute_res mem s op0 res), bump_ap s ap_update, s.fpβ© β§ true,
{ intros t ht,
rw [instruction.next_state_iff_of_eq h, βinstr.next_state, next_state_jump] at ht,
split, ext; simp [ht], trivial },
apply ensuresb_step h1 h2 (Ξ» _, h') _ nlt
end
theorem jnz_ensuresb [char_ge : char_ge_2_63 F] {bound : β}
{op0 : op0_spec} {op1 : op1_spec} {dst : dst_spec} {ap_update : bool}
(h : mem s.pc = (jnz_instr op0 op1 dst ap_update).to_nat)
(hβ : compute_dst mem s dst = 0 β
ensuresb bound mem β¨bump_pc s op1.op1_imm, bump_ap s ap_update, s.fpβ© (Ξ» k t, P (k + 1) t))
(hβ : compute_dst mem s dst β 0 β
ensuresb bound mem β¨s.pc + compute_op1 mem s op0 op1, bump_ap s ap_update, s.fpβ©
(Ξ» k t, P (k + 1) t)) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec,
have h1 : Β¬ is_halting_state mem s,
{ rw not_is_halting_state_iff, left, rw h,
intro h0,
exact jnz_ne_jmp_rel _ _ _ _ (inst_unique char_ge _ _ h0) },
have h2 : β t, next_state mem s t β
t = β¨ite (compute_dst mem s dst = 0) (bump_pc s op1.op1_imm)
(s.pc + compute_op1 mem s op0 op1), bump_ap s ap_update, s.fpβ© β§
true,
{ intros t ht,
rw [instruction.next_state_iff_of_eq h, βinstr.next_state, next_state_jnz] at ht,
simp [ht],
ext; simp [ht] },
apply ensuresb_step h1 h2 _ _ nlt,
by_cases h3 : compute_dst mem s dst = 0,
{ intro _,
rw if_pos h3,
exact hβ h3 },
intro _,
rw if_neg h3,
exact hβ h3
end
theorem call_ensuresb [char_ge : char_ge_2_63 F] {bound : β} {res : res_spec} {call_abs : bool}
(h : mem s.pc = (call_instr call_abs res).to_nat)
(h' : mem s.ap = s.fp β
mem (s.ap + 1) = bump_pc s res.to_op1.op1_imm β
ensuresb bound mem β¨jump_pc s call_abs (compute_res mem s (op0_spec.ap_plus 1) res),
s.ap + 2, s.ap + 2β© (Ξ» k t, P (k + 1) t)) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec,
have h1 : Β¬ is_halting_state mem s,
{ rw not_is_halting_state_iff, left, rw h,
intro h0,
exact call_ne_jmp_rel _ _ (inst_unique char_ge _ _ h0) },
have h2 : β t, next_state mem s t β
t = β¨jump_pc s call_abs (compute_res mem s (op0_spec.ap_plus 1) res), s.ap + 2, s.ap + 2β© β§
mem (s.ap + 1) = bump_pc s res.to_op1.op1_imm β§ mem s.ap = s.fp,
{ intros t ht,
rw [instruction.next_state_iff_of_eq h, βinstr.next_state, next_state_call] at ht,
simp [ht],
ext; simp [ht] },
apply ensuresb_step h1 h2 _ _ nlt,
intro h3,
apply h' h3.2 h3.1
end
theorem ret_ensuresb [char_ge : char_ge_2_63 F] {bound : β}
(h : mem s.pc = ret_instr.to_nat)
(h' : ensuresb bound mem β¨mem (s.fp + -1), s.ap, mem (s.fp - 2)β© (Ξ» k t, P (k + 1) t)) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec,
have h1 : Β¬ is_halting_state mem s,
{ rw not_is_halting_state_iff, left, rw h,
intro h0,
exact ret_ne_jmp_rel (inst_unique char_ge _ _ h0) },
have h2 : β t, next_state mem s t β
t = β¨mem (s.fp + -1), s.ap, mem (s.fp - 2)β© β§ true,
{ intros t ht,
rw [instruction.next_state_iff_of_eq h, βinstr.next_state, next_state_ret] at ht,
simp [ht],
ext; simp [ht] },
apply ensuresb_step h1 h2 (Ξ» _, h') _ nlt
end
theorem call_ensuresb_trans [char_ge : char_ge_2_63 F] {bound : β}
{P Q : β β register_state F β Prop}
{res : res_spec} {call_abs : bool} {x : F}
(hβ : mem s.pc = x)
(hβ : x = (call_instr call_abs res).to_nat)
(hβ : ensures_ret mem β¨jump_pc s call_abs (compute_res mem s (op0_spec.ap_plus 1) res),
s.ap + 2, s.ap + 2β© P)
(hβ : β k ap, P k β¨bump_pc s res.to_op1.op1_imm, ap, s.fpβ© β
ensuresb bound mem β¨bump_pc s res.to_op1.op1_imm, ap, s.fpβ© (Ξ» k', Q (k + k' + 1))) :
ensuresb (bound + 1) mem s Q :=
begin
apply call_ensuresb (hβ.trans hβ),
intros h1 h2,
apply ensuresb_trans hβ, dsimp,
rintros k β¨tpc, tap, tfpβ©, dsimp,
rw [add_sub_assoc, add_sub_assoc, sub_self, add_zero], norm_num1,
rw [h1, h2],
rintros β¨rfl, rfl, hPβ©,
apply hβ _ _ hP
end
theorem call_rec_ensuresb_trans [char_ge : char_ge_2_63 F] {bound : β}
{P Q : β β register_state F β Prop}
{res : res_spec} {call_abs : bool} {x : F}
(hβ : mem s.pc = x)
(hβ : x = (call_instr call_abs res).to_nat)
(hβ : ensuresb_ret bound mem β¨jump_pc s call_abs (compute_res mem s (op0_spec.ap_plus 1) res),
s.ap + 2, s.ap + 2β© P)
(hβ : β k ap, P k β¨bump_pc s res.to_op1.op1_imm, ap, s.fpβ© β
ensuresb bound mem β¨bump_pc s res.to_op1.op1_imm, ap, s.fpβ© (Ξ» k', Q (k + k' + 1))) :
ensuresb (bound + 1) mem s Q :=
begin
apply call_ensuresb (hβ.trans hβ),
intros h1 h2,
apply ensuresb_rec_trans hβ, dsimp,
rintros k β¨tpc, tap, tfpβ©, dsimp,
rw [add_sub_assoc, add_sub_assoc, sub_self, add_zero], norm_num1,
rw [h1, h2],
rintros β¨rfl, rfl, hPβ©,
apply hβ _ _ hP
end
theorem advance_ap_ensuresb [char_ge : char_ge_2_63 F] {bound : β}
{op0 : op0_spec} {res : res_spec}
(h : mem s.pc = (advance_ap_instr op0 res).to_nat)
(h' : ensuresb bound mem β¨bump_pc s res.to_op1.op1_imm, s.ap + compute_res mem s op0 res, s.fpβ©
(Ξ» k t, P (k + 1) t)) :
ensuresb (bound + 1) mem s P :=
begin
intros n nlt exec,
have h1 : Β¬ is_halting_state mem s,
{ rw not_is_halting_state_iff, left, rw h,
intro h0,
exact advance_ap_ne_jmp_rel _ _ (inst_unique char_ge _ _ h0) },
have h2 : β t, next_state mem s t β
t = β¨bump_pc s res.to_op1.op1_imm, s.ap + compute_res mem s op0 res, s.fpβ© β§ true,
{ intros t ht,
rw [instruction.next_state_iff_of_eq h, βinstr.next_state, next_state_advance_ap] at ht,
simp [ht],
ext; simp [ht] },
apply ensuresb_step h1 h2 (Ξ» _, h') _ nlt
end
end next_state
/-
Theorems to handle the range-checked hypotheses.
-/
def is_range_checked (rc_bound : β) (a : F) : Prop := β n : β, n < rc_bound β§ a = βn
def range_checked (mem : F β F) (rc_start : F) (k rc_bound : β) : Prop :=
β i < k, is_range_checked rc_bound (mem (rc_start + i))
theorem range_checked_mono {mem : F β F} {rc_start : F} {k rc_bound : β}
(k' : β) (k'le : k' β€ k)
(h : range_checked mem rc_start k rc_bound) :
range_checked mem rc_start k' rc_bound :=
Ξ» i iltk', h i (lt_of_lt_of_le iltk' k'le)
theorem range_checked_add_left {mem : F β F} {rc_start : F} {k' k rc_bound : β}
(h : range_checked mem rc_start (k' + k) rc_bound) :
range_checked mem rc_start k rc_bound :=
range_checked_mono _ (nat.le_add_left _ _) h
theorem range_checked_add_right {mem : F β F} {rc_start : F} {k' k rc_bound : β}
(h : range_checked mem rc_start (k + k') rc_bound) :
range_checked mem rc_start k rc_bound :=
range_checked_mono _ (nat.le_add_right _ _) h
theorem range_checked_offset {mem : F β F} {rc_start : F} {k' k rc_bound : β}
(h : range_checked mem rc_start (k + k') rc_bound) :
range_checked mem (rc_start + k') k rc_bound :=
begin
intros i iltk,
rcases h _ (add_lt_add_right iltk k') with β¨i', hi'β©,
use i', rwa [add_assoc, βnat.cast_add, add_comm k']
end
theorem range_checked_offset' {mem : F β F} {rc_start : F} {k' k rc_bound : β}
(h : range_checked mem rc_start (k + k') rc_bound) :
range_checked mem (rc_start + k) k' rc_bound :=
by { rw add_comm at h, exact range_checked_offset h }
def rc_ensures (mem : F β F) (rc_bound k : β) (a0 a1 : F) (P : Prop) :=
a1 = a0 + k β§ (range_checked mem a0 k rc_bound β P)
theorem rc_ensures_comp {mem : F β F} {rc_bound k0 k1 : β} {a0 a1 a2 : F} {P Q : Prop}
(h0 : rc_ensures mem rc_bound k0 a0 a1 P)
(h1 : rc_ensures mem rc_bound k1 a1 a2 Q) :
rc_ensures mem rc_bound (k0 + k1) a0 a2 (P β§ Q) :=
begin
rcases h0 with β¨hk0, rc0β©,
rcases h1 with β¨hk1, rc1β©,
split,
{ rw [hk1, hk0, add_assoc, nat.cast_add] },
intro h, split,
{ exact rc0 (range_checked_add_right h) },
apply rc1, rw hk0, exact range_checked_offset' h
end
theorem rc_ensures_trans {mem : F β F} {rc_bound k : β} {a0 a1 : F} {P Q : Prop}
(h1 : rc_ensures mem rc_bound k a0 a1 P)
(h2 : P β Q) :
rc_ensures mem rc_bound k a0 a1 Q :=
begin
rcases h1 with β¨hk, hβ©,
exact β¨hk, Ξ» h', h2 (h h')β©
end
end main
/-
Tactics.
-/
lemma add_neg_eq_sub {G : Type*} [add_group G] (a b : G) : a + -b = a - b := by rw sub_eq_add_neg
lemma sub_add_eq_add_neg_add {G : Type*} [add_group G] (a b c : G) :
a - b + c = a + (-b + c) := by rw [sub_eq_add_neg, add_assoc]
namespace tactic
setup_tactic_parser
variables (F : Type*) [field F]
def loc_target : loc := loc.ns [none]
meta def mk_simp_arg_list : list pexpr β list simp_arg_type
| [] := []
| (p :: ps) := simp_arg_type.expr p :: mk_simp_arg_list ps
namespace interactive
meta def arith_simps (loc : parse location) : tactic unit :=
let cfg : simp_config_ext := {},
simp_args := mk_simp_arg_list [
``(int.cast_zero), ``(int.cast_one), ``(int.cast_bit0), ``(int.cast_bit1), ``(int.cast_neg),
``(nat.cast_zero), ``(nat.cast_one), ``(nat.cast_bit0), ``(nat.cast_bit1),
``(add_assoc), ``(add_sub_assoc), ``(add_zero), ``(add_right_neg), ``(add_left_neg),
``(add_neg_eq_sub), ``(sub_add_eq_add_neg_add), ``(mul_assoc)] in
do try $ simp_core cfg.to_simp_config cfg.discharger tt simp_args [] loc >> skip,
try $ (tactic.norm_num1 norm_num.derive.step loc >>
(try $ simp_core cfg.to_simp_config cfg.discharger tt simp_args [] loc >> skip))
meta def ensures_simps (loc : parse location) : tactic unit :=
let cfg : simp_config_ext := {},
simp_args := mk_simp_arg_list [``(res_spec.to_op1), ``(compute_res), ``(compute_op1),
``(compute_op0), ``(op1_spec.op1_imm), ``(compute_dst), ``(bump_pc), ``(bump_ap),
``(jump_pc), ``(clip_checked), ``(checked_int_nz_eq),
``(int.cast_zero), ``(int.cast_one), ``(int.cast_bit0), ``(int.cast_bit1), ``(int.cast_neg),
``(nat.cast_zero), ``(nat.cast_one), ``(nat.cast_bit0), ``(nat.cast_bit1),
``(add_assoc), ``(add_sub_assoc), ``(add_zero), ``(add_right_neg), ``(add_left_neg),
``(add_neg_eq_sub), ``(sub_add_eq_add_neg_add), ``(mul_assoc)] in
do try $ simp_core cfg.to_simp_config cfg.discharger tt simp_args [] loc >> skip,
try (tactic.norm_num1 norm_num.derive.step loc >>
(try $ simp_core cfg.to_simp_config cfg.discharger tt simp_args [] loc >> skip))
meta def unpack_memory (code : parse ident) (h : parse $ tk "at" *> ident)
(pat : parse $ tk "with" *>rcases_patt_parse) : tactic unit :=
let cfg : simp_config_ext := {},
simp_args := mk_simp_arg_list [``(mem_at), ``(add_assoc), ``(and_true)] in
do unfold [code] (loc.ns [h]),
try $ simp_core cfg.to_simp_config cfg.discharger tt simp_args [] (loc.ns [h]) >> skip,
try $ tactic.norm_num1 norm_num.derive.step (loc.ns [h]),
eh β resolve_name h,
rcases (rcases_args.rcases none eh pat)
meta def ensuresb_make_succ : tactic unit :=
(applyc ``ensuresb_test) <|> (applyc ``ensuresb_succ)
meta def step_assert_eq (h : parse ident) (h' : parse ident?)
(hw : parse $ tk "with" *> ident) :=
do ensuresb_make_succ,
applyc ``assert_eq_ensuresb',
eh β get_local h,
tactic.apply eh,
tactic.clear eh,
ensures_simps loc_target,
match h' with
| (some n) := do eh β get_local n,
try $ tactic.rewrite_target eh >> tactic.clear eh --,
-- ensures_simps loc_target
| none := skip
end,
intro hw
meta def step_jump (h : parse ident) :=
do ensuresb_make_succ,
applyc ``jump_ensuresb,
eh β get_local h,
tactic.apply eh,
tactic.clear eh,
/- first subgoal: not an immediate argument-/
tactic.reflexivity,
/- main goal -/
ensures_simps loc_target
meta def step_jump_imm (h : parse ident) (h' : parse ident) :=
do ensuresb_make_succ,
applyc ``jump_ensuresb',
eh β get_local h,
tactic.apply eh,
arith_simps loc_target,
eh' β get_local h',
tactic.apply eh',
/- main goal -/
ensures_simps loc_target,
eh' β get_local h',
try $ tactic.rewrite_target eh',
tactic.clear eh,
tactic.clear eh',
ensures_simps loc_target
meta def step_jnz (h : parse ident) (h' : parse ident?)
(hw : parse $ tk "with" *> ident) (hw' : parse ident):=
do ensuresb_make_succ,
applyc ``jnz_ensuresb,
eh β get_local h,
tactic.apply eh,
tactic.clear eh,
swap,
tactic.clear eh,
focus $ do { ensures_simps loc_target },
match h' with
| (some n) := do eh β get_local n,
try $ tactic.rewrite_target eh >> tactic.clear eh,
ensures_simps loc_target
| none := skip
end,
ehw' β tactic.intro hw',
try $ tactic.rewrite_target eh,
swap,
focus $ do { ensures_simps loc_target },
intro hw,
match h' with
| (some n) := do eh β get_local n,
try $ tactic.rewrite_target eh >> tactic.clear eh,
ensures_simps loc_target
| none := skip
end
meta def step_call (h : parse ident) :=
do ensuresb_make_succ,
applyc ``call_ensuresb,
eh β get_local h,
tactic.apply eh,
tactic.clear eh,
ensures_simps loc_target
meta def step_ret (h : parse ident) :=
do ensuresb_make_succ,
applyc ``ret_ensuresb,
eh β get_local h,
tactic.apply eh,
tactic.clear eh,
ensures_simps loc_target
meta def step_advance_ap (h : parse ident) (h' : parse ident?) :=
do ensuresb_make_succ,
applyc ``advance_ap_ensuresb,
eh β get_local h,
tactic.apply eh,
tactic.clear eh,
ensures_simps loc_target,
match h' with
| (some n) := do eh β get_local n,
try $ tactic.rewrite_target eh >> tactic.clear eh,
ensures_simps loc_target
| none := skip
end
meta def step_sub (h1 : parse ident) (h2 : parse parser.pexpr) :
tactic unit :=
focus1 $ do
eh β get_local h1,
ensuresb_make_succ,
apply ``(call_ensuresb_trans _ %%eh %%h2 _),
refl,
all_goals' (tactic.clear eh >> ensures_simps loc_target)
meta def step_rec_sub (h1 : parse ident) (h2 : parse parser.pexpr) :
tactic unit :=
focus1 $ do
eh β get_local h1,
ensuresb_make_succ,
apply ``(call_rec_ensuresb_trans _ %%eh %%h2 _),
refl,
all_goals' (tactic.clear eh >> ensures_simps loc_target)
meta def step_done : tactic unit :=
`[ ensuresb_make_succ, apply ensuresb_id ]
/-- A weaker version of the interactive `use` tactic, which doesn't call `triv` -/
meta def use_only (l : parse pexpr_list_or_texpr) : tactic unit :=
focus1 $ tactic.use l
/-- norm_num1 plus an extra simp rule -/
meta def norm_num2 : tactic unit :=
`[ norm_num1, try { simp only [add_neg_eq_sub] } ]
section
open interactive interactive.types expr
private meta def mkdef_arg_p_aux : pexpr β parser (name Γ pexpr)
| (app (app (macro _ [const `eq _ ]) (local_const x _ _ _)) h) := pure (x, h)
| _ := fail "parse error"
private meta def mkdef_arg_p : parser (name Γ pexpr) :=
with_desc "expr = id" $ parser.pexpr 0 >>= mkdef_arg_p_aux
/--
`mkdef h : x = t` introduces a new variable `x` into the context with
assumption `h : x = t`. It is essentially a simplified version of
`generalize'` with the equation syntax reversed.
-/
meta def mkdef (h : parse ident) (_ : parse $ tk ":") (p : parse mkdef_arg_p) :
tactic unit :=
propagate_tags $
do let (x, p) := p,
e β i_to_expr p,
tgt β target,
tgt' β to_expr ``(Ξ x, x = %%e β %%tgt),
t β assert h tgt',
swap,
exact ``(%%t %%e rfl),
intro x,
intro h
end
end interactive
end tactic
/-
Some useful things for the autogenerated proofs.
-/
section
theorem assert_eq_reduction {F : Type} {a b c d : F} (h : c = d) (h' : a = c β§ d = b) :
a = b := (h'.1.trans h).trans h'.2
variables {F : Type*} [field F]
lemma cond_aux1 {a b t : F} (h1 : t = a - b) (h2 : t = 0) : a = b :=
by { rw h2 at h1, exact eq_of_sub_eq_zero h1.symm }
lemma cond_aux2 {a b t : F} (h1 : t = a - b) (h2 : t β 0) : a β b :=
by { intro h3, apply h2, rwa [h3, sub_self] at h1 }
lemma eq_sub_of_eq_add {a b c : F} (h: b = a + c) : a = b - c :=
eq_sub_of_add_eq h.symm
-- a trick for inferring the value of the ap at proof time
lemma of_register_state [decidable_eq F] {bound : β}
{mem : F β F} {s : register_state F} {P : β β register_state F β Prop} :
(β x, x = s β ensuresb bound mem s P) β
ensuresb bound mem s P :=
Ξ» h, h s rfl
/-- division with a default value -/
def ddiv [decidable_eq F] (a b c : F) : F := if b β 0 then a / b else c
theorem ddiv_eq [decidable_eq F] {a b c : F} (h : b β 0) : ddiv a b c = a / b :=
if_pos h
theorem eq_ddiv_of_eq_mul [decidable_eq F] {a b c : F} (h : a = c * b) : c = ddiv a b c :=
begin
by_cases h' : b β 0,
{ rw [ddiv, if_pos h', eq_div_iff h', h] },
rw [ddiv, if_neg h']
end
theorem exists_eq_ddiv_of_eq_mul [decidable_eq F] {a b c : F} (h : a = c * b) :
β d, c = ddiv a b d :=
β¨c, eq_ddiv_of_eq_mul hβ©
-- for handling division by a constant
lemma div_eq_mul_inv' {F : Type*} [field F] {x y z : F}
(h : y * z = 1) : x / y = x * z :=
begin
have : y β 0,
{ intro yzero, simp [yzero] at h, contradiction },
symmetry, apply eq_div_of_mul_eq this,
rw [mul_assoc, mul_comm z, h, mul_one],
end
end
|
c33016fa0a7490908de69522dbdf7570f712e255
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/matrix/pequiv.lean
|
9e602fb011eac198d15809c486d27b1afd1ca952
|
[
"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
| 5,729
|
lean
|
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.matrix.basic
import data.pequiv
/-!
# partial equivalences for matrices
Using partial equivalences to represent matrices.
This file introduces the function `pequiv.to_matrix`, which returns a matrix containing ones and
zeros. For any partial equivalence `f`, `f.to_matrix i j = 1 β f i = some j`.
The following important properties of this function are proved
`to_matrix_trans : (f.trans g).to_matrix = f.to_matrix β¬ g.to_matrix`
`to_matrix_symm : f.symm.to_matrix = f.to_matrixα΅`
`to_matrix_refl : (pequiv.refl n).to_matrix = 1`
`to_matrix_bot : β₯.to_matrix = 0`
This theory gives the matrix representation of projection linear maps, and their right inverses.
For example, the matrix `(single (0 : fin 1) (i : fin n)).to_matrix` corresponds to the ith
projection map from R^n to R.
Any injective function `fin m β fin n` gives rise to a `pequiv`, whose matrix is the projection
map from R^m β R^n represented by the same function. The transpose of this matrix is the right
inverse of this map, sending anything not in the image to zero.
## notations
This file uses the notation ` β¬ ` for `matrix.mul` and `α΅` for `matrix.transpose`.
-/
namespace pequiv
open matrix
universes u v
variables {k l m n : Type*}
variables {Ξ± : Type v}
open_locale matrix
/-- `to_matrix` returns a matrix containing ones and zeros. `f.to_matrix i j` is `1` if
`f i = some j` and `0` otherwise -/
def to_matrix [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] (f : m β. n) : matrix m n Ξ±
| i j := if j β f i then 1 else 0
lemma mul_matrix_apply [fintype m] [decidable_eq m] [semiring Ξ±] (f : l β. m) (M : matrix m n Ξ±)
(i j) : (f.to_matrix β¬ M) i j = option.cases_on (f i) 0 (Ξ» fi, M fi j) :=
begin
dsimp [to_matrix, matrix.mul_apply],
cases h : f i with fi,
{ simp [h] },
{ rw finset.sum_eq_single fi;
simp [h, eq_comm] {contextual := tt} }
end
lemma to_matrix_symm [decidable_eq m] [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] (f : m β. n) :
(f.symm.to_matrix : matrix n m Ξ±) = f.to_matrixα΅ :=
by ext; simp only [transpose, mem_iff_mem f, to_matrix]; congr
@[simp] lemma to_matrix_refl [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] :
((pequiv.refl n).to_matrix : matrix n n Ξ±) = 1 :=
by ext; simp [to_matrix, one_apply]; congr
lemma matrix_mul_apply [fintype m] [semiring Ξ±] [decidable_eq n] (M : matrix l m Ξ±) (f : m β. n)
(i j) : (M β¬ f.to_matrix) i j = option.cases_on (f.symm j) 0 (Ξ» fj, M i fj) :=
begin
dsimp [to_matrix, matrix.mul_apply],
cases h : f.symm j with fj,
{ simp [h, β f.eq_some_iff] },
{ rw finset.sum_eq_single fj,
{ simp [h, β f.eq_some_iff], },
{ intros b H n, simp [h, β f.eq_some_iff, n.symm], },
{ simp, } }
end
lemma to_pequiv_mul_matrix [fintype m] [decidable_eq m] [semiring Ξ±] (f : m β m)
(M : matrix m n Ξ±) : (f.to_pequiv.to_matrix β¬ M) = Ξ» i, M (f i) :=
by { ext i j, rw [mul_matrix_apply, equiv.to_pequiv_apply] }
lemma to_matrix_trans [fintype m] [decidable_eq m] [decidable_eq n] [semiring Ξ±]
(f : l β. m) (g : m β. n) : ((f.trans g).to_matrix : matrix l n Ξ±) = f.to_matrix β¬ g.to_matrix :=
begin
ext i j,
rw [mul_matrix_apply],
dsimp [to_matrix, pequiv.trans],
cases f i; simp
end
@[simp] lemma to_matrix_bot [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] :
((β₯ : pequiv m n).to_matrix : matrix m n Ξ±) = 0 := rfl
lemma to_matrix_injective [decidable_eq n] [monoid_with_zero Ξ±] [nontrivial Ξ±] :
function.injective (@to_matrix m n Ξ± _ _ _) :=
begin
classical,
assume f g,
refine not_imp_not.1 _,
simp only [matrix.ext_iff.symm, to_matrix, pequiv.ext_iff,
not_forall, exists_imp_distrib],
assume i hi,
use i,
cases hf : f i with fi,
{ cases hg : g i with gi,
{ cc },
{ use gi,
simp, } },
{ use fi,
simp [hf.symm, ne.symm hi] }
end
lemma to_matrix_swap [decidable_eq n] [ring Ξ±] (i j : n) :
(equiv.swap i j).to_pequiv.to_matrix =
(1 : matrix n n Ξ±) - (single i i).to_matrix - (single j j).to_matrix + (single i j).to_matrix +
(single j i).to_matrix :=
begin
ext,
dsimp [to_matrix, single, equiv.swap_apply_def, equiv.to_pequiv, one_apply],
split_ifs; simp * at *
end
@[simp] lemma single_mul_single [fintype n] [decidable_eq k] [decidable_eq m] [decidable_eq n]
[semiring Ξ±] (a : m) (b : n) (c : k) :
((single a b).to_matrix : matrix _ _ Ξ±) β¬ (single b c).to_matrix = (single a c).to_matrix :=
by rw [β to_matrix_trans, single_trans_single]
lemma single_mul_single_of_ne [fintype n] [decidable_eq n] [decidable_eq k]
[decidable_eq m] [semiring Ξ±] {bβ bβ : n} (hb : bβ β bβ) (a : m) (c : k) :
((single a bβ).to_matrix : matrix _ _ Ξ±) β¬ (single bβ c).to_matrix = 0 :=
by rw [β to_matrix_trans, single_trans_single_of_ne hb, to_matrix_bot]
/-- Restatement of `single_mul_single`, which will simplify expressions in `simp` normal form,
when associativity may otherwise need to be carefully applied. -/
@[simp] lemma single_mul_single_right [fintype n] [fintype k] [decidable_eq n] [decidable_eq k]
[decidable_eq m] [semiring Ξ±] (a : m) (b : n) (c : k) (M : matrix k l Ξ±) :
(single a b).to_matrix β¬ ((single b c).to_matrix β¬ M) = (single a c).to_matrix β¬ M :=
by rw [β matrix.mul_assoc, single_mul_single]
/-- We can also define permutation matrices by permuting the rows of the identity matrix. -/
lemma equiv_to_pequiv_to_matrix [decidable_eq n] [has_zero Ξ±] [has_one Ξ±] (Ο : equiv n n)
(i j : n) :
Ο.to_pequiv.to_matrix i j = (1 : matrix n n Ξ±) (Ο i) j :=
if_congr option.some_inj rfl rfl
end pequiv
|
98fd7934f044c0c5a6467fdcc924dd8b63985de2
|
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
|
/tests/lean/run/struct2.lean
|
8d4b1b0817cb442a7758e7140d16e4e1bd869b0a
|
[
"Apache-2.0"
] |
permissive
|
banksonian/lean4
|
3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc
|
78da6b3aa2840693eea354a41e89fc5b212a5011
|
refs/heads/master
| 1,673,703,624,165
| 1,605,123,551,000
| 1,605,123,551,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 232
|
lean
|
universe u
structure A (Ξ± : Type u) :=
(f : (Ξ² : Type u) β Ξ± β Ξ² β Ξ±)
set_option pp.all true
structure B (Ξ± : Type u) extends A Ξ± :=
(x : Nat)
(f := fun Ξ² a b => a)
#check B.f._default
#check { x := 10 : B Nat}
|
116c0cffe3bdd114264d8e8b67e8dda315ac4958
|
e61a235b8468b03aee0120bf26ec615c045005d2
|
/stage0/src/Init/Core.lean
|
3ca4ab339317fabdb7adfc2bd08e18af54fa5f64
|
[
"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
| 64,156
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
notation, basic datatypes and type classes
-/
prelude
notation `Prop` := Sort 0
notation f ` $ `:1 a:0 := f a
/- Logical operations and relations -/
reserve prefix `Β¬`:40
reserve infixr ` β§ `:35
reserve infixr ` /\ `:35
reserve infixr ` \/ `:30
reserve infixr ` β¨ `:30
reserve infix ` <-> `:20
reserve infix ` β `:20
reserve infix ` = `:50
reserve infix ` == `:50
reserve infix ` != `:50
reserve infix ` ~= `:50
reserve infix ` β
`:50
reserve infix ` β `:50
reserve infix ` β `:50
reserve infixr ` βΈ `:75
/- types and Type constructors -/
reserve infixr ` Γ `:35
/- arithmetic operations -/
reserve infixl ` + `:65
reserve infixl ` - `:65
reserve infixl ` * `:70
reserve infixl ` / `:70
reserve infixl ` % `:70
reserve infixl ` %β `:70
reserve prefix `-`:100
reserve infixr ` ^ `:80
reserve infixr ` β `:90
reserve infix ` <= `:50
reserve infix ` β€ `:50
reserve infix ` < `:50
reserve infix ` >= `:50
reserve infix ` β₯ `:50
reserve infix ` > `:50
/- boolean operations -/
reserve prefix `!`:40
reserve infixl ` && `:35
reserve infixl ` || `:30
/- other symbols -/
reserve infixl ` ++ `:65
reserve infixr ` :: `:67
/- Control -/
reserve infixr ` <|> `:2
reserve infixr ` >>= `:55
reserve infixr ` >=> `:55
reserve infixl ` <*> `:60
reserve infixl ` <* ` :60
reserve infixr ` *> ` :60
reserve infixr ` >> ` :60
reserve infixr ` <$> `:100
reserve infixr ` <$ ` :100
reserve infixr ` $> ` :100
reserve infixl ` <&> `:100
universes u v w
/-- Auxiliary unsafe constant used by the Compiler when erasing proofs from code. -/
unsafe axiom lcProof {Ξ± : Prop} : Ξ±
/-- Auxiliary unsafe constant used by the Compiler to mark unreachable code. -/
unsafe axiom lcUnreachable {Ξ± : Sort u} : Ξ±
@[inline] def id {Ξ± : Sort u} (a : Ξ±) : Ξ± := a
def inline {Ξ± : Sort u} (a : Ξ±) : Ξ± := a
@[inline] def flip {Ξ± : Sort u} {Ξ² : Sort v} {Ο : Sort w} (f : Ξ± β Ξ² β Ο) : Ξ² β Ξ± β Ο :=
fun b a => f a b
/-
The kernel definitional equality test (t =?= s) has special support for idDelta applications.
It implements the following rules
1) (idDelta t) =?= t
2) t =?= (idDelta t)
3) (idDelta t) =?= s IF (unfoldOf t) =?= s
4) t =?= idDelta s IF t =?= (unfoldOf s)
This is mechanism for controlling the delta reduction (aka unfolding) used in the kernel.
We use idDelta applications to address performance problems when Type checking
theorems generated by the equation Compiler.
-/
@[inline] def idDelta {Ξ± : Sort u} (a : Ξ±) : Ξ± :=
a
/-- Gadget for optional parameter support. -/
@[reducible] def optParam (Ξ± : Sort u) (default : Ξ±) : Sort u :=
Ξ±
/-- Gadget for marking output parameters in type classes. -/
@[reducible] def outParam (Ξ± : Sort u) : Sort u := Ξ±
/-- Auxiliary Declaration used to implement the notation (a : Ξ±) -/
@[reducible] def typedExpr (Ξ± : Sort u) (a : Ξ±) : Ξ± := a
/- `idRhs` is an auxiliary Declaration used in the equation Compiler to address performance
issues when proving equational theorems. The equation Compiler uses it as a marker. -/
@[macroInline, reducible] def idRhs (Ξ± : Sort u) (a : Ξ±) : Ξ± := a
inductive PUnit : Sort u
| unit : PUnit
/-- An abbreviation for `PUnit.{0}`, its most common instantiation.
This Type should be preferred over `PUnit` where possible to avoid
unnecessary universe parameters. -/
abbrev Unit : Type := PUnit
@[matchPattern] abbrev Unit.unit : Unit := PUnit.unit
/- Remark: thunks have an efficient implementation in the runtime. -/
structure Thunk (Ξ± : Type u) : Type u :=
(fn : Unit β Ξ±)
attribute [extern "lean_mk_thunk"] Thunk.mk
@[noinline, extern "lean_thunk_pure"]
protected def Thunk.pure {Ξ± : Type u} (a : Ξ±) : Thunk Ξ± :=
β¨fun _ => aβ©
@[noinline, extern "lean_thunk_get_own"]
protected def Thunk.get {Ξ± : Type u} (x : @& Thunk Ξ±) : Ξ± :=
x.fn ()
@[noinline, extern "lean_thunk_map"]
protected def Thunk.map {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β Ξ²) (x : Thunk Ξ±) : Thunk Ξ² :=
β¨fun _ => f x.getβ©
@[noinline, extern "lean_thunk_bind"]
protected def Thunk.bind {Ξ± : Type u} {Ξ² : Type v} (x : Thunk Ξ±) (f : Ξ± β Thunk Ξ²) : Thunk Ξ² :=
β¨fun _ => (f x.get).getβ©
/- Remark: tasks have an efficient implementation in the runtime. -/
structure Task (Ξ± : Type u) : Type u :=
(fn : Unit β Ξ±)
attribute [extern "lean_mk_task"] Task.mk
@[noinline, extern "lean_task_pure"]
protected def Task.pure {Ξ± : Type u} (a : Ξ±) : Task Ξ± :=
β¨fun _ => aβ©
@[noinline, extern "lean_task_get"]
protected def Task.get {Ξ± : Type u} (x : @& Task Ξ±) : Ξ± :=
x.fn ()
@[noinline, extern "lean_task_map"]
protected def Task.map {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β Ξ²) (x : Task Ξ±) : Task Ξ² :=
β¨fun _ => f x.getβ©
@[noinline, extern "lean_task_bind"]
protected def Task.bind {Ξ± : Type u} {Ξ² : Type v} (x : Task Ξ±) (f : Ξ± β Task Ξ²) : Task Ξ² :=
β¨fun _ => (f x.get).getβ©
inductive True : Prop
| intro : True
inductive False : Prop
inductive Empty : Type
def Not (a : Prop) : Prop := a β False
prefix `Β¬` := Not
inductive Eq {Ξ± : Sort u} (a : Ξ±) : Ξ± β Prop
| refl {} : Eq a
@[elabAsEliminator, inline, reducible]
def Eq.ndrec.{u1, u2} {Ξ± : Sort u2} {a : Ξ±} {C : Ξ± β Sort u1} (m : C a) {b : Ξ±} (h : Eq a b) : C b :=
@Eq.rec Ξ± a (fun Ξ± _ => C Ξ±) m b h
@[elabAsEliminator, inline, reducible]
def Eq.ndrecOn.{u1, u2} {Ξ± : Sort u2} {a : Ξ±} {C : Ξ± β Sort u1} {b : Ξ±} (h : Eq a b) (m : C a) : C b :=
@Eq.rec Ξ± a (fun Ξ± _ => C Ξ±) m b h
/-
Initialize the Quotient Module, which effectively adds the following definitions:
constant Quot {Ξ± : Sort u} (r : Ξ± β Ξ± β Prop) : Sort u
constant Quot.mk {Ξ± : Sort u} (r : Ξ± β Ξ± β Prop) (a : Ξ±) : Quot r
constant Quot.lift {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {Ξ² : Sort v} (f : Ξ± β Ξ²) :
(β a b : Ξ±, r a b β Eq (f a) (f b)) β Quot r β Ξ²
constant Quot.ind {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {Ξ² : Quot r β Prop} :
(β a : Ξ±, Ξ² (Quot.mk r a)) β β q : Quot r, Ξ² q
-/
init_quot
inductive HEq {Ξ± : Sort u} (a : Ξ±) : β {Ξ² : Sort u}, Ξ² β Prop
| refl {} : HEq a
structure Prod (Ξ± : Type u) (Ξ² : Type v) :=
(fst : Ξ±) (snd : Ξ²)
attribute [unbox] Prod
/-- Similar to `Prod`, but Ξ± and Ξ² can be propositions.
We use this Type internally to automatically generate the brecOn recursor. -/
structure PProd (Ξ± : Sort u) (Ξ² : Sort v) :=
(fst : Ξ±) (snd : Ξ²)
structure And (a b : Prop) : Prop :=
intro :: (left : a) (right : b)
structure Iff (a b : Prop) : Prop :=
intro :: (mp : a β b) (mpr : b β a)
/- Eq basic support -/
infix `=` := Eq
@[matchPattern] def rfl {Ξ± : Sort u} {a : Ξ±} : a = a := Eq.refl a
@[elabAsEliminator]
theorem Eq.subst {Ξ± : Sort u} {P : Ξ± β Prop} {a b : Ξ±} (hβ : a = b) (hβ : P a) : P b :=
Eq.ndrec hβ hβ
infixr `βΈ` := Eq.subst
theorem Eq.trans {Ξ± : Sort u} {a b c : Ξ±} (hβ : a = b) (hβ : b = c) : a = c :=
hβ βΈ hβ
theorem Eq.symm {Ξ± : Sort u} {a b : Ξ±} (h : a = b) : b = a :=
h βΈ rfl
infix `~=` := HEq
infix `β
` := HEq
@[matchPattern] def HEq.rfl {Ξ± : Sort u} {a : Ξ±} : a β
a := HEq.refl a
theorem eqOfHEq {Ξ± : Sort u} {a a' : Ξ±} (h : a β
a') : a = a' :=
have β (Ξ±' : Sort u) (a' : Ξ±') (hβ : @HEq Ξ± a Ξ±' a') (hβ : Ξ± = Ξ±'), (Eq.recOn hβ a : Ξ±') = a' :=
fun (Ξ±' : Sort u) (a' : Ξ±') (hβ : @HEq Ξ± a Ξ±' a') => HEq.recOn hβ (fun (hβ : Ξ± = Ξ±) => rfl);
show (Eq.ndrecOn (Eq.refl Ξ±) a : Ξ±) = a' from
this Ξ± a' h (Eq.refl Ξ±)
inductive Sum (Ξ± : Type u) (Ξ² : Type v)
| inl (val : Ξ±) : Sum
| inr (val : Ξ²) : Sum
inductive PSum (Ξ± : Sort u) (Ξ² : Sort v)
| inl (val : Ξ±) : PSum
| inr (val : Ξ²) : PSum
inductive Or (a b : Prop) : Prop
| inl (h : a) : Or
| inr (h : b) : Or
def Or.introLeft {a : Prop} (b : Prop) (ha : a) : Or a b :=
Or.inl ha
def Or.introRight (a : Prop) {b : Prop} (hb : b) : Or a b :=
Or.inr hb
structure Sigma {Ξ± : Type u} (Ξ² : Ξ± β Type v) :=
mk :: (fst : Ξ±) (snd : Ξ² fst)
attribute [unbox] Sigma
structure PSigma {Ξ± : Sort u} (Ξ² : Ξ± β Sort v) :=
mk :: (fst : Ξ±) (snd : Ξ² fst)
inductive Bool : Type
| false : Bool
| true : Bool
/- Remark: Subtype must take a Sort instead of Type because of the axiom strongIndefiniteDescription. -/
structure Subtype {Ξ± : Sort u} (p : Ξ± β Prop) :=
(val : Ξ±) (property : p val)
inductive Exists {Ξ± : Sort u} (p : Ξ± β Prop) : Prop
| intro (w : Ξ±) (h : p w) : Exists
class inductive Decidable (p : Prop)
| isFalse (h : Β¬p) : Decidable
| isTrue (h : p) : Decidable
abbrev DecidablePred {Ξ± : Sort u} (r : Ξ± β Prop) :=
β (a : Ξ±), Decidable (r a)
abbrev DecidableRel {Ξ± : Sort u} (r : Ξ± β Ξ± β Prop) :=
β (a b : Ξ±), Decidable (r a b)
abbrev DecidableEq (Ξ± : Sort u) :=
β (a b : Ξ±), Decidable (a = b)
def decEq {Ξ± : Sort u} [s : DecidableEq Ξ±] (a b : Ξ±) : Decidable (a = b) :=
s a b
inductive Option (Ξ± : Type u)
| none : Option
| some (val : Ξ±) : Option
attribute [unbox] Option
export Option (none some)
export Bool (false true)
inductive List (T : Type u)
| nil : List
| cons (hd : T) (tl : List) : List
infixr `::` := List.cons
inductive Nat
| zero : Nat
| succ (n : Nat) : Nat
/- Auxiliary axiom used to implement `sorry`.
TODO: add this theorem on-demand. That is,
we should only add it if after the first error. -/
axiom sorryAx (Ξ± : Sort u) (synthetic := true) : Ξ±
/- Declare builtin and reserved notation -/
class HasZero (Ξ± : Type u) := mk {} :: (zero : Ξ±)
class HasOne (Ξ± : Type u) := mk {} :: (one : Ξ±)
class HasAdd (Ξ± : Type u) := (add : Ξ± β Ξ± β Ξ±)
class HasMul (Ξ± : Type u) := (mul : Ξ± β Ξ± β Ξ±)
class HasNeg (Ξ± : Type u) := (neg : Ξ± β Ξ±)
class HasSub (Ξ± : Type u) := (sub : Ξ± β Ξ± β Ξ±)
class HasDiv (Ξ± : Type u) := (div : Ξ± β Ξ± β Ξ±)
class HasMod (Ξ± : Type u) := (mod : Ξ± β Ξ± β Ξ±)
class HasModN (Ξ± : Type u) := (modn : Ξ± β Nat β Ξ±)
class HasLessEq (Ξ± : Type u) := (LessEq : Ξ± β Ξ± β Prop)
class HasLess (Ξ± : Type u) := (Less : Ξ± β Ξ± β Prop)
class HasBeq (Ξ± : Type u) := (beq : Ξ± β Ξ± β Bool)
class HasAppend (Ξ± : Type u) := (append : Ξ± β Ξ± β Ξ±)
class HasOrelse (Ξ± : Type u) := (orelse : Ξ± β Ξ± β Ξ±)
class HasAndthen (Ξ± : Type u) := (andthen : Ξ± β Ξ± β Ξ±)
class HasEquiv (Ξ± : Sort u) := (Equiv : Ξ± β Ξ± β Prop)
class HasEmptyc (Ξ± : Type u) := (emptyc : Ξ±)
class HasPow (Ξ± : Type u) (Ξ² : Type v) :=
(pow : Ξ± β Ξ² β Ξ±)
infix `+` := HasAdd.add
infix `*` := HasMul.mul
infix `-` := HasSub.sub
infix `/` := HasDiv.div
infix `%` := HasMod.mod
infix `%β` := HasModN.modn
prefix `-` := HasNeg.neg
infix `<=` := HasLessEq.LessEq
infix `β€` := HasLessEq.LessEq
infix `<` := HasLess.Less
infix `==` := HasBeq.beq
infix `++` := HasAppend.append
notation `β
` := HasEmptyc.emptyc
infix `β` := HasEquiv.Equiv
infixr `^` := HasPow.pow
infixr `/\` := And
infixr `β§` := And
infixr `\/` := Or
infixr `β¨` := Or
infix `<->` := Iff
infix `β` := Iff
-- notation `exists` binders `, ` r:(scoped P, Exists P) := r
-- notation `β` binders `, ` r:(scoped P, Exists P) := r
infixr `<|>` := HasOrelse.orelse
infixr `>>` := HasAndthen.andthen
@[reducible] def GreaterEq {Ξ± : Type u} [HasLessEq Ξ±] (a b : Ξ±) : Prop := HasLessEq.LessEq b a
@[reducible] def Greater {Ξ± : Type u} [HasLess Ξ±] (a b : Ξ±) : Prop := HasLess.Less b a
infix `>=` := GreaterEq
infix `β₯` := GreaterEq
infix `>` := Greater
@[inline] def bit0 {Ξ± : Type u} [s : HasAdd Ξ±] (a : Ξ±) : Ξ± := a + a
@[inline] def bit1 {Ξ± : Type u} [sβ : HasOne Ξ±] [sβ : HasAdd Ξ±] (a : Ξ±) : Ξ± := (bit0 a) + 1
attribute [matchPattern] HasZero.zero HasOne.one bit0 bit1 HasAdd.add HasNeg.neg
/- Nat basic instances -/
@[extern "lean_nat_add"]
protected def Nat.add : (@& Nat) β (@& Nat) β Nat
| a, Nat.zero => a
| a, Nat.succ b => Nat.succ (Nat.add a b)
/- We mark the following definitions as pattern to make sure they can be used in recursive equations,
and reduced by the equation Compiler. -/
attribute [matchPattern] Nat.add Nat.add._main
instance : HasZero Nat := β¨Nat.zeroβ©
instance : HasOne Nat := β¨Nat.succ (Nat.zero)β©
instance : HasAdd Nat := β¨Nat.addβ©
/- Auxiliary constant used by equation compiler. -/
constant hugeFuel : Nat := 10000
def std.priority.default : Nat := 1000
def std.priority.max : Nat := 0xFFFFFFFF
protected def Nat.prio := std.priority.default + 100
/-
Global declarations of right binding strength
If a Module reassigns these, it will be incompatible with other modules that adhere to these
conventions.
When hovering over a symbol, use "C-c C-k" to see how to input it.
-/
def std.prec.max : Nat := 1024 -- the strength of application, identifiers, (, [, etc.
def std.prec.arrow : Nat := 25
/-
The next def is "max + 10". It can be used e.g. for postfix operations that should
be stronger than application.
-/
def std.prec.maxPlus : Nat := std.prec.max + 10
infixr `Γ` := Prod
-- notation for n-ary tuples
/- Some type that is not a scalar value in our runtime. -/
structure NonScalar :=
(val : Nat)
/- Some type that is not a scalar value in our runtime and is universe polymorphic. -/
inductive PNonScalar : Type u
| mk (v : Nat) : PNonScalar
/- For numeric literals notation -/
class HasOfNat (Ξ± : Type u) :=
(ofNat : Nat β Ξ±)
export HasOfNat (ofNat)
instance : HasOfNat Nat :=
β¨idβ©
/- sizeof -/
class HasSizeof (Ξ± : Sort u) :=
(sizeof : Ξ± β Nat)
export HasSizeof (sizeof)
/-
Declare sizeof instances and theorems for types declared before HasSizeof.
From now on, the inductive Compiler will automatically generate sizeof instances and theorems.
-/
/- Every Type `Ξ±` has a default HasSizeof instance that just returns 0 for every element of `Ξ±` -/
protected def default.sizeof (Ξ± : Sort u) : Ξ± β Nat
| a => 0
instance defaultHasSizeof (Ξ± : Sort u) : HasSizeof Ξ± :=
β¨default.sizeof Ξ±β©
protected def Nat.sizeof : Nat β Nat
| n => n
instance : HasSizeof Nat :=
β¨Nat.sizeofβ©
protected def Prod.sizeof {Ξ± : Type u} {Ξ² : Type v} [HasSizeof Ξ±] [HasSizeof Ξ²] : (Prod Ξ± Ξ²) β Nat
| β¨a, bβ© => 1 + sizeof a + sizeof b
instance (Ξ± : Type u) (Ξ² : Type v) [HasSizeof Ξ±] [HasSizeof Ξ²] : HasSizeof (Prod Ξ± Ξ²) :=
β¨Prod.sizeofβ©
protected def Sum.sizeof {Ξ± : Type u} {Ξ² : Type v} [HasSizeof Ξ±] [HasSizeof Ξ²] : (Sum Ξ± Ξ²) β Nat
| Sum.inl a => 1 + sizeof a
| Sum.inr b => 1 + sizeof b
instance (Ξ± : Type u) (Ξ² : Type v) [HasSizeof Ξ±] [HasSizeof Ξ²] : HasSizeof (Sum Ξ± Ξ²) :=
β¨Sum.sizeofβ©
protected def PSum.sizeof {Ξ± : Type u} {Ξ² : Type v} [HasSizeof Ξ±] [HasSizeof Ξ²] : (PSum Ξ± Ξ²) β Nat
| PSum.inl a => 1 + sizeof a
| PSum.inr b => 1 + sizeof b
instance (Ξ± : Type u) (Ξ² : Type v) [HasSizeof Ξ±] [HasSizeof Ξ²] : HasSizeof (PSum Ξ± Ξ²) :=
β¨PSum.sizeofβ©
protected def Sigma.sizeof {Ξ± : Type u} {Ξ² : Ξ± β Type v} [HasSizeof Ξ±] [β a, HasSizeof (Ξ² a)] : Sigma Ξ² β Nat
| β¨a, bβ© => 1 + sizeof a + sizeof b
instance (Ξ± : Type u) (Ξ² : Ξ± β Type v) [HasSizeof Ξ±] [β a, HasSizeof (Ξ² a)] : HasSizeof (Sigma Ξ²) :=
β¨Sigma.sizeofβ©
protected def PSigma.sizeof {Ξ± : Type u} {Ξ² : Ξ± β Type v} [HasSizeof Ξ±] [β a, HasSizeof (Ξ² a)] : PSigma Ξ² β Nat
| β¨a, bβ© => 1 + sizeof a + sizeof b
instance (Ξ± : Type u) (Ξ² : Ξ± β Type v) [HasSizeof Ξ±] [β a, HasSizeof (Ξ² a)] : HasSizeof (PSigma Ξ²) :=
β¨PSigma.sizeofβ©
protected def PUnit.sizeof : PUnit β Nat
| u => 1
instance : HasSizeof PUnit := β¨PUnit.sizeofβ©
protected def Bool.sizeof : Bool β Nat
| b => 1
instance : HasSizeof Bool := β¨Bool.sizeofβ©
protected def Option.sizeof {Ξ± : Type u} [HasSizeof Ξ±] : Option Ξ± β Nat
| none => 1
| some a => 1 + sizeof a
instance (Ξ± : Type u) [HasSizeof Ξ±] : HasSizeof (Option Ξ±) :=
β¨Option.sizeofβ©
protected def List.sizeof {Ξ± : Type u} [HasSizeof Ξ±] : List Ξ± β Nat
| List.nil => 1
| List.cons a l => 1 + sizeof a + List.sizeof l
instance (Ξ± : Type u) [HasSizeof Ξ±] : HasSizeof (List Ξ±) :=
β¨List.sizeofβ©
protected def Subtype.sizeof {Ξ± : Type u} [HasSizeof Ξ±] {p : Ξ± β Prop} : Subtype p β Nat
| β¨a, _β© => sizeof a
instance {Ξ± : Type u} [HasSizeof Ξ±] (p : Ξ± β Prop) : HasSizeof (Subtype p) :=
β¨Subtype.sizeofβ©
theorem natAddZero (n : Nat) : n + 0 = n := rfl
theorem optParamEq (Ξ± : Sort u) (default : Ξ±) : optParam Ξ± default = Ξ± := rfl
/-- Like `by applyInstance`, but not dependent on the tactic framework. -/
@[reducible] def inferInstance {Ξ± : Type u} [i : Ξ±] : Ξ± := i
@[reducible, elabSimple] def inferInstanceAs (Ξ± : Type u) [i : Ξ±] : Ξ± := i
/- Boolean operators -/
@[macroInline] def cond {a : Type u} : Bool β a β a β a
| true, x, y => x
| false, x, y => y
@[inline] def condEq {Ξ² : Sort u} (b : Bool) (hβ : b = true β Ξ²) (hβ : b = false β Ξ²) : Ξ² :=
@Bool.casesOn (Ξ» x => b = x β Ξ²) b hβ hβ rfl
@[macroInline] def or : Bool β Bool β Bool
| true, _ => true
| false, b => b
@[macroInline] def and : Bool β Bool β Bool
| false, _ => false
| true, b => b
@[macroInline] def not : Bool β Bool
| true => false
| false => true
@[macroInline] def xor : Bool β Bool β Bool
| true, b => not b
| false, b => b
prefix `!` := not
infix `||` := or
infix `&&` := and
@[extern c inline "#1 || #2"] def strictOr (bβ bβ : Bool) := bβ || bβ
@[extern c inline "#1 && #2"] def strictAnd (bβ bβ : Bool) := bβ && bβ
@[inline] def bne {Ξ± : Type u} [HasBeq Ξ±] (a b : Ξ±) : Bool :=
!(a == b)
infix `!=` := bne
/- Logical connectives an equality -/
def implies (a b : Prop) := a β b
theorem implies.trans {p q r : Prop} (hβ : implies p q) (hβ : implies q r) : implies p r :=
fun hp => hβ (hβ hp)
def trivial : True := β¨β©
@[macroInline] def False.elim {C : Sort u} (h : False) : C :=
False.rec (fun _ => C) h
@[macroInline] def absurd {a : Prop} {b : Sort v} (hβ : a) (hβ : Β¬a) : b :=
False.elim (hβ hβ)
theorem mt {a b : Prop} (hβ : a β b) (hβ : Β¬b) : Β¬a :=
fun ha => hβ (hβ ha)
theorem notFalse : Β¬False := id
-- proof irrelevance is built in
theorem proofIrrel {a : Prop} (hβ hβ : a) : hβ = hβ := rfl
theorem id.def {Ξ± : Sort u} (a : Ξ±) : id a = a := rfl
@[macroInline] def Eq.mp {Ξ± Ξ² : Sort u} (hβ : Ξ± = Ξ²) (hβ : Ξ±) : Ξ² :=
Eq.recOn hβ hβ
@[macroInline] def Eq.mpr {Ξ± Ξ² : Sort u} : (Ξ± = Ξ²) β Ξ² β Ξ± :=
fun hβ hβ => Eq.recOn (Eq.symm hβ) hβ
@[elabAsEliminator]
theorem Eq.substr {Ξ± : Sort u} {p : Ξ± β Prop} {a b : Ξ±} (hβ : b = a) (hβ : p a) : p b :=
Eq.subst (Eq.symm hβ) hβ
theorem congr {Ξ± : Sort u} {Ξ² : Sort v} {fβ fβ : Ξ± β Ξ²} {aβ aβ : Ξ±} (hβ : fβ = fβ) (hβ : aβ = aβ) : fβ aβ = fβ aβ :=
Eq.subst hβ (Eq.subst hβ rfl)
theorem congrFun {Ξ± : Sort u} {Ξ² : Ξ± β Sort v} {f g : β x, Ξ² x} (h : f = g) (a : Ξ±) : f a = g a :=
Eq.subst h (Eq.refl (f a))
theorem congrArg {Ξ± : Sort u} {Ξ² : Sort v} {aβ aβ : Ξ±} (f : Ξ± β Ξ²) (h : aβ = aβ) : f aβ = f aβ :=
congr rfl h
theorem transRelLeft {Ξ± : Sort u} {a b c : Ξ±} (r : Ξ± β Ξ± β Prop) (hβ : r a b) (hβ : b = c) : r a c :=
hβ βΈ hβ
theorem transRelRight {Ξ± : Sort u} {a b c : Ξ±} (r : Ξ± β Ξ± β Prop) (hβ : a = b) (hβ : r b c) : r a c :=
hβ.symm βΈ hβ
theorem ofEqTrue {p : Prop} (h : p = True) : p :=
h.symm βΈ trivial
theorem notOfEqFalse {p : Prop} (h : p = False) : Β¬p :=
fun hp => h βΈ hp
@[macroInline] def cast {Ξ± Ξ² : Sort u} (h : Ξ± = Ξ²) (a : Ξ±) : Ξ² :=
Eq.rec a h
theorem castProofIrrel {Ξ± Ξ² : Sort u} (hβ hβ : Ξ± = Ξ²) (a : Ξ±) : cast hβ a = cast hβ a := rfl
theorem castEq {Ξ± : Sort u} (h : Ξ± = Ξ±) (a : Ξ±) : cast h a = a := rfl
@[reducible] def Ne {Ξ± : Sort u} (a b : Ξ±) := Β¬(a = b)
infix `β ` := Ne
theorem Ne.def {Ξ± : Sort u} (a b : Ξ±) : a β b = Β¬ (a = b) := rfl
section Ne
variable {Ξ± : Sort u}
variables {a b : Ξ±} {p : Prop}
theorem Ne.intro (h : a = b β False) : a β b := h
theorem Ne.elim (h : a β b) : a = b β False := h
theorem Ne.irrefl (h : a β a) : False := h rfl
theorem Ne.symm (h : a β b) : b β a :=
fun hβ => h (hβ.symm)
theorem falseOfNe : a β a β False := Ne.irrefl
theorem neFalseOfSelf : p β p β False :=
fun (hp : p) (h : p = False) => h βΈ hp
theorem neTrueOfNot : Β¬p β p β True :=
fun (hnp : Β¬p) (h : p = True) => (h βΈ hnp) trivial
theorem trueNeFalse : Β¬True = False :=
neFalseOfSelf trivial
end Ne
theorem eqFalseOfNeTrue : β {b : Bool}, b β true β b = false
| true, h => False.elim (h rfl)
| false, h => rfl
theorem eqTrueOfNeFalse : β {b : Bool}, b β false β b = true
| true, h => rfl
| false, h => False.elim (h rfl)
theorem neFalseOfEqTrue : β {b : Bool}, b = true β b β false
| true, _ => fun h => Bool.noConfusion h
| false, h => Bool.noConfusion h
theorem neTrueOfEqFalse : β {b : Bool}, b = false β b β true
| true, h => Bool.noConfusion h
| false, _ => fun h => Bool.noConfusion h
section
variables {Ξ± Ξ² Ο : Sort u} {a a' : Ξ±} {b b' : Ξ²} {c : Ο}
@[elabAsEliminator]
theorem HEq.ndrec.{u1, u2} {Ξ± : Sort u2} {a : Ξ±} {C : β {Ξ² : Sort u2}, Ξ² β Sort u1} (m : C a) {Ξ² : Sort u2} {b : Ξ²} (h : a β
b) : C b :=
@HEq.rec Ξ± a (fun Ξ² b _ => C b) m Ξ² b h
@[elabAsEliminator]
theorem HEq.ndrecOn.{u1, u2} {Ξ± : Sort u2} {a : Ξ±} {C : β {Ξ² : Sort u2}, Ξ² β Sort u1} {Ξ² : Sort u2} {b : Ξ²} (h : a β
b) (m : C a) : C b :=
@HEq.rec Ξ± a (fun Ξ² b _ => C b) m Ξ² b h
theorem HEq.elim {Ξ± : Sort u} {a : Ξ±} {p : Ξ± β Sort v} {b : Ξ±} (hβ : a β
b) (hβ : p a) : p b :=
Eq.recOn (eqOfHEq hβ) hβ
theorem HEq.subst {p : β (T : Sort u), T β Prop} (hβ : a β
b) (hβ : p Ξ± a) : p Ξ² b :=
HEq.ndrecOn hβ hβ
theorem HEq.symm (h : a β
b) : b β
a :=
HEq.ndrecOn h (HEq.refl a)
theorem heqOfEq (h : a = a') : a β
a' :=
Eq.subst h (HEq.refl a)
theorem HEq.trans (hβ : a β
b) (hβ : b β
c) : a β
c :=
HEq.subst hβ hβ
theorem heqOfHEqOfEq (hβ : a β
b) (hβ : b = b') : a β
b' :=
HEq.trans hβ (heqOfEq hβ)
theorem heqOfEqOfHEq (hβ : a = a') (hβ : a' β
b) : a β
b :=
HEq.trans (heqOfEq hβ) hβ
def typeEqOfHEq (h : a β
b) : Ξ± = Ξ² :=
HEq.ndrecOn h (Eq.refl Ξ±)
end
theorem eqRecHEq {Ξ± : Sort u} {Ο : Ξ± β Sort v} : β {a a' : Ξ±} (h : a = a') (p : Ο a), (Eq.recOn h p : Ο a') β
p
| a, _, rfl, p => HEq.refl p
theorem ofHEqTrue {a : Prop} (h : a β
True) : a :=
ofEqTrue (eqOfHEq h)
theorem castHEq : β {Ξ± Ξ² : Sort u} (h : Ξ± = Ξ²) (a : Ξ±), cast h a β
a
| Ξ±, _, rfl, a => HEq.refl a
variables {a b c d : Prop}
theorem And.elim (hβ : a β§ b) (hβ : a β b β c) : c :=
And.rec hβ hβ
theorem And.swap : a β§ b β b β§ a :=
fun β¨ha, hbβ© => β¨hb, haβ©
def And.symm := @And.swap
theorem Or.elim (hβ : a β¨ b) (hβ : a β c) (hβ : b β c) : c :=
Or.rec hβ hβ hβ
theorem Or.swap (h : a β¨ b) : b β¨ a :=
Or.elim h Or.inr Or.inl
def Or.symm := @Or.swap
/- xor -/
def Xor (a b : Prop) : Prop := (a β§ Β¬ b) β¨ (b β§ Β¬ a)
@[recursor 5]
theorem Iff.elim (hβ : (a β b) β (b β a) β c) (hβ : a β b) : c :=
Iff.rec hβ hβ
theorem Iff.left : (a β b) β a β b := Iff.mp
theorem Iff.right : (a β b) β b β a := Iff.mpr
theorem iffIffImpliesAndImplies (a b : Prop) : (a β b) β (a β b) β§ (b β a) :=
Iff.intro (fun h => And.intro h.mp h.mpr) (fun h => Iff.intro h.left h.right)
theorem Iff.refl (a : Prop) : a β a :=
Iff.intro (fun h => h) (fun h => h)
theorem Iff.rfl {a : Prop} : a β a :=
Iff.refl a
theorem Iff.trans (hβ : a β b) (hβ : b β c) : a β c :=
Iff.intro
(fun ha => Iff.mp hβ (Iff.mp hβ ha))
(fun hc => Iff.mpr hβ (Iff.mpr hβ hc))
theorem Iff.symm (h : a β b) : b β a :=
Iff.intro (Iff.right h) (Iff.left h)
theorem Iff.comm : (a β b) β (b β a) :=
Iff.intro Iff.symm Iff.symm
theorem Eq.toIff {a b : Prop} (h : a = b) : a β b :=
Eq.recOn h Iff.rfl
theorem neqOfNotIff {a b : Prop} : Β¬(a β b) β a β b :=
fun hβ hβ =>
have a β b from Eq.subst hβ (Iff.refl a);
absurd this hβ
theorem notIffNotOfIff (hβ : a β b) : Β¬a β Β¬b :=
Iff.intro
(fun (hna : Β¬ a) (hb : b) => hna (Iff.right hβ hb))
(fun (hnb : Β¬ b) (ha : a) => hnb (Iff.left hβ ha))
theorem ofIffTrue (h : a β True) : a :=
Iff.mp (Iff.symm h) trivial
theorem notOfIffFalse : (a β False) β Β¬a := Iff.mp
theorem iffTrueIntro (h : a) : a β True :=
Iff.intro
(fun hl => trivial)
(fun hr => h)
theorem iffFalseIntro (h : Β¬a) : a β False :=
Iff.intro h (False.rec (fun _ => a))
theorem notNotIntro (ha : a) : ¬¬a :=
fun hna => hna ha
theorem notTrue : (Β¬ True) β False :=
iffFalseIntro (notNotIntro trivial)
/- or resolution rulses -/
theorem resolveLeft {a b : Prop} (h : a β¨ b) (na : Β¬ a) : b :=
Or.elim h (fun ha => absurd ha na) id
theorem negResolveLeft {a b : Prop} (h : Β¬ a β¨ b) (ha : a) : b :=
Or.elim h (fun na => absurd ha na) id
theorem resolveRight {a b : Prop} (h : a β¨ b) (nb : Β¬ b) : a :=
Or.elim h id (fun hb => absurd hb nb)
theorem negResolveRight {a b : Prop} (h : a β¨ Β¬ b) (hb : b) : a :=
Or.elim h id (fun nb => absurd hb nb)
/- Exists -/
theorem Exists.elim {Ξ± : Sort u} {p : Ξ± β Prop} {b : Prop}
(hβ : Exists (fun x => p x)) (hβ : β (a : Ξ±), p a β b) : b :=
Exists.rec hβ hβ
/- Decidable -/
@[inlineIfReduce, nospecialize] def Decidable.decide (p : Prop) [h : Decidable p] : Bool :=
Decidable.casesOn h (fun hβ => false) (fun hβ => true)
export Decidable (isTrue isFalse decide)
instance beqOfEq {Ξ± : Type u} [DecidableEq Ξ±] : HasBeq Ξ± :=
β¨fun a b => decide (a = b)β©
theorem decideTrueEqTrue (h : Decidable True) : @decide True h = true :=
match h with
| isTrue h => rfl
| isFalse h => False.elim (Iff.mp notTrue h)
theorem decideFalseEqFalse (h : Decidable False) : @decide False h = false :=
match h with
| isFalse h => rfl
| isTrue h => False.elim h
theorem decideEqTrue : β {p : Prop} [s : Decidable p], p β decide p = true
| _, isTrue _, _ => rfl
| _, isFalse hβ, hβ => absurd hβ hβ
theorem decideEqFalse : β {p : Prop} [s : Decidable p], Β¬p β decide p = false
| _, isTrue hβ, hβ => absurd hβ hβ
| _, isFalse h, _ => rfl
theorem ofDecideEqTrue {p : Prop} [s : Decidable p] : decide p = true β p :=
fun h => match s with
| isTrue hβ => hβ
| isFalse hβ => absurd h (neTrueOfEqFalse (decideEqFalse hβ))
theorem ofDecideEqFalse {p : Prop} [s : Decidable p] : decide p = false β Β¬p :=
fun h => match s with
| isTrue hβ => absurd h (neFalseOfEqTrue (decideEqTrue hβ))
| isFalse hβ => hβ
/-- Similar to `decide`, but uses an explicit instance -/
@[inline] def toBoolUsing {p : Prop} (d : Decidable p) : Bool :=
@decide p d
theorem toBoolUsingEqTrue {p : Prop} (d : Decidable p) (h : p) : toBoolUsing d = true :=
@decideEqTrue _ d h
theorem ofBoolUsingEqTrue {p : Prop} {d : Decidable p} (h : toBoolUsing d = true) : p :=
@ofDecideEqTrue _ d h
theorem ofBoolUsingEqFalse {p : Prop} {d : Decidable p} (h : toBoolUsing d = false) : Β¬ p :=
@ofDecideEqFalse _ d h
instance : Decidable True :=
isTrue trivial
instance : Decidable False :=
isFalse notFalse
-- We use "dependent" if-then-else to be able to communicate the if-then-else condition
-- to the branches
@[macroInline] def dite {Ξ± : Sort u} (c : Prop) [h : Decidable c] : (c β Ξ±) β (Β¬ c β Ξ±) β Ξ± :=
fun t e => Decidable.casesOn h e t
/- if-then-else -/
@[macroInline] def ite {Ξ± : Sort u} (c : Prop) [h : Decidable c] (t e : Ξ±) : Ξ± :=
Decidable.casesOn h (fun hnc => e) (fun hc => t)
namespace Decidable
variables {p q : Prop}
def recOnTrue [h : Decidable p] {hβ : p β Sort u} {hβ : Β¬p β Sort u} (hβ : p) (hβ : hβ hβ)
: (Decidable.recOn h hβ hβ : Sort u) :=
Decidable.casesOn h (fun h => False.rec _ (h hβ)) (fun h => hβ)
def recOnFalse [h : Decidable p] {hβ : p β Sort u} {hβ : Β¬p β Sort u} (hβ : Β¬p) (hβ : hβ hβ)
: (Decidable.recOn h hβ hβ : Sort u) :=
Decidable.casesOn h (fun h => hβ) (fun h => False.rec _ (hβ h))
@[macroInline] def byCases {q : Sort u} [s : Decidable p] (h1 : p β q) (h2 : Β¬p β q) : q :=
match s with
| isTrue h => h1 h
| isFalse h => h2 h
theorem em (p : Prop) [Decidable p] : p β¨ Β¬p :=
byCases Or.inl Or.inr
theorem byContradiction [Decidable p] (h : Β¬p β False) : p :=
byCases id (fun np => False.elim (h np))
theorem ofNotNot [Decidable p] : Β¬ Β¬ p β p :=
fun hnn => byContradiction (fun hn => absurd hn hnn)
theorem notNotIff (p) [Decidable p] : (Β¬ Β¬ p) β p :=
Iff.intro ofNotNot notNotIntro
theorem notAndIffOrNot (p q : Prop) [dβ : Decidable p] [dβ : Decidable q] : Β¬ (p β§ q) β Β¬ p β¨ Β¬ q :=
Iff.intro
(fun h => match dβ, dβ with
| isTrue hβ, isTrue hβ => absurd (And.intro hβ hβ) h
| _, isFalse hβ => Or.inr hβ
| isFalse hβ, _ => Or.inl hβ)
(fun (h) β¨hp, hqβ© => Or.elim h (fun h => h hp) (fun h => h hq))
end Decidable
section
variables {p q : Prop}
@[inline] def decidableOfDecidableOfIff (hp : Decidable p) (h : p β q) : Decidable q :=
if hp : p then isTrue (Iff.mp h hp)
else isFalse (Iff.mp (notIffNotOfIff h) hp)
@[inline] def decidableOfDecidableOfEq (hp : Decidable p) (h : p = q) : Decidable q :=
decidableOfDecidableOfIff hp h.toIff
end
section
variables {p q : Prop}
@[macroInline] instance [Decidable p] [Decidable q] : Decidable (p β§ q) :=
if hp : p then
if hq : q then isTrue β¨hp, hqβ©
else isFalse (fun h => hq (And.right h))
else isFalse (fun h => hp (And.left h))
@[macroInline] instance [Decidable p] [Decidable q] : Decidable (p β¨ q) :=
if hp : p then isTrue (Or.inl hp) else
if hq : q then isTrue (Or.inr hq) else
isFalse (fun h => Or.elim h hp hq)
instance [Decidable p] : Decidable (Β¬p) :=
if hp : p then isFalse (absurd hp) else isTrue hp
@[macroInline] instance implies.Decidable [Decidable p] [Decidable q] : Decidable (p β q) :=
if hp : p then
if hq : q then isTrue (fun h => hq)
else isFalse (fun h => absurd (h hp) hq)
else isTrue (fun h => absurd h hp)
instance [Decidable p] [Decidable q] : Decidable (p β q) :=
if hp : p then
if hq : q then isTrue β¨fun _ => hq, fun _ => hpβ©
else isFalse $ fun h => hq (h.1 hp)
else
if hq : q then isFalse $ fun h => hp (h.2 hq)
else isTrue $ β¨fun h => absurd h hp, fun h => absurd h hqβ©
instance [Decidable p] [Decidable q] : Decidable (Xor p q) :=
if hp : p then
if hq : q then isFalse (fun h => Or.elim h (fun β¨_, hβ© => h hq : Β¬(p β§ Β¬ q)) (fun β¨_, hβ© => h hp : Β¬(q β§ Β¬ p)))
else isTrue $ Or.inl β¨hp, hqβ©
else
if hq : q then isTrue $ Or.inr β¨hq, hpβ©
else isFalse (fun h => Or.elim h (fun β¨h, _β© => hp h : Β¬(p β§ Β¬ q)) (fun β¨h, _β© => hq h : Β¬(q β§ Β¬ p)))
end
@[inline] instance {Ξ± : Sort u} [DecidableEq Ξ±] (a b : Ξ±) : Decidable (a β b) :=
match decEq a b with
| isTrue h => isFalse $ fun h' => absurd h h'
| isFalse h => isTrue h
theorem Bool.falseNeTrue (h : false = true) : False :=
Bool.noConfusion h
@[inline] instance : DecidableEq Bool :=
fun a b => match a, b with
| false, false => isTrue rfl
| false, true => isFalse Bool.falseNeTrue
| true, false => isFalse (Ne.symm Bool.falseNeTrue)
| true, true => isTrue rfl
/- if-then-else expression theorems -/
theorem ifPos {c : Prop} [h : Decidable c] (hc : c) {Ξ± : Sort u} {t e : Ξ±} : (ite c t e) = t :=
match h with
| (isTrue hc) => rfl
| (isFalse hnc) => absurd hc hnc
theorem ifNeg {c : Prop} [h : Decidable c] (hnc : Β¬c) {Ξ± : Sort u} {t e : Ξ±} : (ite c t e) = e :=
match h with
| (isTrue hc) => absurd hc hnc
| (isFalse hnc) => rfl
theorem difPos {c : Prop} [h : Decidable c] (hc : c) {Ξ± : Sort u} {t : c β Ξ±} {e : Β¬ c β Ξ±} : (dite c t e) = t hc :=
match h with
| (isTrue hc) => rfl
| (isFalse hnc) => absurd hc hnc
theorem difNeg {c : Prop} [h : Decidable c] (hnc : Β¬c) {Ξ± : Sort u} {t : c β Ξ±} {e : Β¬ c β Ξ±} : (dite c t e) = e hnc :=
match h with
| (isTrue hc) => absurd hc hnc
| (isFalse hnc) => rfl
-- Remark: dite and ite are "defally equal" when we ignore the proofs.
theorem difEqIf (c : Prop) [h : Decidable c] {Ξ± : Sort u} (t : Ξ±) (e : Ξ±) : dite c (fun h => t) (fun h => e) = ite c t e :=
match h with
| (isTrue hc) => rfl
| (isFalse hnc) => rfl
instance {c t e : Prop} [dC : Decidable c] [dT : Decidable t] [dE : Decidable e] : Decidable (if c then t else e) :=
match dC with
| (isTrue hc) => dT
| (isFalse hc) => dE
instance {c : Prop} {t : c β Prop} {e : Β¬c β Prop} [dC : Decidable c] [dT : β h, Decidable (t h)] [dE : β h, Decidable (e h)] : Decidable (if h : c then t h else e h) :=
match dC with
| (isTrue hc) => dT hc
| (isFalse hc) => dE hc
/-- Universe lifting operation -/
structure ULift.{r, s} (Ξ± : Type s) : Type (max s r) :=
up :: (down : Ξ±)
namespace ULift
/- Bijection between Ξ± and ULift.{v} Ξ± -/
theorem upDown {Ξ± : Type u} : β (b : ULift.{v} Ξ±), up (down b) = b
| up a => rfl
theorem downUp {Ξ± : Type u} (a : Ξ±) : down (up.{v} a) = a := rfl
end ULift
/-- Universe lifting operation from Sort to Type -/
structure PLift (Ξ± : Sort u) : Type u :=
up :: (down : Ξ±)
namespace PLift
/- Bijection between Ξ± and PLift Ξ± -/
theorem upDown {Ξ± : Sort u} : β (b : PLift Ξ±), up (down b) = b
| up a => rfl
theorem downUp {Ξ± : Sort u} (a : Ξ±) : down (up a) = a := rfl
end PLift
/- pointed types -/
structure PointedType :=
(type : Type u) (val : type)
/- Inhabited -/
class Inhabited (Ξ± : Sort u) :=
mk {} :: (default : Ξ±)
constant arbitrary (Ξ± : Sort u) [Inhabited Ξ±] : Ξ± :=
Inhabited.default Ξ±
instance Prop.Inhabited : Inhabited Prop :=
β¨Trueβ©
instance Fun.Inhabited (Ξ± : Sort u) {Ξ² : Sort v} [h : Inhabited Ξ²] : Inhabited (Ξ± β Ξ²) :=
Inhabited.casesOn h (fun b => β¨fun a => bβ©)
instance Forall.Inhabited (Ξ± : Sort u) {Ξ² : Ξ± β Sort v} [β x, Inhabited (Ξ² x)] : Inhabited (β x, Ξ² x) :=
β¨fun a => arbitrary (Ξ² a)β©
instance : Inhabited Bool := β¨falseβ©
instance : Inhabited True := β¨trivialβ©
instance : Inhabited Nat := β¨0β©
instance : Inhabited NonScalar := β¨β¨arbitrary _β©β©
instance : Inhabited PNonScalar.{u} := β¨β¨arbitrary _β©β©
instance : Inhabited PointedType := β¨{type := PUnit, val := β¨β©}β©
class inductive Nonempty (Ξ± : Sort u) : Prop
| intro (val : Ξ±) : Nonempty
protected def Nonempty.elim {Ξ± : Sort u} {p : Prop} (hβ : Nonempty Ξ±) (hβ : Ξ± β p) : p :=
Nonempty.rec hβ hβ
instance nonemptyOfInhabited {Ξ± : Sort u} [Inhabited Ξ±] : Nonempty Ξ± :=
β¨arbitrary Ξ±β©
theorem nonemptyOfExists {Ξ± : Sort u} {p : Ξ± β Prop} : Exists (fun x => p x) β Nonempty Ξ±
| β¨w, hβ© => β¨wβ©
/- Subsingleton -/
class inductive Subsingleton (Ξ± : Sort u) : Prop
| intro (h : β (a b : Ξ±), a = b) : Subsingleton
protected def Subsingleton.elim {Ξ± : Sort u} [h : Subsingleton Ξ±] : β (a b : Ξ±), a = b :=
Subsingleton.casesOn h (fun p => p)
protected def Subsingleton.helim {Ξ± Ξ² : Sort u} [h : Subsingleton Ξ±] (h : Ξ± = Ξ²) : β (a : Ξ±) (b : Ξ²), a β
b :=
Eq.recOn h (fun a b => heqOfEq (Subsingleton.elim a b))
instance subsingletonProp (p : Prop) : Subsingleton p :=
β¨fun a b => proofIrrel a bβ©
instance (p : Prop) : Subsingleton (Decidable p) :=
Subsingleton.intro $ fun dβ =>
match dβ with
| (isTrue tβ) => fun dβ =>
match dβ with
| (isTrue tβ) => Eq.recOn (proofIrrel tβ tβ) rfl
| (isFalse fβ) => absurd tβ fβ
| (isFalse fβ) => fun dβ =>
match dβ with
| (isTrue tβ) => absurd tβ fβ
| (isFalse fβ) => Eq.recOn (proofIrrel fβ fβ) rfl
protected theorem recSubsingleton {p : Prop} [h : Decidable p] {hβ : p β Sort u} {hβ : Β¬p β Sort u}
[hβ : β (h : p), Subsingleton (hβ h)] [hβ : β (h : Β¬p), Subsingleton (hβ h)]
: Subsingleton (Decidable.casesOn h hβ hβ) :=
match h with
| (isTrue h) => hβ h
| (isFalse h) => hβ h
section relation
variables {Ξ± : Sort u} {Ξ² : Sort v} (r : Ξ² β Ξ² β Prop)
def Reflexive := β x, r x x
def Symmetric := β {x y}, r x y β r y x
def Transitive := β {x y z}, r x y β r y z β r x z
def Equivalence := Reflexive r β§ Symmetric r β§ Transitive r
def Total := β x y, r x y β¨ r y x
def mkEquivalence (rfl : Reflexive r) (symm : Symmetric r) (trans : Transitive r) : Equivalence r :=
β¨rfl, @symm, @transβ©
def Irreflexive := β x, Β¬ r x x
def AntiSymmetric := β {x y}, r x y β r y x β x = y
def emptyRelation (aβ aβ : Ξ±) : Prop := False
def Subrelation (q r : Ξ² β Ξ² β Prop) := β {x y}, q x y β r x y
def InvImage (f : Ξ± β Ξ²) : Ξ± β Ξ± β Prop :=
fun aβ aβ => r (f aβ) (f aβ)
theorem InvImage.Transitive (f : Ξ± β Ξ²) (h : Transitive r) : Transitive (InvImage r f) :=
fun (aβ aβ aβ : Ξ±) (hβ : InvImage r f aβ aβ) (hβ : InvImage r f aβ aβ) => h hβ hβ
theorem InvImage.Irreflexive (f : Ξ± β Ξ²) (h : Irreflexive r) : Irreflexive (InvImage r f) :=
fun (a : Ξ±) (hβ : InvImage r f a a) => h (f a) hβ
inductive TC {Ξ± : Sort u} (r : Ξ± β Ξ± β Prop) : Ξ± β Ξ± β Prop
| base : β a b, r a b β TC a b
| trans : β a b c, TC a b β TC b c β TC a c
@[elabAsEliminator]
theorem TC.ndrec.{u1, u2} {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {C : Ξ± β Ξ± β Prop}
(mβ : β (a b : Ξ±), r a b β C a b)
(mβ : β (a b c : Ξ±), TC r a b β TC r b c β C a b β C b c β C a c)
{a b : Ξ±} (h : TC r a b) : C a b :=
@TC.rec Ξ± r (fun a b _ => C a b) mβ mβ a b h
@[elabAsEliminator]
theorem TC.ndrecOn.{u1, u2} {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {C : Ξ± β Ξ± β Prop}
{a b : Ξ±} (h : TC r a b)
(mβ : β (a b : Ξ±), r a b β C a b)
(mβ : β (a b c : Ξ±), TC r a b β TC r b c β C a b β C b c β C a c)
: C a b :=
@TC.rec Ξ± r (fun a b _ => C a b) mβ mβ a b h
end relation
section Binary
variables {Ξ± : Type u} {Ξ² : Type v}
variable (f : Ξ± β Ξ± β Ξ±)
def Commutative := β a b, f a b = f b a
def Associative := β a b c, f (f a b) c = f a (f b c)
def RightCommutative (h : Ξ² β Ξ± β Ξ²) := β b aβ aβ, h (h b aβ) aβ = h (h b aβ) aβ
def LeftCommutative (h : Ξ± β Ξ² β Ξ²) := β aβ aβ b, h aβ (h aβ b) = h aβ (h aβ b)
theorem leftComm : Commutative f β Associative f β LeftCommutative f :=
fun hcomm hassoc a b c =>
((Eq.symm (hassoc a b c)).trans (hcomm a b βΈ rfl : f (f a b) c = f (f b a) c)).trans (hassoc b a c)
theorem rightComm : Commutative f β Associative f β RightCommutative f :=
fun hcomm hassoc a b c =>
((hassoc a b c).trans (hcomm b c βΈ rfl : f a (f b c) = f a (f c b))).trans (Eq.symm (hassoc a c b))
end Binary
/- Subtype -/
namespace Subtype
def existsOfSubtype {Ξ± : Type u} {p : Ξ± β Prop} : { x // p x } β Exists (fun x => p x)
| β¨a, hβ© => β¨a, hβ©
variables {Ξ± : Type u} {p : Ξ± β Prop}
theorem tagIrrelevant {a : Ξ±} (h1 h2 : p a) : mk a h1 = mk a h2 :=
rfl
protected theorem eq : β {a1 a2 : {x // p x}}, val a1 = val a2 β a1 = a2
| β¨x, h1β©, β¨.(x), h2β©, rfl => rfl
theorem eta (a : {x // p x}) (h : p (val a)) : mk (val a) h = a :=
Subtype.eq rfl
instance {Ξ± : Type u} {p : Ξ± β Prop} {a : Ξ±} (h : p a) : Inhabited {x // p x} :=
β¨β¨a, hβ©β©
instance {Ξ± : Type u} {p : Ξ± β Prop} [DecidableEq Ξ±] : DecidableEq {x : Ξ± // p x} :=
fun β¨a, hββ© β¨b, hββ© =>
if h : a = b then isTrue (Subtype.eq h)
else isFalse (fun h' => Subtype.noConfusion h' (fun h' => absurd h' h))
end Subtype
/- Sum -/
section
variables {Ξ± : Type u} {Ξ² : Type v}
instance Sum.inhabitedLeft [h : Inhabited Ξ±] : Inhabited (Sum Ξ± Ξ²) :=
β¨Sum.inl (arbitrary Ξ±)β©
instance Sum.inhabitedRight [h : Inhabited Ξ²] : Inhabited (Sum Ξ± Ξ²) :=
β¨Sum.inr (arbitrary Ξ²)β©
instance {Ξ± : Type u} {Ξ² : Type v} [DecidableEq Ξ±] [DecidableEq Ξ²] : DecidableEq (Sum Ξ± Ξ²) :=
fun a b =>
match a, b with
| (Sum.inl a), (Sum.inl b) =>
if h : a = b then isTrue (h βΈ rfl)
else isFalse (fun h' => Sum.noConfusion h' (fun h' => absurd h' h))
| (Sum.inr a), (Sum.inr b) =>
if h : a = b then isTrue (h βΈ rfl)
else isFalse (fun h' => Sum.noConfusion h' (fun h' => absurd h' h))
| (Sum.inr a), (Sum.inl b) => isFalse (fun h => Sum.noConfusion h)
| (Sum.inl a), (Sum.inr b) => isFalse (fun h => Sum.noConfusion h)
end
/- Product -/
section
variables {Ξ± : Type u} {Ξ² : Type v}
instance [Inhabited Ξ±] [Inhabited Ξ²] : Inhabited (Prod Ξ± Ξ²) :=
β¨(arbitrary Ξ±, arbitrary Ξ²)β©
instance [DecidableEq Ξ±] [DecidableEq Ξ²] : DecidableEq (Ξ± Γ Ξ²) :=
fun β¨a, bβ© β¨a', b'β© =>
match (decEq a a') with
| (isTrue eβ) =>
match (decEq b b') with
| (isTrue eβ) => isTrue (Eq.recOn eβ (Eq.recOn eβ rfl))
| (isFalse nβ) => isFalse (fun h => Prod.noConfusion h (fun eβ' eβ' => absurd eβ' nβ))
| (isFalse nβ) => isFalse (fun h => Prod.noConfusion h (fun eβ' eβ' => absurd eβ' nβ))
instance [HasBeq Ξ±] [HasBeq Ξ²] : HasBeq (Ξ± Γ Ξ²) :=
β¨fun β¨aβ, bββ© β¨aβ, bββ© => aβ == aβ && bβ == bββ©
instance [HasLess Ξ±] [HasLess Ξ²] : HasLess (Ξ± Γ Ξ²) :=
β¨fun s t => s.1 < t.1 β¨ (s.1 = t.1 β§ s.2 < t.2)β©
instance prodHasDecidableLt
[HasLess Ξ±] [HasLess Ξ²] [DecidableEq Ξ±] [DecidableEq Ξ²]
[β (a b : Ξ±), Decidable (a < b)] [β (a b : Ξ²), Decidable (a < b)]
: β (s t : Ξ± Γ Ξ²), Decidable (s < t) :=
fun t s => Or.Decidable
theorem Prod.ltDef [HasLess Ξ±] [HasLess Ξ²] (s t : Ξ± Γ Ξ²) : (s < t) = (s.1 < t.1 β¨ (s.1 = t.1 β§ s.2 < t.2)) :=
rfl
end
def Prod.map.{uβ, uβ, vβ, vβ} {Ξ±β : Type uβ} {Ξ±β : Type uβ} {Ξ²β : Type vβ} {Ξ²β : Type vβ}
(f : Ξ±β β Ξ±β) (g : Ξ²β β Ξ²β) : Ξ±β Γ Ξ²β β Ξ±β Γ Ξ²β
| (a, b) => (f a, g b)
/- Dependent products -/
-- notation `Ξ£` binders `, ` r:(scoped p, Sigma p) := r
-- notation `Ξ£'` binders `, ` r:(scoped p, PSigma p) := r
theorem exOfPsig {Ξ± : Type u} {p : Ξ± β Prop} : (PSigma (fun x => p x)) β Exists (fun x => p x)
| β¨x, hxβ© => β¨x, hxβ©
section
variables {Ξ± : Type u} {Ξ² : Ξ± β Type v}
protected theorem Sigma.eq : β {pβ pβ : Sigma (fun a => Ξ² a)} (hβ : pβ.1 = pβ.1), (Eq.recOn hβ pβ.2 : Ξ² pβ.1) = pβ.2 β pβ = pβ
| β¨a, bβ©, β¨.(a), .(b)β©, rfl, rfl => rfl
end
section
variables {Ξ± : Sort u} {Ξ² : Ξ± β Sort v}
protected theorem PSigma.eq : β {pβ pβ : PSigma Ξ²} (hβ : pβ.1 = pβ.1), (Eq.recOn hβ pβ.2 : Ξ² pβ.1) = pβ.2 β pβ = pβ
| β¨a, bβ©, β¨.(a), .(b)β©, rfl, rfl => rfl
end
/- Universe polymorphic unit -/
theorem punitEq (a b : PUnit) : a = b :=
PUnit.recOn a (PUnit.recOn b rfl)
theorem punitEqPUnit (a : PUnit) : a = () :=
punitEq a ()
instance : Subsingleton PUnit :=
Subsingleton.intro punitEq
instance : Inhabited PUnit :=
β¨β¨β©β©
instance : DecidableEq PUnit :=
fun a b => isTrue (punitEq a b)
/- Setoid -/
class Setoid (Ξ± : Sort u) :=
(r : Ξ± β Ξ± β Prop) (iseqv {} : Equivalence r)
instance setoidHasEquiv {Ξ± : Sort u} [Setoid Ξ±] : HasEquiv Ξ± :=
β¨Setoid.rβ©
namespace Setoid
variables {Ξ± : Sort u} [Setoid Ξ±]
theorem refl (a : Ξ±) : a β a :=
match Setoid.iseqv Ξ± with
| β¨hRefl, hSymm, hTransβ© => hRefl a
theorem symm {a b : Ξ±} (hab : a β b) : b β a :=
match Setoid.iseqv Ξ± with
| β¨hRefl, hSymm, hTransβ© => hSymm hab
theorem trans {a b c : Ξ±} (hab : a β b) (hbc : b β c) : a β c :=
match Setoid.iseqv Ξ± with
| β¨hRefl, hSymm, hTransβ© => hTrans hab hbc
end Setoid
/- Propositional extensionality -/
axiom propext {a b : Prop} : (a β b) β a = b
theorem eqTrueIntro {a : Prop} (h : a) : a = True :=
propext (iffTrueIntro h)
theorem eqFalseIntro {a : Prop} (h : Β¬a) : a = False :=
propext (iffFalseIntro h)
/- Quotients -/
-- Iff can now be used to do substitutions in a calculation
theorem iffSubst {a b : Prop} {p : Prop β Prop} (hβ : a β b) (hβ : p a) : p b :=
Eq.subst (propext hβ) hβ
namespace Quot
axiom sound : β {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {a b : Ξ±}, r a b β Quot.mk r a = Quot.mk r b
attribute [elabAsEliminator] lift ind
protected theorem liftBeta {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {Ξ² : Sort v} (f : Ξ± β Ξ²) (c : β a b, r a b β f a = f b) (a : Ξ±) : lift f c (Quot.mk r a) = f a :=
rfl
protected theorem indBeta {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {Ξ² : Quot r β Prop} (p : β a, Ξ² (Quot.mk r a)) (a : Ξ±) : (ind p (Quot.mk r a) : Ξ² (Quot.mk r a)) = p a :=
rfl
@[reducible, elabAsEliminator, inline]
protected def liftOn {Ξ± : Sort u} {Ξ² : Sort v} {r : Ξ± β Ξ± β Prop} (q : Quot r) (f : Ξ± β Ξ²) (c : β a b, r a b β f a = f b) : Ξ² :=
lift f c q
@[elabAsEliminator]
protected theorem inductionOn {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} {Ξ² : Quot r β Prop} (q : Quot r) (h : β a, Ξ² (Quot.mk r a)) : Ξ² q :=
ind h q
theorem existsRep {Ξ± : Sort u} {r : Ξ± β Ξ± β Prop} (q : Quot r) : Exists (fun a => (Quot.mk r a) = q) :=
Quot.inductionOn q (fun a => β¨a, rflβ©)
section
variable {Ξ± : Sort u}
variable {r : Ξ± β Ξ± β Prop}
variable {Ξ² : Quot r β Sort v}
@[reducible, macroInline]
protected def indep (f : β a, Ξ² (Quot.mk r a)) (a : Ξ±) : PSigma Ξ² :=
β¨Quot.mk r a, f aβ©
protected theorem indepCoherent (f : β a, Ξ² (Quot.mk r a))
(h : β (a b : Ξ±) (p : r a b), (Eq.rec (f a) (sound p) : Ξ² (Quot.mk r b)) = f b)
: β a b, r a b β Quot.indep f a = Quot.indep f b :=
fun a b e => PSigma.eq (sound e) (h a b e)
protected theorem liftIndepPr1
(f : β a, Ξ² (Quot.mk r a)) (h : β (a b : Ξ±) (p : r a b), (Eq.rec (f a) (sound p) : Ξ² (Quot.mk r b)) = f b)
(q : Quot r) : (lift (Quot.indep f) (Quot.indepCoherent f h) q).1 = q :=
Quot.ind (fun (a : Ξ±) => Eq.refl (Quot.indep f a).1) q
@[reducible, elabAsEliminator, inline]
protected def rec
(f : β a, Ξ² (Quot.mk r a)) (h : β (a b : Ξ±) (p : r a b), (Eq.rec (f a) (sound p) : Ξ² (Quot.mk r b)) = f b)
(q : Quot r) : Ξ² q :=
Eq.ndrecOn (Quot.liftIndepPr1 f h q) ((lift (Quot.indep f) (Quot.indepCoherent f h) q).2)
@[reducible, elabAsEliminator, inline]
protected def recOn
(q : Quot r) (f : β a, Ξ² (Quot.mk r a)) (h : β (a b : Ξ±) (p : r a b), (Eq.rec (f a) (sound p) : Ξ² (Quot.mk r b)) = f b) : Ξ² q :=
Quot.rec f h q
@[reducible, elabAsEliminator, inline]
protected def recOnSubsingleton
[h : β a, Subsingleton (Ξ² (Quot.mk r a))] (q : Quot r) (f : β a, Ξ² (Quot.mk r a)) : Ξ² q :=
Quot.rec f (fun a b h => Subsingleton.elim _ (f b)) q
@[reducible, elabAsEliminator, inline]
protected def hrecOn
(q : Quot r) (f : β a, Ξ² (Quot.mk r a)) (c : β (a b : Ξ±) (p : r a b), f a β
f b) : Ξ² q :=
Quot.recOn q f $
fun a b p => eqOfHEq $
have pβ : (Eq.rec (f a) (sound p) : Ξ² (Quot.mk r b)) β
f a := eqRecHEq (sound p) (f a);
HEq.trans pβ (c a b p)
end
end Quot
def Quotient {Ξ± : Sort u} (s : Setoid Ξ±) :=
@Quot Ξ± Setoid.r
namespace Quotient
@[inline]
protected def mk {Ξ± : Sort u} [s : Setoid Ξ±] (a : Ξ±) : Quotient s :=
Quot.mk Setoid.r a
def sound {Ξ± : Sort u} [s : Setoid Ξ±] {a b : Ξ±} : a β b β Quotient.mk a = Quotient.mk b :=
Quot.sound
@[reducible, elabAsEliminator]
protected def lift {Ξ± : Sort u} {Ξ² : Sort v} [s : Setoid Ξ±] (f : Ξ± β Ξ²) : (β a b, a β b β f a = f b) β Quotient s β Ξ² :=
Quot.lift f
@[elabAsEliminator]
protected theorem ind {Ξ± : Sort u} [s : Setoid Ξ±] {Ξ² : Quotient s β Prop} : (β a, Ξ² (Quotient.mk a)) β β q, Ξ² q :=
Quot.ind
@[reducible, elabAsEliminator, inline]
protected def liftOn {Ξ± : Sort u} {Ξ² : Sort v} [s : Setoid Ξ±] (q : Quotient s) (f : Ξ± β Ξ²) (c : β a b, a β b β f a = f b) : Ξ² :=
Quot.liftOn q f c
@[elabAsEliminator]
protected theorem inductionOn {Ξ± : Sort u} [s : Setoid Ξ±] {Ξ² : Quotient s β Prop} (q : Quotient s) (h : β a, Ξ² (Quotient.mk a)) : Ξ² q :=
Quot.inductionOn q h
theorem existsRep {Ξ± : Sort u} [s : Setoid Ξ±] (q : Quotient s) : Exists (fun (a : Ξ±) => Quotient.mk a = q) :=
Quot.existsRep q
section
variable {Ξ± : Sort u}
variable [s : Setoid Ξ±]
variable {Ξ² : Quotient s β Sort v}
@[inline]
protected def rec
(f : β a, Ξ² (Quotient.mk a)) (h : β (a b : Ξ±) (p : a β b), (Eq.rec (f a) (Quotient.sound p) : Ξ² (Quotient.mk b)) = f b)
(q : Quotient s) : Ξ² q :=
Quot.rec f h q
@[reducible, elabAsEliminator, inline]
protected def recOn
(q : Quotient s) (f : β a, Ξ² (Quotient.mk a)) (h : β (a b : Ξ±) (p : a β b), (Eq.rec (f a) (Quotient.sound p) : Ξ² (Quotient.mk b)) = f b) : Ξ² q :=
Quot.recOn q f h
@[reducible, elabAsEliminator, inline]
protected def recOnSubsingleton
[h : β a, Subsingleton (Ξ² (Quotient.mk a))] (q : Quotient s) (f : β a, Ξ² (Quotient.mk a)) : Ξ² q :=
@Quot.recOnSubsingleton _ _ _ h q f
@[reducible, elabAsEliminator, inline]
protected def hrecOn
(q : Quotient s) (f : β a, Ξ² (Quotient.mk a)) (c : β (a b : Ξ±) (p : a β b), f a β
f b) : Ξ² q :=
Quot.hrecOn q f c
end
section
universes uA uB uC
variables {Ξ± : Sort uA} {Ξ² : Sort uB} {Ο : Sort uC}
variables [sβ : Setoid Ξ±] [sβ : Setoid Ξ²]
@[reducible, elabAsEliminator, inline]
protected def liftβ
(f : Ξ± β Ξ² β Ο)(c : β aβ aβ bβ bβ, aβ β bβ β aβ β bβ β f aβ aβ = f bβ bβ)
(qβ : Quotient sβ) (qβ : Quotient sβ) : Ο :=
Quotient.lift
(fun (aβ : Ξ±) => Quotient.lift (f aβ) (fun (a b : Ξ²) => c aβ a aβ b (Setoid.refl aβ)) qβ)
(fun (a b : Ξ±) (h : a β b) =>
@Quotient.ind Ξ² sβ
(fun (a1 : Quotient sβ) =>
(Quotient.lift (f a) (fun (a1 b : Ξ²) => c a a1 a b (Setoid.refl a)) a1)
=
(Quotient.lift (f b) (fun (a b1 : Ξ²) => c b a b b1 (Setoid.refl b)) a1))
(fun (a' : Ξ²) => c a a' b a' h (Setoid.refl a'))
qβ)
qβ
@[reducible, elabAsEliminator, inline]
protected def liftOnβ
(qβ : Quotient sβ) (qβ : Quotient sβ) (f : Ξ± β Ξ² β Ο) (c : β aβ aβ bβ bβ, aβ β bβ β aβ β bβ β f aβ aβ = f bβ bβ) : Ο :=
Quotient.liftβ f c qβ qβ
@[elabAsEliminator]
protected theorem indβ {Ο : Quotient sβ β Quotient sβ β Prop} (h : β a b, Ο (Quotient.mk a) (Quotient.mk b)) (qβ : Quotient sβ) (qβ : Quotient sβ) : Ο qβ qβ :=
Quotient.ind (fun aβ => Quotient.ind (fun aβ => h aβ aβ) qβ) qβ
@[elabAsEliminator]
protected theorem inductionOnβ
{Ο : Quotient sβ β Quotient sβ β Prop} (qβ : Quotient sβ) (qβ : Quotient sβ) (h : β a b, Ο (Quotient.mk a) (Quotient.mk b)) : Ο qβ qβ :=
Quotient.ind (fun aβ => Quotient.ind (fun aβ => h aβ aβ) qβ) qβ
@[elabAsEliminator]
protected theorem inductionOnβ
[sβ : Setoid Ο]
{Ξ΄ : Quotient sβ β Quotient sβ β Quotient sβ β Prop} (qβ : Quotient sβ) (qβ : Quotient sβ) (qβ : Quotient sβ) (h : β a b c, Ξ΄ (Quotient.mk a) (Quotient.mk b) (Quotient.mk c))
: Ξ΄ qβ qβ qβ :=
Quotient.ind (fun aβ => Quotient.ind (fun aβ => Quotient.ind (fun aβ => h aβ aβ aβ) qβ) qβ) qβ
end
section Exact
variable {Ξ± : Sort u}
private def rel [s : Setoid Ξ±] (qβ qβ : Quotient s) : Prop :=
Quotient.liftOnβ qβ qβ
(fun aβ aβ => aβ β aβ)
(fun aβ aβ bβ bβ aβbβ aβbβ =>
propext (Iff.intro
(fun aβaβ => Setoid.trans (Setoid.symm aβbβ) (Setoid.trans aβaβ aβbβ))
(fun bβbβ => Setoid.trans aβbβ (Setoid.trans bβbβ (Setoid.symm aβbβ)))))
private theorem rel.refl [s : Setoid Ξ±] : β (q : Quotient s), rel q q :=
fun q => Quot.inductionOn q (fun a => Setoid.refl a)
private theorem eqImpRel [s : Setoid Ξ±] {qβ qβ : Quotient s} : qβ = qβ β rel qβ qβ :=
fun h => Eq.ndrecOn h (rel.refl qβ)
theorem exact [s : Setoid Ξ±] {a b : Ξ±} : Quotient.mk a = Quotient.mk b β a β b :=
fun h => eqImpRel h
end Exact
section
universes uA uB uC
variables {Ξ± : Sort uA} {Ξ² : Sort uB}
variables [sβ : Setoid Ξ±] [sβ : Setoid Ξ²]
@[reducible, elabAsEliminator]
protected def recOnSubsingletonβ
{Ο : Quotient sβ β Quotient sβ β Sort uC} [h : β a b, Subsingleton (Ο (Quotient.mk a) (Quotient.mk b))]
(qβ : Quotient sβ) (qβ : Quotient sβ) (f : β a b, Ο (Quotient.mk a) (Quotient.mk b)) : Ο qβ qβ:=
@Quotient.recOnSubsingleton _ sβ (fun q => Ο q qβ) (fun a => Quotient.ind (fun b => h a b) qβ) qβ
(fun a => Quotient.recOnSubsingleton qβ (fun b => f a b))
end
end Quotient
section
variable {Ξ± : Type u}
variable (r : Ξ± β Ξ± β Prop)
inductive EqvGen : Ξ± β Ξ± β Prop
| rel : β x y, r x y β EqvGen x y
| refl : β x, EqvGen x x
| symm : β x y, EqvGen x y β EqvGen y x
| trans : β x y z, EqvGen x y β EqvGen y z β EqvGen x z
theorem EqvGen.isEquivalence : Equivalence (@EqvGen Ξ± r) :=
mkEquivalence _ EqvGen.refl EqvGen.symm EqvGen.trans
def EqvGen.Setoid : Setoid Ξ± :=
Setoid.mk _ (EqvGen.isEquivalence r)
theorem Quot.exact {a b : Ξ±} (H : Quot.mk r a = Quot.mk r b) : EqvGen r a b :=
@Quotient.exact _ (EqvGen.Setoid r) a b (@congrArg _ _ _ _
(Quot.lift (@Quotient.mk _ (EqvGen.Setoid r)) (fun x y h => Quot.sound (EqvGen.rel x y h))) H)
theorem Quot.eqvGenSound {r : Ξ± β Ξ± β Prop} {a b : Ξ±} (H : EqvGen r a b) : Quot.mk r a = Quot.mk r b :=
EqvGen.recOn H
(fun x y h => Quot.sound h)
(fun x => rfl)
(fun x y _ IH => Eq.symm IH)
(fun x y z _ _ IHβ IHβ => Eq.trans IHβ IHβ)
end
instance {Ξ± : Sort u} {s : Setoid Ξ±} [d : β (a b : Ξ±), Decidable (a β b)] : DecidableEq (Quotient s) :=
fun (qβ qβ : Quotient s) =>
Quotient.recOnSubsingletonβ qβ qβ
(fun aβ aβ =>
match (d aβ aβ) with
| (isTrue hβ) => isTrue (Quotient.sound hβ)
| (isFalse hβ) => isFalse (fun h => absurd (Quotient.exact h) hβ))
/- Function extensionality -/
namespace Function
variables {Ξ± : Sort u} {Ξ² : Ξ± β Sort v}
def Equiv (fβ fβ : β (x : Ξ±), Ξ² x) : Prop := β x, fβ x = fβ x
protected theorem Equiv.refl (f : β (x : Ξ±), Ξ² x) : Equiv f f :=
fun x => rfl
protected theorem Equiv.symm {fβ fβ : β (x : Ξ±), Ξ² x} : Equiv fβ fβ β Equiv fβ fβ :=
fun h x => Eq.symm (h x)
protected theorem Equiv.trans {fβ fβ fβ : β (x : Ξ±), Ξ² x} : Equiv fβ fβ β Equiv fβ fβ β Equiv fβ fβ :=
fun hβ hβ x => Eq.trans (hβ x) (hβ x)
protected theorem Equiv.isEquivalence (Ξ± : Sort u) (Ξ² : Ξ± β Sort v) : Equivalence (@Function.Equiv Ξ± Ξ²) :=
mkEquivalence (@Function.Equiv Ξ± Ξ²) (@Equiv.refl Ξ± Ξ²) (@Equiv.symm Ξ± Ξ²) (@Equiv.trans Ξ± Ξ²)
end Function
section
open Quotient
variables {Ξ± : Sort u} {Ξ² : Ξ± β Sort v}
@[instance]
private def funSetoid (Ξ± : Sort u) (Ξ² : Ξ± β Sort v) : Setoid (β (x : Ξ±), Ξ² x) :=
Setoid.mk (@Function.Equiv Ξ± Ξ²) (Function.Equiv.isEquivalence Ξ± Ξ²)
private def extfunApp (f : Quotient $ funSetoid Ξ± Ξ²) : β (x : Ξ±), Ξ² x :=
fun x =>
Quot.liftOn f
(fun (f : β (x : Ξ±), Ξ² x) => f x)
(fun fβ fβ h => h x)
theorem funext {fβ fβ : β (x : Ξ±), Ξ² x} (h : β x, fβ x = fβ x) : fβ = fβ :=
show extfunApp (Quotient.mk fβ) = extfunApp (Quotient.mk fβ) from
congrArg extfunApp (sound h)
end
instance Forall.Subsingleton {Ξ± : Sort u} {Ξ² : Ξ± β Sort v} [β a, Subsingleton (Ξ² a)] : Subsingleton (β a, Ξ² a) :=
β¨fun fβ fβ => funext (fun a => Subsingleton.elim (fβ a) (fβ a))β©
/- General operations on functions -/
namespace Function
universes uβ uβ uβ uβ
variables {Ξ± : Sort uβ} {Ξ² : Sort uβ} {Ο : Sort uβ} {Ξ΄ : Sort uβ} {ΞΆ : Sort uβ}
@[inline, reducible] def comp (f : Ξ² β Ο) (g : Ξ± β Ξ²) : Ξ± β Ο :=
fun x => f (g x)
infixr ` β ` := Function.comp
@[inline, reducible] def onFun (f : Ξ² β Ξ² β Ο) (g : Ξ± β Ξ²) : Ξ± β Ξ± β Ο :=
fun x y => f (g x) (g y)
@[inline, reducible] def combine (f : Ξ± β Ξ² β Ο) (op : Ο β Ξ΄ β ΞΆ) (g : Ξ± β Ξ² β Ξ΄)
: Ξ± β Ξ² β ΞΆ :=
fun x y => op (f x y) (g x y)
@[inline, reducible] def const (Ξ² : Sort uβ) (a : Ξ±) : Ξ² β Ξ± :=
fun x => a
@[inline, reducible] def swap {Ο : Ξ± β Ξ² β Sort uβ} (f : β x y, Ο x y) : β y x, Ο x y :=
fun y x => f x y
end Function
/- Squash -/
def Squash (Ξ± : Type u) := Quot (fun (a b : Ξ±) => True)
def Squash.mk {Ξ± : Type u} (x : Ξ±) : Squash Ξ± := Quot.mk _ x
theorem Squash.ind {Ξ± : Type u} {Ξ² : Squash Ξ± β Prop} (h : β (a : Ξ±), Ξ² (Squash.mk a)) : β (q : Squash Ξ±), Ξ² q :=
Quot.ind h
@[inline] def Squash.lift {Ξ± Ξ²} [Subsingleton Ξ²] (s : Squash Ξ±) (f : Ξ± β Ξ²) : Ξ² :=
Quot.lift f (fun a b _ => Subsingleton.elim _ _) s
instance Squash.Subsingleton {Ξ±} : Subsingleton (Squash Ξ±) :=
β¨Squash.ind (fun (a : Ξ±) => Squash.ind (fun (b : Ξ±) => Quot.sound trivial))β©
namespace Lean
/- Kernel reduction hints -/
/--
When the kernel tries to reduce a term `Lean.reduceBool c`, it will invoke the Lean interpreter to evaluate `c`.
The kernel will not use the interpreter if `c` is not a constant.
This feature is useful for performing proofs by reflection.
Remark: the Lean frontend allows terms of the from `Lean.reduceBool t` where `t` is a term not containing
free variables. The frontend automatically declares a fresh auxiliary constant `c` and replaces the term with
`Lean.reduceBool c`. The main motivation is that the code for `t` will be pre-compiled.
Warning: by using this feature, the Lean compiler and interpreter become part of your trusted code base.
This is extra 30k lines of code. More importantly, you will probably not be able to check your developement using
external type checkers (e.g., Trepplein) that do not implement this feature.
Keep in mind that if you are using Lean as programming language, you are already trusting the Lean compiler and interpreter.
So, you are mainly losing the capability of type checking your developement using external checkers. -/
def reduceBool (b : Bool) : Bool := b
/--
Similar to `Lean.reduceBool` for closed `Nat` terms.
Remark: we do not have plans for supporting a generic `reduceValue {Ξ±} (a : Ξ±) : Ξ± := a`.
The main issue is that it is non-trivial to convert an arbitrary runtime object back into a Lean expression.
We believe `Lean.reduceBool` enables most interesting applications (e.g., proof by reflection). -/
def reduceNat (n : Nat) : Nat := n
def ofReduceBool (a b : Bool) (h : reduceBool a = b) : a = b := h
def ofReduceNat (a b : Nat) (h : reduceNat a = b) : a = b := h
end Lean
/- Classical reasoning support -/
namespace Classical
axiom choice {Ξ± : Sort u} : Nonempty Ξ± β Ξ±
noncomputable def indefiniteDescription {Ξ± : Sort u} (p : Ξ± β Prop)
(h : Exists (fun x => p x)) : {x // p x} :=
choice $ let β¨x, pxβ© := h; β¨β¨x, pxβ©β©
noncomputable def choose {Ξ± : Sort u} {p : Ξ± β Prop} (h : Exists (fun x => p x)) : Ξ± :=
(indefiniteDescription p h).val
theorem chooseSpec {Ξ± : Sort u} {p : Ξ± β Prop} (h : Exists (fun x => p x)) : p (choose h) :=
(indefiniteDescription p h).property
/- Diaconescu's theorem: excluded middle from choice, Function extensionality and propositional extensionality. -/
theorem em (p : Prop) : p β¨ Β¬p :=
let U (x : Prop) : Prop := x = True β¨ p;
let V (x : Prop) : Prop := x = False β¨ p;
have exU : Exists (fun x => U x) from β¨True, Or.inl rflβ©;
have exV : Exists (fun x => V x) from β¨False, Or.inl rflβ©;
let u : Prop := choose exU;
let v : Prop := choose exV;
have uDef : U u from chooseSpec exU;
have vDef : V v from chooseSpec exV;
have notUvOrP : u β v β¨ p from
Or.elim uDef
(fun hut =>
Or.elim vDef
(fun hvf =>
have hne : u β v from hvf.symm βΈ hut.symm βΈ trueNeFalse;
Or.inl hne)
Or.inr)
Or.inr;
have pImpliesUv : p β u = v from
fun hp =>
have hpred : U = V from
funext $ fun x =>
have hl : (x = True β¨ p) β (x = False β¨ p) from
fun a => Or.inr hp;
have hr : (x = False β¨ p) β (x = True β¨ p) from
fun a => Or.inr hp;
show (x = True β¨ p) = (x = False β¨ p) from
propext (Iff.intro hl hr);
have hβ : β exU exV, @choose _ U exU = @choose _ V exV from
hpred βΈ fun exU exV => rfl;
show u = v from hβ _ _;
Or.elim notUvOrP
(fun (hne : u β v) => Or.inr (mt pImpliesUv hne))
Or.inl
theorem existsTrueOfNonempty {Ξ± : Sort u} : Nonempty Ξ± β Exists (fun (x : Ξ±) => True)
| β¨xβ© => β¨x, trivialβ©
noncomputable def inhabitedOfNonempty {Ξ± : Sort u} (h : Nonempty Ξ±) : Inhabited Ξ± :=
β¨choice hβ©
noncomputable def inhabitedOfExists {Ξ± : Sort u} {p : Ξ± β Prop} (h : Exists (fun x => p x)) :
Inhabited Ξ± :=
inhabitedOfNonempty (Exists.elim h (fun w hw => β¨wβ©))
/- all propositions are Decidable -/
noncomputable def propDecidable (a : Prop) : Decidable a :=
choice $ Or.elim (em a)
(fun ha => β¨isTrue haβ©)
(fun hna => β¨isFalse hnaβ©)
noncomputable def decidableInhabited (a : Prop) : Inhabited (Decidable a) :=
β¨propDecidable aβ©
noncomputable def typeDecidableEq (Ξ± : Sort u) : DecidableEq Ξ± :=
fun x y => propDecidable (x = y)
noncomputable def typeDecidable (Ξ± : Sort u) : PSum Ξ± (Ξ± β False) :=
match (propDecidable (Nonempty Ξ±)) with
| (isTrue hp) => PSum.inl (@arbitrary _ (inhabitedOfNonempty hp))
| (isFalse hn) => PSum.inr (fun a => absurd (Nonempty.intro a) hn)
noncomputable def strongIndefiniteDescription {Ξ± : Sort u} (p : Ξ± β Prop)
(h : Nonempty Ξ±) : {x : Ξ± // Exists (fun (y : Ξ±) => p y) β p x} :=
@dite _ (Exists (fun (x : Ξ±) => p x)) (propDecidable _)
(fun (hp : Exists (fun (x : Ξ±) => p x)) =>
show {x : Ξ± // Exists (fun (y : Ξ±) => p y) β p x} from
let xp := indefiniteDescription _ hp;
β¨xp.val, fun h' => xp.propertyβ©)
(fun hp => β¨choice h, fun h => absurd h hpβ©)
/- the Hilbert epsilon Function -/
noncomputable def epsilon {Ξ± : Sort u} [h : Nonempty Ξ±] (p : Ξ± β Prop) : Ξ± :=
(strongIndefiniteDescription p h).val
theorem epsilonSpecAux {Ξ± : Sort u} (h : Nonempty Ξ±) (p : Ξ± β Prop)
: Exists (fun y => p y) β p (@epsilon Ξ± h p) :=
(strongIndefiniteDescription p h).property
theorem epsilonSpec {Ξ± : Sort u} {p : Ξ± β Prop} (hex : Exists (fun y => p y)) :
p (@epsilon Ξ± (nonemptyOfExists hex) p) :=
epsilonSpecAux (nonemptyOfExists hex) p hex
theorem epsilonSingleton {Ξ± : Sort u} (x : Ξ±) : @epsilon Ξ± β¨xβ© (fun y => y = x) = x :=
@epsilonSpec Ξ± (fun y => y = x) β¨x, rflβ©
/- the axiom of choice -/
theorem axiomOfChoice {Ξ± : Sort u} {Ξ² : Ξ± β Sort v} {r : β x, Ξ² x β Prop} (h : β x, Exists (fun y => r x y)) :
Exists (fun (f : β x, Ξ² x) => β x, r x (f x)) :=
β¨_, fun x => chooseSpec (h x)β©
theorem skolem {Ξ± : Sort u} {b : Ξ± β Sort v} {p : β x, b x β Prop} :
(β x, Exists (fun y => p x y)) β Exists (fun (f : β x, b x) => β x, p x (f x)) :=
β¨axiomOfChoice, fun β¨f, hwβ© (x) => β¨f x, hw xβ©β©
theorem propComplete (a : Prop) : a = True β¨ a = False :=
Or.elim (em a)
(fun t => Or.inl (eqTrueIntro t))
(fun f => Or.inr (eqFalseIntro f))
-- this supercedes byCases in Decidable
theorem byCases {p q : Prop} (hpq : p β q) (hnpq : Β¬p β q) : q :=
@Decidable.byCases _ _ (propDecidable _) hpq hnpq
-- this supercedes byContradiction in Decidable
theorem byContradiction {p : Prop} (h : Β¬p β False) : p :=
@Decidable.byContradiction _ (propDecidable _) h
end Classical
|
c4e10938a527eff02b307e3ae3fb14cc875f6168
|
853df553b1d6ca524e3f0a79aedd32dde5d27ec3
|
/src/analysis/normed_space/banach.lean
|
96bcb19c96800be20572517ed34a13f79ba13a8e
|
[
"Apache-2.0"
] |
permissive
|
DanielFabian/mathlib
|
efc3a50b5dde303c59eeb6353ef4c35a345d7112
|
f520d07eba0c852e96fe26da71d85bf6d40fcc2a
|
refs/heads/master
| 1,668,739,922,971
| 1,595,201,756,000
| 1,595,201,756,000
| 279,469,476
| 0
| 0
| null | 1,594,696,604,000
| 1,594,696,604,000
| null |
UTF-8
|
Lean
| false
| false
| 12,080
|
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 topology.metric_space.baire
import analysis.normed_space.operator_norm
/-!
# Banach open mapping theorem
This file contains the Banach open mapping theorem, i.e., the fact that a bijective
bounded linear map between Banach spaces has a bounded inverse.
-/
open function metric set filter finset
open_locale classical topological_space big_operators
variables {π : Type*} [nondiscrete_normed_field π]
{E : Type*} [normed_group E] [normed_space π E]
{F : Type*} [normed_group F] [normed_space π F]
(f : E βL[π] F)
include π
variable [complete_space F]
/--
First step of the proof of the Banach open mapping theorem (using completeness of `F`):
by Baire's theorem, there exists a ball in `E` whose image closure has nonempty interior.
Rescaling everything, it follows that any `y β F` is arbitrarily well approached by
images of elements of norm at most `C * β₯yβ₯`.
For further use, we will only need such an element whose image
is within distance `β₯yβ₯/2` of `y`, to apply an iterative process. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma exists_approx_preimage_norm_le (surj : surjective f) :
βC β₯ 0, βy, βx, dist (f x) y β€ 1/2 * β₯yβ₯ β§ β₯xβ₯ β€ C * β₯yβ₯ :=
begin
have A : (βn:β, closure (f '' (ball 0 n))) = univ,
{ refine subset.antisymm (subset_univ _) (Ξ»y hy, _),
rcases surj y with β¨x, hxβ©,
rcases exists_nat_gt (β₯xβ₯) with β¨n, hnβ©,
refine mem_Union.2 β¨n, subset_closure _β©,
refine (mem_image _ _ _).2 β¨x, β¨_, hxβ©β©,
rwa [mem_ball, dist_eq_norm, sub_zero] },
have : β (n : β) x, x β interior (closure (f '' (ball 0 n))) :=
nonempty_interior_of_Union_of_closed (Ξ»n, is_closed_closure) A,
simp only [mem_interior_iff_mem_nhds, mem_nhds_iff] at this,
rcases this with β¨n, a, Ξ΅, β¨Ξ΅pos, Hβ©β©,
rcases normed_field.exists_one_lt_norm π with β¨c, hcβ©,
refine β¨(Ξ΅/2)β»ΒΉ * β₯cβ₯ * 2 * n, _, Ξ»y, _β©,
{ refine mul_nonneg (mul_nonneg (mul_nonneg _ (norm_nonneg _)) (by norm_num)) _,
refine inv_nonneg.2 (div_nonneg' (le_of_lt Ξ΅pos) (by norm_num)),
exact nat.cast_nonneg n },
{ by_cases hy : y = 0,
{ use 0, simp [hy] },
{ rcases rescale_to_shell hc (half_pos Ξ΅pos) hy with β¨d, hd, ydle, leyd, dinvβ©,
let Ξ΄ := β₯dβ₯ * β₯yβ₯/4,
have Ξ΄pos : 0 < Ξ΄ :=
div_pos (mul_pos (norm_pos_iff.2 hd) (norm_pos_iff.2 hy)) (by norm_num),
have : a + d β’ y β ball a Ξ΅,
by simp [dist_eq_norm, lt_of_le_of_lt ydle (half_lt_self Ξ΅pos)],
rcases metric.mem_closure_iff.1 (H this) _ Ξ΄pos with β¨zβ, zβim, hββ©,
rcases (mem_image _ _ _).1 zβim with β¨xβ, hxβ, xzββ©,
rw β xzβ at hβ,
rw [mem_ball, dist_eq_norm, sub_zero] at hxβ,
have : a β ball a Ξ΅, by { simp, exact Ξ΅pos },
rcases metric.mem_closure_iff.1 (H this) _ Ξ΄pos with β¨zβ, zβim, hββ©,
rcases (mem_image _ _ _).1 zβim with β¨xβ, hxβ, xzββ©,
rw β xzβ at hβ,
rw [mem_ball, dist_eq_norm, sub_zero] at hxβ,
let x := xβ - xβ,
have I : β₯f x - d β’ yβ₯ β€ 2 * Ξ΄ := calc
β₯f x - d β’ yβ₯ = β₯f xβ - (a + d β’ y) - (f xβ - a)β₯ :
by { congr' 1, simp only [x, f.map_sub], abel }
... β€ β₯f xβ - (a + d β’ y)β₯ + β₯f xβ - aβ₯ :
norm_sub_le _ _
... β€ Ξ΄ + Ξ΄ : begin
apply add_le_add,
{ rw [β dist_eq_norm, dist_comm], exact le_of_lt hβ },
{ rw [β dist_eq_norm, dist_comm], exact le_of_lt hβ }
end
... = 2 * Ξ΄ : (two_mul _).symm,
have J : β₯f (dβ»ΒΉ β’ x) - yβ₯ β€ 1/2 * β₯yβ₯ := calc
β₯f (dβ»ΒΉ β’ x) - yβ₯ = β₯dβ»ΒΉ β’ f x - (dβ»ΒΉ * d) β’ yβ₯ :
by rwa [f.map_smul _, inv_mul_cancel, one_smul]
... = β₯dβ»ΒΉ β’ (f x - d β’ y)β₯ : by rw [mul_smul, smul_sub]
... = β₯dβ₯β»ΒΉ * β₯f x - d β’ yβ₯ : by rw [norm_smul, normed_field.norm_inv]
... β€ β₯dβ₯β»ΒΉ * (2 * Ξ΄) : begin
apply mul_le_mul_of_nonneg_left I,
rw inv_nonneg,
exact norm_nonneg _
end
... = (β₯dβ₯β»ΒΉ * β₯dβ₯) * β₯yβ₯ /2 : by { simp only [Ξ΄], ring }
... = β₯yβ₯/2 : by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hd] }
... = (1/2) * β₯yβ₯ : by ring,
rw β dist_eq_norm at J,
have π : β₯dβ»ΒΉ β’ xβ₯ β€ (Ξ΅ / 2)β»ΒΉ * β₯cβ₯ * 2 * βn * β₯yβ₯ := calc
β₯dβ»ΒΉ β’ xβ₯ = β₯dβ₯β»ΒΉ * β₯xβ - xββ₯ : by rw [norm_smul, normed_field.norm_inv]
... β€ ((Ξ΅ / 2)β»ΒΉ * β₯cβ₯ * β₯yβ₯) * (n + n) : begin
refine mul_le_mul dinv _ (norm_nonneg _) _,
{ exact le_trans (norm_sub_le _ _) (add_le_add (le_of_lt hxβ) (le_of_lt hxβ)) },
{ apply mul_nonneg (mul_nonneg _ (norm_nonneg _)) (norm_nonneg _),
exact inv_nonneg.2 (le_of_lt (half_pos Ξ΅pos)) }
end
... = (Ξ΅ / 2)β»ΒΉ * β₯cβ₯ * 2 * βn * β₯yβ₯ : by ring,
exact β¨dβ»ΒΉ β’ x, J, πβ© } },
end
variable [complete_space E]
/-- The Banach open mapping theorem: if a bounded linear map between Banach spaces is onto, then
any point has a preimage with controlled norm. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem exists_preimage_norm_le (surj : surjective f) :
βC > 0, βy, βx, f x = y β§ β₯xβ₯ β€ C * β₯yβ₯ :=
begin
obtain β¨C, C0, hCβ© := exists_approx_preimage_norm_le f surj,
/- Second step of the proof: starting from `y`, we want an exact preimage of `y`. Let `g y` be
the approximate preimage of `y` given by the first step, and `h y = y - f(g y)` the part that
has no preimage yet. We will iterate this process, taking the approximate preimage of `h y`,
leaving only `h^2 y` without preimage yet, and so on. Let `u n` be the approximate preimage
of `h^n y`. Then `u` is a converging series, and by design the sum of the series is a
preimage of `y`. This uses completeness of `E`. -/
choose g hg using hC,
let h := Ξ»y, y - f (g y),
have hle : βy, β₯h yβ₯ β€ (1/2) * β₯yβ₯,
{ assume y,
rw [β dist_eq_norm, dist_comm],
exact (hg y).1 },
refine β¨2 * C + 1, by linarith, Ξ»y, _β©,
have hnle : βn:β, β₯(h^[n]) yβ₯ β€ (1/2)^n * β₯yβ₯,
{ assume n,
induction n with n IH,
{ simp only [one_div_eq_inv, nat.nat_zero_eq_zero, one_mul, iterate_zero_apply,
pow_zero] },
{ rw [iterate_succ'],
apply le_trans (hle _) _,
rw [pow_succ, mul_assoc],
apply mul_le_mul_of_nonneg_left IH,
norm_num } },
let u := Ξ»n, g((h^[n]) y),
have ule : βn, β₯u nβ₯ β€ (1/2)^n * (C * β₯yβ₯),
{ assume n,
apply le_trans (hg _).2 _,
calc C * β₯(h^[n]) yβ₯ β€ C * ((1/2)^n * β₯yβ₯) : mul_le_mul_of_nonneg_left (hnle n) C0
... = (1 / 2) ^ n * (C * β₯yβ₯) : by ring },
have sNu : summable (Ξ»n, β₯u nβ₯),
{ refine summable_of_nonneg_of_le (Ξ»n, norm_nonneg _) ule _,
exact summable.mul_right _ (summable_geometric_of_lt_1 (by norm_num) (by norm_num)) },
have su : summable u := summable_of_summable_norm sNu,
let x := tsum u,
have x_ineq : β₯xβ₯ β€ (2 * C + 1) * β₯yβ₯ := calc
β₯xβ₯ β€ (β'n, β₯u nβ₯) : norm_tsum_le_tsum_norm sNu
... β€ (β'n, (1/2)^n * (C * β₯yβ₯)) :
tsum_le_tsum ule sNu (summable.mul_right _ summable_geometric_two)
... = (β'n, (1/2)^n) * (C * β₯yβ₯) : by { rw tsum_mul_right, exact summable_geometric_two }
... = 2 * (C * β₯yβ₯) : by rw tsum_geometric_two
... = 2 * C * β₯yβ₯ + 0 : by rw [add_zero, mul_assoc]
... β€ 2 * C * β₯yβ₯ + β₯yβ₯ : add_le_add (le_refl _) (norm_nonneg _)
... = (2 * C + 1) * β₯yβ₯ : by ring,
have fsumeq : βn:β, f(β i in finset.range n, u i) = y - (h^[n]) y,
{ assume n,
induction n with n IH,
{ simp [f.map_zero] },
{ rw [sum_range_succ, f.map_add, IH, iterate_succ'],
simp [u, h, sub_eq_add_neg, add_comm, add_left_comm] } },
have : tendsto (Ξ»n, β i in range n, u i) at_top (π x) :=
su.has_sum.tendsto_sum_nat,
have Lβ : tendsto (Ξ»n, f(β i in range n, u i)) at_top (π (f x)) :=
(f.continuous.tendsto _).comp this,
simp only [fsumeq] at Lβ,
have Lβ : tendsto (Ξ»n, y - (h^[n]) y) at_top (π (y - 0)),
{ refine tendsto_const_nhds.sub _,
rw tendsto_iff_norm_tendsto_zero,
simp only [sub_zero],
refine squeeze_zero (Ξ»_, norm_nonneg _) hnle _,
have : 0 = 0 * β₯yβ₯, by rw zero_mul,
rw this,
refine tendsto.mul _ tendsto_const_nhds,
exact tendsto_pow_at_top_nhds_0_of_lt_1 (by norm_num) (by norm_num) },
have feq : f x = y - 0,
{ apply tendsto_nhds_unique _ Lβ Lβ,
simp },
rw sub_zero at feq,
exact β¨x, feq, x_ineqβ©
end
/-- The Banach open mapping theorem: a surjective bounded linear map between Banach spaces is open. -/
theorem open_mapping (surj : surjective f) : is_open_map f :=
begin
assume s hs,
rcases exists_preimage_norm_le f surj with β¨C, Cpos, hCβ©,
refine is_open_iff.2 (Ξ»y yfs, _),
rcases mem_image_iff_bex.1 yfs with β¨x, xs, fxyβ©,
rcases is_open_iff.1 hs x xs with β¨Ξ΅, Ξ΅pos, hΞ΅β©,
refine β¨Ξ΅/C, div_pos Ξ΅pos Cpos, Ξ»z hz, _β©,
rcases hC (z-y) with β¨w, wim, wnormβ©,
have : f (x + w) = z, by { rw [f.map_add, wim, fxy, add_sub_cancel'_right] },
rw β this,
have : x + w β ball x Ξ΅ := calc
dist (x+w) x = β₯wβ₯ : by { rw dist_eq_norm, simp }
... β€ C * β₯z - yβ₯ : wnorm
... < C * (Ξ΅/C) : begin
apply mul_lt_mul_of_pos_left _ Cpos,
rwa [mem_ball, dist_eq_norm] at hz,
end
... = Ξ΅ : mul_div_cancel' _ (ne_of_gt Cpos),
exact set.mem_image_of_mem _ (hΞ΅ this)
end
namespace linear_equiv
/-- If a bounded linear map is a bijection, then its inverse is also a bounded linear map. -/
theorem continuous_symm (e : E ββ[π] F) (h : continuous e) :
continuous e.symm :=
begin
intros s hs,
rw [β e.image_eq_preimage],
rw [β e.coe_coe] at h β’,
exact open_mapping β¨βe, hβ© e.surjective s hs
end
/-- Associating to a linear equivalence between Banach spaces a continuous linear equivalence when
the direct map is continuous, thanks to the Banach open mapping theorem that ensures that the
inverse map is also continuous. -/
def to_continuous_linear_equiv_of_continuous (e : E ββ[π] F) (h : continuous e) :
E βL[π] F :=
{ continuous_to_fun := h,
continuous_inv_fun := e.continuous_symm h,
..e }
@[simp] lemma coe_fn_to_continuous_linear_equiv_of_continuous (e : E ββ[π] F) (h : continuous e) :
β(e.to_continuous_linear_equiv_of_continuous h) = e := rfl
@[simp] lemma coe_fn_to_continuous_linear_equiv_of_continuous_symm (e : E ββ[π] F)
(h : continuous e) :
β(e.to_continuous_linear_equiv_of_continuous h).symm = e.symm := rfl
end linear_equiv
namespace continuous_linear_equiv
/-- Convert a bijective continuous linear map `f : E βL[π] F` between two Banach spaces
to a continuous linear equivalence. -/
noncomputable def of_bijective (f : E βL[π] F) (hinj : f.ker = β₯) (hsurj : f.range = β€) :
E βL[π] F :=
(linear_equiv.of_bijective βf hinj hsurj).to_continuous_linear_equiv_of_continuous f.continuous
@[simp] lemma coe_fn_of_bijective (f : E βL[π] F) (hinj : f.ker = β₯) (hsurj : f.range = β€) :
β(of_bijective f hinj hsurj) = f := rfl
@[simp] lemma of_bijective_symm_apply_apply (f : E βL[π] F) (hinj : f.ker = β₯)
(hsurj : f.range = β€) (x : E) :
(of_bijective f hinj hsurj).symm (f x) = x :=
(of_bijective f hinj hsurj).symm_apply_apply x
@[simp] lemma of_bijective_apply_symm_apply (f : E βL[π] F) (hinj : f.ker = β₯)
(hsurj : f.range = β€) (y : F) :
f ((of_bijective f hinj hsurj).symm y) = y :=
(of_bijective f hinj hsurj).apply_symm_apply y
end continuous_linear_equiv
|
48f7f7c06ee22a64771cfba13839716a570b59da
|
2eab05920d6eeb06665e1a6df77b3157354316ad
|
/src/measure_theory/pi_system.lean
|
312e0e6f11155bc2769af525a5d31420db9b23ec
|
[
"Apache-2.0"
] |
permissive
|
ayush1801/mathlib
|
78949b9f789f488148142221606bf15c02b960d2
|
ce164e28f262acbb3de6281b3b03660a9f744e3c
|
refs/heads/master
| 1,692,886,907,941
| 1,635,270,866,000
| 1,635,270,866,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 17,773
|
lean
|
/-
Copyright (c) 2021 Martin Zinkevich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Martin Zinkevich
-/
import measure_theory.measurable_space_def
import data.equiv.encodable.lattice
/-!
# Induction principles for measurable sets, related to Ο-systems and Ξ»-systems.
## Main statements
* The main theorem of this file is Dynkin's Ο-Ξ» theorem, which appears
here as an induction principle `induction_on_inter`. Suppose `s` is a
collection of subsets of `Ξ±` such that the intersection of two members
of `s` belongs to `s` whenever it is nonempty. Let `m` be the Ο-algebra
generated by `s`. In order to check that a predicate `C` holds on every
member of `m`, it suffices to check that `C` holds on the members of `s` and
that `C` is preserved by complementation and *disjoint* countable
unions.
* The proof of this theorem relies on the notion of `is_pi_system`, i.e., a collection of sets
which is closed under binary non-empty intersections. Note that this is a small variation around
the usual notion in the literature, which often requires that a Ο-system is non-empty, and closed
also under disjoint intersections. This variation turns out to be convenient for the
formalization.
* The proof of Dynkin's Ο-Ξ» theorem also requires the notion of `dynkin_system`, i.e., a collection
of sets which contains the empty set, is closed under complementation and under countable union
of pairwise disjoint sets. The disjointness condition is the only difference with `Ο`-algebras.
* `generate_pi_system g` gives the minimal Ο-system containing `g`.
This can be considered a Galois insertion into both measurable spaces and sets.
* `generate_from_generate_pi_system_eq` proves that if you start from a collection of sets `g`,
take the generated Ο-system, and then the generated Ο-algebra, you get the same result as
the Ο-algebra generated from `g`. This is useful because there are connections between
independent sets that are Ο-systems and the generated independent spaces.
* `mem_generate_pi_system_Union_elim` and `mem_generate_pi_system_Union_elim'` show that any
element of the Ο-system generated from the union of a set of Ο-systems can be
represented as the intersection of a finite number of elements from these sets.
## Implementation details
* `is_pi_system` is a predicate, not a type. Thus, we don't explicitly define the galois
insertion, nor do we define a complete lattice. In theory, we could define a complete
lattice and galois insertion on the subtype corresponding to `is_pi_system`.
-/
open measurable_space set
open_locale classical
/-- A Ο-system is a collection of subsets of `Ξ±` that is closed under binary intersection of
non-disjoint sets. Usually it is also required that the collection is nonempty, but we don't do
that here. -/
def is_pi_system {Ξ±} (C : set (set Ξ±)) : Prop :=
β s t β C, (s β© t : set Ξ±).nonempty β s β© t β C
namespace measurable_space
lemma is_pi_system_measurable_set {Ξ±:Type*} [measurable_space Ξ±] :
is_pi_system {s : set Ξ± | measurable_set s} :=
Ξ» s t hs ht _, hs.inter ht
end measurable_space
lemma is_pi_system.singleton {Ξ±} (S : set Ξ±) : is_pi_system ({S} : set (set Ξ±)) :=
begin
intros s t h_s h_t h_ne,
rw [set.mem_singleton_iff.1 h_s, set.mem_singleton_iff.1 h_t, set.inter_self,
set.mem_singleton_iff],
end
/-- Given a collection `S` of subsets of `Ξ±`, then `generate_pi_system S` is the smallest
Ο-system containing `S`. -/
inductive generate_pi_system {Ξ±} (S : set (set Ξ±)) : set (set Ξ±)
| base {s : set Ξ±} (h_s : s β S) : generate_pi_system s
| inter {s t : set Ξ±} (h_s : generate_pi_system s) (h_t : generate_pi_system t)
(h_nonempty : (s β© t).nonempty) : generate_pi_system (s β© t)
lemma is_pi_system_generate_pi_system {Ξ±} (S : set (set Ξ±)) :
is_pi_system (generate_pi_system S) :=
Ξ» s t h_s h_t h_nonempty, generate_pi_system.inter h_s h_t h_nonempty
lemma subset_generate_pi_system_self {Ξ±} (S : set (set Ξ±)) : S β generate_pi_system S :=
Ξ» s, generate_pi_system.base
lemma generate_pi_system_subset_self {Ξ±} {S : set (set Ξ±)} (h_S : is_pi_system S) :
generate_pi_system S β S :=
begin
intros x h,
induction h with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,
{ exact h_s, },
{ exact h_S _ _ h_s h_u h_nonempty, },
end
lemma generate_pi_system_eq {Ξ±} {S : set (set Ξ±)} (h_pi : is_pi_system S) :
generate_pi_system S = S :=
set.subset.antisymm (generate_pi_system_subset_self h_pi) (subset_generate_pi_system_self S)
lemma generate_pi_system_mono {Ξ±} {S T : set (set Ξ±)} (hST : S β T) :
generate_pi_system S β generate_pi_system T :=
begin
intros t ht,
induction ht with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,
{ exact generate_pi_system.base (set.mem_of_subset_of_mem hST h_s),},
{ exact is_pi_system_generate_pi_system T _ _ h_s h_u h_nonempty, },
end
lemma generate_pi_system_measurable_set {Ξ±} [M : measurable_space Ξ±] {S : set (set Ξ±)}
(h_meas_S : β s β S, measurable_set s) (t : set Ξ±)
(h_in_pi : t β generate_pi_system S) : measurable_set t :=
begin
induction h_in_pi with s h_s s u h_gen_s h_gen_u h_nonempty h_s h_u,
{ apply h_meas_S _ h_s, },
{ apply measurable_set.inter h_s h_u, },
end
lemma generate_from_measurable_set_of_generate_pi_system {Ξ±} {g : set (set Ξ±)} (t : set Ξ±)
(ht : t β generate_pi_system g) :
(generate_from g).measurable_set' t :=
@generate_pi_system_measurable_set Ξ± (generate_from g) g
(Ξ» s h_s_in_g, measurable_set_generate_from h_s_in_g) t ht
lemma generate_from_generate_pi_system_eq {Ξ±} {g : set (set Ξ±)} :
generate_from (generate_pi_system g) = generate_from g :=
begin
apply le_antisymm; apply generate_from_le,
{ exact Ξ» t h_t, generate_from_measurable_set_of_generate_pi_system t h_t, },
{ exact Ξ» t h_t, measurable_set_generate_from (generate_pi_system.base h_t), },
end
/- Every element of the Ο-system generated by the union of a family of Ο-systems
is a finite intersection of elements from the Ο-systems.
For an indexed union version, see `mem_generate_pi_system_Union_elim'`. -/
lemma mem_generate_pi_system_Union_elim {Ξ± Ξ²} {g : Ξ² β set (set Ξ±)}
(h_pi : β b, is_pi_system (g b)) (t : set Ξ±) (h_t : t β generate_pi_system (β b, g b)) :
β (T : finset Ξ²) (f : Ξ² β set Ξ±), (t = β b β T, f b) β§ (β b β T, f b β g b) :=
begin
induction h_t with s h_s s t' h_gen_s h_gen_t' h_nonempty h_s h_t',
{ rcases h_s with β¨t', β¨β¨b, rflβ©, h_s_in_t'β©β©,
refine β¨{b}, (Ξ» _, s), _β©,
simpa using h_s_in_t', },
{ rcases h_t' with β¨T_t', β¨f_t', β¨rfl, h_t'β©β©β©,
rcases h_s with β¨T_s, β¨f_s, β¨rfl, h_sβ© β© β©,
use [(T_s βͺ T_t'), (Ξ» (b:Ξ²),
if (b β T_s) then (if (b β T_t') then (f_s b β© (f_t' b)) else (f_s b))
else (if (b β T_t') then (f_t' b) else (β
: set Ξ±)))],
split,
{ ext a,
simp_rw [set.mem_inter_iff, set.mem_Inter, finset.mem_union, or_imp_distrib],
rw β forall_and_distrib,
split; intros h1 b; by_cases hbs : b β T_s; by_cases hbt : b β T_t'; specialize h1 b;
simp only [hbs, hbt, if_true, if_false, true_implies_iff, and_self, false_implies_iff,
and_true, true_and] at h1 β’,
all_goals { exact h1, }, },
intros b h_b,
split_ifs with hbs hbt hbt,
{ refine h_pi b (f_s b) (f_t' b) (h_s b hbs) (h_t' b hbt) (set.nonempty.mono _ h_nonempty),
exact set.inter_subset_inter (set.bInter_subset_of_mem hbs) (set.bInter_subset_of_mem hbt), },
{ exact h_s b hbs, },
{ exact h_t' b hbt, },
{ rw finset.mem_union at h_b,
apply false.elim (h_b.elim hbs hbt), }, },
end
/- Every element of the Ο-system generated by an indexed union of a family of Ο-systems
is a finite intersection of elements from the Ο-systems.
For a total union version, see `mem_generate_pi_system_Union_elim`. -/
lemma mem_generate_pi_system_Union_elim' {Ξ± Ξ²} {g : Ξ² β set (set Ξ±)} {s: set Ξ²}
(h_pi : β b β s, is_pi_system (g b)) (t : set Ξ±) (h_t : t β generate_pi_system (β b β s, g b)) :
β (T : finset Ξ²) (f : Ξ² β set Ξ±), (βT β s) β§ (t = β b β T, f b) β§ (β b β T, f b β g b) :=
begin
have : t β generate_pi_system (β (b : subtype s), (g β subtype.val) b),
{ suffices h1 : (β (b : subtype s), (g β subtype.val) b) = (β b (H : b β s), g b), by rwa h1,
ext x,
simp only [exists_prop, set.mem_Union, function.comp_app, subtype.exists, subtype.coe_mk],
refl },
rcases @mem_generate_pi_system_Union_elim Ξ± (subtype s) (g β subtype.val)
(Ξ» b, h_pi b.val b.property) t this with β¨T, β¨f,β¨ rfl, h_t'β©β©β©,
refine β¨T.image subtype.val, function.extend subtype.val f (Ξ» (b:Ξ²), (β
: set Ξ±)), by simp, _, _β©,
{ ext a, split;
{ simp only [set.mem_Inter, subtype.forall, finset.set_bInter_finset_image],
intros h1 b h_b h_b_in_T,
have h2 := h1 b h_b h_b_in_T,
revert h2,
rw function.extend_apply subtype.val_injective,
apply id } },
{ intros b h_b,
simp_rw [finset.mem_image, exists_prop, subtype.exists,
exists_and_distrib_right, exists_eq_right] at h_b,
cases h_b,
have h_b_alt : b = (subtype.mk b h_b_w).val := rfl,
rw [h_b_alt, function.extend_apply subtype.val_injective],
apply h_t',
apply h_b_h },
end
namespace measurable_space
variable {Ξ± : Type*}
/-- A Dynkin system is a collection of subsets of a type `Ξ±` that contains the empty set,
is closed under complementation and under countable union of pairwise disjoint sets.
The disjointness condition is the only difference with `Ο`-algebras.
The main purpose of Dynkin systems is to provide a powerful induction rule for Ο-algebras
generated by a collection of sets which is stable under intersection.
A Dynkin system is also known as a "Ξ»-system" or a "d-system".
-/
structure dynkin_system (Ξ± : Type*) :=
(has : set Ξ± β Prop)
(has_empty : has β
)
(has_compl : β {a}, has a β has aαΆ)
(has_Union_nat : β {f : β β set Ξ±}, pairwise (disjoint on f) β (β i, has (f i)) β has (β i, f i))
namespace dynkin_system
@[ext] lemma ext : β {dβ dβ : dynkin_system Ξ±}, (β s : set Ξ±, dβ.has s β dβ.has s) β dβ = dβ
| β¨sβ, _, _, _β© β¨sβ, _, _, _β© h := have sβ = sβ, from funext $ assume x, propext $ h x,
by subst this
variable (d : dynkin_system Ξ±)
lemma has_compl_iff {a} : d.has aαΆ β d.has a :=
β¨Ξ» h, by simpa using d.has_compl h, Ξ» h, d.has_compl hβ©
lemma has_univ : d.has univ :=
by simpa using d.has_compl d.has_empty
theorem has_Union {Ξ²} [encodable Ξ²] {f : Ξ² β set Ξ±}
(hd : pairwise (disjoint on f)) (h : β i, d.has (f i)) : d.has (β i, f i) :=
by { rw β encodable.Union_decodeβ, exact
d.has_Union_nat (encodable.Union_decodeβ_disjoint_on hd)
(Ξ» n, encodable.Union_decodeβ_cases d.has_empty h) }
theorem has_union {sβ sβ : set Ξ±}
(hβ : d.has sβ) (hβ : d.has sβ) (h : sβ β© sβ β β
) : d.has (sβ βͺ sβ) :=
by { rw union_eq_Union, exact
d.has_Union (pairwise_disjoint_on_bool.2 h) (bool.forall_bool.2 β¨hβ, hββ©) }
lemma has_diff {sβ sβ : set Ξ±} (hβ : d.has sβ) (hβ : d.has sβ) (h : sβ β sβ) : d.has (sβ \ sβ) :=
begin
apply d.has_compl_iff.1,
simp [diff_eq, compl_inter],
exact d.has_union (d.has_compl hβ) hβ (Ξ» x β¨hβ, hββ©, hβ (h hβ)),
end
instance : partial_order (dynkin_system Ξ±) :=
{ le := Ξ» mβ mβ, mβ.has β€ mβ.has,
le_refl := assume a b, le_refl _,
le_trans := assume a b c, le_trans,
le_antisymm := assume a b hβ hβ, ext $ assume s, β¨hβ s, hβ sβ© }
/-- Every measurable space (Ο-algebra) forms a Dynkin system -/
def of_measurable_space (m : measurable_space Ξ±) : dynkin_system Ξ± :=
{ has := m.measurable_set',
has_empty := m.measurable_set_empty,
has_compl := m.measurable_set_compl,
has_Union_nat := assume f _ hf, m.measurable_set_Union f hf }
lemma of_measurable_space_le_of_measurable_space_iff {mβ mβ : measurable_space Ξ±} :
of_measurable_space mβ β€ of_measurable_space mβ β mβ β€ mβ :=
iff.rfl
/-- The least Dynkin system containing a collection of basic sets.
This inductive type gives the underlying collection of sets. -/
inductive generate_has (s : set (set Ξ±)) : set Ξ± β Prop
| basic : β t β s, generate_has t
| empty : generate_has β
| compl : β {a}, generate_has a β generate_has aαΆ
| Union : β {f : β β set Ξ±}, pairwise (disjoint on f) β
(β i, generate_has (f i)) β generate_has (β i, f i)
lemma generate_has_compl {C : set (set Ξ±)} {s : set Ξ±} : generate_has C sαΆ β generate_has C s :=
by { refine β¨_, generate_has.complβ©, intro h, convert generate_has.compl h, simp }
/-- The least Dynkin system containing a collection of basic sets. -/
def generate (s : set (set Ξ±)) : dynkin_system Ξ± :=
{ has := generate_has s,
has_empty := generate_has.empty,
has_compl := assume a, generate_has.compl,
has_Union_nat := assume f, generate_has.Union }
lemma generate_has_def {C : set (set Ξ±)} : (generate C).has = generate_has C := rfl
instance : inhabited (dynkin_system Ξ±) := β¨generate univβ©
/-- If a Dynkin system is closed under binary intersection, then it forms a `Ο`-algebra. -/
def to_measurable_space (h_inter : β sβ sβ, d.has sβ β d.has sβ β d.has (sβ β© sβ)) :=
{ measurable_space .
measurable_set' := d.has,
measurable_set_empty := d.has_empty,
measurable_set_compl := assume s h, d.has_compl h,
measurable_set_Union := Ξ» f hf,
begin
rw βUnion_disjointed,
exact d.has_Union (disjoint_disjointed _)
(Ξ» n, disjointed_rec (Ξ» t i h, h_inter _ _ h $ d.has_compl $ hf i) (hf n)),
end }
lemma of_measurable_space_to_measurable_space
(h_inter : β sβ sβ, d.has sβ β d.has sβ β d.has (sβ β© sβ)) :
of_measurable_space (d.to_measurable_space h_inter) = d :=
ext $ assume s, iff.rfl
/-- If `s` is in a Dynkin system `d`, we can form the new Dynkin system `{s β© t | t β d}`. -/
def restrict_on {s : set Ξ±} (h : d.has s) : dynkin_system Ξ± :=
{ has := Ξ» t, d.has (t β© s),
has_empty := by simp [d.has_empty],
has_compl := assume t hts,
have tαΆ β© s = ((t β© s)αΆ) \ sαΆ,
from set.ext $ assume x, by { by_cases x β s; simp [h] },
by { rw [this], exact d.has_diff (d.has_compl hts) (d.has_compl h)
(compl_subset_compl.mpr $ inter_subset_right _ _) },
has_Union_nat := assume f hd hf,
begin
rw [inter_comm, inter_Union],
apply d.has_Union_nat,
{ exact Ξ» i j h x β¨β¨_, hββ©, _, hββ©, hd i j h β¨hβ, hββ© },
{ simpa [inter_comm] using hf },
end }
lemma generate_le {s : set (set Ξ±)} (h : β t β s, d.has t) : generate s β€ d :=
Ξ» t ht, ht.rec_on h d.has_empty
(assume a _ h, d.has_compl h)
(assume f hd _ hf, d.has_Union hd hf)
lemma generate_has_subset_generate_measurable {C : set (set Ξ±)} {s : set Ξ±}
(hs : (generate C).has s) : (generate_from C).measurable_set' s :=
generate_le (of_measurable_space (generate_from C)) (Ξ» t, measurable_set_generate_from) s hs
lemma generate_inter {s : set (set Ξ±)}
(hs : is_pi_system s) {tβ tβ : set Ξ±}
(htβ : (generate s).has tβ) (htβ : (generate s).has tβ) : (generate s).has (tβ β© tβ) :=
have generate s β€ (generate s).restrict_on htβ,
from generate_le _ $ assume sβ hsβ,
have (generate s).has sβ, from generate_has.basic sβ hsβ,
have generate s β€ (generate s).restrict_on this,
from generate_le _ $ assume sβ hsβ,
show (generate s).has (sβ β© sβ), from
(sβ β© sβ).eq_empty_or_nonempty.elim
(Ξ» h, h.symm βΈ generate_has.empty)
(Ξ» h, generate_has.basic _ (hs _ _ hsβ hsβ h)),
have (generate s).has (tβ β© sβ), from this _ htβ,
show (generate s).has (sβ β© tβ), by rwa [inter_comm],
this _ htβ
/--
**Dynkin's Ο-Ξ» theorem**:
Given a collection of sets closed under binary intersections, then the Dynkin system it
generates is equal to the Ο-algebra it generates.
This result is known as the Ο-Ξ» theorem.
A collection of sets closed under binary intersection is called a Ο-system (often requiring
additionnally that is is non-empty, but we drop this condition in the formalization).
-/
lemma generate_from_eq {s : set (set Ξ±)} (hs : is_pi_system s) :
generate_from s = (generate s).to_measurable_space (Ξ» tβ tβ, generate_inter hs) :=
le_antisymm
(generate_from_le $ assume t ht, generate_has.basic t ht)
(of_measurable_space_le_of_measurable_space_iff.mp $
by { rw [of_measurable_space_to_measurable_space],
exact (generate_le _ $ assume t ht, measurable_set_generate_from ht) })
end dynkin_system
theorem induction_on_inter {C : set Ξ± β Prop} {s : set (set Ξ±)} [m : measurable_space Ξ±]
(h_eq : m = generate_from s) (h_inter : is_pi_system s)
(h_empty : C β
) (h_basic : β t β s, C t) (h_compl : β t, measurable_set t β C t β C tαΆ)
(h_union : β f : β β set Ξ±, pairwise (disjoint on f) β
(β i, measurable_set (f i)) β (β i, C (f i)) β C (β i, f i)) :
β β¦tβ¦, measurable_set t β C t :=
have eq : measurable_set = dynkin_system.generate_has s,
by { rw [h_eq, dynkin_system.generate_from_eq h_inter], refl },
assume t ht,
have dynkin_system.generate_has s t, by rwa [eq] at ht,
this.rec_on h_basic h_empty
(assume t ht, h_compl t $ by { rw [eq], exact ht })
(assume f hf ht, h_union f hf $ assume i, by { rw [eq], exact ht _ })
end measurable_space
|
784e7d4341a9e58330e1714cd2c162c5ff8ad61c
|
735bb6d9c54e20a6bdc031c27bff1717e68886b9
|
/tools/auto/experiments/set_basic.lean
|
d6521a984b56ae86cae3a2675cab110fa5401077
|
[] |
no_license
|
digama0/library_dev
|
3ea441564c4d7eca54a562b701febaa4db6a1061
|
56520d5d1dda46d87c98bf3acdf850672fdab00f
|
refs/heads/master
| 1,611,047,574,219
| 1,500,469,648,000
| 1,500,469,648,000
| 87,738,883
| 0
| 0
| null | 1,491,771,880,000
| 1,491,771,879,000
| null |
UTF-8
|
Lean
| false
| false
| 28,086
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Test examples for "finish".
-/
import data.set
import ....logic.basic
import ....algebra.lattice
import ..finish
open function lattice auto
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
namespace set
@[simp]
lemma mem_set_of {a : Ξ±} {p : Ξ± β Prop} : a β {a | p a} = p a :=
rfl
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
theorem subset_def {s t : set Ξ±} : (s β t) = β x, x β s β x β t := rfl
theorem union_def {sβ sβ : set Ξ±} : sβ βͺ sβ = {a | a β sβ β¨ a β sβ} := rfl
theorem inter_def {sβ sβ : set Ξ±} : sβ β© sβ = {a | a β sβ β§ a β sβ} := rfl
theorem union_subset {s t r : set Ξ±} (sr : s β r) (tr : t β r) : s βͺ t β r :=
by finish [subset_def, union_def]
/- old proof
theorem union_subset {s t r : set Ξ±} (sr : s β r) (tr : t β r) : s βͺ t β r :=
Ξ» x xst, or.elim xst (Ξ» xs, sr xs) (Ξ» xt, tr xt)
-/
theorem inter_subset_left (s t : set Ξ±) : s β© t β s := Ξ» x H, and.left H
theorem inter_subset_right (s t : set Ξ±) : s β© t β t := Ξ» x H, and.right H
theorem subset_inter {s t r : set Ξ±} (rs : r β s) (rt : r β t) : r β s β© t :=
by finish [subset_def, inter_def]
/- old proof
theorem subset_inter {s t r : set Ξ±} (rs : r β s) (rt : r β t) : r β s β© t :=
Ξ» x xr, and.intro (rs xr) (rt xr)
-/
instance lattice_set : complete_lattice (set Ξ±) :=
{ lattice.complete_lattice .
le := has_subset.subset,
le_refl := subset.refl,
le_trans := assume a b c, subset.trans,
le_antisymm := assume a b, subset.antisymm,
sup := has_union.union,
le_sup_left := subset_union_left,
le_sup_right := subset_union_right,
sup_le := assume a b c, union_subset,
inf := set.inter,
inf_le_left := inter_subset_left,
inf_le_right := inter_subset_right,
le_inf := assume a b c, subset_inter,
top := {a | true },
le_top := assume s a h, trivial,
bot := β
,
bot_le := assume s a, false.elim,
Sup := Ξ»s, {a | β t β s, a β t },
le_Sup := assume s t t_in a a_in, β¨t, β¨t_in, a_inβ©β©,
Sup_le := assume s t h a β¨t', β¨t'_in, a_inβ©β©, h t' t'_in a_in,
Inf := Ξ»s, {a | β t β s, a β t },
le_Inf := assume s t h a a_in t' t'_in, h t' t'_in a_in,
Inf_le := assume s t t_in a h, h _ t_in }
/- strict subset -/
def strict_subset (a b : set Ξ±) := a β b β§ a β b
instance : has_ssubset (set Ξ±) := β¨strict_subsetβ©
/- empty set -/
attribute [simp] mem_empty_eq empty_subset
theorem set_eq_def (s t : set Ξ±) : s = t β β x, x β s β x β t :=
β¨begin intros h x, rw h end, set.extβ©
theorem empty_def : (β
: set Ξ±) = { x | false } := rfl
theorem exists_mem_of_ne_empty {s : set Ξ±} (h : s β β
) : β x, x β s :=
by finish [set_eq_def]
/- old proof
theorem exists_mem_of_ne_empty {s : set Ξ±} (h : s β β
) : β x, x β s :=
classical.by_contradiction
(assume : Β¬ β x, x β s,
have β x, x β s, from forall_not_of_not_exists this,
show false, from h (eq_empty_of_forall_not_mem this))
-/
theorem subset_empty_iff (s : set Ξ±) : s β β
β s = β
:=
by finish [set_eq_def]
/- old proof
theorem subset_empty_iff (s : set Ξ±) : s β β
β s = β
:=
iff.intro eq_empty_of_subset_empty (assume xeq, begin rw xeq, apply subset.refl end)
-/
lemma bounded_forall_empty_iff {p : Ξ± β Prop} :
(β x β (β
: set Ξ±), p x) β true :=
by finish [iff_def]
/- old proof
lemma bounded_forall_empty_iff {p : Ξ± β Prop} :
(β x β (β
: set Ξ±), p x) β true :=
iff.intro (assume H, true.intro) (assume H x H1, absurd H1 (not_mem_empty _))
-/
/- universal set -/
theorem mem_univ (x : Ξ±) : x β @univ Ξ± :=
by trivial
theorem mem_univ_iff (x : Ξ±) : x β @univ Ξ± β true := iff.rfl
@[simp]
theorem mem_univ_eq (x : Ξ±) : x β @univ Ξ± = true := rfl
theorem empty_ne_univ [h : inhabited Ξ±] : (β
: set Ξ±) β univ :=
by clarify [set_eq_def]
/- old proof
theorem empty_ne_univ [h : inhabited Ξ±] : (β
: set Ξ±) β univ :=
assume H : β
= univ,
absurd (mem_univ (inhabited.default Ξ±)) (eq.rec_on H (not_mem_empty _))
-/
theorem univ_def : @univ Ξ± = { x | true } := rfl
@[simp]
theorem subset_univ (s : set Ξ±) : s β univ := Ξ» x H, trivial
theorem eq_univ_of_univ_subset {s : set Ξ±} (h : univ β s) : s = univ :=
by finish [subset_def, set_eq_def]
/- old proof
theorem eq_univ_of_univ_subset {s : set Ξ±} (h : univ β s) : s = univ :=
eq_of_subset_of_subset (subset_univ s) h
-/
theorem eq_univ_of_forall {s : set Ξ±} (H : β x, x β s) : s = univ :=
by finish [set_eq_def]
/-
theorem eq_univ_of_forall {s : set Ξ±} (H : β x, x β s) : s = univ :=
ext (assume x, iff.intro (assume H', trivial) (assume H', H x))
-/
/- union -/
theorem mem_union_left {x : Ξ±} {a : set Ξ±} (b : set Ξ±) : x β a β x β a βͺ b :=
assume h, or.inl h
theorem mem_union_right {x : Ξ±} {b : set Ξ±} (a : set Ξ±) : x β b β x β a βͺ b :=
assume h, or.inr h
theorem mem_unionl {x : Ξ±} {a b : set Ξ±} : x β a β x β a βͺ b :=
assume h, or.inl h
theorem mem_unionr {x : Ξ±} {a b : set Ξ±} : x β b β x β a βͺ b :=
assume h, or.inr h
theorem mem_or_mem_of_mem_union {x : Ξ±} {a b : set Ξ±} (H : x β a βͺ b) : x β a β¨ x β b := H
theorem mem_union.elim {x : Ξ±} {a b : set Ξ±} {P : Prop}
(Hβ : x β a βͺ b) (Hβ : x β a β P) (Hβ : x β b β P) : P :=
or.elim Hβ Hβ Hβ
theorem mem_union_iff (x : Ξ±) (a b : set Ξ±) : x β a βͺ b β x β a β¨ x β b := iff.rfl
@[simp]
theorem mem_union_eq (x : Ξ±) (a b : set Ξ±) : x β a βͺ b = (x β a β¨ x β b) := rfl
attribute [simp] union_self union_empty empty_union -- union_comm union_assoc
theorem union_left_comm (sβ sβ sβ : set Ξ±) : sβ βͺ (sβ βͺ sβ) = sβ βͺ (sβ βͺ sβ) :=
by finish [set_eq_def]
/- old proof
theorem union_left_comm (sβ sβ sβ : set Ξ±) : sβ βͺ (sβ βͺ sβ) = sβ βͺ (sβ βͺ sβ) :=
by rw [βunion_assoc, union_comm sβ, union_assoc]
-/
theorem union_right_comm (sβ sβ sβ : set Ξ±) : (sβ βͺ sβ) βͺ sβ = (sβ βͺ sβ) βͺ sβ :=
by finish [set_eq_def]
/- old proof
theorem union_right_comm (sβ sβ sβ : set Ξ±) : (sβ βͺ sβ) βͺ sβ = (sβ βͺ sβ) βͺ sβ :=
by rw [union_assoc, union_comm sβ, union_assoc]
-/
theorem union_eq_self_of_subset_left {s t : set Ξ±} (h : s β t) : s βͺ t = t :=
by finish [subset_def, set_eq_def, iff_def]
/- old proof
theorem union_eq_self_of_subset_left {s t : set Ξ±} (h : s β t) : s βͺ t = t :=
eq_of_subset_of_subset (union_subset h (subset.refl _)) (subset_union_right _ _)
-/
theorem union_eq_self_of_subset_right {s t : set Ξ±} (h : t β s) : s βͺ t = s :=
by finish [subset_def, set_eq_def, iff_def]
/- old proof
theorem union_eq_self_of_subset_right {s t : set Ξ±} (h : t β s) : s βͺ t = s :=
by rw [union_comm, union_eq_self_of_subset_left h]
-/
attribute [simp] union_comm union_assoc union_left_comm
/- intersection -/
theorem mem_inter_iff (x : Ξ±) (a b : set Ξ±) : x β a β© b β x β a β§ x β b := iff.rfl
@[simp]
theorem mem_inter_eq (x : Ξ±) (a b : set Ξ±) : x β a β© b = (x β a β§ x β b) := rfl
theorem mem_inter {x : Ξ±} {a b : set Ξ±} (ha : x β a) (hb : x β b) : x β a β© b :=
β¨ha, hbβ©
theorem mem_of_mem_inter_left {x : Ξ±} {a b : set Ξ±} (h : x β a β© b) : x β a :=
h^.left
theorem mem_of_mem_inter_right {x : Ξ±} {a b : set Ξ±} (h : x β a β© b) : x β b :=
h^.right
attribute [simp] inter_self inter_empty empty_inter -- inter_comm inter_assoc
theorem nonempty_of_inter_nonempty_right {T : Type} {s t : set T} (h : s β© t β β
) : t β β
:=
by finish [set_eq_def, iff_def]
/- old proof
theorem nonempty_of_inter_nonempty_right {T : Type} {s t : set T} (h : s β© t β β
) : t β β
:=
assume : t = β
,
have s β© t = β
, from eq.subst (eq.symm this) (inter_empty s),
h this
-/
theorem nonempty_of_inter_nonempty_left {T : Type} {s t : set T} (h : s β© t β β
) : s β β
:=
by finish [set_eq_def, iff_def]
/- old proof
theorem nonempty_of_inter_nonempty_left {T : Type} {s t : set T} (h : s β© t β β
) : s β β
:=
assume : s = β
,
have s β© t = β
,
begin rw this, apply empty_inter end,
h this
-/
theorem inter_left_comm (sβ sβ sβ : set Ξ±) : sβ β© (sβ β© sβ) = sβ β© (sβ β© sβ) :=
by finish [set_eq_def, iff_def]
/- currently this does not work
theorem inter_left_comm' (sβ sβ sβ : set Ξ±) : sβ β© (sβ β© sβ) = sβ β© (sβ β© sβ) :=
begin simp [inter_assoc, inter_comm] end
-/
/- old proof
theorem inter_left_comm (sβ sβ sβ : set Ξ±) : sβ β© (sβ β© sβ) = sβ β© (sβ β© sβ) :=
by rw [βinter_assoc, inter_comm sβ, inter_assoc]
-/
theorem inter_right_comm (sβ sβ sβ : set Ξ±) : (sβ β© sβ) β© sβ = (sβ β© sβ) β© sβ :=
by finish [set_eq_def, iff_def]
/- old proof
theorem inter_right_comm (sβ sβ sβ : set Ξ±) : (sβ β© sβ) β© sβ = (sβ β© sβ) β© sβ :=
by rw [inter_assoc, inter_comm sβ, inter_assoc]
-/
theorem inter_univ (a : set Ξ±) : a β© univ = a :=
ext (assume x, and_true _)
theorem univ_inter (a : set Ξ±) : univ β© a = a :=
ext (assume x, true_and _)
theorem inter_subset_inter_right {s t : set Ξ±} (u : set Ξ±) (H : s β t) : s β© u β t β© u :=
by finish [subset_def]
/- old proof
theorem inter_subset_inter_right {s t : set Ξ±} (u : set Ξ±) (H : s β t) : s β© u β t β© u :=
assume x, assume xsu, and.intro (H (and.left xsu)) (and.right xsu)
-/
theorem inter_subset_inter_left {s t : set Ξ±} (u : set Ξ±) (H : s β t) : u β© s β u β© t :=
assume x, assume xus, and.intro (and.left xus) (H (and.right xus))
/- old proof
theorem inter_subset_inter_left {s t : set Ξ±} (u : set Ξ±) (H : s β t) : u β© s β u β© t :=
assume x, assume xus, and.intro (and.left xus) (H (and.right xus))
-/
theorem inter_eq_self_of_subset_left {s t : set Ξ±} (h : s β t) : s β© t = s :=
by finish [subset_def, set_eq_def, iff_def]
theorem inter_eq_self_of_subset_right {s t : set Ξ±} (h : t β s) : s β© t = t :=
by finish [subset_def, set_eq_def, iff_def]
/- old proofs
theorem inter_eq_self_of_subset_left {s t : set Ξ±} (h : s β t) : s β© t = s :=
eq_of_subset_of_subset (inter_subset_left _ _) (subset_inter (subset.refl _) h)
theorem inter_eq_self_of_subset_right {s t : set Ξ±} (h : t β s) : s β© t = t :=
by rw [inter_comm, inter_eq_self_of_subset_left h]
-/
attribute [simp] inter_comm inter_assoc inter_left_comm
/- distributivity laws -/
theorem inter_distrib_left (s t u : set Ξ±) : s β© (t βͺ u) = (s β© t) βͺ (s β© u) :=
ext (assume x, and_distrib _ _ _)
theorem inter_distrib_right (s t u : set Ξ±) : (s βͺ t) β© u = (s β© u) βͺ (t β© u) :=
ext (assume x, and_distrib_right _ _ _)
theorem union_distrib_left (s t u : set Ξ±) : s βͺ (t β© u) = (s βͺ t) β© (s βͺ u) :=
ext (assume x, or_distrib _ _ _)
theorem union_distrib_right (s t u : set Ξ±) : (s β© t) βͺ u = (s βͺ u) β© (t βͺ u) :=
ext (assume x, or_distrib_right _ _ _)
/- insert -/
theorem insert_def (x : Ξ±) (a : set Ξ±) : insert x a = { y | y = x β¨ y β a } := rfl
theorem subset_insert (x : Ξ±) (a : set Ξ±) : a β insert x a :=
assume y, assume ys, or.inr ys
theorem mem_insert (x : Ξ±) (s : set Ξ±) : x β insert x s :=
or.inl rfl
theorem mem_insert_of_mem {x : Ξ±} {s : set Ξ±} (y : Ξ±) : x β s β x β insert y s :=
assume h, or.inr h
theorem eq_or_mem_of_mem_insert {x a : Ξ±} {s : set Ξ±} : x β insert a s β x = a β¨ x β s :=
assume h, h
theorem mem_of_mem_insert_of_ne {x a : Ξ±} {s : set Ξ±} (xin : x β insert a s) : x β a β x β s :=
by finish [insert_def]
/- old proof
theorem mem_of_mem_insert_of_ne {x a : Ξ±} {s : set Ξ±} (xin : x β insert a s) : x β a β x β s :=
or_resolve_right (eq_or_mem_of_mem_insert xin)
-/
@[simp]
theorem mem_insert_iff (x a : Ξ±) (s : set Ξ±) : x β insert a s β (x = a β¨ x β s) :=
iff.refl _
@[simp]
theorem insert_eq_of_mem {a : Ξ±} {s : set Ξ±} (h : a β s) : insert a s = s :=
by finish [set_eq_def, iff_def]
/- old proof
@[simp]
theorem insert_eq_of_mem {a : Ξ±} {s : set Ξ±} (h : a β s) : insert a s = s :=
ext (assume x, iff.intro
(begin intro h, cases h with h' h', rw h', exact h, exact h' end)
(mem_insert_of_mem _))
-/
theorem insert_comm (a b : Ξ±) (s : set Ξ±) : insert a (insert b s) = insert b (insert a s) :=
ext (assume c, by simp)
-- TODO(Jeremy): make this automatic
theorem insert_ne_empty (a : Ξ±) (s : set Ξ±) : insert a s β β
:=
begin
safe [set_eq_def, iff_def],
have h' := h a, clear h, finish
end
--begin safe [set_eq_def, iff_def]; have h' := h a; finish end
/- old proof
theorem insert_ne_empty (a : Ξ±) (s : set Ξ±) : insert a s β β
:=
Ξ» h, absurd (mem_insert a s) begin rw h, apply not_mem_empty end
-/
-- useful in proofs by induction
theorem forall_of_forall_insert {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} (h : β x, x β insert a s β P x) :
β x, x β s β P x :=
by finish
/- old proof
theorem forall_of_forall_insert {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} (h : β x, x β insert a s β P x) :
β x, x β s β P x :=
Ξ» x xs, h x (mem_insert_of_mem _ xs)
-/
theorem forall_insert_of_forall {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} (h : β x, x β s β P x) (ha : P a) :
β x, x β insert a s β P x :=
by finish
/- old proof
theorem forall_insert_of_forall {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} (h : β x, x β s β P x) (ha : P a) :
β x, x β insert a s β P x
| ._ (or.inl rfl) := ha
| x (or.inr p) := h x p
-/
lemma bounded_forall_insert_iff {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} :
(β x β insert a s, P x) β P a β§ (βx β s, P x) :=
by finish [iff_def]
/- old proof
lemma bounded_forall_insert_iff {P : Ξ± β Prop} {a : Ξ±} {s : set Ξ±} :
(β x β insert a s, P x) β P a β§ (βx β s, P x) :=
β¨assume h, β¨h a $ mem_insert a s, forall_of_forall_insert hβ©,
assume β¨P_a, hβ©, forall_insert_of_forall h P_aβ©
-/
/- properties of singletons -/
theorem singleton_def (a : Ξ±) : ({a} : set Ξ±) = insert a β
:= rfl
@[simp]
theorem mem_singleton_iff (a b : Ξ±) : a β ({b} : set Ξ±) β a = b :=
by finish [singleton_def]
/- old proof
@[simp]
theorem mem_singleton_iff (a b : Ξ±) : a β ({b} : set Ξ±) β a = b :=
iff.intro
(assume ainb,
or.elim (ainb : a = b β¨ false) (Ξ» aeqb, aeqb) (Ξ» f, false.elim f))
(assume aeqb, or.inl aeqb)
-/
-- TODO: again, annotation needed
@[simp]
theorem mem_singleton (a : Ξ±) : a β ({a} : set Ξ±) := mem_insert a _
theorem eq_of_mem_singleton {x y : Ξ±} (h : x β ({y} : set Ξ±)) : x = y :=
by finish
/- old proof
theorem eq_of_mem_singleton {x y : Ξ±} (h : x β ({y} : set Ξ±)) : x = y :=
or.elim (eq_or_mem_of_mem_insert h)
(assume : x = y, this)
(assume : x β (β
: set Ξ±), absurd this (not_mem_empty _))
-/
theorem mem_singleton_of_eq {x y : Ξ±} (H : x = y) : x β ({y} : set Ξ±) :=
by finish
/- old proof
theorem mem_singleton_of_eq {x y : Ξ±} (H : x = y) : x β ({y} : set Ξ±) :=
eq.subst (eq.symm H) (mem_singleton y)
-/
theorem insert_eq (x : Ξ±) (s : set Ξ±) : insert x s = ({x} : set Ξ±) βͺ s :=
by finish [set_eq_def]
/- old proof
theorem insert_eq (x : Ξ±) (s : set Ξ±) : insert x s = ({x} : set Ξ±) βͺ s :=
ext (assume y, iff.intro
(assume : y β insert x s,
or.elim this (assume : y = x, or.inl (or.inl this)) (assume : y β s, or.inr this))
(assume : y β ({x} : set Ξ±) βͺ s,
or.elim this
(assume : y β ({x} : set Ξ±), or.inl (eq_of_mem_singleton this))
(assume : y β s, or.inr this)))
-/
@[simp] theorem insert_of_has_insert (x : Ξ±) (a : set Ξ±) : has_insert.insert x a = insert x a := rfl
@[simp]
theorem pair_eq_singleton (a : Ξ±) : ({a, a} : set Ξ±) = {a} :=
by finish
/- old proof
theorem pair_eq_singleton (a : Ξ±) : ({a, a} : set Ξ±) = {a} :=
begin rw insert_eq_of_mem, apply mem_singleton end
-/
theorem singleton_ne_empty (a : Ξ±) : ({a} : set Ξ±) β β
:= insert_ne_empty _ _
/- separation -/
theorem mem_sep {s : set Ξ±} {p : Ξ± β Prop} {x : Ξ±} (xs : x β s) (px : p x) : x β {x β s | p x} :=
β¨xs, pxβ©
@[simp]
theorem mem_sep_eq {s : set Ξ±} {p : Ξ± β Prop} {x : Ξ±} : x β {x β s | p x} = (x β s β§ p x) :=
rfl
theorem mem_sep_iff {s : set Ξ±} {p : Ξ± β Prop} {x : Ξ±} : x β {x β s | p x} β x β s β§ p x :=
iff.rfl
theorem eq_sep_of_subset {s t : set Ξ±} (ssubt : s β t) : s = {x β t | x β s} :=
by finish [set_eq_def, iff_def, subset_def]
/- old proof
theorem eq_sep_of_subset {s t : set Ξ±} (ssubt : s β t) : s = {x β t | x β s} :=
ext (assume x, iff.intro
(assume : x β s, β¨ssubt this, thisβ©)
(assume : x β {x β t | x β s}, this^.right))
-/
theorem sep_subset (s : set Ξ±) (p : Ξ± β Prop) : {x β s | p x} β s :=
assume x, assume H, and.left H
theorem forall_not_of_sep_empty {s : set Ξ±} {p : Ξ± β Prop} (h : {x β s | p x} = β
) :
β x β s, Β¬ p x :=
by finish [set_eq_def]
/- old proof
theorem forall_not_of_sep_empty {s : set Ξ±} {p : Ξ± β Prop} (h : {x β s | p x} = β
) :
β x β s, Β¬ p x :=
assume x, assume : x β s, assume : p x,
have x β {x β s | p x}, from β¨by assumption, thisβ©,
show false, from ne_empty_of_mem this h
-/
/- complement -/
theorem mem_compl {s : set Ξ±} {x : Ξ±} (h : x β s) : x β -s := h
theorem not_mem_of_mem_compl {s : set Ξ±} {x : Ξ±} (h : x β -s) : x β s := h
@[simp]
theorem mem_compl_eq (s : set Ξ±) (x : Ξ±) : x β -s = (x β s) := rfl
theorem mem_compl_iff (s : set Ξ±) (x : Ξ±) : x β -s β x β s := iff.rfl
@[simp]
theorem inter_compl_self (s : set Ξ±) : s β© -s = β
:=
by finish [set_eq_def]
@[simp]
theorem compl_inter_self (s : set Ξ±) : -s β© s = β
:=
by finish [set_eq_def]
@[simp]
theorem compl_empty : -(β
: set Ξ±) = univ :=
by finish [set_eq_def]
@[simp]
theorem compl_union (s t : set Ξ±) : -(s βͺ t) = -s β© -t :=
by finish [set_eq_def]
@[simp]
theorem compl_compl (s : set Ξ±) : -(-s) = s :=
by finish [set_eq_def]
-- ditto
theorem compl_inter (s t : set Ξ±) : -(s β© t) = -s βͺ -t :=
by finish [set_eq_def]
@[simp]
theorem compl_univ : -(univ : set Ξ±) = β
:=
by finish [set_eq_def]
theorem union_eq_compl_compl_inter_compl (s t : set Ξ±) : s βͺ t = -(-s β© -t) :=
by simp [compl_inter, compl_compl]
theorem inter_eq_compl_compl_union_compl (s t : set Ξ±) : s β© t = -(-s βͺ -t) :=
by simp [compl_compl]
theorem union_compl_self (s : set Ξ±) : s βͺ -s = univ :=
by finish [set_eq_def]
theorem compl_union_self (s : set Ξ±) : -s βͺ s = univ :=
by finish [set_eq_def]
theorem compl_comp_compl : compl β compl = @id (set Ξ±) :=
funext (Ξ» s, compl_compl s)
/- old proofs
@[simp]
theorem inter_compl_self (s : set Ξ±) : s β© -s = β
:=
ext (assume x, and_not_self_iff _)
@[simp]
theorem compl_inter_self (s : set Ξ±) : -s β© s = β
:=
ext (assume x, not_and_self_iff _)
@[simp]
theorem compl_empty : -(β
: set Ξ±) = univ :=
ext (assume x, not_false_iff)
@[simp]
theorem compl_union (s t : set Ξ±) : -(s βͺ t) = -s β© -t :=
ext (assume x, not_or_iff _ _)
theorem compl_compl (s : set Ξ±) : -(-s) = s :=
ext (assume x, classical.not_not_iff _)
-- ditto
theorem compl_inter (s t : set Ξ±) : -(s β© t) = -s βͺ -t :=
ext (assume x, classical.not_and_iff _ _)
@[simp]
theorem compl_univ : -(univ : set Ξ±) = β
:=
ext (assume x, not_true_iff)
theorem union_eq_compl_compl_inter_compl (s t : set Ξ±) : s βͺ t = -(-s β© -t) :=
by simp [compl_inter, compl_compl]
theorem inter_eq_compl_compl_union_compl (s t : set Ξ±) : s β© t = -(-s βͺ -t) :=
by simp [compl_compl]
theorem union_compl_self (s : set Ξ±) : s βͺ -s = univ :=
ext (assume x, classical.or_not_self_iff _)
theorem compl_union_self (s : set Ξ±) : -s βͺ s = univ :=
ext (assume x, classical.not_or_self_iff _)
theorem compl_comp_compl : compl β compl = @id (set Ξ±) :=
funext (Ξ» s, compl_compl s)
-/
/- set difference -/
theorem diff_eq (s t : set Ξ±) : s \ t = s β© -t := rfl
theorem mem_diff {s t : set Ξ±} {x : Ξ±} (h1 : x β s) (h2 : x β t) : x β s \ t :=
β¨h1, h2β©
theorem mem_of_mem_diff {s t : set Ξ±} {x : Ξ±} (h : x β s \ t) : x β s :=
h^.left
theorem not_mem_of_mem_diff {s t : set Ξ±} {x : Ξ±} (h : x β s \ t) : x β t :=
h^.right
theorem mem_diff_iff (s t : set Ξ±) (x : Ξ±) : x β s \ t β x β s β§ x β t := iff.rfl
@[simp]
theorem mem_diff_eq (s t : set Ξ±) (x : Ξ±) : x β s \ t = (x β s β§ x β t) := rfl
theorem union_diff_cancel {s t : set Ξ±} (h : s β t) : s βͺ (t \ s) = t :=
by finish [set_eq_def, iff_def, subset_def]
theorem diff_subset (s t : set Ξ±) : s \ t β s :=
by finish [subset_def]
theorem compl_eq_univ_diff (s : set Ξ±) : -s = univ \ s :=
by finish [set_eq_def]
/- old proofs
theorem union_diff_cancel {s t : set Ξ±} (h : s β t) : s βͺ (t \ s) = t :=
begin rw [diff_eq, union_distrib_left, union_compl_self, inter_univ,
union_eq_self_of_subset_left h] end
theorem diff_subset (s t : set Ξ±) : s \ t β s := @inter_subset_left _ s _
theorem compl_eq_univ_diff (s : set Ξ±) : -s = univ \ s :=
ext (assume x, iff.intro (assume H, and.intro trivial H) (assume H, and.right H))
-/
/- powerset -/
theorem mem_powerset {x s : set Ξ±} (h : x β s) : x β powerset s := h
theorem subset_of_mem_powerset {x s : set Ξ±} (h : x β powerset s) : x β s := h
theorem mem_powerset_iff (x s : set Ξ±) : x β powerset s β x β s := iff.rfl
/- function image -/
section image
@[reducible] def eq_on (f1 f2 : Ξ± β Ξ²) (a : set Ξ±) : Prop :=
β x β a, f1 x = f2 x
-- TODO(Jeremy): use bounded exists in image
theorem mem_image_eq (f : Ξ± β Ξ²) (s : set Ξ±) (y: Ξ²) : y β image f s = β x, x β s β§ f x = y :=
rfl
-- the introduction rule
theorem mem_image {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} {y : Ξ²} (hβ : x β s) (hβ : f x = y) :
y β image f s :=
β¨x, hβ, hββ©
theorem mem_image_of_mem (f : Ξ± β Ξ²) {x : Ξ±} {a : set Ξ±} (h : x β a) : f x β image f a :=
mem_image h rfl
def mem_image_elim {f : Ξ± β Ξ²} {s : set Ξ±} {C : Ξ² β Prop} (h : β (x : Ξ±), x β s β C (f x)) :
β{y : Ξ²}, y β image f s β C y
| ._ β¨a, a_in, rflβ© := h a a_in
def mem_image_elim_on {f : Ξ± β Ξ²} {s : set Ξ±} {C : Ξ² β Prop} {y : Ξ²} (h_y : y β image f s)
(h : β (x : Ξ±), x β s β C (f x)) : C y :=
mem_image_elim h h_y
theorem image_eq_image_of_eq_on {fβ fβ : Ξ± β Ξ²} {s : set Ξ±} (heq : eq_on fβ fβ s) :
image fβ s = image fβ s :=
by finish [set_eq_def, iff_def, mem_image_eq, eq_on]
/- old proof
theorem image_eq_image_of_eq_on {fβ fβ : Ξ± β Ξ²} {s : set Ξ±} (heq : eq_on fβ fβ s) :
fβ ' s = fβ ' s :=
ext (assume y, iff.intro
(assume β¨x, xs, fβxeqβ©, mem_image xs ((heq x xs)^.symm^.trans fβxeq))
(assume β¨x, xs, fβxeqβ©, mem_image xs ((heq x xs)^.trans fβxeq)))
-/
-- TODO(Jeremy): make automatic
lemma image_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (a : set Ξ±) : image (f β g) a = image f (image g a) :=
begin
safe [set_eq_def, iff_def, mem_image_eq, comp],
have h' := h_1 (g a_1),
finish
end
/- old proof
lemma image_comp (f : Ξ² β Ξ³) (g : Ξ± β Ξ²) (a : set Ξ±) : (f β g) ' a = f ' (g ' a) :=
ext (assume z,
iff.intro
(assume β¨x, (hxβ : x β a), (hxβ : f (g x) = z)β©,
have g x β g ' a,
from mem_image hxβ rfl,
show z β f ' (g ' a),
from mem_image this hxβ)
(assume β¨y, β¨x, (hzβ : x β a), (hzβ : g x = y)β©, (hyβ : f y = z)β©,
have f (g x) = z,
from eq.subst (eq.symm hzβ) hyβ,
show z β (f β g) ' a,
from mem_image hzβ this))
-/
lemma image_subset {a b : set Ξ±} (f : Ξ± β Ξ²) (h : a β b) : image f a β image f b :=
by finish [subset_def, mem_image_eq]
/- old_proof
lemma image_subset {a b : set Ξ±} (f : Ξ± β Ξ²) (h : a β b) : f ' a β f ' b :=
assume y,
assume β¨x, hxβ, hxββ©,
mem_image (h hxβ) hxβ
-/
theorem image_union (f : Ξ± β Ξ²) (s t : set Ξ±) :
image f (s βͺ t) = image f s βͺ image f t :=
by finish [set_eq_def, iff_def, mem_image_eq]
/- old proof
theorem image_union (f : Ξ± β Ξ²) (s t : set Ξ±) :
image f (s βͺ t) = image f s βͺ image f t :=
ext (assume y, iff.intro
(assume β¨x, (xst : x β s βͺ t), (fxy : f x = y)β©,
or.elim xst
(assume xs, or.inl (mem_image xs fxy))
(assume xt, or.inr (mem_image xt fxy)))
(assume H : y β image f s βͺ image f t,
or.elim H
(assume β¨x, (xs : x β s), (fxy : f x = y)β©,
mem_image (or.inl xs) fxy)
(assume β¨x, (xt : x β t), (fxy : f x = y)β©,
mem_image (or.inr xt) fxy)))
-/
theorem image_empty (f : Ξ± β Ξ²) : image f β
= β
:=
by finish [set_eq_def, mem_image_eq]
/- old proof
theorem image_empty (f : Ξ± β Ξ²) : image f β
= β
:=
eq_empty_of_forall_not_mem (assume y, assume β¨x, (h : x β β
), h'β©, h)
-/
theorem fix_set_compl (t : set Ξ±) : compl t = - t := rfl
-- TODO(Jeremy): there is an issue with - t unfolding to compl t
theorem mem_image_compl (t : set Ξ±) (S : set (set Ξ±)) :
t β image compl S β -t β S :=
begin
safe [mem_image_eq, iff_def, fix_set_compl],
have h' := h_1 (- t),
safe [compl_compl],
rw compl_compl at h, contradiction
-- TODO(Jeremy): figure out why safe [compl_compl] doesn't solve it.
end
/- old proof
theorem mem_image_compl (t : set Ξ±) (S : set (set Ξ±)) :
t β compl ' S β -t β S :=
iff.intro
(assume β¨t', (Ht' : t' β S), (Ht : -t' = t)β©,
show -t β S, begin rw [βHt, compl_compl], exact Ht' end)
(assume : -t β S,
have -(-t) β compl ' S, from mem_image_of_mem compl this,
show t β compl ' S, from compl_compl t βΈ this)
-/
theorem image_id (s : set Ξ±) : image id s = s :=
by finish [set_eq_def, iff_def, mem_image_eq]
/- old proof
theorem image_id (s : set Ξ±) : id ' s = s :=
ext (assume x, iff.intro
(assume β¨x', (hx' : x' β s), (x'eq : x' = x)β©,
show x β s, begin rw [βx'eq], apply hx' end)
(assume : x β s, mem_image_of_mem id this))
-/
theorem compl_compl_image (S : set (set Ξ±)) :
image compl (image compl S) = S :=
by rw [βimage_comp, compl_comp_compl, image_id]
lemma bounded_forall_image_of_bounded_forall {f : Ξ± β Ξ²} {s : set Ξ±} {p : Ξ² β Prop}
(h : β x β s, p (f x)) : β y β image f s, p y :=
by finish [mem_image_eq]
/- old proof
lemma bounded_forall_image_of_bounded_forall {f : Ξ± β Ξ²} {s : set Ξ±} {p : Ξ² β Prop}
(h : β x β s, p (f x)) : β y β f ' s, p y
| ._ β¨x, s_in, rflβ© := h x s_in
-/
lemma bounded_forall_image_iff {f : Ξ± β Ξ²} {s : set Ξ±} {p : Ξ² β Prop} :
(β y β image f s, p y) β (β x β s, p (f x)) :=
begin
safe [mem_image_eq, iff_def],
have h' := h_1 (f a),
finish
end
/- old proof
lemma bounded_forall_image_iff {f : Ξ± β Ξ²} {s : set Ξ±} {p : Ξ² β Prop} :
(β y β f ' s, p y) β (β x β s, p (f x)) :=
iff.intro (assume h x xs, h _ (mem_image_of_mem _ xs)) bounded_forall_image_of_bounded_forall
-/
lemma image_insert_eq {f : Ξ± β Ξ²} {a : Ξ±} {s : set Ξ±} :
image f (insert a s) = insert (f a) (image f s) :=
begin
safe [set_eq_def, iff_def, mem_image_eq],
have h' := h_1 a,
finish
end
/- old proof
lemma image_insert_eq {f : Ξ± β Ξ²} {a : Ξ±} {s : set Ξ±} :
f ' insert a s = insert (f a) (f ' s) :=
set.ext $ assume x, β¨
assume h, match x, h with
| ._, β¨._, β¨or.inl rfl, rflβ©β© := mem_insert _ _
| ._, β¨b, β¨or.inr h, rflβ©β© := mem_insert_of_mem _ $ mem_image h rfl
end,
assume h, match x, h with
| ._, or.inl rfl := mem_image (mem_insert _ _) rfl
| ._, or.inr β¨x, β¨_, rflβ©β© := mem_image (mem_insert_of_mem _ βΉx β sβΊ) rfl
endβ©
-/
end image
-- TODO(Jeremy): stopped here.
end set
|
e2979705767fba644448394ac586fc98cd8533a2
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/hott/cubical/cubeover.hlean
|
87727cfed1ff49474a868fad6579f77476979f36
|
[
"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
| 4,216
|
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
Cubeovers
-/
import .squareover .cube
open equiv is_equiv
namespace eq
-- we need to specify B explicitly, also in pathovers
inductive cubeover {A : Type} (B : A β Type) {aβββ : A} {bβββ : B aβββ}
: Ξ {aβββ aβββ aβββ aβββ aβββ aβββ aβββ : A}
{pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
{pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
{pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
{pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
{sβββ : square pβββ pβββ pβββ pβββ}
{sβββ : square pβββ pβββ pβββ pβββ}
{sβββ : square pβββ pβββ pβββ pβββ}
{sβββ : square pβββ pβββ pβββ pβββ}
{sβββ : square pβββ pβββ pβββ pβββ}
{sβββ : square pβββ pβββ pβββ pβββ}
(c : cube sβββ sβββ sβββ sβββ sβββ sβββ)
{bβββ : B aβββ} {bβββ : B aβββ} {bβββ : B aβββ}
{bβββ : B aβββ} {bβββ : B aβββ} {bβββ : B aβββ} {bβββ : B aβββ}
{qβββ : pathover B bβββ pβββ bβββ} {qβββ : pathover B bβββ pβββ bβββ}
{qβββ : pathover B bβββ pβββ bβββ} {qβββ : pathover B bβββ pβββ bβββ}
{qβββ : pathover B bβββ pβββ bβββ} {qβββ : pathover B bβββ pβββ bβββ}
{qβββ : pathover B bβββ pβββ bβββ} {qβββ : pathover B bβββ pβββ bβββ}
{qβββ : pathover B bβββ pβββ bβββ} {qβββ : pathover B bβββ pβββ bβββ}
{qβββ : pathover B bβββ pβββ bβββ} {qβββ : pathover B bβββ pβββ bβββ}
(tβββ : squareover B sβββ qβββ qβββ qβββ qβββ)
(tβββ : squareover B sβββ qβββ qβββ qβββ qβββ)
(tβββ : squareover B sβββ qβββ qβββ qβββ qβββ)
(tβββ : squareover B sβββ qβββ qβββ qβββ qβββ)
(tβββ : squareover B sβββ qβββ qβββ qβββ qβββ)
(tβββ : squareover B sβββ qβββ qβββ qβββ qβββ), Type :=
idcubeo : cubeover B idc idso idso idso idso idso idso
-- variables {A : Type} {aβββ aβββ aβββ aβββ aβββ aβββ aβββ aβββ : A}
-- {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
-- {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
-- {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
-- {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ} {pβββ : aβββ = aβββ}
-- {sβββ : square pβββ pβββ pβββ pβββ}
-- {sβββ : square pβββ pβββ pβββ pβββ}
-- {sβββ : square pβββ pβββ pβββ pβββ}
-- {sβββ : square pβββ pβββ pβββ pβββ}
-- {sβββ : square pβββ pβββ pβββ pβββ}
-- {sβββ : square pβββ pβββ pβββ pβββ}
end eq
|
272a09c5e462e0a2ebfbdd5099b6aa6a13455342
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/tests/lean/run/rel_tac1.lean
|
781ba3d405ee56a7b71ef1f22011360e1018b5b1
|
[
"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
| 408
|
lean
|
open tactic
example (a b : nat) : a = a :=
by reflexivity
example (a : nat) (b : bool) : a == b β b == a :=
by do intros, symmetry, trace_state, assumption
print "-----------"
example (a : nat) (b : bool) (c : string) : a == b β b == c β a == c :=
by do
intro_lst [`H1, `H2],
transitivity,
trace_state,
get_local `H1 >>= exact,
assumption
example (a b : bool) : a == a :=
by reflexivity
|
40143fa0948070ed2d04f67da0a0cbab57f6cc39
|
5b273b8c05e2f73fb74340ce100ce261900a98cd
|
/limits.lean
|
8ceca0466e2655243c61e9c15ce1abe3b94be860
|
[] |
no_license
|
ChrisHughes24/leanstuff1
|
2eba44bc48da6e544e07495b41e1703f81dc1c24
|
cbcd788b8b1d07b20b2fff4482c870077a13d1c0
|
refs/heads/master
| 1,631,670,333,297
| 1,527,093,981,000
| 1,527,093,981,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 10,874
|
lean
|
import data.complex.basic tactic.ring
open is_absolute_value
lemma finset.exists_max {Ξ± : Type*} [decidable_linear_order Ξ±] [inhabited Ξ±] (s : finset Ξ±) : β a : Ξ±, β b : Ξ±, b β s β b β€ a := begin
apply finset.induction_on s,
existsi default Ξ±,simp,
assume a s as hi,
cases hi with m hm,
existsi max a m,
assume b,simp,assume h,
cases h with h h,
rw h, exact le_max_left _ _,
exact le_trans (hm b h) (le_max_right _ _),
end
lemma seq_bounded_above_of_cau {Ξ± : Type*} {Ξ² : Type*} [discrete_linear_ordered_field Ξ±]
[ring Ξ²] {f : β β Ξ²} {abv : Ξ² β Ξ±} [is_absolute_value abv] : is_cau_seq abv f β
β a : Ξ±, β i : β, abv (f i) < a := begin
assume h,unfold is_cau_seq at h,
have iΞ± : inhabited Ξ± := β¨0β©,
cases h 1 (by norm_num) with i hi,
have : β j : β, j β₯ i β abv (f j) - abv (f i) < 1,assume j ji,
have := hi j ji,
exact lt_of_le_of_lt (sub_abv_le_abv_sub _ _ _) this,
generalize hs : finset.image (Ξ» k, abv (f k)) (finset.range i) = s,
cases finset.exists_max s with ms hms,
existsi max (1 + abv (f i)) (ms + 1),assume iβ,
cases lt_or_ge iβ i,
have := finset.mem_image_of_mem (Ξ» (k : β), abv (f k)) (finset.mem_range.mpr h_1),rw hs at this,
have := hms _ this,simp at this,
exact lt_of_le_of_lt this (lt_of_lt_of_le (lt_add_one _) (le_max_right _ _)),
have := this iβ h_1,
rw sub_lt_iff_lt_add at this,
exact lt_of_lt_of_le this (le_max_left _ _),
end
section real
open real
lemma real.lim_const {f : β β β} (hf : is_cau_seq abs f) (x : β) : x = real.lim f β
cau_seq.const abs x β β¨f, hfβ© := begin
have := real.equiv_lim β¨f, hfβ©,split,assume h,rw h,simp at this,exact setoid.symm this,
assume h,have := setoid.trans h this,rw cau_seq.const_equiv at this,simp at this, exact this,
end
lemma real.lim_eq_lim_iff_equiv {f g : β β β} (hf : is_cau_seq abs f)
(hg : is_cau_seq abs g) : real.lim f = real.lim g β @has_equiv.equiv
(cau_seq β abs) _ β¨f, hfβ© β¨g, hgβ© := begin
have hβ:= real.lim_const hg (real.lim f),
have hβ:= real.lim_const hf (real.lim g),
split,assume h, simp * at *,
exact setoid.trans (setoid.symm hβ) hβ,
assume h,rw hβ,have := real.equiv_lim β¨f, hfβ©,simp at this,
exact setoid.trans (setoid.symm this) h,
end
-- would be useful to have is_cau_seq abs f β is_cau_seq abs g β is_cau_seq abs (Ξ» i, f i + g i)
-- in the library, similarly for mul
lemma real.lim_add {f g : β β β} (hf : is_cau_seq abs f)
(hg : is_cau_seq abs g) : real.lim f + real.lim g =
real.lim (Ξ» x, f x + g x) := begin
have : β (Ξ΅ : β),
Ξ΅ > 0 β (β (i : β), β (j : β), j β₯ i β abs (f j + (g j + (-real.lim f + -real.lim g))) < Ξ΅),
{assume Ξ΅ Ξ΅0,
cases real.equiv_lim β¨f, hfβ© (Ξ΅ / 2) (div_pos Ξ΅0 (by norm_num)) with fi hfi,simp at hfi,
cases real.equiv_lim β¨g, hgβ© (Ξ΅ / 2) (div_pos Ξ΅0 (by norm_num)) with gi hgi,simp at hgi,
existsi max fi gi,
assume j hj,rw [add_left_comm (g j),βadd_assoc (f j)],
refine lt_of_le_of_lt (abs_add _ _) _,rw βadd_halves Ξ΅,
exact add_lt_add (hfi j (le_trans (le_max_left _ _) hj)) (hgi j (le_trans (le_max_right _ _) hj))},
have cau : is_cau_seq abs (Ξ» (x : β), f x + g x), refine cau_seq.of_near _ (cau_seq.const abs (real.lim f + real.lim g)) _,simpa,
rw real.lim_const,refine setoid.symm _,exact cau,assume Ξ΅ Ξ΅0,simp,exact this Ξ΅ Ξ΅0,
end
lemma real.lim_mul {f g : β β β} (hf : is_cau_seq abs f)
(hg : is_cau_seq abs g) : real.lim f * real.lim g =
real.lim (Ξ» x, f x * g x) := begin
have : β (Ξ΅ : β),
Ξ΅ > 0 β (β (i : β), β (j : β), j β₯ i β abs (f j * g j - (real.lim f * real.lim g)) < Ξ΅),
{ assume Ξ΅ Ξ΅0,
cases seq_bounded_above_of_cau hg with G hG,
have G0 : 0 < G := lt_of_le_of_lt (abs_nonneg _) (hG 0),
have Gf : 0 < G + abs (lim f) := add_pos_of_pos_of_nonneg G0 (abs_nonneg _),
have GΞ΅ : 0 < Ξ΅ / (G + abs (lim f)) := div_pos Ξ΅0 Gf,
cases real.equiv_lim β¨f, hfβ© _ GΞ΅ with fi hfi, simp at hfi,
cases real.equiv_lim β¨g, hgβ© _ GΞ΅ with gi hgi, simp at hgi,
existsi max fi gi,assume j ji,
rw (by simp[mul_add,add_mul];ring : f j * g j -lim f * lim g = (f j - lim f) * g j + lim f * (g j - lim g)),
refine lt_of_le_of_lt (abs_add _ _) _,
rw [abs_mul],
suffices : abs (f j - lim f) * G + abs (lim f * (g j - lim g)) < Ξ΅,
exact lt_of_le_of_lt (add_le_add (mul_le_mul_of_nonneg_left (le_of_lt (hG j)) (abs_nonneg _)) (le_refl _)) this,
rw abs_mul,
have : Ξ΅ = Ξ΅ * G / (G + abs (lim f)) + Ξ΅ * abs (lim f) / (G + abs (lim f)),
{rw [βadd_div,βmul_add,mul_div_cancel _ (ne_of_lt Gf).symm]},
rw this,
refine add_lt_add_of_lt_of_le _ _,
{rw [mul_comm,mul_comm Ξ΅,mul_div_assoc],
exact mul_lt_mul_of_pos_left (hfi j (le_trans (le_max_left _ _) ji)) G0},
rw [mul_comm Ξ΅,mul_div_assoc],
refine mul_le_mul_of_nonneg_left (le_of_lt (hgi j (le_trans (le_max_right _ _) ji))) (abs_nonneg _)},
have cau : is_cau_seq abs (Ξ» (x : β), f x * g x), refine cau_seq.of_near _ (cau_seq.const abs (real.lim f * real.lim g)) _,simpa,
rw real.lim_const, refine setoid.symm _,exact cau,assume Ξ΅ Ξ΅0,simp, exact this Ξ΅ Ξ΅0,
end
end real
lemma complex.re_const_equiv_of_const_equiv {f : β β β} (hf : is_cau_seq complex.abs f) (z : β) :
cau_seq.const complex.abs z β β¨f, hfβ© β cau_seq.const abs z.re β β¨(Ξ» (n : β), (f n).re),
complex.is_cau_seq_re β¨f,hfβ©β© := begin
assume h,assume Ξ΅ Ξ΅0,cases h Ξ΅ Ξ΅0 with i hi,existsi i,assume j ji,
replace hi := hi j ji, simp at *, rw [βcomplex.neg_re,βcomplex.add_re],
exact lt_of_le_of_lt (complex.abs_re_le_abs _) hi,
end
lemma complex.im_const_equiv_of_const_equiv {f : β β β} (hf : is_cau_seq complex.abs f) (z : β) :
cau_seq.const complex.abs z β β¨f, hfβ© β cau_seq.const abs z.im β β¨(Ξ» (n : β), (f n).im),
complex.is_cau_seq_im β¨f,hfβ©β© := begin
assume h,assume Ξ΅ Ξ΅0,cases h Ξ΅ Ξ΅0 with i hi,existsi i,assume j ji,
replace hi := hi j ji, simp at *, rw [βcomplex.neg_im,βcomplex.add_im],
exact lt_of_le_of_lt (complex.abs_im_le_abs _) hi,
end
lemma complex.lim_const {f : β β β} (hf : is_cau_seq complex.abs f) (z : β) : z = complex.lim f β
cau_seq.const complex.abs z β β¨f, hfβ© := begin
split,have := complex.equiv_lim β¨f, hfβ©,simp at this,
assume h,rw h, exact setoid.symm this,assume h,
unfold complex.lim,cases z with zre zim,simp,
split, have := real.equiv_lim β¨(Ξ» (n : β), (f n).re), complex.is_cau_seq_re β¨f,hfβ©β©,
rw βcau_seq.const_equiv,simp at this,
have hf := complex.re_const_equiv_of_const_equiv hf {re := zre, im := zim} h,simp at hf,
exact setoid.trans hf this,
have := real.equiv_lim β¨(Ξ» (n : β), (f n).im), complex.is_cau_seq_im β¨f,hfβ©β©,
rw βcau_seq.const_equiv,simp at this,
have hf := complex.im_const_equiv_of_const_equiv hf {re := zre, im := zim} h,simp at hf,
exact setoid.trans hf this,
end
lemma complex.lim_eq_lim_iff_equiv {f g : β β β} (hf : is_cau_seq complex.abs f)
(hg : is_cau_seq complex.abs g) : complex.lim f = complex.lim g β @has_equiv.equiv
(cau_seq β complex.abs) _ β¨f, hfβ© β¨g, hgβ© := begin
have hβ:= complex.lim_const hg (complex.lim f),
have hβ:= complex.lim_const hf (complex.lim g),
split,assume h, simp * at *,
exact setoid.trans (setoid.symm hβ) hβ,
assume h,rw hβ,have := complex.equiv_lim β¨f, hfβ©,simp at this,
exact setoid.trans (setoid.symm this) h,
end
open complex
lemma complex.lim_add {f g : β β β} (hf : is_cau_seq complex.abs f)
(hg : is_cau_seq complex.abs g) : complex.lim f + complex.lim g =
complex.lim (Ξ» x, f x + g x) := begin
have : β (Ξ΅ : β),
Ξ΅ > 0 β (β (i : β), β (j : β), j β₯ i β complex.abs (f j + (g j + (-complex.lim f + -complex.lim g))) < Ξ΅),
{assume Ξ΅ Ξ΅0,
cases complex.equiv_lim β¨f, hfβ© (Ξ΅ / 2) (div_pos Ξ΅0 (by norm_num)) with fi hfi,simp at hfi,
cases complex.equiv_lim β¨g, hgβ© (Ξ΅ / 2) (div_pos Ξ΅0 (by norm_num)) with gi hgi,simp at hgi,
existsi max fi gi,
assume j hj,rw [add_left_comm (g j),βadd_assoc (f j)],
refine lt_of_le_of_lt (complex.abs_add _ _) _,rw βadd_halves Ξ΅,
exact add_lt_add (hfi j (le_trans (le_max_left _ _) hj)) (hgi j (le_trans (le_max_right _ _) hj))},
have cau : is_cau_seq complex.abs (Ξ» (x : β), f x + g x), refine cau_seq.of_near _ (cau_seq.const complex.abs (lim f + lim g)) _,simpa,
rw lim_const,refine setoid.symm _,exact cau,assume Ξ΅ Ξ΅0,simp,exact this Ξ΅ Ξ΅0,
end
lemma complex.lim_mul {f g : β β β} (hf : is_cau_seq complex.abs f)
(hg : is_cau_seq complex.abs g) : complex.lim f * complex.lim g =
complex.lim (Ξ» x, f x * g x) := begin
have : β (Ξ΅ : β),
Ξ΅ > 0 β (β (i : β), β (j : β), j β₯ i β complex.abs (f j * g j - (complex.lim f * complex.lim g)) < Ξ΅),
{ assume Ξ΅ Ξ΅0,
cases seq_bounded_above_of_cau hg with G hG,
have G0 : 0 < G := lt_of_le_of_lt (complex.abs_nonneg _) (hG 0),
have Gf : 0 < G + complex.abs (complex.lim f) := add_pos_of_pos_of_nonneg G0 (complex.abs_nonneg _),
have GΞ΅ : 0 < Ξ΅ / (G + complex.abs (complex.lim f)) := div_pos Ξ΅0 Gf,
cases complex.equiv_lim β¨f, hfβ© _ GΞ΅ with fi hfi, simp at hfi,
cases complex.equiv_lim β¨g, hgβ© _ GΞ΅ with gi hgi, simp at hgi,
existsi max fi gi,assume j ji,
rw (by simp[mul_add,add_mul];ring : f j * g j -complex.lim f * complex.lim g = (f j - complex.lim f) * g j + complex.lim f * (g j - complex.lim g)),
refine lt_of_le_of_lt (complex.abs_add _ _) _,
rw [complex.abs_mul],
suffices : complex.abs (f j - lim f) * G + complex.abs (lim f * (g j - lim g)) < Ξ΅,
exact lt_of_le_of_lt (add_le_add (mul_le_mul_of_nonneg_left (le_of_lt (hG j)) (abs_nonneg _)) (le_refl _)) this,
rw complex.abs_mul,
have : Ξ΅ = Ξ΅ * G / (G + abs (lim f)) + Ξ΅ * abs (lim f) / (G + abs (lim f)),
{rw [βadd_div,βmul_add,mul_div_cancel _ (ne_of_lt Gf).symm]},
rw this,
refine add_lt_add_of_lt_of_le _ _,
{rw [mul_comm,mul_comm Ξ΅,mul_div_assoc],
exact mul_lt_mul_of_pos_left (hfi j (le_trans (le_max_left _ _) ji)) G0},
rw [mul_comm Ξ΅,mul_div_assoc],
refine mul_le_mul_of_nonneg_left (le_of_lt (hgi j (le_trans (le_max_right _ _) ji))) (abs_nonneg _)},
have cau : is_cau_seq complex.abs (Ξ» (x : β), f x * g x), refine cau_seq.of_near _ (cau_seq.const abs (lim f * lim g)) _,simpa,
rw lim_const, refine setoid.symm _,exact cau,assume Ξ΅ Ξ΅0,simp, exact this Ξ΅ Ξ΅0,
end
|
ed011c832f292d6488db7e4a1f9078cfe53fc93b
|
947b78d97130d56365ae2ec264df196ce769371a
|
/src/Lean/Util/ReplaceLevel.lean
|
8767e7321103ac76802423e031f18068ab5e908e
|
[
"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
| 3,463
|
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
namespace Level
partial def replace (f? : Level β Option Level) : Level β Level
| u =>
match f? u with
| some v => v
| none => match u with
| max vβ vβ _ => mkLevelMax (replace vβ) (replace vβ)
| imax vβ vβ _ => mkLevelIMax (replace vβ) (replace vβ)
| succ v _ => mkLevelSucc (replace v)
| _ => u
end Level
namespace Expr
namespace ReplaceLevelImpl
abbrev cacheSize : USize := 8192
structure State :=
(keys : Array Expr) -- Remark: our "unsafe" implementation relies on the fact that `()` is not a valid Expr
(results : Array Expr)
abbrev ReplaceM := StateM State
@[inline] unsafe def cache (i : USize) (key : Expr) (result : Expr) : ReplaceM Expr := do
modify $ fun s => { keys := s.keys.uset i key lcProof, results := s.results.uset i result lcProof };
pure result
@[specialize] unsafe def replaceUnsafeM (f? : Level β Option Level) (size : USize) : Expr β ReplaceM Expr
| e => do
c β get;
let h := ptrAddrUnsafe e;
let i := h % size;
if ptrAddrUnsafe (c.keys.uget i lcProof) == h then
pure $ c.results.uget i lcProof
else match e with
| Expr.forallE _ d b _ => do d β replaceUnsafeM d; b β replaceUnsafeM b; cache i e $ e.updateForallE! d b
| Expr.lam _ d b _ => do d β replaceUnsafeM d; b β replaceUnsafeM b; cache i e $ e.updateLambdaE! d b
| Expr.mdata _ b _ => do b β replaceUnsafeM b; cache i e $ e.updateMData! b
| Expr.letE _ t v b _ => do t β replaceUnsafeM t; v β replaceUnsafeM v; b β replaceUnsafeM b; cache i e $ e.updateLet! t v b
| Expr.app f a _ => do f β replaceUnsafeM f; a β replaceUnsafeM a; cache i e $ e.updateApp! f a
| Expr.proj _ _ b _ => do b β replaceUnsafeM b; cache i e $ e.updateProj! b
| Expr.sort u _ => cache i e $ e.updateSort! (u.replace f?)
| Expr.const n us _ => cache i e $ e.updateConst! (us.map (Level.replace f?))
| Expr.localE _ _ _ _ => unreachable!
| e => pure e
unsafe def initCache : State :=
{ keys := mkArray cacheSize.toNat (cast lcProof ()), -- `()` is not a valid `Expr`
results := mkArray cacheSize.toNat (arbitrary _) }
@[inline] unsafe def replaceUnsafe (f? : Level β Option Level) (e : Expr) : Expr :=
(replaceUnsafeM f? cacheSize e).run' initCache
end ReplaceLevelImpl
@[implementedBy ReplaceLevelImpl.replaceUnsafe]
partial def replaceLevel (f? : Level β Option Level) : Expr β Expr
| e@(Expr.forallE _ d b _) => let d := replaceLevel d; let b := replaceLevel b; e.updateForallE! d b
| e@(Expr.lam _ d b _) => let d := replaceLevel d; let b := replaceLevel b; e.updateLambdaE! d b
| e@(Expr.mdata _ b _) => let b := replaceLevel b; e.updateMData! b
| e@(Expr.letE _ t v b _) => let t := replaceLevel t; let v := replaceLevel v; let b := replaceLevel b; e.updateLet! t v b
| e@(Expr.app f a _) => let f := replaceLevel f; let a := replaceLevel a; e.updateApp! f a
| e@(Expr.proj _ _ b _) => let b := replaceLevel b; e.updateProj! b
| e@(Expr.sort u _) => e.updateSort! (u.replace f?)
| e@(Expr.const n us _) => e.updateConst! (us.map (Level.replace f?))
| e => e
end Expr
end Lean
|
53a25e1ce59e42ab376504f5369e40409a8bb6aa
|
491068d2ad28831e7dade8d6dff871c3e49d9431
|
/hott/cubical/squareover.hlean
|
41b51adc13d85c19584068a37cec5c7ab8cd10d9
|
[
"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,881
|
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
Squareovers
-/
import .square
open eq equiv is_equiv equiv.ops
namespace eq
-- we give the argument B explicitly, because Lean would find (Ξ»a, B a) by itself, which
-- makes the type uglier (of course the two terms are definitionally equal)
inductive squareover {A : Type} (B : A β Type) {aββ : A} {bββ : B aββ} :
Ξ {aββ aββ aββ : A}
{pββ : aββ = aββ} {pββ : aββ = aββ} {pββ : aββ = aββ} {pββ : aββ = aββ}
(sββ : square pββ pββ pββ pββ)
{bββ : B aββ} {bββ : B aββ} {bββ : B aββ}
(qββ : pathover B bββ pββ bββ) (qββ : pathover B bββ pββ bββ)
(qββ : pathover B bββ pββ bββ) (qββ : pathover B bββ pββ bββ),
Type :=
idsquareo : squareover B ids idpo idpo idpo idpo
variables {A A' : Type} {B : A β Type}
{a a' a'' aββ aββ aββ aββ aββ aββ aββ aββ aββ : A}
/-aββ-/ {pββ : aββ = aββ} /-aββ-/ {pββ : aββ = aββ} /-aββ-/
{pββ : aββ = aββ} /-sββ-/ {pββ : aββ = aββ} /-sββ-/ {pββ : aββ = aββ}
/-aββ-/ {pββ : aββ = aββ} /-aββ-/ {pββ : aββ = aββ} /-aββ-/
{pββ : aββ = aββ} /-sββ-/ {pββ : aββ = aββ} /-sββ-/ {pββ : aββ = aββ}
/-aββ-/ {pββ : aββ = aββ} /-aββ-/ {pββ : aββ = aββ} /-aββ-/
{sββ : square pββ pββ pββ pββ} {sββ : square pββ pββ pββ pββ}
{sββ : square pββ pββ pββ pββ} {sββ : square pββ pββ pββ pββ}
{bββ : B aββ} {bββ : B aββ} {bββ : B aββ}
{bββ : B aββ} {bββ : B aββ} {bββ : B aββ}
{bββ : B aββ} {bββ : B aββ} {bββ : B aββ}
/-bββ-/ {qββ : bββ =[pββ] bββ} /-bββ-/ {qββ : bββ =[pββ] bββ} /-bββ-/
{qββ : bββ =[pββ] bββ} /-tββ-/ {qββ : bββ =[pββ] bββ} /-tββ-/ {qββ : bββ =[pββ] bββ}
/-bββ-/ {qββ : bββ =[pββ] bββ} /-bββ-/ {qββ : bββ =[pββ] bββ} /-bββ-/
{qββ : bββ =[pββ] bββ} /-tββ-/ {qββ : bββ =[pββ] bββ} /-tββ-/ {qββ : bββ =[pββ] bββ}
/-bββ-/ {qββ : bββ =[pββ] bββ} /-bββ-/ {qββ : bββ =[pββ] bββ} /-bββ-/
definition squareo := @squareover A B aββ
definition idsquareo [reducible] [constructor] (bββ : B aββ) := @squareover.idsquareo A B aββ bββ
definition idso [reducible] [constructor] := @squareover.idsquareo A B aββ bββ
definition apds (f : Ξ a, B a) (s : square pββ pββ pββ pββ)
: squareover B s (apdo f pββ) (apdo f pββ) (apdo f pββ) (apdo f pββ) :=
square.rec_on s idso
definition vrflo : squareover B vrfl qββ qββ idpo idpo :=
by induction qββ; exact idso
definition hrflo : squareover B hrfl idpo idpo qββ qββ :=
by induction qββ; exact idso
definition vdeg_squareover {qββ' : bββ =[pββ] bββ} (r : qββ = qββ')
: squareover B vrfl qββ qββ' idpo idpo :=
by induction r; exact vrflo
definition hdeg_squareover {qββ' : bββ =[pββ] bββ} (r : qββ = qββ')
: squareover B hrfl idpo idpo qββ qββ' :=
by induction r; exact hrflo
definition hconcato
(tββ : squareover B sββ qββ qββ qββ qββ) (tββ : squareover B sββ qββ qββ qββ qββ)
: squareover B (hconcat sββ sββ) (qββ β¬o qββ) (qββ β¬o qββ) qββ qββ :=
by induction tββ; exact tββ
definition vconcato
(tββ : squareover B sββ qββ qββ qββ qββ) (tββ : squareover B sββ qββ qββ qββ qββ)
: squareover B (vconcat sββ sββ) qββ qββ (qββ β¬o qββ) (qββ β¬o qββ) :=
by induction tββ; exact tββ
definition hinverseo (tββ : squareover B sββ qββ qββ qββ qββ)
: squareover B (hinverse sββ) qβββ»ΒΉα΅ qβββ»ΒΉα΅ qββ qββ :=
by induction tββ; constructor
definition vinverseo (tββ : squareover B sββ qββ qββ qββ qββ)
: squareover B (vinverse sββ) qββ qββ qβββ»ΒΉα΅ qβββ»ΒΉα΅ :=
by induction tββ; constructor
definition eq_vconcato {q : bββ =[pββ] bββ}
(r : q = qββ) (tββ : squareover B sββ qββ qββ qββ qββ) : squareover B sββ q qββ qββ qββ :=
by induction r; exact tββ
definition vconcato_eq {q : bββ =[pββ] bββ}
(tββ : squareover B sββ qββ qββ qββ qββ) (r : qββ = q) : squareover B sββ qββ q qββ qββ :=
by induction r; exact tββ
definition eq_hconcato {q : bββ =[pββ] bββ}
(r : q = qββ) (tββ : squareover B sββ qββ qββ qββ qββ) : squareover B sββ qββ qββ q qββ :=
by induction r; exact tββ
definition hconcato_eq {q : bββ =[pββ] bββ}
(tββ : squareover B sββ qββ qββ qββ qββ) (r : qββ = q) : squareover B sββ qββ qββ qββ q :=
by induction r; exact tββ
definition pathover_vconcato {p : aββ = aββ} {sp : p = pββ} {q : bββ =[p] bββ}
(r : change_path sp q = qββ) (tββ : squareover B sββ qββ qββ qββ qββ)
: squareover B (sp β¬pv sββ) q qββ qββ qββ :=
by induction sp; induction r; exact tββ
definition vconcato_pathover {p : aββ = aββ} {sp : pββ = p} {q : bββ =[p] bββ}
(tββ : squareover B sββ qββ qββ qββ qββ) (r : change_path sp qββ = q)
: squareover B (sββ β¬vp sp) qββ q qββ qββ :=
by induction sp; induction r; exact tββ
definition pathover_hconcato {p : aββ = aββ} {sp : p = pββ} {q : bββ =[p] bββ}
(r : change_path sp q = qββ) (tββ : squareover B sββ qββ qββ qββ qββ) :
squareover B (sp β¬ph sββ) qββ qββ q qββ :=
by induction sp; induction r; exact tββ
definition hconcato_pathover {p : aββ = aββ} {sp : pββ = p} {q : bββ =[p] bββ}
(tββ : squareover B sββ qββ qββ qββ qββ) (r : change_path sp qββ = q) :
squareover B (sββ β¬hp sp) qββ qββ qββ q :=
by induction sp; induction r; exact tββ
-- relating squareovers to squares
definition square_of_squareover (tββ : squareover B sββ qββ qββ qββ qββ) :
square (!con_tr β¬ ap (Ξ»a, pββ βΈ a) (tr_eq_of_pathover qββ))
(tr_eq_of_pathover qββ)
(ap (Ξ»q, q βΈ bββ) (eq_of_square sββ) β¬ !con_tr β¬ ap (Ξ»a, pββ βΈ a) (tr_eq_of_pathover qββ))
(tr_eq_of_pathover qββ) :=
by induction tββ; esimp; constructor
/-
definition squareover_of_square
(q : square (!con_tr β¬ ap (Ξ»a, pββ βΈ a) (tr_eq_of_pathover qββ))
(tr_eq_of_pathover qββ)
(ap (Ξ»q, q βΈ bββ) (eq_of_square sββ) β¬ !con_tr β¬ ap (Ξ»a, pββ βΈ a) (tr_eq_of_pathover qββ))
(tr_eq_of_pathover qββ))
: squareover B sββ qββ qββ qββ qββ :=
sorry
-/
definition square_of_squareover_ids {bββ bββ bββ bββ : B a}
(t : bββ = bββ) (b : bββ = bββ) (l : bββ = bββ) (r : bββ = bββ)
(so : squareover B ids (pathover_idp_of_eq t)
(pathover_idp_of_eq b)
(pathover_idp_of_eq l)
(pathover_idp_of_eq r)) : square t b l r :=
begin
let H := square_of_squareover so, -- use apply ... in
rewrite [βΈ* at H,+idp_con at H,+ap_id at H,βpathover_idp_of_eq at H],
rewrite [+to_right_inv !(pathover_equiv_tr_eq (refl a)) at H],
exact H
end
definition squareover_ids_of_square {bββ bββ bββ bββ : B a}
(t : bββ = bββ) (b : bββ = bββ) (l : bββ = bββ) (r : bββ = bββ) (q : square t b l r)
: squareover B ids (pathover_idp_of_eq t)
(pathover_idp_of_eq b)
(pathover_idp_of_eq l)
(pathover_idp_of_eq r) :=
square.rec_on q idso
-- relating pathovers to squareovers
definition pathover_of_squareover' (tββ : squareover B sββ qββ qββ qββ qββ)
: qββ β¬o qββ =[eq_of_square sββ] qββ β¬o qββ :=
by induction tββ; constructor
definition pathover_of_squareover {s : pββ β¬ pββ = pββ β¬ pββ}
(tββ : squareover B (square_of_eq s) qββ qββ qββ qββ)
: qββ β¬o qββ =[s] qββ β¬o qββ :=
begin
revert s tββ, refine equiv_rect' !square_equiv_eqβ»ΒΉα΅ (Ξ»a b, squareover B b _ _ _ _ β _) _,
intro s, exact pathover_of_squareover'
end
definition squareover_of_pathover {s : pββ β¬ pββ = pββ β¬ pββ}
(r : qββ β¬o qββ =[s] qββ β¬o qββ) : squareover B (square_of_eq s) qββ qββ qββ qββ :=
by induction qββ; esimp [concato] at r;induction r;induction qββ;induction qββ;constructor
definition pathover_top_of_squareover (tββ : squareover B sββ qββ qββ qββ qββ)
: qββ =[eq_top_of_square sββ] qββ β¬o qββ β¬o qβββ»ΒΉα΅ :=
by induction tββ; constructor
definition squareover_of_pathover_top {s : pββ = pββ β¬ pββ β¬ pβββ»ΒΉ}
(r : qββ =[s] qββ β¬o qββ β¬o qβββ»ΒΉα΅)
: squareover B (square_of_eq_top s) qββ qββ qββ qββ :=
by induction qββ; induction qββ; esimp at r;induction r;induction qββ;constructor
definition pathover_of_hdeg_squareover {pββ' : aββ = aββ} {r : pββ = pββ'} {qββ' : bββ =[pββ'] bββ}
(t : squareover B (hdeg_square r) idpo idpo qββ qββ') : qββ =[r] qββ' :=
by induction r; induction qββ'; exact (pathover_of_squareover' t)β»ΒΉα΅
definition pathover_of_vdeg_squareover {pββ' : aββ = aββ} {r : pββ = pββ'} {qββ' : bββ =[pββ'] bββ}
(t : squareover B (vdeg_square r) qββ qββ' idpo idpo) : qββ =[r] qββ' :=
by induction r; induction qββ'; exact pathover_of_squareover' t
definition squareover_of_eq_top (r : change_path (eq_top_of_square sββ) qββ = qββ β¬o qββ β¬o qβββ»ΒΉα΅)
: squareover B sββ qββ qββ qββ qββ :=
begin
induction sββ, revert qββ qββ r,
eapply idp_rec_on qββ, clear qββ,
intro qββ,
eapply idp_rec_on qββ, clear qββ,
esimp, intros,
induction r, eapply idp_rec_on qββ,
constructor
end
definition eq_top_of_squareover (r : squareover B sββ qββ qββ qββ qββ)
: change_path (eq_top_of_square sββ) qββ = qββ β¬o qββ β¬o qβββ»ΒΉα΅ :=
by induction r; reflexivity
/-
definition squareover_equiv_pathover (qββ : bββ =[pββ] bββ) (qββ : bββ =[pββ] bββ)
(qββ : bββ =[pββ] bββ) (qββ : bββ =[pββ] bββ)
: squareover B sββ qββ qββ qββ qββ β qββ β¬o qββ =[eq_of_square sββ] qββ β¬o qββ :=
begin
fapply equiv.MK,
{ exact pathover_of_squareover},
{ intro r, rewrite [-to_left_inv !square_equiv_eq sββ], apply squareover_of_pathover, exact r},
{ intro r, }, --need characterization of squareover lying over ids.
{ intro s, induction s, apply idp},
end
-/
definition eq_of_vdeg_squareover {qββ' : bββ =[pββ] bββ}
(p : squareover B vrfl qββ qββ' idpo idpo) : qββ = qββ' :=
begin
let H := square_of_squareover p, -- use apply ... in
induction pββ, -- if needed we can remove this induction and use con_tr_idp in types/eq2
rewrite [βΈ* at H,idp_con at H,+ap_id at H],
let H' := eq_of_vdeg_square H,
exact eq_of_fn_eq_fn !pathover_equiv_tr_eq H'
end
-- definition vdeg_tr_squareover {qββ : pββ βΈ bββ =[pββ] pββ βΈ bββ} (r : qββ =[_] qββ)
-- : squareover B sββ qββ qββ !pathover_tr !pathover_tr :=
-- by induction p;exact vrflo
/- charcaterization of pathovers in pathovers -/
-- in this version the fibration (B) of the pathover does not depend on the variable a
definition pathover_pathover {a' aβ' : A'} {p : a' = aβ'} {f g : A' β A}
{b : Ξ a, B (f a)} {bβ : Ξ a, B (g a)} {q : Ξ (a' : A'), f a' = g a'}
(r : pathover B (b a') (q a') (bβ a'))
(rβ : pathover B (b aβ') (q aβ') (bβ aβ'))
(s : squareover B (natural_square_tr q p) r rβ
(pathover_ap B f (apdo b p)) (pathover_ap B g (apdo bβ p)))
: pathover (Ξ»a, pathover B (b a) (q a) (bβ a)) r p rβ :=
begin
induction p, esimp at s, apply pathover_idp_of_eq, apply eq_of_vdeg_squareover, exact s
end
end eq
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.