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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cd9fa88f89125e5b62235d3a9ea20d3cd5a7de1c | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebra/big_operators/norm_num.lean | d1263794b6bf0e68605f2699947d94fa07dc1873 | [
"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 | 14,941 | lean | /-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import algebra.big_operators.basic
import tactic.norm_num
/-! ### `norm_num` plugin for big operators
This `norm_num` plugin provides support for computing sums and products of
lists, multisets and finsets.
Example goals this plugin can solve:
* `∑ i in finset.range 10, (i^2 : ℕ) = 285`
* `Π i in {1, 4, 9, 16}, nat.sqrt i = 24`
* `([1, 2, 1, 3]).sum = 7`
## Implementation notes
The tactic works by first converting the expression denoting the collection
(list, multiset, finset) to a list of expressions denoting each element. For
finsets, this involves erasing duplicate elements (the tactic fails if equality
or disequality cannot be determined).
After rewriting the big operator to a product/sum of lists, we evaluate this
using `norm_num` itself to handle multiplication/addition.
Finally, we package up the result using some congruence lemmas.
-/
open tactic
namespace tactic.norm_num
/-- Use `norm_num` to decide equality between two expressions.
If the decision procedure succeeds, the `bool` value indicates whether the expressions are equal,
and the `expr` is a proof of (dis)equality.
This procedure is partial: it will fail in cases where `norm_num` can't reduce either side
to a rational numeral.
-/
meta def decide_eq (l r : expr) : tactic (bool × expr) := do
(l', l'_pf) ← or_refl_conv norm_num.derive l,
(r', r'_pf) ← or_refl_conv norm_num.derive r,
n₁ ← l'.to_rat, n₂ ← r'.to_rat,
c ← infer_type l' >>= mk_instance_cache,
if n₁ = n₂ then do
pf ← i_to_expr ``(eq.trans %%l'_pf $ eq.symm %%r'_pf),
pure (tt, pf)
else do
(_, p) ← norm_num.prove_ne c l' r' n₁ n₂,
pure (ff, p)
lemma list.not_mem_cons {α : Type*} {x y : α} {ys : list α} (h₁ : x ≠ y) (h₂ : x ∉ ys) :
x ∉ y :: ys :=
λ h, ((list.mem_cons_iff _ _ _).mp h).elim h₁ h₂
/-- Use a decision procedure for the equality of list elements to decide list membership.
If the decision procedure succeeds, the `bool` value indicates whether the expressions are equal,
and the `expr` is a proof of (dis)equality.
This procedure is partial iff its parameter `decide_eq` is partial.
-/
meta def list.decide_mem (decide_eq : expr → expr → tactic (bool × expr)) :
expr → list expr → tactic (bool × expr)
| x [] := do
pf ← i_to_expr ``(list.not_mem_nil %%x),
pure (ff, pf)
| x (y :: ys) := do
(is_head, head_pf) ← decide_eq x y,
if is_head then do
pf ← i_to_expr ``((list.mem_cons_iff %%x %%y _).mpr (or.inl %%head_pf)),
pure (tt, pf)
else do
(mem_tail, tail_pf) ← list.decide_mem x ys,
if mem_tail then do
pf ← i_to_expr ``((list.mem_cons_iff %%x %%y _).mpr (or.inr %%tail_pf)),
pure (tt, pf)
else do
pf ← i_to_expr ``(list.not_mem_cons %%head_pf %%tail_pf),
pure (ff, pf)
lemma list.map_cons_congr {α β : Type*} (f : α → β) {x : α} {xs : list α} {fx : β} {fxs : list β}
(h₁ : f x = fx) (h₂ : xs.map f = fxs) : (x :: xs).map f = fx :: fxs :=
by rw [list.map_cons, h₁, h₂]
/-- Apply `ef : α → β` to all elements of the list, constructing an equality proof. -/
meta def eval_list_map (ef : expr) : list expr → tactic (list expr × expr)
| [] := do
eq ← i_to_expr ``(list.map_nil %%ef),
pure ([], eq)
| (x :: xs) := do
(fx, fx_eq) ← or_refl_conv norm_num.derive (expr.app ef x),
(fxs, fxs_eq) ← eval_list_map xs,
eq ← i_to_expr ``(list.map_cons_congr %%ef %%fx_eq %%fxs_eq),
pure (fx :: fxs, eq)
lemma list.cons_congr {α : Type*} (x : α) {xs : list α} {xs' : list α} (xs_eq : xs' = xs) :
x :: xs' = x :: xs :=
by rw xs_eq
lemma list.map_congr {α β : Type*} (f : α → β) {xs xs' : list α}
{ys : list β} (xs_eq : xs = xs') (ys_eq : xs'.map f = ys) :
xs.map f = ys :=
by rw [← ys_eq, xs_eq]
/-- Convert an expression denoting a list to a list of elements. -/
meta def eval_list : expr → tactic (list expr × expr)
| e@`(list.nil) := do
eq ← mk_eq_refl e,
pure ([], eq)
| e@`(list.cons %%x %%xs) := do
(xs, xs_eq) ← eval_list xs,
eq ← i_to_expr ``(list.cons_congr %%x %%xs_eq),
pure (x :: xs, eq)
| e@`(list.range %%en) := do
n ← expr.to_nat en,
eis ← (list.range n).mmap (λ i, expr.of_nat `(ℕ) i),
eq ← mk_eq_refl e,
pure (eis, eq)
| `(@list.map %%α %%β %%ef %%exs) := do
(xs, xs_eq) ← eval_list exs,
(ys, ys_eq) ← eval_list_map ef xs,
eq ← i_to_expr ``(list.map_congr %%ef %%xs_eq %%ys_eq),
pure (ys, eq)
| e@`(@list.fin_range %%en) := do
n ← expr.to_nat en,
eis ← (list.fin_range n).mmap (λ i, expr.of_nat `(fin %%en) i),
eq ← mk_eq_refl e,
pure (eis, eq)
| e := fail (to_fmt "Unknown list expression" ++ format.line ++ to_fmt e)
lemma multiset.cons_congr {α : Type*} (x : α) {xs : multiset α} {xs' : list α}
(xs_eq : (xs' : multiset α) = xs) : (list.cons x xs' : multiset α) = x ::ₘ xs :=
by rw [← xs_eq]; refl
lemma multiset.map_congr {α β : Type*} (f : α → β) {xs : multiset α}
{xs' : list α} {ys : list β} (xs_eq : xs = (xs' : multiset α)) (ys_eq : xs'.map f = ys) :
xs.map f = (ys : multiset β) :=
by rw [← ys_eq, ← multiset.coe_map, xs_eq]
/-- Convert an expression denoting a multiset to a list of elements.
We return a list rather than a finset, so we can more easily iterate over it
(without having to prove that our tactics are independent of the order of iteration,
which is in general not true).
-/
meta def eval_multiset : expr → tactic (list expr × expr)
| e@`(@has_zero.zero (multiset _) _) := do
eq ← mk_eq_refl e,
pure ([], eq)
| e@`(has_emptyc.emptyc) := do
eq ← mk_eq_refl e,
pure ([], eq)
| e@`(has_singleton.singleton %%x) := do
eq ← mk_eq_refl e,
pure ([x], eq)
| e@`(multiset.cons %%x %%xs) := do
(xs, xs_eq) ← eval_multiset xs,
eq ← i_to_expr ``(multiset.cons_congr %%x %%xs_eq),
pure (x :: xs, eq)
| e@`(@@has_insert.insert multiset.has_insert %%x %%xs) := do
(xs, xs_eq) ← eval_multiset xs,
eq ← i_to_expr ``(multiset.cons_congr %%x %%xs_eq),
pure (x :: xs, eq)
| e@`(multiset.range %%en) := do
n ← expr.to_nat en,
eis ← (list.range n).mmap (λ i, expr.of_nat `(ℕ) i),
eq ← mk_eq_refl e,
pure (eis, eq)
| `(@@coe (@@coe_to_lift (@@coe_base (multiset.has_coe))) %%exs) := do
(xs, xs_eq) ← eval_list exs,
eq ← i_to_expr ``(congr_arg coe %%xs_eq),
pure (xs, eq)
| `(@multiset.map %%α %%β %%ef %%exs) := do
(xs, xs_eq) ← eval_multiset exs,
(ys, ys_eq) ← eval_list_map ef xs,
eq ← i_to_expr ``(multiset.map_congr %%ef %%xs_eq %%ys_eq),
pure (ys, eq)
| e := fail (to_fmt "Unknown multiset expression" ++ format.line ++ to_fmt e)
lemma finset.mk_congr {α : Type*} {xs xs' : multiset α} (h : xs = xs') (nd nd') :
finset.mk xs nd = finset.mk xs' nd' :=
by congr; assumption
lemma finset.insert_eq_coe_list_of_mem {α : Type*} [decidable_eq α] (x : α) (xs : finset α)
{xs' : list α} (h : x ∈ xs') (nd_xs : xs'.nodup)
(hxs' : xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs)) :
insert x xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs) :=
have h : x ∈ xs, by simpa [hxs'] using h,
by rw [finset.insert_eq_of_mem h, hxs']
lemma finset.insert_eq_coe_list_cons {α : Type*} [decidable_eq α] (x : α) (xs : finset α)
{xs' : list α} (h : x ∉ xs') (nd_xs : xs'.nodup) (nd_xxs : (x :: xs').nodup)
(hxs' : xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs)) :
insert x xs = finset.mk ↑(x :: xs') (multiset.coe_nodup.mpr nd_xxs) :=
have h : x ∉ xs, by simpa [hxs'] using h,
by { rw [← finset.val_inj, finset.insert_val_of_not_mem h, hxs'], simp only [multiset.cons_coe] }
/-- Convert an expression denoting a finset to a list of elements,
a proof that this list is equal to the original finset,
and a proof that the list contains no duplicates.
We return a list rather than a finset, so we can more easily iterate over it
(without having to prove that our tactics are independent of the order of iteration,
which is in general not true).
`decide_eq` is a (partial) decision procedure for determining whether two
elements of the finset are equal, for example to parse `{2, 1, 2}` into `[2, 1]`.
-/
meta def eval_finset (decide_eq : expr → expr → tactic (bool × expr)) :
expr → tactic (list expr × expr × expr)
| e@`(finset.mk %%val %%nd) := do
(val', eq) ← eval_multiset val,
eq' ← i_to_expr ``(finset.mk_congr %%eq _ _),
pure (val', eq', nd)
| e@`(has_emptyc.emptyc) := do
eq ← mk_eq_refl e,
nd ← i_to_expr ``(list.nodup_nil),
pure ([], eq, nd)
| e@`(has_singleton.singleton %%x) := do
eq ← mk_eq_refl e,
nd ← i_to_expr ``(list.nodup_singleton %%x),
pure ([x], eq, nd)
| `(@@has_insert.insert (@@finset.has_insert %%dec) %%x %%xs) := do
(exs, xs_eq, xs_nd) ← eval_finset xs,
(is_mem, mem_pf) ← list.decide_mem decide_eq x exs,
if is_mem then do
pf ← i_to_expr ``(finset.insert_eq_coe_list_of_mem %%x %%xs %%mem_pf %%xs_nd %%xs_eq),
pure (exs, pf, xs_nd)
else do
nd ← i_to_expr ``(list.nodup_cons.mpr ⟨%%mem_pf, %%xs_nd⟩),
pf ← i_to_expr ``(finset.insert_eq_coe_list_cons %%x %%xs %%mem_pf %%xs_nd %%nd %%xs_eq),
pure (x :: exs, pf, nd)
| `(@@finset.univ %%ft) := do
-- Convert the fintype instance expression `ft` to a list of its elements.
-- Unfold it to the `fintype.mk` constructor and a list of arguments.
`fintype.mk ← get_app_fn_const_whnf ft
| fail (to_fmt "Unknown fintype expression" ++ format.line ++ to_fmt ft),
[_, args, _] ← get_app_args_whnf ft | fail (to_fmt "Expected 3 arguments to `fintype.mk`"),
eval_finset args
| e@`(finset.range %%en) := do
n ← expr.to_nat en,
eis ← (list.range n).mmap (λ i, expr.of_nat `(ℕ) i),
eq ← mk_eq_refl e,
nd ← i_to_expr ``(list.nodup_range %%en),
pure (eis, eq, nd)
| e := fail (to_fmt "Unknown finset expression" ++ format.line ++ to_fmt e)
@[to_additive]
lemma list.prod_cons_congr {α : Type*} [monoid α] (xs : list α) (x y z : α)
(his : xs.prod = y) (hi : x * y = z) : (x :: xs).prod = z :=
by rw [list.prod_cons, his, hi]
/-- Evaluate `list.prod %%xs`,
producing the evaluated expression and an equality proof. -/
meta def list.prove_prod (α : expr) : list expr → tactic (expr × expr)
| [] := do
result ← expr.of_nat α 1,
proof ← i_to_expr ``(@list.prod_nil %%α _),
pure (result, proof)
| (x :: xs) := do
eval_xs ← list.prove_prod xs,
xxs ← i_to_expr ``(%%x * %%eval_xs.1),
eval_xxs ← or_refl_conv norm_num.derive xxs,
exs ← expr.of_list α xs,
proof ← i_to_expr
``(list.prod_cons_congr %%exs%%x %%eval_xs.1 %%eval_xxs.1 %%eval_xs.2 %%eval_xxs.2),
pure (eval_xxs.1, proof)
/-- Evaluate `list.sum %%xs`,
sumucing the evaluated expression and an equality proof. -/
meta def list.prove_sum (α : expr) : list expr → tactic (expr × expr)
| [] := do
result ← expr.of_nat α 0,
proof ← i_to_expr ``(@list.sum_nil %%α _),
pure (result, proof)
| (x :: xs) := do
eval_xs ← list.prove_sum xs,
xxs ← i_to_expr ``(%%x + %%eval_xs.1),
eval_xxs ← or_refl_conv norm_num.derive xxs,
exs ← expr.of_list α xs,
proof ← i_to_expr
``(list.sum_cons_congr %%exs%%x %%eval_xs.1 %%eval_xxs.1 %%eval_xs.2 %%eval_xxs.2),
pure (eval_xxs.1, proof)
@[to_additive] lemma list.prod_congr {α : Type*} [monoid α] {xs xs' : list α} {z : α}
(h₁ : xs = xs') (h₂ : xs'.prod = z) : xs.prod = z := by cc
@[to_additive] lemma multiset.prod_congr {α : Type*} [comm_monoid α]
{xs : multiset α} {xs' : list α} {z : α}
(h₁ : xs = (xs' : multiset α)) (h₂ : xs'.prod = z) : xs.prod = z :=
by rw [← h₂, ← multiset.coe_prod, h₁]
/-- Evaluate `(%%xs.map (%%ef : %%α → %%β)).prod`,
producing the evaluated expression and an equality proof. -/
meta def list.prove_prod_map (β ef : expr) (xs : list expr) : tactic (expr × expr) := do
(fxs, fxs_eq) ← eval_list_map ef xs,
(prod, prod_eq) ← list.prove_prod β fxs,
eq ← i_to_expr ``(list.prod_congr %%fxs_eq %%prod_eq),
pure (prod, eq)
/-- Evaluate `(%%xs.map (%%ef : %%α → %%β)).sum`,
producing the evaluated expression and an equality proof. -/
meta def list.prove_sum_map (β ef : expr) (xs : list expr) : tactic (expr × expr) := do
(fxs, fxs_eq) ← eval_list_map ef xs,
(sum, sum_eq) ← list.prove_sum β fxs,
eq ← i_to_expr ``(list.sum_congr %%fxs_eq %%sum_eq),
pure (sum, eq)
@[to_additive]
lemma finset.eval_prod_of_list {β α : Type*} [comm_monoid β]
(s : finset α) (f : α → β) {is : list α} (his : is.nodup)
(hs : finset.mk ↑is (multiset.coe_nodup.mpr his) = s)
{x : β} (hx : (is.map f).prod = x) :
s.prod f = x :=
by rw [← hs, finset.prod_mk, multiset.coe_map, multiset.coe_prod, hx]
/-- `norm_num` plugin for evaluating big operators:
* `list.prod`
* `list.sum`
* `multiset.prod`
* `multiset.sum`
* `finset.prod`
* `finset.sum`
-/
@[norm_num] meta def eval_big_operators : expr → tactic (expr × expr)
| `(@list.prod %%α %%inst1 %%inst2 %%exs) :=
tactic.trace_error "Internal error in `tactic.norm_num.eval_big_operators`:" $ do
(xs, list_eq) ← eval_list exs,
(result, sum_eq) ← list.prove_prod α xs,
pf ← i_to_expr ``(list.prod_congr %%list_eq %%sum_eq),
pure (result, pf)
| `(@list.sum %%α %%inst1 %%inst2 %%exs) :=
tactic.trace_error "Internal error in `tactic.norm_num.eval_big_operators`:" $ do
(xs, list_eq) ← eval_list exs,
(result, sum_eq) ← list.prove_sum α xs,
pf ← i_to_expr ``(list.sum_congr %%list_eq %%sum_eq),
pure (result, pf)
| `(@multiset.prod %%α %%inst %%exs) :=
tactic.trace_error "Internal error in `tactic.norm_num.eval_big_operators`:" $ do
(xs, list_eq) ← eval_multiset exs,
(result, sum_eq) ← list.prove_prod α xs,
pf ← i_to_expr ``(multiset.prod_congr %%list_eq %%sum_eq),
pure (result, pf)
| `(@multiset.sum %%α %%inst %%exs) :=
tactic.trace_error "Internal error in `tactic.norm_num.eval_big_operators`:" $ do
(xs, list_eq) ← eval_multiset exs,
(result, sum_eq) ← list.prove_sum α xs,
pf ← i_to_expr ``(multiset.sum_congr %%list_eq %%sum_eq),
pure (result, pf)
| `(@finset.prod %%β %%α %%inst %%es %%ef) :=
tactic.trace_error "Internal error in `tactic.norm_num.eval_big_operators`:" $ do
(xs, list_eq, nodup) ← eval_finset decide_eq es,
(result, sum_eq) ← list.prove_prod_map β ef xs,
pf ← i_to_expr ``(finset.eval_prod_of_list %%es %%ef %%nodup %%list_eq %%sum_eq),
pure (result, pf)
| `(@finset.sum %%β %%α %%inst %%es %%ef) :=
tactic.trace_error "Internal error in `tactic.norm_num.eval_big_operators`:" $ do
(xs, list_eq, nodup) ← eval_finset decide_eq es,
(result, sum_eq) ← list.prove_sum_map β ef xs,
pf ← i_to_expr ``(finset.eval_sum_of_list %%es %%ef %%nodup %%list_eq %%sum_eq),
pure (result, pf)
| _ := failed
end tactic.norm_num
|
60dbfc8c7637db145f2665802ad22071da9566b8 | df7bb3acd9623e489e95e85d0bc55590ab0bc393 | /lean/love06_monads_homework_sheet.lean | 85fa673dbc3db6f48605cc33cc462a2192903474 | [] | no_license | MaschavanderMarel/logical_verification_2020 | a41c210b9237c56cb35f6cd399e3ac2fe42e775d | 7d562ef174cc6578ca6013f74db336480470b708 | refs/heads/master | 1,692,144,223,196 | 1,634,661,675,000 | 1,634,661,675,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,071 | lean | import .love06_monads_demo
/- # LoVe Homework 6: Monads
Homework must be done individually. -/
set_option pp.beta true
set_option pp.generalized_field_notation false
namespace LoVe
/- ## Question 1 (6 points): Better Exceptions
The __error monad__ is a monad stores either a value of type `α` or an error of
type `ε`. This corresponds to the following type: -/
inductive error (ε α : Type) : Type
| good {} : α → error
| bad {} : ε → error
/- The error monad generalizes the option monad seen in the lecture. The `good`
constructor, corresponding to `option.some`, stores the current result of the
computation. But instead of having a single bad state `option.none`, the error
monad has many bad states of the form `bad e`, where `e` is an "exception" of
type `ε`.
1.1 (1 point). Implement a variant of `list.nth` that returns an error
message of the form "index _i_ out of range" instead of `option.none` on
failure.
Hint: For this, you will only need pattern matching (no monadic code). -/
#check list.nth
def list.nth_error {α : Type} (as : list α) (i : ℕ) : error string α :=
sorry
/- 1.2 (1 point). Complete the definitions of the `pure` and `bind` operations
on the error monad: -/
def error.pure {ε α : Type} : α → error ε α :=
sorry
def error.bind {ε α β : Type} : error ε α → (α → error ε β) → error ε β :=
sorry
/- The following type class instance makes it possible to use `>>=` and `do`
notations in conjunction with error monads: -/
@[instance] def error.monad {ε : Type} : monad (error ε) :=
{ pure := @error.pure ε,
bind := @error.bind ε }
/- 1.3 (2 point). Prove the monad laws for the error monad. -/
lemma error.pure_bind {ε α β : Type} (a : α) (f : α → error ε β) :
(pure a >>= f) = f a :=
sorry
lemma error.bind_pure {ε α : Type} (ma : error ε α) :
(ma >>= pure) = ma :=
sorry
lemma error.bind_assoc {ε α β γ : Type} (f : α → error ε β) (g : β → error ε γ)
(ma : error ε α) :
((ma >>= f) >>= g) = (ma >>= (λa, f a >>= g)) :=
sorry
/- 1.4 (1 point). Define the following two operations on the error monad.
The `throw` operation raises an exception `e`, leaving the monad in a bad state
storing `e`.
The `catch` operation can be used to recover from an earlier exception. If the
monad is currently in a bad state storing `e`, `catch` invokes some
exception-handling code (the second argument to `catch`), passing `e` as
argument; this code might in turn raise a new exception. If `catch` is applied
to a good state, nothing happens—the monad remains in the good state. As a
convenient alternative to `error.catch ma g`, Lean lets us write
`ma.catch g`. -/
def error.throw {ε α : Type} : ε → error ε α :=
sorry
def error.catch {ε α : Type} : error ε α → (ε → error ε α) → error ε α :=
sorry
/- 1.5 (1 point). Using `list.nth_error` and the monadic operations on `error`,
and the special `error.catch` operation, write a monadic program that swaps the
values at indexes `i` and `j` in the input list `as`. If either of the indices
is out of range, return `as` unchanged. -/
def list.swap {α : Type} (as : list α) (i j : ℕ) : error string (list α) :=
sorry
#reduce list.swap [3, 1, 4, 1] 0 2 -- expected: error.good [4, 1, 3, 1]
#reduce list.swap [3, 1, 4, 1] 0 7 -- expected: error.good [3, 1, 4, 1]
/- ## Question 2 (3 points + 1 bonus point): Properties of `mmap`
We will prove some properties of the `mmap` function introduced in the
lecture's demo. -/
#check mmap
/- 2.1 (1 point). Prove the following identity law about `mmap` for an
arbitrary monad `m`.
Hint: You will need the lemma `lawful_monad.pure_bind` in the induction step. -/
lemma mmap_pure {m : Type → Type} [lawful_monad m] {α : Type} (as : list α) :
mmap (@pure m _ _) as = pure as :=
sorry
/- Commutative monads are monads for which we can reorder actions that do not
depend on each others. Formally: -/
@[class] structure comm_lawful_monad (m : Type → Type)
extends lawful_monad m : Type 1 :=
(bind_comm {α β γ δ : Type} (ma : m α) (f : α → m β) (g : α → m γ)
(h : α → β → γ → m δ) :
(ma >>= (λa, f a >>= (λb, g a >>= (λc, h a b c)))) =
(ma >>= (λa, g a >>= (λc, f a >>= (λb, h a b c)))))
/- 2.2 (1 point). Prove that `option` is a commutative monad. -/
lemma option.bind_comm {α β γ δ : Type} (ma : option α) (f : α → option β)
(g : α → option γ) (h : α → β → γ → option δ) :
(ma >>= λa, f a >>= λb, g a >>= λc, h a b c) =
(ma >>= λa, g a >>= λc, f a >>= λb, h a b c) :=
sorry
/- 2.3 (1 point). Explain why `error` is not a commutative monad. -/
-- enter your answer here
/- 2.4 (1 bonus point). Prove the following composition law for `mmap`, which
holds for commutative monads.
Hint: You will need structural induction. -/
lemma mmap_mmap {m : Type → Type} [comm_lawful_monad m]
{α β γ : Type} (f : α → m β) (g : β → m γ) (as : list α) :
(mmap f as >>= mmap g) = mmap (λa, f a >>= g) as :=
sorry
end LoVe
|
1d2efd9cba4f6bfd2e1020e994dd7810e35e4920 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/fiber_bundle/basic.lean | e855d01461f1940c57842e5ed0dfb764bb90bdb4 | [
"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 | 44,895 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris van Doorn, Heather Macbeth
-/
import topology.fiber_bundle.trivialization
/-!
# Fiber bundles
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Mathematically, a (topological) fiber bundle with fiber `F` over a base `B` is a space projecting on
`B` for which the fibers are all homeomorphic to `F`, such that the local situation around each
point is a direct product.
In our formalism, a fiber bundle is by definition the type
`bundle.total_space F E` where `E : B → Type*` is a function associating to `x : B` the fiber over
`x`. This type `bundle.total_space F E` is a type of pairs `(proj : B, snd : E proj)`.
To have a fiber bundle structure on `bundle.total_space F E`, one should
additionally have the following data:
* `F` should be a topological space;
* There should be a topology on `bundle.total_space F E`, for which the projection to `B` is
a fiber bundle with fiber `F` (in particular, each fiber `E x` is homeomorphic to `F`);
* For each `x`, the fiber `E x` should be a topological space, and the injection
from `E x` to `bundle.total_space F E` should be an embedding;
* There should be a distinguished set of bundle trivializations, the "trivialization atlas"
* There should be a choice of bundle trivialization at each point, which belongs to this atlas.
If all these conditions are satisfied, we register the typeclass `fiber_bundle F E`.
It is in general nontrivial to construct a fiber bundle. A way is to start from the knowledge of
how changes of local trivializations act on the fiber. From this, one can construct the total space
of the bundle and its topology by a suitable gluing construction. The main content of this file is
an implementation of this construction: starting from an object of type
`fiber_bundle_core` registering the trivialization changes, one gets the corresponding
fiber bundle and projection.
Similarly we implement the object `fiber_prebundle` which allows to define a topological
fiber bundle from trivializations given as local equivalences with minimum additional properties.
## Main definitions
### Basic definitions
* `fiber_bundle F E` : Structure saying that `E : B → Type*` is a fiber bundle with fiber `F`.
### Construction of a bundle from trivializations
* `bundle.total_space F E` is the type of pairs `(proj : B, snd : E proj)`. We can use the extra
argument `F` to construct topology on the total space.
* `fiber_bundle_core ι B F` : structure registering how changes of coordinates act
on the fiber `F` above open subsets of `B`, where local trivializations are indexed by `ι`.
Let `Z : fiber_bundle_core ι B F`. Then we define
* `Z.fiber x` : the fiber above `x`, homeomorphic to `F` (and defeq to `F` as a type).
* `Z.total_space` : the total space of `Z`, defined as a `Type*` as `bundle.total_space F Z.fiber`
with a custom topology.
* `Z.proj` : projection from `Z.total_space` to `B`. It is continuous.
* `Z.local_triv i`: for `i : ι`, bundle trivialization above the set `Z.base_set i`, which is an
open set in `B`.
* `fiber_prebundle F E` : structure registering a cover of prebundle trivializations
and requiring that the relative transition maps are local homeomorphisms.
* `fiber_prebundle.total_space_topology a` : natural topology of the total space, making
the prebundle into a bundle.
## Implementation notes
### Data vs mixins
For both fiber and vector bundles, one faces a choice: should the definition state the *existence*
of local trivializations (a propositional typeclass), or specify a fixed atlas of trivializations (a
typeclass containing data)?
In their initial mathlib implementations, both fiber and vector bundles were defined
propositionally. For vector bundles, this turns out to be mathematically wrong: in infinite
dimension, the transition function between two trivializations is not automatically continuous as a
map from the base `B` to the endomorphisms `F →L[R] F` of the fiber (considered with the
operator-norm topology), and so the definition needs to be modified by restricting consideration to
a family of trivializations (constituting the data) which are all mutually-compatible in this sense.
The PRs #13052 and #13175 implemented this change.
There is still the choice about whether to hold this data at the level of fiber bundles or of vector
bundles. As of PR #17505, the data is all held in `fiber_bundle`, with `vector_bundle` a
(propositional) mixin stating fiberwise-linearity.
This allows bundles to carry instances of typeclasses in which the scalar field, `R`, does not
appear as a parameter. Notably, we would like a vector bundle over `R` with fiber `F` over base `B`
to be a `charted_space (B × F)`, with the trivializations providing the charts. This would be a
dangerous instance for typeclass inference, because `R` does not appear as a parameter in
`charted_space (B × F)`. But if the data of the trivializations is held in `fiber_bundle`, then a
fiber bundle with fiber `F` over base `B` can be a `charted_space (B × F)`, and this is safe for
typeclass inference.
We expect that this choice of definition will also streamline constructions of fiber bundles with
similar underlying structure (e.g., the same bundle being both a real and complex vector bundle).
### Core construction
A fiber bundle with fiber `F` over a base `B` is a family of spaces isomorphic to `F`,
indexed by `B`, which is locally trivial in the following sense: there is a covering of `B` by open
sets such that, on each such open set `s`, the bundle is isomorphic to `s × F`.
To construct a fiber bundle formally, the main data is what happens when one changes trivializations
from `s × F` to `s' × F` on `s ∩ s'`: one should get a family of homeomorphisms of `F`, depending
continuously on the base point, satisfying basic compatibility conditions (cocycle property).
Useful classes of bundles can then be specified by requiring that these homeomorphisms of `F`
belong to some subgroup, preserving some structure (the "structure group of the bundle"): then
these structures are inherited by the fibers of the bundle.
Given such trivialization change data (encoded below in a structure called
`fiber_bundle_core`), one can construct the fiber bundle. The intrinsic canonical
mathematical construction is the following.
The fiber above `x` is the disjoint union of `F` over all trivializations, modulo the gluing
identifications: one gets a fiber which is isomorphic to `F`, but non-canonically
(each choice of one of the trivializations around `x` gives such an isomorphism). Given a
trivialization over a set `s`, one gets an isomorphism between `s × F` and `proj^{-1} s`, by using
the identification corresponding to this trivialization. One chooses the topology on the bundle that
makes all of these into homeomorphisms.
For the practical implementation, it turns out to be more convenient to avoid completely the
gluing and quotienting construction above, and to declare above each `x` that the fiber is `F`,
but thinking that it corresponds to the `F` coming from the choice of one trivialization around `x`.
This has several practical advantages:
* without any work, one gets a topological space structure on the fiber. And if `F` has more
structure it is inherited for free by the fiber.
* In the case of the tangent bundle of manifolds, this implies that on vector spaces the derivative
(from `F` to `F`) and the manifold derivative (from `tangent_space I x` to `tangent_space I' (f x)`)
are equal.
A drawback is that some silly constructions will typecheck: in the case of the tangent bundle, one
can add two vectors in different tangent spaces (as they both are elements of `F` from the point of
view of Lean). To solve this, one could mark the tangent space as irreducible, but then one would
lose the identification of the tangent space to `F` with `F`. There is however a big advantage of
this situation: even if Lean can not check that two basepoints are defeq, it will accept the fact
that the tangent spaces are the same. For instance, if two maps `f` and `g` are locally inverse to
each other, one can express that the composition of their derivatives is the identity of
`tangent_space I x`. One could fear issues as this composition goes from `tangent_space I x` to
`tangent_space I (g (f x))` (which should be the same, but should not be obvious to Lean
as it does not know that `g (f x) = x`). As these types are the same to Lean (equal to `F`), there
are in fact no dependent type difficulties here!
For this construction of a fiber bundle from a `fiber_bundle_core`, we should thus
choose for each `x` one specific trivialization around it. We include this choice in the definition
of the `fiber_bundle_core`, as it makes some constructions more
functorial and it is a nice way to say that the trivializations cover the whole space `B`.
With this definition, the type of the fiber bundle space constructed from the core data is
`bundle.total_space F (λ b : B, F)`, but the topology is not the product one, in general.
We also take the indexing type (indexing all the trivializations) as a parameter to the fiber bundle
core: it could always be taken as a subtype of all the maps from open subsets of `B` to continuous
maps of `F`, but in practice it will sometimes be something else. For instance, on a manifold, one
will use the set of charts as a good parameterization for the trivializations of the tangent bundle.
Or for the pullback of a `fiber_bundle_core`, the indexing type will be the same as
for the initial bundle.
## Tags
Fiber bundle, topological bundle, structure group
-/
variables {ι B F X : Type*} [topological_space X]
open topological_space filter set bundle
open_locale topology classical bundle
attribute [mfld_simps] total_space.coe_proj total_space.coe_snd coe_snd_map_apply
coe_snd_map_smul total_space.mk_cast
/-! ### General definition of fiber bundles -/
section fiber_bundle
variables (F) [topological_space B] [topological_space F] (E : B → Type*)
[topological_space (total_space F E)] [∀ b, topological_space (E b)]
/-- A (topological) fiber bundle with fiber `F` over a base `B` is a space projecting on `B`
for which the fibers are all homeomorphic to `F`, such that the local situation around each point
is a direct product. -/
class fiber_bundle :=
(total_space_mk_inducing [] : ∀ (b : B), inducing (@total_space.mk B F E b))
(trivialization_atlas [] : set (trivialization F (π F E)))
(trivialization_at [] : B → trivialization F (π F E))
(mem_base_set_trivialization_at [] : ∀ b : B, b ∈ (trivialization_at b).base_set)
(trivialization_mem_atlas [] : ∀ b : B, trivialization_at b ∈ trivialization_atlas)
export fiber_bundle
variables {F E}
/-- Given a type `E` equipped with a fiber bundle structure, this is a `Prop` typeclass
for trivializations of `E`, expressing that a trivialization is in the designated atlas for the
bundle. This is needed because lemmas about the linearity of trivializations or the continuity (as
functions to `F →L[R] F`, where `F` is the model fiber) of the transition functions are only
expected to hold for trivializations in the designated atlas. -/
@[mk_iff]
class mem_trivialization_atlas [fiber_bundle F E] (e : trivialization F (π F E)) : Prop :=
(out : e ∈ trivialization_atlas F E)
instance [fiber_bundle F E] (b : B) : mem_trivialization_atlas (trivialization_at F E b) :=
{ out := trivialization_mem_atlas F E b }
namespace fiber_bundle
variables (F) {E} [fiber_bundle F E]
lemma map_proj_nhds (x : total_space F E) :
map (π F E) (𝓝 x) = 𝓝 x.proj :=
(trivialization_at F E x.proj).map_proj_nhds $
(trivialization_at F E x.proj).mem_source.2 $ mem_base_set_trivialization_at F E x.proj
variables (E)
/-- The projection from a fiber bundle to its base is continuous. -/
@[continuity] lemma continuous_proj : continuous (π F E) :=
continuous_iff_continuous_at.2 $ λ x, (map_proj_nhds F x).le
/-- The projection from a fiber bundle to its base is an open map. -/
lemma is_open_map_proj : is_open_map (π F E) :=
is_open_map.of_nhds_le $ λ x, (map_proj_nhds F x).ge
/-- The projection from a fiber bundle with a nonempty fiber to its base is a surjective
map. -/
lemma surjective_proj [nonempty F] : function.surjective (π F E) :=
λ b, let ⟨p, _, hpb⟩ :=
(trivialization_at F E b).proj_surj_on_base_set (mem_base_set_trivialization_at F E b) in ⟨p, hpb⟩
/-- The projection from a fiber bundle with a nonempty fiber to its base is a quotient
map. -/
lemma quotient_map_proj [nonempty F] : quotient_map (π F E) :=
(is_open_map_proj F E).to_quotient_map (continuous_proj F E) (surjective_proj F E)
lemma continuous_total_space_mk (x : B) : continuous (@total_space.mk B F E x) :=
(total_space_mk_inducing F E x).continuous
variables {E F}
@[simp, mfld_simps]
lemma mem_trivialization_at_proj_source {x : total_space F E} :
x ∈ (trivialization_at F E x.proj).source :=
(trivialization.mem_source _).mpr $ mem_base_set_trivialization_at F E x.proj
@[simp, mfld_simps]
lemma trivialization_at_proj_fst {x : total_space F E} :
((trivialization_at F E x.proj) x).1 = x.proj :=
trivialization.coe_fst' _ $ mem_base_set_trivialization_at F E x.proj
variable (F)
open trivialization
/-- Characterization of continuous functions (at a point, within a set) into a fiber bundle. -/
lemma continuous_within_at_total_space (f : X → total_space F E) {s : set X} {x₀ : X} :
continuous_within_at f s x₀ ↔
continuous_within_at (λ x, (f x).proj) s x₀ ∧
continuous_within_at (λ x, ((trivialization_at F E (f x₀).proj) (f x)).2) s x₀ :=
begin
refine (and_iff_right_iff_imp.2 $ λ hf, _).symm.trans (and_congr_right $ λ hf, _),
{ refine (continuous_proj F E).continuous_within_at.comp hf (maps_to_image f s) },
have h1 : (λ x, (f x).proj) ⁻¹' (trivialization_at F E (f x₀).proj).base_set ∈ 𝓝[s] x₀ :=
hf.preimage_mem_nhds_within ((open_base_set _).mem_nhds (mem_base_set_trivialization_at F E _)),
have h2 : continuous_within_at (λ x, (trivialization_at F E (f x₀).proj (f x)).1) s x₀,
{ refine hf.congr_of_eventually_eq (eventually_of_mem h1 $ λ x hx, _) trivialization_at_proj_fst,
rw [coe_fst'],
exact hx },
rw [(trivialization_at F E (f x₀).proj).continuous_within_at_iff_continuous_within_at_comp_left],
{ simp_rw [continuous_within_at_prod_iff, function.comp, trivialization.coe_coe, h2, true_and] },
{ apply mem_trivialization_at_proj_source },
{ rwa [source_eq, preimage_preimage] }
end
/-- Characterization of continuous functions (at a point) into a fiber bundle. -/
lemma continuous_at_total_space (f : X → total_space F E) {x₀ : X} :
continuous_at f x₀ ↔ continuous_at (λ x, (f x).proj) x₀ ∧
continuous_at (λ x, ((trivialization_at F E (f x₀).proj) (f x)).2) x₀ :=
by { simp_rw [← continuous_within_at_univ], exact continuous_within_at_total_space F f }
end fiber_bundle
variables (F E)
/-- If `E` is a fiber bundle over a conditionally complete linear order,
then it is trivial over any closed interval. -/
lemma fiber_bundle.exists_trivialization_Icc_subset
[conditionally_complete_linear_order B] [order_topology B] [fiber_bundle F E] (a b : B) :
∃ e : trivialization F (π F E), Icc a b ⊆ e.base_set :=
begin
classical,
obtain ⟨ea, hea⟩ : ∃ ea : trivialization F (π F E), a ∈ ea.base_set :=
⟨trivialization_at F E a, mem_base_set_trivialization_at F E a⟩,
-- If `a < b`, then `[a, b] = ∅`, and the statement is trivial
cases le_or_lt a b with hab hab; [skip, exact ⟨ea, by simp *⟩],
/- Let `s` be the set of points `x ∈ [a, b]` such that `E` is trivializable over `[a, x]`.
We need to show that `b ∈ s`. Let `c = Sup s`. We will show that `c ∈ s` and `c = b`. -/
set s : set B := {x ∈ Icc a b | ∃ e : trivialization F (π F E), Icc a x ⊆ e.base_set},
have ha : a ∈ s, from ⟨left_mem_Icc.2 hab, ea, by simp [hea]⟩,
have sne : s.nonempty := ⟨a, ha⟩,
have hsb : b ∈ upper_bounds s, from λ x hx, hx.1.2,
have sbd : bdd_above s := ⟨b, hsb⟩,
set c := Sup s,
have hsc : is_lub s c, from is_lub_cSup sne sbd,
have hc : c ∈ Icc a b, from ⟨hsc.1 ha, hsc.2 hsb⟩,
obtain ⟨-, ec : trivialization F (π F E), hec : Icc a c ⊆ ec.base_set⟩ : c ∈ s,
{ cases hc.1.eq_or_lt with heq hlt, { rwa ← heq },
refine ⟨hc, _⟩,
/- In order to show that `c ∈ s`, consider a trivialization `ec` of `proj` over a neighborhood
of `c`. Its base set includes `(c', c]` for some `c' ∈ [a, c)`. -/
obtain ⟨ec, hc⟩ : ∃ ec : trivialization F (π F E), c ∈ ec.base_set :=
⟨trivialization_at F E c, mem_base_set_trivialization_at F E c⟩,
obtain ⟨c', hc', hc'e⟩ : ∃ c' ∈ Ico a c, Ioc c' c ⊆ ec.base_set :=
(mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset hlt).1
(mem_nhds_within_of_mem_nhds $ is_open.mem_nhds ec.open_base_set hc),
/- Since `c' < c = Sup s`, there exists `d ∈ s ∩ (c', c]`. Let `ead` be a trivialization of
`proj` over `[a, d]`. Then we can glue `ead` and `ec` into a trivialization over `[a, c]`. -/
obtain ⟨d, ⟨hdab, ead, had⟩, hd⟩ : ∃ d ∈ s, d ∈ Ioc c' c := hsc.exists_between hc'.2,
refine ⟨ead.piecewise_le ec d (had ⟨hdab.1, le_rfl⟩) (hc'e hd), subset_ite.2 _⟩,
refine ⟨λ x hx, had ⟨hx.1.1, hx.2⟩, λ x hx, hc'e ⟨hd.1.trans (not_le.1 hx.2), hx.1.2⟩⟩ },
/- So, `c ∈ s`. Let `ec` be a trivialization of `proj` over `[a, c]`. If `c = b`, then we are
done. Otherwise we show that `proj` can be trivialized over a larger interval `[a, d]`,
`d ∈ (c, b]`, hence `c` is not an upper bound of `s`. -/
cases hc.2.eq_or_lt with heq hlt, { exact ⟨ec, heq ▸ hec⟩ },
rsuffices ⟨d, hdcb, hd⟩ : ∃ (d ∈ Ioc c b) (e : trivialization F (π F E)), Icc a d ⊆ e.base_set,
{ exact ((hsc.1 ⟨⟨hc.1.trans hdcb.1.le, hdcb.2⟩, hd⟩).not_lt hdcb.1).elim },
/- Since the base set of `ec` is open, it includes `[c, d)` (hence, `[a, d)`) for some
`d ∈ (c, b]`. -/
obtain ⟨d, hdcb, hd⟩ : ∃ d ∈ Ioc c b, Ico c d ⊆ ec.base_set :=
(mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hlt).1
(mem_nhds_within_of_mem_nhds $ is_open.mem_nhds ec.open_base_set (hec ⟨hc.1, le_rfl⟩)),
have had : Ico a d ⊆ ec.base_set,
from Ico_subset_Icc_union_Ico.trans (union_subset hec hd),
by_cases he : disjoint (Iio d) (Ioi c),
{ /- If `(c, d) = ∅`, then let `ed` be a trivialization of `proj` over a neighborhood of `d`.
Then the disjoint union of `ec` restricted to `(-∞, d)` and `ed` restricted to `(c, ∞)` is
a trivialization over `[a, d]`. -/
obtain ⟨ed, hed⟩ : ∃ ed : trivialization F (π F E), d ∈ ed.base_set :=
⟨trivialization_at F E d, mem_base_set_trivialization_at F E d⟩,
refine ⟨d, hdcb, (ec.restr_open (Iio d) is_open_Iio).disjoint_union
(ed.restr_open (Ioi c) is_open_Ioi) (he.mono (inter_subset_right _ _)
(inter_subset_right _ _)), λ x hx, _⟩,
rcases hx.2.eq_or_lt with rfl|hxd,
exacts [or.inr ⟨hed, hdcb.1⟩, or.inl ⟨had ⟨hx.1, hxd⟩, hxd⟩] },
{ /- If `(c, d)` is nonempty, then take `d' ∈ (c, d)`. Since the base set of `ec` includes
`[a, d)`, it includes `[a, d'] ⊆ [a, d)` as well. -/
rw [disjoint_left] at he, push_neg at he, rcases he with ⟨d', hdd' : d' < d, hd'c⟩,
exact ⟨d', ⟨hd'c, hdd'.le.trans hdcb.2⟩, ec, (Icc_subset_Ico_right hdd').trans had⟩ }
end
end fiber_bundle
/-! ### Core construction for constructing fiber bundles -/
/-- Core data defining a locally trivial bundle with fiber `F` over a topological
space `B`. Note that "bundle" is used in its mathematical sense. This is the (computer science)
bundled version, i.e., all the relevant data is contained in the following structure. A family of
local trivializations is indexed by a type `ι`, on open subsets `base_set i` for each `i : ι`.
Trivialization changes from `i` to `j` are given by continuous maps `coord_change i j` from
`base_set i ∩ base_set j` to the set of homeomorphisms of `F`, but we express them as maps
`B → F → F` and require continuity on `(base_set i ∩ base_set j) × F` to avoid the topology on the
space of continuous maps on `F`. -/
@[nolint has_nonempty_instance]
structure fiber_bundle_core (ι : Type*) (B : Type*) [topological_space B]
(F : Type*) [topological_space F] :=
(base_set : ι → set B)
(is_open_base_set : ∀ i, is_open (base_set i))
(index_at : B → ι)
(mem_base_set_at : ∀ x, x ∈ base_set (index_at x))
(coord_change : ι → ι → B → F → F)
(coord_change_self : ∀ i, ∀ x ∈ base_set i, ∀ v, coord_change i i x v = v)
(continuous_on_coord_change : ∀ i j, continuous_on (λp : B × F, coord_change i j p.1 p.2)
(((base_set i) ∩ (base_set j)) ×ˢ univ))
(coord_change_comp : ∀ i j k, ∀ x ∈ (base_set i) ∩ (base_set j) ∩ (base_set k), ∀ v,
(coord_change j k x) (coord_change i j x v) = coord_change i k x v)
namespace fiber_bundle_core
variables [topological_space B] [topological_space F] (Z : fiber_bundle_core ι B F)
include Z
/-- The index set of a fiber bundle core, as a convenience function for dot notation -/
@[nolint unused_arguments has_nonempty_instance]
def index := ι
/-- The base space of a fiber bundle core, as a convenience function for dot notation -/
@[nolint unused_arguments, reducible]
def base := B
/-- The fiber of a fiber bundle core, as a convenience function for dot notation and
typeclass inference -/
@[nolint unused_arguments has_nonempty_instance]
def fiber (x : B) := F
instance topological_space_fiber (x : B) : topological_space (Z.fiber x) :=
‹topological_space F›
/-- The total space of the fiber bundle, as a convenience function for dot notation.
It is by definition equal to `bundle.total_space Z.fiber` -/
@[nolint unused_arguments, reducible]
def total_space := bundle.total_space F Z.fiber
/-- The projection from the total space of a fiber bundle core, on its base. -/
@[reducible, simp, mfld_simps] def proj : Z.total_space → B := bundle.total_space.proj
/-- Local homeomorphism version of the trivialization change. -/
def triv_change (i j : ι) : local_homeomorph (B × F) (B × F) :=
{ source := (Z.base_set i ∩ Z.base_set j) ×ˢ univ,
target := (Z.base_set i ∩ Z.base_set j) ×ˢ univ,
to_fun := λp, ⟨p.1, Z.coord_change i j p.1 p.2⟩,
inv_fun := λp, ⟨p.1, Z.coord_change j i p.1 p.2⟩,
map_source' := λp hp, by simpa using hp,
map_target' := λp hp, by simpa using hp,
left_inv' := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, mem_inter_iff, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx.1 },
{ simp [hx] }
end,
right_inv' := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, mem_inter_iff, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx.2 },
{ simp [hx] },
end,
open_source :=
(is_open.inter (Z.is_open_base_set i) (Z.is_open_base_set j)).prod is_open_univ,
open_target :=
(is_open.inter (Z.is_open_base_set i) (Z.is_open_base_set j)).prod is_open_univ,
continuous_to_fun :=
continuous_on.prod continuous_fst.continuous_on (Z.continuous_on_coord_change i j),
continuous_inv_fun := by simpa [inter_comm]
using continuous_on.prod continuous_fst.continuous_on (Z.continuous_on_coord_change j i) }
@[simp, mfld_simps] lemma mem_triv_change_source (i j : ι) (p : B × F) :
p ∈ (Z.triv_change i j).source ↔ p.1 ∈ Z.base_set i ∩ Z.base_set j :=
by { erw [mem_prod], simp }
/-- Associate to a trivialization index `i : ι` the corresponding trivialization, i.e., a bijection
between `proj ⁻¹ (base_set i)` and `base_set i × F`. As the fiber above `x` is `F` but read in the
chart with index `index_at x`, the trivialization in the fiber above x is by definition the
coordinate change from i to `index_at x`, so it depends on `x`.
The local trivialization will ultimately be a local homeomorphism. For now, we only introduce the
local equiv version, denoted with a prime. In further developments, avoid this auxiliary version,
and use `Z.local_triv` instead.
-/
def local_triv_as_local_equiv (i : ι) : local_equiv Z.total_space (B × F) :=
{ source := Z.proj ⁻¹' (Z.base_set i),
target := Z.base_set i ×ˢ univ,
inv_fun := λp, ⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩,
to_fun := λp, ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩,
map_source' := λp hp,
by simpa only [set.mem_preimage, and_true, set.mem_univ, set.prod_mk_mem_set_prod_eq] using hp,
map_target' := λp hp,
by simpa only [set.mem_preimage, and_true, set.mem_univ, set.mem_prod] using hp,
left_inv' := begin
rintros ⟨x, v⟩ hx,
change x ∈ Z.base_set i at hx,
dsimp only,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact Z.mem_base_set_at _ },
{ simp only [hx, mem_inter_iff, and_self, mem_base_set_at] }
end,
right_inv' := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx },
{ simp only [hx, mem_inter_iff, and_self, mem_base_set_at] }
end }
variable (i : ι)
lemma mem_local_triv_as_local_equiv_source (p : Z.total_space) :
p ∈ (Z.local_triv_as_local_equiv i).source ↔ p.1 ∈ Z.base_set i :=
iff.rfl
lemma mem_local_triv_as_local_equiv_target (p : B × F) :
p ∈ (Z.local_triv_as_local_equiv i).target ↔ p.1 ∈ Z.base_set i :=
by { erw [mem_prod], simp only [and_true, mem_univ] }
lemma local_triv_as_local_equiv_apply (p : Z.total_space) :
(Z.local_triv_as_local_equiv i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl
/-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/
lemma local_triv_as_local_equiv_trans (i j : ι) :
(Z.local_triv_as_local_equiv i).symm.trans
(Z.local_triv_as_local_equiv j) ≈ (Z.triv_change i j).to_local_equiv :=
begin
split,
{ ext x, simp only [mem_local_triv_as_local_equiv_target] with mfld_simps, refl, },
{ rintros ⟨x, v⟩ hx,
simp only [triv_change, local_triv_as_local_equiv, local_equiv.symm, true_and, prod.mk.inj_iff,
prod_mk_mem_set_prod_eq, local_equiv.trans_source, mem_inter_iff, and_true, mem_preimage,
proj, mem_univ, local_equiv.coe_mk, eq_self_iff_true, local_equiv.coe_trans,
total_space.proj] at hx ⊢,
simp only [Z.coord_change_comp, hx, mem_inter_iff, and_self, mem_base_set_at], }
end
/-- Topological structure on the total space of a fiber bundle created from core, designed so
that all the local trivialization are continuous. -/
instance to_topological_space : topological_space Z.total_space :=
topological_space.generate_from $ ⋃ (i : ι) (s : set (B × F)) (s_open : is_open s),
{(Z.local_triv_as_local_equiv i).source ∩ (Z.local_triv_as_local_equiv i) ⁻¹' s}
variables (b : B) (a : F)
lemma open_source' (i : ι) : is_open (Z.local_triv_as_local_equiv i).source :=
begin
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
refine ⟨i, Z.base_set i ×ˢ univ, (Z.is_open_base_set i).prod is_open_univ, _⟩,
ext p,
simp only [local_triv_as_local_equiv_apply, prod_mk_mem_set_prod_eq, mem_inter_iff, and_self,
mem_local_triv_as_local_equiv_source, and_true, mem_univ, mem_preimage],
end
/-- Extended version of the local trivialization of a fiber bundle constructed from core,
registering additionally in its type that it is a local bundle trivialization. -/
def local_triv (i : ι) : trivialization F Z.proj :=
{ base_set := Z.base_set i,
open_base_set := Z.is_open_base_set i,
source_eq := rfl,
target_eq := rfl,
proj_to_fun := λ p hp, by { simp only with mfld_simps, refl },
open_source := Z.open_source' i,
open_target := (Z.is_open_base_set i).prod is_open_univ,
continuous_to_fun := begin
rw continuous_on_open_iff (Z.open_source' i),
assume s s_open,
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
exact ⟨i, s, s_open, rfl⟩
end,
continuous_inv_fun := begin
apply continuous_on_open_of_generate_from ((Z.is_open_base_set i).prod is_open_univ),
assume t ht,
simp only [exists_prop, mem_Union, mem_singleton_iff] at ht,
obtain ⟨j, s, s_open, ts⟩ : ∃ j s, is_open s ∧ t =
(local_triv_as_local_equiv Z j).source ∩ (local_triv_as_local_equiv Z j) ⁻¹' s := ht,
rw ts,
simp only [local_equiv.right_inv, preimage_inter, local_equiv.left_inv],
let e := Z.local_triv_as_local_equiv i,
let e' := Z.local_triv_as_local_equiv j,
let f := e.symm.trans e',
have : is_open (f.source ∩ f ⁻¹' s),
{ rw [(Z.local_triv_as_local_equiv_trans i j).source_inter_preimage_eq],
exact (continuous_on_open_iff (Z.triv_change i j).open_source).1
((Z.triv_change i j).continuous_on) _ s_open },
convert this using 1,
dsimp [local_equiv.trans_source],
rw [← preimage_comp, inter_assoc],
refl,
end,
to_local_equiv := Z.local_triv_as_local_equiv i }
/-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as
a bundle trivialization -/
def local_triv_at (b : B) : trivialization F (π F Z.fiber) :=
Z.local_triv (Z.index_at b)
@[simp, mfld_simps] lemma local_triv_at_def (b : B) :
Z.local_triv (Z.index_at b) = Z.local_triv_at b := rfl
/-- If an element of `F` is invariant under all coordinate changes, then one can define a
corresponding section of the fiber bundle, which is continuous. This applies in particular to the
zero section of a vector bundle. Another example (not yet defined) would be the identity
section of the endomorphism bundle of a vector bundle. -/
lemma continuous_const_section (v : F)
(h : ∀ i j, ∀ x ∈ (Z.base_set i) ∩ (Z.base_set j), Z.coord_change i j x v = v) :
continuous (show B → Z.total_space, from λ x, ⟨x, v⟩) :=
begin
apply continuous_iff_continuous_at.2 (λ x, _),
have A : Z.base_set (Z.index_at x) ∈ 𝓝 x :=
is_open.mem_nhds (Z.is_open_base_set (Z.index_at x)) (Z.mem_base_set_at x),
apply ((Z.local_triv_at x).to_local_homeomorph.continuous_at_iff_continuous_at_comp_left _).2,
{ simp only [(∘)] with mfld_simps,
apply continuous_at_id.prod,
have : continuous_on (λ (y : B), v) (Z.base_set (Z.index_at x)) := continuous_on_const,
apply (this.congr _).continuous_at A,
assume y hy,
simp only [h, hy, mem_base_set_at] with mfld_simps },
{ exact A }
end
@[simp, mfld_simps] lemma local_triv_as_local_equiv_coe :
⇑(Z.local_triv_as_local_equiv i) = Z.local_triv i := rfl
@[simp, mfld_simps] lemma local_triv_as_local_equiv_source :
(Z.local_triv_as_local_equiv i).source = (Z.local_triv i).source := rfl
@[simp, mfld_simps] lemma local_triv_as_local_equiv_target :
(Z.local_triv_as_local_equiv i).target = (Z.local_triv i).target := rfl
@[simp, mfld_simps] lemma local_triv_as_local_equiv_symm :
(Z.local_triv_as_local_equiv i).symm = (Z.local_triv i).to_local_equiv.symm := rfl
@[simp, mfld_simps] lemma base_set_at : Z.base_set i = (Z.local_triv i).base_set := rfl
@[simp, mfld_simps] lemma local_triv_apply (p : Z.total_space) :
(Z.local_triv i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl
@[simp, mfld_simps] lemma local_triv_at_apply (p : Z.total_space) :
((Z.local_triv_at p.1) p) = ⟨p.1, p.2⟩ :=
by { rw [local_triv_at, local_triv_apply, coord_change_self], exact Z.mem_base_set_at p.1 }
@[simp, mfld_simps] lemma local_triv_at_apply_mk (b : B) (a : F) :
((Z.local_triv_at b) ⟨b, a⟩) = ⟨b, a⟩ :=
Z.local_triv_at_apply _
@[simp, mfld_simps] lemma mem_local_triv_source (p : Z.total_space) :
p ∈ (Z.local_triv i).source ↔ p.1 ∈ (Z.local_triv i).base_set := iff.rfl
@[simp, mfld_simps] lemma mem_local_triv_at_source (p : Z.total_space) (b : B) :
p ∈ (Z.local_triv_at b).source ↔ p.1 ∈ (Z.local_triv_at b).base_set := iff.rfl
@[simp, mfld_simps] lemma mem_source_at : (⟨b, a⟩ : Z.total_space) ∈ (Z.local_triv_at b).source :=
by { rw [local_triv_at, mem_local_triv_source], exact Z.mem_base_set_at b }
@[simp, mfld_simps] lemma mem_local_triv_target (p : B × F) :
p ∈ (Z.local_triv i).target ↔ p.1 ∈ (Z.local_triv i).base_set :=
trivialization.mem_target _
@[simp, mfld_simps] lemma mem_local_triv_at_target (p : B × F) (b : B) :
p ∈ (Z.local_triv_at b).target ↔ p.1 ∈ (Z.local_triv_at b).base_set :=
trivialization.mem_target _
@[simp, mfld_simps] lemma local_triv_symm_apply (p : B × F) :
(Z.local_triv i).to_local_homeomorph.symm p =
⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩ := rfl
@[simp, mfld_simps] lemma mem_local_triv_at_base_set (b : B) :
b ∈ (Z.local_triv_at b).base_set :=
by { rw [local_triv_at, ←base_set_at], exact Z.mem_base_set_at b, }
/-- The inclusion of a fiber into the total space is a continuous map. -/
@[continuity]
lemma continuous_total_space_mk (b : B) :
continuous (total_space.mk b : Z.fiber b → Z.total_space) :=
begin
rw [continuous_iff_le_induced, fiber_bundle_core.to_topological_space],
apply le_induced_generate_from,
simp only [mem_Union, mem_singleton_iff, local_triv_as_local_equiv_source,
local_triv_as_local_equiv_coe],
rintros s ⟨i, t, ht, rfl⟩,
rw [←((Z.local_triv i).source_inter_preimage_target_inter t), preimage_inter, ←preimage_comp,
trivialization.source_eq],
apply is_open.inter,
{ simp only [total_space.proj, proj, ←preimage_comp],
by_cases (b ∈ (Z.local_triv i).base_set),
{ rw preimage_const_of_mem h, exact is_open_univ, },
{ rw preimage_const_of_not_mem h, exact is_open_empty, }},
{ simp only [function.comp, local_triv_apply],
rw [preimage_inter, preimage_comp],
by_cases (b ∈ Z.base_set i),
{ have hc : continuous (λ (x : Z.fiber b), (Z.coord_change (Z.index_at b) i b) x),
from (Z.continuous_on_coord_change (Z.index_at b) i).comp_continuous
(continuous_const.prod_mk continuous_id) (λ x, ⟨⟨Z.mem_base_set_at b, h⟩, mem_univ x⟩),
exact (((Z.local_triv i).open_target.inter ht).preimage (continuous.prod.mk b)).preimage hc },
{ rw [(Z.local_triv i).target_eq, ←base_set_at, mk_preimage_prod_right_eq_empty h,
preimage_empty, empty_inter],
exact is_open_empty, }}
end
/-- A fiber bundle constructed from core is indeed a fiber bundle. -/
instance fiber_bundle : fiber_bundle F Z.fiber :=
{ total_space_mk_inducing := λ b, ⟨ begin refine le_antisymm _ (λ s h, _),
{ rw ←continuous_iff_le_induced,
exact continuous_total_space_mk Z b, },
{ refine is_open_induced_iff.mpr ⟨(Z.local_triv_at b).source ∩ (Z.local_triv_at b) ⁻¹'
((Z.local_triv_at b).base_set ×ˢ s), (continuous_on_open_iff
(Z.local_triv_at b).open_source).mp (Z.local_triv_at b).continuous_to_fun _
((Z.local_triv_at b).open_base_set.prod h), _⟩,
rw [preimage_inter, ←preimage_comp, function.comp],
refine ext_iff.mpr (λ a, ⟨λ ha, _, λ ha, ⟨Z.mem_base_set_at b, _⟩⟩),
{ simp only [mem_prod, mem_preimage, mem_inter_iff, local_triv_at_apply_mk] at ha,
exact ha.2.2, },
{ simp only [mem_prod, mem_preimage, mem_inter_iff, local_triv_at_apply_mk],
exact ⟨Z.mem_base_set_at b, ha⟩, } } end⟩,
trivialization_atlas := set.range Z.local_triv,
trivialization_at := Z.local_triv_at,
mem_base_set_trivialization_at := Z.mem_base_set_at,
trivialization_mem_atlas := λ b, ⟨Z.index_at b, rfl⟩ }
/-- The projection on the base of a fiber bundle created from core is continuous -/
lemma continuous_proj : continuous Z.proj := continuous_proj F Z.fiber
/-- The projection on the base of a fiber bundle created from core is an open map -/
lemma is_open_map_proj : is_open_map Z.proj := is_open_map_proj F Z.fiber
end fiber_bundle_core
/-! ### Prebundle construction for constructing fiber bundles -/
variables (F) (E : B → Type*) [topological_space B] [topological_space F]
[Π x, topological_space (E x)]
/-- This structure permits to define a fiber bundle when trivializations are given as local
equivalences but there is not yet a topology on the total space. The total space is hence given a
topology in such a way that there is a fiber bundle structure for which the local equivalences
are also local homeomorphism and hence local trivializations. -/
@[nolint has_nonempty_instance]
structure fiber_prebundle :=
(pretrivialization_atlas : set (pretrivialization F (π F E)))
(pretrivialization_at : B → pretrivialization F (π F E))
(mem_base_pretrivialization_at : ∀ x : B, x ∈ (pretrivialization_at x).base_set)
(pretrivialization_mem_atlas : ∀ x : B, pretrivialization_at x ∈ pretrivialization_atlas)
(continuous_triv_change : ∀ e e' ∈ pretrivialization_atlas,
continuous_on (e ∘ e'.to_local_equiv.symm) (e'.target ∩ (e'.to_local_equiv.symm ⁻¹' e.source)))
(total_space_mk_inducing : ∀ (b : B), inducing ((pretrivialization_at b) ∘ (total_space.mk b)))
namespace fiber_prebundle
variables {F E} (a : fiber_prebundle F E) {e : pretrivialization F (π F E)}
/-- Topology on the total space that will make the prebundle into a bundle. -/
def total_space_topology (a : fiber_prebundle F E) : topological_space (total_space F E) :=
⨆ (e : pretrivialization F (π F E)) (he : e ∈ a.pretrivialization_atlas),
coinduced e.set_symm (subtype.topological_space)
lemma continuous_symm_of_mem_pretrivialization_atlas (he : e ∈ a.pretrivialization_atlas) :
@continuous_on _ _ _ a.total_space_topology
e.to_local_equiv.symm e.target :=
begin
refine id (λ z H, id (λ U h, preimage_nhds_within_coinduced' H
e.open_target (le_def.1 (nhds_mono _) U h))),
exact le_supr₂ e he,
end
lemma is_open_source (e : pretrivialization F (π F E)) : is_open[a.total_space_topology] e.source :=
begin
letI := a.total_space_topology,
refine is_open_supr_iff.mpr (λ e', _),
refine is_open_supr_iff.mpr (λ he', _),
refine is_open_coinduced.mpr (is_open_induced_iff.mpr ⟨e.target, e.open_target, _⟩),
rw [pretrivialization.set_symm, restrict, e.target_eq,
e.source_eq, preimage_comp, subtype.preimage_coe_eq_preimage_coe_iff,
e'.target_eq, prod_inter_prod, inter_univ,
pretrivialization.preimage_symm_proj_inter],
end
lemma is_open_target_of_mem_pretrivialization_atlas_inter (e e' : pretrivialization F (π F E))
(he' : e' ∈ a.pretrivialization_atlas) :
is_open (e'.to_local_equiv.target ∩ e'.to_local_equiv.symm ⁻¹' e.source) :=
begin
letI := a.total_space_topology,
obtain ⟨u, hu1, hu2⟩ := continuous_on_iff'.mp (a.continuous_symm_of_mem_pretrivialization_atlas
he') e.source (a.is_open_source e),
rw [inter_comm, hu2],
exact hu1.inter e'.open_target,
end
/-- Promotion from a `pretrivialization` to a `trivialization`. -/
def trivialization_of_mem_pretrivialization_atlas (he : e ∈ a.pretrivialization_atlas) :
@trivialization B F _ _ _ a.total_space_topology (π F E) :=
{ open_source := a.is_open_source e,
continuous_to_fun := begin
letI := a.total_space_topology,
refine continuous_on_iff'.mpr (λ s hs, ⟨e ⁻¹' s ∩ e.source, (is_open_supr_iff.mpr (λ e', _)),
by { rw [inter_assoc, inter_self], refl }⟩),
refine (is_open_supr_iff.mpr (λ he', _)),
rw [is_open_coinduced, is_open_induced_iff],
obtain ⟨u, hu1, hu2⟩ := continuous_on_iff'.mp (a.continuous_triv_change _ he _ he') s hs,
have hu3 := congr_arg (λ s, (λ x : e'.target, (x : B × F)) ⁻¹' s) hu2,
simp only [subtype.coe_preimage_self, preimage_inter, univ_inter] at hu3,
refine ⟨u ∩ e'.to_local_equiv.target ∩
(e'.to_local_equiv.symm ⁻¹' e.source), _, by
{ simp only [preimage_inter, inter_univ, subtype.coe_preimage_self, hu3.symm], refl }⟩,
rw inter_assoc,
exact hu1.inter (a.is_open_target_of_mem_pretrivialization_atlas_inter e e' he'),
end,
continuous_inv_fun := a.continuous_symm_of_mem_pretrivialization_atlas he,
.. e }
lemma mem_trivialization_at_source (b : B) (x : E b) :
total_space.mk b x ∈ (a.pretrivialization_at b).source :=
begin
simp only [(a.pretrivialization_at b).source_eq, mem_preimage, total_space.proj],
exact a.mem_base_pretrivialization_at b,
end
@[simp] lemma total_space_mk_preimage_source (b : B) :
total_space.mk b ⁻¹' (a.pretrivialization_at b).source = univ :=
begin
apply eq_univ_of_univ_subset,
rw [(a.pretrivialization_at b).source_eq, ←preimage_comp, function.comp],
simp only [total_space.proj],
rw preimage_const_of_mem _,
exact a.mem_base_pretrivialization_at b,
end
@[continuity] lemma continuous_total_space_mk (b : B) :
@continuous _ _ _ a.total_space_topology (total_space.mk b) :=
begin
letI := a.total_space_topology,
let e := a.trivialization_of_mem_pretrivialization_atlas (a.pretrivialization_mem_atlas b),
rw e.to_local_homeomorph.continuous_iff_continuous_comp_left
(a.total_space_mk_preimage_source b),
exact continuous_iff_le_induced.mpr (le_antisymm_iff.mp (a.total_space_mk_inducing b).induced).1,
end
lemma inducing_total_space_mk_of_inducing_comp (b : B)
(h : inducing ((a.pretrivialization_at b) ∘ (total_space.mk b))) :
@inducing _ _ _ a.total_space_topology (total_space.mk b) :=
begin
letI := a.total_space_topology,
rw ←restrict_comp_cod_restrict (a.mem_trivialization_at_source b) at h,
apply inducing.of_cod_restrict (a.mem_trivialization_at_source b),
refine inducing_of_inducing_compose _ (continuous_on_iff_continuous_restrict.mp
(a.trivialization_of_mem_pretrivialization_atlas
(a.pretrivialization_mem_atlas b)).continuous_to_fun) h,
exact (a.continuous_total_space_mk b).cod_restrict (a.mem_trivialization_at_source b),
end
/-- Make a `fiber_bundle` from a `fiber_prebundle`. Concretely this means
that, given a `fiber_prebundle` structure for a sigma-type `E` -- which consists of a
number of "pretrivializations" identifying parts of `E` with product spaces `U × F` -- one
establishes that for the topology constructed on the sigma-type using
`fiber_prebundle.total_space_topology`, these "pretrivializations" are actually
"trivializations" (i.e., homeomorphisms with respect to the constructed topology). -/
def to_fiber_bundle :
@fiber_bundle B F _ _ E a.total_space_topology _ :=
{ total_space_mk_inducing := λ b, a.inducing_total_space_mk_of_inducing_comp b
(a.total_space_mk_inducing b),
trivialization_atlas := {e | ∃ e₀ (he₀ : e₀ ∈ a.pretrivialization_atlas),
e = a.trivialization_of_mem_pretrivialization_atlas he₀},
trivialization_at := λ x, a.trivialization_of_mem_pretrivialization_atlas
(a.pretrivialization_mem_atlas x),
mem_base_set_trivialization_at := a.mem_base_pretrivialization_at,
trivialization_mem_atlas := λ x, ⟨_, a.pretrivialization_mem_atlas x, rfl⟩ }
lemma continuous_proj : @continuous _ _ a.total_space_topology _ (π F E) :=
begin
letI := a.total_space_topology,
letI := a.to_fiber_bundle,
exact continuous_proj F E,
end
/-- For a fiber bundle `E` over `B` constructed using the `fiber_prebundle` mechanism,
continuity of a function `total_space F E → X` on an open set `s` can be checked by precomposing at
each point with the pretrivialization used for the construction at that point. -/
lemma continuous_on_of_comp_right {X : Type*} [topological_space X] {f : total_space F E → X}
{s : set B} (hs : is_open s)
(hf : ∀ b ∈ s, continuous_on (f ∘ (a.pretrivialization_at b).to_local_equiv.symm)
((s ∩ (a.pretrivialization_at b).base_set) ×ˢ (set.univ : set F))) :
@continuous_on _ _ a.total_space_topology _ f ((π F E) ⁻¹' s) :=
begin
letI := a.total_space_topology,
intros z hz,
let e : trivialization F (π F E) :=
a.trivialization_of_mem_pretrivialization_atlas (a.pretrivialization_mem_atlas z.proj),
refine (e.continuous_at_of_comp_right _
((hf z.proj hz).continuous_at (is_open.mem_nhds _ _))).continuous_within_at,
{ exact a.mem_base_pretrivialization_at z.proj },
{ exact ((hs.inter (a.pretrivialization_at z.proj).open_base_set).prod is_open_univ) },
refine ⟨_, mem_univ _⟩,
rw e.coe_fst,
{ exact ⟨hz, a.mem_base_pretrivialization_at z.proj⟩ },
{ rw e.mem_source,
exact a.mem_base_pretrivialization_at z.proj },
end
end fiber_prebundle
|
2b92b1fa47b3be52c6c17a1ec3789b9635365f25 | ee8cdbabf07f77e7be63a449b8483ce308d37218 | /lean/src/test/induction-nfactltnexpnm1ngt3.lean | 7b0a886e831ef4e68778ae53e2c0d53666eed043 | [
"MIT",
"Apache-2.0"
] | permissive | zeta1999/miniF2F | 6d66c75d1c18152e224d07d5eed57624f731d4b7 | c1ba9629559c5273c92ec226894baa0c1ce27861 | refs/heads/main | 1,681,897,460,642 | 1,620,646,361,000 | 1,620,646,361,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 283 | lean | /-
Copyright (c) 2021 OpenAI. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kunhao Zheng
-/
import data.nat.factorial
import data.real.basic
example (n : ℕ) (h₀ : 3 ≤ n) : nat.factorial n < n ^ (n - 1) :=
begin
sorry
end
|
6f75ea73ceb9527173d017b5d281c9611e48e740 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/geometry/manifold/instances/real.lean | 1e6df2db0d8211bbbd1f11cbbaf5227c54957bf9 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 13,718 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import linear_algebra.finite_dimensional
import geometry.manifold.smooth_manifold_with_corners
import analysis.inner_product_space.pi_L2
/-!
# Constructing examples of manifolds over ℝ
We introduce the necessary bits to be able to define manifolds modelled over `ℝ^n`, boundaryless
or with boundary or with corners. As a concrete example, we construct explicitly the manifold with
boundary structure on the real interval `[x, y]`.
More specifically, we introduce
* `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n)` for the model space
used to define `n`-dimensional real manifolds with boundary
* `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
## Notations
In the locale `manifold`, we introduce the notations
* `𝓡 n` for the identity model with corners on `euclidean_space ℝ (fin n)`
* `𝓡∂ n` for `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n)`.
For instance, if a manifold `M` is boundaryless, smooth and modelled on `euclidean_space ℝ (fin m)`,
and `N` is smooth with boundary modelled on `euclidean_half_space n`, and `f : M → N` is a smooth
map, then the derivative of `f` can be written simply as `mfderiv (𝓡 m) (𝓡∂ n) f` (as to why the
model with corners can not be implicit, see the discussion in `smooth_manifold_with_corners.lean`).
## Implementation notes
The manifold structure on the interval `[x, y] = Icc x y` requires the assumption `x < y` as a
typeclass. We provide it as `[fact (x < y)]`.
-/
noncomputable theory
open set function
open_locale manifold
/--
The half-space in `ℝ^n`, used to model manifolds with boundary. We only define it when
`1 ≤ n`, as the definition only makes sense in this case.
-/
def euclidean_half_space (n : ℕ) [has_zero (fin n)] : Type :=
{x : euclidean_space ℝ (fin n) // 0 ≤ x 0}
/--
The quadrant in `ℝ^n`, used to model manifolds with corners, made of all vectors with nonnegative
coordinates.
-/
def euclidean_quadrant (n : ℕ) : Type := {x : euclidean_space ℝ (fin n) // ∀i:fin n, 0 ≤ x i}
section
/- Register class instances for euclidean half-space and quadrant, that can not be noticed
without the following reducibility attribute (which is only set in this section). -/
local attribute [reducible] euclidean_half_space euclidean_quadrant
variable {n : ℕ}
instance [has_zero (fin n)] : topological_space (euclidean_half_space n) := by apply_instance
instance : topological_space (euclidean_quadrant n) := by apply_instance
instance [has_zero (fin n)] : inhabited (euclidean_half_space n) := ⟨⟨0, le_rfl⟩⟩
instance : inhabited (euclidean_quadrant n) := ⟨⟨0, λ i, le_rfl⟩⟩
lemma range_half_space (n : ℕ) [has_zero (fin n)] :
range (λx : euclidean_half_space n, x.val) = {y | 0 ≤ y 0} :=
by simp
lemma range_quadrant (n : ℕ) :
range (λx : euclidean_quadrant n, x.val) = {y | ∀i:fin n, 0 ≤ y i} :=
by simp
end
/--
Definition of the model with corners `(euclidean_space ℝ (fin n), euclidean_half_space n)`, used as
a model for manifolds with boundary. In the locale `manifold`, use the shortcut `𝓡∂ n`.
-/
def model_with_corners_euclidean_half_space (n : ℕ) [has_zero (fin n)] :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n) :=
{ to_fun := subtype.val,
inv_fun := λx, ⟨update x 0 (max (x 0) 0), by simp [le_refl]⟩,
source := univ,
target := {x | 0 ≤ x 0},
map_source' := λx hx, x.property,
map_target' := λx hx, mem_univ _,
left_inv' := λ ⟨xval, xprop⟩ hx, begin
rw [subtype.mk_eq_mk, update_eq_iff],
exact ⟨max_eq_left xprop, λ i _, rfl⟩
end,
right_inv' := λx hx, update_eq_iff.2 ⟨max_eq_left hx, λ i _, rfl⟩,
source_eq := rfl,
unique_diff' :=
have this : unique_diff_on ℝ _ :=
unique_diff_on.pi (fin n) (λ _, ℝ) _ _ (λ i ∈ ({0} : set (fin n)), unique_diff_on_Ici 0),
by simpa only [singleton_pi] using this,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ $ continuous_id.update 0 $
(continuous_apply 0).max continuous_const }
/--
Definition of the model with corners `(euclidean_space ℝ (fin n), euclidean_quadrant n)`, used as a
model for manifolds with corners -/
def model_with_corners_euclidean_quadrant (n : ℕ) :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_quadrant n) :=
{ to_fun := subtype.val,
inv_fun := λx, ⟨λi, max (x i) 0, λi, by simp only [le_refl, or_true, le_max_iff]⟩,
source := univ,
target := {x | ∀ i, 0 ≤ x i},
map_source' := λx hx, by simpa only [subtype.range_val] using x.property,
map_target' := λx hx, mem_univ _,
left_inv' := λ ⟨xval, xprop⟩ hx, by { ext i, simp only [subtype.coe_mk, xprop i, max_eq_left] },
right_inv' := λ x hx, by { ext1 i, simp only [hx i, max_eq_left] },
source_eq := rfl,
unique_diff' :=
have this : unique_diff_on ℝ _ :=
unique_diff_on.univ_pi (fin n) (λ _, ℝ) _ (λ i, unique_diff_on_Ici 0),
by simpa only [pi_univ_Ici] using this,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ $ continuous_pi $ λ i,
(continuous_id.max continuous_const).comp (continuous_apply i) }
localized "notation `𝓡 `n :=
(model_with_corners_self ℝ (euclidean_space ℝ (fin n)) :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_space ℝ (fin n)))" in manifold
localized "notation `𝓡∂ `n :=
(model_with_corners_euclidean_half_space n :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n))" in manifold
/--
The left chart for the topological space `[x, y]`, defined on `[x,y)` and sending `x` to `0` in
`euclidean_half_space 1`.
-/
def Icc_left_chart (x y : ℝ) [fact (x < y)] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | z.val < y},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, z.val - x, sub_nonneg.mpr z.property.1⟩,
inv_fun := λz, ⟨min (z.val 0 + x) y, by simp [le_refl, z.prop, le_of_lt (fact.out (x < y))]⟩,
map_source' := by simp only [imp_self, sub_lt_sub_iff_right, mem_set_of_eq, forall_true_iff],
map_target' :=
by { simp only [min_lt_iff, mem_set_of_eq], assume z hz, left,
dsimp [-subtype.val_eq_coe] at hz, linarith },
left_inv' := begin
rintros ⟨z, hz⟩ h'z,
simp only [mem_set_of_eq, mem_Icc] at hz h'z,
simp only [hz, min_eq_left, sub_add_cancel]
end,
right_inv' := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
dsimp at hz h'z,
have A : x + z 0 ≤ y, by linarith,
rw subsingleton.elim i 0,
simp only [A, add_comm, add_sub_cancel', min_eq_left],
end,
open_source := begin
have : is_open {z : ℝ | z < y} := is_open_Iio,
exact this.preimage continuous_subtype_val
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : euclidean_space ℝ (fin 1) | z 0 < y - x} :=
this.preimage (@continuous_apply (fin 1) (λ _, ℝ) _ 0),
exact this.preimage continuous_subtype_val
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), z - x) :=
continuous.sub (continuous_pi $ λi, continuous_id) continuous_const,
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, min (z + x) y) :=
(continuous_id.add continuous_const).min continuous_const,
have B : continuous (λz : euclidean_space ℝ (fin 1), z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
The right chart for the topological space `[x, y]`, defined on `(x,y]` and sending `y` to `0` in
`euclidean_half_space 1`.
-/
def Icc_right_chart (x y : ℝ) [fact (x < y)] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | x < z.val},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, y - z.val, sub_nonneg.mpr z.property.2⟩,
inv_fun := λz,
⟨max (y - z.val 0) x, by simp [le_refl, z.prop, le_of_lt (fact.out (x < y)), sub_eq_add_neg]⟩,
map_source' := by simp only [imp_self, mem_set_of_eq, sub_lt_sub_iff_left, forall_true_iff],
map_target' :=
by { simp only [lt_max_iff, mem_set_of_eq], assume z hz, left,
dsimp [-subtype.val_eq_coe] at hz, linarith },
left_inv' := begin
rintros ⟨z, hz⟩ h'z,
simp only [mem_set_of_eq, mem_Icc] at hz h'z,
simp only [hz, sub_eq_add_neg, max_eq_left, add_add_neg_cancel'_right, neg_add_rev, neg_neg]
end,
right_inv' := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
dsimp at hz h'z,
have A : x ≤ y - z 0, by linarith,
rw subsingleton.elim i 0,
simp only [A, sub_sub_cancel, max_eq_left],
end,
open_source := begin
have : is_open {z : ℝ | x < z} := is_open_Ioi,
exact this.preimage continuous_subtype_val
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : euclidean_space ℝ (fin 1) | z 0 < y - x} :=
this.preimage (@continuous_apply (fin 1) (λ _, ℝ) _ 0),
exact this.preimage continuous_subtype_val
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), y - z) :=
continuous_const.sub (continuous_pi (λi, continuous_id)),
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, max (y - z) x) :=
(continuous_const.sub continuous_id).max continuous_const,
have B : continuous (λz : euclidean_space ℝ (fin 1), z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
Charted space structure on `[x, y]`, using only two charts taking values in
`euclidean_half_space 1`.
-/
instance Icc_manifold (x y : ℝ) [fact (x < y)] : charted_space (euclidean_half_space 1) (Icc x y) :=
{ atlas := {Icc_left_chart x y, Icc_right_chart x y},
chart_at := λz, if z.val < y then Icc_left_chart x y else Icc_right_chart x y,
mem_chart_source := λz, begin
by_cases h' : z.val < y,
{ simp only [h', if_true],
exact h' },
{ simp only [h', if_false],
apply lt_of_lt_of_le (fact.out (x < y)),
simpa only [not_lt] using h'}
end,
chart_mem_atlas := λ z, by by_cases h' : (z : ℝ) < y; simp [h'] }
/--
The manifold structure on `[x, y]` is smooth.
-/
instance Icc_smooth_manifold (x y : ℝ) [fact (x < y)] :
smooth_manifold_with_corners (𝓡∂ 1) (Icc x y) :=
begin
have M : cont_diff_on ℝ ∞ (λz : euclidean_space ℝ (fin 1), - z + (λi, y - x)) univ,
{ rw cont_diff_on_univ,
exact cont_diff_id.neg.add cont_diff_const },
apply smooth_manifold_with_corners_of_cont_diff_on,
assume e e' he he',
simp only [atlas, mem_singleton_iff, mem_insert_iff] at he he',
/- We need to check that any composition of two charts gives a `C^∞` function. Each chart can be
either the left chart or the right chart, leaving 4 possibilities that we handle successively.
-/
rcases he with rfl | rfl; rcases he' with rfl | rfl,
{ -- `e = left chart`, `e' = left chart`
exact (mem_groupoid_of_pregroupoid.mpr (symm_trans_mem_cont_diff_groupoid _ _ _)).1 },
{ -- `e = left chart`, `e' = right chart`
apply M.congr_mono _ (subset_univ _),
rintro _ ⟨⟨hz₁, hz₂⟩, ⟨⟨z, hz₀⟩, rfl⟩⟩,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart,
update_same, max_eq_left, hz₀, lt_sub_iff_add_lt] with mfld_simps at hz₁ hz₂,
rw [min_eq_left hz₁.le, lt_add_iff_pos_left] at hz₂,
ext i,
rw subsingleton.elim i 0,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, *,
pi_Lp.add_apply, pi_Lp.neg_apply, max_eq_left, min_eq_left hz₁.le, update_same]
with mfld_simps,
abel },
{ -- `e = right chart`, `e' = left chart`
apply M.congr_mono _ (subset_univ _),
rintro _ ⟨⟨hz₁, hz₂⟩, ⟨z, hz₀⟩, rfl⟩,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, max_lt_iff,
update_same, max_eq_left hz₀] with mfld_simps at hz₁ hz₂,
rw lt_sub at hz₁,
ext i,
rw subsingleton.elim i 0,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart,
pi_Lp.add_apply, pi_Lp.neg_apply, update_same, max_eq_left, hz₀, hz₁.le] with mfld_simps,
abel },
{ -- `e = right chart`, `e' = right chart`
exact (mem_groupoid_of_pregroupoid.mpr (symm_trans_mem_cont_diff_groupoid _ _ _)).1 }
end
/-! Register the manifold structure on `Icc 0 1`, and also its zero and one. -/
section
lemma fact_zero_lt_one : fact ((0 : ℝ) < 1) := ⟨zero_lt_one⟩
local attribute [instance] fact_zero_lt_one
instance : charted_space (euclidean_half_space 1) (Icc (0 : ℝ) 1) := by apply_instance
instance : smooth_manifold_with_corners (𝓡∂ 1) (Icc (0 : ℝ) 1) := by apply_instance
end
|
e479788df5411e5c0d726a96403e5e96e5c78c88 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/category_theory/limits/constructions/finite_products_of_binary_products.lean | 6ca3bb7ede315bf5ab8dd0b77cad520ccec1d9e0 | [
"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 | 13,109 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.preserves.shapes.binary_products
import category_theory.limits.preserves.shapes.products
import category_theory.limits.shapes.binary_products
import category_theory.limits.shapes.finite_products
import category_theory.pempty
import logic.equiv.fin
/-!
# Constructing finite products from binary products and terminal.
If a category has binary products and a terminal object then it has finite products.
If a functor preserves binary products and the terminal object then it preserves finite products.
# TODO
Provide the dual results.
Show the analogous results for functors which reflect or create (co)limits.
-/
universes v v' u u'
noncomputable theory
open category_theory category_theory.category category_theory.limits
namespace category_theory
variables {J : Type v} [small_category J]
variables {C : Type u} [category.{v} C]
variables {D : Type u'} [category.{v'} D]
/--
Given `n+1` objects of `C`, a fan for the last `n` with point `c₁.X` and a binary fan on `c₁.X` and
`f 0`, we can build a fan for all `n+1`.
In `extend_fan_is_limit` we show that if the two given fans are limits, then this fan is also a
limit.
-/
@[simps {rhs_md := semireducible}]
def extend_fan {n : ℕ} {f : fin (n+1) → C}
(c₁ : fan (λ (i : fin n), f i.succ))
(c₂ : binary_fan (f 0) c₁.X) :
fan f :=
fan.mk c₂.X
begin
refine fin.cases _ _,
{ apply c₂.fst },
{ intro i, apply c₂.snd ≫ c₁.π.app ⟨i⟩ },
end
/--
Show that if the two given fans in `extend_fan` are limits, then the constructed fan is also a
limit.
-/
def extend_fan_is_limit {n : ℕ} (f : fin (n+1) → C)
{c₁ : fan (λ (i : fin n), f i.succ)} {c₂ : binary_fan (f 0) c₁.X}
(t₁ : is_limit c₁) (t₂ : is_limit c₂) :
is_limit (extend_fan c₁ c₂) :=
{ lift := λ s,
begin
apply (binary_fan.is_limit.lift' t₂ (s.π.app ⟨0⟩) _).1,
apply t₁.lift ⟨_, discrete.nat_trans (λ ⟨i⟩, s.π.app ⟨i.succ⟩)⟩
end,
fac' := λ s ⟨j⟩,
begin
apply fin.induction_on j,
{ apply (binary_fan.is_limit.lift' t₂ _ _).2.1 },
{ rintro i -,
dsimp only [extend_fan_π_app],
rw [fin.cases_succ, ← assoc, (binary_fan.is_limit.lift' t₂ _ _).2.2, t₁.fac],
refl }
end,
uniq' := λ s m w,
begin
apply binary_fan.is_limit.hom_ext t₂,
{ rw (binary_fan.is_limit.lift' t₂ _ _).2.1,
apply w ⟨0⟩ },
{ rw (binary_fan.is_limit.lift' t₂ _ _).2.2,
apply t₁.uniq ⟨_, _⟩,
rintro ⟨j⟩,
rw assoc,
dsimp only [discrete.nat_trans_app, extend_fan_is_limit._match_1],
rw ← w ⟨j.succ⟩,
dsimp only [extend_fan_π_app],
rw fin.cases_succ }
end }
section
variables [has_binary_products C] [has_terminal C]
/--
If `C` has a terminal object and binary products, then it has a product for objects indexed by
`fin n`.
This is a helper lemma for `has_finite_products_of_has_binary_and_terminal`, which is more general
than this.
-/
private lemma has_product_fin :
Π (n : ℕ) (f : fin n → C), has_product f
| 0 := λ f,
begin
letI : has_limits_of_shape (discrete (fin 0)) C :=
has_limits_of_shape_of_equivalence (discrete.equivalence.{0} fin_zero_equiv'.symm),
apply_instance,
end
| (n+1) := λ f,
begin
haveI := has_product_fin n,
apply has_limit.mk ⟨_, extend_fan_is_limit f (limit.is_limit _) (limit.is_limit _)⟩,
end
/--
If `C` has a terminal object and binary products, then it has limits of shape
`discrete (fin n)` for any `n : ℕ`.
This is a helper lemma for `has_finite_products_of_has_binary_and_terminal`, which is more general
than this.
-/
private lemma has_limits_of_shape_fin (n : ℕ) :
has_limits_of_shape (discrete (fin n)) C :=
{ has_limit := λ K,
begin
letI := has_product_fin n (λ n, K.obj ⟨n⟩),
let : discrete.functor (λ n, K.obj ⟨n⟩) ≅ K := discrete.nat_iso (λ ⟨i⟩, iso.refl _),
apply has_limit_of_iso this,
end }
/-- If `C` has a terminal object and binary products, then it has finite products. -/
lemma has_finite_products_of_has_binary_and_terminal : has_finite_products C :=
⟨λ J 𝒥, begin
resetI,
apply has_limits_of_shape_of_equivalence (discrete.equivalence (fintype.equiv_fin J)).symm,
refine has_limits_of_shape_fin (fintype.card J),
end⟩
end
section preserves
variables (F : C ⥤ D)
variables [preserves_limits_of_shape (discrete walking_pair) F]
variables [preserves_limits_of_shape (discrete.{0} pempty) F]
variables [has_finite_products.{v} C]
/--
If `F` preserves the terminal object and binary products, then it preserves products indexed by
`fin n` for any `n`.
-/
noncomputable def preserves_fin_of_preserves_binary_and_terminal :
Π (n : ℕ) (f : fin n → C), preserves_limit (discrete.functor f) F
| 0 := λ f,
begin
letI : preserves_limits_of_shape (discrete (fin 0)) F :=
preserves_limits_of_shape_of_equiv.{0 0}
(discrete.equivalence fin_zero_equiv'.symm) _,
apply_instance,
end
| (n+1) :=
begin
haveI := preserves_fin_of_preserves_binary_and_terminal n,
intro f,
refine preserves_limit_of_preserves_limit_cone
(extend_fan_is_limit f (limit.is_limit _) (limit.is_limit _)) _,
apply (is_limit_map_cone_fan_mk_equiv _ _ _).symm _,
let := extend_fan_is_limit (λ i, F.obj (f i))
(is_limit_of_has_product_of_preserves_limit F _)
(is_limit_of_has_binary_product_of_preserves_limit F _ _),
refine is_limit.of_iso_limit this _,
apply cones.ext _ _,
apply iso.refl _,
rintro ⟨j⟩,
apply fin.induction_on j,
{ apply (category.id_comp _).symm },
{ rintro i -,
dsimp only [extend_fan_π_app, iso.refl_hom, fan.mk_π_app],
rw [fin.cases_succ, fin.cases_succ],
change F.map _ ≫ _ = 𝟙 _ ≫ _,
rw [id_comp, ←F.map_comp],
refl }
end
/--
If `F` preserves the terminal object and binary products, then it preserves limits of shape
`discrete (fin n)`.
-/
def preserves_shape_fin_of_preserves_binary_and_terminal (n : ℕ) :
preserves_limits_of_shape (discrete (fin n)) F :=
{ preserves_limit := λ K,
begin
let : discrete.functor (λ n, K.obj ⟨n⟩) ≅ K := discrete.nat_iso (λ ⟨i⟩, iso.refl _),
haveI := preserves_fin_of_preserves_binary_and_terminal F n (λ n, K.obj ⟨n⟩),
apply preserves_limit_of_iso_diagram F this,
end }
/-- If `F` preserves the terminal object and binary products then it preserves finite products. -/
def preserves_finite_products_of_preserves_binary_and_terminal
(J : Type) [fintype J] :
preserves_limits_of_shape (discrete J) F :=
begin
classical,
let e := fintype.equiv_fin J,
haveI := preserves_shape_fin_of_preserves_binary_and_terminal F (fintype.card J),
apply preserves_limits_of_shape_of_equiv.{0 0}
(discrete.equivalence e).symm,
end
end preserves
/--
Given `n+1` objects of `C`, a cofan for the last `n` with point `c₁.X`
and a binary cofan on `c₁.X` and `f 0`, we can build a cofan for all `n+1`.
In `extend_cofan_is_colimit` we show that if the two given cofans are colimits,
then this cofan is also a colimit.
-/
@[simps {rhs_md := semireducible}]
def extend_cofan {n : ℕ} {f : fin (n+1) → C}
(c₁ : cofan (λ (i : fin n), f i.succ))
(c₂ : binary_cofan (f 0) c₁.X) :
cofan f :=
cofan.mk c₂.X
begin
refine fin.cases _ _,
{ apply c₂.inl },
{ intro i,
apply c₁.ι.app ⟨i⟩ ≫ c₂.inr },
end
/--
Show that if the two given cofans in `extend_cofan` are colimits,
then the constructed cofan is also a colimit.
-/
def extend_cofan_is_colimit {n : ℕ} (f : fin (n+1) → C)
{c₁ : cofan (λ (i : fin n), f i.succ)} {c₂ : binary_cofan (f 0) c₁.X}
(t₁ : is_colimit c₁) (t₂ : is_colimit c₂) :
is_colimit (extend_cofan c₁ c₂) :=
{ desc := λ s,
begin
apply (binary_cofan.is_colimit.desc' t₂ (s.ι.app ⟨0⟩) _).1,
apply t₁.desc ⟨_, discrete.nat_trans (λ i, s.ι.app ⟨i.as.succ⟩)⟩
end,
fac' := λ s,
begin
rintro ⟨j⟩,
apply fin.induction_on j,
{ apply (binary_cofan.is_colimit.desc' t₂ _ _).2.1 },
{ rintro i -,
dsimp only [extend_cofan_ι_app],
rw [fin.cases_succ, assoc, (binary_cofan.is_colimit.desc' t₂ _ _).2.2, t₁.fac],
refl }
end,
uniq' := λ s m w,
begin
apply binary_cofan.is_colimit.hom_ext t₂,
{ rw (binary_cofan.is_colimit.desc' t₂ _ _).2.1,
apply w ⟨0⟩ },
{ rw (binary_cofan.is_colimit.desc' t₂ _ _).2.2,
apply t₁.uniq ⟨_, _⟩,
rintro ⟨j⟩,
dsimp only [discrete.nat_trans_app],
rw ← w ⟨j.succ⟩,
dsimp only [extend_cofan_ι_app],
rw [fin.cases_succ, assoc], }
end }
section
variables [has_binary_coproducts C] [has_initial C]
/--
If `C` has an initial object and binary coproducts, then it has a coproduct for objects indexed by
`fin n`.
This is a helper lemma for `has_cofinite_products_of_has_binary_and_terminal`, which is more general
than this.
-/
private lemma has_coproduct_fin :
Π (n : ℕ) (f : fin n → C), has_coproduct f
| 0 := λ f,
begin
letI : has_colimits_of_shape (discrete (fin 0)) C :=
has_colimits_of_shape_of_equivalence (discrete.equivalence.{0} fin_zero_equiv'.symm),
apply_instance,
end
| (n+1) := λ f,
begin
haveI := has_coproduct_fin n,
apply has_colimit.mk
⟨_, extend_cofan_is_colimit f (colimit.is_colimit _) (colimit.is_colimit _)⟩,
end
/--
If `C` has an initial object and binary coproducts, then it has colimits of shape
`discrete (fin n)` for any `n : ℕ`.
This is a helper lemma for `has_cofinite_products_of_has_binary_and_terminal`, which is more general
than this.
-/
private lemma has_colimits_of_shape_fin (n : ℕ) :
has_colimits_of_shape (discrete (fin n)) C :=
{ has_colimit := λ K,
begin
letI := has_coproduct_fin n (λ n, K.obj ⟨n⟩),
let : K ≅ discrete.functor (λ n, K.obj ⟨n⟩) := discrete.nat_iso (λ ⟨i⟩, iso.refl _),
apply has_colimit_of_iso this,
end }
/-- If `C` has an initial object and binary coproducts, then it has finite coproducts. -/
lemma has_finite_coproducts_of_has_binary_and_initial : has_finite_coproducts C :=
⟨λ J 𝒥, begin
resetI,
apply has_colimits_of_shape_of_equivalence (discrete.equivalence (fintype.equiv_fin J)).symm,
refine has_colimits_of_shape_fin (fintype.card J),
end⟩
end
section preserves
variables (F : C ⥤ D)
variables [preserves_colimits_of_shape (discrete walking_pair) F]
variables [preserves_colimits_of_shape (discrete.{0} pempty) F]
variables [has_finite_coproducts.{v} C]
/--
If `F` preserves the initial object and binary coproducts, then it preserves products indexed by
`fin n` for any `n`.
-/
noncomputable def preserves_fin_of_preserves_binary_and_initial :
Π (n : ℕ) (f : fin n → C), preserves_colimit (discrete.functor f) F
| 0 := λ f,
begin
letI : preserves_colimits_of_shape (discrete (fin 0)) F :=
preserves_colimits_of_shape_of_equiv.{0 0}
(discrete.equivalence fin_zero_equiv'.symm) _,
apply_instance,
end
| (n+1) :=
begin
haveI := preserves_fin_of_preserves_binary_and_initial n,
intro f,
refine preserves_colimit_of_preserves_colimit_cocone
(extend_cofan_is_colimit f (colimit.is_colimit _) (colimit.is_colimit _)) _,
apply (is_colimit_map_cocone_cofan_mk_equiv _ _ _).symm _,
let := extend_cofan_is_colimit (λ i, F.obj (f i))
(is_colimit_of_has_coproduct_of_preserves_colimit F _)
(is_colimit_of_has_binary_coproduct_of_preserves_colimit F _ _),
refine is_colimit.of_iso_colimit this _,
apply cocones.ext _ _,
apply iso.refl _,
rintro ⟨j⟩,
apply fin.induction_on j,
{ apply category.comp_id },
{ rintro i -,
dsimp only [extend_cofan_ι_app, iso.refl_hom, cofan.mk_ι_app],
rw [fin.cases_succ, fin.cases_succ],
erw [comp_id, ←F.map_comp],
refl, }
end
/--
If `F` preserves the initial object and binary coproducts, then it preserves colimits of shape
`discrete (fin n)`.
-/
def preserves_shape_fin_of_preserves_binary_and_initial (n : ℕ) :
preserves_colimits_of_shape (discrete (fin n)) F :=
{ preserves_colimit := λ K,
begin
let : discrete.functor (λ n, K.obj ⟨n⟩) ≅ K := discrete.nat_iso (λ ⟨i⟩, iso.refl _),
haveI := preserves_fin_of_preserves_binary_and_initial F n (λ n, K.obj ⟨n⟩),
apply preserves_colimit_of_iso_diagram F this,
end }
/-- If `F` preserves the initial object and binary coproducts then it preserves finite products. -/
def preserves_finite_coproducts_of_preserves_binary_and_initial
(J : Type) [fintype J] :
preserves_colimits_of_shape (discrete J) F :=
begin
classical,
let e := fintype.equiv_fin J,
haveI := preserves_shape_fin_of_preserves_binary_and_initial F (fintype.card J),
apply preserves_colimits_of_shape_of_equiv.{0 0} (discrete.equivalence e).symm,
end
end preserves
end category_theory
|
1895b382e8d6158b931d5d5081afa9fa0c2c9ef7 | 3b15c7b0b62d8ada1399c112ad88a529e6bfa115 | /stage0/src/Lean/Elab/BuiltinNotation.lean | 526925315b1a53d1ca9da272fac550db40ba2818 | [
"Apache-2.0"
] | permissive | stephenbrady/lean4 | 74bf5cae8a433e9c815708ce96c9e54a5caf2115 | b1bd3fc304d0f7bc6810ec78bfa4c51476d263f9 | refs/heads/master | 1,692,621,473,161 | 1,634,308,743,000 | 1,634,310,749,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,811 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Init.Data.ToString
import Lean.Compiler.BorrowedAnnotation
import Lean.Meta.KAbstract
import Lean.Meta.Transform
import Lean.Elab.App
import Lean.Elab.SyntheticMVars
namespace Lean.Elab.Term
open Meta
@[builtinTermElab anonymousCtor] def elabAnonymousCtor : TermElab := fun stx expectedType? =>
match stx with
| `(⟨$args,*⟩) => do
tryPostponeIfNoneOrMVar expectedType?
match expectedType? with
| some expectedType =>
let expectedType ← whnf expectedType
matchConstInduct expectedType.getAppFn
(fun _ => throwError "invalid constructor ⟨...⟩, expected type must be an inductive type {indentExpr expectedType}")
(fun ival us => do
match ival.ctors with
| [ctor] =>
let cinfo ← getConstInfoCtor ctor
let numExplicitFields ← forallTelescopeReducing cinfo.type fun xs _ => do
let mut n := 0
for i in [cinfo.numParams:xs.size] do
if (← getFVarLocalDecl xs[i]).binderInfo.isExplicit then
n := n + 1
return n
let args := args.getElems
if args.size < numExplicitFields then
throwError "invalid constructor ⟨...⟩, insufficient number of arguments, constructs '{ctor}' has #{numExplicitFields} explicit fields, but only #{args.size} provided"
let newStx ←
if args.size == numExplicitFields then
`($(mkCIdentFrom stx ctor) $(args)*)
else if numExplicitFields == 0 then
throwError "invalid constructor ⟨...⟩, insufficient number of arguments, constructs '{ctor}' does not have explicit fields, but #{args.size} provided"
else
let extra := args[numExplicitFields-1:args.size]
let newLast ← `(⟨$[$extra],*⟩)
let newArgs := args[0:numExplicitFields-1].toArray.push newLast
`($(mkCIdentFrom stx ctor) $(newArgs)*)
withMacroExpansion stx newStx $ elabTerm newStx expectedType?
| _ => throwError "invalid constructor ⟨...⟩, expected type must be an inductive type with only one constructor {indentExpr expectedType}")
| none => throwError "invalid constructor ⟨...⟩, expected type must be known"
| _ => throwUnsupportedSyntax
@[builtinTermElab borrowed] def elabBorrowed : TermElab := fun stx expectedType? =>
match stx with
| `(@& $e) => return markBorrowed (← elabTerm e expectedType?)
| _ => throwUnsupportedSyntax
@[builtinMacro Lean.Parser.Term.show] def expandShow : Macro := fun stx =>
match stx with
| `(show $type from $val) => let thisId := mkIdentFrom stx `this; `(let_fun $thisId : $type := $val; $thisId)
| `(show $type by%$b $tac:tacticSeq) => `(show $type from by%$b $tac:tacticSeq)
| _ => Macro.throwUnsupported
@[builtinMacro Lean.Parser.Term.have] def expandHave : Macro := fun stx =>
let thisId := mkIdentFrom stx `this
match stx with
| `(have $x $bs* $[: $type]? := $val $[;]? $body) => `(let_fun $x $bs* $[: $type]? := $val; $body)
| `(have $[: $type]? := $val $[;]? $body) => `(have $thisId:ident $[: $type]? := $val; $body)
| `(have $x $bs* $[: $type]? $alts:matchAlts $[;]? $body) => `(let_fun $x $bs* $[: $type]? $alts:matchAlts; $body)
| `(have $[: $type]? $alts:matchAlts $[;]? $body) => `(have $thisId:ident $[: $type]? $alts:matchAlts; $body)
| `(have $pattern:term $[: $type]? := $val:term $[;]? $body) => `(let_fun $pattern:term $[: $type]? := $val:term ; $body)
| _ => Macro.throwUnsupported
@[builtinMacro Lean.Parser.Term.suffices] def expandSuffices : Macro
| `(suffices $[$x :]? $type from $val $[;]? $body) => `(have $[$x]? : $type := $body; $val)
| `(suffices $[$x :]? $type by%$b $tac:tacticSeq $[;]? $body) => `(have $[$x]? : $type := $body; by%$b $tac:tacticSeq)
| _ => Macro.throwUnsupported
open Lean.Parser in
private def elabParserMacroAux (prec : Syntax) (e : Syntax) : TermElabM Syntax := do
let (some declName) ← getDeclName?
| throwError "invalid `leading_parser` macro, it must be used in definitions"
match extractMacroScopes declName with
| { name := Name.str _ s _, scopes := scps, .. } =>
let kind := quote declName
let s := quote s
-- if the parser decl is hidden by hygiene, it doesn't make sense to provide an antiquotation kind
let antiquotKind ← if scps == [] then `(some $kind) else `(none)
``(withAntiquot (mkAntiquot $s $antiquotKind) (leadingNode $kind $prec $e))
| _ => throwError "invalid `leading_parser` macro, unexpected declaration name"
@[builtinTermElab «leading_parser»] def elabLeadingParserMacro : TermElab :=
adaptExpander fun stx => match stx with
| `(leading_parser $e) => elabParserMacroAux (quote Parser.maxPrec) e
| `(leading_parser : $prec $e) => elabParserMacroAux prec e
| _ => throwUnsupportedSyntax
private def elabTParserMacroAux (prec lhsPrec : Syntax) (e : Syntax) : TermElabM Syntax := do
let declName? ← getDeclName?
match declName? with
| some declName => let kind := quote declName; ``(Lean.Parser.trailingNode $kind $prec $lhsPrec $e)
| none => throwError "invalid `trailing_parser` macro, it must be used in definitions"
@[builtinTermElab «trailing_parser»] def elabTrailingParserMacro : TermElab :=
adaptExpander fun stx => match stx with
| `(trailing_parser$[:$prec?]?$[:$lhsPrec?]? $e) =>
elabTParserMacroAux (prec?.getD <| quote Parser.maxPrec) (lhsPrec?.getD <| quote 0) e
| _ => throwUnsupportedSyntax
@[builtinTermElab panic] def elabPanic : TermElab := fun stx expectedType? => do
let arg := stx[1]
let pos ← getRefPosition
let env ← getEnv
let stxNew ← match (← getDeclName?) with
| some declName => `(panicWithPosWithDecl $(quote (toString env.mainModule)) $(quote (toString declName)) $(quote pos.line) $(quote pos.column) $arg)
| none => `(panicWithPos $(quote (toString env.mainModule)) $(quote pos.line) $(quote pos.column) $arg)
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
@[builtinMacro Lean.Parser.Term.unreachable] def expandUnreachable : Macro := fun stx =>
`(panic! "unreachable code has been reached")
@[builtinMacro Lean.Parser.Term.assert] def expandAssert : Macro := fun stx =>
-- TODO: support for disabling runtime assertions
let cond := stx[1]
let body := stx[3]
match cond.reprint with
| some code => `(if $cond then $body else panic! ("assertion violation: " ++ $(quote code)))
| none => `(if $cond then $body else panic! ("assertion violation"))
@[builtinMacro Lean.Parser.Term.dbgTrace] def expandDbgTrace : Macro := fun stx =>
let arg := stx[1]
let body := stx[3]
if arg.getKind == interpolatedStrKind then
`(dbgTrace (s! $arg) fun _ => $body)
else
`(dbgTrace (toString $arg) fun _ => $body)
@[builtinTermElab «sorry»] def elabSorry : TermElab := fun stx expectedType? => do
logWarning "declaration uses 'sorry'"
let stxNew ← `(sorryAx _ false)
withMacroExpansion stx stxNew <| elabTerm stxNew expectedType?
/-- Return syntax `Prod.mk elems[0] (Prod.mk elems[1] ... (Prod.mk elems[elems.size - 2] elems[elems.size - 1])))` -/
partial def mkPairs (elems : Array Syntax) : MacroM Syntax :=
let rec loop (i : Nat) (acc : Syntax) := do
if i > 0 then
let i := i - 1
let elem := elems[i]
let acc ← `(Prod.mk $elem $acc)
loop i acc
else
pure acc
loop (elems.size - 1) elems.back
private partial def hasCDot : Syntax → Bool
| Syntax.node k args =>
if k == ``Lean.Parser.Term.paren then false
else if k == ``Lean.Parser.Term.cdot then true
else args.any hasCDot
| _ => false
/--
Return `some` if succeeded expanding `·` notation occurring in
the given syntax. Otherwise, return `none`.
Examples:
- `· + 1` => `fun _a_1 => _a_1 + 1`
- `f · · b` => `fun _a_1 _a_2 => f _a_1 _a_2 b` -/
partial def expandCDot? (stx : Syntax) : MacroM (Option Syntax) := do
if hasCDot stx then
let (newStx, binders) ← (go stx).run #[];
`(fun $binders* => $newStx)
else
pure none
where
/--
Auxiliary function for expanding the `·` notation.
The extra state `Array Syntax` contains the new binder names.
If `stx` is a `·`, we create a fresh identifier, store in the
extra state, and return it. Otherwise, we just return `stx`. -/
go : Syntax → StateT (Array Syntax) MacroM Syntax
| stx@(Syntax.node k args) =>
if k == ``Lean.Parser.Term.paren then pure stx
else if k == ``Lean.Parser.Term.cdot then withFreshMacroScope do
let id ← `(a)
modify fun s => s.push id;
pure id
else do
let args ← args.mapM go
pure $ Syntax.node k args
| stx => pure stx
/--
Helper method for elaborating terms such as `(.+.)` where a constant name is expected.
This method is usually used to implement tactics that function names as arguments (e.g., `simp`).
-/
def elabCDotFunctionAlias? (stx : Syntax) : TermElabM (Option Expr) := do
let some stx ← liftMacroM <| expandCDotArg? stx | pure none
let stx ← liftMacroM <| expandMacros stx
match stx with
| `(fun $binders* => $f:ident $args*) =>
if binders == args then
try Term.resolveId? f catch _ => return none
else
return none
| `(fun $binders* => binop% $f:ident $a $b) =>
if binders == #[a, b] then
try Term.resolveId? f catch _ => return none
else
return none
| _ => return none
where
expandCDotArg? (stx : Syntax) : MacroM (Option Syntax) :=
match stx with
| `(($e)) => Term.expandCDot? e
| _ => Term.expandCDot? stx
/--
Try to expand `·` notation.
Recall that in Lean the `·` notation must be surrounded by parentheses.
We may change this is the future, but right now, here are valid examples
- `(· + 1)`
- `(f ⟨·, 1⟩ ·)`
- `(· + ·)`
- `(f · a b)` -/
@[builtinMacro Lean.Parser.Term.paren] def expandParen : Macro
| `(()) => `(Unit.unit)
| `(($e : $type)) => do
match (← expandCDot? e) with
| some e => `(($e : $type))
| none => Macro.throwUnsupported
| `(($e)) => return (← expandCDot? e).getD e
| `(($e, $es,*)) => do
let pairs ← mkPairs (#[e] ++ es)
(← expandCDot? pairs).getD pairs
| stx =>
if !stx[1][0].isMissing && stx[1][1].isMissing then
-- parsed `(` and `term`, assume it's a basic parenthesis to get any elaboration output at all
`(($(stx[1][0])))
else
throw <| Macro.Exception.error stx "unexpected parentheses notation"
@[builtinTermElab paren] def elabParen : TermElab := fun stx expectedType? => do
match stx with
| `(($e : $type)) =>
let type ← withSynthesize (mayPostpone := true) <| elabType type
let e ← elabTerm e type
ensureHasType type e
| _ => throwUnsupportedSyntax
@[builtinTermElab subst] def elabSubst : TermElab := fun stx expectedType? => do
let expectedType ← tryPostponeIfHasMVars expectedType? "invalid `▸` notation"
match stx with
| `($heq ▸ $h) => do
let mut heq ← elabTerm heq none
let heqType ← inferType heq
let heqType ← instantiateMVars heqType
match (← Meta.matchEq? heqType) with
| none => throwError "invalid `▸` notation, argument{indentExpr heq}\nhas type{indentExpr heqType}\nequality expected"
| some (α, lhs, rhs) =>
let mut lhs := lhs
let mut rhs := rhs
let mkMotive (typeWithLooseBVar : Expr) := do
withLocalDeclD (← mkFreshUserName `x) α fun x => do
mkLambdaFVars #[x] $ typeWithLooseBVar.instantiate1 x
let mut expectedAbst ← kabstract expectedType rhs
unless expectedAbst.hasLooseBVars do
expectedAbst ← kabstract expectedType lhs
unless expectedAbst.hasLooseBVars do
throwError "invalid `▸` notation, expected type{indentExpr expectedType}\ndoes contain equation left-hand-side nor right-hand-side{indentExpr heqType}"
heq ← mkEqSymm heq
(lhs, rhs) := (rhs, lhs)
let hExpectedType := expectedAbst.instantiate1 lhs
let h ← withRef h do
let h ← elabTerm h hExpectedType
try
ensureHasType hExpectedType h
catch ex =>
-- if `rhs` occurs in `hType`, we try to apply `heq` to `h` too
let hType ← inferType h
let hTypeAbst ← kabstract hType rhs
unless hTypeAbst.hasLooseBVars do
throw ex
let hTypeNew := hTypeAbst.instantiate1 lhs
unless (← isDefEq hExpectedType hTypeNew) do
throw ex
mkEqNDRec (← mkMotive hTypeAbst) h (← mkEqSymm heq)
mkEqNDRec (← mkMotive expectedAbst) h heq
| _ => throwUnsupportedSyntax
@[builtinTermElab stateRefT] def elabStateRefT : TermElab := fun stx _ => do
let σ ← elabType stx[1]
let mut mStx := stx[2]
if mStx.getKind == ``Lean.Parser.Term.macroDollarArg then
mStx := mStx[1]
let m ← elabTerm mStx (← mkArrow (mkSort levelOne) (mkSort levelOne))
let ω ← mkFreshExprMVar (mkSort levelOne)
let stWorld ← mkAppM ``STWorld #[ω, m]
discard <| mkInstMVar stWorld
mkAppM ``StateRefT' #[ω, σ, m]
@[builtinTermElab noindex] def elabNoindex : TermElab := fun stx expectedType? => do
let e ← elabTerm stx[1] expectedType?
return DiscrTree.mkNoindexAnnotation e
end Lean.Elab.Term
|
1db9ec804d7139b413c70f6b4b05411b56879a55 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/rw_at_failure.lean | 40cc14662652f5aac510172fadc800f95f6ba149 | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 153 | lean | import data.nat
open nat
example (a b : nat) : a = b → 0 + a = 0 + b :=
begin
rewrite zero_add at {2} -- Should fail since nothing is rewritten
end
|
353a5fc3609d8cc9f2c7c4a5d1eb15b08a95c114 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/sym/sym2.lean | 1a12b0b93ac69ee0cb7f6aeed8712def89896ac7 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,825 | lean | /-
Copyright (c) 2020 Kyle Miller All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import data.sym.basic
import tactic.linarith
/-!
# The symmetric square
This file defines the symmetric square, which is `α × α` modulo
swapping. This is also known as the type of unordered pairs.
More generally, the symmetric square is the second symmetric power
(see `data.sym.basic`). The equivalence is `sym2.equiv_sym`.
From the point of view that an unordered pair is equivalent to a
multiset of cardinality two (see `sym2.equiv_multiset`), there is a
`has_mem` instance `sym2.mem`, which is a `Prop`-valued membership
test. Given `h : a ∈ z` for `z : sym2 α`, then `h.other` is the other
element of the pair, defined using `classical.choice`. If `α` has
decidable equality, then `h.other'` computably gives the other element.
The universal property of `sym2` is provided as `sym2.lift`, which
states that functions from `sym2 α` are equivalent to symmetric
two-argument functions from `α`.
Recall that an undirected graph (allowing self loops, but no multiple
edges) is equivalent to a symmetric relation on the vertex type `α`.
Given a symmetric relation on `α`, the corresponding edge set is
constructed by `sym2.from_rel` which is a special case of `sym2.lift`.
## Notation
The symmetric square has a setoid instance, so `⟦(a, b)⟧` denotes a
term of the symmetric square.
## Tags
symmetric square, unordered pairs, symmetric powers
-/
open finset fintype function sym
universe u
variables {α : Type u}
namespace sym2
/--
This is the relation capturing the notion of pairs equivalent up to permutations.
-/
inductive rel (α : Type u) : (α × α) → (α × α) → Prop
| refl (x y : α) : rel (x, y) (x, y)
| swap (x y : α) : rel (x, y) (y, x)
attribute [refl] rel.refl
@[symm] lemma rel.symm {x y : α × α} : rel α x y → rel α y x :=
by rintro ⟨_, _⟩; constructor
@[trans] lemma rel.trans {x y z : α × α} : rel α x y → rel α y z → rel α x z :=
by { intros a b, cases_matching* rel _ _ _; apply rel.refl <|> apply rel.swap }
lemma rel.is_equivalence : equivalence (rel α) := by tidy; apply rel.trans; assumption
instance rel.setoid (α : Type u) : setoid (α × α) := ⟨rel α, rel.is_equivalence⟩
end sym2
/--
`sym2 α` is the symmetric square of `α`, which, in other words, is the
type of unordered pairs.
It is equivalent in a natural way to multisets of cardinality 2 (see
`sym2.equiv_multiset`).
-/
@[reducible]
def sym2 (α : Type u) := quotient (sym2.rel.setoid α)
namespace sym2
@[elab_as_eliminator]
protected lemma ind {f : sym2 α → Prop} (h : ∀ x y, f ⟦(x, y)⟧) : ∀ i, f i :=
quotient.ind $ prod.rec $ by exact h
@[elab_as_eliminator]
protected lemma induction_on {f : sym2 α → Prop} (i : sym2 α) (hf : ∀ x y, f ⟦(x,y)⟧) : f i :=
i.ind hf
protected lemma «exists» {α : Sort*} {f : sym2 α → Prop} :
(∃ (x : sym2 α), f x) ↔ ∃ x y, f ⟦(x, y)⟧ :=
(surjective_quotient_mk _).exists.trans prod.exists
protected lemma «forall» {α : Sort*} {f : sym2 α → Prop} :
(∀ (x : sym2 α), f x) ↔ ∀ x y, f ⟦(x, y)⟧ :=
(surjective_quotient_mk _).forall.trans prod.forall
lemma eq_swap {a b : α} : ⟦(a, b)⟧ = ⟦(b, a)⟧ :=
by { rw quotient.eq, apply rel.swap }
lemma congr_right {a b c : α} : ⟦(a, b)⟧ = ⟦(a, c)⟧ ↔ b = c :=
by { split; intro h, { rw quotient.eq at h, cases h; refl }, rw h }
lemma congr_left {a b c : α} : ⟦(b, a)⟧ = ⟦(c, a)⟧ ↔ b = c :=
by { split; intro h, { rw quotient.eq at h, cases h; refl }, rw h }
lemma eq_iff {x y z w : α} :
⟦(x, y)⟧ = ⟦(z, w)⟧ ↔ (x = z ∧ y = w) ∨ (x = w ∧ y = z) :=
begin
split; intro h,
{ rw quotient.eq at h, cases h; tidy },
{ cases h; rw [h.1, h.2], rw eq_swap }
end
/-- The universal property of `sym2`; symmetric functions of two arguments are equivalent to
functions from `sym2`. Note that when `β` is `Prop`, it can sometimes be more convenient to use
`sym2.from_rel` instead. -/
def lift {β : Type*} : {f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁} ≃ (sym2 α → β) :=
{ to_fun := λ f, quotient.lift (uncurry ↑f) $ by { rintro _ _ ⟨⟩, exacts [rfl, f.prop _ _] },
inv_fun := λ F, ⟨curry (F ∘ quotient.mk), λ a₁ a₂, congr_arg F eq_swap⟩,
left_inv := λ f, subtype.ext rfl,
right_inv := λ F, funext $ sym2.ind $ by exact λ x y, rfl }
@[simp]
lemma lift_mk {β : Type*} (f : {f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁}) (a₁ a₂ : α) :
lift f ⟦(a₁, a₂)⟧ = (f : α → α → β) a₁ a₂ := rfl
@[simp]
lemma coe_lift_symm_apply {β : Type*} (F : sym2 α → β) (a₁ a₂ : α) :
(lift.symm F : α → α → β) a₁ a₂ = F ⟦(a₁, a₂)⟧ := rfl
/--
The functor `sym2` is functorial, and this function constructs the induced maps.
-/
def map {α β : Type*} (f : α → β) : sym2 α → sym2 β :=
quotient.map (prod.map f f)
(by { rintros _ _ h, cases h, { refl }, apply rel.swap })
@[simp]
lemma map_id : sym2.map (@id α) = id := by tidy
lemma map_comp {α β γ : Type*} {g : β → γ} {f : α → β} :
sym2.map (g ∘ f) = sym2.map g ∘ sym2.map f := by tidy
lemma map_map {α β γ : Type*} {g : β → γ} {f : α → β} (x : sym2 α) :
map g (map f x) = map (g ∘ f) x := by tidy
@[simp]
lemma map_pair_eq {α β : Type*} (f : α → β) (x y : α) : map f ⟦(x, y)⟧ = ⟦(f x, f y)⟧ := rfl
lemma map.injective {α β : Type*} {f : α → β} (hinj : injective f) : injective (map f) :=
begin
intros z z',
refine quotient.ind₂ (λ z z', _) z z',
cases z with x y,
cases z' with x' y',
repeat { rw [map_pair_eq, eq_iff] },
rintro (h|h); simp [hinj h.1, hinj h.2],
end
section membership
/-! ### Declarations about membership -/
/--
This is a predicate that determines whether a given term is a member of a term of the
symmetric square. From this point of view, the symmetric square is the subtype of
cardinality-two multisets on `α`.
-/
def mem (x : α) (z : sym2 α) : Prop :=
∃ (y : α), z = ⟦(x, y)⟧
instance : has_mem α (sym2 α) := ⟨mem⟩
lemma mk_has_mem (x y : α) : x ∈ ⟦(x, y)⟧ := ⟨y, rfl⟩
lemma mk_has_mem_right (x y : α) : y ∈ ⟦(x, y)⟧ := by { rw eq_swap, apply mk_has_mem }
/--
Given an element of the unordered pair, give the other element using `classical.some`.
See also `mem.other'` for the computable version.
-/
noncomputable def mem.other {a : α} {z : sym2 α} (h : a ∈ z) : α :=
classical.some h
@[simp]
lemma mem_other_spec {a : α} {z : sym2 α} (h : a ∈ z) : ⟦(a, h.other)⟧ = z :=
by erw ← classical.some_spec h
@[simp] lemma mem_iff {a b c : α} : a ∈ ⟦(b, c)⟧ ↔ a = b ∨ a = c :=
{ mp := by { rintro ⟨_, h⟩, rw eq_iff at h, tidy },
mpr := by { rintro ⟨_⟩; subst a, { apply mk_has_mem }, apply mk_has_mem_right } }
lemma mem_other_mem {a : α} {z : sym2 α} (h : a ∈ z) :
h.other ∈ z :=
by { convert mk_has_mem_right a h.other, rw mem_other_spec h }
lemma elems_iff_eq {x y : α} {z : sym2 α} (hne : x ≠ y) :
x ∈ z ∧ y ∈ z ↔ z = ⟦(x, y)⟧ :=
begin
split,
{ refine quotient.rec_on_subsingleton z _,
rintros ⟨z₁, z₂⟩ ⟨hx, hy⟩,
rw eq_iff,
cases mem_iff.mp hx with hx hx; cases mem_iff.mp hy with hy hy; subst x; subst y;
try { exact (hne rfl).elim };
simp only [true_or, eq_self_iff_true, and_self, or_true] },
{ rintro rfl, simp },
end
@[ext]
lemma sym2_ext (z z' : sym2 α) (h : ∀ x, x ∈ z ↔ x ∈ z') : z = z' :=
begin
refine quotient.rec_on_subsingleton z (λ w, _) h,
refine quotient.rec_on_subsingleton z' (λ w', _),
intro h,
cases w with x y, cases w' with x' y',
simp only [mem_iff] at h,
apply eq_iff.mpr,
have hx := h x, have hy := h y, have hx' := h x', have hy' := h y',
simp only [true_iff, true_or, eq_self_iff_true, iff_true, or_true] at hx hy hx' hy',
cases hx; subst x; cases hy; subst y; cases hx'; try { subst x' }; cases hy'; try { subst y' };
simp only [eq_self_iff_true, and_self, or_self, true_or, or_true],
end
instance mem.decidable [decidable_eq α] (x : α) (z : sym2 α) : decidable (x ∈ z) :=
quotient.rec_on_subsingleton z (λ ⟨y₁, y₂⟩, decidable_of_iff' _ mem_iff)
end membership
/--
A type `α` is naturally included in the diagonal of `α × α`, and this function gives the image
of this diagonal in `sym2 α`.
-/
def diag (x : α) : sym2 α := ⟦(x, x)⟧
lemma diag_injective : function.injective (sym2.diag : α → sym2 α) :=
λ x y h, by cases quotient.exact h; refl
/--
A predicate for testing whether an element of `sym2 α` is on the diagonal.
-/
def is_diag : sym2 α → Prop :=
lift ⟨eq, λ _ _, propext eq_comm⟩
lemma is_diag_iff_eq {x y : α} : is_diag ⟦(x, y)⟧ ↔ x = y :=
iff.rfl
@[simp]
lemma is_diag_iff_proj_eq (z : α × α) : is_diag ⟦z⟧ ↔ z.1 = z.2 :=
prod.rec_on z $ λ _ _, is_diag_iff_eq
@[simp]
lemma diag_is_diag (a : α) : is_diag (diag a) :=
eq.refl a
lemma is_diag.mem_range_diag {z : sym2 α} : is_diag z → z ∈ set.range (@diag α) :=
begin
induction z using quotient.induction_on,
cases z,
rintro (rfl : z_fst = z_snd),
exact ⟨z_fst, rfl⟩,
end
lemma is_diag_iff_mem_range_diag (z : sym2 α) : is_diag z ↔ z ∈ set.range (@diag α) :=
⟨is_diag.mem_range_diag, λ ⟨i, hi⟩, hi ▸ diag_is_diag i⟩
instance is_diag.decidable_pred (α : Type u) [decidable_eq α] : decidable_pred (@is_diag α) :=
by { refine λ z, quotient.rec_on_subsingleton z (λ a, _), erw is_diag_iff_proj_eq, apply_instance }
lemma mem_other_ne {a : α} {z : sym2 α} (hd : ¬is_diag z) (h : a ∈ z) : h.other ≠ a :=
begin
intro hn, apply hd,
have h' := sym2.mem_other_spec h,
rw hn at h',
rw ←h',
simp,
end
section relations
/-! ### Declarations about symmetric relations -/
variables {r : α → α → Prop}
/--
Symmetric relations define a set on `sym2 α` by taking all those pairs
of elements that are related.
-/
def from_rel (sym : symmetric r) : set (sym2 α) :=
set_of (lift ⟨r, λ x y, propext ⟨λ h, sym h, λ h, sym h⟩⟩)
@[simp]
lemma from_rel_proj_prop {sym : symmetric r} {z : α × α} :
⟦z⟧ ∈ from_rel sym ↔ r z.1 z.2 := iff.rfl
@[simp]
lemma from_rel_prop {sym : symmetric r} {a b : α} :
⟦(a, b)⟧ ∈ from_rel sym ↔ r a b := iff.rfl
lemma from_rel_irreflexive {sym : symmetric r} :
irreflexive r ↔ ∀ {z}, z ∈ from_rel sym → ¬is_diag z :=
{ mp := λ h, sym2.ind $ by { rintros a b hr (rfl : a = b), exact h _ hr },
mpr := λ h x hr, h (from_rel_prop.mpr hr) rfl }
lemma mem_from_rel_irrefl_other_ne {sym : symmetric r} (irrefl : irreflexive r)
{a : α} {z : sym2 α} (hz : z ∈ from_rel sym) (h : a ∈ z) : h.other ≠ a :=
mem_other_ne (from_rel_irreflexive.mp irrefl hz) h
instance from_rel.decidable_pred (sym : symmetric r) [h : decidable_rel r] :
decidable_pred (∈ sym2.from_rel sym) :=
λ z, quotient.rec_on_subsingleton z (λ x, h _ _)
end relations
section sym_equiv
/-! ### Equivalence to the second symmetric power -/
local attribute [instance] vector.perm.is_setoid
private def from_vector {α : Type*} : vector α 2 → α × α
| ⟨[a, b], h⟩ := (a, b)
private lemma perm_card_two_iff {α : Type*} {a₁ b₁ a₂ b₂ : α} :
[a₁, b₁].perm [a₂, b₂] ↔ (a₁ = a₂ ∧ b₁ = b₂) ∨ (a₁ = b₂ ∧ b₁ = a₂) :=
{ mp := by { simp [← multiset.coe_eq_coe, ← multiset.cons_coe, multiset.cons_eq_cons]; tidy },
mpr := by { intro h, cases h; rw [h.1, h.2], apply list.perm.swap', refl } }
/--
The symmetric square is equivalent to length-2 vectors up to permutations.
-/
def sym2_equiv_sym' {α : Type*} : equiv (sym2 α) (sym' α 2) :=
{ to_fun := quotient.map
(λ (x : α × α), ⟨[x.1, x.2], rfl⟩)
(by { rintros _ _ ⟨_⟩, { refl }, apply list.perm.swap', refl }),
inv_fun := quotient.map from_vector (begin
rintros ⟨x, hx⟩ ⟨y, hy⟩ h,
cases x with _ x, { simpa using hx, },
cases x with _ x, { simpa using hx, },
cases x with _ x, swap, { exfalso, simp at hx, linarith [hx] },
cases y with _ y, { simpa using hy, },
cases y with _ y, { simpa using hy, },
cases y with _ y, swap, { exfalso, simp at hy, linarith [hy] },
rcases perm_card_two_iff.mp h with ⟨rfl,rfl⟩|⟨rfl,rfl⟩, { refl },
apply sym2.rel.swap,
end),
left_inv := by tidy,
right_inv := λ x, begin
refine quotient.rec_on_subsingleton x (λ x, _),
{ cases x with x hx,
cases x with _ x, { simpa using hx, },
cases x with _ x, { simpa using hx, },
cases x with _ x, swap, { exfalso, simp at hx, linarith [hx] },
refl },
end }
/--
The symmetric square is equivalent to the second symmetric power.
-/
def equiv_sym (α : Type*) : sym2 α ≃ sym α 2 :=
equiv.trans sym2_equiv_sym' sym_equiv_sym'.symm
/--
The symmetric square is equivalent to multisets of cardinality
two. (This is currently a synonym for `equiv_sym`, but it's provided
in case the definition for `sym` changes.)
-/
def equiv_multiset (α : Type*) : sym2 α ≃ {s : multiset α // s.card = 2} :=
equiv_sym α
end sym_equiv
section decidable
/--
An algorithm for computing `sym2.rel`.
-/
def rel_bool [decidable_eq α] (x y : α × α) : bool :=
if x.1 = y.1 then x.2 = y.2 else
if x.1 = y.2 then x.2 = y.1 else ff
lemma rel_bool_spec [decidable_eq α] (x y : α × α) :
↥(rel_bool x y) ↔ rel α x y :=
begin
cases x with x₁ x₂, cases y with y₁ y₂,
dsimp [rel_bool], split_ifs;
simp only [false_iff, bool.coe_sort_ff, bool.of_to_bool_iff],
rotate 2, { contrapose! h, cases h; cc },
all_goals { subst x₁, split; intro h1,
{ subst h1; apply sym2.rel.swap },
{ cases h1; cc } }
end
/--
Given `[decidable_eq α]` and `[fintype α]`, the following instance gives `fintype (sym2 α)`.
-/
instance (α : Type*) [decidable_eq α] : decidable_rel (sym2.rel α) :=
λ x y, decidable_of_bool (rel_bool x y) (rel_bool_spec x y)
/--
A function that gives the other element of a pair given one of the elements. Used in `mem.other'`.
-/
private def pair_other [decidable_eq α] (a : α) (z : α × α) : α := if a = z.1 then z.2 else z.1
/--
Get the other element of the unordered pair using the decidable equality.
This is the computable version of `mem.other`.
-/
def mem.other' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) : α :=
quot.rec (λ x h', pair_other a x) (begin
clear h z,
intros x y h,
ext hy,
convert_to pair_other a x = _,
{ have h' : ∀ {c e h}, @eq.rec _ ⟦x⟧ (λ s, a ∈ s → α)
(λ _, pair_other a x) c e h = pair_other a x,
{ intros _ e _, subst e },
apply h', },
have h' := (rel_bool_spec x y).mpr h,
cases x with x₁ x₂, cases y with y₁ y₂,
cases mem_iff.mp hy with hy'; subst a; dsimp [rel_bool] at h';
split_ifs at h'; try { rw bool.of_to_bool_iff at h', subst x₁, subst x₂ }; dsimp [pair_other],
simp only [ne.symm h_1, if_true, eq_self_iff_true, if_false],
exfalso, exact bool.not_ff h',
simp only [h_1, if_true, eq_self_iff_true, if_false],
exfalso, exact bool.not_ff h',
end) z h
@[simp]
lemma mem_other_spec' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) :
⟦(a, h.other')⟧ = z :=
begin
induction z, cases z with x y,
have h' := mem_iff.mp h,
dsimp [mem.other', quot.rec, pair_other],
cases h'; subst a,
{ simp only [if_true, eq_self_iff_true], refl, },
{ split_ifs, subst h_1, refl, rw eq_swap, refl, },
refl,
end
@[simp]
lemma other_eq_other' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) : h.other = h.other' :=
by rw [←congr_right, mem_other_spec' h, mem_other_spec]
lemma mem_other_mem' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) :
h.other' ∈ z :=
by { rw ←other_eq_other', exact mem_other_mem h }
lemma other_invol' [decidable_eq α] {a : α} {z : sym2 α} (ha : a ∈ z) (hb : ha.other' ∈ z):
hb.other' = a :=
begin
induction z, cases z with x y,
dsimp [mem.other', quot.rec, pair_other] at hb,
split_ifs at hb; dsimp [mem.other', quot.rec, pair_other],
simp only [h, if_true, eq_self_iff_true],
split_ifs, assumption, refl,
simp only [h, if_false, if_true, eq_self_iff_true],
exact ((mem_iff.mp ha).resolve_left h).symm,
refl,
end
lemma other_invol {a : α} {z : sym2 α} (ha : a ∈ z) (hb : ha.other ∈ z):
hb.other = a :=
begin
classical,
rw other_eq_other' at hb ⊢,
convert other_invol' ha hb,
rw other_eq_other',
end
lemma filter_image_quotient_mk_is_diag [decidable_eq α] (s : finset α) :
((s.product s).image quotient.mk).filter is_diag =
s.diag.image quotient.mk :=
begin
ext z,
induction z using quotient.induction_on,
rcases z with ⟨x, y⟩,
simp only [mem_image, mem_diag, exists_prop, mem_filter, prod.exists, mem_product],
split,
{ rintro ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩,
rw [←h, sym2.is_diag_iff_eq] at hab,
exact ⟨a, b, ⟨ha, hab⟩, h⟩ },
{ rintro ⟨a, b, ⟨ha, rfl⟩, h⟩,
rw ←h,
exact ⟨⟨a, a, ⟨ha, ha⟩, rfl⟩, rfl⟩ }
end
lemma filter_image_quotient_mk_not_is_diag [decidable_eq α] (s : finset α) :
((s.product s).image quotient.mk).filter (λ a : sym2 α, ¬a.is_diag) =
s.off_diag.image quotient.mk :=
begin
ext z,
induction z using quotient.induction_on,
rcases z with ⟨x, y⟩,
simp only [mem_image, mem_off_diag, exists_prop, mem_filter, prod.exists, mem_product],
split,
{ rintro ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩,
rw [←h, sym2.is_diag_iff_eq] at hab,
exact ⟨a, b, ⟨ha, hb, hab⟩, h⟩ },
{ rintro ⟨a, b, ⟨ha, hb, hab⟩, h⟩,
rw [ne.def, ←sym2.is_diag_iff_eq, h] at hab,
exact ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩ }
end
end decidable
end sym2
|
53b0817741f08df8d96a93438e72737fdc91cd63 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/tactic/rewrite_search/search.lean | 8f3a4a029470b7143e827e12aa85036a47277c61 | [] | 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,085 | lean | /-
Copyright (c) 2020 Kevin Lacker, Keeley Hoek, Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Lacker, Keeley Hoek, Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.buffer.basic
import Mathlib.meta.rb_map
import Mathlib.tactic.rewrite_search.discovery
import Mathlib.tactic.rewrite_search.types
import Mathlib.PostPort
namespace Mathlib
/-!
# The graph algorithm part of rewrite search
`search.lean` contains the logic to do a graph search. The search algorithm
starts with an equation to prove, treats the left hand side and right hand side as
two vertices in a graph, and uses rewrite rules to find a path that connects the two sides.
-/
namespace tactic.rewrite_search
/--
An edge represents a proof that can get from one expression to another.
It represents the fact that, starting from the vertex `fr`, the expression in `proof`
can prove the vertex `to`.
`how` contains information that the explainer will use to generate Lean code for the
proof.
-/
|
1741fedcbbcc194e0bd2c6771533b8108c55ce43 | 7cdf3413c097e5d36492d12cdd07030eb991d394 | /src/game/world5/level2.lean | 2dfc37c024a8b39375761a36e91d3e8bbdc9becb | [] | no_license | alreadydone/natural_number_game | 3135b9385a9f43e74cfbf79513fc37e69b99e0b3 | 1a39e693df4f4e871eb449890d3c7715a25c2ec9 | refs/heads/master | 1,599,387,390,105 | 1,573,200,587,000 | 1,573,200,691,000 | 220,397,084 | 0 | 0 | null | 1,573,192,734,000 | 1,573,192,733,000 | null | UTF-8 | Lean | false | false | 2,705 | lean | import mynat.add -- + on mynat
import mynat.mul -- * on mynat
/- Tactic : intro
If your goal is a function `⊢ P → Q` then `intro` is often the
tactic you will use to proceed. What does it mean to define
a function? Given an arbitrary term of type `P` (or an element
of the set `P` if you think set-theoretically) you need
to come up with a term of type `Q`, so your first step is
to choose `p`, an arbitary element of `P`.
`intro p,` is Lean's way of saying "let $p\in P$ be arbitrary".
The tactic `intro p` changes
```
⊢ P → Q
```
into
```
p : P
⊢ Q
```
So `p` is an arbitrary element of `P` about which nothing is known,
and our task is to come up with an element of `Q` (which can of
course depend on `p`).
Note that the opposite of `intro` is `revert`; given a tactic
state
```
p : P
⊢ Q
```
as above, the tactic `revert p` takes us back to `⊢ P → Q`.
-/
/-
# Function world.
## Level 2 : `intro`.
Let's make a function. Let's define the function on the natural
numbers which sends a natural number $n$ to $3n+2$. If you delete the
`sorry` you will see that our goal is `mynat → mynat`. A mathematician
might denote this set with some exotic name such as
$\operatorname{Hom}(\mathbb{N},\mathbb{N})$,
but computer scientists use notation `X → Y` to denote the set of
functions from `X` to `Y` and this name definitely has its merits.
In type theory, `X → Y` is a type (the type of all functions from $X$ to $Y$),
and `f : X → Y` means that `f` is a term
of this type, i.e., $f$ is a function from $X$ to $Y$.
To define a function $X\to Y$ we need to choose an arbitrary
element $x\in X$ and then, perhaps using $x$, make an element of $Y$.
The Lean tactic for "let $x\in X$ be arbitrary" is `intro x`.
## Rule of thumb:
If your goal is `P → Q` then `intro p` will make progress.
To solve the goal below, you have to come up with a function from `mynat`
to `mynat`. Start with
`intro n,`
(i.e. "let $n\in\mathbb{N}$ be arbitrary") and note that our
local context now looks like this:
```
n : mynat
⊢ mynat
```
Our job now is to construct a natural number, which is
allowed to depend on $n$. We can do this using `exact` and
writing a formula for the function we want to define. For example
we imported addition and multiplication at the top of this file,
so
`exact 3*n+2,`
will close the goal, ultimately defining the function $f(n)=3n+2$.
-/
/- Lemma : no-side-bar
We can construct a function $\mathbb{N}\to\mathbb{N}$.
-/
lemma level2 : mynat → mynat :=
begin [less_leaky]
intro n,
exact 3*n+2,
end
-- TODO -- this is not a lemma, this is a definition. But currently
-- the framework making the game will only let me make lemmas. |
a0232dc5ec200198c98bc8a3406aec5bd45b18bd | 94e33a31faa76775069b071adea97e86e218a8ee | /src/algebra/char_p/algebra.lean | 3b4493df13e96bd7c567648e63d4f9c625b89f06 | [
"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 | 3,885 | lean | /-
Copyright (c) 2021 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster, Eric Wieser
-/
import algebra.char_p.basic
import ring_theory.localization.fraction_ring
import algebra.free_algebra
/-!
# Characteristics of algebras
In this file we describe the characteristic of `R`-algebras.
In particular we are interested in the characteristic of free algebras over `R`
and the fraction field `fraction_ring R`.
## Main results
- `char_p_of_injective_algebra_map` If `R →+* A` is an injective algebra map
then `A` has the same characteristic as `R`.
Instances constructed from this result:
- Any `free_algebra R X` has the same characteristic as `R`.
- The `fraction_ring R` of an integral domain `R` has the same characteristic as `R`.
-/
/-- If the algebra map `R →+* A` is injective then `A` has the same characteristic as `R`. -/
lemma char_p_of_injective_algebra_map {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
(h : function.injective (algebra_map R A)) (p : ℕ) [char_p R p] : char_p A p :=
{ cast_eq_zero_iff := λx,
begin
rw ←char_p.cast_eq_zero_iff R p x,
change algebra_map ℕ A x = 0 ↔ algebra_map ℕ R x = 0,
rw is_scalar_tower.algebra_map_apply ℕ R A x,
refine iff.trans _ h.eq_iff,
rw ring_hom.map_zero,
end }
lemma char_p_of_injective_algebra_map' (R A : Type*) [field R] [semiring A] [algebra R A]
[nontrivial A] (p : ℕ) [char_p R p] : char_p A p :=
char_p_of_injective_algebra_map (algebra_map R A).injective p
/-- If the algebra map `R →+* A` is injective and `R` has characteristic zero then so does `A`. -/
lemma char_zero_of_injective_algebra_map {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
(h : function.injective (algebra_map R A)) [char_zero R] : char_zero A :=
{ cast_injective := λ x y hxy,
begin
change algebra_map ℕ A x = algebra_map ℕ A y at hxy,
rw is_scalar_tower.algebra_map_apply ℕ R A x at hxy,
rw is_scalar_tower.algebra_map_apply ℕ R A y at hxy,
exact char_zero.cast_injective (h hxy),
end }
-- `char_p.char_p_to_char_zero A _ (char_p_of_injective_algebra_map h 0)` does not work
-- here as it would require `ring A`.
section
variables (K L : Type*) [field K] [comm_semiring L] [nontrivial L] [algebra K L]
lemma algebra.char_p_iff (p : ℕ) : char_p K p ↔ char_p L p :=
(algebra_map K L).char_p_iff_char_p p
end
namespace free_algebra
variables {R X : Type*} [comm_semiring R] (p : ℕ)
/-- If `R` has characteristic `p`, then so does `free_algebra R X`. -/
instance char_p [char_p R p] : char_p (free_algebra R X) p :=
char_p_of_injective_algebra_map free_algebra.algebra_map_left_inverse.injective p
/-- If `R` has characteristic `0`, then so does `free_algebra R X`. -/
instance char_zero [char_zero R] : char_zero (free_algebra R X) :=
char_zero_of_injective_algebra_map free_algebra.algebra_map_left_inverse.injective
end free_algebra
namespace is_fraction_ring
variables (R : Type*) {K : Type*} [comm_ring R]
[field K] [algebra R K] [is_fraction_ring R K]
variables (p : ℕ)
/-- If `R` has characteristic `p`, then so does Frac(R). -/
lemma char_p_of_is_fraction_ring [char_p R p] : char_p K p :=
char_p_of_injective_algebra_map (is_fraction_ring.injective R K) p
/-- If `R` has characteristic `0`, then so does Frac(R). -/
lemma char_zero_of_is_fraction_ring [char_zero R] : char_zero K :=
@char_p.char_p_to_char_zero K _ (char_p_of_is_fraction_ring R 0)
variables [is_domain R]
/-- If `R` has characteristic `p`, then so does `fraction_ring R`. -/
instance char_p [char_p R p] : char_p (fraction_ring R) p :=
char_p_of_is_fraction_ring R p
/-- If `R` has characteristic `0`, then so does `fraction_ring R`. -/
instance char_zero [char_zero R] : char_zero (fraction_ring R) :=
char_zero_of_is_fraction_ring R
end is_fraction_ring
|
f1c719313727326c0773d2622065ced9f7c40551 | 6d50885e7b3f72447a03f21d5268d6af87c0a404 | /assignments/hw7_bool_sat/hw7_sat.lean | bec24d810cfe806ac52f6fb0c230c8762b378708 | [] | no_license | kevinsullivan/uva-cs-dm-s20-old | 583c756cded281fcee7f1afc42cb3e08f89c2493 | 797672cb0ffae6a42a3518c9225d5807191fd113 | refs/heads/master | 1,607,500,914,982 | 1,578,752,991,000 | 1,578,752,991,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,231 | lean | import .prop_logic
import .bool_sat
open prop_logic
open prop_logic.var
open prop_logic.pExp
/-
An example: The 0th, 1st, and
2nd bits from the right in 100,
the binary numeral for decimal
4, are 0, 0, and 1, respectively.
-/
#eval mth_bit_from_right_in_n 2 4
/-
#1. Write and evaluate expressions
(using eval) to determine what is
the bit in the 9th position from
the right in the binary expansion
of the decimal number 8485672345?
Hint: don't use reduce here. Eval
uses hardware (machine) int values
to represent nats, while reduce
uses the unary nat representation.
Self-test: How much memory might
it take to represent the decimal
number, 8485672345, as a ℕ value
in unary?
-/
#eval _
/-
The next section presents examples
to set up test cases for definitions
to follow.
-/
/-
We define a few variables to use
in the rest of this assignment.
-/
def P : pExp:= varExp (mkVar 0)
def Q: pExp := varExp (mkVar 1)
def R : pExp := varExp (mkVar 2)
/-
We set parameter values used in
some function definitions to follow.
-/
def max_var_index := 2
def num_vars := max_var_index + 1
/-
An example of a propositional logic
expression.
-/
def theExpr : pExp := (P ⇒ (P ∧ R))
/-
An example using the truth_table_results
function to compute and return a list of
the truth values of theExpr under each of
its possible interpretations.
-/
#eval truth_table_results theExpr num_vars
/-
#2. Define interp5 to be the interpretation
in the six row (m=5) of the truth table that
our interps_for_n_vars functions returns for
our three variables (P, Q, and R).
Hint: use the mth_interp_n_vars function.
Definitely check out the definition of the
function, and any specification text, even
if informal, given with the formal definition.
-/
def interp5 := _
/-
#3. What Boolean values are assigned to
P, Q, and R by this interpretation (interp5)?
Use three #eval commands to compute answers by
evaluating each variable expressions under the
interp5 interpretation.
-/
#eval _
#eval _
#eval _
/-
#4. Write a truth table within this
comment block showing the values for
P, Q, and R, in each row in the truth
table, represented by a corresponding
valule in the list of interpretations
returned by interps_for_n_vars. Label
your columns as R, Q, and P, in that
order. (Try to understand why.)
Hint: Don't just write what you think
the answers are:, evaluate each of
the three variable expression under
each interpretation. You can use the
mth_interp_n_vars function if you want
to obtain interpretation functions for
each of the rows individually if you
want.
Answer:
-/
/-
#5. Write an expression here to
compute the "results" column of
the truth table for "theExpr" as
defined above.
-/
#eval _
/-
#6. Copy and paste the truth table
from question #4 here and extend it
with the results you just obtained.
Check the results for correctness.
Answer here:
-/
/-
#7.
Write a "predicate" function, isModel,
that takes a propositional logic
expression, e, and an interpretation,
i, as its arguments and that returns
the Boolean true (tt) value if and only
if i is a model of e (otherwise false).
-/
def isModel :pExp → (var → bool) → bool
/-
#7. Write a one-line implementation
of a function, is_valid, that takes as
its arguments a propositional expression,
e, and the number of variables, n, in its
truth table, and that returns true if and
only if it is valid, construed to mean
tha every result in the list returned by
the truth_table_results function is true.
To do so, define and use a fold function
to reduce returned lists of Boolean truth
values to single truth values. Define and
use a bool-specific function, fold_bool :
(bool → bool → bool) →
bool →
(list bool) →
bool,
where the arguments are, respectively,
a binary operator, an identity element
for that operator, and a list of bools
to be reduced to a single bool result.
-/
def fold_bool :
(bool → bool → bool) → bool → (list bool) → bool
def is_valid : pExp → ℕ → bool
/-
Write similar one-line implementations of the
functions, is_satisfiable and is_unsatisfiable,
respectively. Do not use fold (directly) in your
implementation of is_unsatisfiable.
-/
def is_satisfiable : pExp → ℕ → bool
| _ := _
def is_unsatisfiable : pExp → ℕ → bool
| _ := _
/-
8. Use your is_valid function to determine which
of the following putative valid laws of reasoning
really are valid, and which ones are not. For each
one that is not, give a real-world scenario that
shows that the rule doesn't always lead to a valid
deduction. Use #eval to evaluate the validity of
each proposition. Use -- to put a comment after
each of the following definitions indicating
either "-- valid" or "-- NOT valid".
-/
def true_intro := pTrue
def false_elim := pFalse ⇒ P
def and_intro := P ⇒ Q ⇒ (P ∧ Q)
def and_elim_left := (P ∧ Q) ⇒ P
def and_elim_right := (P ∧ Q) ⇒ Q
def or_intro_left := P ⇒ (P ∨ Q)
def or_intro_right := Q ⇒ (P ∨ Q)
def or_elim := (P ∨ Q) ⇒ (P ⇒ R) ⇒ (Q ⇒ R) ⇒ R
def iff_intro := (P ⇒ Q) ⇒ (Q ⇒ P) ⇒ (P ↔ Q)
def iff_elim_left := (P ↔ Q) ⇒ (P ⇒ Q)
def iff_elim_right := (P ↔ Q) ⇒ (Q ⇒ P)
def arrow_elim := (P ⇒ Q) ⇒ P ⇒ Q
def affirm_consequence := (P ⇒ Q) ⇒ Q ⇒ P
def resolution := (P ∨ Q) ⇒ (¬ Q ∨ R) ⇒ (P ∨ R)
def unit_resolution := (P ∨ Q) ⇒ (¬ Q) ⇒ P
def syllogism := (P ⇒ Q) ⇒ (Q ⇒ R) ⇒ (P ⇒ R)
def modus_tollens := (P ⇒ Q) ⇒ ¬ Q ⇒ ¬ P
def neg_elim := ¬ ¬ P ⇒ P
def excluded_middle := P ∨ ¬ P
def neg_intro := (P ⇒ pFalse) ⇒ ¬ P
def affirm_disjunct := (P ∨ Q) ⇒ P ⇒ ¬ Q
def deny_antecedent := (P ⇒ Q) ⇒ (¬ P ⇒ ¬ Q)
-- Answer below
example : ∃ (n : ℕ), n = 6 :=
exists.intro 6 rfl
example : (∃ (n : ℕ), n = 6) → true :=
begin
assume h,
cases h with w pf,
constructor,
end
axiom Person : Type
axiom Nice : Person → Prop
axiom Tall : Person → Prop
example : (∃ (p : Person), Nice p ∧ Tall p) →
∃ (q : Person), Tall q :=
λ h,
match h with
| exists.intro w pf := exists.intro w pf.right
end
example : false → 0 = 1 :=
λ f,
match f with
end
|
6f7c08d3fda017398041e383660e80936ff00b55 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/finsupp/order.lean | b5aa762727bc9421c17e0bb18b7b54cdbfc523d9 | [
"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 | 7,936 | lean | /-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Aaron Anderson
-/
import data.finsupp.defs
/-!
# Pointwise order on finitely supported functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file lifts order structures on `α` to `ι →₀ α`.
## Main declarations
* `finsupp.order_embedding_to_fun`: The order embedding from finitely supported functions to
functions.
* `finsupp.order_iso_multiset`: The order isomorphism between `ℕ`-valued finitely supported
functions and multisets.
-/
noncomputable theory
open_locale big_operators
open finset
variables {ι α : Type*}
namespace finsupp
/-! ### Order structures -/
section has_zero
variables [has_zero α]
section has_le
variables [has_le α]
instance : has_le (ι →₀ α) := ⟨λ f g, ∀ i, f i ≤ g i⟩
lemma le_def {f g : ι →₀ α} : f ≤ g ↔ ∀ i, f i ≤ g i := iff.rfl
/-- The order on `finsupp`s over a partial order embeds into the order on functions -/
def order_embedding_to_fun : (ι →₀ α) ↪o (ι → α) :=
{ to_fun := λ f, f,
inj' := λ f g h, finsupp.ext $ λ i, by { dsimp at h, rw h },
map_rel_iff' := λ a b, (@le_def _ _ _ _ a b).symm }
@[simp] lemma order_embedding_to_fun_apply {f : ι →₀ α} {i : ι} :
order_embedding_to_fun f i = f i := rfl
end has_le
section preorder
variables [preorder α]
instance : preorder (ι →₀ α) :=
{ le_refl := λ f i, le_rfl,
le_trans := λ f g h hfg hgh i, (hfg i).trans (hgh i),
.. finsupp.has_le }
lemma monotone_to_fun : monotone (finsupp.to_fun : (ι →₀ α) → (ι → α)) := λ f g h a, le_def.1 h a
end preorder
instance [partial_order α] : partial_order (ι →₀ α) :=
{ le_antisymm := λ f g hfg hgf, ext $ λ i, (hfg i).antisymm (hgf i),
.. finsupp.preorder }
instance [semilattice_inf α] : semilattice_inf (ι →₀ α) :=
{ inf := zip_with (⊓) inf_idem,
inf_le_left := λ f g i, inf_le_left,
inf_le_right := λ f g i, inf_le_right,
le_inf := λ f g i h1 h2 s, le_inf (h1 s) (h2 s),
..finsupp.partial_order, }
@[simp] lemma inf_apply [semilattice_inf α] {i : ι} {f g : ι →₀ α} : (f ⊓ g) i = f i ⊓ g i := rfl
instance [semilattice_sup α] : semilattice_sup (ι →₀ α) :=
{ sup := zip_with (⊔) sup_idem,
le_sup_left := λ f g i, le_sup_left,
le_sup_right := λ f g i, le_sup_right,
sup_le := λ f g h hf hg i, sup_le (hf i) (hg i),
..finsupp.partial_order }
@[simp] lemma sup_apply [semilattice_sup α] {i : ι} {f g : ι →₀ α} : (f ⊔ g) i = f i ⊔ g i := rfl
instance [lattice α] : lattice (ι →₀ α) := { ..finsupp.semilattice_inf, ..finsupp.semilattice_sup }
section lattice
variables [decidable_eq ι] [lattice α] (f g : ι →₀ α)
lemma support_inf_union_support_sup : (f ⊓ g).support ∪ (f ⊔ g).support = f.support ∪ g.support :=
coe_injective $ compl_injective $ by { ext, simp [inf_eq_and_sup_eq_iff] }
lemma support_sup_union_support_inf : (f ⊔ g).support ∪ (f ⊓ g).support = f.support ∪ g.support :=
(union_comm _ _).trans $ support_inf_union_support_sup _ _
end lattice
end has_zero
/-! ### Algebraic order structures -/
instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (ι →₀ α) :=
{ add_le_add_left := λ a b h c s, add_le_add_left (h s) (c s),
.. finsupp.add_comm_monoid, .. finsupp.partial_order }
instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_add_comm_monoid (ι →₀ α) :=
{ le_of_add_le_add_left := λ f g i h s, le_of_add_le_add_left (h s),
.. finsupp.ordered_add_comm_monoid }
instance [ordered_add_comm_monoid α] [contravariant_class α α (+) (≤)] :
contravariant_class (ι →₀ α) (ι →₀ α) (+) (≤) :=
⟨λ f g h H x, le_of_add_le_add_left $ H x⟩
section canonically_ordered_add_monoid
variables [canonically_ordered_add_monoid α]
instance : order_bot (ι →₀ α) :=
{ bot := 0,
bot_le := by simp only [le_def, coe_zero, pi.zero_apply, implies_true_iff, zero_le]}
protected lemma bot_eq_zero : (⊥ : ι →₀ α) = 0 := rfl
@[simp] lemma add_eq_zero_iff (f g : ι →₀ α) : f + g = 0 ↔ f = 0 ∧ g = 0 :=
by simp [ext_iff, forall_and_distrib]
lemma le_iff' (f g : ι →₀ α) {s : finset ι} (hf : f.support ⊆ s) : f ≤ g ↔ ∀ i ∈ s, f i ≤ g i :=
⟨λ h s hs, h s,
λ h s, by classical; exact
if H : s ∈ f.support then h s (hf H) else (not_mem_support_iff.1 H).symm ▸ zero_le (g s)⟩
lemma le_iff (f g : ι →₀ α) : f ≤ g ↔ ∀ i ∈ f.support, f i ≤ g i := le_iff' f g $ subset.refl _
instance decidable_le [decidable_rel (@has_le.le α _)] : decidable_rel (@has_le.le (ι →₀ α) _) :=
λ f g, decidable_of_iff _ (le_iff f g).symm
@[simp] lemma single_le_iff {i : ι} {x : α} {f : ι →₀ α} : single i x ≤ f ↔ x ≤ f i :=
(le_iff' _ _ support_single_subset).trans $ by simp
variables [has_sub α] [has_ordered_sub α] {f g : ι →₀ α} {i : ι} {a b : α}
/-- This is called `tsub` for truncated subtraction, to distinguish it with subtraction in an
additive group. -/
instance tsub : has_sub (ι →₀ α) := ⟨zip_with (λ m n, m - n) (tsub_self 0)⟩
instance : has_ordered_sub (ι →₀ α) := ⟨λ n m k, forall_congr $ λ x, tsub_le_iff_right⟩
instance : canonically_ordered_add_monoid (ι →₀ α) :=
{ exists_add_of_le := λ f g h, ⟨g - f, ext $ λ x, (add_tsub_cancel_of_le $ h x).symm⟩,
le_self_add := λ f g x, le_self_add,
.. finsupp.order_bot,
.. finsupp.ordered_add_comm_monoid }
@[simp] lemma coe_tsub (f g : ι →₀ α) : ⇑(f - g) = f - g := rfl
lemma tsub_apply (f g : ι →₀ α) (a : ι) : (f - g) a = f a - g a := rfl
@[simp] lemma single_tsub : single i (a - b) = single i a - single i b :=
begin
ext j,
obtain rfl | h := eq_or_ne i j,
{ rw [tsub_apply, single_eq_same, single_eq_same, single_eq_same] },
{ rw [tsub_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, tsub_self] }
end
lemma support_tsub {f1 f2 : ι →₀ α} : (f1 - f2).support ⊆ f1.support :=
by simp only [subset_iff, tsub_eq_zero_iff_le, mem_support_iff, ne.def, coe_tsub, pi.sub_apply,
not_imp_not, zero_le, implies_true_iff] {contextual := tt}
lemma subset_support_tsub [decidable_eq ι] {f1 f2 : ι →₀ α} :
f1.support \ f2.support ⊆ (f1 - f2).support :=
by simp [subset_iff] {contextual := tt}
end canonically_ordered_add_monoid
section canonically_linear_ordered_add_monoid
variables [canonically_linear_ordered_add_monoid α]
@[simp] lemma support_inf [decidable_eq ι] (f g : ι →₀ α) :
(f ⊓ g).support = f.support ∩ g.support :=
begin
ext,
simp only [inf_apply, mem_support_iff, ne.def,
finset.mem_union, finset.mem_filter, finset.mem_inter],
simp only [inf_eq_min, ←nonpos_iff_eq_zero, min_le_iff, not_or_distrib],
end
@[simp] lemma support_sup [decidable_eq ι] (f g : ι →₀ α) :
(f ⊔ g).support = f.support ∪ g.support :=
begin
ext,
simp only [finset.mem_union, mem_support_iff, sup_apply, ne.def, ←bot_eq_zero],
rw [_root_.sup_eq_bot_iff, not_and_distrib],
end
lemma disjoint_iff {f g : ι →₀ α} : disjoint f g ↔ disjoint f.support g.support :=
begin
classical,
rw [disjoint_iff, disjoint_iff, finsupp.bot_eq_zero, ← finsupp.support_eq_empty,
finsupp.support_inf],
refl,
end
end canonically_linear_ordered_add_monoid
/-! ### Some lemmas about `ℕ` -/
section nat
lemma sub_single_one_add {a : ι} {u u' : ι →₀ ℕ} (h : u a ≠ 0) :
u - single a 1 + u' = u + u' - single a 1 :=
tsub_add_eq_add_tsub $ single_le_iff.mpr $ nat.one_le_iff_ne_zero.mpr h
lemma add_sub_single_one {a : ι} {u u' : ι →₀ ℕ} (h : u' a ≠ 0) :
u + (u' - single a 1) = u + u' - single a 1 :=
(add_tsub_assoc_of_le (single_le_iff.mpr $ nat.one_le_iff_ne_zero.mpr h) _).symm
end nat
end finsupp
|
b814fe432f642481955191ac4932e6d69655a29d | 367134ba5a65885e863bdc4507601606690974c1 | /src/tactic/converter/binders.lean | fa4861296469db893134ed5d2a02507af48d6f58 | [
"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 | 7,438 | 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
Binder elimination
-/
import order
namespace old_conv
open tactic monad
meta instance : monad_fail old_conv :=
{ fail := λ α s, (λr e, tactic.fail (to_fmt s) : old_conv α), ..old_conv.monad }
meta instance : has_monad_lift tactic old_conv :=
⟨λα, lift_tactic⟩
meta instance (α : Type) : has_coe (tactic α) (old_conv α) :=
⟨monad_lift⟩
meta def current_relation : old_conv name := λr lhs, return ⟨r, lhs, none⟩
meta def head_beta : old_conv unit :=
λ r e, do n ← tactic.head_beta e, return ⟨(), n, none⟩
/- congr should forward data! -/
meta def congr_arg : old_conv unit → old_conv unit := congr_core (return ())
meta def congr_fun : old_conv unit → old_conv unit := λc, congr_core c (return ())
meta def congr_rule (congr : expr) (cs : list (list expr → old_conv unit)) : old_conv unit := λr lhs, do
meta_rhs ← infer_type lhs >>= mk_meta_var, -- is maybe overly restricted for `heq`
t ← mk_app r [lhs, meta_rhs],
((), meta_pr) ← solve_aux t (do
apply congr,
focus $ cs.map $ λc, (do
xs ← intros,
conversion (head_beta >> c xs)),
done),
rhs ← instantiate_mvars meta_rhs,
pr ← instantiate_mvars meta_pr,
return ⟨(), rhs, some pr⟩
meta def congr_binder (congr : name) (cs : expr → old_conv unit) : old_conv unit := do
e ← mk_const congr,
congr_rule e [λbs, do [b] ← return bs, cs b]
meta def funext' : (expr → old_conv unit) → old_conv unit := congr_binder ``_root_.funext
meta def propext' {α : Type} (c : old_conv α) : old_conv α := λr lhs, (do
guard (r = `iff),
c r lhs)
<|> (do
guard (r = `eq),
⟨res, rhs, pr⟩ ← c `iff lhs,
match pr with
| some pr := return ⟨res, rhs, (expr.const `propext [] : expr) lhs rhs pr⟩
| none := return ⟨res, rhs, none⟩
end)
meta def apply (pr : expr) : old_conv unit :=
λ r e, do
sl ← simp_lemmas.mk.add pr,
apply_lemmas sl r e
meta def applyc (n : name) : old_conv unit :=
λ r e, do
sl ← simp_lemmas.mk.add_simp n,
apply_lemmas sl r e
meta def apply' (n : name) : old_conv unit := do
e ← mk_const n,
congr_rule e []
end old_conv
open expr tactic old_conv
/- Binder elimination:
We assume a binder `B : p → Π (α : Sort u), (α → t) → t`, where `t` is a type depending on `p`.
Examples:
∃: there is no `p` and `t` is `Prop`.
⨅, ⨆: here p is `β` and `[complete_lattice β]`, `p` is `β`
Problem: ∀x, _ should be a binder, but is not a constant!
Provide a mechanism to rewrite:
B (x : α) ..x.. (h : x = t), p x = B ..x/t.., p t
Here ..x.. are binders, maybe also some constants which provide commutativity rules with `B`.
-/
meta structure binder_eq_elim :=
(match_binder : expr → tactic (expr × expr)) -- returns the bound type and body
(adapt_rel : old_conv unit → old_conv unit) -- optionally adapt `eq` to `iff`
(apply_comm : old_conv unit) -- apply commutativity rule
(apply_congr : (expr → old_conv unit) → old_conv unit) -- apply congruence rule
(apply_elim_eq : old_conv unit) -- (B (x : β) (h : x = t), s x) = s t
meta def binder_eq_elim.check_eq (b : binder_eq_elim) (x : expr) : expr → tactic unit
| `(@eq %%β %%l %%r) := guard ((l = x ∧ ¬ x.occurs r) ∨ (r = x ∧ ¬ x.occurs l))
| _ := fail "no match"
meta def binder_eq_elim.pull (b : binder_eq_elim) (x : expr) : old_conv unit := do
(β, f) ← lhs >>= (lift_tactic ∘ b.match_binder),
guard (¬ x.occurs β)
<|> b.check_eq x β
<|> (do
b.apply_congr $ λx, binder_eq_elim.pull,
b.apply_comm)
meta def binder_eq_elim.push (b : binder_eq_elim) : old_conv unit :=
b.apply_elim_eq
<|> (do
b.apply_comm,
b.apply_congr $ λx, binder_eq_elim.push)
<|> (do
b.apply_congr $ b.pull,
binder_eq_elim.push)
meta def binder_eq_elim.check (b : binder_eq_elim) (x : expr) : expr → tactic unit
| e := do
(β, f) ← b.match_binder e,
b.check_eq x β
<|> (do
(lam n bi d bd) ← return f,
x ← mk_local' n bi d,
binder_eq_elim.check $ bd.instantiate_var x)
meta def binder_eq_elim.old_conv (b : binder_eq_elim) : old_conv unit := do
(β, f) ← lhs >>= (lift_tactic ∘ b.match_binder),
(lam n bi d bd) ← return f,
x ← mk_local' n bi d,
b.check x (bd.instantiate_var x),
b.adapt_rel b.push
theorem {u v} exists_elim_eq_left {α : Sort u} (a : α) (p : Π(a':α), a' = a → Prop) :
(∃(a':α)(h : a' = a), p a' h) ↔ p a rfl :=
⟨λ⟨a', ⟨h, p_h⟩⟩, match a', h, p_h with ._, rfl, h := h end, λh, ⟨a, rfl, h⟩⟩
theorem {u v} exists_elim_eq_right {α : Sort u} (a : α) (p : Π(a':α), a = a' → Prop) :
(∃(a':α)(h : a = a'), p a' h) ↔ p a rfl :=
⟨λ⟨a', ⟨h, p_h⟩⟩, match a', h, p_h with ._, rfl, h := h end, λh, ⟨a, rfl, h⟩⟩
meta def exists_eq_elim : binder_eq_elim :=
{ match_binder := λe, (do `(@Exists %%β %%f) ← return e, return (β, f)),
adapt_rel := propext',
apply_comm := applyc ``exists_comm,
apply_congr := congr_binder ``exists_congr,
apply_elim_eq := apply' ``exists_elim_eq_left <|> apply' ``exists_elim_eq_right }
theorem {u v} forall_comm {α : Sort u} {β : Sort v} (p : α → β → Prop) :
(∀a b, p a b) ↔ (∀b a, p a b) :=
⟨assume h b a, h a b, assume h b a, h a b⟩
theorem {u v} forall_elim_eq_left {α : Sort u} (a : α) (p : Π(a':α), a' = a → Prop) :
(∀(a':α)(h : a' = a), p a' h) ↔ p a rfl :=
⟨λh, h a rfl, λh a' h_eq, match a', h_eq with ._, rfl := h end⟩
theorem {u v} forall_elim_eq_right {α : Sort u} (a : α) (p : Π(a':α), a = a' → Prop) :
(∀(a':α)(h : a = a'), p a' h) ↔ p a rfl :=
⟨λh, h a rfl, λh a' h_eq, match a', h_eq with ._, rfl := h end⟩
meta def forall_eq_elim : binder_eq_elim :=
{ match_binder := λe, (do (expr.pi n bi d bd) ← return e, return (d, expr.lam n bi d bd)),
adapt_rel := propext',
apply_comm := applyc ``forall_comm,
apply_congr := congr_binder ``forall_congr,
apply_elim_eq := apply' ``forall_elim_eq_left <|> apply' ``forall_elim_eq_right }
meta def supr_eq_elim : binder_eq_elim :=
{ match_binder := λe, (do `(@supr %%α %%cl %%β %%f) ← return e, return (β, f)),
adapt_rel := λc, (do r ← current_relation, guard (r = `eq), c),
apply_comm := applyc ``supr_comm,
apply_congr := congr_arg ∘ funext',
apply_elim_eq := applyc ``supr_supr_eq_left <|> applyc ``supr_supr_eq_right }
meta def infi_eq_elim : binder_eq_elim :=
{ match_binder := λe, (do `(@infi %%α %%cl %%β %%f) ← return e, return (β, f)),
adapt_rel := λc, (do r ← current_relation, guard (r = `eq), c),
apply_comm := applyc ``infi_comm,
apply_congr := congr_arg ∘ funext',
apply_elim_eq := applyc ``infi_infi_eq_left <|> applyc ``infi_infi_eq_right }
universes u v w w₂
variables {α : Type u} {β : Type v} {ι : Sort w} {ι₂ : Sort w₂} {s t : set α} {a : α}
section
variables [complete_lattice α]
example {s : set β} {f : β → α} : Inf (set.image f s) = (⨅ a ∈ s, f a) :=
begin
simp [Inf_eq_infi, infi_and],
conversion infi_eq_elim.old_conv,
end
example {s : set β} {f : β → α} : Sup (set.image f s) = (⨆ a ∈ s, f a) :=
begin
simp [Sup_eq_supr, supr_and],
conversion supr_eq_elim.old_conv,
end
end
|
8d5f4ab4cbc09ba1c8c80f43d3365ee8c8438239 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/tactic/lint/basic.lean | 6bd3aabfc60762205074df81c9980ad29620e64b | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 4,180 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Robert Y. Lewis, Gabriel Ebner
-/
import tactic.core
/-!
# Basic linter types and attributes
This file defines the basic types and attributes used by the linting
framework. A linter essentially consists of a function
`declaration → tactic (option string)`, this function together with some
metadata is stored in the `linter` structure. We define two attributes:
* `@[linter]` applies to a declaration of type `linter` and adds it to the default linter set.
* `@[nolint linter_name]` omits the tagged declaration from being checked by
the linter with name `linter_name`.
-/
open tactic
setup_tactic_parser
-- Manual constant subexpression elimination for performance.
private meta def linter_ns := `linter
private meta def nolint_infix := `_nolint
/--
Computes the declaration name used to store the nolint attribute data.
Retrieving the parameters for user attributes is *extremely* slow.
Hence we store the parameters of the nolint attribute as declarations
in the environment. E.g. for `@[nolint foo] def bar := _` we add the
following declaration:
```lean
meta def bar._nolint.foo : unit := ()
```
-/
private meta def mk_nolint_decl_name (decl : name) (linter : name) : name :=
(decl ++ nolint_infix) ++ linter
/-- Defines the user attribute `nolint` for skipping `#lint` -/
@[user_attribute]
meta def nolint_attr : user_attribute _ (list name) :=
{ name := "nolint",
descr := "Do not report this declaration in any of the tests of `#lint`",
after_set := some $ λ n _ _, (do
ls@(_::_) ← nolint_attr.get_param n
| fail "you need to specify at least one linter to disable",
ls.mmap' $ λ l, do
get_decl (linter_ns ++ l) <|> fail ("unknown linter: " ++ to_string l),
try $ add_decl $ declaration.defn (mk_nolint_decl_name n l) []
`(unit) `(unit.star) (default _) ff),
parser := ident* }
add_tactic_doc
{ name := "nolint",
category := doc_category.attr,
decl_names := [`nolint_attr],
tags := ["linting"] }
/-- `should_be_linted linter decl` returns true if `decl` should be checked
using `linter`, i.e., if there is no `nolint` attribute. -/
meta def should_be_linted (linter : name) (decl : name) : tactic bool := do
e ← get_env,
pure $ ¬ e.contains (mk_nolint_decl_name decl linter)
/--
A linting test for the `#lint` command.
`test` defines a test to perform on every declaration. It should never fail. Returning `none`
signifies a passing test. Returning `some msg` reports a failing test with error `msg`.
`no_errors_found` is the message printed when all tests are negative, and `errors_found` is printed
when at least one test is positive.
If `is_fast` is false, this test will be omitted from `#lint-`.
If `auto_decls` is true, this test will also be executed on automatically generated declarations.
-/
meta structure linter :=
(test : declaration → tactic (option string))
(no_errors_found : string)
(errors_found : string)
(is_fast : bool := tt)
(auto_decls : bool := ff)
/-- Takes a list of names that resolve to declarations of type `linter`,
and produces a list of linters. -/
meta def get_linters (l : list name) : tactic (list (name × linter)) :=
l.mmap (λ n, prod.mk n.last <$> (mk_const n >>= eval_expr linter)
<|> fail format!"invalid linter: {n}")
/-- Defines the user attribute `linter` for adding a linter to the default set.
Linters should be defined in the `linter` namespace.
A linter `linter.my_new_linter` is referred to as `my_new_linter` (without the `linter` namespace)
when used in `#lint`.
-/
@[user_attribute]
meta def linter_attr : user_attribute unit unit :=
{ name := "linter",
descr := "Use this declaration as a linting test in #lint",
after_set := some $ λ nm _ _,
mk_const nm >>= infer_type >>= unify `(linter) }
add_tactic_doc
{ name := "linter",
category := doc_category.attr,
decl_names := [`linter_attr],
tags := ["linting"] }
|
a512a4687736daa54b1f9f535ba27981f16be329 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/check_tac.lean | 94ad297445c5242247613fa2915e06f5910d652c | [
"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 | 246 | lean | open tactic
example (a b : nat) : true :=
begin
type_check a + 1,
(do let e : expr := expr.const `bor [],
let one : expr := `(1 : nat),
let t := e one one,
trace t,
fail_if_success (type_check t)),
constructor
end
|
779ed1545e827342a07eab42b3caf67023263e88 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/calculus/parametric_integral.lean | 7e34171961cc18ff8d8ab10f999a87f2ac804cbc | [
"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 | 15,445 | lean | /-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import measure_theory.integral.set_integral
import analysis.calculus.mean_value
/-!
# Derivatives of integrals depending on parameters
A parametric integral is a function with shape `f = λ x : H, ∫ a : α, F x a ∂μ` for some
`F : H → α → E`, where `H` and `E` are normed spaces and `α` is a measured space with measure `μ`.
We already know from `continuous_of_dominated` in `measure_theory.integral.bochner` how to
guarantee that `f` is continuous using the dominated convergence theorem. In this file,
we want to express the derivative of `f` as the integral of the derivative of `F` with respect
to `x`.
## Main results
As explained above, all results express the derivative of a parametric integral as the integral of
a derivative. The variations come from the assumptions and from the different ways of expressing
derivative, especially Fréchet derivatives vs elementary derivative of function of one real
variable.
* `has_fderiv_at_integral_of_dominated_loc_of_lip`: this version assumes that
- `F x` is ae-measurable for x near `x₀`,
- `F x₀` is integrable,
- `λ x, F x a` has derivative `F' a : H →L[ℝ] E` at `x₀` which is ae-measurable,
- `λ x, F x a` is locally Lipschitz near `x₀` for almost every `a`, with a Lipschitz bound which
is integrable with respect to `a`.
A subtle point is that the "near x₀" in the last condition has to be uniform in `a`. This is
controlled by a positive number `ε`.
* `has_fderiv_at_integral_of_dominated_of_fderiv_le`: this version assume `λ x, F x a` has
derivative `F' x a` for `x` near `x₀` and `F' x` is bounded by an integrable function independent
from `x` near `x₀`.
`has_deriv_at_integral_of_dominated_loc_of_lip` and
`has_deriv_at_integral_of_dominated_loc_of_deriv_le` are versions of the above two results that
assume `H = ℝ` or `H = ℂ` and use the high-school derivative `deriv` instead of Fréchet derivative
`fderiv`.
We also provide versions of these theorems for set integrals.
## Tags
integral, derivative
-/
noncomputable theory
open topological_space measure_theory filter metric
open_locale topological_space filter
variables {α : Type*} [measurable_space α] {μ : measure α} {𝕜 : Type*} [is_R_or_C 𝕜]
{E : Type*} [normed_group E] [normed_space ℝ E] [normed_space 𝕜 E]
[complete_space E] [second_countable_topology E]
[measurable_space E] [borel_space E]
{H : Type*} [normed_group H] [normed_space 𝕜 H] [second_countable_topology $ H →L[𝕜] E]
/-- Differentiation under integral of `x ↦ ∫ F x a` at a given point `x₀`, assuming `F x₀` is
integrable, `∥F x a - F x₀ a∥ ≤ bound a * ∥x - x₀∥` for `x` in a ball around `x₀` for ae `a` with
integrable Lipschitz bound `bound` (with a ball radius independent of `a`), and `F x` is
ae-measurable for `x` in the same ball. See `has_fderiv_at_integral_of_dominated_loc_of_lip` for a
slightly less general but usually more useful version. -/
lemma has_fderiv_at_integral_of_dominated_loc_of_lip' {F : H → α → E} {F' : α → (H →L[𝕜] E)}
{x₀ : H} {bound : α → ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ x ∈ ball x₀ ε, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable F' μ)
(h_lipsch : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, ∥F x a - F x₀ a∥ ≤ bound a * ∥x - x₀∥)
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, has_fderiv_at (λ x, F x a) (F' a) x₀) :
integrable F' μ ∧ has_fderiv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' a ∂μ) x₀ :=
begin
letI : measurable_space 𝕜 := borel 𝕜, haveI : opens_measurable_space 𝕜 := ⟨le_rfl⟩,
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos,
have nneg : ∀ x, 0 ≤ ∥x - x₀∥⁻¹ := λ x, inv_nonneg.mpr (norm_nonneg _) ,
set b : α → ℝ := λ a, |bound a|,
have b_int : integrable b μ := bound_integrable.norm,
have b_nonneg : ∀ a, 0 ≤ b a := λ a, abs_nonneg _,
replace h_lipsch : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, ∥F x a - F x₀ a∥ ≤ b a * ∥x - x₀∥,
from h_lipsch.mono (λ a ha x hx, (ha x hx).trans $
mul_le_mul_of_nonneg_right (le_abs_self _) (norm_nonneg _)),
have hF_int' : ∀ x ∈ ball x₀ ε, integrable (F x) μ,
{ intros x x_in,
have : ∀ᵐ a ∂μ, ∥F x₀ a - F x a∥ ≤ ε * b a,
{ simp only [norm_sub_rev (F x₀ _)],
refine h_lipsch.mono (λ a ha, (ha x x_in).trans _),
rw mul_comm ε,
rw [mem_ball, dist_eq_norm] at x_in,
exact mul_le_mul_of_nonneg_left x_in.le (b_nonneg _) },
exact integrable_of_norm_sub_le (hF_meas x x_in) hF_int
(integrable.const_mul bound_integrable.norm ε) this },
have hF'_int : integrable F' μ,
{ have : ∀ᵐ a ∂μ, ∥F' a∥ ≤ b a,
{ apply (h_diff.and h_lipsch).mono,
rintros a ⟨ha_diff, ha_lip⟩,
refine ha_diff.le_of_lip' (b_nonneg a) (mem_of_superset (ball_mem_nhds _ ε_pos) $ ha_lip) },
exact b_int.mono' hF'_meas this },
refine ⟨hF'_int, _⟩,
have h_ball: ball x₀ ε ∈ 𝓝 x₀ := ball_mem_nhds x₀ ε_pos,
have : ∀ᶠ x in 𝓝 x₀,
∥x - x₀∥⁻¹ * ∥∫ a, F x a ∂μ - ∫ a, F x₀ a ∂μ - (∫ a, F' a ∂μ) (x - x₀)∥ =
∥∫ a, ∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀)) ∂μ∥,
{ apply mem_of_superset (ball_mem_nhds _ ε_pos),
intros x x_in,
rw [set.mem_set_of_eq, ← norm_smul_of_nonneg (nneg _), integral_smul,
integral_sub, integral_sub, ← continuous_linear_map.integral_apply hF'_int],
exacts [hF_int' x x_in, hF_int, (hF_int' x x_in).sub hF_int,
hF'_int.apply_continuous_linear_map _] },
rw [has_fderiv_at_iff_tendsto, tendsto_congr' this, ← tendsto_zero_iff_norm_tendsto_zero,
← show ∫ (a : α), ∥x₀ - x₀∥⁻¹ • (F x₀ a - F x₀ a - (F' a) (x₀ - x₀)) ∂μ = 0, by simp],
apply tendsto_integral_filter_of_dominated_convergence,
{ filter_upwards [h_ball] with _ x_in,
apply ae_measurable.const_smul,
exact ((hF_meas _ x_in).sub (hF_meas _ x₀_in)).sub (hF'_meas.apply_continuous_linear_map _) },
{ apply mem_of_superset h_ball,
intros x hx,
apply (h_diff.and h_lipsch).mono,
rintros a ⟨ha_deriv, ha_bound⟩,
show ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))∥ ≤ b a + ∥F' a∥,
replace ha_bound : ∥F x a - F x₀ a∥ ≤ b a * ∥x - x₀∥ := ha_bound x hx,
calc ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))∥
= ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a) - ∥x - x₀∥⁻¹ • F' a (x - x₀)∥ : by rw smul_sub
... ≤ ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a)∥ + ∥∥x - x₀∥⁻¹ • F' a (x - x₀)∥ : norm_sub_le _ _
... = ∥x - x₀∥⁻¹ * ∥F x a - F x₀ a∥ + ∥x - x₀∥⁻¹ * ∥F' a (x - x₀)∥ :
by { rw [norm_smul_of_nonneg, norm_smul_of_nonneg] ; exact nneg _}
... ≤ ∥x - x₀∥⁻¹ * (b a * ∥x - x₀∥) + ∥x - x₀∥⁻¹ * (∥F' a∥ * ∥x - x₀∥) : add_le_add _ _
... ≤ b a + ∥F' a∥ : _,
exact mul_le_mul_of_nonneg_left ha_bound (nneg _),
apply mul_le_mul_of_nonneg_left ((F' a).le_op_norm _) (nneg _),
by_cases h : ∥x - x₀∥ = 0,
{ simpa [h] using add_nonneg (b_nonneg a) (norm_nonneg (F' a)) },
{ field_simp [h] } },
{ exact b_int.add hF'_int.norm },
{ apply h_diff.mono,
intros a ha,
suffices : tendsto (λ x, ∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))) (𝓝 x₀) (𝓝 0),
by simpa,
rw tendsto_zero_iff_norm_tendsto_zero,
have : (λ x, ∥x - x₀∥⁻¹ * ∥F x a - F x₀ a - F' a (x - x₀)∥) =
λ x, ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))∥,
{ ext x,
rw norm_smul_of_nonneg (nneg _) },
rwa [has_fderiv_at_iff_tendsto, this] at ha },
end
/-- Differentiation under integral of `x ↦ ∫ F x a` at a given point `x₀`, assuming
`F x₀` is integrable, `x ↦ F x a` is locally Lipschitz on a ball around `x₀` for ae `a`
(with a ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is ae-measurable
for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_fderiv_at_integral_of_dominated_loc_of_lip {F : H → α → E} {F' : α → (H →L[𝕜] E)} {x₀ : H}
{bound : α → ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable F' μ)
(h_lip : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs $ bound a) (λ x, F x a) (ball x₀ ε))
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, has_fderiv_at (λ x, F x a) (F' a) x₀) :
integrable F' μ ∧ has_fderiv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' a ∂μ) x₀ :=
begin
obtain ⟨δ, δ_pos, hδ⟩ : ∃ δ > 0, ∀ x ∈ ball x₀ δ, ae_measurable (F x) μ ∧ x ∈ ball x₀ ε,
from eventually_nhds_iff_ball.mp (hF_meas.and (ball_mem_nhds x₀ ε_pos)),
choose hδ_meas hδε using hδ,
replace h_lip : ∀ᵐ (a : α) ∂μ, ∀ x ∈ ball x₀ δ, ∥F x a - F x₀ a∥ ≤ |bound a| * ∥x - x₀∥,
from h_lip.mono (λ a lip x hx, lip.norm_sub_le (hδε x hx) (mem_ball_self ε_pos)),
replace bound_integrable := bound_integrable.norm,
apply has_fderiv_at_integral_of_dominated_loc_of_lip' δ_pos; assumption
end
/-- Differentiation under integral of `x ↦ ∫ F x a` at a given point `x₀`, assuming
`F x₀` is integrable, `x ↦ F x a` is differentiable on a ball around `x₀` for ae `a` with
derivative norm uniformly bounded by an integrable function (the ball radius is independent of `a`),
and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_fderiv_at_integral_of_dominated_of_fderiv_le {F : H → α → E} {F' : H → α → (H →L[𝕜] E)}
{x₀ : H} {bound : α → ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable (F' x₀) μ)
(h_bound : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, ∥F' x a∥ ≤ bound a)
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, has_fderiv_at (λ x, F x a) (F' x a) x) :
has_fderiv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' x₀ a ∂μ) x₀ :=
begin
letI : normed_space ℝ H := normed_space.restrict_scalars ℝ 𝕜 H,
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos,
have diff_x₀ : ∀ᵐ a ∂μ, has_fderiv_at (λ x, F x a) (F' x₀ a) x₀ :=
h_diff.mono (λ a ha, ha x₀ x₀_in),
have : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs (bound a)) (λ x, F x a) (ball x₀ ε),
{ apply (h_diff.and h_bound).mono,
rintros a ⟨ha_deriv, ha_bound⟩,
refine (convex_ball _ _).lipschitz_on_with_of_nnnorm_has_fderiv_within_le
(λ x x_in, (ha_deriv x x_in).has_fderiv_within_at) (λ x x_in, _),
rw [← nnreal.coe_le_coe, coe_nnnorm, real.coe_nnabs],
exact (ha_bound x x_in).trans (le_abs_self _) },
exact (has_fderiv_at_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int
hF'_meas this bound_integrable diff_x₀).2
end
/-- Derivative under integral of `x ↦ ∫ F x a` at a given point `x₀ : 𝕜`, `𝕜 = ℝ` or `𝕜 = ℂ`,
assuming `F x₀` is integrable, `x ↦ F x a` is locally Lipschitz on a ball around `x₀` for ae `a`
(with ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is
ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_deriv_at_integral_of_dominated_loc_of_lip {F : 𝕜 → α → E} {F' : α → E} {x₀ : 𝕜}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable F' μ) {bound : α → ℝ}
(h_lipsch : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs $ bound a) (λ x, F x a) (ball x₀ ε))
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, has_deriv_at (λ x, F x a) (F' a) x₀) :
(integrable F' μ) ∧ has_deriv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' a ∂μ) x₀ :=
begin
letI : measurable_space 𝕜 := borel 𝕜, haveI : opens_measurable_space 𝕜 := ⟨le_rfl⟩,
set L : E →L[𝕜] (𝕜 →L[𝕜] E) := (continuous_linear_map.smul_rightL 𝕜 𝕜 E 1),
replace h_diff : ∀ᵐ a ∂μ, has_fderiv_at (λ x, F x a) (L (F' a)) x₀ :=
h_diff.mono (λ x hx, hx.has_fderiv_at),
have hm : ae_measurable (L ∘ F') μ := L.continuous.measurable.comp_ae_measurable hF'_meas,
cases has_fderiv_at_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hm h_lipsch
bound_integrable h_diff with hF'_int key,
replace hF'_int : integrable F' μ,
{ rw [← integrable_norm_iff hm] at hF'_int,
simpa only [L, (∘), integrable_norm_iff, hF'_meas, one_mul, norm_one,
continuous_linear_map.comp_apply, continuous_linear_map.coe_restrict_scalarsL',
continuous_linear_map.norm_restrict_scalars, continuous_linear_map.norm_smul_rightL_apply]
using hF'_int },
refine ⟨hF'_int, _⟩,
simp_rw has_deriv_at_iff_has_fderiv_at at h_diff ⊢,
rwa continuous_linear_map.integral_comp_comm _ hF'_int at key,
all_goals { apply_instance, },
end
/-- Derivative under integral of `x ↦ ∫ F x a` at a given point `x₀ : ℝ`, assuming
`F x₀` is integrable, `x ↦ F x a` is differentiable on an interval around `x₀` for ae `a`
(with interval radius independent of `a`) with derivative uniformly bounded by an integrable
function, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_deriv_at_integral_of_dominated_loc_of_deriv_le {F : 𝕜 → α → E} {F' : 𝕜 → α → E} {x₀ : 𝕜}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable (F' x₀) μ)
{bound : α → ℝ}
(h_bound : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, ∥F' x a∥ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_diff : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, has_deriv_at (λ x, F x a) (F' x a) x) :
(integrable (F' x₀) μ) ∧ has_deriv_at (λn, ∫ a, F n a ∂μ) (∫ a, F' x₀ a ∂μ) x₀ :=
begin
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos,
have diff_x₀ : ∀ᵐ a ∂μ, has_deriv_at (λ x, F x a) (F' x₀ a) x₀ :=
h_diff.mono (λ a ha, ha x₀ x₀_in),
have : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs (bound a)) (λ (x : 𝕜), F x a) (ball x₀ ε),
{ apply (h_diff.and h_bound).mono,
rintros a ⟨ha_deriv, ha_bound⟩,
refine (convex_ball _ _).lipschitz_on_with_of_nnnorm_has_deriv_within_le
(λ x x_in, (ha_deriv x x_in).has_deriv_within_at) (λ x x_in, _),
rw [← nnreal.coe_le_coe, coe_nnnorm, real.coe_nnabs],
exact (ha_bound x x_in).trans (le_abs_self _) },
exact has_deriv_at_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas this
bound_integrable diff_x₀
end
|
169882db00549044e0a7da3fb41c5611b2fcede7 | 682dc1c167e5900ba3168b89700ae1cf501cfa29 | /src/del/announcements.lean | 5bb467e8be798d137d1baa9bf561c9b9826c737c | [] | no_license | paulaneeley/modal | 834558c87f55cdd6d8a29bb46c12f4d1de3239bc | ee5d149d4ecb337005b850bddf4453e56a5daf04 | refs/heads/master | 1,675,911,819,093 | 1,609,785,144,000 | 1,609,785,144,000 | 270,388,715 | 13 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 11,872 | lean | /-
Copyright (c) 2021 Paula Neeley. All rights reserved.
Author: Paula Neeley
Following the textbook "Dynamic Epistemic Logic" by
Hans van Ditmarsch, Wiebe van der Hoek, and Barteld Kooi
-/
import del.languageDEL del.semantics.semanticsDEL
import data.set.basic data.equiv.basic
local attribute [instance] classical.prop_decidable
variable {agents : Type}
---------------------- Facts about Announcements ----------------------
-- Proposition 4.10, pg. 77
lemma functional_announce (φ ψ : formPA agents) :
F_validPA ((¬(U φ (¬ψ))) ⊃ (U φ ψ)) equiv_class :=
begin
intros f h v x h1,
rw forces_update_dual at h1,
cases h1 with Ph1 h1, intro h, exact h1
end
-- Proposition 4.11, pg. 77
lemma partial_announce (φ ψ : formPA agents) :
¬ (F_validPA ¬(U φ ¬⊥)) equiv_class :=
begin
rw F_validPA,
push_neg,
let f : frame agents :=
{ states := nat,
h := ⟨0⟩,
rel := λ a, λ x y : nat, x = y
},
use f, split, intro a,
split, intro x,
exact eq.refl x,
split, intros x y h,
exact eq.symm h,
intros x y z h1 h2,
exact eq.trans h1 h2,
let v : nat → f.states → Prop := λ n x, false,
use v,
let x : f.states := 42,
use x, rw forcesPA, rw not_imp,
split, intro h, intro h1, exact h1,
rw forcesPA, trivial
end
--Proposition 4.22
lemma public_annouce_var (φ : formPA agents) (f : frame agents)
(v : nat → f.states → Prop) (x : f.states) (n : ℕ) :
forcesPA f v x (U φ p n) ↔ forcesPA f v x (φ ⊃ (p n)) :=
begin
split, repeat {intros h1 h2, exact h1 h2},
end
lemma public_annouce_conj (φ ψ χ : formPA agents) (f : frame agents)
(v : nat → f.states → Prop) (x : f.states) :
forcesPA f v x (U φ (ψ & χ)) ↔ forcesPA f v x ((U φ ψ) & (U φ χ)) :=
begin
split,
intro h1,
split,
intro h2,
exact (h1 h2).left,
intro h2,
exact (h1 h2).right,
intros h1 h2,
split,
exact h1.left h2,
exact h1.right h2,
end
-- Proposition 4.12, pg. 77
lemma public_announce_neg (φ ψ : formPA agents) (f : frame agents)
(v : nat → f.states → Prop) (x : f.states) :
forcesPA f v x (U φ (¬ψ)) ↔ forcesPA f v x (φ ⊃ ¬(U φ ψ)) :=
begin
split,
intros h1 h2 h3, specialize h1 h2,
rw ←not_forces_impPA at h1,
exact absurd (h3 h2) h1,
intros h1, rw forcesPA at h1, rw imp_iff_not_or at h1,
cases h1,
intro h2, exact absurd h2 h1,
intros h h2, apply h1, intro h3, exact h2
end
-- Proposition 4.18, pg. 79
lemma public_announce_know (φ ψ : formPA agents) (f : frame agents)
(v : nat → f.states → Prop) (s : f.states) (a : agents) :
forcesPA f v s (U φ (K a ψ)) ↔ forcesPA f v s (φ ⊃ (K a (U φ ψ))) :=
begin
split,
intros h1 h2 t hrel h3,
exact h1 h2 ⟨t, h3⟩ hrel,
rintros h1 h2 ⟨t, h3⟩ hrel,
exact h1 h2 t hrel h3,
end
namespace compositionPA
variables A A' : Prop
variable B : A → Prop
variable A'' : A' → Prop
variable B' : ∀ h : A', A'' h → Prop
lemma comp_helper1 (h : A ↔ ∃ h : A', A'' h)
(h' : ∀ (h1 : A) (h2 : A') (h3 : A'' h2), B h1 ↔ B' h2 h3) :
(∀ h1 : A, B h1) ↔ (∀ h2 h3, B' h2 h3) :=
begin
split,
{ intros hh h2 h3,
have h1 : A := h.mpr ⟨h2, h3⟩,
exact (h' h1 h2 h3).mp (hh h1) },
intros hh h1,
cases h.mp h1 with h2 h3,
exact (h' h1 h2 h3).mpr (hh h2 h3)
end
lemma comp_helper2 (φ ψ : formPA agents) (f : frame agents)
(v : nat → f.states → Prop) (s : f.states) :
forcesPA f v s (φ & U φ ψ) ↔
(∃ h : forcesPA f v s φ, forcesPA (f.restrict
(λ y, forcesPA f v y φ) s h) (λ n u, v n u.val) ⟨s, h⟩ ψ) :=
begin
split,
intro h1,
cases h1 with h1 h2,
use h1,
apply h2,
intro h1,
cases h1 with h1 h2,
split,
exact h1,
intro h3,
exact h2,
end
def is_frame_iso (f1 f2 : frame agents) (F : f1.states ≃ f2.states) :=
∀ x x' : f1.states, ∀ a : agents, (f1.rel a x x' ↔ f2.rel a (F x) (F x'))
def is_model_iso (f1 f2 : frame agents) (v1 : nat → f1.states → Prop)
(v2 : nat → f2.states → Prop) (F : f1.states ≃ f2.states) :=
is_frame_iso f1 f2 F ∧ ∀ n, ∀ x : f1.states, v1 n x = v2 n (F x)
lemma model_iso_symm {f1 f2 : frame agents} {v1 : nat → f1.states → Prop}
{v2 : nat → f2.states → Prop} {F : f1.states ≃ f2.states} :
is_model_iso f1 f2 v1 v2 F → is_model_iso f2 f1 v2 v1 (F.symm) :=
begin
intro h1,
cases h1 with h1 h2,
split,
intros x x' a,
specialize h1 (F.inv_fun x) (F.inv_fun x') a,
simp at h1,
exact h1.symm,
intros n x,
specialize h2 n (F.inv_fun x), simp at *,
exact h2.symm
end
def restrict_F {f1 f2 : frame agents} {v1 : nat → f1.states → Prop}
{v2 : nat → f2.states → Prop} (F : f1.states ≃ f2.states)
(φ : formPA agents) (x : f1.states) (h : ∀ y : f1.states,
(forcesPA f1 v1 y φ ↔ forcesPA f2 v2 (F y) φ)) (h' : forcesPA f1 v1 x φ)
(h'' : forcesPA f2 v2 (F x) φ) :
(f1.restrict (λ y, forcesPA f1 v1 y φ) x h').states
≃ (f2.restrict (λ y, forcesPA f2 v2 y φ) (F x) h'').states :=
{ to_fun := λ ⟨y, hy⟩, ⟨(F y), (h y).mp hy⟩,
inv_fun := λ ⟨y, hy⟩, ⟨(F.inv_fun y), (h (F.inv_fun y)).mpr
begin
convert hy,
apply F.right_inv,
end ⟩,
left_inv :=
begin
intro y,
cases y with y hy,
ext,
apply F.left_inv,
end,
right_inv :=
begin
intro y,
cases y with y hy,
ext,
apply F.right_inv,
end }
lemma update_iso {f1 f2 : frame agents} {v1 : nat → f1.states → Prop}
{v2 : nat → f2.states → Prop} (F : f1.states ≃ f2.states) :
is_model_iso f1 f2 v1 v2 F → ∀ φ : formPA agents,
∀ h : (∀ x : f1.states, forcesPA f1 v1 x φ ↔ forcesPA f2 v2 (F x) φ),
∀ x, ∀ h' : forcesPA f1 v1 x φ,
∀ h'' : forcesPA f2 v2 (F x) φ,
is_model_iso (f1.restrict (λ y, forcesPA f1 v1 y φ) x h')
(f2.restrict (λ y, forcesPA f2 v2 y φ) (F x) h'') (λ n u, v1 n u.val)
(λ n u, v2 n u.val) (restrict_F F φ x h h' h'') :=
begin
intros h1 φ h2 x h3 h4,
cases h1 with h1 h6,
split,
rintros ⟨x1, hx1⟩ ⟨y1, hy1⟩ a,
apply h1 x1 y1 a,
rintros n ⟨x1, hx1⟩,
apply h6 n x1,
end
lemma comp_helper3 (f1 f2 : frame agents) (v1 : nat → f1.states → Prop)
(v2 : nat → f2.states → Prop) (F : f1.states ≃ f2.states) :
is_model_iso f1 f2 v1 v2 F → ∀ s1 : f1.states, ∀ φ : formPA agents,
forcesPA f1 v1 s1 φ ↔ forcesPA f2 v2 (F s1) φ :=
begin
intro h1,
intros x1 φ, induction φ generalizing f1 v1 f2 v2 F h1 x1,
split,
repeat {intro h3, exact h3},
split,
repeat {intro h3,
rename φ n,
cases h1 with h1 h2,
specialize h2 n x1,
rw forcesPA at *,
convert h3},
exact eq.symm h2,
repeat {rename φ_φ φ},
repeat {rename φ_ψ ψ},
repeat {rename φ_ih_φ φ_ih},
repeat {rename φ_ih_ψ ψ_ih},
repeat {rename φ_a a},
split,
repeat {intro h3,
cases h3 with h3 h4,
split},
exact (φ_ih f1 v1 f2 v2 F h1 x1).mp h3,
exact (ψ_ih f1 v1 f2 v2 F h1 x1).mp h4,
exact (φ_ih f1 v1 f2 v2 F h1 x1).mpr h3,
exact (ψ_ih f1 v1 f2 v2 F h1 x1).mpr h4,
split,
repeat {intros h3 h4},
exact (ψ_ih f1 v1 f2 v2 F h1 x1).mp (h3 ((φ_ih f1 v1 f2 v2 F h1 x1).mpr h4)),
exact (ψ_ih f1 v1 f2 v2 F h1 x1).mpr (h3 ((φ_ih f1 v1 f2 v2 F h1 x1).mp h4)),
split,
intros h3 y1 h4,
specialize φ_ih f1 v1 f2 v2 F h1 (F.inv_fun y1),
cases h1 with h1 h5,
specialize h1 x1 (F.inv_fun y1) a,
simp at *,
exact φ_ih.mp (h3 (F.inv_fun y1) (h1.mpr h4)),
intros h3 x2 h4,
specialize φ_ih f1 v1 f2 v2 F h1 x2,
cases h1 with h1 h5,
exact φ_ih.mpr (h3 (F.to_fun x2) ((h1 x1 x2 a).mp h4)),
split,
intro h2,
specialize φ_ih f1 v1 f2 v2 F h1,
intro h3,
have h4 := ((φ_ih x1).mpr h3),
have h5 := update_iso F h1 φ φ_ih x1 h4 h3,
specialize ψ_ih (f1.restrict (λ (y : f1.states), forcesPA f1 v1 y φ) x1 h4)
(λ (n : ℕ) (u : (f1.restrict (λ (y : f1.states), forcesPA f1 v1 y φ) x1 h4).states), v1 n u.val)
(f2.restrict (λ (y : f2.states), forcesPA f2 v2 y φ) (F x1) h3)
(λ (n : ℕ) (u : (f2.restrict (λ (y : f2.states), forcesPA f2 v2 y φ) (F x1) h3).states),
v2 n u.val) (restrict_F F φ x1 φ_ih h4 h3) h5 ⟨x1, h4⟩,
have h6 := ψ_ih.mp (h2 h4),
convert h6,
intro h2,
specialize φ_ih f1 v1 f2 v2 F h1,
intro h3,
have h4 := (φ_ih x1).mp h3,
have h5 := update_iso F h1 φ φ_ih x1 h3 h4,
specialize ψ_ih (f2.restrict (λ (y : f2.states), forcesPA f2 v2 y φ) (F x1) h4)
(λ (n : ℕ) (u : (f2.restrict (λ (y : f2.states), forcesPA f2 v2 y φ) (F x1) h4).states), v2 n u.val)
(f1.restrict (λ (y : f1.states), forcesPA f1 v1 y φ) x1 h3)
(λ (n : ℕ) (u : (f1.restrict (λ (y : f1.states), forcesPA f1 v1 y φ) x1 h3).states), v1 n u.val)
(_) (model_iso_symm h5) ⟨F x1, h4⟩,
have h6 := ψ_ih.mp (h2 h4),
convert h6,
{exact (equiv.eq_symm_apply F).mpr rfl},
end
-- Proposition 4.17, pg. 78
lemma public_announce_comp (φ ψ χ : formPA agents) (f : frame agents)
(v : nat → f.states → Prop) (s : f.states) :
forcesPA f v s (U (φ & U φ ψ) χ) ↔ forcesPA f v s (U φ (U ψ χ)) :=
begin
apply comp_helper1,
apply comp_helper2,
intros h1 h2 h3,
let F : (f.restrict (λ (y : f.states), forcesPA f v y (φ&φ.update ψ)) s h1).states ≃ ((f.restrict
(λ (y : f.states), forcesPA f v y φ) s h2).restrict (λ (y : (f.restrict (λ (y : f.states),
forcesPA f v y φ) s h2).states), forcesPA (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2)
(λ (n : ℕ) (u : (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).states), v n u.val) y ψ)
⟨s, h2⟩ h3).states :=
{to_fun :=
begin
rintro ⟨x, h⟩,
use x,
apply h.left,
apply h.right,
end,
inv_fun :=
begin
rintro ⟨⟨x, h4⟩, h5⟩,
exact ⟨x, ⟨h4, λ _, h5⟩⟩,
end,
left_inv :=
begin
rintro ⟨x, h⟩,
ext,
refl,
end,
right_inv :=
begin
rintro ⟨⟨x, h4⟩, h5⟩,
refl,
end},
have h4 := comp_helper3 (f.restrict (λ (y : f.states), forcesPA f v y (φ&φ.update ψ)) s h1)
((f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).restrict (λ (y : (f.restrict (λ (y : f.states),
forcesPA f v y φ) s h2).states), forcesPA (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2)
(λ (n : ℕ) (u : (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).states), v n u.val) y ψ) ⟨s, h2⟩ h3)
(λ (n : ℕ) (u : (f.restrict (λ (y : f.states), forcesPA f v y (φ&φ.update ψ)) s h1).states), v n u.val)
(λ (n : ℕ) (u : ((f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).restrict (λ (y : (f.restrict
(λ (y : f.states), forcesPA f v y φ) s h2).states), forcesPA (f.restrict (λ (y : f.states), forcesPA f v y φ)
s h2) (λ (n : ℕ) (u : (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).states), v n u.val) y ψ)
⟨s, h2⟩ h3).states), (λ (n : ℕ) (u : (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).states),
v n u.val) n u.val),
specialize h4 F,
have h5 : is_model_iso (f.restrict (λ (y : f.states), forcesPA f v y (φ&φ.update ψ)) s h1)
((f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).restrict (λ (y : (f.restrict (λ (y : f.states),
forcesPA f v y φ) s h2).states), forcesPA (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2)
(λ (n : ℕ) (u : (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).states), v n u.val) y ψ)
⟨s, h2⟩ h3) (λ (n : ℕ) (u : (f.restrict (λ (y : f.states), forcesPA f v y (φ&φ.update ψ)) s h1).states),
v n u.val) (λ (n : ℕ) (u : ((f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).restrict
(λ (y : (f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).states), forcesPA (f.restrict
(λ (y : f.states), forcesPA f v y φ) s h2) (λ (n : ℕ) (u : (f.restrict (λ (y : f.states),
forcesPA f v y φ) s h2).states), v n u.val) y ψ) ⟨s, h2⟩ h3).states), (λ (n : ℕ) (u :
(f.restrict (λ (y : f.states), forcesPA f v y φ) s h2).states), v n u.val) n u.val) F,
{
split,
rintros ⟨x1, hx1⟩ ⟨y1, hy1⟩ a,
refl,
rintros n ⟨x, hx⟩,
refl
},
convert h4 h5 ⟨s, h1⟩ χ
end
end compositionPA
|
a21e493618470ee1aab6a11a5a2f86c09fcff1c8 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/priority_test2.lean | 1b12b528fc26847b5a3c048aece29ff73d1a43bf | [
"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 | 736 | lean | open nat
class foo :=
(a : nat) (b : nat)
attribute [instance, priority std.priority.default-2]
definition i1 : foo :=
foo.mk 1 1
example : foo.a = 1 :=
rfl
attribute [instance, priority std.priority.default-1]
definition i2 : foo :=
foo.mk 2 2
example : foo.a = 2 :=
rfl
attribute [instance]
definition i3 : foo :=
foo.mk 3 3
example : foo.a = 3 :=
rfl
attribute [instance, priority std.priority.default-1]
definition i4 : foo :=
foo.mk 4 4
example : foo.a = 3 :=
rfl
attribute [instance, priority std.priority.default+2] i4
example : foo.a = 4 :=
rfl
attribute [instance, priority std.priority.default+3] i1
example : foo.a = 1 :=
rfl
attribute [instance, priority std.priority.default+4] i2
example : foo.a = 2 :=
rfl
|
982105fede63f99ea8484187bf7d4175ded18856 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/lie/classical.lean | 0bc4ada4aecb44c483a3dfe9be641437f3ceaaf6 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 13,390 | lean | /-
Copyright (c) 2020 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.invertible
import data.matrix.basis
import data.matrix.dmatrix
import algebra.lie.abelian
import linear_algebra.matrix.trace
import algebra.lie.skew_adjoint
/-!
# Classical Lie algebras
This file is the place to find definitions and basic properties of the classical Lie algebras:
* Aₗ = sl(l+1)
* Bₗ ≃ so(l+1, l) ≃ so(2l+1)
* Cₗ = sp(l)
* Dₗ ≃ so(l, l) ≃ so(2l)
## Main definitions
* `lie_algebra.special_linear.sl`
* `lie_algebra.symplectic.sp`
* `lie_algebra.orthogonal.so`
* `lie_algebra.orthogonal.so'`
* `lie_algebra.orthogonal.so_indefinite_equiv`
* `lie_algebra.orthogonal.type_D`
* `lie_algebra.orthogonal.type_B`
* `lie_algebra.orthogonal.type_D_equiv_so'`
* `lie_algebra.orthogonal.type_B_equiv_so'`
## Implementation notes
### Matrices or endomorphisms
Given a finite type and a commutative ring, the corresponding square matrices are equivalent to the
endomorphisms of the corresponding finite-rank free module as Lie algebras, see `lie_equiv_matrix'`.
We can thus define the classical Lie algebras as Lie subalgebras either of matrices or of
endomorphisms. We have opted for the former. At the time of writing (August 2020) it is unclear
which approach should be preferred so the choice should be assumed to be somewhat arbitrary.
### Diagonal quadratic form or diagonal Cartan subalgebra
For the algebras of type `B` and `D`, there are two natural definitions. For example since the
the `2l × 2l` matrix:
$$
J = \left[\begin{array}{cc}
0_l & 1_l\\
1_l & 0_l
\end{array}\right]
$$
defines a symmetric bilinear form equivalent to that defined by the identity matrix `I`, we can
define the algebras of type `D` to be the Lie subalgebra of skew-adjoint matrices either for `J` or
for `I`. Both definitions have their advantages (in particular the `J`-skew-adjoint matrices define
a Lie algebra for which the diagonal matrices form a Cartan subalgebra) and so we provide both.
We thus also provide equivalences `type_D_equiv_so'`, `so_indefinite_equiv` which show the two
definitions are equivalent. Similarly for the algebras of type `B`.
## Tags
classical lie algebra, special linear, symplectic, orthogonal
-/
universes u₁ u₂
namespace lie_algebra
open matrix
open_locale matrix
variables (n p q l : Type*) (R : Type u₂)
variables [decidable_eq n] [decidable_eq p] [decidable_eq q] [decidable_eq l]
variables [comm_ring R]
@[simp] lemma matrix_trace_commutator_zero [fintype n] (X Y : matrix n n R) :
matrix.trace ⁅X, Y⁆ = 0 :=
calc _ = matrix.trace (X ⬝ Y) - matrix.trace (Y ⬝ X) : trace_sub _ _
... = matrix.trace (X ⬝ Y) - matrix.trace (X ⬝ Y) :
congr_arg (λ x, _ - x) (matrix.trace_mul_comm Y X)
... = 0 : sub_self _
namespace special_linear
/-- The special linear Lie algebra: square matrices of trace zero. -/
def sl [fintype n] : lie_subalgebra R (matrix n n R) :=
{ lie_mem' := λ X Y _ _, linear_map.mem_ker.2 $ matrix_trace_commutator_zero _ _ _ _,
..linear_map.ker (matrix.trace_linear_map n R R) }
lemma sl_bracket [fintype n] (A B : sl n R) : ⁅A, B⁆.val = A.val ⬝ B.val - B.val ⬝ A.val := rfl
section elementary_basis
variables {n} [fintype n] (i j : n)
/-- When j ≠ i, the elementary matrices are elements of sl n R, in fact they are part of a natural
basis of sl n R. -/
def Eb (h : j ≠ i) : sl n R :=
⟨matrix.std_basis_matrix i j (1 : R),
show matrix.std_basis_matrix i j (1 : R) ∈ linear_map.ker (matrix.trace_linear_map n R R),
from matrix.std_basis_matrix.trace_zero i j (1 : R) h⟩
@[simp] lemma Eb_val (h : j ≠ i) : (Eb R i j h).val = matrix.std_basis_matrix i j 1 := rfl
end elementary_basis
lemma sl_non_abelian [fintype n] [nontrivial R] (h : 1 < fintype.card n) :
¬is_lie_abelian ↥(sl n R) :=
begin
rcases fintype.exists_pair_of_one_lt_card h with ⟨j, i, hij⟩,
let A := Eb R i j hij,
let B := Eb R j i hij.symm,
intros c,
have c' : A.val ⬝ B.val = B.val ⬝ A.val, by { rw [← sub_eq_zero, ← sl_bracket, c.trivial], refl },
simpa [std_basis_matrix, matrix.mul_apply, hij] using congr_fun (congr_fun c' i) i,
end
end special_linear
namespace symplectic
/-- The matrix defining the canonical skew-symmetric bilinear form. -/
def J : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 0 (-1) 1 0
/-- The symplectic Lie algebra: skew-adjoint matrices with respect to the canonical skew-symmetric
bilinear form. -/
def sp [fintype l] : lie_subalgebra R (matrix (l ⊕ l) (l ⊕ l) R) :=
skew_adjoint_matrices_lie_subalgebra (J l R)
end symplectic
namespace orthogonal
/-- The definite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric
bilinear form defined by the identity matrix. -/
def so [fintype n] : lie_subalgebra R (matrix n n R) :=
skew_adjoint_matrices_lie_subalgebra (1 : matrix n n R)
@[simp] lemma mem_so [fintype n] (A : matrix n n R) : A ∈ so n R ↔ Aᵀ = -A :=
begin
erw mem_skew_adjoint_matrices_submodule,
simp only [matrix.is_skew_adjoint, matrix.is_adjoint_pair, matrix.mul_one, matrix.one_mul],
end
/-- The indefinite diagonal matrix with `p` 1s and `q` -1s. -/
def indefinite_diagonal : matrix (p ⊕ q) (p ⊕ q) R :=
matrix.diagonal $ sum.elim (λ _, 1) (λ _, -1)
/-- The indefinite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric
bilinear form defined by the indefinite diagonal matrix. -/
def so' [fintype p] [fintype q] : lie_subalgebra R (matrix (p ⊕ q) (p ⊕ q) R) :=
skew_adjoint_matrices_lie_subalgebra $ indefinite_diagonal p q R
/-- A matrix for transforming the indefinite diagonal bilinear form into the definite one, provided
the parameter `i` is a square root of -1. -/
def Pso (i : R) : matrix (p ⊕ q) (p ⊕ q) R :=
matrix.diagonal $ sum.elim (λ _, 1) (λ _, i)
variables [fintype p] [fintype q]
lemma Pso_inv {i : R} (hi : i*i = -1) : (Pso p q R i) * (Pso p q R (-i)) = 1 :=
begin
ext x y, rcases x; rcases y,
{ -- x y : p
by_cases h : x = y; simp [Pso, indefinite_diagonal, h], },
{ -- x : p, y : q
simp [Pso, indefinite_diagonal], },
{ -- x : q, y : p
simp [Pso, indefinite_diagonal], },
{ -- x y : q
by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], },
end
/-- There is a constructive inverse of `Pso p q R i`. -/
def invertible_Pso {i : R} (hi : i*i = -1) : invertible (Pso p q R i) :=
invertible_of_right_inverse _ _ (Pso_inv p q R hi)
lemma indefinite_diagonal_transform {i : R} (hi : i*i = -1) :
(Pso p q R i)ᵀ ⬝ (indefinite_diagonal p q R) ⬝ (Pso p q R i) = 1 :=
begin
ext x y, rcases x; rcases y,
{ -- x y : p
by_cases h : x = y; simp [Pso, indefinite_diagonal, h], },
{ -- x : p, y : q
simp [Pso, indefinite_diagonal], },
{ -- x : q, y : p
simp [Pso, indefinite_diagonal], },
{ -- x y : q
by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], },
end
/-- An equivalence between the indefinite and definite orthogonal Lie algebras, over a ring
containing a square root of -1. -/
def so_indefinite_equiv {i : R} (hi : i*i = -1) : so' p q R ≃ₗ⁅R⁆ so (p ⊕ q) R :=
begin
apply (skew_adjoint_matrices_lie_subalgebra_equiv
(indefinite_diagonal p q R) (Pso p q R i) (invertible_Pso p q R hi)).trans,
apply lie_equiv.of_eq,
ext A, rw indefinite_diagonal_transform p q R hi, refl,
end
lemma so_indefinite_equiv_apply {i : R} (hi : i*i = -1) (A : so' p q R) :
(so_indefinite_equiv p q R hi A : matrix (p ⊕ q) (p ⊕ q) R) =
(Pso p q R i)⁻¹ ⬝ (A : matrix (p ⊕ q) (p ⊕ q) R) ⬝ (Pso p q R i) :=
by erw [lie_equiv.trans_apply, lie_equiv.of_eq_apply,
skew_adjoint_matrices_lie_subalgebra_equiv_apply]
/-- A matrix defining a canonical even-rank symmetric bilinear form.
It looks like this as a `2l x 2l` matrix of `l x l` blocks:
[ 0 1 ]
[ 1 0 ]
-/
def JD : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 0 1 1 0
/-- The classical Lie algebra of type D as a Lie subalgebra of matrices associated to the matrix
`JD`. -/
def type_D [fintype l] := skew_adjoint_matrices_lie_subalgebra (JD l R)
/-- A matrix transforming the bilinear form defined by the matrix `JD` into a split-signature
diagonal matrix.
It looks like this as a `2l x 2l` matrix of `l x l` blocks:
[ 1 -1 ]
[ 1 1 ]
-/
def PD : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 1 (-1) 1 1
/-- The split-signature diagonal matrix. -/
def S := indefinite_diagonal l l R
lemma S_as_blocks : S l R = matrix.from_blocks 1 0 0 (-1) :=
begin
rw [← matrix.diagonal_one, matrix.diagonal_neg, matrix.from_blocks_diagonal],
refl,
end
lemma JD_transform [fintype l] : (PD l R)ᵀ ⬝ (JD l R) ⬝ (PD l R) = (2 : R) • (S l R) :=
begin
have h : (PD l R)ᵀ ⬝ (JD l R) = matrix.from_blocks 1 1 1 (-1) := by
{ simp [PD, JD, matrix.from_blocks_transpose, matrix.from_blocks_multiply], },
erw [h, S_as_blocks, matrix.from_blocks_multiply, matrix.from_blocks_smul],
congr; simp [two_smul],
end
lemma PD_inv [fintype l] [invertible (2 : R)] : (PD l R) * (⅟(2 : R) • (PD l R)ᵀ) = 1 :=
begin
have h : ⅟(2 : R) • (1 : matrix l l R) + ⅟(2 : R) • 1 = 1 := by
rw [← smul_add, ← (two_smul R _), smul_smul, inv_of_mul_self, one_smul],
erw [matrix.from_blocks_transpose, matrix.from_blocks_smul, matrix.mul_eq_mul,
matrix.from_blocks_multiply],
simp [h],
end
instance invertible_PD [fintype l] [invertible (2 : R)] : invertible (PD l R) :=
invertible_of_right_inverse _ _ (PD_inv l R)
/-- An equivalence between two possible definitions of the classical Lie algebra of type D. -/
def type_D_equiv_so' [fintype l] [invertible (2 : R)] :
type_D l R ≃ₗ⁅R⁆ so' l l R :=
begin
apply (skew_adjoint_matrices_lie_subalgebra_equiv (JD l R) (PD l R) (by apply_instance)).trans,
apply lie_equiv.of_eq,
ext A,
rw [JD_transform, ← coe_unit_of_invertible (2 : R), ←units.smul_def, lie_subalgebra.mem_coe,
mem_skew_adjoint_matrices_lie_subalgebra_unit_smul],
refl,
end
/-- A matrix defining a canonical odd-rank symmetric bilinear form.
It looks like this as a `(2l+1) x (2l+1)` matrix of blocks:
[ 2 0 0 ]
[ 0 0 1 ]
[ 0 1 0 ]
where sizes of the blocks are:
[`1 x 1` `1 x l` `1 x l`]
[`l x 1` `l x l` `l x l`]
[`l x 1` `l x l` `l x l`]
-/
def JB := matrix.from_blocks ((2 : R) • 1 : matrix unit unit R) 0 0 (JD l R)
/-- The classical Lie algebra of type B as a Lie subalgebra of matrices associated to the matrix
`JB`. -/
def type_B [fintype l] := skew_adjoint_matrices_lie_subalgebra(JB l R)
/-- A matrix transforming the bilinear form defined by the matrix `JB` into an
almost-split-signature diagonal matrix.
It looks like this as a `(2l+1) x (2l+1)` matrix of blocks:
[ 1 0 0 ]
[ 0 1 -1 ]
[ 0 1 1 ]
where sizes of the blocks are:
[`1 x 1` `1 x l` `1 x l`]
[`l x 1` `l x l` `l x l`]
[`l x 1` `l x l` `l x l`]
-/
def PB := matrix.from_blocks (1 : matrix unit unit R) 0 0 (PD l R)
variable [fintype l]
lemma PB_inv [invertible (2 : R)] : PB l R * matrix.from_blocks 1 0 0 (⅟(PD l R)) = 1 :=
begin
rw [PB, matrix.mul_eq_mul, matrix.from_blocks_multiply, matrix.mul_inv_of_self],
simp only [matrix.mul_zero, matrix.mul_one, matrix.zero_mul, zero_add, add_zero,
matrix.from_blocks_one]
end
instance invertible_PB [invertible (2 : R)] : invertible (PB l R) :=
invertible_of_right_inverse _ _ (PB_inv l R)
lemma JB_transform : (PB l R)ᵀ ⬝ (JB l R) ⬝ (PB l R) = (2 : R) • matrix.from_blocks 1 0 0 (S l R) :=
by simp [PB, JB, JD_transform, matrix.from_blocks_transpose, matrix.from_blocks_multiply,
matrix.from_blocks_smul]
lemma indefinite_diagonal_assoc :
indefinite_diagonal (unit ⊕ l) l R =
matrix.reindex_lie_equiv (equiv.sum_assoc unit l l).symm
(matrix.from_blocks 1 0 0 (indefinite_diagonal l l R)) :=
begin
ext i j,
rcases i with ⟨⟨i₁ | i₂⟩ | i₃⟩;
rcases j with ⟨⟨j₁ | j₂⟩ | j₃⟩;
simp only [indefinite_diagonal, matrix.diagonal, equiv.sum_assoc_apply_inl_inl,
matrix.reindex_lie_equiv_apply, matrix.minor_apply, equiv.symm_symm, matrix.reindex_apply,
sum.elim_inl, if_true, eq_self_iff_true, matrix.one_apply_eq, matrix.from_blocks_apply₁₁,
dmatrix.zero_apply, equiv.sum_assoc_apply_inl_inr, if_false, matrix.from_blocks_apply₁₂,
matrix.from_blocks_apply₂₁, matrix.from_blocks_apply₂₂, equiv.sum_assoc_apply_inr,
sum.elim_inr];
congr,
end
/-- An equivalence between two possible definitions of the classical Lie algebra of type B. -/
def type_B_equiv_so' [invertible (2 : R)] :
type_B l R ≃ₗ⁅R⁆ so' (unit ⊕ l) l R :=
begin
apply (skew_adjoint_matrices_lie_subalgebra_equiv (JB l R) (PB l R) (by apply_instance)).trans,
symmetry,
apply (skew_adjoint_matrices_lie_subalgebra_equiv_transpose
(indefinite_diagonal (unit ⊕ l) l R)
(matrix.reindex_alg_equiv _ (equiv.sum_assoc punit l l)) (matrix.transpose_reindex _ _)).trans,
apply lie_equiv.of_eq,
ext A,
rw [JB_transform, ← coe_unit_of_invertible (2 : R), ←units.smul_def, lie_subalgebra.mem_coe,
lie_subalgebra.mem_coe, mem_skew_adjoint_matrices_lie_subalgebra_unit_smul],
simpa [indefinite_diagonal_assoc],
end
end orthogonal
end lie_algebra
|
5d495b369fd29c6ec07162a9fd46b8daa38c44b5 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/category_theory/limits/functor_category.lean | 1aa82cd59ba3e6a8b92da674c17c64b3339fe5fb | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 4,797 | 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.limits.preserves.basic
open category_theory category_theory.category
namespace category_theory.limits
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
variables {C : Type u} [category.{v} C]
variables {J K : Type v} [small_category J] [small_category K]
@[simp] lemma cone.functor_w {F : J ⥤ (K ⥤ C)} (c : cone F) {j j' : J} (f : j ⟶ j') (k : K) :
(c.π.app j).app k ≫ (F.map f).app k = (c.π.app j').app k :=
by convert ←nat_trans.congr_app (c.π.naturality f).symm k; apply id_comp
@[simp] lemma cocone.functor_w {F : J ⥤ (K ⥤ C)} (c : cocone F) {j j' : J} (f : j ⟶ j') (k : K) :
(F.map f).app k ≫ (c.ι.app j').app k = (c.ι.app j).app k :=
by convert ←nat_trans.congr_app (c.ι.naturality f) k; apply comp_id
@[simps] def functor_category_limit_cone [has_limits_of_shape J C] (F : J ⥤ K ⥤ C) :
cone F :=
{ X := F.flip ⋙ lim,
π :=
{ app := λ j,
{ app := λ k, limit.π (F.flip.obj k) j },
naturality' := λ j j' f,
by ext k; convert (limit.w (F.flip.obj k) _).symm using 1; apply id_comp } }
@[simps] def functor_category_colimit_cocone [has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) :
cocone F :=
{ X := F.flip ⋙ colim,
ι :=
{ app := λ j,
{ app := λ k, colimit.ι (F.flip.obj k) j },
naturality' := λ j j' f,
by ext k; convert (colimit.w (F.flip.obj k) _) using 1; apply comp_id } }
@[simp] def evaluate_functor_category_limit_cone
[has_limits_of_shape J C] (F : J ⥤ K ⥤ C) (k : K) :
((evaluation K C).obj k).map_cone (functor_category_limit_cone F) ≅
limit.cone (F.flip.obj k) :=
cones.ext (iso.refl _) (by tidy)
@[simp] def evaluate_functor_category_colimit_cocone
[has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) (k : K) :
((evaluation K C).obj k).map_cocone (functor_category_colimit_cocone F) ≅
colimit.cocone (F.flip.obj k) :=
cocones.ext (iso.refl _) (by tidy)
def functor_category_is_limit_cone [has_limits_of_shape J C] (F : J ⥤ K ⥤ C) :
is_limit (functor_category_limit_cone F) :=
{ lift := λ s,
{ app := λ k, limit.lift (F.flip.obj k) (((evaluation K C).obj k).map_cone s) },
uniq' := λ s m w,
begin
ext1, ext1 k,
exact is_limit.uniq _
(((evaluation K C).obj k).map_cone s) (m.app k) (λ j, nat_trans.congr_app (w j) k)
end }
def functor_category_is_colimit_cocone [has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) :
is_colimit (functor_category_colimit_cocone F) :=
{ desc := λ s,
{ app := λ k, colimit.desc (F.flip.obj k) (((evaluation K C).obj k).map_cocone s) },
uniq' := λ s m w,
begin
ext1, ext1 k,
exact is_colimit.uniq _
(((evaluation K C).obj k).map_cocone s) (m.app k) (λ j, nat_trans.congr_app (w j) k)
end }
instance functor_category_has_limits_of_shape
[has_limits_of_shape J C] : has_limits_of_shape J (K ⥤ C) :=
{ has_limit := λ F,
{ cone := functor_category_limit_cone F,
is_limit := functor_category_is_limit_cone F } }
instance functor_category_has_colimits_of_shape
[has_colimits_of_shape J C] : has_colimits_of_shape J (K ⥤ C) :=
{ has_colimit := λ F,
{ cocone := functor_category_colimit_cocone F,
is_colimit := functor_category_is_colimit_cocone F } }
instance functor_category_has_limits [has_limits C] : has_limits (K ⥤ C) :=
{ has_limits_of_shape := λ J 𝒥, by resetI; apply_instance }
instance functor_category_has_colimits [has_colimits C] : has_colimits (K ⥤ C) :=
{ has_colimits_of_shape := λ J 𝒥, by resetI; apply_instance }
instance evaluation_preserves_limits_of_shape [has_limits_of_shape J C] (k : K) :
preserves_limits_of_shape J ((evaluation K C).obj k) :=
{ preserves_limit :=
λ F, preserves_limit_of_preserves_limit_cone (limit.is_limit _) $
is_limit.of_iso_limit (limit.is_limit _)
(evaluate_functor_category_limit_cone F k).symm }
instance evaluation_preserves_colimits_of_shape [has_colimits_of_shape J C] (k : K) :
preserves_colimits_of_shape J ((evaluation K C).obj k) :=
{ preserves_colimit :=
λ F, preserves_colimit_of_preserves_colimit_cocone (colimit.is_colimit _) $
is_colimit.of_iso_colimit (colimit.is_colimit _)
(evaluate_functor_category_colimit_cocone F k).symm }
instance evaluation_preserves_limits [has_limits C] (k : K) :
preserves_limits ((evaluation K C).obj k) :=
{ preserves_limits_of_shape := λ J 𝒥, by resetI; apply_instance }
instance evaluation_preserves_colimits [has_colimits C] (k : K) :
preserves_colimits ((evaluation K C).obj k) :=
{ preserves_colimits_of_shape := λ J 𝒥, by resetI; apply_instance }
end category_theory.limits
|
84d08b3b3686c2f9d4bd5ee13c964917c87beaa8 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/ring_theory/witt_vector/witt_polynomial.lean | eebf93e8d0dfbc56b5f30edd7866744431208232 | [
"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 | 10,754 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import algebra.char_p.invertible
import data.fintype.card
import data.mv_polynomial.variables
import data.mv_polynomial.comm_ring
import data.mv_polynomial.expand
import data.zmod.basic
/-!
# Witt polynomials
To endow `witt_vector p R` with a ring structure,
we need to study the so-called Witt polynomials.
Fix a base value `p : ℕ`.
The `p`-adic Witt polynomials are an infinite family of polynomials
indexed by a natural number `n`, taking values in an arbitrary ring `R`.
The variables of these polynomials are represented by natural numbers.
The variable set of the `n`th Witt polynomial contains at most `n+1` elements `{0, ..., n}`,
with exactly these variables when `R` has characteristic `0`.
These polynomials are used to define the addition and multiplication operators
on the type of Witt vectors. (While this type itself is not complicated,
the ring operations are what make it interesting.)
When the base `p` is invertible in `R`, the `p`-adic Witt polynomials
form a basis for `mv_polynomial ℕ R`, equivalent to the standard basis.
## Main declarations
* `witt_polynomial p R n`: the `n`-th Witt polynomial, viewed as polynomial over the ring `R`
* `X_in_terms_of_W p R n`: if `p` is invertible, the polynomial `X n` is contained in the subalgebra
generated by the Witt polynomials. `X_in_terms_of_W p R n` is the explicit polynomial,
which upon being bound to the Witt polynomials yields `X n`.
* `bind₁_witt_polynomial_X_in_terms_of_W`: the proof of the claim that
`bind₁ (X_in_terms_of_W p R) (W_ R n) = X n`
* `bind₁_X_in_terms_of_W_witt_polynomial`: the converse of the above statement
## Notation
In this file we use the following notation
* `p` is a natural number, typically assumed to be prime.
* `R` and `S` are commutative rings
* `W n` (and `W_ R n` when the ring needs to be explicit) denotes the `n`th Witt polynomial
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open mv_polynomial
open finset (hiding map)
open finsupp (single)
open_locale big_operators
local attribute [-simp] coe_eval₂_hom
variables (p : ℕ)
variables (R : Type*) [comm_ring R]
/-- `witt_polynomial p R n` is the `n`-th Witt polynomial
with respect to a prime `p` with coefficients in a commutative ring `R`.
It is defined as:
`∑_{i ≤ n} p^i X_i^{p^{n-i}} ∈ R[X_0, X_1, X_2, …]`. -/
noncomputable def witt_polynomial (n : ℕ) : mv_polynomial ℕ R :=
∑ i in range (n+1), monomial (single i (p ^ (n - i))) (p ^ i : R)
lemma witt_polynomial_eq_sum_C_mul_X_pow (n : ℕ) :
witt_polynomial p R n = ∑ i in range (n+1), C (p ^ i : R) * X i ^ (p ^ (n - i)) :=
begin
apply sum_congr rfl,
rintro i -,
rw [monomial_eq, finsupp.prod_single_index],
rw pow_zero,
end
/-! We set up notation locally to this file, to keep statements short and comprehensible.
This allows us to simply write `W n` or `W_ ℤ n`. -/
-- Notation with ring of coefficients explicit
localized "notation `W_` := witt_polynomial p" in witt
-- Notation with ring of coefficients implicit
localized "notation `W` := witt_polynomial p _" in witt
open_locale witt
open mv_polynomial
/- The first observation is that the Witt polynomial doesn't really depend on the coefficient ring.
If we map the coefficients through a ring homomorphism, we obtain the corresponding Witt polynomial
over the target ring. -/
section
variables {R} {S : Type*} [comm_ring S]
@[simp] lemma map_witt_polynomial (f : R →+* S) (n : ℕ) :
map f (W n) = W n :=
begin
rw [witt_polynomial, ring_hom.map_sum, witt_polynomial, sum_congr rfl],
intros i hi,
rw [map_monomial, ring_hom.map_pow, map_nat_cast],
end
variables (R)
@[simp] lemma constant_coeff_witt_polynomial [hp : fact p.prime] (n : ℕ) :
constant_coeff (witt_polynomial p R n) = 0 :=
begin
simp only [witt_polynomial, ring_hom.map_sum, constant_coeff_monomial],
rw [sum_eq_zero],
rintro i hi,
rw [if_neg],
rw [finsupp.single_eq_zero],
exact ne_of_gt (pow_pos hp.1.pos _)
end
@[simp] lemma witt_polynomial_zero : witt_polynomial p R 0 = X 0 :=
by simp only [witt_polynomial, X, sum_singleton, range_one, pow_zero]
@[simp] lemma witt_polynomial_one : witt_polynomial p R 1 = C ↑p * X 1 + (X 0) ^ p :=
by simp only [witt_polynomial_eq_sum_C_mul_X_pow, sum_range_succ_comm, range_one,
sum_singleton, one_mul, pow_one, C_1, pow_zero]
lemma aeval_witt_polynomial {A : Type*} [comm_ring A] [algebra R A] (f : ℕ → A) (n : ℕ) :
aeval f (W_ R n) = ∑ i in range (n+1), p^i * (f i) ^ (p ^ (n-i)) :=
by simp [witt_polynomial, alg_hom.map_sum, aeval_monomial, finsupp.prod_single_index]
/--
Over the ring `zmod (p^(n+1))`, we produce the `n+1`st Witt polynomial
by expanding the `n`th Witt polynomial by `p`.
-/
@[simp] lemma witt_polynomial_zmod_self (n : ℕ) :
W_ (zmod (p ^ (n + 1))) (n + 1) = expand p (W_ (zmod (p^(n + 1))) n) :=
begin
simp only [witt_polynomial_eq_sum_C_mul_X_pow],
rw [sum_range_succ, ← nat.cast_pow, char_p.cast_eq_zero (zmod (p^(n+1))) (p^(n+1)), C_0, zero_mul,
add_zero, alg_hom.map_sum, sum_congr rfl],
intros k hk,
rw [alg_hom.map_mul, alg_hom.map_pow, expand_X, alg_hom_C, ← pow_mul, ← pow_succ],
congr,
rw mem_range at hk,
rw [add_comm, add_tsub_assoc_of_le (nat.lt_succ_iff.mp hk), ← add_comm],
end
section p_prime
-- in fact, `0 < p` would be sufficient
variables [hp : fact p.prime]
include hp
lemma witt_polynomial_vars [char_zero R] (n : ℕ) :
(witt_polynomial p R n).vars = range (n + 1) :=
begin
have : ∀ i, (monomial (finsupp.single i (p ^ (n - i))) (p ^ i : R)).vars = {i},
{ intro i,
refine vars_monomial_single i (pow_ne_zero _ hp.1.ne_zero) _,
rw [← nat.cast_pow, nat.cast_ne_zero],
exact pow_ne_zero i hp.1.ne_zero },
rw [witt_polynomial, vars_sum_of_disjoint],
{ simp only [this, bUnion_singleton_eq_self], },
{ simp only [this],
intros a b h,
apply disjoint_singleton_left.mpr,
rwa mem_singleton, },
end
lemma witt_polynomial_vars_subset (n : ℕ) :
(witt_polynomial p R n).vars ⊆ range (n + 1) :=
begin
rw [← map_witt_polynomial p (int.cast_ring_hom R), ← witt_polynomial_vars p ℤ],
apply vars_map,
end
end p_prime
end
/-!
## Witt polynomials as a basis of the polynomial algebra
If `p` is invertible in `R`, then the Witt polynomials form a basis
of the polynomial algebra `mv_polynomial ℕ R`.
The polynomials `X_in_terms_of_W` give the coordinate transformation in the backwards direction.
-/
/-- The `X_in_terms_of_W p R n` is the polynomial on the basis of Witt polynomials
that corresponds to the ordinary `X n`. -/
noncomputable def X_in_terms_of_W [invertible (p : R)] :
ℕ → mv_polynomial ℕ R
| n := (X n - (∑ i : fin n,
have _ := i.2, (C (p^(i : ℕ) : R) * (X_in_terms_of_W i)^(p^(n-i))))) * C (⅟p ^ n : R)
lemma X_in_terms_of_W_eq [invertible (p : R)] {n : ℕ} :
X_in_terms_of_W p R n =
(X n - (∑ i in range n, C (p^i : R) * X_in_terms_of_W p R i ^ p ^ (n - i))) * C (⅟p ^ n : R) :=
by { rw [X_in_terms_of_W, ← fin.sum_univ_eq_sum_range] }
@[simp] lemma constant_coeff_X_in_terms_of_W [hp : fact p.prime] [invertible (p : R)] (n : ℕ) :
constant_coeff (X_in_terms_of_W p R n) = 0 :=
begin
apply nat.strong_induction_on n; clear n,
intros n IH,
rw [X_in_terms_of_W_eq, mul_comm, ring_hom.map_mul, ring_hom.map_sub, ring_hom.map_sum,
constant_coeff_C, sum_eq_zero],
{ simp only [constant_coeff_X, sub_zero, mul_zero] },
{ intros m H,
rw mem_range at H,
simp only [ring_hom.map_mul, ring_hom.map_pow, constant_coeff_C, IH m H],
rw [zero_pow, mul_zero],
apply pow_pos hp.1.pos, }
end
@[simp] lemma X_in_terms_of_W_zero [invertible (p : R)] :
X_in_terms_of_W p R 0 = X 0 :=
by rw [X_in_terms_of_W_eq, range_zero, sum_empty, pow_zero, C_1, mul_one, sub_zero]
section p_prime
variables [hp : fact p.prime]
include hp
lemma X_in_terms_of_W_vars_aux (n : ℕ) :
n ∈ (X_in_terms_of_W p ℚ n).vars ∧
(X_in_terms_of_W p ℚ n).vars ⊆ range (n + 1) :=
begin
apply nat.strong_induction_on n, clear n,
intros n ih,
rw [X_in_terms_of_W_eq, mul_comm, vars_C_mul, vars_sub_of_disjoint, vars_X, range_succ,
insert_eq],
swap 3, { apply nonzero_of_invertible },
work_on_goal 1
{ simp only [true_and, true_or, eq_self_iff_true,
mem_union, mem_singleton],
intro i,
rw [mem_union, mem_union],
apply or.imp id },
work_on_goal 2 { rw [vars_X, disjoint_singleton_left] },
all_goals
{ intro H,
replace H := vars_sum_subset _ _ H,
rw mem_bUnion at H,
rcases H with ⟨j, hj, H⟩,
rw vars_C_mul at H,
swap,
{ apply pow_ne_zero, exact_mod_cast hp.1.ne_zero },
rw mem_range at hj,
replace H := (ih j hj).2 (vars_pow _ _ H),
rw mem_range at H },
{ rw mem_range,
exact lt_of_lt_of_le H hj },
{ exact lt_irrefl n (lt_of_lt_of_le H hj) },
end
lemma X_in_terms_of_W_vars_subset (n : ℕ) :
(X_in_terms_of_W p ℚ n).vars ⊆ range (n + 1) :=
(X_in_terms_of_W_vars_aux p n).2
end p_prime
lemma X_in_terms_of_W_aux [invertible (p : R)] (n : ℕ) :
X_in_terms_of_W p R n * C (p^n : R) =
X n - ∑ i in range n, C (p^i : R) * (X_in_terms_of_W p R i)^p^(n-i) :=
by rw [X_in_terms_of_W_eq, mul_assoc, ← C_mul, ← mul_pow, inv_of_mul_self, one_pow, C_1, mul_one]
@[simp] lemma bind₁_X_in_terms_of_W_witt_polynomial [invertible (p : R)] (k : ℕ) :
bind₁ (X_in_terms_of_W p R) (W_ R k) = X k :=
begin
rw [witt_polynomial_eq_sum_C_mul_X_pow, alg_hom.map_sum],
simp only [alg_hom.map_pow, C_pow, alg_hom.map_mul, alg_hom_C],
rw [sum_range_succ_comm, tsub_self, pow_zero, pow_one, bind₁_X_right,
mul_comm, ← C_pow, X_in_terms_of_W_aux],
simp only [C_pow, bind₁_X_right, sub_add_cancel],
end
@[simp] lemma bind₁_witt_polynomial_X_in_terms_of_W [invertible (p : R)] (n : ℕ) :
bind₁ (W_ R) (X_in_terms_of_W p R n) = X n :=
begin
apply nat.strong_induction_on n,
clear n, intros n H,
rw [X_in_terms_of_W_eq, alg_hom.map_mul, alg_hom.map_sub, bind₁_X_right, alg_hom_C,
alg_hom.map_sum],
have : W_ R n - ∑ i in range n, C (p ^ i : R) * (X i) ^ p ^ (n - i) = C (p ^ n : R) * X n,
by simp only [witt_polynomial_eq_sum_C_mul_X_pow, tsub_self, sum_range_succ_comm,
pow_one, add_sub_cancel, pow_zero],
rw [sum_congr rfl, this],
{ -- this is really slow for some reason
rw [mul_right_comm, ← C_mul, ← mul_pow, mul_inv_of_self, one_pow, C_1, one_mul] },
{ intros i h,
rw mem_range at h,
simp only [alg_hom.map_mul, alg_hom.map_pow, alg_hom_C, H i h] },
end
|
1ed9a2d251a36281dc574a89b4dcb336264bd357 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/one2.lean | 7732a91078eb895a44a67591dd7e75f49a9a4b78 | [
"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 | 375 | lean | inductive {u} one1 : Type u
| unit : one1
inductive pone : Type 0
| unit : pone
inductive {u} two : Type (max 1 u)
| o : two
| u : two
inductive {u} wrap : Type (max 1 u)
| mk : true → wrap
inductive {u} wrap2 (A : Type u) : Type (max 1 u)
| mk : A → wrap2
set_option pp.universes true
check @one1.rec
check @pone.rec
check @two.rec
check @wrap.rec
check @wrap2.rec
|
d52fbf5ab2f43e2f64e5c3a42359f66ce96e93e4 | 95dcf8dea2baf2b4b0a60d438f27c35ae3dd3990 | /src/category_theory/equivalence.lean | 1d2d791a7bfdb178ad5ebf929d3cf0bd1c4e6bc3 | [
"Apache-2.0"
] | permissive | uniformity1/mathlib | 829341bad9dfa6d6be9adaacb8086a8a492e85a4 | dd0e9bd8f2e5ec267f68e72336f6973311909105 | refs/heads/master | 1,588,592,015,670 | 1,554,219,842,000 | 1,554,219,842,000 | 179,110,702 | 0 | 0 | Apache-2.0 | 1,554,220,076,000 | 1,554,220,076,000 | null | UTF-8 | Lean | false | false | 8,520 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Tim Baumann, Stephen Morgan, Scott Morrison
import category_theory.fully_faithful
import category_theory.functor_category
import category_theory.natural_isomorphism
import tactic.slice
import tactic.converter.interactive
namespace category_theory
universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
structure equivalence (C : Sort u₁) [category.{v₁} C] (D : Sort u₂) [category.{v₂} D] :=
(functor : C ⥤ D)
(inverse : D ⥤ C)
(fun_inv_id' : (functor ⋙ inverse) ≅ (category_theory.functor.id C) . obviously)
(inv_fun_id' : (inverse ⋙ functor) ≅ (category_theory.functor.id D) . obviously)
restate_axiom equivalence.fun_inv_id'
restate_axiom equivalence.inv_fun_id'
infixr ` ≌ `:10 := equivalence
namespace equivalence
variables {C : Sort u₁} [𝒞 : category.{v₁} C]
include 𝒞
@[refl] def refl : C ≌ C :=
{ functor := functor.id C,
inverse := functor.id C }
variables {D : Sort u₂} [𝒟 : category.{v₂} D]
include 𝒟
@[symm] def symm (e : C ≌ D) : D ≌ C :=
{ functor := e.inverse,
inverse := e.functor,
fun_inv_id' := e.inv_fun_id,
inv_fun_id' := e.fun_inv_id }
@[simp] lemma fun_inv_map (e : C ≌ D) (X Y : D) (f : X ⟶ Y) :
e.functor.map (e.inverse.map f) = (e.inv_fun_id.hom.app X) ≫ f ≫ (e.inv_fun_id.inv.app Y) :=
begin
erw [nat_iso.naturality_2],
refl
end
@[simp] lemma inv_fun_map (e : C ≌ D) (X Y : C) (f : X ⟶ Y) :
e.inverse.map (e.functor.map f) = (e.fun_inv_id.hom.app X) ≫ f ≫ (e.fun_inv_id.inv.app Y) :=
begin
erw [nat_iso.naturality_2],
refl
end
variables {E : Sort u₃} [ℰ : category.{v₃} E]
include ℰ
@[simp] private def effe_iso_id (e : C ≌ D) (f : D ≌ E) (X : C) :
(e.inverse).obj ((f.inverse).obj ((f.functor).obj ((e.functor).obj X))) ≅ X :=
calc
(e.inverse).obj ((f.inverse).obj ((f.functor).obj ((e.functor).obj X)))
≅ (e.inverse).obj ((e.functor).obj X) : e.inverse.on_iso (nat_iso.app f.fun_inv_id _)
... ≅ X : nat_iso.app e.fun_inv_id _
@[simp] private def feef_iso_id (e : C ≌ D) (f : D ≌ E) (X : E) :
(f.functor).obj ((e.functor).obj ((e.inverse).obj ((f.inverse).obj X))) ≅ X :=
calc
(f.functor).obj ((e.functor).obj ((e.inverse).obj ((f.inverse).obj X)))
≅ (f.functor).obj ((f.inverse).obj X) : f.functor.on_iso (nat_iso.app e.inv_fun_id _)
... ≅ X : nat_iso.app f.inv_fun_id _
@[trans] def trans (e : C ≌ D) (f : D ≌ E) : C ≌ E :=
{ functor := e.functor ⋙ f.functor,
inverse := f.inverse ⋙ e.inverse,
fun_inv_id' := nat_iso.of_components (effe_iso_id e f)
begin
/- `tidy` says -/
intros X Y f_1, dsimp at *, simp at *, dsimp at *,
/- `rewrite_search` says -/
slice_lhs 3 4 { erw [is_iso.hom_inv_id] },
erw [category.id_comp, is_iso.hom_inv_id, category.comp_id],
end,
inv_fun_id' := nat_iso.of_components (feef_iso_id e f)
begin
/- `tidy` says -/
intros X Y f_1, dsimp at *, simp at *, dsimp at *,
/- `rewrite_search` says -/
slice_lhs 3 4 { erw [is_iso.hom_inv_id] },
erw [category.id_comp, is_iso.hom_inv_id, category.comp_id]
end
}
end equivalence
variables {C : Sort u₁} [𝒞 : category.{v₁} C]
include 𝒞
section
variables {D : Sort u₂} [𝒟 : category.{v₂} D]
include 𝒟
class is_equivalence (F : C ⥤ D) :=
(inverse : D ⥤ C)
(fun_inv_id' : (F ⋙ inverse) ≅ (functor.id C) . obviously)
(inv_fun_id' : (inverse ⋙ F) ≅ (functor.id D) . obviously)
restate_axiom is_equivalence.fun_inv_id'
restate_axiom is_equivalence.inv_fun_id'
end
namespace is_equivalence
variables {D : Sort u₂} [𝒟 : category.{v₂} D]
include 𝒟
instance of_equivalence (F : C ≌ D) : is_equivalence (F.functor) :=
{ inverse := F.inverse,
fun_inv_id' := F.fun_inv_id,
inv_fun_id' := F.inv_fun_id }
instance of_equivalence_inverse (F : C ≌ D) : is_equivalence (F.inverse) :=
{ inverse := F.functor,
fun_inv_id' := F.inv_fun_id,
inv_fun_id' := F.fun_inv_id }
end is_equivalence
namespace functor
instance is_equivalence_refl : is_equivalence (functor.id C) :=
{ inverse := functor.id C }
end functor
variables {D : Sort u₂} [𝒟 : category.{v₂} D]
include 𝒟
namespace functor
def inv (F : C ⥤ D) [is_equivalence F] : D ⥤ C :=
is_equivalence.inverse F
instance is_equivalence_symm (F : C ⥤ D) [is_equivalence F] : is_equivalence (F.inv) :=
{ inverse := F,
fun_inv_id' := is_equivalence.inv_fun_id F,
inv_fun_id' := is_equivalence.fun_inv_id F }
def fun_inv_id (F : C ⥤ D) [is_equivalence F] : (F ⋙ F.inv) ≅ functor.id C :=
is_equivalence.fun_inv_id F
def inv_fun_id (F : C ⥤ D) [is_equivalence F] : (F.inv ⋙ F) ≅ functor.id D :=
is_equivalence.inv_fun_id F
def as_equivalence (F : C ⥤ D) [is_equivalence F] : C ≌ D :=
{ functor := F,
inverse := is_equivalence.inverse F,
fun_inv_id' := is_equivalence.fun_inv_id F,
inv_fun_id' := is_equivalence.inv_fun_id F }
variables {E : Sort u₃} [ℰ : category.{v₃} E]
include ℰ
instance is_equivalence_trans (F : C ⥤ D) (G : D ⥤ E) [is_equivalence F] [is_equivalence G] :
is_equivalence (F ⋙ G) :=
is_equivalence.of_equivalence (equivalence.trans (as_equivalence F) (as_equivalence G))
end functor
namespace is_equivalence
instance is_equivalence_functor (e : C ≌ D) : is_equivalence e.functor :=
{ inverse := e.inverse,
fun_inv_id' := e.fun_inv_id,
inv_fun_id' := e.inv_fun_id }
instance is_equivalence_inverse (e : C ≌ D) : is_equivalence e.inverse :=
{ inverse := e.functor,
fun_inv_id' := e.inv_fun_id,
inv_fun_id' := e.fun_inv_id }
@[simp] lemma fun_inv_map (F : C ⥤ D) [is_equivalence F] (X Y : D) (f : X ⟶ Y) :
F.map (F.inv.map f) = (F.inv_fun_id.hom.app X) ≫ f ≫ (F.inv_fun_id.inv.app Y) :=
begin
erw [nat_iso.naturality_2],
refl
end
@[simp] lemma inv_fun_map (F : C ⥤ D) [is_equivalence F] (X Y : C) (f : X ⟶ Y) :
F.inv.map (F.map f) = (F.fun_inv_id.hom.app X) ≫ f ≫ (F.fun_inv_id.inv.app Y) :=
begin
erw [nat_iso.naturality_2],
refl
end
end is_equivalence
class ess_surj (F : C ⥤ D) :=
(obj_preimage (d : D) : C)
(iso' (d : D) : F.obj (obj_preimage d) ≅ d . obviously)
restate_axiom ess_surj.iso'
namespace functor
def obj_preimage (F : C ⥤ D) [ess_surj F] (d : D) : C := ess_surj.obj_preimage.{v₁ v₂} F d
def fun_obj_preimage_iso (F : C ⥤ D) [ess_surj F] (d : D) : F.obj (F.obj_preimage d) ≅ d :=
ess_surj.iso F d
end functor
namespace equivalence
def ess_surj_of_equivalence (F : C ⥤ D) [is_equivalence F] : ess_surj F :=
⟨ λ Y : D, F.inv.obj Y, λ Y : D, (nat_iso.app F.inv_fun_id Y) ⟩
instance faithful_of_equivalence (F : C ⥤ D) [is_equivalence F] : faithful F :=
{ injectivity' := λ X Y f g w,
begin
have p := congr_arg (@category_theory.functor.map _ _ _ _ F.inv _ _) w,
simp at *,
assumption
end }.
instance full_of_equivalence (F : C ⥤ D) [is_equivalence F] : full F :=
{ preimage := λ X Y f, (nat_iso.app F.fun_inv_id X).inv ≫ (F.inv.map f) ≫ (nat_iso.app F.fun_inv_id Y).hom,
witness' := λ X Y f,
begin
apply F.inv.injectivity,
/- obviously can finish from here... -/
dsimp, simp, dsimp,
slice_lhs 4 6 {
rw [←functor.map_comp, ←functor.map_comp],
rw [←is_equivalence.fun_inv_map],
},
slice_lhs 1 2 { simp },
dsimp, simp,
slice_lhs 2 4 {
rw [←functor.map_comp, ←functor.map_comp],
erw [nat_iso.naturality_2],
},
erw [nat_iso.naturality_1],
refl,
end }.
section
@[simp] private def equivalence_inverse (F : C ⥤ D) [full F] [faithful F] [ess_surj F] : D ⥤ C :=
{ obj := λ X, F.obj_preimage X,
map := λ X Y f, F.preimage ((F.fun_obj_preimage_iso X).hom ≫ f ≫ (F.fun_obj_preimage_iso Y).inv),
map_id' := λ X, begin apply F.injectivity, tidy, end,
map_comp' := λ X Y Z f g, by apply F.injectivity; simp }.
def equivalence_of_fully_faithfully_ess_surj
(F : C ⥤ D) [full F] [faithful : faithful F] [ess_surj F] : is_equivalence F :=
{ inverse := equivalence_inverse F,
fun_inv_id' := nat_iso.of_components
(λ X, preimage_iso (F.fun_obj_preimage_iso (F.obj X)))
(λ X Y f, begin apply F.injectivity, obviously, end),
inv_fun_id' := nat_iso.of_components
(λ Y, (F.fun_obj_preimage_iso Y))
(by obviously) }
end
end equivalence
end category_theory
|
f96d04ecccebc1518e40cb813622a91b4c8b2af0 | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /stage0/src/Init/Data/List/BasicAux.lean | a9eeea012734df7564adf430cd0a27e3c8baa8c0 | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,826 | 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
-/
prelude
import Init.Data.List.Basic
import Init.Util
universes u
namespace List
/- The following functions can't be defined at `init.data.list.basic`, because they depend on `init.util`,
and `init.util` depends on `init.data.list.basic`. -/
variables {α : Type u}
def get! [Inhabited α] : Nat → List α → α
| 0, a::as => a
| n+1, a::as => get! n as
| _, _ => panic! "invalid index"
def get? : Nat → List α → Option α
| 0, a::as => some a
| n+1, a::as => get? n as
| _, _ => none
def getD (idx : Nat) (as : List α) (a₀ : α) : α :=
(as.get? idx).getD a₀
def head! [Inhabited α] : List α → α
| [] => panic! "empty list"
| a::_ => a
def head? : List α → Option α
| [] => none
| a::_ => some a
def headD : List α → α → α
| [], a₀ => a₀
| a::_, _ => a
def tail! : List α → List α
| [] => panic! "empty list"
| a::as => as
def tail? : List α → Option (List α)
| [] => none
| a::as => some as
def tailD : List α → List α → List α
| [], as₀ => as₀
| a::as, _ => as
def getLast : ∀ (as : List α), as ≠ [] → α
| [], h => absurd rfl h
| [a], h => a
| a::b::as, h => getLast (b::as) (fun h => List.noConfusion h)
def getLast! [Inhabited α] : List α → α
| [] => panic! "empty list"
| a::as => getLast (a::as) (fun h => List.noConfusion h)
def getLast? : List α → Option α
| [] => none
| a::as => some (getLast (a::as) (fun h => List.noConfusion h))
def getLastD : List α → α → α
| [], a₀ => a₀
| a::as, _ => getLast (a::as) (fun h => List.noConfusion h)
end List
|
1a6c70110e0af1f92d93314cec461d8df6744baf | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/rb_map1.lean | a9903e7a0c142656ce41a4c8f7beb2c605e9cefe | [
"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 | 728 | lean | import system.io
open io
section
open nat_map
#eval size (insert (insert (mk nat) 10 20) 10 21)
meta definition m := (insert (insert (insert (mk nat) 10 20) 5 50) 10 21)
#eval find m 10
#eval find m 5
#eval find m 8
#eval contains m 5
#eval contains m 8
open list
meta definition m2 := of_list [((1:nat), "one"), (2, "two"), (3, "three")]
#eval size m2
#eval find m2 1
#eval find m2 4
#eval find m2 3
section
variable [io.interface]
#eval do pp m2, put_str "\n"
end
#eval m2
end
section
open rb_map
-- Mapping from (nat × nat) → nat
meta definition m3 := insert (insert (mk (nat × nat) nat) (1, 2) 3) (2, 2) 4
#eval find m3 (1, 2)
#eval find m3 (2, 1)
#eval find m3 (2, 2)
variable [io.interface]
#eval pp m3
end
|
8dd43c0ae08747e24a7253f64038ed97a39244b8 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/topology/constructions.lean | f28a49dd791e17612aca4dec23475f8a73da49fe | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 35,753 | 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
open_locale classical topological_space filter
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 coe 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)
instance ulift.topological_space [t : topological_space α] : topological_space (ulift.{v u} α) :=
t.induced ulift.down
/-- The image of a dense set under `quotient.mk` is a dense set. -/
lemma dense.quotient [setoid α] [topological_space α] {s : set α} (H : dense s) :
dense (quotient.mk '' s) :=
(surjective_quotient_mk α).dense_range.dense_image continuous_coinduced_rng H
/-- The composition of `quotient.mk` and a function with dense range has dense range. -/
lemma dense_range.quotient [setoid α] [topological_space α] {f : β → α} (hf : dense_range f) :
dense_range (quotient.mk ∘ f) :=
(surjective_quotient_mk α).dense_range.comp hf continuous_coinduced_rng
instance {p : α → Prop} [topological_space α] [discrete_topology α] :
discrete_topology (subtype p) :=
⟨bot_unique $ assume s hs,
⟨coe '' s, is_open_discrete _, (set.preimage_image_eq _ subtype.coe_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 : α), coe ⁻¹' u ⊆ t :=
mem_nhds_induced coe a t
theorem nhds_subtype (s : set α) (a : {x // x ∈ s}) :
𝓝 a = comap coe (𝓝 (a : α)) :=
nhds_induced coe a
end topα
end constructions
section prod
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
@[continuity] lemma continuous_fst : continuous (@prod.fst α β) :=
continuous_inf_dom_left continuous_induced_dom
lemma continuous_at_fst {p : α × β} : continuous_at prod.fst p :=
continuous_fst.continuous_at
@[continuity] lemma continuous_snd : continuous (@prod.snd α β) :=
continuous_inf_dom_right continuous_induced_dom
lemma continuous_at_snd {p : α × β} : continuous_at prod.snd p :=
continuous_snd.continuous_at
@[continuity] lemma continuous.prod_mk {f : γ → α} {g : γ → β}
(hf : continuous f) (hg : continuous g) : continuous (λx, (f x, g x)) :=
continuous_inf_rng (continuous_induced_rng hf) (continuous_induced_rng hg)
lemma continuous.prod_map {f : γ → α} {g : δ → β} (hf : continuous f) (hg : continuous g) :
continuous (λ x : γ × δ, (f x.1, g x.2)) :=
(hf.comp continuous_fst).prod_mk (hg.comp continuous_snd)
lemma filter.eventually.prod_inl_nhds {p : α → Prop} {a : α} (h : ∀ᶠ x in 𝓝 a, p x) (b : β) :
∀ᶠ x in 𝓝 (a, b), p (x : α × β).1 :=
continuous_at_fst h
lemma filter.eventually.prod_inr_nhds {p : β → Prop} {b : β} (h : ∀ᶠ x in 𝓝 b, p x) (a : α) :
∀ᶠ x in 𝓝 (a, b), p (x : α × β).2 :=
continuous_at_snd h
lemma filter.eventually.prod_mk_nhds {pa : α → Prop} {a} (ha : ∀ᶠ x in 𝓝 a, pa x)
{pb : β → Prop} {b} (hb : ∀ᶠ y in 𝓝 b, pb y) :
∀ᶠ p in 𝓝 (a, b), pa (p : α × β).1 ∧ pb p.2 :=
(ha.prod_inl_nhds b).and (hb.prod_inr_nhds a)
lemma continuous_swap : continuous (prod.swap : α × β → β × α) :=
continuous.prod_mk continuous_snd continuous_fst
lemma continuous_uncurry_left {f : α → β → γ} (a : α)
(h : continuous (function.uncurry f)) : continuous (f a) :=
show continuous (function.uncurry f ∘ (λ b, (a, b))), from h.comp (by continuity)
lemma continuous_uncurry_right {f : α → β → γ} (b : β)
(h : continuous (function.uncurry f)) : continuous (λ a, f a b) :=
show continuous (function.uncurry f ∘ (λ a, (a, b))), from h.comp (by continuity)
lemma continuous_curry {g : α × β → γ} (a : α)
(h : continuous g) : continuous (function.curry g a) :=
show continuous (g ∘ (λ b, (a, b))), from h.comp (by continuity)
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 (hs.preimage continuous_fst) (ht.preimage continuous_snd)
lemma nhds_prod_eq {a : α} {b : β} : 𝓝 (a, b) = 𝓝 a ×ᶠ 𝓝 b :=
by rw [filter.prod, prod.topological_space, nhds_inf, nhds_induced, nhds_induced]
lemma mem_nhds_prod_iff {a : α} {b : β} {s : set (α × β)} :
s ∈ 𝓝 (a, b) ↔ ∃ (u ∈ 𝓝 a) (v ∈ 𝓝 b), set.prod u v ⊆ s :=
by rw [nhds_prod_eq, mem_prod_iff]
lemma filter.has_basis.prod_nhds {ιa ιb : Type*} {pa : ιa → Prop} {pb : ιb → Prop}
{sa : ιa → set α} {sb : ιb → set β} {a : α} {b : β} (ha : (𝓝 a).has_basis pa sa)
(hb : (𝓝 b).has_basis pb sb) :
(𝓝 (a, b)).has_basis (λ i : ιa × ιb, pa i.1 ∧ pb i.2) (λ i, (sa i.1).prod (sb i.2)) :=
by { rw nhds_prod_eq, exact ha.prod hb }
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 filter.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 filter.eventually.curry_nhds {p : α × β → Prop} {x : α} {y : β} (h : ∀ᶠ x in 𝓝 (x, y), p x) :
∀ᶠ x' in 𝓝 x, ∀ᶠ y' in 𝓝 y, p (x', y') :=
by { rw [nhds_prod_eq] at h, exact h.curry }
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 :=
hf.prod_mk_nhds hg
lemma continuous_at.prod_map {f : α → γ} {g : β → δ} {p : α × β}
(hf : continuous_at f p.fst) (hg : continuous_at g p.snd) :
continuous_at (λ p : α × β, (f p.1, g p.2)) p :=
(hf.comp continuous_fst.continuous_at).prod (hg.comp continuous_snd.continuous_at)
lemma continuous_at.prod_map' {f : α → γ} {g : β → δ} {x : α} {y : β}
(hf : continuous_at f x) (hg : continuous_at g y) :
continuous_at (λ p : α × β, (f p.1, g p.2)) (x, y) :=
have hf : continuous_at f (x, y).fst, from hf,
have hg : continuous_at g (x, y).snd, from hg,
hf.prod_map 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 ▸ hs.prod 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_rw [le_principal_iff, prod.forall,
((nhds_basis_opens _).prod_nhds (nhds_basis_opens _)).mem_iff, prod.exists, exists_prop],
simp only [and_assoc, and.left_comm]
end
lemma continuous_uncurry_of_discrete_topology_left [discrete_topology α]
{f : α → β → γ} (h : ∀ a, continuous (f a)) : continuous (function.uncurry f) :=
continuous_iff_continuous_at.2 $ λ ⟨a, b⟩,
by simp only [continuous_at, nhds_prod_eq, nhds_discrete α, pure_prod, tendsto_map'_iff, (∘),
function.uncurry, (h a).tendsto]
/-- Given a neighborhood `s` of `(x, x)`, then `(x, x)` has a square open neighborhood
that is a subset of `s`. -/
lemma exists_nhds_square {s : set (α × α)} {x : α} (hx : s ∈ 𝓝 (x, x)) :
∃U, is_open U ∧ x ∈ U ∧ set.prod U U ⊆ s :=
by simpa [nhds_prod_eq, (nhds_basis_opens x).prod_self.mem_iff, and.assoc, and.left_comm] using hx
/-- 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
rw is_open_map_iff_nhds_le,
rintro ⟨x, y⟩ s hs,
rcases mem_nhds_prod_iff.1 hs with ⟨tx, htx, ty, hty, ht⟩,
simp only [subset_def, prod.forall, mem_prod] at ht,
exact mem_sets_of_superset htx (λ x hx, ht x y ⟨hx, mem_of_nhds hty⟩)
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. -/
rw is_open_map_iff_nhds_le,
rintro ⟨x, y⟩ s hs,
rcases mem_nhds_prod_iff.1 hs with ⟨tx, htx, ty, hty, ht⟩,
simp only [subset_def, prod.forall, mem_prod] at ht,
exact mem_sets_of_superset hty (λ y hy, ht x y ⟨mem_of_nhds htx, hy⟩)
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
cases (set.prod s t).eq_empty_or_nonempty with h h,
{ simp [h, prod_eq_empty_iff.1 h] },
{ have st : s.nonempty ∧ t.nonempty, from prod_nonempty_iff.1 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 only [st.1.ne_empty, st.2.ne_empty, not_false_iff, or_false] at H,
exact H.1.prod 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 (𝓝 a ×ᶠ 𝓝 b) ⊓ 𝓟 (set.prod s t) = (𝓝 a ⊓ 𝓟 s) ×ᶠ (𝓝 b ⊓ 𝓟 t),
by rw [←prod_inf_prod, prod_principal_principal],
by simp [closure_eq_cluster_pts, cluster_pt, nhds_prod_eq, this]; exact prod_ne_bot
lemma map_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
map_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 only [h₁.closure_eq, h₂.closure_eq, closure_prod_eq]
/-- The product of two dense sets is a dense set. -/
lemma dense.prod {s : set α} {t : set β} (hs : dense s) (ht : dense t) :
dense (s.prod t) :=
λ x, by { rw closure_prod_eq, exact ⟨hs x.1, ht x.2⟩ }
/-- If `f` and `g` are maps with dense range, then `prod.map f g` has dense range. -/
lemma dense_range.prod_map {ι : Type*} {κ : Type*} {f : ι → β} {g : κ → γ}
(hf : dense_range f) (hg : dense_range g) : dense_range (prod.map f g) :=
by simpa only [dense_range, prod_range_range_eq] using hf.prod hg
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
open sum
variables [topological_space α] [topological_space β] [topological_space γ]
@[continuity] lemma continuous_inl : continuous (@inl α β) :=
continuous_sup_rng_left continuous_coinduced_rng
@[continuity] lemma continuous_inr : continuous (@inr α β) :=
continuous_sup_rng_right continuous_coinduced_rng
@[continuity] lemma continuous_sum_rec {f : α → γ} {g : β → γ}
(hf : continuous f) (hg : continuous g) : @continuous (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) :=
begin
apply continuous_sup_dom;
rw continuous_def at hf hg ⊢;
assumption
end
lemma is_open_sum_iff {s : set (α ⊕ β)} :
is_open s ↔ is_open (inl ⁻¹' s) ∧ is_open (inr ⁻¹' s) :=
iff.rfl
lemma is_open_map_sum {f : α ⊕ β → γ}
(h₁ : is_open_map (λ a, f (inl a))) (h₂ : is_open_map (λ b, f (inr b))) :
is_open_map f :=
begin
intros u hu,
rw is_open_sum_iff at hu,
cases hu with hu₁ hu₂,
have : u = inl '' (inl ⁻¹' u) ∪ inr '' (inr ⁻¹' u),
{ ext (_|_); simp },
rw [this, set.image_union, set.image_image, set.image_image],
exact is_open_union (h₁ _ hu₁) (h₂ _ hu₂)
end
lemma embedding_inl : embedding (@inl α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact le_sup_left },
{ intros u hu, existsi (inl '' u),
change
(is_open (inl ⁻¹' (@inl α β '' u)) ∧
is_open (inr ⁻¹' (@inl α β '' u))) ∧
inl ⁻¹' (inl '' u) = u,
have : inl ⁻¹' (@inl α β '' u) = u :=
preimage_image_eq u (λ _ _, inl.inj_iff.mp), rw this,
have : inr ⁻¹' (@inl α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume a ⟨b, _, h⟩, inl_ne_inr h), rw this,
exact ⟨⟨hu, is_open_empty⟩, rfl⟩ }
end,
inj := λ _ _, inl.inj_iff.mp }
lemma embedding_inr : embedding (@inr α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact le_sup_right },
{ intros u hu, existsi (inr '' u),
change
(is_open (inl ⁻¹' (@inr α β '' u)) ∧
is_open (inr ⁻¹' (@inr α β '' u))) ∧
inr ⁻¹' (inr '' u) = u,
have : inl ⁻¹' (@inr α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume b ⟨a, _, h⟩, inr_ne_inl h), rw this,
have : inr ⁻¹' (@inr α β '' u) = u :=
preimage_image_eq u (λ _ _, inr.inj_iff.mp), rw this,
exact ⟨⟨is_open_empty, hu⟩, rfl⟩ }
end,
inj := λ _ _, inr.inj_iff.mp }
lemma is_open_range_inl : is_open (range (inl : α → α ⊕ β)) :=
is_open_sum_iff.2 $ by simp
lemma is_open_range_inr : is_open (range (inr : β → α ⊕ β)) :=
is_open_sum_iff.2 $ by simp
lemma open_embedding_inl : open_embedding (inl : α → α ⊕ β) :=
{ open_range := is_open_range_inl,
.. embedding_inl }
lemma open_embedding_inr : open_embedding (inr : β → α ⊕ β) :=
{ open_range := is_open_range_inr,
.. embedding_inr }
end sum
section subtype
variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop}
lemma embedding_subtype_coe : embedding (coe : subtype p → α) :=
⟨⟨rfl⟩, subtype.coe_injective⟩
@[continuity] lemma continuous_subtype_val : continuous (@subtype.val α p) :=
continuous_induced_dom
lemma continuous_subtype_coe : continuous (coe : subtype p → α) :=
continuous_subtype_val
lemma is_open.open_embedding_subtype_coe {s : set α} (hs : is_open s) :
open_embedding (coe : s → α) :=
{ induced := rfl,
inj := subtype.coe_injective,
open_range := (subtype.range_coe : range coe = s).symm ▸ hs }
lemma is_open.is_open_map_subtype_coe {s : set α} (hs : is_open s) :
is_open_map (coe : s → α) :=
hs.open_embedding_subtype_coe.is_open_map
lemma is_open_map.restrict {f : α → β} (hf : is_open_map f) {s : set α} (hs : is_open s) :
is_open_map (s.restrict f) :=
hf.comp hs.is_open_map_subtype_coe
lemma is_closed.closed_embedding_subtype_coe {s : set α} (hs : is_closed s) :
closed_embedding (coe : {x // x ∈ s} → α) :=
{ induced := rfl,
inj := subtype.coe_injective,
closed_range := (subtype.range_coe : range coe = s).symm ▸ hs }
@[continuity] 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_coe
lemma continuous_at_subtype_coe {p : α → Prop} {a : subtype p} :
continuous_at (coe : subtype p → α) a :=
continuous_iff_continuous_at.mp continuous_subtype_coe _
lemma map_nhds_subtype_coe_eq {a : α} (ha : p a) (h : {a | p a} ∈ 𝓝 a) :
map (coe : subtype p → α) (𝓝 ⟨a, ha⟩) = 𝓝 a :=
map_nhds_induced_eq $ by simpa only [subtype.coe_mk, subtype.range_coe] using h
lemma nhds_subtype_eq_comap {a : α} {h : p a} :
𝓝 (⟨a, h⟩ : subtype p) = comap coe (𝓝 a) :=
nhds_induced _ _
lemma tendsto_subtype_rng {β : Type*} {p : α → Prop} {b : filter β} {f : β → subtype p} :
∀{a:subtype p}, tendsto f b (𝓝 a) ↔ tendsto (λx, (f x : α)) b (𝓝 (a : α))
| ⟨a, ha⟩ := by rw [nhds_subtype_eq_comap, tendsto_comap_iff, subtype.coe_mk]
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)) :
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 coe (𝓝 x')) :
congr_arg (map f) (map_nhds_subtype_coe_eq _ $ c_sets).symm
... = map (λx:subtype (c i), f x) (𝓝 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)) :
continuous f :=
continuous_iff_is_closed.mpr $
assume s hs,
have ∀i, is_closed ((coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' s)),
from assume i,
embedding_is_closed embedding_subtype_coe
(by simp [subtype.range_coe]; exact h_is_closed i)
(continuous_iff_is_closed.mp (f_cont i) _ hs),
have is_closed (⋃i, (coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' 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, (coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' 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⟩,
simpa [and.comm, @and.left_comm (c _ _), ← exists_and_distrib_right],
end,
by rwa [this]
lemma closure_subtype {x : {a // p a}} {s : set {a // p a}}:
x ∈ closure s ↔ (x : α) ∈ closure ((coe : _ → α) '' 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⟩
@[continuity] lemma continuous_quot_mk : continuous (@quot.mk α r) :=
continuous_coinduced_rng
@[continuity] 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*}
@[continuity]
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
@[continuity]
lemma continuous_apply [∀i, topological_space (π i)] (i : ι) :
continuous (λp:Πi, π i, p i) :=
continuous_infi_dom continuous_induced_dom
/-- Embedding a factor into a product space (by fixing arbitrarily all the other coordinates) is
continuous. -/
@[continuity]
lemma continuous_update [decidable_eq ι] [∀i, topological_space (π i)] {i : ι} {f : Πi:ι, π i} :
continuous (λ x : π i, function.update f i x) :=
begin
refine continuous_pi (λj, _),
by_cases h : j = i,
{ rw h,
simpa using continuous_id },
{ simpa [h] using continuous_const }
end
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 tendsto_pi [t : ∀i, topological_space (π i)] {f : α → Πi, π i} {g : Πi, π i} {u : filter α} :
tendsto f u (𝓝 g) ↔ ∀ x, tendsto (λ i, f i x) u (𝓝 (g x)) :=
by simp [nhds_pi, filter.tendsto_comap_iff]
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, (hs _ ha).preimage (continuous_apply _))
lemma set_pi_mem_nhds [Π a, topological_space (π a)] {i : set ι} {s : Π a, set (π a)}
{x : Π a, π a} (hi : finite i) (hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) :
pi i s ∈ 𝓝 x :=
by { rw [pi_def, bInter_mem_sets hi], exact λ a ha, (continuous_apply a).continuous_at (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} :=
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)]
@[continuity]
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 _ sigma_mk_injective },
{ 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 _ sigma_mk_injective },
{ 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 sigma_mk_injective 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 sigma_mk_injective 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. -/
@[continuity]
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))
@[continuity]
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 ⟨⟨_⟩, function.injective_id.sigma_map (λ 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 ⟨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
section ulift
@[continuity] lemma continuous_ulift_down [topological_space α] :
continuous (ulift.down : ulift.{v u} α → α) :=
continuous_induced_dom
@[continuity] lemma continuous_ulift_up [topological_space α] :
continuous (ulift.up : α → ulift.{v u} α) :=
continuous_induced_rng continuous_id
end ulift
lemma mem_closure_of_continuous [topological_space α] [topological_space β]
{f : α → β} {a : α} {s : set α} {t : set β}
(hf : continuous f) (ha : a ∈ closure s) (h : maps_to f s (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 t : closure_minimal h.image_subset is_closed_closure
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₂
|
ad8e925c11cb4a97010782a89d935966dff47085 | 947b78d97130d56365ae2ec264df196ce769371a | /stage0/src/Lean/Elab/CollectFVars.lean | 98fe1a38dc67bc60e12cd4364d4f049a6e9faee9 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,387 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.Util.CollectFVars
import Lean.Elab.Term
namespace Lean
namespace Elab
namespace Term
open Meta
def collectUsedFVars (e : Expr) : StateRefT CollectFVars.State TermElabM Unit := do
e ← instantiateMVars e;
modify fun used => collectFVars used e
def collectUsedFVarsAtFVars (fvars : Array Expr) : StateRefT CollectFVars.State TermElabM Unit :=
fvars.forM fun fvar => do
fvarType ← inferType fvar;
collectUsedFVars fvarType
def removeUnused (vars : Array Expr) (used : CollectFVars.State) : TermElabM (LocalContext × LocalInstances × Array Expr) := do
localInsts ← getLocalInstances;
lctx ← getLCtx;
(lctx, localInsts, newVars, _) ← vars.foldrM
(fun var (result : LocalContext × LocalInstances × Array Expr × CollectFVars.State) =>
let (lctx, localInsts, newVars, used) := result;
if used.fvarSet.contains var.fvarId! then do
varType ← inferType var;
(_, used) ← (collectUsedFVars varType).run used;
pure (lctx, localInsts, newVars.push var, used)
else
pure (lctx.erase var.fvarId!, localInsts.erase var.fvarId!, newVars, used))
(lctx, localInsts, #[], used);
pure (lctx, localInsts, newVars.reverse)
end Term
end Elab
end Lean
|
0f684ac4227761e9afc47d871e20c41d3a36de3d | 968e2f50b755d3048175f176376eff7139e9df70 | /examples/prop_logic_theory/unnamed_1266.lean | b770052a13a0bd436d1381a2100865729af3f8d9 | [] | no_license | gihanmarasingha/mth1001_sphinx | 190a003269ba5e54717b448302a27ca26e31d491 | 05126586cbf5786e521be1ea2ef5b4ba3c44e74a | refs/heads/master | 1,672,913,933,677 | 1,604,516,583,000 | 1,604,516,583,000 | 309,245,750 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 227 | lean | variables (p : Prop)
-- BEGIN
example : p ↔ p :=
begin
split; -- By iff introduction, it suffices to prove `p → p` and `p → p`.
{ exact id }, -- We close both subgoals by reflexivity of implication.
end
-- END |
b31f23530fd00ec1815df3123a313dbc23045ee8 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /library/logic/identities.lean | 97772f093aa660a4f1c5df38278c5e163e074d78 | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,789 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
Useful logical identities. Since we are not using propositional extensionality, some of the
calculations use the type class support provided by logic.instances.
-/
import logic.connectives logic.instances logic.quantifiers logic.cast
open relation decidable relation.iff_ops
theorem or.right_comm (a b c : Prop) : (a ∨ b) ∨ c ↔ (a ∨ c) ∨ b :=
calc
(a ∨ b) ∨ c ↔ a ∨ (b ∨ c) : or.assoc
... ↔ a ∨ (c ∨ b) : {or.comm}
... ↔ (a ∨ c) ∨ b : iff.symm or.assoc
theorem or.left_comm [simp] (a b c : Prop) : a ∨ (b ∨ c) ↔ b ∨ (a ∨ c) :=
calc
a ∨ (b ∨ c) ↔ (a ∨ b) ∨ c : iff.symm or.assoc
... ↔ (b ∨ a) ∨ c : {or.comm}
... ↔ b ∨ (a ∨ c) : or.assoc
theorem and.right_comm (a b c : Prop) : (a ∧ b) ∧ c ↔ (a ∧ c) ∧ b :=
calc
(a ∧ b) ∧ c ↔ a ∧ (b ∧ c) : and.assoc
... ↔ a ∧ (c ∧ b) : {and.comm}
... ↔ (a ∧ c) ∧ b : iff.symm and.assoc
theorem or_not_self_iff {a : Prop} [D : decidable a] : a ∨ ¬ a ↔ true :=
iff.intro (assume H, trivial) (assume H, em a)
theorem not_or_self_iff {a : Prop} [D : decidable a] : ¬ a ∨ a ↔ true :=
!or.comm ▸ !or_not_self_iff
theorem and_not_self_iff {a : Prop} : a ∧ ¬ a ↔ false :=
iff.intro (assume H, (and.right H) (and.left H)) (assume H, false.elim H)
theorem not_and_self_iff {a : Prop} : ¬ a ∧ a ↔ false :=
!and.comm ▸ !and_not_self_iff
theorem and.left_comm [simp] (a b c : Prop) : a ∧ (b ∧ c) ↔ b ∧ (a ∧ c) :=
calc
a ∧ (b ∧ c) ↔ (a ∧ b) ∧ c : iff.symm and.assoc
... ↔ (b ∧ a) ∧ c : {and.comm}
... ↔ b ∧ (a ∧ c) : and.assoc
theorem not_not_iff {a : Prop} [D : decidable a] : (¬¬a) ↔ a :=
iff.intro by_contradiction not_not_intro
theorem not_not_elim {a : Prop} [D : decidable a] : ¬¬a → a :=
by_contradiction
theorem not_or_iff_not_and_not {a b : Prop} : ¬(a ∨ b) ↔ ¬a ∧ ¬b :=
or.imp_distrib
theorem not_and_iff_not_or_not {a b : Prop} [Da : decidable a] :
¬(a ∧ b) ↔ ¬a ∨ ¬b :=
iff.intro
(λH, by_cases (λa, or.inr (not.mto (and.intro a) H)) or.inl)
(or.rec (not.mto and.left) (not.mto and.right))
theorem or_iff_not_and_not {a b : Prop} [Da : decidable a] [Db : decidable b] :
a ∨ b ↔ ¬ (¬a ∧ ¬b) :=
by rewrite [-not_or_iff_not_and_not, not_not_iff]
theorem and_iff_not_or_not {a b : Prop} [Da : decidable a] [Db : decidable b] :
a ∧ b ↔ ¬ (¬ a ∨ ¬ b) :=
by rewrite [-not_and_iff_not_or_not, not_not_iff]
theorem imp_iff_not_or {a b : Prop} [Da : decidable a] : (a → b) ↔ ¬a ∨ b :=
iff.intro
(by_cases (λHa H, or.inr (H Ha)) (λHa H, or.inl Ha))
(or.rec not.elim imp.intro)
theorem not_implies_iff_and_not {a b : Prop} [Da : decidable a] :
¬(a → b) ↔ a ∧ ¬b :=
calc
¬(a → b) ↔ ¬(¬a ∨ b) : {imp_iff_not_or}
... ↔ ¬¬a ∧ ¬b : not_or_iff_not_and_not
... ↔ a ∧ ¬b : {not_not_iff}
theorem peirce {a b : Prop} [D : decidable a] : ((a → b) → a) → a :=
by_cases imp.intro (imp.syl imp.mp not.elim)
theorem forall_not_of_not_exists {A : Type} {p : A → Prop} [D : ∀x, decidable (p x)]
(H : ¬∃x, p x) : ∀x, ¬p x :=
take x, by_cases
(assume Hp : p x, absurd (exists.intro x Hp) H)
imp.id
theorem forall_of_not_exists_not {A : Type} {p : A → Prop} [D : decidable_pred p] :
¬(∃ x, ¬p x) → ∀ x, p x :=
imp.syl (forall_imp_forall (λa, not_not_elim)) forall_not_of_not_exists
theorem exists_not_of_not_forall {A : Type} {p : A → Prop} [D : ∀x, decidable (p x)]
[D' : decidable (∃x, ¬p x)] (H : ¬∀x, p x) :
∃x, ¬p x :=
by_contradiction (λH1, absurd (λx, not_not_elim (forall_not_of_not_exists H1 x)) H)
theorem exists_of_not_forall_not {A : Type} {p : A → Prop} [D : ∀x, decidable (p x)]
[D' : decidable (∃x, p x)] (H : ¬∀x, ¬ p x) :
∃x, p x :=
by_contradiction (imp.syl H forall_not_of_not_exists)
theorem ne_self_iff_false {A : Type} (a : A) : (a ≠ a) ↔ false :=
iff.intro false.of_ne false.elim
theorem eq_self_iff_true [simp] {A : Type} (a : A) : (a = a) ↔ true :=
iff_true_intro rfl
theorem heq_self_iff_true [simp] {A : Type} (a : A) : (a == a) ↔ true :=
iff_true_intro (heq.refl a)
theorem iff_not_self [simp] (a : Prop) : (a ↔ ¬a) ↔ false :=
iff_false_intro (λH,
have H' : ¬a, from (λHa, (mp H Ha) Ha),
H' (iff.mpr H H'))
theorem true_iff_false [simp] : (true ↔ false) ↔ false :=
not_true ▸ (iff_not_self true)
theorem false_iff_true [simp] : (false ↔ true) ↔ false :=
not_false_iff ▸ (iff_not_self false)
|
8339ee4e037a53f7e78b0b7faa3ade48bdbf4efd | 80746c6dba6a866de5431094bf9f8f841b043d77 | /src/category_theory/examples/measurable_space.lean | 6b991d29d23470b336a3c81dc9f7048f1994824b | [
"Apache-2.0"
] | permissive | leanprover-fork/mathlib-backup | 8b5c95c535b148fca858f7e8db75a76252e32987 | 0eb9db6a1a8a605f0cf9e33873d0450f9f0ae9b0 | refs/heads/master | 1,585,156,056,139 | 1,548,864,430,000 | 1,548,864,438,000 | 143,964,213 | 0 | 0 | Apache-2.0 | 1,550,795,966,000 | 1,533,705,322,000 | Lean | UTF-8 | Lean | false | false | 888 | lean | /- Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
Basic setup for measurable spaces.
-/
import category_theory.examples.topological_spaces
import measure_theory.borel_space
open category_theory
universes u v
namespace category_theory.examples
@[reducible] def Meas : Type (u+1) := bundled measurable_space
instance (x : Meas) : measurable_space x := x.str
namespace Meas
instance : concrete_category @measurable := ⟨@measurable_id, @measurable.comp⟩
-- -- If `measurable` were a class, we would summon instances:
-- local attribute [class] measurable
-- instance {X Y : Meas} (f : X ⟶ Y) : measurable (f : X → Y) := f.2
end Meas
def Borel : Top ⥤ Meas :=
concrete_functor @measure_theory.borel @measure_theory.measurable_of_continuous
end category_theory.examples
|
cb7a33cbb5687eaee36327bbb91a3d462e807bc9 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/algebraic_geometry/prime_spectrum.lean | d73f5be921f10c3d88850dc9b578779cb00916d1 | [
"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 | 14,283 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import topology.opens
import ring_theory.ideal.prod
import linear_algebra.finsupp
import algebra.punit_instances
/-!
# Prime spectrum of a commutative ring
The prime spectrum of a commutative ring is the type of all prime ideals.
It is naturally endowed with a topology: the Zariski topology.
(It is also naturally endowed with a sheaf of rings,
which is constructed in `algebraic_geometry.structure_sheaf`.)
## Main definitions
* `prime_spectrum R`: The prime spectrum of a commutative ring `R`,
i.e., the set of all prime ideals of `R`.
* `zero_locus s`: The zero locus of a subset `s` of `R`
is the subset of `prime_spectrum R` consisting of all prime ideals that contain `s`.
* `vanishing_ideal t`: The vanishing ideal of a subset `t` of `prime_spectrum R`
is the intersection of points in `t` (viewed as prime ideals).
## Conventions
We denote subsets of rings with `s`, `s'`, etc...
whereas we denote subsets of prime spectra with `t`, `t'`, etc...
## Inspiration/contributors
The contents of this file draw inspiration from
<https://github.com/ramonfmir/lean-scheme>
which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau,
and Chris Hughes (on an earlier repository).
-/
noncomputable theory
open_locale classical
universe variables u v
variables (R : Type u) [comm_ring R]
/-- The prime spectrum of a commutative ring `R`
is the type of all prime ideals of `R`.
It is naturally endowed with a topology (the Zariski topology),
and a sheaf of commutative rings (see `algebraic_geometry.structure_sheaf`).
It is a fundamental building block in algebraic geometry. -/
@[nolint has_inhabited_instance]
def prime_spectrum := {I : ideal R // I.is_prime}
variable {R}
namespace prime_spectrum
/-- A method to view a point in the prime spectrum of a commutative ring
as an ideal of that ring. -/
abbreviation as_ideal (x : prime_spectrum R) : ideal R := x.val
instance is_prime (x : prime_spectrum R) :
x.as_ideal.is_prime := x.2
/--
The prime spectrum of the zero ring is empty.
-/
lemma punit (x : prime_spectrum punit) : false :=
x.1.ne_top_iff_one.1 x.2.1 $ subsingleton.elim (0 : punit) 1 ▸ x.1.zero_mem
section
variables (R) (S : Type v) [comm_ring S]
/-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of
`R` and the prime spectrum of `S`. -/
noncomputable def prime_spectrum_prod :
prime_spectrum (R × S) ≃ prime_spectrum R ⊕ prime_spectrum S :=
ideal.prime_ideals_equiv R S
variables {R S}
@[simp] lemma prime_spectrum_prod_symm_inl_as_ideal (x : prime_spectrum R) :
((prime_spectrum_prod R S).symm (sum.inl x)).as_ideal = ideal.prod x.as_ideal ⊤ :=
by { cases x, refl }
@[simp] lemma prime_spectrum_prod_symm_inr_as_ideal (x : prime_spectrum S) :
((prime_spectrum_prod R S).symm (sum.inr x)).as_ideal = ideal.prod ⊤ x.as_ideal :=
by { cases x, refl }
end
@[ext] lemma ext {x y : prime_spectrum R} :
x = y ↔ x.as_ideal = y.as_ideal :=
subtype.ext_iff_val
/-- The zero locus of a set `s` of elements of a commutative ring `R`
is the set of all prime ideals of the ring that contain the set `s`.
An element `f` of `R` can be thought of as a dependent function
on the prime spectrum of `R`.
At a point `x` (a prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`.
In this manner, `zero_locus s` is exactly the subset of `prime_spectrum R`
where all "functions" in `s` vanish simultaneously.
-/
def zero_locus (s : set R) : set (prime_spectrum R) :=
{x | s ⊆ x.as_ideal}
@[simp] lemma mem_zero_locus (x : prime_spectrum R) (s : set R) :
x ∈ zero_locus s ↔ s ⊆ x.as_ideal := iff.rfl
@[simp] lemma zero_locus_span (s : set R) :
zero_locus (ideal.span s : set R) = zero_locus s :=
by { ext x, exact (submodule.gi R R).gc s x.as_ideal }
/-- The vanishing ideal of a set `t` of points
of the prime spectrum of a commutative ring `R`
is the intersection of all the prime ideals in the set `t`.
An element `f` of `R` can be thought of as a dependent function
on the prime spectrum of `R`.
At a point `x` (a prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`.
In this manner, `vanishing_ideal t` is exactly the ideal of `R`
consisting of all "functions" that vanish on all of `t`.
-/
def vanishing_ideal (t : set (prime_spectrum R)) : ideal R :=
⨅ (x : prime_spectrum R) (h : x ∈ t), x.as_ideal
lemma coe_vanishing_ideal (t : set (prime_spectrum R)) :
(vanishing_ideal t : set R) = {f : R | ∀ x : prime_spectrum R, x ∈ t → f ∈ x.as_ideal} :=
begin
ext f,
rw [vanishing_ideal, submodule.mem_coe, submodule.mem_infi],
apply forall_congr, intro x,
rw [submodule.mem_infi],
end
lemma mem_vanishing_ideal (t : set (prime_spectrum R)) (f : R) :
f ∈ vanishing_ideal t ↔ ∀ x : prime_spectrum R, x ∈ t → f ∈ x.as_ideal :=
by rw [← submodule.mem_coe, coe_vanishing_ideal, set.mem_set_of_eq]
lemma subset_zero_locus_iff_le_vanishing_ideal (t : set (prime_spectrum R)) (I : ideal R) :
t ⊆ zero_locus I ↔ I ≤ vanishing_ideal t :=
begin
split; intro h,
{ intros f hf,
rw [mem_vanishing_ideal],
intros x hx,
have hxI := h hx,
rw mem_zero_locus at hxI,
exact hxI hf },
{ intros x hx,
rw mem_zero_locus,
refine le_trans h _,
intros f hf,
rw [mem_vanishing_ideal] at hf,
exact hf x hx }
end
section gc
variable (R)
/-- `zero_locus` and `vanishing_ideal` form a galois connection. -/
lemma gc : @galois_connection
(ideal R) (order_dual (set (prime_spectrum R))) _ _
(λ I, zero_locus I) (λ t, vanishing_ideal t) :=
λ I t, subset_zero_locus_iff_le_vanishing_ideal t I
/-- `zero_locus` and `vanishing_ideal` form a galois connection. -/
lemma gc_set : @galois_connection
(set R) (order_dual (set (prime_spectrum R))) _ _
(λ s, zero_locus s) (λ t, vanishing_ideal t) :=
have ideal_gc : galois_connection (ideal.span) coe := (submodule.gi R R).gc,
by simpa [zero_locus_span, function.comp] using galois_connection.compose _ _ _ _ ideal_gc (gc R)
lemma subset_zero_locus_iff_subset_vanishing_ideal (t : set (prime_spectrum R)) (s : set R) :
t ⊆ zero_locus s ↔ s ⊆ vanishing_ideal t :=
(gc_set R) s t
end gc
-- TODO: we actually get the radical ideal,
-- but I think that isn't in mathlib yet.
lemma subset_vanishing_ideal_zero_locus (s : set R) :
s ⊆ vanishing_ideal (zero_locus s) :=
(gc_set R).le_u_l s
lemma le_vanishing_ideal_zero_locus (I : ideal R) :
I ≤ vanishing_ideal (zero_locus I) :=
(gc R).le_u_l I
lemma subset_zero_locus_vanishing_ideal (t : set (prime_spectrum R)) :
t ⊆ zero_locus (vanishing_ideal t) :=
(gc R).l_u_le t
lemma zero_locus_bot :
zero_locus ((⊥ : ideal R) : set R) = set.univ :=
(gc R).l_bot
@[simp] lemma zero_locus_singleton_zero :
zero_locus (0 : set R) = set.univ :=
zero_locus_bot
@[simp] lemma zero_locus_empty :
zero_locus (∅ : set R) = set.univ :=
(gc_set R).l_bot
@[simp] lemma vanishing_ideal_univ :
vanishing_ideal (∅ : set (prime_spectrum R)) = ⊤ :=
by simpa using (gc R).u_top
lemma zero_locus_empty_of_one_mem {s : set R} (h : (1:R) ∈ s) :
zero_locus s = ∅ :=
begin
rw set.eq_empty_iff_forall_not_mem,
intros x hx,
rw mem_zero_locus at hx,
have x_prime : x.as_ideal.is_prime := by apply_instance,
have eq_top : x.as_ideal = ⊤, { rw ideal.eq_top_iff_one, exact hx h },
apply x_prime.1 eq_top,
end
lemma zero_locus_empty_iff_eq_top {I : ideal R} :
zero_locus (I : set R) = ∅ ↔ I = ⊤ :=
begin
split,
{ contrapose!,
intro h,
apply set.ne_empty_iff_nonempty.mpr,
rcases ideal.exists_le_maximal I h with ⟨M, hM, hIM⟩,
exact ⟨⟨M, hM.is_prime⟩, hIM⟩ },
{ rintro rfl, apply zero_locus_empty_of_one_mem, trivial }
end
@[simp] lemma zero_locus_univ :
zero_locus (set.univ : set R) = ∅ :=
zero_locus_empty_of_one_mem (set.mem_univ 1)
lemma zero_locus_sup (I J : ideal R) :
zero_locus ((I ⊔ J : ideal R) : set R) = zero_locus I ∩ zero_locus J :=
(gc R).l_sup
lemma zero_locus_union (s s' : set R) :
zero_locus (s ∪ s') = zero_locus s ∩ zero_locus s' :=
(gc_set R).l_sup
lemma vanishing_ideal_union (t t' : set (prime_spectrum R)) :
vanishing_ideal (t ∪ t') = vanishing_ideal t ⊓ vanishing_ideal t' :=
(gc R).u_inf
lemma zero_locus_supr {ι : Sort*} (I : ι → ideal R) :
zero_locus ((⨆ i, I i : ideal R) : set R) = (⋂ i, zero_locus (I i)) :=
(gc R).l_supr
lemma zero_locus_Union {ι : Sort*} (s : ι → set R) :
zero_locus (⋃ i, s i) = (⋂ i, zero_locus (s i)) :=
(gc_set R).l_supr
lemma vanishing_ideal_Union {ι : Sort*} (t : ι → set (prime_spectrum R)) :
vanishing_ideal (⋃ i, t i) = (⨅ i, vanishing_ideal (t i)) :=
(gc R).u_infi
lemma zero_locus_inf (I J : ideal R) :
zero_locus ((I ⊓ J : ideal R) : set R) = zero_locus I ∪ zero_locus J :=
begin
ext x,
split,
{ rintro h,
rw set.mem_union,
simp only [mem_zero_locus] at h ⊢,
-- TODO: The rest of this proof should be factored out.
rw or_iff_not_imp_right,
intros hs r hr,
rw set.not_subset at hs,
rcases hs with ⟨s, hs1, hs2⟩,
apply (ideal.is_prime.mem_or_mem (by apply_instance) _).resolve_left hs2,
apply h,
split,
{ exact ideal.mul_mem_left _ hr },
{ exact ideal.mul_mem_right _ hs1 } },
{ rintro (h|h),
all_goals
{ rw mem_zero_locus at h ⊢,
refine set.subset.trans _ h,
intros r hr, cases hr, assumption } }
end
lemma union_zero_locus (s s' : set R) :
zero_locus s ∪ zero_locus s' = zero_locus ((ideal.span s) ⊓ (ideal.span s') : ideal R) :=
by { rw zero_locus_inf, simp }
lemma sup_vanishing_ideal_le (t t' : set (prime_spectrum R)) :
vanishing_ideal t ⊔ vanishing_ideal t' ≤ vanishing_ideal (t ∩ t') :=
begin
intros r,
rw [submodule.mem_sup, mem_vanishing_ideal],
rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩,
rw mem_vanishing_ideal at hf hg,
apply submodule.add_mem; solve_by_elim
end
/-- The Zariski topology on the prime spectrum of a commutative ring
is defined via the closed sets of the topology:
they are exactly those sets that are the zero locus of a subset of the ring. -/
instance zariski_topology : topological_space (prime_spectrum R) :=
topological_space.of_closed (set.range prime_spectrum.zero_locus)
(⟨set.univ, by simp⟩)
begin
intros Zs h,
rw set.sInter_eq_Inter,
let f : Zs → set R := λ i, classical.some (h i.2),
have hf : ∀ i : Zs, ↑i = zero_locus (f i) := λ i, (classical.some_spec (h i.2)).symm,
simp only [hf],
exact ⟨_, zero_locus_Union _⟩
end
(by { rintro _ _ ⟨s, rfl⟩ ⟨t, rfl⟩, exact ⟨_, (union_zero_locus s t).symm⟩ })
lemma is_open_iff (U : set (prime_spectrum R)) :
is_open U ↔ ∃ s, Uᶜ = zero_locus s :=
by simp only [@eq_comm _ Uᶜ]; refl
lemma is_closed_iff_zero_locus (Z : set (prime_spectrum R)) :
is_closed Z ↔ ∃ s, Z = zero_locus s :=
by rw [is_closed, is_open_iff, set.compl_compl]
lemma is_closed_zero_locus (s : set R) :
is_closed (zero_locus s) :=
by { rw [is_closed_iff_zero_locus], exact ⟨s, rfl⟩ }
section comap
variables {S : Type v} [comm_ring S] {S' : Type*} [comm_ring S']
/-- The function between prime spectra of commutative rings induced by a ring homomorphism.
This function is continuous. -/
def comap (f : R →+* S) : prime_spectrum S → prime_spectrum R :=
λ y, ⟨ideal.comap f y.as_ideal, by exact ideal.is_prime.comap _⟩
variables (f : R →+* S)
@[simp] lemma comap_as_ideal (y : prime_spectrum S) :
(comap f y).as_ideal = ideal.comap f y.as_ideal :=
rfl
@[simp] lemma comap_id : comap (ring_hom.id R) = id :=
funext $ λ x, ext.mpr $ by { rw [comap_as_ideal], apply ideal.ext, intros r, simp }
@[simp] lemma comap_comp (f : R →+* S) (g : S →+* S') :
comap (g.comp f) = comap f ∘ comap g :=
funext $ λ x, ext.mpr $ by { simp, refl }
@[simp] lemma preimage_comap_zero_locus (s : set R) :
(comap f) ⁻¹' (zero_locus s) = zero_locus (f '' s) :=
begin
ext x,
simp only [mem_zero_locus, set.mem_preimage, comap_as_ideal, set.image_subset_iff],
refl
end
lemma comap_continuous (f : R →+* S) : continuous (comap f) :=
begin
rw continuous_iff_is_closed,
simp only [is_closed_iff_zero_locus],
rintro _ ⟨s, rfl⟩,
exact ⟨_, preimage_comap_zero_locus f s⟩
end
end comap
lemma zero_locus_vanishing_ideal_eq_closure (t : set (prime_spectrum R)) :
zero_locus (vanishing_ideal t : set R) = closure t :=
begin
apply set.subset.antisymm,
{ rintro x hx t' ⟨ht', ht⟩,
obtain ⟨fs, rfl⟩ : ∃ s, t' = zero_locus s,
by rwa [is_closed_iff_zero_locus] at ht',
rw [subset_zero_locus_iff_subset_vanishing_ideal] at ht,
calc fs ⊆ vanishing_ideal t : ht
... ⊆ x.as_ideal : hx },
{ rw (is_closed_zero_locus _).closure_subset_iff,
exact subset_zero_locus_vanishing_ideal t }
end
/-- The prime spectrum of a commutative ring is a compact topological space. -/
instance : compact_space (prime_spectrum R) :=
begin
apply compact_space_of_finite_subfamily_closed,
intros ι Z hZc hZ,
let I : ι → ideal R := λ i, vanishing_ideal (Z i),
have hI : ∀ i, Z i = zero_locus (I i),
{ intro i,
rw [zero_locus_vanishing_ideal_eq_closure, is_closed.closure_eq],
exact hZc i },
have one_mem : (1:R) ∈ ⨆ (i : ι), I i,
{ rw [← ideal.eq_top_iff_one, ← zero_locus_empty_iff_eq_top, zero_locus_supr],
simpa only [hI] using hZ },
obtain ⟨s, hs⟩ : ∃ s : finset ι, (1:R) ∈ ⨆ i ∈ s, I i :=
submodule.exists_finset_of_mem_supr I one_mem,
show ∃ t : finset ι, (⋂ i ∈ t, Z i) = ∅,
use s,
rw [← ideal.eq_top_iff_one, ←zero_locus_empty_iff_eq_top] at hs,
simpa only [zero_locus_supr, hI] using hs
end
section basic_open
/-- `basic_open r` is the open subset containing all prime ideals not containing `r`. -/
def basic_open (r : R) : topological_space.opens (prime_spectrum R) :=
{ val := { x | r ∉ x.as_ideal },
property := ⟨{r}, set.ext $ λ x, set.singleton_subset_iff.trans $ not_not.symm⟩ }
end basic_open
end prime_spectrum
|
47ebc979555c64b360698710ebc62f1346ecec4e | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Compiler/LCNF/MonadScope.lean | b157cdeb9f806bc638a6018e18890a6435bfbee4 | [
"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 | 1,265 | lean | /-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.LCNF.Basic
namespace Lean.Compiler.LCNF
abbrev Scope := FVarIdSet
class MonadScope (m : Type → Type) where
getScope : m Scope
withScope : (Scope → Scope) → m α → m α
export MonadScope (getScope withScope)
abbrev ScopeT (m : Type → Type) := ReaderT Scope m
instance [Monad m] : MonadScope (ScopeT m) where
getScope := read
withScope := withReader
instance (m n) [MonadLift m n] [MonadFunctor m n] [MonadScope m] : MonadScope n where
getScope := liftM (getScope : m _)
withScope f := monadMap (m := m) (withScope f)
def inScope [MonadScope m] [Monad m] (fvarId : FVarId) : m Bool :=
return (← getScope).contains fvarId
@[inline] def withParams [MonadScope m] [Monad m] (ps : Array Param) (x : m α) : m α :=
withScope (fun s => ps.foldl (init := s) fun s p => s.insert p.fvarId) x
@[inline] def withFVar [MonadScope m] [Monad m] (fvarId : FVarId) (x : m α) : m α :=
withScope (fun s => s.insert fvarId) x
@[inline] def withNewScope [MonadScope m] [Monad m] (x : m α) : m α := do
withScope (fun _ => {}) x
end Lean.Compiler.LCNF |
d47ef6744c0e9c4bef860ad00d4b268c30bb387d | 08bd4ba4ca87dba1f09d2c96a26f5d65da81f4b4 | /src/Lean/Meta/Tactic/Apply.lean | 8fd34024a565b178207403c5729680084fbf026e | [
"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",
"Apache-2.0",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | gebner/lean4 | d51c4922640a52a6f7426536ea669ef18a1d9af5 | 8cd9ce06843c9d42d6d6dc43d3e81e3b49dfc20f | refs/heads/master | 1,685,732,780,391 | 1,672,962,627,000 | 1,673,459,398,000 | 373,307,283 | 0 | 0 | Apache-2.0 | 1,691,316,730,000 | 1,622,669,271,000 | Lean | UTF-8 | Lean | false | false | 9,395 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Util.FindMVar
import Lean.Meta.SynthInstance
import Lean.Meta.CollectMVars
import Lean.Meta.Tactic.Util
namespace Lean.Meta
/-- Controls which new mvars are turned in to goals by the `apply` tactic.
- `nonDependentFirst` mvars that don't depend on other goals appear first in the goal list.
- `nonDependentOnly` only mvars that don't depend on other goals are added to goal list.
- `all` all unassigned mvars are added to the goal list.
-/
inductive ApplyNewGoals where
| nonDependentFirst | nonDependentOnly | all
/-- Configures the behaviour of the `apply` tactic. -/
structure ApplyConfig where
newGoals := ApplyNewGoals.nonDependentFirst
/--
If `synthAssignedInstances` is `true`, then `apply` will synthesize instance implicit arguments
even if they have assigned by `isDefEq`, and then check whether the synthesized value matches the
one inferred. The `congr` tactic sets this flag to false.
-/
synthAssignedInstances := true
/--
If `approx := true`, then we turn on `isDefEq` approximations. That is, we use
the `approxDefEq` combinator.
-/
approx : Bool := true
/--
Compute the number of expected arguments and whether the result type is of the form
(?m ...) where ?m is an unassigned metavariable.
-/
def getExpectedNumArgsAux (e : Expr) : MetaM (Nat × Bool) :=
withDefault <| forallTelescopeReducing e fun xs body =>
pure (xs.size, body.getAppFn.isMVar)
def getExpectedNumArgs (e : Expr) : MetaM Nat := do
let (numArgs, _) ← getExpectedNumArgsAux e
pure numArgs
private def throwApplyError {α} (mvarId : MVarId) (eType : Expr) (targetType : Expr) : MetaM α :=
throwTacticEx `apply mvarId m!"failed to unify{indentExpr eType}\nwith{indentExpr targetType}"
def synthAppInstances (tacticName : Name) (mvarId : MVarId) (newMVars : Array Expr) (binderInfos : Array BinderInfo) (synthAssignedInstances : Bool) : MetaM Unit :=
newMVars.size.forM fun i => do
if binderInfos[i]!.isInstImplicit then
let mvar := newMVars[i]!
if synthAssignedInstances || !(← mvar.mvarId!.isAssigned) then
let mvarType ← inferType mvar
let mvarVal ← synthInstance mvarType
unless (← isDefEq mvar mvarVal) do
throwTacticEx tacticName mvarId "failed to assign synthesized instance"
def appendParentTag (mvarId : MVarId) (newMVars : Array Expr) (binderInfos : Array BinderInfo) : MetaM Unit := do
let parentTag ← mvarId.getTag
if newMVars.size == 1 then
-- if there is only one subgoal, we inherit the parent tag
newMVars[0]!.mvarId!.setTag parentTag
else
unless parentTag.isAnonymous do
newMVars.size.forM fun i => do
let mvarIdNew := newMVars[i]!.mvarId!
unless (← mvarIdNew.isAssigned) do
unless binderInfos[i]!.isInstImplicit do
let currTag ← mvarIdNew.getTag
mvarIdNew.setTag (appendTag parentTag currTag)
/--
If `synthAssignedInstances` is `true`, then `apply` will synthesize instance implicit arguments
even if they have assigned by `isDefEq`, and then check whether the synthesized value matches the
one inferred. The `congr` tactic sets this flag to false.
-/
def postprocessAppMVars (tacticName : Name) (mvarId : MVarId) (newMVars : Array Expr) (binderInfos : Array BinderInfo) (synthAssignedInstances := true) : MetaM Unit := do
synthAppInstances tacticName mvarId newMVars binderInfos synthAssignedInstances
-- TODO: default and auto params
appendParentTag mvarId newMVars binderInfos
private def dependsOnOthers (mvar : Expr) (otherMVars : Array Expr) : MetaM Bool :=
otherMVars.anyM fun otherMVar => do
if mvar == otherMVar then
return false
else
let otherMVarType ← inferType otherMVar
return (otherMVarType.findMVar? fun mvarId => mvarId == mvar.mvarId!).isSome
/-- Partitions the given mvars in to two arrays (non-deps, deps)
according to whether the given mvar depends on other mvars in the array.-/
private def partitionDependentMVars (mvars : Array Expr) : MetaM (Array MVarId × Array MVarId) :=
mvars.foldlM (init := (#[], #[])) fun (nonDeps, deps) mvar => do
let currMVarId := mvar.mvarId!
if (← dependsOnOthers mvar mvars) then
return (nonDeps, deps.push currMVarId)
else
return (nonDeps.push currMVarId, deps)
private def reorderGoals (mvars : Array Expr) : ApplyNewGoals → MetaM (List MVarId)
| ApplyNewGoals.nonDependentFirst => do
let (nonDeps, deps) ← partitionDependentMVars mvars
return nonDeps.toList ++ deps.toList
| ApplyNewGoals.nonDependentOnly => do
let (nonDeps, _) ← partitionDependentMVars mvars
return nonDeps.toList
| ApplyNewGoals.all => return mvars.toList.map Lean.Expr.mvarId!
/-- Custom `isDefEq` for the `apply` tactic -/
private def isDefEqApply (cfg : ApplyConfig) (a b : Expr) : MetaM Bool := do
if cfg.approx then
approxDefEq <| isDefEqGuarded a b
else
isDefEqGuarded a b
/--
Close the given goal using `apply e`.
-/
def _root_.Lean.MVarId.apply (mvarId : MVarId) (e : Expr) (cfg : ApplyConfig := {}) : MetaM (List MVarId) :=
mvarId.withContext do
mvarId.checkNotAssigned `apply
let targetType ← mvarId.getType
let eType ← inferType e
let (numArgs, hasMVarHead) ← getExpectedNumArgsAux eType
/-
The `apply` tactic adds `_`s to `e`, and some of these `_`s become new goals.
When `hasMVarHead` is `false` we try different numbers, until we find a type compatible with `targetType`.
We used to try only `numArgs-targetTypeNumArgs` when `hasMVarHead = false`, but this is not always correct.
For example, consider the following example
```
example {α β} [LE_trans β] (x y z : α → β) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z := by
apply le_trans
assumption
assumption
```
In this example, `targetTypeNumArgs = 1` because `LE` for functions is defined as
```
instance {α : Type u} {β : Type v} [LE β] : LE (α → β) where
le f g := ∀ i, f i ≤ g i
```
-/
let rangeNumArgs ← if hasMVarHead then
pure [numArgs : numArgs+1]
else
let targetTypeNumArgs ← getExpectedNumArgs targetType
pure [numArgs - targetTypeNumArgs : numArgs+1]
/-
Auxiliary function for trying to add `n` underscores where `n ∈ [i: rangeNumArgs.stop)`
See comment above
-/
let rec go (i : Nat) : MetaM (Array Expr × Array BinderInfo) := do
if i < rangeNumArgs.stop then
let s ← saveState
let (newMVars, binderInfos, eType) ← forallMetaTelescopeReducing eType i
if (← isDefEqApply cfg eType targetType) then
return (newMVars, binderInfos)
else
s.restore
go (i+1)
else
let (_, _, eType) ← forallMetaTelescopeReducing eType (some rangeNumArgs.start)
throwApplyError mvarId eType targetType
let (newMVars, binderInfos) ← go rangeNumArgs.start
postprocessAppMVars `apply mvarId newMVars binderInfos cfg.synthAssignedInstances
let e ← instantiateMVars e
mvarId.assign (mkAppN e newMVars)
let newMVars ← newMVars.filterM fun mvar => not <$> mvar.mvarId!.isAssigned
let otherMVarIds ← getMVarsNoDelayed e
let newMVarIds ← reorderGoals newMVars cfg.newGoals
let otherMVarIds := otherMVarIds.filter fun mvarId => !newMVarIds.contains mvarId
let result := newMVarIds ++ otherMVarIds.toList
result.forM (·.headBetaType)
return result
termination_by go i => rangeNumArgs.stop - i
@[deprecated MVarId.apply]
def apply (mvarId : MVarId) (e : Expr) (cfg : ApplyConfig := {}) : MetaM (List MVarId) :=
mvarId.apply e cfg
partial def splitAndCore (mvarId : MVarId) : MetaM (List MVarId) :=
mvarId.withContext do
mvarId.checkNotAssigned `splitAnd
let type ← mvarId.getType'
if !type.isAppOfArity ``And 2 then
return [mvarId]
else
let tag ← mvarId.getTag
let rec go (type : Expr) : StateRefT (Array MVarId) MetaM Expr := do
let type ← whnf type
if type.isAppOfArity ``And 2 then
let p₁ := type.appFn!.appArg!
let p₂ := type.appArg!
return mkApp4 (mkConst ``And.intro) p₁ p₂ (← go p₁) (← go p₂)
else
let idx := (← get).size + 1
let mvar ← mkFreshExprSyntheticOpaqueMVar type (tag ++ (`h).appendIndexAfter idx)
modify fun s => s.push mvar.mvarId!
return mvar
let (val, s) ← go type |>.run #[]
mvarId.assign val
return s.toList
/--
Apply `And.intro` as much as possible to goal `mvarId`.
-/
abbrev _root_.Lean.MVarId.splitAnd (mvarId : MVarId) : MetaM (List MVarId) :=
splitAndCore mvarId
@[deprecated MVarId.splitAnd]
def splitAnd (mvarId : MVarId) : MetaM (List MVarId) :=
mvarId.splitAnd
def _root_.Lean.MVarId.exfalso (mvarId : MVarId) : MetaM MVarId :=
mvarId.withContext do
mvarId.checkNotAssigned `exfalso
let target ← instantiateMVars (← mvarId.getType)
let u ← getLevel target
let mvarIdNew ← mkFreshExprSyntheticOpaqueMVar (mkConst ``False) (tag := (← mvarId.getTag))
mvarId.assign (mkApp2 (mkConst ``False.elim [u]) target mvarIdNew)
return mvarIdNew.mvarId!
end Lean.Meta
|
f5f3fed21cd434b7b30291bc83d14aba382629e5 | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/tactic/lint/type_classes.lean | 9670f76695a8e1708eafab3e6726be51dea5a2d0 | [
"Apache-2.0"
] | permissive | aestriplex/mathlib | 77513ff2b176d74a3bec114f33b519069788811d | e2fa8b2b1b732d7c25119229e3cdfba8370cb00f | refs/heads/master | 1,621,969,960,692 | 1,586,279,279,000 | 1,586,279,279,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,507 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Robert Y. Lewis, Gabriel Ebner
-/
import tactic.lint.basic
/-!
# Linters about type classes
This file defines several linters checking the correct usage of type classes
and the appropriate definition of instances:
* `instance_priority` ensures that blanket instances have low priority
* `has_inhabited_instances` checks that every type has an `inhabited` instance
* `impossible_instance` checks that there are no instances which can never apply
* `incorrect_type_class_argument` checks that only type classes are used in
instance-implicit arguments
* `dangerous_instance` checks for instances that generate subproblems with metavariables
* `fails_quickly` checks that type class resolution finishes quickly
* `has_coe_variable` checks that there is no instance of type `has_coe α t`
* `inhabited_nonempty` checks whether `[inhabited α]` arguments could be generalized
to `[inhabited α]`
-/
open tactic
/-- Pretty prints a list of arguments of a declaration. Assumes `l` is a list of argument positions
and binders (or any other element that can be pretty printed).
`l` can be obtained e.g. by applying `list.indexes_values` to a list obtained by
`get_pi_binders`. -/
meta def print_arguments {α} [has_to_tactic_format α] (l : list (ℕ × α)) : tactic string := do
fs ← l.mmap (λ ⟨n, b⟩, (λ s, to_fmt "argument " ++ to_fmt (n+1) ++ ": " ++ s) <$> pp b),
return $ fs.to_string_aux tt
/-- checks whether an instance that always applies has priority ≥ 1000. -/
private meta def instance_priority (d : declaration) : tactic (option string) := do
let nm := d.to_name,
b ← is_instance nm,
/- return `none` if `d` is not an instance -/
if ¬ b then return none else do
(is_persistent, prio) ← has_attribute `instance nm,
/- return `none` if `d` is has low priority -/
if prio < 1000 then return none else do
let (fn, args) := d.type.pi_codomain.get_app_fn_args,
cls ← get_decl fn.const_name,
let (pi_args, _) := cls.type.pi_binders,
guard (args.length = pi_args.length),
/- List all the arguments of the class that block type-class inference from firing
(if they are metavariables). These are all the arguments except instance-arguments and
out-params. -/
let relevant_args := (args.zip pi_args).filter_map $ λ⟨e, ⟨_, info, tp⟩⟩,
if info = binder_info.inst_implicit ∨ tp.get_app_fn.is_constant_of `out_param
then none else some e,
let always_applies := relevant_args.all expr.is_var ∧ relevant_args.nodup,
if always_applies then return $ some "set priority below 1000" else return none
/--
Certain instances always apply during type-class resolution. For example, the instance
`add_comm_group.to_add_group {α} [add_comm_group α] : add_group α` applies to all type-class
resolution problems of the form `add_group _`, and type-class inference will then do an
exhaustive search to find a commutative group. These instances take a long time to fail.
Other instances will only apply if the goal has a certain shape. For example
`int.add_group : add_group ℤ` or
`add_group.prod {α β} [add_group α] [add_group β] : add_group (α × β)`. Usually these instances
will fail quickly, and when they apply, they are almost the desired instance.
For this reason, we want the instances of the second type (that only apply in specific cases) to
always have higher priority than the instances of the first type (that always apply).
See also #1561.
Therefore, if we create an instance that always applies, we set the priority of these instances to
100 (or something similar, which is below the default value of 1000).
-/
library_note "lower instance priority"
/--
Instances that always apply should be applied after instances that only apply in specific cases,
see note [lower instance priority] above.
Classes that use the `extends` keyword automatically generate instances that always apply.
Therefore, we set the priority of these instances to 100 (or something similar, which is below the
default value of 1000) using `set_option default_priority 100`.
We have to put this option inside a section, so that the default priority is the default
1000 outside the section.
-/
library_note "default priority"
/-- A linter object for checking instance priorities of instances that always apply.
This is in the default linter set. -/
@[linter] meta def linter.instance_priority : linter :=
{ test := instance_priority,
no_errors_found := "All instance priorities are good",
errors_found := "DANGEROUS INSTANCE PRIORITIES.
The following instances always apply, and therefore should have a priority < 1000.
If you don't know what priority to choose, use priority 100.
If this is an automatically generated instance (using the keywords `class` and `extends`),
see note [lower instance priority] and see note [default priority] for instructions to change the priority",
auto_decls := tt }
/-- Reports declarations of types that do not have an associated `inhabited` instance. -/
private meta def has_inhabited_instance (d : declaration) : tactic (option string) := do
tt ← pure d.is_trusted | pure none,
ff ← has_attribute' `reducible d.to_name | pure none,
ff ← has_attribute' `class d.to_name | pure none,
(_, ty) ← mk_local_pis d.type,
ty ← whnf ty,
if ty = `(Prop) then pure none else do
`(Sort _) ← whnf ty | pure none,
insts ← attribute.get_instances `instance,
insts_tys ← insts.mmap $ λ i, expr.pi_codomain <$> declaration.type <$> get_decl i,
let inhabited_insts := insts_tys.filter (λ i,
i.app_fn.const_name = ``inhabited ∨ i.app_fn.const_name = `unique),
let inhabited_tys := inhabited_insts.map (λ i, i.app_arg.get_app_fn.const_name),
if d.to_name ∈ inhabited_tys then
pure none
else
pure "inhabited instance missing"
/-- A linter for missing `inhabited` instances. -/
@[linter]
meta def linter.has_inhabited_instance : linter :=
{ test := has_inhabited_instance,
no_errors_found := "No types have missing inhabited instances",
errors_found := "TYPES ARE MISSING INHABITED INSTANCES",
is_fast := ff }
attribute [nolint has_inhabited_instance] pempty
/-- Checks whether an instance can never be applied. -/
private meta def impossible_instance (d : declaration) : tactic (option string) := do
tt ← is_instance d.to_name | return none,
(binders, _) ← get_pi_binders_dep d.type,
let bad_arguments := binders.filter $ λ nb, nb.2.info ≠ binder_info.inst_implicit,
_ :: _ ← return bad_arguments | return none,
(λ s, some $ "Impossible to infer " ++ s) <$> print_arguments bad_arguments
/-- A linter object for `impossible_instance`. -/
@[linter] meta def linter.impossible_instance : linter :=
{ test := impossible_instance,
no_errors_found := "All instances are applicable",
errors_found := "IMPOSSIBLE INSTANCES FOUND.
These instances have an argument that cannot be found during type-class resolution, and therefore can never succeed. Either mark the arguments with square brackets (if it is a class), or don't make it an instance" }
/-- Checks whether an instance can never be applied. -/
private meta def incorrect_type_class_argument (d : declaration) : tactic (option string) := do
(binders, _) ← get_pi_binders d.type,
let instance_arguments := binders.indexes_values $
λ b : binder, b.info = binder_info.inst_implicit,
/- the head of the type should either unfold to a class, or be a local constant.
A local constant is allowed, because that could be a class when applied to the
proper arguments. -/
bad_arguments ← instance_arguments.mfilter (λ ⟨_, b⟩, do
(_, head) ← mk_local_pis b.type,
if head.get_app_fn.is_local_constant then return ff else do
bnot <$> is_class head),
_ :: _ ← return bad_arguments | return none,
(λ s, some $ "These are not classes. " ++ s) <$> print_arguments bad_arguments
/-- A linter object for `incorrect_type_class_argument`. -/
@[linter] meta def linter.incorrect_type_class_argument : linter :=
{ test := incorrect_type_class_argument,
no_errors_found := "All declarations have correct type-class arguments",
errors_found := "INCORRECT TYPE-CLASS ARGUMENTS.
Some declarations have non-classes between [square brackets]" }
/-- Checks whether an instance is dangerous: it creates a new type-class problem with metavariable
arguments. -/
private meta def dangerous_instance (d : declaration) : tactic (option string) := do
tt ← is_instance d.to_name | return none,
(local_constants, target) ← mk_local_pis d.type,
let instance_arguments := local_constants.indexes_values $
λ e : expr, e.local_binding_info = binder_info.inst_implicit,
let bad_arguments := local_constants.indexes_values $ λ x,
!target.has_local_constant x &&
(x.local_binding_info ≠ binder_info.inst_implicit) &&
instance_arguments.any (λ nb, nb.2.local_type.has_local_constant x),
let bad_arguments : list (ℕ × binder) := bad_arguments.map $ λ ⟨n, e⟩, ⟨n, e.to_binder⟩,
_ :: _ ← return bad_arguments | return none,
(λ s, some $ "The following arguments become metavariables. " ++ s) <$> print_arguments bad_arguments
/-- A linter object for `dangerous_instance`. -/
@[linter] meta def linter.dangerous_instance : linter :=
{ test := dangerous_instance,
no_errors_found := "No dangerous instances",
errors_found := "DANGEROUS INSTANCES FOUND.\nThese instances are recursive, and create a new type-class problem which will have metavariables.
Possible solution: remove the instance attribute or make it a local instance instead.
Currently this linter does not check whether the metavariables only occur in arguments marked with `out_param`, in which case this linter gives a false positive.",
auto_decls := tt }
/-- Applies expression `e` to local constants, but lifts all the arguments that are `Sort`-valued to
`Type`-valued sorts. -/
meta def apply_to_fresh_variables (e : expr) : tactic expr := do
t ← infer_type e,
(xs, b) ← mk_local_pis t,
xs.mmap' $ λ x, try $ do {
u ← mk_meta_univ,
tx ← infer_type x,
ttx ← infer_type tx,
unify ttx (expr.sort u.succ) },
return $ e.app_of_list xs
/-- Tests whether type-class inference search for a class will end quickly when applied to
variables. This tactic succeeds if `mk_instance` succeeds quickly or fails quickly with the error
message that it cannot find an instance. It fails if the tactic takes too long, or if any other
error message is raised.
We make sure that we apply the tactic to variables living in `Type u` instead of `Sort u`,
because many instances only apply in that special case, and we do want to catch those loops. -/
meta def fails_quickly (max_steps : ℕ) (d : declaration) : tactic (option string) := do
e ← mk_const d.to_name,
tt ← is_class e | return none,
e' ← apply_to_fresh_variables e,
sum.inr msg ← retrieve_or_report_error $ tactic.try_for max_steps $
succeeds_or_fails_with_msg (mk_instance e')
$ λ s, "tactic.mk_instance failed to generate instance for".is_prefix_of s | return none,
return $ some $
if msg = "try_for tactic failed, timeout" then "type-class inference timed out" else msg
/-- A linter object for `fails_quickly`. If we want to increase the maximum number of steps
type-class inference is allowed to take, we can increase the number `3000` in the definition.
As of 5 Mar 2020 the longest trace (for `is_add_hom`) takes 2900-3000 "heartbeats". -/
@[linter] meta def linter.fails_quickly : linter :=
{ test := fails_quickly 3000,
no_errors_found := "No type-class searches timed out",
errors_found := "TYPE CLASS SEARCHES TIMED OUT.
For the following classes, there is an instance that causes a loop, or an excessively long search.",
is_fast := ff }
/-- Tests whether there is no instance of type `has_coe α t` where `α` is a variable.
See note [use has_coe_t]. -/
private meta def has_coe_variable (d : declaration) : tactic (option string) := do
tt ← is_instance d.to_name | return none,
`(has_coe %%a _) ← return d.type.pi_codomain | return none,
tt ← return a.is_var | return none,
return $ some $ "illegal instance"
/-- A linter object for `has_coe_variable`. -/
@[linter] meta def linter.has_coe_variable : linter :=
{ test := has_coe_variable,
no_errors_found := "No invalid `has_coe` instances",
errors_found := "INVALID `has_coe` INSTANCES.
Make the following declarations instances of the class `has_coe_t` instead of `has_coe`." }
/-- Checks whether a declaration is prop-valued and takes an `inhabited _` argument that is unused
elsewhere in the type. In this case, that argument can be replaced with `nonempty _`. -/
private meta def inhabited_nonempty (d : declaration) : tactic (option string) :=
do tt ← is_prop d.type | return none,
(binders, _) ← get_pi_binders_dep d.type,
let inhd_binders := binders.filter $ λ pr, pr.2.type.is_app_of `inhabited,
if inhd_binders.length = 0 then return none
else (λ s, some $ "The following `inhabited` instances should be `nonempty`. " ++ s) <$>
print_arguments inhd_binders
/-- A linter object for `inhabited_nonempty`. -/
@[linter] meta def linter.inhabited_nonempty : linter :=
{ test := inhabited_nonempty,
no_errors_found := "No uses of `inhabited` arguments should be replaced with `nonempty`",
errors_found := "USES OF `inhabited` SHOULD BE REPLACED WITH `nonempty`." }
|
3da791b3196ed46f2ba407ea047c801ef03ba9bd | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/homotopy/sphere.hlean | 4c4f4ad2ff286458baa541c208ae5d7a62508463 | [
"Apache-2.0"
] | permissive | fpvandoorn/lean2 | 5a430a153b570bf70dc8526d06f18fc000a60ad9 | 0889cf65b7b3cebfb8831b8731d89c2453dd1e9f | refs/heads/master | 1,592,036,508,364 | 1,545,093,958,000 | 1,545,093,958,000 | 75,436,854 | 0 | 0 | null | 1,480,718,780,000 | 1,480,718,780,000 | null | UTF-8 | Lean | false | false | 4,681 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Declaration of the n-spheres
-/
import .susp types.trunc
open eq nat susp bool is_trunc unit pointed algebra equiv
/-
We can define spheres with the following possible indices:
- trunc_index (defining S^-2 = S^-1 = empty)
- nat (forgetting that S^-1 = empty)
- nat, but counting wrong (S^0 = empty, S^1 = bool, ...)
- some new type "integers >= -1"
We choose the second option here.
-/
definition sphere (n : ℕ) : Type* := iterate_susp n pbool
namespace sphere
namespace ops
abbreviation S := sphere
end ops
open sphere.ops
definition sphere_succ [unfold_full] (n : ℕ) : S (n+1) = susp (S n) := idp
definition sphere_eq_iterate_susp (n : ℕ) : S n = iterate_susp n pbool := idp
definition equator [constructor] (n : ℕ) : S n →* Ω (S (succ n)) :=
loop_susp_unit (S n)
definition surf {n : ℕ} : Ω[n] (S n) :=
begin
induction n with n s,
{ exact tt },
{ exact (loopn_succ_in n (S (succ n)))⁻¹ᵉ* (apn n (equator n) s) }
end
definition sphere_equiv_bool [constructor] : S 0 ≃ bool := by reflexivity
definition sphere_pequiv_pbool [constructor] : S 0 ≃* pbool := by reflexivity
definition sphere_pequiv_iterate_susp (n : ℕ) : sphere n ≃* iterate_susp n pbool :=
by reflexivity
definition sphere_pmap_pequiv' (A : Type*) (n : ℕ) : ppmap (S n) A ≃* Ω[n] A :=
begin
revert A, induction n with n IH: intro A,
{ refine !ppmap_pbool_pequiv },
{ refine susp_adjoint_loop (S n) A ⬝e* IH (Ω A) ⬝e* !loopn_succ_in⁻¹ᵉ* }
end
definition sphere_pmap_pequiv (A : Type*) (n : ℕ) : ppmap (S n) A ≃* Ω[n] A :=
begin
fapply pequiv_change_fun,
{ exact sphere_pmap_pequiv' A n },
{ exact papn_fun A surf },
{ revert A, induction n with n IH: intro A,
{ reflexivity },
{ intro f, refine ap !loopn_succ_in⁻¹ᵉ* (IH (Ω A) _ ⬝ !apn_pcompose _) ⬝ _,
exact !loopn_succ_in_inv_natural⁻¹* _ }}
end
protected definition elim {n : ℕ} {P : Type*} (p : Ω[n] P) : S n →* P :=
!sphere_pmap_pequiv⁻¹ᵉ* p
-- definition elim_surf {n : ℕ} {P : Type*} (p : Ω[n] P) : apn n (sphere.elim p) surf = p :=
-- begin
-- induction n with n IH,
-- { esimp [apn,surf,sphere.elim,sphere_pmap_equiv], apply sorry},
-- { apply sorry}
-- end
end sphere
namespace sphere
open is_conn trunc_index sphere.ops
-- Corollary 8.2.2
theorem is_conn_sphere [instance] (n : ℕ) : is_conn (n.-1) (S n) :=
begin
induction n with n IH,
{ apply is_conn_minus_one_pointed },
{ apply is_conn_susp, exact IH }
end
end sphere
open sphere sphere.ops
namespace is_trunc
open trunc_index
variables {n : ℕ} {A : Type}
definition is_trunc_of_sphere_pmap_equiv_constant
(H : Π(a : A) (f : S n →* pointed.Mk a) (x : S n), f x = f pt) : is_trunc (n.-2.+1) A :=
begin
apply iff.elim_right !is_trunc_iff_is_contr_loop,
intro a,
apply is_trunc_equiv_closed, exact !sphere_pmap_pequiv,
fapply is_contr.mk,
{ exact pmap.mk (λx, a) idp},
{ intro f, apply eq_of_phomotopy, fapply phomotopy.mk,
{ intro x, esimp, refine !respect_pt⁻¹ ⬝ (!H ⬝ !H⁻¹)},
{ rewrite [▸*,con.right_inv,▸*,con.left_inv]}}
end
definition is_trunc_iff_map_sphere_constant
(H : Π(f : S n → A) (x : S n), f x = f pt) : is_trunc (n.-2.+1) A :=
begin
apply is_trunc_of_sphere_pmap_equiv_constant,
intros, cases f with f p, esimp at *, apply H
end
definition sphere_pmap_equiv_constant_of_is_trunc' [H : is_trunc (n.-2.+1) A]
(a : A) (f : S n →* pointed.Mk a) (x : S n) : f x = f pt :=
begin
let H' := iff.elim_left (is_trunc_iff_is_contr_loop n A) H a,
have H'' : is_contr (S n →* pointed.Mk a), from
@is_trunc_equiv_closed_rev _ _ _ !sphere_pmap_pequiv H',
have p : f = pmap.mk (λx, f pt) (respect_pt f),
from !is_prop.elim,
exact ap10 (ap pmap.to_fun p) x
end
definition sphere_pmap_equiv_constant_of_is_trunc [H : is_trunc (n.-2.+1) A]
(a : A) (f : S n →* pointed.Mk a) (x y : S n) : f x = f y :=
let H := sphere_pmap_equiv_constant_of_is_trunc' a f in !H ⬝ !H⁻¹
definition map_sphere_constant_of_is_trunc [H : is_trunc (n.-2.+1) A]
(f : S n → A) (x y : S n) : f x = f y :=
sphere_pmap_equiv_constant_of_is_trunc (f pt) (pmap.mk f idp) x y
definition map_sphere_constant_of_is_trunc_self [H : is_trunc (n.-2.+1) A]
(f : S n → A) (x : S n) : map_sphere_constant_of_is_trunc f x x = idp :=
!con.right_inv
end is_trunc
|
bbfcaa58ab87417aceed434484ea521ed2132aaa | 969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb | /src/data/polynomial/algebra_map.lean | 5dd2ffd8c4f308b41165b6ba05f79b8a321825f1 | [
"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 | 9,597 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.eval
import algebra.algebra.tower
/-!
# Theory of univariate polynomials
We show that `polynomial A` is an R-algebra when `A` is an R-algebra.
We promote `eval₂` to an algebra hom in `aeval`.
-/
noncomputable theory
open finset
open_locale big_operators
namespace polynomial
universes u v w z
variables {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ}
section comm_semiring
variables [comm_semiring R] {p q r : polynomial R}
variables [semiring A] [algebra R A]
/-- Note that this instance also provides `algebra R (polynomial R)`. -/
instance algebra_of_algebra : algebra R (polynomial A) := add_monoid_algebra.algebra
lemma algebra_map_apply (r : R) :
algebra_map R (polynomial A) r = C (algebra_map R A r) :=
rfl
/--
When we have `[comm_ring R]`, the function `C` is the same as `algebra_map R (polynomial R)`.
(But note that `C` is defined when `R` is not necessarily commutative, in which case
`algebra_map` is not available.)
-/
lemma C_eq_algebra_map {R : Type*} [comm_ring R] (r : R) :
C r = algebra_map R (polynomial R) r :=
rfl
instance [nontrivial A] : nontrivial (subalgebra R (polynomial A)) :=
⟨⟨⊥, ⊤, begin
rw [ne.def, subalgebra.ext_iff, not_forall],
refine ⟨X, _⟩,
simp only [algebra.mem_bot, not_exists, set.mem_range, iff_true, algebra.mem_top,
algebra_map_apply, not_forall],
intro x,
rw [ext_iff, not_forall],
refine ⟨1, _⟩,
simp [coeff_C],
end⟩⟩
@[simp]
lemma alg_hom_eval₂_algebra_map
{R A B : Type*} [comm_ring R] [ring A] [ring B] [algebra R A] [algebra R B]
(p : polynomial R) (f : A →ₐ[R] B) (a : A) :
f (eval₂ (algebra_map R A) a p) = eval₂ (algebra_map R B) (f a) p :=
begin
dsimp [eval₂, finsupp.sum],
simp only [f.map_sum, f.map_mul, f.map_pow, ring_hom.eq_int_cast, ring_hom.map_int_cast,
alg_hom.commutes],
end
@[simp]
lemma eval₂_algebra_map_X {R A : Type*} [comm_ring R] [ring A] [algebra R A]
(p : polynomial R) (f : polynomial R →ₐ[R] A) :
eval₂ (algebra_map R A) (f X) p = f p :=
begin
conv_rhs { rw [←polynomial.sum_C_mul_X_eq p], },
dsimp [eval₂, finsupp.sum],
simp only [f.map_sum, f.map_mul, f.map_pow, ring_hom.eq_int_cast, ring_hom.map_int_cast],
simp [polynomial.C_eq_algebra_map],
end
@[simp]
lemma ring_hom_eval₂_algebra_map_int {R S : Type*} [ring R] [ring S]
(p : polynomial ℤ) (f : R →+* S) (r : R) :
f (eval₂ (algebra_map ℤ R) r p) = eval₂ (algebra_map ℤ S) (f r) p :=
alg_hom_eval₂_algebra_map p f.to_int_alg_hom r
@[simp]
lemma eval₂_algebra_map_int_X {R : Type*} [ring R] (p : polynomial ℤ) (f : polynomial ℤ →+* R) :
eval₂ (algebra_map ℤ R) (f X) p = f p :=
-- Unfortunately `f.to_int_alg_hom` doesn't work here, as typeclasses don't match up correctly.
eval₂_algebra_map_X p { commutes' := λ n, by simp, .. f }
end comm_semiring
section aeval
variables [comm_semiring R] {p q : polynomial R}
variables [semiring A] [algebra R A]
variables {B : Type*} [semiring B] [algebra R B]
variables (x : A)
/-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is
the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`. -/
def aeval : polynomial R →ₐ[R] A :=
{ commutes' := λ r, eval₂_C _ _,
..eval₂_ring_hom' (algebra_map R A) x (λ a, algebra.commutes _ _) }
variables {R A}
@[ext] lemma alg_hom_ext {f g : polynomial R →ₐ[R] A} (h : f X = g X) : f = g :=
by { ext, exact h }
theorem aeval_def (p : polynomial R) : aeval x p = eval₂ (algebra_map R A) x p := rfl
@[simp] lemma aeval_zero : aeval x (0 : polynomial R) = 0 :=
alg_hom.map_zero (aeval x)
@[simp] lemma aeval_X : aeval x (X : polynomial R) = x := eval₂_X _ x
@[simp] lemma aeval_C (r : R) : aeval x (C r) = algebra_map R A r := eval₂_C _ x
lemma aeval_monomial {n : ℕ} {r : R} : aeval x (monomial n r) = (algebra_map _ _ r) * x^n :=
eval₂_monomial _ _
@[simp] lemma aeval_X_pow {n : ℕ} : aeval x ((X : polynomial R)^n) = x^n :=
eval₂_X_pow _ _
@[simp] lemma aeval_add : aeval x (p + q) = aeval x p + aeval x q :=
alg_hom.map_add _ _ _
@[simp] lemma aeval_one : aeval x (1 : polynomial R) = 1 :=
alg_hom.map_one _
@[simp] lemma aeval_bit0 : aeval x (bit0 p) = bit0 (aeval x p) :=
alg_hom.map_bit0 _ _
@[simp] lemma aeval_bit1 : aeval x (bit1 p) = bit1 (aeval x p) :=
alg_hom.map_bit1 _ _
@[simp] lemma aeval_nat_cast (n : ℕ) : aeval x (n : polynomial R) = n :=
alg_hom.map_nat_cast _ _
lemma aeval_mul : aeval x (p * q) = aeval x p * aeval x q :=
alg_hom.map_mul _ _ _
lemma aeval_comp {A : Type*} [comm_semiring A] [algebra R A] (x : A) :
aeval x (p.comp q) = (aeval (aeval x q) p) :=
eval₂_comp (algebra_map R A)
@[simp] lemma aeval_map {A : Type*} [comm_semiring A] [algebra R A] [algebra A B]
[is_scalar_tower R A B] (b : B) (p : polynomial R) :
aeval b (p.map (algebra_map R A)) = aeval b p :=
by rw [aeval_def, eval₂_map, ←is_scalar_tower.algebra_map_eq, ←aeval_def]
theorem eval_unique (φ : polynomial R →ₐ[R] A) (p) :
φ p = eval₂ (algebra_map R A) (φ X) p :=
begin
apply polynomial.induction_on p,
{ intro r, rw eval₂_C, exact φ.commutes r },
{ intros f g ih1 ih2,
rw [φ.map_add, ih1, ih2, eval₂_add] },
{ intros n r ih,
rw [pow_succ', ← mul_assoc, φ.map_mul,
eval₂_mul_noncomm (algebra_map R A) _ (λ k, algebra.commutes _ _), eval₂_X, ih] }
end
theorem aeval_alg_hom (f : A →ₐ[R] B) (x : A) : aeval (f x) = f.comp (aeval x) :=
alg_hom.ext $ λ p, by rw [eval_unique (f.comp (aeval x)), alg_hom.comp_apply, aeval_X, aeval_def]
theorem aeval_alg_hom_apply (f : A →ₐ[R] B) (x : A) (p : polynomial R) :
aeval (f x) p = f (aeval x p) :=
alg_hom.ext_iff.1 (aeval_alg_hom f x) p
lemma aeval_algebra_map_apply (x : R) (p : polynomial R) :
aeval (algebra_map R A x) p = algebra_map R A (p.eval x) :=
aeval_alg_hom_apply (algebra.of_id R A) x p
@[simp] lemma coe_aeval_eq_eval (r : R) :
(aeval r : polynomial R → R) = eval r := rfl
lemma coeff_zero_eq_aeval_zero (p : polynomial R) : p.coeff 0 = aeval 0 p :=
by simp [coeff_zero_eq_eval_zero]
variables [comm_ring S] {f : R →+* S}
lemma is_root_of_eval₂_map_eq_zero
(hf : function.injective f) {r : R} : eval₂ f (f r) p = 0 → p.is_root r :=
begin
intro h,
apply hf,
rw [←eval₂_hom, h, f.map_zero],
end
lemma is_root_of_aeval_algebra_map_eq_zero [algebra R S] {p : polynomial R}
(inj : function.injective (algebra_map R S))
{r : R} (hr : aeval (algebra_map R S r) p = 0) : p.is_root r :=
is_root_of_eval₂_map_eq_zero inj hr
lemma dvd_term_of_dvd_eval_of_dvd_terms {z p : S} {f : polynomial S} (i : ℕ)
(dvd_eval : p ∣ f.eval z) (dvd_terms : ∀ (j ≠ i), p ∣ f.coeff j * z ^ j) :
p ∣ f.coeff i * z ^ i :=
begin
by_cases hf : f = 0,
{ simp [hf] },
by_cases hi : i ∈ f.support,
{ rw [eval, eval₂, sum_def] at dvd_eval,
rw [←finset.insert_erase hi, finset.sum_insert (finset.not_mem_erase _ _)] at dvd_eval,
refine (dvd_add_left _).mp dvd_eval,
apply finset.dvd_sum,
intros j hj,
exact dvd_terms j (finset.ne_of_mem_erase hj) },
{ convert dvd_zero p,
convert _root_.zero_mul _,
exact finsupp.not_mem_support_iff.mp hi }
end
lemma dvd_term_of_is_root_of_dvd_terms {r p : S} {f : polynomial S} (i : ℕ)
(hr : f.is_root r) (h : ∀ (j ≠ i), p ∣ f.coeff j * r ^ j) : p ∣ f.coeff i * r ^ i :=
dvd_term_of_dvd_eval_of_dvd_terms i (eq.symm hr ▸ dvd_zero p) h
lemma aeval_eq_sum_range [algebra R S] {p : polynomial R} (x : S) :
aeval x p = ∑ i in finset.range (p.nat_degree + 1), p.coeff i • x ^ i :=
by { simp_rw algebra.smul_def, exact eval₂_eq_sum_range (algebra_map R S) x }
lemma aeval_eq_sum_range' [algebra R S] {p : polynomial R} {n : ℕ} (hn : p.nat_degree < n) (x : S) :
aeval x p = ∑ i in finset.range n, p.coeff i • x ^ i :=
by { simp_rw algebra.smul_def, exact eval₂_eq_sum_range' (algebra_map R S) hn x }
end aeval
section ring
variables [ring R]
/--
The evaluation map is not generally multiplicative when the coefficient ring is noncommutative,
but nevertheless any polynomial of the form `p * (X - monomial 0 r)` is sent to zero
when evaluated at `r`.
This is the key step in our proof of the Cayley-Hamilton theorem.
-/
lemma eval_mul_X_sub_C {p : polynomial R} (r : R) :
(p * (X - C r)).eval r = 0 :=
begin
simp only [eval, eval₂, ring_hom.id_apply],
have bound := calc
(p * (X - C r)).nat_degree
≤ p.nat_degree + (X - C r).nat_degree : nat_degree_mul_le
... ≤ p.nat_degree + 1 : add_le_add_left nat_degree_X_sub_C_le _
... < p.nat_degree + 2 : lt_add_one _,
rw sum_over_range' _ _ (p.nat_degree + 2) bound,
swap,
{ simp, },
rw sum_range_succ',
conv_lhs {
congr, apply_congr, skip,
rw [coeff_mul_X_sub_C, sub_mul, mul_assoc, ←pow_succ],
},
simp [sum_range_sub', coeff_monomial],
end
theorem not_is_unit_X_sub_C [nontrivial R] {r : R} : ¬ is_unit (X - C r) :=
λ ⟨⟨_, g, hfg, hgf⟩, rfl⟩, @zero_ne_one R _ _ $ by erw [← eval_mul_X_sub_C, hgf, eval_one]
end ring
lemma aeval_endomorphism {M : Type*}
[comm_ring R] [add_comm_group M] [module R M]
(f : M →ₗ[R] M) (v : M) (p : polynomial R) :
aeval f p v = p.sum (λ n b, b • (f ^ n) v) :=
begin
rw [aeval_def, eval₂],
exact (finset.sum_hom p.support (λ h : M →ₗ[R] M, h v)).symm
end
end polynomial
|
75e9c18e5267710221b69997f315354c3a7e0fb3 | 96b8fa8ff5edc088c62b8e0d92e4599e8edbf1e2 | /Cli/Tests.lean | df7b26d75369fd5e9d1b4fc2f1863380578105a1 | [
"MIT"
] | permissive | pnwamk/lean4-cli | 4429db4cebfca510573150ade5e8ed3087014051 | 0a66055885086864114c8b281830a47f2b601ff4 | refs/heads/main | 1,678,627,315,712 | 1,614,105,437,000 | 1,614,105,437,000 | 342,072,945 | 0 | 0 | null | 1,614,212,319,000 | 1,614,212,318,000 | null | UTF-8 | Lean | false | false | 16,033 | lean | import AssertCmd
import Cli.Basic
import Cli.Extensions
namespace Cli
section Utils
instance [BEq α] [BEq β] : BEq (Except α β) where
beq
| Except.ok a, Except.ok a' => a == a'
| Except.error b, Except.error b' => b == b'
| _, _ => false
instance [Repr α] [Repr β] : Repr (Except α β) where
reprPrec
| Except.ok a, n => s!"Except.ok ({repr a})"
| Except.error b, n => s!"Except.error ({repr b})"
def Cmd.processParsed! (c : Cmd) (args : String) : String := do
match c.process! args.splitOn with
| Except.ok (cmd, parsed) =>
return toString parsed
| Except.error (cmd, error) =>
return error
end Utils
def doNothing (p : Parsed) : IO UInt32 := return 0
def testSubSubCmd : Cmd := `[Cli|
testsubsubcommand VIA doNothing; ["0.0.2"]
"does this even do anything?"
]
def testSubCmd1 : Cmd := `[Cli|
testsubcommand1 VIA doNothing; ["0.0.1"]
"a properly short description"
FLAGS:
"launch-the-nukes"; "please avoid passing this flag at all costs.\nif you like, you can have newlines in descriptions."
ARGS:
"city-location" : String; "can also use hyphens"
SUBCOMMANDS:
testSubSubCmd
]
def testSubCmd2 : Cmd := `[Cli|
testsubcommand2 VIA doNothing; ["0.0.-1"]
"does not do anything interesting"
FLAGS:
r, run; "really, this does not do anything. trust me."
ARGS:
"ominous-input" : Array String; "what could this be for?"
]
def testCmd : Cmd := `[Cli|
testcommand VIA doNothing; ["0.0.0"]
"some short description that happens to be much longer than necessary and hence needs to be wrapped to fit into an 80 character width limit"
FLAGS:
verbose; "a very verbose flag description that also needs to be wrapped to fit into an 80 character width limit"
x, unknown1; "this flag has a short name"
xn, unknown2; "short names do not need to be prefix-free"
ny, unknown3; "-xny will parse as -x -ny and not fail to parse as -xn -y"
t, typed1 : String; "flags can have typed parameters"
ty, typed2; "-ty parsed as --typed2, not -t=y"
"p-n", "level-param" : Nat; "hyphens work, too"
ARGS:
input1 : String; "another very verbose description that also needs to be wrapped to fit into an 80 character width limit"
input2 : Array Nat; "arrays!"
...outputs : Nat; "varargs!"
SUBCOMMANDS: testSubCmd1; testSubCmd2
EXTENSIONS:
author "mhuisi";
longDescription "this could be really long, but i'm too lazy to type it out.";
defaultValues! #[⟨"level-param", "0"⟩];
require! #["typed1"]
]
section ValidInputs
#assert
(testCmd.processParsed! "testcommand foo 1 -ta")
== "cmd: testcommand; flags: #[--typed1=a, --level-param=0]; positionalArgs: #[<input1=foo>, <input2=1>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand -h")
== "cmd: testcommand; flags: #[--help, --level-param=0]; positionalArgs: #[]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand --version")
== "cmd: testcommand; flags: #[--version, --level-param=0]; positionalArgs: #[]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand foo --verbose -p-n 2 1,2,3 1 -xnx 2 --typed1=foo 3")
== "cmd: testcommand; flags: #[--verbose, --level-param=2, --unknown2, --unknown1, --typed1=foo]; positionalArgs: #[<input1=foo>, <input2=1,2,3>]; variableArgs: #[<outputs=1>, <outputs=2>, <outputs=3>]"
#assert
(testCmd.processParsed! "testcommand foo -xny 1 -t 3")
== "cmd: testcommand; flags: #[--unknown1, --unknown3, --typed1=3, --level-param=0]; positionalArgs: #[<input1=foo>, <input2=1>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand -t 3 -- --input 2")
== "cmd: testcommand; flags: #[--typed1=3, --level-param=0]; positionalArgs: #[<input1=--input>, <input2=2>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand -t1 - 2")
== "cmd: testcommand; flags: #[--typed1=1, --level-param=0]; positionalArgs: #[<input1=->, <input2=2>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand -ty -t1 foo 1,2")
== "cmd: testcommand; flags: #[--typed2, --typed1=1, --level-param=0]; positionalArgs: #[<input1=foo>, <input2=1,2>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand testsubcommand1 -- testsubsubcommand")
== "cmd: testcommand testsubcommand1; flags: #[]; positionalArgs: #[<city-location=testsubsubcommand>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand testsubcommand1 --launch-the-nukes x")
== "cmd: testcommand testsubcommand1; flags: #[--launch-the-nukes]; positionalArgs: #[<city-location=x>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand testsubcommand1 -- --launch-the-nukes")
== "cmd: testcommand testsubcommand1; flags: #[]; positionalArgs: #[<city-location=--launch-the-nukes>]; variableArgs: #[]"
#assert
(testCmd.processParsed! "testcommand testsubcommand1 testsubsubcommand")
== "cmd: testcommand testsubcommand1 testsubsubcommand; flags: #[]; positionalArgs: #[]; variableArgs: #[]"
#assert (testCmd.processParsed! "testcommand testsubcommand2 --run asdf,geh")
== "cmd: testcommand testsubcommand2; flags: #[--run]; positionalArgs: #[<ominous-input=asdf,geh>]; variableArgs: #[]"
end ValidInputs
section InvalidInputs
#assert
(testCmd.processParsed! "testcommand")
== "Missing positional argument `<input1>.`"
#assert
(testCmd.processParsed! "testcommand foo")
== "Missing positional argument `<input2>.`"
#assert
(testCmd.processParsed! "testcommand foo asdf")
== "Invalid type of argument `asdf` for positional argument `<input2 : Array Nat>`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3")
== "Missing required flag `--typed1`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t")
== "Missing argument for flag `-t`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 --level-param=")
== "Invalid type of argument `` for flag `--level-param : Nat`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 -p-n=")
== "Invalid type of argument `` for flag `-p-n : Nat`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 --asdf")
== "Unknown flag `--asdf`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 -t2")
== "Duplicate flag `-t` (`--typed1`)."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 --typed1=2")
== "Duplicate flag `--typed1` (`-t`)."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 --typed12")
== "Unknown flag `--typed12`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 -x=1")
== "Redundant argument `1` for flag `-x` that takes no arguments."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 bar")
== "Invalid type of argument `bar` for variable argument `<outputs : Nat>...`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 -t1 -xxn=1")
== "Unknown flag `-xxn`."
#assert
(testCmd.processParsed! "testcommand foo 1,2,3 --t=1")
== "Unknown flag `--t`."
#assert
(testCmd.processParsed! "testcommand testsubcommand1 asdf geh")
== "Redundant positional argument `geh`."
end InvalidInputs
section Info
/-
testcommand [0.0.0]
some short description that happens to be much longer than necessary and hence
needs to be wrapped to fit into an 80 character width limit
USAGE:
testcommand [SUBCOMMAND] [FLAGS] <input1> <input2> <outputs>...
FLAGS:
-h, --help Prints this message.
--version Prints the version.
--verbose a very verbose flag description that also needs
to be wrapped to fit into an 80 character width
limit
-x, --unknown1 this flag has a short name
-xn, --unknown2 short names do not need to be prefix-free
-ny, --unknown3 -xny will parse as -x -ny and not fail to parse
as -xn -y
-t, --typed1 : String flags can have typed parameters
-ty, --typed2 -ty parsed as --typed2, not -t=y
-p-n, --level-param : Nat hyphens work, too
ARGS:
input1 : String another very verbose description that also needs to be
wrapped to fit into an 80 character width limit
input2 : Array Nat arrays!
outputs : Nat varargs!
SUBCOMMANDS:
testsubcommand1 a properly short description
testsubcommand2 does not do anything interesting
-/
#assert
testCmd.help
== "testcommand [0.0.0]\nsome short description that happens to be much longer than necessary and hence\nneeds to be wrapped to fit into an 80 character width limit\n\nUSAGE:\n testcommand [SUBCOMMAND] [FLAGS] <input1> <input2> <outputs>...\n\nFLAGS:\n -h, --help Prints this message.\n --version Prints the version.\n --verbose a very verbose flag description that also needs\n to be wrapped to fit into an 80 character width\n limit\n -x, --unknown1 this flag has a short name\n -xn, --unknown2 short names do not need to be prefix-free\n -ny, --unknown3 -xny will parse as -x -ny and not fail to parse\n as -xn -y\n -t, --typed1 : String flags can have typed parameters\n -ty, --typed2 -ty parsed as --typed2, not -t=y\n -p-n, --level-param : Nat hyphens work, too\n\nARGS:\n input1 : String another very verbose description that also needs to be\n wrapped to fit into an 80 character width limit\n input2 : Array Nat arrays!\n outputs : Nat varargs!\n\nSUBCOMMANDS:\n testsubcommand1 a properly short description\n testsubcommand2 does not do anything interesting"
#assert
testCmd.version
== "0.0.0"
/-
some exceedingly long error that needs to be wrapped to fit within an 80
character width limit. none of our errors are really that long, but flag names
might be.
Run `testcommand -h` for further information.
-/
#assert
(testCmd.error "some exceedingly long error that needs to be wrapped to fit within an 80 character width limit. none of our errors are really that long, but flag names might be.")
== "some exceedingly long error that needs to be wrapped to fit within an 80\ncharacter width limit. none of our errors are really that long, but flag names\nmight be.\nRun `testcommand -h` for further information."
/-
testsubcommand2 [0.0.-1]
does not do anything interesting
USAGE:
testsubcommand2 [FLAGS] <ominous-input>
FLAGS:
-h, --help Prints this message.
--version Prints the version.
-r, --run really, this does not do anything. trust me.
ARGS:
ominous-input : Array String what could this be for?
-/
#assert
testSubCmd2.help
== "testsubcommand2 [0.0.-1]\ndoes not do anything interesting\n\nUSAGE:\n testsubcommand2 [FLAGS] <ominous-input>\n\nFLAGS:\n -h, --help Prints this message.\n --version Prints the version.\n -r, --run really, this does not do anything. trust me.\n\nARGS:\n ominous-input : Array String what could this be for?"
/-
testcommand testsubcommand2 [0.0.-1]
does not do anything interesting
USAGE:
testcommand testsubcommand2 [FLAGS] <ominous-input>
FLAGS:
-h, --help Prints this message.
--version Prints the version.
-r, --run really, this does not do anything. trust me.
ARGS:
ominous-input : Array String what could this be for?
-/
#assert
(testCmd.subCmd! "testsubcommand2").help
== "testcommand testsubcommand2 [0.0.-1]\ndoes not do anything interesting\n\nUSAGE:\n testcommand testsubcommand2 [FLAGS] <ominous-input>\n\nFLAGS:\n -h, --help Prints this message.\n --version Prints the version.\n -r, --run really, this does not do anything. trust me.\n\nARGS:\n ominous-input : Array String what could this be for?"
/-
testcommand testsubcommand1 testsubsubcommand [0.0.2]
does this even do anything?
USAGE:
testcommand testsubcommand1 testsubsubcommand [FLAGS]
FLAGS:
-h, --help Prints this message.
--version Prints the version.
-/
#assert
(testCmd.subCmd! "testsubcommand1" |>.subCmd! "testsubsubcommand").help
== "testcommand testsubcommand1 testsubsubcommand [0.0.2]\ndoes this even do anything?\n\nUSAGE:\n testcommand testsubcommand1 testsubsubcommand [FLAGS]\n\nFLAGS:\n -h, --help Prints this message.\n --version Prints the version."
/-
testcommand [0.0.0]
mhuisi
some short description that happens to be much longer than necessary and hence
needs to be wrapped to fit into an 80 character width limit
USAGE:
testcommand [SUBCOMMAND] [FLAGS] <input1> <input2> <outputs>...
FLAGS:
-h, --help Prints this message.
--version Prints the version.
--verbose a very verbose flag description that also needs
to be wrapped to fit into an 80 character width
limit
-x, --unknown1 this flag has a short name
-xn, --unknown2 short names do not need to be prefix-free
-ny, --unknown3 -xny will parse as -x -ny and not fail to parse
as -xn -y
-t, --typed1 : String [Required] flags can have typed parameters
-ty, --typed2 -ty parsed as --typed2, not -t=y
-p-n, --level-param : Nat hyphens work, too [Default: `0`]
ARGS:
input1 : String another very verbose description that also needs to be
wrapped to fit into an 80 character width limit
input2 : Array Nat arrays!
outputs : Nat varargs!
SUBCOMMANDS:
testsubcommand1 a properly short description
testsubcommand2 does not do anything interesting
DESCRIPTION:
this could be really long, but i'm too lazy to type it out.
-/
#assert
(testCmd.update' (meta := testCmd.extension!.extendMeta testCmd.meta)).help
== "testcommand [0.0.0]\nmhuisi\nsome short description that happens to be much longer than necessary and hence\nneeds to be wrapped to fit into an 80 character width limit\n\nUSAGE:\n testcommand [SUBCOMMAND] [FLAGS] <input1> <input2> <outputs>...\n\nFLAGS:\n -h, --help Prints this message.\n --version Prints the version.\n --verbose a very verbose flag description that also needs\n to be wrapped to fit into an 80 character width\n limit\n -x, --unknown1 this flag has a short name\n -xn, --unknown2 short names do not need to be prefix-free\n -ny, --unknown3 -xny will parse as -x -ny and not fail to parse\n as -xn -y\n -t, --typed1 : String [Required] flags can have typed parameters\n -ty, --typed2 -ty parsed as --typed2, not -t=y\n -p-n, --level-param : Nat hyphens work, too [Default: `0`]\n\nARGS:\n input1 : String another very verbose description that also needs to be\n wrapped to fit into an 80 character width limit\n input2 : Array Nat arrays!\n outputs : Nat varargs!\n\nSUBCOMMANDS:\n testsubcommand1 a properly short description\n testsubcommand2 does not do anything interesting\n\nDESCRIPTION:\n this could be really long, but i'm too lazy to type it out."
end Info
end Cli |
fe36196b6461baea622a19af0ce1a1776f876bf6 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/linear_algebra/quadratic_form.lean | a5b9459f16d960d805cd0a62a19c10d73609057c | [
"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 | 31,369 | 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.invertible
import linear_algebra.bilinear_form
import linear_algebra.determinant
import linear_algebra.special_linear_group
/-!
# Quadratic forms
This file defines quadratic forms over a `R`-module `M`.
A quadratic form is a map `Q : M → R` such that
(`to_fun_smul`) `Q (a • x) = a * a * Q x`
(`polar_...`) The map `polar Q := λ x y, Q (x + y) - Q x - Q y` is bilinear.
They come with a scalar multiplication, `(a • Q) x = Q (a • x) = a * a * Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `quadratic_form.associated`: associated bilinear form
* `quadratic_form.pos_def`: positive definite quadratic forms
* `quadratic_form.anisotropic`: anisotropic quadratic forms
* `quadratic_form.discr`: discriminant of a quadratic form
## Main statements
* `quadratic_form.associated_left_inverse`,
* `quadratic_form.associated_right_inverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic forms and symmetric
bilinear forms
* `bilin_form.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear form `B`.
## Notation
In this file, the variable `R` is used when a `ring` structure is sufficient and
`R₁` is used when specifically a `comm_ring` is required. This allows us to keep
`[module R M]` and `[module R₁ M]` assumptions in the variables without
confusion between `*` from `ring` and `*` from `comm_ring`.
The variable `S` is used when `R` itself has a `•` action.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic form, homogeneous polynomial, quadratic polynomial
-/
universes u v w
variables {S : Type*}
variables {R : Type*} {M : Type*} [add_comm_group M] [ring R]
variables {R₁ : Type*} [comm_ring R₁]
namespace quadratic_form
/-- Up to a factor 2, `Q.polar` is the associated bilinear form for a quadratic form `Q`.d
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M → R) (x y : M) :=
f (x + y) - f x - f y
lemma polar_add (f g : M → R) (x y : M) :
polar (f + g) x y = polar f x y + polar g x y :=
by { simp only [polar, pi.add_apply], abel }
lemma polar_neg (f : M → R) (x y : M) :
polar (-f) x y = - polar f x y :=
by { simp only [polar, pi.neg_apply, sub_eq_add_neg, neg_add] }
lemma polar_smul [monoid S] [distrib_mul_action S R] (f : M → R) (s : S) (x y : M) :
polar (s • f) x y = s • polar f x y :=
by { simp only [polar, pi.smul_apply, smul_sub] }
lemma polar_comm (f : M → R) (x y : M) : polar f x y = polar f y x :=
by rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)]
end quadratic_form
variables [module R M] [module R₁ M]
open quadratic_form
/-- A quadratic form over a module. -/
structure quadratic_form (R : Type u) (M : Type v) [ring R] [add_comm_group M] [module R M] :=
(to_fun : M → R)
(to_fun_smul : ∀ (a : R) (x : M), to_fun (a • x) = a * a * to_fun x)
(polar_add_left' : ∀ (x x' y : M), polar to_fun (x + x') y = polar to_fun x y + polar to_fun x' y)
(polar_smul_left' : ∀ (a : R) (x y : M), polar to_fun (a • x) y = a • polar to_fun x y)
(polar_add_right' : ∀ (x y y' : M), polar to_fun x (y + y') = polar to_fun x y + polar to_fun x y')
(polar_smul_right' : ∀ (a : R) (x y : M), polar to_fun x (a • y) = a • polar to_fun x y)
namespace quadratic_form
variables {Q : quadratic_form R M}
instance : has_coe_to_fun (quadratic_form R M) :=
⟨_, to_fun⟩
/-- The `simp` normal form for a quadratic form is `coe_fn`, not `to_fun`. -/
@[simp] lemma to_fun_eq_apply : Q.to_fun = ⇑ Q := rfl
lemma map_smul (a : R) (x : M) : Q (a • x) = a * a * Q x := Q.to_fun_smul a x
lemma map_add_self (x : M) : Q (x + x) = 4 * Q x :=
by { rw [←one_smul R x, ←add_smul, map_smul], norm_num }
@[simp] lemma map_zero : Q 0 = 0 :=
by rw [←@zero_smul R _ _ _ _ (0 : M), map_smul, zero_mul, zero_mul]
@[simp] lemma map_neg (x : M) : Q (-x) = Q x :=
by rw [←@neg_one_smul R _ _ _ _ x, map_smul, neg_one_mul, neg_neg, one_mul]
lemma map_sub (x y : M) : Q (x - y) = Q (y - x) :=
by rw [←neg_sub, map_neg]
@[simp]
lemma polar_zero_left (y : M) : polar Q 0 y = 0 :=
by simp [polar]
@[simp]
lemma polar_add_left (x x' y : M) :
polar Q (x + x') y = polar Q x y + polar Q x' y :=
Q.polar_add_left' x x' y
@[simp]
lemma polar_smul_left (a : R) (x y : M) :
polar Q (a • x) y = a * polar Q x y :=
Q.polar_smul_left' a x y
@[simp]
lemma polar_neg_left (x y : M) :
polar Q (-x) y = -polar Q x y :=
by rw [←neg_one_smul R x, polar_smul_left, neg_one_mul]
@[simp]
lemma polar_sub_left (x x' y : M) :
polar Q (x - x') y = polar Q x y - polar Q x' y :=
by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
@[simp]
lemma polar_zero_right (y : M) : polar Q y 0 = 0 :=
by simp [polar]
@[simp]
lemma polar_add_right (x y y' : M) :
polar Q x (y + y') = polar Q x y + polar Q x y' :=
Q.polar_add_right' x y y'
@[simp]
lemma polar_smul_right (a : R) (x y : M) :
polar Q x (a • y) = a * polar Q x y :=
Q.polar_smul_right' a x y
@[simp]
lemma polar_neg_right (x y : M) :
polar Q x (-y) = -polar Q x y :=
by rw [←neg_one_smul R y, polar_smul_right, neg_one_mul]
@[simp]
lemma polar_sub_right (x y y' : M) :
polar Q x (y - y') = polar Q x y - polar Q x y' :=
by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right]
@[simp]
lemma polar_self (x : M) : polar Q x x = 2 * Q x :=
begin
rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ←two_mul, ←two_mul, ←mul_assoc],
norm_num
end
section of_tower
variables [comm_semiring S] [algebra S R] [module S M] [is_scalar_tower S R M]
@[simp]
lemma polar_smul_left_of_tower (a : S) (x y : M) :
polar Q (a • x) y = a • polar Q x y :=
by rw [←is_scalar_tower.algebra_map_smul R a x, polar_smul_left, algebra.smul_def]
@[simp]
lemma polar_smul_right_of_tower (a : S) (x y : M) :
polar Q x (a • y) = a • polar Q x y :=
by rw [←is_scalar_tower.algebra_map_smul R a y, polar_smul_right, algebra.smul_def]
end of_tower
variable {Q' : quadratic_form R M}
@[ext] lemma ext (H : ∀ (x : M), Q x = Q' x) : Q = Q' :=
by { cases Q, cases Q', congr, funext, apply H }
instance : has_zero (quadratic_form R M) :=
⟨ { to_fun := λ x, 0,
to_fun_smul := λ a x, by simp,
polar_add_left' := λ x x' y, by simp [polar],
polar_smul_left' := λ a x y, by simp [polar],
polar_add_right' := λ x y y', by simp [polar],
polar_smul_right' := λ a x y, by simp [polar] } ⟩
@[simp] lemma coe_fn_zero : ⇑(0 : quadratic_form R M) = 0 := rfl
@[simp] lemma zero_apply (x : M) : (0 : quadratic_form R M) x = 0 := rfl
instance : inhabited (quadratic_form R M) := ⟨0⟩
instance : has_add (quadratic_form R M) :=
⟨ λ Q Q',
{ to_fun := Q + Q',
to_fun_smul := λ a x,
by simp only [pi.add_apply, map_smul, mul_add],
polar_add_left' := λ x x' y,
by simp only [polar_add, polar_add_left, add_assoc, add_left_comm],
polar_smul_left' := λ a x y,
by simp only [polar_add, smul_eq_mul, mul_add, polar_smul_left],
polar_add_right' := λ x y y',
by simp only [polar_add, polar_add_right, add_assoc, add_left_comm],
polar_smul_right' := λ a x y,
by simp only [polar_add, smul_eq_mul, mul_add, polar_smul_right] } ⟩
@[simp] lemma coe_fn_add (Q Q' : quadratic_form R M) : ⇑(Q + Q') = Q + Q' := rfl
@[simp] lemma add_apply (Q Q' : quadratic_form R M) (x : M) : (Q + Q') x = Q x + Q' x := rfl
instance : has_neg (quadratic_form R M) :=
⟨ λ Q,
{ to_fun := -Q,
to_fun_smul := λ a x,
by simp only [pi.neg_apply, map_smul, mul_neg_eq_neg_mul_symm],
polar_add_left' := λ x x' y,
by simp only [polar_neg, polar_add_left, neg_add],
polar_smul_left' := λ a x y,
by simp only [polar_neg, polar_smul_left, mul_neg_eq_neg_mul_symm, smul_eq_mul],
polar_add_right' := λ x y y',
by simp only [polar_neg, polar_add_right, neg_add],
polar_smul_right' := λ a x y,
by simp only [polar_neg, polar_smul_right, mul_neg_eq_neg_mul_symm, smul_eq_mul] } ⟩
@[simp] lemma coe_fn_neg (Q : quadratic_form R M) : ⇑(-Q) = -Q := rfl
@[simp] lemma neg_apply (Q : quadratic_form R M) (x : M) : (-Q) x = -Q x := rfl
instance : add_comm_group (quadratic_form R M) :=
{ add := (+),
zero := 0,
neg := has_neg.neg,
add_comm := λ Q Q', by { ext, simp only [add_apply, add_comm] },
add_assoc := λ Q Q' Q'', by { ext, simp only [add_apply, add_assoc] },
add_left_neg := λ Q, by { ext, simp only [add_apply, neg_apply, zero_apply, add_left_neg] },
add_zero := λ Q, by { ext, simp only [zero_apply, add_apply, add_zero] },
zero_add := λ Q, by { ext, simp only [zero_apply, add_apply, zero_add] } }
@[simp] lemma coe_fn_sub (Q Q' : quadratic_form R M) : ⇑(Q - Q') = Q - Q' :=
by simp [sub_eq_add_neg]
@[simp] lemma sub_apply (Q Q' : quadratic_form R M) (x : M) : (Q - Q') x = Q x - Q' x :=
by simp [sub_eq_add_neg]
/-- `@coe_fn (quadratic_form R M)` as an `add_monoid_hom`.
This API mirrors `add_monoid_hom.coe_fn`. -/
@[simps apply]
def coe_fn_add_monoid_hom : quadratic_form R M →+ (M → R) :=
{ to_fun := coe_fn, map_zero' := coe_fn_zero, map_add' := coe_fn_add }
/-- Evaluation on a particular element of the module `M` is an additive map over quadratic forms. -/
@[simps apply]
def eval_add_monoid_hom (m : M) : quadratic_form R M →+ R :=
(add_monoid_hom.apply _ m).comp coe_fn_add_monoid_hom
section sum
open_locale big_operators
@[simp] lemma coe_fn_sum {ι : Type*} (Q : ι → quadratic_form R M) (s : finset ι) :
⇑(∑ i in s, Q i) = ∑ i in s, Q i :=
(coe_fn_add_monoid_hom : _ →+ (M → R)).map_sum Q s
@[simp] lemma sum_apply {ι : Type*} (Q : ι → quadratic_form R M) (s : finset ι) (x : M) :
(∑ i in s, Q i) x = ∑ i in s, Q i x :=
(eval_add_monoid_hom x : _ →+ R).map_sum Q s
end sum
section has_scalar
variables [comm_semiring S] [algebra S R]
/-- `quadratic_form R M` inherits the scalar action from any algebra over `R`.
When `R` is commutative, this provides an `R`-action via `algebra.id`. -/
instance : has_scalar S (quadratic_form R M) :=
⟨ λ a Q,
{ to_fun := a • Q,
to_fun_smul := λ b x, by rw [pi.smul_apply, map_smul, pi.smul_apply, algebra.mul_smul_comm],
polar_add_left' := λ x x' y, by simp only [polar_smul, polar_add_left, smul_add],
polar_smul_left' := λ b x y, begin
simp only [polar_smul, polar_smul_left, ←algebra.mul_smul_comm, smul_eq_mul],
end,
polar_add_right' := λ x y y', by simp only [polar_smul, polar_add_right, smul_add],
polar_smul_right' := λ b x y, begin
simp only [polar_smul, polar_smul_right, ←algebra.mul_smul_comm, smul_eq_mul],
end } ⟩
@[simp] lemma coe_fn_smul (a : S) (Q : quadratic_form R M) : ⇑(a • Q) = a • Q := rfl
@[simp] lemma smul_apply (a : S) (Q : quadratic_form R M) (x : M) :
(a • Q) x = a • Q x := rfl
instance : module S (quadratic_form R M) :=
{ mul_smul := λ a b Q, ext (λ x, by
simp only [smul_apply, mul_left_comm, ←smul_eq_mul, smul_assoc]),
one_smul := λ Q, ext (λ x, by simp),
smul_add := λ a Q Q', by { ext, simp only [add_apply, smul_apply, smul_add] },
smul_zero := λ a, by { ext, simp only [zero_apply, smul_apply, smul_zero] },
zero_smul := λ Q, by { ext, simp only [zero_apply, smul_apply, zero_smul] },
add_smul := λ a b Q, by { ext, simp only [add_apply, smul_apply, add_smul] } }
end has_scalar
section comp
variables {N : Type v} [add_comm_group N] [module R N]
/-- Compose the quadratic form with a linear function. -/
def comp (Q : quadratic_form R N) (f : M →ₗ[R] N) :
quadratic_form R M :=
{ to_fun := λ x, Q (f x),
to_fun_smul := λ a x, by simp only [map_smul, f.map_smul],
polar_add_left' := λ x x' y,
by convert polar_add_left (f x) (f x') (f y) using 1;
simp only [polar, f.map_add],
polar_smul_left' := λ a x y,
by convert polar_smul_left a (f x) (f y) using 1;
simp only [polar, f.map_smul, f.map_add, smul_eq_mul],
polar_add_right' := λ x y y',
by convert polar_add_right (f x) (f y) (f y') using 1;
simp only [polar, f.map_add],
polar_smul_right' := λ a x y,
by convert polar_smul_right a (f x) (f y) using 1;
simp only [polar, f.map_smul, f.map_add, smul_eq_mul] }
@[simp] lemma comp_apply (Q : quadratic_form R N) (f : M →ₗ[R] N) (x : M) :
(Q.comp f) x = Q (f x) := rfl
end comp
section comm_ring
/-- Create a quadratic form in a commutative ring by proving only one side of the bilinearity. -/
def mk_left (f : M → R₁)
(to_fun_smul : ∀ a x, f (a • x) = a * a * f x)
(polar_add_left : ∀ x x' y, polar f (x + x') y = polar f x y + polar f x' y)
(polar_smul_left : ∀ a x y, polar f (a • x) y = a * polar f x y) :
quadratic_form R₁ M :=
{ to_fun := f,
to_fun_smul := to_fun_smul,
polar_add_left' := polar_add_left,
polar_smul_left' := polar_smul_left,
polar_add_right' :=
λ x y y', by rw [polar_comm, polar_add_left, polar_comm f y x, polar_comm f y' x],
polar_smul_right' :=
λ a x y, by rw [polar_comm, polar_smul_left, polar_comm f y x, smul_eq_mul] }
/-- The product of linear forms is a quadratic form. -/
def lin_mul_lin (f g : M →ₗ[R₁] R₁) : quadratic_form R₁ M :=
mk_left (f * g)
(λ a x, by { simp, ring })
(λ x x' y, by { simp [polar], ring })
(λ a x y, by { simp [polar], ring })
@[simp]
lemma lin_mul_lin_apply (f g : M →ₗ[R₁] R₁) (x) : lin_mul_lin f g x = f x * g x := rfl
@[simp]
lemma add_lin_mul_lin (f g h : M →ₗ[R₁] R₁) :
lin_mul_lin (f + g) h = lin_mul_lin f h + lin_mul_lin g h :=
ext (λ x, add_mul _ _ _)
@[simp]
lemma lin_mul_lin_add (f g h : M →ₗ[R₁] R₁) :
lin_mul_lin f (g + h) = lin_mul_lin f g + lin_mul_lin f h :=
ext (λ x, mul_add _ _ _)
variables {N : Type v} [add_comm_group N] [module R₁ N]
@[simp]
lemma lin_mul_lin_comp (f g : M →ₗ[R₁] R₁) (h : N →ₗ[R₁] M) :
(lin_mul_lin f g).comp h = lin_mul_lin (f.comp h) (g.comp h) :=
rfl
variables {n : Type*}
/-- `proj i j` is the quadratic form mapping the vector `x : n → R₁` to `x i * x j` -/
def proj (i j : n) : quadratic_form R₁ (n → R₁) :=
lin_mul_lin (@linear_map.proj _ _ _ (λ _, R₁) _ _ i) (@linear_map.proj _ _ _ (λ _, R₁) _ _ j)
@[simp]
lemma proj_apply (i j : n) (x : n → R₁) : proj i j x = x i * x j := rfl
end comm_ring
end quadratic_form
/-!
### Associated bilinear forms
Over a commutative ring with an inverse of 2, the theory of quadratic forms is
basically identical to that of symmetric bilinear forms. The map from quadratic
forms to bilinear forms giving this identification is called the `associated`
quadratic form.
-/
variables {B : bilin_form R M}
namespace bilin_form
open quadratic_form
lemma polar_to_quadratic_form (x y : M) : polar (λ x, B x x) x y = B x y + B y x :=
by simp [polar, add_left, add_right, sub_eq_add_neg _ (B y y), add_comm (B y x) _, add_assoc]
/-- A bilinear form gives a quadratic form by applying the argument twice. -/
def to_quadratic_form (B : bilin_form R M) : quadratic_form R M :=
⟨ λ x, B x x,
λ a x, by simp [smul_left, smul_right, mul_assoc],
λ x x' y, by simp [polar_to_quadratic_form, add_left, add_right, add_left_comm, add_assoc],
λ a x y, by simp [polar_to_quadratic_form, smul_left, smul_right, mul_add],
λ x y y', by simp [polar_to_quadratic_form, add_left, add_right, add_left_comm, add_assoc],
λ a x y, by simp [polar_to_quadratic_form, smul_left, smul_right, mul_add] ⟩
@[simp] lemma to_quadratic_form_apply (B : bilin_form R M) (x : M) :
B.to_quadratic_form x = B x x :=
rfl
end bilin_form
namespace quadratic_form
open bilin_form sym_bilin_form
section associated_hom
variables (S) [comm_semiring S] [algebra S R]
variables [invertible (2 : R)] {B₁ : bilin_form R M}
/-- `associated_hom` is the map that sends a quadratic form on a module `M` over `R` to its
associated symmetric bilinear form. As provided here, this has the structure of an `S`-linear map
where `S` is a commutative subring of `R`.
Over a commutative ring, use `associated`, which gives an `R`-linear map. Over a general ring with
no nontrivial distinguished commutative subring, use `associated'`, which gives an additive
homomorphism (or more precisely a `ℤ`-linear map.) -/
def associated_hom : quadratic_form R M →ₗ[S] bilin_form R M :=
{ to_fun := λ Q,
{ bilin := λ x y, ⅟2 * polar Q x y,
bilin_add_left := λ x y z, by rw [← mul_add, polar_add_left],
bilin_smul_left := λ x y z, begin
have htwo : x * ⅟2 = ⅟2 * x := (commute.one_right x).bit0_right.inv_of_right,
simp [polar_smul_left, ← mul_assoc, htwo]
end,
bilin_add_right := λ x y z, by rw [← mul_add, polar_add_right],
bilin_smul_right := λ x y z, begin
have htwo : x * ⅟2 = ⅟2 * x := (commute.one_right x).bit0_right.inv_of_right,
simp [polar_smul_left, ← mul_assoc, htwo]
end },
map_add' := λ Q Q', by { ext, simp [bilin_form.add_apply, polar_add, mul_add] },
map_smul' := λ s Q, by { ext, simp [polar_smul, algebra.mul_smul_comm] } }
variables {Q : quadratic_form R M} {S}
@[simp] lemma associated_apply (x y : M) :
associated_hom S Q x y = ⅟2 * (Q (x + y) - Q x - Q y) := rfl
lemma associated_is_sym : is_sym (associated_hom S Q) :=
λ x y, by simp only [associated_apply, add_comm, add_left_comm, sub_eq_add_neg]
@[simp] lemma associated_comp {N : Type v} [add_comm_group N] [module R N] (f : N →ₗ[R] M) :
associated_hom S (Q.comp f) = (associated_hom S Q).comp f f :=
by { ext, simp }
lemma associated_to_quadratic_form (B : bilin_form R M) (x y : M) :
associated_hom S B.to_quadratic_form x y = ⅟2 * (B x y + B y x) :=
by simp [associated_apply, ←polar_to_quadratic_form, polar]
lemma associated_left_inverse (h : is_sym B₁) :
associated_hom S (B₁.to_quadratic_form) = B₁ :=
bilin_form.ext $ λ x y,
by rw [associated_to_quadratic_form, sym h x y, ←two_mul, ←mul_assoc, inv_of_mul_self, one_mul]
lemma associated_right_inverse : (associated_hom S Q).to_quadratic_form = Q :=
quadratic_form.ext $ λ x,
calc (associated_hom S Q).to_quadratic_form x
= ⅟2 * (Q x + Q x) : by simp [map_add_self, bit0, add_mul, add_assoc]
... = Q x : by rw [← two_mul (Q x), ←mul_assoc, inv_of_mul_self, one_mul]
lemma associated_eq_self_apply (x : M) : associated_hom S Q x x = Q x :=
begin
rw [associated_apply, map_add_self],
suffices : (⅟2) * (2 * Q x) = Q x,
{ convert this,
simp only [bit0, add_mul, one_mul],
abel },
simp [← mul_assoc],
end
/-- `associated'` is the `ℤ`-linear map that sends a quadratic form on a module `M` over `R` to its
associated symmetric bilinear form. -/
abbreviation associated' : quadratic_form R M →ₗ[ℤ] bilin_form R M :=
associated_hom ℤ
/-- There exists a non-null vector with respect to any quadratic form `Q` whose associated
bilinear form is non-degenerate, i.e. there exists `x` such that `Q x ≠ 0`. -/
lemma exists_quadratic_form_neq_zero [nontrivial M]
{Q : quadratic_form R M} (hB₁ : Q.associated'.nondegenerate) :
∃ x, Q x ≠ 0 :=
begin
rw nondegenerate at hB₁,
contrapose! hB₁,
obtain ⟨x, hx⟩ := exists_ne (0 : M),
refine ⟨x, λ y, _, hx⟩,
have : Q = 0 := quadratic_form.ext hB₁,
simp [this]
end
end associated_hom
section associated
variables [invertible (2 : R₁)]
-- Note: When possible, rather than writing lemmas about `associated`, write a lemma applying to
-- the more general `associated_hom` and place it in the previous section.
/-- `associated` is the linear map that sends a quadratic form over a commutative ring to its
associated symmetric bilinear form. -/
abbreviation associated : quadratic_form R₁ M →ₗ[R₁] bilin_form R₁ M :=
associated_hom R₁
@[simp] lemma associated_lin_mul_lin (f g : M →ₗ[R₁] R₁) :
(lin_mul_lin f g).associated =
⅟(2 : R₁) • (bilin_form.lin_mul_lin f g + bilin_form.lin_mul_lin g f) :=
by { ext, simp [bilin_form.add_apply, bilin_form.smul_apply], ring }
end associated
section anisotropic
/-- An anisotropic quadratic form is zero only on zero vectors. -/
def anisotropic (Q : quadratic_form R M) : Prop := ∀ x, Q x = 0 → x = 0
lemma not_anisotropic_iff_exists (Q : quadratic_form R M) :
¬anisotropic Q ↔ ∃ x ≠ 0, Q x = 0 :=
by simp only [anisotropic, not_forall, exists_prop, and_comm]
/-- The associated bilinear form of an anisotropic quadratic form is nondegenerate. -/
lemma nondegenerate_of_anisotropic [invertible (2 : R)] (Q : quadratic_form R M)
(hB : Q.anisotropic) : Q.associated'.nondegenerate :=
begin
intros x hx,
refine hB _ _,
rw ← hx x,
exact (associated_eq_self_apply x).symm,
end
end anisotropic
section pos_def
variables {R₂ : Type u} [ordered_ring R₂] [module R₂ M] {Q₂ : quadratic_form R₂ M}
/-- A positive definite quadratic form is positive on nonzero vectors. -/
def pos_def (Q₂ : quadratic_form R₂ M) : Prop := ∀ x ≠ 0, 0 < Q₂ x
lemma pos_def.smul {R} [linear_ordered_comm_ring R] [module R M]
{Q : quadratic_form R M} (h : pos_def Q) {a : R} (a_pos : 0 < a) : pos_def (a • Q) :=
λ x hx, mul_pos a_pos (h x hx)
variables {n : Type*}
lemma pos_def.add (Q Q' : quadratic_form R₂ M) (hQ : pos_def Q) (hQ' : pos_def Q') :
pos_def (Q + Q') :=
λ x hx, add_pos (hQ x hx) (hQ' x hx)
lemma lin_mul_lin_self_pos_def {R} [linear_ordered_comm_ring R] [module R M]
(f : M →ₗ[R] R) (hf : linear_map.ker f = ⊥) :
pos_def (lin_mul_lin f f) :=
λ x hx, mul_self_pos (λ h, hx (linear_map.ker_eq_bot.mp hf (by rw [h, linear_map.map_zero])))
end pos_def
end quadratic_form
section
/-!
### Quadratic forms and matrices
Connect quadratic forms and matrices, in order to explicitly compute with them.
The convention is twos out, so there might be a factor 2⁻¹ in the entries of the
matrix.
The determinant of the matrix is the discriminant of the quadratic form.
-/
variables {n : Type w} [fintype n] [decidable_eq n]
/-- `M.to_quadratic_form` is the map `λ x, col x ⬝ M ⬝ row x` as a quadratic form. -/
def matrix.to_quadratic_form' (M : matrix n n R₁) :
quadratic_form R₁ (n → R₁) :=
M.to_bilin'.to_quadratic_form
variables [invertible (2 : R₁)]
/-- A matrix representation of the quadratic form. -/
def quadratic_form.to_matrix' (Q : quadratic_form R₁ (n → R₁)) : matrix n n R₁ :=
Q.associated.to_matrix'
open quadratic_form
lemma quadratic_form.to_matrix'_smul (a : R₁) (Q : quadratic_form R₁ (n → R₁)) :
(a • Q).to_matrix' = a • Q.to_matrix' :=
by simp only [to_matrix', linear_equiv.map_smul, linear_map.map_smul]
end
namespace quadratic_form
variables {n : Type w} [fintype n]
variables [decidable_eq n] [invertible (2 : R₁)]
variables {m : Type w} [decidable_eq m] [fintype m]
open_locale matrix
@[simp]
lemma to_matrix'_comp (Q : quadratic_form R₁ (m → R₁)) (f : (n → R₁) →ₗ[R₁] (m → R₁)) :
(Q.comp f).to_matrix' = f.to_matrix'ᵀ ⬝ Q.to_matrix' ⬝ f.to_matrix' :=
by { ext, simp [to_matrix', bilin_form.to_matrix'_comp] }
section discriminant
variables {Q : quadratic_form R₁ (n → R₁)}
/-- The discriminant of a quadratic form generalizes the discriminant of a quadratic polynomial. -/
def discr (Q : quadratic_form R₁ (n → R₁)) : R₁ := Q.to_matrix'.det
lemma discr_smul (a : R₁) : (a • Q).discr = a ^ fintype.card n * Q.discr :=
by simp only [discr, to_matrix'_smul, matrix.det_smul]
lemma discr_comp (f : (n → R₁) →ₗ[R₁] (n → R₁)) :
(Q.comp f).discr = f.to_matrix'.det * f.to_matrix'.det * Q.discr :=
by simp [discr, mul_left_comm, mul_comm]
end discriminant
end quadratic_form
namespace quadratic_form
variables {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
variables [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M₁] [module R M₂] [module R M₃]
/-- An isometry between two quadratic spaces `M₁, Q₁` and `M₂, Q₂` over a ring `R`,
is a linear equivalence between `M₁` and `M₂` that commutes with the quadratic forms. -/
@[nolint has_inhabited_instance] structure isometry
(Q₁ : quadratic_form R M₁) (Q₂ : quadratic_form R M₂) extends M₁ ≃ₗ[R] M₂ :=
(map_app' : ∀ m, Q₂ (to_fun m) = Q₁ m)
/-- Two quadratic forms over a ring `R` are equivalent
if there exists an isometry between them:
a linear equivalence that transforms one quadratic form into the other. -/
def equivalent (Q₁ : quadratic_form R M₁) (Q₂ : quadratic_form R M₂) := nonempty (Q₁.isometry Q₂)
namespace isometry
variables {Q₁ : quadratic_form R M₁} {Q₂ : quadratic_form R M₂} {Q₃ : quadratic_form R M₃}
instance : has_coe (Q₁.isometry Q₂) (M₁ ≃ₗ[R] M₂) := ⟨isometry.to_linear_equiv⟩
instance : has_coe_to_fun (Q₁.isometry Q₂) :=
{ F := λ _, M₁ → M₂, coe := λ f, ⇑(f : M₁ ≃ₗ[R] M₂) }
@[simp] lemma map_app (f : Q₁.isometry Q₂) (m : M₁) : Q₂ (f m) = Q₁ m := f.map_app' m
/-- The identity isometry from a quadratic form to itself. -/
@[refl]
def refl (Q : quadratic_form R M) : Q.isometry Q :=
{ map_app' := λ m, rfl,
.. linear_equiv.refl R M }
/-- The inverse isometry of an isometry between two quadratic forms. -/
@[symm]
def symm (f : Q₁.isometry Q₂) : Q₂.isometry Q₁ :=
{ map_app' := by { intro m, rw ← f.map_app, congr, exact f.to_linear_equiv.apply_symm_apply m },
.. (f : M₁ ≃ₗ[R] M₂).symm }
/-- The composition of two isometries between quadratic forms. -/
@[trans]
def trans (f : Q₁.isometry Q₂) (g : Q₂.isometry Q₃) : Q₁.isometry Q₃ :=
{ map_app' := by { intro m, rw [← f.map_app, ← g.map_app], refl },
.. (f : M₁ ≃ₗ[R] M₂).trans (g : M₂ ≃ₗ[R] M₃) }
end isometry
namespace equivalent
variables {Q₁ : quadratic_form R M₁} {Q₂ : quadratic_form R M₂} {Q₃ : quadratic_form R M₃}
@[refl]
lemma refl (Q : quadratic_form R M) : Q.equivalent Q := ⟨isometry.refl Q⟩
@[symm]
lemma symm (h : Q₁.equivalent Q₂) : Q₂.equivalent Q₁ := h.elim $ λ f, ⟨f.symm⟩
@[trans]
lemma trans (h : Q₁.equivalent Q₂) (h' : Q₂.equivalent Q₃) : Q₁.equivalent Q₃ :=
h'.elim $ h.elim $ λ f g, ⟨f.trans g⟩
end equivalent
end quadratic_form
namespace bilin_form
/-- A bilinear form is nondegenerate if the quadratic form it is associated with is anisotropic. -/
lemma nondegenerate_of_anisotropic
{B : bilin_form R M} (hB : B.to_quadratic_form.anisotropic) : B.nondegenerate :=
λ x hx, hB _ (hx x)
/-- There exists a non-null vector with respect to any symmetric, nondegenerate bilinear form `B`
on a nontrivial module `M` over a ring `R` with invertible `2`, i.e. there exists some
`x : M` such that `B x x ≠ 0`. -/
lemma exists_bilin_form_self_neq_zero [htwo : invertible (2 : R)] [nontrivial M]
{B : bilin_form R M} (hB₁ : B.nondegenerate) (hB₂ : sym_bilin_form.is_sym B) :
∃ x, ¬ B.is_ortho x x :=
begin
have : B.to_quadratic_form.associated'.nondegenerate,
{ simpa [quadratic_form.associated_left_inverse hB₂] using hB₁ },
obtain ⟨x, hx⟩ := quadratic_form.exists_quadratic_form_neq_zero this,
refine ⟨x, λ h, hx (B.to_quadratic_form_apply x ▸ h)⟩,
end
open finite_dimensional
variables {V : Type u} {K : Type v} [field K] [add_comm_group V] [module K V]
variable [finite_dimensional K V]
-- We start proving that symmetric nondegenerate bilinear forms are diagonalisable, or equivalently
-- there exists a orthogonal basis with respect to any symmetric nondegenerate bilinear form.
lemma exists_orthogonal_basis' [hK : invertible (2 : K)]
{B : bilin_form K V} (hB₁ : B.nondegenerate) (hB₂ : sym_bilin_form.is_sym B) :
∃ v : fin (finrank K V) → V,
B.is_Ortho v ∧ is_basis K v ∧ ∀ i, B (v i) (v i) ≠ 0 :=
begin
tactic.unfreeze_local_instances,
induction hd : finrank K V with d ih generalizing V,
{ exact ⟨λ _, 0, λ _ _ _, zero_left _, is_basis_of_finrank_zero' hd, fin.elim0⟩ },
{ haveI := finrank_pos_iff.1 (hd.symm ▸ nat.succ_pos d : 0 < finrank K V),
cases exists_bilin_form_self_neq_zero hB₁ hB₂ with x hx,
{ have hd' := hd,
rw [← submodule.finrank_add_eq_of_is_compl
(is_compl_span_singleton_orthogonal hx).symm,
finrank_span_singleton (ne_zero_of_not_is_ortho_self x hx)] at hd,
rcases @ih (B.orthogonal $ K ∙ x) _ _ _
(B.restrict _) (B.restrict_orthogonal_span_singleton_nondegenerate hB₁ hB₂ hx)
(B.restrict_sym hB₂ _) (nat.succ.inj hd) with ⟨v', hv₁, hv₂, hv₃⟩,
refine ⟨λ i, if h : i ≠ 0 then coe (v' (i.pred h)) else x, λ i j hij, _, _, _⟩,
{ by_cases hi : i = 0,
{ subst i,
simp only [eq_self_iff_true, not_true, ne.def, dif_neg,
not_false_iff, dite_not],
rw [dif_neg hij.symm, is_ortho, hB₂],
exact (v' (j.pred hij.symm)).2 _ (submodule.mem_span_singleton_self x) },
by_cases hj : j = 0,
{ subst j,
simp only [eq_self_iff_true, not_true, ne.def, dif_neg,
not_false_iff, dite_not],
rw dif_neg hi,
exact (v' (i.pred hi)).2 _ (submodule.mem_span_singleton_self x) },
{ simp_rw [dif_pos hi, dif_pos hj],
rw [is_ortho, hB₂],
exact hv₁ (j.pred hj) (i.pred hi) (by simpa using hij.symm) } },
{ refine is_basis_of_linear_independent_of_card_eq_finrank
(@linear_independent_of_is_Ortho _ _ _ _ _ _ B _ _ _)
(by rw [hd', fintype.card_fin]),
{ intros i j hij,
by_cases hi : i = 0,
{ subst hi,
simp only [eq_self_iff_true, not_true, ne.def, dif_neg,
not_false_iff, dite_not],
rw [dif_neg hij.symm, is_ortho, hB₂],
exact (v' (j.pred hij.symm)).2 _ (submodule.mem_span_singleton_self x) },
by_cases hj : j = 0,
{ subst j,
simp only [eq_self_iff_true, not_true, ne.def, dif_neg,
not_false_iff, dite_not],
rw dif_neg hi,
exact (v' (i.pred hi)).2 _ (submodule.mem_span_singleton_self x) },
{ simp_rw [dif_pos hi, dif_pos hj],
rw [is_ortho, hB₂],
exact hv₁ (j.pred hj) (i.pred hi) (by simpa using hij.symm) } },
{ intro i,
by_cases hi : i ≠ 0,
{ rw dif_pos hi,
exact hv₃ (i.pred hi) },
{ rw dif_neg hi, exact hx } } },
{ intro i,
by_cases hi : i ≠ 0,
{ rw dif_pos hi,
exact hv₃ (i.pred hi) },
{ rw dif_neg hi, exact hx } } } }
end .
/-- Given a nondegenerate symmetric bilinear form `B` on some vector space `V` over the
field `K` with invertible `2`, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : invertible (2 : K)]
{B : bilin_form K V} (hB₁ : B.nondegenerate) (hB₂ : sym_bilin_form.is_sym B) :
∃ v : fin (finrank K V) → V, B.is_Ortho v ∧ is_basis K v :=
let ⟨v, hv₁, hv₂, _⟩ := exists_orthogonal_basis' hB₁ hB₂ in ⟨v, hv₁, hv₂⟩
end bilin_form
|
7d191e13c3489a3405e350643063ecdce9542e69 | ad0c7d243dc1bd563419e2767ed42fb323d7beea | /data/padics/padic_integers.lean | e2d58321dd2649e6b962451cb84159192fa7ce4a | [
"Apache-2.0"
] | permissive | sebzim4500/mathlib | e0b5a63b1655f910dee30badf09bd7e191d3cf30 | 6997cafbd3a7325af5cb318561768c316ceb7757 | refs/heads/master | 1,585,549,958,618 | 1,538,221,723,000 | 1,538,221,723,000 | 150,869,076 | 0 | 0 | Apache-2.0 | 1,538,229,323,000 | 1,538,229,323,000 | null | UTF-8 | Lean | false | false | 1,249 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
Define the p-adic integers ℤ_p as a subtype of ℚ_p. Show ℤ_p is a ring.
-/
import data.padics.padic_rationals
open nat padic
noncomputable theory
section padic_int
variables {p : ℕ} (hp : prime p)
def padic_int := {x : ℚ_[hp] // padic_norm_e x ≤ 1}
notation `ℤ_[`hp`]` := padic_int hp
end padic_int
namespace padic_int
variables {p : ℕ} {hp : prime p}
def add : ℤ_[hp] → ℤ_[hp] → ℤ_[hp]
| ⟨x, hx⟩ ⟨y, hy⟩ := ⟨x+y,
le_trans (padic_norm_e.nonarchimedean _ _) (max_le_iff.2 ⟨hx,hy⟩)⟩
def mul : ℤ_[hp] → ℤ_[hp] → ℤ_[hp]
| ⟨x, hx⟩ ⟨y, hy⟩ := ⟨x*y,
begin rw padic_norm_e.mul, apply mul_le_one; {assumption <|> apply padic_norm_e.nonneg} end⟩
def neg : ℤ_[hp] → ℤ_[hp]
| ⟨x, hx⟩ := ⟨-x, by simpa⟩
instance : ring ℤ_[hp] :=
begin
refine { add := add,
mul := mul,
neg := neg,
zero := ⟨0, by simp⟩,
one := ⟨1, by simp⟩,
.. };
{repeat {rintro ⟨_, _⟩}, simp [mul_assoc, left_distrib, right_distrib, add, mul, neg]}
end
end padic_int |
58bb3ed857fb93efe71cc79dc128b880f1d26310 | a7602958ab456501ff85db8cf5553f7bcab201d7 | /Notes/Logic_and_Proof/Chapter9/9.21.lean | 4febc02dfe1caf925f1d04daac0ce8cdd1ea5cf5 | [] | no_license | enlauren/math-logic | 081e2e737c8afb28dbb337968df95ead47321ba0 | 086b6935543d1841f1db92d0e49add1124054c37 | refs/heads/master | 1,594,506,621,950 | 1,558,634,976,000 | 1,558,634,976,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,094 | lean | -- 9.2 Using the universal quantifier ...continued
import init.data.nat
open nat
variable U : Type
variables A B : U → Prop
-- So we'll be using ∀-Introduction, since we are proving a universally
-- quantified statement, therefore we start with some baser assumption, and
-- introduce a ∀, to match the proof we need.
variable h1: ∀ x, A x → B x
variable h2: ∀ x, A x
example : ∀ x, B x :=
assume y, -- Some |U| (|Type|). Can also be called |x|, it seems.
show B y, from
have h3: A y, from h2 y, -- Just like last file, where we apply an assumption
-- to an assumption whose type matches the formula's
-- input in the hypothesis.
have h4: A y -> B y, from h1 y,
-- show B y, from
h4 h3
-- We can also do the above prove without |have| statements, of course.
-- Another example:
example : (∀ x, A x) → ((∀ x, B x) → (∀ x, A x ∧ B x)) :=
assume h1: (∀ x, A x),
assume h2: (∀ x, B x),
show (∀ x, A x ∧ B x), from
assume y: U,
show A y ∧ B y, from
and.intro (h1 y) (h2 y) |
080dcb02f6f54c936700e744e4e18e0ff26a58b9 | 2bafba05c98c1107866b39609d15e849a4ca2bb8 | /src/week_2/kb_solutions/Part_A_groups_solutions.lean | 54bece575dcbbd7ec6c5739095b768b187f17f46 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/formalising-mathematics | b54c83c94b5c315024ff09997fcd6b303892a749 | 7cf1d51c27e2038d2804561d63c74711924044a1 | refs/heads/master | 1,651,267,046,302 | 1,638,888,459,000 | 1,638,888,459,000 | 331,592,375 | 284 | 24 | Apache-2.0 | 1,669,593,705,000 | 1,611,224,849,000 | Lean | UTF-8 | Lean | false | false | 11,736 | lean | import tactic
/-!
# Groups
Definition and basic properties of a group.
-/
-- Technical note: We work in a namespace `xena` because Lean already has groups.
namespace xena
-- Now our definition of a group will really be called `xena.group`.
/-
## Definition of a group
The `group` class will extend `has_mul`, `has_one` and `has_inv`.
`has_mul G` means that `G` has a multiplication `* : G → G → G`
`has_one G` means that `G` has a `1 : G`
`has_inv G` means that `G` has an `⁻¹ : G → G`
All of `*`, `1` and `⁻¹` are just notation for functions -- no axioms yet.
A `group` has all of this notation, and the group axioms too.
Let's now define the group class.
-/
/-- A `group` structure on a type `G` is multiplication, identity and inverse,
plus the usual axioms -/
class group (G : Type) extends has_mul G, has_one G, has_inv G :=
(mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c))
(one_mul : ∀ (a : G), 1 * a = a)
(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)
/-
Formally, a term of type `group G` is now the following data:
a multiplication, 1, and inverse function,
and proofs that the group axioms are satisfied.
The way to say "let G be a group" is now `(G : Type) [group G]`
The square bracket notation is the notation used for classes.
Formally, it means "put a term of type `group G` into the type class
inference system". In practice this just means "you can use group
notation and axioms in proofs, and Lean will figure out why they're true"
We have been extremely mean with our axioms. Some authors also add
the axioms `mul_one : ∀ (a : G), a * 1 = a`
and `mul_right_inv : ∀ (a : G), a * a⁻¹ = 1`.
But these follow from the three axioms we used. Our first job is
to prove them. As you might imagine, mathematically this is pretty
much the trickiest part, because we have to be careful not to
accidentally assume these axioms when we're proving them.
Here are the four lemmas we will prove next.
`mul_left_cancel : ∀ (a b c : G), a * b = a * c → b = c`
`mul_eq_of_eq_inv_mul {a x y : G} : x = a⁻¹ * y → a * x = y`
`mul_one (a : G) : a * 1 = a`
`mul_right_inv (a : G) : a * a⁻¹ = 1`
-/
-- We're proving things about groups so let's work in the `group` namespace
-- (really this is `xena.group`)
namespace group
-- let `G` be a group.
variables {G : Type} [group G]
/-
We start by proving `mul_left_cancel : ∀ a b c, a * b = a * c → b = c`.
We assume `Habac : a * b = a * c` and deduce `b = c`. I've written
down the maths proof. Your job is to supply the rewrites that are
necessary to justify each step. Each rewrite is either one of
the axioms of a group, or an assumption. A reminder of the axioms:
`mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c)`
`one_mul : ∀ (a : G), 1 * a = a`
`mul_left_inv : ∀ (a : G), a⁻¹ * a = 1`
This proof could be done using rewrites, but I will take this opportunity
to introduce the `calc` tactic.
-/
lemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c :=
begin
calc b = 1 * b : by rw one_mul
... = (a⁻¹ * a) * b : by rw mul_left_inv
... = a⁻¹ * (a * b) : by rw mul_assoc
... = a⁻¹ * (a * c) : by rw Habac
... = (a⁻¹ * a) * c : by rw mul_assoc
... = 1 * c : by rw mul_left_inv
... = c : by rw one_mul
end
/-
Next we prove that if `x = a⁻¹ * y` then `a * x = y`. Remember we are still
missing `mul_one` and `mul_right_inv`. A proof that avoids them is
the following: we want `a * x = y`. Now `apply`ing the previous lemma, it
suffices to prove that `a⁻¹ * (a * x) = a⁻¹ * y.`
Now use associativity and left cancellation on on the left, to reduce
to `h`.
Note that `mul_left_cancel` is a function, and its first input is
called `a`, but you had better give it `a⁻¹` instead.
-/
lemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=
begin
apply mul_left_cancel a⁻¹,
rw ←mul_assoc,
rw mul_left_inv,
rwa one_mul, -- `rwa` is "rewrite, then assumption"
end
-- It's a bore to keep introducing variable names.
-- Let `a,b,c,x,y` be elements of `G`.
variables (a b c x y : G)
/-
We can use `mul_eq_of_eq_inv_mul` to prove the two "missing" axioms `mul_one`
and `mul_right_inv`, and then our lives will be much easier. Try `apply`ing it
in the theorems below.
-/
@[simp] theorem mul_one : a * 1 = a :=
begin
apply mul_eq_of_eq_inv_mul,
rw mul_left_inv,
end
@[simp] theorem mul_right_inv : a * a⁻¹ = 1 :=
begin
apply mul_eq_of_eq_inv_mul,
rw mul_one,
end
-- Now let's talk about what that `@[simp]` means.
/-
## Lean's simplifier
A human sees `a * a⁻¹` in group theory, and instantly replaces it with `1`.
We are going to train a simple AI called `simp` to do the same thing.
Lean's simplifier `simp` is a "term rewriting system". This means
that if you teach it a bunch of theorems of the form `A = B` or
`P ↔ Q` (by tagging them with the `@[simp]` attribute) and then give
it a complicated goal, like
`example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1`
then it will try to use the `rw` tactic as much as it can, using the lemmas
it has been taught, in an attempt to simplify the goal. If it manages
to solve it completely, then great! If it does not, but you feel like
it should have done, you might want to tag more lemmas with `@[simp]`.
`simp` should only be used to completely close goals. We are now
going to train the simplifier to solve the example above (indeed, we are
going to train it to reduce an arbitrary element of a free group into
a unique normal form, so it will solve any equalities which are true
for all groups, like the example above).
## Important note
Lean's simplifier does a series of rewrites, each one replacing something
with something else. But the simplifier will always rewrite from left to right!
If you tell it that `A = B` is a `simp` lemma then it will replace `A`s with
`B`s, but it will never replace `B`s with `A`s. If you tag a proof
of `A = B` with `@[simp]` and you also tag a proof of `B = A` with
`@[simp]`, then the simplifier will get stuck in an infinite loop when
it runs into an `A`! Equality should not be thought of as symmetric here.
Because the simplifier works from left to right, an important
rule of thumb is that if `A = B` is a `simp` lemma, then `B` should
probably be simpler than `A`! In particular, equality should not be
thought of as symmetric here. It is not a coincidence that in
the theorems below
`@[simp] theorem mul_one (a : G) : a * 1 = a`
`@[simp] theorem mul_right_inv (a : G) : a * a⁻¹ = 1`
the right hand side is simpler than the left hand side. It would be a
disaster to tag `a = a * 1` with the `@[simp]` tag -- can you see why?
Let's train Lean's simplifier! Let's teach it the axioms of a group next.
We have already done the axioms, so we have to retrospectively tag
them with the `@[simp]` attribute.
-/
attribute [simp] one_mul mul_left_inv mul_assoc
/-
Now let's teach the simplifier the following five lemmas:
`inv_mul_cancel_left : a⁻¹ * (a * b) = b`
`mul_inv_cancel_left : a * (a⁻¹ * b) = b`
`inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹`
`one_inv : (1 : G)⁻¹ = 1`
`inv_inv : (a⁻¹)⁻¹ = a`
Note that in each case, the right hand side is simpler
than the left hand side.
Try using the simplifier in your proofs! I will do the
first one for you.
-/
@[simp] lemma inv_mul_cancel_left : a⁻¹ * (a * b) = b :=
begin
rw ← mul_assoc, -- the simplifier will not rewrite that way...
simp -- ...but from here on it can manage.
end
@[simp] lemma mul_inv_cancel_left : a * (a⁻¹ * b) = b :=
begin
rw ←mul_assoc,
simp
end
@[simp] lemma inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=
begin
apply mul_left_cancel (a * b),
rw mul_right_inv,
simp,
end
@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=
begin
apply mul_left_cancel (1 : G),
rw mul_right_inv,
simp,
end
@[simp] lemma inv_inv : (a ⁻¹) ⁻¹ = a :=
begin
apply mul_left_cancel a⁻¹,
simp,
end
/-
The reason I choose these five lemmas in particular, is that
term rewriting systems are very well understood by computer
scientists, and in particular there is something called the
Knuth-Bendix algorithm, which, given as input the three axioms
for a group which we used, produces a "confluent and noetherian
term rewrite system" that transforms every term into a unique
normal form. The system it produces is precisely the `simp`
lemmas which we haven proven above! See
https://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group
for more information. I won't talk any more about the Knuth-Bendix
algorithm because it's really computer science, and I don't really
understand it, but apparently if you apply it to polynomial rings
then you get Buchberger's algorithm for computing Gröbner bases.
-/
-- Now let's try our example...
example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1 := by simp -- short for begin simp end
-- The simplifier solves it!
-- try your own identities. `simp` will solve them all!
/-
This is everything I wanted to show you about groups and the simplifier today.
You can now either go on to subgroups in Part B, or practice your group
theory skills by proving the lemmas below.
-/
/-
We already proved `mul_eq_of_eq_inv_mul` but there are several other
similar-looking, but slightly different, versions of this. Here
is one.
-/
lemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c⁻¹ :=
begin
rw ← h,
simp,
end
lemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b⁻¹ * c :=
begin
rw ← h,
simp,
end
lemma mul_left_eq_self {a b : G} : a * b = b ↔ a = 1 :=
begin
split,
{ intro h,
replace h := eq_mul_inv_of_mul_eq h,
simp [h] }, -- use h as well as the simp lemmas
{ intro h,
rw [h, one_mul] }
end
lemma mul_right_eq_self {a b : G} : a * b = a ↔ b = 1 :=
begin
split,
{ intro h,
replace h := eq_inv_mul_of_mul_eq h,
simp [h] },
{ rintro rfl, -- let's define `b` to be 1
simp },
end
lemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b⁻¹ :=
begin
convert eq_mul_inv_of_mul_eq h, -- `convert x` means "I claim the goal is x;
-- now show me the parts where it isn't".
simp,
end
-- Another useful lemma for the interface
lemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a⁻¹ = b :=
begin
-- we can change hypotheses with the `replace` tactic.
-- h implies a = 1 * b⁻¹
replace h := eq_mul_inv_of_mul_eq h,
simp [h],
end
-- you don't even need `begin / end` to do a `calc`.
lemma unique_left_id {e : G} (h : ∀ x : G, e * x = x) : e = 1 :=
calc e = e * 1 : by rw mul_one
... = 1 : by rw h 1
lemma unique_right_inv {a b : G} (h : a * b = 1) : b = a⁻¹ :=
begin
apply mul_left_cancel a,
simp [h],
end
lemma mul_left_cancel_iff (a x y : G) : a * x = a * y ↔ x = y :=
begin
split,
{ apply mul_left_cancel },
{ intro hxy,
rwa hxy }
end
lemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y :=
calc x = x * 1 : by rw mul_one
... = x * (a * a⁻¹) : by rw mul_right_inv
... = x * a * a⁻¹ : by rw mul_assoc
... = y * a * a⁻¹ : by rw Habac
... = y * (a * a⁻¹) : by rw mul_assoc
... = y * 1 : by rw mul_right_inv
... = y : by rw mul_one
-- `↔` lemmas are good simp lemmas too.
@[simp] theorem inv_inj_iff {a b : G}: a⁻¹ = b⁻¹ ↔ a = b :=
begin
split,
{ intro h,
rw [← inv_inv a, h, inv_inv b] },
{ rintro rfl, -- define b to be a
refl }
end
theorem inv_eq {a b : G}: a⁻¹ = b ↔ b⁻¹ = a :=
begin
split;
{ rintro rfl,
rw inv_inv }
end
end group
end xena
|
8cb569d751df1f5c22ab4897dd232b434d338163 | 9bf90df35bb15a2f76571e35c48192142a328c40 | /src/ch7_cont.lean | 6c118f28bb1e8ce7a0f12292c2490989d64330ad | [] | no_license | ehaskell1/set_theory | ed0726520e84990d5f3180bafa0a3674ed31fb5e | e6c829c4dd953d98c9cba08f9f79784cd91794fb | refs/heads/master | 1,693,282,405,362 | 1,636,928,916,000 | 1,636,928,916,000 | 428,055,746 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 47,431 | lean | import ch6_cont
universe u
namespace Set
local attribute [irreducible] mem
local attribute [instance] classical.prop_decidable
lemma finite_lin_order_is_well_order {A R : Set.{u}} (Afin : A.is_finite) (lin : A.lin_order R) : A.well_order R :=
begin
rw well_order_iff_not_exists_desc_chain lin, rintro ⟨f, finto, hd⟩,
refine nat_infinite (finite_of_dominated_by_finite Afin ⟨_, finto, _⟩),
have h : ∀ {n : Set.{u}}, n ∈ nat.{u} → ∀ {m : Set}, m ∈ nat.{u} → n ∈ m → (f.fun_value m).pair (f.fun_value n) ∈ R,
intros n nω m mω nm, rw lt_iff nω mω at nm, rcases nm with ⟨k, kω, nkm⟩, subst nkm, clear mω, revert k,
refine @induction _ _ _,
rw [add_ind nω zero_nat, add_base nω], exact hd nω,
intros k kω ind,
have kω' := nat_induct.succ_closed kω,
rw add_ind nω kω', exact lin.trans (hd (add_into_nat nω kω')) ind,
apply one_to_one_of finto.left, rw finto.right.left,
intros m mω n nω mn fmn,
obtain (mln|nlm) := nat_order_conn mω nω mn,
specialize h mω nω mln, rw fmn at h, exact lin.irrefl h,
specialize h nω mω nlm, rw fmn at h, exact lin.irrefl h,
end
lemma exists_smallest {A R : Set} (Ane : A ≠ ∅) (Afin : A.is_finite) (lin : A.lin_order R) :
∃ x : Set, x ∈ A ∧ ∀ {y : Set}, y ∈ A → y ≠ x → x.pair y ∈ R :=
begin
obtain ⟨x, xA, xle⟩ := (finite_lin_order_is_well_order Afin lin).well Ane subset_self,
refine ⟨x, xA, λ y yA yx, _⟩, apply classical.by_contradiction, intro xy, apply xle,
cases lin.conn yA xA yx with yx xy',
exact ⟨_, yA, yx⟩,
exfalso, exact xy xy',
end
noncomputable def smallest (A R : Set) : Set :=
if Ane : A ≠ ∅ then
if fin : A.is_finite then
if lin : A.lin_order R then
classical.some (exists_smallest Ane fin lin)
else ∅ else ∅ else ∅
lemma smallest_mem {A R : Set} (Ane : A ≠ ∅) (Afin : A.is_finite) (lin : A.lin_order R) :
A.smallest R ∈ A :=
begin
rw [smallest, dif_pos Ane, dif_pos Afin, dif_pos lin],
obtain ⟨xA, h⟩ := classical.some_spec (exists_smallest Ane Afin lin), exact xA,
end
lemma smallest_smallest {A R : Set} (Ane : A ≠ ∅) (Afin : A.is_finite) (lin : A.lin_order R)
{y : Set} (yA : y ∈ A) (yx : y ≠ A.smallest R) : (A.smallest R).pair y ∈ R :=
begin
rw [smallest, dif_pos Ane, dif_pos Afin, dif_pos lin] at yx ⊢,
obtain ⟨xA, h⟩ := classical.some_spec (exists_smallest Ane Afin lin), exact h yA yx,
end
lemma finite_lin_order_iso_nat {A : Set} (fin : A.is_finite)
{R : Set} (Rlin : A.lin_order R) : isomorphic A.card.eps_order_struct ⟨A, R, Rlin.rel⟩ :=
begin
revert A,
have h : ∀ {n : Set}, n ∈ ω → ∀ {A : Set}, A.card = n →
∀ {R : Set}, ∀ (Rlin : A.lin_order R), isomorphic n.eps_order_struct ⟨A, R, Rlin.rel⟩,
refine @induction _ _ _,
intros A Acard R Rlin,
have Ae := eq_empty_of_card_empty Acard, subst Ae,
refine ⟨_, empty_corr_empty, _⟩, dsimp, intros x y xe,
exfalso, exact mem_empty _ xe,
intros n nω ind A Acard R Rlin,
have Ane : A ≠ ∅, apply ne_empty_of_zero_mem_card, rw Acard, exact zero_mem_succ nω,
have Afin : A.is_finite, rw finite_iff, exact ⟨_, nat_induct.succ_closed nω, Acard⟩,
let x := A.smallest R,
let B := A \ {x},
have ABx : A = B ∪ {x} := (diff_singleton_union_eq (smallest_mem Ane Afin Rlin)).symm,
have Bcard : B.card = n,
have Bfin : B.is_finite := subset_finite_of_finite Afin subset_diff,
rw finite_iff at Bfin, rcases Bfin with ⟨m, mω, Bm⟩, rw Bm,
apply cancel_add_right mω nω one_nat,
rw [←succ_eq_add_one nω, ←Acard, ABx,
←card_add_eq_ord_add ⟨_, nat_finite mω, card_nat mω⟩ ⟨_, nat_finite one_nat, card_nat one_nat⟩,
←Bm, ←@card_singleton x, ←card_add_spec rfl rfl],
rw [←@self_inter_diff_empty {x} A, inter_comm],
let S := R \ (prod {x} A),
have Slin : B.lin_order S, split,
{ simp only [subset_def, mem_diff, mem_prod, exists_prop, mem_singleton, mem_diff],
rintros z ⟨zR, h⟩, have zA : z ∈ A.prod A := Rlin.rel zR,
rw mem_prod at zA, rcases zA with ⟨a, aA, b, bA, zab⟩, subst zab,
refine ⟨_, ⟨aA, λ ax, h ⟨_, ax, _, bA, rfl⟩⟩, _, ⟨bA, λ bx, _⟩, rfl⟩,
refine not_lt_and_gt_part (part_order_of_lin_order Rlin) ⟨zR, _⟩,
rw bx, apply smallest_smallest Ane Afin Rlin aA, intro ax, rw [bx, ax] at zR,
exact Rlin.irrefl zR, },
{ intros a b c ab bc, rw [mem_diff, pair_mem_prod, mem_singleton] at ab bc ⊢,
refine ⟨Rlin.trans ab.left bc.left, _⟩, rintro ⟨ax, cA⟩, apply ab.right,
have abA : a.pair b ∈ A.prod A := Rlin.rel ab.left,
rw pair_mem_prod at abA, exact ⟨ax, abA.right⟩, },
{ intros x xx, rw mem_diff at xx, exact Rlin.irrefl xx.left, },
{ intros a b aB bB ab, simp only [mem_diff, pair_mem_prod, mem_singleton] at aB bB ⊢,
cases Rlin.conn aB.left bB.left ab,
exact or.inl ⟨h, λ h, aB.right h.left⟩,
exact or.inr ⟨h, λ h, bB.right h.left⟩, },
specialize ind Bcard Slin, rcases ind with ⟨f, ⟨fonto, foto⟩, fiso⟩, dsimp at fiso fonto,
have de : (pair_sep_eq n.succ A (λ k, if k = ∅ then x else f.fun_value (pred.fun_value k))).dom = n.succ,
apply pair_sep_eq_dom_eq, intros k kn, dsimp,
have kω : k ∈ ω := mem_nat_of_mem_nat_of_mem (nat_induct.succ_closed nω) kn,
by_cases kz : k = ∅,
subst kz, rw if_pos rfl, exact smallest_mem Ane Afin Rlin,
rw if_neg kz, obtain ⟨k', kω', kk'⟩ := or.resolve_left (exists_pred kω) kz, subst kk',
rw pred_succ_eq_self kω',
have fkB : f.fun_value k' ∈ B, rw ←fonto.right.right, apply fun_value_def'' fonto.left,
rw [fonto.right.left, mem_iff_succ_mem_succ kω' nω], exact kn,
rw mem_diff at fkB, exact fkB.left,
refine ⟨pair_sep_eq n.succ A (λ k, if k = ∅ then x else f.fun_value (pred.fun_value k)),
⟨⟨pair_sep_eq_is_fun, de, pair_sep_eq_ran_eq _⟩, pair_sep_eq_oto _⟩, _⟩,
{ intros y yA, by_cases yx : y = x,
refine ⟨_, zero_mem_succ nω, _⟩, dsimp, rw if_pos rfl, exact yx,
have yB : y ∈ B, rw [mem_diff, mem_singleton], exact ⟨yA, yx⟩,
rw [←fonto.right.right, mem_ran_iff fonto.left, fonto.right.left] at yB,
rcases yB with ⟨k, kn, yk⟩,
have kω := mem_nat_of_mem_nat_of_mem nω kn, subst yk, refine ⟨_, (mem_iff_succ_mem_succ kω nω).mp kn, _⟩,
dsimp, rw [if_neg succ_neq_empty, pred_succ_eq_self kω], },
{ intros m mn k kn fmk,
have kω := mem_nat_of_mem_nat_of_mem (nat_induct.succ_closed nω) kn,
have mω := mem_nat_of_mem_nat_of_mem (nat_induct.succ_closed nω) mn,
dsimp at fmk,
by_cases mz : m = ∅, subst mz, rw if_pos rfl at fmk,
by_cases kz : k = ∅, subst kz,
rw if_neg kz at fmk, obtain ⟨k', kω', kk'⟩ := or.resolve_left (exists_pred kω) kz, subst kk',
rw pred_succ_eq_self kω' at fmk,
have xB : x ∈ B, rw [←fonto.right.right, mem_ran_iff fonto.left, fonto.right.left],
use k', rw mem_iff_succ_mem_succ kω' nω, exact ⟨kn, fmk⟩,
rw [mem_diff, mem_singleton] at xB, exfalso, exact xB.right rfl,
rw if_neg mz at fmk, obtain ⟨m', mω', mm'⟩ := or.resolve_left (exists_pred mω) mz, subst mm',
rw pred_succ_eq_self mω' at fmk,
by_cases kz : k = ∅,
subst kz, rw if_pos rfl at fmk,
have xB : x ∈ B, rw [←fonto.right.right, mem_ran_iff fonto.left, fonto.right.left],
use m', rw mem_iff_succ_mem_succ mω' nω, exact ⟨mn, fmk.symm⟩,
rw [mem_diff, mem_singleton] at xB, exfalso, exact xB.right rfl,
rw if_neg kz at fmk, obtain ⟨k', kω', kk'⟩ := or.resolve_left (exists_pred kω) kz, subst kk',
rw pred_succ_eq_self kω' at fmk, congr,
rw ←mem_iff_succ_mem_succ mω' nω at mn, rw ←mem_iff_succ_mem_succ kω' nω at kn,
rw ←fonto.right.left at mn kn, exact from_one_to_one fonto.left foto mn kn fmk, },
{ rw [eps_order_struct_fld, eps_order_struct_rel], dsimp, intros m k mn kn,
have kω := mem_nat_of_mem_nat_of_mem (nat_induct.succ_closed nω) kn,
have mω := mem_nat_of_mem_nat_of_mem (nat_induct.succ_closed nω) mn,
rw [pair_mem_eps_order' mn kn], rw ←de at mn kn,
rw [pair_sep_eq_fun_value mn, pair_sep_eq_fun_value kn], dsimp, rw de at mn kn,
by_cases kz : k = ∅,
subst kz, rw if_pos rfl,
by_cases mz : m = ∅,
subst mz, rw if_pos rfl, split,
intro ee, exfalso, exact mem_empty _ ee,
intro xx, exfalso, exact Rlin.irrefl xx,
rw if_neg mz, obtain ⟨m', mω', mm'⟩ := or.resolve_left (exists_pred mω) mz, subst mm',
rw pred_succ_eq_self mω', split,
intro mz', exfalso, exact mem_empty _ mz',
intro fmx,
have fmA : f.fun_value m' ∈ B, rw ←fonto.right.right,
apply fun_value_def'' fonto.left, rw [fonto.right.left, mem_iff_succ_mem_succ mω' nω],
exact mn,
rw [mem_diff, mem_singleton] at fmA, exfalso,
exact not_lt_and_gt_part (part_order_of_lin_order Rlin) ⟨fmx, smallest_smallest Ane Afin Rlin fmA.left fmA.right⟩,
rw if_neg kz, obtain ⟨k', kω', kk'⟩ := or.resolve_left (exists_pred kω) kz, subst kk',
rw pred_succ_eq_self kω',
by_cases mz : m = ∅,
subst mz, rw if_pos rfl,
have fkB : f.fun_value k' ∈ B, rw ←fonto.right.right, apply fun_value_def'' fonto.left,
rw [fonto.right.left, mem_iff_succ_mem_succ kω' nω], exact kn,
rw [mem_diff, mem_singleton] at fkB, split,
intro zk, exact smallest_smallest Ane Afin Rlin fkB.left fkB.right,
intro xfk, exact zero_mem_succ kω',
rw if_neg mz, obtain ⟨m', mω', mm'⟩ := or.resolve_left (exists_pred mω) mz, subst mm',
rw [pred_succ_eq_self mω', ←mem_iff_succ_mem_succ mω' kω'],
rw ←mem_iff_succ_mem_succ mω' nω at mn, rw ←mem_iff_succ_mem_succ kω' nω at kn,
specialize fiso mn kn, rw [pair_mem_eps_order' mn kn, mem_diff] at fiso, rw fiso,
simp only [pair_mem_prod, not_and, and_iff_left_iff_imp, mem_singleton],
intros fmk fmx fkA,
have fmB : f.fun_value m' ∈ B, rw ←fonto.right.right, apply fun_value_def'' fonto.left,
rw fonto.right.left, exact mn,
rw [mem_diff, mem_singleton] at fmB, exact fmB.right fmx, },
intros A Afin Rlin,
rw finite_iff at Afin, rcases Afin with ⟨n, nω, Acard⟩,
rw Acard, exact h nω Acard Rlin,
end
-- problem 19 chapter 7
lemma finite_lin_order_iso {A : Set} (fin : A.is_finite)
{R : Set} (Rlin : A.lin_order R) {S : Set} (Slin : A.lin_order S) :
isomorphic ⟨A, R, Rlin.rel⟩ ⟨A, S, Slin.rel⟩ :=
iso_trans (iso_symm (finite_lin_order_iso_nat fin Rlin)) (finite_lin_order_iso_nat fin Slin)
-- chapter 7 exercise 20
lemma finite_of_well_orderings {A R : Set} (Rwell : A.well_order R) (Rwell' : A.well_order R.inv) : A.is_finite :=
begin
have eg : ∀ {X : Set}, X ≠ ∅ → X ⊆ A → ∃ m : Set, m ∈ X ∧ ∀ {x : Set}, x ∈ X → R.lin_le x m,
intros X XE XA, obtain ⟨m, mX, ge⟩ := Rwell'.well XE XA,
rw [is_least] at ge, push_neg at ge, refine ⟨_, mX, λ x, assume xX, _⟩,
rw le_iff_not_lt Rwell.lin (XA xX) (XA mX),
specialize ge _ xX, rw pair_mem_inv at ge, exact ge,
let closed := λ X : Set, ∀ {y : Set}, y ∈ X → ∀ {x : Set}, x.pair y ∈ R → x ∈ X,
have un : ∀ {X : Set}, X ≠ ∅ → X ⊆ A → closed X → ∃ m : Set, m ∈ X ∧ X = (R.seg m) ∪ {m},
intros X XE XA cl, obtain ⟨m, mX, ge⟩ := eg XE XA, refine ⟨m, mX, _⟩,
apply ext, intro x, rw [mem_union, mem_singleton, mem_seg, ←lin_le], split,
exact ge, rintro (xm|xm),
exact cl mX xm,
subst xm, exact mX,
have segcl : ∀ {t : Set}, t ∈ A → closed (R.seg t), intros t tA y yt x xy,
rw mem_seg at *, exact Rwell.lin.trans xy yt,
have segsub : ∀ {t : Set}, t ∈ A → R.seg t ⊆ A, intros t tA x xt,
rw mem_seg at xt, replace xt := Rwell.lin.rel xt, rw pair_mem_prod at xt,
exact xt.left,
have Acl : closed A, intros y yA x xy, replace xy := Rwell.lin.rel xy,
rw pair_mem_prod at xy, exact xy.left,
let B := {x ∈ A | (R.seg x).is_finite},
have BA : B = A, apply transfinite_ind Rwell sep_subset,
intros x xA ind, rw mem_sep,
by_cases se : R.seg x = ∅,
rw [se, ←card_finite_iff_finite, card_nat zero_nat, finite_cardinal_iff_nat],
exact ⟨xA, zero_nat⟩,
obtain ⟨m, mx, eq⟩ := un se (segsub xA) (@segcl _ xA), rw eq,
specialize ind mx, rw mem_sep at ind,
exact ⟨xA, union_finite_of_finite ind.right singleton_finite⟩,
by_cases Ae : A = ∅,
subst Ae, rw [←card_finite_iff_finite, card_nat zero_nat, finite_cardinal_iff_nat],
exact zero_nat,
obtain ⟨m, mx, eq⟩ := un Ae subset_self @Acl, rw eq, rw [←BA, mem_sep] at mx,
exact union_finite_of_finite mx.right singleton_finite,
end
-- end of chapter 7 starting from page 199
lemma card_is_ord {κ : Set} (κcard : κ.is_cardinal) : κ.is_ordinal :=
begin
rcases κcard with ⟨K, Kcard⟩, rw ←Kcard, exact card_is_ordinal,
end
lemma card_is_ord' {A : Set} : A.card.is_ordinal :=
card_is_ord ⟨_, rfl⟩
lemma card_lt_of_mem {κ : Set} (κcard : κ.is_cardinal) {μ : Set} (μcard : μ.is_cardinal) (κμ : κ ∈ μ) : κ.card_lt μ :=
begin
have κord := card_is_ord κcard,
have μord := card_is_ord μcard,
rw ord_mem_iff_ssub κord μord at κμ,
rw card_lt, refine ⟨_, κμ.right⟩,
rw [←card_of_cardinal_eq_self κcard, ←card_of_cardinal_eq_self μcard],
exact card_le_of_subset κμ.left,
end
lemma not_card_lt_of_not_mem {κ : Set} (κcard : κ.is_cardinal) {μ : Set} (μcard : μ.is_cardinal) (κμ : κ ∉ μ) : ¬ κ.card_lt μ :=
begin
have κord := card_is_ord κcard,
have μord := card_is_ord μcard,
rw ←ord_not_le_iff_lt μord κord at κμ, push_neg at κμ,
have μκ : μ.card_le κ, cases κμ,
exact (card_lt_of_mem μcard κcard κμ).left,
subst κμ, exact card_le_refl,
intro lt,
exact lt.right (card_eq_of_le_of_le κcard μcard lt.left μκ),
end
lemma card_lt_iff_mem {κ : Set} (κcard : κ.is_cardinal) {μ : Set} (μcard : μ.is_cardinal) : κ.card_lt μ ↔ κ ∈ μ :=
⟨λ κμ, classical.by_contradiction (λ nκμ, (not_card_lt_of_not_mem κcard μcard nκμ) κμ), card_lt_of_mem κcard μcard⟩
lemma card_le_iff_le {κ : Set} (κcard : κ.is_cardinal) {μ : Set} (μcard : μ.is_cardinal) : κ.card_le μ ↔ κ ≤ μ :=
by rw [card_le_iff, le_iff, card_lt_iff_mem κcard μcard]
lemma ord_dom_of_le {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal)
(αβ : α ≤ β) : α ≼ β :=
begin
rw ord_le_iff_sub αord βord at αβ, rw dominated_iff,
exact ⟨_, αβ, equin_refl⟩,
end
lemma ord_lt_of_card_lt {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal)
(lt : α.card.card_lt β.card) : α ∈ β :=
begin
rw card_lt_iff at lt, rw ←ord_not_le_iff_lt βord αord, intro le, apply lt.right,
exact equin_of_dom_of_dom lt.left (ord_dom_of_le βord αord le),
end
-- problem 24 lemma
lemma ord_mem_card_powerset {α : Set} (αord : α.is_ordinal) : α ∈ α.powerset.card :=
begin
apply ord_lt_of_card_lt αord card_is_ord', rw [card_of_cardinal_eq_self ⟨_, rfl⟩, card_power],
exact card_lt_exp ⟨_, rfl⟩,
end
-- problem 24
lemma exists_larger_card {α : Set} (αord : α.is_ordinal) : ∃ κ : Set, κ.is_cardinal ∧ α ∈ κ :=
⟨_, ⟨_, rfl⟩, ord_mem_card_powerset αord⟩
-- problem 25
lemma trans_ind_schema {φ : Set → Prop} (ind : ∀ {α : Set}, α.is_ordinal → (∀ {x : Set}, x ∈ α → φ x) → φ α)
(α : Set) (αord : α.is_ordinal) : φ α :=
begin
let X := {x ∈ α.succ | φ x},
have Xα : X = α.succ,
apply transfinite_ind (ordinal_well_ordered (succ_ord_of_ord αord)) sep_subset,
intros t tα hi, rw mem_sep, refine ⟨tα, ind (ord_of_mem_ord (succ_ord_of_ord αord) tα) _⟩,
intros x xt,
suffices xX : x ∈ X, rw mem_sep at xX, exact xX.right,
apply hi, rw [mem_seg, eps_order, pair_mem_pair_sep' (ord_mem_trans (succ_ord_of_ord αord) xt tα) tα],
exact xt,
suffices h : α ∈ X, rw mem_sep at h, exact h.right,
rw Xα, exact self_mem_succ,
end
def init_ord (α : Set) : Prop := α.is_ordinal ∧ ¬ ∃ β : Set, β ∈ α ∧ α ≈ β
theorem init_iff_card {α : Set} : α.init_ord ↔ α.is_cardinal :=
begin
split,
intro init, use α, symmetry, apply eq_card init.left equin_refl,
intros β βord αβ, apply classical.by_contradiction, intro le,
rw ord_not_le_iff_lt init.left βord at le, exact init.right ⟨_, le, αβ⟩,
intro αcard,
have eq := card_of_cardinal_eq_self αcard, rw ←eq, refine ⟨card_is_ordinal, _⟩,
rintro ⟨β, βA, Aβ⟩,
have βord := ord_of_mem_ord card_is_ordinal βA,
rw ←ord_not_le_iff_lt card_is_ordinal βord at βA,
rw eq at Aβ, apply βA, exact card_least βord Aβ,
end
lemma omega_is_card : is_cardinal ω :=
begin
rw ←init_iff_card, split,
exact omega_is_ord,
rintro ⟨n, nω, ωn⟩, exact nat_infinite ⟨_, nω, ωn⟩,
end
lemma exists_powersets (X : Set) : ∃ B : Set, ∀ (y : Set), y ∈ B ↔ ∃ x : Set, x ∈ X ∧ y = x.powerset :=
replacement'' powerset
noncomputable def powersets (X : Set.{u}) : Set.{u} := classical.some X.exists_powersets
lemma mem_powersets {X y : Set} : y ∈ X.powersets ↔ ∃ x : Set, x ∈ X ∧ y = x.powerset :=
classical.some_spec X.exists_powersets y
lemma L7Q {δ : Set} (δord : δ.is_ordinal) :
∃ F : Set, F.is_function ∧ F.dom = δ ∧ ∀ ⦃α : Set⦄, α ∈ δ → F.fun_value α = ((F.img α).powersets).Union :=
begin
obtain ⟨F, Ffun, Fdom, Fspec⟩ := exists_of_exists_unique (@transfinite_rec' δ δ.eps_order (ordinal_well_ordered δord) (fun x, x.ran.powersets.Union)),
refine ⟨_, Ffun, Fdom, λ α αδ, _⟩, specialize Fspec αδ, rw Fspec,
dsimp, rw [restrict_ran, seg_eq_of_trans (ordinal_trans δord) αδ],
end
noncomputable def L7Q_fun (δ : Set) : Set := if δord : δ.is_ordinal then classical.some (L7Q δord) else ∅
lemma L7Q_fun_spec {δ : Set} (δord : δ.is_ordinal) :
δ.L7Q_fun.is_function ∧ δ.L7Q_fun.dom = δ ∧ ∀ ⦃α : Set⦄, α ∈ δ → δ.L7Q_fun.fun_value α = ((δ.L7Q_fun.img α).powersets).Union :=
begin
simp [L7Q_fun, dif_pos δord], exact classical.some_spec (L7Q δord),
end
lemma L7R : ∀ {δ : Set}, δ.is_ordinal → ∀ {ε : Set}, ε.is_ordinal →
∀ {α : Set}, α ∈ δ ∩ ε → δ.L7Q_fun.fun_value α = ε.L7Q_fun.fun_value α :=
begin
have h₁ : ∀ {δ : Set}, δ.is_ordinal → ∀ {α : Set}, α ∈ δ → ∀ {z : Set}, z ∈ (δ.L7Q_fun.img α).powersets ↔ ∃ β : Set, β ∈ α ∧ z = (δ.L7Q_fun.fun_value β).powerset,
intros δ δord α αδ z, rw mem_powersets,
have αord : α.is_ordinal := ord_of_mem_ord δord αδ,
rw ord_mem_iff_ssub αord δord at αδ,
obtain ⟨δfun, δdom, -⟩ := L7Q_fun_spec δord, rw ←δdom at αδ, simp only [mem_img' δfun αδ.left], split,
rintro ⟨y, ⟨β, βα, yfβ⟩, zy⟩, subst yfβ, exact ⟨_, βα, zy⟩,
rintro ⟨β, βα, zf⟩, exact ⟨_, ⟨_, βα, rfl⟩, zf⟩,
have h₂ : ∀ {δ : Set}, δ.is_ordinal → ∀ {ε : Set}, ε.is_ordinal → δ ⊆ ε → {α ∈ δ | δ.L7Q_fun.fun_value α = ε.L7Q_fun.fun_value α} = δ,
intros δ δord ε εord δε, apply transfinite_ind (ordinal_well_ordered δord) sep_subset,
obtain ⟨-, -, δspec⟩ := L7Q_fun_spec δord, obtain ⟨-, -, εspec⟩ := L7Q_fun_spec εord,
intros α αδ ind, rw [mem_sep, δspec αδ, εspec (δε αδ)], refine ⟨αδ, _⟩,
congr' 1, apply ext, simp only [h₁ δord αδ, h₁ εord (δε αδ)], intro z, apply exists_congr,
intro β, rw and.congr_right_iff, intro βα,
suffices hβ : β ∈ δ.eps_order.seg α, specialize ind hβ, rw mem_sep at ind, rw ind.right,
rw [mem_seg, eps_order, pair_mem_pair_sep' (ord_mem_trans δord βα αδ) αδ], exact βα,
intros δ δord ε εord α hα, cases ord_conn' δord εord,
rw ord_le_iff_sub δord εord at h, rw inter_eq_of_sub h at hα,
specialize h₂ δord εord h, rw [←h₂, mem_sep] at hα, exact hα.right,
rw ord_le_iff_sub εord δord at h, rw [inter_comm, inter_eq_of_sub h] at hα,
specialize h₂ εord δord h, rw [←h₂, mem_sep] at hα, exact hα.right.symm,
end
noncomputable def Veb (α : Set) : Set := α.succ.L7Q_fun.fun_value α
noncomputable def Veb_img (α : Set) : Set :=
classical.some (@replacement'' Veb α)
lemma mem_Veb_img {α V : Set} : V ∈ α.Veb_img ↔ ∃ β : Set, β ∈ α ∧ V = β.Veb :=
classical.some_spec (@replacement'' Veb α)
-- Theorem 7S
theorem Veb_eq {α : Set} (αord : α.is_ordinal) : α.Veb = α.Veb_img.powersets.Union :=
begin
obtain ⟨f, dom, spec⟩ := L7Q_fun_spec (succ_ord_of_ord αord),
rw [Veb, spec self_mem_succ], congr, apply ext, intro V,
have subdom : α ⊆ α.succ.L7Q_fun.dom, rw dom, exact self_sub_succ,
simp only [mem_img' f subdom, mem_Veb_img, Veb], apply exists_congr,
intro β, rw and.congr_right_iff, intro βα, apply eq.congr_right,
apply L7R (succ_ord_of_ord αord) (succ_ord_of_ord (ord_of_mem_ord αord βα)),
rw mem_inter, refine ⟨_, self_mem_succ⟩, rw [succ, mem_union], right, exact βα,
end
lemma mem_Veb {α : Set} (αord : α.is_ordinal) {X : Set} : X ∈ α.Veb ↔ ∃ β : Set, β ∈ α ∧ X ⊆ β.Veb :=
begin
simp only [Veb_eq αord, mem_Union, exists_prop, mem_powersets, mem_Veb_img], split,
rintro ⟨Y, ⟨V, ⟨β, βα, Vβ⟩, YV⟩, XY⟩, subst Vβ, subst YV, rw mem_powerset at XY, exact ⟨_, βα, XY⟩,
rintro ⟨β, βα, Xβ⟩, refine ⟨_, ⟨_, ⟨_, βα, rfl⟩, rfl⟩, _⟩, rw mem_powerset, exact Xβ,
end
-- Theorem 7T
theorem Veb_transitive : ∀ {α : Set}, α.is_ordinal → α.Veb.transitive_set :=
begin
refine trans_ind_schema _, intros α αord hi, rw transitive_set_iff', intros X XV,
simp only [Veb_eq αord, mem_Union, exists_prop, mem_powersets, mem_Veb_img] at XV,
rcases XV with ⟨S, ⟨V, ⟨β, βα, Vβ⟩, SV⟩, XS⟩, subst SV, subst Vβ,
have h := powerset_transitive (hi βα), rw transitive_set_iff' at h,
specialize h XS, apply subset_trans h, intros Z Zβ,
simp only [Veb_eq αord, mem_Union, exists_prop, mem_powersets, mem_Veb_img],
exact ⟨_, ⟨_, ⟨_, βα, rfl⟩, rfl⟩, Zβ⟩,
end
structure limit_ord (α : Set) : Prop :=
(ord : α.is_ordinal)
(ne : α ≠ ∅)
(ns : ¬ ∃ β : Set, α = β.succ)
lemma succ_mem_limit {γ : Set} (γord : γ.limit_ord) {β : Set} (βγ : β ∈ γ) : β.succ ∈ γ :=
begin
cases succ_least_upper_bound γord.ord βγ,
exact h,
exfalso, exact γord.ns ⟨_, h.symm⟩,
end
lemma limit_ord_of_not_bound {γ : Set} (γord : γ.is_ordinal) (γne : γ ≠ ∅)
(h : ¬ ∃ β : Set, β ∈ γ ∧ ∀ {α : Set}, α ∈ γ → α ≤ β) : γ.limit_ord :=
begin
refine ⟨γord, γne, _⟩, rintro ⟨β, βγ⟩, apply h, subst βγ, refine ⟨_, self_mem_succ, λ α αβ, _⟩,
rw ←mem_succ_iff_le, exact αβ,
end
lemma limit_ord_not_bounded {γ : Set} (γord : γ.limit_ord) :
¬ ∃ β : Set, β ∈ γ ∧ ∀ {α : Set}, α ∈ γ → α ≤ β :=
begin
rintro ⟨β, βγ, h⟩,
specialize h (succ_mem_limit γord βγ),
have βord := ord_of_mem_ord γord.ord βγ,
rw ←ord_not_lt_iff_le βord (succ_ord_of_ord βord) at h,
exact h self_mem_succ,
end
lemma limit_ord_inf {γ : Set} (γord : γ.limit_ord) : ¬ γ.is_finite :=
begin
apply inf_of_sup_inf nat_infinite, rw subset_def,
apply induction,
rw ←ord_not_le_iff_lt γord.ord (nat_is_ord zero_nat), rintro (h|h),
exact mem_empty _ h,
exact γord.ne h,
intros n nω nγ, exact succ_mem_limit γord nγ,
end
-- Theorem 7U part a
theorem Veb_sub_of_mem {β α : Set} (αord : α.is_ordinal) (βα : β ∈ α) : β.Veb ⊆ α.Veb :=
begin
intros X Xβ, rw mem_Veb αord,
have βord := ord_of_mem_ord αord βα,
have trans := Veb_transitive βord, rw transitive_set_iff' at trans,
exact ⟨_, βα, trans Xβ⟩,
end
-- Theorem 7U part b
theorem Veb_null_eq_null : Veb ∅ = ∅ :=
begin
rw eq_empty, intros z zV, rw mem_Veb zero_is_ord at zV,
rcases zV with ⟨β, βn, -⟩, exact mem_empty _ βn,
end
-- Theorem 7U part c
theorem Veb_succ_eq_powerset {α : Set} (αord : α.is_ordinal) : α.succ.Veb = α.Veb.powerset :=
begin
apply ext, simp only [mem_Veb (succ_ord_of_ord αord), mem_powerset], intro X, split,
rintro ⟨β, βα, Xβ⟩, rw [succ, mem_union, mem_singleton] at βα, cases βα,
subst βα, exact Xβ,
exact subset_trans Xβ (Veb_sub_of_mem αord βα),
intro Xα, exact ⟨_, self_mem_succ, Xα⟩,
end
lemma mem_Union_Veb_img {α X : Set} : X ∈ α.Veb_img.Union ↔ ∃ β : Set, β ∈ α ∧ X ∈ β.Veb :=
begin
simp only [mem_Union, exists_prop, mem_Veb_img], split,
rintro ⟨V, ⟨β, βα, Vβ⟩, XV⟩, subst Vβ, exact ⟨_, βα, XV⟩,
rintro ⟨β, βα, Xβ⟩, exact ⟨_, ⟨_, βα, rfl⟩, Xβ⟩,
end
-- Theorem 7U part d
theorem Veb_limit_ord_eq {γ : Set} (γord : γ.limit_ord) : γ.Veb = γ.Veb_img.Union :=
begin
apply ext, simp only [mem_Veb γord.ord, mem_Union_Veb_img], intro X, split,
rintro ⟨β, βγ, Xβ⟩, refine ⟨_, succ_mem_limit γord βγ, _⟩,
rw [Veb_succ_eq_powerset (ord_of_mem_ord γord.ord βγ), mem_powerset], exact Xβ,
rintro ⟨β, βγ, Xβ⟩,
have trans := Veb_transitive (ord_of_mem_ord γord.ord βγ),
rw transitive_set_iff' at trans, exact ⟨_, βγ, trans Xβ⟩,
end
lemma exists_least_ord_of_exists {p : Set → Prop} (h : ∃ α : Set, α.is_ordinal ∧ p α) :
∃ α : Set, α.is_ordinal ∧ p α ∧ ∀ {β : Set}, β.is_ordinal → p β → α ≤ β :=
begin
rcases h with ⟨α, αord, pα⟩,
have αord' := succ_ord_of_ord αord,
let X := {β ∈ α.succ | p β},
have XE : X ≠ ∅, apply ne_empty_of_inhabited, use α, rw mem_sep, exact ⟨self_mem_succ, pα⟩,
obtain ⟨γ, γX, h⟩ := (ordinal_well_ordered αord').well XE sep_subset,
rw mem_sep at γX, refine ⟨_, ord_of_mem_ord αord' γX.left, γX.right, λ β, assume βord pβ, _⟩,
apply classical.by_contradiction, intro γβ, apply h, use β,
rw ord_not_le_iff_lt (ord_of_mem_ord αord' γX.left) βord at γβ,
have βα := ord_mem_trans αord' γβ γX.left,
rw [mem_sep, eps_order, pair_mem_pair_sep' βα γX.left],
exact ⟨⟨βα, pβ⟩, γβ⟩,
end
def grounded (A : Set) : Prop := ∃ α : Set, α.is_ordinal ∧ A ⊆ α.Veb
noncomputable def rank (A : Set) : Set := if h : A.grounded then classical.some (exists_least_ord_of_exists h) else ∅
lemma rank_ord_of_grounded {A : Set} (Agr : A.grounded) : A.rank.is_ordinal :=
begin
simp only [rank, dif_pos Agr],
obtain ⟨h, -, -⟩ := classical.some_spec (exists_least_ord_of_exists Agr),
exact h,
end
lemma rank_sub_of_grounded {A : Set} (Agr : A.grounded) : A ⊆ A.rank.Veb :=
begin
simp only [rank, dif_pos Agr],
obtain ⟨-, h, -⟩ := classical.some_spec (exists_least_ord_of_exists Agr),
exact h,
end
lemma rank_least_of_grounded {A : Set} (Agr : A.grounded) : ∀ {β : Set}, β.is_ordinal → A ⊆ β.Veb → A.rank ≤ β :=
begin
simp only [rank, dif_pos Agr],
obtain ⟨-, -, h⟩ := classical.some_spec (exists_least_ord_of_exists Agr),
exact @h,
end
lemma ord_not_sub_Veb {α : Set} (αord : α.is_ordinal) : ∀ {β : Set}, β ∈ α → ¬ (α ⊆ β.Veb) :=
begin
revert α, refine trans_ind_schema _, intros α αord ind β βα αβ,
suffices ββ : β ∉ β.Veb,
exact ββ (αβ βα),
rw mem_Veb (ord_of_mem_ord αord βα), rintro ⟨δ, δβ, βδ⟩,
exact ind βα δβ βδ,
end
lemma ord_sub_Veb_self {α : Set} (αord : α.is_ordinal) : α ⊆ α.Veb :=
begin
revert α, refine trans_ind_schema _, intros α αord ind β βα,
specialize ind βα, rw mem_Veb αord, exact ⟨_, βα, ind⟩,
end
-- exercise 26
theorem ord_grounded {α : Set} (αord : α.is_ordinal) : α.grounded := ⟨_, αord, ord_sub_Veb_self αord⟩
theorem rank_ord_eq_self {α : Set} (αord : α.is_ordinal) : α.rank = α :=
begin
have h := rank_least_of_grounded (ord_grounded αord) αord (ord_sub_Veb_self αord),
cases h,
exfalso, exact ord_not_sub_Veb αord h (rank_sub_of_grounded (ord_grounded αord)),
exact h,
end
-- Theorem 7V part a part 1
theorem grounded_of_mem_grounded {A : Set} (Agr : A.grounded) {a : Set} (aA : a ∈ A) : a.grounded :=
begin
obtain ⟨α, αord, Aα⟩ := Agr,
have trans := Veb_transitive αord, rw transitive_set_iff' at trans,
exact ⟨_, αord, trans (Aα aA)⟩,
end
-- Theorem 7V part a part 2
theorem rank_mem_of_mem_grounded {A : Set} (Agr : A.grounded) {a : Set} (aA : a ∈ A) : a.rank ∈ A.rank :=
begin
have h : a ∈ A.rank.Veb := (rank_sub_of_grounded Agr) aA,
have Aord : A.rank.is_ordinal := rank_ord_of_grounded Agr,
rw mem_Veb Aord at h, rcases h with ⟨β, βA, aβ⟩,
apply @ord_lt_of_le_of_lt _ β _ Aord,
exact (rank_least_of_grounded (grounded_of_mem_grounded Agr aA) (ord_of_mem_ord Aord βA) aβ),
exact βA,
end
lemma T7V_ord {A : Set} (hA : ∀ {a : Set}, a ∈ A → a.grounded) : (A.repl_img (succ ∘ rank)).Union.is_ordinal :=
begin
apply Union_ords_is_ord, intros β βA,
rw mem_repl_img at βA, rcases βA with ⟨a, aA, βa⟩, subst βa,
apply succ_ord_of_ord (rank_ord_of_grounded (hA aA)),
end
lemma T7V_sub {A : Set} (hA : ∀ {a : Set}, a ∈ A → a.grounded) : A ⊆ (A.repl_img (succ ∘ rank)).Union.Veb :=
begin
intros a aA,
have aa : a ∈ a.rank.succ.Veb,
rw [Veb_succ_eq_powerset (rank_ord_of_grounded (hA aA)), mem_powerset],
exact rank_sub_of_grounded (hA aA),
have aα : a.rank.succ ≤ (A.repl_img (succ ∘ rank)).Union,
rw ord_le_iff_sub (succ_ord_of_ord (rank_ord_of_grounded (hA aA))) (T7V_ord @hA),
apply subset_Union, rw mem_repl_img, exact ⟨_, aA, rfl⟩,
cases aα,
exact Veb_sub_of_mem (T7V_ord @hA) aα aa,
rw ←aα, exact aa,
end
-- Theorem 7V part b part 1
theorem grounded_of_all_mem_grounded {A : Set} (hA : ∀ {a : Set}, a ∈ A → a.grounded) : A.grounded :=
⟨_, T7V_ord @hA, T7V_sub @hA⟩
-- Theorem 7V part b part 2
theorem rank_eq_of_all_mem_grounded {A : Set} (hA : ∀ {a : Set}, a ∈ A → a.grounded) : A.rank = (A.repl_img (succ ∘ rank)).Union :=
begin
let α := (A.repl_img (succ ∘ rank)).Union,
have Agr := grounded_of_all_mem_grounded @hA,
rw ord_eq_iff_le_and_le (rank_ord_of_grounded Agr) (T7V_ord @hA), split,
exact rank_least_of_grounded Agr (T7V_ord @hA) (T7V_sub @hA),
have h₁ : ∀ {a : Set}, a ∈ A → a.rank.succ ≤ A.rank,
intros a aA, exact succ_least_upper_bound (rank_ord_of_grounded Agr) (rank_mem_of_mem_grounded Agr aA),
have h₂ : ∀ {β : Set}, β.is_ordinal → (∀ {a : Set}, a ∈ A → a.rank.succ ≤ β) → α ≤ β,
intros β βord hβ, rw ord_le_iff_sub (T7V_ord @hA) βord,
intro δ, simp only [mem_Union, exists_prop, mem_repl_img],
rintro ⟨Z, ⟨a, aA, Za⟩, δZ⟩, subst Za,
specialize hβ aA, rw ord_le_iff_sub (succ_ord_of_ord (rank_ord_of_grounded (hA aA))) βord at hβ,
exact hβ δZ,
exact h₂ (rank_ord_of_grounded Agr) @h₁,
end
noncomputable def cl_fun (C : Set) : Set :=
trans_rec ω nat_order (λ f, C ∪ f.ran.Union.Union)
lemma cl_fun_fun {C : Set} : C.cl_fun.is_function := trans_rec_fun nat_well_order'
lemma cl_fun_dom {C : Set} : C.cl_fun.dom = ω := trans_rec_dom nat_well_order'
-- problem 7(b)
lemma cl_fun_lemma {C n : Set} (nω : n ∈ ω) {a : Set} (an : a ∈ C.cl_fun.fun_value n) : a ⊆ C.cl_fun.fun_value n.succ :=
begin
have nω' := nat_induct.succ_closed nω,
rw [cl_fun, trans_rec_spec nat_well_order' nω', nat_order_seg nω', restrict_ran],
have h : n.succ ⊆ (trans_rec ω nat_order (λ f, C ∪ f.ran.Union.Union)).dom,
rw trans_rec_dom nat_well_order', exact subset_nat_of_mem_nat nω',
apply subset_union_of_subset_right, apply subset_Union,
simp only [mem_Union, exists_prop, mem_img' (trans_rec_fun nat_well_order') h],
rw cl_fun at an, exact ⟨_, ⟨_, self_mem_succ, rfl⟩, an⟩,
end
-- problem 7(c)
noncomputable def trans_cl (C : Set) : Set := C.cl_fun.ran.Union
lemma trans_cl_sub {C : Set} : C ⊆ C.trans_cl :=
begin
apply subset_Union, simp only [cl_fun, mem_ran_iff (trans_rec_fun nat_well_order'), trans_rec_dom nat_well_order'], use ∅,
simp only [trans_rec_spec nat_well_order' zero_nat, nat_order_seg zero_nat, restrict_empty, ran_empty_eq_empty, union_empty_eq_empty, union_empty],
exact ⟨zero_nat, rfl⟩,
end
lemma trans_cl_trans {C : Set} : C.trans_cl.transitive_set :=
begin
rw transitive_set_iff', intros a aC,
simp only [trans_cl, mem_Union, exists_prop, mem_ran_iff cl_fun_fun, cl_fun_dom] at aC,
rcases aC with ⟨y, ⟨n, nω, yn⟩, ay⟩, subst yn,
replace ay := cl_fun_lemma nω ay,
apply subset_trans ay, simp only [subset_def, trans_cl, mem_Union, exists_prop, mem_ran_iff cl_fun_fun, cl_fun_dom],
intros y yn, exact ⟨_, ⟨_, nat_induct.succ_closed nω, rfl⟩, yn⟩,
end
def reg_axiom : Prop := ∀ {A : Set}, A ≠ ∅ → ∃ m : Set, m ∈ A ∧ m ∩ A = ∅
-- Theorem 7W
theorem all_grounded_equiv_reg : (∀ {A : Set.{u}}, A.grounded) ↔ reg_axiom.{u} :=
begin
split,
intros gr A Ane,
let B := A.repl_img rank,
have Bord : ∀ x : Set, x ∈ B → x.is_ordinal, simp only [mem_repl_img],
rintros μ ⟨x, xA, μx⟩, subst μx, exact rank_ord_of_grounded gr,
have Bne : B ≠ ∅, apply ne_empty_of_inhabited,
replace Ane := inhabited_of_ne_empty Ane, rcases Ane with ⟨x, xA⟩,
use x.rank, rw mem_repl_img, exact ⟨_, xA, rfl⟩,
obtain ⟨μ, μB, le⟩ := exists_least_ord_of_nonempty Bord Bne,
rw mem_repl_img at μB, rcases μB with ⟨m, mA, μm⟩, subst μm,
refine ⟨_, mA, _⟩, rw eq_empty, intros x xmA, rw mem_inter at xmA,
apply le, use x.rank, simp only [mem_repl_img, eps_order, pair_mem_pair_sep],
exact ⟨⟨_, xmA.right, rfl⟩, ⟨_, xmA.right, rfl⟩, ⟨_, mA, rfl⟩, rank_mem_of_mem_grounded gr xmA.left⟩,
intros reg, apply @classical.by_contradiction (∀ {A : Set}, A.grounded), intro h,
push_neg at h, rcases h with ⟨c, cng⟩,
let B := trans_cl {c},
let A : Set := {x ∈ B | ¬ x.grounded},
have Ane : A ≠ ∅, apply ne_empty_of_inhabited, use c, rw mem_sep, refine ⟨trans_cl_sub _, cng⟩,
rw mem_singleton,
obtain ⟨m, mA, miA⟩ := reg Ane,
rw mem_sep at mA, apply mA.right, apply grounded_of_all_mem_grounded,
intros x xm,
have trans : B.transitive_set := trans_cl_trans, rw transitive_set_iff at trans,
have xB : x ∈ B := trans mA.left xm,
have xA : x ∉ A, intro xA, apply mem_empty x, rw [←miA, mem_inter], exact ⟨xm, xA⟩,
rw mem_sep at xA, push_neg at xA, exact xA xB,
end
-- A proof of the regularity axiom
theorem regularity' : reg_axiom :=
begin
intros A Ane,
have h := regularity _ Ane,
simp only [exists_prop] at h, simp only [inter_comm], exact h,
end
theorem all_grounded : ∀ {x : Set}, x.grounded :=
begin
rw all_grounded_equiv_reg, exact @regularity',
end
-- Theorem 7X(a)
theorem not_mem_self {A : Set} : A ∉ A :=
begin
intro AA,
obtain ⟨m, mA, miA⟩ := regularity' (@singleton_ne_empty A),
rw mem_singleton at mA, subst mA,
apply mem_empty m, rw [←miA, mem_inter, mem_singleton], exact ⟨AA, rfl⟩,
end
-- Theorem 7X(b)
theorem no_2_cyle {a b : Set} : ¬ (a ∈ b ∧ b ∈ a) :=
begin
rintro ⟨ab, ba⟩,
have abne : ({a, b} : Set) ≠ ∅, apply ne_empty_of_inhabited, use a, rw [mem_insert], left, refl,
obtain ⟨m, mab, miab⟩ := regularity' abne,
rw [mem_insert, mem_singleton] at mab, cases mab with ma mb,
subst ma, apply mem_empty b, rw [←miab, mem_inter, mem_insert, mem_singleton],
exact ⟨ba, or.inr rfl⟩,
subst mb, apply mem_empty a, rw [←miab, mem_inter, mem_insert],
exact ⟨ab, or.inl rfl⟩,
end
-- Theorem 7X(c)
theorem no_ω_cycle : ¬ ∃ f : Set, f.is_function ∧ f.dom = ω ∧ ∀ {n : Set}, n ∈ ω → f.fun_value n.succ ∈ f.fun_value n :=
begin
rintro ⟨f, ffun, fdom, fspec⟩,
have ranne : f.ran ≠ ∅, apply ne_empty_of_inhabited, use f.fun_value ∅,
apply fun_value_def'' ffun, rw fdom, exact zero_nat,
obtain ⟨m, mf, mif⟩ := regularity' ranne,
rw mem_ran_iff ffun at mf, rcases mf with ⟨n, nω, mn⟩, subst mn,
apply mem_empty (f.fun_value n.succ), rw [←mif, mem_inter, mem_ran_iff ffun],
rw fdom at nω, refine ⟨fspec nω, _, _, rfl⟩,
rw fdom, exact nat_induct.succ_closed nω,
end
lemma rank_le_of_subset {x : Set} (xgr : x.grounded) {y : Set} (ygr : y.grounded) (xy : x ⊆ y) : x.rank ≤ y.rank :=
rank_least_of_grounded xgr (rank_ord_of_grounded ygr) (subset_trans xy (rank_sub_of_grounded ygr))
-- exercise 30(b)
theorem ch7_p30b {a : Set} : a.powerset.rank = a.rank.succ :=
begin
rw rank_eq_of_all_mem_grounded (λ x h, all_grounded),
apply ext, simp only [mem_Union, exists_prop, mem_repl_img, mem_powerset], intro z, split,
rintro ⟨w, ⟨x, xa, wx⟩, zw⟩, subst wx, rw mem_succ_iff_le,
have zord : z.is_ordinal := ord_of_mem_ord (succ_ord_of_ord (rank_ord_of_grounded all_grounded)) zw,
rw ←rank_ord_eq_self zord at *, rw mem_succ_iff_le at zw,
apply ord_le_trans (rank_ord_of_grounded all_grounded) zw,
exact rank_le_of_subset all_grounded all_grounded xa,
intro za, exact ⟨_, ⟨_, subset_self, rfl⟩, za⟩,
end
-- exercise 30(c)
theorem ch7_p30c {a : Set} : a.Union.rank ≤ a.rank :=
begin
apply rank_least_of_grounded all_grounded (rank_ord_of_grounded all_grounded),
simp only [subset_def, mem_Union, exists_prop], rintro z ⟨x, xa, zx⟩,
suffices xa₂ : x.rank.Veb ⊆ a.rank.Veb,
apply xa₂, apply rank_sub_of_grounded all_grounded, exact zx,
apply Veb_sub_of_mem (rank_ord_of_grounded all_grounded),
exact rank_mem_of_mem_grounded all_grounded xa,
end
-- exercise 33
theorem ch7_p33 {D : Set} (Dt : D.transitive_set) {B : Set} (BD : ∀ {a : Set}, a ∈ D → a ⊆ B → a ∈ B) : D ⊆ B :=
begin
suffices h : ∀ {α : Set}, α.is_ordinal → D ∩ α.Veb ⊆ B,
obtain ⟨α, αord, Dα⟩ := @all_grounded D,
rw ←inter_eq_of_sub Dα, exact h αord,
apply @trans_ind_schema (λ α, D ∩ α.Veb ⊆ B), intros α αord ind x xDα,
rw [mem_inter, mem_Veb αord] at xDα, rcases xDα with ⟨xD, β, βα, xβ⟩,
rw transitive_set_iff' at Dt, apply BD xD,
exact subset_trans (sub_inter_of_sub (Dt xD) xβ) (ind βα),
end
-- exercise 35
theorem succ_inj' {a b : Set} (ab : a.succ = b.succ) : a = b :=
begin
have amb : a ∈ b.succ, rw ←ab, exact self_mem_succ,
have bma : b ∈ a.succ, rw ab, exact self_mem_succ,
rw [succ, mem_union, mem_singleton] at amb bma,
cases bma,
symmetry, exact bma,
cases amb,
exact amb,
exfalso, exact no_2_cyle ⟨bma, amb⟩,
end
theorem self_ne_succ {x : Set} : x.succ ≠ x :=
begin
intro xx, apply @not_mem_self x, nth_rewrite 1 ←xx, exact self_mem_succ,
end
lemma eq_iff_le_and_le {a b : Set} : a = b ↔ a ≤ b ∧ b ≤ a :=
begin
split,
intro ab, subst ab, exact ⟨or.inr rfl, or.inr rfl⟩,
rintro ⟨ab|ab, ba|ba⟩,
exfalso, exact no_2_cyle ⟨ab, ba⟩,
exact ba.symm,
exact ab,
exact ab,
end
-- exercise 38
theorem limit_ord_eq_Union {γ : Set} (γord : γ.limit_ord) : γ = γ.Union :=
begin
rw eq_iff_subset_and_subset, split,
intros α αγ, rw mem_Union,
have αγ' : α.succ ∈ γ, apply classical.by_contradiction, intro αγ', apply γord.ns,
use α, rw eq_iff_le_and_le,
rw ord_not_lt_iff_le (succ_ord_of_ord (ord_of_mem_ord γord.ord αγ)) γord.ord at αγ',
exact ⟨αγ', succ_least_upper_bound γord.ord αγ⟩,
exact ⟨_, αγ', self_mem_succ⟩,
exact (ordinal_trans γord.ord),
end
theorem zero_ne_succ_ord {α : Set} : ∅ ≠ α.succ :=
λ h, mem_empty α (by rw h; exact self_mem_succ)
theorem zero_mem_succ_ord {α : Set} (αord : α.is_ordinal) : ∅ ∈ α.succ :=
begin
apply classical.by_contradiction, intro zα,
rw ord_not_lt_iff_le zero_is_ord (succ_ord_of_ord αord) at zα, cases zα,
exact mem_empty _ zα,
exact zero_ne_succ_ord zα.symm,
end
theorem succ_ord_not_le_self {α : Set} (αord : α.is_ordinal) : ¬ (α.succ ≤ α) :=
λ αα, ord_mem_irrefl αord (ord_lt_of_lt_of_le αord self_mem_succ αα)
theorem ord_lt_of_succ_le {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal)
(h : α.succ ≤ β) : α ∈ β :=
begin
apply classical.by_contradiction, intro αβ,
rw ord_not_lt_iff_le αord βord at αβ, exact succ_ord_not_le_self αord (ord_le_trans αord h αβ),
end
theorem ord_pos_of_inhab : ∀ {α : Set}, α.is_ordinal → α.inhab → ∅ ∈ α :=
begin
apply @trans_ind_schema (λ α, α.inhab → ∅ ∈ α),
rintros α αord ind ⟨β, βα⟩,
by_cases hβ : β.inhab,
exact ord_mem_trans αord (ind βα hβ) βα,
have βz : β = ∅, rw eq_empty, intros δ δβ, exact hβ ⟨_, δβ⟩,
subst βz, exact βα,
end
theorem ord_succ_lt_iff : ∀ {α : Set}, α.is_ordinal → ∀ {β : Set}, β.is_ordinal →
(α ∈ β ↔ α.succ ∈ β.succ) :=
have h : ∀ {α β : Set}, β.is_ordinal → α ∈ β → α.succ ∈ β.succ,
from λ α β βord αβ, ord_lt_of_le_of_lt (succ_ord_of_ord βord) (succ_least_upper_bound βord αβ) self_mem_succ,
λ α αord β βord,
⟨h βord, λ αβ, classical.by_contradiction (λ βα, begin
rw ord_not_lt_iff_le αord βord at βα, cases βα,
exact ord_mem_irrefl (succ_ord_of_ord βord) (ord_mem_trans (succ_ord_of_ord βord) (h αord βα) αβ),
subst βα, exact ord_mem_irrefl (succ_ord_of_ord βord) αβ,
end)⟩
theorem ord_succ_inj {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal)
(sαβ : α.succ = β.succ) : α = β :=
begin
apply classical.by_contradiction, intro ne,
cases ord_conn αord βord ne with αβ βα,
rw ord_succ_lt_iff αord βord at αβ, rw sαβ at αβ,
exact ord_mem_irrefl (succ_ord_of_ord βord) αβ,
rw ord_succ_lt_iff βord αord at βα, rw sαβ at βα,
exact ord_mem_irrefl (succ_ord_of_ord βord) βα,
end
theorem ord_succ_le_iff {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) :
α ≤ β ↔ α.succ ≤ β.succ :=
⟨λ αβ, αβ.elim (λ h, by left; rwa ←ord_succ_lt_iff αord βord) (λ h, by right; rw h),
λ αβ, αβ.elim (λ h, by left; rwa ord_succ_lt_iff αord βord) (λ h, or.inr (ord_succ_inj αord βord h))⟩
theorem empty_le_ord {α : Set} (αord : α.is_ordinal) : ∅ ≤ α :=
(ord_le_iff_sub zero_is_ord αord).mpr empty_subset
theorem limit_ord_inhab {γ : Set} (γord : γ.limit_ord) : γ.inhab :=
inhab_of_inf (limit_ord_inf γord)
theorem limit_ord_pos {γ : Set} (γord : γ.limit_ord) : ∅ ∈ γ :=
ord_pos_of_inhab γord.ord (limit_ord_inhab γord)
theorem ord_eq_zero_of_le_zero {α : Set} (αord : α.is_ordinal) (hα : α ≤ ∅) : α = ∅ :=
or.elim hα (λ h, false.elim (mem_empty _ h)) (λ h, h)
theorem not_zero_of_pos {α : Set} (hα : ∅ ∈ α) : α ≠ ∅ :=
ne_empty_of_inhabited _ ⟨_, hα⟩
lemma ord_cases {α : Set} (αord : α.is_ordinal) : α = ∅ ∨ (∃ β : Set, α = β.succ) ∨ α.limit_ord :=
classical.by_cases (λ αz : α = ∅, or.inl αz) (λ αnz, or.inr (
classical.by_cases (λ ex : ∃ β : Set, α = β.succ, or.inl ex) (λ nex, or.inr ⟨αord, αnz, nex⟩)))
lemma card_is_card {α : Set} : α.card.is_cardinal :=
⟨_, rfl⟩
lemma card_pos_of_inhab {A : Set} (Ain : A.inhab) : ∅ ∈ A.card :=
begin
cases @empty_le_ord A.card (card_is_ord card_is_card),
exact h,
exfalso, exact @ne_empty_of_inhabited _ Ain (eq_empty_of_card_empty h.symm),
end
lemma card_ge_one_of_inhab {A : Set} (Ain : A.inhab) : one ≤ A.card :=
succ_least_upper_bound (card_is_ord card_is_card) (card_pos_of_inhab Ain)
lemma ne_of_mem {A B : Set} (AB : A ∈ B) : A ≠ B :=
begin
intro h, rw h at AB, apply not_mem_self AB,
end
lemma not_succ_le_empty {α : Set} : ¬ α.succ ≤ ∅ :=
λ h, or.elim h (λ h', mem_empty _ h') (λ h', zero_ne_succ_ord h'.symm)
lemma card_succ_eq {A : Set} : A.succ.card = A.card.card_add one :=
begin
have h : A ∩ {A} = ∅, rw eq_empty, intros z hz, rw [mem_inter, mem_singleton] at hz,
rcases hz with ⟨zA, zA'⟩, subst zA', exact not_mem_self zA,
rw [succ, union_comm, card_add_spec rfl rfl h, card_singleton],
end
lemma succ_imm (m : Set) : ¬ ∃ k : Set, m ∈ k ∧ k ∈ m.succ :=
begin
rintro ⟨k, mk, km⟩, rw [succ, mem_union, mem_singleton] at km, cases km,
subst km, exact not_mem_self mk,
exact no_2_cyle ⟨mk, km⟩,
end
lemma card_le_conn {κ : Set} (κcard : κ.is_cardinal) {μ : Set} (μcard : μ.is_cardinal) : κ.card_le μ ∨ μ.card_le κ :=
begin
rcases κcard with ⟨K, Kcard⟩, rcases μcard with ⟨M, Mcard⟩,
subst Kcard, subst Mcard, simp only [card_le_iff_equin'],
cases ax_ch_5 K M with KM MK,
left, exact KM,
right, exact MK,
end
lemma card_not_lt_iff_le {κ : Set} (κcard : κ.is_cardinal) {μ : Set} (μcard : μ.is_cardinal) :
¬ κ.card_lt μ ↔ μ.card_le κ :=
begin
split,
intro κμ, rcases card_le_conn κcard μcard with (κμ'|μκ),
rw card_le_iff at κμ', cases κμ',
exfalso, exact κμ κμ',
subst κμ', rw card_le_iff, right, refl,
exact μκ,
intros μκ κμ, rw card_le_iff at μκ, cases μκ,
exact not_card_lt_cycle κcard μcard ⟨κμ, μκ⟩,
subst μκ, exact κμ.right rfl,
end
lemma card_not_le_iff_lt {κ : Set} (κcard : κ.is_cardinal) {μ : Set} (μcard : μ.is_cardinal) :
¬ κ.card_le μ ↔ μ.card_lt κ :=
by simp only [←card_not_lt_iff_le μcard κcard, not_not]
lemma card_le_of_ord_mem {α : Set} (αord : α.is_ordinal) {β : Set} (βα : β ∈ α) : β.card.card_le α.card :=
begin
have βord := ord_of_mem_ord αord βα,
rw ord_mem_iff_ssub βord αord at βα, exact card_le_of_subset βα.left,
end
lemma card_lt_iff_ord_mem {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal)
(h : α.card.card_lt β.card) : α ∈ β :=
begin
rcases h with ⟨le, ne⟩, rw ←ord_not_le_iff_lt βord αord, rintro (h|h),
exact ne (card_eq_of_le_of_le card_is_card card_is_card le (card_le_of_ord_mem αord h)),
subst h, exact ne rfl,
end
lemma card_le_of_ord_le {α : Set} (αord : α.is_ordinal) {β : Set} (βα : β ≤ α) : β.card.card_le α.card :=
begin
cases βα,
exact card_le_of_ord_mem αord βα,
subst βα, exact card_le_refl,
end
lemma card_mul_lt_of_lt_of_lt {ν : Set} (hν : ν.is_cardinal) {κ : Set} (hκ : κ.is_cardinal) (κν : κ.card_lt ν)
{μ : Set} (hμ : μ.is_cardinal) (μν : μ.card_lt ν) : (κ.card_mul μ).card_lt (ν.card_mul ν) :=
begin
cases card_le_conn hκ hμ with κμ μκ,
apply card_lt_of_le_of_lt (mul_cardinal hκ hμ) (mul_cardinal hμ hμ) (card_mul_le_of_le_left hκ hμ κμ hμ),
exact card_mul_lt_mul hμ hν μν,
apply card_lt_of_le_of_lt (mul_cardinal hκ hμ) (mul_cardinal hκ hκ) (card_mul_le_of_le_right hμ hκ μκ hκ),
exact card_mul_lt_mul hκ hν κν,
end
end Set |
ddc1a8a81e59c6db5cd270498749b55978c6f852 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/set_theory/cardinal.lean | 8c4cce5dc5e00ad5b9f524bd56e4f6126922bdb9 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 58,993 | 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, Floris van Doorn
-/
import data.set.countable
import set_theory.schroeder_bernstein
import data.fintype.card
import data.nat.enat
/-!
# Cardinal Numbers
We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity.
## Main definitions
* `cardinal` the type of cardinal numbers (in a given universe).
* `cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale
`cardinal`.
* There is an instance that `cardinal` forms a `canonically_ordered_comm_semiring`.
* Addition `c₁ + c₂` is defined by `cardinal.add_def α β : #α + #β = #(α ⊕ β)`.
* Multiplication `c₁ * c₂` is defined by `cardinal.mul_def : #α * #β = #(α * β)`.
* The order `c₁ ≤ c₂` is defined by `cardinal.le_def α β : #α ≤ #β ↔ nonempty (α ↪ β)`.
* Exponentiation `c₁ ^ c₂` is defined by `cardinal.power_def α β : #α ^ #β = #(β → α)`.
* `cardinal.omega` or `ω` the cardinality of `ℕ`. This definition is universe polymorphic:
`cardinal.omega.{u} : cardinal.{u}`
(contrast with `ℕ : Type`, which lives in a specific universe).
In some cases the universe level has to be given explicitly.
* `cardinal.min (I : nonempty ι) (c : ι → cardinal)` is the minimal cardinal in the range of `c`.
* `cardinal.succ c` is the successor cardinal, the smallest cardinal larger than `c`.
* `cardinal.sum` is the sum of a collection of cardinals.
* `cardinal.sup` is the supremum of a collection of cardinals.
* `cardinal.powerlt c₁ c₂` or `c₁ ^< c₂` is defined as `sup_{γ < β} α^γ`.
## Main Statements
* Cantor's theorem: `cardinal.cantor c : c < 2 ^ c`.
* König's theorem: `cardinal.sum_lt_prod`
## Implementation notes
* There is a type of cardinal numbers in every universe level:
`cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`.
The operation `cardinal.lift` lifts cardinal numbers to a higher level.
* Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file
`set_theory/cardinal_ordinal.lean`.
* There is an instance `has_pow cardinal`, but this will only fire if Lean already knows that both
the base and the exponent live in the same universe. As a workaround, you can add
```
local infixr ^ := @has_pow.pow cardinal cardinal cardinal.has_pow
```
to a file. This notation will work even if Lean doesn't know yet that the base and the exponent
live in the same universe (but no exponents in other types can be used).
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, omega,
Cantor's theorem, König's theorem, Konig's theorem
-/
open function set
open_locale classical
universes u v w x
variables {α β : Type u}
/-- The equivalence relation on types given by equivalence (bijective correspondence) of types.
Quotienting by this equivalence relation gives the cardinal numbers.
-/
instance cardinal.is_equivalent : setoid (Type u) :=
{ r := λα β, nonempty (α ≃ β),
iseqv := ⟨λα,
⟨equiv.refl α⟩,
λα β ⟨e⟩, ⟨e.symm⟩,
λα β γ ⟨e₁⟩ ⟨e₂⟩, ⟨e₁.trans e₂⟩⟩ }
/-- `cardinal.{u}` is the type of cardinal numbers in `Type u`,
defined as the quotient of `Type u` by existence of an equivalence
(a bijection with explicit inverse). -/
def cardinal : Type (u + 1) := quotient cardinal.is_equivalent
namespace cardinal
/-- The cardinal number of a type -/
def mk : Type u → cardinal := quotient.mk
localized "notation `#` := cardinal.mk" in cardinal
instance can_lift_cardinal_Type : can_lift cardinal.{u} (Type u) :=
⟨mk, λ c, true, λ c _, quot.induction_on c $ λ α, ⟨α, rfl⟩⟩
@[elab_as_eliminator]
lemma induction_on {p : cardinal → Prop} (c : cardinal) (h : ∀ α, p (#α)) : p c :=
quotient.induction_on c h
@[elab_as_eliminator]
lemma induction_on₂ {p : cardinal → cardinal → Prop} (c₁ : cardinal) (c₂ : cardinal)
(h : ∀ α β, p (#α) (#β)) : p c₁ c₂ :=
quotient.induction_on₂ c₁ c₂ h
@[elab_as_eliminator]
lemma induction_on₃ {p : cardinal → cardinal → cardinal → Prop} (c₁ : cardinal) (c₂ : cardinal)
(c₃ : cardinal) (h : ∀ α β γ, p (#α) (#β) (#γ)) : p c₁ c₂ c₃ :=
quotient.induction_on₃ c₁ c₂ c₃ h
protected lemma eq : #α = #β ↔ nonempty (α ≃ β) := quotient.eq
@[simp] theorem mk_def (α : Type u) : @eq cardinal ⟦α⟧ (#α) := rfl
@[simp] theorem mk_out (c : cardinal) : #(c.out) = c := quotient.out_eq _
/-- The representative of the cardinal of a type is equivalent ot the original type. -/
noncomputable def out_mk_equiv {α : Type v} : (#α).out ≃ α :=
nonempty.some $ cardinal.eq.mp (by simp)
lemma mk_congr (e : α ≃ β) : # α = # β := quot.sound ⟨e⟩
alias mk_congr ← equiv.cardinal_eq
/-- Lift a function between `Type*`s to a function between `cardinal`s. -/
def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) :
cardinal.{u} → cardinal.{v} :=
quotient.map f (λ α β ⟨e⟩, ⟨hf α β e⟩)
@[simp] lemma map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) :
map f hf (#α) = #(f α) := rfl
/-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `cardinal`s. -/
def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) :
cardinal.{u} → cardinal.{v} → cardinal.{w} :=
quotient.map₂ f $ λ α β ⟨e₁⟩ γ δ ⟨e₂⟩, ⟨hf α β γ δ e₁ e₂⟩
/-- The universe lift operation on cardinals. You can specify the universes explicitly with
`lift.{u v} : cardinal.{v} → cardinal.{max v u}` -/
def lift (c : cardinal.{v}) : cardinal.{max v u} :=
map ulift (λ α β e, equiv.ulift.trans $ e.trans equiv.ulift.symm) c
@[simp] theorem mk_ulift (α) : #(ulift.{v u} α) = lift.{v} (#α) := rfl
theorem lift_umax : lift.{(max u v) u} = lift.{v u} :=
funext $ λ a, induction_on a $ λ α, (equiv.ulift.trans equiv.ulift.symm).cardinal_eq
theorem lift_umax' : lift.{(max v u) u} = lift.{v u} := lift_umax
theorem lift_id' (a : cardinal.{max u v}) : lift.{u} a = a :=
induction_on a $ λ α, mk_congr equiv.ulift
@[simp] theorem lift_id (a : cardinal) : lift.{u u} a = a := lift_id'.{u u} a
@[simp] theorem lift_uzero (a : cardinal.{u}) : lift.{0} a = a := lift_id'.{0 u} a
@[simp] theorem lift_lift (a : cardinal) :
lift.{w} (lift.{v} a) = lift.{(max v w)} a :=
induction_on a $ λ α,
(equiv.ulift.trans $ equiv.ulift.trans equiv.ulift.symm).cardinal_eq
/-- We define the order on cardinal numbers by `#α ≤ #β` if and only if
there exists an embedding (injective function) from α to β. -/
instance : has_le cardinal.{u} :=
⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, nonempty $ α ↪ β) $
assume α β γ δ ⟨e₁⟩ ⟨e₂⟩,
propext ⟨assume ⟨e⟩, ⟨e.congr e₁ e₂⟩, assume ⟨e⟩, ⟨e.congr e₁.symm e₂.symm⟩⟩⟩
theorem le_def (α β : Type u) : #α ≤ #β ↔ nonempty (α ↪ β) :=
iff.rfl
theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : injective f) : #α ≤ #β :=
⟨⟨f, hf⟩⟩
theorem _root_.function.embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β := ⟨f⟩
theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : surjective f) : #β ≤ #α :=
⟨embedding.of_surjective f hf⟩
theorem le_mk_iff_exists_set {c : cardinal} {α : Type u} :
c ≤ #α ↔ ∃ p : set α, #p = c :=
⟨induction_on c $ λ β ⟨⟨f, hf⟩⟩,
⟨set.range f, (equiv.of_injective f hf).cardinal_eq.symm⟩,
λ ⟨p, e⟩, e ▸ ⟨⟨subtype.val, λ a b, subtype.eq⟩⟩⟩
theorem out_embedding {c c' : cardinal} : c ≤ c' ↔ nonempty (c.out ↪ c'.out) :=
by { transitivity _, rw [←quotient.out_eq c, ←quotient.out_eq c'], refl }
instance : preorder cardinal.{u} :=
{ le := (≤),
le_refl := by rintros ⟨α⟩; exact ⟨embedding.refl _⟩,
le_trans := by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.trans e₂⟩ }
instance : partial_order cardinal.{u} :=
{ le_antisymm := by { rintros ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩, exact quotient.sound (e₁.antisymm e₂) },
.. cardinal.preorder }
theorem lift_mk_le {α : Type u} {β : Type v} :
lift.{(max v w)} (#α) ≤ lift.{(max u w)} (#β) ↔ nonempty (α ↪ β) :=
⟨λ ⟨f⟩, ⟨embedding.congr equiv.ulift equiv.ulift f⟩,
λ ⟨f⟩, ⟨embedding.congr equiv.ulift.symm equiv.ulift.symm f⟩⟩
/-- A variant of `cardinal.lift_mk_le` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_le' {α : Type u} {β : Type v} :
lift.{v} (#α) ≤ lift.{u} (#β) ↔ nonempty (α ↪ β) :=
lift_mk_le.{u v 0}
theorem lift_mk_eq {α : Type u} {β : Type v} :
lift.{(max v w)} (#α) = lift.{(max u w)} (#β) ↔ nonempty (α ≃ β) :=
quotient.eq.trans
⟨λ ⟨f⟩, ⟨equiv.ulift.symm.trans $ f.trans equiv.ulift⟩,
λ ⟨f⟩, ⟨equiv.ulift.trans $ f.trans equiv.ulift.symm⟩⟩
/-- A variant of `cardinal.lift_mk_eq` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_eq' {α : Type u} {β : Type v} :
lift.{v} (#α) = lift.{u} (#β) ↔ nonempty (α ≃ β) :=
lift_mk_eq.{u v 0}
@[simp] theorem lift_le {a b : cardinal} : lift a ≤ lift b ↔ a ≤ b :=
induction_on₂ a b $ λ α β, by { rw ← lift_umax, exact lift_mk_le }
/-- `cardinal.lift` as an `order_embedding`. -/
@[simps { fully_applied := ff }] def lift_order_embedding : cardinal.{v} ↪o cardinal.{max v u} :=
order_embedding.of_map_le_iff lift (λ _ _, lift_le)
theorem lift_injective : injective lift.{u v} := lift_order_embedding.injective
@[simp] theorem lift_inj {a b : cardinal} : lift a = lift b ↔ a = b :=
lift_injective.eq_iff
@[simp] theorem lift_lt {a b : cardinal} : lift a < lift b ↔ a < b :=
lift_order_embedding.lt_iff_lt
instance : has_zero cardinal.{u} := ⟨#pempty⟩
instance : inhabited cardinal.{u} := ⟨0⟩
lemma mk_eq_zero (α : Type u) [is_empty α] : #α = 0 :=
(equiv.equiv_pempty α).cardinal_eq
@[simp] theorem lift_zero : lift 0 = 0 := mk_congr (equiv.equiv_pempty _)
@[simp] theorem lift_eq_zero {a : cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 :=
lift_injective.eq_iff' lift_zero
lemma mk_eq_zero_iff {α : Type u} : #α = 0 ↔ is_empty α :=
⟨λ e, let ⟨h⟩ := quotient.exact e in h.is_empty, @mk_eq_zero α⟩
theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ nonempty α :=
(not_iff_not.2 mk_eq_zero_iff).trans not_is_empty_iff
@[simp] lemma mk_ne_zero (α : Type u) [nonempty α] : #α ≠ 0 := mk_ne_zero_iff.2 ‹_›
instance : has_one cardinal.{u} := ⟨⟦punit⟧⟩
instance : nontrivial cardinal.{u} := ⟨⟨1, 0, mk_ne_zero _⟩⟩
lemma mk_eq_one (α : Type u) [unique α] : #α = 1 :=
mk_congr equiv_punit_of_unique
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ subsingleton α :=
⟨λ ⟨f⟩, ⟨λ a b, f.injective (subsingleton.elim _ _)⟩,
λ ⟨h⟩, ⟨⟨λ a, punit.star, λ a b _, h _ _⟩⟩⟩
instance : has_add cardinal.{u} := ⟨map₂ sum $ λ α β γ δ, equiv.sum_congr⟩
theorem add_def (α β : Type u) : #α + #β = #(α ⊕ β) := rfl
@[simp] lemma mk_sum (α : Type u) (β : Type v) :
#(α ⊕ β) = lift.{v u} (#α) + lift.{u v} (#β) :=
mk_congr ((equiv.ulift).symm.sum_congr (equiv.ulift).symm)
@[simp] theorem mk_option {α : Type u} : #(option α) = #α + 1 :=
(equiv.option_equiv_sum_punit α).cardinal_eq
@[simp] lemma mk_psum (α : Type u) (β : Type v) : #(psum α β) = lift.{v} (#α) + lift.{u} (#β) :=
(mk_congr (equiv.psum_equiv_sum α β)).trans (mk_sum α β)
@[simp] lemma mk_fintype (α : Type u) [fintype α] : #α = fintype.card α :=
begin
refine fintype.induction_empty_option' _ _ _ α,
{ introsI α β h e hα, letI := fintype.of_equiv β e.symm,
rwa [mk_congr e, fintype.card_congr e] at hα },
{ refl },
{ introsI α h hα, simp [hα] }
end
instance : has_mul cardinal.{u} := ⟨map₂ prod $ λ α β γ δ, equiv.prod_congr⟩
theorem mul_def (α β : Type u) : #α * #β = #(α × β) := rfl
@[simp] lemma mk_prod (α : Type u) (β : Type v) :
#(α × β) = lift.{v u} (#α) * lift.{u v} (#β) :=
mk_congr (equiv.ulift.symm.prod_congr (equiv.ulift).symm)
protected theorem add_comm (a b : cardinal.{u}) : a + b = b + a :=
induction_on₂ a b $ λ α β, mk_congr (equiv.sum_comm α β)
protected theorem mul_comm (a b : cardinal.{u}) : a * b = b * a :=
induction_on₂ a b $ λ α β, mk_congr (equiv.prod_comm α β)
protected theorem zero_add (a : cardinal.{u}) : 0 + a = a :=
induction_on a $ λ α, mk_congr (equiv.empty_sum pempty α)
protected theorem zero_mul (a : cardinal.{u}) : 0 * a = 0 :=
induction_on a $ λ α, mk_congr (equiv.pempty_prod α)
protected theorem one_mul (a : cardinal.{u}) : 1 * a = a :=
induction_on a $ λ α, mk_congr (equiv.punit_prod α)
protected theorem left_distrib (a b c : cardinal.{u}) : a * (b + c) = a * b + a * c :=
induction_on₃ a b c $ λ α β γ, mk_congr (equiv.prod_sum_distrib α β γ)
protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {a b : cardinal.{u}} :
a * b = 0 → a = 0 ∨ b = 0 :=
begin
induction a using cardinal.induction_on with α,
induction b using cardinal.induction_on with β,
simp only [mul_def, mk_eq_zero_iff, is_empty_prod],
exact id
end
/-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/
protected def power (a b : cardinal.{u}) : cardinal.{u} :=
map₂ (λ α β : Type u, β → α) (λ α β γ δ e₁ e₂, e₂.arrow_congr e₁) a b
instance : has_pow cardinal cardinal := ⟨cardinal.power⟩
local infixr ^ := @has_pow.pow cardinal cardinal cardinal.has_pow
local infixr ` ^ℕ `:80 := @has_pow.pow cardinal ℕ monoid.has_pow
theorem power_def (α β) : #α ^ #β = #(β → α) := rfl
theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = lift.{u} (#β) ^ lift.{v} (#α) :=
mk_congr (equiv.ulift.symm.arrow_congr equiv.ulift.symm)
@[simp] theorem lift_power (a b) : lift (a ^ b) = lift a ^ lift b :=
induction_on₂ a b $ λ α β,
mk_congr (equiv.ulift.trans (equiv.ulift.arrow_congr equiv.ulift).symm)
@[simp] theorem power_zero {a : cardinal} : a ^ 0 = 1 :=
induction_on a $ assume α, (equiv.pempty_arrow_equiv_punit α).cardinal_eq
@[simp] theorem power_one {a : cardinal} : a ^ 1 = a :=
induction_on a $ assume α, (equiv.punit_arrow_equiv α).cardinal_eq
theorem power_add {a b c : cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
induction_on₃ a b c $ assume α β γ, (equiv.sum_arrow_equiv_prod_arrow β γ α).cardinal_eq
instance : comm_semiring cardinal.{u} :=
{ zero := 0,
one := 1,
add := (+),
mul := (*),
zero_add := cardinal.zero_add,
add_zero := assume a, by rw [cardinal.add_comm a 0, cardinal.zero_add a],
add_assoc := λa b c, induction_on₃ a b c $ assume α β γ, mk_congr (equiv.sum_assoc α β γ),
add_comm := cardinal.add_comm,
zero_mul := cardinal.zero_mul,
mul_zero := assume a, by rw [cardinal.mul_comm a 0, cardinal.zero_mul a],
one_mul := cardinal.one_mul,
mul_one := assume a, by rw [cardinal.mul_comm a 1, cardinal.one_mul a],
mul_assoc := λa b c, induction_on₃ a b c $ assume α β γ, mk_congr (equiv.prod_assoc α β γ),
mul_comm := cardinal.mul_comm,
left_distrib := cardinal.left_distrib,
right_distrib := assume a b c, by rw [cardinal.mul_comm (a + b) c, cardinal.left_distrib c a b,
cardinal.mul_comm c a, cardinal.mul_comm c b],
npow := λ n c, c ^ n,
npow_zero' := @power_zero,
npow_succ' := λ n c, by rw [nat.cast_succ, power_add, power_one, cardinal.mul_comm] }
@[simp] theorem one_power {a : cardinal} : 1 ^ a = 1 :=
induction_on a $ assume α, (equiv.arrow_punit_equiv_punit α).cardinal_eq
@[simp] theorem mk_bool : #bool = 2 := by simp
@[simp] theorem mk_Prop : #(Prop) = 2 := by simp
@[simp] theorem zero_power {a : cardinal} : a ≠ 0 → 0 ^ a = 0 :=
induction_on a $ assume α heq, mk_eq_zero_iff.2 $ is_empty_pi.2 $
let ⟨a⟩ := mk_ne_zero_iff.1 heq in ⟨a, pempty.is_empty⟩
theorem power_ne_zero {a : cardinal} (b) : a ≠ 0 → a ^ b ≠ 0 :=
induction_on₂ a b $ λ α β h,
let ⟨a⟩ := mk_ne_zero_iff.1 h in mk_ne_zero_iff.2 ⟨λ _, a⟩
theorem mul_power {a b c : cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
induction_on₃ a b c $ assume α β γ, (equiv.arrow_prod_equiv_prod_arrow α β γ).cardinal_eq
theorem power_mul {a b c : cardinal} : a ^ (b * c) = (a ^ b) ^ c :=
by rw [mul_comm b c];
from (induction_on₃ a b c $ assume α β γ, mk_congr (equiv.curry γ β α))
@[simp] lemma pow_cast_right (κ : cardinal.{u}) (n : ℕ) :
(κ ^ (↑n : cardinal.{u})) = κ ^ℕ n :=
rfl
@[simp] theorem lift_one : lift 1 = 1 :=
mk_congr (equiv.ulift.trans equiv.punit_equiv_punit)
@[simp] theorem lift_add (a b) : lift (a + b) = lift a + lift b :=
induction_on₂ a b $ λ α β,
mk_congr (equiv.ulift.trans (equiv.sum_congr equiv.ulift equiv.ulift).symm)
@[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b :=
induction_on₂ a b $ λ α β,
mk_congr (equiv.ulift.trans (equiv.prod_congr equiv.ulift equiv.ulift).symm)
@[simp] theorem lift_bit0 (a : cardinal) : lift (bit0 a) = bit0 (lift a) :=
lift_add a a
@[simp] theorem lift_bit1 (a : cardinal) : lift (bit1 a) = bit1 (lift a) :=
by simp [bit1]
theorem lift_two : lift.{u v} 2 = 2 := by simp
@[simp] theorem mk_set {α : Type u} : #(set α) = 2 ^ #α := by simp [set, mk_arrow]
theorem lift_two_power (a) : lift (2 ^ a) = 2 ^ lift a := by simp
section order_properties
open sum
protected theorem zero_le : ∀(a : cardinal), 0 ≤ a :=
by rintro ⟨α⟩; exact ⟨embedding.of_is_empty⟩
protected theorem add_le_add : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sum_map e₂⟩
protected theorem add_le_add_left (a) {b c : cardinal} : b ≤ c → a + b ≤ a + c :=
cardinal.add_le_add (le_refl _)
protected theorem le_iff_exists_add {a b : cardinal} : a ≤ b ↔ ∃ c, b = a + c :=
⟨induction_on₂ a b $ λ α β ⟨⟨f, hf⟩⟩,
have (α ⊕ ((range f)ᶜ : set β)) ≃ β, from
(equiv.sum_congr (equiv.of_injective f hf) (equiv.refl _)).trans $
(equiv.set.sum_compl (range f)),
⟨#↥(range f)ᶜ, mk_congr this.symm⟩,
λ ⟨c, e⟩, add_zero a ▸ e.symm ▸ cardinal.add_le_add_left _ (cardinal.zero_le _)⟩
instance : order_bot cardinal.{u} :=
{ bot := 0, bot_le := cardinal.zero_le }
instance : canonically_ordered_comm_semiring cardinal.{u} :=
{ add_le_add_left := λ a b h c, cardinal.add_le_add_left _ h,
le_iff_exists_add := @cardinal.le_iff_exists_add,
eq_zero_or_eq_zero_of_mul_eq_zero := @cardinal.eq_zero_or_eq_zero_of_mul_eq_zero,
..cardinal.order_bot,
..cardinal.comm_semiring, ..cardinal.partial_order }
@[simp] theorem zero_lt_one : (0 : cardinal) < 1 :=
lt_of_le_of_ne (zero_le _) zero_ne_one
lemma zero_power_le (c : cardinal.{u}) : (0 : cardinal.{u}) ^ c ≤ 1 :=
by { by_cases h : c = 0, rw [h, power_zero], rw [zero_power h], apply zero_le }
theorem power_le_power_left : ∀{a b c : cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩; exact
let ⟨a⟩ := mk_ne_zero_iff.1 hα in
⟨@embedding.arrow_congr_left _ _ _ ⟨a⟩ e⟩
/-- **Cantor's theorem** -/
theorem cantor (a : cardinal.{u}) : a < 2 ^ a :=
begin
induction a using cardinal.induction_on with α,
rw [← mk_set],
refine ⟨⟨⟨singleton, λ a b, singleton_eq_singleton_iff.1⟩⟩, _⟩,
rintro ⟨⟨f, hf⟩⟩,
exact cantor_injective f hf
end
instance : no_top_order cardinal.{u} :=
{ no_top := λ a, ⟨_, cantor a⟩, ..cardinal.partial_order }
noncomputable instance : linear_order cardinal.{u} :=
{ le_total := by rintros ⟨α⟩ ⟨β⟩; exact embedding.total,
decidable_le := classical.dec_rel _,
.. cardinal.partial_order }
noncomputable instance : canonically_linear_ordered_add_monoid cardinal.{u} :=
{ .. (infer_instance : canonically_ordered_add_monoid cardinal.{u}),
.. cardinal.linear_order }
-- short-circuit type class inference
noncomputable instance : distrib_lattice cardinal.{u} := by apply_instance
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ nontrivial α :=
by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, not_not]
theorem power_le_max_power_one {a b c : cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 :=
begin
by_cases ha : a = 0,
simp [ha, zero_power_le],
exact le_trans (power_le_power_left ha h) (le_max_left _ _)
end
theorem power_le_power_right {a b c : cardinal} : a ≤ b → a ^ c ≤ b ^ c :=
induction_on₃ a b c $ assume α β γ ⟨e⟩, ⟨embedding.arrow_congr_right e⟩
end order_properties
/-- The minimum cardinal in a family of cardinals (the existence
of which is provided by `injective_min`). -/
noncomputable def min {ι} (I : nonempty ι) (f : ι → cardinal) : cardinal :=
f $ classical.some $
@embedding.min_injective _ (λ i, (f i).out) I
theorem min_eq {ι} (I) (f : ι → cardinal) : ∃ i, min I f = f i :=
⟨_, rfl⟩
theorem min_le {ι I} (f : ι → cardinal) (i) : min I f ≤ f i :=
by rw [← mk_out (min I f), ← mk_out (f i)]; exact
let ⟨g⟩ := classical.some_spec
(@embedding.min_injective _ (λ i, (f i).out) I) in
⟨g i⟩
theorem le_min {ι I} {f : ι → cardinal} {a} : a ≤ min I f ↔ ∀ i, a ≤ f i :=
⟨λ h i, le_trans h (min_le _ _),
λ h, let ⟨i, e⟩ := min_eq I f in e.symm ▸ h i⟩
protected theorem wf : @well_founded cardinal.{u} (<) :=
⟨λ a, classical.by_contradiction $ λ h,
let ι := {c :cardinal // ¬ acc (<) c},
f : ι → cardinal := subtype.val,
⟨⟨c, hc⟩, hi⟩ := @min_eq ι ⟨⟨_, h⟩⟩ f in
hc (acc.intro _ (λ j ⟨_, h'⟩,
classical.by_contradiction $ λ hj, h' $
by have := min_le f ⟨j, hj⟩; rwa hi at this))⟩
instance has_wf : @has_well_founded cardinal.{u} := ⟨(<), cardinal.wf⟩
instance wo : @is_well_order cardinal.{u} (<) := ⟨cardinal.wf⟩
/-- The successor cardinal - the smallest cardinal greater than
`c`. This is not the same as `c + 1` except in the case of finite `c`. -/
noncomputable def succ (c : cardinal) : cardinal :=
@min {c' // c < c'} ⟨⟨_, cantor _⟩⟩ subtype.val
theorem lt_succ_self (c : cardinal) : c < succ c :=
by cases min_eq _ _ with s e; rw [succ, e]; exact s.2
theorem succ_le {a b : cardinal} : succ a ≤ b ↔ a < b :=
⟨lt_of_lt_of_le (lt_succ_self _), λ h,
by exact min_le _ (subtype.mk b h)⟩
@[simp] theorem lt_succ {a b : cardinal} : a < succ b ↔ a ≤ b :=
by rw [← not_le, succ_le, not_lt]
theorem add_one_le_succ (c : cardinal.{u}) : c + 1 ≤ succ c :=
begin
refine le_min.2 (λ b, _),
rcases ⟨b, c⟩ with ⟨⟨⟨β⟩, hlt⟩, ⟨γ⟩⟩,
cases hlt.le with f,
have : ¬ surjective f := λ hn, hlt.not_le (mk_le_of_surjective hn),
simp only [surjective, not_forall] at this,
rcases this with ⟨b, hb⟩,
calc #γ + 1 = #(option γ) : mk_option.symm
... ≤ #β : (f.option_elim b hb).cardinal_le
end
lemma succ_pos (c : cardinal) : 0 < succ c := by simp
lemma succ_ne_zero (c : cardinal) : succ c ≠ 0 := (succ_pos _).ne'
/-- The indexed sum of cardinals is the cardinality of the
indexed disjoint union, i.e. sigma type. -/
def sum {ι} (f : ι → cardinal) : cardinal := mk Σ i, (f i).out
theorem le_sum {ι} (f : ι → cardinal) (i) : f i ≤ sum f :=
by rw ← quotient.out_eq (f i); exact
⟨⟨λ a, ⟨i, a⟩, λ a b h, eq_of_heq $ by injection h⟩⟩
@[simp] theorem mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum (λ i, #(f i)) :=
mk_congr $ equiv.sigma_congr_right $ λ i, out_mk_equiv.symm
@[simp] theorem sum_const (ι : Type u) (a : cardinal.{v}) :
sum (λ i : ι, a) = lift.{v} (#ι) * lift.{u} a :=
induction_on a $ λ α, mk_congr $
calc (Σ i : ι, quotient.out (#α)) ≃ ι × quotient.out (#α) : equiv.sigma_equiv_prod _ _
... ≃ ulift ι × ulift α : equiv.ulift.symm.prod_congr (out_mk_equiv.trans equiv.ulift.symm)
theorem sum_const' (ι : Type u) (a : cardinal.{u}) : sum (λ _:ι, a) = #ι * a := by simp
theorem sum_le_sum {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g :=
⟨(embedding.refl _).sigma_map $ λ i, classical.choice $
by have := H i; rwa [← quot.out_eq (f i), ← quot.out_eq (g i)] at this⟩
/-- The indexed supremum of cardinals is the smallest cardinal above
everything in the family. -/
noncomputable def sup {ι} (f : ι → cardinal) : cardinal :=
@min {c // ∀ i, f i ≤ c} ⟨⟨sum f, le_sum f⟩⟩ (λ a, a.1)
theorem le_sup {ι} (f : ι → cardinal) (i) : f i ≤ sup f :=
by dsimp [sup]; cases min_eq _ _ with c hc; rw hc; exact c.2 i
theorem sup_le {ι} {f : ι → cardinal} {a} : sup f ≤ a ↔ ∀ i, f i ≤ a :=
⟨λ h i, le_trans (le_sup _ _) h,
λ h, by dsimp [sup]; change a with (⟨a, h⟩:subtype _).1; apply min_le⟩
theorem sup_le_sup {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sup f ≤ sup g :=
sup_le.2 $ λ i, le_trans (H i) (le_sup _ _)
theorem sup_le_sum {ι} (f : ι → cardinal) : sup f ≤ sum f :=
sup_le.2 $ le_sum _
theorem sum_le_sup {ι : Type u} (f : ι → cardinal.{u}) : sum f ≤ #ι * sup.{u u} f :=
by rw ← sum_const'; exact sum_le_sum _ _ (le_sup _)
theorem sup_eq_zero {ι} {f : ι → cardinal} [is_empty ι] : sup f = 0 :=
by { rw [← nonpos_iff_eq_zero, sup_le], exact is_empty_elim }
/-- The indexed product of cardinals is the cardinality of the Pi type
(dependent product). -/
def prod {ι : Type u} (f : ι → cardinal) : cardinal := #(Π i, (f i).out)
@[simp] theorem mk_pi {ι : Type u} (α : ι → Type v) : #(Π i, α i) = prod (λ i, #(α i)) :=
mk_congr $ equiv.Pi_congr_right $ λ i, out_mk_equiv.symm
@[simp] theorem prod_const (ι : Type u) (a : cardinal.{v}) :
prod (λ i : ι, a) = lift.{u} a ^ lift.{v} (#ι) :=
induction_on a $ λ α, mk_congr $ equiv.Pi_congr equiv.ulift.symm $
λ i, out_mk_equiv.trans equiv.ulift.symm
theorem prod_const' (ι : Type u) (a : cardinal.{u}) : prod (λ _:ι, a) = a ^ #ι :=
induction_on a $ λ α, (mk_pi _).symm
theorem prod_le_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g :=
⟨embedding.Pi_congr_right $ λ i, classical.choice $
by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩
@[simp] theorem prod_eq_zero {ι} (f : ι → cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 :=
by { lift f to ι → Type u using λ _, trivial, simp only [mk_eq_zero_iff, ← mk_pi, is_empty_pi] }
theorem prod_ne_zero {ι} (f : ι → cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 :=
by simp [prod_eq_zero]
@[simp] theorem lift_prod {ι : Type u} (c : ι → cardinal.{v}) :
lift.{w} (prod c) = prod (λ i, lift.{w} (c i)) :=
begin
lift c to ι → Type v using λ _, trivial,
simp only [← mk_pi, ← mk_ulift],
exact mk_congr (equiv.ulift.trans $ equiv.Pi_congr_right $ λ i, equiv.ulift.symm)
end
@[simp] theorem lift_min {ι I} (f : ι → cardinal) : lift (min I f) = min I (lift ∘ f) :=
le_antisymm (le_min.2 $ λ a, lift_le.2 $ min_le _ a) $
let ⟨i, e⟩ := min_eq I (lift ∘ f) in
by rw e; exact lift_le.2 (le_min.2 $ λ j, lift_le.1 $
by have := min_le (lift ∘ f) j; rwa e at this)
theorem lift_down {a : cardinal.{u}} {b : cardinal.{max u v}} :
b ≤ lift a → ∃ a', lift a' = b :=
induction_on₂ a b $ λ α β,
by rw [← lift_id (#β), ← lift_umax, ← lift_umax.{u v}, lift_mk_le]; exact
λ ⟨f⟩, ⟨#(set.range f), eq.symm $ lift_mk_eq.2
⟨embedding.equiv_of_surjective
(embedding.cod_restrict _ f set.mem_range_self)
$ λ ⟨a, ⟨b, e⟩⟩, ⟨b, subtype.eq e⟩⟩⟩
theorem le_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :
b ≤ lift a ↔ ∃ a', lift a' = b ∧ a' ≤ a :=
⟨λ h, let ⟨a', e⟩ := lift_down h in ⟨a', e, lift_le.1 $ e.symm ▸ h⟩,
λ ⟨a', e, h⟩, e ▸ lift_le.2 h⟩
theorem lt_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :
b < lift a ↔ ∃ a', lift a' = b ∧ a' < a :=
⟨λ h, let ⟨a', e⟩ := lift_down (le_of_lt h) in
⟨a', e, lift_lt.1 $ e.symm ▸ h⟩,
λ ⟨a', e, h⟩, e ▸ lift_lt.2 h⟩
@[simp] theorem lift_succ (a) : lift (succ a) = succ (lift a) :=
le_antisymm
(le_of_not_gt $ λ h, begin
rcases lt_lift_iff.1 h with ⟨b, e, h⟩,
rw [lt_succ, ← lift_le, e] at h,
exact not_lt_of_le h (lt_succ_self _)
end)
(succ_le.2 $ lift_lt.2 $ lt_succ_self _)
@[simp] theorem lift_max {a : cardinal.{u}} {b : cardinal.{v}} :
lift.{(max v w)} a = lift.{(max u w)} b ↔ lift.{v} a = lift.{u} b :=
calc lift.{(max v w)} a = lift.{(max u w)} b
↔ lift.{w} (lift.{v} a) = lift.{w} (lift.{u} b) : by simp
... ↔ lift.{v} a = lift.{u} b : lift_inj
protected lemma le_sup_iff {ι : Type v} {f : ι → cardinal.{max v w}} {c : cardinal} :
(c ≤ sup f) ↔ (∀ b, (∀ i, f i ≤ b) → c ≤ b) :=
⟨λ h b hb, le_trans h (sup_le.mpr hb), λ h, h _ $ λ i, le_sup f i⟩
/-- The lift of a supremum is the supremum of the lifts. -/
lemma lift_sup {ι : Type v} (f : ι → cardinal.{max v w}) :
lift.{u} (sup.{v w} f) = sup.{v (max u w)} (λ i : ι, lift.{u} (f i)) :=
begin
apply le_antisymm,
{ rw [cardinal.le_sup_iff], intros c hc, by_contra h,
obtain ⟨d, rfl⟩ := cardinal.lift_down (not_le.mp h).le,
simp only [lift_le, sup_le] at h hc,
exact h hc },
{ simp only [cardinal.sup_le, lift_le, le_sup, implies_true_iff] }
end
/-- To prove that the lift of a supremum is bounded by some cardinal `t`,
it suffices to show that the lift of each cardinal is bounded by `t`. -/
lemma lift_sup_le {ι : Type v} (f : ι → cardinal.{max v w})
(t : cardinal.{max u v w}) (w : ∀ i, lift.{u} (f i) ≤ t) :
lift.{u} (sup f) ≤ t :=
by { rw lift_sup, exact sup_le.mpr w, }
@[simp] lemma lift_sup_le_iff {ι : Type v} (f : ι → cardinal.{max v w}) (t : cardinal.{max u v w}) :
lift.{u} (sup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t :=
⟨λ h i, (lift_le.mpr (le_sup f i)).trans h,
λ h, lift_sup_le f t h⟩
universes v' w'
/--
To prove an inequality between the lifts to a common universe of two different supremums,
it suffices to show that the lift of each cardinal from the smaller supremum
if bounded by the lift of some cardinal from the larger supremum.
-/
lemma lift_sup_le_lift_sup
{ι : Type v} {ι' : Type v'} (f : ι → cardinal.{max v w}) (f' : ι' → cardinal.{max v' w'})
(g : ι → ι') (h : ∀ i, lift.{(max v' w')} (f i) ≤ lift.{(max v w)} (f' (g i))) :
lift.{(max v' w')} (sup f) ≤ lift.{(max v w)} (sup f') :=
begin
apply lift_sup_le.{(max v' w')} f,
intro i,
apply le_trans (h i),
simp only [lift_le],
apply le_sup,
end
/-- A variant of `lift_sup_le_lift_sup` with universes specialized via `w = v` and `w' = v'`.
This is sometimes necessary to avoid universe unification issues. -/
lemma lift_sup_le_lift_sup'
{ι : Type v} {ι' : Type v'} (f : ι → cardinal.{v}) (f' : ι' → cardinal.{v'})
(g : ι → ι') (h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) :
lift.{v'} (sup.{v v} f) ≤ lift.{v} (sup.{v' v'} f') :=
lift_sup_le_lift_sup f f' g h
/-- `ω` is the smallest infinite cardinal, also known as ℵ₀. -/
def omega : cardinal.{u} := lift (#ℕ)
localized "notation `ω` := cardinal.omega" in cardinal
lemma mk_nat : #ℕ = ω := (lift_id _).symm
theorem omega_ne_zero : ω ≠ 0 := mk_ne_zero _
theorem omega_pos : 0 < ω :=
pos_iff_ne_zero.2 omega_ne_zero
@[simp] theorem lift_omega : lift ω = ω := lift_lift _
@[simp] theorem omega_le_lift {c : cardinal.{u}} : ω ≤ lift.{v} c ↔ ω ≤ c :=
by rw [← lift_omega, lift_le]
@[simp] theorem lift_le_omega {c : cardinal.{u}} : lift.{v} c ≤ ω ↔ c ≤ ω :=
by rw [← lift_omega, lift_le]
/-! ### Properties about the cast from `ℕ` -/
@[simp] theorem mk_fin (n : ℕ) : #(fin n) = n := by simp
@[simp] theorem lift_nat_cast (n : ℕ) : lift.{u} (n : cardinal.{v}) = n :=
by induction n; simp *
@[simp] lemma lift_eq_nat_iff {a : cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n :=
lift_injective.eq_iff' (lift_nat_cast n)
@[simp] lemma nat_eq_lift_iff {n : ℕ} {a : cardinal.{u}} :
(n : cardinal) = lift.{v} a ↔ (n : cardinal) = a :=
by rw [← lift_nat_cast.{v} n, lift_inj]
theorem lift_mk_fin (n : ℕ) : lift (#(fin n)) = n := by simp
lemma mk_finset {α : Type u} {s : finset α} : #s = ↑(finset.card s) := by simp
theorem card_le_of_finset {α} (s : finset α) :
(s.card : cardinal) ≤ #α :=
begin
rw (_ : (s.card : cardinal) = #s),
{ exact ⟨function.embedding.subtype _⟩ },
rw [cardinal.mk_fintype, fintype.card_coe]
end
@[simp, norm_cast] theorem nat_cast_pow {m n : ℕ} : (↑(pow m n) : cardinal) = m ^ n :=
by induction n; simp [pow_succ', power_add, *]
@[simp, norm_cast] theorem nat_cast_le {m n : ℕ} : (m : cardinal) ≤ n ↔ m ≤ n :=
by rw [← lift_mk_fin, ← lift_mk_fin, lift_le]; exact
⟨λ ⟨⟨f, hf⟩⟩, by simpa only [fintype.card_fin] using fintype.card_le_of_injective f hf,
λ h, ⟨(fin.cast_le h).to_embedding⟩⟩
@[simp, norm_cast] theorem nat_cast_lt {m n : ℕ} : (m : cardinal) < n ↔ m < n :=
by simp [lt_iff_le_not_le, -not_le]
instance : char_zero cardinal := ⟨strict_mono.injective $ λ m n, nat_cast_lt.2⟩
theorem nat_cast_inj {m n : ℕ} : (m : cardinal) = n ↔ m = n := nat.cast_inj
lemma nat_cast_injective : injective (coe : ℕ → cardinal) :=
nat.cast_injective
@[simp, norm_cast, priority 900] theorem nat_succ (n : ℕ) : (n.succ : cardinal) = succ n :=
le_antisymm (add_one_le_succ _) (succ_le.2 $ nat_cast_lt.2 $ nat.lt_succ_self _)
@[simp] theorem succ_zero : succ 0 = 1 :=
by norm_cast
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : finset α, s.card ≤ n) :
# α ≤ n :=
begin
refine lt_succ.1 (lt_of_not_ge $ λ hn, _),
rw [← cardinal.nat_succ, ← cardinal.lift_mk_fin n.succ] at hn,
cases hn with f,
refine not_lt_of_le (H $ finset.univ.map f) _,
rw [finset.card_map, ← fintype.card, fintype.card_ulift, fintype.card_fin],
exact n.lt_succ_self
end
theorem cantor' (a) {b : cardinal} (hb : 1 < b) : a < b ^ a :=
by rw [← succ_le, (by norm_cast : succ 1 = 2)] at hb;
exact lt_of_lt_of_le (cantor _) (power_le_power_right hb)
theorem one_le_iff_pos {c : cardinal} : 1 ≤ c ↔ 0 < c :=
by rw [← succ_zero, succ_le]
theorem one_le_iff_ne_zero {c : cardinal} : 1 ≤ c ↔ c ≠ 0 :=
by rw [one_le_iff_pos, pos_iff_ne_zero]
theorem nat_lt_omega (n : ℕ) : (n : cardinal.{u}) < ω :=
succ_le.1 $ by rw [← nat_succ, ← lift_mk_fin, omega, lift_mk_le.{0 0 u}]; exact
⟨⟨coe, λ a b, fin.ext⟩⟩
@[simp] theorem one_lt_omega : 1 < ω :=
by simpa using nat_lt_omega 1
theorem lt_omega {c : cardinal.{u}} : c < ω ↔ ∃ n : ℕ, c = n :=
⟨λ h, begin
rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩,
rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩,
suffices : finite S,
{ lift S to finset ℕ using this,
simp },
contrapose! h',
haveI := infinite.to_subtype h',
exact ⟨infinite.nat_embedding S⟩
end, λ ⟨n, e⟩, e.symm ▸ nat_lt_omega _⟩
theorem omega_le {c : cardinal.{u}} : ω ≤ c ↔ ∀ n : ℕ, (n:cardinal) ≤ c :=
⟨λ h n, le_trans (le_of_lt (nat_lt_omega _)) h,
λ h, le_of_not_lt $ λ hn, begin
rcases lt_omega.1 hn with ⟨n, rfl⟩,
exact not_le_of_lt (nat.lt_succ_self _) (nat_cast_le.1 (h (n+1)))
end⟩
theorem lt_omega_iff_fintype {α : Type u} : #α < ω ↔ nonempty (fintype α) :=
lt_omega.trans ⟨λ ⟨n, e⟩, begin
rw [← lift_mk_fin n] at e,
cases quotient.exact e with f,
exact ⟨fintype.of_equiv _ f.symm⟩
end, λ ⟨_⟩, by exactI ⟨_, mk_fintype _⟩⟩
theorem lt_omega_iff_finite {α} {S : set α} : #S < ω ↔ finite S :=
lt_omega_iff_fintype.trans finite_def.symm
instance can_lift_cardinal_nat : can_lift cardinal ℕ :=
⟨ coe, λ x, x < ω, λ x hx, let ⟨n, hn⟩ := lt_omega.mp hx in ⟨n, hn.symm⟩⟩
theorem add_lt_omega {a b : cardinal} (ha : a < ω) (hb : b < ω) : a + b < ω :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_add]; apply nat_lt_omega
end
lemma add_lt_omega_iff {a b : cardinal} : a + b < ω ↔ a < ω ∧ b < ω :=
⟨λ h, ⟨lt_of_le_of_lt (self_le_add_right _ _) h, lt_of_le_of_lt (self_le_add_left _ _) h⟩,
λ⟨h1, h2⟩, add_lt_omega h1 h2⟩
lemma omega_le_add_iff {a b : cardinal} : ω ≤ a + b ↔ ω ≤ a ∨ ω ≤ b :=
by simp only [← not_lt, add_lt_omega_iff, not_and_distrib]
theorem mul_lt_omega {a b : cardinal} (ha : a < ω) (hb : b < ω) : a * b < ω :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_mul]; apply nat_lt_omega
end
lemma mul_lt_omega_iff {a b : cardinal} : a * b < ω ↔ a = 0 ∨ b = 0 ∨ a < ω ∧ b < ω :=
begin
split,
{ intro h, by_cases ha : a = 0, { left, exact ha },
right, by_cases hb : b = 0, { left, exact hb },
right, rw [← ne, ← one_le_iff_ne_zero] at ha hb, split,
{ rw [← mul_one a],
refine lt_of_le_of_lt (mul_le_mul' (le_refl a) hb) h },
{ rw [← one_mul b],
refine lt_of_le_of_lt (mul_le_mul' ha (le_refl b)) h }},
rintro (rfl|rfl|⟨ha,hb⟩); simp only [*, mul_lt_omega, omega_pos, zero_mul, mul_zero]
end
lemma mul_lt_omega_iff_of_ne_zero {a b : cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < ω ↔ a < ω ∧ b < ω :=
by simp [mul_lt_omega_iff, ha, hb]
theorem power_lt_omega {a b : cardinal} (ha : a < ω) (hb : b < ω) : a ^ b < ω :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat_cast_pow]; apply nat_lt_omega
end
lemma eq_one_iff_unique {α : Type*} :
#α = 1 ↔ subsingleton α ∧ nonempty α :=
calc #α = 1 ↔ #α ≤ 1 ∧ ¬#α < 1 : eq_iff_le_not_lt
... ↔ subsingleton α ∧ nonempty α :
begin
apply and_congr le_one_iff_subsingleton,
push_neg,
rw [one_le_iff_ne_zero, mk_ne_zero_iff]
end
theorem infinite_iff {α : Type u} : infinite α ↔ ω ≤ #α :=
by rw [←not_lt, lt_omega_iff_fintype, not_nonempty_iff, is_empty_fintype]
@[simp] lemma omega_le_mk (α : Type u) [infinite α] : ω ≤ #α := infinite_iff.1 ‹_›
lemma encodable_iff {α : Type u} : nonempty (encodable α) ↔ #α ≤ ω :=
⟨λ ⟨h⟩, ⟨(@encodable.encode' α h).trans equiv.ulift.symm.to_embedding⟩,
λ ⟨h⟩, ⟨encodable.of_inj _ (h.trans equiv.ulift.to_embedding).injective⟩⟩
@[simp] lemma mk_le_omega [encodable α] : #α ≤ ω := encodable_iff.1 ⟨‹_›⟩
lemma denumerable_iff {α : Type u} : nonempty (denumerable α) ↔ #α = ω :=
⟨λ ⟨h⟩, mk_congr ((@denumerable.eqv α h).trans equiv.ulift.symm),
λ h, by { cases quotient.exact h with f, exact ⟨denumerable.mk' $ f.trans equiv.ulift⟩ }⟩
@[simp] lemma mk_denumerable (α : Type u) [denumerable α] : #α = ω :=
denumerable_iff.1 ⟨‹_›⟩
@[simp] lemma mk_set_le_omega (s : set α) : #s ≤ ω ↔ countable s :=
begin
rw [countable_iff_exists_injective], split,
{ rintro ⟨f'⟩, cases embedding.trans f' equiv.ulift.to_embedding with f hf, exact ⟨f, hf⟩ },
{ rintro ⟨f, hf⟩, exact ⟨embedding.trans ⟨f, hf⟩ equiv.ulift.symm.to_embedding⟩ }
end
@[simp] lemma omega_add_omega : ω + ω = ω := mk_denumerable _
lemma omega_mul_omega : ω * ω = ω := mk_denumerable _
@[simp] lemma add_le_omega {c₁ c₂ : cardinal} : c₁ + c₂ ≤ ω ↔ c₁ ≤ ω ∧ c₂ ≤ ω :=
⟨λ h, ⟨le_self_add.trans h, le_add_self.trans h⟩, λ h, omega_add_omega ▸ add_le_add h.1 h.2⟩
/-- This function sends finite cardinals to the corresponding natural, and infinite cardinals
to 0. -/
noncomputable def to_nat : zero_hom cardinal ℕ :=
⟨λ c, if h : c < omega.{v} then classical.some (lt_omega.1 h) else 0,
begin
have h : 0 < ω := nat_lt_omega 0,
rw [dif_pos h, ← cardinal.nat_cast_inj, ← classical.some_spec (lt_omega.1 h), nat.cast_zero],
end⟩
lemma to_nat_apply_of_lt_omega {c : cardinal} (h : c < ω) :
c.to_nat = classical.some (lt_omega.1 h) :=
dif_pos h
@[simp]
lemma to_nat_apply_of_omega_le {c : cardinal} (h : ω ≤ c) :
c.to_nat = 0 :=
dif_neg (not_lt_of_le h)
@[simp]
lemma cast_to_nat_of_lt_omega {c : cardinal} (h : c < ω) :
↑c.to_nat = c :=
by rw [to_nat_apply_of_lt_omega h, ← classical.some_spec (lt_omega.1 h)]
@[simp]
lemma cast_to_nat_of_omega_le {c : cardinal} (h : ω ≤ c) :
↑c.to_nat = (0 : cardinal) :=
by rw [to_nat_apply_of_omega_le h, nat.cast_zero]
@[simp]
lemma to_nat_cast (n : ℕ) : cardinal.to_nat n = n :=
begin
rw [to_nat_apply_of_lt_omega (nat_lt_omega n), ← nat_cast_inj],
exact (classical.some_spec (lt_omega.1 (nat_lt_omega n))).symm,
end
/-- `to_nat` has a right-inverse: coercion. -/
lemma to_nat_right_inverse : function.right_inverse (coe : ℕ → cardinal) to_nat := to_nat_cast
lemma to_nat_surjective : surjective to_nat := to_nat_right_inverse.surjective
@[simp]
lemma mk_to_nat_of_infinite [h : infinite α] : (#α).to_nat = 0 :=
dif_neg (not_lt_of_le (infinite_iff.1 h))
lemma mk_to_nat_eq_card [fintype α] : (#α).to_nat = fintype.card α := by simp
@[simp]
lemma zero_to_nat : to_nat 0 = 0 :=
by rw [← to_nat_cast 0, nat.cast_zero]
@[simp]
lemma one_to_nat : to_nat 1 = 1 :=
by rw [← to_nat_cast 1, nat.cast_one]
@[simp] lemma to_nat_eq_one {c : cardinal} : to_nat c = 1 ↔ c = 1 :=
⟨λ h, (cast_to_nat_of_lt_omega (lt_of_not_ge (one_ne_zero ∘ h.symm.trans ∘
to_nat_apply_of_omega_le))).symm.trans ((congr_arg coe h).trans nat.cast_one),
λ h, (congr_arg to_nat h).trans one_to_nat⟩
lemma to_nat_eq_one_iff_unique {α : Type*} : (#α).to_nat = 1 ↔ subsingleton α ∧ nonempty α :=
to_nat_eq_one.trans eq_one_iff_unique
@[simp] lemma to_nat_lift (c : cardinal.{v}) : (lift.{u v} c).to_nat = c.to_nat :=
begin
apply nat_cast_injective,
cases lt_or_ge c ω with hc hc,
{ rw [cast_to_nat_of_lt_omega, ←lift_nat_cast, cast_to_nat_of_lt_omega hc],
rwa [←lift_omega, lift_lt] },
{ rw [cast_to_nat_of_omega_le, ←lift_nat_cast, cast_to_nat_of_omega_le hc, lift_zero],
rwa [←lift_omega, lift_le] },
end
lemma to_nat_congr {β : Type v} (e : α ≃ β) : (#α).to_nat = (#β).to_nat :=
by rw [←to_nat_lift, lift_mk_eq.mpr ⟨e⟩, to_nat_lift]
@[simp] lemma to_nat_mul (x y : cardinal) : (x * y).to_nat = x.to_nat * y.to_nat :=
begin
by_cases hx1 : x = 0,
{ rw [comm_semiring.mul_comm, hx1, mul_zero, zero_to_nat, nat.zero_mul] },
by_cases hy1 : y = 0,
{ rw [hy1, zero_to_nat, mul_zero, mul_zero, zero_to_nat] },
refine nat_cast_injective (eq.trans _ (nat.cast_mul _ _).symm),
cases lt_or_ge x ω with hx2 hx2,
{ cases lt_or_ge y ω with hy2 hy2,
{ rw [cast_to_nat_of_lt_omega, cast_to_nat_of_lt_omega hx2, cast_to_nat_of_lt_omega hy2],
exact mul_lt_omega hx2 hy2 },
{ rw [cast_to_nat_of_omega_le hy2, mul_zero, cast_to_nat_of_omega_le],
exact not_lt.mp (mt (mul_lt_omega_iff_of_ne_zero hx1 hy1).mp (λ h, not_lt.mpr hy2 h.2)) } },
{ rw [cast_to_nat_of_omega_le hx2, zero_mul, cast_to_nat_of_omega_le],
exact not_lt.mp (mt (mul_lt_omega_iff_of_ne_zero hx1 hy1).mp (λ h, not_lt.mpr hx2 h.1)) },
end
@[simp] lemma to_nat_add_of_lt_omega {a : cardinal.{u}} {b : cardinal.{v}}
(ha : a < ω) (hb : b < ω) : ((lift.{v u} a) + (lift.{u v} b)).to_nat = a.to_nat + b.to_nat :=
begin
apply cardinal.nat_cast_injective,
replace ha : (lift.{v u} a) < ω := by { rw [← lift_omega], exact lift_lt.2 ha },
replace hb : (lift.{u v} b) < ω := by { rw [← lift_omega], exact lift_lt.2 hb },
rw [nat.cast_add, ← to_nat_lift.{v u} a, ← to_nat_lift.{u v} b, cast_to_nat_of_lt_omega ha,
cast_to_nat_of_lt_omega hb, cast_to_nat_of_lt_omega (add_lt_omega ha hb)]
end
/-- This function sends finite cardinals to the corresponding natural, and infinite cardinals
to `⊤`. -/
noncomputable def to_enat : cardinal →+ enat :=
{ to_fun := λ c, if c < omega.{v} then c.to_nat else ⊤,
map_zero' := by simp [if_pos (lt_trans zero_lt_one one_lt_omega)],
map_add' := λ x y, begin
by_cases hx : x < ω,
{ obtain ⟨x0, rfl⟩ := lt_omega.1 hx,
by_cases hy : y < ω,
{ obtain ⟨y0, rfl⟩ := lt_omega.1 hy,
simp only [add_lt_omega hx hy, hx, hy, to_nat_cast, if_true],
rw [← nat.cast_add, to_nat_cast, nat.cast_add] },
{ rw [if_neg hy, if_neg, enat.add_top],
contrapose! hy,
apply lt_of_le_of_lt le_add_self hy } },
{ rw [if_neg hx, if_neg, enat.top_add],
contrapose! hx,
apply lt_of_le_of_lt le_self_add hx },
end }
@[simp]
lemma to_enat_apply_of_lt_omega {c : cardinal} (h : c < ω) :
c.to_enat = c.to_nat :=
if_pos h
@[simp]
lemma to_enat_apply_of_omega_le {c : cardinal} (h : ω ≤ c) :
c.to_enat = ⊤ :=
if_neg (not_lt_of_le h)
@[simp]
lemma to_enat_cast (n : ℕ) : cardinal.to_enat n = n :=
by rw [to_enat_apply_of_lt_omega (nat_lt_omega n), to_nat_cast]
@[simp]
lemma mk_to_enat_of_infinite [h : infinite α] : (#α).to_enat = ⊤ :=
to_enat_apply_of_omega_le (infinite_iff.1 h)
lemma to_enat_surjective : surjective to_enat :=
begin
intro x,
exact enat.cases_on x ⟨ω, to_enat_apply_of_omega_le (le_refl ω)⟩
(λ n, ⟨n, to_enat_cast n⟩),
end
lemma mk_to_enat_eq_coe_card [fintype α] : (#α).to_enat = fintype.card α :=
by simp
lemma mk_int : #ℤ = ω := mk_denumerable ℤ
lemma mk_pnat : #ℕ+ = ω := mk_denumerable ℕ+
lemma two_le_iff : (2 : cardinal) ≤ #α ↔ ∃x y : α, x ≠ y :=
begin
split,
{ rintro ⟨f⟩, refine ⟨f $ sum.inl ⟨⟩, f $ sum.inr ⟨⟩, _⟩, intro h, cases f.2 h },
{ rintro ⟨x, y, h⟩, by_contra h',
rw [not_le, ←nat.cast_two, nat_succ, lt_succ, nat.cast_one, le_one_iff_subsingleton] at h',
apply h, exactI subsingleton.elim _ _ }
end
lemma two_le_iff' (x : α) : (2 : cardinal) ≤ #α ↔ ∃y : α, x ≠ y :=
begin
rw [two_le_iff],
split,
{ rintro ⟨y, z, h⟩, refine classical.by_cases (λ(h' : x = y), _) (λ h', ⟨y, h'⟩),
rw [←h'] at h, exact ⟨z, h⟩ },
{ rintro ⟨y, h⟩, exact ⟨x, y, h⟩ }
end
/-- **König's theorem** -/
theorem sum_lt_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i < g i) : sum f < prod g :=
lt_of_not_ge $ λ ⟨F⟩, begin
haveI : inhabited (Π (i : ι), (g i).out),
{ refine ⟨λ i, classical.choice $ mk_ne_zero_iff.1 _⟩,
rw mk_out,
exact (H i).ne_bot },
let G := inv_fun F,
have sG : surjective G := inv_fun_surjective F.2,
choose C hc using show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b,
{ assume i,
simp only [- not_exists, not_exists.symm, not_forall.symm],
refine λ h, not_le_of_lt (H i) _,
rw [← mk_out (f i), ← mk_out (g i)],
exact ⟨embedding.of_surjective _ h⟩ },
exact (let ⟨⟨i, a⟩, h⟩ := sG C in hc i a (congr_fun h _))
end
@[simp] theorem mk_empty : #empty = 0 := mk_eq_zero _
@[simp] theorem mk_pempty : #pempty = 0 := mk_eq_zero _
@[simp] theorem mk_punit : #punit = 1 := mk_eq_one punit
theorem mk_unit : #unit = 1 := mk_punit
@[simp] theorem mk_singleton {α : Type u} (x : α) : #({x} : set α) = 1 :=
mk_eq_one _
@[simp] theorem mk_plift_true : #(plift true) = 1 := mk_eq_one _
@[simp] theorem mk_plift_false : #(plift false) = 0 := mk_eq_zero _
@[simp] theorem mk_vector (α : Type u) (n : ℕ) : #(vector α n) = (#α) ^ℕ n :=
(mk_congr (equiv.vector_equiv_fin α n)).trans $ by simp
theorem mk_list_eq_sum_pow (α : Type u) : #(list α) = sum (λ n : ℕ, (#α) ^ℕ n) :=
calc #(list α) = #(Σ n, vector α n) : mk_congr (equiv.sigma_preimage_equiv list.length).symm
... = sum (λ n : ℕ, (#α) ^ℕ n) : by simp
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(quot r) ≤ #α :=
mk_le_of_surjective quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : setoid α} : #(quotient s) ≤ #α :=
mk_quot_le
theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(subtype p) ≤ #α :=
⟨embedding.subtype p⟩
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
#(subtype p) ≤ #(subtype q) :=
⟨embedding.subtype_map (embedding.refl α) h⟩
@[simp] theorem mk_emptyc (α : Type u) : #(∅ : set α) = 0 := mk_eq_zero _
lemma mk_emptyc_iff {α : Type u} {s : set α} : #s = 0 ↔ s = ∅ :=
begin
split,
{ intro h,
rw mk_eq_zero_iff at h,
exact eq_empty_iff_forall_not_mem.2 (λ x hx, h.elim' ⟨x, hx⟩) },
{ rintro rfl, exact mk_emptyc _ }
end
@[simp] theorem mk_univ {α : Type u} : #(@univ α) = #α :=
mk_congr (equiv.set.univ α)
theorem mk_image_le {α β : Type u} {f : α → β} {s : set α} : #(f '' s) ≤ #s :=
mk_le_of_surjective surjective_onto_image
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : set α} :
lift.{u} (#(f '' s)) ≤ lift.{v} (#s) :=
lift_mk_le.{v u 0}.mpr ⟨embedding.of_surjective _ surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α :=
mk_le_of_surjective surjective_onto_range
theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} :
lift.{u} (#(range f)) ≤ lift.{v} (#α) :=
lift_mk_le.{v u 0}.mpr ⟨embedding.of_surjective _ surjective_onto_range⟩
lemma mk_range_eq (f : α → β) (h : injective f) : #(range f) = #α :=
mk_congr ((equiv.of_injective f h).symm)
lemma mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{u} (#(range f)) = lift.{v} (#α) :=
lift_mk_eq'.mpr ⟨(equiv.of_injective f hf).symm⟩
lemma mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{(max u w)} (# (range f)) = lift.{(max v w)} (# α) :=
lift_mk_eq.mpr ⟨(equiv.of_injective f hf).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : set α} (hf : injective f) :
#(f '' s) = #s :=
mk_congr ((equiv.set.image f s hf).symm)
theorem mk_Union_le_sum_mk {α ι : Type u} {f : ι → set α} : #(⋃ i, f i) ≤ sum (λ i, #(f i)) :=
calc #(⋃ i, f i) ≤ #(Σ i, f i) : mk_le_of_surjective (set.sigma_to_Union_surjective f)
... = sum (λ i, #(f i)) : mk_sigma _
theorem mk_Union_eq_sum_mk {α ι : Type u} {f : ι → set α} (h : ∀i j, i ≠ j → disjoint (f i) (f j)) :
#(⋃ i, f i) = sum (λ i, #(f i)) :=
calc #(⋃ i, f i) = #(Σ i, f i) : mk_congr (set.Union_eq_sigma_of_disjoint h)
... = sum (λi, #(f i)) : mk_sigma _
lemma mk_Union_le {α ι : Type u} (f : ι → set α) :
#(⋃ i, f i) ≤ #ι * cardinal.sup.{u u} (λ i, #(f i)) :=
le_trans mk_Union_le_sum_mk (sum_le_sup _)
lemma mk_sUnion_le {α : Type u} (A : set (set α)) :
#(⋃₀ A) ≤ #A * cardinal.sup.{u u} (λ s : A, #s) :=
by { rw [sUnion_eq_Union], apply mk_Union_le }
lemma mk_bUnion_le {ι α : Type u} (A : ι → set α) (s : set ι) :
#(⋃(x ∈ s), A x) ≤ #s * cardinal.sup.{u u} (λ x : s, #(A x.1)) :=
by { rw [bUnion_eq_Union], apply mk_Union_le }
lemma finset_card_lt_omega (s : finset α) : #(↑s : set α) < ω :=
by { rw [lt_omega_iff_fintype], exact ⟨finset.subtype.fintype s⟩ }
theorem mk_eq_nat_iff_finset {α} {s : set α} {n : ℕ} :
#s = n ↔ ∃ t : finset α, (t : set α) = s ∧ t.card = n :=
begin
split,
{ intro h,
lift s to finset α using lt_omega_iff_finite.1 (h.symm ▸ nat_lt_omega n),
simpa using h },
{ rintro ⟨t, rfl, rfl⟩,
exact mk_finset }
end
theorem mk_union_add_mk_inter {α : Type u} {S T : set α} :
#(S ∪ T : set α) + #(S ∩ T : set α) = #S + #T :=
quot.sound ⟨equiv.set.union_sum_inter S T⟩
/-- The cardinality of a union is at most the sum of the cardinalities
of the two sets. -/
lemma mk_union_le {α : Type u} (S T : set α) : #(S ∪ T : set α) ≤ #S + #T :=
@mk_union_add_mk_inter α S T ▸ self_le_add_right (#(S ∪ T : set α)) (#(S ∩ T : set α))
theorem mk_union_of_disjoint {α : Type u} {S T : set α} (H : disjoint S T) :
#(S ∪ T : set α) = #S + #T :=
quot.sound ⟨equiv.set.union H⟩
theorem mk_insert {α : Type u} {s : set α} {a : α} (h : a ∉ s) :
#(insert a s : set α) = #s + 1 :=
by { rw [← union_singleton, mk_union_of_disjoint, mk_singleton], simpa }
lemma mk_sum_compl {α} (s : set α) : #s + #(sᶜ : set α) = #α :=
mk_congr (equiv.set.sum_compl s)
lemma mk_le_mk_of_subset {α} {s t : set α} (h : s ⊆ t) : #s ≤ #t :=
⟨set.embedding_of_subset s t h⟩
lemma mk_subtype_mono {p q : α → Prop} (h : ∀x, p x → q x) : #{x // p x} ≤ #{x // q x} :=
⟨embedding_of_subset _ _ h⟩
lemma mk_set_le (s : set α) : #s ≤ #α :=
mk_subtype_le s
lemma mk_union_le_omega {α} {P Q : set α} : #((P ∪ Q : set α)) ≤ ω ↔ #P ≤ ω ∧ #Q ≤ ω :=
by simp
lemma mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : set α) (h : injective f) :
lift.{u} (#(f '' s)) = lift.{v} (#s) :=
lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image f s h).symm⟩
lemma mk_image_eq_of_inj_on_lift {α : Type u} {β : Type v} (f : α → β) (s : set α)
(h : inj_on f s) : lift.{u} (#(f '' s)) = lift.{v} (#s) :=
lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image_of_inj_on f s h).symm⟩
lemma mk_image_eq_of_inj_on {α β : Type u} (f : α → β) (s : set α) (h : inj_on f s) :
#(f '' s) = #s :=
mk_congr ((equiv.set.image_of_inj_on f s h).symm)
lemma mk_subtype_of_equiv {α β : Type u} (p : β → Prop) (e : α ≃ β) :
#{a : α // p (e a)} = #{b : β // p b} :=
mk_congr (equiv.subtype_equiv_of_subtype e)
lemma mk_sep (s : set α) (t : α → Prop) : #({ x ∈ s | t x } : set α) = #{ x : s | t x.1 } :=
mk_congr (equiv.set.sep s t)
lemma mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : set β)
(h : injective f) : lift.{v} (#(f ⁻¹' s)) ≤ lift.{u} (#s) :=
begin
rw lift_mk_le.{u v 0}, use subtype.coind (λ x, f x.1) (λ x, x.2),
apply subtype.coind_injective, exact h.comp subtype.val_injective
end
lemma mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : set β)
(h : s ⊆ range f) : lift.{u} (#s) ≤ lift.{v} (#(f ⁻¹' s)) :=
begin
rw lift_mk_le.{v u 0},
refine ⟨⟨_, _⟩⟩,
{ rintro ⟨y, hy⟩, rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩, exact ⟨x, hy⟩ },
rintro ⟨y, hy⟩ ⟨y', hy'⟩, dsimp,
rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩,
rcases classical.subtype_of_exists (h hy') with ⟨x', rfl⟩,
simp, intro hxx', rw hxx'
end
lemma mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : set β)
(h : injective f) (h2 : s ⊆ range f) : lift.{v} (#(f ⁻¹' s)) = lift.{u} (#s) :=
le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2)
lemma mk_preimage_of_injective (f : α → β) (s : set β) (h : injective f) :
#(f ⁻¹' s) ≤ #s :=
by { convert mk_preimage_of_injective_lift.{u u} f s h using 1; rw [lift_id] }
lemma mk_preimage_of_subset_range (f : α → β) (s : set β)
(h : s ⊆ range f) : #s ≤ #(f ⁻¹' s) :=
by { convert mk_preimage_of_subset_range_lift.{u u} f s h using 1; rw [lift_id] }
lemma mk_preimage_of_injective_of_subset_range (f : α → β) (s : set β)
(h : injective f) (h2 : s ⊆ range f) : #(f ⁻¹' s) = #s :=
by { convert mk_preimage_of_injective_of_subset_range_lift.{u u} f s h h2 using 1; rw [lift_id] }
lemma mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : set α}
{t : set β} (h : t ⊆ f '' s) :
lift.{u} (#t) ≤ lift.{v} (#({ x ∈ s | f x ∈ t } : set α)) :=
by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range_lift _ _ h using 1,
rw [mk_sep], refl }
lemma mk_subset_ge_of_subset_image (f : α → β) {s : set α} {t : set β} (h : t ⊆ f '' s) :
#t ≤ #({ x ∈ s | f x ∈ t } : set α) :=
by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range _ _ h using 1,
rw [mk_sep], refl }
theorem le_mk_iff_exists_subset {c : cardinal} {α : Type u} {s : set α} :
c ≤ #s ↔ ∃ p : set α, p ⊆ s ∧ #p = c :=
begin
rw [le_mk_iff_exists_set, ←subtype.exists_set_subtype],
apply exists_congr, intro t, rw [mk_image_eq], apply subtype.val_injective
end
/-- The function α^{<β}, defined to be sup_{γ < β} α^γ.
We index over {s : set β.out // #s < β } instead of {γ // γ < β}, because the latter lives in a
higher universe -/
noncomputable def powerlt (α β : cardinal.{u}) : cardinal.{u} :=
sup.{u u} (λ(s : {s : set β.out // #s < β}), α ^ mk.{u} s)
infix ` ^< `:80 := powerlt
theorem powerlt_aux {c c' : cardinal} (h : c < c') :
∃(s : {s : set c'.out // #s < c'}), #s = c :=
begin
cases out_embedding.mp (le_of_lt h) with f,
have : #↥(range ⇑f) = c, { rwa [mk_range_eq, mk, quotient.out_eq c], exact f.2 },
exact ⟨⟨range f, by convert h⟩, this⟩
end
lemma le_powerlt {c₁ c₂ c₃ : cardinal} (h : c₂ < c₃) : c₁ ^ c₂ ≤ c₁ ^< c₃ :=
by { rcases powerlt_aux h with ⟨s, rfl⟩, apply le_sup _ s }
lemma powerlt_le {c₁ c₂ c₃ : cardinal} : c₁ ^< c₂ ≤ c₃ ↔ ∀(c₄ < c₂), c₁ ^ c₄ ≤ c₃ :=
begin
rw [powerlt, sup_le],
split,
{ intros h c₄ hc₄, rcases powerlt_aux hc₄ with ⟨s, rfl⟩, exact h s },
intros h s, exact h _ s.2
end
lemma powerlt_le_powerlt_left {a b c : cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
by { rw [powerlt, sup_le], rintro ⟨s, hs⟩, apply le_powerlt, exact lt_of_lt_of_le hs h }
lemma powerlt_succ {c₁ c₂ : cardinal} (h : c₁ ≠ 0) : c₁ ^< c₂.succ = c₁ ^ c₂ :=
begin
apply le_antisymm,
{ rw powerlt_le, intros c₃ h2, apply power_le_power_left h, rwa [←lt_succ] },
{ apply le_powerlt, apply lt_succ_self }
end
lemma powerlt_max {c₁ c₂ c₃ : cardinal} : c₁ ^< max c₂ c₃ = max (c₁ ^< c₂) (c₁ ^< c₃) :=
by { cases le_total c₂ c₃; simp only [max_eq_left, max_eq_right, h, powerlt_le_powerlt_left] }
lemma zero_powerlt {a : cardinal} (h : a ≠ 0) : 0 ^< a = 1 :=
begin
apply le_antisymm,
{ rw [powerlt_le], intros c hc, apply zero_power_le },
convert le_powerlt (pos_iff_ne_zero.2 h), rw [power_zero]
end
lemma powerlt_zero {a : cardinal} : a ^< 0 = 0 :=
begin
convert sup_eq_zero,
exact subtype.is_empty_of_false (λ x, (zero_le _).not_lt),
end
end cardinal
|
8b3b6e85f5904316ad0da8ade0b04473ed2e5271 | e514e8b939af519a1d5e9b30a850769d058df4e9 | /src/tactic/rewrite_search/interactive.lean | f151aa5a322346601125a6ff73dc9593dcca3560 | [] | no_license | semorrison/lean-rewrite-search | dca317c5a52e170fb6ffc87c5ab767afb5e3e51a | e804b8f2753366b8957be839908230ee73f9e89f | refs/heads/master | 1,624,051,754,485 | 1,614,160,817,000 | 1,614,160,817,000 | 162,660,605 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 1,173 | lean | -- Copyright (c) 2018 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Keeley Hoek, Scott Morrison
import .tactic
import .discovery
namespace tactic.interactive
open lean.parser interactive interactive.types
open tactic.rewrite_search
variables {α β γ δ : Type}
meta def rewrite_search (try_harder : parse $ optional (tk "!")) (cfg : iconfig rewrite_search) : tactic string :=
tactic.rewrite_search cfg try_harder.is_some
meta def rewrite_search_with (try_harder : parse $ optional (tk "!")) (rs : parse rw_rules) (cfg : iconfig rewrite_search) : tactic string :=
tactic.rewrite_search_with rs.rules cfg try_harder.is_some
meta def rewrite_search_using (try_harder : parse $ optional (tk "!")) (as : list name) (cfg : iconfig rewrite_search) : tactic string :=
tactic.rewrite_search_using as cfg try_harder.is_some
meta def simp_search (cfg : iconfig rewrite_search) : tactic unit :=
tactic.simp_search cfg
meta def simp_search_with (rs : parse rw_rules) (cfg : iconfig rewrite_search := tactic.skip) : tactic unit :=
tactic.simp_search_with rs.rules cfg
end tactic.interactive
|
278542866393f5d29bb1337f758b227b7e07e308 | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/pi.lean | 7a1704bf298f229d73a41335f846ceda74202423 | [
"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 | 3,148 | lean | /-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot, Eric Wieser
-/
import tactic.split_ifs
import tactic.simpa
import tactic.congr
import algebra.group.to_additive
/-!
# Instances and theorems on pi types
This file provides basic definitions and notation instances for Pi types.
Instances of more sophisticated classes are defined in `pi.lean` files elsewhere.
-/
universes u v₁ v₂ v₃
variable {I : Type u} -- The indexing type
-- The families of types already equipped with instances
variables {f : I → Type v₁} {g : I → Type v₂} {h : I → Type v₃}
variables (x y : Π i, f i) (i : I)
namespace pi
/-! `1`, `0`, `+`, `*`, `-`, `⁻¹`, and `/` are defined pointwise. -/
@[to_additive] instance has_one [∀ i, has_one $ f i] :
has_one (Π i : I, f i) :=
⟨λ _, 1⟩
@[simp, to_additive] lemma one_apply [∀ i, has_one $ f i] : (1 : Π i, f i) i = 1 := rfl
@[to_additive] lemma one_def [Π i, has_one $ f i] : (1 : Π i, f i) = λ i, 1 := rfl
@[to_additive]
instance has_mul [∀ i, has_mul $ f i] :
has_mul (Π i : I, f i) :=
⟨λ f g i, f i * g i⟩
@[simp, to_additive] lemma mul_apply [∀ i, has_mul $ f i] : (x * y) i = x i * y i := rfl
@[to_additive] instance has_inv [∀ i, has_inv $ f i] :
has_inv (Π i : I, f i) :=
⟨λ f i, (f i)⁻¹⟩
@[simp, to_additive] lemma inv_apply [∀ i, has_inv $ f i] : x⁻¹ i = (x i)⁻¹ := rfl
@[to_additive] instance has_div [Π i, has_div $ f i] :
has_div (Π i : I, f i) :=
⟨λ f g i, f i / g i⟩
@[simp, to_additive] lemma div_apply [Π i, has_div $ f i] : (x / y) i = x i / y i := rfl
@[to_additive] lemma div_def [Π i, has_div $ f i] : x / y = λ i, x i / y i := rfl
section
variables [decidable_eq I]
variables [Π i, has_zero (f i)] [Π i, has_zero (g i)] [Π i, has_zero (h i)]
/-- The function supported at `i`, with value `x` there. -/
def single (i : I) (x : f i) : Π i, f i :=
function.update 0 i x
@[simp]
lemma single_eq_same (i : I) (x : f i) : single i x i = x :=
function.update_same i x _
@[simp]
lemma single_eq_of_ne {i i' : I} (h : i' ≠ i) (x : f i) : single i x i' = 0 :=
function.update_noteq h x _
lemma apply_single (f' : Π i, f i → g i) (hf' : ∀ i, f' i 0 = 0) (i : I) (x : f i) (j : I):
f' j (single i x j) = single i (f' i x) j :=
by simpa only [pi.zero_apply, hf', single] using function.apply_update f' 0 i x j
lemma apply_single₂ (f' : Π i, f i → g i → h i) (hf' : ∀ i, f' i 0 0 = 0)
(i : I) (x : f i) (y : g i) (j : I):
f' j (single i x j) (single i y j) = single i (f' i x y) j :=
begin
by_cases h : j = i,
{ subst h, simp only [single_eq_same], },
{ simp only [h, single_eq_of_ne, ne.def, not_false_iff, hf'], },
end
variables (f)
lemma single_injective (i : I) : function.injective (single i : f i → Π i, f i) :=
function.update_injective _ i
end
end pi
lemma subsingleton.pi_single_eq {α : Type*} [decidable_eq I] [subsingleton I] [has_zero α]
(i : I) (x : α) :
pi.single i x = λ _, x :=
funext $ λ j, by rw [subsingleton.elim j i, pi.single_eq_same]
|
584ef666d43a3e4d808e1819e70ef2c86d588a50 | 1446f520c1db37e157b631385707cc28a17a595e | /stage0/src/Init/Lean/Elab/SyntheticMVars.lean | 688baf490145c77b121d985157f83d688ab5757f | [
"Apache-2.0"
] | permissive | bdbabiak/lean4 | cab06b8a2606d99a168dd279efdd404edb4e825a | 3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac | refs/heads/master | 1,615,045,275,530 | 1,583,793,696,000 | 1,583,793,696,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,774 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
prelude
import Init.Lean.Elab.Term
import Init.Lean.Elab.Tactic.Basic
namespace Lean
namespace Elab
namespace Term
open Tactic (TacticM evalTactic getUnsolvedGoals)
def liftTacticElabM {α} (ref : Syntax) (mvarId : MVarId) (x : TacticM α) : TermElabM α :=
withMVarContext mvarId $ fun ctx s =>
let savedSyntheticMVars := s.syntheticMVars;
match x { ref := ref, main := mvarId, .. ctx } { goals := [mvarId], syntheticMVars := [], .. s } with
| EStateM.Result.error ex newS => EStateM.Result.error (Term.Exception.ex ex) { syntheticMVars := savedSyntheticMVars, .. newS.toTermState }
| EStateM.Result.ok a newS => EStateM.Result.ok a { syntheticMVars := savedSyntheticMVars, .. newS.toTermState }
def ensureAssignmentHasNoMVars (ref : Syntax) (mvarId : MVarId) : TermElabM Unit := do
val ← instantiateMVars ref (mkMVar mvarId);
when val.hasExprMVar $ throwError ref ("tactic failed, result still contain metavariables" ++ indentExpr val)
def runTactic (ref : Syntax) (mvarId : MVarId) (tacticCode : Syntax) : TermElabM Unit := do
modify $ fun s => { mctx := s.mctx.instantiateMVarDeclMVars mvarId, .. s };
remainingGoals ← liftTacticElabM ref mvarId $ do { evalTactic tacticCode; getUnsolvedGoals };
let tailRef := ref.getTailWithInfo.getD ref;
unless remainingGoals.isEmpty (reportUnsolvedGoals tailRef remainingGoals);
ensureAssignmentHasNoMVars tailRef mvarId
/-- Auxiliary function used to implement `synthesizeSyntheticMVars`. -/
private def resumeElabTerm (stx : Syntax) (expectedType? : Option Expr) (errToSorry := true) : TermElabM Expr :=
-- Remark: if `ctx.errToSorry` is already false, then we don't enable it. Recall tactics disable `errToSorry`
adaptReader (fun (ctx : Context) => { errToSorry := ctx.errToSorry && errToSorry, .. ctx }) $
elabTerm stx expectedType? false
/--
Try to elaborate `stx` that was postponed by an elaboration method using `Expection.postpone`.
It returns `true` if it succeeded, and `false` otherwise.
It is used to implement `synthesizeSyntheticMVars`. -/
private def resumePostponed (macroStack : MacroStack) (stx : Syntax) (mvarId : MVarId) (postponeOnError : Bool) : TermElabM Bool := do
withMVarContext mvarId $ do
s ← get;
catch
(adaptReader (fun (ctx : Context) => { macroStack := macroStack, .. ctx }) $ do
mvarDecl ← getMVarDecl mvarId;
expectedType ← instantiateMVars stx mvarDecl.type;
result ← resumeElabTerm stx expectedType (!postponeOnError);
/- We must ensure `result` has the expected type because it is the one expected by the method that postponed stx.
That is, the method does not have an opportunity to check whether `result` has the expected type or not. -/
result ← ensureHasType stx expectedType result;
assignExprMVar mvarId result;
pure true)
(fun ex => match ex with
| Exception.postpone => do set s; pure false
| Exception.ex Elab.Exception.unsupportedSyntax => unreachable!
| Exception.ex (Elab.Exception.error msg) =>
if postponeOnError then do
set s; pure false
else do
logMessage msg; pure true)
/--
Similar to `synthesizeInstMVarCore`, but makes sure that `instMVar` local context and instances
are used. It also logs any error message produced. -/
private def synthesizePendingInstMVar (ref : Syntax) (instMVar : MVarId) : TermElabM Bool := do
withMVarContext instMVar $ catch
(synthesizeInstMVarCore ref instMVar)
(fun ex => match ex with
| Exception.ex (Elab.Exception.error errMsg) => do logMessage errMsg; pure true
| _ => unreachable!)
/--
Similar to `synthesizePendingInstMVar`, but generates type mismatch error message. -/
private def synthesizePendingCoeInstMVar (ref : Syntax) (instMVar : MVarId) (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr) : TermElabM Bool := do
withMVarContext instMVar $ catch
(synthesizeInstMVarCore ref instMVar)
(fun ex => match ex with
| Exception.ex (Elab.Exception.error errMsg) => throwTypeMismatchError ref expectedType eType e f? errMsg.data
| _ => unreachable!)
/--
Return `true` iff `mvarId` is assigned to a term whose the
head is not a metavariable. We use this method to process `SyntheticMVarKind.withDefault`. -/
private def checkWithDefault (ref : Syntax) (mvarId : MVarId) : TermElabM Bool := do
val ← instantiateMVars ref (mkMVar mvarId);
pure $ !val.getAppFn.isMVar
/-- Try to synthesize the given pending synthetic metavariable. -/
private def synthesizeSyntheticMVar (mvarSyntheticDecl : SyntheticMVarDecl) (postponeOnError : Bool) (runTactics : Bool) : TermElabM Bool :=
match mvarSyntheticDecl.kind with
| SyntheticMVarKind.typeClass => synthesizePendingInstMVar mvarSyntheticDecl.ref mvarSyntheticDecl.mvarId
| SyntheticMVarKind.coe expectedType eType e f? => synthesizePendingCoeInstMVar mvarSyntheticDecl.ref mvarSyntheticDecl.mvarId expectedType eType e f?
-- NOTE: actual processing at `synthesizeSyntheticMVarsAux`
| SyntheticMVarKind.withDefault _ => checkWithDefault mvarSyntheticDecl.ref mvarSyntheticDecl.mvarId
| SyntheticMVarKind.postponed macroStack => resumePostponed macroStack mvarSyntheticDecl.ref mvarSyntheticDecl.mvarId postponeOnError
| SyntheticMVarKind.tactic tacticCode =>
if runTactics then do
runTactic mvarSyntheticDecl.ref mvarSyntheticDecl.mvarId tacticCode;
pure true
else
pure false
/--
Try to synthesize the current list of pending synthetic metavariables.
Return `true` if at least one of them was synthesized. -/
private def synthesizeSyntheticMVarsStep (postponeOnError : Bool) (runTactics : Bool) : TermElabM Bool := do
ctx ← read;
traceAtCmdPos `Elab.resuming $ fun _ =>
fmt "resuming synthetic metavariables, mayPostpone: " ++ fmt ctx.mayPostpone ++ ", postponeOnError: " ++ toString postponeOnError;
s ← get;
let syntheticMVars := s.syntheticMVars;
let numSyntheticMVars := syntheticMVars.length;
-- We reset `syntheticMVars` because new synthetic metavariables may be created by `synthesizeSyntheticMVar`.
modify $ fun s => { syntheticMVars := [], .. s };
-- Recall that `syntheticMVars` is a list where head is the most recent pending synthetic metavariable.
-- We use `filterRevM` instead of `filterM` to make sure we process the synthetic metavariables using the order they were created.
-- It would not be incorrect to use `filterM`.
remainingSyntheticMVars ← syntheticMVars.filterRevM $ fun mvarDecl => do {
trace `Elab.postpone mvarDecl.ref $ fun _ => "resuming ?" ++ mvarDecl.mvarId;
succeeded ← synthesizeSyntheticMVar mvarDecl postponeOnError runTactics;
trace `Elab.postpone mvarDecl.ref $ fun _ => if succeeded then fmt "succeeded" else fmt "not ready yet";
pure $ !succeeded
};
-- Merge new synthetic metavariables with `remainingSyntheticMVars`, i.e., metavariables that still couldn't be synthesized
modify $ fun s => { syntheticMVars := s.syntheticMVars ++ remainingSyntheticMVars, .. s };
pure $ numSyntheticMVars != remainingSyntheticMVars.length
/-- Apply default value to any pending synthetic metavariable of kind `SyntheticMVarKind.withDefault` -/
private def synthesizeUsingDefault : TermElabM Bool := do
s ← get;
let len := s.syntheticMVars.length;
newSyntheticMVars ← s.syntheticMVars.filterM $ fun mvarDecl =>
match mvarDecl.kind with
| SyntheticMVarKind.withDefault defaultVal => withMVarContext mvarDecl.mvarId $ do
val ← instantiateMVars mvarDecl.ref (mkMVar mvarDecl.mvarId);
when val.getAppFn.isMVar $
unlessM (isDefEq mvarDecl.ref val defaultVal) $
throwError mvarDecl.ref "failed to assign default value to metavariable"; -- TODO: better error message
pure false
| _ => pure true;
modify $ fun s => { syntheticMVars := newSyntheticMVars, .. s };
pure $ newSyntheticMVars.length != len
/-- Report an error for each synthetic metavariable that could not be resolved. -/
private def reportStuckSyntheticMVars : TermElabM Unit := do
s ← get;
s.syntheticMVars.forM $ fun mvarSyntheticDecl =>
match mvarSyntheticDecl.kind with
| SyntheticMVarKind.typeClass =>
withMVarContext mvarSyntheticDecl.mvarId $ do
mvarDecl ← getMVarDecl mvarSyntheticDecl.mvarId;
logError mvarSyntheticDecl.ref $
"failed to create type class instance for " ++ indentExpr mvarDecl.type
| SyntheticMVarKind.coe expectedType eType e f? =>
withMVarContext mvarSyntheticDecl.mvarId $ do
mvarDecl ← getMVarDecl mvarSyntheticDecl.mvarId;
throwTypeMismatchError mvarSyntheticDecl.ref expectedType eType e f? (some ("failed to create type class instance for " ++ indentExpr mvarDecl.type))
| _ => unreachable! -- TODO handle other cases.
private def getSomeSynthethicMVarsRef : TermElabM Syntax := do
s ← get;
match s.syntheticMVars.find? $ fun (mvarDecl : SyntheticMVarDecl) => !mvarDecl.ref.getPos.isNone with
| some mvarDecl => pure mvarDecl.ref
| none => pure Syntax.missing
/--
Main loop for `synthesizeSyntheticMVars.
It keeps executing `synthesizeSyntheticMVarsStep` while progress is being made.
If `mayPostpone == false`, then it applies default values to `SyntheticMVarKind.withDefault`
metavariables that are still unresolved, and then tries to resolve metavariables
with `mayPostpone == false`. That is, we force them to produce error messages and/or commit to
a "best option". If, after that, we still haven't made progress, we report "stuck" errors. -/
private partial def synthesizeSyntheticMVarsAux (mayPostpone := true) : Unit → TermElabM Unit
| _ => do
let try (x : TermElabM Bool) (k : TermElabM Unit) : TermElabM Unit := condM x (synthesizeSyntheticMVarsAux ()) k;
ref ← getSomeSynthethicMVarsRef;
withIncRecDepth ref $ do
s ← get;
unless s.syntheticMVars.isEmpty $ do
try (synthesizeSyntheticMVarsStep false false) $
unless mayPostpone $ do
/- Resume pending metavariables with "elaboration postponement" disabled.
We postpone elaboration errors in this step by setting `postponeOnError := true`.
Example:
```
#check let x := ⟨1, 2⟩; Prod.fst x
```
The term `⟨1, 2⟩` can't be elaborated because the expected type is not know.
The `x` at `Prod.fst x` is not elaborated because the type of `x` is not known.
When we execute the following step with "elaboration postponement" disabled,
the elaborator fails at `⟨1, 2⟩` and postpones it, and succeeds at `x` and learns
that its type must be of the form `Prod ?α ?β`.
Recall that we postponed `x` at `Prod.fst x` because its type it is not known.
We the type of `x` may learn later its type and it may contain implicit and/or auto arguments.
By disabling postponement, we are essentially giving up the opportunity of learning `x`s type
and assume it does not have implict and/or auto arguments. -/
try (withoutPostponing (synthesizeSyntheticMVarsStep true false)) $
try synthesizeUsingDefault $
try (withoutPostponing (synthesizeSyntheticMVarsStep false false)) $
try (synthesizeSyntheticMVarsStep false true) $
reportStuckSyntheticMVars
/--
Try to process pending synthetic metavariables. If `mayPostpone == false`,
then `syntheticMVars` is `[]` after executing this method. -/
def synthesizeSyntheticMVars (mayPostpone := true) : TermElabM Unit :=
synthesizeSyntheticMVarsAux mayPostpone ()
end Term
end Elab
end Lean
|
4fd1877cea261d39d70c9ff22e8cb845d89d1776 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/topology/algebra/group.lean | 8b7ac6c21157387fc9bed3c2fba2b6d94050e7c5 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 31,171 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import order.filter.pointwise
import group_theory.quotient_group
import topology.algebra.monoid
import topology.homeomorph
import topology.compacts
/-!
# Theory of topological groups
This file defines the following typeclasses:
* `topological_group`, `topological_add_group`: multiplicative and additive topological groups,
i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`;
* `has_continuous_sub G` means that `G` has a continuous subtraction operation.
There is an instance deducing `has_continuous_sub` from `topological_group` but we use a separate
typeclass because, e.g., `ℕ` and `ℝ≥0` have continuous subtraction but are not additive groups.
We also define `homeomorph` versions of several `equiv`s: `homeomorph.mul_left`,
`homeomorph.mul_right`, `homeomorph.inv`, and prove a few facts about neighbourhood filters in
groups.
## Tags
topological space, group, topological group
-/
open classical set filter topological_space function
open_locale classical topological_space filter pointwise
universes u v w x
variables {α : Type u} {β : Type v} {G : Type w} {H : Type x}
section continuous_mul_group
/-!
### Groups with continuous multiplication
In this section we prove a few statements about groups with continuous `(*)`.
-/
variables [topological_space G] [group G] [has_continuous_mul G]
/-- Multiplication from the left in a topological group as a homeomorphism. -/
@[to_additive "Addition from the left in a topological additive group as a homeomorphism."]
protected def homeomorph.mul_left (a : G) : G ≃ₜ G :=
{ continuous_to_fun := continuous_const.mul continuous_id,
continuous_inv_fun := continuous_const.mul continuous_id,
.. equiv.mul_left a }
@[simp, to_additive]
lemma homeomorph.coe_mul_left (a : G) : ⇑(homeomorph.mul_left a) = (*) a := rfl
@[to_additive]
lemma homeomorph.mul_left_symm (a : G) : (homeomorph.mul_left a).symm = homeomorph.mul_left a⁻¹ :=
by { ext, refl }
@[to_additive]
lemma is_open_map_mul_left (a : G) : is_open_map (λ x, a * x) :=
(homeomorph.mul_left a).is_open_map
@[to_additive]
lemma is_closed_map_mul_left (a : G) : is_closed_map (λ x, a * x) :=
(homeomorph.mul_left a).is_closed_map
/-- Multiplication from the right in a topological group as a homeomorphism. -/
@[to_additive "Addition from the right in a topological additive group as a homeomorphism."]
protected def homeomorph.mul_right (a : G) :
G ≃ₜ G :=
{ continuous_to_fun := continuous_id.mul continuous_const,
continuous_inv_fun := continuous_id.mul continuous_const,
.. equiv.mul_right a }
@[to_additive]
lemma is_open_map_mul_right (a : G) : is_open_map (λ x, x * a) :=
(homeomorph.mul_right a).is_open_map
@[to_additive]
lemma is_closed_map_mul_right (a : G) : is_closed_map (λ x, x * a) :=
(homeomorph.mul_right a).is_closed_map
@[to_additive]
lemma is_open_map_div_right (a : G) : is_open_map (λ x, x / a) :=
by simpa only [div_eq_mul_inv] using is_open_map_mul_right (a⁻¹)
@[to_additive]
lemma is_closed_map_div_right (a : G) : is_closed_map (λ x, x / a) :=
by simpa only [div_eq_mul_inv] using is_closed_map_mul_right (a⁻¹)
@[to_additive]
lemma discrete_topology_of_open_singleton_one (h : is_open ({1} : set G)) : discrete_topology G :=
begin
rw ← singletons_open_iff_discrete,
intro g,
suffices : {g} = (λ (x : G), g⁻¹ * x) ⁻¹' {1},
{ rw this, exact (continuous_mul_left (g⁻¹)).is_open_preimage _ h, },
simp only [mul_one, set.preimage_mul_left_singleton, eq_self_iff_true,
inv_inv, set.singleton_eq_singleton_iff],
end
@[to_additive]
lemma discrete_topology_iff_open_singleton_one : discrete_topology G ↔ is_open ({1} : set G) :=
⟨λ h, forall_open_iff_discrete.mpr h {1}, discrete_topology_of_open_singleton_one⟩
end continuous_mul_group
section topological_group
/-!
### Topological groups
A topological group is a group in which the multiplication and inversion operations are
continuous. Topological additive groups are defined in the same way. Equivalently, we can require
that the division operation `λ x y, x * y⁻¹` (resp., subtraction) is continuous.
-/
/-- A topological (additive) group is a group in which the addition and negation operations are
continuous. -/
class topological_add_group (G : Type u) [topological_space G] [add_group G]
extends has_continuous_add G : Prop :=
(continuous_neg : continuous (λa:G, -a))
/-- A topological group is a group in which the multiplication and inversion operations are
continuous. -/
@[to_additive]
class topological_group (G : Type*) [topological_space G] [group G]
extends has_continuous_mul G : Prop :=
(continuous_inv : continuous (has_inv.inv : G → G))
variables [topological_space G] [group G] [topological_group G]
export topological_group (continuous_inv)
export topological_add_group (continuous_neg)
@[to_additive]
lemma continuous_on_inv {s : set G} : continuous_on has_inv.inv s :=
continuous_inv.continuous_on
@[to_additive]
lemma continuous_within_at_inv {s : set G} {x : G} : continuous_within_at has_inv.inv s x :=
continuous_inv.continuous_within_at
@[to_additive]
lemma continuous_at_inv {x : G} : continuous_at has_inv.inv x :=
continuous_inv.continuous_at
@[to_additive]
lemma tendsto_inv (a : G) : tendsto has_inv.inv (𝓝 a) (𝓝 (a⁻¹)) :=
continuous_at_inv
/-- If a function converges to a value in a multiplicative topological group, then its inverse
converges to the inverse of this value. For the version in normed fields assuming additionally
that the limit is nonzero, use `tendsto.inv'`. -/
@[to_additive]
lemma filter.tendsto.inv {f : α → G} {l : filter α} {y : G} (h : tendsto f l (𝓝 y)) :
tendsto (λ x, (f x)⁻¹) l (𝓝 y⁻¹) :=
(continuous_inv.tendsto y).comp h
variables [topological_space α] {f : α → G} {s : set α} {x : α}
@[continuity, to_additive]
lemma continuous.inv (hf : continuous f) : continuous (λx, (f x)⁻¹) :=
continuous_inv.comp hf
@[to_additive]
lemma continuous_at.inv (hf : continuous_at f x) : continuous_at (λ x, (f x)⁻¹) x :=
continuous_at_inv.comp hf
@[to_additive]
lemma continuous_on.inv (hf : continuous_on f s) : continuous_on (λx, (f x)⁻¹) s :=
continuous_inv.comp_continuous_on hf
@[to_additive]
lemma continuous_within_at.inv (hf : continuous_within_at f s x) :
continuous_within_at (λ x, (f x)⁻¹) s x :=
hf.inv
section ordered_comm_group
variables [topological_space H] [ordered_comm_group H] [topological_group H]
@[to_additive] lemma tendsto_inv_nhds_within_Ioi {a : H} :
tendsto has_inv.inv (𝓝[Ioi a] a) (𝓝[Iio (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iio {a : H} :
tendsto has_inv.inv (𝓝[Iio a] a) (𝓝[Ioi (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ioi_inv {a : H} :
tendsto has_inv.inv (𝓝[Ioi (a⁻¹)] (a⁻¹)) (𝓝[Iio a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ioi _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iio_inv {a : H} :
tendsto has_inv.inv (𝓝[Iio (a⁻¹)] (a⁻¹)) (𝓝[Ioi a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iio _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Ici {a : H} :
tendsto has_inv.inv (𝓝[Ici a] a) (𝓝[Iic (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iic {a : H} :
tendsto has_inv.inv (𝓝[Iic a] a) (𝓝[Ici (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ici_inv {a : H} :
tendsto has_inv.inv (𝓝[Ici (a⁻¹)] (a⁻¹)) (𝓝[Iic a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ici _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iic_inv {a : H} :
tendsto has_inv.inv (𝓝[Iic (a⁻¹)] (a⁻¹)) (𝓝[Ici a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iic _ _ _ _ (a⁻¹)
end ordered_comm_group
@[instance, to_additive]
instance [topological_space H] [group H] [topological_group H] :
topological_group (G × H) :=
{ continuous_inv := continuous_inv.prod_map continuous_inv }
@[to_additive]
instance pi.topological_group {C : β → Type*} [∀ b, topological_space (C b)]
[∀ b, group (C b)] [∀ b, topological_group (C b)] : topological_group (Π b, C b) :=
{ continuous_inv := continuous_pi (λ i, (continuous_apply i).inv) }
variable (G)
/-- Inversion in a topological group as a homeomorphism. -/
@[to_additive "Negation in a topological group as a homeomorphism."]
protected def homeomorph.inv : G ≃ₜ G :=
{ continuous_to_fun := continuous_inv,
continuous_inv_fun := continuous_inv,
.. equiv.inv G }
@[to_additive]
lemma nhds_one_symm : comap has_inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) :=
((homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds one_inv)
/-- The map `(x, y) ↦ (x, xy)` as a homeomorphism. This is a shear mapping. -/
@[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism.
This is a shear mapping."]
protected def homeomorph.shear_mul_right : G × G ≃ₜ G × G :=
{ continuous_to_fun := continuous_fst.prod_mk continuous_mul,
continuous_inv_fun := continuous_fst.prod_mk $ continuous_fst.inv.mul continuous_snd,
.. equiv.prod_shear (equiv.refl _) equiv.mul_left }
@[simp, to_additive]
lemma homeomorph.shear_mul_right_coe :
⇑(homeomorph.shear_mul_right G) = λ z : G × G, (z.1, z.1 * z.2) :=
rfl
@[simp, to_additive]
lemma homeomorph.shear_mul_right_symm_coe :
⇑(homeomorph.shear_mul_right G).symm = λ z : G × G, (z.1, z.1⁻¹ * z.2) :=
rfl
variable {G}
@[to_additive]
lemma inv_closure (s : set G) : (closure s)⁻¹ = closure s⁻¹ :=
(homeomorph.inv G).preimage_closure s
/-- The (topological-space) closure of a subgroup of a space `M` with `has_continuous_mul` is
itself a subgroup. -/
@[to_additive "The (topological-space) closure of an additive subgroup of a space `M` with
`has_continuous_add` is itself an additive subgroup."]
def subgroup.topological_closure (s : subgroup G) : subgroup G :=
{ carrier := closure (s : set G),
inv_mem' := λ g m, by simpa [←mem_inv, inv_closure] using m,
..s.to_submonoid.topological_closure }
@[simp, to_additive] lemma subgroup.topological_closure_coe {s : subgroup G} :
(s.topological_closure : set G) = closure s :=
rfl
@[to_additive]
instance subgroup.topological_closure_topological_group (s : subgroup G) :
topological_group (s.topological_closure) :=
{ continuous_inv :=
begin
apply continuous_induced_rng,
change continuous (λ p : s.topological_closure, (p : G)⁻¹),
continuity,
end
..s.to_submonoid.topological_closure_has_continuous_mul}
@[to_additive] lemma subgroup.subgroup_topological_closure (s : subgroup G) :
s ≤ s.topological_closure :=
subset_closure
@[to_additive] lemma subgroup.is_closed_topological_closure (s : subgroup G) :
is_closed (s.topological_closure : set G) :=
by convert is_closed_closure
@[to_additive] lemma subgroup.topological_closure_minimal
(s : subgroup G) {t : subgroup G} (h : s ≤ t) (ht : is_closed (t : set G)) :
s.topological_closure ≤ t :=
closure_minimal h ht
@[to_additive] lemma dense_range.topological_closure_map_subgroup [group H] [topological_space H]
[topological_group H] {f : G →* H} (hf : continuous f) (hf' : dense_range f) {s : subgroup G}
(hs : s.topological_closure = ⊤) :
(s.map f).topological_closure = ⊤ :=
begin
rw set_like.ext'_iff at hs ⊢,
simp only [subgroup.topological_closure_coe, subgroup.coe_top, ← dense_iff_closure_eq] at hs ⊢,
exact hf'.dense_image hf hs
end
@[to_additive exists_nhds_half_neg]
lemma exists_nhds_split_inv {s : set G} (hs : s ∈ 𝓝 (1 : G)) :
∃ V ∈ 𝓝 (1 : G), ∀ (v ∈ V) (w ∈ V), v / w ∈ s :=
have ((λp : G × G, p.1 * p.2⁻¹) ⁻¹' s) ∈ 𝓝 ((1, 1) : G × G),
from continuous_at_fst.mul continuous_at_snd.inv (by simpa),
by simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage]
using this
@[to_additive]
lemma nhds_translation_mul_inv (x : G) : comap (λ y : G, y * x⁻¹) (𝓝 1) = 𝓝 x :=
((homeomorph.mul_right x⁻¹).comap_nhds_eq 1).trans $ show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x, by simp
@[simp, to_additive] lemma map_mul_left_nhds (x y : G) : map ((*) x) (𝓝 y) = 𝓝 (x * y) :=
(homeomorph.mul_left x).map_nhds_eq y
@[to_additive] lemma map_mul_left_nhds_one (x : G) : map ((*) x) (𝓝 1) = 𝓝 x := by simp
@[to_additive]
lemma topological_group.ext {G : Type*} [group G] {t t' : topological_space G}
(tg : @topological_group G t _) (tg' : @topological_group G t' _)
(h : @nhds G t 1 = @nhds G t' 1) : t = t' :=
eq_of_nhds_eq_nhds $ λ x, by
rw [← @nhds_translation_mul_inv G t _ _ x , ← @nhds_translation_mul_inv G t' _ _ x , ← h]
@[to_additive]
lemma topological_group.of_nhds_aux {G : Type*} [group G] [topological_space G]
(hinv : tendsto (λ (x : G), x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ (x₀ : G), 𝓝 x₀ = map (λ (x : G), x₀ * x) (𝓝 1))
(hconj : ∀ (x₀ : G), map (λ (x : G), x₀ * x * x₀⁻¹) (𝓝 1) ≤ 𝓝 1) : continuous (λ x : G, x⁻¹) :=
begin
rw continuous_iff_continuous_at,
rintros x₀,
have key : (λ x, (x₀*x)⁻¹) = (λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹) ∘ (λ x, x⁻¹),
by {ext ; simp[mul_assoc] },
calc map (λ x, x⁻¹) (𝓝 x₀)
= map (λ x, x⁻¹) (map (λ x, x₀*x) $ 𝓝 1) : by rw hleft
... = map (λ x, (x₀*x)⁻¹) (𝓝 1) : by rw filter.map_map
... = map (((λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹)) ∘ (λ x, x⁻¹)) (𝓝 1) : by rw key
... = map ((λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹)) _ : by rw ← filter.map_map
... ≤ map ((λ x, x₀⁻¹ * x) ∘ λ x, x₀ * x * x₀⁻¹) (𝓝 1) : map_mono hinv
... = map (λ x, x₀⁻¹ * x) (map (λ x, x₀ * x * x₀⁻¹) (𝓝 1)) : filter.map_map
... ≤ map (λ x, x₀⁻¹ * x) (𝓝 1) : map_mono (hconj x₀)
... = 𝓝 x₀⁻¹ : (hleft _).symm
end
@[to_additive]
lemma topological_group.of_nhds_one' {G : Type u} [group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1))
(hright : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x*x₀) (𝓝 1)) : topological_group G :=
begin
refine { continuous_mul := (has_continuous_mul.of_nhds_one hmul hleft hright).continuous_mul,
continuous_inv := topological_group.of_nhds_aux hinv hleft _ },
intros x₀,
suffices : map (λ (x : G), x₀ * x * x₀⁻¹) (𝓝 1) = 𝓝 1, by simp [this, le_refl],
rw [show (λ x, x₀ * x * x₀⁻¹) = (λ x, x₀ * x) ∘ λ x, x*x₀⁻¹, by {ext, simp [mul_assoc] },
← filter.map_map, ← hright, hleft x₀⁻¹, filter.map_map],
convert map_id,
ext,
simp
end
@[to_additive]
lemma topological_group.of_nhds_one {G : Type u} [group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1))
(hconj : ∀ x₀ : G, tendsto (λ x, x₀*x*x₀⁻¹) (𝓝 1) (𝓝 1)) : topological_group G :=
{ continuous_mul := begin
rw continuous_iff_continuous_at,
rintros ⟨x₀, y₀⟩,
have key : (λ (p : G × G), x₀ * p.1 * (y₀ * p.2)) =
((λ x, x₀*y₀*x) ∘ (uncurry (*)) ∘ (prod.map (λ x, y₀⁻¹*x*y₀) id)),
by { ext, simp [uncurry, prod.map, mul_assoc] },
specialize hconj y₀⁻¹, rw inv_inv at hconj,
calc map (λ (p : G × G), p.1 * p.2) (𝓝 (x₀, y₀))
= map (λ (p : G × G), p.1 * p.2) ((𝓝 x₀) ×ᶠ 𝓝 y₀)
: by rw nhds_prod_eq
... = map (λ (p : G × G), x₀ * p.1 * (y₀ * p.2)) ((𝓝 1) ×ᶠ (𝓝 1))
: by rw [hleft x₀, hleft y₀, prod_map_map_eq, filter.map_map]
... = map (((λ x, x₀*y₀*x) ∘ (uncurry (*))) ∘ (prod.map (λ x, y₀⁻¹*x*y₀) id))((𝓝 1) ×ᶠ (𝓝 1))
: by rw key
... = map ((λ x, x₀*y₀*x) ∘ (uncurry (*))) ((map (λ x, y₀⁻¹*x*y₀) $ 𝓝 1) ×ᶠ (𝓝 1))
: by rw [← filter.map_map, ← prod_map_map_eq', map_id]
... ≤ map ((λ x, x₀*y₀*x) ∘ (uncurry (*))) ((𝓝 1) ×ᶠ (𝓝 1))
: map_mono (filter.prod_mono hconj $ le_refl _)
... = map (λ x, x₀*y₀*x) (map (uncurry (*)) ((𝓝 1) ×ᶠ (𝓝 1))) : by rw filter.map_map
... ≤ map (λ x, x₀*y₀*x) (𝓝 1) : map_mono hmul
... = 𝓝 (x₀*y₀) : (hleft _).symm
end,
continuous_inv := topological_group.of_nhds_aux hinv hleft hconj}
@[to_additive]
lemma topological_group.of_comm_of_nhds_one {G : Type u} [comm_group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1)) : topological_group G :=
topological_group.of_nhds_one hmul hinv hleft (by simpa using tendsto_id)
end topological_group
section quotient_topological_group
variables [topological_space G] [group G] [topological_group G] (N : subgroup G) (n : N.normal)
@[to_additive]
instance {G : Type*} [group G] [topological_space G] (N : subgroup G) :
topological_space (quotient_group.quotient N) :=
quotient.topological_space
open quotient_group
@[to_additive]
lemma quotient_group.is_open_map_coe : is_open_map (coe : G → quotient N) :=
begin
intros s s_op,
change is_open ((coe : G → quotient N) ⁻¹' (coe '' s)),
rw quotient_group.preimage_image_coe N s,
exact is_open_Union (λ n, (continuous_mul_right _).is_open_preimage s s_op)
end
@[to_additive]
instance topological_group_quotient [N.normal] : topological_group (quotient N) :=
{ continuous_mul := begin
have cont : continuous ((coe : G → quotient N) ∘ (λ (p : G × G), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul,
have quot : quotient_map (λ p : G × G, ((p.1:quotient N), (p.2:quotient N))),
{ apply is_open_map.to_quotient_map,
{ exact (quotient_group.is_open_map_coe N).prod (quotient_group.is_open_map_coe N) },
{ exact continuous_quot_mk.prod_map continuous_quot_mk },
{ exact (surjective_quot_mk _).prod_map (surjective_quot_mk _) } },
exact (quotient_map.continuous_iff quot).2 cont,
end,
continuous_inv := begin
have : continuous ((coe : G → quotient N) ∘ (λ (a : G), a⁻¹)) :=
continuous_quot_mk.comp continuous_inv,
convert continuous_quotient_lift _ this,
end }
end quotient_topological_group
/-- A typeclass saying that `λ p : G × G, p.1 - p.2` is a continuous function. This property
automatically holds for topological additive groups but it also holds, e.g., for `ℝ≥0`. -/
class has_continuous_sub (G : Type*) [topological_space G] [has_sub G] : Prop :=
(continuous_sub : continuous (λ p : G × G, p.1 - p.2))
/-- A typeclass saying that `λ p : G × G, p.1 / p.2` is a continuous function. This property
automatically holds for topological groups. Lemmas using this class have primes.
The unprimed version is for `group_with_zero`. -/
@[to_additive]
class has_continuous_div (G : Type*) [topological_space G] [has_div G] : Prop :=
(continuous_div' : continuous (λ p : G × G, p.1 / p.2))
@[priority 100, to_additive] -- see Note [lower instance priority]
instance topological_group.to_has_continuous_div [topological_space G] [group G]
[topological_group G] : has_continuous_div G :=
⟨by { simp only [div_eq_mul_inv], exact continuous_fst.mul continuous_snd.inv }⟩
export has_continuous_sub (continuous_sub)
export has_continuous_div (continuous_div')
section has_continuous_div
variables [topological_space G] [has_div G] [has_continuous_div G]
@[to_additive sub]
lemma filter.tendsto.div' {f g : α → G} {l : filter α} {a b : G} (hf : tendsto f l (𝓝 a))
(hg : tendsto g l (𝓝 b)) : tendsto (λ x, f x / g x) l (𝓝 (a / b)) :=
(continuous_div'.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
@[to_additive const_sub]
lemma filter.tendsto.const_div' (b : G) {c : G} {f : α → G} {l : filter α}
(h : tendsto f l (𝓝 c)) : tendsto (λ k : α, b / f k) l (𝓝 (b / c)) :=
tendsto_const_nhds.div' h
@[to_additive sub_const]
lemma filter.tendsto.div_const' (b : G) {c : G} {f : α → G} {l : filter α}
(h : tendsto f l (𝓝 c)) : tendsto (λ k : α, f k / b) l (𝓝 (c / b)) :=
h.div' tendsto_const_nhds
variables [topological_space α] {f g : α → G} {s : set α} {x : α}
@[continuity, to_additive sub] lemma continuous.div' (hf : continuous f) (hg : continuous g) :
continuous (λ x, f x / g x) :=
continuous_div'.comp (hf.prod_mk hg : _)
@[to_additive continuous_sub_left]
lemma continuous_div_left' (a : G) : continuous (λ b : G, a / b) :=
continuous_const.div' continuous_id
@[to_additive continuous_sub_right]
lemma continuous_div_right' (a : G) : continuous (λ b : G, b / a) :=
continuous_id.div' continuous_const
@[to_additive sub]
lemma continuous_at.div' {f g : α → G} {x : α} (hf : continuous_at f x) (hg : continuous_at g x) :
continuous_at (λx, f x / g x) x :=
hf.div' hg
@[to_additive sub]
lemma continuous_within_at.div' (hf : continuous_within_at f s x)
(hg : continuous_within_at g s x) :
continuous_within_at (λ x, f x / g x) s x :=
hf.div' hg
@[to_additive sub]
lemma continuous_on.div' (hf : continuous_on f s) (hg : continuous_on g s) :
continuous_on (λx, f x / g x) s :=
λ x hx, (hf x hx).div' (hg x hx)
end has_continuous_div
@[to_additive]
lemma nhds_translation_div [topological_space G] [group G] [topological_group G] (x : G) :
comap (λy:G, y / x) (𝓝 1) = 𝓝 x :=
by simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x
/-- additive group with a neighbourhood around 0.
Only used to construct a topology and uniform space.
This is currently only available for commutative groups, but it can be extended to
non-commutative groups too.
-/
class add_group_with_zero_nhd (G : Type u) extends add_comm_group G :=
(Z [] : filter G)
(zero_Z : pure 0 ≤ Z)
(sub_Z : tendsto (λp:G×G, p.1 - p.2) (Z ×ᶠ Z) Z)
section filter_mul
section
variables [topological_space G] [group G] [topological_group G]
@[to_additive]
lemma is_open.mul_left {s t : set G} : is_open t → is_open (s * t) := λ ht,
begin
have : ∀a, is_open ((λ (x : G), a * x) '' t) :=
assume a, is_open_map_mul_left a t ht,
rw ← Union_mul_left_image,
exact is_open_Union (λa, is_open_Union $ λha, this _),
end
@[to_additive]
lemma is_open.mul_right {s t : set G} : is_open s → is_open (s * t) := λ hs,
begin
have : ∀a, is_open ((λ (x : G), x * a) '' s),
assume a, apply is_open_map_mul_right, exact hs,
rw ← Union_mul_right_image,
exact is_open_Union (λa, is_open_Union $ λha, this _),
end
variables (G)
@[to_additive]
lemma topological_group.t1_space (h : @is_closed G _ {1}) : t1_space G :=
⟨assume x, by { convert is_closed_map_mul_right x _ h, simp }⟩
@[to_additive]
lemma topological_group.regular_space [t1_space G] : regular_space G :=
⟨assume s a hs ha,
let f := λ p : G × G, p.1 * (p.2)⁻¹ in
have hf : continuous f := continuous_fst.mul continuous_snd.inv,
-- a ∈ -s implies f (a, 1) ∈ -s, and so (a, 1) ∈ f⁻¹' (-s);
-- and so can find t₁ t₂ open such that a ∈ t₁ × t₂ ⊆ f⁻¹' (-s)
let ⟨t₁, t₂, ht₁, ht₂, a_mem_t₁, one_mem_t₂, t_subset⟩ :=
is_open_prod_iff.1 ((is_open_compl_iff.2 hs).preimage hf) a (1:G) (by simpa [f]) in
begin
use [s * t₂, ht₂.mul_left, λ x hx, ⟨x, 1, hx, one_mem_t₂, mul_one _⟩],
rw [nhds_within, inf_principal_eq_bot, mem_nhds_iff],
refine ⟨t₁, _, ht₁, a_mem_t₁⟩,
rintros x hx ⟨y, z, hy, hz, yz⟩,
have : x * z⁻¹ ∈ sᶜ := (prod_subset_iff.1 t_subset) x hx z hz,
have : x * z⁻¹ ∈ s, rw ← yz, simpa,
contradiction
end⟩
local attribute [instance] topological_group.regular_space
@[to_additive]
lemma topological_group.t2_space [t1_space G] : t2_space G := regular_space.t2_space G
end
section
/-! Some results about an open set containing the product of two sets in a topological group. -/
variables [topological_space G] [group G] [topological_group G]
/-- Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of `1`
such that `KV ⊆ U`. -/
@[to_additive "Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of
`0` such that `K + V ⊆ U`."]
lemma compact_open_separated_mul {K U : set G} (hK : is_compact K) (hU : is_open U) (hKU : K ⊆ U) :
∃ V : set G, is_open V ∧ (1 : G) ∈ V ∧ K * V ⊆ U :=
begin
let W : G → set G := λ x, (λ y, x * y) ⁻¹' U,
have h1W : ∀ x, is_open (W x) := λ x, hU.preimage (continuous_mul_left x),
have h2W : ∀ x ∈ K, (1 : G) ∈ W x := λ x hx, by simp only [mem_preimage, mul_one, hKU hx],
choose V hV using λ x : K, exists_open_nhds_one_mul_subset ((h1W x).mem_nhds (h2W x.1 x.2)),
let X : K → set G := λ x, (λ y, (x : G)⁻¹ * y) ⁻¹' (V x),
obtain ⟨t, ht⟩ : ∃ t : finset ↥K, K ⊆ ⋃ i ∈ t, X i,
{ refine hK.elim_finite_subcover X (λ x, (hV x).1.preimage (continuous_mul_left x⁻¹)) _,
intros x hx, rw [mem_Union], use ⟨x, hx⟩, rw [mem_preimage], convert (hV _).2.1,
simp only [mul_left_inv, subtype.coe_mk] },
refine ⟨⋂ x ∈ t, V x, is_open_bInter (finite_mem_finset _) (λ x hx, (hV x).1), _, _⟩,
{ simp only [mem_Inter], intros x hx, exact (hV x).2.1 },
rintro _ ⟨x, y, hx, hy, rfl⟩, simp only [mem_Inter] at hy,
have := ht hx, simp only [mem_Union, mem_preimage] at this, rcases this with ⟨z, h1z, h2z⟩,
have : (z : G)⁻¹ * x * y ∈ W z := (hV z).2.2 (mul_mem_mul h2z (hy z h1z)),
rw [mem_preimage] at this, convert this using 1, simp only [mul_assoc, mul_inv_cancel_left]
end
/-- A compact set is covered by finitely many left multiplicative translates of a set
with non-empty interior. -/
@[to_additive "A compact set is covered by finitely many left additive translates of a set
with non-empty interior."]
lemma compact_covered_by_mul_left_translates {K V : set G} (hK : is_compact K)
(hV : (interior V).nonempty) : ∃ t : finset G, K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V :=
begin
obtain ⟨t, ht⟩ : ∃ t : finset G, K ⊆ ⋃ x ∈ t, interior (((*) x) ⁻¹' V),
{ refine hK.elim_finite_subcover (λ x, interior $ ((*) x) ⁻¹' V) (λ x, is_open_interior) _,
cases hV with g₀ hg₀,
refine λ g hg, mem_Union.2 ⟨g₀ * g⁻¹, _⟩,
refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) _,
rwa [mem_preimage, inv_mul_cancel_right] },
exact ⟨t, subset.trans ht $ bUnion_mono $ λ g hg, interior_subset⟩
end
/-- Every locally compact separable topological group is σ-compact.
Note: this is not true if we drop the topological group hypothesis. -/
@[priority 100, to_additive separable_locally_compact_add_group.sigma_compact_space]
instance separable_locally_compact_group.sigma_compact_space
[separable_space G] [locally_compact_space G] : sigma_compact_space G :=
begin
obtain ⟨L, hLc, hL1⟩ := exists_compact_mem_nhds (1 : G),
refine ⟨⟨λ n, (λ x, x * dense_seq G n) ⁻¹' L, _, _⟩⟩,
{ intro n, exact (homeomorph.mul_right _).compact_preimage.mpr hLc },
{ refine Union_eq_univ_iff.2 (λ x, _),
obtain ⟨_, ⟨n, rfl⟩, hn⟩ : (range (dense_seq G) ∩ (λ y, x * y) ⁻¹' L).nonempty,
{ rw [← (homeomorph.mul_left x).apply_symm_apply 1] at hL1,
exact (dense_range_dense_seq G).inter_nhds_nonempty
((homeomorph.mul_left x).continuous.continuous_at $ hL1) },
exact ⟨n, hn⟩ }
end
/-- Every separated topological group in which there exists a compact set with nonempty interior
is locally compact. -/
@[to_additive] lemma topological_space.positive_compacts.locally_compact_space_of_group
[t2_space G] (K : positive_compacts G) :
locally_compact_space G :=
begin
refine locally_compact_of_compact_nhds (λ x, _),
obtain ⟨y, hy⟩ : ∃ y, y ∈ interior K.1 := K.2.2,
let F := homeomorph.mul_left (x * y⁻¹),
refine ⟨F '' K.1, _, is_compact.image K.2.1 F.continuous⟩,
suffices : F.symm ⁻¹' K.1 ∈ 𝓝 x, by { convert this, apply equiv.image_eq_preimage },
apply continuous_at.preimage_mem_nhds F.symm.continuous.continuous_at,
have : F.symm x = y, by simp [F, homeomorph.mul_left_symm],
rw this,
exact mem_interior_iff_mem_nhds.1 hy
end
end
section
variables [topological_space G] [comm_group G] [topological_group G]
@[to_additive]
lemma nhds_mul (x y : G) : 𝓝 (x * y) = 𝓝 x * 𝓝 y :=
filter_eq $ set.ext $ assume s,
begin
rw [← nhds_translation_mul_inv x, ← nhds_translation_mul_inv y, ← nhds_translation_mul_inv (x*y)],
split,
{ rintros ⟨t, ht, ts⟩,
rcases exists_nhds_one_split ht with ⟨V, V1, h⟩,
refine ⟨(λa, a * x⁻¹) ⁻¹' V, (λa, a * y⁻¹) ⁻¹' V,
⟨V, V1, subset.refl _⟩, ⟨V, V1, subset.refl _⟩, _⟩,
rintros a ⟨v, w, v_mem, w_mem, rfl⟩,
apply ts,
simpa [mul_comm, mul_assoc, mul_left_comm] using h (v * x⁻¹) v_mem (w * y⁻¹) w_mem },
{ rintros ⟨a, c, ⟨b, hb, ba⟩, ⟨d, hd, dc⟩, ac⟩,
refine ⟨b ∩ d, inter_mem hb hd, assume v, _⟩,
simp only [preimage_subset_iff, mul_inv_rev, mem_preimage] at *,
rintros ⟨vb, vd⟩,
refine ac ⟨v * y⁻¹, y, _, _, _⟩,
{ rw ← mul_assoc _ _ _ at vb, exact ba _ vb },
{ apply dc y, rw mul_right_inv, exact mem_of_mem_nhds hd },
{ simp only [inv_mul_cancel_right] } }
end
/-- On a topological group, `𝓝 : G → filter G` can be promoted to a `mul_hom`. -/
@[to_additive "On an additive topological group, `𝓝 : G → filter G` can be promoted to an
`add_hom`.", simps]
def nhds_mul_hom : mul_hom G (filter G) :=
{ to_fun := 𝓝,
map_mul' := λ_ _, nhds_mul _ _ }
end
end filter_mul
instance additive.topological_add_group {G} [h : topological_space G]
[group G] [topological_group G] : @topological_add_group (additive G) h _ :=
{ continuous_neg := @continuous_inv G _ _ _ }
instance multiplicative.topological_group {G} [h : topological_space G]
[add_group G] [topological_add_group G] : @topological_group (multiplicative G) h _ :=
{ continuous_inv := @continuous_neg G _ _ _ }
namespace units
variables [monoid α] [topological_space α] [has_continuous_mul α]
instance : topological_group (units α) :=
{ continuous_inv := continuous_induced_rng ((continuous_unop.comp (continuous_snd.comp
(@continuous_embed_product α _ _))).prod_mk (continuous_op.comp continuous_coe)) }
end units
|
578bea8c72e799e1d32135b00f76a17c38cf755b | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/group_theory/order_of_element.lean | df41cfd566366c23365e9786f79d20897fd3919b | [
"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 | 30,441 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Julian Kuelshammer
-/
import data.nat.modeq
import algebra.iterate_hom
import algebra.pointwise
import dynamics.periodic_pts
import group_theory.coset
/-!
# Order of an element
This file defines the order of an element of a finite group. For a finite group `G` the order of
`x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`.
## Main definitions
* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite
order.
* `is_of_fin_add_order` is the additive analogue of `is_of_find_order`.
* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`
if `x` has infinite order.
* `add_order_of` is the additive analogue of `order_of`.
## Tags
order of an element
-/
open function nat
open_locale pointwise
universes u v
variables {G : Type u} {A : Type v}
variables {x y : G} {a b : A} {n m : ℕ}
section monoid_add_monoid
variables [monoid G] [add_monoid A]
section is_of_fin_order
@[to_additive is_periodic_pt_add_iff_nsmul_eq_zero]
lemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 ↔ x ^ n = 1 :=
by rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]
/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite
order, i.e. there exists `n ≥ 1` such that `n • a = 0`.-/
def is_of_fin_add_order (a : A) : Prop :=
(0 : A) ∈ periodic_pts ((+) a)
/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there
exists `n ≥ 1` such that `x ^ n = 1`.-/
@[to_additive is_of_fin_add_order]
def is_of_fin_order (x : G) : Prop :=
(1 : G) ∈ periodic_pts ((*) x)
lemma is_of_fin_add_order_of_mul_iff :
is_of_fin_add_order (additive.of_mul x) ↔ is_of_fin_order x := iff.rfl
lemma is_of_fin_order_of_add_iff :
is_of_fin_order (multiplicative.of_add a) ↔ is_of_fin_add_order a := iff.rfl
@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]
lemma is_of_fin_order_iff_pow_eq_one (x : G) :
is_of_fin_order x ↔ ∃ n, 0 < n ∧ x ^ n = 1 :=
by { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }
end is_of_fin_order
/-- `order_of x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists.
Otherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/
@[to_additive add_order_of
"`add_order_of a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it
exists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention."]
noncomputable def order_of (x : G) : ℕ :=
minimal_period ((*) x) 1
@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :
add_order_of (additive.of_mul x) = order_of x := rfl
@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :
order_of (multiplicative.of_add a) = add_order_of a := rfl
@[to_additive add_order_of_pos']
lemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=
minimal_period_pos_of_mem_periodic_pts h
@[to_additive add_order_of_nsmul_eq_zero]
lemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=
begin
convert is_periodic_pt_minimal_period ((*) x) _,
rw [order_of, mul_left_iterate, mul_one],
end
@[to_additive add_order_of_eq_zero]
lemma order_of_eq_zero (h : ¬ is_of_fin_order x) : order_of x = 0 :=
by rwa [order_of, minimal_period, dif_neg]
@[to_additive add_order_of_eq_zero_iff] lemma order_of_eq_zero_iff :
order_of x = 0 ↔ ¬ is_of_fin_order x :=
⟨λ h H, (order_of_pos' H).ne' h, order_of_eq_zero⟩
@[to_additive add_order_of_eq_zero_iff'] lemma order_of_eq_zero_iff' :
order_of x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 :=
by simp_rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one, not_exists, not_and]
@[to_additive nsmul_ne_zero_of_lt_add_order_of']
lemma pow_ne_one_of_lt_order_of' (n0 : n ≠ 0) (h : n < order_of x) : x ^ n ≠ 1 :=
λ j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h
((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)
@[to_additive add_order_of_le_of_nsmul_eq_zero]
lemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x ≤ n :=
is_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)
@[simp, to_additive] lemma order_of_one : order_of (1 : G) = 1 :=
by rw [order_of, one_mul_eq_id, minimal_period_id]
@[simp, to_additive add_monoid.order_of_eq_one_iff] lemma order_of_eq_one_iff :
order_of x = 1 ↔ x = 1 :=
by rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]
@[to_additive nsmul_eq_mod_add_order_of]
lemma pow_eq_mod_order_of {n : ℕ} : x ^ n = x ^ (n % order_of x) :=
calc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]
... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]
@[to_additive add_order_of_dvd_of_nsmul_eq_zero]
lemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x ∣ n :=
is_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)
@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]
lemma order_of_dvd_iff_pow_eq_one {n : ℕ} : order_of x ∣ n ↔ x ^ n = 1 :=
⟨λ h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one⟩
@[to_additive exists_nsmul_eq_self_of_coprime]
lemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :
∃ m : ℕ, (x ^ n) ^ m = x :=
begin
by_cases h0 : order_of x = 0,
{ rw [h0, coprime_zero_right] at h,
exact ⟨1, by rw [h, pow_one, pow_one]⟩ },
by_cases h1 : order_of x = 1,
{ exact ⟨0, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]⟩ },
obtain ⟨m, hm⟩ :=
exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩),
exact ⟨m, by rw [←pow_mul, pow_eq_mod_order_of, hm, pow_one]⟩,
end
/--
If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `r`,
then `x` has order `n` in `G`.
-/
@[to_additive add_order_of_eq_of_nsmul_and_div_prime_nsmul]
theorem order_of_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x^n = 1)
(hd : ∀ p : ℕ, p.prime → p ∣ n → x^(n/p) ≠ 1) :
order_of x = n :=
begin
-- Let `a` be `n/(order_of x)`, and show `a = 1`
cases exists_eq_mul_right_of_dvd (order_of_dvd_of_pow_eq_one hx) with a ha,
suffices : a = 1, by simp [this, ha],
-- Assume `a` is not one...
by_contra,
have a_min_fac_dvd_p_sub_one : a.min_fac ∣ n,
{ obtain ⟨b, hb⟩ : ∃ (b : ℕ), a = b * a.min_fac := exists_eq_mul_left_of_dvd a.min_fac_dvd,
rw [hb, ←mul_assoc] at ha,
exact dvd.intro_left (order_of x * b) ha.symm, },
-- Use the minimum prime factor of `a` as `p`.
refine hd a.min_fac (nat.min_fac_prime h) a_min_fac_dvd_p_sub_one _,
rw [←order_of_dvd_iff_pow_eq_one, nat.dvd_div_iff (a_min_fac_dvd_p_sub_one),
ha, mul_comm, nat.mul_dvd_mul_iff_left (order_of_pos' _)],
{ exact nat.min_fac_dvd a, },
{ rw is_of_fin_order_iff_pow_eq_one,
exact Exists.intro n (id ⟨hn, hx⟩) },
end
@[to_additive add_order_of_eq_add_order_of_iff]
lemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :
order_of x = order_of y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 :=
by simp_rw [← is_periodic_pt_mul_iff_pow_eq_one, ← minimal_period_eq_minimal_period_iff, order_of]
@[to_additive add_order_of_injective]
lemma order_of_injective {H : Type*} [monoid H] (f : G →* H)
(hf : function.injective f) (x : G) : order_of (f x) = order_of x :=
by simp_rw [order_of_eq_order_of_iff, ←f.map_pow, ←f.map_one, hf.eq_iff, iff_self, forall_const]
@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}
(y : H) : order_of (y : G) = order_of y :=
order_of_injective H.subtype subtype.coe_injective y
@[to_additive order_of_add_units]
lemma order_of_units {y : Gˣ} : order_of (y : G) = order_of y :=
order_of_injective (units.coe_hom G) units.ext y
variables (x)
@[to_additive add_order_of_nsmul']
lemma order_of_pow' (h : n ≠ 0) :
order_of (x ^ n) = order_of x / gcd (order_of x) n :=
begin
convert minimal_period_iterate_eq_div_gcd h,
simp only [order_of, mul_left_iterate],
end
variables (a) (n)
@[to_additive add_order_of_nsmul'']
lemma order_of_pow'' (h : is_of_fin_order x) :
order_of (x ^ n) = order_of x / gcd (order_of x) n :=
begin
convert minimal_period_iterate_eq_div_gcd' h,
simp only [order_of, mul_left_iterate],
end
@[to_additive]
lemma commute.order_of_mul_dvd_lcm {x y : G} (h : commute x y) :
order_of (x * y) ∣ nat.lcm (order_of x) (order_of y) :=
begin
convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,
rw [order_of, comp_mul_left],
end
@[to_additive add_order_of_add_dvd_mul_add_order_of]
lemma commute.order_of_mul_dvd_mul_order_of {x y : G} (h : commute x y) :
order_of (x * y) ∣ (order_of x) * (order_of y) :=
dvd_trans h.order_of_mul_dvd_lcm (lcm_dvd_mul _ _)
@[to_additive add_order_of_add_eq_mul_add_order_of_of_coprime]
lemma commute.order_of_mul_eq_mul_order_of_of_coprime {x y : G} (h : commute x y)
(hco : nat.coprime (order_of x) (order_of y)) :
order_of (x * y) = (order_of x) * (order_of y) :=
begin
convert h.function_commute_mul_left.minimal_period_of_comp_eq_mul_of_coprime hco,
simp only [order_of, comp_mul_left],
end
section p_prime
variables {a x n} {p : ℕ} [hp : fact p.prime]
include hp
@[to_additive add_order_of_eq_prime]
lemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : order_of x = p :=
minimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)
(by rwa [is_fixed_pt, mul_one])
@[to_additive add_order_of_eq_prime_pow]
lemma order_of_eq_prime_pow (hnot : ¬ x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :
order_of x = p ^ (n + 1) :=
begin
apply minimal_period_eq_prime_pow;
rwa is_periodic_pt_mul_iff_pow_eq_one,
end
omit hp
-- An example on how to determine the order of an element of a finite group.
example : order_of (-1 : ℤˣ) = 2 :=
order_of_eq_prime (int.units_sq _) dec_trivial
end p_prime
end monoid_add_monoid
section cancel_monoid
variables [left_cancel_monoid G] (x y)
@[to_additive nsmul_injective_aux]
lemma pow_injective_aux (h : n ≤ m)
(hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=
by_contradiction $ assume ne : n ≠ m,
have h₁ : m - n > 0, from nat.pos_of_ne_zero (by simp [tsub_eq_iff_eq_add_of_le h, ne.symm]),
have h₂ : m = n + (m - n) := (add_tsub_cancel_of_le h).symm,
have h₃ : x ^ (m - n) = 1,
by { rw [h₂, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (x ^ n) },
have le : order_of x ≤ m - n, from order_of_le_of_pow_eq_one h₁ h₃,
have lt : m - n < order_of x,
from (tsub_lt_iff_left h).mpr $ nat.lt_add_left _ _ _ hm,
lt_irrefl _ (le.trans_lt lt)
@[to_additive nsmul_injective_of_lt_add_order_of]
lemma pow_injective_of_lt_order_of
(hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=
(le_total n m).elim
(assume h, pow_injective_aux x h hm eq)
(assume h, (pow_injective_aux x h hn eq.symm).symm)
@[to_additive mem_multiples_iff_mem_range_add_order_of']
lemma mem_powers_iff_mem_range_order_of' [decidable_eq G] (hx : 0 < order_of x) :
y ∈ submonoid.powers x ↔ y ∈ (finset.range (order_of x)).image ((^) x : ℕ → G) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' hx (λ i, pow_eq_mod_order_of.symm)
lemma pow_eq_one_iff_modeq : x ^ n = 1 ↔ n ≡ 0 [MOD (order_of x)] :=
by rw [modeq_zero_iff_dvd, order_of_dvd_iff_pow_eq_one]
lemma pow_eq_pow_iff_modeq : x ^ n = x ^ m ↔ n ≡ m [MOD (order_of x)] :=
begin
wlog hmn : m ≤ n,
obtain ⟨k, rfl⟩ := nat.exists_eq_add_of_le hmn,
rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modeq],
exact ⟨λ h, nat.modeq.add_left _ h, λ h, nat.modeq.add_left_cancel' _ h⟩,
end
end cancel_monoid
section group
variables [group G] [add_group A] {x a} {i : ℤ}
@[to_additive add_order_of_dvd_iff_zsmul_eq_zero]
lemma order_of_dvd_iff_zpow_eq_one : (order_of x : ℤ) ∣ i ↔ x ^ i = 1 :=
begin
rcases int.eq_coe_or_neg i with ⟨i, rfl|rfl⟩,
{ rw [int.coe_nat_dvd, order_of_dvd_iff_pow_eq_one, zpow_coe_nat] },
{ rw [dvd_neg, int.coe_nat_dvd, zpow_neg, inv_eq_one, zpow_coe_nat,
order_of_dvd_iff_pow_eq_one] }
end
@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}
(y: H) : order_of (y : G) = order_of y :=
order_of_injective H.subtype subtype.coe_injective y
@[to_additive zsmul_eq_mod_add_order_of]
lemma zpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=
calc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :
by rw [int.mod_add_div]
... = x ^ (i % order_of x) :
by simp [zpow_add, zpow_mul, pow_order_of_eq_one]
set_option pp.all true
@[to_additive nsmul_inj_iff_of_add_order_of_eq_zero]
lemma pow_inj_iff_of_order_of_eq_zero (h : order_of x = 0) {n m : ℕ} :
x ^ n = x ^ m ↔ n = m :=
begin
rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one] at h,
push_neg at h,
induction n with n IH generalizing m,
{ cases m,
{ simp },
{ simpa [eq_comm] using h m.succ m.zero_lt_succ } },
{ cases m,
{ simpa using h n.succ n.zero_lt_succ },
{ simp [pow_succ, IH] } }
end
@[to_additive nsmul_inj_mod]
lemma pow_inj_mod {n m : ℕ} :
x ^ n = x ^ m ↔ n % order_of x = m % order_of x :=
begin
cases (order_of x).zero_le.eq_or_lt with hx hx,
{ simp [pow_inj_iff_of_order_of_eq_zero, hx.symm] },
rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ m],
exact ⟨pow_injective_of_lt_order_of _ (nat.mod_lt _ hx) (nat.mod_lt _ hx), λ h, congr_arg _ h⟩
end
end group
section fintype
variables [fintype G] [fintype A]
section finite_monoid
variables [monoid G] [add_monoid A]
open_locale big_operators
@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]
lemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :
∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ x : G, order_of x = m)).card
= (finset.univ.filter (λ x : G, x ^ n = 1)).card :=
calc ∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ x : G, order_of x = m)).card
= _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm
... = _ : congr_arg finset.card (finset.ext (begin
assume x,
suffices : order_of x ≤ n ∧ order_of x ∣ n ↔ x ^ n = 1,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],
λ h, ⟨order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h⟩⟩
end))
end finite_monoid
section finite_cancel_monoid
-- TODO: Of course everything also works for right_cancel_monoids.
variables [left_cancel_monoid G] [add_left_cancel_monoid A]
-- TODO: Use this to show that a finite left cancellative monoid is a group.
@[to_additive exists_nsmul_eq_zero]
lemma exists_pow_eq_one (x : G) : is_of_fin_order x :=
begin
refine (is_of_fin_order_iff_pow_eq_one _).mpr _,
obtain ⟨i, j, a_eq, ne⟩ : ∃(i j : ℕ), x ^ i = x ^ j ∧ i ≠ j :=
by simpa only [not_forall, exists_prop, injective]
using (not_injective_infinite_fintype (λi:ℕ, x^i)),
wlog h'' : j ≤ i,
refine ⟨i - j, tsub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _⟩,
rw [mul_one, ← pow_add, ← a_eq, add_tsub_cancel_of_le h''],
end
@[to_additive add_order_of_le_card_univ]
lemma order_of_le_card_univ : order_of x ≤ fintype.card G :=
finset.le_card_of_inj_on_range ((^) x)
(assume n _, finset.mem_univ _)
(assume i hi j hj, pow_injective_of_lt_order_of x hi hj)
/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative monoid.-/
@[to_additive add_order_of_pos
"This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative additive monoid."]
lemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)
open nat
/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is
automatic in the case of a finite cancellative monoid.-/
@[to_additive add_order_of_nsmul
"This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less
which is automatic in the case of a finite cancellative additive monoid."]
lemma order_of_pow (x : G) :
order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)
@[to_additive mem_multiples_iff_mem_range_add_order_of]
lemma mem_powers_iff_mem_range_order_of [decidable_eq G] :
y ∈ submonoid.powers x ↔ y ∈ (finset.range (order_of x)).image ((^) x : ℕ → G) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)
(assume i, pow_eq_mod_order_of.symm)
@[to_additive decidable_multiples]
noncomputable instance decidable_powers [decidable_eq G] :
decidable_pred (∈ submonoid.powers x) :=
begin
assume y,
apply decidable_of_iff'
(y ∈ (finset.range (order_of x)).image ((^) x)),
exact mem_powers_iff_mem_range_order_of
end
/--The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`."-/
@[to_additive fin_equiv_multiples "The equivalence between `fin (add_order_of a)` and
`add_submonoid.multiples a`, sending `i` to `i • a`."]
noncomputable def fin_equiv_powers (x : G) :
fin (order_of x) ≃ (submonoid.powers x : set G) :=
equiv.of_bijective (λ n, ⟨x ^ ↑n, ⟨n, rfl⟩⟩) ⟨λ ⟨i, hi⟩ ⟨j, hj⟩ ij,
subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),
λ ⟨_, i, rfl⟩, ⟨⟨i % order_of x, mod_lt i (order_of_pos x)⟩, subtype.eq pow_eq_mod_order_of.symm⟩⟩
@[simp, to_additive fin_equiv_multiples_apply]
lemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :
fin_equiv_powers x n = ⟨x ^ ↑n, n, rfl⟩ := rfl
@[simp, to_additive fin_equiv_multiples_symm_apply]
lemma fin_equiv_powers_symm_apply (x : G) (n : ℕ)
{hn : ∃ (m : ℕ), x ^ m = x ^ n} :
((fin_equiv_powers x).symm ⟨x ^ n, hn⟩) = ⟨n % order_of x, nat.mod_lt _ (order_of_pos x)⟩ :=
by rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,
pow_eq_mod_order_of, fin.coe_mk]
/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
@[to_additive multiples_equiv_multiples
"The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`."]
noncomputable def powers_equiv_powers (h : order_of x = order_of y) :
(submonoid.powers x : set G) ≃ (submonoid.powers y : set G) :=
(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))
@[simp, to_additive multiples_equiv_multiples_apply]
lemma powers_equiv_powers_apply (h : order_of x = order_of y)
(n : ℕ) : powers_equiv_powers h ⟨x ^ n, n, rfl⟩ = ⟨y ^ n, n, rfl⟩ :=
begin
rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,
fin_equiv_powers_symm_apply, ← equiv.eq_symm_apply, fin_equiv_powers_symm_apply],
simp [h]
end
@[to_additive add_order_of_eq_card_multiples]
lemma order_eq_card_powers [decidable_eq G] :
order_of x = fintype.card (submonoid.powers x : set G) :=
(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_powers x⟩)
end finite_cancel_monoid
section finite_group
variables [group G] [add_group A]
@[to_additive]
lemma exists_zpow_eq_one (x : G) : ∃ (i : ℤ) (H : i ≠ 0), x ^ (i : ℤ) = 1 :=
begin
rcases exists_pow_eq_one x with ⟨w, hw1, hw2⟩,
refine ⟨w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _⟩,
rw zpow_coe_nat,
exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,
end
open subgroup
@[to_additive mem_multiples_iff_mem_zmultiples]
lemma mem_powers_iff_mem_zpowers : y ∈ submonoid.powers x ↔ y ∈ zpowers x :=
⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩,
λ ⟨i, hi⟩, ⟨(i % order_of x).nat_abs,
by rwa [← zpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),
← zpow_eq_mod_order_of]⟩⟩
@[to_additive multiples_eq_zmultiples]
lemma powers_eq_zpowers (x : G) : (submonoid.powers x : set G) = zpowers x :=
set.ext $ λ x, mem_powers_iff_mem_zpowers
@[to_additive mem_zmultiples_iff_mem_range_add_order_of]
lemma mem_zpowers_iff_mem_range_order_of [decidable_eq G] :
y ∈ subgroup.zpowers x ↔ y ∈ (finset.range (order_of x)).image ((^) x : ℕ → G) :=
by rw [← mem_powers_iff_mem_zpowers, mem_powers_iff_mem_range_order_of]
@[to_additive decidable_zmultiples]
noncomputable instance decidable_zpowers [decidable_eq G] :
decidable_pred (∈ subgroup.zpowers x) :=
begin
simp_rw ←set_like.mem_coe,
rw ← powers_eq_zpowers,
exact decidable_powers,
end
/-- The equivalence between `fin (order_of x)` and `subgroup.zpowers x`, sending `i` to `x ^ i`. -/
@[to_additive fin_equiv_zmultiples
"The equivalence between `fin (add_order_of a)` and `subgroup.zmultiples a`, sending `i`
to `i • a`."]
noncomputable def fin_equiv_zpowers (x : G) :
fin (order_of x) ≃ (subgroup.zpowers x : set G) :=
(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_zpowers x))
@[simp, to_additive fin_equiv_zmultiples_apply]
lemma fin_equiv_zpowers_apply {n : fin (order_of x)} :
fin_equiv_zpowers x n = ⟨x ^ (n : ℕ), n, zpow_coe_nat x n⟩ := rfl
@[simp, to_additive fin_equiv_zmultiples_symm_apply]
lemma fin_equiv_zpowers_symm_apply (x : G) (n : ℕ)
{hn : ∃ (m : ℤ), x ^ m = x ^ n} :
((fin_equiv_zpowers x).symm ⟨x ^ n, hn⟩) = ⟨n % order_of x, nat.mod_lt _ (order_of_pos x)⟩ :=
by { rw [fin_equiv_zpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],
exact fin_equiv_powers_symm_apply x n }
/-- The equivalence between `subgroup.zpowers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
@[to_additive zmultiples_equiv_zmultiples
"The equivalence between `subgroup.zmultiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`."]
noncomputable def zpowers_equiv_zpowers (h : order_of x = order_of y) :
(subgroup.zpowers x : set G) ≃ (subgroup.zpowers y : set G) :=
(fin_equiv_zpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_zpowers y))
@[simp, to_additive zmultiples_equiv_zmultiples_apply]
lemma zpowers_equiv_zpowers_apply (h : order_of x = order_of y)
(n : ℕ) : zpowers_equiv_zpowers h ⟨x ^ n, n, zpow_coe_nat x n⟩ = ⟨y ^ n, n, zpow_coe_nat y n⟩ :=
begin
rw [zpowers_equiv_zpowers, equiv.trans_apply, equiv.trans_apply,
fin_equiv_zpowers_symm_apply, ← equiv.eq_symm_apply, fin_equiv_zpowers_symm_apply],
simp [h]
end
@[to_additive add_order_eq_card_zmultiples]
lemma order_eq_card_zpowers [decidable_eq G] :
order_of x = fintype.card (subgroup.zpowers x : set G) :=
(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_zpowers x⟩)
open quotient_group
/- TODO: use cardinal theory, introduce `card : set G → ℕ`, or setup decidability for cosets -/
@[to_additive add_order_of_dvd_card_univ]
lemma order_of_dvd_card_univ : order_of x ∣ fintype.card G :=
begin
classical,
have ft_prod : fintype ((G ⧸ zpowers x) × zpowers x),
from fintype.of_equiv G group_equiv_quotient_times_subgroup,
have ft_s : fintype (zpowers x),
from @fintype.prod_right _ _ _ ft_prod _,
have ft_cosets : fintype (G ⧸ zpowers x),
from @fintype.prod_left _ _ _ ft_prod ⟨⟨1, (zpowers x).one_mem⟩⟩,
have eq₁ : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,
from calc fintype.card G = @fintype.card _ ft_prod :
@fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup
... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :
congr_arg (@fintype.card _) $ subsingleton.elim _ _
... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :
@fintype.card_prod _ _ ft_cosets ft_s,
have eq₂ : order_of x = @fintype.card _ ft_s,
from calc order_of x = _ : order_eq_card_zpowers
... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,
exact dvd.intro (@fintype.card (G ⧸ subgroup.zpowers x) ft_cosets)
(by rw [eq₁, eq₂, mul_comm])
end
@[simp, to_additive card_nsmul_eq_zero] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=
let ⟨m, hm⟩ := @order_of_dvd_card_univ _ x _ _ in
by simp [hm, pow_mul, pow_order_of_eq_one]
@[to_additive nsmul_eq_mod_card] lemma pow_eq_mod_card (n : ℕ) :
x ^ n = x ^ (n % fintype.card G) :=
by rw [pow_eq_mod_order_of, ←nat.mod_mod_of_dvd n order_of_dvd_card_univ,
← pow_eq_mod_order_of]
@[to_additive] lemma zpow_eq_mod_card (n : ℤ) :
x ^ n = x ^ (n % fintype.card G) :=
by rw [zpow_eq_mod_order_of, ← int.mod_mod_of_dvd n (int.coe_nat_dvd.2 order_of_dvd_card_univ),
← zpow_eq_mod_order_of]
/-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/
@[to_additive nsmul_coprime "If `gcd(|G|,n)=1` then the smul by `n` is a bijection", simps]
def pow_coprime (h : nat.coprime (fintype.card G) n) : G ≃ G :=
{ to_fun := λ g, g ^ n,
inv_fun := λ g, g ^ (nat.gcd_b (fintype.card G) n),
left_inv := λ g, by
{ have key : g ^ _ = g ^ _ := congr_arg (λ n : ℤ, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),
rwa [zpow_add, zpow_mul, zpow_mul, zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,
h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key },
right_inv := λ g, by
{ have key : g ^ _ = g ^ _ := congr_arg (λ n : ℤ, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),
rwa [zpow_add, zpow_mul, zpow_mul', zpow_coe_nat, zpow_coe_nat, zpow_coe_nat,
h.gcd_eq_one, pow_one, pow_card_eq_one, one_zpow, one_mul, eq_comm] at key } }
@[simp, to_additive] lemma pow_coprime_one (h : nat.coprime (fintype.card G) n) :
pow_coprime h 1 = 1 := one_pow n
@[simp, to_additive] lemma pow_coprime_inv (h : nat.coprime (fintype.card G) n) {g : G} :
pow_coprime h g⁻¹ = (pow_coprime h g)⁻¹ := inv_pow g n
@[to_additive add_inf_eq_bot_of_coprime]
lemma inf_eq_bot_of_coprime {G : Type*} [group G] {H K : subgroup G} [fintype H] [fintype K]
(h : nat.coprime (fintype.card H) (fintype.card K)) : H ⊓ K = ⊥ :=
begin
refine (H ⊓ K).eq_bot_iff_forall.mpr (λ x hx, _),
rw [←order_of_eq_one_iff, ←nat.dvd_one, ←h.gcd_eq_one, nat.dvd_gcd_iff],
exact ⟨(congr_arg (∣ fintype.card H) (order_of_subgroup ⟨x, hx.1⟩)).mpr order_of_dvd_card_univ,
(congr_arg (∣ fintype.card K) (order_of_subgroup ⟨x, hx.2⟩)).mpr order_of_dvd_card_univ⟩,
end
variable (a)
/-- TODO: Generalise to `submonoid.powers`.-/
@[to_additive image_range_add_order_of]
lemma image_range_order_of [decidable_eq G] :
finset.image (λ i, x ^ i) (finset.range (order_of x)) = (zpowers x : set G).to_finset :=
by { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_zpowers_iff_mem_range_order_of] }
/-- TODO: Generalise to `finite_cancel_monoid`. -/
@[to_additive gcd_nsmul_card_eq_zero_iff]
lemma pow_gcd_card_eq_one_iff : x ^ n = 1 ↔ x ^ (gcd n (fintype.card G)) = 1 :=
⟨λ h, pow_gcd_eq_one _ h $ pow_card_eq_one,
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card G) in
by rw [hm, pow_mul, h, one_pow]⟩
end finite_group
end fintype
section pow_is_subgroup
/-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/
@[to_additive "A nonempty idempotent subset of a finite cancellative add monoid is a submonoid"]
def submonoid_of_idempotent {M : Type*} [left_cancel_monoid M] [fintype M] (S : set M)
(hS1 : S.nonempty) (hS2 : S * S = S) : submonoid M :=
have pow_mem : ∀ a : M, a ∈ S → ∀ n : ℕ, a ^ (n + 1) ∈ S :=
λ a ha, nat.rec (by rwa [zero_add, pow_one])
(λ n ih, (congr_arg2 (∈) (pow_succ a (n + 1)).symm hS2).mp (set.mul_mem_mul ha ih)),
{ carrier := S,
one_mem' := by
{ obtain ⟨a, ha⟩ := hS1,
rw [←pow_order_of_eq_one a, ← tsub_add_cancel_of_le (succ_le_of_lt (order_of_pos a))],
exact pow_mem a ha (order_of a - 1) },
mul_mem' := λ a b ha hb, (congr_arg2 (∈) rfl hS2).mp (set.mul_mem_mul ha hb) }
/-- A nonempty idempotent subset of a finite group is a subgroup -/
@[to_additive "A nonempty idempotent subset of a finite add group is a subgroup"]
def subgroup_of_idempotent {G : Type*} [group G] [fintype G] (S : set G)
(hS1 : S.nonempty) (hS2 : S * S = S) : subgroup G :=
{ carrier := S,
inv_mem' := λ a ha, by
{ rw [←one_mul a⁻¹, ←pow_one a, ←pow_order_of_eq_one a, ←pow_sub a (order_of_pos a)],
exact (submonoid_of_idempotent S hS1 hS2).pow_mem ha (order_of a - 1) },
.. submonoid_of_idempotent S hS1 hS2 }
/-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/
@[to_additive smul_card_add_subgroup "If `S` is a nonempty subset of a finite add group `G`,
then `|G| • S` is a subgroup", simps]
def pow_card_subgroup {G : Type*} [group G] [fintype G] (S : set G) (hS : S.nonempty) :
subgroup G :=
have one_mem : (1 : G) ∈ (S ^ fintype.card G) := by
{ obtain ⟨a, ha⟩ := hS,
rw ← pow_card_eq_one,
exact set.pow_mem_pow ha (fintype.card G) },
subgroup_of_idempotent (S ^ (fintype.card G)) ⟨1, one_mem⟩ begin
classical,
refine (set.eq_of_subset_of_card_le
(λ b hb, (congr_arg (∈ _) (one_mul b)).mp (set.mul_mem_mul one_mem hb)) (ge_of_eq _)).symm,
change _ = fintype.card (_ * _ : set G),
rw [←pow_add, group.card_pow_eq_card_pow_card_univ S (fintype.card G) le_rfl,
group.card_pow_eq_card_pow_card_univ S (fintype.card G + fintype.card G) le_add_self],
end
end pow_is_subgroup
section linear_ordered_ring
variable [linear_ordered_ring G]
lemma order_of_abs_ne_one (h : |x| ≠ 1) : order_of x = 0 :=
begin
rw order_of_eq_zero_iff',
intros n hn hx,
replace hx : |x| ^ n = 1 := by simpa only [abs_one, abs_pow] using congr_arg abs hx,
cases h.lt_or_lt with h h,
{ exact ((pow_lt_one (abs_nonneg x) h hn.ne').ne hx).elim },
{ exact ((one_lt_pow h hn.ne').ne' hx).elim }
end
lemma linear_ordered_ring.order_of_le_two : order_of x ≤ 2 :=
begin
cases ne_or_eq (|x|) 1 with h h,
{ simp [order_of_abs_ne_one h] },
rcases eq_or_eq_neg_of_abs_eq h with rfl | rfl,
{ simp },
apply order_of_le_of_pow_eq_one; norm_num
end
end linear_ordered_ring
|
11501fb65eac71470c85f1825ea78b7975f6d10e | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/group_theory/double_coset.lean | 7d05e5d7f9e58de24df4e6f1cc40507e390ad67c | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 7,606 | lean | /-
Copyright (c) 2021 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import data.setoid.basic
import group_theory.subgroup.basic
import group_theory.coset
import group_theory.subgroup.pointwise
import data.set.basic
import tactic.group
/-!
# Double cosets
This file defines double cosets for two subgroups `H K` of a group `G` and the quotient of `G` by
the double coset relation, i.e. `H \ G / K`. We also prove that `G` can be writen as a disjoint
union of the double cosets and that if one of `H` or `K` is the trivial group (i.e. `⊥` ) then
this is the usual left or right quotient of a group by a subgroup.
## Main definitions
* `rel`: The double coset relation defined by two subgroups `H K` of `G`.
* `double_coset.quotient`: The quotient of `G` by the double coset relation, i.e, ``H \ G / K`.
-/
variables {G : Type*} [group G] {α : Type*} [has_mul α] (J: subgroup G) (g : G)
namespace doset
open_locale pointwise
/--The double_coset as an element of `set α` corresponding to `s a t` -/
def _root_.doset (a : α) (s t : set α) : set α := s * {a} * t
lemma mem_doset {s t : set α} {a b : α} : b ∈ doset a s t ↔ ∃ (x ∈ s) (y ∈ t), b = x * a * y :=
⟨λ ⟨_, y, ⟨x, _, hx, rfl, rfl⟩, hy, h⟩, ⟨x, hx, y, hy, h.symm⟩,
λ ⟨x, hx, y, hy, h⟩, ⟨x * a, y, ⟨x, a, hx, rfl, rfl⟩, hy, h.symm⟩⟩
lemma mem_doset_self (H K : subgroup G) (a : G) : a ∈ doset a H K :=
mem_doset.mpr ⟨1, H.one_mem, 1, K.one_mem, (one_mul a).symm.trans (mul_one (1 * a)).symm⟩
lemma doset_eq_of_mem {H K : subgroup G} {a b : G} (hb : b ∈ doset a H K) :
doset b H K = doset a H K :=
begin
obtain ⟨_, k, ⟨h, a, hh, (rfl : _ = _), rfl⟩, hk, rfl⟩ := hb,
rw [doset, doset, ←set.singleton_mul_singleton, ←set.singleton_mul_singleton, mul_assoc,
mul_assoc, subgroup.singleton_mul_subgroup hk, ←mul_assoc, ←mul_assoc,
subgroup.subgroup_mul_singleton hh],
end
lemma mem_doset_of_not_disjoint {H K : subgroup G} {a b : G}
(h : ¬ disjoint (doset a H K) (doset b H K)) : b ∈ doset a H K :=
begin
rw set.not_disjoint_iff at h,
simp only [mem_doset] at *,
obtain ⟨x, ⟨l, hl, r, hr, hrx⟩, y, hy, ⟨r', hr', rfl⟩⟩ := h,
refine ⟨y⁻¹ * l, H.mul_mem (H.inv_mem hy) (hl), r * r'⁻¹, K.mul_mem hr (K.inv_mem hr'), _⟩,
rwa [mul_assoc, mul_assoc, eq_inv_mul_iff_mul_eq, ←mul_assoc, ←mul_assoc, eq_mul_inv_iff_mul_eq],
end
lemma eq_of_not_disjoint {H K : subgroup G} {a b : G} (h: ¬ disjoint (doset a H K) (doset b H K)) :
doset a H K = doset b H K :=
begin
rw disjoint.comm at h,
have ha : a ∈ doset b H K := mem_doset_of_not_disjoint h,
apply doset_eq_of_mem ha,
end
/-- The setoid defined by the double_coset relation -/
def setoid (H K : set G) : setoid G :=
setoid.ker (λ x, doset x H K)
/-- Quotient of `G` by the double coset relation, i.e. `H \ G / K` -/
def quotient (H K : set G) : Type* :=
quotient (setoid H K)
lemma rel_iff {H K : subgroup G} {x y : G} :
(setoid ↑H ↑K).rel x y ↔ ∃ (a ∈ H) (b ∈ K), y = a * x * b :=
iff.trans ⟨λ hxy, (congr_arg _ hxy).mpr (mem_doset_self H K y),
λ hxy, (doset_eq_of_mem hxy).symm⟩ mem_doset
lemma bot_rel_eq_left_rel (H : subgroup G) :
(setoid ↑(⊥ : subgroup G) ↑H).rel = (quotient_group.left_rel H).rel :=
begin
ext a b,
rw [rel_iff, setoid.rel, quotient_group.left_rel_apply],
split,
{ rintros ⟨a, (rfl : a = 1), b, hb, rfl⟩,
change a⁻¹ * (1 * a * b) ∈ H,
rwa [one_mul, inv_mul_cancel_left] },
{ rintro (h : a⁻¹ * b ∈ H),
exact ⟨1, rfl, a⁻¹ * b, h, by rw [one_mul, mul_inv_cancel_left]⟩ },
end
lemma rel_bot_eq_right_group_rel (H : subgroup G) :
(setoid ↑H ↑(⊥ : subgroup G)).rel = (quotient_group.right_rel H).rel :=
begin
ext a b,
rw [rel_iff, setoid.rel, quotient_group.right_rel_apply],
split,
{ rintros ⟨b, hb, a, (rfl : a = 1), rfl⟩,
change b * a * 1 * a⁻¹ ∈ H,
rwa [mul_one, mul_inv_cancel_right] },
{ rintro (h : b * a⁻¹ ∈ H),
exact ⟨b * a⁻¹, h, 1, rfl, by rw [mul_one, inv_mul_cancel_right]⟩ },
end
/--Create a doset out of an element of `H \ G / K`-/
def quot_to_doset (H K : subgroup G) (q : quotient ↑H ↑K) : set G := (doset q.out' H K)
/--Map from `G` to `H \ G / K`-/
abbreviation mk (H K : subgroup G) (a : G) : quotient ↑H ↑K :=
quotient.mk' a
instance (H K : subgroup G) : inhabited (quotient ↑H ↑K) := ⟨mk H K (1 : G)⟩
lemma eq (H K : subgroup G) (a b : G) : mk H K a = mk H K b ↔ ∃ (h ∈ H) (k ∈ K), b = h * a * k :=
by { rw quotient.eq', apply rel_iff, }
lemma out_eq' (H K : subgroup G) (q : quotient ↑H ↑K) : mk H K q.out' = q :=
quotient.out_eq' q
lemma mk_out'_eq_mul (H K : subgroup G) (g : G) :
∃ (h k : G), (h ∈ H) ∧ (k ∈ K) ∧ (mk H K g : quotient ↑H ↑K).out' = h * g * k :=
begin
have := eq H K (mk H K g : quotient ↑H ↑K).out' g,
rw out_eq' at this,
obtain ⟨h, h_h, k, hk, T⟩ := this.1 rfl,
refine ⟨h⁻¹, k⁻¹, (H.inv_mem h_h), K.inv_mem hk, eq_mul_inv_of_mul_eq (eq_inv_mul_of_mul_eq _)⟩,
rw [← mul_assoc, ← T]
end
lemma mk_eq_of_doset_eq {H K : subgroup G} {a b : G} (h : doset a H K = doset b H K) :
mk H K a = mk H K b :=
begin
rw eq,
exact mem_doset.mp (h.symm ▸ mem_doset_self H K b)
end
lemma disjoint_out' {H K : subgroup G} {a b : quotient H.1 K} :
a ≠ b → disjoint (doset a.out' H K) (doset b.out' H K) :=
begin
contrapose!,
intro h,
simpa [out_eq'] using mk_eq_of_doset_eq (eq_of_not_disjoint h),
end
lemma union_quot_to_doset (H K : subgroup G) : (⋃ q, quot_to_doset H K q) = set.univ :=
begin
ext x,
simp only [set.mem_Union, quot_to_doset, mem_doset, set_like.mem_coe, exists_prop,
set.mem_univ, iff_true],
use mk H K x,
obtain ⟨h, k, h3, h4, h5⟩ := mk_out'_eq_mul H K x,
refine ⟨h⁻¹, H.inv_mem h3, k⁻¹, K.inv_mem h4, _⟩,
simp only [h5, subgroup.coe_mk, ←mul_assoc, one_mul, mul_left_inv, mul_inv_cancel_right],
end
lemma doset_union_right_coset (H K : subgroup G) (a : G) :
(⋃ (k : K), right_coset ↑H (a * k)) = doset a H K :=
begin
ext x,
simp only [mem_right_coset_iff, exists_prop, mul_inv_rev, set.mem_Union, mem_doset,
subgroup.mem_carrier, set_like.mem_coe],
split,
{rintro ⟨y, h_h⟩,
refine ⟨x * (y⁻¹ * a⁻¹), h_h, y, y.2, _⟩,
simp only [← mul_assoc, subgroup.coe_mk, inv_mul_cancel_right]},
{rintros ⟨x, hx, y, hy, hxy⟩,
refine ⟨⟨y,hy⟩,_⟩,
simp only [hxy, ←mul_assoc, hx, mul_inv_cancel_right, subgroup.coe_mk]},
end
lemma doset_union_left_coset (H K : subgroup G) (a : G) :
(⋃ (h : H), left_coset (h * a : G) K) = doset a H K :=
begin
ext x,
simp only [mem_left_coset_iff, mul_inv_rev, set.mem_Union, mem_doset],
split,
{ rintro ⟨y, h_h⟩,
refine ⟨y, y.2, a⁻¹ * y⁻¹ * x, h_h, _⟩,
simp only [←mul_assoc, one_mul, mul_right_inv, mul_inv_cancel_right]},
{ rintros ⟨x, hx, y, hy, hxy⟩,
refine ⟨⟨x, hx⟩, _⟩,
simp only [hxy, ←mul_assoc, hy, one_mul, mul_left_inv, subgroup.coe_mk, inv_mul_cancel_right]},
end
lemma left_bot_eq_left_quot (H : subgroup G) :
quotient (⊥ : subgroup G).1 H = (G ⧸ H) :=
begin
unfold quotient,
congr,
ext,
simp_rw ← bot_rel_eq_left_rel H,
refl,
end
lemma right_bot_eq_right_quot (H : subgroup G) :
quotient H.1 (⊥ : subgroup G) = _root_.quotient (quotient_group.right_rel H) :=
begin
unfold quotient,
congr,
ext,
simp_rw ← rel_bot_eq_right_group_rel H,
refl,
end
end doset
|
650474ad1a50ae7eb5ec02e7e6531c915db33ecd | 94e33a31faa76775069b071adea97e86e218a8ee | /src/analysis/normed_space/completion.lean | 8a7821cbcd9d48fb3fb7250a56e8f13dedc62283 | [
"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 | 2,120 | lean | /-
Copyright (c) 2022 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import analysis.normed.group.completion
import analysis.normed_space.operator_norm
import topology.algebra.uniform_mul_action
/-!
# Normed space structure on the completion of a normed space
If `E` is a normed space over `𝕜`, then so is `uniform_space.completion E`. In this file we provide
necessary instances and define `uniform_space.completion.to_complₗᵢ` - coercion
`E → uniform_space.completion E` as a bundled linear isometry.
-/
noncomputable theory
namespace uniform_space
namespace completion
variables (𝕜 E : Type*) [normed_field 𝕜] [normed_group E] [normed_space 𝕜 E]
@[priority 100]
instance normed_space.to_has_uniform_continuous_const_smul :
has_uniform_continuous_const_smul 𝕜 E :=
⟨λ c, (lipschitz_with_smul c).uniform_continuous⟩
instance : normed_space 𝕜 (completion E) :=
{ smul := (•),
norm_smul_le := λ c x, induction_on x
(is_closed_le (continuous_const_smul _).norm (continuous_const.mul continuous_norm)) $
λ y, by simp only [← coe_smul, norm_coe, norm_smul],
.. completion.module }
variables {𝕜 E}
/-- Embedding of a normed space to its completion as a linear isometry. -/
def to_complₗᵢ : E →ₗᵢ[𝕜] completion E :=
{ to_fun := coe,
map_smul' := coe_smul,
norm_map' := norm_coe,
.. to_compl }
@[simp] lemma coe_to_complₗᵢ : ⇑(to_complₗᵢ : E →ₗᵢ[𝕜] completion E) = coe := rfl
/-- Embedding of a normed space to its completion as a continuous linear map. -/
def to_complL : E →L[𝕜] completion E :=
to_complₗᵢ.to_continuous_linear_map
@[simp] lemma coe_to_complL : ⇑(to_complL : E →L[𝕜] completion E) = coe := rfl
@[simp] lemma norm_to_complL {𝕜 E : Type*} [nondiscrete_normed_field 𝕜]
[normed_group E] [normed_space 𝕜 E] [nontrivial E] : ∥(to_complL : E →L[𝕜] completion E)∥ = 1 :=
(to_complₗᵢ : E →ₗᵢ[𝕜] completion E).norm_to_continuous_linear_map
end completion
end uniform_space
|
0118bb22e8cb85524e2d558e951b2ce5960e7fc3 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/group/ulift_auto.lean | ddd7d4e580ba6038101568f23218f334ef0188a7 | [] | 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 | 3,032 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.equiv.mul_add
import Mathlib.PostPort
universes u u_1 v
namespace Mathlib
/-!
# `ulift` instances for groups and monoids
This file defines instances for group, monoid, semigroup and related structures on `ulift` types.
(Recall `ulift α` is just a "copy" of a type `α` in a higher universe.)
We use `tactic.pi_instance_derive_field`, even though it wasn't intended for this purpose,
which seems to work fine.
We also provide `ulift.mul_equiv : ulift R ≃* R` (and its additive analogue).
-/
namespace ulift
protected instance has_one {α : Type u} [HasOne α] : HasOne (ulift α) := { one := up 1 }
@[simp] theorem one_down {α : Type u} [HasOne α] : down 1 = 1 := rfl
protected instance has_mul {α : Type u} [Mul α] : Mul (ulift α) :=
{ mul := fun (f g : ulift α) => up (down f * down g) }
@[simp] theorem add_down {α : Type u} {x : ulift α} {y : ulift α} [Add α] :
down (x + y) = down x + down y :=
rfl
protected instance has_sub {α : Type u} [Sub α] : Sub (ulift α) :=
{ sub := fun (f g : ulift α) => up (down f - down g) }
@[simp] theorem sub_down {α : Type u} {x : ulift α} {y : ulift α} [Sub α] :
down (x - y) = down x - down y :=
rfl
protected instance has_inv {α : Type u} [has_inv α] : has_inv (ulift α) :=
has_inv.mk fun (f : ulift α) => up (down f⁻¹)
@[simp] theorem neg_down {α : Type u} {x : ulift α} [Neg α] : down (-x) = -down x := rfl
protected instance add_semigroup {α : Type u} [add_semigroup α] : add_semigroup (ulift α) :=
add_semigroup.mk Add.add sorry
/--
The multiplicative equivalence between `ulift α` and `α`.
-/
def mul_equiv {α : Type u} [semigroup α] : ulift α ≃* α := mul_equiv.mk down up sorry sorry sorry
protected instance add_comm_semigroup {α : Type u} [add_comm_semigroup α] :
add_comm_semigroup (ulift α) :=
add_comm_semigroup.mk Add.add sorry sorry
protected instance monoid {α : Type u} [monoid α] : monoid (ulift α) :=
monoid.mk Mul.mul sorry 1 sorry sorry
protected instance comm_monoid {α : Type u} [comm_monoid α] : comm_monoid (ulift α) :=
comm_monoid.mk Mul.mul sorry 1 sorry sorry sorry
protected instance group {α : Type u} [group α] : group (ulift α) :=
group.mk Mul.mul sorry 1 sorry sorry has_inv.inv Div.div sorry
protected instance comm_group {α : Type u} [comm_group α] : comm_group (ulift α) :=
comm_group.mk Mul.mul sorry 1 sorry sorry has_inv.inv Div.div sorry sorry
protected instance left_cancel_semigroup {α : Type u} [left_cancel_semigroup α] :
left_cancel_semigroup (ulift α) :=
left_cancel_semigroup.mk Mul.mul sorry sorry
protected instance right_cancel_semigroup {α : Type u} [right_cancel_semigroup α] :
right_cancel_semigroup (ulift α) :=
right_cancel_semigroup.mk Mul.mul sorry sorry
end Mathlib |
779332169462052828f055ce9b824d3bfeef5471 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/algebra/gcd_monoid/basic.lean | cc512243c8d92a9e514f608465449f4a43fdfce0 | [
"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 | 34,653 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker
-/
import algebra.associated
import algebra.group_power.lemmas
import data.nat.gcd
/-!
# Monoids with normalization functions, `gcd`, and `lcm`
This file defines extra structures on `comm_cancel_monoid_with_zero`s, including `integral_domain`s.
## Main Definitions
* `normalization_monoid`
* `gcd_monoid`
* `gcd_monoid_of_exists_gcd`
* `gcd_monoid_of_exists_lcm`
For the `gcd_monoid` instances on `ℕ` and `ℤ`, see `ring_theory.int.basic`.
## Implementation Notes
* `normalization_monoid` is defined by assigning to each element a `norm_unit` such that multiplying
by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This
definition as currently implemented does casework on `0`.
* `gcd_monoid` extends `normalization_monoid`, so the `gcd` and `lcm` are always normalized.
This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains, and monoids
without zero.
* `gcd_monoid_of_gcd` noncomputably constructs a `gcd_monoid` structure just from the `gcd`
and its properties.
* `gcd_monoid_of_exists_gcd` noncomputably constructs a `gcd_monoid` structure just from a proof
that any two elements have a (not necessarily normalized) `gcd`.
* `gcd_monoid_of_lcm` noncomputably constructs a `gcd_monoid` structure just from the `lcm`
and its properties.
* `gcd_monoid_of_exists_lcm` noncomputably constructs a `gcd_monoid` structure just from a proof
that any two elements have a (not necessarily normalized) `lcm`.
## TODO
* Port GCD facts about nats, definition of coprime
* Generalize normalization monoids to commutative (cancellative) monoids with or without zero
* Generalize GCD monoid to not require normalization in all cases
## Tags
divisibility, gcd, lcm, normalize
-/
variables {α : Type*}
set_option old_structure_cmd true
/-- Normalization monoid: multiplying with `norm_unit` gives a normal form for associated
elements. -/
@[protect_proj] class normalization_monoid (α : Type*) [nontrivial α]
[comm_cancel_monoid_with_zero α] :=
(norm_unit : α → units α)
(norm_unit_zero : norm_unit 0 = 1)
(norm_unit_mul : ∀{a b}, a ≠ 0 → b ≠ 0 → norm_unit (a * b) = norm_unit a * norm_unit b)
(norm_unit_coe_units : ∀(u : units α), norm_unit u = u⁻¹)
export normalization_monoid (norm_unit norm_unit_zero norm_unit_mul norm_unit_coe_units)
attribute [simp] norm_unit_coe_units norm_unit_zero norm_unit_mul
section normalization_monoid
variables [comm_cancel_monoid_with_zero α] [nontrivial α] [normalization_monoid α]
@[simp] theorem norm_unit_one : norm_unit (1:α) = 1 :=
norm_unit_coe_units 1
/-- Chooses an element of each associate class, by multiplying by `norm_unit` -/
def normalize : monoid_with_zero_hom α α :=
{ to_fun := λ x, x * norm_unit x,
map_zero' := by simp,
map_one' := by rw [norm_unit_one, units.coe_one, mul_one],
map_mul' := λ x y,
classical.by_cases (λ hx : x = 0, by rw [hx, zero_mul, zero_mul, zero_mul]) $ λ hx,
classical.by_cases (λ hy : y = 0, by rw [hy, mul_zero, zero_mul, mul_zero]) $ λ hy,
by simp only [norm_unit_mul hx hy, units.coe_mul]; simp only [mul_assoc, mul_left_comm y], }
theorem associated_normalize (x : α) : associated x (normalize x) :=
⟨_, rfl⟩
theorem normalize_associated (x : α) : associated (normalize x) x :=
(associated_normalize _).symm
lemma associates.mk_normalize (x : α) : associates.mk (normalize x) = associates.mk x :=
associates.mk_eq_mk_iff_associated.2 (normalize_associated _)
@[simp] lemma normalize_apply (x : α) : normalize x = x * norm_unit x := rfl
@[simp] lemma normalize_zero : normalize (0 : α) = 0 := normalize.map_zero
@[simp] lemma normalize_one : normalize (1 : α) = 1 := normalize.map_one
lemma normalize_coe_units (u : units α) : normalize (u : α) = 1 := by simp
lemma normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 :=
⟨λ hx, (associated_zero_iff_eq_zero x).1 $ hx ▸ associated_normalize _,
by rintro rfl; exact normalize_zero⟩
lemma normalize_eq_one {x : α} : normalize x = 1 ↔ is_unit x :=
⟨λ hx, is_unit_iff_exists_inv.2 ⟨_, hx⟩, λ ⟨u, hu⟩, hu ▸ normalize_coe_units u⟩
@[simp] theorem norm_unit_mul_norm_unit (a : α) : norm_unit (a * norm_unit a) = 1 :=
classical.by_cases (assume : a = 0, by simp only [this, norm_unit_zero, zero_mul]) $
assume h, by rw [norm_unit_mul h (units.ne_zero _), norm_unit_coe_units, mul_inv_eq_one]
theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp
theorem normalize_eq_normalize {a b : α}
(hab : a ∣ b) (hba : b ∣ a) : normalize a = normalize b :=
begin
rcases associated_of_dvd_dvd hab hba with ⟨u, rfl⟩,
refine classical.by_cases (by rintro rfl; simp only [zero_mul]) (assume ha : a ≠ 0, _),
suffices : a * ↑(norm_unit a) = a * ↑u * ↑(norm_unit a) * ↑u⁻¹,
by simpa only [normalize_apply, mul_assoc, norm_unit_mul ha u.ne_zero, norm_unit_coe_units],
calc a * ↑(norm_unit a) = a * ↑(norm_unit a) * ↑u * ↑u⁻¹:
(units.mul_inv_cancel_right _ _).symm
... = a * ↑u * ↑(norm_unit a) * ↑u⁻¹ : by rw mul_right_comm a
end
lemma normalize_eq_normalize_iff {x y : α} : normalize x = normalize y ↔ x ∣ y ∧ y ∣ x :=
⟨λ h, ⟨units.dvd_mul_right.1 ⟨_, h.symm⟩, units.dvd_mul_right.1 ⟨_, h⟩⟩,
λ ⟨hxy, hyx⟩, normalize_eq_normalize hxy hyx⟩
theorem dvd_antisymm_of_normalize_eq {a b : α}
(ha : normalize a = a) (hb : normalize b = b) (hab : a ∣ b) (hba : b ∣ a) :
a = b :=
ha ▸ hb ▸ normalize_eq_normalize hab hba
--can be proven by simp
lemma dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b :=
units.dvd_mul_right
--can be proven by simp
lemma normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b :=
units.mul_right_dvd
end normalization_monoid
namespace comm_group_with_zero
variables [decidable_eq α] [comm_group_with_zero α]
@[priority 100] -- see Note [lower instance priority]
instance : normalization_monoid α :=
{ norm_unit := λ x, if h : x = 0 then 1 else (units.mk0 x h)⁻¹,
norm_unit_zero := dif_pos rfl,
norm_unit_mul := λ x y x0 y0, units.eq_iff.1 (by simp [x0, y0, mul_comm]),
norm_unit_coe_units := λ u, by { rw [dif_neg (units.ne_zero _), units.mk0_coe], apply_instance } }
@[simp]
lemma coe_norm_unit {a : α} (h0 : a ≠ 0) : (↑(norm_unit a) : α) = a⁻¹ :=
by simp [norm_unit, h0]
end comm_group_with_zero
namespace associates
variables [comm_cancel_monoid_with_zero α] [nontrivial α] [normalization_monoid α]
local attribute [instance] associated.setoid
/-- Maps an element of `associates` back to the normalized element of its associate class -/
protected def out : associates α → α :=
quotient.lift (normalize : α → α) $ λ a b ⟨u, hu⟩, hu ▸
normalize_eq_normalize ⟨_, rfl⟩ (units.mul_right_dvd.2 $ dvd_refl a)
lemma out_mk (a : α) : (associates.mk a).out = normalize a := rfl
@[simp] lemma out_one : (1 : associates α).out = 1 :=
normalize_one
lemma out_mul (a b : associates α) : (a * b).out = a.out * b.out :=
quotient.induction_on₂ a b $ assume a b,
by simp only [associates.quotient_mk_eq_mk, out_mk, mk_mul_mk, normalize.map_mul]
lemma dvd_out_iff (a : α) (b : associates α) : a ∣ b.out ↔ associates.mk a ≤ b :=
quotient.induction_on b $
by simp [associates.out_mk, associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd_iff]
lemma out_dvd_iff (a : α) (b : associates α) : b.out ∣ a ↔ b ≤ associates.mk a :=
quotient.induction_on b $
by simp [associates.out_mk, associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd_iff]
@[simp] lemma out_top : (⊤ : associates α).out = 0 :=
normalize_zero
@[simp] lemma normalize_out (a : associates α) : normalize a.out = a.out :=
quotient.induction_on a normalize_idem
end associates
/-- GCD monoid: a `comm_cancel_monoid_with_zero` with normalization and `gcd`
(greatest common divisor) and `lcm` (least common multiple) operations. In this setting `gcd` and
`lcm` form a bounded lattice on the associated elements where `gcd` is the infimum, `lcm` is the
supremum, `1` is bottom, and `0` is top. The type class focuses on `gcd` and we derive the
corresponding `lcm` facts from `gcd`.
-/
@[protect_proj] class gcd_monoid (α : Type*) [comm_cancel_monoid_with_zero α] [nontrivial α]
extends normalization_monoid α :=
(gcd : α → α → α)
(lcm : α → α → α)
(gcd_dvd_left : ∀a b, gcd a b ∣ a)
(gcd_dvd_right : ∀a b, gcd a b ∣ b)
(dvd_gcd : ∀{a b c}, a ∣ c → a ∣ b → a ∣ gcd c b)
(normalize_gcd : ∀a b, normalize (gcd a b) = gcd a b)
(gcd_mul_lcm : ∀a b, gcd a b * lcm a b = normalize (a * b))
(lcm_zero_left : ∀a, lcm 0 a = 0)
(lcm_zero_right : ∀a, lcm a 0 = 0)
export gcd_monoid (gcd lcm gcd_dvd_left gcd_dvd_right dvd_gcd lcm_zero_left lcm_zero_right)
attribute [simp] lcm_zero_left lcm_zero_right
section gcd_monoid
variables [comm_cancel_monoid_with_zero α] [nontrivial α] [gcd_monoid α]
@[simp] theorem normalize_gcd : ∀a b:α, normalize (gcd a b) = gcd a b :=
gcd_monoid.normalize_gcd
@[simp] theorem gcd_mul_lcm : ∀a b:α, gcd a b * lcm a b = normalize (a * b) :=
gcd_monoid.gcd_mul_lcm
section gcd
theorem dvd_gcd_iff (a b c : α) : a ∣ gcd b c ↔ (a ∣ b ∧ a ∣ c) :=
iff.intro
(assume h, ⟨h.trans (gcd_dvd_left _ _), h.trans (gcd_dvd_right _ _)⟩)
(assume ⟨hab, hac⟩, dvd_gcd hab hac)
theorem gcd_comm (a b : α) : gcd a b = gcd b a :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
(dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _))
theorem gcd_assoc (m n k : α) : gcd (gcd m n) k = gcd m (gcd n k) :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(dvd_gcd
((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n))
(dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n))
(gcd_dvd_right (gcd m n) k)))
(dvd_gcd
(dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k)))
((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k)))
instance : is_commutative α gcd := ⟨gcd_comm⟩
instance : is_associative α gcd := ⟨gcd_assoc⟩
theorem gcd_eq_normalize {a b c : α} (habc : gcd a b ∣ c) (hcab : c ∣ gcd a b) :
gcd a b = normalize c :=
normalize_gcd a b ▸ normalize_eq_normalize habc hcab
@[simp] theorem gcd_zero_left (a : α) : gcd 0 a = normalize a :=
gcd_eq_normalize (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a))
@[simp] theorem gcd_zero_right (a : α) : gcd a 0 = normalize a :=
gcd_eq_normalize (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _))
@[simp] theorem gcd_eq_zero_iff (a b : α) : gcd a b = 0 ↔ a = 0 ∧ b = 0 :=
iff.intro
(assume h, let ⟨ca, ha⟩ := gcd_dvd_left a b, ⟨cb, hb⟩ := gcd_dvd_right a b in
by rw [h, zero_mul] at ha hb; exact ⟨ha, hb⟩)
(assume ⟨ha, hb⟩, by rw [ha, hb, gcd_zero_left, normalize_zero])
@[simp] theorem gcd_one_left (a : α) : gcd 1 a = 1 :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_left _ _) (one_dvd _)
@[simp] theorem gcd_one_right (a : α) : gcd a 1 = 1 :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_right _ _) (one_dvd _)
theorem gcd_dvd_gcd {a b c d: α} (hab : a ∣ b) (hcd : c ∣ d) : gcd a c ∣ gcd b d :=
dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd)
@[simp] theorem gcd_same (a : α) : gcd a a = normalize a :=
gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a))
@[simp] theorem gcd_mul_left (a b c : α) : gcd (a * b) (a * c) = normalize a * gcd b c :=
classical.by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero]) $
assume ha : a ≠ 0,
suffices gcd (a * b) (a * c) = normalize (a * gcd b c),
by simpa only [normalize.map_mul, normalize_gcd],
let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) in
gcd_eq_normalize
(eq.symm ▸ mul_dvd_mul_left a $ show d ∣ gcd b c, from
dvd_gcd
((mul_dvd_mul_iff_left ha).1 $ eq ▸ gcd_dvd_left _ _)
((mul_dvd_mul_iff_left ha).1 $ eq ▸ gcd_dvd_right _ _))
(dvd_gcd
(mul_dvd_mul_left a $ gcd_dvd_left _ _)
(mul_dvd_mul_left a $ gcd_dvd_right _ _))
@[simp] theorem gcd_mul_right (a b c : α) : gcd (b * a) (c * a) = gcd b c * normalize a :=
by simp only [mul_comm, gcd_mul_left]
theorem gcd_eq_left_iff (a b : α) (h : normalize a = a) : gcd a b = a ↔ a ∣ b :=
iff.intro (assume eq, eq ▸ gcd_dvd_right _ _) $
assume hab, dvd_antisymm_of_normalize_eq (normalize_gcd _ _) h (gcd_dvd_left _ _)
(dvd_gcd (dvd_refl a) hab)
theorem gcd_eq_right_iff (a b : α) (h : normalize b = b) : gcd a b = b ↔ b ∣ a :=
by simpa only [gcd_comm a b] using gcd_eq_left_iff b a h
theorem gcd_dvd_gcd_mul_left (m n k : α) : gcd m n ∣ gcd (k * m) n :=
gcd_dvd_gcd (dvd_mul_left _ _) dvd_rfl
theorem gcd_dvd_gcd_mul_right (m n k : α) : gcd m n ∣ gcd (m * k) n :=
gcd_dvd_gcd (dvd_mul_right _ _) dvd_rfl
theorem gcd_dvd_gcd_mul_left_right (m n k : α) : gcd m n ∣ gcd m (k * n) :=
gcd_dvd_gcd dvd_rfl (dvd_mul_left _ _)
theorem gcd_dvd_gcd_mul_right_right (m n k : α) : gcd m n ∣ gcd m (n * k) :=
gcd_dvd_gcd dvd_rfl (dvd_mul_right _ _)
theorem associated.gcd_eq_left {m n : α} (h : associated m n) (k : α) : gcd m k = gcd n k :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(gcd_dvd_gcd h.dvd dvd_rfl)
(gcd_dvd_gcd h.symm.dvd dvd_rfl)
theorem associated.gcd_eq_right {m n : α} (h : associated m n) (k : α) : gcd k m = gcd k n :=
dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _)
(gcd_dvd_gcd dvd_rfl h.dvd)
(gcd_dvd_gcd dvd_rfl h.symm.dvd)
lemma dvd_gcd_mul_of_dvd_mul {m n k : α} (H : k ∣ m * n) : k ∣ (gcd k m) * n :=
begin
transitivity gcd k m * normalize n,
{ rw ← gcd_mul_right,
exact dvd_gcd (dvd_mul_right _ _) H },
{ apply dvd.intro ↑(norm_unit n)⁻¹,
rw [normalize_apply, mul_assoc, mul_assoc, ← units.coe_mul],
simp }
end
lemma dvd_mul_gcd_of_dvd_mul {m n k : α} (H : k ∣ m * n) : k ∣ m * gcd k n :=
by { rw mul_comm at H ⊢, exact dvd_gcd_mul_of_dvd_mul H }
/-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`.
Note: In general, this representation is highly non-unique. -/
lemma exists_dvd_and_dvd_of_dvd_mul {m n k : α} (H : k ∣ m * n) :
∃ d₁ (hd₁ : d₁ ∣ m) d₂ (hd₂ : d₂ ∣ n), k = d₁ * d₂ :=
begin
by_cases h0 : gcd k m = 0,
{ rw gcd_eq_zero_iff at h0,
rcases h0 with ⟨rfl, rfl⟩,
refine ⟨0, dvd_refl 0, n, dvd_refl n, _⟩,
simp },
{ obtain ⟨a, ha⟩ := gcd_dvd_left k m,
refine ⟨gcd k m, gcd_dvd_right _ _, a, _, ha⟩,
suffices h : gcd k m * a ∣ gcd k m * n,
{ cases h with b hb,
use b,
rw mul_assoc at hb,
apply mul_left_cancel₀ h0 hb },
rw ← ha,
exact dvd_gcd_mul_of_dvd_mul H }
end
theorem gcd_mul_dvd_mul_gcd (k m n : α) : gcd k (m * n) ∣ gcd k m * gcd k n :=
begin
obtain ⟨m', hm', n', hn', h⟩ := (exists_dvd_and_dvd_of_dvd_mul $ gcd_dvd_right k (m * n)),
replace h : gcd k (m * n) = m' * n' := h,
rw h,
have hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _,
apply mul_dvd_mul,
{ have hm'k : m' ∣ k := (dvd_mul_right m' n').trans hm'n',
exact dvd_gcd hm'k hm' },
{ have hn'k : n' ∣ k := (dvd_mul_left n' m').trans hm'n',
exact dvd_gcd hn'k hn' }
end
theorem gcd_pow_right_dvd_pow_gcd {a b : α} {k : ℕ} : gcd a (b ^ k) ∣ (gcd a b) ^ k :=
begin
by_cases hg : gcd a b = 0,
{ rw gcd_eq_zero_iff at hg,
rcases hg with ⟨rfl, rfl⟩,
simp },
{ induction k with k hk, simp,
rw [pow_succ, pow_succ],
transitivity gcd a b * gcd a (b ^ k),
apply gcd_mul_dvd_mul_gcd a b (b ^ k),
refine (mul_dvd_mul_iff_left hg).mpr hk }
end
theorem gcd_pow_left_dvd_pow_gcd {a b : α} {k : ℕ} : gcd (a ^ k) b ∣ (gcd a b) ^ k :=
by { rw [gcd_comm, gcd_comm a b], exact gcd_pow_right_dvd_pow_gcd }
theorem pow_dvd_of_mul_eq_pow {a b c d₁ d₂ : α} (ha : a ≠ 0)
(hab : gcd a b = 1) {k : ℕ} (h : a * b = c ^ k) (hc : c = d₁ * d₂)
(hd₁ : d₁ ∣ a) : d₁ ^ k ≠ 0 ∧ d₁ ^ k ∣ a :=
begin
have h1 : gcd (d₁ ^ k) b = 1,
{ rw ← normalize_gcd (d₁ ^ k) b, rw normalize_eq_one,
apply is_unit_of_dvd_one,
transitivity (gcd d₁ b) ^ k,
{ exact gcd_pow_left_dvd_pow_gcd },
{ apply is_unit.dvd, apply is_unit.pow, apply is_unit_of_dvd_one,
rw ← hab, apply gcd_dvd_gcd hd₁ (dvd_refl b) } },
have h2 : d₁ ^ k ∣ a * b, { use d₂ ^ k, rw [h, hc], exact mul_pow d₁ d₂ k },
rw mul_comm at h2,
have h3 : d₁ ^ k ∣ a, { rw [← one_mul a, ← h1], apply dvd_gcd_mul_of_dvd_mul h2 },
have h4 : d₁ ^ k ≠ 0,
{ intro hdk, rw hdk at h3, apply absurd (zero_dvd_iff.mp h3) ha },
tauto
end
theorem exists_associated_pow_of_mul_eq_pow {a b c : α} (hab : gcd a b = 1) {k : ℕ}
(h : a * b = c ^ k) : ∃ (d : α), associated (d ^ k) a :=
begin
by_cases ha : a = 0,
{ use 0, rw ha,
obtain (rfl | hk) := k.eq_zero_or_pos,
{ exfalso, revert h, rw [ha, zero_mul, pow_zero], apply zero_ne_one },
{ rw zero_pow hk } },
by_cases hb : b = 0,
{ rw [hb, gcd_zero_right] at hab, use 1, rw one_pow,
apply (associated_one_iff_is_unit.mpr (normalize_eq_one.mp hab)).symm },
obtain (rfl | hk) := k.eq_zero_or_pos,
{ use 1, rw pow_zero at h ⊢, use units.mk_of_mul_eq_one _ _ h,
rw [units.coe_mk_of_mul_eq_one, one_mul] },
have hc : c ∣ a * b, { rw h, exact dvd_pow_self _ hk.ne' },
obtain ⟨d₁, hd₁, d₂, hd₂, hc⟩ := exists_dvd_and_dvd_of_dvd_mul hc,
use d₁,
obtain ⟨h0₁, ⟨a', ha'⟩⟩ := pow_dvd_of_mul_eq_pow ha hab h hc hd₁,
rw [mul_comm] at h hc, rw [gcd_comm] at hab,
obtain ⟨h0₂, ⟨b', hb'⟩⟩ := pow_dvd_of_mul_eq_pow hb hab h hc hd₂,
rw [ha', hb', hc, mul_pow] at h,
have h' : a' * b' = 1,
{ apply (mul_right_inj' h0₁).mp, rw mul_one,
apply (mul_right_inj' h0₂).mp, rw ← h,
rw [mul_assoc, mul_comm a', ← mul_assoc _ b', ← mul_assoc b', mul_comm b'] },
use units.mk_of_mul_eq_one _ _ h',
rw [units.coe_mk_of_mul_eq_one, ha']
end
end gcd
section lcm
lemma lcm_dvd_iff {a b c : α} : lcm a b ∣ c ↔ a ∣ c ∧ b ∣ c :=
classical.by_cases
(assume : a = 0 ∨ b = 0, by rcases this with rfl | rfl;
simp only [iff_def, lcm_zero_left, lcm_zero_right, zero_dvd_iff, dvd_zero,
eq_self_iff_true, and_true, imp_true_iff] {contextual:=tt})
(assume this : ¬ (a = 0 ∨ b = 0),
let ⟨h1, h2⟩ := not_or_distrib.1 this in
have h : gcd a b ≠ 0, from λ H, h1 ((gcd_eq_zero_iff _ _).1 H).1,
by rw [← mul_dvd_mul_iff_left h, gcd_mul_lcm, normalize_dvd_iff, ← dvd_normalize_iff,
normalize.map_mul, normalize_gcd, ← gcd_mul_right, dvd_gcd_iff,
mul_comm b c, mul_dvd_mul_iff_left h1, mul_dvd_mul_iff_right h2, and_comm])
lemma dvd_lcm_left (a b : α) : a ∣ lcm a b := (lcm_dvd_iff.1 dvd_rfl).1
lemma dvd_lcm_right (a b : α) : b ∣ lcm a b := (lcm_dvd_iff.1 dvd_rfl).2
lemma lcm_dvd {a b c : α} (hab : a ∣ b) (hcb : c ∣ b) : lcm a c ∣ b :=
lcm_dvd_iff.2 ⟨hab, hcb⟩
@[simp] theorem lcm_eq_zero_iff (a b : α) : lcm a b = 0 ↔ a = 0 ∨ b = 0 :=
iff.intro
(assume h : lcm a b = 0,
have normalize (a * b) = 0,
by rw [← gcd_mul_lcm _ _, h, mul_zero],
by simpa only [normalize_eq_zero, mul_eq_zero, units.ne_zero, or_false])
(by rintro (rfl | rfl); [apply lcm_zero_left, apply lcm_zero_right])
@[simp] lemma normalize_lcm (a b : α) : normalize (lcm a b) = lcm a b :=
classical.by_cases (assume : lcm a b = 0, by rw [this, normalize_zero]) $
assume h_lcm : lcm a b ≠ 0,
have h1 : gcd a b ≠ 0, from mt (by rw [gcd_eq_zero_iff, lcm_eq_zero_iff];
rintros ⟨rfl, rfl⟩; left; refl) h_lcm,
have h2 : normalize (gcd a b * lcm a b) = gcd a b * lcm a b,
by rw [gcd_mul_lcm, normalize_idem],
by simpa only [normalize.map_mul, normalize_gcd, one_mul, mul_right_inj' h1] using h2
theorem lcm_comm (a b : α) : lcm a b = lcm b a :=
dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _)
(lcm_dvd (dvd_lcm_right _ _) (dvd_lcm_left _ _))
(lcm_dvd (dvd_lcm_right _ _) (dvd_lcm_left _ _))
theorem lcm_assoc (m n k : α) : lcm (lcm m n) k = lcm m (lcm n k) :=
dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _)
(lcm_dvd
(lcm_dvd (dvd_lcm_left _ _) ((dvd_lcm_left _ _).trans (dvd_lcm_right _ _)))
((dvd_lcm_right _ _).trans (dvd_lcm_right _ _)))
(lcm_dvd
((dvd_lcm_left _ _).trans (dvd_lcm_left _ _))
(lcm_dvd ((dvd_lcm_right _ _).trans (dvd_lcm_left _ _)) (dvd_lcm_right _ _)))
instance : is_commutative α lcm := ⟨lcm_comm⟩
instance : is_associative α lcm := ⟨lcm_assoc⟩
lemma lcm_eq_normalize {a b c : α} (habc : lcm a b ∣ c) (hcab : c ∣ lcm a b) :
lcm a b = normalize c :=
normalize_lcm a b ▸ normalize_eq_normalize habc hcab
theorem lcm_dvd_lcm {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : lcm a c ∣ lcm b d :=
lcm_dvd (hab.trans (dvd_lcm_left _ _)) (hcd.trans (dvd_lcm_right _ _))
@[simp] theorem lcm_units_coe_left (u : units α) (a : α) : lcm ↑u a = normalize a :=
lcm_eq_normalize (lcm_dvd units.coe_dvd dvd_rfl) (dvd_lcm_right _ _)
@[simp] theorem lcm_units_coe_right (a : α) (u : units α) : lcm a ↑u = normalize a :=
(lcm_comm a u).trans $ lcm_units_coe_left _ _
@[simp] theorem lcm_one_left (a : α) : lcm 1 a = normalize a :=
lcm_units_coe_left 1 a
@[simp] theorem lcm_one_right (a : α) : lcm a 1 = normalize a :=
lcm_units_coe_right a 1
@[simp] theorem lcm_same (a : α) : lcm a a = normalize a :=
lcm_eq_normalize (lcm_dvd dvd_rfl dvd_rfl) (dvd_lcm_left _ _)
@[simp] theorem lcm_eq_one_iff (a b : α) : lcm a b = 1 ↔ a ∣ 1 ∧ b ∣ 1 :=
iff.intro
(assume eq, eq ▸ ⟨dvd_lcm_left _ _, dvd_lcm_right _ _⟩)
(assume ⟨⟨c, hc⟩, ⟨d, hd⟩⟩,
show lcm (units.mk_of_mul_eq_one a c hc.symm : α) (units.mk_of_mul_eq_one b d hd.symm) = 1,
by rw [lcm_units_coe_left, normalize_coe_units])
@[simp] theorem lcm_mul_left (a b c : α) : lcm (a * b) (a * c) = normalize a * lcm b c :=
classical.by_cases (by rintro rfl; simp only [zero_mul, lcm_zero_left, normalize_zero]) $
assume ha : a ≠ 0,
suffices lcm (a * b) (a * c) = normalize (a * lcm b c),
by simpa only [normalize.map_mul, normalize_lcm],
have a ∣ lcm (a * b) (a * c), from (dvd_mul_right _ _).trans (dvd_lcm_left _ _),
let ⟨d, eq⟩ := this in
lcm_eq_normalize
(lcm_dvd (mul_dvd_mul_left a (dvd_lcm_left _ _)) (mul_dvd_mul_left a (dvd_lcm_right _ _)))
(eq.symm ▸ (mul_dvd_mul_left a $ lcm_dvd
((mul_dvd_mul_iff_left ha).1 $ eq ▸ dvd_lcm_left _ _)
((mul_dvd_mul_iff_left ha).1 $ eq ▸ dvd_lcm_right _ _)))
@[simp] theorem lcm_mul_right (a b c : α) : lcm (b * a) (c * a) = lcm b c * normalize a :=
by simp only [mul_comm, lcm_mul_left]
theorem lcm_eq_left_iff (a b : α) (h : normalize a = a) : lcm a b = a ↔ b ∣ a :=
iff.intro (assume eq, eq ▸ dvd_lcm_right _ _) $
assume hab, dvd_antisymm_of_normalize_eq (normalize_lcm _ _) h (lcm_dvd (dvd_refl a) hab)
(dvd_lcm_left _ _)
theorem lcm_eq_right_iff (a b : α) (h : normalize b = b) : lcm a b = b ↔ a ∣ b :=
by simpa only [lcm_comm b a] using lcm_eq_left_iff b a h
theorem lcm_dvd_lcm_mul_left (m n k : α) : lcm m n ∣ lcm (k * m) n :=
lcm_dvd_lcm (dvd_mul_left _ _) dvd_rfl
theorem lcm_dvd_lcm_mul_right (m n k : α) : lcm m n ∣ lcm (m * k) n :=
lcm_dvd_lcm (dvd_mul_right _ _) dvd_rfl
theorem lcm_dvd_lcm_mul_left_right (m n k : α) : lcm m n ∣ lcm m (k * n) :=
lcm_dvd_lcm dvd_rfl (dvd_mul_left _ _)
theorem lcm_dvd_lcm_mul_right_right (m n k : α) : lcm m n ∣ lcm m (n * k) :=
lcm_dvd_lcm dvd_rfl (dvd_mul_right _ _)
theorem lcm_eq_of_associated_left {m n : α} (h : associated m n) (k : α) : lcm m k = lcm n k :=
dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _)
(lcm_dvd_lcm h.dvd dvd_rfl)
(lcm_dvd_lcm h.symm.dvd dvd_rfl)
theorem lcm_eq_of_associated_right {m n : α} (h : associated m n) (k : α) : lcm k m = lcm k n :=
dvd_antisymm_of_normalize_eq (normalize_lcm _ _) (normalize_lcm _ _)
(lcm_dvd_lcm dvd_rfl h.dvd)
(lcm_dvd_lcm dvd_rfl h.symm.dvd)
end lcm
namespace gcd_monoid
theorem prime_of_irreducible {x : α} (hi: irreducible x) : prime x :=
⟨hi.ne_zero, ⟨hi.1, λ a b h,
begin
cases gcd_dvd_left x a with y hy,
cases hi.is_unit_or_is_unit hy with hu hu; cases hu with u hu,
{ right, transitivity (gcd (x * b) (a * b)), apply dvd_gcd (dvd_mul_right x b) h,
rw gcd_mul_right, rw ← hu,
apply associated.dvd, transitivity (normalize b), symmetry, use u, apply mul_comm,
apply normalize_associated, },
{ left, rw [hy, ← hu],
transitivity, { apply associated.dvd, symmetry, use u }, apply gcd_dvd_right, }
end ⟩⟩
theorem irreducible_iff_prime {p : α} : irreducible p ↔ prime p :=
⟨prime_of_irreducible, prime.irreducible⟩
end gcd_monoid
end gcd_monoid
section unique_unit
variables [comm_cancel_monoid_with_zero α] [unique (units α)]
lemma units_eq_one (u : units α) : u = 1 := subsingleton.elim u 1
variable [nontrivial α]
@[priority 100] -- see Note [lower instance priority]
instance normalization_monoid_of_unique_units : normalization_monoid α :=
{ norm_unit := λ x, 1,
norm_unit_zero := rfl,
norm_unit_mul := λ x y hx hy, (mul_one 1).symm,
norm_unit_coe_units := λ u, subsingleton.elim _ _ }
@[simp] lemma norm_unit_eq_one (x : α) : norm_unit x = 1 := rfl
@[simp] lemma normalize_eq (x : α) : normalize x = x := mul_one x
end unique_unit
section integral_domain
variables [integral_domain α] [gcd_monoid α]
lemma gcd_eq_of_dvd_sub_right {a b c : α} (h : a ∣ b - c) : gcd a b = gcd a c :=
begin
apply dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _);
rw dvd_gcd_iff; refine ⟨gcd_dvd_left _ _, _⟩,
{ rcases h with ⟨d, hd⟩,
rcases gcd_dvd_right a b with ⟨e, he⟩,
rcases gcd_dvd_left a b with ⟨f, hf⟩,
use e - f * d,
rw [mul_sub, ← he, ← mul_assoc, ← hf, ← hd, sub_sub_cancel] },
{ rcases h with ⟨d, hd⟩,
rcases gcd_dvd_right a c with ⟨e, he⟩,
rcases gcd_dvd_left a c with ⟨f, hf⟩,
use e + f * d,
rw [mul_add, ← he, ← mul_assoc, ← hf, ← hd, ← add_sub_assoc, add_comm c b, add_sub_cancel] }
end
lemma gcd_eq_of_dvd_sub_left {a b c : α} (h : a ∣ b - c) : gcd b a = gcd c a :=
by rw [gcd_comm _ a, gcd_comm _ a, gcd_eq_of_dvd_sub_right h]
end integral_domain
section constructors
noncomputable theory
open associates
variables [comm_cancel_monoid_with_zero α] [nontrivial α]
private lemma map_mk_unit_aux [decidable_eq α] {f : associates α →* α}
(hinv : function.right_inverse f associates.mk) (a : α) :
a * ↑(classical.some (associated_map_mk hinv a)) = f (associates.mk a) :=
classical.some_spec (associated_map_mk hinv a)
/-- Define `normalization_monoid` on a structure from a `monoid_hom` inverse to `associates.mk`. -/
def normalization_monoid_of_monoid_hom_right_inverse [decidable_eq α] (f : associates α →* α)
(hinv : function.right_inverse f associates.mk) :
normalization_monoid α :=
{ norm_unit := λ a, if a = 0 then 1 else
classical.some (associates.mk_eq_mk_iff_associated.1 (hinv (associates.mk a)).symm),
norm_unit_zero := if_pos rfl,
norm_unit_mul := λ a b ha hb, by {
rw [if_neg (mul_ne_zero ha hb), if_neg ha, if_neg hb, units.ext_iff, units.coe_mul],
suffices : (a * b) * ↑(classical.some (associated_map_mk hinv (a * b))) =
(a * ↑(classical.some (associated_map_mk hinv a))) *
(b * ↑(classical.some (associated_map_mk hinv b))),
{ apply mul_left_cancel₀ (mul_ne_zero ha hb) _,
simpa only [mul_assoc, mul_comm, mul_left_comm] using this },
rw [map_mk_unit_aux hinv a, map_mk_unit_aux hinv (a * b), map_mk_unit_aux hinv b,
← monoid_hom.map_mul, associates.mk_mul_mk] },
norm_unit_coe_units := λ u, by {
rw [if_neg (units.ne_zero u), units.ext_iff],
apply mul_left_cancel₀ (units.ne_zero u),
rw [units.mul_inv, map_mk_unit_aux hinv u,
associates.mk_eq_mk_iff_associated.2 (associated_one_iff_is_unit.2 ⟨u, rfl⟩),
associates.mk_one, monoid_hom.map_one] } }
variable [normalization_monoid α]
/-- Define `gcd_monoid` on a structure just from the `gcd` and its properties. -/
noncomputable def gcd_monoid_of_gcd [decidable_eq α] (gcd : α → α → α)
(gcd_dvd_left : ∀a b, gcd a b ∣ a)
(gcd_dvd_right : ∀a b, gcd a b ∣ b)
(dvd_gcd : ∀{a b c}, a ∣ c → a ∣ b → a ∣ gcd c b)
(normalize_gcd : ∀a b, normalize (gcd a b) = gcd a b) :
gcd_monoid α :=
{ gcd := gcd,
gcd_dvd_left := gcd_dvd_left,
gcd_dvd_right := gcd_dvd_right,
dvd_gcd := λ a b c, dvd_gcd,
normalize_gcd := normalize_gcd,
lcm := λ a b, if a = 0 then 0 else classical.some (dvd_normalize_iff.2
((gcd_dvd_left a b).trans (dvd.intro b rfl))),
gcd_mul_lcm := λ a b, by {
split_ifs with a0,
{ rw [mul_zero, a0, zero_mul, normalize_zero] },
{ exact (classical.some_spec (dvd_normalize_iff.2
((gcd_dvd_left a b).trans (dvd.intro b rfl)))).symm } },
lcm_zero_left := λ a, if_pos rfl,
lcm_zero_right := λ a, by {
split_ifs with a0, { refl },
rw ← normalize_eq_zero at a0,
have h := (classical.some_spec (dvd_normalize_iff.2
((gcd_dvd_left a 0).trans (dvd.intro 0 rfl)))).symm,
have gcd0 : gcd a 0 = normalize a,
{ rw ← normalize_gcd,
exact normalize_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_zero a)) },
rw ← gcd0 at a0,
apply or.resolve_left (mul_eq_zero.1 _) a0,
rw [h, mul_zero, normalize_zero] },
.. (infer_instance : normalization_monoid α) }
/-- Define `gcd_monoid` on a structure just from the `lcm` and its properties. -/
noncomputable def gcd_monoid_of_lcm [decidable_eq α] (lcm : α → α → α)
(dvd_lcm_left : ∀a b, a ∣ lcm a b)
(dvd_lcm_right : ∀a b, b ∣ lcm a b)
(lcm_dvd : ∀{a b c}, c ∣ a → b ∣ a → lcm c b ∣ a)
(normalize_lcm : ∀a b, normalize (lcm a b) = lcm a b) :
gcd_monoid α :=
let exists_gcd := λ a b, dvd_normalize_iff.2 (lcm_dvd (dvd.intro b rfl) (dvd.intro_left a rfl)) in
{ lcm := lcm,
gcd := λ a b, if a = 0 then normalize b else (if b = 0 then normalize a else
classical.some (exists_gcd a b)),
gcd_mul_lcm := λ a b, by {
split_ifs,
{ rw [h, zero_dvd_iff.1 (dvd_lcm_left _ _), mul_zero, zero_mul, normalize_zero] },
{ rw [h_1, zero_dvd_iff.1 (dvd_lcm_right _ _), mul_zero, mul_zero, normalize_zero] },
apply eq.trans (mul_comm _ _) (classical.some_spec
(dvd_normalize_iff.2 (lcm_dvd (dvd.intro b rfl) (dvd.intro_left a rfl)))).symm },
normalize_gcd := λ a b, by {
split_ifs,
{ apply normalize_idem },
{ apply normalize_idem },
have h0 : lcm a b ≠ 0,
{ intro con,
have h := lcm_dvd (dvd.intro b rfl) (dvd.intro_left a rfl),
rw [con, zero_dvd_iff, mul_eq_zero] at h,
cases h; tauto },
apply mul_left_cancel₀ h0,
refine trans _ (classical.some_spec (exists_gcd a b)),
conv_lhs { congr, rw [← normalize_lcm a b] },
erw [← normalize.map_mul, ← classical.some_spec (exists_gcd a b), normalize_idem] },
lcm_zero_left := λ a, zero_dvd_iff.1 (dvd_lcm_left _ _),
lcm_zero_right := λ a, zero_dvd_iff.1 (dvd_lcm_right _ _),
gcd_dvd_left := λ a b, by {
split_ifs,
{ rw h, apply dvd_zero },
{ exact (normalize_associated _).dvd },
have h0 : lcm a b ≠ 0,
{ intro con,
have h := lcm_dvd (dvd.intro b rfl) (dvd.intro_left a rfl),
rw [con, zero_dvd_iff, mul_eq_zero] at h,
cases h; tauto },
rw [← mul_dvd_mul_iff_left h0, ← classical.some_spec (exists_gcd a b),
normalize_dvd_iff, mul_comm, mul_dvd_mul_iff_right h],
apply dvd_lcm_right },
gcd_dvd_right := λ a b, by {
split_ifs,
{ exact (normalize_associated _).dvd },
{ rw h_1, apply dvd_zero },
have h0 : lcm a b ≠ 0,
{ intro con,
have h := lcm_dvd (dvd.intro b rfl) (dvd.intro_left a rfl),
rw [con, zero_dvd_iff, mul_eq_zero] at h,
cases h; tauto },
rw [← mul_dvd_mul_iff_left h0, ← classical.some_spec (exists_gcd a b),
normalize_dvd_iff, mul_dvd_mul_iff_right h_1],
apply dvd_lcm_left },
dvd_gcd := λ a b c ac ab, by {
split_ifs,
{ apply dvd_normalize_iff.2 ab },
{ apply dvd_normalize_iff.2 ac },
have h0 : lcm c b ≠ 0,
{ intro con,
have h := lcm_dvd (dvd.intro b rfl) (dvd.intro_left c rfl),
rw [con, zero_dvd_iff, mul_eq_zero] at h,
cases h; tauto },
rw [← mul_dvd_mul_iff_left h0, ← classical.some_spec (dvd_normalize_iff.2
(lcm_dvd (dvd.intro b rfl) (dvd.intro_left c rfl))), dvd_normalize_iff],
rcases ab with ⟨d, rfl⟩,
rw mul_eq_zero at h_1,
push_neg at h_1,
rw [mul_comm a, ← mul_assoc, mul_dvd_mul_iff_right h_1.1],
apply lcm_dvd (dvd.intro d rfl),
rw [mul_comm, mul_dvd_mul_iff_right h_1.2],
apply ac },
.. (infer_instance : normalization_monoid α) }
/-- Define a `gcd_monoid` structure on a monoid just from the existence of a `gcd`. -/
noncomputable def gcd_monoid_of_exists_gcd [decidable_eq α]
(h : ∀ a b : α, ∃ c : α, ∀ d : α, d ∣ a ∧ d ∣ b ↔ d ∣ c) :
gcd_monoid α :=
gcd_monoid_of_gcd
(λ a b, normalize (classical.some (h a b)))
(λ a b, normalize_dvd_iff.2
(((classical.some_spec (h a b) (classical.some (h a b))).2 dvd_rfl)).1)
(λ a b, normalize_dvd_iff.2
(((classical.some_spec (h a b) (classical.some (h a b))).2 dvd_rfl)).2)
(λ a b c ac ab, dvd_normalize_iff.2 ((classical.some_spec (h c b) a).1 ⟨ac, ab⟩))
(λ a b, normalize_idem _)
/-- Define a `gcd_monoid` structure on a monoid just from the existence of an `lcm`. -/
noncomputable def gcd_monoid_of_exists_lcm [decidable_eq α]
(h : ∀ a b : α, ∃ c : α, ∀ d : α, a ∣ d ∧ b ∣ d ↔ c ∣ d) :
gcd_monoid α :=
gcd_monoid_of_lcm
(λ a b, normalize (classical.some (h a b)))
(λ a b, dvd_normalize_iff.2
(((classical.some_spec (h a b) (classical.some (h a b))).2 dvd_rfl)).1)
(λ a b, dvd_normalize_iff.2
(((classical.some_spec (h a b) (classical.some (h a b))).2 dvd_rfl)).2)
(λ a b c ac ab, normalize_dvd_iff.2 ((classical.some_spec (h c b) a).1 ⟨ac, ab⟩))
(λ a b, normalize_idem _)
end constructors
|
3be621ea9a282816fb1ff3093dc5a35f2561dc96 | 271e26e338b0c14544a889c31c30b39c989f2e0f | /stage0/src/Init/Lean/Hygiene.lean | 5c10103bf4dede236cf854a9fe6ebbafb645ceae | [
"Apache-2.0"
] | permissive | dgorokho/lean4 | 805f99b0b60c545b64ac34ab8237a8504f89d7d4 | e949a052bad59b1c7b54a82d24d516a656487d8a | refs/heads/master | 1,607,061,363,851 | 1,578,006,086,000 | 1,578,006,086,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,615 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
Runtime support for making quotation terms auto-hygienic, by mangling identifiers
introduced by them with a "macro scope" supplied by the context. Details to appear in a
paper soon.
-/
prelude
import Init.Control
import Init.Lean.Syntax
namespace Lean
abbrev MacroScope := Nat
/-- A monad that supports syntax quotations. Syntax quotations (in term
position) are monadic values that when executed retrieve the current "macro
scope" from the monad and apply it to every identifier they introduce
(independent of whether this identifier turns out to be a reference to an
existing declaration, or an actually fresh binding during further
elaboration). -/
class MonadQuotation (m : Type → Type) :=
-- Get the fresh scope of the current macro invocation
(getCurrMacroScope {} : m MacroScope)
/- Execute action in a new macro invocation context. This transformer should be
used at all places that morally qualify as the beginning of a "macro call",
e.g. `elabCommand` and `elabTerm` in the case of the elaborator. However, it
can also be used internally inside a "macro" if identifiers introduced by
e.g. different recursive calls should be independent and not collide. While
returning an intermediate syntax tree that will recursively be expanded by
the elaborator can be used for the same effect, doing direct recursion inside
the macro guarded by this transformer is often easier because one is not
restricted to passing a single syntax tree. Modelling this helper as a
transformer and not just a monadic action ensures that the current macro
scope before the recursive call is restored after it, as expected. -/
(withFreshMacroScope {α : Type} : m α → m α)
export MonadQuotation
def addMacroScope (n : Name) (scp : MacroScope) : Name :=
-- TODO: try harder to avoid clashes with other autogenerated names
mkNameNum n scp
/-- Simplistic MonadQuotation that does not guarantee globally fresh names, that
is, between different runs of this or other MonadQuotation implementations.
It is only safe if the syntax quotations do not introduce bindings around
antiquotations, and if references to globals are prefixed with `_root_.`
(which is not allowed to refer to a local variable).
`Unhygienic` can also be seen as a model implementation of `MonadQuotation`
(since it is completely hygienic as long as it is "run" only once and can
assume that there are no other implentations in use, as is the case for the
elaboration monads that carry their macro scope state through the entire
processing of a file). It uses the state monad to query and allocate the
next macro scope, and uses the reader monad to store the stack of scopes
corresponding to `withFreshMacroScope` calls. -/
abbrev Unhygienic := ReaderT MacroScope $ StateM MacroScope
namespace Unhygienic
instance MonadQuotation : MonadQuotation Unhygienic := {
getCurrMacroScope := read,
withFreshMacroScope := fun α x => do
fresh ← modifyGet (fun n => (n, n + 1));
adaptReader (fun _ => fresh) x
}
protected def run {α : Type} (x : Unhygienic α) : α := run x 0 1
end Unhygienic
instance monadQuotationTrans {m n : Type → Type} [MonadQuotation m] [HasMonadLift m n] [MonadFunctorT m m n n] : MonadQuotation n :=
{ getCurrMacroScope := liftM (getCurrMacroScope : m Nat),
withFreshMacroScope := fun α => monadMap (fun α => (withFreshMacroScope : m α → m α)) }
end Lean
|
2db6dec41534236b62aeb3f5c1dbd1bf95db33bd | 562dafcca9e8bf63ce6217723b51f32e89cdcc80 | /src/super/subsumption.lean | 8a589a50ceb34456c47948a3d22ce6961211c302 | [] | no_license | digama0/super | 660801ef3edab2c046d6a01ba9bbce53e41523e8 | 976957fe46128e6ef057bc771f532c27cce5a910 | refs/heads/master | 1,606,987,814,510 | 1,498,621,778,000 | 1,498,621,778,000 | 95,626,306 | 0 | 0 | null | 1,498,621,692,000 | 1,498,621,692,000 | null | UTF-8 | Lean | false | false | 3,425 | lean | /-
Copyright (c) 2017 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .clause .prover_state
open tactic monad
namespace super
private meta def try_subsume_core : list clause.literal → list clause.literal → tactic unit
| [] _ := skip
| small large := first $ do
i ← small.zip_with_index, j ← large.zip_with_index,
return $ do
unify_lit i.1 j.1,
try_subsume_core (small.remove_nth i.2) (large.remove_nth j.2)
-- FIXME: this is incorrect if a quantifier is unused
meta def try_subsume (small large : clause) : tactic unit := do
small_open ← clause.open_metan small (clause.num_quants small),
large_open ← clause.open_constn large (clause.num_quants large),
guard $ small.num_lits ≤ large.num_lits,
try_subsume_core small_open.1.get_lits large_open.1.get_lits
meta def does_subsume (small large : clause) : tactic bool :=
(try_subsume small large >> return tt) <|> return ff
meta def does_subsume_with_assertions (small large : derived_clause) : prover bool := do
if small.assertions.subset_of large.assertions then do
does_subsume small.c large.c
else
return ff
meta def any_tt {m : Type → Type} [monad m] (active : rb_map clause_id derived_clause) (pred : derived_clause → m bool) : m bool :=
active.fold (return ff) $ λk a cont, do
v ← pred a, if v then return tt else cont
meta def any_tt_list {m : Type → Type} [monad m] {A} (pred : A → m bool) : list A → m bool
| [] := return ff
| (x::xs) := do v ← pred x, if v then return tt else any_tt_list xs
@[super.inf]
meta def forward_subsumption : inf_decl := inf_decl.mk 20 $
take given, do active ← get_active,
sequence' $ do a ← active.values,
guard $ a.id ≠ given.id,
return $ do
ss ← does_subsume a.c given.c,
if ss
then remove_redundant given.id [a]
else return ()
meta def forward_subsumption_pre : prover unit := preprocessing_rule $ λnew, do
active ← get_active, filter (λn, do
do ss ← any_tt active (λa,
if a.assertions.subset_of n.assertions then do
does_subsume a.c n.c
else
-- TODO: move to locked
return ff),
return (bnot ss)) new
meta def subsumption_interreduction : list derived_clause → prover (list derived_clause)
| (c::cs) := do
-- TODO: move to locked
cs_that_subsume_c ← filter (λd, does_subsume_with_assertions d c) cs,
if ¬cs_that_subsume_c.empty then
-- TODO: update score
subsumption_interreduction cs
else do
cs_not_subsumed_by_c ← filter (λd, lift bnot (does_subsume_with_assertions c d)) cs,
cs' ← subsumption_interreduction cs_not_subsumed_by_c,
return (c::cs')
| [] := return []
meta def subsumption_interreduction_pre : prover unit :=
preprocessing_rule $ λnew,
let new' := list.sort_on (λc : derived_clause, c.c.num_lits) new in
subsumption_interreduction new'
meta def keys_where_tt {m} {K V : Type} [monad m] (active : rb_map K V) (pred : V → m bool) : m (list K) :=
@rb_map.fold _ _ (m (list K)) active (return []) $ λk a cont, do
v ← pred a, rest ← cont, return $ if v then k::rest else rest
@[super.inf]
meta def backward_subsumption : inf_decl := inf_decl.mk 20 $ λgiven, do
active ← get_active,
ss ← keys_where_tt active (λa, does_subsume given.c a.c),
sequence' $ do id ← ss, guard (id ≠ given.id), [remove_redundant id [given]]
end super
|
336d06e41ae0d810b57fb2887a6c6182fa1da464 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/topology/uniform_space/completion.lean | 0c2cbfe7068cf308ee48876f186f1f4552c3ddd6 | [
"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 | 23,255 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import topology.uniform_space.abstract_completion
/-!
# Hausdorff completions of uniform spaces
The goal is to construct a left-adjoint to the inclusion of complete Hausdorff uniform spaces
into all uniform spaces. Any uniform space `α` gets a completion `completion α` and a morphism
(ie. uniformly continuous map) `completion : α → completion α` which solves the universal
mapping problem of factorizing morphisms from `α` to any complete Hausdorff uniform space `β`.
It means any uniformly continuous `f : α → β` gives rise to a unique morphism
`completion.extension f : completion α → β` such that `f = completion.extension f ∘ completion α`.
Actually `completion.extension f` is defined for all maps from `α` to `β` but it has the desired
properties only if `f` is uniformly continuous.
Beware that `completion α` is not injective if `α` is not Hausdorff. But its image is always
dense. The adjoint functor acting on morphisms is then constructed by the usual abstract nonsense.
For every uniform spaces `α` and `β`, it turns `f : α → β` into a morphism
`completion.map f : completion α → completion β`
such that
`coe ∘ f = (completion.map f) ∘ coe`
provided `f` is uniformly continuous. This construction is compatible with composition.
In this file we introduce the following concepts:
* `Cauchy α` the uniform completion of the uniform space `α` (using Cauchy filters). These are not
minimal filters.
* `completion α := quotient (separation_setoid (Cauchy α))` the Hausdorff completion.
## References
This formalization is mostly based on
N. Bourbaki: General Topology
I. M. James: Topologies and Uniformities
From a slightly different perspective in order to reuse material in topology.uniform_space.basic.
-/
noncomputable theory
open filter set
universes u v w x
open_locale uniformity classical topological_space filter
/-- Space of Cauchy filters
This is essentially the completion of a uniform space. The embeddings are the neighbourhood filters.
This space is not minimal, the separated uniform space (i.e. quotiented on the intersection of all
entourages) is necessary for this.
-/
def Cauchy (α : Type u) [uniform_space α] : Type u := { f : filter α // cauchy f }
namespace Cauchy
section
parameters {α : Type u} [uniform_space α]
variables {β : Type v} {γ : Type w}
variables [uniform_space β] [uniform_space γ]
def gen (s : set (α × α)) : set (Cauchy α × Cauchy α) :=
{p | s ∈ filter.prod (p.1.val) (p.2.val) }
lemma monotone_gen : monotone gen :=
monotone_set_of $ assume p, @monotone_mem_sets (α×α) (filter.prod (p.1.val) (p.2.val))
private lemma symm_gen : map prod.swap ((𝓤 α).lift' gen) ≤ (𝓤 α).lift' gen :=
calc map prod.swap ((𝓤 α).lift' gen) =
(𝓤 α).lift' (λs:set (α×α), {p | s ∈ filter.prod (p.2.val) (p.1.val) }) :
begin
delta gen,
simp [map_lift'_eq, monotone_set_of, monotone_mem_sets,
function.comp, image_swap_eq_preimage_swap, -subtype.val_eq_coe]
end
... ≤ (𝓤 α).lift' gen :
uniformity_lift_le_swap
(monotone_principal.comp (monotone_set_of $ assume p,
@monotone_mem_sets (α×α) ((filter.prod ((p.2).val) ((p.1).val)))))
begin
have h := λ(p:Cauchy α×Cauchy α), @filter.prod_comm _ _ (p.2.val) (p.1.val),
simp [function.comp, h, -subtype.val_eq_coe],
exact le_refl _
end
private lemma comp_rel_gen_gen_subset_gen_comp_rel {s t : set (α×α)} : comp_rel (gen s) (gen t) ⊆
(gen (comp_rel s t) : set (Cauchy α × Cauchy α)) :=
assume ⟨f, g⟩ ⟨h, h₁, h₂⟩,
let ⟨t₁, (ht₁ : t₁ ∈ f.val), t₂, (ht₂ : t₂ ∈ h.val), (h₁ : set.prod t₁ t₂ ⊆ s)⟩ :=
mem_prod_iff.mp h₁ in
let ⟨t₃, (ht₃ : t₃ ∈ h.val), t₄, (ht₄ : t₄ ∈ g.val), (h₂ : set.prod t₃ t₄ ⊆ t)⟩ :=
mem_prod_iff.mp h₂ in
have t₂ ∩ t₃ ∈ h.val,
from inter_mem_sets ht₂ ht₃,
let ⟨x, xt₂, xt₃⟩ :=
h.property.left.nonempty_of_mem this in
(filter.prod f.val g.val).sets_of_superset
(prod_mem_prod ht₁ ht₄)
(assume ⟨a, b⟩ ⟨(ha : a ∈ t₁), (hb : b ∈ t₄)⟩,
⟨x,
h₁ (show (a, x) ∈ set.prod t₁ t₂, from ⟨ha, xt₂⟩),
h₂ (show (x, b) ∈ set.prod t₃ t₄, from ⟨xt₃, hb⟩)⟩)
private lemma comp_gen :
((𝓤 α).lift' gen).lift' (λs, comp_rel s s) ≤ (𝓤 α).lift' gen :=
calc ((𝓤 α).lift' gen).lift' (λs, comp_rel s s) =
(𝓤 α).lift' (λs, comp_rel (gen s) (gen s)) :
begin
rw [lift'_lift'_assoc],
exact monotone_gen,
exact (monotone_comp_rel monotone_id monotone_id)
end
... ≤ (𝓤 α).lift' (λs, gen $ comp_rel s s) :
lift'_mono' $ assume s hs, comp_rel_gen_gen_subset_gen_comp_rel
... = ((𝓤 α).lift' $ λs:set(α×α), comp_rel s s).lift' gen :
begin
rw [lift'_lift'_assoc],
exact (monotone_comp_rel monotone_id monotone_id),
exact monotone_gen
end
... ≤ (𝓤 α).lift' gen : lift'_mono comp_le_uniformity (le_refl _)
instance : uniform_space (Cauchy α) :=
uniform_space.of_core
{ uniformity := (𝓤 α).lift' gen,
refl := principal_le_lift' $ assume s hs ⟨a, b⟩ (a_eq_b : a = b),
a_eq_b ▸ a.property.right hs,
symm := symm_gen,
comp := comp_gen }
theorem mem_uniformity {s : set (Cauchy α × Cauchy α)} :
s ∈ 𝓤 (Cauchy α) ↔ ∃ t ∈ 𝓤 α, gen t ⊆ s :=
mem_lift'_sets monotone_gen
theorem mem_uniformity' {s : set (Cauchy α × Cauchy α)} :
s ∈ 𝓤 (Cauchy α) ↔ ∃ t ∈ 𝓤 α,
∀ f g : Cauchy α, t ∈ filter.prod f.1 g.1 → (f, g) ∈ s :=
mem_uniformity.trans $ bex_congr $ λ t h, prod.forall
/-- Embedding of `α` into its completion -/
def pure_cauchy (a : α) : Cauchy α :=
⟨pure a, cauchy_pure⟩
lemma uniform_inducing_pure_cauchy : uniform_inducing (pure_cauchy : α → Cauchy α) :=
⟨have (preimage (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ∘ gen) = id,
from funext $ assume s, set.ext $ assume ⟨a₁, a₂⟩,
by simp [preimage, gen, pure_cauchy, prod_principal_principal],
calc comap (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ((𝓤 α).lift' gen)
= (𝓤 α).lift' (preimage (λ (x : α × α), (pure_cauchy (x.fst), pure_cauchy (x.snd))) ∘ gen) :
comap_lift'_eq monotone_gen
... = 𝓤 α : by simp [this]⟩
lemma uniform_embedding_pure_cauchy : uniform_embedding (pure_cauchy : α → Cauchy α) :=
{ inj := assume a₁ a₂ h, pure_injective $ subtype.ext_iff_val.1 h,
..uniform_inducing_pure_cauchy }
lemma pure_cauchy_dense : ∀x, x ∈ closure (range pure_cauchy) :=
assume f,
have h_ex : ∀ s ∈ 𝓤 (Cauchy α), ∃y:α, (f, pure_cauchy y) ∈ s, from
assume s hs,
let ⟨t'', ht''₁, (ht''₂ : gen t'' ⊆ s)⟩ := (mem_lift'_sets monotone_gen).mp hs in
let ⟨t', ht'₁, ht'₂⟩ := comp_mem_uniformity_sets ht''₁ in
have t' ∈ filter.prod (f.val) (f.val),
from f.property.right ht'₁,
let ⟨t, ht, (h : set.prod t t ⊆ t')⟩ := mem_prod_same_iff.mp this in
let ⟨x, (hx : x ∈ t)⟩ := f.property.left.nonempty_of_mem ht in
have t'' ∈ filter.prod f.val (pure x),
from mem_prod_iff.mpr ⟨t, ht, {y:α | (x, y) ∈ t'},
h $ mk_mem_prod hx hx,
assume ⟨a, b⟩ ⟨(h₁ : a ∈ t), (h₂ : (x, b) ∈ t')⟩,
ht'₂ $ prod_mk_mem_comp_rel (@h (a, x) ⟨h₁, hx⟩) h₂⟩,
⟨x, ht''₂ $ by dsimp [gen]; exact this⟩,
begin
simp [closure_eq_cluster_pts, cluster_pt, nhds_eq_uniformity, lift'_inf_principal_eq, set.inter_comm],
exact (lift'_ne_bot_iff $ monotone_inter monotone_const monotone_preimage).mpr
(assume s hs,
let ⟨y, hy⟩ := h_ex s hs in
have pure_cauchy y ∈ range pure_cauchy ∩ {y : Cauchy α | (f, y) ∈ s},
from ⟨mem_range_self y, hy⟩,
⟨_, this⟩)
end
lemma dense_inducing_pure_cauchy : dense_inducing pure_cauchy :=
uniform_inducing_pure_cauchy.dense_inducing pure_cauchy_dense
lemma dense_embedding_pure_cauchy : dense_embedding pure_cauchy :=
uniform_embedding_pure_cauchy.dense_embedding pure_cauchy_dense
lemma nonempty_Cauchy_iff : nonempty (Cauchy α) ↔ nonempty α :=
begin
split ; rintro ⟨c⟩,
{ have := eq_univ_iff_forall.1 dense_embedding_pure_cauchy.to_dense_inducing.closure_range c,
obtain ⟨_, ⟨_, a, _⟩⟩ := mem_closure_iff.1 this _ is_open_univ trivial,
exact ⟨a⟩ },
{ exact ⟨pure_cauchy c⟩ }
end
section
set_option eqn_compiler.zeta true
instance : complete_space (Cauchy α) :=
complete_space_extension
uniform_inducing_pure_cauchy
pure_cauchy_dense $
assume f hf,
let f' : Cauchy α := ⟨f, hf⟩ in
have map pure_cauchy f ≤ (𝓤 $ Cauchy α).lift' (preimage (prod.mk f')),
from le_lift' $ assume s hs,
let ⟨t, ht₁, (ht₂ : gen t ⊆ s)⟩ := (mem_lift'_sets monotone_gen).mp hs in
let ⟨t', ht', (h : set.prod t' t' ⊆ t)⟩ := mem_prod_same_iff.mp (hf.right ht₁) in
have t' ⊆ { y : α | (f', pure_cauchy y) ∈ gen t },
from assume x hx, (filter.prod f (pure x)).sets_of_superset (prod_mem_prod ht' hx) h,
f.sets_of_superset ht' $ subset.trans this (preimage_mono ht₂),
⟨f', by simp [nhds_eq_uniformity]; assumption⟩
end
instance [inhabited α] : inhabited (Cauchy α) :=
⟨pure_cauchy $ default α⟩
instance [h : nonempty α] : nonempty (Cauchy α) :=
h.rec_on $ assume a, nonempty.intro $ Cauchy.pure_cauchy a
section extend
def extend (f : α → β) : (Cauchy α → β) :=
if uniform_continuous f then
dense_inducing_pure_cauchy.extend f
else
λ x, f (classical.inhabited_of_nonempty $ nonempty_Cauchy_iff.1 ⟨x⟩).default
variables [separated_space β]
lemma extend_pure_cauchy {f : α → β} (hf : uniform_continuous f) (a : α) :
extend f (pure_cauchy a) = f a :=
begin
rw [extend, if_pos hf],
exact uniformly_extend_of_ind uniform_inducing_pure_cauchy pure_cauchy_dense hf _
end
variables [_root_.complete_space β]
lemma uniform_continuous_extend {f : α → β} : uniform_continuous (extend f) :=
begin
by_cases hf : uniform_continuous f,
{ rw [extend, if_pos hf],
exact uniform_continuous_uniformly_extend uniform_inducing_pure_cauchy pure_cauchy_dense hf },
{ rw [extend, if_neg hf],
exact uniform_continuous_of_const (assume a b, by congr) }
end
end extend
end
theorem Cauchy_eq
{α : Type*} [inhabited α] [uniform_space α] [complete_space α] [separated_space α] {f g : Cauchy α} :
Lim f.1 = Lim g.1 ↔ (f, g) ∈ separation_rel (Cauchy α) :=
begin
split,
{ intros e s hs,
rcases Cauchy.mem_uniformity'.1 hs with ⟨t, tu, ts⟩,
apply ts,
rcases comp_mem_uniformity_sets tu with ⟨d, du, dt⟩,
refine mem_prod_iff.2
⟨_, f.2.le_nhds_Lim (mem_nhds_right (Lim f.1) du),
_, g.2.le_nhds_Lim (mem_nhds_left (Lim g.1) du), λ x h, _⟩,
cases x with a b, cases h with h₁ h₂,
rw ← e at h₂,
exact dt ⟨_, h₁, h₂⟩ },
{ intros H,
refine separated_def.1 (by apply_instance) _ _ (λ t tu, _),
rcases mem_uniformity_is_closed tu with ⟨d, du, dc, dt⟩,
refine H {p | (Lim p.1.1, Lim p.2.1) ∈ t}
(Cauchy.mem_uniformity'.2 ⟨d, du, λ f g h, _⟩),
rcases mem_prod_iff.1 h with ⟨x, xf, y, yg, h⟩,
have limc : ∀ (f : Cauchy α) (x ∈ f.1), Lim f.1 ∈ closure x,
{ intros f x xf,
rw closure_eq_cluster_pts,
exact ne_bot_of_le_ne_bot f.2.1
(le_inf f.2.le_nhds_Lim (le_principal_iff.2 xf)) },
have := dc.closure_subset_iff.2 h,
rw closure_prod_eq at this,
refine dt (this ⟨_, _⟩); dsimp; apply limc; assumption }
end
section
local attribute [instance] uniform_space.separation_setoid
lemma separated_pure_cauchy_injective {α : Type*} [uniform_space α] [s : separated_space α] :
function.injective (λa:α, ⟦pure_cauchy a⟧) | a b h :=
separated_def.1 s _ _ $ assume s hs,
let ⟨t, ht, hts⟩ :=
by rw [← (@uniform_embedding_pure_cauchy α _).comap_uniformity, filter.mem_comap_sets] at hs; exact hs in
have (pure_cauchy a, pure_cauchy b) ∈ t, from quotient.exact h t ht,
@hts (a, b) this
end
end Cauchy
local attribute [instance] uniform_space.separation_setoid
open Cauchy set
namespace uniform_space
variables (α : Type*) [uniform_space α]
variables {β : Type*} [uniform_space β]
variables {γ : Type*} [uniform_space γ]
instance complete_space_separation [h : complete_space α] :
complete_space (quotient (separation_setoid α)) :=
⟨assume f, assume hf : cauchy f,
have cauchy (f.comap (λx, ⟦x⟧)), from
hf.comap' comap_quotient_le_uniformity $
hf.left.comap_of_surj $ assume b, quotient.exists_rep _,
let ⟨x, (hx : f.comap (λx, ⟦x⟧) ≤ 𝓝 x)⟩ := complete_space.complete this in
⟨⟦x⟧, calc f = map (λx, ⟦x⟧) (f.comap (λx, ⟦x⟧)) :
(map_comap $ univ_mem_sets' $ assume b, quotient.exists_rep _).symm
... ≤ map (λx, ⟦x⟧) (𝓝 x) : map_mono hx
... ≤ _ : continuous_iff_continuous_at.mp uniform_continuous_quotient_mk.continuous _⟩⟩
/-- Hausdorff completion of `α` -/
def completion := quotient (separation_setoid $ Cauchy α)
namespace completion
instance [inhabited α] : inhabited (completion α) :=
by unfold completion; apply_instance
@[priority 50]
instance : uniform_space (completion α) := by dunfold completion ; apply_instance
instance : complete_space (completion α) := by dunfold completion ; apply_instance
instance : separated_space (completion α) := by dunfold completion ; apply_instance
instance : regular_space (completion α) := separated_regular
/-- Automatic coercion from `α` to its completion. Not always injective. -/
instance : has_coe_t α (completion α) := ⟨quotient.mk ∘ pure_cauchy⟩ -- note [use has_coe_t]
protected lemma coe_eq : (coe : α → completion α) = quotient.mk ∘ pure_cauchy := rfl
lemma comap_coe_eq_uniformity :
(𝓤 _).comap (λ(p:α×α), ((p.1 : completion α), (p.2 : completion α))) = 𝓤 α :=
begin
have : (λx:α×α, ((x.1 : completion α), (x.2 : completion α))) =
(λx:(Cauchy α)×(Cauchy α), (⟦x.1⟧, ⟦x.2⟧)) ∘ (λx:α×α, (pure_cauchy x.1, pure_cauchy x.2)),
{ ext ⟨a, b⟩; simp; refl },
rw [this, ← filter.comap_comap],
change filter.comap _ (filter.comap _ (𝓤 $ quotient $ separation_setoid $ Cauchy α)) = 𝓤 α,
rw [comap_quotient_eq_uniformity, uniform_embedding_pure_cauchy.comap_uniformity]
end
lemma uniform_inducing_coe : uniform_inducing (coe : α → completion α) :=
⟨comap_coe_eq_uniformity α⟩
variables {α}
lemma dense : dense_range (coe : α → completion α) :=
begin
rw [dense_range_iff_closure_range, completion.coe_eq, range_comp],
exact quotient_dense_of_dense pure_cauchy_dense
end
variables (α)
def cpkg {α : Type*} [uniform_space α] : abstract_completion α :=
{ space := completion α,
coe := coe,
uniform_struct := by apply_instance,
complete := by apply_instance,
separation := by apply_instance,
uniform_inducing := completion.uniform_inducing_coe α,
dense := completion.dense }
instance abstract_completion.inhabited : inhabited (abstract_completion α) :=
⟨cpkg⟩
local attribute [instance]
abstract_completion.uniform_struct abstract_completion.complete abstract_completion.separation
lemma nonempty_completion_iff : nonempty (completion α) ↔ nonempty α :=
(dense_range.nonempty (cpkg.dense)).symm
lemma uniform_continuous_coe : uniform_continuous (coe : α → completion α) :=
cpkg.uniform_continuous_coe
lemma continuous_coe : continuous (coe : α → completion α) :=
cpkg.continuous_coe
lemma uniform_embedding_coe [separated_space α] : uniform_embedding (coe : α → completion α) :=
{ comap_uniformity := comap_coe_eq_uniformity α,
inj := separated_pure_cauchy_injective }
variable {α}
lemma dense_inducing_coe : dense_inducing (coe : α → completion α) :=
{ dense := dense,
..(uniform_inducing_coe α).inducing }
lemma dense_embedding_coe [separated_space α]: dense_embedding (coe : α → completion α) :=
{ inj := separated_pure_cauchy_injective,
..dense_inducing_coe }
lemma dense₂ : dense_range (λx:α × β, ((x.1 : completion α), (x.2 : completion β))) :=
dense.prod dense
lemma dense₃ :
dense_range (λx:α × (β × γ), ((x.1 : completion α), ((x.2.1 : completion β), (x.2.2 : completion γ)))) :=
dense.prod dense₂
@[elab_as_eliminator]
lemma induction_on {p : completion α → Prop}
(a : completion α) (hp : is_closed {a | p a}) (ih : ∀a:α, p a) : p a :=
is_closed_property dense hp ih a
@[elab_as_eliminator]
lemma induction_on₂ {p : completion α → completion β → Prop}
(a : completion α) (b : completion β)
(hp : is_closed {x : completion α × completion β | p x.1 x.2})
(ih : ∀(a:α) (b:β), p a b) : p a b :=
have ∀x : completion α × completion β, p x.1 x.2, from
is_closed_property dense₂ hp $ assume ⟨a, b⟩, ih a b,
this (a, b)
@[elab_as_eliminator]
lemma induction_on₃ {p : completion α → completion β → completion γ → Prop}
(a : completion α) (b : completion β) (c : completion γ)
(hp : is_closed {x : completion α × completion β × completion γ | p x.1 x.2.1 x.2.2})
(ih : ∀(a:α) (b:β) (c:γ), p a b c) : p a b c :=
have ∀x : completion α × completion β × completion γ, p x.1 x.2.1 x.2.2, from
is_closed_property dense₃ hp $ assume ⟨a, b, c⟩, ih a b c,
this (a, b, c)
lemma ext [t2_space β] {f g : completion α → β} (hf : continuous f) (hg : continuous g)
(h : ∀a:α, f a = g a) : f = g :=
cpkg.funext hf hg h
section extension
variables {f : α → β}
/-- "Extension" to the completion. It is defined for any map `f` but
returns an arbitrary constant value if `f` is not uniformly continuous -/
protected def extension (f : α → β) : completion α → β :=
cpkg.extend f
variables [separated_space β]
@[simp] lemma extension_coe (hf : uniform_continuous f) (a : α) : (completion.extension f) a = f a :=
cpkg.extend_coe hf a
variables [complete_space β]
lemma uniform_continuous_extension : uniform_continuous (completion.extension f) :=
cpkg.uniform_continuous_extend
lemma continuous_extension : continuous (completion.extension f) :=
cpkg.continuous_extend
lemma extension_unique (hf : uniform_continuous f) {g : completion α → β} (hg : uniform_continuous g)
(h : ∀ a : α, f a = g (a : completion α)) : completion.extension f = g :=
cpkg.extend_unique hf hg h
@[simp] lemma extension_comp_coe {f : completion α → β} (hf : uniform_continuous f) :
completion.extension (f ∘ coe) = f :=
cpkg.extend_comp_coe hf
end extension
section map
variables {f : α → β}
/-- Completion functor acting on morphisms -/
protected def map (f : α → β) : completion α → completion β :=
cpkg.map cpkg f
lemma uniform_continuous_map : uniform_continuous (completion.map f) :=
cpkg.uniform_continuous_map cpkg f
lemma continuous_map : continuous (completion.map f) :=
cpkg.continuous_map cpkg f
@[simp] lemma map_coe (hf : uniform_continuous f) (a : α) : (completion.map f) a = f a :=
cpkg.map_coe cpkg hf a
lemma map_unique {f : α → β} {g : completion α → completion β}
(hg : uniform_continuous g) (h : ∀a:α, ↑(f a) = g a) : completion.map f = g :=
cpkg.map_unique cpkg hg h
@[simp] lemma map_id : completion.map (@id α) = id :=
cpkg.map_id
lemma extension_map [complete_space γ] [separated_space γ] {f : β → γ} {g : α → β}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
completion.extension f ∘ completion.map g = completion.extension (f ∘ g) :=
completion.ext (continuous_extension.comp continuous_map) continuous_extension $
by intro a; simp only [hg, hf, hf.comp hg, (∘), map_coe, extension_coe]
lemma map_comp {g : β → γ} {f : α → β} (hg : uniform_continuous g) (hf : uniform_continuous f) :
completion.map g ∘ completion.map f = completion.map (g ∘ f) :=
extension_map ((uniform_continuous_coe _).comp hg) hf
end map
/- In this section we construct isomorphisms between the completion of a uniform space and the
completion of its separation quotient -/
section separation_quotient_completion
def completion_separation_quotient_equiv (α : Type u) [uniform_space α] :
completion (separation_quotient α) ≃ completion α :=
begin
refine ⟨completion.extension (separation_quotient.lift (coe : α → completion α)),
completion.map quotient.mk, _, _⟩,
{ assume a,
refine induction_on a (is_closed_eq (continuous_map.comp continuous_extension) continuous_id) _,
rintros ⟨a⟩,
show completion.map quotient.mk (completion.extension (separation_quotient.lift coe) ↑⟦a⟧) = ↑⟦a⟧,
rw [extension_coe (separation_quotient.uniform_continuous_lift _),
separation_quotient.lift_mk (uniform_continuous_coe α),
completion.map_coe uniform_continuous_quotient_mk] ; apply_instance },
{ assume a,
refine completion.induction_on a (is_closed_eq (continuous_extension.comp continuous_map) continuous_id) _,
assume a,
rw [map_coe uniform_continuous_quotient_mk,
extension_coe (separation_quotient.uniform_continuous_lift _),
separation_quotient.lift_mk (uniform_continuous_coe α) _] ; apply_instance }
end
lemma uniform_continuous_completion_separation_quotient_equiv :
uniform_continuous ⇑(completion_separation_quotient_equiv α) :=
uniform_continuous_extension
lemma uniform_continuous_completion_separation_quotient_equiv_symm :
uniform_continuous ⇑(completion_separation_quotient_equiv α).symm :=
uniform_continuous_map
end separation_quotient_completion
section extension₂
variables (f : α → β → γ)
open function
protected def extension₂ (f : α → β → γ) : completion α → completion β → γ :=
cpkg.extend₂ cpkg f
variables [separated_space γ] {f}
@[simp] lemma extension₂_coe_coe (hf : uniform_continuous₂ f) (a : α) (b : β) :
completion.extension₂ f a b = f a b :=
cpkg.extension₂_coe_coe cpkg hf a b
variables [complete_space γ] (f)
lemma uniform_continuous_extension₂ : uniform_continuous₂ (completion.extension₂ f) :=
cpkg.uniform_continuous_extension₂ cpkg f
end extension₂
section map₂
open function
protected def map₂ (f : α → β → γ) : completion α → completion β → completion γ :=
cpkg.map₂ cpkg cpkg f
lemma uniform_continuous_map₂ (f : α → β → γ) : uniform_continuous₂ (completion.map₂ f) :=
cpkg.uniform_continuous_map₂ cpkg cpkg f
lemma continuous_map₂ {δ} [topological_space δ] {f : α → β → γ}
{a : δ → completion α} {b : δ → completion β} (ha : continuous a) (hb : continuous b) :
continuous (λd:δ, completion.map₂ f (a d) (b d)) :=
cpkg.continuous_map₂ cpkg cpkg ha hb
lemma map₂_coe_coe (a : α) (b : β) (f : α → β → γ) (hf : uniform_continuous₂ f) :
completion.map₂ f (a : completion α) (b : completion β) = f a b :=
cpkg.map₂_coe_coe cpkg cpkg a b f hf
end map₂
end completion
end uniform_space
|
73799ea1d6375491b42932cc4c45609a868b8d9a | 6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf | /src/game/world5/level1.lean | 6de83bfb380095024a0fbf0fed0d19ad321594e3 | [
"Apache-2.0"
] | permissive | arolihas/natural_number_game | 4f0c93feefec93b8824b2b96adff8b702b8b43ce | 8e4f7b4b42888a3b77429f90cce16292bd288138 | refs/heads/master | 1,621,872,426,808 | 1,586,270,467,000 | 1,586,270,467,000 | 253,648,466 | 0 | 0 | null | 1,586,219,694,000 | 1,586,219,694,000 | null | UTF-8 | Lean | false | false | 4,415 | lean | -- World name : Function world
/-
# Function world.
If you have beaten Addition World, then you have got
quite good at manipulating equalities in Lean using the `rw` tactic.
But there are plenty of levels later on which will require you
to manipulate functions, and `rw` is not the tool for you here.
To manipulate functions effectively, we need to learn about a new collection
of tactics, namely `exact`, `intro`, `have` and `apply`. These tactics
are specially designed for dealing with functions. Of course we are
ultimately interested in using these tactics to prove theorems
about the natural numbers – but in this
world there is little point in working with specific sets like `mynat`,
everything works for general sets.
So our notation for this level is: $P$, $Q$, $R$ and so on denote general sets,
and $h$, $j$, $k$ and so on denote general
functions between them. What we will learn in this world is how to use Lean
to move elements around between these sets using the functions
we are given, and the tactics we will learn. A word of warning –
even though there's no harm at all in thinking of $P$ being a set and $p$
being an element, you will not see Lean using the notation $p\in P$, because
internally Lean stores $P$ as a "Type" and $p$ as a "term", and it uses `p : P`
to mean "$p$ is a term of type $P$", Lean's way of expressing the idea that $p$
is an element of the set $P$. You have seen this already – Lean has
been writing `n : mynat` to mean that $n$ is a natural number.
## A new kind of goal.
All through addition world, our goals have been theorems,
and it was our job to find the proofs.
**The levels in function world aren't theorems**. This is the only world where
the levels aren't theorems in fact. In function world the object of a level
is to create an element of the set in the goal. The goal will look like `⊢ X`
with $X$ a set and you get rid of the goal by constructing an element of $X$.
I don't know if you noticed this, but you finished
essentially every goal of Addition World (and Multiplication World and Power World,
if you played them) with `refl`.
This tactic is no use to us here.
We are going to have to learn a new way of solving goals – the `exact` tactic.
If you delete the sorry below then your local context will look like this:
```
P Q : Type,
p : P,
h : P → Q
⊢ Q
```
In this situation, we have sets $P$ and $Q$ (but Lean calls them types),
and an element $p$ of $P$ (written `p : P`
but meaning $p\in P$). We also have a function $h$ from $P$ to $Q$,
and our goal is to construct an
element of the set $Q$. It's clear what to do *mathematically* to solve
this goal -- we can
make an element of $Q$ by applying the function $h$ to
the element $p$. But how to do it in Lean? There are at least two ways
to explain this idea to Lean,
and here we will learn about one of them, namely the method which
uses the `exact` tactic.
## The `exact` tactic.
If you can explicitly see how to make an element of of your goal set,
i.e. you have a formula for it, then you can just write `exact <formula>`
and this will close the goal.
### Example
If your local context looks like this
```
P Q : Type,
p : P,
h : P → Q
⊢ Q
```
then $h(p)$ is an element of $Q$ so you can just write
`exact h(p),`
to close the goal.
## Important note
Note that `exact h(P),` won't work (with a capital $P$);
this is a common error I see from beginners.
$P$ is not an element of $P$, it's $p$ that is an element of $P$.
## Level 1: the `exact` tactic.
-/
/- Definition
Given an element of $P$ and a function from $P$ to $Q$,
we define an element of $Q$.
-/
example (P Q : Type) (p : P) (h : P → Q) : Q :=
begin
end
/- Tactic : exact
## Summary
If the goal is `⊢ X` then `exact x` will close the goal if
and only if `x` is a term of type `X`.
## Details
Say $P$, $Q$ and $R$ are types (i.e., what a mathematician
might think of as either sets or propositions),
and the local context looks like this:
```
p : P,
h : P → Q,
j : Q → R
⊢ R
```
If you can spot how to make a term of type `R`, then you
can just make it and say you're done using the `exact` tactic
together with the formula you have spotted. For example the
above goal could be solved with
`exact j(h(p)),`
because $j(h(p))$ is easily checked to be a term of type $R$
(i.e., an element of the set $R$, or a proof of the proposition $R$).
-/
|
140ebc2873ef3a9fd3d667113ddc149f92e184fc | 7cdf3413c097e5d36492d12cdd07030eb991d394 | /src/game/world3/level4.lean | cbe2efb5a3181d4d9dc66855e994c11f617fa330 | [] | no_license | alreadydone/natural_number_game | 3135b9385a9f43e74cfbf79513fc37e69b99e0b3 | 1a39e693df4f4e871eb449890d3c7715a25c2ec9 | refs/heads/master | 1,599,387,390,105 | 1,573,200,587,000 | 1,573,200,691,000 | 220,397,084 | 0 | 0 | null | 1,573,192,734,000 | 1,573,192,733,000 | null | UTF-8 | Lean | false | false | 1,520 | lean | import game.world3.level3 -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 4: `mul_add`
Currently our tools for multiplication include the
following:
* `mul_zero m : m * 0 = 0`
* `zero_mul m : 0 * m = 0`
* `mul_succ a b : a * succ b = a * b + a`
but for addition we have `add_comm` and `add_assoc`
and are in much better shape.
Where are we going? Well we want to prove `mul_comm`
and `mul_assoc`, i.e. that `a * b = b * a` and
`(a * b) * c = a * (b * c)`. But we *also* want to
establish the way multiplication interacts with addition,
i.e. we want to prove that we can "expand out the brackets"
and show `a * (b + c) = (a * b) + (a * c)`.
The technical term for this is "distributivity of multiplication over addition".
Note the name of this lemma -- `mul_add`. And note the left
hand side -- `a * (b + c)`, a multiplication and then an addition.
I think `mul_add` is much easier to remember than "distributivity".
-/
/- Lemma
Multiplication is distributive over addition.
In other words, for all natural numbers $a$, $b$ and $t$, we have
$$ t(a + b) = ta + tb. $$
-/
lemma mul_add (t a b : mynat) : t * (a + b) = t * a + t * b :=
begin [less_leaky]
induction b with d hd,
{ rewrite [add_zero, mul_zero, add_zero],
},
{
rw add_succ,
rw mul_succ,
rw hd,
rw mul_succ,
rw add_assoc, -- ;-)
refl,
}
end
def left_distrib := mul_add -- stupid field name, -- hide
-- I just don't instinctively know what left_distrib means -- hide
end mynat -- hide
|
e6ed0bd5191470c676a24652860b136e92c17a7e | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /stage0/src/Lean/Compiler/IR/FreeVars.lean | 428b717299845d677c4df234c3b5040846ec0099 | [
"Apache-2.0"
] | permissive | WojciechKarpiel/lean4 | 7f89706b8e3c1f942b83a2c91a3a00b05da0e65b | f6e1314fa08293dea66a329e05b6c196a0189163 | refs/heads/master | 1,686,633,402,214 | 1,625,821,189,000 | 1,625,821,258,000 | 384,640,886 | 0 | 0 | Apache-2.0 | 1,625,903,617,000 | 1,625,903,026,000 | null | UTF-8 | Lean | false | false | 9,601 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.IR.Basic
namespace Lean.IR
namespace MaxIndex
/- Compute the maximum index `M` used in a declaration.
We `M` to initialize the fresh index generator used to create fresh
variable and join point names.
Recall that we variable and join points share the same namespace in
our implementation.
-/
abbrev Collector := Index → Index
@[inline] private def skip : Collector := id
@[inline] private def collect (x : Index) : Collector := fun y => if x > y then x else y
@[inline] private def collectVar (x : VarId) : Collector := collect x.idx
@[inline] private def collectJP (j : JoinPointId) : Collector := collect j.idx
@[inline] private def seq (k₁ k₂ : Collector) : Collector := k₂ ∘ k₁
instance : AndThen Collector := ⟨seq⟩
private def collectArg : Arg → Collector
| Arg.var x => collectVar x
| irrelevant => skip
@[specialize] private def collectArray {α : Type} (as : Array α) (f : α → Collector) : Collector :=
fun m => as.foldl (fun m a => f a m) m
private def collectArgs (as : Array Arg) : Collector := collectArray as collectArg
private def collectParam (p : Param) : Collector := collectVar p.x
private def collectParams (ps : Array Param) : Collector := collectArray ps collectParam
private def collectExpr : Expr → Collector
| Expr.ctor _ ys => collectArgs ys
| Expr.reset _ x => collectVar x
| Expr.reuse x _ _ ys => collectVar x >> collectArgs ys
| Expr.proj _ x => collectVar x
| Expr.uproj _ x => collectVar x
| Expr.sproj _ _ x => collectVar x
| Expr.fap _ ys => collectArgs ys
| Expr.pap _ ys => collectArgs ys
| Expr.ap x ys => collectVar x >> collectArgs ys
| Expr.box _ x => collectVar x
| Expr.unbox x => collectVar x
| Expr.lit v => skip
| Expr.isShared x => collectVar x
| Expr.isTaggedPtr x => collectVar x
private def collectAlts (f : FnBody → Collector) (alts : Array Alt) : Collector :=
collectArray alts $ fun alt => f alt.body
partial def collectFnBody : FnBody → Collector
| FnBody.vdecl x _ v b => collectVar x >> collectExpr v >> collectFnBody b
| FnBody.jdecl j ys v b => collectJP j >> collectFnBody v >> collectParams ys >> collectFnBody b
| FnBody.set x _ y b => collectVar x >> collectArg y >> collectFnBody b
| FnBody.uset x _ y b => collectVar x >> collectVar y >> collectFnBody b
| FnBody.sset x _ _ y _ b => collectVar x >> collectVar y >> collectFnBody b
| FnBody.setTag x _ b => collectVar x >> collectFnBody b
| FnBody.inc x _ _ _ b => collectVar x >> collectFnBody b
| FnBody.dec x _ _ _ b => collectVar x >> collectFnBody b
| FnBody.del x b => collectVar x >> collectFnBody b
| FnBody.mdata _ b => collectFnBody b
| FnBody.case _ x _ alts => collectVar x >> collectAlts collectFnBody alts
| FnBody.jmp j ys => collectJP j >> collectArgs ys
| FnBody.ret x => collectArg x
| FnBody.unreachable => skip
partial def collectDecl : Decl → Collector
| Decl.fdecl (xs := xs) (body := b) .. => collectParams xs >> collectFnBody b
| Decl.extern (xs := xs) .. => collectParams xs
end MaxIndex
def FnBody.maxIndex (b : FnBody) : Index :=
MaxIndex.collectFnBody b 0
def Decl.maxIndex (d : Decl) : Index :=
MaxIndex.collectDecl d 0
namespace FreeIndices
/- We say a variable (join point) index (aka name) is free in a function body
if there isn't a `FnBody.vdecl` (`Fnbody.jdecl`) binding it. -/
abbrev Collector := IndexSet → IndexSet → IndexSet
@[inline] private def skip : Collector :=
fun bv fv => fv
@[inline] private def collectIndex (x : Index) : Collector :=
fun bv fv => if bv.contains x then fv else fv.insert x
@[inline] private def collectVar (x : VarId) : Collector :=
collectIndex x.idx
@[inline] private def collectJP (x : JoinPointId) : Collector :=
collectIndex x.idx
@[inline] private def withIndex (x : Index) : Collector → Collector :=
fun k bv fv => k (bv.insert x) fv
@[inline] private def withVar (x : VarId) : Collector → Collector :=
withIndex x.idx
@[inline] private def withJP (x : JoinPointId) : Collector → Collector :=
withIndex x.idx
def insertParams (s : IndexSet) (ys : Array Param) : IndexSet :=
ys.foldl (init := s) fun s p => s.insert p.x.idx
@[inline] private def withParams (ys : Array Param) : Collector → Collector :=
fun k bv fv => k (insertParams bv ys) fv
@[inline] private def seq : Collector → Collector → Collector :=
fun k₁ k₂ bv fv => k₂ bv (k₁ bv fv)
instance : AndThen Collector := ⟨seq⟩
private def collectArg : Arg → Collector
| Arg.var x => collectVar x
| irrelevant => skip
@[specialize] private def collectArray {α : Type} (as : Array α) (f : α → Collector) : Collector :=
fun bv fv => as.foldl (fun fv a => f a bv fv) fv
private def collectArgs (as : Array Arg) : Collector :=
collectArray as collectArg
private def collectExpr : Expr → Collector
| Expr.ctor _ ys => collectArgs ys
| Expr.reset _ x => collectVar x
| Expr.reuse x _ _ ys => collectVar x >> collectArgs ys
| Expr.proj _ x => collectVar x
| Expr.uproj _ x => collectVar x
| Expr.sproj _ _ x => collectVar x
| Expr.fap _ ys => collectArgs ys
| Expr.pap _ ys => collectArgs ys
| Expr.ap x ys => collectVar x >> collectArgs ys
| Expr.box _ x => collectVar x
| Expr.unbox x => collectVar x
| Expr.lit v => skip
| Expr.isShared x => collectVar x
| Expr.isTaggedPtr x => collectVar x
private def collectAlts (f : FnBody → Collector) (alts : Array Alt) : Collector :=
collectArray alts $ fun alt => f alt.body
partial def collectFnBody : FnBody → Collector
| FnBody.vdecl x _ v b => collectExpr v >> withVar x (collectFnBody b)
| FnBody.jdecl j ys v b => withParams ys (collectFnBody v) >> withJP j (collectFnBody b)
| FnBody.set x _ y b => collectVar x >> collectArg y >> collectFnBody b
| FnBody.uset x _ y b => collectVar x >> collectVar y >> collectFnBody b
| FnBody.sset x _ _ y _ b => collectVar x >> collectVar y >> collectFnBody b
| FnBody.setTag x _ b => collectVar x >> collectFnBody b
| FnBody.inc x _ _ _ b => collectVar x >> collectFnBody b
| FnBody.dec x _ _ _ b => collectVar x >> collectFnBody b
| FnBody.del x b => collectVar x >> collectFnBody b
| FnBody.mdata _ b => collectFnBody b
| FnBody.case _ x _ alts => collectVar x >> collectAlts collectFnBody alts
| FnBody.jmp j ys => collectJP j >> collectArgs ys
| FnBody.ret x => collectArg x
| FnBody.unreachable => skip
end FreeIndices
def FnBody.collectFreeIndices (b : FnBody) (vs : IndexSet) : IndexSet :=
FreeIndices.collectFnBody b {} vs
def FnBody.freeIndices (b : FnBody) : IndexSet :=
b.collectFreeIndices {}
namespace HasIndex
/- In principle, we can check whether a function body `b` contains an index `i` using
`b.freeIndices.contains i`, but it is more efficient to avoid the construction
of the set of freeIndices and just search whether `i` occurs in `b` or not.
-/
def visitVar (w : Index) (x : VarId) : Bool := w == x.idx
def visitJP (w : Index) (x : JoinPointId) : Bool := w == x.idx
def visitArg (w : Index) : Arg → Bool
| Arg.var x => visitVar w x
| _ => false
def visitArgs (w : Index) (xs : Array Arg) : Bool :=
xs.any (visitArg w)
def visitParams (w : Index) (ps : Array Param) : Bool :=
ps.any (fun p => w == p.x.idx)
def visitExpr (w : Index) : Expr → Bool
| Expr.ctor _ ys => visitArgs w ys
| Expr.reset _ x => visitVar w x
| Expr.reuse x _ _ ys => visitVar w x || visitArgs w ys
| Expr.proj _ x => visitVar w x
| Expr.uproj _ x => visitVar w x
| Expr.sproj _ _ x => visitVar w x
| Expr.fap _ ys => visitArgs w ys
| Expr.pap _ ys => visitArgs w ys
| Expr.ap x ys => visitVar w x || visitArgs w ys
| Expr.box _ x => visitVar w x
| Expr.unbox x => visitVar w x
| Expr.lit v => false
| Expr.isShared x => visitVar w x
| Expr.isTaggedPtr x => visitVar w x
partial def visitFnBody (w : Index) : FnBody → Bool
| FnBody.vdecl x _ v b => visitExpr w v || visitFnBody w b
| FnBody.jdecl j ys v b => visitFnBody w v || visitFnBody w b
| FnBody.set x _ y b => visitVar w x || visitArg w y || visitFnBody w b
| FnBody.uset x _ y b => visitVar w x || visitVar w y || visitFnBody w b
| FnBody.sset x _ _ y _ b => visitVar w x || visitVar w y || visitFnBody w b
| FnBody.setTag x _ b => visitVar w x || visitFnBody w b
| FnBody.inc x _ _ _ b => visitVar w x || visitFnBody w b
| FnBody.dec x _ _ _ b => visitVar w x || visitFnBody w b
| FnBody.del x b => visitVar w x || visitFnBody w b
| FnBody.mdata _ b => visitFnBody w b
| FnBody.jmp j ys => visitJP w j || visitArgs w ys
| FnBody.ret x => visitArg w x
| FnBody.case _ x _ alts => visitVar w x || alts.any (fun alt => visitFnBody w alt.body)
| FnBody.unreachable => false
end HasIndex
def Arg.hasFreeVar (arg : Arg) (x : VarId) : Bool := HasIndex.visitArg x.idx arg
def Expr.hasFreeVar (e : Expr) (x : VarId) : Bool := HasIndex.visitExpr x.idx e
def FnBody.hasFreeVar (b : FnBody) (x : VarId) : Bool := HasIndex.visitFnBody x.idx b
end Lean.IR
|
36f50d0e7bf22eafdf4c7116ca0fd3b481a1ea81 | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/real/hyperreal.lean | 468ae5e154eb181c1278745056ef3b612133614d | [
"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,999 | lean | /-
Copyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Abhimanyu Pallavi Sudhir
-/
import order.filter.filter_product
import analysis.specific_limits
/-!
# Construction of the hyperreal numbers as an ultraproduct of real sequences.
-/
open filter filter.germ
open_locale topological_space classical
/-- Hyperreal numbers on the ultrafilter extending the cofinite filter -/
@[derive [linear_ordered_field, inhabited]]
def hyperreal : Type := germ (hyperfilter ℕ : filter ℕ) ℝ
namespace hyperreal
notation `ℝ*` := hyperreal
noncomputable instance : has_coe_t ℝ ℝ* := ⟨λ x, (↑x : germ _ _)⟩
@[simp, norm_cast]
lemma coe_eq_coe {x y : ℝ} : (x : ℝ*) = y ↔ x = y :=
germ.const_inj
@[simp, norm_cast] lemma coe_eq_zero {x : ℝ} : (x : ℝ*) = 0 ↔ x = 0 := coe_eq_coe
@[simp, norm_cast] lemma coe_eq_one {x : ℝ} : (x : ℝ*) = 1 ↔ x = 1 := coe_eq_coe
@[simp, norm_cast] lemma coe_one : ↑(1 : ℝ) = (1 : ℝ*) := rfl
@[simp, norm_cast] lemma coe_zero : ↑(0 : ℝ) = (0 : ℝ*) := rfl
@[simp, norm_cast] lemma coe_inv (x : ℝ) : ↑(x⁻¹) = (x⁻¹ : ℝ*) := rfl
@[simp, norm_cast] lemma coe_neg (x : ℝ) : ↑(-x) = (-x : ℝ*) := rfl
@[simp, norm_cast] lemma coe_add (x y : ℝ) : ↑(x + y) = (x + y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_bit0 (x : ℝ) : ↑(bit0 x) = (bit0 x : ℝ*) := rfl
@[simp, norm_cast] lemma coe_bit1 (x : ℝ) : ↑(bit1 x) = (bit1 x : ℝ*) := rfl
@[simp, norm_cast] lemma coe_mul (x y : ℝ) : ↑(x * y) = (x * y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_div (x y : ℝ) : ↑(x / y) = (x / y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_sub (x y : ℝ) : ↑(x - y) = (x - y : ℝ*) := rfl
@[simp, norm_cast] lemma coe_lt_coe {x y : ℝ} : (x : ℝ*) < y ↔ x < y := germ.const_lt
@[simp, norm_cast] lemma coe_pos {x : ℝ} : 0 < (x : ℝ*) ↔ 0 < x :=
coe_lt_coe
@[simp, norm_cast] lemma coe_le_coe {x y : ℝ} : (x : ℝ*) ≤ y ↔ x ≤ y := germ.const_le_iff
@[simp, norm_cast] lemma coe_abs (x : ℝ) : ((abs x : ℝ) : ℝ*) = abs x := germ.const_abs _
@[simp, norm_cast] lemma coe_max (x y : ℝ) : ((max x y : ℝ) : ℝ*) = max x y := germ.const_max _ _
@[simp, norm_cast] lemma coe_min (x y : ℝ) : ((min x y : ℝ) : ℝ*) = min x y := germ.const_min _ _
/-- Construct a hyperreal number from a sequence of real numbers. -/
noncomputable def of_seq (f : ℕ → ℝ) : ℝ* := (↑f : germ (hyperfilter ℕ : filter ℕ) ℝ)
/-- A sample infinitesimal hyperreal-/
noncomputable def epsilon : ℝ* := of_seq $ λ n, n⁻¹
/-- A sample infinite hyperreal-/
noncomputable def omega : ℝ* := of_seq coe
localized "notation `ε` := hyperreal.epsilon" in hyperreal
localized "notation `ω` := hyperreal.omega" in hyperreal
lemma epsilon_eq_inv_omega : ε = ω⁻¹ := rfl
lemma inv_epsilon_eq_omega : ε⁻¹ = ω := @inv_inv' _ _ ω
lemma epsilon_pos : 0 < ε :=
suffices ∀ᶠ i in hyperfilter ℕ, (0 : ℝ) < (i : ℕ)⁻¹, by rwa lt_def,
have h0' : {n : ℕ | ¬ 0 < n} = {0} :=
by simp only [not_lt, (set.set_of_eq_eq_singleton).symm]; ext; exact nat.le_zero_iff,
begin
simp only [inv_pos, nat.cast_pos],
exact mem_hyperfilter_of_finite_compl (by convert set.finite_singleton _),
end
lemma epsilon_ne_zero : ε ≠ 0 := ne_of_gt epsilon_pos
lemma omega_pos : 0 < ω := by rw ←inv_epsilon_eq_omega; exact inv_pos.2 epsilon_pos
lemma omega_ne_zero : ω ≠ 0 := ne_of_gt omega_pos
theorem epsilon_mul_omega : ε * ω = 1 := @inv_mul_cancel _ _ ω omega_ne_zero
lemma lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : tendsto f at_top (𝓝 0)) :
∀ {r : ℝ}, 0 < r → of_seq f < (r : ℝ*) :=
begin
simp only [metric.tendsto_at_top, dist_zero_right, norm, lt_def] at hf ⊢,
intros r hr, cases hf r hr with N hf',
have hs : {i : ℕ | f i < r}ᶜ ⊆ {i : ℕ | i ≤ N} :=
λ i hi1, le_of_lt (by simp only [lt_iff_not_ge];
exact λ hi2, hi1 (lt_of_le_of_lt (le_abs_self _) (hf' i hi2)) : i < N),
exact mem_hyperfilter_of_finite_compl
((set.finite_le_nat N).subset hs)
end
lemma neg_lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : tendsto f at_top (𝓝 0)) :
∀ {r : ℝ}, 0 < r → (-r : ℝ*) < of_seq f :=
λ r hr, have hg : _ := hf.neg,
neg_lt_of_neg_lt (by rw [neg_zero] at hg; exact lt_of_tendsto_zero_of_pos hg hr)
lemma gt_of_tendsto_zero_of_neg {f : ℕ → ℝ} (hf : tendsto f at_top (𝓝 0)) :
∀ {r : ℝ}, r < 0 → (r : ℝ*) < of_seq f :=
λ r hr, by rw [←neg_neg r, coe_neg];
exact neg_lt_of_tendsto_zero_of_pos hf (neg_pos.mpr hr)
lemma epsilon_lt_pos (x : ℝ) : 0 < x → ε < x :=
lt_of_tendsto_zero_of_pos tendsto_inverse_at_top_nhds_0_nat
/-- Standard part predicate -/
def is_st (x : ℝ*) (r : ℝ) := ∀ δ : ℝ, 0 < δ → (r - δ : ℝ*) < x ∧ x < r + δ
/-- Standard part function: like a "round" to ℝ instead of ℤ -/
noncomputable def st : ℝ* → ℝ :=
λ x, if h : ∃ r, is_st x r then classical.some h else 0
/-- A hyperreal number is infinitesimal if its standard part is 0 -/
def infinitesimal (x : ℝ*) := is_st x 0
/-- A hyperreal number is positive infinite if it is larger than all real numbers -/
def infinite_pos (x : ℝ*) := ∀ r : ℝ, ↑r < x
/-- A hyperreal number is negative infinite if it is smaller than all real numbers -/
def infinite_neg (x : ℝ*) := ∀ r : ℝ, x < r
/-- A hyperreal number is infinite if it is infinite positive or infinite negative -/
def infinite (x : ℝ*) := infinite_pos x ∨ infinite_neg x
/-!
### Some facts about `st`
-/
private lemma is_st_unique' (x : ℝ*) (r s : ℝ) (hr : is_st x r) (hs : is_st x s) (hrs : r < s) :
false :=
have hrs' : _ := half_pos $ sub_pos_of_lt hrs,
have hr' : _ := (hr _ hrs').2,
have hs' : _ := (hs _ hrs').1,
have h : s - ((s - r) / 2) = r + (s - r) / 2 := by linarith,
begin
norm_cast at *,
rw h at hs',
exact not_lt_of_lt hs' hr'
end
theorem is_st_unique {x : ℝ*} {r s : ℝ} (hr : is_st x r) (hs : is_st x s) : r = s :=
begin
rcases lt_trichotomy r s with h | h | h,
{ exact false.elim (is_st_unique' x r s hr hs h) },
{ exact h },
{ exact false.elim (is_st_unique' x s r hs hr h) }
end
theorem not_infinite_of_exists_st {x : ℝ*} : (∃ r : ℝ, is_st x r) → ¬ infinite x :=
λ he hi, Exists.dcases_on he $ λ r hr, hi.elim
(λ hip, not_lt_of_lt (hr 2 zero_lt_two).2 (hip $ r + 2))
(λ hin, not_lt_of_lt (hr 2 zero_lt_two).1 (hin $ r - 2))
theorem is_st_Sup {x : ℝ*} (hni : ¬ infinite x) : is_st x (Sup {y : ℝ | (y : ℝ*) < x}) :=
let S : set ℝ := {y : ℝ | (y : ℝ*) < x} in
let R : _ := Sup S in
have hnile : _ := not_forall.mp (not_or_distrib.mp hni).1,
have hnige : _ := not_forall.mp (not_or_distrib.mp hni).2,
Exists.dcases_on hnile $ Exists.dcases_on hnige $ λ r₁ hr₁ r₂ hr₂,
have HR₁ : ∃ y : ℝ, y ∈ S :=
⟨r₁ - 1, lt_of_lt_of_le (coe_lt_coe.2 $ sub_one_lt _) (not_lt.mp hr₁) ⟩,
have HR₂ : ∃ z : ℝ, ∀ y ∈ S, y ≤ z :=
⟨ r₂, λ y hy, le_of_lt (coe_lt_coe.1 (lt_of_lt_of_le hy (not_lt.mp hr₂))) ⟩,
λ δ hδ,
⟨ lt_of_not_ge' $ λ c,
have hc : ∀ y ∈ S, y ≤ R - δ := λ y hy, coe_le_coe.1 $ le_of_lt $ lt_of_lt_of_le hy c,
not_lt_of_le ((real.Sup_le _ HR₁ HR₂).mpr hc) $ sub_lt_self R hδ,
lt_of_not_ge' $ λ c,
have hc : ↑(R + δ / 2) < x :=
lt_of_lt_of_le (add_lt_add_left (coe_lt_coe.2 (half_lt_self hδ)) R) c,
not_lt_of_le (real.le_Sup _ HR₂ hc) $ (lt_add_iff_pos_right _).mpr $ half_pos hδ⟩
theorem exists_st_of_not_infinite {x : ℝ*} (hni : ¬ infinite x) : ∃ r : ℝ, is_st x r :=
⟨Sup {y : ℝ | (y : ℝ*) < x}, is_st_Sup hni⟩
theorem st_eq_Sup {x : ℝ*} : st x = Sup {y : ℝ | (y : ℝ*) < x} :=
begin
unfold st, split_ifs,
{ exact is_st_unique (classical.some_spec h) (is_st_Sup (not_infinite_of_exists_st h)) },
{ cases not_imp_comm.mp exists_st_of_not_infinite h with H H,
{ rw (set.ext (λ i, ⟨λ hi, set.mem_univ i, λ hi, H i⟩) : {y : ℝ | (y : ℝ*) < x} = set.univ),
exact (real.Sup_univ).symm },
{ rw (set.ext (λ i, ⟨λ hi, false.elim (not_lt_of_lt (H i) hi),
λ hi, false.elim (set.not_mem_empty i hi)⟩) : {y : ℝ | (y : ℝ*) < x} = ∅),
exact (real.Sup_empty).symm } }
end
theorem exists_st_iff_not_infinite {x : ℝ*} : (∃ r : ℝ, is_st x r) ↔ ¬ infinite x :=
⟨ not_infinite_of_exists_st, exists_st_of_not_infinite ⟩
theorem infinite_iff_not_exists_st {x : ℝ*} : infinite x ↔ ¬ ∃ r : ℝ, is_st x r :=
iff_not_comm.mp exists_st_iff_not_infinite
theorem st_infinite {x : ℝ*} (hi : infinite x) : st x = 0 :=
begin
unfold st, split_ifs,
{ exact false.elim ((infinite_iff_not_exists_st.mp hi) h) },
{ refl }
end
lemma st_of_is_st {x : ℝ*} {r : ℝ} (hxr : is_st x r) : st x = r :=
begin
unfold st, split_ifs,
{ exact is_st_unique (classical.some_spec h) hxr },
{ exact false.elim (h ⟨r, hxr⟩) }
end
lemma is_st_st_of_is_st {x : ℝ*} {r : ℝ} (hxr : is_st x r) : is_st x (st x) :=
by rwa [st_of_is_st hxr]
lemma is_st_st_of_exists_st {x : ℝ*} (hx : ∃ r : ℝ, is_st x r) : is_st x (st x) :=
Exists.dcases_on hx (λ r, is_st_st_of_is_st)
lemma is_st_st {x : ℝ*} (hx : st x ≠ 0) : is_st x (st x) :=
begin
unfold st, split_ifs,
{ exact classical.some_spec h },
{ exact false.elim (hx (by unfold st; split_ifs; refl)) }
end
lemma is_st_st' {x : ℝ*} (hx : ¬ infinite x) : is_st x (st x) :=
is_st_st_of_exists_st $ exists_st_of_not_infinite hx
lemma is_st_refl_real (r : ℝ) : is_st r r :=
λ δ hδ, ⟨ sub_lt_self _ (coe_lt_coe.2 hδ), (lt_add_of_pos_right _ (coe_lt_coe.2 hδ)) ⟩
lemma st_id_real (r : ℝ) : st r = r := st_of_is_st (is_st_refl_real r)
lemma eq_of_is_st_real {r s : ℝ} : is_st r s → r = s := is_st_unique (is_st_refl_real r)
lemma is_st_real_iff_eq {r s : ℝ} : is_st r s ↔ r = s :=
⟨eq_of_is_st_real, λ hrs, by rw [hrs]; exact is_st_refl_real s⟩
lemma is_st_symm_real {r s : ℝ} : is_st r s ↔ is_st s r :=
by rw [is_st_real_iff_eq, is_st_real_iff_eq, eq_comm]
lemma is_st_trans_real {r s t : ℝ} : is_st r s → is_st s t → is_st r t :=
by rw [is_st_real_iff_eq, is_st_real_iff_eq, is_st_real_iff_eq]; exact eq.trans
lemma is_st_inj_real {r₁ r₂ s : ℝ} (h1 : is_st r₁ s) (h2 : is_st r₂ s) : r₁ = r₂ :=
eq.trans (eq_of_is_st_real h1) (eq_of_is_st_real h2).symm
lemma is_st_iff_abs_sub_lt_delta {x : ℝ*} {r : ℝ} :
is_st x r ↔ ∀ (δ : ℝ), 0 < δ → abs (x - r) < δ :=
by simp only [abs_sub_lt_iff, @sub_lt _ _ (r : ℝ*) x _,
@sub_lt_iff_lt_add' _ _ x (r : ℝ*) _, and_comm]; refl
lemma is_st_add {x y : ℝ*} {r s : ℝ} : is_st x r → is_st y s → is_st (x + y) (r + s) :=
λ hxr hys d hd,
have hxr' : _ := hxr (d / 2) (half_pos hd),
have hys' : _ := hys (d / 2) (half_pos hd),
⟨by convert add_lt_add hxr'.1 hys'.1 using 1; norm_cast; linarith,
by convert add_lt_add hxr'.2 hys'.2 using 1; norm_cast; linarith⟩
lemma is_st_neg {x : ℝ*} {r : ℝ} (hxr : is_st x r) : is_st (-x) (-r) :=
λ d hd, by show -(r : ℝ*) - d < -x ∧ -x < -r + d; cases (hxr d hd); split; linarith
lemma is_st_sub {x y : ℝ*} {r s : ℝ} : is_st x r → is_st y s → is_st (x - y) (r - s) :=
λ hxr hys, by rw [sub_eq_add_neg, sub_eq_add_neg]; exact is_st_add hxr (is_st_neg hys)
/- (st x < st y) → (x < y) → (x ≤ y) → (st x ≤ st y) -/
lemma lt_of_is_st_lt {x y : ℝ*} {r s : ℝ} (hxr : is_st x r) (hys : is_st y s) :
r < s → x < y :=
λ hrs, have hrs' : 0 < (s - r) / 2 := half_pos (sub_pos.mpr hrs),
have hxr' : _ := (hxr _ hrs').2, have hys' : _ := (hys _ hrs').1,
have H1 : r + ((s - r) / 2) = (r + s) / 2 := by linarith,
have H2 : s - ((s - r) / 2) = (r + s) / 2 := by linarith,
begin
norm_cast at *,
rw H1 at hxr',
rw H2 at hys',
exact lt_trans hxr' hys'
end
lemma is_st_le_of_le {x y : ℝ*} {r s : ℝ} (hrx : is_st x r) (hsy : is_st y s) :
x ≤ y → r ≤ s := by rw [←not_lt, ←not_lt, not_imp_not]; exact lt_of_is_st_lt hsy hrx
lemma st_le_of_le {x y : ℝ*} (hix : ¬ infinite x) (hiy : ¬ infinite y) :
x ≤ y → st x ≤ st y :=
have hx' : _ := is_st_st' hix, have hy' : _ := is_st_st' hiy,
is_st_le_of_le hx' hy'
lemma lt_of_st_lt {x y : ℝ*} (hix : ¬ infinite x) (hiy : ¬ infinite y) :
st x < st y → x < y :=
have hx' : _ := is_st_st' hix, have hy' : _ := is_st_st' hiy,
lt_of_is_st_lt hx' hy'
/-!
### Basic lemmas about infinite
-/
lemma infinite_pos_def {x : ℝ*} : infinite_pos x ↔ ∀ r : ℝ, ↑r < x := by rw iff_eq_eq; refl
lemma infinite_neg_def {x : ℝ*} : infinite_neg x ↔ ∀ r : ℝ, x < r := by rw iff_eq_eq; refl
lemma ne_zero_of_infinite {x : ℝ*} : infinite x → x ≠ 0 :=
λ hI h0, or.cases_on hI
(λ hip, lt_irrefl (0 : ℝ*) ((by rwa ←h0 : infinite_pos 0) 0))
(λ hin, lt_irrefl (0 : ℝ*) ((by rwa ←h0 : infinite_neg 0) 0))
lemma not_infinite_zero : ¬ infinite 0 := λ hI, ne_zero_of_infinite hI rfl
lemma pos_of_infinite_pos {x : ℝ*} : infinite_pos x → 0 < x := λ hip, hip 0
lemma neg_of_infinite_neg {x : ℝ*} : infinite_neg x → x < 0 := λ hin, hin 0
lemma not_infinite_pos_of_infinite_neg {x : ℝ*} : infinite_neg x → ¬ infinite_pos x :=
λ hn hp, not_lt_of_lt (hn 1) (hp 1)
lemma not_infinite_neg_of_infinite_pos {x : ℝ*} : infinite_pos x → ¬ infinite_neg x :=
imp_not_comm.mp not_infinite_pos_of_infinite_neg
lemma infinite_neg_neg_of_infinite_pos {x : ℝ*} : infinite_pos x → infinite_neg (-x) :=
λ hp r, neg_lt.mp (hp (-r))
lemma infinite_pos_neg_of_infinite_neg {x : ℝ*} : infinite_neg x → infinite_pos (-x) :=
λ hp r, lt_neg.mp (hp (-r))
lemma infinite_pos_iff_infinite_neg_neg {x : ℝ*} : infinite_pos x ↔ infinite_neg (-x) :=
⟨ infinite_neg_neg_of_infinite_pos, λ hin, neg_neg x ▸ infinite_pos_neg_of_infinite_neg hin ⟩
lemma infinite_neg_iff_infinite_pos_neg {x : ℝ*} : infinite_neg x ↔ infinite_pos (-x) :=
⟨ infinite_pos_neg_of_infinite_neg, λ hin, neg_neg x ▸ infinite_neg_neg_of_infinite_pos hin ⟩
lemma infinite_iff_infinite_neg {x : ℝ*} : infinite x ↔ infinite (-x) :=
⟨ λ hi, or.cases_on hi
(λ hip, or.inr (infinite_neg_neg_of_infinite_pos hip))
(λ hin, or.inl (infinite_pos_neg_of_infinite_neg hin)),
λ hi, or.cases_on hi
(λ hipn, or.inr (infinite_neg_iff_infinite_pos_neg.mpr hipn))
(λ hinp, or.inl (infinite_pos_iff_infinite_neg_neg.mpr hinp))⟩
lemma not_infinite_of_infinitesimal {x : ℝ*} : infinitesimal x → ¬ infinite x :=
λ hi hI, have hi' : _ := (hi 2 zero_lt_two), or.dcases_on hI
(λ hip, have hip' : _ := hip 2, not_lt_of_lt hip' (by convert hi'.2; exact (zero_add 2).symm))
(λ hin, have hin' : _ := hin (-2), not_lt_of_lt hin' (by convert hi'.1; exact (zero_sub 2).symm))
lemma not_infinitesimal_of_infinite {x : ℝ*} : infinite x → ¬ infinitesimal x :=
imp_not_comm.mp not_infinite_of_infinitesimal
lemma not_infinitesimal_of_infinite_pos {x : ℝ*} : infinite_pos x → ¬ infinitesimal x :=
λ hp, not_infinitesimal_of_infinite (or.inl hp)
lemma not_infinitesimal_of_infinite_neg {x : ℝ*} : infinite_neg x → ¬ infinitesimal x :=
λ hn, not_infinitesimal_of_infinite (or.inr hn)
lemma infinite_pos_iff_infinite_and_pos {x : ℝ*} : infinite_pos x ↔ (infinite x ∧ 0 < x) :=
⟨ λ hip, ⟨or.inl hip, hip 0⟩,
λ ⟨hi, hp⟩, hi.cases_on (λ hip, hip) (λ hin, false.elim (not_lt_of_lt hp (hin 0))) ⟩
lemma infinite_neg_iff_infinite_and_neg {x : ℝ*} : infinite_neg x ↔ (infinite x ∧ x < 0) :=
⟨ λ hip, ⟨or.inr hip, hip 0⟩,
λ ⟨hi, hp⟩, hi.cases_on (λ hin, false.elim (not_lt_of_lt hp (hin 0))) (λ hip, hip) ⟩
lemma infinite_pos_iff_infinite_of_pos {x : ℝ*} (hp : 0 < x) : infinite_pos x ↔ infinite x :=
by rw [infinite_pos_iff_infinite_and_pos]; exact ⟨λ hI, hI.1, λ hI, ⟨hI, hp⟩⟩
lemma infinite_pos_iff_infinite_of_nonneg {x : ℝ*} (hp : 0 ≤ x) : infinite_pos x ↔ infinite x :=
or.cases_on (lt_or_eq_of_le hp) (infinite_pos_iff_infinite_of_pos)
(λ h, by rw h.symm; exact
⟨λ hIP, false.elim (not_infinite_zero (or.inl hIP)), λ hI, false.elim (not_infinite_zero hI)⟩)
lemma infinite_neg_iff_infinite_of_neg {x : ℝ*} (hn : x < 0) : infinite_neg x ↔ infinite x :=
by rw [infinite_neg_iff_infinite_and_neg]; exact ⟨λ hI, hI.1, λ hI, ⟨hI, hn⟩⟩
lemma infinite_pos_abs_iff_infinite_abs {x : ℝ*} : infinite_pos (abs x) ↔ infinite (abs x) :=
infinite_pos_iff_infinite_of_nonneg (abs_nonneg _)
lemma infinite_iff_infinite_pos_abs {x : ℝ*} : infinite x ↔ infinite_pos (abs x) :=
⟨ λ hi d, or.cases_on hi
(λ hip, by rw [abs_of_pos (hip 0)]; exact hip d)
(λ hin, by rw [abs_of_neg (hin 0)]; exact lt_neg.mp (hin (-d))),
λ hipa, by { rcases (lt_trichotomy x 0) with h | h | h,
{ exact or.inr (infinite_neg_iff_infinite_pos_neg.mpr (by rwa abs_of_neg h at hipa)) },
{ exact false.elim (ne_zero_of_infinite (or.inl (by rw [h]; rwa [h, abs_zero] at hipa)) h) },
{ exact or.inl (by rwa abs_of_pos h at hipa) } } ⟩
lemma infinite_iff_infinite_abs {x : ℝ*} : infinite x ↔ infinite (abs x) :=
by rw [←infinite_pos_iff_infinite_of_nonneg (abs_nonneg _), infinite_iff_infinite_pos_abs]
lemma infinite_iff_abs_lt_abs {x : ℝ*} : infinite x ↔ ∀ r : ℝ, (abs r : ℝ*) < abs x :=
⟨ λ hI r, (coe_abs r) ▸ infinite_iff_infinite_pos_abs.mp hI (abs r),
λ hR, or.cases_on (max_choice x (-x))
(λ h, or.inl $ λ r, lt_of_le_of_lt (le_abs_self _) (h ▸ (hR r)))
(λ h, or.inr $ λ r, neg_lt_neg_iff.mp $ lt_of_le_of_lt (neg_le_abs_self _) (h ▸ (hR r)))⟩
lemma infinite_pos_add_not_infinite_neg {x y : ℝ*} :
infinite_pos x → ¬ infinite_neg y → infinite_pos (x + y) :=
begin
intros hip hnin r,
cases not_forall.mp hnin with r₂ hr₂,
convert add_lt_add_of_lt_of_le (hip (r + -r₂)) (not_lt.mp hr₂) using 1,
simp
end
lemma not_infinite_neg_add_infinite_pos {x y : ℝ*} :
¬ infinite_neg x → infinite_pos y → infinite_pos (x + y) :=
λ hx hy, by rw [add_comm]; exact infinite_pos_add_not_infinite_neg hy hx
lemma infinite_neg_add_not_infinite_pos {x y : ℝ*} :
infinite_neg x → ¬ infinite_pos y → infinite_neg (x + y) :=
by rw [@infinite_neg_iff_infinite_pos_neg x, @infinite_pos_iff_infinite_neg_neg y,
@infinite_neg_iff_infinite_pos_neg (x + y), neg_add];
exact infinite_pos_add_not_infinite_neg
lemma not_infinite_pos_add_infinite_neg {x y : ℝ*} :
¬ infinite_pos x → infinite_neg y → infinite_neg (x + y) :=
λ hx hy, by rw [add_comm]; exact infinite_neg_add_not_infinite_pos hy hx
lemma infinite_pos_add_infinite_pos {x y : ℝ*} :
infinite_pos x → infinite_pos y → infinite_pos (x + y) :=
λ hx hy, infinite_pos_add_not_infinite_neg hx (not_infinite_neg_of_infinite_pos hy)
lemma infinite_neg_add_infinite_neg {x y : ℝ*} :
infinite_neg x → infinite_neg y → infinite_neg (x + y) :=
λ hx hy, infinite_neg_add_not_infinite_pos hx (not_infinite_pos_of_infinite_neg hy)
lemma infinite_pos_add_not_infinite {x y : ℝ*} :
infinite_pos x → ¬ infinite y → infinite_pos (x + y) :=
λ hx hy, infinite_pos_add_not_infinite_neg hx (not_or_distrib.mp hy).2
lemma infinite_neg_add_not_infinite {x y : ℝ*} :
infinite_neg x → ¬ infinite y → infinite_neg (x + y) :=
λ hx hy, infinite_neg_add_not_infinite_pos hx (not_or_distrib.mp hy).1
theorem infinite_pos_of_tendsto_top {f : ℕ → ℝ} (hf : tendsto f at_top at_top) :
infinite_pos (of_seq f) :=
λ r, have hf' : _ := tendsto_at_top_at_top.mp hf,
Exists.cases_on (hf' (r + 1)) $ λ i hi,
have hi' : ∀ (a : ℕ), f a < (r + 1) → a < i :=
λ a, by rw [←not_le, ←not_le]; exact not_imp_not.mpr (hi a),
have hS : {a : ℕ | r < f a}ᶜ ⊆ {a : ℕ | a ≤ i} :=
by simp only [set.compl_set_of, not_lt];
exact λ a har, le_of_lt (hi' a (lt_of_le_of_lt har (lt_add_one _))),
germ.coe_lt.2 $ mem_hyperfilter_of_finite_compl $
(set.finite_le_nat _).subset hS
theorem infinite_neg_of_tendsto_bot {f : ℕ → ℝ} (hf : tendsto f at_top at_bot) :
infinite_neg (of_seq f) :=
λ r, have hf' : _ := tendsto_at_top_at_bot.mp hf,
Exists.cases_on (hf' (r - 1)) $ λ i hi,
have hi' : ∀ (a : ℕ), r - 1 < f a → a < i :=
λ a, by rw [←not_le, ←not_le]; exact not_imp_not.mpr (hi a),
have hS : {a : ℕ | f a < r}ᶜ ⊆ {a : ℕ | a ≤ i} :=
by simp only [set.compl_set_of, not_lt];
exact λ a har, le_of_lt (hi' a (lt_of_lt_of_le (sub_one_lt _) har)),
germ.coe_lt.2 $ mem_hyperfilter_of_finite_compl $
(set.finite_le_nat _).subset hS
lemma not_infinite_neg {x : ℝ*} : ¬ infinite x → ¬ infinite (-x) :=
not_imp_not.mpr infinite_iff_infinite_neg.mpr
lemma not_infinite_add {x y : ℝ*} (hx : ¬ infinite x) (hy : ¬ infinite y) :
¬ infinite (x + y) :=
have hx' : _ := exists_st_of_not_infinite hx, have hy' : _ := exists_st_of_not_infinite hy,
Exists.cases_on hx' $ Exists.cases_on hy' $
λ r hr s hs, not_infinite_of_exists_st $ ⟨s + r, is_st_add hs hr⟩
theorem not_infinite_iff_exist_lt_gt {x : ℝ*} : ¬ infinite x ↔ ∃ r s : ℝ, (r : ℝ*) < x ∧ x < s :=
⟨ λ hni,
Exists.dcases_on (not_forall.mp (not_or_distrib.mp hni).1) $
Exists.dcases_on (not_forall.mp (not_or_distrib.mp hni).2) $ λ r hr s hs,
by rw [not_lt] at hr hs; exact ⟨r - 1, s + 1,
⟨ lt_of_lt_of_le (by rw sub_eq_add_neg; norm_num) hr,
lt_of_le_of_lt hs (by norm_num)⟩ ⟩,
λ hrs, Exists.dcases_on hrs $ λ r hr, Exists.dcases_on hr $ λ s hs,
not_or_distrib.mpr ⟨not_forall.mpr ⟨s, lt_asymm (hs.2)⟩, not_forall.mpr ⟨r, lt_asymm (hs.1) ⟩⟩⟩
theorem not_infinite_real (r : ℝ) : ¬ infinite r := by rw not_infinite_iff_exist_lt_gt; exact
⟨ r - 1, r + 1, coe_lt_coe.2 $ sub_one_lt r, coe_lt_coe.2 $ lt_add_one r⟩
theorem not_real_of_infinite {x : ℝ*} : infinite x → ∀ r : ℝ, x ≠ r :=
λ hi r hr, not_infinite_real r $ @eq.subst _ infinite _ _ hr hi
/-!
### Facts about `st` that require some infinite machinery
-/
private lemma is_st_mul' {x y : ℝ*} {r s : ℝ} (hxr : is_st x r) (hys : is_st y s) (hs : s ≠ 0) :
is_st (x * y) (r * s) :=
have hxr' : _ := is_st_iff_abs_sub_lt_delta.mp hxr,
have hys' : _ := is_st_iff_abs_sub_lt_delta.mp hys,
have h : _ := not_infinite_iff_exist_lt_gt.mp $ not_imp_not.mpr infinite_iff_infinite_abs.mpr $
not_infinite_of_exists_st ⟨r, hxr⟩,
Exists.cases_on h $ λ u h', Exists.cases_on h' $ λ t ⟨hu, ht⟩,
is_st_iff_abs_sub_lt_delta.mpr $ λ d hd,
calc abs (x * y - r * s)
= abs (x * (y - s) + (x - r) * s) :
by rw [mul_sub, sub_mul, add_sub, sub_add_cancel]
... ≤ abs (x * (y - s)) + abs ((x - r) * s) : abs_add _ _
... ≤ abs x * abs (y - s) + abs (x - r) * abs s : by simp only [abs_mul]
... ≤ abs x * ((d / t) / 2 : ℝ) + ((d / abs s) / 2 : ℝ) * abs s : add_le_add
(mul_le_mul_of_nonneg_left (le_of_lt $ hys' _ $ half_pos $ div_pos hd $
coe_pos.1 $ lt_of_le_of_lt (abs_nonneg x) ht) $ abs_nonneg _)
(mul_le_mul_of_nonneg_right (le_of_lt $ hxr' _ $ half_pos $ div_pos hd $
abs_pos.2 hs) $ abs_nonneg _)
... = (d / 2 * (abs x / t) + d / 2 : ℝ*) : by
{ push_cast [-filter.germ.const_div], -- TODO: Why wasn't `hyperreal.coe_div` used?
have : (abs s : ℝ*) ≠ 0, by simpa,
have : (2 : ℝ*) ≠ 0 := two_ne_zero,
field_simp [*, add_mul, mul_add, mul_assoc, mul_comm, mul_left_comm] }
... < (d / 2 * 1 + d / 2 : ℝ*) :
add_lt_add_right (mul_lt_mul_of_pos_left
((div_lt_one $ lt_of_le_of_lt (abs_nonneg x) ht).mpr ht) $
half_pos $ coe_pos.2 hd) _
... = (d : ℝ*) : by rw [mul_one, add_halves]
lemma is_st_mul {x y : ℝ*} {r s : ℝ} (hxr : is_st x r) (hys : is_st y s) :
is_st (x * y) (r * s) :=
have h : _ := not_infinite_iff_exist_lt_gt.mp $
not_imp_not.mpr infinite_iff_infinite_abs.mpr $ not_infinite_of_exists_st ⟨r, hxr⟩,
Exists.cases_on h $ λ u h', Exists.cases_on h' $ λ t ⟨hu, ht⟩,
begin
by_cases hs : s = 0,
{ apply is_st_iff_abs_sub_lt_delta.mpr, intros d hd,
have hys' : _ := is_st_iff_abs_sub_lt_delta.mp hys (d / t)
(div_pos hd (coe_pos.1 (lt_of_le_of_lt (abs_nonneg x) ht))),
rw [hs, coe_zero, sub_zero] at hys',
rw [hs, mul_zero, coe_zero, sub_zero, abs_mul, mul_comm,
←div_mul_cancel (d : ℝ*) (ne_of_gt (lt_of_le_of_lt (abs_nonneg x) ht)),
←coe_div],
exact mul_lt_mul'' hys' ht (abs_nonneg _) (abs_nonneg _) },
exact is_st_mul' hxr hys hs,
end
--AN INFINITE LEMMA THAT REQUIRES SOME MORE ST MACHINERY
lemma not_infinite_mul {x y : ℝ*} (hx : ¬ infinite x) (hy : ¬ infinite y) :
¬ infinite (x * y) :=
have hx' : _ := exists_st_of_not_infinite hx, have hy' : _ := exists_st_of_not_infinite hy,
Exists.cases_on hx' $ Exists.cases_on hy' $ λ r hr s hs, not_infinite_of_exists_st $
⟨s * r, is_st_mul hs hr⟩
---
lemma st_add {x y : ℝ*} (hx : ¬infinite x) (hy : ¬infinite y) : st (x + y) = st x + st y :=
have hx' : _ := is_st_st' hx,
have hy' : _ := is_st_st' hy,
have hxy : _ := is_st_st' (not_infinite_add hx hy),
have hxy' : _ := is_st_add hx' hy',
is_st_unique hxy hxy'
lemma st_neg (x : ℝ*) : st (-x) = - st x :=
if h : infinite x
then by rw [st_infinite h, st_infinite (infinite_iff_infinite_neg.mp h), neg_zero]
else is_st_unique (is_st_st' (not_infinite_neg h)) (is_st_neg (is_st_st' h))
lemma st_mul {x y : ℝ*} (hx : ¬infinite x) (hy : ¬infinite y) : st (x * y) = (st x) * (st y) :=
have hx' : _ := is_st_st' hx,
have hy' : _ := is_st_st' hy,
have hxy : _ := is_st_st' (not_infinite_mul hx hy),
have hxy' : _ := is_st_mul hx' hy',
is_st_unique hxy hxy'
/-!
### Basic lemmas about infinitesimal
-/
theorem infinitesimal_def {x : ℝ*} :
infinitesimal x ↔ (∀ r : ℝ, 0 < r → -(r : ℝ*) < x ∧ x < r) :=
⟨ λ hi r hr, by { convert (hi r hr); simp },
λ hi d hd, by { convert (hi d hd); simp } ⟩
theorem lt_of_pos_of_infinitesimal {x : ℝ*} : infinitesimal x → ∀ r : ℝ, 0 < r → x < r :=
λ hi r hr, ((infinitesimal_def.mp hi) r hr).2
theorem lt_neg_of_pos_of_infinitesimal {x : ℝ*} : infinitesimal x → ∀ r : ℝ, 0 < r → -↑r < x :=
λ hi r hr, ((infinitesimal_def.mp hi) r hr).1
theorem gt_of_neg_of_infinitesimal {x : ℝ*} : infinitesimal x → ∀ r : ℝ, r < 0 → ↑r < x :=
λ hi r hr, by convert ((infinitesimal_def.mp hi) (-r) (neg_pos.mpr hr)).1;
exact (neg_neg ↑r).symm
theorem abs_lt_real_iff_infinitesimal {x : ℝ*} :
infinitesimal x ↔ ∀ r : ℝ, r ≠ 0 → abs x < abs r :=
⟨ λ hi r hr, abs_lt.mpr (by rw ←coe_abs;
exact infinitesimal_def.mp hi (abs r) (abs_pos.2 hr)),
λ hR, infinitesimal_def.mpr $ λ r hr, abs_lt.mp $
(abs_of_pos $ coe_pos.2 hr) ▸ hR r $ ne_of_gt hr ⟩
lemma infinitesimal_zero : infinitesimal 0 := is_st_refl_real 0
lemma zero_of_infinitesimal_real {r : ℝ} : infinitesimal r → r = 0 := eq_of_is_st_real
lemma zero_iff_infinitesimal_real {r : ℝ} : infinitesimal r ↔ r = 0 :=
⟨zero_of_infinitesimal_real, λ hr, by rw hr; exact infinitesimal_zero⟩
lemma infinitesimal_add {x y : ℝ*} (hx : infinitesimal x) (hy : infinitesimal y) :
infinitesimal (x + y) :=
by simpa only [add_zero] using is_st_add hx hy
lemma infinitesimal_neg {x : ℝ*} (hx : infinitesimal x) : infinitesimal (-x) :=
by simpa only [neg_zero] using is_st_neg hx
lemma infinitesimal_neg_iff {x : ℝ*} : infinitesimal x ↔ infinitesimal (-x) :=
⟨infinitesimal_neg, λ h, (neg_neg x) ▸ @infinitesimal_neg (-x) h⟩
lemma infinitesimal_mul {x y : ℝ*} (hx : infinitesimal x) (hy : infinitesimal y) :
infinitesimal (x * y) :=
by simpa only [mul_zero] using is_st_mul hx hy
theorem infinitesimal_of_tendsto_zero {f : ℕ → ℝ} :
tendsto f at_top (𝓝 0) → infinitesimal (of_seq f) :=
λ hf d hd, by rw [sub_eq_add_neg, ←coe_neg, ←coe_add, ←coe_add, zero_add, zero_add];
exact ⟨neg_lt_of_tendsto_zero_of_pos hf hd, lt_of_tendsto_zero_of_pos hf hd⟩
theorem infinitesimal_epsilon : infinitesimal ε :=
infinitesimal_of_tendsto_zero tendsto_inverse_at_top_nhds_0_nat
lemma not_real_of_infinitesimal_ne_zero (x : ℝ*) :
infinitesimal x → x ≠ 0 → ∀ r : ℝ, x ≠ r :=
λ hi hx r hr, hx $ hr.trans $ coe_eq_zero.2 $
is_st_unique (hr.symm ▸ is_st_refl_real r : is_st x r) hi
theorem infinitesimal_sub_is_st {x : ℝ*} {r : ℝ} (hxr : is_st x r) : infinitesimal (x - r) :=
show is_st (x - r) 0,
by { rw [sub_eq_add_neg, ← add_neg_self r], exact is_st_add hxr (is_st_refl_real (-r)) }
theorem infinitesimal_sub_st {x : ℝ*} (hx : ¬infinite x) : infinitesimal (x - st x) :=
infinitesimal_sub_is_st $ is_st_st' hx
lemma infinite_pos_iff_infinitesimal_inv_pos {x : ℝ*} :
infinite_pos x ↔ (infinitesimal x⁻¹ ∧ 0 < x⁻¹) :=
⟨ λ hip, ⟨ infinitesimal_def.mpr $ λ r hr,
⟨ lt_trans (coe_lt_coe.2 (neg_neg_of_pos hr)) (inv_pos.2 (hip 0)),
(inv_lt (coe_lt_coe.2 hr) (hip 0)).mp (by convert hip r⁻¹) ⟩,
inv_pos.2 $ hip 0 ⟩,
λ ⟨hi, hp⟩ r, @classical.by_cases (r = 0) (↑r < x) (λ h, eq.substr h (inv_pos.mp hp)) $
λ h, lt_of_le_of_lt (coe_le_coe.2 (le_abs_self r))
((inv_lt_inv (inv_pos.mp hp) (coe_lt_coe.2 (abs_pos.2 h))).mp
((infinitesimal_def.mp hi) ((abs r)⁻¹) (inv_pos.2 (abs_pos.2 h))).2) ⟩
lemma infinite_neg_iff_infinitesimal_inv_neg {x : ℝ*} :
infinite_neg x ↔ (infinitesimal x⁻¹ ∧ x⁻¹ < 0) :=
⟨ λ hin, have hin' : _ := infinite_pos_iff_infinitesimal_inv_pos.mp
(infinite_pos_neg_of_infinite_neg hin),
by rwa [infinitesimal_neg_iff, ←neg_pos, neg_inv],
λ hin, by rwa [←neg_pos, infinitesimal_neg_iff, neg_inv,
←infinite_pos_iff_infinitesimal_inv_pos, ←infinite_neg_iff_infinite_pos_neg] at hin ⟩
theorem infinitesimal_inv_of_infinite {x : ℝ*} : infinite x → infinitesimal x⁻¹ :=
λ hi, or.cases_on hi
(λ hip, (infinite_pos_iff_infinitesimal_inv_pos.mp hip).1)
(λ hin, (infinite_neg_iff_infinitesimal_inv_neg.mp hin).1)
theorem infinite_of_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) (hi : infinitesimal x⁻¹ ) :
infinite x :=
begin
cases (lt_or_gt_of_ne h0) with hn hp,
{ exact or.inr (infinite_neg_iff_infinitesimal_inv_neg.mpr ⟨hi, inv_lt_zero.mpr hn⟩) },
{ exact or.inl (infinite_pos_iff_infinitesimal_inv_pos.mpr ⟨hi, inv_pos.mpr hp⟩) }
end
theorem infinite_iff_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) : infinite x ↔ infinitesimal x⁻¹ :=
⟨ infinitesimal_inv_of_infinite, infinite_of_infinitesimal_inv h0 ⟩
lemma infinitesimal_pos_iff_infinite_pos_inv {x : ℝ*} :
infinite_pos x⁻¹ ↔ (infinitesimal x ∧ 0 < x) :=
by convert infinite_pos_iff_infinitesimal_inv_pos; simp only [inv_inv']
lemma infinitesimal_neg_iff_infinite_neg_inv {x : ℝ*} :
infinite_neg x⁻¹ ↔ (infinitesimal x ∧ x < 0) :=
by convert infinite_neg_iff_infinitesimal_inv_neg; simp only [inv_inv']
theorem infinitesimal_iff_infinite_inv {x : ℝ*} (h : x ≠ 0) : infinitesimal x ↔ infinite x⁻¹ :=
by convert (infinite_iff_infinitesimal_inv (inv_ne_zero h)).symm; simp only [inv_inv']
/-!
### `st` stuff that requires infinitesimal machinery
-/
theorem is_st_of_tendsto {f : ℕ → ℝ} {r : ℝ} (hf : tendsto f at_top (𝓝 r)) :
is_st (of_seq f) r :=
have hg : tendsto (λ n, f n - r) at_top (𝓝 0) :=
(sub_self r) ▸ (hf.sub tendsto_const_nhds),
by rw [←(zero_add r), ←(sub_add_cancel f (λ n, r))];
exact is_st_add (infinitesimal_of_tendsto_zero hg) (is_st_refl_real r)
lemma is_st_inv {x : ℝ*} {r : ℝ} (hi : ¬ infinitesimal x) : is_st x r → is_st x⁻¹ r⁻¹ :=
λ hxr, have h : x ≠ 0 := (λ h, hi (h.symm ▸ infinitesimal_zero)),
have H : _ := exists_st_of_not_infinite $ not_imp_not.mpr (infinitesimal_iff_infinite_inv h).mpr hi,
Exists.cases_on H $ λ s hs,
have H' : is_st 1 (r * s) := mul_inv_cancel h ▸ is_st_mul hxr hs,
have H'' : s = r⁻¹ := one_div r ▸ eq_one_div_of_mul_eq_one (eq_of_is_st_real H').symm,
H'' ▸ hs
lemma st_inv (x : ℝ*) : st x⁻¹ = (st x)⁻¹ :=
begin
by_cases h0 : x = 0,
rw [h0, inv_zero, ←coe_zero, st_id_real, inv_zero],
by_cases h1 : infinitesimal x,
rw [st_infinite ((infinitesimal_iff_infinite_inv h0).mp h1), st_of_is_st h1, inv_zero],
by_cases h2 : infinite x,
rw [st_of_is_st (infinitesimal_inv_of_infinite h2), st_infinite h2, inv_zero],
exact st_of_is_st (is_st_inv h1 (is_st_st' h2)),
end
/-!
### Infinite stuff that requires infinitesimal machinery
-/
lemma infinite_pos_omega : infinite_pos ω :=
infinite_pos_iff_infinitesimal_inv_pos.mpr ⟨infinitesimal_epsilon, epsilon_pos⟩
lemma infinite_omega : infinite ω :=
(infinite_iff_infinitesimal_inv omega_ne_zero).mpr infinitesimal_epsilon
lemma infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos {x y : ℝ*} :
infinite_pos x → ¬ infinitesimal y → 0 < y → infinite_pos (x * y) :=
λ hx hy₁ hy₂ r, have hy₁' : _ := not_forall.mp (by rw infinitesimal_def at hy₁; exact hy₁),
Exists.dcases_on hy₁' $ λ r₁ hy₁'',
have hyr : _ := by rw [not_imp, ←abs_lt, not_lt, abs_of_pos hy₂] at hy₁''; exact hy₁'',
by rw [←div_mul_cancel r (ne_of_gt hyr.1), coe_mul];
exact mul_lt_mul (hx (r / r₁)) hyr.2 (coe_lt_coe.2 hyr.1) (le_of_lt (hx 0))
lemma infinite_pos_mul_of_not_infinitesimal_pos_infinite_pos {x y : ℝ*} :
¬ infinitesimal x → 0 < x → infinite_pos y → infinite_pos (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos hy hx hp
lemma infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg {x y : ℝ*} :
infinite_neg x → ¬ infinitesimal y → y < 0 → infinite_pos (x * y) :=
by rw [infinite_neg_iff_infinite_pos_neg, ←neg_pos, ←neg_mul_neg, infinitesimal_neg_iff];
exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
lemma infinite_pos_mul_of_not_infinitesimal_neg_infinite_neg {x y : ℝ*} :
¬ infinitesimal x → x < 0 → infinite_neg y → infinite_pos (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg hy hx hp
lemma infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg {x y : ℝ*} :
infinite_pos x → ¬ infinitesimal y → y < 0 → infinite_neg (x * y) :=
by rw [infinite_neg_iff_infinite_pos_neg, ←neg_pos, neg_mul_eq_mul_neg, infinitesimal_neg_iff];
exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
lemma infinite_neg_mul_of_not_infinitesimal_neg_infinite_pos {x y : ℝ*} :
¬ infinitesimal x → x < 0 → infinite_pos y → infinite_neg (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg hy hx hp
lemma infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos {x y : ℝ*} :
infinite_neg x → ¬ infinitesimal y → 0 < y → infinite_neg (x * y) :=
by rw [infinite_neg_iff_infinite_pos_neg, infinite_neg_iff_infinite_pos_neg, neg_mul_eq_neg_mul];
exact infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
lemma infinite_neg_mul_of_not_infinitesimal_pos_infinite_neg {x y : ℝ*} :
¬ infinitesimal x → 0 < x → infinite_neg y → infinite_neg (x * y) :=
λ hx hp hy, by rw mul_comm; exact infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos hy hx hp
lemma infinite_pos_mul_infinite_pos {x y : ℝ*} :
infinite_pos x → infinite_pos y → infinite_pos (x * y) :=
λ hx hy, infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos
hx (not_infinitesimal_of_infinite_pos hy) (hy 0)
lemma infinite_neg_mul_infinite_neg {x y : ℝ*} :
infinite_neg x → infinite_neg y → infinite_pos (x * y) :=
λ hx hy, infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg
hx (not_infinitesimal_of_infinite_neg hy) (hy 0)
lemma infinite_pos_mul_infinite_neg {x y : ℝ*} :
infinite_pos x → infinite_neg y → infinite_neg (x * y) :=
λ hx hy, infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg
hx (not_infinitesimal_of_infinite_neg hy) (hy 0)
lemma infinite_neg_mul_infinite_pos {x y : ℝ*} :
infinite_neg x → infinite_pos y → infinite_neg (x * y) :=
λ hx hy, infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos
hx (not_infinitesimal_of_infinite_pos hy) (hy 0)
lemma infinite_mul_of_infinite_not_infinitesimal {x y : ℝ*} :
infinite x → ¬ infinitesimal y → infinite (x * y) :=
λ hx hy, have h0 : y < 0 ∨ 0 < y := lt_or_gt_of_ne (λ H0, hy (eq.substr H0 (is_st_refl_real 0))),
or.dcases_on hx
(or.dcases_on h0
(λ H0 Hx, or.inr (infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg Hx hy H0))
(λ H0 Hx, or.inl (infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos Hx hy H0)))
(or.dcases_on h0
(λ H0 Hx, or.inl (infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg Hx hy H0))
(λ H0 Hx, or.inr (infinite_neg_mul_of_infinite_neg_not_infinitesimal_pos Hx hy H0)))
lemma infinite_mul_of_not_infinitesimal_infinite {x y : ℝ*} :
¬ infinitesimal x → infinite y → infinite (x * y) :=
λ hx hy, by rw [mul_comm]; exact infinite_mul_of_infinite_not_infinitesimal hy hx
lemma infinite_mul_infinite {x y : ℝ*} : infinite x → infinite y → infinite (x * y) :=
λ hx hy, infinite_mul_of_infinite_not_infinitesimal hx (not_infinitesimal_of_infinite hy)
end hyperreal
|
fb4e472c261fb6bcd93f00033724fc27dae31ac8 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/algebra/char_p/basic.lean | fc012e14d75fca853759e6b105340e9073c83bfa | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 15,793 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Joey van Langen, Casper Putz
-/
import data.nat.choose
import data.int.modeq
import algebra.iterate_hom
import group_theory.order_of_element
/-!
# Characteristic of semirings
-/
universes u v
variables (R : Type u)
/-- The generator of the kernel of the unique homomorphism ℕ → R for a semiring R -/
class char_p [add_monoid R] [has_one R] (p : ℕ) : Prop :=
(cast_eq_zero_iff [] : ∀ x:ℕ, (x:R) = 0 ↔ p ∣ x)
theorem char_p.cast_eq_zero [add_monoid R] [has_one R] (p : ℕ) [char_p R p] :
(p:R) = 0 :=
(char_p.cast_eq_zero_iff R p p).2 (dvd_refl p)
@[simp] lemma char_p.cast_card_eq_zero [add_group R] [has_one R] [fintype R] :
(fintype.card R : R) = 0 :=
by rw [← nsmul_one, card_nsmul_eq_zero]
lemma char_p.int_cast_eq_zero_iff [add_group R] [has_one R] (p : ℕ) [char_p R p]
(a : ℤ) :
(a : R) = 0 ↔ (p:ℤ) ∣ a :=
begin
rcases lt_trichotomy a 0 with h|rfl|h,
{ rw [← neg_eq_zero, ← int.cast_neg, ← dvd_neg],
lift -a to ℕ using neg_nonneg.mpr (le_of_lt h) with b,
rw [int.cast_coe_nat, char_p.cast_eq_zero_iff R p, int.coe_nat_dvd] },
{ simp only [int.cast_zero, eq_self_iff_true, dvd_zero] },
{ lift a to ℕ using (le_of_lt h) with b,
rw [int.cast_coe_nat, char_p.cast_eq_zero_iff R p, int.coe_nat_dvd] }
end
lemma char_p.int_coe_eq_int_coe_iff [add_group R] [has_one R] (p : ℕ) [char_p R p] (a b : ℤ) :
(a : R) = (b : R) ↔ a ≡ b [ZMOD p] :=
by rw [eq_comm, ←sub_eq_zero, ←int.cast_sub,
char_p.int_cast_eq_zero_iff R p, int.modeq.modeq_iff_dvd]
theorem char_p.eq [add_monoid R] [has_one R] {p q : ℕ} (c1 : char_p R p) (c2 : char_p R q) :
p = q :=
nat.dvd_antisymm
((char_p.cast_eq_zero_iff R p q).1 (char_p.cast_eq_zero _ _))
((char_p.cast_eq_zero_iff R q p).1 (char_p.cast_eq_zero _ _))
instance char_p.of_char_zero [add_monoid R] [has_one R] [char_zero R] : char_p R 0 :=
⟨λ x, by rw [zero_dvd_iff, ← nat.cast_zero, nat.cast_inj]⟩
theorem char_p.exists [non_assoc_semiring R] : ∃ p, char_p R p :=
by letI := classical.dec_eq R; exact
classical.by_cases
(assume H : ∀ p:ℕ, (p:R) = 0 → p = 0, ⟨0,
⟨λ x, by rw [zero_dvd_iff]; exact ⟨H x, by rintro rfl; refl⟩⟩⟩)
(λ H, ⟨nat.find (not_forall.1 H), ⟨λ x,
⟨λ H1, nat.dvd_of_mod_eq_zero (by_contradiction $ λ H2,
nat.find_min (not_forall.1 H)
(nat.mod_lt x $ nat.pos_of_ne_zero $ not_of_not_imp $
nat.find_spec (not_forall.1 H))
(not_imp_of_and_not ⟨by rwa [← nat.mod_add_div x (nat.find (not_forall.1 H)),
nat.cast_add, nat.cast_mul, of_not_not (not_not_of_not_imp $ nat.find_spec
(not_forall.1 H)),
zero_mul, add_zero] at H1, H2⟩)),
λ H1, by rw [← nat.mul_div_cancel' H1, nat.cast_mul,
of_not_not (not_not_of_not_imp $ nat.find_spec (not_forall.1 H)), zero_mul]⟩⟩⟩)
theorem char_p.exists_unique [non_assoc_semiring R] : ∃! p, char_p R p :=
let ⟨c, H⟩ := char_p.exists R in ⟨c, H, λ y H2, char_p.eq R H2 H⟩
theorem char_p.congr {R : Type u} [add_monoid R] [has_one R] {p : ℕ} (q : ℕ) [hq : char_p R q]
(h : q = p) :
char_p R p :=
h ▸ hq
/-- Noncomputable function that outputs the unique characteristic of a semiring. -/
noncomputable def ring_char [non_assoc_semiring R] : ℕ :=
classical.some (char_p.exists_unique R)
namespace ring_char
variables [non_assoc_semiring R]
theorem spec : ∀ x:ℕ, (x:R) = 0 ↔ ring_char R ∣ x :=
by letI := (classical.some_spec (char_p.exists_unique R)).1;
unfold ring_char; exact char_p.cast_eq_zero_iff R (ring_char R)
theorem eq {p : ℕ} (C : char_p R p) : p = ring_char R :=
(classical.some_spec (char_p.exists_unique R)).2 p C
instance char_p : char_p R (ring_char R) :=
⟨spec R⟩
variables {R}
theorem of_eq {p : ℕ} (h : ring_char R = p) : char_p R p :=
char_p.congr (ring_char R) h
theorem eq_iff {p : ℕ} : ring_char R = p ↔ char_p R p :=
⟨of_eq, eq.symm ∘ eq R⟩
theorem dvd {x : ℕ} (hx : (x : R) = 0) : ring_char R ∣ x :=
(spec R x).1 hx
@[simp]
lemma eq_zero [char_zero R] : ring_char R = 0 := (eq R (char_p.of_char_zero R)).symm
end ring_char
theorem add_pow_char_of_commute [semiring R] {p : ℕ} [fact p.prime]
[char_p R p] (x y : R) (h : commute x y) :
(x + y)^p = x^p + y^p :=
begin
rw [commute.add_pow h, finset.sum_range_succ_comm, nat.sub_self, pow_zero, nat.choose_self],
rw [nat.cast_one, mul_one, mul_one], congr' 1,
convert finset.sum_eq_single 0 _ _,
{ simp only [mul_one, one_mul, nat.choose_zero_right, nat.sub_zero, nat.cast_one, pow_zero] },
{ intros b h1 h2,
suffices : (p.choose b : R) = 0, { rw this, simp },
rw char_p.cast_eq_zero_iff R p,
refine nat.prime.dvd_choose_self (pos_iff_ne_zero.mpr h2) _ (fact.out _),
rwa ← finset.mem_range },
{ intro h1,
contrapose! h1,
rw finset.mem_range,
exact nat.prime.pos (fact.out _) }
end
theorem add_pow_char_pow_of_commute [semiring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) (h : commute x y) :
(x + y) ^ (p ^ n) = x ^ (p ^ n) + y ^ (p ^ n) :=
begin
induction n, { simp, },
rw [pow_succ', pow_mul, pow_mul, pow_mul, n_ih],
apply add_pow_char_of_commute, apply commute.pow_pow h,
end
theorem sub_pow_char_of_commute [ring R] {p : ℕ} [fact p.prime]
[char_p R p] (x y : R) (h : commute x y) :
(x - y)^p = x^p - y^p :=
begin
rw [eq_sub_iff_add_eq, ← add_pow_char_of_commute _ _ _ (commute.sub_left h rfl)],
simp, repeat {apply_instance},
end
theorem sub_pow_char_pow_of_commute [ring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) (h : commute x y) :
(x - y) ^ (p ^ n) = x ^ (p ^ n) - y ^ (p ^ n) :=
begin
induction n, { simp, },
rw [pow_succ', pow_mul, pow_mul, pow_mul, n_ih],
apply sub_pow_char_of_commute, apply commute.pow_pow h,
end
theorem add_pow_char [comm_semiring R] {p : ℕ} [fact p.prime]
[char_p R p] (x y : R) : (x + y)^p = x^p + y^p :=
add_pow_char_of_commute _ _ _ (commute.all _ _)
theorem add_pow_char_pow [comm_semiring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) :
(x + y) ^ (p ^ n) = x ^ (p ^ n) + y ^ (p ^ n) :=
add_pow_char_pow_of_commute _ _ _ (commute.all _ _)
theorem sub_pow_char [comm_ring R] {p : ℕ} [fact p.prime]
[char_p R p] (x y : R) : (x - y)^p = x^p - y^p :=
sub_pow_char_of_commute _ _ _ (commute.all _ _)
theorem sub_pow_char_pow [comm_ring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) :
(x - y) ^ (p ^ n) = x ^ (p ^ n) - y ^ (p ^ n) :=
sub_pow_char_pow_of_commute _ _ _ (commute.all _ _)
lemma eq_iff_modeq_int [ring R] (p : ℕ) [char_p R p] (a b : ℤ) :
(a : R) = b ↔ a ≡ b [ZMOD p] :=
by rw [eq_comm, ←sub_eq_zero, ←int.cast_sub,
char_p.int_cast_eq_zero_iff R p, int.modeq.modeq_iff_dvd]
lemma char_p.neg_one_ne_one [ring R] (p : ℕ) [char_p R p] [fact (2 < p)] :
(-1 : R) ≠ (1 : R) :=
begin
suffices : (2 : R) ≠ 0,
{ symmetry, rw [ne.def, ← sub_eq_zero, sub_neg_eq_add], exact this },
assume h,
rw [show (2 : R) = (2 : ℕ), by norm_cast] at h,
have := (char_p.cast_eq_zero_iff R p 2).mp h,
have := nat.le_of_dvd dec_trivial this,
rw fact_iff at *, linarith,
end
lemma ring_hom.char_p_iff_char_p {K L : Type*} [field K] [field L] (f : K →+* L) (p : ℕ) :
char_p K p ↔ char_p L p :=
begin
split;
{ introI _c, constructor, intro n,
rw [← @char_p.cast_eq_zero_iff _ _ _ p _c n, ← f.injective.eq_iff, f.map_nat_cast, f.map_zero] }
end
section frobenius
section comm_semiring
variables [comm_semiring R] {S : Type v} [comm_semiring S] (f : R →* S) (g : R →+* S)
(p : ℕ) [fact p.prime] [char_p R p] [char_p S p] (x y : R)
/-- The frobenius map that sends x to x^p -/
def frobenius : R →+* R :=
{ to_fun := λ x, x^p,
map_one' := one_pow p,
map_mul' := λ x y, mul_pow x y p,
map_zero' := zero_pow (lt_trans zero_lt_one (fact.out (nat.prime p)).one_lt),
map_add' := add_pow_char R }
variable {R}
theorem frobenius_def : frobenius R p x = x ^ p := rfl
theorem iterate_frobenius (n : ℕ) : (frobenius R p)^[n] x = x ^ p ^ n :=
begin
induction n, {simp},
rw [function.iterate_succ', pow_succ', pow_mul, function.comp_apply, frobenius_def, n_ih]
end
theorem frobenius_mul : frobenius R p (x * y) = frobenius R p x * frobenius R p y :=
(frobenius R p).map_mul x y
theorem frobenius_one : frobenius R p 1 = 1 := one_pow _
theorem monoid_hom.map_frobenius : f (frobenius R p x) = frobenius S p (f x) :=
f.map_pow x p
theorem ring_hom.map_frobenius : g (frobenius R p x) = frobenius S p (g x) :=
g.map_pow x p
theorem monoid_hom.map_iterate_frobenius (n : ℕ) :
f (frobenius R p^[n] x) = (frobenius S p^[n] (f x)) :=
function.semiconj.iterate_right (f.map_frobenius p) n x
theorem ring_hom.map_iterate_frobenius (n : ℕ) :
g (frobenius R p^[n] x) = (frobenius S p^[n] (g x)) :=
g.to_monoid_hom.map_iterate_frobenius p x n
theorem monoid_hom.iterate_map_frobenius (f : R →* R) (p : ℕ) [fact p.prime] [char_p R p] (n : ℕ) :
f^[n] (frobenius R p x) = frobenius R p (f^[n] x) :=
f.iterate_map_pow _ _ _
theorem ring_hom.iterate_map_frobenius (f : R →+* R) (p : ℕ) [fact p.prime] [char_p R p] (n : ℕ) :
f^[n] (frobenius R p x) = frobenius R p (f^[n] x) :=
f.iterate_map_pow _ _ _
variable (R)
theorem frobenius_zero : frobenius R p 0 = 0 := (frobenius R p).map_zero
theorem frobenius_add : frobenius R p (x + y) = frobenius R p x + frobenius R p y :=
(frobenius R p).map_add x y
theorem frobenius_nat_cast (n : ℕ) : frobenius R p n = n := (frobenius R p).map_nat_cast n
end comm_semiring
section comm_ring
variables [comm_ring R] {S : Type v} [comm_ring S] (f : R →* S) (g : R →+* S)
(p : ℕ) [fact p.prime] [char_p R p] [char_p S p] (x y : R)
theorem frobenius_neg : frobenius R p (-x) = -frobenius R p x := (frobenius R p).map_neg x
theorem frobenius_sub : frobenius R p (x - y) = frobenius R p x - frobenius R p y :=
(frobenius R p).map_sub x y
end comm_ring
end frobenius
theorem frobenius_inj [comm_ring R] [no_zero_divisors R]
(p : ℕ) [fact p.prime] [char_p R p] :
function.injective (frobenius R p) :=
λ x h H, by { rw ← sub_eq_zero at H ⊢, rw ← frobenius_sub at H, exact pow_eq_zero H }
namespace char_p
section
variables [ring R]
lemma char_p_to_char_zero [char_p R 0] : char_zero R :=
char_zero_of_inj_zero $
λ n h0, eq_zero_of_zero_dvd ((cast_eq_zero_iff R 0 n).mp h0)
lemma cast_eq_mod (p : ℕ) [char_p R p] (k : ℕ) : (k : R) = (k % p : ℕ) :=
calc (k : R) = ↑(k % p + p * (k / p)) : by rw [nat.mod_add_div]
... = ↑(k % p) : by simp[cast_eq_zero]
theorem char_ne_zero_of_fintype (p : ℕ) [hc : char_p R p] [fintype R] : p ≠ 0 :=
assume h : p = 0,
have char_zero R := @char_p_to_char_zero R _ (h ▸ hc),
absurd (@nat.cast_injective R _ _ this) (not_injective_infinite_fintype coe)
end
section semiring
open nat
variables [non_assoc_semiring R]
theorem char_ne_one [nontrivial R] (p : ℕ) [hc : char_p R p] : p ≠ 1 :=
assume hp : p = 1,
have ( 1 : R) = 0, by simpa using (cast_eq_zero_iff R p 1).mpr (hp ▸ dvd_refl p),
absurd this one_ne_zero
section no_zero_divisors
variable [no_zero_divisors R]
theorem char_is_prime_of_two_le (p : ℕ) [hc : char_p R p] (hp : 2 ≤ p) : nat.prime p :=
suffices ∀d ∣ p, d = 1 ∨ d = p, from ⟨hp, this⟩,
assume (d : ℕ) (hdvd : ∃ e, p = d * e),
let ⟨e, hmul⟩ := hdvd in
have (p : R) = 0, from (cast_eq_zero_iff R p p).mpr (dvd_refl p),
have (d : R) * e = 0, from (@cast_mul R _ d e) ▸ (hmul ▸ this),
or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this)
(assume hd : (d : R) = 0,
have p ∣ d, from (cast_eq_zero_iff R p d).mp hd,
show d = 1 ∨ d = p, from or.inr (dvd_antisymm ⟨e, hmul⟩ this))
(assume he : (e : R) = 0,
have p ∣ e, from (cast_eq_zero_iff R p e).mp he,
have e ∣ p, from dvd_of_mul_left_eq d (eq.symm hmul),
have e = p, from dvd_antisymm ‹e ∣ p› ‹p ∣ e›,
have h₀ : p > 0, from gt_of_ge_of_gt hp (nat.zero_lt_succ 1),
have d * p = 1 * p, by rw ‹e = p› at hmul; rw [one_mul]; exact eq.symm hmul,
show d = 1 ∨ d = p, from or.inl (eq_of_mul_eq_mul_right h₀ this))
section nontrivial
variables [nontrivial R]
theorem char_is_prime_or_zero (p : ℕ) [hc : char_p R p] : nat.prime p ∨ p = 0 :=
match p, hc with
| 0, _ := or.inr rfl
| 1, hc := absurd (eq.refl (1 : ℕ)) (@char_ne_one R _ _ (1 : ℕ) hc)
| (m+2), hc := or.inl (@char_is_prime_of_two_le R _ _ (m+2) hc (nat.le_add_left 2 m))
end
lemma char_is_prime_of_pos (p : ℕ) [h : fact (0 < p)] [char_p R p] : fact p.prime :=
⟨(char_p.char_is_prime_or_zero R _).resolve_right (pos_iff_ne_zero.1 h.1)⟩
end nontrivial
end no_zero_divisors
end semiring
section ring
variables (R) [ring R] [no_zero_divisors R] [nontrivial R] [fintype R]
theorem char_is_prime (p : ℕ) [char_p R p] :
p.prime :=
or.resolve_right (char_is_prime_or_zero R p) (char_ne_zero_of_fintype R p)
end ring
section char_one
variables {R} [non_assoc_semiring R]
@[priority 100] -- see Note [lower instance priority]
instance [char_p R 1] : subsingleton R :=
subsingleton.intro $
suffices ∀ (r : R), r = 0,
from assume a b, show a = b, by rw [this a, this b],
assume r,
calc r = 1 * r : by rw one_mul
... = (1 : ℕ) * r : by rw nat.cast_one
... = 0 * r : by rw char_p.cast_eq_zero
... = 0 : by rw zero_mul
lemma false_of_nontrivial_of_char_one [nontrivial R] [char_p R 1] : false :=
false_of_nontrivial_of_subsingleton R
lemma ring_char_ne_one [nontrivial R] : ring_char R ≠ 1 :=
by { intros h, apply @zero_ne_one R, symmetry, rw [←nat.cast_one, ring_char.spec, h], }
lemma nontrivial_of_char_ne_one {v : ℕ} (hv : v ≠ 1) [hr : char_p R v] :
nontrivial R :=
⟨⟨(1 : ℕ), 0, λ h, hv $ by rwa [char_p.cast_eq_zero_iff _ v, nat.dvd_one] at h; assumption ⟩⟩
end char_one
end char_p
section
variables (R) [comm_ring R] [fintype R] (n : ℕ)
lemma char_p_of_ne_zero (hn : fintype.card R = n) (hR : ∀ i < n, (i : R) = 0 → i = 0) :
char_p R n :=
{ cast_eq_zero_iff :=
begin
have H : (n : R) = 0, by { rw [← hn, char_p.cast_card_eq_zero] },
intro k,
split,
{ intro h,
rw [← nat.mod_add_div k n, nat.cast_add, nat.cast_mul, H, zero_mul, add_zero] at h,
rw nat.dvd_iff_mod_eq_zero,
apply hR _ (nat.mod_lt _ _) h,
rw [← hn, fintype.card_pos_iff],
exact ⟨0⟩, },
{ rintro ⟨k, rfl⟩, rw [nat.cast_mul, H, zero_mul] }
end }
lemma char_p_of_prime_pow_injective (p : ℕ) [hp : fact p.prime] (n : ℕ)
(hn : fintype.card R = p ^ n) (hR : ∀ i ≤ n, (p ^ i : R) = 0 → i = n) :
char_p R (p ^ n) :=
begin
obtain ⟨c, hc⟩ := char_p.exists R, resetI,
have hcpn : c ∣ p ^ n,
{ rw [← char_p.cast_eq_zero_iff R c, ← hn, char_p.cast_card_eq_zero], },
obtain ⟨i, hi, hc⟩ : ∃ i ≤ n, c = p ^ i, by rwa nat.dvd_prime_pow hp.1 at hcpn,
obtain rfl : i = n,
{ apply hR i hi, rw [← nat.cast_pow, ← hc, char_p.cast_eq_zero] },
rwa ← hc
end
end
section prod
variables (S : Type v) [semiring R] [semiring S] (p q : ℕ) [char_p R p]
/-- The characteristic of the product of rings is the least common multiple of the
characteristics of the two rings. -/
instance [char_p S q] : char_p (R × S) (nat.lcm p q) :=
{ cast_eq_zero_iff :=
by simp [prod.ext_iff, char_p.cast_eq_zero_iff R p,
char_p.cast_eq_zero_iff S q, nat.lcm_dvd_iff] }
/-- The characteristic of the product of two rings of the same characteristic
is the same as the characteristic of the rings -/
instance prod.char_p [char_p S p] : char_p (R × S) p :=
by convert nat.lcm.char_p R S p p; simp
end prod
|
47ff50dc3bc873d14ce1b6e5d9fd179b1404133a | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/analysis/calculus/times_cont_diff.lean | 5ab137dce44e0026cd9e04b99b345493647987fb | [
"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 | 138,819 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.calculus.mean_value
import analysis.calculus.formal_multilinear_series
/-!
# Higher differentiability
A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous.
By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or,
equivalently, if it is `C^1` and its derivative is `C^{n-1}`.
Finally, it is `C^∞` if it is `C^n` for all n.
We formalize these notions by defining iteratively the `n+1`-th derivative of a function as the
derivative of the `n`-th derivative. It is called `iterated_fderiv 𝕜 n f x` where `𝕜` is the
field, `n` is the number of iterations, `f` is the function and `x` is the point, and it is given
as an `n`-multilinear map. We also define a version `iterated_fderiv_within` relative to a domain,
as well as predicates `times_cont_diff_within_at`, `times_cont_diff_at`, `times_cont_diff_on` and
`times_cont_diff` saying that the function is `C^n` within a set at a point, at a point, on a set
and on the whole space respectively.
To avoid the issue of choice when choosing a derivative in sets where the derivative is not
necessarily unique, `times_cont_diff_on` is not defined directly in terms of the
regularity of the specific choice `iterated_fderiv_within 𝕜 n f s` inside `s`, but in terms of the
existence of a nice sequence of derivatives, expressed with a predicate
`has_ftaylor_series_up_to_on`.
We prove basic properties of these notions.
## Main definitions and results
Let `f : E → F` be a map between normed vector spaces over a nondiscrete normed field `𝕜`.
* `has_ftaylor_series_up_to n f p`: expresses that the formal multilinear series `p` is a sequence
of iterated derivatives of `f`, up to the `n`-th term (where `n` is a natural number or `∞`).
* `has_ftaylor_series_up_to_on n f p s`: same thing, but inside a set `s`. The notion of derivative
is now taken inside `s`. In particular, derivatives don't have to be unique.
* `times_cont_diff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to
rank `n`.
* `times_cont_diff_on 𝕜 n f s`: expresses that `f` is `C^n` in `s`.
* `times_cont_diff_at 𝕜 n f x`: expresses that `f` is `C^n` around `x`.
* `times_cont_diff_within_at 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`.
* `iterated_fderiv_within 𝕜 n f s x` is an `n`-th derivative of `f` over the field `𝕜` on the
set `s` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a
derivative within `s` of `iterated_fderiv_within 𝕜 (n-1) f s` if one exists, and `0` otherwise.
* `iterated_fderiv 𝕜 n f x` is the `n`-th derivative of `f` over the field `𝕜` at the point `x`.
It is a continuous multilinear map from `E^n` to `F`, defined as a derivative of
`iterated_fderiv 𝕜 (n-1) f` if one exists, and `0` otherwise.
In sets of unique differentiability, `times_cont_diff_on 𝕜 n f s` can be expressed in terms of the
properties of `iterated_fderiv_within 𝕜 m f s` for `m ≤ n`. In the whole space,
`times_cont_diff 𝕜 n f` can be expressed in terms of the properties of `iterated_fderiv 𝕜 m f`
for `m ≤ n`.
We also prove that the usual operations (addition, multiplication, difference, composition, and
so on) preserve `C^n` functions.
## Implementation notes
The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more
complicated than the naive definitions one would guess from the intuition over the real or complex
numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity
in general. In the usual situations, they coincide with the usual definitions.
### Definition of `C^n` functions in domains
One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this
is what we do with `iterated_fderiv_within`) and requiring that all these derivatives up to `n` are
continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n`
functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a
function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`.
This definition still has the problem that a function which is locally `C^n` would not need to
be `C^n`, as different choices of sequences of derivatives around different points might possibly
not be glued together to give a globally defined sequence of derivatives. (Note that this issue
can not happen over reals, thanks to partition of unity, but the behavior over a general field is
not so clear, and we want a definition for general fields). Also, there are locality
problems for the order parameter: one could image a function which, for each `n`, has a nice
sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore
not be glued to give rise to an infinite sequence of derivatives. This would give a function
which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions
in space and order in our definition of `times_cont_diff_within_at` and `times_cont_diff_on`.
The resulting definition is slightly more complicated to work with (in fact not so much), but it
gives rise to completely satisfactory theorems.
For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)`
for each natural `m` is by definition `C^∞` at `0`.
There is another issue with the definition of `times_cont_diff_within_at 𝕜 n f s x`. We can
require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x`
within `s`. However, this does not imply continuity or differentiability within `s` of the function
at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on
a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file).
### Side of the composition, and universe issues
With a naïve direct definition, the `n`-th derivative of a function belongs to the space
`E →L[𝕜] (E →L[𝕜] (E ... F)...)))` where there are n iterations of `E →L[𝕜]`. This space
may also be seen as the space of continuous multilinear functions on `n` copies of `E` with
values in `F`, by uncurrying. This is the point of view that is usually adopted in textbooks,
and that we also use. This means that the definition and the first proofs are slightly involved,
as one has to keep track of the uncurrying operation. The uncurrying can be done from the
left or from the right, amounting to defining the `n+1`-th derivative either as the derivative of
the `n`-th derivative, or as the `n`-th derivative of the derivative.
For proofs, it would be more convenient to use the latter approach (from the right),
as it means to prove things at the `n+1`-th step we only need to understand well enough the
derivative in `E →L[𝕜] F` (contrary to the approach from the left, where one would need to know
enough on the `n`-th derivative to deduce things on the `n+1`-th derivative).
However, the definition from the right leads to a universe polymorphism problem: if we define
`iterated_fderiv 𝕜 (n + 1) f x = iterated_fderiv 𝕜 n (fderiv 𝕜 f) x` by induction, we need to
generalize over all spaces (as `f` and `fderiv 𝕜 f` don't take values in the same space). It is
only possible to generalize over all spaces in some fixed universe in an inductive definition.
For `f : E → F`, then `fderiv 𝕜 f` is a map `E → (E →L[𝕜] F)`. Therefore, the definition will only
work if `F` and `E →L[𝕜] F` are in the same universe.
This issue does not appear with the definition from the left, where one does not need to generalize
over all spaces. Therefore, we use the definition from the left. This means some proofs later on
become a little bit more complicated: to prove that a function is `C^n`, the most efficient approach
is to exhibit a formula for its `n`-th derivative and prove it is continuous (contrary to the
inductive approach where one would prove smoothness statements without giving a formula for the
derivative). In the end, this approach is still satisfactory as it is good to have formulas for the
iterated derivatives in various constructions.
One point where we depart from this explicit approach is in the proof of smoothness of a
composition: there is a formula for the `n`-th derivative of a composition (Faà di Bruno's formula),
but it is very complicated and barely usable, while the inductive proof is very simple. Thus, we
give the inductive proof. As explained above, it works by generalizing over the target space, hence
it only works well if all spaces belong to the same universe. To get the general version, we lift
things to a common universe using a trick.
### Variables management
The textbook definitions and proofs use various identifications and abuse of notations, for instance
when saying that the natural space in which the derivative lives, i.e.,
`E →L[𝕜] (E →L[𝕜] ( ... →L[𝕜] F))`, is the same as a space of multilinear maps. When doing things
formally, we need to provide explicit maps for these identifications, and chase some diagrams to see
everything is compatible with the identifications. In particular, one needs to check that taking the
derivative and then doing the identification, or first doing the identification and then taking the
derivative, gives the same result. The key point for this is that taking the derivative commutes
with continuous linear equivalences. Therefore, we need to implement all our identifications with
continuous linear equivs.
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `⊤ : with_top ℕ` with `∞`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable theory
open_locale classical big_operators
local notation `∞` := (⊤ : with_top ℕ)
universes u v w
local attribute [instance, priority 1001]
normed_group.to_add_comm_group normed_space.to_module add_comm_group.to_add_comm_monoid
open set fin
open_locale topological_space
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{F : Type*} [normed_group F] [normed_space 𝕜 F]
{G : Type*} [normed_group G] [normed_space 𝕜 G]
{s s₁ t u : set E} {f f₁ : E → F} {g : F → G} {x : E} {c : F}
{b : E × F → G}
/-! ### Functions with a Taylor series on a domain -/
variable {p : E → formal_multilinear_series 𝕜 E F}
/-- `has_ftaylor_series_up_to_on n f p s` registers the fact that `p 0 = f` and `p (m+1)` is a
derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to
`has_fderiv_within_at` but for higher order derivatives. -/
structure has_ftaylor_series_up_to_on (n : with_top ℕ)
(f : E → F) (p : E → formal_multilinear_series 𝕜 E F) (s : set E) : Prop :=
(zero_eq : ∀ x ∈ s, (p x 0).uncurry0 = f x)
(fderiv_within : ∀ (m : ℕ) (hm : (m : with_top ℕ) < n), ∀ x ∈ s,
has_fderiv_within_at (λ y, p y m) (p x m.succ).curry_left s x)
(cont : ∀ (m : ℕ) (hm : (m : with_top ℕ) ≤ n), continuous_on (λ x, p x m) s)
lemma has_ftaylor_series_up_to_on.zero_eq' {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) {x : E} (hx : x ∈ s) :
p x 0 = (continuous_multilinear_curry_fin0 𝕜 E F).symm (f x) :=
by { rw ← h.zero_eq x hx, symmetry, exact continuous_multilinear_map.uncurry0_curry0 _ }
/-- If two functions coincide on a set `s`, then a Taylor series for the first one is as well a
Taylor series for the second one. -/
lemma has_ftaylor_series_up_to_on.congr {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) (h₁ : ∀ x ∈ s, f₁ x = f x) :
has_ftaylor_series_up_to_on n f₁ p s :=
begin
refine ⟨λ x hx, _, h.fderiv_within, h.cont⟩,
rw h₁ x hx,
exact h.zero_eq x hx
end
lemma has_ftaylor_series_up_to_on.mono {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) {t : set E} (hst : t ⊆ s) :
has_ftaylor_series_up_to_on n f p t :=
⟨λ x hx, h.zero_eq x (hst hx),
λ m hm x hx, (h.fderiv_within m hm x (hst hx)).mono hst,
λ m hm, (h.cont m hm).mono hst⟩
lemma has_ftaylor_series_up_to_on.of_le {m n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) (hmn : m ≤ n) :
has_ftaylor_series_up_to_on m f p s :=
⟨h.zero_eq,
λ k hk x hx, h.fderiv_within k (lt_of_lt_of_le hk hmn) x hx,
λ k hk, h.cont k (le_trans hk hmn)⟩
lemma has_ftaylor_series_up_to_on.continuous_on {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) : continuous_on f s :=
begin
have := (h.cont 0 bot_le).congr (λ x hx, (h.zero_eq' hx).symm),
rwa linear_isometry_equiv.comp_continuous_on_iff at this
end
lemma has_ftaylor_series_up_to_on_zero_iff :
has_ftaylor_series_up_to_on 0 f p s ↔ continuous_on f s ∧ (∀ x ∈ s, (p x 0).uncurry0 = f x) :=
begin
refine ⟨λ H, ⟨H.continuous_on, H.zero_eq⟩,
λ H, ⟨H.2, λ m hm, false.elim (not_le.2 hm bot_le), _⟩⟩,
assume m hm,
obtain rfl : m = 0, by exact_mod_cast (hm.antisymm (zero_le _)),
have : ∀ x ∈ s, p x 0 = (continuous_multilinear_curry_fin0 𝕜 E F).symm (f x),
by { assume x hx, rw ← H.2 x hx, symmetry, exact continuous_multilinear_map.uncurry0_curry0 _ },
rw [continuous_on_congr this, linear_isometry_equiv.comp_continuous_on_iff],
exact H.1
end
lemma has_ftaylor_series_up_to_on_top_iff :
(has_ftaylor_series_up_to_on ∞ f p s) ↔ (∀ (n : ℕ), has_ftaylor_series_up_to_on n f p s) :=
begin
split,
{ assume H n, exact H.of_le le_top },
{ assume H,
split,
{ exact (H 0).zero_eq },
{ assume m hm,
apply (H m.succ).fderiv_within m (with_top.coe_lt_coe.2 (lt_add_one m)) },
{ assume m hm,
apply (H m).cont m (le_refl _) } }
end
/-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this
series is a derivative of `f`. -/
lemma has_ftaylor_series_up_to_on.has_fderiv_within_at {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≤ n) (hx : x ∈ s) :
has_fderiv_within_at f (continuous_multilinear_curry_fin1 𝕜 E F (p x 1)) s x :=
begin
have A : ∀ y ∈ s, f y = (continuous_multilinear_curry_fin0 𝕜 E F) (p y 0),
{ assume y hy, rw ← h.zero_eq y hy, refl },
suffices H : has_fderiv_within_at
(λ y, continuous_multilinear_curry_fin0 𝕜 E F (p y 0))
(continuous_multilinear_curry_fin1 𝕜 E F (p x 1)) s x,
by exact H.congr A (A x hx),
rw linear_isometry_equiv.comp_has_fderiv_within_at_iff',
have : ((0 : ℕ) : with_top ℕ) < n :=
lt_of_lt_of_le (with_top.coe_lt_coe.2 nat.zero_lt_one) hn,
convert h.fderiv_within _ this x hx,
ext y v,
change (p x 1) (snoc 0 y) = (p x 1) (cons y v),
unfold_coes,
congr' with i,
rw unique.eq_default i,
refl
end
lemma has_ftaylor_series_up_to_on.differentiable_on {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≤ n) : differentiable_on 𝕜 f s :=
λ x hx, (h.has_fderiv_within_at hn hx).differentiable_within_at
/-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then the term
of order `1` of this series is a derivative of `f` at `x`. -/
lemma has_ftaylor_series_up_to_on.has_fderiv_at {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) :
has_fderiv_at f (continuous_multilinear_curry_fin1 𝕜 E F (p x 1)) x :=
(h.has_fderiv_within_at hn (mem_of_mem_nhds hx)).has_fderiv_at hx
/-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then
in a neighborhood of `x`, the term of order `1` of this series is a derivative of `f`. -/
lemma has_ftaylor_series_up_to_on.eventually_has_fderiv_at {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) :
∀ᶠ y in 𝓝 x, has_fderiv_at f (continuous_multilinear_curry_fin1 𝕜 E F (p y 1)) y :=
(eventually_eventually_nhds.2 hx).mono $ λ y hy, h.has_fderiv_at hn hy
/-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then
it is differentiable at `x`. -/
lemma has_ftaylor_series_up_to_on.differentiable_at {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) :
differentiable_at 𝕜 f x :=
(h.has_fderiv_at hn hx).differentiable_at
/-- `p` is a Taylor series of `f` up to `n+1` if and only if `p` is a Taylor series up to `n`, and
`p (n + 1)` is a derivative of `p n`. -/
theorem has_ftaylor_series_up_to_on_succ_iff_left {n : ℕ} :
has_ftaylor_series_up_to_on (n + 1) f p s ↔
has_ftaylor_series_up_to_on n f p s
∧ (∀ x ∈ s, has_fderiv_within_at (λ y, p y n) (p x n.succ).curry_left s x)
∧ continuous_on (λ x, p x (n + 1)) s :=
begin
split,
{ assume h,
exact ⟨h.of_le (with_top.coe_le_coe.2 (nat.le_succ n)),
h.fderiv_within _ (with_top.coe_lt_coe.2 (lt_add_one n)),
h.cont (n + 1) (le_refl _)⟩ },
{ assume h,
split,
{ exact h.1.zero_eq },
{ assume m hm,
by_cases h' : m < n,
{ exact h.1.fderiv_within m (with_top.coe_lt_coe.2 h') },
{ have : m = n := nat.eq_of_lt_succ_of_not_lt (with_top.coe_lt_coe.1 hm) h',
rw this,
exact h.2.1 } },
{ assume m hm,
by_cases h' : m ≤ n,
{ apply h.1.cont m (with_top.coe_le_coe.2 h') },
{ have : m = (n + 1) := le_antisymm (with_top.coe_le_coe.1 hm) (not_le.1 h'),
rw this,
exact h.2.2 } } }
end
/-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n`
for `p 1`, which is a derivative of `f`. -/
theorem has_ftaylor_series_up_to_on_succ_iff_right {n : ℕ} :
has_ftaylor_series_up_to_on ((n + 1) : ℕ) f p s ↔
(∀ x ∈ s, (p x 0).uncurry0 = f x)
∧ (∀ x ∈ s, has_fderiv_within_at (λ y, p y 0) (p x 1).curry_left s x)
∧ has_ftaylor_series_up_to_on n
(λ x, continuous_multilinear_curry_fin1 𝕜 E F (p x 1)) (λ x, (p x).shift) s :=
begin
split,
{ assume H,
refine ⟨H.zero_eq, H.fderiv_within 0 (with_top.coe_lt_coe.2 (nat.succ_pos n)), _⟩,
split,
{ assume x hx, refl },
{ assume m (hm : (m : with_top ℕ) < n) x (hx : x ∈ s),
have A : (m.succ : with_top ℕ) < n.succ,
by { rw with_top.coe_lt_coe at ⊢ hm, exact nat.lt_succ_iff.mpr hm },
change has_fderiv_within_at
((continuous_multilinear_curry_right_equiv' 𝕜 m E F).symm
∘ (λ (y : E), p y m.succ))
(p x m.succ.succ).curry_right.curry_left s x,
rw linear_isometry_equiv.comp_has_fderiv_within_at_iff',
convert H.fderiv_within _ A x hx,
ext y v,
change (p x m.succ.succ) (snoc (cons y (init v)) (v (last _)))
= (p x (nat.succ (nat.succ m))) (cons y v),
rw [← cons_snoc_eq_snoc_cons, snoc_init_self] },
{ assume m (hm : (m : with_top ℕ) ≤ n),
have A : (m.succ : with_top ℕ) ≤ n.succ,
by { rw with_top.coe_le_coe at ⊢ hm, exact nat.pred_le_iff.mp hm },
change continuous_on ((continuous_multilinear_curry_right_equiv' 𝕜 m E F).symm
∘ (λ (y : E), p y m.succ)) s,
rw linear_isometry_equiv.comp_continuous_on_iff,
exact H.cont _ A } },
{ rintros ⟨Hzero_eq, Hfderiv_zero, Htaylor⟩,
split,
{ exact Hzero_eq },
{ assume m (hm : (m : with_top ℕ) < n.succ) x (hx : x ∈ s),
cases m,
{ exact Hfderiv_zero x hx },
{ have A : (m : with_top ℕ) < n,
by { rw with_top.coe_lt_coe at hm ⊢, exact nat.lt_of_succ_lt_succ hm },
have : has_fderiv_within_at ((continuous_multilinear_curry_right_equiv' 𝕜 m E F).symm
∘ (λ (y : E), p y m.succ)) ((p x).shift m.succ).curry_left s x :=
Htaylor.fderiv_within _ A x hx,
rw linear_isometry_equiv.comp_has_fderiv_within_at_iff' at this,
convert this,
ext y v,
change (p x (nat.succ (nat.succ m))) (cons y v)
= (p x m.succ.succ) (snoc (cons y (init v)) (v (last _))),
rw [← cons_snoc_eq_snoc_cons, snoc_init_self] } },
{ assume m (hm : (m : with_top ℕ) ≤ n.succ),
cases m,
{ have : differentiable_on 𝕜 (λ x, p x 0) s :=
λ x hx, (Hfderiv_zero x hx).differentiable_within_at,
exact this.continuous_on },
{ have A : (m : with_top ℕ) ≤ n,
by { rw with_top.coe_le_coe at hm ⊢, exact nat.lt_succ_iff.mp hm },
have : continuous_on ((continuous_multilinear_curry_right_equiv' 𝕜 m E F).symm
∘ (λ (y : E), p y m.succ)) s :=
Htaylor.cont _ A,
rwa linear_isometry_equiv.comp_continuous_on_iff at this } } }
end
/-! ### Smooth functions within a set around a point -/
variable (𝕜)
/-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if
it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not
better, is `C^∞` at `0` within `univ`.
-/
def times_cont_diff_within_at (n : with_top ℕ) (f : E → F) (s : set E) (x : E) :=
∀ (m : ℕ), (m : with_top ℕ) ≤ n →
∃ u ∈ 𝓝[insert x s] x, ∃ p : E → formal_multilinear_series 𝕜 E F,
has_ftaylor_series_up_to_on m f p u
variable {𝕜}
lemma times_cont_diff_within_at_nat {n : ℕ} :
times_cont_diff_within_at 𝕜 n f s x ↔
∃ u ∈ 𝓝[insert x s] x, ∃ p : E → formal_multilinear_series 𝕜 E F,
has_ftaylor_series_up_to_on n f p u :=
⟨λ H, H n (le_refl _), λ ⟨u, hu, p, hp⟩ m hm, ⟨u, hu, p, hp.of_le hm⟩⟩
lemma times_cont_diff_within_at.of_le {m n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (hmn : m ≤ n) :
times_cont_diff_within_at 𝕜 m f s x :=
λ k hk, h k (le_trans hk hmn)
lemma times_cont_diff_within_at_iff_forall_nat_le {n : with_top ℕ} :
times_cont_diff_within_at 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → times_cont_diff_within_at 𝕜 m f s x :=
⟨λ H m hm, H.of_le hm, λ H m hm, H m hm _ le_rfl⟩
lemma times_cont_diff_within_at_top :
times_cont_diff_within_at 𝕜 ∞ f s x ↔ ∀ (n : ℕ), times_cont_diff_within_at 𝕜 n f s x :=
times_cont_diff_within_at_iff_forall_nat_le.trans $ by simp only [forall_prop_of_true, le_top]
lemma times_cont_diff_within_at.continuous_within_at {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) : continuous_within_at f s x :=
begin
rcases h 0 bot_le with ⟨u, hu, p, H⟩,
rw [mem_nhds_within_insert] at hu,
exact (H.continuous_on.continuous_within_at hu.1).mono_of_mem hu.2
end
lemma times_cont_diff_within_at.congr_of_eventually_eq {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
times_cont_diff_within_at 𝕜 n f₁ s x :=
λ m hm, let ⟨u, hu, p, H⟩ := h m hm in
⟨{x ∈ u | f₁ x = f x}, filter.inter_mem_sets hu (mem_nhds_within_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr (λ _, and.right)⟩
lemma times_cont_diff_within_at.congr_of_eventually_eq' {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) :
times_cont_diff_within_at 𝕜 n f₁ s x :=
h.congr_of_eventually_eq h₁ $ h₁.self_of_nhds_within hx
lemma filter.eventually_eq.times_cont_diff_within_at_iff {n : with_top ℕ}
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
times_cont_diff_within_at 𝕜 n f₁ s x ↔ times_cont_diff_within_at 𝕜 n f s x :=
⟨λ H, times_cont_diff_within_at.congr_of_eventually_eq H h₁.symm hx.symm,
λ H, H.congr_of_eventually_eq h₁ hx⟩
lemma times_cont_diff_within_at.congr {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) :
times_cont_diff_within_at 𝕜 n f₁ s x :=
h.congr_of_eventually_eq (filter.eventually_eq_of_mem self_mem_nhds_within h₁) hx
lemma times_cont_diff_within_at.congr' {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) :
times_cont_diff_within_at 𝕜 n f₁ s x :=
h.congr h₁ (h₁ _ hx)
lemma times_cont_diff_within_at.mono_of_mem {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) {t : set E} (hst : s ∈ 𝓝[t] x) :
times_cont_diff_within_at 𝕜 n f t x :=
begin
assume m hm,
rcases h m hm with ⟨u, hu, p, H⟩,
exact ⟨u, nhds_within_le_of_mem (insert_mem_nhds_within_insert hst) hu, p, H⟩
end
lemma times_cont_diff_within_at.mono {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) {t : set E} (hst : t ⊆ s) :
times_cont_diff_within_at 𝕜 n f t x :=
h.mono_of_mem $ filter.mem_sets_of_superset self_mem_nhds_within hst
lemma times_cont_diff_within_at.congr_nhds {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) {t : set E} (hst : 𝓝[s] x = 𝓝[t] x) :
times_cont_diff_within_at 𝕜 n f t x :=
h.mono_of_mem $ hst ▸ self_mem_nhds_within
lemma times_cont_diff_within_at_congr_nhds {n : with_top ℕ} {t : set E} (hst : 𝓝[s] x = 𝓝[t] x) :
times_cont_diff_within_at 𝕜 n f s x ↔ times_cont_diff_within_at 𝕜 n f t x :=
⟨λ h, h.congr_nhds hst, λ h, h.congr_nhds hst.symm⟩
lemma times_cont_diff_within_at_inter' {n : with_top ℕ} (h : t ∈ 𝓝[s] x) :
times_cont_diff_within_at 𝕜 n f (s ∩ t) x ↔ times_cont_diff_within_at 𝕜 n f s x :=
times_cont_diff_within_at_congr_nhds $ eq.symm $ nhds_within_restrict'' _ h
lemma times_cont_diff_within_at_inter {n : with_top ℕ} (h : t ∈ 𝓝 x) :
times_cont_diff_within_at 𝕜 n f (s ∩ t) x ↔ times_cont_diff_within_at 𝕜 n f s x :=
times_cont_diff_within_at_inter' (mem_nhds_within_of_mem_nhds h)
/-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable
within this set at this point. -/
lemma times_cont_diff_within_at.differentiable_within_at' {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (hn : 1 ≤ n) :
differentiable_within_at 𝕜 f (insert x s) x :=
begin
rcases h 1 hn with ⟨u, hu, p, H⟩,
rcases mem_nhds_within.1 hu with ⟨t, t_open, xt, tu⟩,
rw inter_comm at tu,
have := ((H.mono tu).differentiable_on (le_refl _)) x ⟨mem_insert x s, xt⟩,
exact (differentiable_within_at_inter (is_open.mem_nhds t_open xt)).1 this,
end
lemma times_cont_diff_within_at.differentiable_within_at {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (hn : 1 ≤ n) :
differentiable_within_at 𝕜 f s x :=
(h.differentiable_within_at' hn).mono (subset_insert x s)
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/
theorem times_cont_diff_within_at_succ_iff_has_fderiv_within_at {n : ℕ} :
times_cont_diff_within_at 𝕜 ((n + 1) : ℕ) f s x
↔ ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → (E →L[𝕜] F),
(∀ x ∈ u, has_fderiv_within_at f (f' x) u x) ∧ (times_cont_diff_within_at 𝕜 n f' u x) :=
begin
split,
{ assume h,
rcases h n.succ (le_refl _) with ⟨u, hu, p, Hp⟩,
refine ⟨u, hu, λ y, (continuous_multilinear_curry_fin1 𝕜 E F) (p y 1),
λ y hy, Hp.has_fderiv_within_at (with_top.coe_le_coe.2 (nat.le_add_left 1 n)) hy, _⟩,
assume m hm,
refine ⟨u, _, λ (y : E), (p y).shift, _⟩,
{ convert self_mem_nhds_within,
have : x ∈ insert x s, by simp,
exact (insert_eq_of_mem (mem_of_mem_nhds_within this hu)) },
{ rw has_ftaylor_series_up_to_on_succ_iff_right at Hp,
exact Hp.2.2.of_le hm } },
{ rintros ⟨u, hu, f', f'_eq_deriv, Hf'⟩,
rw times_cont_diff_within_at_nat,
rcases Hf' n (le_refl _) with ⟨v, hv, p', Hp'⟩,
refine ⟨v ∩ u, _, λ x, (p' x).unshift (f x), _⟩,
{ apply filter.inter_mem_sets _ hu,
apply nhds_within_le_of_mem hu,
exact nhds_within_mono _ (subset_insert x u) hv },
{ rw has_ftaylor_series_up_to_on_succ_iff_right,
refine ⟨λ y hy, rfl, λ y hy, _, _⟩,
{ change has_fderiv_within_at (λ z, (continuous_multilinear_curry_fin0 𝕜 E F).symm (f z))
((formal_multilinear_series.unshift (p' y) (f y) 1).curry_left) (v ∩ u) y,
rw linear_isometry_equiv.comp_has_fderiv_within_at_iff',
convert (f'_eq_deriv y hy.2).mono (inter_subset_right v u),
rw ← Hp'.zero_eq y hy.1,
ext z,
change ((p' y 0) (init (@cons 0 (λ i, E) z 0))) (@cons 0 (λ i, E) z 0 (last 0))
= ((p' y 0) 0) z,
unfold_coes,
congr },
{ convert (Hp'.mono (inter_subset_left v u)).congr (λ x hx, Hp'.zero_eq x hx.1),
{ ext x y,
change p' x 0 (init (@snoc 0 (λ i : fin 1, E) 0 y)) y = p' x 0 0 y,
rw init_snoc },
{ ext x k v y,
change p' x k (init (@snoc k (λ i : fin k.succ, E) v y))
(@snoc k (λ i : fin k.succ, E) v y (last k)) = p' x k v y,
rw [snoc_last, init_snoc] } } } }
end
/-! ### Smooth functions within a set -/
variable (𝕜)
/-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it
admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
-/
definition times_cont_diff_on (n : with_top ℕ) (f : E → F) (s : set E) :=
∀ x ∈ s, times_cont_diff_within_at 𝕜 n f s x
variable {𝕜}
lemma times_cont_diff_on.times_cont_diff_within_at {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hx : x ∈ s) :
times_cont_diff_within_at 𝕜 n f s x :=
h x hx
lemma times_cont_diff_within_at.times_cont_diff_on {n : with_top ℕ} {m : ℕ}
(hm : (m : with_top ℕ) ≤ n) (h : times_cont_diff_within_at 𝕜 n f s x) :
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ times_cont_diff_on 𝕜 m f u :=
begin
rcases h m hm with ⟨u, u_nhd, p, hp⟩,
refine ⟨u ∩ insert x s, filter.inter_mem_sets u_nhd self_mem_nhds_within,
inter_subset_right _ _, _⟩,
assume y hy m' hm',
refine ⟨u ∩ insert x s, _, p, (hp.mono (inter_subset_left _ _)).of_le hm'⟩,
convert self_mem_nhds_within,
exact insert_eq_of_mem hy
end
lemma times_cont_diff_on.of_le {m n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hmn : m ≤ n) :
times_cont_diff_on 𝕜 m f s :=
λ x hx, (h x hx).of_le hmn
lemma times_cont_diff_on_iff_forall_nat_le {n : with_top ℕ} :
times_cont_diff_on 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → times_cont_diff_on 𝕜 m f s :=
⟨λ H m hm, H.of_le hm, λ H x hx m hm, H m hm x hx m le_rfl⟩
lemma times_cont_diff_on_top :
times_cont_diff_on 𝕜 ∞ f s ↔ ∀ (n : ℕ), times_cont_diff_on 𝕜 n f s :=
times_cont_diff_on_iff_forall_nat_le.trans $ by simp only [le_top, forall_prop_of_true]
lemma times_cont_diff_on_all_iff_nat :
(∀ n, times_cont_diff_on 𝕜 n f s) ↔ (∀ n : ℕ, times_cont_diff_on 𝕜 n f s) :=
begin
refine ⟨λ H n, H n, _⟩,
rintro H (_|n),
exacts [times_cont_diff_on_top.2 H, H n]
end
lemma times_cont_diff_on.continuous_on {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) : continuous_on f s :=
λ x hx, (h x hx).continuous_within_at
lemma times_cont_diff_on.congr {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) :
times_cont_diff_on 𝕜 n f₁ s :=
λ x hx, (h x hx).congr h₁ (h₁ x hx)
lemma times_cont_diff_on_congr {n : with_top ℕ} (h₁ : ∀ x ∈ s, f₁ x = f x) :
times_cont_diff_on 𝕜 n f₁ s ↔ times_cont_diff_on 𝕜 n f s :=
⟨λ H, H.congr (λ x hx, (h₁ x hx).symm), λ H, H.congr h₁⟩
lemma times_cont_diff_on.mono {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) {t : set E} (hst : t ⊆ s) :
times_cont_diff_on 𝕜 n f t :=
λ x hx, (h x (hst hx)).mono hst
lemma times_cont_diff_on.congr_mono {n : with_top ℕ}
(hf : times_cont_diff_on 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) :
times_cont_diff_on 𝕜 n f₁ s₁ :=
(hf.mono hs).congr h₁
/-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/
lemma times_cont_diff_on.differentiable_on {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hn : 1 ≤ n) : differentiable_on 𝕜 f s :=
λ x hx, (h x hx).differentiable_within_at hn
/-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/
lemma times_cont_diff_on_of_locally_times_cont_diff_on {n : with_top ℕ}
(h : ∀ x ∈ s, ∃u, is_open u ∧ x ∈ u ∧ times_cont_diff_on 𝕜 n f (s ∩ u)) :
times_cont_diff_on 𝕜 n f s :=
begin
assume x xs,
rcases h x xs with ⟨u, u_open, xu, hu⟩,
apply (times_cont_diff_within_at_inter _).1 (hu x ⟨xs, xu⟩),
exact is_open.mem_nhds u_open xu
end
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/
theorem times_cont_diff_on_succ_iff_has_fderiv_within_at {n : ℕ} :
times_cont_diff_on 𝕜 ((n + 1) : ℕ) f s
↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → (E →L[𝕜] F),
(∀ x ∈ u, has_fderiv_within_at f (f' x) u x) ∧ (times_cont_diff_on 𝕜 n f' u) :=
begin
split,
{ assume h x hx,
rcases (h x hx) n.succ (le_refl _) with ⟨u, hu, p, Hp⟩,
refine ⟨u, hu, λ y, (continuous_multilinear_curry_fin1 𝕜 E F) (p y 1),
λ y hy, Hp.has_fderiv_within_at (with_top.coe_le_coe.2 (nat.le_add_left 1 n)) hy, _⟩,
rw has_ftaylor_series_up_to_on_succ_iff_right at Hp,
assume z hz m hm,
refine ⟨u, _, λ (x : E), (p x).shift, Hp.2.2.of_le hm⟩,
convert self_mem_nhds_within,
exact insert_eq_of_mem hz, },
{ assume h x hx,
rw times_cont_diff_within_at_succ_iff_has_fderiv_within_at,
rcases h x hx with ⟨u, u_nhbd, f', hu, hf'⟩,
have : x ∈ u := mem_of_mem_nhds_within (mem_insert _ _) u_nhbd,
exact ⟨u, u_nhbd, f', hu, hf' x this⟩ }
end
/-! ### Iterated derivative within a set -/
variable (𝕜)
/--
The `n`-th derivative of a function along a set, defined inductively by saying that the `n+1`-th
derivative of `f` is the derivative of the `n`-th derivative of `f` along this set, together with
an uncurrying step to see it as a multilinear map in `n+1` variables..
-/
noncomputable def iterated_fderiv_within (n : ℕ) (f : E → F) (s : set E) :
E → (E [×n]→L[𝕜] F) :=
nat.rec_on n
(λ x, continuous_multilinear_map.curry0 𝕜 E (f x))
(λ n rec x, continuous_linear_map.uncurry_left (fderiv_within 𝕜 rec s x))
/-- Formal Taylor series associated to a function within a set. -/
def ftaylor_series_within (f : E → F) (s : set E) (x : E) : formal_multilinear_series 𝕜 E F :=
λ n, iterated_fderiv_within 𝕜 n f s x
variable {𝕜}
@[simp] lemma iterated_fderiv_within_zero_apply (m : (fin 0) → E) :
(iterated_fderiv_within 𝕜 0 f s x : ((fin 0) → E) → F) m = f x := rfl
lemma iterated_fderiv_within_zero_eq_comp :
iterated_fderiv_within 𝕜 0 f s = (continuous_multilinear_curry_fin0 𝕜 E F).symm ∘ f := rfl
lemma iterated_fderiv_within_succ_apply_left {n : ℕ} (m : fin (n + 1) → E):
(iterated_fderiv_within 𝕜 (n + 1) f s x : (fin (n + 1) → E) → F) m
= (fderiv_within 𝕜 (iterated_fderiv_within 𝕜 n f s) s x : E → (E [×n]→L[𝕜] F))
(m 0) (tail m) := rfl
/-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv,
and the derivative of the `n`-th derivative. -/
lemma iterated_fderiv_within_succ_eq_comp_left {n : ℕ} :
iterated_fderiv_within 𝕜 (n + 1) f s =
(continuous_multilinear_curry_left_equiv 𝕜 (λ(i : fin (n + 1)), E) F)
∘ (fderiv_within 𝕜 (iterated_fderiv_within 𝕜 n f s) s) := rfl
theorem iterated_fderiv_within_succ_apply_right {n : ℕ}
(hs : unique_diff_on 𝕜 s) (hx : x ∈ s) (m : fin (n + 1) → E) :
(iterated_fderiv_within 𝕜 (n + 1) f s x : (fin (n + 1) → E) → F) m
= iterated_fderiv_within 𝕜 n (λy, fderiv_within 𝕜 f s y) s x (init m) (m (last n)) :=
begin
induction n with n IH generalizing x,
{ rw [iterated_fderiv_within_succ_eq_comp_left, iterated_fderiv_within_zero_eq_comp,
iterated_fderiv_within_zero_apply,
function.comp_apply, linear_isometry_equiv.comp_fderiv_within _ (hs x hx)],
refl },
{ let I := continuous_multilinear_curry_right_equiv' 𝕜 n E F,
have A : ∀ y ∈ s, iterated_fderiv_within 𝕜 n.succ f s y
= (I ∘ (iterated_fderiv_within 𝕜 n (λy, fderiv_within 𝕜 f s y) s)) y,
by { assume y hy, ext m, rw @IH m y hy, refl },
calc
(iterated_fderiv_within 𝕜 (n+2) f s x : (fin (n+2) → E) → F) m =
(fderiv_within 𝕜 (iterated_fderiv_within 𝕜 n.succ f s) s x
: E → (E [×(n + 1)]→L[𝕜] F)) (m 0) (tail m) : rfl
... = (fderiv_within 𝕜 (I ∘ (iterated_fderiv_within 𝕜 n (fderiv_within 𝕜 f s) s)) s x
: E → (E [×(n + 1)]→L[𝕜] F)) (m 0) (tail m) :
by rw fderiv_within_congr (hs x hx) A (A x hx)
... = (I ∘ fderiv_within 𝕜 ((iterated_fderiv_within 𝕜 n (fderiv_within 𝕜 f s) s)) s x
: E → (E [×(n + 1)]→L[𝕜] F)) (m 0) (tail m) :
by { rw linear_isometry_equiv.comp_fderiv_within _ (hs x hx), refl }
... = (fderiv_within 𝕜 ((iterated_fderiv_within 𝕜 n (λ y, fderiv_within 𝕜 f s y) s)) s x
: E → (E [×n]→L[𝕜] (E →L[𝕜] F))) (m 0) (init (tail m)) ((tail m) (last n)) : rfl
... = iterated_fderiv_within 𝕜 (nat.succ n) (λ y, fderiv_within 𝕜 f s y) s x
(init m) (m (last (n + 1))) :
by { rw [iterated_fderiv_within_succ_apply_left, tail_init_eq_init_tail], refl } }
end
/-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv,
and the `n`-th derivative of the derivative. -/
lemma iterated_fderiv_within_succ_eq_comp_right {n : ℕ} (hs : unique_diff_on 𝕜 s) (hx : x ∈ s) :
iterated_fderiv_within 𝕜 (n + 1) f s x =
((continuous_multilinear_curry_right_equiv' 𝕜 n E F)
∘ (iterated_fderiv_within 𝕜 n (λy, fderiv_within 𝕜 f s y) s)) x :=
by { ext m, rw iterated_fderiv_within_succ_apply_right hs hx, refl }
@[simp] lemma iterated_fderiv_within_one_apply
(hs : unique_diff_on 𝕜 s) (hx : x ∈ s) (m : (fin 1) → E) :
(iterated_fderiv_within 𝕜 1 f s x : ((fin 1) → E) → F) m
= (fderiv_within 𝕜 f s x : E → F) (m 0) :=
by { rw [iterated_fderiv_within_succ_apply_right hs hx, iterated_fderiv_within_zero_apply], refl }
/-- If two functions coincide on a set `s` of unique differentiability, then their iterated
differentials within this set coincide. -/
lemma iterated_fderiv_within_congr {n : ℕ}
(hs : unique_diff_on 𝕜 s) (hL : ∀y∈s, f₁ y = f y) (hx : x ∈ s) :
iterated_fderiv_within 𝕜 n f₁ s x = iterated_fderiv_within 𝕜 n f s x :=
begin
induction n with n IH generalizing x,
{ ext m, simp [hL x hx] },
{ have : fderiv_within 𝕜 (λ y, iterated_fderiv_within 𝕜 n f₁ s y) s x
= fderiv_within 𝕜 (λ y, iterated_fderiv_within 𝕜 n f s y) s x :=
fderiv_within_congr (hs x hx) (λ y hy, IH hy) (IH hx),
ext m,
rw [iterated_fderiv_within_succ_apply_left, iterated_fderiv_within_succ_apply_left, this] }
end
/-- The iterated differential within a set `s` at a point `x` is not modified if one intersects
`s` with an open set containing `x`. -/
lemma iterated_fderiv_within_inter_open {n : ℕ} (hu : is_open u)
(hs : unique_diff_on 𝕜 (s ∩ u)) (hx : x ∈ s ∩ u) :
iterated_fderiv_within 𝕜 n f (s ∩ u) x = iterated_fderiv_within 𝕜 n f s x :=
begin
induction n with n IH generalizing x,
{ ext m, simp },
{ have A : fderiv_within 𝕜 (λ y, iterated_fderiv_within 𝕜 n f (s ∩ u) y) (s ∩ u) x
= fderiv_within 𝕜 (λ y, iterated_fderiv_within 𝕜 n f s y) (s ∩ u) x :=
fderiv_within_congr (hs x hx) (λ y hy, IH hy) (IH hx),
have B : fderiv_within 𝕜 (λ y, iterated_fderiv_within 𝕜 n f s y) (s ∩ u) x
= fderiv_within 𝕜 (λ y, iterated_fderiv_within 𝕜 n f s y) s x :=
fderiv_within_inter (is_open.mem_nhds hu hx.2)
((unique_diff_within_at_inter (is_open.mem_nhds hu hx.2)).1 (hs x hx)),
ext m,
rw [iterated_fderiv_within_succ_apply_left, iterated_fderiv_within_succ_apply_left, A, B] }
end
/-- The iterated differential within a set `s` at a point `x` is not modified if one intersects
`s` with a neighborhood of `x` within `s`. -/
lemma iterated_fderiv_within_inter' {n : ℕ}
(hu : u ∈ 𝓝[s] x) (hs : unique_diff_on 𝕜 s) (xs : x ∈ s) :
iterated_fderiv_within 𝕜 n f (s ∩ u) x = iterated_fderiv_within 𝕜 n f s x :=
begin
obtain ⟨v, v_open, xv, vu⟩ : ∃ v, is_open v ∧ x ∈ v ∧ v ∩ s ⊆ u := mem_nhds_within.1 hu,
have A : (s ∩ u) ∩ v = s ∩ v,
{ apply subset.antisymm (inter_subset_inter (inter_subset_left _ _) (subset.refl _)),
exact λ y ⟨ys, yv⟩, ⟨⟨ys, vu ⟨yv, ys⟩⟩, yv⟩ },
have : iterated_fderiv_within 𝕜 n f (s ∩ v) x = iterated_fderiv_within 𝕜 n f s x :=
iterated_fderiv_within_inter_open v_open (hs.inter v_open) ⟨xs, xv⟩,
rw ← this,
have : iterated_fderiv_within 𝕜 n f ((s ∩ u) ∩ v) x = iterated_fderiv_within 𝕜 n f (s ∩ u) x,
{ refine iterated_fderiv_within_inter_open v_open _ ⟨⟨xs, vu ⟨xv, xs⟩⟩, xv⟩,
rw A,
exact hs.inter v_open },
rw A at this,
rw ← this
end
/-- The iterated differential within a set `s` at a point `x` is not modified if one intersects
`s` with a neighborhood of `x`. -/
lemma iterated_fderiv_within_inter {n : ℕ}
(hu : u ∈ 𝓝 x) (hs : unique_diff_on 𝕜 s) (xs : x ∈ s) :
iterated_fderiv_within 𝕜 n f (s ∩ u) x = iterated_fderiv_within 𝕜 n f s x :=
iterated_fderiv_within_inter' (mem_nhds_within_of_mem_nhds hu) hs xs
@[simp] lemma times_cont_diff_on_zero :
times_cont_diff_on 𝕜 0 f s ↔ continuous_on f s :=
begin
refine ⟨λ H, H.continuous_on, λ H, _⟩,
assume x hx m hm,
have : (m : with_top ℕ) = 0 := le_antisymm hm bot_le,
rw this,
refine ⟨insert x s, self_mem_nhds_within, ftaylor_series_within 𝕜 f s, _⟩,
rw has_ftaylor_series_up_to_on_zero_iff,
exact ⟨by rwa insert_eq_of_mem hx, λ x hx, by simp [ftaylor_series_within]⟩
end
lemma times_cont_diff_within_at_zero (hx : x ∈ s) :
times_cont_diff_within_at 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, continuous_on f (s ∩ u) :=
begin
split,
{ intros h,
obtain ⟨u, H, p, hp⟩ := h 0 (by norm_num),
refine ⟨u, _, _⟩,
{ simpa [hx] using H },
{ simp only [with_top.coe_zero, has_ftaylor_series_up_to_on_zero_iff] at hp,
exact hp.1.mono (inter_subset_right s u) } },
{ rintros ⟨u, H, hu⟩,
rw ← times_cont_diff_within_at_inter' H,
have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhds_within hx H⟩,
exact (times_cont_diff_on_zero.mpr hu).times_cont_diff_within_at h' }
end
/-- On a set with unique differentiability, any choice of iterated differential has to coincide
with the one we have chosen in `iterated_fderiv_within 𝕜 m f s`. -/
theorem has_ftaylor_series_up_to_on.eq_ftaylor_series_of_unique_diff_on {n : with_top ℕ}
(h : has_ftaylor_series_up_to_on n f p s)
{m : ℕ} (hmn : (m : with_top ℕ) ≤ n) (hs : unique_diff_on 𝕜 s) (hx : x ∈ s) :
p x m = iterated_fderiv_within 𝕜 m f s x :=
begin
induction m with m IH generalizing x,
{ rw [h.zero_eq' hx, iterated_fderiv_within_zero_eq_comp] },
{ have A : (m : with_top ℕ) < n := lt_of_lt_of_le (with_top.coe_lt_coe.2 (lt_add_one m)) hmn,
have : has_fderiv_within_at (λ (y : E), iterated_fderiv_within 𝕜 m f s y)
(continuous_multilinear_map.curry_left (p x (nat.succ m))) s x :=
(h.fderiv_within m A x hx).congr (λ y hy, (IH (le_of_lt A) hy).symm) (IH (le_of_lt A) hx).symm,
rw [iterated_fderiv_within_succ_eq_comp_left, function.comp_apply,
this.fderiv_within (hs x hx)],
exact (continuous_multilinear_map.uncurry_curry_left _).symm }
end
/-- When a function is `C^n` in a set `s` of unique differentiability, it admits
`ftaylor_series_within 𝕜 f s` as a Taylor series up to order `n` in `s`. -/
theorem times_cont_diff_on.ftaylor_series_within {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hs : unique_diff_on 𝕜 s) :
has_ftaylor_series_up_to_on n f (ftaylor_series_within 𝕜 f s) s :=
begin
split,
{ assume x hx,
simp only [ftaylor_series_within, continuous_multilinear_map.uncurry0_apply,
iterated_fderiv_within_zero_apply] },
{ assume m hm x hx,
rcases (h x hx) m.succ (with_top.add_one_le_of_lt hm) with ⟨u, hu, p, Hp⟩,
rw insert_eq_of_mem hx at hu,
rcases mem_nhds_within.1 hu with ⟨o, o_open, xo, ho⟩,
rw inter_comm at ho,
have : p x m.succ = ftaylor_series_within 𝕜 f s x m.succ,
{ change p x m.succ = iterated_fderiv_within 𝕜 m.succ f s x,
rw ← iterated_fderiv_within_inter (is_open.mem_nhds o_open xo) hs hx,
exact (Hp.mono ho).eq_ftaylor_series_of_unique_diff_on (le_refl _)
(hs.inter o_open) ⟨hx, xo⟩ },
rw [← this, ← has_fderiv_within_at_inter (is_open.mem_nhds o_open xo)],
have A : ∀ y ∈ s ∩ o, p y m = ftaylor_series_within 𝕜 f s y m,
{ rintros y ⟨hy, yo⟩,
change p y m = iterated_fderiv_within 𝕜 m f s y,
rw ← iterated_fderiv_within_inter (is_open.mem_nhds o_open yo) hs hy,
exact (Hp.mono ho).eq_ftaylor_series_of_unique_diff_on (with_top.coe_le_coe.2 (nat.le_succ m))
(hs.inter o_open) ⟨hy, yo⟩ },
exact ((Hp.mono ho).fderiv_within m (with_top.coe_lt_coe.2 (lt_add_one m)) x ⟨hx, xo⟩).congr
(λ y hy, (A y hy).symm) (A x ⟨hx, xo⟩).symm },
{ assume m hm,
apply continuous_on_of_locally_continuous_on,
assume x hx,
rcases h x hx m hm with ⟨u, hu, p, Hp⟩,
rcases mem_nhds_within.1 hu with ⟨o, o_open, xo, ho⟩,
rw insert_eq_of_mem hx at ho,
rw inter_comm at ho,
refine ⟨o, o_open, xo, _⟩,
have A : ∀ y ∈ s ∩ o, p y m = ftaylor_series_within 𝕜 f s y m,
{ rintros y ⟨hy, yo⟩,
change p y m = iterated_fderiv_within 𝕜 m f s y,
rw ← iterated_fderiv_within_inter (is_open.mem_nhds o_open yo) hs hy,
exact (Hp.mono ho).eq_ftaylor_series_of_unique_diff_on (le_refl _)
(hs.inter o_open) ⟨hy, yo⟩ },
exact ((Hp.mono ho).cont m (le_refl _)).congr (λ y hy, (A y hy).symm) }
end
lemma times_cont_diff_on_of_continuous_on_differentiable_on {n : with_top ℕ}
(Hcont : ∀ (m : ℕ), (m : with_top ℕ) ≤ n →
continuous_on (λ x, iterated_fderiv_within 𝕜 m f s x) s)
(Hdiff : ∀ (m : ℕ), (m : with_top ℕ) < n →
differentiable_on 𝕜 (λ x, iterated_fderiv_within 𝕜 m f s x) s) :
times_cont_diff_on 𝕜 n f s :=
begin
assume x hx m hm,
rw insert_eq_of_mem hx,
refine ⟨s, self_mem_nhds_within, ftaylor_series_within 𝕜 f s, _⟩,
split,
{ assume y hy,
simp only [ftaylor_series_within, continuous_multilinear_map.uncurry0_apply,
iterated_fderiv_within_zero_apply] },
{ assume k hk y hy,
convert (Hdiff k (lt_of_lt_of_le hk hm) y hy).has_fderiv_within_at,
simp only [ftaylor_series_within, iterated_fderiv_within_succ_eq_comp_left,
continuous_linear_equiv.coe_apply, function.comp_app, coe_fn_coe_base],
exact continuous_linear_map.curry_uncurry_left _ },
{ assume k hk,
exact Hcont k (le_trans hk hm) }
end
lemma times_cont_diff_on_of_differentiable_on {n : with_top ℕ}
(h : ∀(m : ℕ), (m : with_top ℕ) ≤ n → differentiable_on 𝕜 (iterated_fderiv_within 𝕜 m f s) s) :
times_cont_diff_on 𝕜 n f s :=
times_cont_diff_on_of_continuous_on_differentiable_on
(λ m hm, (h m hm).continuous_on) (λ m hm, (h m (le_of_lt hm)))
lemma times_cont_diff_on.continuous_on_iterated_fderiv_within {n : with_top ℕ} {m : ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hmn : (m : with_top ℕ) ≤ n) (hs : unique_diff_on 𝕜 s) :
continuous_on (iterated_fderiv_within 𝕜 m f s) s :=
(h.ftaylor_series_within hs).cont m hmn
lemma times_cont_diff_on.differentiable_on_iterated_fderiv_within {n : with_top ℕ} {m : ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hmn : (m : with_top ℕ) < n) (hs : unique_diff_on 𝕜 s) :
differentiable_on 𝕜 (iterated_fderiv_within 𝕜 m f s) s :=
λ x hx, ((h.ftaylor_series_within hs).fderiv_within m hmn x hx).differentiable_within_at
lemma times_cont_diff_on_iff_continuous_on_differentiable_on {n : with_top ℕ}
(hs : unique_diff_on 𝕜 s) :
times_cont_diff_on 𝕜 n f s ↔
(∀ (m : ℕ), (m : with_top ℕ) ≤ n →
continuous_on (λ x, iterated_fderiv_within 𝕜 m f s x) s)
∧ (∀ (m : ℕ), (m : with_top ℕ) < n →
differentiable_on 𝕜 (λ x, iterated_fderiv_within 𝕜 m f s x) s) :=
begin
split,
{ assume h,
split,
{ assume m hm, exact h.continuous_on_iterated_fderiv_within hm hs },
{ assume m hm, exact h.differentiable_on_iterated_fderiv_within hm hs } },
{ assume h,
exact times_cont_diff_on_of_continuous_on_differentiable_on h.1 h.2 }
end
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (expressed with `fderiv_within`) is `C^n`. -/
theorem times_cont_diff_on_succ_iff_fderiv_within {n : ℕ} (hs : unique_diff_on 𝕜 s) :
times_cont_diff_on 𝕜 ((n + 1) : ℕ) f s ↔
differentiable_on 𝕜 f s ∧ times_cont_diff_on 𝕜 n (λ y, fderiv_within 𝕜 f s y) s :=
begin
split,
{ assume H,
refine ⟨H.differentiable_on (with_top.coe_le_coe.2 (nat.le_add_left 1 n)), λ x hx, _⟩,
rcases times_cont_diff_within_at_succ_iff_has_fderiv_within_at.1 (H x hx)
with ⟨u, hu, f', hff', hf'⟩,
rcases mem_nhds_within.1 hu with ⟨o, o_open, xo, ho⟩,
rw [inter_comm, insert_eq_of_mem hx] at ho,
have := hf'.mono ho,
rw times_cont_diff_within_at_inter' (mem_nhds_within_of_mem_nhds (is_open.mem_nhds o_open xo))
at this,
apply this.congr_of_eventually_eq' _ hx,
have : o ∩ s ∈ 𝓝[s] x := mem_nhds_within.2 ⟨o, o_open, xo, subset.refl _⟩,
rw inter_comm at this,
apply filter.eventually_eq_of_mem this (λ y hy, _),
have A : fderiv_within 𝕜 f (s ∩ o) y = f' y :=
((hff' y (ho hy)).mono ho).fderiv_within (hs.inter o_open y hy),
rwa fderiv_within_inter (is_open.mem_nhds o_open hy.2) (hs y hy.1) at A, },
{ rintros ⟨hdiff, h⟩ x hx,
rw [times_cont_diff_within_at_succ_iff_has_fderiv_within_at, insert_eq_of_mem hx],
exact ⟨s, self_mem_nhds_within, fderiv_within 𝕜 f s,
λ y hy, (hdiff y hy).has_fderiv_within_at, h x hx⟩ }
end
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/
theorem times_cont_diff_on_succ_iff_fderiv_of_open {n : ℕ} (hs : is_open s) :
times_cont_diff_on 𝕜 ((n + 1) : ℕ) f s ↔
differentiable_on 𝕜 f s ∧ times_cont_diff_on 𝕜 n (λ y, fderiv 𝕜 f y) s :=
begin
rw times_cont_diff_on_succ_iff_fderiv_within hs.unique_diff_on,
congr' 2,
rw ← iff_iff_eq,
apply times_cont_diff_on_congr,
assume x hx,
exact fderiv_within_of_open hs hx
end
/-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable
there, and its derivative (expressed with `fderiv_within`) is `C^∞`. -/
theorem times_cont_diff_on_top_iff_fderiv_within (hs : unique_diff_on 𝕜 s) :
times_cont_diff_on 𝕜 ∞ f s ↔
differentiable_on 𝕜 f s ∧ times_cont_diff_on 𝕜 ∞ (λ y, fderiv_within 𝕜 f s y) s :=
begin
split,
{ assume h,
refine ⟨h.differentiable_on le_top, _⟩,
apply times_cont_diff_on_top.2 (λ n, ((times_cont_diff_on_succ_iff_fderiv_within hs).1 _).2),
exact h.of_le le_top },
{ assume h,
refine times_cont_diff_on_top.2 (λ n, _),
have A : (n : with_top ℕ) ≤ ∞ := le_top,
apply ((times_cont_diff_on_succ_iff_fderiv_within hs).2 ⟨h.1, h.2.of_le A⟩).of_le,
exact with_top.coe_le_coe.2 (nat.le_succ n) }
end
/-- A function is `C^∞` on an open domain if and only if it is differentiable there, and its
derivative (expressed with `fderiv`) is `C^∞`. -/
theorem times_cont_diff_on_top_iff_fderiv_of_open (hs : is_open s) :
times_cont_diff_on 𝕜 ∞ f s ↔
differentiable_on 𝕜 f s ∧ times_cont_diff_on 𝕜 ∞ (λ y, fderiv 𝕜 f y) s :=
begin
rw times_cont_diff_on_top_iff_fderiv_within hs.unique_diff_on,
congr' 2,
rw ← iff_iff_eq,
apply times_cont_diff_on_congr,
assume x hx,
exact fderiv_within_of_open hs hx
end
lemma times_cont_diff_on.fderiv_within {m n : with_top ℕ}
(hf : times_cont_diff_on 𝕜 n f s) (hs : unique_diff_on 𝕜 s) (hmn : m + 1 ≤ n) :
times_cont_diff_on 𝕜 m (λ y, fderiv_within 𝕜 f s y) s :=
begin
cases m,
{ change ∞ + 1 ≤ n at hmn,
have : n = ∞, by simpa using hmn,
rw this at hf,
exact ((times_cont_diff_on_top_iff_fderiv_within hs).1 hf).2 },
{ change (m.succ : with_top ℕ) ≤ n at hmn,
exact ((times_cont_diff_on_succ_iff_fderiv_within hs).1 (hf.of_le hmn)).2 }
end
lemma times_cont_diff_on.fderiv_of_open {m n : with_top ℕ}
(hf : times_cont_diff_on 𝕜 n f s) (hs : is_open s) (hmn : m + 1 ≤ n) :
times_cont_diff_on 𝕜 m (λ y, fderiv 𝕜 f y) s :=
(hf.fderiv_within hs.unique_diff_on hmn).congr (λ x hx, (fderiv_within_of_open hs hx).symm)
lemma times_cont_diff_on.continuous_on_fderiv_within {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hs : unique_diff_on 𝕜 s) (hn : 1 ≤ n) :
continuous_on (λ x, fderiv_within 𝕜 f s x) s :=
((times_cont_diff_on_succ_iff_fderiv_within hs).1 (h.of_le hn)).2.continuous_on
lemma times_cont_diff_on.continuous_on_fderiv_of_open {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f s) (hs : is_open s) (hn : 1 ≤ n) :
continuous_on (λ x, fderiv 𝕜 f x) s :=
((times_cont_diff_on_succ_iff_fderiv_of_open hs).1 (h.of_le hn)).2.continuous_on
/-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is
continuous. -/
lemma times_cont_diff_on.continuous_on_fderiv_within_apply
{n : with_top ℕ} (h : times_cont_diff_on 𝕜 n f s) (hs : unique_diff_on 𝕜 s) (hn : 1 ≤ n) :
continuous_on (λp : E × E, (fderiv_within 𝕜 f s p.1 : E → F) p.2) (set.prod s univ) :=
begin
have A : continuous (λq : (E →L[𝕜] F) × E, q.1 q.2) := is_bounded_bilinear_map_apply.continuous,
have B : continuous_on (λp : E × E, (fderiv_within 𝕜 f s p.1, p.2)) (set.prod s univ),
{ apply continuous_on.prod _ continuous_snd.continuous_on,
exact continuous_on.comp (h.continuous_on_fderiv_within hs hn) continuous_fst.continuous_on
(prod_subset_preimage_fst _ _) },
exact A.comp_continuous_on B
end
/-! ### Functions with a Taylor series on the whole space -/
/-- `has_ftaylor_series_up_to n f p` registers the fact that `p 0 = f` and `p (m+1)` is a
derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to
`has_fderiv_at` but for higher order derivatives. -/
structure has_ftaylor_series_up_to (n : with_top ℕ)
(f : E → F) (p : E → formal_multilinear_series 𝕜 E F) : Prop :=
(zero_eq : ∀ x, (p x 0).uncurry0 = f x)
(fderiv : ∀ (m : ℕ) (hm : (m : with_top ℕ) < n), ∀ x,
has_fderiv_at (λ y, p y m) (p x m.succ).curry_left x)
(cont : ∀ (m : ℕ) (hm : (m : with_top ℕ) ≤ n), continuous (λ x, p x m))
lemma has_ftaylor_series_up_to.zero_eq' {n : with_top ℕ}
(h : has_ftaylor_series_up_to n f p) (x : E) :
p x 0 = (continuous_multilinear_curry_fin0 𝕜 E F).symm (f x) :=
by { rw ← h.zero_eq x, symmetry, exact continuous_multilinear_map.uncurry0_curry0 _ }
lemma has_ftaylor_series_up_to_on_univ_iff {n : with_top ℕ} :
has_ftaylor_series_up_to_on n f p univ ↔ has_ftaylor_series_up_to n f p :=
begin
split,
{ assume H,
split,
{ exact λ x, H.zero_eq x (mem_univ x) },
{ assume m hm x,
rw ← has_fderiv_within_at_univ,
exact H.fderiv_within m hm x (mem_univ x) },
{ assume m hm,
rw continuous_iff_continuous_on_univ,
exact H.cont m hm } },
{ assume H,
split,
{ exact λ x hx, H.zero_eq x },
{ assume m hm x hx,
rw has_fderiv_within_at_univ,
exact H.fderiv m hm x },
{ assume m hm,
rw ← continuous_iff_continuous_on_univ,
exact H.cont m hm } }
end
lemma has_ftaylor_series_up_to.has_ftaylor_series_up_to_on {n : with_top ℕ}
(h : has_ftaylor_series_up_to n f p) (s : set E) :
has_ftaylor_series_up_to_on n f p s :=
(has_ftaylor_series_up_to_on_univ_iff.2 h).mono (subset_univ _)
lemma has_ftaylor_series_up_to.of_le {m n : with_top ℕ}
(h : has_ftaylor_series_up_to n f p) (hmn : m ≤ n) :
has_ftaylor_series_up_to m f p :=
by { rw ← has_ftaylor_series_up_to_on_univ_iff at h ⊢, exact h.of_le hmn }
lemma has_ftaylor_series_up_to.continuous {n : with_top ℕ}
(h : has_ftaylor_series_up_to n f p) : continuous f :=
begin
rw ← has_ftaylor_series_up_to_on_univ_iff at h,
rw continuous_iff_continuous_on_univ,
exact h.continuous_on
end
lemma has_ftaylor_series_up_to_zero_iff :
has_ftaylor_series_up_to 0 f p ↔ continuous f ∧ (∀ x, (p x 0).uncurry0 = f x) :=
by simp [has_ftaylor_series_up_to_on_univ_iff.symm, continuous_iff_continuous_on_univ,
has_ftaylor_series_up_to_on_zero_iff]
/-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this
series is a derivative of `f`. -/
lemma has_ftaylor_series_up_to.has_fderiv_at {n : with_top ℕ}
(h : has_ftaylor_series_up_to n f p) (hn : 1 ≤ n) (x : E) :
has_fderiv_at f (continuous_multilinear_curry_fin1 𝕜 E F (p x 1)) x :=
begin
rw [← has_fderiv_within_at_univ],
exact (has_ftaylor_series_up_to_on_univ_iff.2 h).has_fderiv_within_at hn (mem_univ _)
end
lemma has_ftaylor_series_up_to.differentiable {n : with_top ℕ}
(h : has_ftaylor_series_up_to n f p) (hn : 1 ≤ n) : differentiable 𝕜 f :=
λ x, (h.has_fderiv_at hn x).differentiable_at
/-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n`
for `p 1`, which is a derivative of `f`. -/
theorem has_ftaylor_series_up_to_succ_iff_right {n : ℕ} :
has_ftaylor_series_up_to ((n + 1) : ℕ) f p ↔
(∀ x, (p x 0).uncurry0 = f x)
∧ (∀ x, has_fderiv_at (λ y, p y 0) (p x 1).curry_left x)
∧ has_ftaylor_series_up_to n
(λ x, continuous_multilinear_curry_fin1 𝕜 E F (p x 1)) (λ x, (p x).shift) :=
by simp [has_ftaylor_series_up_to_on_succ_iff_right, has_ftaylor_series_up_to_on_univ_iff.symm,
-add_comm, -with_zero.coe_add]
/-! ### Smooth functions at a point -/
variable (𝕜)
/-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`,
there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous.
-/
def times_cont_diff_at (n : with_top ℕ) (f : E → F) (x : E) :=
times_cont_diff_within_at 𝕜 n f univ x
variable {𝕜}
theorem times_cont_diff_within_at_univ {n : with_top ℕ} :
times_cont_diff_within_at 𝕜 n f univ x ↔ times_cont_diff_at 𝕜 n f x :=
iff.rfl
lemma times_cont_diff_at_top :
times_cont_diff_at 𝕜 ∞ f x ↔ ∀ (n : ℕ), times_cont_diff_at 𝕜 n f x :=
by simp [← times_cont_diff_within_at_univ, times_cont_diff_within_at_top]
lemma times_cont_diff_at.times_cont_diff_within_at {n : with_top ℕ}
(h : times_cont_diff_at 𝕜 n f x) : times_cont_diff_within_at 𝕜 n f s x :=
h.mono (subset_univ _)
lemma times_cont_diff_within_at.times_cont_diff_at {n : with_top ℕ}
(h : times_cont_diff_within_at 𝕜 n f s x) (hx : s ∈ 𝓝 x) :
times_cont_diff_at 𝕜 n f x :=
by rwa [times_cont_diff_at, ← times_cont_diff_within_at_inter hx, univ_inter]
lemma times_cont_diff_at.congr_of_eventually_eq {n : with_top ℕ}
(h : times_cont_diff_at 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) :
times_cont_diff_at 𝕜 n f₁ x :=
h.congr_of_eventually_eq' (by rwa nhds_within_univ) (mem_univ x)
lemma times_cont_diff_at.of_le {m n : with_top ℕ}
(h : times_cont_diff_at 𝕜 n f x) (hmn : m ≤ n) :
times_cont_diff_at 𝕜 m f x :=
h.of_le hmn
lemma times_cont_diff_at.continuous_at {n : with_top ℕ}
(h : times_cont_diff_at 𝕜 n f x) : continuous_at f x :=
by simpa [continuous_within_at_univ] using h.continuous_within_at
/-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/
lemma times_cont_diff_at.differentiable_at {n : with_top ℕ}
(h : times_cont_diff_at 𝕜 n f x) (hn : 1 ≤ n) : differentiable_at 𝕜 f x :=
by simpa [hn, differentiable_within_at_univ] using h.differentiable_within_at
/-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/
theorem times_cont_diff_at_succ_iff_has_fderiv_at {n : ℕ} :
times_cont_diff_at 𝕜 ((n + 1) : ℕ) f x
↔ (∃ f' : E → (E →L[𝕜] F), (∃ u ∈ 𝓝 x, (∀ x ∈ u, has_fderiv_at f (f' x) x))
∧ (times_cont_diff_at 𝕜 n f' x)) :=
begin
rw [← times_cont_diff_within_at_univ, times_cont_diff_within_at_succ_iff_has_fderiv_within_at],
simp only [nhds_within_univ, exists_prop, mem_univ, insert_eq_of_mem],
split,
{ rintros ⟨u, H, f', h_fderiv, h_times_cont_diff⟩,
rcases mem_nhds_iff.mp H with ⟨t, htu, ht, hxt⟩,
refine ⟨f', ⟨t, _⟩, h_times_cont_diff.times_cont_diff_at H⟩,
refine ⟨mem_nhds_iff.mpr ⟨t, subset.rfl, ht, hxt⟩, _⟩,
intros y hyt,
refine (h_fderiv y (htu hyt)).has_fderiv_at _,
exact mem_nhds_iff.mpr ⟨t, htu, ht, hyt⟩ },
{ rintros ⟨f', ⟨u, H, h_fderiv⟩, h_times_cont_diff⟩,
refine ⟨u, H, f', _, h_times_cont_diff.times_cont_diff_within_at⟩,
intros x hxu,
exact (h_fderiv x hxu).has_fderiv_within_at }
end
/-! ### Smooth functions -/
variable (𝕜)
/-- A function is continuously differentiable up to `n` if it admits derivatives up to
order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives
might not be unique) we do not need to localize the definition in space or time.
-/
definition times_cont_diff (n : with_top ℕ) (f : E → F) :=
∃ p : E → formal_multilinear_series 𝕜 E F, has_ftaylor_series_up_to n f p
variable {𝕜}
theorem times_cont_diff_on_univ {n : with_top ℕ} :
times_cont_diff_on 𝕜 n f univ ↔ times_cont_diff 𝕜 n f :=
begin
split,
{ assume H,
use ftaylor_series_within 𝕜 f univ,
rw ← has_ftaylor_series_up_to_on_univ_iff,
exact H.ftaylor_series_within unique_diff_on_univ },
{ rintros ⟨p, hp⟩ x hx m hm,
exact ⟨univ, filter.univ_sets _, p, (hp.has_ftaylor_series_up_to_on univ).of_le hm⟩ }
end
lemma times_cont_diff_iff_times_cont_diff_at {n : with_top ℕ} :
times_cont_diff 𝕜 n f ↔ ∀ x, times_cont_diff_at 𝕜 n f x :=
by simp [← times_cont_diff_on_univ, times_cont_diff_on, times_cont_diff_at]
lemma times_cont_diff.times_cont_diff_at {n : with_top ℕ} (h : times_cont_diff 𝕜 n f) :
times_cont_diff_at 𝕜 n f x :=
times_cont_diff_iff_times_cont_diff_at.1 h x
lemma times_cont_diff.times_cont_diff_within_at {n : with_top ℕ} (h : times_cont_diff 𝕜 n f) :
times_cont_diff_within_at 𝕜 n f s x :=
h.times_cont_diff_at.times_cont_diff_within_at
lemma times_cont_diff_top :
times_cont_diff 𝕜 ∞ f ↔ ∀ (n : ℕ), times_cont_diff 𝕜 n f :=
by simp [times_cont_diff_on_univ.symm, times_cont_diff_on_top]
lemma times_cont_diff_all_iff_nat :
(∀ n, times_cont_diff 𝕜 n f) ↔ (∀ n : ℕ, times_cont_diff 𝕜 n f) :=
by simp only [← times_cont_diff_on_univ, times_cont_diff_on_all_iff_nat]
lemma times_cont_diff.times_cont_diff_on {n : with_top ℕ}
(h : times_cont_diff 𝕜 n f) : times_cont_diff_on 𝕜 n f s :=
(times_cont_diff_on_univ.2 h).mono (subset_univ _)
@[simp] lemma times_cont_diff_zero :
times_cont_diff 𝕜 0 f ↔ continuous f :=
begin
rw [← times_cont_diff_on_univ, continuous_iff_continuous_on_univ],
exact times_cont_diff_on_zero
end
lemma times_cont_diff_at_zero :
times_cont_diff_at 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, continuous_on f u :=
by { rw ← times_cont_diff_within_at_univ, simp [times_cont_diff_within_at_zero, nhds_within_univ] }
lemma times_cont_diff.of_le {m n : with_top ℕ}
(h : times_cont_diff 𝕜 n f) (hmn : m ≤ n) :
times_cont_diff 𝕜 m f :=
times_cont_diff_on_univ.1 $ (times_cont_diff_on_univ.2 h).of_le hmn
lemma times_cont_diff.continuous {n : with_top ℕ}
(h : times_cont_diff 𝕜 n f) : continuous f :=
times_cont_diff_zero.1 (h.of_le bot_le)
/-- If a function is `C^n` with `n ≥ 1`, then it is differentiable. -/
lemma times_cont_diff.differentiable {n : with_top ℕ}
(h : times_cont_diff 𝕜 n f) (hn : 1 ≤ n) : differentiable 𝕜 f :=
differentiable_on_univ.1 $ (times_cont_diff_on_univ.2 h).differentiable_on hn
/-! ### Iterated derivative -/
variable (𝕜)
/-- The `n`-th derivative of a function, as a multilinear map, defined inductively. -/
noncomputable def iterated_fderiv (n : ℕ) (f : E → F) :
E → (E [×n]→L[𝕜] F) :=
nat.rec_on n
(λ x, continuous_multilinear_map.curry0 𝕜 E (f x))
(λ n rec x, continuous_linear_map.uncurry_left (fderiv 𝕜 rec x))
/-- Formal Taylor series associated to a function within a set. -/
def ftaylor_series (f : E → F) (x : E) : formal_multilinear_series 𝕜 E F :=
λ n, iterated_fderiv 𝕜 n f x
variable {𝕜}
@[simp] lemma iterated_fderiv_zero_apply (m : (fin 0) → E) :
(iterated_fderiv 𝕜 0 f x : ((fin 0) → E) → F) m = f x := rfl
lemma iterated_fderiv_zero_eq_comp :
iterated_fderiv 𝕜 0 f = (continuous_multilinear_curry_fin0 𝕜 E F).symm ∘ f := rfl
lemma iterated_fderiv_succ_apply_left {n : ℕ} (m : fin (n + 1) → E):
(iterated_fderiv 𝕜 (n + 1) f x : (fin (n + 1) → E) → F) m
= (fderiv 𝕜 (iterated_fderiv 𝕜 n f) x : E → (E [×n]→L[𝕜] F)) (m 0) (tail m) := rfl
/-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv,
and the derivative of the `n`-th derivative. -/
lemma iterated_fderiv_succ_eq_comp_left {n : ℕ} :
iterated_fderiv 𝕜 (n + 1) f =
(continuous_multilinear_curry_left_equiv 𝕜 (λ(i : fin (n + 1)), E) F)
∘ (fderiv 𝕜 (iterated_fderiv 𝕜 n f)) := rfl
lemma iterated_fderiv_within_univ {n : ℕ} :
iterated_fderiv_within 𝕜 n f univ = iterated_fderiv 𝕜 n f :=
begin
induction n with n IH,
{ ext x, simp },
{ ext x m,
rw [iterated_fderiv_succ_apply_left, iterated_fderiv_within_succ_apply_left, IH,
fderiv_within_univ] }
end
lemma ftaylor_series_within_univ :
ftaylor_series_within 𝕜 f univ = ftaylor_series 𝕜 f :=
begin
ext1 x, ext1 n,
change iterated_fderiv_within 𝕜 n f univ x = iterated_fderiv 𝕜 n f x,
rw iterated_fderiv_within_univ
end
theorem iterated_fderiv_succ_apply_right {n : ℕ} (m : fin (n + 1) → E) :
(iterated_fderiv 𝕜 (n + 1) f x : (fin (n + 1) → E) → F) m
= iterated_fderiv 𝕜 n (λy, fderiv 𝕜 f y) x (init m) (m (last n)) :=
begin
rw [← iterated_fderiv_within_univ, ← iterated_fderiv_within_univ, ← fderiv_within_univ],
exact iterated_fderiv_within_succ_apply_right unique_diff_on_univ (mem_univ _) _
end
/-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv,
and the `n`-th derivative of the derivative. -/
lemma iterated_fderiv_succ_eq_comp_right {n : ℕ} :
iterated_fderiv 𝕜 (n + 1) f x =
((continuous_multilinear_curry_right_equiv' 𝕜 n E F)
∘ (iterated_fderiv 𝕜 n (λy, fderiv 𝕜 f y))) x :=
by { ext m, rw iterated_fderiv_succ_apply_right, refl }
@[simp] lemma iterated_fderiv_one_apply (m : (fin 1) → E) :
(iterated_fderiv 𝕜 1 f x : ((fin 1) → E) → F) m
= (fderiv 𝕜 f x : E → F) (m 0) :=
by { rw [iterated_fderiv_succ_apply_right, iterated_fderiv_zero_apply], refl }
/-- When a function is `C^n` in a set `s` of unique differentiability, it admits
`ftaylor_series_within 𝕜 f s` as a Taylor series up to order `n` in `s`. -/
theorem times_cont_diff_on_iff_ftaylor_series {n : with_top ℕ} :
times_cont_diff 𝕜 n f ↔ has_ftaylor_series_up_to n f (ftaylor_series 𝕜 f) :=
begin
split,
{ rw [← times_cont_diff_on_univ, ← has_ftaylor_series_up_to_on_univ_iff,
← ftaylor_series_within_univ],
exact λ h, times_cont_diff_on.ftaylor_series_within h unique_diff_on_univ },
{ assume h, exact ⟨ftaylor_series 𝕜 f, h⟩ }
end
lemma times_cont_diff_iff_continuous_differentiable {n : with_top ℕ} :
times_cont_diff 𝕜 n f ↔
(∀ (m : ℕ), (m : with_top ℕ) ≤ n → continuous (λ x, iterated_fderiv 𝕜 m f x))
∧ (∀ (m : ℕ), (m : with_top ℕ) < n → differentiable 𝕜 (λ x, iterated_fderiv 𝕜 m f x)) :=
by simp [times_cont_diff_on_univ.symm, continuous_iff_continuous_on_univ,
differentiable_on_univ.symm, iterated_fderiv_within_univ,
times_cont_diff_on_iff_continuous_on_differentiable_on unique_diff_on_univ]
lemma times_cont_diff_of_differentiable_iterated_fderiv {n : with_top ℕ}
(h : ∀(m : ℕ), (m : with_top ℕ) ≤ n → differentiable 𝕜 (iterated_fderiv 𝕜 m f)) :
times_cont_diff 𝕜 n f :=
times_cont_diff_iff_continuous_differentiable.2
⟨λ m hm, (h m hm).continuous, λ m hm, (h m (le_of_lt hm))⟩
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if
it is differentiable there, and its derivative is `C^n`. -/
theorem times_cont_diff_succ_iff_fderiv {n : ℕ} :
times_cont_diff 𝕜 ((n + 1) : ℕ) f ↔
differentiable 𝕜 f ∧ times_cont_diff 𝕜 n (λ y, fderiv 𝕜 f y) :=
by simp [times_cont_diff_on_univ.symm, differentiable_on_univ.symm, fderiv_within_univ.symm,
- fderiv_within_univ, times_cont_diff_on_succ_iff_fderiv_within unique_diff_on_univ,
-with_zero.coe_add, -add_comm]
/-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable
there, and its derivative is `C^∞`. -/
theorem times_cont_diff_top_iff_fderiv :
times_cont_diff 𝕜 ∞ f ↔
differentiable 𝕜 f ∧ times_cont_diff 𝕜 ∞ (λ y, fderiv 𝕜 f y) :=
begin
simp [times_cont_diff_on_univ.symm, differentiable_on_univ.symm, fderiv_within_univ.symm,
- fderiv_within_univ],
rw times_cont_diff_on_top_iff_fderiv_within unique_diff_on_univ,
end
lemma times_cont_diff.continuous_fderiv {n : with_top ℕ}
(h : times_cont_diff 𝕜 n f) (hn : 1 ≤ n) :
continuous (λ x, fderiv 𝕜 f x) :=
((times_cont_diff_succ_iff_fderiv).1 (h.of_le hn)).2.continuous
/-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is
continuous. -/
lemma times_cont_diff.continuous_fderiv_apply {n : with_top ℕ}
(h : times_cont_diff 𝕜 n f) (hn : 1 ≤ n) :
continuous (λp : E × E, (fderiv 𝕜 f p.1 : E → F) p.2) :=
begin
have A : continuous (λq : (E →L[𝕜] F) × E, q.1 q.2) := is_bounded_bilinear_map_apply.continuous,
have B : continuous (λp : E × E, (fderiv 𝕜 f p.1, p.2)),
{ apply continuous.prod_mk _ continuous_snd,
exact continuous.comp (h.continuous_fderiv hn) continuous_fst },
exact A.comp B
end
/-! ### Constants -/
lemma iterated_fderiv_within_zero_fun {n : ℕ} :
iterated_fderiv 𝕜 n (λ x : E, (0 : F)) = 0 :=
begin
induction n with n IH,
{ ext m, simp },
{ ext x m,
rw [iterated_fderiv_succ_apply_left, IH],
change (fderiv 𝕜 (λ (x : E), (0 : (E [×n]→L[𝕜] F))) x : E → (E [×n]→L[𝕜] F)) (m 0) (tail m) = _,
rw fderiv_const,
refl }
end
lemma times_cont_diff_zero_fun {n : with_top ℕ} :
times_cont_diff 𝕜 n (λ x : E, (0 : F)) :=
begin
apply times_cont_diff_of_differentiable_iterated_fderiv (λm hm, _),
rw iterated_fderiv_within_zero_fun,
apply differentiable_const (0 : (E [×m]→L[𝕜] F))
end
/--
Constants are `C^∞`.
-/
lemma times_cont_diff_const {n : with_top ℕ} {c : F} : times_cont_diff 𝕜 n (λx : E, c) :=
begin
suffices h : times_cont_diff 𝕜 ∞ (λx : E, c), by exact h.of_le le_top,
rw times_cont_diff_top_iff_fderiv,
refine ⟨differentiable_const c, _⟩,
rw fderiv_const,
exact times_cont_diff_zero_fun
end
lemma times_cont_diff_on_const {n : with_top ℕ} {c : F} {s : set E} :
times_cont_diff_on 𝕜 n (λx : E, c) s :=
times_cont_diff_const.times_cont_diff_on
lemma times_cont_diff_at_const {n : with_top ℕ} {c : F} :
times_cont_diff_at 𝕜 n (λx : E, c) x :=
times_cont_diff_const.times_cont_diff_at
lemma times_cont_diff_within_at_const {n : with_top ℕ} {c : F} :
times_cont_diff_within_at 𝕜 n (λx : E, c) s x :=
times_cont_diff_at_const.times_cont_diff_within_at
@[nontriviality] lemma times_cont_diff_of_subsingleton [subsingleton F] {n : with_top ℕ} :
times_cont_diff 𝕜 n f :=
by { rw [subsingleton.elim f (λ _, 0)], exact times_cont_diff_const }
@[nontriviality] lemma times_cont_diff_at_of_subsingleton [subsingleton F] {n : with_top ℕ} :
times_cont_diff_at 𝕜 n f x :=
by { rw [subsingleton.elim f (λ _, 0)], exact times_cont_diff_at_const }
@[nontriviality] lemma times_cont_diff_within_at_of_subsingleton [subsingleton F] {n : with_top ℕ} :
times_cont_diff_within_at 𝕜 n f s x :=
by { rw [subsingleton.elim f (λ _, 0)], exact times_cont_diff_within_at_const }
@[nontriviality] lemma times_cont_diff_on_of_subsingleton [subsingleton F] {n : with_top ℕ} :
times_cont_diff_on 𝕜 n f s :=
by { rw [subsingleton.elim f (λ _, 0)], exact times_cont_diff_on_const }
/-! ### Linear functions -/
/--
Unbundled bounded linear functions are `C^∞`.
-/
lemma is_bounded_linear_map.times_cont_diff {n : with_top ℕ} (hf : is_bounded_linear_map 𝕜 f) :
times_cont_diff 𝕜 n f :=
begin
suffices h : times_cont_diff 𝕜 ∞ f, by exact h.of_le le_top,
rw times_cont_diff_top_iff_fderiv,
refine ⟨hf.differentiable, _⟩,
simp [hf.fderiv],
exact times_cont_diff_const
end
lemma continuous_linear_map.times_cont_diff {n : with_top ℕ} (f : E →L[𝕜] F) :
times_cont_diff 𝕜 n f :=
f.is_bounded_linear_map.times_cont_diff
lemma continuous_linear_equiv.times_cont_diff {n : with_top ℕ} (f : E ≃L[𝕜] F) :
times_cont_diff 𝕜 n f :=
(f : E →L[𝕜] F).times_cont_diff
lemma linear_isometry_map.times_cont_diff {n : with_top ℕ} (f : E →ₗᵢ[𝕜] F) :
times_cont_diff 𝕜 n f :=
f.to_continuous_linear_map.times_cont_diff
lemma linear_isometry_equiv.times_cont_diff {n : with_top ℕ} (f : E ≃ₗᵢ[𝕜] F) :
times_cont_diff 𝕜 n f :=
(f : E →L[𝕜] F).times_cont_diff
/--
The first projection in a product is `C^∞`.
-/
lemma times_cont_diff_fst {n : with_top ℕ} : times_cont_diff 𝕜 n (prod.fst : E × F → E) :=
is_bounded_linear_map.times_cont_diff is_bounded_linear_map.fst
/--
The first projection on a domain in a product is `C^∞`.
-/
lemma times_cont_diff_on_fst {s : set (E×F)} {n : with_top ℕ} :
times_cont_diff_on 𝕜 n (prod.fst : E × F → E) s :=
times_cont_diff.times_cont_diff_on times_cont_diff_fst
/--
The first projection at a point in a product is `C^∞`.
-/
lemma times_cont_diff_at_fst {p : E × F} {n : with_top ℕ} :
times_cont_diff_at 𝕜 n (prod.fst : E × F → E) p :=
times_cont_diff_fst.times_cont_diff_at
/--
The first projection within a domain at a point in a product is `C^∞`.
-/
lemma times_cont_diff_within_at_fst {s : set (E × F)} {p : E × F} {n : with_top ℕ} :
times_cont_diff_within_at 𝕜 n (prod.fst : E × F → E) s p :=
times_cont_diff_fst.times_cont_diff_within_at
/--
The second projection in a product is `C^∞`.
-/
lemma times_cont_diff_snd {n : with_top ℕ} : times_cont_diff 𝕜 n (prod.snd : E × F → F) :=
is_bounded_linear_map.times_cont_diff is_bounded_linear_map.snd
/--
The second projection on a domain in a product is `C^∞`.
-/
lemma times_cont_diff_on_snd {s : set (E×F)} {n : with_top ℕ} :
times_cont_diff_on 𝕜 n (prod.snd : E × F → F) s :=
times_cont_diff.times_cont_diff_on times_cont_diff_snd
/--
The second projection at a point in a product is `C^∞`.
-/
lemma times_cont_diff_at_snd {p : E × F} {n : with_top ℕ} :
times_cont_diff_at 𝕜 n (prod.snd : E × F → F) p :=
times_cont_diff_snd.times_cont_diff_at
/--
The second projection within a domain at a point in a product is `C^∞`.
-/
lemma times_cont_diff_within_at_snd {s : set (E × F)} {p : E × F} {n : with_top ℕ} :
times_cont_diff_within_at 𝕜 n (prod.snd : E × F → F) s p :=
times_cont_diff_snd.times_cont_diff_within_at
/--
The identity is `C^∞`.
-/
lemma times_cont_diff_id {n : with_top ℕ} : times_cont_diff 𝕜 n (id : E → E) :=
is_bounded_linear_map.id.times_cont_diff
lemma times_cont_diff_within_at_id {n : with_top ℕ} {s x} :
times_cont_diff_within_at 𝕜 n (id : E → E) s x :=
times_cont_diff_id.times_cont_diff_within_at
lemma times_cont_diff_at_id {n : with_top ℕ} {x} :
times_cont_diff_at 𝕜 n (id : E → E) x :=
times_cont_diff_id.times_cont_diff_at
lemma times_cont_diff_on_id {n : with_top ℕ} {s} :
times_cont_diff_on 𝕜 n (id : E → E) s :=
times_cont_diff_id.times_cont_diff_on
/--
Bilinear functions are `C^∞`.
-/
lemma is_bounded_bilinear_map.times_cont_diff {n : with_top ℕ} (hb : is_bounded_bilinear_map 𝕜 b) :
times_cont_diff 𝕜 n b :=
begin
suffices h : times_cont_diff 𝕜 ∞ b, by exact h.of_le le_top,
rw times_cont_diff_top_iff_fderiv,
refine ⟨hb.differentiable, _⟩,
simp [hb.fderiv],
exact hb.is_bounded_linear_map_deriv.times_cont_diff
end
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor
series whose `k`-th term is given by `g ∘ (p k)`. -/
lemma has_ftaylor_series_up_to_on.continuous_linear_map_comp {n : with_top ℕ} (g : F →L[𝕜] G)
(hf : has_ftaylor_series_up_to_on n f p s) :
has_ftaylor_series_up_to_on n (g ∘ f) (λ x k, g.comp_continuous_multilinear_map (p x k)) s :=
begin
set L : Π m : ℕ, (E [×m]→L[𝕜] F) →L[𝕜] (E [×m]→L[𝕜] G) :=
λ m, continuous_linear_map.comp_continuous_multilinear_mapL g,
split,
{ exact λ x hx, congr_arg g (hf.zero_eq x hx) },
{ intros m hm x hx,
convert (L m).has_fderiv_at.comp_has_fderiv_within_at x (hf.fderiv_within m hm x hx) },
{ intros m hm,
convert (L m).continuous.comp_continuous_on (hf.cont m hm) }
end
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
lemma times_cont_diff_within_at.continuous_linear_map_comp {n : with_top ℕ} (g : F →L[𝕜] G)
(hf : times_cont_diff_within_at 𝕜 n f s x) :
times_cont_diff_within_at 𝕜 n (g ∘ f) s x :=
begin
assume m hm,
rcases hf m hm with ⟨u, hu, p, hp⟩,
exact ⟨u, hu, _, hp.continuous_linear_map_comp g⟩,
end
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
lemma times_cont_diff_at.continuous_linear_map_comp {n : with_top ℕ} (g : F →L[𝕜] G)
(hf : times_cont_diff_at 𝕜 n f x) :
times_cont_diff_at 𝕜 n (g ∘ f) x :=
times_cont_diff_within_at.continuous_linear_map_comp g hf
/-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/
lemma times_cont_diff_on.continuous_linear_map_comp {n : with_top ℕ} (g : F →L[𝕜] G)
(hf : times_cont_diff_on 𝕜 n f s) :
times_cont_diff_on 𝕜 n (g ∘ f) s :=
λ x hx, (hf x hx).continuous_linear_map_comp g
/-- Composition by continuous linear maps on the left preserves `C^n` functions. -/
lemma times_cont_diff.continuous_linear_map_comp {n : with_top ℕ} {f : E → F} (g : F →L[𝕜] G)
(hf : times_cont_diff 𝕜 n f) : times_cont_diff 𝕜 n (λx, g (f x)) :=
times_cont_diff_on_univ.1 $ times_cont_diff_on.continuous_linear_map_comp
_ (times_cont_diff_on_univ.2 hf)
/-- Composition by continuous linear equivs on the left respects higher differentiability on
domains. -/
lemma continuous_linear_equiv.comp_times_cont_diff_within_at_iff
{n : with_top ℕ} (e : F ≃L[𝕜] G) :
times_cont_diff_within_at 𝕜 n (e ∘ f) s x ↔ times_cont_diff_within_at 𝕜 n f s x :=
begin
split,
{ assume H,
have : f = e.symm ∘ (e ∘ f),
by { ext y, simp only [function.comp_app], rw e.symm_apply_apply (f y) },
rw this,
exact H.continuous_linear_map_comp _ },
{ assume H,
exact H.continuous_linear_map_comp _ }
end
/-- Composition by continuous linear equivs on the left respects higher differentiability on
domains. -/
lemma continuous_linear_equiv.comp_times_cont_diff_on_iff
{n : with_top ℕ} (e : F ≃L[𝕜] G) :
times_cont_diff_on 𝕜 n (e ∘ f) s ↔ times_cont_diff_on 𝕜 n f s :=
by simp [times_cont_diff_on, e.comp_times_cont_diff_within_at_iff]
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor
series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vₖ)` . -/
lemma has_ftaylor_series_up_to_on.comp_continuous_linear_map {n : with_top ℕ}
(hf : has_ftaylor_series_up_to_on n f p s) (g : G →L[𝕜] E) :
has_ftaylor_series_up_to_on n (f ∘ g)
(λ x k, (p (g x) k).comp_continuous_linear_map (λ _, g)) (g ⁻¹' s) :=
begin
let A : Π m : ℕ, (E [×m]→L[𝕜] F) → (G [×m]→L[𝕜] F) :=
λ m h, h.comp_continuous_linear_map (λ _, g),
have hA : ∀ m, is_bounded_linear_map 𝕜 (A m) :=
λ m, is_bounded_linear_map_continuous_multilinear_map_comp_linear g,
split,
{ assume x hx,
simp only [(hf.zero_eq (g x) hx).symm, function.comp_app],
change p (g x) 0 (λ (i : fin 0), g 0) = p (g x) 0 0,
rw continuous_linear_map.map_zero,
refl },
{ assume m hm x hx,
convert ((hA m).has_fderiv_at).comp_has_fderiv_within_at x
((hf.fderiv_within m hm (g x) hx).comp x (g.has_fderiv_within_at) (subset.refl _)),
ext y v,
change p (g x) (nat.succ m) (g ∘ (cons y v)) = p (g x) m.succ (cons (g y) (g ∘ v)),
rw comp_cons },
{ assume m hm,
exact (hA m).continuous.comp_continuous_on
((hf.cont m hm).comp g.continuous.continuous_on (subset.refl _)) }
end
/-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on
a domain. -/
lemma times_cont_diff_within_at.comp_continuous_linear_map {n : with_top ℕ} {x : G}
(g : G →L[𝕜] E) (hf : times_cont_diff_within_at 𝕜 n f s (g x)) :
times_cont_diff_within_at 𝕜 n (f ∘ g) (g ⁻¹' s) x :=
begin
assume m hm,
rcases hf m hm with ⟨u, hu, p, hp⟩,
refine ⟨g ⁻¹' u, _, _, hp.comp_continuous_linear_map g⟩,
apply continuous_within_at.preimage_mem_nhds_within',
{ exact g.continuous.continuous_within_at },
{ apply nhds_within_mono (g x) _ hu,
rw image_insert_eq,
exact insert_subset_insert (image_preimage_subset g s) }
end
/-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/
lemma times_cont_diff_on.comp_continuous_linear_map {n : with_top ℕ}
(hf : times_cont_diff_on 𝕜 n f s) (g : G →L[𝕜] E) :
times_cont_diff_on 𝕜 n (f ∘ g) (g ⁻¹' s) :=
λ x hx, (hf (g x) hx).comp_continuous_linear_map g
/-- Composition by continuous linear maps on the right preserves `C^n` functions. -/
lemma times_cont_diff.comp_continuous_linear_map {n : with_top ℕ} {f : E → F} {g : G →L[𝕜] E}
(hf : times_cont_diff 𝕜 n f) : times_cont_diff 𝕜 n (f ∘ g) :=
times_cont_diff_on_univ.1 $
times_cont_diff_on.comp_continuous_linear_map (times_cont_diff_on_univ.2 hf) _
/-- Composition by continuous linear equivs on the right respects higher differentiability at a
point in a domain. -/
lemma continuous_linear_equiv.times_cont_diff_within_at_comp_iff {n : with_top ℕ} (e : G ≃L[𝕜] E) :
times_cont_diff_within_at 𝕜 n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔
times_cont_diff_within_at 𝕜 n f s x :=
begin
split,
{ assume H,
have A : f = (f ∘ e) ∘ e.symm,
by { ext y, simp only [function.comp_app], rw e.apply_symm_apply y },
have B : e.symm ⁻¹' (e ⁻¹' s) = s,
by { rw [← preimage_comp, e.self_comp_symm], refl },
rw [A, ← B],
exact H.comp_continuous_linear_map _},
{ assume H,
have : x = e (e.symm x), by simp,
rw this at H,
exact H.comp_continuous_linear_map _ },
end
/-- Composition by continuous linear equivs on the right respects higher differentiability on
domains. -/
lemma continuous_linear_equiv.times_cont_diff_on_comp_iff {n : with_top ℕ} (e : G ≃L[𝕜] E) :
times_cont_diff_on 𝕜 n (f ∘ e) (e ⁻¹' s) ↔ times_cont_diff_on 𝕜 n f s :=
begin
refine ⟨λ H, _, λ H, H.comp_continuous_linear_map _⟩,
have A : f = (f ∘ e) ∘ e.symm,
by { ext y, simp only [function.comp_app], rw e.apply_symm_apply y },
have B : e.symm ⁻¹' (e ⁻¹' s) = s,
by { rw [← preimage_comp, e.self_comp_symm], refl },
rw [A, ← B],
exact H.comp_continuous_linear_map _
end
/-- If two functions `f` and `g` admit Taylor series `p` and `q` in a set `s`, then the cartesian
product of `f` and `g` admits the cartesian product of `p` and `q` as a Taylor series. -/
lemma has_ftaylor_series_up_to_on.prod {n : with_top ℕ} (hf : has_ftaylor_series_up_to_on n f p s)
{g : E → G} {q : E → formal_multilinear_series 𝕜 E G} (hg : has_ftaylor_series_up_to_on n g q s) :
has_ftaylor_series_up_to_on n (λ y, (f y, g y)) (λ y k, (p y k).prod (q y k)) s :=
begin
set L := λ m, continuous_multilinear_map.prodL 𝕜 (λ i : fin m, E) F G,
split,
{ assume x hx, rw [← hf.zero_eq x hx, ← hg.zero_eq x hx], refl },
{ assume m hm x hx,
convert (L m).has_fderiv_at.comp_has_fderiv_within_at x
((hf.fderiv_within m hm x hx).prod (hg.fderiv_within m hm x hx)) },
{ assume m hm,
exact (L m).continuous.comp_continuous_on ((hf.cont m hm).prod (hg.cont m hm)) }
end
/-- The cartesian product of `C^n` functions at a point in a domain is `C^n`. -/
lemma times_cont_diff_within_at.prod {n : with_top ℕ} {s : set E} {f : E → F} {g : E → G}
(hf : times_cont_diff_within_at 𝕜 n f s x) (hg : times_cont_diff_within_at 𝕜 n g s x) :
times_cont_diff_within_at 𝕜 n (λx:E, (f x, g x)) s x :=
begin
assume m hm,
rcases hf m hm with ⟨u, hu, p, hp⟩,
rcases hg m hm with ⟨v, hv, q, hq⟩,
exact ⟨u ∩ v, filter.inter_mem_sets hu hv, _,
(hp.mono (inter_subset_left u v)).prod (hq.mono (inter_subset_right u v))⟩
end
/-- The cartesian product of `C^n` functions on domains is `C^n`. -/
lemma times_cont_diff_on.prod {n : with_top ℕ} {s : set E} {f : E → F} {g : E → G}
(hf : times_cont_diff_on 𝕜 n f s) (hg : times_cont_diff_on 𝕜 n g s) :
times_cont_diff_on 𝕜 n (λx:E, (f x, g x)) s :=
λ x hx, (hf x hx).prod (hg x hx)
/-- The cartesian product of `C^n` functions at a point is `C^n`. -/
lemma times_cont_diff_at.prod {n : with_top ℕ} {f : E → F} {g : E → G}
(hf : times_cont_diff_at 𝕜 n f x) (hg : times_cont_diff_at 𝕜 n g x) :
times_cont_diff_at 𝕜 n (λx:E, (f x, g x)) x :=
times_cont_diff_within_at_univ.1 $ times_cont_diff_within_at.prod
(times_cont_diff_within_at_univ.2 hf)
(times_cont_diff_within_at_univ.2 hg)
/--
The cartesian product of `C^n` functions is `C^n`.
-/
lemma times_cont_diff.prod {n : with_top ℕ} {f : E → F} {g : E → G}
(hf : times_cont_diff 𝕜 n f) (hg : times_cont_diff 𝕜 n g) :
times_cont_diff 𝕜 n (λx:E, (f x, g x)) :=
times_cont_diff_on_univ.1 $ times_cont_diff_on.prod (times_cont_diff_on_univ.2 hf)
(times_cont_diff_on_univ.2 hg)
/-!
### Smoothness of functions `f : E → Π i, F' i`
-/
section pi
variables {ι : Type*} [fintype ι] {F' : ι → Type*} [Π i, normed_group (F' i)]
[Π i, normed_space 𝕜 (F' i)] {φ : Π i, E → F' i}
{p' : Π i, E → formal_multilinear_series 𝕜 E (F' i)}
{Φ : E → Π i, F' i} {P' : E → formal_multilinear_series 𝕜 E (Π i, F' i)}
{n : with_top ℕ}
lemma has_ftaylor_series_up_to_on_pi :
has_ftaylor_series_up_to_on n (λ x i, φ i x)
(λ x m, continuous_multilinear_map.pi (λ i, p' i x m)) s ↔
∀ i, has_ftaylor_series_up_to_on n (φ i) (p' i) s :=
begin
set pr := @continuous_linear_map.proj 𝕜 _ ι F' _ _ _,
letI : Π (m : ℕ) (i : ι), normed_space 𝕜 (E [×m]→L[𝕜] (F' i)) := λ m i, infer_instance,
set L : Π m : ℕ, (Π i, E [×m]→L[𝕜] (F' i)) ≃ₗᵢ[𝕜] (E [×m]→L[𝕜] (Π i, F' i)) :=
λ m, continuous_multilinear_map.piₗᵢ _ _,
refine ⟨λ h i, _, λ h, ⟨λ x hx, _, _, _⟩⟩,
{ convert h.continuous_linear_map_comp (pr i),
ext, refl },
{ ext1 i,
exact (h i).zero_eq x hx },
{ intros m hm x hx,
have := has_fderiv_within_at_pi.2 (λ i, (h i).fderiv_within m hm x hx),
convert (L m).has_fderiv_at.comp_has_fderiv_within_at x this },
{ intros m hm,
have := continuous_on_pi.2 (λ i, (h i).cont m hm),
convert (L m).continuous.comp_continuous_on this }
end
@[simp] lemma has_ftaylor_series_up_to_on_pi' :
has_ftaylor_series_up_to_on n Φ P' s ↔
∀ i, has_ftaylor_series_up_to_on n (λ x, Φ x i)
(λ x m, (@continuous_linear_map.proj 𝕜 _ ι F' _ _ _ i).comp_continuous_multilinear_map
(P' x m)) s :=
by { convert has_ftaylor_series_up_to_on_pi, ext, refl }
lemma times_cont_diff_within_at_pi :
times_cont_diff_within_at 𝕜 n Φ s x ↔
∀ i, times_cont_diff_within_at 𝕜 n (λ x, Φ x i) s x :=
begin
set pr := @continuous_linear_map.proj 𝕜 _ ι F' _ _ _,
refine ⟨λ h i, h.continuous_linear_map_comp (pr i), λ h m hm, _⟩,
choose u hux p hp using λ i, h i m hm,
exact ⟨⋂ i, u i, filter.Inter_mem_sets.2 hux, _,
has_ftaylor_series_up_to_on_pi.2 (λ i, (hp i).mono $ Inter_subset _ _)⟩,
end
lemma times_cont_diff_on_pi :
times_cont_diff_on 𝕜 n Φ s ↔ ∀ i, times_cont_diff_on 𝕜 n (λ x, Φ x i) s :=
⟨λ h i x hx, times_cont_diff_within_at_pi.1 (h x hx) _,
λ h x hx, times_cont_diff_within_at_pi.2 (λ i, h i x hx)⟩
lemma times_cont_diff_at_pi :
times_cont_diff_at 𝕜 n Φ x ↔ ∀ i, times_cont_diff_at 𝕜 n (λ x, Φ x i) x :=
times_cont_diff_within_at_pi
lemma times_cont_diff_pi :
times_cont_diff 𝕜 n Φ ↔ ∀ i, times_cont_diff 𝕜 n (λ x, Φ x i) :=
by simp only [← times_cont_diff_on_univ, times_cont_diff_on_pi]
end pi
/-!
### Composition of `C^n` functions
We show that the composition of `C^n` functions is `C^n`. One way to prove it would be to write
the `n`-th derivative of the composition (this is Faà di Bruno's formula) and check its continuity,
but this is very painful. Instead, we go for a simple inductive proof. Assume it is done for `n`.
Then, to check it for `n+1`, one needs to check that the derivative of `g ∘ f` is `C^n`, i.e.,
that `Dg(f x) ⬝ Df(x)` is `C^n`. The term `Dg (f x)` is the composition of two `C^n` functions, so
it is `C^n` by the inductive assumption. The term `Df(x)` is also `C^n`. Then, the matrix
multiplication is the application of a bilinear map (which is `C^∞`, and therefore `C^n`) to
`x ↦ (Dg(f x), Df x)`. As the composition of two `C^n` maps, it is again `C^n`, and we are done.
There is a subtlety in this argument: we apply the inductive assumption to functions on other Banach
spaces. In maths, one would say: prove by induction over `n` that, for all `C^n` maps between all
pairs of Banach spaces, their composition is `C^n`. In Lean, this is fine as long as the spaces
stay in the same universe. This is not the case in the above argument: if `E` lives in universe `u`
and `F` lives in universe `v`, then linear maps from `E` to `F` (to which the derivative of `f`
belongs) is in universe `max u v`. If one could quantify over finitely many universes, the above
proof would work fine, but this is not the case. One could still write the proof considering spaces
in any universe in `u, v, w, max u v, max v w, max u v w`, but it would be extremely tedious and
lead to a lot of duplication. Instead, we formulate the above proof when all spaces live in the same
universe (where everything is fine), and then we deduce the general result by lifting all our spaces
to a common universe. We use the trick that any space `H` is isomorphic through a continuous linear
equiv to `continuous_multilinear_map (λ (i : fin 0), E × F × G) H` to change the universe level,
and then argue that composing with such a linear equiv does not change the fact of being `C^n`,
which we have already proved previously.
-/
/-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all
spaces live in the same universe. Use instead `times_cont_diff_on.comp` which removes the universe
assumption (but is deduced from this one). -/
private lemma times_cont_diff_on.comp_same_univ
{Eu : Type u} [normed_group Eu] [normed_space 𝕜 Eu]
{Fu : Type u} [normed_group Fu] [normed_space 𝕜 Fu]
{Gu : Type u} [normed_group Gu] [normed_space 𝕜 Gu]
{n : with_top ℕ} {s : set Eu} {t : set Fu} {g : Fu → Gu} {f : Eu → Fu}
(hg : times_cont_diff_on 𝕜 n g t) (hf : times_cont_diff_on 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
times_cont_diff_on 𝕜 n (g ∘ f) s :=
begin
unfreezingI { induction n using with_top.nat_induction with n IH Itop generalizing Eu Fu Gu },
{ rw times_cont_diff_on_zero at hf hg ⊢,
exact continuous_on.comp hg hf st },
{ rw times_cont_diff_on_succ_iff_has_fderiv_within_at at hg ⊢,
assume x hx,
rcases (times_cont_diff_on_succ_iff_has_fderiv_within_at.1 hf) x hx
with ⟨u, hu, f', hf', f'_diff⟩,
rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩,
rw insert_eq_of_mem hx at hu ⊢,
have xu : x ∈ u := mem_of_mem_nhds_within hx hu,
let w := s ∩ (u ∩ f⁻¹' v),
have wv : w ⊆ f ⁻¹' v := λ y hy, hy.2.2,
have wu : w ⊆ u := λ y hy, hy.2.1,
have ws : w ⊆ s := λ y hy, hy.1,
refine ⟨w, _, λ y, (g' (f y)).comp (f' y), _, _⟩,
show w ∈ 𝓝[s] x,
{ apply filter.inter_mem_sets self_mem_nhds_within,
apply filter.inter_mem_sets hu,
apply continuous_within_at.preimage_mem_nhds_within',
{ rw ← continuous_within_at_inter' hu,
exact (hf' x xu).differentiable_within_at.continuous_within_at.mono
(inter_subset_right _ _) },
{ apply nhds_within_mono _ _ hv,
exact subset.trans (image_subset_iff.mpr st) (subset_insert (f x) t) } },
show ∀ y ∈ w,
has_fderiv_within_at (g ∘ f) ((g' (f y)).comp (f' y)) w y,
{ rintros y ⟨ys, yu, yv⟩,
exact (hg' (f y) yv).comp y ((hf' y yu).mono wu) wv },
show times_cont_diff_on 𝕜 n (λ y, (g' (f y)).comp (f' y)) w,
{ have A : times_cont_diff_on 𝕜 n (λ y, g' (f y)) w :=
IH g'_diff ((hf.of_le (with_top.coe_le_coe.2 (nat.le_succ n))).mono ws) wv,
have B : times_cont_diff_on 𝕜 n f' w := f'_diff.mono wu,
have C : times_cont_diff_on 𝕜 n (λ y, (f' y, g' (f y))) w :=
times_cont_diff_on.prod B A,
have D : times_cont_diff_on 𝕜 n (λ(p : (Eu →L[𝕜] Fu) × (Fu →L[𝕜] Gu)), p.2.comp p.1) univ :=
is_bounded_bilinear_map_comp.times_cont_diff.times_cont_diff_on,
exact IH D C (subset_univ _) } },
{ rw times_cont_diff_on_top at hf hg ⊢,
assume n,
apply Itop n (hg n) (hf n) st }
end
/-- The composition of `C^n` functions on domains is `C^n`. -/
lemma times_cont_diff_on.comp
{n : with_top ℕ} {s : set E} {t : set F} {g : F → G} {f : E → F}
(hg : times_cont_diff_on 𝕜 n g t) (hf : times_cont_diff_on 𝕜 n f s) (st : s ⊆ f ⁻¹' t) :
times_cont_diff_on 𝕜 n (g ∘ f) s :=
begin
/- we lift all the spaces to a common universe, as we have already proved the result in this
situation. For the lift, we use the trick that `H` is isomorphic through a
continuous linear equiv to `continuous_multilinear_map 𝕜 (λ (i : fin 0), (E × F × G)) H`, and
continuous linear equivs respect smoothness classes. -/
let Eu := continuous_multilinear_map 𝕜 (λ (i : fin 0), (E × F × G)) E,
letI : normed_group Eu := by apply_instance,
letI : normed_space 𝕜 Eu := by apply_instance,
let Fu := continuous_multilinear_map 𝕜 (λ (i : fin 0), (E × F × G)) F,
letI : normed_group Fu := by apply_instance,
letI : normed_space 𝕜 Fu := by apply_instance,
let Gu := continuous_multilinear_map 𝕜 (λ (i : fin 0), (E × F × G)) G,
letI : normed_group Gu := by apply_instance,
letI : normed_space 𝕜 Gu := by apply_instance,
-- declare the isomorphisms
let isoE : Eu ≃L[𝕜] E := continuous_multilinear_curry_fin0 𝕜 (E × F × G) E,
let isoF : Fu ≃L[𝕜] F := continuous_multilinear_curry_fin0 𝕜 (E × F × G) F,
let isoG : Gu ≃L[𝕜] G := continuous_multilinear_curry_fin0 𝕜 (E × F × G) G,
-- lift the functions to the new spaces, check smoothness there, and then go back.
let fu : Eu → Fu := (isoF.symm ∘ f) ∘ isoE,
have fu_diff : times_cont_diff_on 𝕜 n fu (isoE ⁻¹' s),
by rwa [isoE.times_cont_diff_on_comp_iff, isoF.symm.comp_times_cont_diff_on_iff],
let gu : Fu → Gu := (isoG.symm ∘ g) ∘ isoF,
have gu_diff : times_cont_diff_on 𝕜 n gu (isoF ⁻¹' t),
by rwa [isoF.times_cont_diff_on_comp_iff, isoG.symm.comp_times_cont_diff_on_iff],
have main : times_cont_diff_on 𝕜 n (gu ∘ fu) (isoE ⁻¹' s),
{ apply times_cont_diff_on.comp_same_univ gu_diff fu_diff,
assume y hy,
simp only [fu, continuous_linear_equiv.coe_apply, function.comp_app, mem_preimage],
rw isoF.apply_symm_apply (f (isoE y)),
exact st hy },
have : gu ∘ fu = (isoG.symm ∘ (g ∘ f)) ∘ isoE,
{ ext y,
simp only [function.comp_apply, gu, fu],
rw isoF.apply_symm_apply (f (isoE y)) },
rwa [this, isoE.times_cont_diff_on_comp_iff, isoG.symm.comp_times_cont_diff_on_iff] at main
end
/-- The composition of `C^n` functions on domains is `C^n`. -/
lemma times_cont_diff_on.comp'
{n : with_top ℕ} {s : set E} {t : set F} {g : F → G} {f : E → F}
(hg : times_cont_diff_on 𝕜 n g t) (hf : times_cont_diff_on 𝕜 n f s) :
times_cont_diff_on 𝕜 n (g ∘ f) (s ∩ f⁻¹' t) :=
hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
/-- The composition of a `C^n` function on a domain with a `C^n` function is `C^n`. -/
lemma times_cont_diff.comp_times_cont_diff_on {n : with_top ℕ} {s : set E} {g : F → G} {f : E → F}
(hg : times_cont_diff 𝕜 n g) (hf : times_cont_diff_on 𝕜 n f s) :
times_cont_diff_on 𝕜 n (g ∘ f) s :=
(times_cont_diff_on_univ.2 hg).comp hf subset_preimage_univ
/-- The composition of `C^n` functions is `C^n`. -/
lemma times_cont_diff.comp {n : with_top ℕ} {g : F → G} {f : E → F}
(hg : times_cont_diff 𝕜 n g) (hf : times_cont_diff 𝕜 n f) :
times_cont_diff 𝕜 n (g ∘ f) :=
times_cont_diff_on_univ.1 $ times_cont_diff_on.comp (times_cont_diff_on_univ.2 hg)
(times_cont_diff_on_univ.2 hf) (subset_univ _)
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
lemma times_cont_diff_within_at.comp
{n : with_top ℕ} {s : set E} {t : set F} {g : F → G} {f : E → F} (x : E)
(hg : times_cont_diff_within_at 𝕜 n g t (f x))
(hf : times_cont_diff_within_at 𝕜 n f s x) (st : s ⊆ f ⁻¹' t) :
times_cont_diff_within_at 𝕜 n (g ∘ f) s x :=
begin
assume m hm,
rcases hg.times_cont_diff_on hm with ⟨u, u_nhd, ut, hu⟩,
rcases hf.times_cont_diff_on hm with ⟨v, v_nhd, vs, hv⟩,
have xmem : x ∈ f ⁻¹' u ∩ v :=
⟨(mem_of_mem_nhds_within (mem_insert (f x) _) u_nhd : _),
mem_of_mem_nhds_within (mem_insert x s) v_nhd⟩,
have : f ⁻¹' u ∈ 𝓝[insert x s] x,
{ apply hf.continuous_within_at.insert_self.preimage_mem_nhds_within',
apply nhds_within_mono _ _ u_nhd,
rw image_insert_eq,
exact insert_subset_insert (image_subset_iff.mpr st) },
have Z := ((hu.comp (hv.mono (inter_subset_right (f ⁻¹' u) v)) (inter_subset_left _ _))
.times_cont_diff_within_at) xmem m (le_refl _),
have : 𝓝[f ⁻¹' u ∩ v] x = 𝓝[insert x s] x,
{ have A : f ⁻¹' u ∩ v = (insert x s) ∩ (f ⁻¹' u ∩ v),
{ apply subset.antisymm _ (inter_subset_right _ _),
rintros y ⟨hy1, hy2⟩,
simp [hy1, hy2, vs hy2] },
rw [A, ← nhds_within_restrict''],
exact filter.inter_mem_sets this v_nhd },
rwa [insert_eq_of_mem xmem, this] at Z,
end
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
lemma times_cont_diff_within_at.comp' {n : with_top ℕ} {s : set E} {t : set F} {g : F → G}
{f : E → F} (x : E)
(hg : times_cont_diff_within_at 𝕜 n g t (f x)) (hf : times_cont_diff_within_at 𝕜 n f s x) :
times_cont_diff_within_at 𝕜 n (g ∘ f) (s ∩ f⁻¹' t) x :=
hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
lemma times_cont_diff_at.comp_times_cont_diff_within_at {n} (x : E)
(hg : times_cont_diff_at 𝕜 n g (f x)) (hf : times_cont_diff_within_at 𝕜 n f s x) :
times_cont_diff_within_at 𝕜 n (g ∘ f) s x :=
hg.comp x hf (maps_to_univ _ _)
/-- The composition of `C^n` functions at points is `C^n`. -/
lemma times_cont_diff_at.comp {n : with_top ℕ} (x : E)
(hg : times_cont_diff_at 𝕜 n g (f x))
(hf : times_cont_diff_at 𝕜 n f x) :
times_cont_diff_at 𝕜 n (g ∘ f) x :=
hg.comp x hf subset_preimage_univ
lemma times_cont_diff.comp_times_cont_diff_within_at
{n : with_top ℕ} {g : F → G} {f : E → F} (h : times_cont_diff 𝕜 n g)
(hf : times_cont_diff_within_at 𝕜 n f t x) :
times_cont_diff_within_at 𝕜 n (g ∘ f) t x :=
begin
have : times_cont_diff_within_at 𝕜 n g univ (f x) :=
h.times_cont_diff_at.times_cont_diff_within_at,
exact this.comp x hf (subset_univ _),
end
lemma times_cont_diff.comp_times_cont_diff_at
{n : with_top ℕ} {g : F → G} {f : E → F} (x : E)
(hg : times_cont_diff 𝕜 n g)
(hf : times_cont_diff_at 𝕜 n f x) :
times_cont_diff_at 𝕜 n (g ∘ f) x :=
hg.comp_times_cont_diff_within_at hf
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
lemma times_cont_diff_on_fderiv_within_apply {m n : with_top ℕ} {s : set E}
{f : E → F} (hf : times_cont_diff_on 𝕜 n f s) (hs : unique_diff_on 𝕜 s) (hmn : m + 1 ≤ n) :
times_cont_diff_on 𝕜 m (λp : E × E, (fderiv_within 𝕜 f s p.1 : E →L[𝕜] F) p.2)
(set.prod s (univ : set E)) :=
begin
have A : times_cont_diff 𝕜 m (λp : (E →L[𝕜] F) × E, p.1 p.2),
{ apply is_bounded_bilinear_map.times_cont_diff,
exact is_bounded_bilinear_map_apply },
have B : times_cont_diff_on 𝕜 m
(λ (p : E × E), ((fderiv_within 𝕜 f s p.fst), p.snd)) (set.prod s univ),
{ apply times_cont_diff_on.prod _ _,
{ have I : times_cont_diff_on 𝕜 m (λ (x : E), fderiv_within 𝕜 f s x) s :=
hf.fderiv_within hs hmn,
have J : times_cont_diff_on 𝕜 m (λ (x : E × E), x.1) (set.prod s univ) :=
times_cont_diff_fst.times_cont_diff_on,
exact times_cont_diff_on.comp I J (prod_subset_preimage_fst _ _) },
{ apply times_cont_diff.times_cont_diff_on _ ,
apply is_bounded_linear_map.snd.times_cont_diff } },
exact A.comp_times_cont_diff_on B
end
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
lemma times_cont_diff.times_cont_diff_fderiv_apply {n m : with_top ℕ} {f : E → F}
(hf : times_cont_diff 𝕜 n f) (hmn : m + 1 ≤ n) :
times_cont_diff 𝕜 m (λp : E × E, (fderiv 𝕜 f p.1 : E →L[𝕜] F) p.2) :=
begin
rw ← times_cont_diff_on_univ at ⊢ hf,
rw [← fderiv_within_univ, ← univ_prod_univ],
exact times_cont_diff_on_fderiv_within_apply hf unique_diff_on_univ hmn
end
/-! ### Sum of two functions -/
/- The sum is smooth. -/
lemma times_cont_diff_add {n : with_top ℕ} :
times_cont_diff 𝕜 n (λp : F × F, p.1 + p.2) :=
(is_bounded_linear_map.fst.add is_bounded_linear_map.snd).times_cont_diff
/-- The sum of two `C^n` functions within a set at a point is `C^n` within this set
at this point. -/
lemma times_cont_diff_within_at.add {n : with_top ℕ} {s : set E} {f g : E → F}
(hf : times_cont_diff_within_at 𝕜 n f s x) (hg : times_cont_diff_within_at 𝕜 n g s x) :
times_cont_diff_within_at 𝕜 n (λx, f x + g x) s x :=
times_cont_diff_add.times_cont_diff_within_at.comp x (hf.prod hg) subset_preimage_univ
/-- The sum of two `C^n` functions at a point is `C^n` at this point. -/
lemma times_cont_diff_at.add {n : with_top ℕ} {f g : E → F}
(hf : times_cont_diff_at 𝕜 n f x) (hg : times_cont_diff_at 𝕜 n g x) :
times_cont_diff_at 𝕜 n (λx, f x + g x) x :=
by rw [← times_cont_diff_within_at_univ] at *; exact hf.add hg
/-- The sum of two `C^n`functions is `C^n`. -/
lemma times_cont_diff.add {n : with_top ℕ} {f g : E → F}
(hf : times_cont_diff 𝕜 n f) (hg : times_cont_diff 𝕜 n g) :
times_cont_diff 𝕜 n (λx, f x + g x) :=
times_cont_diff_add.comp (hf.prod hg)
/-- The sum of two `C^n` functions on a domain is `C^n`. -/
lemma times_cont_diff_on.add {n : with_top ℕ} {s : set E} {f g : E → F}
(hf : times_cont_diff_on 𝕜 n f s) (hg : times_cont_diff_on 𝕜 n g s) :
times_cont_diff_on 𝕜 n (λx, f x + g x) s :=
λ x hx, (hf x hx).add (hg x hx)
/-! ### Negative -/
/- The negative is smooth. -/
lemma times_cont_diff_neg {n : with_top ℕ} :
times_cont_diff 𝕜 n (λp : F, -p) :=
is_bounded_linear_map.id.neg.times_cont_diff
/-- The negative of a `C^n` function within a domain at a point is `C^n` within this domain at
this point. -/
lemma times_cont_diff_within_at.neg {n : with_top ℕ} {s : set E} {f : E → F}
(hf : times_cont_diff_within_at 𝕜 n f s x) : times_cont_diff_within_at 𝕜 n (λx, -f x) s x :=
times_cont_diff_neg.times_cont_diff_within_at.comp x hf subset_preimage_univ
/-- The negative of a `C^n` function at a point is `C^n` at this point. -/
lemma times_cont_diff_at.neg {n : with_top ℕ} {f : E → F}
(hf : times_cont_diff_at 𝕜 n f x) : times_cont_diff_at 𝕜 n (λx, -f x) x :=
by rw ← times_cont_diff_within_at_univ at *; exact hf.neg
/-- The negative of a `C^n`function is `C^n`. -/
lemma times_cont_diff.neg {n : with_top ℕ} {f : E → F} (hf : times_cont_diff 𝕜 n f) :
times_cont_diff 𝕜 n (λx, -f x) :=
times_cont_diff_neg.comp hf
/-- The negative of a `C^n` function on a domain is `C^n`. -/
lemma times_cont_diff_on.neg {n : with_top ℕ} {s : set E} {f : E → F}
(hf : times_cont_diff_on 𝕜 n f s) : times_cont_diff_on 𝕜 n (λx, -f x) s :=
λ x hx, (hf x hx).neg
/-! ### Subtraction -/
/-- The difference of two `C^n` functions within a set at a point is `C^n` within this set
at this point. -/
lemma times_cont_diff_within_at.sub {n : with_top ℕ} {s : set E} {f g : E → F}
(hf : times_cont_diff_within_at 𝕜 n f s x) (hg : times_cont_diff_within_at 𝕜 n g s x) :
times_cont_diff_within_at 𝕜 n (λx, f x - g x) s x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
/-- The difference of two `C^n` functions at a point is `C^n` at this point. -/
lemma times_cont_diff_at.sub {n : with_top ℕ} {f g : E → F}
(hf : times_cont_diff_at 𝕜 n f x) (hg : times_cont_diff_at 𝕜 n g x) :
times_cont_diff_at 𝕜 n (λx, f x - g x) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
/-- The difference of two `C^n` functions on a domain is `C^n`. -/
lemma times_cont_diff_on.sub {n : with_top ℕ} {s : set E} {f g : E → F}
(hf : times_cont_diff_on 𝕜 n f s) (hg : times_cont_diff_on 𝕜 n g s) :
times_cont_diff_on 𝕜 n (λx, f x - g x) s :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
/-- The difference of two `C^n` functions is `C^n`. -/
lemma times_cont_diff.sub {n : with_top ℕ} {f g : E → F}
(hf : times_cont_diff 𝕜 n f) (hg : times_cont_diff 𝕜 n g) : times_cont_diff 𝕜 n (λx, f x - g x) :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
/-! ### Sum of finitely many functions -/
lemma times_cont_diff_within_at.sum
{ι : Type*} {f : ι → E → F} {s : finset ι} {n : with_top ℕ} {t : set E} {x : E}
(h : ∀ i ∈ s, times_cont_diff_within_at 𝕜 n (λ x, f i x) t x) :
times_cont_diff_within_at 𝕜 n (λ x, (∑ i in s, f i x)) t x :=
begin
classical,
induction s using finset.induction_on with i s is IH,
{ simp [times_cont_diff_within_at_const] },
{ simp only [is, finset.sum_insert, not_false_iff],
exact (h _ (finset.mem_insert_self i s)).add (IH (λ j hj, h _ (finset.mem_insert_of_mem hj))) }
end
lemma times_cont_diff_at.sum
{ι : Type*} {f : ι → E → F} {s : finset ι} {n : with_top ℕ} {x : E}
(h : ∀ i ∈ s, times_cont_diff_at 𝕜 n (λ x, f i x) x) :
times_cont_diff_at 𝕜 n (λ x, (∑ i in s, f i x)) x :=
by rw [← times_cont_diff_within_at_univ] at *; exact times_cont_diff_within_at.sum h
lemma times_cont_diff_on.sum
{ι : Type*} {f : ι → E → F} {s : finset ι} {n : with_top ℕ} {t : set E}
(h : ∀ i ∈ s, times_cont_diff_on 𝕜 n (λ x, f i x) t) :
times_cont_diff_on 𝕜 n (λ x, (∑ i in s, f i x)) t :=
λ x hx, times_cont_diff_within_at.sum (λ i hi, h i hi x hx)
lemma times_cont_diff.sum
{ι : Type*} {f : ι → E → F} {s : finset ι} {n : with_top ℕ}
(h : ∀ i ∈ s, times_cont_diff 𝕜 n (λ x, f i x)) :
times_cont_diff 𝕜 n (λ x, (∑ i in s, f i x)) :=
by simp [← times_cont_diff_on_univ] at *; exact times_cont_diff_on.sum h
/-! ### Product of two functions -/
/- The product is smooth. -/
lemma times_cont_diff_mul {n : with_top ℕ} :
times_cont_diff 𝕜 n (λ p : 𝕜 × 𝕜, p.1 * p.2) :=
is_bounded_bilinear_map_mul.times_cont_diff
/-- The product of two `C^n` functions within a set at a point is `C^n` within this set
at this point. -/
lemma times_cont_diff_within_at.mul {n : with_top ℕ} {s : set E} {f g : E → 𝕜}
(hf : times_cont_diff_within_at 𝕜 n f s x) (hg : times_cont_diff_within_at 𝕜 n g s x) :
times_cont_diff_within_at 𝕜 n (λ x, f x * g x) s x :=
times_cont_diff_mul.times_cont_diff_within_at.comp x (hf.prod hg) subset_preimage_univ
/-- The product of two `C^n` functions at a point is `C^n` at this point. -/
lemma times_cont_diff_at.mul {n : with_top ℕ} {f g : E → 𝕜}
(hf : times_cont_diff_at 𝕜 n f x) (hg : times_cont_diff_at 𝕜 n g x) :
times_cont_diff_at 𝕜 n (λ x, f x * g x) x :=
by rw [← times_cont_diff_within_at_univ] at *; exact hf.mul hg
/-- The product of two `C^n` functions on a domain is `C^n`. -/
lemma times_cont_diff_on.mul {n : with_top ℕ} {s : set E} {f g : E → 𝕜}
(hf : times_cont_diff_on 𝕜 n f s) (hg : times_cont_diff_on 𝕜 n g s) :
times_cont_diff_on 𝕜 n (λ x, f x * g x) s :=
λ x hx, (hf x hx).mul (hg x hx)
/-- The product of two `C^n`functions is `C^n`. -/
lemma times_cont_diff.mul {n : with_top ℕ} {f g : E → 𝕜}
(hf : times_cont_diff 𝕜 n f) (hg : times_cont_diff 𝕜 n g) :
times_cont_diff 𝕜 n (λ x, f x * g x) :=
times_cont_diff_mul.comp (hf.prod hg)
lemma times_cont_diff_within_at.div_const {f : E → 𝕜} {n} {c : 𝕜}
(hf : times_cont_diff_within_at 𝕜 n f s x) :
times_cont_diff_within_at 𝕜 n (λ x, f x / c) s x :=
by simpa only [div_eq_mul_inv] using hf.mul times_cont_diff_within_at_const
lemma times_cont_diff_at.div_const {f : E → 𝕜} {n} {c : 𝕜} (hf : times_cont_diff_at 𝕜 n f x) :
times_cont_diff_at 𝕜 n (λ x, f x / c) x :=
by simpa only [div_eq_mul_inv] using hf.mul times_cont_diff_at_const
lemma times_cont_diff_on.div_const {f : E → 𝕜} {n} {c : 𝕜} (hf : times_cont_diff_on 𝕜 n f s) :
times_cont_diff_on 𝕜 n (λ x, f x / c) s :=
by simpa only [div_eq_mul_inv] using hf.mul times_cont_diff_on_const
lemma times_cont_diff.div_const {f : E → 𝕜} {n} {c : 𝕜} (hf : times_cont_diff 𝕜 n f) :
times_cont_diff 𝕜 n (λ x, f x / c) :=
by simpa only [div_eq_mul_inv] using hf.mul times_cont_diff_const
lemma times_cont_diff.pow {n : with_top ℕ} {f : E → 𝕜}
(hf : times_cont_diff 𝕜 n f) :
∀ m : ℕ, times_cont_diff 𝕜 n (λ x, (f x) ^ m)
| 0 := by simpa using times_cont_diff_const
| (m + 1) := by simpa [pow_succ] using hf.mul (times_cont_diff.pow m)
lemma times_cont_diff_at.pow {n : with_top ℕ} {f : E → 𝕜} (hf : times_cont_diff_at 𝕜 n f x)
(m : ℕ) : times_cont_diff_at 𝕜 n (λ y, f y ^ m) x :=
(times_cont_diff_id.pow m).times_cont_diff_at.comp x hf
lemma times_cont_diff_within_at.pow {n : with_top ℕ} {f : E → 𝕜}
(hf : times_cont_diff_within_at 𝕜 n f s x) (m : ℕ) :
times_cont_diff_within_at 𝕜 n (λ y, f y ^ m) s x :=
(times_cont_diff_id.pow m).times_cont_diff_at.comp_times_cont_diff_within_at x hf
lemma times_cont_diff_on.pow {n : with_top ℕ} {f : E → 𝕜}
(hf : times_cont_diff_on 𝕜 n f s) (m : ℕ) :
times_cont_diff_on 𝕜 n (λ y, f y ^ m) s :=
λ y hy, (hf y hy).pow m
/-! ### Scalar multiplication -/
/- The scalar multiplication is smooth. -/
lemma times_cont_diff_smul {n : with_top ℕ} :
times_cont_diff 𝕜 n (λ p : 𝕜 × F, p.1 • p.2) :=
is_bounded_bilinear_map_smul.times_cont_diff
/-- The scalar multiplication of two `C^n` functions within a set at a point is `C^n` within this
set at this point. -/
lemma times_cont_diff_within_at.smul {n : with_top ℕ} {s : set E} {f : E → 𝕜} {g : E → F}
(hf : times_cont_diff_within_at 𝕜 n f s x) (hg : times_cont_diff_within_at 𝕜 n g s x) :
times_cont_diff_within_at 𝕜 n (λ x, f x • g x) s x :=
times_cont_diff_smul.times_cont_diff_within_at.comp x (hf.prod hg) subset_preimage_univ
/-- The scalar multiplication of two `C^n` functions at a point is `C^n` at this point. -/
lemma times_cont_diff_at.smul {n : with_top ℕ} {f : E → 𝕜} {g : E → F}
(hf : times_cont_diff_at 𝕜 n f x) (hg : times_cont_diff_at 𝕜 n g x) :
times_cont_diff_at 𝕜 n (λ x, f x • g x) x :=
by rw [← times_cont_diff_within_at_univ] at *; exact hf.smul hg
/-- The scalar multiplication of two `C^n` functions is `C^n`. -/
lemma times_cont_diff.smul {n : with_top ℕ} {f : E → 𝕜} {g : E → F}
(hf : times_cont_diff 𝕜 n f) (hg : times_cont_diff 𝕜 n g) :
times_cont_diff 𝕜 n (λ x, f x • g x) :=
times_cont_diff_smul.comp (hf.prod hg)
/-- The scalar multiplication of two `C^n` functions on a domain is `C^n`. -/
lemma times_cont_diff_on.smul {n : with_top ℕ} {s : set E} {f : E → 𝕜} {g : E → F}
(hf : times_cont_diff_on 𝕜 n f s) (hg : times_cont_diff_on 𝕜 n g s) :
times_cont_diff_on 𝕜 n (λ x, f x • g x) s :=
λ x hx, (hf x hx).smul (hg x hx)
/-! ### Cartesian product of two functions-/
section prod_map
variables {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{F' : Type*} [normed_group F'] [normed_space 𝕜 F']
{n : with_top ℕ}
/-- The product map of two `C^n` functions within a set at a point is `C^n`
within the product set at the product point. -/
lemma times_cont_diff_within_at.prod_map'
{s : set E} {t : set E'} {f : E → F} {g : E' → F'} {p : E × E'}
(hf : times_cont_diff_within_at 𝕜 n f s p.1) (hg : times_cont_diff_within_at 𝕜 n g t p.2) :
times_cont_diff_within_at 𝕜 n (prod.map f g) (set.prod s t) p :=
(hf.comp p times_cont_diff_within_at_fst (prod_subset_preimage_fst _ _)).prod
(hg.comp p times_cont_diff_within_at_snd (prod_subset_preimage_snd _ _))
lemma times_cont_diff_within_at.prod_map
{s : set E} {t : set E'} {f : E → F} {g : E' → F'} {x : E} {y : E'}
(hf : times_cont_diff_within_at 𝕜 n f s x) (hg : times_cont_diff_within_at 𝕜 n g t y) :
times_cont_diff_within_at 𝕜 n (prod.map f g) (set.prod s t) (x, y) :=
times_cont_diff_within_at.prod_map' hf hg
/-- The product map of two `C^n` functions on a set is `C^n` on the product set. -/
lemma times_cont_diff_on.prod_map {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{F' : Type*} [normed_group F'] [normed_space 𝕜 F']
{s : set E} {t : set E'} {n : with_top ℕ} {f : E → F} {g : E' → F'}
(hf : times_cont_diff_on 𝕜 n f s) (hg : times_cont_diff_on 𝕜 n g t) :
times_cont_diff_on 𝕜 n (prod.map f g) (set.prod s t) :=
(hf.comp times_cont_diff_on_fst (prod_subset_preimage_fst _ _)).prod
(hg.comp (times_cont_diff_on_snd) (prod_subset_preimage_snd _ _))
/-- The product map of two `C^n` functions within a set at a point is `C^n`
within the product set at the product point. -/
lemma times_cont_diff_at.prod_map {f : E → F} {g : E' → F'} {x : E} {y : E'}
(hf : times_cont_diff_at 𝕜 n f x) (hg : times_cont_diff_at 𝕜 n g y) :
times_cont_diff_at 𝕜 n (prod.map f g) (x, y) :=
begin
rw times_cont_diff_at at *,
convert hf.prod_map hg,
simp only [univ_prod_univ]
end
/-- The product map of two `C^n` functions within a set at a point is `C^n`
within the product set at the product point. -/
lemma times_cont_diff_at.prod_map' {f : E → F} {g : E' → F'} {p : E × E'}
(hf : times_cont_diff_at 𝕜 n f p.1) (hg : times_cont_diff_at 𝕜 n g p.2) :
times_cont_diff_at 𝕜 n (prod.map f g) p :=
begin
rcases p,
exact times_cont_diff_at.prod_map hf hg
end
/-- The product map of two `C^n` functions is `C^n`. -/
lemma times_cont_diff.prod_map
{f : E → F} {g : E' → F'}
(hf : times_cont_diff 𝕜 n f) (hg : times_cont_diff 𝕜 n g) :
times_cont_diff 𝕜 n (prod.map f g) :=
begin
rw times_cont_diff_iff_times_cont_diff_at at *,
exact λ ⟨x, y⟩, (hf x).prod_map (hg y)
end
end prod_map
/-! ### Inversion in a complete normed algebra -/
section algebra_inverse
variables (𝕜) {R : Type*} [normed_ring R] [normed_algebra 𝕜 R]
open normed_ring continuous_linear_map ring
/-- In a complete normed algebra, the operation of inversion is `C^n`, for all `n`, at each
invertible element. The proof is by induction, bootstrapping using an identity expressing the
derivative of inversion as a bilinear map of inversion itself. -/
lemma times_cont_diff_at_ring_inverse [complete_space R] {n : with_top ℕ} (x : units R) :
times_cont_diff_at 𝕜 n ring.inverse (x : R) :=
begin
induction n using with_top.nat_induction with n IH Itop,
{ intros m hm,
refine ⟨{y : R | is_unit y}, _, _⟩,
{ simp [nhds_within_univ],
exact x.nhds },
{ use (ftaylor_series_within 𝕜 inverse univ),
rw [le_antisymm hm bot_le, has_ftaylor_series_up_to_on_zero_iff],
split,
{ rintros _ ⟨x', rfl⟩,
exact (inverse_continuous_at x').continuous_within_at },
{ simp [ftaylor_series_within] } } },
{ apply times_cont_diff_at_succ_iff_has_fderiv_at.mpr,
refine ⟨λ (x : R), - lmul_left_right 𝕜 R (inverse x) (inverse x), _, _⟩,
{ refine ⟨{y : R | is_unit y}, x.nhds, _⟩,
rintros _ ⟨y, rfl⟩,
rw [inverse_unit],
exact has_fderiv_at_ring_inverse y },
{ convert (lmul_left_right_is_bounded_bilinear 𝕜 R).times_cont_diff.neg.comp_times_cont_diff_at
(x : R) (IH.prod IH) } },
{ exact times_cont_diff_at_top.mpr Itop }
end
variables (𝕜) {𝕜' : Type*} [normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] [complete_space 𝕜']
lemma times_cont_diff_at_inv {x : 𝕜'} (hx : x ≠ 0) {n} :
times_cont_diff_at 𝕜 n has_inv.inv x :=
by simpa only [inverse_eq_has_inv] using times_cont_diff_at_ring_inverse 𝕜 (units.mk0 x hx)
lemma times_cont_diff_on_inv {n} : times_cont_diff_on 𝕜 n (has_inv.inv : 𝕜' → 𝕜') {0}ᶜ :=
λ x hx, (times_cont_diff_at_inv 𝕜 hx).times_cont_diff_within_at
variable {𝕜}
-- TODO: the next few lemmas don't need `𝕜` or `𝕜'` to be complete
-- A good way to show this is to generalize `times_cont_diff_at_ring_inverse` to the setting
-- of a function `f` such that `∀ᶠ x in 𝓝 a, x * f x = 1`.
lemma times_cont_diff_within_at.inv {f : E → 𝕜'} {n} (hf : times_cont_diff_within_at 𝕜 n f s x)
(hx : f x ≠ 0) :
times_cont_diff_within_at 𝕜 n (λ x, (f x)⁻¹) s x :=
(times_cont_diff_at_inv 𝕜 hx).comp_times_cont_diff_within_at x hf
lemma times_cont_diff_on.inv {f : E → 𝕜'} {n} (hf : times_cont_diff_on 𝕜 n f s)
(h : ∀ x ∈ s, f x ≠ 0) :
times_cont_diff_on 𝕜 n (λ x, (f x)⁻¹) s :=
λ x hx, (hf.times_cont_diff_within_at hx).inv (h x hx)
lemma times_cont_diff_at.inv {f : E → 𝕜'} {n} (hf : times_cont_diff_at 𝕜 n f x) (hx : f x ≠ 0) :
times_cont_diff_at 𝕜 n (λ x, (f x)⁻¹) x :=
hf.inv hx
lemma times_cont_diff.inv {f : E → 𝕜'} {n} (hf : times_cont_diff 𝕜 n f) (h : ∀ x, f x ≠ 0) :
times_cont_diff 𝕜 n (λ x, (f x)⁻¹) :=
by { rw times_cont_diff_iff_times_cont_diff_at, exact λ x, hf.times_cont_diff_at.inv (h x) }
-- TODO: generalize to `f g : E → 𝕜'`
lemma times_cont_diff_within_at.div [complete_space 𝕜] {f g : E → 𝕜} {n}
(hf : times_cont_diff_within_at 𝕜 n f s x) (hg : times_cont_diff_within_at 𝕜 n g s x)
(hx : g x ≠ 0) :
times_cont_diff_within_at 𝕜 n (λ x, f x / g x) s x :=
by simpa only [div_eq_mul_inv] using hf.mul (hg.inv hx)
lemma times_cont_diff_on.div [complete_space 𝕜] {f g : E → 𝕜} {n}
(hf : times_cont_diff_on 𝕜 n f s) (hg : times_cont_diff_on 𝕜 n g s) (h₀ : ∀ x ∈ s, g x ≠ 0) :
times_cont_diff_on 𝕜 n (f / g) s :=
λ x hx, (hf x hx).div (hg x hx) (h₀ x hx)
lemma times_cont_diff_at.div [complete_space 𝕜] {f g : E → 𝕜} {n}
(hf : times_cont_diff_at 𝕜 n f x) (hg : times_cont_diff_at 𝕜 n g x)
(hx : g x ≠ 0) :
times_cont_diff_at 𝕜 n (λ x, f x / g x) x :=
hf.div hg hx
lemma times_cont_diff.div [complete_space 𝕜] {f g : E → 𝕜} {n}
(hf : times_cont_diff 𝕜 n f) (hg : times_cont_diff 𝕜 n g)
(h0 : ∀ x, g x ≠ 0) :
times_cont_diff 𝕜 n (λ x, f x / g x) :=
begin
simp only [times_cont_diff_iff_times_cont_diff_at] at *,
exact λ x, (hf x).div (hg x) (h0 x)
end
end algebra_inverse
/-! ### Inversion of continuous linear maps between Banach spaces -/
section map_inverse
open continuous_linear_map
/-- At a continuous linear equivalence `e : E ≃L[𝕜] F` between Banach spaces, the operation of
inversion is `C^n`, for all `n`. -/
lemma times_cont_diff_at_map_inverse [complete_space E] {n : with_top ℕ} (e : E ≃L[𝕜] F) :
times_cont_diff_at 𝕜 n inverse (e : E →L[𝕜] F) :=
begin
nontriviality E,
-- first, we use the lemma `to_ring_inverse` to rewrite in terms of `ring.inverse` in the ring
-- `E →L[𝕜] E`
let O₁ : (E →L[𝕜] E) → (F →L[𝕜] E) := λ f, f.comp (e.symm : (F →L[𝕜] E)),
let O₂ : (E →L[𝕜] F) → (E →L[𝕜] E) := λ f, (e.symm : (F →L[𝕜] E)).comp f,
have : continuous_linear_map.inverse = O₁ ∘ ring.inverse ∘ O₂ :=
funext (to_ring_inverse e),
rw this,
-- `O₁` and `O₂` are `times_cont_diff`,
-- so we reduce to proving that `ring.inverse` is `times_cont_diff`
have h₁ : times_cont_diff 𝕜 n O₁,
from is_bounded_bilinear_map_comp.times_cont_diff.comp
(times_cont_diff_const.prod times_cont_diff_id),
have h₂ : times_cont_diff 𝕜 n O₂,
from is_bounded_bilinear_map_comp.times_cont_diff.comp
(times_cont_diff_id.prod times_cont_diff_const),
refine h₁.times_cont_diff_at.comp _ (times_cont_diff_at.comp _ _ h₂.times_cont_diff_at),
convert times_cont_diff_at_ring_inverse 𝕜 (1 : units (E →L[𝕜] E)),
simp [O₂, one_def]
end
end map_inverse
section function_inverse
open continuous_linear_map
/-- If `f` is a local homeomorphism and the point `a` is in its target,
and if `f` is `n` times continuously differentiable at `f.symm a`,
and if the derivative at `f.symm a` is a continuous linear equivalence,
then `f.symm` is `n` times continuously differentiable at the point `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem local_homeomorph.times_cont_diff_at_symm [complete_space E] {n : with_top ℕ}
(f : local_homeomorph E F) {f₀' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target)
(hf₀' : has_fderiv_at f (f₀' : E →L[𝕜] F) (f.symm a)) (hf : times_cont_diff_at 𝕜 n f (f.symm a)) :
times_cont_diff_at 𝕜 n f.symm a :=
begin
-- We prove this by induction on `n`
induction n using with_top.nat_induction with n IH Itop,
{ rw times_cont_diff_at_zero,
exact ⟨f.target, is_open.mem_nhds f.open_target ha, f.continuous_inv_fun⟩ },
{ obtain ⟨f', ⟨u, hu, hff'⟩, hf'⟩ := times_cont_diff_at_succ_iff_has_fderiv_at.mp hf,
apply times_cont_diff_at_succ_iff_has_fderiv_at.mpr,
-- For showing `n.succ` times continuous differentiability (the main inductive step), it
-- suffices to produce the derivative and show that it is `n` times continuously differentiable
have eq_f₀' : f' (f.symm a) = f₀',
{ exact (hff' (f.symm a) (mem_of_mem_nhds hu)).unique hf₀' },
-- This follows by a bootstrapping formula expressing the derivative as a function of `f` itself
refine ⟨inverse ∘ f' ∘ f.symm, _, _⟩,
{ -- We first check that the derivative of `f` is that formula
have h_nhds : {y : E | ∃ (e : E ≃L[𝕜] F), ↑e = f' y} ∈ 𝓝 ((f.symm) a),
{ have hf₀' := f₀'.nhds,
rw ← eq_f₀' at hf₀',
exact hf'.continuous_at.preimage_mem_nhds hf₀' },
obtain ⟨t, htu, ht, htf⟩ := mem_nhds_iff.mp (filter.inter_mem_sets hu h_nhds),
use f.target ∩ (f.symm) ⁻¹' t,
refine ⟨is_open.mem_nhds _ _, _⟩,
{ exact f.preimage_open_of_open_symm ht },
{ exact mem_inter ha (mem_preimage.mpr htf) },
intros x hx,
obtain ⟨hxu, e, he⟩ := htu hx.2,
have h_deriv : has_fderiv_at f ↑e ((f.symm) x),
{ rw he,
exact hff' (f.symm x) hxu },
convert f.has_fderiv_at_symm hx.1 h_deriv,
simp [← he] },
{ -- Then we check that the formula, being a composition of `times_cont_diff` pieces, is
-- itself `times_cont_diff`
have h_deriv₁ : times_cont_diff_at 𝕜 n inverse (f' (f.symm a)),
{ rw eq_f₀',
exact times_cont_diff_at_map_inverse _ },
have h_deriv₂ : times_cont_diff_at 𝕜 n f.symm a,
{ refine IH (hf.of_le _),
norm_cast,
exact nat.le_succ n },
exact (h_deriv₁.comp _ hf').comp _ h_deriv₂ } },
{ refine times_cont_diff_at_top.mpr _,
intros n,
exact Itop n (times_cont_diff_at_top.mp hf n) }
end
/-- Let `f` be a local homeomorphism of a nondiscrete normed field, let `a` be a point in its
target. if `f` is `n` times continuously differentiable at `f.symm a`, and if the derivative at
`f.symm a` is nonzero, then `f.symm` is `n` times continuously differentiable at the point `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem local_homeomorph.times_cont_diff_at_symm_deriv [complete_space 𝕜] {n : with_top ℕ}
(f : local_homeomorph 𝕜 𝕜) {f₀' a : 𝕜} (h₀ : f₀' ≠ 0) (ha : a ∈ f.target)
(hf₀' : has_deriv_at f f₀' (f.symm a)) (hf : times_cont_diff_at 𝕜 n f (f.symm a)) :
times_cont_diff_at 𝕜 n f.symm a :=
f.times_cont_diff_at_symm ha (hf₀'.has_fderiv_at_equiv h₀) hf
end function_inverse
section real
/-!
### Results over `ℝ` or `ℂ`
The results in this section rely on the Mean Value Theorem, and therefore hold only over `ℝ` (and
its extension fields such as `ℂ`).
-/
variables
{𝕂 : Type*} [is_R_or_C 𝕂]
{E' : Type*} [normed_group E'] [normed_space 𝕂 E']
{F' : Type*} [normed_group F'] [normed_space 𝕂 F']
/-- If a function has a Taylor series at order at least 1, then at points in the interior of the
domain of definition, the term of order 1 of this series is a strict derivative of `f`. -/
lemma has_ftaylor_series_up_to_on.has_strict_fderiv_at
{s : set E'} {f : E' → F'} {x : E'} {p : E' → formal_multilinear_series 𝕂 E' F'} {n : with_top ℕ}
(hf : has_ftaylor_series_up_to_on n f p s) (hn : 1 ≤ n) (hs : s ∈ 𝓝 x) :
has_strict_fderiv_at f ((continuous_multilinear_curry_fin1 𝕂 E' F') (p x 1)) x :=
has_strict_fderiv_at_of_has_fderiv_at_of_continuous_at (hf.eventually_has_fderiv_at hn hs) $
(continuous_multilinear_curry_fin1 𝕂 E' F').continuous_at.comp $
(hf.cont 1 hn).continuous_at hs
/-- If a function is `C^n` with `1 ≤ n` around a point, and its derivative at that point is given to
us as `f'`, then `f'` is also a strict derivative. -/
lemma times_cont_diff_at.has_strict_fderiv_at'
{f : E' → F'} {f' : E' →L[𝕂] F'} {x : E'}
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f x) (hf' : has_fderiv_at f f' x) (hn : 1 ≤ n) :
has_strict_fderiv_at f f' x :=
begin
rcases hf 1 hn with ⟨u, H, p, hp⟩,
simp only [nhds_within_univ, mem_univ, insert_eq_of_mem] at H,
have := hp.has_strict_fderiv_at le_rfl H,
rwa hf'.unique this.has_fderiv_at
end
/-- If a function is `C^n` with `1 ≤ n` around a point, and its derivative at that point is given to
us as `f'`, then `f'` is also a strict derivative. -/
lemma times_cont_diff_at.has_strict_deriv_at' {f : 𝕂 → F'} {f' : F'} {x : 𝕂}
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f x) (hf' : has_deriv_at f f' x) (hn : 1 ≤ n) :
has_strict_deriv_at f f' x :=
hf.has_strict_fderiv_at' hf' hn
/-- If a function is `C^n` with `1 ≤ n` around a point, then the derivative of `f` at this point
is also a strict derivative. -/
lemma times_cont_diff_at.has_strict_fderiv_at {f : E' → F'} {x : E'} {n : with_top ℕ}
(hf : times_cont_diff_at 𝕂 n f x) (hn : 1 ≤ n) :
has_strict_fderiv_at f (fderiv 𝕂 f x) x :=
hf.has_strict_fderiv_at' (hf.differentiable_at hn).has_fderiv_at hn
/-- If a function is `C^n` with `1 ≤ n` around a point, then the derivative of `f` at this point
is also a strict derivative. -/
lemma times_cont_diff_at.has_strict_deriv_at {f : 𝕂 → F'} {x : 𝕂} {n : with_top ℕ}
(hf : times_cont_diff_at 𝕂 n f x) (hn : 1 ≤ n) :
has_strict_deriv_at f (deriv f x) x :=
(hf.has_strict_fderiv_at hn).has_strict_deriv_at
/-- If a function is `C^n` with `1 ≤ n`, then the derivative of `f` is also a strict derivative. -/
lemma times_cont_diff.has_strict_fderiv_at
{f : E' → F'} {x : E'} {n : with_top ℕ} (hf : times_cont_diff 𝕂 n f) (hn : 1 ≤ n) :
has_strict_fderiv_at f (fderiv 𝕂 f x) x :=
hf.times_cont_diff_at.has_strict_fderiv_at hn
/-- If a function is `C^n` with `1 ≤ n`, then the derivative of `f` is also a strict derivative. -/
lemma times_cont_diff.has_strict_deriv_at
{f : 𝕂 → F'} {x : 𝕂} {n : with_top ℕ} (hf : times_cont_diff 𝕂 n f) (hn : 1 ≤ n) :
has_strict_deriv_at f (deriv f x) x :=
hf.times_cont_diff_at.has_strict_deriv_at hn
end real
section deriv
/-!
### One dimension
All results up to now have been expressed in terms of the general Fréchet derivative `fderiv`. For
maps defined on the field, the one-dimensional derivative `deriv` is often easier to use. In this
paragraph, we reformulate some higher smoothness results in terms of `deriv`.
-/
variables {f₂ : 𝕜 → F} {s₂ : set 𝕜}
open continuous_linear_map (smul_right)
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (formulated with `deriv_within`) is `C^n`. -/
theorem times_cont_diff_on_succ_iff_deriv_within {n : ℕ} (hs : unique_diff_on 𝕜 s₂) :
times_cont_diff_on 𝕜 ((n + 1) : ℕ) f₂ s₂ ↔
differentiable_on 𝕜 f₂ s₂ ∧ times_cont_diff_on 𝕜 n (deriv_within f₂ s₂) s₂ :=
begin
rw times_cont_diff_on_succ_iff_fderiv_within hs,
congr' 2,
apply le_antisymm,
{ assume h,
have : deriv_within f₂ s₂ = (λ u : 𝕜 →L[𝕜] F, u 1) ∘ (fderiv_within 𝕜 f₂ s₂),
by { ext x, refl },
simp only [this],
apply times_cont_diff.comp_times_cont_diff_on _ h,
exact (is_bounded_bilinear_map_apply.is_bounded_linear_map_left _).times_cont_diff },
{ assume h,
have : fderiv_within 𝕜 f₂ s₂ = smul_right (1 : 𝕜 →L[𝕜] 𝕜) ∘ deriv_within f₂ s₂,
by { ext x, simp [deriv_within] },
simp only [this],
apply times_cont_diff.comp_times_cont_diff_on _ h,
exact (is_bounded_bilinear_map_smul_right.is_bounded_linear_map_right _).times_cont_diff }
end
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (formulated with `deriv`) is `C^n`. -/
theorem times_cont_diff_on_succ_iff_deriv_of_open {n : ℕ} (hs : is_open s₂) :
times_cont_diff_on 𝕜 ((n + 1) : ℕ) f₂ s₂ ↔
differentiable_on 𝕜 f₂ s₂ ∧ times_cont_diff_on 𝕜 n (deriv f₂) s₂ :=
begin
rw times_cont_diff_on_succ_iff_deriv_within hs.unique_diff_on,
congr' 2,
rw ← iff_iff_eq,
apply times_cont_diff_on_congr,
assume x hx,
exact deriv_within_of_open hs hx
end
/-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable
there, and its derivative (formulated with `deriv_within`) is `C^∞`. -/
theorem times_cont_diff_on_top_iff_deriv_within (hs : unique_diff_on 𝕜 s₂) :
times_cont_diff_on 𝕜 ∞ f₂ s₂ ↔
differentiable_on 𝕜 f₂ s₂ ∧ times_cont_diff_on 𝕜 ∞ (deriv_within f₂ s₂) s₂ :=
begin
split,
{ assume h,
refine ⟨h.differentiable_on le_top, _⟩,
apply times_cont_diff_on_top.2 (λ n, ((times_cont_diff_on_succ_iff_deriv_within hs).1 _).2),
exact h.of_le le_top },
{ assume h,
refine times_cont_diff_on_top.2 (λ n, _),
have A : (n : with_top ℕ) ≤ ∞ := le_top,
apply ((times_cont_diff_on_succ_iff_deriv_within hs).2 ⟨h.1, h.2.of_le A⟩).of_le,
exact with_top.coe_le_coe.2 (nat.le_succ n) }
end
/-- A function is `C^∞` on an open domain if and only if it is differentiable
there, and its derivative (formulated with `deriv`) is `C^∞`. -/
theorem times_cont_diff_on_top_iff_deriv_of_open (hs : is_open s₂) :
times_cont_diff_on 𝕜 ∞ f₂ s₂ ↔
differentiable_on 𝕜 f₂ s₂ ∧ times_cont_diff_on 𝕜 ∞ (deriv f₂) s₂ :=
begin
rw times_cont_diff_on_top_iff_deriv_within hs.unique_diff_on,
congr' 2,
rw ← iff_iff_eq,
apply times_cont_diff_on_congr,
assume x hx,
exact deriv_within_of_open hs hx
end
lemma times_cont_diff_on.deriv_within {m n : with_top ℕ}
(hf : times_cont_diff_on 𝕜 n f₂ s₂) (hs : unique_diff_on 𝕜 s₂) (hmn : m + 1 ≤ n) :
times_cont_diff_on 𝕜 m (deriv_within f₂ s₂) s₂ :=
begin
cases m,
{ change ∞ + 1 ≤ n at hmn,
have : n = ∞, by simpa using hmn,
rw this at hf,
exact ((times_cont_diff_on_top_iff_deriv_within hs).1 hf).2 },
{ change (m.succ : with_top ℕ) ≤ n at hmn,
exact ((times_cont_diff_on_succ_iff_deriv_within hs).1 (hf.of_le hmn)).2 }
end
lemma times_cont_diff_on.deriv_of_open {m n : with_top ℕ}
(hf : times_cont_diff_on 𝕜 n f₂ s₂) (hs : is_open s₂) (hmn : m + 1 ≤ n) :
times_cont_diff_on 𝕜 m (deriv f₂) s₂ :=
(hf.deriv_within hs.unique_diff_on hmn).congr (λ x hx, (deriv_within_of_open hs hx).symm)
lemma times_cont_diff_on.continuous_on_deriv_within {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f₂ s₂) (hs : unique_diff_on 𝕜 s₂) (hn : 1 ≤ n) :
continuous_on (deriv_within f₂ s₂) s₂ :=
((times_cont_diff_on_succ_iff_deriv_within hs).1 (h.of_le hn)).2.continuous_on
lemma times_cont_diff_on.continuous_on_deriv_of_open {n : with_top ℕ}
(h : times_cont_diff_on 𝕜 n f₂ s₂) (hs : is_open s₂) (hn : 1 ≤ n) :
continuous_on (deriv f₂) s₂ :=
((times_cont_diff_on_succ_iff_deriv_of_open hs).1 (h.of_le hn)).2.continuous_on
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative is `C^n`. -/
theorem times_cont_diff_succ_iff_deriv {n : ℕ} :
times_cont_diff 𝕜 ((n + 1) : ℕ) f₂ ↔
differentiable 𝕜 f₂ ∧ times_cont_diff 𝕜 n (deriv f₂) :=
by simp only [← times_cont_diff_on_univ, times_cont_diff_on_succ_iff_deriv_of_open, is_open_univ,
differentiable_on_univ]
end deriv
section restrict_scalars
/-!
### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜`
If a function is `n` times continuously differentiable over `ℂ`, then it is `n` times continuously
differentiable over `ℝ`. In this paragraph, we give variants of this statement, in the general
situation where `ℂ` and `ℝ` are replaced respectively by `𝕜'` and `𝕜` where `𝕜'` is a normed algebra
over `𝕜`.
-/
variables (𝕜) {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
variables [normed_space 𝕜' E] [is_scalar_tower 𝕜 𝕜' E]
variables [normed_space 𝕜' F] [is_scalar_tower 𝕜 𝕜' F]
variables {p' : E → formal_multilinear_series 𝕜' E F} {n : with_top ℕ}
lemma has_ftaylor_series_up_to_on.restrict_scalars
(h : has_ftaylor_series_up_to_on n f p' s) :
has_ftaylor_series_up_to_on n f (λ x, (p' x).restrict_scalars 𝕜) s :=
{ zero_eq := λ x hx, h.zero_eq x hx,
fderiv_within :=
begin
intros m hm x hx,
convert ((continuous_multilinear_map.restrict_scalars_linear 𝕜).has_fderiv_at)
.comp_has_fderiv_within_at _ ((h.fderiv_within m hm x hx).restrict_scalars 𝕜),
end,
cont := λ m hm, continuous_multilinear_map.continuous_restrict_scalars.comp_continuous_on
(h.cont m hm) }
lemma times_cont_diff_within_at.restrict_scalars (h : times_cont_diff_within_at 𝕜' n f s x) :
times_cont_diff_within_at 𝕜 n f s x :=
begin
intros m hm,
rcases h m hm with ⟨u, u_mem, p', hp'⟩,
exact ⟨u, u_mem, _, hp'.restrict_scalars _⟩
end
lemma times_cont_diff_on.restrict_scalars (h : times_cont_diff_on 𝕜' n f s) :
times_cont_diff_on 𝕜 n f s :=
λ x hx, (h x hx).restrict_scalars _
lemma times_cont_diff_at.restrict_scalars (h : times_cont_diff_at 𝕜' n f x) :
times_cont_diff_at 𝕜 n f x :=
times_cont_diff_within_at_univ.1 $ h.times_cont_diff_within_at.restrict_scalars _
lemma times_cont_diff.restrict_scalars (h : times_cont_diff 𝕜' n f) :
times_cont_diff 𝕜 n f :=
times_cont_diff_iff_times_cont_diff_at.2 $ λ x, h.times_cont_diff_at.restrict_scalars _
end restrict_scalars
|
2b7d84d381340bf4e57a41435de98e9181d1ab0c | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /05_Interacting_with_Lean.org.13.lean | 422548d5a4c3cd9c4aac33e2256250ddeb65b1e6 | [] | no_license | cjmazey/lean-tutorial | ba559a49f82aa6c5848b9bf17b7389bf7f4ba645 | 381f61c9fcac56d01d959ae0fa6e376f2c4e3b34 | refs/heads/master | 1,610,286,098,832 | 1,447,124,923,000 | 1,447,124,923,000 | 43,082,433 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 170 | lean | /- page 72 -/
import standard
import data.nat
open nat
-- BEGIN
local notation `[` a `**` b `]` := a * b + 1
local infix `<*>`:50 := λ a b : ℕ, a * a * b * b
-- END
|
68d1bf0671c8b7ef8f3bfda30276042789057fd5 | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /tests/lean/run/blast_ematch9.lean | 450e2671ba95748bb32dbb94ca88d441285e8f4f | [
"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 | 188 | lean | constant P : nat → Prop
definition h [reducible] (n : nat) := n
definition foo [forward] : ∀ x, P (h x) := sorry
set_option blast.ematch true
example (n : nat) : P (h n) :=
by blast
|
08e8df20968c714d8366420bae988313214a7d7b | b147e1312077cdcfea8e6756207b3fa538982e12 | /algebra/big_operators.lean | e77268f2cffe0cbed916c90c1fab7d2234d1e964 | [
"Apache-2.0"
] | permissive | SzJS/mathlib | 07836ee708ca27cd18347e1e11ce7dd5afb3e926 | 23a5591fca0d43ee5d49d89f6f0ee07a24a6ca29 | refs/heads/master | 1,584,980,332,064 | 1,532,063,841,000 | 1,532,063,841,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,688 | 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
Some big operators for lists and finite sets.
-/
import data.list.basic data.list.perm data.finset
algebra.group algebra.ordered_group algebra.group_power
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
/-- `prod s f` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/
@[to_additive finset.sum]
protected def prod [comm_monoid β] (s : finset α) (f : α → β) : β := (s.1.map f).prod
attribute [to_additive finset.sum.equations._eqn_1] finset.prod.equations._eqn_1
@[to_additive finset.sum_eq_fold]
theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) : s.prod f = s.fold (*) 1 f := rfl
section comm_monoid
variables [comm_monoid β]
@[simp, to_additive finset.sum_empty]
lemma prod_empty {α : Type u} {f : α → β} : (∅:finset α).prod f = 1 := rfl
@[simp, to_additive finset.sum_insert]
lemma prod_insert [decidable_eq α] : a ∉ s → (insert a s).prod f = f a * s.prod f := fold_insert
@[simp, to_additive finset.sum_singleton]
lemma prod_singleton : (singleton a).prod f = f a :=
eq.trans fold_singleton (by simp)
@[simp] lemma prod_const_one : s.prod (λx, (1 : β)) = 1 :=
by simp [finset.prod]
@[simp] lemma sum_const_zero {β} {s : finset α} [add_comm_monoid β] : s.sum (λx, (0 : β)) = 0 :=
@prod_const_one _ (multiplicative β) _ _
attribute [to_additive finset.sum_const_zero] prod_const_one
@[simp, to_additive finset.sum_image]
lemma prod_image [decidable_eq α] [decidable_eq γ] {s : finset γ} {g : γ → α} :
(∀x∈s, ∀y∈s, g x = g y → x = y) → (s.image g).prod f = s.prod (λx, f (g x)) :=
fold_image
@[congr, to_additive finset.sum_congr]
lemma prod_congr (h : s₁ = s₂) : (∀x∈s₂, f x = g x) → s₁.prod f = s₂.prod g :=
by rw [h]; exact fold_congr
attribute [congr] finset.sum_congr
@[to_additive finset.sum_union_inter]
lemma prod_union_inter [decidable_eq α] : (s₁ ∪ s₂).prod f * (s₁ ∩ s₂).prod f = s₁.prod f * s₂.prod f :=
fold_union_inter
@[to_additive finset.sum_union]
lemma prod_union [decidable_eq α] (h : s₁ ∩ s₂ = ∅) : (s₁ ∪ s₂).prod f = s₁.prod f * s₂.prod f :=
by rw [←prod_union_inter, h]; simp
@[to_additive finset.sum_sdiff]
lemma prod_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) : (s₂ \ s₁).prod f * s₁.prod f = s₂.prod f :=
by rw [←prod_union (sdiff_inter_self _ _), sdiff_union_of_subset h]
@[to_additive finset.sum_bind]
lemma prod_bind [decidable_eq α] {s : finset γ} {t : γ → finset α} :
(∀x∈s, ∀y∈s, x ≠ y → t x ∩ t y = ∅) → (s.bind t).prod f = s.prod (λx, (t x).prod f) :=
by haveI := classical.dec_eq γ; exact
finset.induction_on s (by simp)
(assume x s hxs ih hd,
have hd' : ∀x∈s, ∀y∈s, x ≠ y → t x ∩ t y = ∅,
from assume _ hx _ hy, hd _ (mem_insert_of_mem hx) _ (mem_insert_of_mem hy),
have t x ∩ finset.bind s t = ∅,
from ext.2 $ assume a,
by simp [mem_bind];
from assume h₁ y hys hy₂,
have ha : a ∈ t x ∩ t y, by simp [*],
have t x ∩ t y = ∅,
from hd _ (mem_insert_self _ _) _ (mem_insert_of_mem hys) $ assume h, hxs $ h.symm ▸ hys,
by rwa [this] at ha,
by simp [hxs, prod_union this, ih hd'] {contextual := tt})
@[to_additive finset.sum_product]
lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
(s.product t).prod f = s.prod (λx, t.prod $ λy, f (x, y)) :=
begin
haveI := classical.dec_eq α, haveI := classical.dec_eq γ,
rw [product_eq_bind, prod_bind (λ x hx y hy h, ext.2 _)], {simp [prod_image]},
simp [mem_image], intros, intro, refine h _, cc
end
@[to_additive finset.sum_sigma]
lemma prod_sigma {σ : α → Type*}
{s : finset α} {t : Πa, finset (σ a)} {f : sigma σ → β} :
(s.sigma t).prod f = s.prod (λa, (t a).prod $ λs, f ⟨a, s⟩) :=
by haveI := classical.dec_eq α; haveI := (λ a, classical.dec_eq (σ a)); exact
have ∀a₁ a₂:α, ∀s₁ : finset (σ a₁), ∀s₂ : finset (σ a₂), a₁ ≠ a₂ →
s₁.image (sigma.mk a₁) ∩ s₂.image (sigma.mk a₂) = ∅,
from assume b₁ b₂ s₁ s₂ h, ext.2 $ assume ⟨b₃, c₃⟩,
by simp [mem_image, sigma.mk.inj_iff, heq_iff_eq] {contextual := tt}; cc,
calc (s.sigma t).prod f =
(s.bind (λa, (t a).image (λs, sigma.mk a s))).prod f : by rw sigma_eq_bind
... = s.prod (λa, ((t a).image (λs, sigma.mk a s)).prod f) :
prod_bind $ assume a₁ ha a₂ ha₂ h, this a₁ a₂ (t a₁) (t a₂) h
... = (s.prod $ λa, (t a).prod $ λs, f ⟨a, s⟩) :
by simp [prod_image, sigma.mk.inj_iff, heq_iff_eq]
@[to_additive finset.sum_add_distrib]
lemma prod_mul_distrib : s.prod (λx, f x * g x) = s.prod f * s.prod g :=
eq.trans (by simp; refl) fold_op_distrib
@[to_additive finset.sum_comm]
lemma prod_comm [decidable_eq γ] {s : finset γ} {t : finset α} {f : γ → α → β} :
s.prod (λx, t.prod $ f x) = t.prod (λy, s.prod $ λx, f x y) :=
finset.induction_on s (by simp) (by simp [prod_mul_distrib] {contextual := tt})
@[to_additive finset.sum_hom]
lemma prod_hom [comm_monoid γ] (g : β → γ)
(h₁ : g 1 = 1) (h₂ : ∀x y, g (x * y) = g x * g y) : s.prod (λx, g (f x)) = g (s.prod f) :=
eq.trans (by rw [h₁]; refl) (fold_hom h₂)
lemma sum_nat_cast [add_comm_monoid β] [has_one β] (s : finset α) (f : α → ℕ) :
↑(s.sum f) = s.sum (λa, f a : α → β) :=
(sum_hom _ nat.cast_zero nat.cast_add).symm
@[to_additive finset.sum_subset]
lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → f x = 1) : s₁.prod f = s₂.prod f :=
by haveI := classical.dec_eq α; exact
have (s₂ \ s₁).prod f = (s₂ \ s₁).prod (λx, 1),
from prod_congr rfl begin simp [hf] {contextual := tt} end,
by rw [←prod_sdiff h]; simp [this]
@[to_additive sum_attach]
lemma prod_attach {f : α → β} : s.attach.prod (λx, f x.val) = s.prod f :=
by haveI := classical.dec_eq α; exact
calc s.attach.prod (λx, f x.val) = ((s.attach).image subtype.val).prod f :
by rw [prod_image]; exact assume x _ y _, subtype.eq
... = _ : by rw [attach_image_val]
@[to_additive finset.sum_bij]
lemma prod_bij {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Πa∈s, γ) (hi : ∀a ha, i a ha ∈ t) (h : ∀a ha, f a = g (i a ha))
(i_inj : ∀a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀b∈t, ∃a ha, b = i a ha) :
s.prod f = t.prod g :=
by haveI := classical.prop_decidable; exact
calc s.prod f = s.attach.prod (λx, f x.val) : prod_attach.symm
... = s.attach.prod (λx, g (i x.1 x.2)) : prod_congr rfl $ assume x hx, h _ _
... = (s.attach.image $ λx:{x // x ∈ s}, i x.1 x.2).prod g :
(prod_image $ assume (a₁:{x // x ∈ s}) _ a₂ _ eq, subtype.eq $ i_inj a₁.1 a₂.1 a₁.2 a₂.2 eq).symm
... = _ :
prod_subset
(by simp [subset_iff]; intros b a h eq; subst eq; exact hi _ _)
(assume b hb, not_imp_comm.mp $ assume hb₂,
let ⟨a, ha, eq⟩ := i_surj b hb in by simp [eq]; exact ⟨_, _, rfl⟩)
@[to_additive finset.sum_bij_ne_zero]
lemma prod_bij_ne_one {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Πa∈s, f a ≠ 1 → γ) (hi₁ : ∀a h₁ h₂, i a h₁ h₂ ∈ t)
(hi₂ : ∀a₁ a₂ h₁₁ h₁₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(hi₃ : ∀b∈t, g b ≠ 1 → ∃a h₁ h₂, b = i a h₁ h₂)
(h : ∀a h₁ h₂, f a = g (i a h₁ h₂)) :
s.prod f = t.prod g :=
by haveI := classical.prop_decidable; exact
calc s.prod f = (s.filter $ λx, f x ≠ 1).prod f :
(prod_subset (filter_subset _) $ by simp {contextual:=tt}).symm
... = (t.filter $ λx, g x ≠ 1).prod g :
prod_bij (assume a ha, i a (mem_filter.mp ha).1 (mem_filter.mp ha).2)
(assume a ha, (mem_filter.mp ha).elim $ λh₁ h₂, mem_filter.mpr
⟨hi₁ a h₁ h₂, λ hg, h₂ (hg ▸ h a h₁ h₂)⟩)
(assume a ha, (mem_filter.mp ha).elim $ h a)
(assume a₁ a₂ ha₁ ha₂,
(mem_filter.mp ha₁).elim $ λha₁₁ ha₁₂, (mem_filter.mp ha₂).elim $ λha₂₁ ha₂₂, hi₂ a₁ a₂ _ _ _ _)
(assume b hb, (mem_filter.mp hb).elim $ λh₁ h₂,
let ⟨a, ha₁, ha₂, eq⟩ := hi₃ b h₁ h₂ in ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩)
... = t.prod g :
(prod_subset (filter_subset _) $ by simp {contextual:=tt})
@[to_additive finset.exists_ne_zero_of_sum_ne_zero]
lemma exists_ne_one_of_prod_ne_one : s.prod f ≠ 1 → ∃a∈s, f a ≠ 1 :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (assume a s has ih h,
classical.by_cases
(assume ha : f a = 1,
have s.prod f ≠ 1, by simpa [ha, has] using h,
let ⟨a, ha, hfa⟩ := ih this in
⟨a, mem_insert_of_mem ha, hfa⟩)
(assume hna : f a ≠ 1,
⟨a, mem_insert_self _ _, hna⟩))
@[simp] lemma prod_const [decidable_eq α] (b : β) : s.prod (λ a, b) = b ^ s.card :=
finset.induction_on s rfl (by simp [pow_add, mul_comm] {contextual := tt})
end comm_monoid
@[simp] lemma sum_const [add_comm_monoid β] [decidable_eq α] (b : β) :
s.sum (λ a, b) = add_monoid.smul s.card b :=
@prod_const _ (multiplicative β) _ _ _ _
attribute [to_additive finset.sum_const] prod_const
section comm_group
variables [comm_group β]
@[simp, to_additive finset.sum_neg_distrib]
lemma prod_inv_distrib : s.prod (λx, (f x)⁻¹) = (s.prod f)⁻¹ :=
prod_hom has_inv.inv one_inv mul_inv
end comm_group
@[simp] theorem card_sigma {σ : α → Type*} (s : finset α) (t : Π a, finset (σ a)) :
card (s.sigma t) = s.sum (λ a, card (t a)) :=
multiset.card_sigma _ _
end finset
namespace finset
variables {s s₁ s₂ : finset α} {f g : α → β} {b : β} {a : α}
@[simp] lemma sum_sub_distrib [add_comm_group β] : s.sum (λx, f x - g x) = s.sum f - s.sum g :=
by simp [sum_add_distrib]
section ordered_cancel_comm_monoid
variables [decidable_eq α] [ordered_cancel_comm_monoid β]
lemma sum_le_sum : (∀x∈s, f x ≤ g x) → s.sum f ≤ s.sum g :=
finset.induction_on s (by simp) $ assume a s ha ih h,
have f a + s.sum f ≤ g a + s.sum g,
from add_le_add (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simp [*]
lemma zero_le_sum (h : ∀x∈s, 0 ≤ f x) : 0 ≤ s.sum f := le_trans (by simp) (sum_le_sum h)
lemma sum_le_zero (h : ∀x∈s, f x ≤ 0) : s.sum f ≤ 0 := le_trans (sum_le_sum h) (by simp)
end ordered_cancel_comm_monoid
section semiring
variables [semiring β]
lemma sum_mul : s.sum f * b = s.sum (λx, f x * b) :=
(sum_hom (λx, x * b) (zero_mul b) (assume a c, add_mul a c b)).symm
lemma mul_sum : b * s.sum f = s.sum (λx, b * f x) :=
(sum_hom (λx, b * x) (mul_zero b) (assume a c, mul_add b a c)).symm
end semiring
section comm_semiring
variables [decidable_eq α] [comm_semiring β]
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : s.prod f = 0 :=
calc s.prod f = (insert a (erase s a)).prod f : by simp [ha, insert_erase]
... = 0 : by simp [h]
lemma prod_sum {δ : α → Type*} [∀a, decidable_eq (δ a)]
{s : finset α} {t : Πa, finset (δ a)} {f : Πa, δ a → β} :
s.prod (λa, (t a).sum (λb, f a b)) =
(s.pi t).sum (λp, s.attach.prod (λx, f x.1 (p x.1 x.2))) :=
begin
induction s using finset.induction with a s ha ih,
{ simp },
{ have h₁ : ∀x ∈ t a, ∀y∈t a, ∀h : x ≠ y,
image (pi.cons s a x) (pi s t) ∩ image (pi.cons s a y) (pi s t) = ∅,
{ assume x hx y hy h,
apply eq_empty_of_forall_not_mem,
simp,
assume p₁ p₂ hp eq p₃ hp₃ eq', subst eq',
have : pi.cons s a x p₂ a (mem_insert_self _ _) = pi.cons s a y p₃ a (mem_insert_self _ _),
{ rw [eq] },
rw [pi.cons_same, pi.cons_same] at this,
exact h this },
have h₂ : ∀b:δ a, ∀p₁∈pi s t, ∀p₂∈pi s t, pi.cons s a b p₁ = pi.cons s a b p₂ → p₁ = p₂, from
assume b p₁ h₁ p₂ h₂ eq, injective_pi_cons ha eq,
have h₃ : ∀(v:{x // x ∈ s}) (b:δ a) (h : v.1 ∈ insert a s) (p : Πa, a ∈ s → δ a),
pi.cons s a b p v.1 h = p v.1 v.2, from
assume v b h p, pi.cons_ne $ assume eq, ha $ eq.symm ▸ v.2,
simp [ha, ih, sum_bind h₁, sum_image (h₂ _), sum_mul, h₃],
simp [mul_sum] }
end
end comm_semiring
section integral_domain /- add integral_semi_domain to support nat and ennreal -/
variables [decidable_eq α] [integral_domain β]
lemma prod_eq_zero_iff : s.prod f = 0 ↔ (∃a∈s, f a = 0) :=
finset.induction_on s (by simp)
begin
intros a s,
rw [bex_def, bex_def, exists_mem_insert],
simp [mul_eq_zero_iff_eq_zero_or_eq_zero] {contextual := tt}
end
end integral_domain
section ordered_comm_monoid
variables [decidable_eq α] [ordered_comm_monoid β]
lemma sum_le_sum' : (∀x∈s, f x ≤ g x) → s.sum f ≤ s.sum g :=
finset.induction_on s (by simp; refl) $ assume a s ha ih h,
have f a + s.sum f ≤ g a + s.sum g,
from add_le_add' (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simp [*]
lemma zero_le_sum' (h : ∀x∈s, 0 ≤ f x) : 0 ≤ s.sum f := le_trans (by simp) (sum_le_sum' h)
lemma sum_le_zero' (h : ∀x∈s, f x ≤ 0) : s.sum f ≤ 0 := le_trans (sum_le_sum' h) (by simp)
lemma sum_le_sum_of_subset_of_nonneg
(h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → 0 ≤ f x) : s₁.sum f ≤ s₂.sum f :=
calc s₁.sum f ≤ (s₂ \ s₁).sum f + s₁.sum f :
le_add_of_nonneg_left' $ zero_le_sum' $ by simp [hf] {contextual := tt}
... = (s₂ \ s₁ ∪ s₁).sum f : (sum_union (sdiff_inter_self _ _)).symm
... = s₂.sum f : by rw [sdiff_union_of_subset h]
lemma sum_eq_zero_iff_of_nonneg : (∀x∈s, 0 ≤ f x) → (s.sum f = 0 ↔ ∀x∈s, f x = 0) :=
finset.induction_on s (by simp) $
by simp [or_imp_distrib, forall_and_distrib, zero_le_sum' ,
add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg'] {contextual := tt}
lemma single_le_sum (hf : ∀x∈s, 0 ≤ f x) {a} (h : a ∈ s) : f a ≤ s.sum f :=
by simpa using show (singleton a).sum f ≤ s.sum f,
from sum_le_sum_of_subset_of_nonneg
(λ x e, (mem_singleton.1 e).symm ▸ h) (λ x h _, hf x h)
end ordered_comm_monoid
section canonically_ordered_monoid
variables [decidable_eq α] [canonically_ordered_monoid β] [@decidable_rel β (≤)]
lemma sum_le_sum_of_subset (h : s₁ ⊆ s₂) : s₁.sum f ≤ s₂.sum f :=
sum_le_sum_of_subset_of_nonneg h $ assume x h₁ h₂, zero_le _
lemma sum_le_sum_of_ne_zero (h : ∀x∈s₁, f x ≠ 0 → x ∈ s₂) : s₁.sum f ≤ s₂.sum f :=
calc s₁.sum f = (s₁.filter (λx, f x = 0)).sum f + (s₁.filter (λx, f x ≠ 0)).sum f :
by rw [←sum_union, filter_union_filter_neg_eq]; apply filter_inter_filter_neg_eq
... ≤ s₂.sum f : add_le_of_nonpos_of_le'
(sum_le_zero' $ by simp {contextual:=tt})
(sum_le_sum_of_subset $ by simp [subset_iff, *] {contextual:=tt})
end canonically_ordered_monoid
section discrete_linear_ordered_field
variables [discrete_linear_ordered_field α] [decidable_eq β]
lemma abs_sum_le_sum_abs {f : β → α} {s : finset β} : abs (s.sum f) ≤ s.sum (λa, abs (f a)) :=
finset.induction_on s (by simp [abs_zero]) $
assume a s has ih,
calc abs (sum (insert a s) f) ≤ abs (f a) + abs (sum s f) :
by simp [has]; exact abs_add_le_abs_add_abs _ _
... ≤ abs (f a) + s.sum (λa, abs (f a)) : add_le_add (le_refl _) ih
... ≤ sum (insert a s) (λ (a : β), abs (f a)) : by simp [has]
end discrete_linear_ordered_field
@[simp] lemma card_pi [decidable_eq α] {δ : α → Type*}
(s : finset α) (t : Π a, finset (δ a)) :
(s.pi t).card = s.prod (λ a, card (t a)) :=
multiset.card_pi _ _
end finset
section group
open list
variables [group α] [group β]
theorem is_group_hom.prod {f : α → β} [is_group_hom f] (l : list α) :
f (prod l) = prod (map f l) :=
by induction l; simp [*, is_group_hom.mul f, is_group_hom.one f]
theorem is_group_anti_hom.prod {f : α → β} [is_group_anti_hom f] (l : list α) :
f (prod l) = prod (map f (reverse l)) :=
by induction l; simp [*, is_group_anti_hom.mul f, is_group_anti_hom.one f]
theorem inv_prod : ∀ l : list α, (prod l)⁻¹ = prod (map (λ x, x⁻¹) (reverse l)) :=
λ l, @is_group_anti_hom.prod _ _ _ _ _ inv_is_group_anti_hom l -- TODO there is probably a cleaner proof of this
end group
namespace multiset
variables [decidable_eq α]
@[simp] lemma to_finset_sum_count_eq (s : multiset α) :
s.to_finset.sum (λa, s.count a) = s.card :=
multiset.induction_on s (by simp)
(assume a s ih,
calc (to_finset (a :: s)).sum (λx, count x (a :: s)) =
(to_finset (a :: s)).sum (λx, (if x = a then 1 else 0) + count x s) :
by congr; funext x; split_ifs; simp [h, nat.one_add]
... = card (a :: s) :
begin
by_cases a ∈ s.to_finset,
{ have : (to_finset s).sum (λx, ite (x = a) 1 0) = ({a}:finset α).sum (λx, ite (x = a) 1 0),
{ apply (finset.sum_subset _ _).symm,
{ simp [finset.subset_iff, *] at * },
{ simp [if_neg] {contextual := tt} } },
simp [h, ih, this, finset.sum_add_distrib] },
{ have : a ∉ s, by simp * at *,
have : (to_finset s).sum (λx, ite (x = a) 1 0) = (to_finset s).sum (λx, 0), from
finset.sum_congr rfl begin assume a ha, split_ifs; simp [*] at * end,
simp [*, finset.sum_add_distrib], }
end)
end multiset |
92c65741d5e9de55303321f440ef7854815e6465 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/algebra/linear_ordered_comm_group_with_zero.lean | 16010c8c4a2c045f659574b4d5027d4b382eb1b4 | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,627 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Johan Commelin, Patrick Massot
-/
import algebra.ordered_group
import algebra.group_with_zero
import algebra.group_with_zero.power
import tactic.abel
/-!
# Linearly ordered commutative groups and monoids with a zero element adjoined
This file sets up a special class of linearly ordered commutative monoids
that show up as the target of so-called “valuations” in algebraic number theory.
Usually, in the informal literature, these objects are constructed
by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}.
The disadvantage is that a type such as `nnreal` is not of that form,
whereas it is a very common target for valuations.
The solutions is to use a typeclass, and that is exactly what we do in this file.
Note that to avoid issues with import cycles, `linear_ordered_comm_monoid_with_zero` is defined
in another file. However, the lemmas about it are stated here.
-/
set_option old_structure_cmd true
/-- A linearly ordered commutative group with a zero element. -/
class linear_ordered_comm_group_with_zero (α : Type*)
extends linear_ordered_comm_monoid_with_zero α, comm_group_with_zero α
variables {α : Type*}
variables {a b c d x y z : α}
section linear_ordered_comm_monoid
variables [linear_ordered_comm_monoid_with_zero α]
/-
The following facts are true more generally in a (linearly) ordered commutative monoid.
-/
lemma one_le_pow_of_one_le' {n : ℕ} (H : 1 ≤ x) : 1 ≤ x^n :=
begin
induction n with n ih,
{ exact le_refl 1 },
{ exact one_le_mul H ih }
end
lemma pow_le_one_of_le_one {n : ℕ} (H : x ≤ 1) : x^n ≤ 1 :=
begin
induction n with n ih,
{ exact le_refl 1 },
{ exact mul_le_one' H ih }
end
lemma eq_one_of_pow_eq_one {n : ℕ} (hn : n ≠ 0) (H : x ^ n = 1) : x = 1 :=
begin
rcases nat.exists_eq_succ_of_ne_zero hn with ⟨n, rfl⟩, clear hn,
induction n with n ih,
{ simpa using H },
{ cases le_total x 1 with h,
all_goals
{ have h1 := mul_le_mul_right' h (x ^ (n + 1)),
rw pow_succ at H,
rw [H, one_mul] at h1 },
{ have h2 := pow_le_one_of_le_one h,
exact ih (le_antisymm h2 h1) },
{ have h2 := one_le_pow_of_one_le' h,
exact ih (le_antisymm h1 h2) } }
end
lemma pow_eq_one_iff {n : ℕ} (hn : n ≠ 0) : x ^ n = 1 ↔ x = 1 :=
⟨eq_one_of_pow_eq_one hn, by { rintro rfl, exact one_pow _ }⟩
lemma one_le_pow_iff {n : ℕ} (hn : n ≠ 0) : 1 ≤ x^n ↔ 1 ≤ x :=
begin
refine ⟨_, one_le_pow_of_one_le'⟩,
contrapose!,
intro h, apply lt_of_le_of_ne (pow_le_one_of_le_one (le_of_lt h)),
rw [ne.def, pow_eq_one_iff hn],
exact ne_of_lt h,
end
lemma pow_le_one_iff {n : ℕ} (hn : n ≠ 0) : x^n ≤ 1 ↔ x ≤ 1 :=
begin
refine ⟨_, pow_le_one_of_le_one⟩,
contrapose!,
intro h, apply lt_of_le_of_ne (one_le_pow_of_one_le' (le_of_lt h)),
rw [ne.def, eq_comm, pow_eq_one_iff hn],
exact ne_of_gt h,
end
lemma zero_le_one' : (0 : α) ≤ 1 :=
linear_ordered_comm_monoid_with_zero.zero_le_one
@[simp] lemma zero_le' : 0 ≤ a :=
by simpa only [mul_zero, mul_one] using mul_le_mul_left' (@zero_le_one' α _) a
@[simp] lemma not_lt_zero' : ¬a < 0 :=
not_lt_of_le zero_le'
@[simp] lemma le_zero_iff : a ≤ 0 ↔ a = 0 :=
⟨λ h, le_antisymm h zero_le', λ h, h ▸ le_refl _⟩
lemma zero_lt_iff : 0 < a ↔ a ≠ 0 :=
⟨ne_of_gt, λ h, lt_of_le_of_ne zero_le' h.symm⟩
lemma ne_zero_of_lt (h : b < a) : a ≠ 0 :=
λ h1, not_lt_zero' $ show b < 0, from h1 ▸ h
end linear_ordered_comm_monoid
variables [linear_ordered_comm_group_with_zero α]
lemma zero_lt_one'' : (0 : α) < 1 :=
lt_of_le_of_ne zero_le_one' zero_ne_one
lemma le_of_le_mul_right (h : c ≠ 0) (hab : a * c ≤ b * c) : a ≤ b :=
by simpa only [mul_inv_cancel_right' h] using (mul_le_mul_right' hab c⁻¹)
lemma le_mul_inv_of_mul_le (h : c ≠ 0) (hab : a * c ≤ b) : a ≤ b * c⁻¹ :=
le_of_le_mul_right h (by simpa [h] using hab)
lemma mul_inv_le_of_le_mul (h : c ≠ 0) (hab : a ≤ b * c) : a * c⁻¹ ≤ b :=
le_of_le_mul_right h (by simpa [h] using hab)
lemma div_le_div' (a b c d : α) (hb : b ≠ 0) (hd : d ≠ 0) :
a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b :=
begin
by_cases ha : a = 0, { simp [ha] },
by_cases hc : c = 0, { simp [inv_ne_zero hb, hc, hd], },
exact @div_le_div_iff' _ _ (units.mk0 a ha) (units.mk0 b hb) (units.mk0 c hc) (units.mk0 d hd)
end
@[simp] lemma units.zero_lt (u : units α) : (0 : α) < u :=
zero_lt_iff.2 $ u.ne_zero
lemma mul_lt_mul'''' (hab : a < b) (hcd : c < d) : a * c < b * d :=
have hb : b ≠ 0 := ne_zero_of_lt hab,
have hd : d ≠ 0 := ne_zero_of_lt hcd,
if ha : a = 0 then by { rw [ha, zero_mul, zero_lt_iff], exact mul_ne_zero hb hd } else
if hc : c = 0 then by { rw [hc, mul_zero, zero_lt_iff], exact mul_ne_zero hb hd } else
@mul_lt_mul''' _ _ (units.mk0 a ha) (units.mk0 b hb) (units.mk0 c hc) (units.mk0 d hd) hab hcd
lemma mul_inv_lt_of_lt_mul' (h : x < y * z) : x * z⁻¹ < y :=
have hz : z ≠ 0 := (mul_ne_zero_iff.1 $ ne_zero_of_lt h).2,
by { contrapose! h, simpa only [inv_inv'] using mul_inv_le_of_le_mul (inv_ne_zero hz) h }
lemma mul_lt_right' (c : α) (h : a < b) (hc : c ≠ 0) : a * c < b * c :=
by { contrapose! h, exact le_of_le_mul_right hc h }
lemma pow_lt_pow_succ {x : α} {n : ℕ} (hx : 1 < x) : x ^ n < x ^ n.succ :=
by { rw ← one_mul (x ^ n),
exact mul_lt_right' _ hx (pow_ne_zero _ $ ne_of_gt (lt_trans zero_lt_one'' hx)) }
lemma pow_lt_pow' {x : α} {m n : ℕ} (hx : 1 < x) (hmn : m < n) : x ^ m < x ^ n :=
by { induction hmn with n hmn ih, exacts [pow_lt_pow_succ hx, lt_trans ih (pow_lt_pow_succ hx)] }
lemma inv_lt_inv'' (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ < b⁻¹ ↔ b < a :=
@inv_lt_inv_iff _ _ (units.mk0 a ha) (units.mk0 b hb)
lemma inv_le_inv'' (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
@inv_le_inv_iff _ _ (units.mk0 a ha) (units.mk0 b hb)
namespace monoid_hom
variables {R : Type*} [ring R] (f : R →* α)
theorem map_neg_one : f (-1) = 1 :=
begin
apply eq_one_of_pow_eq_one (nat.succ_ne_zero 1) (_ : _ ^ 2 = _),
rw [pow_two, ← f.map_mul, neg_one_mul, neg_neg, f.map_one],
end
@[simp] lemma map_neg (x : R) : f (-x) = f x :=
calc f (-x) = f (-1 * x) : by rw [neg_one_mul]
... = f (-1) * f x : map_mul _ _ _
... = f x : by rw [f.map_neg_one, one_mul]
lemma map_sub_swap (x y : R) : f (x - y) = f (y - x) :=
calc f (x - y) = f (-(y - x)) : by rw show x - y = -(y-x), by abel
... = _ : map_neg _ _
end monoid_hom
|
4eea7532239c2ddad6622e188464bb83b185481d | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/field_theory/normal.lean | 5d5cf7d27bd8418217829e329346f5d3ec3809b5 | [
"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 | 18,170 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Thomas Browning, Patrick Lutz
-/
import field_theory.adjoin
import field_theory.tower
import group_theory.solvable
import ring_theory.power_basis
/-!
# Normal field extensions
In this file we define normal field extensions and prove that for a finite extension, being normal
is the same as being a splitting field (`normal.of_is_splitting_field` and
`normal.exists_is_splitting_field`).
## Main Definitions
- `normal F K` where `K` is a field extension of `F`.
-/
noncomputable theory
open_locale big_operators
open_locale classical polynomial
open polynomial is_scalar_tower
variables (F K : Type*) [field F] [field K] [algebra F K]
/-- Typeclass for normal field extension: `K` is a normal extension of `F` iff the minimal
polynomial of every element `x` in `K` splits in `K`, i.e. every conjugate of `x` is in `K`. -/
class normal : Prop :=
(is_algebraic' : algebra.is_algebraic F K)
(splits' (x : K) : splits (algebra_map F K) (minpoly F x))
variables {F K}
theorem normal.is_algebraic (h : normal F K) (x : K) : is_algebraic F x := normal.is_algebraic' x
theorem normal.is_integral (h : normal F K) (x : K) : is_integral F x :=
is_algebraic_iff_is_integral.mp (h.is_algebraic x)
theorem normal.splits (h : normal F K) (x : K) :
splits (algebra_map F K) (minpoly F x) := normal.splits' x
theorem normal_iff : normal F K ↔
∀ x : K, is_integral F x ∧ splits (algebra_map F K) (minpoly F x) :=
⟨λ h x, ⟨h.is_integral x, h.splits x⟩, λ h, ⟨λ x, (h x).1.is_algebraic F, λ x, (h x).2⟩⟩
theorem normal.out : normal F K →
∀ x : K, is_integral F x ∧ splits (algebra_map F K) (minpoly F x) := normal_iff.1
variables (F K)
instance normal_self : normal F F :=
⟨λ x, is_integral_algebra_map.is_algebraic F, λ x, (minpoly.eq_X_sub_C' x).symm ▸ splits_X_sub_C _⟩
variables {K}
variables (K)
theorem normal.exists_is_splitting_field [h : normal F K] [finite_dimensional F K] :
∃ p : F[X], is_splitting_field F K p :=
begin
let s := basis.of_vector_space F K,
refine ⟨∏ x, minpoly F (s x),
splits_prod _ $ λ x hx, h.splits (s x),
subalgebra.to_submodule_injective _⟩,
rw [algebra.top_to_submodule, eq_top_iff, ← s.span_eq, submodule.span_le, set.range_subset_iff],
refine λ x, algebra.subset_adjoin (multiset.mem_to_finset.mpr $
(mem_roots $ mt (map_eq_zero $ algebra_map F K).1 $
finset.prod_ne_zero_iff.2 $ λ x hx, _).2 _),
{ exact minpoly.ne_zero (h.is_integral (s x)) },
rw [is_root.def, eval_map, ← aeval_def, alg_hom.map_prod],
exact finset.prod_eq_zero (finset.mem_univ _) (minpoly.aeval _ _)
end
section normal_tower
variables (E : Type*) [field E] [algebra F E] [algebra K E] [is_scalar_tower F K E]
lemma normal.tower_top_of_normal [h : normal F E] : normal K E :=
normal_iff.2 $ λ x, begin
cases h.out x with hx hhx,
rw algebra_map_eq F K E at hhx,
exact ⟨is_integral_of_is_scalar_tower x hx, polynomial.splits_of_splits_of_dvd (algebra_map K E)
(polynomial.map_ne_zero (minpoly.ne_zero hx))
((polynomial.splits_map_iff (algebra_map F K) (algebra_map K E)).mpr hhx)
(minpoly.dvd_map_of_is_scalar_tower F K x)⟩,
end
lemma alg_hom.normal_bijective [h : normal F E] (ϕ : E →ₐ[F] K) : function.bijective ϕ :=
⟨ϕ.to_ring_hom.injective, λ x, by
{ letI : algebra E K := ϕ.to_ring_hom.to_algebra,
obtain ⟨h1, h2⟩ := h.out (algebra_map K E x),
cases minpoly.mem_range_of_degree_eq_one E x (or.resolve_left h2 (minpoly.ne_zero h1)
(minpoly.irreducible (is_integral_of_is_scalar_tower x
((is_integral_algebra_map_iff (algebra_map K E).injective).mp h1)))
(minpoly.dvd E x ((algebra_map K E).injective (by
{ rw [ring_hom.map_zero, aeval_map, ←is_scalar_tower.to_alg_hom_apply F K E,
←alg_hom.comp_apply, ←aeval_alg_hom],
exact minpoly.aeval F (algebra_map K E x) })))) with y hy,
exact ⟨y, hy⟩ }⟩
variables {F} {E} {E' : Type*} [field E'] [algebra F E']
lemma normal.of_alg_equiv [h : normal F E] (f : E ≃ₐ[F] E') : normal F E' :=
normal_iff.2 $ λ x, begin
cases h.out (f.symm x) with hx hhx,
have H := is_integral_alg_hom f.to_alg_hom hx,
rw [alg_equiv.to_alg_hom_eq_coe, alg_equiv.coe_alg_hom, alg_equiv.apply_symm_apply] at H,
use H,
apply polynomial.splits_of_splits_of_dvd (algebra_map F E') (minpoly.ne_zero hx),
{ rw ← alg_hom.comp_algebra_map f.to_alg_hom,
exact polynomial.splits_comp_of_splits (algebra_map F E) f.to_alg_hom.to_ring_hom hhx },
{ apply minpoly.dvd _ _,
rw ← add_equiv.map_eq_zero_iff f.symm.to_add_equiv,
exact eq.trans (polynomial.aeval_alg_hom_apply f.symm.to_alg_hom x
(minpoly F (f.symm x))).symm (minpoly.aeval _ _) },
end
lemma alg_equiv.transfer_normal (f : E ≃ₐ[F] E') : normal F E ↔ normal F E' :=
⟨λ h, by exactI normal.of_alg_equiv f, λ h, by exactI normal.of_alg_equiv f.symm⟩
lemma normal.of_is_splitting_field (p : F[X]) [hFEp : is_splitting_field F E p] :
normal F E :=
begin
by_cases hp : p = 0,
{ haveI : is_splitting_field F F p, { rw hp, exact ⟨splits_zero _, subsingleton.elim _ _⟩ },
exactI (alg_equiv.transfer_normal ((is_splitting_field.alg_equiv F p).trans
(is_splitting_field.alg_equiv E p).symm)).mp (normal_self F) },
refine normal_iff.2 (λ x, _),
haveI hFE : finite_dimensional F E := is_splitting_field.finite_dimensional E p,
have Hx : is_integral F x := is_integral_of_noetherian (is_noetherian.iff_fg.2 hFE) x,
refine ⟨Hx, or.inr _⟩,
rintros q q_irred ⟨r, hr⟩,
let D := adjoin_root q,
haveI := fact.mk q_irred,
let pbED := adjoin_root.power_basis q_irred.ne_zero,
haveI : finite_dimensional E D := power_basis.finite_dimensional pbED,
have finrankED : finite_dimensional.finrank E D = q.nat_degree := power_basis.finrank pbED,
letI : algebra F D := ring_hom.to_algebra ((algebra_map E D).comp (algebra_map F E)),
haveI : is_scalar_tower F E D := of_algebra_map_eq (λ _, rfl),
haveI : finite_dimensional F D := finite_dimensional.trans F E D,
suffices : nonempty (D →ₐ[F] E),
{ cases this with ϕ,
rw [←with_bot.coe_one, degree_eq_iff_nat_degree_eq q_irred.ne_zero, ←finrankED],
have nat_lemma : ∀ a b c : ℕ, a * b = c → c ≤ a → 0 < c → b = 1,
{ intros a b c h1 h2 h3, nlinarith },
exact nat_lemma _ _ _ (finite_dimensional.finrank_mul_finrank F E D)
(linear_map.finrank_le_finrank_of_injective (show function.injective ϕ.to_linear_map,
from ϕ.to_ring_hom.injective)) finite_dimensional.finrank_pos, },
let C := adjoin_root (minpoly F x),
haveI Hx_irred := fact.mk (minpoly.irreducible Hx),
letI : algebra C D := ring_hom.to_algebra (adjoin_root.lift
(algebra_map F D) (adjoin_root.root q) (by rw [algebra_map_eq F E D, ←eval₂_map, hr,
adjoin_root.algebra_map_eq, eval₂_mul, adjoin_root.eval₂_root, zero_mul])),
letI : algebra C E := ring_hom.to_algebra (adjoin_root.lift
(algebra_map F E) x (minpoly.aeval F x)),
haveI : is_scalar_tower F C D := of_algebra_map_eq (λ x, (adjoin_root.lift_of _).symm),
haveI : is_scalar_tower F C E := of_algebra_map_eq (λ x, (adjoin_root.lift_of _).symm),
suffices : nonempty (D →ₐ[C] E),
{ exact nonempty.map (alg_hom.restrict_scalars F) this },
let S : set D := ((p.map (algebra_map F E)).roots.map (algebra_map E D)).to_finset,
suffices : ⊤ ≤ intermediate_field.adjoin C S,
{ refine intermediate_field.alg_hom_mk_adjoin_splits' (top_le_iff.mp this) (λ y hy, _),
rcases multiset.mem_map.mp (multiset.mem_to_finset.mp hy) with ⟨z, hz1, hz2⟩,
have Hz : is_integral F z := is_integral_of_noetherian (is_noetherian.iff_fg.2 hFE) z,
use (show is_integral C y, from is_integral_of_noetherian
(is_noetherian.iff_fg.2 (finite_dimensional.right F C D)) y),
apply splits_of_splits_of_dvd (algebra_map C E) (map_ne_zero (minpoly.ne_zero Hz)),
{ rw [splits_map_iff, ←algebra_map_eq F C E],
exact splits_of_splits_of_dvd _ hp hFEp.splits (minpoly.dvd F z
(eq.trans (eval₂_eq_eval_map _) ((mem_roots (map_ne_zero hp)).mp hz1))) },
{ apply minpoly.dvd,
rw [←hz2, aeval_def, eval₂_map, ←algebra_map_eq F C D, algebra_map_eq F E D, ←hom_eval₂,
←aeval_def, minpoly.aeval F z, ring_hom.map_zero] } },
rw [←intermediate_field.to_subalgebra_le_to_subalgebra, intermediate_field.top_to_subalgebra],
apply ge_trans (intermediate_field.algebra_adjoin_le_adjoin C S),
suffices : (algebra.adjoin C S).restrict_scalars F
= (algebra.adjoin E {adjoin_root.root q}).restrict_scalars F,
{ rw [adjoin_root.adjoin_root_eq_top, subalgebra.restrict_scalars_top,
←@subalgebra.restrict_scalars_top F C] at this,
exact top_le_iff.mpr (subalgebra.restrict_scalars_injective F this) },
dsimp only [S],
rw [←finset.image_to_finset, finset.coe_image],
apply eq.trans (algebra.adjoin_res_eq_adjoin_res F E C D
hFEp.adjoin_roots adjoin_root.adjoin_root_eq_top),
rw [set.image_singleton, ring_hom.algebra_map_to_algebra, adjoin_root.lift_root]
end
instance (p : F[X]) : normal F p.splitting_field := normal.of_is_splitting_field p
end normal_tower
namespace intermediate_field
/-- A compositum of normal extensions is normal -/
instance normal_supr {ι : Type*} (t : ι → intermediate_field F K) [h : ∀ i, normal F (t i)] :
normal F (⨆ i, t i : intermediate_field F K) :=
begin
refine ⟨is_algebraic_supr (λ i, (h i).1), λ x, _⟩,
obtain ⟨s, hx⟩ := exists_finset_of_mem_supr'' (λ i, (h i).1) x.2,
let E : intermediate_field F K := ⨆ i ∈ s, adjoin F ((minpoly F (i.2 : _)).root_set K),
have hF : normal F E,
{ apply normal.of_is_splitting_field (∏ i in s, minpoly F i.2),
refine is_splitting_field_supr _ (λ i hi, adjoin_root_set_is_splitting_field _),
{ exact finset.prod_ne_zero_iff.mpr (λ i hi, minpoly.ne_zero ((h i.1).is_integral i.2)) },
{ exact polynomial.splits_comp_of_splits _ (algebra_map (t i.1) K) ((h i.1).splits i.2) } },
have hE : E ≤ ⨆ i, t i,
{ refine supr_le (λ i, supr_le (λ hi, le_supr_of_le i.1 _)),
rw [adjoin_le_iff, ←image_root_set ((h i.1).splits i.2) (t i.1).val],
exact λ _ ⟨a, _, h⟩, h ▸ a.2 },
have := hF.splits ⟨x, hx⟩,
rw [minpoly_eq, subtype.coe_mk, ←minpoly_eq] at this,
exact polynomial.splits_comp_of_splits _ (inclusion hE).to_ring_hom this,
end
end intermediate_field
variables {F} {K} {K₁ K₂ K₃:Type*} [field K₁] [field K₂] [field K₃]
[algebra F K₁] [algebra F K₂] [algebra F K₃]
(ϕ : K₁ →ₐ[F] K₂) (χ : K₁ ≃ₐ[F] K₂) (ψ : K₂ →ₐ[F] K₃) (ω : K₂ ≃ₐ[F] K₃)
section restrict
variables (E : Type*) [field E] [algebra F E] [algebra E K₁] [algebra E K₂] [algebra E K₃]
[is_scalar_tower F E K₁] [is_scalar_tower F E K₂] [is_scalar_tower F E K₃]
/-- Restrict algebra homomorphism to image of normal subfield -/
def alg_hom.restrict_normal_aux [h : normal F E] :
(to_alg_hom F E K₁).range →ₐ[F] (to_alg_hom F E K₂).range :=
{ to_fun := λ x, ⟨ϕ x, by
{ suffices : (to_alg_hom F E K₁).range.map ϕ ≤ _,
{ exact this ⟨x, subtype.mem x, rfl⟩ },
rintros x ⟨y, ⟨z, hy⟩, hx⟩,
rw [←hx, ←hy],
apply minpoly.mem_range_of_degree_eq_one E,
exact or.resolve_left (h.splits z) (minpoly.ne_zero (h.is_integral z))
(minpoly.irreducible $ is_integral_of_is_scalar_tower _ $
is_integral_alg_hom ϕ $ is_integral_alg_hom _ $ h.is_integral z)
(minpoly.dvd E _ $ by rw [aeval_map, aeval_alg_hom, aeval_alg_hom, alg_hom.comp_apply,
alg_hom.comp_apply, minpoly.aeval, alg_hom.map_zero, alg_hom.map_zero]) }⟩,
map_zero' := subtype.ext ϕ.map_zero,
map_one' := subtype.ext ϕ.map_one,
map_add' := λ x y, subtype.ext (ϕ.map_add x y),
map_mul' := λ x y, subtype.ext (ϕ.map_mul x y),
commutes' := λ x, subtype.ext (ϕ.commutes x) }
/-- Restrict algebra homomorphism to normal subfield -/
def alg_hom.restrict_normal [normal F E] : E →ₐ[F] E :=
((alg_equiv.of_injective_field (is_scalar_tower.to_alg_hom F E K₂)).symm.to_alg_hom.comp
(ϕ.restrict_normal_aux E)).comp
(alg_equiv.of_injective_field (is_scalar_tower.to_alg_hom F E K₁)).to_alg_hom
/-- Restrict algebra homomorphism to normal subfield (`alg_equiv` version) -/
def alg_hom.restrict_normal' [normal F E] : E ≃ₐ[F] E :=
alg_equiv.of_bijective (alg_hom.restrict_normal ϕ E) (alg_hom.normal_bijective F E E _)
@[simp] lemma alg_hom.restrict_normal_commutes [normal F E] (x : E) :
algebra_map E K₂ (ϕ.restrict_normal E x) = ϕ (algebra_map E K₁ x) :=
subtype.ext_iff.mp (alg_equiv.apply_symm_apply (alg_equiv.of_injective_field
(is_scalar_tower.to_alg_hom F E K₂)) (ϕ.restrict_normal_aux E
⟨is_scalar_tower.to_alg_hom F E K₁ x, x, rfl⟩))
lemma alg_hom.restrict_normal_comp [normal F E] :
(ψ.restrict_normal E).comp (ϕ.restrict_normal E) = (ψ.comp ϕ).restrict_normal E :=
alg_hom.ext (λ _, (algebra_map E K₃).injective
(by simp only [alg_hom.comp_apply, alg_hom.restrict_normal_commutes]))
/-- Restrict algebra isomorphism to a normal subfield -/
def alg_equiv.restrict_normal [h : normal F E] : E ≃ₐ[F] E :=
alg_hom.restrict_normal' χ.to_alg_hom E
@[simp] lemma alg_equiv.restrict_normal_commutes [normal F E] (x : E) :
algebra_map E K₂ (χ.restrict_normal E x) = χ (algebra_map E K₁ x) :=
χ.to_alg_hom.restrict_normal_commutes E x
lemma alg_equiv.restrict_normal_trans [normal F E] :
(χ.trans ω).restrict_normal E = (χ.restrict_normal E).trans (ω.restrict_normal E) :=
alg_equiv.ext (λ _, (algebra_map E K₃).injective
(by simp only [alg_equiv.trans_apply, alg_equiv.restrict_normal_commutes]))
/-- Restriction to an normal subfield as a group homomorphism -/
def alg_equiv.restrict_normal_hom [normal F E] : (K₁ ≃ₐ[F] K₁) →* (E ≃ₐ[F] E) :=
monoid_hom.mk' (λ χ, χ.restrict_normal E) (λ ω χ, (χ.restrict_normal_trans ω E))
variables (F K₁ E)
/-- If `K₁/E/F` is a tower of fields with `E/F` normal then `normal.alg_hom_equiv_aut` is an
equivalence. -/
@[simps] def normal.alg_hom_equiv_aut [normal F E] : (E →ₐ[F] K₁) ≃ (E ≃ₐ[F] E) :=
{ to_fun := λ σ, alg_hom.restrict_normal' σ E,
inv_fun := λ σ, (is_scalar_tower.to_alg_hom F E K₁).comp σ.to_alg_hom,
left_inv := λ σ, begin
ext,
simp[alg_hom.restrict_normal'],
end,
right_inv := λ σ, begin
ext,
simp only [alg_hom.restrict_normal', alg_equiv.to_alg_hom_eq_coe, alg_equiv.coe_of_bijective],
apply no_zero_smul_divisors.algebra_map_injective E K₁,
rw alg_hom.restrict_normal_commutes,
simp,
end }
end restrict
section lift
variables {F} {K₁ K₂} (E : Type*) [field E] [algebra F E] [algebra K₁ E] [algebra K₂ E]
[is_scalar_tower F K₁ E] [is_scalar_tower F K₂ E]
/-- If `E/Kᵢ/F` are towers of fields with `E/F` normal then we can lift
an algebra homomorphism `ϕ : K₁ →ₐ[F] K₂` to `ϕ.lift_normal E : E →ₐ[F] E`. -/
noncomputable def alg_hom.lift_normal [h : normal F E] : E →ₐ[F] E :=
@alg_hom.restrict_scalars F K₁ E E _ _ _ _ _ _
((is_scalar_tower.to_alg_hom F K₂ E).comp ϕ).to_ring_hom.to_algebra _ _ _ _ $ nonempty.some $
@intermediate_field.alg_hom_mk_adjoin_splits' _ _ _ _ _ _ _
((is_scalar_tower.to_alg_hom F K₂ E).comp ϕ).to_ring_hom.to_algebra _
(intermediate_field.adjoin_univ _ _)
(λ x hx, ⟨is_integral_of_is_scalar_tower x (h.out x).1,
splits_of_splits_of_dvd _ (map_ne_zero (minpoly.ne_zero (h.out x).1))
(by { rw [splits_map_iff, ←is_scalar_tower.algebra_map_eq], exact (h.out x).2 })
(minpoly.dvd_map_of_is_scalar_tower F K₁ x)⟩)
@[simp] lemma alg_hom.lift_normal_commutes [normal F E] (x : K₁) :
ϕ.lift_normal E (algebra_map K₁ E x) = algebra_map K₂ E (ϕ x) :=
by apply @alg_hom.commutes K₁ E E _ _ _ _
@[simp] lemma alg_hom.restrict_lift_normal (ϕ : K₁ →ₐ[F] K₁) [normal F K₁] [normal F E] :
(ϕ.lift_normal E).restrict_normal K₁ = ϕ :=
alg_hom.ext (λ x, (algebra_map K₁ E).injective
(eq.trans (alg_hom.restrict_normal_commutes _ K₁ x) (ϕ.lift_normal_commutes E x)))
/-- If `E/Kᵢ/F` are towers of fields with `E/F` normal then we can lift
an algebra isomorphism `ϕ : K₁ ≃ₐ[F] K₂` to `ϕ.lift_normal E : E ≃ₐ[F] E`. -/
noncomputable def alg_equiv.lift_normal [normal F E] : E ≃ₐ[F] E :=
alg_equiv.of_bijective (χ.to_alg_hom.lift_normal E) (alg_hom.normal_bijective F E E _)
@[simp] lemma alg_equiv.lift_normal_commutes [normal F E] (x : K₁) :
χ.lift_normal E (algebra_map K₁ E x) = algebra_map K₂ E (χ x) :=
χ.to_alg_hom.lift_normal_commutes E x
@[simp] lemma alg_equiv.restrict_lift_normal (χ : K₁ ≃ₐ[F] K₁) [normal F K₁] [normal F E] :
(χ.lift_normal E).restrict_normal K₁ = χ :=
alg_equiv.ext (λ x, (algebra_map K₁ E).injective
(eq.trans (alg_equiv.restrict_normal_commutes _ K₁ x) (χ.lift_normal_commutes E x)))
lemma alg_equiv.restrict_normal_hom_surjective [normal F K₁] [normal F E] :
function.surjective (alg_equiv.restrict_normal_hom K₁ : (E ≃ₐ[F] E) → (K₁ ≃ₐ[F] K₁)) :=
λ χ, ⟨χ.lift_normal E, χ.restrict_lift_normal E⟩
variables (F) (K₁) (E)
lemma is_solvable_of_is_scalar_tower [normal F K₁] [h1 : is_solvable (K₁ ≃ₐ[F] K₁)]
[h2 : is_solvable (E ≃ₐ[K₁] E)] : is_solvable (E ≃ₐ[F] E) :=
begin
let f : (E ≃ₐ[K₁] E) →* (E ≃ₐ[F] E) :=
{ to_fun := λ ϕ, alg_equiv.of_alg_hom (ϕ.to_alg_hom.restrict_scalars F)
(ϕ.symm.to_alg_hom.restrict_scalars F)
(alg_hom.ext (λ x, ϕ.apply_symm_apply x))
(alg_hom.ext (λ x, ϕ.symm_apply_apply x)),
map_one' := alg_equiv.ext (λ _, rfl),
map_mul' := λ _ _, alg_equiv.ext (λ _, rfl) },
refine solvable_of_ker_le_range f (alg_equiv.restrict_normal_hom K₁)
(λ ϕ hϕ, ⟨{commutes' := λ x, _, .. ϕ}, alg_equiv.ext (λ _, rfl)⟩),
exact (eq.trans (ϕ.restrict_normal_commutes K₁ x).symm (congr_arg _ (alg_equiv.ext_iff.mp hϕ x))),
end
end lift
|
2b1bd63d93e84abd3a14f0a80e80ad8bdbba68c4 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/group_with_zero/divisibility.lean | 91c4a445326749c29b099951eb74204f488aa3e4 | [
"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 | 2,946 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland, Aaron Anderson
-/
import algebra.group_with_zero.basic
import algebra.divisibility.units
/-!
# Divisibility in groups with zero.
Lemmas about divisibility in groups and monoids with zero.
-/
variables {α : Type*}
section semigroup_with_zero
variables [semigroup_with_zero α] {a : α}
theorem eq_zero_of_zero_dvd (h : 0 ∣ a) : a = 0 :=
dvd.elim h (λ c H', H'.trans (zero_mul c))
/-- Given an element `a` of a commutative semigroup with zero, there exists another element whose
product with zero equals `a` iff `a` equals zero. -/
@[simp] lemma zero_dvd_iff : 0 ∣ a ↔ a = 0 :=
⟨eq_zero_of_zero_dvd, λ h, by { rw h, use 0, simp }⟩
@[simp] theorem dvd_zero (a : α) : a ∣ 0 := dvd.intro 0 (by simp)
end semigroup_with_zero
/-- Given two elements `b`, `c` of a `cancel_monoid_with_zero` and a nonzero element `a`,
`a*b` divides `a*c` iff `b` divides `c`. -/
theorem mul_dvd_mul_iff_left [cancel_monoid_with_zero α] {a b c : α}
(ha : a ≠ 0) : a * b ∣ a * c ↔ b ∣ c :=
exists_congr $ λ d, by rw [mul_assoc, mul_right_inj' ha]
/-- Given two elements `a`, `b` of a commutative `cancel_monoid_with_zero` and a nonzero
element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/
theorem mul_dvd_mul_iff_right [cancel_comm_monoid_with_zero α] {a b c : α} (hc : c ≠ 0) :
a * c ∣ b * c ↔ a ∣ b :=
exists_congr $ λ d, by rw [mul_right_comm, mul_left_inj' hc]
section comm_monoid_with_zero
variable [comm_monoid_with_zero α]
/-- `dvd_not_unit a b` expresses that `a` divides `b` "strictly", i.e. that `b` divided by `a`
is not a unit. -/
def dvd_not_unit (a b : α) : Prop := a ≠ 0 ∧ ∃ x, ¬is_unit x ∧ b = a * x
lemma dvd_not_unit_of_dvd_of_not_dvd {a b : α} (hd : a ∣ b) (hnd : ¬ b ∣ a) :
dvd_not_unit a b :=
begin
split,
{ rintro rfl, exact hnd (dvd_zero _) },
{ rcases hd with ⟨c, rfl⟩,
refine ⟨c, _, rfl⟩,
rintro ⟨u, rfl⟩,
simpa using hnd }
end
end comm_monoid_with_zero
lemma dvd_and_not_dvd_iff [cancel_comm_monoid_with_zero α] {x y : α} :
x ∣ y ∧ ¬y ∣ x ↔ dvd_not_unit x y :=
⟨λ ⟨⟨d, hd⟩, hyx⟩, ⟨λ hx0, by simpa [hx0] using hyx, ⟨d,
mt is_unit_iff_dvd_one.1 (λ ⟨e, he⟩, hyx ⟨e, by rw [hd, mul_assoc, ← he, mul_one]⟩), hd⟩⟩,
λ ⟨hx0, d, hdu, hdx⟩, ⟨⟨d, hdx⟩, λ ⟨e, he⟩, hdu (is_unit_of_dvd_one _
⟨e, mul_left_cancel₀ hx0 $ by conv {to_lhs, rw [he, hdx]};simp [mul_assoc]⟩)⟩⟩
section monoid_with_zero
variable [monoid_with_zero α]
theorem ne_zero_of_dvd_ne_zero {p q : α} (h₁ : q ≠ 0)
(h₂ : p ∣ q) : p ≠ 0 :=
begin
rcases h₂ with ⟨u, rfl⟩,
exact left_ne_zero_of_mul h₁,
end
end monoid_with_zero
|
900965655c9f19bc1ad3b4e0f609788ae4bb9468 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /stage0/src/Init/Data/Char/Basic.lean | 1806d82c0ba49a1059d235de4fb6e4c9e39e5081 | [
"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 | 2,093 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import Init.Data.UInt
@[inline, reducible] def isValidChar (n : UInt32) : Prop :=
n < 0xd800 ∨ (0xdfff < n ∧ n < 0x110000)
instance : SizeOf Char := ⟨fun c => c.val.toNat⟩
namespace Char
protected def Less (a b : Char) : Prop := a.val < b.val
protected def LessEq (a b : Char) : Prop := a.val ≤ b.val
instance : HasLess Char := ⟨Char.Less⟩
instance : HasLessEq Char := ⟨Char.LessEq⟩
protected def lt (a b : Char) : Bool := a.val < b.val
instance (a b : Char) : Decidable (a < b) :=
UInt32.decLt _ _
instance (a b : Char) : Decidable (a ≤ b) :=
UInt32.decLe _ _
abbrev isValidCharNat (n : Nat) : Prop :=
n < 0xd800 ∨ (0xdfff < n ∧ n < 0x110000)
theorem isValidUInt32 (n : Nat) (h : isValidCharNat n) : n < uint32Sz := by
match h with
| Or.inl h =>
apply Nat.ltTrans h
exact decide!
| Or.inr ⟨h₁, h₂⟩ =>
apply Nat.ltTrans h₂
exact decide!
theorem isValidCharOfValidNat (n : Nat) (h : isValidCharNat n) : isValidChar (UInt32.ofNat' n (isValidUInt32 n h)) :=
match h with
| Or.inl h => Or.inl h
| Or.inr ⟨h₁, h₂⟩ => Or.inr ⟨h₁, h₂⟩
theorem isValidChar0 : isValidChar 0 :=
Or.inl decide!
@[inline] def toNat (c : Char) : Nat :=
c.val.toNat
instance : Inhabited Char :=
⟨'A'⟩
def isWhitespace (c : Char) : Bool :=
c = ' ' || c = '\t' || c = '\r' || c = '\n'
def isUpper (c : Char) : Bool :=
c.val ≥ 65 && c.val ≤ 90
def isLower (c : Char) : Bool :=
c.val ≥ 97 && c.val ≤ 122
def isAlpha (c : Char) : Bool :=
c.isUpper || c.isLower
def isDigit (c : Char) : Bool :=
c.val ≥ 48 && c.val ≤ 57
def isAlphanum (c : Char) : Bool :=
c.isAlpha || c.isDigit
def toLower (c : Char) : Char :=
let n := toNat c;
if n >= 65 ∧ n <= 90 then ofNat (n + 32) else c
def toUpper (c : Char) : Char :=
let n := toNat c;
if n >= 97 ∧ n <= 122 then ofNat (n - 32) else c
end Char
|
7d554e7654bc8775793b492db46d7c10b445e055 | f7315930643edc12e76c229a742d5446dad77097 | /hott/init/tactic.hlean | 39d2b5af67e7916a52fd152630d8026520156cf1 | [
"Apache-2.0"
] | permissive | bmalehorn/lean | 8f77b762a76c59afff7b7403f9eb5fc2c3ce70c1 | 53653c352643751c4b62ff63ec5e555f11dae8eb | refs/heads/master | 1,610,945,684,489 | 1,429,681,220,000 | 1,429,681,449,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,743 | hlean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.tactic
Author: Leonardo de Moura
This is just a trick to embed the 'tactic language' as a Lean
expression. We should view 'tactic' as automation that when execute
produces a term. tactic.builtin is just a "dummy" for creating the
definitions that are actually implemented in C++
-/
prelude
import init.datatypes init.reserved_notation init.num
inductive tactic :
Type := builtin : tactic
namespace tactic
-- Remark the following names are not arbitrary, the tactic module
-- uses them when converting Lean expressions into actual tactic objects.
-- The bultin 'by' construct triggers the process of converting a
-- a term of type 'tactic' into a tactic that sythesizes a term
opaque definition and_then (t1 t2 : tactic) : tactic := builtin
opaque definition or_else (t1 t2 : tactic) : tactic := builtin
opaque definition append (t1 t2 : tactic) : tactic := builtin
opaque definition interleave (t1 t2 : tactic) : tactic := builtin
opaque definition par (t1 t2 : tactic) : tactic := builtin
opaque definition fixpoint (f : tactic → tactic) : tactic := builtin
opaque definition repeat (t : tactic) : tactic := builtin
opaque definition at_most (t : tactic) (k : num) : tactic := builtin
opaque definition discard (t : tactic) (k : num) : tactic := builtin
opaque definition focus_at (t : tactic) (i : num) : tactic := builtin
opaque definition try_for (t : tactic) (ms : num) : tactic := builtin
opaque definition all_goals (t : tactic) : tactic := builtin
opaque definition now : tactic := builtin
opaque definition assumption : tactic := builtin
opaque definition eassumption : tactic := builtin
opaque definition state : tactic := builtin
opaque definition fail : tactic := builtin
opaque definition id : tactic := builtin
opaque definition beta : tactic := builtin
opaque definition info : tactic := builtin
opaque definition whnf : tactic := builtin
opaque definition rotate_left (k : num) := builtin
opaque definition rotate_right (k : num) := builtin
definition rotate (k : num) := rotate_left k
-- This is just a trick to embed expressions into tactics.
-- The nested expressions are "raw". They tactic should
-- elaborate them when it is executed.
inductive expr : Type :=
builtin : expr
opaque definition apply (e : expr) : tactic := builtin
opaque definition rapply (e : expr) : tactic := builtin
opaque definition fapply (e : expr) : tactic := builtin
opaque definition rename (a b : expr) : tactic := builtin
opaque definition intro (e : expr) : tactic := builtin
opaque definition generalize (e : expr) : tactic := builtin
opaque definition clear (e : expr) : tactic := builtin
opaque definition revert (e : expr) : tactic := builtin
opaque definition unfold (e : expr) : tactic := builtin
opaque definition refine (e : expr) : tactic := builtin
opaque definition exact (e : expr) : tactic := builtin
-- Relaxed version of exact that does not enforce goal type
opaque definition rexact (e : expr) : tactic := builtin
opaque definition check_expr (e : expr) : tactic := builtin
opaque definition trace (s : string) : tactic := builtin
inductive expr_list : Type :=
| nil : expr_list
| cons : expr → expr_list → expr_list
-- auxiliary type used to mark optional list of arguments
definition opt_expr_list := expr_list
-- rewrite_tac is just a marker for the builtin 'rewrite' notation
-- used to create instances of this tactic.
opaque definition rewrite_tac (e : expr_list) : tactic := builtin
opaque definition cases (id : expr) (ids : opt_expr_list) : tactic := builtin
opaque definition intros (ids : opt_expr_list) : tactic := builtin
opaque definition generalizes (es : expr_list) : tactic := builtin
opaque definition clears (ids : expr_list) : tactic := builtin
opaque definition reverts (ids : expr_list) : tactic := builtin
opaque definition change (e : expr) : tactic := builtin
opaque definition assert_hypothesis (id : expr) (e : expr) : tactic := builtin
infixl `;`:15 := and_then
notation `(` h `|` r:(foldl `|` (e r, or_else r e) h) `)` := r
definition try (t : tactic) : tactic := (t | id)
definition repeat1 (t : tactic) : tactic := t ; repeat t
definition focus (t : tactic) : tactic := focus_at t 0
definition determ (t : tactic) : tactic := at_most t 1
definition trivial : tactic := ( apply eq.refl | assumption )
definition do (n : num) (t : tactic) : tactic :=
nat.rec id (λn t', (t;t')) (nat.of_num n)
end tactic
|
b58379b39e5fcf2e417ed96197b84615713e12a5 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/sites/sheaf_of_types.lean | cdd033564ed2789e74e9f68ccb526c90fce8d568 | [
"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 | 40,890 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.sites.pretopology
import category_theory.limits.shapes.types
/-!
# Sheaves of types on a Grothendieck topology
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Defines the notion of a sheaf of types (usually called a sheaf of sets by mathematicians)
on a category equipped with a Grothendieck topology, as well as a range of equivalent
conditions useful in different situations.
First define what it means for a presheaf `P : Cᵒᵖ ⥤ Type v` to be a sheaf *for* a particular
presieve `R` on `X`:
* A *family of elements* `x` for `P` at `R` is an element `x_f` of `P Y` for every `f : Y ⟶ X` in
`R`. See `family_of_elements`.
* The family `x` is *compatible* if, for any `f₁ : Y₁ ⟶ X` and `f₂ : Y₂ ⟶ X` both in `R`,
and any `g₁ : Z ⟶ Y₁` and `g₂ : Z ⟶ Y₂` such that `g₁ ≫ f₁ = g₂ ≫ f₂`, the restriction of
`x_f₁` along `g₁` agrees with the restriction of `x_f₂` along `g₂`.
See `family_of_elements.compatible`.
* An *amalgamation* `t` for the family is an element of `P X` such that for every `f : Y ⟶ X` in
`R`, the restriction of `t` on `f` is `x_f`.
See `family_of_elements.is_amalgamation`.
We then say `P` is *separated* for `R` if every compatible family has at most one amalgamation,
and it is a *sheaf* for `R` if every compatible family has a unique amalgamation.
See `is_separated_for` and `is_sheaf_for`.
In the special case where `R` is a sieve, the compatibility condition can be simplified:
* The family `x` is *compatible* if, for any `f : Y ⟶ X` in `R` and `g : Z ⟶ Y`, the restriction of
`x_f` along `g` agrees with `x_(g ≫ f)` (which is well defined since `g ≫ f` is in `R`).
See `family_of_elements.sieve_compatible` and `compatible_iff_sieve_compatible`.
In the special case where `C` has pullbacks, the compatibility condition can be simplified:
* The family `x` is *compatible* if, for any `f : Y ⟶ X` and `g : Z ⟶ X` both in `R`,
the restriction of `x_f` along `π₁ : pullback f g ⟶ Y` agrees with the restriction of `x_g`
along `π₂ : pullback f g ⟶ Z`.
See `family_of_elements.pullback_compatible` and `pullback_compatible_iff`.
Now given a Grothendieck topology `J`, `P` is a sheaf if it is a sheaf for every sieve in the
topology. See `is_sheaf`.
In the case where the topology is generated by a basis, it suffices to check `P` is a sheaf for
every presieve in the pretopology. See `is_sheaf_pretopology`.
We also provide equivalent conditions to satisfy alternate definitions given in the literature.
* Stacks: In `equalizer.presieve.sheaf_condition`, the sheaf condition at a presieve is shown to be
equivalent to that of https://stacks.math.columbia.edu/tag/00VM (and combined with
`is_sheaf_pretopology`, this shows the notions of `is_sheaf` are exactly equivalent.)
The condition of https://stacks.math.columbia.edu/tag/00Z8 is virtually identical to the
statement of `yoneda_condition_iff_sheaf_condition` (since the bijection described there carries
the same information as the unique existence.)
* Maclane-Moerdijk [MM92]: Using `compatible_iff_sieve_compatible`, the definitions of `is_sheaf`
are equivalent. There are also alternate definitions given:
- Yoneda condition: Defined in `yoneda_sheaf_condition` and equivalence in
`yoneda_condition_iff_sheaf_condition`.
- Equalizer condition (Equation 3): Defined in the `equalizer.sieve` namespace, and equivalence
in `equalizer.sieve.sheaf_condition`.
- Matching family for presieves with pullback: `pullback_compatible_iff`.
- Sheaf for a pretopology (Prop 1): `is_sheaf_pretopology` combined with the previous.
- Sheaf for a pretopology as equalizer (Prop 1, bis): `equalizer.presieve.sheaf_condition`
combined with the previous.
## Implementation
The sheaf condition is given as a proposition, rather than a subsingleton in `Type (max u₁ v)`.
This doesn't seem to make a big difference, other than making a couple of definitions noncomputable,
but it means that equivalent conditions can be given as `↔` statements rather than `≃` statements,
which can be convenient.
## References
* [MM92]: *Sheaves in geometry and logic*, Saunders MacLane, and Ieke Moerdijk:
Chapter III, Section 4.
* [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1.
* https://stacks.math.columbia.edu/tag/00VL (sheaves on a pretopology or site)
* https://stacks.math.columbia.edu/tag/00ZB (sheaves on a topology)
-/
universes w v₁ v₂ u₁ u₂
namespace category_theory
open opposite category_theory category limits sieve
namespace presieve
variables {C : Type u₁} [category.{v₁} C]
variables {P Q U : Cᵒᵖ ⥤ Type w}
variables {X Y : C} {S : sieve X} {R : presieve X}
variables (J J₂ : grothendieck_topology C)
/--
A family of elements for a presheaf `P` given a collection of arrows `R` with fixed codomain `X`
consists of an element of `P Y` for every `f : Y ⟶ X` in `R`.
A presheaf is a sheaf (resp, separated) if every *compatible* family of elements has exactly one
(resp, at most one) amalgamation.
This data is referred to as a `family` in [MM92], Chapter III, Section 4. It is also a concrete
version of the elements of the middle object in https://stacks.math.columbia.edu/tag/00VM which is
more useful for direct calculations. It is also used implicitly in Definition C2.1.2 in [Elephant].
-/
def family_of_elements (P : Cᵒᵖ ⥤ Type w) (R : presieve X) :=
Π ⦃Y : C⦄ (f : Y ⟶ X), R f → P.obj (op Y)
instance : inhabited (family_of_elements P (⊥ : presieve X)) := ⟨λ Y f, false.elim⟩
/--
A family of elements for a presheaf on the presieve `R₂` can be restricted to a smaller presieve
`R₁`.
-/
def family_of_elements.restrict {R₁ R₂ : presieve X} (h : R₁ ≤ R₂) :
family_of_elements P R₂ → family_of_elements P R₁ :=
λ x Y f hf, x f (h _ hf)
/--
A family of elements for the arrow set `R` is *compatible* if for any `f₁ : Y₁ ⟶ X` and
`f₂ : Y₂ ⟶ X` in `R`, and any `g₁ : Z ⟶ Y₁` and `g₂ : Z ⟶ Y₂`, if the square `g₁ ≫ f₁ = g₂ ≫ f₂`
commutes then the elements of `P Z` obtained by restricting the element of `P Y₁` along `g₁` and
restricting the element of `P Y₂` along `g₂` are the same.
In special cases, this condition can be simplified, see `pullback_compatible_iff` and
`compatible_iff_sieve_compatible`.
This is referred to as a "compatible family" in Definition C2.1.2 of [Elephant], and on nlab:
https://ncatlab.org/nlab/show/sheaf#GeneralDefinitionInComponents
-/
def family_of_elements.compatible (x : family_of_elements P R) : Prop :=
∀ ⦃Y₁ Y₂ Z⦄ (g₁ : Z ⟶ Y₁) (g₂ : Z ⟶ Y₂) ⦃f₁ : Y₁ ⟶ X⦄ ⦃f₂ : Y₂ ⟶ X⦄
(h₁ : R f₁) (h₂ : R f₂), g₁ ≫ f₁ = g₂ ≫ f₂ → P.map g₁.op (x f₁ h₁) = P.map g₂.op (x f₂ h₂)
/--
If the category `C` has pullbacks, this is an alternative condition for a family of elements to be
compatible: For any `f : Y ⟶ X` and `g : Z ⟶ X` in the presieve `R`, the restriction of the
given elements for `f` and `g` to the pullback agree.
This is equivalent to being compatible (provided `C` has pullbacks), shown in
`pullback_compatible_iff`.
This is the definition for a "matching" family given in [MM92], Chapter III, Section 4,
Equation (5). Viewing the type `family_of_elements` as the middle object of the fork in
https://stacks.math.columbia.edu/tag/00VM, this condition expresses that `pr₀* (x) = pr₁* (x)`,
using the notation defined there.
-/
def family_of_elements.pullback_compatible (x : family_of_elements P R) [has_pullbacks C] : Prop :=
∀ ⦃Y₁ Y₂⦄ ⦃f₁ : Y₁ ⟶ X⦄ ⦃f₂ : Y₂ ⟶ X⦄ (h₁ : R f₁) (h₂ : R f₂),
P.map (pullback.fst : pullback f₁ f₂ ⟶ _).op (x f₁ h₁) = P.map pullback.snd.op (x f₂ h₂)
lemma pullback_compatible_iff (x : family_of_elements P R) [has_pullbacks C] :
x.compatible ↔ x.pullback_compatible :=
begin
split,
{ intros t Y₁ Y₂ f₁ f₂ hf₁ hf₂,
apply t,
apply pullback.condition },
{ intros t Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ comm,
rw [←pullback.lift_fst _ _ comm, op_comp, functor_to_types.map_comp_apply, t hf₁ hf₂,
←functor_to_types.map_comp_apply, ←op_comp, pullback.lift_snd] }
end
/-- The restriction of a compatible family is compatible. -/
lemma family_of_elements.compatible.restrict {R₁ R₂ : presieve X} (h : R₁ ≤ R₂)
{x : family_of_elements P R₂} : x.compatible → (x.restrict h).compatible :=
λ q Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ comm, q g₁ g₂ (h _ h₁) (h _ h₂) comm
/--
Extend a family of elements to the sieve generated by an arrow set.
This is the construction described as "easy" in Lemma C2.1.3 of [Elephant].
-/
noncomputable def family_of_elements.sieve_extend (x : family_of_elements P R) :
family_of_elements P (generate R) :=
λ Z f hf, P.map hf.some_spec.some.op (x _ hf.some_spec.some_spec.some_spec.1)
/-- The extension of a compatible family to the generated sieve is compatible. -/
lemma family_of_elements.compatible.sieve_extend {x : family_of_elements P R} (hx : x.compatible) :
x.sieve_extend.compatible :=
begin
intros _ _ _ _ _ _ _ h₁ h₂ comm,
iterate 2 { erw ← functor_to_types.map_comp_apply, rw ← op_comp }, apply hx,
simp [comm, h₁.some_spec.some_spec.some_spec.2, h₂.some_spec.some_spec.some_spec.2],
end
/-- The extension of a family agrees with the original family. -/
lemma extend_agrees {x : family_of_elements P R} (t : x.compatible) {f : Y ⟶ X} (hf : R f) :
x.sieve_extend f (le_generate R Y hf) = x f hf :=
begin
have h := (le_generate R Y hf).some_spec,
unfold family_of_elements.sieve_extend,
rw t h.some (𝟙 _) _ hf _,
{ simp }, { rw id_comp, exact h.some_spec.some_spec.2 },
end
/-- The restriction of an extension is the original. -/
@[simp]
lemma restrict_extend {x : family_of_elements P R} (t : x.compatible) :
x.sieve_extend.restrict (le_generate R) = x :=
begin
ext Y f hf,
exact extend_agrees t hf,
end
/--
If the arrow set for a family of elements is actually a sieve (i.e. it is downward closed) then the
consistency condition can be simplified.
This is an equivalent condition, see `compatible_iff_sieve_compatible`.
This is the notion of "matching" given for families on sieves given in [MM92], Chapter III,
Section 4, Equation 1, and nlab: https://ncatlab.org/nlab/show/matching+family.
See also the discussion before Lemma C2.1.4 of [Elephant].
-/
def family_of_elements.sieve_compatible (x : family_of_elements P S) : Prop :=
∀ ⦃Y Z⦄ (f : Y ⟶ X) (g : Z ⟶ Y) (hf), x (g ≫ f) (S.downward_closed hf g) = P.map g.op (x f hf)
lemma compatible_iff_sieve_compatible (x : family_of_elements P S) :
x.compatible ↔ x.sieve_compatible :=
begin
split,
{ intros h Y Z f g hf,
simpa using h (𝟙 _) g (S.downward_closed hf g) hf (id_comp _) },
{ intros h Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ k,
simp_rw [← h f₁ g₁ h₁, k, h f₂ g₂ h₂] }
end
lemma family_of_elements.compatible.to_sieve_compatible {x : family_of_elements P S}
(t : x.compatible) : x.sieve_compatible :=
(compatible_iff_sieve_compatible x).1 t
/--
Given a family of elements `x` for the sieve `S` generated by a presieve `R`, if `x` is restricted
to `R` and then extended back up to `S`, the resulting extension equals `x`.
-/
@[simp]
lemma extend_restrict {x : family_of_elements P (generate R)} (t : x.compatible) :
(x.restrict (le_generate R)).sieve_extend = x :=
begin
rw compatible_iff_sieve_compatible at t,
ext _ _ h, apply (t _ _ _).symm.trans, congr,
exact h.some_spec.some_spec.some_spec.2,
end
/--
Two compatible families on the sieve generated by a presieve `R` are equal if and only if they are
equal when restricted to `R`.
-/
lemma restrict_inj {x₁ x₂ : family_of_elements P (generate R)}
(t₁ : x₁.compatible) (t₂ : x₂.compatible) :
x₁.restrict (le_generate R) = x₂.restrict (le_generate R) → x₁ = x₂ :=
λ h, by { rw [←extend_restrict t₁, ←extend_restrict t₂], congr, exact h }
/-- Compatible families of elements for a presheaf of types `P` and a presieve `R`
are in 1-1 correspondence with compatible families for the same presheaf and
the sieve generated by `R`, through extension and restriction. -/
@[simps] noncomputable def compatible_equiv_generate_sieve_compatible :
{x : family_of_elements P R // x.compatible} ≃
{x : family_of_elements P (generate R) // x.compatible} :=
{ to_fun := λ x, ⟨x.1.sieve_extend, x.2.sieve_extend⟩,
inv_fun := λ x, ⟨x.1.restrict (le_generate R), x.2.restrict _⟩,
left_inv := λ x, subtype.ext (restrict_extend x.2),
right_inv := λ x, subtype.ext (extend_restrict x.2) }
lemma family_of_elements.comp_of_compatible (S : sieve X) {x : family_of_elements P S}
(t : x.compatible) {f : Y ⟶ X} (hf : S f) {Z} (g : Z ⟶ Y) :
x (g ≫ f) (S.downward_closed hf g) = P.map g.op (x f hf) :=
by simpa using t (𝟙 _) g (S.downward_closed hf g) hf (id_comp _)
section functor_pullback
variables {D : Type u₂} [category.{v₂} D] (F : D ⥤ C) {Z : D}
variables {T : presieve (F.obj Z)} {x : family_of_elements P T}
/--
Given a family of elements of a sieve `S` on `F(X)`, we can realize it as a family of elements of
`S.functor_pullback F`.
-/
def family_of_elements.functor_pullback (x : family_of_elements P T) :
family_of_elements (F.op ⋙ P) (T.functor_pullback F) := λ Y f hf, x (F.map f) hf
lemma family_of_elements.compatible.functor_pullback (h : x.compatible) :
(x.functor_pullback F).compatible :=
begin
intros Z₁ Z₂ W g₁ g₂ f₁ f₂ h₁ h₂ eq,
exact h (F.map g₁) (F.map g₂) h₁ h₂ (by simp only [← F.map_comp, eq])
end
end functor_pullback
/--
Given a family of elements of a sieve `S` on `X` whose values factors through `F`, we can
realize it as a family of elements of `S.functor_pushforward F`. Since the preimage is obtained by
choice, this is not well-defined generally.
-/
noncomputable
def family_of_elements.functor_pushforward {D : Type u₂} [category.{v₂} D] (F : D ⥤ C) {X : D}
{T : presieve X} (x : family_of_elements (F.op ⋙ P) T) :
family_of_elements P (T.functor_pushforward F) := λ Y f h,
by { obtain ⟨Z, g, h, h₁, _⟩ := get_functor_pushforward_structure h, exact P.map h.op (x g h₁) }
section pullback
/--
Given a family of elements of a sieve `S` on `X`, and a map `Y ⟶ X`, we can obtain a
family of elements of `S.pullback f` by taking the same elements.
-/
def family_of_elements.pullback (f : Y ⟶ X) (x : family_of_elements P S) :
family_of_elements P (S.pullback f) := λ _ g hg, x (g ≫ f) hg
lemma family_of_elements.compatible.pullback (f : Y ⟶ X) {x : family_of_elements P S}
(h : x.compatible) : (x.pullback f).compatible :=
begin
simp only [compatible_iff_sieve_compatible] at h ⊢,
intros W Z f₁ f₂ hf,
unfold family_of_elements.pullback,
rw ← (h (f₁ ≫ f) f₂ hf),
simp only [assoc],
end
end pullback
/--
Given a morphism of presheaves `f : P ⟶ Q`, we can take a family of elements valued in `P` to a
family of elements valued in `Q` by composing with `f`.
-/
def family_of_elements.comp_presheaf_map (f : P ⟶ Q) (x : family_of_elements P R) :
family_of_elements Q R := λ Y g hg, f.app (op Y) (x g hg)
@[simp]
lemma family_of_elements.comp_presheaf_map_id (x : family_of_elements P R) :
x.comp_presheaf_map (𝟙 P) = x := rfl
@[simp]
lemma family_of_elements.comp_prersheaf_map_comp (x : family_of_elements P R)
(f : P ⟶ Q) (g : Q ⟶ U) :
(x.comp_presheaf_map f).comp_presheaf_map g = x.comp_presheaf_map (f ≫ g) := rfl
lemma family_of_elements.compatible.comp_presheaf_map (f : P ⟶ Q) {x : family_of_elements P R}
(h : x.compatible) : (x.comp_presheaf_map f).compatible :=
begin
intros Z₁ Z₂ W g₁ g₂ f₁ f₂ h₁ h₂ eq,
unfold family_of_elements.comp_presheaf_map,
rwa [← functor_to_types.naturality, ← functor_to_types.naturality, h],
end
/--
The given element `t` of `P.obj (op X)` is an *amalgamation* for the family of elements `x` if every
restriction `P.map f.op t = x_f` for every arrow `f` in the presieve `R`.
This is the definition given in https://ncatlab.org/nlab/show/sheaf#GeneralDefinitionInComponents,
and https://ncatlab.org/nlab/show/matching+family, as well as [MM92], Chapter III, Section 4,
equation (2).
-/
def family_of_elements.is_amalgamation (x : family_of_elements P R)
(t : P.obj (op X)) : Prop :=
∀ ⦃Y : C⦄ (f : Y ⟶ X) (h : R f), P.map f.op t = x f h
lemma family_of_elements.is_amalgamation.comp_presheaf_map
{x : family_of_elements P R} {t} (f : P ⟶ Q) (h : x.is_amalgamation t) :
(x.comp_presheaf_map f).is_amalgamation (f.app (op X) t) :=
begin
intros Y g hg,
dsimp [family_of_elements.comp_presheaf_map],
change (f.app _ ≫ Q.map _) _ = _,
simp [← f.naturality, h g hg],
end
lemma is_compatible_of_exists_amalgamation (x : family_of_elements P R)
(h : ∃ t, x.is_amalgamation t) : x.compatible :=
begin
cases h with t ht,
intros Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ comm,
rw [←ht _ h₁, ←ht _ h₂, ←functor_to_types.map_comp_apply, ←op_comp, comm],
simp,
end
lemma is_amalgamation_restrict {R₁ R₂ : presieve X} (h : R₁ ≤ R₂)
(x : family_of_elements P R₂) (t : P.obj (op X)) (ht : x.is_amalgamation t) :
(x.restrict h).is_amalgamation t :=
λ Y f hf, ht f (h Y hf)
lemma is_amalgamation_sieve_extend {R : presieve X}
(x : family_of_elements P R) (t : P.obj (op X)) (ht : x.is_amalgamation t) :
x.sieve_extend.is_amalgamation t :=
begin
intros Y f hf,
dsimp [family_of_elements.sieve_extend],
rw [←ht _, ←functor_to_types.map_comp_apply, ←op_comp, hf.some_spec.some_spec.some_spec.2],
end
/-- A presheaf is separated for a presieve if there is at most one amalgamation. -/
def is_separated_for (P : Cᵒᵖ ⥤ Type w) (R : presieve X) : Prop :=
∀ (x : family_of_elements P R) (t₁ t₂),
x.is_amalgamation t₁ → x.is_amalgamation t₂ → t₁ = t₂
lemma is_separated_for.ext {R : presieve X} (hR : is_separated_for P R)
{t₁ t₂ : P.obj (op X)} (h : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (hf : R f), P.map f.op t₁ = P.map f.op t₂) :
t₁ = t₂ :=
hR (λ Y f hf, P.map f.op t₂) t₁ t₂ (λ Y f hf, h hf) (λ Y f hf, rfl)
lemma is_separated_for_iff_generate :
is_separated_for P R ↔ is_separated_for P (generate R) :=
begin
split,
{ intros h x t₁ t₂ ht₁ ht₂,
apply h (x.restrict (le_generate R)) t₁ t₂ _ _,
{ exact is_amalgamation_restrict _ x t₁ ht₁ },
{ exact is_amalgamation_restrict _ x t₂ ht₂ } },
{ intros h x t₁ t₂ ht₁ ht₂,
apply h (x.sieve_extend),
{ exact is_amalgamation_sieve_extend x t₁ ht₁ },
{ exact is_amalgamation_sieve_extend x t₂ ht₂ } }
end
lemma is_separated_for_top (P : Cᵒᵖ ⥤ Type w) : is_separated_for P (⊤ : presieve X) :=
λ x t₁ t₂ h₁ h₂,
begin
have q₁ := h₁ (𝟙 X) (by simp),
have q₂ := h₂ (𝟙 X) (by simp),
simp only [op_id, functor_to_types.map_id_apply] at q₁ q₂,
rw [q₁, q₂],
end
/--
We define `P` to be a sheaf for the presieve `R` if every compatible family has a unique
amalgamation.
This is the definition of a sheaf for the given presieve given in C2.1.2 of [Elephant], and
https://ncatlab.org/nlab/show/sheaf#GeneralDefinitionInComponents.
Using `compatible_iff_sieve_compatible`,
this is equivalent to the definition of a sheaf in [MM92], Chapter III, Section 4.
-/
def is_sheaf_for (P : Cᵒᵖ ⥤ Type w) (R : presieve X) : Prop :=
∀ (x : family_of_elements P R), x.compatible → ∃! t, x.is_amalgamation t
/--
This is an equivalent condition to be a sheaf, which is useful for the abstraction to local
operators on elementary toposes. However this definition is defined only for sieves, not presieves.
The equivalence between this and `is_sheaf_for` is given in `yoneda_condition_iff_sheaf_condition`.
This version is also useful to establish that being a sheaf is preserved under isomorphism of
presheaves.
See the discussion before Equation (3) of [MM92], Chapter III, Section 4. See also C2.1.4 of
[Elephant]. This is also a direct reformulation of <https://stacks.math.columbia.edu/tag/00Z8>.
-/
def yoneda_sheaf_condition (P : Cᵒᵖ ⥤ Type v₁) (S : sieve X) : Prop :=
∀ (f : S.functor ⟶ P), ∃! g, S.functor_inclusion ≫ g = f
-- TODO: We can generalize the universe parameter v₁ above by composing with
-- appropriate `ulift_functor`s.
/--
(Implementation). This is a (primarily internal) equivalence between natural transformations
and compatible families.
Cf the discussion after Lemma 7.47.10 in <https://stacks.math.columbia.edu/tag/00YW>. See also
the proof of C2.1.4 of [Elephant], and the discussion in [MM92], Chapter III, Section 4.
-/
def nat_trans_equiv_compatible_family {P : Cᵒᵖ ⥤ Type v₁} :
(S.functor ⟶ P) ≃ {x : family_of_elements P S // x.compatible} :=
{ to_fun := λ α,
begin
refine ⟨λ Y f hf, _, _⟩,
{ apply α.app (op Y) ⟨_, hf⟩ },
{ rw compatible_iff_sieve_compatible,
intros Y Z f g hf,
dsimp,
rw ← functor_to_types.naturality _ _ α g.op,
refl }
end,
inv_fun := λ t,
{ app := λ Y f, t.1 _ f.2,
naturality' := λ Y Z g,
begin
ext ⟨f, hf⟩,
apply t.2.to_sieve_compatible _,
end },
left_inv := λ α,
begin
ext X ⟨_, _⟩,
refl
end,
right_inv :=
begin
rintro ⟨x, hx⟩,
refl,
end }
/-- (Implementation). A lemma useful to prove `yoneda_condition_iff_sheaf_condition`. -/
lemma extension_iff_amalgamation {P : Cᵒᵖ ⥤ Type v₁} (x : S.functor ⟶ P) (g : yoneda.obj X ⟶ P) :
S.functor_inclusion ≫ g = x ↔
(nat_trans_equiv_compatible_family x).1.is_amalgamation (yoneda_equiv g) :=
begin
change _ ↔ ∀ ⦃Y : C⦄ (f : Y ⟶ X) (h : S f), P.map f.op (yoneda_equiv g) = x.app (op Y) ⟨f, h⟩,
split,
{ rintro rfl Y f hf,
rw yoneda_equiv_naturality,
dsimp,
simp }, -- See note [dsimp, simp].
{ intro h,
ext Y ⟨f, hf⟩,
have : _ = x.app Y _ := h f hf,
rw yoneda_equiv_naturality at this,
rw ← this,
dsimp,
simp }, -- See note [dsimp, simp].
end
/--
The yoneda version of the sheaf condition is equivalent to the sheaf condition.
C2.1.4 of [Elephant].
-/
lemma is_sheaf_for_iff_yoneda_sheaf_condition {P : Cᵒᵖ ⥤ Type v₁} :
is_sheaf_for P S ↔ yoneda_sheaf_condition P S :=
begin
rw [is_sheaf_for, yoneda_sheaf_condition],
simp_rw [extension_iff_amalgamation],
rw equiv.forall_congr_left' nat_trans_equiv_compatible_family,
rw subtype.forall,
apply ball_congr,
intros x hx,
rw equiv.exists_unique_congr_left _,
simp,
end
/--
If `P` is a sheaf for the sieve `S` on `X`, a natural transformation from `S` (viewed as a functor)
to `P` can be (uniquely) extended to all of `yoneda.obj X`.
f
S → P
↓ ↗
yX
-/
noncomputable def is_sheaf_for.extend {P : Cᵒᵖ ⥤ Type v₁} (h : is_sheaf_for P S)
(f : S.functor ⟶ P) : yoneda.obj X ⟶ P :=
(is_sheaf_for_iff_yoneda_sheaf_condition.1 h f).exists.some
/--
Show that the extension of `f : S.functor ⟶ P` to all of `yoneda.obj X` is in fact an extension, ie
that the triangle below commutes, provided `P` is a sheaf for `S`
f
S → P
↓ ↗
yX
-/
@[simp, reassoc]
lemma is_sheaf_for.functor_inclusion_comp_extend {P : Cᵒᵖ ⥤ Type v₁} (h : is_sheaf_for P S)
(f : S.functor ⟶ P) : S.functor_inclusion ≫ h.extend f = f :=
(is_sheaf_for_iff_yoneda_sheaf_condition.1 h f).exists.some_spec
/-- The extension of `f` to `yoneda.obj X` is unique. -/
lemma is_sheaf_for.unique_extend {P : Cᵒᵖ ⥤ Type v₁} (h : is_sheaf_for P S) {f : S.functor ⟶ P}
(t : yoneda.obj X ⟶ P) (ht : S.functor_inclusion ≫ t = f) :
t = h.extend f :=
((is_sheaf_for_iff_yoneda_sheaf_condition.1 h f).unique ht (h.functor_inclusion_comp_extend f))
/--
If `P` is a sheaf for the sieve `S` on `X`, then if two natural transformations from `yoneda.obj X`
to `P` agree when restricted to the subfunctor given by `S`, they are equal.
-/
lemma is_sheaf_for.hom_ext {P : Cᵒᵖ ⥤ Type v₁} (h : is_sheaf_for P S) (t₁ t₂ : yoneda.obj X ⟶ P)
(ht : S.functor_inclusion ≫ t₁ = S.functor_inclusion ≫ t₂) :
t₁ = t₂ :=
(h.unique_extend t₁ ht).trans (h.unique_extend t₂ rfl).symm
/-- `P` is a sheaf for `R` iff it is separated for `R` and there exists an amalgamation. -/
lemma is_separated_for_and_exists_is_amalgamation_iff_sheaf_for :
is_separated_for P R ∧ (∀ (x : family_of_elements P R), x.compatible → ∃ t, x.is_amalgamation t) ↔
is_sheaf_for P R :=
begin
rw [is_separated_for, ←forall_and_distrib],
apply forall_congr,
intro x,
split,
{ intros z hx, exact exists_unique_of_exists_of_unique (z.2 hx) z.1 },
{ intros h,
refine ⟨_, (exists_of_exists_unique ∘ h)⟩,
intros t₁ t₂ ht₁ ht₂,
apply (h _).unique ht₁ ht₂,
exact is_compatible_of_exists_amalgamation x ⟨_, ht₂⟩ }
end
/--
If `P` is separated for `R` and every family has an amalgamation, then `P` is a sheaf for `R`.
-/
lemma is_separated_for.is_sheaf_for (t : is_separated_for P R) :
(∀ (x : family_of_elements P R), x.compatible → ∃ t, x.is_amalgamation t) →
is_sheaf_for P R :=
begin
rw ← is_separated_for_and_exists_is_amalgamation_iff_sheaf_for,
exact and.intro t,
end
/-- If `P` is a sheaf for `R`, it is separated for `R`. -/
lemma is_sheaf_for.is_separated_for : is_sheaf_for P R → is_separated_for P R :=
λ q, (is_separated_for_and_exists_is_amalgamation_iff_sheaf_for.2 q).1
/-- Get the amalgamation of the given compatible family, provided we have a sheaf. -/
noncomputable def is_sheaf_for.amalgamate
(t : is_sheaf_for P R) (x : family_of_elements P R) (hx : x.compatible) :
P.obj (op X) :=
(t x hx).exists.some
lemma is_sheaf_for.is_amalgamation
(t : is_sheaf_for P R) {x : family_of_elements P R} (hx : x.compatible) :
x.is_amalgamation (t.amalgamate x hx) :=
(t x hx).exists.some_spec
@[simp]
lemma is_sheaf_for.valid_glue
(t : is_sheaf_for P R) {x : family_of_elements P R} (hx : x.compatible) (f : Y ⟶ X) (Hf : R f) :
P.map f.op (t.amalgamate x hx) = x f Hf :=
t.is_amalgamation hx f Hf
/-- C2.1.3 in [Elephant] -/
lemma is_sheaf_for_iff_generate (R : presieve X) :
is_sheaf_for P R ↔ is_sheaf_for P (generate R) :=
begin
rw ← is_separated_for_and_exists_is_amalgamation_iff_sheaf_for,
rw ← is_separated_for_and_exists_is_amalgamation_iff_sheaf_for,
rw ← is_separated_for_iff_generate,
apply and_congr (iff.refl _),
split,
{ intros q x hx,
apply exists_imp_exists _ (q _ (hx.restrict (le_generate R))),
intros t ht,
simpa [hx] using is_amalgamation_sieve_extend _ _ ht },
{ intros q x hx,
apply exists_imp_exists _ (q _ hx.sieve_extend),
intros t ht,
simpa [hx] using is_amalgamation_restrict (le_generate R) _ _ ht },
end
/--
Every presheaf is a sheaf for the family {𝟙 X}.
[Elephant] C2.1.5(i)
-/
lemma is_sheaf_for_singleton_iso (P : Cᵒᵖ ⥤ Type w) :
is_sheaf_for P (presieve.singleton (𝟙 X)) :=
begin
intros x hx,
refine ⟨x _ (presieve.singleton_self _), _, _⟩,
{ rintro _ _ ⟨rfl, rfl⟩,
simp },
{ intros t ht,
simpa using ht _ (presieve.singleton_self _) }
end
/--
Every presheaf is a sheaf for the maximal sieve.
[Elephant] C2.1.5(ii)
-/
lemma is_sheaf_for_top_sieve (P : Cᵒᵖ ⥤ Type w) :
is_sheaf_for P ((⊤ : sieve X) : presieve X) :=
begin
rw ← generate_of_singleton_is_split_epi (𝟙 X),
rw ← is_sheaf_for_iff_generate,
apply is_sheaf_for_singleton_iso,
end
/--
If `P` is a sheaf for `S`, and it is iso to `P'`, then `P'` is a sheaf for `S`. This shows that
"being a sheaf for a presieve" is a mathematical or hygenic property.
-/
lemma is_sheaf_for_iso {P' : Cᵒᵖ ⥤ Type w} (i : P ≅ P') : is_sheaf_for P R → is_sheaf_for P' R :=
begin
intros h x hx,
let x' := x.comp_presheaf_map i.inv,
have : x'.compatible := family_of_elements.compatible.comp_presheaf_map i.inv hx,
obtain ⟨t, ht1, ht2⟩ := h x' this,
use i.hom.app _ t,
fsplit,
{ convert family_of_elements.is_amalgamation.comp_presheaf_map i.hom ht1,
dsimp [x'],
simp },
{ intros y hy,
rw (show y = (i.inv.app (op X) ≫ i.hom.app (op X)) y, by simp),
simp [ ht2 (i.inv.app _ y) (family_of_elements.is_amalgamation.comp_presheaf_map i.inv hy)] }
end
/--
If a presieve `R` on `X` has a subsieve `S` such that:
* `P` is a sheaf for `S`.
* For every `f` in `R`, `P` is separated for the pullback of `S` along `f`,
then `P` is a sheaf for `R`.
This is closely related to [Elephant] C2.1.6(i).
-/
lemma is_sheaf_for_subsieve_aux (P : Cᵒᵖ ⥤ Type w) {S : sieve X} {R : presieve X}
(h : (S : presieve X) ≤ R)
(hS : is_sheaf_for P S)
(trans : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, R f → is_separated_for P (S.pullback f)) :
is_sheaf_for P R :=
begin
rw ← is_separated_for_and_exists_is_amalgamation_iff_sheaf_for,
split,
{ intros x t₁ t₂ ht₁ ht₂,
exact hS.is_separated_for _ _ _ (is_amalgamation_restrict h x t₁ ht₁)
(is_amalgamation_restrict h x t₂ ht₂) },
{ intros x hx,
use hS.amalgamate _ (hx.restrict h),
intros W j hj,
apply (trans hj).ext,
intros Y f hf,
rw [←functor_to_types.map_comp_apply, ←op_comp,
hS.valid_glue (hx.restrict h) _ hf, family_of_elements.restrict,
←hx (𝟙 _) f _ _ (id_comp _)],
simp },
end
/--
If `P` is a sheaf for every pullback of the sieve `S`, then `P` is a sheaf for any presieve which
contains `S`.
This is closely related to [Elephant] C2.1.6.
-/
lemma is_sheaf_for_subsieve (P : Cᵒᵖ ⥤ Type w) {S : sieve X} {R : presieve X}
(h : (S : presieve X) ≤ R)
(trans : Π ⦃Y⦄ (f : Y ⟶ X), is_sheaf_for P (S.pullback f)) :
is_sheaf_for P R :=
is_sheaf_for_subsieve_aux P h (by simpa using trans (𝟙 _)) (λ Y f hf, (trans f).is_separated_for)
/-- A presheaf is separated for a topology if it is separated for every sieve in the topology. -/
def is_separated (P : Cᵒᵖ ⥤ Type w) : Prop :=
∀ {X} (S : sieve X), S ∈ J X → is_separated_for P S
/--
A presheaf is a sheaf for a topology if it is a sheaf for every sieve in the topology.
If the given topology is given by a pretopology, `is_sheaf_for_pretopology` shows it suffices to
check the sheaf condition at presieves in the pretopology.
-/
def is_sheaf (P : Cᵒᵖ ⥤ Type w) : Prop :=
∀ ⦃X⦄ (S : sieve X), S ∈ J X → is_sheaf_for P S
lemma is_sheaf.is_sheaf_for {P : Cᵒᵖ ⥤ Type w} (hp : is_sheaf J P)
(R : presieve X) (hr : generate R ∈ J X) : is_sheaf_for P R :=
(is_sheaf_for_iff_generate R).2 $ hp _ hr
lemma is_sheaf_of_le (P : Cᵒᵖ ⥤ Type w) {J₁ J₂ : grothendieck_topology C} :
J₁ ≤ J₂ → is_sheaf J₂ P → is_sheaf J₁ P :=
λ h t X S hS, t S (h _ hS)
lemma is_separated_of_is_sheaf (P : Cᵒᵖ ⥤ Type w) (h : is_sheaf J P) : is_separated J P :=
λ X S hS, (h S hS).is_separated_for
/-- The property of being a sheaf is preserved by isomorphism. -/
lemma is_sheaf_iso {P' : Cᵒᵖ ⥤ Type w} (i : P ≅ P') (h : is_sheaf J P) : is_sheaf J P' :=
λ X S hS, is_sheaf_for_iso i (h S hS)
lemma is_sheaf_of_yoneda {P : Cᵒᵖ ⥤ Type v₁}
(h : ∀ {X} (S : sieve X), S ∈ J X → yoneda_sheaf_condition P S) : is_sheaf J P :=
λ X S hS, is_sheaf_for_iff_yoneda_sheaf_condition.2 (h _ hS)
/--
For a topology generated by a basis, it suffices to check the sheaf condition on the basis
presieves only.
-/
lemma is_sheaf_pretopology [has_pullbacks C] (K : pretopology C) :
is_sheaf (K.to_grothendieck C) P ↔ (∀ {X : C} (R : presieve X), R ∈ K X → is_sheaf_for P R) :=
begin
split,
{ intros PJ X R hR,
rw is_sheaf_for_iff_generate,
apply PJ (sieve.generate R) ⟨_, hR, le_generate R⟩ },
{ rintro PK X S ⟨R, hR, RS⟩,
have gRS : ⇑(generate R) ≤ S,
{ apply gi_generate.gc.monotone_u,
rwa sets_iff_generate },
apply is_sheaf_for_subsieve P gRS _,
intros Y f,
rw [← pullback_arrows_comm, ← is_sheaf_for_iff_generate],
exact PK (pullback_arrows f R) (K.pullbacks f R hR) }
end
/-- Any presheaf is a sheaf for the bottom (trivial) grothendieck topology. -/
lemma is_sheaf_bot : is_sheaf (⊥ : grothendieck_topology C) P :=
λ X, by simp [is_sheaf_for_top_sieve]
end presieve
namespace equalizer
variables {C : Type u₁} [category.{v₁} C] (P : Cᵒᵖ ⥤ Type (max v₁ u₁))
{X : C} (R : presieve X) (S : sieve X)
noncomputable theory
/--
The middle object of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram
of <https://stacks.math.columbia.edu/tag/00VM>.
-/
def first_obj : Type (max v₁ u₁) :=
∏ (λ (f : Σ Y, {f : Y ⟶ X // R f}), P.obj (op f.1))
/-- Show that `first_obj` is isomorphic to `family_of_elements`. -/
@[simps]
def first_obj_eq_family : first_obj P R ≅ R.family_of_elements P :=
{ hom := λ t Y f hf, pi.π (λ (f : Σ Y, {f : Y ⟶ X // R f}), P.obj (op f.1)) ⟨_, _, hf⟩ t,
inv := pi.lift (λ f x, x _ f.2.2),
hom_inv_id' :=
begin
ext ⟨Y, f, hf⟩ p,
simpa,
end,
inv_hom_id' :=
begin
ext x Y f hf,
apply limits.types.limit.lift_π_apply',
end }
instance : inhabited (first_obj P (⊥ : presieve X)) :=
((first_obj_eq_family P _).to_equiv).inhabited
/--
The left morphism of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram
of <https://stacks.math.columbia.edu/tag/00VM>.
-/
def fork_map : P.obj (op X) ⟶ first_obj P R :=
pi.lift (λ f, P.map f.2.1.op)
/-!
This section establishes the equivalence between the sheaf condition of Equation (3) [MM92] and
the definition of `is_sheaf_for`.
-/
namespace sieve
/--
The rightmost object of the fork diagram of Equation (3) [MM92], which contains the data used
to check a family is compatible.
-/
def second_obj : Type (max v₁ u₁) :=
∏ (λ (f : Σ Y Z (g : Z ⟶ Y), {f' : Y ⟶ X // S f'}), P.obj (op f.2.1))
/-- The map `p` of Equations (3,4) [MM92]. -/
def first_map : first_obj P S ⟶ second_obj P S :=
pi.lift (λ fg, pi.π _ (⟨_, _, S.downward_closed fg.2.2.2.2 fg.2.2.1⟩ : Σ Y, {f : Y ⟶ X // S f}))
instance : inhabited (second_obj P (⊥ : sieve X)) := ⟨first_map _ _ default⟩
/-- The map `a` of Equations (3,4) [MM92]. -/
def second_map : first_obj P S ⟶ second_obj P S :=
pi.lift (λ fg, pi.π _ ⟨_, fg.2.2.2⟩ ≫ P.map fg.2.2.1.op)
lemma w : fork_map P S ≫ first_map P S = fork_map P S ≫ second_map P S :=
begin
apply limit.hom_ext,
rintro ⟨Y, Z, g, f, hf⟩,
simp [first_map, second_map, fork_map],
end
/--
The family of elements given by `x : first_obj P S` is compatible iff `first_map` and `second_map`
map it to the same point.
-/
lemma compatible_iff (x : first_obj P S) :
((first_obj_eq_family P S).hom x).compatible ↔ first_map P S x = second_map P S x :=
begin
rw presieve.compatible_iff_sieve_compatible,
split,
{ intro t,
ext ⟨Y, Z, g, f, hf⟩,
simpa [first_map, second_map] using t _ g hf },
{ intros t Y Z f g hf,
rw types.limit_ext_iff' at t,
simpa [first_map, second_map] using t ⟨⟨Y, Z, g, f, hf⟩⟩ }
end
/-- `P` is a sheaf for `S`, iff the fork given by `w` is an equalizer. -/
lemma equalizer_sheaf_condition :
presieve.is_sheaf_for P S ↔ nonempty (is_limit (fork.of_ι _ (w P S))) :=
begin
rw [types.type_equalizer_iff_unique,
← equiv.forall_congr_left (first_obj_eq_family P S).to_equiv.symm],
simp_rw ← compatible_iff,
simp only [inv_hom_id_apply, iso.to_equiv_symm_fun],
apply ball_congr,
intros x tx,
apply exists_unique_congr,
intro t,
rw ← iso.to_equiv_symm_fun,
rw equiv.eq_symm_apply,
split,
{ intros q,
ext Y f hf,
simpa [first_obj_eq_family, fork_map] using q _ _ },
{ intros q Y f hf,
rw ← q,
simp [first_obj_eq_family, fork_map] }
end
end sieve
/-!
This section establishes the equivalence between the sheaf condition of
https://stacks.math.columbia.edu/tag/00VM and the definition of `is_sheaf_for`.
-/
namespace presieve
variables [has_pullbacks C]
/--
The rightmost object of the fork diagram of https://stacks.math.columbia.edu/tag/00VM, which
contains the data used to check a family of elements for a presieve is compatible.
-/
def second_obj : Type (max v₁ u₁) :=
∏ (λ (fg : (Σ Y, {f : Y ⟶ X // R f}) × (Σ Z, {g : Z ⟶ X // R g})),
P.obj (op (pullback fg.1.2.1 fg.2.2.1)))
/-- The map `pr₀*` of <https://stacks.math.columbia.edu/tag/00VL>. -/
def first_map : first_obj P R ⟶ second_obj P R :=
pi.lift (λ fg, pi.π _ _ ≫ P.map pullback.fst.op)
instance : inhabited (second_obj P (⊥ : presieve X)) := ⟨first_map _ _ default⟩
/-- The map `pr₁*` of <https://stacks.math.columbia.edu/tag/00VL>. -/
def second_map : first_obj P R ⟶ second_obj P R :=
pi.lift (λ fg, pi.π _ _ ≫ P.map pullback.snd.op)
lemma w : fork_map P R ≫ first_map P R = fork_map P R ≫ second_map P R :=
begin
apply limit.hom_ext,
rintro ⟨⟨Y, f, hf⟩, ⟨Z, g, hg⟩⟩,
simp only [first_map, second_map, fork_map],
simp only [limit.lift_π, limit.lift_π_assoc, assoc, fan.mk_π_app, subtype.coe_mk,
subtype.val_eq_coe],
rw [← P.map_comp, ← op_comp, pullback.condition],
simp,
end
/--
The family of elements given by `x : first_obj P S` is compatible iff `first_map` and `second_map`
map it to the same point.
-/
lemma compatible_iff (x : first_obj P R) :
((first_obj_eq_family P R).hom x).compatible ↔ first_map P R x = second_map P R x :=
begin
rw presieve.pullback_compatible_iff,
split,
{ intro t,
ext ⟨⟨Y, f, hf⟩, Z, g, hg⟩,
simpa [first_map, second_map] using t hf hg },
{ intros t Y Z f g hf hg,
rw types.limit_ext_iff' at t,
simpa [first_map, second_map] using t ⟨⟨⟨Y, f, hf⟩, Z, g, hg⟩⟩ }
end
/--
`P` is a sheaf for `R`, iff the fork given by `w` is an equalizer.
See <https://stacks.math.columbia.edu/tag/00VM>.
-/
lemma sheaf_condition :
R.is_sheaf_for P ↔ nonempty (is_limit (fork.of_ι _ (w P R))) :=
begin
rw types.type_equalizer_iff_unique,
erw ← equiv.forall_congr_left (first_obj_eq_family P R).to_equiv.symm,
simp_rw [← compatible_iff, ← iso.to_equiv_fun, equiv.apply_symm_apply],
apply ball_congr,
intros x hx,
apply exists_unique_congr,
intros t,
rw equiv.eq_symm_apply,
split,
{ intros q,
ext Y f hf,
simpa [fork_map] using q _ _ },
{ intros q Y f hf,
rw ← q,
simp [fork_map] }
end
end presieve
end equalizer
variables {C : Type u₁} [category.{v₁} C]
variables (J : grothendieck_topology C)
/-- The category of sheaves on a grothendieck topology. -/
structure SheafOfTypes (J : grothendieck_topology C) : Type (max u₁ v₁ (w+1)) :=
(val : Cᵒᵖ ⥤ Type w)
(cond : presieve.is_sheaf J val)
namespace SheafOfTypes
variable {J}
/-- Morphisms between sheaves of types are just morphisms between the underlying presheaves. -/
@[ext]
structure hom (X Y : SheafOfTypes J) :=
(val : X.val ⟶ Y.val)
@[simps]
instance : category (SheafOfTypes J) :=
{ hom := hom,
id := λ X, ⟨𝟙 _⟩,
comp := λ X Y Z f g, ⟨f.val ≫ g.val⟩,
id_comp' := λ X Y f, hom.ext _ _ $ id_comp _,
comp_id' := λ X Y f, hom.ext _ _ $ comp_id _,
assoc' := λ X Y Z W f g h, hom.ext _ _ $ assoc _ _ _ }
-- Let's make the inhabited linter happy...
instance (X : SheafOfTypes J) : inhabited (hom X X) := ⟨𝟙 X⟩
end SheafOfTypes
/-- The inclusion functor from sheaves to presheaves. -/
@[simps]
def SheafOfTypes_to_presheaf : SheafOfTypes J ⥤ (Cᵒᵖ ⥤ Type w) :=
{ obj := SheafOfTypes.val,
map := λ X Y f, f.val,
map_id' := λ X, rfl,
map_comp' := λ X Y Z f g, rfl }
instance : full (SheafOfTypes_to_presheaf J) := { preimage := λ X Y f, ⟨f⟩ }
instance : faithful (SheafOfTypes_to_presheaf J) := {}
/--
The category of sheaves on the bottom (trivial) grothendieck topology is equivalent to the category
of presheaves.
-/
@[simps]
def SheafOfTypes_bot_equiv : SheafOfTypes (⊥ : grothendieck_topology C) ≌ (Cᵒᵖ ⥤ Type w) :=
{ functor := SheafOfTypes_to_presheaf _,
inverse :=
{ obj := λ P, ⟨P, presieve.is_sheaf_bot⟩,
map := λ P₁ P₂ f, (SheafOfTypes_to_presheaf _).preimage f },
unit_iso :=
{ hom := { app := λ _, ⟨𝟙 _⟩ },
inv := { app := λ _, ⟨𝟙 _⟩ } },
counit_iso := iso.refl _ }
instance : inhabited (SheafOfTypes (⊥ : grothendieck_topology C)) :=
⟨SheafOfTypes_bot_equiv.inverse.obj ((functor.const _).obj punit)⟩
end category_theory
|
3c689dac776420656b32ca15f039a40f49dcd938 | ce89339993655da64b6ccb555c837ce6c10f9ef4 | /ukikagi/primes.lean | 064d404b2e7c4ac3927844ad6533cbb541d8b587 | [] | no_license | zeptometer/LearnLean | ef32dc36a22119f18d843f548d0bb42f907bff5d | bb84d5dbe521127ba134d4dbf9559b294a80b9f7 | refs/heads/master | 1,625,710,824,322 | 1,601,382,570,000 | 1,601,382,570,000 | 195,228,870 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,109 | lean |
definition is_prime (x: ℕ): Prop
:= 1 < x ∧ ∀ y: ℕ, y ∣ x → y = 1 ∨ y = x
definition factorial: ℕ → ℕ
| 0 := 1
| (nat.succ n) := nat.succ n * factorial n
lemma pos_factorial (n: ℕ):
factorial n > 0
:=
begin
induction n with k ih,
{
simp [factorial],
exact nat.succ_pos 0,
},
{
simp [factorial],
have hskpos: nat.succ k > 0, from nat.succ_pos k,
have h: nat.succ k * 0 < nat.succ k * factorial k, from mul_lt_mul_of_pos_left ih hskpos,
rw (mul_zero (nat.succ k)) at h,
exact h
}
end
lemma factorial_division (n: ℕ):
∀ m: ℕ, 1 ≤ m → m ≤ n → m ∣ factorial n
:=
begin
intros m h1 h2,
induction n with k h3,
have le10: 1 ≤ 0 := le_trans h1 h2,
exact absurd le10 (nat.not_succ_le_zero 0),
simp [factorial],
cases h2 with _ hlek,
{
simp
},
{
apply dvd_mul_of_dvd_right,
exact h3 hlek
}
end
lemma construct_prime (n: ℕ) (h: 1 < n):
∃ p: ℕ, is_prime p ∧ p ∣ n
:=
begin
let nontriv_factor := λx, 1 < x ∧ x ∣ n,
have h: ∃ x: ℕ, nontriv_factor x, by {
existsi n,
split,
exact h,
simp
},
let p := nat.find h,
let hp := nat.find_spec h,
have defprev: nat.find h = p, by simp,
rw [defprev] at hp,
cases hp with hpos hdvd,
existsi p,
split,
{
simp [is_prime],
split,
{
exact hpos,
},
{
intros y hyp,
cases lt_trichotomy 1 y with h1lty hrest,
{
right,
have hpley: p ≤ y, from (nat.find_min' h) (and.intro h1lty (dvd_trans hyp hdvd)),
have h0ltp: 0 < p, from lt_trans zero_lt_one hpos,
have hylep: y ≤ p, from (nat.le_of_dvd h0ltp hyp),
exact le_antisymm hylep hpley
},
cases hrest with h1eqy hylt1,
{
left,
exact h1eqy.symm
},
{
exfalso,
have hyeq0: y = 0, by {
apply nat.eq_zero_of_le_zero,
apply nat.le_of_lt_succ,
exact hylt1
},
rw hyeq0 at hyp,
have hpeq0: p = 0, from eq_zero_of_zero_dvd hyp,
have h1lt0: 1 < 0, by { rw hpeq0 at hpos, exact hpos },
exact nat.not_lt_zero 1 h1lt0,
}
}
},
{
exact hdvd
}
end
theorem unbouded_primes:
∀ m: ℕ, ∃ p: ℕ, is_prime p ∧ m < p :=
begin
intro m,
let a := factorial m + 1,
have h1lea: 1 < a, by {
simp [a],
refine nat.lt_add_of_pos_left _,
exact pos_factorial m
},
have h: ∃ p: ℕ, is_prime p ∧ p ∣ a, from construct_prime a h1lea,
cases h with p hp,
cases hp with hprime hpdvda,
existsi p,
split,
{
exact hprime
},
{
simp [is_prime] at hprime,
cases lt_or_ge m p with hmltp hmgep,
{
exact hmltp,
}, {
exfalso,
have h1ltp: 1 < p, from hprime.left,
have hdvdfm: p ∣ factorial m, from factorial_division m p (le_of_lt h1ltp) hmgep,
have hpdvd1: p ∣ 1, by {
refine (nat.dvd_add_iff_right hdvdfm).mpr hpdvda,
},
have hpeq1: p = 1, from nat.eq_one_of_dvd_one hpdvd1,
rw hpeq1 at h1ltp,
exact lt_irrefl 1 h1ltp
}
}
end
|
76d57fcea66c1954273cbd9e82dc44dbe7eb0217 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/category_theory/yoneda.lean | 08ba79c87e69c8b2c27940780a14fa49d8dca5f1 | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 7,487 | 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 category_theory.opposites
/-!
# The Yoneda embedding
The Yoneda embedding as a functor `yoneda : C ⥤ (Cᵒᵖ ⥤ Type v₁)`,
along with an instance that it is `fully_faithful`.
Also the Yoneda lemma, `yoneda_lemma : (yoneda_pairing C) ≅ (yoneda_evaluation C)`.
-/
namespace category_theory
open opposite
universes v₁ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
variables {C : Type u₁} [𝒞 : category.{v₁} C]
include 𝒞
def yoneda : C ⥤ (Cᵒᵖ ⥤ Sort v₁) :=
{ obj := λ X,
{ obj := λ Y, unop Y ⟶ X,
map := λ Y Y' f g, f.unop ≫ g,
map_comp' := λ _ _ _ f g, begin ext1, dsimp, erw [category.assoc] end,
map_id' := λ Y, begin ext1, dsimp, erw [category.id_comp] end },
map := λ X X' f, { app := λ Y g, g ≫ f } }
def coyoneda : Cᵒᵖ ⥤ (C ⥤ Sort v₁) :=
{ obj := λ X,
{ obj := λ Y, unop X ⟶ Y,
map := λ Y Y' f g, g ≫ f,
map_comp' := λ _ _ _ f g, begin ext1, dsimp, erw [category.assoc] end,
map_id' := λ Y, begin ext1, dsimp, erw [category.comp_id] end },
map := λ X X' f, { app := λ Y g, f.unop ≫ g },
map_comp' := λ _ _ _ f g, begin ext1, ext1, dsimp, erw [category.assoc] end,
map_id' := λ X, begin ext1, ext1, dsimp, erw [category.id_comp] end }
namespace yoneda
@[simp] lemma obj_obj (X : C) (Y : Cᵒᵖ) : (yoneda.obj X).obj Y = (unop Y ⟶ X) := rfl
@[simp] lemma obj_map (X : C) {Y Y' : Cᵒᵖ} (f : Y ⟶ Y') :
(yoneda.obj X).map f = λ g, f.unop ≫ g := rfl
@[simp] lemma map_app {X X' : C} (f : X ⟶ X') (Y : Cᵒᵖ) :
(yoneda.map f).app Y = λ g, g ≫ f := rfl
lemma obj_map_id {X Y : C} (f : op X ⟶ op Y) :
((@yoneda C _).obj X).map f (𝟙 X) = ((@yoneda C _).map f.unop).app (op Y) (𝟙 Y) :=
by obviously
@[simp] lemma naturality {X Y : C} (α : yoneda.obj X ⟶ yoneda.obj Y)
{Z Z' : C} (f : Z ⟶ Z') (h : Z' ⟶ X) : f ≫ α.app (op Z') h = α.app (op Z) (f ≫ h) :=
begin erw [functor_to_types.naturality], refl end
instance yoneda_full : full (@yoneda C _) :=
{ preimage := λ X Y f, (f.app (op X)) (𝟙 X) }
instance yoneda_faithful : faithful (@yoneda C _) :=
{ injectivity' := λ X Y f g p,
begin
injection p with h,
convert (congr_fun (congr_fun h (op X)) (𝟙 X)); dsimp; simp,
end }
/-- Extensionality via Yoneda. The typical usage would be
```
-- Goal is `X ≅ Y`
apply yoneda.ext,
-- Goals are now functions `(Z ⟶ X) → (Z ⟶ Y)`, `(Z ⟶ Y) → (Z ⟶ X)`, and the fact that these
functions are inverses and natural in `Z`.
```
-/
def ext (X Y : C)
(p : Π {Z : C}, (Z ⟶ X) → (Z ⟶ Y)) (q : Π {Z : C}, (Z ⟶ Y) → (Z ⟶ X))
(h₁ : Π {Z : C} (f : Z ⟶ X), q (p f) = f) (h₂ : Π {Z : C} (f : Z ⟶ Y), p (q f) = f)
(n : Π {Z Z' : C} (f : Z' ⟶ Z) (g : Z ⟶ X), p (f ≫ g) = f ≫ p g) : X ≅ Y :=
@preimage_iso _ _ _ _ yoneda _ _ _ _
(nat_iso.of_components (λ Z, { hom := p, inv := q, }) (by tidy))
def is_iso {X Y : C} (f : X ⟶ Y) [is_iso (yoneda.map f)] : is_iso f :=
is_iso_of_fully_faithful yoneda f
end yoneda
namespace coyoneda
@[simp] lemma obj_obj (X : Cᵒᵖ) (Y : C) : (coyoneda.obj X).obj Y = (unop X ⟶ Y) := rfl
@[simp] lemma obj_map {X' X : C} (f : X' ⟶ X) (Y : Cᵒᵖ) :
(coyoneda.obj Y).map f = λ g, g ≫ f := rfl
@[simp] lemma map_app (X : C) {Y Y' : Cᵒᵖ} (f : Y ⟶ Y') :
(coyoneda.map f).app X = λ g, f.unop ≫ g := rfl
@[simp] lemma naturality {X Y : Cᵒᵖ} (α : coyoneda.obj X ⟶ coyoneda.obj Y)
{Z Z' : C} (f : Z' ⟶ Z) (h : unop X ⟶ Z') : (α.app Z' h) ≫ f = α.app Z (h ≫ f) :=
begin erw [functor_to_types.naturality], refl end
instance coyoneda_full : full (@coyoneda C _) :=
{ preimage := λ X Y f, ((f.app (unop X)) (𝟙 _)).op }
instance coyoneda_faithful : faithful (@coyoneda C _) :=
{ injectivity' := λ X Y f g p,
begin
injection p with h,
have t := (congr_fun (congr_fun h (unop X)) (𝟙 _)),
simpa using congr_arg has_hom.hom.op t,
end }
def is_iso {X Y : Cᵒᵖ} (f : X ⟶ Y) [is_iso (coyoneda.map f)] : is_iso f :=
is_iso_of_fully_faithful coyoneda f
end coyoneda
class representable (F : Cᵒᵖ ⥤ Sort v₁) :=
(X : C)
(w : yoneda.obj X ≅ F)
end category_theory
namespace category_theory
-- For the rest of the file, we are using product categories,
-- so need to restrict to the case morphisms are in 'Type', not 'Sort'.
universes v₁ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
open opposite
variables (C : Type u₁) [𝒞 : category.{v₁+1} C]
include 𝒞
-- We need to help typeclass inference with some awkward universe levels here.
instance prod_category_instance_1 : category ((Cᵒᵖ ⥤ Type v₁) × Cᵒᵖ) :=
category_theory.prod.{(max u₁ v₁) v₁} (Cᵒᵖ ⥤ Type v₁) Cᵒᵖ
instance prod_category_instance_2 : category (Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) :=
category_theory.prod.{v₁ (max u₁ v₁)} Cᵒᵖ (Cᵒᵖ ⥤ Type v₁)
open yoneda
def yoneda_evaluation : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁) ⥤ Type (max u₁ v₁) :=
evaluation_uncurried Cᵒᵖ (Type v₁) ⋙ ulift_functor.{u₁}
@[simp] lemma yoneda_evaluation_map_down
(P Q : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q) (x : (yoneda_evaluation C).obj P) :
((yoneda_evaluation C).map α x).down = α.2.app Q.1 (P.2.map α.1 x.down) := rfl
def yoneda_pairing : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁) ⥤ Type (max u₁ v₁) :=
functor.prod yoneda.op (functor.id (Cᵒᵖ ⥤ Type v₁)) ⋙ functor.hom (Cᵒᵖ ⥤ Type v₁)
@[simp] lemma yoneda_pairing_map
(P Q : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q) (β : (yoneda_pairing C).obj P) :
(yoneda_pairing C).map α β = yoneda.map α.1.unop ≫ β ≫ α.2 := rfl
def yoneda_lemma : yoneda_pairing C ≅ yoneda_evaluation C :=
{ hom :=
{ app := λ F x, ulift.up ((x.app F.1) (𝟙 (unop F.1))),
naturality' :=
begin
intros X Y f, ext1, ext1,
cases f, cases Y, cases X,
dsimp,
erw [category.id_comp,
←functor_to_types.naturality,
obj_map_id,
functor_to_types.naturality,
functor_to_types.map_id]
end },
inv :=
{ app := λ F x,
{ app := λ X a, (F.2.map a.op) x.down,
naturality' :=
begin
intros X Y f, ext1,
cases x, cases F,
dsimp,
erw [functor_to_types.map_comp]
end },
naturality' :=
begin
intros X Y f, ext1, ext1, ext1,
cases x, cases f, cases Y, cases X,
dsimp,
erw [←functor_to_types.naturality, functor_to_types.map_comp]
end },
hom_inv_id' :=
begin
ext1, ext1, ext1, ext1, cases X, dsimp,
erw [←functor_to_types.naturality,
obj_map_id,
functor_to_types.naturality,
functor_to_types.map_id],
refl,
end,
inv_hom_id' :=
begin
ext1, ext1, ext1,
cases x, cases X,
dsimp,
erw [functor_to_types.map_id]
end }.
variables {C}
@[simp] def yoneda_sections (X : C) (F : Cᵒᵖ ⥤ Type v₁) : (yoneda.obj X ⟶ F) ≅ ulift.{u₁} (F.obj (op X)) :=
(yoneda_lemma C).app (op X, F)
omit 𝒞
@[simp] def yoneda_sections_small {C : Type u₁} [small_category C] (X : C) (F : Cᵒᵖ ⥤ Type u₁) : (yoneda.obj X ⟶ F) ≅ F.obj (op X) :=
yoneda_sections X F ≪≫ ulift_trivial _
end category_theory
|
40eab414f4687f32774a2f0428315c06d2048b50 | 5fbbd711f9bfc21ee168f46a4be146603ece8835 | /lean/natural_number_game/advanced_proposition/06.lean | cb1beba6ffe1c10a8a22154abd2edca4bdfffb96 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | goedel-gang/maths | 22596f71e3fde9c088e59931f128a3b5efb73a2c | a20a6f6a8ce800427afd595c598a5ad43da1408d | refs/heads/master | 1,623,055,941,960 | 1,621,599,441,000 | 1,621,599,441,000 | 169,335,840 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 78 | lean | example (P Q : Prop) : Q → (P ∨ Q) :=
begin
intro q,
right,
cc,
end
|
1edf717dfc013935a47ec8403a78adf3f0b9b891 | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /hott/init/path.hlean | 9aee355763f412143773922968ac8c09ff3a69eb | [
"Apache-2.0"
] | permissive | tjiaqi/lean | 4634d729795c164664d10d093f3545287c76628f | d0ce4cf62f4246b0600c07e074d86e51f2195e30 | refs/heads/master | 1,622,323,796,480 | 1,422,643,069,000 | 1,422,643,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,408 | hlean | -- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Jeremy Avigad, Jakob von Raumer
-- Ported from Coq HoTT
--
-- TODO: things to test:
-- o To what extent can we use opaque definitions outside the file?
-- o Try doing these proofs with tactics.
-- o Try using the simplifier on some of these proofs.
prelude
import .function .datatypes .relation .tactic
open function eq
-- Path equality
-- ---- --------
namespace eq
variables {A B C : Type} {P : A → Type} {x y z t : A}
--notation a = b := eq a b
notation x = y `:>`:50 A:49 := @eq A x y
definition idp {a : A} := refl a
-- unbased path induction
definition rec' [reducible] {P : Π (a b : A), (a = b) -> Type}
(H : Π (a : A), P a a idp) {a b : A} (p : a = b) : P a b p :=
eq.rec (H a) p
definition rec_on' [reducible] {P : Π (a b : A), (a = b) -> Type} {a b : A} (p : a = b)
(H : Π (a : A), P a a idp) : P a b p :=
eq.rec (H a) p
-- Concatenation and inverse
-- -------------------------
definition concat (p : x = y) (q : y = z) : x = z :=
eq.rec (λu, u) q p
definition inverse (p : x = y) : y = x :=
eq.rec (refl x) p
notation p₁ ⬝ p₂ := concat p₁ p₂
notation p ⁻¹ := inverse p
-- The 1-dimensional groupoid structure
-- ------------------------------------
-- The identity path is a right unit.
definition concat_p1 (p : x = y) : p ⬝ idp = p :=
rec_on p idp
-- The identity path is a right unit.
definition concat_1p (p : x = y) : idp ⬝ p = p :=
rec_on p idp
-- Concatenation is associative.
definition concat_p_pp (p : x = y) (q : y = z) (r : z = t) :
p ⬝ (q ⬝ r) = (p ⬝ q) ⬝ r :=
rec_on r (rec_on q idp)
definition concat_pp_p (p : x = y) (q : y = z) (r : z = t) :
(p ⬝ q) ⬝ r = p ⬝ (q ⬝ r) :=
rec_on r (rec_on q idp)
-- The left inverse law.
definition concat_pV (p : x = y) : p ⬝ p⁻¹ = idp :=
rec_on p idp
-- The right inverse law.
definition concat_Vp (p : x = y) : p⁻¹ ⬝ p = idp :=
rec_on p idp
-- Several auxiliary theorems about canceling inverses across associativity. These are somewhat
-- redundant, following from earlier theorems.
definition concat_V_pp (p : x = y) (q : y = z) : p⁻¹ ⬝ (p ⬝ q) = q :=
rec_on q (rec_on p idp)
definition concat_p_Vp (p : x = y) (q : x = z) : p ⬝ (p⁻¹ ⬝ q) = q :=
rec_on q (rec_on p idp)
definition concat_pp_V (p : x = y) (q : y = z) : (p ⬝ q) ⬝ q⁻¹ = p :=
rec_on q (rec_on p idp)
definition concat_pV_p (p : x = z) (q : y = z) : (p ⬝ q⁻¹) ⬝ q = p :=
rec_on q (take p, rec_on p idp) p
-- Inverse distributes over concatenation
definition inv_pp (p : x = y) (q : y = z) : (p ⬝ q)⁻¹ = q⁻¹ ⬝ p⁻¹ :=
rec_on q (rec_on p idp)
definition inv_Vp (p : y = x) (q : y = z) : (p⁻¹ ⬝ q)⁻¹ = q⁻¹ ⬝ p :=
rec_on q (rec_on p idp)
-- universe metavariables
definition inv_pV (p : x = y) (q : z = y) : (p ⬝ q⁻¹)⁻¹ = q ⬝ p⁻¹ :=
rec_on p (take q, rec_on q idp) q
definition inv_VV (p : y = x) (q : z = y) : (p⁻¹ ⬝ q⁻¹)⁻¹ = q ⬝ p :=
rec_on p (rec_on q idp)
-- Inverse is an involution.
definition inv_V (p : x = y) : p⁻¹⁻¹ = p :=
rec_on p idp
-- Theorems for moving things around in equations
-- ----------------------------------------------
definition moveR_Mp (p : x = z) (q : y = z) (r : y = x) :
p = (r⁻¹ ⬝ q) → (r ⬝ p) = q :=
rec_on r (take p h, concat_1p _ ⬝ h ⬝ concat_1p _) p
definition moveR_pM (p : x = z) (q : y = z) (r : y = x) :
r = q ⬝ p⁻¹ → r ⬝ p = q :=
rec_on p (take q h, (concat_p1 _ ⬝ h ⬝ concat_p1 _)) q
definition moveR_Vp (p : x = z) (q : y = z) (r : x = y) :
p = r ⬝ q → r⁻¹ ⬝ p = q :=
rec_on r (take q h, concat_1p _ ⬝ h ⬝ concat_1p _) q
definition moveR_pV (p : z = x) (q : y = z) (r : y = x) :
r = q ⬝ p → r ⬝ p⁻¹ = q :=
rec_on p (take r h, concat_p1 _ ⬝ h ⬝ concat_p1 _) r
definition moveL_Mp (p : x = z) (q : y = z) (r : y = x) :
r⁻¹ ⬝ q = p → q = r ⬝ p :=
rec_on r (take p h, (concat_1p _)⁻¹ ⬝ h ⬝ (concat_1p _)⁻¹) p
definition moveL_pM (p : x = z) (q : y = z) (r : y = x) :
q ⬝ p⁻¹ = r → q = r ⬝ p :=
rec_on p (take q h, (concat_p1 _)⁻¹ ⬝ h ⬝ (concat_p1 _)⁻¹) q
definition moveL_Vp (p : x = z) (q : y = z) (r : x = y) :
r ⬝ q = p → q = r⁻¹ ⬝ p :=
rec_on r (take q h, (concat_1p _)⁻¹ ⬝ h ⬝ (concat_1p _)⁻¹) q
definition moveL_pV (p : z = x) (q : y = z) (r : y = x) :
q ⬝ p = r → q = r ⬝ p⁻¹ :=
rec_on p (take r h, (concat_p1 _)⁻¹ ⬝ h ⬝ (concat_p1 _)⁻¹) r
definition moveL_1M (p q : x = y) :
p ⬝ q⁻¹ = idp → p = q :=
rec_on q (take p h, (concat_p1 _)⁻¹ ⬝ h) p
definition moveL_M1 (p q : x = y) :
q⁻¹ ⬝ p = idp → p = q :=
rec_on q (take p h, (concat_1p _)⁻¹ ⬝ h) p
definition moveL_1V (p : x = y) (q : y = x) :
p ⬝ q = idp → p = q⁻¹ :=
rec_on q (take p h, (concat_p1 _)⁻¹ ⬝ h) p
definition moveL_V1 (p : x = y) (q : y = x) :
q ⬝ p = idp → p = q⁻¹ :=
rec_on q (take p h, (concat_1p _)⁻¹ ⬝ h) p
definition moveR_M1 (p q : x = y) :
idp = p⁻¹ ⬝ q → p = q :=
rec_on p (take q h, h ⬝ (concat_1p _)) q
definition moveR_1M (p q : x = y) :
idp = q ⬝ p⁻¹ → p = q :=
rec_on p (take q h, h ⬝ (concat_p1 _)) q
definition moveR_1V (p : x = y) (q : y = x) :
idp = q ⬝ p → p⁻¹ = q :=
rec_on p (take q h, h ⬝ (concat_p1 _)) q
definition moveR_V1 (p : x = y) (q : y = x) :
idp = p ⬝ q → p⁻¹ = q :=
rec_on p (take q h, h ⬝ (concat_1p _)) q
-- Transport
-- ---------
definition transport [reducible] (P : A → Type) {x y : A} (p : x = y) (u : P x) : P y :=
eq.rec_on p u
-- This idiom makes the operation right associative.
notation p `▹`:65 x:64 := transport _ p x
definition ap ⦃A B : Type⦄ (f : A → B) {x y:A} (p : x = y) : f x = f y :=
eq.rec_on p idp
definition ap01 := ap
definition homotopy [reducible] (f g : Πx, P x) : Type :=
Πx : A, f x = g x
notation f ∼ g := homotopy f g
definition apD10 {f g : Πx, P x} (H : f = g) : f ∼ g :=
λx, eq.rec_on H idp
definition ap10 {f g : A → B} (H : f = g) : f ∼ g := apD10 H
definition ap11 {f g : A → B} (H : f = g) {x y : A} (p : x = y) : f x = g y :=
rec_on H (rec_on p idp)
definition apD (f : Πa:A, P a) {x y : A} (p : x = y) : p ▹ (f x) = f y :=
rec_on p idp
-- calc enviroment
-- ---------------
calc_subst transport
calc_trans concat
calc_refl refl
calc_symm inverse
-- More theorems for moving things around in equations
-- ---------------------------------------------------
definition moveR_transport_p (P : A → Type) {x y : A} (p : x = y) (u : P x) (v : P y) :
u = p⁻¹ ▹ v → p ▹ u = v :=
rec_on p (take v, id) v
definition moveR_transport_V (P : A → Type) {x y : A} (p : y = x) (u : P x) (v : P y) :
u = p ▹ v → p⁻¹ ▹ u = v :=
rec_on p (take u, id) u
definition moveL_transport_V (P : A → Type) {x y : A} (p : x = y) (u : P x) (v : P y) :
p ▹ u = v → u = p⁻¹ ▹ v :=
rec_on p (take v, id) v
definition moveL_transport_p (P : A → Type) {x y : A} (p : y = x) (u : P x) (v : P y) :
p⁻¹ ▹ u = v → u = p ▹ v :=
rec_on p (take u, id) u
-- Functoriality of functions
-- --------------------------
-- Here we prove that functions behave like functors between groupoids, and that [ap] itself is
-- functorial.
-- Functions take identity paths to identity paths
definition ap_1 (x : A) (f : A → B) : (ap f idp) = idp :> (f x = f x) := idp
definition apD_1 (x : A) (f : Π x : A, P x) : apD f idp = idp :> (f x = f x) := idp
-- Functions commute with concatenation.
definition ap_pp (f : A → B) {x y z : A} (p : x = y) (q : y = z) :
ap f (p ⬝ q) = (ap f p) ⬝ (ap f q) :=
rec_on q (rec_on p idp)
definition ap_p_pp (f : A → B) {w x y z : A} (r : f w = f x) (p : x = y) (q : y = z) :
r ⬝ (ap f (p ⬝ q)) = (r ⬝ ap f p) ⬝ (ap f q) :=
rec_on q (take p, rec_on p (concat_p_pp r idp idp)) p
definition ap_pp_p (f : A → B) {w x y z : A} (p : x = y) (q : y = z) (r : f z = f w) :
(ap f (p ⬝ q)) ⬝ r = (ap f p) ⬝ (ap f q ⬝ r) :=
rec_on q (rec_on p (take r, concat_pp_p _ _ _)) r
-- Functions commute with path inverses.
definition inverse_ap (f : A → B) {x y : A} (p : x = y) : (ap f p)⁻¹ = ap f (p⁻¹) :=
rec_on p idp
definition ap_V {A B : Type} (f : A → B) {x y : A} (p : x = y) : ap f (p⁻¹) = (ap f p)⁻¹ :=
rec_on p idp
-- [ap] itself is functorial in the first argument.
definition ap_idmap (p : x = y) : ap id p = p :=
rec_on p idp
definition ap_compose (f : A → B) (g : B → C) {x y : A} (p : x = y) :
ap (g ∘ f) p = ap g (ap f p) :=
rec_on p idp
-- Sometimes we don't have the actual function [compose].
definition ap_compose' (f : A → B) (g : B → C) {x y : A} (p : x = y) :
ap (λa, g (f a)) p = ap g (ap f p) :=
rec_on p idp
-- The action of constant maps.
definition ap_const (p : x = y) (z : B) :
ap (λu, z) p = idp :=
rec_on p idp
-- Naturality of [ap].
definition concat_Ap {f g : A → B} (p : Π x, f x = g x) {x y : A} (q : x = y) :
(ap f q) ⬝ (p y) = (p x) ⬝ (ap g q) :=
rec_on q (concat_1p _ ⬝ (concat_p1 _)⁻¹)
-- Naturality of [ap] at identity.
definition concat_A1p {f : A → A} (p : Πx, f x = x) {x y : A} (q : x = y) :
(ap f q) ⬝ (p y) = (p x) ⬝ q :=
rec_on q (concat_1p _ ⬝ (concat_p1 _)⁻¹)
definition concat_pA1 {f : A → A} (p : Πx, x = f x) {x y : A} (q : x = y) :
(p x) ⬝ (ap f q) = q ⬝ (p y) :=
rec_on q (concat_p1 _ ⬝ (concat_1p _)⁻¹)
-- Naturality with other paths hanging around.
definition concat_pA_pp {f g : A → B} (p : Πx, f x = g x) {x y : A} (q : x = y)
{w z : B} (r : w = f x) (s : g y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (ap g q ⬝ s) :=
rec_on s (rec_on q idp)
definition concat_pA_p {f g : A → B} (p : Πx, f x = g x) {x y : A} (q : x = y)
{w : B} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ ap g q :=
rec_on q idp
-- TODO: try this using the simplifier, and compare proofs
definition concat_A_pp {f g : A → B} (p : Πx, f x = g x) {x y : A} (q : x = y)
{z : B} (s : g y = z) :
(ap f q) ⬝ (p y ⬝ s) = (p x) ⬝ (ap g q ⬝ s) :=
rec_on s (rec_on q
(calc
(ap f idp) ⬝ (p x ⬝ idp) = idp ⬝ p x : idp
... = p x : concat_1p _
... = (p x) ⬝ (ap g idp ⬝ idp) : idp))
-- This also works:
-- rec_on s (rec_on q (concat_1p _ ▹ idp))
definition concat_pA1_pp {f : A → A} (p : Πx, f x = x) {x y : A} (q : x = y)
{w z : A} (r : w = f x) (s : y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (q ⬝ s) :=
rec_on s (rec_on q idp)
definition concat_pp_A1p {g : A → A} (p : Πx, x = g x) {x y : A} (q : x = y)
{w z : A} (r : w = x) (s : g y = z) :
(r ⬝ p x) ⬝ (ap g q ⬝ s) = (r ⬝ q) ⬝ (p y ⬝ s) :=
rec_on s (rec_on q idp)
definition concat_pA1_p {f : A → A} (p : Πx, f x = x) {x y : A} (q : x = y)
{w : A} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ q :=
rec_on q idp
definition concat_A1_pp {f : A → A} (p : Πx, f x = x) {x y : A} (q : x = y)
{z : A} (s : y = z) :
(ap f q) ⬝ (p y ⬝ s) = (p x) ⬝ (q ⬝ s) :=
rec_on s (rec_on q (concat_1p _ ▹ idp))
definition concat_pp_A1 {g : A → A} (p : Πx, x = g x) {x y : A} (q : x = y)
{w : A} (r : w = x) :
(r ⬝ p x) ⬝ ap g q = (r ⬝ q) ⬝ p y :=
rec_on q idp
definition concat_p_A1p {g : A → A} (p : Πx, x = g x) {x y : A} (q : x = y)
{z : A} (s : g y = z) :
p x ⬝ (ap g q ⬝ s) = q ⬝ (p y ⬝ s) :=
begin
apply (rec_on s),
apply (rec_on q),
apply (concat_1p (p x) ▹ idp)
end
-- Action of [apD10] and [ap10] on paths
-- -------------------------------------
-- Application of paths between functions preserves the groupoid structure
definition apD10_1 (f : Πx, P x) (x : A) : apD10 (refl f) x = idp := idp
definition apD10_pp {f f' f'' : Πx, P x} (h : f = f') (h' : f' = f'') (x : A) :
apD10 (h ⬝ h') x = apD10 h x ⬝ apD10 h' x :=
rec_on h (take h', rec_on h' idp) h'
definition apD10_V {f g : Πx : A, P x} (h : f = g) (x : A) :
apD10 (h⁻¹) x = (apD10 h x)⁻¹ :=
rec_on h idp
definition ap10_1 {f : A → B} (x : A) : ap10 (refl f) x = idp := idp
definition ap10_pp {f f' f'' : A → B} (h : f = f') (h' : f' = f'') (x : A) :
ap10 (h ⬝ h') x = ap10 h x ⬝ ap10 h' x := apD10_pp h h' x
definition ap10_V {f g : A → B} (h : f = g) (x : A) : ap10 (h⁻¹) x = (ap10 h x)⁻¹ :=
apD10_V h x
-- [ap10] also behaves nicely on paths produced by [ap]
definition ap_ap10 (f g : A → B) (h : B → C) (p : f = g) (a : A) :
ap h (ap10 p a) = ap10 (ap (λ f', h ∘ f') p) a:=
rec_on p idp
-- Transport and the groupoid structure of paths
-- ---------------------------------------------
definition transport_1 (P : A → Type) {x : A} (u : P x) :
idp ▹ u = u := idp
definition transport_pp (P : A → Type) {x y z : A} (p : x = y) (q : y = z) (u : P x) :
p ⬝ q ▹ u = q ▹ p ▹ u :=
rec_on q (rec_on p idp)
definition transport_pV (P : A → Type) {x y : A} (p : x = y) (z : P y) :
p ▹ p⁻¹ ▹ z = z :=
(transport_pp P (p⁻¹) p z)⁻¹ ⬝ ap (λr, transport P r z) (concat_Vp p)
definition transport_Vp (P : A → Type) {x y : A} (p : x = y) (z : P x) :
p⁻¹ ▹ p ▹ z = z :=
(transport_pp P p (p⁻¹) z)⁻¹ ⬝ ap (λr, transport P r z) (concat_pV p)
definition transport_p_pp (P : A → Type)
{x y z w : A} (p : x = y) (q : y = z) (r : z = w) (u : P x) :
ap (λe, e ▹ u) (concat_p_pp p q r) ⬝ (transport_pp P (p ⬝ q) r u) ⬝
ap (transport P r) (transport_pp P p q u)
= (transport_pp P p (q ⬝ r) u) ⬝ (transport_pp P q r (p ▹ u))
:> ((p ⬝ (q ⬝ r)) ▹ u = r ▹ q ▹ p ▹ u) :=
rec_on r (rec_on q (rec_on p idp))
-- Here is another coherence lemma for transport.
definition transport_pVp (P : A → Type) {x y : A} (p : x = y) (z : P x) :
transport_pV P p (transport P p z) = ap (transport P p) (transport_Vp P p z) :=
rec_on p idp
-- Dependent transport in a doubly dependent type.
-- should P, Q and y all be explicit here?
definition transportD (P : A → Type) (Q : Π a : A, P a → Type)
{a a' : A} (p : a = a') (b : P a) (z : Q a b) : Q a' (p ▹ b) :=
rec_on p z
-- In Coq the variables B, C and y are explicit, but in Lean we can probably have them implicit using the following notation
notation p `▹D`:65 x:64 := transportD _ _ p _ x
-- Transporting along higher-dimensional paths
definition transport2 (P : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : P x) :
p ▹ z = q ▹ z :=
ap (λp', p' ▹ z) r
notation p `▹2`:65 x:64 := transport2 _ p _ x
-- An alternative definition.
definition transport2_is_ap10 (Q : A → Type) {x y : A} {p q : x = y} (r : p = q)
(z : Q x) :
transport2 Q r z = ap10 (ap (transport Q) r) z :=
rec_on r idp
definition transport2_p2p (P : A → Type) {x y : A} {p1 p2 p3 : x = y}
(r1 : p1 = p2) (r2 : p2 = p3) (z : P x) :
transport2 P (r1 ⬝ r2) z = transport2 P r1 z ⬝ transport2 P r2 z :=
rec_on r1 (rec_on r2 idp)
definition transport2_V (Q : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : Q x) :
transport2 Q (r⁻¹) z = ((transport2 Q r z)⁻¹) :=
rec_on r idp
definition transportD2 (B C : A → Type) (D : Π(a:A), B a → C a → Type)
{x1 x2 : A} (p : x1 = x2) (y : B x1) (z : C x1) (w : D x1 y z) : D x2 (p ▹ y) (p ▹ z) :=
rec_on p w
notation p `▹D2`:65 x:64 := transportD2 _ _ _ p _ _ x
definition concat_AT (P : A → Type) {x y : A} {p q : x = y} {z w : P x} (r : p = q)
(s : z = w) :
ap (transport P p) s ⬝ transport2 P r w = transport2 P r z ⬝ ap (transport P q) s :=
rec_on r (concat_p1 _ ⬝ (concat_1p _)⁻¹)
-- TODO (from Coq library): What should this be called?
definition ap_transport {P Q : A → Type} {x y : A} (p : x = y) (f : Πx, P x → Q x) (z : P x) :
f y (p ▹ z) = (p ▹ (f x z)) :=
rec_on p idp
-- Transporting in particular fibrations
-- -------------------------------------
/-
From the Coq HoTT library:
One frequently needs lemmas showing that transport in a certain dependent type is equal to some
more explicitly defined operation, defined according to the structure of that dependent type.
For most dependent types, we prove these lemmas in the appropriate file in the types/
subdirectory. Here we consider only the most basic cases.
-/
-- Transporting in a constant fibration.
definition transport_const (p : x = y) (z : B) : transport (λx, B) p z = z :=
rec_on p idp
definition transport2_const {p q : x = y} (r : p = q) (z : B) :
transport_const p z = transport2 (λu, B) r z ⬝ transport_const q z :=
rec_on r (concat_1p _)⁻¹
-- Transporting in a pulled back fibration.
-- TODO: P can probably be implicit
definition transport_compose (P : B → Type) (f : A → B) (p : x = y) (z : P (f x)) :
transport (P ∘ f) p z = transport P (ap f p) z :=
rec_on p idp
definition transport_precompose (f : A → B) (g g' : B → C) (p : g = g') :
transport (λh : B → C, g ∘ f = h ∘ f) p idp = ap (λh, h ∘ f) p :=
rec_on p idp
definition apD10_ap_precompose (f : A → B) (g g' : B → C) (p : g = g') (a : A) :
apD10 (ap (λh : B → C, h ∘ f) p) a = apD10 p (f a) :=
rec_on p idp
definition apD10_ap_postcompose (f : B → C) (g g' : A → B) (p : g = g') (a : A) :
apD10 (ap (λh : A → B, f ∘ h) p) a = ap f (apD10 p a) :=
rec_on p idp
-- A special case of [transport_compose] which seems to come up a lot.
definition transport_idmap_ap (P : A → Type) x y (p : x = y) (u : P x) :
transport P p u = transport (λz, z) (ap P p) u :=
rec_on p idp
-- The behavior of [ap] and [apD]
-- ------------------------------
-- In a constant fibration, [apD] reduces to [ap], modulo [transport_const].
definition apD_const (f : A → B) (p: x = y) :
apD f p = transport_const p (f x) ⬝ ap f p :=
rec_on p idp
-- The 2-dimensional groupoid structure
-- ------------------------------------
-- Horizontal composition of 2-dimensional paths.
definition concat2 {p p' : x = y} {q q' : y = z} (h : p = p') (h' : q = q') :
p ⬝ q = p' ⬝ q' :=
rec_on h (rec_on h' idp)
infixl `◾`:75 := concat2
-- 2-dimensional path inversion
definition inverse2 {p q : x = y} (h : p = q) : p⁻¹ = q⁻¹ :=
rec_on h idp
-- Whiskering
-- ----------
definition whiskerL (p : x = y) {q r : y = z} (h : q = r) : p ⬝ q = p ⬝ r :=
idp ◾ h
definition whiskerR {p q : x = y} (h : p = q) (r : y = z) : p ⬝ r = q ⬝ r :=
h ◾ idp
-- Unwhiskering, a.k.a. cancelling
definition cancelL {x y z : A} (p : x = y) (q r : y = z) : (p ⬝ q = p ⬝ r) → (q = r) :=
rec_on p (take r, rec_on r (take q a, (concat_1p q)⁻¹ ⬝ a)) r q
definition cancelR {x y z : A} (p q : x = y) (r : y = z) : (p ⬝ r = q ⬝ r) → (p = q) :=
rec_on r (rec_on p (take q a, a ⬝ concat_p1 q)) q
-- Whiskering and identity paths.
definition whiskerR_p1 {p q : x = y} (h : p = q) :
(concat_p1 p)⁻¹ ⬝ whiskerR h idp ⬝ concat_p1 q = h :=
rec_on h (rec_on p idp)
definition whiskerR_1p (p : x = y) (q : y = z) :
whiskerR idp q = idp :> (p ⬝ q = p ⬝ q) :=
rec_on q idp
definition whiskerL_p1 (p : x = y) (q : y = z) :
whiskerL p idp = idp :> (p ⬝ q = p ⬝ q) :=
rec_on q idp
definition whiskerL_1p {p q : x = y} (h : p = q) :
(concat_1p p) ⁻¹ ⬝ whiskerL idp h ⬝ concat_1p q = h :=
rec_on h (rec_on p idp)
definition concat2_p1 {p q : x = y} (h : p = q) :
h ◾ idp = whiskerR h idp :> (p ⬝ idp = q ⬝ idp) :=
rec_on h idp
definition concat2_1p {p q : x = y} (h : p = q) :
idp ◾ h = whiskerL idp h :> (idp ⬝ p = idp ⬝ q) :=
rec_on h idp
-- TODO: note, 4 inductions
-- The interchange law for concatenation.
definition concat_concat2 {p p' p'' : x = y} {q q' q'' : y = z}
(a : p = p') (b : p' = p'') (c : q = q') (d : q' = q'') :
(a ◾ c) ⬝ (b ◾ d) = (a ⬝ b) ◾ (c ⬝ d) :=
rec_on d (rec_on c (rec_on b (rec_on a idp)))
definition concat_whisker {x y z : A} (p p' : x = y) (q q' : y = z) (a : p = p') (b : q = q') :
(whiskerR a q) ⬝ (whiskerL p' b) = (whiskerL p b) ⬝ (whiskerR a q') :=
rec_on b (rec_on a (concat_1p _)⁻¹)
-- Structure corresponding to the coherence equations of a bicategory.
-- The "pentagonator": the 3-cell witnessing the associativity pentagon.
definition pentagon {v w x y z : A} (p : v = w) (q : w = x) (r : x = y) (s : y = z) :
whiskerL p (concat_p_pp q r s)
⬝ concat_p_pp p (q ⬝ r) s
⬝ whiskerR (concat_p_pp p q r) s
= concat_p_pp p q (r ⬝ s) ⬝ concat_p_pp (p ⬝ q) r s :=
rec_on s (rec_on r (rec_on q (rec_on p idp)))
-- The 3-cell witnessing the left unit triangle.
definition triangulator (p : x = y) (q : y = z) :
concat_p_pp p idp q ⬝ whiskerR (concat_p1 p) q = whiskerL p (concat_1p q) :=
rec_on q (rec_on p idp)
definition eckmann_hilton {x:A} (p q : idp = idp :> (x = x)) : p ⬝ q = q ⬝ p :=
(!whiskerR_p1 ◾ !whiskerL_1p)⁻¹
⬝ (!concat_p1 ◾ !concat_p1)
⬝ (!concat_1p ◾ !concat_1p)
⬝ !concat_whisker
⬝ (!concat_1p ◾ !concat_1p)⁻¹
⬝ (!concat_p1 ◾ !concat_p1)⁻¹
⬝ (!whiskerL_1p ◾ !whiskerR_p1)
-- The action of functions on 2-dimensional paths
definition ap02 (f:A → B) {x y : A} {p q : x = y} (r : p = q) : ap f p = ap f q :=
rec_on r idp
definition ap02_pp (f : A → B) {x y : A} {p p' p'' : x = y} (r : p = p') (r' : p' = p'') :
ap02 f (r ⬝ r') = ap02 f r ⬝ ap02 f r' :=
rec_on r (rec_on r' idp)
definition ap02_p2p (f : A → B) {x y z : A} {p p' : x = y} {q q' :y = z} (r : p = p')
(s : q = q') :
ap02 f (r ◾ s) = ap_pp f p q
⬝ (ap02 f r ◾ ap02 f s)
⬝ (ap_pp f p' q')⁻¹ :=
rec_on r (rec_on s (rec_on q (rec_on p idp)))
-- rec_on r (rec_on s (rec_on p (rec_on q idp)))
definition apD02 {p q : x = y} (f : Π x, P x) (r : p = q) :
apD f p = transport2 P r (f x) ⬝ apD f q :=
rec_on r (concat_1p _)⁻¹
-- And now for a lemma whose statement is much longer than its proof.
definition apD02_pp (P : A → Type) (f : Π x:A, P x) {x y : A}
{p1 p2 p3 : x = y} (r1 : p1 = p2) (r2 : p2 = p3) :
apD02 f (r1 ⬝ r2) = apD02 f r1
⬝ whiskerL (transport2 P r1 (f x)) (apD02 f r2)
⬝ concat_p_pp _ _ _
⬝ (whiskerR ((transport2_p2p P r1 r2 (f x))⁻¹) (apD f p3)) :=
rec_on r2 (rec_on r1 (rec_on p1 idp))
end eq
namespace eq
variables {A B C D E : Type} {a a' : A} {b b' : B} {c c' : C} {d d' : D}
theorem congr_arg2 (f : A → B → C) (Ha : a = a') (Hb : b = b') : f a b = f a' b' :=
rec_on Ha (rec_on Hb idp)
theorem congr_arg3 (f : A → B → C → D) (Ha : a = a') (Hb : b = b') (Hc : c = c')
: f a b c = f a' b' c' :=
rec_on Ha (congr_arg2 (f a) Hb Hc)
theorem congr_arg4 (f : A → B → C → D → E) (Ha : a = a') (Hb : b = b') (Hc : c = c') (Hd : d = d')
: f a b c d = f a' b' c' d' :=
rec_on Ha (congr_arg3 (f a) Hb Hc Hd)
end eq
namespace eq
variables {A : Type} {B : A → Type} {C : Πa, B a → Type} {D : Πa b, C a b → Type}
{E : Πa b c, D a b c → Type} {F : Type}
variables {a a' : A}
{b : B a} {b' : B a'}
{c : C a b} {c' : C a' b'}
{d : D a b c} {d' : D a' b' c'}
theorem dcongr_arg2 (f : Πa, B a → F) (Ha : a = a') (Hb : (Ha ▹ b) = b')
: f a b = f a' b' :=
rec_on Hb (rec_on Ha idp)
/- From the Coq version:
-- ** Tactics, hints, and aliases
-- [concat], with arguments flipped. Useful mainly in the idiom [apply (concatR (expression))].
-- Given as a notation not a definition so that the resultant terms are literally instances of
-- [concat], with no unfolding required.
Notation concatR := (λp q, concat q p).
Hint Resolve
concat_1p concat_p1 concat_p_pp
inv_pp inv_V
: path_hints.
(* First try at a paths db
We want the RHS of the equation to become strictly simpler
Hint Rewrite
⬝concat_p1
⬝concat_1p
⬝concat_p_pp (* there is a choice here !*)
⬝concat_pV
⬝concat_Vp
⬝concat_V_pp
⬝concat_p_Vp
⬝concat_pp_V
⬝concat_pV_p
(*⬝inv_pp*) (* I am not sure about this one
⬝inv_V
⬝moveR_Mp
⬝moveR_pM
⬝moveL_Mp
⬝moveL_pM
⬝moveL_1M
⬝moveL_M1
⬝moveR_M1
⬝moveR_1M
⬝ap_1
(* ⬝ap_pp
⬝ap_p_pp ?*)
⬝inverse_ap
⬝ap_idmap
(* ⬝ap_compose
⬝ap_compose'*)
⬝ap_const
(* Unsure about naturality of [ap], was absent in the old implementation*)
⬝apD10_1
:paths.
Ltac hott_simpl :=
autorewrite with paths in * |- * ; auto with path_hints.
-/
end eq
|
6a23b0642a0a3d0fc48f08939e06e2b27763b4ce | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /src/Lean/Compiler/LCNF/OtherDecl.lean | eb75c3a5db64bf58c02cd41ab1ed85290292821e | [
"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 | 1,553 | lean | /-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.LCNF.CompilerM
import Lean.Compiler.LCNF.Types
namespace Lean.Compiler.LCNF
/--
State for the environment extension used to save the type of declarations
that do not have code associated with them.
Example: constructors, inductive types, foreign functions.
-/
structure OtherTypeExtState where
/-- The LCNF type for the `base` phase. -/
base : PHashMap Name Expr := {}
/-- The LCNF type for the `mono` phase. -/
mono : PHashMap Name Expr := {}
deriving Inhabited
builtin_initialize otherTypeExt : EnvExtension OtherTypeExtState ←
registerEnvExtension (pure {})
def getOtherDeclBaseType (declName : Name) (us : List Level) : CoreM Expr := do
let info ← getConstInfo declName
let type ← match otherTypeExt.getState (← getEnv) |>.base.find? declName with
| some type => pure type
| none =>
let type ← Meta.MetaM.run' <| toLCNFType info.type
modifyEnv fun env => otherTypeExt.modifyState env fun s => { s with base := s.base.insert declName type }
pure type
return type.instantiateLevelParams info.levelParams us
/--
Return the LCNF type for constructors, inductive types, and foreign functions.
-/
def getOtherDeclType (declName : Name) (us : List Level := []) : CompilerM Expr := do
match (← getPhase) with
| .base => getOtherDeclBaseType declName us
| _ => unreachable! -- TODO
end Lean.Compiler.LCNF
|
7ea5d14d376a896ae2aae066b444b3a7cc6e42c8 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/category_theory/graded_object.lean | 3600c6e65d0c190cc70fd82cfd10c0bac8f5623f | [] | 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,628 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.shift
import Mathlib.category_theory.concrete_category.default
import Mathlib.category_theory.pi.basic
import Mathlib.algebra.group.basic
import Mathlib.PostPort
universes w u v u_1
namespace Mathlib
/-!
# The category of graded objects
For any type `β`, a `β`-graded object over some category `C` is just
a function `β → C` into the objects of `C`.
We put the "pointwise" category structure on these, as the non-dependent specialization of
`category_theory.pi`.
We describe the `comap` functors obtained by precomposing with functions `β → γ`.
As a consequence a fixed element (e.g. `1`) in an additive group `β` provides a shift
functor on `β`-graded objects
When `C` has coproducts we construct the `total` functor `graded_object β C ⥤ C`,
show that it is faithful, and deduce that when `C` is concrete so is `graded_object β C`.
-/
namespace category_theory
/-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`. -/
def graded_object (β : Type w) (C : Type u) :=
β → C
-- Satisfying the inhabited linter...
protected instance inhabited_graded_object (β : Type w) (C : Type u) [Inhabited C] : Inhabited (graded_object β C) :=
{ default := fun (b : β) => Inhabited.default }
/--
A type synonym for `β → C`, used for `β`-graded objects in a category `C`
with a shift functor given by translation by `s`.
-/
def graded_object_with_shift {β : Type w} [add_comm_group β] (s : β) (C : Type u) :=
graded_object β C
namespace graded_object
protected instance category_of_graded_objects {C : Type u} [category C] (β : Type w) : category (graded_object β C) :=
category_theory.pi fun (_x : β) => C
/--
The natural isomorphism comparing between
pulling back along two propositionally equal functions.
-/
def comap_eq (C : Type u) [category C] {β : Type w} {γ : Type w} {f : β → γ} {g : β → γ} (h : f = g) : pi.comap (fun (i : γ) => C) f ≅ pi.comap (fun (i : γ) => C) g :=
iso.mk (nat_trans.mk fun (X : γ → C) (b : β) => eq_to_hom sorry)
(nat_trans.mk fun (X : γ → C) (b : β) => eq_to_hom sorry)
theorem comap_eq_symm (C : Type u) [category C] {β : Type w} {γ : Type w} {f : β → γ} {g : β → γ} (h : f = g) : comap_eq C (Eq.symm h) = iso.symm (comap_eq C h) :=
Eq.refl (comap_eq C (Eq.symm h))
theorem comap_eq_trans (C : Type u) [category C] {β : Type w} {γ : Type w} {f : β → γ} {g : β → γ} {h : β → γ} (k : f = g) (l : g = h) : comap_eq C (Eq.trans k l) = comap_eq C k ≪≫ comap_eq C l := sorry
/--
The equivalence between β-graded objects and γ-graded objects,
given an equivalence between β and γ.
-/
def comap_equiv (C : Type u) [category C] {β : Type w} {γ : Type w} (e : β ≃ γ) : graded_object β C ≌ graded_object γ C :=
equivalence.mk' (pi.comap (fun (_x : β) => C) ⇑(equiv.symm e)) (pi.comap (fun (_x : γ) => C) ⇑e)
(comap_eq C sorry ≪≫ iso.symm (pi.comap_comp (fun (_x : β) => C) ⇑e ⇑(equiv.symm e)))
(pi.comap_comp (fun (_x : γ) => C) ⇑(equiv.symm e) ⇑e ≪≫ comap_eq C sorry)
protected instance has_shift {C : Type u} [category C] {β : Type u_1} [add_comm_group β] (s : β) : has_shift (graded_object_with_shift s C) :=
has_shift.mk (comap_equiv C (equiv.mk (fun (b : β) => b - s) (fun (b : β) => b + s) sorry sorry))
@[simp] theorem shift_functor_obj_apply {C : Type u} [category C] {β : Type u_1} [add_comm_group β] (s : β) (X : β → C) (t : β) : functor.obj (equivalence.functor (shift (graded_object_with_shift s C))) X t = X (t + s) :=
rfl
@[simp] theorem shift_functor_map_apply {C : Type u} [category C] {β : Type u_1} [add_comm_group β] (s : β) {X : graded_object_with_shift s C} {Y : graded_object_with_shift s C} (f : X ⟶ Y) (t : β) : functor.map (equivalence.functor (shift (graded_object_with_shift s C))) f t = f (t + s) :=
rfl
protected instance has_zero_morphisms {C : Type u} [category C] [limits.has_zero_morphisms C] (β : Type w) : limits.has_zero_morphisms (graded_object β C) :=
limits.has_zero_morphisms.mk
@[simp] theorem zero_apply {C : Type u} [category C] [limits.has_zero_morphisms C] (β : Type w) (X : graded_object β C) (Y : graded_object β C) (b : β) : HasZero.zero b = 0 :=
rfl
protected instance has_zero_object {C : Type u} [category C] [limits.has_zero_object C] [limits.has_zero_morphisms C] (β : Type w) : limits.has_zero_object (graded_object β C) :=
limits.has_zero_object.mk (fun (b : β) => 0)
(fun (X : graded_object β C) => unique.mk { default := fun (b : β) => 0 } sorry)
fun (X : graded_object β C) => unique.mk { default := fun (b : β) => 0 } sorry
end graded_object
namespace graded_object
-- The universes get a little hairy here, so we restrict the universe level for the grading to 0.
-- Since we're typically interested in grading by ℤ or a finite group, this should be okay.
-- If you're grading by things in higher universes, have fun!
/--
The total object of a graded object is the coproduct of the graded components.
-/
def total (β : Type) (C : Type u) [category C] [limits.has_coproducts C] : graded_object β C ⥤ C :=
functor.mk (fun (X : graded_object β C) => ∐ fun (i : ulift β) => X (ulift.down i))
fun (X Y : graded_object β C) (f : X ⟶ Y) => limits.sigma.map fun (i : ulift β) => f (ulift.down i)
/--
The `total` functor taking a graded object to the coproduct of its graded components is faithful.
To prove this, we need to know that the coprojections into the coproduct are monomorphisms,
which follows from the fact we have zero morphisms and decidable equality for the grading.
-/
protected instance total.category_theory.faithful (β : Type) (C : Type u) [category C] [limits.has_coproducts C] [limits.has_zero_morphisms C] : faithful (total β C) :=
faithful.mk
end graded_object
namespace graded_object
protected instance category_theory.concrete_category (β : Type) (C : Type (u + 1)) [large_category C] [concrete_category C] [limits.has_coproducts C] [limits.has_zero_morphisms C] : concrete_category (graded_object β C) :=
concrete_category.mk (total β C ⋙ forget C)
protected instance category_theory.has_forget₂ (β : Type) (C : Type (u + 1)) [large_category C] [concrete_category C] [limits.has_coproducts C] [limits.has_zero_morphisms C] : has_forget₂ (graded_object β C) C :=
has_forget₂.mk (total β C)
|
e80d876deda3a216552b0c4c5567da7f95b6533e | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/examples/ex.lean | 01e5d0846f0c5956c8cc4c37a58107e7ec6ca57d | [
"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 | 7,046 | lean | -- Theorems/Exercises from "Logical Investigations, with the Nuprl Proof Assistant"
-- by Robert L. Constable and Anne Trostle
-- http://www.nuprl.org/MathLibrary/LogicalInvestigations/
import logic
-- 2. The Minimal Implicational Calculus
theorem thm1 {A B : Prop} : A → B → A :=
assume Ha Hb, Ha
theorem thm2 {A B C : Prop} : (A → B) → (A → B → C) → (A → C) :=
assume Hab Habc Ha,
Habc Ha (Hab Ha)
theorem thm3 {A B C : Prop} : (A → B) → (B → C) → (A → C) :=
assume Hab Hbc Ha,
Hbc (Hab Ha)
-- 3. False Propositions and Negation
theorem thm4 {P Q : Prop} : ¬P → P → Q :=
assume Hnp Hp,
absurd Hp Hnp
theorem thm5 {P : Prop} : P → ¬¬P :=
assume (Hp : P) (HnP : ¬P),
absurd Hp HnP
theorem thm6 {P Q : Prop} : (P → Q) → (¬Q → ¬P) :=
assume (Hpq : P → Q) (Hnq : ¬Q) (Hp : P),
have Hq : Q, from Hpq Hp,
show false, from absurd Hq Hnq
theorem thm7 {P Q : Prop} : (P → ¬P) → (P → Q) :=
assume Hpnp Hp,
absurd Hp (Hpnp Hp)
theorem thm8 {P Q : Prop} : ¬(P → Q) → (P → ¬Q) :=
assume (Hn : ¬(P → Q)) (Hp : P) (Hq : Q),
-- Rermak we don't even need the hypothesis Hp
have H : P → Q, from assume H', Hq,
absurd H Hn
-- 4. Conjunction and Disjunction
theorem thm9 {P : Prop} : (P ∨ ¬P) → (¬¬P → P) :=
assume (em : P ∨ ¬P) (Hnn : ¬¬P),
or.elim em
(assume Hp, Hp)
(assume Hn, absurd Hn Hnn)
theorem thm10 {P : Prop} : ¬¬(P ∨ ¬P) :=
assume Hnem : ¬(P ∨ ¬P),
have Hnp : ¬P, from
assume Hp : P,
have Hem : P ∨ ¬P, from or.inl Hp,
absurd Hem Hnem,
have Hem : P ∨ ¬P, from or.inr Hnp,
absurd Hem Hnem
theorem thm11 {P Q : Prop} : ¬P ∨ ¬Q → ¬(P ∧ Q) :=
assume (H : ¬P ∨ ¬Q) (Hn : P ∧ Q),
or.elim H
(assume Hnp : ¬P, absurd (and.elim_left Hn) Hnp)
(assume Hnq : ¬Q, absurd (and.elim_right Hn) Hnq)
theorem thm12 {P Q : Prop} : ¬(P ∨ Q) → ¬P ∧ ¬Q :=
assume H : ¬(P ∨ Q),
have Hnp : ¬P, from assume Hp : P, absurd (or.inl Hp) H,
have Hnq : ¬Q, from assume Hq : Q, absurd (or.inr Hq) H,
and.intro Hnp Hnq
theorem thm13 {P Q : Prop} : ¬P ∧ ¬Q → ¬(P ∨ Q) :=
assume (H : ¬P ∧ ¬Q) (Hn : P ∨ Q),
or.elim Hn
(assume Hp : P, absurd Hp (and.elim_left H))
(assume Hq : Q, absurd Hq (and.elim_right H))
theorem thm14 {P Q : Prop} : ¬P ∨ Q → P → Q :=
assume (Hor : ¬P ∨ Q) (Hp : P),
or.elim Hor
(assume Hnp : ¬P, absurd Hp Hnp)
(assume Hq : Q, Hq)
theorem thm15 {P Q : Prop} : (P → Q) → ¬¬(¬P ∨ Q) :=
assume (Hpq : P → Q) (Hn : ¬(¬P ∨ Q)),
have H1 : ¬¬P ∧ ¬Q, from thm12 Hn,
have Hnp : ¬P, from mt Hpq (and.elim_right H1),
absurd Hnp (and.elim_left H1)
theorem thm16 {P Q : Prop} : (P → Q) ∧ ((P ∨ ¬P) ∨ (Q ∨ ¬Q)) → ¬P ∨ Q :=
assume H : (P → Q) ∧ ((P ∨ ¬P) ∨ (Q ∨ ¬Q)),
have Hpq : P → Q, from and.elim_left H,
or.elim (and.elim_right H)
(assume Hem1 : P ∨ ¬P, or.elim Hem1
(assume Hp : P, or.inr (Hpq Hp))
(assume Hnp : ¬P, or.inl Hnp))
(assume Hem2 : Q ∨ ¬Q, or.elim Hem2
(assume Hq : Q, or.inr Hq)
(assume Hnq : ¬Q, or.inl (mt Hpq Hnq)))
-- 5. First-Order Logic: All and Exists
section
variables {T : Type} {C : Prop} {P : T → Prop}
theorem thm17a : (C → ∀x, P x) → (∀x, C → P x) :=
assume H : C → ∀x, P x,
take x : T, assume Hc : C,
H Hc x
theorem thm17b : (∀x, C → P x) → (C → ∀x, P x) :=
assume (H : ∀x, C → P x) (Hc : C),
take x : T,
H x Hc
theorem thm18a : ((∃x, P x) → C) → (∀x, P x → C) :=
assume H : (∃x, P x) → C,
take x, assume Hp : P x,
have Hex : ∃x, P x, from exists.intro x Hp,
H Hex
theorem thm18b : (∀x, P x → C) → (∃x, P x) → C :=
sorry
/-
assume (H1 : ∀x, P x → C) (H2 : ∃x, P x),
obtain (w : T) (Hw : P w), from H2,
H1 w Hw
-/
theorem thm19a : (C ∨ ¬C) → (∃x : T, true) → (C → (∃x, P x)) → (∃x, C → P x) :=
sorry
/-
assume (Hem : C ∨ ¬C) (Hin : ∃x : T, true) (H1 : C → ∃x, P x),
or.elim Hem
(assume Hc : C,
obtain (w : T) (Hw : P w), from H1 Hc,
have Hr : C → P w, from assume Hc, Hw,
exists.intro w Hr)
(assume Hnc : ¬C,
obtain (w : T) (Hw : true), from Hin,
have Hr : C → P w, from assume Hc, absurd Hc Hnc,
exists.intro w Hr)
-/
theorem thm19b : (∃x, C → P x) → C → (∃x, P x) :=
sorry
/-
assume (H : ∃x, C → P x) (Hc : C),
obtain (w : T) (Hw : C → P w), from H,
exists.intro w (Hw Hc)
-/
theorem thm20a : (C ∨ ¬C) → (∃x : T, true) → ((¬∀x, P x) → ∃x, ¬P x) → ((∀x, P x) → C) → (∃x, P x → C) :=
sorry
/-
assume Hem Hin Hnf H,
or.elim Hem
(assume Hc : C,
obtain (w : T) (Hw : true), from Hin,
exists.intro w (assume H : P w, Hc))
(assume Hnc : ¬C,
have H1 : ¬(∀x, P x), from mt H Hnc,
have H2 : ∃x, ¬P x, from Hnf H1,
obtain (w : T) (Hw : ¬P w), from H2,
exists.intro w (assume H : P w, absurd H Hw))
-/
theorem thm20b : (∃x, P x → C) → (∀ x, P x) → C :=
sorry
/-
assume Hex Hall,
obtain (w : T) (Hw : P w → C), from Hex,
Hw (Hall w)
-/
theorem thm21a : (∃x : T, true) → ((∃x, P x) ∨ C) → (∃x, P x ∨ C) :=
sorry
/-
assume Hin H,
or.elim H
(assume Hex : ∃x, P x,
obtain (w : T) (Hw : P w), from Hex,
exists.intro w (or.inl Hw))
(assume Hc : C,
obtain (w : T) (Hw : true), from Hin,
exists.intro w (or.inr Hc))
-/
theorem thm21b : (∃x, P x ∨ C) → ((∃x, P x) ∨ C) :=
sorry
/-
assume H,
obtain (w : T) (Hw : P w ∨ C), from H,
or.elim Hw
(assume H : P w, or.inl (exists.intro w H))
(assume Hc : C, or.inr Hc)
-/
theorem thm22a : (∀x, P x) ∨ C → ∀x, P x ∨ C :=
assume H, take x,
or.elim H
(assume Hl, or.inl (Hl x))
(assume Hr, or.inr Hr)
theorem thm22b : (C ∨ ¬C) → (∀x, P x ∨ C) → ((∀x, P x) ∨ C) :=
assume Hem H1,
or.elim Hem
(assume Hc : C, or.inr Hc)
(assume Hnc : ¬C,
have Hx : ∀x, P x, from
take x,
have H1 : P x ∨ C, from H1 x,
or_resolve_left H1 Hnc,
or.inl Hx)
theorem thm23a : (∃x, P x) ∧ C → (∃x, P x ∧ C) :=
sorry
/-
assume H,
have Hex : ∃x, P x, from and.elim_left H,
have Hc : C, from and.elim_right H,
obtain (w : T) (Hw : P w), from Hex,
exists.intro w (and.intro Hw Hc)
-/
theorem thm23b : (∃x, P x ∧ C) → (∃x, P x) ∧ C :=
sorry
/-
assume H,
obtain (w : T) (Hw : P w ∧ C), from H,
have Hex : ∃x, P x, from exists.intro w (and.elim_left Hw),
and.intro Hex (and.elim_right Hw)
-/
theorem thm24a : (∀x, P x) ∧ C → (∀x, P x ∧ C) :=
assume H, take x,
and.intro (and.elim_left H x) (and.elim_right H)
theorem thm24b : (∃x : T, true) → (∀x, P x ∧ C) → (∀x, P x) ∧ C :=
sorry
/-
assume Hin H,
obtain (w : T) (Hw : true), from Hin,
have Hc : C, from and.elim_right (H w),
have Hx : ∀x, P x, from take x, and.elim_left (H x),
and.intro Hx Hc
-/
end -- of section
|
c4d8ecc59c315083184074d78152b20ab1db3327 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/number_theory/zsqrtd/gaussian_int.lean | 0370171e376d101a3477a3cfaeb490bbe83a68ed | [
"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 | 12,626 | lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import number_theory.zsqrtd.basic
import data.complex.basic
import ring_theory.principal_ideal_domain
import number_theory.legendre_symbol.quadratic_reciprocity
/-!
# Gaussian integers
The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both
integers.
## Main definitions
The Euclidean domain structure on `ℤ[i]` is defined in this file.
The homomorphism `to_complex` into the complex numbers is also defined in this file.
## Main statements
`prime_iff_mod_four_eq_three_of_nat_prime`
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
## Notations
This file uses the local notation `ℤ[i]` for `gaussian_int`
## Implementation notes
Gaussian integers are implemented using the more general definition `zsqrtd`, the type of integers
adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties
and definitions about `zsqrtd` can easily be used.
-/
open zsqrtd complex
/-- The Gaussian integers, defined as `ℤ√(-1)`. -/
@[reducible] def gaussian_int : Type := zsqrtd (-1)
local notation `ℤ[i]` := gaussian_int
namespace gaussian_int
instance : has_repr ℤ[i] := ⟨λ x, "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩
instance : comm_ring ℤ[i] := zsqrtd.comm_ring
section
local attribute [-instance] complex.field -- Avoid making things noncomputable unnecessarily.
/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/
def to_complex : ℤ[i] →+* ℂ :=
zsqrtd.lift ⟨I, by simp⟩
end
instance : has_coe (ℤ[i]) ℂ := ⟨to_complex⟩
lemma to_complex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I := rfl
lemma to_complex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [to_complex_def]
lemma to_complex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ :=
by apply complex.ext; simp [to_complex_def]
@[simp] lemma to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [to_complex_def]
@[simp] lemma to_real_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by simp [to_complex_def]
@[simp] lemma to_complex_re (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).re = x := by simp [to_complex_def]
@[simp] lemma to_complex_im (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).im = y := by simp [to_complex_def]
@[simp] lemma to_complex_add (x y : ℤ[i]) : ((x + y : ℤ[i]) : ℂ) = x + y := to_complex.map_add _ _
@[simp] lemma to_complex_mul (x y : ℤ[i]) : ((x * y : ℤ[i]) : ℂ) = x * y := to_complex.map_mul _ _
@[simp] lemma to_complex_one : ((1 : ℤ[i]) : ℂ) = 1 := to_complex.map_one
@[simp] lemma to_complex_zero : ((0 : ℤ[i]) : ℂ) = 0 := to_complex.map_zero
@[simp] lemma to_complex_neg (x : ℤ[i]) : ((-x : ℤ[i]) : ℂ) = -x := to_complex.map_neg _
@[simp] lemma to_complex_sub (x y : ℤ[i]) : ((x - y : ℤ[i]) : ℂ) = x - y := to_complex.map_sub _ _
@[simp] lemma to_complex_inj {x y : ℤ[i]} : (x : ℂ) = y ↔ x = y :=
by cases x; cases y; simp [to_complex_def₂]
@[simp] lemma to_complex_eq_zero {x : ℤ[i]} : (x : ℂ) = 0 ↔ x = 0 :=
by rw [← to_complex_zero, to_complex_inj]
@[simp] lemma nat_cast_real_norm (x : ℤ[i]) : (x.norm : ℝ) = (x : ℂ).norm_sq :=
by rw [zsqrtd.norm, norm_sq]; simp
@[simp] lemma nat_cast_complex_norm (x : ℤ[i]) : (x.norm : ℂ) = (x : ℂ).norm_sq :=
by cases x; rw [zsqrtd.norm, norm_sq]; simp
lemma norm_nonneg (x : ℤ[i]) : 0 ≤ norm x := norm_nonneg (by norm_num) _
@[simp] lemma norm_eq_zero {x : ℤ[i]} : norm x = 0 ↔ x = 0 :=
by rw [← @int.cast_inj ℝ _ _ _]; simp
lemma norm_pos {x : ℤ[i]} : 0 < norm x ↔ x ≠ 0 :=
by rw [lt_iff_le_and_ne, ne.def, eq_comm, norm_eq_zero]; simp [norm_nonneg]
lemma coe_nat_abs_norm (x : ℤ[i]) : (x.norm.nat_abs : ℤ) = x.norm :=
int.nat_abs_of_nonneg (norm_nonneg _)
@[simp] lemma nat_cast_nat_abs_norm {α : Type*} [ring α]
(x : ℤ[i]) : (x.norm.nat_abs : α) = x.norm :=
by rw [← int.cast_coe_nat, coe_nat_abs_norm]
lemma nat_abs_norm_eq (x : ℤ[i]) : x.norm.nat_abs =
x.re.nat_abs * x.re.nat_abs + x.im.nat_abs * x.im.nat_abs :=
int.coe_nat_inj $ begin simp, simp [zsqrtd.norm] end
instance : has_div ℤ[i] :=
⟨λ x y, let n := (rat.of_int (norm y))⁻¹, c := y.conj in
⟨round (rat.of_int (x * c).re * n : ℚ), round (rat.of_int (x * c).im * n : ℚ)⟩⟩
lemma div_def (x y : ℤ[i]) : x / y = ⟨round ((x * conj y).re / norm y : ℚ),
round ((x * conj y).im / norm y : ℚ)⟩ :=
show zsqrtd.mk _ _ = _, by simp [rat.of_int_eq_mk, rat.mk_eq_div, div_eq_mul_inv]
lemma to_complex_div_re (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).re = round ((x / y : ℂ).re) :=
by rw [div_def, ← @rat.round_cast ℝ _ _];
simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]
lemma to_complex_div_im (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).im = round ((x / y : ℂ).im) :=
by rw [div_def, ← @rat.round_cast ℝ _ _, ← @rat.round_cast ℝ _ _];
simp [-rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]
lemma norm_sq_le_norm_sq_of_re_le_of_im_le {x y : ℂ} (hre : |x.re| ≤ |y.re|)
(him : |x.im| ≤ |y.im|) : x.norm_sq ≤ y.norm_sq :=
by rw [norm_sq_apply, norm_sq_apply, ← _root_.abs_mul_self, _root_.abs_mul,
← _root_.abs_mul_self y.re, _root_.abs_mul y.re,
← _root_.abs_mul_self x.im, _root_.abs_mul x.im,
← _root_.abs_mul_self y.im, _root_.abs_mul y.im]; exact
(add_le_add (mul_self_le_mul_self (abs_nonneg _) hre)
(mul_self_le_mul_self (abs_nonneg _) him))
lemma norm_sq_div_sub_div_lt_one (x y : ℤ[i]) :
((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)).norm_sq < 1 :=
calc ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)).norm_sq =
((x / y : ℂ).re - ((x / y : ℤ[i]) : ℂ).re +
((x / y : ℂ).im - ((x / y : ℤ[i]) : ℂ).im) * I : ℂ).norm_sq :
congr_arg _ $ by apply complex.ext; simp
... ≤ (1 / 2 + 1 / 2 * I).norm_sq :
have |(2⁻¹ : ℝ)| = 2⁻¹, from _root_.abs_of_nonneg (by norm_num),
norm_sq_le_norm_sq_of_re_le_of_im_le
(by rw [to_complex_div_re]; simp [norm_sq, this];
simpa using abs_sub_round (x / y : ℂ).re)
(by rw [to_complex_div_im]; simp [norm_sq, this];
simpa using abs_sub_round (x / y : ℂ).im)
... < 1 : by simp [norm_sq]; norm_num
instance : has_mod ℤ[i] := ⟨λ x y, x - y * (x / y)⟩
lemma mod_def (x y : ℤ[i]) : x % y = x - y * (x / y) := rfl
lemma norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (x % y).norm < y.norm :=
have (y : ℂ) ≠ 0, by rwa [ne.def, ← to_complex_zero, to_complex_inj],
(@int.cast_lt ℝ _ _ _ _).1 $
calc ↑(zsqrtd.norm (x % y)) = (x - y * (x / y : ℤ[i]) : ℂ).norm_sq : by simp [mod_def]
... = (y : ℂ).norm_sq * (((x / y) - (x / y : ℤ[i])) : ℂ).norm_sq :
by rw [← norm_sq_mul, mul_sub, mul_div_cancel' _ this]
... < (y : ℂ).norm_sq * 1 : mul_lt_mul_of_pos_left (norm_sq_div_sub_div_lt_one _ _)
(norm_sq_pos.2 this)
... = zsqrtd.norm y : by simp
lemma nat_abs_norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) :
(x % y).norm.nat_abs < y.norm.nat_abs :=
int.coe_nat_lt.1 (by simp [-int.coe_nat_lt, norm_mod_lt x hy])
lemma norm_le_norm_mul_left (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) :
(norm x).nat_abs ≤ (norm (x * y)).nat_abs :=
by rw [zsqrtd.norm_mul, int.nat_abs_mul];
exact le_mul_of_one_le_right (nat.zero_le _)
(int.coe_nat_le.1 (by rw [coe_nat_abs_norm]; exact int.add_one_le_of_lt (norm_pos.2 hy)))
instance : nontrivial ℤ[i] :=
⟨⟨0, 1, dec_trivial⟩⟩
instance : euclidean_domain ℤ[i] :=
{ quotient := (/),
remainder := (%),
quotient_zero := by { simp [div_def], refl },
quotient_mul_add_remainder_eq := λ _ _, by simp [mod_def],
r := _,
r_well_founded := measure_wf (int.nat_abs ∘ norm),
remainder_lt := nat_abs_norm_mod_lt,
mul_left_not_lt := λ a b hb0, not_lt_of_ge $ norm_le_norm_mul_left a hb0,
.. gaussian_int.comm_ring,
.. gaussian_int.nontrivial }
open principal_ideal_ring
lemma mod_four_eq_three_of_nat_prime_of_prime (p : ℕ) [hp : fact p.prime] (hpi : prime (p : ℤ[i])) :
p % 4 = 3 :=
hp.1.eq_two_or_odd.elim
(λ hp2, absurd hpi (mt irreducible_iff_prime.2 $
λ ⟨hu, h⟩, begin
have := h ⟨1, 1⟩ ⟨1, -1⟩ (hp2.symm ▸ rfl),
rw [← norm_eq_one_iff, ← norm_eq_one_iff] at this,
exact absurd this dec_trivial
end))
(λ hp1, by_contradiction $ λ hp3 : p % 4 ≠ 3,
have hp41 : p % 4 = 1,
begin
rw [← nat.mod_mul_left_mod p 2 2, show 2 * 2 = 4, from rfl] at hp1,
have := nat.mod_lt p (show 0 < 4, from dec_trivial),
revert this hp3 hp1,
generalize : p % 4 = m, dec_trivial!,
end,
let ⟨k, hk⟩ := zmod.exists_sq_eq_neg_one_iff.2 $
by rw hp41; exact dec_trivial in
begin
obtain ⟨k, k_lt_p, rfl⟩ : ∃ (k' : ℕ) (h : k' < p), (k' : zmod p) = k,
{ refine ⟨k.val, k.val_lt, zmod.nat_cast_zmod_val k⟩ },
have hpk : p ∣ k ^ 2 + 1,
by { rw [pow_two, ← char_p.cast_eq_zero_iff (zmod p) p, nat.cast_add, nat.cast_mul,
nat.cast_one, ← hk, add_left_neg], },
have hkmul : (k ^ 2 + 1 : ℤ[i]) = ⟨k, 1⟩ * ⟨k, -1⟩ :=
by simp [sq, zsqrtd.ext],
have hpne1 : p ≠ 1 := ne_of_gt hp.1.one_lt,
have hkltp : 1 + k * k < p * p,
from calc 1 + k * k ≤ k + k * k :
add_le_add_right (nat.pos_of_ne_zero
(λ hk0, by clear_aux_decl; simp [*, pow_succ'] at *)) _
... = k * (k + 1) : by simp [add_comm, mul_add]
... < p * p : mul_lt_mul k_lt_p k_lt_p (nat.succ_pos _) (nat.zero_le _),
have hpk₁ : ¬ (p : ℤ[i]) ∣ ⟨k, -1⟩ :=
λ ⟨x, hx⟩, lt_irrefl (p * x : ℤ[i]).norm.nat_abs $
calc (norm (p * x : ℤ[i])).nat_abs = (zsqrtd.norm ⟨k, -1⟩).nat_abs : by rw hx
... < (norm (p : ℤ[i])).nat_abs : by simpa [add_comm, zsqrtd.norm] using hkltp
... ≤ (norm (p * x : ℤ[i])).nat_abs : norm_le_norm_mul_left _
(λ hx0, (show (-1 : ℤ) ≠ 0, from dec_trivial) $
by simpa [hx0] using congr_arg zsqrtd.im hx),
have hpk₂ : ¬ (p : ℤ[i]) ∣ ⟨k, 1⟩ :=
λ ⟨x, hx⟩, lt_irrefl (p * x : ℤ[i]).norm.nat_abs $
calc (norm (p * x : ℤ[i])).nat_abs = (zsqrtd.norm ⟨k, 1⟩).nat_abs : by rw hx
... < (norm (p : ℤ[i])).nat_abs : by simpa [add_comm, zsqrtd.norm] using hkltp
... ≤ (norm (p * x : ℤ[i])).nat_abs : norm_le_norm_mul_left _
(λ hx0, (show (1 : ℤ) ≠ 0, from dec_trivial) $
by simpa [hx0] using congr_arg zsqrtd.im hx),
have hpu : ¬ is_unit (p : ℤ[i]), from mt norm_eq_one_iff.2
(by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];
exact λ h, (ne_of_lt hp.1.one_lt).symm h.1),
obtain ⟨y, hy⟩ := hpk,
have := hpi.2.2 ⟨k, 1⟩ ⟨k, -1⟩ ⟨y, by rw [← hkmul, ← nat.cast_mul p, ← hy]; simp⟩,
clear_aux_decl, tauto
end)
lemma sq_add_sq_of_nat_prime_of_not_irreducible (p : ℕ) [hp : fact p.prime]
(hpi : ¬irreducible (p : ℤ[i])) : ∃ a b, a^2 + b^2 = p :=
have hpu : ¬ is_unit (p : ℤ[i]), from mt norm_eq_one_iff.2 $
by rw [norm_nat_cast, int.nat_abs_mul, nat.mul_eq_one_iff];
exact λ h, (ne_of_lt hp.1.one_lt).symm h.1,
have hab : ∃ a b, (p : ℤ[i]) = a * b ∧ ¬ is_unit a ∧ ¬ is_unit b,
by simpa [irreducible_iff, hpu, not_forall, not_or_distrib] using hpi,
let ⟨a, b, hpab, hau, hbu⟩ := hab in
have hnap : (norm a).nat_abs = p, from ((hp.1.mul_eq_prime_sq_iff
(mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 $
by rw [← int.coe_nat_inj', int.coe_nat_pow, sq,
← @norm_nat_cast (-1), hpab];
simp).1,
⟨a.re.nat_abs, a.im.nat_abs, by simpa [nat_abs_norm_eq, sq] using hnap⟩
lemma prime_of_nat_prime_of_mod_four_eq_three (p : ℕ) [hp : fact p.prime] (hp3 : p % 4 = 3) :
prime (p : ℤ[i]) :=
irreducible_iff_prime.1 $ classical.by_contradiction $ λ hpi,
let ⟨a, b, hab⟩ := sq_add_sq_of_nat_prime_of_not_irreducible p hpi in
have ∀ a b : zmod 4, a^2 + b^2 ≠ p, by erw [← zmod.nat_cast_mod p 4, hp3]; exact dec_trivial,
this a b (hab ▸ by simp)
/-- A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` -/
lemma prime_iff_mod_four_eq_three_of_nat_prime (p : ℕ) [hp : fact p.prime] :
prime (p : ℤ[i]) ↔ p % 4 = 3 :=
⟨mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p⟩
end gaussian_int
|
b030cf1263cf345523cd1555bb73013675d2b501 | ff5230333a701471f46c57e8c115a073ebaaa448 | /tests/lean/run/array1.lean | 5bec9970ee46c75b8ed736e91fe28aee5a18c77c | [
"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 | 577 | lean | #check @d_array.mk
#eval mk_array 4 1
def v : array 10 nat :=
@d_array.mk 10 (λ _, nat) (λ ⟨i, _⟩, i)
#eval array.map (+10) v
def w : array 10 nat :=
(mk_array 9 1)^.push_back 3
def f : fin 10 → nat :=
d_array.cases_on w (λ f, f)
#eval f ⟨9, dec_trivial⟩
#eval f ⟨2, dec_trivial⟩
#eval (((mk_array 1 1)^.push_back 2)^.push_back 3)^.foldl 0 (+)
def array_sum {n} (a : array n nat) : nat :=
a^.foldl 0 (+)
#eval array_sum (mk_array 10 1)
#eval (mk_array 10 1)^.data ⟨1, dec_trivial⟩ + 20
#eval (mk_array 10 1)^.data 2
#eval (mk_array 10 3)^.data 2
|
b83f55500550266dadefd420d1660aa04715baf8 | 60bf3fa4185ec5075eaea4384181bfbc7e1dc319 | /src/game/sup_inf/supSumSets.lean | 970da39d74fafd4d8a2f166c15d7d8824eaaeb4c | [
"Apache-2.0"
] | permissive | anrddh/real-number-game | 660f1127d03a78fd35986c771d65c3132c5f4025 | c708c4e02ec306c657e1ea67862177490db041b0 | refs/heads/master | 1,668,214,277,092 | 1,593,105,075,000 | 1,593,105,075,000 | 264,269,218 | 0 | 0 | null | 1,589,567,264,000 | 1,589,567,264,000 | null | UTF-8 | Lean | false | false | 3,299 | lean | import data.real.basic
namespace xena -- hide
/-
# Chapter 3 : Sup and Inf
## Level 5
A classical result: the supremum of an element-wise sum of sets.
-/
-- see also ds_infSum.lean for only the better-organized version -- hide
def mem_sum_sets (A : set ℝ) (B : set ℝ) := { x : ℝ | ∃ y ∈ A, ∃ z ∈ B, x = y + z}
/- Lemma
If $A$ and $B$ are sets of reals, then
$$ \textrm{sup} (A + B) = \textrm{sup} (A) + \textrm{sup}(B)$$
-/
lemma sup_sum_sets (A : set ℝ) (B : set ℝ) (h1A : A.nonempty) (h1B : B.nonempty)
(h2A : bdd_above A) (h2B : bdd_above B) (a : ℝ) (b : ℝ) :
(is_lub A a) ∧ (is_lub B b) → is_lub (mem_sum_sets A B) (a + b) :=
begin
intro h,
cases h with hA hB,
split,
{ -- prove that (a+b) is an upper bound
intros x h0,
cases h0 with y h1, cases h1 with yA h2,
cases h2 with z h3, cases h3 with zB hx,
have H12A := hA.left, have H12B := hB.left,
have H13A := H12A yA, have H13B := H12B zB,
linarith,
},
-- now prove that (a+b) is the least upper bound
intros S hS,
--change ∀ xab ∈ (sum_of_sets A B), xab ≤ S at hS,
have H1 : ∀ y ∈ A, ∀ z ∈ B, (y + z) ∈ (mem_sum_sets A B),
intros y hy z hz,
unfold mem_sum_sets,
existsi y, existsi hy, existsi z, existsi hz, refl,
have H2 : ∀ y ∈ A, ∀ z ∈ B, (y + z) ≤ S,
intros y hy z hz,
apply hS, exact H1 y hy z hz,
have H3 : ∀ y ∈ A, ∀ z ∈ B, y ≤ S - z,
intros y hy z hz,
have H3a := H2 y hy z hz,
exact le_sub_right_of_add_le H3a,
have h21B := hB.right, have h22B := hB.left,
--change ∀ z ∈ B, z ≤ b at h22B,
have H4 : ∀ z ∈ B, (S - z) ∈ upper_bounds A, --!
intros z hz y hy,
exact H3 y hy z hz,
have H5 : ∀ z ∈ B, a ≤ (S - z),
intros z hz,
have H13A := hA.right,
change ∀ u ∈ upper_bounds A, a ≤ u at H13A,
have H5a := H4 z hz,
exact H13A (S-z) H5a,
have H6 : ∀ z ∈ B, z ≤ S - a,
intros z hz,
have H6a := H5 z hz, exact le_sub.1 H6a,
--have H7 : (S - a) ∈ upper_bounds B, exact H6,
have H8 : b ≤ (S-a),
have H13B := hB.right,
change ∀ u ∈ upper_bounds B, b ≤ u at H13B,
exact H13B (S-a) H6, -- I had H7 instead of H6 here
exact add_le_of_le_sub_left H8, done
end
-- begin hide
-- Kevin's term proof for second part
lemma sup_sum_of_sets' (A : set ℝ) (B : set ℝ) (a : ℝ) (b : ℝ)
(hA : is_lub A a) (hB : is_lub B b) :
a + b ∈ lower_bounds (upper_bounds (mem_sum_sets A B)) :=
λ S hS, add_le_of_le_sub_left $ hB.2 $ λ z hz, le_sub.1 $ hA.2 $ λ y hy,
le_sub_right_of_add_le $ hS ⟨y, hy, z, hz, rfl⟩
-- Patrick Massot's proof for second part
lemma sup_sum_of_sets'' (A : set ℝ) (B : set ℝ) (a : ℝ) (b : ℝ)
(hA : is_lub A a) (hB : is_lub B b) :
a + b ∈ lower_bounds (upper_bounds (mem_sum_sets A B)) :=
begin
intros S hS,
have H1 : ∀ x ∈ A, S - x ∈ upper_bounds B,
{ intros x hx y hy,
suffices : x + y ≤ S, by linarith, -- by rwa le_sub_iff_add_le',
exact hS ⟨x, hx, y, hy, rfl⟩, },
have H2 : S - b ∈ upper_bounds A,
{ intros x hx,
suffices : b ≤ S - x, by linarith, -- by rwa le_sub,
exact hB.2 (H1 x hx) },
linarith [hA.2 H2], --exact le_sub_iff_add_le.mp (hA.2 H2),
end
--- end hide
end xena -- hide
|
69744addcd52768f1bdaa25f66de69924d697eaf | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/1208.lean | 26a5d489afc6b648b67d53a87c71f58f35c47013 | [
"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 | 152 | lean | lemma foo {α : Type*} {f : α → α} (a : α) : f a = f a := rfl
example {X : Type} (h : X → X) (x₀ : X) : h x₀ = h x₀ := by apply (foo x₀)
|
c54d1134af3a59d851ce777095abceeb03db177c | 07c6143268cfb72beccd1cc35735d424ebcb187b | /src/data/nat/multiplicity.lean | d3578d9b56e66bf005a97d92629a431b3f9c3703 | [
"Apache-2.0"
] | permissive | khoek/mathlib | bc49a842910af13a3c372748310e86467d1dc766 | aa55f8b50354b3e11ba64792dcb06cccb2d8ee28 | refs/heads/master | 1,588,232,063,837 | 1,587,304,803,000 | 1,587,304,803,000 | 176,688,517 | 0 | 0 | Apache-2.0 | 1,553,070,585,000 | 1,553,070,585,000 | null | UTF-8 | Lean | false | false | 9,474 | lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.nat.choose ring_theory.multiplicity data.nat.modeq algebra.gcd_domain
/-!
# Natural number multiplicity
This file contains lemmas about the multiplicity function (the maximum prime power divding a number).
# Main results
There are natural number versions of some basic lemmas about multiplicity.
There are also lemmas about the multiplicity of primes in factorials and in binomial coefficients.
-/
open finset nat multiplicity
namespace nat
/-- The multiplicity of a divisor `m` of `n`, is the cardinality of the set of
positive natural numbers `i` such that `p ^ i` divides `n`. The set is expressed
by filtering `Ico 1 b` where `b` is any bound at least `n` -/
lemma multiplicity_eq_card_pow_dvd {m n b : ℕ} (hm1 : m ≠ 1) (hn0 : 0 < n) (hb : n ≤ b):
multiplicity m n = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card :=
calc multiplicity m n = ↑(Ico 1 $ ((multiplicity m n).get (finite_nat_iff.2 ⟨hm1, hn0⟩) + 1)).card :
by simp
... = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card : congr_arg coe $ congr_arg card $
finset.ext.2 $ λ i,
have hmn : ¬ m ^ n ∣ n,
from if hm0 : m = 0
then λ _, by cases n; simp [*, lt_irrefl, nat.pow_succ] at *
else mt (le_of_dvd hn0) (not_le_of_gt $ lt_pow_self
(lt_of_le_of_ne (nat.pos_of_ne_zero hm0) hm1.symm) _),
⟨λ hi, begin
simp only [Ico.mem, mem_filter, lt_succ_iff] at *,
exact ⟨⟨hi.1, lt_of_le_of_lt hi.2 $
lt_of_lt_of_le (by rw [← enat.coe_lt_coe, enat.coe_get, multiplicity_lt_iff_neg_dvd,
nat.pow_eq_pow]; exact hmn)
hb⟩,
by rw [← nat.pow_eq_pow, pow_dvd_iff_le_multiplicity];
rw [← @enat.coe_le_coe i, enat.coe_get] at hi; exact hi.2⟩
end,
begin
simp only [Ico.mem, mem_filter, lt_succ_iff, and_imp, true_and] { contextual := tt },
assume h1i hib hmin,
rwa [← enat.coe_le_coe, enat.coe_get, ← pow_dvd_iff_le_multiplicity, nat.pow_eq_pow]
end⟩
namespace prime
lemma multiplicity_one {p : ℕ} (hp : p.prime) :
multiplicity p 1 = 0 :=
by rw [multiplicity.one_right (mt is_unit_nat.mp (ne_of_gt hp.one_lt))]
lemma multiplicity_mul {p m n : ℕ} (hp : p.prime) :
multiplicity p (m * n) = multiplicity p m + multiplicity p n :=
by rw [← int.coe_nat_multiplicity, ← int.coe_nat_multiplicity,
← int.coe_nat_multiplicity, int.coe_nat_mul, multiplicity.mul (nat.prime_iff_prime_int.1 hp)]
lemma multiplicity_pow {p m n : ℕ} (hp : p.prime) :
multiplicity p (m ^ n) = add_monoid.smul n (multiplicity p m) :=
by induction n; simp [nat.pow_succ, hp.multiplicity_mul, *, hp.multiplicity_one, succ_smul, add_comm]
lemma multiplicity_self {p : ℕ} (hp : p.prime) : multiplicity p p = 1 :=
have h₁ : ¬ is_unit (p : ℤ), from mt is_unit_int.1 (ne_of_gt hp.one_lt),
have h₂ : (p : ℤ) ≠ 0, from int.coe_nat_ne_zero.2 hp.ne_zero,
by rw [← int.coe_nat_multiplicity, multiplicity_self h₁ h₂]
lemma multiplicity_pow_self {p n : ℕ} (hp : p.prime) : multiplicity p (p ^ n) = n :=
by induction n; simp [hp.multiplicity_one, nat.pow_succ, hp.multiplicity_mul, *,
hp.multiplicity_self, succ_eq_add_one]
/-- The multiplicity of a prime in `fact n` is the sum of the quotients `n / p ^ i`.
This sum is expressed over the set `Ico 1 b` where `b` is any bound at least `n` -/
lemma multiplicity_fact {p : ℕ} (hp : p.prime) :
∀ {n b : ℕ}, n ≤ b → multiplicity p n.fact = ((Ico 1 b).sum (λ i, n / p ^ i) : ℕ)
| 0 b hb := by simp [Ico, hp.multiplicity_one]
| (n+1) b hb :=
calc multiplicity p (n+1).fact = multiplicity p n.fact + multiplicity p (n+1) :
by rw [fact_succ, hp.multiplicity_mul, add_comm]
... = ((Ico 1 b).sum (λ i, n / p ^ i) : ℕ) + ((finset.Ico 1 b).filter (λ i, p ^ i ∣ n+1)).card :
by rw [multiplicity_fact (le_of_succ_le hb),
← multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (succ_pos _) hb]
... = ((Ico 1 b).sum (λ i, n / p ^ i + if p^i ∣ n+1 then 1 else 0) : ℕ) :
by rw [sum_add_distrib, sum_boole]; simp
... = ((Ico 1 b).sum (λ i, (n + 1) / p ^ i) : ℕ) :
congr_arg coe $ finset.sum_congr rfl (by intros; simp [nat.succ_div]; congr)
/-- A prime power divides `fact n` iff it is at most the sum of the quotients `n / p ^ i`.
This sum is expressed over the set `Ico 1 b` where `b` is any bound at least `n` -/
lemma pow_dvd_fact_iff {p : ℕ} {n r b : ℕ} (hp : p.prime) (hbn : n ≤ b) :
p ^ r ∣ fact n ↔ r ≤ (Ico 1 b).sum (λ i, n / p ^ i) :=
by rw [← enat.coe_le_coe, ← hp.multiplicity_fact hbn, ← pow_dvd_iff_le_multiplicity, nat.pow_eq_pow]
lemma multiplicity_choose_aux {p n b k : ℕ} (hp : p.prime) (hkn : k ≤ n) :
(finset.Ico 1 b).sum (λ i, n / p ^ i) =
(finset.Ico 1 b).sum (λ i, k / p ^ i) + (finset.Ico 1 b).sum (λ i, (n - k) / p ^ i) +
((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card :=
calc (finset.Ico 1 b).sum (λ i, n / p ^ i)
= (finset.Ico 1 b).sum (λ i, (k + (n - k)) / p ^ i) :
by simp only [nat.add_sub_cancel' hkn]
... = (finset.Ico 1 b).sum (λ i, k / p ^ i + (n - k) / p ^ i +
if p ^ i ≤ k % p ^ i + (n - k) % p ^ i then 1 else 0) : by simp only [nat.add_div (nat.pow_pos hp.pos _)]
... = _ : begin simp only [sum_add_distrib], simp [sum_boole], end -- we have to use `sum_add_distrib` before `add_ite` fires.
/-- The multiplity of `p` in `choose n k` is the number of carries when `k` and `n - k`
are added in base `p`. The set is expressed by filtering `Ico 1 b` where `b`
is any bound at least `n`. -/
lemma multiplicity_choose {p n k b : ℕ} (hp : p.prime) (hkn : k ≤ n) (hnb : n ≤ b) :
multiplicity p (choose n k) =
((Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card :=
have h₁ : multiplicity p (choose n k) + multiplicity p (k.fact * (n - k).fact) =
((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card +
multiplicity p (k.fact * (n - k).fact),
begin
rw [← hp.multiplicity_mul, ← mul_assoc, choose_mul_fact_mul_fact hkn,
hp.multiplicity_fact hnb, hp.multiplicity_mul, hp.multiplicity_fact (le_trans hkn hnb),
hp.multiplicity_fact (le_trans (nat.sub_le_self _ _) hnb),
multiplicity_choose_aux hp hkn],
simp [add_comm],
end,
(enat.add_right_cancel_iff
(enat.ne_top_iff_dom.2 $
by exact finite_nat_iff.2 ⟨ne_of_gt hp.one_lt, mul_pos (fact_pos k) (fact_pos (n - k))⟩)).1
h₁
/-- A lower bound on the multiplicity of `p` in `choose n k`. -/
lemma multiplicity_le_multiplicity_choose_add {p : ℕ} (hp : p.prime) (n k : ℕ) :
multiplicity p n ≤ multiplicity p (choose n k) + multiplicity p k :=
if hkn : n < k then by simp [choose_eq_zero_of_lt hkn]
else if hk0 : k = 0 then by simp [hk0]
else if hn0 : n = 0 then by cases k; simp [hn0, *] at *
else begin
rw [multiplicity_choose hp (le_of_not_gt hkn) (le_refl _),
multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (nat.pos_of_ne_zero hk0) (le_of_not_gt hkn),
multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (nat.pos_of_ne_zero hn0) (le_refl _),
← enat.coe_add, enat.coe_le_coe],
calc ((Ico 1 n).filter (λ i, p ^ i ∣ n)).card
≤ ((Ico 1 n).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i) ∪
(Ico 1 n).filter (λ i, p ^ i ∣ k) ).card :
card_le_of_subset $ λ i, begin
have := @le_mod_add_mod_of_dvd_add_of_not_dvd k (n - k) (p ^ i),
simp [nat.add_sub_cancel' (le_of_not_gt hkn)] at * {contextual := tt},
tauto
end
... ≤ ((Ico 1 n).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card +
((Ico 1 n).filter (λ i, p ^ i ∣ k)).card :
card_union_le _ _
end
lemma multiplicity_choose_prime_pow {p n k : ℕ} (hp : p.prime)
(hkn : k ≤ p ^ n) (hk0 : 0 < k) :
multiplicity p (choose (p ^ n) k) + multiplicity p k = n :=
le_antisymm
(have hdisj : disjoint
((Ico 1 (p ^ n)).filter (λ i, p ^ i ≤ k % p ^ i + (p ^ n - k) % p ^ i))
((Ico 1 (p ^ n)).filter (λ i, p ^ i ∣ k)),
by simp [disjoint_right, *, dvd_iff_mod_eq_zero, nat.mod_lt _ (nat.pow_pos hp.pos _)]
{contextual := tt},
have filter_subset_Ico : filter (λ i, p ^ i ≤ k % p ^ i +
(p ^ n - k) % p ^ i ∨ p ^ i ∣ k) (Ico 1 (p ^ n)) ⊆ Ico 1 n.succ,
from begin
simp only [finset.subset_iff, Ico.mem, mem_filter, and_imp, true_and] {contextual := tt},
assume i h1i hip h,
refine lt_succ_of_le (le_of_not_gt (λ hin, _)),
have hpik : ¬ p ^ i ∣ k, from mt (le_of_dvd hk0)
(not_le_of_gt (lt_of_le_of_lt hkn (pow_right_strict_mono hp.two_le hin))),
have hpn : k % p ^ i + (p ^ n - k) % p ^ i < p ^ i,
from calc k % p ^ i + (p ^ n - k) % p ^ i
≤ k + (p ^ n - k) : add_le_add (mod_le _ _) (mod_le _ _)
... = p ^ n : nat.add_sub_cancel' hkn
... < p ^ i : pow_right_strict_mono hp.two_le hin,
simpa [hpik, not_le_of_gt hpn] using h
end,
begin
rw [multiplicity_choose hp hkn (le_refl _),
multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) hk0 hkn, ← enat.coe_add,
enat.coe_le_coe, ← card_disjoint_union hdisj, filter_union_right],
exact le_trans (card_le_of_subset filter_subset_Ico) (by simp)
end)
(by rw [← hp.multiplicity_pow_self];
exact multiplicity_le_multiplicity_choose_add hp _ _)
end prime
end nat
|
f9a43b074bb2d79a1d1c2fbee7bee9c797b22c57 | 37a833c924892ee3ecb911484775a6d6ebb8984d | /src/category_theory/universal/constructions/from_colimits.lean | 0d11ef8969ad1e7d421c3d8f10ddd1a628f0e633 | [] | no_license | silky/lean-category-theory | 28126e80564a1f99e9c322d86b3f7d750da0afa1 | 0f029a2364975f56ac727d31d867a18c95c22fd8 | refs/heads/master | 1,589,555,811,646 | 1,554,673,665,000 | 1,554,673,665,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,047 | 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.universal.constructions.from_limits
-- import category_theory.universal.opposites
-- open category_theory
-- open category_theory.initial
-- open category_theory.walking
-- open category_theory.universal.opposites
-- namespace category_theory.universal
-- universes u₁
-- variable {C : Type (u₁+1)}
-- variable [large_category C]
-- instance Coequalizers_from_Colimits [Cocomplete C] : has_Coequalizers.{u₁+1 u₁} C :=
-- {coequalizer := λ _ _ f g, Coequalizer_from_Equalizer_in_Opposite (@equalizer.{u₁+1 u₁} (Cᵒᵖ) _ _ _ _ f g)}
-- instance Coproducts_from_Colimits [Cocomplete C] : has_Coproducts C := {
-- coproduct := λ _ F, Coproduct_from_Product_in_Opposite (@product (Cᵒᵖ) _ (@universal.Products_from_Limits (Cᵒᵖ) _ (universal.opposites.Opposite_Complete_of_Cocomplete)) _ F)
-- }
-- end category_theory.universal
|
b5652722fe197d6b18b905f2460fd71ba4532c01 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/string_imp.lean | 19758b98dc66a252d76476222181b17b73f6d422 | [
"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 | 583 | lean | #eval ("abc" ++ "cde").length
#eval "abc".pop_back
#eval "".pop_back
#eval "abcd".pop_back
#eval ("abcd".mk_iterator.nextn 2).next_to_string
#eval ("abcd".mk_iterator.nextn 2).prev_to_string
#eval ("abcd".mk_iterator.nextn 10).next_to_string
#eval ("abcd".mk_iterator.nextn 10).prev_to_string
#eval "foo.lean".popn_back 5
#eval "foo.lean".backn 5
#eval "αβγ".pop_back
#eval "αβ".length
#eval ("αβcc".mk_iterator.next.insert "_foo_").to_string
#eval ("αβcc".mk_iterator.next.next.insert "_foo_").to_string
#eval ("αβcc".mk_iterator.next.next.prev.insert "_foo_").to_string
|
be00f4c9117cd07a71eeb483c366cd55d3b66aea | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /tests/lean/run/nicerNestedDos.lean | bf7df4d76f14ea96ba31c48e30d411d3d7f66f17 | [
"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 | 603 | lean |
def f (x : Nat) : IO Nat := do
IO.println "hello"
when (x > 5) do
IO.println ("x: " ++ toString x)
IO.println "done"
pure (x + 1)
#eval f 2
#eval f 10
def g (x : Nat) : StateT Nat Id Unit := do
when (x > 10) do
let s ← get
set (s + x)
pure ()
theorem ex1 : (g 10).run 1 = ((), 1) :=
rfl
theorem ex2 : (g 20).run 1 = ((), 21) :=
rfl
def h (x : Nat) : StateT Nat Id Unit := do
when (x > 10) do {
let s ← get;
set (s + x) -- we don't need to respect indentation when `{` `}` are used
}
pure ()
theorem ex3 : (h 10).run 1 = ((), 1) :=
rfl
theorem ex4 : (h 20).run 1 = ((), 21) :=
rfl
|
2e166b1c4b7275bc65eb6a7ed2c1ae81197a3e58 | 618003631150032a5676f229d13a079ac875ff77 | /src/deprecated/field.lean | 7f30b1ac4754f9d9bfa89a7c500f8c9aad67f391 | [
"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 | 769 | lean | /-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import deprecated.ring
import algebra.field
/-!
# Field properties of unbundled ring homomorphisms (deprecated)
-/
namespace is_ring_hom
open ring_hom (of)
section
variables {α : Type*} {β : Type*} [division_ring α] [division_ring β]
variables (f : α → β) [is_ring_hom f] {x y : α}
lemma map_ne_zero : f x ≠ 0 ↔ x ≠ 0 := (of f).map_ne_zero
lemma map_eq_zero : f x = 0 ↔ x = 0 := (of f).map_eq_zero
lemma map_inv : f x⁻¹ = (f x)⁻¹ := (of f).map_inv
lemma map_div : f (x / y) = f x / f y := (of f).map_div
lemma injective : function.injective f := (of f).injective
end
end is_ring_hom
|
1cbcb682d415690998756ea5f4937b414091aa54 | dfd42d30132c2867977fefe7edae98b6dc703aeb | /src/alexandroff'.lean | 719952d35848bb4a6a6f59fb081f36842a8263f6 | [] | no_license | justadzr/lean-2021 | 1e42057ac75c794c94b8f148a27a24150c685f68 | dfc6b30de2f27bdba5fbc51183e2b84e73a920d1 | refs/heads/master | 1,689,652,366,522 | 1,630,313,809,000 | 1,630,313,809,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 15,177 | lean | /-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang
-/
import topology.separation
import topology.opens
/-!
# The Alexandroff Compactification
We construct the Alexandroff compactification of an arbitrary topological space `X` and prove
some properties inherited from `X`.
## Main defintion
* `alexandroff`: the Alexandroff compactification
* `of`: the inclusion map defined by `option.some`. This map requires the argument
`topological_space X`
* `infty`: the extra point
## Main results
* The topological structure of `alexandroff X`
* The connectedness of `alexandroff X` for noncompact, preconnected `X`
* `alexandroff X` is `T₁` for a T₁ space `X`
* `alexandroff X` is Hausdorff if `X` is locally compact and Hausdorff
-/
noncomputable theory
open set
open_locale classical topological_space filter
section option_topology
/-- The one-point extension of a topological space -/
@[reducible]
def one_point_extension (X : Type*) [topological_space X] :
topological_space (option X) :=
{ is_open := λ s, if none ∈ s then is_compact (some⁻¹' s)ᶜ ∧ is_open (some⁻¹' s)
else is_open (some⁻¹' s),
is_open_univ := by simp,
is_open_inter :=
λ s t hs ht, begin
split_ifs at hs ht with h h' h' h' h,
{ simpa [h, h', compl_inter] using and.intro (hs.1.union ht.1) (hs.2.inter ht.2) },
{ simpa [h, h'] using hs.inter ht.2 },
{ simpa [h, h'] using hs.2.inter ht },
{ simpa [h, h'] using hs.inter ht }
end,
is_open_sUnion :=
λ S ht, begin
suffices : is_open (some⁻¹' ⋃₀S),
{ split_ifs with h,
{ obtain ⟨(a : set (option X)), ha, ha'⟩ := mem_sUnion.mp h,
specialize ht a ha,
rw if_pos ha' at ht,
refine ⟨compact_of_is_closed_subset ht.left this.is_closed_compl _, this⟩,
rw [compl_subset_compl, preimage_subset_iff],
intros y hy,
refine ⟨a, ha, hy⟩ },
{ exact this } },
rw is_open_iff_forall_mem_open,
simp only [and_imp, exists_prop, mem_Union, preimage_sUnion, mem_preimage, exists_imp_distrib],
intros y s hs hy,
refine ⟨some⁻¹' s, subset_subset_Union _ (subset_subset_Union hs (subset.refl _)), _,
mem_preimage.mpr hy⟩,
specialize ht s hs,
split_ifs at ht,
{ exact ht.right },
{ exact ht }
end }
local attribute [instance] one_point_extension
namespace one_point_extension
variables {X : Type*} {s : set (option X)}
lemma some_preimage_none : (some⁻¹' {none} : set X) = ∅ :=
by { ext, simp }
lemma some_mem_range_some (x : X) : some x ∈ (some '' (univ : set X)) :=
by simp
lemma none_not_mem_range_some : none ∉ some '' (univ : set X) .
@[simp] lemma none_not_mem_image_some {s : set X} : none ∉ some '' s :=
not_mem_subset (image_subset _ $ subset_univ _) none_not_mem_range_some
lemma union_none_eq_univ : (some '' univ ∪ {none}) = (univ : set (option X)) :=
begin
refine le_antisymm (subset_univ _) _,
rintros ⟨_|x⟩;
simp
end
lemma inter_none_eq_empty : (some '' univ) ∩ {none} = (∅ : set (option X)) :=
by { ext ⟨_|x⟩; simp }
variables [topological_space X]
lemma is_open_alexandroff_iff_aux :
is_open s ↔ if none ∈ s then is_compact (some⁻¹' s)ᶜ ∧ is_open (some⁻¹' s)
else is_open (some⁻¹' s) :=
iff.rfl
lemma is_open_iff_of_mem (h : none ∈ s) :
is_open s ↔ is_compact (some⁻¹' s)ᶜ ∧ is_closed (some⁻¹' s)ᶜ :=
by simp [is_open_alexandroff_iff_aux, h, is_closed_compl_iff]
lemma is_open_iff_of_not_mem (h : none ∉ s) :
is_open s ↔ is_open (some⁻¹' s) :=
by simp [is_open_alexandroff_iff_aux, h]
lemma is_open_of_is_open (h : is_open s) :
is_open (some⁻¹' s) :=
begin
by_cases H : none ∈ s,
{ simpa using ((is_open_iff_of_mem H).mp h).2 },
{ exact (is_open_iff_of_not_mem H).mp h }
end
lemma is_open_map_some : is_open_map (@some X) :=
λ s hs, begin
rw [← preimage_image_eq s (option.some_injective X)] at hs,
rwa is_open_iff_of_not_mem none_not_mem_image_some
end
lemma continuous_some : continuous (@some X) :=
continuous_def.mpr (λ s hs, is_open_of_is_open hs)
/-- An open set of the extension constructed from a closed compact set in `X`-/
def opens_of_compl {s : set X} (h : is_compact s ∧ is_closed s) :
topological_space.opens (option X) :=
⟨(some '' s)ᶜ, by { rw [is_open_iff_of_mem ((mem_compl_iff _ _).mpr none_not_mem_image_some),
preimage_compl, compl_compl, (option.some_injective X).preimage_image _], assumption' }⟩
lemma none_mem_opens_of_compl {s : set X} (h : is_compact s ∧ is_closed s) :
none ∈ (opens_of_compl h) :=
by { simp only [opens_of_compl, topological_space.opens.coe_mk],
exact mem_compl none_not_mem_image_some }
/-- The one-point extension is compact -/
@[reducible, nolint def_lemma]
def compact_space (X : Type*) [topological_space X] :
compact_space (option X) :=
{ compact_univ :=
begin
refine is_compact_of_finite_subcover (λ ι Z h H, _),
simp only [univ_subset_iff] at H ⊢,
rcases Union_eq_univ_iff.mp H none with ⟨K, hK⟩,
have minor₁ : is_compact (some⁻¹' Z K)ᶜ,
{ specialize h K, rw is_open_iff_of_mem hK at h, exact h.1 },
let p : ι → set X := λ i, some⁻¹' Z i,
have minor₂ : ∀ i, is_open (p i) := λ i, is_open_of_is_open (h i),
have minor₃ : (some⁻¹' Z K)ᶜ ⊆ ⋃ i, p i :=
by simp only [p, ← preimage_Union, H, preimage_univ, subset_univ],
rcases is_compact_iff_finite_subcover.mp minor₁ p minor₂ minor₃ with ⟨ι', H'⟩,
refine ⟨insert K ι', _⟩,
rw ← preimage_compl at H',
simp only [Union_eq_univ_iff],
intros x,
by_cases hx : x ∈ Z K,
{ exact ⟨K, mem_Union.mpr ⟨finset.mem_insert_self _ _, hx⟩⟩ },
{ have triv₁ : x ≠ none := (ne_of_mem_of_not_mem hK hx).symm,
rcases option.ne_none_iff_exists.mp triv₁ with ⟨y, hy⟩,
have triv₂ : some y ∈ {x} := mem_singleton_of_eq hy,
rw [← mem_compl_iff, ← singleton_subset_iff] at hx,
have : some⁻¹' {x} ⊆ some⁻¹' (Z K)ᶜ := λ y hy, hx hy,
have key : y ∈ ⋃ (i : ι) (H : i ∈ ι'), p i := this.trans H' (mem_preimage.mpr triv₂),
rcases mem_bUnion_iff'.mp key with ⟨i, hi, hyi⟩,
refine ⟨i, mem_Union.mpr ⟨finset.subset_insert _ ι' hi, _⟩⟩,
simpa [hy] using hyi }
end }
/-- The one-point extension of a T₁ space `X` is T₁-/
@[reducible, nolint def_lemma]
def t1_space [t1_space X] : t1_space (option X) :=
{ t1 :=
λ z, begin
cases z,
{ rw [← is_open_compl_iff, compl_eq_univ_diff, ← union_none_eq_univ,
union_diff_cancel_right (subset.antisymm_iff.mp inter_none_eq_empty).1],
exact is_open_map_some _ is_open_univ },
{ have : none ∈ ({some z}ᶜ : set (option X)) :=
mem_compl (λ w, (option.some_ne_none z).symm (mem_singleton_iff.mp w)),
rw [← is_open_compl_iff, is_open_iff_of_mem this],
rw [preimage_compl, compl_compl, ← image_singleton,
(option.some_injective X).preimage_image _],
exact ⟨is_compact_singleton, is_closed_singleton⟩ }
end }
/-- The one-point extension of a Hausdorff `X` is Hausdorff -/
@[reducible, nolint def_lemma]
def t2_space [locally_compact_space X] [t2_space X] : t2_space (option X) :=
{ t2 :=
λ x y hxy, begin
have key : ∀ (z : option X), z ≠ none →
∃ (u v : set (option X)), is_open u ∧ is_open v ∧ none ∈ u ∧ z ∈ v ∧ u ∩ v = ∅ :=
λ z h, begin
rcases option.ne_none_iff_exists.mp h with ⟨y', hy'⟩,
rcases exists_open_with_compact_closure y' with ⟨u, hu, huy', Hu⟩,
have minor₁ : _ ∧ is_closed (closure u) := ⟨Hu, is_closed_closure⟩,
refine ⟨opens_of_compl minor₁, some '' u, _⟩,
refine ⟨(opens_of_compl minor₁).2, is_open_map_some _ hu,
none_mem_opens_of_compl minor₁, ⟨y', huy', hy'⟩, _⟩,
simp only [opens_of_compl, topological_space.opens.coe_mk],
have minor₂ : (some '' closure u)ᶜ ∩ some '' u ⊆ (some '' u)ᶜ ∩ some '' u,
{ apply inter_subset_inter_left,
simp only [compl_subset_compl, image_subset _ (subset_closure)] },
rw compl_inter_self at minor₂,
exact eq_empty_of_subset_empty minor₂
end,
cases x; cases y,
{ simpa using hxy },
{ simpa using key y hxy.symm },
{ rcases key x hxy with ⟨u, v, hu, hv, hxu, hyv, huv⟩,
exact ⟨v, u, hv, hu, hyv, hxu, (inter_comm u v) ▸ huv⟩ },
{ have hxy' : x ≠ y := λ w, hxy ((option.some.inj_eq _ _).mpr w),
rcases t2_separation hxy' with ⟨u, v, hu, hv, hxu, hyv, huv⟩,
refine ⟨some '' u, some '' v, is_open_map_some _ hu, is_open_map_some _ hv,
⟨x, hxu, rfl⟩, ⟨y, hyv, rfl⟩, _⟩,
simp only [image_inter (option.some_injective X), huv, image_empty] }
end }
lemma dense_range_some (h : ¬ is_compact (univ : set X)) : dense (some '' (univ : set X)) :=
begin
refine dense_iff_inter_open.mpr (λ s hs Hs, _),
by_cases H : none ∈ s,
{ rw is_open_iff_of_mem H at hs,
have minor₁ : s ≠ {none},
{ by_contra w,
rw [not_not.mp w, some_preimage_none, compl_empty] at hs,
exact h hs.1 },
have minor₂ : some⁻¹' s ≠ ∅,
{ by_contra w,
rw [not_not, eq_empty_iff_forall_not_mem] at w,
simp only [mem_preimage] at w,
have : ∀ z ∈ s, z = none := λ z hz,
by_contra (λ w', let ⟨x, hx⟩ := option.ne_none_iff_exists'.mp w' in
by rw hx at hz; exact (w x) hz),
exact minor₁ (eq_singleton_iff_unique_mem.mpr ⟨H, this⟩) },
rcases ne_empty_iff_nonempty.mp minor₂ with ⟨x, hx⟩,
exact ⟨some x, hx, x, mem_univ _, rfl⟩ },
{ rcases Hs with ⟨z, hz⟩,
rcases option.ne_none_iff_exists'.mp (ne_of_mem_of_not_mem hz H) with ⟨x, hx⟩,
rw hx at hz,
exact ⟨some x, hz, x, mem_univ _, rfl⟩ }
end
lemma connected_space [preconnected_space X] (h : ¬ is_compact (univ : set X)) :
connected_space (option X) :=
{ is_preconnected_univ :=
begin
rw ← dense_iff_closure_eq.mp (dense_range_some h),
exact is_preconnected.closure
(is_preconnected_univ.image some continuous_some.continuous_on)
end,
to_nonempty := ⟨none⟩ }
end one_point_extension
end option_topology
section basic
/-- The Alexandroff extension of an arbitrary topological space `X` -/
@[nolint unused_arguments]
def alexandroff (X : Type*) [topological_space X] := option X
variables {X : Type*} [topological_space X]
/-- The embedding of `X` to its Alexandroff extension -/
def of : X → alexandroff X := some
/-- The range of the embedding -/
def range_of (X : Type*) [topological_space X] : set (alexandroff X) := of '' (univ : set X)
lemma of_apply {x : X} : of x = some x := rfl
lemma of_injective : function.injective (@of X _) :=
option.some_injective X
/-- The extra point in the extension -/
def infty : alexandroff X := none
local notation `∞` := infty
namespace alexandroff
instance : has_coe_t X (alexandroff X) := ⟨of⟩
instance : inhabited(alexandroff X) := ⟨∞⟩
@[norm_cast]
lemma coe_eq_coe {x y : X} : (x : alexandroff X) = y ↔ x = y :=
of_injective.eq_iff
@[simp] lemma coe_ne_infty (x : X) : (x : alexandroff X) ≠ ∞ .
@[simp] lemma infity_ne_coe (x : X) : ∞ ≠ (x : alexandroff X) .
@[simp] lemma of_eq_coe {x : X} : (of x : alexandroff X) = x := rfl
protected lemma prop_infty_of_prop_none {p : option X → Prop} (h : p none) : p infty :=
by simpa [infty] using h
/-- Recursor for `alexandroff` using the preferred forms `∞` and `↑x`. -/
@[elab_as_eliminator]
def rec_infty_coe (C : alexandroff X → Sort*) (h₁ : C infty) (h₂ : Π (x : X), C x) :
Π (z : alexandroff X), C z :=
option.rec h₁ h₂
lemma ne_infty_iff_exists {x : alexandroff X} :
x ≠ infty ↔ ∃ (y : X), x = y :=
by { induction x using alexandroff.rec_infty_coe; simp }
@[simp] lemma coe_mem_range_of (x : X) : (x : alexandroff X) ∈ (range_of X) :=
one_point_extension.some_mem_range_some x
lemma union_infty_eq_univ : (range_of X ∪ {∞}) = univ :=
one_point_extension.union_none_eq_univ
@[simp] lemma infty_not_mem_range_of : ∞ ∉ range_of X :=
one_point_extension.none_not_mem_image_some
@[simp] lemma not_mem_range_of_iff (x : alexandroff X) :
x ∉ range_of X ↔ x = ∞ :=
by { induction x using alexandroff.rec_infty_coe; simp }
@[simp] lemma infty_not_mem_image_of {s : set X} : ∞ ∉ of '' s :=
one_point_extension.none_not_mem_image_some
lemma inter_infty_eq_empty : (range_of X) ∩ {∞} = ∅ :=
one_point_extension.inter_none_eq_empty
lemma of_preimage_infty : (of⁻¹' {∞} : set X) = ∅ :=
one_point_extension.some_preimage_none
end alexandroff
end basic
section topology
open alexandroff
variables {X : Type*} [topological_space X]
instance : topological_space (alexandroff X) := one_point_extension X
variables {s : set (alexandroff X)} {s' : set X}
lemma is_open_alexandroff_iff_aux :
is_open s ↔ if infty ∈ s then is_compact (of⁻¹' s)ᶜ ∧ is_open (of⁻¹' s)
else is_open (of⁻¹' s) :=
iff.rfl
lemma is_open_iff_of_mem' (h : infty ∈ s) :
is_open s ↔ is_compact (of⁻¹' s)ᶜ ∧ is_open (of⁻¹' s) :=
by simp [is_open_alexandroff_iff_aux, h]
lemma is_open_iff_of_mem (h : infty ∈ s) :
is_open s ↔ is_compact (of⁻¹' s)ᶜ ∧ is_closed (of⁻¹' s)ᶜ :=
by simp [is_open_alexandroff_iff_aux, h, is_closed_compl_iff]
lemma is_open_iff_of_not_mem (h : infty ∉ s) :
is_open s ↔ is_open (of⁻¹' s) :=
by simp [is_open_alexandroff_iff_aux, h]
lemma is_open_of_is_open (h : is_open s) :
is_open (of⁻¹' s) :=
one_point_extension.is_open_of_is_open h
end topology
section topological
open alexandroff
variables {X : Type*} [topological_space X]
@[continuity] lemma continuous_of : continuous (@of X _) :=
one_point_extension.continuous_some
/-- An open set in `alexandroff X` constructed from a closed compact set in `X` -/
def opens_of_compl {s : set X} (h : is_compact s ∧ is_closed s) :
topological_space.opens (alexandroff X) :=
⟨(of '' s)ᶜ, (one_point_extension.opens_of_compl h).2⟩
lemma infty_mem_opens_of_compl {s : set X} (h : is_compact s ∧ is_closed s) :
infty ∈ (opens_of_compl h : set (alexandroff X)) :=
one_point_extension.none_mem_opens_of_compl h
lemma is_open_map_of : is_open_map (@of X _) :=
one_point_extension.is_open_map_some
lemma is_open_range_of : is_open (@range_of X _) :=
one_point_extension.is_open_map_some _ is_open_univ
instance : compact_space (alexandroff X) := one_point_extension.compact_space X
lemma dense_range_of (h : ¬ is_compact (univ : set X)) : dense (@range_of X _) :=
one_point_extension.dense_range_some h
lemma connected_space_alexandroff [preconnected_space X] (h : ¬ is_compact (univ : set X)) :
connected_space (alexandroff X) :=
one_point_extension.connected_space h
instance [t1_space X] : t1_space (alexandroff X) :=
one_point_extension.t1_space
instance [locally_compact_space X] [t2_space X] : t2_space (alexandroff X) :=
one_point_extension.t2_space
end topological
#lint |
66b1c3e534ab8e291f0ce5c2af6f421bc8918a96 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Init/Data/Char/Basic.lean | 918bae5688f512f2fa62397096cc3aae1a54900d | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 1,972 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import Init.Data.UInt
@[inline, reducible] def isValidChar (n : UInt32) : Prop :=
n < 0xd800 ∨ (0xdfff < n ∧ n < 0x110000)
namespace Char
protected def lt (a b : Char) : Prop := a.val < b.val
protected def le (a b : Char) : Prop := a.val ≤ b.val
instance : LT Char := ⟨Char.lt⟩
instance : LE Char := ⟨Char.le⟩
instance (a b : Char) : Decidable (a < b) :=
UInt32.decLt _ _
instance (a b : Char) : Decidable (a ≤ b) :=
UInt32.decLe _ _
abbrev isValidCharNat (n : Nat) : Prop :=
n < 0xd800 ∨ (0xdfff < n ∧ n < 0x110000)
theorem isValidUInt32 (n : Nat) (h : isValidCharNat n) : n < UInt32.size := by
match h with
| Or.inl h =>
apply Nat.lt_trans h
decide
| Or.inr ⟨_, h₂⟩ =>
apply Nat.lt_trans h₂
decide
theorem isValidChar_of_isValidChar_Nat (n : Nat) (h : isValidCharNat n) : isValidChar (UInt32.ofNat' n (isValidUInt32 n h)) :=
match h with
| Or.inl h => Or.inl h
| Or.inr ⟨h₁, h₂⟩ => Or.inr ⟨h₁, h₂⟩
theorem isValidChar_zero : isValidChar 0 :=
Or.inl (by decide)
@[inline] def toNat (c : Char) : Nat :=
c.val.toNat
instance : Inhabited Char where
default := 'A'
def isWhitespace (c : Char) : Bool :=
c = ' ' || c = '\t' || c = '\r' || c = '\n'
def isUpper (c : Char) : Bool :=
c.val ≥ 65 && c.val ≤ 90
def isLower (c : Char) : Bool :=
c.val ≥ 97 && c.val ≤ 122
def isAlpha (c : Char) : Bool :=
c.isUpper || c.isLower
def isDigit (c : Char) : Bool :=
c.val ≥ 48 && c.val ≤ 57
def isAlphanum (c : Char) : Bool :=
c.isAlpha || c.isDigit
def toLower (c : Char) : Char :=
let n := toNat c;
if n >= 65 ∧ n <= 90 then ofNat (n + 32) else c
def toUpper (c : Char) : Char :=
let n := toNat c;
if n >= 97 ∧ n <= 122 then ofNat (n - 32) else c
end Char
|
ea96e465900c9ec69063d4a791f4def0b7ccff13 | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/topology/metric_space/completion.lean | 9fe1fc311cf3ff5f51552e7773c5a4e81c382151 | [
"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 | 8,806 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sébastien Gouëzel
The completion of a metric space.
Completion of uniform spaces are already defined in `topology.uniform_space.completion`. We show
here that the uniform space completion of a metric space inherits a metric space structure,
by extending the distance to the completion and checking that it is indeed a distance, and that
it defines the same uniformity as the already defined uniform structure on the completion
-/
import topology.uniform_space.completion topology.metric_space.isometry
open lattice set filter uniform_space uniform_space.completion
noncomputable theory
universes u
variables {α : Type u} [metric_space α]
namespace metric
/-- The distance on the completion is obtained by extending the distance on the original space,
by uniform continuity. -/
instance : has_dist (completion α) :=
⟨λx y, completion.extension (λp:α×α, dist p.1 p.2) (completion.prod (x, y))⟩
/-- The new distance is uniformly continuous. -/
protected lemma completion.uniform_continuous_dist :
uniform_continuous (λp:completion α × completion α, dist p.1 p.2) :=
uniform_continuous.comp uniform_continuous_prod uniform_continuous_extension
/-- The new distance is an extension of the original distance. -/
protected lemma completion.dist_eq (x y : α) : dist (x : completion α) y = dist x y :=
begin
unfold dist,
rw [completion.prod_coe_coe, completion.extension_coe],
exact uniform_continuous_dist',
end
/- Let us check that the new distance satisfies the axioms of a distance, by starting from the
properties on α and extending them to `completion α` by continuity. -/
protected lemma completion.dist_self (x : completion α) : dist x x = 0 :=
begin
apply induction_on x,
{ refine is_closed_eq _ continuous_const,
have : continuous (λx : completion α, (x, x)) :=
continuous.prod_mk continuous_id continuous_id,
exact continuous.comp this completion.uniform_continuous_dist.continuous },
{ assume a,
rw [completion.dist_eq, dist_self] }
end
protected lemma completion.dist_comm (x y : completion α) : dist x y = dist y x :=
begin
apply induction_on₂ x y,
{ refine is_closed_eq completion.uniform_continuous_dist.continuous _,
exact continuous.comp continuous_swap completion.uniform_continuous_dist.continuous },
{ assume a b,
rw [completion.dist_eq, completion.dist_eq, dist_comm] }
end
protected lemma completion.dist_triangle (x y z : completion α) : dist x z ≤ dist x y + dist y z :=
begin
apply induction_on₃ x y z,
{ refine is_closed_le _ (continuous_add _ _),
{ have : continuous (λp : completion α × completion α × completion α, (p.1, p.2.2)) :=
continuous.prod_mk continuous_fst (continuous.comp continuous_snd continuous_snd),
exact continuous.comp this completion.uniform_continuous_dist.continuous },
{ have : continuous (λp : completion α × completion α × completion α, (p.1, p.2.1)) :=
continuous.prod_mk continuous_fst (continuous.comp continuous_snd continuous_fst),
exact continuous.comp this completion.uniform_continuous_dist.continuous },
{ have : continuous (λp : completion α × completion α × completion α, (p.2.1, p.2.2)) :=
continuous.prod_mk (continuous.comp continuous_snd continuous_fst)
(continuous.comp continuous_snd continuous_snd),
exact continuous.comp this completion.uniform_continuous_dist.continuous }},
{ assume a b c,
rw [completion.dist_eq, completion.dist_eq, completion.dist_eq],
exact dist_triangle a b c }
end
/-- Elements of the uniformity (defined generally for completions) can be characterized in terms
of the distance. -/
protected lemma completion.mem_uniformity_dist (s : set (completion α × completion α)) :
s ∈ uniformity (completion α) ↔ (∃ε>0, ∀{a b}, dist a b < ε → (a, b) ∈ s) :=
begin
split,
{ /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in α is an
entourage, so it contains an ε-neighborhood of the diagonal by definition of the entourages
in metric spaces. Then `t` contains an ε-neighborhood of the diagonal in `completion α`, as
closed properties pass to the completion. -/
assume hs,
rcases mem_uniformity_is_closed hs with ⟨t, ht, ⟨tclosed, ts⟩⟩,
have A : {x : α × α | (coe (x.1), coe (x.2)) ∈ t} ∈ uniformity α :=
uniform_continuous_def.1 (uniform_continuous_coe α) t ht,
rcases mem_uniformity_dist.1 A with ⟨ε, εpos, hε⟩,
refine ⟨ε, εpos, λx y hxy, _⟩,
have : ε ≤ dist x y ∨ (x, y) ∈ t,
{ apply induction_on₂ x y,
{ have : {x : completion α × completion α | ε ≤ dist (x.fst) (x.snd) ∨ (x.fst, x.snd) ∈ t}
= {p : completion α × completion α | ε ≤ dist p.1 p.2} ∪ t, by ext; simp,
rw this,
apply is_closed_union _ tclosed,
exact is_closed_le continuous_const completion.uniform_continuous_dist.continuous },
{ assume x y,
rw completion.dist_eq,
by_cases h : ε ≤ dist x y,
{ exact or.inl h },
{ have Z := hε (not_le.1 h),
simp only [set.mem_set_of_eq] at Z,
exact or.inr Z }}},
simp only [not_le.mpr hxy, false_or, not_le] at this,
exact ts this },
{ /- Start from a set `s` containing an ε-neighborhood of the diagonal in `completion α`. To show
that it is an entourage, we use the fact that `dist` is uniformly continuous on
`completion α × completion α` (this is a general property of the extension of uniformly
continuous functions). Therefore, the preimage of the ε-neighborhood of the diagonal in ℝ
is an entourage in `completion α × completion α`. Massaging this property, it follows that
the ε-neighborhood of the diagonal is an entourage in `completion α`, and therefore this is
also the case of `s`. -/
rintros ⟨ε, εpos, hε⟩,
let r : set (ℝ × ℝ) := {p | dist p.1 p.2 < ε},
have : r ∈ uniformity ℝ := metric.dist_mem_uniformity εpos,
have T := uniform_continuous_def.1 (@completion.uniform_continuous_dist α _) r this,
simp only [uniformity_prod_eq_prod, mem_prod_iff, exists_prop,
filter.mem_map, set.mem_set_of_eq] at T,
rcases T with ⟨t1, ht1, t2, ht2, ht⟩,
refine mem_sets_of_superset ht1 _,
have A : ∀a b : completion α, (a, b) ∈ t1 → dist a b < ε,
{ assume a b hab,
have : ((a, b), (a, a)) ∈ set.prod t1 t2 := ⟨hab, refl_mem_uniformity ht2⟩,
have I := ht this,
simp [completion.dist_self, real.dist_eq, completion.dist_comm] at I,
exact lt_of_le_of_lt (le_abs_self _) I },
show t1 ⊆ s,
{ rintros ⟨a, b⟩ hp,
have : dist a b < ε := A a b hp,
exact hε this }}
end
/-- If two points are at distance 0, then they coincide. -/
protected lemma completion.eq_of_dist_eq_zero (x y : completion α) (h : dist x y = 0) : x = y :=
begin
/- This follows from the separation of `completion α` and from the description of
entourages in terms of the distance. -/
have : separated (completion α) := by apply_instance,
refine separated_def.1 this x y (λs hs, _),
rcases (completion.mem_uniformity_dist s).1 hs with ⟨ε, εpos, hε⟩,
rw ← h at εpos,
exact hε εpos
end
/- Reformulate `completion.mem_uniformity_dist` in terms that are suitable for the definition
of the metric space structure. -/
protected lemma completion.uniformity_dist' :
uniformity (completion α) = (⨅ε:{ε:ℝ // ε>0}, principal {p | dist p.1 p.2 < ε.val}) :=
begin
ext s, rw mem_infi,
{ simp [completion.mem_uniformity_dist, subset_def] },
{ rintro ⟨r, hr⟩ ⟨p, hp⟩, use ⟨min r p, lt_min hr hp⟩,
simp [lt_min_iff, (≥)] {contextual := tt} },
{ exact ⟨⟨1, zero_lt_one⟩⟩ }
end
protected lemma completion.uniformity_dist :
uniformity (completion α) = (⨅ ε>0, principal {p | dist p.1 p.2 < ε}) :=
by simpa [infi_subtype] using @completion.uniformity_dist' α _
/-- Metric space structure on the completion of a metric space. -/
instance completion.metric_space : metric_space (completion α) :=
{ dist_self := completion.dist_self,
eq_of_dist_eq_zero := completion.eq_of_dist_eq_zero,
dist_comm := completion.dist_comm,
dist_triangle := completion.dist_triangle,
to_uniform_space := by apply_instance,
uniformity_dist := completion.uniformity_dist }
/-- The embedding of a metric space in its completion is an isometry. -/
lemma completion.coe_isometry : isometry (coe : α → completion α) :=
isometry_emetric_iff_metric.2 completion.dist_eq
end metric
|
8d9073c86a2ab742682d1223ea3f6fde0a04b75e | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/local_extr_auto.lean | 0e9605327cf21fef864379cc1a712c265fc32d9f | [] | 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 | 33,205 | lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.order.filter.extr
import Mathlib.topology.continuous_on
import Mathlib.PostPort
universes u v w x
namespace Mathlib
/-!
# Local extrema of functions on topological spaces
## Main definitions
This file defines special versions of `is_*_filter f a l`, `*=min/max/extr`,
from `order/filter/extr` for two kinds of filters: `nhds_within` and `nhds`.
These versions are called `is_local_*_on` and `is_local_*`, respectively.
## Main statements
Many lemmas in this file restate those from `order/filter/extr`, and you can find
a detailed documentation there. These convenience lemmas are provided only to make the dot notation
return propositions of expected types, not just `is_*_filter`.
Here is the list of statements specific to these two types of filters:
* `is_local_*.on`, `is_local_*_on.on_subset`: restrict to a subset;
* `is_local_*_on.inter` : intersect the set with another one;
* `is_*_on.localize` : a global extremum is a local extremum too.
* `is_[local_]*_on.is_local_*` : if we have `is_local_*_on f s a` and `s ∈ 𝓝 a`,
then we have `is_local_* f a`.
-/
/-- `is_local_min_on f s a` means that `f a ≤ f x` for all `x ∈ s` in some neighborhood of `a`. -/
def is_local_min_on {α : Type u} {β : Type v} [topological_space α] [preorder β] (f : α → β)
(s : set α) (a : α) :=
is_min_filter f (nhds_within a s) a
/-- `is_local_max_on f s a` means that `f x ≤ f a` for all `x ∈ s` in some neighborhood of `a`. -/
def is_local_max_on {α : Type u} {β : Type v} [topological_space α] [preorder β] (f : α → β)
(s : set α) (a : α) :=
is_max_filter f (nhds_within a s) a
/-- `is_local_extr_on f s a` means `is_local_min_on f s a ∨ is_local_max_on f s a`. -/
def is_local_extr_on {α : Type u} {β : Type v} [topological_space α] [preorder β] (f : α → β)
(s : set α) (a : α) :=
is_extr_filter f (nhds_within a s) a
/-- `is_local_min f a` means that `f a ≤ f x` for all `x` in some neighborhood of `a`. -/
def is_local_min {α : Type u} {β : Type v} [topological_space α] [preorder β] (f : α → β) (a : α) :=
is_min_filter f (nhds a) a
/-- `is_local_max f a` means that `f x ≤ f a` for all `x ∈ s` in some neighborhood of `a`. -/
def is_local_max {α : Type u} {β : Type v} [topological_space α] [preorder β] (f : α → β) (a : α) :=
is_max_filter f (nhds a) a
/-- `is_local_extr_on f s a` means `is_local_min_on f s a ∨ is_local_max_on f s a`. -/
def is_local_extr {α : Type u} {β : Type v} [topological_space α] [preorder β] (f : α → β)
(a : α) :=
is_extr_filter f (nhds a) a
theorem is_local_extr_on.elim {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} {p : Prop} :
is_local_extr_on f s a → (is_local_min_on f s a → p) → (is_local_max_on f s a → p) → p :=
or.elim
theorem is_local_extr.elim {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{a : α} {p : Prop} : is_local_extr f a → (is_local_min f a → p) → (is_local_max f a → p) → p :=
or.elim
/-! ### Restriction to (sub)sets -/
theorem is_local_min.on {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{a : α} (h : is_local_min f a) (s : set α) : is_local_min_on f s a :=
is_min_filter.filter_inf h (filter.principal s)
theorem is_local_max.on {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{a : α} (h : is_local_max f a) (s : set α) : is_local_max_on f s a :=
is_max_filter.filter_inf h (filter.principal s)
theorem is_local_extr.on {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{a : α} (h : is_local_extr f a) (s : set α) : is_local_extr_on f s a :=
is_extr_filter.filter_inf h (filter.principal s)
theorem is_local_min_on.on_subset {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} {t : set α} (hf : is_local_min_on f t a) (h : s ⊆ t) :
is_local_min_on f s a :=
is_min_filter.filter_mono hf (nhds_within_mono a h)
theorem is_local_max_on.on_subset {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} {t : set α} (hf : is_local_max_on f t a) (h : s ⊆ t) :
is_local_max_on f s a :=
is_max_filter.filter_mono hf (nhds_within_mono a h)
theorem is_local_extr_on.on_subset {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} {t : set α} (hf : is_local_extr_on f t a) (h : s ⊆ t) :
is_local_extr_on f s a :=
is_extr_filter.filter_mono hf (nhds_within_mono a h)
theorem is_local_min_on.inter {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_local_min_on f s a) (t : set α) :
is_local_min_on f (s ∩ t) a :=
is_local_min_on.on_subset hf (set.inter_subset_left s t)
theorem is_local_max_on.inter {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_local_max_on f s a) (t : set α) :
is_local_max_on f (s ∩ t) a :=
is_local_max_on.on_subset hf (set.inter_subset_left s t)
theorem is_local_extr_on.inter {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_local_extr_on f s a) (t : set α) :
is_local_extr_on f (s ∩ t) a :=
is_local_extr_on.on_subset hf (set.inter_subset_left s t)
theorem is_min_on.localize {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{s : set α} {a : α} (hf : is_min_on f s a) : is_local_min_on f s a :=
is_min_filter.filter_mono hf inf_le_right
theorem is_max_on.localize {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{s : set α} {a : α} (hf : is_max_on f s a) : is_local_max_on f s a :=
is_max_filter.filter_mono hf inf_le_right
theorem is_extr_on.localize {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{s : set α} {a : α} (hf : is_extr_on f s a) : is_local_extr_on f s a :=
is_extr_filter.filter_mono hf inf_le_right
theorem is_local_min_on.is_local_min {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_local_min_on f s a) (hs : s ∈ nhds a) :
is_local_min f a :=
(fun (this : nhds a ≤ filter.principal s) =>
is_min_filter.filter_mono hf (le_inf (le_refl (nhds a)) this))
(iff.mpr filter.le_principal_iff hs)
theorem is_local_max_on.is_local_max {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_local_max_on f s a) (hs : s ∈ nhds a) :
is_local_max f a :=
(fun (this : nhds a ≤ filter.principal s) =>
is_max_filter.filter_mono hf (le_inf (le_refl (nhds a)) this))
(iff.mpr filter.le_principal_iff hs)
theorem is_local_extr_on.is_local_extr {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_local_extr_on f s a) (hs : s ∈ nhds a) :
is_local_extr f a :=
is_local_extr_on.elim hf
(fun (hf : is_local_min_on f s a) => is_min_filter.is_extr (is_local_min_on.is_local_min hf hs))
fun (hf : is_local_max_on f s a) => is_max_filter.is_extr (is_local_max_on.is_local_max hf hs)
theorem is_min_on.is_local_min {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_min_on f s a) (hs : s ∈ nhds a) : is_local_min f a :=
is_local_min_on.is_local_min (is_min_on.localize hf) hs
theorem is_max_on.is_local_max {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_max_on f s a) (hs : s ∈ nhds a) : is_local_max f a :=
is_local_max_on.is_local_max (is_max_on.localize hf) hs
theorem is_extr_on.is_local_extr {α : Type u} {β : Type v} [topological_space α] [preorder β]
{f : α → β} {s : set α} {a : α} (hf : is_extr_on f s a) (hs : s ∈ nhds a) : is_local_extr f a :=
is_local_extr_on.is_local_extr (is_extr_on.localize hf) hs
/-! ### Constant -/
theorem is_local_min_on_const {α : Type u} {β : Type v} [topological_space α] [preorder β]
{s : set α} {a : α} {b : β} : is_local_min_on (fun (_x : α) => b) s a :=
is_min_filter_const
theorem is_local_max_on_const {α : Type u} {β : Type v} [topological_space α] [preorder β]
{s : set α} {a : α} {b : β} : is_local_max_on (fun (_x : α) => b) s a :=
is_max_filter_const
theorem is_local_extr_on_const {α : Type u} {β : Type v} [topological_space α] [preorder β]
{s : set α} {a : α} {b : β} : is_local_extr_on (fun (_x : α) => b) s a :=
is_extr_filter_const
theorem is_local_min_const {α : Type u} {β : Type v} [topological_space α] [preorder β] {a : α}
{b : β} : is_local_min (fun (_x : α) => b) a :=
is_min_filter_const
theorem is_local_max_const {α : Type u} {β : Type v} [topological_space α] [preorder β] {a : α}
{b : β} : is_local_max (fun (_x : α) => b) a :=
is_max_filter_const
theorem is_local_extr_const {α : Type u} {β : Type v} [topological_space α] [preorder β] {a : α}
{b : β} : is_local_extr (fun (_x : α) => b) a :=
is_extr_filter_const
/-! ### Composition with (anti)monotone functions -/
theorem is_local_min.comp_mono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {a : α} (hf : is_local_min f a) {g : β → γ}
(hg : monotone g) : is_local_min (g ∘ f) a :=
is_min_filter.comp_mono hf hg
theorem is_local_max.comp_mono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {a : α} (hf : is_local_max f a) {g : β → γ}
(hg : monotone g) : is_local_max (g ∘ f) a :=
is_max_filter.comp_mono hf hg
theorem is_local_extr.comp_mono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {a : α} (hf : is_local_extr f a) {g : β → γ}
(hg : monotone g) : is_local_extr (g ∘ f) a :=
is_extr_filter.comp_mono hf hg
theorem is_local_min.comp_antimono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {a : α} (hf : is_local_min f a) {g : β → γ}
(hg : ∀ {x y : β}, x ≤ y → g y ≤ g x) : is_local_max (g ∘ f) a :=
is_min_filter.comp_antimono hf hg
theorem is_local_max.comp_antimono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {a : α} (hf : is_local_max f a) {g : β → γ}
(hg : ∀ {x y : β}, x ≤ y → g y ≤ g x) : is_local_min (g ∘ f) a :=
is_max_filter.comp_antimono hf hg
theorem is_local_extr.comp_antimono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {a : α} (hf : is_local_extr f a) {g : β → γ}
(hg : ∀ {x y : β}, x ≤ y → g y ≤ g x) : is_local_extr (g ∘ f) a :=
is_extr_filter.comp_antimono hf hg
theorem is_local_min_on.comp_mono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} (hf : is_local_min_on f s a)
{g : β → γ} (hg : monotone g) : is_local_min_on (g ∘ f) s a :=
is_min_filter.comp_mono hf hg
theorem is_local_max_on.comp_mono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} (hf : is_local_max_on f s a)
{g : β → γ} (hg : monotone g) : is_local_max_on (g ∘ f) s a :=
is_max_filter.comp_mono hf hg
theorem is_local_extr_on.comp_mono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} (hf : is_local_extr_on f s a)
{g : β → γ} (hg : monotone g) : is_local_extr_on (g ∘ f) s a :=
is_extr_filter.comp_mono hf hg
theorem is_local_min_on.comp_antimono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} (hf : is_local_min_on f s a)
{g : β → γ} (hg : ∀ {x y : β}, x ≤ y → g y ≤ g x) : is_local_max_on (g ∘ f) s a :=
is_min_filter.comp_antimono hf hg
theorem is_local_max_on.comp_antimono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} (hf : is_local_max_on f s a)
{g : β → γ} (hg : ∀ {x y : β}, x ≤ y → g y ≤ g x) : is_local_min_on (g ∘ f) s a :=
is_max_filter.comp_antimono hf hg
theorem is_local_extr_on.comp_antimono {α : Type u} {β : Type v} {γ : Type w} [topological_space α]
[preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} (hf : is_local_extr_on f s a)
{g : β → γ} (hg : ∀ {x y : β}, x ≤ y → g y ≤ g x) : is_local_extr_on (g ∘ f) s a :=
is_extr_filter.comp_antimono hf hg
theorem is_local_min.bicomp_mono {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
[topological_space α] [preorder β] [preorder γ] {f : α → β} {a : α} [preorder δ]
{op : β → γ → δ} (hop : relator.lift_fun LessEq (LessEq ⇒ LessEq) op op) (hf : is_local_min f a)
{g : α → γ} (hg : is_local_min g a) : is_local_min (fun (x : α) => op (f x) (g x)) a :=
is_min_filter.bicomp_mono hop hf hg
theorem is_local_max.bicomp_mono {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
[topological_space α] [preorder β] [preorder γ] {f : α → β} {a : α} [preorder δ]
{op : β → γ → δ} (hop : relator.lift_fun LessEq (LessEq ⇒ LessEq) op op) (hf : is_local_max f a)
{g : α → γ} (hg : is_local_max g a) : is_local_max (fun (x : α) => op (f x) (g x)) a :=
is_max_filter.bicomp_mono hop hf hg
-- No `extr` version because we need `hf` and `hg` to be of the same kind
theorem is_local_min_on.bicomp_mono {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
[topological_space α] [preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} [preorder δ]
{op : β → γ → δ} (hop : relator.lift_fun LessEq (LessEq ⇒ LessEq) op op)
(hf : is_local_min_on f s a) {g : α → γ} (hg : is_local_min_on g s a) :
is_local_min_on (fun (x : α) => op (f x) (g x)) s a :=
is_min_filter.bicomp_mono hop hf hg
theorem is_local_max_on.bicomp_mono {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
[topological_space α] [preorder β] [preorder γ] {f : α → β} {s : set α} {a : α} [preorder δ]
{op : β → γ → δ} (hop : relator.lift_fun LessEq (LessEq ⇒ LessEq) op op)
(hf : is_local_max_on f s a) {g : α → γ} (hg : is_local_max_on g s a) :
is_local_max_on (fun (x : α) => op (f x) (g x)) s a :=
is_max_filter.bicomp_mono hop hf hg
/-! ### Composition with `continuous_at` -/
theorem is_local_min.comp_continuous {α : Type u} {β : Type v} {δ : Type x} [topological_space α]
[preorder β] {f : α → β} [topological_space δ] {g : δ → α} {b : δ} (hf : is_local_min f (g b))
(hg : continuous_at g b) : is_local_min (f ∘ g) b :=
hg hf
theorem is_local_max.comp_continuous {α : Type u} {β : Type v} {δ : Type x} [topological_space α]
[preorder β] {f : α → β} [topological_space δ] {g : δ → α} {b : δ} (hf : is_local_max f (g b))
(hg : continuous_at g b) : is_local_max (f ∘ g) b :=
hg hf
theorem is_local_extr.comp_continuous {α : Type u} {β : Type v} {δ : Type x} [topological_space α]
[preorder β] {f : α → β} [topological_space δ] {g : δ → α} {b : δ} (hf : is_local_extr f (g b))
(hg : continuous_at g b) : is_local_extr (f ∘ g) b :=
is_extr_filter.comp_tendsto hf hg
theorem is_local_min.comp_continuous_on {α : Type u} {β : Type v} {δ : Type x} [topological_space α]
[preorder β] {f : α → β} [topological_space δ] {s : set δ} {g : δ → α} {b : δ}
(hf : is_local_min f (g b)) (hg : continuous_on g s) (hb : b ∈ s) :
is_local_min_on (f ∘ g) s b :=
is_min_filter.comp_tendsto hf (hg b hb)
theorem is_local_max.comp_continuous_on {α : Type u} {β : Type v} {δ : Type x} [topological_space α]
[preorder β] {f : α → β} [topological_space δ] {s : set δ} {g : δ → α} {b : δ}
(hf : is_local_max f (g b)) (hg : continuous_on g s) (hb : b ∈ s) :
is_local_max_on (f ∘ g) s b :=
is_max_filter.comp_tendsto hf (hg b hb)
theorem is_local_extr.comp_continuous_on {α : Type u} {β : Type v} {δ : Type x}
[topological_space α] [preorder β] {f : α → β} [topological_space δ] {s : set δ} (g : δ → α)
{b : δ} (hf : is_local_extr f (g b)) (hg : continuous_on g s) (hb : b ∈ s) :
is_local_extr_on (f ∘ g) s b :=
is_local_extr.elim hf
(fun (hf : is_local_min f (g b)) =>
is_min_filter.is_extr (is_local_min.comp_continuous_on hf hg hb))
fun (hf : is_local_max f (g b)) =>
is_max_filter.is_extr (is_local_max.comp_continuous_on hf hg hb)
theorem is_local_min_on.comp_continuous_on {α : Type u} {β : Type v} {δ : Type x}
[topological_space α] [preorder β] {f : α → β} [topological_space δ] {t : set α} {s : set δ}
{g : δ → α} {b : δ} (hf : is_local_min_on f t (g b)) (hst : s ⊆ g ⁻¹' t)
(hg : continuous_on g s) (hb : b ∈ s) : is_local_min_on (f ∘ g) s b :=
is_min_filter.comp_tendsto hf
(tendsto_nhds_within_mono_right (iff.mpr set.image_subset_iff hst)
(continuous_within_at.tendsto_nhds_within_image (hg b hb)))
theorem is_local_max_on.comp_continuous_on {α : Type u} {β : Type v} {δ : Type x}
[topological_space α] [preorder β] {f : α → β} [topological_space δ] {t : set α} {s : set δ}
{g : δ → α} {b : δ} (hf : is_local_max_on f t (g b)) (hst : s ⊆ g ⁻¹' t)
(hg : continuous_on g s) (hb : b ∈ s) : is_local_max_on (f ∘ g) s b :=
is_max_filter.comp_tendsto hf
(tendsto_nhds_within_mono_right (iff.mpr set.image_subset_iff hst)
(continuous_within_at.tendsto_nhds_within_image (hg b hb)))
theorem is_local_extr_on.comp_continuous_on {α : Type u} {β : Type v} {δ : Type x}
[topological_space α] [preorder β] {f : α → β} [topological_space δ] {t : set α} {s : set δ}
(g : δ → α) {b : δ} (hf : is_local_extr_on f t (g b)) (hst : s ⊆ g ⁻¹' t)
(hg : continuous_on g s) (hb : b ∈ s) : is_local_extr_on (f ∘ g) s b :=
is_local_extr_on.elim hf
(fun (hf : is_local_min_on f t (g b)) =>
is_min_filter.is_extr (is_local_min_on.comp_continuous_on hf hst hg hb))
fun (hf : is_local_max_on f t (g b)) =>
is_max_filter.is_extr (is_local_max_on.comp_continuous_on hf hst hg hb)
/-! ### Pointwise addition -/
theorem is_local_min.add {α : Type u} {β : Type v} [topological_space α] [ordered_add_comm_monoid β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_min f a) (hg : is_local_min g a) :
is_local_min (fun (x : α) => f x + g x) a :=
is_min_filter.add hf hg
theorem is_local_max.add {α : Type u} {β : Type v} [topological_space α] [ordered_add_comm_monoid β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_max f a) (hg : is_local_max g a) :
is_local_max (fun (x : α) => f x + g x) a :=
is_max_filter.add hf hg
theorem is_local_min_on.add {α : Type u} {β : Type v} [topological_space α]
[ordered_add_comm_monoid β] {f : α → β} {g : α → β} {a : α} {s : set α}
(hf : is_local_min_on f s a) (hg : is_local_min_on g s a) :
is_local_min_on (fun (x : α) => f x + g x) s a :=
is_min_filter.add hf hg
theorem is_local_max_on.add {α : Type u} {β : Type v} [topological_space α]
[ordered_add_comm_monoid β] {f : α → β} {g : α → β} {a : α} {s : set α}
(hf : is_local_max_on f s a) (hg : is_local_max_on g s a) :
is_local_max_on (fun (x : α) => f x + g x) s a :=
is_max_filter.add hf hg
/-! ### Pointwise negation and subtraction -/
theorem is_local_min.neg {α : Type u} {β : Type v} [topological_space α] [ordered_add_comm_group β]
{f : α → β} {a : α} (hf : is_local_min f a) : is_local_max (fun (x : α) => -f x) a :=
is_min_filter.neg hf
theorem is_local_max.neg {α : Type u} {β : Type v} [topological_space α] [ordered_add_comm_group β]
{f : α → β} {a : α} (hf : is_local_max f a) : is_local_min (fun (x : α) => -f x) a :=
is_max_filter.neg hf
theorem is_local_extr.neg {α : Type u} {β : Type v} [topological_space α] [ordered_add_comm_group β]
{f : α → β} {a : α} (hf : is_local_extr f a) : is_local_extr (fun (x : α) => -f x) a :=
is_extr_filter.neg hf
theorem is_local_min_on.neg {α : Type u} {β : Type v} [topological_space α]
[ordered_add_comm_group β] {f : α → β} {a : α} {s : set α} (hf : is_local_min_on f s a) :
is_local_max_on (fun (x : α) => -f x) s a :=
is_min_filter.neg hf
theorem is_local_max_on.neg {α : Type u} {β : Type v} [topological_space α]
[ordered_add_comm_group β] {f : α → β} {a : α} {s : set α} (hf : is_local_max_on f s a) :
is_local_min_on (fun (x : α) => -f x) s a :=
is_max_filter.neg hf
theorem is_local_extr_on.neg {α : Type u} {β : Type v} [topological_space α]
[ordered_add_comm_group β] {f : α → β} {a : α} {s : set α} (hf : is_local_extr_on f s a) :
is_local_extr_on (fun (x : α) => -f x) s a :=
is_extr_filter.neg hf
theorem is_local_min.sub {α : Type u} {β : Type v} [topological_space α] [ordered_add_comm_group β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_min f a) (hg : is_local_max g a) :
is_local_min (fun (x : α) => f x - g x) a :=
is_min_filter.sub hf hg
theorem is_local_max.sub {α : Type u} {β : Type v} [topological_space α] [ordered_add_comm_group β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_max f a) (hg : is_local_min g a) :
is_local_max (fun (x : α) => f x - g x) a :=
is_max_filter.sub hf hg
theorem is_local_min_on.sub {α : Type u} {β : Type v} [topological_space α]
[ordered_add_comm_group β] {f : α → β} {g : α → β} {a : α} {s : set α}
(hf : is_local_min_on f s a) (hg : is_local_max_on g s a) :
is_local_min_on (fun (x : α) => f x - g x) s a :=
is_min_filter.sub hf hg
theorem is_local_max_on.sub {α : Type u} {β : Type v} [topological_space α]
[ordered_add_comm_group β] {f : α → β} {g : α → β} {a : α} {s : set α}
(hf : is_local_max_on f s a) (hg : is_local_min_on g s a) :
is_local_max_on (fun (x : α) => f x - g x) s a :=
is_max_filter.sub hf hg
/-! ### Pointwise `sup`/`inf` -/
theorem is_local_min.sup {α : Type u} {β : Type v} [topological_space α] [semilattice_sup β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_min f a) (hg : is_local_min g a) :
is_local_min (fun (x : α) => f x ⊔ g x) a :=
is_min_filter.sup hf hg
theorem is_local_max.sup {α : Type u} {β : Type v} [topological_space α] [semilattice_sup β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_max f a) (hg : is_local_max g a) :
is_local_max (fun (x : α) => f x ⊔ g x) a :=
is_max_filter.sup hf hg
theorem is_local_min_on.sup {α : Type u} {β : Type v} [topological_space α] [semilattice_sup β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_min_on f s a)
(hg : is_local_min_on g s a) : is_local_min_on (fun (x : α) => f x ⊔ g x) s a :=
is_min_filter.sup hf hg
theorem is_local_max_on.sup {α : Type u} {β : Type v} [topological_space α] [semilattice_sup β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_max_on f s a)
(hg : is_local_max_on g s a) : is_local_max_on (fun (x : α) => f x ⊔ g x) s a :=
is_max_filter.sup hf hg
theorem is_local_min.inf {α : Type u} {β : Type v} [topological_space α] [semilattice_inf β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_min f a) (hg : is_local_min g a) :
is_local_min (fun (x : α) => f x ⊓ g x) a :=
is_min_filter.inf hf hg
theorem is_local_max.inf {α : Type u} {β : Type v} [topological_space α] [semilattice_inf β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_max f a) (hg : is_local_max g a) :
is_local_max (fun (x : α) => f x ⊓ g x) a :=
is_max_filter.inf hf hg
theorem is_local_min_on.inf {α : Type u} {β : Type v} [topological_space α] [semilattice_inf β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_min_on f s a)
(hg : is_local_min_on g s a) : is_local_min_on (fun (x : α) => f x ⊓ g x) s a :=
is_min_filter.inf hf hg
theorem is_local_max_on.inf {α : Type u} {β : Type v} [topological_space α] [semilattice_inf β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_max_on f s a)
(hg : is_local_max_on g s a) : is_local_max_on (fun (x : α) => f x ⊓ g x) s a :=
is_max_filter.inf hf hg
/-! ### Pointwise `min`/`max` -/
theorem is_local_min.min {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_min f a) (hg : is_local_min g a) :
is_local_min (fun (x : α) => min (f x) (g x)) a :=
is_min_filter.min hf hg
theorem is_local_max.min {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_max f a) (hg : is_local_max g a) :
is_local_max (fun (x : α) => min (f x) (g x)) a :=
is_max_filter.min hf hg
theorem is_local_min_on.min {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_min_on f s a)
(hg : is_local_min_on g s a) : is_local_min_on (fun (x : α) => min (f x) (g x)) s a :=
is_min_filter.min hf hg
theorem is_local_max_on.min {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_max_on f s a)
(hg : is_local_max_on g s a) : is_local_max_on (fun (x : α) => min (f x) (g x)) s a :=
is_max_filter.min hf hg
theorem is_local_min.max {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_min f a) (hg : is_local_min g a) :
is_local_min (fun (x : α) => max (f x) (g x)) a :=
is_min_filter.max hf hg
theorem is_local_max.max {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} (hf : is_local_max f a) (hg : is_local_max g a) :
is_local_max (fun (x : α) => max (f x) (g x)) a :=
is_max_filter.max hf hg
theorem is_local_min_on.max {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_min_on f s a)
(hg : is_local_min_on g s a) : is_local_min_on (fun (x : α) => max (f x) (g x)) s a :=
is_min_filter.max hf hg
theorem is_local_max_on.max {α : Type u} {β : Type v} [topological_space α] [linear_order β]
{f : α → β} {g : α → β} {a : α} {s : set α} (hf : is_local_max_on f s a)
(hg : is_local_max_on g s a) : is_local_max_on (fun (x : α) => max (f x) (g x)) s a :=
is_max_filter.max hf hg
/-! ### Relation with `eventually` comparisons of two functions -/
theorem filter.eventually_le.is_local_max_on {α : Type u} {β : Type v} [topological_space α]
[preorder β] {s : set α} {f : α → β} {g : α → β} {a : α}
(hle : filter.eventually_le (nhds_within a s) g f) (hfga : f a = g a)
(h : is_local_max_on f s a) : is_local_max_on g s a :=
filter.eventually_le.is_max_filter hle hfga h
theorem is_local_max_on.congr {α : Type u} {β : Type v} [topological_space α] [preorder β]
{s : set α} {f : α → β} {g : α → β} {a : α} (h : is_local_max_on f s a)
(heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a ∈ s) : is_local_max_on g s a :=
is_max_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)
theorem filter.eventually_eq.is_local_max_on_iff {α : Type u} {β : Type v} [topological_space α]
[preorder β] {s : set α} {f : α → β} {g : α → β} {a : α}
(heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a ∈ s) :
is_local_max_on f s a ↔ is_local_max_on g s a :=
filter.eventually_eq.is_max_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)
theorem filter.eventually_le.is_local_min_on {α : Type u} {β : Type v} [topological_space α]
[preorder β] {s : set α} {f : α → β} {g : α → β} {a : α}
(hle : filter.eventually_le (nhds_within a s) f g) (hfga : f a = g a)
(h : is_local_min_on f s a) : is_local_min_on g s a :=
filter.eventually_le.is_min_filter hle hfga h
theorem is_local_min_on.congr {α : Type u} {β : Type v} [topological_space α] [preorder β]
{s : set α} {f : α → β} {g : α → β} {a : α} (h : is_local_min_on f s a)
(heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a ∈ s) : is_local_min_on g s a :=
is_min_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)
theorem filter.eventually_eq.is_local_min_on_iff {α : Type u} {β : Type v} [topological_space α]
[preorder β] {s : set α} {f : α → β} {g : α → β} {a : α}
(heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a ∈ s) :
is_local_min_on f s a ↔ is_local_min_on g s a :=
filter.eventually_eq.is_min_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)
theorem is_local_extr_on.congr {α : Type u} {β : Type v} [topological_space α] [preorder β]
{s : set α} {f : α → β} {g : α → β} {a : α} (h : is_local_extr_on f s a)
(heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a ∈ s) : is_local_extr_on g s a :=
is_extr_filter.congr h heq (filter.eventually_eq.eq_of_nhds_within heq hmem)
theorem filter.eventually_eq.is_local_extr_on_iff {α : Type u} {β : Type v} [topological_space α]
[preorder β] {s : set α} {f : α → β} {g : α → β} {a : α}
(heq : filter.eventually_eq (nhds_within a s) f g) (hmem : a ∈ s) :
is_local_extr_on f s a ↔ is_local_extr_on g s a :=
filter.eventually_eq.is_extr_filter_iff heq (filter.eventually_eq.eq_of_nhds_within heq hmem)
theorem filter.eventually_le.is_local_max {α : Type u} {β : Type v} [topological_space α]
[preorder β] {f : α → β} {g : α → β} {a : α} (hle : filter.eventually_le (nhds a) g f)
(hfga : f a = g a) (h : is_local_max f a) : is_local_max g a :=
filter.eventually_le.is_max_filter hle hfga h
theorem is_local_max.congr {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{g : α → β} {a : α} (h : is_local_max f a) (heq : filter.eventually_eq (nhds a) f g) :
is_local_max g a :=
is_max_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)
theorem filter.eventually_eq.is_local_max_iff {α : Type u} {β : Type v} [topological_space α]
[preorder β] {f : α → β} {g : α → β} {a : α} (heq : filter.eventually_eq (nhds a) f g) :
is_local_max f a ↔ is_local_max g a :=
filter.eventually_eq.is_max_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)
theorem filter.eventually_le.is_local_min {α : Type u} {β : Type v} [topological_space α]
[preorder β] {f : α → β} {g : α → β} {a : α} (hle : filter.eventually_le (nhds a) f g)
(hfga : f a = g a) (h : is_local_min f a) : is_local_min g a :=
filter.eventually_le.is_min_filter hle hfga h
theorem is_local_min.congr {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{g : α → β} {a : α} (h : is_local_min f a) (heq : filter.eventually_eq (nhds a) f g) :
is_local_min g a :=
is_min_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)
theorem filter.eventually_eq.is_local_min_iff {α : Type u} {β : Type v} [topological_space α]
[preorder β] {f : α → β} {g : α → β} {a : α} (heq : filter.eventually_eq (nhds a) f g) :
is_local_min f a ↔ is_local_min g a :=
filter.eventually_eq.is_min_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)
theorem is_local_extr.congr {α : Type u} {β : Type v} [topological_space α] [preorder β] {f : α → β}
{g : α → β} {a : α} (h : is_local_extr f a) (heq : filter.eventually_eq (nhds a) f g) :
is_local_extr g a :=
is_extr_filter.congr h heq (filter.eventually_eq.eq_of_nhds heq)
theorem filter.eventually_eq.is_local_extr_iff {α : Type u} {β : Type v} [topological_space α]
[preorder β] {f : α → β} {g : α → β} {a : α} (heq : filter.eventually_eq (nhds a) f g) :
is_local_extr f a ↔ is_local_extr g a :=
filter.eventually_eq.is_extr_filter_iff heq (filter.eventually_eq.eq_of_nhds heq)
end Mathlib |
e54a085d8ad03d7095e64cf56ae93d246120dc6a | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /tests/lean/run/fib_brec.lean | 2ccf338e9efda01ab96a838c6a42dc0930acd93b | [
"Apache-2.0"
] | permissive | chubbymaggie/lean | 0d06ae25f9dd396306fb02190e89422ea94afd7b | d2c7b5c31928c98f545b16420d37842c43b4ae9a | refs/heads/master | 1,611,313,622,901 | 1,430,266,839,000 | 1,430,267,083,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,081 | lean | import data.nat.basic data.prod
open prod
namespace nat
namespace manual
definition brec_on {C : nat → Type} (n : nat) (F : Π (n : nat), @nat.below C n → C n) : C n :=
have general : C n × @nat.below C n, from
nat.rec_on n
(pair (F zero unit.star) unit.star)
(λ (n₁ : nat) (r₁ : C n₁ × @nat.below C n₁),
have b : @nat.below C (succ n₁), from
r₁,
have c : C (succ n₁), from
F (succ n₁) b,
pair c b),
pr₁ general
end manual
definition fib (n : nat) :=
nat.brec_on n (λ (n : nat),
nat.cases_on n
(λ (b₀ : nat.below zero), succ zero)
(λ (n₁ : nat), nat.cases_on n₁
(λ b₁ : nat.below (succ zero), succ zero)
(λ (n₂ : nat) (b₂ : nat.below (succ (succ n₂))), pr₁ b₂ + pr₁ (pr₂ b₂))))
theorem fib_0 : fib 0 = 1 :=
rfl
theorem fib_1 : fib 1 = 1 :=
rfl
theorem fib_s_s (n : nat) : fib (succ (succ n)) = fib (succ n) + fib n :=
rfl
example : fib 5 = 8 :=
rfl
example : fib 9 = 55 :=
rfl
end nat
|
9bad08e373c6795cabf59dcbfea80e04ef6100bc | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/category_theory/limits/shapes/strong_epi.lean | 5d5e3b85353aa25b5b008a1dd66105a9446f2a3b | [
"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 | 5,023 | lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import category_theory.arrow
/-!
# Strong epimorphisms
In this file, we define strong epimorphisms. A strong epimorphism is an epimorphism `f`, such
that for every commutative square with `f` at the top and a monomorphism at the bottom, there is
a diagonal morphism making the two triangles commute. This lift is necessarily unique (as shown in
`comma.lean`).
## Main results
Besides the definition, we show that
* the composition of two strong epimorphisms is a strong epimorphism,
* if `f ≫ g` is a strong epimorphism, then so is `g`,
* if `f` is both a strong epimorphism and a monomorphism, then it is an isomorphism
## TODO
Show that the dual of a strong epimorphism is a strong monomorphism, and vice versa.
## References
* [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1]
-/
universes v u
namespace category_theory
variables {C : Type u} [category.{v} C]
variables {P Q : C}
/-- A strong epimorphism `f` is an epimorphism such that every commutative square with `f` at the
top and a monomorphism at the bottom has a lift. -/
class strong_epi (f : P ⟶ Q) : Prop :=
(epi : epi f)
(has_lift : Π {X Y : C} {u : P ⟶ X} {v : Q ⟶ Y} {z : X ⟶ Y} [mono z] (h : u ≫ z = f ≫ v),
arrow.has_lift $ arrow.hom_mk' h)
/-- A strong monomorphism `f` is a monomorphism such that every commutative square with `f` at the
bottom and an epimorphism at the top has a lift. -/
class strong_mono (f : P ⟶ Q) : Prop :=
(mono : mono f)
(has_lift : Π {X Y : C} {u : X ⟶ P} {v : Y ⟶ Q} {z : X ⟶ Y} [epi z] (h : u ≫ f = z ≫ v),
arrow.has_lift $ arrow.hom_mk' h)
attribute [instance] strong_epi.has_lift
attribute [instance] strong_mono.has_lift
@[priority 100]
instance epi_of_strong_epi (f : P ⟶ Q) [strong_epi f] : epi f := strong_epi.epi
@[priority 100]
instance mono_of_strong_mono (f : P ⟶ Q) [strong_mono f] : mono f := strong_mono.mono
section
variables {R : C} (f : P ⟶ Q) (g : Q ⟶ R)
/-- The composition of two strong epimorphisms is a strong epimorphism. -/
lemma strong_epi_comp [strong_epi f] [strong_epi g] : strong_epi (f ≫ g) :=
{ epi := epi_comp _ _,
has_lift :=
begin
introsI,
have h₀ : u ≫ z = f ≫ g ≫ v, by simpa [category.assoc] using h,
let w : Q ⟶ X := arrow.lift (arrow.hom_mk' h₀),
have h₁ : w ≫ z = g ≫ v, by rw arrow.lift_mk'_right,
exact arrow.has_lift.mk ⟨(arrow.lift (arrow.hom_mk' h₁) : R ⟶ X), by simp, by simp⟩
end }
/-- The composition of two strong monomorphisms is a strong monomorphism. -/
lemma strong_mono_comp [strong_mono f] [strong_mono g] : strong_mono (f ≫ g) :=
{ mono := mono_comp _ _,
has_lift :=
begin
introsI,
have h₀ : (u ≫ f) ≫ g = z ≫ v, by simpa [category.assoc] using h,
let w : Y ⟶ Q := arrow.lift (arrow.hom_mk' h₀),
have h₁ : u ≫ f = z ≫ w, by rw arrow.lift_mk'_left,
exact arrow.has_lift.mk ⟨(arrow.lift (arrow.hom_mk' h₁) : Y ⟶ P), by simp, by simp⟩
end }
/-- If `f ≫ g` is a strong epimorphism, then so is `g`. -/
lemma strong_epi_of_strong_epi [strong_epi (f ≫ g)] : strong_epi g :=
{ epi := epi_of_epi f g,
has_lift :=
begin
introsI,
have h₀ : (f ≫ u) ≫ z = (f ≫ g) ≫ v, by simp only [category.assoc, h],
exact arrow.has_lift.mk
⟨(arrow.lift (arrow.hom_mk' h₀) : R ⟶ X), (cancel_mono z).1 (by simp [h]), by simp⟩,
end }
/-- If `f ≫ g` is a strong monomorphism, then so is `f`. -/
lemma strong_mono_of_strong_mono [strong_mono (f ≫ g)] : strong_mono f :=
{ mono := mono_of_mono f g,
has_lift :=
begin
introsI,
have h₀ : u ≫ f ≫ g = z ≫ v ≫ g, by rw reassoc_of h,
exact arrow.has_lift.mk
⟨(arrow.lift (arrow.hom_mk' h₀) : Y ⟶ P), by simp, (cancel_epi z).1 (by simp [h])⟩
end }
/-- An isomorphism is in particular a strong epimorphism. -/
@[priority 100] instance strong_epi_of_is_iso [is_iso f] : strong_epi f :=
{ epi := by apply_instance,
has_lift := λ X Y u v z _ h, arrow.has_lift.mk ⟨inv f ≫ u, by simp, by simp [h]⟩ }
/-- An isomorphism is in particular a strong monomorphism. -/
@[priority 100] instance strong_mono_of_is_iso [is_iso f] : strong_mono f :=
{ mono := by apply_instance,
has_lift := λ X Y u v z _ h, arrow.has_lift.mk
⟨v ≫ inv f, by simp [← category.assoc, ← h], by simp⟩ }
end
/-- A strong epimorphism that is a monomorphism is an isomorphism. -/
lemma is_iso_of_mono_of_strong_epi (f : P ⟶ Q) [mono f] [strong_epi f] : is_iso f :=
⟨⟨arrow.lift $ arrow.hom_mk' $ show 𝟙 P ≫ f = f ≫ 𝟙 Q, by simp, by tidy⟩⟩
/-- A strong monomorphism that is an epimorphism is an isomorphism. -/
lemma is_iso_of_epi_of_strong_mono (f : P ⟶ Q) [epi f] [strong_mono f] : is_iso f :=
⟨⟨arrow.lift $ arrow.hom_mk' $ show 𝟙 P ≫ f = f ≫ 𝟙 Q, by simp, by tidy⟩⟩
end category_theory
|
c0d73ca2c3e97ee990b0a8b7ac2c0ac6f278f967 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/data/list/perm.lean | 501340baddafd932729ea536d6f297b99a6d5a06 | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 41,013 | 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
List permutations.
-/
import data.list.basic logic.relation
namespace list
universe variables uu vv
variables {α : Type uu} {β : Type vv}
/-- `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 : list α → list α → Prop
| nil : perm [] []
| skip : Π (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₃
open perm
infix ~ := perm
@[refl] protected theorem perm.refl : ∀ (l : list α), l ~ l
| [] := perm.nil
| (x::xs) := skip x (perm.refl xs)
@[symm] protected theorem perm.symm {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₂ ~ l₁ :=
perm.rec_on p
perm.nil
(λ x l₁ l₂ p₁ r₁, skip x r₁)
(λ x y l, swap y x l)
(λ l₁ l₂ l₃ p₁ p₂ r₁ r₂, trans r₂ r₁)
theorem perm.swap'
(x y : α) {l₁ l₂ : list α} (p : l₁ ~ l₂) : y::x::l₁ ~ x::y::l₂ :=
trans (swap _ _ _) (skip _ $ skip _ p)
attribute [trans] perm.trans
theorem perm.eqv (α) : equivalence (@perm α) :=
mk_equivalence (@perm α) (@perm.refl α) (@perm.symm α) (@perm.trans α)
instance is_setoid (α) : setoid (list α) :=
setoid.mk (@perm α) (perm.eqv α)
theorem perm_subset {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₁ ⊆ l₂ :=
λ a, perm.rec_on p
(λ h, h)
(λ x l₁ l₂ p₁ r₁ i, or.elim i
(λ ax, by simp [ax])
(λ al₁, or.inr (r₁ al₁)))
(λ x y l ayxl, or.elim ayxl
(λ ay, by simp [ay])
(λ axl, or.elim axl
(λ ax, by simp [ax])
(λ al, or.inr (or.inr al))))
(λ l₁ l₂ l₃ p₁ p₂ r₁ r₂ ainl₁, r₂ (r₁ ainl₁))
theorem mem_of_perm {a : α} {l₁ l₂ : list α} (h : l₁ ~ l₂) : a ∈ l₁ ↔ a ∈ l₂ :=
iff.intro (λ m, perm_subset h m) (λ m, perm_subset h.symm m)
theorem perm_app_left {l₁ l₂ : list α} (t₁ : list α) (p : l₁ ~ l₂) : l₁++t₁ ~ l₂++t₁ :=
perm.rec_on p
(perm.refl ([] ++ t₁))
(λ x l₁ l₂ p₁ r₁, skip x r₁)
(λ x y l, swap x y _)
(λ l₁ l₂ l₃ p₁ p₂ r₁ r₂, trans r₁ r₂)
theorem perm_app_right {t₁ t₂ : list α} : ∀ (l : list α), t₁ ~ t₂ → l++t₁ ~ l++t₂
| [] p := p
| (x::xs) p := skip x (perm_app_right xs p)
theorem perm_app {l₁ l₂ t₁ t₂ : list α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁++t₁ ~ l₂++t₂ :=
trans (perm_app_left t₁ p₁) (perm_app_right l₂ p₂)
theorem perm_app_cons (a : α) {h₁ h₂ t₁ t₂ : list α}
(p₁ : h₁ ~ h₂) (p₂ : t₁ ~ t₂) : h₁ ++ a::t₁ ~ h₂ ++ a::t₂ :=
perm_app p₁ (skip a p₂)
@[simp] theorem perm_middle {a : α} : ∀ {l₁ l₂ : list α}, l₁++a::l₂ ~ a::(l₁++l₂)
| [] l₂ := perm.refl _
| (b::l₁) l₂ := (skip b (@perm_middle l₁ l₂)).trans (swap a b _)
@[simp] theorem perm_cons_app (a : α) (l : list α) : l ++ [a] ~ a::l :=
by simpa using @perm_middle _ a l []
@[simp] theorem perm_app_comm : ∀ {l₁ l₂ : list α}, (l₁++l₂) ~ (l₂++l₁)
| [] l₂ := by simp
| (a::t) l₂ := (skip a perm_app_comm).trans perm_middle.symm
theorem concat_perm (l : list α) (a : α) : concat l a ~ a :: l :=
by simp
theorem perm_length {l₁ l₂ : list α} (p : l₁ ~ l₂) : length l₁ = length l₂ :=
perm.rec_on p
rfl
(λ x l₁ l₂ p r, by simp[r])
(λ x y l, by simp)
(λ l₁ l₂ l₃ p₁ p₂ r₁ r₂, eq.trans r₁ r₂)
theorem eq_nil_of_perm_nil {l₁ : list α} (p : [] ~ l₁) : l₁ = [] :=
eq_nil_of_length_eq_zero (perm_length p).symm
theorem perm_nil {l₁ : list α} : l₁ ~ [] ↔ l₁ = [] :=
⟨λ p, eq_nil_of_perm_nil p.symm, λ e, e ▸ perm.refl _⟩
theorem not_perm_nil_cons (x : α) (l : list α) : ¬ [] ~ x::l
| p := by injection eq_nil_of_perm_nil p
theorem eq_singleton_of_perm {a b : α} (p : [a] ~ [b]) : a = b :=
by simpa using perm_subset p (by simp)
theorem eq_singleton_of_perm_inv {a : α} {l : list α} (p : [a] ~ l) : l = [a] :=
match l, show 1 = _, from perm_length p, p with
| [a'], rfl, p := by rw [eq_singleton_of_perm p]
end
@[simp] theorem reverse_perm : ∀ (l : list α), reverse l ~ l
| [] := perm.nil
| (a::l) := by rw reverse_cons; exact
(perm_cons_app _ _).trans (skip a $ reverse_perm l)
theorem perm_cons_app_cons {l l₁ l₂ : list α} (a : α) (p : l ~ l₁++l₂) : a::l ~ l₁++(a::l₂) :=
trans (skip a p) perm_middle.symm
@[simp] theorem perm_repeat {a : α} {n : ℕ} {l : list α} : repeat a n ~ l ↔ repeat a n = l :=
⟨λ p, (eq_repeat.2 $ by exact
⟨by simpa using (perm_length p).symm,
λ b m, eq_of_mem_repeat $ perm_subset p.symm m⟩).symm,
λ h, h ▸ perm.refl _⟩
theorem perm_erase [decidable_eq α] {a : α} {l : list α} (h : a ∈ l) : l ~ a :: l.erase a :=
let ⟨l₁, l₂, _, e₁, e₂⟩ := exists_erase_eq h in
e₂.symm ▸ e₁.symm ▸ perm_middle
@[elab_as_eliminator] theorem perm_induction_on
{P : list α → list α → Prop} {l₁ l₂ : list α} (p : l₁ ~ l₂)
(h₁ : P [] [])
(h₂ : ∀ x l₁ l₂, l₁ ~ l₂ → P l₁ l₂ → P (x::l₁) (x::l₂))
(h₃ : ∀ x y l₁ l₂, l₁ ~ l₂ → P l₁ l₂ → P (y::x::l₁) (x::y::l₂))
(h₄ : ∀ l₁ l₂ l₃, l₁ ~ l₂ → l₂ ~ l₃ → P l₁ l₂ → P l₂ l₃ → P l₁ l₃) :
P l₁ l₂ :=
have P_refl : ∀ l, P l l, from
assume l,
list.rec_on l h₁ (λ x xs ih, h₂ x xs xs (perm.refl xs) ih),
perm.rec_on p h₁ h₂ (λ x y l, h₃ x y l l (perm.refl l) (P_refl l)) h₄
@[congr] theorem perm_filter_map (f : α → option β) {l₁ l₂ : list α} (p : l₁ ~ l₂) :
filter_map f l₁ ~ filter_map f l₂ :=
begin
induction p with x l₂ l₂' p IH x y l₂ l₂ m₂ r₂ p₁ p₂ IH₁ IH₂,
{ simp },
{ simp [filter_map], cases f x with a; simp [filter_map, IH, skip] },
{ simp [filter_map], cases f x with a; cases f y with b; simp [filter_map, swap] },
{ exact IH₁.trans IH₂ }
end
@[congr] theorem perm_map (f : α → β) {l₁ l₂ : list α} (p : l₁ ~ l₂) :
map f l₁ ~ map f l₂ :=
by rw ← filter_map_eq_map; apply perm_filter_map _ p
theorem perm_pmap {p : α → Prop} (f : Π a, p a → β)
{l₁ l₂ : list α} (p : l₁ ~ l₂) {H₁ H₂} : pmap f l₁ H₁ ~ pmap f l₂ H₂ :=
begin
induction p with x l₂ l₂' p IH x y l₂ l₂ m₂ r₂ p₁ p₂ IH₁ IH₂,
{ simp },
{ simp [IH, skip] },
{ simp [swap] },
{ refine IH₁.trans IH₂,
exact λ a m, H₂ a (perm_subset p₂ m) }
end
theorem perm_filter (p : α → Prop) [decidable_pred p]
{l₁ l₂ : list α} (s : l₁ ~ l₂) : filter p l₁ ~ filter p l₂ :=
by rw ← filter_map_eq_filter; apply perm_filter_map _ s
theorem exists_perm_sublist {l₁ l₂ l₂' : list α}
(s : l₁ <+ l₂) (p : l₂ ~ l₂') : ∃ l₁' ~ l₁, l₁' <+ l₂' :=
begin
induction p with x l₂ l₂' p IH x y l₂ l₂ m₂ r₂ p₁ p₂ IH₁ IH₂ generalizing l₁ s,
{ exact ⟨[], eq_nil_of_sublist_nil s ▸ perm.refl _, nil_sublist _⟩ },
{ cases s with _ _ _ s l₁ _ _ s,
{ exact let ⟨l₁', p', s'⟩ := IH s in ⟨l₁', p', s'.cons _ _ _⟩ },
{ exact let ⟨l₁', p', s'⟩ := IH s in ⟨x::l₁', skip x p', s'.cons2 _ _ _⟩ } },
{ cases s with _ _ _ s l₁ _ _ s; cases s with _ _ _ s l₁ _ _ s,
{ exact ⟨l₁, perm.refl _, (s.cons _ _ _).cons _ _ _⟩ },
{ exact ⟨x::l₁, perm.refl _, (s.cons _ _ _).cons2 _ _ _⟩ },
{ exact ⟨y::l₁, perm.refl _, (s.cons2 _ _ _).cons _ _ _⟩ },
{ exact ⟨x::y::l₁, perm.swap _ _ _, (s.cons2 _ _ _).cons2 _ _ _⟩ } },
{ exact let ⟨m₁, pm, sm⟩ := IH₁ s, ⟨r₁, pr, sr⟩ := IH₂ sm in
⟨r₁, pr.trans pm, sr⟩ }
end
section rel
open relator
variables {γ : Type*} {δ : Type*} {r : α → β → Prop} {p : γ → δ → Prop}
local infixr ` ∘r ` : 80 := relation.comp
lemma perm_comp_perm : (perm ∘r perm : list α → list α → Prop) = perm :=
begin
funext a c, apply propext,
split,
{ exact assume ⟨b, hab, hba⟩, perm.trans hab hba },
{ exact assume h, ⟨a, perm.refl a, h⟩ }
end
lemma perm_comp_forall₂ {l u v} (hlu : perm l u) (huv : forall₂ r u v) : (forall₂ r ∘r perm) l v :=
begin
induction hlu generalizing v,
case perm.nil { cases huv, exact ⟨[], forall₂.nil, perm.nil⟩ },
case perm.skip : a l u hlu ih {
cases huv with _ b _ v hab huv',
rcases ih huv' with ⟨l₂, h₁₂, h₂₃⟩,
exact ⟨b::l₂, forall₂.cons hab h₁₂, perm.skip _ h₂₃⟩
},
case perm.swap : a₁ a₂ l₁ l₂ h₂₃ {
cases h₂₃ with _ b₁ _ l₂ h₁ hr_₂₃,
cases hr_₂₃ with _ b₂ _ l₂ h₂ h₁₂,
exact ⟨b₂::b₁::l₂, forall₂.cons h₂ (forall₂.cons h₁ h₁₂), perm.swap _ _ _⟩
},
case perm.trans : la₁ la₂ la₃ _ _ ih₁ ih₂ {
rcases ih₂ huv with ⟨lb₂, hab₂, h₂₃⟩,
rcases ih₁ hab₂ with ⟨lb₁, hab₁, h₁₂⟩,
exact ⟨lb₁, hab₁, perm.trans h₁₂ h₂₃⟩
}
end
lemma forall₂_comp_perm_eq_perm_comp_forall₂ : forall₂ r ∘r perm = perm ∘r forall₂ r :=
begin
funext l₁ l₃, apply propext,
split,
{ assume h, rcases h with ⟨l₂, h₁₂, h₂₃⟩,
have : forall₂ (flip r) l₂ l₁, from h₁₂.flip ,
rcases perm_comp_forall₂ h₂₃.symm this with ⟨l', h₁, h₂⟩,
exact ⟨l', h₂.symm, h₁.flip⟩ },
{ exact assume ⟨l₂, h₁₂, h₂₃⟩, perm_comp_forall₂ h₁₂ h₂₃ }
end
lemma rel_perm_imp (hr : right_unique r) : (forall₂ r ⇒ forall₂ r ⇒ implies) perm perm :=
assume a b h₁ c d h₂ h,
have (flip (forall₂ r) ∘r (perm ∘r forall₂ r)) b d, from ⟨a, h₁, c, h, h₂⟩,
have ((flip (forall₂ r) ∘r forall₂ r) ∘r perm) b d,
by rwa [← forall₂_comp_perm_eq_perm_comp_forall₂, ← relation.comp_assoc] at this,
let ⟨b', ⟨c', hbc, hcb⟩, hbd⟩ := this in
have b' = b, from right_unique_forall₂ @hr hcb hbc,
this ▸ hbd
lemma rel_perm (hr : bi_unique r) : (forall₂ r ⇒ forall₂ r ⇒ (↔)) perm perm :=
assume a b hab c d hcd, iff.intro
(rel_perm_imp hr.2 hab hcd)
(rel_perm_imp (assume a b c, left_unique_flip hr.1) hab.flip hcd.flip)
end rel
section subperm
/-- `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 (l₁ l₂ : list α) : Prop := ∃ l ~ l₁, l <+ l₂
infix ` <+~ `:50 := subperm
theorem nil_subperm {l : list α} : [] <+~ l :=
⟨[], perm.nil, by simp⟩
theorem perm.subperm_left {l l₁ l₂ : list α} (p : l₁ ~ l₂) : l <+~ l₁ ↔ l <+~ l₂ :=
suffices ∀ {l₁ l₂ : list α}, l₁ ~ l₂ → l <+~ l₁ → l <+~ l₂,
from ⟨this p, this p.symm⟩,
λ l₁ l₂ p ⟨u, pu, su⟩,
let ⟨v, pv, sv⟩ := exists_perm_sublist su p in
⟨v, pv.trans pu, sv⟩
theorem perm.subperm_right {l₁ l₂ l : list α} (p : l₁ ~ l₂) : l₁ <+~ l ↔ l₂ <+~ l :=
⟨λ ⟨u, pu, su⟩, ⟨u, pu.trans p, su⟩,
λ ⟨u, pu, su⟩, ⟨u, pu.trans p.symm, su⟩⟩
theorem subperm_of_sublist {l₁ l₂ : list α} (s : l₁ <+ l₂) : l₁ <+~ l₂ :=
⟨l₁, perm.refl _, s⟩
theorem subperm_of_perm {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₁ <+~ l₂ :=
⟨l₂, p.symm, sublist.refl _⟩
theorem subperm.refl (l : list α) : l <+~ l := subperm_of_perm (perm.refl _)
theorem subperm.trans {l₁ l₂ l₃ : list α} : l₁ <+~ l₂ → l₂ <+~ l₃ → l₁ <+~ l₃
| s ⟨l₂', p₂, s₂⟩ :=
let ⟨l₁', p₁, s₁⟩ := p₂.subperm_left.2 s in ⟨l₁', p₁, s₁.trans s₂⟩
theorem length_le_of_subperm {l₁ l₂ : list α} : l₁ <+~ l₂ → length l₁ ≤ length l₂
| ⟨l, p, s⟩ := perm_length p ▸ length_le_of_sublist s
theorem subperm.perm_of_length_le {l₁ l₂ : list α} : l₁ <+~ l₂ → length l₂ ≤ length l₁ → l₁ ~ l₂
| ⟨l, p, s⟩ h :=
suffices l = l₂, from this ▸ p.symm,
eq_of_sublist_of_length_le s $ perm_length p.symm ▸ h
theorem subperm.antisymm {l₁ l₂ : list α} (h₁ : l₁ <+~ l₂) (h₂ : l₂ <+~ l₁) : l₁ ~ l₂ :=
h₁.perm_of_length_le (length_le_of_subperm h₂)
theorem subset_of_subperm {l₁ l₂ : list α} : l₁ <+~ l₂ → l₁ ⊆ l₂
| ⟨l, p, s⟩ := subset.trans (perm_subset p.symm) (subset_of_sublist s)
end subperm
theorem exists_perm_append_of_sublist : ∀ {l₁ l₂ : list α}, l₁ <+ l₂ → ∃ l, l₂ ~ l₁ ++ l
| ._ ._ sublist.slnil := ⟨nil, perm.refl _⟩
| ._ ._ (sublist.cons l₁ l₂ a s) :=
let ⟨l, p⟩ := exists_perm_append_of_sublist s in
⟨a::l, (skip a p).trans perm_middle.symm⟩
| ._ ._ (sublist.cons2 l₁ l₂ a s) :=
let ⟨l, p⟩ := exists_perm_append_of_sublist s in
⟨l, skip a p⟩
theorem perm_countp (p : α → Prop) [decidable_pred p]
{l₁ l₂ : list α} (s : l₁ ~ l₂) : countp p l₁ = countp p l₂ :=
by rw [countp_eq_length_filter, countp_eq_length_filter];
exact perm_length (perm_filter _ s)
theorem countp_le_of_subperm (p : α → Prop) [decidable_pred p]
{l₁ l₂ : list α} : l₁ <+~ l₂ → countp p l₁ ≤ countp p l₂
| ⟨l, p', s⟩ := perm_countp p p' ▸ countp_le_of_sublist s
theorem perm_count [decidable_eq α] {l₁ l₂ : list α}
(p : l₁ ~ l₂) (a) : count a l₁ = count a l₂ :=
perm_countp _ p
theorem count_le_of_subperm [decidable_eq α] {l₁ l₂ : list α}
(s : l₁ <+~ l₂) (a) : count a l₁ ≤ count a l₂ :=
countp_le_of_subperm _ s
theorem foldl_eq_of_perm {f : β → α → β} {l₁ l₂ : list α} (rcomm : right_commutative f) (p : l₁ ~ l₂) :
∀ b, foldl f b l₁ = foldl f b l₂ :=
perm_induction_on p
(λ b, rfl)
(λ x t₁ t₂ p r b, r (f b x))
(λ x y t₁ t₂ p r b, by simp; rw rcomm; exact r (f (f b x) y))
(λ t₁ t₂ t₃ p₁ p₂ r₁ r₂ b, eq.trans (r₁ b) (r₂ b))
theorem foldr_eq_of_perm {f : α → β → β} {l₁ l₂ : list α} (lcomm : left_commutative f) (p : l₁ ~ l₂) :
∀ b, foldr f b l₁ = foldr f b l₂ :=
perm_induction_on p
(λ b, rfl)
(λ x t₁ t₂ p r b, by simp; rw [r b])
(λ x y t₁ t₂ p r b, by simp; rw [lcomm, r b])
(λ t₁ t₂ t₃ p₁ p₂ r₁ r₂ a, eq.trans (r₁ a) (r₂ a))
lemma rec_heq_of_perm {β : list α → Sort*} {f : Πa l, β l → β (a::l)} {b : β []} {l l' : list α}
(hl : perm l l')
(f_congr : ∀{a l l' b b'}, perm l l' → b == b' → f a l b == f a l' b')
(f_swap : ∀{a a' l b}, 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' :=
begin
induction hl,
case list.perm.nil { refl },
case list.perm.skip : a l l' h ih { exact f_congr h ih },
case list.perm.swap : a a' l { exact f_swap },
case list.perm.trans : l₁ l₂ l₃ h₁ h₂ ih₁ ih₂ { exact heq.trans ih₁ ih₂ }
end
section
variables {op : α → α → α} [is_associative α op] [is_commutative α op]
local notation a * b := op a b
local notation l <*> a := foldl op a l
lemma fold_op_eq_of_perm {l₁ l₂ : list α} {a : α} (h : l₁ ~ l₂) : l₁ <*> a = l₂ <*> a :=
foldl_eq_of_perm (right_comm _ (is_commutative.comm _) (is_associative.assoc _)) h _
end
section comm_monoid
open list
variable [comm_monoid α]
@[to_additive]
lemma prod_eq_of_perm {l₁ l₂ : list α} (h : perm l₁ l₂) : prod l₁ = prod l₂ :=
by induction h; simp [*, mul_left_comm]
@[to_additive]
lemma prod_reverse (l : list α) : prod l.reverse = prod l :=
prod_eq_of_perm $ reverse_perm l
end comm_monoid
theorem perm_inv_core {a : α} {l₁ l₂ r₁ r₂ : list α} : l₁++a::r₁ ~ l₂++a::r₂ → l₁++r₁ ~ l₂++r₂ :=
begin
generalize e₁ : l₁++a::r₁ = s₁, generalize e₂ : l₂++a::r₂ = s₂,
intro p, revert l₁ l₂ r₁ r₂ e₁ e₂,
refine perm_induction_on p _ (λ x t₁ t₂ p IH, _) (λ x y t₁ t₂ p IH, _) (λ t₁ t₂ t₃ p₁ p₂ IH₁ IH₂, _);
intros l₁ l₂ r₁ r₂ e₁ e₂,
{ apply (not_mem_nil a).elim, rw ← e₁, simp },
{ cases l₁ with y l₁; cases l₂ with z l₂;
dsimp at e₁ e₂; injections; subst x,
{ substs t₁ t₂, exact p },
{ substs z t₁ t₂, exact p.trans perm_middle },
{ substs y t₁ t₂, exact perm_middle.symm.trans p },
{ substs z t₁ t₂, exact skip y (IH rfl rfl) } },
{ rcases l₁ with _|⟨y, _|⟨z, l₁⟩⟩; rcases l₂ with _|⟨u, _|⟨v, l₂⟩⟩;
dsimp at e₁ e₂; injections; substs x y,
{ substs r₁ r₂, exact skip a p },
{ substs r₁ r₂, exact skip u p },
{ substs r₁ v t₂, exact skip u (p.trans perm_middle) },
{ substs r₁ r₂, exact skip y p },
{ substs r₁ r₂ y u, exact skip a p },
{ substs r₁ u v t₂, exact (skip y $ p.trans perm_middle).trans (swap _ _ _) },
{ substs r₂ z t₁, exact skip y (perm_middle.symm.trans p) },
{ substs r₂ y z t₁, exact (swap _ _ _).trans (skip u $ perm_middle.symm.trans p) },
{ substs u v t₁ t₂, exact (IH rfl rfl).swap' _ _ } },
{ substs t₁ t₃,
have : a ∈ t₂ := perm_subset p₁ (by simp),
rcases mem_split this with ⟨l₂, r₂, e₂⟩,
subst t₂, exact (IH₁ rfl rfl).trans (IH₂ rfl rfl) }
end
theorem perm_cons_inv {a : α} {l₁ l₂ : list α} : a::l₁ ~ a::l₂ → l₁ ~ l₂ :=
@perm_inv_core _ _ [] [] _ _
theorem perm_cons (a : α) {l₁ l₂ : list α} : a::l₁ ~ a::l₂ ↔ l₁ ~ l₂ :=
⟨perm_cons_inv, skip a⟩
theorem perm_app_left_iff {l₁ l₂ : list α} : ∀ l, l++l₁ ~ l++l₂ ↔ l₁ ~ l₂
| [] := iff.rfl
| (a::l) := (perm_cons a).trans (perm_app_left_iff l)
theorem perm_app_right_iff {l₁ l₂ : list α} (l) : l₁++l ~ l₂++l ↔ l₁ ~ l₂ :=
⟨λ p, (perm_app_left_iff _).1 $ trans perm_app_comm $ trans p perm_app_comm,
perm_app_left _⟩
theorem perm_option_to_list {o₁ o₂ : option α} : o₁.to_list ~ o₂.to_list ↔ o₁ = o₂ :=
begin
refine ⟨λ p, _, λ e, e ▸ perm.refl _⟩,
cases o₁ with a; cases o₂ with b, {refl},
{ cases (perm_length p) },
{ cases (perm_length p) },
{ exact option.mem_to_list.1 ((mem_of_perm p).2 $ by simp) }
end
theorem subperm_cons (a : α) {l₁ l₂ : list α} : a::l₁ <+~ a::l₂ ↔ l₁ <+~ l₂ :=
⟨λ ⟨l, p, s⟩, begin
cases s with _ _ _ s' u _ _ s',
{ exact (p.subperm_left.2 $ subperm_of_sublist $ sublist_cons _ _).trans
(subperm_of_sublist s') },
{ exact ⟨u, perm_cons_inv p, s'⟩ }
end, λ ⟨l, p, s⟩, ⟨a::l, skip a p, s.cons2 _ _ _⟩⟩
theorem cons_subperm_of_mem {a : α} {l₁ l₂ : list α} (d₁ : nodup l₁) (h₁ : a ∉ l₁) (h₂ : a ∈ l₂)
(s : l₁ <+~ l₂) : a :: l₁ <+~ l₂ :=
begin
rcases s with ⟨l, p, s⟩,
induction s generalizing l₁,
case list.sublist.slnil { cases h₂ },
case list.sublist.cons : r₁ r₂ b s' ih {
simp at h₂,
cases h₂ with e m,
{ subst b, exact ⟨a::r₁, skip a p, s'.cons2 _ _ _⟩ },
{ rcases ih m d₁ h₁ p with ⟨t, p', s'⟩, exact ⟨t, p', s'.cons _ _ _⟩ } },
case list.sublist.cons2 : r₁ r₂ b s' ih {
have bm : b ∈ l₁ := (perm_subset p $ mem_cons_self _ _),
have am : a ∈ r₂ := h₂.resolve_left (λ e, h₁ $ e.symm ▸ bm),
rcases mem_split bm with ⟨t₁, t₂, rfl⟩,
have st : t₁ ++ t₂ <+ t₁ ++ b :: t₂ := by simp,
rcases ih am (nodup_of_sublist st d₁)
(mt (λ x, subset_of_sublist st x) h₁)
(perm_cons_inv $ p.trans perm_middle) with ⟨t, p', s'⟩,
exact ⟨b::t, (skip b p').trans $ (swap _ _ _).trans (skip a perm_middle.symm), s'.cons2 _ _ _⟩ }
end
theorem subperm_app_left {l₁ l₂ : list α} : ∀ l, l++l₁ <+~ l++l₂ ↔ l₁ <+~ l₂
| [] := iff.rfl
| (a::l) := (subperm_cons a).trans (subperm_app_left l)
theorem subperm_app_right {l₁ l₂ : list α} (l) : l₁++l <+~ l₂++l ↔ l₁ <+~ l₂ :=
(perm_app_comm.subperm_left.trans perm_app_comm.subperm_right).trans (subperm_app_left l)
theorem subperm.exists_of_length_lt {l₁ l₂ : list α} :
l₁ <+~ l₂ → length l₁ < length l₂ → ∃ a, a :: l₁ <+~ l₂
| ⟨l, p, s⟩ h :=
suffices length l < length l₂ → ∃ (a : α), a :: l <+~ l₂, from
(this $ perm_length p.symm ▸ h).imp (λ a, (skip a p).subperm_right.1),
begin
clear subperm.exists_of_length_lt p h l₁, rename l₂ u,
induction s with l₁ l₂ a s IH _ _ b s IH; intro h,
{ cases h },
{ cases lt_or_eq_of_le (nat.le_of_lt_succ h : length l₁ ≤ length l₂) with h h,
{ exact (IH h).imp (λ a s, s.trans (subperm_of_sublist $ sublist_cons _ _)) },
{ exact ⟨a, eq_of_sublist_of_length_eq s h ▸ subperm.refl _⟩ } },
{ exact (IH $ nat.lt_of_succ_lt_succ h).imp
(λ a s, (swap _ _ _).subperm_right.1 $ (subperm_cons _).2 s) }
end
theorem subperm_of_subset_nodup
{l₁ l₂ : list α} (d : nodup l₁) (H : l₁ ⊆ l₂) : l₁ <+~ l₂ :=
begin
induction d with a l₁' h d IH,
{ exact ⟨nil, perm.nil, nil_sublist _⟩ },
{ cases forall_mem_cons.1 H with H₁ H₂,
simp at h,
exact cons_subperm_of_mem d h H₁ (IH H₂) }
end
theorem perm_ext {l₁ l₂ : list α} (d₁ : nodup l₁) (d₂ : nodup l₂) : l₁ ~ l₂ ↔ ∀a, a ∈ l₁ ↔ a ∈ l₂ :=
⟨λ p a, mem_of_perm p, λ H, subperm.antisymm
(subperm_of_subset_nodup d₁ (λ a, (H a).1))
(subperm_of_subset_nodup d₂ (λ a, (H a).2))⟩
theorem perm_ext_sublist_nodup {l₁ l₂ l : list α} (d : nodup l)
(s₁ : l₁ <+ l) (s₂ : l₂ <+ l) : l₁ ~ l₂ ↔ l₁ = l₂ :=
⟨λ h, begin
induction s₂ with l₂ l a s₂ IH l₂ l a s₂ IH generalizing l₁,
{ exact eq_nil_of_perm_nil h.symm },
{ simp at d,
cases s₁ with _ _ _ s₁ l₁ _ _ s₁,
{ exact IH d.2 s₁ h },
{ apply d.1.elim,
exact subset_of_subperm ⟨_, h.symm, s₂⟩ (mem_cons_self _ _) } },
{ simp at d,
cases s₁ with _ _ _ s₁ l₁ _ _ s₁,
{ apply d.1.elim,
exact subset_of_subperm ⟨_, h, s₁⟩ (mem_cons_self _ _) },
{ rw IH d.2 s₁ (perm_cons_inv h) } }
end, λ h, by rw h⟩
section
variable [decidable_eq α]
-- attribute [congr]
theorem erase_perm_erase (a : α) {l₁ l₂ : list α} (p : l₁ ~ l₂) :
l₁.erase a ~ l₂.erase a :=
if h₁ : a ∈ l₁ then
have h₂ : a ∈ l₂, from perm_subset p h₁,
perm_cons_inv $ trans (perm_erase h₁).symm $ trans p (perm_erase h₂)
else
have h₂ : a ∉ l₂, from mt (mem_of_perm p).2 h₁,
by rw [erase_of_not_mem h₁, erase_of_not_mem h₂]; exact p
theorem erase_subperm (a : α) (l : list α) : l.erase a <+~ l :=
⟨l.erase a, perm.refl _, erase_sublist _ _⟩
theorem erase_subperm_erase {l₁ l₂ : list α} (a : α) (h : l₁ <+~ l₂) : l₁.erase a <+~ l₂.erase a :=
let ⟨l, hp, hs⟩ := h in ⟨l.erase a, erase_perm_erase _ hp, erase_sublist_erase _ hs⟩
theorem perm_diff_left {l₁ l₂ : list α} (t : list α) (h : l₁ ~ l₂) : l₁.diff t ~ l₂.diff t :=
by induction t generalizing l₁ l₂ h; simp [*, erase_perm_erase]
theorem perm_diff_right (l : list α) {t₁ t₂ : list α} (h : t₁ ~ t₂) : l.diff t₁ = l.diff t₂ :=
by induction h generalizing l; simp [*, erase_perm_erase, erase_comm]
<|> exact (ih_1 _).trans (ih_2 _)
theorem subperm_cons_diff {a : α} : ∀ {l₁ l₂ : list α}, (a :: l₁).diff l₂ <+~ a :: l₁.diff l₂
| l₁ [] := ⟨a::l₁, by simp⟩
| l₁ (b::l₂) :=
begin
repeat {rw diff_cons},
by_cases heq : a = b,
{ by_cases b ∈ l₁,
{ rw perm.subperm_right, apply subperm_cons_diff,
simp [perm_diff_left, heq, perm_erase h] },
{ simp [subperm_of_sublist, sublist.cons, h, heq] } },
{ simp [heq, subperm_cons_diff] }
end
theorem subset_cons_diff {a : α} {l₁ l₂ : list α} : (a :: l₁).diff l₂ ⊆ a :: l₁.diff l₂ :=
subset_of_subperm subperm_cons_diff
theorem perm_bag_inter_left {l₁ l₂ : list α} (t : list α) (h : l₁ ~ l₂) : l₁.bag_inter t ~ l₂.bag_inter t :=
begin
induction h with x _ _ _ _ x y _ _ _ _ _ _ ih_1 ih_2 generalizing t, {simp},
{ by_cases x ∈ t; simp [*, skip] },
{ by_cases x = y, {simp [h]},
by_cases xt : x ∈ t; by_cases yt : y ∈ t,
{ simp [xt, yt, mem_erase_of_ne h, mem_erase_of_ne (ne.symm h), erase_comm, swap] },
{ simp [xt, yt, mt mem_of_mem_erase, skip] },
{ simp [xt, yt, mt mem_of_mem_erase, skip] },
{ simp [xt, yt] } },
{ exact (ih_1 _).trans (ih_2 _) }
end
theorem perm_bag_inter_right (l : list α) {t₁ t₂ : list α} (p : t₁ ~ t₂) : l.bag_inter t₁ = l.bag_inter t₂ :=
begin
induction l with a l IH generalizing t₁ t₂ p, {simp},
by_cases a ∈ t₁,
{ simp [h, (mem_of_perm p).1 h, IH (erase_perm_erase _ p)] },
{ simp [h, mt (mem_of_perm p).2 h, IH p] }
end
theorem cons_perm_iff_perm_erase {a : α} {l₁ l₂ : list α} : a::l₁ ~ l₂ ↔ a ∈ l₂ ∧ l₁ ~ l₂.erase a :=
⟨λ h, have a ∈ l₂, from perm_subset h (mem_cons_self a l₁),
⟨this, perm_cons_inv $ h.trans $ perm_erase this⟩,
λ ⟨m, h⟩, trans (skip a h) (perm_erase m).symm⟩
theorem perm_iff_count {l₁ l₂ : list α} : l₁ ~ l₂ ↔ ∀ a, count a l₁ = count a l₂ :=
⟨perm_count, λ H, begin
induction l₁ with a l₁ IH generalizing l₂,
{ cases l₂ with b l₂, {refl},
specialize H b, simp at H, contradiction },
{ have : a ∈ l₂ := count_pos.1 (by rw ← H; simp; apply nat.succ_pos),
refine trans (skip a $ IH $ λ b, _) (perm_erase this).symm,
specialize H b,
rw perm_count (perm_erase this) at H,
by_cases b = a; simp [h] at H ⊢; assumption }
end⟩
instance decidable_perm : ∀ (l₁ l₂ : list α), decidable (l₁ ~ l₂)
| [] [] := is_true $ perm.refl _
| [] (b::l₂) := is_false $ λ h, by have := eq_nil_of_perm_nil h; contradiction
| (a::l₁) l₂ := by haveI := decidable_perm l₁ (l₂.erase a);
exact decidable_of_iff' _ cons_perm_iff_perm_erase
-- @[congr]
theorem perm_erase_dup_of_perm {l₁ l₂ : list α} (p : l₁ ~ l₂) :
erase_dup l₁ ~ erase_dup l₂ :=
perm_iff_count.2 $ λ a,
if h : a ∈ l₁
then by simp [nodup_erase_dup, h, perm_subset p h]
else by simp [h, mt (mem_of_perm p).2 h]
-- attribute [congr]
theorem perm_insert (a : α)
{l₁ l₂ : list α} (p : l₁ ~ l₂) : insert a l₁ ~ insert a l₂ :=
if h : a ∈ l₁
then by simpa [h, perm_subset p h] using p
else by simpa [h, mt (mem_of_perm p).2 h] using skip a p
theorem perm_insert_swap (x y : α) (l : list α) :
insert x (insert y l) ~ insert y (insert x l) :=
begin
by_cases xl : x ∈ l; by_cases yl : y ∈ l; simp [xl, yl],
by_cases xy : x = y, { simp [xy] },
simp [not_mem_cons_of_ne_of_not_mem xy xl,
not_mem_cons_of_ne_of_not_mem (ne.symm xy) yl],
constructor
end
theorem perm_union_left {l₁ l₂ : list α} (t₁ : list α) (h : l₁ ~ l₂) : l₁ ∪ t₁ ~ l₂ ∪ t₁ :=
begin
induction h with a _ _ _ ih _ _ _ _ _ _ _ _ ih_1 ih_2; try {simp},
{ exact perm_insert a ih },
{ apply perm_insert_swap },
{ exact ih_1.trans ih_2 }
end
theorem perm_union_right (l : list α) {t₁ t₂ : list α} (h : t₁ ~ t₂) : l ∪ t₁ ~ l ∪ t₂ :=
by induction l; simp [*, perm_insert]
-- @[congr]
theorem perm_union {l₁ l₂ t₁ t₂ : list α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∪ t₁ ~ l₂ ∪ t₂ :=
trans (perm_union_left t₁ p₁) (perm_union_right l₂ p₂)
theorem perm_inter_left {l₁ l₂ : list α} (t₁ : list α) : l₁ ~ l₂ → l₁ ∩ t₁ ~ l₂ ∩ t₁ :=
perm_filter _
theorem perm_inter_right (l : list α) {t₁ t₂ : list α} (p : t₁ ~ t₂) : l ∩ t₁ = l ∩ t₂ :=
by dsimp [(∩), list.inter]; congr; funext a; rw [mem_of_perm p]
-- @[congr]
theorem perm_inter {l₁ l₂ t₁ t₂ : list α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ∩ t₁ ~ l₂ ∩ t₂ :=
perm_inter_right l₂ p₂ ▸ perm_inter_left t₁ p₁
end
theorem perm_pairwise {R : α → α → Prop} (S : symmetric R) :
∀ {l₁ l₂ : list α} (p : l₁ ~ l₂), pairwise R l₁ ↔ pairwise R l₂ :=
suffices ∀ {l₁ l₂}, l₁ ~ l₂ → pairwise R l₁ → pairwise R l₂, from λ l₁ l₂ p, ⟨this p, this p.symm⟩,
λ l₁ l₂ p d, begin
induction d with a l₁ h d IH generalizing l₂,
{ rw eq_nil_of_perm_nil p, constructor },
{ have : a ∈ l₂ := perm_subset p (mem_cons_self _ _),
rcases mem_split this with ⟨s₂, t₂, rfl⟩,
have p' := perm_cons_inv (p.trans perm_middle),
refine (pairwise_middle S).2 (pairwise_cons.2 ⟨λ b m, _, IH _ p'⟩),
exact h _ (perm_subset p'.symm m) }
end
theorem perm_nodup {l₁ l₂ : list α} : l₁ ~ l₂ → (nodup l₁ ↔ nodup l₂) :=
perm_pairwise $ @ne.symm α
theorem perm_bind_left {l₁ l₂ : list α} (f : α → list β) (p : l₁ ~ l₂) :
l₁.bind f ~ l₂.bind f :=
begin
induction p with a l₁ l₂ p IH a b l l₁ l₂ l₃ p₁ p₂ IH₁ IH₂, {simp},
{ simp, exact perm_app_right _ IH },
{ simp, rw [← append_assoc, ← append_assoc], exact perm_app_left _ perm_app_comm },
{ exact trans IH₁ IH₂ }
end
theorem perm_bind_right (l : list α) {f g : α → list β} (h : ∀ a, f a ~ g a) :
l.bind f ~ l.bind g :=
by induction l with a l IH; simp; exact perm_app (h a) IH
theorem perm_product_left {l₁ l₂ : list α} (t₁ : list β) (p : l₁ ~ l₂) : product l₁ t₁ ~ product l₂ t₁ :=
perm_bind_left _ p
theorem perm_product_right (l : list α) {t₁ t₂ : list β} (p : t₁ ~ t₂) : product l t₁ ~ product l t₂ :=
perm_bind_right _ $ λ a, perm_map _ p
@[congr] theorem perm_product {l₁ l₂ : list α} {t₁ t₂ : list β}
(p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : product l₁ t₁ ~ product l₂ t₂ :=
trans (perm_product_left t₁ p₁) (perm_product_right l₂ p₂)
theorem sublists_cons_perm_append (a : α) (l : list α) :
sublists (a :: l) ~ sublists l ++ map (cons a) (sublists l) :=
begin
simp [sublists, sublists_aux_cons_cons],
refine skip _ ((skip _ _).trans perm_middle.symm),
induction sublists_aux l cons with b l IH; simp,
exact skip b ((skip _ IH).trans perm_middle.symm)
end
theorem sublists_perm_sublists' : ∀ l : list α, sublists l ~ sublists' l
| [] := perm.refl _
| (a::l) := let IH := sublists_perm_sublists' l in
by rw sublists'_cons; exact
(sublists_cons_perm_append _ _).trans (perm_app IH (perm_map _ IH))
theorem revzip_sublists (l : list α) :
∀ l₁ l₂, (l₁, l₂) ∈ revzip l.sublists → l₁ ++ l₂ ~ l :=
begin
rw revzip,
apply list.reverse_rec_on l,
{ intros l₁ l₂ h, simp at h, simp [h] },
{ intros l a IH l₁ l₂ h,
rw [sublists_concat, reverse_append, zip_append, ← map_reverse,
zip_map_right, zip_map_left] at h; [simp at h, simp],
rcases h with ⟨l₁, l₂', h, rfl, rfl⟩ | ⟨l₁', l₂, h, rfl, rfl⟩,
{ rw ← append_assoc,
exact perm_app_left _ (IH _ _ h) },
{ rw append_assoc,
apply (perm_app_right _ perm_app_comm).trans,
rw ← append_assoc,
exact perm_app_left _ (IH _ _ h) } }
end
theorem revzip_sublists' (l : list α) :
∀ l₁ l₂, (l₁, l₂) ∈ revzip l.sublists' → l₁ ++ l₂ ~ l :=
begin
rw revzip,
induction l with a l IH; intros l₁ l₂ h,
{ simp at h, simp [h] },
{ rw [sublists'_cons, reverse_append, zip_append, ← map_reverse,
zip_map_right, zip_map_left] at h; [simp at h, simp],
rcases h with ⟨l₁, l₂', h, rfl, rfl⟩ | ⟨l₁', l₂, h, rfl, rfl⟩,
{ exact perm_middle.trans (skip _ (IH _ _ h)) },
{ exact skip _ (IH _ _ h) } }
end
theorem perm_lookmap (f : α → option α) {l₁ l₂ : list α}
(H : pairwise (λ a b, ∀ (c ∈ f a) (d ∈ f b), a = b ∧ c = d) l₁)
(p : l₁ ~ l₂) : lookmap f l₁ ~ lookmap f l₂ :=
begin
let F := λ a b, ∀ (c ∈ f a) (d ∈ f b), a = b ∧ c = d,
change pairwise F l₁ at H,
induction p with a l₁ l₂ p IH a b l l₁ l₂ l₃ p₁ p₂ IH₁ IH₂, {simp},
{ cases h : f a,
{ simp [h], exact (IH (pairwise_cons.1 H).2).skip _ },
{ simp [lookmap_cons_some _ _ h], exact p.skip _ } },
{ cases h₁ : f a with c; cases h₂ : f b with d,
{ simp [h₁, h₂], apply swap },
{ simp [h₁, lookmap_cons_some _ _ h₂], apply swap },
{ simp [lookmap_cons_some _ _ h₁, h₂], apply swap },
{ simp [lookmap_cons_some _ _ h₁, lookmap_cons_some _ _ h₂],
rcases (pairwise_cons.1 H).1 _ (or.inl rfl) _ h₂ _ h₁ with ⟨rfl, rfl⟩,
refl } },
{ refine (IH₁ H).trans (IH₂ ((perm_pairwise _ p₁).1 H)),
exact λ a b h c h₁ d h₂, (h d h₂ c h₁).imp eq.symm eq.symm }
end
theorem perm_erasep (f : α → Prop) [decidable_pred f] {l₁ l₂ : list α}
(H : pairwise (λ a b, f a → f b → false) l₁)
(p : l₁ ~ l₂) : erasep f l₁ ~ erasep f l₂ :=
begin
let F := λ a b, f a → f b → false,
change pairwise F l₁ at H,
induction p with a l₁ l₂ p IH a b l l₁ l₂ l₃ p₁ p₂ IH₁ IH₂, {simp},
{ by_cases h : f a,
{ simp [h, p] },
{ simp [h], exact (IH (pairwise_cons.1 H).2).skip _ } },
{ by_cases h₁ : f a; by_cases h₂ : f b; simp [h₁, h₂],
{ cases (pairwise_cons.1 H).1 _ (or.inl rfl) h₂ h₁ },
{ apply swap } },
{ refine (IH₁ H).trans (IH₂ ((perm_pairwise _ p₁).1 H)),
exact λ a b h h₁ h₂, h h₂ h₁ }
end
/- enumerating permutations -/
section permutations
theorem permutations_aux2_fst (t : α) (ts : list α) (r : list β) : ∀ (ys : list α) (f : list α → β),
(permutations_aux2 t ts r ys f).1 = ys ++ ts
| [] f := rfl
| (y::ys) f := match _, permutations_aux2_fst ys _ : ∀ o : list α × list β, o.1 = ys ++ ts →
(permutations_aux2._match_1 t y f o).1 = y :: ys ++ ts with
| ⟨_, zs⟩, rfl := rfl
end
@[simp] theorem permutations_aux2_snd_nil (t : α) (ts : list α) (r : list β) (f : list α → β) :
(permutations_aux2 t ts r [] f).2 = r := rfl
@[simp] theorem permutations_aux2_snd_cons (t : α) (ts : list α) (r : list β) (y : α) (ys : list α) (f : list α → β) :
(permutations_aux2 t ts r (y::ys) f).2 = f (t :: y :: ys ++ ts) ::
(permutations_aux2 t ts r ys (λx : list α, f (y::x))).2 :=
match _, permutations_aux2_fst t ts r _ _ : ∀ o : list α × list β, o.1 = ys ++ ts →
(permutations_aux2._match_1 t y f o).2 = f (t :: y :: ys ++ ts) :: o.2 with
| ⟨_, zs⟩, rfl := rfl
end
theorem permutations_aux2_append (t : α) (ts : list α) (r : list β) (ys : list α) (f : list α → β) :
(permutations_aux2 t ts nil ys f).2 ++ r = (permutations_aux2 t ts r ys f).2 :=
by induction ys generalizing f; simp *
theorem mem_permutations_aux2 {t : α} {ts : list α} {ys : list α} {l l' : list α} :
l' ∈ (permutations_aux2 t ts [] ys (append l)).2 ↔
∃ l₁ l₂, l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l' = l ++ l₁ ++ t :: l₂ ++ ts :=
begin
induction ys with y ys ih generalizing l,
{ simp {contextual := tt} },
{ rw [permutations_aux2_snd_cons, show (λ (x : list α), l ++ y :: x) = append (l ++ [y]),
by funext; simp, mem_cons_iff, ih], split; intro h,
{ rcases h with e | ⟨l₁, l₂, l0, ye, _⟩,
{ subst l', exact ⟨[], y::ys, by simp⟩ },
{ substs l' ys, exact ⟨y::l₁, l₂, l0, by simp⟩ } },
{ rcases h with ⟨_ | ⟨y', l₁⟩, l₂, l0, ye, rfl⟩,
{ simp [ye] },
{ simp at ye, rcases ye with ⟨rfl, rfl⟩,
exact or.inr ⟨l₁, l₂, l0, by simp⟩ } } }
end
theorem mem_permutations_aux2' {t : α} {ts : list α} {ys : list α} {l : list α} :
l ∈ (permutations_aux2 t ts [] ys id).2 ↔
∃ l₁ l₂, l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l = l₁ ++ t :: l₂ ++ ts :=
by rw [show @id (list α) = append nil, by funext; refl]; apply mem_permutations_aux2
theorem length_permutations_aux2 (t : α) (ts : list α) (ys : list α) (f : list α → β) :
length (permutations_aux2 t ts [] ys f).2 = length ys :=
by induction ys generalizing f; simp *
theorem foldr_permutations_aux2 (t : α) (ts : list α) (r L : list (list α)) :
foldr (λy r, (permutations_aux2 t ts r y id).2) r L = L.bind (λ y, (permutations_aux2 t ts [] y id).2) ++ r :=
by induction L with l L ih; [refl, {simp [ih], rw ← permutations_aux2_append}]
theorem mem_foldr_permutations_aux2 {t : α} {ts : list α} {r L : list (list α)} {l' : list α} :
l' ∈ foldr (λy r, (permutations_aux2 t ts r y id).2) r L ↔ l' ∈ r ∨
∃ l₁ l₂, l₁ ++ l₂ ∈ L ∧ l₂ ≠ [] ∧ l' = l₁ ++ t :: l₂ ++ ts :=
have (∃ (a : list α), a ∈ L ∧
∃ (l₁ l₂ : list α), ¬l₂ = nil ∧ a = l₁ ++ l₂ ∧ l' = l₁ ++ t :: (l₂ ++ ts)) ↔
∃ (l₁ l₂ : list α), ¬l₂ = nil ∧ l₁ ++ l₂ ∈ L ∧ l' = l₁ ++ t :: (l₂ ++ ts),
from ⟨λ ⟨a, aL, l₁, l₂, l0, e, h⟩, ⟨l₁, l₂, l0, e ▸ aL, h⟩,
λ ⟨l₁, l₂, l0, aL, h⟩, ⟨_, aL, l₁, l₂, l0, rfl, h⟩⟩,
by rw foldr_permutations_aux2; simp [mem_permutations_aux2', this,
or.comm, or.left_comm, or.assoc, and.comm, and.left_comm, and.assoc]
theorem length_foldr_permutations_aux2 (t : α) (ts : list α) (r L : list (list α)) :
length (foldr (λy r, (permutations_aux2 t ts r y id).2) r L) = sum (map length L) + length r :=
by simp [foldr_permutations_aux2, (∘), length_permutations_aux2]
theorem length_foldr_permutations_aux2' (t : α) (ts : list α) (r L : list (list α))
(n) (H : ∀ l ∈ L, length l = n) :
length (foldr (λy r, (permutations_aux2 t ts r y id).2) r L) = n * length L + length r :=
begin
rw [length_foldr_permutations_aux2, (_ : sum (map length L) = n * length L)],
induction L with l L ih, {simp},
simp [ih (λ l m, H l (mem_cons_of_mem _ m)), H l (mem_cons_self _ _), mul_add]
end
theorem perm_of_mem_permutations_aux :
∀ {ts is l : list α}, l ∈ permutations_aux ts is → l ~ ts ++ is :=
begin
refine permutations_aux.rec (by simp) _,
introv IH1 IH2 m,
rw [permutations_aux_cons, permutations, mem_foldr_permutations_aux2] at m,
rcases m with m | ⟨l₁, l₂, m, _, e⟩,
{ exact (IH1 m).trans perm_middle },
{ subst e,
have p : l₁ ++ l₂ ~ is,
{ simp [permutations] at m,
cases m with e m, {simp [e]},
exact is.append_nil ▸ IH2 m },
exact (perm_app_left _ (perm_middle.trans (skip _ p))).trans (skip _ perm_app_comm) }
end
theorem perm_of_mem_permutations {l₁ l₂ : list α}
(h : l₁ ∈ permutations l₂) : l₁ ~ l₂ :=
(eq_or_mem_of_mem_cons h).elim (λ e, e ▸ perm.refl _)
(λ m, append_nil l₂ ▸ perm_of_mem_permutations_aux m)
theorem length_permutations_aux :
∀ ts is : list α, length (permutations_aux ts is) + is.length.fact = (length ts + length is).fact :=
begin
refine permutations_aux.rec (by simp) _,
intros t ts is IH1 IH2,
have IH2 : length (permutations_aux is nil) + 1 = is.length.fact,
{ simpa using IH2 },
simp [-add_comm, nat.fact, nat.add_succ, mul_comm] at IH1,
rw [permutations_aux_cons,
length_foldr_permutations_aux2' _ _ _ _ _
(λ l m, perm_length (perm_of_mem_permutations m)),
permutations, length, length, IH2,
nat.succ_add, nat.fact_succ, mul_comm (nat.succ _), ← IH1,
add_comm (_*_), add_assoc, nat.mul_succ, mul_comm]
end
theorem length_permutations (l : list α) : length (permutations l) = (length l).fact :=
length_permutations_aux l []
theorem mem_permutations_of_perm_lemma {is l : list α}
(H : l ~ [] ++ is → (∃ ts' ~ [], l = ts' ++ is) ∨ l ∈ permutations_aux is [])
: l ~ is → l ∈ permutations is :=
by simpa [permutations, perm_nil] using H
theorem mem_permutations_aux_of_perm :
∀ {ts is l : list α}, l ~ is ++ ts → (∃ is' ~ is, l = is' ++ ts) ∨ l ∈ permutations_aux ts is :=
begin
refine permutations_aux.rec (by simp) _,
intros t ts is IH1 IH2 l p,
rw [permutations_aux_cons, mem_foldr_permutations_aux2],
rcases IH1 (p.trans perm_middle) with ⟨is', p', e⟩ | m,
{ clear p, subst e,
rcases mem_split (perm_subset p'.symm (mem_cons_self _ _)) with ⟨l₁, l₂, e⟩,
subst is',
have p := perm_cons_inv (perm_middle.symm.trans p'),
cases l₂ with a l₂',
{ exact or.inl ⟨l₁, by simpa using p⟩ },
{ exact or.inr (or.inr ⟨l₁, a::l₂',
mem_permutations_of_perm_lemma IH2 p, by simp⟩) } },
{ exact or.inr (or.inl m) }
end
@[simp] theorem mem_permutations (s t : list α) : s ∈ permutations t ↔ s ~ t :=
⟨perm_of_mem_permutations, mem_permutations_of_perm_lemma mem_permutations_aux_of_perm⟩
end permutations
end list
|
22ac56e5d338dd63b69fd6daba4e5e7d9368f244 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/measure_theory/covering/density_theorem.lean | 143854e2f2ca96eca0320f61c72a5f3dcc7c244d | [
"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 | 8,786 | lean | /-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import measure_theory.measure.doubling
import measure_theory.covering.vitali
import measure_theory.covering.differentiation
/-!
# Uniformly locally doubling measures and Lebesgue's density theorem
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Lebesgue's density theorem states that given a set `S` in a sigma compact metric space with
locally-finite uniformly locally doubling measure `μ` then for almost all points `x` in `S`, for any
sequence of closed balls `B₀, B₁, B₂, ...` containing `x`, the limit `μ (S ∩ Bⱼ) / μ (Bⱼ) → 1` as
`j → ∞`.
In this file we combine general results about existence of Vitali families for uniformly locally
doubling measures with results about differentiation along a Vitali family to obtain an explicit
form of Lebesgue's density theorem.
## Main results
* `is_unif_loc_doubling_measure.ae_tendsto_measure_inter_div`: a version of Lebesgue's density
theorem for sequences of balls converging on a point but whose centres are not required to be
fixed.
-/
noncomputable theory
open set filter metric measure_theory topological_space
open_locale nnreal topology
namespace is_unif_loc_doubling_measure
variables {α : Type*} [metric_space α] [measurable_space α]
(μ : measure α) [is_unif_loc_doubling_measure μ]
section
variables [second_countable_topology α] [borel_space α] [is_locally_finite_measure μ]
open_locale topology
/-- A Vitali family in a space with a uniformly locally doubling measure, designed so that the sets
at `x` contain all `closed_ball y r` when `dist x y ≤ K * r`. -/
@[irreducible] def vitali_family (K : ℝ) : vitali_family μ :=
begin
/- the Vitali covering theorem gives a family that works well at small scales, thanks to the
doubling property. We enlarge this family to add large sets, to make sure that all balls and not
only small ones belong to the family, for convenience. -/
let R := scaling_scale_of μ (max (4 * K + 3) 3),
have Rpos : 0 < R := scaling_scale_of_pos _ _,
have A : ∀ (x : α), ∃ᶠ r in 𝓝[>] (0 : ℝ),
μ (closed_ball x (3 * r)) ≤ scaling_constant_of μ (max (4 * K + 3) 3) * μ (closed_ball x r),
{ assume x,
apply frequently_iff.2 (λ U hU, _),
obtain ⟨ε, εpos, hε⟩ := mem_nhds_within_Ioi_iff_exists_Ioc_subset.1 hU,
refine ⟨min ε R, hε ⟨lt_min εpos Rpos, min_le_left _ _⟩, _⟩,
exact measure_mul_le_scaling_constant_of_mul μ
⟨zero_lt_three, le_max_right _ _⟩ (min_le_right _ _) },
exact (vitali.vitali_family μ (scaling_constant_of μ (max (4 * K + 3) 3)) A).enlarge
(R / 4) (by linarith),
end
/-- In the Vitali family `is_unif_loc_doubling_measure.vitali_family K`, the sets based at `x`
contain all balls `closed_ball y r` when `dist x y ≤ K * r`. -/
lemma closed_ball_mem_vitali_family_of_dist_le_mul
{K : ℝ} {x y : α} {r : ℝ} (h : dist x y ≤ K * r) (rpos : 0 < r) :
closed_ball y r ∈ (vitali_family μ K).sets_at x :=
begin
let R := scaling_scale_of μ (max (4 * K + 3) 3),
simp only [vitali_family, vitali_family.enlarge, vitali.vitali_family, mem_union, mem_set_of_eq,
is_closed_ball, true_and, (nonempty_ball.2 rpos).mono ball_subset_interior_closed_ball,
measurable_set_closed_ball],
/- The measure is doubling on scales smaller than `R`. Therefore, we treat differently small
and large balls. For large balls, this follows directly from the enlargement we used in the
definition. -/
by_cases H : closed_ball y r ⊆ closed_ball x (R / 4),
swap, { exact or.inr H },
left,
/- For small balls, there is the difficulty that `r` could be large but still the ball could be
small, if the annulus `{y | ε ≤ dist y x ≤ R/4}` is empty. We split between the cases `r ≤ R`
and `r < R`, and use the doubling for the former and rough estimates for the latter. -/
rcases le_or_lt r R with hr|hr,
{ refine ⟨(K + 1) * r, _⟩,
split,
{ apply closed_ball_subset_closed_ball',
rw dist_comm,
linarith },
{ have I1 : closed_ball x (3 * ((K + 1) * r)) ⊆ closed_ball y ((4 * K + 3) * r),
{ apply closed_ball_subset_closed_ball',
linarith },
have I2 : closed_ball y ((4 * K + 3) * r) ⊆ closed_ball y ((max (4 * K + 3) 3) * r),
{ apply closed_ball_subset_closed_ball,
exact mul_le_mul_of_nonneg_right (le_max_left _ _) rpos.le },
apply (measure_mono (I1.trans I2)).trans,
exact measure_mul_le_scaling_constant_of_mul _
⟨zero_lt_three.trans_le (le_max_right _ _), le_rfl⟩ hr } },
{ refine ⟨R / 4, H, _⟩,
have : closed_ball x (3 * (R / 4)) ⊆ closed_ball y r,
{ apply closed_ball_subset_closed_ball',
have A : y ∈ closed_ball y r, from mem_closed_ball_self rpos.le,
have B := mem_closed_ball'.1 (H A),
linarith },
apply (measure_mono this).trans _,
refine le_mul_of_one_le_left (zero_le _) _,
exact ennreal.one_le_coe_iff.2 (le_max_right _ _) }
end
lemma tendsto_closed_ball_filter_at {K : ℝ} {x : α} {ι : Type*} {l : filter ι}
(w : ι → α) (δ : ι → ℝ) (δlim : tendsto δ l (𝓝[>] 0))
(xmem : ∀ᶠ j in l, x ∈ closed_ball (w j) (K * δ j)) :
tendsto (λ j, closed_ball (w j) (δ j)) l ((vitali_family μ K).filter_at x) :=
begin
refine (vitali_family μ K).tendsto_filter_at_iff.mpr ⟨_, λ ε hε, _⟩,
{ filter_upwards [xmem, δlim self_mem_nhds_within] with j hj h'j,
exact closed_ball_mem_vitali_family_of_dist_le_mul μ hj h'j },
{ by_cases l.ne_bot,
swap, { simp [not_ne_bot.1 h] },
have hK : 0 ≤ K,
{ resetI,
rcases (xmem.and (δlim self_mem_nhds_within)).exists with ⟨j, hj, h'j⟩,
have : 0 ≤ K * δ j := nonempty_closed_ball.1 ⟨x, hj⟩,
exact (mul_nonneg_iff_left_nonneg_of_pos (mem_Ioi.1 h'j)).1 this },
have δpos := eventually_mem_of_tendsto_nhds_within δlim,
replace δlim := tendsto_nhds_of_tendsto_nhds_within δlim,
replace hK : 0 < K + 1, by linarith,
apply (((metric.tendsto_nhds.mp δlim _ (div_pos hε hK)).and δpos).and xmem).mono,
rintros j ⟨⟨hjε, hj₀ : 0 < δ j⟩, hx⟩ y hy,
replace hjε : (K + 1) * δ j < ε :=
by simpa [abs_eq_self.mpr hj₀.le] using (lt_div_iff' hK).mp hjε,
simp only [mem_closed_ball] at hx hy ⊢,
linarith [dist_triangle_right y x (w j)] }
end
end
section applications
variables [second_countable_topology α] [borel_space α] [is_locally_finite_measure μ]
{E : Type*} [normed_add_comm_group E]
/-- A version of *Lebesgue's density theorem* for a sequence of closed balls whose centers are
not required to be fixed.
See also `besicovitch.ae_tendsto_measure_inter_div`. -/
lemma ae_tendsto_measure_inter_div (S : set α) (K : ℝ) :
∀ᵐ x ∂μ.restrict S, ∀ {ι : Type*} {l : filter ι} (w : ι → α) (δ : ι → ℝ)
(δlim : tendsto δ l (𝓝[>] 0))
(xmem : ∀ᶠ j in l, x ∈ closed_ball (w j) (K * δ j)),
tendsto (λ j, μ (S ∩ closed_ball (w j) (δ j)) / μ (closed_ball (w j) (δ j))) l (𝓝 1) :=
by filter_upwards [(vitali_family μ K).ae_tendsto_measure_inter_div S] with x hx ι l w δ δlim xmem
using hx.comp (tendsto_closed_ball_filter_at μ _ _ δlim xmem)
/-- A version of *Lebesgue differentiation theorem* for a sequence of closed balls whose
centers are not required to be fixed. -/
lemma ae_tendsto_average_norm_sub {f : α → E} (hf : integrable f μ) (K : ℝ) :
∀ᵐ x ∂μ, ∀ {ι : Type*} {l : filter ι} (w : ι → α) (δ : ι → ℝ)
(δlim : tendsto δ l (𝓝[>] 0))
(xmem : ∀ᶠ j in l, x ∈ closed_ball (w j) (K * δ j)),
tendsto (λ j, ⨍ y in closed_ball (w j) (δ j), ‖f y - f x‖ ∂μ) l (𝓝 0) :=
by filter_upwards [(vitali_family μ K).ae_tendsto_average_norm_sub hf] with x hx ι l w δ δlim xmem
using hx.comp (tendsto_closed_ball_filter_at μ _ _ δlim xmem)
/-- A version of *Lebesgue differentiation theorem* for a sequence of closed balls whose
centers are not required to be fixed. -/
lemma ae_tendsto_average [normed_space ℝ E] [complete_space E]
{f : α → E} (hf : integrable f μ) (K : ℝ) :
∀ᵐ x ∂μ, ∀ {ι : Type*} {l : filter ι} (w : ι → α) (δ : ι → ℝ)
(δlim : tendsto δ l (𝓝[>] 0))
(xmem : ∀ᶠ j in l, x ∈ closed_ball (w j) (K * δ j)),
tendsto (λ j, ⨍ y in closed_ball (w j) (δ j), f y ∂μ) l (𝓝 (f x)) :=
by filter_upwards [(vitali_family μ K).ae_tendsto_average hf] with x hx ι l w δ δlim xmem
using hx.comp (tendsto_closed_ball_filter_at μ _ _ δlim xmem)
end applications
end is_unif_loc_doubling_measure
|
8c8d42b9fba89b75e15ca521022e36934dcec722 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/1228.lean | 45dd064b492f9303bf369c8c46f629faaf8831e9 | [
"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 | 1,018 | lean | inductive Foo (n : Nat) : Type
| foo (t: Foo n): Foo n
namespace Foo
inductive Bar: Foo n → Prop
theorem ex₁ {s: Foo n} (H: s.Bar): True := by
cases h₁ : s
case foo s' =>
cases h₂ : n; sorry
have: Bar s' := sorry
exact ex₁ this
termination_by _ => sizeOf s
theorem ex₂
{s: Foo n}
(H: s.Bar):
True := by
generalize hs': s = s'
match s' with
| foo s' =>
have: Bar s' := sorry
have hterm: sizeOf s' < sizeOf s := by simp_all_arith
exact ex₂ this
termination_by _ => sizeOf s
theorem ex₃ {s: Foo n} (H: s.Bar): True := by
cases h₁ : s
case foo s' =>
match n with
| 0 => sorry
| _ =>
have: Bar s' := sorry
exact ex₃ this
termination_by _ => sizeOf s
-- it works
theorem ex₄ {s: Foo n} (H: s.Bar): True := by
match s with
| foo s' =>
match n with
| 0 => sorry
| _ =>
have: Bar s' := sorry
exact ex₄ this
termination_by _ => sizeOf s
|
9277e2749b9169763c3bff71093f588c69d33520 | 46125763b4dbf50619e8846a1371029346f4c3db | /src/analysis/calculus/tangent_cone.lean | 0e07c3a014f0daa898dce15680d5fcc08a258197 | [
"Apache-2.0"
] | permissive | thjread/mathlib | a9d97612cedc2c3101060737233df15abcdb9eb1 | 7cffe2520a5518bba19227a107078d83fa725ddc | refs/heads/master | 1,615,637,696,376 | 1,583,953,063,000 | 1,583,953,063,000 | 246,680,271 | 0 | 0 | Apache-2.0 | 1,583,960,875,000 | 1,583,960,875,000 | null | UTF-8 | Lean | false | false | 16,536 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.convex.basic analysis.normed_space.bounded_linear_maps analysis.specific_limits
/-!
# Tangent cone
In this file, we define two predicates `unique_diff_within_at 𝕜 s x` and `unique_diff_on 𝕜 s`
ensuring that, if a function has two derivatives, then they have to coincide. As a direct
definition of this fact (quantifying on all target types and all functions) would depend on
universes, we use a more intrinsic definition: if all the possible tangent directions to the set
`s` at the point `x` span a dense subset of the whole subset, it is easy to check that the
derivative has to be unique.
Therefore, we introduce the set of all tangent directions, named `tangent_cone_at`,
and express `unique_diff_within_at` and `unique_diff_on` in terms of it.
One should however think of this definition as an implementation detail: the only reason to
introduce the predicates `unique_diff_within_at` and `unique_diff_on` is to ensure the uniqueness
of the derivative. This is why their names reflect their uses, and not how they are defined.
## Implementation details
Note that this file is imported by `fderiv.lean`. Hence, derivatives are not defined yet. The
property of uniqueness of the derivative is therefore proved in `fderiv.lean`, but based on the
properties of the tangent cone we prove here.
-/
variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
variables {E : Type*} [normed_group E] [normed_space 𝕜 E]
variables {F : Type*} [normed_group F] [normed_space 𝕜 F]
variables {G : Type*} [normed_group G] [normed_space ℝ G]
set_option class.instance_max_depth 50
open filter set
open_locale topological_space
/-- The set of all tangent directions to the set `s` at the point `x`. -/
def tangent_cone_at (s : set E) (x : E) : set E :=
{y : E | ∃(c : ℕ → 𝕜) (d : ℕ → E), (∀ᶠ n in at_top, x + d n ∈ s) ∧
(tendsto (λn, ∥c n∥) at_top at_top) ∧ (tendsto (λn, c n • d n) at_top (𝓝 y))}
/-- A property ensuring that the tangent cone to `s` at `x` spans a dense subset of the whole space.
The main role of this property is to ensure that the differential within `s` at `x` is unique,
hence this name. The uniqueness it asserts is proved in `unique_diff_within_at.eq` in `fderiv.lean`.
To avoid pathologies in dimension 0, we also require that `x` belongs to the closure of `s` (which
is automatic when `E` is not `0`-dimensional).
-/
def unique_diff_within_at (s : set E) (x : E) : Prop :=
closure ((submodule.span 𝕜 (tangent_cone_at 𝕜 s x)) : set E) = univ ∧ x ∈ closure s
/-- A property ensuring that the tangent cone to `s` at any of its points spans a dense subset of
the whole space. The main role of this property is to ensure that the differential along `s` is
unique, hence this name. The uniqueness it asserts is proved in `unique_diff_on.eq` in
`fderiv.lean`. -/
def unique_diff_on (s : set E) : Prop :=
∀x ∈ s, unique_diff_within_at 𝕜 s x
variables {𝕜} {x y : E} {s t : set E}
section tangent_cone
/- This section is devoted to the properties of the tangent cone. -/
open normed_field
lemma tangent_cone_univ : tangent_cone_at 𝕜 univ x = univ :=
begin
refine univ_subset_iff.1 (λy hy, _),
rcases exists_one_lt_norm 𝕜 with ⟨w, hw⟩,
refine ⟨λn, w^n, λn, (w^n)⁻¹ • y, univ_mem_sets' (λn, mem_univ _), _, _⟩,
{ simp only [norm_pow],
exact tendsto_pow_at_top_at_top_of_gt_1 hw },
{ convert tendsto_const_nhds,
ext n,
have : w ^ n * (w ^ n)⁻¹ = 1,
{ apply mul_inv_cancel,
apply pow_ne_zero,
simpa [norm_eq_zero] using (ne_of_lt (lt_trans zero_lt_one hw)).symm },
rw [smul_smul, this, one_smul] }
end
lemma tangent_cone_mono (h : s ⊆ t) :
tangent_cone_at 𝕜 s x ⊆ tangent_cone_at 𝕜 t x :=
begin
rintros y ⟨c, d, ds, ctop, clim⟩,
exact ⟨c, d, mem_sets_of_superset ds (λn hn, h hn), ctop, clim⟩
end
/-- Auxiliary lemma ensuring that, under the assumptions defining the tangent cone,
the sequence `d` tends to 0 at infinity. -/
lemma tangent_cone_at.lim_zero {α : Type*} (l : filter α) {c : α → 𝕜} {d : α → E}
(hc : tendsto (λn, ∥c n∥) l at_top) (hd : tendsto (λn, c n • d n) l (𝓝 y)) :
tendsto d l (𝓝 0) :=
begin
have A : tendsto (λn, ∥c n∥⁻¹) l (𝓝 0) := tendsto_inv_at_top_zero.comp hc,
have B : tendsto (λn, ∥c n • d n∥) l (𝓝 ∥y∥) :=
(continuous_norm.tendsto _).comp hd,
have C : tendsto (λn, ∥c n∥⁻¹ * ∥c n • d n∥) l (𝓝 (0 * ∥y∥)) := A.mul B,
rw zero_mul at C,
have : ∀ᶠ n in l, ∥c n∥⁻¹ * ∥c n • d n∥ = ∥d n∥,
{ apply (eventually_ne_of_tendsto_norm_at_top hc 0).mono (λn hn, _),
rw [norm_smul, ← mul_assoc, inv_mul_cancel, one_mul],
rwa [ne.def, norm_eq_zero] },
have D : tendsto (λ n, ∥d n∥) l (𝓝 0) :=
tendsto.congr' this C,
rw tendsto_zero_iff_norm_tendsto_zero,
exact D
end
lemma tangent_cone_mono_nhds (h : nhds_within x s ≤ nhds_within x t) :
tangent_cone_at 𝕜 s x ⊆ tangent_cone_at 𝕜 t x :=
begin
rintros y ⟨c, d, ds, ctop, clim⟩,
refine ⟨c, d, _, ctop, clim⟩,
suffices : tendsto (λ n, x + d n) at_top (nhds_within x t),
from tendsto_principal.1 (tendsto_inf.1 this).2,
apply tendsto_le_right h,
refine tendsto_inf.2 ⟨_, tendsto_principal.2 ds⟩,
simpa only [add_zero] using tendsto_const_nhds.add (tangent_cone_at.lim_zero at_top ctop clim)
end
/-- Tangent cone of `s` at `x` depends only on `nhds_within x s`. -/
lemma tangent_cone_congr (h : nhds_within x s = nhds_within x t) :
tangent_cone_at 𝕜 s x = tangent_cone_at 𝕜 t x :=
subset.antisymm
(tangent_cone_mono_nhds $ le_of_eq h)
(tangent_cone_mono_nhds $ le_of_eq h.symm)
/-- Intersecting with a neighborhood of the point does not change the tangent cone. -/
lemma tangent_cone_inter_nhds (ht : t ∈ 𝓝 x) :
tangent_cone_at 𝕜 (s ∩ t) x = tangent_cone_at 𝕜 s x :=
tangent_cone_congr (nhds_within_restrict' _ ht).symm
/-- The tangent cone of a product contains the tangent cone of its left factor. -/
lemma subset_tangent_cone_prod_left {t : set F} {y : F} (ht : y ∈ closure t) :
prod.inl '' (tangent_cone_at 𝕜 s x) ⊆ tangent_cone_at 𝕜 (set.prod s t) (x, y) :=
begin
rintros _ ⟨v, ⟨c, d, hd, hc, hy⟩, rfl⟩,
have : ∀n, ∃d', y + d' ∈ t ∧ ∥c n • d'∥ ≤ ((1:ℝ)/2)^n,
{ assume n,
have c_pos : 0 < 1 + ∥c n∥ :=
add_pos_of_pos_of_nonneg zero_lt_one (norm_nonneg _),
rcases metric.mem_closure_iff.1 ht ((1 + ∥c n∥)⁻¹ * (1/2)^n) _ with ⟨z, z_pos, hz⟩,
refine ⟨z - y, _, _⟩,
{ convert z_pos, abel },
{ rw [norm_smul, ← dist_eq_norm, dist_comm],
calc ∥c n∥ * dist y z ≤ (1 + ∥c n∥) * ((1 + ∥c n∥)⁻¹ * (1/2)^n) :
begin
apply mul_le_mul _ (le_of_lt hz) dist_nonneg (le_of_lt c_pos),
simp only [zero_le_one, le_add_iff_nonneg_left]
end
... = (1/2)^n :
begin
rw [← mul_assoc, mul_inv_cancel, one_mul],
exact ne_of_gt c_pos
end },
{ apply mul_pos (inv_pos c_pos) (pow_pos _ _),
norm_num } },
choose d' hd' using this,
refine ⟨c, λn, (d n, d' n), _, hc, _⟩,
show ∀ᶠ n in at_top, (x, y) + (d n, d' n) ∈ set.prod s t,
{ apply filter.mem_sets_of_superset hd,
assume n hn,
simp at hn,
simp [hn, (hd' n).1] },
{ apply hy.prod_mk_nhds,
change tendsto (λ (n : ℕ), c n • d' n) at_top (𝓝 0),
rw tendsto_zero_iff_norm_tendsto_zero,
refine squeeze_zero (λn, norm_nonneg _) (λn, (hd' n).2) _,
apply tendsto_pow_at_top_nhds_0_of_lt_1; norm_num }
end
/-- The tangent cone of a product contains the tangent cone of its right factor. -/
lemma subset_tangent_cone_prod_right {t : set F} {y : F}
(hs : x ∈ closure s) :
prod.inr '' (tangent_cone_at 𝕜 t y) ⊆ tangent_cone_at 𝕜 (set.prod s t) (x, y) :=
begin
rintros _ ⟨w, ⟨c, d, hd, hc, hy⟩, rfl⟩,
have : ∀n, ∃d', x + d' ∈ s ∧ ∥c n • d'∥ ≤ ((1:ℝ)/2)^n,
{ assume n,
have c_pos : 0 < 1 + ∥c n∥ :=
add_pos_of_pos_of_nonneg zero_lt_one (norm_nonneg _),
rcases metric.mem_closure_iff.1 hs ((1 + ∥c n∥)⁻¹ * (1/2)^n) _ with ⟨z, z_pos, hz⟩,
refine ⟨z - x, _, _⟩,
{ convert z_pos, abel },
{ rw [norm_smul, ← dist_eq_norm, dist_comm],
calc ∥c n∥ * dist x z ≤ (1 + ∥c n∥) * ((1 + ∥c n∥)⁻¹ * (1/2)^n) :
begin
apply mul_le_mul _ (le_of_lt hz) dist_nonneg (le_of_lt c_pos),
simp only [zero_le_one, le_add_iff_nonneg_left]
end
... = (1/2)^n :
begin
rw [← mul_assoc, mul_inv_cancel, one_mul],
exact ne_of_gt c_pos
end },
{ apply mul_pos (inv_pos c_pos) (pow_pos _ _),
norm_num } },
choose d' hd' using this,
refine ⟨c, λn, (d' n, d n), _, hc, _⟩,
show ∀ᶠ n in at_top, (x, y) + (d' n, d n) ∈ set.prod s t,
{ apply filter.mem_sets_of_superset hd,
assume n hn,
simp at hn,
simp [hn, (hd' n).1] },
{ apply tendsto.prod_mk_nhds _ hy,
change tendsto (λ (n : ℕ), c n • d' n) at_top (𝓝 0),
rw tendsto_zero_iff_norm_tendsto_zero,
refine squeeze_zero (λn, norm_nonneg _) (λn, (hd' n).2) _,
apply tendsto_pow_at_top_nhds_0_of_lt_1; norm_num }
end
/-- If a subset of a real vector space contains a segment, then the direction of this
segment belongs to the tangent cone at its endpoints. -/
lemma mem_tangent_cone_of_segment_subset {s : set G} {x y : G} (h : segment x y ⊆ s) :
y - x ∈ tangent_cone_at ℝ s x :=
begin
let w : ℝ := 2,
let c := λn:ℕ, (2:ℝ)^n,
let d := λn:ℕ, (c n)⁻¹ • (y-x),
refine ⟨c, d, filter.univ_mem_sets' (λn, h _), _, _⟩,
show x + d n ∈ segment x y,
{ rw segment_eq_image,
refine ⟨(c n)⁻¹, ⟨_, _⟩, _⟩,
{ rw inv_nonneg, apply pow_nonneg, norm_num },
{ apply inv_le_one, apply one_le_pow_of_one_le, norm_num },
{ simp only [d, sub_smul, smul_sub, one_smul], abel } },
show filter.tendsto (λ (n : ℕ), ∥c n∥) filter.at_top filter.at_top,
{ have : (λ (n : ℕ), ∥c n∥) = c,
by { ext n, exact abs_of_nonneg (pow_nonneg (by norm_num) _) },
rw this,
exact tendsto_pow_at_top_at_top_of_gt_1 (by norm_num) },
show filter.tendsto (λ (n : ℕ), c n • d n) filter.at_top (𝓝 (y - x)),
{ have : (λ (n : ℕ), c n • d n) = (λn, y - x),
{ ext n,
simp only [d, smul_smul],
rw [mul_inv_cancel, one_smul],
exact pow_ne_zero _ (by norm_num) },
rw this,
apply tendsto_const_nhds }
end
end tangent_cone
section unique_diff
/- This section is devoted to properties of the predicates `unique_diff_within_at` and
`unique_diff_on`. -/
lemma unique_diff_within_at_univ : unique_diff_within_at 𝕜 univ x :=
by { rw [unique_diff_within_at, tangent_cone_univ], simp }
lemma unique_diff_on_univ : unique_diff_on 𝕜 (univ : set E) :=
λx hx, unique_diff_within_at_univ
lemma unique_diff_on_empty : unique_diff_on 𝕜 (∅ : set E) :=
λ x hx, hx.elim
lemma unique_diff_within_at.mono_nhds (h : unique_diff_within_at 𝕜 s x)
(st : nhds_within x s ≤ nhds_within x t) :
unique_diff_within_at 𝕜 t x :=
begin
unfold unique_diff_within_at at *,
rw [← univ_subset_iff, ← h.1],
rw [mem_closure_iff_nhds_within_ne_bot] at h ⊢,
exact ⟨closure_mono (submodule.span_mono (tangent_cone_mono_nhds st)),
lattice.ne_bot_of_le_ne_bot h.2 st⟩
end
lemma unique_diff_within_at.mono (h : unique_diff_within_at 𝕜 s x) (st : s ⊆ t) :
unique_diff_within_at 𝕜 t x :=
h.mono_nhds $ nhds_within_mono _ st
lemma unique_diff_within_at_congr (st : nhds_within x s = nhds_within x t) :
unique_diff_within_at 𝕜 s x ↔ unique_diff_within_at 𝕜 t x :=
⟨λ h, h.mono_nhds $ le_of_eq st, λ h, h.mono_nhds $ le_of_eq st.symm⟩
lemma unique_diff_within_at_inter (ht : t ∈ 𝓝 x) :
unique_diff_within_at 𝕜 (s ∩ t) x ↔ unique_diff_within_at 𝕜 s x :=
unique_diff_within_at_congr $ (nhds_within_restrict' _ ht).symm
lemma unique_diff_within_at.inter (hs : unique_diff_within_at 𝕜 s x) (ht : t ∈ 𝓝 x) :
unique_diff_within_at 𝕜 (s ∩ t) x :=
(unique_diff_within_at_inter ht).2 hs
lemma unique_diff_within_at_inter' (ht : t ∈ nhds_within x s) :
unique_diff_within_at 𝕜 (s ∩ t) x ↔ unique_diff_within_at 𝕜 s x :=
unique_diff_within_at_congr $ (nhds_within_restrict'' _ ht).symm
lemma unique_diff_within_at.inter' (hs : unique_diff_within_at 𝕜 s x) (ht : t ∈ nhds_within x s) :
unique_diff_within_at 𝕜 (s ∩ t) x :=
(unique_diff_within_at_inter' ht).2 hs
lemma is_open.unique_diff_within_at (hs : is_open s) (xs : x ∈ s) : unique_diff_within_at 𝕜 s x :=
begin
have := unique_diff_within_at_univ.inter (mem_nhds_sets hs xs),
rwa univ_inter at this
end
lemma unique_diff_on.inter (hs : unique_diff_on 𝕜 s) (ht : is_open t) : unique_diff_on 𝕜 (s ∩ t) :=
λx hx, (hs x hx.1).inter (mem_nhds_sets ht hx.2)
lemma is_open.unique_diff_on (hs : is_open s) : unique_diff_on 𝕜 s :=
λx hx, is_open.unique_diff_within_at hs hx
/-- The product of two sets of unique differentiability at points `x` and `y` has unique
differentiability at `(x, y)`. -/
lemma unique_diff_within_at.prod {t : set F} {y : F}
(hs : unique_diff_within_at 𝕜 s x) (ht : unique_diff_within_at 𝕜 t y) :
unique_diff_within_at 𝕜 (set.prod s t) (x, y) :=
begin
rw [unique_diff_within_at] at ⊢ hs ht,
rw [← univ_subset_iff, closure_prod_eq],
refine ⟨_, hs.2, ht.2⟩,
have : _ ⊆ tangent_cone_at 𝕜 (s.prod t) (x, y) :=
union_subset (subset_tangent_cone_prod_left ht.2) (subset_tangent_cone_prod_right hs.2),
refine subset.trans _ (closure_mono $ submodule.span_mono this),
rw [linear_map.span_inl_union_inr, submodule.prod_coe, closure_prod_eq,
hs.1, ht.1, univ_prod_univ]
end
/-- The product of two sets of unique differentiability is a set of unique differentiability. -/
lemma unique_diff_on.prod {t : set F} (hs : unique_diff_on 𝕜 s) (ht : unique_diff_on 𝕜 t) :
unique_diff_on 𝕜 (set.prod s t) :=
λ ⟨x, y⟩ h, unique_diff_within_at.prod (hs x h.1) (ht y h.2)
/-- In a real vector space, a convex set with nonempty interior is a set of unique
differentiability. -/
theorem unique_diff_on_convex {s : set G} (conv : convex s) (hs : (interior s).nonempty) :
unique_diff_on ℝ s :=
begin
assume x xs,
rcases hs with ⟨y, hy⟩,
suffices : y - x ∈ interior (tangent_cone_at ℝ s x),
{ refine ⟨_, subset_closure xs⟩,
rw [submodule.eq_top_of_nonempty_interior _ ⟨y - x, interior_mono submodule.subset_span this⟩,
submodule.top_coe, closure_univ] },
rw [mem_interior_iff_mem_nhds] at hy ⊢,
apply mem_sets_of_superset ((is_open_map_add_right (-x)).image_mem_nhds hy),
rintros _ ⟨z, zs, rfl⟩,
exact mem_tangent_cone_of_segment_subset (conv.segment_subset xs zs)
end
lemma unique_diff_on_Ici (a : ℝ) : unique_diff_on ℝ (Ici a) :=
unique_diff_on_convex (convex_Ici a) $ by simp only [interior_Ici, nonempty_Ioi]
lemma unique_diff_on_Iic (a : ℝ) : unique_diff_on ℝ (Iic a) :=
unique_diff_on_convex (convex_Iic a) $ by simp only [interior_Iic, nonempty_Iio]
lemma unique_diff_on_Ioi (a : ℝ) : unique_diff_on ℝ (Ioi a) :=
is_open_Ioi.unique_diff_on
lemma unique_diff_on_Iio (a : ℝ) : unique_diff_on ℝ (Iio a) :=
is_open_Iio.unique_diff_on
lemma unique_diff_on_Icc {a b : ℝ} (hab : a < b) : unique_diff_on ℝ (Icc a b) :=
unique_diff_on_convex (convex_Icc a b) $ by simp only [interior_Icc, nonempty_Ioo, hab]
lemma unique_diff_on_Ico (a b : ℝ) : unique_diff_on ℝ (Ico a b) :=
if hab : a < b
then unique_diff_on_convex (convex_Ico a b) $ by simp only [interior_Ico, nonempty_Ioo, hab]
else by simp only [Ico_eq_empty (le_of_not_lt hab), unique_diff_on_empty]
lemma unique_diff_on_Ioc (a b : ℝ) : unique_diff_on ℝ (Ioc a b) :=
if hab : a < b
then unique_diff_on_convex (convex_Ioc a b) $ by simp only [interior_Ioc, nonempty_Ioo, hab]
else by simp only [Ioc_eq_empty (le_of_not_lt hab), unique_diff_on_empty]
lemma unique_diff_on_Ioo (a b : ℝ) : unique_diff_on ℝ (Ioo a b) :=
is_open_Ioo.unique_diff_on
/-- The real interval `[0, 1]` is a set of unique differentiability. -/
lemma unique_diff_on_Icc_zero_one : unique_diff_on ℝ (Icc (0:ℝ) 1) :=
unique_diff_on_Icc zero_lt_one
end unique_diff
|
664b2e12ddfc0041d40b4c223d80a9996f2de38f | 37da0369b6c03e380e057bf680d81e6c9fdf9219 | /hott/algebra/homotopy_group.hlean | 6a6844d71ebb82e7b595f70481fc585fdc2fc956 | [
"Apache-2.0"
] | permissive | kodyvajjha/lean2 | 72b120d95c3a1d77f54433fa90c9810e14a931a4 | 227fcad22ab2bc27bb7471be7911075d101ba3f9 | refs/heads/master | 1,627,157,512,295 | 1,501,855,676,000 | 1,504,809,427,000 | 109,317,326 | 0 | 0 | null | 1,509,839,253,000 | 1,509,655,713,000 | C++ | UTF-8 | Lean | false | false | 12,127 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
homotopy groups of a pointed space
-/
import .trunc_group types.trunc .group_theory types.nat.hott
open nat eq pointed trunc is_trunc algebra group function equiv unit is_equiv nat
-- TODO: consistently make n an argument before A
-- TODO: rename cghomotopy_group to aghomotopy_group
-- TODO: rename homotopy_group_functor_compose to homotopy_group_functor_pcompose
namespace eq
definition inf_pgroup_loop [constructor] [instance] (A : Type*) : inf_pgroup (Ω A) :=
inf_pgroup.mk concat con.assoc inverse idp_con con_idp con.left_inv
definition inf_group_loop [constructor] (A : Type*) : inf_group (Ω A) := _
definition ab_inf_group_loop [constructor] [instance] (A : Type*) : ab_inf_group (Ω (Ω A)) :=
⦃ab_inf_group, inf_group_loop _, mul_comm := eckmann_hilton⦄
definition inf_group_loopn (n : ℕ) (A : Type*) [H : is_succ n] : inf_group (Ω[n] A) :=
by induction H; exact _
definition ab_inf_group_loopn (n : ℕ) (A : Type*) [H : is_at_least_two n] : ab_inf_group (Ω[n] A) :=
by induction H; exact _
definition gloop [constructor] (A : Type*) : InfGroup :=
InfGroup.mk (Ω A) (inf_group_loop A)
definition homotopy_group [reducible] [constructor] (n : ℕ) (A : Type*) : Set* :=
ptrunc 0 (Ω[n] A)
notation `π[`:95 n:0 `]`:0 := homotopy_group n
section
local attribute inf_group_loopn [instance]
definition group_homotopy_group [instance] [constructor] [reducible] (n : ℕ) [is_succ n] (A : Type*)
: group (π[n] A) :=
trunc_group (Ω[n] A)
end
definition group_homotopy_group2 [instance] (k : ℕ) (A : Type*) :
group (carrier (ptrunctype.to_pType (π[k + 1] A))) :=
group_homotopy_group (k+1) A
section
local attribute ab_inf_group_loopn [instance]
definition ab_group_homotopy_group [constructor] [reducible] (n : ℕ) [is_at_least_two n] (A : Type*)
: ab_group (π[n] A) :=
trunc_ab_group (Ω[n] A)
end
local attribute ab_group_homotopy_group [instance]
definition ghomotopy_group [constructor] (n : ℕ) [is_succ n] (A : Type*) : Group :=
Group.mk (π[n] A) _
definition cghomotopy_group [constructor] (n : ℕ) [is_at_least_two n] (A : Type*) : AbGroup :=
AbGroup.mk (π[n] A) _
definition fundamental_group [constructor] (A : Type*) : Group :=
ghomotopy_group 1 A
notation `πg[`:95 n:0 `]`:0 := ghomotopy_group n
notation `πag[`:95 n:0 `]`:0 := cghomotopy_group n
notation `π₁` := fundamental_group -- should this be notation for the group or pointed type?
definition tr_mul_tr {n : ℕ} {A : Type*} (p q : Ω[n + 1] A) :
tr p *[πg[n+1] A] tr q = tr (p ⬝ q) :=
by reflexivity
definition tr_mul_tr' {n : ℕ} {A : Type*} (p q : Ω[succ n] A)
: tr p *[π[succ n] A] tr q = tr (p ⬝ q) :=
idp
definition homotopy_group_pequiv [constructor] (n : ℕ) {A B : Type*} (H : A ≃* B)
: π[n] A ≃* π[n] B :=
ptrunc_pequiv_ptrunc 0 (loopn_pequiv_loopn n H)
definition homotopy_group_pequiv_loop_ptrunc [constructor] (k : ℕ) (A : Type*) :
π[k] A ≃* Ω[k] (ptrunc k A) :=
begin
refine !loopn_ptrunc_pequiv⁻¹ᵉ* ⬝e* _,
exact loopn_pequiv_loopn k (pequiv_of_eq begin rewrite [trunc_index.zero_add] end)
end
open trunc_index
definition homotopy_group_ptrunc_of_le [constructor] {k n : ℕ} (H : k ≤ n) (A : Type*) :
π[k] (ptrunc n A) ≃* π[k] A :=
calc
π[k] (ptrunc n A) ≃* Ω[k] (ptrunc k (ptrunc n A))
: homotopy_group_pequiv_loop_ptrunc k (ptrunc n A)
... ≃* Ω[k] (ptrunc k A)
: loopn_pequiv_loopn k (ptrunc_ptrunc_pequiv_left A (of_nat_le_of_nat H))
... ≃* π[k] A : (homotopy_group_pequiv_loop_ptrunc k A)⁻¹ᵉ*
definition homotopy_group_ptrunc [constructor] (k : ℕ) (A : Type*) :
π[k] (ptrunc k A) ≃* π[k] A :=
homotopy_group_ptrunc_of_le (le.refl k) A
theorem trivial_homotopy_of_is_set (A : Type*) [H : is_set A] (n : ℕ) : πg[n+1] A ≃g G0 :=
begin
apply trivial_group_of_is_contr,
apply is_trunc_trunc_of_is_trunc,
apply is_contr_loop_of_is_trunc,
apply is_trunc_succ_succ_of_is_set
end
definition homotopy_group_succ_out (A : Type*) (n : ℕ) : π[n + 1] A = π₁ (Ω[n] A) := idp
definition homotopy_group_succ_in (A : Type*) (n : ℕ) : π[n + 1] A ≃* π[n] (Ω A) :=
ptrunc_pequiv_ptrunc 0 (loopn_succ_in A n)
definition ghomotopy_group_succ_out (A : Type*) (n : ℕ) : πg[n + 1] A = π₁ (Ω[n] A) := idp
definition homotopy_group_succ_in_con {A : Type*} {n : ℕ} (g h : πg[n + 2] A) :
homotopy_group_succ_in A (succ n) (g * h) =
homotopy_group_succ_in A (succ n) g * homotopy_group_succ_in A (succ n) h :=
begin
induction g with p, induction h with q, esimp,
apply ap tr, apply loopn_succ_in_con
end
definition ghomotopy_group_succ_in [constructor] (A : Type*) (n : ℕ) :
πg[n + 2] A ≃g πg[n + 1] (Ω A) :=
begin
fapply isomorphism_of_equiv,
{ exact homotopy_group_succ_in A (succ n)},
{ exact homotopy_group_succ_in_con},
end
definition is_contr_homotopy_group_of_is_contr (A : Type*) (n : ℕ) [is_contr A] : is_contr (π[n] A) :=
begin
apply is_trunc_trunc_of_is_trunc,
apply is_contr_loop_of_is_trunc,
apply is_trunc_of_is_contr
end
definition homotopy_group_functor [constructor] (n : ℕ) {A B : Type*} (f : A →* B)
: π[n] A →* π[n] B :=
ptrunc_functor 0 (apn n f)
notation `π→[`:95 n:0 `]`:0 := homotopy_group_functor n
definition homotopy_group_functor_phomotopy [constructor] (n : ℕ) {A B : Type*} {f g : A →* B}
(p : f ~* g) : π→[n] f ~* π→[n] g :=
ptrunc_functor_phomotopy 0 (apn_phomotopy n p)
definition homotopy_group_functor_pid (n : ℕ) (A : Type*) : π→[n] (pid A) ~* pid (π[n] A) :=
ptrunc_functor_phomotopy 0 !apn_pid ⬝* !ptrunc_functor_pid
definition homotopy_group_functor_compose [constructor] (n : ℕ) {A B C : Type*} (g : B →* C)
(f : A →* B) : π→[n] (g ∘* f) ~* π→[n] g ∘* π→[n] f :=
ptrunc_functor_phomotopy 0 !apn_pcompose ⬝* !ptrunc_functor_pcompose
definition is_equiv_homotopy_group_functor [constructor] (n : ℕ) {A B : Type*} (f : A →* B)
[is_equiv f] : is_equiv (π→[n] f) :=
@(is_equiv_trunc_functor 0 _) !is_equiv_apn
definition homotopy_group_functor_succ_phomotopy_in (n : ℕ) {A B : Type*} (f : A →* B) :
homotopy_group_succ_in B n ∘* π→[n + 1] f ~*
π→[n] (Ω→ f) ∘* homotopy_group_succ_in A n :=
begin
refine !ptrunc_functor_pcompose⁻¹* ⬝* _ ⬝* !ptrunc_functor_pcompose,
exact ptrunc_functor_phomotopy 0 (apn_succ_phomotopy_in n f)
end
definition is_equiv_homotopy_group_functor_ap1 (n : ℕ) {A B : Type*} (f : A →* B)
[is_equiv (π→[n + 1] f)] : is_equiv (π→[n] (Ω→ f)) :=
have is_equiv (π→[n] (Ω→ f) ∘ homotopy_group_succ_in A n),
from is_equiv_of_equiv_of_homotopy (equiv.mk (π→[n+1] f) _ ⬝e homotopy_group_succ_in B n)
(homotopy_group_functor_succ_phomotopy_in n f),
is_equiv.cancel_right (homotopy_group_succ_in A n) _
definition tinverse [constructor] {X : Type*} : π[1] X →* π[1] X :=
ptrunc_functor 0 pinverse
definition is_equiv_tinverse [constructor] (A : Type*) : is_equiv (@tinverse A) :=
by apply @is_equiv_trunc_functor; apply is_equiv_eq_inverse
definition ptrunc_functor_pinverse [constructor] {X : Type*}
: ptrunc_functor 0 (@pinverse X) ~* @tinverse X :=
begin
fapply phomotopy.mk,
{ reflexivity},
{ reflexivity}
end
definition homotopy_group_functor_mul [constructor] (n : ℕ) {A B : Type*} (g : A →* B)
(p q : πg[n+1] A) :
(π→[n + 1] g) (p *[πg[n+1] A] q) = (π→[n+1] g) p *[πg[n+1] B] (π→[n + 1] g) q :=
begin
unfold [ghomotopy_group, homotopy_group] at *,
refine @trunc.rec _ _ _ (λq, !is_trunc_eq) _ p, clear p, intro p,
refine @trunc.rec _ _ _ (λq, !is_trunc_eq) _ q, clear q, intro q,
apply ap tr, apply apn_con
end
definition homotopy_group_homomorphism [constructor] (n : ℕ) [H : is_succ n] {A B : Type*}
(f : A →* B) : πg[n] A →g πg[n] B :=
begin
induction H with n, fconstructor,
{ exact homotopy_group_functor (n+1) f},
{ apply homotopy_group_functor_mul}
end
notation `π→g[`:95 n:0 `]`:0 := homotopy_group_homomorphism n
definition homotopy_group_homomorphism_pcompose (n : ℕ) [H : is_succ n] {A B C : Type*} (g : B →* C)
(f : A →* B) : π→g[n] (g ∘* f) ~ π→g[n] g ∘ π→g[n] f :=
begin
induction H with n, exact to_homotopy (homotopy_group_functor_compose (succ n) g f)
end
definition homotopy_group_isomorphism_of_pequiv [constructor] (n : ℕ) {A B : Type*} (f : A ≃* B)
: πg[n+1] A ≃g πg[n+1] B :=
begin
apply isomorphism.mk (homotopy_group_homomorphism (succ n) f),
esimp, apply is_equiv_trunc_functor, apply is_equiv_apn,
end
definition homotopy_group_add (A : Type*) (n m : ℕ) :
πg[n+m+1] A ≃g πg[n+1] (Ω[m] A) :=
begin
revert A, induction m with m IH: intro A,
{ reflexivity},
{ esimp [loopn, nat.add], refine !ghomotopy_group_succ_in ⬝g _, refine !IH ⬝g _,
apply homotopy_group_isomorphism_of_pequiv,
exact !loopn_succ_in⁻¹ᵉ*}
end
theorem trivial_homotopy_add_of_is_set_loopn {A : Type*} {n : ℕ} (m : ℕ)
(H : is_set (Ω[n] A)) : πg[m+n+1] A ≃g G0 :=
!homotopy_group_add ⬝g !trivial_homotopy_of_is_set
theorem trivial_homotopy_le_of_is_set_loopn {A : Type*} {n : ℕ} (m : ℕ) (H1 : n ≤ m)
(H2 : is_set (Ω[n] A)) : πg[m+1] A ≃g G0 :=
obtain (k : ℕ) (p : n + k = m), from le.elim H1,
isomorphism_of_eq (ap (λx, πg[x+1] A) (p⁻¹ ⬝ add.comm n k)) ⬝g
trivial_homotopy_add_of_is_set_loopn k H2
definition homotopy_group_pequiv_loop_ptrunc_con {k : ℕ} {A : Type*} (p q : πg[k +1] A) :
homotopy_group_pequiv_loop_ptrunc (succ k) A (p * q) =
homotopy_group_pequiv_loop_ptrunc (succ k) A p ⬝
homotopy_group_pequiv_loop_ptrunc (succ k) A q :=
begin
refine _ ⬝ !loopn_pequiv_loopn_con,
exact ap (loopn_pequiv_loopn _ _) !loopn_ptrunc_pequiv_inv_con
end
definition homotopy_group_pequiv_loop_ptrunc_inv_con {k : ℕ} {A : Type*}
(p q : Ω[succ k] (ptrunc (succ k) A)) :
(homotopy_group_pequiv_loop_ptrunc (succ k) A)⁻¹ᵉ* (p ⬝ q) =
(homotopy_group_pequiv_loop_ptrunc (succ k) A)⁻¹ᵉ* p *
(homotopy_group_pequiv_loop_ptrunc (succ k) A)⁻¹ᵉ* q :=
inv_preserve_binary (homotopy_group_pequiv_loop_ptrunc (succ k) A) mul concat
(@homotopy_group_pequiv_loop_ptrunc_con k A) p q
definition ghomotopy_group_ptrunc_of_le [constructor] {k n : ℕ} (H : k ≤ n) [Hk : is_succ k] (A : Type*) :
πg[k] (ptrunc n A) ≃g πg[k] A :=
begin
fapply isomorphism_of_equiv,
{ exact homotopy_group_ptrunc_of_le H A},
{ intro g₁ g₂, induction Hk with k,
refine _ ⬝ !homotopy_group_pequiv_loop_ptrunc_inv_con,
apply ap ((homotopy_group_pequiv_loop_ptrunc (k+1) A)⁻¹ᵉ*),
refine _ ⬝ !loopn_pequiv_loopn_con ,
apply ap (loopn_pequiv_loopn (k+1) _),
apply homotopy_group_pequiv_loop_ptrunc_con}
end
definition ghomotopy_group_ptrunc [constructor] (k : ℕ) [is_succ k] (A : Type*) :
πg[k] (ptrunc k A) ≃g πg[k] A :=
ghomotopy_group_ptrunc_of_le (le.refl k) A
/- some homomorphisms -/
-- definition is_homomorphism_cast_loopn_succ_eq_in {A : Type*} (n : ℕ) :
-- is_homomorphism (loopn_succ_in A (succ n) : πg[n+1+1] A → πg[n+1] (Ω A)) :=
-- begin
-- intro g h, induction g with g, induction h with h,
-- xrewrite [tr_mul_tr, - + fn_cast_eq_cast_fn _ (λn, tr), tr_mul_tr, ↑cast, -tr_compose,
-- loopn_succ_eq_in_concat, - + tr_compose],
-- end
definition is_mul_hom_inverse (A : Type*) (n : ℕ)
: is_mul_hom (λp, p⁻¹ : (πag[n+2] A) → (πag[n+2] A)) :=
begin
intro g h, exact ap inv (mul.comm g h) ⬝ mul_inv h g,
end
end eq
|
bc799fdd75995cdfc9115857843f65c45d1b700e | 737dc4b96c97368cb66b925eeea3ab633ec3d702 | /src/Lean/Meta/Reduce.lean | 52fdd8ac2b1c54f511e04378f8c8cc5ea0334e6c | [
"Apache-2.0"
] | permissive | Bioye97/lean4 | 1ace34638efd9913dc5991443777b01a08983289 | bc3900cbb9adda83eed7e6affeaade7cfd07716d | refs/heads/master | 1,690,589,820,211 | 1,631,051,000,000 | 1,631,067,598,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,490 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Basic
import Lean.Meta.FunInfo
import Lean.Util.MonadCache
namespace Lean.Meta
partial def reduce (e : Expr) (explicitOnly skipTypes skipProofs := true) : MetaM Expr :=
let rec visit (e : Expr) : MonadCacheT Expr Expr MetaM Expr :=
checkCache e fun _ => Core.withIncRecDepth do
if (← (skipTypes <&&> isType e)) then
return e
else if (← (skipProofs <&&> isProof e)) then
return e
else
let e ← whnf e
match e with
| Expr.app .. =>
let f := e.getAppFn
let nargs := e.getAppNumArgs
let finfo ← getFunInfoNArgs f nargs
let mut args := e.getAppArgs
for i in [:args.size] do
if i < finfo.paramInfo.size then
let info := finfo.paramInfo[i]
if !explicitOnly || info.isExplicit then
args ← args.modifyM i visit
else
args ← args.modifyM i visit
pure (mkAppN f args)
| Expr.lam .. => lambdaTelescope e fun xs b => do mkLambdaFVars xs (← visit b)
| Expr.forallE .. => forallTelescope e fun xs b => do mkForallFVars xs (← visit b)
| Expr.proj n i s .. => return mkProj n i (← visit s)
| _ => return e
visit e |>.run
end Lean.Meta
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.