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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
e14c59420cdf4f932778f2aa4e96c404eaa3236e | ff5230333a701471f46c57e8c115a073ebaaa448 | /library/system/io.lean | b05bc7edd42b1f6091beef542ec584926669d200 | [
"Apache-2.0"
] | permissive | stanford-cs242/lean | f81721d2b5d00bc175f2e58c57b710d465e6c858 | 7bd861261f4a37326dcf8d7a17f1f1f330e4548c | refs/heads/master | 1,600,957,431,849 | 1,576,465,093,000 | 1,576,465,093,000 | 225,779,423 | 0 | 3 | Apache-2.0 | 1,575,433,936,000 | 1,575,433,935,000 | null | UTF-8 | Lean | false | false | 9,288 | 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
/- Auxiliary definition used in the builtin implementation of monad_io_random_impl -/
def io_rand_nat : std_gen → nat → nat → nat × std_gen :=
rand_nat
@[instance] constant monad_io_impl : monad_io io_core
@[instance] constant monad_io_terminal_impl : monad_io_terminal io_core
@[instance] constant monad_io_net_system_impl : monad_io_net_system io_core
@[instance] constant monad_io_file_system_impl : monad_io_file_system io_core
@[instance] meta constant monad_io_serial_impl : monad_io_serial 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] constant monad_io_random_impl : monad_io_random 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
meta def serialize : handle → expr → io unit :=
monad_io_serial.serialize
meta def deserialize : handle → io expr :=
monad_io_serial.deserialize
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 net
def socket : Type :=
monad_io_net_system.socket io_core
def listen : string → nat → io socket :=
monad_io_net_system.listen io_core
def accept : socket → io socket :=
monad_io_net_system.accept
def connect : string → io socket :=
monad_io_net_system.connect io_core
def recv : socket → nat → io char_buffer :=
monad_io_net_system.recv
def send : socket → char_buffer → io unit :=
monad_io_net_system.send
def close : socket → io unit :=
monad_io_net_system.close
end net
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
def file_exists : string → io bool :=
monad_io_file_system.file_exists io_core
def dir_exists : string → io bool :=
monad_io_file_system.dir_exists io_core
def remove : string → io unit :=
monad_io_file_system.remove io_core
def rename : string → string → io unit :=
monad_io_file_system.rename io_core
def mkdir (path : string) (recursive : bool := ff) : io bool :=
monad_io_file_system.mkdir io_core path recursive
def rmdir : string → io bool :=
monad_io_file_system.rmdir io_core
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
def sleep (n : nat) : io unit :=
monad_io_process.sleep io_core n
end proc
def set_rand_gen : std_gen → io unit :=
monad_io_random.set_rand_gen io_core
def rand (lo : nat := std_range.1) (hi : nat := std_range.2) : io nat :=
monad_io_random.rand io_core lo hi
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,
io.fs.close child.stdout,
exitv ← io.proc.wait child,
when (exitv ≠ 0) $ io.fail $ "process exited with status " ++ repr exitv,
return buf.to_string
/--
This is the "back door" into the `io` monad, allowing IO computation to be performed during tactic execution.
For this to be safe, the IO computation should be ideally free of side effects and independent of its environment.
This primitive is used to invoke external tools (e.g., SAT and SMT solvers) from a tactic.
IMPORTANT: this primitive can be used to implement `unsafe_perform_io {α : Type} : io α → option α`
or `unsafe_perform_io {α : Type} [inhabited α] : io α → α`. This can be accomplished by executing
the resulting tactic using an empty `tactic_state` (we have `tactic_state.mk_empty`).
If `unsafe_perform_io` is defined, and used to perform side-effects, users need to take the following
precautions:
- Use `@[noinline]` attribute in any function to invokes `tactic.unsafe_perform_io`.
Reason: if the call is inlined, the IO may be performed more than once.
- Set `set_option compiler.cse false` before any function that invokes `tactic.unsafe_perform_io`.
This option disables common subexpression elimination. Common subexpression elimination
might combine two side effects that were meant to be separate.
TODO[Leo]: add `[noinline]` attribute and option `compiler.cse`.
-/
meta constant tactic.unsafe_run_io {α : Type} : io α → tactic α
/--
Execute the given tactic with a tactic_state object that contains:
- The current environment in the virtual machine.
- The current set of options in the virtual machine.
- Empty metavariable and local contexts.
- One single goal of the form `⊢ true`.
This action is mainly useful for writing tactics that inspect
the environment. -/
meta constant io.run_tactic {α : Type} (a : tactic α) : io α
|
b3f9ce271c6f42e7de1816b28c9d0e540a1dac46 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/algebra/big_operators/ring.lean | 8ed6121b1b0d7c71bfb10f3162979a0937876bbf | [
"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 | 11,114 | 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 algebra.big_operators.basic
import algebra.field.defs
import data.finset.pi
import data.finset.powerset
/-!
# Results about big operators with values in a (semi)ring
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We prove results about big operators that involve some interaction between
multiplicative and additive structures on the values being combined.
-/
universes u v w
open_locale big_operators
variables {α : Type u} {β : Type v} {γ : Type w}
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {b : β} {f g : α → β}
section comm_monoid
variables [comm_monoid β]
open_locale classical
lemma prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :
∀ {s : finset α}, (∏ i in s, x ^ (f i)) = x ^ (∑ x in s, f x) :=
begin
apply finset.induction,
{ simp },
{ assume a s has H,
rw [finset.prod_insert has, finset.sum_insert has, pow_add, H] }
end
end comm_monoid
section semiring
variables [non_unital_non_assoc_semiring β]
lemma sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=
add_monoid_hom.map_sum (add_monoid_hom.mul_right b) _ s
lemma mul_sum : b * (∑ x in s, f x) = ∑ x in s, b * f x :=
add_monoid_hom.map_sum (add_monoid_hom.mul_left b) _ s
lemma sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : finset ι₁) (s₂ : finset ι₂)
(f₁ : ι₁ → β) (f₂ : ι₂ → β) :
(∑ x₁ in s₁, f₁ x₁) * (∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁ ×ˢ s₂, f₁ p.1 * f₂ p.2 :=
by { rw [sum_product, sum_mul, sum_congr rfl], intros, rw mul_sum }
end semiring
section semiring
variables [non_assoc_semiring β]
lemma sum_mul_boole [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∑ x in s, (f x * ite (a = x) 1 0)) = ite (a ∈ s) (f a) 0 :=
by simp
lemma sum_boole_mul [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∑ x in s, (ite (a = x) 1 0) * f x) = ite (a ∈ s) (f a) 0 :=
by simp
end semiring
lemma sum_div [division_semiring β] {s : finset α} {f : α → β} {b : β} :
(∑ x in s, f x) / b = ∑ x in s, f x / b :=
by simp only [div_eq_mul_inv, sum_mul]
section comm_semiring
variables [comm_semiring β]
/-- The product over a sum can be written as a sum over the product of sets, `finset.pi`.
`finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/
lemma prod_sum {δ : α → Type*} [decidable_eq α] [∀a, decidable_eq (δ a)]
{s : finset α} {t : Πa, finset (δ a)} {f : Πa, δ a → β} :
(∏ a in s, ∑ b in (t a), f a b) =
∑ p in (s.pi t), ∏ x in s.attach, f x.1 (p x.1 x.2) :=
begin
induction s using finset.induction with a s ha ih,
{ rw [pi_empty, sum_singleton], refl },
{ have h₁ : ∀x ∈ t a, ∀y ∈ t a, ∀h : x ≠ y,
disjoint (image (pi.cons s a x) (pi s t)) (image (pi.cons s a y) (pi s t)),
{ assume x hx y hy h,
simp only [disjoint_iff_ne, mem_image],
rintros _ ⟨p₂, hp, eq₂⟩ _ ⟨p₃, hp₃, eq₃⟩ eq,
have : pi.cons s a x p₂ a (mem_insert_self _ _) = pi.cons s a y p₃ a (mem_insert_self _ _),
{ rw [eq₂, eq₃, eq] },
rw [pi.cons_same, pi.cons_same] at this,
exact h this },
rw [prod_insert ha, pi_insert ha, ih, sum_mul, sum_bUnion h₁],
refine sum_congr rfl (λ b _, _),
have h₂ : ∀p₁∈pi s t, ∀p₂∈pi s t, pi.cons s a b p₁ = pi.cons s a b p₂ → p₁ = p₂, from
assume p₁ h₁ p₂ h₂ eq, pi_cons_injective ha eq,
rw [sum_image h₂, mul_sum],
refine sum_congr rfl (λ g _, _),
rw [attach_insert, prod_insert, prod_image],
{ simp only [pi.cons_same],
congr' with ⟨v, hv⟩, congr',
exact (pi.cons_ne (by rintro rfl; exact ha hv)).symm },
{ exact λ _ _ _ _, subtype.eq ∘ subtype.mk.inj },
{ simp only [mem_image], rintro ⟨⟨_, hm⟩, _, rfl⟩, exact ha hm } }
end
open_locale classical
/-- The product of `f a + g a` over all of `s` is the sum
over the powerset of `s` of the product of `f` over a subset `t` times
the product of `g` over the complement of `t` -/
lemma prod_add (f g : α → β) (s : finset α) :
∏ a in s, (f a + g a) = ∑ t in s.powerset, ((∏ a in t, f a) * (∏ a in (s \ t), g a)) :=
calc ∏ a in s, (f a + g a)
= ∏ a in s, ∑ p in ({true, false} : finset Prop), if p then f a else g a : by simp
... = ∑ p in (s.pi (λ _, {true, false}) : finset (Π a ∈ s, Prop)),
∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 : prod_sum
... = ∑ t in s.powerset, (∏ a in t, f a) * (∏ a in (s \ t), g a) : begin
refine eq.symm (sum_bij (λ t _ a _, a ∈ t) _ _ _ _),
{ simp [subset_iff]; tauto },
{ intros t ht,
erw [prod_ite (λ a : {a // a ∈ s}, f a.1) (λ a : {a // a ∈ s}, g a.1)],
refine congr_arg2 _
(prod_bij (λ (a : α) (ha : a ∈ t), ⟨a, mem_powerset.1 ht ha⟩)
_ _ _
(λ b hb, ⟨b, by cases b;
simpa only [true_and, exists_prop, mem_filter, and_true, mem_attach, eq_self_iff_true,
subtype.coe_mk] using hb⟩))
(prod_bij (λ (a : α) (ha : a ∈ s \ t), ⟨a, by simp * at *⟩)
_ _ _
(λ b hb, ⟨b, by cases b; begin
simp only [true_and, mem_filter, mem_attach, subtype.coe_mk] at hb,
simpa only [true_and, exists_prop, and_true, mem_sdiff, eq_self_iff_true, subtype.coe_mk,
b_property],
end⟩));
intros; simp * at *; simp * at * },
{ assume a₁ a₂ h₁ h₂ H,
ext x,
simp only [function.funext_iff, subset_iff, mem_powerset, eq_iff_iff] at h₁ h₂ H,
exact ⟨λ hx, (H x (h₁ hx)).1 hx, λ hx, (H x (h₂ hx)).2 hx⟩ },
{ assume f hf,
exact ⟨s.filter (λ a : α, ∃ h : a ∈ s, f a h),
by simp, by funext; intros; simp *⟩ }
end
/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/
lemma prod_add_ordered {ι R : Type*} [comm_semiring R] [linear_order ι] (s : finset ι)
(f g : ι → R) :
(∏ i in s, (f i + g i)) = (∏ i in s, f i) +
∑ i in s, g i * (∏ j in s.filter (< i), (f j + g j)) * ∏ j in s.filter (λ j, i < j), f j :=
begin
refine finset.induction_on_max s (by simp) _,
clear s, intros a s ha ihs,
have ha' : a ∉ s, from λ ha', (ha a ha').false,
rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),
filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc],
congr' 1, rw add_comm, congr' 1,
{ rw [filter_false_of_mem, prod_empty, mul_one],
exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, λ i hi, (ha i hi).not_lt⟩ },
{ rw mul_sum,
refine sum_congr rfl (λ i hi, _),
rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,
mul_left_comm],
exact mt (λ ha, (mem_filter.1 ha).1) ha' }
end
/-- `∏ i, (f i - g i) = (∏ i, f i) - ∑ i, g i * (∏ j < i, f j - g j) * (∏ j > i, f j)`. -/
lemma prod_sub_ordered {ι R : Type*} [comm_ring R] [linear_order ι] (s : finset ι) (f g : ι → R) :
(∏ i in s, (f i - g i)) = (∏ i in s, f i) -
∑ i in s, g i * (∏ j in s.filter (< i), (f j - g j)) * ∏ j in s.filter (λ j, i < j), f j :=
begin
simp only [sub_eq_add_neg],
convert prod_add_ordered s f (λ i, -g i),
simp,
end
/-- `∏ i, (1 - f i) = 1 - ∑ i, f i * (∏ j < i, 1 - f j)`. This formula is useful in construction of
a partition of unity from a collection of “bump” functions. -/
lemma prod_one_sub_ordered {ι R : Type*} [comm_ring R] [linear_order ι] (s : finset ι) (f : ι → R) :
(∏ i in s, (1 - f i)) = 1 - ∑ i in s, f i * ∏ j in s.filter (< i), (1 - f j) :=
by { rw prod_sub_ordered, simp }
/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `finset`
gives `(a + b)^s.card`.-/
lemma sum_pow_mul_eq_add_pow
{α R : Type*} [comm_semiring R] (a b : R) (s : finset α) :
(∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card :=
begin
rw [← prod_const, prod_add],
refine finset.sum_congr rfl (λ t ht, _),
rw [prod_const, prod_const, ← card_sdiff (mem_powerset.1 ht)]
end
theorem dvd_sum {b : β} {s : finset α} {f : α → β}
(h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ x in s, f x :=
multiset.dvd_sum (λ y hy, by rcases multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx)
@[norm_cast]
lemma prod_nat_cast (s : finset α) (f : α → ℕ) :
↑(∏ x in s, f x : ℕ) = (∏ x in s, (f x : β)) :=
(nat.cast_ring_hom β).map_prod f s
end comm_semiring
section comm_ring
variables {R : Type*} [comm_ring R]
lemma prod_range_cast_nat_sub (n k : ℕ) :
∏ i in range k, (n - i : R) = (∏ i in range k, (n - i) : ℕ) :=
begin
rw prod_nat_cast,
cases le_or_lt k n with hkn hnk,
{ exact prod_congr rfl (λ i hi, (nat.cast_sub $ (mem_range.1 hi).le.trans hkn).symm) },
{ rw ← mem_range at hnk,
rw [prod_eq_zero hnk, prod_eq_zero hnk]; simp }
end
end comm_ring
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets
of `s`, and over all subsets of `s` to which one adds `x`."]
lemma prod_powerset_insert [decidable_eq α] [comm_monoid β] {s : finset α} {x : α} (h : x ∉ s)
(f : finset α → β) :
(∏ a in (insert x s).powerset, f a) =
(∏ a in s.powerset, f a) * (∏ t in s.powerset, f (insert x t)) :=
begin
rw [powerset_insert, finset.prod_union, finset.prod_image],
{ assume t₁ h₁ t₂ h₂ heq,
rw [← finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h),
← finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq] },
{ rw finset.disjoint_iff_ne,
assume t₁ h₁ t₂ h₂,
rcases finset.mem_image.1 h₂ with ⟨t₃, h₃, H₃₂⟩,
rw ← H₃₂,
exact ne_insert_of_not_mem _ _ (not_mem_of_mem_powerset_of_not_mem h₁ h) }
end
/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`. -/
@[to_additive "A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`"]
lemma prod_powerset [comm_monoid β] (s : finset α) (f : finset α → β) :
∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powerset_len j s, f t :=
by rw [powerset_card_disj_Union, prod_disj_Union]
lemma sum_range_succ_mul_sum_range_succ [non_unital_non_assoc_semiring β] (n k : ℕ) (f g : ℕ → β) :
(∑ i in range (n+1), f i) * (∑ i in range (k+1), g i) =
(∑ i in range n, f i) * (∑ i in range k, g i) +
f n * (∑ i in range k, g i) +
(∑ i in range n, f i) * g k +
f n * g k :=
by simp only [add_mul, mul_add, add_assoc, sum_range_succ]
end finset
|
d7b478f74e35b2a8286814d94e2c5e6490ae112e | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/normed_space/ray.lean | 338d77836a30dba38d44f4f9a324e06147ae67f4 | [
"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 | 4,675 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import linear_algebra.ray
import analysis.normed_space.basic
/-!
# Rays in a real normed vector space
In this file we prove some lemmas about the `same_ray` predicate in case of a real normed space. In
this case, for two vectors `x y` in the same ray, the norm of their sum is equal to the sum of their
norms and `∥y∥ • x = ∥x∥ • y`.
-/
open real
variables {E : Type*} [seminormed_add_comm_group E] [normed_space ℝ E]
{F : Type*} [normed_add_comm_group F] [normed_space ℝ F]
namespace same_ray
variables {x y : E}
/-- If `x` and `y` are on the same ray, then the triangle inequality becomes the equality: the norm
of `x + y` is the sum of the norms of `x` and `y`. The converse is true for a strictly convex
space. -/
lemma norm_add (h : same_ray ℝ x y) : ∥x + y∥ = ∥x∥ + ∥y∥ :=
begin
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩,
rw [← add_smul, norm_smul_of_nonneg (add_nonneg ha hb), norm_smul_of_nonneg ha,
norm_smul_of_nonneg hb, add_mul]
end
lemma norm_sub (h : same_ray ℝ x y) : ∥x - y∥ = |∥x∥ - ∥y∥| :=
begin
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩,
wlog hab : b ≤ a := le_total b a using [a b, b a] tactic.skip,
{ rw ← sub_nonneg at hab,
rw [← sub_smul, norm_smul_of_nonneg hab, norm_smul_of_nonneg ha,
norm_smul_of_nonneg hb, ← sub_mul, abs_of_nonneg (mul_nonneg hab (norm_nonneg _))] },
{ intros ha hb hab,
rw [norm_sub_rev, this hb ha hab.symm, abs_sub_comm] }
end
lemma norm_smul_eq (h : same_ray ℝ x y) : ∥x∥ • y = ∥y∥ • x :=
begin
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩,
simp only [norm_smul_of_nonneg, *, mul_smul, smul_comm (∥u∥)],
apply smul_comm
end
end same_ray
variables {x y : F}
lemma norm_inj_on_ray_left (hx : x ≠ 0) : {y | same_ray ℝ x y}.inj_on norm :=
begin
rintro y hy z hz h,
rcases hy.exists_nonneg_left hx with ⟨r, hr, rfl⟩,
rcases hz.exists_nonneg_left hx with ⟨s, hs, rfl⟩,
rw [norm_smul, norm_smul, mul_left_inj' (norm_ne_zero_iff.2 hx), norm_of_nonneg hr,
norm_of_nonneg hs] at h,
rw h
end
lemma norm_inj_on_ray_right (hy : y ≠ 0) : {x | same_ray ℝ x y}.inj_on norm :=
by simpa only [same_ray_comm] using norm_inj_on_ray_left hy
lemma same_ray_iff_norm_smul_eq : same_ray ℝ x y ↔ ∥x∥ • y = ∥y∥ • x :=
⟨same_ray.norm_smul_eq, λ h, or_iff_not_imp_left.2 $ λ hx, or_iff_not_imp_left.2 $ λ hy,
⟨∥y∥, ∥x∥, norm_pos_iff.2 hy, norm_pos_iff.2 hx, h.symm⟩⟩
/-- Two nonzero vectors `x y` in a real normed space are on the same ray if and only if the unit
vectors `∥x∥⁻¹ • x` and `∥y∥⁻¹ • y` are equal. -/
lemma same_ray_iff_inv_norm_smul_eq_of_ne (hx : x ≠ 0) (hy : y ≠ 0) :
same_ray ℝ x y ↔ ∥x∥⁻¹ • x = ∥y∥⁻¹ • y :=
by rw [inv_smul_eq_iff₀, smul_comm, eq_comm, inv_smul_eq_iff₀, same_ray_iff_norm_smul_eq];
rwa norm_ne_zero_iff
alias same_ray_iff_inv_norm_smul_eq_of_ne ↔ same_ray.inv_norm_smul_eq _
/-- Two vectors `x y` in a real normed space are on the ray if and only if one of them is zero or
the unit vectors `∥x∥⁻¹ • x` and `∥y∥⁻¹ • y` are equal. -/
lemma same_ray_iff_inv_norm_smul_eq : same_ray ℝ x y ↔ x = 0 ∨ y = 0 ∨ ∥x∥⁻¹ • x = ∥y∥⁻¹ • y :=
begin
rcases eq_or_ne x 0 with rfl|hx, { simp [same_ray.zero_left] },
rcases eq_or_ne y 0 with rfl|hy, { simp [same_ray.zero_right] },
simp only [same_ray_iff_inv_norm_smul_eq_of_ne hx hy, *, false_or]
end
/-- Two vectors of the same norm are on the same ray if and only if they are equal. -/
lemma same_ray_iff_of_norm_eq (h : ∥x∥ = ∥y∥) : same_ray ℝ x y ↔ x = y :=
begin
obtain rfl | hy := eq_or_ne y 0,
{ rw [norm_zero, norm_eq_zero] at h,
exact iff_of_true (same_ray.zero_right _) h },
{ exact ⟨λ hxy, norm_inj_on_ray_right hy hxy same_ray.rfl h, λ hxy, hxy ▸ same_ray.rfl⟩ }
end
lemma not_same_ray_iff_of_norm_eq (h : ∥x∥ = ∥y∥) : ¬ same_ray ℝ x y ↔ x ≠ y :=
(same_ray_iff_of_norm_eq h).not
/-- If two points on the same ray have the same norm, then they are equal. -/
lemma same_ray.eq_of_norm_eq (h : same_ray ℝ x y) (hn : ∥x∥ = ∥y∥) : x = y :=
(same_ray_iff_of_norm_eq hn).mp h
/-- The norms of two vectors on the same ray are equal if and only if they are equal. -/
lemma same_ray.norm_eq_iff (h : same_ray ℝ x y) : ∥x∥ = ∥y∥ ↔ x = y :=
⟨h.eq_of_norm_eq, λ h, h ▸ rfl⟩
|
ed4acb871c84a5bd872e1078fa36cd85d8b8241d | c1a29ca460720df88ab68dc42d9a1a02e029d505 | /examples/basics/unnamed_1567.lean | 697f45ee48efb63c46dbddac5e68ec081dbe9856 | [] | no_license | agusakov/mathematics_in_lean | acb5b3d659e4522ae4b4836ea550527f03f6546c | 2539562e4d91c858c73dbecb5b282ce1a7d38b6d | refs/heads/master | 1,665,963,365,241 | 1,592,080,022,000 | 1,592,080,022,000 | 272,078,062 | 0 | 0 | null | 1,592,078,772,000 | 1,592,078,772,000 | null | UTF-8 | Lean | false | false | 281 | lean | import data.nat.gcd
variables x y z : ℕ
example (h₀ : x ∣ y) (h₁ : y ∣ z) : x ∣ z :=
dvd_trans h₀ h₁
example : x ∣ y * x * z :=
begin
apply dvd_mul_of_dvd_left,
apply dvd_mul_left
end
example : x ∣ x^2 :=
begin
rw nat.pow_two,
apply dvd_mul_left
end |
7fd8a8085d5c5b0a1c8e94a37902f7310286e66e | 799b5de27cebaa6eaa49ff982110d59bbd6c6693 | /mechanized/instantiation.lean | 9a24296e21bdc82d92c26a872623044e6e5c0288 | [
"MIT"
] | permissive | philnguyen/soft-contract | 263efdbc9ca2f35234b03f0d99233a66accda78b | 13e7d99e061509f0a45605508dd1a27a51f4648e | refs/heads/master | 1,625,975,131,435 | 1,617,775,585,000 | 1,617,775,704,000 | 17,326,137 | 33 | 7 | MIT | 1,613,722,535,000 | 1,393,714,126,000 | Racket | UTF-8 | Lean | false | false | 5,911 | lean | import data.set definitions metafunctions reduction assumptions
-- Instantiation of expression
inductive inst_e: e → e → Prop
-- Structural cases
| n : ∀ {n}, inst_e (e.n n) (e.n n)
| lam: ∀ {x e e'},
kn_x x →
inst_e e e' →
inst_e (e.lam x e) (e.lam x e')
| x : ∀ {x}, kn_x x → inst_e (e.x x) (e.x x)
| app: ∀ {e₁ e₂ e₁' e₂'},
inst_e e₁ e₁' →
inst_e e₂ e₂' →
inst_e (e.app ℓ.kn e₁ e₂) (e.app ℓ.kn e₁' e₂')
| set: ∀ {x e e'},
kn_x x →
inst_e e e' →
inst_e (e.set x e) (e.set x e')
-- Each symbol stands for the base value or a syntactically closed lambdas
| n_s: ∀ {n}, inst_e (e.n n) e.s
| l_s: ∀ {x e},
uk_x x →
uk_e e →
fv (e.lam x e) = ∅ →
inst_e (e.lam x e) e.s
infix `⊑ₑ`: 40 := inst_e
-- Instantiation of environment
inductive inst_ρ: F → ρ → ρ → Prop
| mt : ∀ {F}, inst_ρ F [] []
| ext: ∀ {F x a a' ρ ρ'},
kn_x x →
kn_a a →
kn_a a' →
F_to F a a' →
inst_ρ F ρ ρ' →
inst_ρ F (ρ_ext ρ x a) (ρ_ext ρ' x a')
inductive opq_ρ: F → ρ → Prop
| mt : ∀ {F}, opq_ρ F []
| ext: ∀ {F a x ρ},
uk_x x →
uk_a a →
F_to F a aₗ →
opq_ρ F ρ →
opq_ρ F (ρ_ext ρ x a)
-- Instantiation between run-time values
inductive inst_V: F → V → V → Prop
| n : ∀ {F n}, inst_V F (V.n n) (V.n n)
| clo: ∀ {F x e e' ρ ρ'},
kn_x x →
inst_e e e' →
inst_ρ F ρ ρ' →
inst_V F (V.c x e ρ) (V.c x e' ρ')
-- non-structural cases
| n_s: ∀ {F n}, inst_V F (V.n n) V.s
| l_s: ∀ {F x e ρ},
uk_x x →
uk_e e →
opq_ρ F ρ →
inst_V F (V.c x e ρ) V.s
inductive rstr_V: F → σ → V → Prop
| of : ∀ {F σ' V V'}, σ_to σ' aₗ V' → inst_V F V V' → rstr_V F σ' V
inductive inst_A: F → A → A → Prop
| V : ∀ {F V V'},
inst_V F V V' →
inst_A F (A.V V) (A.V V')
| blm: ∀ {F}, inst_A F (A.blm ℓ.kn) (A.blm ℓ.kn)
inductive inst_E: F → E → E → Prop
-- structural cases
| ev : ∀ {F e e' ρ ρ'},
inst_e e e' →
inst_ρ F ρ ρ' →
inst_E F (E.ev e ρ) (E.ev e' ρ')
| rt : ∀ {F A A'},
inst_A F A A' →
inst_E F (E.rt A) (E.rt A')
-- non-structural cases
-- `hv Cs` form approximates entire classes of "unknown code" with access to leak set `Cs`
| hv : ∀ {F e ρ},
uk_e e →
opq_ρ F ρ →
inst_E F (E.ev e ρ) E.hv
-- Instantiation between stack frames
inductive inst_φ: F → φ → φ → Prop
| fn: ∀ {F V V'},
inst_V F V V' →
inst_φ F (φ.fn ℓ.kn V) (φ.fn ℓ.kn V')
| ar: ∀ {F e e' ρ ρ'},
inst_e e e' →
inst_ρ F ρ ρ' →
inst_φ F (φ.ar ℓ.kn e ρ) (φ.ar ℓ.kn e' ρ')
| st: ∀ {F a a'},
kn_a a →
kn_a a' →
F_to F a a' →
inst_φ F (φ.st a) (φ.st a')
-- Purely opaque stack frame
inductive rstr_φ: F → σ → φ → Prop
| fn: ∀ {F σ' V}, rstr_V F σ' V → rstr_φ F σ' (φ.fn ℓ.uk V)
| ar: ∀ {F σ' e ρ}, uk_e e → opq_ρ F ρ → rstr_φ F σ' (φ.ar ℓ.uk e ρ)
| st: ∀ {F σ' a}, uk_a a → F_to F a aₗ → rstr_φ F σ' (φ.st a)
-- Instantiation of stack
-- In case it's more intuitive in evaluation-hole notation:
--
-- -----------------------------------------[mt]
-- [] ⊑ []
--
-- V ⊑ V' ℰ ⊑ ℰ'
-- -----------------------------------------[ext_fn]
-- ℰ[V []] ⊑ ℰ'[V' []]
--
-- ℰ ⊑ ℰ'
-- -----------------------------------------[ns0]
-- ℰ ⊑ ℰ'[●/Cs []]
--
-- rstr⟦⟨e,ρ⟩, Cs⟧ ℰ ⊑ ℰ'[●/Cs []]
-- -----------------------------------------[nsn_ar]
-- ℰ[[] ⟨e,ρ⟩] ⊑ ℰ[●_Cs []]
--
-- rstr⟦V, Cs⟧ ℰ ⊑ ℰ'[●/Cs []]
-- -----------------------------------------[nsn_fn]
-- ℰ[V []] ⊑ ℰ[●/Cs []]
inductive inst_κ: F → σ → κ → κ → Prop
-- structural cases
| mt : ∀ {F σ'}, inst_κ F σ' [] []
| ext: ∀ {F σ' φ φ' κ κ'},
inst_φ F φ φ' →
inst_κ F σ' κ κ' →
inst_κ F σ' (φ :: κ) (φ' :: κ')
-- non-structural cases: opaque application approximates 0+ unknown frames
-- as long as the frames are restricted up to `Cs` behavior from the known
| ns0: ∀ {F σ' κ κ'},
inst_κ F σ' κ κ' →
inst_κ F σ' κ (φ.fn ℓ.uk V.s :: κ')
| nsn: ∀ {F σ' φ κ κ'},
rstr_φ F σ' φ →
inst_κ F σ' κ (φ.fn ℓ.uk V.s :: κ') →
inst_κ F σ' (φ :: κ) (φ.fn ℓ.uk V.s :: κ')
inductive inst_σ: F → σ → σ → Prop -- TODO am I sure about this defn?
/-| of : ∀ {F σ σ'},
(∀ {a a' V}, F_to F a a' → σ_to σ a V → (∃ V', σ_to σ' a' V' ∧ inst_V F V V')) →
inst_σ F σ σ'-/
| mt : ∀ {σ'}, inst_σ [] [] σ'
| ext: ∀ {F σ σ' a a' V V'},
map_excl F a →
map_excl σ a →
inst_V F V V' →
inst_σ F σ σ' →
inst_σ (F_ext F a a') (σ_ext σ a V) (σ_ext σ' a' V')
| wid: ∀ {F σ σ' a' V'},
inst_σ F σ σ' →
inst_σ F σ (σ_ext σ' a' V')
| mut: ∀ {F σ σ' a a' V V'},
F_to F a a' →
inst_V F V V' →
inst_σ F σ σ' →
inst_σ F (σ_ext σ a V) (σ_ext σ' a' V')
-- Instantiation of state
inductive inst_s: F → s → s → Prop
| of: ∀ {F E E' κ κ' σ σ'},
inst_E F E E' →
inst_κ F σ' κ κ' →
inst_σ F σ σ' →
inst_s F ⟨E, κ, σ⟩ ⟨E', κ', σ'⟩
noncomputable def inst (s s': s): Prop := ∃ F, inst_s F s s'
attribute [reducible] inst
infix `⊑`: 40 := inst
|
e77d717bc0eaef66250ab89c29d2c4819fa72679 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/category_theory/subobject/basic.lean | 15bf310804562f03687f95688c3dfd50ba08fea1 | [
"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 | 22,748 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Scott Morrison
-/
import category_theory.subobject.mono_over
import category_theory.skeletal
/-!
# Subobjects
We define `subobject X` as the quotient (by isomorphisms) of
`mono_over X := {f : over X // mono f.hom}`.
Here `mono_over X` is a thin category (a pair of objects has at most one morphism between them),
so we can think of it as a preorder. However as it is not skeletal, it is not a partial order.
There is a coercion from `subobject X` back to the ambient category `C`
(using choice to pick a representative), and for `P : subobject X`,
`P.arrow : (P : C) ⟶ X` is the inclusion morphism.
We provide
* `def pullback [has_pullbacks C] (f : X ⟶ Y) : subobject Y ⥤ subobject X`
* `def map (f : X ⟶ Y) [mono f] : subobject X ⥤ subobject Y`
* `def «exists» [has_images C] (f : X ⟶ Y) : subobject X ⥤ subobject Y`
and prove their basic properties and relationships.
These are all easy consequences of the earlier development
of the corresponding functors for `mono_over`.
The subobjects of `X` form a preorder making them into a category. We have `X ≤ Y` if and only if
`X.arrow` factors through `Y.arrow`: see `of_le`/`of_le_mk`/`of_mk_le`/`of_mk_le_mk` and
`le_of_comm`. Similarly, to show that two subobjects are equal, we can supply an isomorphism between
the underlying objects that commutes with the arrows (`eq_of_comm`).
See also
* `category_theory.subobject.factor_thru` :
an API describing factorization of morphisms through subobjects.
* `category_theory.subobject.lattice` :
the lattice structures on subobjects.
## Notes
This development originally appeared in Bhavik Mehta's "Topos theory for Lean" repository,
and was ported to mathlib by Scott Morrison.
### Implementation note
Currently we describe `pullback`, `map`, etc., as functors.
It may be better to just say that they are monotone functions,
and even avoid using categorical language entirely when describing `subobject X`.
(It's worth keeping this in mind in future use; it should be a relatively easy change here
if it looks preferable.)
### Relation to pseudoelements
There is a separate development of pseudoelements in `category_theory.abelian.pseudoelements`,
as a quotient (but not by isomorphism) of `over X`.
When a morphism `f` has an image, the image represents the same pseudoelement.
In a category with images `pseudoelements X` could be constructed as a quotient of `mono_over X`.
In fact, in an abelian category (I'm not sure in what generality beyond that),
`pseudoelements X` agrees with `subobject X`, but we haven't developed this in mathlib yet.
-/
universes v₁ v₂ u₁ u₂
noncomputable theory
namespace category_theory
open category_theory category_theory.category category_theory.limits
variables {C : Type u₁} [category.{v₁} C] {X Y Z : C}
variables {D : Type u₂} [category.{v₂} D]
/-!
We now construct the subobject lattice for `X : C`,
as the quotient by isomorphisms of `mono_over X`.
Since `mono_over X` is a thin category, we use `thin_skeleton` to take the quotient.
Essentially all the structure defined above on `mono_over X` descends to `subobject X`,
with morphisms becoming inequalities, and isomorphisms becoming equations.
-/
/--
The category of subobjects of `X : C`, defined as isomorphism classes of monomorphisms into `X`.
-/
@[derive [partial_order, category]]
def subobject (X : C) := thin_skeleton (mono_over X)
namespace subobject
/-- Convenience constructor for a subobject. -/
abbreviation mk {X A : C} (f : A ⟶ X) [mono f] : subobject X :=
(to_thin_skeleton _).obj (mono_over.mk' f)
/-- The category of subobjects is equivalent to the `mono_over` category. It is more convenient to
use the former due to the partial order instance, but oftentimes it is easier to define structures
on the latter. -/
noncomputable def equiv_mono_over (X : C) : subobject X ≌ mono_over X :=
thin_skeleton.equivalence _
/--
Use choice to pick a representative `mono_over X` for each `subobject X`.
-/
noncomputable
def representative {X : C} : subobject X ⥤ mono_over X :=
(equiv_mono_over X).functor
/--
Starting with `A : mono_over X`, we can take its equivalence class in `subobject X`
then pick an arbitrary representative using `representative.obj`.
This is isomorphic (in `mono_over X`) to the original `A`.
-/
noncomputable
def representative_iso {X : C} (A : mono_over X) :
representative.obj ((to_thin_skeleton _).obj A) ≅ A :=
(equiv_mono_over X).counit_iso.app A
/--
Use choice to pick a representative underlying object in `C` for any `subobject X`.
Prefer to use the coercion `P : C` rather than explicitly writing `underlying.obj P`.
-/
noncomputable
def underlying {X : C} : subobject X ⥤ C :=
representative ⋙ mono_over.forget _ ⋙ over.forget _
instance : has_coe (subobject X) C :=
{ coe := λ Y, underlying.obj Y, }
@[simp] lemma underlying_as_coe {X : C} (P : subobject X) : underlying.obj P = P := rfl
/--
If we construct a `subobject Y` from an explicit `f : X ⟶ Y` with `[mono f]`,
then pick an arbitrary choice of underlying object `(subobject.mk f : C)` back in `C`,
it is isomorphic (in `C`) to the original `X`.
-/
noncomputable
def underlying_iso {X Y : C} (f : X ⟶ Y) [mono f] : (subobject.mk f : C) ≅ X :=
(mono_over.forget _ ⋙ over.forget _).map_iso (representative_iso (mono_over.mk' f))
/--
The morphism in `C` from the arbitrarily chosen underlying object to the ambient object.
-/
noncomputable
def arrow {X : C} (Y : subobject X) : (Y : C) ⟶ X :=
(representative.obj Y).val.hom
instance arrow_mono {X : C} (Y : subobject X) : mono (Y.arrow) :=
(representative.obj Y).property
@[simp]
lemma arrow_congr {A : C} (X Y : subobject A) (h : X = Y) :
eq_to_hom (congr_arg (λ X : subobject A, (X : C)) h) ≫ Y.arrow = X.arrow :=
by { induction h, simp, }
@[simp]
lemma representative_coe (Y : subobject X) :
(representative.obj Y : C) = (Y : C) :=
rfl
@[simp]
lemma representative_arrow (Y : subobject X) :
(representative.obj Y).arrow = Y.arrow :=
rfl
@[simp, reassoc]
lemma underlying_arrow {X : C} {Y Z : subobject X} (f : Y ⟶ Z) :
underlying.map f ≫ arrow Z = arrow Y :=
over.w (representative.map f)
@[simp, reassoc]
lemma underlying_iso_arrow {X Y : C} (f : X ⟶ Y) [mono f] :
(underlying_iso f).inv ≫ (subobject.mk f).arrow = f :=
over.w _
@[simp, reassoc]
lemma underlying_iso_hom_comp_eq_mk {X Y : C} (f : X ⟶ Y) [mono f] :
(underlying_iso f).hom ≫ f = (mk f).arrow :=
(iso.eq_inv_comp _).1 (underlying_iso_arrow f).symm
/-- Two morphisms into a subobject are equal exactly if
the morphisms into the ambient object are equal -/
@[ext]
lemma eq_of_comp_arrow_eq {X Y : C} {P : subobject Y}
{f g : X ⟶ P} (h : f ≫ P.arrow = g ≫ P.arrow) : f = g :=
(cancel_mono P.arrow).mp h
lemma mk_le_mk_of_comm {B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [mono f₁] [mono f₂] (g : A₁ ⟶ A₂)
(w : g ≫ f₂ = f₁) : mk f₁ ≤ mk f₂ :=
⟨mono_over.hom_mk _ w⟩
@[simp] lemma mk_arrow (P : subobject X) : mk P.arrow = P :=
quotient.induction_on' P $ λ Q,
begin
obtain ⟨e⟩ := @quotient.mk_out' _ (is_isomorphic_setoid _) Q,
refine quotient.sound' ⟨mono_over.iso_mk _ _ ≪≫ e⟩;
tidy
end
lemma le_of_comm {B : C} {X Y : subobject B} (f : (X : C) ⟶ (Y : C)) (w : f ≫ Y.arrow = X.arrow) :
X ≤ Y :=
by convert mk_le_mk_of_comm _ w; simp
lemma le_mk_of_comm {B A : C} {X : subobject B} {f : A ⟶ B} [mono f] (g : (X : C) ⟶ A)
(w : g ≫ f = X.arrow) : X ≤ mk f :=
le_of_comm (g ≫ (underlying_iso f).inv) $ by simp [w]
lemma mk_le_of_comm {B A : C} {X : subobject B} {f : A ⟶ B} [mono f] (g : A ⟶ (X : C))
(w : g ≫ X.arrow = f) : mk f ≤ X :=
le_of_comm ((underlying_iso f).hom ≫ g) $ by simp [w]
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
@[ext] lemma eq_of_comm {B : C} {X Y : subobject B} (f : (X : C) ≅ (Y : C))
(w : f.hom ≫ Y.arrow = X.arrow) : X = Y :=
le_antisymm (le_of_comm f.hom w) $ le_of_comm f.inv $ f.inv_comp_eq.2 w.symm
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
@[ext] lemma eq_mk_of_comm {B A : C} {X : subobject B} (f : A ⟶ B) [mono f] (i : (X : C) ≅ A)
(w : i.hom ≫ f = X.arrow) : X = mk f :=
eq_of_comm (i.trans (underlying_iso f).symm) $ by simp [w]
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
@[ext] lemma mk_eq_of_comm {B A : C} {X : subobject B} (f : A ⟶ B) [mono f] (i : A ≅ (X : C))
(w : i.hom ≫ X.arrow = f) : mk f = X :=
eq.symm $ eq_mk_of_comm _ i.symm $ by rw [iso.symm_hom, iso.inv_comp_eq, w]
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
@[ext] lemma mk_eq_mk_of_comm {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [mono f] [mono g]
(i : A₁ ≅ A₂) (w : i.hom ≫ g = f) : mk f = mk g :=
eq_mk_of_comm _ ((underlying_iso f).trans i) $ by simp [w]
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
-- We make `X` and `Y` explicit arguments here so that when `of_le` appears in goal statements
-- it is possible to see its source and target
-- (`h` will just display as `_`, because it is in `Prop`).
def of_le {B : C} (X Y : subobject B) (h : X ≤ Y) : (X : C) ⟶ (Y : C) :=
underlying.map $ h.hom
@[simp, reassoc] lemma of_le_arrow {B : C} {X Y : subobject B} (h : X ≤ Y) :
of_le X Y h ≫ Y.arrow = X.arrow :=
underlying_arrow _
instance {B : C} (X Y : subobject B) (h : X ≤ Y) : mono (of_le X Y h) :=
begin
fsplit,
intros Z f g w,
replace w := w =≫ Y.arrow,
ext,
simpa using w,
end
lemma of_le_mk_le_mk_of_comm
{B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [mono f₁] [mono f₂] (g : A₁ ⟶ A₂) (w : g ≫ f₂ = f₁) :
of_le _ _ (mk_le_mk_of_comm g w) = (underlying_iso _).hom ≫ g ≫ (underlying_iso _).inv :=
by { ext, simp [w], }
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
@[derive mono]
def of_le_mk {B A : C} (X : subobject B) (f : A ⟶ B) [mono f] (h : X ≤ mk f) : (X : C) ⟶ A :=
of_le X (mk f) h ≫ (underlying_iso f).hom
@[simp] lemma of_le_mk_comp {B A : C} {X : subobject B} {f : A ⟶ B} [mono f] (h : X ≤ mk f) :
of_le_mk X f h ≫ f = X.arrow :=
by simp [of_le_mk]
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
@[derive mono]
def of_mk_le {B A : C} (f : A ⟶ B) [mono f] (X : subobject B) (h : mk f ≤ X) : A ⟶ (X : C) :=
(underlying_iso f).inv ≫ of_le (mk f) X h
@[simp] lemma of_mk_le_arrow {B A : C} {f : A ⟶ B} [mono f] {X : subobject B} (h : mk f ≤ X) :
of_mk_le f X h ≫ X.arrow = f :=
by simp [of_mk_le]
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
@[derive mono]
def of_mk_le_mk {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [mono f] [mono g] (h : mk f ≤ mk g) :
A₁ ⟶ A₂ :=
(underlying_iso f).inv ≫ of_le (mk f) (mk g) h ≫ (underlying_iso g).hom
@[simp] lemma of_mk_le_mk_comp {B A₁ A₂ : C} {f : A₁ ⟶ B} {g : A₂ ⟶ B} [mono f] [mono g]
(h : mk f ≤ mk g) : of_mk_le_mk f g h ≫ g = f :=
by simp [of_mk_le_mk]
@[simp, reassoc] lemma of_le_comp_of_le {B : C} (X Y Z : subobject B) (h₁ : X ≤ Y) (h₂ : Y ≤ Z) :
of_le X Y h₁ ≫ of_le Y Z h₂ = of_le X Z (h₁.trans h₂) :=
by simp [of_le, ←functor.map_comp underlying]
@[simp, reassoc] lemma of_le_comp_of_le_mk {B A : C} (X Y : subobject B) (f : A ⟶ B) [mono f]
(h₁ : X ≤ Y) (h₂ : Y ≤ mk f) : of_le X Y h₁ ≫ of_le_mk Y f h₂ = of_le_mk X f (h₁.trans h₂) :=
by simp [of_mk_le, of_le_mk, of_le, ←functor.map_comp_assoc underlying]
@[simp, reassoc] lemma of_le_mk_comp_of_mk_le {B A : C} (X : subobject B) (f : A ⟶ B) [mono f]
(Y : subobject B) (h₁ : X ≤ mk f) (h₂ : mk f ≤ Y) :
of_le_mk X f h₁ ≫ of_mk_le f Y h₂ = of_le X Y (h₁.trans h₂) :=
by simp [of_mk_le, of_le_mk, of_le, ←functor.map_comp underlying]
@[simp, reassoc] lemma of_le_mk_comp_of_mk_le_mk {B A₁ A₂ : C} (X : subobject B) (f : A₁ ⟶ B)
[mono f] (g : A₂ ⟶ B) [mono g] (h₁ : X ≤ mk f) (h₂ : mk f ≤ mk g) :
of_le_mk X f h₁ ≫ of_mk_le_mk f g h₂ = of_le_mk X g (h₁.trans h₂) :=
by simp [of_mk_le, of_le_mk, of_le, of_mk_le_mk, ←functor.map_comp_assoc underlying]
@[simp, reassoc] lemma of_mk_le_comp_of_le {B A₁ : C} (f : A₁ ⟶ B) [mono f] (X Y : subobject B)
(h₁ : mk f ≤ X) (h₂ : X ≤ Y) :
of_mk_le f X h₁ ≫ of_le X Y h₂ = of_mk_le f Y (h₁.trans h₂) :=
by simp [of_mk_le, of_le_mk, of_le, of_mk_le_mk, ←functor.map_comp underlying]
@[simp, reassoc] lemma of_mk_le_comp_of_le_mk {B A₁ A₂ : C} (f : A₁ ⟶ B) [mono f] (X : subobject B)
(g : A₂ ⟶ B) [mono g] (h₁ : mk f ≤ X) (h₂ : X ≤ mk g) :
of_mk_le f X h₁ ≫ of_le_mk X g h₂ = of_mk_le_mk f g (h₁.trans h₂) :=
by simp [of_mk_le, of_le_mk, of_le, of_mk_le_mk, ←functor.map_comp_assoc underlying]
@[simp, reassoc] lemma of_mk_le_mk_comp_of_mk_le {B A₁ A₂ : C} (f : A₁ ⟶ B) [mono f] (g : A₂ ⟶ B)
[mono g] (X : subobject B) (h₁ : mk f ≤ mk g) (h₂ : mk g ≤ X) :
of_mk_le_mk f g h₁ ≫ of_mk_le g X h₂ = of_mk_le f X (h₁.trans h₂) :=
by simp [of_mk_le, of_le_mk, of_le, of_mk_le_mk, ←functor.map_comp underlying]
@[simp, reassoc] lemma of_mk_le_mk_comp_of_mk_le_mk {B A₁ A₂ A₃ : C} (f : A₁ ⟶ B) [mono f]
(g : A₂ ⟶ B) [mono g] (h : A₃ ⟶ B) [mono h] (h₁ : mk f ≤ mk g) (h₂ : mk g ≤ mk h) :
of_mk_le_mk f g h₁ ≫ of_mk_le_mk g h h₂ = of_mk_le_mk f h (h₁.trans h₂) :=
by simp [of_mk_le, of_le_mk, of_le, of_mk_le_mk, ←functor.map_comp_assoc underlying]
@[simp] lemma of_le_refl {B : C} (X : subobject B) :
of_le X X le_rfl = 𝟙 _ :=
by { apply (cancel_mono X.arrow).mp, simp }
@[simp] lemma of_mk_le_mk_refl {B A₁ : C} (f : A₁ ⟶ B) [mono f] :
of_mk_le_mk f f le_rfl = 𝟙 _ :=
by { apply (cancel_mono f).mp, simp }
/-- An equality of subobjects gives an isomorphism of the corresponding objects.
(One could use `underlying.map_iso (eq_to_iso h))` here, but this is more readable.) -/
-- As with `of_le`, we have `X` and `Y` as explicit arguments for readability.
@[simps]
def iso_of_eq {B : C} (X Y : subobject B) (h : X = Y) : (X : C) ≅ (Y : C) :=
{ hom := of_le _ _ h.le,
inv := of_le _ _ h.ge, }
/-- An equality of subobjects gives an isomorphism of the corresponding objects. -/
@[simps]
def iso_of_eq_mk {B A : C} (X : subobject B) (f : A ⟶ B) [mono f] (h : X = mk f) : (X : C) ≅ A :=
{ hom := of_le_mk X f h.le,
inv := of_mk_le f X h.ge }
/-- An equality of subobjects gives an isomorphism of the corresponding objects. -/
@[simps]
def iso_of_mk_eq {B A : C} (f : A ⟶ B) [mono f] (X : subobject B) (h : mk f = X) : A ≅ (X : C) :=
{ hom := of_mk_le f X h.le,
inv := of_le_mk X f h.ge, }
/-- An equality of subobjects gives an isomorphism of the corresponding objects. -/
@[simps]
def iso_of_mk_eq_mk {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [mono f] [mono g] (h : mk f = mk g) :
A₁ ≅ A₂ :=
{ hom := of_mk_le_mk f g h.le,
inv := of_mk_le_mk g f h.ge, }
end subobject
open category_theory.limits
namespace subobject
/-- Any functor `mono_over X ⥤ mono_over Y` descends to a functor
`subobject X ⥤ subobject Y`, because `mono_over Y` is thin. -/
def lower {Y : D} (F : mono_over X ⥤ mono_over Y) : subobject X ⥤ subobject Y :=
thin_skeleton.map F
/-- Isomorphic functors become equal when lowered to `subobject`.
(It's not as evil as usual to talk about equality between functors
because the categories are thin and skeletal.) -/
lemma lower_iso (F₁ F₂ : mono_over X ⥤ mono_over Y) (h : F₁ ≅ F₂) :
lower F₁ = lower F₂ :=
thin_skeleton.map_iso_eq h
/-- A ternary version of `subobject.lower`. -/
def lower₂ (F : mono_over X ⥤ mono_over Y ⥤ mono_over Z) :
subobject X ⥤ subobject Y ⥤ subobject Z :=
thin_skeleton.map₂ F
@[simp]
lemma lower_comm (F : mono_over Y ⥤ mono_over X) :
to_thin_skeleton _ ⋙ lower F = F ⋙ to_thin_skeleton _ :=
rfl
/-- An adjunction between `mono_over A` and `mono_over B` gives an adjunction
between `subobject A` and `subobject B`. -/
def lower_adjunction {A : C} {B : D}
{L : mono_over A ⥤ mono_over B} {R : mono_over B ⥤ mono_over A} (h : L ⊣ R) :
lower L ⊣ lower R :=
thin_skeleton.lower_adjunction _ _ h
/-- An equivalence between `mono_over A` and `mono_over B` gives an equivalence
between `subobject A` and `subobject B`. -/
@[simps]
def lower_equivalence {A : C} {B : D} (e : mono_over A ≌ mono_over B) : subobject A ≌ subobject B :=
{ functor := lower e.functor,
inverse := lower e.inverse,
unit_iso :=
begin
apply eq_to_iso,
convert thin_skeleton.map_iso_eq e.unit_iso,
{ exact thin_skeleton.map_id_eq.symm },
{ exact (thin_skeleton.map_comp_eq _ _).symm },
end,
counit_iso :=
begin
apply eq_to_iso,
convert thin_skeleton.map_iso_eq e.counit_iso,
{ exact (thin_skeleton.map_comp_eq _ _).symm },
{ exact thin_skeleton.map_id_eq.symm },
end }
section pullback
variables [has_pullbacks C]
/-- When `C` has pullbacks, a morphism `f : X ⟶ Y` induces a functor `subobject Y ⥤ subobject X`,
by pulling back a monomorphism along `f`. -/
def pullback (f : X ⟶ Y) : subobject Y ⥤ subobject X :=
lower (mono_over.pullback f)
lemma pullback_id (x : subobject X) : (pullback (𝟙 X)).obj x = x :=
begin
apply quotient.induction_on' x,
intro f,
apply quotient.sound,
exact ⟨mono_over.pullback_id.app f⟩,
end
lemma pullback_comp (f : X ⟶ Y) (g : Y ⟶ Z) (x : subobject Z) :
(pullback (f ≫ g)).obj x = (pullback f).obj ((pullback g).obj x) :=
begin
apply quotient.induction_on' x,
intro t,
apply quotient.sound,
refine ⟨(mono_over.pullback_comp _ _).app t⟩,
end
instance (f : X ⟶ Y) : faithful (pullback f) := {}
end pullback
section map
/--
We can map subobjects of `X` to subobjects of `Y`
by post-composition with a monomorphism `f : X ⟶ Y`.
-/
def map (f : X ⟶ Y) [mono f] : subobject X ⥤ subobject Y :=
lower (mono_over.map f)
lemma map_id (x : subobject X) : (map (𝟙 X)).obj x = x :=
begin
apply quotient.induction_on' x,
intro f,
apply quotient.sound,
exact ⟨mono_over.map_id.app f⟩,
end
lemma map_comp (f : X ⟶ Y) (g : Y ⟶ Z) [mono f] [mono g] (x : subobject X) :
(map (f ≫ g)).obj x = (map g).obj ((map f).obj x) :=
begin
apply quotient.induction_on' x,
intro t,
apply quotient.sound,
refine ⟨(mono_over.map_comp _ _).app t⟩,
end
/-- Isomorphic objects have equivalent subobject lattices. -/
def map_iso {A B : C} (e : A ≅ B) : subobject A ≌ subobject B :=
lower_equivalence (mono_over.map_iso e)
/-- In fact, there's a type level bijection between the subobjects of isomorphic objects,
which preserves the order. -/
-- @[simps] here generates a lemma `map_iso_to_order_iso_to_equiv_symm_apply`
-- whose left hand side is not in simp normal form.
def map_iso_to_order_iso (e : X ≅ Y) : subobject X ≃o subobject Y :=
{ to_fun := (map e.hom).obj,
inv_fun := (map e.inv).obj,
left_inv := λ g, by simp_rw [← map_comp, e.hom_inv_id, map_id],
right_inv := λ g, by simp_rw [← map_comp, e.inv_hom_id, map_id],
map_rel_iff' := λ A B, begin
dsimp, fsplit,
{ intro h,
apply_fun (map e.inv).obj at h,
simp_rw [← map_comp, e.hom_inv_id, map_id] at h,
exact h, },
{ intro h,
apply_fun (map e.hom).obj at h,
exact h, },
end }
@[simp] lemma map_iso_to_order_iso_apply (e : X ≅ Y) (P : subobject X) :
map_iso_to_order_iso e P = (map e.hom).obj P :=
rfl
@[simp] lemma map_iso_to_order_iso_symm_apply (e : X ≅ Y) (Q : subobject Y) :
(map_iso_to_order_iso e).symm Q = (map e.inv).obj Q :=
rfl
/-- `map f : subobject X ⥤ subobject Y` is
the left adjoint of `pullback f : subobject Y ⥤ subobject X`. -/
def map_pullback_adj [has_pullbacks C] (f : X ⟶ Y) [mono f] : map f ⊣ pullback f :=
lower_adjunction (mono_over.map_pullback_adj f)
@[simp]
lemma pullback_map_self [has_pullbacks C] (f : X ⟶ Y) [mono f] (g : subobject X) :
(pullback f).obj ((map f).obj g) = g :=
begin
revert g,
apply quotient.ind,
intro g',
apply quotient.sound,
exact ⟨(mono_over.pullback_map_self f).app _⟩,
end
lemma map_pullback [has_pullbacks C]
{X Y Z W : C} {f : X ⟶ Y} {g : X ⟶ Z} {h : Y ⟶ W} {k : Z ⟶ W} [mono h] [mono g]
(comm : f ≫ h = g ≫ k) (t : is_limit (pullback_cone.mk f g comm)) (p : subobject Y) :
(map g).obj ((pullback f).obj p) = (pullback k).obj ((map h).obj p) :=
begin
revert p,
apply quotient.ind',
intro a,
apply quotient.sound,
apply thin_skeleton.equiv_of_both_ways,
{ refine mono_over.hom_mk (pullback.lift pullback.fst _ _) (pullback.lift_snd _ _ _),
change _ ≫ a.arrow ≫ h = (pullback.snd ≫ g) ≫ _,
rw [assoc, ← comm, pullback.condition_assoc] },
{ refine mono_over.hom_mk (pullback.lift pullback.fst
(pullback_cone.is_limit.lift' t (pullback.fst ≫ a.arrow) pullback.snd _).1
(pullback_cone.is_limit.lift' _ _ _ _).2.1.symm) _,
{ rw [← pullback.condition, assoc], refl },
{ dsimp, rw [pullback.lift_snd_assoc],
apply (pullback_cone.is_limit.lift' _ _ _ _).2.2 } }
end
end map
section «exists»
variables [has_images C]
/--
The functor from subobjects of `X` to subobjects of `Y` given by
sending the subobject `S` to its "image" under `f`, usually denoted $\exists_f$.
For instance, when `C` is the category of types,
viewing `subobject X` as `set X` this is just `set.image f`.
This functor is left adjoint to the `pullback f` functor (shown in `exists_pullback_adj`)
provided both are defined, and generalises the `map f` functor, again provided it is defined.
-/
def «exists» (f : X ⟶ Y) : subobject X ⥤ subobject Y :=
lower (mono_over.exists f)
/--
When `f : X ⟶ Y` is a monomorphism, `exists f` agrees with `map f`.
-/
lemma exists_iso_map (f : X ⟶ Y) [mono f] : «exists» f = map f :=
lower_iso _ _ (mono_over.exists_iso_map f)
/--
`exists f : subobject X ⥤ subobject Y` is
left adjoint to `pullback f : subobject Y ⥤ subobject X`.
-/
def exists_pullback_adj (f : X ⟶ Y) [has_pullbacks C] : «exists» f ⊣ pullback f :=
lower_adjunction (mono_over.exists_pullback_adj f)
end «exists»
end subobject
end category_theory
|
0e4c9f4470d3413a3f3565cb3518cbc2fdf5732e | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/uniform_space/uniform_embedding.lean | 863c6714f2b13b56eb3590f4a50b2dfbfe438576 | [
"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 | 26,845 | 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, Sébastien Gouëzel, Patrick Massot
-/
import topology.uniform_space.cauchy
import topology.uniform_space.separation
import topology.dense_embedding
/-!
# Uniform embeddings of uniform spaces.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Extension of uniform continuous functions.
-/
open filter topological_space set function classical
open_locale classical uniformity topology filter
section
variables {α : Type*} {β : Type*} {γ : Type*}
[uniform_space α] [uniform_space β] [uniform_space γ]
universes u v
/-!
### Uniform inducing maps
-/
/-- A map `f : α → β` between uniform spaces is called *uniform inducing* if the uniformity filter
on `α` is the pullback of the uniformity filter on `β` under `prod.map f f`. If `α` is a separated
space, then this implies that `f` is injective, hence it is a `uniform_embedding`. -/
@[mk_iff]
structure uniform_inducing (f : α → β) : Prop :=
(comap_uniformity : comap (λx:α×α, (f x.1, f x.2)) (𝓤 β) = 𝓤 α)
protected lemma uniform_inducing.comap_uniform_space {f : α → β} (hf : uniform_inducing f) :
‹uniform_space β›.comap f = ‹uniform_space α› :=
uniform_space_eq hf.1
lemma uniform_inducing_iff' {f : α → β} :
uniform_inducing f ↔ uniform_continuous f ∧ comap (prod.map f f) (𝓤 β) ≤ 𝓤 α :=
by rw [uniform_inducing_iff, uniform_continuous, tendsto_iff_comap, le_antisymm_iff, and_comm]; refl
protected lemma filter.has_basis.uniform_inducing_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'}
(h : (𝓤 α).has_basis p s) (h' : (𝓤 β).has_basis p' s') {f : α → β} :
uniform_inducing f ↔
(∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧
(∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) :=
by simp [uniform_inducing_iff', h.uniform_continuous_iff h', (h'.comap _).le_basis_iff h,
subset_def]
lemma uniform_inducing.mk' {f : α → β} (h : ∀ s, s ∈ 𝓤 α ↔
∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : uniform_inducing f :=
⟨by simp [eq_comm, filter.ext_iff, subset_def, h]⟩
lemma uniform_inducing_id : uniform_inducing (@id α) :=
⟨by rw [← prod.map_def, prod.map_id, comap_id]⟩
lemma uniform_inducing.comp {g : β → γ} (hg : uniform_inducing g)
{f : α → β} (hf : uniform_inducing f) : uniform_inducing (g ∘ f) :=
⟨by rw [← hf.1, ← hg.1, comap_comap]⟩
lemma uniform_inducing.basis_uniformity {f : α → β} (hf : uniform_inducing f)
{ι : Sort*} {p : ι → Prop} {s : ι → set (β × β)} (H : (𝓤 β).has_basis p s) :
(𝓤 α).has_basis p (λ i, prod.map f f ⁻¹' s i) :=
hf.1 ▸ H.comap _
lemma uniform_inducing.cauchy_map_iff {f : α → β} (hf : uniform_inducing f) {F : filter α} :
cauchy (map f F) ↔ cauchy F :=
by simp only [cauchy, map_ne_bot_iff, prod_map_map_eq, map_le_iff_le_comap, ← hf.comap_uniformity]
lemma uniform_inducing_of_compose {f : α → β} {g : β → γ} (hf : uniform_continuous f)
(hg : uniform_continuous g) (hgf : uniform_inducing (g ∘ f)) : uniform_inducing f :=
begin
refine ⟨le_antisymm _ hf.le_comap⟩,
rw [← hgf.1, ← prod.map_def, ← prod.map_def, ← prod.map_comp_map f f g g,
← @comap_comap _ _ _ _ (prod.map f f)],
exact comap_mono hg.le_comap
end
lemma uniform_inducing.uniform_continuous {f : α → β}
(hf : uniform_inducing f) : uniform_continuous f :=
(uniform_inducing_iff'.1 hf).1
lemma uniform_inducing.uniform_continuous_iff {f : α → β} {g : β → γ} (hg : uniform_inducing g) :
uniform_continuous f ↔ uniform_continuous (g ∘ f) :=
by { dsimp only [uniform_continuous, tendsto],
rw [← hg.comap_uniformity, ← map_le_iff_le_comap, filter.map_map] }
protected lemma uniform_inducing.inducing {f : α → β} (h : uniform_inducing f) : inducing f :=
begin
unfreezingI { obtain rfl := h.comap_uniform_space },
letI := uniform_space.comap f _,
exact ⟨rfl⟩
end
lemma uniform_inducing.prod {α' : Type*} {β' : Type*} [uniform_space α'] [uniform_space β']
{e₁ : α → α'} {e₂ : β → β'} (h₁ : uniform_inducing e₁) (h₂ : uniform_inducing e₂) :
uniform_inducing (λp:α×β, (e₁ p.1, e₂ p.2)) :=
⟨by simp [(∘), uniformity_prod, h₁.comap_uniformity.symm, h₂.comap_uniformity.symm,
comap_inf, comap_comap]⟩
lemma uniform_inducing.dense_inducing {f : α → β} (h : uniform_inducing f) (hd : dense_range f) :
dense_inducing f :=
{ dense := hd,
induced := h.inducing.induced }
protected lemma uniform_inducing.injective [t0_space α] {f : α → β} (h : uniform_inducing f) :
injective f :=
h.inducing.injective
/-- A map `f : α → β` between uniform spaces is a *uniform embedding* if it is uniform inducing and
injective. If `α` is a separated space, then the latter assumption follows from the former. -/
@[mk_iff]
structure uniform_embedding (f : α → β) extends uniform_inducing f : Prop :=
(inj : function.injective f)
theorem uniform_embedding_iff' {f : α → β} :
uniform_embedding f ↔ injective f ∧ uniform_continuous f ∧ comap (prod.map f f) (𝓤 β) ≤ 𝓤 α :=
by rw [uniform_embedding_iff, and_comm, uniform_inducing_iff']
theorem filter.has_basis.uniform_embedding_iff' {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'}
(h : (𝓤 α).has_basis p s) (h' : (𝓤 β).has_basis p' s') {f : α → β} :
uniform_embedding f ↔ injective f ∧
(∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧
(∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) :=
by rw [uniform_embedding_iff, and_comm, h.uniform_inducing_iff h']
theorem filter.has_basis.uniform_embedding_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'}
(h : (𝓤 α).has_basis p s) (h' : (𝓤 β).has_basis p' s') {f : α → β} :
uniform_embedding f ↔ injective f ∧ uniform_continuous f ∧
(∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) :=
by simp only [h.uniform_embedding_iff' h', h.uniform_continuous_iff h', exists_prop]
lemma uniform_embedding_subtype_val {p : α → Prop} :
uniform_embedding (subtype.val : subtype p → α) :=
{ comap_uniformity := rfl,
inj := subtype.val_injective }
lemma uniform_embedding_subtype_coe {p : α → Prop} :
uniform_embedding (coe : subtype p → α) :=
uniform_embedding_subtype_val
lemma uniform_embedding_set_inclusion {s t : set α} (hst : s ⊆ t) :
uniform_embedding (inclusion hst) :=
{ comap_uniformity :=
by { erw [uniformity_subtype, uniformity_subtype, comap_comap], congr },
inj := inclusion_injective hst }
lemma uniform_embedding.comp {g : β → γ} (hg : uniform_embedding g)
{f : α → β} (hf : uniform_embedding f) : uniform_embedding (g ∘ f) :=
{ inj := hg.inj.comp hf.inj,
..hg.to_uniform_inducing.comp hf.to_uniform_inducing }
lemma equiv.uniform_embedding {α β : Type*} [uniform_space α] [uniform_space β] (f : α ≃ β)
(h₁ : uniform_continuous f) (h₂ : uniform_continuous f.symm) : uniform_embedding f :=
uniform_embedding_iff'.2 ⟨f.injective, h₁, by rwa [← equiv.prod_congr_apply, ← map_equiv_symm]⟩
theorem uniform_embedding_inl : uniform_embedding (sum.inl : α → α ⊕ β) :=
begin
refine ⟨⟨_⟩, sum.inl_injective⟩,
rw [sum.uniformity, comap_sup, comap_map, comap_eq_bot_iff_compl_range.2 _, sup_bot_eq],
{ refine mem_map.2 (univ_mem' _),
simp },
{ exact sum.inl_injective.prod_map sum.inl_injective }
end
theorem uniform_embedding_inr : uniform_embedding (sum.inr : β → α ⊕ β) :=
begin
refine ⟨⟨_⟩, sum.inr_injective⟩,
rw [sum.uniformity, comap_sup, comap_eq_bot_iff_compl_range.2 _, comap_map, bot_sup_eq],
{ exact sum.inr_injective.prod_map sum.inr_injective },
{ refine mem_map.2 (univ_mem' _),
simp },
end
/-- If the domain of a `uniform_inducing` map `f` is a `separated_space`, then `f` is injective,
hence it is a `uniform_embedding`. -/
protected theorem uniform_inducing.uniform_embedding [t0_space α] {f : α → β}
(hf : uniform_inducing f) :
uniform_embedding f :=
⟨hf, hf.injective⟩
theorem uniform_embedding_iff_uniform_inducing [t0_space α] {f : α → β} :
uniform_embedding f ↔ uniform_inducing f :=
⟨uniform_embedding.to_uniform_inducing, uniform_inducing.uniform_embedding⟩
/-- If a map `f : α → β` sends any two distinct points to point that are **not** related by a fixed
`s ∈ 𝓤 β`, then `f` is uniform inducing with respect to the discrete uniformity on `α`:
the preimage of `𝓤 β` under `prod.map f f` is the principal filter generated by the diagonal in
`α × α`. -/
lemma comap_uniformity_of_spaced_out {α} {f : α → β} {s : set (β × β)} (hs : s ∈ 𝓤 β)
(hf : pairwise (λ x y, (f x, f y) ∉ s)) :
comap (prod.map f f) (𝓤 β) = 𝓟 id_rel :=
begin
refine le_antisymm _ (@refl_le_uniformity α (uniform_space.comap f ‹_›)),
calc comap (prod.map f f) (𝓤 β) ≤ comap (prod.map f f) (𝓟 s) : comap_mono (le_principal_iff.2 hs)
... = 𝓟 (prod.map f f ⁻¹' s) : comap_principal
... ≤ 𝓟 id_rel : principal_mono.2 _,
rintro ⟨x, y⟩, simpa [not_imp_not] using @hf x y
end
/-- If a map `f : α → β` sends any two distinct points to point that are **not** related by a fixed
`s ∈ 𝓤 β`, then `f` is a uniform embedding with respect to the discrete uniformity on `α`. -/
lemma uniform_embedding_of_spaced_out {α} {f : α → β} {s : set (β × β)} (hs : s ∈ 𝓤 β)
(hf : pairwise (λ x y, (f x, f y) ∉ s)) :
@uniform_embedding α β ⊥ ‹_› f :=
begin
letI : uniform_space α := ⊥, haveI := discrete_topology_bot α,
haveI : separated_space α := separated_iff_t2.2 infer_instance,
exact uniform_inducing.uniform_embedding ⟨comap_uniformity_of_spaced_out hs hf⟩
end
protected lemma uniform_embedding.embedding {f : α → β} (h : uniform_embedding f) : embedding f :=
{ induced := h.to_uniform_inducing.inducing.induced,
inj := h.inj }
lemma uniform_embedding.dense_embedding {f : α → β} (h : uniform_embedding f) (hd : dense_range f) :
dense_embedding f :=
{ dense := hd,
inj := h.inj,
induced := h.embedding.induced }
lemma closed_embedding_of_spaced_out {α} [topological_space α] [discrete_topology α]
[separated_space β] {f : α → β} {s : set (β × β)} (hs : s ∈ 𝓤 β)
(hf : pairwise (λ x y, (f x, f y) ∉ s)) :
closed_embedding f :=
begin
unfreezingI { rcases (discrete_topology.eq_bot α) with rfl }, letI : uniform_space α := ⊥,
exact { closed_range := is_closed_range_of_spaced_out hs hf,
.. (uniform_embedding_of_spaced_out hs hf).embedding }
end
lemma closure_image_mem_nhds_of_uniform_inducing
{s : set (α×α)} {e : α → β} (b : β)
(he₁ : uniform_inducing e) (he₂ : dense_inducing e) (hs : s ∈ 𝓤 α) :
∃ a, closure (e '' {a' | (a, a') ∈ s}) ∈ 𝓝 b :=
have s ∈ comap (λp:α×α, (e p.1, e p.2)) (𝓤 β),
from he₁.comap_uniformity.symm ▸ hs,
let ⟨t₁, ht₁u, ht₁⟩ := this in
have ht₁ : ∀p:α×α, (e p.1, e p.2) ∈ t₁ → p ∈ s, from ht₁,
let ⟨t₂, ht₂u, ht₂s, ht₂c⟩ := comp_symm_of_uniformity ht₁u in
let ⟨t, htu, hts, htc⟩ := comp_symm_of_uniformity ht₂u in
have preimage e {b' | (b, b') ∈ t₂} ∈ comap e (𝓝 b),
from preimage_mem_comap $ mem_nhds_left b ht₂u,
let ⟨a, (ha : (b, e a) ∈ t₂)⟩ := (he₂.comap_nhds_ne_bot _).nonempty_of_mem this in
have ∀b' (s' : set (β × β)), (b, b') ∈ t → s' ∈ 𝓤 β →
({y : β | (b', y) ∈ s'} ∩ e '' {a' : α | (a, a') ∈ s}).nonempty,
from assume b' s' hb' hs',
have preimage e {b'' | (b', b'') ∈ s' ∩ t} ∈ comap e (𝓝 b'),
from preimage_mem_comap $ mem_nhds_left b' $ inter_mem hs' htu,
let ⟨a₂, ha₂s', ha₂t⟩ := (he₂.comap_nhds_ne_bot _).nonempty_of_mem this in
have (e a, e a₂) ∈ t₁,
from ht₂c $ prod_mk_mem_comp_rel (ht₂s ha) $ htc $ prod_mk_mem_comp_rel hb' ha₂t,
have e a₂ ∈ {b'':β | (b', b'') ∈ s'} ∩ e '' {a' | (a, a') ∈ s},
from ⟨ha₂s', mem_image_of_mem _ $ ht₁ (a, a₂) this⟩,
⟨_, this⟩,
have ∀b', (b, b') ∈ t → ne_bot (𝓝 b' ⊓ 𝓟 (e '' {a' | (a, a') ∈ s})),
begin
intros b' hb',
rw [nhds_eq_uniformity, lift'_inf_principal_eq, lift'_ne_bot_iff],
exact assume s, this b' s hb',
exact monotone_preimage.inter monotone_const
end,
have ∀b', (b, b') ∈ t → b' ∈ closure (e '' {a' | (a, a') ∈ s}),
from assume b' hb', by rw [closure_eq_cluster_pts]; exact this b' hb',
⟨a, (𝓝 b).sets_of_superset (mem_nhds_left b htu) this⟩
lemma uniform_embedding_subtype_emb (p : α → Prop) {e : α → β} (ue : uniform_embedding e)
(de : dense_embedding e) : uniform_embedding (dense_embedding.subtype_emb p e) :=
{ comap_uniformity := by simp [comap_comap, (∘), dense_embedding.subtype_emb,
uniformity_subtype, ue.comap_uniformity.symm],
inj := (de.subtype p).inj }
lemma uniform_embedding.prod {α' : Type*} {β' : Type*} [uniform_space α'] [uniform_space β']
{e₁ : α → α'} {e₂ : β → β'} (h₁ : uniform_embedding e₁) (h₂ : uniform_embedding e₂) :
uniform_embedding (λp:α×β, (e₁ p.1, e₂ p.2)) :=
{ inj := h₁.inj.prod_map h₂.inj,
..h₁.to_uniform_inducing.prod h₂.to_uniform_inducing }
lemma is_complete_of_complete_image {m : α → β} {s : set α} (hm : uniform_inducing m)
(hs : is_complete (m '' s)) : is_complete s :=
begin
intros f hf hfs,
rw le_principal_iff at hfs,
obtain ⟨_, ⟨x, hx, rfl⟩, hyf⟩ : ∃ y ∈ m '' s, map m f ≤ 𝓝 y,
from hs (f.map m) (hf.map hm.uniform_continuous)
(le_principal_iff.2 (image_mem_map hfs)),
rw [map_le_iff_le_comap, ← nhds_induced, ← hm.inducing.induced] at hyf,
exact ⟨x, hx, hyf⟩
end
lemma is_complete.complete_space_coe {s : set α} (hs : is_complete s) :
complete_space s :=
complete_space_iff_is_complete_univ.2 $
is_complete_of_complete_image uniform_embedding_subtype_coe.to_uniform_inducing $ by simp [hs]
/-- A set is complete iff its image under a uniform inducing map is complete. -/
lemma is_complete_image_iff {m : α → β} {s : set α} (hm : uniform_inducing m) :
is_complete (m '' s) ↔ is_complete s :=
begin
refine ⟨is_complete_of_complete_image hm, λ c, _⟩,
haveI : complete_space s := c.complete_space_coe,
set m' : s → β := m ∘ coe,
suffices : is_complete (range m'), by rwa [range_comp, subtype.range_coe] at this,
have hm' : uniform_inducing m' := hm.comp uniform_embedding_subtype_coe.to_uniform_inducing,
intros f hf hfm,
rw filter.le_principal_iff at hfm,
have cf' : cauchy (comap m' f) :=
hf.comap' hm'.comap_uniformity.le (ne_bot.comap_of_range_mem hf.1 hfm),
rcases complete_space.complete cf' with ⟨x, hx⟩,
rw [hm'.inducing.nhds_eq_comap, comap_le_comap_iff hfm] at hx,
use [m' x, mem_range_self _, hx]
end
lemma complete_space_iff_is_complete_range {f : α → β} (hf : uniform_inducing f) :
complete_space α ↔ is_complete (range f) :=
by rw [complete_space_iff_is_complete_univ, ← is_complete_image_iff hf, image_univ]
lemma uniform_inducing.is_complete_range [complete_space α] {f : α → β}
(hf : uniform_inducing f) :
is_complete (range f) :=
(complete_space_iff_is_complete_range hf).1 ‹_›
lemma complete_space_congr {e : α ≃ β} (he : uniform_embedding e) :
complete_space α ↔ complete_space β :=
by rw [complete_space_iff_is_complete_range he.to_uniform_inducing, e.range_eq_univ,
complete_space_iff_is_complete_univ]
lemma complete_space_coe_iff_is_complete {s : set α} :
complete_space s ↔ is_complete s :=
(complete_space_iff_is_complete_range uniform_embedding_subtype_coe.to_uniform_inducing).trans $
by rw [subtype.range_coe]
lemma is_closed.complete_space_coe [complete_space α] {s : set α} (hs : is_closed s) :
complete_space s :=
hs.is_complete.complete_space_coe
/-- The lift of a complete space to another universe is still complete. -/
instance ulift.complete_space [h : complete_space α] : complete_space (ulift α) :=
begin
have : uniform_embedding (@equiv.ulift α), from ⟨⟨rfl⟩, ulift.down_injective⟩,
exact (complete_space_congr this).2 h,
end
lemma complete_space_extension {m : β → α} (hm : uniform_inducing m) (dense : dense_range m)
(h : ∀f:filter β, cauchy f → ∃x:α, map m f ≤ 𝓝 x) : complete_space α :=
⟨assume (f : filter α), assume hf : cauchy f,
let
p : set (α × α) → set α → set α := λs t, {y : α| ∃x:α, x ∈ t ∧ (x, y) ∈ s},
g := (𝓤 α).lift (λs, f.lift' (p s))
in
have mp₀ : monotone p,
from assume a b h t s ⟨x, xs, xa⟩, ⟨x, xs, h xa⟩,
have mp₁ : ∀{s}, monotone (p s),
from assume s a b h x ⟨y, ya, yxs⟩, ⟨y, h ya, yxs⟩,
have f ≤ g, from
le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht,
le_principal_iff.mpr $
mem_of_superset ht $ assume x hx, ⟨x, hx, refl_mem_uniformity hs⟩,
have ne_bot g, from hf.left.mono this,
have ne_bot (comap m g), from comap_ne_bot $ assume t ht,
let ⟨t', ht', ht_mem⟩ := (mem_lift_sets $ monotone_lift' monotone_const mp₀).mp ht in
let ⟨t'', ht'', ht'_sub⟩ := (mem_lift'_sets mp₁).mp ht_mem in
let ⟨x, (hx : x ∈ t'')⟩ := hf.left.nonempty_of_mem ht'' in
have h₀ : ne_bot (𝓝[range m] x),
from dense.nhds_within_ne_bot x,
have h₁ : {y | (x, y) ∈ t'} ∈ 𝓝[range m] x,
from @mem_inf_of_left α (𝓝 x) (𝓟 (range m)) _ $ mem_nhds_left x ht',
have h₂ : range m ∈ 𝓝[range m] x,
from @mem_inf_of_right α (𝓝 x) (𝓟 (range m)) _ $ subset.refl _,
have {y | (x, y) ∈ t'} ∩ range m ∈ 𝓝[range m] x,
from @inter_mem α (𝓝[range m] x) _ _ h₁ h₂,
let ⟨y, xyt', b, b_eq⟩ := h₀.nonempty_of_mem this in
⟨b, b_eq.symm ▸ ht'_sub ⟨x, hx, xyt'⟩⟩,
have cauchy g, from
⟨‹ne_bot g›, assume s hs,
let
⟨s₁, hs₁, (comp_s₁ : comp_rel s₁ s₁ ⊆ s)⟩ := comp_mem_uniformity_sets hs,
⟨s₂, hs₂, (comp_s₂ : comp_rel s₂ s₂ ⊆ s₁)⟩ := comp_mem_uniformity_sets hs₁,
⟨t, ht, (prod_t : t ×ˢ t ⊆ s₂)⟩ := mem_prod_same_iff.mp (hf.right hs₂)
in
have hg₁ : p (preimage prod.swap s₁) t ∈ g,
from mem_lift (symm_le_uniformity hs₁) $ @mem_lift' α α f _ t ht,
have hg₂ : p s₂ t ∈ g,
from mem_lift hs₂ $ @mem_lift' α α f _ t ht,
have hg : p (prod.swap ⁻¹' s₁) t ×ˢ p s₂ t ∈ g ×ᶠ g,
from @prod_mem_prod α α _ _ g g hg₁ hg₂,
(g ×ᶠ g).sets_of_superset hg
(assume ⟨a, b⟩ ⟨⟨c₁, c₁t, hc₁⟩, ⟨c₂, c₂t, hc₂⟩⟩,
have (c₁, c₂) ∈ t ×ˢ t, from ⟨c₁t, c₂t⟩,
comp_s₁ $ prod_mk_mem_comp_rel hc₁ $
comp_s₂ $ prod_mk_mem_comp_rel (prod_t this) hc₂)⟩,
have cauchy (filter.comap m g),
from ‹cauchy g›.comap' (le_of_eq hm.comap_uniformity) ‹_›,
let ⟨x, (hx : map m (filter.comap m g) ≤ 𝓝 x)⟩ := h _ this in
have cluster_pt x (map m (filter.comap m g)),
from (le_nhds_iff_adhp_of_cauchy (this.map hm.uniform_continuous)).mp hx,
have cluster_pt x g,
from this.mono map_comap_le,
⟨x, calc f ≤ g : by assumption
... ≤ 𝓝 x : le_nhds_of_cauchy_adhp ‹cauchy g› this⟩⟩
lemma totally_bounded_preimage {f : α → β} {s : set β} (hf : uniform_embedding f)
(hs : totally_bounded s) : totally_bounded (f ⁻¹' s) :=
λ t ht, begin
rw ← hf.comap_uniformity at ht,
rcases mem_comap.2 ht with ⟨t', ht', ts⟩,
rcases totally_bounded_iff_subset.1
(totally_bounded_subset (image_preimage_subset f s) hs) _ ht' with ⟨c, cs, hfc, hct⟩,
refine ⟨f ⁻¹' c, hfc.preimage (hf.inj.inj_on _), λ x h, _⟩,
have := hct (mem_image_of_mem f h), simp at this ⊢,
rcases this with ⟨z, zc, zt⟩,
rcases cs zc with ⟨y, yc, rfl⟩,
exact ⟨y, zc, ts (by exact zt)⟩
end
instance complete_space.sum [complete_space α] [complete_space β] :
complete_space (α ⊕ β) :=
begin
rw [complete_space_iff_is_complete_univ, ← range_inl_union_range_inr],
exact uniform_embedding_inl.to_uniform_inducing.is_complete_range.union
uniform_embedding_inr.to_uniform_inducing.is_complete_range
end
end
lemma uniform_embedding_comap {α : Type*} {β : Type*} {f : α → β} [u : uniform_space β]
(hf : function.injective f) : @uniform_embedding α β (uniform_space.comap f u) u f :=
@uniform_embedding.mk _ _ (uniform_space.comap f u) _ _
(@uniform_inducing.mk _ _ (uniform_space.comap f u) _ _ rfl) hf
/-- Pull back a uniform space structure by an embedding, adjusting the new uniform structure to
make sure that its topology is defeq to the original one. -/
def embedding.comap_uniform_space {α β} [topological_space α] [u : uniform_space β] (f : α → β)
(h : embedding f) : uniform_space α :=
(u.comap f).replace_topology h.induced
lemma embedding.to_uniform_embedding {α β} [topological_space α] [u : uniform_space β] (f : α → β)
(h : embedding f) :
@uniform_embedding α β (h.comap_uniform_space f) u f :=
{ comap_uniformity := rfl,
inj := h.inj }
section uniform_extension
variables {α : Type*} {β : Type*} {γ : Type*}
[uniform_space α] [uniform_space β] [uniform_space γ]
{e : β → α}
(h_e : uniform_inducing e)
(h_dense : dense_range e)
{f : β → γ}
(h_f : uniform_continuous f)
local notation `ψ` := (h_e.dense_inducing h_dense).extend f
lemma uniformly_extend_exists [complete_space γ] (a : α) :
∃c, tendsto f (comap e (𝓝 a)) (𝓝 c) :=
let de := (h_e.dense_inducing h_dense) in
have cauchy (𝓝 a), from cauchy_nhds,
have cauchy (comap e (𝓝 a)), from
this.comap' (le_of_eq h_e.comap_uniformity) (de.comap_nhds_ne_bot _),
have cauchy (map f (comap e (𝓝 a))), from this.map h_f,
complete_space.complete this
lemma uniform_extend_subtype [complete_space γ]
{p : α → Prop} {e : α → β} {f : α → γ} {b : β} {s : set α}
(hf : uniform_continuous (λx:subtype p, f x.val))
(he : uniform_embedding e) (hd : ∀x:β, x ∈ closure (range e))
(hb : closure (e '' s) ∈ 𝓝 b) (hs : is_closed s) (hp : ∀x∈s, p x) :
∃c, tendsto f (comap e (𝓝 b)) (𝓝 c) :=
have de : dense_embedding e,
from he.dense_embedding hd,
have de' : dense_embedding (dense_embedding.subtype_emb p e),
by exact de.subtype p,
have ue' : uniform_embedding (dense_embedding.subtype_emb p e),
from uniform_embedding_subtype_emb _ he de,
have b ∈ closure (e '' {x | p x}),
from (closure_mono $ monotone_image $ hp) (mem_of_mem_nhds hb),
let ⟨c, (hc : tendsto (f ∘ subtype.val)
(comap (dense_embedding.subtype_emb p e) (𝓝 ⟨b, this⟩)) (𝓝 c))⟩ :=
uniformly_extend_exists ue'.to_uniform_inducing de'.dense hf _ in
begin
rw [nhds_subtype_eq_comap] at hc,
simp [comap_comap] at hc,
change (tendsto (f ∘ @subtype.val α p) (comap (e ∘ @subtype.val α p) (𝓝 b)) (𝓝 c)) at hc,
rw [←comap_comap, tendsto_comap'_iff] at hc,
exact ⟨c, hc⟩,
exact ⟨_, hb, assume x,
begin
change e x ∈ (closure (e '' s)) → x ∈ range subtype.val,
rw [← closure_induced, mem_closure_iff_cluster_pt, cluster_pt, ne_bot_iff,
nhds_induced, ← de.to_dense_inducing.nhds_eq_comap,
← mem_closure_iff_nhds_ne_bot, hs.closure_eq],
exact assume hxs, ⟨⟨x, hp x hxs⟩, rfl⟩,
end⟩
end
include h_f
lemma uniformly_extend_spec [complete_space γ] (a : α) :
tendsto f (comap e (𝓝 a)) (𝓝 (ψ a)) :=
by simpa only [dense_inducing.extend] using tendsto_nhds_lim (uniformly_extend_exists h_e ‹_› h_f _)
lemma uniform_continuous_uniformly_extend [cγ : complete_space γ] : uniform_continuous ψ :=
assume d hd,
let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $
monotone_id.comp_rel $ monotone_id.comp_rel monotone_id).mp
(comp_le_uniformity3 hd) in
have h_pnt : ∀{a m}, m ∈ 𝓝 a → ∃c, c ∈ f '' preimage e m ∧ (c, ψ a) ∈ s ∧ (ψ a, c) ∈ s,
from assume a m hm,
have nb : ne_bot (map f (comap e (𝓝 a))),
from ((h_e.dense_inducing h_dense).comap_nhds_ne_bot _).map _,
have (f '' preimage e m) ∩ ({c | (c, ψ a) ∈ s } ∩ {c | (ψ a, c) ∈ s }) ∈ map f (comap e (𝓝 a)),
from inter_mem (image_mem_map $ preimage_mem_comap $ hm)
(uniformly_extend_spec h_e h_dense h_f _
(inter_mem (mem_nhds_right _ hs) (mem_nhds_left _ hs))),
nb.nonempty_of_mem this,
have preimage (λp:β×β, (f p.1, f p.2)) s ∈ 𝓤 β,
from h_f hs,
have preimage (λp:β×β, (f p.1, f p.2)) s ∈ comap (λx:β×β, (e x.1, e x.2)) (𝓤 α),
by rwa [h_e.comap_uniformity.symm] at this,
let ⟨t, ht, ts⟩ := this in
show preimage (λp:(α×α), (ψ p.1, ψ p.2)) d ∈ 𝓤 α,
from (𝓤 α).sets_of_superset (interior_mem_uniformity ht) $
assume ⟨x₁, x₂⟩ hx_t,
have 𝓝 (x₁, x₂) ≤ 𝓟 (interior t),
from is_open_iff_nhds.mp is_open_interior (x₁, x₂) hx_t,
have interior t ∈ 𝓝 x₁ ×ᶠ 𝓝 x₂,
by rwa [nhds_prod_eq, le_principal_iff] at this,
let ⟨m₁, hm₁, m₂, hm₂, (hm : m₁ ×ˢ m₂ ⊆ interior t)⟩ := mem_prod_iff.mp this in
let ⟨a, ha₁, _, ha₂⟩ := h_pnt hm₁ in
let ⟨b, hb₁, hb₂, _⟩ := h_pnt hm₂ in
have (e ⁻¹' m₁) ×ˢ (e ⁻¹' m₂) ⊆ (λ p : β × β, (f p.1, f p.2)) ⁻¹' s,
from calc _ ⊆ preimage (λp:(β×β), (e p.1, e p.2)) (interior t) : preimage_mono hm
... ⊆ preimage (λp:(β×β), (e p.1, e p.2)) t : preimage_mono interior_subset
... ⊆ preimage (λp:(β×β), (f p.1, f p.2)) s : ts,
have (f '' (e ⁻¹' m₁)) ×ˢ (f '' (e ⁻¹' m₂)) ⊆ s,
from calc (f '' (e ⁻¹' m₁)) ×ˢ (f '' (e ⁻¹' m₂)) =
(λp:(β×β), (f p.1, f p.2)) '' ((e ⁻¹' m₁) ×ˢ (e ⁻¹' m₂)) : prod_image_image_eq
... ⊆ (λp:(β×β), (f p.1, f p.2)) '' ((λp:(β×β), (f p.1, f p.2)) ⁻¹' s) : monotone_image this
... ⊆ s : image_preimage_subset _ _,
have (a, b) ∈ s, from @this (a, b) ⟨ha₁, hb₁⟩,
hs_comp $ show (ψ x₁, ψ x₂) ∈ comp_rel s (comp_rel s s),
from ⟨a, ha₂, ⟨b, this, hb₂⟩⟩
omit h_f
variables [separated_space γ]
lemma uniformly_extend_of_ind (b : β) : ψ (e b) = f b :=
dense_inducing.extend_eq_at _ h_f.continuous.continuous_at
lemma uniformly_extend_unique {g : α → γ} (hg : ∀ b, g (e b) = f b)
(hc : continuous g) :
ψ = g :=
dense_inducing.extend_unique _ hg hc
end uniform_extension
|
50ff299f15f0e48b0f0a07cd6d449f3e65786654 | 2d041ea7f2e9b29093ffd7c99b11decfaa8b20ca | /ch3.lean | 45f009b4b8155d7b2240d460511a7152056f0d64 | [] | no_license | 0xpr/lean_tutorial | 1a66577602baa9a52c2b01130b9d70089653ea37 | 56ef609d8df9e392916012db5354bf182cbbb8d8 | refs/heads/master | 1,606,955,421,810 | 1,499,014,388,000 | 1,499,014,388,000 | 96,036,899 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,646 | lean | open classical
variables p q r s : Prop
-- commutativity of ∧ and ∨
example : p ∧ q ↔ q ∧ p :=
iff.intro
(assume H : p ∧ q,
show q ∧ p, from and.intro (and.elim_right H) (and.elim_left H))
(assume H : q ∧ p,
show p ∧ q, from and.intro (and.elim_right H) (and.elim_left H))
example : p ∨ q ↔ q ∨ p :=
iff.intro
(assume H : p ∨ q, show q ∨ p, from
or.elim H
(assume H : p, show q ∨ p, from or.intro_right q H)
(assume H : q, show q ∨ p, from or.intro_left p H))
(assume H : q ∨ p, show p ∨ q, from
or.elim H
(assume H : q, show p ∨ q, from or.intro_right p H)
(assume H : p, show p ∨ q, from or.intro_left q H))
-- associativity of ∧ and ∨
example : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=
iff.intro
(assume H : (p ∧ q) ∧ r, show p ∧ (q ∧ r), from
and.intro
(and.elim_left (and.elim_left H))
(and.intro (and.elim_right (and.elim_left H)) (and.elim_right H)))
(assume H : p ∧ (q ∧ r), show (p ∧ q) ∧ r, from
and.intro
(and.intro (and.elim_left H) (and.elim_left (and.elim_right H)))
(and.elim_right (and.elim_right H)))
example : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=
iff.intro
(assume H : (p ∨ q) ∨ r, show p ∨ (q ∨ r), from
or.elim H
(assume H : p ∨ q, show p ∨ (q ∨ r), from
or.elim H
(assume H : p, show p ∨ (q ∨ r), from
or.intro_left (q ∨ r) H)
(assume H : q, show p ∨ (q ∨ r), from
or.intro_right p (or.intro_left r H)))
(assume H : r, show p ∨ (q ∨ r), from
or.intro_right p (or.intro_right q H)))
(assume H : p ∨ (q ∨ r), show (p ∨ q) ∨ r, from
or.elim H
(assume H : p, show (p ∨ q) ∨ r, from
or.intro_left r (or.intro_left q H))
(assume H : q ∨ r, show (p ∨ q) ∨ r, from
or.elim H
(assume H : q, show (p ∨ q) ∨ r, from
or.intro_left r (or.intro_right p H))
(assume H : r, show (p ∨ q) ∨ r, from
or.intro_right (p ∨ q) H)))
-- distributivity
example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=
iff.intro
(assume H : p ∧ (q ∨ r), show (p ∧ q) ∨ (p ∧ r), from
have Hp : p, from and.elim_left H,
or.elim (and.elim_right H)
(assume Hq : q, show (p ∧ q) ∨ (p ∧ r), from
or.intro_left (p ∧ r) (and.intro Hp Hq))
(assume Hr : r, show (p ∧ q) ∨ (p ∧ r), from
or.intro_right (p ∧ q) (and.intro Hp Hr)))
(assume H : (p ∧ q) ∨ (p ∧ r), show p ∧ (q ∨ r), from
or.elim H
(assume H : p ∧ q, show p ∧ (q ∨ r), from
and.intro (and.elim_left H)
(or.intro_left r (and.elim_right H)))
(assume H : p ∧ r, show p ∧ (q ∨ r), from
and.intro (and.elim_left H)
(or.intro_right q (and.elim_right H))))
example : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=
iff.intro
(assume H : p ∨ (q ∧ r), show (p ∨ q) ∧ (p ∨ r), from
or.elim H
(assume Hp : p, show (p ∨ q) ∧ (p ∨ r), from
and.intro (or.intro_left q Hp) (or.intro_left r Hp))
(assume Hqr : q ∧ r, show (p ∨ q) ∧ (p ∨ r), from
and.intro (or.intro_right p (and.elim_left Hqr))
(or.intro_right p (and.elim_right Hqr))))
(assume H : (p ∨ q) ∧ (p ∨ r), show p ∨ (q ∧ r), from
(λ Hpq : p ∨ q,
or.elim Hpq
(λ Hp : p,
λ Hpr : p ∨ r, or.inl Hp)
(λ Hq : q,
(λ Hpr : p ∨ r,
or.elim Hpr
(λ Hp : p, or.inl Hp)
(λ Hr : r, or.inr (and.intro Hq Hr)))))
(and.elim_left H)
(and.elim_right H))
-- other properties
example : (p → (q → r)) ↔ (p ∧ q → r) :=
iff.intro
(assume H : p → (q → r), show (p ∧ q → r), from
(assume Hpq : p ∧ q, show r, from
(H (and.elim_left Hpq)) (and.elim_right Hpq)))
(assume H : p ∧ q → r, show p → (q → r), from
(assume Hp : p, show q → r, from
(assume Hq : q, show r, from
H (and.intro Hp Hq))))
example : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=
iff.intro
(λ H : (p ∨ q) → r,
and.intro (λ Hp : p, H (or.inl Hp)) (λ Hq : q, H (or.inr Hq)))
(λ H : (p → r) ∧ (q → r),
(λ Hpq : p ∨ q,
or.elim Hpq
(λ Hp : p, (and.elim_left H) Hp)
(λ Hq : q, (and.elim_right H) Hq)))
example : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=
iff.intro
(λ H : ¬(p ∨ q), and.intro
(λ Hp : p, H (or.inl Hp))
(λ Hq : q, H (or.inr Hq)))
(λ H : ¬p ∧ ¬q,
(λ Hpq : p ∨ q, or.elim Hpq
(λ Hp : p, (and.elim_left H) Hp)
(λ Hq : q, (and.elim_right H) Hq)))
example : ¬p ∨ ¬q → ¬(p ∧ q) :=
(λ H : ¬p ∨ ¬q, or.elim H
(λ Hp : ¬p,
(λ Hpq : p ∧ q, Hp (and.elim_left Hpq)))
(λ Hq : ¬q,
(λ Hpq : p ∧ q, Hq (and.elim_right Hpq))))
example : ¬(p ∧ ¬ p) :=
(λ H : p ∧ ¬ p, (and.elim_right H) (and.elim_left H))
example : p ∧ ¬q → ¬(p → q) :=
(λ H : p ∧ ¬q,
(λ H1 : p → q,
(and.elim_right H) (H1 (and.elim_left H))))
example : ¬p → (p → q) :=
(λ Hnp : ¬p,
(λ Hp : p, false.elim (Hnp Hp)))
example : (¬p ∨ q) → (p → q) :=
(λ H : ¬p ∨ q, or.elim H
(λ Hnp : ¬p, (λ Hp : p, false.elim (Hnp Hp)))
(λ Hq : q, (λ Hp : p, Hq)))
example : p ∨ false ↔ p :=
iff.intro
(λ H : p ∨ false, or.elim H
(λ Hp : p, Hp)
(λ H : false, false.elim H))
(λ Hp : p, or.inl Hp)
example : p ∧ false ↔ false :=
iff.intro
(λ H : p ∧ false, and.elim_right H)
(λ H : false, false.elim H)
example : ¬(p ↔ ¬p) := iff.elim
(λ H1 : p → ¬p,
(λ H2 : ¬p → p,
let Hnp := (λ Hp : p, (H1 Hp) Hp) in
let Hp := H2 Hnp in
Hnp Hp))
example : (p → q) → (¬q → ¬p) :=
(λ H : p → q,
(λ Hnq : ¬q,
(λ Hp : p, Hnq (H Hp))))
-- these require classical reasoning
example : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=
let or_help (Hnr : ¬r) (H : r ∨ s) :=
or.elim H
(λ Hr : r, false.elim (Hnr Hr))
(λ Hs : s, Hs)
in
(λ H : p → r ∨ s,
let mr := em r in
or.elim mr
(λ Hr : r, or.inl (λ Hp : p, Hr))
(λ Hnr : ¬r, or.inr (λ Hp : p, or_help Hnr (H Hp))))
example : ¬(p ∧ q) → ¬p ∨ ¬q :=
(λ H : ¬(p ∧ q),
or.elim (em p)
(λ Hp : p,
or.elim (em q)
(λ Hq : q, false.elim (H (and.intro Hp Hq)))
(λ Hnq : ¬q, or.inr Hnq))
(λ Hnp : ¬p, or.inl Hnp))
example : ¬(p → q) → p ∧ ¬q :=
(λ H : ¬(p → q),
let Hnq := (λ Hq : q, H (λ Hp : p, Hq)) in
let Hp := or.elim (em p)
(λ Hp : p, Hp)
(λ Hnp : ¬p, false.elim (H (λ Hp : p, false.elim (Hnp Hp))))
in
and.intro Hp Hnq)
example : (p → q) → (¬p ∨ q) :=
(λ H : p → q,
or.elim (em p)
(λ Hp : p, or.inr (H Hp))
(λ Hnp : ¬p, or.inl Hnp))
example : (¬q → ¬p) → (p → q) :=
(λ H : ¬q → ¬p,
(λ Hp : p, or.elim (em q)
(λ Hq : q, Hq)
(λ Hnq : ¬q, false.elim ((H Hnq) Hp))))
example : p ∨ ¬p := em p
example : (((p → q) → p) → p) :=
(λ H : (p → q) → p,
or.elim (em p)
(λ Hp : p, Hp)
(λ Hnp : ¬p, H
(λ Hp : p, false.elim (Hnp Hp))))
|
5a35e9cd6ab8f9d34fcde87a7827baf762ae5149 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0409.lean | 0c14d0b6e02941006d3db851425719fc79b49e08 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 306 | lean | example (p q r : Prop) : p ∧ (q ∨ r) → (p ∧ q) ∨ (p ∧ r) :=
begin
intro h,
cases h with hp hqr,
show (p ∧ q) ∨ (p ∧ r),
cases hqr with hq hr,
have : p ∧ q,
split; assumption,
left, exact this,
have : p ∧ r,
split; assumption,
right, exact this
end
|
0a5d65cc100c7e3c432acf612bed04f9d1d9ff42 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/bornology/constructions.lean | 1cbbd2438f29fba8623d7986d3f17df28616d64a | [
"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,131 | lean | /-
Copyright (c) 2022 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import topology.bornology.basic
/-!
# Bornology structure on products and subtypes
In this file we define `bornology` and `bounded_space` instances on `α × β`, `Π i, π i`, and
`{x // p x}`. We also prove basic lemmas about `bornology.cobounded` and `bornology.is_bounded`
on these types.
-/
open set filter bornology function
open_locale filter
variables {α β ι : Type*} {π : ι → Type*} [fintype ι] [bornology α] [bornology β]
[Π i, bornology (π i)]
instance : bornology (α × β) :=
{ cobounded := (cobounded α).coprod (cobounded β),
le_cofinite := @coprod_cofinite α β ▸ coprod_mono ‹bornology α›.le_cofinite
‹bornology β›.le_cofinite }
instance : bornology (Π i, π i) :=
{ cobounded := filter.Coprod (λ i, cobounded (π i)),
le_cofinite := @Coprod_cofinite ι π _ ▸ (filter.Coprod_mono $ λ i, bornology.le_cofinite _) }
/-- Inverse image of a bornology. -/
@[reducible] def bornology.induced {α β : Type*} [bornology β] (f : α → β) : bornology α :=
{ cobounded := comap f (cobounded β),
le_cofinite := (comap_mono (bornology.le_cofinite β)).trans (comap_cofinite_le _) }
instance {p : α → Prop} : bornology (subtype p) := bornology.induced (coe : subtype p → α)
namespace bornology
/-!
### Bounded sets in `α × β`
-/
lemma cobounded_prod : cobounded (α × β) = (cobounded α).coprod (cobounded β) := rfl
lemma is_bounded_image_fst_and_snd {s : set (α × β)} :
is_bounded (prod.fst '' s) ∧ is_bounded (prod.snd '' s) ↔ is_bounded s :=
compl_mem_coprod.symm
variables {s : set α} {t : set β} {S : Π i, set (π i)}
lemma is_bounded.fst_of_prod (h : is_bounded (s ×ˢ t)) (ht : t.nonempty) :
is_bounded s :=
fst_image_prod s ht ▸ (is_bounded_image_fst_and_snd.2 h).1
lemma is_bounded.snd_of_prod (h : is_bounded (s ×ˢ t)) (hs : s.nonempty) :
is_bounded t :=
snd_image_prod hs t ▸ (is_bounded_image_fst_and_snd.2 h).2
lemma is_bounded.prod (hs : is_bounded s) (ht : is_bounded t) : is_bounded (s ×ˢ t) :=
is_bounded_image_fst_and_snd.1
⟨hs.subset $ fst_image_prod_subset _ _, ht.subset $ snd_image_prod_subset _ _⟩
lemma is_bounded_prod_of_nonempty (hne : set.nonempty (s ×ˢ t)) :
is_bounded (s ×ˢ t) ↔ is_bounded s ∧ is_bounded t :=
⟨λ h, ⟨h.fst_of_prod hne.snd, h.snd_of_prod hne.fst⟩, λ h, h.1.prod h.2⟩
lemma is_bounded_prod : is_bounded (s ×ˢ t) ↔ s = ∅ ∨ t = ∅ ∨ is_bounded s ∧ is_bounded t :=
begin
rcases s.eq_empty_or_nonempty with rfl|hs, { simp },
rcases t.eq_empty_or_nonempty with rfl|ht, { simp },
simp only [hs.ne_empty, ht.ne_empty, is_bounded_prod_of_nonempty (hs.prod ht), false_or]
end
lemma is_bounded_prod_self : is_bounded (s ×ˢ s) ↔ is_bounded s :=
begin
rcases s.eq_empty_or_nonempty with rfl|hs, { simp },
exact (is_bounded_prod_of_nonempty (hs.prod hs)).trans (and_self _)
end
/-!
### Bounded sets in `Π i, π i`
-/
lemma cobounded_pi : cobounded (Π i, π i) = filter.Coprod (λ i, cobounded (π i)) := rfl
lemma forall_is_bounded_image_eval_iff {s : set (Π i, π i)} :
(∀ i, is_bounded (eval i '' s)) ↔ is_bounded s :=
compl_mem_Coprod.symm
lemma is_bounded.pi (h : ∀ i, is_bounded (S i)) : is_bounded (pi univ S) :=
forall_is_bounded_image_eval_iff.1 $ λ i, (h i).subset eval_image_univ_pi_subset
lemma is_bounded_pi_of_nonempty (hne : (pi univ S).nonempty) :
is_bounded (pi univ S) ↔ ∀ i, is_bounded (S i) :=
⟨λ H i, @eval_image_univ_pi _ _ _ i hne ▸ forall_is_bounded_image_eval_iff.2 H i, is_bounded.pi⟩
lemma is_bounded_pi : is_bounded (pi univ S) ↔ (∃ i, S i = ∅) ∨ ∀ i, is_bounded (S i) :=
begin
by_cases hne : ∃ i, S i = ∅,
{ simp [hne, univ_pi_eq_empty_iff.2 hne] },
{ simp only [hne, false_or],
simp only [not_exists, ← ne.def, ne_empty_iff_nonempty, ← univ_pi_nonempty_iff] at hne,
exact is_bounded_pi_of_nonempty hne }
end
/-!
### Bounded sets in `{x // p x}`
-/
lemma is_bounded_induced {α β : Type*} [bornology β] {f : α → β} {s : set α} :
@is_bounded α (bornology.induced f) s ↔ is_bounded (f '' s) :=
compl_mem_comap
lemma is_bounded_image_subtype_coe {p : α → Prop} {s : set {x // p x}} :
is_bounded (coe '' s : set α) ↔ is_bounded s :=
is_bounded_induced.symm
end bornology
/-!
### Bounded spaces
-/
open bornology
instance [bounded_space α] [bounded_space β] : bounded_space (α × β) :=
by simp [← cobounded_eq_bot_iff, cobounded_prod]
instance [∀ i, bounded_space (π i)] : bounded_space (Π i, π i) :=
by simp [← cobounded_eq_bot_iff, cobounded_pi]
lemma bounded_space_induced_iff {α β : Type*} [bornology β] {f : α → β} :
@bounded_space α (bornology.induced f) ↔ is_bounded (range f) :=
by rw [← is_bounded_univ, is_bounded_induced, image_univ]
lemma bounded_space_subtype_iff {p : α → Prop} : bounded_space (subtype p) ↔ is_bounded {x | p x} :=
by rw [bounded_space_induced_iff, subtype.range_coe_subtype]
lemma bounded_space_coe_set_iff {s : set α} : bounded_space s ↔ is_bounded s :=
bounded_space_subtype_iff
alias bounded_space_subtype_iff ↔ _ bornology.is_bounded.bounded_space_subtype
alias bounded_space_coe_set_iff ↔ _ bornology.is_bounded.bounded_space_coe
instance [bounded_space α] {p : α → Prop} : bounded_space (subtype p) :=
(is_bounded.all {x | p x}).bounded_space_subtype
/-!
### `additive`, `multiplicative`
The bornology on those type synonyms is inherited without change.
-/
instance : bornology (additive α) := ‹bornology α›
instance : bornology (multiplicative α) := ‹bornology α›
instance [bounded_space α] : bounded_space (additive α) := ‹bounded_space α›
instance [bounded_space α] : bounded_space (multiplicative α) := ‹bounded_space α›
/-!
### Order dual
The bornology on this type synonym is inherited without change.
-/
instance : bornology αᵒᵈ := ‹bornology α›
instance [bounded_space α] : bounded_space αᵒᵈ := ‹bounded_space α›
|
2c037df2aa7a5de5e5aac346282f3b63cb10015b | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/testing/slim_check/functions.lean | 6b1944c1b0d9d1078619ed068138d298280478fa | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 16,688 | lean | /-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import data.list.sigma
import testing.slim_check.sampleable
import testing.slim_check.testable
import tactic.pretty_cases
/-!
## `slim_check`: generators for functions
This file defines `sampleable` instances for `α → β` functions and
`ℤ → ℤ` injective functions.
Functions are generated by creating a list of pairs and one more value
using the list as a lookup table and resorting to the additional value
when a value is not found in the table.
Injective functions are generated by creating a list of numbers and
a permutation of that list. The permutation insures that every input
is mapped to a unique output. When an input is not found in the list
the input itself is used as an output.
Injective functions `f : α → α` could be generated easily instead of
`ℤ → ℤ` by generating a `list α`, removing duplicates and creating a
permutations. One has to be careful when generating the domain to make
if vast enough that, when generating arguments to apply `f` to,
they argument should be likely to lie in the domain of `f`. This is
the reason that injective functions `f : ℤ → ℤ` are generated by
fixing the domain to the range `[-2*size .. -2*size]`, with `size`
the size parameter of the `gen` monad.
Much of the machinery provided in this file is applicable to generate
injective functions of type `α → α` and new instances should be easy
to define.
Other classes of functions such as monotone functions can generated using
similar techniques. For monotone functions, generating two lists, sorting them
and matching them should suffice, with appropriate default values.
Some care must be taken for shrinking such functions to make sure
their defining property is invariant through shrinking. Injective
functions are an example of how complicated it can get.
-/
universes u v w
variables {α : Type u} {β : Type v} {γ : Sort w}
namespace slim_check
/-- Data structure specifying a total function using a list of pairs
and a default value returned when the input is not in the domain of
the partial function.
`with_default f y` encodes `x ↦ f x` when `x ∈ f` and `x ↦ y`
otherwise.
We use `Σ` to encode mappings instead of `×` because we
rely on the association list API defined in `data.list.sigma`.
-/
inductive total_function (α : Type u) (β : Type v) : Type (max u v)
| with_default : list (Σ _ : α, β) → β → total_function
instance total_function.inhabited [inhabited β] : inhabited (total_function α β) :=
⟨ total_function.with_default ∅ (default _) ⟩
namespace total_function
/-- Apply a total function to an argument. -/
def apply [decidable_eq α] : total_function α β → α → β
| (total_function.with_default m y) x := (m.lookup x).get_or_else y
/--
Implementation of `has_repr (total_function α β)`.
Creates a string for a given `finmap` and output, `x₀ ↦ y₀, .. xₙ ↦ yₙ`
for each of the entries. The brackets are provided by the calling function.
-/
def repr_aux [has_repr α] [has_repr β] (m : list (Σ _ : α, β)) : string :=
string.join $ list.qsort (λ x y, x < y)
(m.map $ λ x, sformat!"{repr $ sigma.fst x} ↦ {repr $ sigma.snd x}, ")
/--
Produce a string for a given `total_function`.
The output is of the form `[x₀ ↦ f x₀, .. xₙ ↦ f xₙ, _ ↦ y]`.
-/
protected def repr [has_repr α] [has_repr β] : total_function α β → string
| (total_function.with_default m y) := sformat!"[{repr_aux m}_ ↦ {has_repr.repr y}]"
instance (α : Type u) (β : Type v) [has_repr α] [has_repr β] : has_repr (total_function α β) :=
⟨ total_function.repr ⟩
/-- Create a `finmap` from a list of pairs. -/
def list.to_finmap' (xs : list (α × β)) : list (Σ _ : α, β) :=
xs.map prod.to_sigma
section
variables [sampleable α] [sampleable β]
/-- Redefine `sizeof` to follow the structure of `sampleable` instances. -/
def total.sizeof : total_function α β → ℕ
| ⟨m, x⟩ := 1 + @sizeof _ sampleable.wf m + sizeof x
@[priority 2000]
instance : has_sizeof (total_function α β) :=
⟨ total.sizeof ⟩
variables [decidable_eq α]
/-- Shrink a total function by shrinking the lists that represent it. -/
protected def shrink : shrink_fn (total_function α β)
| ⟨m, x⟩ := (sampleable.shrink (m, x)).map $ λ ⟨⟨m', x'⟩, h⟩, ⟨⟨list.erase_dupkeys m', x'⟩,
lt_of_le_of_lt
(by unfold_wf; refine @list.sizeof_erase_dupkeys _ _ _ (@sampleable.wf _ _) _) h ⟩
variables [has_repr α] [has_repr β]
instance pi.sampleable_ext : sampleable_ext (α → β) :=
{ proxy_repr := total_function α β,
interp := total_function.apply,
sample := do {
xs ← (sampleable.sample (list (α × β)) : gen ((list (α × β)))),
⟨x⟩ ← (uliftable.up $ sample β : gen (ulift.{max u v} β)),
pure $ total_function.with_default (list.to_finmap' xs) x },
shrink := total_function.shrink }
end
section sampleable_ext
open sampleable_ext
@[priority 2000]
instance pi_pred.sampleable_ext [sampleable_ext (α → bool)] :
sampleable_ext.{u+1} (α → Prop) :=
{ proxy_repr := proxy_repr (α → bool),
interp := λ m x, interp (α → bool) m x,
sample := sample (α → bool),
shrink := shrink }
@[priority 2000]
instance pi_uncurry.sampleable_ext
[sampleable_ext (α × β → γ)] : sampleable_ext.{(imax (u+1) (v+1) w)} (α → β → γ) :=
{ proxy_repr := proxy_repr (α × β → γ),
interp := λ m x y, interp (α × β → γ) m (x, y),
sample := sample (α × β → γ),
shrink := shrink }
end sampleable_ext
end total_function
/--
Data structure specifying a total function using a list of pairs
and a default value returned when the input is not in the domain of
the partial function.
`map_to_self f` encodes `x ↦ f x` when `x ∈ f` and `x ↦ x`,
i.e. `x` to itself, otherwise.
We use `Σ` to encode mappings instead of `×` because we
rely on the association list API defined in `data.list.sigma`.
-/
inductive injective_function (α : Type u) : Type u
| map_to_self (xs : list (Σ _ : α, α)) :
xs.map sigma.fst ~ xs.map sigma.snd → list.nodup (xs.map sigma.snd) → injective_function
instance : inhabited (injective_function α) :=
⟨ ⟨ [], list.perm.nil, list.nodup_nil ⟩ ⟩
namespace injective_function
/-- Apply a total function to an argument. -/
def apply [decidable_eq α] : injective_function α → α → α
| (injective_function.map_to_self m _ _) x := (m.lookup x).get_or_else x
/--
Produce a string for a given `total_function`.
The output is of the form `[x₀ ↦ f x₀, .. xₙ ↦ f xₙ, x ↦ x]`.
Unlike for `total_function`, the default value is not a constant
but the identity function.
-/
protected def repr [has_repr α] : injective_function α → string
| (injective_function.map_to_self m _ _) := sformat!"[{total_function.repr_aux m}x ↦ x]"
instance (α : Type u) [has_repr α] : has_repr (injective_function α) :=
⟨ injective_function.repr ⟩
/-- Interpret a list of pairs as a total function, defaulting to
the identity function when no entries are found for a given function -/
def list.apply_id [decidable_eq α] (xs : list (α × α)) (x : α) : α :=
((xs.map prod.to_sigma).lookup x).get_or_else x
@[simp]
lemma list.apply_id_cons [decidable_eq α] (xs : list (α × α)) (x y z : α) :
list.apply_id ((y, z) :: xs) x = if y = x then z else list.apply_id xs x :=
by simp only [list.apply_id, list.lookup, eq_rec_constant, prod.to_sigma, list.map]; split_ifs; refl
open function list prod (to_sigma)
open nat
lemma list.apply_id_zip_eq [decidable_eq α] {xs ys : list α} (h₀ : list.nodup xs)
(h₁ : xs.length = ys.length) (x y : α) (i : ℕ)
(h₂ : xs.nth i = some x) :
list.apply_id.{u} (xs.zip ys) x = y ↔ ys.nth i = some y :=
begin
induction xs generalizing ys i,
case list.nil : ys i h₁ h₂
{ cases h₂ },
case list.cons : x' xs xs_ih ys i h₁ h₂
{ cases i,
{ injection h₂ with h₀ h₁, subst h₀,
cases ys,
{ cases h₁ },
{ simp only [list.apply_id, to_sigma, option.get_or_else_some, nth, lookup_cons_eq,
zip_cons_cons, list.map], } },
{ cases ys,
{ cases h₁ },
{ cases h₀ with _ _ h₀ h₁,
simp only [nth, zip_cons_cons, list.apply_id_cons] at h₂ ⊢,
rw if_neg,
{ apply xs_ih; solve_by_elim [succ.inj] },
{ apply h₀, apply nth_mem h₂ } } } }
end
lemma apply_id_mem_iff [decidable_eq α] {xs ys : list α} (h₀ : list.nodup xs)
(h₁ : xs ~ ys)
(x : α) :
list.apply_id.{u} (xs.zip ys) x ∈ ys ↔ x ∈ xs :=
begin
simp only [list.apply_id],
cases h₃ : (lookup x (map prod.to_sigma (xs.zip ys))),
{ dsimp [option.get_or_else],
rw h₁.mem_iff },
{ have h₂ : ys.nodup := h₁.nodup_iff.1 h₀,
replace h₁ : xs.length = ys.length := h₁.length_eq,
dsimp,
induction xs generalizing ys,
case list.nil : ys h₃ h₂ h₁
{ contradiction },
case list.cons : x' xs xs_ih ys h₃ h₂ h₁
{ cases ys with y ys,
{ cases h₃ },
dsimp [lookup] at h₃, split_ifs at h₃,
{ subst x', subst val,
simp only [mem_cons_iff, true_or, eq_self_iff_true], },
{ cases h₀ with _ _ h₀ h₅,
cases h₂ with _ _ h₂ h₄,
have h₆ := nat.succ.inj h₁,
specialize @xs_ih h₅ ys h₃ h₄ h₆,
simp only [ne.symm h, xs_ih, mem_cons_iff, false_or],
suffices : val ∈ ys, tauto!,
erw [← option.mem_def, mem_lookup_iff] at h₃,
simp only [to_sigma, mem_map, heq_iff_eq, prod.exists] at h₃,
rcases h₃ with ⟨a, b, h₃, h₄, h₅⟩,
subst a, subst b,
apply (mem_zip h₃).2,
simp only [nodupkeys, keys, comp, prod.fst_to_sigma, map_map],
rwa map_fst_zip _ _ (le_of_eq h₆) } } }
end
lemma list.apply_id_eq_self [decidable_eq α] {xs ys : list α} (x : α) :
x ∉ xs → list.apply_id.{u} (xs.zip ys) x = x :=
begin
intro h,
dsimp [list.apply_id],
rw lookup_eq_none.2, refl,
simp only [keys, not_exists, to_sigma, exists_and_distrib_right, exists_eq_right, mem_map,
comp_app, map_map, prod.exists],
intros y hy,
exact h (mem_zip hy).1,
end
lemma apply_id_injective [decidable_eq α] {xs ys : list α} (h₀ : list.nodup xs)
(h₁ : xs ~ ys) : injective.{u+1 u+1} (list.apply_id (xs.zip ys)) :=
begin
intros x y h,
by_cases hx : x ∈ xs;
by_cases hy : y ∈ xs,
{ rw mem_iff_nth at hx hy,
cases hx with i hx,
cases hy with j hy,
suffices : some x = some y,
{ injection this },
have h₂ := h₁.length_eq,
rw [list.apply_id_zip_eq h₀ h₂ _ _ _ hx] at h,
rw [← hx, ← hy], congr,
apply nth_injective _ (h₁.nodup_iff.1 h₀),
{ symmetry, rw h,
rw ← list.apply_id_zip_eq; assumption },
{ rw ← h₁.length_eq,
rw nth_eq_some at hx,
cases hx with hx hx',
exact hx } },
{ rw ← apply_id_mem_iff h₀ h₁ at hx hy,
rw h at hx,
contradiction, },
{ rw ← apply_id_mem_iff h₀ h₁ at hx hy,
rw h at hx,
contradiction, },
{ rwa [list.apply_id_eq_self, list.apply_id_eq_self] at h; assumption },
end
open total_function (list.to_finmap')
open sampleable
/--
Remove a slice of length `m` at index `n` in a list and a permutation, maintaining the property
that it is a permutation.
-/
def perm.slice [decidable_eq α] (n m : ℕ) :
(Σ' xs ys : list α, xs ~ ys ∧ ys.nodup) → (Σ' xs ys : list α, xs ~ ys ∧ ys.nodup)
| ⟨xs, ys, h, h'⟩ :=
let xs' := list.slice n m xs in
have h₀ : xs' ~ ys.inter xs',
from perm.slice_inter _ _ h h',
⟨xs', ys.inter xs', h₀, nodup_inter_of_nodup _ h'⟩
/--
A lazy list, in decreasing order, of sizes that should be
sliced off a list of length `n`
-/
def slice_sizes : ℕ → lazy_list ℕ+
| n :=
if h : 0 < n then
have n / 2 < n, from div_lt_self h dec_trivial,
lazy_list.cons ⟨_, h⟩ (slice_sizes $ n / 2)
else lazy_list.nil
/--
Shrink a permutation of a list, slicing a segment in the middle.
The sizes of the slice being removed start at `n` (with `n` the length
of the list) and then `n / 2`, then `n / 4`, etc down to 1. The slices
will be taken at index `0`, `n / k`, `2n / k`, `3n / k`, etc.
-/
protected def shrink_perm {α : Type} [decidable_eq α] [has_sizeof α] :
shrink_fn (Σ' xs ys : list α, xs ~ ys ∧ ys.nodup)
| xs := do
let k := xs.1.length,
n ← slice_sizes k,
i ← lazy_list.of_list $ list.fin_range $ k / n,
have ↑i * ↑n < xs.1.length,
from nat.lt_of_div_lt_div
(lt_of_le_of_lt (by simp only [nat.mul_div_cancel, gt_iff_lt, fin.val_eq_coe, pnat.pos]) i.2),
pure ⟨perm.slice (i*n) n xs,
by rcases xs with ⟨a,b,c,d⟩; dsimp [sizeof_lt]; unfold_wf; simp only [perm.slice];
unfold_wf; apply list.sizeof_slice_lt _ _ n.2 _ this⟩
instance [has_sizeof α] : has_sizeof (injective_function α) :=
⟨ λ ⟨xs,_,_⟩, sizeof (xs.map sigma.fst) ⟩
/--
Shrink an injective function slicing a segment in the middle of the domain and removing
the corresponding elements in the codomain, hence maintaining the property that
one is a permutation of the other.
-/
protected def shrink {α : Type} [has_sizeof α] [decidable_eq α] : shrink_fn (injective_function α)
| ⟨xs, h₀, h₁⟩ := do
⟨⟨xs', ys', h₀, h₁⟩, h₂⟩ ← injective_function.shrink_perm ⟨_, _, h₀, h₁⟩,
have h₃ : xs'.length ≤ ys'.length, from le_of_eq (perm.length_eq h₀),
have h₄ : ys'.length ≤ xs'.length, from le_of_eq (perm.length_eq h₀.symm),
pure ⟨⟨(list.zip xs' ys').map prod.to_sigma,
by simp only [comp, map_fst_zip, map_snd_zip, *, prod.fst_to_sigma, prod.snd_to_sigma, map_map],
by simp only [comp, map_snd_zip, *, prod.snd_to_sigma, map_map] ⟩,
by revert h₂; dsimp [sizeof_lt]; unfold_wf;
simp only [has_sizeof._match_1, map_map, comp, map_fst_zip, *, prod.fst_to_sigma];
unfold_wf; intro h₂; convert h₂ ⟩
/-- Create an injective function from one list and a permutation of that list. -/
protected def mk (xs ys : list α) (h : xs ~ ys) (h' : ys.nodup) : injective_function α :=
have h₀ : xs.length ≤ ys.length, from le_of_eq h.length_eq,
have h₁ : ys.length ≤ xs.length, from le_of_eq h.length_eq.symm,
injective_function.map_to_self (list.to_finmap' (xs.zip ys))
(by { simp only [list.to_finmap', comp, map_fst_zip, map_snd_zip, *,
prod.fst_to_sigma, prod.snd_to_sigma, map_map] })
(by { simp only [list.to_finmap', comp, map_snd_zip, *, prod.snd_to_sigma, map_map] })
protected lemma injective [decidable_eq α] (f : injective_function α) :
injective (apply f) :=
begin
cases f with xs hperm hnodup,
generalize h₀ : map sigma.fst xs = xs₀,
generalize h₁ : xs.map (@id ((Σ _ : α, α) → α) $ @sigma.snd α (λ _ : α, α)) = xs₁,
dsimp [id] at h₁,
have hxs : xs = total_function.list.to_finmap' (xs₀.zip xs₁),
{ rw [← h₀, ← h₁, list.to_finmap'], clear h₀ h₁ xs₀ xs₁ hperm hnodup,
induction xs,
case list.nil
{ simp only [zip_nil_right, map_nil] },
case list.cons : xs_hd xs_tl xs_ih
{ simp only [true_and, to_sigma, eq_self_iff_true, sigma.eta, zip_cons_cons, list.map],
exact xs_ih }, },
revert hperm hnodup,
rw hxs, intros,
apply apply_id_injective,
{ rwa [← h₀, hxs, hperm.nodup_iff], },
{ rwa [← hxs, h₀, h₁] at hperm, },
end
instance pi_injective.sampleable_ext : sampleable_ext { f : ℤ → ℤ // function.injective f } :=
{ proxy_repr := injective_function ℤ,
interp := λ f, ⟨ apply f, f.injective ⟩,
sample := gen.sized $ λ sz, do {
let xs' := int.range (-(2*sz+2)) (2*sz + 2),
ys ← gen.permutation_of xs',
have Hinj : injective (λ (r : ℕ), -(2*sz + 2 : ℤ) + ↑r),
from λ x y h, int.coe_nat_inj (add_right_injective _ h),
let r : injective_function ℤ :=
injective_function.mk.{0} xs' ys.1 ys.2 (ys.2.nodup_iff.1 $ nodup_map Hinj (nodup_range _)) in
pure r },
shrink := @injective_function.shrink ℤ _ _ }
end injective_function
open function
instance injective.testable (f : α → β)
[I : testable (named_binder "x" $
∀ x : α, named_binder "y" $ ∀ y : α, named_binder "H" $ f x = f y → x = y)] :
testable (injective f) := I
instance monotone.testable [preorder α] [preorder β] (f : α → β)
[I : testable (named_binder "x" $
∀ x : α, named_binder "y" $ ∀ y : α, named_binder "H" $ x ≤ y → f x ≤ f y)] :
testable (monotone f) := I
end slim_check
|
8ce8c9c73e2bbf96e48459da5a07cc7202318bc0 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0106.lean | a8096383bdf3e6f767623a821483018dcae75a35 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 118 | lean | theorem test (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p :=
begin
apply and.intro hp; exact and.intro hq hp,
end
|
132befc4774c60725c2afdc38f2a1a791c4062d7 | 43390109ab88557e6090f3245c47479c123ee500 | /src/Topology/Material/Path_Homotopy_09_08.lean | e8f9153cac6598ec1cb4ec50f4f546813ec9761a | [
"Apache-2.0"
] | permissive | Ja1941/xena-UROP-2018 | 41f0956519f94d56b8bf6834a8d39473f4923200 | b111fb87f343cf79eca3b886f99ee15c1dd9884b | refs/heads/master | 1,662,355,955,139 | 1,590,577,325,000 | 1,590,577,325,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 40,872 | lean | import analysis.topology.continuity
import analysis.topology.topological_space
import analysis.topology.infinite_sum
import analysis.topology.topological_structures
import analysis.topology.uniform_space
import analysis.real
import data.real.basic tactic.norm_num
import data.set.basic
import Topology.Material.subsets
universe u
open set filter lattice classical
noncomputable theory
namespace path
variables {α : Type*} [topological_space α ] ( x y : α )
---- PATH and I01 DEFINITION
/- The following definition of path was created by Mario Carneiro -/
def I01 := {x : ℝ | 0 ≤ x ∧ x ≤ 1}
instance : topological_space I01 := by unfold I01; apply_instance
instance : has_zero I01 := ⟨⟨0, le_refl _, zero_le_one⟩⟩
instance : has_one I01 := ⟨⟨1, zero_le_one, le_refl _⟩⟩
structure path {α} [topological_space α] (x y : α) :=
(to_fun : I01 → α)
(at_zero : to_fun 0 = x)
(at_one : to_fun 1 = y)
(cont : continuous to_fun)
instance {α} [topological_space α] (x y : α) :
has_coe_to_fun (path x y) := ⟨_, path.to_fun⟩
----------
--attribute [class] path
variables ( z w x0 : α )
variables ( g1 : path x y ) ( g2 : path z w)
variable l : I01 → α
-- PATH INTERFACE
@[simp]
lemma start_pt_path {α} [topological_space α ] { x y : α } ( f : path x y) : f.to_fun 0 = x := f.2
@[simp]
lemma end_pt_path {α} [topological_space α ] { x y : α } ( f : path x y) : f.to_fun 1 = y := f.3
-- for later paths homotopy -- checking ending points -- Can Remove
def equal_of_pts (f g : I01 → α ) : Prop := f 0 = g 0 ∧ f 1 = g 1
def equal_of_pts_path : Prop := equal_of_pts g1 g2
def check_pts ( x y : α ) ( g : I01 → α ) := g 0 = x ∧ g 1 = y
def check_pts_of_path ( x y : α ) ( h : path z w ) := check_pts x y h.to_fun
def equal_of_path : Prop := g1.to_fun = g2.to_fun -- == ?
------
theorem path_equal {α} [topological_space α ] { x y : α } {f g: path x y} : f = g ↔ f.to_fun = g.to_fun :=
begin split, intro H, rw H, intro H2, cases f, cases g, cc, end
-- for later paths homotopy (do not Remove)
def is_path ( x y : α ) ( f : I01 → α ) : Prop := f 0 = x ∧ f 1 = y ∧ continuous f
def to_path { x y : α} ( f : I01 → α ) ( H : is_path x y f) : path x y :=
{ to_fun := f,
at_zero := H.left,
at_one := H.right.left,
cont := H.right.right
}
--- Can Remove
lemma cont_of_path ( g : path z w ) : continuous g.to_fun := g.cont
--- Can Remove
def fun_of_path {α} [topological_space α ] { x1 x2 : α } ( g : path x1 x2 ) : I01 → α := g.to_fun
--------------------
--- COMPOSITION OF PATHS
variable A : set ℝ
variables a b : I01
variable Hab : a.val < b.val
----- Can Remove (unneded with T _ _ _ layering )
definition S (a b : ℝ) : set ℝ := {x : ℝ | a ≤ x ∧ x ≤ b}
lemma lemma1 {a : I01} {b : I01} (Hab : a.val < b.val) : a.val ∈ (S a.val b.val) :=
begin
show a.val ≤ a.val ∧ a.val ≤ b.val,
split,
exact le_of_eq rfl,
exact le_of_lt Hab,
end
lemma lemma2 {a : I01} {b : I01} (Hab : a.val < b.val) : b.val ∈ (S a.val b.val) :=
begin
show a.val ≤ b.val ∧ b.val ≤ b.val,
split,
exact le_of_lt Hab,
exact le_of_eq rfl,
end
lemma I01_bound (a : I01) (b : I01) (x : S a.val b.val) :
0 ≤ x.val ∧ x.val ≤ 1 :=
begin
have H := x.property,
split,
exact le_trans (a.property.1 : 0 ≤ a.val) (x.property.1 : a.val ≤ x.val),
exact le_trans (x.property.2 : x.val ≤ b.val) (b.property.2)
end
lemma lemma_sub_ba (a b : I01) {Hab : a.val < b.val } : b.val - a.val ∈ S 0 (b.val - a.val) :=
begin split, exact sub_nonneg.2 (le_of_lt Hab), trivial end
--------------------------------------------
-------------------------------------
-- Useful ℝ result
--- Continuity of linear functions
theorem real.continuous_add_const (r : ℝ) : continuous (λ x : ℝ, x + r) :=
begin
have H₁ : continuous (λ x, (x,r) : ℝ → ℝ × ℝ),
exact continuous.prod_mk continuous_id continuous_const,
exact continuous.comp H₁ continuous_add',
end
theorem real.continuous_div_const (r : ℝ) : continuous (λ x : ℝ, x / r) :=
begin
conv in (_ / r) begin
rw div_eq_mul_inv,
end,
have H₁ : continuous (λ x, (x,r⁻¹) : ℝ → ℝ × ℝ),
exact continuous.prod_mk continuous_id continuous_const,
exact continuous.comp H₁ continuous_mul',
end
theorem real.continuous_scale (a b : ℝ) : continuous (λ x : ℝ, (x + a) / b) :=
continuous.comp (real.continuous_add_const a) (real.continuous_div_const b)
theorem real.continuous_mul_const (r : ℝ) : continuous (λ x : ℝ, r*x) :=
begin
have H₁ : continuous (λ x, (r,x) : ℝ → ℝ × ℝ),
exact continuous.prod_mk continuous_const continuous_id,
show continuous ( (λ p : ℝ × ℝ , p.1 * p.2) ∘ (λ (x : ℝ), (r,x))),
refine continuous.comp H₁ continuous_mul' ,
end
theorem real.continuous_mul_const_right (r : ℝ) : continuous (λ x : ℝ, x*r) :=
begin
have H₁ : continuous (λ x, (x,r) : ℝ → ℝ × ℝ),
exact continuous.prod_mk continuous_id continuous_const,
refine continuous.comp H₁ continuous_mul' ,
end
theorem real.continuous_linear (m q : ℝ) : continuous (λ x : ℝ, m*x + q) :=
begin
exact continuous.comp (real.continuous_mul_const m) (real.continuous_add_const q),
end
--- Definition of closed intervals in ℝ
def int_clos { r s : ℝ } ( Hrs : r < s ) : set ℝ := {x : ℝ | r ≤ x ∧ x ≤ s}
theorem is_closed_int_clos { r s : ℝ } ( Hrs : r < s ) : is_closed (int_clos Hrs) :=
begin
let L := {x : ℝ | x ≤ s} ,
let R := {x : ℝ | r ≤ x} ,
have C1 : is_closed L, exact is_closed_le' s,
have C2 : is_closed R, exact is_closed_ge' r,
have Int : int_clos Hrs = R ∩ L,
unfold has_inter.inter set.inter , unfold int_clos, simp,
rw Int, exact is_closed_inter C2 C1,
end
lemma is_closed_I01 : is_closed I01 :=
begin exact @is_closed_int_clos 0 1 (by norm_num) end
---------------------
-------------------------------------------------------
-- Define closed subintervals of I01 = [0, 1]
definition T ( a b : ℝ ) ( Hab : a < b ) : set I01 := { x : I01 | a ≤ x.val ∧ x.val ≤ b }
-- Prove any T r s Hrs is closed in I01
lemma T_is_closed { r s : ℝ } ( Hrs : r < s ) : is_closed (T r s Hrs) :=
begin
let R := {x : ↥I01 | r ≤ x.val }, let L := {x : ↥I01 | x.val ≤ s } ,
have C1 : is_closed L,
rw is_closed_induced_iff,
existsi {x : ℝ | 0 ≤ x ∧ x ≤ (min 1 s)},
split,
exact is_closed_inter (is_closed_ge' 0) (is_closed_le' _),
apply set.ext,intro x,
show x.val ≤ s ↔ 0 ≤ x.val ∧ x.val ≤ min 1 s,
split,
intro H,
split,
exact x.property.1,
apply le_min,exact x.property.2,assumption,
intro H,
exact le_trans H.2 (min_le_right _ _),
have C2 : is_closed R,
rw is_closed_induced_iff,
existsi {x : ℝ | (max 0 r) ≤ x ∧ x ≤ 1},
split,
exact is_closed_inter (is_closed_ge' _) (is_closed_le' 1),
apply set.ext, intro x,
show r ≤ x.val ↔ max 0 r ≤ x.val ∧ x.val ≤ 1,
split,
intro H,
split,
exact max_le x.2.1 H,
exact x.2.2,
intro H, exact (max_le_iff.1 H.1).2,
have Int : T r s Hrs = set.inter R L, unfold T set.inter, simp,
exact (is_closed_inter C2 C1),
end
-- Reparametrisation from T _ _ _ to I01
definition par {r s : ℝ} (Hrs : r < s) : T r s Hrs → I01 :=
λ x, ⟨ (x.val - r)/(s - r) , begin
have D1 : 0 < (s - r) ,
apply sub_pos.2 Hrs,
have D2 : 0 < (s - r)⁻¹,
exact inv_pos D1,
have N1 : 0 ≤ ((x.val : ℝ ) - r),
exact sub_nonneg.2 (x.property.1),
have N2 : (x.val : ℝ )- r ≤ s - r,
have this : -r ≤ -r, trivial,
show (x.val : ℝ ) + - r ≤ s + - r,
exact add_le_add (x.property.2) this,
split,
show 0 ≤ ((x.val : ℝ ) - r) * (s - r)⁻¹,
exact mul_nonneg N1 (le_of_lt D2),
have H1 : 0 < (s - r),
exact sub_pos.2 Hrs,
have H2 : ((x.val : ℝ ) - r) / (s - r) ≤ (s - r) / (s - r),
exact @div_le_div_of_le_of_pos _ _ ((x.val : ℝ ) - r) (s - r) (s - r) N2 H1,
rwa [@div_self _ _ (s - r) (ne.symm ( @ne_of_lt _ _ 0 (s - r) H1) ) ] at H2
end ⟩
-- Continuity of reparametrisation (later employed in compositions of path/homotopy)
lemma continuous_par {r s : ℝ} (Hrs : r < s) : continuous ( par Hrs ) :=
begin unfold par,
apply continuous_subtype_mk,
show continuous (λ (x : ↥(T r s Hrs)), ((x.1:ℝ ) - r) / (s - r)),
show continuous ((λ ( y: ℝ ), (y - r) / (s - r)) ∘ (λ (x : ↥(T r s Hrs)), x.val.val)),
have H : continuous (λ (x : ↥(T r s Hrs)), x.val.val),
exact continuous.comp continuous_subtype_val continuous_subtype_val ,
exact continuous.comp H (real.continuous_scale (-r) (s-r)),
end
-----------------
-- Define T1 = [0, 1/2] and T2 = [1/2, 1]
def T1 : set I01 := T 0 (1/2: ℝ ) ( by norm_num )
def T2 : set I01 := T (1/2: ℝ ) 1 ( by norm_num )
lemma T1_is_closed : is_closed T1 :=
begin unfold T1, exact T_is_closed _, end
lemma T2_is_closed : is_closed T2 :=
begin unfold T2, exact T_is_closed _, end
lemma help_T1 : (0 : I01) ∈ T 0 (1/2) T1._proof_1 :=
begin unfold T, rw mem_set_of_eq, show 0 ≤ (0:ℝ) ∧ ( 0:ℝ ) ≤ 1 / 2, norm_num, end
lemma help_T2 : (1 : I01) ∈ T (1 / 2) 1 T2._proof_1 :=
begin unfold T, rw mem_set_of_eq, split, show 1/2 ≤ (1:ℝ) , norm_num, show (1:ℝ )≤ 1, norm_num, end
lemma help_01 : (1 / 2 :ℝ) ∈ I01 := begin unfold I01, rw mem_set_of_eq, norm_num end
lemma help_02 : (1:I01) ∉ T1 := begin unfold T1 T,rw mem_set_of_eq, show ¬(0 ≤ (1:ℝ ) ∧ (1:ℝ) ≤ 1 / 2) , norm_num, end
lemma help_half_T1 : ( ⟨ 1/2, help_01⟩ : I01) ∈ T 0 (1/2) T1._proof_1 :=
begin unfold T, exact set.mem_sep
(begin simp [has_mem.mem, -one_div_eq_inv], unfold set.mem, norm_num, end )
(begin norm_num end ),
end
lemma help_half_T2 : ( ⟨ 1/2, help_01⟩ : I01) ∈ T (1/2) 1 T2._proof_1 :=
begin unfold T, exact set.mem_sep
(begin simp [has_mem.mem, -one_div_eq_inv], unfold set.mem, norm_num, end )
(begin norm_num end ),
end
--- Intersection and covering of T1, T2
lemma inter_T : set.inter T1 T2 = { x : I01 | x.val = 1/2 }
:=
begin unfold T1 T2 T set.inter, simp [mem_set_of_eq, -one_div_eq_inv], apply set.ext, intro x, split,
rw mem_set_of_eq , rw mem_set_of_eq, simp [-one_div_eq_inv], intros A B C D, have H : x.val < 1 / 2 ∨ x.val = 1/2,
exact lt_or_eq_of_le B, exact le_antisymm B C,
rw mem_set_of_eq , rw mem_set_of_eq, intro H, rw H, norm_num,
end
lemma cover_I01 : T1 ∪ T2 = set.univ :=
begin
unfold univ, unfold has_union.union , unfold T1 T2 T, apply set.ext, intro x,unfold set.union, simp [mem_set_of_eq , -one_div_eq_inv],
split, intro H, simp [has_mem.mem],
intro B, simp [has_mem.mem] at B, unfold set.mem at B, --unfold I01 at x,
have H : 0≤ x.val ∧ x.val ≤ 1, exact x.property, simp [or_iff_not_imp_left, -one_div_eq_inv],
intro nL, have H2 : (1 / 2 :ℝ )< x.val, exact nL H.1, exact ⟨ le_of_lt H2, H.2 ⟩ ,
end
---- Lemmas to simplify evaluations of par
@[simp]
lemma eqn_start : par T1._proof_1 ⟨0, help_T1⟩ = 0 :=
begin unfold par, simp [-one_div_eq_inv], exact subtype.mk_eq_mk.2 (begin exact zero_div _, end ), end
@[simp]
lemma eqn_1 : par T1._proof_1 ⟨⟨1 / 2, begin unfold I01, rw mem_set_of_eq, norm_num end⟩, begin unfold T, rw mem_set_of_eq, show 0 ≤ (1/2 : ℝ ) ∧ (1/2 : ℝ ) ≤ 1 / 2 , norm_num end ⟩
= 1 := begin unfold par, simp [-one_div_eq_inv], exact subtype.mk_eq_mk.2 (begin exact div_self (begin norm_num, end), end) end
@[simp]
lemma eqn_2 : par T2._proof_1 ⟨⟨1 / 2, help_01 ⟩, begin unfold T, rw mem_set_of_eq, show 1/2 ≤ (1/2 : ℝ ) ∧ (1/2 : ℝ ) ≤ 1 , norm_num end⟩
= 0 := begin unfold par, simp [-one_div_eq_inv], exact subtype.mk_eq_mk.2 (by refl) end
@[simp]
lemma eqn_end : par T2._proof_1 ⟨1, help_T2 ⟩ = 1 :=
begin unfold par, exact subtype.mk_eq_mk.2 ( begin show ( ( 1:ℝ ) - 1 / 2) / (1 - 1 / 2) = 1, norm_num, end ), end
-------------------------------------
-- Definition and continuity of general / T1 / T2 reparametrisation of path function (path.to_fun)
---------- to be used with cont_of_paste for path/homotopy composition
def fgen_path {α } [topological_space α ] { x y : α }{r s : ℝ} (Hrs : r < s)(f : path x y ) : T r s Hrs → α :=
λ t, f.to_fun ( par Hrs t)
lemma pp_cont { x y : α }{r s : ℝ} (Hrs : r < s)(f : path x y ) : continuous (fgen_path Hrs f) := begin
unfold fgen_path,
exact continuous.comp (continuous_par Hrs) f.cont,
end
definition fa_path { x y : α } (f : path x y ) : T1 → α := λ t, f.to_fun (par T1._proof_1 t)
lemma CA { x y : α } (f : path x y ) : continuous ( fa_path f):=
begin
unfold fa_path, exact continuous.comp (continuous_par T1._proof_1 ) f.cont,
end
definition fb_path { x y : α }(f : path x y ) : T2 → α := λ t, f.to_fun (par T2._proof_1 t)
lemma CB { x y : α } (f : path x y ) : continuous ( fb_path f):=
begin
unfold fb_path, exact continuous.comp (continuous_par T2._proof_1 ) f.cont,
end
----- Composition of Path function
definition comp_of_path {α} [topological_space α] { x y z : α } ( f : path x y )( g : path y z ) : path x z :=
{ to_fun := λ t, ( paste cover_I01 ( fa_path f ) ( fb_path g ) ) t ,
at_zero :=
begin unfold paste, rw dif_pos,
unfold fa_path,
rw eqn_start, exact f.at_zero,
end,
at_one :=
begin unfold paste, rw dif_neg,
unfold fb_path, show @path.to_fun α _inst_2 y z g (par T2._proof_1 (@subtype.mk ↥I01 (λ (x : ↥I01), x ∈ T2) 1 help_T2)) = z,
simp [eqn_end], --- exact g.at_one,
exact help_02,
end,
cont :=
begin
-- both images are f.to_fun 1 = g.to_fun 0 = y
have HM : match_of_fun (fa_path f) (fb_path g),
unfold match_of_fun, intros x B1 B2,
have Int : x ∈ set.inter T1 T2, exact ⟨ B1 , B2 ⟩ ,
rwa [inter_T] at Int,
have V : x.val = 1/2, rwa [mem_set_of_eq] at Int,
have xeq : x = (⟨ 1/2 , help_01 ⟩ : I01 ) , apply subtype.eq, rw V,
unfold fa_path fb_path, simp [xeq, -one_div_eq_inv],
show f.to_fun (par T1._proof_1 ⟨⟨1 / 2, help_01⟩, help_half_T1⟩) = g.to_fun (par T2._proof_1 ⟨⟨1 / 2, help_01⟩, help_half_T2⟩),
simp [eqn_1, eqn_2, -one_div_eq_inv], --rw [f.at_one, g.at_zero],
-- Use pasting lemma via closed T1, T2
exact cont_of_paste T1_is_closed T2_is_closed HM (CA f) (CB g),
end
}
----------------------------------------------------
--- INVERSE OF PATH
--- Similarly to Composition of Path: define par_inv, prove continuity and create some [simp] lemmas
lemma inv_in_I01 (x : I01) : 1 - x.val ∈ I01 :=
begin unfold I01, rw mem_set_of_eq, split, simp [-sub_eq_add_neg] , exact x.2.2, simp, exact x.2.1, end
definition par_inv : I01 → I01 := λ x, ⟨ 1 - x.val , inv_in_I01 x ⟩
@[simp] lemma eqn_1_par_inv : par_inv 0 = 1 := by refl
@[simp] lemma eqn_2_par_inv : par_inv 1 = 0 := by refl
lemma help_inv (y : ℝ ) : ( 1 - y) = (-1) * y + 1 := by simp
theorem continuous_par_inv : continuous (par_inv ) :=
begin unfold par_inv, apply continuous_subtype_mk,
show continuous ((λ ( y: ℝ ), 1 - y ) ∘ (λ (x : ↥I01), x.val)),
refine continuous.comp continuous_subtype_val _, --
conv in ( (1:ℝ)-_)
begin
rw help_inv,
end ,
exact continuous.comp (real.continuous_mul_const (-1) ) (real.continuous_add_const 1),
end
definition inv_of_path {α} [topological_space α] { x y : α } ( f : path x y ) : path y x :=
{ to_fun := λ t , f.to_fun ( par_inv t ) , -- or better f.to_fun ∘ par_inv
at_zero := begin rw eqn_1_par_inv, exact f.at_one end ,
at_one := begin rw eqn_2_par_inv, exact f.at_zero end,
cont := by exact continuous.comp continuous_par_inv f.cont
}
-- LOOP
-- Definition of loop
--- (Extends path?)
------------
/-
structure loop {α} [topological_space α] (x : α) { y : α } extends path x y :=
(base_pt : to_fun 0 = x ∧ to_fun 1 = x) -/
/- structure loop {α} [topological_space α] (x : α) :=
(to_fun : I01 → α)
(base_pt : to_fun 0 = x ∧ to_fun 1 = x)
(cont : continuous to_fun)
-/
def is_loop ( g : path x y) : Prop := x = y -- function to check loop
/-
structure loop3 {α} [topological_space α] (x : α) extends path x x :=
(base_pt : to_fun 0 = x ∧ to_fun 1 = x) -/
--(base_pt : is_loop )
--@[simp]
def loop {α} [topological_space α] (x0 : α) : Type* := path x0 x0
def loop_const {α} [topological_space α] (x0 : α) : loop x0 :=
{ to_fun:= λ t, x0 ,
at_zero := by refl ,
at_one := by refl,
cont := continuous_const
}
-- lemma
-- instance loop_is_path (l1 : loop3 x0) : path x0 x0 := l1.to_path
end path
----------------------------
----------------------------
namespace homotopy
open path
variables {α : Type*} [topological_space α ]
variables {β : Type*} [topological_space β ] ( x y : β )
variables ( z w x0 : β )
variable s : I01
def P := topological_space (I01 × α )
-- HOMOTOPY
-- General Homotopy
structure homotopy {α} {β} [topological_space α] [topological_space β] (f : α → β)
( hcf : continuous f) (g : α → β) ( hcg : continuous g) :=
(to_fun : I01 × α → β ) -- for product topology
(at_zero : ( λ x, to_fun ( 0 , x) ) = f )
(at_one : ( λ x, to_fun ( 1 , x) ) = g)
(cont : continuous to_fun ) -- w.r.t product topology
structure path_homotopy {β} [topological_space β] { x y : β } ( f : path x y) ( g : path x y) :=
(to_fun : I01 × I01 → β )
(path_s : ∀ s : I01, is_path x y ( λ t, to_fun (s, t) ) )
(at_zero : ∀ y, to_fun (0,y) = f.to_fun y )
(at_one : ∀ y, to_fun (1,y) = g.to_fun y)
(cont : continuous to_fun)
@[simp]
lemma at_zero_path_hom {β} [topological_space β] { x y : β } { f : path x y} { g : path x y} {F : path_homotopy f g} (y : I01) :
F.to_fun (0, y) = path.to_fun f y := F.3 y
@[simp]
lemma at_one_path_hom {β} [topological_space β] { x y : β } { f : path x y} { g : path x y} {F : path_homotopy f g} (y : I01) :
F.to_fun (1, y) = path.to_fun g y := F.4 y
@[simp]
lemma at_pt_zero_hom {β} [topological_space β] { x y : β } { f : path x y} { g : path x y} {F : path_homotopy f g} (s : I01) :
F.to_fun (s, 0) = x := begin exact (F.2 s).1 end
@[simp]
lemma at_pt_one_hom {β} [topological_space β] { x y : β } { f : path x y} { g : path x y} {F : path_homotopy f g} (s : I01) :
F.to_fun (s, 1) = y := begin exact (F.2 s).2.1 end
/- Alternative definitions
structure path_homotopy2 {β} [topological_space β] { x y : β } ( f : path x y) ( g : path x y) :=
(to_fun : I01 × I01 → β )
(path_s : ∀ s : I01, to_fun (s ,0) = x ∧ to_fun (s, 1) = y )
(at_zero : ∀ y, to_fun 0 y = f.to_fun y )
(at_one : ∀ y, to_fun 1 y = g.to_fun y)
(cont : continuous to_fun)
structure path_homotopy3 {β} [topological_space β] { x y : β } ( f : path x y) ( g : path x y) :=
(to_fun : I01 → I01 → β )
(path_s : ∀ s : I01, is_path x y ( λ t, to_fun s t ) ) -- ∀ s, points match and continuous (λ t, to_fun s t )
(at_zero : to_fun 0 = f.to_fun )
(at_one : to_fun 1 = g.to_fun )
(cont : continuous to_fun) -/
variables (f : path x y) (g : path x y)
variable F : path_homotopy f g
def hom_to_path { x y : β } { f g : path x y }
( F : path_homotopy f g ) (s : I01) : path x y :=
to_path ( λ t, F.to_fun (s, t)) (F.path_s s)
-- Ending points of path_homotopy are fixed (Can Remove - not Used)
lemma hom_eq_of_pts { x y : β } { f g : path x y } ( F : path_homotopy f g ) :
∀ s : I01, check_pts x y ( λ t, F.to_fun (s, t)) :=
begin
intro s, unfold check_pts, split,
have H1: F.to_fun (s, 0) = ( λ t, F.to_fun (s, t)) 0,
simp,
rw H1, exact (F.path_s s).left,
have H1: F.to_fun (s, 1) = ( λ t, F.to_fun (s, t)) 1,
simp,
rw H1, exact (F.path_s s).right.left
end
--- (Can Remove - not Used)
lemma hom_path_is_cont { x y : β } { f g : path x y } ( F : path_homotopy f g ) :
∀ s : I01, continuous ( λ t, F.to_fun (s, t)) :=
begin
intro s, exact (F.path_s s).right.right
end
--------------------------------------------
-- IDENTITY / INVERSE / COMPOSITION of HOMOTOPY
--- Identity homotopy
def path_homotopy_id { x y : β} (f : path x y) : path_homotopy f f :=
{ to_fun := λ st , f.to_fun (prod.snd st) ,
path_s := begin intro s, unfold is_path,
exact ⟨ f.at_zero, f.at_one, f.cont ⟩ end,
at_zero := by simp ,
at_one := by simp ,
cont := begin
let h := λ st, f.to_fun ( @prod.snd I01 I01 st ) ,
have hc : continuous h,
exact continuous.comp continuous_snd f.cont,
exact hc,
end
}
--- Inverse homotopy
lemma help_hom_inv : (λ (st : ↥I01 × ↥I01), F.to_fun (par_inv (st.fst), st.snd)) = ((λ (st : ↥I01 × ↥I01), F.to_fun (st.fst , st.snd)) ∘ (λ (x : I01 × I01) , (( par_inv x.1 , x.2 ) : I01 × I01))) :=
begin trivial, end
def path_homotopy_inverse { x y : β} (f : path x y) (g : path x y) ( F : path_homotopy f g) : path_homotopy g f :=
{ to_fun := λ st , F.to_fun ( par_inv st.1 , st.2 ),
path_s := begin
intro s, unfold is_path, split,
exact (F.path_s (par_inv s)).1, split,
exact (F.path_s (par_inv s)).2.1,
exact (F.path_s (par_inv s)).2.2
end,
at_zero := begin intro t, simp, end, --exact F.at_one t
at_one := begin intro t, simp, end, --exact F.at_zero t
cont := begin
show continuous ((λ (st : ↥I01 × ↥I01), F.to_fun (st.fst , st.snd)) ∘ (λ (x : I01 × I01) , (( par_inv x.1 , x.2 ) : I01 × I01))),
have H : continuous (λ (x : I01 × I01) , (( par_inv x.1 , x.2 ) : I01 × I01)),
exact continuous.prod_mk ( @continuous.comp (I01×I01) I01 I01 _ _ _ (λ x : I01×I01, x.1) _ continuous_fst continuous_par_inv) ( @continuous.comp (I01×I01) I01 I01 _ _ _ (λ x : I01×I01, x.2) _ continuous_snd continuous_id),
simp [continuous.comp H F.cont],
end
}
---- Composition of homotopy
local notation `I` := @set.univ I01
lemma cover_prod_I01 : ( (set.prod T1 (@set.univ I01)) ∪ (set.prod T2 (@set.univ I01)) ) = @set.univ (I01 × I01) :=
begin apply set.ext, intro x, split,
simp [mem_set_of_eq],
intro H, simp, have H : 0≤ x.1.val ∧ x.1.val ≤ 1, exact x.1.property, unfold T1 T2 T, simp [mem_set_of_eq, or_iff_not_imp_left, -one_div_eq_inv],
intro nL, have H2 : (1 / 2 :ℝ )< x.1.val, exact nL H.1, exact ⟨ le_of_lt H2, H.2 ⟩ ,
end
def fgen_hom {α } [topological_space α ] { x y : α }{r s : ℝ}{f g: path x y } (Hrs : r < s)
( F : path_homotopy f g) : (set.prod (T r s Hrs ) I) → α :=
λ st, F.to_fun (( par Hrs ⟨st.1.1, (mem_prod.1 st.2).1 ⟩) , st.1.2 )
theorem p_hom_cont {α } [topological_space α ]{ x y : α }{r s : ℝ} {f g : path x y } (Hrs : r < s) ( F : path_homotopy f g) : continuous (fgen_hom Hrs F) :=
begin unfold fgen_hom,
refine continuous.comp _ F.cont ,
refine continuous.prod_mk _ (continuous.comp continuous_subtype_val continuous_snd),
refine continuous.comp _ (continuous_par Hrs),
refine continuous_subtype_mk _ _,
exact continuous.comp continuous_subtype_val continuous_fst,
end
def fa_hom { x y : α }{f g: path x y } ( F : path_homotopy f g) : (set.prod T1 I) → α := @fgen_hom _ _ _ _ 0 (1/2 : ℝ ) _ _ T1._proof_1 F
lemma CA_hom { x y : α }{f g: path x y } ( F : path_homotopy f g) : continuous (fa_hom F) := p_hom_cont T1._proof_1 F
def fb_hom { x y : α }{f g: path x y } ( F : path_homotopy f g) : (set.prod T2 I) → α := @fgen_hom _ _ _ _ (1/2 : ℝ ) 1 _ _ T2._proof_1 F
lemma CB_hom { x y : α }{f g: path x y } ( F : path_homotopy f g) : continuous (fb_hom F) := p_hom_cont T2._proof_1 F
lemma help_hom_1 {s t : I01} (H : s ∈ T1) : (s, t) ∈ set.prod T1 I := by simpa
lemma prod_T1_is_closed : is_closed (set.prod T1 I) := begin simp [T1_is_closed, is_closed_prod] end
lemma prod_T2_is_closed : is_closed (set.prod T2 I) := begin simp [T2_is_closed, is_closed_prod] end
lemma prod_inter_T : set.inter (set.prod T1 I) (set.prod T2 I) = set.prod { x : I01 | x.val = 1/2 } I :=
begin unfold T1 T2 T set.inter set.prod, simp [mem_set_of_eq, -one_div_eq_inv], apply set.ext, intro x, split,
{rw mem_set_of_eq , rw mem_set_of_eq, simp [-one_div_eq_inv], intros A B C D, have H : x.1.val < 1 / 2 ∨ x.1.val = 1/2,
exact lt_or_eq_of_le B, exact le_antisymm B C,
}, { rw mem_set_of_eq , rw mem_set_of_eq, intro H, rw H, norm_num }
end
local attribute [instance] classical.prop_decidable
@[simp]
lemma cond_start { x y : β} {f : path x y} {g : path x y} {h : path x y}
( F : path_homotopy f g) ( G : path_homotopy g h) : paste cover_prod_I01 (fa_hom F) (fb_hom G) (s, 0) = x :=
begin unfold paste, split_ifs, unfold fa_hom fgen_hom, simp, unfold fb_hom fgen_hom, simp, end
@[simp]
lemma cond_end { x y : β} {f : path x y} {g : path x y} {h : path x y}
( F : path_homotopy f g) ( G : path_homotopy g h) : paste cover_prod_I01 (fa_hom F) (fb_hom G) (s, 1) = y :=
begin unfold paste, split_ifs, unfold fa_hom fgen_hom, simp, unfold fb_hom fgen_hom, simp, end
lemma part_CA_hom { x y : α }{f g: path x y } ( F : path_homotopy f g) (s : I01) (H : s ∈ T1) : continuous (λ (t: ↥I01), (fa_hom F) ⟨ (s, t), (help_hom_1 H ) ⟩ ) :=
begin unfold fa_hom fgen_hom, simp, exact (F.path_s (par T1._proof_1 ⟨ s, H ⟩ )).2.2,
end
lemma T2_of_not_T1 { s : I01} : (s ∉ T1) → s ∈ T2 :=
begin intro H, have H2 : T1 ∪ T2 = @set.univ I01, exact cover_I01, unfold T1 T2 T at *, simp [-one_div_eq_inv],
rw mem_set_of_eq at H, rw not_and at H, have H3 : 1/2 < s.val, have H4 : ¬s.val ≤ 1 / 2, exact H (s.2.1), exact lt_of_not_ge H4,
exact ⟨ le_of_lt H3, s.2.2⟩ ,
end
--set_option trace.simplify.rewrite true
def path_homotopy_comp { x y : β} {f : path x y} {g : path x y} {h : path x y} ( F : path_homotopy f g) ( G : path_homotopy g h) :
path_homotopy f h :=
{ to_fun := λ st, ( @paste (I01 × I01) β (set.prod T1 I) (set.prod T2 I) cover_prod_I01 ( λ st , (fa_hom F ) st ) ) ( λ st, (fb_hom G ) st ) st ,
path_s := begin intro s, unfold is_path, split,
simp, --exact cond_start s F G,
split, ---exact cond_end s F G,
simp, simp, --refine cont_of_paste cover_prod_I01 prod_T1_is_closed prod_T2_is_closed (part_CA_hom F s _) _,
unfold paste, unfold fa_hom fb_hom fgen_hom, simp, --rw (F.path_s (par T1._proof_1 s)).2.2 ,
by_cases H : ∀ t : I01, (s, t) ∈ set.prod T1 I, simp [H],
refine (F.path_s (par T1._proof_1 ⟨ s, _ ⟩ )).2.2, unfold set.prod at H,
have H2 : (s, s) ∈ {p : ↥I01 × ↥I01 | p.fst ∈ T1 ∧ p.snd ∈ univ}, exact H s, simp [mem_set_of_eq] at H2, exact H2,
simp at H,
have H3: s ∉ T1, simp [not_forall] at H, exact H.2,
simp [H3], refine (G.path_s (par T2._proof_1 ⟨ s, _ ⟩ )).2.2,
exact T2_of_not_T1 H3,
--simp [mem_set_of_eq] at H,
--exact F.cont,
end,
at_zero := begin intro y, simp, unfold paste, rw dif_pos, unfold fa_hom fgen_hom, simp ,
simp [mem_set_of_eq], exact help_T1, end,
at_one := begin intro y, simp, unfold paste, rw dif_neg, unfold fb_hom fgen_hom, simp ,
simp [mem_set_of_eq], exact help_02, end,
cont := begin simp, refine cont_of_paste _ _ _ (CA_hom F) (CB_hom G) ,
exact prod_T1_is_closed,
exact prod_T2_is_closed,
unfold match_of_fun, intros x B1 B2,
have Int : x ∈ set.inter (set.prod T1 I) (set.prod T2 I), exact ⟨ B1 , B2 ⟩ ,
rwa [prod_inter_T] at Int,
have V : x.1.1 = 1/2, rwa [set.prod, mem_set_of_eq] at Int, rwa [mem_set_of_eq] at Int, exact Int.1, cases x,
have xeq : x_fst = ⟨ 1/2 , help_01 ⟩ , apply subtype.eq, rw V,
simp [xeq, -one_div_eq_inv],
show fa_hom F ⟨(⟨1 / 2, help_01⟩, x_snd), _⟩ = fb_hom G ⟨(⟨1 / 2, help_01⟩, x_snd), _⟩ , unfold fa_hom fb_hom fgen_hom,
simp [eqn_1, eqn_2, -one_div_eq_inv],
end
}
------------------------------------------------------
---- EQUIVALENCE OF HOMOTOPY
definition is_homotopic_to { x y : β } (f : path x y) ( g : path x y) : Prop := nonempty ( path_homotopy f g)
theorem is_reflexive {β : Type*} [topological_space β ] { x y : β } : @reflexive (path x y) ( is_homotopic_to ) :=
begin
unfold reflexive, intro f, unfold is_homotopic_to,
have H : path_homotopy f f,
exact path_homotopy_id f ,
exact ⟨ H ⟩
end
theorem is_symmetric {β : Type*} [topological_space β ] { x y : β } : @symmetric (path x y) (is_homotopic_to) :=
begin
unfold symmetric, intros f g H, unfold is_homotopic_to,
cases H with F, exact ⟨path_homotopy_inverse f g F⟩,
end
theorem is_transitive {β : Type*} [topological_space β ] { x y : β } : @transitive (path x y) (is_homotopic_to) :=
begin
unfold transitive, intros f g h Hfg Hgh, unfold is_homotopic_to at *,
cases Hfg with F, cases Hgh with G,
exact ⟨ path_homotopy_comp F G⟩ ,
end
theorem is_equivalence : @equivalence (path x y) (is_homotopic_to) :=
⟨ is_reflexive, is_symmetric, is_transitive⟩
---- Reparametrisation of path and homotopies
-- (Formalise paragraph 2 pg 27 of AT, https://pi.math.cornell.edu/~hatcher/AT/AT.pdf )
structure repar_I01 :=
(to_fun : I01 → I01 )
(at_zero : to_fun 0 = 0 )
(at_one : to_fun 1 = 1 )
(cont : continuous to_fun )
@[simp]
lemma repar_I01_at_zero (f : repar_I01) : f.to_fun 0 = 0 := f.2
@[simp]
lemma repar_I01_at_one ( f : repar_I01) : f.to_fun 1 = 1 := f.3
def repar_path {α : Type*} [topological_space α ] {x y : α } ( f : path x y)( φ : repar_I01 ) : path x y :=
{ to_fun := λ t , f.to_fun ( φ.to_fun t) ,
at_zero := by simp,
at_one := by simp,
cont := continuous.comp φ.cont f.cont
}
def rep_hom (φ : repar_I01) : I01 × I01 → I01 := λ st, ⟨ ((1 : ℝ ) - st.1.1)*(φ.to_fun st.2).1 + st.1.1 * st.2.1,
begin unfold I01, rw mem_set_of_eq, split,
{ suffices H1 : 0 ≤ (1 - (st.fst).val) * (φ.to_fun (st.snd)).val ,
suffices H2 : 0 ≤ (st.fst).val * (st.snd).val, exact add_le_add H1 H2,
refine mul_nonneg _ _, exact st.1.2.1, exact st.2.2.1,
refine mul_nonneg _ _, show 0 ≤ 1 - (st.fst).val , refine sub_nonneg.2 _ , exact st.1.2.2, exact (φ.to_fun (st.snd)).2.1,
}, rw (@mul_comm _ _ (1 - (st.fst).val) (φ.to_fun (st.snd)).val),
simp [@mul_add ℝ _ ((φ.to_fun (st.snd)).val ) (1:ℝ ) (- st.fst.val) ], rw mul_comm ((φ.to_fun (st.snd)).val ) ((st.fst).val),
simpa,
sorry, --rw mul_add
--have H1: (φ.to_fun (st.snd)).val + ((st.fst).val * (st.snd).val + -((φ.to_fun (st.snd)).val * (st.fst).val)) ≤
/- refine calc
(st.fst).val * (st.snd).val + (φ.to_fun (st.snd)).val * (1 + -(st.fst).val) = (st.fst).val * (st.snd).val + (φ.to_fun (st.snd)).val* (1:ℝ ) + (φ.to_fun (st.snd)).val * - (st.fst).val : begin end---rw [@mul_add ℝ _ ((φ.to_fun (st.snd)).val ) (1:ℝ ) (- st.fst.val) _], end
... ≤ 1-/
--( 1-s )φ t + s t =
-- φ t + s (t - φ t) ≤
-- φ t + (t - φ t) =
-- t ≤ 1
end ⟩
@[simp]
lemma rep_hom_at_zero {φ : repar_I01} ( y : I01) : rep_hom φ (0, y) = φ.to_fun y :=
begin unfold rep_hom, simp, apply subtype.eq, simp [mul_comm, mul_zero],
show y.val * 0 + (φ.to_fun y).val * (1 + -0) = (φ.to_fun y).val, simp [mul_zero, mul_add, add_zero]
end
@[simp]
lemma rep_hom_at_one {φ : repar_I01} ( y : I01) : rep_hom φ (1, y) = y :=
begin unfold rep_hom, apply subtype.eq, simp [-sub_eq_add_neg],
show 1 * y.val + (1 - 1) * (φ.to_fun y).val = y.val, simp
end
@[simp]
lemma rep_hom_pt_at_zero {φ : repar_I01} ( s : I01) : rep_hom φ (s, 0) = 0 :=
begin unfold rep_hom, simp, apply subtype.eq, simp, show s.val * 0+ (1 + -s.val) * 0 = 0, simp, end
@[simp]
lemma rep_hom_pt_at_one {φ : repar_I01} ( s : I01) : rep_hom φ (s, 1) = 1 :=
begin unfold rep_hom, simp, apply subtype.eq, simp, show s.val * 1 + (1 + -s.val) * 1 = 1, simp end
lemma cont_rep_hom (φ : repar_I01) : continuous (rep_hom φ ) :=
begin unfold rep_hom, refine continuous_subtype_mk _ _,
refine @continuous_add _ _ _ _ _ _ (λ st: I01×I01 , (1 - (st.fst).val) * (φ.to_fun (st.snd)).val ) _ _ _,
{ refine continuous_mul _ _, refine continuous_add _ _, exact continuous_const,
show continuous (( λ x : ℝ , - x ) ∘ (λ (st : ↥I01 × ↥I01), (st.fst).val) ),
refine continuous.comp (continuous.comp continuous_fst continuous_subtype_val) (continuous_neg continuous_id),
exact continuous.comp (continuous.comp continuous_snd φ.cont) continuous_subtype_val
},
refine continuous_mul _ _ , exact continuous.comp continuous_fst continuous_subtype_val,
exact continuous.comp continuous_snd continuous_subtype_val
end
-- Define homtopy from f φ to f , for any repar φ
def hom_repar_path_to_path {α : Type*} [topological_space α ] {x y : α } ( f : path x y)( φ : repar_I01 ) : path_homotopy (repar_path f φ ) f :=
{ to_fun := λ st, f.to_fun ( (rep_hom φ) st),
path_s := begin intro s, unfold is_path, split, simp, split, simp,
show continuous ( (λ (st : I01×I01), f.to_fun (rep_hom φ st )) ∘ ( λ t : I01, ((s, t) : I01 × I01) ) ),
refine continuous.comp _ (continuous.comp (cont_rep_hom φ ) f.cont ),
exact continuous.prod_mk continuous_const continuous_id
end,
at_zero := by simp,
at_one := by simp,
cont := continuous.comp (cont_rep_hom φ ) f.cont
}
theorem repar_path_is_homeq {α : Type*} [topological_space α ] {x y : α } ( f : path x y)( φ : repar_I01 )
: is_homotopic_to (repar_path f φ ) f :=
begin unfold is_homotopic_to, exact nonempty.intro (hom_repar_path_to_path f φ ), end
------------------------------
end homotopy
---------------------------------------------------
---------------------------------------------------
---- FUNDAMENTAL GROUP
namespace fundamental_group
open homotopy
open path
variables {α : Type*} [topological_space α ] {x : α }
--- Underlying Notions
def setoid_hom {α : Type*} [topological_space α ] (x : α ) : setoid (loop x) := setoid.mk is_homotopic_to (is_equivalence x x)
--@[simp]
def space_π_1 {α : Type*} [topological_space α ] (x : α ) := quotient (setoid_hom x)
---#print prefix quotient
/- def hom_eq_class2 {α : Type*} [topological_space α ] {x : α } ( f : loop x ) : set (path x x) :=
{ g : path x x | is_homotopic_to f g } -/
def eq_class {α : Type*} [topological_space α ] {x : α } ( f : loop x ) : space_π_1 x := @quotient.mk _ (setoid_hom x) f
def out_loop {α : Type*} [topological_space α ] {x : α } ( F : space_π_1 x ) : loop x := @quotient.out (loop x) (setoid_hom x) F
def id_eq_class {α : Type*} [topological_space α ] (x : α ) : space_π_1 x := eq_class (loop_const x)
def inv_eq_class {α : Type*} [topological_space α ] {x : α } (F : space_π_1 x) : space_π_1 x := eq_class (inv_of_path (out_loop F))
-- Multiplication
def und_mul {α : Type*} [topological_space α ] (x : α ) ( f : loop x ) ( g : loop x ) : space_π_1 x :=
eq_class (comp_of_path f g)
def mul2 {α : Type*} [topological_space α ] {x : α } : space_π_1 x → space_π_1 x → space_π_1 x :=
begin
intros F G, let f := out_loop F , let g := out_loop G,
exact eq_class ( comp_of_path f g )
end
def mul {α : Type*} [topological_space α ] {x : α } : space_π_1 x → space_π_1 x → space_π_1 x :=
λ F G, und_mul x (out_loop F) (out_loop G)
/-
#print prefix quotient
#print ≈
#print has_equiv.equiv
#print setoid.r -/
--------
-- Identity Elememt
-- right identity - mul_one
def p1 : repar_I01 :=
{ to_fun := λ t, (paste cover_I01 (λ s, par T1._proof_1 s ) (λ s, 1) ) t ,
at_zero := begin unfold paste, rw dif_pos, swap, exact help_T1, simp end,
at_one := begin unfold paste, rw dif_neg, exact help_02 end,
cont := begin simp, refine cont_of_paste _ _ _ (continuous_par _) continuous_const,
exact T1_is_closed,
exact T2_is_closed,
unfold match_of_fun, intros x B1 B2,
have Int : x ∈ set.inter T1 T2, exact ⟨ B1 , B2 ⟩ ,
rwa [inter_T] at Int,
have V : x.val = 1/2, rwa [mem_set_of_eq] at Int,
have xeq : x = (⟨ 1/2 , help_01 ⟩ : I01 ) , apply subtype.eq, rw V,
simp [xeq, -one_div_eq_inv],
show par T1._proof_1 ⟨⟨1 / 2, help_01⟩, help_half_T1⟩ = 1, exact eqn_1,
end
}
local attribute [instance] classical.prop_decidable
--mul a (id_eq_class x) = a
def hom_f_to_f_const {α : Type*} [topological_space α ] {x y : α } ( f : path x y) : path_homotopy (comp_of_path f (loop_const y)) f:=
begin
have H : comp_of_path f (loop_const y) = repar_path f p1,
{ apply path_equal.2, unfold comp_of_path repar_path, simp, unfold fa_path fb_path fgen_path loop_const p1, simp, unfold par, funext,
unfold paste, split_ifs, simp [-one_div_eq_inv], simp,
},
rw H, exact hom_repar_path_to_path f p1,
end
-- f ⬝ c ≈ f by using homotopy f → f ⬝ c above
lemma path_const_homeq_path {α : Type*} [topological_space α ] {x y : α } ( f : path x y) : is_homotopic_to (comp_of_path f (loop_const y)) f :=
begin unfold is_homotopic_to, refine nonempty.intro (hom_f_to_f_const f), end
/-
#check quotient.exists_rep
#check quotient.induction_on
#check quotient.out_eq
#check setoid -/
-- Now prove [f][c] = [f]
theorem mul_one {α : Type*} [topological_space α ] {x : α } ( F : space_π_1 x) : mul F (id_eq_class x) = F :=
begin unfold mul und_mul eq_class, --have H : F = ⟦ quotient.out _ (setoid_hom x) F ⟧,
--- Code below does not lead to much progress atm
/- refine quotient.induction_on _ (setoid_hom x) _ F ,
have f := @quotient.out (loop x) (setoid_hom x) F ,
have H : F = @quotient.mk _ (setoid_hom x) f ,
refine eq.symm _ , refine quotient.out_eq _ (setoid_hom x) F ,
simp [@quotient.exists_rep (loop x) (setoid_hom x) F],
apply @quotient.out (loop x) (setoid_hom x) ,
unfold mul und_mul eq_class, let f := out_loop F , have H : F = eq_class f, unfold eq_class, -- simp [@quotient.out_eq F, eq.symm],
--have Hf: f = out_loop F, trivial, subst Hf, -/
sorry
end
--set_option trace.simplify.rewrite true
--set_option pp.implicit true
-----
-- Group π₁ (α , x)
def π_1_group {α : Type*} [topological_space α ] (x : α ) : group (space_π_1 x) :=
{ mul := mul,
mul_assoc := begin sorry end,
one := id_eq_class x ,
one_mul := begin sorry end ,
mul_one := begin sorry end ,
inv := inv_eq_class ,
mul_left_inv := begin
intro F, simp,
sorry end
}
--------------------- Next things after identity for π_1 group
-- Inverse
lemma hom_comp_inv_to_const {α : Type*} [topological_space α ] {x : α } (f : loop x) : path_homotopy (comp_of_path (inv_of_path f) f) (loop_const x) :=
{ to_fun := sorry,
path_s := sorry,
at_zero := sorry,
at_one := sorry,
cont := sorry
----- NEED STOP FUNCTION
}
--instance : @topological_semiring I01 (by apply_instance ) :=
lemma comp_inv_eqv_const {α : Type*} [topological_space α ] {x : α } (F : space_π_1 x) : is_homotopic_to (comp_of_path (out_loop (inv_eq_class F)) (out_loop F) ) (loop_const x) :=
begin
unfold is_homotopic_to,
sorry,
end
theorem mul_left_inv {α : Type*} [topological_space α ] {x : α } (F : space_π_1 x) : mul (inv_eq_class F) F = id_eq_class x :=
begin
unfold mul und_mul, unfold id_eq_class, unfold eq_class, simp [quotient.eq], unfold inv_eq_class out_loop, unfold has_equiv.equiv,
--suffices H : is_homotopic_to (comp_of_path (out_loop (inv_eq_class F)) (out_loop F) ) (loop_const x)
sorry,
end
--- out lemma ,
-- (or define multiplication given loops (mul_1) )
-- Ignore below
/- def space_π_1 {α : Type*} [topological_space α ] {x : α } := --: set (hom_eq_class x)
{ h : hom_eq_class ( path x x) } -/
/-
def space_π_1 {α : Type*} [topological_space α ] {x : α } : set (set (path x x)) :=
{ ∀ f : loop3 x, hom_eq_class ( f) } -/
/- { to_fun := sorry,
path_s := sorry,
at_zero := sorry,
at_one := sorry,
cont := sorry-/
--set_option trace.simplify.rewrite true
--set_option pp.implicit true
-- Associativity of homotopy
-- Homotopy as a class ????
end fundamental_group
|
5ecd2734cc3ec839175b90ef3eeee29e697d2242 | 8be24982c807641260370bd09243eac768750811 | /src/algebraic_countable_over_Z.lean | 5a385f1c03054042b3539a421c025ebeee1ae2e3 | [] | no_license | jjaassoonn/transcendental | 8008813253af3aa80b5a5c56551317e7ab4246ab | 99bc6ea6089f04ed90a0f55f0533ebb7f47b22ff | refs/heads/master | 1,607,869,957,944 | 1,599,659,687,000 | 1,599,659,687,000 | 234,444,826 | 9 | 1 | null | 1,598,218,307,000 | 1,579,224,232,000 | HTML | UTF-8 | Lean | false | false | 23,845 | lean | import ring_theory.algebraic
import data.real.cardinality
import small_things
import tactic
noncomputable theory
open_locale classical
notation α`[X]` := polynomial α
/--
- For the purpose of this project, we define a real number $x$ to be algebraic if and only if
there is a non-zero polynomial $p ∈ ℤ[T]$ such that $p(x)=0$.
- `algebraic_set` is the set of all algebraic number in ℝ.
- For any polynomial $p ∈ ℤ[T]$, `roots_real p` is the set of real roots of $p$.
- `poly_int_to_poly_real` is the trivial ring homomorphism $ℤ[T] → ℝ[T]$.
- We are essentially evaluating polynomial in two ways: one is `polynomial.aeval` used in the definition of `is_algebraic`;
the other is to evaluate the polynomial after the embeding `poly_int_to_poly_real`. The reason that we need two method is
because the (mathlib) built-in `polynomial.roots` which gives us a `finset ℝ` for any $p ∈ ℝ[T]$.
`poly_int_to_poly_real_wd` is assertion that the two evaluation methods produce the same results.
`poly_int_to_poly_real_well_defined` proves the assertion.
- Having that the two evaluation methods agree, we can use `polynomial.roots` to show ∀ p ∈ ℤ[T], `roots_real p` is finite.
This is `roots_finite`.
-/
def algebraic_set : set ℝ := {x | is_algebraic ℤ x }
def roots_real (p : ℤ[X]) : set ℝ := {x | @polynomial.aeval ℤ ℝ _ _ _ x p = 0}
def poly_int_to_poly_real (p : ℤ[X]) : polynomial ℝ := polynomial.map ℤembℝ p
def poly_int_to_poly_real_wd (p : ℤ[X]) := ∀ x : real, @polynomial.aeval ℤ ℝ _ _ _ x p = (poly_int_to_poly_real p).eval x
theorem poly_int_to_poly_real_preserve_deg (p : ℤ[X]) : p.degree = (poly_int_to_poly_real p).degree :=
begin
rw [poly_int_to_poly_real],
apply eq.symm, apply polynomial.degree_map_eq_of_injective,
intros x y H, simp only [ring_hom.eq_int_cast, int.cast_inj] at H, exact H,
end
theorem poly_int_to_poly_real_C_wd' (a : int) : polynomial.C (a:ℝ) = poly_int_to_poly_real (polynomial.C a) :=
begin
simp only [poly_int_to_poly_real], rw polynomial.map_C, ext, simp only [ring_hom.eq_int_cast],
end
theorem poly_int_to_poly_real_C_wd : ∀ a : ℤ, poly_int_to_poly_real_wd (polynomial.C a) := λ _ _, by simp only [poly_int_to_poly_real, polynomial.aeval_def, polynomial.eval_map, ℤembℝ]
theorem poly_int_to_poly_real_add (p1 p2 : polynomial ℤ) : poly_int_to_poly_real (p1 + p2) = poly_int_to_poly_real p1 + poly_int_to_poly_real p2 :=
begin
simp only [poly_int_to_poly_real, polynomial.map_add],
end
theorem poly_int_to_poly_real_add_wd (p1 p2 : ℤ[X])
(h1 : poly_int_to_poly_real_wd p1)
(h2 : poly_int_to_poly_real_wd p2) : poly_int_to_poly_real_wd (p1 + p2) :=
begin
simp only [poly_int_to_poly_real_wd, alg_hom.map_add] at h1 h2 ⊢,
intro x,
rw [h1, h2, <-polynomial.eval_add, poly_int_to_poly_real_add]
end
theorem poly_int_to_poly_real_pow1 (n : nat) : poly_int_to_poly_real (polynomial.X ^ n) = polynomial.X ^ n :=
begin
ext m,
simp only [poly_int_to_poly_real, polynomial.map_X, polynomial.map_pow],
end
theorem poly_int_to_poly_real_pow2 (n : nat) (a : ℤ) : poly_int_to_poly_real ((polynomial.C a) * polynomial.X ^ n) = (polynomial.C (real.of_rat a)) * polynomial.X ^ n :=
begin
rw [poly_int_to_poly_real, polynomial.map_mul, polynomial.map_C, polynomial.map_pow, polynomial.map_X], simp only [ring_hom.eq_int_cast, rat.cast_coe_int, real.of_rat_eq_cast],
end
theorem poly_int_to_poly_real_pow_wd (n : nat) (a : ℤ) (h : poly_int_to_poly_real_wd ((polynomial.C a) * polynomial.X ^ n)) : poly_int_to_poly_real_wd ((polynomial.C a) * polynomial.X ^ n.succ) :=
begin
intro x,
rw [polynomial.aeval_def, poly_int_to_poly_real, polynomial.map_mul, polynomial.map_C, polynomial.eval_mul, polynomial.eval_C, polynomial.map_pow, polynomial.eval_pow, polynomial.eval₂_mul, polynomial.eval₂_C, polynomial.eval₂_pow],
simp only [polynomial.eval_X, polynomial.map_X, polynomial.eval₂_X, ℤembℝ],
end
theorem poly_int_to_poly_real_ne_zero (p : ℤ[X]) : p ≠ 0 ↔ (poly_int_to_poly_real p) ≠ 0 :=
begin
suffices : p = 0 ↔ (poly_int_to_poly_real p) = 0, exact not_congr this,
split,
intros h, rw h, ext, simp only [poly_int_to_poly_real, polynomial.map_zero],
simp only [poly_int_to_poly_real], intro hp,
ext, rw polynomial.ext_iff at hp,
replace hp := hp n, simp only [polynomial.coeff_zero, polynomial.coeff_map] at hp ⊢,
rw <-ℤembℝ_zero at hp,
exact ℤembℝ_inj hp,
end
theorem poly_int_to_poly_real_well_defined (x : real) (p : polynomial ℤ) :
poly_int_to_poly_real_wd p :=
begin
apply polynomial.induction_on p,
exact poly_int_to_poly_real_C_wd,
exact poly_int_to_poly_real_add_wd,
exact poly_int_to_poly_real_pow_wd,
end
def roots_real' (p : ℤ[X]) : set ℝ := {x | (poly_int_to_poly_real p).eval x = 0}
theorem roots_real_eq_roots (p : ℤ[X]) (hp : p ≠ 0) : roots_real p = ↑(poly_int_to_poly_real p).roots :=
begin
simp only [roots_real], ext, split,
intros hx, simp only [set.mem_set_of_eq] at hx,
simp only [finset.mem_coe],
rw [polynomial.mem_roots, polynomial.is_root.def, <-(poly_int_to_poly_real_well_defined x)],
exact hx,
rw <-poly_int_to_poly_real_ne_zero, exact hp,
intro hx, simp only [finset.mem_coe] at hx,
rw [polynomial.mem_roots, polynomial.is_root.def, <-(poly_int_to_poly_real_well_defined x)] at hx,
simp only [set.mem_set_of_eq], exact hx,
rw <-poly_int_to_poly_real_ne_zero, exact hp,
end
theorem roots_finite (p : polynomial ℤ) (hp : p ≠ 0) : set.finite (roots_real p) :=
begin
rw (roots_real_eq_roots p hp), exact (poly_int_to_poly_real p).roots.finite_to_set,
end
/-
We allow the zero polynomial to have degree zero.
Otherwise we need to use type `with_bot ℕ` so that the zero polynomial has degree negative infinity
-/
notation `int_n` n := fin n -> ℤ -- the set of ℤⁿ
notation `nat_n` n := fin n -> ℕ -- the set of ℕⁿ
notation `poly_n'` n := {p : ℤ[X] // p ≠ 0 ∧ p.nat_degree < n} -- the set of all nonzero polynomials in $ℤ[T]$ with degree < n
notation `int_n'` n := {f : fin n -> ℤ // f ≠ 0} -- ℤⁿ - {(0,0,...,0)}
notation `int'` := {r : ℤ // r ≠ 0} -- ℤ - {0}
def strange_fun : ℤ -> int' := λ m, if h : m < 0 then ⟨m, by linarith⟩ else ⟨m + 1, by linarith⟩
-- This is the bijection from ℤ to ℤ - {0}
-- Given by
-- | n if n < 0
-- n ↦ -|
-- | n + 1 if n ≥ 0
theorem strange_fun_inj : function.injective strange_fun := -- This is the proof that the strange function is injective
begin
intros x y H, rw strange_fun at H, simp only [subtype.mk_eq_mk] at H, split_ifs at H,
exact H, linarith, linarith,
simp only [subtype.mk_eq_mk, add_left_inj] at H, exact H,
end
theorem strange_fun_sur : function.surjective strange_fun :=
begin
intro x, -- The surjection part:
by_cases (x.val < 0), -- For any x ∈ ℤ - {0}
use x.val, simp only [strange_fun], simp only [h, if_true, subtype.eta, dif_pos], simp only [not_lt] at h, -- if x < 0 then x ↦ x
replace h : 0 = x.val ∨ 0 < x.val, exact eq_or_lt_of_le h, cases h,
replace h := eq.symm h,
exfalso, exact x.property h,
replace h : 1 ≤ x.val, exact h,
replace h : ¬ (1 > x.val), exact not_lt.mpr h,
replace h : ¬ (x.val < 1), exact h,
use x.val-1, -- if x ≥ 0 since x ≠ 0, we have x > 0
simp only [strange_fun, h, sub_lt_zero, sub_add_cancel, subtype.eta, if_false, sub_lt_zero, dif_neg, not_false_iff],
end
theorem int_eqiv_int' : ℤ ≃ int' := -- So ℤ ≃ ℤ - {0} because the strange function is a bijection
begin
apply equiv.of_bijective strange_fun,
split,
exact strange_fun_inj, -- The injection part is proved above
exact strange_fun_sur
end
-- def zero_int_n {n : nat} : int_n n.succ := (fun m, 0) -- ℤ⁰ = {0}
-- def zero_poly_n {n : nat} : poly_n n.succ := ⟨0, nat.succ_pos n⟩ -- no polynomial in $ℤ[T]$ with degree < 0
def identify (n : nat) : (poly_n' n) -> (int_n' n) := λ p,
⟨λ m, p.1.coeff m.1, λ rid, begin
rw function.funext_iff at rid,
simp only [pi.zero_apply, subtype.val_eq_coe] at rid,
have contra : p.1 = 0,
ext m, simp only [polynomial.coeff_zero, subtype.val_eq_coe],
by_cases (m < n),
replace rid := rid ⟨m, h⟩, simp only [] at rid, exact rid,
simp only [not_lt] at h,
rw polynomial.coeff_eq_zero_of_nat_degree_lt,
have deg := p.2.2, simp only [subtype.val_eq_coe] at deg, linarith,
exact p.2.1 contra,
end⟩
lemma m_mod_n_lt_n : ∀ n : nat, n ≠ 0 -> ∀ m : nat, m % n < n :=
λ n hn m, @nat.mod_lt m n (zero_lt_iff_ne_zero.mpr hn)
theorem sur_identify_n (n : nat) (hn : n ≠ 0) : function.surjective (identify n) :=
begin
intro q,
-- we can define a polynomial whose non-zero coefficients are exact at non-zero elements of q; -- given an element q in ℤⁿ
set p : polynomial ℤ := { support := finset.filter (λ m : nat, (q.1 (⟨m % n, m_mod_n_lt_n n hn m⟩ : fin n)) ≠ 0) (finset.range n),
to_fun := (λ m : nat, ite (m ∈ (finset.filter (λ m : nat, (q.1 (⟨m % n, m_mod_n_lt_n n hn m⟩ : fin n)) ≠ 0) (finset.range n))) (q.1 (⟨m % n, m_mod_n_lt_n n hn m⟩ : fin n)) 0),
mem_support_to_fun := begin
intro m, -- every index with a non-zero coefficient is in support
split,
intro hm,
rw finset.mem_filter at hm,
cases hm with hm_left qm_ne0,
simp only [ne.def, finset.mem_filter, finset.mem_range, ne.def, finset.mem_filter, finset.mem_range],
split_ifs,
exact h.2,
simp only [not_and, not_not] at h, simp only [finset.mem_range] at hm_left,
replace h := h hm_left, exfalso, exact qm_ne0 h,
intro hm,
dsimp at hm,
have g : ite (m ∈ (finset.filter (λ m : nat, (q.1 (⟨m % n, m_mod_n_lt_n n hn m⟩ : fin n)) ≠ 0) (finset.range n))) (q.1 ⟨m % n, m_mod_n_lt_n n hn m⟩) 0 ≠ 0 -> (m ∈ (finset.filter (λ m : nat, (q.1 (⟨m % n, m_mod_n_lt_n n hn m⟩ : fin n)) ≠ 0) (finset.range n))),
{
intro h,
by_contra,
split_ifs at h,
have h' : (0 : ℤ) = 0 := rfl,
exact h h',
},
exact g hm,
end} with hp,
have hp_support2 : ∀ m ∈ p.support, m < n,
{
dsimp,
intro m,
rw finset.mem_filter,
intro hm,
cases hm,
exact list.mem_range.mp hm_left,
},
have hp_deg : (p.degree ≠ ⊥) -> p.degree < n,
{
intro hp_deg_not_bot,
rw polynomial.degree,
rw finset.sup_lt_iff,
intros m hm,
have hmn := hp_support2 m hm,
swap,
exact @with_bot.bot_lt_coe nat _ n,
have g := @with_bot.some_eq_coe nat n,
rw <-g,
rw with_bot.some_lt_some,
exact hmn,
},
have hp_nat_deg : p.nat_degree < n, -- So the polynomial has degree < n
{
by_cases (p = 0),
rename h hp_eq_0,
have g := polynomial.nat_degree_zero,
rw <-hp_eq_0 at g,
rw g,
rw zero_lt_iff_ne_zero,
exact hn,
rename h hp_ne_0,
have p_deg_ne_bot : p.degree ≠ ⊥,
{
intro gg,
rw polynomial.degree_eq_bot at gg,
exact hp_ne_0 gg,
},
have hp_deg' := hp_deg p_deg_ne_bot,
have g := polynomial.degree_eq_nat_degree hp_ne_0,
rw g at hp_deg',
rw <-with_bot.coe_lt_coe,
exact hp_deg',
},
have p_nonzero : p ≠ 0,
{
intro rid, rw polynomial.ext_iff at rid,
have hq := q.2,
replace hq : ∃ x, q.1 x ≠ 0, rw <-not_forall, intro rid, replace rid : q.1 = 0, ext m, exact rid m, exact hq rid,
choose x hx using hq,
rw hp at rid, simp only [not_and, ne.def, polynomial.coeff_zero, finset.mem_filter, finset.mem_range, finset.filter_congr_decidable,
polynomial.coeff_mk, not_not] at rid,
replace rid := rid x.1, split_ifs at rid, exact h.2 rid,
simp only [not_and, not_not] at h,
replace h := h _,
have triv : x = ⟨x.val % n, _⟩, rw fin.eq_iff_veq, simp only [],
rw nat.mod_eq_of_lt, exact x.2, rw <-triv at h, exact hx h, exact x.2,
},
use ⟨p, ⟨p_nonzero, hp_nat_deg⟩⟩, -- We claim that this polynomial is identified with q
{
ext m,
simp only [identify, polynomial.coeff_mk, not_and, ne.def, finset.mem_filter, finset.mem_range,
not_not], simp only [not_and, ne.def, finset.mem_filter, finset.mem_range, subtype.coe_mk, polynomial.coeff_mk, not_not,
subtype.val_eq_coe],
split_ifs,
apply congr_arg,
ext, simp only [], rw nat.mod_eq_of_lt, exact h.1,
simp only [not_and, not_not] at h,
replace h := h m.2, rw <-h, apply congr_arg,
ext, simp only [], rw nat.mod_eq_of_lt, exact m.2,
},
end
theorem inj_identify_n (n : nat) (hn : n ≠ 0) : function.injective (identify n) := λ x1 x2 hx,
begin
simp only [subtype.mk_eq_mk, identify, function.funext_iff, subtype.coe_mk, subtype.val_eq_coe] at hx, apply subtype.eq,
ext m,
have h1 := x1.2.2, have h2 := x2.2.2,
by_cases (m ≥ n),
rw [polynomial.coeff_eq_zero_of_nat_degree_lt, polynomial.coeff_eq_zero_of_nat_degree_lt],
exact lt_of_lt_of_le h2 h, exact lt_of_lt_of_le h1 h,
replace h : m < n, exact not_le.mp h,
exact hx ⟨m, h⟩,
end
theorem poly_n'_equiv_int_n' (n : nat) : (poly_n' n.succ) ≃ (int_n' n.succ) := -- We use the fact that identification is bijection to prove
begin -- that non-zero polynomial of degree < n is equipotent to ℤⁿ for n ≥ 1
apply equiv.of_bijective (identify n.succ),
split,
exact inj_identify_n n.succ (nat.succ_ne_zero n),
exact sur_identify_n n.succ (nat.succ_ne_zero n),
end
def F (n : nat) : (int_n n.succ) -> (int_n' n.succ) := λ f,
⟨λ m, (strange_fun (f m)).1, λ rid, begin
rw function.funext_iff at rid,
replace rid := rid 0,
simp only [pi.zero_apply] at rid,
exact (strange_fun (f 0)).2 rid,
end⟩
theorem F_inj (n : nat) : function.injective (F n) := λ f1 f2 Hf,
begin
simp only [F] at Hf, rw function.funext_iff at Hf ⊢,
intro m,
replace Hf := Hf m, rw <-subtype.ext_iff_val at Hf,
exact strange_fun_inj Hf,
end
def G (n : nat) : (int_n' n.succ) -> (int_n n.succ) := λ f m, (f.1 m)
theorem G_inj (n : nat) : function.injective (G n) := λ f1 f2 Hf,
begin
simp only [G] at Hf, rw function.funext_iff at Hf, ext m,
exact Hf m,
end
theorem int_n_equiv_int_n' (n : nat) : (int_n n.succ) ≃ int_n' n.succ :=
begin
choose B HB using function.embedding.schroeder_bernstein (F_inj n) (G_inj n),
apply equiv.of_bijective B HB,
end
def fn (n : nat) : (int_n n.succ.succ) -> (int_n n.succ) × ℤ := λ r, -- This is an injection from ℤ^{n+1} to ℤⁿ × ℤ for n ≥ 1
⟨λ m, r (⟨m.1, nat.lt_trans m.2 (nat.lt_succ_self n.succ)⟩), r (⟨n.succ, nat.lt_succ_self n.succ⟩)⟩
theorem fn_inj (n : ℕ) : function.injective (fn n) := λ x1 x2 hx,
begin
simp only [fn, id.def, prod.mk.inj_iff] at hx, cases hx with h1 h2, rw function.funext_iff at h1, ext,
by_cases (x = ⟨n.succ, nat.lt_succ_self n.succ⟩), rw <-h at h2, assumption,
simp only [fin.eq_iff_veq] at h, have h2 := x.2, replace h2 : x.1 ≤ n.succ := fin.le_last x,
have h3 : x.1 < n.succ := lt_of_le_of_ne h2 h,
have H := h1 ⟨x.1, h3⟩, simp only [fin.eta] at H, exact H,
end
def gn (n : nat) : (int_n n.succ) × ℤ -> (int_n n.succ.succ) := λ r m, -- This is an injection from ℤⁿ × ℤ to ℤ^{n+1} for n ≥ 1
begin
by_cases (m.1 = n.succ),
exact r.2,
exact r.1 (⟨m.1, lt_of_le_of_ne (fin.le_last m) h⟩),
end
theorem gn_inj (n : nat) : function.injective (gn n) := λ x1 x2 hx,
begin
cases x1 with p1 x1, cases x2 with p2 x2,
ext; simp only []; simp only [gn, id.def] at hx; rw function.funext_iff at hx, swap,
generalize hm : (⟨n.succ, nat.lt_succ_self n.succ⟩ : fin n.succ.succ) = m,
have hm' : m.val = n.succ, rw <-hm, replace hx := hx m, simp only [hm', dif_pos] at hx, assumption,
generalize hm : (⟨x.1, nat.lt_trans x.2 (nat.lt_succ_self n.succ)⟩ : fin n.succ.succ) = m,
replace hx := hx m, have hm' : m.1 ≠ n.succ,
intro a, rw <-hm at a, simp only [] at a, have hx' := x.2, linarith,
simp only [hm', dif_neg, not_false_iff] at hx, have hm2 := m.2, replace hm2 : m.1 ≤ n.succ, exact fin.le_last m,
have hm3 : m.1 < n.succ, exact lt_of_le_of_ne hm2 hm',
have H : x = ⟨m.1, hm3⟩, rw fin.ext_iff at hm ⊢, simp only [] at hm ⊢, exact hm,
rw H, exact hx,
end
theorem aux_int_n (n : nat) : -- So again using the two injections and Schröder-Berstein
(int_n n.succ.succ) ≃ (int_n n.succ) × ℤ := -- We know ℤⁿ × ℤ ≃ ℤ^{n+1} for n ≥ 1
begin
choose B HB using function.embedding.schroeder_bernstein (fn_inj n) (gn_inj n),
apply equiv.of_bijective B HB,
end
/--
- For any n ∈ ℕ_{≥1}, `algebraic_set'_n` is the set of all the roots of non-zero polynomials of degree less than n.
- `algebraic_set'` is the set of all the roots of all the non-zero polynomials with integer coefficient.
- Both of the definition is of the flavour of the second evaluation methods.
- The `algebraic_set'_eq_algebraic_set` asserts `algebraic_set' = algebraic_set`. LHS is using the second evaluation method; RHS is using
the first method.
-/
def algebraic_set'_n (n : ℕ) : set ℝ := ⋃ p : (poly_n' n.succ), roots_real p.1
def algebraic_set' : set real := ⋃ n : ℕ, algebraic_set'_n n.succ
theorem algebraic_set'_eq_algebraic_set : algebraic_set' = algebraic_set :=
begin
ext, split; intro hx,
{
rw [algebraic_set', set.mem_Union] at hx,
choose n hx using hx,
rw [algebraic_set'_n, set.mem_Union] at hx,
choose p hp using hx, rw [roots_real, set.mem_set_of_eq] at hp,
rw [algebraic_set, set.mem_set_of_eq, is_algebraic],
use p.val, split, exact p.2.1,assumption
},
{
rw [algebraic_set, set.mem_set_of_eq] at hx,
choose p hp using hx,
cases hp with p_ne_0 p_x_0,
rw [algebraic_set', set.mem_Union],
use p.nat_degree.succ, rw [algebraic_set'_n, set.mem_Union],
use p, split, exact p_ne_0,
{
suffices h1 : p.nat_degree < p.nat_degree.succ,
suffices h2 : p.nat_degree.succ < p.nat_degree.succ.succ,
suffices h3 : p.nat_degree.succ.succ < p.nat_degree.succ.succ.succ,
exact lt.trans (lt.trans h1 h2) h3,
exact lt_add_one p.nat_degree.succ.succ, exact lt_add_one (nat.succ (polynomial.nat_degree p)),
exact lt_add_one (polynomial.nat_degree p),
},
simpa only [],
},
end
-- So we can identify the set of non-zero polynomial of degree < 1 with ℤ - {0}
theorem int_1_equiv_int : (int_n 1) ≃ ℤ := -- ℤ¹ ≃ ℤ
{ to_fun := (λ f, f ⟨0, by linarith⟩),
inv_fun := (λ r m, r),
left_inv := begin
intro x, dsimp, ext m, fin_cases m,
end,
right_inv := λ x, rfl,}
/--
- denumerable means countably infinite
- countable means countably infinite or finite
-/
theorem int_n_denumerable {n : nat} : denumerable (int_n n.succ) := -- for all n ∈ ℕ, n ≥ 1 → ℤⁿ is denumerable
begin
induction n with n hn, -- To prove this, we use induction: ℤ¹ ≃ ℤ is denumerable
apply denumerable.mk', suffices H : (int_n 1) ≃ ℤ, apply equiv.trans H, exact denumerable.eqv ℤ,
exact int_1_equiv_int,
apply denumerable.mk', -- Suppose ℤⁿ is denumerable, then ℤ^{n+1} ≃ ℤⁿ × ℤ ≃ ℕ × ℤ is denumerable
have Hn := @denumerable.eqv (int_n n.succ) hn,
have e1 := aux_int_n n, suffices H : (int_n n.succ) × ℤ ≃ ℕ, exact equiv.trans e1 H,
have e2 : (int_n n.succ) × ℤ ≃ ℕ × ℤ, apply equiv.prod_congr, exact Hn, refl,
suffices H : ℕ × ℤ ≃ nat, exact equiv.trans e2 H, exact denumerable.eqv (ℕ × ℤ),
end
theorem poly_n'_denumerable (n : nat) : denumerable (poly_n' n.succ) := -- So the set of non-zero polynomials of degree < n ≃ ℤⁿ - {0} ≃ ℤⁿ is denumerable
begin
apply denumerable.mk',
suffices e1 : (int_n' n.succ) ≃ ℕ, exact equiv.trans (poly_n'_equiv_int_n' n) e1,
suffices e2 : (int_n n.succ) ≃ ℕ, exact equiv.trans (int_n_equiv_int_n' n).symm e2,
exact @denumerable.eqv (int_n n.succ) int_n_denumerable,
end
theorem algebraic_set'_n_countable (n : nat) : -- The set of roots of non-zero polynomial of degree < n is countable
set.countable (algebraic_set'_n n) := -- being countable union of finite set.
@set.countable_Union (poly_n' n.succ) ℝ (λ p, roots_real p.1) (poly_n'_denumerable n).1
(λ q, set.finite.countable (roots_finite q.1 q.2.1))
theorem algebraic_set'_countable : set.countable algebraic_set' := -- So the set of roots of non-zero polynomial is countable
set.countable_Union (λ n, algebraic_set'_n_countable n.succ) -- being countable union of countable set
theorem algebraic_set_countable : set.countable algebraic_set := -- So the set of algebraic numb
-- (no matter which evaluation method we are using)
begin -- is countable
rw <-algebraic_set'_eq_algebraic_set, exact algebraic_set'_countable
end
def real_set : set ℝ := @set.univ ℝ -- the set ℝ
notation `transcendental` x := ¬(is_algebraic ℤ x)
theorem transcendental_number_exists : ∃ x : ℝ, transcendental x := -- Since ℝ is uncouble, algebraic numbers are countable
begin
have H : algebraic_set ≠ real_set, -- ℝ ≠ algebraic_set
{ -- otherwise ℝ must be countable which is not true
intro h1,
have h2 : set.countable real_set,
{
rw <-h1, exact algebraic_set_countable,
},
have h3 : ¬ set.countable real_set := cardinal.not_countable_real,
exact h3 h2,
},
rw [ne.def, set.ext_iff, not_forall] at H, -- Since algebraic_set ⊊ ℝ, there is some x ∈ ℝ but not algebraic
choose x Hx using H, rw not_iff at Hx, replace Hx := Hx.mpr,
use x, exact Hx trivial,
end
|
eedad57ed398ec66d97d44f74cc295527947121f | c3de33d4701e6113627153fe1103b255e752ed7d | /tools/tactic/simp_tactic.lean | ec3f0b481abbe7cc081db2126a4f74da651145b0 | [] | no_license | jroesch/library_dev | 77d2b246ff47ab05d55cb9706a37d3de97038388 | 4faa0a45c6aa7eee6e661113c2072b8840bff79b | refs/heads/master | 1,611,281,606,352 | 1,495,661,644,000 | 1,495,661,644,000 | 92,340,430 | 0 | 0 | null | 1,495,663,344,000 | 1,495,663,344,000 | null | UTF-8 | Lean | false | false | 11,042 | lean | /-
Copyright (c) 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
Variants of the simplifier tactics.
-/
import init.meta.lean.parser
import .tactic
open expr
namespace tactic
/- In the main library, (simp_at h) replaces the local constant h by
a new local constant with the same name. This variant returns the
new expression, so that a tactic can continue to use it. -/
meta def simp_at' (h : expr) (extra_lemmas : list expr := []) (cfg : simp_config := {}) : tactic expr :=
do when (expr.is_local_constant h = ff) (fail "tactic simp_at failed, the given expression is not a hypothesis"),
htype ← infer_type h,
S ← simp_lemmas.mk_default,
S ← S.append extra_lemmas,
(new_htype, heq) ← simplify S htype cfg,
newh ← assert' (expr.local_pp_name h) new_htype,
mk_eq_mp heq h >>= exact,
try $ clear h,
return newh
meta def simp_at_using_hs' (h : expr) (extra_lemmas : list expr := []) (cfg : simp_config := {}) : tactic expr :=
do hs ← collect_ctx_simps,
simp_at' h (list.filter (≠ h) hs ++ extra_lemmas) cfg
meta def simph_at' (h : expr) (extra_lemmas : list expr := []) (cfg : simp_config := {}) : tactic expr :=
simp_at_using_hs' h extra_lemmas cfg
/- The simp tactics use default simp rules. This version uses only the given list. -/
meta def simp_only (hs : list expr) (cfg : simp_config := {}) : tactic unit :=
do S ← simp_lemmas.mk^.append hs,
simplify_goal S cfg >> try triv
meta def simp_only_at (h : expr) (hs : list expr := []) (cfg : simp_config := {}) :
tactic expr :=
do when (expr.is_local_constant h = ff)
(fail "tactic simp_only_at failed, the given expression is not a hypothesis"),
htype ← infer_type h,
S ← simp_lemmas.mk^.append hs,
(new_htype, heq) ← simplify S htype cfg,
newh ← assert' (expr.local_pp_name h) new_htype,
mk_eq_mp heq h >>= exact,
try $ clear h,
return newh
/- Modifications of tactics in the library -/
-- unchanged
private meta def is_equation : expr → bool
| (expr.pi n bi d b) := is_equation b
| e := match (expr.is_eq e) with (some a) := tt | none := ff end
-- fixes a bug and clears a hypothesis earlier, so we can reuse the name: see below
meta def simp_intro_aux' (cfg : simp_config) (updt : bool) : simp_lemmas → bool → list name → tactic simp_lemmas
| S tt [] := try (simplify_goal S cfg) >> return S
| S use_ns ns := do
t ← target,
if t.is_napp_of `not 1 then
intro1_aux use_ns ns >> simp_intro_aux' S use_ns ns.tail
else if t.is_arrow then
do {
d ← return t.binding_domain,
(new_d, h_d_eq_new_d) ← simplify S d cfg,
h_d ← intro1_aux use_ns ns,
h_new_d ← mk_eq_mp h_d_eq_new_d h_d,
assertv_core h_d.local_pp_name new_d h_new_d,
clear h_d, -- this was two lines later
h_new ← intro1,
new_S ← if updt && is_equation new_d then S.add h_new else return S,
simp_intro_aux' new_S use_ns ns.tail -- bug: this is ns in the library
}
<|>
-- failed to simplify... we just introduce and continue
(intro1_aux use_ns ns >> simp_intro_aux' S use_ns ns.tail)
else if t.is_pi || t.is_let then
intro1_aux use_ns ns >> simp_intro_aux' S use_ns ns.tail
else do
new_t ← whnf t reducible,
if new_t.is_pi then change new_t >> simp_intro_aux' S use_ns ns
else
try (simplify_goal S cfg) >>
mcond (expr.is_pi <$> target)
(simp_intro_aux' S use_ns ns)
(if use_ns ∧ ¬ns.empty then failed else return S)
meta def simp_intro_lst_using' (ns : list name) (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
step $ simp_intro_aux' cfg ff s tt ns
meta def simph_intro_lst_using' (ns : list name) (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
step $
do s ← collect_ctx_simps >>= s.append,
simp_intro_aux' cfg tt s tt ns
/- Tactics that apply to all hypothesis and the goal. These duplicate some code
from simp_tactic. -/
private meta def dunfold_all_aux (cs : list name) : ℕ → tactic unit
| 0 := skip
| (k+1) := do (expr.pi n bi d b : expr) ← target,
new_d ← dunfold_core reducible default_max_steps cs d,
change $ expr.pi n bi new_d b,
intro1,
dunfold_all_aux k
-- unfold constants in all hypotheses and the goal
meta def dunfold_all (cs : list name) : tactic unit :=
do n ← revert_all,
dunfold_all_aux cs n,
dunfold cs
private meta def delta_all_aux (cs : list name) : ℕ → tactic unit
| 0 := skip
| (k+1) := do (expr.pi n bi d b : expr) ← target,
new_d ← delta_core {} cs d,
change $ expr.pi n bi new_d b,
intro1,
delta_all_aux k
-- expand definitions in all hypotheses and the goal
meta def delta_all (cs : list name) : tactic unit :=
do n ← revert_all,
delta_all_aux cs n,
delta cs
meta def dsimp_all_aux (s : simp_lemmas) : ℕ → tactic unit
| 0 := skip
| (k+1) := do expr.pi n bi d b ← target,
h_simp ← s.dsimplify d,
tactic.change $ expr.pi n bi h_simp b,
intron 1,
dsimp_all_aux k
-- apply dsimp at all the hypotheses and the goal
meta def dsimp_all (s : simp_lemmas) : tactic unit :=
do n ← revert_all,
dsimp_all_aux s n,
dsimp_core s
-- simplify all the hypotheses and the goal
meta def simp_all (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
do ctx ← local_context,
let ns := ctx.map local_pp_name,
revert_lst ctx,
simp_intro_lst_using' ns s {}
-- simplify all the hypotheses and the goal, using preceding hypotheses along the way
meta def simph_all (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
do ctx ← local_context,
let ns := ctx.map local_pp_name,
revert_lst ctx,
simp_intro_lst_using' ns s {}
/- Interactive tactics -/
namespace interactive
open lean lean.parser interactive interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many
-- copied from library
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
-- copied from library
private meta def report_invalid_simp_lemma {α : Type} (n : name): tactic α :=
fail ("invalid simplification lemma '" ++ to_string n ++ "' (use command 'set_option trace.simp_lemmas true' for more details)")
-- copied from library
private meta def simp_lemmas.resolve_and_add (s : simp_lemmas) (n : name) (ref : pexpr) : tactic simp_lemmas :=
do
p ← resolve_name n,
match p with
| const n _ :=
(do b ← is_valid_simp_lemma_cnst reducible n, guard b, save_const_type_info n ref, s.add_simp n)
<|>
(do eqns ← get_eqn_lemmas_for tt n, guard (eqns.length > 0), save_const_type_info n ref, add_simps s eqns)
<|>
report_invalid_simp_lemma n
| _ :=
(do e ← i_to_expr p, b ← is_valid_simp_lemma reducible e, guard b, try (save_type_info e ref), s.add e)
<|>
report_invalid_simp_lemma n
end
-- copied from library
private meta def simp_lemmas.add_pexpr (s : simp_lemmas) (p : pexpr) : tactic simp_lemmas :=
match p with
| (const c []) := simp_lemmas.resolve_and_add s c p
| (local_const c _ _ _) := simp_lemmas.resolve_and_add s c p
| _ := do new_e ← i_to_expr p, s.add new_e
end
-- copied from library
private meta def simp_lemmas.append_pexprs : simp_lemmas → list pexpr → tactic simp_lemmas
| s [] := return s
| s (l::ls) := do new_s ← simp_lemmas.add_pexpr s l, simp_lemmas.append_pexprs new_s ls
-- copied from library
-- TODO(Jeremy): note this is not private, because it is used by auto
meta def mk_simp_set (attr_names : list name) (hs : list pexpr) (ex : list name) : tactic simp_lemmas :=
do s₀ ← join_user_simp_lemmas attr_names,
s₁ ← simp_lemmas.append_pexprs s₀ hs,
-- add equational lemmas, if any
ex ← ex.mfor (λ n, list.cons n <$> get_eqn_lemmas_for tt n),
return $ simp_lemmas.erase s₁ $ ex.join
-- copied from library
private meta def simp_goal (cfg : simp_config) : simp_lemmas → tactic unit
| s := do
(new_target, Heq) ← target >>= simplify_core cfg s `eq,
tactic.assert `Htarget new_target, swap,
Ht ← get_local `Htarget,
mk_eq_mpr Heq Ht >>= tactic.exact
-- copied from library
private meta def simp_hyp (cfg : simp_config) (s : simp_lemmas) (h_name : name) : tactic unit :=
do h ← get_local h_name,
htype ← infer_type h,
(new_htype, eqpr) ← simplify_core cfg s `eq htype,
tactic.assert (expr.local_pp_name h) new_htype,
mk_eq_mp eqpr h >>= tactic.exact,
try $ tactic.clear h
-- copied from library
private meta def simp_hyps (cfg : simp_config) : simp_lemmas → list name → tactic unit
| s [] := skip
| s (h::hs) := simp_hyp cfg s h >> simp_hyps s hs
-- copied from library
private meta def simp_core (cfg : simp_config) (ctx : list expr) (hs : list pexpr) (attr_names : list name) (ids : list name) (loc : list name) : tactic unit :=
do s ← mk_simp_set attr_names hs ids,
s ← s.append ctx,
match loc : _ → tactic unit with
| [] := simp_goal cfg s
| _ := simp_hyps cfg s loc
end,
try tactic.triv, try (tactic.reflexivity reducible)
/- The new tactics -/
/-- Unfolds definitions in all the hypotheses and the goal. -/
meta def dunfold_all (ids : parse ident*) : tactic unit :=
tactic.dunfold_all ids
/-- Expands definitions in all the hypotheses and the goal. -/
meta def delta_all (ids : parse ident*) : tactic unit :=
tactic.dunfold_all ids
-- Note: in the next tactics we revert before building the simp set, because the
-- given lemmas should not mention the local context
/-- Applies dsimp to all the hypotheses and the goal. -/
meta def dsimp_all (es : parse opt_qexpr_list) (attr_names : parse with_ident_list)
(ids : parse without_ident_list) : tactic unit :=
do n ← revert_all,
s ← mk_simp_set attr_names es ids,
dsimp_all_aux s n,
dsimp_core s
/-- Simplifies all the hypotheses and the goal. -/
meta def simp_all (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list)
(ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit :=
do ctx ← local_context,
let ns := ctx.map local_pp_name,
revert_lst ctx,
s ← mk_simp_set attr_names hs ids,
simp_intro_lst_using' ns s cfg,
try tactic.triv, try (tactic.reflexivity reducible)
/-- Simplifies all the hypotheses and the goal, using preceding hypotheses along the way. -/
meta def simph_all (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list)
(ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit :=
do ctx ← local_context,
let ns := ctx.map local_pp_name,
revert_lst ctx,
s ← mk_simp_set attr_names hs ids,
simph_intro_lst_using' ns s cfg,
try tactic.triv, try (tactic.reflexivity reducible)
end interactive
end tactic
|
b5e0af128608773b1206eca17484c3312ebe8745 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/sequences.lean | 5b71cc2becf914f606eac79888c19e47f4508bd9 | [
"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 | 19,445 | lean | /-
Copyright (c) 2018 Jan-David Salchow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Patrick Massot, Yury Kudryashov
-/
import topology.subset_properties
import topology.metric_space.basic
/-!
# Sequences in topological spaces
In this file we define sequences in topological spaces and show how they are related to
filters and the topology.
## Main definitions
### Set operation
* `seq_closure s`: sequential closure of a set, the set of limits of sequences of points of `s`;
### Predicates
* `is_seq_closed s`: predicate saying that a set is sequentially closed, i.e., `seq_closure s ⊆ s`;
* `seq_continuous f`: predicate saying that a function is sequentially continuous, i.e.,
for any sequence `u : ℕ → X` that converges to a point `x`, the sequence `f ∘ u` converges to
`f x`;
* `is_seq_compact s`: predicate saying that a set is sequentially compact, i.e., every sequence
taking values in `s` has a converging subsequence.
### Type classes
* `frechet_urysohn_space X`: a typeclass saying that a topological space is a *Fréchet-Urysohn
space*, i.e., the sequential closure of any set is equal to its closure.
* `sequential_space X`: a typeclass saying that a topological space is a *sequential space*, i.e.,
any sequentially closed set in this space is closed. This condition is weaker than being a
Fréchet-Urysohn space.
* `seq_compact_space X`: a typeclass saying that a topological space is sequentially compact, i.e.,
every sequence in `X` has a converging subsequence.
## Main results
* `seq_closure_subset_closure`: closure of a set includes its sequential closure;
* `is_closed.is_seq_closed`: a closed set is sequentially closed;
* `is_seq_closed.seq_closure_eq`: sequential closure of a sequentially closed set `s` is equal
to `s`;
* `seq_closure_eq_closure`: in a Fréchet-Urysohn space, the sequential closure of a set is equal to
its closure;
* `tendsto_nhds_iff_seq_tendsto`, `frechet_urysohn_space.of_seq_tendsto_imp_tendsto`: a topological
space is a Fréchet-Urysohn space if and only if sequential convergence implies convergence;
* `topological_space.first_countable_topology.frechet_urysohn_space`: every topological space with
first countable topology is a Fréchet-Urysohn space;
* `frechet_urysohn_space.to_sequential_space`: every Fréchet-Urysohn space is a sequential space;
* `is_seq_compact.is_compact`: a sequentially compact set in a uniform space with countably
generated uniformity is compact.
## Tags
sequentially closed, sequentially compact, sequential space
-/
open set function filter topological_space
open_locale topological_space filter
variables {X Y : Type*}
/-! ### Sequential closures, sequential continuity, and sequential spaces. -/
section topological_space
variables [topological_space X] [topological_space Y]
/-- The sequential closure of a set `s : set X` in a topological space `X` is the set of all `a : X`
which arise as limit of sequences in `s`. Note that the sequential closure of a set is not
guaranteed to be sequentially closed. -/
def seq_closure (s : set X) : set X :=
{a | ∃ x : ℕ → X, (∀ n : ℕ, x n ∈ s) ∧ tendsto x at_top (𝓝 a)}
lemma subset_seq_closure {s : set X} : s ⊆ seq_closure s :=
λ p hp, ⟨const ℕ p, λ _, hp, tendsto_const_nhds⟩
/-- The sequential closure of a set is contained in the closure of that set.
The converse is not true. -/
lemma seq_closure_subset_closure {s : set X} : seq_closure s ⊆ closure s :=
λ p ⟨x, xM, xp⟩, mem_closure_of_tendsto xp (univ_mem' xM)
/-- A set `s` is sequentially closed if for any converging sequence `x n` of elements of `s`, the
limit belongs to `s` as well. Note that the sequential closure of a set is not guaranteed to be
sequentially closed. -/
def is_seq_closed (s : set X) : Prop :=
∀ ⦃x : ℕ → X⦄ ⦃p : X⦄, (∀ n, x n ∈ s) → tendsto x at_top (𝓝 p) → p ∈ s
/-- The sequential closure of a sequentially closed set is the set itself. -/
lemma is_seq_closed.seq_closure_eq {s : set X} (hs : is_seq_closed s) :
seq_closure s = s :=
subset.antisymm (λ p ⟨x, hx, hp⟩, hs hx hp) subset_seq_closure
/-- If a set is equal to its sequential closure, then it is sequentially closed. -/
lemma is_seq_closed_of_seq_closure_eq {s : set X} (hs : seq_closure s = s) :
is_seq_closed s :=
λ x p hxs hxp, hs ▸ ⟨x, hxs, hxp⟩
/-- A set is sequentially closed iff it is equal to its sequential closure. -/
lemma is_seq_closed_iff {s : set X} :
is_seq_closed s ↔ seq_closure s = s :=
⟨is_seq_closed.seq_closure_eq, is_seq_closed_of_seq_closure_eq⟩
/-- A set is sequentially closed if it is closed. -/
protected lemma is_closed.is_seq_closed {s : set X} (hc : is_closed s) : is_seq_closed s :=
λ u x hu hx, hc.mem_of_tendsto hx (eventually_of_forall hu)
/-- A topological space is called a *Fréchet-Urysohn space*, if the sequential closure of any set
is equal to its closure. Since one of the inclusions is trivial, we require only the non-trivial one
in the definition. -/
class frechet_urysohn_space (X : Type*) [topological_space X] : Prop :=
(closure_subset_seq_closure : ∀ s : set X, closure s ⊆ seq_closure s)
lemma seq_closure_eq_closure [frechet_urysohn_space X] (s : set X) :
seq_closure s = closure s :=
seq_closure_subset_closure.antisymm $ frechet_urysohn_space.closure_subset_seq_closure s
/-- In a Fréchet-Urysohn space, a point belongs to the closure of a set iff it is a limit
of a sequence taking values in this set. -/
lemma mem_closure_iff_seq_limit [frechet_urysohn_space X] {s : set X} {a : X} :
a ∈ closure s ↔ ∃ x : ℕ → X, (∀ n : ℕ, x n ∈ s) ∧ tendsto x at_top (𝓝 a) :=
by { rw [← seq_closure_eq_closure], refl }
/-- If the domain of a function `f : α → β` is a Fréchet-Urysohn space, then convergence
is equivalent to sequential convergence. See also `filter.tendsto_iff_seq_tendsto` for a version
that works for any pair of filters assuming that the filter in the domain is countably generated.
This property is equivalent to the definition of `frechet_urysohn_space`, see
`frechet_urysohn_space.of_seq_tendsto_imp_tendsto`. -/
lemma tendsto_nhds_iff_seq_tendsto [frechet_urysohn_space X] {f : X → Y} {a : X} {b : Y} :
tendsto f (𝓝 a) (𝓝 b) ↔ ∀ u : ℕ → X, tendsto u at_top (𝓝 a) → tendsto (f ∘ u) at_top (𝓝 b) :=
begin
refine ⟨λ hf u hu, hf.comp hu,
λ h, ((nhds_basis_closeds _).tendsto_iff (nhds_basis_closeds _)).2 _⟩,
rintro s ⟨hbs, hsc⟩,
refine ⟨closure (f ⁻¹' s), ⟨mt _ hbs, is_closed_closure⟩, λ x, mt $ λ hx, subset_closure hx⟩,
rw [← seq_closure_eq_closure],
rintro ⟨u, hus, hu⟩,
exact hsc.mem_of_tendsto (h u hu) (eventually_of_forall hus)
end
/-- An alternative construction for `frechet_urysohn_space`: if sequential convergence implies
convergence, then the space is a Fréchet-Urysohn space. -/
lemma frechet_urysohn_space.of_seq_tendsto_imp_tendsto
(h : ∀ (f : X → Prop) (a : X),
(∀ u : ℕ → X, tendsto u at_top (𝓝 a) → tendsto (f ∘ u) at_top (𝓝 (f a))) → continuous_at f a) :
frechet_urysohn_space X :=
begin
refine ⟨λ s x hcx, _⟩,
specialize h (∉ s) x,
by_cases hx : x ∈ s, { exact subset_seq_closure hx },
simp_rw [(∘), continuous_at, hx, not_false_iff, nhds_true, tendsto_pure, eq_true_iff,
← mem_compl_iff, eventually_mem_set, ← mem_interior_iff_mem_nhds, interior_compl] at h,
rw [mem_compl_iff, imp_not_comm] at h,
simp only [not_forall, not_eventually, mem_compl_iff, not_not] at h,
rcases h hcx with ⟨u, hux, hus⟩,
rcases extraction_of_frequently_at_top hus with ⟨φ, φ_mono, hφ⟩,
exact ⟨u ∘ φ, hφ, hux.comp φ_mono.tendsto_at_top⟩
end
/-- Every first-countable space is a Fréchet-Urysohn space. -/
@[priority 100] -- see Note [lower instance priority]
instance topological_space.first_countable_topology.frechet_urysohn_space
[first_countable_topology X] : frechet_urysohn_space X :=
frechet_urysohn_space.of_seq_tendsto_imp_tendsto $ λ f a, tendsto_iff_seq_tendsto.2
/-- A topological space is said to be a *sequential space* if any sequentially closed set in this
space is closed. This condition is weaker than being a Fréchet-Urysohn space. -/
class sequential_space (X : Type*) [topological_space X] : Prop :=
(is_closed_of_seq : ∀ s : set X, is_seq_closed s → is_closed s)
/-- Every Fréchet-Urysohn space is a sequential space. -/
@[priority 100] -- see Note [lower instance priority]
instance frechet_urysohn_space.to_sequential_space [frechet_urysohn_space X] :
sequential_space X :=
⟨λ s hs, by rw [← closure_eq_iff_is_closed, ← seq_closure_eq_closure, hs.seq_closure_eq]⟩
/-- In a sequential space, a sequentially closed set is closed. -/
protected lemma is_seq_closed.is_closed [sequential_space X] {s : set X} (hs : is_seq_closed s) :
is_closed s :=
sequential_space.is_closed_of_seq s hs
/-- In a sequential space, a set is closed iff it's sequentially closed. -/
lemma is_seq_closed_iff_is_closed [sequential_space X] {M : set X} :
is_seq_closed M ↔ is_closed M :=
⟨is_seq_closed.is_closed, is_closed.is_seq_closed⟩
/-- A function between topological spaces is sequentially continuous if it commutes with limit of
convergent sequences. -/
def seq_continuous (f : X → Y) : Prop :=
∀ ⦃x : ℕ → X⦄ ⦃p : X⦄, tendsto x at_top (𝓝 p) → tendsto (f ∘ x) at_top (𝓝 (f p))
/-- The preimage of a sequentially closed set under a sequentially continuous map is sequentially
closed. -/
lemma is_seq_closed.preimage {f : X → Y} {s : set Y} (hs : is_seq_closed s)
(hf : seq_continuous f) :
is_seq_closed (f ⁻¹' s) :=
λ x p hx hp, hs hx (hf hp)
/- A continuous function is sequentially continuous. -/
protected lemma continuous.seq_continuous {f : X → Y} (hf : continuous f) :
seq_continuous f :=
λ x p hx, (hf.tendsto p).comp hx
/-- A sequentially continuous function defined on a sequential space is continuous. -/
protected lemma seq_continuous.continuous [sequential_space X] {f : X → Y} (hf : seq_continuous f) :
continuous f :=
continuous_iff_is_closed.mpr $ λ s hs, (hs.is_seq_closed.preimage hf).is_closed
/-- If the domain of a function is a sequential space, then continuity of this function is
equivalent to its sequential continuity. -/
lemma continuous_iff_seq_continuous [sequential_space X] {f : X → Y} :
continuous f ↔ seq_continuous f :=
⟨continuous.seq_continuous, seq_continuous.continuous⟩
lemma quotient_map.sequential_space [sequential_space X] {f : X → Y} (hf : quotient_map f) :
sequential_space Y :=
⟨λ s hs, hf.is_closed_preimage.mp $ (hs.preimage $ hf.continuous.seq_continuous).is_closed⟩
/-- The quotient of a sequential space is a sequential space. -/
instance [sequential_space X] {s : setoid X} : sequential_space (quotient s) :=
quotient_map_quot_mk.sequential_space
end topological_space
section seq_compact
open topological_space topological_space.first_countable_topology
variables [topological_space X]
/-- A set `s` is sequentially compact if every sequence taking values in `s` has a
converging subsequence. -/
def is_seq_compact (s : set X) :=
∀ ⦃x : ℕ → X⦄, (∀ n, x n ∈ s) → ∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a)
/-- A space `X` is sequentially compact if every sequence in `X` has a
converging subsequence. -/
@[mk_iff] class seq_compact_space (X : Type*) [topological_space X] : Prop :=
(seq_compact_univ : is_seq_compact (univ : set X))
export seq_compact_space (seq_compact_univ)
lemma is_seq_compact.subseq_of_frequently_in {s : set X} (hs : is_seq_compact s) {x : ℕ → X}
(hx : ∃ᶠ n in at_top, x n ∈ s) :
∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a) :=
let ⟨ψ, hψ, huψ⟩ := extraction_of_frequently_at_top hx, ⟨a, a_in, φ, hφ, h⟩ := hs huψ in
⟨a, a_in, ψ ∘ φ, hψ.comp hφ, h⟩
lemma seq_compact_space.tendsto_subseq [seq_compact_space X] (x : ℕ → X) :
∃ a (φ : ℕ → ℕ), strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a) :=
let ⟨a, _, φ, mono, h⟩ := seq_compact_univ (λ n, mem_univ (x n)) in ⟨a, φ, mono, h⟩
section first_countable_topology
variables [first_countable_topology X]
open topological_space.first_countable_topology
protected lemma is_compact.is_seq_compact {s : set X} (hs : is_compact s) : is_seq_compact s :=
λ x x_in, let ⟨a, a_in, ha⟩ := hs (tendsto_principal.mpr (eventually_of_forall x_in))
in ⟨a, a_in, tendsto_subseq ha⟩
lemma is_compact.tendsto_subseq' {s : set X} {x : ℕ → X} (hs : is_compact s)
(hx : ∃ᶠ n in at_top, x n ∈ s) :
∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a) :=
hs.is_seq_compact.subseq_of_frequently_in hx
lemma is_compact.tendsto_subseq {s : set X} {x : ℕ → X} (hs : is_compact s) (hx : ∀ n, x n ∈ s) :
∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a) :=
hs.is_seq_compact hx
@[priority 100] -- see Note [lower instance priority]
instance first_countable_topology.seq_compact_of_compact [compact_space X] : seq_compact_space X :=
⟨is_compact_univ.is_seq_compact⟩
lemma compact_space.tendsto_subseq [compact_space X] (x : ℕ → X) :
∃ a (φ : ℕ → ℕ), strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a) :=
seq_compact_space.tendsto_subseq x
end first_countable_topology
end seq_compact
section uniform_space_seq_compact
open_locale uniformity
open uniform_space prod
variables [uniform_space X] {s : set X}
lemma is_seq_compact.exists_tendsto_of_frequently_mem (hs : is_seq_compact s) {u : ℕ → X}
(hu : ∃ᶠ n in at_top, u n ∈ s) (huc : cauchy_seq u) :
∃ x ∈ s, tendsto u at_top (𝓝 x) :=
let ⟨x, hxs, φ, φ_mono, hx⟩ := hs.subseq_of_frequently_in hu
in ⟨x, hxs, tendsto_nhds_of_cauchy_seq_of_subseq huc φ_mono.tendsto_at_top hx⟩
lemma is_seq_compact.exists_tendsto (hs : is_seq_compact s) {u : ℕ → X} (hu : ∀ n, u n ∈ s)
(huc : cauchy_seq u) : ∃ x ∈ s, tendsto u at_top (𝓝 x) :=
hs.exists_tendsto_of_frequently_mem (frequently_of_forall hu) huc
/-- A sequentially compact set in a uniform space is totally bounded. -/
protected lemma is_seq_compact.totally_bounded (h : is_seq_compact s) : totally_bounded s :=
begin
intros V V_in,
unfold is_seq_compact at h,
contrapose! h,
obtain ⟨u, u_in, hu⟩ : ∃ u : ℕ → X, (∀ n, u n ∈ s) ∧ ∀ n m, m < n → u m ∉ ball (u n) V,
{ simp only [not_subset, mem_Union₂, not_exists, exists_prop] at h,
simpa only [forall_and_distrib, ball_image_iff, not_and] using seq_of_forall_finite_exists h },
refine ⟨u, u_in, λ x x_in φ hφ huφ, _⟩,
obtain ⟨N, hN⟩ : ∃ N, ∀ p q, p ≥ N → q ≥ N → (u (φ p), u (φ q)) ∈ V,
from huφ.cauchy_seq.mem_entourage V_in,
exact hu (φ $ N + 1) (φ N) (hφ $ lt_add_one N) (hN (N + 1) N N.le_succ le_rfl)
end
variables [is_countably_generated (𝓤 X)]
/-- A sequentially compact set in a uniform set with countably generated uniformity filter
is complete. -/
protected lemma is_seq_compact.is_complete (hs : is_seq_compact s) : is_complete s :=
begin
intros l hl hls,
haveI := hl.1,
rcases exists_antitone_basis (𝓤 X) with ⟨V, hV⟩,
choose W hW hWV using λ n, comp_mem_uniformity_sets (hV.mem n),
have hWV' : ∀ n, W n ⊆ V n, from λ n ⟨x, y⟩ hx, @hWV n (x, y) ⟨x, refl_mem_uniformity $ hW _, hx⟩,
obtain ⟨t, ht_anti, htl, htW, hts⟩ : ∃ t : ℕ → set X, antitone t ∧ (∀ n, t n ∈ l) ∧
(∀ n, t n ×ˢ t n ⊆ W n) ∧ (∀ n, t n ⊆ s),
{ have : ∀ n, ∃ t ∈ l, t ×ˢ t ⊆ W n ∧ t ⊆ s,
{ rw [le_principal_iff] at hls,
have : ∀ n, W n ∩ s ×ˢ s ∈ l ×ᶠ l := λ n, inter_mem (hl.2 (hW n)) (prod_mem_prod hls hls),
simpa only [l.basis_sets.prod_self.mem_iff, true_implies_iff, subset_inter_iff,
prod_self_subset_prod_self, and.assoc] using this },
choose t htl htW hts,
have : ∀ n, (⋂ k ≤ n, t k) ⊆ t n, from λ n, Inter₂_subset _ le_rfl,
exact ⟨λ n, ⋂ k ≤ n, t k, λ m n h, bInter_subset_bInter_left (λ k (hk : k ≤ m), hk.trans h),
λ n, (bInter_mem (finite_le_nat n)).2 (λ k hk, htl k),
λ n, (prod_mono (this n) (this n)).trans (htW n), λ n, (this n).trans (hts n)⟩ },
choose u hu using λ n, filter.nonempty_of_mem (htl n),
have huc : cauchy_seq u := hV.to_has_basis.cauchy_seq_iff.2
(λ N hN, ⟨N, λ m hm n hn, hWV' _ $ @htW N (_, _) ⟨ht_anti hm (hu _), (ht_anti hn (hu _))⟩⟩),
rcases hs.exists_tendsto (λ n, hts n (hu n)) huc with ⟨x, hxs, hx⟩,
refine ⟨x, hxs, (nhds_basis_uniformity' hV.to_has_basis).ge_iff.2 $ λ N hN, _⟩,
obtain ⟨n, hNn, hn⟩ : ∃ n, N ≤ n ∧ u n ∈ ball x (W N),
from ((eventually_ge_at_top N).and (hx $ ball_mem_nhds x (hW N))).exists,
refine mem_of_superset (htl n) (λ y hy, hWV N ⟨u n, _, htW N ⟨_, _⟩⟩),
exacts [hn, ht_anti hNn (hu n), ht_anti hNn hy]
end
/-- If `𝓤 β` is countably generated, then any sequentially compact set is compact. -/
protected lemma is_seq_compact.is_compact (hs : is_seq_compact s) : is_compact s :=
is_compact_iff_totally_bounded_is_complete.2 ⟨hs.totally_bounded, hs.is_complete⟩
/-- A version of Bolzano-Weistrass: in a uniform space with countably generated uniformity filter
(e.g., in a metric space), a set is compact if and only if it is sequentially compact. -/
protected lemma uniform_space.is_compact_iff_is_seq_compact : is_compact s ↔ is_seq_compact s :=
⟨λ H, H.is_seq_compact, λ H, H.is_compact⟩
lemma uniform_space.compact_space_iff_seq_compact_space : compact_space X ↔ seq_compact_space X :=
by simp only [← is_compact_univ_iff, seq_compact_space_iff,
uniform_space.is_compact_iff_is_seq_compact]
end uniform_space_seq_compact
section metric_seq_compact
variables [pseudo_metric_space X]
open metric
lemma seq_compact.lebesgue_number_lemma_of_metric {ι : Sort*} {c : ι → set X}
{s : set X} (hs : is_seq_compact s) (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ δ > 0, ∀ a ∈ s, ∃ i, ball a δ ⊆ c i :=
lebesgue_number_lemma_of_metric hs.is_compact hc₁ hc₂
variables [proper_space X] {s : set X}
/-- A version of **Bolzano-Weistrass**: in a proper metric space (eg. $ℝ^n$),
every bounded sequence has a converging subsequence. This version assumes only
that the sequence is frequently in some bounded set. -/
lemma tendsto_subseq_of_frequently_bounded (hs : bounded s)
{x : ℕ → X} (hx : ∃ᶠ n in at_top, x n ∈ s) :
∃ a ∈ closure s, ∃ φ : ℕ → ℕ, strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a) :=
have hcs : is_seq_compact (closure s), from hs.is_compact_closure.is_seq_compact,
have hu' : ∃ᶠ n in at_top, x n ∈ closure s, from hx.mono (λ n hn, subset_closure hn),
hcs.subseq_of_frequently_in hu'
/-- A version of Bolzano-Weistrass: in a proper metric space (eg. $ℝ^n$),
every bounded sequence has a converging subsequence. -/
lemma tendsto_subseq_of_bounded (hs : bounded s) {x : ℕ → X} (hx : ∀ n, x n ∈ s) :
∃ a ∈ closure s, ∃ φ : ℕ → ℕ, strict_mono φ ∧ tendsto (x ∘ φ) at_top (𝓝 a) :=
tendsto_subseq_of_frequently_bounded hs $ frequently_of_forall hx
end metric_seq_compact
|
eaf46157bd68079a47b8cb1681f7af437959b7df | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/measure_theory/measure/vector_measure.lean | 3d76cc55ff340f3777e7d84b7116d714196d2307 | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 44,700 | 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.integral.lebesgue
/-!
# 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
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.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_refl _] },
{ intro, split_ifs,
exacts [le_refl _, 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
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_lt_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
/-- 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_refl _,
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_refl _ },
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_refl _,
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_refl _,
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
infix ` ≪ `:50 := absolutely_continuous
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
end mutually_singular
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
|
8e842d0a259b2ef4d83050bc6f3e02e2371288af | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/sub_bug.lean | c2d8664ea6c3f1987b7352e9c3e0117335c21290 | [
"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 | 44 | lean | open nat subtype
#check { x : nat // x > 0}
|
5ffdc63072adfada5ab9b00843394f11c1dc2aaa | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/adjunction/opposites.lean | 45bd32f1334c11047948318b0f7a298f7d3867bd | [
"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 | 4,628 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Thomas Read
-/
import category_theory.adjunction.basic
import category_theory.yoneda
import category_theory.opposites
/-!
# Opposite adjunctions
This file contains constructions to relate adjunctions of functors to adjunctions of their
opposites.
These constructions are used to show uniqueness of adjoints (up to natural isomorphism).
## Tags
adjunction, opposite, uniqueness
-/
open category_theory
universes v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes].
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
namespace adjunction
/-- If `G.op` is adjoint to `F.op` then `F` is adjoint to `G`. -/
def adjoint_of_op_adjoint_op (F : C ⥤ D) (G : D ⥤ C) (h : G.op ⊣ F.op) : F ⊣ G :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X Y,
((h.hom_equiv (opposite.op Y) (opposite.op X)).trans (op_equiv _ _)).symm.trans (op_equiv _ _) }
/-- If `G` is adjoint to `F.op` then `F` is adjoint to `G.unop`. -/
def adjoint_unop_of_adjoint_op (F : C ⥤ D) (G : Dᵒᵖ ⥤ Cᵒᵖ) (h : G ⊣ F.op) : F ⊣ G.unop :=
adjoint_of_op_adjoint_op F G.unop (h.of_nat_iso_left G.op_unop_iso.symm)
/-- If `G.op` is adjoint to `F` then `F.unop` is adjoint to `G`. -/
def unop_adjoint_of_op_adjoint (F : Cᵒᵖ ⥤ Dᵒᵖ) (G : D ⥤ C) (h : G.op ⊣ F) : F.unop ⊣ G :=
adjoint_of_op_adjoint_op _ _ (h.of_nat_iso_right F.op_unop_iso.symm)
/-- If `G` is adjoint to `F` then `F.unop` is adjoint to `G.unop`. -/
def unop_adjoint_unop_of_adjoint (F : Cᵒᵖ ⥤ Dᵒᵖ) (G : Dᵒᵖ ⥤ Cᵒᵖ) (h : G ⊣ F) : F.unop ⊣ G.unop :=
adjoint_unop_of_adjoint_op F.unop G (h.of_nat_iso_right F.op_unop_iso.symm)
/-- If `G` is adjoint to `F` then `F.op` is adjoint to `G.op`. -/
def op_adjoint_op_of_adjoint (F : C ⥤ D) (G : D ⥤ C) (h : G ⊣ F) : F.op ⊣ G.op :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X Y,
(op_equiv _ Y).trans ((h.hom_equiv _ _).symm.trans (op_equiv X (opposite.op _)).symm) }
/-- If `G` is adjoint to `F.unop` then `F` is adjoint to `G.op`. -/
def adjoint_op_of_adjoint_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) (G : D ⥤ C) (h : G ⊣ F.unop) : F ⊣ G.op :=
(op_adjoint_op_of_adjoint F.unop _ h).of_nat_iso_left F.op_unop_iso
/-- If `G.unop` is adjoint to `F` then `F.op` is adjoint to `G`. -/
def op_adjoint_of_unop_adjoint (F : C ⥤ D) (G : Dᵒᵖ ⥤ Cᵒᵖ) (h : G.unop ⊣ F) : F.op ⊣ G :=
(op_adjoint_op_of_adjoint _ G.unop h).of_nat_iso_right G.op_unop_iso
/-- If `G.unop` is adjoint to `F.unop` then `F` is adjoint to `G`. -/
def adjoint_of_unop_adjoint_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) (G : Dᵒᵖ ⥤ Cᵒᵖ) (h : G.unop ⊣ F.unop) : F ⊣ G :=
(adjoint_op_of_adjoint_unop _ _ h).of_nat_iso_right G.op_unop_iso
/--
If `F` and `F'` are both adjoint to `G`, there is a natural isomorphism
`F.op ⋙ coyoneda ≅ F'.op ⋙ coyoneda`.
We use this in combination with `fully_faithful_cancel_right` to show left adjoints are unique.
-/
def left_adjoints_coyoneda_equiv {F F' : C ⥤ D} {G : D ⥤ C}
(adj1 : F ⊣ G) (adj2 : F' ⊣ G):
F.op ⋙ coyoneda ≅ F'.op ⋙ coyoneda :=
nat_iso.of_components
(λ X, nat_iso.of_components
(λ Y, ((adj1.hom_equiv X.unop Y).trans (adj2.hom_equiv X.unop Y).symm).to_iso)
(by tidy))
(by tidy)
/-- If `F` and `F'` are both left adjoint to `G`, then they are naturally isomorphic. -/
def left_adjoint_uniq {F F' : C ⥤ D} {G : D ⥤ C}
(adj1 : F ⊣ G) (adj2 : F' ⊣ G) : F ≅ F' :=
nat_iso.remove_op (fully_faithful_cancel_right _ (left_adjoints_coyoneda_equiv adj2 adj1))
/-- If `G` and `G'` are both right adjoint to `F`, then they are naturally isomorphic. -/
def right_adjoint_uniq {F : C ⥤ D} {G G' : D ⥤ C}
(adj1 : F ⊣ G) (adj2 : F ⊣ G') : G ≅ G' :=
nat_iso.remove_op
(left_adjoint_uniq (op_adjoint_op_of_adjoint _ F adj2) (op_adjoint_op_of_adjoint _ _ adj1))
/--
Given two adjunctions, if the left adjoints are naturally isomorphic, then so are the right
adjoints.
-/
def nat_iso_of_left_adjoint_nat_iso {F F' : C ⥤ D} {G G' : D ⥤ C}
(adj1 : F ⊣ G) (adj2 : F' ⊣ G') (l : F ≅ F') :
G ≅ G' :=
right_adjoint_uniq adj1 (adj2.of_nat_iso_left l.symm)
/--
Given two adjunctions, if the right adjoints are naturally isomorphic, then so are the left
adjoints.
-/
def nat_iso_of_right_adjoint_nat_iso {F F' : C ⥤ D} {G G' : D ⥤ C}
(adj1 : F ⊣ G) (adj2 : F' ⊣ G') (r : G ≅ G') :
F ≅ F' :=
left_adjoint_uniq adj1 (adj2.of_nat_iso_right r.symm)
end adjunction
|
f1d3a5e644394b982b62f34ee222e43a95f8c86f | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/2005.lean | 79616ee7e43b510e9cc442434a92afbbecdfd493 | [
"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 | 189 | lean | import Lean
open Lean
syntax (docComment)? "foo" term : command
def foo2 : Syntax → Nat
| `($[$_]? foo !$_) => 1
| `(foo -$_) => 2
| _ => 0
#eval foo2 (Unhygienic.run `(foo -x))
|
d493e849a5151a8bb293440c3fd307847cf0c3a0 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/topology/bornology/hom.lean | aeca18629976d0618c80e6680933fd3b3b07ef4b | [
"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 | 4,967 | 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 topology.bornology.basic
/-!
# Locally bounded maps
This file defines locally bounded maps between bornologies.
We use the `fun_like` design, so each type of morphisms has a companion typeclass which is meant to
be satisfied by itself and all stricter types.
## Types of morphisms
* `locally_bounded_map`: Locally bounded maps. Maps which preserve boundedness.
## Typeclasses
* `locally_bounded_map_class`
-/
open bornology filter function set
variables {F α β γ δ : Type*}
/-- The type of bounded maps from `α` to `β`, the maps which send a bounded set to a bounded set. -/
structure locally_bounded_map (α β : Type*) [bornology α] [bornology β] :=
(to_fun : α → β)
(comap_cobounded_le' : (cobounded β).comap to_fun ≤ cobounded α)
/-- `locally_bounded_map_class F α β` states that `F` is a type of bounded maps.
You should extend this class when you extend `locally_bounded_map`. -/
class locally_bounded_map_class (F : Type*) (α β : out_param $ Type*) [bornology α]
[bornology β]
extends fun_like F α (λ _, β) :=
(comap_cobounded_le (f : F) : (cobounded β).comap f ≤ cobounded α)
export locally_bounded_map_class (comap_cobounded_le)
lemma is_bounded.image [bornology α] [bornology β] [locally_bounded_map_class F α β] {f : F}
{s : set α} (hs : is_bounded s) : is_bounded (f '' s) :=
comap_cobounded_le_iff.1 (comap_cobounded_le f) hs
instance [bornology α] [bornology β] [locally_bounded_map_class F α β] :
has_coe_t F (locally_bounded_map α β) :=
⟨λ f, ⟨f, comap_cobounded_le f⟩⟩
namespace locally_bounded_map
variables [bornology α] [bornology β] [bornology γ]
[bornology δ]
instance : locally_bounded_map_class (locally_bounded_map α β) α β :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, by { cases f, cases g, congr' },
comap_cobounded_le := λ f, f.comap_cobounded_le' }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (locally_bounded_map α β) (λ _, α → β) := fun_like.has_coe_to_fun
@[simp] lemma to_fun_eq_coe {f : locally_bounded_map α β} : f.to_fun = (f : α → β) := rfl
@[ext] lemma ext {f g : locally_bounded_map α β} (h : ∀ a, f a = g a) : f = g := fun_like.ext f g h
/-- Copy of a `locally_bounded_map` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (f : locally_bounded_map α β) (f' : α → β) (h : f' = f) :
locally_bounded_map α β :=
⟨f', h.symm ▸ f.comap_cobounded_le'⟩
/-- Construct a `locally_bounded_map` from the fact that the function maps bounded sets to bounded
sets. -/
def of_map_bounded (f : α → β) (h) : locally_bounded_map α β := ⟨f, comap_cobounded_le_iff.2 h⟩
@[simp] lemma coe_of_map_bounded (f : α → β) {h} : ⇑(of_map_bounded f h) = f := rfl
@[simp] lemma of_map_bounded_apply (f : α → β) {h} (a : α) : of_map_bounded f h a = f a := rfl
variables (α)
/-- `id` as a `locally_bounded_map`. -/
protected def id : locally_bounded_map α α := ⟨id, comap_id.le⟩
instance : inhabited (locally_bounded_map α α) := ⟨locally_bounded_map.id α⟩
@[simp] lemma coe_id : ⇑(locally_bounded_map.id α) = id := rfl
variables {α}
@[simp] lemma id_apply (a : α) : locally_bounded_map.id α a = a := rfl
/-- Composition of `locally_bounded_map`s as a `locally_bounded_map`. -/
def comp (f : locally_bounded_map β γ) (g : locally_bounded_map α β) : locally_bounded_map α γ :=
{ to_fun := f ∘ g,
comap_cobounded_le' :=
comap_comap.ge.trans $ (comap_mono f.comap_cobounded_le').trans g.comap_cobounded_le' }
@[simp] lemma coe_comp (f : locally_bounded_map β γ) (g : locally_bounded_map α β) :
⇑(f.comp g) = f ∘ g := rfl
@[simp] lemma comp_apply (f : locally_bounded_map β γ) (g : locally_bounded_map α β) (a : α) :
f.comp g a = f (g a) := rfl
@[simp] lemma comp_assoc (f : locally_bounded_map γ δ) (g : locally_bounded_map β γ)
(h : locally_bounded_map α β) :
(f.comp g).comp h = f.comp (g.comp h) := rfl
@[simp] lemma comp_id (f : locally_bounded_map α β) :
f.comp (locally_bounded_map.id α) = f := ext $ λ a, rfl
@[simp] lemma id_comp (f : locally_bounded_map α β) :
(locally_bounded_map.id β).comp f = f := ext $ λ a, rfl
lemma cancel_right {g₁ g₂ : locally_bounded_map β γ} {f : locally_bounded_map α β}
(hf : surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, ext $ hf.forall.2 $ fun_like.ext_iff.1 h, congr_arg _⟩
lemma cancel_left {g : locally_bounded_map β γ} {f₁ f₂ : locally_bounded_map α β}
(hg : injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, ext $ λ a, hg $ by rw [←comp_apply, h, comp_apply], congr_arg _⟩
end locally_bounded_map
|
f0b548f7ca867e2b269c2b8aff9a8fa19a94ec13 | 34c1747a946aa0941114ffca77a3b7c1e4cfb686 | /src/sheaves/presheaf_of_rings_extension.lean | 8498508ba32a2d8b20c943166db688bacaebb7e4 | [] | no_license | martrik/lean-scheme | 2b9edd63550c4579a451f793ab289af9fc79a16d | 033dc47192ba4c61e4e771701f5e29f8007e6332 | refs/heads/master | 1,588,866,287,405 | 1,554,922,682,000 | 1,554,922,682,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,668 | lean | /-
Presheaf of rings extension.
https://stacks.math.columbia.edu/tag/009N
-/
import to_mathlib.opens
import sheaves.presheaf_of_rings
import sheaves.presheaf_of_rings_on_basis
import sheaves.sheaf_on_basis
import sheaves.stalk_of_rings_on_standard_basis
universes u v w
open topological_space
open lattice
open covering
open stalk_of_rings_on_standard_basis.
section presheaf_of_rings_extension
variables {α : Type u} [topological_space α]
variables {B : set (opens α)} {HB : opens.is_basis B}
variables (Bstd : opens.univ ∈ B ∧ ∀ {U V}, U ∈ B → V ∈ B → U ∩ V ∈ B)
variables (F : presheaf_of_rings_on_basis α HB) (U : opens α)
include Bstd
section presheaf_of_rings_on_basis_extension_is_ring
@[reducible] def Fext :=
{ s : Π (x ∈ U), stalk_of_rings_on_standard_basis Bstd F x //
∀ (x ∈ U), ∃ (V) (BV : V ∈ B) (Hx : x ∈ V) (σ : F.to_presheaf_on_basis BV),
∀ (y ∈ U ∩ V), s y = λ _, ⟦{U := V, BU := BV, Hx := H.2, s := σ}⟧ }
-- Add.
private def Fext_add_aux (x : α)
: stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x :=
(stalk_of_rings_on_standard_basis.has_add Bstd F x).add
private def Fext_add : Fext Bstd F U → Fext Bstd F U → Fext Bstd F U
:= λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩,
⟨λ x Hx, (Fext_add_aux Bstd F x) (s₁ x Hx) (s₂ x Hx),
begin
intros x Hx,
replace Hs₁ := Hs₁ x Hx,
replace Hs₂ := Hs₂ x Hx,
rcases Hs₁ with ⟨V₁, BV₁, HxV₁, σ₁, Hs₁⟩,
rcases Hs₂ with ⟨V₂, BV₂, HxV₂, σ₂, Hs₂⟩,
use [V₁ ∩ V₂, Bstd.2 BV₁ BV₂, ⟨HxV₁, HxV₂⟩],
let σ₁' := F.res BV₁ (Bstd.2 BV₁ BV₂) (set.inter_subset_left _ _) σ₁,
let σ₂' := F.res BV₂ (Bstd.2 BV₁ BV₂) (set.inter_subset_right _ _) σ₂,
use [σ₁' + σ₂'],
rintros y ⟨HyU, ⟨HyV₁, HyV₂⟩⟩,
apply funext,
intros Hy,
replace Hs₁ := Hs₁ y ⟨HyU, HyV₁⟩,
replace Hs₂ := Hs₂ y ⟨HyU, HyV₂⟩,
rw Hs₁,
rw Hs₂,
refl,
end⟩
instance Fext_has_add : has_add (Fext Bstd F U) :=
{ add := Fext_add Bstd F U }
@[simp] lemma Fext_add.eq (x : α) (Hx : x ∈ U)
: ∀ (a b : Fext Bstd F U), (a + b).val x Hx = (a.val x Hx) + (b.val x Hx) :=
λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, rfl
instance Fext_add_semigroup : add_semigroup (Fext Bstd F U) :=
{ add_assoc := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_has_add Bstd F U }
instance Fext_add_comm_semigroup : add_comm_semigroup (Fext Bstd F U) :=
{ add_comm := λ a b, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_add_semigroup Bstd F U }
-- Zero.
private def Fext_zero : Fext Bstd F U :=
⟨λ x Hx, (stalk_of_rings_on_standard_basis.has_zero Bstd F x).zero,
λ x Hx, ⟨opens.univ, Bstd.1, trivial, 0, (λ y Hy, funext $ λ HyU, rfl)⟩⟩
instance Fext_has_zero : has_zero (Fext Bstd F U) :=
{ zero := Fext_zero Bstd F U }
@[simp] lemma Fext_zero.eq (x : α) (Hx : x ∈ U)
: (0 : Fext Bstd F U).val x Hx = (stalk_of_rings_on_standard_basis.has_zero Bstd F x).zero := rfl
instance Fext_add_comm_monoid : add_comm_monoid (Fext Bstd F U) :=
{ zero_add := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
add_zero := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_has_zero Bstd F U,
..Fext_add_comm_semigroup Bstd F U, }
-- Neg.
private def Fext_neg_aux (x : α)
: stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x :=
(stalk_of_rings_on_standard_basis.has_neg Bstd F x).neg
private def Fext_neg : Fext Bstd F U → Fext Bstd F U :=
λ ⟨s, Hs⟩,
⟨λ x Hx, (Fext_neg_aux Bstd F x) (s x Hx),
begin
intros x Hx,
replace Hs := Hs x Hx,
rcases Hs with ⟨V, BV, HxV, σ, Hs⟩,
use [V, BV, HxV, -σ],
rintros y ⟨HyU, HyV⟩,
apply funext,
intros Hy,
replace Hs := Hs y ⟨HyU, HyV⟩,
rw Hs,
refl,
end⟩
instance Fext_has_neg : has_neg (Fext Bstd F U) :=
{ neg := Fext_neg Bstd F U, }
@[simp] lemma Fext_neg.eq (x : α) (Hx : x ∈ U)
: ∀ (a : Fext Bstd F U), (-a).val x Hx = -(a.val x Hx) :=
λ ⟨s, Hs⟩, rfl
instance Fext_add_comm_group : add_comm_group (Fext Bstd F U) :=
{ add_left_neg := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU, by simp,
..Fext_has_neg Bstd F U,
..Fext_add_comm_monoid Bstd F U, }
-- Mul.
private def Fext_mul_aux (x : α)
: stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x
→ stalk_of_rings_on_standard_basis Bstd F x :=
(stalk_of_rings_on_standard_basis.has_mul Bstd F x).mul
private def Fext_mul : Fext Bstd F U → Fext Bstd F U → Fext Bstd F U
:= λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩,
⟨λ x Hx, (Fext_mul_aux Bstd F x) (s₁ x Hx) (s₂ x Hx),
begin
intros x Hx,
replace Hs₁ := Hs₁ x Hx,
replace Hs₂ := Hs₂ x Hx,
rcases Hs₁ with ⟨V₁, BV₁, HxV₁, σ₁, Hs₁⟩,
rcases Hs₂ with ⟨V₂, BV₂, HxV₂, σ₂, Hs₂⟩,
use [V₁ ∩ V₂, Bstd.2 BV₁ BV₂, ⟨HxV₁, HxV₂⟩],
let σ₁' := F.res BV₁ (Bstd.2 BV₁ BV₂) (set.inter_subset_left _ _) σ₁,
let σ₂' := F.res BV₂ (Bstd.2 BV₁ BV₂) (set.inter_subset_right _ _) σ₂,
use [σ₁' * σ₂'],
rintros y ⟨HyU, ⟨HyV₁, HyV₂⟩⟩,
apply funext,
intros Hy,
replace Hs₁ := Hs₁ y ⟨HyU, HyV₁⟩,
replace Hs₂ := Hs₂ y ⟨HyU, HyV₂⟩,
rw Hs₁,
rw Hs₂,
refl,
end⟩
instance Fext_has_mul : has_mul (Fext Bstd F U) :=
{ mul := Fext_mul Bstd F U }
@[simp] lemma Fext_mul.eq (x : α) (Hx : x ∈ U)
: ∀ (a b : Fext Bstd F U), (a * b).val x Hx = (a.val x Hx) * (b.val x Hx) :=
λ ⟨s₁, Hs₁⟩ ⟨s₂, Hs₂⟩, rfl
instance Fext_mul_semigroup : semigroup (Fext Bstd F U) :=
{ mul_assoc := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_semigroup Bstd F x).mul_assoc,
end,
..Fext_has_mul Bstd F U, }
instance Fext_mul_comm_semigroup : comm_semigroup (Fext Bstd F U) :=
{ mul_comm := λ a b, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_comm_semigroup Bstd F x).mul_comm,
end,
..Fext_mul_semigroup Bstd F U, }
-- One.
private def Fext_one : Fext Bstd F U :=
⟨λ x Hx, (stalk_of_rings_on_standard_basis.has_one Bstd F x).one,
λ x Hx, ⟨opens.univ, Bstd.1, trivial, 1, (λ y Hy, funext $ λ HyU, rfl)⟩⟩
instance Fext_has_one : has_one (Fext Bstd F U) :=
{ one := Fext_one Bstd F U }
instance Fext_mul_comm_monoid : comm_monoid (Fext Bstd F U) :=
{ one_mul := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_comm_monoid Bstd F x).one_mul,
end,
mul_one := λ a, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
simp,
apply (stalk_of_rings_on_standard_basis.mul_comm_monoid Bstd F x).mul_one,
end,
..Fext_has_one Bstd F U,
..Fext_mul_comm_semigroup Bstd F U, }
-- Ring
instance Fext_comm_ring : comm_ring (Fext Bstd F U) :=
{ left_distrib := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
rw Fext_add.eq,
repeat { rw Fext_mul.eq, },
rw Fext_add.eq,
eapply (stalk_of_rings_on_standard_basis.comm_ring Bstd F x).left_distrib,
end,
right_distrib := λ a b c, subtype.eq $ funext $ λ x, funext $ λ HxU,
begin
rw Fext_add.eq,
repeat { rw Fext_mul.eq, },
rw Fext_add.eq,
eapply (stalk_of_rings_on_standard_basis.comm_ring Bstd F x).right_distrib,
end,
..Fext_add_comm_group Bstd F U,
..Fext_mul_comm_monoid Bstd F U, }
end presheaf_of_rings_on_basis_extension_is_ring
-- F defined in the whole space to F defined on the basis.
def presheaf_of_rings_to_presheaf_of_rings_on_basis
(F : presheaf_of_rings α) : presheaf_of_rings_on_basis α HB :=
{ F := λ U BU, F U,
res := λ U V BU BV HVU, F.res U V HVU,
Hid := λ U BU, F.Hid U,
Hcomp := λ U V W BU BV BW, F.Hcomp U V W,
Fring := λ U BU, F.Fring U,
res_is_ring_hom := λ U V BU BV HVU, F.res_is_ring_hom U V HVU, }
-- F defined on the bases extended to the whole space.
def presheaf_of_rings_on_basis_to_presheaf_of_rings
(F : presheaf_of_rings_on_basis α HB) : presheaf_of_rings α :=
{ F := λ U, {s : Π (x ∈ U), stalk_on_basis F.to_presheaf_on_basis x //
∀ (x ∈ U), ∃ (V) (BV : V ∈ B) (Hx : x ∈ V) (σ : F.to_presheaf_on_basis BV),
∀ (y ∈ U ∩ V), s y = λ _, ⟦{U := V, BU := BV, Hx := H.2, s := σ}⟧},
res := λ U W HWU FU,
{ val := λ x HxW, (FU.val x $ HWU HxW),
property := λ x HxW,
begin
rcases (FU.property x (HWU HxW)) with ⟨V, ⟨BV, ⟨HxV, ⟨σ, HFV⟩⟩⟩⟩,
use [V, BV, HxV, σ],
rintros y ⟨HyW, HyV⟩,
rw (HFV y ⟨HWU HyW, HyV⟩),
end },
Hid := λ U, funext $ λ x, subtype.eq rfl,
Hcomp := λ U V W HWV HVU, funext $ λ x, subtype.eq rfl,
Fring := λ U, Fext_comm_ring Bstd F U,
res_is_ring_hom := λ U V HVU,
{ map_one := rfl,
map_mul := λ x y, subtype.eq $ funext $ λ x, funext $ λ Hx,
begin
erw Fext_mul.eq,
refl,
end,
map_add := λ x y, subtype.eq $ funext $ λ x, funext $ λ Hx,
begin
erw Fext_add.eq,
refl,
end, } }
notation F `ᵣₑₓₜ`:1 Bstd := presheaf_of_rings_on_basis_to_presheaf_of_rings Bstd F
end presheaf_of_rings_extension
|
3951a33c02b83e6fa45c2afdeb72f3051f990a00 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/linear_algebra/matrix/reindex.lean | 56e22e46b138b8ee78f7979b0089437f3d302eac | [
"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 | 5,487 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import linear_algebra.matrix.determinant
/-!
# Changing the index type of a matrix
This file concerns the map `matrix.reindex`, mapping a `m` by `n` matrix
to an `m'` by `n'` matrix, as long as `m ≃ m'` and `n ≃ n'`.
## Main definitions
* `matrix.reindex_linear_equiv R A`: `matrix.reindex` is an `R`-linear equivalence between
`A`-matrices.
* `matrix.reindex_alg_equiv R`: `matrix.reindex` is an `R`-algebra equivalence between `R`-matrices.
## Tags
matrix, reindex
-/
namespace matrix
open equiv
open_locale matrix
variables {l m n o : Type*} {l' m' n' o' : Type*} {m'' n'' : Type*}
variables (R A : Type*)
section add_comm_monoid
variables [semiring R] [add_comm_monoid A] [module R A]
/-- The natural map that reindexes a matrix's rows and columns with equivalent types,
`matrix.reindex`, is a linear equivalence. -/
def reindex_linear_equiv (eₘ : m ≃ m') (eₙ : n ≃ n') : matrix m n A ≃ₗ[R] matrix m' n' A :=
{ map_add' := λ _ _, rfl,
map_smul' := λ _ _, rfl,
..(reindex eₘ eₙ)}
@[simp] lemma reindex_linear_equiv_apply
(eₘ : m ≃ m') (eₙ : n ≃ n') (M : matrix m n A) :
reindex_linear_equiv R A eₘ eₙ M = reindex eₘ eₙ M :=
rfl
@[simp] lemma reindex_linear_equiv_symm (eₘ : m ≃ m') (eₙ : n ≃ n') :
(reindex_linear_equiv R A eₘ eₙ).symm = reindex_linear_equiv R A eₘ.symm eₙ.symm :=
rfl
@[simp] lemma reindex_linear_equiv_refl_refl :
reindex_linear_equiv R A (equiv.refl m) (equiv.refl n) = linear_equiv.refl R _ :=
linear_equiv.ext $ λ _, rfl
lemma reindex_linear_equiv_trans (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'')
(e₂' : n' ≃ n'') : (reindex_linear_equiv R A e₁ e₂).trans (reindex_linear_equiv R A e₁' e₂') =
(reindex_linear_equiv R A (e₁.trans e₁') (e₂.trans e₂') : _ ≃ₗ[R] _) :=
by { ext, refl }
lemma reindex_linear_equiv_comp (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'')
(e₂' : n' ≃ n'') :
(reindex_linear_equiv R A e₁' e₂') ∘ (reindex_linear_equiv R A e₁ e₂)
= reindex_linear_equiv R A (e₁.trans e₁') (e₂.trans e₂') :=
by { rw [← reindex_linear_equiv_trans], refl }
lemma reindex_linear_equiv_comp_apply (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'')
(e₂' : n' ≃ n'') (M : matrix m n A) :
(reindex_linear_equiv R A e₁' e₂') (reindex_linear_equiv R A e₁ e₂ M) =
reindex_linear_equiv R A (e₁.trans e₁') (e₂.trans e₂') M :=
submatrix_submatrix _ _ _ _ _
lemma reindex_linear_equiv_one [decidable_eq m] [decidable_eq m'] [has_one A]
(e : m ≃ m') : (reindex_linear_equiv R A e e (1 : matrix m m A)) = 1 :=
submatrix_one_equiv e.symm
end add_comm_monoid
section semiring
variables [semiring R] [semiring A] [module R A]
lemma reindex_linear_equiv_mul [fintype n] [fintype n']
(eₘ : m ≃ m') (eₙ : n ≃ n') (eₒ : o ≃ o') (M : matrix m n A) (N : matrix n o A) :
reindex_linear_equiv R A eₘ eₙ M ⬝ reindex_linear_equiv R A eₙ eₒ N =
reindex_linear_equiv R A eₘ eₒ (M ⬝ N) :=
submatrix_mul_equiv M N _ _ _
lemma mul_reindex_linear_equiv_one [fintype n] [fintype o] [decidable_eq o] (e₁ : o ≃ n)
(e₂ : o ≃ n') (M : matrix m n A) : M.mul (reindex_linear_equiv R A e₁ e₂ 1) =
reindex_linear_equiv R A (equiv.refl m) (e₁.symm.trans e₂) M :=
mul_submatrix_one _ _ _
end semiring
section algebra
variables [comm_semiring R] [fintype n] [fintype m] [decidable_eq m] [decidable_eq n]
/--
For square matrices with coefficients in commutative semirings, the natural map that reindexes
a matrix's rows and columns with equivalent types, `matrix.reindex`, is an equivalence of algebras.
-/
def reindex_alg_equiv (e : m ≃ n) : matrix m m R ≃ₐ[R] matrix n n R :=
{ to_fun := reindex e e,
map_mul' := λ a b, (reindex_linear_equiv_mul R R e e e a b).symm,
commutes' := λ r, by simp [algebra_map, algebra.to_ring_hom, submatrix_smul],
..(reindex_linear_equiv R R e e) }
@[simp] lemma reindex_alg_equiv_apply (e : m ≃ n) (M : matrix m m R) :
reindex_alg_equiv R e M = reindex e e M :=
rfl
@[simp] lemma reindex_alg_equiv_symm (e : m ≃ n) :
(reindex_alg_equiv R e).symm = reindex_alg_equiv R e.symm :=
rfl
@[simp] lemma reindex_alg_equiv_refl : reindex_alg_equiv R (equiv.refl m) = alg_equiv.refl :=
alg_equiv.ext $ λ _, rfl
lemma reindex_alg_equiv_mul (e : m ≃ n) (M : matrix m m R) (N : matrix m m R) :
reindex_alg_equiv R e (M ⬝ N) = reindex_alg_equiv R e M ⬝ reindex_alg_equiv R e N :=
(reindex_alg_equiv R e).map_mul M N
end algebra
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_submatrix_equiv_self`.
-/
lemma det_reindex_linear_equiv_self [comm_ring R] [fintype m] [decidable_eq m]
[fintype n] [decidable_eq n] (e : m ≃ n) (M : matrix m m R) :
det (reindex_linear_equiv R R e e M) = det M :=
det_reindex_self e M
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_submatrix_equiv_self`.
-/
lemma det_reindex_alg_equiv [comm_ring R] [fintype m] [decidable_eq m] [fintype n] [decidable_eq n]
(e : m ≃ n) (A : matrix m m R) :
det (reindex_alg_equiv R e A) = det A :=
det_reindex_self e A
end matrix
|
d7f7b8e92e13d11f8525040fd9a84700ae81eef8 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/linear_algebra/finsupp_vector_space.lean | 301c9c2a9c934a9da09ef98e3c49c3e1309cd82e | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 7,424 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
Linear structures on function with finite support `ι →₀ β`.
-/
import data.mv_polynomial
import linear_algebra.dimension
import linear_algebra.direct_sum.finsupp
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
open set linear_map submodule
namespace finsupp
section ring
variables {R : Type*} {M : Type*} {ι : Type*}
variables [ring R] [add_comm_group M] [module R M]
lemma linear_independent_single {φ : ι → Type*}
{f : Π ι, φ ι → M} (hf : ∀i, linear_independent R (f i)) :
linear_independent R (λ ix : Σ i, φ i, single ix.1 (f ix.1 ix.2)) :=
begin
apply @linear_independent_Union_finite R _ _ _ _ ι φ (λ i x, single i (f i x)),
{ assume i,
have h_disjoint : disjoint (span R (range (f i))) (ker (lsingle i)),
{ rw ker_lsingle,
exact disjoint_bot_right },
apply (hf i).map h_disjoint },
{ intros i t ht hit,
refine (disjoint_lsingle_lsingle {i} t (disjoint_singleton_left.2 hit)).mono _ _,
{ rw span_le,
simp only [supr_singleton],
rw range_coe,
apply range_comp_subset_range },
{ refine supr_le_supr (λ i, supr_le_supr _),
intros hi,
rw span_le,
rw range_coe,
apply range_comp_subset_range } }
end
open linear_map submodule
lemma is_basis_single {φ : ι → Type*} (f : Π ι, φ ι → M)
(hf : ∀i, is_basis R (f i)) :
is_basis R (λ ix : Σ i, φ i, single ix.1 (f ix.1 ix.2)) :=
begin
split,
{ apply linear_independent_single,
exact λ i, (hf i).1 },
{ rw [range_sigma_eq_Union_range, span_Union],
simp only [image_univ.symm, λ i, image_comp (single i) (f i), span_single_image],
simp only [image_univ, (hf _).2, map_top, supr_lsingle_range] }
end
lemma is_basis_single_one : is_basis R (λ i : ι, single i (1 : R)) :=
by convert (is_basis_single (λ (i : ι) (x : unit), (1 : R)) (λ i, is_basis_singleton_one R)).comp
(λ i : ι, ⟨i, ()⟩) ⟨λ _ _, and.left ∘ sigma.mk.inj, λ ⟨i, ⟨⟩⟩, ⟨i, rfl⟩⟩
end ring
section comm_ring
variables {R : Type*} {M : Type*} {N : Type*} {ι : Type*} {κ : Type*}
variables [comm_ring R] [add_comm_group M] [module R M] [add_comm_group N] [module R N]
/-- If b : ι → M and c : κ → N are bases then so is λ i, b i.1 ⊗ₜ c i.2 : ι × κ → M ⊗ N. -/
lemma is_basis.tensor_product {b : ι → M} (hb : is_basis R b) {c : κ → N} (hc : is_basis R c) :
is_basis R (λ i : ι × κ, b i.1 ⊗ₜ[R] c i.2) :=
by { convert linear_equiv.is_basis is_basis_single_one
((tensor_product.congr (module_equiv_finsupp hb) (module_equiv_finsupp hc)).trans $
(finsupp_tensor_finsupp _ _ _ _ _).trans $
lcongr (equiv.refl _) (tensor_product.lid R R)).symm,
ext ⟨i, k⟩, rw [function.comp_apply, linear_equiv.eq_symm_apply], simp }
end comm_ring
section dim
universes u v
variables {K : Type u} {V : Type v} {ι : Type v}
variables [field K] [add_comm_group V] [vector_space K V]
lemma dim_eq : vector_space.dim K (ι →₀ V) = cardinal.mk ι * vector_space.dim K V :=
begin
rcases exists_is_basis K V with ⟨bs, hbs⟩,
rw [← cardinal.lift_inj, cardinal.lift_mul, ← hbs.mk_eq_dim,
← (is_basis_single _ (λa:ι, hbs)).mk_eq_dim, ← cardinal.sum_mk,
← cardinal.lift_mul, cardinal.lift_inj],
{ simp only [cardinal.mk_image_eq (single_injective.{u u} _), cardinal.sum_const] }
end
end dim
end finsupp
section vector_space
/- We use `universe variables` instead of `universes` here because universes introduced by the
`universes` keyword do not get replaced by metavariables once a lemma has been proven. So if you
prove a lemma using universe `u`, you can only apply it to universe `u` in other lemmas of the
same section. -/
universe variables u v w
variables {K : Type u} {V V₁ V₂ : Type v} {V' : Type w}
variables [field K]
variables [add_comm_group V] [vector_space K V]
variables [add_comm_group V₁] [vector_space K V₁]
variables [add_comm_group V₂] [vector_space K V₂]
variables [add_comm_group V'] [vector_space K V']
open vector_space
lemma equiv_of_dim_eq_lift_dim
(h : cardinal.lift.{v w} (dim K V) = cardinal.lift.{w v} (dim K V')) :
nonempty (V ≃ₗ[K] V') :=
begin
haveI := classical.dec_eq V,
haveI := classical.dec_eq V',
rcases exists_is_basis K V with ⟨m, hm⟩,
rcases exists_is_basis K V' with ⟨m', hm'⟩,
rw [←cardinal.lift_inj.1 hm.mk_eq_dim, ←cardinal.lift_inj.1 hm'.mk_eq_dim] at h,
rcases quotient.exact h with ⟨e⟩,
let e := (equiv.ulift.symm.trans e).trans equiv.ulift,
exact ⟨((module_equiv_finsupp hm).trans
(finsupp.dom_lcongr e)).trans
(module_equiv_finsupp hm').symm⟩,
end
/-- Two `K`-vector spaces are equivalent if their dimension is the same. -/
def equiv_of_dim_eq_dim (h : dim K V₁ = dim K V₂) : V₁ ≃ₗ[K] V₂ :=
begin
classical,
exact classical.choice (equiv_of_dim_eq_lift_dim (cardinal.lift_inj.2 h))
end
/-- An `n`-dimensional `K`-vector space is equivalent to `fin n → K`. -/
def fin_dim_vectorspace_equiv (n : ℕ)
(hn : (dim K V) = n) : V ≃ₗ[K] (fin n → K) :=
begin
have : cardinal.lift.{v u} (n : cardinal.{v}) = cardinal.lift.{u v} (n : cardinal.{u}),
by simp,
have hn := cardinal.lift_inj.{v u}.2 hn,
rw this at hn,
rw ←@dim_fin_fun K _ n at hn,
exact classical.choice (equiv_of_dim_eq_lift_dim hn),
end
lemma eq_bot_iff_dim_eq_zero (p : submodule K V) (h : dim K p = 0) : p = ⊥ :=
begin
have : dim K p = dim K (⊥ : submodule K V) := by rwa [dim_bot],
let e := equiv_of_dim_eq_dim this,
exact e.eq_bot_of_equiv _
end
lemma injective_of_surjective (f : V₁ →ₗ[K] V₂)
(hV₁ : dim K V₁ < cardinal.omega) (heq : dim K V₂ = dim K V₁) (hf : f.range = ⊤) : f.ker = ⊥ :=
have hk : dim K f.ker < cardinal.omega := lt_of_le_of_lt (dim_submodule_le _) hV₁,
begin
rcases cardinal.lt_omega.1 hV₁ with ⟨d₁, eq₁⟩,
rcases cardinal.lt_omega.1 hk with ⟨d₂, eq₂⟩,
have : 0 = d₂,
{ have := dim_eq_of_surjective f (linear_map.range_eq_top.1 hf),
rw [heq, eq₁, eq₂, ← nat.cast_add, cardinal.nat_cast_inj] at this,
exact nat.add_left_cancel this },
refine eq_bot_iff_dim_eq_zero _ _,
rw [eq₂, ← this, nat.cast_zero]
end
end vector_space
section vector_space
universes u
open vector_space
variables {K V : Type u} [field K] [add_comm_group V] [vector_space K V]
lemma cardinal_mk_eq_cardinal_mk_field_pow_dim (h : dim K V < cardinal.omega) :
cardinal.mk V = cardinal.mk K ^ dim K V :=
begin
rcases exists_is_basis K V with ⟨s, hs⟩,
have : nonempty (fintype s),
{ rwa [← cardinal.lt_omega_iff_fintype, cardinal.lift_inj.1 hs.mk_eq_dim] },
cases this with hsf, letI := hsf,
calc cardinal.mk V = cardinal.mk (s →₀ K) : quotient.sound ⟨(module_equiv_finsupp hs).to_equiv⟩
... = cardinal.mk (s → K) : quotient.sound ⟨finsupp.equiv_fun_on_fintype⟩
... = _ : by rw [← cardinal.lift_inj.1 hs.mk_eq_dim, cardinal.power_def]
end
lemma cardinal_lt_omega_of_dim_lt_omega [fintype K] (h : dim K V < cardinal.omega) :
cardinal.mk V < cardinal.omega :=
begin
rw [cardinal_mk_eq_cardinal_mk_field_pow_dim h],
exact cardinal.power_lt_omega (cardinal.lt_omega_iff_fintype.2 ⟨infer_instance⟩) h
end
end vector_space
|
8aef4cab6dc55a7dc8ee09760b7f481fa3a97a90 | 5d76f062116fa5bd22eda20d6fd74da58dba65bb | /src/polynomial_tactic_test.lean | 0ae84a1cdca6b8f4fdfdfe06aae5c5284fa0b37b | [] | no_license | brando90/formal_baby_snark | 59e4732dfb43f97776a3643f2731262f58d2bb81 | 4732da237784bd461ff949729cc011db83917907 | refs/heads/master | 1,682,650,246,414 | 1,621,103,975,000 | 1,621,103,975,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 642 | lean | import polynomial_tactic
open_locale big_operators
section
open mv_polynomial
noncomputable theory
universes u
/-- The finite field parameter of our SNARK -/
parameter {F : Type u}
parameter [field F]
@[derive decidable_eq]
inductive vars : Type
| x : vars
| y : vars
| z : vars
def my_polynomial : mv_polynomial vars F := (X vars.x + X vars.y + 2 * X vars.z) * (X vars.x + X vars.y + 2 * X vars.z)
example : coeff (finsupp.single vars.z 1 + finsupp.single vars.y 1) my_polynomial = 4 :=
begin
rw my_polynomial,
simp only with coeff_simp,
-- TODO you can probably take queues from what you do in the babysnark file
end
end |
26663692accf6b523ae790becbbc6750e50aa435 | d1a52c3f208fa42c41df8278c3d280f075eb020c | /stage0/src/Lean/Compiler/NameMangling.lean | 3a763657f227b6c13cd58d6a1cbe3f5179b2c21c | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 1,930 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import Lean.Data.Name
namespace String
private def mangleAux : Nat → String.Iterator → String → String
| 0, it, r => r
| i+1, it, r =>
let c := it.curr
if c.isAlpha || c.isDigit then
mangleAux i it.next (r.push c)
else if c = '_' then
mangleAux i it.next (r ++ "__")
else if c.toNat < 0x100 then
let n := c.toNat
let r := r ++ "_x"
let r := r.push $ Nat.digitChar (n / 0x10)
let r := r.push $ Nat.digitChar (n % 0x10)
mangleAux i it.next r
else if c.toNat < 0x10000 then
let n := c.toNat
let r := r ++ "_u"
let r := r.push $ Nat.digitChar (n / 0x1000)
let n := n % 0x1000
let r := r.push $ Nat.digitChar (n / 0x100)
let n := n % 0x100
let r := r.push $ Nat.digitChar (n / 0x10)
let r := r.push $ Nat.digitChar (n % 0x10)
mangleAux i it.next r
else
let n := c.toNat
let r := r ++ "_U"
let ds := Nat.toDigits 16 n
let r := Nat.repeat (·.push '0') (8 - ds.length) r
let r := ds.foldl (fun r c => r.push c) r
mangleAux i it.next r
def mangle (s : String) : String :=
mangleAux s.length s.mkIterator ""
end String
namespace Lean
private def Name.mangleAux : Name → String
| Name.anonymous => ""
| Name.str p s _ =>
let m := String.mangle s
match p with
| Name.anonymous => m
| p => mangleAux p ++ "_" ++ m
| Name.num p n _ => mangleAux p ++ "_" ++ toString n ++ "_"
@[export lean_name_mangle]
def Name.mangle (n : Name) (pre : String := "l_") : String :=
pre ++ Name.mangleAux n
@[export lean_mk_module_initialization_function_name]
def mkModuleInitializationFunctionName (moduleName : Name) : String :=
"initialize_" ++ moduleName.mangle ""
end Lean
|
e15586071ba1c24c0b6963b30192efc4641eaaf7 | 4d3f29a7b2eff44af8fd0d3176232e039acb9ee3 | /Mathlib/Mathlib/Tactic/NormNum.lean | e38fea730579d7f3896ac92eeb14f4be6984abfd | [] | no_license | marijnheule/lamr | 5fc5d69d326ff92e321242cfd7f72e78d7f99d7e | 28cc4114c7361059bb54f407fa312bf38b48728b | refs/heads/main | 1,689,338,013,620 | 1,630,359,632,000 | 1,630,359,632,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,277 | lean | /-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Lean.Elab.Tactic.Basic
import Mathlib.Algebra.Ring.Basic
import Mathlib.Tactic.Core
namespace Lean
/--
Return true if `e` is one of the following
- A nat literal (numeral)
- `Nat.zero`
- `Nat.succ x` where `isNumeral x`
- `OfNat.ofNat _ x _` where `isNumeral x` -/
partial def Expr.numeral? (e : Expr) : Option Nat :=
if let some n := e.natLit? then n
else
let f := e.getAppFn
if !f.isConst then none
else
let fName := f.constName!
if fName == ``Nat.succ && e.getAppNumArgs == 1 then (numeral? e.appArg!).map Nat.succ
else if fName == ``OfNat.ofNat && e.getAppNumArgs == 3 then numeral? (e.getArg! 1)
else if fName == ``Nat.zero && e.getAppNumArgs == 0 then some 0
else none
namespace Meta
def mkOfNatLit (u : Level) (α sα n : Expr) : Expr :=
let inst := mkApp3 (mkConst ``Numeric.OfNat [u]) α n sα
mkApp3 (mkConst ``OfNat.ofNat [u]) α n inst
namespace NormNum
theorem ofNat_nat (n : ℕ) : n = @OfNat.ofNat _ n (@Numeric.OfNat _ _ _) := rfl
set_option pp.all true
theorem ofNat_add {α} [Semiring α] : (a b : α) → (a' b' c : Nat) →
a = OfNat.ofNat a' → b = OfNat.ofNat b' → a' + b' = c → a + b = OfNat.ofNat c
| _, _, _, _, _, rfl, rfl, rfl => (Semiring.ofNat_add _ _).symm
theorem ofNat_mul {α} [Semiring α] : (a b : α) → (a' b' c : Nat) →
a = OfNat.ofNat a' → b = OfNat.ofNat b' → a' * b' = c → a * b = OfNat.ofNat c
| _, _, _, _, _, rfl, rfl, rfl => (Semiring.ofNat_mul _ _).symm
theorem ofNat_pow {α} [Semiring α] : (a : α) → (n a' c : Nat) →
a = OfNat.ofNat a' → a'^n = c → a ^ n = OfNat.ofNat c
| _, _, _, _, rfl, rfl => (Semiring.ofNat_pow _ _).symm
partial def eval' (e : Expr) : MetaM (Expr × Expr) := do
match e.getAppFnArgs with
| (``HAdd.hAdd, #[_, _, α, _, a, b]) => evalBinOp ``NormNum.ofNat_add (·+·) α a b
| (``HMul.hMul, #[_, _, α, _, a, b]) => evalBinOp ``NormNum.ofNat_mul (·*·) α a b
| (``HPow.hPow, #[_, _, α, _, a, n]) => evalPow ``NormNum.ofNat_pow (·^·) α a n
| (``OfNat.ofNat, #[α, ln, _]) =>
match ← ln.natLit? with
| some 0 =>
let Level.succ u _ ← getLevel α | throwError "fail"
let nα ← synthInstance (mkApp (mkConst ``Numeric [u]) α)
let sα ← synthInstance (mkApp (mkConst ``Semiring [u]) α)
let e ← mkOfNatLit u α nα (mkRawNatLit 0)
let p ← mkEqSymm (mkApp2 (mkConst ``Semiring.ofNat_zero [u]) α sα)
(e, p)
| some 1 =>
let Level.succ u _ ← getLevel α | throwError "fail"
let nα ← synthInstance (mkApp (mkConst ``Numeric [u]) α)
let sα ← synthInstance (mkApp (mkConst ``Semiring [u]) α)
let e ← mkOfNatLit u α nα (mkRawNatLit 1)
let p ← mkEqSymm (mkApp2 (mkConst ``Semiring.ofNat_one [u]) α sα)
(e, p)
| some _ => pure (e, ← mkEqRefl e)
| none => throwError "fail"
| _ =>
if e.isNatLit then
(mkOfNatLit levelZero (mkConst ``Nat) (mkConst ``Nat.instNumericNat) e,
mkApp (mkConst ``ofNat_nat) e)
else throwError "fail"
where
evalBinOp (name : Name) (f : Nat → Nat → Nat) (α a b : Expr) : MetaM (Expr × Expr) := do
let Level.succ u _ ← getLevel α | throwError "fail"
let nα ← synthInstance (mkApp (mkConst ``Numeric [u]) α)
let sα ← synthInstance (mkApp (mkConst ``Semiring [u]) α)
let (a', pa) ← eval' a
let (b', pb) ← eval' b
let la := Expr.getRevArg! a' 1
let lb := Expr.getRevArg! b' 1
let lc := mkRawNatLit (f la.natLit! lb.natLit!)
let c := mkOfNatLit u α nα lc
(c, mkApp10 (mkConst name [u]) α sα a b la lb lc pa pb (← mkEqRefl lc))
evalPow (name : Name) (f : Nat → Nat → Nat) (α a n : Expr) : MetaM (Expr × Expr) := do
let Level.succ u _ ← getLevel α | throwError "fail"
let nα ← synthInstance (mkApp (mkConst ``Numeric [u]) α)
let sα ← synthInstance (mkApp (mkConst ``Semiring [u]) α)
let (a', pa) ← eval' a
let la := Expr.getRevArg! a' 1
let some nn ← n.numeral? | throwError "fail"
let lc := mkRawNatLit (f la.natLit! nn)
let c := mkOfNatLit u α nα lc
(c, mkApp8 (mkConst name [u]) α sα a n la lc pa (← mkEqRefl lc))
def eval (e : Expr) : MetaM (Expr × Expr) := do
let (e', p) ← eval' e
e'.withApp fun f args => do
if f.isConstOf ``OfNat.ofNat then
let #[α,ln,_] ← args | throwError "fail"
let some n ← ln.natLit? | throwError "fail"
if n = 0 then
let Level.succ u _ ← getLevel α | throwError "fail"
let sα ← synthInstance (mkApp (mkConst ``Semiring [u]) α)
let nα ← synthInstance (mkApp2 (mkConst ``OfNat [u]) α (mkRawNatLit 0))
let e'' ← mkApp3 (mkConst ``OfNat.ofNat [u]) α (mkRawNatLit 0) nα
let p' ← mkEqTrans p (mkApp2 (mkConst ``Semiring.ofNat_zero [u]) α sα)
(e'', p')
else if n = 1 then
let Level.succ u _ ← getLevel α | throwError "fail"
let sα ← synthInstance (mkApp (mkConst ``Semiring [u]) α)
let nα ← synthInstance (mkApp2 (mkConst ``OfNat [u]) α (mkRawNatLit 1))
let e'' ← mkApp3 (mkConst ``OfNat.ofNat [u]) α (mkRawNatLit 1) nα
let p' ← mkEqTrans p (mkApp2 (mkConst ``Semiring.ofNat_one [u]) α sα)
(e'', p')
else (e', p)
else (e', p)
end NormNum
end Meta
syntax (name := Parser.Tactic.normNum) "normNum" : tactic
open Meta Elab Tactic
@[tactic normNum] def Tactic.evalNormNum : Tactic := fun stx =>
liftMetaTactic fun g => do
let some (α, lhs, rhs) ← matchEq? (← getMVarType g) | throwError "fail"
let (lhs₂, lp) ← NormNum.eval' lhs
let (rhs₂, rp) ← NormNum.eval' rhs
unless ← isDefEq lhs₂ rhs₂ do throwError "fail"
let p ← mkEqTrans lp (← mkEqSymm rp)
assignExprMVar g p
pure []
end Lean
variable (α) [Semiring α]
example : (1 + 0 : α) = (0 + 1 : α) := by normNum
example : (0 + (2 + 3) + 1 : α) = 6 := by normNum
example : (70 * (33 + 2) : α) = 2450 := by normNum
example : (8 + 2 ^ 2 * 3 : α) = 20 := by normNum
example : ((2 * 1 + 1) ^ 2 : α) = (3 * 3 : α) := by normNum
|
a5c99a5b6c4f99eed4f169fa3a6f892485200444 | 98e19516c8c6ccdcd3b092955d47773a0aaabf7b | /test/bench/lean/rbtree.lean | 11412470691efdbf9783ab1453ce40703cb464ad | [
"Apache-2.0"
] | permissive | koka-lang/koka | d31daf7d06b28ea7b1fc8084cc76cdf5459610b6 | b3122869ac74bfb6f432f7e76eeb723b1f69a491 | refs/heads/master | 1,693,461,288,476 | 1,688,408,308,000 | 1,688,408,308,000 | 75,982,258 | 2,806 | 154 | NOASSERTION | 1,689,870,454,000 | 1,481,238,037,000 | Haskell | UTF-8 | Lean | false | false | 2,887 | 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
-/
prelude
import Init.Coe
import Init.Data.Option.Basic
import Init.Data.List.BasicAux
import Init.System.IO
universes u v w w'
inductive color
| Red | Black
inductive Tree
| Leaf {} : Tree
| Node (color : color) (lchild : Tree) (key : Nat) (val : Bool) (rchild : Tree) : Tree
/- variables {σ : Type w} -/
open color Nat Tree
def fold : (Nat → Bool → Nat → Nat) -> Tree → Nat → Nat
| f, Leaf, b => b
| f, Node _ l k v r, b => fold f r (f k v (fold f l b))
@[inline]
def balance1 : Nat → Bool → Tree → Tree → Tree
| kv, vv, t, Node _ (Node Red l kx vx r₁) ky vy r₂ => Node Red (Node Black l kx vx r₁) ky vy (Node Black r₂ kv vv t)
| kv, vv, t, Node _ l₁ ky vy (Node Red l₂ kx vx r) => Node Red (Node Black l₁ ky vy l₂) kx vx (Node Black r kv vv t)
| kv, vv, t, Node _ l ky vy r => Node Black (Node Red l ky vy r) kv vv t
| _, _, _, _ => Leaf
@[inline]
def balance2 : Tree → Nat → Bool → Tree → Tree
| t, kv, vv, Node _ (Node Red l kx₁ vx₁ r₁) ky vy r₂ => Node Red (Node Black t kv vv l) kx₁ vx₁ (Node Black r₁ ky vy r₂)
| t, kv, vv, Node _ l₁ ky vy (Node Red l₂ kx₂ vx₂ r₂) => Node Red (Node Black t kv vv l₁) ky vy (Node Black l₂ kx₂ vx₂ r₂)
| t, kv, vv, Node _ l ky vy r => Node Black t kv vv (Node Red l ky vy r)
| _, _, _, _ => Leaf
def isRed : Tree → Bool
| Node Red _ _ _ _ => true
| _ => false
def ins : Tree → Nat → Bool → Tree
| Leaf, kx, vx => Node Red Leaf kx vx Leaf
| Node Red a ky vy b, kx, vx =>
(if kx < ky then Node Red (ins a kx vx) ky vy b
else if kx = ky then Node Red a kx vx b
else Node Red a ky vy (ins b kx vx))
| Node Black a ky vy b, kx, vx =>
if kx < ky then
(if isRed a then balance1 ky vy b (ins a kx vx)
else Node Black (ins a kx vx) ky vy b)
else if kx = ky then Node Black a kx vx b
else if isRed b then balance2 a ky vy (ins b kx vx)
else Node Black a ky vy (ins b kx vx)
def setBlack : Tree → Tree
| Node _ l k v r => Node Black l k v r
| e => e
def insert (t : Tree) (k : Nat) (v : Bool) : Tree :=
if isRed t then setBlack (ins t k v)
else ins t k v
def mkMapAux : Nat → Tree → Tree
| 0, m => m
| n+1, m => mkMapAux n (insert m n (n % 10 = 0))
def mkMap (n : Nat) :=
mkMapAux n Leaf
def main : IO UInt32 :=
let m := mkMap (4200000);
let v := fold (fun (k : Nat) (v : Bool) (r : Nat) => if v then r + 1 else r) m 0;
IO.println (toString v) *>
pure 0
|
f05d3999b2ab99fcb5160b727a41f1042673124d | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /src/Init/Data/Option/Basic.lean | ae88231c3a9b2b56c9f1fe9763bc89671d38d166 | [
"Apache-2.0"
] | permissive | williamdemeo/lean4 | 72161c58fe65c3ad955d6a3050bb7d37c04c0d54 | 6d00fcf1d6d873e195f9220c668ef9c58e9c4a35 | refs/heads/master | 1,678,305,356,877 | 1,614,708,995,000 | 1,614,708,995,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,439 | 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
-/
prelude
import Init.Core
import Init.Control.Basic
import Init.Coe
namespace Option
def toMonad [Monad m] [Alternative m] : Option α → m α
| none => failure
| some a => pure a
@[macroInline] def getD : Option α → α → α
| some x, _ => x
| none, e => e
@[inline] def toBool : Option α → Bool
| some _ => true
| none => false
@[inline] def isSome : Option α → Bool
| some _ => true
| none => false
@[inline] def isNone : Option α → Bool
| some _ => false
| none => true
@[inline] protected def bind : Option α → (α → Option β) → Option β
| none, b => none
| some a, b => b a
@[inline] protected def map (f : α → β) (o : Option α) : Option β :=
Option.bind o (some ∘ f)
theorem mapId : (Option.map id : Option α → Option α) = id :=
funext (fun o => match o with | none => rfl | some x => rfl)
instance : Monad Option := {
pure := some
bind := Option.bind
map := Option.map
}
@[inline] protected def filter (p : α → Bool) : Option α → Option α
| some a => if p a then some a else none
| none => none
@[inline] protected def all (p : α → Bool) : Option α → Bool
| some a => p a
| none => true
@[inline] protected def any (p : α → Bool) : Option α → Bool
| some a => p a
| none => false
@[macroInline] protected def orElse : Option α → Option α → Option α
| some a, _ => some a
| none, b => b
/- Remark: when using the polymorphic notation `a <|> b` is not a `[macroInline]`.
Thus, `a <|> b` will make `Option.orelse` to behave like it was marked as `[inline]`. -/
instance : Alternative Option where
failure := none
orElse := Option.orElse
@[inline] protected def lt (r : α → α → Prop) : Option α → Option α → Prop
| none, some x => True
| some x, some y => r x y
| _, _ => False
instance (r : α → α → Prop) [s : DecidableRel r] : DecidableRel (Option.lt r)
| none, some y => isTrue trivial
| some x, some y => s x y
| some x, none => isFalse notFalse
| none, none => isFalse notFalse
end Option
deriving instance DecidableEq for Option
deriving instance BEq for Option
instance [HasLess α] : HasLess (Option α) := {
Less := Option.lt (· < ·)
}
|
1ddb239194533d0682bde32c6982b69e21c737e3 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /src/Init/Lean/Delaborator.lean | 5f8a01919e38aa98523f2a15b579c52f2f54d742 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 17,214 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
-/
/-!
The delaborator is the first stage of the pretty printer, and the inverse of the
elaborator: it turns fully elaborated `Expr` core terms back into surface-level
`Syntax`, omitting some implicit information again and using higher-level syntax
abstractions like notations where possible. The exact behavior can be customized
using pretty printer options; activating `pp.all` should guarantee that the
delaborator is injective and that re-elaborating the resulting `Syntax`
round-trips.
Pretty printer options can be given not only for the whole term, but also
specific subterms. This is used both when automatically refining pp options
until round-trip and when interactively selecting pp options for a subterm (both
TBD). The association of options to subterms is done by assigning a unique,
synthetic Nat position to each subterm derived from its position in the full
term. This position is added to the corresponding Syntax object so that
elaboration errors and interactions with the pretty printer output can be traced
back to the subterm.
The delaborator is extensible via the `[delab]` attribute.
-/
prelude
import Init.Lean.KeyedDeclsAttribute
import Init.Lean.ProjFns
import Init.Lean.Syntax
namespace Lean
-- TODO: move, maybe
namespace Level
protected partial def quote : Level → Syntax
| zero _ => Unhygienic.run `(level|0)
| l@(succ _ _) => match l.toNat with
| some n => Unhygienic.run `(level|$(mkStxNumLitAux n):numLit)
| none => Unhygienic.run `(level|$(quote l.getLevelOffset) + $(mkStxNumLitAux l.getOffset):numLit)
| max l1 l2 _ => match_syntax quote l2 with
| `(level|max $ls*) => Unhygienic.run `(level|max $(quote l1) $ls*)
| l2 => Unhygienic.run `(level|max $(quote l1) $l2)
| imax l1 l2 _ => match_syntax quote l2 with
| `(level|imax $ls*) => Unhygienic.run `(level|imax $(quote l1) $ls*)
| l2 => Unhygienic.run `(level|imax $(quote l1) $l2)
| param n _ => Unhygienic.run `(level|$(mkIdent n):ident)
-- HACK: approximation
| mvar n _ => Unhygienic.run `(level|_)
instance HasQuote : HasQuote Level := ⟨Level.quote⟩
end Level
def getPPBinderTypes (o : Options) : Bool := o.get `pp.binder_types true
def getPPCoercions (o : Options) : Bool := o.get `pp.coercions true
def getPPExplicit (o : Options) : Bool := o.get `pp.explicit false
def getPPStructureProjections (o : Options) : Bool := o.get `pp.structure_projections true
def getPPUniverses (o : Options) : Bool := o.get `pp.universes false
def getPPAll (o : Options) : Bool := o.get `pp.all false
@[init] def ppOptions : IO Unit := do
registerOption `pp.explicit { defValue := false, group := "pp", descr := "(pretty printer) display implicit arguments" };
-- TODO: register other options when old pretty printer is removed
--registerOption `pp.universes { defValue := false, group := "pp", descr := "(pretty printer) display universes" };
pure ()
/-- Associate pretty printer options to a specific subterm using a synthetic position. -/
abbrev OptionsPerPos := RBMap Nat Options (fun a b => a < b)
namespace Delaborator
open Lean.Meta
structure Context :=
-- In contrast to other systems like the elaborator, we do not pass the current term explicitly as a
-- parameter, but store it in the monad so that we can keep it in sync with `pos`.
(expr : Expr)
(pos : Nat := 1)
(defaultOptions : Options)
(optionsPerPos : OptionsPerPos)
-- Exceptions from delaborators are not expected, so use a simple `OptionT` to signal whether
-- the delaborator was able to produce a Syntax object.
abbrev DelabM := ReaderT Context $ OptionT MetaM
abbrev Delab := DelabM Syntax
instance DelabM.inhabited {α} : Inhabited (DelabM α) := ⟨failure⟩
-- Macro scopes in the delaborator output are ultimately ignored by the pretty printer,
-- so give a trivial implementation.
instance DelabM.monadQuotation : MonadQuotation DelabM := {
getCurrMacroScope := pure $ arbitrary _,
getMainModule := pure $ arbitrary _,
withFreshMacroScope := fun α x => x,
}
unsafe def mkDelabAttribute : IO (KeyedDeclsAttribute Delab) :=
KeyedDeclsAttribute.init {
builtinName := `builtinDelab,
name := `delab,
descr := "Register a delaborator.
[delab k] registers a declaration of type `Lean.Delaborator.Delab` for the `Lean.Expr`
constructor `k`. Multiple delaborators for a single constructor are tried in turn until
the first success. If the term to be delaborated is an application of a constant `c`,
elaborators for `app.c` are tried first; this is also done for `Expr.const`s (\"nullary applications\")
to reduce special casing. If the term is an `Expr.mdata` with a single key `k`, `mdata.k`
is tried first.",
valueTypeName := `Lean.Delaborator.Delab
} `Lean.Delaborator.delabAttribute
@[init mkDelabAttribute] constant delabAttribute : KeyedDeclsAttribute Delab := arbitrary _
def getExpr : DelabM Expr := do
ctx ← read;
pure ctx.expr
def getExprKind : DelabM Name := do
e ← getExpr;
pure $ match e with
| Expr.bvar _ _ => `bvar
| Expr.fvar _ _ => `fvar
| Expr.mvar _ _ => `mvar
| Expr.sort _ _ => `sort
| Expr.const c _ _ =>
-- we identify constants as "nullary applications" to reduce special casing
`app ++ c
| Expr.app fn _ _ => match fn.getAppFn with
| Expr.const c _ _ => `app ++ c
| _ => `app
| Expr.lam _ _ _ _ => `lam
| Expr.forallE _ _ _ _ => `forallE
| Expr.letE _ _ _ _ _ => `letE
| Expr.lit _ _ => `lit
| Expr.mdata m _ _ => match m.entries with
| [(key, _)] => `mdata ++ key
| _ => `mdata
| Expr.proj _ _ _ _ => `proj
| Expr.localE _ _ _ _ => `localE
/-- Evaluate option accessor, using subterm-specific options if set. Default to `true` if `pp.all` is set. -/
def getPPOption (opt : Options → Bool) : DelabM Bool := do
ctx ← read;
let opt := fun opts => opt opts || getPPAll opts;
let val := opt ctx.defaultOptions;
match ctx.optionsPerPos.find? ctx.pos with
| some opts => pure $ opt opts
| none => pure val
def whenPPOption (opt : Options → Bool) (d : Delab) : Delab := do
b ← getPPOption opt;
if b then d else failure
def whenNotPPOption (opt : Options → Bool) (d : Delab) : Delab := do
b ← getPPOption opt;
if b then failure else d
/--
Descend into `child`, the `childIdx`-th subterm of the current term, and update position.
Because `childIdx < 3` in the case of `Expr`, we can injectively map a path
`childIdxs` to a natural number by computing the value of the 3-ary representation
`1 :: childIdxs`, since n-ary representations without leading zeros are unique.
Note that `pos` is initialized to `1` (case `childIdxs == []`).
-/
def descend {α} (child : Expr) (childIdx : Nat) (d : DelabM α) : DelabM α :=
adaptReader (fun (cfg : Context) => { cfg with expr := child, pos := cfg.pos * 3 + childIdx }) d
def withAppFn {α} (d : DelabM α) : DelabM α := do
Expr.app fn _ _ ← getExpr | unreachable!;
descend fn 0 d
def withAppArg {α} (d : DelabM α) : DelabM α := do
Expr.app _ arg _ ← getExpr | unreachable!;
descend arg 1 d
partial def withAppFnArgs {α} : DelabM α → (α → DelabM α) → DelabM α
| fnD, argD => do
Expr.app fn arg _ ← getExpr | fnD;
a ← withAppFn (withAppFnArgs fnD argD);
withAppArg (argD a)
def withBindingDomain {α} (d : DelabM α) : DelabM α := do
e ← getExpr;
descend e.bindingDomain! 0 d
def withBindingBody {α} (n : Name) (d : DelabM α) : DelabM α := do
e ← getExpr;
fun ctx => withLocalDecl n e.bindingDomain! e.binderInfo $ fun fvar =>
let b := e.bindingBody!.instantiate1 fvar;
descend b 1 d ctx
def withProj {α} (d : DelabM α) : DelabM α := do
Expr.app fn _ _ ← getExpr | unreachable!;
descend fn 0 d
def infoForPos (pos : Nat) : SourceInfo :=
{ leading := " ".toSubstring, pos := pos, trailing := " ".toSubstring }
partial def annotatePos (pos : Nat) : Syntax → Syntax
| stx@(Syntax.ident _ _ _ _) => stx.setInfo (infoForPos pos)
-- Term.ids => annotate ident
-- TODO: universes?
| stx@(Syntax.node `Lean.Parser.Term.id args) => stx.modifyArg 0 annotatePos
-- app => annotate function
| stx@(Syntax.node `Lean.Parser.Term.app args) => stx.modifyArg 0 annotatePos
-- otherwise, annotate first direct child token if any
| stx => match stx.getArgs.findIdx? Syntax.isAtom with
| some idx => stx.modifyArg idx (Syntax.setInfo (infoForPos pos))
| none => stx
def annotateCurPos (stx : Syntax) : Delab := do
ctx ← read;
pure $ annotatePos ctx.pos stx
partial def delabFor : Name → Delab
| k => do
env ← liftM getEnv;
(match (delabAttribute.ext.getState env).table.find? k with
| some delabs => delabs.firstM id >>= annotateCurPos
| none => failure) <|>
(match k with
| Name.str Name.anonymous _ _ => failure
| Name.str n _ _ => delabFor n.getRoot -- have `app.Option.some` fall back to `app` etc.
| _ => failure)
def delab : Delab := do
k ← getExprKind;
delabFor k <|> (liftM $ show MetaM Syntax from throw $ Meta.Exception.other $ "don't know how to delaborate '" ++ toString k ++ "'")
@[builtinDelab fvar]
def delabFVar : Delab := do
Expr.fvar id _ ← getExpr | unreachable!;
l ← liftM $ getLocalDecl id;
pure $ mkTermId l.userName
@[builtinDelab mvar]
def delabMVar : Delab := do
Expr.mvar n _ ← getExpr | unreachable!;
`(?$(mkIdent n))
@[builtinDelab sort]
def delabSort : Delab := do
expr ← getExpr;
match expr with
| Expr.sort (Level.zero _) _ => `(Prop)
| Expr.sort (Level.succ (Level.zero _) _) _ => `(Type)
| Expr.sort l _ => match l.dec with
| some l' => `(Type $(quote l'))
| none => `(Sort $(quote l))
| _ => unreachable!
-- NOTE: not a registered delaborator, as `const` is never called (see [delab] description)
def delabConst : Delab := do
Expr.const c ls _ ← getExpr | unreachable!;
ppUnivs ← getPPOption getPPUniverses;
if ls.isEmpty || !ppUnivs then
`($(mkIdent c):ident)
else
`($(mkIdent c):ident.{$(ls.toArray.map quote)*})
/-- Return array with n-th element set to `true` iff n-th parameter of `e` is implicit. -/
def getImplicitParams (e : Expr) : MetaM (Array Bool) := do
t ← inferType e;
forallTelescopeReducing t $ fun params _ =>
params.mapM $ fun param => do
l ← getLocalDecl param.fvarId!;
pure (!l.binderInfo.isExplicit)
@[builtinDelab app]
def delabAppExplicit : Delab := do
(fnStx, argStxs) ← withAppFnArgs
(do
fn ← getExpr;
stx ← if fn.isConst then delabConst else delab;
implicitParams ← liftM $ getImplicitParams fn;
stx ← if implicitParams.any id then `(@$stx) else pure stx;
pure (stx, #[]))
(fun ⟨fnStx, argStxs⟩ => do
argStx ← delab;
pure (fnStx, argStxs.push argStx));
-- avoid degenerate `app` node
if argStxs.isEmpty then pure fnStx else `($fnStx $argStxs*)
@[builtinDelab app]
def delabAppImplicit : Delab := whenNotPPOption getPPExplicit $ do
(fnStx, _, argStxs) ← withAppFnArgs
(do
fn ← getExpr;
stx ← if fn.isConst then delabConst else delab;
implicitParams ← liftM $ getImplicitParams fn;
pure (stx, implicitParams.toList, #[]))
(fun ⟨fnStx, implicitParams, argStxs⟩ => match implicitParams with
| true :: implicitParams => pure (fnStx, implicitParams, argStxs)
| _ => do
argStx ← delab;
pure (fnStx, implicitParams.tailD [], argStxs.push argStx));
-- avoid degenerate `app` node
if argStxs.isEmpty then pure fnStx else `($fnStx $argStxs*)
/--
Return `true` iff current binder should be merged with the nested
binder, if any, into a single binder group:
* both binders must have same binder info and domain
* they cannot be inst-implicit (`[a b : A]` is not valid syntax)
* `pp.binder_types` must be the same value for both terms
* prefer `fun a b` over `fun (a b)`
-/
private def shouldGroupWithNext : DelabM Bool := do
e ← getExpr;
ppEType ← getPPOption getPPBinderTypes;
let go (e' : Expr) := do {
ppE'Type ← withBindingBody `_ $ getPPOption getPPBinderTypes;
pure $ e.binderInfo == e'.binderInfo &&
e.bindingDomain! == e'.bindingDomain! &&
e'.binderInfo != BinderInfo.instImplicit &&
ppEType == ppE'Type &&
(e'.binderInfo != BinderInfo.default || ppE'Type)
};
match e with
| Expr.lam _ _ e'@(Expr.lam _ _ _ _) _ => go e'
| Expr.forallE _ _ e'@(Expr.forallE _ _ _ _) _ => go e'
| _ => pure false
private partial def delabLamAux : Array Syntax → Array Syntax → Delab
-- Accumulate finished binder groups `(a b : Nat) (c : Bool) ...` and names
-- (`Syntax.ident`s with position information) of the current, unfinished
-- binder group `(d e ...)`.
| binderGroups, curNames => do
ppTypes ← getPPOption getPPBinderTypes;
e@(Expr.lam n t body _) ← getExpr | unreachable!;
lctx ← liftM $ getLCtx;
let n := lctx.getUnusedName n;
stxN ← annotateCurPos (mkIdent n);
let curNames := curNames.push stxN;
condM shouldGroupWithNext
-- group with nested binder => recurse immediately
(withBindingBody n $ delabLamAux binderGroups curNames) $
-- don't group => finish current binder group
do
stxT ← withBindingDomain delab;
group ← match e.binderInfo, ppTypes with
| BinderInfo.default, true => do
-- "default" binder group is the only one that expects binder names
-- as a term, i.e. a single `Term.id` or an application thereof
let curNames := curNames.map mkTermIdFromIdent;
stxCurNames ← if curNames.size > 1 then `($(curNames.get! 0) $(curNames.eraseIdx 0)*)
else pure $ curNames.get! 0;
`(funBinder| ($stxCurNames : $stxT))
| BinderInfo.default, false => pure $ mkTermIdFromIdent stxN -- here `curNames == #[stxN]`
| BinderInfo.implicit, true => `(funBinder| {$curNames* : $stxT})
| BinderInfo.implicit, false => `(funBinder| {$curNames*})
-- here `curNames == #[stxN]`
| BinderInfo.instImplicit, _ => `(funBinder| [$stxN : $stxT])
| _ , _ => unreachable!;
let binderGroups := binderGroups.push group;
withBindingBody n $
if body.isLambda then
delabLamAux binderGroups #[]
else do
stxBody ← delab;
`(@(fun $binderGroups* => $stxBody))
@[builtinDelab lam]
def delabExplicitLam : Delab :=
delabLamAux #[] #[]
-- TODO: implicit lambdas
@[builtinDelab lit]
def delabLit : Delab := do
Expr.lit l _ ← getExpr | unreachable!;
match l with
| Literal.natVal n => pure $ quote n
| Literal.strVal s => pure $ quote s
-- `ofNat 0` ~> `0`
@[builtinDelab app.HasOfNat.ofNat]
def delabOfNat : Delab := whenPPOption getPPCoercions $ do
e@(Expr.app _ (Expr.lit (Literal.natVal n) _) _) ← getExpr | failure;
pure $ quote n
/--
Delaborate a projection primitive. These do not usually occur in
user code, but are pretty-printed when e.g. `#print`ing a projection
function.
-/
@[builtinDelab proj]
def delabProj : Delab := do
Expr.proj _ idx e _ ← getExpr | unreachable!;
e ← withProj delab;
-- not perfectly authentic: elaborates to the `idx`-th named projection
-- function (e.g. `e.1` is `Prod.fst e`), which unfolds to the actual
-- `proj`.
`($(e).$(mkStxNumLitAux idx):fieldIdx)
/-- Delaborate a call to a projection function such as `Prod.fst`. -/
@[builtinDelab app]
def delabProjectionApp : Delab := whenPPOption getPPStructureProjections $ do
e@(Expr.app fn _ _) ← getExpr | failure;
Expr.const c@(Name.str _ f _) _ _ ← pure fn.getAppFn | failure;
env ← liftM getEnv;
some info ← pure $ env.getProjectionFnInfo c | failure;
-- can't use with classes since the instance parameter is implicit
assert (!info.fromClass);
-- projection function should be fully applied (#struct params + 1 instance parameter)
-- TODO: support over-application
assert $ e.getAppNumArgs == info.nparams + 1;
-- If pp.explicit is true, and the structure has parameters, we should not
-- use field notation because we will not be able to see the parameters.
expl ← getPPOption getPPExplicit;
assert $ !expl || info.nparams == 0;
appStx ← withAppArg delab;
`($(appStx).$(mkIdent f):ident)
-- abbrev coe {α : Sort u} {β : Sort v} (a : α) [CoeT α a β] : β
@[builtinDelab app.coe]
def delabCoe : Delab := whenPPOption getPPCoercions $ do
e ← getExpr;
assert $ e.getAppNumArgs >= 4;
-- delab as application, then discard function
stx ← delabAppImplicit;
match_syntax stx with
| `($fn $args*) =>
if args.size == 1 then
pure $ args.get! 0
else
`($(args.get! 0) $(args.eraseIdx 0)*)
| _ => failure
-- abbrev coeFun {α : Sort u} {γ : α → Sort v} (a : α) [CoeFun α γ] : γ a
@[builtinDelab app.coeFun]
def delabCoeFun : Delab := delabCoe
end Delaborator
/-- "Delaborate" the given term into surface-level syntax using the given general and subterm-specific options. -/
def delab (e : Expr) (defaultOptions : Options) (optionsPerPos : OptionsPerPos := {}) : MetaM Syntax := do
some stx ← Delaborator.delab { expr := e, defaultOptions := defaultOptions, optionsPerPos := optionsPerPos }
| unreachable!;
pure stx
end Lean
|
202ae1dacd759bab2ae330bb1c581dd195327fc5 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/meta/injection_tactic.lean | 1eb7b67c15d521238378215a5378534a80646abc | [] | 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 | 1,193 | 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, Jannis Limperg
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.meta.tactic
namespace Mathlib
namespace tactic
/- Given a local constant `H : C x₁ ... xₙ = D y₁ ... yₘ`, where `C` and `D` are
fully applied constructors, `injection_with H ns base offset` does the
following:
- If `C ≠ D`, it solves the goal (using the no-confusion rule).
- If `C = D` (and thus `n = m`), it adds hypotheses
`h₁ : x₁ = y₁, ..., hₙ : xₙ = yₙ` to the local context. Names for the `hᵢ`
are taken from `ns`. If `ns` does not contain enough names, then the names
are derived from `base` and `offset` (by default `h_1`, `h_2` etc.; see
`intro_fresh`).
- Special case: if `C = D` and `n = 0` (i.e. the constructors have no
arguments), the hypothesis `h : true` is added to the context.
`injection_with` returns the new hypotheses and the leftover names from `ns`
(i.e. those names that were not used to name the new hypotheses). If (and only
if) the goal was solved, the list of new hypotheses is empty.
-/
|
ecaaec674f4a2911cf9c4ccd17d30d87827bcfb2 | d1a52c3f208fa42c41df8278c3d280f075eb020c | /src/Lean/Elab/Tactic/Delta.lean | 158d12abef2d7e5413a1630c1d9646b078b06cdd | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 1,398 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Tactic.Delta
import Lean.Elab.Tactic.Basic
import Lean.Elab.Tactic.Location
namespace Lean.Elab.Tactic
open Meta
def deltaLocalDecl (declName : Name) (fvarId : FVarId) : TacticM Unit := do
let mvarId ← getMainGoal
let localDecl ← getLocalDecl fvarId
let typeNew ← deltaExpand localDecl.type (. == declName)
if typeNew == localDecl.type then
throwTacticEx `delta mvarId m!"did not delta reduce '{declName}' at '{localDecl.userName}'"
replaceMainGoal [← replaceLocalDeclDefEq mvarId fvarId typeNew]
def deltaTarget (declName : Name) : TacticM Unit := do
let mvarId ← getMainGoal
let target ← getMainTarget
let targetNew ← deltaExpand target (. == declName)
if targetNew == target then
throwTacticEx `delta mvarId m!"did not delta reduce '{declName}'"
replaceMainGoal [← replaceTargetDefEq mvarId targetNew]
/--
"delta " ident (location)?
-/
@[builtinTactic Lean.Parser.Tactic.delta] def evalDelta : Tactic := fun stx => do
let declName ← resolveGlobalConstNoOverload stx[1]
let loc := expandOptLocation stx[2]
withLocation loc (deltaLocalDecl declName) (deltaTarget declName) (throwTacticEx `delta . m!"did not delta reduce '{declName}'")
end Lean.Elab.Tactic
|
f2374af51c53d4ebbb92cdc43567f3aaae5a88c2 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/quaternion.lean | f00c116fe91f626e186d6f65dadbb3c14dddc20f | [
"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 | 7,305 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Eric Wieser
-/
import algebra.quaternion
import analysis.inner_product_space.basic
import analysis.inner_product_space.pi_L2
import topology.algebra.algebra
/-!
# Quaternions as a normed algebra
In this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions:
* inner product space;
* normed ring;
* normed space over `ℝ`.
We show that the norm on `ℍ[ℝ]` agrees with the euclidean norm of its components.
## Notation
The following notation is available with `open_locale quaternion`:
* `ℍ` : quaternions
## Tags
quaternion, normed ring, normed space, normed algebra
-/
localized "notation (name := quaternion.real) `ℍ` := quaternion ℝ" in quaternion
open_locale real_inner_product_space
namespace quaternion
instance : has_inner ℝ ℍ := ⟨λ a b, (a * star b).re⟩
lemma inner_self (a : ℍ) : ⟪a, a⟫ = norm_sq a := rfl
lemma inner_def (a b : ℍ) : ⟪a, b⟫ = (a * star b).re := rfl
noncomputable instance : normed_add_comm_group ℍ :=
@inner_product_space.core.to_normed_add_comm_group ℝ ℍ _ _ _
{ to_has_inner := infer_instance,
conj_symm := λ x y, by simp [inner_def, mul_comm],
nonneg_re := λ x, norm_sq_nonneg,
definite := λ x, norm_sq_eq_zero.1,
add_left := λ x y z, by simp only [inner_def, add_mul, add_re],
smul_left := λ x y r, by simp [inner_def] }
noncomputable instance : inner_product_space ℝ ℍ :=
inner_product_space.of_core _
lemma norm_sq_eq_norm_sq (a : ℍ) : norm_sq a = ‖a‖ * ‖a‖ :=
by rw [← inner_self, real_inner_self_eq_norm_mul_norm]
instance : norm_one_class ℍ :=
⟨by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_one, real.sqrt_one]⟩
@[simp, norm_cast] lemma norm_coe (a : ℝ) : ‖(a : ℍ)‖ = ‖a‖ :=
by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_coe, real.sqrt_sq_eq_abs, real.norm_eq_abs]
@[simp, norm_cast] lemma nnnorm_coe (a : ℝ) : ‖(a : ℍ)‖₊ = ‖a‖₊ :=
subtype.ext $ norm_coe a
@[simp] lemma norm_star (a : ℍ) : ‖star a‖ = ‖a‖ :=
by simp_rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_star]
@[simp] lemma nnnorm_star (a : ℍ) : ‖star a‖₊ = ‖a‖₊ :=
subtype.ext $ norm_star a
noncomputable instance : normed_division_ring ℍ :=
{ dist_eq := λ _ _, rfl,
norm_mul' := λ a b, by { simp only [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_mul],
exact real.sqrt_mul norm_sq_nonneg _ } }
instance : normed_algebra ℝ ℍ :=
{ norm_smul_le := norm_smul_le,
to_algebra := (quaternion.algebra : algebra ℝ ℍ) }
instance : cstar_ring ℍ :=
{ norm_star_mul_self := λ x, (norm_mul _ _).trans $ congr_arg (* ‖x‖) (norm_star x) }
instance : has_coe ℂ ℍ := ⟨λ z, ⟨z.re, z.im, 0, 0⟩⟩
@[simp, norm_cast] lemma coe_complex_re (z : ℂ) : (z : ℍ).re = z.re := rfl
@[simp, norm_cast] lemma coe_complex_im_i (z : ℂ) : (z : ℍ).im_i = z.im := rfl
@[simp, norm_cast] lemma coe_complex_im_j (z : ℂ) : (z : ℍ).im_j = 0 := rfl
@[simp, norm_cast] lemma coe_complex_im_k (z : ℂ) : (z : ℍ).im_k = 0 := rfl
@[simp, norm_cast] lemma coe_complex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext; simp
@[simp, norm_cast] lemma coe_complex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext; simp
@[simp, norm_cast] lemma coe_complex_zero : ((0 : ℂ) : ℍ) = 0 := rfl
@[simp, norm_cast] lemma coe_complex_one : ((1 : ℂ) : ℍ) = 1 := rfl
@[simp, norm_cast] lemma coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z :=
by ext; simp
@[simp, norm_cast] lemma coe_complex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r := rfl
/-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/
def of_complex : ℂ →ₐ[ℝ] ℍ :=
{ to_fun := coe,
map_one' := rfl,
map_zero' := rfl,
map_add' := coe_complex_add,
map_mul' := coe_complex_mul,
commutes' := λ x, rfl }
@[simp] lemma coe_of_complex : ⇑of_complex = coe := rfl
/-- The norm of the components as a euclidean vector equals the norm of the quaternion. -/
lemma norm_pi_Lp_equiv_symm_equiv_tuple (x : ℍ) :
‖(pi_Lp.equiv 2 (λ _ : fin 4, _)).symm (equiv_tuple ℝ x)‖ = ‖x‖ :=
begin
rw [norm_eq_sqrt_real_inner, norm_eq_sqrt_real_inner, inner_self, norm_sq_def', pi_Lp.inner_apply,
fin.sum_univ_four],
simp_rw [is_R_or_C.inner_apply, star_ring_end_apply, star_trivial, ←sq],
refl,
end
/-- `quaternion_algebra.linear_equiv_tuple` as a `linear_isometry_equiv`. -/
@[simps apply symm_apply]
noncomputable def linear_isometry_equiv_tuple : ℍ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin 4) :=
{ to_fun := λ a, (pi_Lp.equiv _ (λ _ : fin 4, _)).symm ![a.1, a.2, a.3, a.4],
inv_fun := λ a, ⟨a 0, a 1, a 2, a 3⟩,
norm_map' := norm_pi_Lp_equiv_symm_equiv_tuple,
..(quaternion_algebra.linear_equiv_tuple (-1 : ℝ) (-1 : ℝ)).trans
(pi_Lp.linear_equiv 2 ℝ (λ _ : fin 4, ℝ)).symm }
@[continuity] lemma continuous_coe : continuous (coe : ℝ → ℍ) :=
continuous_algebra_map ℝ ℍ
@[continuity] lemma continuous_norm_sq : continuous (norm_sq : ℍ → ℝ) :=
by simpa [←norm_sq_eq_norm_sq]
using (continuous_norm.mul continuous_norm : continuous (λ q : ℍ, ‖q‖ * ‖q‖))
@[continuity] lemma continuous_re : continuous (λ q : ℍ, q.re) :=
(continuous_apply 0).comp linear_isometry_equiv_tuple.continuous
@[continuity] lemma continuous_im_i : continuous (λ q : ℍ, q.im_i) :=
(continuous_apply 1).comp linear_isometry_equiv_tuple.continuous
@[continuity] lemma continuous_im_j : continuous (λ q : ℍ, q.im_j) :=
(continuous_apply 2).comp linear_isometry_equiv_tuple.continuous
@[continuity] lemma continuous_im_k : continuous (λ q : ℍ, q.im_k) :=
(continuous_apply 3).comp linear_isometry_equiv_tuple.continuous
@[continuity] lemma continuous_im : continuous (λ q : ℍ, q.im) :=
by simpa only [←sub_self_re] using continuous_id.sub (continuous_coe.comp continuous_re)
instance : complete_space ℍ :=
begin
have : uniform_embedding linear_isometry_equiv_tuple.to_linear_equiv.to_equiv.symm :=
linear_isometry_equiv_tuple.to_continuous_linear_equiv.symm.uniform_embedding,
exact (complete_space_congr this).1 (by apply_instance)
end
section infinite_sum
variables {α : Type*}
@[simp, norm_cast] lemma has_sum_coe {f : α → ℝ} {r : ℝ} :
has_sum (λ a, (f a : ℍ)) (↑r : ℍ) ↔ has_sum f r :=
⟨λ h, by simpa only using
h.map (show ℍ →ₗ[ℝ] ℝ, from quaternion_algebra.re_lm _ _) continuous_re,
λ h, by simpa only using h.map (algebra_map ℝ ℍ) (continuous_algebra_map _ _)⟩
@[simp, norm_cast]
lemma summable_coe {f : α → ℝ} : summable (λ a, (f a : ℍ)) ↔ summable f :=
by simpa only using summable.map_iff_of_left_inverse (algebra_map ℝ ℍ)
(show ℍ →ₗ[ℝ] ℝ, from quaternion_algebra.re_lm _ _)
(continuous_algebra_map _ _) continuous_re coe_re
@[norm_cast] lemma tsum_coe (f : α → ℝ) : ∑' a, (f a : ℍ) = ↑(∑' a, f a) :=
begin
by_cases hf : summable f,
{ exact (has_sum_coe.mpr hf.has_sum).tsum_eq, },
{ simp [tsum_eq_zero_of_not_summable hf,
tsum_eq_zero_of_not_summable (summable_coe.not.mpr hf)] },
end
end infinite_sum
end quaternion
|
68d6a0ea60d7aa1e9d63f523ec41263456ec019b | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/algebra/support.lean | 9dec2b5e0b82a6441d798d285cfd473927708647 | [
"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 | 10,899 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import order.conditionally_complete_lattice
import algebra.big_operators.basic
import algebra.group.prod
import algebra.group.pi
import algebra.module.pi
/-!
# Support of a function
In this file we define `function.support f = {x | f x ≠ 0}` and prove its basic properties.
We also define `function.mul_support f = {x | f x ≠ 1}`.
-/
open set
open_locale big_operators
namespace function
variables {α β A B M N P R S G M₀ G₀ : Type*} {ι : Sort*}
section has_one
variables [has_one M] [has_one N] [has_one P]
/-- `support` of a function is the set of points `x` such that `f x ≠ 0`. -/
def support [has_zero A] (f : α → A) : set α := {x | f x ≠ 0}
/-- `mul_support` of a function is the set of points `x` such that `f x ≠ 1`. -/
@[to_additive] def mul_support (f : α → M) : set α := {x | f x ≠ 1}
@[to_additive] lemma nmem_mul_support {f : α → M} {x : α} :
x ∉ mul_support f ↔ f x = 1 :=
not_not
@[to_additive] lemma compl_mul_support {f : α → M} :
(mul_support f)ᶜ = {x | f x = 1} :=
ext $ λ x, nmem_mul_support
@[simp, to_additive] lemma mem_mul_support {f : α → M} {x : α} :
x ∈ mul_support f ↔ f x ≠ 1 :=
iff.rfl
@[simp, to_additive] lemma mul_support_subset_iff {f : α → M} {s : set α} :
mul_support f ⊆ s ↔ ∀ x, f x ≠ 1 → x ∈ s :=
iff.rfl
@[to_additive] lemma mul_support_subset_iff' {f : α → M} {s : set α} :
mul_support f ⊆ s ↔ ∀ x ∉ s, f x = 1 :=
forall_congr $ λ x, not_imp_comm
@[simp, to_additive] lemma mul_support_eq_empty_iff {f : α → M} :
mul_support f = ∅ ↔ f = 1 :=
by { simp_rw [← subset_empty_iff, mul_support_subset_iff', funext_iff], simp }
@[simp, to_additive] lemma mul_support_one' : mul_support (1 : α → M) = ∅ :=
mul_support_eq_empty_iff.2 rfl
@[simp, to_additive] lemma mul_support_one : mul_support (λ x : α, (1 : M)) = ∅ :=
mul_support_one'
@[to_additive] lemma mul_support_const {c : M} (hc : c ≠ 1) :
mul_support (λ x : α, c) = set.univ :=
by { ext x, simp [hc] }
@[to_additive] lemma mul_support_binop_subset (op : M → N → P) (op1 : op 1 1 = 1)
(f : α → M) (g : α → N) :
mul_support (λ x, op (f x) (g x)) ⊆ mul_support f ∪ mul_support g :=
λ x hx, classical.by_cases
(λ hf : f x = 1, or.inr $ λ hg, hx $ by simp only [hf, hg, op1])
or.inl
@[to_additive] lemma mul_support_sup [semilattice_sup M] (f g : α → M) :
mul_support (λ x, f x ⊔ g x) ⊆ mul_support f ∪ mul_support g :=
mul_support_binop_subset (⊔) sup_idem f g
@[to_additive] lemma mul_support_inf [semilattice_inf M] (f g : α → M) :
mul_support (λ x, f x ⊓ g x) ⊆ mul_support f ∪ mul_support g :=
mul_support_binop_subset (⊓) inf_idem f g
@[to_additive] lemma mul_support_max [linear_order M] (f g : α → M) :
mul_support (λ x, max (f x) (g x)) ⊆ mul_support f ∪ mul_support g :=
mul_support_sup f g
@[to_additive] lemma mul_support_min [linear_order M] (f g : α → M) :
mul_support (λ x, min (f x) (g x)) ⊆ mul_support f ∪ mul_support g :=
mul_support_inf f g
@[to_additive] lemma mul_support_supr [conditionally_complete_lattice M] [nonempty ι]
(f : ι → α → M) :
mul_support (λ x, ⨆ i, f i x) ⊆ ⋃ i, mul_support (f i) :=
begin
rw mul_support_subset_iff',
simp only [mem_Union, not_exists, nmem_mul_support],
intros x hx,
simp only [hx, csupr_const]
end
@[to_additive] lemma mul_support_infi [conditionally_complete_lattice M] [nonempty ι]
(f : ι → α → M) :
mul_support (λ x, ⨅ i, f i x) ⊆ ⋃ i, mul_support (f i) :=
@mul_support_supr _ (order_dual M) ι ⟨(1:M)⟩ _ _ f
@[to_additive] lemma mul_support_comp_subset {g : M → N} (hg : g 1 = 1) (f : α → M) :
mul_support (g ∘ f) ⊆ mul_support f :=
λ x, mt $ λ h, by simp only [(∘), *]
@[to_additive] lemma mul_support_subset_comp {g : M → N} (hg : ∀ {x}, g x = 1 → x = 1)
(f : α → M) :
mul_support f ⊆ mul_support (g ∘ f) :=
λ x, mt hg
@[to_additive] lemma mul_support_comp_eq (g : M → N) (hg : ∀ {x}, g x = 1 ↔ x = 1)
(f : α → M) :
mul_support (g ∘ f) = mul_support f :=
set.ext $ λ x, not_congr hg
@[to_additive] lemma mul_support_comp_eq_preimage (g : β → M) (f : α → β) :
mul_support (g ∘ f) = f ⁻¹' mul_support g :=
rfl
@[to_additive support_prod_mk] lemma mul_support_prod_mk (f : α → M) (g : α → N) :
mul_support (λ x, (f x, g x)) = mul_support f ∪ mul_support g :=
set.ext $ λ x, by simp only [mul_support, not_and_distrib, mem_union_eq, mem_set_of_eq,
prod.mk_eq_one, ne.def]
@[to_additive support_prod_mk'] lemma mul_support_prod_mk' (f : α → M × N) :
mul_support f = mul_support (λ x, (f x).1) ∪ mul_support (λ x, (f x).2) :=
by simp only [← mul_support_prod_mk, prod.mk.eta]
@[to_additive] lemma mul_support_along_fiber_subset (f : α × β → M) (a : α) :
mul_support (λ b, f (a, b)) ⊆ (mul_support f).image prod.snd :=
by tidy
@[simp, to_additive] lemma mul_support_along_fiber_finite_of_finite
(f : α × β → M) (a : α) (h : (mul_support f).finite) :
(mul_support (λ b, f (a, b))).finite :=
(h.image prod.snd).subset (mul_support_along_fiber_subset f a)
end has_one
@[to_additive] lemma mul_support_mul [monoid M] (f g : α → M) :
mul_support (λ x, f x * g x) ⊆ mul_support f ∪ mul_support g :=
mul_support_binop_subset (*) (one_mul _) f g
@[simp, to_additive] lemma mul_support_inv [group G] (f : α → G) :
mul_support (λ x, (f x)⁻¹) = mul_support f :=
set.ext $ λ x, not_congr inv_eq_one
@[simp, to_additive support_neg'] lemma mul_support_inv'' [group G] (f : α → G) :
mul_support (f⁻¹) = mul_support f :=
mul_support_inv f
@[simp] lemma mul_support_inv₀ [group_with_zero G₀] (f : α → G₀) :
mul_support (λ x, (f x)⁻¹) = mul_support f :=
set.ext $ λ x, not_congr inv_eq_one₀
@[to_additive] lemma mul_support_mul_inv [group G] (f g : α → G) :
mul_support (λ x, f x * (g x)⁻¹) ⊆ mul_support f ∪ mul_support g :=
mul_support_binop_subset (λ a b, a * b⁻¹) (by simp) f g
@[to_additive support_sub] lemma mul_support_group_div [group G] (f g : α → G) :
mul_support (λ x, f x / g x) ⊆ mul_support f ∪ mul_support g :=
mul_support_binop_subset (/) (by simp only [one_div, one_inv]) f g
lemma mul_support_div [group_with_zero G₀] (f g : α → G₀) :
mul_support (λ x, f x / g x) ⊆ mul_support f ∪ mul_support g :=
mul_support_binop_subset (/) (by simp only [div_one]) f g
@[simp] lemma support_mul [mul_zero_class R] [no_zero_divisors R] (f g : α → R) :
support (λ x, f x * g x) = support f ∩ support g :=
set.ext $ λ x, by simp only [mem_support, mul_ne_zero_iff, mem_inter_eq, not_or_distrib]
lemma support_smul_subset_right [add_monoid A] [monoid B] [distrib_mul_action B A]
(b : B) (f : α → A) :
support (b • f) ⊆ support f :=
λ x hbf hf, hbf $ by rw [pi.smul_apply, hf, smul_zero]
lemma support_smul_subset_left [semiring R] [add_comm_monoid M] [module R M]
(f : α → R) (g : α → M) :
support (f • g) ⊆ support f :=
λ x hfg hf, hfg $ by rw [pi.smul_apply', hf, zero_smul]
lemma support_smul [semiring R] [add_comm_monoid M] [module R M]
[no_zero_smul_divisors R M] (f : α → R) (g : α → M) :
support (f • g) = support f ∩ support g :=
ext $ λ x, smul_ne_zero
@[simp] lemma support_inv [group_with_zero G₀] (f : α → G₀) :
support (λ x, (f x)⁻¹) = support f :=
set.ext $ λ x, not_congr inv_eq_zero
@[simp] lemma support_div [group_with_zero G₀] (f g : α → G₀) :
support (λ x, f x / g x) = support f ∩ support g :=
by simp [div_eq_mul_inv]
@[to_additive] lemma mul_support_prod [comm_monoid M] (s : finset α) (f : α → β → M) :
mul_support (λ x, ∏ i in s, f i x) ⊆ ⋃ i ∈ s, mul_support (f i) :=
begin
rw mul_support_subset_iff',
simp only [mem_Union, not_exists, nmem_mul_support],
exact λ x, finset.prod_eq_one
end
lemma support_prod_subset [comm_monoid_with_zero A] (s : finset α) (f : α → β → A) :
support (λ x, ∏ i in s, f i x) ⊆ ⋂ i ∈ s, support (f i) :=
λ x hx, mem_bInter_iff.2 $ λ i hi H, hx $ finset.prod_eq_zero hi H
lemma support_prod [comm_monoid_with_zero A] [no_zero_divisors A] [nontrivial A]
(s : finset α) (f : α → β → A) :
support (λ x, ∏ i in s, f i x) = ⋂ i ∈ s, support (f i) :=
set.ext $ λ x, by
simp only [support, ne.def, finset.prod_eq_zero_iff, mem_set_of_eq, set.mem_Inter, not_exists]
lemma mul_support_one_add [has_one R] [add_left_cancel_monoid R] (f : α → R) :
mul_support (λ x, 1 + f x) = support f :=
set.ext $ λ x, not_congr add_right_eq_self
lemma mul_support_one_add' [has_one R] [add_left_cancel_monoid R] (f : α → R) :
mul_support (1 + f) = support f :=
mul_support_one_add f
lemma mul_support_add_one [has_one R] [add_right_cancel_monoid R] (f : α → R) :
mul_support (λ x, f x + 1) = support f :=
set.ext $ λ x, not_congr add_left_eq_self
lemma mul_support_add_one' [has_one R] [add_right_cancel_monoid R] (f : α → R) :
mul_support (f + 1) = support f :=
mul_support_add_one f
lemma mul_support_one_sub' [has_one R] [add_group R] (f : α → R) :
mul_support (1 - f) = support f :=
by rw [sub_eq_add_neg, mul_support_one_add', support_neg']
lemma mul_support_one_sub [has_one R] [add_group R] (f : α → R) :
mul_support (λ x, 1 - f x) = support f :=
mul_support_one_sub' f
end function
namespace set
open function
variables {α β M : Type*} [has_one M] {f : α → M}
@[to_additive] lemma image_inter_mul_support_eq {s : set β} {g : β → α} :
(g '' s ∩ mul_support f) = g '' (s ∩ mul_support (f ∘ g)) :=
by rw [mul_support_comp_eq_preimage f g, image_inter_preimage]
end set
namespace pi
variables {A : Type*} {B : Type*} [decidable_eq A] [has_zero B] {a : A} {b : B}
lemma support_single_zero : function.support (pi.single a (0 : B)) = ∅ := by simp
@[simp] lemma support_single_of_ne (h : b ≠ 0) :
function.support (pi.single a b) = {a} :=
begin
ext,
simp only [mem_singleton_iff, ne.def, function.mem_support],
split,
{ contrapose!,
exact λ h', single_eq_of_ne h' b },
{ rintro rfl,
rw single_eq_same,
exact h }
end
lemma support_single [decidable_eq B] :
function.support (pi.single a b) = if b = 0 then ∅ else {a} := by { split_ifs with h; simp [h] }
lemma support_single_subset : function.support (pi.single a b) ⊆ {a} :=
begin
classical,
rw support_single,
split_ifs; simp
end
lemma support_single_disjoint {b' : B} (hb : b ≠ 0) (hb' : b' ≠ 0) {i j : A} :
disjoint (function.support (single i b)) (function.support (single j b')) ↔ i ≠ j :=
by rw [support_single_of_ne hb, support_single_of_ne hb', disjoint_singleton]
end pi
|
7ecd52de86544a934fff5c6affaf2ee82ab817c8 | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/measure_theory/integral/set_integral.lean | ea05ed0a36bb590dfc91a5775367e7e610b39642 | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 36,902 | lean | /-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov
-/
import measure_theory.integral.integrable_on
import measure_theory.integral.bochner
/-!
# Set integral
In this file we prove some properties of `∫ x in s, f x ∂μ`. Recall that this notation
is defined as `∫ x, f x ∂(μ.restrict s)`. In `integral_indicator` we prove that for a measurable
function `f` and a measurable set `s` this definition coincides with another natural definition:
`∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ`, where `indicator s f x` is equal to `f x` for `x ∈ s`
and is zero otherwise.
Since `∫ x in s, f x ∂μ` is a notation, one can rewrite or apply any theorem about `∫ x, f x ∂μ`
directly. In this file we prove some theorems about dependence of `∫ x in s, f x ∂μ` on `s`, e.g.
`integral_union`, `integral_empty`, `integral_univ`.
We use the property `integrable_on f s μ := integrable f (μ.restrict s)`, defined in
`measure_theory.integrable_on`. We also defined in that same file a predicate
`integrable_at_filter (f : α → E) (l : filter α) (μ : measure α)` saying that `f` is integrable at
some set `s ∈ l`.
Finally, we prove a version of the
[Fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus)
for set integral, see `filter.tendsto.integral_sub_linear_is_o_ae` and its corollaries.
Namely, consider a measurably generated filter `l`, a measure `μ` finite at this filter, and
a function `f` that has a finite limit `c` at `l ⊓ μ.ae`. Then `∫ x in s, f x ∂μ = μ s • c + o(μ s)`
as `s` tends to `l.lift' powerset`, i.e. for any `ε>0` there exists `t ∈ l` such that
`∥∫ x in s, f x ∂μ - μ s • c∥ ≤ ε * μ s` whenever `s ⊆ t`. We also formulate a version of this
theorem for a locally finite measure `μ` and a function `f` continuous at a point `a`.
## Notation
We provide the following notations for expressing the integral of a function on a set :
* `∫ a in s, f a ∂μ` is `measure_theory.integral (μ.restrict s) f`
* `∫ a in s, f a` is `∫ a in s, f a ∂volume`
Note that the set notations are defined in the file `measure_theory/bochner_integration`,
but we reference them here because all theorems about set integrals are in this file.
## TODO
The file ends with over a hundred lines of commented out code. This is the old contents of this file
using the `indicator` approach to the definition of `∫ x in s, f x ∂μ`. This code should be
migrated to the new definition.
-/
noncomputable theory
open set filter topological_space measure_theory function
open_locale classical topological_space interval big_operators filter ennreal measure_theory
variables {α β E F : Type*} [measurable_space α]
namespace measure_theory
section normed_group
variables [normed_group E] [measurable_space E] {f g : α → E} {s t : set α} {μ ν : measure α}
{l l' : filter α} [borel_space E] [second_countable_topology E]
variables [complete_space E] [normed_space ℝ E]
lemma set_integral_congr_ae (hs : measurable_set s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) :
∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ :=
integral_congr_ae ((ae_restrict_iff' hs).2 h)
lemma set_integral_congr (hs : measurable_set s) (h : eq_on f g s) :
∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ :=
set_integral_congr_ae hs $ eventually_of_forall h
lemma integral_union (hst : disjoint s t) (hs : measurable_set s) (ht : measurable_set t)
(hfs : integrable_on f s μ) (hft : integrable_on f t μ) :
∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ :=
by simp only [integrable_on, measure.restrict_union hst hs ht, integral_add_measure hfs hft]
lemma integral_empty : ∫ x in ∅, f x ∂μ = 0 := by rw [measure.restrict_empty, integral_zero_measure]
lemma integral_univ : ∫ x in univ, f x ∂μ = ∫ x, f x ∂μ := by rw [measure.restrict_univ]
lemma integral_add_compl (hs : measurable_set s) (hfi : integrable f μ) :
∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ :=
by rw [← integral_union (@disjoint_compl_right (set α) _ _) hs hs.compl
hfi.integrable_on hfi.integrable_on, union_compl_self, integral_univ]
/-- For a function `f` and a measurable set `s`, the integral of `indicator s f`
over the whole space is equal to `∫ x in s, f x ∂μ` defined as `∫ x, f x ∂(μ.restrict s)`. -/
lemma integral_indicator (hs : measurable_set s) :
∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ :=
begin
by_cases hf : ae_measurable f (μ.restrict s), swap,
{ rw integral_non_ae_measurable hf,
rw [← ae_measurable_indicator_iff hs] at hf,
exact integral_non_ae_measurable hf },
by_cases hfi : integrable_on f s μ, swap,
{ rwa [integral_undef, integral_undef],
rwa integrable_indicator_iff hs },
calc ∫ x, indicator s f x ∂μ = ∫ x in s, indicator s f x ∂μ + ∫ x in sᶜ, indicator s f x ∂μ :
(integral_add_compl hs (hfi.indicator hs)).symm
... = ∫ x in s, f x ∂μ + ∫ x in sᶜ, 0 ∂μ :
congr_arg2 (+) (integral_congr_ae (indicator_ae_eq_restrict hs))
(integral_congr_ae (indicator_ae_eq_restrict_compl hs))
... = ∫ x in s, f x ∂μ : by simp
end
lemma set_integral_congr_set_ae (hst : s =ᵐ[μ] t) :
∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ :=
by rw restrict_congr_set hst
lemma set_integral_const (c : E) : ∫ x in s, c ∂μ = (μ s).to_real • c :=
by rw [integral_const, measure.restrict_apply_univ]
@[simp]
lemma integral_indicator_const (e : E) ⦃s : set α⦄ (s_meas : measurable_set s) :
∫ (a : α), s.indicator (λ (x : α), e) a ∂μ = (μ s).to_real • e :=
by rw [integral_indicator s_meas, ← set_integral_const]
lemma set_integral_map {β} [measurable_space β] {g : α → β} {f : β → E} {s : set β}
(hs : measurable_set s) (hf : ae_measurable f (measure.map g μ)) (hg : measurable g) :
∫ y in s, f y ∂(measure.map g μ) = ∫ x in g ⁻¹' s, f (g x) ∂μ :=
begin
rw [measure.restrict_map hg hs, integral_map hg (hf.mono_measure _)],
exact measure.map_mono g measure.restrict_le_self
end
lemma set_integral_map_of_closed_embedding [topological_space α] [borel_space α]
{β} [measurable_space β] [topological_space β] [borel_space β]
{g : α → β} {f : β → E} {s : set β} (hs : measurable_set s) (hg : closed_embedding g) :
∫ y in s, f y ∂(measure.map g μ) = ∫ x in g ⁻¹' s, f (g x) ∂μ :=
begin
rw [measure.restrict_map hg.measurable hs, integral_map_of_closed_embedding hg],
apply_instance,
end
lemma norm_set_integral_le_of_norm_le_const_ae {C : ℝ} (hs : μ s < ∞)
(hC : ∀ᵐ x ∂μ.restrict s, ∥f x∥ ≤ C) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
begin
rw ← measure.restrict_apply_univ at *,
haveI : finite_measure (μ.restrict s) := ⟨‹_›⟩,
exact norm_integral_le_of_norm_le_const hC
end
lemma norm_set_integral_le_of_norm_le_const_ae' {C : ℝ} (hs : μ s < ∞)
(hC : ∀ᵐ x ∂μ, x ∈ s → ∥f x∥ ≤ C) (hfm : ae_measurable f (μ.restrict s)) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
begin
apply norm_set_integral_le_of_norm_le_const_ae hs,
have A : ∀ᵐ (x : α) ∂μ, x ∈ s → ∥ae_measurable.mk f hfm x∥ ≤ C,
{ filter_upwards [hC, hfm.ae_mem_imp_eq_mk],
assume a h1 h2 h3,
rw [← h2 h3],
exact h1 h3 },
have B : measurable_set {x | ∥(hfm.mk f) x∥ ≤ C} := hfm.measurable_mk.norm measurable_set_Iic,
filter_upwards [hfm.ae_eq_mk, (ae_restrict_iff B).2 A],
assume a h1 h2,
rwa h1
end
lemma norm_set_integral_le_of_norm_le_const_ae'' {C : ℝ} (hs : μ s < ∞) (hsm : measurable_set s)
(hC : ∀ᵐ x ∂μ, x ∈ s → ∥f x∥ ≤ C) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
norm_set_integral_le_of_norm_le_const_ae hs $ by rwa [ae_restrict_eq hsm, eventually_inf_principal]
lemma norm_set_integral_le_of_norm_le_const {C : ℝ} (hs : μ s < ∞)
(hC : ∀ x ∈ s, ∥f x∥ ≤ C) (hfm : ae_measurable f (μ.restrict s)) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
norm_set_integral_le_of_norm_le_const_ae' hs (eventually_of_forall hC) hfm
lemma norm_set_integral_le_of_norm_le_const' {C : ℝ} (hs : μ s < ∞) (hsm : measurable_set s)
(hC : ∀ x ∈ s, ∥f x∥ ≤ C) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
norm_set_integral_le_of_norm_le_const_ae'' hs hsm $ eventually_of_forall hC
lemma set_integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f)
(hfi : integrable_on f s μ) :
∫ x in s, f x ∂μ = 0 ↔ f =ᵐ[μ.restrict s] 0 :=
integral_eq_zero_iff_of_nonneg_ae hf hfi
lemma set_integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f)
(hfi : integrable_on f s μ) :
0 < ∫ x in s, f x ∂μ ↔ 0 < μ (support f ∩ s) :=
begin
rw [integral_pos_iff_support_of_nonneg_ae hf hfi, restrict_apply_of_null_measurable_set],
exact hfi.ae_measurable.null_measurable_set (measurable_set_singleton 0).compl
end
lemma set_integral_trim {α} {m m0 : measurable_space α} {μ : measure α} (hm : m ≤ m0) {f : α → E}
(hf_meas : @measurable _ _ m _ f) {s : set α} (hs : measurable_set[m] s) :
∫ x in s, f x ∂μ = ∫ x in s, f x ∂(μ.trim hm) :=
by rwa [integral_trim hm hf_meas, restrict_trim hm μ]
end normed_group
section mono
variables {μ : measure α} {f g : α → ℝ} {s : set α}
(hf : integrable_on f s μ) (hg : integrable_on g s μ)
lemma set_integral_mono_ae_restrict (h : f ≤ᵐ[μ.restrict s] g) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
integral_mono_ae hf hg h
lemma set_integral_mono_ae (h : f ≤ᵐ[μ] g) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
set_integral_mono_ae_restrict hf hg (ae_restrict_of_ae h)
lemma set_integral_mono_on (hs : measurable_set s) (h : ∀ x ∈ s, f x ≤ g x) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
set_integral_mono_ae_restrict hf hg
(by simp [hs, eventually_le, eventually_inf_principal, ae_of_all _ h])
lemma set_integral_mono (h : f ≤ g) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
integral_mono hf hg h
end mono
section nonneg
variables {μ : measure α} {f : α → ℝ} {s : set α}
lemma set_integral_nonneg_of_ae_restrict (hf : 0 ≤ᵐ[μ.restrict s] f) :
(0:ℝ) ≤ (∫ a in s, f a ∂μ) :=
integral_nonneg_of_ae hf
lemma set_integral_nonneg_of_ae (hf : 0 ≤ᵐ[μ] f) : (0:ℝ) ≤ (∫ a in s, f a ∂μ) :=
set_integral_nonneg_of_ae_restrict (ae_restrict_of_ae hf)
lemma set_integral_nonneg (hs : measurable_set s) (hf : ∀ a, a ∈ s → 0 ≤ f a) :
(0:ℝ) ≤ (∫ a in s, f a ∂μ) :=
set_integral_nonneg_of_ae_restrict ((ae_restrict_iff' hs).mpr (ae_of_all μ hf))
end nonneg
lemma set_integral_mono_set {α : Type*} [measurable_space α] {μ : measure α}
{s t : set α} {f : α → ℝ} (hfi : integrable f μ) (hf : 0 ≤ᵐ[μ] f) (hst : s ≤ᵐ[μ] t) :
∫ x in s, f x ∂μ ≤ ∫ x in t, f x ∂μ :=
begin
repeat { rw integral_eq_lintegral_of_nonneg_ae (ae_restrict_of_ae hf)
(hfi.1.mono_measure measure.restrict_le_self) },
rw ennreal.to_real_le_to_real
(ne_of_lt $ (has_finite_integral_iff_of_real (ae_restrict_of_ae hf)).mp hfi.integrable_on.2)
(ne_of_lt $ (has_finite_integral_iff_of_real (ae_restrict_of_ae hf)).mp hfi.integrable_on.2),
exact (lintegral_mono_set' hst),
end
section continuous_set_integral
/-! ### Continuity of the set integral
We prove that for any set `s`, the function `λ f : α →₁[μ] E, ∫ x in s, f x ∂μ` is continuous. -/
variables [normed_group E] [measurable_space E] [second_countable_topology E] [borel_space E]
{𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜]
[normed_group F] [measurable_space F] [second_countable_topology F] [borel_space F]
[normed_space 𝕜 F]
{p : ℝ≥0∞} {μ : measure α}
/-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by
`(Lp.mem_ℒp f).restrict s).to_Lp f`. This map is additive. -/
lemma Lp_to_Lp_restrict_add (f g : Lp E p μ) (s : set α) :
((Lp.mem_ℒp (f + g)).restrict s).to_Lp ⇑(f + g)
= ((Lp.mem_ℒp f).restrict s).to_Lp f + ((Lp.mem_ℒp g).restrict s).to_Lp g :=
begin
ext1,
refine (ae_restrict_of_ae (Lp.coe_fn_add f g)).mp _,
refine (Lp.coe_fn_add (mem_ℒp.to_Lp f ((Lp.mem_ℒp f).restrict s))
(mem_ℒp.to_Lp g ((Lp.mem_ℒp g).restrict s))).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).restrict s)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp g).restrict s)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp (f+g)).restrict s)).mono (λ x hx1 hx2 hx3 hx4 hx5, _),
rw [hx4, hx1, pi.add_apply, hx2, hx3, hx5, pi.add_apply],
end
/-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by
`(Lp.mem_ℒp f).restrict s).to_Lp f`. This map commutes with scalar multiplication. -/
lemma Lp_to_Lp_restrict_smul [opens_measurable_space 𝕜] (c : 𝕜) (f : Lp F p μ) (s : set α) :
((Lp.mem_ℒp (c • f)).restrict s).to_Lp ⇑(c • f) = c • (((Lp.mem_ℒp f).restrict s).to_Lp f) :=
begin
ext1,
refine (ae_restrict_of_ae (Lp.coe_fn_smul c f)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).restrict s)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp (c • f)).restrict s)).mp _,
refine (Lp.coe_fn_smul c (mem_ℒp.to_Lp f ((Lp.mem_ℒp f).restrict s))).mono
(λ x hx1 hx2 hx3 hx4, _),
rw [hx2, hx1, pi.smul_apply, hx3, hx4, pi.smul_apply],
end
/-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by
`(Lp.mem_ℒp f).restrict s).to_Lp f`. This map is non-expansive. -/
lemma norm_Lp_to_Lp_restrict_le (s : set α) (f : Lp E p μ) :
∥((Lp.mem_ℒp f).restrict s).to_Lp f∥ ≤ ∥f∥ :=
begin
rw [Lp.norm_def, Lp.norm_def, ennreal.to_real_le_to_real (Lp.snorm_ne_top _) (Lp.snorm_ne_top _)],
refine (le_of_eq _).trans (snorm_mono_measure _ measure.restrict_le_self),
{ exact s, },
exact snorm_congr_ae (mem_ℒp.coe_fn_to_Lp _),
end
variables (α F 𝕜)
/-- Continuous linear map sending a function of `Lp F p μ` to the same function in
`Lp F p (μ.restrict s)`. -/
def Lp_to_Lp_restrict_clm [borel_space 𝕜] (μ : measure α) (p : ℝ≥0∞) [hp : fact (1 ≤ p)]
(s : set α) :
Lp F p μ →L[𝕜] Lp F p (μ.restrict s) :=
@linear_map.mk_continuous 𝕜 (Lp F p μ) (Lp F p (μ.restrict s)) _ _ _ _ _
⟨λ f, mem_ℒp.to_Lp f ((Lp.mem_ℒp f).restrict s), λ f g, Lp_to_Lp_restrict_add f g s,
λ c f, Lp_to_Lp_restrict_smul c f s⟩
1 (by { intro f, rw one_mul, exact norm_Lp_to_Lp_restrict_le s f, })
variables {α F 𝕜}
variables (𝕜)
lemma Lp_to_Lp_restrict_clm_coe_fn [borel_space 𝕜] [hp : fact (1 ≤ p)] (s : set α) (f : Lp F p μ) :
Lp_to_Lp_restrict_clm α F 𝕜 μ p s f =ᵐ[μ.restrict s] f :=
mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).restrict s)
variables {𝕜}
@[continuity]
lemma continuous_set_integral [normed_space ℝ E] [complete_space E] (s : set α) :
continuous (λ f : α →₁[μ] E, ∫ x in s, f x ∂μ) :=
begin
haveI : fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩,
have h_comp : (λ f : α →₁[μ] E, ∫ x in s, f x ∂μ)
= (integral (μ.restrict s)) ∘ (λ f, Lp_to_Lp_restrict_clm α E ℝ μ 1 s f),
{ ext1 f,
rw [function.comp_apply, integral_congr_ae (Lp_to_Lp_restrict_clm_coe_fn ℝ s f)], },
rw h_comp,
exact continuous_integral.comp (Lp_to_Lp_restrict_clm α E ℝ μ 1 s).continuous,
end
end continuous_set_integral
end measure_theory
open measure_theory asymptotics metric
variables {ι : Type*} [measurable_space E] [normed_group E]
/-- Fundamental theorem of calculus for set integrals: if `μ` is a measure that is finite at a
filter `l` and `f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then `∫ x in
s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that `s i` tends to `l.lift'
powerset` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).to_real` in the
actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma filter.tendsto.integral_sub_linear_is_o_ae
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} {l : filter α} [l.is_measurably_generated]
{f : α → E} {b : E} (h : tendsto f (l ⊓ μ.ae) (𝓝 b))
(hfm : measurable_at_filter f l μ) (hμ : μ.finite_at_filter l)
{s : ι → set α} {li : filter ι} (hs : tendsto s li (l.lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • b) m li :=
begin
suffices : is_o (λ s, ∫ x in s, f x ∂μ - (μ s).to_real • b) (λ s, (μ s).to_real)
(l.lift' powerset),
from (this.comp_tendsto hs).congr' (hsμ.mono $ λ a ha, ha ▸ rfl) hsμ,
refine is_o_iff.2 (λ ε ε₀, _),
have : ∀ᶠ s in l.lift' powerset, ∀ᶠ x in μ.ae, x ∈ s → f x ∈ closed_ball b ε :=
eventually_lift'_powerset_eventually.2 (h.eventually $ closed_ball_mem_nhds _ ε₀),
filter_upwards [hμ.eventually, (hμ.integrable_at_filter_of_tendsto_ae hfm h).eventually,
hfm.eventually, this],
simp only [mem_closed_ball, dist_eq_norm],
intros s hμs h_integrable hfm h_norm,
rw [← set_integral_const, ← integral_sub h_integrable (integrable_on_const.2 $ or.inr hμs),
real.norm_eq_abs, abs_of_nonneg ennreal.to_real_nonneg],
exact norm_set_integral_le_of_norm_le_const_ae' hμs h_norm (hfm.sub ae_measurable_const)
end
/-- Fundamental theorem of calculus for set integrals, `nhds_within` version: if `μ` is a locally
finite measure and `f` is an almost everywhere measurable function that is continuous at a point `a`
within a measurable set `t`, then `∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at a filter `li`
provided that `s i` tends to `(𝓝[t] a).lift' powerset` along `li`. Since `μ (s i)` is an `ℝ≥0∞`
number, we use `(μ (s i)).to_real` in the actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma continuous_within_at.integral_sub_linear_is_o_ae
[topological_space α] [opens_measurable_space α]
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} [locally_finite_measure μ] {a : α} {t : set α}
{f : α → E} (ha : continuous_within_at f t a) (ht : measurable_set t)
(hfm : measurable_at_filter f (𝓝[t] a) μ)
{s : ι → set α} {li : filter ι} (hs : tendsto s li ((𝓝[t] a).lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • f a) m li :=
by haveI : (𝓝[t] a).is_measurably_generated := ht.nhds_within_is_measurably_generated _;
exact (ha.mono_left inf_le_left).integral_sub_linear_is_o_ae
hfm (μ.finite_at_nhds_within a t) hs m hsμ
/-- Fundamental theorem of calculus for set integrals, `nhds` version: if `μ` is a locally finite
measure and `f` is an almost everywhere measurable function that is continuous at a point `a`, then
`∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at `li` provided that `s` tends to `(𝓝 a).lift'
powerset` along `li. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).to_real` in the
actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma continuous_at.integral_sub_linear_is_o_ae
[topological_space α] [opens_measurable_space α]
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} [locally_finite_measure μ] {a : α}
{f : α → E} (ha : continuous_at f a) (hfm : measurable_at_filter f (𝓝 a) μ)
{s : ι → set α} {li : filter ι} (hs : tendsto s li ((𝓝 a).lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • f a) m li :=
(ha.mono_left inf_le_left).integral_sub_linear_is_o_ae hfm (μ.finite_at_nhds a) hs m hsμ
/-- If a function is continuous on an open set `s`, then it is measurable at the filter `𝓝 x` for
all `x ∈ s`. -/
lemma continuous_on.measurable_at_filter
[topological_space α] [opens_measurable_space α] [borel_space E]
{f : α → E} {s : set α} {μ : measure α} (hs : is_open s) (hf : continuous_on f s) :
∀ x ∈ s, measurable_at_filter f (𝓝 x) μ :=
λ x hx, ⟨s, is_open.mem_nhds hs hx, hf.ae_measurable hs.measurable_set⟩
lemma continuous_at.measurable_at_filter
[topological_space α] [opens_measurable_space α] [borel_space E]
{f : α → E} {s : set α} {μ : measure α} (hs : is_open s) (hf : ∀ x ∈ s, continuous_at f x) :
∀ x ∈ s, measurable_at_filter f (𝓝 x) μ :=
continuous_on.measurable_at_filter hs $ continuous_at.continuous_on hf
/-- Fundamental theorem of calculus for set integrals, `nhds_within` version: if `μ` is a locally
finite measure, `f` is continuous on a measurable set `t`, and `a ∈ t`, then `∫ x in (s i), f x ∂μ =
μ (s i) • f a + o(μ (s i))` at `li` provided that `s i` tends to `(𝓝[t] a).lift' powerset` along
`li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).to_real` in the actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma continuous_on.integral_sub_linear_is_o_ae
[topological_space α] [opens_measurable_space α]
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} [locally_finite_measure μ] {a : α} {t : set α}
{f : α → E} (hft : continuous_on f t) (ha : a ∈ t) (ht : measurable_set t)
{s : ι → set α} {li : filter ι} (hs : tendsto s li ((𝓝[t] a).lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • f a) m li :=
(hft a ha).integral_sub_linear_is_o_ae ht ⟨t, self_mem_nhds_within, hft.ae_measurable ht⟩ hs m hsμ
section
/-! ### Continuous linear maps composed with integration
The goal of this section is to prove that integration commutes with continuous linear maps.
This holds for simple functions. The general result follows from the continuity of all involved
operations on the space `L¹`. Note that composition by a continuous linear map on `L¹` is not just
the composition, as we are dealing with classes of functions, but it has already been defined
as `continuous_linear_map.comp_Lp`. We take advantage of this construction here.
-/
variables {μ : measure α} {𝕜 : Type*} [is_R_or_C 𝕜] [normed_space 𝕜 E]
[normed_group F] [normed_space 𝕜 F]
{p : ennreal}
local attribute [instance] fact_one_le_one_ennreal
namespace continuous_linear_map
variables [measurable_space F] [borel_space F]
variables [second_countable_topology F] [complete_space F]
[borel_space E] [second_countable_topology E] [normed_space ℝ F]
lemma integral_comp_Lp (L : E →L[𝕜] F) (φ : Lp E p μ) :
∫ a, (L.comp_Lp φ) a ∂μ = ∫ a, L (φ a) ∂μ :=
integral_congr_ae $ coe_fn_comp_Lp _ _
lemma continuous_integral_comp_L1 [measurable_space 𝕜] [opens_measurable_space 𝕜] (L : E →L[𝕜] F) :
continuous (λ (φ : α →₁[μ] E), ∫ (a : α), L (φ a) ∂μ) :=
by { rw ← funext L.integral_comp_Lp, exact continuous_integral.comp (L.comp_LpL 1 μ).continuous, }
variables [complete_space E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
[normed_space ℝ E] [is_scalar_tower ℝ 𝕜 E] [is_scalar_tower ℝ 𝕜 F]
lemma integral_comp_comm (L : E →L[𝕜] F) {φ : α → E} (φ_int : integrable φ μ) :
∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
begin
apply integrable.induction (λ φ, ∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ)),
{ intros e s s_meas s_finite,
rw [integral_indicator_const e s_meas, ← @smul_one_smul E ℝ 𝕜 _ _ _ _ _ (μ s).to_real e,
continuous_linear_map.map_smul, @smul_one_smul F ℝ 𝕜 _ _ _ _ _ (μ s).to_real (L e),
← integral_indicator_const (L e) s_meas],
congr' 1 with a,
rw set.indicator_comp_of_zero L.map_zero },
{ intros f g H f_int g_int hf hg,
simp [L.map_add, integral_add f_int g_int,
integral_add (L.integrable_comp f_int) (L.integrable_comp g_int), hf, hg] },
{ exact is_closed_eq L.continuous_integral_comp_L1 (L.continuous.comp continuous_integral) },
{ intros f g hfg f_int hf,
convert hf using 1 ; clear hf,
{ exact integral_congr_ae (hfg.fun_comp L).symm },
{ rw integral_congr_ae hfg.symm } },
all_goals { assumption }
end
lemma integral_apply {H : Type*} [normed_group H] [normed_space ℝ H]
[second_countable_topology $ H →L[ℝ] E] {φ : α → H →L[ℝ] E} (φ_int : integrable φ μ) (v : H) :
(∫ a, φ a ∂μ) v = ∫ a, φ a v ∂μ :=
((continuous_linear_map.apply ℝ E v).integral_comp_comm φ_int).symm
lemma integral_comp_comm' (L : E →L[𝕜] F) {K} (hL : antilipschitz_with K L) (φ : α → E) :
∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
begin
by_cases h : integrable φ μ,
{ exact integral_comp_comm L h },
have : ¬ (integrable (L ∘ φ) μ),
by rwa lipschitz_with.integrable_comp_iff_of_antilipschitz L.lipschitz hL (L.map_zero),
simp [integral_undef, h, this]
end
lemma integral_comp_L1_comm (L : E →L[𝕜] F) (φ : α →₁[μ] E) : ∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
L.integral_comp_comm (L1.integrable_coe_fn φ)
end continuous_linear_map
namespace linear_isometry
variables [measurable_space F] [borel_space F] [second_countable_topology F] [complete_space F]
[normed_space ℝ F] [is_scalar_tower ℝ 𝕜 F]
[borel_space E] [second_countable_topology E] [complete_space E] [normed_space ℝ E]
[is_scalar_tower ℝ 𝕜 E]
[measurable_space 𝕜] [opens_measurable_space 𝕜]
lemma integral_comp_comm (L : E →ₗᵢ[𝕜] F) (φ : α → E) : ∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
L.to_continuous_linear_map.integral_comp_comm' L.antilipschitz _
end linear_isometry
variables [borel_space E] [second_countable_topology E] [complete_space E] [normed_space ℝ E]
[measurable_space F] [borel_space F] [second_countable_topology F] [complete_space F]
[normed_space ℝ F]
[measurable_space 𝕜] [borel_space 𝕜]
@[norm_cast] lemma integral_of_real {f : α → ℝ} : ∫ a, (f a : 𝕜) ∂μ = ↑∫ a, f a ∂μ :=
(@is_R_or_C.of_real_li 𝕜 _).integral_comp_comm f
lemma integral_re {f : α → 𝕜} (hf : integrable f μ) :
∫ a, is_R_or_C.re (f a) ∂μ = is_R_or_C.re ∫ a, f a ∂μ :=
(@is_R_or_C.re_clm 𝕜 _).integral_comp_comm hf
lemma integral_im {f : α → 𝕜} (hf : integrable f μ) :
∫ a, is_R_or_C.im (f a) ∂μ = is_R_or_C.im ∫ a, f a ∂μ :=
(@is_R_or_C.im_clm 𝕜 _).integral_comp_comm hf
lemma integral_conj {f : α → 𝕜} : ∫ a, is_R_or_C.conj (f a) ∂μ = is_R_or_C.conj ∫ a, f a ∂μ :=
(@is_R_or_C.conj_lie 𝕜 _).to_linear_isometry.integral_comp_comm f
lemma fst_integral {f : α → E × F} (hf : integrable f μ) :
(∫ x, f x ∂μ).1 = ∫ x, (f x).1 ∂μ :=
((continuous_linear_map.fst ℝ E F).integral_comp_comm hf).symm
lemma snd_integral {f : α → E × F} (hf : integrable f μ) :
(∫ x, f x ∂μ).2 = ∫ x, (f x).2 ∂μ :=
((continuous_linear_map.snd ℝ E F).integral_comp_comm hf).symm
lemma integral_pair {f : α → E} {g : α → F} (hf : integrable f μ) (hg : integrable g μ) :
∫ x, (f x, g x) ∂μ = (∫ x, f x ∂μ, ∫ x, g x ∂μ) :=
have _ := hf.prod_mk hg, prod.ext (fst_integral this) (snd_integral this)
lemma integral_smul_const (f : α → ℝ) (c : E) :
∫ x, f x • c ∂μ = (∫ x, f x ∂μ) • c :=
begin
by_cases hf : integrable f μ,
{ exact ((continuous_linear_map.id ℝ ℝ).smul_right c).integral_comp_comm hf },
{ by_cases hc : c = 0,
{ simp only [hc, integral_zero, smul_zero] },
rw [integral_undef hf, integral_undef, zero_smul],
simp_rw [integrable_smul_const hc, hf, not_false_iff] }
end
section inner
variables {E' : Type*} [inner_product_space 𝕜 E'] [measurable_space E'] [borel_space E']
[second_countable_topology E'] [complete_space E'] [normed_space ℝ E'] [is_scalar_tower ℝ 𝕜 E']
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E' _ x y
lemma integral_inner {f : α → E'} (hf : integrable f μ) (c : E') :
∫ x, ⟪c, f x⟫ ∂μ = ⟪c, ∫ x, f x ∂μ⟫ :=
((@inner_right 𝕜 E' _ _ c).restrict_scalars ℝ).integral_comp_comm hf
lemma integral_eq_zero_of_forall_integral_inner_eq_zero (f : α → E') (hf : integrable f μ)
(hf_int : ∀ (c : E'), ∫ x, ⟪c, f x⟫ ∂μ = 0) :
∫ x, f x ∂μ = 0 :=
by { specialize hf_int (∫ x, f x ∂μ), rwa [integral_inner hf, inner_self_eq_zero] at hf_int }
end inner
end
/-
namespace integrable
variables [measurable_space α] [measurable_space β] [normed_group E]
protected lemma measure_mono
end integrable
end measure_theory
section integral_on
variables [measurable_space α]
[normed_group β] [second_countable_topology β] [normed_space ℝ β] [complete_space β]
[measurable_space β] [borel_space β]
{s t : set α} {f g : α → β} {μ : measure α}
open set
lemma integral_on_congr (hf : measurable f) (hg : measurable g) (hs : measurable_set s)
(h : ∀ᵐ a ∂μ, a ∈ s → f a = g a) : ∫ a in s, f a ∂μ = ∫ a in s, g a ∂μ :=
integral_congr_ae hf hg $ _
lemma integral_on_congr_of_set (hsm : measurable_on s f) (htm : measurable_on t f)
(h : ∀ᵐ a, a ∈ s ↔ a ∈ t) : (∫ a in s, f a) = (∫ a in t, f a) :=
integral_congr_ae hsm htm $ indicator_congr_of_set h
lemma integral_on_add {s : set α} (hfm : measurable_on s f) (hfi : integrable_on s f)
(hgm : measurable_on s g) (hgi : integrable_on s g) :
(∫ a in s, f a + g a) = (∫ a in s, f a) + (∫ a in s, g a) :=
by { simp only [indicator_add], exact integral_add hfm hfi hgm hgi }
lemma integral_on_sub (hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : (∫ a in s, f a - g a) = (∫ a in s, f a) - (∫ a in s, g a) :=
by { simp only [indicator_sub], exact integral_sub hfm hfi hgm hgi }
lemma integral_on_le_integral_on_ae {f g : α → ℝ} (hfm : measurable_on s f)
(hfi : integrable_on s f) (hgm : measurable_on s g) (hgi : integrable_on s g)
(h : ∀ᵐ a, a ∈ s → f a ≤ g a) :
(∫ a in s, f a) ≤ (∫ a in s, g a) :=
begin
apply integral_le_integral_ae hfm hfi hgm hgi,
apply indicator_le_indicator_ae,
exact h
end
lemma integral_on_le_integral_on {f g : α → ℝ} (hfm : measurable_on s f) (hfi : integrable_on s f)
(hgm : measurable_on s g) (hgi : integrable_on s g) (h : ∀ a, a ∈ s → f a ≤ g a) :
(∫ a in s, f a) ≤ (∫ a in s, g a) :=
integral_on_le_integral_on_ae hfm hfi hgm hgi $ by filter_upwards [] h
lemma integral_on_union (hsm : measurable_on s f) (hsi : integrable_on s f)
(htm : measurable_on t f) (hti : integrable_on t f) (h : disjoint s t) :
(∫ a in (s ∪ t), f a) = (∫ a in s, f a) + (∫ a in t, f a) :=
by { rw [indicator_union_of_disjoint h, integral_add hsm hsi htm hti] }
lemma integral_on_union_ae (hs : measurable_set s) (ht : measurable_set t) (hsm : measurable_on s f)
(hsi : integrable_on s f) (htm : measurable_on t f) (hti : integrable_on t f)
(h : ∀ᵐ a, a ∉ s ∩ t) :
(∫ a in (s ∪ t), f a) = (∫ a in s, f a) + (∫ a in t, f a) :=
begin
have := integral_congr_ae _ _ (indicator_union_ae h f),
rw [this, integral_add hsm hsi htm hti],
{ exact hsm.union hs ht htm },
{ exact measurable.add hsm htm }
end
lemma integral_on_nonneg_of_ae {f : α → ℝ} (hf : ∀ᵐ a, a ∈ s → 0 ≤ f a) : (0:ℝ) ≤ (∫ a in s, f a) :=
integral_nonneg_of_ae $ by { filter_upwards [hf] λ a h, indicator_nonneg' h }
lemma integral_on_nonneg {f : α → ℝ} (hf : ∀ a, a ∈ s → 0 ≤ f a) : (0:ℝ) ≤ (∫ a in s, f a) :=
integral_on_nonneg_of_ae $ univ_mem' hf
lemma integral_on_nonpos_of_ae {f : α → ℝ} (hf : ∀ᵐ a, a ∈ s → f a ≤ 0) : (∫ a in s, f a) ≤ 0 :=
integral_nonpos_of_nonpos_ae $ by { filter_upwards [hf] λ a h, indicator_nonpos' h }
lemma integral_on_nonpos {f : α → ℝ} (hf : ∀ a, a ∈ s → f a ≤ 0) : (∫ a in s, f a) ≤ 0 :=
integral_on_nonpos_of_ae $ univ_mem' hf
lemma tendsto_integral_on_of_monotone {s : ℕ → set α} {f : α → β} (hsm : ∀i, measurable_set (s i))
(h_mono : monotone s) (hfm : measurable_on (Union s) f) (hfi : integrable_on (Union s) f) :
tendsto (λi, ∫ a in (s i), f a) at_top (nhds (∫ a in (Union s), f a)) :=
let bound : α → ℝ := indicator (Union s) (λa, ∥f a∥) in
begin
apply tendsto_integral_of_dominated_convergence,
{ assume i, exact hfm.subset (hsm i) (subset_Union _ _) },
{ assumption },
{ show integrable_on (Union s) (λa, ∥f a∥), rwa integrable_on_norm_iff },
{ assume i, apply ae_of_all,
assume a,
rw [norm_indicator_eq_indicator_norm],
exact indicator_le_indicator_of_subset (subset_Union _ _) (λa, norm_nonneg _) _ },
{ filter_upwards [] λa, le_trans (tendsto_indicator_of_monotone _ h_mono _ _) (pure_le_nhds _) }
end
lemma tendsto_integral_on_of_antimono (s : ℕ → set α) (f : α → β) (hsm : ∀i, measurable_set (s i))
(h_mono : ∀i j, i ≤ j → s j ⊆ s i) (hfm : measurable_on (s 0) f) (hfi : integrable_on (s 0) f) :
tendsto (λi, ∫ a in (s i), f a) at_top (nhds (∫ a in (Inter s), f a)) :=
let bound : α → ℝ := indicator (s 0) (λa, ∥f a∥) in
begin
apply tendsto_integral_of_dominated_convergence,
{ assume i, refine hfm.subset (hsm i) (h_mono _ _ (zero_le _)) },
{ exact hfm.subset (measurable_set.Inter hsm) (Inter_subset _ _) },
{ show integrable_on (s 0) (λa, ∥f a∥), rwa integrable_on_norm_iff },
{ assume i, apply ae_of_all,
assume a,
rw [norm_indicator_eq_indicator_norm],
refine indicator_le_indicator_of_subset (h_mono _ _ (zero_le _)) (λa, norm_nonneg _) _ },
{ filter_upwards [] λa, le_trans (tendsto_indicator_of_antimono _ h_mono _ _) (pure_le_nhds _) }
end
-- TODO : prove this for an encodable type
-- by proving an encodable version of `filter.is_countably_generated_at_top_finset_nat `
lemma integral_on_Union (s : ℕ → set α) (f : α → β) (hm : ∀i, measurable_set (s i))
(hd : ∀ i j, i ≠ j → s i ∩ s j = ∅) (hfm : measurable_on (Union s) f)
(hfi : integrable_on (Union s) f) :
(∫ a in (Union s), f a) = ∑'i, ∫ a in s i, f a :=
suffices h : tendsto (λn:finset ℕ, ∑ i in n, ∫ a in s i, f a) at_top (𝓝 $ (∫ a in (Union s), f a)),
by { rwa has_sum.tsum_eq },
begin
have : (λn:finset ℕ, ∑ i in n, ∫ a in s i, f a) = λn:finset ℕ, ∫ a in (⋃i∈n, s i), f a,
{ funext,
rw [← integral_finset_sum, indicator_finset_bUnion],
{ assume i hi j hj hij, exact hd i j hij },
{ assume i, refine hfm.subset (hm _) (subset_Union _ _) },
{ assume i, refine hfi.subset (subset_Union _ _) } },
rw this,
refine tendsto_integral_filter_of_dominated_convergence _ _ _ _ _ _ _,
{ exact indicator (Union s) (λ a, ∥f a∥) },
{ exact is_countably_generated_at_top_finset_nat },
{ refine univ_mem' (λ n, _),
simp only [mem_set_of_eq],
refine hfm.subset (measurable_set.Union (λ i, measurable_set.Union_Prop (λh, hm _)))
(bUnion_subset_Union _ _), },
{ assumption },
{ refine univ_mem' (λ n, univ_mem' $ _),
simp only [mem_set_of_eq],
assume a,
rw ← norm_indicator_eq_indicator_norm,
refine norm_indicator_le_of_subset (bUnion_subset_Union _ _) _ _ },
{ rw [← integrable_on, integrable_on_norm_iff], assumption },
{ filter_upwards [] λa, le_trans (tendsto_indicator_bUnion_finset _ _ _) (pure_le_nhds _) }
end
end integral_on
-/
|
5c765ef46fda1f60984858e44bb7ce8dbd309e88 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/group_theory/index.lean | 92cb3e3464e34a8bf85a3094af63b34f403efcc8 | [
"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 | 2,800 | lean | /-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import group_theory.coset
import set_theory.cardinal
/-!
# Index of a Subgroup
In this file we define the index of a subgroup, and prove several divisibility properties.
## Main definitions
- `H.index` : the index of `H : subgroup G` as a natural number,
and returns 0 if the index is infinite.
# Main results
- `index_mul_card` : `H.index * fintype.card H = fintype.card G`
- `index_dvd_card` : `H.index ∣ fintype.card G`
- `index_eq_mul_of_le` : If `H ≤ K`, then `H.index = K.index * (H.subgroup_of K).index`
- `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ H.index`
-/
namespace subgroup
variables {G : Type*} [group G] (H : subgroup G)
/-- The index of a subgroup as a natural number, and returns 0 if the index is infinite. -/
@[to_additive "The index of a subgroup as a natural number,
and returns 0 if the index is infinite."]
noncomputable def index : ℕ :=
(cardinal.mk (quotient_group.quotient H)).to_nat
@[to_additive] lemma index_comap_of_surjective {G' : Type*} [group G'] {f : G' →* G}
(hf : function.surjective f) : (H.comap f).index = H.index :=
begin
letI := quotient_group.left_rel H,
letI := quotient_group.left_rel (H.comap f),
have key : ∀ x y : G', setoid.r x y ↔ setoid.r (f x) (f y) :=
λ x y, iff_of_eq (congr_arg (∈ H) (by rw [f.map_mul, f.map_inv])),
refine cardinal.to_nat_congr (equiv.of_bijective (quotient.map' f (λ x y, (key x y).mp)) ⟨_, _⟩),
{ simp_rw [←quotient.eq'] at key,
refine quotient.ind' (λ x, _),
refine quotient.ind' (λ y, _),
exact (key x y).mpr },
{ refine quotient.ind' (λ x, _),
obtain ⟨y, hy⟩ := hf x,
exact ⟨y, (quotient.map'_mk' f _ y).trans (congr_arg quotient.mk' hy)⟩ },
end
@[to_additive] lemma index_eq_card [fintype (quotient_group.quotient H)] :
H.index = fintype.card (quotient_group.quotient H) :=
cardinal.mk_to_nat_eq_card
@[to_additive] lemma index_mul_card [fintype G] [hH : fintype H] :
H.index * fintype.card H = fintype.card G :=
begin
classical,
rw H.index_eq_card,
apply H.card_eq_card_quotient_mul_card_subgroup.symm,
end
@[to_additive] lemma index_dvd_card [fintype G] : H.index ∣ fintype.card G :=
begin
classical,
exact ⟨fintype.card H, H.index_mul_card.symm⟩,
end
variables {H} {K : subgroup G}
@[to_additive] lemma index_eq_mul_of_le (h : H ≤ K) :
H.index = K.index * (H.subgroup_of K).index :=
(congr_arg cardinal.to_nat (by exact (quotient_equiv_prod_of_le h).cardinal_eq)).trans
(cardinal.to_nat_mul _ _)
@[to_additive] lemma index_dvd_of_le (h : H ≤ K) : K.index ∣ H.index :=
⟨(H.subgroup_of K).index, index_eq_mul_of_le h⟩
end subgroup
|
73dca2493b480ce5383b2e1db5d920ed161dd775 | 71c05f289da9a856f1d16197a32b6a874eb1052e | /hlean/rats.hlean | e2ac740882b1592cce14ddad0a1914d14bf51fdd | [] | no_license | gbaz/works-in-progress | e7701b1c2f8d0cfb6bfb8d84fc4d21ffd9937521 | af7bacd7f68649106a3581c232548958aca79a08 | refs/heads/master | 1,661,485,946,844 | 1,659,018,408,000 | 1,659,018,408,000 | 32,045,948 | 14 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 7,417 | hlean | import types.int algebra.field hit.set_quotient hit.trunc int_order
open eq sigma sigma.ops equiv is_equiv equiv.ops eq.ops int algebra set_quotient is_trunc trunc quotient
record prerat : Type := (num : ℤ) (denom : ℤ) --(dp : denom > 0)
inductive rat_rel : prerat → prerat → Type :=
| Rmk : Π (a b : prerat), int.mul (prerat.num a) (prerat.denom b) =
int.mul (prerat.num b) (prerat.denom a)
→ rat_rel a b
namespace prerat
definition of_int (i : int) : prerat := prerat.mk i (of_num 1)
definition zero : prerat := of_int (of_num 0)
definition one : prerat := of_int (of_num 1)
definition add (a b : prerat) : prerat :=
prerat.mk (num a * denom b + num b * denom a) (denom a * denom b)
definition mul (a b : prerat) : prerat :=
prerat.mk (num a * num b) (denom a * denom b)
definition neg (a : prerat) : prerat :=
prerat.mk (- num a) (denom a)
definition rat_rel_refl (a : ℤ) (b : ℤ) : rat_rel (mk a b) (mk a b) :=
rat_rel.Rmk (prerat.mk a b) (prerat.mk a b) (refl _)
theorem of_int_add (a b : ℤ) : rat_rel (of_int (#int a + b)) (add (of_int a) (of_int b)) :=
begin
esimp [of_int, add, nat.mul, nat.add, one, zero],
rewrite [+int.mul_one],
fapply rat_rel_refl
end
theorem of_int_mul (a b : ℤ) : rat_rel (of_int (#int a * b)) (mul (of_int a) (of_int b)) :=
begin
esimp [of_int, add, nat.mul, mul],
rewrite [+int.mul_one],
fapply rat_rel_refl
end
theorem of_int_neg (a : ℤ) : rat_rel (of_int (#int -a)) (neg (of_int a)) :=
begin
esimp [neg, of_int],
fapply rat_rel_refl
end
theorem of_int.inj {a b : ℤ} : rat_rel (of_int a) (of_int b) → a = b :=
begin
intros,
cases a_1 with [a,b,p],
generalize p,
clear p,
esimp [denom],
rewrite[+mul_one],
intros,
exact p
end
theorem equiv_zero_of_num_eq_zero {a : prerat} (H : num a = of_num 0) : rat_rel a zero :=
rat_rel.Rmk a zero (
begin
rewrite [H],
esimp [zero, of_int, num],
rewrite[+zero_mul]
end
)
theorem num_eq_zero_of_equiv_zero {a : prerat} : rat_rel a zero → num a = 0 :=
begin
intros,
cases a_1 with [a,z,p],
generalize p,
clear p,
esimp [denom],
rewrite [zero_mul,mul_one],
exact (λ x, x),
end
theorem add_rel_add {a1 b1 a2 b2 : prerat} (r1 : rat_rel a1 a2) (r2 : rat_rel b1 b2) : rat_rel (add a1 b1) (add a2 b2) :=
rat_rel.cases_on r1 (λ a_1 a_2 H1,
rat_rel.cases_on r2 (λ b_1 b_2 H2,
rat_rel.Rmk (add a_1 b_1) (add a_2 b_2)
(calc
num (add a_1 b_1) * denom (add a_2 b_2)
= (num a_1 * denom b_1 + num b_1 * denom a_1) * (denom a_2 * denom b_2) : by esimp [add]
... = num a_1 * denom a_2 * denom b_1 * denom b_2 + num b_1 * denom b_2 * denom a_1 * denom a_2 :
by rewrite [mul.right_distrib, *mul.assoc, mul.left_comm (denom b_1), mul.comm (denom b_2), *mul.assoc]
... = num a_2 * denom a_1 * denom b_1 * denom b_2 + num b_2 * denom b_1 * denom a_1 * denom a_2 :
by rewrite [H1, H2]
... = (num a_2 * denom b_2 + num b_2 * denom a_2) * (denom a_1 * denom b_1) :
by rewrite [mul.right_distrib, *mul.assoc, *mul.left_comm (denom b_2), *mul.comm (denom b_1), *mul.assoc, mul.left_comm (denom a_2)]
)
))
/- field operations -/
/-TODO have an ordering on the ints so we can give -/
/-
definition smul (a : ℤ) (b : prerat) (H : a > 0) : prerat :=
prerat.mk (a * num b) (int2nat a H * denom b)
-/
end prerat
/-
definition inv : prerat → prerat
| inv (prerat.mk nat.zero d dp) := zero
| inv (prerat.mk (nat.succ n) d dp) := prerat.mk d (nat.succ n) !of_nat_succ_pos
| inv (prerat.mk -[1+n] d dp) := prerat.mk (-d) (nat.succ n) !of_nat_succ_pos
theorem inv_zero {d : int} (dp : d > 0) : inv (mk nat.zero d dp) = zero :=
begin rewrite [↑inv, ▸*] end
theorem inv_zero' : inv zero = zero := inv_zero (of_nat_succ_pos nat.zero)
theorem inv_of_pos {n d : int} (np : n > 0) (dp : d > 0) : inv (mk n d dp) ≡ mk d n np :=
obtain (n' : nat) (Hn' : n = of_nat n'), from exists_eq_of_nat (le_of_lt np),
have (#nat n' > nat.zero), from lt_of_of_nat_lt_of_nat (Hn' ▸ np),
obtain (k : nat) (Hk : n' = nat.succ k), from nat.exists_eq_succ_of_lt this,
have d * n = d * nat.succ k, by rewrite [Hn', Hk],
Hn'⁻¹ ▸ (Hk⁻¹ ▸ this)
theorem inv_neg {n d : int} (np : n > 0) (dp : d > 0) : inv (mk (-n) d dp) ≡ mk (-d) n np :=
obtain (n' : nat) (Hn' : n = of_nat n'), from exists_eq_of_nat (le_of_lt np),
have (#nat n' > nat.zero), from lt_of_of_nat_lt_of_nat (Hn' ▸ np),
obtain (k : nat) (Hk : n' = nat.succ k), from nat.exists_eq_succ_of_lt this,
have -d * n = -d * nat.succ k, by rewrite [Hn', Hk],
have H3 : inv (mk -[1+k] d dp) ≡ mk (-d) n np, from this,
have H4 : -[1+k] = -n, from calc
-[1+k] = -(nat.succ k) : rfl
... = -n : by rewrite [Hk⁻¹, Hn'],
H4 ▸ H3
theorem inv_of_neg {n d : int} (nn : n < 0) (dp : d > 0) :
inv (mk n d dp) ≡ mk (-d) (-n) (neg_pos_of_neg nn) :=
have inv (mk (-(-n)) d dp) ≡ mk (-d) (-n) (neg_pos_of_neg nn),
from inv_neg (neg_pos_of_neg nn) dp,
!neg_neg ▸ this
theorem of_int.inj {a b : ℤ} : of_int a ≡ of_int b → a = b :=
by rewrite [↑of_int, ↑equiv, *mul_one]; intros; assumption
-/
/-
the rationals
-/
namespace rat
definition rat_rel_trunc (a : prerat) (b : prerat) : hprop := trunctype.mk (trunc -1 (rat_rel a b)) _
definition rat := set_quotient rat_rel_trunc
notation `ℚ` := rat
open nat
definition of_int [coercion] (i : ℤ) : ℚ := set_quotient.class_of rat_rel_trunc (prerat.of_int i)
definition of_nat [coercion] (n : ℕ) : ℚ := n
definition of_num [coercion] [reducible] (n : num) : ℚ := n
definition lift0 (p : prerat) : ℚ := set_quotient.class_of rat_rel_trunc p
definition prerat_refl (a : prerat) : rat_rel_trunc a a := tr (rat_rel.Rmk a a (refl _))
definition lift1 {A : Type} [hs : is_hset A] (f : prerat → A) (coh : Π (p q : prerat), rat_rel_trunc p q -> f p = f q) (r : rat) : A :=
set_quotient.elim_on rat_rel_trunc r f coh
/-
lemma ext_c {A B C : Type} {rel_a : A → A → hprop} {rel_b : B → B → hprop} (f : A -> B -> C) (c : Π (a1 a2 : A) (b1 b2 : B) , rel_a a1 a2 → rel_b b1 b2 → f a1 b1 = f a2 b2) : Π (a1 a2 : A), rel_a a1 a2 → f a1 = f a2 :=
λ (a1 a2 : A) (myrel : rel_a a1 a2), _ (λ (b : B), (c a1 a2 b b myrel sorry))
-/
set_option formatter.hide_full_terms false
definition lift2 {A B C : Type} [hs : is_hset C] {rel_a : A → A → hprop} {rel_b : B → B → hprop} (rel_a_refl : Π (a : A), rel_a a a) (f : A -> B -> C) (c : Π (a1 a2 : A) (b1 b2 : B) , rel_a a1 a2 → rel_b b1 b2 → f a1 b1 = f a2 b2) (q1 : set_quotient rel_a) (q2 : set_quotient rel_b) : C :=
set_quotient.elim_on
rel_a
q1
(λ a, set_quotient.elim_on rel_b q2 (f a) (begin intros, apply c, exact (rel_a_refl a), assumption end))
sorry
/-
(λ (a a' : A) (H : rel_a a a'), ap (λ a1, set_quotient.elim_on rel_b q2 (f a1) (begin intros, apply c, exact (rel_a_refl a1), assumption end)) (ext_c f c a a' H))
-/
theorem rat_is_hset : is_hset ℚ := set_quotient.is_hset_set_quotient rat_rel_trunc
definition lift2rat (f : prerat -> prerat -> ℚ) (c : Π (a1 a2 b1 b2 : prerat), rat_rel_trunc a1 a2 → rat_rel_trunc b1 b2 → f a1 b1 = f a2 b2) := @lift2 prerat prerat ℚ (rat_is_hset) rat_rel_trunc rat_rel_trunc prerat_refl f c
definition add : ℚ → ℚ → ℚ :=
lift2rat
(λ a b : prerat, lift0 (prerat.add a b))
(begin
intros,
apply (set_quotient.eq_of_rel rat_rel_trunc),
apply (trunc.elim_on a (λ a', trunc.elim_on a_1 (λ a_1', tr (prerat.add_rel_add a' a_1'))))
end)
end rat
|
679d61e061a6dd4412bb9997a40f1e95e1c9c3fb | 9cba98daa30c0804090f963f9024147a50292fa0 | /old/metrology/quantity_test.lean | 50c3798ef6ec12285f9212fdbd1e9a8cfb3feec3 | [] | no_license | kevinsullivan/phys | dcb192f7b3033797541b980f0b4a7e75d84cea1a | ebc2df3779d3605ff7a9b47eeda25c2a551e011f | refs/heads/master | 1,637,490,575,500 | 1,629,899,064,000 | 1,629,899,064,000 | 168,012,884 | 0 | 3 | null | 1,629,644,436,000 | 1,548,699,832,000 | Lean | UTF-8 | Lean | false | false | 554 | lean | import .quantity
open quantity
open dimension
open measurementSystem
-- Examples
def oneMeter := mkQuantity BasicDimension.length si_measurement_system (1 : ℝ)
def twoSeconds := mkQuantity BasicDimension.time si_measurement_system (2 : ℝ)
def threePounds := mkQuantity BasicDimension.mass imperial_measurement_system ⟨(3 : ℝ), by linarith ⟩
/-
Kevin: Note that at this point we can only make quantities from basic dimensions,
so if we want a derived quantity, we have to derive it from quantities made in this
way.
-/
#check threePounds
|
8c19b9c64a46b9a5d461ea248a85b5b3a8f65829 | a5271082abc327bbe26fc4acdaa885da9582cefa | /src/test.lean | 814f2d97ac81793cf6332d4a42d2c8eaf0d67ea2 | [
"Apache-2.0"
] | permissive | avigad/embed | 9ee7d104609eeded173ca1e6e7a1925897b1652a | 0e3612028d4039d29d06239ef03bc50576ca0f8b | refs/heads/master | 1,584,548,951,613 | 1,527,883,346,000 | 1,527,883,346,000 | 134,967,973 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 192 | lean | /-example : 1 + 2222 = 2223 :=
begin
reflexivity
end
theorem foo : 1 + (2222222222222 : nat) = 2222222222223 :=
begin
reflexivity
end
-/
theorem bar : 100003 + 100003 = 200006 :=
rfl
|
391630b4de25faf572271d1875c3cf5e9ba9c6e8 | c3de33d4701e6113627153fe1103b255e752ed7d | /data/nat/basic.lean | 43e74d2371736670c4545251a86821d44d03dff9 | [] | no_license | jroesch/library_dev | 77d2b246ff47ab05d55cb9706a37d3de97038388 | 4faa0a45c6aa7eee6e661113c2072b8840bff79b | refs/heads/master | 1,611,281,606,352 | 1,495,661,644,000 | 1,495,661,644,000 | 92,340,430 | 0 | 0 | null | 1,495,663,344,000 | 1,495,663,344,000 | null | UTF-8 | Lean | false | false | 3,255 | lean | /-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad
Basic operations on the natural numbers.
-/
import tools.super.prover
open tactic
namespace nat
-- TODO(gabriel): can we drop addl?
/- a variant of add, defined by recursion on the first argument -/
definition addl : ℕ → ℕ → ℕ
| (succ x) y := succ (addl x y)
| 0 y := y
local infix ` ⊕ `:65 := addl
@[simp] lemma addl_zero_left (n : ℕ) : 0 ⊕ n = n := rfl
@[simp] lemma addl_succ_left (m n : ℕ) : succ m ⊕ n = succ (m ⊕ n) := rfl
@[simp] lemma zero_has_zero : nat.zero = 0 := rfl
local attribute [simp] nat.add_zero nat.add_succ nat.zero_add nat.succ_add
@[simp] theorem addl_zero_right (n : ℕ) : n ⊕ 0 = n :=
begin induction n, simp, simp [ih_1] end
@[simp] theorem addl_succ_right (n m : ℕ) : n ⊕ succ m = succ (n ⊕ m) :=
begin induction n, simp, simp [ih_1] end
@[simp] theorem add_eq_addl (x y : ℕ) : x ⊕ y = x + y :=
begin induction x, simp, simp [ih_1] end
/- successor and predecessor -/
theorem add_one_ne_zero (n : ℕ) : n + 1 ≠ 0 := succ_ne_zero _
theorem eq_zero_or_eq_succ_pred (n : ℕ) : n = 0 ∨ n = succ (pred n) :=
begin induction n, repeat { super } end
theorem exists_eq_succ_of_ne_zero {n : ℕ} (H : n ≠ 0) : ∃k : ℕ, n = succ k :=
by super with nat.eq_zero_or_eq_succ_pred
theorem succ_inj {n m : ℕ} (H : succ n = succ m) : n = m := by super
theorem discriminate {B : Type _} {n : ℕ} (H1: n = 0 → B) (H2 : ∀m, n = succ m → B) : B :=
begin cases n, super, super end
lemma one_succ_zero : 1 = succ 0 := rfl
local attribute [simp] one_succ_zero
theorem two_step_induction_on {P : ℕ → Prop} (a : ℕ) (H1 : P 0) (H2 : P 1)
(H3 : ∀ (n : ℕ) (IH1 : P n) (IH2 : P (succ n)), P (succ (succ n))) : P a :=
begin assert stronger : P a ∧ P (succ a), induction a,
repeat { super with nat.one_succ_zero } end
theorem sub_induction {P : ℕ → ℕ → Prop} (n m : ℕ) (H1 : ∀m, P 0 m)
(H2 : ∀n, P (succ n) 0) (H3 : ∀n m, P n m → P (succ n) (succ m)) : P n m :=
begin assert general : ∀m, P n m,
induction n, super with nat.one_succ_zero, intro, induction m_1,
repeat { super with nat.one_succ_zero } end
/- addition -/
/-
Remark: we use 'local attributes' because in the end of the file
we show nat is a comm_semiring, and we will automatically inherit
the associated [simp] lemmas from algebra
-/
theorem succ_add_eq_succ_add (n m : ℕ) : succ n + m = n + succ m := by simp
local attribute [simp] nat.add_comm nat.add_assoc nat.add_left_comm
theorem eq_zero_and_eq_zero_of_add_eq_zero {n m : ℕ} (H : n + m = 0) : n = 0 ∧ m = 0 :=
⟨nat.eq_zero_of_add_eq_zero_right H, nat.eq_zero_of_add_eq_zero_left H⟩
theorem add_one (n : ℕ) : n + 1 = succ n := rfl
-- TODO(gabriel): make add_one and one_add global simp lemmas?
local attribute [simp] add_one
theorem one_add (n : ℕ) : 1 + n = succ n := by simp
local attribute [simp] one_add
end nat
section
open nat
definition iterate {A : Type} (op : A → A) : ℕ → A → A
| 0 := λ a, a
| (succ k) := λ a, op (iterate k a)
notation f`^[`n`]` := iterate f n
end
|
9165f4c55a4a356c084e81932dc52749a294320b | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/1143.lean | 355c330632d2e2f3b563d09068b9598e94d7231c | [
"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 | 135 | lean | inductive Foo
| foo | bar
def baz (b : Bool) (x : Foo := .foo) : Foo := Id.run <| do
let mut y := x
if b then
y := .bar
y
|
109626eb87aadf489b99f4b0f4475b69ebf1bb1c | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/tactic/algebra_auto.lean | dca578fcc022ed93327e62240f02a35d15eee4c2 | [] | 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 | 309 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.core
import Mathlib.PostPort
namespace Mathlib
namespace tactic
end Mathlib |
ab15d9ac91dc290e1e67f55ccfda7ff9e6c51671 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/qpf/multivariate/constructions/comp.lean | 00e56d65ee4c59ef3068a65986e84a1b21f3ff7b | [
"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 | 2,662 | lean | /-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Simon Hudon
-/
import data.pfunctor.multivariate.basic
import data.qpf.multivariate.basic
/-!
# The composition of QPFs is itself a QPF
We define composition between one `n`-ary functor and `n` `m`-ary functors
and show that it preserves the QPF structure
-/
universes u
namespace mvqpf
open_locale mvfunctor
variables {n m : ℕ}
(F : typevec.{u} n → Type*) [fF : mvfunctor F] [q : mvqpf F]
(G : fin2 n → typevec.{u} m → Type u) [fG : ∀ i, mvfunctor $ G i] [q' : ∀ i, mvqpf $ G i]
/-- Composition of an `n`-ary functor with `n` `m`-ary
functors gives us one `m`-ary functor -/
def comp (v : typevec.{u} m) : Type* :=
F $ λ i : fin2 n, G i v
namespace comp
open mvfunctor mvpfunctor
variables {F G} {α β : typevec.{u} m} (f : α ⟹ β)
instance [I : inhabited (F $ λ i : fin2 n, G i α)] : inhabited (comp F G α) := I
/-- Constructor for functor composition -/
protected def mk (x : F $ λ i, G i α) : (comp F G) α := x
/-- Destructor for functor composition -/
protected def get (x : (comp F G) α) : F $ λ i, G i α := x
@[simp] protected lemma mk_get (x : (comp F G) α) : comp.mk (comp.get x) = x := rfl
@[simp] protected lemma get_mk (x : F $ λ i, G i α) : comp.get (comp.mk x) = x := rfl
include fG
/-- map operation defined on a vector of functors -/
protected def map' : (λ (i : fin2 n), G i α) ⟹ λ (i : fin2 n), G i β :=
λ i, map f
include fF
/-- The composition of functors is itself functorial -/
protected def map : (comp F G) α → (comp F G) β :=
(map (λ i, map f) : F (λ i, G i α) → F (λ i, G i β))
instance : mvfunctor (comp F G) :=
{ map := λ α β, comp.map }
lemma map_mk (x : F $ λ i, G i α) :
f <$$> comp.mk x = comp.mk ((λ i (x : G i α), f <$$> x) <$$> x) := rfl
lemma get_map (x : comp F G α) :
comp.get (f <$$> x) = (λ i (x : G i α), f <$$> x) <$$> comp.get x := rfl
include q q'
instance : mvqpf (comp F G) :=
{ P := mvpfunctor.comp (P F) (λ i, P $ G i),
abs := λ α, comp.mk ∘ map (λ i, abs) ∘ abs ∘ mvpfunctor.comp.get,
repr := λ α, mvpfunctor.comp.mk ∘ repr ∘
map (λ i, (repr : G i α → (λ (i : fin2 n), obj (P (G i)) α) i)) ∘ comp.get,
abs_repr := by { intros, simp [(∘), mvfunctor.map_map, (⊚), abs_repr] },
abs_map := by { intros, simp [(∘)], rw [← abs_map],
simp [mvfunctor.id_map, (⊚), map_mk, mvpfunctor.comp.get_map, abs_map,
mvfunctor.map_map, abs_repr] } }
end comp
end mvqpf
|
f439b8f35db39b9fe5fc716da9efd7bccb4c2897 | bb31430994044506fa42fd667e2d556327e18dfe | /src/topology/continuous_function/stone_weierstrass.lean | 581de93c3648ea7d0870d6ebbd3bf839c2a8c333 | [
"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 | 21,051 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Heather Macbeth
-/
import topology.continuous_function.weierstrass
import data.complex.is_R_or_C
/-!
# The Stone-Weierstrass theorem
If a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
separates points, then it is dense.
We argue as follows.
* In any subalgebra `A` of `C(X, ℝ)`, if `f ∈ A`, then `abs f ∈ A.topological_closure`.
This follows from the Weierstrass approximation theorem on `[-‖f‖, ‖f‖]` by
approximating `abs` uniformly thereon by polynomials.
* This ensures that `A.topological_closure` is actually a sublattice:
if it contains `f` and `g`, then it contains the pointwise supremum `f ⊔ g`
and the pointwise infimum `f ⊓ g`.
* Any nonempty sublattice `L` of `C(X, ℝ)` which separates points is dense,
by a nice argument approximating a given `f` above and below using separating functions.
For each `x y : X`, we pick a function `g x y ∈ L` so `g x y x = f x` and `g x y y = f y`.
By continuity these functions remain close to `f` on small patches around `x` and `y`.
We use compactness to identify a certain finitely indexed infimum of finitely indexed supremums
which is then close to `f` everywhere, obtaining the desired approximation.
* Finally we put these pieces together. `L = A.topological_closure` is a nonempty sublattice
which separates points since `A` does, and so is dense (in fact equal to `⊤`).
We then prove the complex version for self-adjoint subalgebras `A`, by separately approximating
the real and imaginary parts using the real subalgebra of real-valued functions in `A`
(which still separates points, by taking the norm-square of a separating function).
## Future work
Extend to cover the case of subalgebras of the continuous functions vanishing at infinity,
on non-compact spaces.
-/
noncomputable theory
namespace continuous_map
variables {X : Type*} [topological_space X] [compact_space X]
open_locale polynomial
/--
Turn a function `f : C(X, ℝ)` into a continuous map into `set.Icc (-‖f‖) (‖f‖)`,
thereby explicitly attaching bounds.
-/
def attach_bound (f : C(X, ℝ)) : C(X, set.Icc (-‖f‖) (‖f‖)) :=
{ to_fun := λ x, ⟨f x, ⟨neg_norm_le_apply f x, apply_le_norm f x⟩⟩ }
@[simp] lemma attach_bound_apply_coe (f : C(X, ℝ)) (x : X) : ((attach_bound f) x : ℝ) = f x := rfl
lemma polynomial_comp_attach_bound (A : subalgebra ℝ C(X, ℝ)) (f : A) (g : ℝ[X]) :
(g.to_continuous_map_on (set.Icc (-‖f‖) ‖f‖)).comp (f : C(X, ℝ)).attach_bound =
polynomial.aeval f g :=
begin
ext,
simp only [continuous_map.coe_comp, function.comp_app,
continuous_map.attach_bound_apply_coe,
polynomial.to_continuous_map_on_apply,
polynomial.aeval_subalgebra_coe,
polynomial.aeval_continuous_map_apply,
polynomial.to_continuous_map_apply],
end
/--
Given a continuous function `f` in a subalgebra of `C(X, ℝ)`, postcomposing by a polynomial
gives another function in `A`.
This lemma proves something slightly more subtle than this:
we take `f`, and think of it as a function into the restricted target `set.Icc (-‖f‖) ‖f‖)`,
and then postcompose with a polynomial function on that interval.
This is in fact the same situation as above, and so also gives a function in `A`.
-/
lemma polynomial_comp_attach_bound_mem (A : subalgebra ℝ C(X, ℝ)) (f : A) (g : ℝ[X]) :
(g.to_continuous_map_on (set.Icc (-‖f‖) ‖f‖)).comp (f : C(X, ℝ)).attach_bound ∈ A :=
begin
rw polynomial_comp_attach_bound,
apply set_like.coe_mem,
end
theorem comp_attach_bound_mem_closure
(A : subalgebra ℝ C(X, ℝ)) (f : A) (p : C(set.Icc (-‖f‖) (‖f‖), ℝ)) :
p.comp (attach_bound f) ∈ A.topological_closure :=
begin
-- `p` itself is in the closure of polynomials, by the Weierstrass theorem,
have mem_closure : p ∈ (polynomial_functions (set.Icc (-‖f‖) (‖f‖))).topological_closure :=
continuous_map_mem_polynomial_functions_closure _ _ p,
-- and so there are polynomials arbitrarily close.
have frequently_mem_polynomials := mem_closure_iff_frequently.mp mem_closure,
-- To prove `p.comp (attached_bound f)` is in the closure of `A`,
-- we show there are elements of `A` arbitrarily close.
apply mem_closure_iff_frequently.mpr,
-- To show that, we pull back the polynomials close to `p`,
refine ((comp_right_continuous_map ℝ (attach_bound (f : C(X, ℝ)))).continuous_at p).tendsto
.frequently_map _ _ frequently_mem_polynomials,
-- but need to show that those pullbacks are actually in `A`.
rintros _ ⟨g, ⟨-,rfl⟩⟩,
simp only [set_like.mem_coe, alg_hom.coe_to_ring_hom, comp_right_continuous_map_apply,
polynomial.to_continuous_map_on_alg_hom_apply],
apply polynomial_comp_attach_bound_mem,
end
theorem abs_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f : A) :
(f : C(X, ℝ)).abs ∈ A.topological_closure :=
begin
let M := ‖f‖,
let f' := attach_bound (f : C(X, ℝ)),
let abs : C(set.Icc (-‖f‖) (‖f‖), ℝ) :=
{ to_fun := λ x : set.Icc (-‖f‖) (‖f‖), |(x : ℝ)| },
change (abs.comp f') ∈ A.topological_closure,
apply comp_attach_bound_mem_closure,
end
theorem inf_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A.topological_closure :=
begin
rw inf_eq,
refine A.topological_closure.smul_mem
(A.topological_closure.sub_mem
(A.topological_closure.add_mem (A.le_topological_closure f.property)
(A.le_topological_closure g.property)) _) _,
exact_mod_cast abs_mem_subalgebra_closure A _,
end
theorem inf_mem_closed_subalgebra (A : subalgebra ℝ C(X, ℝ)) (h : is_closed (A : set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A :=
begin
convert inf_mem_subalgebra_closure A f g,
apply set_like.ext',
symmetry,
erw closure_eq_iff_is_closed,
exact h,
end
theorem sup_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A.topological_closure :=
begin
rw sup_eq,
refine A.topological_closure.smul_mem
(A.topological_closure.add_mem
(A.topological_closure.add_mem (A.le_topological_closure f.property)
(A.le_topological_closure g.property)) _) _,
exact_mod_cast abs_mem_subalgebra_closure A _,
end
theorem sup_mem_closed_subalgebra (A : subalgebra ℝ C(X, ℝ)) (h : is_closed (A : set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A :=
begin
convert sup_mem_subalgebra_closure A f g,
apply set_like.ext',
symmetry,
erw closure_eq_iff_is_closed,
exact h,
end
open_locale topological_space
-- Here's the fun part of Stone-Weierstrass!
theorem sublattice_closure_eq_top
(L : set C(X, ℝ)) (nA : L.nonempty)
(inf_mem : ∀ f g ∈ L, f ⊓ g ∈ L) (sup_mem : ∀ f g ∈ L, f ⊔ g ∈ L)
(sep : L.separates_points_strongly) :
closure L = ⊤ :=
begin
-- We start by boiling down to a statement about close approximation.
apply eq_top_iff.mpr,
rintros f -,
refine filter.frequently.mem_closure
((filter.has_basis.frequently_iff metric.nhds_basis_ball).mpr (λ ε pos, _)),
simp only [exists_prop, metric.mem_ball],
-- It will be helpful to assume `X` is nonempty later,
-- so we get that out of the way here.
by_cases nX : nonempty X,
swap,
exact ⟨nA.some, (dist_lt_iff pos).mpr (λ x, false.elim (nX ⟨x⟩)), nA.some_spec⟩,
/-
The strategy now is to pick a family of continuous functions `g x y` in `A`
with the property that `g x y x = f x` and `g x y y = f y`
(this is immediate from `h : separates_points_strongly`)
then use continuity to see that `g x y` is close to `f` near both `x` and `y`,
and finally using compactness to produce the desired function `h`
as a maximum over finitely many `x` of a minimum over finitely many `y` of the `g x y`.
-/
dsimp [set.separates_points_strongly] at sep,
let g : X → X → L := λ x y, (sep f x y).some,
have w₁ : ∀ x y, g x y x = f x := λ x y, (sep f x y).some_spec.1,
have w₂ : ∀ x y, g x y y = f y := λ x y, (sep f x y).some_spec.2,
-- For each `x y`, we define `U x y` to be `{z | f z - ε < g x y z}`,
-- and observe this is a neighbourhood of `y`.
let U : X → X → set X := λ x y, {z | f z - ε < g x y z},
have U_nhd_y : ∀ x y, U x y ∈ 𝓝 y,
{ intros x y,
refine is_open.mem_nhds _ _,
{ apply is_open_lt; continuity, },
{ rw [set.mem_set_of_eq, w₂],
exact sub_lt_self _ pos, }, },
-- Fixing `x` for a moment, we have a family of functions `λ y, g x y`
-- which on different patches (the `U x y`) are greater than `f z - ε`.
-- Taking the supremum of these functions
-- indexed by a finite collection of patches which cover `X`
-- will give us an element of `A` that is globally greater than `f z - ε`
-- and still equal to `f x` at `x`.
-- Since `X` is compact, for every `x` there is some finset `ys t`
-- so the union of the `U x y` for `y ∈ ys x` still covers everything.
let ys : Π x, finset X := λ x, (compact_space.elim_nhds_subcover (U x) (U_nhd_y x)).some,
let ys_w : ∀ x, (⋃ y ∈ ys x, U x y) = ⊤ :=
λ x, (compact_space.elim_nhds_subcover (U x) (U_nhd_y x)).some_spec,
have ys_nonempty : ∀ x, (ys x).nonempty :=
λ x, set.nonempty_of_union_eq_top_of_nonempty _ _ nX (ys_w x),
-- Thus for each `x` we have the desired `h x : A` so `f z - ε < h x z` everywhere
-- and `h x x = f x`.
let h : Π x, L := λ x,
⟨(ys x).sup' (ys_nonempty x) (λ y, (g x y : C(X, ℝ))),
finset.sup'_mem _ sup_mem _ _ _ (λ y _, (g x y).2)⟩,
have lt_h : ∀ x z, f z - ε < h x z,
{ intros x z,
obtain ⟨y, ym, zm⟩ := set.exists_set_mem_of_union_eq_top _ _ (ys_w x) z,
dsimp [h],
simp only [coe_fn_coe_base', subtype.coe_mk, sup'_coe, finset.sup'_apply, finset.lt_sup'_iff],
exact ⟨y, ym, zm⟩ },
have h_eq : ∀ x, h x x = f x,
{ intro x, simp only [coe_fn_coe_base'] at w₁, simp [coe_fn_coe_base', w₁], },
-- For each `x`, we define `W x` to be `{z | h x z < f z + ε}`,
let W : Π x, set X := λ x, {z | h x z < f z + ε},
-- This is still a neighbourhood of `x`.
have W_nhd : ∀ x, W x ∈ 𝓝 x,
{ intros x,
refine is_open.mem_nhds _ _,
{ apply is_open_lt; continuity, },
{ dsimp only [W, set.mem_set_of_eq],
rw h_eq,
exact lt_add_of_pos_right _ pos}, },
-- Since `X` is compact, there is some finset `ys t`
-- so the union of the `W x` for `x ∈ xs` still covers everything.
let xs : finset X := (compact_space.elim_nhds_subcover W W_nhd).some,
let xs_w : (⋃ x ∈ xs, W x) = ⊤ :=
(compact_space.elim_nhds_subcover W W_nhd).some_spec,
have xs_nonempty : xs.nonempty := set.nonempty_of_union_eq_top_of_nonempty _ _ nX xs_w,
-- Finally our candidate function is the infimum over `x ∈ xs` of the `h x`.
-- This function is then globally less than `f z + ε`.
let k : (L : Type*) :=
⟨xs.inf' xs_nonempty (λ x, (h x : C(X, ℝ))),
finset.inf'_mem _ inf_mem _ _ _ (λ x _, (h x).2)⟩,
refine ⟨k.1, _, k.2⟩,
-- We just need to verify the bound, which we do pointwise.
rw dist_lt_iff pos,
intro z,
-- We rewrite into this particular form,
-- so that simp lemmas about inequalities involving `finset.inf'` can fire.
rw [(show ∀ a b ε : ℝ, dist a b < ε ↔ a < b + ε ∧ b - ε < a,
by { intros, simp only [← metric.mem_ball, real.ball_eq_Ioo, set.mem_Ioo, and_comm], })],
fsplit,
{ dsimp [k],
simp only [finset.inf'_lt_iff, continuous_map.inf'_apply],
exact set.exists_set_mem_of_union_eq_top _ _ xs_w z, },
{ dsimp [k],
simp only [finset.lt_inf'_iff, continuous_map.inf'_apply],
intros x xm,
apply lt_h, },
end
/--
The **Stone-Weierstrass Approximation Theorem**,
that a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
is dense if it separates points.
-/
theorem subalgebra_topological_closure_eq_top_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points) :
A.topological_closure = ⊤ :=
begin
-- The closure of `A` is closed under taking `sup` and `inf`,
-- and separates points strongly (since `A` does),
-- so we can apply `sublattice_closure_eq_top`.
apply set_like.ext',
let L := A.topological_closure,
have n : set.nonempty (L : set C(X, ℝ)) :=
⟨(1 : C(X, ℝ)), A.le_topological_closure A.one_mem⟩,
convert sublattice_closure_eq_top
(L : set C(X, ℝ)) n
(λ f fm g gm, inf_mem_closed_subalgebra L A.is_closed_topological_closure ⟨f, fm⟩ ⟨g, gm⟩)
(λ f fm g gm, sup_mem_closed_subalgebra L A.is_closed_topological_closure ⟨f, fm⟩ ⟨g, gm⟩)
(subalgebra.separates_points.strongly
(subalgebra.separates_points_monotone (A.le_topological_closure) w)),
{ simp, },
end
/--
An alternative statement of the Stone-Weierstrass theorem.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is a uniform limit of elements of `A`.
-/
theorem continuous_map_mem_subalgebra_closure_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : C(X, ℝ)) :
f ∈ A.topological_closure :=
begin
rw subalgebra_topological_closure_eq_top_of_separates_points A w,
simp,
end
/--
An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuous_map_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : C(X, ℝ)) (ε : ℝ) (pos : 0 < ε) :
∃ (g : A), ‖(g : C(X, ℝ)) - f‖ < ε :=
begin
have w := mem_closure_iff_frequently.mp
(continuous_map_mem_subalgebra_closure_of_separates_points A w f),
rw metric.nhds_basis_ball.frequently_iff at w,
obtain ⟨g, H, m⟩ := w ε pos,
rw [metric.mem_ball, dist_eq_norm] at H,
exact ⟨⟨g, m⟩, H⟩,
end
/--
An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons and don't like bundled continuous functions.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuous_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : X → ℝ) (c : continuous f) (ε : ℝ) (pos : 0 < ε) :
∃ (g : A), ∀ x, ‖g x - f x‖ < ε :=
begin
obtain ⟨g, b⟩ := exists_mem_subalgebra_near_continuous_map_of_separates_points A w ⟨f, c⟩ ε pos,
use g,
rwa norm_lt_iff _ pos at b,
end
end continuous_map
section is_R_or_C
open is_R_or_C
-- Redefine `X`, since for the next few lemmas it need not be compact
variables {𝕜 : Type*} {X : Type*} [is_R_or_C 𝕜] [topological_space X]
namespace continuous_map
/-- A real subalgebra of `C(X, 𝕜)` is `conj_invariant`, if it contains all its conjugates. -/
def conj_invariant_subalgebra (A : subalgebra ℝ C(X, 𝕜)) : Prop :=
A.map (conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) ≤ A
lemma mem_conj_invariant_subalgebra {A : subalgebra ℝ C(X, 𝕜)} (hA : conj_invariant_subalgebra A)
{f : C(X, 𝕜)} (hf : f ∈ A) :
(conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) f ∈ A :=
hA ⟨f, hf, rfl⟩
/-- If a set `S` is conjugation-invariant, then its `𝕜`-span is conjugation-invariant. -/
lemma subalgebra_conj_invariant {S : set C(X, 𝕜)}
(hS : ∀ f, f ∈ S → (conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) f ∈ S) :
conj_invariant_subalgebra ((algebra.adjoin 𝕜 S).restrict_scalars ℝ) :=
begin
rintros _ ⟨f, hf, rfl⟩,
change _ ∈ ((algebra.adjoin 𝕜 S).restrict_scalars ℝ),
change _ ∈ ((algebra.adjoin 𝕜 S).restrict_scalars ℝ) at hf,
rw subalgebra.mem_restrict_scalars at hf ⊢,
apply algebra.adjoin_induction hf,
{ exact λ g hg, algebra.subset_adjoin (hS g hg), },
{ exact λ c, subalgebra.algebra_map_mem _ (star_ring_end 𝕜 c) },
{ intros f g hf hg,
convert subalgebra.add_mem _ hf hg,
exact alg_hom.map_add _ f g },
{ intros f g hf hg,
convert subalgebra.mul_mem _ hf hg,
exact alg_hom.map_mul _ f g, }
end
end continuous_map
open continuous_map
/-- If a conjugation-invariant subalgebra of `C(X, 𝕜)` separates points, then the real subalgebra
of its purely real-valued elements also separates points. -/
lemma subalgebra.separates_points.is_R_or_C_to_real {A : subalgebra 𝕜 C(X, 𝕜)}
(hA : A.separates_points) (hA' : conj_invariant_subalgebra (A.restrict_scalars ℝ)) :
((A.restrict_scalars ℝ).comap
(of_real_am.comp_left_continuous ℝ continuous_of_real)).separates_points :=
begin
intros x₁ x₂ hx,
-- Let `f` in the subalgebra `A` separate the points `x₁`, `x₂`
obtain ⟨_, ⟨f, hfA, rfl⟩, hf⟩ := hA hx,
let F : C(X, 𝕜) := f - const _ (f x₂),
-- Subtract the constant `f x₂` from `f`; this is still an element of the subalgebra
have hFA : F ∈ A,
{ refine A.sub_mem hfA (@eq.subst _ (∈ A) _ _ _ $ A.smul_mem A.one_mem $ f x₂),
ext1, simp only [coe_smul, coe_one, pi.smul_apply,
pi.one_apply, algebra.id.smul_eq_mul, mul_one, const_apply] },
-- Consider now the function `λ x, |f x - f x₂| ^ 2`
refine ⟨_, ⟨(⟨is_R_or_C.norm_sq, continuous_norm_sq⟩ : C(𝕜, ℝ)).comp F, _, rfl⟩, _⟩,
{ -- This is also an element of the subalgebra, and takes only real values
rw [set_like.mem_coe, subalgebra.mem_comap],
convert (A.restrict_scalars ℝ).mul_mem (mem_conj_invariant_subalgebra hA' hFA) hFA,
ext1,
rw [mul_comm],
exact (is_R_or_C.mul_conj _).symm },
{ -- And it also separates the points `x₁`, `x₂`
have : f x₁ - f x₂ ≠ 0 := sub_ne_zero.mpr hf,
simpa only [comp_apply, coe_sub, coe_const, pi.sub_apply,
coe_mk, sub_self, map_zero, ne.def, norm_sq_eq_zero] using this },
end
variables [compact_space X]
/--
The Stone-Weierstrass approximation theorem, `is_R_or_C` version,
that a subalgebra `A` of `C(X, 𝕜)`, where `X` is a compact topological space and `is_R_or_C 𝕜`,
is dense if it is conjugation-invariant and separates points.
-/
theorem continuous_map.subalgebra_is_R_or_C_topological_closure_eq_top_of_separates_points
(A : subalgebra 𝕜 C(X, 𝕜)) (hA : A.separates_points)
(hA' : conj_invariant_subalgebra (A.restrict_scalars ℝ)) :
A.topological_closure = ⊤ :=
begin
rw algebra.eq_top_iff,
-- Let `I` be the natural inclusion of `C(X, ℝ)` into `C(X, 𝕜)`
let I : C(X, ℝ) →ₗ[ℝ] C(X, 𝕜) := of_real_clm.comp_left_continuous ℝ X,
-- The main point of the proof is that its range (i.e., every real-valued function) is contained
-- in the closure of `A`
have key : I.range ≤ (A.to_submodule.restrict_scalars ℝ).topological_closure,
{ -- Let `A₀` be the subalgebra of `C(X, ℝ)` consisting of `A`'s purely real elements; it is the
-- preimage of `A` under `I`. In this argument we only need its submodule structure.
let A₀ : submodule ℝ C(X, ℝ) := (A.to_submodule.restrict_scalars ℝ).comap I,
-- By `subalgebra.separates_points.complex_to_real`, this subalgebra also separates points, so
-- we may apply the real Stone-Weierstrass result to it.
have SW : A₀.topological_closure = ⊤,
{ have := subalgebra_topological_closure_eq_top_of_separates_points _
(hA.is_R_or_C_to_real hA'),
exact congr_arg subalgebra.to_submodule this },
rw [← submodule.map_top, ← SW],
-- So it suffices to prove that the image under `I` of the closure of `A₀` is contained in the
-- closure of `A`, which follows by abstract nonsense
have h₁ := A₀.topological_closure_map ((@of_real_clm 𝕜 _).comp_left_continuous_compact X),
have h₂ := (A.to_submodule.restrict_scalars ℝ).map_comap_le I,
exact h₁.trans (submodule.topological_closure_mono h₂) },
-- In particular, for a function `f` in `C(X, 𝕜)`, the real and imaginary parts of `f` are in the
-- closure of `A`
intros f,
let f_re : C(X, ℝ) := (⟨is_R_or_C.re, is_R_or_C.re_clm.continuous⟩ : C(𝕜, ℝ)).comp f,
let f_im : C(X, ℝ) := (⟨is_R_or_C.im, is_R_or_C.im_clm.continuous⟩ : C(𝕜, ℝ)).comp f,
have h_f_re : I f_re ∈ A.topological_closure := key ⟨f_re, rfl⟩,
have h_f_im : I f_im ∈ A.topological_closure := key ⟨f_im, rfl⟩,
-- So `f_re + I • f_im` is in the closure of `A`
convert A.topological_closure.add_mem h_f_re (A.topological_closure.smul_mem h_f_im is_R_or_C.I),
-- And this, of course, is just `f`
ext,
apply eq.symm,
simp [I, mul_comm is_R_or_C.I _],
end
end is_R_or_C
|
cf18367005f2ad35f6ffe6093be2f526fd84658c | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /tests/lean/run/coeIssues4.lean | f96296207b141ae1c9a156cc056ec301e61debed | [
"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 | 534 | lean |
def f : List Int → Bool := fun _ => true
def ex3 : IO Bool := do
let xs ← pure [1, 2, 3];
pure $ f xs -- Works
inductive Expr
| val : Nat → Expr
| app : Expr → Expr → Expr
instance : Coe Nat Expr := ⟨Expr.val⟩
def foo : Expr → Expr := fun e => e
def ex1 : Bool :=
f [1, 2, 3] -- Works
def ex2 : Bool :=
let xs := [1, 2, 3];
f xs -- Works
def ex4 :=
[1, 2, 3].map $ fun x => x+1
def ex5 (xs : List String) :=
xs.foldl (fun r x => r.push x) Array.empty
set_option pp.all true
#check foo 1
def ex6 :=
foo 1
|
9b7d9ce1064cfc58096b0bb4eacb3e7b48fd2bd1 | 969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb | /src/topology/algebra/algebra.lean | 6d263e60b12a51f5b96a6696183589fce89b04b9 | [
"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 | 2,926 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.algebra.subalgebra
import topology.algebra.module
/-!
# Topological (sub)algebras
A topological algebra over a topological ring `R` is a
topological ring with a compatible continuous scalar multiplication by elements of `R`.
## Results
This is just a minimal stub for now!
The topological closure of a subalgebra is still a subalgebra,
which as an algebra is a topological algebra.
-/
open classical set topological_space algebra
open_locale classical
universes u v w
section topological_algebra
variables (R : Type*) [topological_space R] [comm_ring R] [topological_ring R]
variables (A : Type u) [topological_space A]
variables [ring A]
/-- A topological algebra over a topological ring `R` is a
topological ring with a compatible continuous scalar multiplication by elements of `R`. -/
class topological_algebra [algebra R A] [topological_ring A] : Prop :=
(continuous_algebra_map : continuous (algebra_map R A))
attribute [continuity] topological_algebra.continuous_algebra_map
end topological_algebra
section topological_algebra
variables {R : Type*} [comm_ring R]
variables {A : Type u} [topological_space A]
variables [ring A]
variables [algebra R A] [topological_ring A]
@[priority 200] -- see Note [lower instance priority]
instance topological_algebra.to_topological_module
[topological_space R] [topological_ring R] [topological_algebra R A] :
topological_semimodule R A :=
{ continuous_smul := begin
simp_rw algebra.smul_def,
continuity,
end, }
/-- The closure of a subalgebra in a topological algebra as a subalgebra. -/
def subalgebra.topological_closure (s : subalgebra R A) : subalgebra R A :=
{ carrier := closure (s : set A),
algebra_map_mem' := λ r, s.to_subring.subring_topological_closure (s.algebra_map_mem r),
..s.to_subring.topological_closure }
instance subalgebra.topological_closure_topological_ring (s : subalgebra R A) :
topological_ring (s.topological_closure) :=
s.to_subring.topological_closure_topological_ring
instance subalgebra.topological_closure_topological_algebra
[topological_space R] [topological_ring R] [topological_algebra R A] (s : subalgebra R A) :
topological_algebra R (s.topological_closure) :=
{ continuous_algebra_map :=
begin
change continuous (λ r, _),
continuity,
end }
lemma subalgebra.subring_topological_closure (s : subalgebra R A) :
s ≤ s.topological_closure :=
subset_closure
lemma subalgebra.is_closed_topological_closure (s : subalgebra R A) :
is_closed (s.topological_closure : set A) :=
by convert is_closed_closure
lemma subalgebra.topological_closure_minimal
(s : subalgebra R A) {t : subalgebra R A} (h : s ≤ t) (ht : is_closed (t : set A)) :
s.topological_closure ≤ t :=
closure_minimal h ht
end topological_algebra
|
c5bade9a43e9174f84f10f6b76617bfafd8ec5f1 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/topology/algebra/ring.lean | b12b9aecb6746662bb2c0c0ee65c838e7c944f1f | [
"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 | 4,007 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
Theory of topological rings.
-/
import topology.algebra.group
import ring_theory.ideals
open classical set filter topological_space
open_locale classical
section topological_ring
universes u v w
variables (α : Type u) [topological_space α]
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A topological semiring is a semiring where addition and multiplication are continuous. -/
class topological_semiring [semiring α]
extends has_continuous_add α, has_continuous_mul α : Prop
end prio
variables [ring α]
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A topological ring is a ring where the ring operations are continuous. -/
class topological_ring extends has_continuous_add α, has_continuous_mul α : Prop :=
(continuous_neg : continuous (λa:α, -a))
end prio
variables [t : topological_ring α]
@[priority 100] -- see Note [lower instance priority]
instance topological_ring.to_topological_semiring : topological_semiring α := {..t}
@[priority 100] -- see Note [lower instance priority]
instance topological_ring.to_topological_add_group : topological_add_group α := {..t}
end topological_ring
section topological_comm_ring
variables {α : Type*} [topological_space α] [comm_ring α] [topological_ring α]
def ideal.closure (S : ideal α) : ideal α :=
{ carrier := closure S,
zero_mem' := subset_closure S.zero_mem,
add_mem' := assume x y hx hy,
mem_closure2 continuous_add hx hy $ assume a b, S.add_mem,
smul_mem' := assume c x hx,
have continuous (λx:α, c * x) := continuous_const.mul continuous_id,
mem_closure this hx $ assume a, S.mul_mem_left }
@[simp] lemma ideal.coe_closure (S : ideal α) :
(S.closure : set α) = closure S := rfl
end topological_comm_ring
section topological_ring
variables {α : Type*} [topological_space α] [comm_ring α] (N : ideal α)
open ideal.quotient
instance topological_ring_quotient_topology : topological_space N.quotient :=
by dunfold ideal.quotient submodule.quotient; apply_instance
lemma quotient_ring_saturate {α : Type*} [comm_ring α] (N : ideal α) (s : set α) :
mk N ⁻¹' (mk N '' s) = (⋃ x : N, (λ y, x.1 + y) '' s) :=
begin
ext x,
simp only [mem_preimage, mem_image, mem_Union, ideal.quotient.eq],
split,
{ exact assume ⟨a, a_in, h⟩, ⟨⟨_, N.neg_mem h⟩, a, a_in, by simp⟩ },
{ exact assume ⟨⟨i, hi⟩, a, ha, eq⟩, ⟨a, ha,
by rw [← eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub];
exact N.neg_mem hi⟩ }
end
variable [topological_ring α]
lemma quotient_ring.is_open_map_coe : is_open_map (mk N) :=
begin
assume s s_op,
show is_open (mk N ⁻¹' (mk N '' s)),
rw quotient_ring_saturate N s,
exact is_open_Union (assume ⟨n, _⟩, is_open_map_add_left n s s_op)
end
lemma quotient_ring.quotient_map_coe_coe : quotient_map (λ p : α × α, (mk N p.1, mk N p.2)) :=
begin
apply is_open_map.to_quotient_map,
{ exact (quotient_ring.is_open_map_coe N).prod (quotient_ring.is_open_map_coe N) },
{ exact (continuous_quot_mk.comp continuous_fst).prod_mk
(continuous_quot_mk.comp continuous_snd) },
{ rintro ⟨⟨x⟩, ⟨y⟩⟩,
exact ⟨(x, y), rfl⟩ }
end
instance topological_ring_quotient : topological_ring N.quotient :=
{ continuous_add :=
have cont : continuous (mk N ∘ (λ (p : α × α), p.fst + p.snd)) :=
continuous_quot_mk.comp continuous_add,
(quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).2 cont,
continuous_neg := continuous_quotient_lift _ (continuous_quot_mk.comp continuous_neg),
continuous_mul :=
have cont : continuous (mk N ∘ (λ (p : α × α), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul,
(quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).2 cont }
end topological_ring
|
c1e5cd6e53ac342fe7fedc33b3d36b85179d66c2 | b815abf92ce063fe0d1fabf5b42da483552aa3e8 | /library/data/bitvec.lean | 7f079bece1448e7f5a6d2028f3040de8cd73360f | [
"Apache-2.0"
] | permissive | yodalee/lean | a368d842df12c63e9f79414ed7bbee805b9001ef | 317989bf9ef6ae1dec7488c2363dbfcdc16e0756 | refs/heads/master | 1,610,551,176,860 | 1,481,430,138,000 | 1,481,646,441,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,259 | lean | /-
Copyright (c) 2015 Joe Hendrix. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Joe Hendrix
Basic operations on bitvectors.
This is a work-in-progress, and contains additions to other theories.
-/
import data.tuple
def bitvec (n : ℕ) := tuple bool n
namespace bitvec
open nat
open tuple
instance (n : nat) : decidable_eq (bitvec n) :=
begin unfold bitvec, apply_instance end
-- Create a zero bitvector
def zero {n : ℕ} : bitvec n := tuple.repeat ff
-- Create a bitvector with the constant one.
def one {n : ℕ} : bitvec (succ n) := tuple.append (tuple.repeat ff : bitvec n) [ tt ]
section shift
-- shift left
def shl {n : ℕ} : bitvec n → ℕ → bitvec n
| x i :=
if le : i ≤ n then
let eq := nat.sub_add_cancel le in
cast (congr_arg bitvec eq) (tuple.append (dropn i x) (zero : bitvec i))
else
zero
-- unsigned shift right
def ushr {n : ℕ} : bitvec n → ℕ → bitvec n
| x i :=
if le : i ≤ n then
let y : bitvec (n-i) := @firstn _ _ _ (sub_le n i) x in
let eq := calc (i+(n-i)) = (n - i) + i : nat.add_comm i (n - i)
... = n : nat.sub_add_cancel le in
cast (congr_arg bitvec eq) (tuple.append zero y)
else
zero
-- signed shift right
def sshr {m : ℕ} : bitvec (succ m) → ℕ → bitvec (succ m)
| x i :=
let n := succ m in
if le : i ≤ n then
let z : bitvec i := repeat (head x) in
let y : bitvec (n-i) := @firstn _ _ (n - i) (sub_le n i) x in
let eq := calc (i+(n-i)) = (n-i) + i : nat.add_comm i (n - i)
... = n : nat.sub_add_cancel le in
cast (congr_arg bitvec eq) (tuple.append z y)
else
zero
end shift
section bitwise
variable {n : ℕ}
def not : bitvec n → bitvec n := map bnot
def and : bitvec n → bitvec n → bitvec n := map₂ band
def or : bitvec n → bitvec n → bitvec n := map₂ bor
def xor : bitvec n → bitvec n → bitvec n := map₂ bxor
end bitwise
section arith
variable {n : ℕ}
protected def xor3 (x:bool) (y:bool) (c:bool) := bxor (bxor x y) c
protected def carry (x:bool) (y:bool) (c:bool) :=
x && y || x && c || y && c
def neg : bitvec n → bitvec n
| x :=
let f := λy c, (y || c, bxor y c) in
prod.snd (map_accumr f x ff)
-- Add with carry (no overflow)
def adc : bitvec n → bitvec n → bool → bitvec (n+1)
| x y c :=
let f := λx y c, (bitvec.carry x y c, bitvec.xor3 x y c) in
let z := tuple.map_accumr₂ f x y c in
prod.fst z :: prod.snd z
def add : bitvec n → bitvec n → bitvec n
| x y := tail (adc x y ff)
protected def borrow (x:bool) (y:bool) (b:bool) :=
bnot x && y || bnot x && b || y && b
-- Subtract with borrow
def sbb : bitvec n → bitvec n → bool → bool × bitvec n
| x y b :=
let f := λx y c, (bitvec.borrow x y c, bitvec.xor3 x y c) in
tuple.map_accumr₂ f x y b
def sub : bitvec n → bitvec n → bitvec n
| x y := prod.snd (sbb x y ff)
instance : has_zero (bitvec n) := ⟨zero⟩
/- Remark: we used to have the instance has_one only for (bitvec (succ n)).
Now, we define it for all n to make sure we don't have to solve unification problems such as:
succ ?n =?= (bit0 (bit1 one)) -/
instance : has_one (bitvec n) :=
match n with
| 0 := ⟨zero⟩
| (nat.succ n) := ⟨one⟩
end
instance : has_add (bitvec n) := ⟨add⟩
instance : has_sub (bitvec n) := ⟨sub⟩
instance : has_neg (bitvec n) := ⟨neg⟩
def mul : bitvec n → bitvec n → bitvec n
| x y :=
let f := λr b, cond b (r + r + y) (r + r) in
list.foldl f 0 (to_list x)
instance : has_mul (bitvec n) := ⟨mul⟩
end arith
section comparison
variable {n : ℕ}
def uborrow : bitvec n → bitvec n → bool := λx y, prod.fst (sbb x y ff)
def ult (x y : bitvec n) : Prop := uborrow x y = tt
def ugt (x y : bitvec n) : Prop := ult y x
def ule (x y : bitvec n) : Prop := ¬ (ult y x)
def uge : bitvec n → bitvec n → Prop := λx y, ule y x
def sborrow : bitvec (succ n) → bitvec (succ n) → bool := λx y,
bool.cases_on
(head x)
(bool.cases_on (head y) (uborrow (tail x) (tail y)) tt)
(bool.cases_on (head y) ff (uborrow (tail x) (tail y)))
def slt : bitvec (succ n) → bitvec (succ n) → Prop := λx y,
sborrow x y = tt
def sgt : bitvec (succ n) → bitvec (succ n) → Prop := λx y, slt y x
def sle : bitvec (succ n) → bitvec (succ n) → Prop := λx y, ¬ (slt y x)
def sge : bitvec (succ n) → bitvec (succ n) → Prop := λx y, sle y x
end comparison
section from_bitvec
variable {α : Type}
-- Convert a bitvector to another number.
def from_bitvec [has_add α] [has_zero α] [has_one α] {n : nat} (v : bitvec n) : α :=
let f : α → bool → α := λr b, cond b (r + r + 1) (r + r) in
list.foldl f (0 : α) (to_list v)
end from_bitvec
private def to_string {n : nat} : bitvec n → string
| ⟨bs, p⟩ :=
"0b" ++ (bs^.reverse^.for (λ b, if b then #"1" else #"0"))
instance (n : nat) : has_to_string (bitvec n) :=
⟨to_string⟩
end bitvec
|
44e49940ca36eee58812c36921f59751fcf317f3 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/category_theory/concrete_category/default_auto.lean | e5b03c5c3696a58c52f5005f756c227dbc0eecf1 | [] | 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 | 178 | lean | import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.concrete_category.unbundled_hom
import Mathlib.PostPort
namespace Mathlib
end Mathlib |
5c587ca0e608c20001de9879e8eae2b3f282b851 | efa51dd2edbbbbd6c34bd0ce436415eb405832e7 | /20161026_ICTAC_Tutorial/ex42.lean | e214463ecf4485a5216c95e418cb9268360c233d | [
"Apache-2.0"
] | permissive | leanprover/presentations | dd031a05bcb12c8855676c77e52ed84246bd889a | 3ce2d132d299409f1de269fa8e95afa1333d644e | refs/heads/master | 1,688,703,388,796 | 1,686,838,383,000 | 1,687,465,742,000 | 29,750,158 | 12 | 9 | Apache-2.0 | 1,540,211,670,000 | 1,422,042,683,000 | Lean | UTF-8 | Lean | false | false | 294 | lean | variables (A : Type) (r : A → A → Prop)
variable refl_r : ∀ x, r x x
variable symm_r : ∀ {x y}, r x y → r y x
variable trans_r : ∀ {x y z}, r x y → r y z → r x z
example (a b c d : A) (hab : r a b) (hcb : r c b) (hcd : r c d) : r a d :=
trans_r (trans_r hab (symm_r hcb)) hcd
|
336f34ee8e3a559580db39c2872c2425218cb64e | e38e95b38a38a99ecfa1255822e78e4b26f65bb0 | /src/certigrad/label.lean | 955eb2f450401e0f6a6d135c2b81f86136c72f37 | [
"Apache-2.0"
] | permissive | ColaDrill/certigrad | fefb1be3670adccd3bed2f3faf57507f156fd501 | fe288251f623ac7152e5ce555f1cd9d3a20203c2 | refs/heads/master | 1,593,297,324,250 | 1,499,903,753,000 | 1,499,903,753,000 | 97,075,797 | 1 | 0 | null | 1,499,916,210,000 | 1,499,916,210,000 | null | UTF-8 | Lean | false | false | 2,802 | lean | /-
Copyright (c) 2017 Daniel Selsam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Daniel Selsam
Labels.
Note: this file is just because strings are slow and cumbersome in current Lean.
-/
import .tactics
namespace certigrad
inductive label : Type
| default
| batch_start
| W_encode, W_encode₁, W_encode₂, h_encode, W_encode_μ, W_encode_logσ₂
| W_decode, W_decode₁, W_decode₂, h_decode, W_decode_p
| μ, σ, σ₂, log_σ₂, z, encoding_loss, decoding_loss, ε, x, p, x_all
namespace label
instance : decidable_eq label := by tactic.mk_dec_eq_instance
def to_str : label → string
| default := "<default>"
| batch_start := "batch_start"
| W_encode := "W_encode"
| W_encode₁ := "W_encode_1"
| W_encode₂ := "W_encode_2"
| h_encode := "h_encode"
| W_encode_μ := "W_encode_mu"
| W_encode_logσ₂ := "W_encode_logs₂"
| W_decode := "W_decode"
| W_decode₁ := "W_decode_1"
| W_decode₂ := "W_decode_2"
| h_decode := "h_decode"
| W_decode_p := "W_decode_p"
| μ := "mu"
| σ := "sigma"
| σ₂ := "sigma_sq"
| log_σ₂ := "log_s₂"
| z := "z"
| encoding_loss := "encoding_loss"
| decoding_loss := "decoding_loss"
| ε := "eps"
| x := "x"
| p := "p"
| x_all := "x_all"
instance : has_to_string label := ⟨to_str⟩
def to_nat : label → ℕ
| default := 0
| batch_start := 1
| W_encode := 2
| W_encode₁ := 3
| W_encode₂ := 4
| h_encode := 5
| W_encode_μ := 6
| W_encode_logσ₂ := 7
| W_decode := 8
| W_decode₁ := 9
| W_decode₂ := 10
| h_decode := 11
| W_decode_p := 12
| μ := 13
| σ := 14
| σ₂ := 15
| log_σ₂ := 16
| z := 17
| encoding_loss := 18
| decoding_loss := 19
| ε := 20
| x := 21
| p := 22
| x_all := 23
section proofs
open tactic
meta def prove_neq_case_core : tactic unit :=
do H ← intro `H,
dunfold_at [`certigrad.label.to_nat] H,
H ← get_local `H,
(lhs, rhs) ← infer_type H >>= match_eq,
nty ← mk_app `ne [lhs, rhs],
assert `H_not nty,
solve1 prove_nats_neq,
exfalso,
get_local `H_not >>= λ H_not, exact (expr.app H_not H)
lemma eq_of_to_nat_eq {x y : label} : x = y → to_nat x = to_nat y :=
begin
intro H,
subst H,
end
lemma to_nat_eq_of_eq {x y : label} : to_nat x = to_nat y → x = y :=
begin
cases x,
all_goals { cases y },
any_goals { intros, reflexivity },
all_goals { prove_neq_case_core }
end
lemma neq_of_to_nat {x y : label} : (x ≠ y) = (x^.to_nat ≠ y^.to_nat) :=
begin
apply propext,
split,
intros H_ne H_eq,
exact H_ne (to_nat_eq_of_eq H_eq),
intros H_ne H_eq,
exact H_ne (eq_of_to_nat_eq H_eq)
end
end proofs
def less_than (x y : label) : Prop := x^.to_nat < y^.to_nat
instance : has_lt label := ⟨less_than⟩
instance decidable_less_than (x y : label) : decidable (x < y) := by apply nat.decidable_lt
end label
end certigrad
|
b7deb2554d1a1782f0d4df64f693344767f1e97f | 5d166a16ae129621cb54ca9dde86c275d7d2b483 | /tests/lean/run/smt_assert_define.lean | d09d890b8ec9d6e5249da700274c62fb31ff161c | [
"Apache-2.0"
] | permissive | jcarlson23/lean | b00098763291397e0ac76b37a2dd96bc013bd247 | 8de88701247f54d325edd46c0eed57aeacb64baf | refs/heads/master | 1,611,571,813,719 | 1,497,020,963,000 | 1,497,021,515,000 | 93,882,536 | 1 | 0 | null | 1,497,029,896,000 | 1,497,029,896,000 | null | UTF-8 | Lean | false | false | 893 | lean | open smt_tactic
constant p : nat → nat → Prop
constant f : nat → nat
axiom pf (a : nat) : p (f a) (f a) → p a a
lemma ex1 (a b c : nat) : a = b + 0 → a + c = b + c :=
by using_smt $ do
pr ← tactic.to_expr ```(add_zero b),
note `h none pr,
trace_state, return ()
lemma ex2(a b c : nat) : a = b → p (f a) (f b) → p a b :=
by using_smt $ do
intros,
t ← tactic.to_expr ```(p (f a) (f a)),
assert `h t, -- assert automatically closed the new goal
trace_state,
tactic.trace "-----",
pr ← tactic.to_expr ```(pf _ h),
note `h2 none pr,
trace_state,
return ()
def foo := 0
lemma fooex : foo = 0 := rfl
lemma ex3 (a b c : nat) : a = b + foo → a + c = b + c :=
begin [smt]
intros,
add_fact fooex,
ematch
end
lemma ex4 (a b c : nat) : a = b → p (f a) (f b) → p a b :=
begin [smt]
intros,
assert h : p (f a) (f a),
add_fact (pf _ h)
end
|
3213afc9b8b54d4c66f110d64ae764616a4f7233 | 618003631150032a5676f229d13a079ac875ff77 | /src/algebra/category/Module/basic.lean | 6d640759abbaf713c255d9d4d8f9a8c6391101b1 | [
"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 | 5,740 | lean | /-
Copyright (c) 2019 Robert A. Spencer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert A. Spencer, Markus Himmel
-/
import algebra.category.Group.basic
import category_theory.concrete_category
import category_theory.limits.shapes.kernels
import category_theory.preadditive
import linear_algebra.basic
open category_theory
open category_theory.limits
open category_theory.limits.walking_parallel_pair
universe u
variables (R : Type u) [ring R]
/-- The category of R-modules and their morphisms. -/
structure Module :=
(carrier : Type u)
[is_add_comm_group : add_comm_group carrier]
[is_module : module R carrier]
attribute [instance] Module.is_add_comm_group Module.is_module
namespace Module
-- TODO revisit this after #1438 merges, to check coercions and instances are handled consistently
instance : has_coe_to_sort (Module R) :=
{ S := Type u, coe := Module.carrier }
instance : category (Module.{u} R) :=
{ hom := λ M N, M →ₗ[R] N,
id := λ M, 1,
comp := λ A B C f g, g.comp f }
instance : concrete_category (Module.{u} R) :=
{ forget := { obj := λ R, R, map := λ R S f, (f : R → S) },
forget_faithful := { } }
instance has_forget_to_AddCommGroup : has_forget₂ (Module R) AddCommGroup :=
{ forget₂ :=
{ obj := λ M, AddCommGroup.of M,
map := λ M₁ M₂ f, linear_map.to_add_monoid_hom f } }
/-- The object in the category of R-modules associated to an R-module -/
def of (X : Type u) [add_comm_group X] [module R X] : Module R := ⟨X⟩
instance : inhabited (Module R) := ⟨of R punit⟩
@[simp]
lemma of_apply (X : Type u) [add_comm_group X] [module R X] : (of R X : Type u) = X := rfl
variables {R}
/-- Forgetting to the underlying type and then building the bundled object returns the original module. -/
@[simps]
def of_self_iso (M : Module R) : Module.of R M ≅ M :=
{ hom := 𝟙 M, inv := 𝟙 M }
instance : subsingleton (of R punit) :=
by { rw of_apply R punit, apply_instance }
instance : has_zero_object.{u} (Module R) :=
{ zero := of R punit,
unique_to := λ X,
{ default := (0 : punit →ₗ[R] X),
uniq := λ _, linear_map.ext $ λ x,
have h : x = 0, from subsingleton.elim _ _,
by simp only [h, linear_map.map_zero]},
unique_from := λ X,
{ default := (0 : X →ₗ[R] punit),
uniq := λ _, linear_map.ext $ λ x, subsingleton.elim _ _ } }
variables {R} {M N U : Module R}
@[simp] lemma id_apply (m : M) : (𝟙 M : M → M) m = m := rfl
@[simp] lemma coe_comp (f : M ⟶ N) (g : N ⟶ U) :
((f ≫ g) : M → U) = g ∘ f := rfl
instance hom_is_module_hom (f : M ⟶ N) :
is_linear_map R (f : M → N) := linear_map.is_linear _
end Module
variables {R}
variables {X₁ X₂ : Type u}
/-- Build an isomorphism in the category `Module R` from a `linear_equiv` between `module`s. -/
@[simps]
def linear_equiv.to_Module_iso
{g₁ : add_comm_group X₁} {g₂ : add_comm_group X₂} {m₁ : module R X₁} {m₂ : module R X₂} (e : X₁ ≃ₗ[R] X₂) :
Module.of R X₁ ≅ Module.of R X₂ :=
{ hom := (e : X₁ →ₗ[R] X₂),
inv := (e.symm : X₂ →ₗ[R] X₁),
hom_inv_id' := begin ext, exact e.left_inv x, end,
inv_hom_id' := begin ext, exact e.right_inv x, end, }
namespace category_theory.iso
/-- Build a `linear_equiv` from an isomorphism in the category `Module R`. -/
@[simps]
def to_linear_equiv {X Y : Module.{u} R} (i : X ≅ Y) : X ≃ₗ[R] Y :=
{ to_fun := i.hom,
inv_fun := i.inv,
left_inv := by tidy,
right_inv := by tidy,
add := by tidy,
smul := by tidy, }.
end category_theory.iso
/-- linear equivalences between `module`s are the same as (isomorphic to) isomorphisms in `Module` -/
@[simps]
def linear_equiv_iso_Group_iso {X Y : Type u} [add_comm_group X] [add_comm_group Y] [module R X] [module R Y] :
(X ≃ₗ[R] Y) ≅ (Module.of R X ≅ Module.of R Y) :=
{ hom := λ e, e.to_Module_iso,
inv := λ i, i.to_linear_equiv, }
namespace Module
section preadditive
instance : preadditive.{u} (Module.{u} R) :=
{ add_comp' := λ P Q R f f' g,
show (f + f') ≫ g = f ≫ g + f' ≫ g, by { ext, simp },
comp_add' := λ P Q R f g g',
show f ≫ (g + g') = f ≫ g + f ≫ g', by { ext, simp } }
end preadditive
section kernel
variables {R} {M N : Module R} (f : M ⟶ N)
/-- The cone on the equalizer diagram of f and 0 induced by the kernel of f -/
def kernel_cone : cone (parallel_pair f 0) :=
{ X := of R f.ker,
π :=
{ app := λ j,
match j with
| zero := f.ker.subtype
| one := 0
end,
naturality' := λ j j' g, by { cases j; cases j'; cases g; tidy } } }
/-- The kernel of a linear map is a kernel in the categorical sense -/
def kernel_is_limit : is_limit (kernel_cone f) :=
{ lift := λ s, linear_map.cod_restrict f.ker (fork.ι s) (λ c, linear_map.mem_ker.2 $
by { erw [←@function.comp_apply _ _ _ f (fork.ι s) c, ←coe_comp, fork.condition,
has_zero_morphisms.comp_zero (fork.ι s) N], refl }),
fac' := λ s j, linear_map.ext $ λ x,
begin
rw [coe_comp, function.comp_app, ←linear_map.comp_apply],
cases j,
{ erw @linear_map.subtype_comp_cod_restrict _ _ _ _ _ _ _ _ (fork.ι s) f.ker _ },
{ rw [←fork.app_zero_left, ←fork.app_zero_left], refl }
end,
uniq' := λ s m h, linear_map.ext $ λ x, subtype.ext.2 $
have h₁ : (m ≫ (kernel_cone f).π.app zero).to_fun = (s.π.app zero).to_fun,
by { congr, exact h zero },
by convert @congr_fun _ _ _ _ h₁ x }
end kernel
instance : has_kernels.{u} (Module R) :=
⟨λ _ _ f, ⟨kernel_cone f, kernel_is_limit f⟩⟩
end Module
instance (M : Type u) [add_comm_group M] [module R M] : has_coe (submodule R M) (Module R) :=
⟨ λ N, Module.of R N ⟩
|
f6e094a5392d94d349a8f1549da746d88a234db1 | 49bd2218ae088932d847f9030c8dbff1c5607bb7 | /src/topology/constructions.lean | de28bdc2ca6abd713d05c0250a7983a2a15c39b8 | [
"Apache-2.0"
] | permissive | FredericLeRoux/mathlib | e8f696421dd3e4edc8c7edb3369421c8463d7bac | 3645bf8fb426757e0a20af110d1fdded281d286e | refs/heads/master | 1,607,062,870,732 | 1,578,513,186,000 | 1,578,513,186,000 | 231,653,181 | 0 | 0 | Apache-2.0 | 1,578,080,327,000 | 1,578,080,326,000 | null | UTF-8 | Lean | false | false | 29,790 | 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 topology.maps
/-!
# Constructions of new topological spaces from old ones
This file constructs products, sums, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, sum, disjoint union, subspace, quotient space
-/
noncomputable theory
open topological_space set filter lattice
open_locale classical topological_space
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
section constructions
instance {p : α → Prop} [t : topological_space α] : topological_space (subtype p) :=
induced subtype.val t
instance {r : α → α → Prop} [t : topological_space α] : topological_space (quot r) :=
coinduced (quot.mk r) t
instance {s : setoid α} [t : topological_space α] : topological_space (quotient s) :=
coinduced quotient.mk t
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α × β) :=
induced prod.fst t₁ ⊓ induced prod.snd t₂
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α ⊕ β) :=
coinduced sum.inl t₁ ⊔ coinduced sum.inr t₂
instance {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (sigma β) :=
⨆a, coinduced (sigma.mk a) (t₂ a)
instance Pi.topological_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] :
topological_space (Πa, β a) :=
⨅a, induced (λf, f a) (t₂ a)
lemma quotient_dense_of_dense [setoid α] [topological_space α] {s : set α} (H : ∀ x, x ∈ closure s) :
closure (quotient.mk '' s) = univ :=
eq_univ_of_forall $ λ x, begin
rw mem_closure_iff,
intros U U_op x_in_U,
let V := quotient.mk ⁻¹' U,
cases quotient.exists_rep x with y y_x,
have y_in_V : y ∈ V, by simp only [mem_preimage, y_x, x_in_U],
have V_op : is_open V := U_op,
have : V ∩ s ≠ ∅ := mem_closure_iff.1 (H y) V V_op y_in_V,
rcases exists_mem_of_ne_empty this with ⟨w, w_in_V, w_in_range⟩,
exact ne_empty_of_mem ⟨w_in_V, mem_image_of_mem quotient.mk w_in_range⟩
end
instance {p : α → Prop} [topological_space α] [discrete_topology α] :
discrete_topology (subtype p) :=
⟨bot_unique $ assume s hs,
⟨subtype.val '' s, is_open_discrete _, (set.preimage_image_eq _ subtype.val_injective)⟩⟩
instance sum.discrete_topology [topological_space α] [topological_space β]
[hα : discrete_topology α] [hβ : discrete_topology β] : discrete_topology (α ⊕ β) :=
⟨by unfold sum.topological_space; simp [hα.eq_bot, hβ.eq_bot]⟩
instance sigma.discrete_topology {β : α → Type v} [Πa, topological_space (β a)]
[h : Πa, discrete_topology (β a)] : discrete_topology (sigma β) :=
⟨by { unfold sigma.topological_space, simp [λ a, (h a).eq_bot] }⟩
section topα
variable [topological_space α]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : set α) (a : {x // x ∈ s}) (t : set {x // x ∈ s}) :
t ∈ 𝓝 a ↔ ∃ u ∈ 𝓝 a.val, (@subtype.val α s) ⁻¹' u ⊆ t :=
mem_nhds_induced subtype.val a t
theorem nhds_subtype (s : set α) (a : {x // x ∈ s}) :
𝓝 a = comap subtype.val (𝓝 a.val) :=
nhds_induced subtype.val a
end topα
end constructions
section prod
open topological_space
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
lemma continuous_fst : continuous (@prod.fst α β) :=
continuous_inf_dom_left continuous_induced_dom
lemma continuous_snd : continuous (@prod.snd α β) :=
continuous_inf_dom_right continuous_induced_dom
lemma continuous.prod_mk {f : γ → α} {g : γ → β}
(hf : continuous f) (hg : continuous g) : continuous (λx, prod.mk (f x) (g x)) :=
continuous_inf_rng (continuous_induced_rng hf) (continuous_induced_rng hg)
lemma continuous_swap : continuous (prod.swap : α × β → β × α) :=
continuous.prod_mk continuous_snd continuous_fst
lemma is_open_prod {s : set α} {t : set β} (hs : is_open s) (ht : is_open t) :
is_open (set.prod s t) :=
is_open_inter (continuous_fst s hs) (continuous_snd t ht)
lemma nhds_prod_eq {a : α} {b : β} : 𝓝 (a, b) = filter.prod (𝓝 a) (𝓝 b) :=
by rw [filter.prod, prod.topological_space, nhds_inf, nhds_induced, nhds_induced]
instance [discrete_topology α] [discrete_topology β] : discrete_topology (α × β) :=
⟨eq_of_nhds_eq_nhds $ assume ⟨a, b⟩,
by rw [nhds_prod_eq, nhds_discrete α, nhds_discrete β, nhds_bot, filter.prod_pure_pure]⟩
lemma prod_mem_nhds_sets {s : set α} {t : set β} {a : α} {b : β}
(ha : s ∈ 𝓝 a) (hb : t ∈ 𝓝 b) : set.prod s t ∈ 𝓝 (a, b) :=
by rw [nhds_prod_eq]; exact prod_mem_prod ha hb
lemma nhds_swap (a : α) (b : β) : 𝓝 (a, b) = (𝓝 (b, a)).map prod.swap :=
by rw [nhds_prod_eq, filter.prod_comm, nhds_prod_eq]; refl
lemma tendsto_prod_mk_nhds {γ} {a : α} {b : β} {f : filter γ} {ma : γ → α} {mb : γ → β}
(ha : tendsto ma f (𝓝 a)) (hb : tendsto mb f (𝓝 b)) :
tendsto (λc, (ma c, mb c)) f (𝓝 (a, b)) :=
by rw [nhds_prod_eq]; exact filter.tendsto.prod_mk ha hb
lemma continuous_at.prod {f : α → β} {g : α → γ} {x : α}
(hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (λx, (f x, g x)) x :=
tendsto_prod_mk_nhds hf hg
lemma prod_generate_from_generate_from_eq {α : Type*} {β : Type*} {s : set (set α)} {t : set (set β)}
(hs : ⋃₀ s = univ) (ht : ⋃₀ t = univ) :
@prod.topological_space α β (generate_from s) (generate_from t) =
generate_from {g | ∃u∈s, ∃v∈t, g = set.prod u v} :=
let G := generate_from {g | ∃u∈s, ∃v∈t, g = set.prod u v} in
le_antisymm
(le_generate_from $ assume g ⟨u, hu, v, hv, g_eq⟩, g_eq.symm ▸
@is_open_prod _ _ (generate_from s) (generate_from t) _ _
(generate_open.basic _ hu) (generate_open.basic _ hv))
(le_inf
(coinduced_le_iff_le_induced.mp $ le_generate_from $ assume u hu,
have (⋃v∈t, set.prod u v) = prod.fst ⁻¹' u,
from calc (⋃v∈t, set.prod u v) = set.prod u univ :
set.ext $ assume ⟨a, b⟩, by rw ← ht; simp [and.left_comm] {contextual:=tt}
... = prod.fst ⁻¹' u : by simp [set.prod, preimage],
show G.is_open (prod.fst ⁻¹' u),
from this ▸ @is_open_Union _ _ G _ $ assume v, @is_open_Union _ _ G _ $ assume hv,
generate_open.basic _ ⟨_, hu, _, hv, rfl⟩)
(coinduced_le_iff_le_induced.mp $ le_generate_from $ assume v hv,
have (⋃u∈s, set.prod u v) = prod.snd ⁻¹' v,
from calc (⋃u∈s, set.prod u v) = set.prod univ v:
set.ext $ assume ⟨a, b⟩, by rw [←hs]; by_cases b ∈ v; simp [h] {contextual:=tt}
... = prod.snd ⁻¹' v : by simp [set.prod, preimage],
show G.is_open (prod.snd ⁻¹' v),
from this ▸ @is_open_Union _ _ G _ $ assume u, @is_open_Union _ _ G _ $ assume hu,
generate_open.basic _ ⟨_, hu, _, hv, rfl⟩))
lemma prod_eq_generate_from :
prod.topological_space =
generate_from {g | ∃(s:set α) (t:set β), is_open s ∧ is_open t ∧ g = set.prod s t} :=
le_antisymm
(le_generate_from $ assume g ⟨s, t, hs, ht, g_eq⟩, g_eq.symm ▸ is_open_prod hs ht)
(le_inf
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨t, univ, by simpa [set.prod_eq] using ht⟩)
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨univ, t, by simpa [set.prod_eq] using ht⟩))
lemma is_open_prod_iff {s : set (α×β)} : is_open s ↔
(∀a b, (a, b) ∈ s → ∃u v, is_open u ∧ is_open v ∧ a ∈ u ∧ b ∈ v ∧ set.prod u v ⊆ s) :=
begin
rw [is_open_iff_nhds],
simp [nhds_prod_eq, mem_prod_iff],
simp [mem_nhds_sets_iff],
exact forall_congr (assume a, ball_congr $ assume b h,
⟨assume ⟨u', ⟨u, us, uo, au⟩, v', ⟨v, vs, vo, bv⟩, h⟩,
⟨u, uo, v, vo, au, bv, subset.trans (set.prod_mono us vs) h⟩,
assume ⟨u, uo, v, vo, au, bv, h⟩,
⟨u, ⟨u, subset.refl u, uo, au⟩, v, ⟨v, subset.refl v, vo, bv⟩, h⟩⟩)
end
/-- The first projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_fst : is_open_map (@prod.fst α β) :=
begin
assume s hs,
rw is_open_iff_forall_mem_open,
assume x xs,
rw mem_image_eq at xs,
rcases xs with ⟨⟨y₁, y₂⟩, ys, yx⟩,
rcases is_open_prod_iff.1 hs _ _ ys with ⟨o₁, o₂, o₁_open, o₂_open, yo₁, yo₂, ho⟩,
simp at yx,
rw yx at yo₁,
refine ⟨o₁, _, o₁_open, yo₁⟩,
assume z zs,
rw mem_image_eq,
exact ⟨(z, y₂), ho (by simp [zs, yo₂]), rfl⟩
end
/-- The second projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_snd : is_open_map (@prod.snd α β) :=
begin
/- This lemma could be proved by composing the fact that the first projection is open, and
exchanging coordinates is a homeomorphism, hence open. As the `prod_comm` homeomorphism is defined
later, we rather go for the direct proof, copy-pasting the proof for the first projection. -/
assume s hs,
rw is_open_iff_forall_mem_open,
assume x xs,
rw mem_image_eq at xs,
rcases xs with ⟨⟨y₁, y₂⟩, ys, yx⟩,
rcases is_open_prod_iff.1 hs _ _ ys with ⟨o₁, o₂, o₁_open, o₂_open, yo₁, yo₂, ho⟩,
simp at yx,
rw yx at yo₂,
refine ⟨o₂, _, o₂_open, yo₂⟩,
assume z zs,
rw mem_image_eq,
exact ⟨(y₁, z), ho (by simp [zs, yo₁]), rfl⟩
end
/-- A product set is open in a product space if and only if each factor is open, or one of them is
empty -/
lemma is_open_prod_iff' {s : set α} {t : set β} :
is_open (set.prod s t) ↔ (is_open s ∧ is_open t) ∨ (s = ∅) ∨ (t = ∅) :=
begin
by_cases h : set.prod s t = ∅,
{ simp [h, prod_eq_empty_iff.1 h] },
{ have st : s ≠ ∅ ∧ t ≠ ∅, by rwa [← ne.def, prod_ne_empty_iff] at h,
split,
{ assume H : is_open (set.prod s t),
refine or.inl ⟨_, _⟩,
show is_open s,
{ rw ← fst_image_prod s st.2,
exact is_open_map_fst _ H },
show is_open t,
{ rw ← snd_image_prod st.1 t,
exact is_open_map_snd _ H } },
{ assume H,
simp [st] at H,
exact is_open_prod H.1 H.2 } }
end
lemma closure_prod_eq {s : set α} {t : set β} :
closure (set.prod s t) = set.prod (closure s) (closure t) :=
set.ext $ assume ⟨a, b⟩,
have filter.prod (𝓝 a) (𝓝 b) ⊓ principal (set.prod s t) =
filter.prod (𝓝 a ⊓ principal s) (𝓝 b ⊓ principal t),
by rw [←prod_inf_prod, prod_principal_principal],
by simp [closure_eq_nhds, nhds_prod_eq, this]; exact prod_neq_bot
lemma mem_closure2 {s : set α} {t : set β} {u : set γ} {f : α → β → γ} {a : α} {b : β}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(hu : ∀a b, a ∈ s → b ∈ t → f a b ∈ u) :
f a b ∈ closure u :=
have (a, b) ∈ closure (set.prod s t), by rw [closure_prod_eq]; from ⟨ha, hb⟩,
show (λp:α×β, f p.1 p.2) (a, b) ∈ closure u, from
mem_closure hf this $ assume ⟨a, b⟩ ⟨ha, hb⟩, hu a b ha hb
lemma is_closed_prod {s₁ : set α} {s₂ : set β} (h₁ : is_closed s₁) (h₂ : is_closed s₂) :
is_closed (set.prod s₁ s₂) :=
closure_eq_iff_is_closed.mp $ by simp [h₁, h₂, closure_prod_eq, closure_eq_of_is_closed]
lemma inducing.prod_mk {f : α → β} {g : γ → δ} (hf : inducing f) (hg : inducing g) :
inducing (λx:α×γ, (f x.1, g x.2)) :=
⟨by rw [prod.topological_space, prod.topological_space, hf.induced, hg.induced,
induced_compose, induced_compose, induced_inf, induced_compose, induced_compose]⟩
lemma embedding.prod_mk {f : α → β} {g : γ → δ} (hf : embedding f) (hg : embedding g) :
embedding (λx:α×γ, (f x.1, g x.2)) :=
{ inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume h₁ h₂, ⟨hf.inj h₁, hg.inj h₂⟩,
..hf.to_inducing.prod_mk hg.to_inducing }
protected lemma is_open_map.prod {f : α → β} {g : γ → δ} (hf : is_open_map f) (hg : is_open_map g) :
is_open_map (λ p : α × γ, (f p.1, g p.2)) :=
begin
rw [is_open_map_iff_nhds_le],
rintros ⟨a, b⟩,
rw [nhds_prod_eq, nhds_prod_eq, ← filter.prod_map_map_eq],
exact filter.prod_mono (is_open_map_iff_nhds_le.1 hf a) (is_open_map_iff_nhds_le.1 hg b)
end
protected lemma open_embedding.prod {f : α → β} {g : γ → δ}
(hf : open_embedding f) (hg : open_embedding g) : open_embedding (λx:α×γ, (f x.1, g x.2)) :=
open_embedding_of_embedding_open (hf.1.prod_mk hg.1)
(hf.is_open_map.prod hg.is_open_map)
lemma embedding_graph {f : α → β} (hf : continuous f) : embedding (λx, (x, f x)) :=
embedding_of_embedding_compose (continuous_id.prod_mk hf) continuous_fst embedding_id
end prod
section sum
variables [topological_space α] [topological_space β] [topological_space γ]
lemma continuous_inl : continuous (@sum.inl α β) :=
continuous_sup_rng_left continuous_coinduced_rng
lemma continuous_inr : continuous (@sum.inr α β) :=
continuous_sup_rng_right continuous_coinduced_rng
lemma continuous_sum_rec {f : α → γ} {g : β → γ}
(hf : continuous f) (hg : continuous g) : @continuous (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) :=
continuous_sup_dom hf hg
lemma embedding_inl : embedding (@sum.inl α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact lattice.le_sup_left },
{ intros u hu, existsi (sum.inl '' u),
change
(is_open (sum.inl ⁻¹' (@sum.inl α β '' u)) ∧
is_open (sum.inr ⁻¹' (@sum.inl α β '' u))) ∧
sum.inl ⁻¹' (sum.inl '' u) = u,
have : sum.inl ⁻¹' (@sum.inl α β '' u) = u :=
preimage_image_eq u (λ _ _, sum.inl.inj_iff.mp), rw this,
have : sum.inr ⁻¹' (@sum.inl α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume a ⟨b, _, h⟩, sum.inl_ne_inr h), rw this,
exact ⟨⟨hu, is_open_empty⟩, rfl⟩ }
end,
inj := λ _ _, sum.inl.inj_iff.mp }
lemma embedding_inr : embedding (@sum.inr α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact lattice.le_sup_right },
{ intros u hu, existsi (sum.inr '' u),
change
(is_open (sum.inl ⁻¹' (@sum.inr α β '' u)) ∧
is_open (sum.inr ⁻¹' (@sum.inr α β '' u))) ∧
sum.inr ⁻¹' (sum.inr '' u) = u,
have : sum.inl ⁻¹' (@sum.inr α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume b ⟨a, _, h⟩, sum.inr_ne_inl h), rw this,
have : sum.inr ⁻¹' (@sum.inr α β '' u) = u :=
preimage_image_eq u (λ _ _, sum.inr.inj_iff.mp), rw this,
exact ⟨⟨is_open_empty, hu⟩, rfl⟩ }
end,
inj := λ _ _, sum.inr.inj_iff.mp }
end sum
section subtype
variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop}
lemma embedding_subtype_val : embedding (@subtype.val α p) :=
⟨⟨rfl⟩, subtype.val_injective⟩
lemma continuous_subtype_val : continuous (@subtype.val α p) :=
continuous_induced_dom
lemma is_open.open_embedding_subtype_val {s : set α} (hs : is_open s) :
open_embedding (subtype.val : s → α) :=
{ induced := rfl,
inj := subtype.val_injective,
open_range := (subtype.val_range : range subtype.val = s).symm ▸ hs }
lemma is_open.is_open_map_subtype_val {s : set α} (hs : is_open s) :
is_open_map (subtype.val : s → α) :=
hs.open_embedding_subtype_val.is_open_map
lemma is_open_map.restrict {f : α → β} (hf : is_open_map f) {s : set α} (hs : is_open s) :
is_open_map (function.restrict f s) :=
hf.comp hs.is_open_map_subtype_val
lemma is_closed.closed_embedding_subtype_val {s : set α} (hs : is_closed s) :
closed_embedding (subtype.val : {x // x ∈ s} → α) :=
{ induced := rfl,
inj := subtype.val_injective,
closed_range := (subtype.val_range : range subtype.val = s).symm ▸ hs }
lemma continuous_subtype_mk {f : β → α}
(hp : ∀x, p (f x)) (h : continuous f) : continuous (λx, (⟨f x, hp x⟩ : subtype p)) :=
continuous_induced_rng h
lemma continuous_inclusion {s t : set α} (h : s ⊆ t) : continuous (inclusion h) :=
continuous_subtype_mk _ continuous_subtype_val
lemma continuous_at_subtype_val {p : α → Prop} {a : subtype p} :
continuous_at subtype.val a :=
continuous_iff_continuous_at.mp continuous_subtype_val _
lemma map_nhds_subtype_val_eq {a : α} (ha : p a) (h : {a | p a} ∈ 𝓝 a) :
map (@subtype.val α p) (𝓝 ⟨a, ha⟩) = 𝓝 a :=
map_nhds_induced_eq (by simp [subtype.val_image, h])
lemma nhds_subtype_eq_comap {a : α} {h : p a} :
𝓝 (⟨a, h⟩ : subtype p) = comap subtype.val (𝓝 a) :=
nhds_induced _ _
lemma tendsto_subtype_rng {β : Type*} {p : α → Prop} {b : filter β} {f : β → subtype p} :
∀{a:subtype p}, tendsto f b (𝓝 a) ↔ tendsto (λx, subtype.val (f x)) b (𝓝 a.val)
| ⟨a, ha⟩ := by rw [nhds_subtype_eq_comap, tendsto_comap_iff]
lemma continuous_subtype_nhds_cover {ι : Sort*} {f : α → β} {c : ι → α → Prop}
(c_cover : ∀x:α, ∃i, {x | c i x} ∈ 𝓝 x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) :
continuous f :=
continuous_iff_continuous_at.mpr $ assume x,
let ⟨i, (c_sets : {x | c i x} ∈ 𝓝 x)⟩ := c_cover x in
let x' : subtype (c i) := ⟨x, mem_of_nhds c_sets⟩ in
calc map f (𝓝 x) = map f (map subtype.val (𝓝 x')) :
congr_arg (map f) (map_nhds_subtype_val_eq _ $ c_sets).symm
... = map (λx:subtype (c i), f x.val) (𝓝 x') : rfl
... ≤ 𝓝 (f x) : continuous_iff_continuous_at.mp (f_cont i) x'
lemma continuous_subtype_is_closed_cover {ι : Sort*} {f : α → β} (c : ι → α → Prop)
(h_lf : locally_finite (λi, {x | c i x}))
(h_is_closed : ∀i, is_closed {x | c i x})
(h_cover : ∀x, ∃i, c i x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) :
continuous f :=
continuous_iff_is_closed.mpr $
assume s hs,
have ∀i, is_closed (@subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
from assume i,
embedding_is_closed embedding_subtype_val
(by simp [subtype.val_range]; exact h_is_closed i)
(continuous_iff_is_closed.mp (f_cont i) _ hs),
have is_closed (⋃i, @subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
from is_closed_Union_of_locally_finite
(locally_finite_subset h_lf $ assume i x ⟨⟨x', hx'⟩, _, heq⟩, heq ▸ hx')
this,
have f ⁻¹' s = (⋃i, @subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
begin
apply set.ext,
have : ∀ (x : α), f x ∈ s ↔ ∃ (i : ι), c i x ∧ f x ∈ s :=
λ x, ⟨λ hx, let ⟨i, hi⟩ := h_cover x in ⟨i, hi, hx⟩,
λ ⟨i, hi, hx⟩, hx⟩,
simp [and.comm, and.left_comm], simpa [(∘)],
end,
by rwa [this]
lemma closure_subtype {x : {a // p a}} {s : set {a // p a}}:
x ∈ closure s ↔ x.val ∈ closure (subtype.val '' s) :=
closure_induced $ assume x y, subtype.eq
end subtype
section quotient
variables [topological_space α] [topological_space β] [topological_space γ]
variables {r : α → α → Prop} {s : setoid α}
lemma quotient_map_quot_mk : quotient_map (@quot.mk α r) :=
⟨quot.exists_rep, rfl⟩
lemma continuous_quot_mk : continuous (@quot.mk α r) :=
continuous_coinduced_rng
lemma continuous_quot_lift {f : α → β} (hr : ∀ a b, r a b → f a = f b)
(h : continuous f) : continuous (quot.lift f hr : quot r → β) :=
continuous_coinduced_dom h
lemma quotient_map_quotient_mk : quotient_map (@quotient.mk α s) :=
quotient_map_quot_mk
lemma continuous_quotient_mk : continuous (@quotient.mk α s) :=
continuous_coinduced_rng
lemma continuous_quotient_lift {f : α → β} (hs : ∀ a b, a ≈ b → f a = f b)
(h : continuous f) : continuous (quotient.lift f hs : quotient s → β) :=
continuous_coinduced_dom h
end quotient
section pi
variables {ι : Type*} {π : ι → Type*}
open topological_space
lemma continuous_pi [topological_space α] [∀i, topological_space (π i)] {f : α → Πi:ι, π i}
(h : ∀i, continuous (λa, f a i)) : continuous f :=
continuous_infi_rng $ assume i, continuous_induced_rng $ h i
lemma continuous_apply [∀i, topological_space (π i)] (i : ι) :
continuous (λp:Πi, π i, p i) :=
continuous_infi_dom continuous_induced_dom
lemma nhds_pi [t : ∀i, topological_space (π i)] {a : Πi, π i} :
𝓝 a = (⨅i, comap (λx, x i) (𝓝 (a i))) :=
calc 𝓝 a = (⨅i, @nhds _ (@topological_space.induced _ _ (λx:Πi, π i, x i) (t i)) a) : nhds_infi
... = (⨅i, comap (λx, x i) (𝓝 (a i))) : by simp [nhds_induced]
lemma is_open_set_pi [∀a, topological_space (π a)] {i : set ι} {s : Πa, set (π a)}
(hi : finite i) (hs : ∀a∈i, is_open (s a)) : is_open (pi i s) :=
by rw [pi_def]; exact (is_open_bInter hi $ assume a ha, continuous_apply a _ $ hs a ha)
lemma pi_eq_generate_from [∀a, topological_space (π a)] :
Pi.topological_space =
generate_from {g | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, is_open (s a)) ∧ g = pi ↑i s} :=
le_antisymm
(le_generate_from $ assume g ⟨s, i, hi, eq⟩, eq.symm ▸ is_open_set_pi (finset.finite_to_set _) hi)
(le_infi $ assume a s ⟨t, ht, s_eq⟩, generate_open.basic _ $
⟨function.update (λa, univ) a t, {a}, by simpa using ht, by ext f; simp [s_eq.symm, pi]⟩)
lemma pi_generate_from_eq {g : Πa, set (set (π a))} :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} :=
let G := {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} in
begin
rw [pi_eq_generate_from],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, i, ht, eq⟩, ⟨t, i, assume a ha, generate_open.basic _ (ht a ha), eq⟩,
{ rintros s ⟨t, i, hi, rfl⟩,
rw [pi_def],
apply is_open_bInter (finset.finite_to_set _),
assume a ha, show ((generate_from G).coinduced (λf:Πa, π a, f a)).is_open (t a),
refine le_generate_from _ _ (hi a ha),
exact assume s hs, generate_open.basic _ ⟨function.update (λa, univ) a s, {a}, by simp [hs]⟩ }
end
lemma pi_generate_from_eq_fintype {g : Πa, set (set (π a))} [fintype ι] (hg : ∀a, ⋃₀ g a = univ) :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)), (∀a, s a ∈ g a) ∧ t = pi univ s} :=
let G := {t | ∃(s:Πa, set (π a)), (∀a, s a ∈ g a) ∧ t = pi univ s} in
begin
rw [pi_generate_from_eq],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, ht, eq⟩, ⟨t, finset.univ, by simp [ht, eq]⟩,
{ rintros s ⟨t, i, ht, rfl⟩,
apply is_open_iff_forall_mem_open.2 _,
assume f hf,
choose c hc using show ∀a, ∃s, s ∈ g a ∧ f a ∈ s,
{ assume a, have : f a ∈ ⋃₀ g a, { rw [hg], apply mem_univ }, simpa },
refine ⟨pi univ (λa, if a ∈ i then t a else (c : Πa, set (π a)) a), _, _, _⟩,
{ simp [pi_if] },
{ refine generate_open.basic _ ⟨_, assume a, _, rfl⟩,
by_cases a ∈ i; simp [*, pi] at * },
{ have : f ∈ pi {a | a ∉ i} c, { simp [*, pi] at * },
simpa [pi_if, hf] } }
end
end pi
section sigma
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
open lattice
lemma continuous_sigma_mk {i : ι} : continuous (@sigma.mk ι σ i) :=
continuous_supr_rng continuous_coinduced_rng
lemma is_open_sigma_iff {s : set (sigma σ)} : is_open s ↔ ∀ i, is_open (sigma.mk i ⁻¹' s) :=
by simp only [is_open_supr_iff, is_open_coinduced]
lemma is_closed_sigma_iff {s : set (sigma σ)} : is_closed s ↔ ∀ i, is_closed (sigma.mk i ⁻¹' s) :=
is_open_sigma_iff
lemma is_open_map_sigma_mk {i : ι} : is_open_map (@sigma.mk ι σ i) :=
begin
intros s hs,
rw is_open_sigma_iff,
intro j,
classical,
by_cases h : i = j,
{ subst j,
convert hs,
exact set.preimage_image_eq _ injective_sigma_mk },
{ convert is_open_empty,
apply set.eq_empty_of_subset_empty,
rintro x ⟨y, _, hy⟩,
have : i = j, by cc,
contradiction }
end
lemma is_open_range_sigma_mk {i : ι} : is_open (set.range (@sigma.mk ι σ i)) :=
by { rw ←set.image_univ, exact is_open_map_sigma_mk _ is_open_univ }
lemma is_closed_map_sigma_mk {i : ι} : is_closed_map (@sigma.mk ι σ i) :=
begin
intros s hs,
rw is_closed_sigma_iff,
intro j,
classical,
by_cases h : i = j,
{ subst j,
convert hs,
exact set.preimage_image_eq _ injective_sigma_mk },
{ convert is_closed_empty,
apply set.eq_empty_of_subset_empty,
rintro x ⟨y, _, hy⟩,
have : i = j, by cc,
contradiction }
end
lemma is_closed_sigma_mk {i : ι} : is_closed (set.range (@sigma.mk ι σ i)) :=
by { rw ←set.image_univ, exact is_closed_map_sigma_mk _ is_closed_univ }
lemma open_embedding_sigma_mk {i : ι} : open_embedding (@sigma.mk ι σ i) :=
open_embedding_of_continuous_injective_open
continuous_sigma_mk injective_sigma_mk is_open_map_sigma_mk
lemma closed_embedding_sigma_mk {i : ι} : closed_embedding (@sigma.mk ι σ i) :=
closed_embedding_of_continuous_injective_closed
continuous_sigma_mk injective_sigma_mk is_closed_map_sigma_mk
lemma embedding_sigma_mk {i : ι} : embedding (@sigma.mk ι σ i) :=
closed_embedding_sigma_mk.1
/-- A map out of a sum type is continuous if its restriction to each summand is. -/
lemma continuous_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, continuous (λ a, f ⟨i, a⟩)) : continuous f :=
continuous_supr_dom (λ i, continuous_coinduced_dom (h i))
lemma continuous_sigma_map {κ : Type*} {τ : κ → Type*} [Π k, topological_space (τ k)]
{f₁ : ι → κ} {f₂ : Π i, σ i → τ (f₁ i)} (hf : ∀ i, continuous (f₂ i)) :
continuous (sigma.map f₁ f₂) :=
continuous_sigma $ λ i,
show continuous (λ a, sigma.mk (f₁ i) (f₂ i a)),
from continuous_sigma_mk.comp (hf i)
lemma is_open_map_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, is_open_map (λ a, f ⟨i, a⟩)) : is_open_map f :=
begin
intros s hs,
rw is_open_sigma_iff at hs,
have : s = ⋃ i, sigma.mk i '' (sigma.mk i ⁻¹' s),
{ rw Union_image_preimage_sigma_mk_eq_self },
rw this,
rw [image_Union],
apply is_open_Union,
intro i,
rw [image_image],
exact h i _ (hs i)
end
/-- The sum of embeddings is an embedding. -/
lemma embedding_sigma_map {τ : ι → Type*} [Π i, topological_space (τ i)]
{f : Π i, σ i → τ i} (hf : ∀ i, embedding (f i)) : embedding (sigma.map id f) :=
begin
refine ⟨⟨_⟩, injective_sigma_map function.injective_id (λ i, (hf i).inj)⟩,
refine le_antisymm
(continuous_iff_le_induced.mp (continuous_sigma_map (λ i, (hf i).continuous))) _,
intros s hs,
replace hs := is_open_sigma_iff.mp hs,
have : ∀ i, ∃ t, is_open t ∧ f i ⁻¹' t = sigma.mk i ⁻¹' s,
{ intro i,
apply is_open_induced_iff.mp,
convert hs i,
exact (hf i).induced.symm },
choose t ht using this,
apply is_open_induced_iff.mpr,
refine ⟨⋃ i, sigma.mk i '' t i, is_open_Union (λ i, is_open_map_sigma_mk _ (ht i).1), _⟩,
ext p,
rcases p with ⟨i, x⟩,
change (sigma.mk i (f i x) ∈ ⋃ (i : ι), sigma.mk i '' t i) ↔ x ∈ sigma.mk i ⁻¹' s,
rw [←(ht i).2, mem_Union],
split,
{ rintro ⟨j, hj⟩,
rw mem_image at hj,
rcases hj with ⟨y, hy₁, hy₂⟩,
rcases sigma.mk.inj_iff.mp hy₂ with ⟨rfl, hy⟩,
replace hy := eq_of_heq hy,
subst y,
exact hy₁ },
{ intro hx,
use i,
rw mem_image,
exact ⟨f i x, hx, rfl⟩ }
end
end sigma
lemma mem_closure_of_continuous [topological_space α] [topological_space β]
{f : α → β} {a : α} {s : set α} {t : set β}
(hf : continuous f) (ha : a ∈ closure s) (h : ∀a∈s, f a ∈ closure t) :
f a ∈ closure t :=
calc f a ∈ f '' closure s : mem_image_of_mem _ ha
... ⊆ closure (f '' s) : image_closure_subset_closure_image hf
... ⊆ closure (closure t) : closure_mono $ image_subset_iff.mpr $ h
... ⊆ closure t : begin rw [closure_eq_of_is_closed], exact subset.refl _, exact is_closed_closure end
lemma mem_closure_of_continuous2 [topological_space α] [topological_space β] [topological_space γ]
{f : α → β → γ} {a : α} {b : β} {s : set α} {t : set β} {u : set γ}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(h : ∀a∈s, ∀b∈t, f a b ∈ closure u) :
f a b ∈ closure u :=
have (a,b) ∈ closure (set.prod s t),
by simp [closure_prod_eq, ha, hb],
show f (a, b).1 (a, b).2 ∈ closure u,
from @mem_closure_of_continuous (α×β) _ _ _ (λp:α×β, f p.1 p.2) (a,b) _ u hf this $
assume ⟨p₁, p₂⟩ ⟨h₁, h₂⟩, h p₁ h₁ p₂ h₂
|
d22c13dc190b22f5f141cc55c9c4b0f7bda5f95b | 3dc4623269159d02a444fe898d33e8c7e7e9461b | /.github/workflows/project_1_a_decrire/lean-scheme-submission/src/to_mathlib/localization/localization_ideal.lean | 3ac29108fa0b90f959a341335cb93d930c0f9267 | [] | no_license | Or7ando/lean | cc003e6c41048eae7c34aa6bada51c9e9add9e66 | d41169cf4e416a0d42092fb6bdc14131cee9dd15 | refs/heads/master | 1,650,600,589,722 | 1,587,262,906,000 | 1,587,262,906,000 | 255,387,160 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,418 | lean | /-
A concrete characterisation of the ideal map induced by a ring homomorphism
with the localization property.
-/
import ring_theory.ideal_operations
import ring_theory.localization
import to_mathlib.localization.localization_alt
open localization_alt
universe u
section
parameters {R : Type u} [comm_ring R]
parameters {Rf : Type u} [comm_ring Rf] {h : R → Rf} [is_ring_hom h]
parameters {f : R} (HL : is_localization_data (powers f) h)
include HL
lemma localization.zero (I : ideal R) [PI : ideal.is_prime I]
(Hfn : (0 : R) ∈ powers f)
: (ideal.map h I : ideal Rf) = ⊥ :=
begin
have HL' := HL,
rcases HL' with ⟨Hinv, Hden, Hker⟩,
apply ideal.ext,
intros x,
split,
swap,
{ intros H,
simp at H,
rw H,
rw ←is_ring_hom.map_zero h,
apply ideal.mem_map_of_mem,
simp, },
{ intros Hx,
rcases (Hden x) with ⟨⟨a, b⟩, Hab⟩,
simp at Hab,
rcases (Hinv a) with ⟨w, Hw⟩,
have Hall : ∀ (y : R), y ∈ submonoid_ann (powers f),
intros y,
simp [submonoid_ann, set.range, ann_aux],
use [⟨y, ⟨0, Hfn⟩⟩],
simp,
have Htop : submonoid_ann (powers f) = ⊤,
apply ideal.ext,
intros x,
split,
{ intros Hx,
cases Hx,
unfold ann_aux at Hx_w, },
{ intros Hx,
exact (Hall x), },
replace Hker := inverts_ker (powers f) h (inverts_of_data (powers f) h Hinv),
unfold ker at Hker,
rw Htop at Hker,
have Hx : (1 : R) ∈ (⊤ : ideal R),
trivial,
replace Hx := Hker Hx,
replace Hx : h 1 = 0 := Hx,
rw (is_ring_hom.map_one h) at Hx,
rw ←mul_one x,
rw Hx,
simp, },
end
-- Concrete ideal.
def localisation_map_ideal (I : ideal R) : ideal Rf :=
{ carrier := { x | ∃ (y ∈ h '' I) (r : Rf), x = y * r },
zero :=
begin
use [h 0, 0],
exact ⟨I.2, rfl⟩,
use 1,
rw mul_one,
rw ←is_ring_hom.map_zero h,
end,
add :=
begin
intros x y Hx Hy,
rcases Hx with ⟨a, ⟨Ha, ⟨r, Hx⟩⟩⟩,
rcases Hy with ⟨b, ⟨Hb, ⟨t, Hy⟩⟩⟩,
rcases Ha with ⟨v, ⟨Hv, Ha⟩⟩,
rcases Hb with ⟨w, ⟨Hw, Hb⟩⟩,
rw ←Ha at Hx,
rw ←Hb at Hy,
rw [Hx, Hy],
rcases HL with ⟨Hinv, Hden, Hker⟩,
rcases (Hden r) with ⟨⟨fn, l⟩, Hl⟩,
rcases (Hinv fn) with ⟨hfninv, Hfn⟩,
simp at Hl,
rw mul_comm at Hfn,
rcases (Hden t) with ⟨⟨fm, k⟩, Hk⟩,
rcases (Hinv fm) with ⟨hfminv, Hfm⟩,
simp at Hk,
rw mul_comm at Hfm,
-- Get rid of r.
rw [←one_mul (_ + _), ←Hfn, mul_assoc, mul_add, mul_comm _ r, ←mul_assoc _ r _, Hl],
-- Get rid of t.
rw [←one_mul (_ * _), ←Hfm, mul_assoc, ←mul_assoc (h _) _ _, mul_comm (h _)],
rw [mul_assoc _ (h _) _, mul_add, ←mul_assoc _ _ t, add_comm],
rw [←mul_assoc (h fm) _ _, mul_comm (h fm), mul_assoc _ _ t, Hk],
-- Rearrange.
repeat { rw ←is_ring_hom.map_mul h, },
rw [←mul_assoc _ _ v, mul_assoc ↑fn, mul_comm w, ←mul_assoc ↑fn],
rw [←is_ring_hom.map_add h, ←mul_assoc, mul_comm],
-- Ready to prove it.
have HyI : ↑fn * k * w + ↑fm * l * v ∈ ↑I,
apply I.3,
{ apply I.4,
exact Hw, },
{ apply I.4,
exact Hv, },
use [h (↑fn * k * w + ↑fm * l * v)],
use [⟨↑fn * k * w + ↑fm * l * v, ⟨HyI, rfl⟩⟩],
use [hfminv * hfninv],
end,
smul :=
begin
intros c x Hx,
rcases Hx with ⟨a, ⟨Ha, ⟨r, Hx⟩⟩⟩,
rcases Ha with ⟨v, ⟨Hv, Ha⟩⟩,
rw [Hx, ←Ha],
rw mul_comm _ r,
unfold has_scalar.smul,
rw [mul_comm r, mul_comm c, mul_assoc],
use [h v, ⟨v, ⟨Hv, rfl⟩⟩, r * c],
end, }
-- They coincide
lemma localisation_map_ideal.eq (I : ideal R) [PI : ideal.is_prime I]
: ideal.map h I = localisation_map_ideal I :=
begin
have HL' := HL,
rcases HL' with ⟨Hinv, Hden, Hker⟩,
apply le_antisymm,
{ have Hgen : h '' I ⊆ localisation_map_ideal I,
intros x Hx,
use [x, Hx, 1],
simp,
replace Hgen := ideal.span_mono Hgen,
rw ideal.span_eq at Hgen,
exact Hgen, },
{ intros x Hx,
rcases Hx with ⟨y, ⟨z, ⟨HzI, Hzy⟩⟩, ⟨r, Hr⟩⟩,
rw [Hr, ←Hzy],
exact ideal.mul_mem_right _ (ideal.mem_map_of_mem HzI), }
end
end
|
6edf855dd7fd10d4b3d18e3d5dae2cc40faeaae1 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /src/Init/Lean/Compiler/IR/CtorLayout.lean | e3fe13f61a209872a349e76ca15a02fa070b2683 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 1,001 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Environment
import Init.Lean.Compiler.IR.Format
namespace Lean
namespace IR
inductive CtorFieldInfo
| irrelevant
| object (i : Nat)
| usize (i : Nat)
| scalar (sz : Nat) (offset : Nat) (type : IRType)
namespace CtorFieldInfo
def format : CtorFieldInfo → Format
| irrelevant => "◾"
| object i => "obj@" ++ fmt i
| usize i => "usize@" ++ fmt i
| scalar sz offset type => "scalar#" ++ fmt sz ++ "@" ++ fmt offset ++ ":" ++ fmt type
instance : HasFormat CtorFieldInfo := ⟨format⟩
end CtorFieldInfo
structure CtorLayout :=
(cidx : Nat)
(fieldInfo : List CtorFieldInfo)
(numObjs : Nat)
(numUSize : Nat)
(scalarSize : Nat)
@[extern "lean_ir_get_ctor_layout"]
constant getCtorLayout (env : @& Environment) (ctorName : @& Name) : Except String CtorLayout := arbitrary _
end IR
end Lean
|
83afb4a0ae46dae0898035b85e75fe4697d8d5fc | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/category_theory/closed/cartesian.lean | 9de363075a2f3e24149406c69bb615c20873aece | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 16,332 | lean | /-
Copyright (c) 2020 Bhavik Mehta, Edward Ayers, Thomas Read. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Edward Ayers, Thomas Read
-/
import category_theory.limits.shapes.finite_products
import category_theory.limits.shapes.constructions.preserve_binary_products
import category_theory.closed.monoidal
import category_theory.monoidal.of_has_finite_products
import category_theory.adjunction
import category_theory.epi_mono
/-!
# Cartesian closed categories
Given a category with finite products, the cartesian monoidal structure is provided by the local
instance `monoidal_of_has_finite_products`.
We define exponentiable objects to be closed objects with respect to this monoidal structure,
i.e. `(X × -)` is a left adjoint.
We say a category is cartesian closed if every object is exponentiable
(equivalently, that the category equipped with the cartesian monoidal structure is closed monoidal).
Show that exponential forms a difunctor and define the exponential comparison morphisms.
## TODO
Some of the results here are true more generally for closed objects and
for closed monoidal categories, and these could be generalised.
-/
universes v u u₂
noncomputable theory
namespace category_theory
open category_theory category_theory.category category_theory.limits
local attribute [instance] monoidal_of_has_finite_products
/--
An object `X` is *exponentiable* if `(X × -)` is a left adjoint.
We define this as being `closed` in the cartesian monoidal structure.
-/
abbreviation exponentiable {C : Type u} [category.{v} C] [has_finite_products C] (X : C) :=
closed X
/--
If `X` and `Y` are exponentiable then `X ⨯ Y` is.
This isn't an instance because it's not usually how we want to construct exponentials, we'll usually
prove all objects are exponential uniformly.
-/
def binary_product_exponentiable {C : Type u} [category.{v} C] [has_finite_products C] {X Y : C}
(hX : exponentiable X) (hY : exponentiable Y) : exponentiable (X ⨯ Y) :=
{ is_adj :=
begin
haveI := hX.is_adj,
haveI := hY.is_adj,
exact adjunction.left_adjoint_of_nat_iso (monoidal_category.tensor_left_tensor _ _).symm
end }
/--
The terminal object is always exponentiable.
This isn't an instance because most of the time we'll prove cartesian closed for all objects
at once, rather than just for this one.
-/
def terminal_exponentiable {C : Type u} [category.{v} C] [has_finite_products C] :
exponentiable ⊤_C :=
unit_closed
/--
A category `C` is cartesian closed if it has finite products and every object is exponentiable.
We define this as `monoidal_closed` with respect to the cartesian monoidal structure.
-/
abbreviation cartesian_closed (C : Type u) [category.{v} C] [has_finite_products C] :=
monoidal_closed C
variables {C : Type u} [category.{v} C] (A B : C) {X X' Y Y' Z : C}
section exp
variables [has_finite_products C] [exponentiable A]
/-- This is (-)^A. -/
def exp : C ⥤ C :=
(@closed.is_adj _ _ _ A _).right
/-- The adjunction between A ⨯ - and (-)^A. -/
def exp.adjunction : prod.functor.obj A ⊣ exp A :=
closed.is_adj.adj
/-- The evaluation natural transformation. -/
def ev : exp A ⋙ prod.functor.obj A ⟶ 𝟭 C :=
closed.is_adj.adj.counit
/-- The coevaluation natural transformation. -/
def coev : 𝟭 C ⟶ prod.functor.obj A ⋙ exp A :=
closed.is_adj.adj.unit
@[simp, reassoc]
lemma ev_naturality {X Y : C} (f : X ⟶ Y) :
limits.prod.map (𝟙 A) ((exp A).map f) ≫ (ev A).app Y = (ev A).app X ≫ f :=
(ev A).naturality f
@[simp, reassoc]
lemma coev_naturality {X Y : C} (f : X ⟶ Y) :
f ≫ (coev A).app Y = (coev A).app X ≫ (exp A).map (limits.prod.map (𝟙 A) f) :=
(coev A).naturality f
notation A ` ⟹ `:20 B:20 := (exp A).obj B
notation B ` ^^ `:30 A:30 := (exp A).obj B
@[simp, reassoc] lemma ev_coev :
limits.prod.map (𝟙 A) ((coev A).app B) ≫ (ev A).app (A ⨯ B) = 𝟙 (A ⨯ B) :=
adjunction.left_triangle_components (exp.adjunction A)
@[simp, reassoc] lemma coev_ev : (coev A).app (A⟹B) ≫ (exp A).map ((ev A).app B) = 𝟙 (A⟹B) :=
adjunction.right_triangle_components (exp.adjunction A)
end exp
variables {A}
-- Wrap these in a namespace so we don't clash with the core versions.
namespace cartesian_closed
variables [has_finite_products C] [exponentiable A]
/-- Currying in a cartesian closed category. -/
def curry : (A ⨯ Y ⟶ X) → (Y ⟶ A ⟹ X) :=
(closed.is_adj.adj.hom_equiv _ _).to_fun
/-- Uncurrying in a cartesian closed category. -/
def uncurry : (Y ⟶ A ⟹ X) → (A ⨯ Y ⟶ X) :=
(closed.is_adj.adj.hom_equiv _ _).inv_fun
end cartesian_closed
open cartesian_closed
variables [has_finite_products C] [exponentiable A]
@[reassoc]
lemma curry_natural_left (f : X ⟶ X') (g : A ⨯ X' ⟶ Y) :
curry (limits.prod.map (𝟙 _) f ≫ g) = f ≫ curry g :=
adjunction.hom_equiv_naturality_left _ _ _
@[reassoc]
lemma curry_natural_right (f : A ⨯ X ⟶ Y) (g : Y ⟶ Y') :
curry (f ≫ g) = curry f ≫ (exp _).map g :=
adjunction.hom_equiv_naturality_right _ _ _
@[reassoc]
lemma uncurry_natural_right (f : X ⟶ A⟹Y) (g : Y ⟶ Y') :
uncurry (f ≫ (exp _).map g) = uncurry f ≫ g :=
adjunction.hom_equiv_naturality_right_symm _ _ _
@[reassoc]
lemma uncurry_natural_left (f : X ⟶ X') (g : X' ⟶ A⟹Y) :
uncurry (f ≫ g) = limits.prod.map (𝟙 _) f ≫ uncurry g :=
adjunction.hom_equiv_naturality_left_symm _ _ _
@[simp]
lemma uncurry_curry (f : A ⨯ X ⟶ Y) : uncurry (curry f) = f :=
(closed.is_adj.adj.hom_equiv _ _).left_inv f
@[simp]
lemma curry_uncurry (f : X ⟶ A⟹Y) : curry (uncurry f) = f :=
(closed.is_adj.adj.hom_equiv _ _).right_inv f
lemma curry_eq_iff (f : A ⨯ Y ⟶ X) (g : Y ⟶ A ⟹ X) :
curry f = g ↔ f = uncurry g :=
adjunction.hom_equiv_apply_eq _ f g
lemma eq_curry_iff (f : A ⨯ Y ⟶ X) (g : Y ⟶ A ⟹ X) :
g = curry f ↔ uncurry g = f :=
adjunction.eq_hom_equiv_apply _ f g
-- I don't think these two should be simp.
lemma uncurry_eq (g : Y ⟶ A ⟹ X) : uncurry g = limits.prod.map (𝟙 A) g ≫ (ev A).app X :=
adjunction.hom_equiv_counit _
lemma curry_eq (g : A ⨯ Y ⟶ X) : curry g = (coev A).app Y ≫ (exp A).map g :=
adjunction.hom_equiv_unit _
lemma uncurry_id_eq_ev (A X : C) [exponentiable A] : uncurry (𝟙 (A ⟹ X)) = (ev A).app X :=
by rw [uncurry_eq, prod.map_id_id, id_comp]
lemma curry_id_eq_coev (A X : C) [exponentiable A] : curry (𝟙 _) = (coev A).app X :=
by { rw [curry_eq, (exp A).map_id (A ⨯ _)], apply comp_id }
lemma curry_injective : function.injective (curry : (A ⨯ Y ⟶ X) → (Y ⟶ A ⟹ X)) :=
(closed.is_adj.adj.hom_equiv _ _).injective
lemma uncurry_injective : function.injective (uncurry : (Y ⟶ A ⟹ X) → (A ⨯ Y ⟶ X)) :=
(closed.is_adj.adj.hom_equiv _ _).symm.injective
/--
Show that the exponential of the terminal object is isomorphic to itself, i.e. `X^1 ≅ X`.
The typeclass argument is explicit: any instance can be used.
-/
def exp_terminal_iso_self [exponentiable ⊤_C] : (⊤_C ⟹ X) ≅ X :=
yoneda.ext (⊤_ C ⟹ X) X
(λ Y f, (prod.left_unitor Y).inv ≫ uncurry f)
(λ Y f, curry ((prod.left_unitor Y).hom ≫ f))
(λ Z g, by rw [curry_eq_iff, iso.hom_inv_id_assoc] )
(λ Z g, by simp)
(λ Z W f g, by rw [uncurry_natural_left, prod.left_unitor_inv_naturality_assoc f] )
/-- The internal element which points at the given morphism. -/
def internalize_hom (f : A ⟶ Y) : ⊤_C ⟶ (A ⟹ Y) :=
curry (limits.prod.fst ≫ f)
section pre
variables {B}
/-- Pre-compose an internal hom with an external hom. -/
def pre (X : C) (f : B ⟶ A) [exponentiable B] : (A⟹X) ⟶ B⟹X :=
curry (limits.prod.map f (𝟙 _) ≫ (ev A).app X)
lemma pre_id (A X : C) [exponentiable A] : pre X (𝟙 A) = 𝟙 (A⟹X) :=
by { rw [pre, prod.map_id_id, id_comp, ← uncurry_id_eq_ev], simp }
-- There's probably a better proof of this somehow
/-- Precomposition is contrafunctorial. -/
lemma pre_map [exponentiable B] {D : C} [exponentiable D] (f : A ⟶ B) (g : B ⟶ D) :
pre X (f ≫ g) = pre X g ≫ pre X f :=
begin
rw [pre, curry_eq_iff, pre, uncurry_natural_left, pre, uncurry_curry, prod.map_swap_assoc,
prod.map_comp_id, assoc, ← uncurry_id_eq_ev, ← uncurry_id_eq_ev, ← uncurry_natural_left,
curry_natural_right, comp_id, uncurry_natural_right, uncurry_curry],
end
end pre
lemma pre_post_comm [cartesian_closed C] {A B : C} {X Y : Cᵒᵖ} (f : A ⟶ B) (g : X ⟶ Y) :
pre A g.unop ≫ (exp Y.unop).map f = (exp X.unop).map f ≫ pre B g.unop :=
begin
rw [pre, pre, ← curry_natural_left, eq_curry_iff, uncurry_natural_right, uncurry_curry,
prod.map_swap_assoc, ev_naturality, assoc],
end
/-- The internal hom functor given by the cartesian closed structure. -/
def internal_hom [cartesian_closed C] : C ⥤ Cᵒᵖ ⥤ C :=
{ obj := λ X,
{ obj := λ Y, Y.unop ⟹ X,
map := λ Y Y' f, pre _ f.unop,
map_id' := λ Y, pre_id _ _,
map_comp' := λ Y Y' Y'' f g, pre_map _ _ },
map := λ A B f, { app := λ X, (exp X.unop).map f, naturality' := λ X Y g, pre_post_comm _ _ },
map_id' := λ X, by { ext, apply functor.map_id },
map_comp' := λ X Y Z f g, by { ext, apply functor.map_comp } }
/-- If an initial object `I` exists in a CCC, then `A ⨯ I ≅ I`. -/
@[simps]
def zero_mul {I : C} (t : is_initial I) : A ⨯ I ≅ I :=
{ hom := limits.prod.snd,
inv := t.to _,
hom_inv_id' :=
begin
have: (limits.prod.snd : A ⨯ I ⟶ I) = uncurry (t.to _),
rw ← curry_eq_iff,
apply t.hom_ext,
rw [this, ← uncurry_natural_right, ← eq_curry_iff],
apply t.hom_ext,
end,
inv_hom_id' := t.hom_ext _ _ }
/-- If an initial object `0` exists in a CCC, then `0 ⨯ A ≅ 0`. -/
def mul_zero {I : C} (t : is_initial I) : I ⨯ A ≅ I :=
limits.prod.braiding _ _ ≪≫ zero_mul t
/-- If an initial object `0` exists in a CCC then `0^B ≅ 1` for any `B`. -/
def pow_zero {I : C} (t : is_initial I) [cartesian_closed C] : I ⟹ B ≅ ⊤_ C :=
{ hom := default _,
inv := curry ((mul_zero t).hom ≫ t.to _),
hom_inv_id' :=
begin
rw [← curry_natural_left, curry_eq_iff, ← cancel_epi (mul_zero t).inv],
{ apply t.hom_ext },
{ apply_instance },
{ apply_instance }
end }
-- TODO: Generalise the below to its commutated variants.
-- TODO: Define a distributive category, so that zero_mul and friends can be derived from this.
/-- In a CCC with binary coproducts, the distribution morphism is an isomorphism. -/
def prod_coprod_distrib [has_binary_coproducts C] [cartesian_closed C] (X Y Z : C) :
(Z ⨯ X) ⨿ (Z ⨯ Y) ≅ Z ⨯ (X ⨿ Y) :=
{ hom := coprod.desc (limits.prod.map (𝟙 _) coprod.inl) (limits.prod.map (𝟙 _) coprod.inr),
inv := uncurry (coprod.desc (curry coprod.inl) (curry coprod.inr)),
hom_inv_id' :=
begin
apply coprod.hom_ext,
rw [coprod.inl_desc_assoc, comp_id, ←uncurry_natural_left, coprod.inl_desc, uncurry_curry],
rw [coprod.inr_desc_assoc, comp_id, ←uncurry_natural_left, coprod.inr_desc, uncurry_curry],
end,
inv_hom_id' :=
begin
rw [← uncurry_natural_right, ←eq_curry_iff],
apply coprod.hom_ext,
rw [coprod.inl_desc_assoc, ←curry_natural_right, coprod.inl_desc, ←curry_natural_left, comp_id],
rw [coprod.inr_desc_assoc, ←curry_natural_right, coprod.inr_desc, ←curry_natural_left, comp_id],
end }
/--
If an initial object `I` exists in a CCC then it is a strict initial object,
i.e. any morphism to `I` is an iso.
This actually shows a slightly stronger version: any morphism to an initial object from an
exponentiable object is an isomorphism.
-/
def strict_initial {I : C} (t : is_initial I) (f : A ⟶ I) : is_iso f :=
begin
haveI : mono (limits.prod.lift (𝟙 A) f ≫ (zero_mul t).hom) := mono_comp _ _,
rw [zero_mul_hom, prod.lift_snd] at _inst,
haveI: split_epi f := ⟨t.to _, t.hom_ext _ _⟩,
apply is_iso_of_mono_of_split_epi
end
instance to_initial_is_iso [has_initial C] (f : A ⟶ ⊥_ C) : is_iso f :=
strict_initial initial_is_initial _
/-- If an initial object `0` exists in a CCC then every morphism from it is monic. -/
lemma initial_mono {I : C} (B : C) (t : is_initial I) [cartesian_closed C] : mono (t.to B) :=
⟨λ B g h _, by { haveI := strict_initial t g, haveI := strict_initial t h, exact eq_of_inv_eq_inv (t.hom_ext _ _) }⟩
instance initial.mono_to [has_initial C] (B : C) [cartesian_closed C] : mono (initial.to B) :=
initial_mono B initial_is_initial
variables {D : Type u₂} [category.{v} D]
section functor
variables [has_finite_products D]
/--
Transport the property of being cartesian closed across an equivalence of categories.
Note we didn't require any coherence between the choice of finite products here, since we transport
along the `prod_comparison` isomorphism.
-/
def cartesian_closed_of_equiv (e : C ≌ D) [h : cartesian_closed C] : cartesian_closed D :=
{ closed := λ X,
{ is_adj :=
begin
haveI q : exponentiable (e.inverse.obj X) := infer_instance,
have : is_left_adjoint (prod.functor.obj (e.inverse.obj X)) := q.is_adj,
have : e.functor ⋙ prod.functor.obj X ⋙ e.inverse ≅ prod.functor.obj (e.inverse.obj X),
apply nat_iso.of_components _ _,
intro Y,
{ apply as_iso (prod_comparison e.inverse X (e.functor.obj Y)) ≪≫ _,
apply prod.map_iso (iso.refl _) (e.unit_iso.app Y).symm },
{ intros Y Z g,
dsimp [prod_comparison],
simp [prod.comp_lift, ← e.inverse.map_comp, ← e.inverse.map_comp_assoc],
-- I wonder if it would be a good idea to make `map_comp` a simp lemma the other way round
dsimp, simp -- See note [dsimp, simp]
},
{ have : is_left_adjoint (e.functor ⋙ prod.functor.obj X ⋙ e.inverse) :=
by exactI adjunction.left_adjoint_of_nat_iso this.symm,
have : is_left_adjoint (e.inverse ⋙ e.functor ⋙ prod.functor.obj X ⋙ e.inverse) :=
by exactI adjunction.left_adjoint_of_comp e.inverse _,
have : (e.inverse ⋙ e.functor ⋙ prod.functor.obj X ⋙ e.inverse) ⋙ e.functor ≅
prod.functor.obj X,
{ apply iso_whisker_right e.counit_iso (prod.functor.obj X ⋙ e.inverse ⋙ e.functor) ≪≫ _,
change prod.functor.obj X ⋙ e.inverse ⋙ e.functor ≅ prod.functor.obj X,
apply iso_whisker_left (prod.functor.obj X) e.counit_iso, },
resetI,
apply adjunction.left_adjoint_of_nat_iso this },
end } }
variables [cartesian_closed C] [cartesian_closed D]
variables (F : C ⥤ D) [preserves_limits_of_shape (discrete walking_pair) F]
/--
The exponential comparison map.
`F` is a cartesian closed functor if this is an iso for all `A,B`.
-/
def exp_comparison (A B : C) :
F.obj (A ⟹ B) ⟶ F.obj A ⟹ F.obj B :=
curry (inv (prod_comparison F A _) ≫ F.map ((ev _).app _))
/-- The exponential comparison map is natural in its left argument. -/
lemma exp_comparison_natural_left (A A' B : C) (f : A' ⟶ A) :
exp_comparison F A B ≫ pre (F.obj B) (F.map f) = F.map (pre B f) ≫ exp_comparison F A' B :=
begin
rw [exp_comparison, exp_comparison, ← curry_natural_left, eq_curry_iff, uncurry_natural_left,
pre, uncurry_curry, prod.map_swap_assoc, curry_eq, prod.map_id_comp, assoc, ev_naturality],
erw [ev_coev_assoc, ← F.map_id, ← prod_comparison_inv_natural_assoc,
← F.map_id, ← prod_comparison_inv_natural_assoc, ← F.map_comp, ← F.map_comp, pre, curry_eq,
prod.map_id_comp, assoc, (ev _).naturality, ev_coev_assoc], refl,
end
/-- The exponential comparison map is natural in its right argument. -/
lemma exp_comparison_natural_right (A B B' : C) (f : B ⟶ B') :
exp_comparison F A B ≫ (exp (F.obj A)).map (F.map f) =
F.map ((exp A).map f) ≫ exp_comparison F A B' :=
by
erw [exp_comparison, ← curry_natural_right, curry_eq_iff, exp_comparison, uncurry_natural_left,
uncurry_curry, assoc, ← F.map_comp, ← (ev _).naturality, F.map_comp,
prod_comparison_inv_natural_assoc, F.map_id]
-- TODO: If F has a left adjoint L, then F is cartesian closed if and only if
-- L (B ⨯ F A) ⟶ L B ⨯ L F A ⟶ L B ⨯ A
-- is an iso for all A ∈ D, B ∈ C.
-- Corollary: If F has a left adjoint L which preserves finite products, F is cartesian closed iff
-- F is full and faithful.
end functor
end category_theory
|
cef1f4a65a6dfe9edcb385e0d60ef25b9c2af8ee | f083c4ed5d443659f3ed9b43b1ca5bb037ddeb58 | /analysis/metric_space.lean | 636a91be4e6d112e457435c9bcd914a1b38d7a18 | [
"Apache-2.0"
] | permissive | semorrison/mathlib | 1be6f11086e0d24180fec4b9696d3ec58b439d10 | 20b4143976dad48e664c4847b75a85237dca0a89 | refs/heads/master | 1,583,799,212,170 | 1,535,634,130,000 | 1,535,730,505,000 | 129,076,205 | 0 | 0 | Apache-2.0 | 1,551,697,998,000 | 1,523,442,265,000 | Lean | UTF-8 | Lean | false | false | 21,888 | lean | /-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Metric spaces.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro
Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and
topological spaces. For example:
open and closed sets, compactness, completeness, continuity and uniform continuity
-/
import data.real.nnreal analysis.topology.topological_structures
open lattice set filter classical
noncomputable theory
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- Construct a metric space from a distance function and metric space axioms -/
def metric_space.uniform_space_of_dist
(dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space α :=
uniform_space.of_core {
uniformity := (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}),
refl := le_infi $ assume ε, le_infi $
by simp [set.subset_def, id_rel, dist_self, (>)] {contextual := tt},
comp := le_infi $ assume ε, le_infi $ assume h, lift'_le
(mem_infi_sets (ε / 2) $ mem_infi_sets (div_pos_of_pos_of_pos h two_pos) (subset.refl _)) $
have ∀ (a b c : α), dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε,
from assume a b c hac hcb,
calc dist a b ≤ dist a c + dist c b : dist_triangle _ _ _
... < ε / 2 + ε / 2 : add_lt_add hac hcb
... = ε : by rw [div_add_div_same, add_self_div_two],
by simpa [comp_rel],
symm := tendsto_infi.2 $ assume ε, tendsto_infi.2 $ assume h,
tendsto_infi' ε $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [dist_comm] }
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
class has_dist (α : Type*) := (dist : α → α → ℝ)
export has_dist (dist)
/-- Metric space
Each metric space induces a canonical `uniform_space` and hence a canonical `topological_space`.
This is enforced in the type class definition, by extending the `uniform_space` structure. When
instantiating a `metric_space` structure, the uniformity fields are not necessary, they will be
filled in by default. -/
class metric_space (α : Type u) extends has_dist α : Type u :=
(dist_self : ∀ x : α, dist x x = 0)
(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(to_uniform_space : uniform_space α := metric_space.uniform_space_of_dist dist dist_self dist_comm dist_triangle)
(uniformity_dist : uniformity = ⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε} . control_laws_tac)
theorem uniformity_dist_of_mem_uniformity {U : filter (α × α)} (D : α → α → ℝ)
(H : ∀ s, s ∈ U.sets ↔ ∃ε>0, ∀{a b:α}, D a b < ε → (a, b) ∈ s) :
U = ⨅ ε>0, principal {p:α×α | D p.1 p.2 < ε} :=
le_antisymm
(le_infi $ λ ε, le_infi $ λ ε0, le_principal_iff.2 $ (H _).2 ⟨ε, ε0, λ a b, id⟩)
(λ r ur, let ⟨ε, ε0, h⟩ := (H _).1 ur in
mem_infi_sets ε $ mem_infi_sets ε0 $ mem_principal_sets.2 $ λ ⟨a, b⟩, h)
variables [metric_space α]
instance metric_space.to_uniform_space' : uniform_space α :=
metric_space.to_uniform_space α
@[simp] theorem dist_self (x : α) : dist x x = 0 := metric_space.dist_self x
theorem eq_of_dist_eq_zero {x y : α} : dist x y = 0 → x = y :=
metric_space.eq_of_dist_eq_zero
theorem dist_comm (x y : α) : dist x y = dist y x := metric_space.dist_comm x y
@[simp] theorem dist_eq_zero {x y : α} : dist x y = 0 ↔ x = y :=
iff.intro eq_of_dist_eq_zero (assume : x = y, this ▸ dist_self _)
@[simp] theorem zero_eq_dist {x y : α} : 0 = dist x y ↔ x = y :=
by rw [eq_comm, dist_eq_zero]
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
metric_space.dist_triangle x y z
theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y :=
by rw dist_comm z; apply dist_triangle
theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z :=
by rw dist_comm y; apply dist_triangle
theorem swap_dist : function.swap (@dist α _) = dist :=
by funext x y; exact dist_comm _ _
theorem abs_dist_sub_le (x y z : α) : abs (dist x z - dist y z) ≤ dist x y :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add.2 (dist_triangle _ _ _),
sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
have 2 * dist x y ≥ 0,
from calc 2 * dist x y = dist x y + dist y x : by rw [dist_comm x y, two_mul]
... ≥ 0 : by rw ← dist_self x; apply dist_triangle,
nonneg_of_mul_nonneg_left this two_pos
@[simp] theorem dist_le_zero {x y : α} : dist x y ≤ 0 ↔ x = y :=
by simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y
@[simp] theorem dist_pos {x y : α} : 0 < dist x y ↔ x ≠ y :=
by simpa [-dist_le_zero] using not_congr (@dist_le_zero _ _ x y)
section
variables [metric_space α]
def nndist (a b : α) : nnreal := ⟨dist a b, dist_nonneg⟩
@[simp] lemma nndist_self (a : α) : nndist a a = 0 := (nnreal.coe_eq_zero _).1 (dist_self a)
@[simp] lemma coe_dist (a b : α) : (nndist a b : ℝ) = dist a b := rfl
theorem eq_of_nndist_eq_zero {x y : α} : nndist x y = 0 → x = y :=
by simpa [nnreal.eq_iff.symm] using @eq_of_dist_eq_zero α _ x y
theorem nndist_comm (x y : α) : nndist x y = nndist y x :=
by simpa [nnreal.eq_iff.symm] using dist_comm x y
@[simp] theorem nndist_eq_zero {x y : α} : nndist x y = 0 ↔ x = y :=
by simpa [nnreal.eq_iff.symm]
@[simp] theorem zero_eq_nndist {x y : α} : 0 = nndist x y ↔ x = y :=
by simpa [nnreal.eq_iff.symm]
theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
by simpa [nnreal.coe_le] using dist_triangle x y z
theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
by simpa [nnreal.coe_le] using dist_triangle_left x y z
theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
by simpa [nnreal.coe_le] using dist_triangle_right x y z
end
/- instantiate metric space as a topology -/
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
def ball (x : α) (ε : ℝ) : set α := {y | dist y x < ε}
@[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := iff.rfl
theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw dist_comm; refl
/-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/
def closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}
@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : ε > 0 :=
lt_of_le_of_lt dist_nonneg hy
theorem mem_ball_self (h : ε > 0) : x ∈ ball x ε :=
show dist x x < ε, by rw dist_self; assumption
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=
by simp [dist_comm]
theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ :=
λ y (yx : _ < ε₁), lt_of_lt_of_le yx h
theorem ball_disjoint (h : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ z ⟨h₁, h₂⟩,
not_lt_of_le (dist_triangle_left x y z)
(lt_of_lt_of_le (add_lt_add h₁ h₂) h)
theorem ball_disjoint_same (h : ε ≤ dist x y / 2) : ball x ε ∩ ball y ε = ∅ :=
ball_disjoint $ by rwa [← two_mul, ← le_div_iff' two_pos]
theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ :=
λ z zx, by rw ← add_sub_cancel'_right ε₁ ε₂; exact
lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)
theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=
ball_subset $ by rw sub_self_div_two; exact le_of_lt h
theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
⟨_, sub_pos.2 h, ball_subset $ by rw sub_sub_self⟩
theorem ball_eq_empty_iff_nonpos : ε ≤ 0 ↔ ball x ε = ∅ :=
(eq_empty_iff_forall_not_mem.trans
⟨λ h, le_of_not_gt $ λ ε0, h _ $ mem_ball_self ε0,
λ ε0 y h, not_lt_of_le ε0 $ pos_of_mem_ball h⟩).symm
theorem uniformity_dist : uniformity = (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}) :=
metric_space.uniformity_dist _
theorem uniformity_dist' : uniformity = (⨅ε:{ε:ℝ // ε>0}, principal {p:α×α | dist p.1 p.2 < ε.val}) :=
by simp [infi_subtype]; exact uniformity_dist
theorem mem_uniformity_dist {s : set (α×α)} :
s ∈ (@uniformity α _).sets ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) :=
begin
rw [uniformity_dist', infi_sets_eq],
simp [subset_def],
exact assume ⟨r, hr⟩ ⟨p, hp⟩, ⟨⟨min r p, lt_min hr hp⟩, by simp [lt_min_iff] {contextual := tt}⟩,
exact ⟨⟨1, zero_lt_one⟩⟩
end
theorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) :
{p:α×α | dist p.1 p.2 < ε} ∈ (@uniformity α _).sets :=
mem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩
theorem uniform_continuous_of_metric [metric_space β] {f : α → β} :
uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,
∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε :=
uniform_continuous_def.trans
⟨λ H ε ε0, mem_uniformity_dist.1 $ H _ $ dist_mem_uniformity ε0,
λ H r ru,
let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru, ⟨δ, δ0, hδ⟩ := H _ ε0 in
mem_uniformity_dist.2 ⟨δ, δ0, λ a b h, hε (hδ h)⟩⟩
theorem uniform_embedding_of_metric [metric_space β] {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0),
⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu in
⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,
λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in
⟨_, dist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩
theorem totally_bounded_of_metric {s : set α} :
totally_bounded s ↔ ∀ ε > 0, ∃t : set α, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
⟨λ H ε ε0, H _ (dist_mem_uniformity ε0),
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
⟨t, ft, h⟩ := H ε ε0 in
⟨t, ft, subset.trans h $ Union_subset_Union $ λ y, Union_subset_Union $ λ yt z, hε⟩⟩
lemma cauchy_of_metric {f : filter α} :
cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f.sets, ∀ x y ∈ t, dist x y < ε :=
cauchy_iff.trans $ and_congr iff.rfl
⟨λ H ε ε0, let ⟨t, tf, ts⟩ := H _ (dist_mem_uniformity ε0) in
⟨t, tf, λ x y xt yt, @ts (x, y) ⟨xt, yt⟩⟩,
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
⟨t, tf, h⟩ := H ε ε0 in
⟨t, tf, λ ⟨x, y⟩ ⟨hx, hy⟩, hε (h x y hx hy)⟩⟩
theorem nhds_eq_metric : nhds x = (⨅ε:{ε:ℝ // ε>0}, principal (ball x ε.val)) :=
begin
rw [nhds_eq_uniformity, uniformity_dist', lift'_infi],
{ apply congr_arg, funext ε,
rw [lift'_principal],
{ simp [ball, dist_comm] },
{ exact monotone_preimage } },
{ exact ⟨⟨1, zero_lt_one⟩⟩ },
{ intros, refl }
end
theorem mem_nhds_iff_metric : s ∈ (nhds x).sets ↔ ∃ε>0, ball x ε ⊆ s :=
begin
rw [nhds_eq_metric, infi_sets_eq],
{ simp },
{ intros y z, cases y with y hy, cases z with z hz,
refine ⟨⟨min y z, lt_min hy hz⟩, _⟩,
simp [ball_subset_ball, min_le_left, min_le_right] },
{ exact ⟨⟨1, zero_lt_one⟩⟩ }
end
theorem is_open_metric : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=
by simp [is_open_iff_nhds, mem_nhds_iff_metric]
theorem is_open_ball : is_open (ball x ε) :=
is_open_metric.2 $ λ y, exists_ball_subset_ball
theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ (nhds x).sets :=
mem_nhds_sets is_open_ball (mem_ball_self ε0)
theorem tendsto_nhds_of_metric [metric_space β] {f : α → β} {a b} :
tendsto f (nhds a) (nhds b) ↔ ∀ ε > 0,
∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε :=
⟨λ H ε ε0, mem_nhds_iff_metric.1 (H (ball_mem_nhds _ ε0)),
λ H s hs,
let ⟨ε, ε0, hε⟩ := mem_nhds_iff_metric.1 hs, ⟨δ, δ0, hδ⟩ := H _ ε0 in
mem_nhds_iff_metric.2 ⟨δ, δ0, λ x h, hε (hδ h)⟩⟩
theorem continuous_of_metric [metric_space β] {f : α → β} :
continuous f ↔ ∀b (ε > 0), ∃ δ > 0, ∀a,
dist a b < δ → dist (f a) (f b) < ε :=
continuous_iff_tendsto.trans $ forall_congr $ λ b, tendsto_nhds_of_metric
theorem exists_delta_of_continuous [metric_space β] {f : α → β} {ε:ℝ}
(hf : continuous f) (hε : ε > 0) (b : α) :
∃ δ > 0, ∀a, dist a b ≤ δ → dist (f a) (f b) < ε :=
let ⟨δ, δ_pos, hδ⟩ := continuous_of_metric.1 hf b ε hε in
⟨δ / 2, half_pos δ_pos, assume a ha, hδ a $ lt_of_le_of_lt ha $ div_two_lt_of_pos δ_pos⟩
theorem eq_of_forall_dist_le {x y : α} (h : ∀ε, ε > 0 → dist x y ≤ ε) : x = y :=
eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)
instance metric_space.to_separated : separated α :=
separated_def.2 $ λ x y h, eq_of_forall_dist_le $
λ ε ε0, le_of_lt (h _ (dist_mem_uniformity ε0))
/-- Instantiate the reals as a metric space. -/
instance : metric_space ℝ :=
{ dist := λx y, abs (x - y),
dist_self := by simp [abs_zero],
eq_of_dist_eq_zero := by simp [add_neg_eq_zero],
dist_comm := assume x y, abs_sub _ _,
dist_triangle := assume x y z, abs_sub_le _ _ _ }
theorem real.dist_eq (x y : ℝ) : dist x y = abs (x - y) := rfl
theorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x :=
by simp [real.dist_eq]
@[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b :=
abs_of_nonneg dist_nonneg
instance : orderable_topology ℝ :=
orderable_topology_of_nhds_abs $ λ x, begin
simp only [show ∀ r, {b : ℝ | abs (x - b) < r} = ball x r,
by simp [-sub_eq_add_neg, abs_sub, ball, real.dist_eq]],
apply le_antisymm,
{ simp [le_infi_iff],
exact λ ε ε0, mem_nhds_sets (is_open_ball) (mem_ball_self ε0) },
{ intros s h,
rcases mem_nhds_iff_metric.1 h with ⟨ε, ε0, ss⟩,
exact mem_infi_sets _ (mem_infi_sets ε0 (mem_principal_sets.2 ss)) },
end
def metric_space.replace_uniformity {α} [U : uniform_space α] (m : metric_space α)
(H : @uniformity _ U = @uniformity _ (metric_space.to_uniform_space α)) :
metric_space α :=
{ dist := @dist _ m.to_has_dist,
dist_self := dist_self,
eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _,
dist_comm := dist_comm,
dist_triangle := dist_triangle,
to_uniform_space := U,
uniformity_dist := H.trans (@uniformity_dist α _) }
def metric_space.induced {α β} (f : α → β) (hf : function.injective f)
(m : metric_space β) : metric_space α :=
{ dist := λ x y, dist (f x) (f y),
dist_self := λ x, dist_self _,
eq_of_dist_eq_zero := λ x y h, hf (dist_eq_zero.1 h),
dist_comm := λ x y, dist_comm _ _,
dist_triangle := λ x y z, dist_triangle _ _ _,
to_uniform_space := uniform_space.vmap f m.to_uniform_space,
uniformity_dist := begin
apply @uniformity_dist_of_mem_uniformity _ _ (λ x y, dist (f x) (f y)),
refine λ s, mem_vmap_sets.trans _,
split; intro H,
{ rcases H with ⟨r, ru, rs⟩,
rcases mem_uniformity_dist.1 ru with ⟨ε, ε0, hε⟩,
refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
{ rcases H with ⟨ε, ε0, hε⟩,
exact ⟨_, dist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
end }
theorem metric_space.induced_uniform_embedding {α β} (f : α → β) (hf : function.injective f)
(m : metric_space β) :
by haveI := metric_space.induced f hf m;
exact uniform_embedding f :=
by let := metric_space.induced f hf m; exactI
uniform_embedding_of_metric.2 ⟨hf, uniform_continuous_vmap, λ ε ε0, ⟨ε, ε0, λ a b, id⟩⟩
instance {p : α → Prop} [t : metric_space α] : metric_space (subtype p) :=
metric_space.induced subtype.val (λ x y, subtype.eq) t
theorem subtype.dist_eq {p : α → Prop} [t : metric_space α] (x y : subtype p) :
dist x y = dist x.1 y.1 := rfl
instance prod.metric_space_max [metric_space β] : metric_space (α × β) :=
{ dist := λ x y, max (dist x.1 y.1) (dist x.2 y.2),
dist_self := λ x, by simp,
eq_of_dist_eq_zero := λ x y h, begin
cases max_le_iff.1 (le_of_eq h) with h₁ h₂,
exact prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩
end,
dist_comm := λ x y, by simp [dist_comm],
dist_triangle := λ x y z, max_le
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
uniformity_dist := begin
refine uniformity_prod.trans _,
simp [uniformity_dist, vmap_infi],
rw ← infi_inf_eq, congr, funext,
rw ← infi_inf_eq, congr, funext,
simp [inf_principal, ext_iff, max_lt_iff]
end,
to_uniform_space := prod.uniform_space }
theorem uniform_continuous_dist' : uniform_continuous (λp:α×α, dist p.1 p.2) :=
uniform_continuous_of_metric.2 (λ ε ε0, ⟨ε/2, half_pos ε0,
begin
suffices,
{ intros p q h, cases p with p₁ p₂, cases q with q₁ q₂,
cases max_lt_iff.1 h with h₁ h₂, clear h,
dsimp at h₁ h₂ ⊢,
rw real.dist_eq,
refine abs_sub_lt_iff.2 ⟨_, _⟩,
{ revert p₁ p₂ q₁ q₂ h₁ h₂, exact this },
{ apply this; rwa dist_comm } },
intros p₁ p₂ q₁ q₂ h₁ h₂,
have := add_lt_add
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1,
rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this
end⟩)
theorem uniform_continuous_dist [uniform_space β] {f g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (λb, dist (f b) (g b)) :=
(hf.prod_mk hg).comp uniform_continuous_dist'
theorem continuous_dist' : continuous (λp:α×α, dist p.1 p.2) :=
uniform_continuous_dist'.continuous
theorem continuous_dist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, dist (f b) (g b)) :=
(hf.prod_mk hg).comp continuous_dist'
theorem tendsto_dist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) :
tendsto (λx, dist (f x) (g x)) x (nhds (dist a b)) :=
have tendsto (λp:α×α, dist p.1 p.2) (nhds (a, b)) (nhds (dist a b)),
from continuous_iff_tendsto.mp continuous_dist' (a, b),
(hf.prod_mk hg).comp (by rw [nhds_prod_eq] at this; exact this)
lemma nhds_vmap_dist (a : α) : (nhds (0 : ℝ)).vmap (λa', dist a' a) = nhds a :=
have h₁ : ∀ε, (λa', dist a' a) ⁻¹' ball 0 ε ⊆ ball a ε,
by simp [subset_def, real.dist_0_eq_abs],
have h₂ : tendsto (λa', dist a' a) (nhds a) (nhds (dist a a)),
from tendsto_dist tendsto_id tendsto_const_nhds,
le_antisymm
(by simp [h₁, nhds_eq_metric, infi_le_infi, principal_mono,
-le_principal_iff, -le_infi_iff])
(by simpa [map_le_iff_le_vmap.symm, tendsto] using h₂)
lemma tendsto_iff_dist_tendsto_zero {f : β → α} {x : filter β} {a : α} :
(tendsto f x (nhds a)) ↔ (tendsto (λb, dist (f b) a) x (nhds 0)) :=
by rw [← nhds_vmap_dist a, tendsto_vmap_iff]
theorem is_closed_ball : is_closed (closed_ball x ε) :=
is_closed_le (continuous_dist continuous_id continuous_const) continuous_const
section pi
open finset lattice
variables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
instance has_dist_pi : has_dist (Πb, π b) :=
⟨λf g, ((finset.sup univ (λb, nndist (f b) (g b)) : nnreal) : ℝ)⟩
lemma dist_pi_def (f g : Πb, π b) :
dist f g = (finset.sup univ (λb, nndist (f b) (g b)) : nnreal) := rfl
instance metric_space_pi : metric_space (Πb, π b) :=
{ dist := dist,
dist_self := assume f, (nnreal.coe_eq_zero _).2 $ bot_unique $ finset.sup_le $ by simp,
dist_comm := assume f g, nnreal.eq_iff.2 $ by congr; ext a; exact nndist_comm _ _,
dist_triangle := assume f g h, show dist f h ≤ (dist f g) + (dist g h), from
begin
simp only [dist_pi_def, (nnreal.coe_add _ _).symm, (nnreal.coe_le _ _).symm,
finset.sup_le_iff],
assume b hb,
exact le_trans (nndist_triangle _ (g b) _) (add_le_add (le_sup hb) (le_sup hb))
end,
eq_of_dist_eq_zero := assume f g eq0,
begin
simp only [dist_pi_def, nnreal.coe_eq_zero, nnreal.bot_eq_zero.symm, eq_bot_iff,
finset.sup_le_iff] at eq0,
exact (funext $ assume b, eq_of_nndist_eq_zero $ bot_unique $ eq0 b $ mem_univ b),
end }
end pi
lemma lebesgue_number_lemma_of_metric
{s : set α} {ι} {c : ι → set α} (hs : compact s)
(hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=
let ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂,
⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en in
⟨δ, δ0, assume x hx, let ⟨i, hi⟩ := hn x hx in
⟨i, assume y hy, hi (hδ (mem_ball'.mp hy))⟩⟩
lemma lebesgue_number_lemma_of_metric_sUnion
{s : set α} {c : set (set α)} (hs : compact s)
(hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t :=
by rw sUnion_eq_Union at hc₂;
simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
|
03a5cb7e81c68d0e4255de8d5c2fa0bbc22549c4 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/algebra/direct_sum/decomposition.lean | 359f406bbb84dea83f9bd4d147d3627fc008ccd5 | [
"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,272 | lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Jujian Zhang
-/
import algebra.direct_sum.module
import algebra.module.submodule.basic
/-!
# Decompositions of additive monoids, groups, and modules into direct sums
## Main definitions
* `direct_sum.decomposition ℳ`: A typeclass to provide a constructive decomposition from
an additive monoid `M` into a family of additive submonoids `ℳ`
* `direct_sum.decompose ℳ`: The canonical equivalence provided by the above typeclass
## Main statements
* `direct_sum.decomposition.is_internal`: The link to `direct_sum.is_internal`.
## Implementation details
As we want to talk about different types of decomposition (additive monoids, modules, rings, ...),
we choose to avoid heavily bundling `direct_sum.decompose`, instead making copies for the
`add_equiv`, `linear_equiv`, etc. This means we have to repeat statements that follow from these
bundled homs, but means we don't have to repeat statements for different types of decomposition.
-/
variables {ι R M σ : Type*}
open_locale direct_sum big_operators
namespace direct_sum
section add_comm_monoid
variables [decidable_eq ι] [add_comm_monoid M]
variables [set_like σ M] [add_submonoid_class σ M] (ℳ : ι → σ)
/-- A decomposition is an equivalence between an additive monoid `M` and a direct sum of additive
submonoids `ℳ i` of that `M`, such that the "recomposition" is canonical. This definition also
works for additive groups and modules.
This is a version of `direct_sum.is_internal` which comes with a constructive inverse to the
canonical "recomposition" rather than just a proof that the "recomposition" is bijective. -/
class decomposition :=
(decompose' : M → ⨁ i, ℳ i)
(left_inv : function.left_inverse (direct_sum.coe_add_monoid_hom ℳ) decompose' )
(right_inv : function.right_inverse (direct_sum.coe_add_monoid_hom ℳ) decompose')
include M
/-- `direct_sum.decomposition` instances, while carrying data, are always equal. -/
instance : subsingleton (decomposition ℳ) :=
⟨λ x y, begin
cases x with x xl xr,
cases y with y yl yr,
congr',
exact function.left_inverse.eq_right_inverse xr yl,
end⟩
variables [decomposition ℳ]
protected lemma decomposition.is_internal : direct_sum.is_internal ℳ :=
⟨decomposition.right_inv.injective, decomposition.left_inv.surjective⟩
/-- If `M` is graded by `ι` with degree `i` component `ℳ i`, then it is isomorphic as
to a direct sum of components. This is the canonical spelling of the `decompose'` field. -/
def decompose : M ≃ ⨁ i, ℳ i :=
{ to_fun := decomposition.decompose',
inv_fun := direct_sum.coe_add_monoid_hom ℳ,
left_inv := decomposition.left_inv,
right_inv := decomposition.right_inv }
protected lemma decomposition.induction_on {p : M → Prop}
(h_zero : p 0) (h_homogeneous : ∀ {i} (m : ℳ i), p (m : M))
(h_add : ∀ (m m' : M), p m → p m' → p (m + m')) : ∀ m, p m :=
begin
let ℳ' : ι → add_submonoid M :=
λ i, (⟨ℳ i, λ _ _, add_mem_class.add_mem, zero_mem_class.zero_mem _⟩ : add_submonoid M),
haveI t : direct_sum.decomposition ℳ' :=
{ decompose' := direct_sum.decompose ℳ,
left_inv := λ _, (decompose ℳ).left_inv _,
right_inv := λ _, (decompose ℳ).right_inv _, },
have mem : ∀ m, m ∈ supr ℳ' :=
λ m, (direct_sum.is_internal.add_submonoid_supr_eq_top ℳ'
(decomposition.is_internal ℳ')).symm ▸ trivial,
exact λ m, add_submonoid.supr_induction ℳ' (mem m) (λ i m h, h_homogeneous ⟨m, h⟩) h_zero h_add,
end
@[simp] lemma decomposition.decompose'_eq : decomposition.decompose' = decompose ℳ := rfl
@[simp] lemma decompose_symm_of {i : ι} (x : ℳ i) :
(decompose ℳ).symm (direct_sum.of _ i x) = x :=
direct_sum.coe_add_monoid_hom_of ℳ _ _
@[simp] lemma decompose_coe {i : ι} (x : ℳ i) :
decompose ℳ (x : M) = direct_sum.of _ i x :=
by rw [←decompose_symm_of, equiv.apply_symm_apply]
lemma decompose_of_mem {x : M} {i : ι} (hx : x ∈ ℳ i) :
decompose ℳ x = direct_sum.of (λ i, ℳ i) i ⟨x, hx⟩ :=
decompose_coe _ ⟨x, hx⟩
lemma decompose_of_mem_same {x : M} {i : ι} (hx : x ∈ ℳ i) :
(decompose ℳ x i : M) = x :=
by rw [decompose_of_mem _ hx, direct_sum.of_eq_same, subtype.coe_mk]
lemma decompose_of_mem_ne {x : M} {i j : ι} (hx : x ∈ ℳ i) (hij : i ≠ j):
(decompose ℳ x j : M) = 0 :=
by rw [decompose_of_mem _ hx, direct_sum.of_eq_of_ne _ _ _ _ hij,
add_submonoid_class.coe_zero]
/-- If `M` is graded by `ι` with degree `i` component `ℳ i`, then it is isomorphic as
an additive monoid to a direct sum of components. -/
@[simps {fully_applied := ff}]
def decompose_add_equiv : M ≃+ ⨁ i, ℳ i := add_equiv.symm
{ map_add' := map_add (direct_sum.coe_add_monoid_hom ℳ),
..(decompose ℳ).symm }
@[simp] lemma decompose_zero : decompose ℳ (0 : M) = 0 := map_zero (decompose_add_equiv ℳ)
@[simp] lemma decompose_symm_zero : (decompose ℳ).symm 0 = (0 : M) :=
map_zero (decompose_add_equiv ℳ).symm
@[simp] lemma decompose_add (x y : M) : decompose ℳ (x + y) = decompose ℳ x + decompose ℳ y :=
map_add (decompose_add_equiv ℳ) x y
@[simp] lemma decompose_symm_add (x y : ⨁ i, ℳ i) :
(decompose ℳ).symm (x + y) = (decompose ℳ).symm x + (decompose ℳ).symm y :=
map_add (decompose_add_equiv ℳ).symm x y
@[simp] lemma decompose_sum {ι'} (s : finset ι') (f : ι' → M) :
decompose ℳ (∑ i in s, f i) = ∑ i in s, decompose ℳ (f i) :=
map_sum (decompose_add_equiv ℳ) f s
@[simp] lemma decompose_symm_sum {ι'} (s : finset ι') (f : ι' → ⨁ i, ℳ i) :
(decompose ℳ).symm (∑ i in s, f i) = ∑ i in s, (decompose ℳ).symm (f i) :=
map_sum (decompose_add_equiv ℳ).symm f s
lemma sum_support_decompose [Π i (x : ℳ i), decidable (x ≠ 0)] (r : M) :
∑ i in (decompose ℳ r).support, (decompose ℳ r i : M) = r :=
begin
conv_rhs { rw [←(decompose ℳ).symm_apply_apply r,
←sum_support_of (λ i, (ℳ i)) (decompose ℳ r)] },
rw [decompose_symm_sum],
simp_rw decompose_symm_of,
end
end add_comm_monoid
/-- The `-` in the statements below doesn't resolve without this line.
This seems to a be a problem of synthesized vs inferred typeclasses disagreeing. If we replace
the statement of `decompose_neg` with `@eq (⨁ i, ℳ i) (decompose ℳ (-x)) (-decompose ℳ x)`
instead of `decompose ℳ (-x) = -decompose ℳ x`, which forces the typeclasses needed by `⨁ i, ℳ i` to
be found by unification rather than synthesis, then everything works fine without this instance. -/
instance add_comm_group_set_like [add_comm_group M] [set_like σ M] [add_subgroup_class σ M]
(ℳ : ι → σ) : add_comm_group (⨁ i, ℳ i) := by apply_instance
section add_comm_group
variables [decidable_eq ι] [add_comm_group M]
variables [set_like σ M] [add_subgroup_class σ M] (ℳ : ι → σ)
variables [decomposition ℳ]
include M
@[simp] lemma decompose_neg (x : M) : decompose ℳ (-x) = -decompose ℳ x :=
map_neg (decompose_add_equiv ℳ) x
@[simp] lemma decompose_symm_neg (x : ⨁ i, ℳ i) :
(decompose ℳ).symm (-x) = -(decompose ℳ).symm x :=
map_neg (decompose_add_equiv ℳ).symm x
@[simp] lemma decompose_sub (x y : M) : decompose ℳ (x - y) = decompose ℳ x - decompose ℳ y :=
map_sub (decompose_add_equiv ℳ) x y
@[simp] lemma decompose_symm_sub (x y : ⨁ i, ℳ i) :
(decompose ℳ).symm (x - y) = (decompose ℳ).symm x - (decompose ℳ).symm y :=
map_sub (decompose_add_equiv ℳ).symm x y
end add_comm_group
section module
variables [decidable_eq ι] [semiring R] [add_comm_monoid M] [module R M]
variables (ℳ : ι → submodule R M)
variables [decomposition ℳ]
include M
/-- If `M` is graded by `ι` with degree `i` component `ℳ i`, then it is isomorphic as
a module to a direct sum of components. -/
@[simps {fully_applied := ff}]
def decompose_linear_equiv : M ≃ₗ[R] ⨁ i, ℳ i := linear_equiv.symm
{ map_smul' := map_smul (direct_sum.coe_linear_map ℳ),
..(decompose_add_equiv ℳ).symm }
@[simp] lemma decompose_smul (r : R) (x : M) : decompose ℳ (r • x) = r • decompose ℳ x :=
map_smul (decompose_linear_equiv ℳ) r x
end module
end direct_sum
|
b4e2cd720b0ae3df17d130f3c080c6ec97fcaa09 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/category/Module/epi_mono.lean | 2a793833675e0811c1efaba4bfe9045eff5bc5ff | [
"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,720 | lean | /-
Copyright (c) 2021 Scott Morrison All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.category.Module.adjunctions
import category_theory.epi_mono
/-!
# Monomorphisms in `Module R`
This file shows that an `R`-linear map is a monomorphism in the category of `R`-modules
if and only if it is injective, and similarly an epimorphism if and only if it is surjective.
-/
universes v u
open category_theory
open Module
open_locale Module
namespace Module
variables {R : Type u} [ring R] {X Y : Module.{v} R} (f : X ⟶ Y)
lemma ker_eq_bot_of_mono [mono f] : f.ker = ⊥ :=
linear_map.ker_eq_bot_of_cancel $ λ u v, (@cancel_mono _ _ _ _ _ f _ ↟u ↟v).1
lemma range_eq_top_of_epi [epi f] : f.range = ⊤ :=
linear_map.range_eq_top_of_cancel $ λ u v, (@cancel_epi _ _ _ _ _ f _ ↟u ↟v).1
lemma mono_iff_ker_eq_bot : mono f ↔ f.ker = ⊥ :=
⟨λ hf, by exactI ker_eq_bot_of_mono _,
λ hf, concrete_category.mono_of_injective _ $ linear_map.ker_eq_bot.1 hf⟩
lemma mono_iff_injective : mono f ↔ function.injective f :=
by rw [mono_iff_ker_eq_bot, linear_map.ker_eq_bot]
lemma epi_iff_range_eq_top : epi f ↔ f.range = ⊤ :=
⟨λ hf, by exactI range_eq_top_of_epi _,
λ hf, concrete_category.epi_of_surjective _ $ linear_map.range_eq_top.1 hf⟩
lemma epi_iff_surjective : epi f ↔ function.surjective f :=
by rw [epi_iff_range_eq_top, linear_map.range_eq_top]
instance mono_as_hom'_subtype (U : submodule R X) : mono ↾U.subtype :=
(mono_iff_ker_eq_bot _).mpr (submodule.ker_subtype U)
instance epi_as_hom''_mkq (U : submodule R X) : epi ↿U.mkq :=
(epi_iff_range_eq_top _).mpr $ submodule.range_mkq _
end Module
|
25e56d9547fec5fa2a0e76368e16b3de1b2ac036 | 56e5b79a7ab4f2c52e6eb94f76d8100a25273cf3 | /src/backends/bfs/openai.lean | a03d4913b3c573f0863025d23d5a25f8145e319d | [
"Apache-2.0"
] | permissive | DyeKuu/lean-tpe-public | 3a9968f286ca182723ef7e7d97e155d8cb6b1e70 | 750ade767ab28037e80b7a80360d213a875038f8 | refs/heads/master | 1,682,842,633,115 | 1,621,330,793,000 | 1,621,330,793,000 | 368,475,816 | 0 | 0 | Apache-2.0 | 1,621,330,745,000 | 1,621,330,744,000 | null | UTF-8 | Lean | false | false | 11,048 | lean | import evaluation
import utils
-- TODO(jesse): code duplication >:(
namespace openai
section openai_api
meta structure CompletionRequest : Type :=
(prompt : string)
(max_tokens : int := 16)
(temperature : native.float := 1.0)
(top_p : native.float := 1)
(n : int := 1)
(best_of : option int := none)
(stream : option bool := none)
(logprobs : int := 0)
(echo : option bool := none)
(stop : option string := none) -- TODO(jesse): list string
(presence_penalty : option native.float := none)
(frequency_penalty : option native.float := none)
(show_trace : bool := ff)
(prompt_token := "PROOFSTEP")
-- don't support logit_bias for now
-- TODO(jesse): write a derive handler for this kind of structure serialization
/-- this is responsible for validating parameters,
e.g. ensuring floats are between 0 and 1 -/
meta instance : has_to_tactic_json CompletionRequest :=
let validate_max_tokens : int → bool := λ n, n ≤ 2048 in
let validate_float_frac : native.float → bool := λ k, 0 ≤ k ∧ k ≤ 1 in
let validate_and_return {α} [has_to_format α] (pred : α → bool) : α → tactic α :=
λ a, ((guard $ pred a) *> pure a <|> by {tactic.unfreeze_local_instances, exact (tactic.fail format!"[openai.CompletionRequest.to_tactic_json] VALIDATION FAILED FOR {a}")}) in
let validate_optional_and_return {α} [has_to_format α] (pred : α → bool) : option α → tactic (option α) := λ x, do {
match x with
| (some val) := some <$> by {tactic.unfreeze_local_instances, exact (validate_and_return pred val)}
| none := pure none
end
} in
let MAX_N : int := 100000 in
let fn : CompletionRequest → tactic json := λ req, match req with
| ⟨prompt, max_tokens, temperature, top_p, n, best_of,
stream, logprobs, echo, stop, presence_penalty, frequency_penalty, _, _⟩ := do
-- TODO(jesse): ensure validation does not fail silently
max_tokens ← validate_and_return validate_max_tokens max_tokens,
-- temperature ← validate_and_return validate_float_frac temperature,
top_p ← validate_and_return validate_float_frac top_p,
n ← validate_and_return (λ x, 0 ≤ x ∧ x ≤ MAX_N) /- go wild with the candidates -/ n,
best_of ← validate_optional_and_return (λ x, n ≤ x ∧ x ≤ MAX_N) best_of,
presence_penalty ← validate_optional_and_return validate_float_frac presence_penalty,
frequency_penalty ← validate_optional_and_return validate_float_frac frequency_penalty,
eval_trace $ "[openai.CompletionRequest.to_tactic_json] VALIDATION PASSED",
let pre_kvs : list (string × option json) := [
("prompt", json.of_string prompt),
("max_tokens", json.of_int max_tokens),
("temperature", json.of_float temperature),
("top_p", json.of_float top_p),
("n", json.of_int n),
("best_of", json.of_int <$> best_of),
("stream", json.of_bool <$> stream),
("logprobs", some $ json.of_int logprobs),
("echo", json.of_bool <$> echo),
("stop", json.of_string <$> stop),
("presence_penalty", json.of_float <$> presence_penalty),
("frequency_penalty", json.of_float <$> frequency_penalty)
],
pure $ json.object $ pre_kvs.filter_map (λ ⟨k,mv⟩, prod.mk k <$> mv)
end
in ⟨fn⟩
/-
example from API docs:
curl https://api.openai.com/v1/engines/davinci/completions \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $OPENAI_API_KEY' \
-d '{
"prompt": "Once upon a time",
"max_tokens": 5
}'
-/
meta def dummy_cr : CompletionRequest :=
{prompt := "Once upon a time", max_tokens := 5, temperature := 1.0, top_p := 1.0, n := 3}
meta def CompletionRequest.to_cmd (engine_id : string) (api_key : string) : CompletionRequest → io (io.process.spawn_args)
| req@⟨prompt, max_tokens, temperature, top_p, n, best_of,
stream, logprobs, echo, stop, presence_penalty, frequency_penalty, _, _⟩ := do
when EVAL_TRACE $ io.put_str_ln' format!"[openai.CompletionRequest.to_cmd] ENTERING",
serialized_req ← io.run_tactic' $ has_to_tactic_json.to_tactic_json req,
when EVAL_TRACE $ io.put_str_ln' format!"[openai.CompletionRequest.to_cmd] SERIALIZED",
pure {
cmd := "curl",
args := [
"-u"
, format.to_string $ format!":{api_key}"
, "-X"
, "POST"
-- , format.to_string format!"http://router.api.svc.owl.sci.openai.org:5004/v1/engines/{engine_id}/completions"
, format.to_string format!"https://api.openai.com/v1/engines/{engine_id}/completions"
, "-H", "OpenAI-Organization: org-kuQ09yewcuHU5GN5YYEUp2hh"
, "-H", "Content-Type: application/json"
, "-d"
, json.unparse serialized_req
]
}
setup_tactic_parser
-- nice, it works
-- example {p q} (h₁ : p) (h₂ : q) : p ∧ q :=
-- begin
-- apply and.intro, do {tactic.read >>= postprocess_tactic_state >>= eval_trace}
-- end
meta def serialize_ts
(req : CompletionRequest)
: tactic_state → tactic CompletionRequest := λ ts, do {
ts_str ← ts.fully_qualified >>= postprocess_tactic_state,
let prompt : string :=
"[LN] GOAL " ++ ts_str ++ (format! " {req.prompt_token} ").to_string,
eval_trace format!"\n \n \n PROMPT: {prompt} \n \n \n ",
pure {
prompt := prompt,
..req}
}
setup_tactic_parser
private meta def decode_response_msg : json → io (json × json) := λ response_msg, do {
(json.array choices) ← lift_option $ response_msg.lookup "choices" | io.fail' format!"can't find choices in {response_msg}",
prod.mk <$> (json.array <$> choices.mmap (λ choice, lift_option $ json.lookup choice "text")) <*> do {
logprobss ← choices.mmap (λ msg, lift_option $ msg.lookup "logprobs"),
scoress ← logprobss.mmap (λ logprobs, lift_option $ logprobs.lookup "token_logprobs"),
result ← json.array <$> scoress.mmap (lift_option ∘ json_float_array_sum),
pure result
}
}
meta def openai_api (engine_id : string) (api_key : string) : ModelAPI CompletionRequest :=
let fn : CompletionRequest → io json := λ req, do {
proc_cmds ← req.to_cmd engine_id api_key,
-- when req.show_trace $ io.put_str_ln' format!"[openai_api] PROC_CMDS: {proc_cmds}",
response_raw ← io.cmd proc_cmds,
when req.show_trace $ io.put_str_ln' format!"[openai_api] RAW RESPONSE: {response_raw}",
response_msg ← (lift_option $ json.parse response_raw) | io.fail' format!"[openai_api] JSON PARSE FAILED {response_raw}",
when req.show_trace $ io.put_str_ln' format!"GOT RESPONSE_MSG",
-- predictions ← (lift_option $ do {
-- (json.array choices) ← response_msg.lookup "choices" | none,
-- /- `choices` is a list of {text: ..., index: ..., logprobs: ..., finish_reason: ...}-/
-- texts ← choices.mmap (λ choice, choice.lookup "text"),
-- (scoress : list json) ← choices.mmap (λ msg, msg.lookup "logprobs" >>= λ x, x.lookup "token_logprobs"),
-- -- scores ← scoress.mmap (λ xs, xs.map (λ msg,
-- scores ← scoress.mmap json_float_array_sum,
-- pure $ prod.mk texts scores
-- })
do {
predictions ← decode_response_msg response_msg | io.fail' format!"[openai_api] UNEXPECTED RESPONSE MSG: {response_msg}",
when req.show_trace $ io.put_str_ln' format!"PREDICTIONS: {predictions}",
pure (json.array [predictions.fst, predictions.snd])
} <|> pure (json.array $ [json.of_string $ format.to_string $ format!"ERROR {response_msg}"]) -- catch API errors here
} in ⟨fn⟩
end openai_api
section openai_proof_search
meta def read_first_line : string → io string := λ path, do
buffer.to_string <$> (io.mk_file_handle path io.mode.read >>= io.fs.get_line)
-- in entry point, API key is read from command line and then set as an environment variable for the execution
-- of the command
@[inline, reducible]meta def tab : char := '\t'
@[inline, reducible]meta def newline : char := '\n'
meta def default_partial_req : openai.CompletionRequest :=
{
prompt := "",
max_tokens := 128,
temperature := (0.7 : native.float),
top_p := 1,
n := 1,
best_of := none,
stream := none,
logprobs := 0,
echo := none,
stop := none, -- TODO(jesse): list string,
presence_penalty := none,
frequency_penalty := none,
show_trace := EVAL_TRACE
}
/- this is the entry point for the evalution harness -/
meta def openai_bfs_proof_search_core
(partial_req : openai.CompletionRequest)
(engine_id : string)
(api_key : string)
(fuel := 5)
: state_t BFSState tactic unit := do
monad_lift $ set_show_eval_trace partial_req.show_trace,
bfs_core
(openai_api engine_id api_key)
(openai.serialize_ts partial_req)
(λ msg n, run_all_beam_candidates (unwrap_lm_response_logprobs $ some "[openai_greedy_proof_search_core]") msg n)
(fuel)
/- for testing API failure handling.
replace `openai.openai_bfs_proof_search_core` with
`openai.dummy_openai_bfs_proof_search_core` in
`evaluation/bfs/gptf.lean` and confirm that the
produced `.json` files show `api_failures = 1`
-/
meta def dummy_openai_bfs_proof_search_core
(partial_req : openai.CompletionRequest)
(engine_id : string)
(api_key : string)
(fuel := 5)
: state_t BFSState tactic unit := do
monad_lift $ set_show_eval_trace partial_req.show_trace,
bfs_core
dummy_api
(openai.serialize_ts partial_req)
(λ msg n, run_all_beam_candidates (unwrap_lm_response_logprobs $ some "[openai_greedy_proof_search_core]") msg n)
(fuel)
/- meant for interactive use -/
meta def openai_bfs_proof_search
(partial_req : openai.CompletionRequest)
(engine_id : string)
(api_key : string)
(fuel := 5)
(verbose := ff)
(max_width : ℕ := 25)
(max_depth : ℕ := 50)
: tactic unit := do
set_show_eval_trace partial_req.show_trace,
bfs
(openai_api engine_id api_key)
(openai.serialize_ts partial_req)
(λ msg n, run_all_beam_candidates (unwrap_lm_response_logprobs $ some "[openai_greedy_proof_search]") msg n)
(fuel) (verbose) (max_width) (max_depth)
end openai_proof_search
section playground
example : true :=
begin
trivial
-- openai_bfs_proof_search default_partial_req "formal-large-lean-webmath-1230-v1-c4" API_KEY
end
-- example : true :=
-- begin
-- openai_greedy_proof_search
-- default_partial_req
-- "formal-large-lean-webmath-1230-v1-c4"
-- API_KEY
-- end
-- example (n : ℕ) (m : ℕ) : nat.succ (n + m) < (nat.succ n + m) + 1 :=
-- begin
-- -- openai_greedy_proof_search
-- -- {n := 10, temperature := 0.7, ..default_partial_req}
-- -- "formal-large-lean-webmath-1230-v1-c4"
-- -- API_KEY 10 tt,
-- sorry
-- -- rw succ_add, exact nat.lt_succ_self _
-- end
-- theorem t2 (p q r : Prop) (h₁ : p) (h₂ : q) : (q ∧ p) ∨ r :=
-- lemma peirce_identity {P Q :Prop} : ((P → Q) → P) → P :=
-- begin
-- openai_greedy_proof_search
-- {n := 25, temperature := 0.7, ..default_partial_req}
-- "formal-large-lean-webmath-1230-v1-c4"
-- API_KEY 10,
-- end
-- -- openai_greedy_proof_search
-- -- default_partial_req
-- -- "formal-large-lean-webmath-1230-v1-c4"
-- -- API_KEY
-- -- -- simp [or_assoc, or_comm, or_left_comm]
-- end
end playground
end openai
|
11ae5237a59115c9c65594fe04ecab70a4274ba8 | c86b74188c4b7a462728b1abd659ab4e5828dd61 | /stage0/src/Std/Data/HashSet.lean | 875816169ecea4872163d4d8e78e2a6921e17800 | [
"Apache-2.0"
] | permissive | cwb96/lean4 | 75e1f92f1ba98bbaa6b34da644b3dfab2ce7bf89 | b48831cda76e64f13dd1c0edde7ba5fb172ed57a | refs/heads/master | 1,686,347,881,407 | 1,624,483,842,000 | 1,624,483,842,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,119 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
namespace Std
universes u v w
def HashSetBucket (α : Type u) :=
{ b : Array (List α) // b.size > 0 }
def HashSetBucket.update {α : Type u} (data : HashSetBucket α) (i : USize) (d : List α) (h : i.toNat < data.val.size) : HashSetBucket α :=
⟨ data.val.uset i d h,
by erw [Array.size_set]; exact data.property ⟩
structure HashSetImp (α : Type u) where
size : Nat
buckets : HashSetBucket α
def mkHashSetImp {α : Type u} (nbuckets := 8) : HashSetImp α :=
let n := if nbuckets = 0 then 8 else nbuckets
{ size := 0,
buckets :=
⟨ mkArray n [],
by rw [Array.size_mkArray]; cases nbuckets; decide; apply Nat.zeroLtSucc ⟩ }
namespace HashSetImp
variable {α : Type u}
def mkIdx {n : Nat} (h : n > 0) (u : USize) : { u : USize // u.toNat < n } :=
⟨u % n, USize.modn_lt _ h⟩
@[inline] def reinsertAux (hashFn : α → UInt64) (data : HashSetBucket α) (a : α) : HashSetBucket α :=
let ⟨i, h⟩ := mkIdx data.property (hashFn a |>.toUSize)
data.update i (a :: data.val.uget i h) h
@[inline] def foldBucketsM {δ : Type w} {m : Type w → Type w} [Monad m] (data : HashSetBucket α) (d : δ) (f : δ → α → m δ) : m δ :=
data.val.foldlM (init := d) fun d as => as.foldlM f d
@[inline] def foldBuckets {δ : Type w} (data : HashSetBucket α) (d : δ) (f : δ → α → δ) : δ :=
Id.run $ foldBucketsM data d f
@[inline] def foldM {δ : Type w} {m : Type w → Type w} [Monad m] (f : δ → α → m δ) (d : δ) (h : HashSetImp α) : m δ :=
foldBucketsM h.buckets d f
@[inline] def fold {δ : Type w} (f : δ → α → δ) (d : δ) (m : HashSetImp α) : δ :=
foldBuckets m.buckets d f
def find? [BEq α] [Hashable α] (m : HashSetImp α) (a : α) : Option α :=
match m with
| ⟨_, buckets⟩ =>
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
(buckets.val.uget i h).find? (fun a' => a == a')
def contains [BEq α] [Hashable α] (m : HashSetImp α) (a : α) : Bool :=
match m with
| ⟨_, buckets⟩ =>
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
(buckets.val.uget i h).contains a
-- TODO: remove `partial` by using well-founded recursion
partial def moveEntries [Hashable α] (i : Nat) (source : Array (List α)) (target : HashSetBucket α) : HashSetBucket α :=
if h : i < source.size then
let idx : Fin source.size := ⟨i, h⟩
let es : List α := source.get idx
-- We remove `es` from `source` to make sure we can reuse its memory cells when performing es.foldl
let source := source.set idx []
let target := es.foldl (reinsertAux hash) target
moveEntries (i+1) source target
else target
def expand [Hashable α] (size : Nat) (buckets : HashSetBucket α) : HashSetImp α :=
let nbuckets := buckets.val.size * 2
have : nbuckets > 0 := Nat.mulPos buckets.property (by decide)
let new_buckets : HashSetBucket α := ⟨mkArray nbuckets [], by rw [Array.size_mkArray]; assumption⟩
{ size := size,
buckets := moveEntries 0 buckets.val new_buckets }
def insert [BEq α] [Hashable α] (m : HashSetImp α) (a : α) : HashSetImp α :=
match m with
| ⟨size, buckets⟩ =>
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
let bkt := buckets.val.uget i h
if bkt.contains a
then ⟨size, buckets.update i (bkt.replace a a) h⟩
else
let size' := size + 1
let buckets' := buckets.update i (a :: bkt) h
if size' ≤ buckets.val.size
then { size := size', buckets := buckets' }
else expand size' buckets'
def erase [BEq α] [Hashable α] (m : HashSetImp α) (a : α) : HashSetImp α :=
match m with
| ⟨ size, buckets ⟩ =>
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
let bkt := buckets.val.uget i h
if bkt.contains a then ⟨size - 1, buckets.update i (bkt.erase a) h⟩
else m
inductive WellFormed [BEq α] [Hashable α] : HashSetImp α → Prop where
| mkWff : ∀ n, WellFormed (mkHashSetImp n)
| insertWff : ∀ m a, WellFormed m → WellFormed (insert m a)
| eraseWff : ∀ m a, WellFormed m → WellFormed (erase m a)
end HashSetImp
def HashSet (α : Type u) [BEq α] [Hashable α] :=
{ m : HashSetImp α // m.WellFormed }
open HashSetImp
def mkHashSet {α : Type u} [BEq α] [Hashable α] (nbuckets := 8) : HashSet α :=
⟨ mkHashSetImp nbuckets, WellFormed.mkWff nbuckets ⟩
namespace HashSet
variable {α : Type u} [BEq α] [Hashable α]
instance : Inhabited (HashSet α) where
default := mkHashSet
instance : EmptyCollection (HashSet α) := ⟨mkHashSet⟩
@[inline] def insert (m : HashSet α) (a : α) : HashSet α :=
match m with
| ⟨ m, hw ⟩ => ⟨ m.insert a, WellFormed.insertWff m a hw ⟩
@[inline] def erase (m : HashSet α) (a : α) : HashSet α :=
match m with
| ⟨ m, hw ⟩ => ⟨ m.erase a, WellFormed.eraseWff m a hw ⟩
@[inline] def find? (m : HashSet α) (a : α) : Option α :=
match m with
| ⟨ m, _ ⟩ => m.find? a
@[inline] def contains (m : HashSet α) (a : α) : Bool :=
match m with
| ⟨ m, _ ⟩ => m.contains a
@[inline] def foldM {δ : Type w} {m : Type w → Type w} [Monad m] (f : δ → α → m δ) (init : δ) (h : HashSet α) : m δ :=
match h with
| ⟨ h, _ ⟩ => h.foldM f init
@[inline] def fold {δ : Type w} (f : δ → α → δ) (init : δ) (m : HashSet α) : δ :=
match m with
| ⟨ m, _ ⟩ => m.fold f init
@[inline] def size (m : HashSet α) : Nat :=
match m with
| ⟨ {size := sz, ..}, _ ⟩ => sz
@[inline] def isEmpty (m : HashSet α) : Bool :=
m.size = 0
@[inline] def empty : HashSet α :=
mkHashSet
def toList (m : HashSet α) : List α :=
m.fold (init := []) fun r a => a::r
def toArray (m : HashSet α) : Array α :=
m.fold (init := #[]) fun r a => r.push a
def numBuckets (m : HashSet α) : Nat :=
m.val.buckets.val.size
end HashSet
end Std
|
a3dc823a64e1bd894780a66939806645913bc72f | 8cb37a089cdb4af3af9d8bf1002b417e407a8e9e | /tests/lean/run/simp_tc_err.lean | 41c1932796dfed4abfdaef1aa0e733e95c7dd5a2 | [
"Apache-2.0"
] | permissive | kbuzzard/lean | ae3c3db4bb462d750dbf7419b28bafb3ec983ef7 | ed1788fd674bb8991acffc8fca585ec746711928 | refs/heads/master | 1,620,983,366,617 | 1,618,937,600,000 | 1,618,937,600,000 | 359,886,396 | 1 | 0 | Apache-2.0 | 1,618,936,987,000 | 1,618,936,987,000 | null | UTF-8 | Lean | false | false | 507 | lean | def c : ℕ := default _
def d : ℕ := default _
local attribute [simp] nat.add_zero
class foo (α : Type)
-- type class resolution for [foo α] will always time out
instance foo.foo {α} [foo α] : foo α := ‹foo α›
-- would break simp on any term containing c
@[simp] lemma c_eq_d [foo ℕ] : c = d := by refl
set_option trace.simplify.rewrite true
example : c = d + 0 :=
begin
-- shouldn't fail, even though type class resolution for c_eq_d times out
simp,
guard_target c = d,
refl,
end |
58a012990721e75415bcde04fa76232b09f8dc5b | 626e312b5c1cb2d88fca108f5933076012633192 | /src/field_theory/separable.lean | 0bc6f2e9738b94dc05f7d1f9988147f5e6e16847 | [
"Apache-2.0"
] | permissive | Bioye97/mathlib | 9db2f9ee54418d29dd06996279ba9dc874fd6beb | 782a20a27ee83b523f801ff34efb1a9557085019 | refs/heads/master | 1,690,305,956,488 | 1,631,067,774,000 | 1,631,067,774,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,115 | 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.polynomial.big_operators
import field_theory.minpoly
import field_theory.splitting_field
import field_theory.tower
import algebra.squarefree
/-!
# 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ⁿ`.
-/
universes u v w
open_locale classical big_operators
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 : polynomial R) : Prop :=
is_coprime f f.derivative
lemma separable_def (f : polynomial R) :
f.separable ↔ is_coprime f f.derivative :=
iff.rfl
lemma separable_def' (f : polynomial R) :
f.separable ↔ ∃ a b : polynomial R, a * f + b * f.derivative = 1 :=
iff.rfl
lemma not_separable_zero [nontrivial R] : ¬ separable (0 : polynomial R) :=
begin
rintro ⟨x, y, h⟩,
simpa only [derivative_zero, mul_zero, add_zero, zero_ne_one] using h,
end
lemma separable_one : (1 : polynomial R).separable :=
is_coprime_one_left
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 : polynomial R).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 : polynomial R} (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 : polynomial R} (h : (f * g).separable) : g.separable :=
by { rw mul_comm at h, exact h.of_mul_left }
lemma separable.of_dvd {f g : polynomial R} (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 : polynomial F}
(hf : f.separable) (g : polynomial F) : (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 : polynomial F}
(f : polynomial F) (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 : polynomial R} (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 : polynomial R} :
∀ {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 : polynomial R} (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 : polynomial R} (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, ← map_mul, ← map_mul, ← map_add, H, map_one]⟩
variables (R) (p q : ℕ)
/-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. -/
noncomputable def expand : polynomial R →ₐ[R] polynomial R :=
{ commutes' := λ r, eval₂_C _ _,
.. (eval₂_ring_hom C (X ^ p) : polynomial R →+* polynomial R) }
lemma coe_expand : (expand R p : polynomial R → polynomial R) = eval₂ C (X ^ p) := rfl
variables {R}
lemma expand_eq_sum {f : polynomial R} :
expand R p f = f.sum (λ e a, C a * (X ^ p) ^ e) :=
by { dsimp [expand, eval₂], refl, }
@[simp] lemma expand_C (r : R) : expand R p (C r) = C r := eval₂_C _ _
@[simp] lemma expand_X : expand R p X = X ^ p := eval₂_X _ _
@[simp] lemma expand_monomial (r : R) : expand R p (monomial q r) = monomial (q * p) r :=
by simp_rw [monomial_eq_smul_X, alg_hom.map_smul, alg_hom.map_pow, expand_X, mul_comm, pow_mul]
theorem expand_expand (f : polynomial R) : expand R p (expand R q f) = expand R (p * q) f :=
polynomial.induction_on f (λ r, by simp_rw expand_C)
(λ f g ihf ihg, by simp_rw [alg_hom.map_add, ihf, ihg])
(λ n r ih, by simp_rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X,
alg_hom.map_pow, expand_X, pow_mul])
theorem expand_mul (f : polynomial R) : expand R (p * q) f = expand R p (expand R q f) :=
(expand_expand p q f).symm
@[simp] theorem expand_one (f : polynomial R) : expand R 1 f = f :=
polynomial.induction_on f
(λ r, by rw expand_C)
(λ f g ihf ihg, by rw [alg_hom.map_add, ihf, ihg])
(λ n r ih, by rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X, pow_one])
theorem expand_pow (f : polynomial R) : expand R (p ^ q) f = (expand R p ^[q] f) :=
nat.rec_on q (by rw [pow_zero, expand_one, function.iterate_zero, id]) $ λ n ih,
by rw [function.iterate_succ_apply', pow_succ, expand_mul, ih]
theorem derivative_expand (f : polynomial R) :
(expand R p f).derivative = expand R p f.derivative * (p * X ^ (p - 1)) :=
by rw [coe_expand, derivative_eval₂_C, derivative_pow, derivative_X, mul_one]
theorem coeff_expand {p : ℕ} (hp : 0 < p) (f : polynomial R) (n : ℕ) :
(expand R p f).coeff n = if p ∣ n then f.coeff (n / p) else 0 :=
begin
simp only [expand_eq_sum],
simp_rw [coeff_sum, ← pow_mul, C_mul_X_pow_eq_monomial, coeff_monomial, sum],
split_ifs with h,
{ rw [finset.sum_eq_single (n/p), nat.mul_div_cancel' h, if_pos rfl],
{ intros b hb1 hb2, rw if_neg, intro hb3, apply hb2, rw [← hb3, nat.mul_div_cancel_left b hp] },
{ intro hn, rw not_mem_support_iff.1 hn, split_ifs; refl } },
{ rw finset.sum_eq_zero, intros k hk, rw if_neg, exact λ hkn, h ⟨k, hkn.symm⟩, },
end
@[simp] theorem coeff_expand_mul {p : ℕ} (hp : 0 < p) (f : polynomial R) (n : ℕ) :
(expand R p f).coeff (n * p) = f.coeff n :=
by rw [coeff_expand hp, if_pos (dvd_mul_left _ _), nat.mul_div_cancel _ hp]
@[simp] theorem coeff_expand_mul' {p : ℕ} (hp : 0 < p) (f : polynomial R) (n : ℕ) :
(expand R p f).coeff (p * n) = f.coeff n :=
by rw [mul_comm, coeff_expand_mul hp]
theorem expand_inj {p : ℕ} (hp : 0 < p) {f g : polynomial R} :
expand R p f = expand R p g ↔ f = g :=
⟨λ H, ext $ λ n, by rw [← coeff_expand_mul hp, H, coeff_expand_mul hp], congr_arg _⟩
theorem expand_eq_zero {p : ℕ} (hp : 0 < p) {f : polynomial R} : expand R p f = 0 ↔ f = 0 :=
by rw [← (expand R p).map_zero, expand_inj hp, alg_hom.map_zero]
theorem expand_eq_C {p : ℕ} (hp : 0 < p) {f : polynomial R} {r : R} :
expand R p f = C r ↔ f = C r :=
by rw [← expand_C, expand_inj hp, expand_C]
theorem nat_degree_expand (p : ℕ) (f : polynomial R) :
(expand R p f).nat_degree = f.nat_degree * p :=
begin
cases p.eq_zero_or_pos with hp hp,
{ rw [hp, coe_expand, pow_zero, mul_zero, ← C_1, eval₂_hom, nat_degree_C] },
by_cases hf : f = 0,
{ rw [hf, alg_hom.map_zero, nat_degree_zero, zero_mul] },
have hf1 : expand R p f ≠ 0 := mt (expand_eq_zero hp).1 hf,
rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree hf1],
refine le_antisymm ((degree_le_iff_coeff_zero _ _).2 $ λ n hn, _) _,
{ rw coeff_expand hp, split_ifs with hpn,
{ rw coeff_eq_zero_of_nat_degree_lt, contrapose! hn,
rw [with_bot.coe_le_coe, ← nat.div_mul_cancel hpn], exact nat.mul_le_mul_right p hn },
{ refl } },
{ refine le_degree_of_ne_zero _,
rw [coeff_expand_mul hp, ← leading_coeff], exact mt leading_coeff_eq_zero.1 hf }
end
theorem map_expand {p : ℕ} (hp : 0 < p) {f : R →+* S} {q : polynomial R} :
map f (expand R p q) = expand S p (map f q) :=
by { ext, rw [coeff_map, coeff_expand hp, coeff_expand hp], split_ifs; simp, }
/-- Expansion is injective. -/
lemma expand_injective {n : ℕ} (hn : 0 < n) :
function.injective (expand R n) :=
λ g g' h, begin
ext,
have h' : (expand R n g).coeff (n * n_1) = (expand R n g').coeff (n * n_1) :=
begin
apply polynomial.ext_iff.1,
exact h,
end,
rw [polynomial.coeff_expand hn g (n * n_1), polynomial.coeff_expand hn g' (n * n_1)] at h',
simp only [if_true, dvd_mul_right] at h',
rw (nat.mul_div_right n_1 hn) at h',
exact h',
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 : polynomial R} (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 : ι → polynomial R} {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 : ι → polynomial R}
(h1 : pairwise (is_coprime on f)) (h2 : ∀ x, (f x).separable) : (∏ x, f x).separable :=
separable_prod' (λ x hx y hy hxy, h1 x y 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 is_unit_of_self_mul_dvd_separable {p q : polynomial R}
(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
end comm_ring
section integral_domain
variables (R : Type u) [integral_domain R]
theorem is_local_ring_hom_expand {p : ℕ} (hp : 0 < p) :
is_local_ring_hom (↑(expand R p) : polynomial R →+* polynomial R) :=
begin
refine ⟨λ f hf1, _⟩, rw ← coe_fn_coe_base at hf1,
have hf2 := eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit hf1),
rw [coeff_expand hp, if_pos (dvd_zero _), p.zero_div] at hf2,
rw [hf2, is_unit_C] at hf1, rw expand_eq_C hp at hf2, rwa [hf2, is_unit_C]
end
end integral_domain
section field
variables {F : Type u} [field F] {K : Type v} [field K]
theorem separable_iff_derivative_ne_zero {f : polynomial F} (hf : irreducible f) :
f.separable ↔ f.derivative ≠ 0 :=
⟨λ h1 h2, hf.not_unit $ is_coprime_zero_right.1 $ h2 ▸ h1,
λ h, 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 h⟩
theorem separable_map (f : F →+* K) {p : polynomial F} : (p.map f).separable ↔ p.separable :=
by simp_rw [separable_def, derivative_map, is_coprime_map]
section char_p
/-- The opposite of `expand`: sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`. -/
noncomputable def contract (p : ℕ) (f : polynomial F) : polynomial F :=
∑ n in range (f.nat_degree + 1), monomial n (f.coeff (n * p))
variables (p : ℕ) [hp : fact p.prime]
include hp
theorem coeff_contract (f : polynomial F) (n : ℕ) : (contract p f).coeff n = f.coeff (n * p) :=
begin
simp only [contract, coeff_monomial, sum_ite_eq', finset_sum_coeff, mem_range, not_lt,
ite_eq_left_iff],
assume hn,
apply (coeff_eq_zero_of_nat_degree_lt _).symm,
calc f.nat_degree < f.nat_degree + 1 : nat.lt_succ_self _
... ≤ n * 1 : by simpa only [mul_one] using hn
... ≤ n * p : mul_le_mul_of_nonneg_left (@nat.prime.one_lt p (fact.out _)).le (zero_le n)
end
theorem of_irreducible_expand {f : polynomial F} (hf : irreducible (expand F p f)) :
irreducible f :=
@@of_irreducible_map _ _ _ (is_local_ring_hom_expand F hp.1.pos) hf
theorem of_irreducible_expand_pow {f : polynomial F} {n : ℕ} :
irreducible (expand F (p ^ n) f) → irreducible f :=
nat.rec_on n (λ hf, by rwa [pow_zero, expand_one] at hf) $ λ n ih hf,
ih $ of_irreducible_expand p $ by { rw pow_succ at hf, rwa [expand_expand] }
variables [HF : char_p F p]
include HF
theorem expand_char (f : polynomial F) :
map (frobenius F p) (expand F p f) = f ^ p :=
begin
refine f.induction_on' (λ a b ha hb, _) (λ n a, _),
{ rw [alg_hom.map_add, map_add, ha, hb, add_pow_char], },
{ rw [expand_monomial, map_monomial, monomial_eq_C_mul_X, monomial_eq_C_mul_X,
mul_pow, ← C.map_pow, frobenius_def],
ring_exp }
end
theorem map_expand_pow_char (f : polynomial F) (n : ℕ) :
map ((frobenius F p) ^ n) (expand F (p ^ n) f) = f ^ (p ^ n) :=
begin
induction n, { simp [ring_hom.one_def] },
symmetry,
rw [pow_succ', pow_mul, ← n_ih, ← expand_char, pow_succ, ring_hom.mul_def, ← map_map, mul_comm,
expand_mul, ← map_expand (nat.prime.pos hp.1)],
end
theorem expand_contract {f : polynomial F} (hf : f.derivative = 0) :
expand F p (contract p f) = f :=
begin
ext n, rw [coeff_expand hp.1.pos, coeff_contract], split_ifs with h,
{ rw nat.div_mul_cancel h },
{ cases n, { exact absurd (dvd_zero p) h },
have := coeff_derivative f n, rw [hf, coeff_zero, zero_eq_mul] at this, cases this, { rw this },
rw [← nat.cast_succ, char_p.cast_eq_zero_iff F p] at this,
exact absurd this h }
end
theorem separable_or {f : polynomial F} (hf : irreducible f) : f.separable ∨
¬f.separable ∧ ∃ g : polynomial F, irreducible g ∧ expand F p g = f :=
if H : f.derivative = 0 then or.inr
⟨by rw [separable_iff_derivative_ne_zero hf, not_not, H],
contract p f,
by haveI := is_local_ring_hom_expand F hp.1.pos; exact
of_irreducible_map ↑(expand F p) (by rwa ← expand_contract p H at hf),
expand_contract p H⟩
else or.inl $ (separable_iff_derivative_ne_zero hf).2 H
theorem exists_separable_of_irreducible {f : polynomial F} (hf : irreducible f) (hf0 : f ≠ 0) :
∃ (n : ℕ) (g : polynomial F), g.separable ∧ expand F (p ^ n) g = f :=
begin
generalize hn : f.nat_degree = N, unfreezingI { revert f },
apply nat.strong_induction_on N, intros N ih f hf hf0 hn,
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,
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.1.one_lt (nat.pos_of_ne_zero hg2) },
have hg4 : g ≠ 0,
{ rintro rfl, exact hg2 nat_degree_zero },
rcases ih _ hg3 hg hg4 rfl with ⟨n, g, hg5, rfl⟩, refine ⟨n+1, g, hg5, _⟩,
rw [← hgf, expand_expand, pow_succ] }
end
theorem is_unit_or_eq_zero_of_separable_expand {f : polynomial F} (n : ℕ)
(hf : (expand F (p ^ n) f).separable) : is_unit f ∨ n = 0 :=
begin
rw or_iff_not_imp_right, intro hn,
have hf2 : (expand F (p ^ n) f).derivative = 0,
{ by rw [derivative_expand, nat.cast_pow, char_p.cast_eq_zero,
zero_pow (nat.pos_of_ne_zero hn), 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.1.pos _)] at hrf,
rwa [hrf, is_unit_C]
end
theorem unique_separable_of_irreducible {f : polynomial F} (hf : irreducible f) (hf0 : f ≠ 0)
(n₁ : ℕ) (g₁ : polynomial F) (hg₁ : g₁.separable) (hgf₁ : expand F (p ^ n₁) g₁ = f)
(n₂ : ℕ) (g₂ : polynomial F) (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₁] tactic.skip,
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.1.pos n₁)] at hgf₂, subst hgf₂,
subst hgf₁,
rcases is_unit_or_eq_zero_of_separable_expand p k 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 } },
exact λ g₁ g₂ hg₁ hgf₁ hg₂ hgf₂, let ⟨hn, hg⟩ :=
this g₂ g₁ hg₂ hgf₂ hg₁ hgf₁ in ⟨hn.symm, hg.symm⟩
end
end char_p
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 _ _ { 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]
section splits
open_locale big_operators
variables {i : F →+* K}
lemma not_unit_X_sub_C (a : F) : ¬ is_unit (X - C a) :=
λ h, have one_eq_zero : (1 : with_bot ℕ) = 0, by simpa using degree_eq_zero_of_is_unit h,
one_ne_zero (option.some_injective _ one_eq_zero)
lemma nodup_of_separable_prod {s : multiset F}
(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_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
lemma multiplicity_le_one_of_separable {p q : polynomial F} (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,
exact_mod_cast (enat.add_one_le_of_lt hq)
end
lemma separable.squarefree {p : polynomial F} (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
/--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) :=
begin
cases nat.eq_zero_or_pos n with hzero hpos,
{ exfalso,
rw hzero at hn,
exact hn (refl 0) },
apply (separable_def' (X ^ n - C a)).2,
use [-C (a⁻¹), (C ((a⁻¹) * (↑n)⁻¹) * X)],
have mul_pow_sub : X * X ^ (n - 1) = X ^ n,
{ nth_rewrite 0 [←pow_one X],
rw pow_mul_pow_sub X (nat.succ_le_iff.mpr hpos) },
rw [derivative_sub, derivative_C, sub_zero, derivative_pow X n, derivative_X, mul_one],
have hcalc : C (a⁻¹ * (↑n)⁻¹) * (↑n * (X ^ n)) = C a⁻¹ * (X ^ n),
{ calc C (a⁻¹ * (↑n)⁻¹) * (↑n * (X ^ n))
= C a⁻¹ * C ((↑n)⁻¹) * (C ↑n * (X ^ n)) : by rw [C_mul, C_eq_nat_cast]
... = C a⁻¹ * (C ((↑n)⁻¹) * C ↑n) * (X ^ n) : by ring
... = C a⁻¹ * C ((↑n)⁻¹ * ↑n) * (X ^ n) : by rw [← C_mul]
... = C a⁻¹ * C 1 * (X ^ n) : by field_simp [hn]
... = C a⁻¹ * (X ^ n) : by rw [C_1, mul_one] },
calc -C a⁻¹ * (X ^ n - C a) + C (a⁻¹ * (↑n)⁻¹) * X * (↑n * X ^ (n - 1))
= -C a⁻¹ * (X ^ n - C a) + C (a⁻¹ * (↑n)⁻¹) * (↑n * (X * X ^ (n - 1))) : by ring
... = -C a⁻¹ * (X ^ n - C a) + C a⁻¹ * (X ^ n) : by rw [mul_pow_sub, hcalc]
... = C a⁻¹ * C a : by ring
... = (1 : polynomial F) : by rw [← C_mul, inv_mul_cancel ha, C_1]
end
/--If `n ≠ 0` in `F`, then ` X ^ n - a` is squarefree for any `a ≠ 0`. -/
lemma squarefree_X_pow_sub_C {n : ℕ} (a : F) (hn : (n : F) ≠ 0) (ha : a ≠ 0) :
squarefree (X ^ n - C a) :=
(separable_X_pow_sub_C a hn ha).squarefree
lemma root_multiplicity_le_one_of_separable {p : polynomial F} (hp : p ≠ 0)
(hsep : separable p) (x : F) : root_multiplicity x p ≤ 1 :=
begin
rw [root_multiplicity_eq_multiplicity, dif_neg hp, ← enat.coe_le_coe, enat.coe_get],
exact multiplicity_le_one_of_separable (not_unit_X_sub_C _) hsep
end
lemma count_roots_le_one {p : polynomial F} (hsep : separable p) (x : F) :
p.roots.count x ≤ 1 :=
begin
by_cases hp : p = 0,
{ simp [hp] },
rw count_roots hp,
exact root_multiplicity_le_one_of_separable hp hsep x
end
lemma nodup_roots {p : polynomial F} (hsep : separable p) :
p.roots.nodup :=
multiset.nodup_iff_count_le_one.mpr (count_roots_le_one hsep)
lemma card_root_set_eq_nat_degree [algebra F K] {p : polynomial F} (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
lemma eq_X_sub_C_of_separable_of_root_eq {x : F} {h : polynomial F} (h_ne_zero : h ≠ 0)
(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
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 : polynomial F} (sep : separable f) (sp : splits i f) :
∃ (s : finset K), f.map i =
C (i f.leading_coeff) * (s.prod (λ a : K, (X : polynomial K) - C a)) :=
begin
classical,
obtain ⟨s, h⟩ := exists_multiset_of_splits i 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
end field
end polynomial
open polynomial
theorem irreducible.separable {F : Type u} [field F] [char_zero F] {f : polynomial F}
(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
-- 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. -/
class is_separable (F K : Sort*) [field F] [field K] [algebra F K] : Prop :=
(is_integral' (x : K) : is_integral F x)
(separable' (x : K) : (minpoly F x).separable)
theorem is_separable.is_integral (F) {K} [field F] [field K] [algebra F K] [is_separable F K] :
∀ x : K, is_integral F x := is_separable.is_integral'
theorem is_separable.separable (F) {K} [field F] [field K] [algebra F K] [is_separable F K] :
∀ x : K, (minpoly F x).separable := is_separable.separable'
theorem is_separable_iff {F K} [field F] [field K] [algebra F K] : 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⟩⟩
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 }⟩
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 x (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
(is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero_field
(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
|
ba053915d88d1564dd97a425e6e89b3b4dd18d69 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/qexpr1.lean | 8f6e3c6bee21227b22440f45b90149c9c635af91 | [
"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 | 322 | lean | open tactic
set_option pp.all true
example (a b c : nat) : true :=
by do
x ← to_expr ```(a + b),
trace x, infer_type x >>= trace,
constructor
example (a b c : nat) : true :=
by do
x ← get_local `a,
x ← mk_app `nat.succ [x],
r ← to_expr ```(%%x + b),
trace r, infer_type r >>= trace,
constructor
|
d67f9252f5252082ce82cde4b0dee4474f351999 | 6b10c15e653d49d146378acda9f3692e9b5b1950 | /examples/basic_skills/unnamed_207.lean | ca835e473a66589193f6b47b15a814a7ce6352fd | [] | no_license | gebner/mathematics_in_lean | 3cf7f18767208ea6c3307ec3a67c7ac266d8514d | 6d1462bba46d66a9b948fc1aef2714fd265cde0b | refs/heads/master | 1,655,301,945,565 | 1,588,697,505,000 | 1,588,697,505,000 | 261,523,603 | 0 | 0 | null | 1,588,695,611,000 | 1,588,695,610,000 | null | UTF-8 | Lean | false | false | 315 | lean | import data.real.basic
-- BEGIN
example (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) :
a * (b * e) = c * (d * f) :=
begin
rw [h', ←mul_assoc, h, mul_assoc]
end
example (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) :
a * (b * e) = c * (d * f) :=
by rw [h', ←mul_assoc, h, mul_assoc]
-- END |
aed1184d348fceb77884521e717b3d162e6446f2 | 367134ba5a65885e863bdc4507601606690974c1 | /src/order/filter/bases.lean | ab198170ca6a5e30fd25ea28d9ac1969256b33b2 | [
"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 | 36,639 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import order.filter.basic
import data.set.countable
/-!
# Filter bases
A filter basis `B : filter_basis α` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element of
the collection. Compared to filters, filter bases do not require that any set containing
an element of `B` belongs to `B`.
A filter basis `B` can be used to construct `B.filter : filter α` such that a set belongs
to `B.filter` if and only if it contains an element of `B`.
Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → set α`,
the proposition `h : filter.is_basis p s` makes sure the range of `s` bounded by `p`
(ie. `s '' set_of p`) defines a filter basis `h.filter_basis`.
If one already has a filter `l` on `α`, `filter.has_basis l p s` (where `p : ι → Prop`
and `s : ι → set α` as above) means that a set belongs to `l` if and
only if it contains some `s i` with `p i`. It implies `h : filter.is_basis p s`, and
`l = h.filter_basis.filter`. The point of this definition is that checking statements
involving elements of `l` often reduces to checking them on the basis elements.
We define a function `has_basis.index (h : filter.has_basis l p s) (t) (ht : t ∈ l)` that returns
some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual
destruction of `h.mem_iff.mpr ht` using `cases` or `let`.
This file also introduces more restricted classes of bases, involving monotonicity or
countability. In particular, for `l : filter α`, `l.is_countably_generated` means
there is a countable set of sets which generates `s`. This is reformulated in term of bases,
and consequences are derived.
## Main statements
* `has_basis.mem_iff`, `has_basis.mem_of_superset`, `has_basis.mem_of_mem` : restate `t ∈ f`
in terms of a basis;
* `basis_sets` : all sets of a filter form a basis;
* `has_basis.inf`, `has_basis.inf_principal`, `has_basis.prod`, `has_basis.prod_self`,
`has_basis.map`, `has_basis.comap` : combinators to construct filters of `l ⊓ l'`,
`l ⊓ 𝓟 t`, `l ×ᶠ l'`, `l ×ᶠ l`, `l.map f`, `l.comap f` respectively;
* `has_basis.le_iff`, `has_basis.ge_iff`, has_basis.le_basis_iff` : restate `l ≤ l'` in terms
of bases.
* `has_basis.tendsto_right_iff`, `has_basis.tendsto_left_iff`, `has_basis.tendsto_iff` : restate
`tendsto f l l'` in terms of bases.
* `is_countably_generated_iff_exists_antimono_basis` : proves a filter is
countably generated if and only if it admis a basis parametrized by a
decreasing sequence of sets indexed by `ℕ`.
* `tendsto_iff_seq_tendsto ` : an abstract version of "sequentially continuous implies continuous".
## Implementation notes
As with `Union`/`bUnion`/`sUnion`, there are three different approaches to filter bases:
* `has_basis l s`, `s : set (set α)`;
* `has_basis l s`, `s : ι → set α`;
* `has_basis l p s`, `p : ι → Prop`, `s : ι → set α`.
We use the latter one because, e.g., `𝓝 x` in an `emetric_space` or in a `metric_space` has a basis
of this form. The other two can be emulated using `s = id` or `p = λ _, true`.
With this approach sometimes one needs to `simp` the statement provided by the `has_basis`
machinery, e.g., `simp only [exists_prop, true_and]` or `simp only [forall_const]` can help
with the case `p = λ _, true`.
-/
open set filter
open_locale filter classical
variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*} {ι' : Type*}
/-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure filter_basis (α : Type*) :=
(sets : set (set α))
(nonempty : sets.nonempty)
(inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y)
instance filter_basis.nonempty_sets (B : filter_basis α) : nonempty B.sets := B.nonempty.to_subtype
/-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as
on paper. -/
@[reducible]
instance {α : Type*}: has_mem (set α) (filter_basis α) := ⟨λ U B, U ∈ B.sets⟩
-- For illustration purposes, the filter basis defining (at_top : filter ℕ)
instance : inhabited (filter_basis ℕ) :=
⟨{ sets := range Ici,
nonempty := ⟨Ici 0, mem_range_self 0⟩,
inter_sets := begin
rintros _ _ ⟨n, rfl⟩ ⟨m, rfl⟩,
refine ⟨Ici (max n m), mem_range_self _, _⟩,
rintros p p_in,
split ; rw mem_Ici at *,
exact le_of_max_le_left p_in,
exact le_of_max_le_right p_in,
end }⟩
/-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/
protected structure filter.is_basis (p : ι → Prop) (s : ι → set α) : Prop :=
(nonempty : ∃ i, p i)
(inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j)
namespace filter
namespace is_basis
/-- Constructs a filter basis from an indexed family of sets satisfying `is_basis`. -/
protected def filter_basis {p : ι → Prop} {s : ι → set α} (h : is_basis p s) : filter_basis α :=
{ sets := s '' set_of p,
nonempty := let ⟨i, hi⟩ := h.nonempty in ⟨s i, mem_image_of_mem s hi⟩,
inter_sets := by { rintros _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩,
rcases h.inter hi hj with ⟨k, hk, hk'⟩,
exact ⟨_, mem_image_of_mem s hk, hk'⟩ } }
variables {p : ι → Prop} {s : ι → set α} (h : is_basis p s)
lemma mem_filter_basis_iff {U : set α} : U ∈ h.filter_basis ↔ ∃ i, p i ∧ s i = U :=
iff.rfl
end is_basis
end filter
namespace filter_basis
/-- The filter associated to a filter basis. -/
protected def filter (B : filter_basis α) : filter α :=
{ sets := {s | ∃ t ∈ B, t ⊆ s},
univ_sets := let ⟨s, s_in⟩ := B.nonempty in ⟨s, s_in, s.subset_univ⟩,
sets_of_superset := λ x y ⟨s, s_in, h⟩ hxy, ⟨s, s_in, set.subset.trans h hxy⟩,
inter_sets := λ x y ⟨s, s_in, hs⟩ ⟨t, t_in, ht⟩,
let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in in
⟨u, u_in, set.subset.trans u_sub $ set.inter_subset_inter hs ht⟩ }
lemma mem_filter_iff (B : filter_basis α) {U : set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U :=
iff.rfl
lemma mem_filter_of_mem (B : filter_basis α) {U : set α} : U ∈ B → U ∈ B.filter:=
λ U_in, ⟨U, U_in, subset.refl _⟩
lemma eq_infi_principal (B : filter_basis α) : B.filter = ⨅ s : B.sets, 𝓟 s :=
begin
have : directed (≥) (λ (s : B.sets), 𝓟 (s : set α)),
{ rintros ⟨U, U_in⟩ ⟨V, V_in⟩,
rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩,
use [W, W_in],
finish },
ext U,
simp [mem_filter_iff, mem_infi this]
end
protected lemma generate (B : filter_basis α) : generate B.sets = B.filter :=
begin
apply le_antisymm,
{ intros U U_in,
rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩,
exact generate_sets.superset (generate_sets.basic V_in) h },
{ rw sets_iff_generate,
apply mem_filter_of_mem }
end
end filter_basis
namespace filter
namespace is_basis
variables {p : ι → Prop} {s : ι → set α}
/-- Constructs a filter from an indexed family of sets satisfying `is_basis`. -/
protected def filter (h : is_basis p s) : filter α := h.filter_basis.filter
protected lemma mem_filter_iff (h : is_basis p s) {U : set α} :
U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U :=
begin
erw [h.filter_basis.mem_filter_iff],
simp only [mem_filter_basis_iff h, exists_prop],
split,
{ rintros ⟨_, ⟨i, pi, rfl⟩, h⟩,
tauto },
{ tauto }
end
lemma filter_eq_generate (h : is_basis p s) : h.filter = generate {U | ∃ i, p i ∧ s i = U} :=
by erw h.filter_basis.generate ; refl
end is_basis
/-- We say that a filter `l` has a basis `s : ι → set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/
protected structure has_basis (l : filter α) (p : ι → Prop) (s : ι → set α) : Prop :=
(mem_iff' : ∀ (t : set α), t ∈ l ↔ ∃ i (hi : p i), s i ⊆ t)
section same_type
variables {l l' : filter α} {p : ι → Prop} {s : ι → set α} {t : set α} {i : ι}
{p' : ι' → Prop} {s' : ι' → set α} {i' : ι'}
lemma has_basis_generate (s : set (set α)) :
(generate s).has_basis (λ t, finite t ∧ t ⊆ s) (λ t, ⋂₀ t) :=
⟨begin
intro U,
rw mem_generate_iff,
apply exists_congr,
tauto
end⟩
/-- The smallest filter basis containing a given collection of sets. -/
def filter_basis.of_sets (s : set (set α)) : filter_basis α :=
{ sets := sInter '' { t | finite t ∧ t ⊆ s},
nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩,
inter_sets := begin
rintros _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩,
exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩,
by rw sInter_union⟩,
end }
/-- Definition of `has_basis` unfolded with implicit set argument. -/
lemma has_basis.mem_iff (hl : l.has_basis p s) : t ∈ l ↔ ∃ i (hi : p i), s i ⊆ t :=
hl.mem_iff' t
lemma has_basis_iff : l.has_basis p s ↔ ∀ t, t ∈ l ↔ ∃ i (hi : p i), s i ⊆ t :=
⟨λ ⟨h⟩, h, λ h, ⟨h⟩⟩
lemma has_basis.ex_mem (h : l.has_basis p s) : ∃ i, p i :=
let ⟨i, pi, h⟩ := h.mem_iff.mp univ_mem_sets in ⟨i, pi⟩
protected lemma has_basis.nonempty (h : l.has_basis p s) : nonempty ι :=
nonempty_of_exists h.ex_mem
protected lemma is_basis.has_basis (h : is_basis p s) : has_basis h.filter p s :=
⟨λ t, by simp only [h.mem_filter_iff, exists_prop]⟩
lemma has_basis.mem_of_superset (hl : l.has_basis p s) (hi : p i) (ht : s i ⊆ t) : t ∈ l :=
(hl.mem_iff).2 ⟨i, hi, ht⟩
lemma has_basis.mem_of_mem (hl : l.has_basis p s) (hi : p i) : s i ∈ l :=
hl.mem_of_superset hi $ subset.refl _
/-- Index of a basis set such that `s i ⊆ t` as an element of `subtype p`. -/
noncomputable def has_basis.index (h : l.has_basis p s) (t : set α) (ht : t ∈ l) :
{i : ι // p i} :=
⟨(h.mem_iff.1 ht).some, (h.mem_iff.1 ht).some_spec.fst⟩
lemma has_basis.property_index (h : l.has_basis p s) (ht : t ∈ l) : p (h.index t ht) :=
(h.index t ht).2
lemma has_basis.set_index_mem (h : l.has_basis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l :=
h.mem_of_mem $ h.property_index _
lemma has_basis.set_index_subset (h : l.has_basis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t :=
(h.mem_iff.1 ht).some_spec.snd
lemma has_basis.is_basis (h : l.has_basis p s) : is_basis p s :=
{ nonempty := let ⟨i, hi, H⟩ := h.mem_iff.mp univ_mem_sets in ⟨i, hi⟩,
inter := λ i j hi hj, by simpa [h.mem_iff]
using l.inter_sets (h.mem_of_mem hi) (h.mem_of_mem hj) }
lemma has_basis.filter_eq (h : l.has_basis p s) : h.is_basis.filter = l :=
by { ext U, simp [h.mem_iff, is_basis.mem_filter_iff] }
lemma has_basis.eq_generate (h : l.has_basis p s) : l = generate { U | ∃ i, p i ∧ s i = U } :=
by rw [← h.is_basis.filter_eq_generate, h.filter_eq]
lemma generate_eq_generate_inter (s : set (set α)) :
generate s = generate (sInter '' { t | finite t ∧ t ⊆ s}) :=
by erw [(filter_basis.of_sets s).generate, ← (has_basis_generate s).filter_eq] ; refl
lemma of_sets_filter_eq_generate (s : set (set α)) : (filter_basis.of_sets s).filter = generate s :=
by rw [← (filter_basis.of_sets s).generate, generate_eq_generate_inter s] ; refl
lemma has_basis.to_has_basis (hl : l.has_basis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.has_basis p' s' :=
begin
constructor,
intro t,
rw hl.mem_iff,
split,
{ rintros ⟨i, pi, hi⟩,
rcases h i pi with ⟨i', pi', hi'⟩,
use [i', pi'],
tauto },
{ rintros ⟨i', pi', hi'⟩,
rcases h' i' pi' with ⟨i, pi, hi⟩,
use [i, pi],
tauto },
end
lemma has_basis.eventually_iff (hl : l.has_basis p s) {q : α → Prop} :
(∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x :=
by simpa using hl.mem_iff
lemma has_basis.frequently_iff (hl : l.has_basis p s) {q : α → Prop} :
(∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x :=
by simp [filter.frequently, hl.eventually_iff]
lemma has_basis.exists_iff (hl : l.has_basis p s) {P : set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) :
(∃ s ∈ l, P s) ↔ ∃ (i) (hi : p i), P (s i) :=
⟨λ ⟨s, hs, hP⟩, let ⟨i, hi, his⟩ := hl.mem_iff.1 hs in ⟨i, hi, mono his hP⟩,
λ ⟨i, hi, hP⟩, ⟨s i, hl.mem_of_mem hi, hP⟩⟩
lemma has_basis.forall_iff (hl : l.has_basis p s) {P : set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) :
(∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) :=
⟨λ H i hi, H (s i) $ hl.mem_of_mem hi,
λ H s hs, let ⟨i, hi, his⟩ := hl.mem_iff.1 hs in mono his (H i hi)⟩
lemma has_basis.ne_bot_iff (hl : l.has_basis p s) :
ne_bot l ↔ (∀ {i}, p i → (s i).nonempty) :=
forall_sets_nonempty_iff_ne_bot.symm.trans $ hl.forall_iff $ λ _ _, nonempty.mono
lemma has_basis.eq_bot_iff (hl : l.has_basis p s) :
l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ :=
not_iff_not.1 $ ne_bot_iff.symm.trans $ hl.ne_bot_iff.trans $
by simp only [not_exists, not_and, ← ne_empty_iff_nonempty]
lemma basis_sets (l : filter α) : l.has_basis (λ s : set α, s ∈ l) id :=
⟨λ t, exists_sets_subset_iff.symm⟩
lemma has_basis_self {l : filter α} {P : set α → Prop} :
has_basis l (λ s, s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t :=
begin
simp only [has_basis_iff, exists_prop, id, and_assoc],
exact forall_congr (λ s, ⟨λ h, h.1, λ h, ⟨h, λ ⟨t, hl, hP, hts⟩, mem_sets_of_superset hl hts⟩⟩)
end
/-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that
`p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/
lemma has_basis.restrict (h : l.has_basis p s) {q : ι → Prop}
(hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) :
l.has_basis (λ i, p i ∧ q i) s :=
begin
refine ⟨λ t, ⟨λ ht, _, λ ⟨i, hpi, hti⟩, h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩,
rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩,
rcases hq i hpi with ⟨j, hpj, hqj, hji⟩,
exact ⟨j, ⟨hpj, hqj⟩, subset.trans hji hti⟩
end
/-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}`
is a basis of `l`. -/
lemma has_basis.restrict_subset (h : l.has_basis p s) {V : set α} (hV : V ∈ l) :
l.has_basis (λ i, p i ∧ s i ⊆ V) s :=
h.restrict $ λ i hi, (h.mem_iff.1 (inter_mem_sets hV (h.mem_of_mem hi))).imp $
λ j hj, ⟨hj.fst, subset_inter_iff.1 hj.snd⟩
lemma has_basis.has_basis_self_subset {p : set α → Prop} (h : l.has_basis (λ s, s ∈ l ∧ p s) id)
{V : set α} (hV : V ∈ l) : l.has_basis (λ s, s ∈ l ∧ p s ∧ s ⊆ V) id :=
by simpa only [and_assoc] using h.restrict_subset hV
theorem has_basis.ge_iff (hl' : l'.has_basis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l :=
⟨λ h i' hi', h $ hl'.mem_of_mem hi',
λ h s hs, let ⟨i', hi', hs⟩ := hl'.mem_iff.1 hs in mem_sets_of_superset (h _ hi') hs⟩
theorem has_basis.le_iff (hl : l.has_basis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i (hi : p i), s i ⊆ t :=
by simp only [le_def, hl.mem_iff]
theorem has_basis.le_basis_iff (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
l ≤ l' ↔ ∀ i', p' i' → ∃ i (hi : p i), s i ⊆ s' i' :=
by simp only [hl'.ge_iff, hl.mem_iff]
lemma has_basis.ext (hl : l.has_basis p s) (hl' : l'.has_basis p' s')
(h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l = l' :=
begin
apply le_antisymm,
{ rw hl.le_basis_iff hl',
simpa using h' },
{ rw hl'.le_basis_iff hl,
simpa using h },
end
lemma has_basis.inf (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
(l ⊓ l').has_basis (λ i : ι × ι', p i.1 ∧ p' i.2) (λ i, s i.1 ∩ s' i.2) :=
⟨begin
intro t,
simp only [mem_inf_sets, exists_prop, hl.mem_iff, hl'.mem_iff],
split,
{ rintros ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, H⟩,
use [(i, i'), ⟨hi, hi'⟩, subset.trans (inter_subset_inter ht ht') H] },
{ rintros ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩,
use [s i, i, hi, subset.refl _, s' i', i', hi', subset.refl _, H] }
end⟩
lemma has_basis_principal (t : set α) : (𝓟 t).has_basis (λ i : unit, true) (λ i, t) :=
⟨λ U, by simp⟩
lemma has_basis.sup (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
(l ⊔ l').has_basis (λ i : ι × ι', p i.1 ∧ p' i.2) (λ i, s i.1 ∪ s' i.2) :=
⟨begin
intros t,
simp only [mem_sup_sets, hl.mem_iff, hl'.mem_iff, prod.exists, union_subset_iff, exists_prop,
and_assoc, exists_and_distrib_left],
simp only [← and_assoc, exists_and_distrib_right, and_comm]
end⟩
lemma has_basis.inf_principal (hl : l.has_basis p s) (s' : set α) :
(l ⊓ 𝓟 s').has_basis p (λ i, s i ∩ s') :=
⟨λ t, by simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_set_of_eq,
mem_inter_iff, and_imp]⟩
lemma has_basis.inf_basis_ne_bot_iff (hl : l.has_basis p s) (hl' : l'.has_basis p' s') :
ne_bot (l ⊓ l') ↔ ∀ ⦃i⦄ (hi : p i) ⦃i'⦄ (hi' : p' i'), (s i ∩ s' i').nonempty :=
(hl.inf hl').ne_bot_iff.trans $ by simp [@forall_swap _ ι']
lemma has_basis.inf_ne_bot_iff (hl : l.has_basis p s) :
ne_bot (l ⊓ l') ↔ ∀ ⦃i⦄ (hi : p i) ⦃s'⦄ (hs' : s' ∈ l'), (s i ∩ s').nonempty :=
hl.inf_basis_ne_bot_iff l'.basis_sets
lemma has_basis.inf_principal_ne_bot_iff (hl : l.has_basis p s) {t : set α} :
ne_bot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄ (hi : p i), (s i ∩ t).nonempty :=
(hl.inf_principal t).ne_bot_iff
lemma inf_ne_bot_iff :
ne_bot (l ⊓ l') ↔ ∀ ⦃s : set α⦄ (hs : s ∈ l) ⦃s'⦄ (hs' : s' ∈ l'), (s ∩ s').nonempty :=
l.basis_sets.inf_ne_bot_iff
lemma inf_principal_ne_bot_iff {s : set α} :
ne_bot (l ⊓ 𝓟 s) ↔ ∀ U ∈ l, (U ∩ s).nonempty :=
l.basis_sets.inf_principal_ne_bot_iff
lemma inf_eq_bot_iff {f g : filter α} :
f ⊓ g = ⊥ ↔ ∃ (U ∈ f) (V ∈ g), U ∩ V = ∅ :=
not_iff_not.1 $ ne_bot_iff.symm.trans $ inf_ne_bot_iff.trans $
by simp [← ne_empty_iff_nonempty]
protected lemma disjoint_iff {f g : filter α} :
disjoint f g ↔ ∃ (U ∈ f) (V ∈ g), U ∩ V = ∅ :=
disjoint_iff.trans inf_eq_bot_iff
lemma mem_iff_inf_principal_compl {f : filter α} {s : set α} :
s ∈ f ↔ f ⊓ 𝓟 sᶜ = ⊥ :=
begin
refine not_iff_not.1 ((inf_principal_ne_bot_iff.trans _).symm.trans ne_bot_iff),
exact ⟨λ h hs, by simpa [empty_not_nonempty] using h s hs,
λ hs t ht, inter_compl_nonempty_iff.2 $ λ hts, hs $ mem_sets_of_superset ht hts⟩,
end
lemma not_mem_iff_inf_principal_compl {f : filter α} {s : set α} :
s ∉ f ↔ ne_bot (f ⊓ 𝓟 sᶜ) :=
(not_congr mem_iff_inf_principal_compl).trans ne_bot_iff.symm
lemma mem_iff_disjoint_principal_compl {f : filter α} {s : set α} :
s ∈ f ↔ disjoint f (𝓟 sᶜ) :=
mem_iff_inf_principal_compl.trans disjoint_iff.symm
lemma le_iff_forall_disjoint_principal_compl {f g : filter α} :
f ≤ g ↔ ∀ V ∈ g, disjoint f (𝓟 Vᶜ) :=
forall_congr $ λ _, forall_congr $ λ _, mem_iff_disjoint_principal_compl
lemma le_iff_forall_inf_principal_compl {f g : filter α} :
f ≤ g ↔ ∀ V ∈ g, f ⊓ 𝓟 Vᶜ = ⊥ :=
forall_congr $ λ _, forall_congr $ λ _, mem_iff_inf_principal_compl
lemma inf_ne_bot_iff_frequently_left {f g : filter α} :
ne_bot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in f, p x) → ∃ᶠ x in g, p x :=
by simpa only [inf_ne_bot_iff, frequently_iff, exists_prop, and_comm]
lemma inf_ne_bot_iff_frequently_right {f g : filter α} :
ne_bot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in g, p x) → ∃ᶠ x in f, p x :=
by { rw inf_comm, exact inf_ne_bot_iff_frequently_left }
lemma has_basis.eq_binfi (h : l.has_basis p s) :
l = ⨅ i (_ : p i), 𝓟 (s i) :=
eq_binfi_of_mem_sets_iff_exists_mem $ λ t, by simp only [h.mem_iff, mem_principal_sets]
lemma has_basis.eq_infi (h : l.has_basis (λ _, true) s) :
l = ⨅ i, 𝓟 (s i) :=
by simpa only [infi_true] using h.eq_binfi
lemma has_basis_infi_principal {s : ι → set α} (h : directed (≥) s) [nonempty ι] :
(⨅ i, 𝓟 (s i)).has_basis (λ _, true) s :=
⟨begin
refine λ t, (mem_infi (h.mono_comp _ _) t).trans $
by simp only [exists_prop, true_and, mem_principal_sets],
exact λ _ _, principal_mono.2
end⟩
/-- If `s : ι → set α` is an indexed family of sets, then finite intersections of `s i` form a basis
of `⨅ i, 𝓟 (s i)`. -/
lemma has_basis_infi_principal_finite (s : ι → set α) :
(⨅ i, 𝓟 (s i)).has_basis (λ t : set ι, finite t) (λ t, ⋂ i ∈ t, s i) :=
begin
refine ⟨λ U, (mem_infi_finite _).trans _⟩,
simp only [infi_principal_finset, mem_Union, mem_principal_sets, exists_prop,
exists_finite_iff_finset, finset.set_bInter_coe]
end
lemma has_basis_binfi_principal {s : β → set α} {S : set β} (h : directed_on (s ⁻¹'o (≥)) S)
(ne : S.nonempty) :
(⨅ i ∈ S, 𝓟 (s i)).has_basis (λ i, i ∈ S) s :=
⟨begin
refine λ t, (mem_binfi _ ne).trans $ by simp only [mem_principal_sets],
rw [directed_on_iff_directed, ← directed_comp, (∘)] at h ⊢,
apply h.mono_comp _ _,
exact λ _ _, principal_mono.2
end⟩
lemma has_basis_binfi_principal'
(h : ∀ i, p i → ∀ j, p j → ∃ k (h : p k), s k ⊆ s i ∧ s k ⊆ s j) (ne : ∃ i, p i) :
(⨅ i (h : p i), 𝓟 (s i)).has_basis p s :=
filter.has_basis_binfi_principal h ne
lemma has_basis.map (f : α → β) (hl : l.has_basis p s) :
(l.map f).has_basis p (λ i, f '' (s i)) :=
⟨λ t, by simp only [mem_map, image_subset_iff, hl.mem_iff, preimage]⟩
lemma has_basis.comap (f : β → α) (hl : l.has_basis p s) :
(l.comap f).has_basis p (λ i, f ⁻¹' (s i)) :=
⟨begin
intro t,
simp only [mem_comap_sets, exists_prop, hl.mem_iff],
split,
{ rintros ⟨t', ⟨i, hi, ht'⟩, H⟩,
exact ⟨i, hi, subset.trans (preimage_mono ht') H⟩ },
{ rintros ⟨i, hi, H⟩,
exact ⟨s i, ⟨i, hi, subset.refl _⟩, H⟩ }
end⟩
lemma comap_has_basis (f : α → β) (l : filter β) :
has_basis (comap f l) (λ s : set β, s ∈ l) (λ s, f ⁻¹' s) :=
⟨λ t, mem_comap_sets⟩
lemma has_basis.prod_self (hl : l.has_basis p s) :
(l ×ᶠ l).has_basis p (λ i, (s i).prod (s i)) :=
⟨begin
intro t,
apply mem_prod_iff.trans,
split,
{ rintros ⟨t₁, ht₁, t₂, ht₂, H⟩,
rcases hl.mem_iff.1 (inter_mem_sets ht₁ ht₂) with ⟨i, hi, ht⟩,
exact ⟨i, hi, λ p ⟨hp₁, hp₂⟩, H ⟨(ht hp₁).1, (ht hp₂).2⟩⟩ },
{ rintros ⟨i, hi, H⟩,
exact ⟨s i, hl.mem_of_mem hi, s i, hl.mem_of_mem hi, H⟩ }
end⟩
lemma mem_prod_self_iff {s} : s ∈ l ×ᶠ l ↔ ∃ t ∈ l, set.prod t t ⊆ s :=
l.basis_sets.prod_self.mem_iff
lemma has_basis.sInter_sets (h : has_basis l p s) :
⋂₀ l.sets = ⋂ i ∈ set_of p, s i :=
begin
ext x,
suffices : (∀ t ∈ l, x ∈ t) ↔ ∀ i, p i → x ∈ s i,
by simpa only [mem_Inter, mem_set_of_eq, mem_sInter],
simp_rw h.mem_iff,
split,
{ intros h i hi,
exact h (s i) ⟨i, hi, subset.refl _⟩ },
{ rintros h _ ⟨i, hi, sub⟩,
exact sub (h i hi) },
end
variables [preorder ι] (l p s)
/-- `is_antimono_basis p s` means the image of `s` bounded by `p` is a filter basis
such that `s` is decreasing and `p` is increasing, ie `i ≤ j → p i → p j`. -/
structure is_antimono_basis extends is_basis p s : Prop :=
(decreasing : ∀ {i j}, p i → p j → i ≤ j → s j ⊆ s i)
(mono : monotone p)
/-- We say that a filter `l` has a antimono basis `s : ι → set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`,
and `s` is decreasing and `p` is increasing, ie `i ≤ j → p i → p j`. -/
structure has_antimono_basis [preorder ι] (l : filter α) (p : ι → Prop) (s : ι → set α)
extends has_basis l p s : Prop :=
(decreasing : ∀ {i j}, p i → p j → i ≤ j → s j ⊆ s i)
(mono : monotone p)
end same_type
section two_types
variables {la : filter α} {pa : ι → Prop} {sa : ι → set α}
{lb : filter β} {pb : ι' → Prop} {sb : ι' → set β} {f : α → β}
lemma has_basis.tendsto_left_iff (hla : la.has_basis pa sa) :
tendsto f la lb ↔ ∀ t ∈ lb, ∃ i (hi : pa i), ∀ x ∈ sa i, f x ∈ t :=
by { simp only [tendsto, (hla.map f).le_iff, image_subset_iff], refl }
lemma has_basis.tendsto_right_iff (hlb : lb.has_basis pb sb) :
tendsto f la lb ↔ ∀ i (hi : pb i), ∀ᶠ x in la, f x ∈ sb i :=
by simp only [tendsto, hlb.ge_iff, mem_map, filter.eventually]
lemma has_basis.tendsto_iff (hla : la.has_basis pa sa) (hlb : lb.has_basis pb sb) :
tendsto f la lb ↔ ∀ ib (hib : pb ib), ∃ ia (hia : pa ia), ∀ x ∈ sa ia, f x ∈ sb ib :=
by simp [hlb.tendsto_right_iff, hla.eventually_iff]
lemma tendsto.basis_left (H : tendsto f la lb) (hla : la.has_basis pa sa) :
∀ t ∈ lb, ∃ i (hi : pa i), ∀ x ∈ sa i, f x ∈ t :=
hla.tendsto_left_iff.1 H
lemma tendsto.basis_right (H : tendsto f la lb) (hlb : lb.has_basis pb sb) :
∀ i (hi : pb i), ∀ᶠ x in la, f x ∈ sb i :=
hlb.tendsto_right_iff.1 H
lemma tendsto.basis_both (H : tendsto f la lb) (hla : la.has_basis pa sa)
(hlb : lb.has_basis pb sb) :
∀ ib (hib : pb ib), ∃ ia (hia : pa ia), ∀ x ∈ sa ia, f x ∈ sb ib :=
(hla.tendsto_iff hlb).1 H
lemma has_basis.prod (hla : la.has_basis pa sa) (hlb : lb.has_basis pb sb) :
(la ×ᶠ lb).has_basis (λ i : ι × ι', pa i.1 ∧ pb i.2) (λ i, (sa i.1).prod (sb i.2)) :=
(hla.comap prod.fst).inf (hlb.comap prod.snd)
lemma has_basis.prod' {la : filter α} {lb : filter β} {ι : Type*} {p : ι → Prop}
{sa : ι → set α} {sb : ι → set β}
(hla : la.has_basis p sa) (hlb : lb.has_basis p sb)
(h_dir : ∀ {i j}, p i → p j → ∃ k, p k ∧ sa k ⊆ sa i ∧ sb k ⊆ sb j) :
(la ×ᶠ lb).has_basis p (λ i, (sa i).prod (sb i)) :=
⟨begin
intros t,
rw mem_prod_iff,
split,
{ rintros ⟨u, u_in, v, v_in, huv⟩,
rcases hla.mem_iff.mp u_in with ⟨i, hi, si⟩,
rcases hlb.mem_iff.mp v_in with ⟨j, hj, sj⟩,
rcases h_dir hi hj with ⟨k, hk, ki, kj⟩,
use [k, hk],
calc
(sa k).prod (sb k) ⊆ (sa i).prod (sb j) : set.prod_mono ki kj
... ⊆ u.prod v : set.prod_mono si sj
... ⊆ t : huv, },
{ rintro ⟨i, hi, h⟩,
exact ⟨sa i, hla.mem_of_mem hi, sb i, hlb.mem_of_mem hi, h⟩ },
end⟩
end two_types
/-- `is_countably_generated f` means `f = generate s` for some countable `s`. -/
def is_countably_generated (f : filter α) : Prop :=
∃ s : set (set α), countable s ∧ f = generate s
/-- `is_countable_basis p s` means the image of `s` bounded by `p` is a countable filter basis. -/
structure is_countable_basis (p : ι → Prop) (s : ι → set α) extends is_basis p s : Prop :=
(countable : countable $ set_of p)
/-- We say that a filter `l` has a countable basis `s : ι → set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`, and the set
defined by `p` is countable. -/
structure has_countable_basis (l : filter α) (p : ι → Prop) (s : ι → set α)
extends has_basis l p s : Prop :=
(countable : countable $ set_of p)
/-- A countable filter basis `B` on a type `α` is a nonempty countable collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure countable_filter_basis (α : Type*) extends filter_basis α :=
(countable : countable sets)
-- For illustration purposes, the countable filter basis defining (at_top : filter ℕ)
instance nat.inhabited_countable_filter_basis : inhabited (countable_filter_basis ℕ) :=
⟨{ countable := countable_range (λ n, Ici n),
..(default $ filter_basis ℕ),}⟩
lemma antimono_seq_of_seq (s : ℕ → set α) :
∃ t : ℕ → set α, (∀ i j, i ≤ j → t j ⊆ t i) ∧ (⨅ i, 𝓟 $ s i) = ⨅ i, 𝓟 (t i) :=
begin
use λ n, ⋂ m ≤ n, s m, split,
{ exact λ i j hij, bInter_mono' (Iic_subset_Iic.2 hij) (λ n hn, subset.refl _) },
apply le_antisymm; rw le_infi_iff; intro i,
{ rw le_principal_iff, refine (bInter_mem_sets (finite_le_nat _)).2 (λ j hji, _),
rw ← le_principal_iff, apply infi_le_of_le j _, apply le_refl _ },
{ apply infi_le_of_le i _, rw principal_mono, intro a, simp, intro h, apply h, refl },
end
lemma countable_binfi_eq_infi_seq [complete_lattice α] {B : set ι} (Bcbl : countable B)
(Bne : B.nonempty) (f : ι → α) :
∃ (x : ℕ → ι), (⨅ t ∈ B, f t) = ⨅ i, f (x i) :=
begin
rw countable_iff_exists_surjective_to_subtype Bne at Bcbl,
rcases Bcbl with ⟨g, gsurj⟩,
rw infi_subtype',
use (λ n, g n), apply le_antisymm; rw le_infi_iff,
{ intro i, apply infi_le_of_le (g i) _, apply le_refl _ },
{ intros a, rcases gsurj a with ⟨i, rfl⟩, apply infi_le }
end
lemma countable_binfi_eq_infi_seq' [complete_lattice α] {B : set ι} (Bcbl : countable B) (f : ι → α)
{i₀ : ι} (h : f i₀ = ⊤) :
∃ (x : ℕ → ι), (⨅ t ∈ B, f t) = ⨅ i, f (x i) :=
begin
cases B.eq_empty_or_nonempty with hB Bnonempty,
{ rw [hB, infi_emptyset],
use λ n, i₀,
simp [h] },
{ exact countable_binfi_eq_infi_seq Bcbl Bnonempty f }
end
lemma countable_binfi_principal_eq_seq_infi {B : set (set α)} (Bcbl : countable B) :
∃ (x : ℕ → set α), (⨅ t ∈ B, 𝓟 t) = ⨅ i, 𝓟 (x i) :=
countable_binfi_eq_infi_seq' Bcbl 𝓟 principal_univ
namespace is_countably_generated
/-- A set generating a countably generated filter. -/
def generating_set {f : filter α} (h : is_countably_generated f) :=
classical.some h
lemma countable_generating_set {f : filter α} (h : is_countably_generated f) :
countable h.generating_set :=
(classical.some_spec h).1
lemma eq_generate {f : filter α} (h : is_countably_generated f) :
f = generate h.generating_set :=
(classical.some_spec h).2
/-- A countable filter basis for a countably generated filter. -/
def countable_filter_basis {l : filter α} (h : is_countably_generated l) :
countable_filter_basis α :=
{ countable := (countable_set_of_finite_subset h.countable_generating_set).image _,
..filter_basis.of_sets (h.generating_set) }
lemma filter_basis_filter {l : filter α} (h : is_countably_generated l) :
h.countable_filter_basis.to_filter_basis.filter = l :=
begin
conv_rhs { rw h.eq_generate },
apply of_sets_filter_eq_generate,
end
lemma has_countable_basis {l : filter α} (h : is_countably_generated l) :
l.has_countable_basis (λ t, finite t ∧ t ⊆ h.generating_set) (λ t, ⋂₀ t) :=
⟨by convert has_basis_generate _ ; exact h.eq_generate,
countable_set_of_finite_subset h.countable_generating_set⟩
lemma exists_countable_infi_principal {f : filter α} (h : f.is_countably_generated) :
∃ s : set (set α), countable s ∧ f = ⨅ t ∈ s, 𝓟 t :=
begin
let B := h.countable_filter_basis,
use [B.sets, B.countable],
rw ← h.filter_basis_filter,
rw B.to_filter_basis.eq_infi_principal,
rw infi_subtype''
end
lemma exists_seq {f : filter α} (cblb : f.is_countably_generated) :
∃ x : ℕ → set α, f = ⨅ i, 𝓟 (x i) :=
begin
rcases cblb.exists_countable_infi_principal with ⟨B, Bcbl, rfl⟩,
exact countable_binfi_principal_eq_seq_infi Bcbl,
end
/-- If `f` is countably generated and `f.has_basis p s`, then `f` admits a decreasing basis
enumerated by natural numbers such that all sets have the form `s i`. More precisely, there is a
sequence `i n` such that `p (i n)` for all `n` and `s (i n)` is a decreasing sequence of sets which
forms a basis of `f`-/
lemma exists_antimono_subbasis {f : filter α} (cblb : f.is_countably_generated)
{p : ι → Prop} {s : ι → set α} (hs : f.has_basis p s) :
∃ x : ℕ → ι, (∀ i, p (x i)) ∧ f.has_antimono_basis (λ _, true) (λ i, s (x i)) :=
begin
rcases cblb.exists_seq with ⟨x', hx'⟩,
have : ∀ i, x' i ∈ f := λ i, hx'.symm ▸ (infi_le (λ i, 𝓟 (x' i)) i) (mem_principal_self _),
let x : ℕ → {i : ι // p i} := λ n, nat.rec_on n (hs.index _ $ this 0)
(λ n xn, (hs.index _ $ inter_mem_sets (this $ n + 1) (hs.mem_of_mem xn.coe_prop))),
have x_mono : ∀ n : ℕ, s (x n.succ) ⊆ s (x n) :=
λ n, subset.trans (hs.set_index_subset _) (inter_subset_right _ _),
replace x_mono : ∀ ⦃i j⦄, i ≤ j → s (x j) ≤ s (x i),
{ refine @monotone_of_monotone_nat (order_dual $ set α) _ _ _,
exact x_mono },
have x_subset : ∀ i, s (x i) ⊆ x' i,
{ rintro (_|i),
exacts [hs.set_index_subset _, subset.trans (hs.set_index_subset _) (inter_subset_left _ _)] },
refine ⟨λ i, x i, λ i, (x i).2, _⟩,
have : (⨅ i, 𝓟 (s (x i))).has_antimono_basis (λ _, true) (λ i, s (x i)) :=
⟨has_basis_infi_principal (directed_of_sup x_mono), λ i j _ _ hij, x_mono hij, monotone_const⟩,
convert this,
exact le_antisymm (le_infi $ λ i, le_principal_iff.2 $ by cases i; apply hs.set_index_mem)
(hx'.symm ▸ le_infi (λ i, le_principal_iff.2 $
this.to_has_basis.mem_iff.2 ⟨i, trivial, x_subset i⟩))
end
/-- A countably generated filter admits a basis formed by a monotonically decreasing sequence of
sets. -/
lemma exists_antimono_basis {f : filter α} (cblb : f.is_countably_generated) :
∃ x : ℕ → set α, f.has_antimono_basis (λ _, true) x :=
let ⟨x, hxf, hx⟩ := cblb.exists_antimono_subbasis f.basis_sets in ⟨x, hx⟩
end is_countably_generated
lemma has_countable_basis.is_countably_generated {f : filter α} {p : ι → Prop} {s : ι → set α}
(h : f.has_countable_basis p s) :
f.is_countably_generated :=
⟨{t | ∃ i, p i ∧ s i = t}, h.countable.image s, h.to_has_basis.eq_generate⟩
lemma is_countably_generated_seq (x : ℕ → set α) : is_countably_generated (⨅ i, 𝓟 $ x i) :=
begin
rcases antimono_seq_of_seq x with ⟨y, am, h⟩,
rw h,
use [range y, countable_range _],
rw (has_basis_infi_principal _).eq_generate,
{ simp [range] },
{ exact directed_of_sup am },
{ use 0 },
end
lemma is_countably_generated_of_seq {f : filter α} (h : ∃ x : ℕ → set α, f = ⨅ i, 𝓟 $ x i) :
f.is_countably_generated :=
let ⟨x, h⟩ := h in by rw h ; apply is_countably_generated_seq
lemma is_countably_generated_binfi_principal {B : set $ set α} (h : countable B) :
is_countably_generated (⨅ (s ∈ B), 𝓟 s) :=
is_countably_generated_of_seq (countable_binfi_principal_eq_seq_infi h)
lemma is_countably_generated_iff_exists_antimono_basis {f : filter α} :
is_countably_generated f ↔ ∃ x : ℕ → set α, f.has_antimono_basis (λ _, true) x :=
begin
split,
{ exact λ h, h.exists_antimono_basis },
{ rintros ⟨x, h⟩,
rw h.to_has_basis.eq_infi,
exact is_countably_generated_seq x },
end
lemma is_countably_generated_principal (s : set α) : is_countably_generated (𝓟 s) :=
begin
rw show 𝓟 s = ⨅ i : ℕ, 𝓟 s, by simp,
apply is_countably_generated_seq
end
namespace is_countably_generated
lemma inf {f g : filter α} (hf : is_countably_generated f) (hg : is_countably_generated g) :
is_countably_generated (f ⊓ g) :=
begin
rw is_countably_generated_iff_exists_antimono_basis at hf hg,
rcases hf with ⟨s, hs⟩,
rcases hg with ⟨t, ht⟩,
exact has_countable_basis.is_countably_generated
⟨hs.to_has_basis.inf ht.to_has_basis, set.countable_encodable _⟩
end
lemma inf_principal {f : filter α} (h : is_countably_generated f) (s : set α) :
is_countably_generated (f ⊓ 𝓟 s) :=
h.inf (filter.is_countably_generated_principal s)
lemma exists_antimono_seq' {f : filter α} (cblb : f.is_countably_generated) :
∃ x : ℕ → set α, (∀ i j, i ≤ j → x j ⊆ x i) ∧ ∀ {s}, (s ∈ f ↔ ∃ i, x i ⊆ s) :=
let ⟨x, hx⟩ := is_countably_generated_iff_exists_antimono_basis.mp cblb in
⟨x, λ i j, hx.decreasing trivial trivial, λ s, by simp [hx.to_has_basis.mem_iff]⟩
protected lemma comap {l : filter β} (h : l.is_countably_generated) (f : α → β) :
(comap f l).is_countably_generated :=
let ⟨x, hx_mono⟩ := h.exists_antimono_basis in
is_countably_generated_of_seq ⟨_, (hx_mono.to_has_basis.comap _).eq_infi⟩
end is_countably_generated
end filter
|
0b11ac47c84eadfa48316e69014a859888f8bdab | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/inductive_pred.lean | 19ef52b70a522ae4dc6f20e830d428ec18289474 | [
"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 | 3,941 | lean | import Lean
open Lean
namespace Ex
inductive LE : Nat → Nat → Prop
| refl : LE n n
| succ : LE n m → LE n m.succ
def typeOf {α : Sort u} (a : α) := α
theorem LE.trans' : LE m n → LE n o → LE m o
| h1, refl => h1
| h1, succ h2 => succ (trans' h1 h2) -- the structural recursion in being performed on the implicit `Nat` parameter
inductive Even : Nat → Prop
| zero : Even 0
| ss : Even n → Even n.succ.succ
theorem Even_brecOn : typeOf @Even.brecOn = ∀ {motive : (a : Nat) → Even a → Prop} {a : Nat} (x : Even a),
(∀ (a : Nat) (x : Even a), @Even.below motive a x → motive a x) → motive a x := rfl
theorem Even.add : Even n → Even m → Even (n+m) := by
intro h1 h2
induction h2 with
| zero => exact h1
| ss h2 ih => exact ss ih
theorem Even.add' : Even n → Even m → Even (n+m)
| h1, zero => h1
| h1, ss h2 => ss (add' h1 h2) -- the structural recursion in being performed on the implicit `Nat` parameter
theorem mul_left_comm (n m o : Nat) : n * (m * o) = m * (n * o) := by
rw [← Nat.mul_assoc, Nat.mul_comm n m, Nat.mul_assoc]
inductive Power2 : Nat → Prop
| base : Power2 1
| ind : Power2 n → Power2 (2*n) -- Note that index here is not a constructor
theorem Power2_brecOn : typeOf @Power2.brecOn = ∀ {motive : (a : Nat) → Power2 a → Prop} {a : Nat} (x : Power2 a),
(∀ (a : Nat) (x : Power2 a), @Power2.below motive a x → motive a x) → motive a x := rfl
theorem Power2.mul : Power2 n → Power2 m → Power2 (n*m) := by
intro h1 h2
induction h2 with
| base => simp_all
| ind h2 ih => exact mul_left_comm .. ▸ ind ih
/- The following example fails because the structural recursion cannot be performed on the `Nat`s and
the `brecOn` construction doesn't work for inductive predicates -/
set_option trace.Elab.definition.structural true in
set_option trace.Meta.IndPredBelow.match true in
set_option pp.explicit true in
theorem Power2.mul' : Power2 n → Power2 m → Power2 (n*m)
| h1, base => by simp_all
| h1, ind h2 => mul_left_comm .. ▸ ind (mul' h1 h2)
inductive tm : Type :=
| C : Nat → tm
| P : tm → tm → tm
open tm
set_option hygiene false in
infixl:40 " ==> " => step
inductive step : tm → tm → Prop :=
| ST_PlusConstConst : ∀ n1 n2,
P (C n1) (C n2) ==> C (n1 + n2)
| ST_Plus1 : ∀ t1 t1' t2,
t1 ==> t1' →
P t1 t2 ==> P t1' t2
| ST_Plus2 : ∀ n1 t2 t2',
t2 ==> t2' →
P (C n1) t2 ==> P (C n1) t2'
def deterministic {X : Type} (R : X → X → Prop) :=
∀ x y1 y2 : X, R x y1 → R x y2 → y1 = y2
theorem step_deterministic' : deterministic step := λ x y₁ y₂ hy₁ hy₂ =>
@step.brecOn (λ s t st => ∀ y₂, s ==> y₂ → t = y₂) _ _ hy₁ (λ s t st hy₁ y₂ hy₂ =>
match hy₁, hy₂ with
| step.below.ST_PlusConstConst _ _, step.ST_PlusConstConst _ _ => rfl
| step.below.ST_Plus1 _ _ _ hy₁ ih, step.ST_Plus1 _ t₁' _ _ => by rw [←ih t₁']; assumption
| step.below.ST_Plus1 _ _ _ hy₁ ih, step.ST_Plus2 _ _ _ _ => by cases hy₁
| step.below.ST_Plus2 _ _ _ _ ih, step.ST_Plus2 _ _ t₂ _ => by rw [←ih t₂]; assumption
| step.below.ST_Plus2 _ _ _ hy₁ _, step.ST_PlusConstConst _ _ => by cases hy₁
) y₂ hy₂
section NestedRecursion
axiom f : Nat → Nat
inductive is_nat : Nat -> Prop
| Z : is_nat 0
| S {n} : is_nat n → is_nat (f n)
axiom P : Nat → Prop
axiom F0 : P 0
axiom F1 : P (f 0)
axiom FS {n : Nat} : P n → P (f (f n))
-- we would like to write this
theorem foo : ∀ {n}, is_nat n → P n
| _, is_nat.Z => F0
| _, is_nat.S is_nat.Z => F1
| _, is_nat.S (is_nat.S h) => FS (foo h)
theorem foo' : ∀ {n}, is_nat n → P n := fun h =>
@is_nat.brecOn (fun n hn => P n) _ h fun n h ih =>
match ih with
| is_nat.below.Z => F0
| is_nat.below.S is_nat.below.Z _ => F1
| is_nat.below.S (is_nat.below.S b hx) h₂ => FS hx
end NestedRecursion
end Ex
|
98ba395e77177aa1e377cb261585150e74c2f407 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/topology/algebra/field.lean | f394d0115f4f0e020aadf0815c8c8be85a68f116 | [
"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 | 4,518 | lean | /-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Scott Morrison
-/
import topology.algebra.ring
import topology.algebra.group_with_zero
/-!
# Topological fields
A topological division ring is a topological ring whose inversion function is continuous at every
non-zero element.
-/
namespace topological_ring
open topological_space function
variables (R : Type*) [semiring R]
variables [topological_space R]
/-- The induced topology on units of a topological semiring.
This is not a global instance since other topologies could be relevant. Instead there is a class
`induced_units` asserting that something equivalent to this construction holds. -/
def topological_space_units : topological_space Rˣ := induced (coe : Rˣ → R) ‹_›
/-- Asserts the topology on units is the induced topology.
Note: this is not always the correct topology.
Another good candidate is the subspace topology of $R \times R$,
with the units embedded via $u \mapsto (u, u^{-1})$.
These topologies are not (propositionally) equal in general. -/
class induced_units [t : topological_space $ Rˣ] : Prop :=
(top_eq : t = induced (coe : Rˣ → R) ‹_›)
variables [topological_space $ Rˣ]
lemma units_topology_eq [induced_units R] :
‹topological_space Rˣ› = induced (coe : Rˣ → R) ‹_› :=
induced_units.top_eq
lemma induced_units.continuous_coe [induced_units R] : continuous (coe : Rˣ → R) :=
(units_topology_eq R).symm ▸ continuous_induced_dom
lemma units_embedding [induced_units R] :
embedding (coe : Rˣ → R) :=
{ induced := units_topology_eq R,
inj := λ x y h, units.ext h }
instance top_monoid_units [topological_semiring R] [induced_units R] :
has_continuous_mul Rˣ :=
⟨begin
let mulR := (λ (p : R × R), p.1*p.2),
let mulRx := (λ (p : Rˣ × Rˣ), p.1*p.2),
have key : coe ∘ mulRx = mulR ∘ (λ p, (p.1.val, p.2.val)), from rfl,
rw [continuous_iff_le_induced, units_topology_eq R, prod_induced_induced,
induced_compose, key, ← induced_compose],
apply induced_mono,
rw ← continuous_iff_le_induced,
exact continuous_mul,
end⟩
end topological_ring
variables (K : Type*) [division_ring K] [topological_space K]
/-- A topological division ring is a division ring with a topology where all operations are
continuous, including inversion. -/
class topological_division_ring extends topological_ring K, has_continuous_inv₀ K : Prop
namespace topological_division_ring
open filter set
/-!
In this section, we show that units of a topological division ring endowed with the
induced topology form a topological group. These are not global instances because
one could want another topology on units. To turn on this feature, use:
```lean
local attribute [instance]
topological_semiring.topological_space_units topological_division_ring.units_top_group
```
-/
local attribute [instance] topological_ring.topological_space_units
@[priority 100] instance induced_units : topological_ring.induced_units K := ⟨rfl⟩
variables [topological_division_ring K]
lemma units_top_group : topological_group Kˣ :=
{ continuous_inv := begin
rw continuous_iff_continuous_at,
intros x,
rw [continuous_at, nhds_induced, nhds_induced, tendsto_iff_comap,
←function.semiconj.filter_comap units.coe_inv _],
apply comap_mono,
rw [← tendsto_iff_comap, units.coe_inv],
exact continuous_at_inv₀ x.ne_zero
end,
..topological_ring.top_monoid_units K}
local attribute [instance] units_top_group
lemma continuous_units_inv : continuous (λ x : Kˣ, (↑(x⁻¹) : K)) :=
(topological_ring.induced_units.continuous_coe K).comp continuous_inv
end topological_division_ring
section affine_homeomorph
/-!
This section is about affine homeomorphisms from a topological field `𝕜` to itself.
Technically it does not require `𝕜` to be a topological field, a topological ring that
happens to be a field is enough.
-/
variables {𝕜 : Type*} [field 𝕜] [topological_space 𝕜] [topological_ring 𝕜]
/--
The map `λ x, a * x + b`, as a homeomorphism from `𝕜` (a topological field) to itself, when `a ≠ 0`.
-/
@[simps]
def affine_homeomorph (a b : 𝕜) (h : a ≠ 0) : 𝕜 ≃ₜ 𝕜 :=
{ to_fun := λ x, a * x + b,
inv_fun := λ y, (y - b) / a,
left_inv := λ x, by { simp only [add_sub_cancel], exact mul_div_cancel_left x h, },
right_inv := λ y, by { simp [mul_div_cancel' _ h], }, }
end affine_homeomorph
|
98eca398aa3f1b7af1f88a74801a5037fe8e9bb6 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tmp/new-frontend/parser/trie.lean | 16b4baad8aae09408efe55b42d79c8e0f347e118 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 3,507 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich, Leonardo de Moura
Trie for tokenizing the Lean language
-/
prelude
import init.data.rbmap
import init.lean.format init.lean.parser.parsec
namespace Lean
namespace Parser
inductive Trie (α : Type)
| Node : Option α → RBNode Char (λ _, Trie) → Trie
namespace Trie
variables {α : Type}
def empty : Trie α :=
⟨none, RBNode.leaf⟩
instance : HasEmptyc (Trie α) :=
⟨empty⟩
instance : Inhabited (Trie α) :=
⟨Node none RBNode.leaf⟩
private partial def insertEmptyAux (s : String) (val : α) : String.Pos → Trie α
| i := match s.atEnd i with
| true := Trie.Node (some val) RBNode.leaf
| false :=
let c := s.get i in
let t := insertEmptyAux (s.next i) in
Trie.Node none (RBNode.singleton c t)
private partial def insertAux (s : String) (val : α) : Trie α → String.Pos → Trie α
| (Trie.Node v m) i :=
match s.atEnd i with
| true := Trie.Node (some val) m -- overrides old value
| false :=
let c := s.get i in
let i := s.next i in
let t := match RBNode.find Char.lt m c with
| none := insertEmptyAux s val i
| some t := insertAux t i in
Trie.Node v (RBNode.insert Char.lt m c t)
def insert (t : Trie α) (s : String) (val : α) : Trie α :=
insertAux s val t 0
private partial def findAux (s : String) : Trie α → String.Pos → Option α
| (Trie.Node val m) i :=
match s.atEnd i with
| true := val
| false :=
let c := s.get i in
let i := s.next i in
match RBNode.find Char.lt m c with
| none := none
| some t := findAux t i
def find (t : Trie α) (s : String) : Option α :=
findAux s t 0
private def updtAcc (v : Option α) (i : String.Pos) (acc : String.Pos × Option α) : String.Pos × Option α :=
match v, acc with
| some v, (j, w) := (i, some v) -- we pattern match on `acc` to enable memory reuse
| none, acc := acc
private partial def matchPrefixAux (s : String) : Trie α → String.Pos → (String.Pos × Option α) → String.Pos × Option α
| (Trie.Node v m) i acc :=
match s.atEnd i with
| true := updtAcc v i acc
| false :=
let acc := updtAcc v i acc in
let c := s.get i in
let i := s.next i in
match RBNode.find Char.lt m c with
| some t := matchPrefixAux t i acc
| none := acc
def matchPrefix (s : String) (t : Trie α) (i : String.Pos) : String.Pos × Option α :=
matchPrefixAux s t i (i, none)
-- TODO: delete
private def oldMatchPrefixAux : Nat → Trie α → String.OldIterator → Option (String.OldIterator × α) → Option (String.OldIterator × α)
| 0 (Trie.Node val map) it Acc := Prod.mk it <$> val <|> Acc
| (n+1) (Trie.Node val map) it Acc :=
let Acc' := Prod.mk it <$> val <|> Acc in
match RBNode.find Char.lt map it.curr with
| some t := oldMatchPrefixAux n t it.next Acc'
| none := Acc'
-- TODO: delete
def oldMatchPrefix {α : Type} (t : Trie α) (it : String.OldIterator) : Option (String.OldIterator × α) :=
oldMatchPrefixAux it.remaining t it none
private partial def toStringAux {α : Type} : Trie α → List Format
| (Trie.Node val map) := map.fold (λ Fs c t,
format (repr c) :: (Format.group $ Format.nest 2 $ flip Format.joinSep Format.line $ toStringAux t) :: Fs) []
instance {α : Type} : HasToString (Trie α) :=
⟨λ t, (flip Format.joinSep Format.line $ toStringAux t).pretty⟩
end Trie
end Parser
end Lean
|
ecd8a873632d4f9cfdb7842018df365daaec2f05 | 30b012bb72d640ec30c8fdd4c45fdfa67beb012c | /ring_theory/ideals.lean | 9b9071906719662bd435ac4ddd0662d36d68834d | [
"Apache-2.0"
] | permissive | kckennylau/mathlib | 21fb810b701b10d6606d9002a4004f7672262e83 | 47b3477e20ffb5a06588dd3abb01fe0fe3205646 | refs/heads/master | 1,634,976,409,281 | 1,542,042,832,000 | 1,542,319,733,000 | 109,560,458 | 0 | 0 | Apache-2.0 | 1,542,369,208,000 | 1,509,867,494,000 | Lean | UTF-8 | Lean | false | false | 12,233 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Mario Carneiro
-/
import linear_algebra.basic ring_theory.associated order.zorn
universes u v
variables {α : Type u} {β : Type v} [comm_ring α] {a b : α}
open set function lattice
local attribute [instance] classical.prop_decidable
namespace ideal
variable (I : ideal α)
theorem eq_top_of_unit_mem
(x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ :=
eq_top_iff.2 $ λ z _, calc
z = z * (y * x) : by simp [h]
... = (z * y) * x : eq.symm $ mul_assoc z y x
... ∈ I : I.mul_mem_left hx
theorem eq_top_of_is_unit_mem {x} (hx : x ∈ I) (h : is_unit x) : I = ⊤ :=
let ⟨y, hy⟩ := is_unit_iff_exists_inv'.1 h in eq_top_of_unit_mem I x y hx hy
theorem eq_top_iff_one : I = ⊤ ↔ (1:α) ∈ I :=
⟨by rintro rfl; trivial,
λ h, eq_top_of_unit_mem _ _ 1 h (by simp)⟩
theorem ne_top_iff_one : I ≠ ⊤ ↔ (1:α) ∉ I :=
not_congr I.eq_top_iff_one
def span (s : set α) : ideal α := submodule.span s
lemma subset_span {s : set α} : s ⊆ span s := submodule.subset_span
lemma span_le {s : set α} {I} : span s ≤ I ↔ s ⊆ I := submodule.span_le
lemma span_mono {s t : set α} : s ⊆ t → span s ≤ span t := submodule.span_mono
@[simp] lemma span_eq : span (I : set α) = I := submodule.span_eq _
@[simp] lemma span_singleton_one : span ({1} : set α) = ⊤ :=
(eq_top_iff_one _).2 $ subset_span $ mem_singleton _
lemma mem_span_insert {s : set α} {x y} :
x ∈ span (insert y s) ↔ ∃ a (z ∈ span s), x = a * y + z := submodule.mem_span_insert
lemma mem_span_insert' {s : set α} {x y} :
x ∈ span (insert y s) ↔ ∃a, x + a * y ∈ span s := submodule.mem_span_insert'
lemma mem_span_singleton' {x y : α} :
x ∈ span ({y} : set α) ↔ ∃ a, a * y = x := submodule.mem_span_singleton
lemma mem_span_singleton {x y : α} :
x ∈ span ({y} : set α) ↔ y ∣ x :=
mem_span_singleton'.trans $ exists_congr $ λ _, by rw [eq_comm, mul_comm]; refl
lemma span_singleton_le_span_singleton {x y : α} :
span ({x} : set α) ≤ span ({y} : set α) ↔ y ∣ x :=
span_le.trans $ singleton_subset_iff.trans mem_span_singleton
lemma span_eq_bot {s : set α} : span s = ⊥ ↔ ∀ x ∈ s, (x:α) = 0 := submodule.span_eq_bot
lemma span_singleton_eq_bot {x} : span ({x} : set α) = ⊥ ↔ x = 0 := submodule.span_singleton_eq_bot
lemma span_singleton_eq_top {x} : span ({x} : set α) = ⊤ ↔ is_unit x :=
by rw [is_unit_iff_dvd_one, ← span_singleton_le_span_singleton, span_singleton_one, eq_top_iff]
@[class] def is_prime (I : ideal α) : Prop :=
I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I
theorem is_prime.mem_or_mem {I : ideal α} (hI : I.is_prime) :
∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I := hI.2
theorem is_prime.mem_or_mem_of_mul_eq_zero {I : ideal α} (hI : I.is_prime)
{x y : α} (h : x * y = 0) : x ∈ I ∨ y ∈ I :=
hI.2 (h.symm ▸ I.zero_mem)
theorem is_prime.mem_of_pow_mem {I : ideal α} (hI : I.is_prime)
{r : α} (n : ℕ) (H : r^n ∈ I) : r ∈ I :=
begin
induction n with n ih,
{ exact (mt (eq_top_iff_one _).2 hI.1).elim H },
exact or.cases_on (hI.mem_or_mem H) id ih
end
@[class] def zero_ne_one_of_proper {I : ideal α} (h : I ≠ ⊤) : (0:α) ≠ 1 :=
λ hz, I.ne_top_iff_one.1 h $ hz ▸ I.zero_mem
theorem span_singleton_prime {p : α} (hp : p ≠ 0) :
is_prime (span ({p} : set α)) ↔ prime p :=
by simp [is_prime, prime, span_singleton_eq_top, hp, mem_span_singleton]
@[class] def is_maximal (I : ideal α) : Prop :=
I ≠ ⊤ ∧ ∀ J, I < J → J = ⊤
theorem is_maximal_iff {I : ideal α} : I.is_maximal ↔
(1:α) ∉ I ∧ ∀ (J : ideal α) x, I ≤ J → x ∉ I → x ∈ J → (1:α) ∈ J :=
and_congr I.ne_top_iff_one $ forall_congr $ λ J,
by rw [lt_iff_le_not_le]; exact
⟨λ H x h hx₁ hx₂, J.eq_top_iff_one.1 $
H ⟨h, not_subset.2 ⟨_, hx₂, hx₁⟩⟩,
λ H ⟨h₁, h₂⟩, let ⟨x, xJ, xI⟩ := not_subset.1 h₂ in
J.eq_top_iff_one.2 $ H x h₁ xI xJ⟩
theorem is_maximal.eq_of_le {I J : ideal α}
(hI : I.is_maximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J :=
eq_iff_le_not_lt.2 ⟨IJ, λ h, hJ (hI.2 _ h)⟩
theorem is_maximal.exists_inv {I : ideal α}
(hI : I.is_maximal) {x} (hx : x ∉ I) : ∃ y, y * x - 1 ∈ I :=
begin
cases is_maximal_iff.1 hI with H₁ H₂,
rcases mem_span_insert'.1 (H₂ (span (insert x I)) x
(set.subset.trans (subset_insert _ _) subset_span)
hx (subset_span (mem_insert _ _))) with ⟨y, hy⟩,
rw [span_eq, ← neg_mem_iff, add_comm, neg_add', neg_mul_eq_neg_mul] at hy,
exact ⟨-y, hy⟩
end
theorem is_maximal.is_prime {I : ideal α} (H : I.is_maximal) : I.is_prime :=
⟨H.1, λ x y hxy, or_iff_not_imp_left.2 $ λ hx, begin
cases H.exists_inv hx with z hz,
have := I.mul_mem_left hz,
rw [mul_sub, mul_one, mul_comm, mul_assoc] at this,
exact I.neg_mem_iff.1 ((I.add_mem_iff_right $ I.mul_mem_left hxy).1 this)
end⟩
instance is_maximal.is_prime' (I : ideal α) : ∀ [H : I.is_maximal], I.is_prime := is_maximal.is_prime
theorem exists_le_maximal (I : ideal α) (hI : I ≠ ⊤) :
∃ M : ideal α, M.is_maximal ∧ I ≤ M :=
begin
rcases zorn.zorn_partial_order₀ { J : ideal α | J ≠ ⊤ } _ I hI with ⟨M, M0, IM, h⟩,
{ refine ⟨M, ⟨M0, λ J hJ, by_contradiction $ λ J0, _⟩, IM⟩,
cases h J J0 (le_of_lt hJ), exact lt_irrefl _ hJ },
{ intros S SC cC I IS,
refine ⟨Sup S, λ H, _, λ _, le_Sup⟩,
rcases submodule.mem_Sup_of_directed ((eq_top_iff_one _).1 H) I IS cC.directed_on with ⟨J, JS, J0⟩,
exact SC JS ((eq_top_iff_one _).2 J0) }
end
end ideal
def nonunits (α : Type u) [monoid α] : set α := { x | ¬is_unit x }
@[simp] theorem mem_nonunits_iff {α} [comm_monoid α] {x} : x ∈ nonunits α ↔ ¬ is_unit x := iff.rfl
theorem mul_mem_nonunits_right {α} [comm_monoid α]
{x y : α} : y ∈ nonunits α → x * y ∈ nonunits α :=
mt is_unit_of_mul_is_unit_right
theorem mul_mem_nonunits_left {α} [comm_monoid α]
{x y : α} : x ∈ nonunits α → x * y ∈ nonunits α :=
mt is_unit_of_mul_is_unit_left
theorem zero_mem_nonunits {α} [semiring α] : 0 ∈ nonunits α ↔ (0:α) ≠ 1 :=
not_congr is_unit_zero_iff
theorem one_not_mem_nonunits {α} [monoid α] : (1:α) ∉ nonunits α :=
not_not_intro is_unit_one
theorem coe_subset_nonunits {I : ideal α} (h : I ≠ ⊤) :
(I : set α) ⊆ nonunits α :=
λ x hx hu, h $ I.eq_top_of_is_unit_mem hx hu
@[class] def is_local_ring (α : Type u) [comm_ring α] : Prop :=
∃! I : ideal α, I.is_maximal
@[class] def is_local_ring.zero_ne_one (h : is_local_ring α) : (0:α) ≠ 1 :=
let ⟨I, ⟨hI, _⟩, _⟩ := h in ideal.zero_ne_one_of_proper hI
def nonunits_ideal (h : is_local_ring α) : ideal α :=
{ carrier := nonunits α,
zero := zero_mem_nonunits.2 h.zero_ne_one,
add := begin
rcases id h with ⟨M, mM, hM⟩,
have : ∀ x ∈ nonunits α, x ∈ M,
{ intros x hx,
rcases (ideal.span {x} : ideal α).exists_le_maximal _ with ⟨N, mN, hN⟩,
{ cases hM N mN,
rwa [ideal.span_le, singleton_subset_iff] at hN },
{ exact mt ideal.span_singleton_eq_top.1 hx } },
intros x y hx hy,
exact coe_subset_nonunits mM.1 (M.add_mem (this _ hx) (this _ hy))
end,
smul := λ a x, mul_mem_nonunits_right }
@[simp] theorem mem_nonunits_ideal (h : is_local_ring α) {x} :
x ∈ nonunits_ideal h ↔ x ∈ nonunits α := iff.rfl
theorem local_of_nonunits_ideal (hnze : (0:α) ≠ 1)
(h : ∀ x y ∈ nonunits α, x + y ∈ nonunits α) : is_local_ring α :=
begin
letI NU : ideal α := ⟨nonunits α,
zero_mem_nonunits.2 hnze, h, λ a x, mul_mem_nonunits_right⟩,
have NU1 := NU.ne_top_iff_one.2 one_not_mem_nonunits,
exact ⟨NU, ⟨NU1,
λ J hJ, not_not.1 $ λ J0, not_le_of_gt hJ (coe_subset_nonunits J0)⟩,
λ J mJ, mJ.eq_of_le NU1 (coe_subset_nonunits mJ.1)⟩,
end
namespace ideal
open ideal
def quotient (I : ideal α) := I.quotient
namespace quotient
variables {I : ideal α} {x y : α}
def mk (I : ideal α) (a : α) : I.quotient := submodule.quotient.mk a
protected theorem eq : mk I x = mk I y ↔ x - y ∈ I := submodule.quotient.eq I
instance (I : ideal α) : has_one I.quotient := ⟨mk I 1⟩
@[simp] lemma mk_one (I : ideal α) : mk I 1 = 1 := rfl
instance (I : ideal α) : has_mul I.quotient :=
⟨λ a b, quotient.lift_on₂' a b (λ a b, mk I (a * b)) $
λ a₁ a₂ b₁ b₂ h₁ h₂, quot.sound $ begin
refine calc a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ : _
... ∈ I : I.add_mem (I.mul_mem_left h₁) (I.mul_mem_right h₂),
rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁]
end⟩
@[simp] theorem mk_mul : mk I (x * y) = mk I x * mk I y := rfl
instance (I : ideal α) : comm_ring I.quotient :=
{ mul := (*),
one := 1,
mul_assoc := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg (mk _) (mul_assoc a b c),
mul_comm := λ a b, quotient.induction_on₂' a b $
λ a b, congr_arg (mk _) (mul_comm a b),
one_mul := λ a, quotient.induction_on' a $
λ a, congr_arg (mk _) (one_mul a),
mul_one := λ a, quotient.induction_on' a $
λ a, congr_arg (mk _) (mul_one a),
left_distrib := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg (mk _) (left_distrib a b c),
right_distrib := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg (mk _) (right_distrib a b c),
..submodule.quotient.add_comm_group I }
instance is_ring_hom_mk (I : ideal α) : is_ring_hom (mk I) :=
⟨rfl, λ _ _, rfl, λ _ _, rfl⟩
def map_mk (I J : ideal α) : ideal I.quotient :=
{ carrier := mk I '' J,
zero := ⟨0, J.zero_mem, rfl⟩,
add := by rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩;
exact ⟨x + y, J.add_mem hx hy, rfl⟩,
smul := by rintro ⟨c⟩ _ ⟨x, hx, rfl⟩;
exact ⟨c * x, J.mul_mem_left hx, rfl⟩ }
@[simp] lemma mk_zero (I : ideal α) : mk I 0 = 0 := rfl
@[simp] lemma mk_add (I : ideal α) (a b : α) : mk I (a + b) = mk I a + mk I b := rfl
@[simp] lemma mk_neg (I : ideal α) (a : α) : mk I (-a : α) = -mk I a := rfl
@[simp] lemma mk_sub (I : ideal α) (a b : α) : mk I (a - b : α) = mk I a - mk I b := rfl
@[simp] lemma mk_pow (I : ideal α) (a : α) (n : ℕ) : mk I (a ^ n : α) = mk I a ^ n :=
by induction n; simp [*, pow_succ]
lemma eq_zero_iff_mem {I : ideal α} : mk I a = 0 ↔ a ∈ I :=
by conv {to_rhs, rw ← sub_zero a }; exact quotient.eq'
theorem zero_eq_one_iff {I : ideal α} : (0 : I.quotient) = 1 ↔ I = ⊤ :=
eq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm
theorem zero_ne_one_iff {I : ideal α} : (0 : I.quotient) ≠ 1 ↔ I ≠ ⊤ :=
not_congr zero_eq_one_iff
protected def nonzero_comm_ring {I : ideal α} (hI : I ≠ ⊤) : nonzero_comm_ring I.quotient :=
{ zero_ne_one := zero_ne_one_iff.2 hI, ..quotient.comm_ring I }
instance (I : ideal α) [hI : I.is_prime] : integral_domain I.quotient :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b,
quotient.induction_on₂' a b $ λ a b hab,
(hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim
(or.inl ∘ eq_zero_iff_mem.2)
(or.inr ∘ eq_zero_iff_mem.2),
..quotient.nonzero_comm_ring hI.1 }
lemma exists_inv {I : ideal α} [hI : I.is_maximal] :
∀ {a : I.quotient}, a ≠ 0 → ∃ b : I.quotient, a * b = 1 :=
begin
rintro ⟨a⟩ h,
cases hI.exists_inv (mt eq_zero_iff_mem.2 h) with b hb,
rw [mul_comm] at hb,
exact ⟨mk _ b, quot.sound hb⟩
end
/-- quotient by maximal ideal is a field. def rather than instance, since users will have
computable inverses in some applications -/
protected noncomputable def field (I : ideal α) [hI : I.is_maximal] : field I.quotient :=
{ inv := λ a, if ha : a = 0 then 0 else classical.some (exists_inv ha),
mul_inv_cancel := λ a (ha : a ≠ 0), show a * dite _ _ _ = _,
by rw dif_neg ha;
exact classical.some_spec (exists_inv ha),
inv_mul_cancel := λ a (ha : a ≠ 0), show dite _ _ _ * a = _,
by rw [mul_comm, dif_neg ha];
exact classical.some_spec (exists_inv ha),
..quotient.integral_domain I }
end quotient
end ideal
|
88bd03db4c46fc66f7809d8ab12ad363b861e7d4 | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /tests/lean/run/blast_cc5.lean | b7b0c9b46f13b5feb26f8431cfc261c844b606c8 | [
"Apache-2.0"
] | permissive | YHVHvx/lean | 732bf0fb7a298cd7fe0f15d82f8e248c11db49e9 | 038369533e0136dd395dc252084d3c1853accbf2 | refs/heads/master | 1,610,701,080,210 | 1,449,128,595,000 | 1,449,128,595,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 608 | lean | set_option blast.simp false
set_option blast.subst false
example (a b c : Prop) : (a ↔ b) → ((a ∧ (c ∨ b)) ↔ (b ∧ (c ∨ a))) :=
by blast
example (a b c : Prop) : (a ↔ b) → ((a ∧ (c ∨ (b ↔ a))) ↔ (b ∧ (c ∨ (a ↔ b)))) :=
by blast
example (a₁ a₂ b₁ b₂ : Prop) : (a₁ ↔ b₁) → (a₂ ↔ b₂) → (a₁ ∧ a₂ ∧ a₁ ∧ a₂ ↔ b₁ ∧ b₂ ∧ b₁ ∧ b₂) :=
by blast
definition lemma1 (a₁ a₂ b₁ b₂ : Prop) : (a₁ = b₁) → (a₂ ↔ b₂) → (a₁ ∧ a₂ ∧ a₁ ∧ a₂ ↔ b₁ ∧ b₂ ∧ b₁ ∧ b₂) :=
by blast
print lemma1
|
bfa92ba04fff5ae0da526785265e28881a335e44 | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/print_ax3.lean | 1c36701678c25f4e206c1967ae6e3095b879495d | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 308 | lean | theorem foo1 : 0 = (0:num) :=
rfl
theorem foo2 : 0 = (0:num) :=
rfl
theorem foo3 : 0 = (0:num) :=
foo2
definition foo4 : 0 = (0:num) :=
eq.trans foo2 foo1
lemma foo5 : true = false :=
propext sorry
print axioms foo4
print "------"
print axioms
print "------"
print foo3
print "------"
print axioms foo5
|
905ca7e4bf1915ae617a429b1644e525029bcb4b | 94e33a31faa76775069b071adea97e86e218a8ee | /src/order/compare.lean | 5dd03daff8d5c6474e9b50a83852d143d4a4f111 | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 8,239 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import order.synonym
/-!
# Comparison
This file provides basic results about orderings and comparison in linear orders.
## Definitions
* `cmp_le`: An `ordering` from `≤`.
* `ordering.compares`: Turns an `ordering` into `<` and `=` propositions.
* `linear_order_of_compares`: Constructs a `linear_order` instance from the fact that any two
elements that are not one strictly less than the other either way are equal.
-/
variables {α : Type*}
/-- Like `cmp`, but uses a `≤` on the type instead of `<`. Given two elements `x` and `y`, returns a
three-way comparison result `ordering`. -/
def cmp_le {α} [has_le α] [@decidable_rel α (≤)] (x y : α) : ordering :=
if x ≤ y then
if y ≤ x then ordering.eq else ordering.lt
else ordering.gt
lemma cmp_le_swap {α} [has_le α] [is_total α (≤)] [@decidable_rel α (≤)] (x y : α) :
(cmp_le x y).swap = cmp_le y x :=
begin
by_cases xy : x ≤ y; by_cases yx : y ≤ x; simp [cmp_le, *, ordering.swap],
cases not_or xy yx (total_of _ _ _)
end
lemma cmp_le_eq_cmp {α} [preorder α] [is_total α (≤)]
[@decidable_rel α (≤)] [@decidable_rel α (<)] (x y : α) : cmp_le x y = cmp x y :=
begin
by_cases xy : x ≤ y; by_cases yx : y ≤ x;
simp [cmp_le, lt_iff_le_not_le, *, cmp, cmp_using],
cases not_or xy yx (total_of _ _ _)
end
namespace ordering
/-- `compares o a b` means that `a` and `b` have the ordering relation `o` between them, assuming
that the relation `a < b` is defined. -/
@[simp] def compares [has_lt α] : ordering → α → α → Prop
| lt a b := a < b
| eq a b := a = b
| gt a b := a > b
lemma compares_swap [has_lt α] {a b : α} {o : ordering} :
o.swap.compares a b ↔ o.compares b a :=
by { cases o, exacts [iff.rfl, eq_comm, iff.rfl] }
alias compares_swap ↔ compares.of_swap compares.swap
lemma swap_eq_iff_eq_swap {o o' : ordering} : o.swap = o' ↔ o = o'.swap :=
⟨λ h, by rw [← swap_swap o, h], λ h, by rw [← swap_swap o', h]⟩
lemma compares.eq_lt [preorder α] :
∀ {o} {a b : α}, compares o a b → (o = lt ↔ a < b)
| lt a b h := ⟨λ _, h, λ _, rfl⟩
| eq a b h := ⟨λ h, by injection h, λ h', (ne_of_lt h' h).elim⟩
| gt a b h := ⟨λ h, by injection h, λ h', (lt_asymm h h').elim⟩
lemma compares.ne_lt [preorder α] :
∀ {o} {a b : α}, compares o a b → (o ≠ lt ↔ b ≤ a)
| lt a b h := ⟨absurd rfl, λ h', (not_le_of_lt h h').elim⟩
| eq a b h := ⟨λ _, ge_of_eq h, λ _ h, by injection h⟩
| gt a b h := ⟨λ _, le_of_lt h, λ _ h, by injection h⟩
lemma compares.eq_eq [preorder α] :
∀ {o} {a b : α}, compares o a b → (o = eq ↔ a = b)
| lt a b h := ⟨λ h, by injection h, λ h', (ne_of_lt h h').elim⟩
| eq a b h := ⟨λ _, h, λ _, rfl⟩
| gt a b h := ⟨λ h, by injection h, λ h', (ne_of_gt h h').elim⟩
lemma compares.eq_gt [preorder α] {o} {a b : α} (h : compares o a b) : (o = gt ↔ b < a) :=
swap_eq_iff_eq_swap.symm.trans h.swap.eq_lt
lemma compares.ne_gt [preorder α] {o} {a b : α} (h : compares o a b) : (o ≠ gt ↔ a ≤ b) :=
(not_congr swap_eq_iff_eq_swap.symm).trans h.swap.ne_lt
lemma compares.le_total [preorder α] {a b : α} :
∀ {o}, compares o a b → a ≤ b ∨ b ≤ a
| lt h := or.inl (le_of_lt h)
| eq h := or.inl (le_of_eq h)
| gt h := or.inr (le_of_lt h)
lemma compares.le_antisymm [preorder α] {a b : α} :
∀ {o}, compares o a b → a ≤ b → b ≤ a → a = b
| lt h _ hba := (not_le_of_lt h hba).elim
| eq h _ _ := h
| gt h hab _ := (not_le_of_lt h hab).elim
lemma compares.inj [preorder α] {o₁} :
∀ {o₂} {a b : α}, compares o₁ a b → compares o₂ a b → o₁ = o₂
| lt a b h₁ h₂ := h₁.eq_lt.2 h₂
| eq a b h₁ h₂ := h₁.eq_eq.2 h₂
| gt a b h₁ h₂ := h₁.eq_gt.2 h₂
lemma compares_iff_of_compares_impl {β : Type*} [linear_order α] [preorder β] {a b : α}
{a' b' : β} (h : ∀ {o}, compares o a b → compares o a' b') (o) :
compares o a b ↔ compares o a' b' :=
begin
refine ⟨h, λ ho, _⟩,
cases lt_trichotomy a b with hab hab,
{ change compares ordering.lt a b at hab,
rwa [ho.inj (h hab)] },
{ cases hab with hab hab,
{ change compares ordering.eq a b at hab,
rwa [ho.inj (h hab)] },
{ change compares ordering.gt a b at hab,
rwa [ho.inj (h hab)] } }
end
lemma swap_or_else (o₁ o₂) : (or_else o₁ o₂).swap = or_else o₁.swap o₂.swap :=
by cases o₁; try {refl}; cases o₂; refl
lemma or_else_eq_lt (o₁ o₂) : or_else o₁ o₂ = lt ↔ o₁ = lt ∨ (o₁ = eq ∧ o₂ = lt) :=
by cases o₁; cases o₂; exact dec_trivial
end ordering
open ordering order_dual
@[simp] lemma to_dual_compares_to_dual [has_lt α] {a b : α} {o : ordering} :
compares o (to_dual a) (to_dual b) ↔ compares o b a :=
by { cases o, exacts [iff.rfl, eq_comm, iff.rfl] }
@[simp] lemma of_dual_compares_of_dual [has_lt α] {a b : αᵒᵈ} {o : ordering} :
compares o (of_dual a) (of_dual b) ↔ compares o b a :=
by { cases o, exacts [iff.rfl, eq_comm, iff.rfl] }
lemma cmp_compares [linear_order α] (a b : α) : (cmp a b).compares a b :=
by obtain h | h | h := lt_trichotomy a b; simp [cmp, cmp_using, h, h.not_lt]
lemma ordering.compares.cmp_eq [linear_order α] {a b : α} {o : ordering} (h : o.compares a b) :
cmp a b = o :=
(cmp_compares a b).inj h
lemma cmp_swap [preorder α] [@decidable_rel α (<)] (a b : α) : (cmp a b).swap = cmp b a :=
begin
unfold cmp cmp_using,
by_cases a < b; by_cases h₂ : b < a; simp [h, h₂, ordering.swap],
exact lt_asymm h h₂
end
@[simp] lemma cmp_le_to_dual [has_le α] [@decidable_rel α (≤)] (x y : α) :
cmp_le (to_dual x) (to_dual y) = cmp_le y x := rfl
@[simp] lemma cmp_le_of_dual [has_le α] [@decidable_rel α (≤)] (x y : αᵒᵈ) :
cmp_le (of_dual x) (of_dual y) = cmp_le y x := rfl
@[simp] lemma cmp_to_dual [has_lt α] [@decidable_rel α (<)] (x y : α) :
cmp (to_dual x) (to_dual y) = cmp y x := rfl
@[simp] lemma cmp_of_dual [has_lt α] [@decidable_rel α (<)] (x y : αᵒᵈ) :
cmp (of_dual x) (of_dual y) = cmp y x := rfl
/-- Generate a linear order structure from a preorder and `cmp` function. -/
def linear_order_of_compares [preorder α] (cmp : α → α → ordering)
(h : ∀ a b, (cmp a b).compares a b) :
linear_order α :=
{ le_antisymm := λ a b, (h a b).le_antisymm,
le_total := λ a b, (h a b).le_total,
decidable_le := λ a b, decidable_of_iff _ (h a b).ne_gt,
decidable_lt := λ a b, decidable_of_iff _ (h a b).eq_lt,
decidable_eq := λ a b, decidable_of_iff _ (h a b).eq_eq,
.. ‹preorder α› }
variables [linear_order α] (x y : α)
@[simp] lemma cmp_eq_lt_iff : cmp x y = ordering.lt ↔ x < y :=
ordering.compares.eq_lt (cmp_compares x y)
@[simp] lemma cmp_eq_eq_iff : cmp x y = ordering.eq ↔ x = y :=
ordering.compares.eq_eq (cmp_compares x y)
@[simp] lemma cmp_eq_gt_iff : cmp x y = ordering.gt ↔ y < x :=
ordering.compares.eq_gt (cmp_compares x y)
@[simp] lemma cmp_self_eq_eq : cmp x x = ordering.eq :=
by rw cmp_eq_eq_iff
variables {x y} {β : Type*} [linear_order β] {x' y' : β}
lemma cmp_eq_cmp_symm : cmp x y = cmp x' y' ↔ cmp y x = cmp y' x' :=
by { split, rw [←cmp_swap _ y, ←cmp_swap _ y'], cc,
rw [←cmp_swap _ x, ←cmp_swap _ x'], cc, }
lemma lt_iff_lt_of_cmp_eq_cmp (h : cmp x y = cmp x' y') : x < y ↔ x' < y' :=
by rw [←cmp_eq_lt_iff, ←cmp_eq_lt_iff, h]
lemma le_iff_le_of_cmp_eq_cmp (h : cmp x y = cmp x' y') : x ≤ y ↔ x' ≤ y' :=
by { rw [←not_lt, ←not_lt], apply not_congr,
apply lt_iff_lt_of_cmp_eq_cmp, rwa cmp_eq_cmp_symm }
lemma eq_iff_eq_of_cmp_eq_cmp (h : cmp x y = cmp x' y') : x = y ↔ x' = y' :=
by rw [le_antisymm_iff, le_antisymm_iff, le_iff_le_of_cmp_eq_cmp h,
le_iff_le_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 h)]
lemma has_lt.lt.cmp_eq_lt (h : x < y) : cmp x y = ordering.lt := (cmp_eq_lt_iff _ _).2 h
lemma has_lt.lt.cmp_eq_gt (h : x < y) : cmp y x = ordering.gt := (cmp_eq_gt_iff _ _).2 h
lemma eq.cmp_eq_eq (h : x = y) : cmp x y = ordering.eq := (cmp_eq_eq_iff _ _).2 h
lemma eq.cmp_eq_eq' (h : x = y) : cmp y x = ordering.eq := h.symm.cmp_eq_eq
|
a3a4680bb4303b9cade595b7f09ac96389a3cf4d | de91c42b87530c3bdcc2b138ef1a3c3d9bee0d41 | /old/expressions/boolean_test.lean | 1d49a113d65bf8d760b908936b6650e1cc945c06 | [] | no_license | kevinsullivan/lang | d3e526ba363dc1ddf5ff1c2f36607d7f891806a7 | e9d869bff94fb13ad9262222a6f3c4aafba82d5e | refs/heads/master | 1,687,840,064,795 | 1,628,047,969,000 | 1,628,047,969,000 | 282,210,749 | 0 | 1 | null | 1,608,153,830,000 | 1,595,592,637,000 | Lean | UTF-8 | Lean | false | false | 177 | lean | import .boolean
def init_benv : benv := λ v, ff
def myFirstProg := bCmd.bAssm (bvar.mk 0) (bExpr.BLit ff)
def newEnv := cEval init_benv myFirstProg
#eval newEnv (bvar.mk 0) |
2eaa764fb7c5c49748db3c4757aafa1630aaf7fd | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/topology/connected.lean | 6b12847670692f6087c5ae72995c484a131f2691 | [
"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 | 40,077 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import topology.subset_properties
/-!
# Connected subsets of topological spaces
In this file we define connected subsets of a topological spaces and various other properties and
classes related to connectivity.
## Main definitions
We define the following properties for sets in a topological space:
* `is_connected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
* `connected_component` is the connected component of an element in the space.
* `is_totally_disconnected`: all of its connected components are singletons.
* `is_totally_separated`: any two points can be separated by two disjoint opens that cover the set.
For each of these definitions, we also have a class stating that the whole space
satisfies that property:
`connected_space`, `totally_disconnected_space`, `totally_separated_space`.
## On the definition of connected sets/spaces
In informal mathematics, connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption as `is_preconnected`.
In other words, the only difference is whether the empty space counts as connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open set classical topological_space
open_locale classical topological_space
universes u v
variables {α : Type u} {β : Type v} [topological_space α] {s t : set α}
section preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def is_preconnected (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def is_connected (s : set α) : Prop :=
s.nonempty ∧ is_preconnected s
lemma is_connected.nonempty {s : set α} (h : is_connected s) :
s.nonempty := h.1
lemma is_connected.is_preconnected {s : set α} (h : is_connected s) :
is_preconnected s := h.2
theorem is_preirreducible.is_preconnected {s : set α} (H : is_preirreducible s) :
is_preconnected s :=
λ _ _ hu hv _, H _ _ hu hv
theorem is_irreducible.is_connected {s : set α} (H : is_irreducible s) : is_connected s :=
⟨H.nonempty, H.is_preirreducible.is_preconnected⟩
theorem is_preconnected_empty : is_preconnected (∅ : set α) :=
is_preirreducible_empty.is_preconnected
theorem is_connected_singleton {x} : is_connected ({x} : set α) :=
is_irreducible_singleton.is_connected
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall {s : set α} (x : α)
(H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩,
have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt },
wlog xu : x ∈ u := hs xs using [u v y z, v u z y],
rcases H y ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall_pair {s : set α}
(H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
rcases H x y xs ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem is_preconnected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, is_preconnected s) : is_preconnected (⋃₀ c) :=
begin
apply is_preconnected_of_forall x,
rintros y ⟨s, sc, ys⟩,
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
end
theorem is_preconnected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t)
(H3 : is_preconnected s) (H4 : is_preconnected t) : is_preconnected (s ∪ t) :=
sUnion_pair s t ▸ is_preconnected_sUnion x {s, t}
(by rintro r (rfl | rfl | h); assumption)
(by rintro r (rfl | rfl | h); assumption)
theorem is_connected.union {s t : set α} (H : (s ∩ t).nonempty)
(Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) :=
begin
rcases H with ⟨x, hx⟩,
refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, _⟩,
exact is_preconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx)
Hs.is_preconnected Ht.is_preconnected
end
theorem is_preconnected.closure {s : set α} (H : is_preconnected s) :
is_preconnected (closure s) :=
λ u v hu hv hcsuv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in
let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in
let ⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans subset_closure hcsuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
theorem is_connected.closure {s : set α} (H : is_connected s) :
is_connected (closure s) :=
⟨H.nonempty.closure, H.is_preconnected.closure⟩
theorem is_preconnected.image [topological_space β] {s : set α} (H : is_preconnected s)
(f : α → β) (hf : continuous_on f s) : is_preconnected (f '' s) :=
begin
-- Unfold/destruct definitions in hypotheses
rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
-- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'`
replace huv : s ⊆ u' ∪ v',
{ rw [image_subset_iff, preimage_union] at huv,
replace huv := subset_inter huv (subset.refl _),
rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv,
exact (subset_inter_iff.1 huv).1 },
-- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_preconnected s›`
obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty,
{ refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm,
exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] },
rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc,
inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz,
exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩
end
theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s)
(f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preconnected.image f hf⟩
theorem is_preconnected_closed_iff {s : set α} :
is_preconnected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' →
(s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty :=
⟨begin
rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h',
have xt' : x ∉ t', from (h' xs).elim (absurd xt) id,
have yt : y ∉ t, from (h' ys).elim id (absurd yt'),
have := ne_empty_iff_nonempty.2 (h tᶜ t'ᶜ (is_open_compl_iff.2 ht)
(is_open_compl_iff.2 ht') h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end,
begin
rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not,
← subset_compl_iff_disjoint, compl_inter] at h',
have xv : x ∉ v, from (h' xs).elim (absurd xu) id,
have yu : y ∉ u, from (h' ys).elim id (absurd yv),
have := ne_empty_iff_nonempty.2 (h uᶜ vᶜ (is_closed_compl_iff.2 hu)
(is_closed_compl_iff.2 hv) h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end⟩
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component (x : α) : set α :=
⋃₀ { s : set α | is_preconnected s ∧ x ∈ s }
/-- The connected component of a point inside a set. -/
def connected_component_in (F : set α) (x : F) : set α := coe '' (connected_component x)
theorem mem_connected_component {x : α} : x ∈ connected_component x :=
mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton.is_preconnected, mem_singleton x⟩
theorem is_preconnected_connected_component {x : α} : is_preconnected (connected_component x) :=
is_preconnected_sUnion x _ (λ _, and.right) (λ _, and.left)
theorem is_connected_connected_component {x : α} : is_connected (connected_component x) :=
⟨⟨x, mem_connected_component⟩, is_preconnected_connected_component⟩
theorem is_preconnected.subset_connected_component {x : α} {s : set α}
(H1 : is_preconnected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩
theorem is_connected.subset_connected_component {x : α} {s : set α}
(H1 : is_connected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
H1.2.subset_connected_component H2
theorem connected_component_eq {x y : α} (h : y ∈ connected_component x) :
connected_component x = connected_component y :=
eq_of_subset_of_subset
(is_connected_connected_component.subset_connected_component h)
(is_connected_connected_component.subset_connected_component
(set.mem_of_mem_of_subset mem_connected_component
(is_connected_connected_component.subset_connected_component h)))
lemma connected_component_disjoint {x y : α} (h : connected_component x ≠ connected_component y) :
disjoint (connected_component x) (connected_component y) :=
set.disjoint_left.2 (λ a h1 h2, h
((connected_component_eq h1).trans (connected_component_eq h2).symm))
theorem is_closed_connected_component {x : α} :
is_closed (connected_component x) :=
closure_eq_iff_is_closed.1 $ subset.antisymm
(is_connected_connected_component.closure.subset_connected_component
(subset_closure mem_connected_component))
subset_closure
lemma continuous.image_connected_component_subset {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) (a : α) : f '' connected_component a ⊆ connected_component (f a) :=
(is_connected_connected_component.image f h.continuous_on).subset_connected_component
((mem_image f (connected_component a) (f a)).2 ⟨a, mem_connected_component, rfl⟩)
theorem irreducible_component_subset_connected_component {x : α} :
irreducible_component x ⊆ connected_component x :=
is_irreducible_irreducible_component.is_connected.subset_connected_component
mem_irreducible_component
/-- A preconnected space is one where there is no non-trivial open partition. -/
class preconnected_space (α : Type u) [topological_space α] : Prop :=
(is_preconnected_univ : is_preconnected (univ : set α))
export preconnected_space (is_preconnected_univ)
/-- A connected space is a nonempty one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] extends preconnected_space α : Prop :=
(to_nonempty : nonempty α)
attribute [instance, priority 50] connected_space.to_nonempty -- see Note [lower instance priority]
lemma is_connected_range [topological_space β] [connected_space α] {f : α → β} (h : continuous f) :
is_connected (range f) :=
begin
inhabit α,
rw ← image_univ,
exact ⟨⟨f (default α), mem_image_of_mem _ (mem_univ _)⟩,
is_preconnected.image is_preconnected_univ _ h.continuous_on⟩
end
lemma connected_space_iff_connected_component :
connected_space α ↔ ∃ x : α, connected_component x = univ :=
begin
split,
{ rintros ⟨h, ⟨x⟩⟩,
exactI ⟨x, eq_univ_of_univ_subset $
is_preconnected_univ.subset_connected_component (mem_univ x)⟩ },
{ rintros ⟨x, h⟩,
haveI : preconnected_space α := ⟨by { rw ← h, exact is_preconnected_connected_component }⟩,
exact ⟨⟨x⟩⟩ }
end
@[priority 100] -- see Note [lower instance priority]
instance preirreducible_space.preconnected_space (α : Type u) [topological_space α]
[preirreducible_space α] : preconnected_space α :=
⟨(preirreducible_space.is_preirreducible_univ α).is_preconnected⟩
@[priority 100] -- see Note [lower instance priority]
instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
{ to_nonempty := irreducible_space.to_nonempty α }
theorem nonempty_inter [preconnected_space α] {s t : set α} :
is_open s → is_open t → s ∪ t = univ → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preconnected_space.is_preconnected_univ α _ _ s t
theorem is_clopen_iff [preconnected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ :=
⟨λ hs, classical.by_contradiction $ λ h,
have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅, from ⟨mt or.inl h,
mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩,
let ⟨_, h2, h3⟩ := nonempty_inter hs.1 hs.2.is_open_compl (union_compl_self s)
(ne_empty_iff_nonempty.1 h1.1) (ne_empty_iff_nonempty.1 h1.2) in
h3 h2,
by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩
lemma eq_univ_of_nonempty_clopen [preconnected_space α] {s : set α}
(h : s.nonempty) (h' : is_clopen s) : s = univ :=
by { rw is_clopen_iff at h', finish [h.ne_empty] }
lemma subtype.preconnected_space {s : set α} (h : is_preconnected s) :
preconnected_space s :=
{ is_preconnected_univ :=
begin
intros u v hu hv hs hsu hsv,
rw is_open_induced_iff at hu hv,
rcases hu with ⟨u, hu, rfl⟩,
rcases hv with ⟨v, hv, rfl⟩,
rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩,
rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩,
rcases h u v hu hv _ ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩,
exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩,
intros z hz,
rcases hs (mem_univ ⟨z, hz⟩) with hzu|hzv,
{ left, assumption },
{ right, assumption }
end }
lemma subtype.connected_space {s : set α} (h : is_connected s) :
connected_space s :=
{ is_preconnected_univ :=
(subtype.preconnected_space h.is_preconnected).is_preconnected_univ,
to_nonempty := h.nonempty.to_subtype }
lemma is_preconnected_iff_preconnected_space {s : set α} :
is_preconnected s ↔ preconnected_space s :=
⟨subtype.preconnected_space,
begin
introI,
simpa using is_preconnected_univ.image (coe : s → α) continuous_subtype_coe.continuous_on
end⟩
lemma is_connected_iff_connected_space {s : set α} : is_connected s ↔ connected_space s :=
⟨subtype.connected_space,
λ h, ⟨nonempty_subtype.mp h.2, is_preconnected_iff_preconnected_space.mpr h.1⟩⟩
/-- A set `s` is preconnected if and only if
for every cover by two open sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
lemma is_preconnected_iff_subset_of_disjoint {s : set α} :
is_preconnected s ↔
∀ (u v : set α) (hu : is_open u) (hv : is_open v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A set `s` is connected if and only if
for every cover by a finite collection of open sets that are pairwise disjoint on `s`,
it is contained in one of the members of the collection. -/
lemma is_connected_iff_sUnion_disjoint_open {s : set α} :
is_connected s ↔
∀ (U : finset (set α)) (H : ∀ (u v : set α), u ∈ U → v ∈ U → (s ∩ (u ∩ v)).nonempty → u = v)
(hU : ∀ u ∈ U, is_open u) (hs : s ⊆ ⋃₀ ↑U),
∃ u ∈ U, s ⊆ u :=
begin
rw [is_connected, is_preconnected_iff_subset_of_disjoint],
split; intro h,
{ intro U, apply finset.induction_on U,
{ rcases h.left,
suffices : s ⊆ ∅ → false, { simpa },
intro, solve_by_elim },
{ intros u U hu IH hs hU H,
rw [finset.coe_insert, sUnion_insert] at H,
cases h.2 u (⋃₀ ↑U) _ _ H _ with hsu hsU,
{ exact ⟨u, finset.mem_insert_self _ _, hsu⟩ },
{ rcases IH _ _ hsU with ⟨v, hvU, hsv⟩,
{ exact ⟨v, finset.mem_insert_of_mem hvU, hsv⟩ },
{ intros, apply hs; solve_by_elim [finset.mem_insert_of_mem] },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sUnion,
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ apply eq_empty_of_subset_empty,
rintro x ⟨hxs, hxu, hxU⟩,
rw mem_sUnion at hxU,
rcases hxU with ⟨v, hvU, hxv⟩,
rcases hs u v (finset.mem_insert_self _ _) (finset.mem_insert_of_mem hvU) _ with rfl,
{ contradiction },
{ exact ⟨x, hxs, hxu, hxv⟩ } } } },
{ split,
{ rw ← ne_empty_iff_nonempty,
by_contradiction hs, push_neg at hs, subst hs,
simpa using h ∅ _ _ _; simp },
intros u v hu hv hs hsuv,
rcases h {u, v} _ _ _ with ⟨t, ht, ht'⟩,
{ rw [finset.mem_insert, finset.mem_singleton] at ht,
rcases ht with rfl|rfl; tauto },
{ intros t₁ t₂ ht₁ ht₂ hst,
rw ← ne_empty_iff_nonempty at hst,
rw [finset.mem_insert, finset.mem_singleton] at ht₁ ht₂,
rcases ht₁ with rfl|rfl; rcases ht₂ with rfl|rfl,
all_goals { refl <|> contradiction <|> skip },
rw inter_comm t₁ at hst, contradiction },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using hs } }
end
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem subset_or_disjoint_of_clopen {α : Type*} [topological_space α] {s t : set α}
(h : is_preconnected t) (h1 : is_clopen s) : s ∩ t = ∅ ∨ t ⊆ s :=
begin
by_contradiction h2,
have h3 : (s ∩ t).nonempty := ne_empty_iff_nonempty.mp (mt or.inl h2),
have h4 : (t ∩ sᶜ).nonempty,
{ apply inter_compl_nonempty_iff.2,
push_neg at h2,
exact h2.2 },
rw [inter_comm] at h3,
apply ne_empty_iff_nonempty.2 (h s sᶜ h1.1 (is_open_compl_iff.2 h1.2) _ h3 h4),
{ rw [inter_compl_self, inter_empty] },
{ rw [union_compl_self],
exact subset_univ t },
end
/-- A set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_disjoint_closed {α : Type*} {s : set α}
[topological_space α] :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
rw is_preconnected_closed_iff at h,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ rw is_preconnected_closed_iff,
intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A closed set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_fully_disjoint_closed {s : set α} (hs : is_closed s) :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hss : s ⊆ u ∪ v) (huv : u ∩ v = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split,
{ intros h u v hu hv hss huv,
apply is_preconnected_iff_subset_of_disjoint_closed.1 h u v hu hv hss,
rw huv,
exact inter_empty s },
intro H,
rw is_preconnected_iff_subset_of_disjoint_closed,
intros u v hu hv hss huv,
have H1 := H (u ∩ s) (v ∩ s),
rw [subset_inter_iff, subset_inter_iff] at H1,
simp only [subset.refl, and_true] at H1,
apply H1 (is_closed.inter hu hs) (is_closed.inter hv hs),
{ rw ←inter_distrib_right,
apply subset_inter_iff.2,
exact ⟨hss, subset.refl s⟩ },
{ rw [inter_comm v s, inter_assoc, ←inter_assoc s, inter_self s,
inter_comm, inter_assoc, inter_comm v u, huv] }
end
/-- The connected component of a point is always a subset of the intersection of all its clopen
neighbourhoods. -/
lemma connected_component_subset_Inter_clopen {x : α} :
connected_component x ⊆ ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z :=
begin
apply subset_Inter (λ Z, _),
cases (subset_or_disjoint_of_clopen (@is_connected_connected_component _ _ x).2 Z.2.1),
{ exfalso,
apply nonempty.ne_empty
(nonempty_of_mem (mem_inter (@mem_connected_component _ _ x) Z.2.2)),
rw inter_comm,
exact h },
exact h,
end
/-- A clopen set is the union of its connected components. -/
lemma is_clopen.eq_union_connected_components {Z : set α} (h : is_clopen Z) :
Z = (⋃ (x : α) (H : x ∈ Z), connected_component x) :=
eq_of_subset_of_subset (λ x xZ, mem_Union.2 ⟨x, mem_Union.2 ⟨xZ, mem_connected_component⟩⟩)
(Union_subset $ λ x, Union_subset $ λ xZ,
(by { apply subset.trans connected_component_subset_Inter_clopen
(Inter_subset _ ⟨Z, ⟨h, xZ⟩⟩) }))
/-- The preimage of a connected component is preconnected if the function has connected fibers
and a subset is closed iff the preimage is. -/
lemma preimage_connected_component_connected {β : Type*} [topological_space β] {f : α → β}
(connected_fibers : ∀ t : β, is_connected (f ⁻¹' {t}))
(hcl : ∀ (T : set β), is_closed T ↔ is_closed (f ⁻¹' T)) (t : β) :
is_connected (f ⁻¹' connected_component t) :=
begin
-- The following proof is essentially https://stacks.math.columbia.edu/tag/0377
-- although the statement is slightly different
have hf : function.surjective f := function.surjective.of_comp (λ t : β, (connected_fibers t).1),
split,
{ cases hf t with s hs,
use s,
rw [mem_preimage, hs],
exact mem_connected_component },
have hT : is_closed (f ⁻¹' connected_component t) :=
(hcl (connected_component t)).1 is_closed_connected_component,
-- To show it's preconnected we decompose (f ⁻¹' connected_component t) as a subset of two
-- closed disjoint sets in α. We want to show that it's a subset of either.
rw is_preconnected_iff_subset_of_fully_disjoint_closed hT,
intros u v hu hv huv uv_disj,
-- To do this we decompose connected_component t into T₁ and T₂
-- we will show that connected_component t is a subset of either and hence
-- (f ⁻¹' connected_component t) is a subset of u or v
let T₁ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ u},
let T₂ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ v},
have fiber_decomp : ∀ t' ∈ connected_component t, f ⁻¹' {t'} ⊆ u ∨ f ⁻¹' {t'} ⊆ v,
{ intros t' ht',
apply is_preconnected_iff_subset_of_disjoint_closed.1 (connected_fibers t').2 u v hu hv,
{ exact subset.trans (hf.preimage_subset_preimage_iff.2 (singleton_subset_iff.2 ht')) huv },
rw uv_disj,
exact inter_empty _ },
have T₁_u : f ⁻¹' T₁ = (f ⁻¹' connected_component t) ∩ u,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine bUnion_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hau⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ exact h },
{ exfalso,
rw ←not_nonempty_iff_eq_empty at uv_disj,
exact uv_disj (nonempty_of_mem (mem_inter hau (h rfl))) } },
-- This proof is exactly the same as the above (modulo some symmetry)
have T₂_v : f ⁻¹' T₂ = (f ⁻¹' connected_component t) ∩ v,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine bUnion_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hav⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ exfalso,
rw ←not_nonempty_iff_eq_empty at uv_disj,
exact uv_disj (nonempty_of_mem (mem_inter (h rfl) hav)) },
{ exact h } },
-- Now we show T₁, T₂ are closed, cover connected_component t and are disjoint.
have hT₁ : is_closed T₁ := ((hcl T₁).2 (T₁_u.symm ▸ (is_closed.inter hT hu))),
have hT₂ : is_closed T₂ := ((hcl T₂).2 (T₂_v.symm ▸ (is_closed.inter hT hv))),
have T_decomp : connected_component t ⊆ T₁ ∪ T₂,
{ intros t' ht',
rw mem_union t' T₁ T₂,
cases fiber_decomp t' ht' with htu htv,
{ left, exact ⟨ht', htu⟩ },
right, exact ⟨ht', htv⟩ },
have T_disjoint : T₁ ∩ T₂ = ∅,
{ rw ←image_preimage_eq (T₁ ∩ T₂) hf,
suffices : f ⁻¹' (T₁ ∩ T₂) = ∅,
{ rw this, exact image_empty _ },
rw [preimage_inter, T₁_u, T₂_v],
rw inter_comm at uv_disj,
conv
{ congr,
rw [inter_assoc],
congr, skip,
rw [←inter_assoc, inter_comm, ←inter_assoc, uv_disj, empty_inter], },
exact inter_empty _ },
-- Now we do cases on whether (connected_component t) is a subset of T₁ or T₂ to show
-- that the preimage is a subset of u or v.
cases (is_preconnected_iff_subset_of_fully_disjoint_closed is_closed_connected_component).1
is_preconnected_connected_component T₁ T₂ hT₁ hT₂ T_decomp T_disjoint,
{ left,
rw subset.antisymm_iff at T₁_u,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₁,
{ exact subset.trans (subset.trans this T₁_u.1) (inter_subset_right _ _) },
exact preimage_mono h },
right,
rw subset.antisymm_iff at T₂_v,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₂,
{ exact subset.trans (subset.trans this T₂_v.1) (inter_subset_right _ _) },
exact preimage_mono h,
end
end preconnected
section totally_disconnected
/-- A set `s` is called totally disconnected if every subset `t ⊆ s` which is preconnected is
a subsingleton, ie either empty or a singleton.-/
def is_totally_disconnected (s : set α) : Prop :=
∀ t, t ⊆ s → is_preconnected t → t.subsingleton
theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) :=
λ _ ht _ _ x_in _ _, (ht x_in).elim
theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) :=
λ _ ht _, subsingleton.mono subsingleton_singleton ht
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] : Prop :=
(is_totally_disconnected_univ : is_totally_disconnected (univ : set α))
lemma is_preconnected.subsingleton [totally_disconnected_space α]
{s : set α} (h : is_preconnected s) : s.subsingleton :=
totally_disconnected_space.is_totally_disconnected_univ s (subset_univ s) h
instance pi.totally_disconnected_space {α : Type*} {β : α → Type*}
[t₂ : Πa, topological_space (β a)] [∀a, totally_disconnected_space (β a)] :
totally_disconnected_space (Π (a : α), β a) :=
⟨λ t h1 h2,
have this : ∀ a, is_preconnected ((λ x : Π a, β a, x a) '' t),
from λ a, h2.image (λ x, x a) (continuous_apply a).continuous_on,
λ x x_in y y_in, funext $ λ a, (this a).subsingleton ⟨x, x_in, rfl⟩ ⟨y, y_in, rfl⟩⟩
/-- A space is totally disconnected iff its connected components are subsingletons. -/
lemma totally_disconnected_space_iff_connected_component_subsingleton :
totally_disconnected_space α ↔ ∀ x : α, (connected_component x).subsingleton :=
begin
split,
{ intros h x,
apply h.1,
{ exact subset_univ _ },
exact is_preconnected_connected_component },
intro h, constructor,
intros s s_sub hs,
rcases eq_empty_or_nonempty s with rfl | ⟨x, x_in⟩,
{ exact subsingleton_empty },
{ exact (h x).mono (hs.subset_connected_component x_in) }
end
/-- A space is totally disconnected iff its connected components are singletons. -/
lemma totally_disconnected_space_iff_connected_component_singleton :
totally_disconnected_space α ↔ ∀ x : α, connected_component x = {x} :=
begin
rw totally_disconnected_space_iff_connected_component_subsingleton,
apply forall_congr (λ x, _),
rw set.subsingleton_iff_singleton,
exact mem_connected_component
end
/-- The image of a connected component in a totally disconnected space is a singleton. -/
@[simp] lemma continuous.image_connected_component_eq_singleton {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) (a : α) :
f '' connected_component a = {f a} :=
(set.subsingleton_iff_singleton $ mem_image_of_mem f mem_connected_component).mp
(is_preconnected_connected_component.image f h.continuous_on).subsingleton
lemma is_totally_disconnected_of_totally_disconnected_space [totally_disconnected_space α]
(s : set α) : is_totally_disconnected s :=
λ t hts ht, totally_disconnected_space.is_totally_disconnected_univ _ t.subset_univ ht
lemma is_totally_disconnected_of_image [topological_space β] {f : α → β} (hf : continuous_on f s)
(hf' : function.injective f) (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s :=
λ t hts ht x x_in y y_in, hf' $ h _ (image_subset f hts) (ht.image f $ hf.mono hts)
(mem_image_of_mem f x_in) (mem_image_of_mem f y_in)
lemma embedding.is_totally_disconnected [topological_space β] {f : α → β} (hf : embedding f)
{s : set α} (h : is_totally_disconnected (f '' s)) : is_totally_disconnected s :=
is_totally_disconnected_of_image hf.continuous.continuous_on hf.inj h
instance subtype.totally_disconnected_space {α : Type*} {p : α → Prop} [topological_space α]
[totally_disconnected_space α] : totally_disconnected_space (subtype p) :=
⟨embedding_subtype_coe.is_totally_disconnected
(is_totally_disconnected_of_totally_disconnected_space _)⟩
end totally_disconnected
section totally_separated
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated (s : set α) : Prop :=
∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧
x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ u ∩ v = ∅
theorem is_totally_separated_empty : is_totally_separated (∅ : set α) :=
λ x, false.elim
theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) :=
λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim
theorem is_totally_disconnected_of_is_totally_separated {s : set α}
(H : is_totally_separated s) : is_totally_disconnected s :=
begin
intros t hts ht x x_in y y_in,
by_contra h,
obtain ⟨u : set α, v : set α, hu : is_open u, hv : is_open v,
hxu : x ∈ u, hyv : y ∈ v, hs : s ⊆ u ∪ v, huv : u ∩ v = ∅⟩ :=
H x (hts x_in) y (hts y_in) h,
have : (t ∩ u).nonempty → (t ∩ v).nonempty → (t ∩ (u ∩ v)).nonempty :=
ht _ _ hu hv (subset.trans hts hs),
obtain ⟨z, hz : z ∈ t ∩ (u ∩ v)⟩ := this ⟨x, x_in, hxu⟩ ⟨y, y_in, hyv⟩,
simpa [huv] using hz
end
alias is_totally_disconnected_of_is_totally_separated ← is_totally_separated.is_totally_disconnected
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] : Prop :=
(is_totally_separated_univ [] : is_totally_separated (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α]
[totally_separated_space α] : totally_disconnected_space α :=
⟨is_totally_disconnected_of_is_totally_separated $
totally_separated_space.is_totally_separated_univ α⟩
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.of_discrete
(α : Type*) [topological_space α] [discrete_topology α] : totally_separated_space α :=
⟨λ a _ b _ h, ⟨{b}ᶜ, {b}, is_open_discrete _, is_open_discrete _, by simpa⟩⟩
end totally_separated
section connected_component_setoid
/-- The setoid of connected components of a topological space -/
def connected_component_setoid (α : Type*) [topological_space α] : setoid α :=
⟨λ x y, connected_component x = connected_component y,
⟨λ x, by trivial, λ x y h1, h1.symm, λ x y z h1 h2, h1.trans h2⟩⟩
-- see Note [lower instance priority]
local attribute [instance, priority 100] connected_component_setoid
lemma connected_component_rel_iff {x y : α} : ⟦x⟧ = ⟦y⟧ ↔
connected_component x = connected_component y :=
⟨λ h, quotient.exact h, λ h, quotient.sound h⟩
lemma connected_component_nrel_iff {x y : α} : ⟦x⟧ ≠ ⟦y⟧ ↔
connected_component x ≠ connected_component y :=
by { rw not_iff_not, exact connected_component_rel_iff }
/-- The quotient of a space by its connected components -/
def connected_components (α : Type u) [topological_space α] :=
quotient (connected_component_setoid α)
instance [inhabited α] : inhabited (connected_components α) := ⟨quotient.mk (default _)⟩
instance connected_components.topological_space : topological_space (connected_components α) :=
quotient.topological_space
lemma continuous.image_eq_of_equiv {β : Type*} [topological_space β] [totally_disconnected_space β]
{f : α → β} (h : continuous f) (a b : α) (hab : a ≈ b) : f a = f b :=
singleton_eq_singleton_iff.1 $
h.image_connected_component_eq_singleton a ▸
h.image_connected_component_eq_singleton b ▸ hab ▸ rfl
/--
The lift to `connected_components α` of a continuous map from `α` to a totally disconnected space
-/
def continuous.connected_components_lift {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) : connected_components α → β :=
quotient.lift f h.image_eq_of_equiv
@[continuity] lemma continuous.connected_components_lift_continuous {β : Type*}
[topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) :
continuous h.connected_components_lift :=
continuous_quotient_lift h.image_eq_of_equiv h
@[simp] lemma continuous.connected_components_lift_factors {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) :
h.connected_components_lift ∘ quotient.mk = f := rfl
lemma continuous.connected_components_lift_unique {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) (g : connected_components α → β)
(hg : g ∘ quotient.mk = f) : g = h.connected_components_lift :=
by { subst hg, ext1 x, exact quotient.induction_on x (λ a, refl _) }
lemma connected_components_lift_unique' {β : Type*} (g₁ : connected_components α → β)
(g₂ : connected_components α → β) (hg : g₁ ∘ quotient.mk = g₂ ∘ quotient.mk ) : g₁ = g₂ :=
begin
ext1 x,
refine quotient.induction_on x (λ a, _),
change (g₁ ∘ quotient.mk) a = (g₂ ∘ quotient.mk) a,
rw hg,
end
/-- The preimage of a singleton in `connected_components` is the connected component
of an element in the equivalence class. -/
lemma connected_components_preimage_singleton {t : α} :
connected_component t = quotient.mk ⁻¹' {⟦t⟧} :=
begin
apply set.eq_of_subset_of_subset; intros a ha,
{ have H : ⟦a⟧ = ⟦t⟧ := quotient.sound (connected_component_eq ha).symm,
rw [mem_preimage, H],
exact mem_singleton ⟦t⟧ },
rw [mem_preimage, mem_singleton_iff] at ha,
have ha' : connected_component a = connected_component t := quotient.exact ha,
rw ←ha',
exact mem_connected_component,
end
/-- The preimage of the image of a set under the quotient map to `connected_components α`
is the union of the connected components of the elements in it. -/
lemma connected_components_preimage_image (U : set α) :
quotient.mk ⁻¹' (quotient.mk '' U) = ⋃ (x : α) (h : x ∈ U), connected_component x :=
begin
apply set.eq_of_subset_of_subset,
{ rintros a ⟨b, hb, hab⟩,
refine mem_Union.2 ⟨b, mem_Union.2 ⟨hb, _⟩⟩,
rw connected_component_rel_iff.1 hab,
exact mem_connected_component },
refine Union_subset (λ a, Union_subset (λ ha, _)),
rw [connected_components_preimage_singleton,
(surjective_quotient_mk _).preimage_subset_preimage_iff, singleton_subset_iff],
exact ⟨a, ha, refl _⟩,
end
instance connected_components.totally_disconnected_space :
totally_disconnected_space (connected_components α) :=
begin
rw totally_disconnected_space_iff_connected_component_singleton,
refine λ x, quotient.induction_on x (λ a, _),
apply eq_of_subset_of_subset _ (singleton_subset_iff.2 mem_connected_component),
rw subset_singleton_iff,
refine λ x, quotient.induction_on x (λ b hb, _),
rw [connected_component_rel_iff, connected_component_eq],
suffices : is_preconnected (quotient.mk ⁻¹' connected_component ⟦a⟧),
{ apply mem_of_subset_of_mem (this.subset_connected_component hb),
exact mem_preimage.2 mem_connected_component },
apply (@preimage_connected_component_connected _ _ _ _ _ _ _ _).2,
{ refine λ t, quotient.induction_on t (λ s, _),
rw ←connected_components_preimage_singleton,
exact is_connected_connected_component },
refine λ T, ⟨λ hT, hT.preimage continuous_quotient_mk, λ hT, _⟩,
rwa [← is_open_compl_iff, ← preimage_compl, quotient_map_quotient_mk.is_open_preimage,
is_open_compl_iff] at hT,
end
/-- Functoriality of `connected_components` -/
def continuous.connected_components_map {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : connected_components α → connected_components β :=
continuous.connected_components_lift (continuous_quotient_mk.comp h)
lemma continuous.connected_components_map_continuous {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : continuous h.connected_components_map :=
continuous.connected_components_lift_continuous (continuous_quotient_mk.comp h)
end connected_component_setoid
|
53a1e21062d40fd9e5937852be40c19a7ebdfebb | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/list/perm_auto.lean | bce87e74d18d7749d30e1e79e513ebeb952f235f | [] | 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 | 30,085 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.list.bag_inter
import Mathlib.data.list.erase_dup
import Mathlib.data.list.zip
import Mathlib.logic.relation
import Mathlib.data.nat.factorial
import Mathlib.PostPort
universes uu u_1 vv
namespace Mathlib
/-!
# List permutations
-/
namespace list
/-- `perm l₁ l₂` or `l₁ ~ l₂` asserts that `l₁` and `l₂` are permutations
of each other. This is defined by induction using pairwise swaps. -/
inductive perm {α : Type uu} : List α → List α → Prop where
| nil : perm [] []
| cons : ∀ (x : α) {l₁ l₂ : List α}, perm l₁ l₂ → perm (x :: l₁) (x :: l₂)
| swap : ∀ (x y : α) (l : List α), perm (y :: x :: l) (x :: y :: l)
| trans : ∀ {l₁ l₂ l₃ : List α}, perm l₁ l₂ → perm l₂ l₃ → perm l₁ l₃
infixl:50 " ~ " => Mathlib.list.perm
protected theorem perm.refl {α : Type uu} (l : List α) : l ~ l := sorry
protected theorem perm.symm {α : Type uu} {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) : l₂ ~ l₁ :=
perm.rec_on p perm.nil
(fun (x : α) (l₁ l₂ : List α) (p₁ : l₁ ~ l₂) (r₁ : l₂ ~ l₁) => perm.cons x r₁)
(fun (x y : α) (l : List α) => perm.swap y x l)
fun (l₁ l₂ l₃ : List α) (p₁ : l₁ ~ l₂) (p₂ : l₂ ~ l₃) (r₁ : l₂ ~ l₁) (r₂ : l₃ ~ l₂) =>
perm.trans r₂ r₁
theorem perm_comm {α : Type uu} {l₁ : List α} {l₂ : List α} : l₁ ~ l₂ ↔ l₂ ~ l₁ :=
{ mp := perm.symm, mpr := perm.symm }
theorem perm.swap' {α : Type uu} (x : α) (y : α) {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) :
y :: x :: l₁ ~ x :: y :: l₂ :=
perm.trans (perm.swap x y l₁) (perm.cons x (perm.cons y p))
theorem perm.eqv (α : Type u_1) : equivalence perm :=
mk_equivalence perm perm.refl perm.symm perm.trans
protected instance is_setoid (α : Type u_1) : setoid (List α) := setoid.mk perm (perm.eqv α)
theorem perm.subset {α : Type uu} {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) : l₁ ⊆ l₂ := sorry
theorem perm.mem_iff {α : Type uu} {a : α} {l₁ : List α} {l₂ : List α} (h : l₁ ~ l₂) :
a ∈ l₁ ↔ a ∈ l₂ :=
{ mp := fun (m : a ∈ l₁) => perm.subset h m,
mpr := fun (m : a ∈ l₂) => perm.subset (perm.symm h) m }
theorem perm.append_right {α : Type uu} {l₁ : List α} {l₂ : List α} (t₁ : List α) (p : l₁ ~ l₂) :
l₁ ++ t₁ ~ l₂ ++ t₁ :=
sorry
theorem perm.append_left {α : Type uu} {t₁ : List α} {t₂ : List α} (l : List α) :
t₁ ~ t₂ → l ++ t₁ ~ l ++ t₂ :=
sorry
theorem perm.append {α : Type uu} {l₁ : List α} {l₂ : List α} {t₁ : List α} {t₂ : List α}
(p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ++ t₁ ~ l₂ ++ t₂ :=
perm.trans (perm.append_right t₁ p₁) (perm.append_left l₂ p₂)
theorem perm.append_cons {α : Type uu} (a : α) {h₁ : List α} {h₂ : List α} {t₁ : List α}
{t₂ : List α} (p₁ : h₁ ~ h₂) (p₂ : t₁ ~ t₂) : h₁ ++ a :: t₁ ~ h₂ ++ a :: t₂ :=
perm.append p₁ (perm.cons a p₂)
@[simp] theorem perm_middle {α : Type uu} {a : α} {l₁ : List α} {l₂ : List α} :
l₁ ++ a :: l₂ ~ a :: (l₁ ++ l₂) :=
sorry
@[simp] theorem perm_append_singleton {α : Type uu} (a : α) (l : List α) : l ++ [a] ~ a :: l :=
perm.trans perm_middle
(eq.mpr (id (Eq._oldrec (Eq.refl (a :: (l ++ []) ~ a :: l)) (append_nil l)))
(perm.refl (a :: l)))
theorem perm_append_comm {α : Type uu} {l₁ : List α} {l₂ : List α} : l₁ ++ l₂ ~ l₂ ++ l₁ := sorry
theorem concat_perm {α : Type uu} (l : List α) (a : α) : concat l a ~ a :: l := sorry
theorem perm.length_eq {α : Type uu} {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) :
length l₁ = length l₂ :=
sorry
theorem perm.eq_nil {α : Type uu} {l : List α} (p : l ~ []) : l = [] :=
eq_nil_of_length_eq_zero (perm.length_eq p)
theorem perm.nil_eq {α : Type uu} {l : List α} (p : [] ~ l) : [] = l :=
Eq.symm (perm.eq_nil (perm.symm p))
theorem perm_nil {α : Type uu} {l₁ : List α} : l₁ ~ [] ↔ l₁ = [] :=
{ mp := fun (p : l₁ ~ []) => perm.eq_nil p, mpr := fun (e : l₁ = []) => e ▸ perm.refl l₁ }
theorem not_perm_nil_cons {α : Type uu} (x : α) (l : List α) : ¬[] ~ x :: l :=
fun (ᾰ : [] ~ x :: l) =>
idRhs (list.no_confusion_type False (x :: l) []) (list.no_confusion (perm.eq_nil (perm.symm ᾰ)))
@[simp] theorem reverse_perm {α : Type uu} (l : List α) : reverse l ~ l := sorry
theorem perm_cons_append_cons {α : Type uu} {l : List α} {l₁ : List α} {l₂ : List α} (a : α)
(p : l ~ l₁ ++ l₂) : a :: l ~ l₁ ++ a :: l₂ :=
perm.trans (perm.cons a p) (perm.symm perm_middle)
@[simp] theorem perm_repeat {α : Type uu} {a : α} {n : ℕ} {l : List α} :
l ~ repeat a n ↔ l = repeat a n :=
sorry
@[simp] theorem repeat_perm {α : Type uu} {a : α} {n : ℕ} {l : List α} :
repeat a n ~ l ↔ repeat a n = l :=
iff.trans (iff.trans perm_comm perm_repeat) eq_comm
@[simp] theorem perm_singleton {α : Type uu} {a : α} {l : List α} : l ~ [a] ↔ l = [a] := perm_repeat
@[simp] theorem singleton_perm {α : Type uu} {a : α} {l : List α} : [a] ~ l ↔ [a] = l := repeat_perm
theorem perm.eq_singleton {α : Type uu} {a : α} {l : List α} (p : l ~ [a]) : l = [a] :=
iff.mp perm_singleton p
theorem perm.singleton_eq {α : Type uu} {a : α} {l : List α} (p : [a] ~ l) : [a] = l :=
Eq.symm (perm.eq_singleton (perm.symm p))
theorem singleton_perm_singleton {α : Type uu} {a : α} {b : α} : [a] ~ [b] ↔ a = b := sorry
theorem perm_cons_erase {α : Type uu} [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
l ~ a :: list.erase l a :=
sorry
theorem perm_induction_on {α : Type uu} {P : List α → List α → Prop} {l₁ : List α} {l₂ : List α}
(p : l₁ ~ l₂) (h₁ : P [] [])
(h₂ : ∀ (x : α) (l₁ l₂ : List α), l₁ ~ l₂ → P l₁ l₂ → P (x :: l₁) (x :: l₂))
(h₃ : ∀ (x y : α) (l₁ l₂ : List α), l₁ ~ l₂ → P l₁ l₂ → P (y :: x :: l₁) (x :: y :: l₂))
(h₄ : ∀ (l₁ l₂ l₃ : List α), l₁ ~ l₂ → l₂ ~ l₃ → P l₁ l₂ → P l₂ l₃ → P l₁ l₃) : P l₁ l₂ :=
(fun (P_refl : ∀ (l : List α), P l l) =>
perm.rec_on p h₁ h₂ (fun (x y : α) (l : List α) => h₃ x y l l (perm.refl l) (P_refl l)) h₄)
fun (l : List α) =>
list.rec_on l h₁ fun (x : α) (xs : List α) (ih : P xs xs) => h₂ x xs xs (perm.refl xs) ih
theorem perm.filter_map {α : Type uu} {β : Type vv} (f : α → Option β) {l₁ : List α} {l₂ : List α}
(p : l₁ ~ l₂) : filter_map f l₁ ~ filter_map f l₂ :=
sorry
theorem perm.map {α : Type uu} {β : Type vv} (f : α → β) {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) :
map f l₁ ~ map f l₂ :=
filter_map_eq_map f ▸ perm.filter_map (some ∘ f) p
theorem perm.pmap {α : Type uu} {β : Type vv} {p : α → Prop} (f : (a : α) → p a → β) {l₁ : List α}
{l₂ : List α} :
l₁ ~ l₂ →
∀ {H₁ : ∀ (a : α), a ∈ l₁ → p a} {H₂ : ∀ (a : α), a ∈ l₂ → p a},
pmap f l₁ H₁ ~ pmap f l₂ H₂ :=
sorry
theorem perm.filter {α : Type uu} (p : α → Prop) [decidable_pred p] {l₁ : List α} {l₂ : List α}
(s : l₁ ~ l₂) : filter p l₁ ~ filter p l₂ :=
eq.mpr (id (Eq._oldrec (Eq.refl (filter p l₁ ~ filter p l₂)) (Eq.symm (filter_map_eq_filter p))))
(perm.filter_map (option.guard p) s)
theorem exists_perm_sublist {α : Type uu} {l₁ : List α} {l₂ : List α} {l₂' : List α} (s : l₁ <+ l₂)
(p : l₂ ~ l₂') : ∃ (l₁' : List α), ∃ (H : l₁' ~ l₁), l₁' <+ l₂' :=
sorry
theorem perm.sizeof_eq_sizeof {α : Type uu} [SizeOf α] {l₁ : List α} {l₂ : List α} (h : l₁ ~ l₂) :
list.sizeof l₁ = list.sizeof l₂ :=
sorry
theorem perm_comp_perm {α : Type uu} : relation.comp perm perm = perm := sorry
theorem perm_comp_forall₂ {α : Type uu} {β : Type vv} {r : α → β → Prop} {l : List α} {u : List α}
{v : List β} (hlu : l ~ u) (huv : forall₂ r u v) : relation.comp (forall₂ r) perm l v :=
sorry
theorem forall₂_comp_perm_eq_perm_comp_forall₂ {α : Type uu} {β : Type vv} {r : α → β → Prop} :
relation.comp (forall₂ r) perm = relation.comp perm (forall₂ r) :=
sorry
theorem rel_perm_imp {α : Type uu} {β : Type vv} {r : α → β → Prop} (hr : relator.right_unique r) :
relator.lift_fun (forall₂ r) (forall₂ r ⇒ implies) perm perm :=
sorry
theorem rel_perm {α : Type uu} {β : Type vv} {r : α → β → Prop} (hr : relator.bi_unique r) :
relator.lift_fun (forall₂ r) (forall₂ r ⇒ Iff) perm perm :=
sorry
/-- `subperm l₁ l₂`, denoted `l₁ <+~ l₂`, means that `l₁` is a sublist of
a permutation of `l₂`. This is an analogue of `l₁ ⊆ l₂` which respects
multiplicities of elements, and is used for the `≤` relation on multisets. -/
def subperm {α : Type uu} (l₁ : List α) (l₂ : List α) := ∃ (l : List α), ∃ (H : l ~ l₁), l <+ l₂
infixl:50 " <+~ " => Mathlib.list.subperm
theorem nil_subperm {α : Type uu} {l : List α} : [] <+~ l :=
Exists.intro []
(Exists.intro perm.nil
(eq.mpr (id (propext ((fun {α : Type uu} (l : List α) => iff_true_intro (nil_sublist l)) l)))
trivial))
theorem perm.subperm_left {α : Type uu} {l : List α} {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) :
l <+~ l₁ ↔ l <+~ l₂ :=
sorry
theorem perm.subperm_right {α : Type uu} {l₁ : List α} {l₂ : List α} {l : List α} (p : l₁ ~ l₂) :
l₁ <+~ l ↔ l₂ <+~ l :=
sorry
theorem sublist.subperm {α : Type uu} {l₁ : List α} {l₂ : List α} (s : l₁ <+ l₂) : l₁ <+~ l₂ :=
Exists.intro l₁ (Exists.intro (perm.refl l₁) s)
theorem perm.subperm {α : Type uu} {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) : l₁ <+~ l₂ :=
Exists.intro l₂ (Exists.intro (perm.symm p) (sublist.refl l₂))
theorem subperm.refl {α : Type uu} (l : List α) : l <+~ l := perm.subperm (perm.refl l)
theorem subperm.trans {α : Type uu} {l₁ : List α} {l₂ : List α} {l₃ : List α} :
l₁ <+~ l₂ → l₂ <+~ l₃ → l₁ <+~ l₃ :=
sorry
theorem subperm.length_le {α : Type uu} {l₁ : List α} {l₂ : List α} :
l₁ <+~ l₂ → length l₁ ≤ length l₂ :=
sorry
theorem subperm.perm_of_length_le {α : Type uu} {l₁ : List α} {l₂ : List α} :
l₁ <+~ l₂ → length l₂ ≤ length l₁ → l₁ ~ l₂ :=
sorry
theorem subperm.antisymm {α : Type uu} {l₁ : List α} {l₂ : List α} (h₁ : l₁ <+~ l₂)
(h₂ : l₂ <+~ l₁) : l₁ ~ l₂ :=
subperm.perm_of_length_le h₁ (subperm.length_le h₂)
theorem subperm.subset {α : Type uu} {l₁ : List α} {l₂ : List α} : l₁ <+~ l₂ → l₁ ⊆ l₂ := sorry
theorem sublist.exists_perm_append {α : Type uu} {l₁ : List α} {l₂ : List α} :
l₁ <+ l₂ → ∃ (l : List α), l₂ ~ l₁ ++ l :=
sorry
theorem perm.countp_eq {α : Type uu} (p : α → Prop) [decidable_pred p] {l₁ : List α} {l₂ : List α}
(s : l₁ ~ l₂) : countp p l₁ = countp p l₂ :=
eq.mpr (id (Eq._oldrec (Eq.refl (countp p l₁ = countp p l₂)) (countp_eq_length_filter p l₁)))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (length (filter p l₁) = countp p l₂)) (countp_eq_length_filter p l₂)))
(perm.length_eq (perm.filter p s)))
theorem subperm.countp_le {α : Type uu} (p : α → Prop) [decidable_pred p] {l₁ : List α}
{l₂ : List α} : l₁ <+~ l₂ → countp p l₁ ≤ countp p l₂ :=
sorry
theorem perm.count_eq {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂)
(a : α) : count a l₁ = count a l₂ :=
perm.countp_eq (Eq a) p
theorem subperm.count_le {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (s : l₁ <+~ l₂)
(a : α) : count a l₁ ≤ count a l₂ :=
subperm.countp_le (Eq a) s
theorem perm.foldl_eq' {α : Type uu} {β : Type vv} {f : β → α → β} {l₁ : List α} {l₂ : List α}
(p : l₁ ~ l₂) :
(∀ (x : α), x ∈ l₁ → ∀ (y : α), y ∈ l₁ → ∀ (z : β), f (f z x) y = f (f z y) x) →
∀ (b : β), foldl f b l₁ = foldl f b l₂ :=
sorry
theorem perm.foldl_eq {α : Type uu} {β : Type vv} {f : β → α → β} {l₁ : List α} {l₂ : List α}
(rcomm : right_commutative f) (p : l₁ ~ l₂) (b : β) : foldl f b l₁ = foldl f b l₂ :=
perm.foldl_eq' p fun (x : α) (hx : x ∈ l₁) (y : α) (hy : y ∈ l₁) (z : β) => rcomm z x y
theorem perm.foldr_eq {α : Type uu} {β : Type vv} {f : α → β → β} {l₁ : List α} {l₂ : List α}
(lcomm : left_commutative f) (p : l₁ ~ l₂) (b : β) : foldr f b l₁ = foldr f b l₂ :=
sorry
theorem perm.rec_heq {α : Type uu} {β : List α → Sort u_1}
{f : (a : α) → (l : List α) → β l → β (a :: l)} {b : β []} {l : List α} {l' : List α}
(hl : l ~ l')
(f_congr :
∀ {a : α} {l l' : List α} {b : β l} {b' : β l'}, l ~ l' → b == b' → f a l b == f a l' b')
(f_swap :
∀ {a a' : α} {l : List α} {b : β l}, f a (a' :: l) (f a' l b) == f a' (a :: l) (f a l b)) :
List.rec b f l == List.rec b f l' :=
sorry
theorem perm.fold_op_eq {α : Type uu} {op : α → α → α} [is_associative α op] [is_commutative α op]
{l₁ : List α} {l₂ : List α} {a : α} (h : l₁ ~ l₂) : foldl op a l₁ = foldl op a l₂ :=
perm.foldl_eq (right_comm op is_commutative.comm is_associative.assoc) h a
/-- If elements of a list commute with each other, then their product does not
depend on the order of elements-/
theorem perm.sum_eq' {α : Type uu} [add_monoid α] {l₁ : List α} {l₂ : List α} (h : l₁ ~ l₂)
(hc : pairwise (fun (x y : α) => x + y = y + x) l₁) : sum l₁ = sum l₂ :=
sorry
theorem perm.sum_eq {α : Type uu} [add_comm_monoid α] {l₁ : List α} {l₂ : List α} (h : l₁ ~ l₂) :
sum l₁ = sum l₂ :=
perm.fold_op_eq h
theorem sum_reverse {α : Type uu} [add_comm_monoid α] (l : List α) : sum (reverse l) = sum l :=
perm.sum_eq (reverse_perm l)
theorem perm_inv_core {α : Type uu} {a : α} {l₁ : List α} {l₂ : List α} {r₁ : List α}
{r₂ : List α} : l₁ ++ a :: r₁ ~ l₂ ++ a :: r₂ → l₁ ++ r₁ ~ l₂ ++ r₂ :=
sorry
theorem perm.cons_inv {α : Type uu} {a : α} {l₁ : List α} {l₂ : List α} :
a :: l₁ ~ a :: l₂ → l₁ ~ l₂ :=
perm_inv_core
@[simp] theorem perm_cons {α : Type uu} (a : α) {l₁ : List α} {l₂ : List α} :
a :: l₁ ~ a :: l₂ ↔ l₁ ~ l₂ :=
{ mp := perm.cons_inv, mpr := perm.cons a }
theorem perm_append_left_iff {α : Type uu} {l₁ : List α} {l₂ : List α} (l : List α) :
l ++ l₁ ~ l ++ l₂ ↔ l₁ ~ l₂ :=
sorry
theorem perm_append_right_iff {α : Type uu} {l₁ : List α} {l₂ : List α} (l : List α) :
l₁ ++ l ~ l₂ ++ l ↔ l₁ ~ l₂ :=
sorry
theorem perm_option_to_list {α : Type uu} {o₁ : Option α} {o₂ : Option α} :
option.to_list o₁ ~ option.to_list o₂ ↔ o₁ = o₂ :=
sorry
theorem subperm_cons {α : Type uu} (a : α) {l₁ : List α} {l₂ : List α} :
a :: l₁ <+~ a :: l₂ ↔ l₁ <+~ l₂ :=
sorry
theorem cons_subperm_of_mem {α : Type uu} {a : α} {l₁ : List α} {l₂ : List α} (d₁ : nodup l₁)
(h₁ : ¬a ∈ l₁) (h₂ : a ∈ l₂) (s : l₁ <+~ l₂) : a :: l₁ <+~ l₂ :=
sorry
theorem subperm_append_left {α : Type uu} {l₁ : List α} {l₂ : List α} (l : List α) :
l ++ l₁ <+~ l ++ l₂ ↔ l₁ <+~ l₂ :=
sorry
theorem subperm_append_right {α : Type uu} {l₁ : List α} {l₂ : List α} (l : List α) :
l₁ ++ l <+~ l₂ ++ l ↔ l₁ <+~ l₂ :=
iff.trans (iff.trans (perm.subperm_left perm_append_comm) (perm.subperm_right perm_append_comm))
(subperm_append_left l)
theorem subperm.exists_of_length_lt {α : Type uu} {l₁ : List α} {l₂ : List α} :
l₁ <+~ l₂ → length l₁ < length l₂ → ∃ (a : α), a :: l₁ <+~ l₂ :=
sorry
theorem subperm_of_subset_nodup {α : Type uu} {l₁ : List α} {l₂ : List α} (d : nodup l₁)
(H : l₁ ⊆ l₂) : l₁ <+~ l₂ :=
sorry
theorem perm_ext {α : Type uu} {l₁ : List α} {l₂ : List α} (d₁ : nodup l₁) (d₂ : nodup l₂) :
l₁ ~ l₂ ↔ ∀ (a : α), a ∈ l₁ ↔ a ∈ l₂ :=
sorry
theorem nodup.sublist_ext {α : Type uu} {l₁ : List α} {l₂ : List α} {l : List α} (d : nodup l)
(s₁ : l₁ <+ l) (s₂ : l₂ <+ l) : l₁ ~ l₂ ↔ l₁ = l₂ :=
sorry
-- attribute [congr]
theorem perm.erase {α : Type uu} [DecidableEq α] (a : α) {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) :
list.erase l₁ a ~ list.erase l₂ a :=
sorry
theorem subperm_cons_erase {α : Type uu} [DecidableEq α] (a : α) (l : List α) :
l <+~ a :: list.erase l a :=
sorry
theorem erase_subperm {α : Type uu} [DecidableEq α] (a : α) (l : List α) : list.erase l a <+~ l :=
sublist.subperm (erase_sublist a l)
theorem subperm.erase {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (a : α)
(h : l₁ <+~ l₂) : list.erase l₁ a <+~ list.erase l₂ a :=
sorry
theorem perm.diff_right {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (t : List α)
(h : l₁ ~ l₂) : list.diff l₁ t ~ list.diff l₂ t :=
sorry
theorem perm.diff_left {α : Type uu} [DecidableEq α] (l : List α) {t₁ : List α} {t₂ : List α}
(h : t₁ ~ t₂) : list.diff l t₁ = list.diff l t₂ :=
sorry
theorem perm.diff {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} {t₁ : List α}
{t₂ : List α} (hl : l₁ ~ l₂) (ht : t₁ ~ t₂) : list.diff l₁ t₁ ~ list.diff l₂ t₂ :=
perm.diff_left l₂ ht ▸ perm.diff_right t₁ hl
theorem subperm.diff_right {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (h : l₁ <+~ l₂)
(t : List α) : list.diff l₁ t <+~ list.diff l₂ t :=
sorry
theorem erase_cons_subperm_cons_erase {α : Type uu} [DecidableEq α] (a : α) (b : α) (l : List α) :
list.erase (a :: l) b <+~ a :: list.erase l b :=
sorry
theorem subperm_cons_diff {α : Type uu} [DecidableEq α] {a : α} {l₁ : List α} {l₂ : List α} :
list.diff (a :: l₁) l₂ <+~ a :: list.diff l₁ l₂ :=
sorry
theorem subset_cons_diff {α : Type uu} [DecidableEq α] {a : α} {l₁ : List α} {l₂ : List α} :
list.diff (a :: l₁) l₂ ⊆ a :: list.diff l₁ l₂ :=
subperm.subset subperm_cons_diff
theorem perm.bag_inter_right {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (t : List α)
(h : l₁ ~ l₂) : list.bag_inter l₁ t ~ list.bag_inter l₂ t :=
sorry
theorem perm.bag_inter_left {α : Type uu} [DecidableEq α] (l : List α) {t₁ : List α} {t₂ : List α}
(p : t₁ ~ t₂) : list.bag_inter l t₁ = list.bag_inter l t₂ :=
sorry
theorem perm.bag_inter {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} {t₁ : List α}
{t₂ : List α} (hl : l₁ ~ l₂) (ht : t₁ ~ t₂) : list.bag_inter l₁ t₁ ~ list.bag_inter l₂ t₂ :=
perm.bag_inter_left l₂ ht ▸ perm.bag_inter_right t₁ hl
theorem cons_perm_iff_perm_erase {α : Type uu} [DecidableEq α] {a : α} {l₁ : List α} {l₂ : List α} :
a :: l₁ ~ l₂ ↔ a ∈ l₂ ∧ l₁ ~ list.erase l₂ a :=
sorry
theorem perm_iff_count {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} :
l₁ ~ l₂ ↔ ∀ (a : α), count a l₁ = count a l₂ :=
sorry
protected instance decidable_perm {α : Type uu} [DecidableEq α] (l₁ : List α) (l₂ : List α) :
Decidable (l₁ ~ l₂) :=
sorry
-- @[congr]
theorem perm.erase_dup {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (p : l₁ ~ l₂) :
erase_dup l₁ ~ erase_dup l₂ :=
sorry
-- attribute [congr]
theorem perm.insert {α : Type uu} [DecidableEq α] (a : α) {l₁ : List α} {l₂ : List α}
(p : l₁ ~ l₂) : insert a l₁ ~ insert a l₂ :=
sorry
theorem perm_insert_swap {α : Type uu} [DecidableEq α] (x : α) (y : α) (l : List α) :
insert x (insert y l) ~ insert y (insert x l) :=
sorry
theorem perm_insert_nth {α : Type u_1} (x : α) (l : List α) {n : ℕ} (h : n ≤ length l) :
insert_nth n x l ~ x :: l :=
sorry
theorem perm.union_right {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (t₁ : List α)
(h : l₁ ~ l₂) : l₁ ∪ t₁ ~ l₂ ∪ t₁ :=
sorry
theorem perm.union_left {α : Type uu} [DecidableEq α] (l : List α) {t₁ : List α} {t₂ : List α}
(h : t₁ ~ t₂) : l ∪ t₁ ~ l ∪ t₂ :=
sorry
-- @[congr]
theorem perm.union {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} {t₁ : List α}
{t₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∪ t₁ ~ l₂ ∪ t₂ :=
perm.trans (perm.union_right t₁ p₁) (perm.union_left l₂ p₂)
theorem perm.inter_right {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} (t₁ : List α) :
l₁ ~ l₂ → l₁ ∩ t₁ ~ l₂ ∩ t₁ :=
perm.filter fun (_x : α) => _x ∈ t₁
theorem perm.inter_left {α : Type uu} [DecidableEq α] (l : List α) {t₁ : List α} {t₂ : List α}
(p : t₁ ~ t₂) : l ∩ t₁ = l ∩ t₂ :=
sorry
-- @[congr]
theorem perm.inter {α : Type uu} [DecidableEq α] {l₁ : List α} {l₂ : List α} {t₁ : List α}
{t₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∩ t₁ ~ l₂ ∩ t₂ :=
perm.inter_left l₂ p₂ ▸ perm.inter_right t₁ p₁
theorem perm.inter_append {α : Type uu} [DecidableEq α] {l : List α} {t₁ : List α} {t₂ : List α}
(h : disjoint t₁ t₂) : l ∩ (t₁ ++ t₂) ~ l ∩ t₁ ++ l ∩ t₂ :=
sorry
theorem perm.pairwise_iff {α : Type uu} {R : α → α → Prop} (S : symmetric R) {l₁ : List α}
{l₂ : List α} (p : l₁ ~ l₂) : pairwise R l₁ ↔ pairwise R l₂ :=
sorry
theorem perm.nodup_iff {α : Type uu} {l₁ : List α} {l₂ : List α} :
l₁ ~ l₂ → (nodup l₁ ↔ nodup l₂) :=
perm.pairwise_iff ne.symm
theorem perm.bind_right {α : Type uu} {β : Type vv} {l₁ : List α} {l₂ : List α} (f : α → List β)
(p : l₁ ~ l₂) : list.bind l₁ f ~ list.bind l₂ f :=
sorry
theorem perm.bind_left {α : Type uu} {β : Type vv} (l : List α) {f : α → List β} {g : α → List β}
(h : ∀ (a : α), f a ~ g a) : list.bind l f ~ list.bind l g :=
sorry
theorem perm.product_right {α : Type uu} {β : Type vv} {l₁ : List α} {l₂ : List α} (t₁ : List β)
(p : l₁ ~ l₂) : product l₁ t₁ ~ product l₂ t₁ :=
perm.bind_right (fun (a : α) => map (Prod.mk a) t₁) p
theorem perm.product_left {α : Type uu} {β : Type vv} (l : List α) {t₁ : List β} {t₂ : List β}
(p : t₁ ~ t₂) : product l t₁ ~ product l t₂ :=
perm.bind_left l fun (a : α) => perm.map (Prod.mk a) p
theorem perm.product {α : Type uu} {β : Type vv} {l₁ : List α} {l₂ : List α} {t₁ : List β}
{t₂ : List β} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : product l₁ t₁ ~ product l₂ t₂ :=
perm.trans (perm.product_right t₁ p₁) (perm.product_left l₂ p₂)
theorem sublists_cons_perm_append {α : Type uu} (a : α) (l : List α) :
sublists (a :: l) ~ sublists l ++ map (List.cons a) (sublists l) :=
sorry
theorem sublists_perm_sublists' {α : Type uu} (l : List α) : sublists l ~ sublists' l := sorry
theorem revzip_sublists {α : Type uu} (l : List α) (l₁ : List α) (l₂ : List α) :
(l₁, l₂) ∈ revzip (sublists l) → l₁ ++ l₂ ~ l :=
sorry
theorem revzip_sublists' {α : Type uu} (l : List α) (l₁ : List α) (l₂ : List α) :
(l₁, l₂) ∈ revzip (sublists' l) → l₁ ++ l₂ ~ l :=
sorry
theorem perm_lookmap {α : Type uu} (f : α → Option α) {l₁ : List α} {l₂ : List α}
(H : pairwise (fun (a b : α) => ∀ (c : α), c ∈ f a → ∀ (d : α), d ∈ f b → a = b ∧ c = d) l₁)
(p : l₁ ~ l₂) : lookmap f l₁ ~ lookmap f l₂ :=
sorry
theorem perm.erasep {α : Type uu} (f : α → Prop) [decidable_pred f] {l₁ : List α} {l₂ : List α}
(H : pairwise (fun (a b : α) => f a → f b → False) l₁) (p : l₁ ~ l₂) :
erasep f l₁ ~ erasep f l₂ :=
sorry
theorem perm.take_inter {α : Type u_1} [DecidableEq α] {xs : List α} {ys : List α} (n : ℕ)
(h : xs ~ ys) (h' : nodup ys) : take n xs ~ list.inter ys (take n xs) :=
sorry
theorem perm.drop_inter {α : Type u_1} [DecidableEq α] {xs : List α} {ys : List α} (n : ℕ)
(h : xs ~ ys) (h' : nodup ys) : drop n xs ~ list.inter ys (drop n xs) :=
sorry
theorem perm.slice_inter {α : Type u_1} [DecidableEq α] {xs : List α} {ys : List α} (n : ℕ) (m : ℕ)
(h : xs ~ ys) (h' : nodup ys) : slice n m xs ~ ys ∩ slice n m xs :=
sorry
/- enumerating permutations -/
theorem permutations_aux2_fst {α : Type uu} {β : Type vv} (t : α) (ts : List α) (r : List β)
(ys : List α) (f : List α → β) : prod.fst (permutations_aux2 t ts r ys f) = ys ++ ts :=
sorry
@[simp] theorem permutations_aux2_snd_nil {α : Type uu} {β : Type vv} (t : α) (ts : List α)
(r : List β) (f : List α → β) : prod.snd (permutations_aux2 t ts r [] f) = r :=
rfl
@[simp] theorem permutations_aux2_snd_cons {α : Type uu} {β : Type vv} (t : α) (ts : List α)
(r : List β) (y : α) (ys : List α) (f : List α → β) :
prod.snd (permutations_aux2 t ts r (y :: ys) f) =
f (t :: y :: ys ++ ts) ::
prod.snd (permutations_aux2 t ts r ys fun (x : List α) => f (y :: x)) :=
sorry
theorem permutations_aux2_append {α : Type uu} {β : Type vv} (t : α) (ts : List α) (r : List β)
(ys : List α) (f : List α → β) :
prod.snd (permutations_aux2 t ts [] ys f) ++ r = prod.snd (permutations_aux2 t ts r ys f) :=
sorry
theorem mem_permutations_aux2 {α : Type uu} {t : α} {ts : List α} {ys : List α} {l : List α}
{l' : List α} :
l' ∈ prod.snd (permutations_aux2 t ts [] ys (append l)) ↔
∃ (l₁ : List α), ∃ (l₂ : List α), l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l' = l ++ l₁ ++ t :: l₂ ++ ts :=
sorry
theorem mem_permutations_aux2' {α : Type uu} {t : α} {ts : List α} {ys : List α} {l : List α} :
l ∈ prod.snd (permutations_aux2 t ts [] ys id) ↔
∃ (l₁ : List α), ∃ (l₂ : List α), l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l = l₁ ++ t :: l₂ ++ ts :=
sorry
theorem length_permutations_aux2 {α : Type uu} {β : Type vv} (t : α) (ts : List α) (ys : List α)
(f : List α → β) : length (prod.snd (permutations_aux2 t ts [] ys f)) = length ys :=
sorry
theorem foldr_permutations_aux2 {α : Type uu} (t : α) (ts : List α) (r : List (List α))
(L : List (List α)) :
foldr (fun (y : List α) (r : List (List α)) => prod.snd (permutations_aux2 t ts r y id)) r L =
(list.bind L fun (y : List α) => prod.snd (permutations_aux2 t ts [] y id)) ++ r :=
sorry
theorem mem_foldr_permutations_aux2 {α : Type uu} {t : α} {ts : List α} {r : List (List α)}
{L : List (List α)} {l' : List α} :
l' ∈
foldr (fun (y : List α) (r : List (List α)) => prod.snd (permutations_aux2 t ts r y id)) r
L ↔
l' ∈ r ∨
∃ (l₁ : List α), ∃ (l₂ : List α), l₁ ++ l₂ ∈ L ∧ l₂ ≠ [] ∧ l' = l₁ ++ t :: l₂ ++ ts :=
sorry
theorem length_foldr_permutations_aux2 {α : Type uu} (t : α) (ts : List α) (r : List (List α))
(L : List (List α)) :
length
(foldr (fun (y : List α) (r : List (List α)) => prod.snd (permutations_aux2 t ts r y id))
r L) =
sum (map length L) + length r :=
sorry
theorem length_foldr_permutations_aux2' {α : Type uu} (t : α) (ts : List α) (r : List (List α))
(L : List (List α)) (n : ℕ) (H : ∀ (l : List α), l ∈ L → length l = n) :
length
(foldr (fun (y : List α) (r : List (List α)) => prod.snd (permutations_aux2 t ts r y id))
r L) =
n * length L + length r :=
sorry
theorem perm_of_mem_permutations_aux {α : Type uu} {ts : List α} {is : List α} {l : List α} :
l ∈ permutations_aux ts is → l ~ ts ++ is :=
sorry
theorem perm_of_mem_permutations {α : Type uu} {l₁ : List α} {l₂ : List α}
(h : l₁ ∈ permutations l₂) : l₁ ~ l₂ :=
or.elim (eq_or_mem_of_mem_cons h) (fun (e : l₁ = l₂) => e ▸ perm.refl l₁)
fun (m : l₁ ∈ permutations_aux l₂ []) => append_nil l₂ ▸ perm_of_mem_permutations_aux m
theorem length_permutations_aux {α : Type uu} (ts : List α) (is : List α) :
length (permutations_aux ts is) + nat.factorial (length is) =
nat.factorial (length ts + length is) :=
sorry
theorem length_permutations {α : Type uu} (l : List α) :
length (permutations l) = nat.factorial (length l) :=
length_permutations_aux l []
theorem mem_permutations_of_perm_lemma {α : Type uu} {is : List α} {l : List α}
(H :
l ~ [] ++ is →
(∃ (ts' : List α), ∃ (H : ts' ~ []), l = ts' ++ is) ∨ l ∈ permutations_aux is []) :
l ~ is → l ∈ permutations is :=
sorry
theorem mem_permutations_aux_of_perm {α : Type uu} {ts : List α} {is : List α} {l : List α} :
l ~ is ++ ts →
(∃ (is' : List α), ∃ (H : is' ~ is), l = is' ++ ts) ∨ l ∈ permutations_aux ts is :=
sorry
@[simp] theorem mem_permutations {α : Type uu} (s : List α) (t : List α) :
s ∈ permutations t ↔ s ~ t :=
{ mp := perm_of_mem_permutations,
mpr := mem_permutations_of_perm_lemma mem_permutations_aux_of_perm }
end Mathlib |
9ec35b430d587062aa6db1b69e85eee0e4111900 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/combinatorics/simple_graph/adj_matrix.lean | 6363e3062da21dc518237a89e8ed9ce8e1135b1d | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,154 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark
-/
import linear_algebra.matrix
import data.rel
import combinatorics.simple_graph.basic
/-!
# Adjacency Matrices
This module defines the adjacency matrix of a graph, and provides theorems connecting graph
properties to computational properties of the matrix.
## Main definitions
* `adj_matrix` is the adjacency matrix of a `simple_graph` with coefficients in a given semiring.
-/
open_locale big_operators matrix
open finset matrix simple_graph
universes u v
variables {α : Type u} [fintype α]
variables (R : Type v) [semiring R]
namespace simple_graph
variables (G : simple_graph α) (R) [decidable_rel G.adj]
/-- `adj_matrix G R` is the matrix `A` such that `A i j = (1 : R)` if `i` and `j` are
adjacent in the simple graph `G`, and otherwise `A i j = 0`. -/
def adj_matrix : matrix α α R
| i j := if (G.adj i j) then 1 else 0
variable {R}
@[simp]
lemma adj_matrix_apply (v w : α) : G.adj_matrix R v w = if (G.adj v w) then 1 else 0 := rfl
@[simp]
theorem transpose_adj_matrix : (G.adj_matrix R)ᵀ = G.adj_matrix R :=
by { ext, simp [edge_symm] }
@[simp]
lemma adj_matrix_dot_product (v : α) (vec : α → R) :
dot_product (G.adj_matrix R v) vec = ∑ u in G.neighbor_finset v, vec u :=
by simp [neighbor_finset_eq_filter, dot_product, sum_filter]
@[simp]
lemma dot_product_adj_matrix (v : α) (vec : α → R) :
dot_product vec (G.adj_matrix R v) = ∑ u in G.neighbor_finset v, vec u :=
by simp [neighbor_finset_eq_filter, dot_product, sum_filter, sum_apply]
@[simp]
lemma adj_matrix_mul_vec_apply (v : α) (vec : α → R) :
((G.adj_matrix R).mul_vec vec) v = ∑ u in G.neighbor_finset v, vec u :=
by rw [mul_vec, adj_matrix_dot_product]
@[simp]
lemma adj_matrix_vec_mul_apply (v : α) (vec : α → R) :
((G.adj_matrix R).vec_mul vec) v = ∑ u in G.neighbor_finset v, vec u :=
begin
rw [← dot_product_adj_matrix, vec_mul],
refine congr rfl _, ext,
rw [← transpose_apply (adj_matrix R G) x v, transpose_adj_matrix],
end
@[simp]
lemma adj_matrix_mul_apply (M : matrix α α R) (v w : α) :
(G.adj_matrix R ⬝ M) v w = ∑ u in G.neighbor_finset v, M u w :=
by simp [mul_apply, neighbor_finset_eq_filter, sum_filter]
@[simp]
lemma mul_adj_matrix_apply (M : matrix α α R) (v w : α) :
(M ⬝ G.adj_matrix R) v w = ∑ u in G.neighbor_finset w, M v u :=
by simp [mul_apply, neighbor_finset_eq_filter, sum_filter, edge_symm]
variable (R)
theorem trace_adj_matrix : matrix.trace α R R (G.adj_matrix R) = 0 := by simp
variable {R}
theorem adj_matrix_mul_self_apply_self (i : α) :
((G.adj_matrix R) ⬝ (G.adj_matrix R)) i i = degree G i :=
by simp [degree]
variable {G}
@[simp]
lemma adj_matrix_mul_vec_const_apply {r : R} {v : α} :
(G.adj_matrix R).mul_vec (function.const _ r) v = G.degree v * r :=
by simp [degree]
lemma adj_matrix_mul_vec_const_apply_of_regular {d : ℕ} {r : R} (hd : G.is_regular_of_degree d)
{v : α} :
(G.adj_matrix R).mul_vec (function.const _ r) v = (d * r) :=
by simp [hd v]
end simple_graph
|
f75cabb8b9a05787459a7048488e8dae1a1fff8a | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/theories/topology/order_topology.lean | 308835100c1337379f6ab1fad97607fae9cc251e | [
"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 | 3,241 | lean | /-
Copyright (c) 2016 Jacob Gross. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jacob Gross
The order topology.
-/
import data.set theories.topology.basic algebra.interval
open algebra eq.ops set interval topology
namespace order_topology
variables {X : Type} [linear_strong_order_pair X]
definition linorder_generators : set (set X) := {y | ∃ a, y = '(a, ∞) } ∪ {y | ∃ a, y = '(-∞, a)}
attribute [instance]
definition linorder_topology : topology X :=
topology.generated_by linorder_generators
theorem Open_Ioi {a : X} : Open '(a, ∞) :=
(generators_mem_topology_generated_by linorder_generators) (!mem_unionl (exists.intro a rfl))
theorem Open_Iio {a : X} : Open '(-∞, a) :=
(generators_mem_topology_generated_by linorder_generators) (!mem_unionr (exists.intro a rfl))
theorem closed_Ici (a : X) : closed '[a,∞) :=
!compl_Ici⁻¹ ▸ Open_Iio
theorem closed_Iic (a : X) : closed '(-∞,a] :=
have '(a, ∞) = -'(-∞,a], from ext(take x, iff.intro
(assume H, not_le_of_gt H)
(assume H, lt_of_not_ge H)),
this ▸ Open_Ioi
theorem Open_Ioo (a b : X) : Open '(a, b) :=
Open_inter !Open_Ioi !Open_Iio
theorem closed_Icc (a b : X) : closed '[a, b] :=
closed_inter !closed_Ici !closed_Iic
section
local attribute classical.prop_decidable [instance]
theorem linorder_separation {x y : X} :
x < y → ∃ a b, (x < a ∧ b < y) ∧ '(-∞, a) ∩ '(b, ∞) = ∅ :=
suppose x < y,
if H1 : ∃ z, x < z ∧ z < y then
obtain z (Hz : x < z ∧ z < y), from H1,
have '(-∞, z) ∩ '(z, ∞) = ∅, from ext (take r, iff.intro
(assume H, absurd (!lt.trans (and.elim_left H) (and.elim_right H)) !lt.irrefl)
(assume H, !not.elim !not_mem_empty H)),
exists.intro z (exists.intro z (and.intro Hz this))
else
have '(-∞, y) ∩ '(x, ∞) = ∅, from ext(take r, iff.intro
(assume H, absurd (exists.intro r (iff.elim_left and.comm H)) H1)
(assume H, !not.elim !not_mem_empty H)),
exists.intro y (exists.intro x (and.intro (and.intro `x < y` `x < y`) this))
end
attribute [trans_instance]
protected definition T2_space.of_linorder_topology :
T2_space X :=
⦃ T2_space, linorder_topology,
T2 := abstract
take x y, assume H,
or.elim (lt_or_gt_of_ne H)
(assume H,
obtain a [b Hab], from linorder_separation H,
show _, from exists.intro '(-∞, a) (exists.intro '(b, ∞)
(and.intro Open_Iio (and.intro Open_Ioi (iff.elim_left and.assoc Hab)))))
(assume H,
obtain a [b Hab], from linorder_separation H,
have Hx : x ∈ '(b, ∞), from and.elim_right (and.elim_left Hab),
have Hy : y ∈ '(-∞, a), from and.elim_left (and.elim_left Hab),
have Hi : '(b, ∞) ∩ '(-∞, a) = ∅, from !inter_comm ▸ (and.elim_right Hab),
have (Open '(b,∞)) ∧ (Open '(-∞, a)) ∧ x ∈ '(b, ∞) ∧ y ∈ '(-∞, a) ∧
'(b, ∞) ∩ '(-∞, a) = ∅, from
and.intro Open_Ioi (and.intro Open_Iio (and.intro Hx (and.intro Hy Hi))),
show _, from exists.intro '(b,∞) (exists.intro '(-∞, a) this))
end ⦄
end order_topology
|
d3e0a9c6fd2c6d45ad8e3ed21ea98d4725dd8f61 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/whiskering.lean | f63f6ec9a485e35309ddc55ba3cbe5bf0d6d1c71 | [
"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 | 7,095 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.natural_isomorphism
namespace category_theory
universes u₁ v₁ u₂ v₂ u₃ v₃ u₄ v₄
section
variables {C : Type u₁} [category.{v₁} C]
{D : Type u₂} [category.{v₂} D]
{E : Type u₃} [category.{v₃} E]
/--
If `α : G ⟶ H` then
`whisker_left F α : (F ⋙ G) ⟶ (F ⋙ H)` has components `α.app (F.obj X)`.
-/
@[simps] def whisker_left (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) : (F ⋙ G) ⟶ (F ⋙ H) :=
{ app := λ X, α.app (F.obj X),
naturality' := λ X Y f, by rw [functor.comp_map, functor.comp_map, α.naturality] }
/--
If `α : G ⟶ H` then
`whisker_right α F : (G ⋙ F) ⟶ (G ⋙ F)` has components `F.map (α.app X)`.
-/
@[simps] def whisker_right {G H : C ⥤ D} (α : G ⟶ H) (F : D ⥤ E) : (G ⋙ F) ⟶ (H ⋙ F) :=
{ app := λ X, F.map (α.app X),
naturality' := λ X Y f,
by rw [functor.comp_map, functor.comp_map, ←F.map_comp, ←F.map_comp, α.naturality] }
variables (C D E)
/--
Left-composition gives a functor `(C ⥤ D) ⥤ ((D ⥤ E) ⥤ (C ⥤ E))`.
`(whiskering_lift.obj F).obj G` is `F ⋙ G`, and
`(whiskering_lift.obj F).map α` is `whisker_left F α`.
-/
@[simps] def whiskering_left : (C ⥤ D) ⥤ ((D ⥤ E) ⥤ (C ⥤ E)) :=
{ obj := λ F,
{ obj := λ G, F ⋙ G,
map := λ G H α, whisker_left F α },
map := λ F G τ,
{ app := λ H,
{ app := λ c, H.map (τ.app c),
naturality' := λ X Y f, begin dsimp, rw [←H.map_comp, ←H.map_comp, ←τ.naturality] end },
naturality' := λ X Y f, begin ext, dsimp, rw [f.naturality] end } }
/--
Right-composition gives a functor `(D ⥤ E) ⥤ ((C ⥤ D) ⥤ (C ⥤ E))`.
`(whiskering_right.obj H).obj F` is `F ⋙ H`, and
`(whiskering_right.obj H).map α` is `whisker_right α H`.
-/
@[simps] def whiskering_right : (D ⥤ E) ⥤ ((C ⥤ D) ⥤ (C ⥤ E)) :=
{ obj := λ H,
{ obj := λ F, F ⋙ H,
map := λ _ _ α, whisker_right α H },
map := λ G H τ,
{ app := λ F,
{ app := λ c, τ.app (F.obj c),
naturality' := λ X Y f, begin dsimp, rw [τ.naturality] end },
naturality' := λ X Y f, begin ext, dsimp, rw [←nat_trans.naturality] end } }
variables {C} {D} {E}
@[simp] lemma whisker_left_id (F : C ⥤ D) {G : D ⥤ E} :
whisker_left F (nat_trans.id G) = nat_trans.id (F.comp G) :=
rfl
@[simp] lemma whisker_left_id' (F : C ⥤ D) {G : D ⥤ E} :
whisker_left F (𝟙 G) = 𝟙 (F.comp G) :=
rfl
@[simp] lemma whisker_right_id {G : C ⥤ D} (F : D ⥤ E) :
whisker_right (nat_trans.id G) F = nat_trans.id (G.comp F) :=
((whiskering_right C D E).obj F).map_id _
@[simp] lemma whisker_right_id' {G : C ⥤ D} (F : D ⥤ E) :
whisker_right (𝟙 G) F = 𝟙 (G.comp F) :=
((whiskering_right C D E).obj F).map_id _
@[simp] lemma whisker_left_comp (F : C ⥤ D) {G H K : D ⥤ E} (α : G ⟶ H) (β : H ⟶ K) :
whisker_left F (α ≫ β) = (whisker_left F α) ≫ (whisker_left F β) :=
rfl
@[simp] lemma whisker_right_comp {G H K : C ⥤ D} (α : G ⟶ H) (β : H ⟶ K) (F : D ⥤ E) :
whisker_right (α ≫ β) F = (whisker_right α F) ≫ (whisker_right β F) :=
((whiskering_right C D E).obj F).map_comp α β
/--
If `α : G ≅ H` is a natural isomorphism then
`iso_whisker_left F α : (F ⋙ G) ≅ (F ⋙ H)` has components `α.app (F.obj X)`.
-/
def iso_whisker_left (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) : (F ⋙ G) ≅ (F ⋙ H) :=
((whiskering_left C D E).obj F).map_iso α
@[simp] lemma iso_whisker_left_hom (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) :
(iso_whisker_left F α).hom = whisker_left F α.hom :=
rfl
@[simp] lemma iso_whisker_left_inv (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) :
(iso_whisker_left F α).inv = whisker_left F α.inv :=
rfl
/--
If `α : G ≅ H` then
`iso_whisker_right α F : (G ⋙ F) ≅ (G ⋙ F)` has components `F.map_iso (α.app X)`.
-/
def iso_whisker_right {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) : (G ⋙ F) ≅ (H ⋙ F) :=
((whiskering_right C D E).obj F).map_iso α
@[simp] lemma iso_whisker_right_hom {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) :
(iso_whisker_right α F).hom = whisker_right α.hom F :=
rfl
@[simp] lemma iso_whisker_right_inv {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) :
(iso_whisker_right α F).inv = whisker_right α.inv F :=
rfl
instance is_iso_whisker_left (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) [is_iso α] :
is_iso (whisker_left F α) :=
is_iso.of_iso (iso_whisker_left F (as_iso α))
instance is_iso_whisker_right {G H : C ⥤ D} (α : G ⟶ H) (F : D ⥤ E) [is_iso α] :
is_iso (whisker_right α F) :=
is_iso.of_iso (iso_whisker_right (as_iso α) F)
variables {B : Type u₄} [category.{v₄} B]
local attribute [elab_simple] whisker_left whisker_right
@[simp] lemma whisker_left_twice (F : B ⥤ C) (G : C ⥤ D) {H K : D ⥤ E} (α : H ⟶ K) :
whisker_left F (whisker_left G α) = whisker_left (F ⋙ G) α :=
rfl
@[simp] lemma whisker_right_twice {H K : B ⥤ C} (F : C ⥤ D) (G : D ⥤ E) (α : H ⟶ K) :
whisker_right (whisker_right α F) G = whisker_right α (F ⋙ G) :=
rfl
lemma whisker_right_left (F : B ⥤ C) {G H : C ⥤ D} (α : G ⟶ H) (K : D ⥤ E) :
whisker_right (whisker_left F α) K = whisker_left F (whisker_right α K) :=
rfl
end
namespace functor
universes u₅ v₅
variables {A : Type u₁} [category.{v₁} A]
variables {B : Type u₂} [category.{v₂} B]
/--
The left unitor, a natural isomorphism `((𝟭 _) ⋙ F) ≅ F`.
-/
@[simps] def left_unitor (F : A ⥤ B) : ((𝟭 A) ⋙ F) ≅ F :=
{ hom := { app := λ X, 𝟙 (F.obj X) },
inv := { app := λ X, 𝟙 (F.obj X) } }
/--
The right unitor, a natural isomorphism `(F ⋙ (𝟭 B)) ≅ F`.
-/
@[simps] def right_unitor (F : A ⥤ B) : (F ⋙ (𝟭 B)) ≅ F :=
{ hom := { app := λ X, 𝟙 (F.obj X) },
inv := { app := λ X, 𝟙 (F.obj X) } }
variables {C : Type u₃} [category.{v₃} C]
variables {D : Type u₄} [category.{v₄} D]
/--
The associator for functors, a natural isomorphism `((F ⋙ G) ⋙ H) ≅ (F ⋙ (G ⋙ H))`.
(In fact, `iso.refl _` will work here, but it tends to make Lean slow later,
and it's usually best to insert explicit associators.)
-/
@[simps] def associator (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) : ((F ⋙ G) ⋙ H) ≅ (F ⋙ (G ⋙ H)) :=
{ hom := { app := λ _, 𝟙 _ },
inv := { app := λ _, 𝟙 _ } }
lemma triangle (F : A ⥤ B) (G : B ⥤ C) :
(associator F (𝟭 B) G).hom ≫ (whisker_left F (left_unitor G).hom) =
(whisker_right (right_unitor F).hom G) :=
by { ext, dsimp, simp } -- See note [dsimp, simp].
variables {E : Type u₅} [category.{v₅} E]
variables (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) (K : D ⥤ E)
lemma pentagon :
(whisker_right (associator F G H).hom K) ≫
(associator F (G ⋙ H) K).hom ≫
(whisker_left F (associator G H K).hom) =
((associator (F ⋙ G) H K).hom ≫ (associator F G (H ⋙ K)).hom) :=
by { ext, dsimp, simp }
end functor
end category_theory
|
bcbd5f539443fc3e0233ccd8260534b1539935cf | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /library/data/nat/bigops.lean | 4307166cff0b127136cd95406d8a4b42e36c1fef | [
"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 | 7,409 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Finite sums and products over intervals of natural numbers.
-/
import data.nat.order algebra.group_bigops algebra.interval
namespace nat
/- sums -/
section add_monoid
variables {A : Type} [add_monoid A]
definition sum_up_to (n : ℕ) (f : ℕ → A) : A :=
nat.rec_on n 0 (λ n a, a + f n)
notation `∑` binders ` < ` n `, ` r:(scoped f, sum_up_to n f) := r
proposition sum_up_to_zero (f : ℕ → A) : (∑ i < 0, f i) = 0 := rfl
proposition sum_up_to_succ (n : ℕ) (f : ℕ → A) : (∑ i < succ n, f i) = (∑ i < n, f i) + f n := rfl
proposition sum_up_to_one (f : ℕ → A) : (∑ i < 1, f i) = f 0 := zero_add (f 0)
definition sum_range (m n : ℕ) (f : ℕ → A) : A := sum_up_to (succ n - m) (λ i, f (i + m))
notation `∑` binders `=` m `...` n `, ` r:(scoped f, sum_range m n f) := r
proposition sum_range_def (m n : ℕ) (f : ℕ → A) :
(∑ i = m...n, f i) = (∑ i < (succ n - m), f (i + m)) := rfl
proposition sum_range_self (m : ℕ) (f : ℕ → A) :
(∑ i = m...m, f i) = f m :=
by krewrite [↑sum_range, succ_sub !le.refl, nat.sub_self, sum_up_to_one, zero_add]
proposition sum_range_succ {m n : ℕ} (f : ℕ → A) (H : m ≤ succ n) :
(∑ i = m...succ n, f i) = (∑ i = m...n, f i) + f (succ n) :=
by rewrite [↑sum_range, succ_sub H, sum_up_to_succ, nat.sub_add_cancel H]
proposition sum_up_to_succ_eq_sum_range_zero (n : ℕ) (f : ℕ → A) :
(∑ i < succ n, f i) = (∑ i = 0...n, f i) := rfl
end add_monoid
section finset
variables {A : Type} [add_comm_monoid A]
open finset
proposition sum_up_to_eq_Sum_upto (n : ℕ) (f : ℕ → A) :
(∑ i < n, f i) = (∑ i ∈ upto n, f i) :=
begin
induction n with n ih,
{exact rfl},
have H : upto n ∩ '{n} = ∅, from
inter_eq_empty
(take x,
suppose x ∈ upto n,
have x < n, from lt_of_mem_upto this,
suppose x ∈ '{n},
have x = n, using this, by rewrite -mem_singleton_iff; apply this,
have n < n, from eq.subst this `x < n`,
show false, from !lt.irrefl this),
rewrite [sum_up_to_succ, ih, upto_succ, Sum_union _ H, Sum_singleton]
end
end finset
section set
variables {A : Type} [add_comm_monoid A]
open set interval
proposition sum_range_eq_sum_interval_aux (m n : ℕ) (f : ℕ → A) :
(∑ i = m...m+n, f i) = (∑ i ∈ '[m, m + n], f i) :=
begin
induction n with n ih,
{rewrite [nat.add_zero, sum_range_self, Icc_self, Sum_singleton]},
have H : m ≤ succ (m + n), from le_of_lt (lt_of_le_of_lt !le_add_right !lt_succ_self),
have H' : '[m, m + n] ∩ '{succ (m + n)} = ∅, from
eq_empty_of_forall_not_mem (take x, assume H1,
have x = succ (m + n), from eq_of_mem_singleton (and.right H1),
have succ (m + n) ≤ m + n, from eq.subst this (and.right (and.left H1)),
show false, from not_lt_of_ge this !lt_succ_self),
rewrite [add_succ, sum_range_succ f H, Icc_eq_Icc_union_Ioc !le_add_right !le_succ,
nat.Ioc_eq_Icc_succ, Icc_self, Sum_union f H', Sum_singleton, ih]
end
proposition sum_range_eq_sum_interval {m n : ℕ} (f : ℕ → A) (H : m ≤ n) :
(∑ i = m...n, f i) = (∑ i ∈ '[m, n], f i) :=
have n = m + (n - m), by rewrite [add.comm, nat.sub_add_cancel H],
using this, by rewrite this; apply sum_range_eq_sum_interval_aux
proposition sum_range_offset (m n : ℕ) (f : ℕ → A) :
(∑ i = m...m+n, f i) = (∑ i = 0...n, f (m + i)) :=
have bij_on (add m) ('[0, n]) ('[m, m+n]), from !nat.bij_on_add_Icc_zero,
by+ rewrite [-zero_add n at {2}, *sum_range_eq_sum_interval_aux, Sum_eq_of_bij_on f this, zero_add]
end set
/- products -/
section monoid
variables {A : Type} [monoid A]
definition prod_up_to (n : ℕ) (f : ℕ → A) : A :=
nat.rec_on n 1 (λ n a, a * f n)
notation `∏` binders ` < ` n `, ` r:(scoped f, prod_up_to n f) := r
proposition prod_up_to_zero (f : ℕ → A) : (∏ i < 0, f i) = 1 := rfl
proposition prod_up_to_succ (n : ℕ) (f : ℕ → A) : (∏ i < succ n, f i) = (∏ i < n, f i) * f n := rfl
proposition prod_up_to_one (f : ℕ → A) : (∏ i < 1, f i) = f 0 := one_mul (f 0)
definition prod_range (m n : ℕ) (f : ℕ → A) : A := prod_up_to (succ n - m) (λ i, f (i + m))
notation `∏` binders `=` m `...` n `, ` r:(scoped f, prod_range m n f) := r
proposition prod_range_def (m n : ℕ) (f : ℕ → A) :
(∏ i = m...n, f i) = (∏ i < (succ n - m), f (i + m)) := rfl
proposition prod_range_self (m : ℕ) (f : ℕ → A) :
(∏ i = m...m, f i) = f m :=
by krewrite [↑prod_range, succ_sub !le.refl, nat.sub_self, prod_up_to_one, zero_add]
proposition prod_range_succ {m n : ℕ} (f : ℕ → A) (H : m ≤ succ n) :
(∏ i = m...succ n, f i) = (∏ i = m...n, f i) * f (succ n) :=
by rewrite [↑prod_range, succ_sub H, prod_up_to_succ, nat.sub_add_cancel H]
proposition prod_up_to_succ_eq_prod_range_zero (n : ℕ) (f : ℕ → A) :
(∏ i < succ n, f i) = (∏ i = 0...n, f i) := rfl
end monoid
section finset
variables {A : Type} [comm_monoid A]
open finset
proposition prod_up_to_eq_Prod_upto (n : ℕ) (f : ℕ → A) :
(∏ i < n, f i) = (∏ i ∈ upto n, f i) :=
begin
induction n with n ih,
{exact rfl},
have H : upto n ∩ '{n} = ∅, from
inter_eq_empty
(take x,
suppose x ∈ upto n,
have x < n, from lt_of_mem_upto this,
suppose x ∈ '{n},
have x = n, using this, by rewrite -mem_singleton_iff; apply this,
have n < n, from eq.subst this `x < n`,
show false, from !lt.irrefl this),
rewrite [prod_up_to_succ, ih, upto_succ, Prod_union _ H, Prod_singleton]
end
end finset
section set
variables {A : Type} [comm_monoid A]
open set interval
proposition prod_range_eq_prod_interval_aux (m n : ℕ) (f : ℕ → A) :
(∏ i = m...m+n, f i) = (∏ i ∈ '[m, m + n], f i) :=
begin
induction n with n ih,
{rewrite [nat.add_zero, prod_range_self, Icc_self, Prod_singleton]},
have H : m ≤ succ (m + n), from le_of_lt (lt_of_le_of_lt !le_add_right !lt_succ_self),
have H' : '[m, m + n] ∩ '{succ (m + n)} = ∅, from
eq_empty_of_forall_not_mem (take x, assume H1,
have x = succ (m + n), from eq_of_mem_singleton (and.right H1),
have succ (m + n) ≤ m + n, from eq.subst this (and.right (and.left H1)),
show false, from not_lt_of_ge this !lt_succ_self),
rewrite [add_succ, prod_range_succ f H, Icc_eq_Icc_union_Ioc !le_add_right !le_succ,
nat.Ioc_eq_Icc_succ, Icc_self, Prod_union f H', Prod_singleton, ih]
end
proposition prod_range_eq_prod_interval {m n : ℕ} (f : ℕ → A) (H : m ≤ n) :
(∏ i = m...n, f i) = (∏ i ∈ '[m, n], f i) :=
have n = m + (n - m), by rewrite [add.comm, nat.sub_add_cancel H],
using this, by rewrite this; apply prod_range_eq_prod_interval_aux
proposition prod_range_offset (m n : ℕ) (f : ℕ → A) :
(∏ i = m...m+n, f i) = (∏ i = 0...n, f (m + i)) :=
have bij_on (add m) ('[0, n]) ('[m, m+n]), from !nat.bij_on_add_Icc_zero,
by+ rewrite [-zero_add n at {2}, *prod_range_eq_prod_interval_aux, Prod_eq_of_bij_on f this,
zero_add]
end set
end nat
|
3d1f9d48a0c6ba429aef8c38d452156b115034bb | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/topology/metric_space/emetric_paracompact.lean | 39cd889359e506647849b4d4aab160857fdbfbc9 | [
"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 | 8,360 | lean | /-
Copyright (c) 202 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import topology.metric_space.emetric_space
import topology.paracompact
import set_theory.ordinal
/-!
# (Extended) metric spaces are paracompact
In this file we provide two instances:
* `emetric.paracompact_space`: a `pseudo_emetric_space` is paracompact; formalization is based
on [MR0236876];
* `emetric.normal_of_metric`: an `emetric_space` is a normal topological space.
## Tags
metric space, paracompact space, normal space
-/
variable {α : Type*}
open_locale ennreal topological_space
open set
namespace emetric
/-- A `pseudo_emetric_space` is always a paracompact space. Formalization is based
on [MR0236876]. -/
@[priority 100] -- See note [lower instance priority]
instance [pseudo_emetric_space α] : paracompact_space α :=
begin
classical,
/- We start with trivial observations about `1 / 2 ^ k`. Here and below we use `1 / 2 ^ k` in
the comments and `2⁻¹ ^ k` in the code. -/
have pow_pos : ∀ k : ℕ, (0 : ℝ≥0∞) < 2⁻¹ ^ k,
from λ k, ennreal.pow_pos (ennreal.inv_pos.2 ennreal.two_ne_top) _,
have hpow_le : ∀ {m n : ℕ}, m ≤ n → (2⁻¹ : ℝ≥0∞) ^ n ≤ 2⁻¹ ^ m,
from λ m n h, ennreal.pow_le_pow_of_le_one (ennreal.inv_le_one.2 ennreal.one_lt_two.le) h,
have h2pow : ∀ n : ℕ, 2 * (2⁻¹ : ℝ≥0∞) ^ (n + 1) = 2⁻¹ ^ n,
by { intro n, simp [pow_succ, ← mul_assoc, ennreal.mul_inv_cancel] },
-- Consider an open covering `S : set (set α)`
refine ⟨λ ι s ho hcov, _⟩,
simp only [Union_eq_univ_iff] at hcov,
-- choose a well founded order on `S`
letI : linear_order ι := linear_order_of_STO' well_ordering_rel,
have wf : well_founded ((<) : ι → ι → Prop) := @is_well_order.wf ι well_ordering_rel _,
-- Let `ind x` be the minimal index `s : S` such that `x ∈ s`.
set ind : α → ι := λ x, wf.min {i : ι | x ∈ s i} (hcov x),
have mem_ind : ∀ x, x ∈ s (ind x), from λ x, wf.min_mem _ (hcov x),
have nmem_of_lt_ind : ∀ {x i}, i < (ind x) → x ∉ s i,
from λ x i hlt hxi, wf.not_lt_min _ (hcov x) hxi hlt,
/- The refinement `D : ℕ → ι → set α` is defined recursively. For each `n` and `i`, `D n i`
is the union of balls `ball x (1 / 2 ^ n)` over all points `x` such that
* `ind x = i`;
* `x` does not belong to any `D m j`, `m < n`;
* `ball x (3 / 2 ^ n) ⊆ s i`;
We define this sequence using `nat.strong_rec_on'`, then restate it as `Dn` and `memD`.
-/
set D : ℕ → ι → set α :=
λ n, nat.strong_rec_on' n (λ n D' i,
⋃ (x : α) (hxs : ind x = i) (hb : ball x (3 * 2⁻¹ ^ n) ⊆ s i)
(hlt : ∀ (m < n) (j : ι), x ∉ D' m ‹_› j), ball x (2⁻¹ ^ n)),
have Dn : ∀ n i, D n i = ⋃ (x : α) (hxs : ind x = i) (hb : ball x (3 * 2⁻¹ ^ n) ⊆ s i)
(hlt : ∀ (m < n) (j : ι), x ∉ D m j), ball x (2⁻¹ ^ n),
from λ n s, by { simp only [D], rw nat.strong_rec_on_beta' },
have memD : ∀ {n i y}, y ∈ D n i ↔ ∃ x (hi : ind x = i) (hb : ball x (3 * 2⁻¹ ^ n) ⊆ s i)
(hlt : ∀ (m < n) (j : ι), x ∉ D m j), edist y x < 2⁻¹ ^ n,
{ intros n i y, rw [Dn n i], simp only [mem_Union, mem_ball] },
-- The sets `D n i` cover the whole space. Indeed, for each `x` we can choose `n` such that
-- `ball x (3 / 2 ^ n) ⊆ s (ind x)`, then either `x ∈ D n i`, or `x ∈ D m i` for some `m < n`.
have Dcov : ∀ x, ∃ n i, x ∈ D n i,
{ intro x,
obtain ⟨n, hn⟩ : ∃ n : ℕ, ball x (3 * 2⁻¹ ^ n) ⊆ s (ind x),
{ -- This proof takes 5 lines because we can't import `specific_limits` here
rcases is_open_iff.1 (ho $ ind x) x (mem_ind x) with ⟨ε, ε0, hε⟩,
have : 0 < ε / 3 := ennreal.div_pos_iff.2 ⟨ε0.lt.ne', ennreal.coe_ne_top⟩,
rcases ennreal.exists_inv_two_pow_lt this.ne' with ⟨n, hn⟩,
refine ⟨n, subset.trans (ball_subset_ball _) hε⟩,
simpa only [div_eq_mul_inv, mul_comm] using (ennreal.mul_lt_of_lt_div hn).le },
by_contra' h,
apply h n (ind x),
exact memD.2 ⟨x, rfl, hn, λ _ _ _, h _ _, mem_ball_self (pow_pos _)⟩ },
-- Each `D n i` is a union of open balls, hence it is an open set
have Dopen : ∀ n i, is_open (D n i),
{ intros n i,
rw Dn,
iterate 4 { refine is_open_Union (λ _, _) },
exact is_open_ball },
-- the covering `D n i` is a refinement of the original covering: `D n i ⊆ s i`
have HDS : ∀ n i, D n i ⊆ s i,
{ intros n s x,
rw memD,
rintro ⟨y, rfl, hsub, -, hyx⟩,
refine hsub (lt_of_lt_of_le hyx _),
calc 2⁻¹ ^ n = 1 * 2⁻¹ ^ n : (one_mul _).symm
... ≤ 3 * 2⁻¹ ^ n : ennreal.mul_le_mul _ le_rfl,
-- TODO: use `norm_num`
have : ((1 : ℕ) : ℝ≥0∞) ≤ (3 : ℕ), from ennreal.coe_nat_le_coe_nat.2 (by norm_num1),
exact_mod_cast this },
-- Let us show the rest of the properties. Since the definition expects a family indexed
-- by a single parameter, we use `ℕ × ι` as the domain.
refine ⟨ℕ × ι, λ ni, D ni.1 ni.2, λ _, Dopen _ _, _, _, λ ni, ⟨ni.2, HDS _ _⟩⟩,
-- The sets `D n i` cover the whole space as we proved earlier
{ refine Union_eq_univ_iff.2 (λ x, _),
rcases Dcov x with ⟨n, i, h⟩,
exact ⟨⟨n, i⟩, h⟩ },
{ /- Let us prove that the covering `D n i` is locally finite. Take a point `x` and choose
`n`, `i` so that `x ∈ D n i`. Since `D n i` is an open set, we can choose `k` so that
`B = ball x (1 / 2 ^ (n + k + 1)) ⊆ D n i`. -/
intro x,
rcases Dcov x with ⟨n, i, hn⟩,
have : D n i ∈ 𝓝 x, from is_open.mem_nhds (Dopen _ _) hn,
rcases (nhds_basis_uniformity uniformity_basis_edist_inv_two_pow).mem_iff.1 this
with ⟨k, -, hsub : ball x (2⁻¹ ^ k) ⊆ D n i⟩,
set B := ball x (2⁻¹ ^ (n + k + 1)),
refine ⟨B, ball_mem_nhds _ (pow_pos _), _⟩,
-- The sets `D m i`, `m > n + k`, are disjoint with `B`
have Hgt : ∀ (m ≥ n + k + 1) (i : ι), disjoint (D m i) B,
{ rintros m hm i y ⟨hym, hyx⟩,
rcases memD.1 hym with ⟨z, rfl, hzi, H, hz⟩,
have : z ∉ ball x (2⁻¹ ^ k), from λ hz, H n (by linarith) i (hsub hz), apply this,
calc edist z x ≤ edist y z + edist y x : edist_triangle_left _ _ _
... < (2⁻¹ ^ m) + (2⁻¹ ^ (n + k + 1)) : ennreal.add_lt_add hz hyx
... ≤ (2⁻¹ ^ (k + 1)) + (2⁻¹ ^ (k + 1)) :
add_le_add (hpow_le $ by linarith) (hpow_le $ by linarith)
... = (2⁻¹ ^ k) : by rw [← two_mul, h2pow] },
-- For each `m ≤ n + k` there is at most one `j` such that `D m j ∩ B` is nonempty.
have Hle : ∀ m ≤ n + k, set.subsingleton {j | (D m j ∩ B).nonempty},
{ rintros m hm j₁ ⟨y, hyD, hyB⟩ j₂ ⟨z, hzD, hzB⟩,
by_contra h,
wlog h : j₁ < j₂ := ne.lt_or_lt h using [j₁ j₂ y z, j₂ j₁ z y],
rcases memD.1 hyD with ⟨y', rfl, hsuby, -, hdisty⟩,
rcases memD.1 hzD with ⟨z', rfl, -, -, hdistz⟩,
suffices : edist z' y' < 3 * 2⁻¹ ^ m, from nmem_of_lt_ind h (hsuby this),
calc edist z' y' ≤ edist z' x + edist x y' : edist_triangle _ _ _
... ≤ (edist z z' + edist z x) + (edist y x + edist y y') :
add_le_add (edist_triangle_left _ _ _) (edist_triangle_left _ _ _)
... < (2⁻¹ ^ m + 2⁻¹ ^ (n + k + 1)) + (2⁻¹ ^ (n + k + 1) + 2⁻¹ ^ m) :
by apply_rules [ennreal.add_lt_add]
... = 2 * (2⁻¹ ^ m + 2⁻¹ ^ (n + k + 1)) : by simp only [two_mul, add_comm]
... ≤ 2 * (2⁻¹ ^ m + 2⁻¹ ^ (m + 1)) :
ennreal.mul_le_mul le_rfl $ add_le_add le_rfl $ hpow_le (add_le_add hm le_rfl)
... = 3 * 2⁻¹ ^ m : by rw [mul_add, h2pow, bit1, add_mul, one_mul] },
-- Finally, we glue `Hgt` and `Hle`
have : (⋃ (m ≤ n + k) (i ∈ {i : ι | (D m i ∩ B).nonempty}), {(m, i)}).finite,
from (finite_le_nat _).bUnion (λ i hi, (Hle i hi).finite.bUnion (λ _ _, finite_singleton _)),
refine this.subset (λ I hI, _), simp only [mem_Union],
refine ⟨I.1, _, I.2, hI, prod.mk.eta.symm⟩,
exact not_lt.1 (λ hlt, Hgt I.1 hlt I.2 hI.some_spec) }
end
@[priority 100] -- see Note [lower instance priority]
instance normal_of_emetric [emetric_space α] : normal_space α := normal_of_paracompact_t2
end emetric
|
c85e4c3335bb7af9d169955c9cfcf66c96afd2b3 | e4a7c8ab8b68ca0e53d2c21397320ea590fa01c6 | /src/data/polya/field/sterm.lean | babc4c2452a2bcbfad557225516411372339bd8a | [] | no_license | lean-forward/field | 3ff5dc5f43de40f35481b375f8c871cd0a07c766 | 7e2127ad485aec25e58a1b9c82a6bb74a599467a | refs/heads/master | 1,590,947,010,909 | 1,563,811,881,000 | 1,563,811,881,000 | 190,415,651 | 1 | 0 | null | 1,563,643,371,000 | 1,559,746,688,000 | Lean | UTF-8 | Lean | false | false | 8,134 | lean | import .basic
namespace polya.field
open nterm
--@[derive decidable_eq]
structure cterm (γ : Type) [const_space γ] : Type :=
(term : nterm γ)
(coeff : γ)
(pr : coeff ≠ 0)
namespace cterm
variables {α : Type} [discrete_field α]
variables {γ : Type} [const_space γ]
variables [morph γ α] {ρ : dict α}
instance : inhabited (cterm γ) := ⟨⟨nterm.const 0, 1, by simp⟩⟩
def to_nterm (x : cterm γ) : nterm γ :=
x.term * x.coeff
def eval (ρ : dict α) (x : cterm γ) : α :=
nterm.eval ρ x.term * ↑x.coeff
@[simp]
def eval_to_nterm {x : cterm γ} :
nterm.eval ρ x.to_nterm = cterm.eval ρ x :=
begin
simp [to_nterm, nterm.eval, cterm.eval]
end
theorem eval_to_nterm' :
nterm.eval ρ ∘ @cterm.to_nterm γ _ = cterm.eval ρ :=
begin
unfold function.comp,
simp [eval_to_nterm]
end
--TODO
theorem eval_def {x : nterm γ} {c : γ} {hc : c ≠ 0} :
cterm.eval ρ ⟨x, c, hc⟩ = nterm.eval ρ x * ↑c :=
rfl
theorem eval_add {x : nterm γ} {a b : γ}
{ha : a ≠ 0} {hb : b ≠ 0} {hc : a + b ≠ 0} :
cterm.eval ρ ⟨x, a + b, hc⟩ = cterm.eval ρ ⟨x, a, ha⟩ + cterm.eval ρ ⟨x, b, hb⟩ :=
begin
simp [eval_def, morph.morph_add, mul_add],
end
def mul (x : cterm γ) (a : γ) (ha : a ≠ 0) : cterm γ :=
⟨x.term, x.coeff * a, by simp [ha, x.pr]⟩
theorem eval_mul {x : cterm γ} {a : γ} {ha : a ≠ 0} :
cterm.eval ρ (x.mul a ha) = cterm.eval ρ x * ↑a :=
begin
simp [cterm.eval, morph.morph_mul, mul], ring
end
theorem eval_mul' {a : γ} {ha : a ≠ 0} :
cterm.eval ρ ∘ (λ x : cterm γ, x.mul a ha) =
λ x, cterm.eval ρ x * (a : α) :=
begin
unfold function.comp,
simp [eval_mul]
end
theorem eval_sum_mul {xs : list (cterm γ)} {a : γ} {ha : a ≠ 0} :
list.sum (list.map (cterm.eval ρ) xs) * ↑a
= list.sum (list.map (λ x : cterm γ, cterm.eval ρ (x.mul a ha)) xs) :=
begin
induction xs with x xs ih,
{ simp },
{ repeat {rw [list.map_cons, list.sum_cons]},
rw [eval_mul, add_mul, ih] }
end
def smerge : list (cterm γ) → list (cterm γ) → list (cterm γ)
| (x::xs) (y::ys) :=
if x.term = y.term then
let c := x.coeff + y.coeff in
if hc : c = 0 then smerge xs ys
else ⟨x.term, c, hc⟩ :: smerge xs ys
else if x.term < y.term then
x :: smerge xs (y::ys)
else
y :: smerge (x::xs) ys
| xs [] := xs
| [] ys := ys
lemma smerge_nil_left {ys : list (cterm γ)} :
smerge [] ys = ys :=
begin
induction ys with y ys ih,
{ unfold smerge },
{ unfold smerge }
end
lemma smerge_nil_right {xs : list (cterm γ)} :
smerge xs [] = xs :=
begin
induction xs with x xs ih,
{ unfold smerge },
{ unfold smerge }
end
lemma smerge_def1 {x y : cterm γ} {xs ys : list (cterm γ)} :
x.term = y.term → x.coeff + y.coeff = 0 →
smerge (x::xs) (y::ys) = smerge xs ys :=
by intros h1 h2; simp [smerge, h1, h2]
lemma smerge_def2 {x y : cterm γ} {xs ys : list (cterm γ)} :
x.term = y.term → Π (hc : x.coeff + y.coeff ≠ 0),
smerge (x::xs) (y::ys) = ⟨x.term, x.coeff + y.coeff, hc⟩ :: smerge xs ys :=
by intros h1 h2; simp [smerge, h1, h2]
lemma smerge_def3 {x y : cterm γ} {xs ys : list (cterm γ)} :
x.term ≠ y.term → x.term < y.term →
smerge (x::xs) (y::ys) = x :: smerge xs (y :: ys) :=
by intros h1 h2; simp [smerge, h1, h2]
lemma smerge_def4 {x y : cterm γ} {xs ys : list (cterm γ)} :
x.term ≠ y.term → ¬ x.term < y.term →
smerge (x::xs) (y::ys) = y :: smerge (x::xs) ys :=
by intros h1 h2; simp [smerge, h1, h2]
theorem eval_smerge (xs ys : list (cterm γ)) :
list.sum (list.map (cterm.eval ρ) (smerge xs ys))
= list.sum (list.map (cterm.eval ρ) xs)
+ list.sum (list.map (cterm.eval ρ) ys) :=
begin
revert ys,
induction xs with x xs ihx,
{ intro ys, simp [smerge_nil_left] },
{ intro ys, induction ys with y ys ihy,
{ simp [smerge_nil_right] },
{ by_cases h1 : x.term = y.term,
{ by_cases h2 : x.coeff + y.coeff = 0,
{ have : eval ρ x = - eval ρ y,
by {
rw add_eq_zero_iff_eq_neg at h2,
unfold cterm.eval, rw [h1, h2, morph.morph_neg],
ring },
rw [smerge_def1 h1 h2, ihx],
repeat {rw [list.map_cons, list.sum_cons]},
rw this, ring },
{ rw smerge_def2 h1 h2,
cases x with x n, cases y with y m,
simp only [] at h1, rw h1 at *,
repeat {rw [list.map_cons, list.sum_cons]},
rw [eval_add, ihx ys], { simp },
repeat {assumption }}},
{ by_cases h2 : x.term < y.term,
{ rw smerge_def3 h1 h2,
repeat {rw [list.map_cons, list.sum_cons]},
rw [ihx (y::ys), list.map_cons, list.sum_cons],
ring},
{ rw smerge_def4 h1 h2,
repeat {rw [list.map_cons, list.sum_cons]},
rw [ihy, list.map_cons, list.sum_cons],
ring}}}}
end
end cterm
structure sterm (γ : Type) [const_space γ] : Type :=
(terms : list (cterm γ))
namespace sterm
variables {α : Type} [discrete_field α]
variables {γ : Type} [const_space γ]
variables [morph γ α] {ρ : dict α}
def of_const (a : γ) : sterm γ :=
if ha : a = 0 then { terms := [] }
else { terms := [⟨1, a, ha⟩] }
def singleton (x : nterm γ) : sterm γ :=
{ terms := [⟨x, 1, by simp⟩] }
def eval (ρ : dict α) (S : sterm γ) : α :=
list.sum (S.terms.map (cterm.eval ρ))
theorem eval_of_const (a : γ) :
sterm.eval ρ (of_const a) = ↑a :=
begin
by_cases ha : a = 0;
simp [of_const, sterm.eval, cterm.eval, ha]
end
theorem eval_singleton (x : nterm γ) :
sterm.eval ρ (singleton x) = nterm.eval ρ x :=
begin
by_cases hx : nterm.eval ρ x = 0,
repeat {simp [singleton, sterm.eval, cterm.eval, hx]}
end
--mul
def add (S T : sterm γ) : sterm γ :=
{ terms := cterm.smerge S.terms T.terms, }
--pow
def mul (S : sterm γ) (a : γ) : sterm γ :=
if ha : a = 0 then { terms := [] }
else { terms := S.terms.map (λ x, cterm.mul x a ha), }
instance : has_add (sterm γ) := ⟨add⟩
theorem add_terms {S T : sterm γ} :
(S + T).terms = cterm.smerge S.terms T.terms :=
by simp [has_add.add, add]
theorem eval_add {S T : sterm γ} :
sterm.eval ρ (S + T) = sterm.eval ρ S + sterm.eval ρ T :=
begin
unfold sterm.eval,
rw [add_terms, cterm.eval_smerge]
end
theorem eval_mul {S : sterm γ} {a : γ} :
sterm.eval ρ (S.mul a) = sterm.eval ρ S * ↑a :=
begin
by_cases ha : a = 0,
{ simp [mul, eval, ha] },
{ unfold sterm.eval, unfold mul,
rw cterm.eval_sum_mul,
{ simp [ha] },
{ exact ha }}
end
def to_nterm (S : sterm γ) : nterm γ :=
match S.terms with
| [] := 0
| [x] := x.to_nterm
| (x0::xs) :=
have h0 : x0.coeff⁻¹ ≠ 0, by simp [x0.pr],
( nterm.sum (xs.map (λ x, (x.mul x0.coeff⁻¹ h0).to_nterm))
+ x0.term * 1 ) * x0.coeff
end
theorem eval_to_nterm {S : sterm γ} :
sterm.eval ρ S = nterm.eval ρ S.to_nterm :=
begin
cases S with xs,
cases xs with x0 xs,
{ simp [eval, to_nterm] },
cases xs with x1 xs,
{ simp [eval, to_nterm] },
unfold eval, unfold to_nterm,
rw [nterm.eval_mul, nterm.eval_add, nterm.eval_sum, nterm.eval_const],
rw [← list.map_map cterm.to_nterm,
list.map_map _ cterm.to_nterm,
cterm.eval_to_nterm', list.map_map,
← cterm.eval_sum_mul],
rw [add_mul, mul_assoc, ← morph.morph_mul, inv_mul_cancel,
morph.morph_one', mul_one],
swap, by simp [x0.pr],
rw [list.map_cons, list.sum_cons],
rw [nterm.eval_mul, nterm.eval_one, mul_one],
unfold cterm.eval, apply add_comm
end
def of_nterm : nterm γ → sterm γ
| (nterm.add x y) := of_nterm x + of_nterm y
| (nterm.mul x (nterm.const a)) := (of_nterm x).mul a
| (nterm.const a) := of_const a
| x := singleton x
theorem eval_of_nterm {x : nterm γ} :
sterm.eval ρ (of_nterm x) = nterm.eval ρ x :=
begin
induction x with i c x y ihx ihy x y ihx ihy x n ihx,
{ simp [of_nterm, eval_singleton] },
{ simp [of_nterm, eval_of_const, nterm.eval] },
{ simp [of_nterm, eval_add, nterm.eval, ihx, ihy] },
{ cases y; try {simp [of_nterm, eval_singleton]},
simp [eval_mul, nterm.eval, ihx] },
{ simp [of_nterm, eval_singleton] }
end
end sterm
end polya.field
|
8a85c4f4ac6e3f6ad5f32dbb7875ab8ca786fc90 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/lake/test/75/foo/Main.lean | fbeacd4c97339bf797d712b0d39f57d0a2970357 | [
"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 | 67 | lean | import Foo
def main : IO Unit :=
IO.println s!"Hello, {hello}!"
|
3e395cd9cdf2a84adb72f2eb99508667f641885f | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/topology/metric_space/antilipschitz.lean | 596c61b8444839447226aa2109e6611148eb5771 | [
"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 | 5,443 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import topology.metric_space.lipschitz
/-!
# Antilipschitz functions
We say that a map `f : α → β` between two (extended) metric spaces is
`antilipschitz_with K`, `K ≥ 0`, if for all `x, y` we have `edist x y ≤ K * edist (f x) (f y)`.
For a metric space, the latter inequality is equivalent to `dist x y ≤ K * dist (f x) (f y)`.
## Implementation notes
The parameter `K` has type `ℝ≥0`. This way we avoid conjuction in the definition and have
coercions both to `ℝ` and `ennreal`. We do not require `0 < K` in the definition, mostly because
we do not have a `posreal` type.
-/
variables {α : Type*} {β : Type*} {γ : Type*}
open_locale nnreal
open set
/-- We say that `f : α → β` is `antilipschitz_with K` if for any two points `x`, `y` we have
`K * edist x y ≤ edist (f x) (f y)`. -/
def antilipschitz_with [emetric_space α] [emetric_space β] (K : ℝ≥0) (f : α → β) :=
∀ x y, edist x y ≤ K * edist (f x) (f y)
lemma antilipschitz_with_iff_le_mul_dist [metric_space α] [metric_space β] {K : ℝ≥0} {f : α → β} :
antilipschitz_with K f ↔ ∀ x y, dist x y ≤ K * dist (f x) (f y) :=
by { simp only [antilipschitz_with, edist_nndist, dist_nndist], norm_cast }
alias antilipschitz_with_iff_le_mul_dist ↔ antilipschitz_with.le_mul_dist
antilipschitz_with.of_le_mul_dist
lemma antilipschitz_with.mul_le_dist [metric_space α] [metric_space β] {K : ℝ≥0} {f : α → β}
(hf : antilipschitz_with K f) (x y : α) :
↑K⁻¹ * dist x y ≤ dist (f x) (f y) :=
begin
by_cases hK : K = 0, by simp [hK, dist_nonneg],
rw [nnreal.coe_inv, ← div_eq_inv_mul],
rw div_le_iff' (nnreal.coe_pos.2 $ pos_iff_ne_zero.2 hK),
exact hf.le_mul_dist x y
end
namespace antilipschitz_with
variables [emetric_space α] [emetric_space β] [emetric_space γ] {K : ℝ≥0} {f : α → β}
/-- Extract the constant from `hf : antilipschitz_with K f`. This is useful, e.g.,
if `K` is given by a long formula, and we want to reuse this value. -/
@[nolint unused_arguments] -- uses neither `f` nor `hf`
protected def K (hf : antilipschitz_with K f) : ℝ≥0 := K
protected lemma injective (hf : antilipschitz_with K f) :
function.injective f :=
λ x y h, by simpa only [h, edist_self, mul_zero, edist_le_zero] using hf x y
lemma mul_le_edist (hf : antilipschitz_with K f) (x y : α) :
↑K⁻¹ * edist x y ≤ edist (f x) (f y) :=
begin
by_cases hK : K = 0, by simp [hK],
rw [ennreal.coe_inv hK, mul_comm, ← div_eq_mul_inv],
apply ennreal.div_le_of_le_mul,
rw mul_comm,
exact hf x y
end
protected lemma id : antilipschitz_with 1 (id : α → α) :=
λ x y, by simp only [ennreal.coe_one, one_mul, id, le_refl]
lemma comp {Kg : ℝ≥0} {g : β → γ} (hg : antilipschitz_with Kg g)
{Kf : ℝ≥0} {f : α → β} (hf : antilipschitz_with Kf f) :
antilipschitz_with (Kf * Kg) (g ∘ f) :=
λ x y,
calc edist x y ≤ Kf * edist (f x) (f y) : hf x y
... ≤ Kf * (Kg * edist (g (f x)) (g (f y))) : ennreal.mul_left_mono (hg _ _)
... = _ : by rw [ennreal.coe_mul, mul_assoc]
lemma restrict (hf : antilipschitz_with K f) (s : set α) :
antilipschitz_with K (s.restrict f) :=
λ x y, hf x y
lemma cod_restrict (hf : antilipschitz_with K f) {s : set β} (hs : ∀ x, f x ∈ s) :
antilipschitz_with K (s.cod_restrict f hs) :=
λ x y, hf x y
lemma to_right_inv_on' {s : set α} (hf : antilipschitz_with K (s.restrict f))
{g : β → α} {t : set β} (g_maps : maps_to g t s) (g_inv : right_inv_on g f t) :
lipschitz_with K (t.restrict g) :=
λ x y, by simpa only [restrict_apply, g_inv x.mem, g_inv y.mem, subtype.edist_eq, subtype.coe_mk]
using hf ⟨g x, g_maps x.mem⟩ ⟨g y, g_maps y.mem⟩
lemma to_right_inv_on (hf : antilipschitz_with K f) {g : β → α} {t : set β}
(h : right_inv_on g f t) :
lipschitz_with K (t.restrict g) :=
(hf.restrict univ).to_right_inv_on' (maps_to_univ g t) h
lemma to_right_inverse (hf : antilipschitz_with K f) {g : β → α} (hg : function.right_inverse g f) :
lipschitz_with K g :=
begin
intros x y,
have := hf (g x) (g y),
rwa [hg x, hg y] at this
end
lemma uniform_embedding (hf : antilipschitz_with K f) (hfc : uniform_continuous f) :
uniform_embedding f :=
begin
refine emetric.uniform_embedding_iff.2 ⟨hf.injective, hfc, λ δ δ0, _⟩,
by_cases hK : K = 0,
{ refine ⟨1, ennreal.zero_lt_one, λ x y _, lt_of_le_of_lt _ δ0⟩,
simpa only [hK, ennreal.coe_zero, zero_mul] using hf x y },
{ refine ⟨K⁻¹ * δ, _, λ x y hxy, lt_of_le_of_lt (hf x y) _⟩,
{ exact canonically_ordered_semiring.mul_pos.2 ⟨ennreal.inv_pos.2 ennreal.coe_ne_top, δ0⟩ },
{ rw [mul_comm, ← div_eq_mul_inv] at hxy,
have := ennreal.mul_lt_of_lt_div hxy,
rwa mul_comm } }
end
lemma subtype_coe (s : set α) : antilipschitz_with 1 (coe : s → α) :=
antilipschitz_with.id.restrict s
lemma of_subsingleton [subsingleton α] {K : ℝ≥0} : antilipschitz_with K f :=
λ x y, by simp only [subsingleton.elim x y, edist_self, zero_le]
end antilipschitz_with
lemma lipschitz_with.to_right_inverse [emetric_space α] [emetric_space β] {K : ℝ≥0} {f : α → β}
(hf : lipschitz_with K f) {g : β → α} (hg : function.right_inverse g f) :
antilipschitz_with K g :=
λ x y, by simpa only [hg _] using hf (g x) (g y)
|
78253573671e9280b1e989edbacec29f66c772f1 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/hott/619.hlean | 27e8565f5968f96c224c5c07a9236dd8098b975d | [
"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 | 312 | hlean | -- HoTT
open is_equiv equiv eq
definition my_rec_on_ua [recursor] {A B : Type} {P : A ≃ B → Type}
(f : A ≃ B) (H : Π(q : A = B), P (equiv_of_eq q)) : P f :=
right_inv equiv_of_eq f ▸ H (ua f)
theorem foo {A B : Type} (f : A ≃ B) : A = B :=
begin
induction f using my_rec_on_ua,
assumption
end
|
f180d1893191679a27b624c56225ecdceed6fef6 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/field_theory/subfield.lean | 7646e4832fa7991df4bbb05ed779dccb0eb52905 | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 24,848 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import algebra.algebra.basic
/-!
# Subfields
Let `K` be a field. This file defines the "bundled" subfield type `subfield K`, a type
whose terms correspond to subfields of `K`. This is the preferred way to talk
about subfields in mathlib. Unbundled subfields (`s : set K` and `is_subfield s`)
are not in this file, and they will ultimately be deprecated.
We prove that subfields are a complete lattice, and that you can `map` (pushforward) and
`comap` (pull back) them along ring homomorphisms.
We define the `closure` construction from `set R` to `subfield R`, sending a subset of `R`
to the subfield it generates, and prove that it is a Galois insertion.
## Main definitions
Notation used here:
`(K : Type u) [field K] (L : Type u) [field L] (f g : K →+* L)`
`(A : subfield K) (B : subfield L) (s : set K)`
* `subfield R` : the type of subfields of a ring `R`.
* `instance : complete_lattice (subfield R)` : the complete lattice structure on the subfields.
* `subfield.closure` : subfield closure of a set, i.e., the smallest subfield that includes the set.
* `subfield.gi` : `closure : set M → subfield M` and coercion `coe : subfield M → set M`
form a `galois_insertion`.
* `comap f B : subfield K` : the preimage of a subfield `B` along the ring homomorphism `f`
* `map f A : subfield L` : the image of a subfield `A` along the ring homomorphism `f`.
* `prod A B : subfield (K × L)` : the product of subfields
* `f.field_range : subfield B` : the range of the ring homomorphism `f`.
* `eq_locus_field f g : subfield K` : given ring homomorphisms `f g : K →+* R`,
the subfield of `K` where `f x = g x`
## Implementation notes
A subfield is implemented as a subring which is is closed under `⁻¹`.
Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although
`∈` is defined as membership of a subfield's underlying set.
## Tags
subfield, subfields
-/
open_locale big_operators
universes u v w
variables {K : Type u} {L : Type v} {M : Type w} [field K] [field L] [field M]
set_option old_structure_cmd true
/-- `subfield R` is the type of subfields of `R`. A subfield of `R` is a subset `s` that is a
multiplicative submonoid and an additive subgroup. Note in particular that it shares the
same 0 and 1 as R. -/
structure subfield (K : Type u) [field K] extends subring K :=
(inv_mem' : ∀ x ∈ carrier, x⁻¹ ∈ carrier)
/-- Reinterpret a `subfield` as a `subring`. -/
add_decl_doc subfield.to_subring
namespace subfield
/-- The underlying `add_subgroup` of a subfield. -/
def to_add_subgroup (s : subfield K) : add_subgroup K :=
{ ..s.to_subring.to_add_subgroup }
/-- The underlying submonoid of a subfield. -/
def to_submonoid (s : subfield K) : submonoid K :=
{ ..s.to_subring.to_submonoid }
instance : set_like (subfield K) K :=
⟨subfield.carrier, λ p q h, by cases p; cases q; congr'⟩
@[simp]
lemma mem_carrier {s : subfield K} {x : K} : x ∈ s.carrier ↔ x ∈ s := iff.rfl
@[simp]
lemma mem_mk {S : set K} {x : K} (h₁ h₂ h₃ h₄ h₅ h₆) :
x ∈ (⟨S, h₁, h₂, h₃, h₄, h₅, h₆⟩ : subfield K) ↔ x ∈ S := iff.rfl
@[simp] lemma coe_set_mk (S : set K) (h₁ h₂ h₃ h₄ h₅ h₆) :
((⟨S, h₁, h₂, h₃, h₄, h₅, h₆⟩ : subfield K) : set K) = S := rfl
@[simp]
lemma mk_le_mk {S S' : set K} (h₁ h₂ h₃ h₄ h₅ h₆ h₁' h₂' h₃' h₄' h₅' h₆') :
(⟨S, h₁, h₂, h₃, h₄, h₅, h₆⟩ : subfield K) ≤ (⟨S', h₁', h₂', h₃', h₄', h₅', h₆'⟩ : subfield K) ↔
S ⊆ S' :=
iff.rfl
/-- Two subfields are equal if they have the same elements. -/
@[ext] theorem ext {S T : subfield K} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := set_like.ext h
/-- Copy of a subfield with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (S : subfield K) (s : set K) (hs : s = ↑S) : subfield K :=
{ carrier := s,
inv_mem' := hs.symm ▸ S.inv_mem',
..S.to_subring.copy s hs }
@[simp] lemma coe_to_subring (s : subfield K) : (s.to_subring : set K) = s :=
rfl
@[simp] lemma mem_to_subring (s : subfield K) (x : K) :
x ∈ s.to_subring ↔ x ∈ s := iff.rfl
end subfield
/-- A `subring` containing inverses is a `subfield`. -/
def subring.to_subfield (s : subring K) (hinv : ∀ x ∈ s, x⁻¹ ∈ s) : subfield K :=
{ inv_mem' := hinv
..s }
namespace subfield
variables (s t : subfield K)
/-- A subfield contains the ring's 1. -/
theorem one_mem : (1 : K) ∈ s := s.one_mem'
/-- A subfield contains the ring's 0. -/
theorem zero_mem : (0 : K) ∈ s := s.zero_mem'
/-- A subfield is closed under multiplication. -/
theorem mul_mem : ∀ {x y : K}, x ∈ s → y ∈ s → x * y ∈ s := s.mul_mem'
/-- A subfield is closed under addition. -/
theorem add_mem : ∀ {x y : K}, x ∈ s → y ∈ s → x + y ∈ s := s.add_mem'
/-- A subfield is closed under negation. -/
theorem neg_mem : ∀ {x : K}, x ∈ s → -x ∈ s := s.neg_mem'
/-- A subfield is closed under subtraction. -/
theorem sub_mem {x y : K} : x ∈ s → y ∈ s → x - y ∈ s := s.to_subring.sub_mem
/-- A subfield is closed under inverses. -/
theorem inv_mem : ∀ {x : K}, x ∈ s → x⁻¹ ∈ s := s.inv_mem'
/-- A subfield is closed under division. -/
theorem div_mem {x y : K} (hx : x ∈ s) (hy : y ∈ s) : x / y ∈ s :=
by { rw div_eq_mul_inv, exact s.mul_mem hx (s.inv_mem hy) }
/-- Product of a list of elements in a subfield is in the subfield. -/
lemma list_prod_mem {l : list K} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s :=
s.to_submonoid.list_prod_mem
/-- Sum of a list of elements in a subfield is in the subfield. -/
lemma list_sum_mem {l : list K} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s :=
s.to_add_subgroup.list_sum_mem
/-- Product of a multiset of elements in a subfield is in the subfield. -/
lemma multiset_prod_mem (m : multiset K) :
(∀ a ∈ m, a ∈ s) → m.prod ∈ s :=
s.to_submonoid.multiset_prod_mem m
/-- Sum of a multiset of elements in a `subfield` is in the `subfield`. -/
lemma multiset_sum_mem (m : multiset K) :
(∀ a ∈ m, a ∈ s) → m.sum ∈ s :=
s.to_add_subgroup.multiset_sum_mem m
/-- Product of elements of a subfield indexed by a `finset` is in the subfield. -/
lemma prod_mem {ι : Type*} {t : finset ι} {f : ι → K} (h : ∀ c ∈ t, f c ∈ s) :
∏ i in t, f i ∈ s :=
s.to_submonoid.prod_mem h
/-- Sum of elements in a `subfield` indexed by a `finset` is in the `subfield`. -/
lemma sum_mem {ι : Type*} {t : finset ι} {f : ι → K} (h : ∀ c ∈ t, f c ∈ s) :
∑ i in t, f i ∈ s :=
s.to_add_subgroup.sum_mem h
lemma pow_mem {x : K} (hx : x ∈ s) (n : ℕ) : x^n ∈ s := s.to_submonoid.pow_mem hx n
lemma gsmul_mem {x : K} (hx : x ∈ s) (n : ℤ) :
n • x ∈ s := s.to_add_subgroup.gsmul_mem hx n
lemma coe_int_mem (n : ℤ) : (n : K) ∈ s :=
by simp only [← gsmul_one, gsmul_mem, one_mem]
instance : ring s := s.to_subring.to_ring
instance : has_div s := ⟨λ x y, ⟨x / y, s.div_mem x.2 y.2⟩⟩
instance : has_inv s := ⟨λ x, ⟨x⁻¹, s.inv_mem x.2⟩⟩
/-- A subfield inherits a field structure -/
instance to_field : field s :=
subtype.coe_injective.field coe
rfl rfl (λ _ _, rfl) (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl)
/-- A subfield of a `linear_ordered_field` is a `linear_ordered_field`. -/
instance to_linear_ordered_field {K} [linear_ordered_field K] (s : subfield K) :
linear_ordered_field s :=
subtype.coe_injective.linear_ordered_field coe
rfl rfl (λ _ _, rfl) (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl)
@[simp, norm_cast] lemma coe_add (x y : s) : (↑(x + y) : K) = ↑x + ↑y := rfl
@[simp, norm_cast] lemma coe_sub (x y : s) : (↑(x - y) : K) = ↑x - ↑y := rfl
@[simp, norm_cast] lemma coe_neg (x : s) : (↑(-x) : K) = -↑x := rfl
@[simp, norm_cast] lemma coe_mul (x y : s) : (↑(x * y) : K) = ↑x * ↑y := rfl
@[simp, norm_cast] lemma coe_div (x y : s) : (↑(x / y) : K) = ↑x / ↑y := rfl
@[simp, norm_cast] lemma coe_inv (x : s) : (↑(x⁻¹) : K) = (↑x)⁻¹ := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : s) : K) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : s) : K) = 1 := rfl
/-- The embedding from a subfield of the field `K` to `K`. -/
def subtype (s : subfield K) : s →+* K :=
{ to_fun := coe,
.. s.to_submonoid.subtype, .. s.to_add_subgroup.subtype }
instance to_algebra : algebra s K := ring_hom.to_algebra s.subtype
@[simp] theorem coe_subtype : ⇑s.subtype = coe := rfl
lemma to_subring.subtype_eq_subtype (F : Type*) [field F] (S : subfield F) :
S.to_subring.subtype = S.subtype := rfl
/-! # Partial order -/
variables (s t)
@[simp] lemma mem_to_submonoid {s : subfield K} {x : K} : x ∈ s.to_submonoid ↔ x ∈ s := iff.rfl
@[simp] lemma coe_to_submonoid : (s.to_submonoid : set K) = s := rfl
@[simp] lemma mem_to_add_subgroup {s : subfield K} {x : K} :
x ∈ s.to_add_subgroup ↔ x ∈ s := iff.rfl
@[simp] lemma coe_to_add_subgroup : (s.to_add_subgroup : set K) = s := rfl
/-! # top -/
/-- The subfield of `K` containing all elements of `K`. -/
instance : has_top (subfield K) :=
⟨{ inv_mem' := λ x _, subring.mem_top x, .. (⊤ : subring K)}⟩
instance : inhabited (subfield K) := ⟨⊤⟩
@[simp] lemma mem_top (x : K) : x ∈ (⊤ : subfield K) := set.mem_univ x
@[simp] lemma coe_top : ((⊤ : subfield K) : set K) = set.univ := rfl
/-! # comap -/
variables (f : K →+* L)
/-- The preimage of a subfield along a ring homomorphism is a subfield. -/
def comap (s : subfield L) : subfield K :=
{ inv_mem' := λ x hx, show f (x⁻¹) ∈ s, by { rw f.map_inv, exact s.inv_mem hx },
.. s.to_subring.comap f }
@[simp] lemma coe_comap (s : subfield L) : (s.comap f : set K) = f ⁻¹' s := rfl
@[simp]
lemma mem_comap {s : subfield L} {f : K →+* L} {x : K} : x ∈ s.comap f ↔ f x ∈ s := iff.rfl
lemma comap_comap (s : subfield M) (g : L →+* M) (f : K →+* L) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-! # map -/
/-- The image of a subfield along a ring homomorphism is a subfield. -/
def map (s : subfield K) : subfield L :=
{ inv_mem' := by { rintros _ ⟨x, hx, rfl⟩, exact ⟨x⁻¹, s.inv_mem hx, f.map_inv x⟩ },
.. s.to_subring.map f }
@[simp] lemma coe_map : (s.map f : set L) = f '' s := rfl
@[simp] lemma mem_map {f : K →+* L} {s : subfield K} {y : L} :
y ∈ s.map f ↔ ∃ x ∈ s, f x = y :=
set.mem_image_iff_bex
lemma map_map (g : L →+* M) (f : K →+* L) : (s.map f).map g = s.map (g.comp f) :=
set_like.ext' $ set.image_image _ _ _
lemma map_le_iff_le_comap {f : K →+* L} {s : subfield K} {t : subfield L} :
s.map f ≤ t ↔ s ≤ t.comap f :=
set.image_subset_iff
lemma gc_map_comap (f : K →+* L) : galois_connection (map f) (comap f) :=
λ S T, map_le_iff_le_comap
end subfield
namespace ring_hom
variables (g : L →+* M) (f : K →+* L)
/-! # range -/
/-- The range of a ring homomorphism, as a subfield of the target. See Note [range copy pattern]. -/
def field_range : subfield L :=
((⊤ : subfield K).map f).copy (set.range f) set.image_univ.symm
@[simp] lemma coe_field_range : (f.field_range : set L) = set.range f := rfl
@[simp] lemma mem_field_range {f : K →+* L} {y : L} : y ∈ f.field_range ↔ ∃ x, f x = y := iff.rfl
lemma field_range_eq_map : f.field_range = subfield.map f ⊤ :=
by { ext, simp }
lemma map_field_range : f.field_range.map g = (g.comp f).field_range :=
by simpa only [field_range_eq_map] using (⊤ : subfield K).map_map g f
/-- The range of a morphism of fields is a fintype, if the domain is a fintype.
Note that this instance can cause a diamond with `subtype.fintype` if `L` is also a fintype.-/
instance fintype_field_range [fintype K] [decidable_eq L] (f : K →+* L) : fintype f.field_range :=
set.fintype_range f
end ring_hom
namespace subfield
/-! # inf -/
/-- The inf of two subfields is their intersection. -/
instance : has_inf (subfield K) :=
⟨λ s t,
{ inv_mem' := λ x hx, subring.mem_inf.mpr
⟨s.inv_mem (subring.mem_inf.mp hx).1,
t.inv_mem (subring.mem_inf.mp hx).2⟩,
.. s.to_subring ⊓ t.to_subring }⟩
@[simp] lemma coe_inf (p p' : subfield K) : ((p ⊓ p' : subfield K) : set K) = p ∩ p' := rfl
@[simp] lemma mem_inf {p p' : subfield K} {x : K} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl
instance : has_Inf (subfield K) :=
⟨λ S,
{ inv_mem' := begin
rintros x hx,
apply subring.mem_Inf.mpr,
rintro _ ⟨p, p_mem, rfl⟩,
exact p.inv_mem (subring.mem_Inf.mp hx p.to_subring ⟨p, p_mem, rfl⟩),
end,
.. Inf (subfield.to_subring '' S) }⟩
@[simp, norm_cast] lemma coe_Inf (S : set (subfield K)) :
((Inf S : subfield K) : set K) = ⋂ s ∈ S, ↑s :=
show ((Inf (subfield.to_subring '' S) : subring K) : set K) = ⋂ s ∈ S, ↑s,
begin
ext x,
rw [subring.coe_Inf, set.mem_Inter, set.mem_Inter],
exact ⟨λ h s s' ⟨s_mem, s'_eq⟩, h s.to_subring _ ⟨⟨s, s_mem, rfl⟩, s'_eq⟩,
λ h s s' ⟨⟨s'', s''_mem, s_eq⟩, (s'_eq : ↑s = s')⟩,
h s'' _ ⟨s''_mem, by simp [←s_eq, ← s'_eq]⟩⟩
end
lemma mem_Inf {S : set (subfield K)} {x : K} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p :=
subring.mem_Inf.trans
⟨λ h p hp, h p.to_subring ⟨p, hp, rfl⟩,
λ h p ⟨p', hp', p_eq⟩, p_eq ▸ h p' hp'⟩
@[simp] lemma Inf_to_subring (s : set (subfield K)) :
(Inf s).to_subring = ⨅ t ∈ s, subfield.to_subring t :=
begin
ext x,
rw [mem_to_subring, mem_Inf],
erw subring.mem_Inf,
exact ⟨λ h p ⟨p', hp⟩, hp ▸ subring.mem_Inf.mpr (λ p ⟨hp', hp⟩, hp ▸ h _ hp'),
λ h p hp, h p.to_subring ⟨p, subring.ext (λ x,
⟨λ hx, subring.mem_Inf.mp hx _ ⟨hp, rfl⟩,
λ hx, subring.mem_Inf.mpr (λ p' ⟨hp, p'_eq⟩, p'_eq ▸ hx)⟩)⟩⟩
end
lemma is_glb_Inf (S : set (subfield K)) : is_glb S (Inf S) :=
begin
refine is_glb.of_image (λ s t, show (s : set K) ≤ t ↔ s ≤ t, from set_like.coe_subset_coe) _,
convert is_glb_binfi,
exact coe_Inf _
end
/-- Subfields of a ring form a complete lattice. -/
instance : complete_lattice (subfield K) :=
{ top := ⊤,
le_top := λ s x hx, trivial,
inf := (⊓),
inf_le_left := λ s t x, and.left,
inf_le_right := λ s t x, and.right,
le_inf := λ s t₁ t₂ h₁ h₂ x hx, ⟨h₁ hx, h₂ hx⟩,
.. complete_lattice_of_Inf (subfield K) is_glb_Inf }
/-! # subfield closure of a subset -/
/-- The `subfield` generated by a set. -/
def closure (s : set K) : subfield K :=
{ carrier := { (x / y) | (x ∈ subring.closure s) (y ∈ subring.closure s) },
zero_mem' := ⟨0, subring.zero_mem _, 1, subring.one_mem _, div_one _⟩,
one_mem' := ⟨1, subring.one_mem _, 1, subring.one_mem _, div_one _⟩,
neg_mem' := λ x ⟨y, hy, z, hz, x_eq⟩, ⟨-y, subring.neg_mem _ hy, z, hz, x_eq ▸ neg_div _ _⟩,
inv_mem' := λ x ⟨y, hy, z, hz, x_eq⟩, ⟨z, hz, y, hy, x_eq ▸ inv_div.symm⟩,
add_mem' := λ x y x_mem y_mem, begin
obtain ⟨nx, hnx, dx, hdx, rfl⟩ := id x_mem,
obtain ⟨ny, hny, dy, hdy, rfl⟩ := id y_mem,
by_cases hx0 : dx = 0, { rwa [hx0, div_zero, zero_add] },
by_cases hy0 : dy = 0, { rwa [hy0, div_zero, add_zero] },
exact ⟨nx * dy + dx * ny,
subring.add_mem _ (subring.mul_mem _ hnx hdy) (subring.mul_mem _ hdx hny),
dx * dy, subring.mul_mem _ hdx hdy,
(div_add_div nx ny hx0 hy0).symm⟩
end,
mul_mem' := λ x y x_mem y_mem, begin
obtain ⟨nx, hnx, dx, hdx, rfl⟩ := id x_mem,
obtain ⟨ny, hny, dy, hdy, rfl⟩ := id y_mem,
exact ⟨nx * ny, subring.mul_mem _ hnx hny,
dx * dy, subring.mul_mem _ hdx hdy,
(div_mul_div _ _ _ _).symm⟩
end }
lemma mem_closure_iff {s : set K} {x} :
x ∈ closure s ↔ ∃ (y ∈ subring.closure s) (z ∈ subring.closure s), y / z = x := iff.rfl
lemma subring_closure_le (s : set K) : subring.closure s ≤ (closure s).to_subring :=
λ x hx, ⟨x, hx, 1, subring.one_mem _, div_one x⟩
/-- The subfield generated by a set includes the set. -/
@[simp] lemma subset_closure {s : set K} : s ⊆ closure s :=
set.subset.trans subring.subset_closure (subring_closure_le s)
lemma mem_closure {x : K} {s : set K} : x ∈ closure s ↔ ∀ S : subfield K, s ⊆ S → x ∈ S :=
⟨λ ⟨y, hy, z, hz, x_eq⟩ t le, x_eq ▸
t.div_mem
(subring.mem_closure.mp hy t.to_subring le)
(subring.mem_closure.mp hz t.to_subring le),
λ h, h (closure s) subset_closure⟩
/-- A subfield `t` includes `closure s` if and only if it includes `s`. -/
@[simp]
lemma closure_le {s : set K} {t : subfield K} : closure s ≤ t ↔ s ⊆ t :=
⟨set.subset.trans subset_closure, λ h x hx, mem_closure.mp hx t h⟩
/-- Subfield closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/
lemma closure_mono ⦃s t : set K⦄ (h : s ⊆ t) : closure s ≤ closure t :=
closure_le.2 $ set.subset.trans h subset_closure
lemma closure_eq_of_le {s : set K} {t : subfield K} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) :
closure s = t :=
le_antisymm (closure_le.2 h₁) h₂
/-- An induction principle for closure membership. If `p` holds for `1`, and all elements
of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all
elements of the closure of `s`. -/
@[elab_as_eliminator]
lemma closure_induction {s : set K} {p : K → Prop} {x} (h : x ∈ closure s)
(Hs : ∀ x ∈ s, p x) (H1 : p 1)
(Hadd : ∀ x y, p x → p y → p (x + y))
(Hneg : ∀ x, p x → p (-x))
(Hinv : ∀ x, p x → p (x⁻¹))
(Hmul : ∀ x y, p x → p y → p (x * y)) : p x :=
(@closure_le _ _ _ ⟨p, H1, Hmul,
@add_neg_self K _ 1 ▸ Hadd _ _ H1 (Hneg _ H1), Hadd, Hneg, Hinv⟩).2 Hs h
variable (K)
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : galois_insertion (@closure K _) coe :=
{ choice := λ s _, closure s,
gc := λ s t, closure_le,
le_l_u := λ s, subset_closure,
choice_eq := λ s h, rfl }
variable {K}
/-- Closure of a subfield `S` equals `S`. -/
lemma closure_eq (s : subfield K) : closure (s : set K) = s := (subfield.gi K).l_u_eq s
@[simp] lemma closure_empty : closure (∅ : set K) = ⊥ := (subfield.gi K).gc.l_bot
@[simp] lemma closure_univ : closure (set.univ : set K) = ⊤ := @coe_top K _ ▸ closure_eq ⊤
lemma closure_union (s t : set K) : closure (s ∪ t) = closure s ⊔ closure t :=
(subfield.gi K).gc.l_sup
lemma closure_Union {ι} (s : ι → set K) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(subfield.gi K).gc.l_supr
lemma closure_sUnion (s : set (set K)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t :=
(subfield.gi K).gc.l_Sup
lemma map_sup (s t : subfield K) (f : K →+* L) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
lemma map_supr {ι : Sort*} (f : K →+* L) (s : ι → subfield K) :
(supr s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_supr
lemma comap_inf (s t : subfield L) (f : K →+* L) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f :=
(gc_map_comap f).u_inf
lemma comap_infi {ι : Sort*} (f : K →+* L) (s : ι → subfield L) :
(infi s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_infi
@[simp] lemma map_bot (f : K →+* L) : (⊥ : subfield K).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma comap_top (f : K →+* L) : (⊤ : subfield L).comap f = ⊤ :=
(gc_map_comap f).u_top
/-- The underlying set of a non-empty directed Sup of subfields is just a union of the subfields.
Note that this fails without the directedness assumption (the union of two subfields is
typically not a subfield) -/
lemma mem_supr_of_directed {ι} [hι : nonempty ι] {S : ι → subfield K} (hS : directed (≤) S)
{x : K} : 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 K)) → ∃ i, x ∈ S i,
by simpa only [closure_Union, closure_eq],
refine λ hx, closure_induction hx (λ x, set.mem_Union.mp) _ _ _ _ _,
{ exact hι.elim (λ i, ⟨i, (S i).one_mem⟩) },
{ rintros x y ⟨i, hi⟩ ⟨j, hj⟩,
obtain ⟨k, hki, hkj⟩ := hS i j,
exact ⟨k, (S k).add_mem (hki hi) (hkj hj)⟩ },
{ rintros x ⟨i, hi⟩,
exact ⟨i, (S i).neg_mem hi⟩ },
{ rintros x ⟨i, hi⟩,
exact ⟨i, (S i).inv_mem hi⟩ },
{ rintros x y ⟨i, hi⟩ ⟨j, hj⟩,
obtain ⟨k, hki, hkj⟩ := hS i j,
exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ }
end
lemma coe_supr_of_directed {ι} [hι : nonempty ι] {S : ι → subfield K} (hS : directed (≤) S) :
((⨆ i, S i : subfield K) : set K) = ⋃ i, ↑(S i) :=
set.ext $ λ x, by simp [mem_supr_of_directed hS]
lemma mem_Sup_of_directed_on {S : set (subfield K)} (Sne : S.nonempty)
(hS : directed_on (≤) S) {x : K} :
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
lemma coe_Sup_of_directed_on {S : set (subfield K)} (Sne : S.nonempty) (hS : directed_on (≤) S) :
(↑(Sup S) : set K) = ⋃ s ∈ S, ↑s :=
set.ext $ λ x, by simp [mem_Sup_of_directed_on Sne hS]
end subfield
namespace ring_hom
variables {s : subfield K}
open subfield
/-- Restrict the codomain of a ring homomorphism to a subfield that includes the range. -/
def cod_restrict_field (f : K →+* L)
(s : subfield L) (h : ∀ x, f x ∈ s) : K →+* s :=
{ to_fun := λ x, ⟨f x, h x⟩,
map_add' := λ x y, subtype.eq $ f.map_add x y,
map_zero' := subtype.eq f.map_zero,
map_mul' := λ x y, subtype.eq $ f.map_mul x y,
map_one' := subtype.eq f.map_one }
/-- Restriction of a ring homomorphism to a subfield of the domain. -/
def restrict_field (f : K →+* L) (s : subfield K) : s →+* L := f.comp s.subtype
@[simp] lemma restrict_field_apply (f : K →+* L) (x : s) : f.restrict_field s x = f x := rfl
/-- Restriction of a ring homomorphism to its range interpreted as a subfield. -/
def range_restrict_field (f : K →+* L) : K →+* f.field_range :=
f.srange_restrict
@[simp] lemma coe_range_restrict_field (f : K →+* L) (x : K) :
(f.range_restrict_field x : L) = f x := rfl
/-- The subfield of elements `x : R` such that `f x = g x`, i.e.,
the equalizer of f and g as a subfield of R -/
def eq_locus_field (f g : K →+* L) : subfield K :=
{ inv_mem' := λ x (hx : f x = g x), show f x⁻¹ = g x⁻¹, by rw [f.map_inv, g.map_inv, hx],
carrier := {x | f x = g x}, .. (f : K →+* L).eq_locus g }
/-- If two ring homomorphisms are equal on a set, then they are equal on its subfield closure. -/
lemma eq_on_field_closure {f g : K →+* L} {s : set K} (h : set.eq_on f g s) :
set.eq_on f g (closure s) :=
show closure s ≤ f.eq_locus_field g, from closure_le.2 h
lemma eq_of_eq_on_subfield_top {f g : K →+* L} (h : set.eq_on f g (⊤ : subfield K)) :
f = g :=
ext $ λ x, h trivial
lemma eq_of_eq_on_of_field_closure_eq_top {s : set K} (hs : closure s = ⊤) {f g : K →+* L}
(h : s.eq_on f g) : f = g :=
eq_of_eq_on_subfield_top $ hs ▸ eq_on_field_closure h
lemma field_closure_preimage_le (f : K →+* L) (s : set L) :
closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 $ λ x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx
/-- The image under a ring homomorphism of the subfield generated by a set equals
the subfield generated by the image of the set. -/
lemma map_field_closure (f : K →+* L) (s : set K) :
(closure s).map f = closure (f '' s) :=
le_antisymm
(map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _)
(field_closure_preimage_le _ _))
(closure_le.2 $ set.image_subset _ subset_closure)
end ring_hom
namespace subfield
open ring_hom
/-- The ring homomorphism associated to an inclusion of subfields. -/
def inclusion {S T : subfield K} (h : S ≤ T) : S →+* T :=
S.subtype.cod_restrict_field _ (λ x, h x.2)
@[simp] lemma field_range_subtype (s : subfield K) : s.subtype.field_range = s :=
set_like.ext' $ (coe_srange _).trans subtype.range_coe
end subfield
namespace ring_equiv
variables {s t : subfield K}
/-- Makes the identity isomorphism from a proof two subfields of a multiplicative
monoid are equal. -/
def subfield_congr (h : s = t) : s ≃+* t :=
{ map_mul' := λ _ _, rfl, map_add' := λ _ _, rfl, ..equiv.set_congr $ set_like.ext'_iff.1 h }
end ring_equiv
namespace subfield
variables {s : set K}
lemma closure_preimage_le (f : K →+* L) (s : set L) :
closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 $ λ x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx
end subfield
|
d9ca257378cfc4a9e12c67789716a3c024f70b56 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/category_theory/glue_data.lean | 422f45d391d19446cc017da70633ba28d5d07c47 | [
"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 | 12,568 | lean | /-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import tactic.elementwise
import category_theory.limits.shapes.multiequalizer
import category_theory.limits.constructions.epi_mono
import category_theory.limits.preserves.limits
import category_theory.limits.shapes.types
/-!
# Gluing data
We define `glue_data` as a family of data needed to glue topological spaces, schemes, etc. We
provide the API to realize it as a multispan diagram, and also states lemmas about its
interaction with a functor that preserves certain pullbacks.
-/
noncomputable theory
open category_theory.limits
namespace category_theory
universes v u₁ u₂
variables (C : Type u₁) [category.{v} C] {C' : Type u₂} [category.{v} C']
/--
A gluing datum consists of
1. An index type `J`
2. An object `U i` for each `i : J`.
3. An object `V i j` for each `i j : J`.
4. A monomorphism `f i j : V i j ⟶ U i` for each `i j : J`.
5. A transition map `t i j : V i j ⟶ V j i` for each `i j : J`.
such that
6. `f i i` is an isomorphism.
7. `t i i` is the identity.
8. The pullback for `f i j` and `f i k` exists.
9. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some
`t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`.
10. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`.
-/
@[nolint has_inhabited_instance]
structure glue_data :=
(J : Type v)
(U : J → C)
(V : J × J → C)
(f : Π i j, V (i, j) ⟶ U i)
(f_mono : ∀ i j, mono (f i j) . tactic.apply_instance)
(f_has_pullback : ∀ i j k, has_pullback (f i j) (f i k) . tactic.apply_instance)
(f_id : ∀ i, is_iso (f i i) . tactic.apply_instance)
(t : Π i j, V (i, j) ⟶ V (j, i))
(t_id : ∀ i, t i i = 𝟙 _)
(t' : Π i j k, pullback (f i j) (f i k) ⟶ pullback (f j k) (f j i))
(t_fac : ∀ i j k, t' i j k ≫ pullback.snd = pullback.fst ≫ t i j)
(cocycle : ∀ i j k , t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _)
attribute [simp] glue_data.t_id
attribute [instance] glue_data.f_id glue_data.f_mono glue_data.f_has_pullback
attribute [reassoc] glue_data.t_fac glue_data.cocycle
namespace glue_data
variables {C} (D : glue_data C)
@[simp] lemma t'_iij (i j : D.J) : D.t' i i j = (pullback_symmetry _ _).hom :=
begin
have eq₁ := D.t_fac i i j,
have eq₂ := (is_iso.eq_comp_inv (D.f i i)).mpr (@pullback.condition _ _ _ _ _ _ (D.f i j) _),
rw [D.t_id, category.comp_id, eq₂] at eq₁,
have eq₃ := (is_iso.eq_comp_inv (D.f i i)).mp eq₁,
rw [category.assoc, ←pullback.condition, ←category.assoc] at eq₃,
exact mono.right_cancellation _ _
((mono.right_cancellation _ _ eq₃).trans (pullback_symmetry_hom_comp_fst _ _).symm)
end
lemma t'_jii (i j : D.J) : D.t' j i i = pullback.fst ≫ D.t j i ≫ inv pullback.snd :=
by { rw [←category.assoc, ←D.t_fac], simp }
lemma t'_iji (i j : D.J) : D.t' i j i = pullback.fst ≫ D.t i j ≫ inv pullback.snd :=
by { rw [←category.assoc, ←D.t_fac], simp }
@[simp, reassoc, elementwise] lemma t_inv (i j : D.J) :
D.t i j ≫ D.t j i = 𝟙 _ :=
begin
have eq : (pullback_symmetry (D.f i i) (D.f i j)).hom = pullback.snd ≫ inv pullback.fst,
{ simp },
have := D.cocycle i j i,
rw [D.t'_iij, D.t'_jii, D.t'_iji, fst_eq_snd_of_mono_eq, eq] at this,
simp only [category.assoc, is_iso.inv_hom_id_assoc] at this,
rw [←is_iso.eq_inv_comp, ←category.assoc, is_iso.comp_inv_eq] at this,
simpa using this,
end
lemma t'_inv (i j k : D.J) : D.t' i j k ≫ (pullback_symmetry _ _).hom ≫
D.t' j i k ≫ (pullback_symmetry _ _).hom = 𝟙 _ :=
begin
rw ← cancel_mono (pullback.fst : pullback (D.f i j) (D.f i k) ⟶ _),
simp [t_fac, t_fac_assoc]
end
instance t_is_iso (i j : D.J) : is_iso (D.t i j) :=
⟨⟨D.t j i, D.t_inv _ _, D.t_inv _ _⟩⟩
instance t'_is_iso (i j k : D.J) : is_iso (D.t' i j k) :=
⟨⟨D.t' j k i ≫ D.t' k i j, D.cocycle _ _ _, (by simpa using D.cocycle _ _ _)⟩⟩
@[reassoc]
lemma t'_comp_eq_pullback_symmetry (i j k : D.J) :
D.t' j k i ≫ D.t' k i j = (pullback_symmetry _ _).hom ≫
D.t' j i k ≫ (pullback_symmetry _ _).hom :=
begin
transitivity inv (D.t' i j k),
{ exact is_iso.eq_inv_of_hom_inv_id (D.cocycle _ _ _) },
{ rw ← cancel_mono (pullback.fst : pullback (D.f i j) (D.f i k) ⟶ _),
simp [t_fac, t_fac_assoc] }
end
/-- (Implementation) The disjoint union of `U i`. -/
def sigma_opens [has_coproduct D.U] : C := ∐ D.U
/-- (Implementation) The diagram to take colimit of. -/
def diagram : multispan_index C :=
{ L := D.J × D.J, R := D.J,
fst_from := _root_.prod.fst, snd_from := _root_.prod.snd,
left := D.V, right := D.U,
fst := λ ⟨i, j⟩, D.f i j,
snd := λ ⟨i, j⟩, D.t i j ≫ D.f j i }
@[simp] lemma diagram_L : D.diagram.L = (D.J × D.J) := rfl
@[simp] lemma diagram_R : D.diagram.R = D.J := rfl
@[simp] lemma diagram_fst_from (i j : D.J) : D.diagram.fst_from ⟨i, j⟩ = i := rfl
@[simp] lemma diagram_snd_from (i j : D.J) : D.diagram.snd_from ⟨i, j⟩ = j := rfl
@[simp] lemma diagram_fst (i j : D.J) : D.diagram.fst ⟨i, j⟩ = D.f i j := rfl
@[simp] lemma diagram_snd (i j : D.J) : D.diagram.snd ⟨i, j⟩ = D.t i j ≫ D.f j i := rfl
@[simp] lemma diagram_left : D.diagram.left = D.V := rfl
@[simp] lemma diagram_right : D.diagram.right = D.U := rfl
section
variable [has_multicoequalizer D.diagram]
/-- The glued object given a family of gluing data. -/
def glued : C := multicoequalizer D.diagram
/-- The map `D.U i ⟶ D.glued` for each `i`. -/
def ι (i : D.J) : D.U i ⟶ D.glued :=
multicoequalizer.π D.diagram i
@[simp, elementwise]
lemma glue_condition (i j : D.J) :
D.t i j ≫ D.f j i ≫ D.ι j = D.f i j ≫ D.ι i :=
(category.assoc _ _ _).symm.trans (multicoequalizer.condition D.diagram ⟨i, j⟩).symm
/-- The pullback cone spanned by `V i j ⟶ U i` and `V i j ⟶ U j`.
This will often be a pullback diagram. -/
def V_pullback_cone (i j : D.J) : pullback_cone (D.ι i) (D.ι j) :=
pullback_cone.mk (D.f i j) (D.t i j ≫ D.f j i) (by simp)
variables [has_colimits C]
/-- The projection `∐ D.U ⟶ D.glued` given by the colimit. -/
def π : D.sigma_opens ⟶ D.glued := multicoequalizer.sigma_π D.diagram
instance π_epi : epi D.π := by { unfold π, apply_instance }
end
lemma types_π_surjective (D : glue_data Type*) :
function.surjective D.π := (epi_iff_surjective _).mp infer_instance
lemma types_ι_jointly_surjective (D : glue_data Type*) (x : D.glued) :
∃ i (y : D.U i), D.ι i y = x :=
begin
delta category_theory.glue_data.ι,
simp_rw ← multicoequalizer.ι_sigma_π D.diagram,
rcases D.types_π_surjective x with ⟨x', rfl⟩,
have := colimit.iso_colimit_cocone (types.coproduct_colimit_cocone _),
rw ← (show (colimit.iso_colimit_cocone (types.coproduct_colimit_cocone _)).inv _ = x',
from concrete_category.congr_hom
((colimit.iso_colimit_cocone (types.coproduct_colimit_cocone _)).hom_inv_id) x'),
rcases (colimit.iso_colimit_cocone (types.coproduct_colimit_cocone _)).hom x' with ⟨i, y⟩,
exact ⟨i, y, by { simpa [← multicoequalizer.ι_sigma_π, -multicoequalizer.ι_sigma_π] }⟩
end
variables (F : C ⥤ C') [H : ∀ i j k, preserves_limit (cospan (D.f i j) (D.f i k)) F]
include H
instance (i j k : D.J) : has_pullback (F.map (D.f i j)) (F.map (D.f i k)) :=
⟨⟨⟨_, is_limit_of_has_pullback_of_preserves_limit F (D.f i j) (D.f i k)⟩⟩⟩
/-- A functor that preserves the pullbacks of `f i j` and `f i k` can map a family of glue data. -/
@[simps] def map_glue_data :
glue_data C' :=
{ J := D.J,
U := λ i, F.obj (D.U i),
V := λ i, F.obj (D.V i),
f := λ i j, F.map (D.f i j),
f_mono := λ i j, category_theory.preserves_mono F (D.f i j),
f_id := λ i, infer_instance,
t := λ i j, F.map (D.t i j),
t_id := λ i, by { rw D.t_id i, simp },
t' := λ i j k, (preserves_pullback.iso F (D.f i j) (D.f i k)).inv ≫
F.map (D.t' i j k) ≫ (preserves_pullback.iso F (D.f j k) (D.f j i)).hom,
t_fac := λ i j k, by simpa [iso.inv_comp_eq] using congr_arg (λ f, F.map f) (D.t_fac i j k),
cocycle := λ i j k, by simp only [category.assoc, iso.hom_inv_id_assoc, ← functor.map_comp_assoc,
D.cocycle, iso.inv_hom_id, category_theory.functor.map_id, category.id_comp] }
/--
The diagram of the image of a `glue_data` under a functor `F` is naturally isomorphic to the
original diagram of the `glue_data` via `F`.
-/
def diagram_iso : D.diagram.multispan ⋙ F ≅ (D.map_glue_data F).diagram.multispan :=
nat_iso.of_components
(λ x, match x with
| walking_multispan.left a := iso.refl _
| walking_multispan.right b := iso.refl _
end)
(begin
rintros (⟨_,_⟩|_) _ (_|_|_),
{ erw [category.comp_id, category.id_comp, functor.map_id], refl },
{ erw [category.comp_id, category.id_comp], refl },
{ erw [category.comp_id, category.id_comp, functor.map_comp], refl },
{ erw [category.comp_id, category.id_comp, functor.map_id], refl },
end)
@[simp] lemma diagram_iso_app_left (i : D.J × D.J) :
(D.diagram_iso F).app (walking_multispan.left i) = iso.refl _ := rfl
@[simp] lemma diagram_iso_app_right (i : D.J) :
(D.diagram_iso F).app (walking_multispan.right i) = iso.refl _ := rfl
@[simp] lemma diagram_iso_hom_app_left (i : D.J × D.J) :
(D.diagram_iso F).hom.app (walking_multispan.left i) = 𝟙 _ := rfl
@[simp] lemma diagram_iso_hom_app_right (i : D.J) :
(D.diagram_iso F).hom.app (walking_multispan.right i) = 𝟙 _ := rfl
@[simp] lemma diagram_iso_inv_app_left (i : D.J × D.J) :
(D.diagram_iso F).inv.app (walking_multispan.left i) = 𝟙 _ := rfl
@[simp] lemma diagram_iso_inv_app_right (i : D.J) :
(D.diagram_iso F).inv.app (walking_multispan.right i) = 𝟙 _ := rfl
variables [has_multicoequalizer D.diagram] [preserves_colimit D.diagram.multispan F]
omit H
lemma has_colimit_multispan_comp : has_colimit (D.diagram.multispan ⋙ F) :=
⟨⟨⟨_,preserves_colimit.preserves (colimit.is_colimit _)⟩⟩⟩
include H
local attribute [instance] has_colimit_multispan_comp
lemma has_colimit_map_glue_data_diagram : has_multicoequalizer (D.map_glue_data F).diagram :=
has_colimit_of_iso (D.diagram_iso F).symm
local attribute [instance] has_colimit_map_glue_data_diagram
/-- If `F` preserves the gluing, we obtain an iso between the glued objects. -/
def glued_iso : F.obj D.glued ≅ (D.map_glue_data F).glued :=
preserves_colimit_iso F D.diagram.multispan ≪≫
(limits.has_colimit.iso_of_nat_iso (D.diagram_iso F))
@[simp, reassoc]
lemma ι_glued_iso_hom (i : D.J) :
F.map (D.ι i) ≫ (D.glued_iso F).hom = (D.map_glue_data F).ι i :=
by { erw ι_preserves_colimits_iso_hom_assoc, rw has_colimit.iso_of_nat_iso_ι_hom,
erw category.id_comp, refl }
@[simp, reassoc]
lemma ι_glued_iso_inv (i : D.J) :
(D.map_glue_data F).ι i ≫ (D.glued_iso F).inv = F.map (D.ι i) :=
by rw [iso.comp_inv_eq, ι_glued_iso_hom]
/-- If `F` preserves the gluing, and reflects the pullback of `U i ⟶ glued` and `U j ⟶ glued`,
then `F` reflects the fact that `V_pullback_cone` is a pullback. -/
def V_pullback_cone_is_limit_of_map (i j : D.J) [reflects_limit (cospan (D.ι i) (D.ι j)) F]
(hc : is_limit ((D.map_glue_data F).V_pullback_cone i j)) :
is_limit (D.V_pullback_cone i j) :=
begin
apply is_limit_of_reflects F,
apply (is_limit_map_cone_pullback_cone_equiv _ _).symm _,
let e : cospan (F.map (D.ι i)) (F.map (D.ι j)) ≅
cospan ((D.map_glue_data F).ι i) ((D.map_glue_data F).ι j),
exact nat_iso.of_components
(λ x, by { cases x, exacts [D.glued_iso F, iso.refl _] })
(by rintros (_|_) (_|_) (_|_|_); simp),
apply is_limit.postcompose_hom_equiv e _ _,
apply hc.of_iso_limit,
refine cones.ext (iso.refl _) _,
{ rintro (_|_|_),
change _ = _ ≫ (_ ≫ _) ≫ _,
all_goals { change _ = 𝟙 _ ≫ _ ≫ _, simpa } }
end
omit H
/-- If there is a forgetful functor into `Type` that preserves enough (co)limits, then `D.ι` will
be jointly surjective. -/
lemma ι_jointly_surjective (F : C ⥤ Type v) [preserves_colimit D.diagram.multispan F]
[Π (i j k : D.J), preserves_limit (cospan (D.f i j) (D.f i k)) F] (x : F.obj (D.glued)) :
∃ i (y : F.obj (D.U i)), F.map (D.ι i) y = x :=
begin
let e := D.glued_iso F,
obtain ⟨i, y, eq⟩ := (D.map_glue_data F).types_ι_jointly_surjective (e.hom x),
replace eq := congr_arg e.inv eq,
change ((D.map_glue_data F).ι i ≫ e.inv) y = (e.hom ≫ e.inv) x at eq,
rw [e.hom_inv_id, D.ι_glued_iso_inv] at eq,
exact ⟨i, y, eq⟩
end
end glue_data
end category_theory
|
44764b10243af82fc3c4e171779febe3a8255c78 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/polynomial/lifts_auto.lean | fe90170e859b459db0d9909a3f0a5f904d73be00 | [] | 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 | 6,884 | lean | /-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Riccardo Brasca
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.polynomial.algebra_map
import Mathlib.algebra.algebra.subalgebra
import Mathlib.algebra.polynomial.big_operators
import Mathlib.data.polynomial.erase_lead
import Mathlib.PostPort
universes u v
namespace Mathlib
/-!
# Polynomials that lift
Given semirings `R` and `S` with a morphism `f : R →+* S`, we define a subsemiring `lifts` of
`polynomial S` by the image of `ring_hom.of (map f)`.
Then, we prove that a polynomial that lifts can always be lifted to a polynomial of the same degree
and that a monic polynomial that lifts can be lifted to a monic polynomial (of the same degree).
## Main definition
* `lifts (f : R →+* S)` : the subsemiring of polynomials that lift.
## Main results
* `lifts_and_degree_eq` : A polynomial lifts if and only if it can be lifted to a polynomial
of the same degree.
* `lifts_and_degree_eq_and_monic` : A monic polynomial lifts if and only if it can be lifted to a
monic polynomial of the same degree.
* `lifts_iff_alg` : if `R` is commutative, a polynomial lifts if and only if it is in the image of
`map_alg`, where `map_alg : polynomial R →ₐ[R] polynomial S` is the only `R`-algebra map
that sends `X` to `X`.
## Implementation details
In general `R` and `S` are semiring, so `lifts` is a semiring. In the case of rings, see
`lifts_iff_lifts_ring`.
Since we do not assume `R` to be commutative, we cannot say in general that the set of polynomials
that lift is a subalgebra. (By `lift_iff` this is true if `R` is commutative.)
-/
namespace polynomial
/-- We define the subsemiring of polynomials that lifts as the image of `ring_hom.of (map f)`. -/
def lifts {R : Type u} [semiring R] {S : Type v} [semiring S] (f : R →+* S) :
subsemiring (polynomial S) :=
ring_hom.srange (ring_hom.of (map f))
theorem mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S}
(p : polynomial S) : p ∈ lifts f ↔ ∃ (q : polynomial R), map f q = p :=
sorry
theorem lifts_iff_set_range {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S}
(p : polynomial S) : p ∈ lifts f ↔ p ∈ set.range (map f) :=
sorry
theorem lifts_iff_coeff_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S}
(p : polynomial S) : p ∈ lifts f ↔ ∀ (n : ℕ), coeff p n ∈ set.range ⇑f :=
sorry
/--If `(r : R)`, then `C (f r)` lifts. -/
theorem C_mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] (f : R →+* S) (r : R) :
coe_fn C (coe_fn f r) ∈ lifts f :=
sorry
/-- If `(s : S)` is in the image of `f`, then `C s` lifts. -/
theorem C'_mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S} {s : S}
(h : s ∈ set.range ⇑f) : coe_fn C s ∈ lifts f :=
sorry
/-- The polynomial `X` lifts. -/
theorem X_mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] (f : R →+* S) :
X ∈ lifts f :=
sorry
/-- The polynomial `X ^ n` lifts. -/
theorem X_pow_mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] (f : R →+* S) (n : ℕ) :
X ^ n ∈ lifts f :=
sorry
/-- If `p` lifts and `(r : R)` then `r * p` lifts. -/
theorem base_mul_mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S}
{p : polynomial S} (r : R) (hp : p ∈ lifts f) : coe_fn C (coe_fn f r) * p ∈ lifts f :=
sorry
/-- If `(s : S)` is in the image of `f`, then `monomial n s` lifts. -/
theorem monomial_mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S} {s : S}
(n : ℕ) (h : s ∈ set.range ⇑f) : coe_fn (monomial n) s ∈ lifts f :=
sorry
/-- If `p` lifts then `p.erase n` lifts. -/
theorem erase_mem_lifts {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S}
{p : polynomial S} (n : ℕ) (h : p ∈ lifts f) : finsupp.erase n p ∈ lifts f :=
sorry
theorem monomial_mem_lifts_and_degree_eq {R : Type u} [semiring R] {S : Type v} [semiring S]
{f : R →+* S} {s : S} {n : ℕ} (hl : coe_fn (monomial n) s ∈ lifts f) :
∃ (q : polynomial R),
map f q = coe_fn (monomial n) s ∧ degree q = degree (coe_fn (monomial n) s) :=
sorry
/-- A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. -/
theorem mem_lifts_and_degree_eq {R : Type u} [semiring R] {S : Type v} [semiring S] {f : R →+* S}
{p : polynomial S} (hlifts : p ∈ lifts f) :
∃ (q : polynomial R), map f q = p ∧ degree q = degree p :=
sorry
/-- A monic polynomial lifts if and only if it can be lifted to a monic polynomial
of the same degree. -/
theorem lifts_and_degree_eq_and_monic {R : Type u} [semiring R] {S : Type v} [semiring S]
{f : R →+* S} [nontrivial S] {p : polynomial S} (hlifts : p ∈ lifts f) (hmonic : monic p) :
∃ (q : polynomial R), map f q = p ∧ degree q = degree p ∧ monic q :=
sorry
/-- The subring of polynomials that lift. -/
def lifts_ring {R : Type u} [ring R] {S : Type v} [ring S] (f : R →+* S) : subring (polynomial S) :=
ring_hom.range (ring_hom.of (map f))
/-- If `R` and `S` are rings, `p` is in the subring of polynomials that lift if and only if it is in
the subsemiring of polynomials that lift. -/
theorem lifts_iff_lifts_ring {R : Type u} [ring R] {S : Type v} [ring S] (f : R →+* S)
(p : polynomial S) : p ∈ lifts f ↔ p ∈ lifts_ring f :=
sorry
/-- The map `polynomial R → polynomial S` as an algebra homomorphism. -/
def map_alg (R : Type u) [comm_semiring R] (S : Type v) [semiring S] [algebra R S] :
alg_hom R (polynomial R) (polynomial S) :=
aeval X
/-- `map_alg` is the morphism induced by `R → S`. -/
theorem map_alg_eq_map {R : Type u} [comm_semiring R] {S : Type v} [semiring S] [algebra R S]
(p : polynomial R) : coe_fn (map_alg R S) p = map (algebra_map R S) p :=
sorry
/-- A polynomial `p` lifts if and only if it is in the image of `map_alg`. -/
theorem mem_lifts_iff_mem_alg (R : Type u) [comm_semiring R] {S : Type v} [semiring S] [algebra R S]
(p : polynomial S) : p ∈ lifts (algebra_map R S) ↔ p ∈ alg_hom.range (map_alg R S) :=
sorry
/-- If `p` lifts and `(r : R)` then `r • p` lifts. -/
theorem smul_mem_lifts {R : Type u} [comm_semiring R] {S : Type v} [semiring S] [algebra R S]
{p : polynomial S} (r : R) (hp : p ∈ lifts (algebra_map R S)) :
r • p ∈ lifts (algebra_map R S) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (r • p ∈ lifts (algebra_map R S)))
(propext (mem_lifts_iff_mem_alg R (r • p)))))
(subalgebra.smul_mem (alg_hom.range (map_alg R S))
(eq.mp
(Eq._oldrec (Eq.refl (p ∈ lifts (algebra_map R S))) (propext (mem_lifts_iff_mem_alg R p)))
hp)
r)
end Mathlib |
e5250aa4249ea49d80a9f5e682e9ce229273400e | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/bad_quoted_symbol.lean | a75c825d3e4cfb3b5e194ebbfebd85bbe3d1e4e7 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 152 | lean | notation a ` \/ ` b := a ∨ b
notation a `1\/` b := a ∨ b
notation a ` 1\/` b := a ∨ b
notation a ` \ / ` b := a ∨ b
notation a ` ` b := a ∨ b
|
837e94062dd932ce974ab408b9e63d4bbdd9c3d7 | e61a235b8468b03aee0120bf26ec615c045005d2 | /stage0/src/Init/Lean/Compiler/IR/ElimDeadBranches.lean | 357d3005ff261c501eeb6ca3a41d319582efe3bb | [
"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 | 9,650 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Control.Reader
import Init.Data.Option
import Init.Data.Nat
import Init.Lean.Compiler.IR.Format
import Init.Lean.Compiler.IR.Basic
import Init.Lean.Compiler.IR.CompilerM
namespace Lean
namespace IR
namespace UnreachableBranches
/-- Value used in the abstract interpreter -/
inductive Value
| bot -- undefined
| top -- any value
| ctor (i : CtorInfo) (vs : Array Value)
| choice (vs : List Value)
namespace Value
instance : Inhabited Value := ⟨top⟩
protected partial def beq : Value → Value → Bool
| bot, bot => true
| top, top => true
| ctor i₁ vs₁, ctor i₂ vs₂ => i₁ == i₂ && Array.isEqv vs₁ vs₂ beq
| choice vs₁, choice vs₂ =>
vs₁.all (fun v₁ => vs₂.any $ fun v₂ => beq v₁ v₂)
&&
vs₂.all (fun v₂ => vs₁.any $ fun v₁ => beq v₁ v₂)
| _, _ => false
instance : HasBeq Value := ⟨Value.beq⟩
partial def addChoice (merge : Value → Value → Value) : List Value → Value → List Value
| [], v => [v]
| v₁@(ctor i₁ vs₁) :: cs, v₂@(ctor i₂ vs₂) =>
if i₁ == i₂ then merge v₁ v₂ :: cs
else v₁ :: addChoice cs v₂
| _, _ => panic! "invalid addChoice"
partial def merge : Value → Value → Value
| bot, v => v
| v, bot => v
| top, _ => top
| _, top => top
| v₁@(ctor i₁ vs₁), v₂@(ctor i₂ vs₂) =>
if i₁ == i₂ then ctor i₁ $ vs₁.size.fold (fun i r => r.push (merge (vs₁.get! i) (vs₂.get! i))) #[]
else choice [v₁, v₂]
| choice vs₁, choice vs₂ => choice $ vs₁.foldl (addChoice merge) vs₂
| choice vs, v => choice $ addChoice merge vs v
| v, choice vs => choice $ addChoice merge vs v
protected partial def format : Value → Format
| top => "top"
| bot => "bot"
| choice vs => fmt "@" ++ @List.format _ ⟨format⟩ vs
| ctor i vs => fmt "#" ++ if vs.isEmpty then fmt i.name else Format.paren (fmt i.name ++ @formatArray _ ⟨format⟩ vs)
instance : HasFormat Value := ⟨Value.format⟩
instance : HasToString Value := ⟨Format.pretty ∘ Value.format⟩
/- Make sure constructors of recursive inductive datatypes can only occur once in each path.
We use this function this function to implement a simple widening operation for our abstract
interpreter. -/
partial def truncate (env : Environment) : Value → NameSet → Value
| ctor i vs, found =>
let I := i.name.getPrefix;
if found.contains I then
top
else
let cont (found' : NameSet) : Value :=
ctor i (vs.map $ fun v => truncate v found');
match env.find? I with
| some (ConstantInfo.inductInfo d) =>
if d.isRec then cont (found.insert I)
else cont found
| _ => cont found
| choice vs, found =>
let newVs := vs.map $ fun v => truncate v found;
if newVs.elem top then top
else choice newVs
| v, _ => v
/- Widening operator that guarantees termination in our abstract interpreter. -/
def widening (env : Environment) (v₁ v₂ : Value) : Value :=
truncate env (merge v₁ v₂) {}
end Value
abbrev FunctionSummaries := SMap FunId Value
def mkFunctionSummariesExtension : IO (SimplePersistentEnvExtension (FunId × Value) FunctionSummaries) :=
registerSimplePersistentEnvExtension {
name := `unreachBranchesFunSummary,
addImportedFn := fun as =>
let cache : FunctionSummaries := mkStateFromImportedEntries (fun s (p : FunId × Value) => s.insert p.1 p.2) {} as;
cache.switch,
addEntryFn := fun s ⟨e, n⟩ => s.insert e n
}
@[init mkFunctionSummariesExtension]
constant functionSummariesExt : SimplePersistentEnvExtension (FunId × Value) FunctionSummaries := arbitrary _
def addFunctionSummary (env : Environment) (fid : FunId) (v : Value) : Environment :=
functionSummariesExt.addEntry env (fid, v)
def getFunctionSummary? (env : Environment) (fid : FunId) : Option Value :=
(functionSummariesExt.getState env).find? fid
abbrev Assignment := HashMap VarId Value
structure InterpContext :=
(currFnIdx : Nat := 0)
(decls : Array Decl)
(env : Environment)
(lctx : LocalContext := {})
structure InterpState :=
(assignments : Array Assignment)
(funVals : PArray Value) -- we take snapshots during fixpoint computations
abbrev M := ReaderT InterpContext (StateM InterpState)
open Value
def findVarValue (x : VarId) : M Value := do
ctx ← read;
s ← get;
let assignment := s.assignments.get! ctx.currFnIdx;
pure $ assignment.findD x bot
def findArgValue (arg : Arg) : M Value :=
match arg with
| Arg.var x => findVarValue x
| _ => pure top
def updateVarAssignment (x : VarId) (v : Value) : M Unit := do
v' ← findVarValue x;
ctx ← read;
modify $ fun s => { s with assignments := s.assignments.modify ctx.currFnIdx $ fun a => a.insert x (merge v v') }
partial def projValue : Value → Nat → Value
| ctor _ vs, i => vs.getD i bot
| choice vs, i => vs.foldl (fun r v => merge r (projValue v i)) bot
| v, _ => v
def interpExpr : Expr → M Value
| Expr.ctor i ys => ctor i <$> ys.mapM (fun y => findArgValue y)
| Expr.proj i x => do v ← findVarValue x; pure $ projValue v i
| Expr.fap fid ys => do
ctx ← read;
match getFunctionSummary? ctx.env fid with
| some v => pure v
| none => do
s ← get;
match ctx.decls.findIdx? (fun decl => decl.name == fid) with
| some idx => pure $ s.funVals.get! idx
| none => pure top
| _ => pure top
partial def containsCtor : Value → CtorInfo → Bool
| top, _ => true
| ctor i _, j => i == j
| choice vs, j => vs.any $ fun v => containsCtor v j
| _, _ => false
def updateCurrFnSummary (v : Value) : M Unit := do
ctx ← read;
let currFnIdx := ctx.currFnIdx;
modify $ fun s => { s with funVals := s.funVals.modify currFnIdx (fun v' => widening ctx.env v v') }
/-- Return true if the assignment of at least one parameter has been updated. -/
def updateJPParamsAssignment (ys : Array Param) (xs : Array Arg) : M Bool := do
ctx ← read;
let currFnIdx := ctx.currFnIdx;
ys.size.foldM
(fun i r => do
let y := ys.get! i;
let x := xs.get! i;
yVal ← findVarValue y.x;
xVal ← findArgValue x;
let newVal := merge yVal xVal;
if newVal == yVal then pure r
else do
modify $ fun s => { s with assignments := s.assignments.modify currFnIdx $ fun a => a.insert y.x newVal };
pure true)
false
partial def interpFnBody : FnBody → M Unit
| FnBody.vdecl x _ e b => do
v ← interpExpr e;
updateVarAssignment x v;
interpFnBody b
| FnBody.jdecl j ys v b =>
adaptReader (fun (ctx : InterpContext) => { ctx with lctx := ctx.lctx.addJP j ys v }) $
interpFnBody b
| FnBody.case _ x _ alts => do
v ← findVarValue x;
alts.forM $ fun alt =>
match alt with
| Alt.ctor i b => when (containsCtor v i) $ interpFnBody b
| Alt.default b => interpFnBody b
| FnBody.ret x => do
v ← findArgValue x;
-- dbgTrace ("ret " ++ toString v) $ fun _ =>
updateCurrFnSummary v
| FnBody.jmp j xs => do
ctx ← read;
let ys := (ctx.lctx.getJPParams j).get!;
updated ← updateJPParamsAssignment ys xs;
when updated $
interpFnBody $ (ctx.lctx.getJPBody j).get!
| e => unless (e.isTerminal) $ interpFnBody e.body
def inferStep : M Bool := do
ctx ← read;
modify $ fun s => { s with assignments := ctx.decls.map $ fun _ => {} };
ctx.decls.size.foldM (fun idx modified => do
match ctx.decls.get! idx with
| Decl.fdecl fid ys _ b => do
s ← get;
-- dbgTrace (">> " ++ toString fid) $ fun _ =>
let currVals := s.funVals.get! idx;
adaptReader (fun (ctx : InterpContext) => { ctx with currFnIdx := idx }) $ do
ys.forM $ fun y => updateVarAssignment y.x top;
interpFnBody b;
s ← get;
let newVals := s.funVals.get! idx;
pure (modified || currVals != newVals)
| Decl.extern _ _ _ _ => pure modified)
false
partial def inferMain : Unit → M Unit
| _ => do
modified ← inferStep;
if modified then inferMain () else pure ()
partial def elimDeadAux (assignment : Assignment) : FnBody → FnBody
| FnBody.vdecl x t e b => FnBody.vdecl x t e (elimDeadAux b)
| FnBody.jdecl j ys v b => FnBody.jdecl j ys (elimDeadAux v) (elimDeadAux b)
| FnBody.case tid x xType alts =>
let v := assignment.findD x bot;
let alts := alts.map $ fun alt =>
match alt with
| Alt.ctor i b => Alt.ctor i $ if containsCtor v i then elimDeadAux b else FnBody.unreachable
| Alt.default b => Alt.default (elimDeadAux b);
FnBody.case tid x xType alts
| e =>
if e.isTerminal then e
else
let (instr, b) := e.split;
let b := elimDeadAux b;
instr.setBody b
partial def elimDead (assignment : Assignment) : Decl → Decl
| Decl.fdecl fid ys t b => Decl.fdecl fid ys t $ elimDeadAux assignment b
| other => other
end UnreachableBranches
open UnreachableBranches
def elimDeadBranches (decls : Array Decl) : CompilerM (Array Decl) := do
s ← get;
let env := s.env;
let assignments : Array Assignment := decls.map $ fun _ => {};
let funVals := mkPArray decls.size Value.bot;
let ctx : InterpContext := { decls := decls, env := env };
let s : InterpState := { assignments := assignments, funVals := funVals };
let (_, s) := (inferMain () ctx).run s;
let funVals := s.funVals;
let assignments := s.assignments;
modify $ fun s =>
let env := decls.size.fold (fun i env =>
-- dbgTrace (">> " ++ toString (decls.get! i).name ++ " " ++ toString (funVals.get! i)) $ fun _ =>
addFunctionSummary env (decls.get! i).name (funVals.get! i))
s.env;
{ s with env := env };
pure $ decls.mapIdx $ fun i decl => elimDead (assignments.get! i) decl
end IR
end Lean
|
167372458cfc04d40efc95ba2333f197f51c2d86 | 4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d | /src/Lean/Elab/Tactic/Location.lean | ead32d6082b447657ed60a2b7b851894cb91906b | [
"Apache-2.0"
] | permissive | subfish-zhou/leanprover-zh_CN.github.io | 30b9fba9bd790720bd95764e61ae796697d2f603 | 8b2985d4a3d458ceda9361ac454c28168d920d3f | refs/heads/master | 1,689,709,967,820 | 1,632,503,056,000 | 1,632,503,056,000 | 409,962,097 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,716 | 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.Elab.Tactic.Basic
namespace Lean.Elab.Tactic
inductive Location where
| wildcard
| targets (hypotheses : Array Name) (type : Bool)
/-
Recall that
```
syntax locationWildcard := "*"
syntax locationTargets := (colGt ident)+ ("⊢" <|> "|-")?
syntax location := withPosition("at " locationWildcard <|> locationHyp)
```
-/
def expandLocation (stx : Syntax) : Location :=
let arg := stx[1]
if arg.getKind == ``Parser.Tactic.locationWildcard then
Location.wildcard
else
Location.targets (arg[0].getArgs.map fun stx => stx.getId) (!arg[1].isNone)
def expandOptLocation (stx : Syntax) : Location :=
if stx.isNone then
Location.targets #[] true
else
expandLocation stx[0]
open Meta
def withLocation (loc : Location) (atLocal : FVarId → TacticM Unit) (atTarget : TacticM Unit) (failed : MVarId → TacticM Unit) : TacticM Unit := do
match loc with
| Location.targets hyps type =>
hyps.forM fun userName => withMainContext do
let localDecl ← getLocalDeclFromUserName userName
atLocal localDecl.fvarId
if type then
atTarget
| Location.wildcard =>
let worked ← tryTactic <| withMainContext <| atTarget
withMainContext do
let mut worked := worked
-- We must traverse backwards because the given `atLocal` may use the revert/intro idiom
for fvarId in (← getLCtx).getFVarIds.reverse do
worked := worked || (← tryTactic <| withMainContext <| atLocal fvarId)
unless worked do
failed (← getMainGoal)
end Lean.Elab.Tactic
|
3f60c86cdcb6014b32761615f1aa26f3b33837da | 9d00e4b237465921fb33aa10eed92a2495ca2e46 | /negBotRules.lean | c043d43a54df4edd67379c22b68515bc11ac4d97 | [] | no_license | Bpalkmim/LeanNatD | 7756abf1ed7b0e7a3e3b9d16ad756018f5c70c7c | 2e73bb44e44b955839e7a0874cd7013fbfb9c4e3 | refs/heads/master | 1,610,999,141,530 | 1,475,515,895,000 | 1,475,515,895,000 | 69,893,600 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,094 | lean | namespace negBotRules
-- Requer o namespace de implicação
open implRules
print " "
print "Provas com NEG & BOT - início"
print " "
constant neg : Prop → Prop
constant Bottom : Prop
constant A : Prop
-- Definições
constant neg_intro {X : Prop} : (Π x : Proof X, Proof Bottom) → Proof Bottom → Proof (neg X)
constant neg_elim {X : Prop} : Proof X → Proof (neg X) → Proof Bottom
constant bot_classic {X : Prop} : (Π x : Proof (neg X), Proof Bottom) → Proof Bottom → Proof X
constant bot_intui {X : Prop} : Proof Bottom → Proof X → Proof X
-- Termos úteis
variable a : Proof A
variable na : Proof (neg A)
variable bot : Proof Bottom
variable aDEPbot : Π x : Proof A, Proof Bottom
variable naDEPbot : Π x : Proof (neg A), Proof Bottom
-- Testes iniciais
check @neg_intro
check @neg_elim
check @bot_classic
check @bot_intui
check neg_intro aDEPbot bot
check neg_elim a na
check bot_classic naDEPbot bot
check bot_intui bot a
print "------"
-- Testes parciais
print "------"
-- Teste final
print " "
print "Provas com NEG & BOT - fim"
print " "
end negBotRules |
8f7d9de71aa81eb896e1161ac7eb819bcbe7d617 | d1a52c3f208fa42c41df8278c3d280f075eb020c | /stage0/src/Leanpkg/Proc.lean | cd4db43195a73b3846a9be6b6adaa65f161f3e71 | [
"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 | 729 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sebastian Ullrich
-/
namespace Leanpkg
def execCmd (args : IO.Process.SpawnArgs) : IO Unit := do
let envstr := String.join <| args.env.toList.map fun (k, v) => s!"{k}={v.getD ""} "
let cmdstr := " ".intercalate (args.cmd :: args.args.toList)
IO.eprintln <| "> " ++ envstr ++
match args.cwd with
| some cwd => s!"{cmdstr} # in directory {cwd}"
| none => cmdstr
let child ← IO.Process.spawn args
let exitCode ← child.wait
if exitCode != 0 then
throw <| IO.userError <| s!"external command exited with status {exitCode}"
end Leanpkg
|
9fbea9e743b4d38d3a8c590dd85de8651c0808d3 | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/tactic/tidy.lean | 0079c54baa3bf7e5283f77d5e4b31b1b18c531c8 | [
"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 | 3,084 | 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.ext
import tactic.auto_cases
import tactic.chain
import tactic.interactive
namespace tactic
namespace tidy
meta def tidy_attribute : user_attribute := {
name := `tidy,
descr := "A tactic that should be called by `tidy`."
}
run_cmd attribute.register ``tidy_attribute
meta def name_to_tactic (n : name) : tactic string :=
do d ← get_decl n,
e ← mk_const n,
let t := d.type,
if (t =ₐ `(tactic unit)) then
(eval_expr (tactic unit) e) >>= (λ t, t >> pure n.to_string)
else if (t =ₐ `(tactic string)) then
(eval_expr (tactic string) e) >>= (λ t, t)
else fail "invalid type for @[tidy] tactic"
meta def run_tactics : tactic string :=
do names ← attribute.get_instances `tidy,
first (names.map name_to_tactic) <|> fail "no @[tidy] tactics succeeded"
meta def ext1_wrapper : tactic string :=
do ng ← num_goals,
ext1 [] {apply_cfg . new_goals := new_goals.all},
ng' ← num_goals,
return $ if ng' > ng then
"tactic.ext1 [] {new_goals := tactic.new_goals.all}"
else "ext1"
meta def default_tactics : list (tactic string) :=
[ reflexivity >> pure "refl",
`[exact dec_trivial] >> pure "exact dec_trivial",
propositional_goal >> assumption >> pure "assumption",
ext1_wrapper,
intros1 >>= λ ns, pure ("intros " ++ (" ".intercalate (ns.map (λ e, e.to_string)))),
auto_cases,
`[apply_auto_param] >> pure "apply_auto_param",
`[dsimp at *] >> pure "dsimp at *",
`[simp at *] >> pure "simp at *",
fsplit >> pure "fsplit",
injections_and_clear >> pure "injections_and_clear",
propositional_goal >> (`[solve_by_elim]) >> pure "solve_by_elim",
`[unfold_aux] >> pure "unfold_aux",
tidy.run_tactics ]
meta structure cfg :=
(trace_result : bool := ff)
(trace_result_prefix : string := "/- `tidy` says -/ ")
(tactics : list (tactic string) := default_tactics)
declare_trace tidy
meta def core (cfg : cfg := {}) : tactic (list string) :=
do
results ← chain cfg.tactics,
when (cfg.trace_result ∨ is_trace_enabled_for `tidy) $
trace (cfg.trace_result_prefix ++ (", ".intercalate results)),
return results
end tidy
meta def tidy (cfg : tidy.cfg := {}) := tactic.tidy.core cfg >> skip
namespace interactive
open lean.parser interactive
meta def tidy (trace : parse $ optional (tk "?")) (cfg : tidy.cfg := {}) :=
tactic.tidy { trace_result := trace.is_some, ..cfg }
end interactive
@[hole_command] meta def tidy_hole_cmd : hole_command :=
{ name := "tidy",
descr := "Use `tidy` to complete the goal.",
action := λ _, do script ← tidy.core, return [("begin " ++ (", ".intercalate script) ++ " end", "by tidy")] }
end tactic
|
0a748d54618d042e4303111acd17f909c79314c8 | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /stage0/src/Lean/Compiler/LCNF/PassManager.lean | 2ec91334cb32412394888833134eb273bae42cee | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 5,950 | lean | /-
Copyright (c) 2022 Henrik Böving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving
-/
import Lean.Attributes
import Lean.Environment
import Lean.Meta.Basic
import Lean.Compiler.LCNF.CompilerM
namespace Lean.Compiler.LCNF
/--
A single compiler `Pass`, consisting of the actual pass function operating
on the `Decl`s as well as meta information.
-/
structure Pass where
/--
Which occurrence of the pass in the pipeline this is.
Some passes, like simp, can occur multiple times in the pipeline.
For most passes this value does not matter.
-/
occurrence : Nat := 0
/--
Which phase this `Pass` is supposed to run in
-/
phase : Phase
/--
The name of the `Pass`
-/
name : Name
/--
The actual pass function, operating on the `Decl`s.
-/
run : Array Decl → CompilerM (Array Decl)
deriving Inhabited
/--
Can be used to install, remove, replace etc. passes by tagging a declaration
of type `PassInstaller` with the `cpass` attribute.
-/
structure PassInstaller where
/--
When the installer is run this function will receive a list of all
current `Pass`es and return a new one, this can modify the list (and
the `Pass`es contained within) in any way it wants.
-/
install : Array Pass → CoreM (Array Pass)
deriving Inhabited
/--
The `PassManager` used to store all `Pass`es that will be run within
pipeline.
-/
structure PassManager where
passes : Array Pass
deriving Inhabited
namespace Phase
def toNat : Phase → Nat
| .base => 0
| .mono => 1
| .impure => 2
instance : LT Phase where
lt l r := l.toNat < r.toNat
instance : LE Phase where
le l r := l.toNat ≤ r.toNat
instance {p1 p2 : Phase} : Decidable (p1 < p2) := Nat.decLt p1.toNat p2.toNat
instance {p1 p2 : Phase} : Decidable (p1 ≤ p2) := Nat.decLe p1.toNat p2.toNat
instance : ToString Phase where
toString
| .base => "base"
| .mono => "mono"
| .impure => "impure"
end Phase
namespace Pass
def mkPerDeclaration (name : Name) (run : Decl → CompilerM Decl) (phase : Phase) (occurrence : Nat := 0) : Pass where
occurrence := occurrence
phase := phase
name := name
run := fun xs => xs.mapM run
end Pass
namespace PassManager
def validate (manager : PassManager) : CoreM Unit := do
let mut current := .base
for pass in manager.passes do
if ¬(current ≤ pass.phase) then
throwError s!"{pass.name} has phase {pass.phase} but should at least have {current}"
current := pass.phase
def findHighestOccurrence (targetName : Name) (passes : Array Pass) : CoreM Nat := do
let mut highest := none
for pass in passes do
if pass.name == targetName then
highest := some pass.occurrence
let some val := highest | throwError s!"Could not find any occurrence of {targetName}"
return val
end PassManager
namespace PassInstaller
def installAtEnd (p : Pass) : PassInstaller where
install passes := return passes.push p
def append (passesNew : Array Pass) : PassInstaller where
install passes := return passes ++ passesNew
def withEachOccurrence (targetName : Name) (f : Nat → PassInstaller) : PassInstaller where
install passes := do
let highestOccurrence ← PassManager.findHighestOccurrence targetName passes
let mut passes := passes
for occurrence in [0:highestOccurrence+1] do
passes ← f occurrence |>.install passes
return passes
def installAfter (targetName : Name) (p : Pass → Pass) (occurrence : Nat := 0) : PassInstaller where
install passes :=
if let some idx := passes.findIdx? (fun p => p.name == targetName && p.occurrence == occurrence) then
let passUnderTest := passes[idx]!
return passes.insertAt! (idx + 1) (p passUnderTest)
else
throwError s!"Tried to insert pass after {targetName}, occurrence {occurrence} but {targetName} is not in the pass list"
def installAfterEach (targetName : Name) (p : Pass → Pass) : PassInstaller :=
withEachOccurrence targetName (installAfter targetName p ·)
def installBefore (targetName : Name) (p : Pass → Pass) (occurrence : Nat := 0): PassInstaller where
install passes :=
if let some idx := passes.findIdx? (fun p => p.name == targetName && p.occurrence == occurrence) then
let passUnderTest := passes[idx]!
return passes.insertAt! idx (p passUnderTest)
else
throwError s!"Tried to insert pass after {targetName}, occurrence {occurrence} but {targetName} is not in the pass list"
def installBeforeEachOccurrence (targetName : Name) (p : Pass → Pass) : PassInstaller :=
withEachOccurrence targetName (installBefore targetName p ·)
def replacePass (targetName : Name) (p : Pass → Pass) (occurrence : Nat := 0) : PassInstaller where
install passes := do
let some idx := passes.findIdx? (fun p => p.name == targetName && p.occurrence == occurrence) | throwError s!"Tried to replace {targetName}, occurrence {occurrence} but {targetName} is not in the pass list"
let target := passes[idx]!
let replacement := p target
return passes.set! idx replacement
def replaceEachOccurrence (targetName : Name) (p : Pass → Pass) : PassInstaller :=
withEachOccurrence targetName (replacePass targetName p ·)
def run (manager : PassManager) (installer : PassInstaller) : CoreM PassManager := do
return { manager with passes := (← installer.install manager.passes) }
private unsafe def getPassInstallerUnsafe (declName : Name) : CoreM PassInstaller := do
ofExcept <| (← getEnv).evalConstCheck PassInstaller (← getOptions) ``PassInstaller declName
@[implementedBy getPassInstallerUnsafe]
private opaque getPassInstaller (declName : Name) : CoreM PassInstaller
def runFromDecl (manager : PassManager) (declName : Name) : CoreM PassManager := do
let installer ← getPassInstaller declName
let newState ← installer.run manager
newState.validate
return newState
end PassInstaller
end Lean.Compiler.LCNF
|
a6e931e2a6018b01fdd12d39569a9ca8e7dbd816 | 853df553b1d6ca524e3f0a79aedd32dde5d27ec3 | /src/category_theory/closed/cartesian.lean | e99ad286c72bcb4ac149fa6181222208e6a2a1c0 | [
"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 | 16,087 | lean | /-
Copyright (c) 2020 Bhavik Mehta, Edward Ayers, Thomas Read. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Edward Ayers, Thomas Read
-/
import category_theory.limits.shapes.finite_products
import category_theory.limits.shapes.constructions.preserve_binary_products
import category_theory.closed.monoidal
import category_theory.monoidal.of_has_finite_products
import category_theory.adjunction
import category_theory.epi_mono
/-!
# Cartesian closed categories
Given a category with finite products, the cartesian monoidal structure is provided by the local
instance `monoidal_of_has_finite_products`.
We define exponentiable objects to be closed objects with respect to this monoidal structure,
i.e. `(X × -)` is a left adjoint.
We say a category is cartesian closed if every object is exponentiable
(equivalently, that the category equipped with the cartesian monoidal structure is closed monoidal).
Show that exponential forms a difunctor and define the exponential comparison morphisms.
## TODO
Some of the results here are true more generally for closed objects and
for closed monoidal categories, and these could be generalised.
-/
universes v u u₂
namespace category_theory
open category_theory category_theory.category category_theory.limits
local attribute [instance] monoidal_of_has_finite_products
/--
An object `X` is *exponentiable* if `(X × -)` is a left adjoint.
We define this as being `closed` in the cartesian monoidal structure.
-/
abbreviation exponentiable {C : Type u} [category.{v} C] [has_finite_products C] (X : C) :=
closed X
/--
If `X` and `Y` are exponentiable then `X ⨯ Y` is.
This isn't an instance because it's not usually how we want to construct exponentials, we'll usually
prove all objects are exponential uniformly.
-/
def binary_product_exponentiable {C : Type u} [category.{v} C] [has_finite_products C] {X Y : C}
(hX : exponentiable X) (hY : exponentiable Y) : exponentiable (X ⨯ Y) :=
{ is_adj :=
begin
haveI := hX.is_adj,
haveI := hY.is_adj,
exact adjunction.left_adjoint_of_nat_iso (monoidal_category.tensor_left_tensor _ _).symm
end }
/--
The terminal object is always exponentiable.
This isn't an instance because most of the time we'll prove cartesian closed for all objects
at once, rather than just for this one.
-/
def terminal_exponentiable {C : Type u} [category.{v} C] [has_finite_products C] :
exponentiable ⊤_C :=
unit_closed
/--
A category `C` is cartesian closed if it has finite products and every object is exponentiable.
We define this as `monoidal_closed` with respect to the cartesian monoidal structure.
-/
abbreviation cartesian_closed (C : Type u) [category.{v} C] [has_finite_products C] :=
monoidal_closed C
variables {C : Type u} [category.{v} C] (A B : C) {X X' Y Y' Z : C}
section exp
variables [has_finite_products C] [exponentiable A]
/-- This is (-)^A. -/
def exp : C ⥤ C :=
(@closed.is_adj _ _ _ A _).right
/-- The adjunction between A ⨯ - and (-)^A. -/
def exp.adjunction : prod_functor.obj A ⊣ exp A :=
closed.is_adj.adj
/-- The evaluation natural transformation. -/
def ev : exp A ⋙ prod_functor.obj A ⟶ 𝟭 C :=
closed.is_adj.adj.counit
/-- The coevaluation natural transformation. -/
def coev : 𝟭 C ⟶ prod_functor.obj A ⋙ exp A :=
closed.is_adj.adj.unit
notation A ` ⟹ `:20 B:20 := (exp A).obj B
notation B ` ^^ `:30 A:30 := (exp A).obj B
@[simp, reassoc] lemma ev_coev :
limits.prod.map (𝟙 A) ((coev A).app B) ≫ (ev A).app (A ⨯ B) = 𝟙 (A ⨯ B) :=
adjunction.left_triangle_components (exp.adjunction A)
@[simp, reassoc] lemma coev_ev : (coev A).app (A⟹B) ≫ (exp A).map ((ev A).app B) = 𝟙 (A⟹B) :=
adjunction.right_triangle_components (exp.adjunction A)
end exp
variables {A}
-- Wrap these in a namespace so we don't clash with the core versions.
namespace cartesian_closed
variables [has_finite_products C] [exponentiable A]
/-- Currying in a cartesian closed category. -/
def curry : (A ⨯ Y ⟶ X) → (Y ⟶ A ⟹ X) :=
(closed.is_adj.adj.hom_equiv _ _).to_fun
/-- Uncurrying in a cartesian closed category. -/
def uncurry : (Y ⟶ A ⟹ X) → (A ⨯ Y ⟶ X) :=
(closed.is_adj.adj.hom_equiv _ _).inv_fun
end cartesian_closed
open cartesian_closed
variables [has_finite_products C] [exponentiable A]
@[reassoc]
lemma curry_natural_left (f : X ⟶ X') (g : A ⨯ X' ⟶ Y) :
curry (limits.prod.map (𝟙 _) f ≫ g) = f ≫ curry g :=
adjunction.hom_equiv_naturality_left _ _ _
@[reassoc]
lemma curry_natural_right (f : A ⨯ X ⟶ Y) (g : Y ⟶ Y') :
curry (f ≫ g) = curry f ≫ (exp _).map g :=
adjunction.hom_equiv_naturality_right _ _ _
@[reassoc]
lemma uncurry_natural_right (f : X ⟶ A⟹Y) (g : Y ⟶ Y') :
uncurry (f ≫ (exp _).map g) = uncurry f ≫ g :=
adjunction.hom_equiv_naturality_right_symm _ _ _
@[reassoc]
lemma uncurry_natural_left (f : X ⟶ X') (g : X' ⟶ A⟹Y) :
uncurry (f ≫ g) = limits.prod.map (𝟙 _) f ≫ uncurry g :=
adjunction.hom_equiv_naturality_left_symm _ _ _
@[simp]
lemma uncurry_curry (f : A ⨯ X ⟶ Y) : uncurry (curry f) = f :=
(closed.is_adj.adj.hom_equiv _ _).left_inv f
@[simp]
lemma curry_uncurry (f : X ⟶ A⟹Y) : curry (uncurry f) = f :=
(closed.is_adj.adj.hom_equiv _ _).right_inv f
lemma curry_eq_iff (f : A ⨯ Y ⟶ X) (g : Y ⟶ A ⟹ X) :
curry f = g ↔ f = uncurry g :=
adjunction.hom_equiv_apply_eq _ f g
lemma eq_curry_iff (f : A ⨯ Y ⟶ X) (g : Y ⟶ A ⟹ X) :
g = curry f ↔ uncurry g = f :=
adjunction.eq_hom_equiv_apply _ f g
-- I don't think these two should be simp.
lemma uncurry_eq (g : Y ⟶ A ⟹ X) : uncurry g = limits.prod.map (𝟙 A) g ≫ (ev A).app X :=
adjunction.hom_equiv_counit _
lemma curry_eq (g : A ⨯ Y ⟶ X) : curry g = (coev A).app Y ≫ (exp A).map g :=
adjunction.hom_equiv_unit _
lemma uncurry_id_eq_ev (A X : C) [exponentiable A] : uncurry (𝟙 (A ⟹ X)) = (ev A).app X :=
by rw [uncurry_eq, prod_map_id_id, id_comp]
lemma curry_id_eq_coev (A X : C) [exponentiable A] : curry (𝟙 _) = (coev A).app X :=
by { rw [curry_eq, (exp A).map_id (A ⨯ _)], apply comp_id }
lemma curry_injective : function.injective (curry : (A ⨯ Y ⟶ X) → (Y ⟶ A ⟹ X)) :=
(closed.is_adj.adj.hom_equiv _ _).injective
lemma uncurry_injective : function.injective (uncurry : (Y ⟶ A ⟹ X) → (A ⨯ Y ⟶ X)) :=
(closed.is_adj.adj.hom_equiv _ _).symm.injective
/--
Show that the exponential of the terminal object is isomorphic to itself, i.e. `X^1 ≅ X`.
The typeclass argument is explicit: any instance can be used.
-/
def exp_terminal_iso_self [exponentiable ⊤_C] : (⊤_C ⟹ X) ≅ X :=
yoneda.ext (⊤_ C ⟹ X) X
(λ Y f, (prod.left_unitor Y).inv ≫ uncurry f)
(λ Y f, curry ((prod.left_unitor Y).hom ≫ f))
(λ Z g, by rw [curry_eq_iff, iso.hom_inv_id_assoc] )
(λ Z g, by simp)
(λ Z W f g, by rw [uncurry_natural_left, prod_left_unitor_inv_naturality_assoc f] )
/-- The internal element which points at the given morphism. -/
def internalize_hom (f : A ⟶ Y) : ⊤_C ⟶ (A ⟹ Y) :=
curry (limits.prod.fst ≫ f)
section pre
variables {B}
/-- Pre-compose an internal hom with an external hom. -/
def pre (X : C) (f : B ⟶ A) [exponentiable B] : (A⟹X) ⟶ B⟹X :=
curry (limits.prod.map f (𝟙 _) ≫ (ev A).app X)
lemma pre_id (A X : C) [exponentiable A] : pre X (𝟙 A) = 𝟙 (A⟹X) :=
by { rw [pre, prod_map_id_id, id_comp, ← uncurry_id_eq_ev], simp }
-- There's probably a better proof of this somehow
/-- Precomposition is contrafunctorial. -/
lemma pre_map [exponentiable B] {D : C} [exponentiable D] (f : A ⟶ B) (g : B ⟶ D) :
pre X (f ≫ g) = pre X g ≫ pre X f :=
begin
rw [pre, curry_eq_iff, pre, pre, uncurry_natural_left, uncurry_curry, prod_map_map_assoc,
prod_map_comp_id, assoc, ← uncurry_id_eq_ev, ← uncurry_id_eq_ev, ← uncurry_natural_left,
curry_natural_right, comp_id, uncurry_natural_right, uncurry_curry],
end
end pre
lemma pre_post_comm [cartesian_closed C] {A B : C} {X Y : Cᵒᵖ} (f : A ⟶ B) (g : X ⟶ Y) :
pre A g.unop ≫ (exp Y.unop).map f = (exp X.unop).map f ≫ pre B g.unop :=
begin
erw [← curry_natural_left, eq_curry_iff, uncurry_natural_right, uncurry_curry, prod_map_map_assoc,
(ev _).naturality, assoc], refl
end
/-- The internal hom functor given by the cartesian closed structure. -/
def internal_hom [cartesian_closed C] : C ⥤ Cᵒᵖ ⥤ C :=
{ obj := λ X,
{ obj := λ Y, Y.unop ⟹ X,
map := λ Y Y' f, pre _ f.unop,
map_id' := λ Y, pre_id _ _,
map_comp' := λ Y Y' Y'' f g, pre_map _ _ },
map := λ A B f, { app := λ X, (exp X.unop).map f, naturality' := λ X Y g, pre_post_comm _ _ },
map_id' := λ X, by { ext, apply functor.map_id },
map_comp' := λ X Y Z f g, by { ext, apply functor.map_comp } }
/-- If an initial object `0` exists in a CCC, then `A ⨯ 0 ≅ 0`. -/
@[simps]
def zero_mul [has_initial C] : A ⨯ ⊥_ C ≅ ⊥_ C :=
{ hom := limits.prod.snd,
inv := default (⊥_ C ⟶ A ⨯ ⊥_ C),
hom_inv_id' :=
begin
have: (limits.prod.snd : A ⨯ ⊥_ C ⟶ ⊥_ C) = uncurry (default _),
rw ← curry_eq_iff,
apply subsingleton.elim,
rw [this, ← uncurry_natural_right, ← eq_curry_iff],
apply subsingleton.elim
end,
}
/-- If an initial object `0` exists in a CCC, then `0 ⨯ A ≅ 0`. -/
def mul_zero [has_initial C] : ⊥_ C ⨯ A ≅ ⊥_ C :=
limits.prod.braiding _ _ ≪≫ zero_mul
/-- If an initial object `0` exists in a CCC then `0^B ≅ 1` for any `B`. -/
def pow_zero [has_initial C] [cartesian_closed C] : ⊥_C ⟹ B ≅ ⊤_ C :=
{ hom := default _,
inv := curry (mul_zero.hom ≫ default (⊥_ C ⟶ B)),
hom_inv_id' :=
begin
rw [← curry_natural_left, curry_eq_iff, ← cancel_epi mul_zero.inv],
{ apply subsingleton.elim },
{ apply_instance },
{ apply_instance }
end }
-- TODO: Generalise the below to its commutated variants.
-- TODO: Define a distributive category, so that zero_mul and friends can be derived from this.
/-- In a CCC with binary coproducts, the distribution morphism is an isomorphism. -/
def prod_coprod_distrib [has_binary_coproducts C] [cartesian_closed C] (X Y Z : C) :
(Z ⨯ X) ⨿ (Z ⨯ Y) ≅ Z ⨯ (X ⨿ Y) :=
{ hom := coprod.desc (limits.prod.map (𝟙 _) coprod.inl) (limits.prod.map (𝟙 _) coprod.inr),
inv := uncurry (coprod.desc (curry coprod.inl) (curry coprod.inr)),
hom_inv_id' :=
begin
apply coprod.hom_ext,
rw [coprod.inl_desc_assoc, comp_id, ←uncurry_natural_left, coprod.inl_desc, uncurry_curry],
rw [coprod.inr_desc_assoc, comp_id, ←uncurry_natural_left, coprod.inr_desc, uncurry_curry],
end,
inv_hom_id' :=
begin
rw [← uncurry_natural_right, ←eq_curry_iff],
apply coprod.hom_ext,
rw [coprod.inl_desc_assoc, ←curry_natural_right, coprod.inl_desc, ←curry_natural_left, comp_id],
rw [coprod.inr_desc_assoc, ←curry_natural_right, coprod.inr_desc, ←curry_natural_left, comp_id],
end }
/--
If an initial object `0` exists in a CCC then it is a strict initial object,
i.e. any morphism to `0` is an iso.
-/
instance strict_initial [has_initial C] {f : A ⟶ ⊥_ C} : is_iso f :=
begin
haveI : mono (limits.prod.lift (𝟙 A) f ≫ zero_mul.hom) := mono_comp _ _,
rw [zero_mul_hom, prod.lift_snd] at _inst,
haveI: split_epi f := ⟨default _, subsingleton.elim _ _⟩,
apply is_iso_of_mono_of_split_epi
end
/-- If an initial object `0` exists in a CCC then every morphism from it is monic. -/
instance initial_mono (B : C) [has_initial C] [cartesian_closed C] : mono (initial.to B) :=
⟨λ B g h _, eq_of_inv_eq_inv (subsingleton.elim (inv g) (inv h))⟩
variables {D : Type u₂} [category.{v} D]
section functor
variables [has_finite_products D]
/--
Transport the property of being cartesian closed across an equivalence of categories.
Note we didn't require any coherence between the choice of finite products here, since we transport
along the `prod_comparison` isomorphism.
-/
def cartesian_closed_of_equiv (e : C ≌ D) [h : cartesian_closed C] : cartesian_closed D :=
{ closed := λ X,
{ is_adj :=
begin
haveI q : exponentiable (e.inverse.obj X) := infer_instance,
have : is_left_adjoint (prod_functor.obj (e.inverse.obj X)) := q.is_adj,
have : e.functor ⋙ prod_functor.obj X ⋙ e.inverse ≅ prod_functor.obj (e.inverse.obj X),
apply nat_iso.of_components _ _,
intro Y,
{ apply as_iso (prod_comparison e.inverse X (e.functor.obj Y)) ≪≫ _,
exact ⟨limits.prod.map (𝟙 _) (e.unit_inv.app _),
limits.prod.map (𝟙 _) (e.unit.app _),
by simpa [←prod_map_id_comp, prod_map_id_id],
by simpa [←prod_map_id_comp, prod_map_id_id]⟩, },
{ intros Y Z g,
simp only [prod_comparison, inv_prod_comparison_map_fst, inv_prod_comparison_map_snd,
prod.lift_map, functor.comp_map, prod_functor_obj_map, assoc, comp_id,
iso.trans_hom, as_iso_hom],
apply prod.hom_ext,
{ rw [assoc, prod.lift_fst, prod.lift_fst, ←functor.map_comp,
limits.prod.map_fst, comp_id], },
{ rw [assoc, prod.lift_snd, prod.lift_snd, ←functor.map_comp_assoc, limits.prod.map_snd],
simp only [nat_iso.hom_inv_id_app, assoc, equivalence.inv_fun_map,
functor.map_comp, comp_id],
erw comp_id, }, },
{ have : is_left_adjoint (e.functor ⋙ prod_functor.obj X ⋙ e.inverse) :=
by exactI adjunction.left_adjoint_of_nat_iso this.symm,
have : is_left_adjoint (e.inverse ⋙ e.functor ⋙ prod_functor.obj X ⋙ e.inverse) :=
by exactI adjunction.left_adjoint_of_comp e.inverse _,
have : (e.inverse ⋙ e.functor ⋙ prod_functor.obj X ⋙ e.inverse) ⋙ e.functor ≅
prod_functor.obj X,
{ apply iso_whisker_right e.counit_iso (prod_functor.obj X ⋙ e.inverse ⋙ e.functor) ≪≫ _,
change prod_functor.obj X ⋙ e.inverse ⋙ e.functor ≅ prod_functor.obj X,
apply iso_whisker_left (prod_functor.obj X) e.counit_iso, },
resetI,
apply adjunction.left_adjoint_of_nat_iso this },
end } }
variables [cartesian_closed C] [cartesian_closed D]
variables (F : C ⥤ D) [preserves_limits_of_shape (discrete walking_pair) F]
/--
The exponential comparison map.
`F` is a cartesian closed functor if this is an iso for all `A,B`.
-/
def exp_comparison (A B : C) :
F.obj (A ⟹ B) ⟶ F.obj A ⟹ F.obj B :=
curry (inv (prod_comparison F A _) ≫ F.map ((ev _).app _))
/-- The exponential comparison map is natural in its left argument. -/
lemma exp_comparison_natural_left (A A' B : C) (f : A' ⟶ A) :
exp_comparison F A B ≫ pre (F.obj B) (F.map f) = F.map (pre B f) ≫ exp_comparison F A' B :=
begin
rw [exp_comparison, exp_comparison, ← curry_natural_left, eq_curry_iff, uncurry_natural_left,
pre, uncurry_curry, prod_map_map_assoc, curry_eq, prod_map_id_comp, assoc],
erw [(ev _).naturality, ev_coev_assoc, ← F.map_id, ← prod_comparison_inv_natural_assoc,
← F.map_id, ← prod_comparison_inv_natural_assoc, ← F.map_comp, ← F.map_comp, pre, curry_eq,
prod_map_id_comp, assoc, (ev _).naturality, ev_coev_assoc], refl,
end
/-- The exponential comparison map is natural in its right argument. -/
lemma exp_comparison_natural_right (A B B' : C) (f : B ⟶ B') :
exp_comparison F A B ≫ (exp (F.obj A)).map (F.map f) =
F.map ((exp A).map f) ≫ exp_comparison F A B' :=
by
erw [exp_comparison, ← curry_natural_right, curry_eq_iff, exp_comparison, uncurry_natural_left,
uncurry_curry, assoc, ← F.map_comp, ← (ev _).naturality, F.map_comp,
prod_comparison_inv_natural_assoc, F.map_id]
-- TODO: If F has a left adjoint L, then F is cartesian closed if and only if
-- L (B ⨯ F A) ⟶ L B ⨯ L F A ⟶ L B ⨯ A
-- is an iso for all A ∈ D, B ∈ C.
-- Corollary: If F has a left adjoint L which preserves finite products, F is cartesian closed iff
-- F is full and faithful.
end functor
end category_theory
|
9b233ecafa87e349b49fa789dbb221bf158b3f2a | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/calculus/dslope.lean | 594cc93865f6d48da6091470b392eab06e938845 | [
"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 | 6,410 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.calculus.deriv.slope
import analysis.calculus.deriv.inv
/-!
# Slope of a differentiable function
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Given a function `f : 𝕜 → E` from a nontrivially normed field to a normed space over this field,
`dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and as `deriv f a`
for `a = b`.
In this file we define `dslope` and prove some basic lemmas about its continuity and
differentiability.
-/
open_locale classical topology filter
open function set filter
variables {𝕜 E : Type*} [nontrivially_normed_field 𝕜] [normed_add_comm_group E] [normed_space 𝕜 E]
/-- `dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and
`deriv f a` for `a = b`. -/
noncomputable def dslope (f : 𝕜 → E) (a : 𝕜) : 𝕜 → E := update (slope f a) a (deriv f a)
@[simp] lemma dslope_same (f : 𝕜 → E) (a : 𝕜) : dslope f a a = deriv f a := update_same _ _ _
variables {f : 𝕜 → E} {a b : 𝕜} {s : set 𝕜}
lemma dslope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a b = slope f a b :=
update_noteq h _ _
lemma continuous_linear_map.dslope_comp {F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]
(f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → differentiable_at 𝕜 g a) :
dslope (f ∘ g) a b = f (dslope g a b) :=
begin
rcases eq_or_ne b a with rfl|hne,
{ simp only [dslope_same],
exact (f.has_fderiv_at.comp_has_deriv_at b (H rfl).has_deriv_at).deriv },
{ simpa only [dslope_of_ne _ hne] using f.to_linear_map.slope_comp g a b }
end
lemma eq_on_dslope_slope (f : 𝕜 → E) (a : 𝕜) : eq_on (dslope f a) (slope f a) {a}ᶜ :=
λ b, dslope_of_ne f
lemma dslope_eventually_eq_slope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a =ᶠ[𝓝 b] slope f a :=
(eq_on_dslope_slope f a).eventually_eq_of_mem (is_open_ne.mem_nhds h)
lemma dslope_eventually_eq_slope_punctured_nhds (f : 𝕜 → E) : dslope f a =ᶠ[𝓝[≠] a] slope f a :=
(eq_on_dslope_slope f a).eventually_eq_of_mem self_mem_nhds_within
@[simp] lemma sub_smul_dslope (f : 𝕜 → E) (a b : 𝕜) : (b - a) • dslope f a b = f b - f a :=
by rcases eq_or_ne b a with rfl | hne; simp [dslope_of_ne, *]
lemma dslope_sub_smul_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope (λ x, (x - a) • f x) a b = f b :=
by rw [dslope_of_ne _ h, slope_sub_smul _ h.symm]
lemma eq_on_dslope_sub_smul (f : 𝕜 → E) (a : 𝕜) : eq_on (dslope (λ x, (x - a) • f x) a) f {a}ᶜ :=
λ b, dslope_sub_smul_of_ne f
lemma dslope_sub_smul [decidable_eq 𝕜] (f : 𝕜 → E) (a : 𝕜) :
dslope (λ x, (x - a) • f x) a = update f a (deriv (λ x, (x - a) • f x) a) :=
eq_update_iff.2 ⟨dslope_same _ _, eq_on_dslope_sub_smul f a⟩
@[simp] lemma continuous_at_dslope_same : continuous_at (dslope f a) a ↔ differentiable_at 𝕜 f a :=
by simp only [dslope, continuous_at_update_same, ← has_deriv_at_deriv_iff,
has_deriv_at_iff_tendsto_slope]
lemma continuous_within_at.of_dslope (h : continuous_within_at (dslope f a) s b) :
continuous_within_at f s b :=
have continuous_within_at (λ x, (x - a) • dslope f a x + f a) s b,
from ((continuous_within_at_id.sub continuous_within_at_const).smul h).add
continuous_within_at_const,
by simpa only [sub_smul_dslope, sub_add_cancel] using this
lemma continuous_at.of_dslope (h : continuous_at (dslope f a) b) : continuous_at f b :=
(continuous_within_at_univ _ _).1 h.continuous_within_at.of_dslope
lemma continuous_on.of_dslope (h : continuous_on (dslope f a) s) : continuous_on f s :=
λ x hx, (h x hx).of_dslope
lemma continuous_within_at_dslope_of_ne (h : b ≠ a) :
continuous_within_at (dslope f a) s b ↔ continuous_within_at f s b :=
begin
refine ⟨continuous_within_at.of_dslope, λ hc, _⟩,
simp only [dslope, continuous_within_at_update_of_ne h],
exact ((continuous_within_at_id.sub continuous_within_at_const).inv₀
(sub_ne_zero.2 h)).smul (hc.sub continuous_within_at_const)
end
lemma continuous_at_dslope_of_ne (h : b ≠ a) : continuous_at (dslope f a) b ↔ continuous_at f b :=
by simp only [← continuous_within_at_univ, continuous_within_at_dslope_of_ne h]
lemma continuous_on_dslope (h : s ∈ 𝓝 a) :
continuous_on (dslope f a) s ↔ continuous_on f s ∧ differentiable_at 𝕜 f a :=
begin
refine ⟨λ hc, ⟨hc.of_dslope, continuous_at_dslope_same.1 $ hc.continuous_at h⟩, _⟩,
rintro ⟨hc, hd⟩ x hx,
rcases eq_or_ne x a with rfl | hne,
exacts [(continuous_at_dslope_same.2 hd).continuous_within_at,
(continuous_within_at_dslope_of_ne hne).2 (hc x hx)]
end
lemma differentiable_within_at.of_dslope (h : differentiable_within_at 𝕜 (dslope f a) s b) :
differentiable_within_at 𝕜 f s b :=
by simpa only [id, sub_smul_dslope f a, sub_add_cancel]
using ((differentiable_within_at_id.sub_const a).smul h).add_const (f a)
lemma differentiable_at.of_dslope (h : differentiable_at 𝕜 (dslope f a) b) :
differentiable_at 𝕜 f b :=
differentiable_within_at_univ.1 h.differentiable_within_at.of_dslope
lemma differentiable_on.of_dslope (h : differentiable_on 𝕜 (dslope f a) s) :
differentiable_on 𝕜 f s :=
λ x hx, (h x hx).of_dslope
lemma differentiable_within_at_dslope_of_ne (h : b ≠ a) :
differentiable_within_at 𝕜 (dslope f a) s b ↔ differentiable_within_at 𝕜 f s b :=
begin
refine ⟨differentiable_within_at.of_dslope, λ hd, _⟩,
refine (((differentiable_within_at_id.sub_const a).inv
(sub_ne_zero.2 h)).smul (hd.sub_const (f a))).congr_of_eventually_eq _ (dslope_of_ne _ h),
refine (eq_on_dslope_slope _ _).eventually_eq_of_mem _,
exact mem_nhds_within_of_mem_nhds (is_open_ne.mem_nhds h)
end
lemma differentiable_on_dslope_of_nmem (h : a ∉ s) :
differentiable_on 𝕜 (dslope f a) s ↔ differentiable_on 𝕜 f s :=
forall_congr $ λ x, forall_congr $ λ hx, differentiable_within_at_dslope_of_ne $
ne_of_mem_of_not_mem hx h
lemma differentiable_at_dslope_of_ne (h : b ≠ a) :
differentiable_at 𝕜 (dslope f a) b ↔ differentiable_at 𝕜 f b :=
by simp only [← differentiable_within_at_univ,
differentiable_within_at_dslope_of_ne h]
|
7c5a522f9189debef9a727f782239eed9f895f57 | ac49064e8a9a038e07cf5574b4fccd8a70d115c8 | /hott/algebra/homomorphism.hlean | 3cfa8c31b0830fbd91e92c135ecdc48e0b68b3d8 | [
"Apache-2.0"
] | permissive | Bolt64/lean2 | 7c75016729569e04a3f403c7a4fc7c1de4377c9d | 75fd8162488214a959dbe3303a185cbbb83f60f9 | refs/heads/master | 1,611,290,445,156 | 1,493,763,922,000 | 1,493,763,922,000 | 81,566,307 | 0 | 0 | null | 1,486,732,167,000 | 1,486,732,167,000 | null | UTF-8 | Lean | false | false | 6,175 | hlean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Homomorphisms between structures.
-/
import algebra.ring algebra.category.category
open eq function is_trunc
namespace algebra
/- additive structures -/
variables {A B C : Type}
definition is_add_hom [class] [has_add A] [has_add B] (f : A → B) : Type :=
∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂
definition respect_add [has_add A] [has_add B] (f : A → B) [H : is_add_hom f] (a₁ a₂ : A) :
f (a₁ + a₂) = f a₁ + f a₂ := H a₁ a₂
definition is_prop_is_add_hom [instance] [has_add A] [has_add B] [is_set B] (f : A → B) :
is_prop (is_add_hom f) :=
by unfold is_add_hom; apply _
definition is_add_hom_id (A : Type) [has_add A] : is_add_hom (@id A) :=
take a₁ a₂, rfl
definition is_add_hom_compose [has_add A] [has_add B] [has_add C]
(f : B → C) (g : A → B) [is_add_hom f] [is_add_hom g] : is_add_hom (f ∘ g) :=
take a₁ a₂, begin esimp, rewrite [respect_add g, respect_add f] end
section add_group_A_B
variables [add_group A] [add_group B]
definition respect_zero (f : A → B) [is_add_hom f] :
f (0 : A) = 0 :=
have f 0 + f 0 = f 0 + 0, by rewrite [-respect_add f, +add_zero],
eq_of_add_eq_add_left this
definition respect_neg (f : A → B) [is_add_hom f] (a : A) :
f (- a) = - f a :=
have f (- a) + f a = 0, by rewrite [-respect_add f, add.left_inv, respect_zero f],
eq_neg_of_add_eq_zero this
definition respect_sub (f : A → B) [is_add_hom f] (a₁ a₂ : A) :
f (a₁ - a₂) = f a₁ - f a₂ :=
by rewrite [*sub_eq_add_neg, *(respect_add f), (respect_neg f)]
definition is_embedding_of_is_add_hom [add_group B] (f : A → B) [is_add_hom f]
(H : ∀ x, f x = 0 → x = 0) :
is_embedding f :=
is_embedding_of_is_injective
(take x₁ x₂,
suppose f x₁ = f x₂,
have f (x₁ - x₂) = 0, by rewrite [respect_sub f, this, sub_self],
have x₁ - x₂ = 0, from H _ this,
eq_of_sub_eq_zero this)
definition eq_zero_of_is_add_hom [add_group B] {f : A → B} [is_add_hom f]
[is_embedding f] {a : A} (fa0 : f a = 0) :
a = 0 :=
have f a = f 0, by rewrite [fa0, respect_zero f],
show a = 0, from is_injective_of_is_embedding this
end add_group_A_B
/- multiplicative structures -/
definition is_mul_hom [class] [has_mul A] [has_mul B] (f : A → B) : Type :=
∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂
definition respect_mul [has_mul A] [has_mul B] (f : A → B) [H : is_mul_hom f] (a₁ a₂ : A) :
f (a₁ * a₂) = f a₁ * f a₂ := H a₁ a₂
definition is_prop_is_mul_hom [instance] [has_mul A] [has_mul B] [is_set B] (f : A → B) :
is_prop (is_mul_hom f) :=
begin unfold is_mul_hom, apply _ end
definition is_mul_hom_id (A : Type) [has_mul A] : is_mul_hom (@id A) :=
take a₁ a₂, rfl
definition is_mul_hom_compose [has_mul A] [has_mul B] [has_mul C]
(f : B → C) (g : A → B) [is_mul_hom f] [is_mul_hom g] : is_mul_hom (f ∘ g) :=
take a₁ a₂, begin esimp, rewrite [respect_mul g, respect_mul f] end
section group_A_B
variables [group A] [group B]
definition respect_one (f : A → B) [is_mul_hom f] :
f (1 : A) = 1 :=
have f 1 * f 1 = f 1 * 1, by rewrite [-respect_mul f, *mul_one],
eq_of_mul_eq_mul_left' this
definition respect_inv (f : A → B) [is_mul_hom f] (a : A) :
f (a⁻¹) = (f a)⁻¹ :=
have f (a⁻¹) * f a = 1, by rewrite [-respect_mul f, mul.left_inv, respect_one f],
eq_inv_of_mul_eq_one this
definition is_embedding_of_is_mul_hom [group B] (f : A → B) [is_mul_hom f]
(H : ∀ x, f x = 1 → x = 1) :
is_embedding f :=
is_embedding_of_is_injective
(take x₁ x₂,
suppose f x₁ = f x₂,
have f (x₁ * x₂⁻¹) = 1, by rewrite [respect_mul f, respect_inv f, this, mul.right_inv],
have x₁ * x₂⁻¹ = 1, from H _ this,
eq_of_mul_inv_eq_one this)
definition eq_one_of_is_mul_hom [add_group B] {f : A → B} [is_mul_hom f]
[is_embedding f] {a : A} (fa1 : f a = 1) :
a = 1 :=
have f a = f 1, by rewrite [fa1, respect_one f],
show a = 1, from is_injective_of_is_embedding this
end group_A_B
/- rings -/
definition is_ring_hom [class] {R₁ R₂ : Type} [semiring R₁] [semiring R₂] (f : R₁ → R₂) :=
is_add_hom f × is_mul_hom f × f 1 = 1
definition is_ring_hom.mk {R₁ R₂ : Type} [semiring R₁] [semiring R₂] (f : R₁ → R₂)
(h₁ : is_add_hom f) (h₂ : is_mul_hom f) (h₃ : f 1 = 1) : is_ring_hom f :=
pair h₁ (pair h₂ h₃)
definition is_add_hom_of_is_ring_hom [instance] {R₁ R₂ : Type} [semiring R₁] [semiring R₂]
(f : R₁ → R₂) [H : is_ring_hom f] : is_add_hom f :=
prod.pr1 H
definition is_mul_hom_of_is_ring_hom [instance] {R₁ R₂ : Type} [semiring R₁] [semiring R₂]
(f : R₁ → R₂) [H : is_ring_hom f] : is_mul_hom f :=
prod.pr1 (prod.pr2 H)
definition is_ring_hom.respect_one {R₁ R₂ : Type} [semiring R₁] [semiring R₂]
(f : R₁ → R₂) [H : is_ring_hom f] : f 1 = 1 :=
prod.pr2 (prod.pr2 H)
definition is_prop_is_ring_hom [instance] {R₁ R₂ : Type} [semiring R₁] [semiring R₂] (f : R₁ → R₂) :
is_prop (is_ring_hom f) :=
have h₁ : is_prop (is_add_hom f), from _,
have h₂ : is_prop (is_mul_hom f), from _,
have h₃ : is_prop (f 1 = 1), from _,
begin unfold is_ring_hom, apply _ end
section semiring
variables {R₁ R₂ R₃ : Type} [semiring R₁] [semiring R₂] [semiring R₃]
variables (g : R₂ → R₃) (f : R₁ → R₂) [is_ring_hom g] [is_ring_hom f]
definition is_ring_hom_id : is_ring_hom (@id R₁) :=
is_ring_hom.mk id (λ a₁ a₂, rfl) (λ a₁ a₂, rfl) rfl
definition is_ring_hom_comp : is_ring_hom (g ∘ f) :=
is_ring_hom.mk _
(take a₁ a₂, begin esimp, rewrite [respect_add f, respect_add g] end)
(take r a, by esimp; rewrite [respect_mul f, respect_mul g])
(by esimp; rewrite *is_ring_hom.respect_one)
definition respect_mul_add_mul (a b c d : R₁) : f (a * b + c * d) = f a * f b + f c * f d :=
by rewrite [respect_add f, +(respect_mul f)]
end semiring
end algebra
|
48b8c88b077b3305d8748e83a1756b98fd464c1a | c777c32c8e484e195053731103c5e52af26a25d1 | /src/ring_theory/localization/norm.lean | 5eba4dbb697eaaada658a93e5a563e76f0726172 | [
"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 | 2,055 | lean | /-
Copyright (c) 2023 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import ring_theory.localization.module
import ring_theory.norm
/-!
# Field/algebra norm and localization
This file contains results on the combination of `algebra.norm` and `is_localization`.
## Main results
* `algebra.norm_localization`: let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M`
of `R S` respectively. Then the norm of `a : Sₘ` over `Rₘ` is the norm of `a : S` over `R`
if `S` is free as `R`-module
## Tags
field norm, algebra norm, localization
-/
open_locale non_zero_divisors
variables (R : Type*) {S : Type*} [comm_ring R] [comm_ring S] [algebra R S]
variables {Rₘ Sₘ : Type*} [comm_ring Rₘ] [algebra R Rₘ] [comm_ring Sₘ] [algebra S Sₘ]
variables (M : submonoid R)
variables [is_localization M Rₘ] [is_localization (algebra.algebra_map_submonoid S M) Sₘ]
variables [algebra Rₘ Sₘ] [algebra R Sₘ] [is_scalar_tower R Rₘ Sₘ] [is_scalar_tower R S Sₘ]
include M
/-- Let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively.
Then the norm of `a : Sₘ` over `Rₘ` is the norm of `a : S` over `R` if `S` is free as `R`-module.
-/
lemma algebra.norm_localization [module.free R S] [module.finite R S] (a : S) :
algebra.norm Rₘ (algebra_map S Sₘ a) = algebra_map R Rₘ (algebra.norm R a) :=
begin
casesI subsingleton_or_nontrivial R,
{ haveI : subsingleton Rₘ := module.subsingleton R Rₘ,
simp },
let b := module.free.choose_basis R S,
letI := classical.dec_eq (module.free.choose_basis_index R S),
rw [algebra.norm_eq_matrix_det (b.localization_localization Rₘ M Sₘ),
algebra.norm_eq_matrix_det b, ring_hom.map_det],
congr,
ext i j,
simp only [matrix.map_apply, ring_hom.map_matrix_apply, algebra.left_mul_matrix_eq_repr_mul,
basis.localization_localization_apply, ← _root_.map_mul],
apply basis.localization_localization_repr_algebra_map
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.