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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
d88352e608b0644e410f808b1f68050f68e0abf6 | df561f413cfe0a88b1056655515399c546ff32a5 | /8-inequality-world/l15.lean | 180d34aa360d62478b70b02b23d18fa48483f2a7 | [] | no_license | nicholaspun/natural-number-game-solutions | 31d5158415c6f582694680044c5c6469032c2a06 | 1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0 | refs/heads/main | 1,675,123,625,012 | 1,607,633,548,000 | 1,607,633,548,000 | 318,933,860 | 3 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 293 | lean | lemma lt_aux_one (a b : mynat) : a ≤ b ∧ ¬ (b ≤ a) → succ a ≤ b :=
begin
intro h,
cases h,
cases h_left,
cases h_left_w,
rw add_zero at h_left_h,
rw h_left_h at h_right,
exfalso,
exact h_right (le_refl a),
rw add_succ at h_left_h,
rw h_left_h,
use h_left_w,
rw succ_add,
refl,
end |
63996ac703af1af19726e7332055dd3ddfa2a4db | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/tactic/ring.lean | 26d99fb1854f16121dbad5cf10a4cb872736ce69 | [
"Apache-2.0"
] | permissive | roro47/mathlib | 761fdc002aef92f77818f3fef06bf6ec6fc1a28e | 80aa7d52537571a2ca62a3fdf71c9533a09422cf | refs/heads/master | 1,599,656,410,625 | 1,573,649,488,000 | 1,573,649,488,000 | 221,452,951 | 0 | 0 | Apache-2.0 | 1,573,647,693,000 | 1,573,647,692,000 | null | UTF-8 | Lean | false | false | 20,904 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Evaluate expressions in the language of commutative (semi)rings.
Based on http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf .
-/
import algebra.group_power tactic.norm_num
import tactic.converter.interactive
namespace tactic
namespace ring
def horner {α} [comm_semiring α] (a x : α) (n : ℕ) (b : α) := a * x ^ n + b
meta structure cache :=
(α : expr)
(univ : level)
(comm_semiring_inst : expr)
(red : transparency)
meta def ring_m (α : Type) : Type :=
reader_t cache (state_t (buffer expr) tactic) α
meta instance : monad ring_m := by dunfold ring_m; apply_instance
meta instance : alternative ring_m := by dunfold ring_m; apply_instance
meta def get_cache : ring_m cache := reader_t.read
meta def get_atom (n : ℕ) : ring_m expr :=
reader_t.lift $ (λ es : buffer expr, es.read' n) <$> state_t.get
meta def get_transparency : ring_m transparency :=
cache.red <$> get_cache
meta def add_atom (e : expr) : ring_m ℕ :=
do red ← get_transparency,
reader_t.lift ⟨λ es, (do
n ← es.iterate failed (λ n e' t, t <|> (is_def_eq e e' red $> n)),
return (n, es)) <|> return (es.size, es.push_back e)⟩
meta def lift {α} (m : tactic α) : ring_m α :=
reader_t.lift (state_t.lift m)
meta def ring_m.run (red : transparency) (e : expr) {α} (m : ring_m α) : tactic α :=
do α ← infer_type e,
c ← mk_app ``comm_semiring [α] >>= mk_instance,
u ← mk_meta_univ,
infer_type α >>= unify (expr.sort (level.succ u)),
u ← get_univ_assignment u,
prod.fst <$> state_t.run (reader_t.run m ⟨α, u, c, red⟩) mk_buffer
meta def cache.cs_app (c : cache) (n : name) : list expr → expr :=
(@expr.const tt n [c.univ] c.α c.comm_semiring_inst).mk_app
meta def ring_m.mk_app (n inst : name) (l : list expr) : ring_m expr :=
do c ← get_cache,
m ← lift $ mk_instance ((expr.const inst [c.univ] : expr) c.α),
return $ (@expr.const tt n [c.univ] c.α m).mk_app l
meta inductive horner_expr : Type
| const (e : expr) : horner_expr
| xadd (e : expr) (a : horner_expr) (x : expr × ℕ) (n : expr × ℕ) (b : horner_expr) : horner_expr
meta def horner_expr.e : horner_expr → expr
| (horner_expr.const e) := e
| (horner_expr.xadd e _ _ _ _) := e
meta instance : has_coe horner_expr expr := ⟨horner_expr.e⟩
meta def horner_expr.xadd' (c : cache) (a : horner_expr)
(x : expr × ℕ) (n : expr × ℕ) (b : horner_expr) : horner_expr :=
horner_expr.xadd (c.cs_app ``horner [a, x.1, n.1, b]) a x n b
open horner_expr
meta def horner_expr.to_string : horner_expr → string
| (const e) := to_string e
| (xadd e a x (_, n) b) :=
"(" ++ a.to_string ++ ") * (" ++ to_string x ++ ")^"
++ to_string n ++ " + " ++ b.to_string
meta def horner_expr.pp : horner_expr → tactic format
| (const e) := pp e
| (xadd e a x (_, n) b) := do
pa ← a.pp, pb ← b.pp, px ← pp x,
return $ "(" ++ pa ++ ") * (" ++ px ++ ")^" ++ to_string n ++ " + " ++ pb
meta instance : has_to_tactic_format horner_expr := ⟨horner_expr.pp⟩
meta def horner_expr.refl_conv (e : horner_expr) : ring_m (horner_expr × expr) :=
do p ← lift $ mk_eq_refl e, return (e, p)
theorem zero_horner {α} [comm_semiring α] (x n b) :
@horner α _ 0 x n b = b :=
by simp [horner]
theorem horner_horner {α} [comm_semiring α] (a₁ x n₁ n₂ b n')
(h : n₁ + n₂ = n') :
@horner α _ (horner a₁ x n₁ 0) x n₂ b = horner a₁ x n' b :=
by simp [h.symm, horner, pow_add, mul_assoc]
meta def eval_horner : horner_expr → expr × ℕ → expr × ℕ → horner_expr → ring_m (horner_expr × expr)
| ha@(const a) x n b := do
c ← get_cache,
if a.to_nat = some 0 then
return (b, c.cs_app ``zero_horner [x.1, n.1, b])
else (xadd' c ha x n b).refl_conv
| ha@(xadd a a₁ x₁ n₁ b₁) x n b := do
c ← get_cache,
if x₁.2 = x.2 ∧ b₁.e.to_nat = some 0 then do
(n', h) ← lift $ mk_app ``has_add.add [n₁.1, n.1] >>= norm_num,
return (xadd' c a₁ x (n', n₁.2 + n.2) b,
c.cs_app ``horner_horner [a₁, x.1, n₁.1, n.1, b, n', h])
else (xadd' c ha x n b).refl_conv
theorem const_add_horner {α} [comm_semiring α] (k a x n b b') (h : k + b = b') :
k + @horner α _ a x n b = horner a x n b' :=
by simp [h.symm, horner]
theorem horner_add_const {α} [comm_semiring α] (a x n b k b') (h : b + k = b') :
@horner α _ a x n b + k = horner a x n b' :=
by simp [h.symm, horner]
theorem horner_add_horner_lt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₁ + k = n₂) (h₂ : (a₁ + horner a₂ x k 0 : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₁ b' :=
by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]
theorem horner_add_horner_gt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₂ + k = n₁) (h₂ : (horner a₁ x k 0 + a₂ : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₂ b' :=
by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]
theorem horner_add_horner_eq {α} [comm_semiring α] (a₁ x n b₁ a₂ b₂ a' b' t)
(h₁ : a₁ + a₂ = a') (h₂ : b₁ + b₂ = b') (h₃ : horner a' x n b' = t) :
@horner α _ a₁ x n b₁ + horner a₂ x n b₂ = t :=
by simp [h₃.symm, h₂.symm, h₁.symm, horner, add_mul, mul_comm]
meta def eval_add : horner_expr → horner_expr → ring_m (horner_expr × expr)
| (const e₁) (const e₂) := do
(e, p) ← lift $ mk_app ``has_add.add [e₁, e₂] >>= norm_num,
return (const e, p)
| he₁@(const e₁) he₂@(xadd e₂ a x n b) := do
c ← get_cache,
if e₁.to_nat = some 0 then do
p ← lift $ mk_app ``zero_add [e₂],
return (he₂, p)
else do
(b', h) ← eval_add he₁ b,
return (xadd' c a x n b',
c.cs_app ``const_add_horner [e₁, a, x.1, n.1, b, b', h])
| he₁@(xadd e₁ a x n b) he₂@(const e₂) := do
c ← get_cache,
if e₂.to_nat = some 0 then do
p ← lift $ mk_app ``add_zero [e₁],
return (he₁, p)
else do
(b', h) ← eval_add b he₂,
return (xadd' c a x n b',
c.cs_app ``horner_add_const [a, x.1, n.1, b, e₂, b', h])
| he₁@(xadd e₁ a₁ x₁ n₁ b₁) he₂@(xadd e₂ a₂ x₂ n₂ b₂) := do
c ← get_cache,
if x₁.2 < x₂.2 then do
(b', h) ← eval_add b₁ he₂,
return (xadd' c a₁ x₁ n₁ b',
c.cs_app ``horner_add_const [a₁, x₁.1, n₁.1, b₁, e₂, b', h])
else if x₁.2 ≠ x₂.2 then do
(b', h) ← eval_add he₁ b₂,
return (xadd' c a₂ x₂ n₂ b',
c.cs_app ``const_add_horner [e₁, a₂, x₂.1, n₂.1, b₂, b', h])
else if n₁.2 < n₂.2 then do
let k := n₂.2 - n₁.2,
ek ← lift $ expr.of_nat (expr.const `nat []) k,
(_, h₁) ← lift $ mk_app ``has_add.add [n₁.1, ek] >>= norm_num,
α0 ← lift $ expr.of_nat c.α 0,
(a', h₂) ← eval_add a₁ (xadd' c a₂ x₁ (ek, k) (const α0)),
(b', h₃) ← eval_add b₁ b₂,
return (xadd' c a' x₁ n₁ b',
c.cs_app ``horner_add_horner_lt [a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, ek, a', b', h₁, h₂, h₃])
else if n₁.2 ≠ n₂.2 then do
let k := n₁.2 - n₂.2,
ek ← lift $ expr.of_nat (expr.const `nat []) k,
(_, h₁) ← lift $ mk_app ``has_add.add [n₂.1, ek] >>= norm_num,
α0 ← lift $ expr.of_nat c.α 0,
(a', h₂) ← eval_add (xadd' c a₁ x₁ (ek, k) (const α0)) a₂,
(b', h₃) ← eval_add b₁ b₂,
return (xadd' c a' x₁ n₂ b',
c.cs_app ``horner_add_horner_gt [a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, ek, a', b', h₁, h₂, h₃])
else do
(a', h₁) ← eval_add a₁ a₂,
(b', h₂) ← eval_add b₁ b₂,
(t, h₃) ← eval_horner a' x₁ n₁ b',
return (t, c.cs_app ``horner_add_horner_eq
[a₁, x₁.1, n₁.1, b₁, a₂, b₂, a', b', t, h₁, h₂, h₃])
theorem horner_neg {α} [comm_ring α] (a x n b a' b')
(h₁ : -a = a') (h₂ : -b = b') :
-@horner α _ a x n b = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner]
meta def eval_neg : horner_expr → ring_m (horner_expr × expr)
| (const e) := do
(e', p) ← lift $ mk_app ``has_neg.neg [e] >>= norm_num,
return (const e', p)
| (xadd e a x n b) := do
c ← get_cache,
(a', h₁) ← eval_neg a,
(b', h₂) ← eval_neg b,
p ← ring_m.mk_app ``horner_neg ``comm_ring [a, x.1, n.1, b, a', b', h₁, h₂],
return (xadd' c a' x n b', p)
theorem horner_const_mul {α} [comm_semiring α] (c a x n b a' b')
(h₁ : c * a = a') (h₂ : c * b = b') :
c * @horner α _ a x n b = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner, mul_add, mul_assoc]
theorem horner_mul_const {α} [comm_semiring α] (a x n b c a' b')
(h₁ : a * c = a') (h₂ : b * c = b') :
@horner α _ a x n b * c = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner, add_mul, mul_right_comm]
meta def eval_const_mul (k : expr) :
horner_expr → ring_m (horner_expr × expr)
| (const e) := do
(e', p) ← lift $ mk_app ``has_mul.mul [k, e] >>= norm_num,
return (const e', p)
| (xadd e a x n b) := do
c ← get_cache,
(a', h₁) ← eval_const_mul a,
(b', h₂) ← eval_const_mul b,
return (xadd' c a' x n b',
c.cs_app ``horner_const_mul [k, a, x.1, n.1, b, a', b', h₁, h₂])
theorem horner_mul_horner_zero {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ aa t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ 0 = t :=
by rw [← h₂, ← h₁];
simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc]
theorem horner_mul_horner {α} [comm_semiring α]
(a₁ x n₁ b₁ a₂ n₂ b₂ aa haa ab bb t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = haa)
(h₃ : a₁ * b₂ = ab) (h₄ : b₁ * b₂ = bb)
(H : haa + horner ab x n₁ bb = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ b₂ = t :=
by rw [← H, ← h₂, ← h₁, ← h₃, ← h₄];
simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc]
meta def eval_mul : horner_expr → horner_expr → ring_m (horner_expr × expr)
| (const e₁) (const e₂) := do
(e', p) ← lift $ mk_app ``has_mul.mul [e₁, e₂] >>= norm_num,
return (const e', p)
| (const e₁) e₂ :=
match e₁.to_nat with
| (some 0) := do
c ← get_cache,
α0 ← lift $ expr.of_nat c.α 0,
p ← lift $ mk_app ``zero_mul [e₂],
return (const α0, p)
| (some 1) := do
p ← lift $ mk_app ``one_mul [e₂],
return (e₂, p)
| _ := eval_const_mul e₁ e₂
end
| e₁ he₂@(const e₂) := do
p₁ ← lift $ mk_app ``mul_comm [e₁, e₂],
(e', p₂) ← eval_mul he₂ e₁,
p ← lift $ mk_eq_trans p₁ p₂, return (e', p)
| he₁@(xadd e₁ a₁ x₁ n₁ b₁) he₂@(xadd e₂ a₂ x₂ n₂ b₂) := do
c ← get_cache,
if x₁.2 < x₂.2 then do
(a', h₁) ← eval_mul a₁ he₂,
(b', h₂) ← eval_mul b₁ he₂,
return (xadd' c a' x₁ n₁ b',
c.cs_app ``horner_mul_const [a₁, x₁.1, n₁.1, b₁, e₂, a', b', h₁, h₂])
else if x₁.2 ≠ x₂.2 then do
(a', h₁) ← eval_mul he₁ a₂,
(b', h₂) ← eval_mul he₁ b₂,
return (xadd' c a' x₂ n₂ b',
c.cs_app ``horner_const_mul [e₁, a₂, x₂.1, n₂.1, b₂, a', b', h₁, h₂])
else do
(aa, h₁) ← eval_mul he₁ a₂,
α0 ← lift $ expr.of_nat c.α 0,
(haa, h₂) ← eval_horner aa x₁ n₂ (const α0),
if b₂.e.to_nat = some 0 then
return (haa, c.cs_app ``horner_mul_horner_zero
[a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, aa, haa, h₁, h₂])
else do
(ab, h₃) ← eval_mul a₁ b₂,
(bb, h₄) ← eval_mul b₁ b₂,
(t, H) ← eval_add haa (xadd' c ab x₁ n₁ bb),
return (t, c.cs_app ``horner_mul_horner
[a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, aa, haa, ab, bb, t, h₁, h₂, h₃, h₄, H])
theorem horner_pow {α} [comm_semiring α] (a x n m n' a')
(h₁ : n * m = n') (h₂ : a ^ m = a') :
@horner α _ a x n 0 ^ m = horner a' x n' 0 :=
by simp [h₁.symm, h₂.symm, horner, mul_pow, pow_mul]
meta def eval_pow : horner_expr → expr × ℕ → ring_m (horner_expr × expr)
| e (_, 0) := do
c ← get_cache,
α1 ← lift $ expr.of_nat c.α 1,
p ← lift $ mk_app ``pow_zero [e],
return (const α1, p)
| e (_, 1) := do
p ← lift $ mk_app ``pow_one [e],
return (e, p)
| (const e) (e₂, m) := do
(e', p) ← lift $ mk_app ``monoid.pow [e, e₂] >>= norm_num.derive,
return (const e', p)
| he@(xadd e a x n b) m := do
c ← get_cache,
let N : expr := expr.const `nat [],
match b.e.to_nat with
| some 0 := do
(n', h₁) ← lift $ mk_app ``has_mul.mul [n.1, m.1] >>= norm_num,
(a', h₂) ← eval_pow a m,
α0 ← lift $ expr.of_nat c.α 0,
return (xadd' c a' x (n', n.2 * m.2) (const α0),
c.cs_app ``horner_pow [a, x.1, n.1, m.1, n', a', h₁, h₂])
| _ := do
e₂ ← lift $ expr.of_nat N (m.2-1),
l ← lift $ mk_app ``monoid.pow [e, e₂],
(tl, hl) ← eval_pow he (e₂, m.2-1),
(t, p₂) ← eval_mul tl he,
hr ← lift $ mk_eq_refl e,
p₂ ← ring_m.mk_app ``norm_num.subst_into_prod ``has_mul [l, e, tl, e, t, hl, hr, p₂],
p₁ ← lift $ mk_app ``pow_succ' [e, e₂],
p ← lift $ mk_eq_trans p₁ p₂,
return (t, p)
end
theorem horner_atom {α} [comm_semiring α] (x : α) : x = horner 1 x 1 0 :=
by simp [horner]
meta def eval_atom (e : expr) : ring_m (horner_expr × expr) :=
do c ← get_cache,
i ← add_atom e,
α0 ← lift $ expr.of_nat c.α 0,
α1 ← lift $ expr.of_nat c.α 1,
n1 ← lift $ expr.of_nat (expr.const `nat []) 1,
return (xadd' c (const α1) (e, i) (n1, 1) (const α0),
c.cs_app ``horner_atom [e])
lemma subst_into_pow {α} [monoid α] (l r tl tr t)
(prl : (l : α) = tl) (prr : (r : ℕ) = tr) (prt : tl ^ tr = t) : l ^ r = t :=
by simp [prl, prr, prt]
lemma unfold_sub {α} [add_group α] (a b c : α)
(h : a + -b = c) : a - b = c := h
lemma unfold_div {α} [division_ring α] (a b c : α)
(h : a * b⁻¹ = c) : a / b = c := h
meta def eval : expr → ring_m (horner_expr × expr)
| `(%%e₁ + %%e₂) := do
(e₁', p₁) ← eval e₁,
(e₂', p₂) ← eval e₂,
(e', p') ← eval_add e₁' e₂',
p ← ring_m.mk_app ``norm_num.subst_into_sum ``has_add [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
return (e', p)
| `(%%e₁ - %%e₂) := do
c ← get_cache,
e₂' ← lift $ mk_app ``has_neg.neg [e₂],
e ← lift $ mk_app ``has_add.add [e₁, e₂'],
(e', p) ← eval e,
p' ← ring_m.mk_app ``unfold_sub ``add_group [e₁, e₂, e', p],
return (e', p')
| `(- %%e) := do
(e₁, p₁) ← eval e,
(e₂, p₂) ← eval_neg e₁,
p ← ring_m.mk_app ``norm_num.subst_into_neg ``has_neg [e, e₁, e₂, p₁, p₂],
return (e₂, p)
| `(%%e₁ * %%e₂) := do
(e₁', p₁) ← eval e₁,
(e₂', p₂) ← eval e₂,
(e', p') ← eval_mul e₁' e₂',
p ← ring_m.mk_app ``norm_num.subst_into_prod ``has_mul [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
return (e', p)
| e@`(has_inv.inv %%_) := (do
(e', p) ← lift $ norm_num.derive e,
lift $ e'.to_rat,
return (const e', p)) <|> eval_atom e
| `(%%e₁ / %%e₂) := do
e₂' ← lift $ mk_app ``has_inv.inv [e₂],
e ← lift $ mk_app ``has_mul.mul [e₁, e₂'],
(e', p) ← eval e,
p' ← ring_m.mk_app ``unfold_div ``division_ring [e₁, e₂, e', p],
return (e', p')
| e@`(@has_pow.pow _ _ %%P %%e₁ %%e₂) := do
(e₂', p₂) ← eval e₂,
match e₂'.e.to_nat, P with
| some k, `(monoid.has_pow) := do
(e₁', p₁) ← eval e₁,
(e', p') ← eval_pow e₁' (e₂, k),
p ← ring_m.mk_app ``subst_into_pow ``monoid [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
return (e', p)
| some k, `(nat.has_pow) := do
(e₁', p₁) ← eval e₁,
(e', p') ← eval_pow e₁' (e₂, k),
p₃ ← ring_m.mk_app ``subst_into_pow ``monoid [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
p₄ ← lift $ mk_app ``nat.pow_eq_pow [e₁, e₂] >>= mk_eq_symm,
p ← lift $ mk_eq_trans p₄ p₃,
return (e', p)
| _, _ := eval_atom e
end
| e := match e.to_nat with
| some n := (const e).refl_conv
| none := eval_atom e
end
meta def eval' (red : transparency) (e : expr) : tactic (expr × expr) :=
ring_m.run red e $ do (e', p) ← eval e, return (e', p)
theorem horner_def' {α} [comm_semiring α] (a x n b) : @horner α _ a x n b = x ^ n * a + b :=
by simp [horner, mul_comm]
theorem mul_assoc_rev {α} [semigroup α] (a b c : α) : a * (b * c) = a * b * c :=
by simp [mul_assoc]
theorem pow_add_rev {α} [monoid α] (a : α) (m n : ℕ) : a ^ m * a ^ n = a ^ (m + n) :=
by simp [pow_add]
theorem pow_add_rev_right {α} [monoid α] (a b : α) (m n : ℕ) : b * a ^ m * a ^ n = b * a ^ (m + n) :=
by simp [pow_add, mul_assoc]
theorem add_neg_eq_sub {α} [add_group α] (a b : α) : a + -b = a - b := rfl
@[derive has_reflect]
inductive normalize_mode | raw | SOP | horner
meta def normalize (red : transparency) (mode := normalize_mode.horner) (e : expr) : tactic (expr × expr) := do
pow_lemma ← simp_lemmas.mk.add_simp ``pow_one,
let lemmas := match mode with
| normalize_mode.SOP :=
[``horner_def', ``add_zero, ``mul_one, ``mul_add, ``mul_sub,
``mul_assoc_rev, ``pow_add_rev, ``pow_add_rev_right,
``mul_neg_eq_neg_mul_symm, ``add_neg_eq_sub]
| normalize_mode.horner :=
[``horner.equations._eqn_1, ``add_zero, ``one_mul, ``pow_one,
``neg_mul_eq_neg_mul_symm, ``add_neg_eq_sub]
| _ := []
end,
lemmas ← lemmas.mfoldl simp_lemmas.add_simp simp_lemmas.mk,
(_, e', pr) ← ext_simplify_core () {}
simp_lemmas.mk (λ _, failed) (λ _ _ _ _ e, do
(new_e, pr) ← match mode with
| normalize_mode.raw := eval' red
| normalize_mode.horner := trans_conv (eval' red) (simplify lemmas [])
| normalize_mode.SOP :=
trans_conv (eval' red) $
trans_conv (simplify lemmas []) $
simp_bottom_up' (λ e, norm_num e <|> pow_lemma.rewrite e)
end e,
guard (¬ new_e =ₐ e),
return ((), new_e, some pr, ff))
(λ _ _ _ _ _, failed) `eq e,
return (e', pr)
end ring
namespace interactive
open interactive interactive.types lean.parser
open tactic.ring
local postfix `?`:9001 := optional
/-- Tactic for solving equations in the language of *commutative* (semi)rings.
This version of `ring` fails if the target is not an equality
that is provable by the axioms of commutative (semi)rings. -/
meta def ring1 (red : parse (tk "!")?) : tactic unit :=
let transp := if red.is_some then semireducible else reducible in
do `(%%e₁ = %%e₂) ← target,
((e₁', p₁), (e₂', p₂)) ← ring_m.run transp e₁ $
prod.mk <$> eval e₁ <*> eval e₂,
is_def_eq e₁' e₂',
p ← mk_eq_symm p₂ >>= mk_eq_trans p₁,
tactic.exact p
meta def ring.mode : lean.parser ring.normalize_mode :=
with_desc "(SOP|raw|horner)?" $
do mode ← ident?, match mode with
| none := return ring.normalize_mode.horner
| some `horner := return ring.normalize_mode.horner
| some `SOP := return ring.normalize_mode.SOP
| some `raw := return ring.normalize_mode.raw
| _ := failed
end
/-- Tactic for solving equations in the language of *commutative* (semi)rings.
Attempts to prove the goal outright if there is no `at`
specifier and the target is an equality, but if this
fails it falls back to rewriting all ring expressions
into a normal form. When writing a normal form,
`ring SOP` will use sum-of-products form instead of horner form.
`ring!` will use a more aggressive reducibility setting to identify atoms. -/
meta def ring (red : parse (tk "!")?) (SOP : parse ring.mode) (loc : parse location) : tactic unit :=
match loc with
| interactive.loc.ns [none] := instantiate_mvars_in_target >> ring1 red
| _ := failed
end <|>
do ns ← loc.get_locals,
let transp := if red.is_some then semireducible else reducible,
tt ← tactic.replace_at (normalize transp SOP) ns loc.include_goal
| fail "ring failed to simplify",
when loc.include_goal $ try tactic.reflexivity
end interactive
end tactic
namespace conv.interactive
open conv interactive
open tactic tactic.interactive (ring.mode ring1)
open tactic.ring (normalize)
local postfix `?`:9001 := optional
meta def ring (red : parse (lean.parser.tk "!")?) (SOP : parse ring.mode) : conv unit :=
let transp := if red.is_some then semireducible else reducible in
discharge_eq_lhs (ring1 red)
<|> replace_lhs (normalize transp SOP)
<|> fail "ring failed to simplify"
end conv.interactive
|
a7102be93da62a5c5a00744d1b808ce34240e2ed | 367134ba5a65885e863bdc4507601606690974c1 | /src/analysis/analytic/composition.lean | 40b121cb999cf630a627a2a9d287f160c44ffbac | [
"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 | 58,723 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johan Commelin
-/
import analysis.analytic.basic
import combinatorics.composition
/-!
# Composition of analytic functions
in this file we prove that the composition of analytic functions is analytic.
The argument is the following. Assume `g z = ∑' qₙ (z, ..., z)` and `f y = ∑' pₖ (y, ..., y)`. Then
`g (f y) = ∑' qₙ (∑' pₖ (y, ..., y), ..., ∑' pₖ (y, ..., y))
= ∑' qₙ (p_{i₁} (y, ..., y), ..., p_{iₙ} (y, ..., y))`.
For each `n` and `i₁, ..., iₙ`, define a `i₁ + ... + iₙ` multilinear function mapping
`(y₀, ..., y_{i₁ + ... + iₙ - 1})` to
`qₙ (p_{i₁} (y₀, ..., y_{i₁-1}), p_{i₂} (y_{i₁}, ..., y_{i₁ + i₂ - 1}), ..., p_{iₙ} (....)))`.
Then `g ∘ f` is obtained by summing all these multilinear functions.
To formalize this, we use compositions of an integer `N`, i.e., its decompositions into
a sum `i₁ + ... + iₙ` of positive integers. Given such a composition `c` and two formal
multilinear series `q` and `p`, let `q.comp_along_composition p c` be the above multilinear
function. Then the `N`-th coefficient in the power series expansion of `g ∘ f` is the sum of these
terms over all `c : composition N`.
To complete the proof, we need to show that this power series has a positive radius of convergence.
This follows from the fact that `composition N` has cardinality `2^(N-1)` and estimates on
the norm of `qₙ` and `pₖ`, which give summability. We also need to show that it indeed converges to
`g ∘ f`. For this, we note that the composition of partial sums converges to `g ∘ f`, and that it
corresponds to a part of the whole sum, on a subset that increases to the whole space. By
summability of the norms, this implies the overall convergence.
## Main results
* `q.comp p` is the formal composition of the formal multilinear series `q` and `p`.
* `has_fpower_series_at.comp` states that if two functions `g` and `f` admit power series expansions
`q` and `p`, then `g ∘ f` admits a power series expansion given by `q.comp p`.
* `analytic_at.comp` states that the composition of analytic functions is analytic.
* `formal_multilinear_series.comp_assoc` states that composition is associative on formal
multilinear series.
## Implementation details
The main technical difficulty is to write down things. In particular, we need to define precisely
`q.comp_along_composition p c` and to show that it is indeed a continuous multilinear
function. This requires a whole interface built on the class `composition`. Once this is set,
the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum
over some subset of `Σ n, composition n`. We need to check that the reordering is a bijection,
running over difficulties due to the dependent nature of the types under consideration, that are
controlled thanks to the interface for `composition`.
The associativity of composition on formal multilinear series is a nontrivial result: it does not
follow from the associativity of composition of analytic functions, as there is no uniqueness for
the formal multilinear series representing a function (and also, it holds even when the radius of
convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering
double sums in a careful way. The change of variables is a canonical (combinatorial) bijection
`composition.sigma_equiv_sigma_pi` between `(Σ (a : composition n), composition a.length)` and
`(Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i))`, and is described
in more details below in the paragraph on associativity.
-/
noncomputable theory
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]
{H : Type*} [normed_group H] [normed_space 𝕜 H]
open filter list
open_locale topological_space big_operators classical nnreal ennreal
/-! ### Composing formal multilinear series -/
namespace formal_multilinear_series
/-!
In this paragraph, we define the composition of formal multilinear series, by summing over all
possible compositions of `n`.
-/
/-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a
block of `c`, we may define a function on `fin n → E` by picking the variables in the `i`-th block
of `n`, and applying the corresponding coefficient of `p` to these variables. This function is
called `p.apply_composition c v i` for `v : fin n → E` and `i : fin c.length`. -/
def apply_composition
(p : formal_multilinear_series 𝕜 E F) {n : ℕ} (c : composition n) :
(fin n → E) → (fin (c.length) → F) :=
λ v i, p (c.blocks_fun i) (v ∘ (c.embedding i))
lemma apply_composition_ones (p : formal_multilinear_series 𝕜 E F) (n : ℕ) :
p.apply_composition (composition.ones n) =
λ v i, p 1 (λ _, v (fin.cast_le (composition.length_le _) i)) :=
begin
funext v i,
apply p.congr (composition.ones_blocks_fun _ _),
intros j hjn hj1,
obtain rfl : j = 0, { linarith },
refine congr_arg v _,
rw [fin.ext_iff, fin.coe_cast_le, composition.ones_embedding, fin.coe_mk],
end
lemma apply_composition_single (p : formal_multilinear_series 𝕜 E F) {n : ℕ} (hn : 0 < n)
(v : fin n → E) : p.apply_composition (composition.single n hn) v = λ j, p n v :=
begin
ext j,
refine p.congr (by simp) (λ i hi1 hi2, _),
dsimp,
congr' 1,
convert composition.single_embedding hn ⟨i, hi2⟩,
cases j,
have : j_val = 0 := le_bot_iff.1 (nat.lt_succ_iff.1 j_property),
unfold_coes,
congr; try { assumption <|> simp },
end
@[simp] lemma remove_zero_apply_composition
(p : formal_multilinear_series 𝕜 E F) {n : ℕ} (c : composition n) :
p.remove_zero.apply_composition c = p.apply_composition c :=
begin
ext v i,
simp [apply_composition, zero_lt_one.trans_le (c.one_le_blocks_fun i), remove_zero_of_pos],
end
/-- Technical lemma stating how `p.apply_composition` commutes with updating variables. This
will be the key point to show that functions constructed from `apply_composition` retain
multilinearity. -/
lemma apply_composition_update
(p : formal_multilinear_series 𝕜 E F) {n : ℕ} (c : composition n)
(j : fin n) (v : fin n → E) (z : E) :
p.apply_composition c (function.update v j z) =
function.update (p.apply_composition c v) (c.index j)
(p (c.blocks_fun (c.index j))
(function.update (v ∘ (c.embedding (c.index j))) (c.inv_embedding j) z)) :=
begin
ext k,
by_cases h : k = c.index j,
{ rw h,
let r : fin (c.blocks_fun (c.index j)) → fin n := c.embedding (c.index j),
simp only [function.update_same],
change p (c.blocks_fun (c.index j)) ((function.update v j z) ∘ r) = _,
let j' := c.inv_embedding j,
suffices B : (function.update v j z) ∘ r = function.update (v ∘ r) j' z,
by rw B,
suffices C : (function.update v (r j') z) ∘ r = function.update (v ∘ r) j' z,
by { convert C, exact (c.embedding_comp_inv j).symm },
exact function.update_comp_eq_of_injective _ (c.embedding _).injective _ _ },
{ simp only [h, function.update_eq_self, function.update_noteq, ne.def, not_false_iff],
let r : fin (c.blocks_fun k) → fin n := c.embedding k,
change p (c.blocks_fun k) ((function.update v j z) ∘ r) = p (c.blocks_fun k) (v ∘ r),
suffices B : (function.update v j z) ∘ r = v ∘ r, by rw B,
apply function.update_comp_eq_of_not_mem_range,
rwa c.mem_range_embedding_iff' }
end
@[simp] lemma comp_continuous_linear_map_apply_composition {n : ℕ}
(p : formal_multilinear_series 𝕜 F G) (f : E →L[𝕜] F) (c : composition n) (v : fin n → E) :
(p.comp_continuous_linear_map f).apply_composition c v = p.apply_composition c (f ∘ v) :=
by simp [apply_composition]
end formal_multilinear_series
namespace continuous_multilinear_map
open formal_multilinear_series
/-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear
map `f` in `c.length` variables, one may form a multilinear map in `n` variables by applying
the right coefficient of `p` to each block of the composition, and then applying `f` to the
resulting vector. It is called `f.comp_along_composition_aux p c`.
This function admits a version as a continuous multilinear map, called
`f.comp_along_composition p c` below. -/
def comp_along_composition_aux {n : ℕ}
(p : formal_multilinear_series 𝕜 E F) (c : composition n)
(f : continuous_multilinear_map 𝕜 (λ (i : fin c.length), F) G) :
multilinear_map 𝕜 (λ i : fin n, E) G :=
{ to_fun := λ v, f (p.apply_composition c v),
map_add' := λ v i x y, by simp only [apply_composition_update,
continuous_multilinear_map.map_add],
map_smul' := λ v i c x, by simp only [apply_composition_update,
continuous_multilinear_map.map_smul] }
/-- The norm of `f.comp_along_composition_aux p c` is controlled by the product of
the norms of the relevant bits of `f` and `p`. -/
lemma comp_along_composition_aux_bound {n : ℕ}
(p : formal_multilinear_series 𝕜 E F) (c : composition n)
(f : continuous_multilinear_map 𝕜 (λ (i : fin c.length), F) G) (v : fin n → E) :
∥f.comp_along_composition_aux p c v∥ ≤
∥f∥ * (∏ i, ∥p (c.blocks_fun i)∥) * (∏ i : fin n, ∥v i∥) :=
calc ∥f.comp_along_composition_aux p c v∥ = ∥f (p.apply_composition c v)∥ : rfl
... ≤ ∥f∥ * ∏ i, ∥p.apply_composition c v i∥ : continuous_multilinear_map.le_op_norm _ _
... ≤ ∥f∥ * ∏ i, ∥p (c.blocks_fun i)∥ *
∏ j : fin (c.blocks_fun i), ∥(v ∘ (c.embedding i)) j∥ :
begin
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _),
refine finset.prod_le_prod (λ i hi, norm_nonneg _) (λ i hi, _),
apply continuous_multilinear_map.le_op_norm,
end
... = ∥f∥ * (∏ i, ∥p (c.blocks_fun i)∥) *
∏ i (j : fin (c.blocks_fun i)), ∥(v ∘ (c.embedding i)) j∥ :
by rw [finset.prod_mul_distrib, mul_assoc]
... = ∥f∥ * (∏ i, ∥p (c.blocks_fun i)∥) * (∏ i : fin n, ∥v i∥) :
by { rw [← c.blocks_fin_equiv.prod_comp, ← finset.univ_sigma_univ, finset.prod_sigma],
congr }
/-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear
map `f` in `c.length` variables, one may form a continuous multilinear map in `n` variables by
applying the right coefficient of `p` to each block of the composition, and then applying `f` to
the resulting vector. It is called `f.comp_along_composition p c`. It is constructed from the
analogous multilinear function `f.comp_along_composition_aux p c`, together with a norm
control to get the continuity. -/
def comp_along_composition {n : ℕ}
(p : formal_multilinear_series 𝕜 E F) (c : composition n)
(f : continuous_multilinear_map 𝕜 (λ (i : fin c.length), F) G) :
continuous_multilinear_map 𝕜 (λ i : fin n, E) G :=
(f.comp_along_composition_aux p c).mk_continuous _
(f.comp_along_composition_aux_bound p c)
@[simp] lemma comp_along_composition_apply {n : ℕ}
(p : formal_multilinear_series 𝕜 E F) (c : composition n)
(f : continuous_multilinear_map 𝕜 (λ (i : fin c.length), F) G) (v : fin n → E) :
(f.comp_along_composition p c) v = f (p.apply_composition c v) := rfl
end continuous_multilinear_map
namespace formal_multilinear_series
/-- Given two formal multilinear series `q` and `p` and a composition `c` of `n`, one may
form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each
block of the composition, and then applying `q c.length` to the resulting vector. It is
called `q.comp_along_composition p c`. It is constructed from the analogous multilinear
function `q.comp_along_composition_aux p c`, together with a norm control to get
the continuity. -/
def comp_along_composition {n : ℕ}
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F)
(c : composition n) : continuous_multilinear_map 𝕜 (λ i : fin n, E) G :=
(q c.length).comp_along_composition p c
@[simp] lemma comp_along_composition_apply {n : ℕ}
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F)
(c : composition n) (v : fin n → E) :
(q.comp_along_composition p c) v = q c.length (p.apply_composition c v) := rfl
/-- The norm of `q.comp_along_composition p c` is controlled by the product of
the norms of the relevant bits of `q` and `p`. -/
lemma comp_along_composition_norm {n : ℕ}
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F)
(c : composition n) :
∥q.comp_along_composition p c∥ ≤ ∥q c.length∥ * ∏ i, ∥p (c.blocks_fun i)∥ :=
multilinear_map.mk_continuous_norm_le _
(mul_nonneg (norm_nonneg _) (finset.prod_nonneg (λ i hi, norm_nonneg _))) _
lemma comp_along_composition_nnnorm {n : ℕ}
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F)
(c : composition n) :
nnnorm (q.comp_along_composition p c) ≤ nnnorm (q c.length) * ∏ i, nnnorm (p (c.blocks_fun i)) :=
by { rw ← nnreal.coe_le_coe, push_cast, exact q.comp_along_composition_norm p c }
/-- Formal composition of two formal multilinear series. The `n`-th coefficient in the composition
is defined to be the sum of `q.comp_along_composition p c` over all compositions of
`n`. In other words, this term (as a multilinear function applied to `v_0, ..., v_{n-1}`) is
`∑'_{k} ∑'_{i₁ + ... + iₖ = n} pₖ (q_{i_1} (...), ..., q_{i_k} (...))`, where one puts all variables
`v_0, ..., v_{n-1}` in increasing order in the dots.
In general, the composition `q ∘ p` only makes sense when the constant coefficient of `p` vanishes.
We give a general formula but which ignores the value of `p 0` instead.
-/
protected def comp (q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F) :
formal_multilinear_series 𝕜 E G :=
λ n, ∑ c : composition n, q.comp_along_composition p c
/-- The `0`-th coefficient of `q.comp p` is `q 0`. Since these maps are multilinear maps in zero
variables, but on different spaces, we can not state this directly, so we state it when applied to
arbitrary vectors (which have to be the zero vector). -/
lemma comp_coeff_zero (q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F)
(v : fin 0 → E) (v' : fin 0 → F) :
(q.comp p) 0 v = q 0 v' :=
begin
let c : composition 0 := composition.ones 0,
dsimp [formal_multilinear_series.comp],
have : {c} = (finset.univ : finset (composition 0)),
{ apply finset.eq_of_subset_of_card_le; simp [finset.card_univ, composition_card 0] },
rw [← this, finset.sum_singleton, comp_along_composition_apply],
symmetry, congr'
end
@[simp] lemma comp_coeff_zero'
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F) (v : fin 0 → E) :
(q.comp p) 0 v = q 0 (λ i, 0) :=
q.comp_coeff_zero p v _
/-- The `0`-th coefficient of `q.comp p` is `q 0`. When `p` goes from `E` to `E`, this can be
expressed as a direct equality -/
lemma comp_coeff_zero'' (q : formal_multilinear_series 𝕜 E F)
(p : formal_multilinear_series 𝕜 E E) :
(q.comp p) 0 = q 0 :=
by { ext v, exact q.comp_coeff_zero p _ _ }
/-- The first coefficient of a composition of formal multilinear series is the composition of the
first coefficients seen as continuous linear maps. -/
lemma comp_coeff_one (q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F)
(v : fin 1 → E) : (q.comp p) 1 v = q 1 (λ i, p 1 v) :=
begin
have : {composition.ones 1} = (finset.univ : finset (composition 1)) :=
finset.eq_univ_of_card _ (by simp [composition_card]),
simp only [formal_multilinear_series.comp, comp_along_composition_apply, ← this,
finset.sum_singleton],
refine q.congr (by simp) (λ i hi1 hi2, _),
simp only [apply_composition_ones],
exact p.congr rfl (λ j hj1 hj2, by congr)
end
lemma remove_zero_comp_of_pos (q : formal_multilinear_series 𝕜 F G)
(p : formal_multilinear_series 𝕜 E F) {n : ℕ} (hn : 0 < n) :
q.remove_zero.comp p n = q.comp p n :=
begin
ext v,
simp only [formal_multilinear_series.comp, comp_along_composition,
continuous_multilinear_map.comp_along_composition_apply, continuous_multilinear_map.sum_apply],
apply finset.sum_congr rfl (λ c hc, _),
rw remove_zero_of_pos _ (c.length_pos_of_pos hn)
end
@[simp] lemma comp_remove_zero (q : formal_multilinear_series 𝕜 F G)
(p : formal_multilinear_series 𝕜 E F) :
q.comp p.remove_zero = q.comp p :=
by { ext n, simp [formal_multilinear_series.comp] }
/-!
### The identity formal power series
We will now define the identity power series, and show that it is a neutral element for left and
right composition.
-/
section
variables (𝕜 E)
/-- The identity formal multilinear series, with all coefficients equal to `0` except for `n = 1`
where it is (the continuous multilinear version of) the identity. -/
def id : formal_multilinear_series 𝕜 E E
| 0 := 0
| 1 := (continuous_multilinear_curry_fin1 𝕜 E E).symm (continuous_linear_map.id 𝕜 E)
| _ := 0
/-- The first coefficient of `id 𝕜 E` is the identity. -/
@[simp] lemma id_apply_one (v : fin 1 → E) : (formal_multilinear_series.id 𝕜 E) 1 v = v 0 := rfl
/-- The `n`th coefficient of `id 𝕜 E` is the identity when `n = 1`. We state this in a dependent
way, as it will often appear in this form. -/
lemma id_apply_one' {n : ℕ} (h : n = 1) (v : fin n → E) :
(id 𝕜 E) n v = v ⟨0, h.symm ▸ zero_lt_one⟩ :=
begin
subst n,
apply id_apply_one
end
/-- For `n ≠ 1`, the `n`-th coefficient of `id 𝕜 E` is zero, by definition. -/
@[simp] lemma id_apply_ne_one {n : ℕ} (h : n ≠ 1) : (formal_multilinear_series.id 𝕜 E) n = 0 :=
by { cases n, { refl }, cases n, { contradiction }, refl }
end
@[simp] theorem comp_id (p : formal_multilinear_series 𝕜 E F) : p.comp (id 𝕜 E) = p :=
begin
ext1 n,
dsimp [formal_multilinear_series.comp],
rw finset.sum_eq_single (composition.ones n),
show comp_along_composition p (id 𝕜 E) (composition.ones n) = p n,
{ ext v,
rw comp_along_composition_apply,
apply p.congr (composition.ones_length n),
intros,
rw apply_composition_ones,
refine congr_arg v _,
rw [fin.ext_iff, fin.coe_cast_le, fin.coe_mk, fin.coe_mk], },
show ∀ (b : composition n),
b ∈ finset.univ → b ≠ composition.ones n → comp_along_composition p (id 𝕜 E) b = 0,
{ assume b _ hb,
obtain ⟨k, hk, lt_k⟩ : ∃ (k : ℕ) (H : k ∈ composition.blocks b), 1 < k :=
composition.ne_ones_iff.1 hb,
obtain ⟨i, i_lt, hi⟩ : ∃ (i : ℕ) (h : i < b.blocks.length), b.blocks.nth_le i h = k :=
nth_le_of_mem hk,
let j : fin b.length := ⟨i, b.blocks_length ▸ i_lt⟩,
have A : 1 < b.blocks_fun j := by convert lt_k,
ext v,
rw [comp_along_composition_apply, continuous_multilinear_map.zero_apply],
apply continuous_multilinear_map.map_coord_zero _ j,
dsimp [apply_composition],
rw id_apply_ne_one _ _ (ne_of_gt A),
refl },
{ simp }
end
@[simp] theorem id_comp (p : formal_multilinear_series 𝕜 E F) (h : p 0 = 0) : (id 𝕜 F).comp p = p :=
begin
ext1 n,
by_cases hn : n = 0,
{ rw [hn, h],
ext v,
rw [comp_coeff_zero', id_apply_ne_one _ _ zero_ne_one],
refl },
{ dsimp [formal_multilinear_series.comp],
have n_pos : 0 < n := bot_lt_iff_ne_bot.mpr hn,
rw finset.sum_eq_single (composition.single n n_pos),
show comp_along_composition (id 𝕜 F) p (composition.single n n_pos) = p n,
{ ext v,
rw [comp_along_composition_apply, id_apply_one' _ _ (composition.single_length n_pos)],
dsimp [apply_composition],
refine p.congr rfl (λ i him hin, congr_arg v $ _),
ext, simp },
show ∀ (b : composition n),
b ∈ finset.univ → b ≠ composition.single n n_pos → comp_along_composition (id 𝕜 F) p b = 0,
{ assume b _ hb,
have A : b.length ≠ 1, by simpa [composition.eq_single_iff_length] using hb,
ext v,
rw [comp_along_composition_apply, id_apply_ne_one _ _ A],
refl },
{ simp } }
end
/-! ### Summability properties of the composition of formal power series-/
/-- If two formal multilinear series have positive radius of convergence, then the terms appearing
in the definition of their composition are also summable (when multiplied by a suitable positive
geometric term). -/
theorem comp_summable_nnreal
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F)
(hq : 0 < q.radius) (hp : 0 < p.radius) :
∃ r > (0 : ℝ≥0),
summable (λ i : Σ n, composition n, nnnorm (q.comp_along_composition p i.2) * r ^ i.1) :=
begin
/- This follows from the fact that the growth rate of `∥qₙ∥` and `∥pₙ∥` is at most geometric,
giving a geometric bound on each `∥q.comp_along_composition p op∥`, together with the
fact that there are `2^(n-1)` compositions of `n`, giving at most a geometric loss. -/
rcases ennreal.lt_iff_exists_nnreal_btwn.1 (lt_min ennreal.zero_lt_one hq) with ⟨rq, rq_pos, hrq⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 (lt_min ennreal.zero_lt_one hp) with ⟨rp, rp_pos, hrp⟩,
simp only [lt_min_iff, ennreal.coe_lt_one_iff, ennreal.coe_pos] at hrp hrq rp_pos rq_pos,
obtain ⟨Cq, hCq0, hCq⟩ : ∃ Cq > 0, ∀ n, nnnorm (q n) * rq^n ≤ Cq :=
q.nnnorm_mul_pow_le_of_lt_radius hrq.2,
obtain ⟨Cp, hCp1, hCp⟩ : ∃ Cp ≥ 1, ∀ n, nnnorm (p n) * rp^n ≤ Cp,
{ rcases p.nnnorm_mul_pow_le_of_lt_radius hrp.2 with ⟨Cp, -, hCp⟩,
exact ⟨max Cp 1, le_max_right _ _, λ n, (hCp n).trans (le_max_left _ _)⟩ },
let r0 : ℝ≥0 := (4 * Cp)⁻¹,
have r0_pos : 0 < r0 := nnreal.inv_pos.2 (mul_pos zero_lt_four (zero_lt_one.trans_le hCp1)),
set r : ℝ≥0 := rp * rq * r0,
have r_pos : 0 < r := mul_pos (mul_pos rp_pos rq_pos) r0_pos,
have I : ∀ (i : Σ (n : ℕ), composition n),
nnnorm (q.comp_along_composition p i.2) * r ^ i.1 ≤ Cq / 4 ^ i.1,
{ rintros ⟨n, c⟩,
have A,
calc nnnorm (q c.length) * rq ^ n ≤ nnnorm (q c.length)* rq ^ c.length :
mul_le_mul' le_rfl (pow_le_pow_of_le_one rq.2 hrq.1.le c.length_le)
... ≤ Cq : hCq _,
have B,
calc ((∏ i, nnnorm (p (c.blocks_fun i))) * rp ^ n)
= ∏ i, nnnorm (p (c.blocks_fun i)) * rp ^ c.blocks_fun i :
by simp only [finset.prod_mul_distrib, finset.prod_pow_eq_pow_sum, c.sum_blocks_fun]
... ≤ ∏ i : fin c.length, Cp : finset.prod_le_prod' (λ i _, hCp _)
... = Cp ^ c.length : by simp
... ≤ Cp ^ n : pow_le_pow hCp1 c.length_le,
calc nnnorm (q.comp_along_composition p c) * r ^ n
≤ (nnnorm (q c.length) * ∏ i, nnnorm (p (c.blocks_fun i))) * r ^ n :
mul_le_mul' (q.comp_along_composition_nnnorm p c) le_rfl
... = (nnnorm (q c.length) * rq ^ n) * ((∏ i, nnnorm (p (c.blocks_fun i))) * rp ^ n) * r0 ^ n :
by { simp only [r, mul_pow], ac_refl }
... ≤ Cq * Cp ^ n * r0 ^ n : mul_le_mul' (mul_le_mul' A B) le_rfl
... = Cq / 4 ^ n :
begin
simp only [r0],
field_simp [mul_pow, (zero_lt_one.trans_le hCp1).ne'],
ac_refl
end },
refine ⟨r, r_pos, nnreal.summable_of_le I (summable.mul_left _ _)⟩,
have h4 : ∀ n : ℕ, 0 < (4 ^ n : ℝ≥0)⁻¹ := λ n, nnreal.inv_pos.2 (pow_pos zero_lt_four _),
have : ∀ n : ℕ, has_sum (λ c : composition n, (4 ^ n : ℝ≥0)⁻¹) (2 ^ (n - 1) / 4 ^ n),
{ intro n,
convert has_sum_fintype (λ c : composition n, (4 ^ n : ℝ≥0)⁻¹),
simp [finset.card_univ, composition_card, div_eq_mul_inv] },
refine nnreal.summable_sigma.2 ⟨λ n, (this n).summable, (nnreal.summable_nat_add_iff 1).1 _⟩,
convert (nnreal.summable_geometric (nnreal.div_lt_one_of_lt one_lt_two)).mul_left (1 / 4),
ext1 n,
rw [(this _).tsum_eq, nat.add_sub_cancel],
field_simp [← mul_assoc, pow_succ', mul_pow, show (4 : ℝ≥0) = 2 * 2, from (two_mul 2).symm,
mul_right_comm]
end
/-- Bounding below the radius of the composition of two formal multilinear series assuming
summability over all compositions. -/
theorem le_comp_radius_of_summable
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F) (r : ℝ≥0)
(hr : summable (λ i : (Σ n, composition n), nnnorm (q.comp_along_composition p i.2) * r ^ i.1)) :
(r : ℝ≥0∞) ≤ (q.comp p).radius :=
begin
refine le_radius_of_bound_nnreal _
(∑' i : (Σ n, composition n), nnnorm (comp_along_composition q p i.snd) * r ^ i.fst) (λ n, _),
calc nnnorm (formal_multilinear_series.comp q p n) * r ^ n ≤
∑' (c : composition n), nnnorm (comp_along_composition q p c) * r ^ n :
begin
rw [tsum_fintype, ← finset.sum_mul],
exact mul_le_mul' (nnnorm_sum_le _ _) le_rfl
end
... ≤ ∑' (i : Σ (n : ℕ), composition n), nnnorm (comp_along_composition q p i.snd) * r ^ i.fst :
nnreal.tsum_comp_le_tsum_of_inj hr sigma_mk_injective
end
/-!
### Composing analytic functions
Now, we will prove that the composition of the partial sums of `q` and `p` up to order `N` is
given by a sum over some large subset of `Σ n, composition n` of `q.comp_along_composition p`, to
deduce that the series for `q.comp p` indeed converges to `g ∘ f` when `q` is a power series for
`g` and `p` is a power series for `f`.
This proof is a big reindexing argument of a sum. Since it is a bit involved, we define first
the source of the change of variables (`comp_partial_source`), its target
(`comp_partial_target`) and the change of variables itself (`comp_change_of_variables`) before
giving the main statement in `comp_partial_sum`. -/
/-- Source set in the change of variables to compute the composition of partial sums of formal
power series.
See also `comp_partial_sum`. -/
def comp_partial_sum_source (m M N : ℕ) : finset (Σ n, (fin n) → ℕ) :=
finset.sigma (finset.Ico m M) (λ (n : ℕ), fintype.pi_finset (λ (i : fin n), finset.Ico 1 N) : _)
@[simp] lemma mem_comp_partial_sum_source_iff (m M N : ℕ) (i : Σ n, (fin n) → ℕ) :
i ∈ comp_partial_sum_source m M N ↔
(m ≤ i.1 ∧ i.1 < M) ∧ ∀ (a : fin i.1), 1 ≤ i.2 a ∧ i.2 a < N :=
by simp only [comp_partial_sum_source, finset.Ico.mem, fintype.mem_pi_finset, finset.mem_sigma,
iff_self]
/-- Change of variables appearing to compute the composition of partial sums of formal
power series -/
def comp_change_of_variables (m M N : ℕ) (i : Σ n, (fin n) → ℕ)
(hi : i ∈ comp_partial_sum_source m M N) : (Σ n, composition n) :=
begin
rcases i with ⟨n, f⟩,
rw mem_comp_partial_sum_source_iff at hi,
refine ⟨∑ j, f j, of_fn (λ a, f a), λ i hi', _, by simp [sum_of_fn]⟩,
obtain ⟨j, rfl⟩ : ∃ (j : fin n), f j = i, by rwa [mem_of_fn, set.mem_range] at hi',
exact (hi.2 j).1
end
@[simp] lemma comp_change_of_variables_length
(m M N : ℕ) {i : Σ n, (fin n) → ℕ} (hi : i ∈ comp_partial_sum_source m M N) :
composition.length (comp_change_of_variables m M N i hi).2 = i.1 :=
begin
rcases i with ⟨k, blocks_fun⟩,
dsimp [comp_change_of_variables],
simp only [composition.length, map_of_fn, length_of_fn]
end
lemma comp_change_of_variables_blocks_fun
(m M N : ℕ) {i : Σ n, (fin n) → ℕ} (hi : i ∈ comp_partial_sum_source m M N) (j : fin i.1) :
(comp_change_of_variables m M N i hi).2.blocks_fun
⟨j, (comp_change_of_variables_length m M N hi).symm ▸ j.2⟩ = i.2 j :=
begin
rcases i with ⟨n, f⟩,
dsimp [composition.blocks_fun, composition.blocks, comp_change_of_variables],
simp only [map_of_fn, nth_le_of_fn', function.comp_app],
apply congr_arg,
exact fin.eta _ _
end
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a set. -/
def comp_partial_sum_target_set (m M N : ℕ) : set (Σ n, composition n) :=
{i | (m ≤ i.2.length) ∧ (i.2.length < M) ∧ (∀ (j : fin i.2.length), i.2.blocks_fun j < N)}
lemma comp_partial_sum_target_subset_image_comp_partial_sum_source
(m M N : ℕ) (i : Σ n, composition n) (hi : i ∈ comp_partial_sum_target_set m M N) :
∃ j (hj : j ∈ comp_partial_sum_source m M N), i = comp_change_of_variables m M N j hj :=
begin
rcases i with ⟨n, c⟩,
refine ⟨⟨c.length, c.blocks_fun⟩, _, _⟩,
{ simp only [comp_partial_sum_target_set, set.mem_set_of_eq] at hi,
simp only [mem_comp_partial_sum_source_iff, hi.left, hi.right, true_and, and_true],
exact λ a, c.one_le_blocks' _ },
{ dsimp [comp_change_of_variables],
rw composition.sigma_eq_iff_blocks_eq,
simp only [composition.blocks_fun, composition.blocks, subtype.coe_eta, nth_le_map'],
conv_lhs { rw ← of_fn_nth_le c.blocks } }
end
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a finset.
See also `comp_partial_sum`. -/
def comp_partial_sum_target (m M N : ℕ) : finset (Σ n, composition n) :=
set.finite.to_finset $ ((finset.finite_to_set _).dependent_image _).subset $
comp_partial_sum_target_subset_image_comp_partial_sum_source m M N
@[simp] lemma mem_comp_partial_sum_target_iff {m M N : ℕ} {a : Σ n, composition n} :
a ∈ comp_partial_sum_target m M N ↔
m ≤ a.2.length ∧ a.2.length < M ∧ (∀ (j : fin a.2.length), a.2.blocks_fun j < N) :=
by simp [comp_partial_sum_target, comp_partial_sum_target_set]
/-- `comp_change_of_variables m M N` is a bijection between `comp_partial_sum_source m M N`
and `comp_partial_sum_target m M N`, yielding equal sums for functions that correspond to each
other under the bijection. As `comp_change_of_variables m M N` is a dependent function, stating
that it is a bijection is not directly possible, but the consequence on sums can be stated
more easily. -/
lemma comp_change_of_variables_sum {α : Type*} [add_comm_monoid α] (m M N : ℕ)
(f : (Σ (n : ℕ), fin n → ℕ) → α) (g : (Σ n, composition n) → α)
(h : ∀ e (he : e ∈ comp_partial_sum_source m M N),
f e = g (comp_change_of_variables m M N e he)) :
∑ e in comp_partial_sum_source m M N, f e = ∑ e in comp_partial_sum_target m M N, g e :=
begin
apply finset.sum_bij (comp_change_of_variables m M N),
-- We should show that the correspondance we have set up is indeed a bijection
-- between the index sets of the two sums.
-- 1 - show that the image belongs to `comp_partial_sum_target m N N`
{ rintros ⟨k, blocks_fun⟩ H,
rw mem_comp_partial_sum_source_iff at H,
simp only [mem_comp_partial_sum_target_iff, composition.length, composition.blocks, H.left,
map_of_fn, length_of_fn, true_and, comp_change_of_variables],
assume j,
simp only [composition.blocks_fun, (H.right _).right, nth_le_of_fn'] },
-- 2 - show that the composition gives the `comp_along_composition` application
{ rintros ⟨k, blocks_fun⟩ H,
rw h },
-- 3 - show that the map is injective
{ rintros ⟨k, blocks_fun⟩ ⟨k', blocks_fun'⟩ H H' heq,
obtain rfl : k = k',
{ have := (comp_change_of_variables_length m M N H).symm,
rwa [heq, comp_change_of_variables_length] at this, },
congr,
funext i,
calc blocks_fun i = (comp_change_of_variables m M N _ H).2.blocks_fun _ :
(comp_change_of_variables_blocks_fun m M N H i).symm
... = (comp_change_of_variables m M N _ H').2.blocks_fun _ :
begin
apply composition.blocks_fun_congr; try { rw heq },
refl
end
... = blocks_fun' i : comp_change_of_variables_blocks_fun m M N H' i },
-- 4 - show that the map is surjective
{ assume i hi,
apply comp_partial_sum_target_subset_image_comp_partial_sum_source m M N i,
simpa [comp_partial_sum_target] using hi }
end
/-- The auxiliary set corresponding to the composition of partial sums asymptotically contains
all possible compositions. -/
lemma comp_partial_sum_target_tendsto_at_top :
tendsto (λ N, comp_partial_sum_target 0 N N) at_top at_top :=
begin
apply monotone.tendsto_at_top_finset,
{ assume m n hmn a ha,
have : ∀ i, i < m → i < n := λ i hi, lt_of_lt_of_le hi hmn,
tidy },
{ rintros ⟨n, c⟩,
simp only [mem_comp_partial_sum_target_iff],
obtain ⟨n, hn⟩ : bdd_above ↑(finset.univ.image (λ (i : fin c.length), c.blocks_fun i)) :=
finset.bdd_above _,
refine ⟨max n c.length + 1, bot_le, lt_of_le_of_lt (le_max_right n c.length) (lt_add_one _),
λ j, lt_of_le_of_lt (le_trans _ (le_max_left _ _)) (lt_add_one _)⟩,
apply hn,
simp only [finset.mem_image_of_mem, finset.mem_coe, finset.mem_univ] }
end
/-- Composing the partial sums of two multilinear series coincides with the sum over all
compositions in `comp_partial_sum_target 0 N N`. This is precisely the motivation for the
definition of `comp_partial_sum_target`. -/
lemma comp_partial_sum
(q : formal_multilinear_series 𝕜 F G) (p : formal_multilinear_series 𝕜 E F) (N : ℕ) (z : E) :
q.partial_sum N (∑ i in finset.Ico 1 N, p i (λ j, z)) =
∑ i in comp_partial_sum_target 0 N N, q.comp_along_composition p i.2 (λ j, z) :=
begin
-- we expand the composition, using the multilinearity of `q` to expand along each coordinate.
suffices H : ∑ n in finset.range N, ∑ r in fintype.pi_finset (λ (i : fin n), finset.Ico 1 N),
q n (λ (i : fin n), p (r i) (λ j, z)) =
∑ i in comp_partial_sum_target 0 N N, q.comp_along_composition p i.2 (λ j, z),
by simpa only [formal_multilinear_series.partial_sum,
continuous_multilinear_map.map_sum_finset] using H,
-- rewrite the first sum as a big sum over a sigma type, in the finset
-- `comp_partial_sum_target 0 N N`
rw [finset.range_eq_Ico, finset.sum_sigma'],
-- use `comp_change_of_variables_sum`, saying that this change of variables respects sums
apply comp_change_of_variables_sum 0 N N,
rintros ⟨k, blocks_fun⟩ H,
apply congr _ (comp_change_of_variables_length 0 N N H).symm,
intros,
rw ← comp_change_of_variables_blocks_fun 0 N N H,
refl
end
end formal_multilinear_series
open formal_multilinear_series
/-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, then
`g ∘ f` admits the power series `q.comp p` at `x`. -/
theorem has_fpower_series_at.comp {g : F → G} {f : E → F}
{q : formal_multilinear_series 𝕜 F G} {p : formal_multilinear_series 𝕜 E F} {x : E}
(hg : has_fpower_series_at g q (f x)) (hf : has_fpower_series_at f p x) :
has_fpower_series_at (g ∘ f) (q.comp p) x :=
begin
/- Consider `rf` and `rg` such that `f` and `g` have power series expansion on the disks
of radius `rf` and `rg`. -/
rcases hg with ⟨rg, Hg⟩,
rcases hf with ⟨rf, Hf⟩,
/- The terms defining `q.comp p` are geometrically summable in a disk of some radius `r`. -/
rcases q.comp_summable_nnreal p Hg.radius_pos Hf.radius_pos with ⟨r, r_pos : 0 < r, hr⟩,
/- We will consider `y` which is smaller than `r` and `rf`, and also small enough that
`f (x + y)` is close enough to `f x` to be in the disk where `g` is well behaved. Let
`min (r, rf, δ)` be this new radius.-/
have : continuous_at f x := Hf.analytic_at.continuous_at,
obtain ⟨δ, δpos, hδ⟩ : ∃ (δ : ℝ≥0∞) (H : 0 < δ),
∀ {z : E}, z ∈ emetric.ball x δ → f z ∈ emetric.ball (f x) rg,
{ have : emetric.ball (f x) rg ∈ 𝓝 (f x) := emetric.ball_mem_nhds _ Hg.r_pos,
rcases emetric.mem_nhds_iff.1 (Hf.analytic_at.continuous_at this) with ⟨δ, δpos, Hδ⟩,
exact ⟨δ, δpos, λ z hz, Hδ hz⟩ },
let rf' := min rf δ,
have min_pos : 0 < min rf' r,
by simp only [r_pos, Hf.r_pos, δpos, lt_min_iff, ennreal.coe_pos, and_self],
/- We will show that `g ∘ f` admits the power series `q.comp p` in the disk of
radius `min (r, rf', δ)`. -/
refine ⟨min rf' r, _⟩,
refine ⟨le_trans (min_le_right rf' r)
(formal_multilinear_series.le_comp_radius_of_summable q p r hr), min_pos, λ y hy, _⟩,
/- Let `y` satisfy `∥y∥ < min (r, rf', δ)`. We want to show that `g (f (x + y))` is the sum of
`q.comp p` applied to `y`. -/
-- First, check that `y` is small enough so that estimates for `f` and `g` apply.
have y_mem : y ∈ emetric.ball (0 : E) rf :=
(emetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_left _ _))) hy,
have fy_mem : f (x + y) ∈ emetric.ball (f x) rg,
{ apply hδ,
have : y ∈ emetric.ball (0 : E) δ :=
(emetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_right _ _))) hy,
simpa [edist_eq_coe_nnnorm_sub, edist_eq_coe_nnnorm] },
/- Now the proof starts. To show that the sum of `q.comp p` at `y` is `g (f (x + y))`, we will
write `q.comp p` applied to `y` as a big sum over all compositions. Since the sum is
summable, to get its convergence it suffices to get the convergence along some increasing sequence
of sets. We will use the sequence of sets `comp_partial_sum_target 0 n n`, along which the sum is
exactly the composition of the partial sums of `q` and `p`, by design. To show that it converges
to `g (f (x + y))`, pointwise convergence would not be enough, but we have uniform convergence
to save the day. -/
-- First step: the partial sum of `p` converges to `f (x + y)`.
have A : tendsto (λ n, ∑ a in finset.Ico 1 n, p a (λ b, y)) at_top (𝓝 (f (x + y) - f x)),
{ have L : ∀ᶠ n in at_top, ∑ a in finset.range n, p a (λ b, y) - f x =
∑ a in finset.Ico 1 n, p a (λ b, y),
{ rw eventually_at_top,
refine ⟨1, λ n hn, _⟩,
symmetry,
rw [eq_sub_iff_add_eq', finset.range_eq_Ico, ← Hf.coeff_zero (λi, y),
finset.sum_eq_sum_Ico_succ_bot hn] },
have : tendsto (λ n, ∑ a in finset.range n, p a (λ b, y) - f x) at_top (𝓝 (f (x + y) - f x)) :=
(Hf.has_sum y_mem).tendsto_sum_nat.sub tendsto_const_nhds,
exact tendsto.congr' L this },
-- Second step: the composition of the partial sums of `q` and `p` converges to `g (f (x + y))`.
have B : tendsto (λ n, q.partial_sum n (∑ a in finset.Ico 1 n, p a (λ b, y)))
at_top (𝓝 (g (f (x + y)))),
{ -- we use the fact that the partial sums of `q` converge locally uniformly to `g`, and that
-- composition passes to the limit under locally uniform convergence.
have B₁ : continuous_at (λ (z : F), g (f x + z)) (f (x + y) - f x),
{ refine continuous_at.comp _ (continuous_const.add continuous_id).continuous_at,
simp only [add_sub_cancel'_right, id.def],
exact Hg.continuous_on.continuous_at (mem_nhds_sets (emetric.is_open_ball) fy_mem) },
have B₂ : f (x + y) - f x ∈ emetric.ball (0 : F) rg,
by simpa [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] using fy_mem,
rw [← nhds_within_eq_of_open B₂ emetric.is_open_ball] at A,
convert Hg.tendsto_locally_uniformly_on.tendsto_comp B₁.continuous_within_at B₂ A,
simp only [add_sub_cancel'_right] },
-- Third step: the sum over all compositions in `comp_partial_sum_target 0 n n` converges to
-- `g (f (x + y))`. As this sum is exactly the composition of the partial sum, this is a direct
-- consequence of the second step
have C : tendsto (λ n,
∑ i in comp_partial_sum_target 0 n n, q.comp_along_composition p i.2 (λ j, y))
at_top (𝓝 (g (f (x + y)))),
by simpa [comp_partial_sum] using B,
-- Fourth step: the sum over all compositions is `g (f (x + y))`. This follows from the
-- convergence along a subsequence proved in the third step, and the fact that the sum is Cauchy
-- thanks to the summability properties.
have D : has_sum (λ i : (Σ n, composition n),
q.comp_along_composition p i.2 (λ j, y)) (g (f (x + y))),
{ have cau : cauchy_seq (λ (s : finset (Σ n, composition n)),
∑ i in s, q.comp_along_composition p i.2 (λ j, y)),
{ apply cauchy_seq_finset_of_norm_bounded _ (nnreal.summable_coe.2 hr) _,
simp only [coe_nnnorm, nnreal.coe_mul, nnreal.coe_pow],
rintros ⟨n, c⟩,
calc ∥(comp_along_composition q p c) (λ (j : fin n), y)∥
≤ ∥comp_along_composition q p c∥ * ∏ j : fin n, ∥y∥ :
by apply continuous_multilinear_map.le_op_norm
... ≤ ∥comp_along_composition q p c∥ * (r : ℝ) ^ n :
begin
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _),
rw [finset.prod_const, finset.card_fin],
apply pow_le_pow_of_le_left (norm_nonneg _),
rw [emetric.mem_ball, edist_eq_coe_nnnorm] at hy,
have := (le_trans (le_of_lt hy) (min_le_right _ _)),
rwa [ennreal.coe_le_coe, ← nnreal.coe_le_coe, coe_nnnorm] at this
end },
exact tendsto_nhds_of_cauchy_seq_of_subseq cau
comp_partial_sum_target_tendsto_at_top C },
-- Fifth step: the sum over `n` of `q.comp p n` can be expressed as a particular resummation of
-- the sum over all compositions, by grouping together the compositions of the same
-- integer `n`. The convergence of the whole sum therefore implies the converence of the sum
-- of `q.comp p n`
have E : has_sum (λ n, (q.comp p) n (λ j, y)) (g (f (x + y))),
{ apply D.sigma,
assume n,
dsimp [formal_multilinear_series.comp],
convert has_sum_fintype _,
simp only [continuous_multilinear_map.sum_apply],
refl },
exact E
end
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is
analytic at `x`. -/
theorem analytic_at.comp {g : F → G} {f : E → F} {x : E}
(hg : analytic_at 𝕜 g (f x)) (hf : analytic_at 𝕜 f x) : analytic_at 𝕜 (g ∘ f) x :=
let ⟨q, hq⟩ := hg, ⟨p, hp⟩ := hf in (hq.comp hp).analytic_at
/-!
### Associativity of the composition of formal multilinear series
In this paragraph, we prove the associativity of the composition of formal power series.
By definition,
```
(r.comp q).comp p n v
= ∑_{i₁ + ... + iₖ = n} (r.comp q)ₖ (p_{i₁} (v₀, ..., v_{i₁ -1}), p_{i₂} (...), ..., p_{iₖ}(...))
= ∑_{a : composition n} (r.comp q) a.length (apply_composition p a v)
```
decomposing `r.comp q` in the same way, we get
```
(r.comp q).comp p n v
= ∑_{a : composition n} ∑_{b : composition a.length}
r b.length (apply_composition q b (apply_composition p a v))
```
On the other hand,
```
r.comp (q.comp p) n v = ∑_{c : composition n} r c.length (apply_composition (q.comp p) c v)
```
Here, `apply_composition (q.comp p) c v` is a vector of length `c.length`, whose `i`-th term is
given by `(q.comp p) (c.blocks_fun i) (v_l, v_{l+1}, ..., v_{m-1})` where `{l, ..., m-1}` is the
`i`-th block in the composition `c`, of length `c.blocks_fun i` by definition. To compute this term,
we expand it as `∑_{dᵢ : composition (c.blocks_fun i)} q dᵢ.length (apply_composition p dᵢ v')`,
where `v' = (v_l, v_{l+1}, ..., v_{m-1})`. Therefore, we get
```
r.comp (q.comp p) n v =
∑_{c : composition n} ∑_{d₀ : composition (c.blocks_fun 0),
..., d_{c.length - 1} : composition (c.blocks_fun (c.length - 1))}
r c.length (λ i, q dᵢ.length (apply_composition p dᵢ v'ᵢ))
```
To show that these terms coincide, we need to explain how to reindex the sums to put them in
bijection (and then the terms we are summing will correspond to each other). Suppose we have a
composition `a` of `n`, and a composition `b` of `a.length`. Then `b` indicates how to group
together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of blocks
can be called `d₀, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by saying that
each `dᵢ` is one single block. Conversely, if one starts from `c` and the `dᵢ`s, one can concatenate
the `dᵢ`s to obtain a composition `a` of `n`, and register the lengths of the `dᵢ`s in a composition
`b` of `a.length`.
An example might be enlightening. Suppose `a = [2, 2, 3, 4, 2]`. It is a composition of
length 5 of 13. The content of the blocks may be represented as `0011222333344`.
Now take `b = [2, 3]` as a composition of `a.length = 5`. It says that the first 2 blocks of `a`
should be merged, and the last 3 blocks of `a` should be merged, giving a new composition of `13`
made of two blocks of length `4` and `9`, i.e., `c = [4, 9]`. But one can also remember that
the new first block was initially made of two blocks of size `2`, so `d₀ = [2, 2]`, and the new
second block was initially made of three blocks of size `3`, `4` and `2`, so `d₁ = [3, 4, 2]`.
This equivalence is called `composition.sigma_equiv_sigma_pi n` below.
We start with preliminary results on compositions, of a very specialized nature, then define the
equivalence `composition.sigma_equiv_sigma_pi n`, and we deduce finally the associativity of
composition of formal multilinear series in `formal_multilinear_series.comp_assoc`.
-/
namespace composition
variable {n : ℕ}
/-- Rewriting equality in the dependent type `Σ (a : composition n), composition a.length)` in
non-dependent terms with lists, requiring that the blocks coincide. -/
lemma sigma_composition_eq_iff (i j : Σ (a : composition n), composition a.length) :
i = j ↔ i.1.blocks = j.1.blocks ∧ i.2.blocks = j.2.blocks :=
begin
refine ⟨by rintro rfl; exact ⟨rfl, rfl⟩, _⟩,
rcases i with ⟨a, b⟩,
rcases j with ⟨a', b'⟩,
rintros ⟨h, h'⟩,
have H : a = a', by { ext1, exact h },
induction H, congr, ext1, exact h'
end
/-- Rewriting equality in the dependent type
`Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i)` in
non-dependent terms with lists, requiring that the lists of blocks coincide. -/
lemma sigma_pi_composition_eq_iff
(u v : Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i)) :
u = v ↔ of_fn (λ i, (u.2 i).blocks) = of_fn (λ i, (v.2 i).blocks) :=
begin
refine ⟨λ H, by rw H, λ H, _⟩,
rcases u with ⟨a, b⟩,
rcases v with ⟨a', b'⟩,
dsimp at H,
have h : a = a',
{ ext1,
have : map list.sum (of_fn (λ (i : fin (composition.length a)), (b i).blocks)) =
map list.sum (of_fn (λ (i : fin (composition.length a')), (b' i).blocks)), by rw H,
simp only [map_of_fn] at this,
change of_fn (λ (i : fin (composition.length a)), (b i).blocks.sum) =
of_fn (λ (i : fin (composition.length a')), (b' i).blocks.sum) at this,
simpa [composition.blocks_sum, composition.of_fn_blocks_fun] using this },
induction h,
simp only [true_and, eq_self_iff_true, heq_iff_eq],
ext i : 2,
have : nth_le (of_fn (λ (i : fin (composition.length a)), (b i).blocks)) i (by simp [i.is_lt]) =
nth_le (of_fn (λ (i : fin (composition.length a)), (b' i).blocks)) i (by simp [i.is_lt]) :=
nth_le_of_eq H _,
rwa [nth_le_of_fn, nth_le_of_fn] at this
end
/-- When `a` is a composition of `n` and `b` is a composition of `a.length`, `a.gather b` is the
composition of `n` obtained by gathering all the blocks of `a` corresponding to a block of `b`.
For instance, if `a = [6, 5, 3, 5, 2]` and `b = [2, 3]`, one should gather together
the first two blocks of `a` and its last three blocks, giving `a.gather b = [11, 10]`. -/
def gather (a : composition n) (b : composition a.length) : composition n :=
{ blocks := (a.blocks.split_wrt_composition b).map sum,
blocks_pos :=
begin
rw forall_mem_map_iff,
intros j hj,
suffices H : ∀ i ∈ j, 1 ≤ i, from
calc 0 < j.length : length_pos_of_mem_split_wrt_composition hj
... ≤ j.sum : length_le_sum_of_one_le _ H,
intros i hi,
apply a.one_le_blocks,
rw ← a.blocks.join_split_wrt_composition b,
exact mem_join_of_mem hj hi,
end,
blocks_sum := by { rw [← sum_join, join_split_wrt_composition, a.blocks_sum] } }
lemma length_gather (a : composition n) (b : composition a.length) :
length (a.gather b) = b.length :=
show (map list.sum (a.blocks.split_wrt_composition b)).length = b.blocks.length,
by rw [length_map, length_split_wrt_composition]
/-- An auxiliary function used in the definition of `sigma_equiv_sigma_pi` below, associating to
two compositions `a` of `n` and `b` of `a.length`, and an index `i` bounded by the length of
`a.gather b`, the subcomposition of `a` made of those blocks belonging to the `i`-th block of
`a.gather b`. -/
def sigma_composition_aux (a : composition n) (b : composition a.length)
(i : fin (a.gather b).length) :
composition ((a.gather b).blocks_fun i) :=
{ blocks := nth_le (a.blocks.split_wrt_composition b) i
(by { rw [length_split_wrt_composition, ← length_gather], exact i.2 }),
blocks_pos := assume i hi, a.blocks_pos
(by { rw ← a.blocks.join_split_wrt_composition b,
exact mem_join_of_mem (nth_le_mem _ _ _) hi }),
blocks_sum := by simp only [composition.blocks_fun, nth_le_map', composition.gather] }
lemma length_sigma_composition_aux (a : composition n) (b : composition a.length)
(i : fin b.length) :
composition.length (composition.sigma_composition_aux a b ⟨i, (length_gather a b).symm ▸ i.2⟩) =
composition.blocks_fun b i :=
show list.length (nth_le (split_wrt_composition a.blocks b) i _) = blocks_fun b i,
by { rw [nth_le_map_rev list.length, nth_le_of_eq (map_length_split_wrt_composition _ _)], refl }
lemma blocks_fun_sigma_composition_aux (a : composition n) (b : composition a.length)
(i : fin b.length) (j : fin (blocks_fun b i)) :
blocks_fun (sigma_composition_aux a b ⟨i, (length_gather a b).symm ▸ i.2⟩)
⟨j, (length_sigma_composition_aux a b i).symm ▸ j.2⟩ = blocks_fun a (embedding b i j) :=
show nth_le (nth_le _ _ _) _ _ = nth_le a.blocks _ _,
by { rw [nth_le_of_eq (nth_le_split_wrt_composition _ _ _), nth_le_drop', nth_le_take'], refl }
/-- Auxiliary lemma to prove that the composition of formal multilinear series is associative.
Consider a composition `a` of `n` and a composition `b` of `a.length`. Grouping together some
blocks of `a` according to `b` as in `a.gather b`, one can compute the total size of the blocks
of `a` up to an index `size_up_to b i + j` (where the `j` corresponds to a set of blocks of `a`
that do not fill a whole block of `a.gather b`). The first part corresponds to a sum of blocks
in `a.gather b`, and the second one to a sum of blocks in the next block of
`sigma_composition_aux a b`. This is the content of this lemma. -/
lemma size_up_to_size_up_to_add (a : composition n) (b : composition a.length)
{i j : ℕ} (hi : i < b.length) (hj : j < blocks_fun b ⟨i, hi⟩) :
size_up_to a (size_up_to b i + j) = size_up_to (a.gather b) i +
(size_up_to (sigma_composition_aux a b ⟨i, (length_gather a b).symm ▸ hi⟩) j) :=
begin
induction j with j IHj,
{ show sum (take ((b.blocks.take i).sum) a.blocks) =
sum (take i (map sum (split_wrt_composition a.blocks b))),
induction i with i IH,
{ refl },
{ have A : i < b.length := nat.lt_of_succ_lt hi,
have B : i < list.length (map list.sum (split_wrt_composition a.blocks b)), by simp [A],
have C : 0 < blocks_fun b ⟨i, A⟩ := composition.blocks_pos' _ _ _,
rw [sum_take_succ _ _ B, ← IH A C],
have : take (sum (take i b.blocks)) a.blocks =
take (sum (take i b.blocks)) (take (sum (take (i+1) b.blocks)) a.blocks),
{ rw [take_take, min_eq_left],
apply monotone_sum_take _ (nat.le_succ _) },
rw [this, nth_le_map', nth_le_split_wrt_composition,
← take_append_drop (sum (take i b.blocks))
((take (sum (take (nat.succ i) b.blocks)) a.blocks)), sum_append],
congr,
rw [take_append_drop] } },
{ have A : j < blocks_fun b ⟨i, hi⟩ := lt_trans (lt_add_one j) hj,
have B : j < length (sigma_composition_aux a b ⟨i, (length_gather a b).symm ▸ hi⟩),
by { convert A, rw [← length_sigma_composition_aux], refl },
have C : size_up_to b i + j < size_up_to b (i + 1),
{ simp only [size_up_to_succ b hi, add_lt_add_iff_left],
exact A },
have D : size_up_to b i + j < length a := lt_of_lt_of_le C (b.size_up_to_le _),
have : size_up_to b i + nat.succ j = (size_up_to b i + j).succ := rfl,
rw [this, size_up_to_succ _ D, IHj A, size_up_to_succ _ B],
simp only [sigma_composition_aux, add_assoc, add_left_inj, fin.coe_mk],
rw [nth_le_of_eq (nth_le_split_wrt_composition _ _ _), nth_le_drop', nth_le_take _ _ C] }
end
/--
Natural equivalence between `(Σ (a : composition n), composition a.length)` and
`(Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i))`, that shows up as a
change of variables in the proof that composition of formal multilinear series is associative.
Consider a composition `a` of `n` and a composition `b` of `a.length`. Then `b` indicates how to
group together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of
blocks can be called `d₀, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by
saying that each `dᵢ` is one single block. The map `⟨a, b⟩ → ⟨c, (d₀, ..., d_{a.length - 1})⟩` is
the direct map in the equiv.
Conversely, if one starts from `c` and the `dᵢ`s, one can join the `dᵢ`s to obtain a composition
`a` of `n`, and register the lengths of the `dᵢ`s in a composition `b` of `a.length`. This is the
inverse map of the equiv.
-/
def sigma_equiv_sigma_pi (n : ℕ) :
(Σ (a : composition n), composition a.length) ≃
(Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i)) :=
{ to_fun := λ i, ⟨i.1.gather i.2, i.1.sigma_composition_aux i.2⟩,
inv_fun := λ i, ⟨
{ blocks := (of_fn (λ j, (i.2 j).blocks)).join,
blocks_pos :=
begin
simp only [and_imp, mem_join, exists_imp_distrib, forall_mem_of_fn_iff],
exact λ i j hj, composition.blocks_pos _ hj
end,
blocks_sum := by simp [sum_of_fn, composition.blocks_sum, composition.sum_blocks_fun] },
{ blocks := of_fn (λ j, (i.2 j).length),
blocks_pos := forall_mem_of_fn_iff.2
(λ j, composition.length_pos_of_pos _ (composition.blocks_pos' _ _ _)),
blocks_sum := by { dsimp only [composition.length], simp [sum_of_fn] } }⟩,
left_inv :=
begin
-- the fact that we have a left inverse is essentially `join_split_wrt_composition`,
-- but we need to massage it to take care of the dependent setting.
rintros ⟨a, b⟩,
rw sigma_composition_eq_iff,
dsimp,
split,
{ have A := length_map list.sum (split_wrt_composition a.blocks b),
conv_rhs { rw [← join_split_wrt_composition a.blocks b,
← of_fn_nth_le (split_wrt_composition a.blocks b)] },
congr,
{ exact A },
{ exact (fin.heq_fun_iff A).2 (λ i, rfl) } },
{ have B : composition.length (composition.gather a b) = list.length b.blocks :=
composition.length_gather _ _,
conv_rhs { rw [← of_fn_nth_le b.blocks] },
congr' 1,
apply (fin.heq_fun_iff B).2 (λ i, _),
rw [sigma_composition_aux, composition.length, nth_le_map_rev list.length,
nth_le_of_eq (map_length_split_wrt_composition _ _)], refl }
end,
right_inv :=
begin
-- the fact that we have a right inverse is essentially `split_wrt_composition_join`,
-- but we need to massage it to take care of the dependent setting.
rintros ⟨c, d⟩,
have : map list.sum (of_fn (λ (i : fin (composition.length c)), (d i).blocks)) = c.blocks,
by simp [map_of_fn, (∘), composition.blocks_sum, composition.of_fn_blocks_fun],
rw sigma_pi_composition_eq_iff,
dsimp,
congr,
{ ext1,
dsimp [composition.gather],
rwa split_wrt_composition_join,
simp only [map_of_fn] },
{ rw fin.heq_fun_iff,
{ assume i,
dsimp [composition.sigma_composition_aux],
rw [nth_le_of_eq (split_wrt_composition_join _ _ _)],
{ simp only [nth_le_of_fn'] },
{ simp only [map_of_fn] } },
{ congr,
ext1,
dsimp [composition.gather],
rwa split_wrt_composition_join,
simp only [map_of_fn] } }
end }
end composition
namespace formal_multilinear_series
open composition
theorem comp_assoc (r : formal_multilinear_series 𝕜 G H) (q : formal_multilinear_series 𝕜 F G)
(p : formal_multilinear_series 𝕜 E F) :
(r.comp q).comp p = r.comp (q.comp p) :=
begin
ext n v,
/- First, rewrite the two compositions appearing in the theorem as two sums over complicated
sigma types, as in the description of the proof above. -/
let f : (Σ (a : composition n), composition a.length) → H :=
λ c, r c.2.length (apply_composition q c.2 (apply_composition p c.1 v)),
let g : (Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i)) → H :=
λ c, r c.1.length (λ (i : fin c.1.length),
q (c.2 i).length (apply_composition p (c.2 i) (v ∘ c.1.embedding i))),
suffices : ∑ c, f c = ∑ c, g c,
by simpa only [formal_multilinear_series.comp, continuous_multilinear_map.sum_apply,
comp_along_composition_apply, continuous_multilinear_map.map_sum, finset.sum_sigma',
apply_composition],
/- Now, we use `composition.sigma_equiv_sigma_pi n` to change
variables in the second sum, and check that we get exactly the same sums. -/
rw ← (sigma_equiv_sigma_pi n).sum_comp,
/- To check that we have the same terms, we should check that we apply the same component of
`r`, and the same component of `q`, and the same component of `p`, to the same coordinate of
`v`. This is true by definition, but at each step one needs to convince Lean that the types
one considers are the same, using a suitable congruence lemma to avoid dependent type issues.
This dance has to be done three times, one for `r`, one for `q` and one for `p`.-/
apply finset.sum_congr rfl,
rintros ⟨a, b⟩ _,
dsimp [f, g, sigma_equiv_sigma_pi],
-- check that the `r` components are the same. Based on `composition.length_gather`
apply r.congr (composition.length_gather a b).symm,
intros i hi1 hi2,
-- check that the `q` components are the same. Based on `length_sigma_composition_aux`
apply q.congr (length_sigma_composition_aux a b _).symm,
intros j hj1 hj2,
-- check that the `p` components are the same. Based on `blocks_fun_sigma_composition_aux`
apply p.congr (blocks_fun_sigma_composition_aux a b _ _).symm,
intros k hk1 hk2,
-- finally, check that the coordinates of `v` one is using are the same. Based on
-- `size_up_to_size_up_to_add`.
refine congr_arg v (fin.eq_of_veq _),
dsimp [composition.embedding],
rw [size_up_to_size_up_to_add _ _ hi1 hj1, add_assoc],
end
end formal_multilinear_series
|
0b09afd5655fabd113bf37f53eadd4f4e71d42b7 | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/analysis/complex/exponential.lean | d73568332c752f266ee75063a56f32413899c8c5 | [
"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 | 88,594 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import tactic.linarith data.complex.exponential analysis.specific_limits
group_theory.quotient_group analysis.complex.basic
/-!
# Exponential
## Main definitions
This file contains the following definitions:
* π, arcsin, arccos, arctan
* argument of a complex number
* logarithm on real and complex numbers
* complex and real power function
## Main statements
The following functions are shown to be continuous:
* complex and real exponential function
* sin, cos, tan, sinh, cosh
* logarithm on real numbers
* real power function
* square root function
The following functions are shown to be differentiable, and their derivatives are computed:
* complex and real exponential function
* sin, cos, sinh, cosh
## Tags
exp, log, sin, cos, tan, arcsin, arccos, arctan, angle, argument, power, square root,
-/
noncomputable theory
open finset filter metric asymptotics
open_locale classical
open_locale topological_space
namespace complex
/-- The complex exponential is everywhere differentiable, with the derivative `exp x`. -/
lemma has_deriv_at_exp (x : ℂ) : has_deriv_at exp (exp x) x :=
begin
rw has_deriv_at_iff_is_o_nhds_zero,
have : (1 : ℕ) < 2 := by norm_num,
refine is_O.trans_is_o ⟨∥exp x∥, _⟩ (is_o_pow_id this),
have : metric.ball (0 : ℂ) 1 ∈ nhds (0 : ℂ) := metric.ball_mem_nhds 0 zero_lt_one,
apply filter.mem_sets_of_superset this (λz hz, _),
simp only [metric.mem_ball, dist_zero_right] at hz,
simp only [exp_zero, mul_one, one_mul, add_comm, normed_field.norm_pow,
zero_add, set.mem_set_of_eq],
calc ∥exp (x + z) - exp x - z * exp x∥
= ∥exp x * (exp z - 1 - z)∥ : by { congr, rw [exp_add], ring }
... = ∥exp x∥ * ∥exp z - 1 - z∥ : normed_field.norm_mul _ _
... ≤ ∥exp x∥ * ∥z∥^2 :
mul_le_mul_of_nonneg_left (abs_exp_sub_one_sub_id_le (le_of_lt hz)) (norm_nonneg _)
end
lemma differentiable_exp : differentiable ℂ exp :=
λx, (has_deriv_at_exp x).differentiable_at
@[simp] lemma deriv_exp : deriv exp = exp :=
funext $ λ x, (has_deriv_at_exp x).deriv
@[simp] lemma iter_deriv_exp : ∀ n : ℕ, (deriv^[n] exp) = exp
| 0 := rfl
| (n+1) := by rw [nat.iterate_succ, deriv_exp, iter_deriv_exp n]
lemma continuous_exp : continuous exp :=
differentiable_exp.continuous
end complex
lemma has_deriv_at.cexp {f : ℂ → ℂ} {f' x : ℂ} (hf : has_deriv_at f f' x) :
has_deriv_at (complex.exp ∘ f) (f' * complex.exp (f x)) x :=
(complex.has_deriv_at_exp (f x)).comp x hf
lemma has_deriv_within_at.cexp {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
(hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (complex.exp ∘ f) (f' * complex.exp (f x)) s x :=
(complex.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf
namespace complex
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x :=
begin
simp only [cos, div_eq_mul_inv],
convert ((((has_deriv_at_id x).neg.mul_const I).cexp.sub
((has_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
rw [add_comm, one_mul, mul_comm (_ - _), mul_sub, mul_left_comm, ← mul_assoc, ← mul_assoc,
I_mul_I, mul_assoc (-1:ℂ), I_mul_I, neg_one_mul, neg_neg, one_mul, neg_one_mul, sub_neg_eq_add]
end
lemma differentiable_sin : differentiable ℂ sin :=
λx, (has_deriv_at_sin x).differentiable_at
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x :=
begin
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],
convert (((has_deriv_at_id x).mul_const I).cexp.add
((has_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
rw [one_mul, neg_one_mul, neg_sub, mul_comm, mul_sub, sub_eq_add_neg, neg_mul_eq_neg_mul]
end
lemma differentiable_cos : differentiable ℂ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) :=
funext $ λ x, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_tan : continuous (λ x : {x // cos x ≠ 0}, tan x) :=
(continuous_sin.comp continuous_subtype_val).mul
(continuous.inv subtype.property (continuous_cos.comp continuous_subtype_val))
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `sinh x`. -/
lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x :=
begin
simp only [cosh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).sub (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, neg_one_mul, neg_neg]
end
lemma differentiable_sinh : differentiable ℂ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `cosh x`. -/
lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x :=
begin
simp only [sinh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).add (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, neg_one_mul, sub_eq_add_neg]
end
lemma differentiable_cosh : differentiable ℂ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
end complex
namespace real
variables {x y z : ℝ}
lemma has_deriv_at_exp (x : ℝ) : has_deriv_at exp (exp x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_exp x)
lemma differentiable_exp : differentiable ℝ exp :=
λx, (has_deriv_at_exp x).differentiable_at
@[simp] lemma deriv_exp : deriv exp = exp :=
funext $ λ x, (has_deriv_at_exp x).deriv
@[simp] lemma iter_deriv_exp : ∀ n : ℕ, (deriv^[n] exp) = exp
| 0 := rfl
| (n+1) := by rw [nat.iterate_succ, deriv_exp, iter_deriv_exp n]
lemma continuous_exp : continuous exp :=
differentiable_exp.continuous
lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_sin x)
lemma differentiable_sin : differentiable ℝ sin :=
λx, (has_deriv_at_sin x).differentiable_at
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x :=
(has_deriv_at_real_of_complex (complex.has_deriv_at_cos x) : _)
lemma differentiable_cos : differentiable ℝ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma deriv_cos : deriv cos x = - sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) :=
funext $ λ _, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_tan : continuous (λ x : {x // cos x ≠ 0}, tan x) :=
by simp only [tan_eq_sin_div_cos]; exact
(continuous_sin.comp continuous_subtype_val).mul
(continuous.inv subtype.property
(continuous_cos.comp continuous_subtype_val))
lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_sinh x)
lemma differentiable_sinh : differentiable ℝ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x :=
has_deriv_at_real_of_complex (complex.has_deriv_at_cosh x)
lemma differentiable_cosh : differentiable ℝ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma exists_exp_eq_of_pos {x : ℝ} (hx : 0 < x) : ∃ y, exp y = x :=
have ∀ {z:ℝ}, 1 ≤ z → z ∈ set.range exp,
from λ z hz, intermediate_value_univ 0 (z - 1) continuous_exp
⟨by simpa, by simpa using add_one_le_exp_of_nonneg (sub_nonneg.2 hz)⟩,
match le_total x 1 with
| (or.inl hx1) := let ⟨y, hy⟩ := this (one_le_inv hx hx1) in
⟨-y, by rw [exp_neg, hy, inv_inv']⟩
| (or.inr hx1) := this hx1
end
/-- The real logarithm function, equal to `0` for `x ≤ 0` and to the inverse of the exponential
for `x > 0`. -/
noncomputable def log (x : ℝ) : ℝ :=
if hx : 0 < x then classical.some (exists_exp_eq_of_pos hx) else 0
lemma exp_log {x : ℝ} (hx : 0 < x) : exp (log x) = x :=
by rw [log, dif_pos hx]; exact classical.some_spec (exists_exp_eq_of_pos hx)
@[simp] lemma log_exp (x : ℝ) : log (exp x) = x :=
exp_injective $ exp_log (exp_pos x)
@[simp] lemma log_zero : log 0 = 0 :=
by simp [log, lt_irrefl]
@[simp] lemma log_one : log 1 = 0 :=
exp_injective $ by rw [exp_log zero_lt_one, exp_zero]
lemma log_mul {x y : ℝ} (hx : 0 < x) (hy : 0 < y) : log (x * y) = log x + log y :=
exp_injective $ by rw [exp_log (mul_pos hx hy), exp_add, exp_log hx, exp_log hy]
lemma log_le_log {x y : ℝ} (h : 0 < x) (h₁ : 0 < y) : real.log x ≤ real.log y ↔ x ≤ y :=
⟨λ h₂, by rwa [←real.exp_le_exp, real.exp_log h, real.exp_log h₁] at h₂, λ h₂,
(real.exp_le_exp).1 $ by rwa [real.exp_log h₁, real.exp_log h]⟩
lemma log_lt_log (hx : 0 < x) : x < y → log x < log y :=
by { intro h, rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] }
lemma log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y :=
by { rw [← exp_lt_exp, exp_log hx, exp_log hy] }
lemma log_pos_iff (x : ℝ) : 0 < log x ↔ 1 < x :=
begin
by_cases h : 0 < x,
{ rw ← log_one, exact log_lt_log_iff (by norm_num) h },
{ rw [log, dif_neg], split, repeat {intro, linarith} }
end
lemma log_pos : 1 < x → 0 < log x := (log_pos_iff x).2
lemma log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 :=
by { rw ← log_one, exact log_lt_log_iff h (by norm_num) }
lemma log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1
lemma log_nonneg : 1 ≤ x → 0 ≤ log x :=
by { intro, rwa [← log_one, log_le_log], norm_num, linarith }
lemma log_nonpos : x ≤ 1 → log x ≤ 0 :=
begin
intro, by_cases hx : 0 < x,
{ rwa [← log_one, log_le_log], exact hx, norm_num },
{ simp [log, dif_neg hx] }
end
section prove_log_is_continuous
lemma tendsto_log_one_zero : tendsto log (𝓝 1) (𝓝 0) :=
begin
rw tendsto_nhds_nhds, assume ε ε0,
let δ := min (exp ε - 1) (1 - exp (-ε)),
have : 0 < δ,
refine lt_min (sub_pos_of_lt (by rwa one_lt_exp_iff)) (sub_pos_of_lt _),
by { rw exp_lt_one_iff, linarith },
use [δ, this], assume x h,
cases le_total 1 x with hx hx,
{ have h : x < exp ε,
rw [dist_eq, abs_of_nonneg (sub_nonneg_of_le hx)] at h,
linarith [(min_le_left _ _ : δ ≤ exp ε - 1)],
calc abs (log x - 0) = abs (log x) : by simp
... = log x : abs_of_nonneg $ log_nonneg hx
... < ε : by { rwa [← exp_lt_exp, exp_log], linarith }},
{ have h : exp (-ε) < x,
rw [dist_eq, abs_of_nonpos (sub_nonpos_of_le hx)] at h,
linarith [(min_le_right _ _ : δ ≤ 1 - exp (-ε))],
have : 0 < x := lt_trans (exp_pos _) h,
calc abs (log x - 0) = abs (log x) : by simp
... = -log x : abs_of_nonpos $ log_nonpos hx
... < ε : by { rw [neg_lt, ← exp_lt_exp, exp_log], assumption' } }
end
lemma continuous_log' : continuous (λx : {x:ℝ // 0 < x}, log x.val) :=
continuous_iff_continuous_at.2 $ λ x,
begin
rw continuous_at,
let f₁ := λ h:{h:ℝ // 0 < h}, log (x.1 * h.1),
let f₂ := λ y:{y:ℝ // 0 < y}, subtype.mk (x.1 ⁻¹ * y.1) (mul_pos (inv_pos.2 x.2) y.2),
have H1 : tendsto f₁ (𝓝 ⟨1, zero_lt_one⟩) (𝓝 (log (x.1*1))),
have : f₁ = λ h:{h:ℝ // 0 < h}, log x.1 + log h.1,
ext h, rw ← log_mul x.2 h.2,
simp only [this, log_mul x.2 zero_lt_one, log_one],
exact tendsto_const_nhds.add (tendsto.comp tendsto_log_one_zero continuous_at_subtype_val),
have H2 : tendsto f₂ (𝓝 x) (𝓝 ⟨x.1⁻¹ * x.1, mul_pos (inv_pos.2 x.2) x.2⟩),
rw tendsto_subtype_rng, exact tendsto_const_nhds.mul continuous_at_subtype_val,
suffices h : tendsto (f₁ ∘ f₂) (𝓝 x) (𝓝 (log x.1)),
begin
convert h, ext y,
have : x.val * (x.val⁻¹ * y.val) = y.val,
rw [← mul_assoc, mul_inv_cancel (ne_of_gt x.2), one_mul],
show log (y.val) = log (x.val * (x.val⁻¹ * y.val)), rw this
end,
exact tendsto.comp (by rwa mul_one at H1)
(by { simp only [inv_mul_cancel (ne_of_gt x.2)] at H2, assumption })
end
lemma continuous_at_log (hx : 0 < x) : continuous_at log x :=
continuous_within_at.continuous_at (continuous_on_iff_continuous_restrict.2 continuous_log' _ hx)
(mem_nhds_sets (is_open_lt' _) hx)
/--
Three forms of the continuity of `real.log` is provided.
For the other two forms, see `real.continuous_log'` and `real.continuous_at_log`
-/
lemma continuous_log {α : Type*} [topological_space α] {f : α → ℝ} (h : ∀a, 0 < f a)
(hf : continuous f) : continuous (λa, log (f a)) :=
show continuous ((log ∘ @subtype.val ℝ (λr, 0 < r)) ∘ λa, ⟨f a, h a⟩),
from continuous_log'.comp (continuous_subtype_mk _ hf)
end prove_log_is_continuous
lemma exists_cos_eq_zero : 0 ∈ cos '' set.Icc (1:ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuous_cos.continuous_on
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `data.real.pi`. -/
noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : π / 2 ≤ 2 :=
by rw [pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two)
lemma pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(calc π / 2 ≤ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * π :=
by linarith [pi_pos]
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← mul_div_cancel_left pi (@two_ne_zero ℝ _), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : ℝ) + 2 = 4, from rfl,
have π - x ≤ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
match lt_or_eq_of_le h0x with
| or.inl h0x := (lt_or_eq_of_le hxp).elim
(le_of_lt ∘ sin_pos_of_pos_of_lt_pi h0x)
(λ hpx, by simp [hpx])
| or.inr h0x := by simp [h0x.symm]
end
lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
have sin (π / 2) = 1 ∨ sin (π / 2) = -1 :=
by simpa [pow_two, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2),
this.resolve_right
(λ h, (show ¬(0 : ℝ) < -1, by norm_num) $
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two
{x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_pos_of_lt_pi (by linarith) (by linarith)
lemma cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two
{x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : 0 ≤ cos x :=
match lt_or_eq_of_le hx₁, lt_or_eq_of_le hx₂ with
| or.inl hx₁, or.inl hx₂ := le_of_lt (cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two hx₁ hx₂)
| or.inl hx₁, or.inr hx₂ := by simp [hx₂]
| or.inr hx₁, _ := by simp [hx₁.symm]
end
lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x ▸
cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) (by linarith)
lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 :=
neg_nonneg.1 $ cos_pi_sub x ▸
cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two (by linarith) (by linarith)
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) :
sin x = 0 ↔ x = 0 :=
⟨λ h, le_antisymm
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂
... = 0 : h))
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)),
λ h, by simp [h]⟩
lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃, ne_of_lt (sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos))
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 :=
by rw [← mul_self_eq_one_iff (cos x), ← sin_sq_add_cos_sq x,
pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
theorem sin_sub_sin (θ ψ : ℝ) : sin θ - sin ψ = 2 * sin((θ - ψ)/2) * cos((θ + ψ)/2) :=
begin
have s1 := sin_add ((θ + ψ) / 2) ((θ - ψ) / 2),
have s2 := sin_sub ((θ + ψ) / 2) ((θ - ψ) / 2),
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel, add_self_div_two] at s1,
rw [div_sub_div_same, ←sub_add, add_sub_cancel', add_self_div_two] at s2,
rw [s1, s2, ←sub_add, add_sub_cancel', ← two_mul, ← mul_assoc, mul_right_comm]
end
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
(λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [← hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))⟩,
λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩
theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * pi / 2 :=
begin
rw [←real.sin_pi_div_two_sub, sin_eq_zero_iff],
split,
{ rintro ⟨n, hn⟩, existsi -n,
rw [int.cast_neg, add_mul, add_div, mul_assoc, mul_div_cancel_left _ two_ne_zero,
one_mul, ←neg_mul_eq_neg_mul, hn, neg_sub, sub_add_cancel] },
{ rintro ⟨n, hn⟩, existsi -n,
rw [hn, add_mul, one_mul, add_div, mul_assoc, mul_div_cancel_left _ two_ne_zero,
sub_add_eq_sub_sub_swap, sub_self, zero_sub, neg_mul_eq_neg_mul, int.cast_neg] }
end
lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 :=
⟨λ h, let ⟨n, hn⟩ := (cos_eq_one_iff x).1 h in
begin
clear _let_match,
subst hn,
rw [mul_lt_iff_lt_one_left two_pi_pos, ← int.cast_one, int.cast_lt, ← int.le_sub_one_iff, sub_self] at hx₂,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos, neg_lt,
← int.cast_one, ← int.cast_neg, int.cast_lt, ← int.add_one_le_iff, neg_add_self] at hx₁,
exact mul_eq_zero.2 (or.inl (int.cast_eq_zero.2 (le_antisymm hx₂ hx₁))),
end,
λ h, by simp [h]⟩
theorem cos_sub_cos (θ ψ : ℝ) : cos θ - cos ψ = -2 * sin((θ + ψ)/2) * sin((θ - ψ)/2) :=
by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub, sin_sub_sin, sub_sub_sub_cancel_left,
add_sub, sub_add_eq_add_sub, add_halves, sub_sub, sub_div π, cos_pi_div_two_sub,
← neg_sub, neg_div, sin_neg, ← neg_mul_eq_mul_neg, neg_mul_eq_neg_mul, mul_right_comm]
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π / 2)
(hy₁ : 0 ≤ y) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x :=
calc cos y = cos x * cos (y - x) - sin x * sin (y - x) :
by rw [← cos_add, add_sub_cancel'_right]
... < (cos x * 1) - sin x * sin (y - x) :
sub_lt_sub_right ((mul_lt_mul_left
(cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (lt_of_lt_of_le (neg_neg_of_pos pi_div_two_pos) hx₁)
(lt_of_lt_of_le hxy hy₂))).2
(lt_of_le_of_ne (cos_le_one _) (mt (cos_eq_one_iff_of_lt_of_lt
(show -(2 * π) < y - x, by linarith) (show y - x < 2 * π, by linarith)).1
(sub_ne_zero.2 (ne_of_lt hxy).symm)))) _
... ≤ _ : by rw mul_one;
exact sub_le_self _ (mul_nonneg (sin_nonneg_of_nonneg_of_le_pi hx₁ (by linarith))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith)))
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π)
(hy₁ : 0 ≤ y) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x :=
match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hx hy₁ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) hx)
(λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π)
(hy₁ : 0 ≤ y) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x :=
(lt_or_eq_of_le hxy).elim
(le_of_lt ∘ cos_lt_cos_of_nonneg_of_le_pi hx₁ hx₂ hy₁ hy₂)
(λ h, h ▸ le_refl _)
lemma sin_lt_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) (hy₁ : -(π / 2) ≤ y)
(hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y :=
by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) (hy₁ : -(π / 2) ≤ y)
(hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y :=
(lt_or_eq_of_le hxy).elim
(le_of_lt ∘ sin_lt_sin_of_le_of_le_pi_div_two hx₁ hx₂ hy₁ hy₂)
(λ h, h ▸ le_refl _)
lemma sin_inj_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) (hy₁ : -(π / 2) ≤ y)
(hy₂ : y ≤ π / 2) (hxy : sin x = sin y) : x = y :=
match lt_trichotomy x y with
| or.inl h := absurd (sin_lt_sin_of_le_of_le_pi_div_two hx₁ hx₂ hy₁ hy₂ h) (by rw hxy; exact lt_irrefl _)
| or.inr (or.inl h) := h
| or.inr (or.inr h) := absurd (sin_lt_sin_of_le_of_le_pi_div_two hy₁ hy₂ hx₁ hx₂ h) (by rw hxy; exact lt_irrefl _)
end
lemma cos_inj_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) (hy₁ : 0 ≤ y) (hy₂ : y ≤ π)
(hxy : cos x = cos y) : x = y :=
begin
rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] at hxy,
refine (sub_left_inj).1 (sin_inj_of_le_of_le_pi_div_two _ _ _ _ hxy);
linarith
end
lemma exists_sin_eq : set.Icc (-1:ℝ) 1 ⊆ sin '' set.Icc (-(π / 2)) (π / 2) :=
by convert intermediate_value_Icc
(le_trans (neg_nonpos.2 (le_of_lt pi_div_two_pos)) (le_of_lt pi_div_two_pos))
continuous_sin.continuous_on; simp only [sin_neg, sin_pi_div_two]
lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x :=
begin
cases le_or_gt x 1 with h' h',
{ have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.2, rw [sub_le_iff_le_add', hx] at this,
apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),
apply sub_lt_sub_left, rw sub_pos, apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h },
exact lt_of_le_of_lt (sin_le_one x) h'
end
/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.
note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/
lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x :=
begin
have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.1, rw [le_sub_iff_add_le, hx] at this,
refine lt_of_lt_of_le _ this,
rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,
apply add_lt_of_lt_sub_left,
rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 / 12,
by simp [div_eq_mul_inv, (mul_sub _ _ _).symm, -sub_eq_add_neg]; congr; norm_num),
apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h
end
/-- The type of angles -/
def angle : Type :=
quotient_add_group.quotient (gmultiples (2 * π))
namespace angle
instance angle.add_comm_group : add_comm_group angle :=
quotient_add_group.add_comm_group _
instance : inhabited angle := ⟨0⟩
instance angle.has_coe : has_coe ℝ angle :=
⟨quotient.mk'⟩
instance angle.is_add_group_hom : @is_add_group_hom ℝ angle _ _ (coe : ℝ → angle) :=
@quotient_add_group.is_add_group_hom _ _ _ (normal_add_subgroup_of_add_comm_group _)
@[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl
@[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl
@[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl
@[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) := rfl
@[simp] lemma coe_smul (x : ℝ) (n : ℕ) :
↑(add_monoid.smul n x : ℝ) = add_monoid.smul n (↑x : angle) :=
add_monoid_hom.map_smul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp] lemma coe_gsmul (x : ℝ) (n : ℤ) : ↑(gsmul n x : ℝ) = gsmul n (↑x : angle) :=
add_monoid_hom.map_gsmul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) :=
quotient.sound' ⟨-1, by dsimp only; rw [neg_one_gsmul, add_zero]⟩
lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k :=
by simp only [quotient_add_group.eq, gmultiples, set.mem_range, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ :=
begin
split,
{ intro Hcos,
rw [←sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false_intro two_ne_zero,
false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos,
rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩,
{ right,
rw [eq_div_iff_mul_eq _ _ (@two_ne_zero ℝ _), ← sub_eq_iff_eq_add] at hn,
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc,
← gsmul_eq_mul, coe_gsmul, mul_comm, coe_two_pi, gsmul_zero] },
{ left,
rw [eq_div_iff_mul_eq _ _ (@two_ne_zero ℝ _), eq_sub_iff_add_eq] at hn,
rw [← hn, coe_add, mul_assoc,
← gsmul_eq_mul, coe_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] } },
{ rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero_iff_eq, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left _ two_ne_zero,
mul_comm π _, sin_int_mul_pi, mul_zero],
rw [←sub_eq_zero_iff_eq, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left _ two_ne_zero, mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] }
end
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π :=
begin
split,
{ intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin,
cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h,
{ left, rw coe_sub at h, exact sub_left_inj.1 h },
right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub,
sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h,
exact h.symm },
{ rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero_iff_eq, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left _ two_ne_zero,
mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul],
have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add,
mul_assoc, mul_comm π _, ←mul_assoc] at H,
rw [← sub_eq_zero_iff_eq, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left _ two_ne_zero,
cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] }
end
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ :=
begin
cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc },
cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs },
rw [eq_neg_iff_add_eq_zero, hs] at hc,
cases quotient.exact' hc with n hn, dsimp only at hn,
rw [← neg_one_mul, add_zero, ← sub_eq_zero_iff_eq, gsmul_eq_mul, ← mul_assoc, ← sub_mul,
mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add,
← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add, int.cast_inj] at hn,
have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn,
rw [add_comm, int.add_mul_mod_self] at this,
exact absurd this one_ne_zero
end
end angle
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x` and `arcsin x ≤ π / 2`.
If the argument is not between `-1` and `1` it defaults to `0` -/
noncomputable def arcsin (x : ℝ) : ℝ :=
if hx : -1 ≤ x ∧ x ≤ 1 then classical.some (exists_sin_eq hx) else 0
lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 :=
if hx : -1 ≤ x ∧ x ≤ 1
then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (exists_sin_eq hx)).1.2
else by rw [arcsin, dif_neg hx]; exact le_of_lt pi_div_two_pos
lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x :=
if hx : -1 ≤ x ∧ x ≤ 1
then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (exists_sin_eq hx)).1.1
else by rw [arcsin, dif_neg hx]; exact neg_nonpos.2 (le_of_lt pi_div_two_pos)
lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
by rw [arcsin, dif_pos (and.intro hx₁ hx₂)];
exact (classical.some_spec (exists_sin_eq ⟨hx₁, hx₂⟩)).2
lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
sin_inj_of_le_of_le_pi_div_two (neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _) hx₁ hx₂
(by rw sin_arcsin (neg_one_le_sin _) (sin_le_one _))
lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1)
(hxy : arcsin x = arcsin y) : x = y :=
by rw [← sin_arcsin hx₁ hx₂, ← sin_arcsin hy₁ hy₂, hxy]
@[simp] lemma arcsin_zero : arcsin 0 = 0 :=
sin_inj_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _)
(arcsin_le_pi_div_two _)
(neg_nonpos.2 (le_of_lt pi_div_two_pos))
(le_of_lt pi_div_two_pos)
(by rw [sin_arcsin, sin_zero]; norm_num)
@[simp] lemma arcsin_one : arcsin 1 = π / 2 :=
sin_inj_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _)
(arcsin_le_pi_div_two _)
(by linarith [pi_pos])
(le_refl _)
(by rw [sin_arcsin, sin_pi_div_two]; norm_num)
@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=
if h : -1 ≤ x ∧ x ≤ 1 then
have -1 ≤ -x ∧ -x ≤ 1, by rwa [neg_le_neg_iff, neg_le, and.comm],
sin_inj_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _)
(arcsin_le_pi_div_two _)
(neg_le_neg (arcsin_le_pi_div_two _))
(neg_le.1 (neg_pi_div_two_le_arcsin _))
(by rw [sin_arcsin this.1 this.2, sin_neg, sin_arcsin h.1 h.2])
else
have ¬(-1 ≤ -x ∧ -x ≤ 1) := by rwa [neg_le_neg_iff, neg_le, and.comm],
by rw [arcsin, arcsin, dif_neg h, dif_neg this, neg_zero]
@[simp] lemma arcsin_neg_one : arcsin (-1) = -(π / 2) := by simp
lemma arcsin_nonneg {x : ℝ} (hx : 0 ≤ x) : 0 ≤ arcsin x :=
if hx₁ : x ≤ 1 then
not_lt.1 (λ h, not_lt.2 hx begin
have := sin_lt_sin_of_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _)
(neg_nonpos.2 (le_of_lt pi_div_two_pos)) (le_of_lt pi_div_two_pos) h,
rw [real.sin_arcsin, sin_zero] at this; linarith
end)
else by rw [arcsin, dif_neg]; simp [hx₁]
lemma arcsin_eq_zero_iff {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : arcsin x = 0 ↔ x = 0 :=
⟨λ h, have sin (arcsin x) = 0, by simp [h],
by rwa [sin_arcsin hx₁ hx₂] at this,
λ h, by simp [h]⟩
lemma arcsin_pos {x : ℝ} (hx₁ : 0 < x) (hx₂ : x ≤ 1) : 0 < arcsin x :=
lt_of_le_of_ne (arcsin_nonneg (le_of_lt hx₁))
(ne.symm (mt (arcsin_eq_zero_iff (by linarith) hx₂).1 (ne_of_lt hx₁).symm))
lemma arcsin_nonpos {x : ℝ} (hx : x ≤ 0) : arcsin x ≤ 0 :=
neg_nonneg.1 (arcsin_neg x ▸ arcsin_nonneg (neg_nonneg.2 hx))
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
If the argument is not between `-1` and `1` it defaults to `π / 2` -/
noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
lemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl
lemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=
by simp [sub_eq_add_neg, arccos]
lemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=
by unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
lemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=
by unfold arccos; linarith [arcsin_le_pi_div_two x]
lemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=
by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
lemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=
by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1)
(hxy : arccos x = arccos y) : x = y :=
arcsin_inj hx₁ hx₂ hy₁ hy₂ $ by simp [arccos, *] at *
@[simp] lemma arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp] lemma arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=
by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self]; simp
lemma cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _) (arcsin_le_pi_div_two _)
lemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) :=
have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x),
begin
rw [← eq_sub_iff_add_eq', ← sqrt_inj (pow_two_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))),
pow_two, sqrt_mul_self (cos_arcsin_nonneg _)] at this,
rw [this, sin_arcsin hx₁ hx₂],
end
lemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arccos x) = sqrt (1 - x ^ 2) :=
by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx₁ hx₂]
lemma abs_div_sqrt_one_add_lt (x : ℝ) : abs (x / sqrt (1 + x ^ 2)) < 1 :=
have h₁ : 0 < 1 + x ^ 2, from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _),
have h₂ : 0 < sqrt (1 + x ^ 2), from sqrt_pos.2 h₁,
by rw [abs_div, div_lt_iff (abs_pos_of_pos h₂), one_mul,
mul_self_lt_mul_self_iff (abs_nonneg x) (abs_nonneg _),
← abs_mul, ← abs_mul, mul_self_sqrt (add_nonneg zero_le_one (pow_two_nonneg _)),
abs_of_nonneg (mul_self_nonneg x), abs_of_nonneg (le_of_lt h₁), pow_two, add_comm];
exact lt_add_one _
lemma div_sqrt_one_add_lt_one (x : ℝ) : x / sqrt (1 + x ^ 2) < 1 :=
(abs_lt.1 (abs_div_sqrt_one_add_lt _)).2
lemma neg_one_lt_div_sqrt_one_add (x : ℝ) : -1 < x / sqrt (1 + x ^ 2) :=
(abs_lt.1 (abs_div_sqrt_one_add_lt _)).1
lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x :=
by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))
(cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) hxp)
lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]
| or.inr hx0, _ := by simp [hx0.symm]
end
lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 :=
neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x < π / 2) (hy₁ : 0 ≤ y)
(hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y :=
begin
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],
exact div_lt_div
(sin_lt_sin_of_le_of_le_pi_div_two (by linarith) (le_of_lt hx₂)
(by linarith) (le_of_lt hy₂) hxy)
(cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) hy₁ (by linarith) (le_of_lt hxy))
(sin_nonneg_of_nonneg_of_le_pi hy₁ (by linarith))
(cos_pos_of_neg_pi_div_two_lt_of_lt_pi_div_two (by linarith) hy₂)
end
lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y :=
match le_total x 0, le_total y 0 with
| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact
tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0) (neg_lt.2 hy₁)
(neg_nonneg.2 hx0) (neg_lt.2 hx₁) (neg_lt_neg hxy)
| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim
(λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁)
... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂)
(λ hy0, by rw [← hy0, tan_zero]; exact
tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁)
| or.inr hx0, or.inl hy0 := by linarith
| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hx₂ hy0 hy₂ hxy
end
lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y :=
match lt_trichotomy x y with
| or.inl h := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hx₁ hx₂ hy₁ hy₂ h) (by rw hxy; exact lt_irrefl _)
| or.inr (or.inl h) := h
| or.inr (or.inr h) := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hy₁ hy₂ hx₁ hx₂ h) (by rw hxy; exact lt_irrefl _)
end
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and `arctan x < π / 2` -/
noncomputable def arctan (x : ℝ) : ℝ :=
arcsin (x / sqrt (1 + x ^ 2))
lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) :=
sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _))
lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) :=
have h₁ : (0 : ℝ) < 1 + x ^ 2,
from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _),
have h₂ : (x / sqrt (1 + x ^ 2)) ^ 2 < 1,
by rw [pow_two, ← abs_mul_self, _root_.abs_mul];
exact mul_lt_one_of_nonneg_of_lt_one_left (abs_nonneg _)
(abs_div_sqrt_one_add_lt _) (le_of_lt (abs_div_sqrt_one_add_lt _)),
by rw [arctan, cos_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)),
one_div_eq_inv, ← sqrt_inv, sqrt_inj (sub_nonneg.2 (le_of_lt h₂)) (inv_nonneg.2 (le_of_lt h₁)),
div_pow, pow_two (sqrt _), mul_self_sqrt (le_of_lt h₁),
← domain.mul_left_inj (ne.symm (ne_of_lt h₁)), mul_sub,
mul_div_cancel' _ (ne.symm (ne_of_lt h₁)), mul_inv_cancel (ne.symm (ne_of_lt h₁))];
simp
lemma tan_arctan (x : ℝ) : tan (arctan x) = x :=
by rw [tan_eq_sin_div_cos, sin_arctan, cos_arctan, div_div_div_div_eq, mul_one,
mul_div_assoc,
div_self (mt sqrt_eq_zero'.1 (not_le_of_gt (add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg x)))),
mul_one]
lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
lt_of_le_of_ne (arcsin_le_pi_div_two _)
(λ h, ne_of_lt (div_sqrt_one_add_lt_one x) $
by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _))
(le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, h, sin_pi_div_two])
lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
lt_of_le_of_ne (neg_pi_div_two_le_arcsin _)
(λ h, ne_of_lt (neg_one_lt_div_sqrt_one_add x) $
by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _))
(le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, ← h, sin_neg, sin_pi_div_two])
lemma tan_surjective : function.surjective tan :=
function.surjective_of_has_right_inverse ⟨_, tan_arctan⟩
lemma arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan _)
(arctan_lt_pi_div_two _) hx₁ hx₂ (by rw tan_arctan)
@[simp] lemma arctan_zero : arctan 0 = 0 :=
by simp [arctan]
@[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x :=
by simp [arctan, neg_div]
end real
namespace complex
open_locale real
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re
then real.arcsin (x.im / x.abs)
else if 0 ≤ x.im
then real.arcsin ((-x).im / x.abs) + π
else real.arcsin ((-x).im / x.abs) - π
lemma arg_le_pi (x : ℂ) : arg x ≤ π :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos))
else
have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁,
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂];
exact le_sub_iff_add_le.1 (by rw sub_self;
exact real.arcsin_nonpos (by rw [neg_im, neg_div, neg_nonpos]; exact div_nonneg hx₂ (abs_pos.2 hx)))
else by rw [arg, if_neg hx₁, if_neg hx₂];
exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _)
(by linarith [real.pi_pos]))
lemma neg_pi_lt_arg (x : ℂ) : -π < arg x :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _)
else
have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁,
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂];
exact sub_lt_iff_lt_add.1
(lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _))
else by rw [arg, if_neg hx₁, if_neg hx₂];
exact lt_sub_iff_add_lt.2 (by rw neg_add_self;
exact real.arcsin_pos (by rw [neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hx₂))
(abs_pos.2 hx)) (by rw [← abs_neg x]; exact (abs_le.1 (abs_im_div_abs_le_one _)).2))
lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : 0 ≤ x.im) :
arg x = arg (-x) + π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg]
lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : x.im < 0) :
arg x = arg (-x) - π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg]
@[simp] lemma arg_zero : arg 0 = 0 :=
by simp [arg, le_refl]
@[simp] lemma arg_one : arg 1 = 0 :=
by simp [arg, zero_le_one]
@[simp] lemma arg_neg_one : arg (-1) = π :=
by simp [arg, le_refl, not_le.2 (@zero_lt_one ℝ _)]
@[simp] lemma arg_I : arg I = π / 2 :=
by simp [arg, le_refl]
@[simp] lemma arg_neg_I : arg (-I) = -(π / 2) :=
by simp [arg, le_refl]
lemma sin_arg (x : ℂ) : real.sin (arg x) = x.im / x.abs :=
by unfold arg; split_ifs;
simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg,
real.sin_neg]
private lemma cos_arg_of_re_nonneg {x : ℂ} (hx : x ≠ 0) (hxr : 0 ≤ x.re) : real.cos (arg x) = x.re / x.abs :=
have 0 ≤ 1 - (x.im / abs x) ^ 2,
from sub_nonneg.2 $ by rw [pow_two, ← _root_.abs_mul_self, _root_.abs_mul, ← pow_two];
exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _),
by rw [eq_div_iff_mul_eq _ _ (mt abs_eq_zero.1 hx), ← real.mul_self_sqrt (abs_nonneg x),
arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, ← real.sqrt_mul (abs_nonneg _), ← real.sqrt_mul this,
sub_mul, div_pow, ← pow_two, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)),
one_mul, pow_two, mul_self_abs, norm_sq, pow_two, add_sub_cancel, real.sqrt_mul_self hxr]
lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs :=
if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr
else
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
if hxi : 0 ≤ x.im
then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi,
cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this];
simp [neg_div]
else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)];
simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]
lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re :=
begin
by_cases h : x = 0,
{ simp only [h, euclidean_domain.zero_div,
complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re]},
rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
div_div_div_cancel_right' _ (mt abs_eq_zero.1 h)]
end
lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) :
arg (cos x + sin x * I) = x :=
if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2
then
have hx₄ : 0 ≤ (cos x + sin x * I).re,
by simp; exact real.cos_nonneg_of_neg_pi_div_two_le_of_le_pi_div_two hx₃.1 hx₃.2,
by rw [arg, if_pos hx₄];
simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2]
else if hx₄ : x < -(π / 2)
then
have hx₅ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬ 0 ≤ real.cos x, by simpa,
not_le.2 $ by rw ← real.cos_neg;
apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im :=
suffices real.sin x < 0, by simpa,
by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith,
suffices -π + -real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₅, if_neg hx₆];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]}; linarith
else
have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith,
have hx₆ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬0 ≤ real.cos x, by simpa,
not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₇ : 0 ≤ (cos x + sin x * I).im :=
suffices 0 ≤ real.sin x, by simpa,
by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith,
suffices π - real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₆, if_pos hx₇];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (abs y / abs x : ℂ) * x = y :=
have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx),
have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy),
⟨λ h,
begin
have hcos := congr_arg real.cos h,
rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos,
have hsin := congr_arg real.sin h,
rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin,
apply complex.ext,
{ rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm,
← mul_div_assoc, hcos, mul_div_cancel _ hax] },
{ rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero,
mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] }
end,
λ h,
have hre : abs (y / x) * x.re = y.re,
by rw ← of_real_div at h;
simpa [-of_real_div] using congr_arg re h,
have hre' : abs (x / y) * y.re = x.re,
by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have him : abs (y / x) * x.im = y.im,
by rw ← of_real_div at h;
simpa [-of_real_div] using congr_arg im h,
have him' : abs (x / y) * y.im = x.im,
by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have hxya : x.im / abs x = y.im / abs y,
by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay],
have hnxya : (-x).im / abs x = (-y).im / abs y,
by rw [neg_im, neg_im, neg_div, neg_div, hxya],
if hxr : 0 ≤ x.re
then
have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr,
by simp [arg, *] at *
else
have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr,
if hxi : 0 ≤ x.im
then
have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi,
by simp [arg, *] at *
else
have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi,
by simp [arg, *] at *⟩
lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x :=
if hx : x = 0 then by simp [hx]
else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $
by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc,
of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul,
div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm),
div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul]
lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y :=
if hy : y = 0 then by simp * at *
else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *,
by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul] at h₂
lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 :=
by simp [arg, hx]
lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π :=
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg, ← of_real_neg, arg_of_real_of_nonneg];
simp [*, le_iff_eq_or_lt, lt_neg]
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`.
`log 0 = 0`-/
noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I
lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log]
lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log]
lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x :=
by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx,
← of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), ← mul_assoc,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]
lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π)
(hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y :=
by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy;
exact complex.ext
(real.exp_injective $
by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy)
(by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _),
arg_cos_add_sin_mul_I hx₁ hx₂, arg_cos_add_sin_mul_I hy₁ hy₂] using congr_arg arg hxy)
lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x :=
exp_inj_of_neg_pi_lt_of_le_pi
(by rw log_im; exact neg_pi_lt_arg _)
(by rw log_im; exact arg_le_pi _)
hx₁ hx₂ (by rw [exp_log (exp_ne_zero _)])
lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x :=
complex.ext
(by rw [log_re, of_real_re, abs_of_nonneg hx])
(by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])
@[simp] lemma log_zero : log 0 = 0 := by simp [log]
@[simp] lemma log_one : log 1 = 0 := by simp [log]
lemma log_neg_one : log (-1) = π * I := by simp [log]
lemma log_I : log I = π / 2 * I := by simp [log]
lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log]
lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :=
have real.exp (x.re) * real.cos (x.im) = 1 → real.cos x.im ≠ -1,
from λ h₁ h₂, begin
rw [h₂, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h₁,
have := real.exp_pos x.re,
rw ← h₁ at this,
exact absurd this (by norm_num)
end,
calc exp x = 1 ↔ (exp x).re = 1 ∧ (exp x).im = 0 : by simp [complex.ext_iff]
... ↔ real.cos x.im = 1 ∧ real.sin x.im = 0 ∧ x.re = 0 :
begin
rw exp_eq_exp_re_mul_sin_add_cos,
simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re,
real.exp_ne_zero],
split; finish [real.sin_eq_zero_iff_cos_eq]
end
... ↔ (∃ n : ℤ, ↑n * (2 * π) = x.im) ∧ (∃ n : ℤ, ↑n * π = x.im) ∧ x.re = 0 :
by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff]
... ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :
⟨λ ⟨⟨n, hn⟩, ⟨m, hm⟩, h⟩, ⟨n, by simp [complex.ext_iff, hn.symm, h]⟩,
λ ⟨n, hn⟩, ⟨⟨n, by simp [hn]⟩, ⟨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]⟩,
by simp [hn]⟩⟩
lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 :=
by rw [exp_sub, div_eq_one_iff_eq _ (exp_ne_zero _)]
lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) :=
by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp
... = 0 : by simp
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp
... = 1 : by simp
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← of_real_sin, real.sin_pi]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← of_real_cos, real.cos_pi]; simp
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
section pow
/-- The complex power function `x^y`, given by `x^y = exp(y log x)` (where `log` is the principal
determination of the logarithm), unless `x = 0` where one sets `0^0 = 1` and `0^y = 0` for
`y ≠ 0`. -/
noncomputable def cpow (x y : ℂ) : ℂ :=
if x = 0
then if y = 0
then 1
else 0
else exp (log x * y)
noncomputable instance : has_pow ℂ ℂ := ⟨cpow⟩
@[simp] lemma cpow_eq_pow (x y : ℂ) : cpow x y = x ^ y := rfl
lemma cpow_def (x y : ℂ) : x ^ y =
if x = 0
then if y = 0
then 1
else 0
else exp (log x * y) := rfl
@[simp] lemma cpow_zero (x : ℂ) : x ^ (0 : ℂ) = 1 := by simp [cpow_def]
@[simp] lemma cpow_eq_zero_iff (x y : ℂ) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 :=
by { simp only [cpow_def], split_ifs; simp [*, exp_ne_zero] }
@[simp] lemma zero_cpow {x : ℂ} (h : x ≠ 0) : (0 : ℂ) ^ x = 0 :=
by simp [cpow_def, *]
@[simp] lemma cpow_one (x : ℂ) : x ^ (1 : ℂ) = x :=
if hx : x = 0 then by simp [hx, cpow_def]
else by rw [cpow_def, if_neg (@one_ne_zero ℂ _), if_neg hx, mul_one, exp_log hx]
@[simp] lemma one_cpow (x : ℂ) : (1 : ℂ) ^ x = 1 :=
by rw cpow_def; split_ifs; simp [one_ne_zero, *] at *
lemma cpow_add {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y + z) = x ^ y * x ^ z :=
by simp [cpow_def]; split_ifs; simp [*, exp_add, mul_add] at *
lemma cpow_mul {x y : ℂ} (z : ℂ) (h₁ : -π < (log x * y).im) (h₂ : (log x * y).im ≤ π) :
x ^ (y * z) = (x ^ y) ^ z :=
begin
simp [cpow_def],
split_ifs;
simp [*, exp_ne_zero, log_exp h₁ h₂, mul_assoc] at *
end
lemma cpow_neg (x y : ℂ) : x ^ -y = (x ^ y)⁻¹ :=
by simp [cpow_def]; split_ifs; simp [exp_neg]
@[simp] lemma cpow_nat_cast (x : ℂ) : ∀ (n : ℕ), x ^ (n : ℂ) = x ^ n
| 0 := by simp
| (n + 1) := if hx : x = 0 then by simp only [hx, pow_succ,
complex.zero_cpow (nat.cast_ne_zero.2 (nat.succ_ne_zero _)), zero_mul]
else by simp [cpow_def, hx, mul_comm, mul_add, exp_add, pow_succ, (cpow_nat_cast n).symm,
exp_log hx]
@[simp] lemma cpow_int_cast (x : ℂ) : ∀ (n : ℤ), x ^ (n : ℂ) = x ^ n
| (n : ℕ) := by simp; refl
| -[1+ n] := by rw fpow_neg_succ_of_nat;
simp only [int.neg_succ_of_nat_coe, int.cast_neg, complex.cpow_neg, inv_eq_one_div,
int.cast_coe_nat, cpow_nat_cast]
lemma cpow_nat_inv_pow (x : ℂ) {n : ℕ} (hn : 0 < n) : (x ^ (n⁻¹ : ℂ)) ^ n = x :=
have (log x * (↑n)⁻¹).im = (log x).im / n,
by rw [div_eq_mul_inv, ← of_real_nat_cast, ← of_real_inv, mul_im,
of_real_re, of_real_im]; simp,
have h : -π < (log x * (↑n)⁻¹).im ∧ (log x * (↑n)⁻¹).im ≤ π,
from (le_total (log x).im 0).elim
(λ h, ⟨calc -π < (log x).im : by simp [log, neg_pi_lt_arg]
... ≤ ((log x).im * 1) / n : le_div_of_mul_le (nat.cast_pos.2 hn)
(mul_le_mul_of_nonpos_left (by rw ← nat.cast_one; exact nat.cast_le.2 hn) h)
... = (log x * (↑n)⁻¹).im : by simp [this],
this.symm ▸ le_trans (div_nonpos_of_nonpos_of_pos h (nat.cast_pos.2 hn))
(le_of_lt real.pi_pos)⟩)
(λ h, ⟨this.symm ▸ lt_of_lt_of_le (neg_neg_of_pos real.pi_pos)
(div_nonneg h (nat.cast_pos.2 hn)),
calc (log x * (↑n)⁻¹).im = (1 * (log x).im) / n : by simp [this]
... ≤ (log x).im : (div_le_of_le_mul (nat.cast_pos.2 hn)
(mul_le_mul_of_nonneg_right (by rw ← nat.cast_one; exact nat.cast_le.2 hn) h))
... ≤ _ : by simp [log, arg_le_pi]⟩),
by rw [← cpow_nat_cast, ← cpow_mul _ h.1 h.2,
inv_mul_cancel (show (n : ℂ) ≠ 0, from nat.cast_ne_zero.2 (nat.pos_iff_ne_zero.1 hn)),
cpow_one]
end pow
end complex
namespace real
/-- The real power function `x^y`, defined as the real part of the complex power function.
For `x > 0`, it is equal to `exp(y log x)`. For `x = 0`, one sets `0^0=1` and `0^y=0` for `y ≠ 0`.
For `x < 0`, the definition is somewhat arbitary as it depends on the choice of a complex
determination of the logarithm. With our conventions, it is equal to `exp (y log (-x)) cos (πy)`. -/
noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re
noncomputable instance : has_pow ℝ ℝ := ⟨rpow⟩
@[simp] lemma rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl
lemma rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl
lemma rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y =
if x = 0
then if y = 0
then 1
else 0
else exp (log x * y) :=
by simp only [rpow_def, complex.cpow_def];
split_ifs;
simp [*, (complex.of_real_log hx).symm, -complex.of_real_mul,
(complex.of_real_mul _ _).symm, complex.exp_of_real_re] at *
lemma rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) :=
by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]
lemma rpow_eq_zero_iff_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 :=
by { simp only [rpow_def_of_nonneg hx], split_ifs; simp [*, exp_ne_zero] }
open_locale real
lemma rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log (-x) * y) * cos (y * π) :=
begin
rw [rpow_def, complex.cpow_def, if_neg],
have : complex.log x * y = ↑(log(-x) * y) + ↑(y * π) * complex.I,
simp only [complex.log, abs_of_neg hx, complex.arg_of_real_of_neg hx,
complex.abs_of_real, complex.of_real_mul], ring,
{ rw [this, complex.exp_add_mul_I, ← complex.of_real_exp, ← complex.of_real_cos,
← complex.of_real_sin, mul_add, ← complex.of_real_mul, ← mul_assoc, ← complex.of_real_mul,
complex.add_re, complex.of_real_re, complex.mul_re, complex.I_re, complex.of_real_im], ring },
{ rw complex.of_real_eq_zero, exact ne_of_lt hx }
end
lemma rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y =
if x = 0
then if y = 0
then 1
else 0
else exp (log (-x) * y) * cos (y * π) :=
by split_ifs; simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _
lemma rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y :=
by rw rpow_def_of_pos hx; apply exp_pos
lemma abs_rpow_le_abs_rpow (x y : ℝ) : abs (x ^ y) ≤ abs (x) ^ y :=
abs_le_of_le_of_neg_le
begin
cases lt_trichotomy 0 x, { rw abs_of_pos h },
cases h, { simp [h.symm] },
rw [rpow_def_of_neg h, rpow_def_of_pos (abs_pos_of_neg h), abs_of_neg h],
calc exp (log (-x) * y) * cos (y * π) ≤ exp (log (-x) * y) * 1 :
mul_le_mul_of_nonneg_left (cos_le_one _) (le_of_lt $ exp_pos _)
... = _ : mul_one _
end
begin
cases lt_trichotomy 0 x, { rw abs_of_pos h, have : 0 < x^y := rpow_pos_of_pos h _, linarith },
cases h, { simp only [h.symm, abs_zero, rpow_def_of_nonneg], split_ifs, repeat {norm_num}},
rw [rpow_def_of_neg h, rpow_def_of_pos (abs_pos_of_neg h), abs_of_neg h],
calc -(exp (log (-x) * y) * cos (y * π)) = exp (log (-x) * y) * (-cos (y * π)) : by ring
... ≤ exp (log (-x) * y) * 1 :
mul_le_mul_of_nonneg_left (neg_le.2 $ neg_one_le_cos _) (le_of_lt $ exp_pos _)
... = exp (log (-x) * y) : mul_one _
end
end real
namespace complex
lemma of_real_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) :=
by simp [real.rpow_def_of_nonneg hx, complex.cpow_def]; split_ifs; simp [complex.of_real_log hx]
@[simp] lemma abs_cpow_real (x : ℂ) (y : ℝ) : abs (x ^ (y : ℂ)) = x.abs ^ y :=
begin
rw [real.rpow_def_of_nonneg (abs_nonneg _), complex.cpow_def],
split_ifs;
simp [*, abs_of_nonneg (le_of_lt (real.exp_pos _)), complex.log, complex.exp_add,
add_mul, mul_right_comm _ I, exp_mul_I, abs_cos_add_sin_mul_I,
(complex.of_real_mul _ _).symm, -complex.of_real_mul] at *
end
@[simp] lemma abs_cpow_inv_nat (x : ℂ) (n : ℕ) : abs (x ^ (n⁻¹ : ℂ)) = x.abs ^ (n⁻¹ : ℝ) :=
by rw ← abs_cpow_real; simp [-abs_cpow_real]
end complex
namespace real
open_locale real
variables {x y z : ℝ}
@[simp] lemma rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def]
@[simp] lemma zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 :=
by simp [rpow_def, *]
@[simp] lemma rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def]
@[simp] lemma one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def]
lemma rpow_nonneg_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y :=
by rw [rpow_def_of_nonneg hx];
split_ifs; simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)]
lemma rpow_add {x : ℝ} (y z : ℝ) (hx : 0 < x) : x ^ (y + z) = x ^ y * x ^ z :=
by simp only [rpow_def_of_pos hx, mul_add, exp_add]
lemma rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
by rw [← complex.of_real_inj, complex.of_real_cpow (rpow_nonneg_of_nonneg hx _),
complex.of_real_cpow hx, complex.of_real_mul, complex.cpow_mul, complex.of_real_cpow hx];
simp only [(complex.of_real_mul _ _).symm, (complex.of_real_log hx).symm,
complex.of_real_im, neg_lt_zero, pi_pos, le_of_lt pi_pos]
lemma rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ -y = (x ^ y)⁻¹ :=
by simp only [rpow_def_of_nonneg hx]; split_ifs; simp [*, exp_neg] at *
@[simp] lemma rpow_nat_cast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
by simp only [rpow_def, (complex.of_real_pow _ _).symm, complex.cpow_nat_cast,
complex.of_real_nat_cast, complex.of_real_re]
@[simp] lemma rpow_int_cast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n :=
by simp only [rpow_def, (complex.of_real_fpow _ _).symm, complex.cpow_int_cast,
complex.of_real_int_cast, complex.of_real_re]
lemma mul_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : 0 ≤ y) : (x*y)^z = x^z * y^z :=
begin
iterate 3 { rw real.rpow_def_of_nonneg }, split_ifs; simp * at *,
{ have hx : 0 < x, cases lt_or_eq_of_le h with h₂ h₂, exact h₂, exfalso, apply h_2, exact eq.symm h₂,
have hy : 0 < y, cases lt_or_eq_of_le h₁ with h₂ h₂, exact h₂, exfalso, apply h_3, exact eq.symm h₂,
rw [log_mul hx hy, add_mul, exp_add]},
{ exact h₁},
{ exact h},
{ exact mul_nonneg h h₁},
end
lemma one_le_rpow {x z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x^z :=
begin
rw real.rpow_def_of_nonneg, split_ifs with h₂ h₃,
{ refl},
{ simp [*, not_le_of_gt zero_lt_one] at *},
{ have hx : 0 < x, exact lt_of_lt_of_le zero_lt_one h,
rw [←log_le_log zero_lt_one hx, log_one] at h,
have pos : 0 ≤ log x * z, exact mul_nonneg h h₁,
rwa [←exp_le_exp, exp_zero] at pos},
{ exact le_trans zero_le_one h},
end
lemma rpow_le_rpow {x y z: ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x^z ≤ y^z :=
begin
rw le_iff_eq_or_lt at h h₂, cases h₂,
{ rw [←h₂, rpow_zero, rpow_zero]},
{ cases h,
{ rw [←h, zero_rpow], rw real.rpow_def_of_nonneg, split_ifs,
{ exact zero_le_one},
{ refl},
{ exact le_of_lt (exp_pos (log y * z))},
{ rwa ←h at h₁},
{ exact ne.symm (ne_of_lt h₂)}},
{ have one_le : 1 ≤ y / x, rw one_le_div_iff_le h, exact h₁,
have one_le_pow : 1 ≤ (y / x)^z, exact one_le_rpow one_le (le_of_lt h₂),
rw [←mul_div_cancel y (ne.symm (ne_of_lt h)), mul_comm, mul_div_assoc],
rw [mul_rpow (le_of_lt h) (le_trans zero_le_one one_le), mul_comm],
exact (le_mul_of_ge_one_left (rpow_nonneg_of_nonneg (le_of_lt h) z) one_le_pow) } }
end
lemma rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x^z < y^z :=
begin
rw le_iff_eq_or_lt at hx, cases hx,
{ rw [← hx, zero_rpow (ne_of_gt hz)], exact rpow_pos_of_pos (by rwa ← hx at hxy) _ },
rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp],
exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz
end
lemma rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x^y < x^z :=
begin
repeat {rw [rpow_def_of_pos (lt_trans zero_lt_one hx)]},
rw exp_lt_exp, exact mul_lt_mul_of_pos_left hyz (log_pos hx),
end
lemma rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x^y ≤ x^z :=
begin
repeat {rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)]},
rw exp_le_exp, exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx),
end
lemma rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x^y < x^z :=
begin
repeat {rw [rpow_def_of_pos hx0]},
rw exp_lt_exp, exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1),
end
lemma rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x^y ≤ x^z :=
begin
repeat {rw [rpow_def_of_pos hx0]},
rw exp_le_exp, exact mul_le_mul_of_nonpos_left hyz (log_nonpos hx1),
end
lemma rpow_le_one {x e : ℝ} (he : 0 ≤ e) (hx : 0 ≤ x) (hx2 : x ≤ 1) : x^e ≤ 1 :=
by rw ←one_rpow e; apply rpow_le_rpow; assumption
lemma one_lt_rpow (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=
by { rw ← one_rpow z, exact rpow_lt_rpow zero_le_one hx hz }
lemma rpow_lt_one (hx : 0 < x) (hx1 : x < 1) (hz : 0 < z) : x^z < 1 :=
by { rw ← one_rpow z, exact rpow_lt_rpow (le_of_lt hx) hx1 hz }
lemma pow_nat_rpow_nat_inv {x : ℝ} (hx : 0 ≤ x) {n : ℕ} (hn : 0 < n) :
(x ^ n) ^ (n⁻¹ : ℝ) = x :=
have hn0 : (n : ℝ) ≠ 0, by simpa [nat.pos_iff_ne_zero] using hn,
by rw [← rpow_nat_cast, ← rpow_mul hx, mul_inv_cancel hn0, rpow_one]
lemma rpow_nat_inv_pow_nat {x : ℝ} (hx : 0 ≤ x) {n : ℕ} (hn : 0 < n) :
(x ^ (n⁻¹ : ℝ)) ^ n = x :=
have hn0 : (n : ℝ) ≠ 0, by simpa [nat.pos_iff_ne_zero] using hn,
by rw [← rpow_nat_cast, ← rpow_mul hx, inv_mul_cancel hn0, rpow_one]
section prove_rpow_is_continuous
lemma continuous_rpow_aux1 : continuous (λp : {p:ℝ×ℝ // 0 < p.1}, p.val.1 ^ p.val.2) :=
suffices h : continuous (λ p : {p:ℝ×ℝ // 0 < p.1 }, exp (log p.val.1 * p.val.2)),
by { convert h, ext p, rw rpow_def_of_pos p.2 },
continuous_exp.comp $
(show continuous ((λp:{p:ℝ//0 < p}, log (p.val)) ∘ (λp:{p:ℝ×ℝ//0<p.fst}, ⟨p.val.1, p.2⟩)), from
continuous_log'.comp $ continuous_subtype_mk _ $ continuous_fst.comp continuous_subtype_val).mul
(continuous_snd.comp $ continuous_subtype_val.comp continuous_id)
lemma continuous_rpow_aux2 : continuous (λ p : {p:ℝ×ℝ // p.1 < 0}, p.val.1 ^ p.val.2) :=
suffices h : continuous (λp:{p:ℝ×ℝ // p.1 < 0}, exp (log (-p.val.1) * p.val.2) * cos (p.val.2 * π)),
by { convert h, ext p, rw [rpow_def_of_neg p.2] },
(continuous_exp.comp $
(show continuous $ (λp:{p:ℝ//0<p},
log (p.val))∘(λp:{p:ℝ×ℝ//p.1<0}, ⟨-p.val.1, neg_pos_of_neg p.2⟩),
from continuous_log'.comp $ continuous_subtype_mk _ $ continuous_neg.comp $
continuous_fst.comp continuous_subtype_val).mul
(continuous_snd.comp $ continuous_subtype_val.comp continuous_id)).mul
(continuous_cos.comp $
(continuous_snd.comp $ continuous_subtype_val.comp continuous_id).mul continuous_const)
lemma continuous_at_rpow_of_ne_zero (hx : x ≠ 0) (y : ℝ) :
continuous_at (λp:ℝ×ℝ, p.1^p.2) (x, y) :=
begin
cases lt_trichotomy 0 x,
exact continuous_within_at.continuous_at
(continuous_on_iff_continuous_restrict.2 continuous_rpow_aux1 _ h)
(mem_nhds_sets (by { convert is_open_prod (is_open_lt' (0:ℝ)) is_open_univ, ext, finish }) h),
cases h,
{ exact absurd h.symm hx },
exact continuous_within_at.continuous_at
(continuous_on_iff_continuous_restrict.2 continuous_rpow_aux2 _ h)
(mem_nhds_sets (by { convert is_open_prod (is_open_gt' (0:ℝ)) is_open_univ, ext, finish }) h)
end
lemma continuous_rpow_aux3 : continuous (λ p : {p:ℝ×ℝ // 0 < p.2}, p.val.1 ^ p.val.2) :=
continuous_iff_continuous_at.2 $ λ ⟨(x₀, y₀), hy₀⟩,
begin
by_cases hx₀ : x₀ = 0,
{ simp only [continuous_at, hx₀, zero_rpow (ne_of_gt hy₀), tendsto_nhds_nhds], assume ε ε0,
rcases exists_pos_rat_lt (half_pos hy₀) with ⟨q, q_pos, q_lt⟩,
let q := (q:ℝ), replace q_pos : 0 < q := rat.cast_pos.2 q_pos,
let δ := min (min q (ε ^ (1 / q))) (1/2),
have δ0 : 0 < δ := lt_min (lt_min q_pos (rpow_pos_of_pos ε0 _)) (by norm_num),
have : δ ≤ q := le_trans (min_le_left _ _) (min_le_left _ _),
have : δ ≤ ε ^ (1 / q) := le_trans (min_le_left _ _) (min_le_right _ _),
have : δ < 1 := lt_of_le_of_lt (min_le_right _ _) (by norm_num),
use δ, use δ0, rintros ⟨⟨x, y⟩, hy⟩,
simp only [subtype.dist_eq, real.dist_eq, prod.dist_eq, sub_zero, subtype.coe_mk],
assume h, rw max_lt_iff at h, cases h with xδ yy₀,
have qy : q < y, calc q < y₀ / 2 : q_lt
... = y₀ - y₀ / 2 : (sub_half _).symm
... ≤ y₀ - δ : by linarith
... < y : sub_lt_of_abs_sub_lt_left yy₀,
calc abs(x^y) ≤ abs(x)^y : abs_rpow_le_abs_rpow _ _
... < δ ^ y : rpow_lt_rpow (abs_nonneg _) xδ hy
... < δ ^ q : by { refine rpow_lt_rpow_of_exponent_gt _ _ _, repeat {linarith} }
... ≤ (ε ^ (1 / q)) ^ q : by { refine rpow_le_rpow _ _ _, repeat {linarith} }
... = ε : by { rw [← rpow_mul, div_mul_cancel, rpow_one], exact ne_of_gt q_pos, linarith }},
{ exact (continuous_within_at_iff_continuous_at_restrict (λp:ℝ×ℝ, p.1^p.2) _).1
(continuous_at_rpow_of_ne_zero hx₀ _).continuous_within_at }
end
lemma continuous_at_rpow_of_pos (hy : 0 < y) (x : ℝ) :
continuous_at (λp:ℝ×ℝ, p.1^p.2) (x, y) :=
continuous_within_at.continuous_at
(continuous_on_iff_continuous_restrict.2 continuous_rpow_aux3 _ hy)
(mem_nhds_sets (by { convert is_open_prod is_open_univ (is_open_lt' (0:ℝ)), ext, finish }) hy)
lemma continuous_at_rpow {x y : ℝ} (h : x ≠ 0 ∨ 0 < y) :
continuous_at (λp:ℝ×ℝ, p.1^p.2) (x, y) :=
by { cases h, exact continuous_at_rpow_of_ne_zero h _, exact continuous_at_rpow_of_pos h x }
variables {α : Type*} [topological_space α] {f g : α → ℝ}
/--
`real.rpow` is continuous at all points except for the lower half of the y-axis.
In other words, the function `λp:ℝ×ℝ, p.1^p.2` is continuous at `(x, y)` if `x ≠ 0` or `y > 0`.
Multiple forms of the claim is provided in the current section.
-/
lemma continuous_rpow (h : ∀a, f a ≠ 0 ∨ 0 < g a) (hf : continuous f) (hg : continuous g):
continuous (λa:α, (f a) ^ (g a)) :=
continuous_iff_continuous_at.2 $ λ a,
begin
show continuous_at ((λp:ℝ×ℝ, p.1^p.2) ∘ (λa, (f a, g a))) a,
refine continuous_at.comp _ (continuous_iff_continuous_at.1 (hf.prod_mk hg) _),
{ replace h := h a, cases h,
{ exact continuous_at_rpow_of_ne_zero h _ },
{ exact continuous_at_rpow_of_pos h _ }},
end
lemma continuous_rpow_of_ne_zero (h : ∀a, f a ≠ 0) (hf : continuous f) (hg : continuous g):
continuous (λa:α, (f a) ^ (g a)) := continuous_rpow (λa, or.inl $ h a) hf hg
lemma continuous_rpow_of_pos (h : ∀a, 0 < g a) (hf : continuous f) (hg : continuous g):
continuous (λa:α, (f a) ^ (g a)) := continuous_rpow (λa, or.inr $ h a) hf hg
end prove_rpow_is_continuous
section sqrt
lemma sqrt_eq_rpow : sqrt = λx:ℝ, x ^ (1/(2:ℝ)) :=
begin
funext, by_cases h : 0 ≤ x,
{ rw [← mul_self_inj_of_nonneg, mul_self_sqrt h, ← pow_two, ← rpow_nat_cast, ← rpow_mul h],
norm_num, exact sqrt_nonneg _, exact rpow_nonneg_of_nonneg h _ },
{ replace h : x < 0 := lt_of_not_ge h,
have : 1 / (2:ℝ) * π = π / (2:ℝ), ring,
rw [sqrt_eq_zero_of_nonpos (le_of_lt h), rpow_def_of_neg h, this, cos_pi_div_two, mul_zero] }
end
lemma continuous_sqrt : continuous sqrt :=
by rw sqrt_eq_rpow; exact continuous_rpow_of_pos (λa, by norm_num) continuous_id continuous_const
end sqrt
section exp
/-- The real exponential function tends to +infinity at +infinity -/
lemma tendsto_exp_at_top : tendsto exp at_top at_top :=
begin
have A : tendsto (λx:ℝ, x + 1) at_top at_top :=
tendsto_at_top_add_const_right at_top 1 tendsto_id,
have B : ∀ᶠ x in at_top, x + 1 ≤ exp x,
{ have : ∀ᶠ (x : ℝ) in at_top, 0 ≤ x := mem_at_top 0,
filter_upwards [this],
exact λx hx, add_one_le_exp_of_nonneg hx },
exact tendsto_at_top_mono' at_top B A
end
/-- The real exponential function tends to 0 at -infinity or, equivalently, `exp(-x)` tends to `0`
at +infinity -/
lemma tendsto_exp_neg_at_top_nhds_0 : tendsto (λx, exp (-x)) at_top (𝓝 0) :=
(tendsto_inv_at_top_zero.comp (tendsto_exp_at_top)).congr (λx, (exp_neg x).symm)
/-- The function `exp(x)/x^n` tends to +infinity at +infinity, for any natural number `n` -/
lemma tendsto_exp_div_pow_at_top (n : ℕ) : tendsto (λx, exp x / x^n) at_top at_top :=
begin
have n_pos : (0 : ℝ) < n + 1 := nat.cast_add_one_pos n,
have n_ne_zero : (n : ℝ) + 1 ≠ 0 := ne_of_gt n_pos,
have A : ∀x:ℝ, 0 < x → exp (x / (n+1)) / (n+1)^n ≤ exp x / x^n,
{ assume x hx,
let y := x / (n+1),
have y_pos : 0 < y := div_pos hx n_pos,
have : exp (x / (n+1)) ≤ (n+1)^n * (exp x / x^n), from calc
exp y = exp y * 1 : by simp
... ≤ exp y * (exp y / y)^n : begin
apply mul_le_mul_of_nonneg_left (one_le_pow_of_one_le _ n) (le_of_lt (exp_pos _)),
apply one_le_div_of_le _ y_pos,
apply le_trans _ (add_one_le_exp_of_nonneg (le_of_lt y_pos)),
exact le_add_of_le_of_nonneg (le_refl _) (zero_le_one)
end
... = exp y * exp (n * y) / y^n :
by rw [div_pow, exp_nat_mul, mul_div_assoc]
... = exp ((n + 1) * y) / y^n :
by rw [← exp_add, add_mul, one_mul, add_comm]
... = exp x / (x / (n+1))^n :
by { dsimp [y], rw mul_div_cancel' _ n_ne_zero }
... = (n+1)^n * (exp x / x^n) :
by rw [← mul_div_assoc, div_pow, div_div_eq_mul_div, mul_comm],
rwa div_le_iff' (pow_pos n_pos n) },
have B : ∀ᶠ x in at_top, exp (x / (n+1)) / (n+1)^n ≤ exp x / x^n :=
mem_at_top_sets.2 ⟨1, λx hx, A _ (lt_of_lt_of_le zero_lt_one hx)⟩,
have C : tendsto (λx, exp (x / (n+1)) / (n+1)^n) at_top at_top :=
tendsto_at_top_div (pow_pos n_pos n)
(tendsto_exp_at_top.comp (tendsto_at_top_div (nat.cast_add_one_pos n) tendsto_id)),
exact tendsto_at_top_mono' at_top B C
end
/-- The function `x^n * exp(-x)` tends to `0` at +infinity, for any natural number `n`. -/
lemma tendsto_pow_mul_exp_neg_at_top_nhds_0 (n : ℕ) : tendsto (λx, x^n * exp (-x)) at_top (𝓝 0) :=
(tendsto_inv_at_top_zero.comp (tendsto_exp_div_pow_at_top n)).congr $ λx,
by rw [function.comp_app, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg]
end exp
end real
lemma has_deriv_at.rexp {f : ℝ → ℝ} {f' x : ℝ} (hf : has_deriv_at f f' x) :
has_deriv_at (real.exp ∘ f) (f' * real.exp (f x)) x :=
(real.has_deriv_at_exp (f x)).comp x hf
lemma has_deriv_within_at.rexp {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
(hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (real.exp ∘ f) (f' * real.exp (f x)) s x :=
(real.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf
namespace nnreal
/-- The nonnegative real power function `x^y`, defined for `x : nnreal` and `y : ℝ ` as the
restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`,
one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def rpow (x : nnreal) (y : ℝ) : nnreal :=
⟨(x : ℝ) ^ y, real.rpow_nonneg_of_nonneg x.2 y⟩
noncomputable instance : has_pow nnreal ℝ := ⟨rpow⟩
@[simp] lemma rpow_eq_pow (x : nnreal) (y : ℝ) : rpow x y = x ^ y := rfl
@[simp, move_cast] lemma coe_rpow (x : nnreal) (y : ℝ) : ((x ^ y : nnreal) : ℝ) = (x : ℝ) ^ y := rfl
@[simp] lemma rpow_zero (x : nnreal) : x ^ (0 : ℝ) = 1 :=
by { rw ← nnreal.coe_eq, exact real.rpow_zero _ }
@[simp] lemma rpow_eq_zero_iff {x : nnreal} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 :=
begin
rw [← nnreal.coe_eq, coe_rpow, ← nnreal.coe_eq_zero],
exact real.rpow_eq_zero_iff_of_nonneg x.2
end
@[simp] lemma zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : nnreal) ^ x = 0 :=
by { rw ← nnreal.coe_eq, exact real.zero_rpow h }
@[simp] lemma rpow_one (x : nnreal) : x ^ (1 : ℝ) = x :=
by { rw ← nnreal.coe_eq, exact real.rpow_one _ }
@[simp] lemma one_rpow (x : ℝ) : (1 : nnreal) ^ x = 1 :=
by { rw ← nnreal.coe_eq, exact real.one_rpow _ }
lemma rpow_add {x : nnreal} (y z : ℝ) (hx : 0 < x) : x ^ (y + z) = x ^ y * x ^ z :=
by { rw ← nnreal.coe_eq, exact real.rpow_add _ _ hx }
lemma rpow_mul (x : nnreal) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
by { rw ← nnreal.coe_eq, exact real.rpow_mul x.2 y z }
lemma rpow_neg (x : nnreal) (y : ℝ) : x ^ -y = (x ^ y)⁻¹ :=
by { rw ← nnreal.coe_eq, exact real.rpow_neg x.2 _ }
@[simp] lemma rpow_nat_cast (x : nnreal) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
by { rw [← nnreal.coe_eq, coe_pow], exact real.rpow_nat_cast (x : ℝ) n }
lemma mul_rpow {x y : nnreal} {z : ℝ} : (x*y)^z = x^z * y^z :=
by { rw ← nnreal.coe_eq, exact real.mul_rpow x.2 y.2 }
lemma one_le_rpow {x : nnreal} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x^z :=
real.one_le_rpow h h₁
lemma rpow_le_rpow {x y : nnreal} {z: ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x^z ≤ y^z :=
real.rpow_le_rpow x.2 h₁ h₂
lemma rpow_lt_rpow {x y : nnreal} {z: ℝ} (h₁ : x < y) (h₂ : 0 < z) : x^z < y^z :=
real.rpow_lt_rpow x.2 h₁ h₂
lemma rpow_lt_rpow_of_exponent_lt {x : nnreal} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x^y < x^z :=
real.rpow_lt_rpow_of_exponent_lt hx hyz
lemma rpow_le_rpow_of_exponent_le {x : nnreal} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x^y ≤ x^z :=
real.rpow_le_rpow_of_exponent_le hx hyz
lemma rpow_lt_rpow_of_exponent_gt {x : nnreal} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x^y < x^z :=
real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz
lemma rpow_le_rpow_of_exponent_ge {x : nnreal} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x^y ≤ x^z :=
real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz
lemma rpow_le_one {x : nnreal} {e : ℝ} (he : 0 ≤ e) (hx2 : x ≤ 1) : x^e ≤ 1 :=
real.rpow_le_one he x.2 hx2
lemma one_lt_rpow {x : nnreal} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=
real.one_lt_rpow hx hz
lemma rpow_lt_one {x : nnreal} {z : ℝ} (hx : 0 < x) (hx1 : x < 1) (hz : 0 < z) : x^z < 1 :=
real.rpow_lt_one hx hx1 hz
lemma pow_nat_rpow_nat_inv (x : nnreal) {n : ℕ} (hn : 0 < n) :
(x ^ n) ^ (n⁻¹ : ℝ) = x :=
by { rw [← nnreal.coe_eq, coe_rpow, coe_pow], exact real.pow_nat_rpow_nat_inv x.2 hn }
lemma rpow_nat_inv_pow_nat (x : nnreal) {n : ℕ} (hn : 0 < n) :
(x ^ (n⁻¹ : ℝ)) ^ n = x :=
by { rw [← nnreal.coe_eq, coe_pow, coe_rpow], exact real.rpow_nat_inv_pow_nat x.2 hn }
lemma continuous_at_rpow {x : nnreal} {y : ℝ} (h : x ≠ 0 ∨ 0 < y) :
continuous_at (λp:nnreal×ℝ, p.1^p.2) (x, y) :=
begin
have : (λp:nnreal×ℝ, p.1^p.2) = nnreal.of_real ∘ (λp:ℝ×ℝ, p.1^p.2) ∘ (λp:nnreal × ℝ, (p.1.1, p.2)),
{ ext p,
rw [← nnreal.coe_eq, coe_rpow, coe_of_real _ (real.rpow_nonneg_of_nonneg p.1.2 _)],
refl },
rw this,
refine continuous_of_real.continuous_at.comp (continuous_at.comp _ _),
{ apply real.continuous_at_rpow,
simp at h,
rw ← (nnreal.coe_eq_zero x) at h,
exact h },
{ exact ((continuous_subtype_val.comp continuous_fst).prod_mk continuous_snd).continuous_at }
end
end nnreal
lemma filter.tendsto.nnrpow {α : Type*} {f : filter α} {u : α → nnreal} {v : α → ℝ} {x : nnreal} {y : ℝ}
(hx : tendsto u f (𝓝 x)) (hy : tendsto v f (𝓝 y)) (h : x ≠ 0 ∨ 0 < y) :
tendsto (λ a, (u a) ^ (v a)) f (𝓝 (x ^ y)) :=
tendsto.comp (nnreal.continuous_at_rpow h) (tendsto.prod_mk_nhds hx hy)
|
25e7536bc536408d34cc2d6b4cc6e3598d487139 | b70031c8e2c5337b91d7e70f1e0c5f528f7b0e77 | /src/algebra/group/defs.lean | 946ae02af9911c17b8317d0927501ad69650502f | [
"Apache-2.0"
] | permissive | molodiuc/mathlib | cae2ba3ef1601c1f42ca0b625c79b061b63fef5b | 98ebe5a6739fbe254f9ee9d401882d4388f91035 | refs/heads/master | 1,674,237,127,059 | 1,606,353,533,000 | 1,606,353,533,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 14,222 | 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, Simon Hudon, Mario Carneiro
-/
import algebra.group.to_additive
import tactic.basic
/-!
# Typeclasses for (semi)groups and monoid
In this file we define typeclasses for algebraic structures with one binary operation.
The classes are named `(add_)?(comm_)?(semigroup|monoid|group)`, where `add_` means that
the class uses additive notation and `comm_` means that the class assumes that the binary
operation is commutative.
The file does not contain any lemmas except for
* axioms of typeclasses restated in the root namespace;
* lemmas required for instances.
For basic lemmas about these classes see `algebra.group.basic`.
-/
set_option old_structure_cmd true
universe u
/- Additive "sister" structures.
Example, add_semigroup mirrors semigroup.
These structures exist just to help automation.
In an alternative design, we could have the binary operation as an
extra argument for semigroup, monoid, group, etc. However, the lemmas
would be hard to index since they would not contain any constant.
For example, mul_assoc would be
lemma mul_assoc {α : Type u} {op : α → α → α} [semigroup α op] :
∀ a b c : α, op (op a b) c = op a (op b c) :=
semigroup.mul_assoc
The simplifier cannot effectively use this lemma since the pattern for
the left-hand-side would be
?op (?op ?a ?b) ?c
Remark: we use a tactic for transporting theorems from the multiplicative fragment
to the additive one.
-/
section has_mul
variables {G : Type u} [has_mul G]
/-- `left_mul g` denotes left multiplication by `g` -/
@[to_additive "`left_add g` denotes left addition by `g`"]
def left_mul : G → G → G := λ g : G, λ x : G, g * x
/-- `right_mul g` denotes right multiplication by `g` -/
@[to_additive "`right_add g` denotes right addition by `g`"]
def right_mul : G → G → G := λ g : G, λ x : G, x * g
end has_mul
/-- A semigroup is a type with an associative `(*)`. -/
@[protect_proj, ancestor has_mul] class semigroup (G : Type u) extends has_mul G :=
(mul_assoc : ∀ a b c : G, a * b * c = a * (b * c))
/-- An additive semigroup is a type with an associative `(+)`. -/
@[protect_proj, ancestor has_add] class add_semigroup (G : Type u) extends has_add G :=
(add_assoc : ∀ a b c : G, a + b + c = a + (b + c))
attribute [to_additive] semigroup
section semigroup
variables {G : Type u} [semigroup G]
@[no_rsimp, to_additive]
lemma mul_assoc : ∀ a b c : G, a * b * c = a * (b * c) :=
semigroup.mul_assoc
attribute [no_rsimp] add_assoc -- TODO(Mario): find out why this isn't copying
@[to_additive]
instance semigroup.to_is_associative : is_associative G (*) :=
⟨mul_assoc⟩
end semigroup
/-- A commutative semigroup is a type with an associative commutative `(*)`. -/
@[protect_proj, ancestor semigroup]
class comm_semigroup (G : Type u) extends semigroup G :=
(mul_comm : ∀ a b : G, a * b = b * a)
/-- A commutative additive semigroup is a type with an associative commutative `(+)`. -/
@[protect_proj, ancestor add_semigroup]
class add_comm_semigroup (G : Type u) extends add_semigroup G :=
(add_comm : ∀ a b : G, a + b = b + a)
attribute [to_additive] comm_semigroup
section comm_semigroup
variables {G : Type u} [comm_semigroup G]
@[no_rsimp, to_additive]
lemma mul_comm : ∀ a b : G, a * b = b * a :=
comm_semigroup.mul_comm
attribute [no_rsimp] add_comm
@[to_additive]
instance comm_semigroup.to_is_commutative : is_commutative G (*) :=
⟨mul_comm⟩
end comm_semigroup
/-- A `left_cancel_semigroup` is a semigroup such that `a * b = a * c` implies `b = c`. -/
@[protect_proj, ancestor semigroup]
class left_cancel_semigroup (G : Type u) extends semigroup G :=
(mul_left_cancel : ∀ a b c : G, a * b = a * c → b = c)
/-- An `add_left_cancel_semigroup` is an additive semigroup such that
`a + b = a + c` implies `b = c`. -/
@[protect_proj, ancestor add_semigroup]
class add_left_cancel_semigroup (G : Type u) extends add_semigroup G :=
(add_left_cancel : ∀ a b c : G, a + b = a + c → b = c)
attribute [to_additive add_left_cancel_semigroup] left_cancel_semigroup
section left_cancel_semigroup
variables {G : Type u} [left_cancel_semigroup G] {a b c : G}
@[to_additive]
lemma mul_left_cancel : a * b = a * c → b = c :=
left_cancel_semigroup.mul_left_cancel a b c
@[to_additive]
lemma mul_left_cancel_iff : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congr_arg _⟩
@[to_additive]
theorem mul_right_injective (a : G) : function.injective ((*) a) :=
λ b c, mul_left_cancel
@[simp, to_additive]
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congr_arg _⟩
end left_cancel_semigroup
/-- A `right_cancel_semigroup` is a semigroup such that `a * b = c * b` implies `a = c`. -/
@[protect_proj, ancestor semigroup]
class right_cancel_semigroup (G : Type u) extends semigroup G :=
(mul_right_cancel : ∀ a b c : G, a * b = c * b → a = c)
/-- An `add_right_cancel_semigroup` is an additive semigroup such that
`a + b = c + b` implies `a = c`. -/
@[protect_proj, ancestor add_semigroup]
class add_right_cancel_semigroup (G : Type u) extends add_semigroup G :=
(add_right_cancel : ∀ a b c : G, a + b = c + b → a = c)
attribute [to_additive add_right_cancel_semigroup] right_cancel_semigroup
section right_cancel_semigroup
variables {G : Type u} [right_cancel_semigroup G] {a b c : G}
@[to_additive]
lemma mul_right_cancel : a * b = c * b → a = c :=
right_cancel_semigroup.mul_right_cancel a b c
@[to_additive]
lemma mul_right_cancel_iff : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congr_arg _⟩
@[to_additive]
theorem mul_left_injective (a : G) : function.injective (λ x, x * a) :=
λ b c, mul_right_cancel
@[simp, to_additive]
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congr_arg _⟩
end right_cancel_semigroup
/-- A `monoid` is a `semigroup` with an element `1` such that `1 * a = a * 1 = a`. -/
@[ancestor semigroup has_one]
class monoid (M : Type u) extends semigroup M, has_one M :=
(one_mul : ∀ a : M, 1 * a = a) (mul_one : ∀ a : M, a * 1 = a)
/-- An `add_monoid` is an `add_semigroup` with an element `0` such that `0 + a = a + 0 = a`. -/
@[ancestor add_semigroup has_zero]
class add_monoid (M : Type u) extends add_semigroup M, has_zero M :=
(zero_add : ∀ a : M, 0 + a = a) (add_zero : ∀ a : M, a + 0 = a)
attribute [to_additive] monoid
section monoid
variables {M : Type u} [monoid M]
@[ematch, simp, to_additive]
lemma one_mul : ∀ a : M, 1 * a = a :=
monoid.one_mul
@[ematch, simp, to_additive]
lemma mul_one : ∀ a : M, a * 1 = a :=
monoid.mul_one
attribute [ematch] add_zero zero_add -- TODO(Mario): Make to_additive transfer this
@[to_additive]
instance monoid_to_is_left_id : is_left_id M (*) 1 :=
⟨ monoid.one_mul ⟩
@[to_additive]
instance monoid_to_is_right_id : is_right_id M (*) 1 :=
⟨ monoid.mul_one ⟩
@[to_additive]
lemma left_inv_eq_right_inv {a b c : M} (hba : b * a = 1) (hac : a * c = 1) : b = c :=
by rw [←one_mul c, ←hba, mul_assoc, hac, mul_one b]
end monoid
/-- A commutative monoid is a monoid with commutative `(*)`. -/
@[protect_proj, ancestor monoid comm_semigroup]
class comm_monoid (M : Type u) extends monoid M, comm_semigroup M
/-- An additive commutative monoid is an additive monoid with commutative `(+)`. -/
@[protect_proj, ancestor add_monoid add_comm_semigroup]
class add_comm_monoid (M : Type u) extends add_monoid M, add_comm_semigroup M
attribute [to_additive] comm_monoid
section left_cancel_monoid
/-- An additive monoid in which addition is left-cancellative.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `add_left_cancel_semigroup` is not enough. -/
@[protect_proj, ancestor add_left_cancel_semigroup add_monoid]
class add_left_cancel_monoid (M : Type u) extends add_left_cancel_semigroup M, add_monoid M
-- TODO: I found 1 (one) lemma assuming `[add_left_cancel_monoid]`.
-- Should we port more lemmas to this typeclass?
/-- A monoid in which multiplication is left-cancellative. -/
@[protect_proj, ancestor left_cancel_semigroup monoid, to_additive add_left_cancel_monoid]
class left_cancel_monoid (M : Type u) extends left_cancel_semigroup M, monoid M
/-- Commutative version of add_left_cancel_monoid. -/
@[protect_proj, ancestor add_left_cancel_monoid add_comm_monoid]
class add_left_cancel_comm_monoid (M : Type u) extends add_left_cancel_monoid M, add_comm_monoid M
/-- Commutative version of left_cancel_monoid. -/
@[protect_proj, ancestor left_cancel_monoid comm_monoid, to_additive add_left_cancel_comm_monoid]
class left_cancel_comm_monoid (M : Type u) extends left_cancel_monoid M, comm_monoid M
end left_cancel_monoid
section right_cancel_monoid
/-- An additive monoid in which addition is right-cancellative.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/
@[protect_proj, ancestor add_right_cancel_semigroup add_monoid]
class add_right_cancel_monoid (M : Type u) extends add_right_cancel_semigroup M, add_monoid M
/-- A monoid in which multiplication is right-cancellative. -/
@[protect_proj, ancestor right_cancel_semigroup monoid, to_additive add_right_cancel_monoid]
class right_cancel_monoid (M : Type u) extends right_cancel_semigroup M, monoid M
/-- Commutative version of add_right_cancel_monoid. -/
@[protect_proj, ancestor add_right_cancel_monoid add_comm_monoid]
class add_right_cancel_comm_monoid (M : Type u) extends add_right_cancel_monoid M, add_comm_monoid M
/-- Commutative version of right_cancel_monoid. -/
@[protect_proj, ancestor right_cancel_monoid comm_monoid, to_additive add_right_cancel_comm_monoid]
class right_cancel_comm_monoid (M : Type u) extends right_cancel_monoid M, comm_monoid M
end right_cancel_monoid
section cancel_monoid
/-- An additive monoid in which addition is cancellative on both sides.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/
@[protect_proj, ancestor add_left_cancel_monoid add_right_cancel_monoid]
class add_cancel_monoid (M : Type u)
extends add_left_cancel_monoid M, add_right_cancel_monoid M
/-- A monoid in which multiplication is cancellative. -/
@[protect_proj, ancestor left_cancel_monoid right_cancel_monoid, to_additive add_cancel_monoid]
class cancel_monoid (M : Type u) extends left_cancel_monoid M, right_cancel_monoid M
/-- Commutative version of add_cancel_monoid. -/
@[protect_proj, ancestor add_left_cancel_comm_monoid add_right_cancel_comm_monoid]
class add_cancel_comm_monoid (M : Type u)
extends add_left_cancel_comm_monoid M, add_right_cancel_comm_monoid M
/-- Commutative version of cancel_monoid. -/
@[protect_proj, ancestor right_cancel_comm_monoid left_cancel_comm_monoid, to_additive add_cancel_comm_monoid]
class cancel_comm_monoid (M : Type u) extends left_cancel_comm_monoid M, right_cancel_comm_monoid M
end cancel_monoid
/-- A `group` is a `monoid` with an operation `⁻¹` satisfying `a⁻¹ * a = 1`. -/
@[protect_proj, ancestor monoid has_inv]
class group (α : Type u) extends monoid α, has_inv α :=
(mul_left_inv : ∀ a : α, a⁻¹ * a = 1)
/-- An `add_group` is an `add_monoid` with a unary `-` satisfying `-a + a = 0`. -/
@[protect_proj, ancestor add_monoid has_neg]
class add_group (α : Type u) extends add_monoid α, has_neg α :=
(add_left_neg : ∀ a : α, -a + a = 0)
attribute [to_additive] group
section group
variables {G : Type u} [group G] {a b c : G}
@[simp, to_additive]
lemma mul_left_inv : ∀ a : G, a⁻¹ * a = 1 :=
group.mul_left_inv
@[to_additive] lemma inv_mul_self (a : G) : a⁻¹ * a = 1 := mul_left_inv a
@[simp, to_additive]
lemma inv_mul_cancel_left (a b : G) : a⁻¹ * (a * b) = b :=
by rw [← mul_assoc, mul_left_inv, one_mul]
@[simp, to_additive]
lemma inv_eq_of_mul_eq_one (h : a * b = 1) : a⁻¹ = b :=
left_inv_eq_right_inv (inv_mul_self a) h
@[simp, to_additive]
lemma inv_inv (a : G) : (a⁻¹)⁻¹ = a :=
inv_eq_of_mul_eq_one (mul_left_inv a)
@[simp, to_additive]
lemma mul_right_inv (a : G) : a * a⁻¹ = 1 :=
have a⁻¹⁻¹ * a⁻¹ = 1 := mul_left_inv a⁻¹,
by rwa [inv_inv] at this
@[to_additive] lemma mul_inv_self (a : G) : a * a⁻¹ = 1 := mul_right_inv a
@[simp, to_additive]
lemma mul_inv_cancel_right (a b : G) : a * b * b⁻¹ = a :=
by rw [mul_assoc, mul_right_inv, mul_one]
@[priority 100, to_additive] -- see Note [lower instance priority]
instance group.to_cancel_monoid : cancel_monoid G :=
{ mul_right_cancel := λ a b c h, by rw [← mul_inv_cancel_right a b, h, mul_inv_cancel_right],
mul_left_cancel := λ a b c h, by rw [← inv_mul_cancel_left a b, h, inv_mul_cancel_left],
..‹group G› }
end group
section add_group
variables {G : Type u} [add_group G]
/-- The subtraction operation on an `add_group` -/
@[reducible] protected def algebra.sub (a b : G) : G :=
a + -b
@[priority 100] -- see Note [lower instance priority]
instance add_group_has_sub : has_sub G :=
⟨algebra.sub⟩
lemma sub_eq_add_neg (a b : G) : a - b = a + -b :=
rfl
end add_group
/-- A commutative group is a group with commutative `(*)`. -/
@[protect_proj, ancestor group comm_monoid]
class comm_group (G : Type u) extends group G, comm_monoid G
/-- An additive commutative group is an additive group with commutative `(+)`. -/
@[protect_proj, ancestor add_group add_comm_monoid]
class add_comm_group (G : Type u) extends add_group G, add_comm_monoid G
attribute [to_additive] comm_group
attribute [instance, priority 300] add_comm_group.to_add_comm_monoid
section comm_group
variables {G : Type u} [comm_group G]
@[priority 100, to_additive] -- see Note [lower instance priority]
instance comm_group.to_cancel_comm_monoid : cancel_comm_monoid G :=
{ ..‹comm_group G›,
..group.to_cancel_monoid }
end comm_group
|
17c7b6e1a357ef4ccde7cbf8352d7def1f3dc1c0 | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/run/auto_param2.lean | 415002fe1e0fdcaaf7f47a333fb564752bcb6f7d | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 618 | lean | open tactic
meta def my_tac : tactic unit :=
assumption <|> abstract (comp_val >> skip) <|> fail "my_tac failed to synthesize auto_param"
def f (x : nat) (h : x > 0 . my_tac) : nat :=
nat.pred x
check f 12
check f 13
lemma f_inj {x₁ x₂ : nat} {h₁ : x₁ > 0} {h₂ : x₂ > 0} : f x₁ = f x₂ → x₁ = x₂ :=
begin
unfold f, intro h,
cases x₁,
exact absurd h₁ (lt_irrefl _),
cases x₂,
exact absurd h₂ (lt_irrefl _),
apply congr_arg nat.succ,
assumption
end
check @f_inj
lemma f_def {x : nat} (h : x > 0) : f x = nat.pred x :=
rfl
-- The following is an error
-- check λ x, f x
|
739a19a35ddc797586b43d65b5e269b5447b5204 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /tests/lean/substlet.lean | 3a90761d2d544ee49b50b357f4bbe14844519a08 | [
"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 | 526 | lean | theorem ex1 (n : Nat) : 0 + n = n := by
let m := n
have h : ∃ k, id k = m := ⟨m, rfl⟩
cases h with
| intro a e =>
traceState
subst e
traceState
apply Nat.zero_add
theorem ex2 (n : Nat) : 0 + n = n := by
let m := n
have h : ∃ k, m = id k := ⟨m, rfl⟩
cases h with
| intro a e =>
traceState
subst e
traceState
apply Nat.zero_add
theorem ex3 (n : Nat) (h : n = 0) : 0 + n = 0 := by
let m := n + 1
let v := m + 1
have : v = n + 2 := rfl
subst v -- error
done
|
66451382e7f4e608ade8e988df568181d424c931 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/meta/rb_map_auto.lean | dd27e27bc71f42eb6d44980c8792100c84f4f10c | [] | 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 | 443 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.ordering.basic
import Mathlib.Lean3Lib.init.function
import Mathlib.Lean3Lib.init.meta.name
import Mathlib.Lean3Lib.init.meta.format
import Mathlib.Lean3Lib.init.control.monad
namespace Mathlib
end Mathlib |
7517b3daaefedc550c9ba49497e2f74c77b27f37 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/field_theory/is_alg_closed/basic.lean | 9b4b51071aed6d12b973ae210556800035464d86 | [
"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 | 19,390 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import field_theory.splitting_field
import field_theory.perfect_closure
import field_theory.separable
/-!
# Algebraically Closed Field
In this file we define the typeclass for algebraically closed fields and algebraic closures,
and prove some of their properties.
## Main Definitions
- `is_alg_closed k` is the typeclass saying `k` is an algebraically closed field, i.e. every
polynomial in `k` splits.
- `is_alg_closure R K` is the typeclass saying `K` is an algebraic closure of `R`, where `R` is a
commutative ring. This means that the map from `R` to `K` is injective, and `K` is
algebraically closed and algebraic over `R`
- `is_alg_closed.lift` is a map from an algebraic extension `L` of `R`, into any algebraically
closed extension of `R`.
- `is_alg_closure.equiv` is a proof that any two algebraic closures of the
same field are isomorphic.
## Tags
algebraic closure, algebraically closed
-/
universes u v w
open_locale classical big_operators polynomial
open polynomial
variables (k : Type u) [field k]
/-- Typeclass for algebraically closed fields.
To show `polynomial.splits p f` for an arbitrary ring homomorphism `f`,
see `is_alg_closed.splits_codomain` and `is_alg_closed.splits_domain`.
-/
class is_alg_closed : Prop :=
(splits : ∀ p : k[X], p.splits $ ring_hom.id k)
/-- Every polynomial splits in the field extension `f : K →+* k` if `k` is algebraically closed.
See also `is_alg_closed.splits_domain` for the case where `K` is algebraically closed.
-/
theorem is_alg_closed.splits_codomain {k K : Type*} [field k] [is_alg_closed k] [field K]
{f : K →+* k} (p : K[X]) : p.splits f :=
by { convert is_alg_closed.splits (p.map f), simp [splits_map_iff] }
/-- Every polynomial splits in the field extension `f : K →+* k` if `K` is algebraically closed.
See also `is_alg_closed.splits_codomain` for the case where `k` is algebraically closed.
-/
theorem is_alg_closed.splits_domain {k K : Type*} [field k] [is_alg_closed k] [field K]
{f : k →+* K} (p : k[X]) : p.splits f :=
polynomial.splits_of_splits_id _ $ is_alg_closed.splits _
namespace is_alg_closed
variables {k}
theorem exists_root [is_alg_closed k] (p : k[X]) (hp : p.degree ≠ 0) : ∃ x, is_root p x :=
exists_root_of_splits _ (is_alg_closed.splits p) hp
lemma exists_pow_nat_eq [is_alg_closed k] (x : k) {n : ℕ} (hn : 0 < n) : ∃ z, z ^ n = x :=
begin
rcases exists_root (X ^ n - C x) _ with ⟨z, hz⟩, swap,
{ rw degree_X_pow_sub_C hn x,
exact ne_of_gt (with_bot.coe_lt_coe.2 hn) },
use z,
simp only [eval_C, eval_X, eval_pow, eval_sub, is_root.def] at hz,
exact sub_eq_zero.1 hz
end
lemma exists_eq_mul_self [is_alg_closed k] (x : k) : ∃ z, x = z * z :=
begin
rcases exists_pow_nat_eq x zero_lt_two with ⟨z, rfl⟩,
exact ⟨z, sq z⟩
end
lemma roots_eq_zero_iff [is_alg_closed k] {p : k[X]} :
p.roots = 0 ↔ p = polynomial.C (p.coeff 0) :=
begin
refine ⟨λ h, _, λ hp, by rw [hp, roots_C]⟩,
cases (le_or_lt (degree p) 0) with hd hd,
{ exact eq_C_of_degree_le_zero hd },
{ obtain ⟨z, hz⟩ := is_alg_closed.exists_root p hd.ne',
rw [←mem_roots (ne_zero_of_degree_gt hd), h] at hz,
simpa using hz }
end
theorem exists_eval₂_eq_zero_of_injective {R : Type*} [ring R] [is_alg_closed k] (f : R →+* k)
(hf : function.injective f) (p : R[X]) (hp : p.degree ≠ 0) : ∃ x, p.eval₂ f x = 0 :=
let ⟨x, hx⟩ := exists_root (p.map f) (by rwa [degree_map_eq_of_injective hf]) in
⟨x, by rwa [eval₂_eq_eval_map, ← is_root]⟩
theorem exists_eval₂_eq_zero {R : Type*} [field R] [is_alg_closed k] (f : R →+* k)
(p : R[X]) (hp : p.degree ≠ 0) : ∃ x, p.eval₂ f x = 0 :=
exists_eval₂_eq_zero_of_injective f f.injective p hp
variables (k)
theorem exists_aeval_eq_zero_of_injective {R : Type*} [comm_ring R] [is_alg_closed k] [algebra R k]
(hinj : function.injective (algebra_map R k)) (p : R[X]) (hp : p.degree ≠ 0) :
∃ x : k, aeval x p = 0 :=
exists_eval₂_eq_zero_of_injective (algebra_map R k) hinj p hp
theorem exists_aeval_eq_zero {R : Type*} [field R] [is_alg_closed k] [algebra R k]
(p : R[X]) (hp : p.degree ≠ 0) : ∃ x : k, aeval x p = 0 :=
exists_eval₂_eq_zero (algebra_map R k) p hp
theorem of_exists_root (H : ∀ p : k[X], p.monic → irreducible p → ∃ x, p.eval x = 0) :
is_alg_closed k :=
⟨λ p, or.inr $ λ q hq hqp,
have irreducible (q * C (leading_coeff q)⁻¹),
by { rw ← coe_norm_unit_of_ne_zero hq.ne_zero,
exact (associated_normalize _).irreducible hq },
let ⟨x, hx⟩ := H (q * C (leading_coeff q)⁻¹) (monic_mul_leading_coeff_inv hq.ne_zero) this in
degree_mul_leading_coeff_inv q hq.ne_zero ▸ degree_eq_one_of_irreducible_of_root this hx⟩
lemma degree_eq_one_of_irreducible [is_alg_closed k] {p : k[X]}
(hp : irreducible p) :
p.degree = 1 :=
degree_eq_one_of_irreducible_of_splits hp (is_alg_closed.splits_codomain _)
lemma algebra_map_surjective_of_is_integral {k K : Type*} [field k] [ring K] [is_domain K]
[hk : is_alg_closed k] [algebra k K] (hf : algebra.is_integral k K) :
function.surjective (algebra_map k K) :=
begin
refine λ x, ⟨-((minpoly k x).coeff 0), _⟩,
have hq : (minpoly k x).leading_coeff = 1 := minpoly.monic (hf x),
have h : (minpoly k x).degree = 1 := degree_eq_one_of_irreducible k
(minpoly.irreducible (hf x)),
have : (aeval x (minpoly k x)) = 0 := minpoly.aeval k x,
rw [eq_X_add_C_of_degree_eq_one h, hq, C_1, one_mul,
aeval_add, aeval_X, aeval_C, add_eq_zero_iff_eq_neg] at this,
exact (ring_hom.map_neg (algebra_map k K) ((minpoly k x).coeff 0)).symm ▸ this.symm,
end
lemma algebra_map_surjective_of_is_integral'
{k K : Type*} [field k] [comm_ring K] [is_domain K]
[hk : is_alg_closed k] (f : k →+* K) (hf : f.is_integral) : function.surjective f :=
@algebra_map_surjective_of_is_integral k K _ _ _ _ f.to_algebra hf
lemma algebra_map_surjective_of_is_algebraic {k K : Type*} [field k] [ring K] [is_domain K]
[hk : is_alg_closed k] [algebra k K] (hf : algebra.is_algebraic k K) :
function.surjective (algebra_map k K) :=
algebra_map_surjective_of_is_integral (algebra.is_algebraic_iff_is_integral.mp hf)
end is_alg_closed
/-- Typeclass for an extension being an algebraic closure. -/
class is_alg_closure (R : Type u) (K : Type v) [comm_ring R]
[field K] [algebra R K] [no_zero_smul_divisors R K] : Prop :=
(alg_closed : is_alg_closed K)
(algebraic : algebra.is_algebraic R K)
theorem is_alg_closure_iff (K : Type v) [field K] [algebra k K] :
is_alg_closure k K ↔ is_alg_closed K ∧ algebra.is_algebraic k K :=
⟨λ h, ⟨h.1, h.2⟩, λ h, ⟨h.1, h.2⟩⟩
namespace lift
/- In this section, the homomorphism from any algebraic extension into an algebraically
closed extension is proven to exist. The assumption that M is algebraically closed could probably
easily be switched to an assumption that M contains all the roots of polynomials in K -/
variables {K : Type u} {L : Type v} {M : Type w} [field K] [field L] [algebra K L]
[field M] [algebra K M] [is_alg_closed M] (hL : algebra.is_algebraic K L)
variables (K L M)
include hL
open subalgebra alg_hom function
/-- This structure is used to prove the existence of a homomorphism from any algebraic extension
into an algebraic closure -/
structure subfield_with_hom :=
(carrier : subalgebra K L)
(emb : carrier →ₐ[K] M)
variables {K L M hL}
namespace subfield_with_hom
variables {E₁ E₂ E₃ : subfield_with_hom K L M hL}
instance : has_le (subfield_with_hom K L M hL) :=
{ le := λ E₁ E₂, ∃ h : E₁.carrier ≤ E₂.carrier, ∀ x, E₂.emb (inclusion h x) = E₁.emb x }
noncomputable instance : inhabited (subfield_with_hom K L M hL) :=
⟨{ carrier := ⊥,
emb := (algebra.of_id K M).comp (algebra.bot_equiv K L).to_alg_hom }⟩
lemma le_def : E₁ ≤ E₂ ↔ ∃ h : E₁.carrier ≤ E₂.carrier, ∀ x, E₂.emb (inclusion h x) = E₁.emb x :=
iff.rfl
lemma compat (h : E₁ ≤ E₂) : ∀ x, E₂.emb (inclusion h.fst x) = E₁.emb x :=
by { rw le_def at h, cases h, assumption }
instance : preorder (subfield_with_hom K L M hL) :=
{ le := (≤),
le_refl := λ E, ⟨le_rfl, by simp⟩,
le_trans := λ E₁ E₂ E₃ h₁₂ h₂₃,
⟨le_trans h₁₂.fst h₂₃.fst,
λ _, by erw [← inclusion_inclusion h₁₂.fst h₂₃.fst, compat, compat]⟩ }
open lattice
lemma maximal_subfield_with_hom_chain_bounded (c : set (subfield_with_hom K L M hL))
(hc : is_chain (≤) c) :
∃ ub : subfield_with_hom K L M hL, ∀ N, N ∈ c → N ≤ ub :=
if hcn : c.nonempty then
let ub : subfield_with_hom K L M hL :=
by haveI : nonempty c := set.nonempty.to_subtype hcn; exact
{ carrier := ⨆ i : c, (i : subfield_with_hom K L M hL).carrier,
emb := subalgebra.supr_lift
(λ i : c, (i : subfield_with_hom K L M hL).carrier)
(λ i j, let ⟨k, hik, hjk⟩ := directed_on_iff_directed.1 hc.directed_on i j in
⟨k, hik.fst, hjk.fst⟩)
(λ i, (i : subfield_with_hom K L M hL).emb)
begin
assume i j h,
ext x,
cases hc.total i.prop j.prop with hij hji,
{ simp [← hij.snd x] },
{ erw [alg_hom.comp_apply, ← hji.snd (inclusion h x),
inclusion_inclusion, inclusion_self, alg_hom.id_apply x] }
end _ rfl } in
⟨ub, λ N hN, ⟨(le_supr (λ i : c, (i : subfield_with_hom K L M hL).carrier) ⟨N, hN⟩ : _),
begin
intro x,
simp [ub],
refl
end⟩⟩
else by { rw [set.not_nonempty_iff_eq_empty] at hcn, simp [hcn], }
variables (hL M)
lemma exists_maximal_subfield_with_hom : ∃ E : subfield_with_hom K L M hL,
∀ N, E ≤ N → N ≤ E :=
exists_maximal_of_chains_bounded
maximal_subfield_with_hom_chain_bounded (λ _ _ _, le_trans)
/-- The maximal `subfield_with_hom`. We later prove that this is equal to `⊤`. -/
noncomputable def maximal_subfield_with_hom : subfield_with_hom K L M hL :=
classical.some (exists_maximal_subfield_with_hom M hL)
lemma maximal_subfield_with_hom_is_maximal :
∀ (N : subfield_with_hom K L M hL),
(maximal_subfield_with_hom M hL) ≤ N → N ≤ (maximal_subfield_with_hom M hL) :=
classical.some_spec (exists_maximal_subfield_with_hom M hL)
lemma maximal_subfield_with_hom_eq_top :
(maximal_subfield_with_hom M hL).carrier = ⊤ :=
begin
rw [eq_top_iff],
intros x _,
let p := minpoly K x,
let N : subalgebra K L := (maximal_subfield_with_hom M hL).carrier,
letI : field N := (subalgebra.is_field_of_algebraic N hL).to_field,
letI : algebra N M := (maximal_subfield_with_hom M hL).emb.to_ring_hom.to_algebra,
cases is_alg_closed.exists_aeval_eq_zero M (minpoly N x)
(ne_of_gt (minpoly.degree_pos
(is_algebraic_iff_is_integral.1
(algebra.is_algebraic_of_larger_base _ _ hL x)))) with y hy,
let O : subalgebra N L := algebra.adjoin N {(x : L)},
let larger_emb := ((adjoin_root.lift_hom (minpoly N x) y hy).comp
(alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly N x).to_alg_hom),
have hNO : N ≤ O.restrict_scalars K,
{ intros z hz,
show algebra_map N L ⟨z, hz⟩ ∈ O,
exact O.algebra_map_mem _ },
let O' : subfield_with_hom K L M hL :=
{ carrier := O.restrict_scalars K,
emb := larger_emb.restrict_scalars K },
have hO' : maximal_subfield_with_hom M hL ≤ O',
{ refine ⟨hNO, _⟩,
intros z,
show O'.emb (algebra_map N O z) = algebra_map N M z,
simp only [O', restrict_scalars_apply, alg_hom.commutes] },
refine (maximal_subfield_with_hom_is_maximal M hL O' hO').fst _,
exact algebra.subset_adjoin (set.mem_singleton x),
end
end subfield_with_hom
end lift
namespace is_alg_closed
variables {K : Type u} [field K] {L : Type v} {M : Type w} [field L] [algebra K L]
[field M] [algebra K M] [is_alg_closed M] (hL : algebra.is_algebraic K L)
variables (K L M)
include hL
/-- Less general version of `lift`. -/
@[irreducible] private noncomputable def lift_aux : L →ₐ[K] M :=
(lift.subfield_with_hom.maximal_subfield_with_hom M hL).emb.comp $
eq.rec_on (lift.subfield_with_hom.maximal_subfield_with_hom_eq_top M hL).symm algebra.to_top
omit hL
variables {R : Type u} [comm_ring R]
variables {S : Type v} [comm_ring S] [is_domain S] [algebra R S]
[algebra R M] [no_zero_smul_divisors R S]
[no_zero_smul_divisors R M]
(hS : algebra.is_algebraic R S)
variables {M}
include hS
private lemma fraction_ring.is_algebraic :
by letI : is_domain R := (no_zero_smul_divisors.algebra_map_injective R S).is_domain _; exact
algebra.is_algebraic (fraction_ring R) (fraction_ring S) :=
begin
introsI inst x,
exact (is_fraction_ring.is_algebraic_iff R (fraction_ring R) (fraction_ring S)).1
((is_fraction_ring.is_algebraic_iff' R S (fraction_ring S)).1 hS x)
end
/-- A (random) homomorphism from an algebraic extension of R into an algebraically
closed extension of R. -/
@[irreducible] noncomputable def lift : S →ₐ[R] M :=
begin
letI : is_domain R := (no_zero_smul_divisors.algebra_map_injective R S).is_domain _,
have hfRfS : algebra.is_algebraic (fraction_ring R) (fraction_ring S) :=
fraction_ring.is_algebraic hS,
let f : fraction_ring S →ₐ[fraction_ring R] M :=
lift_aux (fraction_ring R) (fraction_ring S) M hfRfS,
exact (f.restrict_scalars R).comp ((algebra.of_id S (fraction_ring S)).restrict_scalars R),
end
omit hS
@[priority 100]
noncomputable instance perfect_ring (p : ℕ) [fact p.prime] [char_p k p]
[is_alg_closed k] : perfect_ring k p :=
perfect_ring.of_surjective k p $ λ x, is_alg_closed.exists_pow_nat_eq _ $ fact.out _
/-- Algebraically closed fields are infinite since `Xⁿ⁺¹ - 1` is separable when `#K = n` -/
@[priority 500]
instance {K : Type*} [field K] [is_alg_closed K] : infinite K :=
begin
apply infinite.mk,
introsI hfin,
set n := fintype.card K with hn,
set f := (X : K[X]) ^ (n + 1) - 1 with hf,
have hfsep : separable f := separable_X_pow_sub_C 1 (by simp) one_ne_zero,
apply nat.not_succ_le_self (fintype.card K),
have hroot : n.succ = fintype.card (f.root_set K),
{ erw [card_root_set_eq_nat_degree hfsep (is_alg_closed.splits_domain _),
nat_degree_X_pow_sub_C] },
rw hroot,
exact fintype.card_le_of_injective coe subtype.coe_injective,
end
end is_alg_closed
namespace is_alg_closure
variables (K : Type*) (J : Type*) (R : Type u) (S : Type*) [field K] [field J] [comm_ring R]
(L : Type v) (M : Type w) [field L] [field M] [algebra R M] [no_zero_smul_divisors R M]
[is_alg_closure R M] [algebra K M] [is_alg_closure K M]
[comm_ring S] [algebra S L] [no_zero_smul_divisors S L] [is_alg_closure S L]
local attribute [instance] is_alg_closure.alg_closed
section
variables [algebra R L] [no_zero_smul_divisors R L] [is_alg_closure R L]
/-- A (random) isomorphism between two algebraic closures of `R`. -/
noncomputable def equiv : L ≃ₐ[R] M :=
let f : L →ₐ[R] M := is_alg_closed.lift is_alg_closure.algebraic in
alg_equiv.of_bijective f
⟨ring_hom.injective f.to_ring_hom,
begin
letI : algebra L M := ring_hom.to_algebra f,
letI : is_scalar_tower R L M :=
is_scalar_tower.of_algebra_map_eq (by simp [ring_hom.algebra_map_to_algebra]),
show function.surjective (algebra_map L M),
exact is_alg_closed.algebra_map_surjective_of_is_algebraic
(algebra.is_algebraic_of_larger_base_of_injective
(no_zero_smul_divisors.algebra_map_injective R _) is_alg_closure.algebraic),
end⟩
end
section equiv_of_algebraic
variables [algebra R S] [algebra R L] [is_scalar_tower R S L]
variables [algebra K J] [algebra J L] [is_alg_closure J L] [algebra K L]
[is_scalar_tower K J L]
/-- A (random) isomorphism between an algebraic closure of `R` and an algebraic closure of
an algebraic extension of `R` -/
noncomputable def equiv_of_algebraic' [nontrivial S] [no_zero_smul_divisors R S]
(hRL : algebra.is_algebraic R L) : L ≃ₐ[R] M :=
begin
letI : no_zero_smul_divisors R L :=
no_zero_smul_divisors.of_algebra_map_injective begin
rw [is_scalar_tower.algebra_map_eq R S L],
exact function.injective.comp
(no_zero_smul_divisors.algebra_map_injective _ _)
(no_zero_smul_divisors.algebra_map_injective _ _)
end,
letI : is_alg_closure R L :=
{ alg_closed := by apply_instance,
algebraic := hRL },
exact is_alg_closure.equiv _ _ _
end
/-- A (random) isomorphism between an algebraic closure of `K` and an algebraic closure
of an algebraic extension of `K` -/
noncomputable def equiv_of_algebraic (hKJ : algebra.is_algebraic K J) : L ≃ₐ[K] M :=
equiv_of_algebraic' K J _ _ (algebra.is_algebraic_trans hKJ is_alg_closure.algebraic)
end equiv_of_algebraic
section equiv_of_equiv
variables {R S}
/-- Used in the definition of `equiv_of_equiv` -/
noncomputable def equiv_of_equiv_aux (hSR : S ≃+* R) :
{ e : L ≃+* M // e.to_ring_hom.comp (algebra_map S L) =
(algebra_map R M).comp hSR.to_ring_hom }:=
begin
letI : algebra R S := ring_hom.to_algebra hSR.symm.to_ring_hom,
letI : algebra S R := ring_hom.to_algebra hSR.to_ring_hom,
letI : is_domain R := (no_zero_smul_divisors.algebra_map_injective R M).is_domain _,
letI : is_domain S := (no_zero_smul_divisors.algebra_map_injective S L).is_domain _,
have : algebra.is_algebraic R S,
from λ x, begin
rw [← ring_equiv.symm_apply_apply hSR x],
exact is_algebraic_algebra_map _
end,
letI : algebra R L := ring_hom.to_algebra ((algebra_map S L).comp (algebra_map R S)),
haveI : is_scalar_tower R S L := is_scalar_tower.of_algebra_map_eq (λ _, rfl),
haveI : is_scalar_tower S R L := is_scalar_tower.of_algebra_map_eq
(by simp [ring_hom.algebra_map_to_algebra]),
haveI : no_zero_smul_divisors R S :=
no_zero_smul_divisors.of_algebra_map_injective hSR.symm.injective,
refine ⟨equiv_of_algebraic' R S L M (algebra.is_algebraic_of_larger_base_of_injective
(show function.injective (algebra_map S R), from hSR.injective)
is_alg_closure.algebraic) , _⟩,
ext,
simp only [ring_equiv.to_ring_hom_eq_coe, function.comp_app, ring_hom.coe_comp,
alg_equiv.coe_ring_equiv, ring_equiv.coe_to_ring_hom],
conv_lhs { rw [← hSR.symm_apply_apply x] },
show equiv_of_algebraic' R S L M _ (algebra_map R L (hSR x)) = _,
rw [alg_equiv.commutes]
end
/-- Algebraic closure of isomorphic fields are isomorphic -/
noncomputable def equiv_of_equiv (hSR : S ≃+* R) : L ≃+* M :=
equiv_of_equiv_aux L M hSR
@[simp] lemma equiv_of_equiv_comp_algebra_map (hSR : S ≃+* R) :
(↑(equiv_of_equiv L M hSR) : L →+* M).comp (algebra_map S L) =
(algebra_map R M).comp hSR :=
(equiv_of_equiv_aux L M hSR).2
@[simp] lemma equiv_of_equiv_algebra_map (hSR : S ≃+* R) (s : S):
equiv_of_equiv L M hSR (algebra_map S L s) =
algebra_map R M (hSR s) :=
ring_hom.ext_iff.1 (equiv_of_equiv_comp_algebra_map L M hSR) s
@[simp] lemma equiv_of_equiv_symm_algebra_map (hSR : S ≃+* R) (r : R):
(equiv_of_equiv L M hSR).symm (algebra_map R M r) =
algebra_map S L (hSR.symm r) :=
(equiv_of_equiv L M hSR).injective (by simp)
@[simp] lemma equiv_of_equiv_symm_comp_algebra_map (hSR : S ≃+* R) :
((equiv_of_equiv L M hSR).symm : M →+* L).comp (algebra_map R M) =
(algebra_map S L).comp hSR.symm :=
ring_hom.ext_iff.2 (equiv_of_equiv_symm_algebra_map L M hSR)
end equiv_of_equiv
end is_alg_closure
|
15cd2b4d6ec7e0f959f9c53dd1f8b790699211ad | 7fc0ec5c526f706107537a6e2e34ac4cdf88d232 | /src/group_theory/representation/basic.lean | 46d16d2ee0f0ddc578ad31acbe3de27666741c06 | [
"Apache-2.0"
] | permissive | fpvandoorn/group-representations | 7440a81f2ac9e0d2defa44dc1643c3167f7a2d99 | bd9d72311749187d3bd4f542d5eab83e8341856c | refs/heads/master | 1,684,128,141,684 | 1,623,338,135,000 | 1,623,338,135,000 | 256,117,709 | 0 | 2 | null | null | null | null | UTF-8 | Lean | false | false | 16,927 | lean | /- Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Douglas, Floris van Doorn
-/
import linear_algebra.finite_dimensional linear_algebra.bilinear_form
import data.fintype.card tactic.apply_fun
import misc
universe variables u v w w' w''
open linear_map
variables {G : Type u} {R : Type v} {M : Type w} {M' : Type w'} {M'' : Type w''}
[group G] [comm_ring R] [add_comm_group M] [module R M] [add_comm_group M'] [module R M']
[add_comm_group M''] [module R M''] {N N' : submodule R M}
{K : Type v} [field K] {V : Type w} [add_comm_group V] [vector_space K V]
namespace submodule
/- module facts -/
lemma eq_bot_iff' (N : submodule R M) : N = ⊥ ↔ ∀ x : M, x ∈ N → x = 0 :=
begin
rw [eq_bot_iff], split,
{ intros h x hx, simpa using h hx },
{ intros h x hx, simp [h x hx] }
end
@[simp] lemma range_coprod (f : M →ₗ[R] M'') (g : M' →ₗ[R] M'') :
(f.coprod g).range = f.range ⊔ g.range :=
begin
unfold linear_map.range,
convert map_coprod_prod _ _ _ _,
rw prod_top,
end
lemma mem_sup_left {p p' : submodule R M} {x : M} (h : x ∈ p) : x ∈ p ⊔ p' :=
by { have : p ≤ p ⊔ p' := le_sup_left, exact this h }
lemma mem_sup_right {p p' : submodule R M} {x : M} (h : x ∈ p') : x ∈ p ⊔ p' :=
by { have : p' ≤ p ⊔ p' := le_sup_right, exact this h }
/-- A projection is an idempotent linear map -/
@[reducible] def is_projection (π : M →ₗ[R] M) : Prop := ∀ x, π (π x) = π x
-- def is_projection_on (N : submodule R M) (π : M →ₗ[R] M): Prop := ∀ x : N, π x = x ∧ range π ≤ N
-- lemma projections (N : submodule R M) (π : M →ₗ[R] M) : is_projection_on N π → is_projection π :=
-- sorry
/-- Two elements in a lattice are complementary if they have meet ⊥ and join ⊤. -/
def complementary {α} [bounded_lattice α] (x x' : α) : Prop :=
covering x x' ∧ disjoint x x'
lemma complementary.comm {α} [bounded_lattice α] {x x' : α} :
complementary x x' ↔ complementary x' x :=
by { dsimp [complementary], rw [covering.comm, disjoint.comm] }
namespace complementary
/-- Given two complementary submodules `N` and `N'` of an `R`-module `M`, we get a linear equivalence from `N × N'` to `M` by adding the elements of `N` and `N'`. -/
protected noncomputable def linear_equiv (h : complementary N N') :
(N × N') ≃ₗ[R] M := -- default precendences are wrong
begin
apply linear_equiv.of_bijective (N.subtype.coprod N'.subtype),
{ refine (eq_bot_iff' _).mpr _, rintro ⟨⟨x, hx⟩, ⟨x', hx'⟩⟩ hxx',
simp only [mem_ker, subtype_apply, submodule.coe_mk, coprod_apply] at hxx',
have : x = 0,
{ apply disjoint_def.mp h.2 x hx,
rw [← eq_neg_iff_add_eq_zero] at hxx', rw hxx', exact neg_mem _ hx' },
subst this, rw [zero_add] at hxx', subst hxx', refl },
{ simp only [range_coprod, range_subtype, h.1.eq_top] }
end
/-- Given two complementary submodules `N` and `N'` of an `R`-module `M`, the projection onto `N` along `N'`. -/
protected noncomputable def pr1 (h : complementary N N') :
M →ₗ[R] M :=
N.subtype.comp $ (fst R N N').comp h.linear_equiv.symm
lemma pr1_mem (h : complementary N N') (x : M) :
h.pr1 x ∈ N :=
(fst R N N' $ h.linear_equiv.symm x).2
/-- Given two complementary submodules `N` and `N'` of an `R`-module `M`, the projection onto `N'` along `N`. -/
protected noncomputable def pr2 (h : complementary N N') :
M →ₗ[R] M :=
N'.subtype.comp $ (snd R N N').comp h.linear_equiv.symm
lemma pr2_mem (h : complementary N N') (x : M) :
h.pr2 x ∈ N' :=
(snd R N N' $ h.linear_equiv.symm x).2
@[simp] lemma pr1_add_pr2 (h : complementary N N') (x : M) :
h.pr1 x + h.pr2 x = x :=
h.linear_equiv.right_inv x
lemma pr1_eq_and_pr2_eq (h : complementary N N') {x y z : M}
(hx : x ∈ N) (hy : y ∈ N') (hz : z = x + y) : h.pr1 z = x ∧ h.pr2 z = y :=
begin
subst z, have h2 := h.linear_equiv.left_inv (⟨x, hx⟩, ⟨y, hy⟩),
simp only [prod.ext_iff, subtype.ext] at h2, exact h2
end
lemma pr1_pr1 (h : complementary N N') (x : M) :
h.pr1 (h.pr1 x) = h.pr1 x :=
(h.pr1_eq_and_pr2_eq (h.pr1_mem x) (zero_mem _) (by rw add_zero)).1
lemma pr2_pr2 (h : complementary N N') (x : M) :
h.pr2 (h.pr2 x) = h.pr2 x :=
(h.pr1_eq_and_pr2_eq (zero_mem _) (h.pr2_mem x) (by rw zero_add)).2
lemma range_pr1 (h : complementary N N') : range h.pr1 = N :=
by simp [complementary.pr1, range_comp]
lemma range_pr2 (h : complementary N N') : range h.pr2 = N' :=
by simp [complementary.pr2, range_comp]
end complementary
lemma complementary_ker_range {π : M →ₗ[R] M} (hp : is_projection π) :
complementary (ker π) (range π) :=
begin
unfold is_projection at hp, split,
{ rw [covering_iff, eq_top_iff'], intro x, rw mem_sup, use (linear_map.id - π) x,
split, { simp [hp] },
use π x, simp only [and_true, sub_apply, sub_add_cancel, mem_range, eq_self_iff_true, id_apply],
use x },
{ intros, rw [disjoint_def], simp only [and_imp, mem_ker, mem_range, mem_inf, exists_imp_distrib],
intros x hx x' hx', have h2x' := hx', apply_fun π at hx', simp [hp, hx] at hx', cc }
end
-- instance general_linear_group.coe : has_coe (general_linear_group R M) (M →ₗ[R] M) := ⟨λ x, x.1⟩
end submodule
open submodule
section subspace
noncomputable example (s : set V) (hs1 : is_basis K (subtype.val : s → V))
(hs2 : s.finite) (f : V → K) : K :=
begin let sfin := hs2.to_finset, exact sfin.sum f,
end
/- finding a complementary subspace -/
/-- The set of subspaces disjoint from N (which means they only have 0 in common) -/
def disjoint_subspaces (N : subspace K V) : set (subspace K V) :=
{ N' | disjoint N N' }
lemma mem_disjoint_subspaces {N M : subspace K V} : M ∈ disjoint_subspaces N ↔
∀ x : V, x ∈ N → x ∈ M → x = 0 :=
disjoint_def
instance (N : subspace K V) : nonempty (disjoint_subspaces N) :=
⟨⟨⊥, disjoint_bot_right⟩⟩
theorem exists_maximal_disjoint_subspaces (N : subspace K V) :
∃ Nmax : disjoint_subspaces N, ∀N, Nmax ≤ N → N = Nmax :=
begin
apply zorn.zorn_partial_order_nonempty,
intros c hc h0c, refine ⟨⟨Sup (subtype.val '' c), _⟩, _⟩,
{ rw [mem_disjoint_subspaces],
intros x h1x h2x, rw [mem_Sup_of_directed] at h2x,
{ rcases h2x with ⟨_, ⟨⟨y, h0y⟩, h1y, rfl⟩, h2y⟩,
rw [mem_disjoint_subspaces] at h0y, exact h0y x h1x h2y },
{ simp only [set.nonempty_image_iff, h0c] },
{ rw directed_on_image, exact hc.directed_on }},
{ intros N hN, change N.1 ≤ Sup (subtype.val '' c), refine le_Sup _, simp [hN] }
end
theorem exists_complementary_subspace (N : subspace K V) :
∃ N' : subspace K V, complementary N N' :=
begin
rcases exists_maximal_disjoint_subspaces N with ⟨⟨N', h1N'⟩, h2N'⟩,
use N',
refine ⟨_, h1N'⟩,
classical,
rw [covering_iff, eq_top_iff'], intro x, by_contra H,
have : disjoint N (N' ⊔ span K {x}),
{ rw disjoint_def, intros y h1y h2y, rw mem_sup at h2y,
rcases h2y with ⟨z, hz, w, hw, rfl⟩,
rw mem_span_singleton at hw, rcases hw with ⟨r, rfl⟩,
by_cases hr : r = 0,
{ subst hr, rw [zero_smul, add_zero] at h1y ⊢, apply mem_disjoint_subspaces.1 h1N' _ h1y hz },
{ exfalso, apply H,
rw [← smul_mem_iff _ hr],
rw [← add_mem_iff_right _ (mem_sup_right hz)],
apply mem_sup_left h1y }},
have : N' ⊔ span K {x} = N',
{ have := h2N' ⟨_, this⟩ _, rwa [subtype.mk_eq_mk] at this, rw subtype.le_def, exact le_sup_left },
apply H, apply mem_sup_right, rw ←this, apply mem_sup_right, apply subset_span,
apply set.mem_singleton
end
end subspace
/-- A representation of a group `G` on an `R`-module `M` is a group homomorphism from `G` to
`GL(M)`. Normally `M` is a vector space, but we don't need that for the definition. -/
@[derive inhabited] def group_representation (G R M : Type*) [group G] [ring R] [add_comm_group M]
[module R M] : Type* :=
G →* M →ₗ[R] M
variables {ρ : group_representation G R M} {π : M →ₗ[R] M}
instance : has_coe_to_fun (group_representation G R M) := ⟨_, λ f, f.to_fun⟩
/-- A submodule `N` is invariant under a representation `ρ` if `ρ g` maps `N` into `N` for all `g`. -/
def submodule.invariant_under (ρ : group_representation G R M) (N : submodule R M) : Prop :=
∀ x ∈ N, ∀ g : G, ρ g x ∈ N
open submodule
namespace group_representation
/-- An equivalence between two group representations. -/
protected structure equiv (ρ : group_representation G R M) (ρ' : group_representation G R M') :
Type (max w w') :=
(α : M ≃ₗ[R] M')
(commute : ∀(g : G), α ∘ ρ g = ρ' g ∘ α)
--structure subrepresentation (ρ : group_representation G R M) (π : group_representation G R M') :
-- Type (max w w') :=
--(α : M →ₗ[R] M')
--(commute : ∀(g : G), α ∘ ρ g = π g ∘ α)
--left_inv := λ m, show (f.inv * f.val) m = m
/-- An `R`-module `M` is irreducible if every invariant submodule is either `⊥` or `⊤`. -/
def irreducible (ρ : group_representation G R M) : Prop :=
∀ N : submodule R M, N.invariant_under ρ → N = ⊥ ∨ N = ⊤
/- Maschke's theorem -/
/-- A function is equivariant if it commutes with `ρ g` for all `g : G`. -/
def is_equivariant (ρ : group_representation G R M) (π : M →ₗ[R] M) : Prop :=
∀ g : G, ∀ x : M, π (ρ g x) = ρ g (π x)
/-- The invariant projector modifies a projector `π` to be equivariant. -/
def invariant_multiple_of_projector [fintype G] (ρ : group_representation G R M) (π : M →ₗ[R] M) : M →ₗ[R] M :=
finset.univ.sum (λ g : G, ((ρ g⁻¹).comp π).comp (ρ g))
-- lemma invariant_multiple_of_projector_is_scalar_on [fintype G] (r : R) (ρ : group_representation G R M) (π : M →ₗ[R] M)
-- {N : submodule R M} (hR : N.invariant_under ρ) (hp : is_projection_on N π) :
-- ∀ x : N, invariant_multiple_of_projector ρ π x = r • x :=
-- begin dunfold invariant_multiple_of_projector, intro,
-- suffices : ∀ g : G, (comp (comp (ρ g⁻¹) π) (ρ g)) ↑x = r • ↑x,
-- { sorry },
-- unfold is_projection_on at hp,
-- unfold invariant_under at hR,
-- simp, intro, sorry -- simp [(hp ↥N ((ρ g) x)).1, hR x],
-- end
noncomputable def invariant_projector [fintype G] (hG : is_unit (fintype.card G : R)) (ρ : group_representation G R M) (π : M →ₗ[R] M) : M →ₗ[R] M :=
begin
let invr := is_unit_iff_exists_inv.1 hG,
exact (classical.some invr) • invariant_multiple_of_projector ρ π
end
-- /-- `π` is a multiple `r` times a projection. -/
-- def is_multiple_of_projection (π : M →ₗ[R] M) (r : R) : Prop := ∀ x, π (π x) = r • π x
-- lemma is_multiple_of_projection_invariant_multiple_of_projector [fintype G] (ρ : group_representation G R M)
-- (π : M →ₗ[R] M) : is_multiple_of_projection (invariant_multiple_of_projector ρ π) (fintype.card G) :=
-- begin sorry
-- end
lemma is_invariant_ker (h : is_equivariant ρ π) : (ker π).invariant_under ρ :=
by { rintros x hx g, rw [mem_ker, h g x, mem_ker.mp hx, linear_map.map_zero] }
lemma sum_apply {α} (s : finset α) (f : α → M →ₗ[R] M) (m : M) :
s.sum f m = s.sum (λ x, f x m) :=
begin
classical,
refine finset.induction _ _ s,
{ refl },
{ intros x s hx h_ind,
have : finset.sum (insert x s) f = f x + finset.sum s f := by simp [hx],
rw this, simp [hx, h_ind] }
end
lemma is_equivariant_invariant_projector [fintype G] (hG : is_unit (fintype.card G : R)) (ρ : group_representation G R M)
(π : M →ₗ[R] M) : is_equivariant ρ (invariant_projector hG ρ π) :=
begin intros g1 x, dunfold invariant_projector, dsimp, rw linear_map.map_smul, congr' 1,
dunfold invariant_multiple_of_projector, simp [sum_apply],
apply finset.sum_bij (λ g _, g * g1),
{ intros, apply finset.mem_univ },
{ intros, dsimp, rw [ ρ.map_mul ],
suffices : (ρ a⁻¹) (π ((ρ a) ((ρ g1) x))) = (ρ (g1 * (a * g1)⁻¹) (π ((ρ a * ρ g1) x))),
{ rw this, rw ρ.map_mul, refl },
apply congr_fun, congr, simp [mul_inv] },
{ intros g g' _ _ h, simpa using h },
{ intros, use b * g1⁻¹, simp }
end
lemma submodule_comap_smul (f : M →ₗ[R] M) (p : submodule R M) (r : R) (h : is_unit r) :
p.comap (r • f) = p.comap f :=
begin
let ur := (classical.some h),
have : r = (ur : R) := (classical.some_spec h).symm,
ext b; simp only [submodule.mem_comap, linear_map.smul_apply, this, p.smul_mem_iff' ur],
end
lemma submodule_map_smul (f : M →ₗ[R] M) (p : submodule R M) (r : R) (h : is_unit r) :
p.map (r • f) = p.map f :=
le_antisymm
begin rw [map_le_iff_le_comap, submodule_comap_smul f _ r h, ← map_le_iff_le_comap], exact le_refl _ end
begin rw [map_le_iff_le_comap, ← submodule_comap_smul f _ r h, ← map_le_iff_le_comap], exact le_refl _ end
lemma range_smul (f : M →ₗ[R] M) (r : R) (h : is_unit r) : range (r • f) = range f :=
begin exact submodule_map_smul f _ r h
end
lemma invariant_multiple_of_projector_on_range [fintype G] (ρ : group_representation G R M)
(π : M →ₗ[R] M) (hp : is_projection π) (hR : (range π).invariant_under ρ) {x : M} (h1 : x ∈ range π) :
invariant_multiple_of_projector ρ π x = (fintype.card G : R) • x :=
begin
dunfold invariant_multiple_of_projector, rw sum_apply,
convert finset.sum_const x, ext g, dsimp, {
have h2 : (ρ g) x ∈ range π := by { apply hR, exact h1 },
rw mem_range at h2,
cases h2 with y h3,
rw [← h3, hp y, h3],
suffices : (ρ (g⁻¹ * g)) x = x,
{ rw [ρ.map_mul] at this, exact this },
rw [mul_left_inv, ρ.map_one], refl },
rw finset.card_univ, symmetry, apply semimodule.smul_eq_smul
end
lemma invariant_projector_on_range [fintype G] (hG : is_unit (fintype.card G : R))
(ρ : group_representation G R M)
(π : M →ₗ[R] M) (hp : is_projection π) (hR : (range π).invariant_under ρ) {x : M} (h1 : x ∈ range π) :
invariant_projector hG ρ π x = x :=
begin
dunfold invariant_projector, dsimp,
rw [invariant_multiple_of_projector_on_range ρ π hp hR h1],
rw [← mul_smul, mul_comm, classical.some_spec (is_unit_iff_exists_inv.1 hG), one_smul],
end
lemma range_invariant_projector [fintype G] (hG : is_unit (fintype.card G : R)) (ρ : group_representation G R M)
(π : M →ₗ[R] M) (hp : is_projection π) (hR : (range π).invariant_under ρ) :
range (invariant_projector hG ρ π) = range π :=
begin unfold invariant_projector,
let invr := classical.some(is_unit_iff_exists_inv.1 hG),
have h_invr : (fintype.card G : R) * invr = 1 :=
classical.some_spec (is_unit_iff_exists_inv.1 hG),
rw [range_smul _ invr],
ext x, split,
{ rintro ⟨x,hx,rfl⟩, dunfold invariant_multiple_of_projector, rw sum_apply, apply sum_mem, intros, dsimp, apply hR, rw mem_range, exact ⟨_, rfl⟩ },
{ intro hx,
let x' := invr • π x,
use x', use trivial,
have h1 : x' ∈ range π := by { apply smul_mem, rw mem_range, exact ⟨_, rfl⟩ },
rw [invariant_multiple_of_projector_on_range ρ π hp hR h1],
simp only [x'], rw [← mul_smul, h_invr, one_smul], rcases hx with ⟨x, hx, rfl⟩, rw hp x },
{ apply is_unit_iff_exists_inv'.mpr, exact ⟨_, h_invr⟩ }
end
lemma is_projection_invariant_projector [fintype G] (hG : is_unit (fintype.card G : R))
(ρ : group_representation G R M) (π : M →ₗ[R] M) (hp : is_projection π)
(hR : (range π).invariant_under ρ) : is_projection (invariant_projector hG ρ π) :=
begin
intro x,
have : (invariant_projector hG ρ π) x ∈ range (invariant_projector hG ρ π),
{ rw mem_range, exact ⟨_, rfl⟩ },
rw [range_invariant_projector hG ρ π hp hR] at this,
rw [invariant_projector_on_range hG ρ π hp hR this]
end
theorem maschke [fintype G] (ρ : group_representation G R M) (N N' : submodule R M)
(h : complementary N N') (hN : N.invariant_under ρ) (hG : is_unit (fintype.card G : R)) :
∃ N' : submodule R M, N'.invariant_under ρ ∧ complementary N N' :=
begin
let π := invariant_projector hG ρ h.pr1, use ker π,
use is_invariant_ker (is_equivariant_invariant_projector hG ρ h.pr1),
suffices hR : (range (complementary.pr1 h)).invariant_under ρ,
rw [complementary.comm, ← h.range_pr1, ← range_invariant_projector hG ρ h.pr1 h.pr1_pr1 hR],
convert complementary_ker_range (is_projection_invariant_projector hG ρ h.pr1 h.pr1_pr1 hR),
rw complementary.range_pr1, exact hN
end
end group_representation
/- from [https://github.com/Shenyang1995/M4R/blob/66f1450f206dc05c3093bc4eaa1361309bf8633b/src/G_module/basic.lean#L10-L14].
Do we want to use this definition instead? This might allow us to write `g • x` instead of `ρ g x` -/
class G_module (G : Type*) [group G] (M : Type*) [add_comm_group M]
extends has_scalar G M :=
(id : ∀ m : M, (1 : G) • m = m)
(mul : ∀ g h : G, ∀ m : M, g • (h • m) = (g * h) • m)
(linear : ∀ g : G, ∀ m n : M, g • (m + n) = g • m + g • n)
|
603894503658dbbe2b0bb48996863e4b6ab2d37e | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/group/conj.lean | 6912b20fa5912ef12a58bab95b1b45416af566a9 | [
"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 | 10,064 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Chris Hughes, Michael Howes
-/
import algebra.group.semiconj
import algebra.group_with_zero.basic
import algebra.hom.aut
import algebra.hom.group
/-!
# Conjugacy of group elements
See also `mul_aut.conj` and `quandle.conj`.
-/
universes u v
variables {α : Type u} {β : Type v}
section monoid
variables [monoid α] [monoid β]
/-- We say that `a` is conjugate to `b` if for some unit `c` we have `c * a * c⁻¹ = b`. -/
def is_conj (a b : α) := ∃ c : αˣ, semiconj_by ↑c a b
@[refl] lemma is_conj.refl (a : α) : is_conj a a :=
⟨1, semiconj_by.one_left a⟩
@[symm] lemma is_conj.symm {a b : α} : is_conj a b → is_conj b a
| ⟨c, hc⟩ := ⟨c⁻¹, hc.units_inv_symm_left⟩
lemma is_conj_comm {g h : α} : is_conj g h ↔ is_conj h g :=
⟨is_conj.symm, is_conj.symm⟩
@[trans] lemma is_conj.trans {a b c : α} : is_conj a b → is_conj b c → is_conj a c
| ⟨c₁, hc₁⟩ ⟨c₂, hc₂⟩ := ⟨c₂ * c₁, hc₂.mul_left hc₁⟩
@[simp] lemma is_conj_iff_eq {α : Type*} [comm_monoid α] {a b : α} : is_conj a b ↔ a = b :=
⟨λ ⟨c, hc⟩, begin
rw [semiconj_by, mul_comm, ← units.mul_inv_eq_iff_eq_mul, mul_assoc, c.mul_inv, mul_one] at hc,
exact hc,
end, λ h, by rw h⟩
protected lemma monoid_hom.map_is_conj (f : α →* β) {a b : α} : is_conj a b → is_conj (f a) (f b)
| ⟨c, hc⟩ := ⟨units.map f c, by rw [units.coe_map, semiconj_by, ← f.map_mul, hc.eq, f.map_mul]⟩
end monoid
section cancel_monoid
variables [cancel_monoid α]
-- These lemmas hold for `right_cancel_monoid` with the current proofs, but for the sake of
-- not duplicating code (these lemmas also hold for `left_cancel_monoids`) we leave these
-- not generalised.
@[simp] lemma is_conj_one_right {a : α} : is_conj 1 a ↔ a = 1 :=
⟨λ ⟨c, hc⟩, mul_right_cancel (hc.symm.trans ((mul_one _).trans (one_mul _).symm)), λ h, by rw [h]⟩
@[simp] lemma is_conj_one_left {a : α} : is_conj a 1 ↔ a = 1 :=
calc is_conj a 1 ↔ is_conj 1 a : ⟨is_conj.symm, is_conj.symm⟩
... ↔ a = 1 : is_conj_one_right
end cancel_monoid
section group
variables [group α]
@[simp] lemma is_conj_iff {a b : α} :
is_conj a b ↔ ∃ c : α, c * a * c⁻¹ = b :=
⟨λ ⟨c, hc⟩, ⟨c, mul_inv_eq_iff_eq_mul.2 hc⟩, λ ⟨c, hc⟩,
⟨⟨c, c⁻¹, mul_inv_self c, inv_mul_self c⟩, mul_inv_eq_iff_eq_mul.1 hc⟩⟩
@[simp] lemma conj_inv {a b : α} : (b * a * b⁻¹)⁻¹ = b * a⁻¹ * b⁻¹ :=
((mul_aut.conj b).map_inv a).symm
@[simp] lemma conj_mul {a b c : α} : (b * a * b⁻¹) * (b * c * b⁻¹) = b * (a * c) * b⁻¹ :=
((mul_aut.conj b).map_mul a c).symm
@[simp] lemma conj_pow {i : ℕ} {a b : α} : (a * b * a⁻¹) ^ i = a * (b ^ i) * a⁻¹ :=
begin
induction i with i hi,
{ simp },
{ simp [pow_succ, hi] }
end
@[simp] lemma conj_zpow {i : ℤ} {a b : α} : (a * b * a⁻¹) ^ i = a * (b ^ i) * a⁻¹ :=
begin
induction i,
{ simp },
{ simp [zpow_neg_succ_of_nat, conj_pow] }
end
lemma conj_injective {x : α} : function.injective (λ (g : α), x * g * x⁻¹) :=
(mul_aut.conj x).injective
end group
@[simp] lemma is_conj_iff₀ [group_with_zero α] {a b : α} :
is_conj a b ↔ ∃ c : α, c ≠ 0 ∧ c * a * c⁻¹ = b :=
⟨λ ⟨c, hc⟩, ⟨c, begin
rw [← units.coe_inv, units.mul_inv_eq_iff_eq_mul],
exact ⟨c.ne_zero, hc⟩,
end⟩, λ ⟨c, c0, hc⟩,
⟨units.mk0 c c0, begin
rw [semiconj_by, ← units.mul_inv_eq_iff_eq_mul, units.coe_inv, units.coe_mk0],
exact hc
end⟩⟩
namespace is_conj
/- This small quotient API is largely copied from the API of `associates`;
where possible, try to keep them in sync -/
/-- The setoid of the relation `is_conj` iff there is a unit `u` such that `u * x = y * u` -/
protected def setoid (α : Type*) [monoid α] : setoid α :=
{ r := is_conj, iseqv := ⟨is_conj.refl, λa b, is_conj.symm, λa b c, is_conj.trans⟩ }
end is_conj
local attribute [instance, priority 100] is_conj.setoid
/-- The quotient type of conjugacy classes of a group. -/
def conj_classes (α : Type*) [monoid α] : Type* :=
quotient (is_conj.setoid α)
namespace conj_classes
section monoid
variables [monoid α] [monoid β]
/-- The canonical quotient map from a monoid `α` into the `conj_classes` of `α` -/
protected def mk {α : Type*} [monoid α] (a : α) : conj_classes α :=
⟦a⟧
instance : inhabited (conj_classes α) := ⟨⟦1⟧⟩
theorem mk_eq_mk_iff_is_conj {a b : α} :
conj_classes.mk a = conj_classes.mk b ↔ is_conj a b :=
iff.intro quotient.exact quot.sound
theorem quotient_mk_eq_mk (a : α) : ⟦ a ⟧ = conj_classes.mk a := rfl
theorem quot_mk_eq_mk (a : α) : quot.mk setoid.r a = conj_classes.mk a := rfl
theorem forall_is_conj {p : conj_classes α → Prop} :
(∀a, p a) ↔ (∀a, p (conj_classes.mk a)) :=
iff.intro
(assume h a, h _)
(assume h a, quotient.induction_on a h)
theorem mk_surjective : function.surjective (@conj_classes.mk α _) :=
forall_is_conj.2 (λ a, ⟨a, rfl⟩)
instance : has_one (conj_classes α) := ⟨⟦ 1 ⟧⟩
theorem one_eq_mk_one : (1 : conj_classes α) = conj_classes.mk 1 := rfl
lemma exists_rep (a : conj_classes α) : ∃ a0 : α, conj_classes.mk a0 = a :=
quot.exists_rep a
/-- A `monoid_hom` maps conjugacy classes of one group to conjugacy classes of another. -/
def map (f : α →* β) : conj_classes α → conj_classes β :=
quotient.lift (conj_classes.mk ∘ f) (λ a b ab, mk_eq_mk_iff_is_conj.2 (f.map_is_conj ab))
lemma map_surjective {f : α →* β} (hf : function.surjective f) :
function.surjective (conj_classes.map f) :=
begin
intros b,
obtain ⟨b, rfl⟩ := conj_classes.mk_surjective b,
obtain ⟨a, rfl⟩ := hf b,
exact ⟨conj_classes.mk a, rfl⟩,
end
/--
Certain instances trigger further searches when they are considered as candidate instances;
these instances should be assigned a priority lower than the default of 1000 (for example, 900).
The conditions for this rule are as follows:
* a class `C` has instances `instT : C T` and `instT' : C T'`
* types `T` and `T'` are both specializations of another type `S`
* the parameters supplied to `S` to produce `T` are not (fully) determined by `instT`,
instead they have to be found by instance search
If those conditions hold, the instance `instT` should be assigned lower priority.
For example, suppose the search for an instance of `decidable_eq (multiset α)` tries the
candidate instance `con.quotient.decidable_eq (c : con M) : decidable_eq c.quotient`.
Since `multiset` and `con.quotient` are both quotient types, unification will check
that the relations `list.perm` and `c.to_setoid.r` unify. However, `c.to_setoid` depends on
a `has_mul M` instance, so this unification triggers a search for `has_mul (list α)`;
this will traverse all subclasses of `has_mul` before failing.
On the other hand, the search for an instance of `decidable_eq (con.quotient c)` for `c : con M`
can quickly reject the candidate instance `multiset.has_decidable_eq` because the type of
`list.perm : list ?m_1 → list ?m_1 → Prop` does not unify with `M → M → Prop`.
Therefore, we should assign `con.quotient.decidable_eq` a lower priority because it fails slowly.
(In terms of the rules above, `C := decidable_eq`, `T := con.quotient`,
`instT := con.quotient.decidable_eq`, `T' := multiset`, `instT' := multiset.has_decidable_eq`,
and `S := quot`.)
If the type involved is a free variable (rather than an instantiation of some type `S`),
the instance priority should be even lower, see Note [lower instance priority].
-/
library_note "slow-failing instance priority"
@[priority 900] -- see Note [slow-failing instance priority]
instance [decidable_rel (is_conj : α → α → Prop)] : decidable_eq (conj_classes α) :=
quotient.decidable_eq
end monoid
section comm_monoid
variable [comm_monoid α]
lemma mk_injective : function.injective (@conj_classes.mk α _) :=
λ _ _, (mk_eq_mk_iff_is_conj.trans is_conj_iff_eq).1
lemma mk_bijective : function.bijective (@conj_classes.mk α _) :=
⟨mk_injective, mk_surjective⟩
/-- The bijection between a `comm_group` and its `conj_classes`. -/
def mk_equiv : α ≃ conj_classes α :=
⟨conj_classes.mk, quotient.lift id (λ (a : α) b, is_conj_iff_eq.1), quotient.lift_mk _ _,
begin
rw [function.right_inverse, function.left_inverse, forall_is_conj],
intro x,
rw [← quotient_mk_eq_mk, ← quotient_mk_eq_mk, quotient.lift_mk, id.def],
end⟩
end comm_monoid
end conj_classes
section monoid
variables [monoid α]
/-- Given an element `a`, `conjugates a` is the set of conjugates. -/
def conjugates_of (a : α) : set α := {b | is_conj a b}
lemma mem_conjugates_of_self {a : α} : a ∈ conjugates_of a := is_conj.refl _
lemma is_conj.conjugates_of_eq {a b : α} (ab : is_conj a b) :
conjugates_of a = conjugates_of b :=
set.ext (λ g, ⟨λ ag, (ab.symm).trans ag, λ bg, ab.trans bg⟩)
lemma is_conj_iff_conjugates_of_eq {a b : α} :
is_conj a b ↔ conjugates_of a = conjugates_of b :=
⟨is_conj.conjugates_of_eq, λ h, begin
have ha := mem_conjugates_of_self,
rwa ← h at ha,
end⟩
end monoid
namespace conj_classes
variables [monoid α]
local attribute [instance] is_conj.setoid
/-- Given a conjugacy class `a`, `carrier a` is the set it represents. -/
def carrier : conj_classes α → set α :=
quotient.lift conjugates_of (λ (a : α) b ab, is_conj.conjugates_of_eq ab)
lemma mem_carrier_mk {a : α} : a ∈ carrier (conj_classes.mk a) := is_conj.refl _
lemma mem_carrier_iff_mk_eq {a : α} {b : conj_classes α} :
a ∈ carrier b ↔ conj_classes.mk a = b :=
begin
revert b,
rw forall_is_conj,
intro b,
rw [carrier, eq_comm, mk_eq_mk_iff_is_conj, ← quotient_mk_eq_mk, quotient.lift_mk],
refl,
end
lemma carrier_eq_preimage_mk {a : conj_classes α} :
a.carrier = conj_classes.mk ⁻¹' {a} :=
set.ext (λ x, mem_carrier_iff_mk_eq)
end conj_classes
assert_not_exists multiset
|
88751f607f661f77eb9862ef2c283f0ac9977214 | ea11767c9c6a467c4b7710ec6f371c95cfc023fd | /src/monoidal_categories/internal_objects/semigroup_modules.lean | aafae3430d24cd145532cc6e5782963b8ca72639 | [] | no_license | RitaAhmadi/lean-monoidal-categories | 68a23f513e902038e44681336b87f659bbc281e0 | 81f43e1e0d623a96695aa8938951d7422d6d7ba6 | refs/heads/master | 1,651,458,686,519 | 1,529,824,613,000 | 1,529,824,613,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,510 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan, Scott Morrison
import .semigroups
open categories
open categories.monoidal_category
namespace categories.internal_objects
universes u v
open SemigroupObject
structure SemigroupModuleObject {C : Type u} [monoidal_category.{u v} C] (A : C) [SemigroupObject A] :=
(module : C)
(action : (A ⊗ module) ⟶ module)
(associativity : ((μ A) ⊗ (𝟙 module)) ≫ action = (associator A A module) ≫ ((𝟙 A) ⊗ action) ≫ action)
attribute [ematch] SemigroupModuleObject.associativity
variables {C : Type u} [𝒞 : monoidal_category.{u v} C] {A : C} [SemigroupObject A]
include 𝒞
structure SemigroupModuleMorphism (X Y : SemigroupModuleObject A) :=
(map : X.module ⟶ Y.module)
(compatibility : ((𝟙 A) ⊗ map) ≫ Y.action = X.action ≫ map)
attribute [simp,ematch] SemigroupModuleMorphism.compatibility
@[applicable] lemma SemigroupModuleMorphism_pointwise_equal
{X Y : SemigroupModuleObject A}
(f g : SemigroupModuleMorphism X Y)
(w : f.map = g.map) : f = g :=
begin
induction f,
induction g,
tidy
end
definition CategoryOfSemigroupModules : category.{(max u v) v} (SemigroupModuleObject A) :=
{ Hom := λ X Y, SemigroupModuleMorphism X Y,
identity := λ X, ⟨ 𝟙 X.module, by obviously ⟩,
compose := λ X Y Z f g, ⟨ f.map ≫ g.map, by obviously ⟩ }
end categories.internal_objects |
c2c22368079c5f374f77c75b376a916e86351449 | 3ca6dd8bf23783927a6f1faedd16c92f0c96da9e | /lean/n_subset_z.lean | c3aa35baf984c3c25d5ff22c80125f606633eee1 | [
"MIT"
] | permissive | anqurvanillapy/fpl | 139a368655091c27b0ab78fa266ad9f74348ccb8 | 9576d5b76e6a868992dbe52930712ac67697bed2 | refs/heads/master | 1,623,285,455,999 | 1,616,136,159,000 | 1,616,136,159,000 | 128,802,535 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 204 | lean | variables Z : ℤ → Prop
variables z : ℤ
variables n : ℕ
def set_of_Z : set ℤ := set_of Z
def set_of_N : set ℤ := {z | z = int.of_nat n}
def N_subset_Z := set.subset (set_of_N n) (set_of_Z Z)
|
12502aafaa8c52f1dc78fbec6b1217992d633790 | 32a2d1642d7519c99693bc1d3b24069e4853dd1f | /order/lattice.lean | 7470de21cd4c75a0880cfc6c715f43110977b421 | [
"Apache-2.0"
] | permissive | Cedric0099/mathlib | 7edb81d5d68e280b4d21f6c0377dad1f9b8c0d71 | a97101d2df5d186848075a2d0452f6a04d8a13eb | refs/heads/master | 1,584,201,847,599 | 1,524,979,632,000 | 1,524,979,632,000 | 131,690,350 | 0 | 0 | null | 1,525,162,341,000 | 1,525,162,341,000 | null | UTF-8 | Lean | false | false | 13,661 | 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
Defines the inf/sup (semi)-lattice with optionally top/bot type class hierarchy.
-/
import order.basic tactic.finish
open auto
set_option old_structure_cmd true
universes u v w
-- TODO: move this eventually, if we decide to use them
attribute [ematch] le_trans lt_of_le_of_lt lt_of_lt_of_le lt_trans
section
variable {α : Type u}
-- TODO: this seems crazy, but it also seems to work reasonably well
@[ematch] theorem le_antisymm' [partial_order α] : ∀ {a b : α}, (: a ≤ b :) → b ≤ a → a = b :=
@le_antisymm _ _
end
/- TODO: automatic construction of dual definitions / theorems -/
namespace lattice
reserve infixl ` ⊓ `:70
reserve infixl ` ⊔ `:65
/-- Typeclass for the `⊤` (`\top`) notation -/
class has_top (α : Type u) := (top : α)
/-- Typeclass for the `⊥` (`\bot`) notation -/
class has_bot (α : Type u) := (bot : α)
/-- Typeclass for the `⊔` (`\lub`) notation -/
class has_sup (α : Type u) := (sup : α → α → α)
/-- Typeclass for the `⊓` (`\glb`) notation -/
class has_inf (α : Type u) := (inf : α → α → α)
infix ⊔ := has_sup.sup
infix ⊓ := has_inf.inf
notation `⊤` := has_top.top _
notation `⊥` := has_bot.bot _
/-- An `order_top` is a partial order with a maximal element.
(We could state this on preorders, but then it wouldn't be unique
so distinguishing one would seem odd.) -/
class order_top (α : Type u) extends has_top α, partial_order α :=
(le_top : ∀ a : α, a ≤ ⊤)
section order_top
variables {α : Type u} [order_top α] {a : α}
@[simp] theorem le_top : a ≤ ⊤ :=
order_top.le_top a
theorem top_unique (h : ⊤ ≤ a) : a = ⊤ :=
le_antisymm le_top h
-- TODO: delete in favor of the next?
theorem eq_top_iff : a = ⊤ ↔ ⊤ ≤ a :=
⟨assume eq, eq.symm ▸ le_refl ⊤, top_unique⟩
@[simp] theorem top_le_iff : ⊤ ≤ a ↔ a = ⊤ :=
⟨top_unique, λ h, h.symm ▸ le_refl ⊤⟩
@[simp] theorem not_top_lt : ¬ ⊤ < a :=
assume h, lt_irrefl a (lt_of_le_of_lt le_top h)
end order_top
/-- An `order_bot` is a partial order with a minimal element.
(We could state this on preorders, but then it wouldn't be unique
so distinguishing one would seem odd.) -/
class order_bot (α : Type u) extends has_bot α, partial_order α :=
(bot_le : ∀ a : α, ⊥ ≤ a)
section order_bot
variables {α : Type u} [order_bot α] {a : α}
@[simp] theorem bot_le : ⊥ ≤ a := order_bot.bot_le a
theorem bot_unique (h : a ≤ ⊥) : a = ⊥ :=
le_antisymm h bot_le
-- TODO: delete?
theorem eq_bot_iff : a = ⊥ ↔ a ≤ ⊥ :=
⟨assume eq, eq.symm ▸ le_refl ⊥, bot_unique⟩
@[simp] theorem le_bot_iff : a ≤ ⊥ ↔ a = ⊥ :=
⟨bot_unique, assume h, h.symm ▸ le_refl ⊥⟩
@[simp] theorem not_lt_bot : ¬ a < ⊥ :=
assume h, lt_irrefl a (lt_of_lt_of_le h bot_le)
theorem neq_bot_of_le_neq_bot {a b : α} (hb : b ≠ ⊥) (hab : b ≤ a) : a ≠ ⊥ :=
assume ha, hb $ bot_unique $ ha ▸ hab
end order_bot
/-- A `semilattice_sup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`⊔` which is the least element larger than both factors. -/
class semilattice_sup (α : Type u) extends has_sup α, partial_order α :=
(le_sup_left : ∀ a b : α, a ≤ a ⊔ b)
(le_sup_right : ∀ a b : α, b ≤ a ⊔ b)
(sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c)
section semilattice_sup
variables {α : Type u} [semilattice_sup α] {a b c d : α}
@[simp] theorem le_sup_left : a ≤ a ⊔ b :=
semilattice_sup.le_sup_left a b
@[ematch] theorem le_sup_left' : a ≤ (: a ⊔ b :) :=
semilattice_sup.le_sup_left a b
@[simp] theorem le_sup_right : b ≤ a ⊔ b :=
semilattice_sup.le_sup_right a b
@[ematch] theorem le_sup_right' : b ≤ (: a ⊔ b :) :=
semilattice_sup.le_sup_right a b
theorem le_sup_left_of_le (h : c ≤ a) : c ≤ a ⊔ b :=
by finish
theorem le_sup_right_of_le (h : c ≤ b) : c ≤ a ⊔ b :=
by finish
theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c :=
semilattice_sup.sup_le a b c
@[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c :=
⟨assume h : a ⊔ b ≤ c, ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩,
assume ⟨h₁, h₂⟩, sup_le h₁ h₂⟩
-- TODO: if we just write le_antisymm, Lean doesn't know which ≤ we want to use
-- Can we do anything about that?
theorem sup_of_le_left (h : b ≤ a) : a ⊔ b = a :=
by apply le_antisymm; finish
theorem sup_of_le_right (h : a ≤ b) : a ⊔ b = b :=
by apply le_antisymm; finish
theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d :=
by finish
theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b :=
by finish
theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c :=
by finish
theorem le_of_sup_eq (h : a ⊔ b = b) : a ≤ b :=
by finish
@[simp] theorem sup_idem : a ⊔ a = a :=
by apply le_antisymm; finish
theorem sup_comm : a ⊔ b = b ⊔ a :=
by apply le_antisymm; finish
instance semilattice_sup_to_is_commutative : is_commutative α (⊔) :=
⟨@sup_comm _ _⟩
theorem sup_assoc : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) :=
by apply le_antisymm; finish
instance semilattice_sup_to_is_associative : is_associative α (⊔) :=
⟨@sup_assoc _ _⟩
lemma forall_le_or_exists_lt_sup (a : α) : (∀b, b ≤ a) ∨ (∃b, a < b) :=
suffices (∃b, ¬b ≤ a) → (∃b, a < b),
by rwa [classical.or_iff_not_imp_left, classical.not_forall],
assume ⟨b, hb⟩,
have a ≠ a ⊔ b, from assume eq, hb $ eq.symm ▸ le_sup_right,
⟨a ⊔ b, lt_of_le_of_ne le_sup_left ‹a ≠ a ⊔ b›⟩
end semilattice_sup
/-- A `semilattice_sup` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`⊓` which is the greatest element smaller than both factors. -/
class semilattice_inf (α : Type u) extends has_inf α, partial_order α :=
(inf_le_left : ∀ a b : α, a ⊓ b ≤ a)
(inf_le_right : ∀ a b : α, a ⊓ b ≤ b)
(le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c)
section semilattice_inf
variables {α : Type u} [semilattice_inf α] {a b c d : α}
@[simp] theorem inf_le_left : a ⊓ b ≤ a :=
semilattice_inf.inf_le_left a b
@[ematch] theorem inf_le_left' : (: a ⊓ b :) ≤ a :=
semilattice_inf.inf_le_left a b
@[simp] theorem inf_le_right : a ⊓ b ≤ b :=
semilattice_inf.inf_le_right a b
@[ematch] theorem inf_le_right' : (: a ⊓ b :) ≤ b :=
semilattice_inf.inf_le_right a b
theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c :=
semilattice_inf.le_inf a b c
theorem inf_le_left_of_le (h : a ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_left h
theorem inf_le_right_of_le (h : b ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_right h
@[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c :=
⟨assume h : a ≤ b ⊓ c, ⟨le_trans h inf_le_left, le_trans h inf_le_right⟩,
assume ⟨h₁, h₂⟩, le_inf h₁ h₂⟩
theorem inf_of_le_left (h : a ≤ b) : a ⊓ b = a :=
by apply le_antisymm; finish
theorem inf_of_le_right (h : b ≤ a) : a ⊓ b = b :=
by apply le_antisymm; finish
theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d :=
by finish
theorem le_of_inf_eq (h : a ⊓ b = a) : a ≤ b :=
by finish
@[simp] theorem inf_idem : a ⊓ a = a :=
by apply le_antisymm; finish
theorem inf_comm : a ⊓ b = b ⊓ a :=
by apply le_antisymm; finish
instance semilattice_inf_to_is_commutative : is_commutative α (⊓) :=
⟨@inf_comm _ _⟩
theorem inf_assoc : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) :=
by apply le_antisymm; finish
instance semilattice_inf_to_is_associative : is_associative α (⊓) :=
⟨@inf_assoc _ _⟩
lemma forall_le_or_exists_lt_inf (a : α) : (∀b, a ≤ b) ∨ (∃b, b < a) :=
suffices (∃b, ¬a ≤ b) → (∃b, b < a),
by rwa [classical.or_iff_not_imp_left, classical.not_forall],
assume ⟨b, hb⟩,
have a ⊓ b ≠ a, from assume eq, hb $ eq ▸ inf_le_right,
⟨a ⊓ b, lt_of_le_of_ne inf_le_left ‹a ⊓ b ≠ a›⟩
end semilattice_inf
/-- A `semilattice_sup_top` is a semilattice with top and join. -/
class semilattice_sup_top (α : Type u) extends order_top α, semilattice_sup α
section semilattice_sup_top
variables {α : Type u} [semilattice_sup_top α] {a : α}
@[simp] theorem top_sup_eq : ⊤ ⊔ a = ⊤ :=
sup_of_le_left le_top
@[simp] theorem sup_top_eq : a ⊔ ⊤ = ⊤ :=
sup_of_le_right le_top
end semilattice_sup_top
/-- A `semilattice_sup_bot` is a semilattice with bottom and join. -/
class semilattice_sup_bot (α : Type u) extends order_bot α, semilattice_sup α
section semilattice_sup_bot
variables {α : Type u} [semilattice_sup_bot α] {a b : α}
@[simp] theorem bot_sup_eq : ⊥ ⊔ a = a :=
sup_of_le_right bot_le
@[simp] theorem sup_bot_eq : a ⊔ ⊥ = a :=
sup_of_le_left bot_le
@[simp] theorem sup_eq_bot_iff : a ⊔ b = ⊥ ↔ (a = ⊥ ∧ b = ⊥) :=
by rw [eq_bot_iff, sup_le_iff]; simp
end semilattice_sup_bot
/-- A `semilattice_inf_top` is a semilattice with top and meet. -/
class semilattice_inf_top (α : Type u) extends order_top α, semilattice_inf α
section semilattice_inf_top
variables {α : Type u} [semilattice_inf_top α] {a b : α}
@[simp] theorem top_inf_eq : ⊤ ⊓ a = a :=
inf_of_le_right le_top
@[simp] theorem inf_top_eq : a ⊓ ⊤ = a :=
inf_of_le_left le_top
@[simp] theorem inf_eq_top_iff : a ⊓ b = ⊤ ↔ (a = ⊤ ∧ b = ⊤) :=
by rw [eq_top_iff, le_inf_iff]; simp
end semilattice_inf_top
/-- A `semilattice_inf_bot` is a semilattice with bottom and meet. -/
class semilattice_inf_bot (α : Type u) extends order_bot α, semilattice_inf α
section semilattice_inf_bot
variables {α : Type u} [semilattice_inf_bot α] {a : α}
@[simp] theorem bot_inf_eq : ⊥ ⊓ a = ⊥ :=
inf_of_le_left bot_le
@[simp] theorem inf_bot_eq : a ⊓ ⊥ = ⊥ :=
inf_of_le_right bot_le
end semilattice_inf_bot
/- Lattices -/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class lattice (α : Type u) extends semilattice_sup α, semilattice_inf α
section lattice
variables {α : Type u} [lattice α] {a b c d : α}
/- Distributivity laws -/
/- TODO: better names? -/
theorem sup_inf_le : a ⊔ (b ⊓ c) ≤ (a ⊔ b) ⊓ (a ⊔ c) :=
by finish
theorem le_inf_sup : (a ⊓ b) ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c) :=
by finish
theorem inf_sup_self : a ⊓ (a ⊔ b) = a :=
le_antisymm (by finish) (by finish)
theorem sup_inf_self : a ⊔ (a ⊓ b) = a :=
le_antisymm (by finish) (by finish)
end lattice
variables {α : Type u} {x y z w : α}
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distribution properties (of sup over inf or inf over sup,
on the left or right). A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class distrib_lattice α extends lattice α :=
(le_sup_inf : ∀x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z))
section distrib_lattice
variables [distrib_lattice α]
theorem le_sup_inf : ∀{x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z) :=
distrib_lattice.le_sup_inf
theorem sup_inf_left : x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z) :=
le_antisymm sup_inf_le le_sup_inf
theorem sup_inf_right : (y ⊓ z) ⊔ x = (y ⊔ x) ⊓ (z ⊔ x) :=
by simp [sup_inf_left, λy:α, @sup_comm α _ y x]
theorem inf_sup_left : x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z) :=
calc x ⊓ (y ⊔ z) = (x ⊓ (x ⊔ z)) ⊓ (y ⊔ z) : by rw [inf_sup_self]
... = x ⊓ ((x ⊓ y) ⊔ z) : by simp [inf_assoc, sup_inf_right]
... = (x ⊔ (x ⊓ y)) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_inf_self]
... = ((x ⊓ y) ⊔ x) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_comm]
... = (x ⊓ y) ⊔ (x ⊓ z) : by rw [sup_inf_left]
theorem inf_sup_right : (y ⊔ z) ⊓ x = (y ⊓ x) ⊔ (z ⊓ x) :=
by simp [inf_sup_left, λy:α, @inf_comm α _ y x]
lemma eq_of_sup_eq_inf_eq {α : Type u} [distrib_lattice α] {a b c : α}
(h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c :=
le_antisymm
(calc b ≤ (c ⊓ a) ⊔ b : le_sup_right
... = (c ⊔ b) ⊓ (a ⊔ b) : sup_inf_right
... = c ⊔ (c ⊓ a) : by rw [←h₁, sup_inf_left, ←h₂]; simp [sup_comm]
... = c : sup_inf_self)
(calc c ≤ (b ⊓ a) ⊔ c : le_sup_right
... = (b ⊔ c) ⊓ (a ⊔ c) : sup_inf_right
... = b ⊔ (b ⊓ a) : by rw [h₁, sup_inf_left, h₂]; simp [sup_comm]
... = b : sup_inf_self)
end distrib_lattice
/- Lattices derived from linear orders -/
instance lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : lattice α :=
{ sup := max,
le_sup_left := le_max_left,
le_sup_right := le_max_right,
sup_le := assume a b c, max_le,
inf := min,
inf_le_left := min_le_left,
inf_le_right := min_le_right,
le_inf := assume a b c, le_min,
..o }
instance distrib_lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : distrib_lattice α :=
{ le_sup_inf := assume a b c,
match le_total b c with
| or.inl h := inf_le_left_of_le $ sup_le_sup_left (le_inf (le_refl b) h) _
| or.inr h := inf_le_right_of_le $ sup_le_sup_left (le_inf h (le_refl c)) _
end,
..lattice.lattice_of_decidable_linear_order }
end lattice
|
9f6255bfde58e4b2f7fb4d01b49b46c48b62d9d0 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/category/BoolAlg.lean | a84443001449e0ccd867ce449c05a11b54cb8b7c | [
"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 | 2,761 | lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import order.category.HeytAlg
/-!
# The category of boolean algebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This defines `BoolAlg`, the category of boolean algebras.
-/
open order_dual opposite set
universes u
open category_theory
/-- The category of boolean algebras. -/
def BoolAlg := bundled boolean_algebra
namespace BoolAlg
instance : has_coe_to_sort BoolAlg Type* := bundled.has_coe_to_sort
instance (X : BoolAlg) : boolean_algebra X := X.str
/-- Construct a bundled `BoolAlg` from a `boolean_algebra`. -/
def of (α : Type*) [boolean_algebra α] : BoolAlg := bundled.of α
@[simp] lemma coe_of (α : Type*) [boolean_algebra α] : ↥(of α) = α := rfl
instance : inhabited BoolAlg := ⟨of punit⟩
/-- Turn a `BoolAlg` into a `BddDistLat` by forgetting its complement operation. -/
def to_BddDistLat (X : BoolAlg) : BddDistLat := BddDistLat.of X
@[simp] lemma coe_to_BddDistLat (X : BoolAlg) : ↥X.to_BddDistLat = ↥X := rfl
instance : large_category.{u} BoolAlg := induced_category.category to_BddDistLat
instance : concrete_category BoolAlg := induced_category.concrete_category to_BddDistLat
instance has_forget_to_BddDistLat : has_forget₂ BoolAlg BddDistLat :=
induced_category.has_forget₂ to_BddDistLat
section
local attribute [instance] bounded_lattice_hom_class.to_biheyting_hom_class
@[simps] instance has_forget_to_HeytAlg : has_forget₂ BoolAlg HeytAlg :=
{ forget₂ := { obj := λ X, ⟨X⟩, map := λ X Y f, show bounded_lattice_hom X Y, from f } }
end
/-- Constructs an equivalence between Boolean algebras from an order isomorphism between them. -/
@[simps] def iso.mk {α β : BoolAlg.{u}} (e : α ≃o β) : α ≅ β :=
{ hom := (e : bounded_lattice_hom α β),
inv := (e.symm : bounded_lattice_hom β α),
hom_inv_id' := by { ext, exact e.symm_apply_apply _ },
inv_hom_id' := by { ext, exact e.apply_symm_apply _ } }
/-- `order_dual` as a functor. -/
@[simps] def dual : BoolAlg ⥤ BoolAlg :=
{ obj := λ X, of Xᵒᵈ, map := λ X Y, bounded_lattice_hom.dual }
/-- The equivalence between `BoolAlg` and itself induced by `order_dual` both ways. -/
@[simps functor inverse] def dual_equiv : BoolAlg ≌ BoolAlg :=
equivalence.mk dual dual
(nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl)
(nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl)
end BoolAlg
lemma BoolAlg_dual_comp_forget_to_BddDistLat :
BoolAlg.dual ⋙ forget₂ BoolAlg BddDistLat =
forget₂ BoolAlg BddDistLat ⋙ BddDistLat.dual := rfl
|
2fda4f28a902d10074868943a54bbf71c63bf541 | 4fa161becb8ce7378a709f5992a594764699e268 | /src/topology/constructions.lean | 36b608ebaf0de1777c00707037028140b35087e5 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 33,251 | 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
lemma quotient_dense_of_dense [setoid α] [topological_space α] {s : set α} (H : ∀ x, x ∈ closure s) :
closure (quotient.mk '' s) = univ :=
eq_univ_of_forall $ λ x, begin
rw mem_closure_iff,
intros U U_op x_in_U,
let V := quotient.mk ⁻¹' U,
cases quotient.exists_rep x with y y_x,
have y_in_V : y ∈ V, by simp only [mem_preimage, y_x, x_in_U],
have V_op : is_open V := U_op,
obtain ⟨w, w_in_V, w_in_range⟩ : (V ∩ s).nonempty := mem_closure_iff.1 (H y) V V_op y_in_V,
exact ⟨_, w_in_V, mem_image_of_mem quotient.mk w_in_range⟩
end
instance {p : α → Prop} [topological_space α] [discrete_topology α] :
discrete_topology (subtype p) :=
⟨bot_unique $ assume s hs,
⟨subtype.val '' s, is_open_discrete _, (set.preimage_image_eq _ subtype.val_injective)⟩⟩
instance sum.discrete_topology [topological_space α] [topological_space β]
[hα : discrete_topology α] [hβ : discrete_topology β] : discrete_topology (α ⊕ β) :=
⟨by unfold sum.topological_space; simp [hα.eq_bot, hβ.eq_bot]⟩
instance sigma.discrete_topology {β : α → Type v} [Πa, topological_space (β a)]
[h : Πa, discrete_topology (β a)] : discrete_topology (sigma β) :=
⟨by { unfold sigma.topological_space, simp [λ a, (h a).eq_bot] }⟩
section topα
variable [topological_space α]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : set α) (a : {x // x ∈ s}) (t : set {x // x ∈ s}) :
t ∈ 𝓝 a ↔ ∃ u ∈ 𝓝 a.val, (@subtype.val α s) ⁻¹' u ⊆ t :=
mem_nhds_induced subtype.val a t
theorem nhds_subtype (s : set α) (a : {x // x ∈ s}) :
𝓝 a = comap subtype.val (𝓝 a.val) :=
nhds_induced subtype.val a
end topα
end constructions
section prod
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
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
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
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 is_open_prod {s : set α} {t : set β} (hs : is_open s) (ht : is_open t) :
is_open (set.prod s t) :=
is_open_inter (continuous_fst s hs) (continuous_snd t ht)
lemma nhds_prod_eq {a : α} {b : β} : 𝓝 (a, b) = filter.prod (𝓝 a) (𝓝 b) :=
by rw [filter.prod, prod.topological_space, nhds_inf, nhds_induced, nhds_induced]
instance [discrete_topology α] [discrete_topology β] : discrete_topology (α × β) :=
⟨eq_of_nhds_eq_nhds $ assume ⟨a, b⟩,
by rw [nhds_prod_eq, nhds_discrete α, nhds_discrete β, nhds_bot, filter.prod_pure_pure]⟩
lemma prod_mem_nhds_sets {s : set α} {t : set β} {a : α} {b : β}
(ha : s ∈ 𝓝 a) (hb : t ∈ 𝓝 b) : set.prod s t ∈ 𝓝 (a, b) :=
by rw [nhds_prod_eq]; exact prod_mem_prod ha hb
lemma nhds_swap (a : α) (b : β) : 𝓝 (a, b) = (𝓝 (b, a)).map prod.swap :=
by rw [nhds_prod_eq, filter.prod_comm, nhds_prod_eq]; refl
lemma 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 ▸ is_open_prod hs ht)
(le_inf
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨t, univ, by simpa [set.prod_eq] using ht⟩)
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨univ, t, by simpa [set.prod_eq] using ht⟩))
lemma is_open_prod_iff {s : set (α×β)} : is_open s ↔
(∀a b, (a, b) ∈ s → ∃u v, is_open u ∧ is_open v ∧ a ∈ u ∧ b ∈ v ∧ set.prod u v ⊆ s) :=
begin
rw [is_open_iff_nhds],
simp [nhds_prod_eq, mem_prod_iff],
simp [mem_nhds_sets_iff],
exact forall_congr (assume a, ball_congr $ assume b h,
⟨assume ⟨u', ⟨u, us, uo, au⟩, v', ⟨v, vs, vo, bv⟩, h⟩,
⟨u, uo, v, vo, au, bv, subset.trans (set.prod_mono us vs) h⟩,
assume ⟨u, uo, v, vo, au, bv, h⟩,
⟨u, ⟨u, subset.refl u, uo, au⟩, v, ⟨v, subset.refl v, vo, bv⟩, h⟩⟩)
end
/-- The first projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_fst : is_open_map (@prod.fst α β) :=
begin
assume s hs,
rw is_open_iff_forall_mem_open,
assume x xs,
rw mem_image_eq at xs,
rcases xs with ⟨⟨y₁, y₂⟩, ys, yx⟩,
rcases is_open_prod_iff.1 hs _ _ ys with ⟨o₁, o₂, o₁_open, o₂_open, yo₁, yo₂, ho⟩,
simp at yx,
rw yx at yo₁,
refine ⟨o₁, _, o₁_open, yo₁⟩,
assume z zs,
rw mem_image_eq,
exact ⟨(z, y₂), ho (by simp [zs, yo₂]), rfl⟩
end
/-- The second projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_snd : is_open_map (@prod.snd α β) :=
begin
/- This lemma could be proved by composing the fact that the first projection is open, and
exchanging coordinates is a homeomorphism, hence open. As the `prod_comm` homeomorphism is defined
later, we rather go for the direct proof, copy-pasting the proof for the first projection. -/
assume s hs,
rw is_open_iff_forall_mem_open,
assume x xs,
rw mem_image_eq at xs,
rcases xs with ⟨⟨y₁, y₂⟩, ys, yx⟩,
rcases is_open_prod_iff.1 hs _ _ ys with ⟨o₁, o₂, o₁_open, o₂_open, yo₁, yo₂, ho⟩,
simp at yx,
rw yx at yo₂,
refine ⟨o₂, _, o₂_open, yo₂⟩,
assume z zs,
rw mem_image_eq,
exact ⟨(y₁, z), ho (by simp [zs, yo₁]), rfl⟩
end
/-- A product set is open in a product space if and only if each factor is open, or one of them is
empty -/
lemma is_open_prod_iff' {s : set α} {t : set β} :
is_open (set.prod s t) ↔ (is_open s ∧ is_open t) ∨ (s = ∅) ∨ (t = ∅) :=
begin
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 [st.1.ne_empty, st.2.ne_empty] at H,
exact is_open_prod H.1 H.2 } }
end
lemma closure_prod_eq {s : set α} {t : set β} :
closure (set.prod s t) = set.prod (closure s) (closure t) :=
set.ext $ assume ⟨a, b⟩,
have filter.prod (𝓝 a) (𝓝 b) ⊓ principal (set.prod s t) =
filter.prod (𝓝 a ⊓ principal s) (𝓝 b ⊓ principal t),
by rw [←prod_inf_prod, prod_principal_principal],
by simp [closure_eq_nhds, nhds_prod_eq, this]; exact prod_ne_bot
lemma mem_closure2 {s : set α} {t : set β} {u : set γ} {f : α → β → γ} {a : α} {b : β}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(hu : ∀a b, a ∈ s → b ∈ t → f a b ∈ u) :
f a b ∈ closure u :=
have (a, b) ∈ closure (set.prod s t), by rw [closure_prod_eq]; from ⟨ha, hb⟩,
show (λp:α×β, f p.1 p.2) (a, b) ∈ closure u, from
mem_closure hf this $ assume ⟨a, b⟩ ⟨ha, hb⟩, hu a b ha hb
lemma is_closed_prod {s₁ : set α} {s₂ : set β} (h₁ : is_closed s₁) (h₂ : is_closed s₂) :
is_closed (set.prod s₁ s₂) :=
closure_eq_iff_is_closed.mp $ by simp [h₁, h₂, closure_prod_eq, closure_eq_of_is_closed]
lemma inducing.prod_mk {f : α → β} {g : γ → δ} (hf : inducing f) (hg : inducing g) :
inducing (λx:α×γ, (f x.1, g x.2)) :=
⟨by rw [prod.topological_space, prod.topological_space, hf.induced, hg.induced,
induced_compose, induced_compose, induced_inf, induced_compose, induced_compose]⟩
lemma embedding.prod_mk {f : α → β} {g : γ → δ} (hf : embedding f) (hg : embedding g) :
embedding (λx:α×γ, (f x.1, g x.2)) :=
{ inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume h₁ h₂, ⟨hf.inj h₁, hg.inj h₂⟩,
..hf.to_inducing.prod_mk hg.to_inducing }
protected lemma is_open_map.prod {f : α → β} {g : γ → δ} (hf : is_open_map f) (hg : is_open_map g) :
is_open_map (λ p : α × γ, (f p.1, g p.2)) :=
begin
rw [is_open_map_iff_nhds_le],
rintros ⟨a, b⟩,
rw [nhds_prod_eq, nhds_prod_eq, ← filter.prod_map_map_eq],
exact filter.prod_mono (is_open_map_iff_nhds_le.1 hf a) (is_open_map_iff_nhds_le.1 hg b)
end
protected lemma open_embedding.prod {f : α → β} {g : γ → δ}
(hf : open_embedding f) (hg : open_embedding g) : open_embedding (λx:α×γ, (f x.1, g x.2)) :=
open_embedding_of_embedding_open (hf.1.prod_mk hg.1)
(hf.is_open_map.prod hg.is_open_map)
lemma embedding_graph {f : α → β} (hf : continuous f) : embedding (λx, (x, f x)) :=
embedding_of_embedding_compose (continuous_id.prod_mk hf) continuous_fst embedding_id
end prod
section sum
open sum
variables [topological_space α] [topological_space β] [topological_space γ]
lemma continuous_inl : continuous (@inl α β) :=
continuous_sup_rng_left continuous_coinduced_rng
lemma continuous_inr : continuous (@inr α β) :=
continuous_sup_rng_right continuous_coinduced_rng
lemma continuous_sum_rec {f : α → γ} {g : β → γ}
(hf : continuous f) (hg : continuous g) : @continuous (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) :=
continuous_sup_dom hf hg
lemma 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 open_embedding_inl : open_embedding (inl : α → α ⊕ β) :=
{ open_range := begin
rw is_open_sum_iff,
convert and.intro is_open_univ is_open_empty;
{ ext, simp }
end,
.. embedding_inl }
lemma open_embedding_inr : open_embedding (inr : β → α ⊕ β) :=
{ open_range := begin
rw is_open_sum_iff,
convert and.intro is_open_empty is_open_univ;
{ ext, simp }
end,
.. embedding_inr }
end sum
section subtype
variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop}
lemma embedding_subtype_val : embedding (@subtype.val α p) :=
⟨⟨rfl⟩, subtype.val_injective⟩
lemma continuous_subtype_val : continuous (@subtype.val α p) :=
continuous_induced_dom
lemma continuous_subtype_coe : continuous (coe : subtype p → α) :=
continuous_subtype_val
lemma is_open.open_embedding_subtype_val {s : set α} (hs : is_open s) :
open_embedding (subtype.val : s → α) :=
{ induced := rfl,
inj := subtype.val_injective,
open_range := (subtype.val_range : range subtype.val = s).symm ▸ hs }
lemma is_open.is_open_map_subtype_val {s : set α} (hs : is_open s) :
is_open_map (subtype.val : s → α) :=
hs.open_embedding_subtype_val.is_open_map
lemma is_open_map.restrict {f : α → β} (hf : is_open_map f) {s : set α} (hs : is_open s) :
is_open_map (s.restrict f) :=
hf.comp hs.is_open_map_subtype_val
lemma is_closed.closed_embedding_subtype_val {s : set α} (hs : is_closed s) :
closed_embedding (subtype.val : {x // x ∈ s} → α) :=
{ induced := rfl,
inj := subtype.val_injective,
closed_range := (subtype.val_range : range subtype.val = s).symm ▸ hs }
lemma continuous_subtype_mk {f : β → α}
(hp : ∀x, p (f x)) (h : continuous f) : continuous (λx, (⟨f x, hp x⟩ : subtype p)) :=
continuous_induced_rng h
lemma continuous_inclusion {s t : set α} (h : s ⊆ t) : continuous (inclusion h) :=
continuous_subtype_mk _ continuous_subtype_val
lemma continuous_at_subtype_val {p : α → Prop} {a : subtype p} :
continuous_at subtype.val a :=
continuous_iff_continuous_at.mp continuous_subtype_val _
lemma map_nhds_subtype_val_eq {a : α} (ha : p a) (h : {a | p a} ∈ 𝓝 a) :
map (@subtype.val α p) (𝓝 ⟨a, ha⟩) = 𝓝 a :=
map_nhds_induced_eq (by simp [subtype.val_image, h])
lemma nhds_subtype_eq_comap {a : α} {h : p a} :
𝓝 (⟨a, h⟩ : subtype p) = comap subtype.val (𝓝 a) :=
nhds_induced _ _
lemma tendsto_subtype_rng {β : Type*} {p : α → Prop} {b : filter β} {f : β → subtype p} :
∀{a:subtype p}, tendsto f b (𝓝 a) ↔ tendsto (λx, subtype.val (f x)) b (𝓝 a.val)
| ⟨a, ha⟩ := by rw [nhds_subtype_eq_comap, tendsto_comap_iff]
lemma continuous_subtype_nhds_cover {ι : Sort*} {f : α → β} {c : ι → α → Prop}
(c_cover : ∀x:α, ∃i, {x | c i x} ∈ 𝓝 x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) :
continuous f :=
continuous_iff_continuous_at.mpr $ assume x,
let ⟨i, (c_sets : {x | c i x} ∈ 𝓝 x)⟩ := c_cover x in
let x' : subtype (c i) := ⟨x, mem_of_nhds c_sets⟩ in
calc map f (𝓝 x) = map f (map subtype.val (𝓝 x')) :
congr_arg (map f) (map_nhds_subtype_val_eq _ $ c_sets).symm
... = map (λx:subtype (c i), f x.val) (𝓝 x') : rfl
... ≤ 𝓝 (f x) : continuous_iff_continuous_at.mp (f_cont i) x'
lemma continuous_subtype_is_closed_cover {ι : Sort*} {f : α → β} (c : ι → α → Prop)
(h_lf : locally_finite (λi, {x | c i x}))
(h_is_closed : ∀i, is_closed {x | c i x})
(h_cover : ∀x, ∃i, c i x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) :
continuous f :=
continuous_iff_is_closed.mpr $
assume s hs,
have ∀i, is_closed (@subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
from assume i,
embedding_is_closed embedding_subtype_val
(by simp [subtype.val_range]; exact h_is_closed i)
(continuous_iff_is_closed.mp (f_cont i) _ hs),
have is_closed (⋃i, @subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
from is_closed_Union_of_locally_finite
(locally_finite_subset h_lf $ assume i x ⟨⟨x', hx'⟩, _, heq⟩, heq ▸ hx')
this,
have f ⁻¹' s = (⋃i, @subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
begin
apply set.ext,
have : ∀ (x : α), f x ∈ s ↔ ∃ (i : ι), c i x ∧ f x ∈ s :=
λ x, ⟨λ hx, let ⟨i, hi⟩ := h_cover x in ⟨i, hi, hx⟩,
λ ⟨i, hi, hx⟩, hx⟩,
simp [and.comm, and.left_comm], simpa [(∘)],
end,
by rwa [this]
lemma closure_subtype {x : {a // p a}} {s : set {a // p a}}:
x ∈ closure s ↔ x.val ∈ closure (subtype.val '' s) :=
closure_induced $ assume x y, subtype.eq
end subtype
section quotient
variables [topological_space α] [topological_space β] [topological_space γ]
variables {r : α → α → Prop} {s : setoid α}
lemma quotient_map_quot_mk : quotient_map (@quot.mk α r) :=
⟨quot.exists_rep, rfl⟩
lemma continuous_quot_mk : continuous (@quot.mk α r) :=
continuous_coinduced_rng
lemma continuous_quot_lift {f : α → β} (hr : ∀ a b, r a b → f a = f b)
(h : continuous f) : continuous (quot.lift f hr : quot r → β) :=
continuous_coinduced_dom h
lemma quotient_map_quotient_mk : quotient_map (@quotient.mk α s) :=
quotient_map_quot_mk
lemma continuous_quotient_mk : continuous (@quotient.mk α s) :=
continuous_coinduced_rng
lemma continuous_quotient_lift {f : α → β} (hs : ∀ a b, a ≈ b → f a = f b)
(h : continuous f) : continuous (quotient.lift f hs : quotient s → β) :=
continuous_coinduced_dom h
end quotient
section pi
variables {ι : Type*} {π : ι → Type*}
lemma continuous_pi [topological_space α] [∀i, topological_space (π i)] {f : α → Πi:ι, π i}
(h : ∀i, continuous (λa, f a i)) : continuous f :=
continuous_infi_rng $ assume i, continuous_induced_rng $ h i
lemma continuous_apply [∀i, topological_space (π i)] (i : ι) :
continuous (λp:Πi, π i, p i) :=
continuous_infi_dom continuous_induced_dom
/-- Embedding a factor into a product space (by fixing arbitrarily all the other coordinates) is
continuous. -/
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 is_open_set_pi [∀a, topological_space (π a)] {i : set ι} {s : Πa, set (π a)}
(hi : finite i) (hs : ∀a∈i, is_open (s a)) : is_open (pi i s) :=
by rw [pi_def]; exact (is_open_bInter hi $ assume a ha, continuous_apply a _ $ hs a ha)
lemma pi_eq_generate_from [∀a, topological_space (π a)] :
Pi.topological_space =
generate_from {g | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, is_open (s a)) ∧ g = pi ↑i s} :=
le_antisymm
(le_generate_from $ assume g ⟨s, i, hi, eq⟩, eq.symm ▸ is_open_set_pi (finset.finite_to_set _) hi)
(le_infi $ assume a s ⟨t, ht, s_eq⟩, generate_open.basic _ $
⟨function.update (λa, univ) a t, {a}, by simpa using ht, by ext f; simp [s_eq.symm, pi]⟩)
lemma pi_generate_from_eq {g : Πa, set (set (π a))} :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} :=
let G := {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} in
begin
rw [pi_eq_generate_from],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, i, ht, eq⟩, ⟨t, i, assume a ha, generate_open.basic _ (ht a ha), eq⟩,
{ rintros s ⟨t, i, hi, rfl⟩,
rw [pi_def],
apply is_open_bInter (finset.finite_to_set _),
assume a ha, show ((generate_from G).coinduced (λf:Πa, π a, f a)).is_open (t a),
refine le_generate_from _ _ (hi a ha),
exact assume s hs, generate_open.basic _ ⟨function.update (λa, univ) a s, {a}, by simp [hs]⟩ }
end
lemma pi_generate_from_eq_fintype {g : Πa, set (set (π a))} [fintype ι] (hg : ∀a, ⋃₀ g a = univ) :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)), (∀a, s a ∈ g a) ∧ t = pi univ s} :=
let G := {t | ∃(s:Πa, set (π a)), (∀a, s a ∈ g a) ∧ t = pi univ s} in
begin
rw [pi_generate_from_eq],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, ht, eq⟩, ⟨t, finset.univ, by simp [ht, eq]⟩,
{ rintros s ⟨t, i, ht, rfl⟩,
apply is_open_iff_forall_mem_open.2 _,
assume f hf,
choose c hc using show ∀a, ∃s, s ∈ g a ∧ f a ∈ s,
{ assume a, have : f a ∈ ⋃₀ g a, { rw [hg], apply mem_univ }, simpa },
refine ⟨pi univ (λa, if a ∈ i then t a else (c : Πa, set (π a)) a), _, _, _⟩,
{ simp [pi_if] },
{ refine generate_open.basic _ ⟨_, assume a, _, rfl⟩,
by_cases a ∈ i; simp [*, pi] at * },
{ have : f ∈ pi {a | a ∉ i} c, { simp [*, pi] at * },
simpa [pi_if, hf] } }
end
end pi
section sigma
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
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. -/
lemma continuous_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, continuous (λ a, f ⟨i, a⟩)) : continuous f :=
continuous_supr_dom (λ i, continuous_coinduced_dom (h i))
lemma continuous_sigma_map {κ : Type*} {τ : κ → Type*} [Π k, topological_space (τ k)]
{f₁ : ι → κ} {f₂ : Π i, σ i → τ (f₁ i)} (hf : ∀ i, continuous (f₂ i)) :
continuous (sigma.map f₁ f₂) :=
continuous_sigma $ λ i,
show continuous (λ a, sigma.mk (f₁ i) (f₂ i a)),
from continuous_sigma_mk.comp (hf i)
lemma is_open_map_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, is_open_map (λ a, f ⟨i, a⟩)) : is_open_map f :=
begin
intros s hs,
rw is_open_sigma_iff at hs,
have : s = ⋃ i, sigma.mk i '' (sigma.mk i ⁻¹' s),
{ rw Union_image_preimage_sigma_mk_eq_self },
rw this,
rw [image_Union],
apply is_open_Union,
intro i,
rw [image_image],
exact h i _ (hs i)
end
/-- The sum of embeddings is an embedding. -/
lemma embedding_sigma_map {τ : ι → Type*} [Π i, topological_space (τ i)]
{f : Π i, σ i → τ i} (hf : ∀ i, embedding (f i)) : embedding (sigma.map id f) :=
begin
refine ⟨⟨_⟩, sigma_map_injective function.injective_id (λ i, (hf i).inj)⟩,
refine le_antisymm
(continuous_iff_le_induced.mp (continuous_sigma_map (λ i, (hf i).continuous))) _,
intros s hs,
replace hs := is_open_sigma_iff.mp hs,
have : ∀ i, ∃ t, is_open t ∧ f i ⁻¹' t = sigma.mk i ⁻¹' s,
{ intro i,
apply is_open_induced_iff.mp,
convert hs i,
exact (hf i).induced.symm },
choose t ht using this,
apply is_open_induced_iff.mpr,
refine ⟨⋃ i, sigma.mk i '' t i, is_open_Union (λ i, is_open_map_sigma_mk _ (ht i).1), _⟩,
ext ⟨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
lemma continuous_ulift_down [topological_space α] : continuous (ulift.down : ulift.{v u} α → α) :=
continuous_induced_dom
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 : ∀a∈s, f a ∈ closure t) :
f a ∈ closure t :=
calc f a ∈ f '' closure s : mem_image_of_mem _ ha
... ⊆ closure (f '' s) : image_closure_subset_closure_image hf
... ⊆ closure (closure t) : closure_mono $ image_subset_iff.mpr $ h
... ⊆ closure t : begin rw [closure_eq_of_is_closed], exact subset.refl _, exact is_closed_closure end
lemma mem_closure_of_continuous2 [topological_space α] [topological_space β] [topological_space γ]
{f : α → β → γ} {a : α} {b : β} {s : set α} {t : set β} {u : set γ}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(h : ∀a∈s, ∀b∈t, f a b ∈ closure u) :
f a b ∈ closure u :=
have (a,b) ∈ closure (set.prod s t),
by simp [closure_prod_eq, ha, hb],
show f (a, b).1 (a, b).2 ∈ closure u,
from @mem_closure_of_continuous (α×β) _ _ _ (λp:α×β, f p.1 p.2) (a,b) _ u hf this $
assume ⟨p₁, p₂⟩ ⟨h₁, h₂⟩, h p₁ h₁ p₂ h₂
|
d7eed4edaf2c9b6edd4b2b1cc11ddcb433a4e99c | 92b50235facfbc08dfe7f334827d47281471333b | /library/data/list/basic.lean | dcceeb6224b44709ffd961f85794f4d5d4488c4a | [
"Apache-2.0"
] | permissive | htzh/lean | 24f6ed7510ab637379ec31af406d12584d31792c | d70c79f4e30aafecdfc4a60b5d3512199200ab6e | refs/heads/master | 1,607,677,731,270 | 1,437,089,952,000 | 1,437,089,952,000 | 37,078,816 | 0 | 0 | null | 1,433,780,956,000 | 1,433,780,955,000 | null | UTF-8 | Lean | false | false | 22,958 | lean | /-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura
Basic properties of lists.
-/
import logic tools.helper_tactics data.nat.order
open eq.ops helper_tactics nat prod function option
inductive list (T : Type) : Type :=
| nil {} : list T
| cons : T → list T → list T
namespace list
notation h :: t := cons h t
notation `[` l:(foldr `,` (h t, cons h t) nil `]`) := l
variable {T : Type}
lemma cons_ne_nil [rewrite] (a : T) (l : list T) : a::l ≠ [] :=
by contradiction
lemma head_eq_of_cons_eq {A : Type} {h₁ h₂ : A} {t₁ t₂ : list A} :
(h₁::t₁) = (h₂::t₂) → h₁ = h₂ :=
assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pheq)
lemma tail_eq_of_cons_eq {A : Type} {h₁ h₂ : A} {t₁ t₂ : list A} :
(h₁::t₁) = (h₂::t₂) → t₁ = t₂ :=
assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pteq)
lemma cons_inj {A : Type} {a : A} : injective (cons a) :=
take l₁ l₂, assume Pe, tail_eq_of_cons_eq Pe
/- append -/
definition append : list T → list T → list T
| [] l := l
| (h :: s) t := h :: (append s t)
notation l₁ ++ l₂ := append l₁ l₂
theorem append_nil_left [rewrite] (t : list T) : [] ++ t = t
theorem append_cons [rewrite] (x : T) (s t : list T) : (x::s) ++ t = x::(s ++ t)
theorem append_nil_right [rewrite] : ∀ (t : list T), t ++ [] = t
| [] := rfl
| (a :: l) := calc
(a :: l) ++ [] = a :: (l ++ []) : rfl
... = a :: l : append_nil_right l
theorem append.assoc [rewrite] : ∀ (s t u : list T), s ++ t ++ u = s ++ (t ++ u)
| [] t u := rfl
| (a :: l) t u :=
show a :: (l ++ t ++ u) = (a :: l) ++ (t ++ u),
by rewrite (append.assoc l t u)
/- length -/
definition length : list T → nat
| [] := 0
| (a :: l) := length l + 1
theorem length_nil [rewrite] : length (@nil T) = 0
theorem length_cons [rewrite] (x : T) (t : list T) : length (x::t) = length t + 1
theorem length_append [rewrite] : ∀ (s t : list T), length (s ++ t) = length s + length t
| [] t := calc
length ([] ++ t) = length t : rfl
... = length [] + length t : zero_add
| (a :: s) t := calc
length (a :: s ++ t) = length (s ++ t) + 1 : rfl
... = length s + length t + 1 : length_append
... = (length s + 1) + length t : succ_add
... = length (a :: s) + length t : rfl
theorem eq_nil_of_length_eq_zero : ∀ {l : list T}, length l = 0 → l = []
| [] H := rfl
| (a::s) H := by contradiction
theorem ne_nil_of_length_eq_succ : ∀ {l : list T} {n : nat}, length l = succ n → l ≠ []
| [] n h := by contradiction
| (a::l) n h := by contradiction
-- add_rewrite length_nil length_cons
/- concat -/
definition concat : Π (x : T), list T → list T
| a [] := [a]
| a (b :: l) := b :: concat a l
theorem concat_nil [rewrite] (x : T) : concat x [] = [x]
theorem concat_cons [rewrite] (x y : T) (l : list T) : concat x (y::l) = y::(concat x l)
theorem concat_eq_append (a : T) : ∀ (l : list T), concat a l = l ++ [a]
| [] := rfl
| (b :: l) :=
show b :: (concat a l) = (b :: l) ++ (a :: []),
by rewrite concat_eq_append
theorem concat_ne_nil [rewrite] (a : T) : ∀ (l : list T), concat a l ≠ [] :=
by intro l; induction l; repeat contradiction
/- last -/
definition last : Π l : list T, l ≠ [] → T
| [] h := absurd rfl h
| [a] h := a
| (a₁::a₂::l) h := last (a₂::l) !cons_ne_nil
lemma last_singleton [rewrite] (a : T) (h : [a] ≠ []) : last [a] h = a :=
rfl
lemma last_cons_cons [rewrite] (a₁ a₂ : T) (l : list T) (h : a₁::a₂::l ≠ []) : last (a₁::a₂::l) h = last (a₂::l) !cons_ne_nil :=
rfl
theorem last_congr {l₁ l₂ : list T} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : last l₁ h₁ = last l₂ h₂ :=
by subst l₁
theorem last_concat [rewrite] {x : T} : ∀ {l : list T} (h : concat x l ≠ []), last (concat x l) h = x
| [] h := rfl
| [a] h := rfl
| (a₁::a₂::l) h :=
begin
change last (a₁::a₂::concat x l) !cons_ne_nil = x,
rewrite last_cons_cons,
change last (concat x (a₂::l)) !concat_ne_nil = x,
apply last_concat
end
-- add_rewrite append_nil append_cons
/- reverse -/
definition reverse : list T → list T
| [] := []
| (a :: l) := concat a (reverse l)
theorem reverse_nil [rewrite] : reverse (@nil T) = []
theorem reverse_cons [rewrite] (x : T) (l : list T) : reverse (x::l) = concat x (reverse l)
theorem reverse_singleton [rewrite] (x : T) : reverse [x] = [x]
theorem reverse_append [rewrite] : ∀ (s t : list T), reverse (s ++ t) = (reverse t) ++ (reverse s)
| [] t2 := calc
reverse ([] ++ t2) = reverse t2 : rfl
... = (reverse t2) ++ [] : append_nil_right
... = (reverse t2) ++ (reverse []) : by rewrite reverse_nil
| (a2 :: s2) t2 := calc
reverse ((a2 :: s2) ++ t2) = concat a2 (reverse (s2 ++ t2)) : rfl
... = concat a2 (reverse t2 ++ reverse s2) : reverse_append
... = (reverse t2 ++ reverse s2) ++ [a2] : concat_eq_append
... = reverse t2 ++ (reverse s2 ++ [a2]) : append.assoc
... = reverse t2 ++ concat a2 (reverse s2) : concat_eq_append
... = reverse t2 ++ reverse (a2 :: s2) : rfl
theorem reverse_reverse [rewrite] : ∀ (l : list T), reverse (reverse l) = l
| [] := rfl
| (a :: l) := calc
reverse (reverse (a :: l)) = reverse (concat a (reverse l)) : rfl
... = reverse (reverse l ++ [a]) : concat_eq_append
... = reverse [a] ++ reverse (reverse l) : reverse_append
... = reverse [a] ++ l : reverse_reverse
... = a :: l : rfl
theorem concat_eq_reverse_cons (x : T) (l : list T) : concat x l = reverse (x :: reverse l) :=
calc
concat x l = concat x (reverse (reverse l)) : reverse_reverse
... = reverse (x :: reverse l) : rfl
/- head and tail -/
definition head [h : inhabited T] : list T → T
| [] := arbitrary T
| (a :: l) := a
theorem head_cons [rewrite] [h : inhabited T] (a : T) (l : list T) : head (a::l) = a
theorem head_append [rewrite] [h : inhabited T] (t : list T) : ∀ {s : list T}, s ≠ [] → head (s ++ t) = head s
| [] H := absurd rfl H
| (a :: s) H :=
show head (a :: (s ++ t)) = head (a :: s),
by rewrite head_cons
definition tail : list T → list T
| [] := []
| (a :: l) := l
theorem tail_nil [rewrite] : tail (@nil T) = []
theorem tail_cons [rewrite] (a : T) (l : list T) : tail (a::l) = l
theorem cons_head_tail [h : inhabited T] {l : list T} : l ≠ [] → (head l)::(tail l) = l :=
list.cases_on l
(assume H : [] ≠ [], absurd rfl H)
(take x l, assume H : x::l ≠ [], rfl)
/- list membership -/
definition mem : T → list T → Prop
| a [] := false
| a (b :: l) := a = b ∨ mem a l
notation e ∈ s := mem e s
notation e ∉ s := ¬ e ∈ s
theorem mem_nil_iff [rewrite] (x : T) : x ∈ [] ↔ false :=
iff.rfl
theorem not_mem_nil (x : T) : x ∉ [] :=
iff.mp !mem_nil_iff
theorem mem_cons [rewrite] (x : T) (l : list T) : x ∈ x :: l :=
or.inl rfl
theorem mem_cons_of_mem (y : T) {x : T} {l : list T} : x ∈ l → x ∈ y :: l :=
assume H, or.inr H
theorem mem_cons_iff (x y : T) (l : list T) : x ∈ y::l ↔ (x = y ∨ x ∈ l) :=
iff.rfl
theorem eq_or_mem_of_mem_cons {x y : T} {l : list T} : x ∈ y::l → x = y ∨ x ∈ l :=
assume h, h
theorem mem_singleton {x a : T} : x ∈ [a] → x = a :=
assume h : x ∈ [a], or.elim (eq_or_mem_of_mem_cons h)
(λ xeqa : x = a, xeqa)
(λ xinn : x ∈ [], absurd xinn !not_mem_nil)
theorem mem_of_mem_cons_of_mem {a b : T} {l : list T} : a ∈ b::l → b ∈ l → a ∈ l :=
assume ainbl binl, or.elim (eq_or_mem_of_mem_cons ainbl)
(λ aeqb : a = b, by substvars; exact binl)
(λ ainl : a ∈ l, ainl)
theorem mem_or_mem_of_mem_append {x : T} {s t : list T} : x ∈ s ++ t → x ∈ s ∨ x ∈ t :=
list.induction_on s or.inr
(take y s,
assume IH : x ∈ s ++ t → x ∈ s ∨ x ∈ t,
assume H1 : x ∈ y::s ++ t,
have H2 : x = y ∨ x ∈ s ++ t, from H1,
have H3 : x = y ∨ x ∈ s ∨ x ∈ t, from or_of_or_of_imp_right H2 IH,
iff.elim_right or.assoc H3)
theorem mem_append_of_mem_or_mem {x : T} {s t : list T} : x ∈ s ∨ x ∈ t → x ∈ s ++ t :=
list.induction_on s
(take H, or.elim H false.elim (assume H, H))
(take y s,
assume IH : x ∈ s ∨ x ∈ t → x ∈ s ++ t,
assume H : x ∈ y::s ∨ x ∈ t,
or.elim H
(assume H1,
or.elim (eq_or_mem_of_mem_cons H1)
(take H2 : x = y, or.inl H2)
(take H2 : x ∈ s, or.inr (IH (or.inl H2))))
(assume H1 : x ∈ t, or.inr (IH (or.inr H1))))
theorem mem_append_iff (x : T) (s t : list T) : x ∈ s ++ t ↔ x ∈ s ∨ x ∈ t :=
iff.intro mem_or_mem_of_mem_append mem_append_of_mem_or_mem
theorem not_mem_of_not_mem_append_left {x : T} {s t : list T} : x ∉ s++t → x ∉ s :=
λ nxinst xins, absurd (mem_append_of_mem_or_mem (or.inl xins)) nxinst
theorem not_mem_of_not_mem_append_right {x : T} {s t : list T} : x ∉ s++t → x ∉ t :=
λ nxinst xint, absurd (mem_append_of_mem_or_mem (or.inr xint)) nxinst
theorem not_mem_append {x : T} {s t : list T} : x ∉ s → x ∉ t → x ∉ s++t :=
λ nxins nxint xinst, or.elim (mem_or_mem_of_mem_append xinst)
(λ xins, by contradiction)
(λ xint, by contradiction)
lemma length_pos_of_mem {a : T} : ∀ {l : list T}, a ∈ l → 0 < length l
| [] := assume Pinnil, by contradiction
| (b::l) := assume Pin, !zero_lt_succ
local attribute mem [reducible]
local attribute append [reducible]
theorem mem_split {x : T} {l : list T} : x ∈ l → ∃s t : list T, l = s ++ (x::t) :=
list.induction_on l
(take H : x ∈ [], false.elim (iff.elim_left !mem_nil_iff H))
(take y l,
assume IH : x ∈ l → ∃s t : list T, l = s ++ (x::t),
assume H : x ∈ y::l,
or.elim (eq_or_mem_of_mem_cons H)
(assume H1 : x = y,
exists.intro [] (!exists.intro (H1 ▸ rfl)))
(assume H1 : x ∈ l,
obtain s (H2 : ∃t : list T, l = s ++ (x::t)), from IH H1,
obtain t (H3 : l = s ++ (x::t)), from H2,
have H4 : y :: l = (y::s) ++ (x::t),
from H3 ▸ rfl,
!exists.intro (!exists.intro H4)))
theorem mem_append_left {a : T} {l₁ : list T} (l₂ : list T) : a ∈ l₁ → a ∈ l₁ ++ l₂ :=
assume ainl₁, mem_append_of_mem_or_mem (or.inl ainl₁)
theorem mem_append_right {a : T} (l₁ : list T) {l₂ : list T} : a ∈ l₂ → a ∈ l₁ ++ l₂ :=
assume ainl₂, mem_append_of_mem_or_mem (or.inr ainl₂)
definition decidable_mem [instance] [H : decidable_eq T] (x : T) (l : list T) : decidable (x ∈ l) :=
list.rec_on l
(decidable.inr (not_of_iff_false !mem_nil_iff))
(take (h : T) (l : list T) (iH : decidable (x ∈ l)),
show decidable (x ∈ h::l), from
decidable.rec_on iH
(assume Hp : x ∈ l,
decidable.rec_on (H x h)
(assume Heq : x = h,
decidable.inl (or.inl Heq))
(assume Hne : x ≠ h,
decidable.inl (or.inr Hp)))
(assume Hn : ¬x ∈ l,
decidable.rec_on (H x h)
(assume Heq : x = h,
decidable.inl (or.inl Heq))
(assume Hne : x ≠ h,
have H1 : ¬(x = h ∨ x ∈ l), from
assume H2 : x = h ∨ x ∈ l, or.elim H2
(assume Heq, by contradiction)
(assume Hp, by contradiction),
have H2 : ¬x ∈ h::l, from
iff.elim_right (not_iff_not_of_iff !mem_cons_iff) H1,
decidable.inr H2)))
theorem mem_of_ne_of_mem {x y : T} {l : list T} (H₁ : x ≠ y) (H₂ : x ∈ y :: l) : x ∈ l :=
or.elim (eq_or_mem_of_mem_cons H₂) (λe, absurd e H₁) (λr, r)
theorem ne_of_not_mem_cons {a b : T} {l : list T} : a ∉ b::l → a ≠ b :=
assume nin aeqb, absurd (or.inl aeqb) nin
theorem not_mem_of_not_mem_cons {a b : T} {l : list T} : a ∉ b::l → a ∉ l :=
assume nin nainl, absurd (or.inr nainl) nin
lemma not_mem_cons_of_ne_of_not_mem {x y : T} {l : list T} : x ≠ y → x ∉ l → x ∉ y::l :=
assume P1 P2, not.intro (assume Pxin, absurd (eq_or_mem_of_mem_cons Pxin) (not_or P1 P2))
lemma ne_and_not_mem_of_not_mem_cons {x y : T} {l : list T} : x ∉ y::l → x ≠ y ∧ x ∉ l :=
assume P, and.intro (ne_of_not_mem_cons P) (not_mem_of_not_mem_cons P)
definition sublist (l₁ l₂ : list T) := ∀ ⦃a : T⦄, a ∈ l₁ → a ∈ l₂
infix `⊆` := sublist
theorem nil_sub [rewrite] (l : list T) : [] ⊆ l :=
λ b i, false.elim (iff.mp (mem_nil_iff b) i)
theorem sub.refl [rewrite] (l : list T) : l ⊆ l :=
λ b i, i
theorem sub.trans {l₁ l₂ l₃ : list T} (H₁ : l₁ ⊆ l₂) (H₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ :=
λ b i, H₂ (H₁ i)
theorem sub_cons [rewrite] (a : T) (l : list T) : l ⊆ a::l :=
λ b i, or.inr i
theorem sub_of_cons_sub {a : T} {l₁ l₂ : list T} : a::l₁ ⊆ l₂ → l₁ ⊆ l₂ :=
λ s b i, s b (mem_cons_of_mem _ i)
theorem cons_sub_cons {l₁ l₂ : list T} (a : T) (s : l₁ ⊆ l₂) : (a::l₁) ⊆ (a::l₂) :=
λ b Hin, or.elim (eq_or_mem_of_mem_cons Hin)
(λ e : b = a, or.inl e)
(λ i : b ∈ l₁, or.inr (s i))
theorem sub_append_left [rewrite] (l₁ l₂ : list T) : l₁ ⊆ l₁++l₂ :=
λ b i, iff.mp' (mem_append_iff b l₁ l₂) (or.inl i)
theorem sub_append_right [rewrite] (l₁ l₂ : list T) : l₂ ⊆ l₁++l₂ :=
λ b i, iff.mp' (mem_append_iff b l₁ l₂) (or.inr i)
theorem sub_cons_of_sub (a : T) {l₁ l₂ : list T} : l₁ ⊆ l₂ → l₁ ⊆ (a::l₂) :=
λ (s : l₁ ⊆ l₂) (x : T) (i : x ∈ l₁), or.inr (s i)
theorem sub_app_of_sub_left (l l₁ l₂ : list T) : l ⊆ l₁ → l ⊆ l₁++l₂ :=
λ (s : l ⊆ l₁) (x : T) (xinl : x ∈ l),
have xinl₁ : x ∈ l₁, from s xinl,
mem_append_of_mem_or_mem (or.inl xinl₁)
theorem sub_app_of_sub_right (l l₁ l₂ : list T) : l ⊆ l₂ → l ⊆ l₁++l₂ :=
λ (s : l ⊆ l₂) (x : T) (xinl : x ∈ l),
have xinl₁ : x ∈ l₂, from s xinl,
mem_append_of_mem_or_mem (or.inr xinl₁)
theorem cons_sub_of_sub_of_mem {a : T} {l m : list T} : a ∈ m → l ⊆ m → a::l ⊆ m :=
λ (ainm : a ∈ m) (lsubm : l ⊆ m) (x : T) (xinal : x ∈ a::l), or.elim (eq_or_mem_of_mem_cons xinal)
(assume xeqa : x = a, by substvars; exact ainm)
(assume xinl : x ∈ l, lsubm xinl)
theorem app_sub_of_sub_of_sub {l₁ l₂ l : list T} : l₁ ⊆ l → l₂ ⊆ l → l₁++l₂ ⊆ l :=
λ (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) (x : T) (xinl₁l₂ : x ∈ l₁++l₂),
or.elim (mem_or_mem_of_mem_append xinl₁l₂)
(λ xinl₁ : x ∈ l₁, l₁subl xinl₁)
(λ xinl₂ : x ∈ l₂, l₂subl xinl₂)
/- find -/
section
variable [H : decidable_eq T]
include H
definition find : T → list T → nat
| a [] := 0
| a (b :: l) := if a = b then 0 else succ (find a l)
theorem find_nil [rewrite] (x : T) : find x [] = 0
theorem find_cons (x y : T) (l : list T) : find x (y::l) = if x = y then 0 else succ (find x l)
theorem find_cons_of_eq {x y : T} (l : list T) : x = y → find x (y::l) = 0 :=
assume e, if_pos e
theorem find_cons_of_ne {x y : T} (l : list T) : x ≠ y → find x (y::l) = succ (find x l) :=
assume n, if_neg n
theorem find_of_not_mem {l : list T} {x : T} : ¬x ∈ l → find x l = length l :=
list.rec_on l
(assume P₁ : ¬x ∈ [], _)
(take y l,
assume iH : ¬x ∈ l → find x l = length l,
assume P₁ : ¬x ∈ y::l,
have P₂ : ¬(x = y ∨ x ∈ l), from iff.elim_right (not_iff_not_of_iff !mem_cons_iff) P₁,
have P₃ : ¬x = y ∧ ¬x ∈ l, from (iff.elim_left not_or_iff_not_and_not P₂),
calc
find x (y::l) = if x = y then 0 else succ (find x l) : !find_cons
... = succ (find x l) : if_neg (and.elim_left P₃)
... = succ (length l) : {iH (and.elim_right P₃)}
... = length (y::l) : !length_cons⁻¹)
lemma find_le_length : ∀ {a} {l : list T}, find a l ≤ length l
| a [] := !le.refl
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq]; exact !zero_le)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons],
apply succ_le_succ, apply find_le_length
end)
lemma not_mem_of_find_eq_length : ∀ {a} {l : list T}, find a l = length l → a ∉ l
| a [] := assume Peq, !not_mem_nil
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq, length_cons]; contradiction)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons, mem_cons_iff],
intro Plen, apply (not_or Pne),
exact not_mem_of_find_eq_length (succ.inj Plen)
end)
lemma find_lt_length {a} {l : list T} (Pin : a ∈ l) : find a l < length l :=
begin
apply nat.lt_of_le_and_ne,
apply find_le_length,
apply not.intro, intro Peq,
exact absurd Pin (not_mem_of_find_eq_length Peq)
end
end
/- nth element -/
section nth
definition nth : list T → nat → option T
| [] n := none
| (a :: l) 0 := some a
| (a :: l) (n+1) := nth l n
theorem nth_zero [rewrite] (a : T) (l : list T) : nth (a :: l) 0 = some a
theorem nth_succ [rewrite] (a : T) (l : list T) (n : nat) : nth (a::l) (succ n) = nth l n
theorem nth_eq_some : ∀ {l : list T} {n : nat}, n < length l → Σ a : T, nth l n = some a
| [] n h := absurd h !not_lt_zero
| (a::l) 0 h := ⟨a, rfl⟩
| (a::l) (succ n) h :=
have aux : n < length l, from lt_of_succ_lt_succ h,
obtain (r : T) (req : nth l n = some r), from nth_eq_some aux,
⟨r, by rewrite [nth_succ, req]⟩
open decidable
theorem find_nth [h : decidable_eq T] {a : T} : ∀ {l}, a ∈ l → nth l (find a l) = some a
| [] ain := absurd ain !not_mem_nil
| (b::l) ainbl := by_cases
(λ aeqb : a = b, by rewrite [find_cons_of_eq _ aeqb, nth_zero, aeqb])
(λ aneb : a ≠ b, or.elim (eq_or_mem_of_mem_cons ainbl)
(λ aeqb : a = b, absurd aeqb aneb)
(λ ainl : a ∈ l, by rewrite [find_cons_of_ne _ aneb, nth_succ, find_nth ainl]))
definition inth [h : inhabited T] (l : list T) (n : nat) : T :=
match nth l n with
| some a := a
| none := arbitrary T
end
theorem inth_zero [h : inhabited T] (a : T) (l : list T) : inth (a :: l) 0 = a
theorem inth_succ [h : inhabited T] (a : T) (l : list T) (n : nat) : inth (a::l) (n+1) = inth l n
end nth
open decidable
definition has_decidable_eq {A : Type} [H : decidable_eq A] : ∀ l₁ l₂ : list A, decidable (l₁ = l₂)
| [] [] := inl rfl
| [] (b::l₂) := inr (by contradiction)
| (a::l₁) [] := inr (by contradiction)
| (a::l₁) (b::l₂) :=
match H a b with
| inl Hab :=
match has_decidable_eq l₁ l₂ with
| inl He := inl (by congruence; repeat assumption)
| inr Hn := inr (by intro H; injection H; contradiction)
end
| inr Hnab := inr (by intro H; injection H; contradiction)
end
/- quasiequal a l l' means that l' is exactly l, with a added
once somewhere -/
section qeq
variable {A : Type}
inductive qeq (a : A) : list A → list A → Prop :=
| qhead : ∀ l, qeq a l (a::l)
| qcons : ∀ (b : A) {l l' : list A}, qeq a l l' → qeq a (b::l) (b::l')
open qeq
notation l' `≈`:50 a `|` l:50 := qeq a l l'
theorem qeq_app : ∀ (l₁ : list A) (a : A) (l₂ : list A), l₁++(a::l₂) ≈ a|l₁++l₂
| [] a l₂ := qhead a l₂
| (x::xs) a l₂ := qcons x (qeq_app xs a l₂)
theorem mem_head_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → a ∈ l₁ :=
take q, qeq.induction_on q
(λ l, !mem_cons)
(λ b l l' q r, or.inr r)
theorem mem_tail_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → ∀ x, x ∈ l₂ → x ∈ l₁ :=
take q, qeq.induction_on q
(λ l x i, or.inr i)
(λ b l l' q r x xinbl, or.elim (eq_or_mem_of_mem_cons xinbl)
(λ xeqb : x = b, xeqb ▸ mem_cons x l')
(λ xinl : x ∈ l, or.inr (r x xinl)))
theorem mem_cons_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → ∀ x, x ∈ l₁ → x ∈ a::l₂ :=
take q, qeq.induction_on q
(λ l x i, i)
(λ b l l' q r x xinbl', or.elim (eq_or_mem_of_mem_cons xinbl')
(λ xeqb : x = b, xeqb ▸ or.inr (mem_cons x l))
(λ xinl' : x ∈ l', or.elim (eq_or_mem_of_mem_cons (r x xinl'))
(λ xeqa : x = a, xeqa ▸ mem_cons x (b::l))
(λ xinl : x ∈ l, or.inr (or.inr xinl))))
theorem length_eq_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → length l₁ = succ (length l₂) :=
take q, qeq.induction_on q
(λ l, rfl)
(λ b l l' q r, by rewrite [*length_cons, r])
theorem qeq_of_mem {a : A} {l : list A} : a ∈ l → (∃l', l≈a|l') :=
list.induction_on l
(λ h : a ∈ nil, absurd h (not_mem_nil a))
(λ x xs r ainxxs, or.elim (eq_or_mem_of_mem_cons ainxxs)
(λ aeqx : a = x,
assert aux : ∃ l, x::xs≈x|l, from
exists.intro xs (qhead x xs),
by rewrite aeqx; exact aux)
(λ ainxs : a ∈ xs,
have ex : ∃l', xs ≈ a|l', from r ainxs,
obtain (l' : list A) (q : xs ≈ a|l'), from ex,
have q₂ : x::xs ≈ a | x::l', from qcons x q,
exists.intro (x::l') q₂))
theorem qeq_split {a : A} {l l' : list A} : l'≈a|l → ∃l₁ l₂, l = l₁++l₂ ∧ l' = l₁++(a::l₂) :=
take q, qeq.induction_on q
(λ t,
have aux : t = []++t ∧ a::t = []++(a::t), from and.intro rfl rfl,
exists.intro [] (exists.intro t aux))
(λ b t t' q r,
obtain (l₁ l₂ : list A) (h : t = l₁++l₂ ∧ t' = l₁++(a::l₂)), from r,
have aux : b::t = (b::l₁)++l₂ ∧ b::t' = (b::l₁)++(a::l₂),
begin
rewrite [and.elim_right h, and.elim_left h],
constructor, repeat reflexivity
end,
exists.intro (b::l₁) (exists.intro l₂ aux))
theorem sub_of_mem_of_sub_of_qeq {a : A} {l : list A} {u v : list A} : a ∉ l → a::l ⊆ v → v≈a|u → l ⊆ u :=
λ (nainl : a ∉ l) (s : a::l ⊆ v) (q : v≈a|u) (x : A) (xinl : x ∈ l),
have xinv : x ∈ v, from s (or.inr xinl),
have xinau : x ∈ a::u, from mem_cons_of_qeq q x xinv,
or.elim (eq_or_mem_of_mem_cons xinau)
(λ xeqa : x = a, by substvars; contradiction)
(λ xinu : x ∈ u, xinu)
end qeq
end list
attribute list.has_decidable_eq [instance]
attribute list.decidable_mem [instance]
|
4fa7d5db01511069d86eee95a033a4e5423fd80c | 94935fb4ab68d4ce640296d02911624a93282575 | /src/solutions/thursday/afternoon/category_theory/exercise17.lean | 34bfad7807a55ce5e97729988f19343ce24b4248 | [] | permissive | marius-leonhardt/lftcm2020 | 41c0d7fe3457c1cf3b72cbb1c312b48fc94b85d2 | a3eb53f18d9be9a5be748dfe8fe74d0d31a0c1f7 | refs/heads/master | 1,668,623,789,936 | 1,594,710,949,000 | 1,594,710,949,000 | 279,514,936 | 0 | 0 | MIT | 1,594,711,916,000 | 1,594,711,916,000 | null | UTF-8 | Lean | false | false | 3,675 | lean | import algebra.category.CommRing.basic
import data.polynomial
/-!
Let's show that taking polynomials over a ring is functor `Ring ⥤ Ring`.
-/
noncomputable theory -- the default implementation of polynomials is noncomputable
-- Just ignore this for now: it's a hack that prevents an annoying problem,
-- and cleaner fix is on its way to mathlib.
local attribute [irreducible] polynomial.eval₂
/-!
mathlib is undergoing a transition at the moment from using "unbundled" homomorphisms
(e.g. we talk about a bare function `f : R → S`, along with a typeclass `[is_semiring_hom f]`)
to using "bundled" homomorphisms
(e.g. a structure `f : R →+* S`, which has a coercion to a bare function).
The category `Ring` uses bundled homomorphisms (and in future all of mathlib will).
However at present the polynomial library hasn't been updated.
You may find the `ring_hom.of` useful -- this upgrades an unbundled homomorphism
to a bundled homomorphism.
-/
/-!
Hints:
* use `polynomial.map`
-/
def Ring.polynomial : Ring ⥤ Ring :=
-- sorry
{ obj := λ R, Ring.of (polynomial R),
map := λ R S f, ring_hom.of (polynomial.map f), }
-- sorry
def CommRing.polynomial : CommRing ⥤ CommRing :=
-- sorry
{ obj := λ R, CommRing.of (polynomial R),
map := λ R S f, ring_hom.of (polynomial.map f), }
-- sorry
open category_theory
def commutes :
(forget₂ CommRing Ring) ⋙ Ring.polynomial ≅ CommRing.polynomial ⋙ (forget₂ CommRing Ring) :=
-- Hint: You can do this in two lines, ≤ 33 columns!
-- sorry
{ hom := { app := λ R, 𝟙 _, },
inv := { app := λ R, 𝟙 _, }, }.
-- sorry
/-!
Bonus problem:
Why did we set `local attribute [irreducible] polynomial.eval₂`?
What goes wrong without it? Why?
-/
-- omit
local attribute [semireducible] polynomial.eval₂
def Ring.polynomial' : Ring ⥤ Ring :=
{ obj := λ R, Ring.of (polynomial R),
map := λ R S f, ring_hom.of (polynomial.map f),
map_comp' := λ R S T f g, begin refl end, }. -- fails, but takes >5s seconds to do so!
/-!
What's going on?
For some reason trying to solve the goal in `map_comp'` using `refl` takes a huge amount of time.
This causes the automation which is responsible for
automatically proving functoriality of functors to time out, and fail.
How can `refl` take so long? Isn't it just checking if two things are the same?
The problem is that when we work in type theory, in principle no definition is "opaque",
and Lean sometimes has to unfold definitions in order to compare if two things are actually the same.
Usually it's pretty conservative about this, and manages to avoid unfolding too deeply
before coming up with an answer, but in bad cases it can get really bad.
Somehow this is happening here!
The solution we have available is to mark definitions as `[irreducible]`,
which (almost, but not quite completely) prevents Lean from unfolding when checking
definitional equality. Of course, this has a consequence --- Lean will sometimes
fail to prove things by `refl` now!
The solution to this is to provide a thorough API for our important definitions,
so that after some point in the development one never needs to unfold the actual definition again,
but one can work through theorems proved about the definition
(e.g. characterisations and universal properties).
An important example of this is that we have marked `real` as `[irreducible]` in Lean ---
after you've got things working, no one should ever have to know whether the "actual definition"
is in terms of Cauchy sequences or Dedekind cuts.
Unfortunately at this point we don't use `[irreducible]` often enough in Lean, and improving this
aspect of mathlib is an ongoin project.
-/
-- omit
|
a3b66da087b8b6aea4c730befe985b7aca352127 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/elab_cmd.lean | 6f4f805a9af123b63b0ad5a6270b57b92b676737 | [
"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 | 663 | lean | import Lean
open Lean.Elab.Term
open Lean.Elab.Command
elab "∃'" b:term "," P:term : term => do
let ex ← `(Exists (fun $b => $P));
elabTerm ex none
elab "#check2" b:term : command => do
let cmd ← `(#check $b #check $b);
elabCommand cmd
#check ∃' x, x > 0
#check ∃' (x : UInt32), x > 0
#check2 10
elab "try" t:tactic : tactic => do
let t' ← `(tactic| first | $t:tactic | skip);
Lean.Elab.Tactic.evalTactic t'
theorem tst (x y z : Nat) : y = z → x = x → x = y → x = z :=
by {
intro h1; intro h2; intro h3;
apply @Eq.trans;
try exact h1; -- `exact h1` fails
trace_state;
try exact h3;
trace_state;
try exact h1;
}
|
e6a038bee115ff0467fc92fd62f70bc89f3b3a94 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/tactic/simps.lean | 965f66946a5b62927fb7c8ee03658cfff090fcb3 | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 46,702 | lean | /-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import algebra.group.to_additive
import tactic.protected
import data.sum
/-!
# simps attribute
This file defines the `@[simps]` attribute, to automatically generate `simp` lemmas
reducing a definition when projections are applied to it.
## Implementation Notes
There are three attributes being defined here
* `@[simps]` is the attribute for objects of a structure or instances of a class. It will
automatically generate simplification lemmas for each projection of the object/instance that
contains data. See the doc strings for `simps_attr` and `simps_cfg` for more details and
configuration options.
* `@[_simps_str]` is automatically added to structures that have been used in `@[simps]` at least
once. This attribute contains the data of the projections used for this structure by all following
invocations of `@[simps]`.
* `@[notation_class]` should be added to all classes that define notation, like `has_mul` and
`has_zero`. This specifies that the projections that `@[simps]` used are the projections from
these notation classes instead of the projections of the superclasses.
Example: if `has_mul` is tagged with `@[notation_class]` then the projection used for `semigroup`
will be `λ α hα, @has_mul.mul α (@semigroup.to_has_mul α hα)` instead of `@semigroup.mul`.
## Tags
structures, projections, simp, simplifier, generates declarations
-/
open tactic expr option sum
setup_tactic_parser
declare_trace simps.verbose
declare_trace simps.debug
/--
Projection data for a single projection of a structure, consisting of the following fields:
- the name used in the generated `simp` lemmas
- an expression used by simps for the projection. It must be definitionally equal to an original
projection (or a composition of multiple projections).
These expressions can contain the universe parameters specified in the first argument of
`simps_str_attr`.
- a list of natural numbers, which is the projection number(s) that have to be applied to the
expression. For example the list `[0, 1]` corresponds to applying the first projection of the
structure, and then the second projection of the resulting structure (this assumes that the
target of the first projection is a structure with at least two projections).
The composition of these projections is required to be definitionally equal to the provided
expression.
- A boolean specifying whether `simp` lemmas are generated for this projection by default.
- A boolean specifying whether this projection is written as prefix.
-/
@[protect_proj, derive [has_reflect, inhabited]]
meta structure projection_data :=
(name : name)
(expr : expr)
(proj_nrs : list ℕ)
(is_default : bool)
(is_prefix : bool)
/-- Temporary projection data parsed from `initialize_simps_projections` before the expression
matching this projection has been found. Only used internally in `simps_get_raw_projections`. -/
meta structure parsed_projection_data :=
(orig_name : name) -- name for this projection used in the structure definition
(new_name : name) -- name for this projection used in the generated `simp` lemmas
(is_default : bool)
(is_prefix : bool)
section
open format
meta instance : has_to_tactic_format projection_data :=
⟨λ ⟨a, b, c, d, e⟩, (λ x, group $ nest 1 $ to_fmt "⟨" ++ to_fmt a ++ to_fmt "," ++ line ++ x ++
to_fmt "," ++ line ++ to_fmt c ++ to_fmt "," ++ line ++ to_fmt d ++ to_fmt "," ++ line ++
to_fmt e ++ to_fmt "⟩") <$> pp b⟩
meta instance : has_to_format parsed_projection_data :=
⟨λ ⟨a, b, c, d⟩, group $ nest 1 $ to_fmt "⟨" ++ to_fmt a ++ to_fmt "," ++ line ++ to_fmt b ++
to_fmt "," ++ line ++ to_fmt c ++ to_fmt "," ++ line ++ to_fmt d ++ to_fmt "⟩"⟩
end
/-- The type of rules that specify how metadata for projections in changes.
See `initialize_simps_projection`. -/
abbreviation projection_rule := (name × name ⊕ name) × bool
/--
The `@[_simps_str]` attribute specifies the preferred projections of the given structure,
used by the `@[simps]` attribute.
- This will usually be tagged by the `@[simps]` tactic.
- You can also generate this with the command `initialize_simps_projections`.
- To change the default value, see Note [custom simps projection].
- You are strongly discouraged to add this attribute manually.
- The first argument is the list of names of the universe variables used in the structure
- The second argument is a list that consists of the projection data for each projection.
-/
@[user_attribute] meta def simps_str_attr :
user_attribute unit (list name × list projection_data) :=
{ name := `_simps_str,
descr := "An attribute specifying the projection of the given structure.",
parser := failed }
/--
The `@[notation_class]` attribute specifies that this is a notation class,
and this notation should be used instead of projections by @[simps].
* The first argument `tt` for notation classes and `ff` for classes applied to the structure,
like `has_coe_to_sort` and `has_coe_to_fun`
* The second argument is the name of the projection (by default it is the first projection
of the structure)
-/
@[user_attribute] meta def notation_class_attr : user_attribute unit (bool × option name) :=
{ name := `notation_class,
descr := "An attribute specifying that this is a notation class. Used by @[simps].",
parser := prod.mk <$> (option.is_none <$> (tk "*")?) <*> ident? }
attribute [notation_class] has_zero has_one has_add has_mul has_inv has_neg has_sub has_div has_dvd
has_mod has_le has_lt has_append has_andthen has_union has_inter has_sdiff has_equiv has_subset
has_ssubset has_emptyc has_insert has_singleton has_sep has_mem has_pow
attribute [notation_class* coe_sort] has_coe_to_sort
attribute [notation_class* coe_fn] has_coe_to_fun
/-- Returns the projection information of a structure. -/
meta def projections_info (l : list projection_data) (pref : string) (str : name) : tactic format :=
do
⟨defaults, nondefaults⟩ ← return $ l.partition_map $
λ s, if s.is_default then inl s else inr s,
to_print ← defaults.mmap $ λ s, to_string <$>
let prefix_str := if s.is_prefix then "(prefix) " else "" in
pformat!"Projection {prefix_str}{s.name}: {s.expr}",
let print2 :=
string.join $ (nondefaults.map (λ nm : projection_data, to_string nm.1)).intersperse ", ",
let to_print := to_print ++ if nondefaults.length = 0 then [] else
["No lemmas are generated for the projections: " ++ print2 ++ "."],
let to_print := string.join $ to_print.intersperse "\n > ",
return format!"[simps] > {pref} {str}:\n > {to_print}"
/-- Auxiliary function of `get_composite_of_projections`. -/
meta def get_composite_of_projections_aux : Π (str : name) (proj : string) (x : expr)
(pos : list ℕ) (args : list expr), tactic (expr × list ℕ) | str proj x pos args := do
e ← get_env,
projs ← e.structure_fields str,
let proj_info := projs.map_with_index $ λ n p, (λ x, (x, n, p)) <$> proj.get_rest ("_" ++ p.last),
when (proj_info.filter_map id = []) $
fail!"Failed to find constructor {proj.popn 1} in structure {str}.",
(proj_rest, index, proj_nm) ← return (proj_info.filter_map id).ilast,
str_d ← e.get str,
let proj_e : expr := const (str ++ proj_nm) str_d.univ_levels,
proj_d ← e.get (str ++ proj_nm),
type ← infer_type x,
let params := get_app_args type,
let univs := proj_d.univ_params.zip type.get_app_fn.univ_levels,
let new_x := (proj_e.instantiate_univ_params univs).mk_app $ params ++ [x],
let new_pos := pos ++ [index],
if proj_rest.is_empty then return (new_x.lambdas args, new_pos) else do
type ← infer_type new_x,
(type_args, tgt) ← open_pis_whnf type,
let new_str := tgt.get_app_fn.const_name,
get_composite_of_projections_aux new_str proj_rest (new_x.mk_app type_args) new_pos
(args ++ type_args)
/-- Given a structure `str` and a projection `proj`, that could be multiple nested projections
(separated by `_`), returns an expression that is the composition of these projections and a
list of natural numbers, that are the projection numbers of the applied projections. -/
meta def get_composite_of_projections (str : name) (proj : string) : tactic (expr × list ℕ) := do
e ← get_env,
str_d ← e.get str,
let str_e : expr := const str str_d.univ_levels,
type ← infer_type str_e,
(type_args, tgt) ← open_pis_whnf type,
let str_ap := str_e.mk_app type_args,
x ← mk_local' `x binder_info.default str_ap,
get_composite_of_projections_aux str ("_" ++ proj) x [] $ type_args ++ [x]
/--
Get the projections used by `simps` associated to a given structure `str`.
The returned information is also stored in a parameter of the attribute `@[_simps_str]`, which
is given to `str`. If `str` already has this attribute, the information is read from this
attribute instead. See the documentation for this attribute for the data this tactic returns.
The returned universe levels are the universe levels of the structure. For the projections there
are three cases
* If the declaration `{structure_name}.simps.{projection_name}` has been declared, then the value
of this declaration is used (after checking that it is definitionally equal to the actual
projection. If you rename the projection name, the declaration should have the *new* projection
name.
* You can also declare a custom projection that is a composite of multiple projections.
* Otherwise, for every class with the `notation_class` attribute, and the structure has an
instance of that notation class, then the projection of that notation class is used for the
projection that is definitionally equal to it (if there is such a projection).
This means in practice that coercions to function types and sorts will be used instead of
a projection, if this coercion is definitionally equal to a projection. Furthermore, for
notation classes like `has_mul` and `has_zero` those projections are used instead of the
corresponding projection.
Projections for coercions and notation classes are not automatically generated if they are
composites of multiple projections (for example when you use `extend` without the
`old_structure_cmd`).
* Otherwise, the projection of the structure is chosen.
For example: ``simps_get_raw_projections env `prod`` gives the default projections
```
([u, v], [prod.fst.{u v}, prod.snd.{u v}])
```
while ``simps_get_raw_projections env `equiv`` gives
```
([u_1, u_2], [λ α β, coe_fn, λ {α β} (e : α ≃ β), ⇑(e.symm), left_inv, right_inv])
```
after declaring the coercion from `equiv` to function and adding the declaration
```
def equiv.simps.inv_fun {α β} (e : α ≃ β) : β → α := e.symm
```
Optionally, this command accepts three optional arguments:
* If `trace_if_exists` the command will always generate a trace message when the structure already
has the attribute `@[_simps_str]`.
* The `rules` argument accepts a list of pairs `sum.inl (old_name, new_name)`. This is used to
change the projection name `old_name` to the custom projection name `new_name`. Example:
for the structure `equiv` the projection `to_fun` could be renamed `apply`. This name will be
used for parsing and generating projection names. This argument is ignored if the structure
already has an existing attribute. If an element of `rules` is of the form `sum.inr name`, this
means that the projection `name` will not be applied by default.
* if `trc` is true, this tactic will trace information.
-/
-- if performance becomes a problem, possible heuristic: use the names of the projections to
-- skip all classes that don't have the corresponding field.
meta def simps_get_raw_projections (e : environment) (str : name) (trace_if_exists : bool := ff)
(rules : list projection_rule := []) (trc := ff) :
tactic (list name × list projection_data) := do
let trc := trc || is_trace_enabled_for `simps.verbose,
has_attr ← has_attribute' `_simps_str str,
if has_attr then do
data ← simps_str_attr.get_param str,
-- We always print the projections when they already exists and are called by
-- `initialize_simps_projections`.
when (trace_if_exists || is_trace_enabled_for `simps.verbose) $ projections_info data.2
"Already found projection information for structure" str >>= trace,
return data
else do
when trc trace!"[simps] > generating projection information for structure {str}.",
when_tracing `simps.debug trace!"[simps] > Applying the rules {rules}.",
d_str ← e.get str,
let raw_univs := d_str.univ_params,
let raw_levels := level.param <$> raw_univs,
/- Figure out projections, including renamings. The information for a projection is (before we
figure out the `expr` of the projection:
`(original name, given name, is default, is prefix)`.
The first projections are always the actual projections of the structure, but `rules` could
specify custom projections that are compositions of multiple projections. -/
projs ← e.structure_fields str,
let projs : list parsed_projection_data := projs.map $ λ nm, ⟨nm, nm, tt, ff⟩,
let projs : list parsed_projection_data := rules.foldl (λ projs rule,
match rule with
| (inl (old_nm, new_nm), is_prefix) := if old_nm ∈ projs.map (λ x, x.new_name) then
projs.map $ λ proj,
if proj.new_name = old_nm then
{ new_name := new_nm, is_prefix := is_prefix, ..proj } else
proj else
projs ++ [⟨old_nm, new_nm, tt, is_prefix⟩]
| (inr nm, is_prefix) := if nm ∈ projs.map (λ x, x.new_name) then
projs.map $ λ proj, if proj.new_name = nm then
{ is_default := ff, is_prefix := is_prefix, ..proj } else
proj else
projs ++ [⟨nm, nm, ff, is_prefix⟩]
end) projs,
when_tracing `simps.debug trace!"[simps] > Projection info after applying the rules: {projs}.",
when ¬ (projs.map $ λ x, x.new_name : list name).nodup $
fail $ "Invalid projection names. Two projections have the same name.
This is likely because a custom composition of projections was given the same name as an " ++
"existing projection. Solution: rename the existing projection (before renaming the custom " ++
"projection).",
/- Define the raw expressions for the projections, by default as the projections
(as an expression), but this can be overriden by the user. -/
raw_exprs_and_nrs ← projs.mmap $ λ ⟨orig_nm, new_nm, _, _⟩, do {
(raw_expr, nrs) ← get_composite_of_projections str orig_nm.last,
custom_proj ← do {
decl ← e.get (str ++ `simps ++ new_nm.last),
let custom_proj := decl.value.instantiate_univ_params $ decl.univ_params.zip raw_levels,
when trc trace!
"[simps] > found custom projection for {new_nm}:\n > {custom_proj}",
return custom_proj } <|> return raw_expr,
is_def_eq custom_proj raw_expr <|>
-- if the type of the expression is different, we show a different error message, because
-- that is more likely going to be helpful.
do {
custom_proj_type ← infer_type custom_proj,
raw_expr_type ← infer_type raw_expr,
b ← succeeds (is_def_eq custom_proj_type raw_expr_type),
if b then fail!"Invalid custom projection:\n {custom_proj}
Expression is not definitionally equal to\n {raw_expr}"
else fail!"Invalid custom projection:\n {custom_proj}
Expression has different type than {str ++ orig_nm}. Given type:\n {custom_proj_type}
Expected type:\n {raw_expr_type}" },
return (custom_proj, nrs) },
let raw_exprs := raw_exprs_and_nrs.map prod.fst,
/- Check for other coercions and type-class arguments to use as projections instead. -/
(args, _) ← open_pis d_str.type,
let e_str := (expr.const str raw_levels).mk_app args,
automatic_projs ← attribute.get_instances `notation_class,
raw_exprs ← automatic_projs.mfoldl (λ (raw_exprs : list expr) class_nm, do {
(is_class, proj_nm) ← notation_class_attr.get_param class_nm,
proj_nm ← proj_nm <|> (e.structure_fields_full class_nm).map list.head,
/- For this class, find the projection. `raw_expr` is the projection found applied to `args`,
and `lambda_raw_expr` has the arguments `args` abstracted. -/
(raw_expr, lambda_raw_expr) ← if is_class then (do
guard $ args.length = 1,
let e_inst_type := (const class_nm raw_levels).mk_app args,
(hyp, e_inst) ← try_for 1000 (mk_conditional_instance e_str e_inst_type),
raw_expr ← mk_mapp proj_nm [args.head, e_inst],
clear hyp,
-- Note: `expr.bind_lambda` doesn't give the correct type
raw_expr_lambda ← lambdas [hyp] raw_expr,
return (raw_expr, raw_expr_lambda.lambdas args))
else (do
e_inst_type ← to_expr ((const class_nm []).app (pexpr.of_expr e_str)),
e_inst ← try_for 1000 (mk_instance e_inst_type),
raw_expr ← mk_mapp proj_nm [e_str, e_inst],
return (raw_expr, raw_expr.lambdas args)),
raw_expr_whnf ← whnf raw_expr,
let relevant_proj := raw_expr_whnf.binding_body.get_app_fn.const_name,
/- Use this as projection, if the function reduces to a projection, and this projection has
not been overrriden by the user. -/
guard $ projs.any $
λ x, x.1 = relevant_proj.last ∧ ¬ e.contains (str ++ `simps ++ x.new_name.last),
let pos := projs.find_index (λ x, x.1 = relevant_proj.last),
when trc trace!
" > using {proj_nm} instead of the default projection {relevant_proj.last}.",
when_tracing `simps.debug trace!"[simps] > The raw projection is:\n {lambda_raw_expr}",
return $ raw_exprs.update_nth pos lambda_raw_expr } <|> return raw_exprs) raw_exprs,
let positions := raw_exprs_and_nrs.map prod.snd,
let proj_names := projs.map (λ x, x.new_name),
let defaults := projs.map (λ x, x.is_default),
let prefixes := projs.map (λ x, x.is_prefix),
let projs := proj_names.zip_with5 projection_data.mk raw_exprs positions defaults prefixes,
/- make all proof non-default. -/
projs ← projs.mmap $ λ proj,
is_proof proj.expr >>= λ b, return $ if b then { is_default := ff, .. proj } else proj,
when trc $ projections_info projs "generated projections for" str >>= trace,
simps_str_attr.set str (raw_univs, projs) tt,
when_tracing `simps.debug trace!
"[simps] > Generated raw projection data: \n{(raw_univs, projs)}",
return (raw_univs, projs)
/-- Parse a rule for `initialize_simps_projections`. It is either `<name>→<name>` or `-<name>`,
possibly following by `as_prefix`.-/
meta def simps_parse_rule : parser projection_rule :=
prod.mk <$>
((λ x y, inl (x, y)) <$> ident <*> (tk "->" >> ident) <|> inr <$> (tk "-" >> ident)) <*>
is_some <$> (tk "as_prefix")?
/--
You can specify custom projections for the `@[simps]` attribute.
To do this for the projection `my_structure.original_projection` by adding a declaration
`my_structure.simps.my_projection` that is definitionally equal to
`my_structure.original_projection` but has the projection in the desired (simp-normal) form.
Then you can call
```
initialize_simps_projections (original_projection → my_projection, ...)
```
to register this projection. See `initialize_simps_projections_cmd` for more information.
You can also specify custom projections that are definitionally equal to a composite of multiple
projections. This is often desirable when extending structures (without `old_structure_cmd`).
`has_coe_to_fun` and notation class (like `has_mul`) instances will be automatically used, if they
are definitionally equal to a projection of the structure (but not when they are equal to the
composite of multiple projections).
-/
library_note "custom simps projection"
/--
This command specifies custom names and custom projections for the simp attribute `simps_attr`.
* You can specify custom names by writing e.g.
`initialize_simps_projections equiv (to_fun → apply, inv_fun → symm_apply)`.
* See Note [custom simps projection] and the examples below for information how to declare custom
projections.
* If no custom projection is specified, the projection will be `coe_fn`/`⇑` if a `has_coe_to_fun`
instance has been declared, or the notation of a notation class (like `has_mul`) if such an
instance is available. If none of these cases apply, the projection itself will be used.
* You can disable a projection by default by running
`initialize_simps_projections equiv (-inv_fun)`
This will ensure that no simp lemmas are generated for this projection,
unless this projection is explicitly specified by the user.
* If you want the projection name added as a prefix in the generated lemma name, you can add the
`as_prefix` modifier:
`initialize_simps_projections equiv (to_fun → coe as_prefix)`
Note that this does not influence the parsing of projection names: if you have a declaration
`foo` and you want to apply the projections `snd`, `coe` (which is a prefix) and `fst`, in that
order you can run `@[simps snd_coe_fst] def foo ...` and this will generate a lemma with the
name `coe_foo_snd_fst`.
* Run `initialize_simps_projections?` (or `set_option trace.simps.verbose true`)
to see the generated projections.
* You can declare a new name for a projection that is the composite of multiple projections, e.g.
```
structure A := (proj : ℕ)
structure B extends A
initialize_simps_projections? B (to_A_proj → proj, -to_A)
```
You can also make your custom projection that is definitionally equal to a composite of
projections. In this case, coercions and notation classes are not automatically recognized, and
should be manually given by giving a custom projection.
This is especially useful when extending a structure (without `old_structure_cmd`).
In the above example, it is desirable to add `-to_A`, so that `@[simps]` doesn't automatically
apply the `B.to_A` projection and then recursively the `A.proj` projection in the lemmas it
generates. If you want to get both the `foo_proj` and `foo_to_A` simp lemmas, you can use
`@[simps, simps to_A]`.
* Running `initialize_simps_projections my_struc` without arguments is not necessary, it has the
same effect if you just add `@[simps]` to a declaration.
* If you do anything to change the default projections, make sure to call either `@[simps]` or
`initialize_simps_projections` in the same file as the structure declaration. Otherwise, you might
have a file that imports the structure, but not your custom projections.
Some common uses:
* If you define a new homomorphism-like structure (like `mul_hom`) you can just run
`initialize_simps_projections` after defining the `has_coe_to_fun` instance
```
instance {mM : has_mul M} {mN : has_mul N} : has_coe_to_fun (mul_hom M N) := ...
initialize_simps_projections mul_hom (to_fun → apply)
```
This will generate `foo_apply` lemmas for each declaration `foo`.
* If you prefer `coe_foo` lemmas that state equalities between functions, use
`initialize_simps_projections mul_hom (to_fun → coe as_prefix)`
In this case you have to use `@[simps {fully_applied := ff}]` or equivalently `@[simps as_fn]`
whenever you call `@[simps]`.
* You can also initialize to use both, in which case you have to choose which one to use by default,
by using either of the following
```
initialize_simps_projections mul_hom (to_fun → apply, to_fun → coe, -coe as_prefix)
initialize_simps_projections mul_hom (to_fun → apply, to_fun → coe as_prefix, -apply)
```
In the first case, you can get both lemmas using `@[simps, simps coe as_fn]` and in the second
case you can get both lemmas using `@[simps as_fn, simps apply]`.
* If your new homomorphism-like structure extends another structure (without `old_structure_cmd`)
(like `rel_embedding`), then you have to specify explicitly that you want to use a coercion
as a custom projection. For example
```
def rel_embedding.simps.apply (h : r ↪r s) : α → β := h
initialize_simps_projections rel_embedding (to_embedding_to_fun → apply, -to_embedding)
```
* If you have an isomorphism-like structure (like `equiv`) you often want to define a custom
projection for the inverse:
```
def equiv.simps.symm_apply (e : α ≃ β) : β → α := e.symm
initialize_simps_projections equiv (to_fun → apply, inv_fun → symm_apply)
```
-/
@[user_command] meta def initialize_simps_projections_cmd
(_ : parse $ tk "initialize_simps_projections") : parser unit := do
env ← get_env,
trc ← is_some <$> (tk "?")?,
ns ← (prod.mk <$> ident <*> (tk "(" >> sep_by (tk ",") simps_parse_rule <* tk ")")?)*,
ns.mmap' $ λ data, do
nm ← resolve_constant data.1,
simps_get_raw_projections env nm tt (data.2.get_or_else []) trc
add_tactic_doc
{ name := "initialize_simps_projections",
category := doc_category.cmd,
decl_names := [`initialize_simps_projections_cmd],
tags := ["simplification"] }
/--
Configuration options for the `@[simps]` attribute.
* `attrs` specifies the list of attributes given to the generated lemmas. Default: ``[`simp]``.
The attributes can be either basic attributes, or user attributes without parameters.
There are two attributes which `simps` might add itself:
* If ``[`simp]`` is in the list, then ``[`_refl_lemma]`` is added automatically if appropriate.
* If the definition is marked with `@[to_additive ...]` then all generated lemmas are marked
with `@[to_additive]`. This is governed by the `add_additive` configuration option.
* if `simp_rhs` is `tt` then the right-hand-side of the generated lemmas will be put in
simp-normal form. More precisely: `dsimp, simp` will be called on all these expressions.
See note [dsimp, simp].
* `type_md` specifies how aggressively definitions are unfolded in the type of expressions
for the purposes of finding out whether the type is a function type.
Default: `instances`. This will unfold coercion instances (so that a coercion to a function type
is recognized as a function type), but not declarations like `set`.
* `rhs_md` specifies how aggressively definition in the declaration are unfolded for the purposes
of finding out whether it is a constructor.
Default: `none`
Exception: `@[simps]` will automatically add the options
`{rhs_md := semireducible, simp_rhs := tt}` if the given definition is not a constructor with
the given reducibility setting for `rhs_md`.
* If `fully_applied` is `ff` then the generated `simp` lemmas will be between non-fully applied
terms, i.e. equalities between functions. This does not restrict the recursive behavior of
`@[simps]`, so only the "final" projection will be non-fully applied.
However, it can be used in combination with explicit field names, to get a partially applied
intermediate projection.
* The option `not_recursive` contains the list of names of types for which `@[simps]` doesn't
recursively apply projections. For example, given an equivalence `α × β ≃ β × α` one usually
wants to only apply the projections for `equiv`, and not also those for `×`. This option is
only relevant if no explicit projection names are given as argument to `@[simps]`.
* The option `trace` is set to `tt` when you write `@[simps?]`. In this case, the attribute will
print all generated lemmas. It is almost the same as setting the option `trace.simps.verbose`,
except that it doesn't print information about the found projections.
* if `add_additive` is `some nm` then `@[to_additive]` is added to the generated lemma. This
option is automatically set to `tt` when the original declaration was tagged with
`@[to_additive, simps]` (in that order), where `nm` is the additive name of the original
declaration.
-/
@[derive [has_reflect, inhabited]] structure simps_cfg :=
(attrs := [`simp])
(simp_rhs := ff)
(type_md := transparency.instances)
(rhs_md := transparency.none)
(fully_applied := tt)
(not_recursive := [`prod, `pprod])
(trace := ff)
(add_additive := @none name)
/-- A common configuration for `@[simps]`: generate equalities between functions instead equalities
between fully applied expressions. -/
def as_fn : simps_cfg := {fully_applied := ff}
/-- A common configuration for `@[simps]`: don't tag the generated lemmas with `@[simp]`. -/
def lemmas_only : simps_cfg := {attrs := []}
/--
Get the projections of a structure used by `@[simps]` applied to the appropriate arguments.
Returns a list of tuples
```
(corresponding right-hand-side, given projection name, projection expression, projection numbers,
used by default, is prefix)
```
(where all fields except the first are packed in a `projection_data` structure)
one for each projection. The given projection name is the name for the projection used by the user
used to generate (and parse) projection names. For example, in the structure
Example 1: ``simps_get_projection_exprs env `(α × β) `(⟨x, y⟩)`` will give the output
```
[(`(x), `fst, `(@prod.fst.{u v} α β), [0], tt, ff),
(`(y), `snd, `(@prod.snd.{u v} α β), [1], tt, ff)]
```
Example 2: ``simps_get_projection_exprs env `(α ≃ α) `(⟨id, id, λ _, rfl, λ _, rfl⟩)``
will give the output
```
[(`(id), `apply, `(coe), [0], tt, ff),
(`(id), `symm_apply, `(λ f, ⇑f.symm), [1], tt, ff),
...,
...]
```
-/
meta def simps_get_projection_exprs (e : environment) (tgt : expr)
(rhs : expr) (cfg : simps_cfg) : tactic $ list $ expr × projection_data := do
let params := get_app_args tgt, -- the parameters of the structure
(params.zip $ (get_app_args rhs).take params.length).mmap' (λ ⟨a, b⟩, is_def_eq a b)
<|> fail "unreachable code (1)",
let str := tgt.get_app_fn.const_name,
let rhs_args := (get_app_args rhs).drop params.length, -- the fields of the object
(raw_univs, proj_data) ← simps_get_raw_projections e str ff [] cfg.trace,
let univs := raw_univs.zip tgt.get_app_fn.univ_levels,
let new_proj_data : list $ expr × projection_data := proj_data.map $
λ proj, (rhs_args.inth proj.proj_nrs.head,
{ expr := (proj.expr.instantiate_univ_params univs).instantiate_lambdas_or_apps params,
proj_nrs := proj.proj_nrs.tail,
.. proj }),
return new_proj_data
/-- Add a lemma with `nm` stating that `lhs = rhs`. `type` is the type of both `lhs` and `rhs`,
`args` is the list of local constants occurring, and `univs` is the list of universe variables. -/
meta def simps_add_projection (nm : name) (type lhs rhs : expr) (args : list expr)
(univs : list name) (cfg : simps_cfg) : tactic unit := do
when_tracing `simps.debug trace!
"[simps] > Planning to add the equality\n > {lhs} = ({rhs} : {type})",
lvl ← get_univ_level type,
-- simplify `rhs` if `cfg.simp_rhs` is true
(rhs, prf) ← do { guard cfg.simp_rhs,
rhs' ← rhs.dsimp {fail_if_unchanged := ff},
when_tracing `simps.debug $ when (rhs ≠ rhs') trace!
"[simps] > `dsimp` simplified rhs to\n > {rhs'}",
(rhsprf1, rhsprf2, ns) ← rhs'.simp {fail_if_unchanged := ff},
when_tracing `simps.debug $ when (rhs' ≠ rhsprf1) trace!
"[simps] > `simp` simplified rhs to\n > {rhsprf1}",
return (prod.mk rhsprf1 rhsprf2) }
<|> return (rhs, const `eq.refl [lvl] type lhs),
let eq_ap := const `eq [lvl] type lhs rhs,
decl_name ← get_unused_decl_name nm,
let decl_type := eq_ap.pis args,
let decl_value := prf.lambdas args,
let decl := declaration.thm decl_name univs decl_type (pure decl_value),
when cfg.trace trace!
"[simps] > adding projection {decl_name}:\n > {decl_type}",
decorate_error ("Failed to add projection lemma " ++ decl_name.to_string ++ ". Nested error:") $
add_decl decl,
b ← succeeds $ is_def_eq lhs rhs,
when (b ∧ `simp ∈ cfg.attrs) (set_basic_attribute `_refl_lemma decl_name tt),
cfg.attrs.mmap' $ λ nm, set_attribute nm decl_name tt,
when cfg.add_additive.is_some $
to_additive.attr.set decl_name ⟨ff, cfg.trace, cfg.add_additive.iget, none, tt⟩ tt
/-- Derive lemmas specifying the projections of the declaration.
If `todo` is non-empty, it will generate exactly the names in `todo`.
`to_apply` is non-empty after a custom projection that is a composition of multiple projections
was just used. In that case we need to apply these projections before we continue changing lhs. -/
meta def simps_add_projections : Π (e : environment) (nm : name)
(type lhs rhs : expr) (args : list expr) (univs : list name) (must_be_str : bool)
(cfg : simps_cfg) (todo : list string) (to_apply : list ℕ), tactic unit
| e nm type lhs rhs args univs must_be_str cfg todo to_apply := do
-- we don't want to unfold non-reducible definitions (like `set`) to apply more arguments
when_tracing `simps.debug trace!
"[simps] > Type of the expression before normalizing: {type}",
(type_args, tgt) ← open_pis_whnf type cfg.type_md,
when_tracing `simps.debug trace!"[simps] > Type after removing pi's: {tgt}",
tgt ← whnf tgt,
when_tracing `simps.debug trace!"[simps] > Type after reduction: {tgt}",
let new_args := args ++ type_args,
let lhs_ap := lhs.instantiate_lambdas_or_apps type_args,
let rhs_ap := rhs.instantiate_lambdas_or_apps type_args,
let str := tgt.get_app_fn.const_name,
/- We want to generate the current projection if it is in `todo` -/
let todo_next := todo.filter (≠ ""),
/- Don't recursively continue if `str` is not a structure or if the structure is in
`not_recursive`. -/
if e.is_structure str ∧ ¬(todo = [] ∧ str ∈ cfg.not_recursive ∧ ¬must_be_str) then do
[intro] ← return $ e.constructors_of str | fail "unreachable code (3)",
rhs_whnf ← whnf rhs_ap cfg.rhs_md,
(rhs_ap, todo_now) ← -- `todo_now` means that we still have to generate the current simp lemma
if ¬ is_constant_of rhs_ap.get_app_fn intro ∧
is_constant_of rhs_whnf.get_app_fn intro then
/- If this was a desired projection, we want to apply it before taking the whnf.
However, if the current field is an eta-expansion (see below), we first want
to eta-reduce it and only then construct the projection.
This makes the flow of this function messy. -/
when ("" ∈ todo ∧ to_apply = []) (if cfg.fully_applied then
simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else
simps_add_projection nm type lhs rhs args univs cfg) >>
return (rhs_whnf, ff) else
return (rhs_ap, "" ∈ todo ∧ to_apply = []),
if is_constant_of (get_app_fn rhs_ap) intro then do -- if the value is a constructor application
proj_info ← simps_get_projection_exprs e tgt rhs_ap cfg,
when_tracing `simps.debug trace!"[simps] > Raw projection information:\n {proj_info}",
eta ← rhs_ap.is_eta_expansion, -- check whether `rhs_ap` is an eta-expansion
let rhs_ap := eta.lhoare rhs_ap, -- eta-reduce `rhs_ap`
/- As a special case, we want to automatically generate the current projection if `rhs_ap`
was an eta-expansion. Also, when this was a desired projection, we need to generate the
current projection if we haven't done it above. -/
when (todo_now ∨ (todo = [] ∧ eta.is_some ∧ to_apply = [])) $
if cfg.fully_applied then
simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else
simps_add_projection nm type lhs rhs args univs cfg,
/- If we are in the middle of a composite projection. -/
when (to_apply ≠ []) $ do {
⟨new_rhs, proj, proj_expr, proj_nrs, is_default, is_prefix⟩ ←
return $ proj_info.inth to_apply.head,
new_type ← infer_type new_rhs,
when_tracing `simps.debug
trace!"[simps] > Applying a custom composite projection. Current lhs:
> {lhs_ap}",
simps_add_projections e nm new_type lhs_ap new_rhs new_args univs ff cfg todo
to_apply.tail },
/- We stop if no further projection is specified or if we just reduced an eta-expansion and we
automatically choose projections -/
when ¬(to_apply ≠ [] ∨ todo = [""] ∨ (eta.is_some ∧ todo = [])) $ do
let projs : list name := proj_info.map $ λ x, x.snd.name,
let todo := if to_apply = [] then todo_next else todo,
-- check whether all elements in `todo` have a projection as prefix
guard (todo.all $ λ x, projs.any $ λ proj, ("_" ++ proj.last).is_prefix_of x) <|>
let x := (todo.find $ λ x, projs.all $ λ proj, ¬ ("_" ++ proj.last).is_prefix_of x).iget,
simp_lemma := nm.append_suffix x,
needed_proj := (x.split_on '_').tail.head in
fail!
"Invalid simp lemma {simp_lemma}. Structure {str} does not have projection {needed_proj}.
The known projections are:
{projs}
You can also see this information by running
`initialize_simps_projections? {str}`.
Note: these projection names might not correspond to the projection names of the structure.",
proj_info.mmap_with_index' $
λ proj_nr ⟨new_rhs, proj, proj_expr, proj_nrs, is_default, is_prefix⟩, do
new_type ← infer_type new_rhs,
let new_todo :=
todo.filter_map $ λ x, x.get_rest ("_" ++ proj.last),
-- we only continue with this field if it is non-propositional or mentioned in todo
when ((is_default ∧ todo = []) ∨ new_todo ≠ []) $ do
let new_lhs := proj_expr.instantiate_lambdas_or_apps [lhs_ap],
let new_nm := nm.append_to_last proj.last is_prefix,
let new_cfg := { add_additive := cfg.add_additive.map $
λ nm, nm.append_to_last (to_additive.guess_name proj.last) is_prefix, ..cfg },
when_tracing `simps.debug trace!"[simps] > Recursively add projections for:
> {new_lhs}",
simps_add_projections e new_nm new_type new_lhs new_rhs new_args univs
ff new_cfg new_todo proj_nrs
-- if I'm about to run into an error, try to set the transparency for `rhs_md` higher.
else if cfg.rhs_md = transparency.none ∧ (must_be_str ∨ todo_next ≠ [] ∨ to_apply ≠ []) then do
when cfg.trace trace!
"[simps] > The given definition is not a constructor application:
> {rhs_ap}
> Retrying with the options {{ rhs_md := semireducible, simp_rhs := tt}.",
simps_add_projections e nm type lhs rhs args univs must_be_str
{ rhs_md := semireducible, simp_rhs := tt, ..cfg} todo to_apply
else do
when (to_apply ≠ []) $
fail!"Invalid simp lemma {nm}.
The given definition is not a constructor application:\n {rhs_ap}",
when must_be_str $
fail!"Invalid `simps` attribute. The body is not a constructor application:\n {rhs_ap}",
when (todo_next ≠ []) $
fail!"Invalid simp lemma {nm.append_suffix todo_next.head}.
The given definition is not a constructor application:\n {rhs_ap}",
if cfg.fully_applied then
simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else
simps_add_projection nm type lhs rhs args univs cfg
else do
when must_be_str $
fail!"Invalid `simps` attribute. Target {str} is not a structure",
when (todo_next ≠ [] ∧ str ∉ cfg.not_recursive) $
let first_todo := todo_next.head in
fail!"Invalid simp lemma {nm.append_suffix first_todo}.
Projection {(first_todo.split_on '_').tail.head} doesn't exist, because target is not a structure.",
if cfg.fully_applied then
simps_add_projection nm tgt lhs_ap rhs_ap new_args univs cfg else
simps_add_projection nm type lhs rhs args univs cfg
/-- `simps_tac` derives `simp` lemmas for all (nested) non-Prop projections of the declaration.
If `todo` is non-empty, it will generate exactly the names in `todo`.
If `short_nm` is true, the generated names will only use the last projection name.
If `trc` is true, trace as if `trace.simps.verbose` is true. -/
meta def simps_tac (nm : name) (cfg : simps_cfg := {}) (todo : list string := []) (trc := ff) :
tactic unit := do
e ← get_env,
d ← e.get nm,
let lhs : expr := const d.to_name d.univ_levels,
let todo := todo.erase_dup.map $ λ proj, "_" ++ proj,
let cfg := { trace := cfg.trace || is_trace_enabled_for `simps.verbose || trc, ..cfg },
b ← has_attribute' `to_additive nm,
cfg ← if b then do {
dict ← to_additive.aux_attr.get_cache,
when cfg.trace
trace!"[simps] > @[to_additive] will be added to all generated lemmas.",
return { add_additive := dict.find nm, ..cfg } } else
return cfg,
simps_add_projections e nm d.type lhs d.value [] d.univ_params tt cfg todo []
/-- The parser for the `@[simps]` attribute. -/
meta def simps_parser : parser (bool × list string × simps_cfg) := do
/- note: we don't check whether the user has written a nonsense namespace in an argument. -/
prod.mk <$> is_some <$> (tk "?")? <*>
(prod.mk <$> many (name.last <$> ident) <*>
(do some e ← parser.pexpr? | return {}, eval_pexpr simps_cfg e))
/--
The `@[simps]` attribute automatically derives lemmas specifying the projections of this
declaration.
Example:
```lean
@[simps] def foo : ℕ × ℤ := (1, 2)
```
derives two `simp` lemmas:
```lean
@[simp] lemma foo_fst : foo.fst = 1
@[simp] lemma foo_snd : foo.snd = 2
```
* It does not derive `simp` lemmas for the prop-valued projections.
* It will automatically reduce newly created beta-redexes, but will not unfold any definitions.
* If the structure has a coercion to either sorts or functions, and this is defined to be one
of the projections, then this coercion will be used instead of the projection.
* If the structure is a class that has an instance to a notation class, like `has_mul`, then this
notation is used instead of the corresponding projection.
* You can specify custom projections, by giving a declaration with name
`{structure_name}.simps.{projection_name}`. See Note [custom simps projection].
Example:
```lean
def equiv.simps.inv_fun (e : α ≃ β) : β → α := e.symm
@[simps] def equiv.trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm⟩
```
generates
```
@[simp] lemma equiv.trans_to_fun : ∀ {α β γ} (e₁ e₂) (a : α), ⇑(e₁.trans e₂) a = (⇑e₂ ∘ ⇑e₁) a
@[simp] lemma equiv.trans_inv_fun : ∀ {α β γ} (e₁ e₂) (a : γ),
⇑((e₁.trans e₂).symm) a = (⇑(e₁.symm) ∘ ⇑(e₂.symm)) a
```
* You can specify custom projection names, by specifying the new projection names using
`initialize_simps_projections`.
Example: `initialize_simps_projections equiv (to_fun → apply, inv_fun → symm_apply)`.
See `initialize_simps_projections_cmd` for more information.
* If one of the fields itself is a structure, this command will recursively create
`simp` lemmas for all fields in that structure.
* Exception: by default it will not recursively create `simp` lemmas for fields in the structures
`prod` and `pprod`. You can give explicit projection names or change the value of
`simps_cfg.not_recursive` to override this behavior.
Example:
```lean
structure my_prod (α β : Type*) := (fst : α) (snd : β)
@[simps] def foo : prod ℕ ℕ × my_prod ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩
```
generates
```lean
@[simp] lemma foo_fst : foo.fst = (1, 2)
@[simp] lemma foo_snd_fst : foo.snd.fst = 3
@[simp] lemma foo_snd_snd : foo.snd.snd = 4
```
* You can use `@[simps proj1 proj2 ...]` to only generate the projection lemmas for the specified
projections.
* Recursive projection names can be specified using `proj1_proj2_proj3`.
This will create a lemma of the form `foo.proj1.proj2.proj3 = ...`.
Example:
```lean
structure my_prod (α β : Type*) := (fst : α) (snd : β)
@[simps fst fst_fst snd] def foo : prod ℕ ℕ × my_prod ℕ ℕ := ⟨⟨1, 2⟩, 3, 4⟩
```
generates
```lean
@[simp] lemma foo_fst : foo.fst = (1, 2)
@[simp] lemma foo_fst_fst : foo.fst.fst = 1
@[simp] lemma foo_snd : foo.snd = {fst := 3, snd := 4}
```
* If one of the values is an eta-expanded structure, we will eta-reduce this structure.
Example:
```lean
structure equiv_plus_data (α β) extends α ≃ β := (data : bool)
@[simps] def bar {α} : equiv_plus_data α α := { data := tt, ..equiv.refl α }
```
generates the following:
```lean
@[simp] lemma bar_to_equiv : ∀ {α : Sort*}, bar.to_equiv = equiv.refl α
@[simp] lemma bar_data : ∀ {α : Sort*}, bar.data = tt
```
This is true, even though Lean inserts an eta-expanded version of `equiv.refl α` in the
definition of `bar`.
* For configuration options, see the doc string of `simps_cfg`.
* The precise syntax is `('simps' ident* e)`, where `e` is an expression of type `simps_cfg`.
* `@[simps]` reduces let-expressions where necessary.
* When option `trace.simps.verbose` is true, `simps` will print the projections it finds and the
lemmas it generates. The same can be achieved by using `@[simps?]`, except that in this case it
will not print projection information.
* Use `@[to_additive, simps]` to apply both `to_additive` and `simps` to a definition, making sure
that `simps` comes after `to_additive`. This will also generate the additive versions of all
`simp` lemmas.
-/
/- If one of the fields is a partially applied constructor, we will eta-expand it
(this likely never happens, so is not included in the official doc). -/
@[user_attribute] meta def simps_attr : user_attribute unit (bool × list string × simps_cfg) :=
{ name := `simps,
descr := "Automatically derive lemmas specifying the projections of this declaration.",
parser := simps_parser,
after_set := some $
λ n _ persistent, do
guard persistent <|> fail "`simps` currently cannot be used as a local attribute",
(trc, todo, cfg) ← simps_attr.get_param n,
simps_tac n cfg todo trc }
add_tactic_doc
{ name := "simps",
category := doc_category.attr,
decl_names := [`simps_attr],
tags := ["simplification"] }
|
60e5e6e8d8e258f8235a0c50ea45e75584b52381 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/category/FinBoolAlg.lean | ad889807c39f81e82759e3ce636f0b57dc402ce1 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 4,036 | lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.fintype.powerset
import order.category.BoolAlg
import order.category.FinBddDistLat
import order.hom.complete_lattice
/-!
# The category of finite boolean algebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines `FinBoolAlg`, the category of finite boolean algebras.
## TODO
Birkhoff's representation for finite Boolean algebras.
`Fintype_to_FinBoolAlg_op.left_op ⋙ FinBoolAlg.dual ≅ Fintype_to_FinBoolAlg_op.left_op`
`FinBoolAlg` is essentially small.
-/
universes u
open category_theory order_dual opposite
/-- The category of finite boolean algebras with bounded lattice morphisms. -/
structure FinBoolAlg :=
(to_BoolAlg : BoolAlg)
[is_fintype : fintype to_BoolAlg]
namespace FinBoolAlg
instance : has_coe_to_sort FinBoolAlg Type* := ⟨λ X, X.to_BoolAlg⟩
instance (X : FinBoolAlg) : boolean_algebra X := X.to_BoolAlg.str
attribute [instance] FinBoolAlg.is_fintype
@[simp] lemma coe_to_BoolAlg (X : FinBoolAlg) : ↥X.to_BoolAlg = ↥X := rfl
/-- Construct a bundled `FinBoolAlg` from `boolean_algebra` + `fintype`. -/
def of (α : Type*) [boolean_algebra α] [fintype α] : FinBoolAlg := ⟨⟨α⟩⟩
@[simp] lemma coe_of (α : Type*) [boolean_algebra α] [fintype α] : ↥(of α) = α := rfl
instance : inhabited FinBoolAlg := ⟨of punit⟩
instance large_category : large_category FinBoolAlg :=
induced_category.category FinBoolAlg.to_BoolAlg
instance concrete_category : concrete_category FinBoolAlg :=
induced_category.concrete_category FinBoolAlg.to_BoolAlg
instance has_forget_to_BoolAlg : has_forget₂ FinBoolAlg BoolAlg :=
induced_category.has_forget₂ FinBoolAlg.to_BoolAlg
instance has_forget_to_FinBddDistLat : has_forget₂ FinBoolAlg FinBddDistLat :=
{ forget₂ := { obj := λ X, FinBddDistLat.of X, map := λ X Y f, f },
forget_comp := rfl }
instance forget_to_BoolAlg_full : full (forget₂ FinBoolAlg BoolAlg) := induced_category.full _
instance forget_to_BoolAlg_faithful : faithful (forget₂ FinBoolAlg BoolAlg) :=
induced_category.faithful _
@[simps] instance has_forget_to_FinPartOrd : has_forget₂ FinBoolAlg FinPartOrd :=
{ forget₂ := { obj := λ X, FinPartOrd.of X, map := λ X Y f,
show order_hom X Y, from ↑(show bounded_lattice_hom X Y, from f) } }
instance forget_to_FinPartOrd_faithful : faithful (forget₂ FinBoolAlg FinPartOrd) :=
⟨λ X Y f g h, by { have := congr_arg (coe_fn : _ → X → Y) h, exact fun_like.coe_injective this }⟩
/-- Constructs an equivalence between finite Boolean algebras from an order isomorphism between
them. -/
@[simps] def iso.mk {α β : FinBoolAlg.{u}} (e : α ≃o β) : α ≅ β :=
{ hom := (e : bounded_lattice_hom α β),
inv := (e.symm : bounded_lattice_hom β α),
hom_inv_id' := by { ext, exact e.symm_apply_apply _ },
inv_hom_id' := by { ext, exact e.apply_symm_apply _ } }
/-- `order_dual` as a functor. -/
@[simps] def dual : FinBoolAlg ⥤ FinBoolAlg :=
{ obj := λ X, of Xᵒᵈ, map := λ X Y, bounded_lattice_hom.dual }
/-- The equivalence between `FinBoolAlg` and itself induced by `order_dual` both ways. -/
@[simps functor inverse] def dual_equiv : FinBoolAlg ≌ FinBoolAlg :=
equivalence.mk dual dual
(nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl)
(nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl)
end FinBoolAlg
lemma FinBoolAlg_dual_comp_forget_to_FinBddDistLat :
FinBoolAlg.dual ⋙ forget₂ FinBoolAlg FinBddDistLat =
forget₂ FinBoolAlg FinBddDistLat ⋙ FinBddDistLat.dual := rfl
/-- The powerset functor. `set` as a functor. -/
@[simps] def Fintype_to_FinBoolAlg_op : Fintype ⥤ FinBoolAlgᵒᵖ :=
{ obj := λ X, op $ FinBoolAlg.of (set X),
map := λ X Y f, quiver.hom.op $
(complete_lattice_hom.set_preimage f : bounded_lattice_hom (set Y) (set X)) }
|
d533117a5214f8a4224a0ed22765bc032067bff5 | 02fbe05a45fda5abde7583464416db4366eedfbf | /library/init/data/int/comp_lemmas.lean | bc1352286bca0f44e9f5f7126ee4b12a11b379ce | [
"Apache-2.0"
] | permissive | jasonrute/lean | cc12807e11f9ac6b01b8951a8bfb9c2eb35a0154 | 4be962c167ca442a0ec5e84472d7ff9f5302788f | refs/heads/master | 1,672,036,664,637 | 1,601,642,826,000 | 1,601,642,826,000 | 260,777,966 | 0 | 0 | Apache-2.0 | 1,588,454,819,000 | 1,588,454,818,000 | null | UTF-8 | Lean | false | false | 5,023 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
Auxiliary lemmas used to compare int numerals.
-/
prelude
import init.data.int.order
namespace int
/- Auxiliary lemmas for proving that to int numerals are different -/
/- 1. Lemmas for reducing the problem to the case where the numerals are positive -/
protected lemma ne_neg_of_ne {a b : ℤ} : a ≠ b → -a ≠ -b :=
λ h₁ h₂, absurd (int.neg_inj h₂) h₁
protected lemma neg_ne_zero_of_ne {a : ℤ} : a ≠ 0 → -a ≠ 0 :=
λ h₁ h₂,
have -a = -0, by rwa int.neg_zero,
have a = 0, from int.neg_inj this,
by contradiction
protected lemma zero_ne_neg_of_ne {a : ℤ} (h : 0 ≠ a) : 0 ≠ -a :=
ne.symm (int.neg_ne_zero_of_ne (ne.symm h))
protected lemma neg_ne_of_pos {a b : ℤ} : a > 0 → b > 0 → -a ≠ b :=
λ h₁ h₂ h,
begin
rw [← h] at h₂,
change 0 < a at h₁,
have := le_of_lt h₁,
exact absurd (le_of_lt h₁) (not_le_of_gt (int.neg_of_neg_pos h₂))
end
protected lemma ne_neg_of_pos {a b : ℤ} : a > 0 → b > 0 → a ≠ -b :=
λ h₁ h₂, ne.symm (int.neg_ne_of_pos h₂ h₁)
/- 2. Lemmas for proving that positive int numerals are nonneg and positive -/
protected lemma one_pos : (1:int) > 0 :=
int.zero_lt_one
protected lemma bit0_pos {a : ℤ} : a > 0 → bit0 a > 0 :=
λ h, int.add_pos h h
protected lemma bit1_pos {a : ℤ} : a ≥ 0 → bit1 a > 0 :=
λ h, int.lt_add_of_le_of_pos (int.add_nonneg h h) int.zero_lt_one
protected lemma zero_nonneg : (0:int) ≥ 0 :=
le_refl 0
protected lemma one_nonneg : (1:int) ≥ 0 :=
le_of_lt (int.zero_lt_one)
protected lemma bit0_nonneg {a : ℤ} : a ≥ 0 → bit0 a ≥ 0 :=
λ h, int.add_nonneg h h
protected lemma bit1_nonneg {a : ℤ} : a ≥ 0 → bit1 a ≥ 0 :=
λ h, le_of_lt (int.bit1_pos h)
protected lemma nonneg_of_pos {a : ℤ} : a > 0 → a ≥ 0 :=
le_of_lt
/- 3. nat_abs auxiliary lemmas -/
lemma neg_succ_of_nat_lt_zero (n : ℕ) : neg_succ_of_nat n < 0 :=
@lt.intro _ _ n (by simp [neg_succ_of_nat_coe, int.coe_nat_succ, int.coe_nat_add, int.coe_nat_one,
int.add_comm, int.add_left_comm, int.neg_add, int.add_right_neg, int.zero_add])
lemma of_nat_ge_zero (n : ℕ) : of_nat n ≥ 0 :=
@le.intro _ _ n (by rw [int.zero_add, int.coe_nat_eq])
lemma of_nat_nat_abs_eq_of_nonneg : ∀ {a : ℤ}, a ≥ 0 → of_nat (nat_abs a) = a
| (of_nat n) h := rfl
| (neg_succ_of_nat n) h := absurd (neg_succ_of_nat_lt_zero n) (not_lt_of_ge h)
lemma ne_of_nat_abs_ne_nat_abs_of_nonneg {a b : ℤ} (ha : a ≥ 0) (hb : b ≥ 0) (h : nat_abs a ≠ nat_abs b) : a ≠ b :=
assume h,
have of_nat (nat_abs a) = of_nat (nat_abs b), by rwa [of_nat_nat_abs_eq_of_nonneg ha, of_nat_nat_abs_eq_of_nonneg hb],
begin injection this, contradiction end
protected lemma ne_of_nat_ne_nonneg_case {a b : ℤ} {n m : nat} (ha : a ≥ 0) (hb : b ≥ 0) (e1 : nat_abs a = n) (e2 : nat_abs b = m) (h : n ≠ m) : a ≠ b :=
have nat_abs a ≠ nat_abs b, by rwa [e1, e2],
ne_of_nat_abs_ne_nat_abs_of_nonneg ha hb this
/- 4. Aux lemmas for pushing nat_abs inside numerals
nat_abs_zero and nat_abs_one are defined at init/data/int/basic.lean -/
lemma nat_abs_of_nat_core (n : ℕ) : nat_abs (of_nat n) = n :=
rfl
lemma nat_abs_of_neg_succ_of_nat (n : ℕ) : nat_abs (neg_succ_of_nat n) = nat.succ n :=
rfl
protected lemma nat_abs_add_nonneg : ∀ {a b : int}, a ≥ 0 → b ≥ 0 → nat_abs (a + b) = nat_abs a + nat_abs b
| (of_nat n) (of_nat m) h₁ h₂ :=
have of_nat n + of_nat m = of_nat (n + m), from rfl,
by simp [nat_abs_of_nat_core, this]
| _ (neg_succ_of_nat m) h₁ h₂ := absurd (neg_succ_of_nat_lt_zero m) (not_lt_of_ge h₂)
| (neg_succ_of_nat n) _ h₁ h₂ := absurd (neg_succ_of_nat_lt_zero n) (not_lt_of_ge h₁)
protected lemma nat_abs_add_neg : ∀ {a b : int}, a < 0 → b < 0 → nat_abs (a + b) = nat_abs a + nat_abs b
| (neg_succ_of_nat n) (neg_succ_of_nat m) h₁ h₂ :=
have -[1+ n] + -[1+ m] = -[1+ nat.succ (n + m)], from rfl,
begin simp [nat_abs_of_neg_succ_of_nat, this, nat.succ_add, nat.add_succ] end
protected lemma nat_abs_bit0 : ∀ (a : int), nat_abs (bit0 a) = bit0 (nat_abs a)
| (of_nat n) := int.nat_abs_add_nonneg (of_nat_ge_zero n) (of_nat_ge_zero n)
| (neg_succ_of_nat n) := int.nat_abs_add_neg (neg_succ_of_nat_lt_zero n) (neg_succ_of_nat_lt_zero n)
protected lemma nat_abs_bit0_step {a : int} {n : nat} (h : nat_abs a = n) : nat_abs (bit0 a) = bit0 n :=
begin rw [← h], apply int.nat_abs_bit0 end
protected lemma nat_abs_bit1_nonneg {a : int} (h : a ≥ 0) : nat_abs (bit1 a) = bit1 (nat_abs a) :=
show nat_abs (bit0 a + 1) = bit0 (nat_abs a) + nat_abs 1, from
by rw [int.nat_abs_add_nonneg (int.bit0_nonneg h) (le_of_lt (int.zero_lt_one)), int.nat_abs_bit0]
protected lemma nat_abs_bit1_nonneg_step {a : int} {n : nat} (h₁ : a ≥ 0) (h₂ : nat_abs a = n) : nat_abs (bit1 a) = bit1 n :=
begin rw [← h₂], apply int.nat_abs_bit1_nonneg h₁ end
end int
|
b9ecd79d347eba102f54feda859f4d458305df7f | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/category_theory/sums/associator.lean | 78e0c7555d260516b5e7ad9b5895b43f5fc2cbe7 | [
"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 | 3,430 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.sums.basic
/-#
The associator functor `((C ⊕ D) ⊕ E) ⥤ (C ⊕ (D ⊕ E))` and its inverse form an equivalence.
-/
universes v u
open category_theory
open sum
namespace category_theory.sum
variables (C : Type u) [category.{v} C]
(D : Type u) [category.{v} D]
(E : Type u) [category.{v} E]
/--
The associator functor `(C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E)` for sums of categories.
-/
def associator : (C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E) :=
{ obj := λ X, match X with
| inl (inl X) := inl X
| inl (inr X) := inr (inl X)
| inr X := inr (inr X)
end,
map := λ X Y f, match X, Y, f with
| inl (inl X), inl (inl Y), f := f
| inl (inr X), inl (inr Y), f := f
| inr X, inr Y, f := f
end }
@[simp] lemma associator_obj_inl_inl (X) : (associator C D E).obj (inl (inl X)) = inl X := rfl
@[simp] lemma associator_obj_inl_inr (X) : (associator C D E).obj (inl (inr X)) = inr (inl X) := rfl
@[simp] lemma associator_obj_inr (X) : (associator C D E).obj (inr X) = inr (inr X) := rfl
@[simp] lemma associator_map_inl_inl {X Y : C} (f : inl (inl X) ⟶ inl (inl Y)) :
(associator C D E).map f = f := rfl
@[simp] lemma associator_map_inl_inr {X Y : D} (f : inl (inr X) ⟶ inl (inr Y)) :
(associator C D E).map f = f := rfl
@[simp] lemma associator_map_inr {X Y : E} (f : inr X ⟶ inr Y) :
(associator C D E).map f = f := rfl
/--
The inverse associator functor `C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E` for sums of categories.
-/
def inverse_associator : C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E :=
{ obj := λ X, match X with
| inl X := inl (inl X)
| inr (inl X) := inl (inr X)
| inr (inr X) := inr X
end,
map := λ X Y f, match X, Y, f with
| inl X, inl Y, f := f
| inr (inl X), inr (inl Y), f := f
| inr (inr X), inr (inr Y), f := f
end }
@[simp] lemma inverse_associator_obj_inl (X) : (inverse_associator C D E).obj (inl X) = inl (inl X) := rfl
@[simp] lemma inverse_associator_obj_inr_inl (X) : (inverse_associator C D E).obj (inr (inl X)) = inl (inr X) := rfl
@[simp] lemma inverse_associator_obj_inr_inr (X) : (inverse_associator C D E).obj (inr (inr X)) = inr X := rfl
@[simp] lemma inverse_associator_map_inl {X Y : C} (f : inl X ⟶ inl Y) :
(inverse_associator C D E).map f = f := rfl
@[simp] lemma inverse_associator_map_inr_inl {X Y : D} (f : inr (inl X) ⟶ inr (inl Y)) :
(inverse_associator C D E).map f = f := rfl
@[simp] lemma inverse_associator_map_inr_inr {X Y : E} (f : inr (inr X) ⟶ inr (inr Y)) :
(inverse_associator C D E).map f = f := rfl
/--
The equivalence of categories expressing associativity of sums of categories.
-/
def associativity : (C ⊕ D) ⊕ E ≌ C ⊕ (D ⊕ E) :=
equivalence.mk (associator C D E) (inverse_associator C D E)
(nat_iso.of_components (λ X, eq_to_iso (by tidy)) (by tidy))
(nat_iso.of_components (λ X, eq_to_iso (by tidy)) (by tidy))
instance associator_is_equivalence : is_equivalence (associator C D E) :=
(by apply_instance : is_equivalence (associativity C D E).functor)
instance inverse_associator_is_equivalence : is_equivalence (inverse_associator C D E) :=
(by apply_instance : is_equivalence (associativity C D E).inverse)
-- TODO unitors?
-- TODO pentagon natural transformation? ...satisfying?
end category_theory.sum
|
01c4c534819719c3df4727b9114e3ef881863ec6 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /test/coinductive.lean | c37a6ed4247ddf1f7937ec074fd9e77a65ed4163 | [
"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 | 5,297 | lean | /- test cases for coinductive predicates -/
import data.stream
import meta.coinductive_predicates
universe u
coinductive all_stream {α : Type u} (s : set α) : stream α → Prop
| step : ∀{a : α} {ω : stream α}, a ∈ s → all_stream ω → all_stream (a :: ω)
example : Π {α : Type u}, set α → stream α → Prop :=
@all_stream
example : ∀ {α : Type u} {s : set α} {a : α} {ω : stream α}, a ∈ s → all_stream s ω →
all_stream s (a :: ω) :=
@all_stream.step
example : ∀ {α : Type u} (s : set α) {a : stream α}, all_stream s a →
all_stream.functional s (all_stream s) a :=
@all_stream.destruct
example : ∀ {α : Type u} (s : set α) (C : stream α → Prop) {a : stream α},
C a →
(∀ (a : stream α), C a → (∃ {a_1 : α} {ω : stream α}, a_1 ∈ s ∧ C ω ∧ a_1 :: ω = a)) →
all_stream s a :=
@all_stream.corec_on
example : ∀ {α : Type u} (s : set α) (C : stream α → Prop),
(∀ (a : stream α), C a → all_stream.functional s C a) →
∀ (a : stream α), C a → all_stream s a :=
@all_stream.corec_functional
coinductive all_stream' {α : Type u} (s : set α) : stream α → Prop
| step : ∀{ω : stream α}, stream.head ω ∈ s → all_stream' (stream.tail ω) → all_stream' ω
coinductive alt_stream : stream bool → Prop
| tt_step : ∀{ω : stream bool}, alt_stream (ff :: ω) → alt_stream (tt :: ff :: ω)
| ff_step : ∀{ω : stream bool}, alt_stream (tt :: ω) → alt_stream (ff :: tt :: ω)
example : stream bool → Prop := @alt_stream
example : ∀ {ω : stream bool}, alt_stream (ff :: ω) → alt_stream (tt :: ff :: ω) :=
@alt_stream.tt_step
example : ∀ {ω : stream bool}, alt_stream (tt :: ω) → alt_stream (ff :: tt :: ω) :=
@alt_stream.ff_step
example : ∀ (C : stream bool → Prop), (∀ (a : stream bool), C a → alt_stream.functional C a) →
∀ (a : stream bool), C a → alt_stream a :=
@alt_stream.corec_functional
mutual coinductive tt_stream, ff_stream
with tt_stream : stream bool → Prop
| step : ∀{ω : stream bool}, ff_stream ω → tt_stream (stream.cons tt ω)
with ff_stream : stream bool → Prop
| step : ∀{ω : stream bool}, tt_stream ω → ff_stream (stream.cons ff ω)
example : stream bool → Prop := @tt_stream
example : stream bool → Prop := @ff_stream
example : ∀ (C_tt_stream C_ff_stream : stream bool → Prop),
(∀ (a : stream bool), C_tt_stream a → tt_stream.functional C_tt_stream C_ff_stream a) →
(∀ (a : stream bool), C_ff_stream a → ff_stream.functional C_tt_stream C_ff_stream a) →
∀ (a : stream bool), C_tt_stream a → tt_stream a :=
@tt_stream.corec_functional
example : ∀ (C_tt_stream C_ff_stream : stream bool → Prop),
(∀ (a : stream bool), C_tt_stream a → tt_stream.functional C_tt_stream C_ff_stream a) →
(∀ (a : stream bool), C_ff_stream a → ff_stream.functional C_tt_stream C_ff_stream a) →
∀ (a : stream bool), C_ff_stream a → ff_stream a :=
@ff_stream.corec_functional
mutual coinductive tt_ff_stream, ff_tt_stream
with tt_ff_stream : stream bool → Prop
| step : ∀{ω : stream bool}, tt_ff_stream ω ∨ ff_tt_stream ω → tt_ff_stream (stream.cons tt ω)
with ff_tt_stream : stream bool → Prop
| step : ∀{ω : stream bool}, ff_tt_stream ω ∨ tt_ff_stream ω → ff_tt_stream (stream.cons ff ω)
inductive all_list {α : Type} (p : α → Prop) : list α → Prop
| nil : all_list []
| cons : ∀a xs, p a → all_list xs → all_list (a :: xs)
@[monotonicity]
lemma monotonicity.all_list {α : Type} {p q : α → Prop} (h : ∀a, implies (p a) (q a)) :
∀xs, implies (all_list p xs) (all_list q xs)
| _ (all_list.nil) := all_list.nil
| _ (all_list.cons a xs ha hxs) := all_list.cons _ _ (h a ha) (monotonicity.all_list _ hxs)
mutual coinductive walk_a, walk_b {α β : Type} (f : α → list β) (g : β → α) (p : α → Prop)
(t : α → Prop)
with walk_a : α → Prop
| step : ∀a, all_list walk_b (f a) → p a → walk_a a
| term : ∀a, t a → walk_a a
with walk_b : β → Prop
| step : ∀b, walk_a (g b) → walk_b b
example : ∀ {α β : Type} (f : α → list β) (g : β → α) (p t C_walk_a : α → Prop)
(C_walk_b : β → Prop) {a : α},
C_walk_a a →
(∀ (a : α), C_walk_a a → all_list C_walk_b (f a) ∧ p a ∨ t a) →
(∀ (a : β), C_walk_b a → C_walk_a (g a)) → walk_a f g p t a :=
@walk_a.corec_on
coinductive walk_list {α : Type} (f : α → list α) (p : α → Prop) : ℕ → α → Prop
| step : ∀n a, all_list (walk_list n) (f a) → p a → walk_list (n + 1) a
example {f : ℕ → list ℕ} {a' : ℕ} {n : ℕ} {a : fin n} : true :=
begin
suffices : walk_list f (λ a'', a'' = a') (n + 1) a', {trivial},
coinduction walk_list.corec_on generalizing a n,
show ∃ (n : ℕ),
all_list (λ (a : ℕ), ∃ {n_1 : ℕ} {a_1 : fin n_1}, n_1 + 1 = n ∧ a' = a) (f a') ∧
a' = a' ∧ n + 1 = w + 1,
admit
end
coinductive coind_foo : list ℕ → Prop
| mk : ∀ xs, (∀ k l m, coind_foo (k::l::m::xs)) → coind_foo xs
meta example : true :=
begin
success_if_fail { let := compact_relation },
trivial
end
import_private compact_relation from tactic.coinduction
meta example : true :=
begin
let := compact_relation,
trivial
end
|
4eef251f7fbb81e0717cca6078b63ff91b829bf1 | 6950a6e5cebf75da9b91f42789baf52514655111 | /hol/translation_hol.lean | bbe11d5e980e1241a1d730926b467650a2a479c1 | [] | no_license | phlippe/Lean_hammer | a6d0a1af09fbce0c58b801032099b9b91d49ecf0 | 2116279b9c6b334f5b661e4abf4561368cca2391 | refs/heads/master | 1,587,486,769,513 | 1,561,466,931,000 | 1,561,466,931,000 | 169,705,506 | 0 | 1 | null | 1,550,228,564,000 | 1,549,614,939,000 | Lean | UTF-8 | Lean | false | false | 11,938 | lean | import .datastructures_hol
meta instance : monad hammer_tactic :=
state_t.monad
meta instance (α : Type) : has_coe (tactic α) (hammer_tactic α) :=
⟨state_t.lift⟩
meta def using_hammer {α} (t : hammer_tactic α) : tactic (α × hammer_state) :=
do let ss := hammer_state.mk [] [] [],
state_t.run t ss
meta def when' (c : Prop) [decidable c] (tac : hammer_tactic unit) : hammer_tactic unit :=
if c then tac else tactic.skip
meta def lives_in_prop_p (e : expr) : hammer_tactic bool :=
do tp ← tactic.infer_type e,
return (if eq tp (expr.sort level.zero) then tt else ff)
meta def lives_in_type (e : expr) : hammer_tactic bool :=
do tp ← tactic.infer_type e,
return (if eq tp (expr.sort (level.succ (level.succ level.zero))) then tt else ff)
meta def add_axiom (n : name) (axioma : holform) : hammer_tactic unit :=
do state_t.modify (fun state, {state with axiomas := ⟨n, axioma⟩ :: state.axiomas})
meta def add_type_def (def_name : name) (type_name : name) (t : holtype) : hammer_tactic unit :=
do state_t.modify (fun state, {state with type_definitions := ⟨def_name, type_name, t⟩ :: state.type_definitions})
meta def add_constant (n : name) (e : expr) : hammer_tactic unit :=
do state_t.modify (fun state, {state with introduced_constants := ⟨n, e⟩ :: state.introduced_constants })
-- TODO: Check type for being unique/defined!
-- meta def is_type_defined (type : holtype) : bool := list_contains_type
-- meta def list_contains_type : list type_def → holtype → bool
-- | (c :: cs) t := ff || list_contains_type cs t
-- | [] t := ff
meta def holtype.from_name : name → holtype
| "$o" := holtype.o
-- | "bool" := holtype.o -- TODO: Check the expression name for a boolean!
| "$i" := holtype.i
| "$tType" := holtype.type
| s := holtype.ltype s
-- TODO: Integrate a mechanism for adding the new local type as type into tactic state
meta def holtype.infer_type : holterm → tactic holtype
| (holterm.const n) := return (holtype.ltype n) -- TODO: Check for "n" in type definitions. If in there, use found type. Otherwise, add it with type $i
| (holterm.lconst n n1) := return n1
| (holterm.prf) := return holtype.o
| (holterm.var n) := return holtype.i -- TODO: Infer types of variables in holterms
| (holterm.app t u) := return holtype.i -- TODO: Infer type for application (application is probably a function defined as "tff(application, type, a : ($i * $i) > $i)", but we know the type of some specific applications...)
| _ := return holtype.i
meta def holtype.from_expr : expr → holtype
| e@(expr.const n _) := holtype.ltype n
| e := holtype.i
-- might want to do something different
meta def mk_fresh_name : tactic name := tactic.mk_fresh_name
--
meta def body_of : expr → hammer_tactic (expr × name)
| e@(expr.pi n bi d b) := do id ← mk_fresh_name,
let x := expr.local_const id n bi d,
return $ prod.mk (expr.instantiate_var b x) id
| e@(expr.lam n bi d b) := do id ← mk_fresh_name,
let x := expr.local_const id n bi d,
return $ prod.mk (expr.instantiate_var b x) id
| e := return (e, name.anonymous)
meta def var_list_to_type_list : list (name × name × expr) → list (name × holtype × expr)
| ((n, n1, t) :: xs) := (n, holtype.from_name n1, t) :: var_list_to_type_list xs
| [] := []
-- FC(Γ;Πx:t.s): List of free variables in expression excluding x in s
meta def hammer_fc (e: expr) : list $ name × holtype × expr :=
var_list_to_type_list $
expr.fold e []
(λ (e : expr) n l,
match e with
| e@(expr.local_const n n1 _ t) := let e := (n, n1, t) in if e ∉ l then e::l else l
| _ := l
end)
-- Set of free variables that are not Γ proofs
meta def hammer_ff (l : list $ name × holtype × expr) : hammer_tactic $ list $ name × holtype :=
do exprs ← list.mfilter
(λ x, let (⟨_, _, t⟩ : name × holtype × expr) := x in
do lip ← lives_in_prop_p t,
return ¬lip)
l,
return $ list.foldl
(λ a (x : name × holtype × expr), let (⟨n, n1, t⟩ : name × holtype × expr) := x in
⟨n, n1⟩ :: a)
[] exprs
meta def wrap_quantifier (binder : name → holtype → holform → holform) (ns : list $ name × holtype) (f : holform) : holform :=
list.foldr
(λ (np : name × holtype) f, binder np.1 np.2 f)
(holform.abstract_locals f (list.map (λ (np : name × holtype), np.1) ns))
ns
meta def collect_lambdas_aux :
(expr × (list $ name × holtype × expr)) →
hammer_tactic (expr × (list $ name × holtype × expr))
| (e@(expr.lam n n1 t _), l) := do (b, xn) ← body_of e, tactic.trace b, tactic.trace xn, collect_lambdas_aux (b, (xn, holtype.from_expr t, t) :: l)
| a := return a
meta def remove_suffix_of_string : list char → list char
| ['.','_','m','a','i','n'] := []
-- | ('.' :: '_' :: b) := [] -- What about other suffixes than main?
| (a :: b) := ([a] ++ remove_suffix_of_string b)
| [] := []
meta def collect_lambdas (e : expr) := collect_lambdas_aux (e, [])
meta def trace_list : list (name × holtype) → hammer_tactic unit
| (x :: xs) := do tactic.trace (x.1), trace_list xs
| _ := tactic.trace "End"
meta mutual def hammer_c_aux, hammer_g_aux, hammer_f_aux
with hammer_c_aux : expr → ℕ → hammer_tactic holterm
| e@(expr.const n _) _ :=
do
t ← tactic.infer_type e, -- consult the environment (get type of expression)
lip ← lives_in_prop_p t, -- check whether t is prop or not
if lip
then
return $ holterm.prf -- What about the type/formula it actually proofs?
else
return $ holterm.const $ (remove_suffix_of_string n.to_string.to_list).as_string
| (expr.local_const n pp _ t) depth := -- Same for local constants
do lip ← lives_in_prop_p t,
if lip
then
return $ holterm.prf
else
do ttype ← (hammer_g_aux t depth),
return $ holterm.lconst n ttype
| (expr.app t s) depth := -- Application (in paper C_Γ(ts)=...)
do tp ← hammer_c_aux t depth, -- Get C_Γ(t)
sp ← hammer_c_aux s depth, -- Get C_Γ(s)
match tp with
| holterm.prf := return holterm.prf -- If C_Γ(t) is type proof, then just return type proof
| _ := -- Anything else: check what type C_Γ(s) has
match sp with
| holterm.prf := return tp -- If it is a proof, return C_Γ(t)
| _ := return $ holterm.app tp sp -- else: Return C_Γ(t) applied on C_Γ(s)
end
end
| e@(expr.pi n n1 t _) depth := -- Dependent types
do sorry -- TODO: How to deal with pi expressions the best? Can we translate them into lambda expressions?
| e@(expr.lam n b a c) depth := -- Lambda expression C_Γ(λx:τ.t)=Fy_0
do -- tactic.trace "Lambda at depth ",
let vname := "V" ++ to_string depth,
-- tactic.trace vname,
vtype <- hammer_g_aux a depth, -- Type of variable
inner_expr <- hammer_c_aux c (depth+1), -- Expression within the lambda expression
return $ holterm.lambda vname vtype inner_expr
| e@(expr.var n) depth := return $ holterm.var n
-- TODO: Check if those need to be implemented as well
| e@(expr.elet x τ t s) depth := do tactic.trace "Found elet during translation",
undefined
| e@(expr.sort _) depth := do tactic.trace "Found sort during translation",
undefined
| e@(expr.mvar _ _ _) depth := do tactic.trace "Found mvar during translation",
undefined
| e@(expr.macro _ _) depth := do tactic.trace "Found macro during translation",
undefined
with hammer_g_aux : expr → ℕ → hammer_tactic holtype
| `(ℕ) _ := return holtype.int
| `(expr.sort level.zero) _ := return holtype.o
| `(Sort _) _ := return holtype.type
| e@(expr.app a b) depth := do
transl_a <- hammer_c_aux a depth,
transl_b <- hammer_c_aux b depth,
return $ holtype.partial_app $ holterm.app transl_a transl_b
| e@(expr.lam n b a c) depth := do
let vname := "V" ++ to_string depth,
vtype <- hammer_g_aux a depth, -- Type of variable
inner_expr <- hammer_g_aux c (depth+1), -- Expression within the lambda expression
match inner_expr with
| holtype.dep_binder l t := return $ holtype.dep_binder ([(vname, vtype)]++l) t
| _ := return $ holtype.dep_binder [(vname, vtype)] inner_expr
end
-- Equal to Π equation
| `(%%l → %%r) depth := do
right_type <- hammer_g_aux r depth,
left_type <- hammer_g_aux l depth,
match right_type with
| holtype.functor list_params return_type := return $ holtype.functor ([left_type] ++ list_params) return_type
| _ := return $ holtype.functor [left_type] right_type
end
| e@(expr.const n _) _ := return $ holtype.ltype e.to_string
| e depth := do tactic.trace "hammer_g_aux expression Type", tactic.trace e, return $ holtype.i
with hammer_f_aux : expr → ℕ → hammer_tactic holform
-- Pi notations are translated as ∀x
| e@(expr.pi n _ t s) depth :=
do lip ← lives_in_prop_p t,
if lip -- If t is prop, we can translate it more efficiently (t → s)
then
do fe1 ← hammer_f_aux t depth,
(s, _) ← body_of e,
fe2 ← hammer_f_aux s depth,
return $ holform.imp fe1 fe2
else
do let vname := "V" ++ to_string depth,
vtype <- hammer_g_aux t depth, -- Type of variable
fe2 ← hammer_f_aux s (depth+1),
return $ holform.all vname vtype fe2
-- Translating conjunction
| e@`(and %%t %%s) depth :=
do fe1 ← hammer_f_aux t depth,
fe2 ← hammer_f_aux s depth,
return $ holform.conj fe1 fe2
-- Translating disjunction
| `(or %%t %%s) depth :=
do fe1 ← hammer_f_aux t depth,
fe2 ← hammer_f_aux s depth,
return $ holform.disj fe1 fe2
-- Translating two-sided implication A⇄B
| `(iff %%t %%s) depth :=
do fe1 ← hammer_f_aux t depth,
fe2 ← hammer_f_aux s depth,
return $ holform.iff fe1 fe2
-- Translating negation
| `(not %%t) depth :=
do fe1 ← hammer_f_aux t depth,
return $ holform.neg $ fe1
-- Translating equality
| `(%%t = %%s) depth :=
do fe1 ← hammer_c_aux t depth,
fe2 ← hammer_c_aux s depth,
return $ holform.eq fe1 fe2
| t depth :=
do ge1 ← hammer_c_aux t depth,
return $ holform.P ge1
meta def hammer_f (e : expr) : hammer_tactic holform := hammer_f_aux e 1
meta def hammer_c (e : expr) : hammer_tactic holterm := hammer_c_aux e 1
meta def hammer_g (e : expr) : hammer_tactic holtype := hammer_g_aux e 1
---------------------
-- DEBUG FUNCTIONS --
---------------------
run_cmd do (c, _) <- using_hammer $ hammer_c_aux `(1+1=2) 1, tactic.trace $ holterm.to_format c
run_cmd do (c, _) <- using_hammer $ hammer_c_aux `(λ (x:ℕ→ℕ), x 1 + 1 = (λ(y:ℕ), (x 1)-y*1) 1 ) 1, tactic.trace $ holterm.to_format c
run_cmd do (c, _) <- using_hammer $ hammer_c_aux `(λ (x:(list ℕ)→ℕ), 1) 1, tactic.trace $ holterm.to_format c
run_cmd do (c, _) <- using_hammer $ hammer_c_aux `(λ {α : Type} (x:(list α)→ℕ), 1) 1, tactic.trace $ holterm.to_format c
def fib : nat -> nat
| 0 := 1
| 1 := 1
| (nat.succ (nat.succ n)) := fib n + fib (nat.succ n)
run_cmd do (c, _) <- using_hammer $ hammer_f_aux `(1+1=2) 1, tactic.trace $ holform.to_format c
run_cmd do (c, _) <- using_hammer $ hammer_g_aux `(fib) 1, tactic.trace $ holtype.to_format c
run_cmd do tp ← tactic.infer_type `(fib), (c, _) <- using_hammer $ hammer_g_aux tp 1, tactic.trace $ holtype.to_format c
|
b17d49366f6d3b20e0b94cc8b7bf248593dc8e39 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/field_theory/normal.lean | 0ffe508f3c704fe66a6bde9b0b9dc6bcf0d25ba9 | [
"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 | 21,848 | 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
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
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 (polynomial.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 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 (h2.def.resolve_left (minpoly.ne_zero h1)
(minpoly.irreducible (is_integral_of_is_scalar_tower
((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_algebra_map, ← aeval_algebra_map_apply],
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 := map_is_integral 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⟩
-- seems to be causing a diamond in the below proof
-- however, this may be a fluke and the proof below uses non-canonical `algebra` instances:
-- when I replaced all the instances inside the proof with the "canonical" instances we have,
-- I had the (unprovable) goal (of the form) `adjoin_root.mk f (C x) = adjoin_root.mk f X`
-- for some `x, f`. So maybe this is indeed the correct approach and rewriting this proof is
-- salient in the future, or at least taking a closer look at the algebra instances it uses.
local attribute [-instance] adjoin_root.has_smul
lemma normal.of_is_splitting_field (p : F[X]) [hFEp : is_splitting_field F E p] : normal F E :=
begin
unfreezingI { rcases eq_or_ne p 0 with rfl | hp },
{ have := hFEp.adjoin_root_set,
simp only [root_set_zero, algebra.adjoin_empty] at this,
exact normal.of_alg_equiv (alg_equiv.of_bijective (algebra.of_id F E)
(algebra.bijective_algebra_map_iff.2 this.symm)) },
refine normal_iff.2 (λ x, _),
have 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,
{ rw [power_basis.finrank pbED, adjoin_root.power_basis_dim] },
haveI : finite_dimensional F D := finite_dimensional.trans F E D,
rsuffices ⟨ϕ⟩ : nonempty (D →ₐ[F] E),
{ 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_root_set adjoin_root.adjoin_root_eq_top),
rw [set.image_singleton, ring_hom.algebra_map_to_algebra, adjoin_root.lift_root]
end
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
variables {F K} {L : Type*} [field L] [algebra F L] [algebra K L] [is_scalar_tower F K L]
@[simp] lemma restrict_scalars_normal {E : intermediate_field K L} :
normal F (E.restrict_scalars F) ↔ normal F E :=
iff.rfl
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,
refine or.resolve_left (h.splits z).def (minpoly.ne_zero (h.is_integral z))
(minpoly.irreducible _) (minpoly.dvd E _ (by simp [aeval_alg_hom_apply])),
simp only [alg_hom.to_ring_hom_eq_coe, alg_hom.coe_to_ring_hom],
suffices : is_integral F _,
{ exact is_integral_of_is_scalar_tower this },
exact map_is_integral ϕ (map_is_integral (to_alg_hom F E K₁) (h.is_integral z)) }⟩,
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]))
lemma alg_hom.field_range_of_normal {E : intermediate_field F K} [normal F E] (f : E →ₐ[F] K) :
f.field_range = E :=
begin
haveI : is_scalar_tower F E E := by apply_instance,
let g := f.restrict_normal' E,
rw [←show E.val.comp ↑g = f, from fun_like.ext_iff.mpr (f.restrict_normal_commutes E),
←alg_hom.map_field_range, g.field_range_eq_top, ←E.val.field_range_eq_map, E.field_range_val],
end
/-- 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 (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
section normal_closure
open intermediate_field
variables (F K) (L : Type*) [field L] [algebra F L] [algebra K L] [is_scalar_tower F K L]
/-- The normal closure of `K` in `L`. -/
noncomputable! def normal_closure : intermediate_field K L :=
{ algebra_map_mem' := λ r, le_supr (λ f : K →ₐ[F] L, f.field_range)
(is_scalar_tower.to_alg_hom F K L) ⟨r, rfl⟩,
.. (⨆ f : K →ₐ[F] L, f.field_range).to_subfield }
namespace normal_closure
lemma restrict_scalars_eq_supr_adjoin [h : normal F L] :
(normal_closure F K L).restrict_scalars F = ⨆ x : K, adjoin F ((minpoly F x).root_set L) :=
begin
refine le_antisymm (supr_le _) (supr_le (λ x, adjoin_le_iff.mpr (λ y hy, _))),
{ rintros f _ ⟨x, rfl⟩,
refine le_supr (λ x, adjoin F ((minpoly F x).root_set L)) x
(subset_adjoin F ((minpoly F x).root_set L) _),
rw [mem_root_set_of_ne, alg_hom.to_ring_hom_eq_coe, alg_hom.coe_to_ring_hom,
polynomial.aeval_alg_hom_apply, minpoly.aeval, map_zero],
exact minpoly.ne_zero ((is_integral_algebra_map_iff (algebra_map K L).injective).mp
(h.is_integral (algebra_map K L x))) },
{ rw [polynomial.root_set, finset.mem_coe, multiset.mem_to_finset] at hy,
let g := (alg_hom_adjoin_integral_equiv F ((is_integral_algebra_map_iff
(algebra_map K L).injective).mp (h.is_integral (algebra_map K L x)))).symm ⟨y, hy⟩,
refine le_supr (λ f : K →ₐ[F] L, f.field_range)
((g.lift_normal L).comp (is_scalar_tower.to_alg_hom F K L))
⟨x, (g.lift_normal_commutes L (adjoin_simple.gen F x)).trans _⟩,
rw [algebra.id.map_eq_id, ring_hom.id_apply],
apply power_basis.lift_gen },
end
instance normal [h : normal F L] : normal F (normal_closure F K L) :=
let ϕ := algebra_map K L in begin
rw [←intermediate_field.restrict_scalars_normal, restrict_scalars_eq_supr_adjoin],
apply intermediate_field.normal_supr F L _,
intro x,
apply normal.of_is_splitting_field (minpoly F x),
exact adjoin_root_set_is_splitting_field ((minpoly.eq_of_algebra_map_eq ϕ.injective
((is_integral_algebra_map_iff ϕ.injective).mp (h.is_integral (ϕ x))) rfl).symm ▸ h.splits _),
end
instance is_finite_dimensional [finite_dimensional F K] :
finite_dimensional F (normal_closure F K L) :=
begin
haveI : ∀ f : K →ₐ[F] L, finite_dimensional F f.field_range :=
λ f, f.to_linear_map.finite_dimensional_range,
apply intermediate_field.finite_dimensional_supr_of_finite,
end
instance is_scalar_tower : is_scalar_tower F (normal_closure F K L) L :=
is_scalar_tower.subalgebra' F L L _
end normal_closure
end normal_closure
|
db9345dfb1f6a2d4c99cf2b45a40898eec8cc173 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/big_operators/finsupp.lean | 3f5f0befbb492beda6f5016560f20ec21d4aedbe | [
"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 | 1,994 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import data.finsupp.basic
import algebra.big_operators.pi
import algebra.big_operators.ring
import algebra.big_operators.order
/-!
# Big operators for finsupps
This file contains theorems relevant to big operators in finitely supported functions.
-/
open_locale big_operators
variables {α ι γ A B C : Type*} [add_comm_monoid A] [add_comm_monoid B] [add_comm_monoid C]
variables {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)
variables {s : finset α} {f : α → (ι →₀ A)} (i : ι)
variables (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)
theorem finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i :=
(finsupp.apply_add_hom i : (ι →₀ A) →+ A).map_sum f s
theorem finsupp.sum_apply' : g.sum k x = g.sum (λ i b, k i b x) :=
finset.sum_apply _ _ _
section
include h0 h1
open_locale classical
theorem finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t :=
finset.induction_on s rfl $ λ a s has ih,
by simp_rw [finset.sum_insert has, finsupp.sum_add_index' h0 h1, ih]
end
section
variables {R S : Type*} [non_unital_non_assoc_semiring R] [non_unital_non_assoc_semiring S]
lemma finsupp.sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :
(s.sum f) * b = s.sum (λ a c, (f a c) * b) :=
by simp only [finsupp.sum, finset.sum_mul]
lemma finsupp.mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :
b * (s.sum f) = s.sum (λ a c, b * (f a c)) :=
by simp only [finsupp.sum, finset.mul_sum]
end
namespace nat
/-- If `0 : ℕ` is not in the support of `f : ℕ →₀ ℕ` then `0 < ∏ x in f.support, x ^ (f x)`. -/
lemma prod_pow_pos_of_zero_not_mem_support {f : ℕ →₀ ℕ} (hf : 0 ∉ f.support) : 0 < f.prod pow :=
finset.prod_pos (λ a ha, pos_iff_ne_zero.mpr (pow_ne_zero _ (λ H, by {subst H, exact hf ha})))
end nat
|
b48916c37d13001f7c1fb9276b24f00da7852d0c | 798dd332c1ad790518589a09bc82459fb12e5156 | /analysis/topology/continuity.lean | 8cebe94725f9af1c8d87e0591717500f9f8b3a21 | [
"Apache-2.0"
] | permissive | tobiasgrosser/mathlib | b040b7eb42d5942206149371cf92c61404de3c31 | 120635628368ec261e031cefc6d30e0304088b03 | refs/heads/master | 1,644,803,442,937 | 1,536,663,752,000 | 1,536,663,907,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 47,794 | 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
Continuous functions.
Parts of the formalization is based on the books:
N. Bourbaki: General Topology
I. M. James: Topologies and Uniformities
A major difference is that this formalization is heavily based on the filter library.
-/
import analysis.topology.topological_space
noncomputable theory
open set filter lattice
local attribute [instance] classical.prop_decidable
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
section
variables [topological_space α] [topological_space β] [topological_space γ]
/-- A function between topological spaces is continuous if the preimage
of every open set is open. -/
def continuous (f : α → β) := ∀s, is_open s → is_open (f ⁻¹' s)
lemma continuous_id : continuous (id : α → α) :=
assume s h, h
lemma continuous.comp {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g):
continuous (g ∘ f) :=
assume s h, hf _ (hg s h)
lemma continuous.tendsto {f : α → β} (hf : continuous f) (x) :
tendsto f (nhds x) (nhds (f x)) | s :=
show s ∈ (nhds (f x)).sets → s ∈ (map f (nhds x)).sets,
by simp [nhds_sets]; exact
assume t t_subset t_open fx_in_t,
⟨f ⁻¹' t, preimage_mono t_subset, hf t t_open, fx_in_t⟩
lemma continuous_iff_tendsto {f : α → β} :
continuous f ↔ (∀x, tendsto f (nhds x) (nhds (f x))) :=
⟨continuous.tendsto,
assume hf : ∀x, tendsto f (nhds x) (nhds (f x)),
assume s, assume hs : is_open s,
have ∀a, f a ∈ s → s ∈ (nhds (f a)).sets,
by simp [nhds_sets]; exact assume a ha, ⟨s, subset.refl s, hs, ha⟩,
show is_open (f ⁻¹' s),
by simp [is_open_iff_nhds]; exact assume a ha, hf a (this a ha)⟩
lemma continuous_const {b : β} : continuous (λa:α, b) :=
continuous_iff_tendsto.mpr $ assume a, tendsto_const_nhds
lemma continuous_iff_is_closed {f : α → β} :
continuous f ↔ (∀s, is_closed s → is_closed (f ⁻¹' s)) :=
⟨assume hf s hs, hf (-s) hs,
assume hf s, by rw [←is_closed_compl_iff, ←is_closed_compl_iff]; exact hf _⟩
lemma continuous_if {p : α → Prop} {f g : α → β} {h : ∀a, decidable (p a)}
(hp : ∀a∈frontier {a | p a}, f a = g a) (hf : continuous f) (hg : continuous g) :
continuous (λa, @ite (p a) (h a) β (f a) (g a)) :=
continuous_iff_is_closed.mpr $
assume s hs,
have (λa, ite (p a) (f a) (g a)) ⁻¹' s =
(closure {a | p a} ∩ f ⁻¹' s) ∪ (closure {a | ¬ p a} ∩ g ⁻¹' s),
from set.ext $ assume a,
classical.by_cases
(assume : a ∈ frontier {a | p a},
have hac : a ∈ closure {a | p a}, from this.left,
have hai : a ∈ closure {a | ¬ p a},
from have a ∈ - interior {a | p a}, from this.right, by rwa [←closure_compl] at this,
by by_cases p a; simp [h, hp a this, hac, hai, iff_def] {contextual := tt})
(assume hf : a ∈ - frontier {a | p a},
classical.by_cases
(assume : p a,
have hc : a ∈ closure {a | p a}, from subset_closure this,
have hnc : a ∉ closure {a | ¬ p a},
by show a ∉ closure (- {a | p a}); rw [closure_compl]; simpa [frontier, hc] using hf,
by simp [this, hc, hnc])
(assume : ¬ p a,
have hc : a ∈ closure {a | ¬ p a}, from subset_closure this,
have hnc : a ∉ closure {a | p a},
begin
have hc : a ∈ closure (- {a | p a}), from hc,
simp [closure_compl] at hc,
simpa [frontier, hc] using hf
end,
by simp [this, hc, hnc])),
by rw [this]; exact is_closed_union
(is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hf s hs)
(is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hg s hs)
lemma image_closure_subset_closure_image {f : α → β} {s : set α} (h : continuous f) :
f '' closure s ⊆ closure (f '' s) :=
have ∀ (a : α), nhds a ⊓ principal s ≠ ⊥ → nhds (f a) ⊓ principal (f '' s) ≠ ⊥,
from assume a ha,
have h₁ : ¬ map f (nhds a ⊓ principal s) = ⊥,
by rwa[map_eq_bot_iff],
have h₂ : map f (nhds a ⊓ principal s) ≤ nhds (f a) ⊓ principal (f '' s),
from le_inf
(le_trans (map_mono inf_le_left) $ by rw [continuous_iff_tendsto] at h; exact h a)
(le_trans (map_mono inf_le_right) $ by simp; exact subset.refl _),
neq_bot_of_le_neq_bot h₁ h₂,
by simp [image_subset_iff, closure_eq_nhds]; assumption
lemma compact_image {s : set α} {f : α → β} (hs : compact s) (hf : continuous f) : compact (f '' s) :=
compact_of_finite_subcover $ assume c hco hcs,
have hdo : ∀t∈c, is_open (f ⁻¹' t), from assume t' ht, hf _ $ hco _ ht,
have hds : s ⊆ ⋃i∈c, f ⁻¹' i,
by simpa [subset_def, -mem_image] using hcs,
let ⟨d', hcd', hfd', hd'⟩ := compact_elim_finite_subcover_image hs hdo hds in
⟨d', hcd', hfd', by simpa [subset_def, -mem_image, image_subset_iff] using hd'⟩
end
section constructions
local notation `cont` := @continuous _ _
local notation `tspace` := topological_space
open topological_space
variables {f : α → β} {ι : Sort*}
lemma continuous_iff_le_coinduced {t₁ : tspace α} {t₂ : tspace β} :
cont t₁ t₂ f ↔ t₂ ≤ coinduced f t₁ := iff.rfl
lemma continuous_iff_induced_le {t₁ : tspace α} {t₂ : tspace β} :
cont t₁ t₂ f ↔ induced f t₂ ≤ t₁ :=
iff.trans continuous_iff_le_coinduced (gc_induced_coinduced f _ _).symm
theorem continuous_generated_from {t : tspace α} {b : set (set β)}
(h : ∀s∈b, is_open (f ⁻¹' s)) : cont t (generate_from b) f :=
continuous_iff_le_coinduced.2 $ generate_from_le h
lemma continuous_induced_dom {t : tspace β} : cont (induced f t) t f :=
assume s h, ⟨_, h, rfl⟩
lemma continuous_induced_rng {g : γ → α} {t₂ : tspace β} {t₁ : tspace γ}
(h : cont t₁ t₂ (f ∘ g)) : cont t₁ (induced f t₂) g :=
assume s ⟨t, ht, s_eq⟩, s_eq.symm ▸ h t ht
lemma continuous_coinduced_rng {t : tspace α} : cont t (coinduced f t) f :=
assume s h, h
lemma continuous_coinduced_dom {g : β → γ} {t₁ : tspace α} {t₂ : tspace γ}
(h : cont t₁ t₂ (g ∘ f)) : cont (coinduced f t₁) t₂ g :=
assume s hs, h s hs
lemma continuous_le_dom {t₁ t₂ : tspace α} {t₃ : tspace β}
(h₁ : t₁ ≤ t₂) (h₂ : cont t₁ t₃ f) : cont t₂ t₃ f :=
assume s h, h₁ _ (h₂ s h)
lemma continuous_le_rng {t₁ : tspace α} {t₂ t₃ : tspace β}
(h₁ : t₃ ≤ t₂) (h₂ : cont t₁ t₂ f) : cont t₁ t₃ f :=
assume s h, h₂ s (h₁ s h)
lemma continuous_inf_dom {t₁ t₂ : tspace α} {t₃ : tspace β}
(h₁ : cont t₁ t₃ f) (h₂ : cont t₂ t₃ f) : cont (t₁ ⊓ t₂) t₃ f :=
assume s h, ⟨h₁ s h, h₂ s h⟩
lemma continuous_inf_rng_left {t₁ : tspace α} {t₃ t₂ : tspace β} :
cont t₁ t₂ f → cont t₁ (t₂ ⊓ t₃) f :=
continuous_le_rng inf_le_left
lemma continuous_inf_rng_right {t₁ : tspace α} {t₃ t₂ : tspace β} :
cont t₁ t₃ f → cont t₁ (t₂ ⊓ t₃) f :=
continuous_le_rng inf_le_right
lemma continuous_Inf_dom {t₁ : set (tspace α)} {t₂ : tspace β}
(h : ∀t∈t₁, cont t t₂ f) : cont (Inf t₁) t₂ f :=
continuous_iff_induced_le.2 $ le_Inf $ assume t ht, continuous_iff_induced_le.1 $ h t ht
lemma continuous_Inf_rng {t₁ : tspace α} {t₂ : set (tspace β)} {t : tspace β}
(h₁ : t ∈ t₂) (hf : cont t₁ t f) : cont t₁ (Inf t₂) f :=
continuous_iff_le_coinduced.2 $ Inf_le_of_le h₁ $ continuous_iff_le_coinduced.1 hf
lemma continuous_infi_dom {t₁ : ι → tspace α} {t₂ : tspace β}
(h : ∀i, cont (t₁ i) t₂ f) : cont (infi t₁) t₂ f :=
continuous_Inf_dom $ assume t ⟨i, (t_eq : t = t₁ i)⟩, t_eq.symm ▸ h i
lemma continuous_infi_rng {t₁ : tspace α} {t₂ : ι → tspace β} {i : ι}
(h : cont t₁ (t₂ i) f) : cont t₁ (infi t₂) f :=
continuous_Inf_rng ⟨i, rfl⟩ h
lemma continuous_sup_rng {t₁ : tspace α} {t₂ t₃ : tspace β}
(h₁ : cont t₁ t₂ f) (h₂ : cont t₁ t₃ f) : cont t₁ (t₂ ⊔ t₃) f :=
continuous_iff_le_coinduced.2 $ sup_le
(continuous_iff_le_coinduced.1 h₁)
(continuous_iff_le_coinduced.1 h₂)
lemma continuous_sup_dom_left {t₁ t₂ : tspace α} {t₃ : tspace β} :
cont t₁ t₃ f → cont (t₁ ⊔ t₂) t₃ f :=
continuous_le_dom le_sup_left
lemma continuous_sup_dom_right {t₁ t₂ : tspace α} {t₃ : tspace β} :
cont t₂ t₃ f → cont (t₁ ⊔ t₂) t₃ f :=
continuous_le_dom le_sup_right
lemma continuous_Sup_dom {t₁ : set (tspace α)} {t₂ : tspace β} {t : tspace α} (h₁ : t ∈ t₁) :
cont t t₂ f → cont (Sup t₁) t₂ f :=
continuous_le_dom $ le_Sup h₁
lemma continuous_Sup_rng {t₁ : tspace α} {t₂ : set (tspace β)}
(h : ∀t∈t₂, cont t₁ t f) : cont t₁ (Sup t₂) f :=
continuous_iff_le_coinduced.2 $ Sup_le $ assume b hb, continuous_iff_le_coinduced.1 $ h b hb
lemma continuous_supr_dom {t₁ : ι → tspace α} {t₂ : tspace β} {i : ι} :
cont (t₁ i) t₂ f → cont (supr t₁) t₂ f :=
continuous_le_dom $ le_supr _ _
lemma continuous_supr_rng {t₁ : tspace α} {t₂ : ι → tspace β}
(h : ∀i, cont t₁ (t₂ i) f) : cont t₁ (supr t₂) f :=
continuous_iff_le_coinduced.2 $ supr_le $ assume i, continuous_iff_le_coinduced.1 $ h i
lemma continuous_top {t : tspace β} : cont ⊤ t f :=
continuous_iff_induced_le.2 $ le_top
lemma continuous_bot {t : tspace α} : cont t ⊥ f :=
continuous_iff_le_coinduced.2 $ bot_le
end constructions
section embedding
/-- A function between topological spaces is an embedding if it is injective,
and for all `s : set α`, `s` is open iff it is the preimage of an open set. -/
def embedding [tα : topological_space α] [tβ : topological_space β] (f : α → β) : Prop :=
function.injective f ∧ tα = tβ.induced f
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
lemma embedding_id : embedding (@id α) :=
⟨assume a₁ a₂ h, h, induced_id.symm⟩
lemma embedding_compose {f : α → β} {g : β → γ} (hf : embedding f) (hg : embedding g) :
embedding (g ∘ f) :=
⟨assume a₁ a₂ h, hf.left $ hg.left h, by rw [hf.right, hg.right, induced_compose]⟩
lemma embedding_prod_mk {f : α → β} {g : γ → δ} (hf : embedding f) (hg : embedding g) :
embedding (λx:α×γ, (f x.1, g x.2)) :=
⟨assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume h₁ h₂, ⟨hf.left h₁, hg.left h₂⟩,
by rw [prod.topological_space, prod.topological_space, hf.right, hg.right,
induced_compose, induced_compose, induced_sup, induced_compose, induced_compose]⟩
lemma embedding_of_embedding_compose {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g)
(hgf : embedding (g ∘ f)) : embedding f :=
⟨assume a₁ a₂ h, hgf.left $ by simp [h, (∘)],
le_antisymm
(by rw [hgf.right, ← continuous_iff_induced_le];
apply continuous_induced_dom.comp hg)
(by rwa ← continuous_iff_induced_le)⟩
lemma embedding_open {f : α → β} {s : set α}
(hf : embedding f) (h : is_open (range f)) (hs : is_open s) : is_open (f '' s) :=
let ⟨t, ht, h_eq⟩ := by rw [hf.right] at hs; exact hs in
have is_open (t ∩ range f), from is_open_inter ht h,
h_eq.symm ▸ by rwa [image_preimage_eq_inter_range]
lemma embedding_is_closed {f : α → β} {s : set α}
(hf : embedding f) (h : is_closed (range f)) (hs : is_closed s) : is_closed (f '' s) :=
let ⟨t, ht, h_eq⟩ := by rw [hf.right, is_closed_induced_iff] at hs; exact hs in
have is_closed (t ∩ range f), from is_closed_inter ht h,
h_eq.symm ▸ by rwa [image_preimage_eq_inter_range]
end embedding
section quotient_map
/-- A function between topological spaces is a quotient map if it is surjective,
and for all `s : set β`, `s` is open iff its preimage is an open set. -/
def quotient_map [tα : topological_space α] [tβ : topological_space β] (f : α → β) : Prop :=
function.surjective f ∧ tβ = tα.coinduced f
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
lemma quotient_map_id : quotient_map (@id α) :=
⟨assume a, ⟨a, rfl⟩, coinduced_id.symm⟩
lemma quotient_map_compose {f : α → β} {g : β → γ} (hf : quotient_map f) (hg : quotient_map g) :
quotient_map (g ∘ f) :=
⟨function.surjective_comp hg.left hf.left, by rw [hg.right, hf.right, coinduced_compose]⟩
lemma quotient_map_of_quotient_map_compose {f : α → β} {g : β → γ}
(hf : continuous f) (hg : continuous g)
(hgf : quotient_map (g ∘ f)) : quotient_map g :=
⟨assume b, let ⟨a, h⟩ := hgf.left b in ⟨f a, h⟩,
le_antisymm
(by rwa ← continuous_iff_le_coinduced)
(by rw [hgf.right, ← continuous_iff_le_coinduced];
apply hf.comp continuous_coinduced_rng)⟩
end quotient_map
section sierpinski
variables [topological_space α]
@[simp] lemma is_open_singleton_true : is_open ({true} : set Prop) :=
topological_space.generate_open.basic _ (by simp)
lemma continuous_Prop {p : α → Prop} : continuous p ↔ is_open {x | p x} :=
⟨assume h : continuous p,
have is_open (p ⁻¹' {true}),
from h _ is_open_singleton_true,
by simp [preimage, eq_true] at this; assumption,
assume h : is_open {x | p x},
continuous_generated_from $ assume s (hs : s ∈ {{true}}),
by simp at hs; simp [hs, preimage, eq_true, h]⟩
end sierpinski
section induced
open topological_space
variables [t : topological_space β] {f : α → β}
theorem is_open_induced {s : set β} (h : is_open s) : (induced f t).is_open (f ⁻¹' s) :=
⟨s, h, rfl⟩
lemma nhds_induced_eq_comap {a : α} : @nhds α (induced f t) a = comap f (nhds (f a)) :=
le_antisymm
(assume s ⟨s', hs', (h_s : f ⁻¹' s' ⊆ s)⟩,
let ⟨t', hsub, ht', hin⟩ := mem_nhds_sets_iff.1 hs' in
(@nhds α (induced f t) a).sets_of_superset
begin
simp [mem_nhds_sets_iff],
exact ⟨preimage f t', preimage_mono hsub, is_open_induced ht', hin⟩
end
h_s)
(le_infi $ assume s, le_infi $ assume ⟨as, s', is_open_s', s_eq⟩,
begin
simp [comap, mem_nhds_sets_iff, s_eq],
exact ⟨s', ⟨s', subset.refl _, is_open_s', by rwa [s_eq] at as⟩, subset.refl _⟩
end)
lemma map_nhds_induced_eq {a : α} (h : image f univ ∈ (nhds (f a)).sets) :
map f (@nhds α (induced f t) a) = nhds (f a) :=
le_antisymm
(@continuous.tendsto α β (induced f t) _ _ continuous_induced_dom a)
(assume s, assume hs : f ⁻¹' s ∈ (@nhds α (induced f t) a).sets,
let ⟨t', t_subset, is_open_t, a_in_t⟩ := mem_nhds_sets_iff.mp h in
let ⟨s', s'_subset, ⟨s'', is_open_s'', s'_eq⟩, a_in_s'⟩ := (@mem_nhds_sets_iff _ (induced f t) _ _).mp hs in
by subst s'_eq; exact (mem_nhds_sets_iff.mpr $
⟨t' ∩ s'',
assume x ⟨h₁, h₂⟩, match x, h₂, t_subset h₁ with
| x, h₂, ⟨y, _, y_eq⟩ := begin subst y_eq, exact s'_subset h₂ end
end,
is_open_inter is_open_t is_open_s'',
⟨a_in_t, a_in_s'⟩⟩))
lemma embedding.map_nhds_eq [topological_space α] [topological_space β] {f : α → β} (hf : embedding f) (a : α)
(h : f '' univ ∈ (nhds (f a)).sets) : (nhds a).map f = nhds (f a) :=
by rw [hf.2]; exact map_nhds_induced_eq h
lemma closure_induced [t : topological_space β] {f : α → β} {a : α} {s : set α}
(hf : ∀x y, f x = f y → x = y) :
a ∈ @closure α (topological_space.induced f t) s ↔ f a ∈ closure (f '' s) :=
have comap f (nhds (f a) ⊓ principal (f '' s)) ≠ ⊥ ↔ nhds (f a) ⊓ principal (f '' s) ≠ ⊥,
from ⟨assume h₁ h₂, h₁ $ h₂.symm ▸ comap_bot,
assume h,
forall_sets_neq_empty_iff_neq_bot.mp $
assume s₁ ⟨s₂, hs₂, (hs : f ⁻¹' s₂ ⊆ s₁)⟩,
have f '' s ∈ (nhds (f a) ⊓ principal (f '' s)).sets,
from mem_inf_sets_of_right $ by simp [subset.refl],
have s₂ ∩ f '' s ∈ (nhds (f a) ⊓ principal (f '' s)).sets,
from inter_mem_sets hs₂ this,
let ⟨b, hb₁, ⟨a, ha, ha₂⟩⟩ := inhabited_of_mem_sets h this in
ne_empty_of_mem $ hs $ by rwa [←ha₂] at hb₁⟩,
calc a ∈ @closure α (topological_space.induced f t) s
↔ (@nhds α (topological_space.induced f t) a) ⊓ principal s ≠ ⊥ : by rw [closure_eq_nhds]; refl
... ↔ comap f (nhds (f a)) ⊓ principal (f ⁻¹' (f '' s)) ≠ ⊥ : by rw [nhds_induced_eq_comap, preimage_image_eq _ hf]
... ↔ comap f (nhds (f a) ⊓ principal (f '' s)) ≠ ⊥ : by rw [comap_inf, ←comap_principal]
... ↔ _ : by rwa [closure_eq_nhds]
end induced
section prod
open topological_space
variables [topological_space α] [topological_space β] [topological_space γ]
lemma continuous_fst : continuous (@prod.fst α β) :=
continuous_sup_dom_left continuous_induced_dom
lemma continuous_snd : continuous (@prod.snd α β) :=
continuous_sup_dom_right continuous_induced_dom
lemma continuous.prod_mk {f : γ → α} {g : γ → β}
(hf : continuous f) (hg : continuous g) : continuous (λx, prod.mk (f x) (g x)) :=
continuous_sup_rng (continuous_induced_rng hf) (continuous_induced_rng hg)
lemma continuous_swap : continuous (prod.swap : α × β → β × α) :=
continuous.prod_mk continuous_snd continuous_fst
lemma is_open_prod {s : set α} {t : set β} (hs : is_open s) (ht : is_open t) :
is_open (set.prod s t) :=
is_open_inter (continuous_fst s hs) (continuous_snd t ht)
lemma nhds_prod_eq {a : α} {b : β} : nhds (a, b) = filter.prod (nhds a) (nhds b) :=
by rw [filter.prod, prod.topological_space, nhds_sup, nhds_induced_eq_comap, nhds_induced_eq_comap]
lemma prod_mem_nhds_sets {s : set α} {t : set β} {a : α} {b : β}
(ha : s ∈ (nhds a).sets) (hb : t ∈ (nhds b).sets) : set.prod s t ∈ (nhds (a, b)).sets :=
by rw [nhds_prod_eq]; exact prod_mem_prod ha hb
lemma nhds_swap (a : α) (b : β) : nhds (a, b) = (nhds (b, a)).map prod.swap :=
by rw [nhds_prod_eq, filter.prod_comm, nhds_prod_eq]; refl
lemma tendsto_prod_mk_nhds {γ} {a : α} {b : β} {f : filter γ} {ma : γ → α} {mb : γ → β}
(ha : tendsto ma f (nhds a)) (hb : tendsto mb f (nhds b)) :
tendsto (λc, (ma c, mb c)) f (nhds (a, b)) :=
by rw [nhds_prod_eq]; exact filter.tendsto.prod_mk ha hb
lemma prod_generate_from_generate_from_eq {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
(sup_le
(induced_le_iff_le_coinduced.mpr $ generate_from_le $ 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⟩)
(induced_le_iff_le_coinduced.mpr $ generate_from_le $ 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⟩))
(generate_from_le $ 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))
lemma prod_eq_generate_from [tα : topological_space α] [tβ : topological_space β] :
prod.topological_space =
generate_from {g | ∃(s:set α) (t:set β), is_open s ∧ is_open t ∧ g = set.prod s t} :=
le_antisymm
(sup_le
(assume s ⟨t, ht, s_eq⟩,
have set.prod t univ = s, by simp [s_eq, preimage, set.prod],
this ▸ (generate_open.basic _ ⟨t, univ, ht, is_open_univ, rfl⟩))
(assume s ⟨t, ht, s_eq⟩,
have set.prod univ t = s, by simp [s_eq, preimage, set.prod],
this ▸ (generate_open.basic _ ⟨univ, t, is_open_univ, ht, rfl⟩)))
(generate_from_le $ assume g ⟨s, t, hs, ht, g_eq⟩, g_eq.symm ▸ is_open_prod hs ht)
lemma is_open_prod_iff {s : set (α×β)} : is_open s ↔
(∀a b, (a, b) ∈ s → ∃u v, is_open u ∧ is_open v ∧ a ∈ u ∧ b ∈ v ∧ set.prod u v ⊆ s) :=
begin
rw [is_open_iff_nhds],
simp [nhds_prod_eq, mem_prod_iff],
simp [mem_nhds_sets_iff],
exact forall_congr (assume a, ball_congr $ assume b h,
⟨assume ⟨u', ⟨u, us, uo, au⟩, v', ⟨v, vs, vo, bv⟩, h⟩,
⟨u, uo, v, vo, au, bv, subset.trans (set.prod_mono us vs) h⟩,
assume ⟨u, uo, v, vo, au, bv, h⟩,
⟨u, ⟨u, subset.refl u, uo, au⟩, v, ⟨v, subset.refl v, vo, bv⟩, h⟩⟩)
end
lemma closure_prod_eq {s : set α} {t : set β} :
closure (set.prod s t) = set.prod (closure s) (closure t) :=
set.ext $ assume ⟨a, b⟩,
have filter.prod (nhds a) (nhds b) ⊓ principal (set.prod s t) =
filter.prod (nhds a ⊓ principal s) (nhds b ⊓ principal t),
by rw [←prod_inf_prod, prod_principal_principal],
by simp [closure_eq_nhds, nhds_prod_eq, this]; exact prod_neq_bot
lemma is_closed_prod [topological_space α] [topological_space β] {s₁ : set α} {s₂ : set β}
(h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (set.prod s₁ s₂) :=
closure_eq_iff_is_closed.mp $ by simp [h₁, h₂, closure_prod_eq, closure_eq_of_is_closed]
section tube_lemma
def nhds_contain_boxes (s : set α) (t : set β) : Prop :=
∀ (n : set (α × β)) (hn : is_open n) (hp : set.prod s t ⊆ n),
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n
lemma nhds_contain_boxes.symm {s : set α} {t : set β} :
nhds_contain_boxes s t → nhds_contain_boxes t s :=
assume H n hn hp,
let ⟨u, v, uo, vo, su, tv, p⟩ :=
H (prod.swap ⁻¹' n)
(continuous_swap n hn)
(by rwa [←image_subset_iff, prod.swap, image_swap_prod]) in
⟨v, u, vo, uo, tv, su,
by rwa [←image_subset_iff, prod.swap, image_swap_prod] at p⟩
lemma nhds_contain_boxes.comm {s : set α} {t : set β} :
nhds_contain_boxes s t ↔ nhds_contain_boxes t s :=
iff.intro nhds_contain_boxes.symm nhds_contain_boxes.symm
lemma nhds_contain_boxes_of_singleton {x : α} {y : β} :
nhds_contain_boxes ({x} : set α) ({y} : set β) :=
assume n hn hp,
let ⟨u, v, uo, vo, xu, yv, hp'⟩ :=
is_open_prod_iff.mp hn x y (hp $ by simp) in
⟨u, v, uo, vo, by simpa, by simpa, hp'⟩
lemma nhds_contain_boxes_of_compact {s : set α} (hs : compact s) (t : set β)
(H : ∀ x ∈ s, nhds_contain_boxes ({x} : set α) t) : nhds_contain_boxes s t :=
assume n hn hp,
have ∀x : subtype s, ∃uv : set α × set β,
is_open uv.1 ∧ is_open uv.2 ∧ {↑x} ⊆ uv.1 ∧ t ⊆ uv.2 ∧ set.prod uv.1 uv.2 ⊆ n,
from assume ⟨x, hx⟩,
have set.prod {x} t ⊆ n, from
subset.trans (prod_mono (by simpa) (subset.refl _)) hp,
let ⟨ux,vx,H1⟩ := H x hx n hn this in ⟨⟨ux,vx⟩,H1⟩,
let ⟨uvs, h⟩ := classical.axiom_of_choice this in
have us_cover : s ⊆ ⋃i, (uvs i).1, from
assume x hx, set.subset_Union _ ⟨x,hx⟩ (by simpa using (h ⟨x,hx⟩).2.2.1),
let ⟨s0, _, s0_fin, s0_cover⟩ :=
compact_elim_finite_subcover_image hs (λi _, (h i).1) $
by rw bUnion_univ; exact us_cover in
let u := ⋃(i ∈ s0), (uvs i).1 in
let v := ⋂(i ∈ s0), (uvs i).2 in
have is_open u, from is_open_bUnion (λi _, (h i).1),
have is_open v, from is_open_bInter s0_fin (λi _, (h i).2.1),
have t ⊆ v, from subset_bInter (λi _, (h i).2.2.2.1),
have set.prod u v ⊆ n, from assume ⟨x',y'⟩ ⟨hx',hy'⟩,
have ∃i ∈ s0, x' ∈ (uvs i).1, by simpa using hx',
let ⟨i,is0,hi⟩ := this in
(h i).2.2.2.2 ⟨hi, (bInter_subset_of_mem is0 : v ⊆ (uvs i).2) hy'⟩,
⟨u, v, ‹is_open u›, ‹is_open v›, s0_cover, ‹t ⊆ v›, ‹set.prod u v ⊆ n›⟩
lemma generalized_tube_lemma {s : set α} (hs : compact s) {t : set β} (ht : compact t)
{n : set (α × β)} (hn : is_open n) (hp : set.prod s t ⊆ n) :
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n :=
have _, from
nhds_contain_boxes_of_compact hs t $ assume x _, nhds_contain_boxes.symm $
nhds_contain_boxes_of_compact ht {x} $ assume y _, nhds_contain_boxes_of_singleton,
this n hn hp
end tube_lemma
lemma is_closed_diagonal [topological_space α] [t2_space α] : is_closed {p:α×α | p.1 = p.2} :=
is_closed_iff_nhds.mpr $ assume ⟨a₁, a₂⟩ h, eq_of_nhds_neq_bot $ assume : nhds a₁ ⊓ nhds a₂ = ⊥, h $
let ⟨t₁, ht₁, t₂, ht₂, (h' : t₁ ∩ t₂ ⊆ ∅)⟩ :=
by rw [←empty_in_sets_eq_bot, mem_inf_sets] at this; exact this in
begin
rw [nhds_prod_eq, ←empty_in_sets_eq_bot],
apply filter.sets_of_superset,
apply inter_mem_inf_sets (prod_mem_prod ht₁ ht₂) (mem_principal_sets.mpr (subset.refl _)),
exact assume ⟨x₁, x₂⟩ ⟨⟨hx₁, hx₂⟩, (heq : x₁ = x₂)⟩,
show false, from @h' x₁ ⟨hx₁, heq.symm ▸ hx₂⟩
end
lemma is_closed_eq [topological_space α] [t2_space α] [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : is_closed {x:β | f x = g x} :=
continuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_diagonal
lemma diagonal_eq_range_diagonal_map : {p:α×α | p.1 = p.2} = range (λx, (x,x)) :=
ext $ assume p, iff.intro
(assume h, ⟨p.1, prod.ext_iff.2 ⟨rfl, h⟩⟩)
(assume ⟨x, hx⟩, show p.1 = p.2, by rw ←hx)
lemma prod_subset_compl_diagonal_iff_disjoint {s t : set α} :
set.prod s t ⊆ - {p:α×α | p.1 = p.2} ↔ s ∩ t = ∅ :=
by rw [eq_empty_iff_forall_not_mem, subset_compl_comm,
diagonal_eq_range_diagonal_map, range_subset_iff]; simp
lemma compact_compact_separated [t2_space α] {s t : set α}
(hs : compact s) (ht : compact t) (hst : s ∩ t = ∅) :
∃u v : set α, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ u ∩ v = ∅ :=
by simp only [prod_subset_compl_diagonal_iff_disjoint.symm] at ⊢ hst;
exact generalized_tube_lemma hs ht is_closed_diagonal hst
lemma closed_of_compact [t2_space α] (s : set α) (hs : compact s) : is_closed s :=
is_open_compl_iff.mpr $ is_open_iff_forall_mem_open.mpr $ assume x hx,
let ⟨u, v, uo, vo, su, xv, uv⟩ :=
compact_compact_separated hs (compact_singleton : compact {x})
(by rwa [inter_comm, ←subset_compl_iff_disjoint, singleton_subset_iff]) in
have v ⊆ -s, from
subset_compl_comm.mp (subset.trans su (subset_compl_iff_disjoint.mpr uv)),
⟨v, this, vo, by simpa using xv⟩
/- TODO: more fine grained instances for first_countable_topology, separable_space, t2_space, ... -/
instance [second_countable_topology α] [second_countable_topology β] :
second_countable_topology (α × β) :=
⟨let ⟨a, ha₁, ha₂, ha₃, ha₄, ha₅⟩ := is_open_generated_countable_inter α in
let ⟨b, hb₁, hb₂, hb₃, hb₄, hb₅⟩ := is_open_generated_countable_inter β in
⟨{g | ∃u∈a, ∃v∈b, g = set.prod u v},
have {g | ∃u∈a, ∃v∈b, g = set.prod u v} = (⋃u∈a, ⋃v∈b, {set.prod u v}),
by apply set.ext; simp,
by rw [this]; exact (countable_bUnion ha₁ $ assume u hu, countable_bUnion hb₁ $ by simp),
by rw [ha₅, hb₅, prod_generate_from_generate_from_eq ha₄ hb₄]⟩⟩
end prod
section sum
variables [topological_space α] [topological_space β] [topological_space γ]
lemma continuous_inl : continuous (@sum.inl α β) :=
continuous_inf_rng_left continuous_coinduced_rng
lemma continuous_inr : continuous (@sum.inr α β) :=
continuous_inf_rng_right continuous_coinduced_rng
lemma continuous_sum_rec {f : α → γ} {g : β → γ}
(hf : continuous f) (hg : continuous g) : @continuous (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) :=
continuous_inf_dom hf hg
end sum
lemma embedding.tendsto_nhds_iff [topological_space β] [topological_space γ]
{f : α → β} {g : β → γ} {a : filter α} {b : β} (hg : embedding g) :
tendsto f a (nhds b) ↔ tendsto (g ∘ f) a (nhds (g b)) :=
by rw [tendsto, tendsto, hg.right, nhds_induced_eq_comap, ← map_le_iff_le_comap, filter.map_map]
section subtype
variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop}
lemma embedding.continuous_iff {f : α → β} {g : β → γ} (hg : embedding g) :
continuous f ↔ continuous (g ∘ f) :=
by simp [continuous_iff_tendsto, @embedding.tendsto_nhds_iff α β γ _ _ f g _ _ hg]
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
lemma embedding_subtype_val : embedding (@subtype.val α p) :=
⟨assume a₁ a₂, subtype.eq, rfl⟩
lemma continuous_subtype_val : continuous (@subtype.val α p) :=
continuous_induced_dom
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 embedding_inl : embedding (@sum.inl α β) :=
⟨λ _ _, sum.inl.inj_iff.mp,
begin
unfold sum.topological_space,
apply le_antisymm,
{ intros u hu, existsi (sum.inl '' u),
change
(is_open (sum.inl ⁻¹' (@sum.inl α β '' u)) ∧
is_open (sum.inr ⁻¹' (@sum.inl α β '' u))) ∧
u = sum.inl ⁻¹' (sum.inl '' u),
have : sum.inl ⁻¹' (@sum.inl α β '' u) = u :=
preimage_image_eq u (λ _ _, sum.inl.inj_iff.mp), rw this,
have : sum.inr ⁻¹' (@sum.inl α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume a ⟨b, _, h⟩, sum.inl_ne_inr h), rw this,
exact ⟨⟨hu, is_open_empty⟩, rfl⟩ },
{ rw induced_le_iff_le_coinduced, exact lattice.inf_le_left }
end⟩
lemma embedding_inr : embedding (@sum.inr α β) :=
⟨λ _ _, sum.inr.inj_iff.mp,
begin
unfold sum.topological_space,
apply le_antisymm,
{ intros u hu, existsi (sum.inr '' u),
change
(is_open (sum.inl ⁻¹' (@sum.inr α β '' u)) ∧
is_open (sum.inr ⁻¹' (@sum.inr α β '' u))) ∧
u = sum.inr ⁻¹' (sum.inr '' u),
have : sum.inl ⁻¹' (@sum.inr α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume b ⟨a, _, h⟩, sum.inr_ne_inl h), rw this,
have : sum.inr ⁻¹' (@sum.inr α β '' u) = u :=
preimage_image_eq u (λ _ _, sum.inr.inj_iff.mp), rw this,
exact ⟨⟨is_open_empty, hu⟩, rfl⟩ },
{ rw induced_le_iff_le_coinduced, exact lattice.inf_le_right }
end⟩
lemma map_nhds_subtype_val_eq {a : α} (ha : p a) (h : {a | p a} ∈ (nhds a).sets) :
map (@subtype.val α p) (nhds ⟨a, ha⟩) = nhds a :=
map_nhds_induced_eq (by simp [subtype_val_image, h])
lemma nhds_subtype_eq_comap {a : α} {h : p a} :
nhds (⟨a, h⟩ : subtype p) = comap subtype.val (nhds a) :=
nhds_induced_eq_comap
lemma continuous_subtype_nhds_cover {ι : Sort*} {f : α → β} {c : ι → α → Prop}
(c_cover : ∀x:α, ∃i, {x | c i x} ∈ (nhds x).sets)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) :
continuous f :=
continuous_iff_tendsto.mpr $ assume x,
let ⟨i, (c_sets : {x | c i x} ∈ (nhds x).sets)⟩ := c_cover x in
let x' : subtype (c i) := ⟨x, mem_of_nhds c_sets⟩ in
calc map f (nhds x) = map f (map subtype.val (nhds x')) :
congr_arg (map f) (map_nhds_subtype_val_eq _ $ c_sets).symm
... = map (λx:subtype (c i), f x.val) (nhds x') : rfl
... ≤ nhds (f x) : continuous_iff_tendsto.mp (f_cont i) x'
lemma continuous_subtype_is_closed_cover {ι : Sort*} {f : α → β} (c : ι → α → Prop)
(h_lf : locally_finite (λi, {x | c i x}))
(h_is_closed : ∀i, is_closed {x | c i x})
(h_cover : ∀x, ∃i, c i x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x.val)) :
continuous f :=
continuous_iff_is_closed.mpr $
assume s hs,
have ∀i, is_closed (@subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
from assume i,
embedding_is_closed embedding_subtype_val
(by simp [subtype_val_range]; exact h_is_closed i)
(continuous_iff_is_closed.mp (f_cont i) _ hs),
have is_closed (⋃i, @subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
from is_closed_Union_of_locally_finite
(locally_finite_subset h_lf $ assume i x ⟨⟨x', hx'⟩, _, heq⟩, heq ▸ hx')
this,
have f ⁻¹' s = (⋃i, @subtype.val α {x | c i x} '' (f ∘ subtype.val ⁻¹' s)),
begin
apply set.ext,
have : ∀ (x : α), f x ∈ s ↔ ∃ (i : ι), c i x ∧ f x ∈ s :=
λ x, ⟨λ hx, let ⟨i, hi⟩ := h_cover x in ⟨i, hi, hx⟩,
λ ⟨i, hi, hx⟩, hx⟩,
simp [and.comm, and.left_comm], simpa [(∘)],
end,
by rwa [this]
lemma closure_subtype {p : α → Prop} {x : {a // p a}} {s : set {a // p a}}:
x ∈ closure s ↔ x.val ∈ closure (subtype.val '' s) :=
closure_induced $ assume x y, subtype.eq
end subtype
section quotient
variables [topological_space α] [topological_space β] [topological_space γ]
variables {r : α → α → Prop} {s : setoid α}
lemma quotient_map.continuous_iff {f : α → β} {g : β → γ} (hf : quotient_map f) :
continuous g ↔ continuous (g ∘ f) :=
by rw [continuous_iff_le_coinduced, continuous_iff_le_coinduced, hf.right, coinduced_compose]
lemma quotient_map_quot_mk : quotient_map (@quot.mk α r) :=
⟨quot.exists_rep, rfl⟩
lemma continuous_quot_mk : continuous (@quot.mk α r) :=
continuous_coinduced_rng
lemma continuous_quot_lift {f : α → β} (hr : ∀ a b, r a b → f a = f b)
(h : continuous f) : continuous (quot.lift f hr : quot r → β) :=
continuous_coinduced_dom h
lemma quotient_map_quotient_mk : quotient_map (@quotient.mk α s) :=
quotient_map_quot_mk
lemma continuous_quotient_mk : continuous (@quotient.mk α s) :=
continuous_coinduced_rng
lemma continuous_quotient_lift {f : α → β} (hs : ∀ a b, a ≈ b → f a = f b)
(h : continuous f) : continuous (quotient.lift f hs : quotient s → β) :=
continuous_coinduced_dom h
end quotient
section pi
variables {ι : Type*} {π : ι → Type*}
lemma continuous_pi [topological_space α] [∀i, topological_space (π i)] {f : α → Πi:ι, π i}
(h : ∀i, continuous (λa, f a i)) : continuous f :=
continuous_supr_rng $ assume i, continuous_induced_rng $ h i
lemma continuous_apply [∀i, topological_space (π i)] (i : ι) :
continuous (λp:Πi, π i, p i) :=
continuous_supr_dom continuous_induced_dom
lemma nhds_pi [t : ∀i, topological_space (π i)] {a : Πi, π i} :
nhds a = (⨅i, comap (λx, x i) (nhds (a i))) :=
calc nhds a = (⨅i, @nhds _ (@topological_space.induced _ _ (λx:Πi, π i, x i) (t i)) a) : nhds_supr
... = (⨅i, comap (λx, x i) (nhds (a i))) : by simp [nhds_induced_eq_comap]
/-- Tychonoff's theorem -/
lemma compact_pi_infinite [∀i, topological_space (π i)] {s : Πi:ι, set (π i)} :
(∀i, compact (s i)) → compact {x : Πi:ι, π i | ∀i, x i ∈ s i} :=
begin
simp [compact_iff_ultrafilter_le_nhds, nhds_pi],
exact assume h f hf hfs,
let p : Πi:ι, filter (π i) := λi, map (λx:Πi:ι, π i, x i) f in
have ∀i:ι, ∃a, a∈s i ∧ p i ≤ nhds a,
from assume i, h i (p i) (ultrafilter_map hf) $
show (λx:Πi:ι, π i, x i) ⁻¹' s i ∈ f.sets,
from mem_sets_of_superset hfs $ assume x (hx : ∀i, x i ∈ s i), hx i,
let ⟨a, ha⟩ := classical.axiom_of_choice this in
⟨a, assume i, (ha i).left, assume i, map_le_iff_le_comap.mp $ (ha i).right⟩
end
end pi
-- TODO: use embeddings from above!
structure dense_embedding [topological_space α] [topological_space β] (e : α → β) : Prop :=
(dense : ∀x, x ∈ closure (range e))
(inj : function.injective e)
(induced : ∀a, comap e (nhds (e a)) = nhds a)
theorem dense_embedding.mk'
[topological_space α] [topological_space β] (e : α → β)
(c : continuous e)
(dense : ∀x, x ∈ closure (range e))
(inj : function.injective e)
(H : ∀ (a:α) s ∈ (nhds a).sets,
∃t ∈ (nhds (e a)).sets, ∀ b, e b ∈ t → b ∈ s) :
dense_embedding e :=
⟨dense, inj, λ a, le_antisymm
(by simpa [le_def] using H a)
(tendsto_iff_comap.1 $ c.tendsto _)⟩
namespace dense_embedding
variables [topological_space α] [topological_space β]
variables {e : α → β} (de : dense_embedding e)
protected lemma embedding (de : dense_embedding e) : embedding e :=
⟨de.inj, eq_of_nhds_eq_nhds begin intro a, rw [← de.induced a, nhds_induced_eq_comap] end⟩
protected lemma tendsto (de : dense_embedding e) {a : α} : tendsto e (nhds a) (nhds (e a)) :=
by rw [←de.induced a]; exact tendsto_comap
protected lemma continuous (de : dense_embedding e) {a : α} : continuous e :=
continuous_iff_tendsto.2 $ λ a, de.tendsto
lemma inj_iff (de : dense_embedding e) {x y} : e x = e y ↔ x = y := de.inj.eq_iff
lemma closure_range : closure (range e) = univ :=
let h := de.dense in
set.ext $ assume x, ⟨assume _, trivial, assume _, @h x⟩
lemma self_sub_closure_image_preimage_of_open {s : set β} (de : dense_embedding e) :
is_open s → s ⊆ closure (e '' (e ⁻¹' s)) :=
begin
intros s_op b b_in_s,
rw [image_preimage_eq_inter_range, mem_closure_iff],
intros U U_op b_in,
rw ←inter_assoc,
have ne_e : U ∩ s ≠ ∅ := ne_empty_of_mem ⟨b_in, b_in_s⟩,
exact (dense_iff_inter_open.1 de.closure_range) _ (is_open_inter U_op s_op) ne_e
end
lemma closure_image_nhds_of_nhds {s : set α} {a : α} (de : dense_embedding e) :
s ∈ (nhds a).sets → closure (e '' s) ∈ (nhds (e a)).sets :=
begin
rw [← de.induced a, mem_comap_sets],
intro h,
rcases h with ⟨t, t_nhd, sub⟩,
rw mem_nhds_sets_iff at t_nhd,
rcases t_nhd with ⟨U, U_sub, ⟨U_op, e_a_in_U⟩⟩,
have := calc e ⁻¹' U ⊆ e⁻¹' t : preimage_mono U_sub
... ⊆ s : sub,
have := calc U ⊆ closure (e '' (e ⁻¹' U)) : self_sub_closure_image_preimage_of_open de U_op
... ⊆ closure (e '' s) : closure_mono (image_subset e this),
have U_nhd : U ∈ (nhds (e a)).sets := mem_nhds_sets U_op e_a_in_U,
exact (nhds (e a)).sets_of_superset U_nhd this
end
variables [topological_space δ] {f : γ → α} {g : γ → δ} {h : δ → β}
/--
γ -f→ α
g↓ ↓e
δ -h→ β
-/
lemma tendsto_comap_nhds_nhds {d : δ} {a : α} (de : dense_embedding e) (H : tendsto h (nhds d) (nhds (e a)))
(comm : h ∘ g = e ∘ f) : tendsto f (comap g (nhds d)) (nhds a) :=
begin
have lim1 : map g (comap g (nhds d)) ≤ nhds d := map_comap_le,
replace lim1 : map h (map g (comap g (nhds d))) ≤ map h (nhds d) := map_mono lim1,
rw [filter.map_map, comm, ← filter.map_map, map_le_iff_le_comap] at lim1,
have lim2 : comap e (map h (nhds d)) ≤ comap e (nhds (e a)) := comap_mono H,
rw de.induced at lim2,
exact le_trans lim1 lim2,
end
protected lemma nhds_inf_neq_bot (de : dense_embedding e) {b : β} : nhds b ⊓ principal (range e) ≠ ⊥ :=
begin
have h := de.dense,
simp [closure_eq_nhds] at h,
exact h _
end
lemma comap_nhds_neq_bot (de : dense_embedding e) {b : β} : comap e (nhds b) ≠ ⊥ :=
forall_sets_neq_empty_iff_neq_bot.mp $
assume s ⟨t, ht, (hs : e ⁻¹' t ⊆ s)⟩,
have t ∩ range e ∈ (nhds b ⊓ principal (range e)).sets,
from inter_mem_inf_sets ht (subset.refl _),
let ⟨_, ⟨hx₁, y, rfl⟩⟩ := inhabited_of_mem_sets de.nhds_inf_neq_bot this in
subset_ne_empty hs $ ne_empty_of_mem hx₁
variables [topological_space γ]
/-- If `e : α → β` is a dense embedding, then any function `α → γ` extends to a function `β → γ`. -/
def extend (de : dense_embedding e) (f : α → γ) (b : β) : γ :=
have nonempty γ, from
let ⟨_, ⟨_, a, _⟩⟩ := exists_mem_of_ne_empty
(mem_closure_iff.1 (de.dense b) _ is_open_univ trivial) in ⟨f a⟩,
@lim _ (classical.inhabited_of_nonempty this) _ (map f (comap e (nhds b)))
lemma extend_eq [t2_space γ] {b : β} {c : γ} {f : α → γ}
(hf : map f (comap e (nhds b)) ≤ nhds c) : de.extend f b = c :=
@lim_eq _ (id _) _ _ _ _ (by simp; exact comap_nhds_neq_bot de) hf
lemma extend_e_eq [t2_space γ] {a : α} {f : α → γ} (de : dense_embedding e)
(hf : map f (nhds a) ≤ nhds (f a)) : de.extend f (e a) = f a :=
de.extend_eq begin rw de.induced; exact hf end
lemma tendsto_extend [regular_space γ] {b : β} {f : α → γ} (de : dense_embedding e)
(hf : {b | ∃c, tendsto f (comap e $ nhds b) (nhds c)} ∈ (nhds b).sets) :
tendsto (de.extend f) (nhds b) (nhds (de.extend f b)) :=
let φ := {b | tendsto f (comap e $ nhds b) (nhds $ de.extend f b)} in
have hφ : φ ∈ (nhds b).sets,
from (nhds b).sets_of_superset hf $ assume b ⟨c, hc⟩,
show tendsto f (comap e (nhds b)) (nhds (de.extend f b)), from (de.extend_eq hc).symm ▸ hc,
assume s hs,
let ⟨s'', hs''₁, hs''₂, hs''₃⟩ := nhds_is_closed hs in
let ⟨s', hs'₁, (hs'₂ : e ⁻¹' s' ⊆ f ⁻¹' s'')⟩ := mem_of_nhds hφ hs''₁ in
let ⟨t, (ht₁ : t ⊆ φ ∩ s'), ht₂, ht₃⟩ := mem_nhds_sets_iff.mp $ inter_mem_sets hφ hs'₁ in
have h₁ : closure (f '' (e ⁻¹' s')) ⊆ s'',
by rw [closure_subset_iff_subset_of_is_closed hs''₃, image_subset_iff]; exact hs'₂,
have h₂ : t ⊆ de.extend f ⁻¹' closure (f '' (e ⁻¹' t)), from
assume b' hb',
have nhds b' ≤ principal t, by simp; exact mem_nhds_sets ht₂ hb',
have map f (comap e (nhds b')) ≤ nhds (de.extend f b') ⊓ principal (f '' (e ⁻¹' t)),
from calc _ ≤ map f (comap e (nhds b' ⊓ principal t)) : map_mono $ comap_mono $ le_inf (le_refl _) this
... ≤ map f (comap e (nhds b')) ⊓ map f (comap e (principal t)) :
le_inf (map_mono $ comap_mono $ inf_le_left) (map_mono $ comap_mono $ inf_le_right)
... ≤ map f (comap e (nhds b')) ⊓ principal (f '' (e ⁻¹' t)) : by simp [le_refl]
... ≤ _ : inf_le_inf ((ht₁ hb').left) (le_refl _),
show de.extend f b' ∈ closure (f '' (e ⁻¹' t)),
begin
rw [closure_eq_nhds],
apply neq_bot_of_le_neq_bot _ this,
simp,
exact de.comap_nhds_neq_bot
end,
(nhds b).sets_of_superset
(show t ∈ (nhds b).sets, from mem_nhds_sets ht₂ ht₃)
(calc t ⊆ de.extend f ⁻¹' closure (f '' (e ⁻¹' t)) : h₂
... ⊆ de.extend f ⁻¹' closure (f '' (e ⁻¹' s')) :
preimage_mono $ closure_mono $ image_subset f $ preimage_mono $ subset.trans ht₁ $ inter_subset_right _ _
... ⊆ de.extend f ⁻¹' s'' : preimage_mono h₁
... ⊆ de.extend f ⁻¹' s : preimage_mono hs''₂)
lemma continuous_extend [regular_space γ] {f : α → γ} (de : dense_embedding e)
(hf : ∀b, ∃c, tendsto f (comap e (nhds b)) (nhds c)) : continuous (de.extend f) :=
continuous_iff_tendsto.mpr $ assume b, de.tendsto_extend $ univ_mem_sets' hf
end dense_embedding
namespace dense_embedding
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
/-- The product of two dense embeddings is a dense embedding -/
protected def prod {e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_embedding e₁) (de₂ : dense_embedding e₂) :
dense_embedding (λ(p : α × γ), (e₁ p.1, e₂ p.2)) :=
{ dense_embedding .
dense :=
have closure (range (λ(p : α × γ), (e₁ p.1, e₂ p.2))) =
set.prod (closure (range e₁)) (closure (range e₂)),
by rw [←closure_prod_eq, prod_range_range_eq],
assume ⟨b, d⟩, begin rw [this], simp, constructor, apply de₁.dense, apply de₂.dense end,
inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩,
by simp; exact assume h₁ h₂, ⟨de₁.inj h₁, de₂.inj h₂⟩,
induced := assume ⟨a, b⟩,
by rw [nhds_prod_eq, nhds_prod_eq, ←prod_comap_comap_eq, de₁.induced, de₂.induced] }
def subtype_emb (p : α → Prop) {e : α → β} (de : dense_embedding e) (x : {x // p x}) :
{x // x ∈ closure (e '' {x | p x})} :=
⟨e x.1, subset_closure $ mem_image_of_mem e x.2⟩
protected def subtype (p : α → Prop) {e : α → β} (de : dense_embedding e) :
dense_embedding (de.subtype_emb p) :=
{ dense_embedding .
dense := assume ⟨x, hx⟩, closure_subtype.mpr $
have (λ (x : {x // p x}), e (x.val)) = e ∘ subtype.val, from rfl,
begin
rw ← image_univ,
simp [(image_comp _ _ _).symm, (∘), subtype_emb, -image_univ],
rw [this, image_comp, subtype_val_image],
simp,
assumption
end,
inj := assume ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq $ de.inj $ @@congr_arg subtype.val h,
induced := assume ⟨x, hx⟩,
by simp [subtype_emb, nhds_subtype_eq_comap, comap_comap_comp, (∘), (de.induced x).symm] }
end dense_embedding
lemma is_closed_property [topological_space α] [topological_space β] {e : α → β} {p : β → Prop}
(he : closure (range e) = univ) (hp : is_closed {x | p x}) (h : ∀a, p (e a)) :
∀b, p b :=
have univ ⊆ {b | p b},
from calc univ = closure (range e) : he.symm
... ⊆ closure {b | p b} : closure_mono $ range_subset_iff.mpr h
... = _ : closure_eq_of_is_closed hp,
assume b, this trivial
lemma is_closed_property2 [topological_space α] [topological_space β] {e : α → β} {p : β → β → Prop}
(he : dense_embedding e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂)) :
∀b₁ b₂, p b₁ b₂ :=
have ∀q:β×β, p q.1 q.2,
from is_closed_property (he.prod he).closure_range hp $ assume a, h _ _,
assume b₁ b₂, this ⟨b₁, b₂⟩
lemma is_closed_property3 [topological_space α] [topological_space β] {e : α → β} {p : β → β → β → Prop}
(he : dense_embedding e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) :
∀b₁ b₂ b₃, p b₁ b₂ b₃ :=
have ∀q:β×β×β, p q.1 q.2.1 q.2.2,
from is_closed_property (he.prod $ he.prod he).closure_range hp $ assume ⟨a₁, a₂, a₃⟩, h _ _ _,
assume b₁ b₂ b₃, this ⟨b₁, b₂, b₃⟩
lemma mem_closure_of_continuous [topological_space α] [topological_space β]
{f : α → β} {a : α} {s : set α} {t : set β}
(hf : continuous f) (ha : a ∈ closure s) (h : ∀a∈s, f a ∈ closure t) :
f a ∈ closure t :=
calc f a ∈ f '' closure s : mem_image_of_mem _ ha
... ⊆ closure (f '' s) : image_closure_subset_closure_image hf
... ⊆ closure (closure t) : closure_mono $ image_subset_iff.mpr $ h
... ⊆ closure t : begin rw [closure_eq_of_is_closed], exact subset.refl _, exact is_closed_closure end
lemma mem_closure_of_continuous2 [topological_space α] [topological_space β] [topological_space γ]
{f : α → β → γ} {a : α} {b : β} {s : set α} {t : set β} {u : set γ}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(h : ∀a∈s, ∀b∈t, f a b ∈ closure u) :
f a b ∈ closure u :=
have (a,b) ∈ closure (set.prod s t),
by simp [closure_prod_eq, ha, hb],
show f (a, b).1 (a, b).2 ∈ closure u,
from @mem_closure_of_continuous (α×β) _ _ _ (λp:α×β, f p.1 p.2) (a,b) _ u hf this $
assume ⟨p₁, p₂⟩ ⟨h₁, h₂⟩, h p₁ h₁ p₂ h₂
|
22a567ddbc6a68fe91780b924cbd3206c2707420 | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/tactic/monotonicity/default.lean | 1e2fe9f8e2072b458145931596809732b071452c | [
"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 | 73 | lean | import tactic.monotonicity.interactive
import tactic.monotonicity.lemmas
|
c736cdff0bd94a6151d46cfc0d0acae7f0b72177 | 367134ba5a65885e863bdc4507601606690974c1 | /src/group_theory/group_action/defs.lean | 1bb5eed8894f1c5d5e8889dcfedf6e03bf23adf2 | [
"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 | 9,288 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.equiv.basic
import algebra.group.defs
import algebra.group.hom
import logic.embedding
/-!
# Definitions of group actions
This file defines a hierarchy of group action type-classes:
* `has_scalar α β`
* `mul_action α β`
* `distrib_mul_action α β`
The hierarchy is extended further by `semimodule`, defined elsewhere.
Also provided are type-classes regarding the interaction of different group actions,
* `smul_comm_class M N α`
* `is_scalar_tower M N α`
## Notation
`a • b` is used as notation for `smul a b`.
## Implementation details
This file should avoid depending on other parts of `group_theory`, to avoid import cycles.
More sophisticated lemmas belong in `group_theory.group_action`.
-/
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
open function
/-- Typeclass for types with a scalar multiplication operation, denoted `•` (`\bu`) -/
class has_scalar (α : Type u) (γ : Type v) := (smul : α → γ → γ)
infixr ` • `:73 := has_scalar.smul
/-- Typeclass for multiplicative actions by monoids. This generalizes group actions. -/
@[protect_proj] class mul_action (α : Type u) (β : Type v) [monoid α] extends has_scalar α β :=
(one_smul : ∀ b : β, (1 : α) • b = b)
(mul_smul : ∀ (x y : α) (b : β), (x * y) • b = x • y • b)
/-- A typeclass mixin saying that two actions on the same space commute. -/
class smul_comm_class (M N α : Type*) [has_scalar M α] [has_scalar N α] : Prop :=
(smul_comm : ∀ (m : M) (n : N) (a : α), m • n • a = n • m • a)
export mul_action (mul_smul) smul_comm_class (smul_comm)
/--
Frequently, we find ourselves wanting to express a bilinear map `M →ₗ[R] N →ₗ[R] P` or an
equivalence between maps `(M →ₗ[R] N) ≃ₗ[R] (M' →ₗ[R] N')` where the maps have an associated ring
`R`. Unfortunately, using definitions like these requires that `R` satisfy `comm_semiring R`, and
not just `semiring R`. Using `M →ₗ[R] N →+ P` and `(M →ₗ[R] N) ≃+ (M' →ₗ[R] N')` avoids this
problem, but throws away structure that is useful for when we _do_ have a commutative (semi)ring.
To avoid making this compromise, we instead state these definitions as `M →ₗ[R] N →ₗ[S] P` or
`(M →ₗ[R] N) ≃ₗ[S] (M' →ₗ[R] N')` and require `smul_comm_class S R` on the appropriate modules. When
the caller has `comm_semiring R`, they can set `S = R` and `smul_comm_class_self` will populate the
instance. If the caller only has `semiring R` they can still set either `R = ℕ` or `S = ℕ`, and
`add_comm_monoid.nat_smul_comm_class` or `add_comm_monoid.nat_smul_comm_class'` will populate
the typeclass, which is still sufficient to recover a `≃+` or `→+` structure.
An example of where this is used is `linear_map.prod_equiv`.
-/
library_note "bundled maps over different rings"
/-- Commutativity of actions is a symmetric relation. This lemma can't be an instance because this
would cause a loop in the instance search graph. -/
lemma smul_comm_class.symm (M N α : Type*) [has_scalar M α] [has_scalar N α]
[smul_comm_class M N α] : smul_comm_class N M α :=
⟨λ a' a b, (smul_comm a a' b).symm⟩
instance smul_comm_class_self (M α : Type*) [comm_monoid M] [mul_action M α] :
smul_comm_class M M α :=
⟨λ a a' b, by rw [← mul_smul, mul_comm, mul_smul]⟩
/-- An instance of `is_scalar_tower M N α` states that the multiplicative
action of `M` on `α` is determined by the multiplicative actions of `M` on `N`
and `N` on `α`. -/
class is_scalar_tower (M N α : Type*) [has_scalar M N] [has_scalar N α] [has_scalar M α] : Prop :=
(smul_assoc : ∀ (x : M) (y : N) (z : α), (x • y) • z = x • (y • z))
@[simp] lemma smul_assoc {M N} [has_scalar M N] [has_scalar N α] [has_scalar M α]
[is_scalar_tower M N α] (x : M) (y : N) (z : α) :
(x • y) • z = x • y • z :=
is_scalar_tower.smul_assoc x y z
section
variables [monoid α] [mul_action α β]
lemma smul_smul (a₁ a₂ : α) (b : β) : a₁ • a₂ • b = (a₁ * a₂) • b := (mul_smul _ _ _).symm
variable (α)
@[simp] theorem one_smul (b : β) : (1 : α) • b = b := mul_action.one_smul _
variables {α}
/-- Pullback a multiplicative action along an injective map respecting `•`. -/
protected def function.injective.mul_action [has_scalar α γ] (f : γ → β)
(hf : injective f) (smul : ∀ (c : α) x, f (c • x) = c • f x) :
mul_action α γ :=
{ smul := (•),
one_smul := λ x, hf $ (smul _ _).trans $ one_smul _ (f x),
mul_smul := λ c₁ c₂ x, hf $ by simp only [smul, mul_smul] }
/-- Pushforward a multiplicative action along a surjective map respecting `•`. -/
protected def function.surjective.mul_action [has_scalar α γ] (f : β → γ) (hf : surjective f)
(smul : ∀ (c : α) x, f (c • x) = c • f x) :
mul_action α γ :=
{ smul := (•),
one_smul := λ y, by { rcases hf y with ⟨x, rfl⟩, rw [← smul, one_smul] },
mul_smul := λ c₁ c₂ y, by { rcases hf y with ⟨x, rfl⟩, simp only [← smul, mul_smul] } }
section ite
variables (p : Prop) [decidable p]
lemma ite_smul (a₁ a₂ : α) (b : β) : (ite p a₁ a₂) • b = ite p (a₁ • b) (a₂ • b) :=
by split_ifs; refl
lemma smul_ite (a : α) (b₁ b₂ : β) : a • (ite p b₁ b₂) = ite p (a • b₁) (a • b₂) :=
by split_ifs; refl
end ite
section
variables (α)
/-- The regular action of a monoid on itself by left multiplication.
This is promoted to a semimodule by `semiring.to_semimodule`. -/
@[priority 910] -- see Note [lower instance priority]
instance monoid.to_mul_action : mul_action α α :=
{ smul := (*),
one_smul := one_mul,
mul_smul := mul_assoc }
@[simp] lemma smul_eq_mul {a a' : α} : a • a' = a * a' := rfl
instance is_scalar_tower.left : is_scalar_tower α α β :=
⟨λ x y z, mul_smul x y z⟩
end
namespace mul_action
variables (α β)
/-- Embedding induced by action. -/
def to_fun : β ↪ (α → β) :=
⟨λ y x, x • y, λ y₁ y₂ H, one_smul α y₁ ▸ one_smul α y₂ ▸ by convert congr_fun H 1⟩
variables {α β}
@[simp] lemma to_fun_apply (x : α) (y : β) : mul_action.to_fun α β y x = x • y :=
rfl
variable (β)
/-- An action of `α` on `β` and a monoid homomorphism `γ → α` induce an action of `γ` on `β`. -/
def comp_hom [monoid γ] (g : γ →* α) :
mul_action γ β :=
{ smul := λ x b, (g x) • b,
one_smul := by simp [g.map_one, mul_action.one_smul],
mul_smul := by simp [g.map_mul, mul_action.mul_smul] }
end mul_action
end
section compatible_scalar
@[simp] lemma smul_one_smul {M} (N) [monoid N] [has_scalar M N] [mul_action N α] [has_scalar M α]
[is_scalar_tower M N α] (x : M) (y : α) :
(x • (1 : N)) • y = x • y :=
by rw [smul_assoc, one_smul]
end compatible_scalar
/-- Typeclass for multiplicative actions on additive structures. This generalizes group modules. -/
class distrib_mul_action (α : Type u) (β : Type v) [monoid α] [add_monoid β]
extends mul_action α β :=
(smul_add : ∀(r : α) (x y : β), r • (x + y) = r • x + r • y)
(smul_zero : ∀(r : α), r • (0 : β) = 0)
section
variables [monoid α] [add_monoid β] [distrib_mul_action α β]
theorem smul_add (a : α) (b₁ b₂ : β) : a • (b₁ + b₂) = a • b₁ + a • b₂ :=
distrib_mul_action.smul_add _ _ _
@[simp] theorem smul_zero (a : α) : a • (0 : β) = 0 :=
distrib_mul_action.smul_zero _
/-- Pullback a distributive multiplicative action along an injective additive monoid
homomorphism. -/
protected def function.injective.distrib_mul_action [add_monoid γ] [has_scalar α γ] (f : γ →+ β)
(hf : injective f) (smul : ∀ (c : α) x, f (c • x) = c • f x) :
distrib_mul_action α γ :=
{ smul := (•),
smul_add := λ c x y, hf $ by simp only [smul, f.map_add, smul_add],
smul_zero := λ c, hf $ by simp only [smul, f.map_zero, smul_zero],
.. hf.mul_action f smul }
/-- Pushforward a distributive multiplicative action along a surjective additive monoid
homomorphism.-/
protected def function.surjective.distrib_mul_action [add_monoid γ] [has_scalar α γ] (f : β →+ γ)
(hf : surjective f) (smul : ∀ (c : α) x, f (c • x) = c • f x) :
distrib_mul_action α γ :=
{ smul := (•),
smul_add := λ c x y, by { rcases hf x with ⟨x, rfl⟩, rcases hf y with ⟨y, rfl⟩,
simp only [smul_add, ← smul, ← f.map_add] },
smul_zero := λ c, by simp only [← f.map_zero, ← smul, smul_zero],
.. hf.mul_action f smul }
variable (β)
/-- Scalar multiplication by `r` as an `add_monoid_hom`. -/
def const_smul_hom (r : α) : β →+ β :=
{ to_fun := (•) r,
map_zero' := smul_zero r,
map_add' := smul_add r }
variable {β}
@[simp] lemma const_smul_hom_apply (r : α) (x : β) :
const_smul_hom β r x = r • x := rfl
end
section
variables [monoid α] [add_group β] [distrib_mul_action α β]
@[simp] theorem smul_neg (r : α) (x : β) : r • (-x) = -(r • x) :=
eq_neg_of_add_eq_zero $ by rw [← smul_add, neg_add_self, smul_zero]
theorem smul_sub (r : α) (x y : β) : r • (x - y) = r • x - r • y :=
by rw [sub_eq_add_neg, sub_eq_add_neg, smul_add, smul_neg]
end
|
284396a6b337ba6e34637ae0057fe554642b231e | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/multiset/finset_ops.lean | 1935e66db4a651e12b5e26694c651fcebedd2275 | [
"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,985 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.multiset.dedup
/-!
# Preparations for defining operations on `finset`.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The operations here ignore multiplicities,
and preparatory for defining the corresponding operations on `finset`.
-/
namespace multiset
open list
variables {α : Type*} [decidable_eq α] {s : multiset α}
/-! ### finset insert -/
/-- `ndinsert a s` is the lift of the list `insert` operation. This operation
does not respect multiplicities, unlike `cons`, but it is suitable as
an insert operation on `finset`. -/
def ndinsert (a : α) (s : multiset α) : multiset α :=
quot.lift_on s (λ l, (l.insert a : multiset α))
(λ s t p, quot.sound (p.insert a))
@[simp] theorem coe_ndinsert (a : α) (l : list α) : ndinsert a l = (insert a l : list α) := rfl
@[simp] theorem ndinsert_zero (a : α) : ndinsert a 0 = {a} := rfl
@[simp, priority 980]
theorem ndinsert_of_mem {a : α} {s : multiset α} : a ∈ s → ndinsert a s = s :=
quot.induction_on s $ λ l h, congr_arg coe $ insert_of_mem h
@[simp, priority 980]
theorem ndinsert_of_not_mem {a : α} {s : multiset α} : a ∉ s → ndinsert a s = a ::ₘ s :=
quot.induction_on s $ λ l h, congr_arg coe $ insert_of_not_mem h
@[simp] theorem mem_ndinsert {a b : α} {s : multiset α} : a ∈ ndinsert b s ↔ a = b ∨ a ∈ s :=
quot.induction_on s $ λ l, mem_insert_iff
@[simp] theorem le_ndinsert_self (a : α) (s : multiset α) : s ≤ ndinsert a s :=
quot.induction_on s $ λ l, (sublist_insert _ _).subperm
@[simp] theorem mem_ndinsert_self (a : α) (s : multiset α) : a ∈ ndinsert a s :=
mem_ndinsert.2 (or.inl rfl)
theorem mem_ndinsert_of_mem {a b : α} {s : multiset α} (h : a ∈ s) : a ∈ ndinsert b s :=
mem_ndinsert.2 (or.inr h)
@[simp, priority 980]
theorem length_ndinsert_of_mem {a : α} {s : multiset α} (h : a ∈ s) :
card (ndinsert a s) = card s :=
by simp [h]
@[simp, priority 980]
theorem length_ndinsert_of_not_mem {a : α} {s : multiset α} (h : a ∉ s) :
card (ndinsert a s) = card s + 1 :=
by simp [h]
theorem dedup_cons {a : α} {s : multiset α} :
dedup (a ::ₘ s) = ndinsert a (dedup s) :=
by by_cases a ∈ s; simp [h]
lemma nodup.ndinsert (a : α) : nodup s → nodup (ndinsert a s) :=
quot.induction_on s $ λ l, nodup.insert
theorem ndinsert_le {a : α} {s t : multiset α} : ndinsert a s ≤ t ↔ s ≤ t ∧ a ∈ t :=
⟨λ h, ⟨le_trans (le_ndinsert_self _ _) h, mem_of_le h (mem_ndinsert_self _ _)⟩,
λ ⟨l, m⟩, if h : a ∈ s then by simp [h, l] else
by rw [ndinsert_of_not_mem h, ← cons_erase m, cons_le_cons_iff,
← le_cons_of_not_mem h, cons_erase m]; exact l⟩
lemma attach_ndinsert (a : α) (s : multiset α) :
(s.ndinsert a).attach =
ndinsert ⟨a, mem_ndinsert_self a s⟩ (s.attach.map $ λp, ⟨p.1, mem_ndinsert_of_mem p.2⟩) :=
have eq : ∀h : ∀(p : {x // x ∈ s}), p.1 ∈ s,
(λ (p : {x // x ∈ s}), ⟨p.val, h p⟩ : {x // x ∈ s} → {x // x ∈ s}) = id, from
assume h, funext $ assume p, subtype.eq rfl,
have ∀t (eq : s.ndinsert a = t), t.attach = ndinsert ⟨a, eq ▸ mem_ndinsert_self a s⟩
(s.attach.map $ λp, ⟨p.1, eq ▸ mem_ndinsert_of_mem p.2⟩),
begin
intros t ht,
by_cases a ∈ s,
{ rw [ndinsert_of_mem h] at ht,
subst ht,
rw [eq, map_id, ndinsert_of_mem (mem_attach _ _)] },
{ rw [ndinsert_of_not_mem h] at ht,
subst ht,
simp [attach_cons, h] }
end,
this _ rfl
@[simp] theorem disjoint_ndinsert_left {a : α} {s t : multiset α} :
disjoint (ndinsert a s) t ↔ a ∉ t ∧ disjoint s t :=
iff.trans (by simp [disjoint]) disjoint_cons_left
@[simp] theorem disjoint_ndinsert_right {a : α} {s t : multiset α} :
disjoint s (ndinsert a t) ↔ a ∉ s ∧ disjoint s t :=
by rw [disjoint_comm, disjoint_ndinsert_left]; tauto
/-! ### finset union -/
/-- `ndunion s t` is the lift of the list `union` operation. This operation
does not respect multiplicities, unlike `s ∪ t`, but it is suitable as
a union operation on `finset`. (`s ∪ t` would also work as a union operation
on finset, but this is more efficient.) -/
def ndunion (s t : multiset α) : multiset α :=
quotient.lift_on₂ s t (λ l₁ l₂, (l₁.union l₂ : multiset α)) $ λ v₁ v₂ w₁ w₂ p₁ p₂,
quot.sound $ p₁.union p₂
@[simp] theorem coe_ndunion (l₁ l₂ : list α) : @ndunion α _ l₁ l₂ = (l₁ ∪ l₂ : list α) := rfl
@[simp] theorem zero_ndunion (s : multiset α) : ndunion 0 s = s :=
quot.induction_on s $ λ l, rfl
@[simp] theorem cons_ndunion (s t : multiset α) (a : α) :
ndunion (a ::ₘ s) t = ndinsert a (ndunion s t) :=
quotient.induction_on₂ s t $ λ l₁ l₂, rfl
@[simp] theorem mem_ndunion {s t : multiset α} {a : α} : a ∈ ndunion s t ↔ a ∈ s ∨ a ∈ t :=
quotient.induction_on₂ s t $ λ l₁ l₂, list.mem_union
theorem le_ndunion_right (s t : multiset α) : t ≤ ndunion s t :=
quotient.induction_on₂ s t $ λ l₁ l₂, (suffix_union_right _ _).sublist.subperm
theorem subset_ndunion_right (s t : multiset α) : t ⊆ ndunion s t :=
subset_of_le (le_ndunion_right s t)
theorem ndunion_le_add (s t : multiset α) : ndunion s t ≤ s + t :=
quotient.induction_on₂ s t $ λ l₁ l₂, (union_sublist_append _ _).subperm
theorem ndunion_le {s t u : multiset α} : ndunion s t ≤ u ↔ s ⊆ u ∧ t ≤ u :=
multiset.induction_on s (by simp)
(by simp [ndinsert_le, and_comm, and.left_comm] {contextual := tt})
theorem subset_ndunion_left (s t : multiset α) : s ⊆ ndunion s t :=
λ a h, mem_ndunion.2 $ or.inl h
theorem le_ndunion_left {s} (t : multiset α) (d : nodup s) : s ≤ ndunion s t :=
(le_iff_subset d).2 $ subset_ndunion_left _ _
theorem ndunion_le_union (s t : multiset α) : ndunion s t ≤ s ∪ t :=
ndunion_le.2 ⟨subset_of_le (le_union_left _ _), le_union_right _ _⟩
lemma nodup.ndunion (s : multiset α) {t : multiset α} : nodup t → nodup (ndunion s t) :=
quotient.induction_on₂ s t $ λ l₁ l₂, list.nodup.union _
@[simp, priority 980]
theorem ndunion_eq_union {s t : multiset α} (d : nodup s) : ndunion s t = s ∪ t :=
le_antisymm (ndunion_le_union _ _) $ union_le (le_ndunion_left _ d) (le_ndunion_right _ _)
theorem dedup_add (s t : multiset α) : dedup (s + t) = ndunion s (dedup t) :=
quotient.induction_on₂ s t $ λ l₁ l₂, congr_arg coe $ dedup_append _ _
/-! ### finset inter -/
/-- `ndinter s t` is the lift of the list `∩` operation. This operation
does not respect multiplicities, unlike `s ∩ t`, but it is suitable as
an intersection operation on `finset`. (`s ∩ t` would also work as a union operation
on finset, but this is more efficient.) -/
def ndinter (s t : multiset α) : multiset α := filter (∈ t) s
@[simp] theorem coe_ndinter (l₁ l₂ : list α) : @ndinter α _ l₁ l₂ = (l₁ ∩ l₂ : list α) := rfl
@[simp] theorem zero_ndinter (s : multiset α) : ndinter 0 s = 0 := rfl
@[simp, priority 980]
theorem cons_ndinter_of_mem {a : α} (s : multiset α) {t : multiset α} (h : a ∈ t) :
ndinter (a ::ₘ s) t = a ::ₘ (ndinter s t) := by simp [ndinter, h]
@[simp, priority 980]
theorem ndinter_cons_of_not_mem {a : α} (s : multiset α) {t : multiset α} (h : a ∉ t) :
ndinter (a ::ₘ s) t = ndinter s t := by simp [ndinter, h]
@[simp] theorem mem_ndinter {s t : multiset α} {a : α} : a ∈ ndinter s t ↔ a ∈ s ∧ a ∈ t :=
mem_filter
@[simp]
lemma nodup.ndinter {s : multiset α} (t : multiset α) : nodup s → nodup (ndinter s t) :=
nodup.filter _
theorem le_ndinter {s t u : multiset α} : s ≤ ndinter t u ↔ s ≤ t ∧ s ⊆ u :=
by simp [ndinter, le_filter, subset_iff]
theorem ndinter_le_left (s t : multiset α) : ndinter s t ≤ s :=
(le_ndinter.1 le_rfl).1
theorem ndinter_subset_left (s t : multiset α) : ndinter s t ⊆ s :=
subset_of_le (ndinter_le_left s t)
theorem ndinter_subset_right (s t : multiset α) : ndinter s t ⊆ t :=
(le_ndinter.1 le_rfl).2
theorem ndinter_le_right {s} (t : multiset α) (d : nodup s) : ndinter s t ≤ t :=
(le_iff_subset $ d.ndinter _).2 $ ndinter_subset_right _ _
theorem inter_le_ndinter (s t : multiset α) : s ∩ t ≤ ndinter s t :=
le_ndinter.2 ⟨inter_le_left _ _, subset_of_le $ inter_le_right _ _⟩
@[simp, priority 980]
theorem ndinter_eq_inter {s t : multiset α} (d : nodup s) : ndinter s t = s ∩ t :=
le_antisymm (le_inter (ndinter_le_left _ _) (ndinter_le_right _ d)) (inter_le_ndinter _ _)
theorem ndinter_eq_zero_iff_disjoint {s t : multiset α} : ndinter s t = 0 ↔ disjoint s t :=
by rw ← subset_zero; simp [subset_iff, disjoint]
end multiset
-- Assert that we define `finset` without the material on the set lattice.
-- Note that we cannot put this in `data.finset.basic` because we proved relevant lemmas there.
assert_not_exists set.sInter
|
8421ccfd80800be859e7c158a53f854ff12e3c06 | 618003631150032a5676f229d13a079ac875ff77 | /src/group_theory/group_action.lean | b1d2bcc23abdcaef75ed7be344c71209fa20259a | [
"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 | 10,329 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.set.finite
import group_theory.coset
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- Typeclass for types with a scalar multiplication operation, denoted `•` (`\bu`) -/
class has_scalar (α : Type u) (γ : Type v) := (smul : α → γ → γ)
infixr ` • `:73 := has_scalar.smul
section prio
set_option default_priority 100 -- see Note [default priority]
/-- Typeclass for multiplicative actions by monoids. This generalizes group actions. -/
class mul_action (α : Type u) (β : Type v) [monoid α] extends has_scalar α β :=
(one_smul : ∀ b : β, (1 : α) • b = b)
(mul_smul : ∀ (x y : α) (b : β), (x * y) • b = x • y • b)
end prio
section
variables [monoid α] [mul_action α β]
theorem mul_smul (a₁ a₂ : α) (b : β) : (a₁ * a₂) • b = a₁ • a₂ • b := mul_action.mul_smul _ _ _
lemma smul_smul (a₁ a₂ : α) (b : β) : a₁ • a₂ • b = (a₁ * a₂) • b := (mul_smul _ _ _).symm
lemma smul_comm {α : Type u} {β : Type v} [comm_monoid α] [mul_action α β] (a₁ a₂ : α) (b : β) :
a₁ • a₂ • b = a₂ • a₁ • b := by rw [←mul_smul, ←mul_smul, mul_comm]
variable (α)
@[simp] theorem one_smul (b : β) : (1 : α) • b = b := mul_action.one_smul _
variables {α}
@[simp] lemma units.inv_smul_smul (u : units α) (x : β) :
(↑u⁻¹:α) • (u:α) • x = x :=
by rw [smul_smul, u.inv_mul, one_smul]
@[simp] lemma units.smul_inv_smul (u : units α) (x : β) :
(u:α) • (↑u⁻¹:α) • x = x :=
by rw [smul_smul, u.mul_inv, one_smul]
section gwz
variables {G : Type*} [group_with_zero G] [mul_action G β]
lemma inv_smul_smul' {c : G} (hc : c ≠ 0) (x : β) : c⁻¹ • c • x = x :=
(units.mk0 c hc).inv_smul_smul x
lemma smul_inv_smul' {c : G} (hc : c ≠ 0) (x : β) : c • c⁻¹ • x = x :=
(units.mk0 c hc).smul_inv_smul x
end gwz
variables (p : Prop) [decidable p]
lemma ite_smul (a₁ a₂ : α) (b : β) : (ite p a₁ a₂) • b = ite p (a₁ • b) (a₂ • b) :=
by split_ifs; refl
lemma smul_ite (a : α) (b₁ b₂ : β) : a • (ite p b₁ b₂) = ite p (a • b₁) (a • b₂) :=
by split_ifs; refl
end
namespace mul_action
variables (α) [monoid α]
/-- The regular action of a monoid on itself by left multiplication. -/
def regular : mul_action α α :=
{ smul := λ a₁ a₂, a₁ * a₂,
one_smul := λ a, one_mul a,
mul_smul := λ a₁ a₂ a₃, mul_assoc _ _ _, }
variables [mul_action α β]
/-- The orbit of an element under an action. -/
def orbit (b : β) := set.range (λ x : α, x • b)
variable {α}
@[simp] lemma mem_orbit_iff {b₁ b₂ : β} : b₂ ∈ orbit α b₁ ↔ ∃ x : α, x • b₁ = b₂ :=
iff.rfl
@[simp] lemma mem_orbit (b : β) (x : α) : x • b ∈ orbit α b :=
⟨x, rfl⟩
@[simp] lemma mem_orbit_self (b : β) : b ∈ orbit α b :=
⟨1, by simp [mul_action.one_smul]⟩
instance orbit_fintype (b : β) [fintype α] [decidable_eq β] :
fintype (orbit α b) := set.fintype_range _
variable (α)
/-- The stabilizer of an element under an action, i.e. what sends the element to itself. -/
def stabilizer (b : β) : set α :=
{x : α | x • b = b}
variable {α}
@[simp] lemma mem_stabilizer_iff {b : β} {x : α} :
x ∈ stabilizer α b ↔ x • b = b := iff.rfl
variables (α) (β)
/-- The set of elements fixed under the whole action. -/
def fixed_points : set β := {b : β | ∀ x, x ∈ stabilizer α b}
variables {α} (β)
@[simp] lemma mem_fixed_points {b : β} :
b ∈ fixed_points α β ↔ ∀ x : α, x • b = b := iff.rfl
lemma mem_fixed_points' {b : β} : b ∈ fixed_points α β ↔
(∀ b', b' ∈ orbit α b → b' = b) :=
⟨λ h b h₁, let ⟨x, hx⟩ := mem_orbit_iff.1 h₁ in hx ▸ h x,
λ h b, mem_stabilizer_iff.2 (h _ (mem_orbit _ _))⟩
/-- An action of `α` on `β` and a monoid homomorphism `γ → α` induce an action of `γ` on `β`. -/
def comp_hom [monoid γ] (g : γ → α) [is_monoid_hom g] :
mul_action γ β :=
{ smul := λ x b, (g x) • b,
one_smul := by simp [is_monoid_hom.map_one g, mul_action.one_smul],
mul_smul := by simp [is_monoid_hom.map_mul g, mul_action.mul_smul] }
instance (b : β) : is_submonoid (stabilizer α b) :=
{ one_mem := one_smul b,
mul_mem := λ a a' (ha : a • b = b) (hb : a' • b = b),
by rw [mem_stabilizer_iff, ←smul_smul, hb, ha] }
end mul_action
namespace mul_action
variables [group α] [mul_action α β]
section
open mul_action quotient_group
lemma inv_smul_smul (c : α) (x : β) : c⁻¹ • c • x = x :=
(to_units α c).inv_smul_smul x
lemma smul_inv_smul (c : α) (x : β) : c • c⁻¹ • x = x :=
(to_units α c).smul_inv_smul x
variables (α) (β)
/-- Given an action of a group `α` on a set `β`, each `g : α` defines a permutation of `β`. -/
def to_perm (g : α) : equiv.perm β :=
{ to_fun := (•) g,
inv_fun := (•) g⁻¹,
left_inv := inv_smul_smul g,
right_inv := smul_inv_smul g }
variables {α} {β}
instance : is_group_hom (to_perm α β) :=
{ map_mul := λ x y, equiv.ext (λ a, mul_action.mul_smul x y a) }
lemma bijective (g : α) : function.bijective (λ b : β, g • b) :=
(to_perm α β g).bijective
lemma orbit_eq_iff {a b : β} :
orbit α a = orbit α b ↔ a ∈ orbit α b:=
⟨λ h, h ▸ mem_orbit_self _,
λ ⟨x, (hx : x • b = a)⟩, set.ext (λ c, ⟨λ ⟨y, (hy : y • a = c)⟩, ⟨y * x,
show (y * x) • b = c, by rwa [mul_action.mul_smul, hx]⟩,
λ ⟨y, (hy : y • b = c)⟩, ⟨y * x⁻¹,
show (y * x⁻¹) • a = c, by
conv {to_rhs, rw [← hy, ← mul_one y, ← inv_mul_self x, ← mul_assoc,
mul_action.mul_smul, hx]}⟩⟩)⟩
instance (b : β) : is_subgroup (stabilizer α b) :=
{ one_mem := mul_action.one_smul _,
mul_mem := λ x y (hx : x • b = b) (hy : y • b = b),
show (x * y) • b = b, by rw mul_action.mul_smul; simp *,
inv_mem := λ x (hx : x • b = b), show x⁻¹ • b = b,
by rw [← hx, ← mul_action.mul_smul, inv_mul_self, mul_action.one_smul, hx] }
variables (α) (β)
/-- The relation "in the same orbit". -/
def orbit_rel : setoid β :=
{ r := λ a b, a ∈ orbit α b,
iseqv := ⟨mem_orbit_self, λ a b, by simp [orbit_eq_iff.symm, eq_comm],
λ a b, by simp [orbit_eq_iff.symm, eq_comm] {contextual := tt}⟩ }
variables {β}
open quotient_group
/-- Orbit-stabilizer theorem. -/
noncomputable def orbit_equiv_quotient_stabilizer (b : β) :
orbit α b ≃ quotient (stabilizer α b) :=
equiv.symm (@equiv.of_bijective _ _
(λ x : quotient (stabilizer α b), quotient.lift_on' x
(λ x, (⟨x • b, mem_orbit _ _⟩ : orbit α b))
(λ g h (H : _ = _), subtype.eq $ (mul_action.bijective (g⁻¹)).1
$ show g⁻¹ • (g • b) = g⁻¹ • (h • b),
by rw [← mul_action.mul_smul, ← mul_action.mul_smul,
H, inv_mul_self, mul_action.one_smul]))
⟨λ g h, quotient.induction_on₂' g h (λ g h H, quotient.sound' $
have H : g • b = h • b := subtype.mk.inj H,
show (g⁻¹ * h) • b = b,
by rw [mul_action.mul_smul, ← H, ← mul_action.mul_smul, inv_mul_self, mul_action.one_smul]),
λ ⟨b, ⟨g, hgb⟩⟩, ⟨g, subtype.eq hgb⟩⟩)
@[simp] theorem orbit_equiv_quotient_stabilizer_symm_apply (b : β) (a : α) :
((orbit_equiv_quotient_stabilizer α b).symm a : β) = a • b :=
rfl
end
open quotient_group mul_action is_subgroup
/-- Action on left cosets. -/
def mul_left_cosets (H : set α) [is_subgroup H]
(x : α) (y : quotient H) : quotient H :=
quotient.lift_on' y (λ y, quotient_group.mk ((x : α) * y))
(λ a b (hab : _ ∈ H), quotient_group.eq.2
(by rwa [mul_inv_rev, ← mul_assoc, mul_assoc (a⁻¹), inv_mul_self, mul_one]))
instance (H : set α) [is_subgroup H] : mul_action α (quotient H) :=
{ smul := mul_left_cosets H,
one_smul := λ a, quotient.induction_on' a (λ a, quotient_group.eq.2
(by simp [is_submonoid.one_mem])),
mul_smul := λ x y a, quotient.induction_on' a (λ a, quotient_group.eq.2
(by simp [mul_inv_rev, is_submonoid.one_mem, mul_assoc])) }
instance mul_left_cosets_comp_subtype_val (H I : set α) [is_subgroup H] [is_subgroup I] :
mul_action I (quotient H) :=
mul_action.comp_hom (quotient H) (subtype.val : I → α)
end mul_action
section prio
set_option default_priority 100 -- see Note [default priority]
/-- Typeclass for multiplicative actions on additive structures. This generalizes group modules. -/
class distrib_mul_action (α : Type u) (β : Type v) [monoid α] [add_monoid β] extends mul_action α β :=
(smul_add : ∀(r : α) (x y : β), r • (x + y) = r • x + r • y)
(smul_zero : ∀(r : α), r • (0 : β) = 0)
end prio
section
variables [monoid α] [add_monoid β] [distrib_mul_action α β]
theorem smul_add (a : α) (b₁ b₂ : β) : a • (b₁ + b₂) = a • b₁ + a • b₂ :=
distrib_mul_action.smul_add _ _ _
@[simp] theorem smul_zero (a : α) : a • (0 : β) = 0 :=
distrib_mul_action.smul_zero _
theorem units.smul_eq_zero (u : units α) {x : β} : (u : α) • x = 0 ↔ x = 0 :=
⟨λ h, by rw [← u.inv_smul_smul x, h, smul_zero], λ h, h.symm ▸ smul_zero _⟩
theorem units.smul_ne_zero (u : units α) {x : β} : (u : α) • x ≠ 0 ↔ x ≠ 0 :=
not_congr u.smul_eq_zero
@[simp] theorem is_unit.smul_eq_zero {u : α} (hu : is_unit u) {x : β} :
u • x = 0 ↔ x = 0 :=
exists.elim hu $ λ u hu, hu ▸ u.smul_eq_zero
variable (β)
/-- Scalar multiplication by `r` as an `add_monoid_hom`. -/
def const_smul_hom (r : α) : β →+ β :=
{ to_fun := (•) r,
map_zero' := smul_zero r,
map_add' := smul_add r }
variable {β}
@[simp] lemma const_smul_hom_apply (r : α) (x : β) :
const_smul_hom β r x = r • x := rfl
lemma list.smul_sum {r : α} {l : list β} :
r • l.sum = (l.map ((•) r)).sum :=
(const_smul_hom β r).map_list_sum l
end
section
variables [monoid α] [add_comm_monoid β] [distrib_mul_action α β]
lemma multiset.smul_sum {r : α} {s : multiset β} :
r • s.sum = (s.map ((•) r)).sum :=
(const_smul_hom β r).map_multiset_sum s
lemma finset.smul_sum {r : α} {f : γ → β} {s : finset γ} :
r • s.sum f = s.sum (λ x, r • f x) :=
(const_smul_hom β r).map_sum f s
end
|
6467f2fec69a681fab9123de68cbe6a76535658b | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/full.lean | 880dbc5ee72ccb438aef0ec0e30deeda37480ef4 | [
"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 | 103 | lean | namespace foo
constant x : num
check x
check x
set_option pp.full_names true
check x
end foo
|
f85cb69227f63a6561b1f338b401633da2d03137 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/algebra/equicontinuity.lean | 8b68b827aa406f4504095a632042638a2af48906 | [
"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 | 1,828 | lean | /-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import topology.algebra.uniform_convergence
/-!
# Algebra-related equicontinuity criterions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
open function
open_locale uniform_convergence
@[to_additive] lemma equicontinuous_of_equicontinuous_at_one {ι G M hom : Type*}
[topological_space G] [uniform_space M] [group G] [group M] [topological_group G]
[uniform_group M] [monoid_hom_class hom G M] (F : ι → hom)
(hf : equicontinuous_at (coe_fn ∘ F) (1 : G)) :
equicontinuous (coe_fn ∘ F) :=
begin
letI : has_coe_to_fun hom (λ _, G → M) := fun_like.has_coe_to_fun,
rw equicontinuous_iff_continuous,
rw equicontinuous_at_iff_continuous_at at hf,
let φ : G →* (ι → M) :=
{ to_fun := swap (coe_fn ∘ F),
map_one' := by ext; exact map_one _,
map_mul' := λ a b, by ext; exact map_mul _ _ _ },
exact continuous_of_continuous_at_one φ hf
end
@[to_additive] lemma uniform_equicontinuous_of_equicontinuous_at_one {ι G M hom : Type*}
[uniform_space G] [uniform_space M] [group G] [group M] [uniform_group G] [uniform_group M]
[monoid_hom_class hom G M] (F : ι → hom) (hf : equicontinuous_at (coe_fn ∘ F) (1 : G)) :
uniform_equicontinuous (coe_fn ∘ F) :=
begin
letI : has_coe_to_fun hom (λ _, G → M) := fun_like.has_coe_to_fun,
rw uniform_equicontinuous_iff_uniform_continuous,
rw equicontinuous_at_iff_continuous_at at hf,
let φ : G →* (ι → M) :=
{ to_fun := swap (coe_fn ∘ F),
map_one' := by ext; exact map_one _,
map_mul' := λ a b, by ext; exact map_mul _ _ _ },
exact uniform_continuous_of_continuous_at_one φ hf
end
|
7e39f3ae13cbd794e62d7e8e7cfa28c8b35ec5be | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/linear_algebra/matrix/finite_dimensional.lean | c1b75404d66b93a88993ed85932839abf2c835d7 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 1,377 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import linear_algebra.finite_dimensional
/-!
# The finite-dimensional space of matrices
This file shows that `m` by `n` matrices form a finite-dimensional space,
and proves the `finrank` of that space is equal to `card m * card n`.
## Main definitions
* `matrix.finite_dimensional`: matrices form a finite dimensional vector space over a field `K`
* `matrix.finrank_matrix`: the `finrank` of `matrix m n R` is `card m * card n`
## Tags
matrix, finite dimensional, findim, finrank
-/
universes u v
namespace matrix
section finite_dimensional
variables {m n : Type*} [fintype m] [fintype n]
variables {R : Type v} [field R]
instance : finite_dimensional R (matrix m n R) :=
linear_equiv.finite_dimensional (linear_equiv.curry R m n)
/--
The dimension of the space of finite dimensional matrices
is the product of the number of rows and columns.
-/
@[simp] lemma finrank_matrix :
finite_dimensional.finrank R (matrix m n R) = fintype.card m * fintype.card n :=
by rw [@linear_equiv.finrank_eq R (matrix m n R) _ _ _ _ _ _ (linear_equiv.curry R m n).symm,
finite_dimensional.finrank_fintype_fun_eq_card, fintype.card_prod]
end finite_dimensional
end matrix
|
b4e187caf331452c646123da1c9dc0f58ba1e69c | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/category_theory/abelian/projective.lean | 8eab95f8307b1aab22fa76d17015b3a4e8d2e244 | [
"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 | 2,648 | lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Scott Morrison
-/
import category_theory.abelian.exact
import category_theory.preadditive.projective_resolution
/-!
# Abelian categories with enough projectives have projective resolutions
When `C` is abelian `projective.d f` and `f` are exact.
Hence, starting from an epimorphism `P ⟶ X`, where `P` is projective,
we can apply `projective.d` repeatedly to obtain a projective resolution of `X`.
-/
noncomputable theory
open category_theory
open category_theory.limits
universes v u
namespace category_theory
open category_theory.projective
variables {C : Type u} [category.{v} C]
section
variables [enough_projectives C] [abelian C]
/--
When `C` is abelian, `projective.d f` and `f` are exact.
-/
lemma exact_d_f {X Y : C} (f : X ⟶ Y) : exact (d f) f :=
(abelian.exact_iff _ _).2 $
⟨by simp, zero_of_epi_comp (π _) $ by rw [←category.assoc, cokernel.condition]⟩
end
namespace ProjectiveResolution
/-!
Our goal is to define `ProjectiveResolution.of Z : ProjectiveResolution Z`.
The `0`-th object in this resolution will just be `projective.over Z`,
i.e. an arbitrarily chosen projective object with a map to `Z`.
After that, we build the `n+1`-st object as `projective.syzygies`
applied to the previously constructed morphism,
and the map to the `n`-th object as `projective.d`.
-/
variables [abelian C] [enough_projectives C]
/-- Auxiliary definition for `ProjectiveResolution.of`. -/
@[simps]
def of_complex (Z : C) : chain_complex C ℕ :=
chain_complex.mk'
(projective.over Z) (projective.syzygies (projective.π Z)) (projective.d (projective.π Z))
(λ ⟨X, Y, f⟩, ⟨projective.syzygies f, projective.d f, (exact_d_f f).w⟩)
/--
In any abelian category with enough projectives,
`ProjectiveResolution.of Z` constructs a projection resolution of the object `Z`.
-/
@[irreducible] def of (Z : C) : ProjectiveResolution Z :=
{ complex := of_complex Z,
π := chain_complex.mk_hom _ _ (projective.π Z) 0
(by { simp, exact (exact_d_f (projective.π Z)).w.symm, })
(λ n _, ⟨0, by ext⟩),
projective := by { rintros (_|_|_|n); apply projective.projective_over, },
exact₀ := by simpa using exact_d_f (projective.π Z),
exact := by { rintros (_|n); { simp, apply exact_d_f, }, },
epi := projective.π_epi Z, }
@[priority 100]
instance (Z : C) : has_projective_resolution Z :=
{ out := ⟨of Z⟩ }
@[priority 100]
instance : has_projective_resolutions C :=
{ out := λ Z, by apply_instance }
end ProjectiveResolution
end category_theory
|
6189ba98f1339036d13ff6eb163162d1eb4f98b6 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/subobject/factor_thru.lean | f63a488d8aa5fc9b6af5809ca6ef2094230311e6 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 6,909 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Scott Morrison
-/
import category_theory.subobject.basic
/-!
# Factoring through subobjects
The predicate `h : P.factors f`, for `P : subobject Y` and `f : X ⟶ Y`
asserts the existence of some `P.factor_thru f : X ⟶ (P : C)` making the obvious diagram commute.
-/
universes v₁ v₂ u₁ u₂
noncomputable theory
open category_theory category_theory.category category_theory.limits
variables {C : Type u₁} [category.{v₁} C] {X Y Z : C}
variables {D : Type u₂} [category.{v₂} D]
namespace category_theory
namespace mono_over
/-- When `f : X ⟶ Y` and `P : mono_over Y`,
`P.factors f` expresses that there exists a factorisation of `f` through `P`.
Given `h : P.factors f`, you can recover the morphism as `P.factor_thru f h`.
-/
def factors {X Y : C} (P : mono_over Y) (f : X ⟶ Y) : Prop := ∃ g : X ⟶ P.val.left, g ≫ P.arrow = f
lemma factors_congr {X : C} {f g : mono_over X} {Y : C} (h : Y ⟶ X) (e : f ≅ g) :
f.factors h ↔ g.factors h :=
⟨λ ⟨u, hu⟩, ⟨u ≫ (((mono_over.forget _).map e.hom)).left, by simp [hu]⟩,
λ ⟨u, hu⟩, ⟨u ≫ (((mono_over.forget _).map e.inv)).left, by simp [hu]⟩⟩
/-- `P.factor_thru f h` provides a factorisation of `f : X ⟶ Y` through some `P : mono_over Y`,
given the evidence `h : P.factors f` that such a factorisation exists. -/
def factor_thru {X Y : C} (P : mono_over Y) (f : X ⟶ Y) (h : factors P f) : X ⟶ P.val.left :=
classical.some h
end mono_over
namespace subobject
/-- When `f : X ⟶ Y` and `P : subobject Y`,
`P.factors f` expresses that there exists a factorisation of `f` through `P`.
Given `h : P.factors f`, you can recover the morphism as `P.factor_thru f h`.
-/
def factors {X Y : C} (P : subobject Y) (f : X ⟶ Y) : Prop :=
quotient.lift_on' P (λ P, P.factors f)
begin
rintros P Q ⟨h⟩,
apply propext,
split,
{ rintro ⟨i, w⟩,
exact ⟨i ≫ h.hom.left, by erw [category.assoc, over.w h.hom, w]⟩, },
{ rintro ⟨i, w⟩,
exact ⟨i ≫ h.inv.left, by erw [category.assoc, over.w h.inv, w]⟩, },
end
@[simp] lemma mk_factors_iff {X Y Z : C} (f : Y ⟶ X) [mono f] (g : Z ⟶ X) :
(subobject.mk f).factors g ↔ (mono_over.mk' f).factors g :=
iff.rfl
lemma factors_iff {X Y : C} (P : subobject Y) (f : X ⟶ Y) :
P.factors f ↔ (representative.obj P).factors f :=
quot.induction_on P $ λ a, mono_over.factors_congr _ (representative_iso _).symm
lemma factors_self {X : C} (P : subobject X) : P.factors P.arrow :=
(factors_iff _ _).mpr ⟨𝟙 P, (by simp)⟩
lemma factors_comp_arrow {X Y : C} {P : subobject Y} (f : X ⟶ P) : P.factors (f ≫ P.arrow) :=
(factors_iff _ _).mpr ⟨f, rfl⟩
lemma factors_of_factors_right {X Y Z : C} {P : subobject Z} (f : X ⟶ Y) {g : Y ⟶ Z}
(h : P.factors g) : P.factors (f ≫ g) :=
begin
revert P,
refine quotient.ind' _,
intro P,
rintro ⟨g, rfl⟩,
exact ⟨f ≫ g, by simp⟩,
end
lemma factors_zero [has_zero_morphisms C] {X Y : C} {P : subobject Y} :
P.factors (0 : X ⟶ Y) :=
(factors_iff _ _).mpr ⟨0, by simp⟩
lemma factors_of_le {Y Z : C} {P Q : subobject Y} (f : Z ⟶ Y) (h : P ≤ Q) :
P.factors f → Q.factors f :=
by { simp only [factors_iff], exact λ ⟨u, hu⟩, ⟨u ≫ of_le _ _ h, by simp [←hu]⟩ }
/-- `P.factor_thru f h` provides a factorisation of `f : X ⟶ Y` through some `P : subobject Y`,
given the evidence `h : P.factors f` that such a factorisation exists. -/
def factor_thru {X Y : C} (P : subobject Y) (f : X ⟶ Y) (h : factors P f) : X ⟶ P :=
classical.some ((factors_iff _ _).mp h)
@[simp, reassoc] lemma factor_thru_arrow {X Y : C} (P : subobject Y) (f : X ⟶ Y) (h : factors P f) :
P.factor_thru f h ≫ P.arrow = f :=
classical.some_spec ((factors_iff _ _).mp h)
@[simp] lemma factor_thru_self {X : C} (P : subobject X) (h) :
P.factor_thru P.arrow h = 𝟙 P :=
by { ext, simp, }
@[simp] lemma factor_thru_comp_arrow {X Y : C} {P : subobject Y} (f : X ⟶ P) (h) :
P.factor_thru (f ≫ P.arrow) h = f :=
by { ext, simp, }
@[simp] lemma factor_thru_eq_zero [has_zero_morphisms C]
{X Y : C} {P : subobject Y} {f : X ⟶ Y} {h : factors P f} :
P.factor_thru f h = 0 ↔ f = 0 :=
begin
fsplit,
{ intro w,
replace w := w =≫ P.arrow,
simpa using w, },
{ rintro rfl,
ext, simp, },
end
lemma factor_thru_right {X Y Z : C} {P : subobject Z} (f : X ⟶ Y) (g : Y ⟶ Z) (h : P.factors g) :
f ≫ P.factor_thru g h = P.factor_thru (f ≫ g) (factors_of_factors_right f h) :=
begin
apply (cancel_mono P.arrow).mp,
simp,
end
@[simp]
lemma factor_thru_zero
[has_zero_morphisms C] {X Y : C} {P : subobject Y} (h : P.factors (0 : X ⟶ Y)) :
P.factor_thru 0 h = 0 :=
by simp
-- `h` is an explicit argument here so we can use
-- `rw factor_thru_le h`, obtaining a subgoal `P.factors f`.
-- (While the reverse direction looks plausible as a simp lemma, it seems to be unproductive.)
lemma factor_thru_of_le
{Y Z : C} {P Q : subobject Y} {f : Z ⟶ Y} (h : P ≤ Q) (w : P.factors f) :
Q.factor_thru f (factors_of_le f h w) = P.factor_thru f w ≫ of_le P Q h :=
by { ext, simp, }
section preadditive
variables [preadditive C]
lemma factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (wf : P.factors f) (wg : P.factors g) :
P.factors (f + g) :=
(factors_iff _ _).mpr ⟨P.factor_thru f wf + P.factor_thru g wg, by simp⟩
-- This can't be a `simp` lemma as `wf` and `wg` may not exist.
-- However you can `rw` by it to assert that `f` and `g` factor through `P` separately.
lemma factor_thru_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wf : P.factors f) (wg : P.factors g) :
P.factor_thru (f + g) w = P.factor_thru f wf + P.factor_thru g wg :=
by { ext, simp, }
lemma factors_left_of_factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wg : P.factors g) : P.factors f :=
(factors_iff _ _).mpr ⟨P.factor_thru (f + g) w - P.factor_thru g wg, by simp⟩
@[simp]
lemma factor_thru_add_sub_factor_thru_right {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wg : P.factors g) :
P.factor_thru (f + g) w - P.factor_thru g wg =
P.factor_thru f (factors_left_of_factors_add f g w wg) :=
by { ext, simp, }
lemma factors_right_of_factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wf : P.factors f) : P.factors g :=
(factors_iff _ _).mpr ⟨P.factor_thru (f + g) w - P.factor_thru f wf, by simp⟩
@[simp]
lemma factor_thru_add_sub_factor_thru_left {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wf : P.factors f) :
P.factor_thru (f + g) w - P.factor_thru f wf =
P.factor_thru g (factors_right_of_factors_add f g w wf) :=
by { ext, simp, }
end preadditive
end subobject
end category_theory
|
4bb552f4b1a5cb6d8a6489dc1a5e746715b3c7c7 | ad3e8f15221a986da27c99f371922c0b3f5792b6 | /src/week-02/e02-functions.lean | 25ce42397aecb9fba384aad97fae56e33eaf4e6a | [] | no_license | VArtem/lean-itmo | a0e1424c8cc4c2de2ac85ab6fd4a12d80e9b85f1 | dc44cd06f9f5b984d051831b3aaa7364e64c2dc4 | refs/heads/main | 1,683,761,214,467 | 1,622,821,295,000 | 1,622,821,295,000 | 357,236,048 | 12 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,937 | lean | import tactic
-- Упражнения в этом файле сосредоточены на свойствах функций: инъекции, сюръекции и биекции.
-- По большей части заимствовано из курса Formalising Mathematics:
-- https://github.com/ImperialCollegeLondon/formalising-mathematics/blob/master/src/week_1/Part_C_functions.lean
-- https://github.com/ImperialCollegeLondon/formalising-mathematics/blob/master/src/week_4/Part_A_sets.lean
open function
-- Определим namespace, чтобы не пересекаться по названиям со стандартной библиотекой
namespace itmo.lean
-- Определим типы `X, Y, Z`, функции `f : X → Y`, `g : Y → Z` и вспомогательные элементы `(x : X) (y : Y) (z : Z)`
variables {X Y Z : Type} {f : X → Y} {g : Y → Z} (x : X) (y : Y) (z : Z)
-- Функция `f` является инъекцией, если из `f a = f b` следует, что `a = b` (то есть, для разных входов она выдает разные результаты)
lemma injective_def : injective f ↔ ∀ a b : X, f a = f b → a = b :=
begin
-- верно по определению
refl,
end
-- Тождественная функция id : X → X определена, как `id x = x`:
lemma id_def : id x = x :=
begin
refl
end
/-- Тождественная функция инъективна -/
lemma injective_id : injective (id : X → X) :=
begin
sorry,
end
-- Композиция функций `g ∘ f` (∘ = \o или \circ) определена, как `(g ∘ f) x = g (f x)`
lemma comp_def : (g ∘ f) x = g (f x) :=
begin
-- верно по определению
refl,
end
/-- Композиция инъекций является инъекцией -/
lemma injective_comp (hf : injective f) (hg : injective g) : injective (g ∘ f) :=
begin
sorry,
end
-- Функция `f : X → Y` называется сюръекцией, если для любого `y : Y` существует `x : X`, что `f x = y`
lemma surjective_def : surjective f ↔ ∀ y : Y, ∃ x : X, f x = y :=
begin
-- верно по определению
refl
end
/-- Тождественная функция - сюръекция -/
lemma surjective_id : surjective (id : X → X) :=
begin
sorry,
end
-- Композиция сюръекций является сюръекцией
lemma surjective_comp (hf : surjective f) (hg : surjective g) : surjective (g ∘ f) :=
begin
sorry,
end
-- Функция `f` называется биекцией, если она является инъекцией и сюръекцией
lemma bijective_def : bijective f ↔ injective f ∧ surjective f :=
begin
-- верно по определению
refl
end
-- Используйте доказанные ранее утверждения, чтобы доказать, что тождественная функция - биекция
lemma bijective_id : bijective (id : X → X) :=
begin
sorry,
end
-- Композиция биекций является биекцией
lemma bijective_comp (hf : bijective f) (hg : bijective g) : bijective (g ∘ f) :=
begin
sorry,
end
variables (S : set X) (T : set Y)
-- Образ множества `S : set X` под действием функции `f : X → Y` обозначается как `(f '' S) : set Y`
-- `y ∈ f '' S` по определению равно `∃ x : X, x ∈ S ∧ f x = y`
-- В стандартной библиотеке это называется `set.image : (X → Y) → set X → set Y`
#check set.image
example : set.image f S = f '' S := rfl
lemma mem_image : y ∈ f '' S = ∃ x : X, x ∈ S ∧ f x = y :=
begin
refl,
end
-- Образ тождественной функции
lemma image_id : id '' S = S :=
begin
ext x,
split,
{ rintro ⟨x₁, x₁S, hx₁⟩,
rw [← hx₁, id],
exact x₁S, },
{ intro xS,
use x,
rw id,
use xS,
-- оставшая цель закрыта с помощью `refl` после `use`
}
end
-- `simp` справится с такой целью, потому что в стандартной библиотеке есть функция `set.image_id'`, помеченная атрибутом `@[simp]`, что включает ее в список используемых `simp` лемм
example : id '' S = S :=
begin
ext, simp,
end
-- Это хорошее место, чтобы опробовать `rintro ⟨...⟩` и `refine ⟨...⟩`
-- Тактика `refine` очень похожа на `exact` и `apply`, но к тому же позволяет писать `_` в некоторых местах, генерируя цели для пропущенных аргументов
-- Например, пусть у нас есть состояние
-- x : X
-- xS : x ∈ S
-- h: (g ∘ f) x = z
-- ⊢ z ∈ g '' (f '' S)
-- После применения `refine ⟨f x, _, h⟩`, цель меняется на
-- ⊢ f x ∈ f '' S
-- Если подчеркиваний нет, и все корректно, `refine` закроет цель
lemma image_comp (S : set X) : (g ∘ f) '' S = g '' (f '' S) :=
begin
sorry,
end
-- Если `f` - инъекция, то функция `λ S, f '' S` (то есть функция, которая переводит множество `S` в `f '' S`) - тоже
-- Тактика `dsimp` (`definitional simp`) действует так же, как `simp`, но использует только равенства, верные по определению
-- С помощью `dsimp` можно упростить "очевидные" выражения, такие, как применения λ-функций:
-- `h : (λ (S : set X), f '' S) S = (λ (S : set X), f '' S) T`
-- `dsimp at h`
-- `h : f '' S = f '' T`
-- Аналогично `simp`, `dsimp only [h₁, h₂, h₃]` будет применять только леммы `h₁`, `h₂` и `h₃`, а `dsimp only at h` не будет применять дополнительных лемм (но, например, раскроет применения лямбд и подобные вещи)
-- Для себя я нашел полезным доказать лемму `image_subset_of_subset: ∀ S T, f '' S ⊆ f '' T → S ⊆ T`
lemma image_injective : injective f → injective (λ S, f '' S) :=
begin
sorry,
end
-- Прообраз функции `f : X → Y` обозначается `f ⁻¹' : set Y → set X
-- По определению: `x ∈ f ⁻¹' T ↔ f x ∈ T`
lemma mem_preimage : x ∈ f ⁻¹' T ↔ f x ∈ T :=
begin
refl,
end
lemma comp_preimage (T : set Z) : (g ∘ f) ⁻¹' T = f ⁻¹' (g ⁻¹' T) :=
begin
sorry,
end
lemma preimage_injective (hf : surjective f) : injective (λ T, f ⁻¹' T) :=
begin
sorry,
end
lemma image_surjective (hf : surjective f) : surjective (λ S, f '' S) :=
begin
sorry,
end
lemma preimage_surjective (hf : injective f) : surjective (λ S, f ⁻¹' S) :=
begin
sorry,
end
variables (ι : Type)
-- Образ объединения множеств `G i` под функцией `f`, равен объединению образов множеств `G i`
-- Используйте `set.mem_Union` для переписывания
lemma image_Union (G : ι → set X) : f '' (⋃ (i : ι), G i) = ⋃ (i : ι), f '' (G i) :=
begin
sorry,
end
-- Прообраз объединения множеств равен объединению прообразов
-- Используйте `set.mem_bUnion_iff` для переписывания
lemma preimage_bUnion (F : ι → set Y) (Z : set ι) :
f ⁻¹' (⋃ (i ∈ Z), F i) = ⋃ (i ∈ Z), f ⁻¹' (F i) :=
begin
sorry,
end
end itmo.lean |
dcfeea6cf8c38c603a15b0ada82deef3b3ae313a | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/order/ring/lemmas.lean | cff9f4f845790dacce045e10dd14da7189331d92 | [
"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 | 38,131 | lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Yuyang Zhao
-/
import algebra.covariant_and_contravariant
import algebra.group_with_zero.defs
/-!
# Multiplication by ·positive· elements is monotonic
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Let `α` be a type with `<` and `0`. We use the type `{x : α // 0 < x}` of positive elements of `α`
to prove results about monotonicity of multiplication. We also introduce the local notation `α>0`
for the subtype `{x : α // 0 < x}`:
If the type `α` also has a multiplication, then we combine this with (`contravariant_`)
`covariant_class`es to assume that multiplication by positive elements is (strictly) monotone on a
`mul_zero_class`, `monoid_with_zero`,...
More specifically, we use extensively the following typeclasses:
* monotone left
* * `covariant_class α>0 α (λ x y, x * y) (≤)`, abbreviated `pos_mul_mono α`,
expressing that multiplication by positive elements on the left is monotone;
* * `covariant_class α>0 α (λ x y, x * y) (<)`, abbreviated `pos_mul_strict_mono α`,
expressing that multiplication by positive elements on the left is strictly monotone;
* monotone right
* * `covariant_class α>0 α (λ x y, y * x) (≤)`, abbreviated `mul_pos_mono α`,
expressing that multiplication by positive elements on the right is monotone;
* * `covariant_class α>0 α (λ x y, y * x) (<)`, abbreviated `mul_pos_strict_mono α`,
expressing that multiplication by positive elements on the right is strictly monotone.
* reverse monotone left
* * `contravariant_class α>0 α (λ x y, x * y) (≤)`, abbreviated `pos_mul_mono_rev α`,
expressing that multiplication by positive elements on the left is reverse monotone;
* * `contravariant_class α>0 α (λ x y, x * y) (<)`, abbreviated `pos_mul_reflect_lt α`,
expressing that multiplication by positive elements on the left is strictly reverse monotone;
* reverse reverse monotone right
* * `contravariant_class α>0 α (λ x y, y * x) (≤)`, abbreviated `mul_pos_mono_rev α`,
expressing that multiplication by positive elements on the right is reverse monotone;
* * `contravariant_class α>0 α (λ x y, y * x) (<)`, abbreviated `mul_pos_reflect_lt α`,
expressing that multiplication by positive elements on the right is strictly reverse monotone.
## Notation
The following is local notation in this file:
* `α≥0`: `{x : α // 0 ≤ x}`
* `α>0`: `{x : α // 0 < x}`
-/
variable (α : Type*)
/- Notations for nonnegative and positive elements
https://
leanprover.zulipchat.com/#narrow/stream/113488-general/topic/notation.20for.20positive.20elements
-/
local notation `α≥0` := {x : α // 0 ≤ x}
local notation `α>0` := {x : α // 0 < x}
section abbreviations
variables [has_mul α] [has_zero α] [preorder α]
/-- `pos_mul_mono α` is an abbreviation for `covariant_class α≥0 α (λ x y, x * y) (≤)`,
expressing that multiplication by nonnegative elements on the left is monotone. -/
abbreviation pos_mul_mono : Prop := covariant_class α≥0 α (λ x y, x * y) (≤)
/-- `mul_pos_mono α` is an abbreviation for `covariant_class α≥0 α (λ x y, y * x) (≤)`,
expressing that multiplication by nonnegative elements on the right is monotone. -/
abbreviation mul_pos_mono : Prop := covariant_class α≥0 α (λ x y, y * x) (≤)
/-- `pos_mul_strict_mono α` is an abbreviation for `covariant_class α>0 α (λ x y, x * y) (<)`,
expressing that multiplication by positive elements on the left is strictly monotone. -/
abbreviation pos_mul_strict_mono : Prop := covariant_class α>0 α (λ x y, x * y) (<)
/-- `mul_pos_strict_mono α` is an abbreviation for `covariant_class α>0 α (λ x y, y * x) (<)`,
expressing that multiplication by positive elements on the right is strictly monotone. -/
abbreviation mul_pos_strict_mono : Prop := covariant_class α>0 α (λ x y, y * x) (<)
/-- `pos_mul_reflect_lt α` is an abbreviation for `contravariant_class α≥0 α (λ x y, x * y) (<)`,
expressing that multiplication by nonnegative elements on the left is strictly reverse monotone. -/
abbreviation pos_mul_reflect_lt : Prop := contravariant_class α≥0 α (λ x y, x * y) (<)
/-- `mul_pos_reflect_lt α` is an abbreviation for `contravariant_class α≥0 α (λ x y, y * x) (<)`,
expressing that multiplication by nonnegative elements on the right is strictly reverse monotone. -/
abbreviation mul_pos_reflect_lt : Prop := contravariant_class α≥0 α (λ x y, y * x) (<)
/-- `pos_mul_mono_rev α` is an abbreviation for `contravariant_class α>0 α (λ x y, x * y) (≤)`,
expressing that multiplication by positive elements on the left is reverse monotone. -/
abbreviation pos_mul_mono_rev : Prop := contravariant_class α>0 α (λ x y, x * y) (≤)
/-- `mul_pos_mono_rev α` is an abbreviation for `contravariant_class α>0 α (λ x y, y * x) (≤)`,
expressing that multiplication by positive elements on the right is reverse monotone. -/
abbreviation mul_pos_mono_rev : Prop := contravariant_class α>0 α (λ x y, y * x) (≤)
end abbreviations
variables {α} {a b c d : α}
section has_mul_zero
variables [has_mul α] [has_zero α]
section preorder
variables [preorder α]
instance pos_mul_mono.to_covariant_class_pos_mul_le [pos_mul_mono α] :
covariant_class α>0 α (λ x y, x * y) (≤) :=
⟨λ a b c bc, @covariant_class.elim α≥0 α (λ x y, x * y) (≤) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance mul_pos_mono.to_covariant_class_pos_mul_le [mul_pos_mono α] :
covariant_class α>0 α (λ x y, y * x) (≤) :=
⟨λ a b c bc, @covariant_class.elim α≥0 α (λ x y, y * x) (≤) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance pos_mul_reflect_lt.to_contravariant_class_pos_mul_lt [pos_mul_reflect_lt α] :
contravariant_class α>0 α (λ x y, x * y) (<) :=
⟨λ a b c bc, @contravariant_class.elim α≥0 α (λ x y, x * y) (<) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance mul_pos_reflect_lt.to_contravariant_class_pos_mul_lt [mul_pos_reflect_lt α] :
contravariant_class α>0 α (λ x y, y * x) (<) :=
⟨λ a b c bc, @contravariant_class.elim α≥0 α (λ x y, y * x) (<) _ ⟨_, a.2.le⟩ _ _ bc⟩
lemma mul_le_mul_of_nonneg_left [pos_mul_mono α] (h : b ≤ c) (a0 : 0 ≤ a) : a * b ≤ a * c :=
@covariant_class.elim α≥0 α (λ x y, x * y) (≤) _ ⟨a, a0⟩ _ _ h
lemma mul_le_mul_of_nonneg_right [mul_pos_mono α] (h : b ≤ c) (a0 : 0 ≤ a) : b * a ≤ c * a :=
@covariant_class.elim α≥0 α (λ x y, y * x) (≤) _ ⟨a, a0⟩ _ _ h
lemma mul_lt_mul_of_pos_left [pos_mul_strict_mono α] (bc : b < c) (a0 : 0 < a) : a * b < a * c :=
@covariant_class.elim α>0 α (λ x y, x * y) (<) _ ⟨a, a0⟩ _ _ bc
lemma mul_lt_mul_of_pos_right [mul_pos_strict_mono α] (bc : b < c) (a0 : 0 < a) : b * a < c * a :=
@covariant_class.elim α>0 α (λ x y, y * x) (<) _ ⟨a, a0⟩ _ _ bc
lemma lt_of_mul_lt_mul_left [pos_mul_reflect_lt α] (h : a * b < a * c) (a0 : 0 ≤ a) : b < c :=
@contravariant_class.elim α≥0 α (λ x y, x * y) (<) _ ⟨a, a0⟩ _ _ h
lemma lt_of_mul_lt_mul_right [mul_pos_reflect_lt α] (h : b * a < c * a) (a0 : 0 ≤ a) : b < c :=
@contravariant_class.elim α≥0 α (λ x y, y * x) (<) _ ⟨a, a0⟩ _ _ h
lemma le_of_mul_le_mul_left [pos_mul_mono_rev α] (bc : a * b ≤ a * c) (a0 : 0 < a) : b ≤ c :=
@contravariant_class.elim α>0 α (λ x y, x * y) (≤) _ ⟨a, a0⟩ _ _ bc
lemma le_of_mul_le_mul_right [mul_pos_mono_rev α] (bc : b * a ≤ c * a) (a0 : 0 < a) : b ≤ c :=
@contravariant_class.elim α>0 α (λ x y, y * x) (≤) _ ⟨a, a0⟩ _ _ bc
alias lt_of_mul_lt_mul_left ← lt_of_mul_lt_mul_of_nonneg_left
alias lt_of_mul_lt_mul_right ← lt_of_mul_lt_mul_of_nonneg_right
alias le_of_mul_le_mul_left ← le_of_mul_le_mul_of_pos_left
alias le_of_mul_le_mul_right ← le_of_mul_le_mul_of_pos_right
@[simp] lemma mul_lt_mul_left [pos_mul_strict_mono α] [pos_mul_reflect_lt α]
(a0 : 0 < a) :
a * b < a * c ↔ b < c :=
@rel_iff_cov α>0 α (λ x y, x * y) (<) _ _ ⟨a, a0⟩ _ _
@[simp] lemma mul_lt_mul_right [mul_pos_strict_mono α] [mul_pos_reflect_lt α]
(a0 : 0 < a) :
b * a < c * a ↔ b < c :=
@rel_iff_cov α>0 α (λ x y, y * x) (<) _ _ ⟨a, a0⟩ _ _
@[simp] lemma mul_le_mul_left [pos_mul_mono α] [pos_mul_mono_rev α]
(a0 : 0 < a) :
a * b ≤ a * c ↔ b ≤ c :=
@rel_iff_cov α>0 α (λ x y, x * y) (≤) _ _ ⟨a, a0⟩ _ _
@[simp] lemma mul_le_mul_right [mul_pos_mono α] [mul_pos_mono_rev α]
(a0 : 0 < a) :
b * a ≤ c * a ↔ b ≤ c :=
@rel_iff_cov α>0 α (λ x y, y * x) (≤) _ _ ⟨a, a0⟩ _ _
lemma mul_lt_mul_of_pos_of_nonneg [pos_mul_strict_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c < d) (a0 : 0 < a) (d0 : 0 ≤ d) : a * c < b * d :=
(mul_lt_mul_of_pos_left h₂ a0).trans_le (mul_le_mul_of_nonneg_right h₁ d0)
lemma mul_lt_mul_of_le_of_le' [pos_mul_strict_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c < d) (b0 : 0 < b) (c0 : 0 ≤ c) : a * c < b * d :=
(mul_le_mul_of_nonneg_right h₁ c0).trans_lt (mul_lt_mul_of_pos_left h₂ b0)
lemma mul_lt_mul_of_nonneg_of_pos [pos_mul_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c ≤ d) (a0 : 0 ≤ a) (d0 : 0 < d) : a * c < b * d :=
(mul_le_mul_of_nonneg_left h₂ a0).trans_lt (mul_lt_mul_of_pos_right h₁ d0)
lemma mul_lt_mul_of_le_of_lt' [pos_mul_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c ≤ d) (b0 : 0 ≤ b) (c0 : 0 < c) : a * c < b * d :=
(mul_lt_mul_of_pos_right h₁ c0).trans_le (mul_le_mul_of_nonneg_left h₂ b0)
lemma mul_lt_mul_of_pos_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c < d) (a0 : 0 < a) (d0 : 0 < d) : a * c < b * d :=
(mul_lt_mul_of_pos_left h₂ a0).trans (mul_lt_mul_of_pos_right h₁ d0)
lemma mul_lt_mul_of_lt_of_lt' [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c < d) (b0 : 0 < b) (c0 : 0 < c) : a * c < b * d :=
(mul_lt_mul_of_pos_right h₁ c0).trans (mul_lt_mul_of_pos_left h₂ b0)
lemma mul_lt_of_mul_lt_of_nonneg_left [pos_mul_mono α] (h : a * b < c) (hdb : d ≤ b) (ha : 0 ≤ a) :
a * d < c :=
(mul_le_mul_of_nonneg_left hdb ha).trans_lt h
lemma lt_mul_of_lt_mul_of_nonneg_left [pos_mul_mono α] (h : a < b * c) (hcd : c ≤ d) (hb : 0 ≤ b) :
a < b * d :=
h.trans_le $ mul_le_mul_of_nonneg_left hcd hb
lemma mul_lt_of_mul_lt_of_nonneg_right [mul_pos_mono α] (h : a * b < c) (hda : d ≤ a) (hb : 0 ≤ b) :
d * b < c :=
(mul_le_mul_of_nonneg_right hda hb).trans_lt h
lemma lt_mul_of_lt_mul_of_nonneg_right [mul_pos_mono α] (h : a < b * c) (hbd : b ≤ d) (hc : 0 ≤ c) :
a < d * c :=
h.trans_le $ mul_le_mul_of_nonneg_right hbd hc
end preorder
section linear_order
variables [linear_order α]
@[priority 100] -- see Note [lower instance priority]
instance pos_mul_strict_mono.to_pos_mul_mono_rev [pos_mul_strict_mono α] : pos_mul_mono_rev α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ mul_lt_mul_of_pos_left h' x.prop⟩
@[priority 100] -- see Note [lower instance priority]
instance mul_pos_strict_mono.to_mul_pos_mono_rev [mul_pos_strict_mono α] : mul_pos_mono_rev α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ mul_lt_mul_of_pos_right h' x.prop⟩
lemma pos_mul_mono_rev.to_pos_mul_strict_mono [pos_mul_mono_rev α] : pos_mul_strict_mono α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ le_of_mul_le_mul_of_pos_left h' x.prop⟩
lemma mul_pos_mono_rev.to_mul_pos_strict_mono [mul_pos_mono_rev α] : mul_pos_strict_mono α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ le_of_mul_le_mul_of_pos_right h' x.prop⟩
lemma pos_mul_strict_mono_iff_pos_mul_mono_rev : pos_mul_strict_mono α ↔ pos_mul_mono_rev α :=
⟨@pos_mul_strict_mono.to_pos_mul_mono_rev _ _ _ _, @pos_mul_mono_rev.to_pos_mul_strict_mono _ _ _ _⟩
lemma mul_pos_strict_mono_iff_mul_pos_mono_rev : mul_pos_strict_mono α ↔ mul_pos_mono_rev α :=
⟨@mul_pos_strict_mono.to_mul_pos_mono_rev _ _ _ _, @mul_pos_mono_rev.to_mul_pos_strict_mono _ _ _ _⟩
lemma pos_mul_reflect_lt.to_pos_mul_mono [pos_mul_reflect_lt α] : pos_mul_mono α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ lt_of_mul_lt_mul_left h' x.prop⟩
lemma mul_pos_reflect_lt.to_mul_pos_mono [mul_pos_reflect_lt α] : mul_pos_mono α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ lt_of_mul_lt_mul_right h' x.prop⟩
lemma pos_mul_mono.to_pos_mul_reflect_lt [pos_mul_mono α] : pos_mul_reflect_lt α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ mul_le_mul_of_nonneg_left h' x.prop⟩
lemma mul_pos_mono.to_mul_pos_reflect_lt [mul_pos_mono α] : mul_pos_reflect_lt α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ mul_le_mul_of_nonneg_right h' x.prop⟩
lemma pos_mul_mono_iff_pos_mul_reflect_lt : pos_mul_mono α ↔ pos_mul_reflect_lt α :=
⟨@pos_mul_mono.to_pos_mul_reflect_lt _ _ _ _, @pos_mul_reflect_lt.to_pos_mul_mono _ _ _ _⟩
lemma mul_pos_mono_iff_mul_pos_reflect_lt : mul_pos_mono α ↔ mul_pos_reflect_lt α :=
⟨@mul_pos_mono.to_mul_pos_reflect_lt _ _ _ _, @mul_pos_reflect_lt.to_mul_pos_mono _ _ _ _⟩
end linear_order
end has_mul_zero
section mul_zero_class
variables [mul_zero_class α]
section preorder
variables [preorder α]
/-- Assumes left covariance. -/
lemma left.mul_pos [pos_mul_strict_mono α] (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
by simpa only [mul_zero] using mul_lt_mul_of_pos_left hb ha
alias left.mul_pos ← mul_pos
lemma mul_neg_of_pos_of_neg [pos_mul_strict_mono α] (ha : 0 < a) (hb : b < 0) : a * b < 0 :=
by simpa only [mul_zero] using mul_lt_mul_of_pos_left hb ha
@[simp] lemma zero_lt_mul_left [pos_mul_strict_mono α] [pos_mul_reflect_lt α] (h : 0 < c) :
0 < c * b ↔ 0 < b :=
by { convert mul_lt_mul_left h, simp }
/-- Assumes right covariance. -/
lemma right.mul_pos [mul_pos_strict_mono α] (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
by simpa only [zero_mul] using mul_lt_mul_of_pos_right ha hb
lemma mul_neg_of_neg_of_pos [mul_pos_strict_mono α] (ha : a < 0) (hb : 0 < b) : a * b < 0 :=
by simpa only [zero_mul] using mul_lt_mul_of_pos_right ha hb
@[simp] lemma zero_lt_mul_right [mul_pos_strict_mono α] [mul_pos_reflect_lt α] (h : 0 < c) :
0 < b * c ↔ 0 < b :=
by { convert mul_lt_mul_right h, simp }
/-- Assumes left covariance. -/
lemma left.mul_nonneg [pos_mul_mono α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
by simpa only [mul_zero] using mul_le_mul_of_nonneg_left hb ha
alias left.mul_nonneg ← mul_nonneg
lemma mul_nonpos_of_nonneg_of_nonpos [pos_mul_mono α] (ha : 0 ≤ a) (hb : b ≤ 0) : a * b ≤ 0 :=
by simpa only [mul_zero] using mul_le_mul_of_nonneg_left hb ha
/-- Assumes right covariance. -/
lemma right.mul_nonneg [mul_pos_mono α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
by simpa only [zero_mul] using mul_le_mul_of_nonneg_right ha hb
lemma mul_nonpos_of_nonpos_of_nonneg [mul_pos_mono α] (ha : a ≤ 0) (hb : 0 ≤ b) : a * b ≤ 0 :=
by simpa only [zero_mul] using mul_le_mul_of_nonneg_right ha hb
lemma pos_of_mul_pos_right [pos_mul_reflect_lt α] (h : 0 < a * b) (ha : 0 ≤ a) : 0 < b :=
lt_of_mul_lt_mul_left ((mul_zero a).symm ▸ h : a * 0 < a * b) ha
lemma pos_of_mul_pos_left [mul_pos_reflect_lt α] (h : 0 < a * b) (hb : 0 ≤ b) : 0 < a :=
lt_of_mul_lt_mul_right ((zero_mul b).symm ▸ h : 0 * b < a * b) hb
lemma pos_iff_pos_of_mul_pos [pos_mul_reflect_lt α] [mul_pos_reflect_lt α] (hab : 0 < a * b) :
0 < a ↔ 0 < b :=
⟨pos_of_mul_pos_right hab ∘ le_of_lt, pos_of_mul_pos_left hab ∘ le_of_lt⟩
lemma mul_le_mul_of_le_of_le [pos_mul_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c ≤ d) (a0 : 0 ≤ a) (d0 : 0 ≤ d) : a * c ≤ b * d :=
(mul_le_mul_of_nonneg_left h₂ a0).trans $ mul_le_mul_of_nonneg_right h₁ d0
lemma mul_le_mul [pos_mul_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c ≤ d) (c0 : 0 ≤ c) (b0 : 0 ≤ b) : a * c ≤ b * d :=
(mul_le_mul_of_nonneg_right h₁ c0).trans $ mul_le_mul_of_nonneg_left h₂ b0
lemma mul_self_le_mul_self [pos_mul_mono α] [mul_pos_mono α] (ha : 0 ≤ a) (hab : a ≤ b) :
a * a ≤ b * b :=
mul_le_mul hab hab ha $ ha.trans hab
lemma mul_le_of_mul_le_of_nonneg_left [pos_mul_mono α] (h : a * b ≤ c) (hle : d ≤ b) (a0 : 0 ≤ a) :
a * d ≤ c :=
(mul_le_mul_of_nonneg_left hle a0).trans h
lemma le_mul_of_le_mul_of_nonneg_left [pos_mul_mono α] (h : a ≤ b * c) (hle : c ≤ d) (b0 : 0 ≤ b) :
a ≤ b * d :=
h.trans (mul_le_mul_of_nonneg_left hle b0)
lemma mul_le_of_mul_le_of_nonneg_right [mul_pos_mono α] (h : a * b ≤ c) (hle : d ≤ a) (b0 : 0 ≤ b) :
d * b ≤ c :=
(mul_le_mul_of_nonneg_right hle b0).trans h
lemma le_mul_of_le_mul_of_nonneg_right [mul_pos_mono α] (h : a ≤ b * c) (hle : b ≤ d) (c0 : 0 ≤ c) :
a ≤ d * c :=
h.trans (mul_le_mul_of_nonneg_right hle c0)
end preorder
section partial_order
variables [partial_order α]
lemma pos_mul_mono_iff_covariant_pos : pos_mul_mono α ↔ covariant_class α>0 α (λ x y, x * y) (≤) :=
⟨@pos_mul_mono.to_covariant_class_pos_mul_le _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simp only [ha, zero_mul] },
{ exactI @covariant_class.elim α>0 α (λ x y, x * y) (≤) _ ⟨_, ha⟩ _ _ h }
end⟩⟩
lemma mul_pos_mono_iff_covariant_pos : mul_pos_mono α ↔ covariant_class α>0 α (λ x y, y * x) (≤) :=
⟨@mul_pos_mono.to_covariant_class_pos_mul_le _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simp only [ha, mul_zero] },
{ exactI @covariant_class.elim α>0 α (λ x y, y * x) (≤) _ ⟨_, ha⟩ _ _ h }
end⟩⟩
lemma pos_mul_reflect_lt_iff_contravariant_pos :
pos_mul_reflect_lt α ↔ contravariant_class α>0 α (λ x y, x * y) (<) :=
⟨@pos_mul_reflect_lt.to_contravariant_class_pos_mul_lt _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simpa [ha] using h },
{ exactI (@contravariant_class.elim α>0 α (λ x y, x * y) (<) _ ⟨_, ha⟩ _ _ h) }
end⟩⟩
lemma mul_pos_reflect_lt_iff_contravariant_pos :
mul_pos_reflect_lt α ↔ contravariant_class α>0 α (λ x y, y * x) (<) :=
⟨@mul_pos_reflect_lt.to_contravariant_class_pos_mul_lt _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simpa [ha] using h },
{ exactI (@contravariant_class.elim α>0 α (λ x y, y * x) (<) _ ⟨_, ha⟩ _ _ h) }
end⟩⟩
@[priority 100] -- see Note [lower instance priority]
instance pos_mul_strict_mono.to_pos_mul_mono [pos_mul_strict_mono α] : pos_mul_mono α :=
pos_mul_mono_iff_covariant_pos.2 $ ⟨λ a, strict_mono.monotone $ @covariant_class.elim _ _ _ _ _ _⟩
@[priority 100] -- see Note [lower instance priority]
instance mul_pos_strict_mono.to_mul_pos_mono [mul_pos_strict_mono α] : mul_pos_mono α :=
mul_pos_mono_iff_covariant_pos.2 $ ⟨λ a, strict_mono.monotone $ @covariant_class.elim _ _ _ _ _ _⟩
@[priority 100] -- see Note [lower instance priority]
instance pos_mul_mono_rev.to_pos_mul_reflect_lt [pos_mul_mono_rev α] : pos_mul_reflect_lt α :=
pos_mul_reflect_lt_iff_contravariant_pos.2
⟨λ a b c h, (le_of_mul_le_mul_of_pos_left h.le a.2).lt_of_ne $ by { rintro rfl, simpa using h }⟩
@[priority 100] -- see Note [lower instance priority]
instance mul_pos_mono_rev.to_mul_pos_reflect_lt [mul_pos_mono_rev α] : mul_pos_reflect_lt α :=
mul_pos_reflect_lt_iff_contravariant_pos.2
⟨λ a b c h, (le_of_mul_le_mul_of_pos_right h.le a.2).lt_of_ne $ by { rintro rfl, simpa using h }⟩
lemma mul_left_cancel_iff_of_pos [pos_mul_mono_rev α] (a0 : 0 < a) : a * b = a * c ↔ b = c :=
⟨λ h, (le_of_mul_le_mul_of_pos_left h.le a0).antisymm $ le_of_mul_le_mul_of_pos_left h.ge a0,
congr_arg _⟩
lemma mul_right_cancel_iff_of_pos [mul_pos_mono_rev α] (b0 : 0 < b) : a * b = c * b ↔ a = c :=
⟨λ h, (le_of_mul_le_mul_of_pos_right h.le b0).antisymm $ le_of_mul_le_mul_of_pos_right h.ge b0,
congr_arg _⟩
lemma mul_eq_mul_iff_eq_and_eq_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
[pos_mul_mono_rev α] [mul_pos_mono_rev α]
(hac : a ≤ b) (hbd : c ≤ d) (a0 : 0 < a) (d0 : 0 < d) :
a * c = b * d ↔ a = b ∧ c = d :=
begin
refine ⟨λ h, _, λ h, congr_arg2 (*) h.1 h.2⟩,
rcases hac.eq_or_lt with rfl | hac,
{ exact ⟨rfl, (mul_left_cancel_iff_of_pos a0).mp h⟩ },
rcases eq_or_lt_of_le hbd with rfl | hbd,
{ exact ⟨(mul_right_cancel_iff_of_pos d0).mp h, rfl⟩ },
exact ((mul_lt_mul_of_pos_of_pos hac hbd a0 d0).ne h).elim,
end
lemma mul_eq_mul_iff_eq_and_eq_of_pos' [pos_mul_strict_mono α] [mul_pos_strict_mono α]
[pos_mul_mono_rev α] [mul_pos_mono_rev α]
(hac : a ≤ b) (hbd : c ≤ d) (b0 : 0 < b) (c0 : 0 < c) :
a * c = b * d ↔ a = b ∧ c = d :=
begin
refine ⟨λ h, _, λ h, congr_arg2 (*) h.1 h.2⟩,
rcases hac.eq_or_lt with rfl | hac,
{ exact ⟨rfl, (mul_left_cancel_iff_of_pos b0).mp h⟩ },
rcases eq_or_lt_of_le hbd with rfl | hbd,
{ exact ⟨(mul_right_cancel_iff_of_pos c0).mp h, rfl⟩ },
exact ((mul_lt_mul_of_lt_of_lt' hac hbd b0 c0).ne h).elim,
end
end partial_order
section linear_order
variables [linear_order α]
lemma pos_and_pos_or_neg_and_neg_of_mul_pos [pos_mul_mono α] [mul_pos_mono α]
(hab : 0 < a * b) :
(0 < a ∧ 0 < b) ∨ (a < 0 ∧ b < 0) :=
begin
rcases lt_trichotomy 0 a with ha | rfl | ha,
{ refine or.inl ⟨ha, lt_imp_lt_of_le_imp_le (λ hb, _) hab⟩,
exact mul_nonpos_of_nonneg_of_nonpos ha.le hb },
{ rw [zero_mul] at hab, exact hab.false.elim },
{ refine or.inr ⟨ha, lt_imp_lt_of_le_imp_le (λ hb, _) hab⟩,
exact mul_nonpos_of_nonpos_of_nonneg ha.le hb }
end
lemma neg_of_mul_pos_right [pos_mul_mono α] [mul_pos_mono α]
(h : 0 < a * b) (ha : a ≤ 0) :
b < 0 :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left $ λ h, h.1.not_le ha).2
lemma neg_of_mul_pos_left [pos_mul_mono α] [mul_pos_mono α]
(h : 0 < a * b) (ha : b ≤ 0) :
a < 0 :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left $ λ h, h.2.not_le ha).1
lemma neg_iff_neg_of_mul_pos [pos_mul_mono α] [mul_pos_mono α]
(hab : 0 < a * b) :
a < 0 ↔ b < 0 :=
⟨neg_of_mul_pos_right hab ∘ le_of_lt, neg_of_mul_pos_left hab ∘ le_of_lt⟩
lemma left.neg_of_mul_neg_left [pos_mul_mono α]
(h : a * b < 0) (h1 : 0 ≤ a) :
b < 0 :=
lt_of_not_ge (assume h2 : b ≥ 0, (left.mul_nonneg h1 h2).not_lt h)
lemma right.neg_of_mul_neg_left [mul_pos_mono α]
(h : a * b < 0) (h1 : 0 ≤ a) :
b < 0 :=
lt_of_not_ge (assume h2 : b ≥ 0, (right.mul_nonneg h1 h2).not_lt h)
lemma left.neg_of_mul_neg_right [pos_mul_mono α]
(h : a * b < 0) (h1 : 0 ≤ b) : a < 0 :=
lt_of_not_ge (assume h2 : a ≥ 0, (left.mul_nonneg h2 h1).not_lt h)
lemma right.neg_of_mul_neg_right [mul_pos_mono α]
(h : a * b < 0) (h1 : 0 ≤ b) : a < 0 :=
lt_of_not_ge (assume h2 : a ≥ 0, (right.mul_nonneg h2 h1).not_lt h)
end linear_order
end mul_zero_class
section mul_one_class
variables [mul_one_class α] [has_zero α]
section preorder
variables [preorder α]
/-! Lemmas of the form `a ≤ a * b ↔ 1 ≤ b` and `a * b ≤ a ↔ b ≤ 1`,
which assume left covariance. -/
@[simp]
lemma le_mul_iff_one_le_right
[pos_mul_mono α] [pos_mul_mono_rev α]
(a0 : 0 < a) :
a ≤ a * b ↔ 1 ≤ b :=
iff.trans (by rw [mul_one]) (mul_le_mul_left a0)
@[simp]
lemma lt_mul_iff_one_lt_right
[pos_mul_strict_mono α] [pos_mul_reflect_lt α]
(a0 : 0 < a) :
a < a * b ↔ 1 < b :=
iff.trans (by rw [mul_one]) (mul_lt_mul_left a0)
@[simp]
lemma mul_le_iff_le_one_right
[pos_mul_mono α] [pos_mul_mono_rev α]
(a0 : 0 < a) :
a * b ≤ a ↔ b ≤ 1 :=
iff.trans (by rw [mul_one]) (mul_le_mul_left a0)
@[simp]
lemma mul_lt_iff_lt_one_right
[pos_mul_strict_mono α] [pos_mul_reflect_lt α]
(a0 : 0 < a) :
a * b < a ↔ b < 1 :=
iff.trans (by rw [mul_one]) (mul_lt_mul_left a0)
/-! Lemmas of the form `a ≤ b * a ↔ 1 ≤ b` and `a * b ≤ b ↔ a ≤ 1`,
which assume right covariance. -/
@[simp]
lemma le_mul_iff_one_le_left
[mul_pos_mono α] [mul_pos_mono_rev α]
(a0 : 0 < a) :
a ≤ b * a ↔ 1 ≤ b :=
iff.trans (by rw [one_mul]) (mul_le_mul_right a0)
@[simp]
lemma lt_mul_iff_one_lt_left
[mul_pos_strict_mono α] [mul_pos_reflect_lt α]
(a0 : 0 < a) :
a < b * a ↔ 1 < b :=
iff.trans (by rw [one_mul]) (mul_lt_mul_right a0)
@[simp]
lemma mul_le_iff_le_one_left
[mul_pos_mono α] [mul_pos_mono_rev α]
(b0 : 0 < b) :
a * b ≤ b ↔ a ≤ 1 :=
iff.trans (by rw [one_mul]) (mul_le_mul_right b0)
@[simp]
lemma mul_lt_iff_lt_one_left
[mul_pos_strict_mono α] [mul_pos_reflect_lt α]
(b0 : 0 < b) :
a * b < b ↔ a < 1 :=
iff.trans (by rw [one_mul]) (mul_lt_mul_right b0)
/-! Lemmas of the form `1 ≤ b → a ≤ a * b`.
Variants with `< 0` and `≤ 0` instead of `0 <` and `0 ≤` appear in `algebra/order/ring/defs` (which
imports this file) as they need additional results which are not yet available here. -/
lemma mul_le_of_le_one_left [mul_pos_mono α] (hb : 0 ≤ b) (h : a ≤ 1) : a * b ≤ b :=
by simpa only [one_mul] using mul_le_mul_of_nonneg_right h hb
lemma le_mul_of_one_le_left [mul_pos_mono α] (hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ a * b :=
by simpa only [one_mul] using mul_le_mul_of_nonneg_right h hb
lemma mul_le_of_le_one_right [pos_mul_mono α] (ha : 0 ≤ a) (h : b ≤ 1) : a * b ≤ a :=
by simpa only [mul_one] using mul_le_mul_of_nonneg_left h ha
lemma le_mul_of_one_le_right [pos_mul_mono α] (ha : 0 ≤ a) (h : 1 ≤ b) : a ≤ a * b :=
by simpa only [mul_one] using mul_le_mul_of_nonneg_left h ha
lemma mul_lt_of_lt_one_left [mul_pos_strict_mono α] (hb : 0 < b) (h : a < 1) : a * b < b :=
by simpa only [one_mul] using mul_lt_mul_of_pos_right h hb
lemma lt_mul_of_one_lt_left [mul_pos_strict_mono α] (hb : 0 < b) (h : 1 < a) : b < a * b :=
by simpa only [one_mul] using mul_lt_mul_of_pos_right h hb
lemma mul_lt_of_lt_one_right [pos_mul_strict_mono α] (ha : 0 < a) (h : b < 1) : a * b < a :=
by simpa only [mul_one] using mul_lt_mul_of_pos_left h ha
lemma lt_mul_of_one_lt_right [pos_mul_strict_mono α] (ha : 0 < a) (h : 1 < b) : a < a * b :=
by simpa only [mul_one] using mul_lt_mul_of_pos_left h ha
/-! Lemmas of the form `b ≤ c → a ≤ 1 → b * a ≤ c`. -/
/- Yaël: What's the point of these lemmas? They just chain an existing lemma with an assumption in
all possible ways, thereby artificially inflating the API and making the truly relevant lemmas hard
to find -/
lemma mul_le_of_le_of_le_one_of_nonneg [pos_mul_mono α] (h : b ≤ c) (ha : a ≤ 1) (hb : 0 ≤ b) :
b * a ≤ c :=
(mul_le_of_le_one_right hb ha).trans h
lemma mul_lt_of_le_of_lt_one_of_pos [pos_mul_strict_mono α] (bc : b ≤ c) (ha : a < 1) (b0 : 0 < b) :
b * a < c :=
(mul_lt_of_lt_one_right b0 ha).trans_le bc
lemma mul_lt_of_lt_of_le_one_of_nonneg [pos_mul_mono α] (h : b < c) (ha : a ≤ 1) (hb : 0 ≤ b) :
b * a < c :=
(mul_le_of_le_one_right hb ha).trans_lt h
/-- Assumes left covariance. -/
lemma left.mul_le_one_of_le_of_le [pos_mul_mono α] (ha : a ≤ 1) (hb : b ≤ 1) (a0 : 0 ≤ a) :
a * b ≤ 1 :=
mul_le_of_le_of_le_one_of_nonneg ha hb a0
/-- Assumes left covariance. -/
lemma left.mul_lt_of_le_of_lt_one_of_pos [pos_mul_strict_mono α]
(ha : a ≤ 1) (hb : b < 1) (a0 : 0 < a) : a * b < 1 :=
mul_lt_of_le_of_lt_one_of_pos ha hb a0
/-- Assumes left covariance. -/
lemma left.mul_lt_of_lt_of_le_one_of_nonneg [pos_mul_mono α]
(ha : a < 1) (hb : b ≤ 1) (a0 : 0 ≤ a) : a * b < 1 :=
mul_lt_of_lt_of_le_one_of_nonneg ha hb a0
lemma mul_le_of_le_of_le_one' [pos_mul_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : a ≤ 1) (a0 : 0 ≤ a) (c0 : 0 ≤ c) : b * a ≤ c :=
(mul_le_mul_of_nonneg_right bc a0).trans $ mul_le_of_le_one_right c0 ha
lemma mul_lt_of_lt_of_le_one' [pos_mul_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : a ≤ 1) (a0 : 0 < a) (c0 : 0 ≤ c) : b * a < c :=
(mul_lt_mul_of_pos_right bc a0).trans_le $ mul_le_of_le_one_right c0 ha
lemma mul_lt_of_le_of_lt_one' [pos_mul_strict_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : a < 1) (a0 : 0 ≤ a) (c0 : 0 < c) : b * a < c :=
(mul_le_mul_of_nonneg_right bc a0).trans_lt $ mul_lt_of_lt_one_right c0 ha
lemma mul_lt_of_lt_of_lt_one_of_pos [pos_mul_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : a ≤ 1) (a0 : 0 < a) (c0 : 0 ≤ c) : b * a < c :=
(mul_lt_mul_of_pos_right bc a0).trans_le $ mul_le_of_le_one_right c0 ha
/-! Lemmas of the form `b ≤ c → 1 ≤ a → b ≤ c * a`. -/
lemma le_mul_of_le_of_one_le_of_nonneg [pos_mul_mono α] (h : b ≤ c) (ha : 1 ≤ a) (hc : 0 ≤ c) :
b ≤ c * a :=
h.trans $ le_mul_of_one_le_right hc ha
lemma lt_mul_of_le_of_one_lt_of_pos [pos_mul_strict_mono α] (bc : b ≤ c) (ha : 1 < a) (c0 : 0 < c) :
b < c * a :=
bc.trans_lt $ lt_mul_of_one_lt_right c0 ha
lemma lt_mul_of_lt_of_one_le_of_nonneg [pos_mul_mono α] (h : b < c) (ha : 1 ≤ a) (hc : 0 ≤ c) :
b < c * a :=
h.trans_le $ le_mul_of_one_le_right hc ha
/-- Assumes left covariance. -/
lemma left.one_le_mul_of_le_of_le [pos_mul_mono α] (ha : 1 ≤ a) (hb : 1 ≤ b) (a0 : 0 ≤ a) :
1 ≤ a * b :=
le_mul_of_le_of_one_le_of_nonneg ha hb a0
/-- Assumes left covariance. -/
lemma left.one_lt_mul_of_le_of_lt_of_pos [pos_mul_strict_mono α]
(ha : 1 ≤ a) (hb : 1 < b) (a0 : 0 < a) : 1 < a * b :=
lt_mul_of_le_of_one_lt_of_pos ha hb a0
/-- Assumes left covariance. -/
lemma left.lt_mul_of_lt_of_one_le_of_nonneg [pos_mul_mono α]
(ha : 1 < a) (hb : 1 ≤ b) (a0 : 0 ≤ a) : 1 < a * b :=
lt_mul_of_lt_of_one_le_of_nonneg ha hb a0
lemma le_mul_of_le_of_one_le' [pos_mul_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : 1 ≤ a) (a0 : 0 ≤ a) (b0 : 0 ≤ b) : b ≤ c * a :=
(le_mul_of_one_le_right b0 ha).trans $ mul_le_mul_of_nonneg_right bc a0
lemma lt_mul_of_le_of_one_lt' [pos_mul_strict_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : 1 < a) (a0 : 0 ≤ a) (b0 : 0 < b) : b < c * a :=
(lt_mul_of_one_lt_right b0 ha).trans_le $ mul_le_mul_of_nonneg_right bc a0
lemma lt_mul_of_lt_of_one_le' [pos_mul_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : 1 ≤ a) (a0 : 0 < a) (b0 : 0 ≤ b) : b < c * a :=
(le_mul_of_one_le_right b0 ha).trans_lt $ mul_lt_mul_of_pos_right bc a0
lemma lt_mul_of_lt_of_one_lt_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : 1 < a) (a0 : 0 < a) (b0 : 0 < b) : b < c * a :=
(lt_mul_of_one_lt_right b0 ha).trans $ mul_lt_mul_of_pos_right bc a0
/-! Lemmas of the form `a ≤ 1 → b ≤ c → a * b ≤ c`. -/
lemma mul_le_of_le_one_of_le_of_nonneg [mul_pos_mono α] (ha : a ≤ 1) (h : b ≤ c) (hb : 0 ≤ b) :
a * b ≤ c :=
(mul_le_of_le_one_left hb ha).trans h
lemma mul_lt_of_lt_one_of_le_of_pos [mul_pos_strict_mono α] (ha : a < 1) (h : b ≤ c) (hb : 0 < b) :
a * b < c :=
(mul_lt_of_lt_one_left hb ha).trans_le h
lemma mul_lt_of_le_one_of_lt_of_nonneg [mul_pos_mono α] (ha : a ≤ 1) (h : b < c) (hb : 0 ≤ b) :
a * b < c :=
(mul_le_of_le_one_left hb ha).trans_lt h
/-- Assumes right covariance. -/
lemma right.mul_lt_one_of_lt_of_le_of_pos [mul_pos_strict_mono α]
(ha : a < 1) (hb : b ≤ 1) (b0 : 0 < b) : a * b < 1 :=
mul_lt_of_lt_one_of_le_of_pos ha hb b0
/-- Assumes right covariance. -/
lemma right.mul_lt_one_of_le_of_lt_of_nonneg [mul_pos_mono α]
(ha : a ≤ 1) (hb : b < 1) (b0 : 0 ≤ b) : a * b < 1 :=
mul_lt_of_le_one_of_lt_of_nonneg ha hb b0
lemma mul_lt_of_lt_one_of_lt_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(ha : a < 1) (bc : b < c) (a0 : 0 < a) (c0 : 0 < c) : a * b < c :=
(mul_lt_mul_of_pos_left bc a0).trans $ mul_lt_of_lt_one_left c0 ha
/-- Assumes right covariance. -/
lemma right.mul_le_one_of_le_of_le [mul_pos_mono α]
(ha : a ≤ 1) (hb : b ≤ 1) (b0 : 0 ≤ b) : a * b ≤ 1 :=
mul_le_of_le_one_of_le_of_nonneg ha hb b0
lemma mul_le_of_le_one_of_le' [pos_mul_mono α] [mul_pos_mono α]
(ha : a ≤ 1) (bc : b ≤ c) (a0 : 0 ≤ a) (c0 : 0 ≤ c) : a * b ≤ c :=
(mul_le_mul_of_nonneg_left bc a0).trans $ mul_le_of_le_one_left c0 ha
lemma mul_lt_of_lt_one_of_le' [pos_mul_mono α] [mul_pos_strict_mono α]
(ha : a < 1) (bc : b ≤ c) (a0 : 0 ≤ a) (c0 : 0 < c) : a * b < c :=
(mul_le_mul_of_nonneg_left bc a0).trans_lt $ mul_lt_of_lt_one_left c0 ha
lemma mul_lt_of_le_one_of_lt' [pos_mul_strict_mono α] [mul_pos_mono α]
(ha : a ≤ 1) (bc : b < c) (a0 : 0 < a) (c0 : 0 ≤ c) : a * b < c :=
(mul_lt_mul_of_pos_left bc a0).trans_le $ mul_le_of_le_one_left c0 ha
/-! Lemmas of the form `1 ≤ a → b ≤ c → b ≤ a * c`. -/
lemma lt_mul_of_one_lt_of_le_of_pos [mul_pos_strict_mono α] (ha : 1 < a) (h : b ≤ c) (hc : 0 < c) :
b < a * c :=
h.trans_lt $ lt_mul_of_one_lt_left hc ha
lemma lt_mul_of_one_le_of_lt_of_nonneg [mul_pos_mono α] (ha : 1 ≤ a) (h : b < c) (hc : 0 ≤ c) :
b < a * c :=
h.trans_le $ le_mul_of_one_le_left hc ha
lemma lt_mul_of_one_lt_of_lt_of_pos [mul_pos_strict_mono α] (ha : 1 < a) (h : b < c) (hc : 0 < c) :
b < a * c :=
h.trans $ lt_mul_of_one_lt_left hc ha
/-- Assumes right covariance. -/
lemma right.one_lt_mul_of_lt_of_le_of_pos [mul_pos_strict_mono α]
(ha : 1 < a) (hb : 1 ≤ b) (b0 : 0 < b) : 1 < a * b :=
lt_mul_of_one_lt_of_le_of_pos ha hb b0
/-- Assumes right covariance. -/
lemma right.one_lt_mul_of_le_of_lt_of_nonneg [mul_pos_mono α]
(ha : 1 ≤ a) (hb : 1 < b) (b0 : 0 ≤ b) : 1 < a * b :=
lt_mul_of_one_le_of_lt_of_nonneg ha hb b0
/-- Assumes right covariance. -/
lemma right.one_lt_mul_of_lt_of_lt [mul_pos_strict_mono α]
(ha : 1 < a) (hb : 1 < b) (b0 : 0 < b) : 1 < a * b :=
lt_mul_of_one_lt_of_lt_of_pos ha hb b0
lemma lt_mul_of_one_lt_of_lt_of_nonneg [mul_pos_mono α] (ha : 1 ≤ a) (h : b < c) (hc : 0 ≤ c) :
b < a * c :=
h.trans_le $ le_mul_of_one_le_left hc ha
lemma lt_of_mul_lt_of_one_le_of_nonneg_left [pos_mul_mono α] (h : a * b < c) (hle : 1 ≤ b)
(ha : 0 ≤ a) :
a < c :=
(le_mul_of_one_le_right ha hle).trans_lt h
lemma lt_of_lt_mul_of_le_one_of_nonneg_left [pos_mul_mono α] (h : a < b * c) (hc : c ≤ 1)
(hb : 0 ≤ b) :
a < b :=
h.trans_le $ mul_le_of_le_one_right hb hc
lemma lt_of_lt_mul_of_le_one_of_nonneg_right [mul_pos_mono α] (h : a < b * c) (hb : b ≤ 1)
(hc : 0 ≤ c) :
a < c :=
h.trans_le $ mul_le_of_le_one_left hc hb
lemma le_mul_of_one_le_of_le_of_nonneg [mul_pos_mono α] (ha : 1 ≤ a) (bc : b ≤ c) (c0 : 0 ≤ c) :
b ≤ a * c :=
bc.trans $ le_mul_of_one_le_left c0 ha
/-- Assumes right covariance. -/
lemma right.one_le_mul_of_le_of_le [mul_pos_mono α] (ha : 1 ≤ a) (hb : 1 ≤ b) (b0 : 0 ≤ b) :
1 ≤ a * b :=
le_mul_of_one_le_of_le_of_nonneg ha hb b0
lemma le_of_mul_le_of_one_le_of_nonneg_left [pos_mul_mono α] (h : a * b ≤ c) (hb : 1 ≤ b)
(ha : 0 ≤ a) :
a ≤ c :=
(le_mul_of_one_le_right ha hb).trans h
lemma le_of_le_mul_of_le_one_of_nonneg_left [pos_mul_mono α] (h : a ≤ b * c) (hc : c ≤ 1)
(hb : 0 ≤ b) :
a ≤ b :=
h.trans $ mul_le_of_le_one_right hb hc
lemma le_of_mul_le_of_one_le_nonneg_right [mul_pos_mono α] (h : a * b ≤ c) (ha : 1 ≤ a)
(hb : 0 ≤ b) :
b ≤ c :=
(le_mul_of_one_le_left hb ha).trans h
lemma le_of_le_mul_of_le_one_of_nonneg_right [mul_pos_mono α] (h : a ≤ b * c) (hb : b ≤ 1)
(hc : 0 ≤ c) :
a ≤ c :=
h.trans $ mul_le_of_le_one_left hc hb
end preorder
section linear_order
variables [linear_order α]
-- Yaël: What's the point of this lemma? If we have `0 * 0 = 0`, then we can just take `b = 0`.
-- proven with `a0 : 0 ≤ a` as `exists_square_le`
lemma exists_square_le' [pos_mul_strict_mono α] (a0 : 0 < a) : ∃ (b : α), b * b ≤ a :=
begin
obtain ha | ha := lt_or_le a 1,
{ exact ⟨a, (mul_lt_of_lt_one_right a0 ha).le⟩ },
{ exact ⟨1, by rwa mul_one⟩ }
end
end linear_order
end mul_one_class
section cancel_monoid_with_zero
variables [cancel_monoid_with_zero α]
section partial_order
variables [partial_order α]
lemma pos_mul_mono.to_pos_mul_strict_mono [pos_mul_mono α] : pos_mul_strict_mono α :=
⟨λ x a b h, (mul_le_mul_of_nonneg_left h.le x.2.le).lt_of_ne (h.ne ∘ mul_left_cancel₀ x.2.ne')⟩
lemma pos_mul_mono_iff_pos_mul_strict_mono : pos_mul_mono α ↔ pos_mul_strict_mono α :=
⟨@pos_mul_mono.to_pos_mul_strict_mono α _ _, @pos_mul_strict_mono.to_pos_mul_mono α _ _⟩
lemma mul_pos_mono.to_mul_pos_strict_mono [mul_pos_mono α] : mul_pos_strict_mono α :=
⟨λ x a b h, (mul_le_mul_of_nonneg_right h.le x.2.le).lt_of_ne (h.ne ∘ mul_right_cancel₀ x.2.ne')⟩
lemma mul_pos_mono_iff_mul_pos_strict_mono : mul_pos_mono α ↔ mul_pos_strict_mono α :=
⟨@mul_pos_mono.to_mul_pos_strict_mono α _ _, @mul_pos_strict_mono.to_mul_pos_mono α _ _⟩
lemma pos_mul_reflect_lt.to_pos_mul_mono_rev [pos_mul_reflect_lt α] : pos_mul_mono_rev α :=
⟨λ x a b h, h.eq_or_lt.elim (le_of_eq ∘ mul_left_cancel₀ x.2.ne.symm)
(λ h', (lt_of_mul_lt_mul_left h' x.2.le).le)⟩
lemma pos_mul_mono_rev_iff_pos_mul_reflect_lt : pos_mul_mono_rev α ↔ pos_mul_reflect_lt α :=
⟨@pos_mul_mono_rev.to_pos_mul_reflect_lt α _ _, @pos_mul_reflect_lt.to_pos_mul_mono_rev α _ _⟩
lemma mul_pos_reflect_lt.to_mul_pos_mono_rev [mul_pos_reflect_lt α] : mul_pos_mono_rev α :=
⟨λ x a b h, h.eq_or_lt.elim (le_of_eq ∘ mul_right_cancel₀ x.2.ne.symm)
(λ h', (lt_of_mul_lt_mul_right h' x.2.le).le)⟩
lemma mul_pos_mono_rev_iff_mul_pos_reflect_lt : mul_pos_mono_rev α ↔ mul_pos_reflect_lt α :=
⟨@mul_pos_mono_rev.to_mul_pos_reflect_lt α _ _, @mul_pos_reflect_lt.to_mul_pos_mono_rev α _ _⟩
end partial_order
end cancel_monoid_with_zero
section comm_semigroup_has_zero
variables [comm_semigroup α] [has_zero α] [preorder α]
lemma pos_mul_strict_mono_iff_mul_pos_strict_mono :
pos_mul_strict_mono α ↔ mul_pos_strict_mono α :=
by simp ! only [mul_comm]
lemma pos_mul_reflect_lt_iff_mul_pos_reflect_lt :
pos_mul_reflect_lt α ↔ mul_pos_reflect_lt α :=
by simp ! only [mul_comm]
lemma pos_mul_mono_iff_mul_pos_mono :
pos_mul_mono α ↔ mul_pos_mono α :=
by simp ! only [mul_comm]
lemma pos_mul_mono_rev_iff_mul_pos_mono_rev :
pos_mul_mono_rev α ↔ mul_pos_mono_rev α :=
by simp ! only [mul_comm]
end comm_semigroup_has_zero
|
703f5b69e2cf96d5a10ba31e0926ce63057863c6 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/computability/partrec_code.lean | 9da8385ea9150505dc345ab2deee8ef736abbac4 | [
"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 | 38,845 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Godel numbering for partial recursive functions.
-/
import computability.partrec
open encodable denumerable
namespace nat.partrec
open nat (mkpair)
theorem rfind' {f} (hf : nat.partrec f) : nat.partrec (nat.unpaired (λ a m,
(nat.rfind (λ n, (λ m, m = 0) <$> f (mkpair a (n + m)))).map (+ m))) :=
partrec₂.unpaired'.2 $
begin
refine partrec.map
((@partrec₂.unpaired' (λ (a b : ℕ),
nat.rfind (λ n, (λ m, m = 0) <$> f (mkpair a (n + b))))).1 _)
(primrec.nat_add.comp primrec.snd $
primrec.snd.comp primrec.fst).to_comp.to₂,
have := rfind (partrec₂.unpaired'.2 ((partrec.nat_iff.2 hf).comp
(primrec₂.mkpair.comp
(primrec.fst.comp $ primrec.unpair.comp primrec.fst)
(primrec.nat_add.comp primrec.snd
(primrec.snd.comp $ primrec.unpair.comp primrec.fst))).to_comp).to₂),
simp at this, exact this
end
inductive code : Type
| zero : code
| succ : code
| left : code
| right : code
| pair : code → code → code
| comp : code → code → code
| prec : code → code → code
| rfind' : code → code
end nat.partrec
namespace nat.partrec.code
open nat (mkpair unpair)
open nat.partrec (code)
instance : inhabited code := ⟨zero⟩
protected def const : ℕ → code
| 0 := zero
| (n+1) := comp succ (const n)
theorem const_inj : Π {n₁ n₂}, nat.partrec.code.const n₁ = nat.partrec.code.const n₂ → n₁ = n₂
| 0 0 h := by simp
| (n₁+1) (n₂+1) h := by { dsimp [nat.partrec.code.const] at h,
injection h with h₁ h₂,
simp only [const_inj h₂] }
protected def id : code := pair left right
def curry (c : code) (n : ℕ) : code :=
comp c (pair (code.const n) code.id)
def encode_code : code → ℕ
| zero := 0
| succ := 1
| left := 2
| right := 3
| (pair cf cg) := bit0 (bit0 $ mkpair (encode_code cf) (encode_code cg)) + 4
| (comp cf cg) := bit0 (bit1 $ mkpair (encode_code cf) (encode_code cg)) + 4
| (prec cf cg) := bit1 (bit0 $ mkpair (encode_code cf) (encode_code cg)) + 4
| (rfind' cf) := bit1 (bit1 $ encode_code cf) + 4
def of_nat_code : ℕ → code
| 0 := zero
| 1 := succ
| 2 := left
| 3 := right
| (n+4) := let m := n.div2.div2 in
have hm : m < n + 4, by simp [m, nat.div2_val];
from lt_of_le_of_lt
(le_trans (nat.div_le_self _ _) (nat.div_le_self _ _))
(nat.succ_le_succ (nat.le_add_right _ _)),
have m1 : m.unpair.1 < n + 4, from lt_of_le_of_lt m.unpair_left_le hm,
have m2 : m.unpair.2 < n + 4, from lt_of_le_of_lt m.unpair_right_le hm,
match n.bodd, n.div2.bodd with
| ff, ff := pair (of_nat_code m.unpair.1) (of_nat_code m.unpair.2)
| ff, tt := comp (of_nat_code m.unpair.1) (of_nat_code m.unpair.2)
| tt, ff := prec (of_nat_code m.unpair.1) (of_nat_code m.unpair.2)
| tt, tt := rfind' (of_nat_code m)
end
private theorem encode_of_nat_code : ∀ n, encode_code (of_nat_code n) = n
| 0 := by simp [of_nat_code, encode_code]
| 1 := by simp [of_nat_code, encode_code]
| 2 := by simp [of_nat_code, encode_code]
| 3 := by simp [of_nat_code, encode_code]
| (n+4) := let m := n.div2.div2 in
have hm : m < n + 4, by simp [m, nat.div2_val];
from lt_of_le_of_lt
(le_trans (nat.div_le_self _ _) (nat.div_le_self _ _))
(nat.succ_le_succ (nat.le_add_right _ _)),
have m1 : m.unpair.1 < n + 4, from lt_of_le_of_lt m.unpair_left_le hm,
have m2 : m.unpair.2 < n + 4, from lt_of_le_of_lt m.unpair_right_le hm,
have IH : _ := encode_of_nat_code m,
have IH1 : _ := encode_of_nat_code m.unpair.1,
have IH2 : _ := encode_of_nat_code m.unpair.2,
begin
transitivity, swap,
rw [← nat.bit_decomp n, ← nat.bit_decomp n.div2],
simp [encode_code, of_nat_code, -add_comm],
cases n.bodd; cases n.div2.bodd;
simp [encode_code, of_nat_code, -add_comm, IH, IH1, IH2, m, nat.bit]
end
instance : denumerable code :=
mk' ⟨encode_code, of_nat_code,
λ c, by induction c; try {refl}; simp [
encode_code, of_nat_code, -add_comm, *],
encode_of_nat_code⟩
theorem encode_code_eq : encode = encode_code := rfl
theorem of_nat_code_eq : of_nat code = of_nat_code := rfl
theorem encode_lt_pair (cf cg) :
encode cf < encode (pair cf cg) ∧
encode cg < encode (pair cf cg) :=
begin
simp [encode_code_eq, encode_code, -add_comm],
have := nat.mul_le_mul_right _ (dec_trivial : 1 ≤ 2*2),
rw [one_mul, mul_assoc, ← bit0_eq_two_mul, ← bit0_eq_two_mul] at this,
have := lt_of_le_of_lt this (lt_add_of_pos_right _ (dec_trivial:0<4)),
exact ⟨
lt_of_le_of_lt (nat.left_le_mkpair _ _) this,
lt_of_le_of_lt (nat.right_le_mkpair _ _) this⟩
end
theorem encode_lt_comp (cf cg) :
encode cf < encode (comp cf cg) ∧
encode cg < encode (comp cf cg) :=
begin
suffices, exact (encode_lt_pair cf cg).imp
(λ h, lt_trans h this) (λ h, lt_trans h this),
change _, simp [encode_code_eq, encode_code]
end
theorem encode_lt_prec (cf cg) :
encode cf < encode (prec cf cg) ∧
encode cg < encode (prec cf cg) :=
begin
suffices, exact (encode_lt_pair cf cg).imp
(λ h, lt_trans h this) (λ h, lt_trans h this),
change _, simp [encode_code_eq, encode_code],
end
theorem encode_lt_rfind' (cf) : encode cf < encode (rfind' cf) :=
begin
simp [encode_code_eq, encode_code, -add_comm],
have := nat.mul_le_mul_right _ (dec_trivial : 1 ≤ 2*2),
rw [one_mul, mul_assoc, ← bit0_eq_two_mul, ← bit0_eq_two_mul] at this,
refine lt_of_le_of_lt (le_trans this _)
(lt_add_of_pos_right _ (dec_trivial:0<4)),
exact le_of_lt (nat.bit0_lt_bit1 $ le_of_lt $
nat.bit0_lt_bit1 $ le_refl _),
end
section
open primrec
theorem pair_prim : primrec₂ pair :=
primrec₂.of_nat_iff.2 $ primrec₂.encode_iff.1 $ nat_add.comp
(nat_bit0.comp $ nat_bit0.comp $
primrec₂.mkpair.comp
(encode_iff.2 $ (primrec.of_nat code).comp fst)
(encode_iff.2 $ (primrec.of_nat code).comp snd))
(primrec₂.const 4)
theorem comp_prim : primrec₂ comp :=
primrec₂.of_nat_iff.2 $ primrec₂.encode_iff.1 $ nat_add.comp
(nat_bit0.comp $ nat_bit1.comp $
primrec₂.mkpair.comp
(encode_iff.2 $ (primrec.of_nat code).comp fst)
(encode_iff.2 $ (primrec.of_nat code).comp snd))
(primrec₂.const 4)
theorem prec_prim : primrec₂ prec :=
primrec₂.of_nat_iff.2 $ primrec₂.encode_iff.1 $ nat_add.comp
(nat_bit1.comp $ nat_bit0.comp $
primrec₂.mkpair.comp
(encode_iff.2 $ (primrec.of_nat code).comp fst)
(encode_iff.2 $ (primrec.of_nat code).comp snd))
(primrec₂.const 4)
theorem rfind_prim : primrec rfind' :=
of_nat_iff.2 $ encode_iff.1 $ nat_add.comp
(nat_bit1.comp $ nat_bit1.comp $
encode_iff.2 $ primrec.of_nat code)
(const 4)
theorem rec_prim' {α σ} [primcodable α] [primcodable σ]
{c : α → code} (hc : primrec c)
{z : α → σ} (hz : primrec z)
{s : α → σ} (hs : primrec s)
{l : α → σ} (hl : primrec l)
{r : α → σ} (hr : primrec r)
{pr : α → code × code × σ × σ → σ} (hpr : primrec₂ pr)
{co : α → code × code × σ × σ → σ} (hco : primrec₂ co)
{pc : α → code × code × σ × σ → σ} (hpc : primrec₂ pc)
{rf : α → code × σ → σ} (hrf : primrec₂ rf) :
let PR (a) := λ cf cg hf hg, pr a (cf, cg, hf, hg),
CO (a) := λ cf cg hf hg, co a (cf, cg, hf, hg),
PC (a) := λ cf cg hf hg, pc a (cf, cg, hf, hg),
RF (a) := λ cf hf, rf a (cf, hf),
F (a) (c : code) : σ := nat.partrec.code.rec_on c
(z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a) in
primrec (λ a, F a (c a)) :=
begin
intros,
let G₁ : (α × list σ) × ℕ × ℕ → option σ := λ p,
let a := p.1.1, IH := p.1.2, n := p.2.1, m := p.2.2 in
(IH.nth m).bind $ λ s,
(IH.nth m.unpair.1).bind $ λ s₁,
(IH.nth m.unpair.2).map $ λ s₂,
cond n.bodd
(cond n.div2.bodd
(rf a (of_nat code m, s))
(pc a (of_nat code m.unpair.1, of_nat code m.unpair.2, s₁, s₂)))
(cond n.div2.bodd
(co a (of_nat code m.unpair.1, of_nat code m.unpair.2, s₁, s₂))
(pr a (of_nat code m.unpair.1, of_nat code m.unpair.2, s₁, s₂))),
have : primrec G₁,
{ refine option_bind (list_nth.comp (snd.comp fst) (snd.comp snd)) _,
refine option_bind ((list_nth.comp (snd.comp fst)
(fst.comp $ primrec.unpair.comp (snd.comp snd))).comp fst) _,
refine option_map ((list_nth.comp (snd.comp fst)
(snd.comp $ primrec.unpair.comp (snd.comp snd))).comp $ fst.comp fst) _,
have a := fst.comp (fst.comp $ fst.comp $ fst.comp fst),
have n := fst.comp (snd.comp $ fst.comp $ fst.comp fst),
have m := snd.comp (snd.comp $ fst.comp $ fst.comp fst),
have m₁ := fst.comp (primrec.unpair.comp m),
have m₂ := snd.comp (primrec.unpair.comp m),
have s := snd.comp (fst.comp fst),
have s₁ := snd.comp fst,
have s₂ := snd,
exact (nat_bodd.comp n).cond
((nat_bodd.comp $ nat_div2.comp n).cond
(hrf.comp a (((primrec.of_nat code).comp m).pair s))
(hpc.comp a (((primrec.of_nat code).comp m₁).pair $
((primrec.of_nat code).comp m₂).pair $ s₁.pair s₂)))
(primrec.cond (nat_bodd.comp $ nat_div2.comp n)
(hco.comp a (((primrec.of_nat code).comp m₁).pair $
((primrec.of_nat code).comp m₂).pair $ s₁.pair s₂))
(hpr.comp a (((primrec.of_nat code).comp m₁).pair $
((primrec.of_nat code).comp m₂).pair $ s₁.pair s₂))) },
let G : α → list σ → option σ := λ a IH,
IH.length.cases (some (z a)) $ λ n,
n.cases (some (s a)) $ λ n,
n.cases (some (l a)) $ λ n,
n.cases (some (r a)) $ λ n,
G₁ ((a, IH), n, n.div2.div2),
have : primrec₂ G := (nat_cases
(list_length.comp snd) (option_some_iff.2 (hz.comp fst)) $
nat_cases snd (option_some_iff.2 (hs.comp (fst.comp fst))) $
nat_cases snd (option_some_iff.2 (hl.comp (fst.comp $ fst.comp fst))) $
nat_cases snd (option_some_iff.2 (hr.comp (fst.comp $ fst.comp $ fst.comp fst)))
(this.comp $
((fst.pair snd).comp $ fst.comp $ fst.comp $ fst.comp $ fst).pair $
snd.pair $ nat_div2.comp $ nat_div2.comp snd)),
refine ((nat_strong_rec
(λ a n, F a (of_nat code n)) this.to₂ $ λ a n, _).comp
primrec.id $ encode_iff.2 hc).of_eq (λ a, by simp),
simp,
iterate 4 {cases n with n, {simp [of_nat_code_eq, of_nat_code]; refl}},
simp [G], rw [list.length_map, list.length_range],
let m := n.div2.div2,
show G₁ ((a, (list.range (n+4)).map (λ n, F a (of_nat code n))), n, m)
= some (F a (of_nat code (n+4))),
have hm : m < n + 4, by simp [nat.div2_val, m];
from lt_of_le_of_lt
(le_trans (nat.div_le_self _ _) (nat.div_le_self _ _))
(nat.succ_le_succ (nat.le_add_right _ _)),
have m1 : m.unpair.1 < n + 4, from lt_of_le_of_lt m.unpair_left_le hm,
have m2 : m.unpair.2 < n + 4, from lt_of_le_of_lt m.unpair_right_le hm,
simp [G₁], simp [list.nth_map, list.nth_range, hm, m1, m2],
change of_nat code (n+4) with of_nat_code (n+4),
simp [of_nat_code],
cases n.bodd; cases n.div2.bodd; refl
end
theorem rec_prim {α σ} [primcodable α] [primcodable σ]
{c : α → code} (hc : primrec c)
{z : α → σ} (hz : primrec z)
{s : α → σ} (hs : primrec s)
{l : α → σ} (hl : primrec l)
{r : α → σ} (hr : primrec r)
{pr : α → code → code → σ → σ → σ}
(hpr : primrec (λ a : α × code × code × σ × σ,
pr a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2))
{co : α → code → code → σ → σ → σ}
(hco : primrec (λ a : α × code × code × σ × σ,
co a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2))
{pc : α → code → code → σ → σ → σ}
(hpc : primrec (λ a : α × code × code × σ × σ,
pc a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2))
{rf : α → code → σ → σ}
(hrf : primrec (λ a : α × code × σ, rf a.1 a.2.1 a.2.2)) :
let F (a) (c : code) : σ := nat.partrec.code.rec_on c
(z a) (s a) (l a) (r a) (pr a) (co a) (pc a) (rf a) in
primrec (λ a, F a (c a)) :=
begin
intros,
let G₁ : (α × list σ) × ℕ × ℕ → option σ := λ p,
let a := p.1.1, IH := p.1.2, n := p.2.1, m := p.2.2 in
(IH.nth m).bind $ λ s,
(IH.nth m.unpair.1).bind $ λ s₁,
(IH.nth m.unpair.2).map $ λ s₂,
cond n.bodd
(cond n.div2.bodd
(rf a (of_nat code m) s)
(pc a (of_nat code m.unpair.1) (of_nat code m.unpair.2) s₁ s₂))
(cond n.div2.bodd
(co a (of_nat code m.unpair.1) (of_nat code m.unpair.2) s₁ s₂)
(pr a (of_nat code m.unpair.1) (of_nat code m.unpair.2) s₁ s₂)),
have : primrec G₁,
{ refine option_bind (list_nth.comp (snd.comp fst) (snd.comp snd)) _,
refine option_bind ((list_nth.comp (snd.comp fst)
(fst.comp $ primrec.unpair.comp (snd.comp snd))).comp fst) _,
refine option_map ((list_nth.comp (snd.comp fst)
(snd.comp $ primrec.unpair.comp (snd.comp snd))).comp $ fst.comp fst) _,
have a := fst.comp (fst.comp $ fst.comp $ fst.comp fst),
have n := fst.comp (snd.comp $ fst.comp $ fst.comp fst),
have m := snd.comp (snd.comp $ fst.comp $ fst.comp fst),
have m₁ := fst.comp (primrec.unpair.comp m),
have m₂ := snd.comp (primrec.unpair.comp m),
have s := snd.comp (fst.comp fst),
have s₁ := snd.comp fst,
have s₂ := snd,
exact (nat_bodd.comp n).cond
((nat_bodd.comp $ nat_div2.comp n).cond
(hrf.comp $ a.pair (((primrec.of_nat code).comp m).pair s))
(hpc.comp $ a.pair (((primrec.of_nat code).comp m₁).pair $
((primrec.of_nat code).comp m₂).pair $ s₁.pair s₂)))
(primrec.cond (nat_bodd.comp $ nat_div2.comp n)
(hco.comp $ a.pair (((primrec.of_nat code).comp m₁).pair $
((primrec.of_nat code).comp m₂).pair $ s₁.pair s₂))
(hpr.comp $ a.pair (((primrec.of_nat code).comp m₁).pair $
((primrec.of_nat code).comp m₂).pair $ s₁.pair s₂))) },
let G : α → list σ → option σ := λ a IH,
IH.length.cases (some (z a)) $ λ n,
n.cases (some (s a)) $ λ n,
n.cases (some (l a)) $ λ n,
n.cases (some (r a)) $ λ n,
G₁ ((a, IH), n, n.div2.div2),
have : primrec₂ G := (nat_cases
(list_length.comp snd) (option_some_iff.2 (hz.comp fst)) $
nat_cases snd (option_some_iff.2 (hs.comp (fst.comp fst))) $
nat_cases snd (option_some_iff.2 (hl.comp (fst.comp $ fst.comp fst))) $
nat_cases snd (option_some_iff.2 (hr.comp (fst.comp $ fst.comp $ fst.comp fst)))
(this.comp $
((fst.pair snd).comp $ fst.comp $ fst.comp $ fst.comp $ fst).pair $
snd.pair $ nat_div2.comp $ nat_div2.comp snd)),
refine ((nat_strong_rec
(λ a n, F a (of_nat code n)) this.to₂ $ λ a n, _).comp
primrec.id $ encode_iff.2 hc).of_eq (λ a, by simp),
simp,
iterate 4 {cases n with n, {simp [of_nat_code_eq, of_nat_code]; refl}},
simp [G], rw [list.length_map, list.length_range],
let m := n.div2.div2,
show G₁ ((a, (list.range (n+4)).map (λ n, F a (of_nat code n))), n, m)
= some (F a (of_nat code (n+4))),
have hm : m < n + 4, by simp [nat.div2_val, m];
from lt_of_le_of_lt
(le_trans (nat.div_le_self _ _) (nat.div_le_self _ _))
(nat.succ_le_succ (nat.le_add_right _ _)),
have m1 : m.unpair.1 < n + 4, from lt_of_le_of_lt m.unpair_left_le hm,
have m2 : m.unpair.2 < n + 4, from lt_of_le_of_lt m.unpair_right_le hm,
simp [G₁], simp [list.nth_map, list.nth_range, hm, m1, m2],
change of_nat code (n+4) with of_nat_code (n+4),
simp [of_nat_code],
cases n.bodd; cases n.div2.bodd; refl
end
end
section
open computable
/- TODO(Mario): less copy-paste from previous proof -/
theorem rec_computable {α σ} [primcodable α] [primcodable σ]
{c : α → code} (hc : computable c)
{z : α → σ} (hz : computable z)
{s : α → σ} (hs : computable s)
{l : α → σ} (hl : computable l)
{r : α → σ} (hr : computable r)
{pr : α → code × code × σ × σ → σ} (hpr : computable₂ pr)
{co : α → code × code × σ × σ → σ} (hco : computable₂ co)
{pc : α → code × code × σ × σ → σ} (hpc : computable₂ pc)
{rf : α → code × σ → σ} (hrf : computable₂ rf) :
let PR (a) := λ cf cg hf hg, pr a (cf, cg, hf, hg),
CO (a) := λ cf cg hf hg, co a (cf, cg, hf, hg),
PC (a) := λ cf cg hf hg, pc a (cf, cg, hf, hg),
RF (a) := λ cf hf, rf a (cf, hf),
F (a) (c : code) : σ := nat.partrec.code.rec_on c
(z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a) in
computable (λ a, F a (c a)) :=
begin
intros,
let G₁ : (α × list σ) × ℕ × ℕ → option σ := λ p,
let a := p.1.1, IH := p.1.2, n := p.2.1, m := p.2.2 in
(IH.nth m).bind $ λ s,
(IH.nth m.unpair.1).bind $ λ s₁,
(IH.nth m.unpair.2).map $ λ s₂,
cond n.bodd
(cond n.div2.bodd
(rf a (of_nat code m, s))
(pc a (of_nat code m.unpair.1, of_nat code m.unpair.2, s₁, s₂)))
(cond n.div2.bodd
(co a (of_nat code m.unpair.1, of_nat code m.unpair.2, s₁, s₂))
(pr a (of_nat code m.unpair.1, of_nat code m.unpair.2, s₁, s₂))),
have : computable G₁,
{ refine option_bind (list_nth.comp (snd.comp fst) (snd.comp snd)) _,
refine option_bind ((list_nth.comp (snd.comp fst)
(fst.comp $ computable.unpair.comp (snd.comp snd))).comp fst) _,
refine option_map ((list_nth.comp (snd.comp fst)
(snd.comp $ computable.unpair.comp (snd.comp snd))).comp $ fst.comp fst) _,
have a := fst.comp (fst.comp $ fst.comp $ fst.comp fst),
have n := fst.comp (snd.comp $ fst.comp $ fst.comp fst),
have m := snd.comp (snd.comp $ fst.comp $ fst.comp fst),
have m₁ := fst.comp (computable.unpair.comp m),
have m₂ := snd.comp (computable.unpair.comp m),
have s := snd.comp (fst.comp fst),
have s₁ := snd.comp fst,
have s₂ := snd,
exact (nat_bodd.comp n).cond
((nat_bodd.comp $ nat_div2.comp n).cond
(hrf.comp a (((computable.of_nat code).comp m).pair s))
(hpc.comp a (((computable.of_nat code).comp m₁).pair $
((computable.of_nat code).comp m₂).pair $ s₁.pair s₂)))
(computable.cond (nat_bodd.comp $ nat_div2.comp n)
(hco.comp a (((computable.of_nat code).comp m₁).pair $
((computable.of_nat code).comp m₂).pair $ s₁.pair s₂))
(hpr.comp a (((computable.of_nat code).comp m₁).pair $
((computable.of_nat code).comp m₂).pair $ s₁.pair s₂))) },
let G : α → list σ → option σ := λ a IH,
IH.length.cases (some (z a)) $ λ n,
n.cases (some (s a)) $ λ n,
n.cases (some (l a)) $ λ n,
n.cases (some (r a)) $ λ n,
G₁ ((a, IH), n, n.div2.div2),
have : computable₂ G := (nat_cases
(list_length.comp snd) (option_some_iff.2 (hz.comp fst)) $
nat_cases snd (option_some_iff.2 (hs.comp (fst.comp fst))) $
nat_cases snd (option_some_iff.2 (hl.comp (fst.comp $ fst.comp fst))) $
nat_cases snd (option_some_iff.2 (hr.comp (fst.comp $ fst.comp $ fst.comp fst)))
(this.comp $
((fst.pair snd).comp $ fst.comp $ fst.comp $ fst.comp $ fst).pair $
snd.pair $ nat_div2.comp $ nat_div2.comp snd)),
refine ((nat_strong_rec
(λ a n, F a (of_nat code n)) this.to₂ $ λ a n, _).comp
computable.id $ encode_iff.2 hc).of_eq (λ a, by simp),
simp,
iterate 4 {cases n with n, {simp [of_nat_code_eq, of_nat_code]; refl}},
simp [G], rw [list.length_map, list.length_range],
let m := n.div2.div2,
show G₁ ((a, (list.range (n+4)).map (λ n, F a (of_nat code n))), n, m)
= some (F a (of_nat code (n+4))),
have hm : m < n + 4, by simp [nat.div2_val, m];
from lt_of_le_of_lt
(le_trans (nat.div_le_self _ _) (nat.div_le_self _ _))
(nat.succ_le_succ (nat.le_add_right _ _)),
have m1 : m.unpair.1 < n + 4, from lt_of_le_of_lt m.unpair_left_le hm,
have m2 : m.unpair.2 < n + 4, from lt_of_le_of_lt m.unpair_right_le hm,
simp [G₁], simp [list.nth_map, list.nth_range, hm, m1, m2],
change of_nat code (n+4) with of_nat_code (n+4),
simp [of_nat_code],
cases n.bodd; cases n.div2.bodd; refl
end
end
def eval : code → ℕ →. ℕ
| zero := pure 0
| succ := nat.succ
| left := ↑(λ n : ℕ, n.unpair.1)
| right := ↑(λ n : ℕ, n.unpair.2)
| (pair cf cg) := λ n, mkpair <$> eval cf n <*> eval cg n
| (comp cf cg) := λ n, eval cg n >>= eval cf
| (prec cf cg) := nat.unpaired (λ a n,
n.elim (eval cf a) (λ y IH, do i ← IH, eval cg (mkpair a (mkpair y i))))
| (rfind' cf) := nat.unpaired (λ a m,
(nat.rfind (λ n, (λ m, m = 0) <$>
eval cf (mkpair a (n + m)))).map (+ m))
instance : has_mem (ℕ →. ℕ) code := ⟨λ f c, eval c = f⟩
@[simp] theorem eval_const : ∀ n m, eval (code.const n) m = roption.some n
| 0 m := rfl
| (n+1) m := by simp! *
@[simp] theorem eval_id (n) : eval code.id n = roption.some n := by simp! [(<*>)]
@[simp] theorem eval_curry (c n x) : eval (curry c n) x = eval c (mkpair n x) :=
by simp! [(<*>)]
theorem const_prim : primrec code.const :=
(primrec.id.nat_iterate (primrec.const zero)
(comp_prim.comp (primrec.const succ) primrec.snd).to₂).of_eq $
λ n, by simp; induction n; simp [*, code.const, function.iterate_succ']
theorem curry_prim : primrec₂ curry :=
comp_prim.comp primrec.fst $
pair_prim.comp (const_prim.comp primrec.snd) (primrec.const code.id)
theorem curry_inj {c₁ c₂ n₁ n₂} (h : curry c₁ n₁ = curry c₂ n₂) : c₁ = c₂ ∧ n₁ = n₂ :=
⟨by injection h, by { injection h,
injection h with h₁ h₂,
injection h₂ with h₃ h₄,
exact const_inj h₃ }⟩
theorem smn : ∃ f : code → ℕ → code,
computable₂ f ∧ ∀ c n x, eval (f c n) x = eval c (mkpair n x) :=
⟨curry, primrec₂.to_comp curry_prim, eval_curry⟩
theorem exists_code {f : ℕ →. ℕ} : nat.partrec f ↔ ∃ c : code, eval c = f :=
⟨λ h, begin
induction h,
case nat.partrec.zero { exact ⟨zero, rfl⟩ },
case nat.partrec.succ { exact ⟨succ, rfl⟩ },
case nat.partrec.left { exact ⟨left, rfl⟩ },
case nat.partrec.right { exact ⟨right, rfl⟩ },
case nat.partrec.pair : f g pf pg hf hg {
rcases hf with ⟨cf, rfl⟩, rcases hg with ⟨cg, rfl⟩,
exact ⟨pair cf cg, rfl⟩ },
case nat.partrec.comp : f g pf pg hf hg {
rcases hf with ⟨cf, rfl⟩, rcases hg with ⟨cg, rfl⟩,
exact ⟨comp cf cg, rfl⟩ },
case nat.partrec.prec : f g pf pg hf hg {
rcases hf with ⟨cf, rfl⟩, rcases hg with ⟨cg, rfl⟩,
exact ⟨prec cf cg, rfl⟩ },
case nat.partrec.rfind : f pf hf {
rcases hf with ⟨cf, rfl⟩,
refine ⟨comp (rfind' cf) (pair code.id zero), _⟩,
simp [eval, (<*>), pure, pfun.pure, roption.map_id'] },
end, λ h, begin
rcases h with ⟨c, rfl⟩, induction c,
case nat.partrec.code.zero { exact nat.partrec.zero },
case nat.partrec.code.succ { exact nat.partrec.succ },
case nat.partrec.code.left { exact nat.partrec.left },
case nat.partrec.code.right { exact nat.partrec.right },
case nat.partrec.code.pair : cf cg pf pg { exact pf.pair pg },
case nat.partrec.code.comp : cf cg pf pg { exact pf.comp pg },
case nat.partrec.code.prec : cf cg pf pg { exact pf.prec pg },
case nat.partrec.code.rfind' : cf pf { exact pf.rfind' },
end⟩
def evaln : ∀ k : ℕ, code → ℕ → option ℕ
| 0 _ := λ m, none
| (k+1) zero := λ n, guard (n ≤ k) >> pure 0
| (k+1) succ := λ n, guard (n ≤ k) >> pure (nat.succ n)
| (k+1) left := λ n, guard (n ≤ k) >> pure n.unpair.1
| (k+1) right := λ n, guard (n ≤ k) >> pure n.unpair.2
| (k+1) (pair cf cg) := λ n, guard (n ≤ k) >>
mkpair <$> evaln (k+1) cf n <*> evaln (k+1) cg n
| (k+1) (comp cf cg) := λ n, guard (n ≤ k) >>
do x ← evaln (k+1) cg n, evaln (k+1) cf x
| (k+1) (prec cf cg) := λ n, guard (n ≤ k) >>
n.unpaired (λ a n,
n.cases (evaln (k+1) cf a) $ λ y, do
i ← evaln k (prec cf cg) (mkpair a y),
evaln (k+1) cg (mkpair a (mkpair y i)))
| (k+1) (rfind' cf) := λ n, guard (n ≤ k) >>
n.unpaired (λ a m, do
x ← evaln (k+1) cf (mkpair a m),
if x = 0 then pure m else
evaln k (rfind' cf) (mkpair a (m+1)))
theorem evaln_bound : ∀ {k c n x}, x ∈ evaln k c n → n < k
| 0 c n x h := by simp [evaln] at h; cases h
| (k+1) c n x h := begin
suffices : ∀ {o : option ℕ}, x ∈ guard (n ≤ k) >> o → n < k + 1,
{ cases c; rw [evaln] at h; exact this h },
simpa [(>>)] using nat.lt_succ_of_le
end
theorem evaln_mono : ∀ {k₁ k₂ c n x}, k₁ ≤ k₂ → x ∈ evaln k₁ c n → x ∈ evaln k₂ c n
| 0 k₂ c n x hl h := by simp [evaln] at h; cases h
| (k+1) (k₂+1) c n x hl h := begin
have hl' := nat.le_of_succ_le_succ hl,
have : ∀ {k k₂ n x : ℕ} {o₁ o₂ : option ℕ},
k ≤ k₂ → (x ∈ o₁ → x ∈ o₂) → x ∈ guard (n ≤ k) >> o₁ → x ∈ guard (n ≤ k₂) >> o₂,
{ simp [(>>)], introv h h₁ h₂ h₃, exact ⟨le_trans h₂ h, h₁ h₃⟩ },
simp at h ⊢,
induction c with cf cg hf hg cf cg hf hg cf cg hf hg cf hf generalizing x n;
rw [evaln] at h ⊢; refine this hl' (λ h, _) h,
iterate 4 {exact h},
{ -- pair cf cg
simp [(<*>)] at h ⊢,
exact h.imp (λ a, and.imp (hf _ _) $ Exists.imp $ λ b, and.imp_left (hg _ _)) },
{ -- comp cf cg
simp at h ⊢,
exact h.imp (λ a, and.imp (hg _ _) (hf _ _)) },
{ -- prec cf cg
revert h, simp,
induction n.unpair.2; simp,
{ apply hf },
{ exact λ y h₁ h₂, ⟨y, evaln_mono hl' h₁, hg _ _ h₂⟩ } },
{ -- rfind' cf
simp at h ⊢,
refine h.imp (λ x, and.imp (hf _ _) _),
by_cases x0 : x = 0; simp [x0],
exact evaln_mono hl' }
end
theorem evaln_sound : ∀ {k c n x}, x ∈ evaln k c n → x ∈ eval c n
| 0 _ n x h := by simp [evaln] at h; cases h
| (k+1) c n x h := begin
induction c with cf cg hf hg cf cg hf hg cf cg hf hg cf hf generalizing x n;
simp [eval, evaln, (>>), (<*>)] at h ⊢; cases h with _ h,
iterate 4 {simpa [pure, pfun.pure, eq_comm] using h},
{ -- pair cf cg
rcases h with ⟨y, ef, z, eg, rfl⟩,
exact ⟨_, hf _ _ ef, _, hg _ _ eg, rfl⟩ },
{ --comp hf hg
rcases h with ⟨y, eg, ef⟩,
exact ⟨_, hg _ _ eg, hf _ _ ef⟩ },
{ -- prec cf cg
revert h,
induction n.unpair.2 with m IH generalizing x; simp,
{ apply hf },
{ refine λ y h₁ h₂, ⟨y, IH _ _, _⟩,
{ have := evaln_mono k.le_succ h₁,
simp [evaln, (>>)] at this,
exact this.2 },
{ exact hg _ _ h₂ } } },
{ -- rfind' cf
rcases h with ⟨m, h₁, h₂⟩,
by_cases m0 : m = 0; simp [m0] at h₂,
{ exact ⟨0,
⟨by simpa [m0] using hf _ _ h₁,
λ m, (nat.not_lt_zero _).elim⟩,
by injection h₂ with h₂; simp [h₂]⟩ },
{ have := evaln_sound h₂, simp [eval] at this,
rcases this with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩,
refine ⟨ y+1, ⟨by simpa [add_comm, add_left_comm] using hy₁, λ i im, _⟩,
by simp [add_comm, add_left_comm] ⟩,
cases i with i,
{ exact ⟨m, by simpa using hf _ _ h₁, m0⟩ },
{ rcases hy₂ (nat.lt_of_succ_lt_succ im) with ⟨z, hz, z0⟩,
exact ⟨z, by simpa [nat.succ_eq_add_one, add_comm, add_left_comm] using hz, z0⟩ } } }
end
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n :=
⟨λ h, begin
suffices : ∃ k, x ∈ evaln (k+1) c n,
{ exact let ⟨k, h⟩ := this in ⟨k+1, h⟩ },
induction c generalizing n x;
simp [eval, evaln, pure, pfun.pure, (<*>), (>>)] at h ⊢,
iterate 4 { exact ⟨⟨_, le_refl _⟩, h.symm⟩ },
case nat.partrec.code.pair : cf cg hf hg {
rcases h with ⟨x, hx, y, hy, rfl⟩,
rcases hf hx with ⟨k₁, hk₁⟩, rcases hg hy with ⟨k₂, hk₂⟩,
refine ⟨max k₁ k₂, _⟩,
refine ⟨le_max_of_le_left $ nat.le_of_lt_succ $ evaln_bound hk₁,
_, evaln_mono (nat.succ_le_succ $ le_max_left _ _) hk₁,
_, evaln_mono (nat.succ_le_succ $ le_max_right _ _) hk₂, rfl⟩ },
case nat.partrec.code.comp : cf cg hf hg {
rcases h with ⟨y, hy, hx⟩,
rcases hg hy with ⟨k₁, hk₁⟩, rcases hf hx with ⟨k₂, hk₂⟩,
refine ⟨max k₁ k₂, _⟩,
exact ⟨le_max_of_le_left $ nat.le_of_lt_succ $ evaln_bound hk₁, _,
evaln_mono (nat.succ_le_succ $ le_max_left _ _) hk₁,
evaln_mono (nat.succ_le_succ $ le_max_right _ _) hk₂⟩ },
case nat.partrec.code.prec : cf cg hf hg {
revert h,
generalize : n.unpair.1 = n₁, generalize : n.unpair.2 = n₂,
induction n₂ with m IH generalizing x n; simp,
{ intro, rcases hf h with ⟨k, hk⟩,
exact ⟨_, le_max_left _ _,
evaln_mono (nat.succ_le_succ $ le_max_right _ _) hk⟩ },
{ intros y hy hx,
rcases IH hy with ⟨k₁, nk₁, hk₁⟩, rcases hg hx with ⟨k₂, hk₂⟩,
refine ⟨(max k₁ k₂).succ, nat.le_succ_of_le $ le_max_of_le_left $
le_trans (le_max_left _ (mkpair n₁ m)) nk₁, y,
evaln_mono (nat.succ_le_succ $ le_max_left _ _) _,
evaln_mono (nat.succ_le_succ $ nat.le_succ_of_le $ le_max_right _ _) hk₂⟩,
simp [evaln, (>>)],
exact ⟨le_trans (le_max_right _ _) nk₁, hk₁⟩ } },
case nat.partrec.code.rfind' : cf hf {
rcases h with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩,
suffices : ∃ k, y + n.unpair.2 ∈ evaln (k+1) (rfind' cf)
(mkpair n.unpair.1 n.unpair.2), {simpa [evaln, (>>)]},
revert hy₁ hy₂, generalize : n.unpair.2 = m, intros,
induction y with y IH generalizing m; simp [evaln, (>>)],
{ simp at hy₁, rcases hf hy₁ with ⟨k, hk⟩,
exact ⟨_, nat.le_of_lt_succ $ evaln_bound hk, _, hk, by simp; refl⟩ },
{ rcases hy₂ (nat.succ_pos _) with ⟨a, ha, a0⟩,
rcases hf ha with ⟨k₁, hk₁⟩,
rcases IH m.succ
(by simpa [nat.succ_eq_add_one, add_comm, add_left_comm] using hy₁)
(λ i hi, by simpa [nat.succ_eq_add_one, add_comm, add_left_comm] using
hy₂ (nat.succ_lt_succ hi))
with ⟨k₂, hk₂⟩,
use (max k₁ k₂).succ,
rw [zero_add] at hk₁,
use (nat.le_succ_of_le $ le_max_of_le_left $ nat.le_of_lt_succ $ evaln_bound hk₁),
use a,
use evaln_mono (nat.succ_le_succ $ nat.le_succ_of_le $ le_max_left _ _) hk₁,
simpa [nat.succ_eq_add_one, a0, -max_eq_left, -max_eq_right, add_comm, add_left_comm] using
evaln_mono (nat.succ_le_succ $ le_max_right _ _) hk₂ } }
end, λ ⟨k, h⟩, evaln_sound h⟩
section
open primrec
private def lup (L : list (list (option ℕ))) (p : ℕ × code) (n : ℕ) :=
do l ← L.nth (encode p), o ← l.nth n, o
private lemma hlup : primrec (λ p:_×(_×_)×_, lup p.1 p.2.1 p.2.2) :=
option_bind
(list_nth.comp fst (primrec.encode.comp $ fst.comp snd))
(option_bind (list_nth.comp snd $ snd.comp $ snd.comp fst) snd)
private def G (L : list (list (option ℕ))) : option (list (option ℕ)) :=
option.some $
let a := of_nat (ℕ × code) L.length,
k := a.1, c := a.2 in
(list.range k).map (λ n,
k.cases none $ λ k',
nat.partrec.code.rec_on c
(some 0) -- zero
(some (nat.succ n))
(some n.unpair.1)
(some n.unpair.2)
(λ cf cg _ _, do
x ← lup L (k, cf) n,
y ← lup L (k, cg) n,
some (mkpair x y))
(λ cf cg _ _, do
x ← lup L (k, cg) n,
lup L (k, cf) x)
(λ cf cg _ _,
let z := n.unpair.1 in
n.unpair.2.cases
(lup L (k, cf) z)
(λ y, do
i ← lup L (k', c) (mkpair z y),
lup L (k, cg) (mkpair z (mkpair y i))))
(λ cf _,
let z := n.unpair.1, m := n.unpair.2 in do
x ← lup L (k, cf) (mkpair z m),
x.cases
(some m)
(λ _, lup L (k', c) (mkpair z (m+1)))))
private lemma hG : primrec G :=
begin
have a := (primrec.of_nat (ℕ × code)).comp list_length,
have k := fst.comp a,
refine option_some.comp
(list_map (list_range.comp k) (_ : primrec _)),
replace k := k.comp fst, have n := snd,
refine nat_cases k (const none) (_ : primrec _),
have k := k.comp fst, have n := n.comp fst, have k' := snd,
have c := snd.comp (a.comp $ fst.comp fst),
apply rec_prim c
(const (some 0))
(option_some.comp (primrec.succ.comp n))
(option_some.comp (fst.comp $ primrec.unpair.comp n))
(option_some.comp (snd.comp $ primrec.unpair.comp n)),
{ have L := (fst.comp fst).comp fst,
have k := k.comp fst, have n := n.comp fst,
have cf := fst.comp snd,
have cg := (fst.comp snd).comp snd,
exact option_bind
(hlup.comp $ L.pair $ (k.pair cf).pair n)
(option_map ((hlup.comp $
L.pair $ (k.pair cg).pair n).comp fst)
(primrec₂.mkpair.comp (snd.comp fst) snd)) },
{ have L := (fst.comp fst).comp fst,
have k := k.comp fst, have n := n.comp fst,
have cf := fst.comp snd,
have cg := (fst.comp snd).comp snd,
exact option_bind
(hlup.comp $ L.pair $ (k.pair cg).pair n)
(hlup.comp ((L.comp fst).pair $
((k.pair cf).comp fst).pair snd)) },
{ have L := (fst.comp fst).comp fst,
have k := k.comp fst, have n := n.comp fst,
have cf := fst.comp snd,
have cg := (fst.comp snd).comp snd,
have z := fst.comp (primrec.unpair.comp n),
refine nat_cases
(snd.comp (primrec.unpair.comp n))
(hlup.comp $ L.pair $ (k.pair cf).pair z)
(_ : primrec _),
have L := L.comp fst, have z := z.comp fst, have y := snd,
refine option_bind
(hlup.comp $ L.pair $
(((k'.pair c).comp fst).comp fst).pair
(primrec₂.mkpair.comp z y))
(_ : primrec _),
have z := z.comp fst, have y := y.comp fst, have i := snd,
exact hlup.comp ((L.comp fst).pair $
((k.pair cg).comp $ fst.comp fst).pair $
primrec₂.mkpair.comp z $ primrec₂.mkpair.comp y i) },
{ have L := (fst.comp fst).comp fst,
have k := k.comp fst, have n := n.comp fst,
have cf := fst.comp snd,
have z := fst.comp (primrec.unpair.comp n),
have m := snd.comp (primrec.unpair.comp n),
refine option_bind
(hlup.comp $ L.pair $ (k.pair cf).pair (primrec₂.mkpair.comp z m))
(_ : primrec _),
have m := m.comp fst,
exact nat_cases snd (option_some.comp m)
((hlup.comp ((L.comp fst).pair $
((k'.pair c).comp $ fst.comp fst).pair
(primrec₂.mkpair.comp (z.comp fst)
(primrec.succ.comp m)))).comp fst) }
end
private lemma evaln_map (k c n) :
(((list.range k).nth n).map (evaln k c)).bind (λ b, b) = evaln k c n :=
begin
by_cases kn : n < k,
{ simp [list.nth_range kn] },
{ rw list.nth_len_le,
{ cases e : evaln k c n, {refl},
exact kn.elim (evaln_bound e) },
simpa using kn }
end
theorem evaln_prim : primrec (λ (a : (ℕ × code) × ℕ), evaln a.1.1 a.1.2 a.2) :=
have primrec₂ (λ (_:unit) (n : ℕ),
let a := of_nat (ℕ × code) n in
(list.range a.1).map (evaln a.1 a.2)), from
primrec.nat_strong_rec _ (hG.comp snd).to₂ $
λ _ p, begin
simp [G],
rw (_ : (of_nat (ℕ × code) _).snd =
of_nat code p.unpair.2), swap, {simp},
apply list.map_congr (λ n, _),
rw (by simp : list.range p = list.range
(mkpair p.unpair.1 (encode (of_nat code p.unpair.2)))),
generalize : p.unpair.1 = k,
generalize : of_nat code p.unpair.2 = c,
intro nk,
cases k with k', {simp [evaln]},
let k := k'+1, change k'.succ with k,
simp [nat.lt_succ_iff] at nk,
have hg : ∀ {k' c' n},
mkpair k' (encode c') < mkpair k (encode c) →
lup ((list.range (mkpair k (encode c))).map (λ n,
(list.range n.unpair.1).map
(evaln n.unpair.1 (of_nat code n.unpair.2))))
(k', c') n = evaln k' c' n,
{ intros k₁ c₁ n₁ hl,
simp [lup, list.nth_range hl, evaln_map, (>>=)] },
cases c with cf cg cf cg cf cg cf;
simp [evaln, nk, (>>), (>>=), (<$>), (<*>), pure],
{ cases encode_lt_pair cf cg with lf lg,
rw [hg (nat.mkpair_lt_mkpair_right _ lf),
hg (nat.mkpair_lt_mkpair_right _ lg)],
cases evaln k cf n, {refl},
cases evaln k cg n; refl },
{ cases encode_lt_comp cf cg with lf lg,
rw hg (nat.mkpair_lt_mkpair_right _ lg),
cases evaln k cg n, {refl},
simp [hg (nat.mkpair_lt_mkpair_right _ lf)] },
{ cases encode_lt_prec cf cg with lf lg,
rw hg (nat.mkpair_lt_mkpair_right _ lf),
cases n.unpair.2, {refl},
simp,
rw hg (nat.mkpair_lt_mkpair_left _ k'.lt_succ_self),
cases evaln k' _ _, {refl},
simp [hg (nat.mkpair_lt_mkpair_right _ lg)] },
{ have lf := encode_lt_rfind' cf,
rw hg (nat.mkpair_lt_mkpair_right _ lf),
cases evaln k cf n with x, {refl},
simp,
cases x; simp [nat.succ_ne_zero],
rw hg (nat.mkpair_lt_mkpair_left _ k'.lt_succ_self) }
end,
(option_bind (list_nth.comp
(this.comp (const ()) (encode_iff.2 fst)) snd)
snd.to₂).of_eq $ λ ⟨⟨k, c⟩, n⟩, by simp [evaln_map]
end
section
open partrec computable
theorem eval_eq_rfind_opt (c n) :
eval c n = nat.rfind_opt (λ k, evaln k c n) :=
roption.ext $ λ x, begin
refine evaln_complete.trans (nat.rfind_opt_mono _).symm,
intros a m n hl, apply evaln_mono hl,
end
theorem eval_part : partrec₂ eval :=
(rfind_opt (evaln_prim.to_comp.comp
((snd.pair (fst.comp fst)).pair (snd.comp fst))).to₂).of_eq $
λ a, by simp [eval_eq_rfind_opt]
theorem fixed_point
{f : code → code} (hf : computable f) : ∃ c : code, eval (f c) = eval c :=
let g (x y : ℕ) : roption ℕ :=
eval (of_nat code x) x >>= λ b, eval (of_nat code b) y in
have partrec₂ g :=
(eval_part.comp ((computable.of_nat _).comp fst) fst).bind
(eval_part.comp ((computable.of_nat _).comp snd) (snd.comp fst)).to₂,
let ⟨cg, eg⟩ := exists_code.1 this in
have eg' : ∀ a n, eval cg (mkpair a n) = roption.map encode (g a n) :=
by simp [eg],
let F (x : ℕ) : code := f (curry cg x) in
have computable F :=
hf.comp (curry_prim.comp (primrec.const cg) primrec.id).to_comp,
let ⟨cF, eF⟩ := exists_code.1 this in
have eF' : eval cF (encode cF) = roption.some (encode (F (encode cF))),
by simp [eF],
⟨curry cg (encode cF), funext (λ n,
show eval (f (curry cg (encode cF))) n = eval (curry cg (encode cF)) n,
by simp [eg', eF', roption.map_id', g])⟩
theorem fixed_point₂
{f : code → ℕ →. ℕ} (hf : partrec₂ f) : ∃ c : code, eval c = f c :=
let ⟨cf, ef⟩ := exists_code.1 hf in
(fixed_point (curry_prim.comp
(primrec.const cf) primrec.encode).to_comp).imp $
λ c e, funext $ λ n, by simp [e.symm, ef, roption.map_id']
end
end nat.partrec.code
|
f427188db2b6f09f17741f96b8dde2e110bf4012 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/linear_algebra/linear_action.lean | f61cc0a59b17bc200671e31d3c5544666baa8b76 | [
"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 | 3,419 | 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 linear_algebra.basic
/-!
# Linear actions
For modules M and N, we can regard a linear map M →ₗ End N as a "linear action" of M on N.
In this file we introduce the class `linear_action` to make it easier to work with such actions.
## Tags
linear action
-/
universes u v
section linear_action
variables (R : Type u) (M N : Type v)
variables [comm_ring R] [add_comm_group M] [add_comm_group N] [module R M] [module R N]
section prio
set_option default_priority 100 -- see Note [default priority]
/--
A binary operation representing one module acting linearly on another.
-/
class linear_action :=
(act : M → N → N)
(add_act : ∀ (m m' : M) (n : N), act (m + m') n = act m n + act m' n)
(act_add : ∀ (m : M) (n n' : N), act m (n + n') = act m n + act m n')
(act_smul : ∀ (r : R) (m : M) (n : N), act (r • m) n = r • (act m n))
(smul_act : ∀ (r : R) (m : M) (n : N), act m (r • n) = act (r • m) n)
end prio
@[simp] lemma zero_linear_action [linear_action R M N] (n : N) :
linear_action.act R (0 : M) n = 0 :=
begin
let z := linear_action.act R (0 : M) n,
have H : z + z = z + 0 := by { rw ←linear_action.add_act, simp, },
exact add_left_cancel H,
end
@[simp] lemma linear_action_zero [linear_action R M N] (m : M) :
linear_action.act R m (0 : N) = 0 :=
begin
let z := linear_action.act R m (0 : N),
have H : z + z = z + 0 := by { rw ←linear_action.act_add, simp, },
exact add_left_cancel H,
end
@[simp] lemma linear_action_add_act [linear_action R M N] (m m' : M) (n : N) :
linear_action.act R (m + m') n = linear_action.act R m n +
linear_action.act R m' n :=
linear_action.add_act m m' n
@[simp] lemma linear_action_act_add [linear_action R M N] (m : M) (n n' : N) :
linear_action.act R m (n + n') = linear_action.act R m n +
linear_action.act R m n' :=
linear_action.act_add m n n'
@[simp] lemma linear_action_act_smul [linear_action R M N] (r : R) (m : M) (n : N) :
linear_action.act R (r • m) n = r • (linear_action.act R m n) :=
linear_action.act_smul r m n
@[simp] lemma linear_action_smul_act [linear_action R M N] (r : R) (m : M) (n : N) :
linear_action.act R m (r • n) = linear_action.act R (r • m) n :=
linear_action.smul_act r m n
end linear_action
namespace linear_action
variables (R : Type u) (M N : Type v)
variables [comm_ring R] [add_comm_group M] [add_comm_group N] [module R M] [module R N]
/--
A linear map to the endomorphism algebra yields a linear action.
-/
def of_endo_map (α : M →ₗ[R] module.End R N) : linear_action R M N :=
{ act := λ m n, α m n,
add_act := by { intros, rw linear_map.map_add, simp, },
act_add := by { intros, simp, },
act_smul := by { intros, rw linear_map.map_smul, simp, },
smul_act := by { intros, repeat { rw linear_map.map_smul }, simp, } }
/--
A linear action yields a linear map to the endomorphism algebra.
-/
def to_endo_map (α : linear_action R M N) : M →ₗ[R] module.End R N :=
{ to_fun := λ m,
{ to_fun := λ n, linear_action.act R m n,
map_add' := by { intros, simp, },
map_smul' := by { intros, simp, }, },
map_add' := by { intros, ext, simp, },
map_smul' := by { intros, ext, simp, } }
end linear_action
|
de3667cdd6301fce5416536615f23ac29fd59a87 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/algebra/order/module.lean | c8daf52710803c496ab98e21580ce0b6d3ac5328 | [
"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,899 | lean | /-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Yaël Dillies
-/
import algebra.module.pi
import algebra.module.prod
import algebra.order.pi
import algebra.order.smul
import data.set.pointwise
/-!
# Ordered module
In this file we provide lemmas about `ordered_smul` that hold once a module structure is present.
## References
* https://en.wikipedia.org/wiki/Ordered_module
## Tags
ordered module, ordered scalar, ordered smul, ordered action, ordered vector space
-/
open_locale pointwise
variables {k M N : Type*}
namespace order_dual
instance [semiring k] [ordered_add_comm_monoid M] [module k M] : module k Mᵒᵈ :=
{ add_smul := λ r s x, order_dual.rec (add_smul _ _) x,
zero_smul := λ m, order_dual.rec (zero_smul _) m }
end order_dual
section semiring
variables [ordered_semiring k] [ordered_add_comm_group M] [module k M] [ordered_smul k M]
{a b : M} {c : k}
/- can be generalized from `module k M` to `distrib_mul_action_with_zero k M` once it exists.
where `distrib_mul_action_with_zero k M`is the conjunction of `distrib_mul_action k M` and
`smul_with_zero k M`.-/
lemma smul_neg_iff_of_pos (hc : 0 < c) :
c • a < 0 ↔ a < 0 :=
begin
rw [←neg_neg a, smul_neg, neg_neg_iff_pos, neg_neg_iff_pos],
exact smul_pos_iff_of_pos hc,
end
end semiring
section ring
variables [ordered_ring k] [ordered_add_comm_group M] [module k M] [ordered_smul k M]
{a b : M} {c : k}
lemma smul_lt_smul_of_neg (h : a < b) (hc : c < 0) :
c • b < c • a :=
begin
rw [←neg_neg c, neg_smul, neg_smul (-c), neg_lt_neg_iff],
exact smul_lt_smul_of_pos h (neg_pos_of_neg hc),
end
lemma smul_le_smul_of_nonpos (h : a ≤ b) (hc : c ≤ 0) :
c • b ≤ c • a :=
begin
rw [←neg_neg c, neg_smul, neg_smul (-c), neg_le_neg_iff],
exact smul_le_smul_of_nonneg h (neg_nonneg_of_nonpos hc),
end
lemma eq_of_smul_eq_smul_of_neg_of_le (hab : c • a = c • b) (hc : c < 0) (h : a ≤ b) :
a = b :=
begin
rw [←neg_neg c, neg_smul, neg_smul (-c), neg_inj] at hab,
exact eq_of_smul_eq_smul_of_pos_of_le hab (neg_pos_of_neg hc) h,
end
lemma lt_of_smul_lt_smul_of_nonpos (h : c • a < c • b) (hc : c ≤ 0) :
b < a :=
begin
rw [←neg_neg c, neg_smul, neg_smul (-c), neg_lt_neg_iff] at h,
exact lt_of_smul_lt_smul_of_nonneg h (neg_nonneg_of_nonpos hc),
end
lemma smul_lt_smul_iff_of_neg (hc : c < 0) :
c • a < c • b ↔ b < a :=
begin
rw [←neg_neg c, neg_smul, neg_smul (-c), neg_lt_neg_iff],
exact smul_lt_smul_iff_of_pos (neg_pos_of_neg hc),
end
lemma smul_neg_iff_of_neg (hc : c < 0) :
c • a < 0 ↔ 0 < a :=
begin
rw [←neg_neg c, neg_smul, neg_neg_iff_pos],
exact smul_pos_iff_of_pos (neg_pos_of_neg hc),
end
lemma smul_pos_iff_of_neg (hc : c < 0) :
0 < c • a ↔ a < 0 :=
begin
rw [←neg_neg c, neg_smul, neg_pos],
exact smul_neg_iff_of_pos (neg_pos_of_neg hc),
end
lemma smul_nonpos_of_nonpos_of_nonneg (hc : c ≤ 0) (ha : 0 ≤ a) : c • a ≤ 0 :=
calc
c • a ≤ c • 0 : smul_le_smul_of_nonpos ha hc
... = 0 : smul_zero' M c
lemma smul_nonneg_of_nonpos_of_nonpos (hc : c ≤ 0) (ha : a ≤ 0) : 0 ≤ c • a :=
@smul_nonpos_of_nonpos_of_nonneg k Mᵒᵈ _ _ _ _ _ _ hc ha
alias smul_pos_iff_of_neg ↔ _ smul_pos_of_neg_of_neg
alias smul_neg_iff_of_pos ↔ _ smul_neg_of_pos_of_neg
alias smul_neg_iff_of_neg ↔ _ smul_neg_of_neg_of_pos
lemma antitone_smul_left (hc : c ≤ 0) : antitone (has_smul.smul c : M → M) :=
λ a b h, smul_le_smul_of_nonpos h hc
lemma strict_anti_smul_left (hc : c < 0) : strict_anti (has_smul.smul c : M → M) :=
λ a b h, smul_lt_smul_of_neg h hc
/-- Binary **rearrangement inequality**. -/
lemma smul_add_smul_le_smul_add_smul [contravariant_class M M (+) (≤)] {a b : k} {c d : M}
(hab : a ≤ b) (hcd : c ≤ d) :
a • d + b • c ≤ a • c + b • d :=
begin
obtain ⟨b, rfl⟩ := exists_add_of_le hab,
obtain ⟨d, rfl⟩ := exists_add_of_le hcd,
rw [smul_add, add_right_comm, smul_add, ←add_assoc, add_smul _ _ d],
rw le_add_iff_nonneg_right at hab hcd,
exact add_le_add_left (le_add_of_nonneg_right $ smul_nonneg hab hcd) _,
end
/-- Binary **rearrangement inequality**. -/
lemma smul_add_smul_le_smul_add_smul' [contravariant_class M M (+) (≤)] {a b : k} {c d : M}
(hba : b ≤ a) (hdc : d ≤ c) : a • d + b • c ≤ a • c + b • d :=
by { rw [add_comm (a • d), add_comm (a • c)], exact smul_add_smul_le_smul_add_smul hba hdc }
/-- Binary strict **rearrangement inequality**. -/
lemma smul_add_smul_lt_smul_add_smul [covariant_class M M (+) (<)] [contravariant_class M M (+) (<)]
{a b : k} {c d : M} (hab : a < b) (hcd : c < d) : a • d + b • c < a • c + b • d :=
begin
obtain ⟨b, rfl⟩ := exists_add_of_le hab.le,
obtain ⟨d, rfl⟩ := exists_add_of_le hcd.le,
rw [smul_add, add_right_comm, smul_add, ←add_assoc, add_smul _ _ d],
rw lt_add_iff_pos_right at hab hcd,
exact add_lt_add_left (lt_add_of_pos_right _ $ smul_pos hab hcd) _,
end
/-- Binary strict **rearrangement inequality**. -/
lemma smul_add_smul_lt_smul_add_smul' [covariant_class M M (+) (<)]
[contravariant_class M M (+) (<)] {a b : k} {c d : M} (hba : b < a) (hdc : d < c) :
a • d + b • c < a • c + b • d :=
by { rw [add_comm (a • d), add_comm (a • c)], exact smul_add_smul_lt_smul_add_smul hba hdc }
end ring
section field
variables [linear_ordered_field k] [ordered_add_comm_group M] [module k M] [ordered_smul k M]
{a b : M} {c : k}
lemma smul_le_smul_iff_of_neg (hc : c < 0) : c • a ≤ c • b ↔ b ≤ a :=
begin
rw [←neg_neg c, neg_smul, neg_smul (-c), neg_le_neg_iff],
exact smul_le_smul_iff_of_pos (neg_pos_of_neg hc),
end
lemma smul_lt_iff_of_neg (hc : c < 0) : c • a < b ↔ c⁻¹ • b < a :=
begin
rw [←neg_neg c, ←neg_neg a, neg_smul_neg, inv_neg, neg_smul _ b, neg_lt_neg_iff],
exact smul_lt_iff_of_pos (neg_pos_of_neg hc),
end
lemma lt_smul_iff_of_neg (hc : c < 0) : a < c • b ↔ b < c⁻¹ • a :=
begin
rw [←neg_neg c, ←neg_neg b, neg_smul_neg, inv_neg, neg_smul _ a, neg_lt_neg_iff],
exact lt_smul_iff_of_pos (neg_pos_of_neg hc),
end
variables (M)
/-- Left scalar multiplication as an order isomorphism. -/
@[simps] def order_iso.smul_left_dual {c : k} (hc : c < 0) : M ≃o Mᵒᵈ :=
{ to_fun := λ b, order_dual.to_dual (c • b),
inv_fun := λ b, c⁻¹ • (order_dual.of_dual b),
left_inv := inv_smul_smul₀ hc.ne,
right_inv := smul_inv_smul₀ hc.ne,
map_rel_iff' := λ b₁ b₂, smul_le_smul_iff_of_neg hc }
variables {M} [ordered_add_comm_group N] [module k N] [ordered_smul k N]
-- TODO: solve `prod.has_lt` and `prod.has_le` misalignment issue
instance prod.ordered_smul : ordered_smul k (M × N) :=
ordered_smul.mk' $ λ (v u : M × N) (c : k) h hc,
⟨smul_le_smul_of_nonneg h.1.1 hc.le, smul_le_smul_of_nonneg h.1.2 hc.le⟩
instance pi.smul_with_zero'' {ι : Type*} {M : ι → Type*} [Π i, ordered_add_comm_group (M i)]
[Π i, mul_action_with_zero k (M i)] :
smul_with_zero k (Π i : ι, M i) := by apply_instance
instance pi.ordered_smul {ι : Type*} {M : ι → Type*} [Π i, ordered_add_comm_group (M i)]
[Π i, mul_action_with_zero k (M i)] [∀ i, ordered_smul k (M i)] :
ordered_smul k (Π i : ι, M i) :=
begin
refine (ordered_smul.mk' $ λ v u c h hc i, _),
change c • v i ≤ c • u i,
exact smul_le_smul_of_nonneg (h.le i) hc.le,
end
-- Sometimes Lean fails to apply the dependent version to non-dependent functions,
-- so we define another instance
instance pi.ordered_smul' {ι : Type*} {M : Type*} [ordered_add_comm_group M]
[mul_action_with_zero k M] [ordered_smul k M] :
ordered_smul k (ι → M) :=
pi.ordered_smul
end field
/-! ### Upper/lower bounds -/
section ordered_semiring
variables [ordered_semiring k] [ordered_add_comm_monoid M] [smul_with_zero k M] [ordered_smul k M]
{s : set M} {c : k}
lemma smul_lower_bounds_subset_lower_bounds_smul (hc : 0 ≤ c) :
c • lower_bounds s ⊆ lower_bounds (c • s) :=
(monotone_smul_left hc).image_lower_bounds_subset_lower_bounds_image
lemma smul_upper_bounds_subset_upper_bounds_smul (hc : 0 ≤ c) :
c • upper_bounds s ⊆ upper_bounds (c • s) :=
(monotone_smul_left hc).image_upper_bounds_subset_upper_bounds_image
lemma bdd_below.smul_of_nonneg (hs : bdd_below s) (hc : 0 ≤ c) : bdd_below (c • s) :=
(monotone_smul_left hc).map_bdd_below hs
lemma bdd_above.smul_of_nonneg (hs : bdd_above s) (hc : 0 ≤ c) : bdd_above (c • s) :=
(monotone_smul_left hc).map_bdd_above hs
end ordered_semiring
section ordered_ring
variables [ordered_ring k] [ordered_add_comm_group M] [module k M] [ordered_smul k M]
{s : set M} {c : k}
lemma smul_lower_bounds_subset_upper_bounds_smul (hc : c ≤ 0) :
c • lower_bounds s ⊆ upper_bounds (c • s) :=
(antitone_smul_left hc).image_lower_bounds_subset_upper_bounds_image
lemma smul_upper_bounds_subset_lower_bounds_smul (hc : c ≤ 0) :
c • upper_bounds s ⊆ lower_bounds (c • s) :=
(antitone_smul_left hc).image_upper_bounds_subset_lower_bounds_image
lemma bdd_below.smul_of_nonpos (hc : c ≤ 0) (hs : bdd_below s) : bdd_above (c • s) :=
(antitone_smul_left hc).map_bdd_below hs
lemma bdd_above.smul_of_nonpos (hc : c ≤ 0) (hs : bdd_above s) : bdd_below (c • s) :=
(antitone_smul_left hc).map_bdd_above hs
end ordered_ring
section linear_ordered_field
variables [linear_ordered_field k] [ordered_add_comm_group M]
section mul_action_with_zero
variables [mul_action_with_zero k M] [ordered_smul k M] {s t : set M} {c : k}
@[simp] lemma lower_bounds_smul_of_pos (hc : 0 < c) : lower_bounds (c • s) = c • lower_bounds s :=
(order_iso.smul_left _ hc).lower_bounds_image
@[simp] lemma upper_bounds_smul_of_pos (hc : 0 < c) : upper_bounds (c • s) = c • upper_bounds s :=
(order_iso.smul_left _ hc).upper_bounds_image
@[simp] lemma bdd_below_smul_iff_of_pos (hc : 0 < c) : bdd_below (c • s) ↔ bdd_below s :=
(order_iso.smul_left _ hc).bdd_below_image
@[simp] lemma bdd_above_smul_iff_of_pos (hc : 0 < c) : bdd_above (c • s) ↔ bdd_above s :=
(order_iso.smul_left _ hc).bdd_above_image
end mul_action_with_zero
section module
variables [module k M] [ordered_smul k M] {s t : set M} {c : k}
@[simp] lemma lower_bounds_smul_of_neg (hc : c < 0) : lower_bounds (c • s) = c • upper_bounds s :=
(order_iso.smul_left_dual M hc).upper_bounds_image
@[simp] lemma upper_bounds_smul_of_neg (hc : c < 0) : upper_bounds (c • s) = c • lower_bounds s :=
(order_iso.smul_left_dual M hc).lower_bounds_image
@[simp] lemma bdd_below_smul_iff_of_neg (hc : c < 0) : bdd_below (c • s) ↔ bdd_above s :=
(order_iso.smul_left_dual M hc).bdd_above_image
@[simp] lemma bdd_above_smul_iff_of_neg (hc : c < 0) : bdd_above (c • s) ↔ bdd_below s :=
(order_iso.smul_left_dual M hc).bdd_below_image
end module
end linear_ordered_field
|
405353488dbcda12dfd1d8542e40f5afd61c5490 | f5f7e6fae601a5fe3cac7cc3ed353ed781d62419 | /src/category/monad/cont.lean | a27ed1792ee8f16c7bccf26925a55562bc54ebd5 | [
"Apache-2.0"
] | permissive | EdAyers/mathlib | 9ecfb2f14bd6caad748b64c9c131befbff0fb4e0 | ca5d4c1f16f9c451cf7170b10105d0051db79e1b | refs/heads/master | 1,626,189,395,845 | 1,555,284,396,000 | 1,555,284,396,000 | 144,004,030 | 0 | 0 | Apache-2.0 | 1,533,727,664,000 | 1,533,727,663,000 | null | UTF-8 | Lean | false | false | 2,834 | lean | /-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
Monad encapsulating continuation passing programming style, similar to
Haskell's `Cont`, `ContT` and `MonadCont`:
http://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Cont.html
-/
import tactic.interactive
universes u v w
structure monad_cont.label (α : Type w) (m : Type u → Type v) (β : Type u) :=
(apply : α → m β)
def monad_cont.goto {α β} {m : Type u → Type v} (f : monad_cont.label α m β) (x : α) := f.apply x
class monad_cont (m : Type u → Type v)
extends monad m :=
(call_cc : Π {α β}, ((monad_cont.label α m β) → m α) → m α)
open monad_cont
class is_lawful_monad_cont (m : Type u → Type v) [monad_cont m]
extends is_lawful_monad m :=
(call_cc_bind_right {α ω γ} (cmd : m α) (next : (label ω m γ) → α → m ω) :
call_cc (λ f, cmd >>= next f) = cmd >>= λ x, call_cc (λ f, next f x))
(call_cc_bind_left {α} (β) (x : α) (dead : label α m β → β → m α) :
call_cc (λ f : label α m β, goto f x >>= dead f) = pure x)
(call_cc_dummy {α β} (dummy : m α) :
call_cc (λ f : label α m β, dummy) = dummy)
export is_lawful_monad_cont
def cont_t (r : Type u) (m : Type u → Type v) (α : Type w) := (α → m r) → m r
namespace cont_t
export monad_cont (label goto)
variables {r : Type u} {m : Type u → Type v} {α β γ ω : Type w}
def run : cont_t r m α → (α → m r) → m r := id
def map (f : m r → m r) (x : cont_t r m α) : cont_t r m α := f ∘ x
lemma run_cont_t_map_cont_t (f : m r → m r) (x : cont_t r m α) :
run (map f x) = f ∘ run x := rfl
def with_cont_t (f : (β → m r) → α → m r) (x : cont_t r m α) : cont_t r m β :=
λ g, x $ f g
lemma run_with_cont_t (f : (β → m r) → α → m r) (x : cont_t r m α) :
run (with_cont_t f x) = run x ∘ f := rfl
instance : monad (cont_t r m) :=
{ pure := λ α x f, f x,
bind := λ α β x f g, x $ λ i, f i g }
instance : is_lawful_monad (cont_t r m) :=
{ id_map := by { intros, refl },
pure_bind := by { intros, ext, refl },
bind_assoc := by { intros, ext, refl } }
instance [monad m] : has_monad_lift m (cont_t r m) :=
{ monad_lift := λ a x f, x >>= f }
lemma monad_lift_bind [monad m] [is_lawful_monad m] {α β} (x : m α) (f : α → m β) :
(monad_lift (x >>= f) : cont_t r m β) = monad_lift x >>= monad_lift ∘ f :=
by { ext, simp only [monad_lift,has_monad_lift.monad_lift,(∘),(>>=),bind_assoc,id.def] }
instance : monad_cont (cont_t r m) :=
{ call_cc := λ α β f g, f ⟨λ x h, g x⟩ g }
instance : is_lawful_monad_cont (cont_t r m) :=
{ call_cc_bind_right := by intros; ext; refl,
call_cc_bind_left := by intros; ext; refl,
call_cc_dummy := by intros; ext; refl }
end cont_t
|
d23abf93752f59dc9ecedfad3f8ef2d8d2fe7eba | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/data/real/sqrt.lean | 85c8c7bb8d5842dd340c7cc574a3aa43a03ed5f6 | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,359 | lean | /-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Yury Kudryashov
-/
import topology.instances.nnreal
/-!
# Square root of a real number
In this file we define
* `nnreal.sqrt` to be the square root of a nonnegative real number.
* `real.sqrt` to be the square root of a real number, defined to be zero on negative numbers.
Then we prove some basic properties of these functions.
## Implementation notes
We define `nnreal.sqrt` as the noncomputable inverse to the function `x ↦ x * x`. We use general
theory of inverses of strictly monotone functions to prove that `nnreal.sqrt x` exists. As a side
effect, `nnreal.sqrt` is a bundled `order_iso`, so for `nnreal` numbers we get continuity as well as
theorems like `sqrt x ≤ y ↔ x * x ≤ y` for free.
Then we define `real.sqrt x` to be `nnreal.sqrt (real.to_nnreal x)`. We also define a Cauchy
sequence `real.sqrt_aux (f : cau_seq ℚ abs)` which converges to `sqrt (mk f)` but do not prove (yet)
that this sequence actually converges to `sqrt (mk f)`.
## Tags
square root
-/
open set filter
open_locale filter nnreal topological_space
namespace nnreal
variables {x y : ℝ≥0}
/-- Square root of a nonnegative real number. -/
@[pp_nodot] noncomputable def sqrt : ℝ≥0 ≃o ℝ≥0 :=
order_iso.symm $ strict_mono.order_iso_of_surjective (λ x, x * x)
(λ x y h, mul_self_lt_mul_self x.2 h) $
(continuous_id.mul continuous_id).surjective tendsto_mul_self_at_top $
by simp [order_bot.at_bot_eq]
lemma sqrt_le_sqrt_iff : sqrt x ≤ sqrt y ↔ x ≤ y :=
sqrt.le_iff_le
lemma sqrt_lt_sqrt_iff : sqrt x < sqrt y ↔ x < y :=
sqrt.lt_iff_lt
lemma sqrt_eq_iff_sq_eq : sqrt x = y ↔ y * y = x :=
sqrt.to_equiv.apply_eq_iff_eq_symm_apply.trans eq_comm
lemma sqrt_le_iff : sqrt x ≤ y ↔ x ≤ y * y :=
sqrt.to_galois_connection _ _
lemma le_sqrt_iff : x ≤ sqrt y ↔ x * x ≤ y :=
(sqrt.symm.to_galois_connection _ _).symm
@[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 :=
sqrt_eq_iff_sq_eq.trans $ by rw [eq_comm, zero_mul]
@[simp] lemma sqrt_zero : sqrt 0 = 0 := sqrt_eq_zero.2 rfl
@[simp] lemma sqrt_one : sqrt 1 = 1 := sqrt_eq_iff_sq_eq.2 $ mul_one 1
@[simp] lemma mul_self_sqrt (x : ℝ≥0) : sqrt x * sqrt x = x :=
sqrt.symm_apply_apply x
@[simp] lemma sqrt_mul_self (x : ℝ≥0) : sqrt (x * x) = x := sqrt.apply_symm_apply x
@[simp] lemma sq_sqrt (x : ℝ≥0) : (sqrt x)^2 = x :=
by rw [sq, mul_self_sqrt x]
@[simp] lemma sqrt_sq (x : ℝ≥0) : sqrt (x^2) = x :=
by rw [sq, sqrt_mul_self x]
lemma sqrt_mul (x y : ℝ≥0) : sqrt (x * y) = sqrt x * sqrt y :=
by rw [sqrt_eq_iff_sq_eq, mul_mul_mul_comm, mul_self_sqrt, mul_self_sqrt]
/-- `nnreal.sqrt` as a `monoid_with_zero_hom`. -/
noncomputable def sqrt_hom : monoid_with_zero_hom ℝ≥0 ℝ≥0 := ⟨sqrt, sqrt_zero, sqrt_one, sqrt_mul⟩
lemma sqrt_inv (x : ℝ≥0) : sqrt (x⁻¹) = (sqrt x)⁻¹ := sqrt_hom.map_inv' x
lemma sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y := sqrt_hom.map_div x y
lemma continuous_sqrt : continuous sqrt := sqrt.continuous
end nnreal
namespace real
/-- An auxiliary sequence of rational numbers that converges to `real.sqrt (mk f)`.
Currently this sequence is not used in `mathlib`. -/
def sqrt_aux (f : cau_seq ℚ abs) : ℕ → ℚ
| 0 := rat.mk_nat (f 0).num.to_nat.sqrt (f 0).denom.sqrt
| (n + 1) := let s := sqrt_aux n in max 0 $ (s + f (n+1) / s) / 2
theorem sqrt_aux_nonneg (f : cau_seq ℚ abs) : ∀ i : ℕ, 0 ≤ sqrt_aux f i
| 0 := by rw [sqrt_aux, rat.mk_nat_eq, rat.mk_eq_div];
apply div_nonneg; exact int.cast_nonneg.2 (int.of_nat_nonneg _)
| (n + 1) := le_max_left _ _
/- TODO(Mario): finish the proof
theorem sqrt_aux_converges (f : cau_seq ℚ abs) : ∃ h x, 0 ≤ x ∧ x * x = max 0 (mk f) ∧
mk ⟨sqrt_aux f, h⟩ = x :=
begin
rcases sqrt_exists (le_max_left 0 (mk f)) with ⟨x, x0, hx⟩,
suffices : ∃ h, mk ⟨sqrt_aux f, h⟩ = x,
{ exact this.imp (λ h e, ⟨x, x0, hx, e⟩) },
apply of_near,
suffices : ∃ δ > 0, ∀ i, abs (↑(sqrt_aux f i) - x) < δ / 2 ^ i,
{ rcases this with ⟨δ, δ0, hδ⟩,
intros }
end -/
/-- The square root of a real number. This returns 0 for negative inputs. -/
@[pp_nodot] noncomputable def sqrt (x : ℝ) : ℝ :=
nnreal.sqrt (real.to_nnreal x)
/-quotient.lift_on x
(λ f, mk ⟨sqrt_aux f, (sqrt_aux_converges f).fst⟩)
(λ f g e, begin
rcases sqrt_aux_converges f with ⟨hf, x, x0, xf, xs⟩,
rcases sqrt_aux_converges g with ⟨hg, y, y0, yg, ys⟩,
refine xs.trans (eq.trans _ ys.symm),
rw [← @mul_self_inj_of_nonneg ℝ _ x y x0 y0, xf, yg],
congr' 1, exact quotient.sound e
end)-/
variables {x y : ℝ}
@[simp, norm_cast] lemma coe_sqrt {x : ℝ≥0} : (nnreal.sqrt x : ℝ) = real.sqrt x :=
by rw [real.sqrt, real.to_nnreal_coe]
@[continuity]
lemma continuous_sqrt : continuous sqrt :=
nnreal.continuous_coe.comp $ nnreal.sqrt.continuous.comp nnreal.continuous_of_real
theorem sqrt_eq_zero_of_nonpos (h : x ≤ 0) : sqrt x = 0 :=
by simp [sqrt, real.to_nnreal_eq_zero.2 h]
theorem sqrt_nonneg (x : ℝ) : 0 ≤ sqrt x := nnreal.coe_nonneg _
@[simp] theorem mul_self_sqrt (h : 0 ≤ x) : sqrt x * sqrt x = x :=
by rw [sqrt, ← nnreal.coe_mul, nnreal.mul_self_sqrt, real.coe_to_nnreal _ h]
@[simp] theorem sqrt_mul_self (h : 0 ≤ x) : sqrt (x * x) = x :=
(mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _))
theorem sqrt_eq_iff_mul_self_eq (hx : 0 ≤ x) (hy : 0 ≤ y) :
sqrt x = y ↔ y * y = x :=
⟨λ h, by rw [← h, mul_self_sqrt hx], λ h, by rw [← h, sqrt_mul_self hy]⟩
@[simp] theorem sq_sqrt (h : 0 ≤ x) : (sqrt x)^2 = x :=
by rw [sq, mul_self_sqrt h]
@[simp] theorem sqrt_sq (h : 0 ≤ x) : sqrt (x ^ 2) = x :=
by rw [sq, sqrt_mul_self h]
theorem sqrt_eq_iff_sq_eq (hx : 0 ≤ x) (hy : 0 ≤ y) :
sqrt x = y ↔ y ^ 2 = x :=
by rw [sq, sqrt_eq_iff_mul_self_eq hx hy]
theorem sqrt_mul_self_eq_abs (x : ℝ) : sqrt (x * x) = abs x :=
by rw [← abs_mul_abs_self x, sqrt_mul_self (abs_nonneg _)]
theorem sqrt_sq_eq_abs (x : ℝ) : sqrt (x ^ 2) = abs x :=
by rw [sq, sqrt_mul_self_eq_abs]
@[simp] theorem sqrt_zero : sqrt 0 = 0 := by simp [sqrt]
@[simp] theorem sqrt_one : sqrt 1 = 1 := by simp [sqrt]
@[simp] theorem sqrt_le_sqrt_iff (hy : 0 ≤ y) : sqrt x ≤ sqrt y ↔ x ≤ y :=
by rw [sqrt, sqrt, nnreal.coe_le_coe, nnreal.sqrt_le_sqrt_iff, real.to_nnreal_le_to_nnreal_iff hy]
@[simp] theorem sqrt_lt_sqrt_iff (hx : 0 ≤ x) : sqrt x < sqrt y ↔ x < y :=
lt_iff_lt_of_le_iff_le (sqrt_le_sqrt_iff hx)
theorem sqrt_lt_sqrt_iff_of_pos (hy : 0 < y) : sqrt x < sqrt y ↔ x < y :=
by rw [sqrt, sqrt, nnreal.coe_lt_coe, nnreal.sqrt_lt_sqrt_iff, to_nnreal_lt_to_nnreal_iff hy]
theorem sqrt_le_sqrt (h : x ≤ y) : sqrt x ≤ sqrt y :=
by { rw [sqrt, sqrt, nnreal.coe_le_coe, nnreal.sqrt_le_sqrt_iff], exact to_nnreal_le_to_nnreal h }
theorem sqrt_lt_sqrt (hx : 0 ≤ x) (h : x < y) : sqrt x < sqrt y :=
(sqrt_lt_sqrt_iff hx).2 h
theorem sqrt_le_left (hy : 0 ≤ y) : sqrt x ≤ y ↔ x ≤ y ^ 2 :=
by rw [sqrt, ← real.le_to_nnreal_iff_coe_le hy, nnreal.sqrt_le_iff, ← real.to_nnreal_mul hy,
real.to_nnreal_le_to_nnreal_iff (mul_self_nonneg y), sq]
theorem sqrt_le_iff : sqrt x ≤ y ↔ 0 ≤ y ∧ x ≤ y ^ 2 :=
begin
rw [← and_iff_right_of_imp (λ h, (sqrt_nonneg x).trans h), and.congr_right_iff],
exact sqrt_le_left
end
/- note: if you want to conclude `x ≤ sqrt y`, then use `le_sqrt_of_sq_le`.
if you have `x > 0`, consider using `le_sqrt'` -/
theorem le_sqrt (hx : 0 ≤ x) (hy : 0 ≤ y) : x ≤ sqrt y ↔ x ^ 2 ≤ y :=
by rw [mul_self_le_mul_self_iff hx (sqrt_nonneg _), sq, mul_self_sqrt hy]
theorem le_sqrt' (hx : 0 < x) : x ≤ sqrt y ↔ x ^ 2 ≤ y :=
by { rw [sqrt, ← nnreal.coe_mk x hx.le, nnreal.coe_le_coe, nnreal.le_sqrt_iff,
real.le_to_nnreal_iff_coe_le', sq, nnreal.coe_mul], exact mul_pos hx hx }
theorem abs_le_sqrt (h : x^2 ≤ y) : abs x ≤ sqrt y :=
by rw ← sqrt_sq_eq_abs; exact sqrt_le_sqrt h
theorem sq_le (h : 0 ≤ y) : x^2 ≤ y ↔ -sqrt y ≤ x ∧ x ≤ sqrt y :=
begin
split,
{ simpa only [abs_le] using abs_le_sqrt },
{ rw [← abs_le, ← sq_abs],
exact (le_sqrt (abs_nonneg x) h).mp },
end
theorem neg_sqrt_le_of_sq_le (h : x^2 ≤ y) : -sqrt y ≤ x :=
((sq_le ((sq_nonneg x).trans h)).mp h).1
theorem le_sqrt_of_sq_le (h : x^2 ≤ y) : x ≤ sqrt y :=
((sq_le ((sq_nonneg x).trans h)).mp h).2
@[simp] theorem sqrt_inj (hx : 0 ≤ x) (hy : 0 ≤ y) : sqrt x = sqrt y ↔ x = y :=
by simp [le_antisymm_iff, hx, hy]
@[simp] theorem sqrt_eq_zero (h : 0 ≤ x) : sqrt x = 0 ↔ x = 0 :=
by simpa using sqrt_inj h (le_refl _)
theorem sqrt_eq_zero' : sqrt x = 0 ↔ x ≤ 0 :=
by rw [sqrt, nnreal.coe_eq_zero, nnreal.sqrt_eq_zero, real.to_nnreal_eq_zero]
theorem sqrt_ne_zero (h : 0 ≤ x) : sqrt x ≠ 0 ↔ x ≠ 0 :=
by rw [not_iff_not, sqrt_eq_zero h]
theorem sqrt_ne_zero' : sqrt x ≠ 0 ↔ 0 < x :=
by rw [← not_le, not_iff_not, sqrt_eq_zero']
@[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le (iff.trans
(by simp [le_antisymm_iff, sqrt_nonneg]) sqrt_eq_zero')
@[simp] theorem sqrt_mul (hx : 0 ≤ x) (y : ℝ) : sqrt (x * y) = sqrt x * sqrt y :=
by simp_rw [sqrt, ← nnreal.coe_mul, nnreal.coe_eq, real.to_nnreal_mul hx, nnreal.sqrt_mul]
@[simp] theorem sqrt_mul' (x) {y : ℝ} (hy : 0 ≤ y) : sqrt (x * y) = sqrt x * sqrt y :=
by rw [mul_comm, sqrt_mul hy, mul_comm]
@[simp] theorem sqrt_inv (x : ℝ) : sqrt x⁻¹ = (sqrt x)⁻¹ :=
by rw [sqrt, real.to_nnreal_inv, nnreal.sqrt_inv, nnreal.coe_inv, sqrt]
@[simp] theorem sqrt_div (hx : 0 ≤ x) (y : ℝ) : sqrt (x / y) = sqrt x / sqrt y :=
by rw [division_def, sqrt_mul hx, sqrt_inv, division_def]
@[simp] theorem div_sqrt : x / sqrt x = sqrt x :=
begin
cases le_or_lt x 0,
{ rw [sqrt_eq_zero'.mpr h, div_zero] },
{ rw [div_eq_iff (sqrt_ne_zero'.mpr h), mul_self_sqrt h.le] },
end
theorem lt_sqrt (hx : 0 ≤ x) (hy : 0 ≤ y) : x < sqrt y ↔ x ^ 2 < y :=
by rw [mul_self_lt_mul_self_iff hx (sqrt_nonneg y), sq, mul_self_sqrt hy]
theorem sq_lt : x^2 < y ↔ -sqrt y < x ∧ x < sqrt y :=
begin
split,
{ simpa only [← sqrt_lt_sqrt_iff (sq_nonneg x), sqrt_sq_eq_abs] using abs_lt.mp },
{ rw [← abs_lt, ← sq_abs],
exact λ h, (lt_sqrt (abs_nonneg x) (sqrt_pos.mp (lt_of_le_of_lt (abs_nonneg x) h)).le).mp h },
end
theorem neg_sqrt_lt_of_sq_lt (h : x^2 < y) : -sqrt y < x := (sq_lt.mp h).1
theorem lt_sqrt_of_sq_lt (h : x^2 < y) : x < sqrt y := (sq_lt.mp h).2
end real
open real
variables {α : Type*}
lemma filter.tendsto.sqrt {f : α → ℝ} {l : filter α} {x : ℝ} (h : tendsto f l (𝓝 x)) :
tendsto (λ x, sqrt (f x)) l (𝓝 (sqrt x)) :=
(continuous_sqrt.tendsto _).comp h
variables [topological_space α] {f : α → ℝ} {s : set α} {x : α}
lemma continuous_within_at.sqrt (h : continuous_within_at f s x) :
continuous_within_at (λ x, sqrt (f x)) s x :=
h.sqrt
lemma continuous_at.sqrt (h : continuous_at f x) : continuous_at (λ x, sqrt (f x)) x := h.sqrt
lemma continuous_on.sqrt (h : continuous_on f s) : continuous_on (λ x, sqrt (f x)) s :=
λ x hx, (h x hx).sqrt
@[continuity]
lemma continuous.sqrt (h : continuous f) : continuous (λ x, sqrt (f x)) := continuous_sqrt.comp h
|
21da38869e1cebfc2987342630d3bf791f97d991 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/control/traversable/equiv_auto.lean | 35731dde347108818b33050f7c43623bdac298a5 | [] | 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,421 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
Transferring `traversable` instances using isomorphisms.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.equiv.basic
import Mathlib.control.traversable.lemmas
import Mathlib.PostPort
universes u
namespace Mathlib
namespace equiv
/-- Given a functor `t`, a function `t' : Type u → Type u`, and
equivalences `t α ≃ t' α` for all `α`, then every function `α → β` can
be mapped to a function `t' α → t' β` functorially (see
`equiv.functor`). -/
protected def map {t : Type u → Type u} {t' : Type u → Type u} (eqv : (α : Type u) → t α ≃ t' α)
[Functor t] {α : Type u} {β : Type u} (f : α → β) (x : t' α) : t' β :=
coe_fn (eqv β) (f <$> coe_fn (equiv.symm (eqv α)) x)
/-- The function `equiv.map` transfers the functoriality of `t` to
`t'` using the equivalences `eqv`. -/
protected def functor {t : Type u → Type u} {t' : Type u → Type u} (eqv : (α : Type u) → t α ≃ t' α)
[Functor t] : Functor t' :=
{ map := equiv.map eqv, mapConst := fun (α β : Type u) => equiv.map eqv ∘ function.const β }
protected theorem id_map {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [Functor t] [is_lawful_functor t] {α : Type u} (x : t' α) :
equiv.map eqv id x = x :=
sorry
protected theorem comp_map {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [Functor t] [is_lawful_functor t] {α : Type u} {β : Type u}
{γ : Type u} (g : α → β) (h : β → γ) (x : t' α) :
equiv.map eqv (h ∘ g) x = equiv.map eqv h (equiv.map eqv g x) :=
sorry
protected theorem is_lawful_functor {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [Functor t] [is_lawful_functor t] : is_lawful_functor t' :=
is_lawful_functor.mk (equiv.id_map eqv) (equiv.comp_map eqv)
protected theorem is_lawful_functor' {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [Functor t] [is_lawful_functor t] [F : Functor t']
(h₀ : ∀ {α β : Type u} (f : α → β), Functor.map f = equiv.map eqv f)
(h₁ :
∀ {α β : Type u} (f : β),
Functor.mapConst f = function.comp (equiv.map eqv) (function.const α) f) :
is_lawful_functor t' :=
sorry
/-- Like `equiv.map`, a function `t' : Type u → Type u` can be given
the structure of a traversable functor using a traversable functor
`t'` and equivalences `t α ≃ t' α` for all α. See `equiv.traversable`. -/
protected def traverse {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] {m : Type u → Type u} [Applicative m]
{α : Type u} {β : Type u} (f : α → m β) (x : t' α) : m (t' β) :=
⇑(eqv β) <$> traverse f (coe_fn (equiv.symm (eqv α)) x)
/-- The function `equiv.tranverse` transfers a traversable functor
instance across the equivalences `eqv`. -/
protected def traversable {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] : traversable t' :=
traversable.mk (equiv.traverse eqv)
protected theorem id_traverse {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] [is_lawful_traversable t] {α : Type u}
(x : t' α) : equiv.traverse eqv id.mk x = x :=
sorry
protected theorem traverse_eq_map_id {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] [is_lawful_traversable t] {α : Type u}
{β : Type u} (f : α → β) (x : t' α) :
equiv.traverse eqv (id.mk ∘ f) x = id.mk (equiv.map eqv f x) :=
sorry
protected theorem comp_traverse {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] [is_lawful_traversable t]
{F : Type u → Type u} {G : Type u → Type u} [Applicative F] [Applicative G]
[is_lawful_applicative F] [is_lawful_applicative G] {α : Type u} {β : Type u} {γ : Type u}
(f : β → F γ) (g : α → G β) (x : t' α) :
equiv.traverse eqv (functor.comp.mk ∘ Functor.map f ∘ g) x =
functor.comp.mk (equiv.traverse eqv f <$> equiv.traverse eqv g x) :=
sorry
protected theorem naturality {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] [is_lawful_traversable t]
{F : Type u → Type u} {G : Type u → Type u} [Applicative F] [Applicative G]
[is_lawful_applicative F] [is_lawful_applicative G] (η : applicative_transformation F G)
{α : Type u} {β : Type u} (f : α → F β) (x : t' α) :
coe_fn η (t' β) (equiv.traverse eqv f x) = equiv.traverse eqv (coe_fn η β ∘ f) x :=
sorry
/-- The fact that `t` is a lawful traversable functor carries over the
equivalences to `t'`, with the traversable functor structure given by
`equiv.traversable`. -/
protected def is_lawful_traversable {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] [is_lawful_traversable t] :
is_lawful_traversable t' :=
is_lawful_traversable.mk (equiv.id_traverse eqv) (equiv.comp_traverse eqv)
(equiv.traverse_eq_map_id eqv) (equiv.naturality eqv)
/-- If the `traversable t'` instance has the properties that `map`,
`map_const`, and `traverse` are equal to the ones that come from
carrying the traversable functor structure from `t` over the
equivalences, then the the fact `t` is a lawful traversable functor
carries over as well. -/
protected def is_lawful_traversable' {t : Type u → Type u} {t' : Type u → Type u}
(eqv : (α : Type u) → t α ≃ t' α) [traversable t] [is_lawful_traversable t] [traversable t']
(h₀ : ∀ {α β : Type u} (f : α → β), Functor.map f = equiv.map eqv f)
(h₁ :
∀ {α β : Type u} (f : β),
Functor.mapConst f = function.comp (equiv.map eqv) (function.const α) f)
(h₂ :
∀ {F : Type u → Type u} [_inst_7 : Applicative F] [_inst_8 : is_lawful_applicative F]
{α β : Type u} (f : α → F β), traverse f = equiv.traverse eqv f) :
is_lawful_traversable t' :=
is_lawful_traversable.mk sorry sorry sorry sorry
end Mathlib |
4be8e029caaf57bc25e56997c34c3944e8d9b41f | 5412d79aa1dc0b521605c38bef9f0d4557b5a29d | /stage0/src/Lean/Elab/Structure.lean | 7057c8fc8a4c2e303dbf2f3a5fdf35775fa534b7 | [
"Apache-2.0"
] | permissive | smunix/lean4 | a450ec0927dc1c74816a1bf2818bf8600c9fc9bf | 3407202436c141e3243eafbecb4b8720599b970a | refs/heads/master | 1,676,334,875,188 | 1,610,128,510,000 | 1,610,128,521,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 26,876 | 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.Parser.Command
import Lean.Meta.Closure
import Lean.Elab.Command
import Lean.Elab.DeclModifiers
import Lean.Elab.DeclUtil
import Lean.Elab.Inductive
namespace Lean.Elab.Command
open Meta
/- Recall that the `structure command syntax is
```
parser! (structureTk <|> classTk) >> declId >> many Term.bracketedBinder >> optional «extends» >> Term.optType >> optional (" := " >> optional structCtor >> structFields)
```
-/
structure StructCtorView where
ref : Syntax
modifiers : Modifiers
inferMod : Bool -- true if `{}` is used in the constructor declaration
name : Name
declName : Name
structure StructFieldView where
ref : Syntax
modifiers : Modifiers
binderInfo : BinderInfo
inferMod : Bool
declName : Name
name : Name
binders : Syntax
type? : Option Syntax
value? : Option Syntax
structure StructView where
ref : Syntax
modifiers : Modifiers
scopeLevelNames : List Name -- All `universe` declarations in the current scope
allUserLevelNames : List Name -- `scopeLevelNames` ++ explicit universe parameters provided in the `structure` command
isClass : Bool
declName : Name
scopeVars : Array Expr -- All `variable` declaration in the current scope
params : Array Expr -- Explicit parameters provided in the `structure` command
parents : Array Syntax
type : Syntax
ctor : StructCtorView
fields : Array StructFieldView
inductive StructFieldKind where
| newField | fromParent | subobject
deriving Inhabited
structure StructFieldInfo where
name : Name
declName : Name -- Remark: this field value doesn't matter for fromParent fields.
fvar : Expr
kind : StructFieldKind
inferMod : Bool := false
value? : Option Expr := none
deriving Inhabited
def StructFieldInfo.isFromParent (info : StructFieldInfo) : Bool :=
match info.kind with
| StructFieldKind.fromParent => true
| _ => false
def StructFieldInfo.isSubobject (info : StructFieldInfo) : Bool :=
match info.kind with
| StructFieldKind.subobject => true
| _ => false
/- Auxiliary declaration for `mkProjections` -/
structure ProjectionInfo where
declName : Name
inferMod : Bool
structure ElabStructResult where
decl : Declaration
projInfos : List ProjectionInfo
projInstances : List Name -- projections (to parent classes) that must be marked as instances.
mctx : MetavarContext
lctx : LocalContext
localInsts : LocalInstances
defaultAuxDecls : Array (Name × Expr × Expr)
private def defaultCtorName := `mk
/-
The structure constructor syntax is
```
parser! try (declModifiers >> ident >> optional inferMod >> " :: ")
```
-/
private def expandCtor (structStx : Syntax) (structModifiers : Modifiers) (structDeclName : Name) : TermElabM StructCtorView :=
let useDefault :=
pure { ref := structStx, modifiers := {}, inferMod := false, name := defaultCtorName, declName := structDeclName ++ defaultCtorName }
if structStx[5].isNone then
useDefault
else
let optCtor := structStx[5][1]
if optCtor.isNone then
useDefault
else
let ctor := optCtor[0]
withRef ctor do
let ctorModifiers ← elabModifiers ctor[0]
checkValidCtorModifier ctorModifiers
if ctorModifiers.isPrivate && structModifiers.isPrivate then
throwError "invalid 'private' constructor in a 'private' structure"
if ctorModifiers.isProtected && structModifiers.isPrivate then
throwError "invalid 'protected' constructor in a 'private' structure"
let inferMod := !ctor[2].isNone
let name := ctor[1].getId
let declName := structDeclName ++ name
let declName ← applyVisibility ctorModifiers.visibility declName
pure { ref := ctor, name := name, modifiers := ctorModifiers, inferMod := inferMod, declName := declName }
def checkValidFieldModifier (modifiers : Modifiers) : TermElabM Unit := do
if modifiers.isNoncomputable then
throwError "invalid use of 'noncomputable' in field declaration"
if modifiers.isPartial then
throwError "invalid use of 'partial' in field declaration"
if modifiers.isUnsafe then
throwError "invalid use of 'unsafe' in field declaration"
if modifiers.attrs.size != 0 then
throwError "invalid use of attributes in field declaration"
if modifiers.isPrivate then
throwError "private fields are not supported yet"
/-
```
def structExplicitBinder := parser! atomic (declModifiers true >> "(") >> many1 ident >> optional inferMod >> optDeclSig >> optional Term.binderDefault >> ")"
def structImplicitBinder := parser! atomic (declModifiers true >> "{") >> many1 ident >> optional inferMod >> declSig >> "}"
def structInstBinder := parser! atomic (declModifiers true >> "[") >> many1 ident >> optional inferMod >> declSig >> "]"
def structSimpleBinder := parser! atomic (declModifiers true >> ident) >> optional inferMod >> optDeclSig >> optional Term.binderDefault
def structFields := parser! many (structExplicitBinder <|> structImplicitBinder <|> structInstBinder)
```
-/
private def expandFields (structStx : Syntax) (structModifiers : Modifiers) (structDeclName : Name) : TermElabM (Array StructFieldView) :=
let fieldBinders := if structStx[5].isNone then #[] else structStx[5][2][0].getArgs
fieldBinders.foldlM (init := #[]) fun (views : Array StructFieldView) fieldBinder => withRef fieldBinder do
let mut fieldBinder := fieldBinder
if fieldBinder.getKind == ``Parser.Command.structSimpleBinder then
fieldBinder := Syntax.node ``Parser.Command.structExplicitBinder
#[ fieldBinder[0], mkAtomFrom fieldBinder "(", mkNullNode #[ fieldBinder[1] ], fieldBinder[2], fieldBinder[3], fieldBinder[4], mkAtomFrom fieldBinder ")" ]
let k := fieldBinder.getKind
let binfo ←
if k == ``Parser.Command.structExplicitBinder then pure BinderInfo.default
else if k == ``Parser.Command.structImplicitBinder then pure BinderInfo.implicit
else if k == ``Parser.Command.structInstBinder then pure BinderInfo.instImplicit
else throwError "unexpected kind of structure field"
let fieldModifiers ← elabModifiers fieldBinder[0]
checkValidFieldModifier fieldModifiers
if fieldModifiers.isPrivate && structModifiers.isPrivate then
throwError "invalid 'private' field in a 'private' structure"
if fieldModifiers.isProtected && structModifiers.isPrivate then
throwError "invalid 'protected' field in a 'private' structure"
let inferMod := !fieldBinder[3].isNone
let (binders, type?) :=
if binfo == BinderInfo.default then
expandOptDeclSig fieldBinder[4]
else
let (binders, type) := expandDeclSig fieldBinder[4]
(binders, some type)
let value? :=
if binfo != BinderInfo.default then none
else
let optBinderDefault := fieldBinder[5]
if optBinderDefault.isNone then none
else
-- binderDefault := parser! " := " >> termParser
some optBinderDefault[0][1]
let idents := fieldBinder[2].getArgs
idents.foldlM (init := views) fun (views : Array StructFieldView) ident => withRef ident do
let name := ident.getId
if isInternalSubobjectFieldName name then
throwError! "invalid field name '{name}', identifiers starting with '_' are reserved to the system"
let declName := structDeclName ++ name
let declName ← applyVisibility fieldModifiers.visibility declName
return views.push {
ref := ident,
modifiers := fieldModifiers,
binderInfo := binfo,
inferMod := inferMod,
declName := declName,
name := name,
binders := binders,
type? := type?,
value? := value?
}
private def validStructType (type : Expr) : Bool :=
match type with
| Expr.sort .. => true
| _ => false
private def checkParentIsStructure (parent : Expr) : TermElabM Name :=
match parent.getAppFn with
| Expr.const c _ _ => do
unless isStructure (← getEnv) c do
throwError! "'{c}' is not a structure"
pure c
| _ => throwError "expected structure"
private def findFieldInfo? (infos : Array StructFieldInfo) (fieldName : Name) : Option StructFieldInfo :=
infos.find? fun info => info.name == fieldName
private def containsFieldName (infos : Array StructFieldInfo) (fieldName : Name) : Bool :=
(findFieldInfo? infos fieldName).isSome
private partial def processSubfields (structDeclName : Name) (parentFVar : Expr) (parentStructName : Name) (subfieldNames : Array Name)
(infos : Array StructFieldInfo) (k : Array StructFieldInfo → TermElabM α) : TermElabM α :=
let rec loop (i : Nat) (infos : Array StructFieldInfo) := do
if h : i < subfieldNames.size then
let subfieldName := subfieldNames.get ⟨i, h⟩
if containsFieldName infos subfieldName then
throwError! "field '{subfieldName}' from '{parentStructName}' has already been declared"
let val ← mkProjection parentFVar subfieldName
let type ← inferType val
withLetDecl subfieldName type val fun subfieldFVar =>
/- The following `declName` is only used for creating the `_default` auxiliary declaration name when
its default value is overwritten in the structure. -/
let declName := structDeclName ++ subfieldName
let infos := infos.push { name := subfieldName, declName := declName, fvar := subfieldFVar, kind := StructFieldKind.fromParent }
loop (i+1) infos
else
k infos
loop 0 infos
private partial def withParents (view : StructView) (i : Nat) (infos : Array StructFieldInfo) (k : Array StructFieldInfo → TermElabM α) : TermElabM α := do
if h : i < view.parents.size then
let parentStx := view.parents.get ⟨i, h⟩
withRef parentStx do
let parent ← Term.elabType parentStx
let parentName ← checkParentIsStructure parent
let toParentName := Name.mkSimple $ "to" ++ parentName.eraseMacroScopes.getString! -- erase macro scopes?
if containsFieldName infos toParentName then
throwErrorAt! parentStx "field '{toParentName}' has already been declared"
let env ← getEnv
let binfo := if view.isClass && isClass env parentName then BinderInfo.instImplicit else BinderInfo.default
withLocalDecl toParentName binfo parent fun parentFVar =>
let infos := infos.push { name := toParentName, declName := view.declName ++ toParentName, fvar := parentFVar, kind := StructFieldKind.subobject }
let subfieldNames := getStructureFieldsFlattened env parentName
processSubfields view.declName parentFVar parentName subfieldNames infos fun infos => withParents view (i+1) infos k
else
k infos
private def elabFieldTypeValue (view : StructFieldView) (params : Array Expr) : TermElabM (Option Expr × Option Expr) := do
match view.type? with
| none =>
match view.value? with
| none => pure (none, none)
| some valStx =>
let value ← Term.elabTerm valStx none
let value ← mkLambdaFVars params value
pure (none, value)
| some typeStx =>
let type ← Term.elabType typeStx
match view.value? with
| none =>
let type ← mkForallFVars params type
pure (type, none)
| some valStx =>
let value ← Term.elabTermEnsuringType valStx type
let type ← mkForallFVars params type
let value ← mkLambdaFVars params value
pure (type, value)
private partial def withFields
(views : Array StructFieldView) (i : Nat) (infos : Array StructFieldInfo) (k : Array StructFieldInfo → TermElabM α) : TermElabM α := do
if h : i < views.size then
let view := views.get ⟨i, h⟩
withRef view.ref $
match findFieldInfo? infos view.name with
| none => do
let (type?, value?) ← Term.elabBinders view.binders.getArgs fun params => elabFieldTypeValue view params
match type?, value? with
| none, none => throwError "invalid field, type expected"
| some type, _ =>
withLocalDecl view.name view.binderInfo type fun fieldFVar =>
let infos := infos.push { name := view.name, declName := view.declName, fvar := fieldFVar, value? := value?,
kind := StructFieldKind.newField, inferMod := view.inferMod }
withFields views (i+1) infos k
| none, some value =>
let type ← inferType value
withLocalDecl view.name view.binderInfo type fun fieldFVar =>
let infos := infos.push { name := view.name, declName := view.declName, fvar := fieldFVar, value? := value,
kind := StructFieldKind.newField, inferMod := view.inferMod }
withFields views (i+1) infos k
| some info =>
match info.kind with
| StructFieldKind.newField => throwError! "field '{view.name}' has already been declared"
| StructFieldKind.fromParent =>
match view.value? with
| none => throwError! "field '{view.name}' has been declared in parent structure"
| some valStx => do
if let some type := view.type? then
throwErrorAt! type "omit field '{view.name}' type to set default value"
else
let mut valStx := valStx
if view.binders.getArgs.size > 0 then
valStx ← `(fun $(view.binders.getArgs)* => $valStx:term)
let fvarType ← inferType info.fvar
let value ← Term.elabTermEnsuringType valStx fvarType
let infos := infos.push { info with value? := value }
withFields views (i+1) infos k
| StructFieldKind.subobject => unreachable!
else
k infos
private def getResultUniverse (type : Expr) : TermElabM Level := do
let type ← whnf type
match type with
| Expr.sort u _ => pure u
| _ => throwError "unexpected structure resulting type"
private def collectUsed (params : Array Expr) (fieldInfos : Array StructFieldInfo) : StateRefT CollectFVars.State TermElabM Unit := do
params.forM fun p => do
let type ← inferType p
Term.collectUsedFVars type
fieldInfos.forM fun info => do
let fvarType ← inferType info.fvar
Term.collectUsedFVars fvarType
match info.value? with
| none => pure ()
| some value => Term.collectUsedFVars value
private def removeUnused (scopeVars : Array Expr) (params : Array Expr) (fieldInfos : Array StructFieldInfo)
: TermElabM (LocalContext × LocalInstances × Array Expr) := do
let (_, used) ← (collectUsed params fieldInfos).run {}
Term.removeUnused scopeVars used
private def withUsed {α} (scopeVars : Array Expr) (params : Array Expr) (fieldInfos : Array StructFieldInfo) (k : Array Expr → TermElabM α)
: TermElabM α := do
let (lctx, localInsts, vars) ← removeUnused scopeVars params fieldInfos
withLCtx lctx localInsts $ k vars
private def levelMVarToParamFVar (fvar : Expr) : StateRefT Nat TermElabM Unit := do
let type ← inferType fvar
discard <| Term.levelMVarToParam' type
private def levelMVarToParamFVars (fvars : Array Expr) : StateRefT Nat TermElabM Unit :=
fvars.forM levelMVarToParamFVar
private def levelMVarToParamAux (scopeVars : Array Expr) (params : Array Expr) (fieldInfos : Array StructFieldInfo)
: StateRefT Nat TermElabM (Array StructFieldInfo) := do
levelMVarToParamFVars scopeVars
levelMVarToParamFVars params
fieldInfos.mapM fun info => do
levelMVarToParamFVar info.fvar
match info.value? with
| none => pure info
| some value =>
let value ← Term.levelMVarToParam' value
pure { info with value? := value }
private def levelMVarToParam (scopeVars : Array Expr) (params : Array Expr) (fieldInfos : Array StructFieldInfo) : TermElabM (Array StructFieldInfo) :=
(levelMVarToParamAux scopeVars params fieldInfos).run' 1
private partial def collectUniversesFromFields (r : Level) (rOffset : Nat) (fieldInfos : Array StructFieldInfo) : TermElabM (Array Level) := do
fieldInfos.foldlM (init := #[]) fun (us : Array Level) (info : StructFieldInfo) => do
let type ← inferType info.fvar
let u ← getLevel type
let u ← instantiateLevelMVars u
accLevelAtCtor u r rOffset us
private def updateResultingUniverse (fieldInfos : Array StructFieldInfo) (type : Expr) : TermElabM Expr := do
let r ← getResultUniverse type
let rOffset : Nat := r.getOffset
let r : Level := r.getLevelOffset
match r with
| Level.mvar mvarId _ =>
let us ← collectUniversesFromFields r rOffset fieldInfos
let rNew := mkResultUniverse us rOffset
assignLevelMVar mvarId rNew
instantiateMVars type
| _ => throwError "failed to compute resulting universe level of structure, provide universe explicitly"
private def collectLevelParamsInFVar (s : CollectLevelParams.State) (fvar : Expr) : TermElabM CollectLevelParams.State := do
let type ← inferType fvar
let type ← instantiateMVars type
pure $ collectLevelParams s type
private def collectLevelParamsInFVars (fvars : Array Expr) (s : CollectLevelParams.State) : TermElabM CollectLevelParams.State :=
fvars.foldlM collectLevelParamsInFVar s
private def collectLevelParamsInStructure (structType : Expr) (scopeVars : Array Expr) (params : Array Expr) (fieldInfos : Array StructFieldInfo)
: TermElabM (Array Name) := do
let s := collectLevelParams {} structType
let s ← collectLevelParamsInFVars scopeVars s
let s ← collectLevelParamsInFVars params s
let s ← fieldInfos.foldlM (fun (s : CollectLevelParams.State) info => collectLevelParamsInFVar s info.fvar) s
pure s.params
private def addCtorFields (fieldInfos : Array StructFieldInfo) : Nat → Expr → TermElabM Expr
| 0, type => pure type
| i+1, type => do
let info := fieldInfos[i]
let decl ← Term.getFVarLocalDecl! info.fvar
let type ← instantiateMVars type
let type := type.abstract #[info.fvar]
match info.kind with
| StructFieldKind.fromParent =>
let val := decl.value
addCtorFields fieldInfos i (type.instantiate1 val)
| StructFieldKind.subobject =>
let n := mkInternalSubobjectFieldName $ decl.userName
addCtorFields fieldInfos i (mkForall n decl.binderInfo decl.type type)
| StructFieldKind.newField =>
addCtorFields fieldInfos i (mkForall decl.userName decl.binderInfo decl.type type)
private def mkCtor (view : StructView) (levelParams : List Name) (params : Array Expr) (fieldInfos : Array StructFieldInfo) : TermElabM Constructor :=
withRef view.ref do
let type := mkAppN (mkConst view.declName (levelParams.map mkLevelParam)) params
let type ← addCtorFields fieldInfos fieldInfos.size type
let type ← mkForallFVars params type
let type ← instantiateMVars type
let type := type.inferImplicit params.size !view.ctor.inferMod
pure { name := view.ctor.declName, type := type }
@[extern "lean_mk_projections"]
private constant mkProjections (env : Environment) (structName : Name) (projs : List ProjectionInfo) (isClass : Bool) : Except KernelException Environment
private def addProjections (structName : Name) (projs : List ProjectionInfo) (isClass : Bool) : TermElabM Unit := do
let env ← getEnv
match mkProjections env structName projs isClass with
| Except.ok env => setEnv env
| Except.error ex => throwKernelException ex
private def mkAuxConstructions (declName : Name) : TermElabM Unit := do
let env ← getEnv
let hasUnit := env.contains `PUnit
let hasEq := env.contains `Eq
let hasHEq := env.contains `HEq
mkRecOn declName
if hasUnit then mkCasesOn declName
if hasUnit && hasEq && hasHEq then mkNoConfusion declName
private def addDefaults (lctx : LocalContext) (defaultAuxDecls : Array (Name × Expr × Expr)) : TermElabM Unit := do
let localInsts ← getLocalInstances
withLCtx lctx localInsts do
defaultAuxDecls.forM fun (declName, type, value) => do
/- The identity function is used as "marker". -/
let value ← mkId value
discard <| mkAuxDefinition declName type value (zeta := true)
setReducibleAttribute declName
private def elabStructureView (view : StructView) : TermElabM Unit := do
view.fields.forM fun field => do
if field.declName == view.ctor.declName then
throwErrorAt! field.ref "invalid field name '{field.name}', it is equal to structure constructor name"
let numExplicitParams := view.params.size
let type ← Term.elabType view.type
unless validStructType type do throwErrorAt view.type "expected Type"
withRef view.ref do
withParents view 0 #[] fun fieldInfos =>
withFields view.fields 0 fieldInfos fun fieldInfos => do
Term.synthesizeSyntheticMVarsNoPostponing
let u ← getResultUniverse type
let inferLevel ← shouldInferResultUniverse u
withUsed view.scopeVars view.params fieldInfos $ fun scopeVars => do
let numParams := scopeVars.size + numExplicitParams
let fieldInfos ← levelMVarToParam scopeVars view.params fieldInfos
let type ← withRef view.ref do
if inferLevel then
updateResultingUniverse fieldInfos type
else
checkResultingUniverse (← getResultUniverse type)
pure type
trace[Elab.structure]! "type: {type}"
let usedLevelNames ← collectLevelParamsInStructure type scopeVars view.params fieldInfos
match sortDeclLevelParams view.scopeLevelNames view.allUserLevelNames usedLevelNames with
| Except.error msg => withRef view.ref <| throwError msg
| Except.ok levelParams =>
let params := scopeVars ++ view.params
let ctor ← mkCtor view levelParams params fieldInfos
let type ← mkForallFVars params type
let type ← instantiateMVars type
let indType := { name := view.declName, type := type, ctors := [ctor] : InductiveType }
let decl := Declaration.inductDecl levelParams params.size [indType] view.modifiers.isUnsafe
Term.ensureNoUnassignedMVars decl
addDecl decl
let projInfos := (fieldInfos.filter fun (info : StructFieldInfo) => !info.isFromParent).toList.map fun (info : StructFieldInfo) =>
{ declName := info.declName, inferMod := info.inferMod : ProjectionInfo }
addProjections view.declName projInfos view.isClass
mkAuxConstructions view.declName
let instParents ← fieldInfos.filterM fun info => do
let decl ← Term.getFVarLocalDecl! info.fvar
pure (info.isSubobject && decl.binderInfo.isInstImplicit)
let projInstances := instParents.toList.map fun info => info.declName
Term.applyAttributesAt view.declName view.modifiers.attrs AttributeApplicationTime.afterTypeChecking
projInstances.forM fun declName => addInstance declName AttributeKind.global (evalPrio! default)
let lctx ← getLCtx
let fieldsWithDefault := fieldInfos.filter fun info => info.value?.isSome
let defaultAuxDecls ← fieldsWithDefault.mapM fun info => do
let type ← inferType info.fvar
pure (info.declName ++ `_default, type, info.value?.get!)
/- The `lctx` and `defaultAuxDecls` are used to create the auxiliary `_default` declarations
The parameters `params` for these definitions must be marked as implicit, and all others as explicit. -/
let lctx :=
params.foldl (init := lctx) fun (lctx : LocalContext) (p : Expr) =>
lctx.updateBinderInfo p.fvarId! BinderInfo.implicit
let lctx :=
fieldInfos.foldl (init := lctx) fun (lctx : LocalContext) (info : StructFieldInfo) =>
if info.isFromParent then lctx -- `fromParent` fields are elaborated as let-decls, and are zeta-expanded when creating `_default`.
else lctx.updateBinderInfo info.fvar.fvarId! BinderInfo.default
addDefaults lctx defaultAuxDecls
/-
parser! (structureTk <|> classTk) >> declId >> many Term.bracketedBinder >> optional «extends» >> Term.optType >> " := " >> optional structCtor >> structFields >> optDeriving
where
def «extends» := parser! " extends " >> sepBy1 termParser ", "
def typeSpec := parser! " : " >> termParser
def optType : Parser := optional typeSpec
def structFields := parser! many (structExplicitBinder <|> structImplicitBinder <|> structInstBinder)
def structCtor := parser! try (declModifiers >> ident >> optional inferMod >> " :: ")
-/
def elabStructure (modifiers : Modifiers) (stx : Syntax) : CommandElabM Unit := do
checkValidInductiveModifier modifiers
let isClass := stx[0].getKind == ``Parser.Command.classTk
let modifiers := if isClass then modifiers.addAttribute { name := `class } else modifiers
let declId := stx[1]
let params := stx[2].getArgs
let exts := stx[3]
let parents := if exts.isNone then #[] else exts[0][1].getSepArgs
let optType := stx[4]
let derivingClassViews ← getOptDerivingClasses stx[6]
let type ← if optType.isNone then `(Sort _) else pure optType[0][1]
let declName ←
runTermElabM none fun scopeVars => do
let scopeLevelNames ← Term.getLevelNames
let ⟨name, declName, allUserLevelNames⟩ ← Elab.expandDeclId (← getCurrNamespace) scopeLevelNames declId modifiers
Term.withDeclName declName do
let ctor ← expandCtor stx modifiers declName
let fields ← expandFields stx modifiers declName
Term.withLevelNames allUserLevelNames <| Term.withAutoBoundImplicitLocal <|
Term.elabBinders params (catchAutoBoundImplicit := true) fun params => do
let params ← Term.addAutoBoundImplicits params
let allUserLevelNames ← Term.getLevelNames
Term.withAutoBoundImplicitLocal (flag := false) do
elabStructureView {
ref := stx
modifiers := modifiers
scopeLevelNames := scopeLevelNames
allUserLevelNames := allUserLevelNames
declName := declName
isClass := isClass
scopeVars := scopeVars
params := params
parents := parents
type := type
ctor := ctor
fields := fields
}
return declName
derivingClassViews.forM fun view => view.applyHandlers #[declName]
builtin_initialize registerTraceClass `Elab.structure
end Lean.Elab.Command
|
0c30bd61bdbaf000e25d2e3edba53de9a05c1662 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/complex/phragmen_lindelof.lean | 71e462a2b384f905946d02b25c38e3bd3ba5cf84 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 49,541 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.complex.abs_max
import analysis.asymptotics.superpolynomial_decay
/-!
# Phragmen-Lindelöf principle
In this file we prove several versions of the Phragmen-Lindelöf principle, a version of the maximum
modulus principle for an unbounded domain.
## Main statements
* `phragmen_lindelof.horizontal_strip`: the Phragmen-Lindelöf principle in a horizontal strip
`{z : ℂ | a < complex.im z < b}`;
* `phragmen_lindelof.eq_zero_on_horizontal_strip`, `phragmen_lindelof.eq_on_horizontal_strip`:
extensionality lemmas based on the Phragmen-Lindelöf principle in a horizontal strip;
* `phragmen_lindelof.vertical_strip`: the Phragmen-Lindelöf principle in a vertical strip
`{z : ℂ | a < complex.re z < b}`;
* `phragmen_lindelof.eq_zero_on_vertical_strip`, `phragmen_lindelof.eq_on_vertical_strip`:
extensionality lemmas based on the Phragmen-Lindelöf principle in a vertical strip;
* `phragmen_lindelof.quadrant_I`, `phragmen_lindelof.quadrant_II`, `phragmen_lindelof.quadrant_III`,
`phragmen_lindelof.quadrant_IV`: the Phragmen-Lindelöf principle in the coordinate quadrants;
* `phragmen_lindelof.right_half_plane_of_tendsto_zero_on_real`,
`phragmen_lindelof.right_half_plane_of_bounded_on_real`: two versions of the Phragmen-Lindelöf
principle in the right half-plane;
* `phragmen_lindelof.eq_zero_on_right_half_plane_of_superexponential_decay`,
`phragmen_lindelof.eq_on_right_half_plane_of_superexponential_decay`: extensionality lemmas based
on the Phragmen-Lindelöf principle in the right half-plane.
In the case of the right half-plane, we prove a version of the Phragmen-Lindelöf principle that is
useful for Ilyashenko's proof of the individual finiteness theorem (a polynomial vector field on the
real plane has only finitely many limit cycles).
-/
open set function filter asymptotics metric complex
open_locale topology filter real
local notation `expR` := real.exp
namespace phragmen_lindelof
/-!
### Auxiliary lemmas
-/
variables {E : Type*} [normed_add_comm_group E]
/-- An auxiliary lemma that combines two double exponential estimates into a similar estimate
on the difference of the functions. -/
lemma is_O_sub_exp_exp {a : ℝ} {f g : ℂ → E} {l : filter ℂ} {u : ℂ → ℝ}
(hBf : ∃ (c < a) B, f =O[l] (λ z, expR (B * expR (c * |u z|))))
(hBg : ∃ (c < a) B, g =O[l] (λ z, expR (B * expR (c * |u z|)))) :
∃ (c < a) B, (f - g) =O[l] (λ z, expR (B * expR (c * |u z|))) :=
begin
have : ∀ {c₁ c₂ B₁ B₂}, c₁ ≤ c₂ → 0 ≤ B₂ → B₁ ≤ B₂ → ∀ z,
‖expR (B₁ * expR (c₁ * |u z|))‖ ≤ ‖expR (B₂ * expR (c₂ * |u z|))‖,
{ intros c₁ c₂ B₁ B₂ hc hB₀ hB z,
rw [real.norm_eq_abs, real.norm_eq_abs, real.abs_exp, real.abs_exp, real.exp_le_exp],
exact mul_le_mul hB (real.exp_le_exp.2 $ mul_le_mul_of_nonneg_right hc $ abs_nonneg _)
(real.exp_pos _).le hB₀ },
rcases hBf with ⟨cf, hcf, Bf, hOf⟩, rcases hBg with ⟨cg, hcg, Bg, hOg⟩,
refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), _⟩,
refine (hOf.trans_le $ this _ _ _).sub (hOg.trans_le $ this _ _ _),
exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _),
le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)]
end
/-- An auxiliary lemma that combines two “exponential of a power” estimates into a similar estimate
on the difference of the functions. -/
lemma is_O_sub_exp_rpow {a : ℝ} {f g : ℂ → E} {l : filter ℂ}
(hBf : ∃ (c < a) B, f =O[comap complex.abs at_top ⊓ l] (λ z, expR (B * (abs z) ^ c)))
(hBg : ∃ (c < a) B, g =O[comap complex.abs at_top ⊓ l] (λ z, expR (B * (abs z) ^ c))) :
∃ (c < a) B, (f - g) =O[comap complex.abs at_top ⊓ l] (λ z, expR (B * (abs z) ^ c)) :=
begin
have : ∀ {c₁ c₂ B₁ B₂ : ℝ}, c₁ ≤ c₂ → 0 ≤ B₂ → B₁ ≤ B₂ →
(λ z : ℂ, expR (B₁ * (abs z) ^ c₁)) =O[comap complex.abs at_top ⊓ l]
(λ z, expR (B₂ * (abs z) ^ c₂)),
{ have : ∀ᶠ z : ℂ in comap complex.abs at_top ⊓ l, 1 ≤ abs z,
from ((eventually_ge_at_top 1).comap _).filter_mono inf_le_left,
refine λ c₁ c₂ B₁ B₂ hc hB₀ hB, is_O.of_bound 1 (this.mono $ λ z hz, _),
rw [one_mul, real.norm_eq_abs, real.norm_eq_abs, real.abs_exp, real.abs_exp, real.exp_le_exp],
exact mul_le_mul hB (real.rpow_le_rpow_of_exponent_le hz hc)
(real.rpow_nonneg_of_nonneg (complex.abs.nonneg _) _) hB₀ },
rcases hBf with ⟨cf, hcf, Bf, hOf⟩, rcases hBg with ⟨cg, hcg, Bg, hOg⟩,
refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), _⟩,
refine (hOf.trans $ this _ _ _).sub (hOg.trans $ this _ _ _),
exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _),
le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)]
end
variables [normed_space ℂ E] {a b C : ℝ} {f g : ℂ → E} {z : ℂ}
/-!
### Phragmen-Lindelöf principle in a horizontal strip
-/
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < π / (b - a)`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of `U`.
Then `‖f z‖` is bounded by the same constant on the closed strip
`{z : ℂ | a ≤ im z ≤ b}`. Moreover, it suffices to verify the second assumption
only for sufficiently large values of `|re z|`.
-/
lemma horizontal_strip (hfd : diff_cont_on_cl ℂ f (im ⁻¹' Ioo a b))
(hB : ∃ (c < π / (b - a)) B, f =O[comap (has_abs.abs ∘ re) at_top ⊓ 𝓟 (im ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.re|))))
(hle_a : ∀ z : ℂ, im z = a → ‖f z‖ ≤ C) (hle_b : ∀ z, im z = b → ‖f z‖ ≤ C)
(hza : a ≤ im z) (hzb : im z ≤ b) :
‖f z‖ ≤ C :=
begin
-- If `im z = a` or `im z = b`, then we apply `hle_a` or `hle_b`, otherwise `im z ∈ Ioo a b`.
rw le_iff_eq_or_lt at hza hzb,
cases hza with hza hza, { exact hle_a _ hza.symm },
cases hzb with hzb hzb, { exact hle_b _ hzb },
-- WLOG, `0 < C`.
suffices : ∀ C' : ℝ, 0 < C' → (∀ w : ℂ, im w = a → ‖f w‖ ≤ C') →
(∀ w : ℂ, im w = b → ‖f w‖ ≤ C') → ‖f z‖ ≤ C',
{ refine le_of_forall_le_of_dense (λ C' hC', this C' _ (λ w hw, _) (λ w hw, _)),
{ refine ((norm_nonneg (f (a * I))).trans (hle_a _ _)).trans_lt hC',
rw [mul_I_im, of_real_re] },
exacts [(hle_a _ hw).trans hC'.le, (hle_b _ hw).trans hC'.le] },
clear_dependent C, intros C hC₀ hle_a hle_b,
-- After a change of variables, we deal with the strip `a - b < im z < a + b` instead
-- of `a < im z < b`
obtain ⟨a, b, rfl, rfl⟩ : ∃ a' b', a = a' - b' ∧ b = a' + b' :=
⟨(a + b) / 2, (b - a) / 2, by ring, by ring⟩,
have hab : a - b < a + b, from hza.trans hzb,
have hb : 0 < b,
by simpa only [sub_eq_add_neg, add_lt_add_iff_left, neg_lt_self_iff] using hab,
rw [add_sub_sub_cancel, ← two_mul, div_mul_eq_div_div] at hB,
have hπb : 0 < π / 2 / b, from div_pos real.pi_div_two_pos hb,
-- Choose some `c B : ℝ` satisfying `hB`, then choose `max c 0 < d < π / 2 / b`.
rcases hB with ⟨c, hc, B, hO⟩,
obtain ⟨d, ⟨hcd, hd₀⟩, hd⟩ : ∃ d, (c < d ∧ 0 < d) ∧ d < π / 2 / b,
by simpa only [max_lt_iff] using exists_between (max_lt hc hπb),
have hb' : d * b < π / 2, from (lt_div_iff hb).1 hd,
set aff : ℂ → ℂ := λ w, d * (w - a * I),
set g : ℝ → ℂ → ℂ := λ ε w, exp (ε * (exp (aff w) + exp (-aff w))),
/- Since `g ε z → 1` as `ε → 0⁻`, it suffices to prove that `‖g ε z • f z‖ ≤ C`
for all negative `ε`. -/
suffices : ∀ᶠ ε : ℝ in 𝓝[<] 0, ‖g ε z • f z‖ ≤ C,
{ refine le_of_tendsto (tendsto.mono_left _ nhds_within_le_nhds) this,
apply ((continuous_of_real.mul continuous_const).cexp.smul continuous_const).norm.tendsto',
simp, apply_instance },
filter_upwards [self_mem_nhds_within] with ε ε₀, change ε < 0 at ε₀,
-- An upper estimate on `‖g ε w‖` that will be used in two branches of the proof.
obtain ⟨δ, δ₀, hδ⟩ : ∃ δ : ℝ, δ < 0 ∧ ∀ ⦃w⦄, im w ∈ Icc (a - b) (a + b) →
abs (g ε w) ≤ expR (δ * expR (d * |re w|)),
{ refine ⟨ε * real.cos (d * b), mul_neg_of_neg_of_pos ε₀ (real.cos_pos_of_mem_Ioo $ abs_lt.1 $
(abs_of_pos (mul_pos hd₀ hb)).symm ▸ hb'), λ w hw, _⟩,
replace hw : |im (aff w)| ≤ d * b,
{ rw [← real.closed_ball_eq_Icc] at hw,
rwa [of_real_mul_im, sub_im, mul_I_im, of_real_re, _root_.abs_mul, abs_of_pos hd₀,
mul_le_mul_left hd₀] },
simpa only [of_real_mul_re, _root_.abs_mul, abs_of_pos hd₀, sub_re, mul_I_re, of_real_im,
zero_mul, neg_zero, sub_zero]
using abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le ε₀.le hw hb'.le },
-- `abs (g ε w) ≤ 1` on the lines `w.im = a ± b` (actually, it holds everywhere in the strip)
have hg₁ : ∀ w, (im w = a - b ∨ im w = a + b) → abs (g ε w) ≤ 1,
{ refine λ w hw, (hδ $ hw.by_cases _ _).trans (real.exp_le_one_iff.2 _),
exacts [λ h, h.symm ▸ left_mem_Icc.2 hab.le, λ h, h.symm ▸ right_mem_Icc.2 hab.le,
mul_nonpos_of_nonpos_of_nonneg δ₀.le (real.exp_pos _).le] },
/- Our apriori estimate on `f` implies that `g ε w • f w → 0` as `|w.re| → ∞` along the strip. In
particular, its norm is less than or equal to `C` for sufficiently large `|w.re|`. -/
obtain ⟨R, hzR, hR⟩ : ∃ R : ℝ, |z.re| < R ∧ ∀ w, |re w| = R → im w ∈ Ioo (a - b) (a + b) →
‖g ε w • f w‖ ≤ C,
{ refine ((eventually_gt_at_top _).and _).exists,
rcases hO.exists_pos with ⟨A, hA₀, hA⟩,
simp only [is_O_with_iff, eventually_inf_principal, eventually_comap, mem_Ioo, ← abs_lt,
mem_preimage, (∘), real.norm_eq_abs, abs_of_pos (real.exp_pos _)] at hA,
suffices : tendsto (λ R, expR (δ * expR (d * R) + B * expR (c * R) + real.log A)) at_top (𝓝 0),
{ filter_upwards [this.eventually (ge_mem_nhds hC₀), hA] with R hR Hle w hre him,
calc ‖g ε w • f w‖ ≤ expR (δ * expR (d * R) + B * expR (c * R) + real.log A) : _
... ≤ C : hR,
rw [norm_smul, real.exp_add, ← hre, real.exp_add, real.exp_log hA₀, mul_assoc, mul_comm _ A],
exact mul_le_mul (hδ $ Ioo_subset_Icc_self him) (Hle _ hre him) (norm_nonneg _)
(real.exp_pos _).le },
refine real.tendsto_exp_at_bot.comp _,
suffices H : tendsto (λ R, δ + B * (expR ((d - c) * R))⁻¹) at_top (𝓝 (δ + B * 0)),
{ rw [mul_zero, add_zero] at H,
refine tendsto.at_bot_add _ tendsto_const_nhds,
simpa only [id, (∘), add_mul, mul_assoc, ← div_eq_inv_mul, ← real.exp_sub,
← sub_mul, sub_sub_cancel]
using H.neg_mul_at_top δ₀ (real.tendsto_exp_at_top.comp $
tendsto_const_nhds.mul_at_top hd₀ tendsto_id) },
refine tendsto_const_nhds.add (tendsto_const_nhds.mul _),
exact tendsto_inv_at_top_zero.comp (real.tendsto_exp_at_top.comp $
tendsto_const_nhds.mul_at_top (sub_pos.2 hcd) tendsto_id) },
have hR₀ : 0 < R, from (_root_.abs_nonneg _).trans_lt hzR,
/- Finally, we apply the bounded version of the maximum modulus principle to the rectangle
`(-R, R) × (a - b, a + b)`. The function is bounded by `C` on the horizontal sides by assumption
(and because `‖g ε w‖ ≤ 1`) and on the vertical sides by the choice of `R`. -/
have hgd : differentiable ℂ (g ε),
from ((((differentiable_id.sub_const _).const_mul _).cexp.add
((differentiable_id.sub_const _).const_mul _).neg.cexp).const_mul _).cexp,
replace hd : diff_cont_on_cl ℂ (λ w, g ε w • f w) (Ioo (-R) R ×ℂ Ioo (a - b) (a + b)),
from (hgd.diff_cont_on_cl.smul hfd).mono (inter_subset_right _ _),
convert norm_le_of_forall_mem_frontier_norm_le ((bounded_Ioo _ _).re_prod_im (bounded_Ioo _ _))
hd (λ w hw, _) _,
{ have hwc := frontier_subset_closure hw,
rw [frontier_re_prod_im, closure_Ioo (neg_lt_self hR₀).ne, frontier_Ioo hab,
closure_Ioo hab.ne, frontier_Ioo (neg_lt_self hR₀)] at hw,
by_cases him : w.im = a - b ∨ w.im = a + b,
{ rw [closure_re_prod_im, closure_Ioo (neg_lt_self hR₀).ne] at hwc,
rw [norm_smul, ← one_mul C],
exact mul_le_mul (hg₁ _ him) (him.by_cases (hle_a _) (hle_b _)) (norm_nonneg _) zero_le_one },
{ replace hw : w ∈ {-R, R} ×ℂ Icc (a - b) (a + b), from hw.resolve_left (λ h, him h.2),
have hw' := eq_endpoints_or_mem_Ioo_of_mem_Icc hw.2, rw ← or.assoc at hw',
exact hR _ ((abs_eq hR₀.le).2 hw.1.symm) (hw'.resolve_left him) } },
{ rw [closure_re_prod_im, closure_Ioo hab.ne, closure_Ioo (neg_lt_self hR₀).ne],
exact ⟨abs_le.1 hzR.le, ⟨hza.le, hzb.le⟩⟩ }
end
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < π / (b - a)`;
* `f z = 0` on the boundary of `U`.
Then `f` is equal to zero on the closed strip `{z : ℂ | a ≤ im z ≤ b}`.
-/
lemma eq_zero_on_horizontal_strip (hd : diff_cont_on_cl ℂ f (im ⁻¹' Ioo a b))
(hB : ∃ (c < π / (b - a)) B, f =O[comap (has_abs.abs ∘ re) at_top ⊓ 𝓟 (im ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.re|))))
(ha : ∀ z : ℂ, z.im = a → f z = 0) (hb : ∀ z : ℂ, z.im = b → f z = 0) :
eq_on f 0 (im ⁻¹' Icc a b) :=
λ z hz, norm_le_zero_iff.1 $ horizontal_strip hd hB
(λ z hz, (ha z hz).symm ▸ norm_zero.le) (λ z hz, (hb z hz).symm ▸ norm_zero.le) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable on `U` and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some
`c < π / (b - a)`;
* `f z = g z` on the boundary of `U`.
Then `f` is equal to `g` on the closed strip `{z : ℂ | a ≤ im z ≤ b}`.
-/
lemma eq_on_horizontal_strip {g : ℂ → E} (hdf : diff_cont_on_cl ℂ f (im ⁻¹' Ioo a b))
(hBf : ∃ (c < π / (b - a)) B, f =O[comap (has_abs.abs ∘ re) at_top ⊓ 𝓟 (im ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.re|))))
(hdg : diff_cont_on_cl ℂ g (im ⁻¹' Ioo a b))
(hBg : ∃ (c < π / (b - a)) B, g =O[comap (has_abs.abs ∘ re) at_top ⊓ 𝓟 (im ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.re|))))
(ha : ∀ z : ℂ, z.im = a → f z = g z) (hb : ∀ z : ℂ, z.im = b → f z = g z) :
eq_on f g (im ⁻¹' Icc a b) :=
λ z hz, sub_eq_zero.1 (eq_zero_on_horizontal_strip (hdf.sub hdg) (is_O_sub_exp_exp hBf hBg)
(λ w hw, sub_eq_zero.2 (ha w hw)) (λ w hw, sub_eq_zero.2 (hb w hw)) hz)
/-!
### Phragmen-Lindelöf principle in a vertical strip
-/
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < π / (b - a)`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of `U`.
Then `‖f z‖` is bounded by the same constant on the closed strip
`{z : ℂ | a ≤ re z ≤ b}`. Moreover, it suffices to verify the second assumption
only for sufficiently large values of `|im z|`.
-/
lemma vertical_strip (hfd : diff_cont_on_cl ℂ f (re ⁻¹' Ioo a b))
(hB : ∃ (c < π / (b - a)) B, f =O[comap (has_abs.abs ∘ im) at_top ⊓ 𝓟 (re ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.im|))))
(hle_a : ∀ z : ℂ, re z = a → ‖f z‖ ≤ C) (hle_b : ∀ z, re z = b → ‖f z‖ ≤ C)
(hza : a ≤ re z) (hzb : re z ≤ b) :
‖f z‖ ≤ C :=
begin
suffices : ‖(λ z, f (z * (-I))) (z * I)‖ ≤ C, by simpa [mul_assoc] using this,
have H : maps_to (λ z, z * (-I)) (im ⁻¹' Ioo a b) (re ⁻¹' Ioo a b),
{ intros z hz, simpa using hz },
refine horizontal_strip (hfd.comp (differentiable_id.mul_const _).diff_cont_on_cl H)
_ (λ z hz, hle_a _ _) (λ z hz, hle_b _ _) _ _,
{ refine Exists₃.imp (λ c hc B hO, _) hB,
have : tendsto (λ z, z * (-I)) (comap (has_abs.abs ∘ re) at_top ⊓ 𝓟 (im ⁻¹' Ioo a b))
(comap (has_abs.abs ∘ im) at_top ⊓ 𝓟 (re ⁻¹' Ioo a b)),
{ refine (tendsto_comap_iff.2 _).inf H.tendsto,
simpa [(∘)] using tendsto_comap },
simpa [(∘)] using hO.comp_tendsto this },
all_goals { simpa }
end
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < π / (b - a)`;
* `f z = 0` on the boundary of `U`.
Then `f` is equal to zero on the closed strip `{z : ℂ | a ≤ re z ≤ b}`.
-/
lemma eq_zero_on_vertical_strip (hd : diff_cont_on_cl ℂ f (re ⁻¹' Ioo a b))
(hB : ∃ (c < π / (b - a)) B, f =O[comap (has_abs.abs ∘ im) at_top ⊓ 𝓟 (re ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.im|))))
(ha : ∀ z : ℂ, re z = a → f z = 0) (hb : ∀ z : ℂ, re z = b → f z = 0) :
eq_on f 0 (re ⁻¹' Icc a b) :=
λ z hz, norm_le_zero_iff.1 $ vertical_strip hd hB
(λ z hz, (ha z hz).symm ▸ norm_zero.le) (λ z hz, (hb z hz).symm ▸ norm_zero.le) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable on `U` and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some
`c < π / (b - a)`;
* `f z = g z` on the boundary of `U`.
Then `f` is equal to `g` on the closed strip `{z : ℂ | a ≤ re z ≤ b}`.
-/
lemma eq_on_vertical_strip {g : ℂ → E} (hdf : diff_cont_on_cl ℂ f (re ⁻¹' Ioo a b))
(hBf : ∃ (c < π / (b - a)) B, f =O[comap (has_abs.abs ∘ im) at_top ⊓ 𝓟 (re ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.im|))))
(hdg : diff_cont_on_cl ℂ g (re ⁻¹' Ioo a b))
(hBg : ∃ (c < π / (b - a)) B, g =O[comap (has_abs.abs ∘ im) at_top ⊓ 𝓟 (re ⁻¹' Ioo a b)]
(λ z, expR (B * expR (c * |z.im|))))
(ha : ∀ z : ℂ, re z = a → f z = g z) (hb : ∀ z : ℂ, re z = b → f z = g z) :
eq_on f g (re ⁻¹' Icc a b) :=
λ z hz, sub_eq_zero.1 (eq_zero_on_vertical_strip (hdf.sub hdg) (is_O_sub_exp_exp hBf hBg)
(λ w hw, sub_eq_zero.2 (ha w hw)) (λ w hw, sub_eq_zero.2 (hb w hw)) hz)
/-!
### Phragmen-Lindelöf principle in coordinate quadrants
-/
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open first quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the first quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed first quadrant. -/
lemma quadrant_I (hd : diff_cont_on_cl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, 0 ≤ x → ‖f x‖ ≤ C) (him : ∀ x : ℝ, 0 ≤ x → ‖f (x * I)‖ ≤ C)
(hz_re : 0 ≤ z.re) (hz_im : 0 ≤ z.im) :
‖f z‖ ≤ C :=
begin
-- The case `z = 0` is trivial.
rcases eq_or_ne z 0 with rfl|hzne, { exact hre 0 le_rfl },
-- Otherwise, `z = e ^ ζ` for some `ζ : ℂ`, `0 < Im ζ < π / 2`.
obtain ⟨ζ, hζ, rfl⟩ : ∃ ζ : ℂ, ζ.im ∈ Icc 0 (π / 2) ∧ exp ζ = z,
{ refine ⟨log z, _, exp_log hzne⟩,
rw log_im,
exact ⟨arg_nonneg_iff.2 hz_im, arg_le_pi_div_two_iff.2 (or.inl hz_re)⟩ },
clear hz_re hz_im hzne,
-- We are going to apply `phragmen_lindelof.horizontal_strip` to `f ∘ complex.exp` and `ζ`.
change ‖(f ∘ exp) ζ‖ ≤ C,
have H : maps_to exp (im ⁻¹' Ioo 0 (π / 2)) (Ioi 0 ×ℂ Ioi 0),
{ intros z hz,
rw [mem_re_prod_im, exp_re, exp_im, mem_Ioi, mem_Ioi],
refine ⟨mul_pos (real.exp_pos _)
(real.cos_pos_of_mem_Ioo ⟨(neg_lt_zero.2 $ div_pos real.pi_pos two_pos).trans hz.1, hz.2⟩),
mul_pos (real.exp_pos _)
(real.sin_pos_of_mem_Ioo ⟨hz.1, hz.2.trans (half_lt_self real.pi_pos)⟩)⟩ },
refine horizontal_strip (hd.comp differentiable_exp.diff_cont_on_cl H) _ _ _ hζ.1 hζ.2;
clear hζ ζ,
{ -- The estimate `hB` on `f` implies the required estimate on
-- `f ∘ exp` with the same `c` and `B' = max B 0`.
rw [sub_zero, div_div_cancel' real.pi_pos.ne'],
rcases hB with ⟨c, hc, B, hO⟩,
refine ⟨c, hc, max B 0, _⟩,
rw [← comap_comap, comap_abs_at_top, comap_sup, inf_sup_right],
-- We prove separately the estimates as `ζ.re → ∞` and as `ζ.re → -∞`
refine is_O.sup _ ((hO.comp_tendsto $ tendsto_exp_comap_re_at_top.inf H.tendsto).trans $
is_O.of_bound 1 _),
{ -- For the estimate as `ζ.re → -∞`, note that `f` is continuous within the first quadrant at
-- zero, hence `f (exp ζ)` has a limit as `ζ.re → -∞`, `0 < ζ.im < π / 2`.
have hc : continuous_within_at f (Ioi 0 ×ℂ Ioi 0) 0,
{ refine (hd.continuous_on _ _).mono subset_closure,
simp [closure_re_prod_im, mem_re_prod_im] },
refine ((hc.tendsto.comp $ tendsto_exp_comap_re_at_bot.inf
H.tendsto).is_O_one ℝ).trans (is_O_of_le _ (λ w, _)),
rw [norm_one, real.norm_of_nonneg (real.exp_pos _).le, real.one_le_exp_iff],
exact mul_nonneg (le_max_right _ _) (real.exp_pos _).le },
{ -- For the estimate as `ζ.re → ∞`, we reuse the uppoer estimate on `f`
simp only [eventually_inf_principal, eventually_comap, comp_app, one_mul,
real.norm_of_nonneg (real.exp_pos _).le, abs_exp, ← real.exp_mul, real.exp_le_exp],
refine (eventually_ge_at_top 0).mono (λ x hx z hz hz', _),
rw [hz, _root_.abs_of_nonneg hx, mul_comm _ c],
exact mul_le_mul_of_nonneg_right (le_max_left _ _) (real.exp_pos _).le } },
{ -- If `ζ.im = 0`, then `complex.exp ζ` is a positive real number
intros ζ hζ, lift ζ to ℝ using hζ,
rw [comp_app, ← of_real_exp],
exact hre _ (real.exp_pos _).le },
{ -- If `ζ.im = π / 2`, then `complex.exp ζ` is a purely imaginary number with positive `im`
intros ζ hζ,
rw [← re_add_im ζ, hζ, comp_app, exp_add_mul_I, ← of_real_cos, ← of_real_sin,
real.cos_pi_div_two, real.sin_pi_div_two, of_real_zero, of_real_one, one_mul, zero_add,
← of_real_exp],
exact him _ (real.exp_pos _).le }
end
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open first quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant
for some `A`, `B`, and `c < 2`;
* `f` is equal to zero on the boundary of the first quadrant.
Then `f` is equal to zero on the closed first quadrant. -/
lemma eq_zero_on_quadrant_I (hd : diff_cont_on_cl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, 0 ≤ x → f x = 0) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = 0) :
eq_on f 0 {z | 0 ≤ z.re ∧ 0 ≤ z.im} :=
λ z hz, norm_le_zero_iff.1 $ quadrant_I hd hB (λ x hx, norm_le_zero_iff.2 $ hre x hx)
(λ x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable in the open first quadrant and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open first
quadrant for some `A`, `B`, and `c < 2`;
* `f` is equal to `g` on the boundary of the first quadrant.
Then `f` is equal to `g` on the closed first quadrant. -/
lemma eq_on_quadrant_I (hdf : diff_cont_on_cl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hBf : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hdg : diff_cont_on_cl ℂ g (Ioi 0 ×ℂ Ioi 0))
(hBg : ∃ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, 0 ≤ x → f x = g x) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = g (x * I)) :
eq_on f g {z | 0 ≤ z.re ∧ 0 ≤ z.im} :=
λ z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_I (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg)
(λ x hx, sub_eq_zero.2 $ hre x hx) (λ x hx, sub_eq_zero.2 $ him x hx) hz
/-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open second quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the second quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed second quadrant. -/
lemma quadrant_II (hd : diff_cont_on_cl ℂ f (Iio 0 ×ℂ Ioi 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, x ≤ 0 → ‖f x‖ ≤ C) (him : ∀ x : ℝ, 0 ≤ x → ‖f (x * I)‖ ≤ C)
(hz_re : z.re ≤ 0) (hz_im : 0 ≤ z.im) :
‖f z‖ ≤ C :=
begin
obtain ⟨z, rfl⟩ : ∃ z', z' * I = z, from ⟨z / I, div_mul_cancel _ I_ne_zero⟩,
simp only [mul_I_re, mul_I_im, neg_nonpos] at hz_re hz_im,
change ‖(f ∘ (* I)) z‖ ≤ C,
have H : maps_to (* I) (Ioi 0 ×ℂ Ioi 0) (Iio 0 ×ℂ Ioi 0),
{ intros w hw,
simpa only [mem_re_prod_im, mul_I_re, mul_I_im, neg_lt_zero, mem_Iio] using hw.symm },
refine quadrant_I (hd.comp (differentiable_id.mul_const _).diff_cont_on_cl H)
(Exists₃.imp (λ c hc B hO, _) hB) him (λ x hx, _) hz_im hz_re,
{ simpa only [(∘), map_mul, abs_I, mul_one]
using hO.comp_tendsto ((tendsto_mul_right_cobounded I_ne_zero).inf H.tendsto) },
{ rw [comp_app, mul_assoc, I_mul_I, mul_neg_one, ← of_real_neg],
exact hre _ (neg_nonpos.2 hx) }
end
/-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open second quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant
for some `A`, `B`, and `c < 2`;
* `f` is equal to zero on the boundary of the second quadrant.
Then `f` is equal to zero on the closed second quadrant. -/
lemma eq_zero_on_quadrant_II (hd : diff_cont_on_cl ℂ f (Iio 0 ×ℂ Ioi 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, x ≤ 0 → f x = 0) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = 0) :
eq_on f 0 {z | z.re ≤ 0 ∧ 0 ≤ z.im} :=
λ z hz, norm_le_zero_iff.1 $ quadrant_II hd hB (λ x hx, norm_le_zero_iff.2 $ hre x hx)
(λ x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable in the open second quadrant and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open second
quadrant for some `A`, `B`, and `c < 2`;
* `f` is equal to `g` on the boundary of the second quadrant.
Then `f` is equal to `g` on the closed second quadrant. -/
lemma eq_on_quadrant_II (hdf : diff_cont_on_cl ℂ f (Iio 0 ×ℂ Ioi 0))
(hBf : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hdg : diff_cont_on_cl ℂ g (Iio 0 ×ℂ Ioi 0))
(hBg : ∃ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, x ≤ 0 → f x = g x) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = g (x * I)) :
eq_on f g {z | z.re ≤ 0 ∧ 0 ≤ z.im} :=
λ z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_II (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg)
(λ x hx, sub_eq_zero.2 $ hre x hx) (λ x hx, sub_eq_zero.2 $ him x hx) hz
/-- **Phragmen-Lindelöf principle** in the third quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open third quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp (B * (abs z) ^ c)` on the open third quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the third quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed third quadrant. -/
lemma quadrant_III (hd : diff_cont_on_cl ℂ f (Iio 0 ×ℂ Iio 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, x ≤ 0 → ‖f x‖ ≤ C) (him : ∀ x : ℝ, x ≤ 0 → ‖f (x * I)‖ ≤ C)
(hz_re : z.re ≤ 0) (hz_im : z.im ≤ 0) :
‖f z‖ ≤ C :=
begin
obtain ⟨z, rfl⟩ : ∃ z', -z' = z, from ⟨-z, neg_neg z⟩,
simp only [neg_re, neg_im, neg_nonpos] at hz_re hz_im,
change ‖(f ∘ has_neg.neg) z‖ ≤ C,
have H : maps_to has_neg.neg (Ioi 0 ×ℂ Ioi 0) (Iio 0 ×ℂ Iio 0),
{ intros w hw,
simpa only [mem_re_prod_im, neg_re, neg_im, neg_lt_zero, mem_Iio] using hw },
refine quadrant_I (hd.comp differentiable_neg.diff_cont_on_cl H) _ (λ x hx, _) (λ x hx, _)
hz_re hz_im,
{ refine Exists₃.imp (λ c hc B hO, _) hB,
simpa only [(∘), complex.abs.map_neg]
using hO.comp_tendsto (tendsto_neg_cobounded.inf H.tendsto) },
{ rw [comp_app, ← of_real_neg],
exact hre (-x) (neg_nonpos.2 hx) },
{ rw [comp_app, ← neg_mul, ← of_real_neg],
exact him (-x) (neg_nonpos.2 hx) }
end
/-- **Phragmen-Lindelöf principle** in the third quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open third quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open third quadrant
for some `A`, `B`, and `c < 2`;
* `f` is equal to zero on the boundary of the third quadrant.
Then `f` is equal to zero on the closed third quadrant. -/
lemma eq_zero_on_quadrant_III (hd : diff_cont_on_cl ℂ f (Iio 0 ×ℂ Iio 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, x ≤ 0 → f x = 0) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = 0) :
eq_on f 0 {z | z.re ≤ 0 ∧ z.im ≤ 0} :=
λ z hz, norm_le_zero_iff.1 $ quadrant_III hd hB (λ x hx, norm_le_zero_iff.2 $ hre x hx)
(λ x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in the third quadrant. Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable in the open third quadrant and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open third
quadrant for some `A`, `B`, and `c < 2`;
* `f` is equal to `g` on the boundary of the third quadrant.
Then `f` is equal to `g` on the closed third quadrant. -/
lemma eq_on_quadrant_III (hdf : diff_cont_on_cl ℂ f (Iio 0 ×ℂ Iio 0))
(hBf : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hdg : diff_cont_on_cl ℂ g (Iio 0 ×ℂ Iio 0))
(hBg : ∃ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, x ≤ 0 → f x = g x) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = g (x * I)) :
eq_on f g {z | z.re ≤ 0 ∧ z.im ≤ 0} :=
λ z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_III (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg)
(λ x hx, sub_eq_zero.2 $ hre x hx) (λ x hx, sub_eq_zero.2 $ him x hx) hz
/-- **Phragmen-Lindelöf principle** in the fourth quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open fourth quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the fourth quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed fourth quadrant. -/
lemma quadrant_IV (hd : diff_cont_on_cl ℂ f (Ioi 0 ×ℂ Iio 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, 0 ≤ x → ‖f x‖ ≤ C) (him : ∀ x : ℝ, x ≤ 0 → ‖f (x * I)‖ ≤ C)
(hz_re : 0 ≤ z.re) (hz_im : z.im ≤ 0) :
‖f z‖ ≤ C :=
begin
obtain ⟨z, rfl⟩ : ∃ z', -z' = z, from ⟨-z, neg_neg z⟩,
simp only [neg_re, neg_im, neg_nonpos, neg_nonneg] at hz_re hz_im,
change ‖(f ∘ has_neg.neg) z‖ ≤ C,
have H : maps_to has_neg.neg (Iio 0 ×ℂ Ioi 0) (Ioi 0 ×ℂ Iio 0),
{ intros w hw,
simpa only [mem_re_prod_im, neg_re, neg_im, neg_lt_zero, neg_pos, mem_Ioi, mem_Iio] using hw },
refine quadrant_II (hd.comp differentiable_neg.diff_cont_on_cl H) _ (λ x hx, _) (λ x hx, _)
hz_re hz_im,
{ refine Exists₃.imp (λ c hc B hO, _) hB,
simpa only [(∘), complex.abs.map_neg]
using hO.comp_tendsto (tendsto_neg_cobounded.inf H.tendsto) },
{ rw [comp_app, ← of_real_neg],
exact hre (-x) (neg_nonneg.2 hx) },
{ rw [comp_app, ← neg_mul, ← of_real_neg],
exact him (-x) (neg_nonpos.2 hx) }
end
/-- **Phragmen-Lindelöf principle** in the fourth quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open fourth quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant
for some `A`, `B`, and `c < 2`;
* `f` is equal to zero on the boundary of the fourth quadrant.
Then `f` is equal to zero on the closed fourth quadrant. -/
lemma eq_zero_on_quadrant_IV (hd : diff_cont_on_cl ℂ f (Ioi 0 ×ℂ Iio 0))
(hB : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, 0 ≤ x → f x = 0) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = 0) :
eq_on f 0 {z | 0 ≤ z.re ∧ z.im ≤ 0} :=
λ z hz, norm_le_zero_iff.1 $ quadrant_IV hd hB (λ x hx, norm_le_zero_iff.2 $ hre x hx)
(λ x hx, norm_le_zero_iff.2 $ him x hx) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in the fourth quadrant. Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable in the open fourth quadrant and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth
quadrant for some `A`, `B`, and `c < 2`;
* `f` is equal to `g` on the boundary of the fourth quadrant.
Then `f` is equal to `g` on the closed fourth quadrant. -/
lemma eq_on_quadrant_IV (hdf : diff_cont_on_cl ℂ f (Ioi 0 ×ℂ Iio 0))
(hBf : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hdg : diff_cont_on_cl ℂ g (Ioi 0 ×ℂ Iio 0))
(hBg : ∃ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)]
(λ z, expR (B * (abs z) ^ c)))
(hre : ∀ x : ℝ, 0 ≤ x → f x = g x) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = g (x * I)) :
eq_on f g {z | 0 ≤ z.re ∧ z.im ≤ 0} :=
λ z hz, sub_eq_zero.1 $ eq_zero_on_quadrant_IV (hdf.sub hdg) (is_O_sub_exp_rpow hBf hBg)
(λ x hx, sub_eq_zero.2 $ hre x hx) (λ x hx, sub_eq_zero.2 $ him x hx) hz
/-!
### Phragmen-Lindelöf principle in the right half-plane
-/
/-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open right half-plane and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the imaginary axis;
* `f x → 0` as `x : ℝ` tends to infinity.
Then `‖f z‖` is bounded from above by the same constant on the closed right half-plane.
See also `phragmen_lindelof.right_half_plane_of_bounded_on_real` for a stronger version. -/
lemma right_half_plane_of_tendsto_zero_on_real (hd : diff_cont_on_cl ℂ f {z | 0 < z.re})
(hexp : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 {z | 0 < z.re}]
(λ z, expR (B * (abs z) ^ c)))
(hre : tendsto (λ x : ℝ, f x) at_top (𝓝 0)) (him : ∀ x : ℝ, ‖f (x * I)‖ ≤ C) (hz : 0 ≤ z.re) :
‖f z‖ ≤ C :=
begin
/- We are going to apply the Phragmen-Lindelöf principle in the first and fourth quadrants.
The lemmas immediately imply that for any upper estimate `C'` on `‖f x‖`, `x : ℝ`, `0 ≤ x`,
the number `max C C'` is an upper estimate on `f` in the whole right half-plane. -/
revert z,
have hle : ∀ C', (∀ x : ℝ, 0 ≤ x → ‖f x‖ ≤ C') → ∀ z : ℂ, 0 ≤ z.re → ‖f z‖ ≤ max C C',
{ intros C' hC' z hz,
cases le_total z.im 0,
{ refine quadrant_IV (hd.mono $ λ _, and.left) (Exists₃.imp (λ c hc B hO, _) hexp)
(λ x hx, (hC' x hx).trans $ le_max_right _ _) (λ x hx, (him x).trans (le_max_left _ _))
hz h,
exact hO.mono (inf_le_inf_left _ $ principal_mono.2 $ λ _, and.left) },
{ refine quadrant_I (hd.mono $ λ _, and.left) (Exists₃.imp (λ c hc B hO, _) hexp)
(λ x hx, (hC' x hx).trans $ le_max_right _ _) (λ x hx, (him x).trans (le_max_left _ _))
hz h,
exact hO.mono (inf_le_inf_left _ $ principal_mono.2 $ λ _, and.left) } },
-- Since `f` is continuous on `Ici 0` and `‖f x‖` tends to zero as `x → ∞`,
-- the norm `‖f x‖` takes its maximum value at some `x₀ : ℝ`.
obtain ⟨x₀, hx₀, hmax⟩ : ∃ x : ℝ, 0 ≤ x ∧ ∀ y : ℝ, 0 ≤ y → ‖f y‖ ≤ ‖f x‖,
{ have hfc : continuous_on (λ x : ℝ, f x) (Ici 0),
{ refine hd.continuous_on.comp continuous_of_real.continuous_on (λ x hx, _),
rwa closure_set_of_lt_re },
by_cases h₀ : ∀ x : ℝ, 0 ≤ x → f x = 0,
{ refine ⟨0, le_rfl, λ y hy, _⟩, rw [h₀ y hy, h₀ 0 le_rfl] },
push_neg at h₀,
rcases h₀ with ⟨x₀, hx₀, hne⟩,
have hlt : ‖(0 : E)‖ < ‖f x₀‖, by rwa [norm_zero, norm_pos_iff],
suffices : ∀ᶠ x : ℝ in cocompact ℝ ⊓ 𝓟 (Ici 0), ‖f x‖ ≤ ‖f x₀‖,
by simpa only [exists_prop] using hfc.norm.exists_forall_ge' is_closed_Ici hx₀ this,
rw [real.cocompact_eq, inf_sup_right, (disjoint_at_bot_principal_Ici (0 : ℝ)).eq_bot,
bot_sup_eq],
exact (hre.norm.eventually $ ge_mem_nhds hlt).filter_mono inf_le_left },
cases le_or_lt (‖f x₀‖) C,
{ -- If `‖f x₀‖ ≤ C`, then `hle` implies the required estimate
simpa only [max_eq_left h] using hle _ hmax },
{ -- Otherwise, `‖f z‖ ≤ ‖f x₀‖` for all `z` in the right half-plane due to `hle`.
replace hmax : is_max_on (norm ∘ f) {z | 0 < z.re} x₀,
{ rintros z (hz : 0 < z.re),
simpa [max_eq_right h.le] using hle _ hmax _ hz.le },
-- Due to the maximum modulus principle applied to the closed ball of radius `x₀.re`,
-- `‖f 0‖ = ‖f x₀‖`.
have : ‖f 0‖ = ‖f x₀‖,
{ apply norm_eq_norm_of_is_max_on_of_ball_subset hd hmax,
-- move to a lemma?
intros z hz,
rw [mem_ball, dist_zero_left, dist_eq, norm_eq_abs, complex.abs_of_nonneg hx₀] at hz,
rw mem_set_of_eq,
contrapose! hz,
calc x₀ ≤ x₀ - z.re : (le_sub_self_iff _).2 hz
... ≤ |x₀ - z.re| : le_abs_self _
... = |(z - x₀).re| : by rw [sub_re, of_real_re, _root_.abs_sub_comm]
... ≤ abs (z - x₀) : abs_re_le_abs _ },
-- Thus we have `C < ‖f x₀‖ = ‖f 0‖ ≤ C`. Contradiction completes the proof.
refine (h.not_le $ this ▸ _).elim,
simpa using him 0 }
end
/-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open right half-plane and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the imaginary axis;
* `‖f x‖` is bounded from above by a constant for large real values of `x`.
Then `‖f z‖` is bounded from above by `C` on the closed right half-plane.
See also `phragmen_lindelof.right_half_plane_of_tendsto_zero_on_real` for a weaker version. -/
lemma right_half_plane_of_bounded_on_real (hd : diff_cont_on_cl ℂ f {z | 0 < z.re})
(hexp : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 {z | 0 < z.re}]
(λ z, expR (B * (abs z) ^ c)))
(hre : is_bounded_under (≤) at_top (λ x : ℝ, ‖f x‖))
(him : ∀ x : ℝ, ‖f (x * I)‖ ≤ C) (hz : 0 ≤ z.re) :
‖f z‖ ≤ C :=
begin
-- For each `ε < 0`, the function `λ z, exp (ε * z) • f z` satisfies assumptions of
-- `right_half_plane_of_tendsto_zero_on_real`, hence `‖exp (ε * z) • f z‖ ≤ C` for all `ε < 0`.
-- Taking the limit as `ε → 0`, we obtain the required inequality.
suffices : ∀ᶠ ε : ℝ in 𝓝[<] 0, ‖exp (ε * z) • f z‖ ≤ C,
{ refine le_of_tendsto (tendsto.mono_left _ nhds_within_le_nhds) this,
apply ((continuous_of_real.mul continuous_const).cexp.smul continuous_const).norm.tendsto',
simp, apply_instance },
filter_upwards [self_mem_nhds_within] with ε ε₀, change ε < 0 at ε₀,
set g : ℂ → E := λ z, exp (ε * z) • f z, change ‖g z‖ ≤ C,
replace hd : diff_cont_on_cl ℂ g {z : ℂ | 0 < z.re},
from (differentiable_id.const_mul _).cexp.diff_cont_on_cl.smul hd,
have hgn : ∀ z, ‖g z‖ = expR (ε * z.re) * ‖f z‖,
{ intro z, rw [norm_smul, norm_eq_abs, abs_exp, of_real_mul_re] },
refine right_half_plane_of_tendsto_zero_on_real hd _ _ (λ y, _) hz,
{ refine Exists₃.imp (λ c hc B hO, (is_O.of_bound 1 _).trans hO) hexp,
refine (eventually_inf_principal.2 $ eventually_of_forall $ λ z hz, _),
rw [hgn, one_mul],
refine mul_le_of_le_one_left (norm_nonneg _) (real.exp_le_one_iff.2 _),
exact mul_nonpos_of_nonpos_of_nonneg ε₀.le (le_of_lt hz) },
{ simp_rw [g, ← of_real_mul, ← of_real_exp, coe_smul],
have h₀ : tendsto (λ x : ℝ, expR (ε * x)) at_top (𝓝 0),
from real.tendsto_exp_at_bot.comp (tendsto_const_nhds.neg_mul_at_top ε₀ tendsto_id),
exact h₀.zero_smul_is_bounded_under_le hre },
{ rw [hgn, of_real_mul_re, I_re, mul_zero, mul_zero, real.exp_zero, one_mul],
exact him y }
end
/-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open right half-plane and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant on the imaginary axis;
* `f x`, `x : ℝ`, tends to zero superexponentially fast as `x → ∞`:
for any natural `n`, `exp (n * x) * ‖f x‖` tends to zero as `x → ∞`.
Then `f` is equal to zero on the closed right half-plane. -/
lemma eq_zero_on_right_half_plane_of_superexponential_decay
(hd : diff_cont_on_cl ℂ f {z | 0 < z.re})
(hexp : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 {z | 0 < z.re}]
(λ z, expR (B * (abs z) ^ c)))
(hre : superpolynomial_decay at_top expR (λ x, ‖f x‖))
(him : ∃ C, ∀ x : ℝ, ‖f (x * I)‖ ≤ C) :
eq_on f 0 {z : ℂ | 0 ≤ z.re} :=
begin
rcases him with ⟨C, hC⟩,
-- Due to continuity, it suffices to prove the equality on the open right half-plane.
suffices : ∀ z : ℂ, 0 < z.re → f z = 0,
{ simpa only [closure_set_of_lt_re] using eq_on.of_subset_closure this hd.continuous_on
continuous_on_const subset_closure subset.rfl },
-- Consider $g_n(z)=e^{nz}f(z)$.
set g : ℕ → ℂ → E := λ n z, (exp z) ^ n • f z,
have hg : ∀ n z, ‖g n z‖ = (expR z.re) ^ n * ‖f z‖,
{ intros n z, simp only [norm_smul, norm_eq_abs, complex.abs_pow, abs_exp] },
intros z hz,
-- Since `e^{nz} → ∞` as `n → ∞`, it suffices to show that each `g_n` is bounded from above by `C`
suffices H : ∀ n : ℕ, ‖g n z‖ ≤ C,
{ contrapose! H,
simp only [hg],
exact (((tendsto_pow_at_top_at_top_of_one_lt (real.one_lt_exp_iff.2 hz)).at_top_mul
(norm_pos_iff.2 H) tendsto_const_nhds).eventually (eventually_gt_at_top C)).exists },
intro n,
-- This estimate follows from the Phragmen-Lindelöf principle in the right half-plane.
refine right_half_plane_of_tendsto_zero_on_real
((differentiable_exp.pow n).diff_cont_on_cl.smul hd) _ _ (λ y, _) hz.le,
{ rcases hexp with ⟨c, hc, B, hO⟩,
refine ⟨max c 1, max_lt hc one_lt_two, n + max B 0, is_O.of_norm_left _⟩,
simp only [hg],
refine ((is_O_refl (λ z : ℂ, expR z.re ^ n) _).mul hO.norm_left).trans (is_O.of_bound 1 _),
simp only [← real.exp_nat_mul, ← real.exp_add, real.norm_of_nonneg (real.exp_pos _).le,
real.exp_le_exp, add_mul, eventually_inf_principal, eventually_comap, one_mul],
filter_upwards [eventually_ge_at_top (1 : ℝ)] with r hr z hzr hre, subst r,
refine add_le_add (mul_le_mul_of_nonneg_left _ n.cast_nonneg) _,
{ calc z.re ≤ abs z : re_le_abs _
... = abs z ^ (1 : ℝ) : (real.rpow_one _).symm
... ≤ abs z ^ (max c 1) : real.rpow_le_rpow_of_exponent_le hr (le_max_right _ _) },
{ exact mul_le_mul (le_max_left _ _) (real.rpow_le_rpow_of_exponent_le hr (le_max_left _ _))
(real.rpow_nonneg_of_nonneg (complex.abs.nonneg _) _) (le_max_right _ _) } },
{ rw tendsto_zero_iff_norm_tendsto_zero, simp only [hg],
exact hre n },
{ rw [hg, of_real_mul_re, I_re, mul_zero, real.exp_zero, one_pow, one_mul],
exact hC y }
end
/-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f g : ℂ → E` be functions such
that
* `f` and `g` are differentiable in the open right half-plane and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open right
half-plane for some `c < 2`;
* `‖f z‖` and `‖g z‖` are bounded from above by constants on the imaginary axis;
* `f x - g x`, `x : ℝ`, tends to zero superexponentially fast as `x → ∞`:
for any natural `n`, `exp (n * x) * ‖f x - g x‖` tends to zero as `x → ∞`.
Then `f` is equal to `g` on the closed right half-plane. -/
lemma eq_on_right_half_plane_of_superexponential_decay {g : ℂ → E}
(hfd : diff_cont_on_cl ℂ f {z | 0 < z.re}) (hgd : diff_cont_on_cl ℂ g {z | 0 < z.re})
(hfexp : ∃ (c < (2 : ℝ)) B, f =O[comap complex.abs at_top ⊓ 𝓟 {z | 0 < z.re}]
(λ z, expR (B * (abs z) ^ c)))
(hgexp : ∃ (c < (2 : ℝ)) B, g =O[comap complex.abs at_top ⊓ 𝓟 {z | 0 < z.re}]
(λ z, expR (B * (abs z) ^ c)))
(hre : superpolynomial_decay at_top expR (λ x, ‖f x - g x‖))
(hfim : ∃ C, ∀ x : ℝ, ‖f (x * I)‖ ≤ C) (hgim : ∃ C, ∀ x : ℝ, ‖g (x * I)‖ ≤ C) :
eq_on f g {z : ℂ | 0 ≤ z.re} :=
begin
suffices : eq_on (f - g) 0 {z : ℂ | 0 ≤ z.re},
by simpa only [eq_on, pi.sub_apply, pi.zero_apply, sub_eq_zero] using this,
refine eq_zero_on_right_half_plane_of_superexponential_decay (hfd.sub hgd) _ hre _,
{ set l : filter ℂ := comap complex.abs at_top ⊓ 𝓟 {z : ℂ | 0 < z.re},
suffices : ∀ {c₁ c₂ B₁ B₂ : ℝ}, c₁ ≤ c₂ → B₁ ≤ B₂ → 0 ≤ B₂ →
(λ z, expR (B₁ * abs z ^ c₁)) =O[l] (λ z, expR (B₂ * abs z ^ c₂)),
{ rcases hfexp with ⟨cf, hcf, Bf, hOf⟩, rcases hgexp with ⟨cg, hcg, Bg, hOg⟩,
refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), _⟩,
refine is_O.sub (hOf.trans $ this _ _ _) (hOg.trans $ this _ _ _); simp },
intros c₁ c₂ B₁ B₂ hc hB hB₂,
have : ∀ᶠ z : ℂ in l, 1 ≤ abs z,
from ((eventually_ge_at_top 1).comap _).filter_mono inf_le_left,
refine is_O.of_bound 1 (this.mono $ λ z hz, _),
simp only [real.norm_of_nonneg (real.exp_pos _).le, real.exp_le_exp, one_mul],
exact mul_le_mul hB (real.rpow_le_rpow_of_exponent_le hz hc)
(real.rpow_nonneg_of_nonneg (complex.abs.nonneg _) _) hB₂ },
{ rcases hfim with ⟨Cf, hCf⟩, rcases hgim with ⟨Cg, hCg⟩,
exact ⟨Cf + Cg, λ x, norm_sub_le_of_le (hCf x) (hCg x)⟩ }
end
end phragmen_lindelof
|
608cba9edaabfb5ab11173ccda8eb2769a421f5f | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/data/set/pointwise.lean | 0c5e4a104948d1a98026c37027e923d05b1271d4 | [
"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 | 65,748 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Floris van Doorn
-/
import algebra.module.basic
import data.fin.tuple.basic
import data.set.finite
import group_theory.submonoid.basic
/-!
# Pointwise operations of sets
This file defines pointwise algebraic operations on sets.
## Main declarations
For sets `s` and `t` and scalar `a`:
* `s * t`: Multiplication, set of all `x * y` where `x ∈ s` and `y ∈ t`.
* `s + t`: Addition, set of all `x + y` where `x ∈ s` and `y ∈ t`.
* `s⁻¹`: Inversion, set of all `x⁻¹` where `x ∈ s`.
* `-s`: Negation, set of all `-x` where `x ∈ s`.
* `s / t`: Division, set of all `x / y` where `x ∈ s` and `y ∈ t`.
* `s - t`: Subtraction, set of all `x - y` where `x ∈ s` and `y ∈ t`.
* `s • t`: Scalar multiplication, set of all `x • y` where `x ∈ s` and `y ∈ t`.
* `s +ᵥ t`: Scalar addition, set of all `x +ᵥ y` where `x ∈ s` and `y ∈ t`.
* `s -ᵥ t`: Scalar subtraction, set of all `x -ᵥ y` where `x ∈ s` and `y ∈ t`.
* `a • s`: Scaling, set of all `a • x` where `x ∈ s`.
* `a +ᵥ s`: Translation, set of all `a +ᵥ x` where `x ∈ s`.
For `α` a semigroup/monoid, `set α` is a semigroup/monoid.
As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between
pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action].
Appropriate definitions and results are also transported to the additive theory via `to_additive`.
## Implementation notes
* The following expressions are considered in simp-normal form in a group:
`(λ h, h * g) ⁻¹' s`, `(λ h, g * h) ⁻¹' s`, `(λ h, h * g⁻¹) ⁻¹' s`, `(λ h, g⁻¹ * h) ⁻¹' s`,
`s * t`, `s⁻¹`, `(1 : set _)` (and similarly for additive variants).
Expressions equal to one of these will be simplified.
* We put all instances in the locale `pointwise`, so that these instances are not available by
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
since we expect the locale to be open whenever the instances are actually used (and making the
instances reducible changes the behavior of `simp`.
## Tags
set multiplication, set addition, pointwise addition, pointwise multiplication,
pointwise subtraction
-/
/--
Pointwise monoids (`set`, `finset`, `filter`) have derived pointwise actions of the form
`has_smul α β → has_smul α (set β)`. When `α` is `ℕ` or `ℤ`, this action conflicts with the
nat or int action coming from `set β` being a `monoid` or `div_inv_monoid`. For example,
`2 • {a, b}` can both be `{2 • a, 2 • b}` (pointwise action, pointwise repeated addition,
`set.has_smul_set`) and `{a + a, a + b, b + a, b + b}` (nat or int action, repeated pointwise
addition, `set.has_nsmul`).
Because the pointwise action can easily be spelled out in such cases, we give higher priority to the
nat and int actions.
-/
library_note "pointwise nat action"
open function
variables {F α β γ : Type*}
namespace set
/-! ### `0`/`1` as sets -/
section one
variables [has_one α] {s : set α} {a : α}
/-- The set `1 : set α` is defined as `{1}` in locale `pointwise`. -/
@[to_additive "The set `0 : set α` is defined as `{0}` in locale `pointwise`."]
protected def has_one : has_one (set α) := ⟨{1}⟩
localized "attribute [instance] set.has_one set.has_zero" in pointwise
@[to_additive] lemma singleton_one : ({1} : set α) = 1 := rfl
@[simp, to_additive] lemma mem_one : a ∈ (1 : set α) ↔ a = 1 := iff.rfl
@[to_additive] lemma one_mem_one : (1 : α) ∈ (1 : set α) := eq.refl _
@[simp, to_additive] lemma one_subset : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff
@[to_additive] lemma one_nonempty : (1 : set α).nonempty := ⟨1, rfl⟩
@[simp, to_additive] lemma image_one {f : α → β} : f '' 1 = {f 1} := image_singleton
@[to_additive] lemma subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff_eq
@[to_additive] lemma nonempty.subset_one_iff (h : s.nonempty) : s ⊆ 1 ↔ s = 1 :=
h.subset_singleton_iff
/-- The singleton operation as a `one_hom`. -/
@[to_additive "The singleton operation as a `zero_hom`."]
def singleton_one_hom : one_hom α (set α) := ⟨singleton, singleton_one⟩
@[simp, to_additive] lemma coe_singleton_one_hom : (singleton_one_hom : α → set α) = singleton :=
rfl
end one
/-! ### Set negation/inversion -/
section inv
/-- The pointwise inversion of set `s⁻¹` is defined as `{x | x⁻¹ ∈ s}` in locale `pointwise`. It i
equal to `{x⁻¹ | x ∈ s}`, see `set.image_inv`. -/
@[to_additive "The pointwise negation of set `-s` is defined as `{x | -x ∈ s}` in locale
`pointwise`. It is equal to `{-x | x ∈ s}`, see `set.image_neg`."]
protected def has_inv [has_inv α] : has_inv (set α) := ⟨preimage has_inv.inv⟩
localized "attribute [instance] set.has_inv set.has_neg" in pointwise
section has_inv
variables {ι : Sort*} [has_inv α] {s t : set α} {a : α}
@[simp, to_additive] lemma mem_inv : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := iff.rfl
@[simp, to_additive] lemma inv_preimage : has_inv.inv ⁻¹' s = s⁻¹ := rfl
@[simp, to_additive] lemma inv_empty : (∅ : set α)⁻¹ = ∅ := rfl
@[simp, to_additive] lemma inv_univ : (univ : set α)⁻¹ = univ := rfl
@[simp, to_additive] lemma inter_inv : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter
@[simp, to_additive] lemma union_inv : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union
@[simp, to_additive] lemma Inter_inv (s : ι → set α) : (⋂ i, s i)⁻¹ = ⋂ i, (s i)⁻¹ := preimage_Inter
@[simp, to_additive] lemma Union_inv (s : ι → set α) : (⋃ i, s i)⁻¹ = ⋃ i, (s i)⁻¹ := preimage_Union
@[simp, to_additive] lemma compl_inv : (sᶜ)⁻¹ = (s⁻¹)ᶜ := preimage_compl
end has_inv
section has_involutive_inv
variables [has_involutive_inv α] {s t : set α} {a : α}
@[to_additive] lemma inv_mem_inv : a⁻¹ ∈ s⁻¹ ↔ a ∈ s := by simp only [mem_inv, inv_inv]
@[simp, to_additive] lemma nonempty_inv : s⁻¹.nonempty ↔ s.nonempty :=
inv_involutive.surjective.nonempty_preimage
@[to_additive] lemma nonempty.inv (h : s.nonempty) : s⁻¹.nonempty := nonempty_inv.2 h
@[to_additive] lemma finite.inv (hs : s.finite) : s⁻¹.finite :=
hs.preimage $ inv_injective.inj_on _
@[simp, to_additive]
lemma image_inv : has_inv.inv '' s = s⁻¹ :=
congr_fun (image_eq_preimage_of_inverse inv_involutive.left_inverse inv_involutive.right_inverse) _
@[simp, to_additive]
instance : has_involutive_inv (set α) :=
{ inv := has_inv.inv,
inv_inv := λ s, by { simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] } }
@[simp, to_additive]
lemma inv_subset_inv : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t :=
(equiv.inv α).surjective.preimage_subset_preimage_iff
@[to_additive] lemma inv_subset : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ := by { rw [← inv_subset_inv, inv_inv] }
@[simp, to_additive] lemma inv_singleton (a : α) : ({a} : set α)⁻¹ = {a⁻¹} :=
by rw [←image_inv, image_singleton]
@[to_additive] lemma inv_range {ι : Sort*} {f : ι → α} : (range f)⁻¹ = range (λ i, (f i)⁻¹) :=
by { rw ←image_inv, exact (range_comp _ _).symm }
open mul_opposite
@[to_additive]
lemma image_op_inv : op '' s⁻¹ = (op '' s)⁻¹ :=
by simp_rw [←image_inv, function.semiconj.set_image op_inv s]
end has_involutive_inv
end inv
open_locale pointwise
/-! ### Set addition/multiplication -/
section has_mul
variables {ι : Sort*} {κ : ι → Sort*} [has_mul α] {s s₁ s₂ t t₁ t₂ u : set α} {a b : α}
/-- The pointwise multiplication of sets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}` in
locale `pointwise`. -/
@[to_additive "The pointwise addition of sets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in
locale `pointwise`."]
protected def has_mul : has_mul (set α) := ⟨image2 (*)⟩
localized "attribute [instance] set.has_mul set.has_add" in pointwise
@[simp, to_additive]
lemma image2_mul : image2 has_mul.mul s t = s * t := rfl
@[to_additive]
lemma mem_mul : a ∈ s * t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x * y = a := iff.rfl
@[to_additive] lemma mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t := mem_image2_of_mem
@[to_additive add_image_prod]
lemma image_mul_prod : (λ x : α × α, x.fst * x.snd) '' s ×ˢ t = s * t := image_prod _
@[simp, to_additive] lemma empty_mul : ∅ * s = ∅ := image2_empty_left
@[simp, to_additive] lemma mul_empty : s * ∅ = ∅ := image2_empty_right
@[simp, to_additive] lemma mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff
@[simp, to_additive] lemma mul_nonempty : (s * t).nonempty ↔ s.nonempty ∧ t.nonempty :=
image2_nonempty_iff
@[to_additive] lemma nonempty.mul : s.nonempty → t.nonempty → (s * t).nonempty := nonempty.image2
@[to_additive] lemma nonempty.of_mul_left : (s * t).nonempty → s.nonempty := nonempty.of_image2_left
@[to_additive] lemma nonempty.of_mul_right : (s * t).nonempty → t.nonempty :=
nonempty.of_image2_right
@[simp, to_additive] lemma mul_singleton : s * {b} = (* b) '' s := image2_singleton_right
@[simp, to_additive] lemma singleton_mul : {a} * t = ((*) a) '' t := image2_singleton_left
@[simp, to_additive] lemma singleton_mul_singleton : ({a} : set α) * {b} = {a * b} :=
image2_singleton
@[to_additive, mono] lemma mul_subset_mul : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ * s₂ ⊆ t₁ * t₂ := image2_subset
@[to_additive] lemma mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ := image2_subset_left
@[to_additive] lemma mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t := image2_subset_right
@[to_additive] lemma mul_subset_iff : s * t ⊆ u ↔ ∀ (x ∈ s) (y ∈ t), x * y ∈ u := image2_subset_iff
attribute [mono] add_subset_add
@[to_additive] lemma union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t := image2_union_left
@[to_additive] lemma mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ := image2_union_right
@[to_additive] lemma inter_mul_subset : (s₁ ∩ s₂) * t ⊆ s₁ * t ∩ (s₂ * t) :=
image2_inter_subset_left
@[to_additive] lemma mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) :=
image2_inter_subset_right
@[to_additive] lemma Union_mul_left_image : (⋃ a ∈ s, ((*) a) '' t) = s * t := Union_image_left _
@[to_additive] lemma Union_mul_right_image : (⋃ a ∈ t, (* a) '' s) = s * t := Union_image_right _
@[to_additive] lemma Union_mul (s : ι → set α) (t : set α) : (⋃ i, s i) * t = ⋃ i, s i * t :=
image2_Union_left _ _ _
@[to_additive] lemma mul_Union (s : set α) (t : ι → set α) : s * (⋃ i, t i) = ⋃ i, s * t i :=
image2_Union_right _ _ _
@[to_additive]
lemma Union₂_mul (s : Π i, κ i → set α) (t : set α) : (⋃ i j, s i j) * t = ⋃ i j, s i j * t :=
image2_Union₂_left _ _ _
@[to_additive]
lemma mul_Union₂ (s : set α) (t : Π i, κ i → set α) : s * (⋃ i j, t i j) = ⋃ i j, s * t i j :=
image2_Union₂_right _ _ _
@[to_additive]
lemma Inter_mul_subset (s : ι → set α) (t : set α) : (⋂ i, s i) * t ⊆ ⋂ i, s i * t :=
image2_Inter_subset_left _ _ _
@[to_additive]
lemma mul_Inter_subset (s : set α) (t : ι → set α) : s * (⋂ i, t i) ⊆ ⋂ i, s * t i :=
image2_Inter_subset_right _ _ _
@[to_additive]
lemma Inter₂_mul_subset (s : Π i, κ i → set α) (t : set α) :
(⋂ i j, s i j) * t ⊆ ⋂ i j, s i j * t :=
image2_Inter₂_subset_left _ _ _
@[to_additive]
lemma mul_Inter₂_subset (s : set α) (t : Π i, κ i → set α) :
s * (⋂ i j, t i j) ⊆ ⋂ i j, s * t i j :=
image2_Inter₂_subset_right _ _ _
@[to_additive] lemma finite.mul : s.finite → t.finite → (s * t).finite := finite.image2 _
/-- Multiplication preserves finiteness. -/
@[to_additive "Addition preserves finiteness."]
def fintype_mul [decidable_eq α] (s t : set α) [fintype s] [fintype t] : fintype (s * t : set α) :=
set.fintype_image2 _ _ _
/-- The singleton operation as a `mul_hom`. -/
@[to_additive "The singleton operation as an `add_hom`."]
def singleton_mul_hom : α →ₙ* set α := ⟨singleton, λ a b, singleton_mul_singleton.symm⟩
@[simp, to_additive] lemma coe_singleton_mul_hom : (singleton_mul_hom : α → set α) = singleton :=
rfl
@[simp, to_additive] lemma singleton_mul_hom_apply (a : α) : singleton_mul_hom a = {a} := rfl
open mul_opposite
@[simp, to_additive]
lemma image_op_mul : op '' (s * t) = op '' t * op '' s := image_image2_antidistrib op_mul
end has_mul
/-! ### Set subtraction/division -/
section has_div
variables {ι : Sort*} {κ : ι → Sort*} [has_div α] {s s₁ s₂ t t₁ t₂ u : set α} {a b : α}
/-- The pointwise division of sets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale
`pointwise`. -/
@[to_additive "The pointwise subtraction of sets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}` in
locale `pointwise`."]
protected def has_div : has_div (set α) := ⟨image2 (/)⟩
localized "attribute [instance] set.has_div set.has_sub" in pointwise
@[simp, to_additive]
lemma image2_div : image2 has_div.div s t = s / t := rfl
@[to_additive]
lemma mem_div : a ∈ s / t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x / y = a := iff.rfl
@[to_additive] lemma div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t := mem_image2_of_mem
@[to_additive add_image_prod]
lemma image_div_prod : (λ x : α × α, x.fst / x.snd) '' s ×ˢ t = s / t := image_prod _
@[simp, to_additive] lemma empty_div : ∅ / s = ∅ := image2_empty_left
@[simp, to_additive] lemma div_empty : s / ∅ = ∅ := image2_empty_right
@[simp, to_additive] lemma div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff
@[simp, to_additive] lemma div_nonempty : (s / t).nonempty ↔ s.nonempty ∧ t.nonempty :=
image2_nonempty_iff
@[to_additive] lemma nonempty.div : s.nonempty → t.nonempty → (s / t).nonempty := nonempty.image2
@[to_additive] lemma nonempty.of_div_left : (s / t).nonempty → s.nonempty := nonempty.of_image2_left
@[to_additive] lemma nonempty.of_div_right : (s / t).nonempty → t.nonempty :=
nonempty.of_image2_right
@[simp, to_additive] lemma div_singleton : s / {b} = (/ b) '' s := image2_singleton_right
@[simp, to_additive] lemma singleton_div : {a} / t = ((/) a) '' t := image2_singleton_left
@[simp, to_additive] lemma singleton_div_singleton : ({a} : set α) / {b} = {a / b} :=
image2_singleton
@[to_additive, mono] lemma div_subset_div : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ / s₂ ⊆ t₁ / t₂ := image2_subset
@[to_additive] lemma div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ := image2_subset_left
@[to_additive] lemma div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t := image2_subset_right
@[to_additive] lemma div_subset_iff : s / t ⊆ u ↔ ∀ (x ∈ s) (y ∈ t), x / y ∈ u := image2_subset_iff
attribute [mono] sub_subset_sub
@[to_additive] lemma union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t := image2_union_left
@[to_additive] lemma div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ := image2_union_right
@[to_additive] lemma inter_div_subset : (s₁ ∩ s₂) / t ⊆ s₁ / t ∩ (s₂ / t) :=
image2_inter_subset_left
@[to_additive] lemma div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) :=
image2_inter_subset_right
@[to_additive] lemma Union_div_left_image : (⋃ a ∈ s, ((/) a) '' t) = s / t := Union_image_left _
@[to_additive] lemma Union_div_right_image : (⋃ a ∈ t, (/ a) '' s) = s / t := Union_image_right _
@[to_additive] lemma Union_div (s : ι → set α) (t : set α) : (⋃ i, s i) / t = ⋃ i, s i / t :=
image2_Union_left _ _ _
@[to_additive] lemma div_Union (s : set α) (t : ι → set α) : s / (⋃ i, t i) = ⋃ i, s / t i :=
image2_Union_right _ _ _
@[to_additive]
lemma Union₂_div (s : Π i, κ i → set α) (t : set α) : (⋃ i j, s i j) / t = ⋃ i j, s i j / t :=
image2_Union₂_left _ _ _
@[to_additive]
lemma div_Union₂ (s : set α) (t : Π i, κ i → set α) : s / (⋃ i j, t i j) = ⋃ i j, s / t i j :=
image2_Union₂_right _ _ _
@[to_additive]
lemma Inter_div_subset (s : ι → set α) (t : set α) : (⋂ i, s i) / t ⊆ ⋂ i, s i / t :=
image2_Inter_subset_left _ _ _
@[to_additive]
lemma div_Inter_subset (s : set α) (t : ι → set α) : s / (⋂ i, t i) ⊆ ⋂ i, s / t i :=
image2_Inter_subset_right _ _ _
@[to_additive]
lemma Inter₂_div_subset (s : Π i, κ i → set α) (t : set α) :
(⋂ i j, s i j) / t ⊆ ⋂ i j, s i j / t :=
image2_Inter₂_subset_left _ _ _
@[to_additive]
lemma div_Inter₂_subset (s : set α) (t : Π i, κ i → set α) :
s / (⋂ i j, t i j) ⊆ ⋂ i j, s / t i j :=
image2_Inter₂_subset_right _ _ _
end has_div
open_locale pointwise
/-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `finset`. See
note [pointwise nat action].-/
protected def has_nsmul [has_zero α] [has_add α] : has_smul ℕ (set α) := ⟨nsmul_rec⟩
/-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a
`set`. See note [pointwise nat action]. -/
@[to_additive]
protected def has_npow [has_one α] [has_mul α] : has_pow (set α) ℕ := ⟨λ s n, npow_rec n s⟩
/-- Repeated pointwise addition/subtraction (not the same as pointwise repeated
addition/subtraction!) of a `set`. See note [pointwise nat action]. -/
protected def has_zsmul [has_zero α] [has_add α] [has_neg α] : has_smul ℤ (set α) := ⟨zsmul_rec⟩
/-- Repeated pointwise multiplication/division (not the same as pointwise repeated
multiplication/division!) of a `set`. See note [pointwise nat action]. -/
@[to_additive] protected def has_zpow [has_one α] [has_mul α] [has_inv α] : has_pow (set α) ℤ :=
⟨λ s n, zpow_rec n s⟩
localized "attribute [instance] set.has_nsmul set.has_npow set.has_zsmul set.has_zpow" in pointwise
/-- `set α` is a `semigroup` under pointwise operations if `α` is. -/
@[to_additive "`set α` is an `add_semigroup` under pointwise operations if `α` is."]
protected def semigroup [semigroup α] : semigroup (set α) :=
{ mul_assoc := λ _ _ _, image2_assoc mul_assoc,
..set.has_mul }
/-- `set α` is a `comm_semigroup` under pointwise operations if `α` is. -/
@[to_additive "`set α` is an `add_comm_semigroup` under pointwise operations if `α` is."]
protected def comm_semigroup [comm_semigroup α] : comm_semigroup (set α) :=
{ mul_comm := λ s t, image2_comm mul_comm
..set.semigroup }
section mul_one_class
variables [mul_one_class α]
/-- `set α` is a `mul_one_class` under pointwise operations if `α` is. -/
@[to_additive "`set α` is an `add_zero_class` under pointwise operations if `α` is."]
protected def mul_one_class : mul_one_class (set α) :=
{ mul_one := λ s, by { simp only [← singleton_one, mul_singleton, mul_one, image_id'] },
one_mul := λ s, by { simp only [← singleton_one, singleton_mul, one_mul, image_id'] },
..set.has_one, ..set.has_mul }
localized "attribute [instance] set.mul_one_class set.add_zero_class set.semigroup set.add_semigroup
set.comm_semigroup set.add_comm_semigroup" in pointwise
@[to_additive] lemma subset_mul_left (s : set α) {t : set α} (ht : (1 : α) ∈ t) : s ⊆ s * t :=
λ x hx, ⟨x, 1, hx, ht, mul_one _⟩
@[to_additive] lemma subset_mul_right {s : set α} (t : set α) (hs : (1 : α) ∈ s) : t ⊆ s * t :=
λ x hx, ⟨1, x, hs, hx, one_mul _⟩
/-- The singleton operation as a `monoid_hom`. -/
@[to_additive "The singleton operation as an `add_monoid_hom`."]
def singleton_monoid_hom : α →* set α := { ..singleton_mul_hom, ..singleton_one_hom }
@[simp, to_additive] lemma coe_singleton_monoid_hom :
(singleton_monoid_hom : α → set α) = singleton := rfl
@[simp, to_additive] lemma singleton_monoid_hom_apply (a : α) : singleton_monoid_hom a = {a} := rfl
end mul_one_class
section monoid
variables [monoid α] {s t : set α} {a : α} {m n : ℕ}
/-- `set α` is a `monoid` under pointwise operations if `α` is. -/
@[to_additive "`set α` is an `add_monoid` under pointwise operations if `α` is."]
protected def monoid : monoid (set α) := { ..set.semigroup, ..set.mul_one_class, ..set.has_npow }
localized "attribute [instance] set.monoid set.add_monoid" in pointwise
@[to_additive]
instance decidable_mem_mul [fintype α] [decidable_eq α] [decidable_pred (∈ s)]
[decidable_pred (∈ t)] :
decidable_pred (∈ s * t) :=
λ _, decidable_of_iff _ mem_mul.symm
@[to_additive]
instance decidable_mem_pow [fintype α] [decidable_eq α] [decidable_pred (∈ s)] (n : ℕ) :
decidable_pred (∈ (s ^ n)) :=
begin
induction n with n ih,
{ simp_rw [pow_zero, mem_one], apply_instance },
{ letI := ih, rw pow_succ, apply_instance }
end
@[to_additive] lemma pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n
| 0 := by { rw pow_zero, exact one_mem_one }
| (n + 1) := by { rw pow_succ, exact mul_mem_mul ha (pow_mem_pow _) }
@[to_additive] lemma pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n
| 0 := by { rw pow_zero, exact subset.rfl }
| (n + 1) := by { rw pow_succ, exact mul_subset_mul hst (pow_subset_pow _) }
@[to_additive] lemma pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) : m ≤ n → s ^ m ⊆ s ^ n :=
begin
refine nat.le_induction _ (λ n h ih, _) _,
{ exact subset.rfl },
{ rw pow_succ,
exact ih.trans (subset_mul_right _ hs) }
end
@[to_additive] lemma mem_prod_list_of_fn {a : α} {s : fin n → set α} :
a ∈ (list.of_fn s).prod ↔ ∃ f : (Π i : fin n, s i), (list.of_fn (λ i, (f i : α))).prod = a :=
begin
induction n with n ih generalizing a,
{ simp_rw [list.of_fn_zero, list.prod_nil, fin.exists_fin_zero_pi, eq_comm, set.mem_one] },
{ simp_rw [list.of_fn_succ, list.prod_cons, fin.exists_fin_succ_pi, fin.cons_zero, fin.cons_succ,
mem_mul, @ih, exists_and_distrib_left, exists_exists_eq_and, set_coe.exists, subtype.coe_mk,
exists_prop] }
end
@[to_additive] lemma mem_list_prod {l : list (set α)} {a : α} :
a ∈ l.prod ↔ ∃ l' : list (Σ s : set α, ↥s),
list.prod (l'.map (λ x, (sigma.snd x : α))) = a ∧ l'.map sigma.fst = l :=
begin
induction l using list.of_fn_rec with n f,
simp_rw [list.exists_iff_exists_tuple, list.map_of_fn, list.of_fn_inj', and.left_comm,
exists_and_distrib_left, exists_eq_left, heq_iff_eq, function.comp, mem_prod_list_of_fn],
split,
{ rintros ⟨fi, rfl⟩, exact ⟨λ i, ⟨_, fi i⟩, rfl, rfl⟩, },
{ rintros ⟨fi, rfl, rfl⟩, exact ⟨λ i, _, rfl⟩, },
end
@[to_additive] lemma mem_pow {a : α} {n : ℕ} :
a ∈ s ^ n ↔ ∃ f : fin n → s, (list.of_fn (λ i, (f i : α))).prod = a :=
by rw [←mem_prod_list_of_fn, list.of_fn_const, list.prod_repeat]
@[simp, to_additive] lemma empty_pow {n : ℕ} (hn : n ≠ 0) : (∅ : set α) ^ n = ∅ :=
by rw [← tsub_add_cancel_of_le (nat.succ_le_of_lt $ nat.pos_of_ne_zero hn), pow_succ, empty_mul]
@[to_additive] lemma mul_univ_of_one_mem (hs : (1 : α) ∈ s) : s * univ = univ :=
eq_univ_iff_forall.2 $ λ a, mem_mul.2 ⟨_, _, hs, mem_univ _, one_mul _⟩
@[to_additive] lemma univ_mul_of_one_mem (ht : (1 : α) ∈ t) : univ * t = univ :=
eq_univ_iff_forall.2 $ λ a, mem_mul.2 ⟨_, _, mem_univ _, ht, mul_one _⟩
@[simp, to_additive] lemma univ_mul_univ : (univ : set α) * univ = univ :=
mul_univ_of_one_mem $ mem_univ _
--TODO: `to_additive` trips up on the `1 : ℕ` used in the pattern-matching.
@[simp] lemma nsmul_univ {α : Type*} [add_monoid α] : ∀ {n : ℕ}, n ≠ 0 → n • (univ : set α) = univ
| 0 := λ h, (h rfl).elim
| 1 := λ _, one_nsmul _
| (n + 2) := λ _, by { rw [succ_nsmul, nsmul_univ n.succ_ne_zero, univ_add_univ] }
@[simp, to_additive nsmul_univ] lemma univ_pow : ∀ {n : ℕ}, n ≠ 0 → (univ : set α) ^ n = univ
| 0 := λ h, (h rfl).elim
| 1 := λ _, pow_one _
| (n + 2) := λ _, by { rw [pow_succ, univ_pow n.succ_ne_zero, univ_mul_univ] }
@[to_additive] protected lemma _root_.is_unit.set : is_unit a → is_unit ({a} : set α) :=
is_unit.map (singleton_monoid_hom : α →* set α)
end monoid
/-- `set α` is a `comm_monoid` under pointwise operations if `α` is. -/
@[to_additive "`set α` is an `add_comm_monoid` under pointwise operations if `α` is."]
protected def comm_monoid [comm_monoid α] : comm_monoid (set α) :=
{ ..set.monoid, ..set.comm_semigroup }
localized "attribute [instance] set.comm_monoid set.add_comm_monoid" in pointwise
open_locale pointwise
section division_monoid
variables [division_monoid α] {s t : set α}
@[to_additive] protected lemma mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 :=
begin
refine ⟨λ h, _, _⟩,
{ have hst : (s * t).nonempty := h.symm.subst one_nonempty,
obtain ⟨a, ha⟩ := hst.of_image2_left,
obtain ⟨b, hb⟩ := hst.of_image2_right,
have H : ∀ {a b}, a ∈ s → b ∈ t → a * b = (1 : α) :=
λ a b ha hb, (h.subset $ mem_image2_of_mem ha hb),
refine ⟨a, b, _, _, H ha hb⟩; refine eq_singleton_iff_unique_mem.2 ⟨‹_›, λ x hx, _⟩,
{ exact (eq_inv_of_mul_eq_one_left $ H hx hb).trans (inv_eq_of_mul_eq_one_left $ H ha hb) },
{ exact (eq_inv_of_mul_eq_one_right $ H ha hx).trans (inv_eq_of_mul_eq_one_right $ H ha hb) } },
{ rintro ⟨b, c, rfl, rfl, h⟩,
rw [singleton_mul_singleton, h, singleton_one] }
end
/-- `set α` is a division monoid under pointwise operations if `α` is. -/
@[to_additive subtraction_monoid "`set α` is a subtraction monoid under pointwise operations if `α`
is."]
protected def division_monoid : division_monoid (set α) :=
{ mul_inv_rev := λ s t, by { simp_rw ←image_inv, exact image_image2_antidistrib mul_inv_rev },
inv_eq_of_mul := λ s t h, begin
obtain ⟨a, b, rfl, rfl, hab⟩ := set.mul_eq_one_iff.1 h,
rw [inv_singleton, inv_eq_of_mul_eq_one_right hab],
end,
div_eq_mul_inv := λ s t,
by { rw [←image_id (s / t), ←image_inv], exact image_image2_distrib_right div_eq_mul_inv },
..set.monoid, ..set.has_involutive_inv, ..set.has_div, ..set.has_zpow }
@[simp, to_additive] lemma is_unit_iff : is_unit s ↔ ∃ a, s = {a} ∧ is_unit a :=
begin
split,
{ rintro ⟨u, rfl⟩,
obtain ⟨a, b, ha, hb, h⟩ := set.mul_eq_one_iff.1 u.mul_inv,
refine ⟨a, ha, ⟨a, b, h, singleton_injective _⟩, rfl⟩,
rw [←singleton_mul_singleton, ←ha, ←hb],
exact u.inv_mul },
{ rintro ⟨a, rfl, ha⟩,
exact ha.set }
end
end division_monoid
/-- `set α` is a commutative division monoid under pointwise operations if `α` is. -/
@[to_additive subtraction_comm_monoid "`set α` is a commutative subtraction monoid under pointwise
operations if `α` is."]
protected def division_comm_monoid [division_comm_monoid α] : division_comm_monoid (set α) :=
{ ..set.division_monoid, ..set.comm_semigroup }
/-- `set α` has distributive negation if `α` has. -/
protected def has_distrib_neg [has_mul α] [has_distrib_neg α] : has_distrib_neg (set α) :=
{ neg_mul := λ _ _, by { simp_rw ←image_neg, exact image2_image_left_comm neg_mul },
mul_neg := λ _ _, by { simp_rw ←image_neg, exact image_image2_right_comm mul_neg },
..set.has_involutive_neg }
localized "attribute [instance] set.division_monoid set.subtraction_monoid set.division_comm_monoid
set.subtraction_comm_monoid set.has_distrib_neg" in pointwise
section distrib
variables [distrib α] (s t u : set α)
/-!
Note that `set α` is not a `distrib` because `s * t + s * u` has cross terms that `s * (t + u)`
lacks.
-/
lemma mul_add_subset : s * (t + u) ⊆ s * t + s * u := image2_distrib_subset_left mul_add
lemma add_mul_subset : (s + t) * u ⊆ s * u + t * u := image2_distrib_subset_right add_mul
end distrib
section mul_zero_class
variables [mul_zero_class α] {s t : set α}
/-! Note that `set` is not a `mul_zero_class` because `0 * ∅ ≠ 0`. -/
lemma mul_zero_subset (s : set α) : s * 0 ⊆ 0 := by simp [subset_def, mem_mul]
lemma zero_mul_subset (s : set α) : 0 * s ⊆ 0 := by simp [subset_def, mem_mul]
lemma nonempty.mul_zero (hs : s.nonempty) : s * 0 = 0 :=
s.mul_zero_subset.antisymm $ by simpa [mem_mul] using hs
lemma nonempty.zero_mul (hs : s.nonempty) : 0 * s = 0 :=
s.zero_mul_subset.antisymm $ by simpa [mem_mul] using hs
end mul_zero_class
section group
variables [group α] {s t : set α} {a b : α}
/-! Note that `set` is not a `group` because `s / s ≠ 1` in general. -/
@[simp, to_additive] lemma one_mem_div_iff : (1 : α) ∈ s / t ↔ ¬ disjoint s t :=
by simp [not_disjoint_iff_nonempty_inter, mem_div, div_eq_one, set.nonempty]
@[to_additive] lemma not_one_mem_div_iff : (1 : α) ∉ s / t ↔ disjoint s t :=
one_mem_div_iff.not_left
alias not_one_mem_div_iff ↔ _ _root_.disjoint.one_not_mem_div_set
attribute [to_additive] disjoint.one_not_mem_div_set
@[to_additive] lemma nonempty.one_mem_div (h : s.nonempty) : (1 : α) ∈ s / s :=
let ⟨a, ha⟩ := h in mem_div.2 ⟨a, a, ha, ha, div_self' _⟩
@[to_additive] lemma is_unit_singleton (a : α) : is_unit ({a} : set α) := (group.is_unit a).set
@[simp, to_additive] lemma is_unit_iff_singleton : is_unit s ↔ ∃ a, s = {a} :=
by simp only [is_unit_iff, group.is_unit, and_true]
@[simp, to_additive] lemma image_mul_left : ((*) a) '' t = ((*) a⁻¹) ⁻¹' t :=
by { rw image_eq_preimage_of_inverse; intro c; simp }
@[simp, to_additive] lemma image_mul_right : (* b) '' t = (* b⁻¹) ⁻¹' t :=
by { rw image_eq_preimage_of_inverse; intro c; simp }
@[to_additive] lemma image_mul_left' : (λ b, a⁻¹ * b) '' t = (λ b, a * b) ⁻¹' t := by simp
@[to_additive] lemma image_mul_right' : (* b⁻¹) '' t = (* b) ⁻¹' t := by simp
@[simp, to_additive] lemma preimage_mul_left_singleton : ((*) a) ⁻¹' {b} = {a⁻¹ * b} :=
by rw [← image_mul_left', image_singleton]
@[simp, to_additive] lemma preimage_mul_right_singleton : (* a) ⁻¹' {b} = {b * a⁻¹} :=
by rw [← image_mul_right', image_singleton]
@[simp, to_additive] lemma preimage_mul_left_one : ((*) a) ⁻¹' 1 = {a⁻¹} :=
by rw [← image_mul_left', image_one, mul_one]
@[simp, to_additive] lemma preimage_mul_right_one : (* b) ⁻¹' 1 = {b⁻¹} :=
by rw [← image_mul_right', image_one, one_mul]
@[to_additive] lemma preimage_mul_left_one' : (λ b, a⁻¹ * b) ⁻¹' 1 = {a} := by simp
@[to_additive] lemma preimage_mul_right_one' : (* b⁻¹) ⁻¹' 1 = {b} := by simp
@[simp, to_additive] lemma mul_univ (hs : s.nonempty) : s * (univ : set α) = univ :=
let ⟨a, ha⟩ := hs in eq_univ_of_forall $ λ b, ⟨a, a⁻¹ * b, ha, trivial, mul_inv_cancel_left _ _⟩
@[simp, to_additive] lemma univ_mul (ht : t.nonempty) : (univ : set α) * t = univ :=
let ⟨a, ha⟩ := ht in eq_univ_of_forall $ λ b, ⟨b * a⁻¹, a, trivial, ha, inv_mul_cancel_right _ _⟩
end group
section group_with_zero
variables [group_with_zero α] {s t : set α}
lemma div_zero_subset (s : set α) : s / 0 ⊆ 0 := by simp [subset_def, mem_div]
lemma zero_div_subset (s : set α) : 0 / s ⊆ 0 := by simp [subset_def, mem_div]
lemma nonempty.div_zero (hs : s.nonempty) : s / 0 = 0 :=
s.div_zero_subset.antisymm $ by simpa [mem_div] using hs
lemma nonempty.zero_div (hs : s.nonempty) : 0 / s = 0 :=
s.zero_div_subset.antisymm $ by simpa [mem_div] using hs
end group_with_zero
section has_mul
variables [has_mul α] [has_mul β] [mul_hom_class F α β] (m : F) {s t : set α}
include α β
@[to_additive] lemma image_mul : m '' (s * t) = m '' s * m '' t := image_image2_distrib $ map_mul m
@[to_additive]
lemma preimage_mul_preimage_subset {s t : set β} : m ⁻¹' s * m ⁻¹' t ⊆ m ⁻¹' (s * t) :=
by { rintro _ ⟨_, _, _, _, rfl⟩, exact ⟨_, _, ‹_›, ‹_›, (map_mul m _ _).symm ⟩ }
end has_mul
section group
variables [group α] [division_monoid β] [monoid_hom_class F α β] (m : F) {s t : set α}
include α β
@[to_additive] lemma image_div : m '' (s / t) = m '' s / m '' t := image_image2_distrib $ map_div m
@[to_additive]
lemma preimage_div_preimage_subset {s t : set β} : m ⁻¹' s / m ⁻¹' t ⊆ m ⁻¹' (s / t) :=
by { rintro _ ⟨_, _, _, _, rfl⟩, exact ⟨_, _, ‹_›, ‹_›, (map_div m _ _).symm ⟩ }
end group
@[to_additive]
lemma bdd_above_mul [ordered_comm_monoid α] {A B : set α} :
bdd_above A → bdd_above B → bdd_above (A * B) :=
begin
rintro ⟨bA, hbA⟩ ⟨bB, hbB⟩,
use bA * bB,
rintro x ⟨xa, xb, hxa, hxb, rfl⟩,
exact mul_le_mul' (hbA hxa) (hbB hxb),
end
open_locale pointwise
section big_operators
open_locale big_operators
variables {ι : Type*} [comm_monoid α]
/-- The n-ary version of `set.mem_mul`. -/
@[to_additive /-" The n-ary version of `set.mem_add`. "-/]
lemma mem_finset_prod (t : finset ι) (f : ι → set α) (a : α) :
a ∈ ∏ i in t, f i ↔ ∃ (g : ι → α) (hg : ∀ {i}, i ∈ t → g i ∈ f i), ∏ i in t, g i = a :=
begin
classical,
induction t using finset.induction_on with i is hi ih generalizing a,
{ simp_rw [finset.prod_empty, set.mem_one],
exact ⟨λ h, ⟨λ i, a, λ i, false.elim, h.symm⟩, λ ⟨f, _, hf⟩, hf.symm⟩ },
rw [finset.prod_insert hi, set.mem_mul],
simp_rw [finset.prod_insert hi],
simp_rw ih,
split,
{ rintro ⟨x, y, hx, ⟨g, hg, rfl⟩, rfl⟩,
refine ⟨function.update g i x, λ j hj, _, _⟩,
obtain rfl | hj := finset.mem_insert.mp hj,
{ rw function.update_same, exact hx },
{ rw update_noteq (ne_of_mem_of_not_mem hj hi), exact hg hj, },
rw [finset.prod_update_of_not_mem hi, function.update_same], },
{ rintro ⟨g, hg, rfl⟩,
exact ⟨g i, is.prod g, hg (is.mem_insert_self _),
⟨g, λ i hi, hg (finset.mem_insert_of_mem hi), rfl⟩, rfl⟩ },
end
/-- A version of `set.mem_finset_prod` with a simpler RHS for products over a fintype. -/
@[to_additive /-" A version of `set.mem_finset_sum` with a simpler RHS for sums over a fintype. "-/]
lemma mem_fintype_prod [fintype ι] (f : ι → set α) (a : α) :
a ∈ ∏ i, f i ↔ ∃ (g : ι → α) (hg : ∀ i, g i ∈ f i), ∏ i, g i = a :=
by { rw mem_finset_prod, simp }
/-- An n-ary version of `set.mul_mem_mul`. -/
@[to_additive /-" An n-ary version of `set.add_mem_add`. "-/]
lemma list_prod_mem_list_prod (t : list ι) (f : ι → set α)
(g : ι → α) (hg : ∀ i ∈ t, g i ∈ f i) :
(t.map g).prod ∈ (t.map f).prod :=
begin
induction t with h tl ih,
{ simp_rw [list.map_nil, list.prod_nil, set.mem_one] },
{ simp_rw [list.map_cons, list.prod_cons],
exact mul_mem_mul
(hg h $ list.mem_cons_self _ _) (ih $ λ i hi, hg i $ list.mem_cons_of_mem _ hi) }
end
/-- An n-ary version of `set.mul_subset_mul`. -/
@[to_additive /-" An n-ary version of `set.add_subset_add`. "-/]
lemma list_prod_subset_list_prod (t : list ι) (f₁ f₂ : ι → set α) (hf : ∀ i ∈ t, f₁ i ⊆ f₂ i) :
(t.map f₁).prod ⊆ (t.map f₂).prod :=
begin
induction t with h tl ih,
{ refl, },
{ simp_rw [list.map_cons, list.prod_cons],
exact mul_subset_mul
(hf h $ list.mem_cons_self _ _) (ih $ λ i hi, hf i $ list.mem_cons_of_mem _ hi) }
end
@[to_additive]
lemma list_prod_singleton {M : Type*} [comm_monoid M] (s : list M) :
(s.map $ λ i, ({i} : set M)).prod = {s.prod} :=
(map_list_prod (singleton_monoid_hom : M →* set M) _).symm
/-- An n-ary version of `set.mul_mem_mul`. -/
@[to_additive /-" An n-ary version of `set.add_mem_add`. "-/]
lemma multiset_prod_mem_multiset_prod (t : multiset ι) (f : ι → set α)
(g : ι → α) (hg : ∀ i ∈ t, g i ∈ f i) :
(t.map g).prod ∈ (t.map f).prod :=
begin
induction t using quotient.induction_on,
simp_rw [multiset.quot_mk_to_coe, multiset.coe_map, multiset.coe_prod],
exact list_prod_mem_list_prod _ _ _ hg,
end
/-- An n-ary version of `set.mul_subset_mul`. -/
@[to_additive /-" An n-ary version of `set.add_subset_add`. "-/]
lemma multiset_prod_subset_multiset_prod (t : multiset ι) (f₁ f₂ : ι → set α)
(hf : ∀ i ∈ t, f₁ i ⊆ f₂ i) :
(t.map f₁).prod ⊆ (t.map f₂).prod :=
begin
induction t using quotient.induction_on,
simp_rw [multiset.quot_mk_to_coe, multiset.coe_map, multiset.coe_prod],
exact list_prod_subset_list_prod _ _ _ hf,
end
@[to_additive]
lemma multiset_prod_singleton {M : Type*} [comm_monoid M] (s : multiset M) :
(s.map $ λ i, ({i} : set M)).prod = {s.prod} :=
(map_multiset_prod (singleton_monoid_hom : M →* set M) _).symm
/-- An n-ary version of `set.mul_mem_mul`. -/
@[to_additive /-" An n-ary version of `set.add_mem_add`. "-/]
lemma finset_prod_mem_finset_prod (t : finset ι) (f : ι → set α)
(g : ι → α) (hg : ∀ i ∈ t, g i ∈ f i) :
∏ i in t, g i ∈ ∏ i in t, f i :=
multiset_prod_mem_multiset_prod _ _ _ hg
/-- An n-ary version of `set.mul_subset_mul`. -/
@[to_additive /-" An n-ary version of `set.add_subset_add`. "-/]
lemma finset_prod_subset_finset_prod (t : finset ι) (f₁ f₂ : ι → set α)
(hf : ∀ i ∈ t, f₁ i ⊆ f₂ i) :
∏ i in t, f₁ i ⊆ ∏ i in t, f₂ i :=
multiset_prod_subset_multiset_prod _ _ _ hf
@[to_additive]
lemma finset_prod_singleton {M ι : Type*} [comm_monoid M] (s : finset ι) (I : ι → M) :
∏ (i : ι) in s, ({I i} : set M) = {∏ (i : ι) in s, I i} :=
(map_prod (singleton_monoid_hom : M →* set M) _ _).symm
/-! TODO: define `decidable_mem_finset_prod` and `decidable_mem_finset_sum`. -/
end big_operators
/-! ### Translation/scaling of sets -/
section smul
/-- The dilation of set `x • s` is defined as `{x • y | y ∈ s}` in locale `pointwise`. -/
@[to_additive "The translation of set `x +ᵥ s` is defined as `{x +ᵥ y | y ∈ s}` in
locale `pointwise`."]
protected def has_smul_set [has_smul α β] : has_smul α (set β) :=
⟨λ a, image (has_smul.smul a)⟩
/-- The pointwise scalar multiplication of sets `s • t` is defined as `{x • y | x ∈ s, y ∈ t}` in
locale `pointwise`. -/
@[to_additive "The pointwise scalar addition of sets `s +ᵥ t` is defined as
`{x +ᵥ y | x ∈ s, y ∈ t}` in locale `pointwise`."]
protected def has_smul [has_smul α β] : has_smul (set α) (set β) :=
⟨image2 has_smul.smul⟩
localized "attribute [instance] set.has_smul_set set.has_smul" in pointwise
localized "attribute [instance] set.has_vadd_set set.has_vadd" in pointwise
section has_smul
variables {ι : Sort*} {κ : ι → Sort*} [has_smul α β] {s s₁ s₂ : set α} {t t₁ t₂ u : set β} {a : α}
{b : β}
@[simp, to_additive]
lemma image2_smul : image2 has_smul.smul s t = s • t := rfl
@[to_additive add_image_prod]
lemma image_smul_prod : (λ x : α × β, x.fst • x.snd) '' s ×ˢ t = s • t := image_prod _
@[to_additive]
lemma mem_smul : b ∈ s • t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x • y = b := iff.rfl
@[to_additive] lemma smul_mem_smul : a ∈ s → b ∈ t → a • b ∈ s • t := mem_image2_of_mem
@[simp, to_additive] lemma empty_smul : (∅ : set α) • t = ∅ := image2_empty_left
@[simp, to_additive] lemma smul_empty : s • (∅ : set β) = ∅ := image2_empty_right
@[simp, to_additive] lemma smul_eq_empty : s • t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff
@[simp, to_additive] lemma smul_nonempty : (s • t).nonempty ↔ s.nonempty ∧ t.nonempty :=
image2_nonempty_iff
@[to_additive] lemma nonempty.smul : s.nonempty → t.nonempty → (s • t).nonempty := nonempty.image2
@[to_additive] lemma nonempty.of_smul_left : (s • t).nonempty → s.nonempty :=
nonempty.of_image2_left
@[to_additive] lemma nonempty.of_smul_right : (s • t).nonempty → t.nonempty :=
nonempty.of_image2_right
@[simp, to_additive] lemma smul_singleton : s • {b} = (• b) '' s := image2_singleton_right
@[simp, to_additive] lemma singleton_smul : ({a} : set α) • t = a • t := image2_singleton_left
@[simp, to_additive] lemma singleton_smul_singleton : ({a} : set α) • ({b} : set β) = {a • b} :=
image2_singleton
@[to_additive, mono] lemma smul_subset_smul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ • t₁ ⊆ s₂ • t₂ := image2_subset
@[to_additive] lemma smul_subset_smul_left : t₁ ⊆ t₂ → s • t₁ ⊆ s • t₂ := image2_subset_left
@[to_additive] lemma smul_subset_smul_right : s₁ ⊆ s₂ → s₁ • t ⊆ s₂ • t := image2_subset_right
@[to_additive] lemma smul_subset_iff : s • t ⊆ u ↔ ∀ (a ∈ s) (b ∈ t), a • b ∈ u := image2_subset_iff
attribute [mono] vadd_subset_vadd
@[to_additive] lemma union_smul : (s₁ ∪ s₂) • t = s₁ • t ∪ s₂ • t := image2_union_left
@[to_additive] lemma smul_union : s • (t₁ ∪ t₂) = s • t₁ ∪ s • t₂ := image2_union_right
@[to_additive] lemma inter_smul_subset : (s₁ ∩ s₂) • t ⊆ s₁ • t ∩ s₂ • t := image2_inter_subset_left
@[to_additive] lemma smul_inter_subset : s • (t₁ ∩ t₂) ⊆ s • t₁ ∩ s • t₂ :=
image2_inter_subset_right
@[to_additive] lemma Union_smul_left_image : (⋃ a ∈ s, a • t) = s • t := Union_image_left _
@[to_additive] lemma Union_smul_right_image : (⋃ a ∈ t, (• a) '' s) = s • t := Union_image_right _
@[to_additive] lemma Union_smul (s : ι → set α) (t : set β) : (⋃ i, s i) • t = ⋃ i, s i • t :=
image2_Union_left _ _ _
@[to_additive] lemma smul_Union (s : set α) (t : ι → set β) : s • (⋃ i, t i) = ⋃ i, s • t i :=
image2_Union_right _ _ _
@[to_additive]
lemma Union₂_smul (s : Π i, κ i → set α) (t : set β) : (⋃ i j, s i j) • t = ⋃ i j, s i j • t :=
image2_Union₂_left _ _ _
@[to_additive]
lemma smul_Union₂ (s : set α) (t : Π i, κ i → set β) : s • (⋃ i j, t i j) = ⋃ i j, s • t i j :=
image2_Union₂_right _ _ _
@[to_additive]
lemma Inter_smul_subset (s : ι → set α) (t : set β) : (⋂ i, s i) • t ⊆ ⋂ i, s i • t :=
image2_Inter_subset_left _ _ _
@[to_additive]
lemma smul_Inter_subset (s : set α) (t : ι → set β) : s • (⋂ i, t i) ⊆ ⋂ i, s • t i :=
image2_Inter_subset_right _ _ _
@[to_additive]
lemma Inter₂_smul_subset (s : Π i, κ i → set α) (t : set β) :
(⋂ i j, s i j) • t ⊆ ⋂ i j, s i j • t :=
image2_Inter₂_subset_left _ _ _
@[to_additive]
lemma smul_Inter₂_subset (s : set α) (t : Π i, κ i → set β) :
s • (⋂ i j, t i j) ⊆ ⋂ i j, s • t i j :=
image2_Inter₂_subset_right _ _ _
@[to_additive] lemma finite.smul : s.finite → t.finite → (s • t).finite := finite.image2 _
@[simp, to_additive] lemma bUnion_smul_set (s : set α) (t : set β) :
(⋃ a ∈ s, a • t) = s • t :=
Union_image_left _
end has_smul
section has_smul_set
variables {ι : Sort*} {κ : ι → Sort*} [has_smul α β] {s t t₁ t₂ : set β} {a : α} {b : β} {x y : β}
@[simp, to_additive] lemma image_smul : (λ x, a • x) '' t = a • t := rfl
@[to_additive] lemma mem_smul_set : x ∈ a • t ↔ ∃ y, y ∈ t ∧ a • y = x := iff.rfl
@[to_additive] lemma smul_mem_smul_set : b ∈ s → a • b ∈ a • s := mem_image_of_mem _
@[simp, to_additive] lemma smul_set_empty : a • (∅ : set β) = ∅ := image_empty _
@[simp, to_additive] lemma smul_set_eq_empty : a • s = ∅ ↔ s = ∅ := image_eq_empty
@[simp, to_additive] lemma smul_set_nonempty : (a • s).nonempty ↔ s.nonempty := nonempty_image_iff
@[simp, to_additive] lemma smul_set_singleton : a • ({b} : set β) = {a • b} := image_singleton
@[to_additive] lemma smul_set_mono : s ⊆ t → a • s ⊆ a • t := image_subset _
@[to_additive] lemma smul_set_subset_iff : a • s ⊆ t ↔ ∀ ⦃b⦄, b ∈ s → a • b ∈ t := image_subset_iff
@[to_additive] lemma smul_set_union : a • (t₁ ∪ t₂) = a • t₁ ∪ a • t₂ := image_union _ _ _
@[to_additive]
lemma smul_set_inter_subset : a • (t₁ ∩ t₂) ⊆ a • t₁ ∩ (a • t₂) := image_inter_subset _ _ _
@[to_additive]
lemma smul_set_Union (a : α) (s : ι → set β) : a • (⋃ i, s i) = ⋃ i, a • s i := image_Union
@[to_additive]
lemma smul_set_Union₂ (a : α) (s : Π i, κ i → set β) : a • (⋃ i j, s i j) = ⋃ i j, a • s i j :=
image_Union₂ _ _
@[to_additive]
lemma smul_set_Inter_subset (a : α) (t : ι → set β) : a • (⋂ i, t i) ⊆ ⋂ i, a • t i :=
image_Inter_subset _ _
@[to_additive]
lemma smul_set_Inter₂_subset (a : α) (t : Π i, κ i → set β) :
a • (⋂ i j, t i j) ⊆ ⋂ i j, a • t i j :=
image_Inter₂_subset _ _
@[to_additive] lemma nonempty.smul_set : s.nonempty → (a • s).nonempty := nonempty.image _
@[to_additive] lemma finite.smul_set : s.finite → (a • s).finite := finite.image _
end has_smul_set
variables {s s₁ s₂ : set α} {t t₁ t₂ : set β} {a : α} {b : β}
@[to_additive]
lemma smul_set_inter [group α] [mul_action α β] {s t : set β} :
a • (s ∩ t) = a • s ∩ a • t :=
(image_inter $ mul_action.injective a).symm
lemma smul_set_inter₀ [group_with_zero α] [mul_action α β] {s t : set β} (ha : a ≠ 0) :
a • (s ∩ t) = a • s ∩ a • t :=
show units.mk0 a ha • _ = _, from smul_set_inter
@[simp, to_additive]
lemma smul_set_univ [group α] [mul_action α β] {a : α} : a • (univ : set β) = univ :=
eq_univ_of_forall $ λ b, ⟨a⁻¹ • b, trivial, smul_inv_smul _ _⟩
@[simp, to_additive]
lemma smul_univ [group α] [mul_action α β] {s : set α} (hs : s.nonempty) :
s • (univ : set β) = univ :=
let ⟨a, ha⟩ := hs in eq_univ_of_forall $ λ b, ⟨a, a⁻¹ • b, ha, trivial, smul_inv_smul _ _⟩
@[to_additive]
theorem range_smul_range {ι κ : Type*} [has_smul α β] (b : ι → α) (c : κ → β) :
range b • range c = range (λ p : ι × κ, b p.1 • c p.2) :=
ext $ λ x, ⟨λ hx, let ⟨p, q, ⟨i, hi⟩, ⟨j, hj⟩, hpq⟩ := set.mem_smul.1 hx in
⟨(i, j), hpq ▸ hi ▸ hj ▸ rfl⟩,
λ ⟨⟨i, j⟩, h⟩, set.mem_smul.2 ⟨b i, c j, ⟨i, rfl⟩, ⟨j, rfl⟩, h⟩⟩
@[to_additive] lemma smul_set_range [has_smul α β] {ι : Sort*} {f : ι → β} :
a • range f = range (λ i, a • f i) := (range_comp _ _).symm
@[to_additive]
instance smul_comm_class_set [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] :
smul_comm_class α β (set γ) :=
⟨λ _ _, commute.set_image $ smul_comm _ _⟩
@[to_additive]
instance smul_comm_class_set' [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] :
smul_comm_class α (set β) (set γ) :=
⟨λ _ _ _, image_image2_distrib_right $ smul_comm _⟩
@[to_additive]
instance smul_comm_class_set'' [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] :
smul_comm_class (set α) β (set γ) :=
by haveI := smul_comm_class.symm α β γ; exact smul_comm_class.symm _ _ _
@[to_additive]
instance smul_comm_class [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] :
smul_comm_class (set α) (set β) (set γ) :=
⟨λ _ _ _, image2_left_comm smul_comm⟩
@[to_additive]
instance is_scalar_tower [has_smul α β] [has_smul α γ] [has_smul β γ] [is_scalar_tower α β γ] :
is_scalar_tower α β (set γ) :=
{ smul_assoc := λ a b T, by simp only [←image_smul, image_image, smul_assoc] }
@[to_additive]
instance is_scalar_tower' [has_smul α β] [has_smul α γ] [has_smul β γ] [is_scalar_tower α β γ] :
is_scalar_tower α (set β) (set γ) :=
⟨λ _ _ _, image2_image_left_comm $ smul_assoc _⟩
@[to_additive]
instance is_scalar_tower'' [has_smul α β] [has_smul α γ] [has_smul β γ] [is_scalar_tower α β γ] :
is_scalar_tower (set α) (set β) (set γ) :=
{ smul_assoc := λ T T' T'', image2_assoc smul_assoc }
instance is_central_scalar [has_smul α β] [has_smul αᵐᵒᵖ β] [is_central_scalar α β] :
is_central_scalar α (set β) :=
⟨λ a S, congr_arg (λ f, f '' S) $ by exact funext (λ _, op_smul_eq_smul _ _)⟩
/-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of `set α`
on `set β`. -/
@[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action
of `set α` on `set β`"]
protected def mul_action [monoid α] [mul_action α β] : mul_action (set α) (set β) :=
{ mul_smul := λ _ _ _, image2_assoc mul_smul,
one_smul := λ s, image2_singleton_left.trans $ by simp_rw [one_smul, image_id'] }
/-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `set β`. -/
@[to_additive "An additive action of an additive monoid on a type `β` gives an additive action
on `set β`."]
protected def mul_action_set [monoid α] [mul_action α β] : mul_action α (set β) :=
{ mul_smul := by { intros, simp only [← image_smul, image_image, ← mul_smul] },
one_smul := by { intros, simp only [← image_smul, one_smul, image_id'] } }
localized "attribute [instance] set.mul_action_set set.add_action_set
set.mul_action set.add_action" in pointwise
/-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive
multiplicative action on `set β`. -/
protected def distrib_mul_action_set [monoid α] [add_monoid β] [distrib_mul_action α β] :
distrib_mul_action α (set β) :=
{ smul_add := λ _ _ _, image_image2_distrib $ smul_add _,
smul_zero := λ _, image_singleton.trans $ by rw [smul_zero, singleton_zero] }
/-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `set β`. -/
protected def mul_distrib_mul_action_set [monoid α] [monoid β] [mul_distrib_mul_action α β] :
mul_distrib_mul_action α (set β) :=
{ smul_mul := λ _ _ _, image_image2_distrib $ smul_mul' _,
smul_one := λ _, image_singleton.trans $ by rw [smul_one, singleton_one] }
localized "attribute [instance] set.distrib_mul_action_set set.mul_distrib_mul_action_set"
in pointwise
instance [has_zero α] [has_zero β] [has_smul α β] [no_zero_smul_divisors α β] :
no_zero_smul_divisors (set α) (set β) :=
⟨λ s t h, begin
by_contra' H,
have hst : (s • t).nonempty := h.symm.subst zero_nonempty,
simp_rw [←hst.of_smul_left.subset_zero_iff, ←hst.of_smul_right.subset_zero_iff, not_subset,
mem_zero] at H,
obtain ⟨⟨a, hs, ha⟩, b, ht, hb⟩ := H,
exact (eq_zero_or_eq_zero_of_smul_eq_zero $ h.subset $ smul_mem_smul hs ht).elim ha hb,
end⟩
instance no_zero_smul_divisors_set [has_zero α] [has_zero β] [has_smul α β]
[no_zero_smul_divisors α β] : no_zero_smul_divisors α (set β) :=
⟨λ a s h, begin
by_contra' H,
have hst : (a • s).nonempty := h.symm.subst zero_nonempty,
simp_rw [←hst.of_image.subset_zero_iff, not_subset, mem_zero] at H,
obtain ⟨ha, b, ht, hb⟩ := H,
exact (eq_zero_or_eq_zero_of_smul_eq_zero $ h.subset $ smul_mem_smul_set ht).elim ha hb,
end⟩
instance [has_zero α] [has_mul α] [no_zero_divisors α] : no_zero_divisors (set α) :=
⟨λ s t h, eq_zero_or_eq_zero_of_smul_eq_zero h⟩
end smul
section vsub
variables {ι : Sort*} {κ : ι → Sort*} [has_vsub α β] {s s₁ s₂ t t₁ t₂ : set β} {u : set α} {a : α}
{b c : β}
include α
instance has_vsub : has_vsub (set α) (set β) := ⟨image2 (-ᵥ)⟩
@[simp] lemma image2_vsub : (image2 has_vsub.vsub s t : set α) = s -ᵥ t := rfl
lemma image_vsub_prod : (λ x : β × β, x.fst -ᵥ x.snd) '' s ×ˢ t = s -ᵥ t := image_prod _
lemma mem_vsub : a ∈ s -ᵥ t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x -ᵥ y = a := iff.rfl
lemma vsub_mem_vsub (hb : b ∈ s) (hc : c ∈ t) : b -ᵥ c ∈ s -ᵥ t := mem_image2_of_mem hb hc
@[simp] lemma empty_vsub (t : set β) : ∅ -ᵥ t = ∅ := image2_empty_left
@[simp] lemma vsub_empty (s : set β) : s -ᵥ ∅ = ∅ := image2_empty_right
@[simp] lemma vsub_eq_empty : s -ᵥ t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff
@[simp] lemma vsub_nonempty : (s -ᵥ t : set α).nonempty ↔ s.nonempty ∧ t.nonempty :=
image2_nonempty_iff
lemma nonempty.vsub : s.nonempty → t.nonempty → (s -ᵥ t : set α).nonempty := nonempty.image2
lemma nonempty.of_vsub_left : (s -ᵥ t :set α).nonempty → s.nonempty := nonempty.of_image2_left
lemma nonempty.of_vsub_right : (s -ᵥ t : set α).nonempty → t.nonempty := nonempty.of_image2_right
@[simp] lemma vsub_singleton (s : set β) (b : β) : s -ᵥ {b} = (-ᵥ b) '' s := image2_singleton_right
@[simp] lemma singleton_vsub (t : set β) (b : β) : {b} -ᵥ t = ((-ᵥ) b) '' t := image2_singleton_left
@[simp] lemma singleton_vsub_singleton : ({b} : set β) -ᵥ {c} = {b -ᵥ c} := image2_singleton
@[mono] lemma vsub_subset_vsub : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ -ᵥ t₁ ⊆ s₂ -ᵥ t₂ := image2_subset
lemma vsub_subset_vsub_left : t₁ ⊆ t₂ → s -ᵥ t₁ ⊆ s -ᵥ t₂ := image2_subset_left
lemma vsub_subset_vsub_right : s₁ ⊆ s₂ → s₁ -ᵥ t ⊆ s₂ -ᵥ t := image2_subset_right
lemma vsub_subset_iff : s -ᵥ t ⊆ u ↔ ∀ (x ∈ s) (y ∈ t), x -ᵥ y ∈ u := image2_subset_iff
lemma vsub_self_mono (h : s ⊆ t) : s -ᵥ s ⊆ t -ᵥ t := vsub_subset_vsub h h
lemma union_vsub : (s₁ ∪ s₂) -ᵥ t = s₁ -ᵥ t ∪ (s₂ -ᵥ t) := image2_union_left
lemma vsub_union : s -ᵥ (t₁ ∪ t₂) = s -ᵥ t₁ ∪ (s -ᵥ t₂) := image2_union_right
lemma inter_vsub_subset : s₁ ∩ s₂ -ᵥ t ⊆ (s₁ -ᵥ t) ∩ (s₂ -ᵥ t) := image2_inter_subset_left
lemma vsub_inter_subset : s -ᵥ t₁ ∩ t₂ ⊆ (s -ᵥ t₁) ∩ (s -ᵥ t₂) := image2_inter_subset_right
lemma Union_vsub_left_image : (⋃ a ∈ s, ((-ᵥ) a) '' t) = s -ᵥ t := Union_image_left _
lemma Union_vsub_right_image : (⋃ a ∈ t, (-ᵥ a) '' s) = s -ᵥ t := Union_image_right _
lemma Union_vsub (s : ι → set β) (t : set β) : (⋃ i, s i) -ᵥ t = ⋃ i, s i -ᵥ t :=
image2_Union_left _ _ _
lemma vsub_Union (s : set β) (t : ι → set β) : s -ᵥ (⋃ i, t i) = ⋃ i, s -ᵥ t i :=
image2_Union_right _ _ _
lemma Union₂_vsub (s : Π i, κ i → set β) (t : set β) : (⋃ i j, s i j) -ᵥ t = ⋃ i j, s i j -ᵥ t :=
image2_Union₂_left _ _ _
lemma vsub_Union₂ (s : set β) (t : Π i, κ i → set β) : s -ᵥ (⋃ i j, t i j) = ⋃ i j, s -ᵥ t i j :=
image2_Union₂_right _ _ _
lemma Inter_vsub_subset (s : ι → set β) (t : set β) : (⋂ i, s i) -ᵥ t ⊆ ⋂ i, s i -ᵥ t :=
image2_Inter_subset_left _ _ _
lemma vsub_Inter_subset (s : set β) (t : ι → set β) : s -ᵥ (⋂ i, t i) ⊆ ⋂ i, s -ᵥ t i :=
image2_Inter_subset_right _ _ _
lemma Inter₂_vsub_subset (s : Π i, κ i → set β) (t : set β) :
(⋂ i j, s i j) -ᵥ t ⊆ ⋂ i j, s i j -ᵥ t :=
image2_Inter₂_subset_left _ _ _
lemma vsub_Inter₂_subset (s : set β) (t : Π i, κ i → set β) :
s -ᵥ (⋂ i j, t i j) ⊆ ⋂ i j, s -ᵥ t i j :=
image2_Inter₂_subset_right _ _ _
lemma finite.vsub (hs : s.finite) (ht : t.finite) : set.finite (s -ᵥ t) := hs.image2 _ ht
end vsub
open_locale pointwise
section ring
variables [ring α] [add_comm_group β] [module α β] {s : set α} {t : set β} {a : α}
@[simp] lemma neg_smul_set : -a • t = -(a • t) :=
by simp_rw [←image_smul, ←image_neg, image_image, neg_smul]
@[simp] lemma smul_set_neg : a • -t = -(a • t) :=
by simp_rw [←image_smul, ←image_neg, image_image, smul_neg]
@[simp] protected lemma neg_smul : -s • t = -(s • t) :=
by { simp_rw ←image_neg, exact image2_image_left_comm neg_smul }
@[simp] protected lemma smul_neg : s • -t = -(s • t) :=
by { simp_rw ←image_neg, exact image_image2_right_comm smul_neg }
end ring
section smul_with_zero
variables [has_zero α] [has_zero β] [smul_with_zero α β] {s : set α} {t : set β}
/-!
Note that we have neither `smul_with_zero α (set β)` nor `smul_with_zero (set α) (set β)`
because `0 * ∅ ≠ 0`.
-/
lemma smul_zero_subset (s : set α) : s • (0 : set β) ⊆ 0 := by simp [subset_def, mem_smul]
lemma zero_smul_subset (t : set β) : (0 : set α) • t ⊆ 0 := by simp [subset_def, mem_smul]
lemma nonempty.smul_zero (hs : s.nonempty) : s • (0 : set β) = 0 :=
s.smul_zero_subset.antisymm $ by simpa [mem_smul] using hs
lemma nonempty.zero_smul (ht : t.nonempty) : (0 : set α) • t = 0 :=
t.zero_smul_subset.antisymm $ by simpa [mem_smul] using ht
/-- A nonempty set is scaled by zero to the singleton set containing 0. -/
lemma zero_smul_set {s : set β} (h : s.nonempty) : (0 : α) • s = (0 : set β) :=
by simp only [← image_smul, image_eta, zero_smul, h.image_const, singleton_zero]
lemma zero_smul_set_subset (s : set β) : (0 : α) • s ⊆ 0 :=
image_subset_iff.2 $ λ x _, zero_smul α x
lemma subsingleton_zero_smul_set (s : set β) : ((0 : α) • s).subsingleton :=
subsingleton_singleton.anti $ zero_smul_set_subset s
lemma zero_mem_smul_set {t : set β} {a : α} (h : (0 : β) ∈ t) : (0 : β) ∈ a • t :=
⟨0, h, smul_zero' _ _⟩
variables [no_zero_smul_divisors α β] {a : α}
lemma zero_mem_smul_iff : (0 : β) ∈ s • t ↔ (0 : α) ∈ s ∧ t.nonempty ∨ (0 : β) ∈ t ∧ s.nonempty :=
begin
split,
{ rintro ⟨a, b, ha, hb, h⟩,
obtain rfl | rfl := eq_zero_or_eq_zero_of_smul_eq_zero h,
{ exact or.inl ⟨ha, b, hb⟩ },
{ exact or.inr ⟨hb, a, ha⟩ } },
{ rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩),
{ exact ⟨0, b, hs, hb, zero_smul _ _⟩ },
{ exact ⟨a, 0, ha, ht, smul_zero' _ _⟩ } }
end
lemma zero_mem_smul_set_iff (ha : a ≠ 0) : (0 : β) ∈ a • t ↔ (0 : β) ∈ t :=
begin
refine ⟨_, zero_mem_smul_set⟩,
rintro ⟨b, hb, h⟩,
rwa (eq_zero_or_eq_zero_of_smul_eq_zero h).resolve_left ha at hb,
end
end smul_with_zero
section left_cancel_semigroup
variables [left_cancel_semigroup α] {s t : set α}
@[to_additive] lemma pairwise_disjoint_smul_iff :
s.pairwise_disjoint (• t) ↔ (s ×ˢ t).inj_on (λ p, p.1 * p.2) :=
pairwise_disjoint_image_right_iff $ λ _ _, mul_right_injective _
end left_cancel_semigroup
section group
variables [group α] [mul_action α β] {s t A B : set β} {a : α} {x : β}
@[simp, to_additive]
lemma smul_mem_smul_set_iff : a • x ∈ a • s ↔ x ∈ s := (mul_action.injective _).mem_set_image
@[to_additive]
lemma mem_smul_set_iff_inv_smul_mem : x ∈ a • A ↔ a⁻¹ • x ∈ A :=
show x ∈ mul_action.to_perm a '' A ↔ _, from mem_image_equiv
@[to_additive]
lemma mem_inv_smul_set_iff : x ∈ a⁻¹ • A ↔ a • x ∈ A :=
by simp only [← image_smul, mem_image, inv_smul_eq_iff, exists_eq_right]
@[to_additive]
lemma preimage_smul (a : α) (t : set β) : (λ x, a • x) ⁻¹' t = a⁻¹ • t :=
((mul_action.to_perm a).symm.image_eq_preimage _).symm
@[to_additive]
lemma preimage_smul_inv (a : α) (t : set β) : (λ x, a⁻¹ • x) ⁻¹' t = a • t :=
preimage_smul (to_units a)⁻¹ t
@[simp, to_additive]
lemma set_smul_subset_set_smul_iff : a • A ⊆ a • B ↔ A ⊆ B :=
image_subset_image_iff $ mul_action.injective _
@[to_additive]
lemma set_smul_subset_iff : a • A ⊆ B ↔ A ⊆ a⁻¹ • B :=
(image_subset_iff).trans $ iff_of_eq $ congr_arg _ $
preimage_equiv_eq_image_symm _ $ mul_action.to_perm _
@[to_additive]
lemma subset_set_smul_iff : A ⊆ a • B ↔ a⁻¹ • A ⊆ B :=
iff.symm $ (image_subset_iff).trans $ iff.symm $ iff_of_eq $ congr_arg _ $
image_equiv_eq_preimage_symm _ $ mul_action.to_perm _
end group
section group_with_zero
variables [group_with_zero α] [mul_action α β] {s : set α} {a : α}
@[simp] lemma smul_mem_smul_set_iff₀ (ha : a ≠ 0) (A : set β)
(x : β) : a • x ∈ a • A ↔ x ∈ A :=
show units.mk0 a ha • _ ∈ _ ↔ _, from smul_mem_smul_set_iff
lemma mem_smul_set_iff_inv_smul_mem₀ (ha : a ≠ 0) (A : set β) (x : β) :
x ∈ a • A ↔ a⁻¹ • x ∈ A :=
show _ ∈ units.mk0 a ha • _ ↔ _, from mem_smul_set_iff_inv_smul_mem
lemma mem_inv_smul_set_iff₀ (ha : a ≠ 0) (A : set β) (x : β) : x ∈ a⁻¹ • A ↔ a • x ∈ A :=
show _ ∈ (units.mk0 a ha)⁻¹ • _ ↔ _, from mem_inv_smul_set_iff
lemma preimage_smul₀ (ha : a ≠ 0) (t : set β) : (λ x, a • x) ⁻¹' t = a⁻¹ • t :=
preimage_smul (units.mk0 a ha) t
lemma preimage_smul_inv₀ (ha : a ≠ 0) (t : set β) :
(λ x, a⁻¹ • x) ⁻¹' t = a • t :=
preimage_smul ((units.mk0 a ha)⁻¹) t
@[simp] lemma set_smul_subset_set_smul_iff₀ (ha : a ≠ 0) {A B : set β} :
a • A ⊆ a • B ↔ A ⊆ B :=
show units.mk0 a ha • _ ⊆ _ ↔ _, from set_smul_subset_set_smul_iff
lemma set_smul_subset_iff₀ (ha : a ≠ 0) {A B : set β} : a • A ⊆ B ↔ A ⊆ a⁻¹ • B :=
show units.mk0 a ha • _ ⊆ _ ↔ _, from set_smul_subset_iff
lemma subset_set_smul_iff₀ (ha : a ≠ 0) {A B : set β} : A ⊆ a • B ↔ a⁻¹ • A ⊆ B :=
show _ ⊆ units.mk0 a ha • _ ↔ _, from subset_set_smul_iff
lemma smul_univ₀ (hs : ¬ s ⊆ 0) : s • (univ : set β) = univ :=
let ⟨a, ha, ha₀⟩ := not_subset.1 hs in eq_univ_of_forall $ λ b,
⟨a, a⁻¹ • b, ha, trivial, smul_inv_smul₀ ha₀ _⟩
lemma smul_set_univ₀ (ha : a ≠ 0) : a • (univ : set β) = univ :=
eq_univ_of_forall $ λ b, ⟨a⁻¹ • b, trivial, smul_inv_smul₀ ha _⟩
end group_with_zero
end set
/-! ### Miscellaneous -/
open set
open_locale pointwise
/-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in
`group_theory.submonoid.basic`, but currently we cannot because that file is imported by this. -/
namespace submonoid
variables {M : Type*} [monoid M] {s t u : set M}
@[to_additive]
lemma mul_subset {S : submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S :=
by { rintro _ ⟨p, q, hp, hq, rfl⟩, exact submonoid.mul_mem _ (hs hp) (ht hq) }
@[to_additive]
lemma mul_subset_closure (hs : s ⊆ u) (ht : t ⊆ u) : s * t ⊆ submonoid.closure u :=
mul_subset (subset.trans hs submonoid.subset_closure) (subset.trans ht submonoid.subset_closure)
@[to_additive]
lemma coe_mul_self_eq (s : submonoid M) : (s : set M) * s = s :=
begin
ext x,
refine ⟨_, λ h, ⟨x, 1, h, s.one_mem, mul_one x⟩⟩,
rintro ⟨a, b, ha, hb, rfl⟩,
exact s.mul_mem ha hb
end
@[to_additive]
lemma closure_mul_le (S T : set M) : closure (S * T) ≤ closure S ⊔ closure T :=
Inf_le $ λ x ⟨s, t, hs, ht, hx⟩, hx ▸ (closure S ⊔ closure T).mul_mem
(set_like.le_def.mp le_sup_left $ subset_closure hs)
(set_like.le_def.mp le_sup_right $ subset_closure ht)
@[to_additive]
lemma sup_eq_closure (H K : submonoid M) : H ⊔ K = closure (H * K) :=
le_antisymm
(sup_le
(λ h hh, subset_closure ⟨h, 1, hh, K.one_mem, mul_one h⟩)
(λ k hk, subset_closure ⟨1, k, H.one_mem, hk, one_mul k⟩))
(by conv_rhs { rw [← closure_eq H, ← closure_eq K] }; apply closure_mul_le)
@[to_additive]
lemma pow_smul_mem_closure_smul {N : Type*} [comm_monoid N] [mul_action M N]
[is_scalar_tower M N N] (r : M) (s : set N) {x : N} (hx : x ∈ closure s) :
∃ n : ℕ, r ^ n • x ∈ closure (r • s) :=
begin
apply @closure_induction N _ s
(λ (x : N), ∃ n : ℕ, r ^ n • x ∈ closure (r • s)) _ hx,
{ intros x hx,
exact ⟨1, subset_closure ⟨_, hx, by rw pow_one⟩⟩ },
{ exact ⟨0, by simpa using one_mem _⟩ },
{ rintro x y ⟨nx, hx⟩ ⟨ny, hy⟩,
use nx + ny,
convert mul_mem hx hy,
rw [pow_add, smul_mul_assoc, mul_smul, mul_comm, ← smul_mul_assoc, mul_comm] }
end
end submonoid
namespace group
lemma card_pow_eq_card_pow_card_univ_aux {f : ℕ → ℕ} (h1 : monotone f)
{B : ℕ} (h2 : ∀ n, f n ≤ B) (h3 : ∀ n, f n = f (n + 1) → f (n + 1) = f (n + 2)) :
∀ k, B ≤ k → f k = f B :=
begin
have key : ∃ n : ℕ, n ≤ B ∧ f n = f (n + 1),
{ contrapose! h2,
suffices : ∀ n : ℕ, n ≤ B + 1 → n ≤ f n,
{ exact ⟨B + 1, this (B + 1) (le_refl (B + 1))⟩ },
exact λ n, nat.rec (λ h, nat.zero_le (f 0)) (λ n ih h, lt_of_le_of_lt (ih (n.le_succ.trans h))
(lt_of_le_of_ne (h1 n.le_succ) (h2 n (nat.succ_le_succ_iff.mp h)))) n },
{ obtain ⟨n, hn1, hn2⟩ := key,
replace key : ∀ k : ℕ, f (n + k) = f (n + k + 1) ∧ f (n + k) = f n :=
λ k, nat.rec ⟨hn2, rfl⟩ (λ k ih, ⟨h3 _ ih.1, ih.1.symm.trans ih.2⟩) k,
replace key : ∀ k : ℕ, n ≤ k → f k = f n :=
λ k hk, (congr_arg f (add_tsub_cancel_of_le hk)).symm.trans (key (k - n)).2,
exact λ k hk, (key k (hn1.trans hk)).trans (key B hn1).symm },
end
variables {G : Type*} [group G] [fintype G] (S : set G)
@[to_additive]
lemma card_pow_eq_card_pow_card_univ [∀ (k : ℕ), decidable_pred (∈ (S ^ k))] :
∀ k, fintype.card G ≤ k → fintype.card ↥(S ^ k) = fintype.card ↥(S ^ (fintype.card G)) :=
begin
have hG : 0 < fintype.card G := fintype.card_pos_iff.mpr ⟨1⟩,
by_cases hS : S = ∅,
{ refine λ k hk, fintype.card_congr _,
rw [hS, empty_pow (ne_of_gt (lt_of_lt_of_le hG hk)), empty_pow (ne_of_gt hG)] },
obtain ⟨a, ha⟩ := set.ne_empty_iff_nonempty.mp hS,
classical!,
have key : ∀ a (s t : set G), (∀ b : G, b ∈ s → a * b ∈ t) → fintype.card s ≤ fintype.card t,
{ refine λ a s t h, fintype.card_le_of_injective (λ ⟨b, hb⟩, ⟨a * b, h b hb⟩) _,
rintro ⟨b, hb⟩ ⟨c, hc⟩ hbc,
exact subtype.ext (mul_left_cancel (subtype.ext_iff.mp hbc)) },
have mono : monotone (λ n, fintype.card ↥(S ^ n) : ℕ → ℕ) :=
monotone_nat_of_le_succ (λ n, key a _ _ (λ b hb, set.mul_mem_mul ha hb)),
convert card_pow_eq_card_pow_card_univ_aux mono (λ n, set_fintype_card_le_univ (S ^ n))
(λ n h, le_antisymm (mono (n + 1).le_succ) (key a⁻¹ _ _ _)),
{ simp only [finset.filter_congr_decidable, fintype.card_of_finset] },
replace h : {a} * S ^ n = S ^ (n + 1),
{ refine set.eq_of_subset_of_card_le _ (le_trans (ge_of_eq h) _),
{ exact mul_subset_mul (set.singleton_subset_iff.mpr ha) set.subset.rfl },
{ convert key a (S ^ n) ({a} * S ^ n) (λ b hb, set.mul_mem_mul (set.mem_singleton a) hb) } },
rw [pow_succ', ←h, mul_assoc, ←pow_succ', h],
rintro _ ⟨b, c, hb, hc, rfl⟩,
rwa [set.mem_singleton_iff.mp hb, inv_mul_cancel_left],
end
end group
|
215f8b36314f482c22e02a2e15e542c4235ab0aa | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/partial1.lean | 863bd30ab72b221cbb9d9651c5b2f17c77871d6a | [
"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 | 524 | lean |
partial def reverse {α} (as : List α) : List α :=
let rec loop : List α → List α → List α
| [], r => r
| a::as, r => loop as (a::r)
loop as []
#eval reverse [3, 2, 1]
#eval reverse [1, 2, 3, 4]
#print reverse
#print reverse.loop
#print reverse.loop._unsafe_rec
partial def appendRev {α} (extra : List α) (as : List α) : List α :=
let rec loop (as acc : List α) : List α :=
match as, acc with
| [], r => extra ++ r
| a::as, r => loop as (a::r)
loop as []
#eval appendRev [3, 4] [1, 2, 0]
|
c9f20ed9353fcec110d3741d0e1d79ecca1ce2b4 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /stage0/src/Init/Coe.lean | 773e46b14e1c4f97ba022bdb2261e1d1a6f4e5d6 | [
"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 | 6,375 | 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
-/
prelude
import Init.Core
universe u v w w'
class Coe (α : Sort u) (β : Sort v) where
coe : α → β
/-- Auxiliary class that contains the transitive closure of `Coe`. -/
class CoeTC (α : Sort u) (β : Sort v) where
coe : α → β
/- Expensive coercion that can only appear at the beginning of a sequence of coercions. -/
class CoeHead (α : Sort u) (β : Sort v) where
coe : α → β
/- Expensive coercion that can only appear at the end of a sequence of coercions. -/
class CoeTail (α : Sort u) (β : Sort v) where
coe : α → β
/-- Auxiliary class that contains `CoeHead` + `CoeTC` + `CoeTail`. -/
class CoeHTCT (α : Sort u) (β : Sort v) where
coe : α → β
class CoeDep (α : Sort u) (a : α) (β : Sort v) where
coe : β
/- Combines CoeHead, CoeTC, CoeTail, CoeDep -/
class CoeT (α : Sort u) (a : α) (β : Sort v) where
coe : β
class CoeFun (α : Sort u) (γ : outParam (α → Sort v)) where
coe : (a : α) → γ a
class CoeSort (α : Sort u) (β : outParam (Sort v)) where
coe : α → β
abbrev coeB {α : Sort u} {β : Sort v} [Coe α β] (a : α) : β :=
Coe.coe a
abbrev coeHead {α : Sort u} {β : Sort v} [CoeHead α β] (a : α) : β :=
CoeHead.coe a
abbrev coeTail {α : Sort u} {β : Sort v} [CoeTail α β] (a : α) : β :=
CoeTail.coe a
abbrev coeD {α : Sort u} {β : Sort v} (a : α) [CoeDep α a β] : β :=
CoeDep.coe a
abbrev coeTC {α : Sort u} {β : Sort v} [CoeTC α β] (a : α) : β :=
CoeTC.coe a
/-- Apply coercion manually. -/
abbrev coe {α : Sort u} {β : Sort v} (a : α) [CoeT α a β] : β :=
CoeT.coe a
prefix:max "↑" => coe
abbrev coeFun {α : Sort u} {γ : α → Sort v} (a : α) [CoeFun α γ] : γ a :=
CoeFun.coe a
abbrev coeSort {α : Sort u} {β : Sort v} (a : α) [CoeSort α β] : β :=
CoeSort.coe a
instance coeTrans {α : Sort u} {β : Sort v} {δ : Sort w} [Coe β δ] [CoeTC α β] : CoeTC α δ where
coe a := coeB (coeTC a : β)
instance coeBase {α : Sort u} {β : Sort v} [Coe α β] : CoeTC α β where
coe a := coeB a
instance coeOfHeafOfTCOfTail {α : Sort u} {β : Sort v} {δ : Sort w} {γ : Sort w'} [CoeHead α β] [CoeTail δ γ] [CoeTC β δ] : CoeHTCT α γ where
coe a := coeTail (coeTC (coeHead a : β) : δ)
instance coeOfHeadOfTC {α : Sort u} {β : Sort v} {δ : Sort w} [CoeHead α β] [CoeTC β δ] : CoeHTCT α δ where
coe a := coeTC (coeHead a : β)
instance coeOfTCOfTail {α : Sort u} {β : Sort v} {δ : Sort w} [CoeTail β δ] [CoeTC α β] : CoeHTCT α δ where
coe a := coeTail (coeTC a : β)
instance coeOfHead {α : Sort u} {β : Sort v} [CoeHead α β] : CoeHTCT α β where
coe a := coeHead a
instance coeOfTail {α : Sort u} {β : Sort v} [CoeTail α β] : CoeHTCT α β where
coe a := coeTail a
instance coeOfTC {α : Sort u} {β : Sort v} [CoeTC α β] : CoeHTCT α β where
coe a := coeTC a
instance coeOfHTCT {α : Sort u} {β : Sort v} [CoeHTCT α β] (a : α) : CoeT α a β where
coe := CoeHTCT.coe a
instance coeOfDep {α : Sort u} {β : Sort v} (a : α) [CoeDep α a β] : CoeT α a β where
coe := coeD a
instance coeId {α : Sort u} (a : α) : CoeT α a α where
coe := a
/- Basic instances -/
@[inline] instance boolToProp : Coe Bool Prop where
coe b := b = true
instance boolToSort : CoeSort Bool Prop where
coe b := b
@[inline] instance coeDecidableEq (x : Bool) : Decidable (coe x) :=
inferInstanceAs (Decidable (x = true))
instance decPropToBool (p : Prop) [Decidable p] : CoeDep Prop p Bool where
coe := decide p
instance optionCoe {α : Type u} : CoeTail α (Option α) where
coe := some
instance subtypeCoe {α : Sort u} {p : α → Prop} : CoeHead { x // p x } α where
coe v := v.val
/- Coe & OfNat bridge -/
/-
Remark: one may question why we use `OfNat α` instead of `Coe Nat α`.
Reason: `OfNat` is for implementing polymorphic numeric literals, and we may
want to have numeric literals for a type α and **no** coercion from `Nat` to `α`. -/
instance hasOfNatOfCoe [Coe α β] [OfNat α n] : OfNat β n where
ofNat := coe (OfNat.ofNat n : α)
@[inline] def liftCoeM {m : Type u → Type v} {n : Type u → Type w} {α β : Type u} [MonadLiftT m n] [∀ a, CoeT α a β] [Monad n] (x : m α) : n β := do
let a ← liftM x
pure (coe a)
@[inline] def coeM {m : Type u → Type v} {α β : Type u} [∀ a, CoeT α a β] [Monad m] (x : m α) : m β := do
let a ← x
pure <| coe a
instance [CoeFun α β] (a : α) : CoeDep α a (β a) where
coe := coeFun a
instance [CoeFun α (fun _ => β)] : CoeTail α β where
coe a := coeFun a
instance [CoeSort α β] : CoeTail α β where
coe a := coeSort a
/- Coe and heterogeneous operators, we use `CoeHTCT` instead of `CoeT` to avoid expensive coercions such as `CoeDep` -/
instance [CoeHTCT α β] [Add β] : HAdd α β β where
hAdd a b := Add.add a b
instance [CoeHTCT α β] [Add β] : HAdd β α β where
hAdd a b := Add.add a b
instance [CoeHTCT α β] [Sub β] : HSub α β β where
hSub a b := Sub.sub a b
instance [CoeHTCT α β] [Sub β] : HSub β α β where
hSub a b := Sub.sub a b
instance [CoeHTCT α β] [Mul β] : HMul α β β where
hMul a b := Mul.mul a b
instance [CoeHTCT α β] [Mul β] : HMul β α β where
hMul a b := Mul.mul a b
instance [CoeHTCT α β] [Div β] : HDiv α β β where
hDiv a b := Div.div a b
instance [CoeHTCT α β] [Div β] : HDiv β α β where
hDiv a b := Div.div a b
instance [CoeHTCT α β] [Mod β] : HMod α β β where
hMod a b := Mod.mod a b
instance [CoeHTCT α β] [Mod β] : HMod β α β where
hMod a b := Mod.mod a b
instance [CoeHTCT α β] [Append β] : HAppend α β β where
hAppend a b := Append.append a b
instance [CoeHTCT α β] [Append β] : HAppend β α β where
hAppend a b := Append.append a b
instance [CoeHTCT α β] [OrElse β] : HOrElse α β β where
hOrElse a b := OrElse.orElse a b
instance [CoeHTCT α β] [OrElse β] : HOrElse β α β where
hOrElse a b := OrElse.orElse a b
instance [CoeHTCT α β] [AndThen β] : HAndThen α β β where
hAndThen a b := AndThen.andThen a b
instance [CoeHTCT α β] [AndThen β] : HAndThen β α β where
hAndThen a b := AndThen.andThen a b
|
f328ee1ce45e789ecb95d85154920574ae64dfb6 | 6660717bc6481a8daa9f91dc7dcef5eccea1b0bd | /lib_test/groups.lean | d9d9e52255a52fbbba098de055c04292ab8e4843 | [] | no_license | beschmi/lean-ocaml-bindings | cf314f245144147e69b28b16c53400035ca94652 | 33f76adaf7a8b697126b80738f8e8812f41846cb | refs/heads/master | 1,515,416,835,673 | 1,462,538,164,000 | 1,462,538,164,000 | 54,384,212 | 3 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 471 | lean | import data.fin
open nat fin
-- * Finite fields and groups
--constant (q : ℕ)
definition fq := fin q
notation `𝓕` := fq
definition fq.comm_ring [instance] : comm_ring 𝓕 := sorry
definition fq.fintype [instance] : fintype 𝓕 := sorry
definition fq.inhabited [instance] : inhabited 𝓕 := sorry
definition fq.decidable_eq [instance] : decidable_eq 𝓕 := sorry
structure grp := (dlog : 𝓕)
notation `𝓖` := grp
notation `⟦` x `⟧` := grp.mk x
|
92237018598a401e017ac471097e5ac6f5f1b533 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/matchEqnsHEqIssue.lean | 603ff6aa7463bd5ddf4db59ab0c5c194dae59caa | [
"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 | 600 | lean | inductive Ty :=
| int: Ty
| other: Ty
inductive Tensor :=
| int: Int -> Tensor
| nested: List Tensor -> Tensor
def hasBaseType: Tensor → Ty → Bool
| .int _, Ty.int => true
| .int _, Ty.other => true
| .nested _, _ => true
def flatten (e: Tensor) (τ: Ty) (h: hasBaseType e τ): List Int :=
match e, τ with
| .int _, Ty.int => []
| .int _, _ => []
| .nested [], _ => []
| .nested (_::_), _ => []
theorem flatten_list (l: List Tensor) τ (h: hasBaseType (.nested l) τ):
flatten (.nested l) τ h = [] := by
simp [flatten]
repeat sorry
|
7104ce164a5258edd7decd05ff04f59abd161352 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/algebra/monoid_algebra/grading.lean | 3fa0098a8a862b35ea87e174a83590ebb9c7185e | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 8,660 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import linear_algebra.finsupp
import algebra.monoid_algebra.support
import algebra.direct_sum.internal
import ring_theory.graded_algebra.basic
/-!
# Internal grading of an `add_monoid_algebra`
In this file, we show that an `add_monoid_algebra` has an internal direct sum structure.
## Main results
* `add_monoid_algebra.grade_by R f i`: the `i`th grade of an `add_monoid_algebra R M` given by the
degree function `f`.
* `add_monoid_algebra.grade R i`: the `i`th grade of an `add_monoid_algebra R M` when the degree
function is the identity.
* `add_monoid_algebra.grade_by.graded_algebra`: `add_monoid_algebra` is an algebra graded by
`add_monoid_algebra.grade_by`.
* `add_monoid_algebra.grade.graded_algebra`: `add_monoid_algebra` is an algebra graded by
`add_monoid_algebra.grade`.
* `add_monoid_algebra.grade_by.is_internal`: propositionally, the statement that
`add_monoid_algebra.grade_by` defines an internal graded structure.
* `add_monoid_algebra.grade.is_internal`: propositionally, the statement that
`add_monoid_algebra.grade` defines an internal graded structure when the degree function
is the identity.
-/
noncomputable theory
namespace add_monoid_algebra
variables {M : Type*} {ι : Type*} {R : Type*} [decidable_eq M]
section
variables (R) [comm_semiring R]
/-- The submodule corresponding to each grade given by the degree function `f`. -/
abbreviation grade_by (f : M → ι) (i : ι) : submodule R (add_monoid_algebra R M) :=
{ carrier := {a | ∀ m, m ∈ a.support → f m = i },
zero_mem' := set.empty_subset _,
add_mem' := λ a b ha hb m h,
or.rec_on (finset.mem_union.mp (finsupp.support_add h)) (ha m) (hb m),
smul_mem' := λ a m h, set.subset.trans finsupp.support_smul h }
/-- The submodule corresponding to each grade. -/
abbreviation grade (m : M) : submodule R (add_monoid_algebra R M) := grade_by R id m
lemma grade_by_id : grade_by R (id : M → M) = grade R := by refl
lemma mem_grade_by_iff (f : M → ι) (i : ι) (a : add_monoid_algebra R M) :
a ∈ grade_by R f i ↔ (a.support : set M) ⊆ f ⁻¹' {i} := by refl
lemma mem_grade_iff (m : M) (a : add_monoid_algebra R M) : a ∈ grade R m ↔ a.support ⊆ {m} :=
begin
rw [← finset.coe_subset, finset.coe_singleton],
refl
end
lemma mem_grade_iff' (m : M) (a : add_monoid_algebra R M) :
a ∈ grade R m ↔
a ∈ ((finsupp.lsingle m : R →ₗ[R] (M →₀ R)).range : submodule R (add_monoid_algebra R M)) :=
begin
rw [mem_grade_iff, finsupp.support_subset_singleton'],
apply exists_congr,
intros r,
split; exact eq.symm
end
lemma grade_eq_lsingle_range (m : M) : grade R m = (finsupp.lsingle m : R →ₗ[R] (M →₀ R)).range :=
submodule.ext (mem_grade_iff' R m)
lemma single_mem_grade_by {R} [comm_semiring R] (f : M → ι) (m : M) (r : R) :
finsupp.single m r ∈ grade_by R f (f m) :=
begin
intros x hx,
rw finset.mem_singleton.mp (finsupp.support_single_subset hx),
end
lemma single_mem_grade {R} [comm_semiring R] (i : M) (r : R) : finsupp.single i r ∈ grade R i :=
single_mem_grade_by _ _ _
end
open_locale direct_sum
instance grade_by.graded_monoid [add_monoid M] [add_monoid ι] [comm_semiring R] (f : M →+ ι) :
set_like.graded_monoid (grade_by R f : ι → submodule R (add_monoid_algebra R M)) :=
{ one_mem := λ m h, begin
rw one_def at h,
by_cases H : (1 : R) = (0 : R),
{ rw [H , finsupp.single_zero] at h,
exfalso,
exact h },
{ rw [finsupp.support_single_ne_zero _ H, finset.mem_singleton] at h,
rw [h, add_monoid_hom.map_zero] }
end,
mul_mem := λ i j a b ha hb c hc, begin
set h := support_mul a b hc,
simp only [finset.mem_bUnion] at h,
rcases h with ⟨ma, ⟨hma, ⟨mb, ⟨hmb, hmc⟩⟩⟩⟩,
rw [← ha ma hma, ← hb mb hmb, finset.mem_singleton.mp hmc],
apply add_monoid_hom.map_add
end }
instance grade.graded_monoid [add_monoid M] [comm_semiring R] :
set_like.graded_monoid (grade R : M → submodule R (add_monoid_algebra R M)) :=
by apply grade_by.graded_monoid (add_monoid_hom.id _)
variables {R} [add_monoid M] [decidable_eq ι] [add_monoid ι] [comm_semiring R] (f : M →+ ι)
/-- Auxiliary definition; the canonical grade decomposition, used to provide
`direct_sum.decompose`. -/
def decompose_aux : add_monoid_algebra R M →ₐ[R] ⨁ i : ι, grade_by R f i :=
add_monoid_algebra.lift R M _
{ to_fun := λ m, direct_sum.of (λ i : ι, grade_by R f i) (f m.to_add)
⟨finsupp.single m.to_add 1, single_mem_grade_by _ _ _⟩,
map_one' := direct_sum.of_eq_of_graded_monoid_eq (by congr' 2; try {ext};
simp only [submodule.mem_to_add_submonoid, to_add_one, add_monoid_hom.map_zero]),
map_mul' := λ i j, begin
symmetry,
convert direct_sum.of_mul_of _ _,
apply direct_sum.of_eq_of_graded_monoid_eq,
congr' 2,
{ rw [to_add_mul, add_monoid_hom.map_add] },
{ ext,
simp only [submodule.mem_to_add_submonoid, add_monoid_hom.map_add, to_add_mul] },
{ exact eq.trans (by rw [one_mul, to_add_mul]) single_mul_single.symm }
end }
lemma decompose_aux_single (m : M) (r : R) :
decompose_aux f (finsupp.single m r) =
direct_sum.of (λ i : ι, grade_by R f i) (f m)
⟨finsupp.single m r, single_mem_grade_by _ _ _⟩ :=
begin
refine (lift_single _ _ _).trans _,
refine (direct_sum.of_smul _ _ _ _).symm.trans _,
apply direct_sum.of_eq_of_graded_monoid_eq,
refine sigma.subtype_ext rfl _,
refine (finsupp.smul_single' _ _ _).trans _,
rw mul_one,
refl,
end
lemma decompose_aux_coe {i : ι} (x : grade_by R f i) :
decompose_aux f ↑x = direct_sum.of (λ i, grade_by R f i) i x :=
begin
obtain ⟨x, hx⟩ := x,
revert hx,
refine finsupp.induction x _ _,
{ intros hx,
symmetry,
exact add_monoid_hom.map_zero _ },
{ intros m b y hmy hb ih hmby,
have : disjoint (finsupp.single m b).support y.support,
{ simpa only [finsupp.support_single_ne_zero _ hb, finset.disjoint_singleton_left] },
rw [mem_grade_by_iff, finsupp.support_add_eq this, finset.coe_union,
set.union_subset_iff] at hmby,
cases hmby with h1 h2,
have : f m = i,
{ rwa [finsupp.support_single_ne_zero _ hb, finset.coe_singleton,
set.singleton_subset_iff] at h1 },
subst this,
simp only [alg_hom.map_add, submodule.coe_mk, decompose_aux_single f m],
let ih' := ih h2,
dsimp at ih',
rw [ih', ← add_monoid_hom.map_add],
apply direct_sum.of_eq_of_graded_monoid_eq,
congr' 2 }
end
instance grade_by.graded_algebra : graded_algebra (grade_by R f) :=
graded_algebra.of_alg_hom _
(decompose_aux f)
(begin
ext : 2,
simp only [alg_hom.coe_to_monoid_hom, function.comp_app, alg_hom.coe_comp,
function.comp.left_id, alg_hom.coe_id, add_monoid_algebra.of_apply, monoid_hom.coe_comp],
rw [decompose_aux_single, direct_sum.coe_alg_hom_of, subtype.coe_mk],
end)
(λ i x, by rw [decompose_aux_coe f x])
-- Lean can't find this later without us repeating it
instance grade_by.decomposition : direct_sum.decomposition (grade_by R f) :=
by apply_instance
@[simp] lemma decompose_aux_eq_decompose :
⇑(decompose_aux f : add_monoid_algebra R M →ₐ[R] ⨁ i : ι, grade_by R f i) =
(direct_sum.decompose (grade_by R f)) := rfl
@[simp] lemma grades_by.decompose_single (m : M) (r : R) :
direct_sum.decompose (grade_by R f) (finsupp.single m r : add_monoid_algebra R M) =
direct_sum.of (λ i : ι, grade_by R f i) (f m)
⟨finsupp.single m r, single_mem_grade_by _ _ _⟩ :=
decompose_aux_single _ _ _
instance grade.graded_algebra : graded_algebra (grade R : ι → submodule _ _) :=
add_monoid_algebra.grade_by.graded_algebra (add_monoid_hom.id _)
-- Lean can't find this later without us repeating it
instance grade.decomposition : direct_sum.decomposition (grade R : ι → submodule _ _) :=
by apply_instance
@[simp]
lemma grade.decompose_single (i : ι) (r : R) :
direct_sum.decompose (grade R : ι → submodule _ _) (finsupp.single i r : add_monoid_algebra _ _) =
direct_sum.of (λ i : ι, grade R i) i ⟨finsupp.single i r, single_mem_grade _ _⟩ :=
decompose_aux_single _ _ _
/-- `add_monoid_algebra.gradesby` describe an internally graded algebra -/
lemma grade_by.is_internal : direct_sum.is_internal (grade_by R f) :=
direct_sum.decomposition.is_internal _
/-- `add_monoid_algebra.grades` describe an internally graded algebra -/
lemma grade.is_internal : direct_sum.is_internal (grade R : ι → submodule R _) :=
direct_sum.decomposition.is_internal _
end add_monoid_algebra
|
c6731fd1ae6af715c30c5a133682b3cbedb8fb8a | 26ac254ecb57ffcb886ff709cf018390161a9225 | /src/algebra/group_action_hom.lean | c1c91dfc2c2e5b1a05e8d9763075a80edc05d449 | [
"Apache-2.0"
] | permissive | eric-wieser/mathlib | 42842584f584359bbe1fc8b88b3ff937c8acd72d | d0df6b81cd0920ad569158c06a3fd5abb9e63301 | refs/heads/master | 1,669,546,404,255 | 1,595,254,668,000 | 1,595,254,668,000 | 281,173,504 | 0 | 0 | Apache-2.0 | 1,595,263,582,000 | 1,595,263,581,000 | null | UTF-8 | Lean | false | false | 8,871 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.group_ring_action
/-!
# Equivariant homomorphisms
## Main definitions
* `mul_action_hom M X Y`, the type of equivariant functions from `X` to `Y`, where `M` is a monoid
that acts on the types `X` and `Y`.
* `distrib_mul_action_hom M A B`, the type of equivariant additive monoid homomorphisms
from `A` to `B`, where `M` is a monoid that acts on the additive monoids `A` and `B`.
* `mul_semiring_action_hom M R S`, the type of equivariant ring homomorphisms
from `R` to `S`, where `M` is a monoid that acts on the rings `R` and `S`.
## Notations
* `X →[M] Y` is `mul_action_hom M X Y`.
* `A →+[M] B` is `distrib_mul_action_hom M X Y`.
* `R →+*[M] S` is `mul_semiring_action_hom M X Y`.
-/
variables (M : Type*) [monoid M]
variables (X : Type*) [mul_action M X]
variables (Y : Type*) [mul_action M Y]
variables (Z : Type*) [mul_action M Z]
variables (A : Type*) [add_monoid A] [distrib_mul_action M A]
variables (A' : Type*) [add_group A'] [distrib_mul_action M A']
variables (B : Type*) [add_monoid B] [distrib_mul_action M B]
variables (B' : Type*) [add_group B'] [distrib_mul_action M B']
variables (C : Type*) [add_monoid C] [distrib_mul_action M C]
variables (R : Type*) [semiring R] [mul_semiring_action M R]
variables (R' : Type*) [ring R'] [mul_semiring_action M R']
variables (S : Type*) [semiring S] [mul_semiring_action M S]
variables (S' : Type*) [ring S'] [mul_semiring_action M S']
variables (T : Type*) [semiring T] [mul_semiring_action M T]
variables (G : Type*) [group G] (H : set G) [is_subgroup H]
set_option old_structure_cmd true
/-- Equivariant functions. -/
@[nolint has_inhabited_instance]
structure mul_action_hom :=
(to_fun : X → Y)
(map_smul' : ∀ (m : M) (x : X), to_fun (m • x) = m • to_fun x)
notation X ` →[`:25 M:25 `] `:0 Y:0 := mul_action_hom M X Y
namespace mul_action_hom
instance : has_coe_to_fun (X →[M] Y) :=
⟨_, λ c, c.to_fun⟩
variables {M X Y}
@[simp] lemma map_smul (f : X →[M] Y) (m : M) (x : X) : f (m • x) = m • f x :=
f.map_smul' m x
@[ext] theorem ext : ∀ {f g : X →[M] Y}, (∀ x, f x = g x) → f = g
| ⟨f, _⟩ ⟨g, _⟩ H := by { congr' 1, ext x, exact H x }
theorem ext_iff {f g : X →[M] Y} : f = g ↔ ∀ x, f x = g x :=
⟨λ H x, by rw H, ext⟩
variables (M) {X}
/-- The identity map as an equivariant map. -/
protected def id : X →[M] X :=
⟨id, λ _ _, rfl⟩
@[simp] lemma id_apply (x : X) : mul_action_hom.id M x = x := rfl
variables {M X Y Z}
/-- Composition of two equivariant maps. -/
def comp (g : Y →[M] Z) (f : X →[M] Y) : X →[M] Z :=
⟨g ∘ f, λ m x, calc
g (f (m • x)) = g (m • f x) : by rw f.map_smul
... = m • g (f x) : g.map_smul _ _⟩
@[simp] lemma comp_apply (g : Y →[M] Z) (f : X →[M] Y) (x : X) : g.comp f x = g (f x) := rfl
@[simp] lemma id_comp (f : X →[M] Y) : (mul_action_hom.id M).comp f = f :=
ext $ λ x, by rw [comp_apply, id_apply]
@[simp] lemma comp_id (f : X →[M] Y) : f.comp (mul_action_hom.id M) = f :=
ext $ λ x, by rw [comp_apply, id_apply]
local attribute [instance] mul_action.regular
variables {G} (H)
/-- The canonical map to the left cosets. -/
def to_quotient : G →[G] quotient_group.quotient H :=
⟨coe, λ g x, rfl⟩
@[simp] lemma to_quotient_apply (g : G) : to_quotient H g = g := rfl
end mul_action_hom
/-- Equivariant additive monoid homomorphisms. -/
@[nolint has_inhabited_instance]
structure distrib_mul_action_hom extends A →[M] B, A →+ B.
/-- Reinterpret an equivariant additive monoid homomorphism as an additive monoid homomorphism. -/
add_decl_doc distrib_mul_action_hom.to_add_monoid_hom
/-- Reinterpret an equivariant additive monoid homomorphism as an equivariant function. -/
add_decl_doc distrib_mul_action_hom.to_mul_action_hom
notation A ` →+[`:25 M:25 `] `:0 B:0 := distrib_mul_action_hom M A B
namespace distrib_mul_action_hom
instance has_coe : has_coe (A →+[M] B) (A →+ B) :=
⟨to_add_monoid_hom⟩
instance has_coe' : has_coe (A →+[M] B) (A →[M] B) :=
⟨to_mul_action_hom⟩
instance : has_coe_to_fun (A →+[M] B) :=
⟨_, λ c, c.to_fun⟩
variables {M A B}
@[norm_cast] lemma coe_fn_coe (f : A →+[M] B) : ((f : A →+ B) : A → B) = f := rfl
@[norm_cast] lemma coe_fn_coe' (f : A →+[M] B) : ((f : A →[M] B) : A → B) = f := rfl
@[ext] theorem ext : ∀ {f g : A →+[M] B}, (∀ x, f x = g x) → f = g
| ⟨f, _, _, _⟩ ⟨g, _, _, _⟩ H := by { congr' 1, ext x, exact H x }
theorem ext_iff {f g : A →+[M] B} : f = g ↔ ∀ x, f x = g x :=
⟨λ H x, by rw H, ext⟩
@[simp] lemma map_zero (f : A →+[M] B) : f 0 = 0 :=
f.map_zero'
@[simp] lemma map_add (f : A →+[M] B) (x y : A) : f (x + y) = f x + f y :=
f.map_add' x y
@[simp] lemma map_neg (f : A' →+[M] B') (x : A') : f (-x) = -f x :=
(f : A' →+ B').map_neg x
@[simp] lemma map_sub (f : A' →+[M] B') (x y : A') : f (x - y) = f x - f y :=
(f : A' →+ B').map_sub x y
@[simp] lemma map_smul (f : A →+[M] B) (m : M) (x : A) : f (m • x) = m • f x :=
f.map_smul' m x
variables (M) {A}
/-- The identity map as an equivariant additive monoid homomorphism. -/
protected def id : A →+[M] A :=
⟨id, λ _ _, rfl, rfl, λ _ _, rfl⟩
@[simp] lemma id_apply (x : A) : distrib_mul_action_hom.id M x = x := rfl
variables {M A B C}
/-- Composition of two equivariant additive monoid homomorphisms. -/
def comp (g : B →+[M] C) (f : A →+[M] B) : A →+[M] C :=
{ .. mul_action_hom.comp (g : B →[M] C) (f : A →[M] B),
.. add_monoid_hom.comp (g : B →+ C) (f : A →+ B), }
@[simp] lemma comp_apply (g : B →+[M] C) (f : A →+[M] B) (x : A) : g.comp f x = g (f x) := rfl
@[simp] lemma id_comp (f : A →+[M] B) : (distrib_mul_action_hom.id M).comp f = f :=
ext $ λ x, by rw [comp_apply, id_apply]
@[simp] lemma comp_id (f : A →+[M] B) : f.comp (distrib_mul_action_hom.id M) = f :=
ext $ λ x, by rw [comp_apply, id_apply]
end distrib_mul_action_hom
/-- Equivariant ring homomorphisms. -/
@[nolint has_inhabited_instance]
structure mul_semiring_action_hom extends R →+[M] S, R →+* S.
/-- Reinterpret an equivariant ring homomorphism as a ring homomorphism. -/
add_decl_doc mul_semiring_action_hom.to_ring_hom
/-- Reinterpret an equivariant ring homomorphism as an equivariant additive monoid homomorphism. -/
add_decl_doc mul_semiring_action_hom.to_distrib_mul_action_hom
notation R ` →+*[`:25 M:25 `] `:0 S:0 := mul_semiring_action_hom M R S
namespace mul_semiring_action_hom
instance has_coe : has_coe (R →+*[M] S) (R →+* S) :=
⟨to_ring_hom⟩
instance has_coe' : has_coe (R →+*[M] S) (R →+[M] S) :=
⟨to_distrib_mul_action_hom⟩
instance : has_coe_to_fun (R →+*[M] S) :=
⟨_, λ c, c.to_fun⟩
variables {M R S}
@[norm_cast] lemma coe_fn_coe (f : R →+*[M] S) : ((f : R →+* S) : R → S) = f := rfl
@[norm_cast] lemma coe_fn_coe' (f : R →+*[M] S) : ((f : R →+[M] S) : R → S) = f := rfl
@[ext] theorem ext : ∀ {f g : R →+*[M] S}, (∀ x, f x = g x) → f = g
| ⟨f, _, _, _, _, _⟩ ⟨g, _, _, _, _, _⟩ H := by { congr' 1, ext x, exact H x }
theorem ext_iff {f g : R →+*[M] S} : f = g ↔ ∀ x, f x = g x :=
⟨λ H x, by rw H, ext⟩
@[simp] lemma map_zero (f : R →+*[M] S) : f 0 = 0 :=
f.map_zero'
@[simp] lemma map_add (f : R →+*[M] S) (x y : R) : f (x + y) = f x + f y :=
f.map_add' x y
@[simp] lemma map_neg (f : R' →+*[M] S') (x : R') : f (-x) = -f x :=
(f : R' →+* S').map_neg x
@[simp] lemma map_sub (f : R' →+*[M] S') (x y : R') : f (x - y) = f x - f y :=
(f : R' →+* S').map_sub x y
@[simp] lemma map_one (f : R →+*[M] S) : f 1 = 1 :=
f.map_one'
@[simp] lemma map_mul (f : R →+*[M] S) (x y : R) : f (x * y) = f x * f y :=
f.map_mul' x y
@[simp] lemma map_smul (f : R →+*[M] S) (m : M) (x : R) : f (m • x) = m • f x :=
f.map_smul' m x
variables (M) {R}
/-- The identity map as an equivariant ring homomorphism. -/
protected def id : R →+*[M] R :=
⟨id, λ _ _, rfl, rfl, λ _ _, rfl, rfl, λ _ _, rfl⟩
@[simp] lemma id_apply (x : R) : mul_semiring_action_hom.id M x = x := rfl
variables {M R S T}
/-- Composition of two equivariant additive monoid homomorphisms. -/
def comp (g : S →+*[M] T) (f : R →+*[M] S) : R →+*[M] T :=
{ .. distrib_mul_action_hom.comp (g : S →+[M] T) (f : R →+[M] S),
.. ring_hom.comp (g : S →+* T) (f : R →+* S), }
@[simp] lemma comp_apply (g : S →+*[M] T) (f : R →+*[M] S) (x : R) : g.comp f x = g (f x) := rfl
@[simp] lemma id_comp (f : R →+*[M] S) : (mul_semiring_action_hom.id M).comp f = f :=
ext $ λ x, by rw [comp_apply, id_apply]
@[simp] lemma comp_id (f : R →+*[M] S) : f.comp (mul_semiring_action_hom.id M) = f :=
ext $ λ x, by rw [comp_apply, id_apply]
end mul_semiring_action_hom
|
7ad90f52d508c2c8bf4c5bddfb6c8796feef032b | c777c32c8e484e195053731103c5e52af26a25d1 | /src/measure_theory/function/jacobian.lean | 3be38f43111b4bcf007d520cefd2f5d32fd9614b | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 69,640 | lean | /-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import measure_theory.covering.besicovitch_vector_space
import measure_theory.measure.haar_lebesgue
import analysis.normed_space.pointwise
import measure_theory.constructions.polish
/-!
# Change of variables in higher-dimensional integrals
Let `μ` be a Lebesgue measure on a finite-dimensional real vector space `E`.
Let `f : E → E` be a function which is injective and differentiable on a measurable set `s`,
with derivative `f'`. Then we prove that `f '' s` is measurable, and
its measure is given by the formula `μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ` (where `(f' x).det`
is almost everywhere measurable, but not Borel-measurable in general). This formula is proved in
`lintegral_abs_det_fderiv_eq_add_haar_image`. We deduce the change of variables
formula for the Lebesgue and Bochner integrals, in `lintegral_image_eq_lintegral_abs_det_fderiv_mul`
and `integral_image_eq_integral_abs_det_fderiv_smul` respectively.
## Main results
* `add_haar_image_eq_zero_of_differentiable_on_of_add_haar_eq_zero`: if `f` is differentiable on a
set `s` with zero measure, then `f '' s` also has zero measure.
* `add_haar_image_eq_zero_of_det_fderiv_within_eq_zero`: if `f` is differentiable on a set `s`, and
its derivative is never invertible, then `f '' s` has zero measure (a version of Sard's lemma).
* `ae_measurable_fderiv_within`: if `f` is differentiable on a measurable set `s`, then `f'`
is almost everywhere measurable on `s`.
For the next statements, `s` is a measurable set and `f` is differentiable on `s`
(with a derivative `f'`) and injective on `s`.
* `measurable_image_of_fderiv_within`: the image `f '' s` is measurable.
* `measurable_embedding_of_fderiv_within`: the function `s.restrict f` is a measurable embedding.
* `lintegral_abs_det_fderiv_eq_add_haar_image`: the image measure is given by
`μ (f '' s) = ∫⁻ x in s, |(f' x).det| ∂μ`.
* `lintegral_image_eq_lintegral_abs_det_fderiv_mul`: for `g : E → ℝ≥0∞`, one has
`∫⁻ x in f '' s, g x ∂μ = ∫⁻ x in s, ennreal.of_real (|(f' x).det|) * g (f x) ∂μ`.
* `integral_image_eq_integral_abs_det_fderiv_smul`: for `g : E → F`, one has
`∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ`.
* `integrable_on_image_iff_integrable_on_abs_det_fderiv_smul`: for `g : E → F`, the function `g` is
integrable on `f '' s` if and only if `|(f' x).det| • g (f x))` is integrable on `s`.
## Implementation
Typical versions of these results in the literature have much stronger assumptions: `s` would
typically be open, and the derivative `f' x` would depend continuously on `x` and be invertible
everywhere, to have the local inverse theorem at our disposal. The proof strategy under our weaker
assumptions is more involved. We follow [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2].
The first remark is that, if `f` is sufficiently well approximated by a linear map `A` on a set
`s`, then `f` expands the volume of `s` by at least `A.det - ε` and at most `A.det + ε`, where
the closeness condition depends on `A` in a non-explicit way (see `add_haar_image_le_mul_of_det_lt`
and `mul_le_add_haar_image_of_lt_det`). This fact holds for balls by a simple inclusion argument,
and follows for general sets using the Besicovitch covering theorem to cover the set by balls with
measures adding up essentially to `μ s`.
When `f` is differentiable on `s`, one may partition `s` into countably many subsets `s ∩ t n`
(where `t n` is measurable), on each of which `f` is well approximated by a linear map, so that the
above results apply. See `exists_partition_approximates_linear_on_of_has_fderiv_within_at`, which
follows from the pointwise differentiability (in a non-completely trivial way, as one should ensure
a form of uniformity on the sets of the partition).
Combining the above two results would give the conclusion, except for two difficulties: it is not
obvious why `f '' s` and `f'` should be measurable, which prevents us from using countable
additivity for the measure and the integral. It turns out that `f '' s` is indeed measurable,
and that `f'` is almost everywhere measurable, which is enough to recover countable additivity.
The measurability of `f '' s` follows from the deep Lusin-Souslin theorem ensuring that, in a
Polish space, a continuous injective image of a measurable set is measurable.
The key point to check the almost everywhere measurability of `f'` is that, if `f` is approximated
up to `δ` by a linear map on a set `s`, then `f'` is within `δ` of `A` on a full measure subset
of `s` (namely, its density points). With the above approximation argument, it follows that `f'`
is the almost everywhere limit of a sequence of measurable functions (which are constant on the
pieces of the good discretization), and is therefore almost everywhere measurable.
## Tags
Change of variables in integrals
## References
[Fremlin, *Measure Theory* (volume 2)][fremlin_vol2]
-/
open measure_theory measure_theory.measure metric filter set finite_dimensional asymptotics
topological_space
open_locale nnreal ennreal topology pointwise
variables {E F : Type*} [normed_add_comm_group E] [normed_space ℝ E] [finite_dimensional ℝ E]
[normed_add_comm_group F] [normed_space ℝ F] {s : set E} {f : E → E} {f' : E → E →L[ℝ] E}
/-!
### Decomposition lemmas
We state lemmas ensuring that a differentiable function can be approximated, on countably many
measurable pieces, by linear maps (with a prescribed precision depending on the linear map).
-/
/-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may cover `s`
with countably many closed sets `t n` on which `f` is well approximated by linear maps `A n`. -/
lemma exists_closed_cover_approximates_linear_on_of_has_fderiv_within_at
[second_countable_topology F]
(f : E → F) (s : set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x)
(r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) :
∃ (t : ℕ → set E) (A : ℕ → (E →L[ℝ] F)), (∀ n, is_closed (t n)) ∧ (s ⊆ ⋃ n, t n)
∧ (∀ n, approximates_linear_on f (A n) (s ∩ t n) (r (A n)))
∧ (s.nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
begin
/- Choose countably many linear maps `f' z`. For every such map, if `f` has a derivative at `x`
close enough to `f' z`, then `f y - f x` is well approximated by `f' z (y - x)` for `y` close
enough to `x`, say on a ball of radius `r` (or even `u n` for some `n`, where `u` is a fixed
sequence tending to `0`).
Let `M n z` be the points where this happens. Then this set is relatively closed inside `s`,
and moreover in every closed ball of radius `u n / 3` inside it the map is well approximated by
`f' z`. Using countably many closed balls to split `M n z` into small diameter subsets `K n z p`,
one obtains the desired sets `t q` after reindexing.
-/
-- exclude the trivial case where `s` is empty
rcases eq_empty_or_nonempty s with rfl|hs,
{ refine ⟨λ n, ∅, λ n, 0, _, _, _, _⟩;
simp },
-- we will use countably many linear maps. Select these from all the derivatives since the
-- space of linear maps is second-countable
obtain ⟨T, T_count, hT⟩ : ∃ T : set s, T.countable ∧
(⋃ x ∈ T, ball (f' (x : E)) (r (f' x))) = ⋃ (x : s), ball (f' x) (r (f' x)) :=
topological_space.is_open_Union_countable _ (λ x, is_open_ball),
-- fix a sequence `u` of positive reals tending to zero.
obtain ⟨u, u_anti, u_pos, u_lim⟩ :
∃ (u : ℕ → ℝ), strict_anti u ∧ (∀ (n : ℕ), 0 < u n) ∧ tendsto u at_top (𝓝 0) :=
exists_seq_strict_anti_tendsto (0 : ℝ),
-- `M n z` is the set of points `x` such that `f y - f x` is close to `f' z (y - x)` for `y`
-- in the ball of radius `u n` around `x`.
let M : ℕ → T → set E := λ n z, {x | x ∈ s ∧
∀ y ∈ s ∩ ball x (u n), ‖f y - f x - f' z (y - x)‖ ≤ r (f' z) * ‖y - x‖},
-- As `f` is differentiable everywhere on `s`, the sets `M n z` cover `s` by design.
have s_subset : ∀ x ∈ s, ∃ (n : ℕ) (z : T), x ∈ M n z,
{ assume x xs,
obtain ⟨z, zT, hz⟩ : ∃ z ∈ T, f' x ∈ ball (f' (z : E)) (r (f' z)),
{ have : f' x ∈ ⋃ (z ∈ T), ball (f' (z : E)) (r (f' z)),
{ rw hT,
refine mem_Union.2 ⟨⟨x, xs⟩, _⟩,
simpa only [mem_ball, subtype.coe_mk, dist_self] using (rpos (f' x)).bot_lt },
rwa mem_Union₂ at this },
obtain ⟨ε, εpos, hε⟩ : ∃ (ε : ℝ), 0 < ε ∧ ‖f' x - f' z‖ + ε ≤ r (f' z),
{ refine ⟨r (f' z) - ‖f' x - f' z‖, _, le_of_eq (by abel)⟩,
simpa only [sub_pos] using mem_ball_iff_norm.mp hz },
obtain ⟨δ, δpos, hδ⟩ : ∃ (δ : ℝ) (H : 0 < δ),
ball x δ ∩ s ⊆ {y | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} :=
metric.mem_nhds_within_iff.1 (is_o.def (hf' x xs) εpos),
obtain ⟨n, hn⟩ : ∃ n, u n < δ := ((tendsto_order.1 u_lim).2 _ δpos).exists,
refine ⟨n, ⟨z, zT⟩, ⟨xs, _⟩⟩,
assume y hy,
calc ‖f y - f x - (f' z) (y - x)‖
= ‖(f y - f x - (f' x) (y - x)) + (f' x - f' z) (y - x)‖ :
begin
congr' 1,
simp only [continuous_linear_map.coe_sub', map_sub, pi.sub_apply],
abel,
end
... ≤ ‖f y - f x - (f' x) (y - x)‖ + ‖(f' x - f' z) (y - x)‖ : norm_add_le _ _
... ≤ ε * ‖y - x‖ + ‖f' x - f' z‖ * ‖y - x‖ :
begin
refine add_le_add (hδ _) (continuous_linear_map.le_op_norm _ _),
rw inter_comm,
exact inter_subset_inter_right _ (ball_subset_ball hn.le) hy,
end
... ≤ r (f' z) * ‖y - x‖ :
begin
rw [← add_mul, add_comm],
exact mul_le_mul_of_nonneg_right hε (norm_nonneg _),
end },
-- the sets `M n z` are relatively closed in `s`, as all the conditions defining it are clearly
-- closed
have closure_M_subset : ∀ n z, s ∩ closure (M n z) ⊆ M n z,
{ rintros n z x ⟨xs, hx⟩,
refine ⟨xs, λ y hy, _⟩,
obtain ⟨a, aM, a_lim⟩ : ∃ (a : ℕ → E), (∀ k, a k ∈ M n z) ∧ tendsto a at_top (𝓝 x) :=
mem_closure_iff_seq_limit.1 hx,
have L1 : tendsto (λ (k : ℕ), ‖f y - f (a k) - (f' z) (y - a k)‖) at_top
(𝓝 ‖f y - f x - (f' z) (y - x)‖),
{ apply tendsto.norm,
have L : tendsto (λ k, f (a k)) at_top (𝓝 (f x)),
{ apply (hf' x xs).continuous_within_at.tendsto.comp,
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ a_lim,
exact eventually_of_forall (λ k, (aM k).1) },
apply tendsto.sub (tendsto_const_nhds.sub L),
exact ((f' z).continuous.tendsto _).comp (tendsto_const_nhds.sub a_lim) },
have L2 : tendsto (λ (k : ℕ), (r (f' z) : ℝ) * ‖y - a k‖) at_top (𝓝 (r (f' z) * ‖y - x‖)) :=
(tendsto_const_nhds.sub a_lim).norm.const_mul _,
have I : ∀ᶠ k in at_top, ‖f y - f (a k) - (f' z) (y - a k)‖ ≤ r (f' z) * ‖y - a k‖,
{ have L : tendsto (λ k, dist y (a k)) at_top (𝓝 (dist y x)) := tendsto_const_nhds.dist a_lim,
filter_upwards [(tendsto_order.1 L).2 _ hy.2],
assume k hk,
exact (aM k).2 y ⟨hy.1, hk⟩ },
exact le_of_tendsto_of_tendsto L1 L2 I },
-- choose a dense sequence `d p`
rcases topological_space.exists_dense_seq E with ⟨d, hd⟩,
-- split `M n z` into subsets `K n z p` of small diameters by intersecting with the ball
-- `closed_ball (d p) (u n / 3)`.
let K : ℕ → T → ℕ → set E := λ n z p, closure (M n z) ∩ closed_ball (d p) (u n / 3),
-- on the sets `K n z p`, the map `f` is well approximated by `f' z` by design.
have K_approx : ∀ n (z : T) p, approximates_linear_on f (f' z) (s ∩ K n z p) (r (f' z)),
{ assume n z p x hx y hy,
have yM : y ∈ M n z := closure_M_subset _ _ ⟨hy.1, hy.2.1⟩,
refine yM.2 _ ⟨hx.1, _⟩,
calc dist x y ≤ dist x (d p) + dist y (d p) : dist_triangle_right _ _ _
... ≤ u n / 3 + u n / 3 : add_le_add hx.2.2 hy.2.2
... < u n : by linarith [u_pos n] },
-- the sets `K n z p` are also closed, again by design.
have K_closed : ∀ n (z : T) p, is_closed (K n z p) :=
λ n z p, is_closed_closure.inter is_closed_ball,
-- reindex the sets `K n z p`, to let them only depend on an integer parameter `q`.
obtain ⟨F, hF⟩ : ∃ F : ℕ → ℕ × T × ℕ, function.surjective F,
{ haveI : encodable T := T_count.to_encodable,
haveI : nonempty T,
{ unfreezingI { rcases eq_empty_or_nonempty T with rfl|hT },
{ rcases hs with ⟨x, xs⟩,
rcases s_subset x xs with ⟨n, z, hnz⟩,
exact false.elim z.2 },
{ exact hT.coe_sort } },
inhabit (ℕ × T × ℕ),
exact ⟨_, encodable.surjective_decode_iget _⟩ },
-- these sets `t q = K n z p` will do
refine ⟨λ q, K (F q).1 (F q).2.1 (F q).2.2, λ q, f' (F q).2.1, λ n, K_closed _ _ _, λ x xs, _,
λ q, K_approx _ _ _, λ h's q, ⟨(F q).2.1, (F q).2.1.1.2, rfl⟩⟩,
-- the only fact that needs further checking is that they cover `s`.
-- we already know that any point `x ∈ s` belongs to a set `M n z`.
obtain ⟨n, z, hnz⟩ : ∃ (n : ℕ) (z : T), x ∈ M n z := s_subset x xs,
-- by density, it also belongs to a ball `closed_ball (d p) (u n / 3)`.
obtain ⟨p, hp⟩ : ∃ (p : ℕ), x ∈ closed_ball (d p) (u n / 3),
{ have : set.nonempty (ball x (u n / 3)),
{ simp only [nonempty_ball], linarith [u_pos n] },
obtain ⟨p, hp⟩ : ∃ (p : ℕ), d p ∈ ball x (u n / 3) := hd.exists_mem_open is_open_ball this,
exact ⟨p, (mem_ball'.1 hp).le⟩ },
-- choose `q` for which `t q = K n z p`.
obtain ⟨q, hq⟩ : ∃ q, F q = (n, z, p) := hF _,
-- then `x` belongs to `t q`.
apply mem_Union.2 ⟨q, _⟩,
simp only [hq, subset_closure hnz, hp, mem_inter_iff, and_self],
end
variables [measurable_space E] [borel_space E] (μ : measure E) [is_add_haar_measure μ]
/-- Assume that a function `f` has a derivative at every point of a set `s`. Then one may
partition `s` into countably many disjoint relatively measurable sets (i.e., intersections
of `s` with measurable sets `t n`) on which `f` is well approximated by linear maps `A n`. -/
lemma exists_partition_approximates_linear_on_of_has_fderiv_within_at
[second_countable_topology F]
(f : E → F) (s : set E) (f' : E → E →L[ℝ] F) (hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x)
(r : (E →L[ℝ] F) → ℝ≥0) (rpos : ∀ A, r A ≠ 0) :
∃ (t : ℕ → set E) (A : ℕ → (E →L[ℝ] F)), pairwise (disjoint on t)
∧ (∀ n, measurable_set (t n)) ∧ (s ⊆ ⋃ n, t n)
∧ (∀ n, approximates_linear_on f (A n) (s ∩ t n) (r (A n)))
∧ (s.nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
begin
rcases exists_closed_cover_approximates_linear_on_of_has_fderiv_within_at f s f' hf' r rpos
with ⟨t, A, t_closed, st, t_approx, ht⟩,
refine ⟨disjointed t, A, disjoint_disjointed _,
measurable_set.disjointed (λ n, (t_closed n).measurable_set), _, _, ht⟩,
{ rw Union_disjointed, exact st },
{ assume n, exact (t_approx n).mono_set (inter_subset_inter_right _ (disjointed_subset _ _)) },
end
namespace measure_theory
/-!
### Local lemmas
We check that a function which is well enough approximated by a linear map expands the volume
essentially like this linear map, and that its derivative (if it exists) is almost everywhere close
to the approximating linear map.
-/
/-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear
map `A`. Then it expands the volume of any set by at most `m` for any `m > det A`. -/
lemma add_haar_image_le_mul_of_det_lt
(A : E →L[ℝ] E) {m : ℝ≥0} (hm : ennreal.of_real (|A.det|) < m) :
∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : set E) (f : E → E) (hf : approximates_linear_on f A s δ),
μ (f '' s) ≤ m * μ s :=
begin
apply nhds_within_le_nhds,
let d := ennreal.of_real (|A.det|),
-- construct a small neighborhood of `A '' (closed_ball 0 1)` with measure comparable to
-- the determinant of `A`.
obtain ⟨ε, hε, εpos⟩ : ∃ (ε : ℝ),
μ (closed_ball 0 ε + A '' (closed_ball 0 1)) < m * μ (closed_ball 0 1) ∧ 0 < ε,
{ have HC : is_compact (A '' closed_ball 0 1) :=
(proper_space.is_compact_closed_ball _ _).image A.continuous,
have L0 : tendsto (λ ε, μ (cthickening ε (A '' (closed_ball 0 1))))
(𝓝[>] 0) (𝓝 (μ (A '' (closed_ball 0 1)))),
{ apply tendsto.mono_left _ nhds_within_le_nhds,
exact tendsto_measure_cthickening_of_is_compact HC },
have L1 : tendsto (λ ε, μ (closed_ball 0 ε + A '' (closed_ball 0 1)))
(𝓝[>] 0) (𝓝 (μ (A '' (closed_ball 0 1)))),
{ apply L0.congr' _,
filter_upwards [self_mem_nhds_within] with r hr,
rw [←HC.add_closed_ball_zero (le_of_lt hr), add_comm] },
have L2 : tendsto (λ ε, μ (closed_ball 0 ε + A '' (closed_ball 0 1)))
(𝓝[>] 0) (𝓝 (d * μ (closed_ball 0 1))),
{ convert L1,
exact (add_haar_image_continuous_linear_map _ _ _).symm },
have I : d * μ (closed_ball 0 1) < m * μ (closed_ball 0 1) :=
(ennreal.mul_lt_mul_right ((measure_closed_ball_pos μ _ zero_lt_one).ne')
measure_closed_ball_lt_top.ne).2 hm,
have H : ∀ᶠ (b : ℝ) in 𝓝[>] 0,
μ (closed_ball 0 b + A '' closed_ball 0 1) < m * μ (closed_ball 0 1) :=
(tendsto_order.1 L2).2 _ I,
exact (H.and self_mem_nhds_within).exists },
have : Iio (⟨ε, εpos.le⟩ : ℝ≥0) ∈ 𝓝 (0 : ℝ≥0), { apply Iio_mem_nhds, exact εpos },
filter_upwards [this],
-- fix a function `f` which is close enough to `A`.
assume δ hδ s f hf,
-- This function expands the volume of any ball by at most `m`
have I : ∀ x r, x ∈ s → 0 ≤ r → μ (f '' (s ∩ closed_ball x r)) ≤ m * μ (closed_ball x r),
{ assume x r xs r0,
have K : f '' (s ∩ closed_ball x r) ⊆ A '' (closed_ball 0 r) + closed_ball (f x) (ε * r),
{ rintros y ⟨z, ⟨zs, zr⟩, rfl⟩,
apply set.mem_add.2 ⟨A (z - x), f z - f x - A (z - x) + f x, _, _, _⟩,
{ apply mem_image_of_mem,
simpa only [dist_eq_norm, mem_closed_ball, mem_closed_ball_zero_iff] using zr },
{ rw [mem_closed_ball_iff_norm, add_sub_cancel],
calc ‖f z - f x - A (z - x)‖
≤ δ * ‖z - x‖ : hf _ zs _ xs
... ≤ ε * r :
mul_le_mul (le_of_lt hδ) (mem_closed_ball_iff_norm.1 zr) (norm_nonneg _) εpos.le },
{ simp only [map_sub, pi.sub_apply],
abel } },
have : A '' (closed_ball 0 r) + closed_ball (f x) (ε * r)
= {f x} + r • (A '' (closed_ball 0 1) + closed_ball 0 ε),
by rw [smul_add, ← add_assoc, add_comm ({f x}), add_assoc, smul_closed_ball _ _ εpos.le,
smul_zero, singleton_add_closed_ball_zero, ← image_smul_set ℝ E E A,
smul_closed_ball _ _ zero_le_one, smul_zero, real.norm_eq_abs, abs_of_nonneg r0, mul_one,
mul_comm],
rw this at K,
calc μ (f '' (s ∩ closed_ball x r))
≤ μ ({f x} + r • (A '' (closed_ball 0 1) + closed_ball 0 ε)) : measure_mono K
... = ennreal.of_real (r ^ finrank ℝ E) * μ (A '' closed_ball 0 1 + closed_ball 0 ε) :
by simp only [abs_of_nonneg r0, add_haar_smul, image_add_left, abs_pow, singleton_add,
measure_preimage_add]
... ≤ ennreal.of_real (r ^ finrank ℝ E) * (m * μ (closed_ball 0 1)) :
by { rw add_comm, exact mul_le_mul_left' hε.le _ }
... = m * μ (closed_ball x r) :
by { simp only [add_haar_closed_ball' _ _ r0], ring } },
-- covering `s` by closed balls with total measure very close to `μ s`, one deduces that the
-- measure of `f '' s` is at most `m * (μ s + a)` for any positive `a`.
have J : ∀ᶠ a in 𝓝[>] (0 : ℝ≥0∞), μ (f '' s) ≤ m * (μ s + a),
{ filter_upwards [self_mem_nhds_within] with a ha,
change 0 < a at ha,
obtain ⟨t, r, t_count, ts, rpos, st, μt⟩ : ∃ (t : set E) (r : E → ℝ), t.countable ∧ t ⊆ s
∧ (∀ (x : E), x ∈ t → 0 < r x) ∧ (s ⊆ ⋃ (x ∈ t), closed_ball x (r x))
∧ ∑' (x : ↥t), μ (closed_ball ↑x (r ↑x)) ≤ μ s + a :=
besicovitch.exists_closed_ball_covering_tsum_measure_le μ ha.ne' (λ x, Ioi 0) s
(λ x xs δ δpos, ⟨δ/2, by simp [half_pos δpos, half_lt_self δpos]⟩),
haveI : encodable t := t_count.to_encodable,
calc μ (f '' s)
≤ μ (⋃ (x : t), f '' (s ∩ closed_ball x (r x))) :
begin
rw bUnion_eq_Union at st,
apply measure_mono,
rw [← image_Union, ← inter_Union],
exact image_subset _ (subset_inter (subset.refl _) st)
end
... ≤ ∑' (x : t), μ (f '' (s ∩ closed_ball x (r x))) : measure_Union_le _
... ≤ ∑' (x : t), m * μ (closed_ball x (r x)) :
ennreal.tsum_le_tsum (λ x, I x (r x) (ts x.2) (rpos x x.2).le)
... ≤ m * (μ s + a) :
by { rw ennreal.tsum_mul_left, exact mul_le_mul_left' μt _ } },
-- taking the limit in `a`, one obtains the conclusion
have L : tendsto (λ a, (m : ℝ≥0∞) * (μ s + a)) (𝓝[>] 0) (𝓝 (m * (μ s + 0))),
{ apply tendsto.mono_left _ nhds_within_le_nhds,
apply ennreal.tendsto.const_mul (tendsto_const_nhds.add tendsto_id),
simp only [ennreal.coe_ne_top, ne.def, or_true, not_false_iff] },
rw add_zero at L,
exact ge_of_tendsto L J,
end
/-- Let `f` be a function which is sufficiently close (in the Lipschitz sense) to a given linear
map `A`. Then it expands the volume of any set by at least `m` for any `m < det A`. -/
lemma mul_le_add_haar_image_of_lt_det
(A : E →L[ℝ] E) {m : ℝ≥0} (hm : (m : ℝ≥0∞) < ennreal.of_real (|A.det|)) :
∀ᶠ δ in 𝓝[>] (0 : ℝ≥0), ∀ (s : set E) (f : E → E) (hf : approximates_linear_on f A s δ),
(m : ℝ≥0∞) * μ s ≤ μ (f '' s) :=
begin
apply nhds_within_le_nhds,
-- The assumption `hm` implies that `A` is invertible. If `f` is close enough to `A`, it is also
-- invertible. One can then pass to the inverses, and deduce the estimate from
-- `add_haar_image_le_mul_of_det_lt` applied to `f⁻¹` and `A⁻¹`.
-- exclude first the trivial case where `m = 0`.
rcases eq_or_lt_of_le (zero_le m) with rfl|mpos,
{ apply eventually_of_forall,
simp only [forall_const, zero_mul, implies_true_iff, zero_le, ennreal.coe_zero] },
have hA : A.det ≠ 0,
{ assume h, simpa only [h, ennreal.not_lt_zero, ennreal.of_real_zero, abs_zero] using hm },
-- let `B` be the continuous linear equiv version of `A`.
let B := A.to_continuous_linear_equiv_of_det_ne_zero hA,
-- the determinant of `B.symm` is bounded by `m⁻¹`
have I : ennreal.of_real (|(B.symm : E →L[ℝ] E).det|) < (m⁻¹ : ℝ≥0),
{ simp only [ennreal.of_real, abs_inv, real.to_nnreal_inv, continuous_linear_equiv.det_coe_symm,
continuous_linear_map.coe_to_continuous_linear_equiv_of_det_ne_zero, ennreal.coe_lt_coe]
at ⊢ hm,
exact nnreal.inv_lt_inv mpos.ne' hm },
-- therefore, we may apply `add_haar_image_le_mul_of_det_lt` to `B.symm` and `m⁻¹`.
obtain ⟨δ₀, δ₀pos, hδ₀⟩ : ∃ (δ : ℝ≥0), 0 < δ ∧ ∀ (t : set E) (g : E → E),
approximates_linear_on g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t,
{ have : ∀ᶠ (δ : ℝ≥0) in 𝓝[>] 0, ∀ (t : set E) (g : E → E),
approximates_linear_on g (B.symm : E →L[ℝ] E) t δ → μ (g '' t) ≤ ↑m⁻¹ * μ t :=
add_haar_image_le_mul_of_det_lt μ B.symm I,
rcases (this.and self_mem_nhds_within).exists with ⟨δ₀, h, h'⟩,
exact ⟨δ₀, h', h⟩, },
-- record smallness conditions for `δ` that will be needed to apply `hδ₀` below.
have L1 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0), subsingleton E ∨ δ < ‖(B.symm : E →L[ℝ] E)‖₊⁻¹,
{ by_cases (subsingleton E),
{ simp only [h, true_or, eventually_const] },
simp only [h, false_or],
apply Iio_mem_nhds,
simpa only [h, false_or, inv_pos] using B.subsingleton_or_nnnorm_symm_pos },
have L2 : ∀ᶠ δ in 𝓝 (0 : ℝ≥0),
‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ < δ₀,
{ have : tendsto (λ δ, ‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - δ)⁻¹ * δ)
(𝓝 0) (𝓝 (‖(B.symm : E →L[ℝ] E)‖₊ * (‖(B.symm : E →L[ℝ] E)‖₊⁻¹ - 0)⁻¹ * 0)),
{ rcases eq_or_ne (‖(B.symm : E →L[ℝ] E)‖₊) 0 with H|H,
{ simpa only [H, zero_mul] using tendsto_const_nhds },
refine tendsto.mul (tendsto_const_nhds.mul _) tendsto_id,
refine (tendsto.sub tendsto_const_nhds tendsto_id).inv₀ _,
simpa only [tsub_zero, inv_eq_zero, ne.def] using H },
simp only [mul_zero] at this,
exact (tendsto_order.1 this).2 δ₀ δ₀pos },
-- let `δ` be small enough, and `f` approximated by `B` up to `δ`.
filter_upwards [L1, L2],
assume δ h1δ h2δ s f hf,
have hf' : approximates_linear_on f (B : E →L[ℝ] E) s δ,
by { convert hf, exact A.coe_to_continuous_linear_equiv_of_det_ne_zero _ },
let F := hf'.to_local_equiv h1δ,
-- the condition to be checked can be reformulated in terms of the inverse maps
suffices H : μ ((F.symm) '' F.target) ≤ (m⁻¹ : ℝ≥0) * μ F.target,
{ change (m : ℝ≥0∞) * μ (F.source) ≤ μ (F.target),
rwa [← F.symm_image_target_eq_source, mul_comm, ← ennreal.le_div_iff_mul_le, div_eq_mul_inv,
mul_comm, ← ennreal.coe_inv (mpos.ne')],
{ apply or.inl,
simpa only [ennreal.coe_eq_zero, ne.def] using mpos.ne'},
{ simp only [ennreal.coe_ne_top, true_or, ne.def, not_false_iff] } },
-- as `f⁻¹` is well approximated by `B⁻¹`, the conclusion follows from `hδ₀`
-- and our choice of `δ`.
exact hδ₀ _ _ ((hf'.to_inv h1δ).mono_num h2δ.le),
end
/-- If a differentiable function `f` is approximated by a linear map `A` on a set `s`, up to `δ`,
then at almost every `x` in `s` one has `‖f' x - A‖ ≤ δ`. -/
lemma _root_.approximates_linear_on.norm_fderiv_sub_le
{A : E →L[ℝ] E} {δ : ℝ≥0}
(hf : approximates_linear_on f A s δ) (hs : measurable_set s)
(f' : E → E →L[ℝ] E) (hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) :
∀ᵐ x ∂(μ.restrict s), ‖f' x - A‖₊ ≤ δ :=
begin
/- The conclusion will hold at the Lebesgue density points of `s` (which have full measure).
At such a point `x`, for any `z` and any `ε > 0` one has for small `r`
that `{x} + r • closed_ball z ε` intersects `s`. At a point `y` in the intersection,
`f y - f x` is close both to `f' x (r z)` (by differentiability) and to `A (r z)`
(by linear approximation), so these two quantities are close, i.e., `(f' x - A) z` is small. -/
filter_upwards [besicovitch.ae_tendsto_measure_inter_div μ s, ae_restrict_mem hs],
-- start from a Lebesgue density point `x`, belonging to `s`.
assume x hx xs,
-- consider an arbitrary vector `z`.
apply continuous_linear_map.op_norm_le_bound _ δ.2 (λ z, _),
-- to show that `‖(f' x - A) z‖ ≤ δ ‖z‖`, it suffices to do it up to some error that vanishes
-- asymptotically in terms of `ε > 0`.
suffices H : ∀ ε, 0 < ε → ‖(f' x - A) z‖ ≤ (δ + ε) * (‖z‖ + ε) + ‖(f' x - A)‖ * ε,
{ have : tendsto (λ (ε : ℝ), ((δ : ℝ) + ε) * (‖z‖ + ε) + ‖(f' x - A)‖ * ε) (𝓝[>] 0)
(𝓝 ((δ + 0) * (‖z‖ + 0) + ‖(f' x - A)‖ * 0)) :=
tendsto.mono_left (continuous.tendsto (by continuity) 0) nhds_within_le_nhds,
simp only [add_zero, mul_zero] at this,
apply le_of_tendsto_of_tendsto tendsto_const_nhds this,
filter_upwards [self_mem_nhds_within],
exact H },
-- fix a positive `ε`.
assume ε εpos,
-- for small enough `r`, the rescaled ball `r • closed_ball z ε` intersects `s`, as `x` is a
-- density point
have B₁ : ∀ᶠ r in 𝓝[>] (0 : ℝ), (s ∩ ({x} + r • closed_ball z ε)).nonempty :=
eventually_nonempty_inter_smul_of_density_one μ s x hx
_ measurable_set_closed_ball (measure_closed_ball_pos μ z εpos).ne',
obtain ⟨ρ, ρpos, hρ⟩ :
∃ ρ > 0, ball x ρ ∩ s ⊆ {y : E | ‖f y - f x - (f' x) (y - x)‖ ≤ ε * ‖y - x‖} :=
mem_nhds_within_iff.1 (is_o.def (hf' x xs) εpos),
-- for small enough `r`, the rescaled ball `r • closed_ball z ε` is included in the set where
-- `f y - f x` is well approximated by `f' x (y - x)`.
have B₂ : ∀ᶠ r in 𝓝[>] (0 : ℝ), {x} + r • closed_ball z ε ⊆ ball x ρ := nhds_within_le_nhds
(eventually_singleton_add_smul_subset bounded_closed_ball (ball_mem_nhds x ρpos)),
-- fix a small positive `r` satisfying the above properties, as well as a corresponding `y`.
obtain ⟨r, ⟨y, ⟨ys, hy⟩⟩, rρ, rpos⟩ : ∃ (r : ℝ), (s ∩ ({x} + r • closed_ball z ε)).nonempty ∧
{x} + r • closed_ball z ε ⊆ ball x ρ ∧ 0 < r := (B₁.and (B₂.and self_mem_nhds_within)).exists,
-- write `y = x + r a` with `a ∈ closed_ball z ε`.
obtain ⟨a, az, ya⟩ : ∃ a, a ∈ closed_ball z ε ∧ y = x + r • a,
{ simp only [mem_smul_set, image_add_left, mem_preimage, singleton_add] at hy,
rcases hy with ⟨a, az, ha⟩,
exact ⟨a, az, by simp only [ha, add_neg_cancel_left]⟩ },
have norm_a : ‖a‖ ≤ ‖z‖ + ε := calc
‖a‖ = ‖z + (a - z)‖ : by simp only [add_sub_cancel'_right]
... ≤ ‖z‖ + ‖a - z‖ : norm_add_le _ _
... ≤ ‖z‖ + ε : add_le_add_left (mem_closed_ball_iff_norm.1 az) _,
-- use the approximation properties to control `(f' x - A) a`, and then `(f' x - A) z` as `z` is
-- close to `a`.
have I : r * ‖(f' x - A) a‖ ≤ r * (δ + ε) * (‖z‖ + ε) := calc
r * ‖(f' x - A) a‖ = ‖(f' x - A) (r • a)‖ :
by simp only [continuous_linear_map.map_smul, norm_smul, real.norm_eq_abs,
abs_of_nonneg rpos.le]
... = ‖(f y - f x - A (y - x)) -
(f y - f x - (f' x) (y - x))‖ :
begin
congr' 1,
simp only [ya, add_sub_cancel', sub_sub_sub_cancel_left, continuous_linear_map.coe_sub',
eq_self_iff_true, sub_left_inj, pi.sub_apply, continuous_linear_map.map_smul, smul_sub],
end
... ≤ ‖f y - f x - A (y - x)‖ +
‖f y - f x - (f' x) (y - x)‖ : norm_sub_le _ _
... ≤ δ * ‖y - x‖ + ε * ‖y - x‖ :
add_le_add (hf _ ys _ xs) (hρ ⟨rρ hy, ys⟩)
... = r * (δ + ε) * ‖a‖ :
by { simp only [ya, add_sub_cancel', norm_smul, real.norm_eq_abs, abs_of_nonneg rpos.le],
ring }
... ≤ r * (δ + ε) * (‖z‖ + ε) :
mul_le_mul_of_nonneg_left norm_a (mul_nonneg rpos.le (add_nonneg δ.2 εpos.le)),
show ‖(f' x - A) z‖ ≤ (δ + ε) * (‖z‖ + ε) + ‖(f' x - A)‖ * ε, from calc
‖(f' x - A) z‖ = ‖(f' x - A) a + (f' x - A) (z - a)‖ :
begin
congr' 1,
simp only [continuous_linear_map.coe_sub', map_sub, pi.sub_apply],
abel
end
... ≤ ‖(f' x - A) a‖ + ‖(f' x - A) (z - a)‖ : norm_add_le _ _
... ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ‖z - a‖ :
begin
apply add_le_add,
{ rw mul_assoc at I, exact (mul_le_mul_left rpos).1 I },
{ apply continuous_linear_map.le_op_norm }
end
... ≤ (δ + ε) * (‖z‖ + ε) + ‖f' x - A‖ * ε : add_le_add le_rfl
(mul_le_mul_of_nonneg_left (mem_closed_ball_iff_norm'.1 az) (norm_nonneg _)),
end
/-!
### Measure zero of the image, over non-measurable sets
If a set has measure `0`, then its image under a differentiable map has measure zero. This doesn't
require the set to be measurable. In the same way, if `f` is differentiable on a set `s` with
non-invertible derivative everywhere, then `f '' s` has measure `0`, again without measurability
assumptions.
-/
/-- A differentiable function maps sets of measure zero to sets of measure zero. -/
lemma add_haar_image_eq_zero_of_differentiable_on_of_add_haar_eq_zero
(hf : differentiable_on ℝ f s) (hs : μ s = 0) :
μ (f '' s) = 0 :=
begin
refine le_antisymm _ (zero_le _),
have : ∀ (A : E →L[ℝ] E), ∃ (δ : ℝ≥0), 0 < δ ∧ ∀ (t : set E)
(hf : approximates_linear_on f A t δ), μ (f '' t) ≤ (real.to_nnreal (|A.det|) + 1 : ℝ≥0) * μ t,
{ assume A,
let m : ℝ≥0 := real.to_nnreal ((|A.det|)) + 1,
have I : ennreal.of_real (|A.det|) < m,
by simp only [ennreal.of_real, m, lt_add_iff_pos_right, zero_lt_one, ennreal.coe_lt_coe],
rcases ((add_haar_image_le_mul_of_det_lt μ A I).and self_mem_nhds_within).exists
with ⟨δ, h, h'⟩,
exact ⟨δ, h', λ t ht, h t f ht⟩ },
choose δ hδ using this,
obtain ⟨t, A, t_disj, t_meas, t_cover, ht, -⟩ : ∃ (t : ℕ → set E) (A : ℕ → (E →L[ℝ] E)),
pairwise (disjoint on t) ∧ (∀ (n : ℕ), measurable_set (t n)) ∧ (s ⊆ ⋃ (n : ℕ), t n)
∧ (∀ (n : ℕ), approximates_linear_on f (A n) (s ∩ t n) (δ (A n)))
∧ (s.nonempty → ∀ n, ∃ y ∈ s, A n = fderiv_within ℝ f s y) :=
exists_partition_approximates_linear_on_of_has_fderiv_within_at f s
(fderiv_within ℝ f s) (λ x xs, (hf x xs).has_fderiv_within_at) δ (λ A, (hδ A).1.ne'),
calc μ (f '' s)
≤ μ (⋃ n, f '' (s ∩ t n)) :
begin
apply measure_mono,
rw [← image_Union, ← inter_Union],
exact image_subset f (subset_inter subset.rfl t_cover)
end
... ≤ ∑' n, μ (f '' (s ∩ t n)) : measure_Union_le _
... ≤ ∑' n, (real.to_nnreal (|(A n).det|) + 1 : ℝ≥0) * μ (s ∩ t n) :
begin
apply ennreal.tsum_le_tsum (λ n, _),
apply (hδ (A n)).2,
exact ht n,
end
... ≤ ∑' n, (real.to_nnreal (|(A n).det|) + 1 : ℝ≥0) * 0 :
begin
refine ennreal.tsum_le_tsum (λ n, mul_le_mul_left' _ _),
exact le_trans (measure_mono (inter_subset_left _ _)) (le_of_eq hs),
end
... = 0 : by simp only [tsum_zero, mul_zero]
end
/-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and
a set where the differential is not invertible, then the image of this set has zero measure.
Here, we give an auxiliary statement towards this result. -/
lemma add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x)
(R : ℝ) (hs : s ⊆ closed_ball 0 R) (ε : ℝ≥0) (εpos : 0 < ε)
(h'f' : ∀ x ∈ s, (f' x).det = 0) :
μ (f '' s) ≤ ε * μ (closed_ball 0 R) :=
begin
rcases eq_empty_or_nonempty s with rfl|h's, { simp only [measure_empty, zero_le, image_empty] },
have : ∀ (A : E →L[ℝ] E), ∃ (δ : ℝ≥0), 0 < δ ∧ ∀ (t : set E)
(hf : approximates_linear_on f A t δ), μ (f '' t) ≤ (real.to_nnreal (|A.det|) + ε : ℝ≥0) * μ t,
{ assume A,
let m : ℝ≥0 := real.to_nnreal (|A.det|) + ε,
have I : ennreal.of_real (|A.det|) < m,
by simp only [ennreal.of_real, m, lt_add_iff_pos_right, εpos, ennreal.coe_lt_coe],
rcases ((add_haar_image_le_mul_of_det_lt μ A I).and self_mem_nhds_within).exists
with ⟨δ, h, h'⟩,
exact ⟨δ, h', λ t ht, h t f ht⟩ },
choose δ hδ using this,
obtain ⟨t, A, t_disj, t_meas, t_cover, ht, Af'⟩ : ∃ (t : ℕ → set E) (A : ℕ → (E →L[ℝ] E)),
pairwise (disjoint on t) ∧ (∀ (n : ℕ), measurable_set (t n)) ∧ (s ⊆ ⋃ (n : ℕ), t n)
∧ (∀ (n : ℕ), approximates_linear_on f (A n) (s ∩ t n) (δ (A n)))
∧ (s.nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
exists_partition_approximates_linear_on_of_has_fderiv_within_at f s
f' hf' δ (λ A, (hδ A).1.ne'),
calc μ (f '' s)
≤ μ (⋃ n, f '' (s ∩ t n)) :
begin
apply measure_mono,
rw [← image_Union, ← inter_Union],
exact image_subset f (subset_inter subset.rfl t_cover)
end
... ≤ ∑' n, μ (f '' (s ∩ t n)) : measure_Union_le _
... ≤ ∑' n, (real.to_nnreal (|(A n).det|) + ε : ℝ≥0) * μ (s ∩ t n) :
begin
apply ennreal.tsum_le_tsum (λ n, _),
apply (hδ (A n)).2,
exact ht n,
end
... = ∑' n, ε * μ (s ∩ t n) :
begin
congr' with n,
rcases Af' h's n with ⟨y, ys, hy⟩,
simp only [hy, h'f' y ys, real.to_nnreal_zero, abs_zero, zero_add]
end
... ≤ ε * ∑' n, μ (closed_ball 0 R ∩ t n) :
begin
rw ennreal.tsum_mul_left,
refine mul_le_mul_left' (ennreal.tsum_le_tsum (λ n, measure_mono _)) _,
exact inter_subset_inter_left _ hs,
end
... = ε * μ (⋃ n, closed_ball 0 R ∩ t n) :
begin
rw measure_Union,
{ exact pairwise_disjoint.mono t_disj (λ n, inter_subset_right _ _) },
{ assume n,
exact measurable_set_closed_ball.inter (t_meas n) }
end
... ≤ ε * μ (closed_ball 0 R) :
begin
rw ← inter_Union,
exact mul_le_mul_left' (measure_mono (inter_subset_left _ _)) _,
end
end
/-- A version of Sard lemma in fixed dimension: given a differentiable function from `E` to `E` and
a set where the differential is not invertible, then the image of this set has zero measure. -/
lemma add_haar_image_eq_zero_of_det_fderiv_within_eq_zero
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x)
(h'f' : ∀ x ∈ s, (f' x).det = 0) :
μ (f '' s) = 0 :=
begin
suffices H : ∀ R, μ (f '' (s ∩ closed_ball 0 R)) = 0,
{ apply le_antisymm _ (zero_le _),
rw ← Union_inter_closed_ball_nat s 0,
calc μ (f '' ⋃ (n : ℕ), s ∩ closed_ball 0 n) ≤ ∑' (n : ℕ), μ (f '' (s ∩ closed_ball 0 n)) :
by { rw image_Union, exact measure_Union_le _ }
... ≤ 0 : by simp only [H, tsum_zero, nonpos_iff_eq_zero] },
assume R,
have A : ∀ (ε : ℝ≥0) (εpos : 0 < ε), μ (f '' (s ∩ closed_ball 0 R)) ≤ ε * μ (closed_ball 0 R) :=
λ ε εpos, add_haar_image_eq_zero_of_det_fderiv_within_eq_zero_aux μ
(λ x hx, (hf' x hx.1).mono (inter_subset_left _ _)) R (inter_subset_right _ _) ε εpos
(λ x hx, h'f' x hx.1),
have B : tendsto (λ (ε : ℝ≥0), (ε : ℝ≥0∞) * μ (closed_ball 0 R)) (𝓝[>] 0) (𝓝 0),
{ have : tendsto (λ (ε : ℝ≥0), (ε : ℝ≥0∞) * μ (closed_ball 0 R))
(𝓝 0) (𝓝 (((0 : ℝ≥0) : ℝ≥0∞) * μ (closed_ball 0 R))) :=
ennreal.tendsto.mul_const (ennreal.tendsto_coe.2 tendsto_id)
(or.inr ((measure_closed_ball_lt_top).ne)),
simp only [zero_mul, ennreal.coe_zero] at this,
exact tendsto.mono_left this nhds_within_le_nhds },
apply le_antisymm _ (zero_le _),
apply ge_of_tendsto B,
filter_upwards [self_mem_nhds_within],
exact A,
end
/-!
### Weak measurability statements
We show that the derivative of a function on a set is almost everywhere measurable, and that the
image `f '' s` is measurable if `f` is injective on `s`. The latter statement follows from the
Lusin-Souslin theorem.
-/
/-- The derivative of a function on a measurable set is almost everywhere measurable on this set
with respect to Lebesgue measure. Note that, in general, it is not genuinely measurable there,
as `f'` is not unique (but only on a set of measure `0`, as the argument shows). -/
lemma ae_measurable_fderiv_within (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) :
ae_measurable f' (μ.restrict s) :=
begin
/- It suffices to show that `f'` can be uniformly approximated by a measurable function.
Fix `ε > 0`. Thanks to `exists_partition_approximates_linear_on_of_has_fderiv_within_at`, one
can find a countable measurable partition of `s` into sets `s ∩ t n` on which `f` is well
approximated by linear maps `A n`. On almost all of `s ∩ t n`, it follows from
`approximates_linear_on.norm_fderiv_sub_le` that `f'` is uniformly approximated by `A n`, which
gives the conclusion. -/
-- fix a precision `ε`
refine ae_measurable_of_unif_approx (λ ε εpos, _),
let δ : ℝ≥0 := ⟨ε, le_of_lt εpos⟩,
have δpos : 0 < δ := εpos,
-- partition `s` into sets `s ∩ t n` on which `f` is approximated by linear maps `A n`.
obtain ⟨t, A, t_disj, t_meas, t_cover, ht, Af'⟩ : ∃ (t : ℕ → set E) (A : ℕ → (E →L[ℝ] E)),
pairwise (disjoint on t) ∧ (∀ (n : ℕ), measurable_set (t n)) ∧ (s ⊆ ⋃ (n : ℕ), t n)
∧ (∀ (n : ℕ), approximates_linear_on f (A n) (s ∩ t n) δ)
∧ (s.nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
exists_partition_approximates_linear_on_of_has_fderiv_within_at f s
f' hf' (λ A, δ) (λ A, δpos.ne'),
-- define a measurable function `g` which coincides with `A n` on `t n`.
obtain ⟨g, g_meas, hg⟩ : ∃ g : E → (E →L[ℝ] E), measurable g ∧
∀ (n : ℕ) (x : E), x ∈ t n → g x = A n :=
exists_measurable_piecewise_nat t t_meas t_disj (λ n x, A n) (λ n, measurable_const),
refine ⟨g, g_meas.ae_measurable, _⟩,
-- reduce to checking that `f'` and `g` are close on almost all of `s ∩ t n`, for all `n`.
suffices H : ∀ᵐ (x : E) ∂(sum (λ n, μ.restrict (s ∩ t n))), dist (g x) (f' x) ≤ ε,
{ have : μ.restrict s ≤ sum (λ n, μ.restrict (s ∩ t n)),
{ have : s = ⋃ n, s ∩ t n,
{ rw ← inter_Union,
exact subset.antisymm (subset_inter subset.rfl t_cover) (inter_subset_left _ _) },
conv_lhs { rw this },
exact restrict_Union_le },
exact ae_mono this H },
-- fix such an `n`.
refine ae_sum_iff.2 (λ n, _),
-- on almost all `s ∩ t n`, `f' x` is close to `A n` thanks to
-- `approximates_linear_on.norm_fderiv_sub_le`.
have E₁ : ∀ᵐ (x : E) ∂μ.restrict (s ∩ t n), ‖f' x - A n‖₊ ≤ δ :=
(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f'
(λ x hx, (hf' x hx.1).mono (inter_subset_left _ _)),
-- moreover, `g x` is equal to `A n` there.
have E₂ : ∀ᵐ (x : E) ∂μ.restrict (s ∩ t n), g x = A n,
{ suffices H : ∀ᵐ (x : E) ∂μ.restrict (t n), g x = A n,
from ae_mono (restrict_mono (inter_subset_right _ _) le_rfl) H,
filter_upwards [ae_restrict_mem (t_meas n)],
exact hg n },
-- putting these two properties together gives the conclusion.
filter_upwards [E₁, E₂] with x hx1 hx2,
rw ← nndist_eq_nnnorm at hx1,
rw [hx2, dist_comm],
exact hx1,
end
lemma ae_measurable_of_real_abs_det_fderiv_within (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) :
ae_measurable (λ x, ennreal.of_real (|(f' x).det|)) (μ.restrict s) :=
begin
apply ennreal.measurable_of_real.comp_ae_measurable,
refine continuous_abs.measurable.comp_ae_measurable _,
refine continuous_linear_map.continuous_det.measurable.comp_ae_measurable _,
exact ae_measurable_fderiv_within μ hs hf'
end
lemma ae_measurable_to_nnreal_abs_det_fderiv_within (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) :
ae_measurable (λ x, |(f' x).det|.to_nnreal) (μ.restrict s) :=
begin
apply measurable_real_to_nnreal.comp_ae_measurable,
refine continuous_abs.measurable.comp_ae_measurable _,
refine continuous_linear_map.continuous_det.measurable.comp_ae_measurable _,
exact ae_measurable_fderiv_within μ hs hf'
end
/-- If a function is differentiable and injective on a measurable set,
then the image is measurable.-/
lemma measurable_image_of_fderiv_within (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) :
measurable_set (f '' s) :=
begin
have : differentiable_on ℝ f s := λ x hx, (hf' x hx).differentiable_within_at,
exact hs.image_of_continuous_on_inj_on (differentiable_on.continuous_on this) hf,
end
/-- If a function is differentiable and injective on a measurable set `s`, then its restriction
to `s` is a measurable embedding. -/
lemma measurable_embedding_of_fderiv_within (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) :
measurable_embedding (s.restrict f) :=
begin
have : differentiable_on ℝ f s := λ x hx, (hf' x hx).differentiable_within_at,
exact this.continuous_on.measurable_embedding hs hf
end
/-!
### Proving the estimate for the measure of the image
We show the formula `∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ = μ (f '' s)`,
in `lintegral_abs_det_fderiv_eq_add_haar_image`. For this, we show both inequalities in both
directions, first up to controlled errors and then letting these errors tend to `0`.
-/
lemma add_haar_image_le_lintegral_abs_det_fderiv_aux1 (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) {ε : ℝ≥0} (εpos : 0 < ε) :
μ (f '' s) ≤ ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ + 2 * ε * μ s :=
begin
/- To bound `μ (f '' s)`, we cover `s` by sets where `f` is well-approximated by linear maps
`A n` (and where `f'` is almost everywhere close to `A n`), and then use that `f` expands the
measure of such a set by at most `(A n).det + ε`. -/
have : ∀ (A : E →L[ℝ] E), ∃ (δ : ℝ≥0), 0 < δ ∧
(∀ (B : E →L[ℝ] E), ‖B - A‖ ≤ δ → |B.det - A.det| ≤ ε) ∧
∀ (t : set E) (g : E → E) (hf : approximates_linear_on g A t δ),
μ (g '' t) ≤ (ennreal.of_real (|A.det|) + ε) * μ t,
{ assume A,
let m : ℝ≥0 := real.to_nnreal (|A.det|) + ε,
have I : ennreal.of_real (|A.det|) < m,
by simp only [ennreal.of_real, m, lt_add_iff_pos_right, εpos, ennreal.coe_lt_coe],
rcases ((add_haar_image_le_mul_of_det_lt μ A I).and self_mem_nhds_within).exists
with ⟨δ, h, δpos⟩,
obtain ⟨δ', δ'pos, hδ'⟩ :
∃ (δ' : ℝ) (H : 0 < δ'), ∀ B, dist B A < δ' → dist B.det A.det < ↑ε :=
continuous_at_iff.1 continuous_linear_map.continuous_det.continuous_at ε εpos,
let δ'' : ℝ≥0 := ⟨δ' / 2, (half_pos δ'pos).le⟩,
refine ⟨min δ δ'', lt_min δpos (half_pos δ'pos), _, _⟩,
{ assume B hB,
rw ← real.dist_eq,
apply (hδ' B _).le,
rw dist_eq_norm,
calc ‖B - A‖ ≤ (min δ δ'' : ℝ≥0) : hB
... ≤ δ'' : by simp only [le_refl, nnreal.coe_min, min_le_iff, or_true]
... < δ' : half_lt_self δ'pos },
{ assume t g htg,
exact h t g (htg.mono_num (min_le_left _ _)) } },
choose δ hδ using this,
obtain ⟨t, A, t_disj, t_meas, t_cover, ht, -⟩ : ∃ (t : ℕ → set E) (A : ℕ → (E →L[ℝ] E)),
pairwise (disjoint on t) ∧ (∀ (n : ℕ), measurable_set (t n)) ∧ (s ⊆ ⋃ (n : ℕ), t n)
∧ (∀ (n : ℕ), approximates_linear_on f (A n) (s ∩ t n) (δ (A n)))
∧ (s.nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
exists_partition_approximates_linear_on_of_has_fderiv_within_at f s
f' hf' δ (λ A, (hδ A).1.ne'),
calc μ (f '' s)
≤ μ (⋃ n, f '' (s ∩ t n)) :
begin
apply measure_mono,
rw [← image_Union, ← inter_Union],
exact image_subset f (subset_inter subset.rfl t_cover)
end
... ≤ ∑' n, μ (f '' (s ∩ t n)) : measure_Union_le _
... ≤ ∑' n, (ennreal.of_real (|(A n).det|) + ε) * μ (s ∩ t n) :
begin
apply ennreal.tsum_le_tsum (λ n, _),
apply (hδ (A n)).2.2,
exact ht n,
end
... = ∑' n, ∫⁻ x in s ∩ t n, ennreal.of_real (|(A n).det|) + ε ∂μ :
by simp only [lintegral_const, measurable_set.univ, measure.restrict_apply, univ_inter]
... ≤ ∑' n, ∫⁻ x in s ∩ t n, ennreal.of_real (|(f' x).det|) + 2 * ε ∂μ :
begin
apply ennreal.tsum_le_tsum (λ n, _),
apply lintegral_mono_ae,
filter_upwards [(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f'
(λ x hx, (hf' x hx.1).mono (inter_subset_left _ _))],
assume x hx,
have I : |(A n).det| ≤ |(f' x).det| + ε := calc
|(A n).det| = |(f' x).det - ((f' x).det - (A n).det)| : by { congr' 1, abel }
... ≤ |(f' x).det| + |(f' x).det - (A n).det| : abs_sub _ _
... ≤ |(f' x).det| + ε : add_le_add le_rfl ((hδ (A n)).2.1 _ hx),
calc ennreal.of_real (|(A n).det|) + ε
≤ ennreal.of_real (|(f' x).det| + ε) + ε :
add_le_add (ennreal.of_real_le_of_real I) le_rfl
... = ennreal.of_real (|(f' x).det|) + 2 * ε :
by simp only [ennreal.of_real_add, abs_nonneg, two_mul, add_assoc, nnreal.zero_le_coe,
ennreal.of_real_coe_nnreal],
end
... = ∫⁻ x in ⋃ n, s ∩ t n, ennreal.of_real (|(f' x).det|) + 2 * ε ∂μ :
begin
have M : ∀ (n : ℕ), measurable_set (s ∩ t n) := λ n, hs.inter (t_meas n),
rw lintegral_Union M,
exact pairwise_disjoint.mono t_disj (λ n, inter_subset_right _ _),
end
... = ∫⁻ x in s, ennreal.of_real (|(f' x).det|) + 2 * ε ∂μ :
begin
have : s = ⋃ n, s ∩ t n,
{ rw ← inter_Union,
exact subset.antisymm (subset_inter subset.rfl t_cover) (inter_subset_left _ _) },
rw ← this,
end
... = ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ + 2 * ε * μ s :
by simp only [lintegral_add_right' _ ae_measurable_const, set_lintegral_const]
end
lemma add_haar_image_le_lintegral_abs_det_fderiv_aux2 (hs : measurable_set s) (h's : μ s ≠ ∞)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) :
μ (f '' s) ≤ ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ :=
begin
/- We just need to let the error tend to `0` in the previous lemma. -/
have : tendsto (λ (ε : ℝ≥0), ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ + 2 * ε * μ s)
(𝓝[>] 0) (𝓝 (∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ + 2 * (0 : ℝ≥0) * μ s)),
{ apply tendsto.mono_left _ nhds_within_le_nhds,
refine tendsto_const_nhds.add _,
refine ennreal.tendsto.mul_const _ (or.inr h's),
exact ennreal.tendsto.const_mul (ennreal.tendsto_coe.2 tendsto_id)
(or.inr ennreal.coe_ne_top) },
simp only [add_zero, zero_mul, mul_zero, ennreal.coe_zero] at this,
apply ge_of_tendsto this,
filter_upwards [self_mem_nhds_within],
rintros ε (εpos : 0 < ε),
exact add_haar_image_le_lintegral_abs_det_fderiv_aux1 μ hs hf' εpos,
end
lemma add_haar_image_le_lintegral_abs_det_fderiv (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) :
μ (f '' s) ≤ ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ :=
begin
/- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using
`spanning_sets μ`, and apply the previous result to each of these parts. -/
let u := λ n, disjointed (spanning_sets μ) n,
have u_meas : ∀ n, measurable_set (u n),
{ assume n,
apply measurable_set.disjointed (λ i, _),
exact measurable_spanning_sets μ i },
have A : s = ⋃ n, s ∩ u n,
by rw [← inter_Union, Union_disjointed, Union_spanning_sets, inter_univ],
calc μ (f '' s) ≤ ∑' n, μ (f '' (s ∩ u n)) :
begin
conv_lhs { rw [A, image_Union] },
exact measure_Union_le _,
end
... ≤ ∑' n, ∫⁻ x in s ∩ u n, ennreal.of_real (|(f' x).det|) ∂μ :
begin
apply ennreal.tsum_le_tsum (λ n, _),
apply add_haar_image_le_lintegral_abs_det_fderiv_aux2 μ (hs.inter (u_meas n)) _
(λ x hx, (hf' x hx.1).mono (inter_subset_left _ _)),
have : μ (u n) < ∞ :=
lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanning_sets_lt_top μ n),
exact ne_of_lt (lt_of_le_of_lt (measure_mono (inter_subset_right _ _)) this),
end
... = ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ :
begin
conv_rhs { rw A },
rw lintegral_Union,
{ assume n, exact hs.inter (u_meas n) },
{ exact pairwise_disjoint.mono (disjoint_disjointed _) (λ n, inter_subset_right _ _) }
end
end
lemma lintegral_abs_det_fderiv_le_add_haar_image_aux1 (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s)
{ε : ℝ≥0} (εpos : 0 < ε) :
∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ ≤ μ (f '' s) + 2 * ε * μ s :=
begin
/- To bound `∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ`, we cover `s` by sets where `f` is
well-approximated by linear maps `A n` (and where `f'` is almost everywhere close to `A n`),
and then use that `f` expands the measure of such a set by at least `(A n).det - ε`. -/
have : ∀ (A : E →L[ℝ] E), ∃ (δ : ℝ≥0), 0 < δ ∧
(∀ (B : E →L[ℝ] E), ‖B - A‖ ≤ δ → |B.det - A.det| ≤ ε) ∧
∀ (t : set E) (g : E → E) (hf : approximates_linear_on g A t δ),
ennreal.of_real (|A.det|) * μ t ≤ μ (g '' t) + ε * μ t,
{ assume A,
obtain ⟨δ', δ'pos, hδ'⟩ :
∃ (δ' : ℝ) (H : 0 < δ'), ∀ B, dist B A < δ' → dist B.det A.det < ↑ε :=
continuous_at_iff.1 continuous_linear_map.continuous_det.continuous_at ε εpos,
let δ'' : ℝ≥0 := ⟨δ' / 2, (half_pos δ'pos).le⟩,
have I'' : ∀ (B : E →L[ℝ] E), ‖B - A‖ ≤ ↑δ'' → |B.det - A.det| ≤ ↑ε,
{ assume B hB,
rw ← real.dist_eq,
apply (hδ' B _).le,
rw dist_eq_norm,
exact hB.trans_lt (half_lt_self δ'pos) },
rcases eq_or_ne A.det 0 with hA|hA,
{ refine ⟨δ'', half_pos δ'pos, I'', _⟩,
simp only [hA, forall_const, zero_mul, ennreal.of_real_zero, implies_true_iff, zero_le,
abs_zero] },
let m : ℝ≥0 := real.to_nnreal (|A.det|) - ε,
have I : (m : ℝ≥0∞) < ennreal.of_real (|A.det|),
{ simp only [ennreal.of_real, with_top.coe_sub],
apply ennreal.sub_lt_self ennreal.coe_ne_top,
{ simpa only [abs_nonpos_iff, real.to_nnreal_eq_zero, ennreal.coe_eq_zero, ne.def] using hA },
{ simp only [εpos.ne', ennreal.coe_eq_zero, ne.def, not_false_iff] } },
rcases ((mul_le_add_haar_image_of_lt_det μ A I).and self_mem_nhds_within).exists
with ⟨δ, h, δpos⟩,
refine ⟨min δ δ'', lt_min δpos (half_pos δ'pos), _, _⟩,
{ assume B hB,
apply I'' _ (hB.trans _),
simp only [le_refl, nnreal.coe_min, min_le_iff, or_true] },
{ assume t g htg,
rcases eq_or_ne (μ t) ∞ with ht|ht,
{ simp only [ht, εpos.ne', with_top.mul_top, ennreal.coe_eq_zero, le_top, ne.def,
not_false_iff, _root_.add_top] },
have := h t g (htg.mono_num (min_le_left _ _)),
rwa [with_top.coe_sub, ennreal.sub_mul, tsub_le_iff_right] at this,
simp only [ht, implies_true_iff, ne.def, not_false_iff] } },
choose δ hδ using this,
obtain ⟨t, A, t_disj, t_meas, t_cover, ht, -⟩ : ∃ (t : ℕ → set E) (A : ℕ → (E →L[ℝ] E)),
pairwise (disjoint on t) ∧ (∀ (n : ℕ), measurable_set (t n)) ∧ (s ⊆ ⋃ (n : ℕ), t n)
∧ (∀ (n : ℕ), approximates_linear_on f (A n) (s ∩ t n) (δ (A n)))
∧ (s.nonempty → ∀ n, ∃ y ∈ s, A n = f' y) :=
exists_partition_approximates_linear_on_of_has_fderiv_within_at f s
f' hf' δ (λ A, (hδ A).1.ne'),
have s_eq : s = ⋃ n, s ∩ t n,
{ rw ← inter_Union,
exact subset.antisymm (subset_inter subset.rfl t_cover) (inter_subset_left _ _) },
calc ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ
= ∑' n, ∫⁻ x in s ∩ t n, ennreal.of_real (|(f' x).det|) ∂μ :
begin
conv_lhs { rw s_eq },
rw lintegral_Union,
{ exact λ n, hs.inter (t_meas n) },
{ exact pairwise_disjoint.mono t_disj (λ n, inter_subset_right _ _) }
end
... ≤ ∑' n, ∫⁻ x in s ∩ t n, ennreal.of_real (|(A n).det|) + ε ∂μ :
begin
apply ennreal.tsum_le_tsum (λ n, _),
apply lintegral_mono_ae,
filter_upwards [(ht n).norm_fderiv_sub_le μ (hs.inter (t_meas n)) f'
(λ x hx, (hf' x hx.1).mono (inter_subset_left _ _))],
assume x hx,
have I : |(f' x).det| ≤ |(A n).det| + ε := calc
|(f' x).det| = |(A n).det + ((f' x).det - (A n).det)| : by { congr' 1, abel }
... ≤ |(A n).det| + |(f' x).det - (A n).det| : abs_add _ _
... ≤ |(A n).det| + ε : add_le_add le_rfl ((hδ (A n)).2.1 _ hx),
calc ennreal.of_real (|(f' x).det|) ≤ ennreal.of_real (|(A n).det| + ε) :
ennreal.of_real_le_of_real I
... = ennreal.of_real (|(A n).det|) + ε :
by simp only [ennreal.of_real_add, abs_nonneg, nnreal.zero_le_coe,
ennreal.of_real_coe_nnreal]
end
... = ∑' n, (ennreal.of_real (|(A n).det|) * μ (s ∩ t n) + ε * μ (s ∩ t n)) :
by simp only [set_lintegral_const, lintegral_add_right _ measurable_const]
... ≤ ∑' n, ((μ (f '' (s ∩ t n)) + ε * μ (s ∩ t n)) + ε * μ (s ∩ t n)) :
begin
refine ennreal.tsum_le_tsum (λ n, add_le_add_right _ _),
exact (hδ (A n)).2.2 _ _ (ht n),
end
... = μ (f '' s) + 2 * ε * μ s :
begin
conv_rhs { rw s_eq },
rw [image_Union, measure_Union], rotate,
{ assume i j hij,
apply (disjoint.image _ hf (inter_subset_left _ _) (inter_subset_left _ _)),
exact disjoint.mono (inter_subset_right _ _) (inter_subset_right _ _) (t_disj hij) },
{ assume i,
exact measurable_image_of_fderiv_within (hs.inter (t_meas i)) (λ x hx,
(hf' x hx.1).mono (inter_subset_left _ _)) (hf.mono (inter_subset_left _ _)) },
rw measure_Union, rotate,
{ exact pairwise_disjoint.mono t_disj (λ i, inter_subset_right _ _) },
{ exact λ i, hs.inter (t_meas i) },
rw [← ennreal.tsum_mul_left, ← ennreal.tsum_add],
congr' 1,
ext1 i,
rw [mul_assoc, two_mul, add_assoc],
end
end
lemma lintegral_abs_det_fderiv_le_add_haar_image_aux2 (hs : measurable_set s) (h's : μ s ≠ ∞)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) :
∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ ≤ μ (f '' s) :=
begin
/- We just need to let the error tend to `0` in the previous lemma. -/
have : tendsto (λ (ε : ℝ≥0), μ (f '' s) + 2 * ε * μ s)
(𝓝[>] 0) (𝓝 (μ (f '' s) + 2 * (0 : ℝ≥0) * μ s)),
{ apply tendsto.mono_left _ nhds_within_le_nhds,
refine tendsto_const_nhds.add _,
refine ennreal.tendsto.mul_const _ (or.inr h's),
exact ennreal.tendsto.const_mul (ennreal.tendsto_coe.2 tendsto_id)
(or.inr ennreal.coe_ne_top) },
simp only [add_zero, zero_mul, mul_zero, ennreal.coe_zero] at this,
apply ge_of_tendsto this,
filter_upwards [self_mem_nhds_within],
rintros ε (εpos : 0 < ε),
exact lintegral_abs_det_fderiv_le_add_haar_image_aux1 μ hs hf' hf εpos
end
lemma lintegral_abs_det_fderiv_le_add_haar_image (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) :
∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ ≤ μ (f '' s) :=
begin
/- We already know the result for finite-measure sets. We cover `s` by finite-measure sets using
`spanning_sets μ`, and apply the previous result to each of these parts. -/
let u := λ n, disjointed (spanning_sets μ) n,
have u_meas : ∀ n, measurable_set (u n),
{ assume n,
apply measurable_set.disjointed (λ i, _),
exact measurable_spanning_sets μ i },
have A : s = ⋃ n, s ∩ u n,
by rw [← inter_Union, Union_disjointed, Union_spanning_sets, inter_univ],
calc ∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ
= ∑' n, ∫⁻ x in s ∩ u n, ennreal.of_real (|(f' x).det|) ∂μ :
begin
conv_lhs { rw A },
rw lintegral_Union,
{ assume n, exact hs.inter (u_meas n) },
{ exact pairwise_disjoint.mono (disjoint_disjointed _) (λ n, inter_subset_right _ _) }
end
... ≤ ∑' n, μ (f '' (s ∩ u n)) :
begin
apply ennreal.tsum_le_tsum (λ n, _),
apply lintegral_abs_det_fderiv_le_add_haar_image_aux2 μ (hs.inter (u_meas n)) _
(λ x hx, (hf' x hx.1).mono (inter_subset_left _ _)) (hf.mono (inter_subset_left _ _)),
have : μ (u n) < ∞ :=
lt_of_le_of_lt (measure_mono (disjointed_subset _ _)) (measure_spanning_sets_lt_top μ n),
exact ne_of_lt (lt_of_le_of_lt (measure_mono (inter_subset_right _ _)) this),
end
... = μ (f '' s) :
begin
conv_rhs { rw [A, image_Union] },
rw measure_Union,
{ assume i j hij,
apply disjoint.image _ hf (inter_subset_left _ _) (inter_subset_left _ _),
exact disjoint.mono (inter_subset_right _ _) (inter_subset_right _ _)
(disjoint_disjointed _ hij) },
{ assume i,
exact measurable_image_of_fderiv_within (hs.inter (u_meas i)) (λ x hx,
(hf' x hx.1).mono (inter_subset_left _ _)) (hf.mono (inter_subset_left _ _)) },
end
end
/-- Change of variable formula for differentiable functions, set version: if a function `f` is
injective and differentiable on a measurable set `s`, then the measure of `f '' s` is given by the
integral of `|(f' x).det|` on `s`.
Note that the measurability of `f '' s` is given by `measurable_image_of_fderiv_within`. -/
theorem lintegral_abs_det_fderiv_eq_add_haar_image (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) :
∫⁻ x in s, ennreal.of_real (|(f' x).det|) ∂μ = μ (f '' s) :=
le_antisymm (lintegral_abs_det_fderiv_le_add_haar_image μ hs hf' hf)
(add_haar_image_le_lintegral_abs_det_fderiv μ hs hf')
/-- Change of variable formula for differentiable functions, set version: if a function `f` is
injective and differentiable on a measurable set `s`, then the pushforward of the measure with
density `|(f' x).det|` on `s` is the Lebesgue measure on the image set. This version requires
that `f` is measurable, as otherwise `measure.map f` is zero per our definitions.
For a version without measurability assumption but dealing with the restricted
function `s.restrict f`, see `restrict_map_with_density_abs_det_fderiv_eq_add_haar`.
-/
theorem map_with_density_abs_det_fderiv_eq_add_haar (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s)
(h'f : measurable f) :
measure.map f ((μ.restrict s).with_density (λ x, ennreal.of_real (|(f' x).det|)))
= μ.restrict (f '' s) :=
begin
apply measure.ext (λ t ht, _),
rw [map_apply h'f ht, with_density_apply _ (h'f ht), measure.restrict_apply ht,
restrict_restrict (h'f ht),
lintegral_abs_det_fderiv_eq_add_haar_image μ ((h'f ht).inter hs)
(λ x hx, (hf' x hx.2).mono (inter_subset_right _ _)) (hf.mono (inter_subset_right _ _)),
image_preimage_inter]
end
/-- Change of variable formula for differentiable functions, set version: if a function `f` is
injective and differentiable on a measurable set `s`, then the pushforward of the measure with
density `|(f' x).det|` on `s` is the Lebesgue measure on the image set. This version is expressed
in terms of the restricted function `s.restrict f`.
For a version for the original function, but with a measurability assumption,
see `map_with_density_abs_det_fderiv_eq_add_haar`.
-/
theorem restrict_map_with_density_abs_det_fderiv_eq_add_haar (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) :
measure.map (s.restrict f)
(comap coe (μ.with_density (λ x, ennreal.of_real (|(f' x).det|)))) = μ.restrict (f '' s) :=
begin
obtain ⟨u, u_meas, uf⟩ : ∃ u, measurable u ∧ eq_on u f s,
{ classical,
refine ⟨piecewise s f 0, _, piecewise_eq_on _ _ _⟩,
refine continuous_on.measurable_piecewise _ continuous_zero.continuous_on hs,
have : differentiable_on ℝ f s := λ x hx, (hf' x hx).differentiable_within_at,
exact this.continuous_on },
have u' : ∀ x ∈ s, has_fderiv_within_at u (f' x) s x :=
λ x hx, (hf' x hx).congr (λ y hy, uf hy) (uf hx),
set F : s → E := u ∘ coe with hF,
have A : measure.map F
(comap coe (μ.with_density (λ x, ennreal.of_real (|(f' x).det|)))) = μ.restrict (u '' s),
{ rw [hF, ← measure.map_map u_meas measurable_subtype_coe, map_comap_subtype_coe hs,
restrict_with_density hs],
exact map_with_density_abs_det_fderiv_eq_add_haar μ hs u' (hf.congr uf.symm) u_meas },
rw uf.image_eq at A,
have : F = s.restrict f,
{ ext x,
exact uf x.2 },
rwa this at A,
end
/-! ### Change of variable formulas in integrals -/
/- Change of variable formula for differentiable functions: if a function `f` is
injective and differentiable on a measurable set `s`, then the Lebesgue integral of a function
`g : E → ℝ≥0∞` on `f '' s` coincides with the integral of `|(f' x).det| * g ∘ f` on `s`.
Note that the measurability of `f '' s` is given by `measurable_image_of_fderiv_within`. -/
theorem lintegral_image_eq_lintegral_abs_det_fderiv_mul (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) (g : E → ℝ≥0∞) :
∫⁻ x in f '' s, g x ∂μ = ∫⁻ x in s, ennreal.of_real (|(f' x).det|) * g (f x) ∂μ :=
begin
rw [← restrict_map_with_density_abs_det_fderiv_eq_add_haar μ hs hf' hf,
(measurable_embedding_of_fderiv_within hs hf' hf).lintegral_map],
have : ∀ (x : s), g (s.restrict f x) = (g ∘ f) x := λ x, rfl,
simp only [this],
rw [← (measurable_embedding.subtype_coe hs).lintegral_map, map_comap_subtype_coe hs,
set_lintegral_with_density_eq_set_lintegral_mul_non_measurable₀ _ _ _ hs],
{ refl },
{ simp only [eventually_true, ennreal.of_real_lt_top] },
{ exact ae_measurable_of_real_abs_det_fderiv_within μ hs hf' }
end
/-- Integrability in the change of variable formula for differentiable functions: if a
function `f` is injective and differentiable on a measurable set `s`, then a function
`g : E → F` is integrable on `f '' s` if and only if `|(f' x).det| • g ∘ f` is
integrable on `s`. -/
theorem integrable_on_image_iff_integrable_on_abs_det_fderiv_smul (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) (g : E → F) :
integrable_on g (f '' s) μ ↔ integrable_on (λ x, |(f' x).det| • g (f x)) s μ :=
begin
rw [integrable_on, ← restrict_map_with_density_abs_det_fderiv_eq_add_haar μ hs hf' hf,
(measurable_embedding_of_fderiv_within hs hf' hf).integrable_map_iff],
change (integrable ((g ∘ f) ∘ (coe : s → E)) _) ↔ _,
rw [← (measurable_embedding.subtype_coe hs).integrable_map_iff, map_comap_subtype_coe hs],
simp only [ennreal.of_real],
rw [restrict_with_density hs, integrable_with_density_iff_integrable_coe_smul₀, integrable_on],
{ congr' 2 with x,
rw real.coe_to_nnreal,
exact abs_nonneg _ },
{ exact ae_measurable_to_nnreal_abs_det_fderiv_within μ hs hf' }
end
/-- Change of variable formula for differentiable functions: if a function `f` is
injective and differentiable on a measurable set `s`, then the Bochner integral of a function
`g : E → F` on `f '' s` coincides with the integral of `|(f' x).det| • g ∘ f` on `s`. -/
theorem integral_image_eq_integral_abs_det_fderiv_smul [complete_space F] (hs : measurable_set s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hf : inj_on f s) (g : E → F) :
∫ x in f '' s, g x ∂μ = ∫ x in s, |(f' x).det| • g (f x) ∂μ :=
begin
rw [← restrict_map_with_density_abs_det_fderiv_eq_add_haar μ hs hf' hf,
(measurable_embedding_of_fderiv_within hs hf' hf).integral_map],
have : ∀ (x : s), g (s.restrict f x) = (g ∘ f) x := λ x, rfl,
simp only [this, ennreal.of_real],
rw [← (measurable_embedding.subtype_coe hs).integral_map, map_comap_subtype_coe hs,
set_integral_with_density_eq_set_integral_smul₀
(ae_measurable_to_nnreal_abs_det_fderiv_within μ hs hf') _ hs],
congr' with x,
conv_rhs { rw ← real.coe_to_nnreal _ (abs_nonneg (f' x).det) },
refl
end
/-- Change of variable formula for differentiable functions (one-variable version): if a function
`f` is injective and differentiable on a measurable set `s ⊆ ℝ`, then the Bochner integral of a
function `g : ℝ → F` on `f '' s` coincides with the integral of `|(f' x).det| • g ∘ f` on `s`. -/
theorem integral_image_eq_integral_abs_deriv_smul {s : set ℝ} {f : ℝ → ℝ} {f' : ℝ → ℝ}
[complete_space F] (hs : measurable_set s) (hf' : ∀ x ∈ s, has_deriv_within_at f (f' x) s x)
(hf : inj_on f s) (g : ℝ → F) :
∫ x in f '' s, g x = ∫ x in s, |(f' x)| • g (f x) :=
begin
convert integral_image_eq_integral_abs_det_fderiv_smul volume hs
(λ x hx, (hf' x hx).has_fderiv_within_at) hf g,
ext1 x,
rw (by { ext, simp } : (1 : ℝ →L[ℝ] ℝ).smul_right (f' x) = (f' x) • (1 : ℝ →L[ℝ] ℝ)),
rw [continuous_linear_map.det, continuous_linear_map.coe_smul],
have : ((1 : ℝ →L[ℝ] ℝ) : ℝ →ₗ[ℝ] ℝ) = (1 : ℝ →ₗ[ℝ] ℝ) := by refl,
rw [this, linear_map.det_smul, finite_dimensional.finrank_self],
suffices : (1 : ℝ →ₗ[ℝ] ℝ).det = 1, { rw this, simp },
exact linear_map.det_id,
end
theorem integral_target_eq_integral_abs_det_fderiv_smul [complete_space F]
{f : local_homeomorph E E} (hf' : ∀ x ∈ f.source, has_fderiv_at f (f' x) x) (g : E → F) :
∫ x in f.target, g x ∂μ = ∫ x in f.source, |(f' x).det| • g (f x) ∂μ :=
begin
have : f '' f.source = f.target := local_equiv.image_source_eq_target f.to_local_equiv,
rw ← this,
apply integral_image_eq_integral_abs_det_fderiv_smul μ f.open_source.measurable_set _ f.inj_on,
assume x hx,
exact (hf' x hx).has_fderiv_within_at
end
end measure_theory
|
629632ecfeb072bda83be7a3f5fee1aa96c2d4a0 | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/leak1.lean | 32e929928b30105a7ab49c391eaf1d4f8602aa08 | [
"Apache-2.0"
] | permissive | codyroux/lean0.1 | 1ce92751d664aacff0529e139083304a7bbc8a71 | 0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef | refs/heads/master | 1,610,830,535,062 | 1,402,150,480,000 | 1,402,150,480,000 | 19,588,851 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11 | lean | print 2 * a |
334359fd28990a8b8bd63854d486f1e96123bc60 | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /library/data/option.lean | 49a6017801158628d74030e9a70db031cc71aef7 | [
"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,368 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: data.option
Author: Leonardo de Moura
-/
import logic.eq
open eq.ops decidable
namespace option
definition is_none {A : Type} (o : option A) : Prop :=
option.rec true (λ a, false) o
theorem is_none_none {A : Type} : is_none (@none A) :=
trivial
theorem not_is_none_some {A : Type} (a : A) : ¬ is_none (some a) :=
not_false
theorem none_ne_some {A : Type} (a : A) : none ≠ some a :=
assume H, option.no_confusion H
theorem some.inj {A : Type} {a₁ a₂ : A} (H : some a₁ = some a₂) : a₁ = a₂ :=
option.no_confusion H (λe, e)
protected definition is_inhabited [instance] (A : Type) : inhabited (option A) :=
inhabited.mk none
protected definition has_decidable_eq [instance] {A : Type} [H : decidable_eq A] : decidable_eq (option A) :=
take o₁ o₂ : option A,
option.rec_on o₁
(option.rec_on o₂ (inl rfl) (take a₂, (inr (none_ne_some a₂))))
(take a₁ : A, option.rec_on o₂
(inr (ne.symm (none_ne_some a₁)))
(take a₂ : A, decidable.rec_on (H a₁ a₂)
(assume Heq : a₁ = a₂, inl (Heq ▸ rfl))
(assume Hne : a₁ ≠ a₂, inr (assume Hn : some a₁ = some a₂, absurd (some.inj Hn) Hne))))
end option
|
3ebdc3192a511195adb10c39e0095ef36547213e | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/mv_polynomial/basic.lean | 6d16a29fbd35417feec19850f2fcb139f1d0359c | [
"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 | 41,899 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import data.polynomial.eval
import data.finsupp.antidiagonal
import algebra.algebra.tower
/-!
# Multivariate polynomials
This file defines polynomial rings over a base ring (or even semiring),
with variables from a general type `σ` (which could be infinite).
## Important definitions
Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary
type. This file creates the type `mv_polynomial σ R`, which mathematicians
might denote $R[X_i : i \in σ]$. It is the type of multivariate
(a.k.a. multivariable) polynomials, with variables
corresponding to the terms in `σ`, and coefficients in `R`.
### Notation
In the definitions below, we use the following notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[comm_semiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `mv_polynomial σ R` which mathematicians might call `X^s`
+ `a : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : mv_polynomial σ R`
### Definitions
* `mv_polynomial σ R` : the type of polynomials with variables of type `σ` and coefficients
in the commutative semiring `R`
* `monomial s a` : the monomial which mathematically would be denoted `a * X^s`
* `C a` : the constant polynomial with value `a`
* `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`.
* `coeff s p` : the coefficient of `s` in `p`.
* `eval₂ (f : R → S₁) (g : σ → S₁) p` : given a semiring homomorphism from `R` to another
semiring `S₁`, and a map `σ → S₁`, evaluates `p` at this valuation, returning a term of type `S₁`.
Note that `eval₂` can be made using `eval` and `map` (see below), and it has been suggested
that sticking to `eval` and `map` might make the code less brittle.
* `eval (g : σ → R) p` : given a map `σ → R`, evaluates `p` at this valuation,
returning a term of type `R`
* `map (f : R → S₁) p` : returns the multivariate polynomial obtained from `p` by the change of
coefficient semiring corresponding to `f`
## Implementation notes
Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite
support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`.
The definition of `mv_polynomial σ R` is `(σ →₀ ℕ) →₀ R` ; here `σ →₀ ℕ` denotes the space of all
monomials in the variables, and the function to `R` sends a monomial to its coefficient in
the polynomial being represented.
## Tags
polynomial, multivariate polynomial, multivariable polynomial
-/
noncomputable theory
open_locale classical big_operators
open set function finsupp add_monoid_algebra
open_locale big_operators
universes u v w x
variables {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x}
/-- Multivariate polynomial, where `σ` is the index set of the variables and
`R` is the coefficient ring -/
def mv_polynomial (σ : Type*) (R : Type*) [comm_semiring R] := add_monoid_algebra R (σ →₀ ℕ)
namespace mv_polynomial
variables {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section comm_semiring
section instances
instance decidable_eq_mv_polynomial [comm_semiring R] [decidable_eq σ] [decidable_eq R] :
decidable_eq (mv_polynomial σ R) := finsupp.decidable_eq
instance [comm_semiring R] : comm_semiring (mv_polynomial σ R) := add_monoid_algebra.comm_semiring
instance [comm_semiring R] : inhabited (mv_polynomial σ R) := ⟨0⟩
instance [monoid R] [comm_semiring S₁] [distrib_mul_action R S₁] :
distrib_mul_action R (mv_polynomial σ S₁) :=
add_monoid_algebra.distrib_mul_action
instance [monoid R] [comm_semiring S₁] [distrib_mul_action R S₁] [has_faithful_scalar R S₁] :
has_faithful_scalar R (mv_polynomial σ S₁) :=
add_monoid_algebra.has_faithful_scalar
instance [semiring R] [comm_semiring S₁] [module R S₁] : module R (mv_polynomial σ S₁) :=
add_monoid_algebra.module
instance [monoid R] [monoid S₁] [comm_semiring S₂]
[has_scalar R S₁] [distrib_mul_action R S₂] [distrib_mul_action S₁ S₂] [is_scalar_tower R S₁ S₂] :
is_scalar_tower R S₁ (mv_polynomial σ S₂) :=
add_monoid_algebra.is_scalar_tower
instance [monoid R] [monoid S₁][comm_semiring S₂]
[distrib_mul_action R S₂] [distrib_mul_action S₁ S₂] [smul_comm_class R S₁ S₂] :
smul_comm_class R S₁ (mv_polynomial σ S₂) :=
add_monoid_algebra.smul_comm_class
instance [comm_semiring R] [comm_semiring S₁] [algebra R S₁] : algebra R (mv_polynomial σ S₁) :=
add_monoid_algebra.algebra
-- TODO[gh-6025]: make this an instance once safe to do so
/-- If `R` is a subsingleton, then `mv_polynomial σ R` has a unique element -/
protected def unique [comm_semiring R] [subsingleton R] : unique (mv_polynomial σ R) :=
add_monoid_algebra.unique
end instances
variables [comm_semiring R] [comm_semiring S₁] {p q : mv_polynomial σ R}
/-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/
def monomial (s : σ →₀ ℕ) : R →ₗ[R] mv_polynomial σ R := lsingle s
lemma single_eq_monomial (s : σ →₀ ℕ) (a : R) : single s a = monomial s a := rfl
lemma mul_def : (p * q) = p.sum (λ m a, q.sum $ λ n b, monomial (m + n) (a * b)) := rfl
/-- `C a` is the constant polynomial with value `a` -/
def C : R →+* mv_polynomial σ R :=
{ to_fun := monomial 0, ..single_zero_ring_hom }
variables (R σ)
theorem algebra_map_eq : algebra_map R (mv_polynomial σ R) = C := rfl
variables {R σ}
/-- `X n` is the degree `1` monomial $X_n$. -/
def X (n : σ) : mv_polynomial σ R := monomial (single n 1) 1
lemma C_apply : (C a : mv_polynomial σ R) = monomial 0 a := rfl
@[simp] lemma C_0 : C 0 = (0 : mv_polynomial σ R) := by simp [C_apply, monomial]
@[simp] lemma C_1 : C 1 = (1 : mv_polynomial σ R) := rfl
lemma C_mul_monomial : C a * monomial s a' = monomial s (a * a') :=
by simp [C_apply, monomial, single_mul_single]
@[simp] lemma C_add : (C (a + a') : mv_polynomial σ R) = C a + C a' := single_add
@[simp] lemma C_mul : (C (a * a') : mv_polynomial σ R) = C a * C a' := C_mul_monomial.symm
@[simp] lemma C_pow (a : R) (n : ℕ) : (C (a^n) : mv_polynomial σ R) = (C a)^n :=
by induction n; simp [pow_succ, *]
lemma C_injective (σ : Type*) (R : Type*) [comm_semiring R] :
function.injective (C : R → mv_polynomial σ R) :=
finsupp.single_injective _
lemma C_surjective {R : Type*} [comm_semiring R] (σ : Type*) [is_empty σ] :
function.surjective (C : R → mv_polynomial σ R) :=
begin
refine λ p, ⟨p.to_fun 0, finsupp.ext (λ a, _)⟩,
simpa [(finsupp.ext is_empty_elim : a = 0), C_apply, monomial],
end
@[simp] lemma C_inj {σ : Type*} (R : Type*) [comm_semiring R] (r s : R) :
(C r : mv_polynomial σ R) = C s ↔ r = s :=
(C_injective σ R).eq_iff
instance infinite_of_infinite (σ : Type*) (R : Type*) [comm_semiring R] [infinite R] :
infinite (mv_polynomial σ R) :=
infinite.of_injective C (C_injective _ _)
instance infinite_of_nonempty (σ : Type*) (R : Type*) [nonempty σ] [comm_semiring R]
[nontrivial R] :
infinite (mv_polynomial σ R) :=
infinite.of_injective ((λ s : σ →₀ ℕ, monomial s 1) ∘ single (classical.arbitrary σ)) $
function.injective.comp
(λ m n, (finsupp.single_left_inj one_ne_zero).mp) (finsupp.single_injective _)
lemma C_eq_coe_nat (n : ℕ) : (C ↑n : mv_polynomial σ R) = n :=
by induction n; simp [nat.succ_eq_add_one, *]
theorem C_mul' : mv_polynomial.C a * p = a • p :=
(algebra.smul_def a p).symm
lemma smul_eq_C_mul (p : mv_polynomial σ R) (a : R) : a • p = C a * p := C_mul'.symm
lemma C_eq_smul_one : (C a : mv_polynomial σ R) = a • 1 :=
by rw [← C_mul', mul_one]
lemma monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) :=
add_monoid_algebra.single_pow e
@[simp] lemma monomial_mul {s s' : σ →₀ ℕ} {a b : R} :
monomial s a * monomial s' b = monomial (s + s') (a * b) :=
add_monoid_algebra.single_mul_single
variables (σ R)
/-- `λ s, monomial s 1` as a homomorphism. -/
def monomial_one_hom : multiplicative (σ →₀ ℕ) →* mv_polynomial σ R :=
add_monoid_algebra.of _ _
variables {σ R}
@[simp] lemma monomial_one_hom_apply :
monomial_one_hom R σ s = (monomial s 1 : mv_polynomial σ R) := rfl
lemma X_pow_eq_monomial : X n ^ e = monomial (single n e) (1 : R) :=
by simp [X, monomial_pow]
lemma monomial_add_single : monomial (s + single n e) a = (monomial s a * X n ^ e) :=
by rw [X_pow_eq_monomial, monomial_mul, mul_one]
lemma monomial_single_add : monomial (single n e + s) a = (X n ^ e * monomial s a) :=
by rw [X_pow_eq_monomial, monomial_mul, one_mul]
lemma monomial_eq_C_mul_X {s : σ} {a : R} {n : ℕ} :
monomial (single s n) a = C a * (X s)^n :=
by rw [← zero_add (single s n), monomial_add_single, C_apply]
@[simp] lemma monomial_zero {s : σ →₀ ℕ}: monomial s (0 : R) = 0 :=
single_zero
@[simp] lemma monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → mv_polynomial σ R) = C := rfl
@[simp] lemma sum_monomial_eq {A : Type*} [add_comm_monoid A]
{u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A} (w : b u 0 = 0) :
sum (monomial u r) b = b u r :=
sum_single_index w
@[simp] lemma sum_C {A : Type*} [add_comm_monoid A]
{b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) :
sum (C a) b = b 0 a :=
sum_monomial_eq w
lemma monomial_sum_one {α : Type*} (s : finset α) (f : α → (σ →₀ ℕ)) :
(monomial (∑ i in s, f i) 1 : mv_polynomial σ R) = ∏ i in s, monomial (f i) 1 :=
(monomial_one_hom R σ).map_prod (λ i, multiplicative.of_add (f i)) s
lemma monomial_sum_index {α : Type*} (s : finset α) (f : α → (σ →₀ ℕ)) (a : R) :
(monomial (∑ i in s, f i) a) = C a * ∏ i in s, monomial (f i) 1 :=
by rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one]
lemma monomial_finsupp_sum_index {α β : Type*} [has_zero β] (f : α →₀ β)
(g : α → β → (σ →₀ ℕ)) (a : R) :
(monomial (f.sum g) a) = C a * f.prod (λ a b, monomial (g a b) 1) :=
monomial_sum_index _ _ _
lemma monomial_eq : monomial s a = C a * (s.prod $ λn e, X n ^ e : mv_polynomial σ R) :=
by simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, finsupp.sum_single]
@[recursor 5]
lemma induction_on {M : mv_polynomial σ R → Prop} (p : mv_polynomial σ R)
(h_C : ∀a, M (C a)) (h_add : ∀p q, M p → M q → M (p + q)) (h_X : ∀p n, M p → M (p * X n)) :
M p :=
have ∀s a, M (monomial s a),
begin
assume s a,
apply @finsupp.induction σ ℕ _ _ s,
{ show M (monomial 0 a), from h_C a, },
{ assume n e p hpn he ih,
have : ∀e:ℕ, M (monomial p a * X n ^ e),
{ intro e,
induction e,
{ simp [ih] },
{ simp [ih, pow_succ', (mul_assoc _ _ _).symm, h_X, e_ih] } },
simp [add_comm, monomial_add_single, this] }
end,
finsupp.induction p
(by have : M (C 0) := h_C 0; rwa [C_0] at this)
(assume s a p hsp ha hp, h_add _ _ (this s a) hp)
attribute [elab_as_eliminator]
theorem induction_on' {P : mv_polynomial σ R → Prop} (p : mv_polynomial σ R)
(h1 : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a))
(h2 : ∀ (p q : mv_polynomial σ R), P p → P q → P (p + q)) : P p :=
finsupp.induction p (suffices P (monomial 0 0), by rwa monomial_zero at this,
show P (monomial 0 0), from h1 0 0)
(λ a b f ha hb hPf, h2 _ _ (h1 _ _) hPf)
lemma ring_hom_ext {A : Type*} [semiring A] {f g : mv_polynomial σ R →+* A}
(hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) :
f = g :=
by { ext, exacts [hC _, hX _] }
/-- See note [partially-applied ext lemmas]. -/
@[ext] lemma ring_hom_ext' {A : Type*} [semiring A] {f g : mv_polynomial σ R →+* A}
(hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) :
f = g :=
ring_hom_ext (ring_hom.ext_iff.1 hC) hX
lemma hom_eq_hom [semiring S₂]
(f g : mv_polynomial σ R →+* S₂)
(hC : f.comp C = g.comp C) (hX : ∀n:σ, f (X n) = g (X n)) (p : mv_polynomial σ R) :
f p = g p :=
ring_hom.congr_fun (ring_hom_ext' hC hX) p
lemma is_id (f : mv_polynomial σ R →+* mv_polynomial σ R)
(hC : f.comp C = C) (hX : ∀n:σ, f (X n) = (X n)) (p : mv_polynomial σ R) :
f p = p :=
hom_eq_hom f (ring_hom.id _) hC hX p
@[ext] lemma alg_hom_ext' {A B : Type*} [comm_semiring A] [comm_semiring B]
[algebra R A] [algebra R B] {f g : mv_polynomial σ A →ₐ[R] B}
(h₁ : f.comp (is_scalar_tower.to_alg_hom R A (mv_polynomial σ A)) =
g.comp (is_scalar_tower.to_alg_hom R A (mv_polynomial σ A)))
(h₂ : ∀ i, f (X i) = g (X i)) : f = g :=
alg_hom.coe_ring_hom_injective (mv_polynomial.ring_hom_ext'
(congr_arg alg_hom.to_ring_hom h₁) h₂)
@[ext] lemma alg_hom_ext {A : Type*} [comm_semiring A] [algebra R A]
{f g : mv_polynomial σ R →ₐ[R] A} (hf : ∀ i : σ, f (X i) = g (X i)) :
f = g :=
add_monoid_algebra.alg_hom_ext' (mul_hom_ext' (λ (x : σ), monoid_hom.ext_mnat (hf x)))
@[simp] lemma alg_hom_C (f : mv_polynomial σ R →ₐ[R] mv_polynomial σ R) (r : R) :
f (C r) = C r :=
f.commutes r
section support
/--
The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient.
-/
def support (p : mv_polynomial σ R) : finset (σ →₀ ℕ) :=
p.support
lemma finsupp_support_eq_support (p : mv_polynomial σ R) : finsupp.support p = p.support := rfl
lemma support_monomial [decidable (a = 0)] : (monomial s a).support = if a = 0 then ∅ else {s} :=
by convert rfl
lemma support_monomial_subset : (monomial s a).support ⊆ {s} :=
support_single_subset
lemma support_add : (p + q).support ⊆ p.support ∪ q.support := finsupp.support_add
lemma support_X [nontrivial R] : (X n : mv_polynomial σ R).support = {single n 1} :=
by rw [X, support_monomial, if_neg]; exact one_ne_zero
end support
section coeff
/-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/
def coeff (m : σ →₀ ℕ) (p : mv_polynomial σ R) : R :=
@coe_fn _ _ (monoid_algebra.has_coe_to_fun _ _) p m
@[simp] lemma mem_support_iff {p : mv_polynomial σ R} {m : σ →₀ ℕ} :
m ∈ p.support ↔ p.coeff m ≠ 0 :=
by simp [support, coeff]
lemma not_mem_support_iff {p : mv_polynomial σ R} {m : σ →₀ ℕ} :
m ∉ p.support ↔ p.coeff m = 0 :=
by simp
lemma sum_def {A} [add_comm_monoid A] {p : mv_polynomial σ R} {b : (σ →₀ ℕ) → R → A} :
p.sum b = ∑ m in p.support, b m (p.coeff m) :=
by simp [support, finsupp.sum, coeff]
lemma support_mul (p q : mv_polynomial σ R) :
(p * q).support ⊆ p.support.bUnion (λ a, q.support.bUnion $ λ b, {a + b}) :=
by convert add_monoid_algebra.support_mul p q; ext; convert iff.rfl
@[ext] lemma ext (p q : mv_polynomial σ R) :
(∀ m, coeff m p = coeff m q) → p = q := ext
lemma ext_iff (p q : mv_polynomial σ R) :
p = q ↔ (∀ m, coeff m p = coeff m q) :=
⟨ λ h m, by rw h, ext p q⟩
@[simp] lemma coeff_add (m : σ →₀ ℕ) (p q : mv_polynomial σ R) :
coeff m (p + q) = coeff m p + coeff m q := add_apply p q m
@[simp] lemma coeff_smul {S₁ : Type*} [monoid S₁] [distrib_mul_action S₁ R]
(m : σ →₀ ℕ) (c : S₁) (p : mv_polynomial σ R) :
coeff m (c • p) = c • coeff m p := smul_apply c p m
@[simp] lemma coeff_zero (m : σ →₀ ℕ) :
coeff m (0 : mv_polynomial σ R) = 0 := rfl
@[simp] lemma coeff_zero_X (i : σ) : coeff 0 (X i : mv_polynomial σ R) = 0 :=
single_eq_of_ne (λ h, by cases single_eq_zero.1 h)
/-- `mv_polynomial.coeff m` but promoted to an `add_monoid_hom`. -/
@[simps] def coeff_add_monoid_hom (m : σ →₀ ℕ) : mv_polynomial σ R →+ R :=
{ to_fun := coeff m,
map_zero' := coeff_zero m,
map_add' := coeff_add m }
lemma coeff_sum {X : Type*} (s : finset X) (f : X → mv_polynomial σ R) (m : σ →₀ ℕ) :
coeff m (∑ x in s, f x) = ∑ x in s, coeff m (f x) :=
(coeff_add_monoid_hom _).map_sum _ s
lemma monic_monomial_eq (m) : monomial m (1:R) = (m.prod $ λn e, X n ^ e : mv_polynomial σ R) :=
by simp [monomial_eq]
@[simp] lemma coeff_monomial [decidable_eq σ] (m n) (a) :
coeff m (monomial n a : mv_polynomial σ R) = if n = m then a else 0 :=
single_apply
@[simp] lemma coeff_C [decidable_eq σ] (m) (a) :
coeff m (C a : mv_polynomial σ R) = if 0 = m then a else 0 :=
single_apply
lemma coeff_one [decidable_eq σ] (m) :
coeff m (1 : mv_polynomial σ R) = if 0 = m then 1 else 0 :=
coeff_C m 1
@[simp] lemma coeff_zero_C (a) : coeff 0 (C a : mv_polynomial σ R) = a :=
single_eq_same
@[simp] lemma coeff_zero_one : coeff 0 (1 : mv_polynomial σ R) = 1 :=
coeff_zero_C 1
lemma coeff_X_pow [decidable_eq σ] (i : σ) (m) (k : ℕ) :
coeff m (X i ^ k : mv_polynomial σ R) = if single i k = m then 1 else 0 :=
begin
have := coeff_monomial m (finsupp.single i k) (1:R),
rwa [@monomial_eq _ _ (1:R) (finsupp.single i k) _,
C_1, one_mul, finsupp.prod_single_index] at this,
exact pow_zero _
end
lemma coeff_X' [decidable_eq σ] (i : σ) (m) :
coeff m (X i : mv_polynomial σ R) = if single i 1 = m then 1 else 0 :=
by rw [← coeff_X_pow, pow_one]
@[simp] lemma coeff_X (i : σ) :
coeff (single i 1) (X i : mv_polynomial σ R) = 1 :=
by rw [coeff_X', if_pos rfl]
@[simp] lemma coeff_C_mul (m) (a : R) (p : mv_polynomial σ R) :
coeff m (C a * p) = a * coeff m p :=
begin
rw [mul_def, sum_C],
{ simp [sum_def, coeff_sum] {contextual := tt} },
simp
end
lemma coeff_mul (p q : mv_polynomial σ R) (n : σ →₀ ℕ) :
coeff n (p * q) = ∑ x in antidiagonal n, coeff x.1 p * coeff x.2 q :=
add_monoid_algebra.mul_apply_antidiagonal p q _ _ $ λ p, mem_antidiagonal
@[simp] lemma coeff_mul_X (m) (s : σ) (p : mv_polynomial σ R) :
coeff (m + single s 1) (p * X s) = coeff m p :=
(add_monoid_algebra.mul_single_apply_aux p _ _ _ _ (λ a, add_left_inj _)).trans (mul_one _)
@[simp] lemma support_mul_X (s : σ) (p : mv_polynomial σ R) :
(p * X s).support = p.support.map (add_right_embedding (single s 1)) :=
add_monoid_algebra.support_mul_single p _ (by simp) _
lemma coeff_mul_X' [decidable_eq σ] (m) (s : σ) (p : mv_polynomial σ R) :
coeff m (p * X s) = if s ∈ m.support then coeff (m - single s 1) p else 0 :=
begin
nontriviality R,
split_ifs with h h,
{ conv_rhs {rw ← coeff_mul_X _ s},
congr' with t,
by_cases hj : s = t,
{ subst t, simp only [tsub_apply, add_apply, single_eq_same],
refine (tsub_add_cancel_of_le (nat.pos_of_ne_zero _).nat_succ_le).symm,
rwa finsupp.mem_support_iff at h },
{ simp [single_eq_of_ne hj] } },
{ rw ← not_mem_support_iff, intro hm, apply h,
have H := support_mul _ _ hm, simp only [finset.mem_bUnion] at H,
rcases H with ⟨j, hj, i', hi', H⟩,
rw [support_X, finset.mem_singleton] at hi', subst i',
rw finset.mem_singleton at H, subst m,
rw [finsupp.mem_support_iff, add_apply, single_apply, if_pos rfl],
intro H, rw [_root_.add_eq_zero_iff] at H, exact one_ne_zero H.2 }
end
lemma eq_zero_iff {p : mv_polynomial σ R} :
p = 0 ↔ ∀ d, coeff d p = 0 :=
by { rw ext_iff, simp only [coeff_zero], }
lemma ne_zero_iff {p : mv_polynomial σ R} :
p ≠ 0 ↔ ∃ d, coeff d p ≠ 0 :=
by { rw [ne.def, eq_zero_iff], push_neg, }
lemma exists_coeff_ne_zero {p : mv_polynomial σ R} (h : p ≠ 0) :
∃ d, coeff d p ≠ 0 :=
ne_zero_iff.mp h
lemma C_dvd_iff_dvd_coeff (r : R) (φ : mv_polynomial σ R) :
C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i :=
begin
split,
{ rintros ⟨φ, rfl⟩ c, rw coeff_C_mul, apply dvd_mul_right },
{ intro h,
choose c hc using h,
classical,
let c' : (σ →₀ ℕ) → R := λ i, if i ∈ φ.support then c i else 0,
let ψ : mv_polynomial σ R := ∑ i in φ.support, monomial i (c' i),
use ψ,
apply mv_polynomial.ext, intro i,
simp only [coeff_C_mul, coeff_sum, coeff_monomial, finset.sum_ite_eq', c'],
split_ifs with hi hi,
{ rw hc },
{ rw not_mem_support_iff at hi, rwa mul_zero } },
end
end coeff
section constant_coeff
/--
`constant_coeff p` returns the constant term of the polynomial `p`, defined as `coeff 0 p`.
This is a ring homomorphism.
-/
def constant_coeff : mv_polynomial σ R →+* R :=
{ to_fun := coeff 0,
map_one' := by simp [coeff, add_monoid_algebra.one_def],
map_mul' := by simp [coeff_mul, finsupp.support_single_ne_zero],
map_zero' := coeff_zero _,
map_add' := coeff_add _ }
lemma constant_coeff_eq : (constant_coeff : mv_polynomial σ R → R) = coeff 0 := rfl
@[simp]
lemma constant_coeff_C (r : R) :
constant_coeff (C r : mv_polynomial σ R) = r :=
by simp [constant_coeff_eq]
@[simp]
lemma constant_coeff_X (i : σ) :
constant_coeff (X i : mv_polynomial σ R) = 0 :=
by simp [constant_coeff_eq]
lemma constant_coeff_monomial [decidable_eq σ] (d : σ →₀ ℕ) (r : R) :
constant_coeff (monomial d r) = if d = 0 then r else 0 :=
by rw [constant_coeff_eq, coeff_monomial]
variables (σ R)
@[simp] lemma constant_coeff_comp_C :
constant_coeff.comp (C : R →+* mv_polynomial σ R) = ring_hom.id R :=
by { ext, apply constant_coeff_C }
@[simp] lemma constant_coeff_comp_algebra_map :
constant_coeff.comp (algebra_map R (mv_polynomial σ R)) = ring_hom.id R :=
constant_coeff_comp_C _ _
end constant_coeff
section as_sum
@[simp] lemma support_sum_monomial_coeff (p : mv_polynomial σ R) :
∑ v in p.support, monomial v (coeff v p) = p :=
finsupp.sum_single p
lemma as_sum (p : mv_polynomial σ R) : p = ∑ v in p.support, monomial v (coeff v p) :=
(support_sum_monomial_coeff p).symm
end as_sum
section eval₂
variables (f : R →+* S₁) (g : σ → S₁)
/-- Evaluate a polynomial `p` given a valuation `g` of all the variables
and a ring hom `f` from the scalar ring to the target -/
def eval₂ (p : mv_polynomial σ R) : S₁ :=
p.sum (λs a, f a * s.prod (λn e, g n ^ e))
lemma eval₂_eq (g : R →+* S₁) (x : σ → S₁) (f : mv_polynomial σ R) :
f.eval₂ g x = ∑ d in f.support, g (f.coeff d) * ∏ i in d.support, x i ^ d i :=
rfl
lemma eval₂_eq' [fintype σ] (g : R →+* S₁) (x : σ → S₁) (f : mv_polynomial σ R) :
f.eval₂ g x = ∑ d in f.support, g (f.coeff d) * ∏ i, x i ^ d i :=
by { simp only [eval₂_eq, ← finsupp.prod_pow], refl }
@[simp] lemma eval₂_zero : (0 : mv_polynomial σ R).eval₂ f g = 0 :=
finsupp.sum_zero_index
section
@[simp] lemma eval₂_add : (p + q).eval₂ f g = p.eval₂ f g + q.eval₂ f g :=
finsupp.sum_add_index
(by simp [f.map_zero])
(by simp [add_mul, f.map_add])
@[simp] lemma eval₂_monomial : (monomial s a).eval₂ f g = f a * s.prod (λn e, g n ^ e) :=
finsupp.sum_single_index (by simp [f.map_zero])
@[simp] lemma eval₂_C (a) : (C a).eval₂ f g = f a :=
by rw [C_apply, eval₂_monomial, prod_zero_index, mul_one]
@[simp] lemma eval₂_one : (1 : mv_polynomial σ R).eval₂ f g = 1 :=
(eval₂_C _ _ _).trans f.map_one
@[simp] lemma eval₂_X (n) : (X n).eval₂ f g = g n :=
by simp [eval₂_monomial, f.map_one, X, prod_single_index, pow_one]
lemma eval₂_mul_monomial :
∀{s a}, (p * monomial s a).eval₂ f g = p.eval₂ f g * f a * s.prod (λn e, g n ^ e) :=
begin
apply mv_polynomial.induction_on p,
{ assume a' s a,
simp [C_mul_monomial, eval₂_monomial, f.map_mul] },
{ assume p q ih_p ih_q, simp [add_mul, eval₂_add, ih_p, ih_q] },
{ assume p n ih s a,
from calc (p * X n * monomial s a).eval₂ f g = (p * monomial (single n 1 + s) a).eval₂ f g :
by rw [monomial_single_add, pow_one, mul_assoc]
... = (p * monomial (single n 1) 1).eval₂ f g * f a * s.prod (λn e, g n ^ e) :
by simp [ih, prod_single_index, prod_add_index, pow_one, pow_add, mul_assoc, mul_left_comm,
f.map_one, -add_comm] }
end
lemma eval₂_mul_C : (p * C a).eval₂ f g = p.eval₂ f g * f a :=
(eval₂_mul_monomial _ _).trans $ by simp
@[simp] lemma eval₂_mul : ∀{p}, (p * q).eval₂ f g = p.eval₂ f g * q.eval₂ f g :=
begin
apply mv_polynomial.induction_on q,
{ simp [eval₂_C, eval₂_mul_C] },
{ simp [mul_add, eval₂_add] {contextual := tt} },
{ simp [X, eval₂_monomial, eval₂_mul_monomial, ← mul_assoc] { contextual := tt} }
end
@[simp] lemma eval₂_pow {p:mv_polynomial σ R} : ∀{n:ℕ}, (p ^ n).eval₂ f g = (p.eval₂ f g)^n
| 0 := by { rw [pow_zero, pow_zero], exact eval₂_one _ _ }
| (n + 1) := by rw [pow_add, pow_one, pow_add, pow_one, eval₂_mul, eval₂_pow]
/-- `mv_polynomial.eval₂` as a `ring_hom`. -/
def eval₂_hom (f : R →+* S₁) (g : σ → S₁) : mv_polynomial σ R →+* S₁ :=
{ to_fun := eval₂ f g,
map_one' := eval₂_one _ _,
map_mul' := λ p q, eval₂_mul _ _,
map_zero' := eval₂_zero _ _,
map_add' := λ p q, eval₂_add _ _ }
@[simp] lemma coe_eval₂_hom (f : R →+* S₁) (g : σ → S₁) :
⇑(eval₂_hom f g) = eval₂ f g := rfl
lemma eval₂_hom_congr {f₁ f₂ : R →+* S₁} {g₁ g₂ : σ → S₁} {p₁ p₂ : mv_polynomial σ R} :
f₁ = f₂ → g₁ = g₂ → p₁ = p₂ → eval₂_hom f₁ g₁ p₁ = eval₂_hom f₂ g₂ p₂ :=
by rintros rfl rfl rfl; refl
end
@[simp] lemma eval₂_hom_C (f : R →+* S₁) (g : σ → S₁) (r : R) :
eval₂_hom f g (C r) = f r := eval₂_C f g r
@[simp] lemma eval₂_hom_X' (f : R →+* S₁) (g : σ → S₁) (i : σ) :
eval₂_hom f g (X i) = g i := eval₂_X f g i
@[simp] lemma comp_eval₂_hom [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₁) (φ : S₁ →+* S₂) :
φ.comp (eval₂_hom f g) = (eval₂_hom (φ.comp f) (λ i, φ (g i))) :=
begin
apply mv_polynomial.ring_hom_ext,
{ intro r, rw [ring_hom.comp_apply, eval₂_hom_C, eval₂_hom_C, ring_hom.comp_apply] },
{ intro i, rw [ring_hom.comp_apply, eval₂_hom_X', eval₂_hom_X'] }
end
lemma map_eval₂_hom [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₁) (φ : S₁ →+* S₂)
(p : mv_polynomial σ R) :
φ (eval₂_hom f g p) = (eval₂_hom (φ.comp f) (λ i, φ (g i)) p) :=
by { rw ← comp_eval₂_hom, refl }
lemma eval₂_hom_monomial (f : R →+* S₁) (g : σ → S₁) (d : σ →₀ ℕ) (r : R) :
eval₂_hom f g (monomial d r) = f r * d.prod (λ i k, g i ^ k) :=
by simp only [monomial_eq, ring_hom.map_mul, eval₂_hom_C, finsupp.prod,
ring_hom.map_prod, ring_hom.map_pow, eval₂_hom_X']
section
lemma eval₂_comp_left {S₂} [comm_semiring S₂]
(k : S₁ →+* S₂) (f : R →+* S₁) (g : σ → S₁)
(p) : k (eval₂ f g p) = eval₂ (k.comp f) (k ∘ g) p :=
by apply mv_polynomial.induction_on p; simp [
eval₂_add, k.map_add,
eval₂_mul, k.map_mul] {contextual := tt}
end
@[simp] lemma eval₂_eta (p : mv_polynomial σ R) : eval₂ C X p = p :=
by apply mv_polynomial.induction_on p;
simp [eval₂_add, eval₂_mul] {contextual := tt}
lemma eval₂_congr (g₁ g₂ : σ → S₁)
(h : ∀ {i : σ} {c : σ →₀ ℕ}, i ∈ c.support → coeff c p ≠ 0 → g₁ i = g₂ i) :
p.eval₂ f g₁ = p.eval₂ f g₂ :=
begin
apply finset.sum_congr rfl,
intros c hc, dsimp, congr' 1,
apply finset.prod_congr rfl,
intros i hi, dsimp, congr' 1,
apply h hi,
rwa finsupp.mem_support_iff at hc
end
@[simp] lemma eval₂_prod (s : finset S₂) (p : S₂ → mv_polynomial σ R) :
eval₂ f g (∏ x in s, p x) = ∏ x in s, eval₂ f g (p x) :=
(eval₂_hom f g).map_prod _ s
@[simp] lemma eval₂_sum (s : finset S₂) (p : S₂ → mv_polynomial σ R) :
eval₂ f g (∑ x in s, p x) = ∑ x in s, eval₂ f g (p x) :=
(eval₂_hom f g).map_sum _ s
attribute [to_additive] eval₂_prod
lemma eval₂_assoc (q : S₂ → mv_polynomial σ R) (p : mv_polynomial S₂ R) :
eval₂ f (λ t, eval₂ f g (q t)) p = eval₂ f g (eval₂ C q p) :=
begin
show _ = eval₂_hom f g (eval₂ C q p),
rw eval₂_comp_left (eval₂_hom f g), congr' with a, simp,
end
end eval₂
section eval
variables {f : σ → R}
/-- Evaluate a polynomial `p` given a valuation `f` of all the variables -/
def eval (f : σ → R) : mv_polynomial σ R →+* R := eval₂_hom (ring_hom.id _) f
lemma eval_eq (x : σ → R) (f : mv_polynomial σ R) :
eval x f = ∑ d in f.support, f.coeff d * ∏ i in d.support, x i ^ d i :=
rfl
lemma eval_eq' [fintype σ] (x : σ → R) (f : mv_polynomial σ R) :
eval x f = ∑ d in f.support, f.coeff d * ∏ i, x i ^ d i :=
eval₂_eq' (ring_hom.id R) x f
lemma eval_monomial : eval f (monomial s a) = a * s.prod (λn e, f n ^ e) :=
eval₂_monomial _ _
@[simp] lemma eval_C : ∀ a, eval f (C a) = a := eval₂_C _ _
@[simp] lemma eval_X : ∀ n, eval f (X n) = f n := eval₂_X _ _
@[simp] lemma smul_eval (x) (p : mv_polynomial σ R) (s) : eval x (s • p) = s * eval x p :=
by rw [smul_eq_C_mul, (eval x).map_mul, eval_C]
lemma eval_sum {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ R) (g : σ → R) :
eval g (∑ i in s, f i) = ∑ i in s, eval g (f i) :=
(eval g).map_sum _ _
@[to_additive]
lemma eval_prod {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ R) (g : σ → R) :
eval g (∏ i in s, f i) = ∏ i in s, eval g (f i) :=
(eval g).map_prod _ _
theorem eval_assoc {τ}
(f : σ → mv_polynomial τ R) (g : τ → R)
(p : mv_polynomial σ R) :
eval (eval g ∘ f) p = eval g (eval₂ C f p) :=
begin
rw eval₂_comp_left (eval g),
unfold eval, simp only [coe_eval₂_hom],
congr' with a, simp
end
end eval
section map
variables (f : R →+* S₁)
/-- `map f p` maps a polynomial `p` across a ring hom `f` -/
def map : mv_polynomial σ R →+* mv_polynomial σ S₁ := eval₂_hom (C.comp f) X
@[simp] theorem map_monomial (s : σ →₀ ℕ) (a : R) : map f (monomial s a) = monomial s (f a) :=
(eval₂_monomial _ _).trans monomial_eq.symm
@[simp] theorem map_C : ∀ (a : R), map f (C a : mv_polynomial σ R) = C (f a) := map_monomial _ _
@[simp] theorem map_X : ∀ (n : σ), map f (X n : mv_polynomial σ R) = X n := eval₂_X _ _
theorem map_id : ∀ (p : mv_polynomial σ R), map (ring_hom.id R) p = p := eval₂_eta
theorem map_map [comm_semiring S₂]
(g : S₁ →+* S₂)
(p : mv_polynomial σ R) :
map g (map f p) = map (g.comp f) p :=
(eval₂_comp_left (map g) (C.comp f) X p).trans $
begin
congr,
{ ext1 a, simp only [map_C, comp_app, ring_hom.coe_comp], },
{ ext1 n, simp only [map_X, comp_app], }
end
theorem eval₂_eq_eval_map (g : σ → S₁) (p : mv_polynomial σ R) :
p.eval₂ f g = eval g (map f p) :=
begin
unfold map eval, simp only [coe_eval₂_hom],
have h := eval₂_comp_left (eval₂_hom _ g),
dsimp at h,
rw h,
congr,
{ ext1 a, simp only [coe_eval₂_hom, ring_hom.id_apply, comp_app, eval₂_C, ring_hom.coe_comp], },
{ ext1 n, simp only [comp_app, eval₂_X], },
end
lemma eval₂_comp_right {S₂} [comm_semiring S₂]
(k : S₁ →+* S₂) (f : R →+* S₁) (g : σ → S₁)
(p) : k (eval₂ f g p) = eval₂ k (k ∘ g) (map f p) :=
begin
apply mv_polynomial.induction_on p,
{ intro r, rw [eval₂_C, map_C, eval₂_C] },
{ intros p q hp hq, rw [eval₂_add, k.map_add, (map f).map_add, eval₂_add, hp, hq] },
{ intros p s hp,
rw [eval₂_mul, k.map_mul, (map f).map_mul, eval₂_mul, map_X, hp, eval₂_X, eval₂_X] }
end
lemma map_eval₂ (f : R →+* S₁) (g : S₂ → mv_polynomial S₃ R) (p : mv_polynomial S₂ R) :
map f (eval₂ C g p) = eval₂ C (map f ∘ g) (map f p) :=
begin
apply mv_polynomial.induction_on p,
{ intro r, rw [eval₂_C, map_C, map_C, eval₂_C] },
{ intros p q hp hq, rw [eval₂_add, (map f).map_add, hp, hq, (map f).map_add, eval₂_add] },
{ intros p s hp,
rw [eval₂_mul, (map f).map_mul, hp, (map f).map_mul, map_X, eval₂_mul, eval₂_X, eval₂_X] }
end
lemma coeff_map (p : mv_polynomial σ R) : ∀ (m : σ →₀ ℕ), coeff m (map f p) = f (coeff m p) :=
begin
apply mv_polynomial.induction_on p; clear p,
{ intros r m, rw [map_C], simp only [coeff_C], split_ifs, {refl}, rw f.map_zero },
{ intros p q hp hq m, simp only [hp, hq, (map f).map_add, coeff_add], rw f.map_add },
{ intros p i hp m, simp only [hp, (map f).map_mul, map_X],
simp only [hp, mem_support_iff, coeff_mul_X'],
split_ifs, {refl},
rw f.map_zero }
end
lemma map_injective (hf : function.injective f) :
function.injective (map f : mv_polynomial σ R → mv_polynomial σ S₁) :=
begin
intros p q h,
simp only [ext_iff, coeff_map] at h ⊢,
intro m,
exact hf (h m),
end
lemma map_surjective (hf : function.surjective f) :
function.surjective (map f : mv_polynomial σ R → mv_polynomial σ S₁) :=
λ p, begin
induction p using mv_polynomial.induction_on' with i fr a b ha hb,
{ obtain ⟨r, rfl⟩ := hf fr,
exact ⟨monomial i r, map_monomial _ _ _⟩, },
{ obtain ⟨a, rfl⟩ := ha,
obtain ⟨b, rfl⟩ := hb,
exact ⟨a + b, ring_hom.map_add _ _ _⟩ },
end
/-- If `f` is a left-inverse of `g` then `map f` is a left-inverse of `map g`. -/
lemma map_left_inverse {f : R →+* S₁} {g : S₁ →+* R} (hf : function.left_inverse f g) :
function.left_inverse (map f : mv_polynomial σ R → mv_polynomial σ S₁) (map g) :=
λ x, by rw [map_map, (ring_hom.ext hf : f.comp g = ring_hom.id _), map_id]
/-- If `f` is a right-inverse of `g` then `map f` is a right-inverse of `map g`. -/
lemma map_right_inverse {f : R →+* S₁} {g : S₁ →+* R} (hf : function.right_inverse f g) :
function.right_inverse (map f : mv_polynomial σ R → mv_polynomial σ S₁) (map g) :=
(map_left_inverse hf.left_inverse).right_inverse
@[simp] lemma eval_map (f : R →+* S₁) (g : σ → S₁) (p : mv_polynomial σ R) :
eval g (map f p) = eval₂ f g p :=
by { apply mv_polynomial.induction_on p; { simp { contextual := tt } } }
@[simp] lemma eval₂_map [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₂) (φ : S₁ →+* S₂)
(p : mv_polynomial σ R) :
eval₂ φ g (map f p) = eval₂ (φ.comp f) g p :=
by { rw [← eval_map, ← eval_map, map_map], }
@[simp] lemma eval₂_hom_map_hom [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₂) (φ : S₁ →+* S₂)
(p : mv_polynomial σ R) :
eval₂_hom φ g (map f p) = eval₂_hom (φ.comp f) g p :=
eval₂_map f g φ p
@[simp] lemma constant_coeff_map (f : R →+* S₁) (φ : mv_polynomial σ R) :
constant_coeff (mv_polynomial.map f φ) = f (constant_coeff φ) :=
coeff_map f φ 0
lemma constant_coeff_comp_map (f : R →+* S₁) :
(constant_coeff : mv_polynomial σ S₁ →+* S₁).comp (mv_polynomial.map f) = f.comp constant_coeff :=
by { ext; simp }
lemma support_map_subset (p : mv_polynomial σ R) : (map f p).support ⊆ p.support :=
begin
intro x,
simp only [mem_support_iff],
contrapose!,
change p.coeff x = 0 → (map f p).coeff x = 0,
rw coeff_map,
intro hx,
rw hx,
exact ring_hom.map_zero f
end
lemma support_map_of_injective (p : mv_polynomial σ R) {f : R →+* S₁} (hf : injective f) :
(map f p).support = p.support :=
begin
apply finset.subset.antisymm,
{ exact mv_polynomial.support_map_subset _ _ },
intros x hx,
rw mem_support_iff,
contrapose! hx,
simp only [not_not, mem_support_iff],
change (map f p).coeff x = 0 at hx,
rw [coeff_map, ← f.map_zero] at hx,
exact hf hx
end
lemma C_dvd_iff_map_hom_eq_zero
(q : R →+* S₁) (r : R) (hr : ∀ r' : R, q r' = 0 ↔ r ∣ r')
(φ : mv_polynomial σ R) :
C r ∣ φ ↔ map q φ = 0 :=
begin
rw [C_dvd_iff_dvd_coeff, mv_polynomial.ext_iff],
simp only [coeff_map, coeff_zero, hr],
end
lemma map_map_range_eq_iff (f : R →+* S₁) (g : S₁ → R) (hg : g 0 = 0) (φ : mv_polynomial σ S₁) :
map f (finsupp.map_range g hg φ) = φ ↔ ∀ d, f (g (coeff d φ)) = coeff d φ :=
begin
rw mv_polynomial.ext_iff,
apply forall_congr, intro m,
rw [coeff_map],
apply eq_iff_eq_cancel_right.mpr,
refl
end
/-- If `f : S₁ →ₐ[R] S₂` is a morphism of `R`-algebras, then so is `mv_polynomial.map f`. -/
@[simps]
def map_alg_hom [comm_semiring S₂] [algebra R S₁] [algebra R S₂] (f : S₁ →ₐ[R] S₂) :
mv_polynomial σ S₁ →ₐ[R] mv_polynomial σ S₂ :=
{ to_fun := map ↑f,
commutes' := λ r, begin
have h₁ : algebra_map R (mv_polynomial σ S₁) r = C (algebra_map R S₁ r) := rfl,
have h₂ : algebra_map R (mv_polynomial σ S₂) r = C (algebra_map R S₂ r) := rfl,
rw [h₁, h₂, map, eval₂_hom_C, ring_hom.comp_apply, alg_hom.coe_to_ring_hom, alg_hom.commutes],
end,
..map ↑f }
@[simp] lemma map_alg_hom_id [algebra R S₁] :
map_alg_hom (alg_hom.id R S₁) = alg_hom.id R (mv_polynomial σ S₁) :=
alg_hom.ext map_id
@[simp] lemma map_alg_hom_coe_ring_hom [comm_semiring S₂] [algebra R S₁] [algebra R S₂]
(f : S₁ →ₐ[R] S₂) :
↑(map_alg_hom f : _ →ₐ[R] mv_polynomial σ S₂) =
(map ↑f : mv_polynomial σ S₁ →+* mv_polynomial σ S₂) :=
ring_hom.mk_coe _ _ _ _ _
end map
section aeval
/-! ### The algebra of multivariate polynomials -/
variables [algebra R S₁] [comm_semiring S₂]
variables (f : σ → S₁)
/-- A map `σ → S₁` where `S₁` is an algebra over `R` generates an `R`-algebra homomorphism
from multivariate polynomials over `σ` to `S₁`. -/
def aeval : mv_polynomial σ R →ₐ[R] S₁ :=
{ commutes' := λ r, eval₂_C _ _ _
.. eval₂_hom (algebra_map R S₁) f }
theorem aeval_def (p : mv_polynomial σ R) : aeval f p = eval₂ (algebra_map R S₁) f p := rfl
lemma aeval_eq_eval₂_hom (p : mv_polynomial σ R) :
aeval f p = eval₂_hom (algebra_map R S₁) f p := rfl
@[simp] lemma aeval_X (s : σ) : aeval f (X s : mv_polynomial _ R) = f s := eval₂_X _ _ _
@[simp] lemma aeval_C (r : R) : aeval f (C r) = algebra_map R S₁ r := eval₂_C _ _ _
theorem aeval_unique (φ : mv_polynomial σ R →ₐ[R] S₁) :
φ = aeval (φ ∘ X) :=
by { ext i, simp }
lemma comp_aeval {B : Type*} [comm_semiring B] [algebra R B]
(φ : S₁ →ₐ[R] B) :
φ.comp (aeval f) = aeval (λ i, φ (f i)) :=
by { ext i, simp }
@[simp] lemma map_aeval {B : Type*} [comm_semiring B]
(g : σ → S₁) (φ : S₁ →+* B) (p : mv_polynomial σ R) :
φ (aeval g p) = (eval₂_hom (φ.comp (algebra_map R S₁)) (λ i, φ (g i)) p) :=
by { rw ← comp_eval₂_hom, refl }
@[simp] lemma eval₂_hom_zero (f : R →+* S₂) (p : mv_polynomial σ R) :
eval₂_hom f (0 : σ → S₂) p = f (constant_coeff p) :=
begin
suffices : eval₂_hom f (0 : σ → S₂) = f.comp constant_coeff,
from ring_hom.congr_fun this p,
ext; simp
end
@[simp] lemma eval₂_hom_zero' (f : R →+* S₂) (p : mv_polynomial σ R) :
eval₂_hom f (λ _, 0 : σ → S₂) p = f (constant_coeff p) :=
eval₂_hom_zero f p
@[simp] lemma aeval_zero (p : mv_polynomial σ R) :
aeval (0 : σ → S₁) p = algebra_map _ _ (constant_coeff p) :=
eval₂_hom_zero (algebra_map R S₁) p
@[simp] lemma aeval_zero' (p : mv_polynomial σ R) :
aeval (λ _, 0 : σ → S₁) p = algebra_map _ _ (constant_coeff p) :=
aeval_zero p
lemma aeval_monomial (g : σ → S₁) (d : σ →₀ ℕ) (r : R) :
aeval g (monomial d r) = algebra_map _ _ r * d.prod (λ i k, g i ^ k) :=
eval₂_hom_monomial _ _ _ _
lemma eval₂_hom_eq_zero (f : R →+* S₂) (g : σ → S₂) (φ : mv_polynomial σ R)
(h : ∀ d, φ.coeff d ≠ 0 → ∃ i ∈ d.support, g i = 0) :
eval₂_hom f g φ = 0 :=
begin
rw [φ.as_sum, ring_hom.map_sum, finset.sum_eq_zero],
intros d hd,
obtain ⟨i, hi, hgi⟩ : ∃ i ∈ d.support, g i = 0 := h d (finsupp.mem_support_iff.mp hd),
rw [eval₂_hom_monomial, finsupp.prod, finset.prod_eq_zero hi, mul_zero],
rw [hgi, zero_pow],
rwa [pos_iff_ne_zero, ← finsupp.mem_support_iff]
end
lemma aeval_eq_zero [algebra R S₂] (f : σ → S₂) (φ : mv_polynomial σ R)
(h : ∀ d, φ.coeff d ≠ 0 → ∃ i ∈ d.support, f i = 0) :
aeval f φ = 0 :=
eval₂_hom_eq_zero _ _ _ h
end aeval
section aeval_tower
variables {S A B : Type*} [comm_semiring S] [comm_semiring A] [comm_semiring B]
variables [algebra S R] [algebra S A] [algebra S B]
/-- Version of `aeval` for defining algebra homs out of `mv_polynomial σ R` over a smaller base ring
than `R`. -/
def aeval_tower (f : R →ₐ[S] A) (x : σ → A) : mv_polynomial σ R →ₐ[S] A :=
{ commutes' := λ r,
by simp [is_scalar_tower.algebra_map_eq S R (mv_polynomial σ R), algebra_map_eq],
..eval₂_hom ↑f x }
variables (g : R →ₐ[S] A) (y : σ → A)
@[simp] lemma aeval_tower_X (i : σ): aeval_tower g y (X i) = y i := eval₂_X _ _ _
@[simp] lemma aeval_tower_C (x : R) : aeval_tower g y (C x) = g x := eval₂_C _ _ _
@[simp] lemma aeval_tower_comp_C : ((aeval_tower g y : mv_polynomial σ R →+* A).comp C) = g :=
ring_hom.ext $ aeval_tower_C _ _
@[simp] lemma aeval_tower_algebra_map (x : R) :
aeval_tower g y (algebra_map R (mv_polynomial σ R) x) = g x := eval₂_C _ _ _
@[simp] lemma aeval_tower_comp_algebra_map :
(aeval_tower g y : mv_polynomial σ R →+* A).comp (algebra_map R (mv_polynomial σ R)) = g :=
aeval_tower_comp_C _ _
lemma aeval_tower_to_alg_hom (x : R) :
aeval_tower g y (is_scalar_tower.to_alg_hom S R (mv_polynomial σ R) x) = g x :=
aeval_tower_algebra_map _ _ _
@[simp] lemma aeval_tower_comp_to_alg_hom :
(aeval_tower g y).comp (is_scalar_tower.to_alg_hom S R (mv_polynomial σ R)) = g :=
alg_hom.coe_ring_hom_injective $ aeval_tower_comp_algebra_map _ _
@[simp] lemma aeval_tower_id : aeval_tower (alg_hom.id S S) =
(aeval : (σ → S) → (mv_polynomial σ S →ₐ[S] S)) :=
by { ext, simp only [aeval_tower_X, aeval_X] }
@[simp] lemma aeval_tower_of_id : aeval_tower (algebra.of_id S A) =
(aeval : (σ → A) → (mv_polynomial σ S →ₐ[S] A)) :=
by { ext, simp only [aeval_X, aeval_tower_X] }
end aeval_tower
end comm_semiring
end mv_polynomial
|
8bbb2aa4484b7691868b667f49cbe64ea5923e1a | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/special_functions/trigonometric/inverse.lean | 3e8f1bc2dbb40e4997bc4f28eba22dd35ddcaa56 | [
"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,918 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.trigonometric.basic
import topology.algebra.order.proj_Icc
/-!
# Inverse trigonometric functions.
See also `analysis.special_functions.trigonometric.arctan` for the inverse tan function.
(This is delayed as it is easier to set up after developing complex trigonometric functions.)
Basic inequalities on trigonometric functions.
-/
noncomputable theory
open_locale classical topological_space filter
open set filter
open_locale real
namespace real
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.
It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/
@[pp_nodot] noncomputable def arcsin : ℝ → ℝ :=
coe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm
lemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _
@[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) :=
by { rw [arcsin, range_comp coe], simp [Icc] }
lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2
lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1
lemma arcsin_proj_Icc (x : ℝ) :
arcsin (proj_Icc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x :=
by rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend]
lemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x :=
by simpa [arcsin, Icc_extend_of_mem _ _ hx, -order_iso.apply_symm_apply]
using subtype.ext_iff.1 (sin_order_iso.apply_symm_apply ⟨x, hx⟩)
lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
sin_arcsin' ⟨hx₁, hx₂⟩
lemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x :=
inj_on_sin (arcsin_mem_Icc _) hx $ by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]
lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
arcsin_sin' ⟨hx₁, hx₂⟩
lemma strict_mono_on_arcsin : strict_mono_on arcsin (Icc (-1) 1) :=
(subtype.strict_mono_coe _).comp_strict_mono_on $
sin_order_iso.symm.strict_mono.strict_mono_on_Icc_extend _
lemma monotone_arcsin : monotone arcsin :=
(subtype.mono_coe _).comp $ sin_order_iso.symm.monotone.Icc_extend _
lemma inj_on_arcsin : inj_on arcsin (Icc (-1) 1) := strict_mono_on_arcsin.inj_on
lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arcsin x = arcsin y ↔ x = y :=
inj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[continuity]
lemma continuous_arcsin : continuous arcsin :=
continuous_subtype_coe.comp sin_order_iso.symm.continuous.Icc_extend'
lemma continuous_at_arcsin {x : ℝ} : continuous_at arcsin x :=
continuous_arcsin.continuous_at
lemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :
arcsin y = x :=
begin
subst y,
exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))
end
@[simp] lemma arcsin_zero : arcsin 0 = 0 :=
arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩
@[simp] lemma arcsin_one : arcsin 1 = π / 2 :=
arcsin_eq_of_sin_eq sin_pi_div_two $ right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
lemma arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 :=
by rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one]
lemma arcsin_neg_one : arcsin (-1) = -(π / 2) :=
arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) $
left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
lemma arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) :=
by rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one]
@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=
begin
cases le_total x (-1) with hx₁ hx₁,
{ rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] },
cases le_total 1 x with hx₂ hx₂,
{ rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] },
refine arcsin_eq_of_sin_eq _ _,
{ rw [sin_neg, sin_arcsin hx₁ hx₂] },
{ exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ }
end
lemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y :=
by rw [← arcsin_sin' hy, strict_mono_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]
lemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y :=
begin
cases le_total x (-1) with hx₁ hx₁,
{ simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] },
cases lt_or_le 1 x with hx₂ hx₂,
{ simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] },
exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)
end
lemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x ≤ arcsin y ↔ sin x ≤ y :=
by rw [← neg_le_neg_iff, ← arcsin_neg,
arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
lemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :
x ≤ arcsin y ↔ sin x ≤ y :=
by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
lemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le hy hx).trans not_le
lemma arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le' hy).trans not_le
lemma lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin hy hx).trans not_le
lemma lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin' hx).trans not_le
lemma arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :
arcsin x = y ↔ x = sin y :=
by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),
le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]
@[simp] lemma arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=
(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero]
@[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=
neg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg
@[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 :=
by simp [le_antisymm_iff]
@[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=
eq_comm.trans arcsin_eq_zero_iff
@[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le arcsin_nonpos
@[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=
lt_iff_lt_of_le_iff_le arcsin_nonneg
@[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 :=
(arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 $ neg_lt_self pi_div_two_pos)).trans $
by rw sin_pi_div_two
@[simp] lemma neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x :=
(lt_arcsin_iff_sin_lt' $ left_mem_Ico.2 $ neg_lt_self pi_div_two_pos).trans $
by rw [sin_neg, sin_pi_div_two]
@[simp] lemma arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=
⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩
@[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=
eq_comm.trans arcsin_eq_pi_div_two
@[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x :=
(arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin
@[simp] lemma arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=
⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩
@[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=
eq_comm.trans arcsin_eq_neg_pi_div_two
@[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=
(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two
@[simp] lemma pi_div_four_le_arcsin {x} : π / 4 ≤ arcsin x ↔ sqrt 2 / 2 ≤ x :=
by { rw [← sin_pi_div_four, le_arcsin_iff_sin_le'], have := pi_pos, split; linarith }
lemma maps_to_sin_Ioo : maps_to sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) :=
λ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin,
arcsin_sin h.1.le h.2.le]
/-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/
@[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ :=
{ to_fun := sin,
inv_fun := arcsin,
source := Ioo (-(π / 2)) (π / 2),
target := Ioo (-1) 1,
map_source' := maps_to_sin_Ioo,
map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩,
left_inv' := λ x hx, arcsin_sin hx.1.le hx.2.le,
right_inv' := λ y hy, sin_arcsin hy.1.le hy.2.le,
open_source := is_open_Ioo,
open_target := is_open_Ioo,
continuous_to_fun := continuous_sin.continuous_on,
continuous_inv_fun := continuous_arcsin.continuous_on }
lemma cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
lemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) :=
have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x),
begin
rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))),
sq, sqrt_mul_self (cos_arcsin_nonneg _)] at this,
rw [this, sin_arcsin hx₁ hx₂],
end
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
If the argument is not between `-1` and `1` it defaults to `π / 2` -/
@[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
lemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl
lemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=
by simp [arccos]
lemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=
by unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
lemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=
by unfold arccos; linarith [arcsin_le_pi_div_two x]
lemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=
by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
lemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=
by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma strict_anti_on_arccos : strict_anti_on arccos (Icc (-1) 1) :=
λ x hx y hy h, sub_lt_sub_left (strict_mono_on_arcsin hx hy h) _
lemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_anti_on_arccos.inj_on
lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arccos x = arccos y ↔ x = y :=
arccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[simp] lemma arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp] lemma arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
@[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x :=
by simp [arccos, sub_eq_zero]
@[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 :=
by simp [arccos]
@[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 :=
by rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]
lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=
by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]
lemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arccos x) = sqrt (1 - x ^ 2) :=
by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx₁ hx₂]
@[simp] lemma arccos_le_pi_div_two {x} : arccos x ≤ π / 2 ↔ 0 ≤ x := by simp [arccos]
@[simp] lemma arccos_le_pi_div_four {x} : arccos x ≤ π / 4 ↔ sqrt 2 / 2 ≤ x :=
by { rw [arccos, ← pi_div_four_le_arcsin], split; { intro, linarith } }
@[continuity]
lemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin
end real
|
3ed69312d856c0133ff47d23e3cafdc6f2983b42 | 853df553b1d6ca524e3f0a79aedd32dde5d27ec3 | /src/data/nat/prime.lean | 5f224afd8393fa1e25e5e9b36feb9fbc87f16cd1 | [
"Apache-2.0"
] | permissive | DanielFabian/mathlib | efc3a50b5dde303c59eeb6353ef4c35a345d7112 | f520d07eba0c852e96fe26da71d85bf6d40fcc2a | refs/heads/master | 1,668,739,922,971 | 1,595,201,756,000 | 1,595,201,756,000 | 279,469,476 | 0 | 0 | null | 1,594,696,604,000 | 1,594,696,604,000 | null | UTF-8 | Lean | false | false | 22,977 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import data.nat.sqrt
import data.nat.gcd
import algebra.group_power
import tactic.wlog
/-!
# Prime numbers
This file deals with prime numbers: natural numbers `p ≥ 2` whose only divisors are `p` and `1`.
## Important declarations
All the following declarations exist in the namespace `nat`.
- `prime`: the predicate that expresses that a natural number `p` is prime
- `primes`: the subtype of natural numbers that are prime
- `min_fac n`: the minimal prime factor of a natural number `n ≠ 1`
- `exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers
- `factors n`: the prime factorization of `n`
- `factors_unique`: uniqueness of the prime factorisation
-/
open bool subtype
namespace nat
open decidable
/-- `prime p` means that `p` is a prime number, that is, a natural number
at least 2 whose only divisors are `p` and `1`. -/
@[pp_nodot]
def prime (p : ℕ) := 2 ≤ p ∧ ∀ m ∣ p, m = 1 ∨ m = p
theorem prime.two_le {p : ℕ} : prime p → 2 ≤ p := and.left
theorem prime.one_lt {p : ℕ} : prime p → 1 < p := prime.two_le
instance prime.one_lt' (p : ℕ) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := hp.one_lt
lemma prime.ne_one {p : ℕ} (hp : p.prime) : p ≠ 1 :=
ne.symm $ (ne_of_lt hp.one_lt)
theorem prime_def_lt {p : ℕ} : prime p ↔ 2 ≤ p ∧ ∀ m < p, m ∣ p → m = 1 :=
and_congr_right $ λ p2, forall_congr $ λ m,
⟨λ h l d, (h d).resolve_right (ne_of_lt l),
λ h d, (decidable.lt_or_eq_of_le $
le_of_dvd (le_of_succ_le p2) d).imp_left (λ l, h l d)⟩
theorem prime_def_lt' {p : ℕ} : prime p ↔ 2 ≤ p ∧ ∀ m, 2 ≤ m → m < p → ¬ m ∣ p :=
prime_def_lt.trans $ and_congr_right $ λ p2, forall_congr $ λ m,
⟨λ h m2 l d, not_lt_of_ge m2 ((h l d).symm ▸ dec_trivial),
λ h l d, begin
rcases m with _|_|m,
{ rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },
{ refl },
{ exact (h dec_trivial l).elim d }
end⟩
theorem prime_def_le_sqrt {p : ℕ} : prime p ↔ 2 ≤ p ∧
∀ m, 2 ≤ m → m ≤ sqrt p → ¬ m ∣ p :=
prime_def_lt'.trans $ and_congr_right $ λ p2,
⟨λ a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,
λ a, have ∀ {m k}, m ≤ k → 1 < m → p ≠ m * k, from
λ m k mk m1 e, a m m1
(le_sqrt.2 (e.symm ▸ mul_le_mul_left m mk)) ⟨k, e⟩,
λ m m2 l ⟨k, e⟩, begin
cases (le_total m k) with mk km,
{ exact this mk m2 e },
{ rw [mul_comm] at e,
refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,
rwa [one_mul, ← e] }
end⟩
/--
This instance is slower than the instance `decidable_prime` defined below,
but has the advantage that it works in the kernel.
If you need to prove that a particular number is prime, in any case
you should not use `dec_trivial`, but rather `by norm_num`, which is
much faster.
-/
def decidable_prime_1 (p : ℕ) : decidable (prime p) :=
decidable_of_iff' _ prime_def_lt'
local attribute [instance] decidable_prime_1
lemma prime.ne_zero {n : ℕ} (h : prime n) : n ≠ 0 :=
assume hn : n = 0,
have h2 : ¬ prime 0, from dec_trivial,
h2 (hn ▸ h)
theorem prime.pos {p : ℕ} (pp : prime p) : 0 < p :=
lt_of_succ_lt pp.one_lt
theorem not_prime_zero : ¬ prime 0 := dec_trivial
theorem not_prime_one : ¬ prime 1 := dec_trivial
theorem prime_two : prime 2 := dec_trivial
theorem prime_three : prime 3 := dec_trivial
theorem prime.pred_pos {p : ℕ} (pp : prime p) : 0 < pred p :=
lt_pred_iff.2 pp.one_lt
theorem succ_pred_prime {p : ℕ} (pp : prime p) : succ (pred p) = p :=
succ_pred_eq_of_pos pp.pos
theorem dvd_prime {p m : ℕ} (pp : prime p) : m ∣ p ↔ m = 1 ∨ m = p :=
⟨λ d, pp.2 m d, λ h, h.elim (λ e, e.symm ▸ one_dvd _) (λ e, e.symm ▸ dvd_refl _)⟩
theorem dvd_prime_two_le {p m : ℕ} (pp : prime p) (H : 2 ≤ m) : m ∣ p ↔ m = p :=
(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H
theorem prime.not_dvd_one {p : ℕ} (pp : prime p) : ¬ p ∣ 1
| d := (not_le_of_gt pp.one_lt) $ le_of_dvd dec_trivial d
theorem not_prime_mul {a b : ℕ} (a1 : 1 < a) (b1 : 1 < b) : ¬ prime (a * b) :=
λ h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $
by simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)
section min_fac
private lemma min_fac_lemma (n k : ℕ) (h : ¬ n < k * k) :
sqrt n - k < sqrt n + 2 - k :=
(nat.sub_lt_sub_right_iff $ le_sqrt.2 $ le_of_not_gt h).2 $
nat.lt_add_of_pos_right dec_trivial
def min_fac_aux (n : ℕ) : ℕ → ℕ | k :=
if h : n < k * k then n else
if k ∣ n then k else
have _, from min_fac_lemma n k h,
min_fac_aux (k + 2)
using_well_founded {rel_tac :=
λ _ _, `[exact ⟨_, measure_wf (λ k, sqrt n + 2 - k)⟩]}
/-- Returns the smallest prime factor of `n ≠ 1`. -/
def min_fac : ℕ → ℕ
| 0 := 2
| 1 := 1
| (n+2) := if 2 ∣ n then 2 else min_fac_aux (n + 2) 3
@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl
@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl
theorem min_fac_eq : ∀ n, min_fac n = if 2 ∣ n then 2 else min_fac_aux n 3
| 0 := rfl
| 1 := by simp [show 2≠1, from dec_trivial]; rw min_fac_aux; refl
| (n+2) :=
have 2 ∣ n + 2 ↔ 2 ∣ n, from
(nat.dvd_add_iff_left (by refl)).symm,
by simp [min_fac, this]; congr
private def min_fac_prop (n k : ℕ) :=
2 ≤ k ∧ k ∣ n ∧ ∀ m, 2 ≤ m → m ∣ n → k ≤ m
theorem min_fac_aux_has_prop {n : ℕ} (n2 : 2 ≤ n) (nd2 : ¬ 2 ∣ n) :
∀ k i, k = 2*i+3 → (∀ m, 2 ≤ m → m ∣ n → k ≤ m) → min_fac_prop n (min_fac_aux n k)
| k := λ i e a, begin
rw min_fac_aux,
by_cases h : n < k*k; simp [h],
{ have pp : prime n :=
prime_def_le_sqrt.2 ⟨n2, λ m m2 l d,
not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)⟩,
from ⟨n2, dvd_refl _, λ m m2 d, le_of_eq
((dvd_prime_two_le pp m2).1 d).symm⟩ },
have k2 : 2 ≤ k, { subst e, exact dec_trivial },
by_cases dk : k ∣ n; simp [dk],
{ exact ⟨k2, dk, a⟩ },
{ refine have _, from min_fac_lemma n k h,
min_fac_aux_has_prop (k+2) (i+1)
(by simp [e, left_distrib]) (λ m m2 d, _),
cases nat.eq_or_lt_of_le (a m m2 d) with me ml,
{ subst me, contradiction },
apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,
rw [← me, e] at d, change 2 * (i + 2) ∣ n at d,
have := dvd_of_mul_right_dvd d, contradiction }
end
using_well_founded {rel_tac :=
λ _ _, `[exact ⟨_, measure_wf (λ k, sqrt n + 2 - k)⟩]}
theorem min_fac_has_prop {n : ℕ} (n1 : n ≠ 1) :
min_fac_prop n (min_fac n) :=
begin
by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},
have n2 : 2 ≤ n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },
simp [min_fac_eq],
by_cases d2 : 2 ∣ n; simp [d2],
{ exact ⟨le_refl _, d2, λ k k2 d, k2⟩ },
{ refine min_fac_aux_has_prop n2 d2 3 0 rfl
(λ m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),
exact λ e, e.symm ▸ d }
end
theorem min_fac_dvd (n : ℕ) : min_fac n ∣ n :=
by by_cases n1 : n = 1;
[exact n1.symm ▸ dec_trivial, exact (min_fac_has_prop n1).2.1]
theorem min_fac_prime {n : ℕ} (n1 : n ≠ 1) : prime (min_fac n) :=
let ⟨f2, fd, a⟩ := min_fac_has_prop n1 in
prime_def_lt'.2 ⟨f2, λ m m2 l d, not_le_of_gt l (a m m2 (dvd_trans d fd))⟩
theorem min_fac_le_of_dvd {n : ℕ} : ∀ {m : ℕ}, 2 ≤ m → m ∣ n → min_fac n ≤ m :=
by by_cases n1 : n = 1;
[exact λ m m2 d, n1.symm ▸ le_trans dec_trivial m2,
exact (min_fac_has_prop n1).2.2]
theorem min_fac_pos (n : ℕ) : 0 < min_fac n :=
by by_cases n1 : n = 1;
[exact n1.symm ▸ dec_trivial, exact (min_fac_prime n1).pos]
theorem min_fac_le {n : ℕ} (H : 0 < n) : min_fac n ≤ n :=
le_of_dvd H (min_fac_dvd n)
theorem prime_def_min_fac {p : ℕ} : prime p ↔ 2 ≤ p ∧ min_fac p = p :=
⟨λ pp, ⟨pp.two_le,
let ⟨f2, fd, a⟩ := min_fac_has_prop $ ne_of_gt pp.one_lt in
((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)⟩,
λ ⟨p2, e⟩, e ▸ min_fac_prime (ne_of_gt p2)⟩
/--
This instance is faster in the virtual machine than `decidable_prime_1`,
but slower in the kernel.
If you need to prove that a particular number is prime, in any case
you should not use `dec_trivial`, but rather `by norm_num`, which is
much faster.
-/
instance decidable_prime (p : ℕ) : decidable (prime p) :=
decidable_of_iff' _ prime_def_min_fac
theorem not_prime_iff_min_fac_lt {n : ℕ} (n2 : 2 ≤ n) : ¬ prime n ↔ min_fac n < n :=
(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $
(lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm
lemma min_fac_le_div {n : ℕ} (pos : 0 < n) (np : ¬ prime n) : min_fac n ≤ n / min_fac n :=
match min_fac_dvd n with
| ⟨0, h0⟩ := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial
| ⟨1, h1⟩ :=
begin
rw mul_one at h1,
rw [prime_def_min_fac, not_and_distrib, ← h1, eq_self_iff_true, not_true, or_false, not_le] at np,
rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]
end
| ⟨(x+2), hx⟩ :=
begin
conv_rhs { congr, rw hx },
rw [nat.mul_div_cancel_left _ (min_fac_pos _)],
exact min_fac_le_of_dvd dec_trivial ⟨min_fac n, by rwa mul_comm⟩
end
end
/--
The square of the smallest prime factor of a composite number `n` is at most `n`.
-/
lemma min_fac_sq_le_self {n : ℕ} (w : 0 < n) (h : ¬ prime n) : (min_fac n)^2 ≤ n :=
have t : (min_fac n) ≤ (n/min_fac n) := min_fac_le_div w h,
calc
(min_fac n)^2 = (min_fac n) * (min_fac n) : pow_two (min_fac n)
... ≤ (n/min_fac n) * (min_fac n) : mul_le_mul_right (min_fac n) t
... ≤ n : div_mul_le_self n (min_fac n)
@[simp]
lemma min_fac_eq_one_iff {n : ℕ} : min_fac n = 1 ↔ n = 1 :=
begin
split,
{ intro h,
by_contradiction,
have := min_fac_prime a,
rw h at this,
exact not_prime_one this, },
{ rintro rfl, refl, }
end
@[simp]
lemma min_fac_eq_two_iff (n : ℕ) : min_fac n = 2 ↔ 2 ∣ n :=
begin
split,
{ intro h,
convert min_fac_dvd _,
rw h, },
{ intro h,
have ub := min_fac_le_of_dvd (le_refl 2) h,
have lb := min_fac_pos n,
-- If `interval_cases` and `norm_num` were already available here,
-- this would be easy and pleasant.
-- But they aren't, so it isn't.
cases h : n.min_fac with m,
{ rw h at lb, cases lb, },
{ cases m with m,
{ simp at h, subst h, cases h with n h, cases n; cases h, },
{ cases m with m,
{ refl, },
{ rw h at ub,
cases ub with _ ub, cases ub with _ ub, cases ub, } } } }
end
end min_fac
theorem exists_dvd_of_not_prime {n : ℕ} (n2 : 2 ≤ n) (np : ¬ prime n) :
∃ m, m ∣ n ∧ m ≠ 1 ∧ m ≠ n :=
⟨min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,
ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np⟩
theorem exists_dvd_of_not_prime2 {n : ℕ} (n2 : 2 ≤ n) (np : ¬ prime n) :
∃ m, m ∣ n ∧ 2 ≤ m ∧ m < n :=
⟨min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,
(not_prime_iff_min_fac_lt n2).1 np⟩
theorem exists_prime_and_dvd {n : ℕ} (n2 : 2 ≤ n) : ∃ p, prime p ∧ p ∣ n :=
⟨min_fac n, min_fac_prime (ne_of_gt n2), min_fac_dvd _⟩
/-- Euclid's theorem. There exist infinitely many prime numbers.
Here given in the form: for every `n`, there exists a prime number `p ≥ n`. -/
theorem exists_infinite_primes (n : ℕ) : ∃ p, n ≤ p ∧ prime p :=
let p := min_fac (fact n + 1) in
have f1 : fact n + 1 ≠ 1, from ne_of_gt $ succ_lt_succ $ fact_pos _,
have pp : prime p, from min_fac_prime f1,
have np : n ≤ p, from le_of_not_ge $ λ h,
have h₁ : p ∣ fact n, from dvd_fact (min_fac_pos _) h,
have h₂ : p ∣ 1, from (nat.dvd_add_iff_right h₁).2 (min_fac_dvd _),
pp.not_dvd_one h₂,
⟨p, np, pp⟩
lemma prime.eq_two_or_odd {p : ℕ} (hp : prime p) : p = 2 ∨ p % 2 = 1 :=
(nat.mod_two_eq_zero_or_one p).elim
(λ h, or.inl ((hp.2 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)
or.inr
theorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=
div_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt
/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/
def factors : ℕ → list ℕ
| 0 := []
| 1 := []
| n@(k+2) :=
let m := min_fac n in have n / m < n := factors_lemma,
m :: factors (n / m)
lemma mem_factors : ∀ {n p}, p ∈ factors n → prime p
| 0 := λ p, false.elim
| 1 := λ p, false.elim
| n@(k+2) := λ p h,
let m := min_fac n in have n / m < n := factors_lemma,
have h₁ : p = m ∨ p ∈ (factors (n / m)) :=
(list.mem_cons_iff _ _ _).1 h,
or.cases_on h₁ (λ h₂, h₂.symm ▸ min_fac_prime dec_trivial)
mem_factors
lemma prod_factors : ∀ {n}, 0 < n → list.prod (factors n) = n
| 0 := (lt_irrefl _).elim
| 1 := λ h, rfl
| n@(k+2) := λ h,
let m := min_fac n in have n / m < n := factors_lemma,
show list.prod (m :: factors (n / m)) = n, from
have h₁ : 0 < n / m :=
nat.pos_of_ne_zero $ λ h,
have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,
by rw zero_mul at this; exact (show k + 2 ≠ 0, from dec_trivial) this,
by rw [list.prod_cons, prod_factors h₁, nat.mul_div_cancel' (min_fac_dvd _)]
lemma factors_prime {p : ℕ} (hp : nat.prime p) : p.factors = [p] :=
begin
have : p = (p - 2) + 2 := (nat.sub_eq_iff_eq_add hp.1).mp rfl,
rw [this, nat.factors],
simp only [eq.symm this],
have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,
split,
{ exact this, },
{ simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },
end
theorem prime.coprime_iff_not_dvd {p n : ℕ} (pp : prime p) : coprime p n ↔ ¬ p ∣ n :=
⟨λ co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),
λ nd, coprime_of_dvd $ λ m m2 mp, ((dvd_prime_two_le pp m2).1 mp).symm ▸ nd⟩
theorem prime.dvd_iff_not_coprime {p n : ℕ} (pp : prime p) : p ∣ n ↔ ¬ coprime p n :=
iff_not_comm.2 pp.coprime_iff_not_dvd
theorem prime.not_coprime_iff_dvd {m n : ℕ} :
¬ coprime m n ↔ ∃p, prime p ∧ p ∣ m ∧ p ∣ n :=
begin
apply iff.intro,
{ intro h,
exact ⟨min_fac (gcd m n), min_fac_prime h,
(dvd.trans (min_fac_dvd (gcd m n)) (gcd_dvd_left m n)),
(dvd.trans (min_fac_dvd (gcd m n)) (gcd_dvd_right m n))⟩ },
{ intro h,
cases h with p hp,
apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }
end
theorem prime.dvd_mul {p m n : ℕ} (pp : prime p) : p ∣ m * n ↔ p ∣ m ∨ p ∣ n :=
⟨λ H, or_iff_not_imp_left.2 $ λ h,
(pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,
or.rec (λ h, dvd_mul_of_dvd_left h _) (λ h, dvd_mul_of_dvd_right h _)⟩
theorem prime.not_dvd_mul {p m n : ℕ} (pp : prime p)
(Hm : ¬ p ∣ m) (Hn : ¬ p ∣ n) : ¬ p ∣ m * n :=
mt pp.dvd_mul.1 $ by simp [Hm, Hn]
theorem prime.dvd_of_dvd_pow {p m n : ℕ} (pp : prime p) (h : p ∣ m^n) : p ∣ m :=
by induction n with n IH;
[exact pp.not_dvd_one.elim h,
exact (pp.dvd_mul.1 h).elim IH id]
lemma prime.pow_not_prime {x n : ℕ} (hn : 2 ≤ n) : ¬ (x ^ n).prime :=
λ hp, (hp.2 x $ dvd_trans ⟨x, nat.pow_two _⟩ (nat.pow_dvd_pow _ hn)).elim
(λ hx1, hp.ne_one $ hx1.symm ▸ nat.one_pow _)
(λ hxn, lt_irrefl x $ calc x = x ^ 1 : (nat.pow_one _).symm
... < x ^ n : nat.pow_right_strict_mono (hxn.symm ▸ hp.two_le) hn
... = x : hxn.symm)
lemma prime.mul_eq_prime_pow_two_iff {x y p : ℕ} (hp : p.prime) (hx : x ≠ 1) (hy : y ≠ 1) :
x * y = p ^ 2 ↔ x = p ∧ y = p :=
⟨λ h, have pdvdxy : p ∣ x * y, by rw h; simp [nat.pow_two],
begin
wlog := hp.dvd_mul.1 pdvdxy using x y,
cases case with a ha,
have hap : a ∣ p, from ⟨y, by rwa [ha, nat.pow_two,
mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at h⟩,
exact ((nat.dvd_prime hp).1 hap).elim
(λ _, by clear_aux_decl; simp [*, nat.pow_two, nat.mul_right_inj hp.pos] at *
{contextual := tt})
(λ _, by clear_aux_decl; simp [*, nat.pow_two, mul_comm, mul_assoc,
nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *
{contextual := tt})
end,
λ ⟨h₁, h₂⟩, h₁.symm ▸ h₂.symm ▸ (nat.pow_two _).symm⟩
lemma prime.dvd_fact : ∀ {n p : ℕ} (hp : prime p), p ∣ n.fact ↔ p ≤ n
| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)
| (n+1) p hp := begin
rw [fact_succ, hp.dvd_mul, prime.dvd_fact hp],
exact ⟨λ h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,
λ h, (_root_.lt_or_eq_of_le h).elim (or.inr ∘ le_of_lt_succ)
(λ h, or.inl $ by rw h)⟩
end
theorem prime.coprime_pow_of_not_dvd {p m a : ℕ} (pp : prime p) (h : ¬ p ∣ a) : coprime a (p^m) :=
(pp.coprime_iff_not_dvd.2 h).symm.pow_right _
theorem coprime_primes {p q : ℕ} (pp : prime p) (pq : prime q) : coprime p q ↔ p ≠ q :=
pp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le
theorem coprime_pow_primes {p q : ℕ} (n m : ℕ) (pp : prime p) (pq : prime q) (h : p ≠ q) :
coprime (p^n) (q^m) :=
((coprime_primes pp pq).2 h).pow _ _
theorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : ℕ) : coprime p i ∨ p ∣ i :=
by rw [pp.dvd_iff_not_coprime]; apply em
theorem dvd_prime_pow {p : ℕ} (pp : prime p) {m i : ℕ} : i ∣ (p^m) ↔ ∃ k ≤ m, i = p^k :=
begin
induction m with m IH generalizing i, {simp [pow_succ, le_zero_iff] at *},
by_cases p ∣ i,
{ cases h with a e, subst e,
rw [nat.pow_succ, mul_comm (p^m) p, nat.mul_dvd_mul_iff_left pp.pos, IH],
split; intro h; rcases h with ⟨k, h, e⟩,
{ exact ⟨succ k, succ_le_succ h, by rw [mul_comm, e]; refl⟩ },
cases k with k,
{ apply pp.not_dvd_one.elim,
simp at e, rw ← e, apply dvd_mul_right },
{ refine ⟨k, le_of_succ_le_succ h, _⟩,
rwa [mul_comm, nat.pow_succ, nat.mul_left_inj pp.pos] at e } },
{ split; intro d,
{ rw (pp.coprime_pow_of_not_dvd h).eq_one_of_dvd d,
exact ⟨0, zero_le _, rfl⟩ },
{ rcases d with ⟨k, l, e⟩,
rw e, exact pow_dvd_pow _ l } }
end
/--
If `p` is prime,
and `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`
then `a = p^(k+1)`.
-/
lemma eq_prime_pow_of_dvd_least_prime_pow
{a p k : ℕ} (pp : prime p) (h₁ : ¬(a ∣ p^k)) (h₂ : a ∣ p^(k+1)) :
a = p^(k+1) :=
begin
obtain ⟨l, ⟨h, rfl⟩⟩ := (dvd_prime_pow pp).1 h₂,
congr,
exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h₁)),
end
section
open list
lemma mem_list_primes_of_dvd_prod {p : ℕ} (hp : prime p) :
∀ {l : list ℕ}, (∀ p ∈ l, prime p) → p ∣ prod l → p ∈ l
| [] := λ h₁ h₂, absurd h₂ (prime.not_dvd_one hp)
| (q :: l) := λ h₁ h₂,
have h₃ : p ∣ q * prod l := @prod_cons _ _ l q ▸ h₂,
have hq : prime q := h₁ q (mem_cons_self _ _),
or.cases_on ((prime.dvd_mul hp).1 h₃)
(λ h, by rw [prime.dvd_iff_not_coprime hp, coprime_primes hp hq, ne.def, not_not] at h;
exact h ▸ mem_cons_self _ _)
(λ h, have hl : ∀ p ∈ l, prime p := λ p hlp, h₁ p ((mem_cons_iff _ _ _).2 (or.inr hlp)),
(mem_cons_iff _ _ _).2 (or.inr (mem_list_primes_of_dvd_prod hl h)))
lemma mem_factors_iff_dvd {n p : ℕ} (hn : 0 < n) (hp : prime p) : p ∈ factors n ↔ p ∣ n :=
⟨λ h, prod_factors hn ▸ list.dvd_prod h,
λ h, mem_list_primes_of_dvd_prod hp (@mem_factors n) ((prod_factors hn).symm ▸ h)⟩
lemma perm_of_prod_eq_prod : ∀ {l₁ l₂ : list ℕ}, prod l₁ = prod l₂ →
(∀ p ∈ l₁, prime p) → (∀ p ∈ l₂, prime p) → l₁ ~ l₂
| [] [] _ _ _ := perm.nil
| [] (a :: l) h₁ h₂ h₃ :=
have ha : a ∣ 1 := @prod_nil ℕ _ ▸ h₁.symm ▸ (@prod_cons _ _ l a).symm ▸ dvd_mul_right _ _,
absurd ha (prime.not_dvd_one (h₃ a (mem_cons_self _ _)))
| (a :: l) [] h₁ h₂ h₃ :=
have ha : a ∣ 1 := @prod_nil ℕ _ ▸ h₁ ▸ (@prod_cons _ _ l a).symm ▸ dvd_mul_right _ _,
absurd ha (prime.not_dvd_one (h₂ a (mem_cons_self _ _)))
| (a :: l₁) (b :: l₂) h hl₁ hl₂ :=
have hl₁' : ∀ p ∈ l₁, prime p := λ p hp, hl₁ p (mem_cons_of_mem _ hp),
have hl₂' : ∀ p ∈ (b :: l₂).erase a, prime p := λ p hp, hl₂ p (mem_of_mem_erase hp),
have ha : a ∈ (b :: l₂) := mem_list_primes_of_dvd_prod (hl₁ a (mem_cons_self _ _)) hl₂
(h ▸ by rw prod_cons; exact dvd_mul_right _ _),
have hb : b :: l₂ ~ a :: (b :: l₂).erase a := perm_cons_erase ha,
have hl : prod l₁ = prod ((b :: l₂).erase a) :=
(nat.mul_right_inj (prime.pos (hl₁ a (mem_cons_self _ _)))).1 $
by rwa [← prod_cons, ← prod_cons, ← hb.prod_eq],
perm.trans ((perm_of_prod_eq_prod hl hl₁' hl₂').cons _) hb.symm
lemma factors_unique {n : ℕ} {l : list ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, prime p) : l ~ factors n :=
have hn : 0 < n := nat.pos_of_ne_zero $ λ h, begin
rw h at *, clear h,
induction l with a l hi,
{ exact absurd h₁ dec_trivial },
{ rw prod_cons at h₁,
exact nat.mul_ne_zero (ne_of_lt (prime.pos (h₂ a (mem_cons_self _ _)))).symm
(hi (λ p hp, h₂ p (mem_cons_of_mem _ hp))) h₁ }
end,
perm_of_prod_eq_prod (by rwa prod_factors hn) h₂ (@mem_factors _)
end
lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : prime p) {m n k l : ℕ}
(hpm : p ^ k ∣ m) (hpn : p ^ l ∣ n) (hpmn : p ^ (k+l+1) ∣ m*n) :
p ^ (k+1) ∣ m ∨ p ^ (l+1) ∣ n :=
have hpd : p^(k+l) * p ∣ m*n, from hpmn,
have hpd2 : p ∣ (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,
have hpd3 : p ∣ (m*n) / (p^k * p^l), by simpa [nat.pow_add] using hpd2,
have hpd4 : p ∣ (m / p^k) * (n / p^l), by simpa [nat.div_mul_div hpm hpn] using hpd3,
have hpd5 : p ∣ (m / p^k) ∨ p ∣ (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,
show p^k*p ∣ m ∨ p^l*p ∣ n, from
hpd5.elim
(assume : p ∣ m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)
(assume : p ∣ n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)
/-- The type of prime numbers -/
def primes := {p : ℕ // p.prime}
namespace primes
instance : has_repr nat.primes := ⟨λ p, repr p.val⟩
instance : inhabited primes := ⟨⟨2, prime_two⟩⟩
instance coe_nat : has_coe nat.primes ℕ := ⟨subtype.val⟩
theorem coe_nat_inj (p q : nat.primes) : (p : ℕ) = (q : ℕ) → p = q :=
λ h, subtype.eq h
end primes
instance monoid.prime_pow {α : Type*} [monoid α] : has_pow α primes := ⟨λ x p, x^p.val⟩
end nat
|
65bbde3e03ad08bffdd423383b094e72ecd9d206 | 0845ae2ca02071debcfd4ac24be871236c01784f | /tests/lean/run/handlers.lean | 24014be6f562877ad0c238647a8f7e1da82d87f5 | [
"Apache-2.0"
] | permissive | GaloisInc/lean4 | 74c267eb0e900bfaa23df8de86039483ecbd60b7 | 228ddd5fdcd98dd4e9c009f425284e86917938aa | refs/heads/master | 1,643,131,356,301 | 1,562,715,572,000 | 1,562,715,572,000 | 192,390,898 | 0 | 0 | null | 1,560,792,750,000 | 1,560,792,749,000 | null | UTF-8 | Lean | false | false | 4,787 | lean | import init.io
#exit
/- Based on https://github.com/slindley/effect-handlers -/
def N := 100 -- Default number of interations for testing
namespace handlers
class isOp (op : Type → Type → Type*) := mk {} ::
(return : Type → Type → Type)
class handler (h : Type) := mk {} ::
(Result : Type)
class handles (h : Type) [handler h] (op : Type → Type → Type*) [isOp op] (e : outParam Type) :=
(clause {} {u} : op e u → (isOp.return op e u → h → handler.Result h) → h → handler.Result h)
structure comp (h : Type*) [handler h] (α : Type*) :=
(handle : (α → h → handler.Result h) → h → handler.Result h)
@[inline] def comp.do {h e u} {op : Type → Type → Type*} [isOp op] [handler h] [handles h op e] (f : op e u) : comp h (isOp.return op e u) :=
⟨fun k h => r handles.clause f k h⟩
instance (h) [handler h] : Monad (comp h) :=
{ pure := fun α v => ⟨fun k h => k v h⟩,
bind := fun α β ⟨c⟩ f => ⟨fun k h => c (fun x h' => (f x).handle k h') h⟩ }
inductive Put : Type → Type → Type 1
| mk {σ : Type} (s : σ) : Put σ Unit
instance Put.op : isOp Put := ⟨fun _ _ => Unit⟩
inductive Get : Type → Type → Type 1
| mk {σ : Type} : Get σ Unit
instance Get.op : isOp Get := ⟨fun σ _ => σ⟩
@[inline] def get {h σ } [handler h] [handles h Get σ] : comp h σ :=
comp.do Get.mk
@[inline] def put {h σ} [handler h] [handles h Put σ] (s : σ) : comp h Unit :=
comp.do (Put.mk s)
instance (h σ) [handler h] [handles h Get σ] [handles h Put σ] : MonadState σ (comp h) :=
{ get := get,
put := put,
modify := fun f => f <$> get >>= put }
structure stateH (h : Type) (σ : Type) (α : Type) := mk {} ::
(State : σ)
instance (h σ α) [handler h] : handler (stateH h σ α) := ⟨comp h α⟩
instance stateHHandleGet (h σ α) [handler h] : handles (stateH h σ α) Get σ :=
⟨fun _ _ k ⟨st⟩ => k st ⟨st⟩⟩
instance stateHHandlePut (h σ α) [handler h] : handles (stateH h σ α) Put σ :=
⟨fun _ op k _ => by cases op with _ st'; apply k () ⟨st'⟩⟩
instance stateHForward (h op σ α) [handler h] [isOp op] [handles h op α] : handles (stateH h σ α) op α :=
⟨fun _ op k hi => comp.do op >>= (fun x => k x hi)⟩
@[inline] def handleState {h σ α} [handler h] (st : σ) (x : comp (stateH h σ α) α) : comp h α :=
x.handle (fun a _ => (pure a : comp h α)) ⟨st⟩
inductive Read : Type → Type → Type 1
| mk {ρ : Type} : Read ρ Unit
instance Read.op : isOp Read := ⟨fun ρ _ => ρ⟩
@[inline] def read {h ρ} [handler h] [handles h Read ρ] : comp h ρ :=
comp.do Read.mk
instance (h ρ) [handler h] [handles h Read ρ] : MonadReader ρ (comp h) :=
⟨read⟩
structure readH (h : Type) (ρ : Type) (α : Type) := mk {} ::
(env : ρ)
instance readH.handler (h ρ α) [handler h] : handler (readH h ρ α) := ⟨comp h α⟩
instance readHHandleRead (h ρ α) [handler h] : handles (readH h ρ α) Read ρ :=
⟨fun _ _ k ⟨env⟩ => k env ⟨env⟩⟩
instance readHForward (h op ρ α) [handler h] [isOp op] [handles h op α] : handles (readH h ρ α) op α :=
⟨fun _ op k hi => comp.do op >>= (fun x => k x hi)⟩
@[inline] def handleRead {h ρ α} [handler h] (env : ρ) (x : comp (readH h ρ α) α) : comp h α :=
x.handle (fun a _ => (pure a : comp h α)) ⟨env⟩
structure pureH (α : Type) := mk {}
instance pureH.handler (α) : handler (pureH α) := ⟨α⟩
@[inline] def handlePure {α} (x : comp (pureH α) α) : α :=
x.handle (fun a _ => a) ⟨⟩
end handlers
open handlers
section benchmarks
def State.run {σ α : Type*} : State σ α → σ → α × σ := StateT.run
def benchStateClassy {m : Type → Type*} [Monad m] [MonadState ℕ m] : ℕ → m ℕ
| 0 := get
| (Nat.succ n) := modify (+n) >> benchStateClassy n
setOption profiler True
#eval State.run (benchStateClassy N) 0
#eval handlePure $ handleState 0 (benchStateClassy N)
#eval State.run (ReaderT.run (ReaderT.run (benchStateClassy N) 0) 0) 0
#eval handlePure $ handleState 0 $ handleRead 0 $ handleRead 0 (benchStateClassy N)
-- left-associated binds lead to quadratic run time (section 2.6)
def benchStateClassy' {m : Type → Type*} [Monad m] [MonadState ℕ m] : ℕ → m ℕ
| 0 := get
| (Nat.succ n) := benchStateClassy' n <* modify (+n)
#eval handlePure $ handleState 0 (benchStateClassy' (N/100))
#eval handlePure $ handleState 0 (benchStateClassy' (N/20))
#eval handlePure $ handleState 0 (benchStateClassy' (N/10))
def benchStateT : ℕ → State ℕ ℕ
| 0 := get
| (Nat.succ n) := modify (+n) >> benchStateT n
#eval State.run (benchStateT N) 0
def benchStateH : ℕ → comp (stateH (pureH ℕ) ℕ ℕ) ℕ
| 0 := handlers.get
| (Nat.succ n) := modify (+n) >> benchStateH n
#eval handlePure $ handleState 0 (benchStateH N)
end benchmarks
|
a86824df7002e6eb9adc875110a528c8e49115f3 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/order/omega_complete_partial_order_auto.lean | b5025437b56896a43888fbd84a8efc3a58b575d1 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 30,079 | lean | /-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.pfun
import Mathlib.order.preorder_hom
import Mathlib.tactic.wlog
import Mathlib.tactic.monotonicity.default
import Mathlib.PostPort
universes u_1 u_2 u_5 u_6 u_3 u v l u_4
namespace Mathlib
/-!
# Omega Complete Partial Orders
An omega-complete partial order is a partial order with a supremum
operation on increasing sequences indexed by natural numbers (which we
call `ωSup`). In this sense, it is strictly weaker than join complete
semi-lattices as only ω-sized totally ordered sets have a supremum.
The concept of an omega-complete partial order (ωCPO) is useful for the
formalization of the semantics of programming languages. Its notion of
supremum helps define the meaning of recursive procedures.
## Main definitions
* class `omega_complete_partial_order`
* `ite`, `map`, `bind`, `seq` as continuous morphisms
## Instances of `omega_complete_partial_order`
* `roption`
* every `complete_lattice`
* pi-types
* product types
* `monotone_hom`
* `continuous_hom` (with notation →𝒄)
* an instance of `omega_complete_partial_order (α →𝒄 β)`
* `continuous_hom.of_fun`
* `continuous_hom.of_mono`
* continuous functions:
* `id`
* `ite`
* `const`
* `roption.bind`
* `roption.map`
* `roption.seq`
## References
* [G. Markowsky, *Chain-complete posets and directed sets with applications*, https://doi.org/10.1007/BF02485815][markowsky]
* [J. M. Cadiou and Zohar Manna, *Recursive definitions of partial functions and their computations.*, https://doi.org/10.1145/942580.807072][cadiou]
* [Carl A. Gunter, *Semantics of Programming Languages: Structures and Techniques*, ISBN: 0262570955][gunter]
-/
namespace preorder_hom
/-- The constant function, as a monotone function. -/
@[simp] theorem const_to_fun (α : Type u_1) {β : Type u_2} [preorder α] [preorder β] (f : β) :
∀ (ᾰ : α), coe_fn (const α f) ᾰ = function.const α f ᾰ :=
fun (ᾰ : α) => Eq.refl (coe_fn (const α f) ᾰ)
/-- The diagonal function, as a monotone function. -/
def prod.diag {α : Type u_1} [preorder α] : α →ₘ α × α := mk (fun (x : α) => (x, x)) sorry
/-- The `prod.map` function, as a monotone function. -/
@[simp] theorem prod.map_to_fun {α : Type u_1} {β : Type u_2} [preorder α] [preorder β]
{α' : Type u_5} {β' : Type u_6} [preorder α'] [preorder β'] (f : α →ₘ β) (f' : α' →ₘ β')
(x : α × α') : coe_fn (prod.map f f') x = prod.map (⇑f) (⇑f') x :=
Eq.refl (coe_fn (prod.map f f') x)
/-- The `prod.fst` projection, as a monotone function. -/
def prod.fst {α : Type u_1} {β : Type u_2} [preorder α] [preorder β] : α × β →ₘ α :=
mk prod.fst sorry
/-- The `prod.snd` projection, as a monotone function. -/
def prod.snd {α : Type u_1} {β : Type u_2} [preorder α] [preorder β] : α × β →ₘ β :=
mk prod.snd sorry
/-- The `prod` constructor, as a monotone function. -/
@[simp] theorem prod.zip_to_fun {α : Type u_1} {β : Type u_2} {γ : Type u_3} [preorder α]
[preorder β] [preorder γ] (f : α →ₘ β) (g : α →ₘ γ) :
∀ (ᾰ : α), coe_fn (prod.zip f g) ᾰ = (coe_fn f ᾰ, coe_fn g ᾰ) :=
fun (ᾰ : α) => Eq.refl (coe_fn f ᾰ, coe_fn g ᾰ)
/-- `roption.bind` as a monotone function -/
@[simp] theorem bind_to_fun {α : Type u_1} [preorder α] {β : Type u_2} {γ : Type u_2}
(f : α →ₘ roption β) (g : α →ₘ β → roption γ) (x : α) :
coe_fn (bind f g) x = coe_fn f x >>= coe_fn g x :=
Eq.refl (coe_fn (bind f g) x)
end preorder_hom
namespace omega_complete_partial_order
/-- A chain is a monotonically increasing sequence.
See the definition on page 114 of [gunter]. -/
def chain (α : Type u) [preorder α] := ℕ →ₘ α
namespace chain
protected instance has_coe_to_fun {α : Type u} [preorder α] : has_coe_to_fun (chain α) :=
infer_instance
protected instance inhabited {α : Type u} [preorder α] [Inhabited α] : Inhabited (chain α) :=
{ default := preorder_hom.mk (fun (_x : ℕ) => Inhabited.default) sorry }
protected instance has_mem {α : Type u} [preorder α] : has_mem α (chain α) :=
has_mem.mk fun (a : α) (c : ℕ →ₘ α) => ∃ (i : ℕ), a = coe_fn c i
protected instance has_le {α : Type u} [preorder α] : HasLessEq (chain α) :=
{ LessEq := fun (x y : chain α) => ∀ (i : ℕ), ∃ (j : ℕ), coe_fn x i ≤ coe_fn y j }
/-- `map` function for `chain` -/
@[simp] theorem map_to_fun {α : Type u} {β : Type v} [preorder α] [preorder β] (c : chain α)
(f : α →ₘ β) : ∀ (ᾰ : ℕ), coe_fn (map c f) ᾰ = coe_fn f (coe_fn c ᾰ) :=
fun (ᾰ : ℕ) => Eq.refl (coe_fn f (coe_fn c ᾰ))
theorem mem_map {α : Type u} {β : Type v} [preorder α] [preorder β] (c : chain α) {f : α →ₘ β}
(x : α) : x ∈ c → coe_fn f x ∈ map c f :=
sorry
theorem exists_of_mem_map {α : Type u} {β : Type v} [preorder α] [preorder β] (c : chain α)
{f : α →ₘ β} {b : β} : b ∈ map c f → ∃ (a : α), a ∈ c ∧ coe_fn f a = b :=
sorry
theorem mem_map_iff {α : Type u} {β : Type v} [preorder α] [preorder β] (c : chain α) {f : α →ₘ β}
{b : β} : b ∈ map c f ↔ ∃ (a : α), a ∈ c ∧ coe_fn f a = b :=
sorry
@[simp] theorem map_id {α : Type u} [preorder α] (c : chain α) : map c preorder_hom.id = c :=
preorder_hom.comp_id c
theorem map_comp {α : Type u} {β : Type v} {γ : Type u_1} [preorder α] [preorder β] [preorder γ]
(c : chain α) {f : α →ₘ β} (g : β →ₘ γ) : map (map c f) g = map c (preorder_hom.comp g f) :=
rfl
theorem map_le_map {α : Type u} {β : Type v} [preorder α] [preorder β] (c : chain α) {f : α →ₘ β}
{g : α →ₘ β} (h : f ≤ g) : map c f ≤ map c g :=
sorry
/-- `chain.zip` pairs up the elements of two chains that have the same index -/
@[simp] theorem zip_to_fun {α : Type u} {β : Type v} [preorder α] [preorder β] (c₀ : chain α)
(c₁ : chain β) : ∀ (ᾰ : ℕ), coe_fn (zip c₀ c₁) ᾰ = (coe_fn c₀ ᾰ, coe_fn c₁ ᾰ) :=
fun (ᾰ : ℕ) => Eq.refl (coe_fn c₀ ᾰ, coe_fn c₁ ᾰ)
end chain
end omega_complete_partial_order
/-- An omega-complete partial order is a partial order with a supremum
operation on increasing sequences indexed by natural numbers (which we
call `ωSup`). In this sense, it is strictly weaker than join complete
semi-lattices as only ω-sized totally ordered sets have a supremum.
See the definition on page 114 of [gunter]. -/
class omega_complete_partial_order (α : Type u_1) extends partial_order α where
ωSup : omega_complete_partial_order.chain α → α
le_ωSup : ∀ (c : omega_complete_partial_order.chain α) (i : ℕ), coe_fn c i ≤ ωSup c
ωSup_le :
∀ (c : omega_complete_partial_order.chain α) (x : α), (∀ (i : ℕ), coe_fn c i ≤ x) → ωSup c ≤ x
namespace omega_complete_partial_order
/-- Transfer a `omega_complete_partial_order` on `β` to a `omega_complete_partial_order` on `α` using
a strictly monotone function `f : β →ₘ α`, a definition of ωSup and a proof that `f` is continuous
with regard to the provided `ωSup` and the ωCPO on `α`. -/
protected def lift {α : Type u} {β : Type v} [omega_complete_partial_order α] [partial_order β]
(f : β →ₘ α) (ωSup₀ : chain β → β) (h : ∀ (x y : β), coe_fn f x ≤ coe_fn f y → x ≤ y)
(h' : ∀ (c : chain β), coe_fn f (ωSup₀ c) = ωSup (chain.map c f)) :
omega_complete_partial_order β :=
mk ωSup₀ sorry sorry
theorem le_ωSup_of_le {α : Type u} [omega_complete_partial_order α] {c : chain α} {x : α} (i : ℕ)
(h : x ≤ coe_fn c i) : x ≤ ωSup c :=
le_trans h (le_ωSup c i)
theorem ωSup_total {α : Type u} [omega_complete_partial_order α] {c : chain α} {x : α}
(h : ∀ (i : ℕ), coe_fn c i ≤ x ∨ x ≤ coe_fn c i) : ωSup c ≤ x ∨ x ≤ ωSup c :=
sorry
theorem ωSup_le_ωSup_of_le {α : Type u} [omega_complete_partial_order α] {c₀ : chain α}
{c₁ : chain α} (h : c₀ ≤ c₁) : ωSup c₀ ≤ ωSup c₁ :=
ωSup_le c₀ (ωSup c₁)
fun (i : ℕ) =>
Exists.rec_on (h i) fun (j : ℕ) (h : coe_fn c₀ i ≤ coe_fn c₁ j) => le_trans h (le_ωSup c₁ j)
theorem ωSup_le_iff {α : Type u} [omega_complete_partial_order α] (c : chain α) (x : α) :
ωSup c ≤ x ↔ ∀ (i : ℕ), coe_fn c i ≤ x :=
{ mp := fun (ᾰ : ωSup c ≤ x) (i : ℕ) => le_trans (le_ωSup c i) ᾰ,
mpr := fun (ᾰ : ∀ (i : ℕ), coe_fn c i ≤ x) => ωSup_le c x ᾰ }
/-- A subset `p : α → Prop` of the type closed under `ωSup` induces an
`omega_complete_partial_order` on the subtype `{a : α // p a}`. -/
def subtype {α : Type u_1} [omega_complete_partial_order α] (p : α → Prop)
(hp : ∀ (c : chain α), (∀ (i : α), i ∈ c → p i) → p (ωSup c)) :
omega_complete_partial_order (Subtype p) :=
omega_complete_partial_order.lift (preorder_hom.subtype.val p)
(fun (c : chain (Subtype p)) =>
{ val := ωSup (chain.map c (preorder_hom.subtype.val p)), property := sorry })
sorry sorry
/-- A monotone function `f : α →ₘ β` is continuous if it distributes over ωSup.
In order to distinguish it from the (more commonly used) continuity from topology
(see topology/basic.lean), the present definition is often referred to as
"Scott-continuity" (referring to Dana Scott). It corresponds to continuity
in Scott topological spaces (not defined here). -/
def continuous {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →ₘ β) :=
∀ (c : chain α), coe_fn f (ωSup c) = ωSup (chain.map c f)
/-- `continuous' f` asserts that `f` is both monotone and continuous. -/
def continuous' {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α → β) :=
∃ (hf : monotone f), continuous (preorder_hom.mk f hf)
theorem continuous.to_monotone {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] {f : α → β} (hf : continuous' f) : monotone f :=
Exists.fst hf
theorem continuous.of_bundled {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α → β) (hf : monotone f)
(hf' : continuous (preorder_hom.mk f hf)) : continuous' f :=
Exists.intro hf hf'
theorem continuous.of_bundled' {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →ₘ β) (hf' : continuous f) : continuous' ⇑f :=
Exists.intro (preorder_hom.monotone f) hf'
theorem continuous.to_bundled {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α → β) (hf : continuous' f) :
continuous (preorder_hom.mk f (continuous.to_monotone hf)) :=
Exists.snd hf
theorem continuous_id {α : Type u} [omega_complete_partial_order α] : continuous preorder_hom.id :=
sorry
theorem continuous_comp {α : Type u} {β : Type v} {γ : Type u_1} [omega_complete_partial_order α]
[omega_complete_partial_order β] [omega_complete_partial_order γ] (f : α →ₘ β) (g : β →ₘ γ)
(hfc : continuous f) (hgc : continuous g) : continuous (preorder_hom.comp g f) :=
sorry
theorem id_continuous' {α : Type u} [omega_complete_partial_order α] : continuous' id := sorry
theorem const_continuous' {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (x : β) : continuous' (function.const α x) :=
sorry
end omega_complete_partial_order
namespace roption
theorem eq_of_chain {α : Type u} {c : omega_complete_partial_order.chain (roption α)} {a : α}
{b : α} (ha : some a ∈ c) (hb : some b ∈ c) : a = b :=
sorry
/-- The (noncomputable) `ωSup` definition for the `ω`-CPO structure on `roption α`. -/
protected def ωSup {α : Type u} (c : omega_complete_partial_order.chain (roption α)) : roption α :=
dite (∃ (a : α), some a ∈ c) (fun (h : ∃ (a : α), some a ∈ c) => some (classical.some h))
fun (h : ¬∃ (a : α), some a ∈ c) => none
theorem ωSup_eq_some {α : Type u} {c : omega_complete_partial_order.chain (roption α)} {a : α}
(h : some a ∈ c) : roption.ωSup c = some a :=
sorry
theorem ωSup_eq_none {α : Type u} {c : omega_complete_partial_order.chain (roption α)}
(h : ¬∃ (a : α), some a ∈ c) : roption.ωSup c = none :=
dif_neg h
theorem mem_chain_of_mem_ωSup {α : Type u} {c : omega_complete_partial_order.chain (roption α)}
{a : α} (h : a ∈ roption.ωSup c) : some a ∈ c :=
sorry
protected instance omega_complete_partial_order {α : Type u} :
omega_complete_partial_order (roption α) :=
omega_complete_partial_order.mk roption.ωSup sorry sorry
theorem mem_ωSup {α : Type u} (x : α) (c : omega_complete_partial_order.chain (roption α)) :
x ∈ omega_complete_partial_order.ωSup c ↔ some x ∈ c :=
sorry
end roption
namespace pi
/-- Function application `λ f, f a` is monotone with respect to `f` for fixed `a`. -/
def monotone_apply {α : Type u_1} {β : α → Type u_2} [(a : α) → partial_order (β a)] (a : α) :
((a : α) → β a) →ₘ β a :=
preorder_hom.mk (fun (f : (a : α) → β a) => f a) sorry
protected instance omega_complete_partial_order {α : Type u_1} {β : α → Type u_2}
[(a : α) → omega_complete_partial_order (β a)] : omega_complete_partial_order ((a : α) → β a) :=
omega_complete_partial_order.mk
(fun (c : omega_complete_partial_order.chain ((a : α) → β a)) (a : α) =>
omega_complete_partial_order.ωSup
(omega_complete_partial_order.chain.map c (monotone_apply a)))
sorry sorry
namespace omega_complete_partial_order
theorem flip₁_continuous' {α : Type u_1} {β : α → Type u_2} {γ : Type u_3}
[(x : α) → omega_complete_partial_order (β x)] [omega_complete_partial_order γ]
(f : (x : α) → γ → β x) (a : α)
(hf : omega_complete_partial_order.continuous' fun (x : γ) (y : α) => f y x) :
omega_complete_partial_order.continuous' (f a) :=
sorry
theorem flip₂_continuous' {α : Type u_1} {β : α → Type u_2} {γ : Type u_3}
[(x : α) → omega_complete_partial_order (β x)] [omega_complete_partial_order γ]
(f : γ → (x : α) → β x)
(hf : ∀ (x : α), omega_complete_partial_order.continuous' fun (g : γ) => f g x) :
omega_complete_partial_order.continuous' f :=
sorry
end omega_complete_partial_order
end pi
namespace prod
/-- The supremum of a chain in the product `ω`-CPO. -/
protected def ωSup {α : Type u_1} {β : Type u_2} [omega_complete_partial_order α]
[omega_complete_partial_order β] (c : omega_complete_partial_order.chain (α × β)) : α × β :=
(omega_complete_partial_order.ωSup
(omega_complete_partial_order.chain.map c preorder_hom.prod.fst),
omega_complete_partial_order.ωSup
(omega_complete_partial_order.chain.map c preorder_hom.prod.snd))
protected instance omega_complete_partial_order {α : Type u_1} {β : Type u_2}
[omega_complete_partial_order α] [omega_complete_partial_order β] :
omega_complete_partial_order (α × β) :=
omega_complete_partial_order.mk prod.ωSup sorry sorry
end prod
namespace complete_lattice
/-- Any complete lattice has an `ω`-CPO structure where the countable supremum is a special case
of arbitrary suprema. -/
protected instance omega_complete_partial_order (α : Type u) [complete_lattice α] :
omega_complete_partial_order α :=
omega_complete_partial_order.mk
(fun (c : omega_complete_partial_order.chain α) => supr fun (i : ℕ) => coe_fn c i) sorry sorry
theorem inf_continuous {α : Type u} {β : Type v} [omega_complete_partial_order α]
[complete_lattice β] [is_total β LessEq] (f : α →ₘ β) (g : α →ₘ β)
(hf : omega_complete_partial_order.continuous f)
(hg : omega_complete_partial_order.continuous g) :
omega_complete_partial_order.continuous (f ⊓ g) :=
sorry
theorem Sup_continuous {α : Type u} {β : Type v} [omega_complete_partial_order α]
[complete_lattice β] (s : set (α →ₘ β))
(hs : ∀ (f : α →ₘ β), f ∈ s → omega_complete_partial_order.continuous f) :
omega_complete_partial_order.continuous (Sup s) :=
sorry
theorem Sup_continuous' {α : Type u} {β : Type v} [omega_complete_partial_order α]
[complete_lattice β] (s : set (α → β)) :
(∀ (t : α → β), t ∈ s → omega_complete_partial_order.continuous' t) →
omega_complete_partial_order.continuous' (Sup s) :=
sorry
theorem sup_continuous {α : Type u} {β : Type v} [omega_complete_partial_order α]
[complete_lattice β] {f : α →ₘ β} {g : α →ₘ β} (hf : omega_complete_partial_order.continuous f)
(hg : omega_complete_partial_order.continuous g) :
omega_complete_partial_order.continuous (f ⊔ g) :=
sorry
theorem top_continuous {α : Type u} {β : Type v} [omega_complete_partial_order α]
[complete_lattice β] : omega_complete_partial_order.continuous ⊤ :=
sorry
theorem bot_continuous {α : Type u} {β : Type v} [omega_complete_partial_order α]
[complete_lattice β] : omega_complete_partial_order.continuous ⊥ :=
sorry
end complete_lattice
namespace omega_complete_partial_order
namespace preorder_hom
/-- Function application `λ f, f a` (for fixed `a`) is a monotone function from the
monotone function space `α →ₘ β` to `β`. -/
def monotone_apply {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (a : α) : (α →ₘ β) →ₘ β :=
preorder_hom.mk (fun (f : α →ₘ β) => coe_fn f a) sorry
/-- The "forgetful functor" from `α →ₘ β` to `α → β` that takes the underlying function,
is monotone. -/
def to_fun_hom {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] : (α →ₘ β) →ₘ α → β :=
preorder_hom.mk (fun (f : α →ₘ β) => preorder_hom.to_fun f) sorry
/-- The `ωSup` operator for monotone functions. -/
@[simp] theorem ωSup_to_fun {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (c : chain (α →ₘ β)) (a : α) :
coe_fn (preorder_hom.ωSup c) a = ωSup (chain.map c (monotone_apply a)) :=
Eq.refl (coe_fn (preorder_hom.ωSup c) a)
protected instance omega_complete_partial_order {α : Type u} {β : Type v}
[omega_complete_partial_order α] [omega_complete_partial_order β] :
omega_complete_partial_order (α →ₘ β) :=
omega_complete_partial_order.lift to_fun_hom preorder_hom.ωSup sorry sorry
end preorder_hom
/-- A monotone function on `ω`-continuous partial orders is said to be continuous
if for every chain `c : chain α`, `f (⊔ i, c i) = ⊔ i, f (c i)`.
This is just the bundled version of `preorder_hom.continuous`. -/
structure continuous_hom (α : Type u) (β : Type v) [omega_complete_partial_order α]
[omega_complete_partial_order β]
extends α →ₘ β where
cont : continuous (preorder_hom.mk to_fun monotone')
infixr:25 " →𝒄 " => Mathlib.omega_complete_partial_order.continuous_hom
protected instance continuous_hom.has_coe_to_fun (α : Type u) (β : Type v)
[omega_complete_partial_order α] [omega_complete_partial_order β] : has_coe_to_fun (α →𝒄 β) :=
has_coe_to_fun.mk (fun (_x : α →𝒄 β) => α → β) continuous_hom.to_fun
protected instance preorder_hom.has_coe (α : Type u) (β : Type v) [omega_complete_partial_order α]
[omega_complete_partial_order β] : has_coe (α →𝒄 β) (α →ₘ β) :=
has_coe.mk continuous_hom.to_preorder_hom
protected instance continuous_hom.partial_order (α : Type u) (β : Type v)
[omega_complete_partial_order α] [omega_complete_partial_order β] : partial_order (α →𝒄 β) :=
partial_order.lift continuous_hom.to_fun sorry
namespace continuous_hom
theorem congr_fun {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] {f : α →𝒄 β} {g : α →𝒄 β} (h : f = g) (x : α) :
coe_fn f x = coe_fn g x :=
congr_arg (fun (h : α →𝒄 β) => coe_fn h x) h
theorem congr_arg {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →𝒄 β) {x : α} {y : α} (h : x = y) :
coe_fn f x = coe_fn f y :=
congr_arg (fun (x : α) => coe_fn f x) h
theorem monotone {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →𝒄 β) : monotone ⇑f :=
monotone' f
theorem ite_continuous' {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] {p : Prop} [hp : Decidable p] (f : α → β) (g : α → β)
(hf : continuous' f) (hg : continuous' g) : continuous' fun (x : α) => ite p (f x) (g x) :=
sorry
theorem ωSup_bind {α : Type u} [omega_complete_partial_order α] {β : Type v} {γ : Type v}
(c : chain α) (f : α →ₘ roption β) (g : α →ₘ β → roption γ) :
ωSup (chain.map c (preorder_hom.bind f g)) = ωSup (chain.map c f) >>= ωSup (chain.map c g) :=
sorry
theorem bind_continuous' {α : Type u} [omega_complete_partial_order α] {β : Type v} {γ : Type v}
(f : α → roption β) (g : α → β → roption γ) :
continuous' f → continuous' g → continuous' fun (x : α) => f x >>= g x :=
sorry
theorem map_continuous' {α : Type u} [omega_complete_partial_order α] {β : Type v} {γ : Type v}
(f : β → γ) (g : α → roption β) (hg : continuous' g) : continuous' fun (x : α) => f <$> g x :=
sorry
theorem seq_continuous' {α : Type u} [omega_complete_partial_order α] {β : Type v} {γ : Type v}
(f : α → roption (β → γ)) (g : α → roption β) (hf : continuous' f) (hg : continuous' g) :
continuous' fun (x : α) => f x <*> g x :=
sorry
theorem continuous {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (F : α →𝒄 β) (C : chain α) :
coe_fn F (ωSup C) = ωSup (chain.map C ↑F) :=
cont F C
/-- Construct a continuous function from a bare function, a continuous function, and a proof that
they are equal. -/
def of_fun {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α → β) (g : α →𝒄 β) (h : f = ⇑g) : α →𝒄 β :=
mk f sorry sorry
/-- Construct a continuous function from a monotone function with a proof of continuity. -/
def of_mono {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →ₘ β)
(h : ∀ (c : chain α), coe_fn f (ωSup c) = ωSup (chain.map c f)) : α →𝒄 β :=
mk ⇑f sorry h
/-- The identity as a continuous function. -/
@[simp] theorem id_to_fun {α : Type u} [omega_complete_partial_order α] :
∀ (ᾰ : α), coe_fn id ᾰ = ᾰ :=
fun (ᾰ : α) => Eq.refl ᾰ
/-- The composition of continuous functions. -/
def comp {α : Type u} {β : Type v} {γ : Type u_3} [omega_complete_partial_order α]
[omega_complete_partial_order β] [omega_complete_partial_order γ] (f : β →𝒄 γ) (g : α →𝒄 β) :
α →𝒄 γ :=
of_mono (preorder_hom.comp ↑f ↑g) sorry
protected theorem ext {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →𝒄 β) (g : α →𝒄 β)
(h : ∀ (x : α), coe_fn f x = coe_fn g x) : f = g :=
sorry
protected theorem coe_inj {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →𝒄 β) (g : α →𝒄 β) (h : ⇑f = ⇑g) : f = g :=
continuous_hom.ext f g (congr_fun h)
@[simp] theorem comp_id {β : Type v} {γ : Type u_3} [omega_complete_partial_order β]
[omega_complete_partial_order γ] (f : β →𝒄 γ) : comp f id = f :=
continuous_hom.ext (comp f id) f fun (x : β) => Eq.refl (coe_fn (comp f id) x)
@[simp] theorem id_comp {β : Type v} {γ : Type u_3} [omega_complete_partial_order β]
[omega_complete_partial_order γ] (f : β →𝒄 γ) : comp id f = f :=
continuous_hom.ext (comp id f) f fun (x : β) => Eq.refl (coe_fn (comp id f) x)
@[simp] theorem comp_assoc {α : Type u} {β : Type v} {γ : Type u_3} {φ : Type u_4}
[omega_complete_partial_order α] [omega_complete_partial_order β]
[omega_complete_partial_order γ] [omega_complete_partial_order φ] (f : γ →𝒄 φ) (g : β →𝒄 γ)
(h : α →𝒄 β) : comp f (comp g h) = comp (comp f g) h :=
continuous_hom.ext (comp f (comp g h)) (comp (comp f g) h)
fun (x : α) => Eq.refl (coe_fn (comp f (comp g h)) x)
@[simp] theorem coe_apply {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (a : α) (f : α →𝒄 β) : coe_fn (↑f) a = coe_fn f a :=
rfl
/-- `function.const` is a continuous function. -/
def const {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : β) : α →𝒄 β :=
of_mono (preorder_hom.const α f) sorry
@[simp] theorem const_apply {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : β) (a : α) : coe_fn (const f) a = f :=
rfl
protected instance inhabited {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] [Inhabited β] : Inhabited (α →𝒄 β) :=
{ default := const Inhabited.default }
namespace prod
/-- The application of continuous functions as a monotone function.
(It would make sense to make it a continuous function, but we are currently constructing a
`omega_complete_partial_order` instance for `α →𝒄 β`, and we cannot use it as the domain or image
of a continuous function before we do.) -/
def apply {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] : (α →𝒄 β) × α →ₘ β :=
preorder_hom.mk (fun (f : (α →𝒄 β) × α) => coe_fn (prod.fst f) (prod.snd f)) sorry
end prod
/-- The map from continuous functions to monotone functions is itself a monotone function. -/
@[simp] theorem to_mono_to_fun {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (f : α →𝒄 β) : coe_fn to_mono f = ↑f :=
Eq.refl (coe_fn to_mono f)
/-- When proving that a chain of applications is below a bound `z`, it suffices to consider the
functions and values being selected from the same index in the chains.
This lemma is more specific than necessary, i.e. `c₀` only needs to be a
chain of monotone functions, but it is only used with continuous functions. -/
@[simp] theorem forall_forall_merge {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (c₀ : chain (α →𝒄 β)) (c₁ : chain α) (z : β) :
(∀ (i j : ℕ), coe_fn (coe_fn c₀ i) (coe_fn c₁ j) ≤ z) ↔
∀ (i : ℕ), coe_fn (coe_fn c₀ i) (coe_fn c₁ i) ≤ z :=
sorry
@[simp] theorem forall_forall_merge' {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (c₀ : chain (α →𝒄 β)) (c₁ : chain α) (z : β) :
(∀ (j i : ℕ), coe_fn (coe_fn c₀ i) (coe_fn c₁ j) ≤ z) ↔
∀ (i : ℕ), coe_fn (coe_fn c₀ i) (coe_fn c₁ i) ≤ z :=
sorry
/-- The `ωSup` operator for continuous functions, which takes the pointwise countable supremum
of the functions in the `ω`-chain. -/
protected def ωSup {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (c : chain (α →𝒄 β)) : α →𝒄 β :=
of_mono (ωSup (chain.map c to_mono)) sorry
protected instance omega_complete_partial_order {α : Type u} {β : Type v}
[omega_complete_partial_order α] [omega_complete_partial_order β] :
omega_complete_partial_order (α →𝒄 β) :=
omega_complete_partial_order.lift to_mono continuous_hom.ωSup sorry sorry
theorem ωSup_def {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (c : chain (α →𝒄 β)) (x : α) :
coe_fn (ωSup c) x = coe_fn (continuous_hom.ωSup c) x :=
rfl
theorem ωSup_ωSup {α : Type u} {β : Type v} [omega_complete_partial_order α]
[omega_complete_partial_order β] (c₀ : chain (α →𝒄 β)) (c₁ : chain α) :
coe_fn (ωSup c₀) (ωSup c₁) = ωSup (preorder_hom.comp prod.apply (chain.zip c₀ c₁)) :=
sorry
/-- A family of continuous functions yields a continuous family of functions. -/
def flip {β : Type v} {γ : Type u_3} [omega_complete_partial_order β]
[omega_complete_partial_order γ] {α : Type u_1} (f : α → β →𝒄 γ) : β →𝒄 α → γ :=
mk (fun (x : β) (y : α) => coe_fn (f y) x) sorry sorry
/-- `roption.bind` as a continuous function. -/
def bind {α : Type u} [omega_complete_partial_order α] {β : Type v} {γ : Type v}
(f : α →𝒄 roption β) (g : α →𝒄 β → roption γ) : α →𝒄 roption γ :=
of_mono (preorder_hom.bind ↑f ↑g) sorry
/-- `roption.map` as a continuous function. -/
@[simp] theorem map_to_fun {α : Type u} [omega_complete_partial_order α] {β : Type v} {γ : Type v}
(f : β → γ) (g : α →𝒄 roption β) (x : α) : coe_fn (map f g) x = f <$> coe_fn g x :=
Eq.refl (coe_fn (map f g) x)
/-- `roption.seq` as a continuous function. -/
def seq {α : Type u} [omega_complete_partial_order α] {β : Type v} {γ : Type v}
(f : α →𝒄 roption (β → γ)) (g : α →𝒄 roption β) : α →𝒄 roption γ :=
of_fun (fun (x : α) => coe_fn f x <*> coe_fn g x) (bind f (flip (flip map g))) sorry
end Mathlib |
e67e77b794be72c7a4988c8fc5b441dd28461259 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/list/tfae.lean | 364a4830e0d0d95c4e5ef58b32b8a55205cb894d | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,122 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.list.basic
import Mathlib.PostPort
namespace Mathlib
namespace list
/--
tfae: The Following (propositions) Are Equivalent.
The `tfae_have` and `tfae_finish` tactics can be useful in proofs with `tfae` goals.
-/
def tfae (l : List Prop) :=
∀ (x : Prop), x ∈ l → ∀ (y : Prop), y ∈ l → (x ↔ y)
theorem tfae_nil : tfae [] :=
forall_mem_nil fun (x : Prop) => ∀ (y : Prop), y ∈ [] → (x ↔ y)
theorem tfae_singleton (p : Prop) : tfae [p] := sorry
theorem tfae_cons_of_mem {a : Prop} {b : Prop} {l : List Prop} (h : b ∈ l) : tfae (a :: l) ↔ (a ↔ b) ∧ tfae l := sorry
theorem tfae_cons_cons {a : Prop} {b : Prop} {l : List Prop} : tfae (a :: b :: l) ↔ (a ↔ b) ∧ tfae (b :: l) :=
tfae_cons_of_mem (Or.inl rfl)
theorem tfae_of_forall (b : Prop) (l : List Prop) (h : ∀ (a : Prop), a ∈ l → (a ↔ b)) : tfae l :=
fun (a₁ : Prop) (h₁ : a₁ ∈ l) (a₂ : Prop) (h₂ : a₂ ∈ l) => iff.trans (h a₁ h₁) (iff.symm (h a₂ h₂))
theorem tfae_of_cycle {a : Prop} {b : Prop} {l : List Prop} : chain (fun (_x _y : Prop) => _x → _y) a (b :: l) → (ilast' b l → a) → tfae (a :: b :: l) := sorry
theorem tfae.out {l : List Prop} (h : tfae l) (n₁ : ℕ) (n₂ : ℕ) {a : Prop} {b : Prop} (h₁ : autoParam (nth l n₁ = some a)
(Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.tactic.interactive.refl")
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic") "interactive") "refl")
[])) (h₂ : autoParam (nth l n₂ = some b)
(Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.tactic.interactive.refl")
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic") "interactive") "refl")
[])) : a ↔ b :=
h a (nth_mem h₁) b (nth_mem h₂)
|
bd0f3585d5b1a1543720952fa3ee22d72a1c51cf | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/field_theory/perfect_closure.lean | 66bd8256bc3cf144f0365b617d22f51a468a801e | [
"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 | 18,013 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import algebra.char_p.basic
import algebra.group_with_zero.power
import algebra.hom.iterate
import algebra.ring.equiv
/-!
# The perfect closure of a field
-/
universes u v
open function
section defs
variables (R : Type u) [comm_semiring R] (p : ℕ) [fact p.prime] [char_p R p]
/-- A perfect ring is a ring of characteristic p that has p-th root. -/
class perfect_ring : Type u :=
(pth_root' : R → R)
(frobenius_pth_root' : ∀ x, frobenius R p (pth_root' x) = x)
(pth_root_frobenius' : ∀ x, pth_root' (frobenius R p x) = x)
/-- Frobenius automorphism of a perfect ring. -/
def frobenius_equiv [perfect_ring R p] : R ≃+* R :=
{ inv_fun := perfect_ring.pth_root' p,
left_inv := perfect_ring.pth_root_frobenius',
right_inv := perfect_ring.frobenius_pth_root',
.. frobenius R p }
/-- `p`-th root of an element in a `perfect_ring` as a `ring_hom`. -/
def pth_root [perfect_ring R p] : R →+* R :=
(frobenius_equiv R p).symm
end defs
section
variables {R : Type u} [comm_semiring R] {S : Type v} [comm_semiring S] (f : R →* S) (g : R →+* S)
{p : ℕ} [fact p.prime] [char_p R p] [perfect_ring R p] [char_p S p] [perfect_ring S p]
@[simp] lemma coe_frobenius_equiv : ⇑(frobenius_equiv R p) = frobenius R p := rfl
@[simp] lemma coe_frobenius_equiv_symm : ⇑(frobenius_equiv R p).symm = pth_root R p := rfl
@[simp] theorem frobenius_pth_root (x : R) : frobenius R p (pth_root R p x) = x :=
(frobenius_equiv R p).apply_symm_apply x
@[simp] theorem pth_root_pow_p (x : R) : pth_root R p x ^ p = x :=
frobenius_pth_root x
@[simp] theorem pth_root_frobenius (x : R) : pth_root R p (frobenius R p x) = x :=
(frobenius_equiv R p).symm_apply_apply x
@[simp] theorem pth_root_pow_p' (x : R) : pth_root R p (x ^ p) = x :=
pth_root_frobenius x
theorem left_inverse_pth_root_frobenius : left_inverse (pth_root R p) (frobenius R p) :=
pth_root_frobenius
theorem right_inverse_pth_root_frobenius : function.right_inverse (pth_root R p) (frobenius R p) :=
frobenius_pth_root
theorem commute_frobenius_pth_root : function.commute (frobenius R p) (pth_root R p) :=
λ x, (frobenius_pth_root x).trans (pth_root_frobenius x).symm
theorem eq_pth_root_iff {x y : R} : x = pth_root R p y ↔ frobenius R p x = y :=
(frobenius_equiv R p).to_equiv.eq_symm_apply
theorem pth_root_eq_iff {x y : R} : pth_root R p x = y ↔ x = frobenius R p y :=
(frobenius_equiv R p).to_equiv.symm_apply_eq
theorem monoid_hom.map_pth_root (x : R) : f (pth_root R p x) = pth_root S p (f x) :=
eq_pth_root_iff.2 $ by rw [← f.map_frobenius, frobenius_pth_root]
theorem monoid_hom.map_iterate_pth_root (x : R) (n : ℕ) :
f (pth_root R p^[n] x) = (pth_root S p^[n] (f x)) :=
semiconj.iterate_right f.map_pth_root n x
theorem ring_hom.map_pth_root (x : R) :
g (pth_root R p x) = pth_root S p (g x) :=
g.to_monoid_hom.map_pth_root x
theorem ring_hom.map_iterate_pth_root (x : R) (n : ℕ) :
g (pth_root R p^[n] x) = (pth_root S p^[n] (g x)) :=
g.to_monoid_hom.map_iterate_pth_root x n
variables (p)
lemma injective_pow_p {x y : R} (hxy : x ^ p = y ^ p) : x = y :=
left_inverse_pth_root_frobenius.injective hxy
end
section
variables (K : Type u) [comm_ring K] (p : ℕ) [fact p.prime] [char_p K p]
/-- `perfect_closure K p` is the quotient by this relation. -/
@[mk_iff] inductive perfect_closure.r : (ℕ × K) → (ℕ × K) → Prop
| intro : ∀ n x, perfect_closure.r (n, x) (n+1, frobenius K p x)
/-- The perfect closure is the smallest extension that makes frobenius surjective. -/
def perfect_closure : Type u := quot (perfect_closure.r K p)
end
namespace perfect_closure
variables (K : Type u)
section ring
variables [comm_ring K] (p : ℕ) [fact p.prime] [char_p K p]
/-- Constructor for `perfect_closure`. -/
def mk (x : ℕ × K) : perfect_closure K p := quot.mk (r K p) x
@[simp] lemma quot_mk_eq_mk (x : ℕ × K) :
(quot.mk (r K p) x : perfect_closure K p) = mk K p x := rfl
variables {K p}
/-- Lift a function `ℕ × K → L` to a function on `perfect_closure K p`. -/
@[elab_as_eliminator]
def lift_on {L : Type*} (x : perfect_closure K p) (f : ℕ × K → L)
(hf : ∀ x y, r K p x y → f x = f y) : L :=
quot.lift_on x f hf
@[simp] lemma lift_on_mk {L : Sort*} (f : ℕ × K → L)
(hf : ∀ x y, r K p x y → f x = f y) (x : ℕ × K) :
(mk K p x).lift_on f hf = f x :=
rfl
@[elab_as_eliminator]
lemma induction_on (x : perfect_closure K p) {q : perfect_closure K p → Prop}
(h : ∀ x, q (mk K p x)) : q x :=
quot.induction_on x h
variables (K p)
private lemma mul_aux_left (x1 x2 y : ℕ × K) (H : r K p x1 x2) :
mk K p (x1.1 + y.1, ((frobenius K p)^[y.1] x1.2) * ((frobenius K p)^[x1.1] y.2)) =
mk K p (x2.1 + y.1, ((frobenius K p)^[y.1] x2.2) * ((frobenius K p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro n x := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_mul, nat.succ_add]; apply r.intro
end
private lemma mul_aux_right (x y1 y2 : ℕ × K) (H : r K p y1 y2) :
mk K p (x.1 + y1.1, ((frobenius K p)^[y1.1] x.2) * ((frobenius K p)^[x.1] y1.2)) =
mk K p (x.1 + y2.1, ((frobenius K p)^[y2.1] x.2) * ((frobenius K p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro n y := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_mul]; apply r.intro
end
instance : has_mul (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.lift (λ y:ℕ×K, mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) * ((frobenius K p)^[x.1] y.2))) (mul_aux_right K p x))
(λ x1 x2 (H : r K p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
mul_aux_left K p x1 x2 y H)⟩
@[simp] lemma mk_mul_mk (x y : ℕ × K) :
mk K p x * mk K p y = mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) * ((frobenius K p)^[x.1] y.2)) :=
rfl
instance : comm_monoid (perfect_closure K p) :=
{ mul_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [add_assoc, mul_assoc, ring_hom.iterate_map_mul,
← iterate_add_apply, add_comm, add_left_comm],
one := mk K p (0, 1),
one_mul := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_one, iterate_zero_apply, one_mul, zero_add]),
mul_one := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_one, iterate_zero_apply, mul_one, add_zero]),
mul_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm, mul_comm])),
.. (infer_instance : has_mul (perfect_closure K p)) }
lemma one_def : (1 : perfect_closure K p) = mk K p (0, 1) := rfl
instance : inhabited (perfect_closure K p) := ⟨1⟩
private lemma add_aux_left (x1 x2 y : ℕ × K) (H : r K p x1 x2) :
mk K p (x1.1 + y.1, ((frobenius K p)^[y.1] x1.2) + ((frobenius K p)^[x1.1] y.2)) =
mk K p (x2.1 + y.1, ((frobenius K p)^[y.1] x2.2) + ((frobenius K p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro n x := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_add, nat.succ_add]; apply r.intro
end
private lemma add_aux_right (x y1 y2 : ℕ × K) (H : r K p y1 y2) :
mk K p (x.1 + y1.1, ((frobenius K p)^[y1.1] x.2) + ((frobenius K p)^[x.1] y1.2)) =
mk K p (x.1 + y2.1, ((frobenius K p)^[y2.1] x.2) + ((frobenius K p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro n y := quot.sound $ by rw [← iterate_succ_apply, iterate_succ',
iterate_succ', ← frobenius_add]; apply r.intro
end
instance : has_add (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.lift (λ y:ℕ×K, mk K p
(x.1 + y.1, ((frobenius K p)^[y.1] x.2) + ((frobenius K p)^[x.1] y.2))) (add_aux_right K p x))
(λ x1 x2 (H : r K p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
add_aux_left K p x1 x2 y H)⟩
@[simp] lemma mk_add_mk (x y : ℕ × K) :
mk K p x + mk K p y =
mk K p (x.1 + y.1, ((frobenius K p)^[y.1] x.2) + ((frobenius K p)^[x.1] y.2)) := rfl
instance : has_neg (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, mk K p (x.1, -x.2)) (λ x y (H : r K p x y), match x, y, H with
| _, _, r.intro n x := quot.sound $ by rw ← frobenius_neg; apply r.intro
end)⟩
@[simp] lemma neg_mk (x : ℕ × K) : - mk K p x = mk K p (x.1, -x.2) := rfl
instance : has_zero (perfect_closure K p) := ⟨mk K p (0, 0)⟩
lemma zero_def : (0 : perfect_closure K p) = mk K p (0, 0) := rfl
@[simp] lemma mk_zero_zero : mk K p (0, 0) = 0 := rfl
theorem mk_zero (n : ℕ) : mk K p (n, 0) = 0 :=
by induction n with n ih; [refl, rw ← ih]; symmetry; apply quot.sound;
have := r.intro n (0:K); rwa [frobenius_zero K p] at this
theorem r.sound (m n : ℕ) (x y : K) (H : frobenius K p^[m] x = y) :
mk K p (n, x) = mk K p (m + n, y) :=
by subst H; induction m with m ih; [simp only [zero_add, iterate_zero_apply],
rw [ih, nat.succ_add, iterate_succ']]; apply quot.sound; apply r.intro
instance : add_comm_group (perfect_closure K p) :=
{ add_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_add, ← iterate_add_apply, add_assoc, add_comm s _],
zero := 0,
zero_add := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_zero, iterate_zero_apply, zero_add]),
add_zero := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [ring_hom.iterate_map_zero, iterate_zero_apply, add_zero]),
sub_eq_add_neg := λ a b, rfl,
add_left_neg := λ e, by exact quot.induction_on e (λ ⟨n, x⟩,
by simp only [quot_mk_eq_mk, neg_mk, mk_add_mk,
ring_hom.iterate_map_neg, add_left_neg, mk_zero]),
add_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm])),
.. (infer_instance : has_add (perfect_closure K p)),
.. (infer_instance : has_neg (perfect_closure K p)) }
instance : comm_ring (perfect_closure K p) :=
{ left_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm, add_left_comm]; apply r.sound;
simp only [ring_hom.iterate_map_mul, ring_hom.iterate_map_add,
← iterate_add_apply, mul_add, add_comm, add_left_comm],
right_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm _ s, add_left_comm _ s]; apply r.sound;
simp only [ring_hom.iterate_map_mul, ring_hom.iterate_map_add,
← iterate_add_apply, add_mul, add_comm, add_left_comm],
.. perfect_closure.add_comm_group K p,
.. add_monoid_with_one.unary,
.. (infer_instance : comm_monoid (perfect_closure K p)) }
theorem eq_iff' (x y : ℕ × K) : mk K p x = mk K p y ↔
∃ z, (frobenius K p^[y.1 + z] x.2) = (frobenius K p^[x.1 + z] y.2) :=
begin
split,
{ intro H,
replace H := quot.exact _ H,
induction H,
case eqv_gen.rel : x y H
{ cases H with n x, exact ⟨0, rfl⟩ },
case eqv_gen.refl : H
{ exact ⟨0, rfl⟩ },
case eqv_gen.symm : x y H ih
{ cases ih with w ih, exact ⟨w, ih.symm⟩ },
case eqv_gen.trans : x y z H1 H2 ih1 ih2
{ cases ih1 with z1 ih1,
cases ih2 with z2 ih2,
existsi z2+(y.1+z1),
rw [← add_assoc, iterate_add_apply, ih1],
rw [← iterate_add_apply, add_comm, iterate_add_apply, ih2],
rw [← iterate_add_apply],
simp only [add_comm, add_left_comm] } },
intro H,
cases x with m x,
cases y with n y,
cases H with z H, dsimp only at H,
rw [r.sound K p (n+z) m x _ rfl, r.sound K p (m+z) n y _ rfl, H],
rw [add_assoc, add_comm, add_comm z]
end
theorem nat_cast (n x : ℕ) : (x : perfect_closure K p) = mk K p (n, x) :=
begin
induction n with n ih,
{ induction x with x ih, {simp},
rw [nat.cast_succ, nat.cast_succ, ih], refl },
rw ih, apply quot.sound,
conv {congr, skip, skip, rw ← frobenius_nat_cast K p x},
apply r.intro
end
theorem int_cast (x : ℤ) : (x : perfect_closure K p) = mk K p (0, x) :=
by induction x; simp only [int.cast_of_nat, int.cast_neg_succ_of_nat, nat_cast K p 0]; refl
theorem nat_cast_eq_iff (x y : ℕ) : (x : perfect_closure K p) = y ↔ (x : K) = y :=
begin
split; intro H,
{ rw [nat_cast K p 0, nat_cast K p 0, eq_iff'] at H,
cases H with z H,
simpa only [zero_add, iterate_fixed (frobenius_nat_cast K p _)] using H },
rw [nat_cast K p 0, nat_cast K p 0, H]
end
instance : char_p (perfect_closure K p) p :=
begin
constructor, intro x, rw ← char_p.cast_eq_zero_iff K,
rw [← nat.cast_zero, nat_cast_eq_iff, nat.cast_zero]
end
theorem frobenius_mk (x : ℕ × K) :
(frobenius (perfect_closure K p) p : perfect_closure K p → perfect_closure K p)
(mk K p x) = mk _ _ (x.1, x.2^p) :=
begin
simp only [frobenius_def], cases x with n x, dsimp only,
suffices : ∀ p':ℕ, mk K p (n, x) ^ p' = mk K p (n, x ^ p'),
{ apply this },
intro p, induction p with p ih,
case nat.zero { apply r.sound, rw [(frobenius _ _).iterate_map_one, pow_zero] },
case nat.succ
{ rw [pow_succ, ih],
symmetry,
apply r.sound,
simp only [pow_succ, (frobenius _ _).iterate_map_mul] }
end
/-- Embedding of `K` into `perfect_closure K p` -/
def of : K →+* perfect_closure K p :=
{ to_fun := λ x, mk _ _ (0, x),
map_one' := rfl,
map_mul' := λ x y, rfl,
map_zero' := rfl,
map_add' := λ x y, rfl }
lemma of_apply (x : K) : of K p x = mk _ _ (0, x) := rfl
end ring
theorem eq_iff [comm_ring K] [is_domain K] (p : ℕ) [fact p.prime] [char_p K p]
(x y : ℕ × K) : quot.mk (r K p) x = quot.mk (r K p) y ↔
(frobenius K p^[y.1] x.2) = (frobenius K p^[x.1] y.2) :=
(eq_iff' K p x y).trans ⟨λ ⟨z, H⟩, (frobenius_inj K p).iterate z $
by simpa only [add_comm, iterate_add] using H,
λ H, ⟨0, H⟩⟩
section field
variables [field K] (p : ℕ) [fact p.prime] [char_p K p]
instance : has_inv (perfect_closure K p) :=
⟨quot.lift (λ x:ℕ×K, quot.mk (r K p) (x.1, x.2⁻¹)) (λ x y (H : r K p x y), match x, y, H with
| _, _, r.intro n x := quot.sound $ by { simp only [frobenius_def], rw ← inv_pow, apply r.intro }
end)⟩
instance : field (perfect_closure K p) :=
{ exists_pair_ne := ⟨0, 1, λ H, zero_ne_one ((eq_iff _ _ _ _).1 H)⟩,
mul_inv_cancel := λ e, induction_on e $ λ ⟨m, x⟩ H,
have _ := mt (eq_iff _ _ _ _).2 H, (eq_iff _ _ _ _).2
(by simp only [(frobenius _ _).iterate_map_one, (frobenius K p).iterate_map_zero,
iterate_zero_apply, ← (frobenius _ p).iterate_map_mul] at this ⊢;
rw [mul_inv_cancel this, (frobenius _ _).iterate_map_one]),
inv_zero := congr_arg (quot.mk (r K p)) (by rw [inv_zero]),
.. (infer_instance : has_inv (perfect_closure K p)),
.. (infer_instance : comm_ring (perfect_closure K p)) }
instance : perfect_ring (perfect_closure K p) p :=
{ pth_root' := λ e, lift_on e (λ x, mk K p (x.1 + 1, x.2)) (λ x y H,
match x, y, H with
| _, _, r.intro n x := quot.sound (r.intro _ _)
end),
frobenius_pth_root' := λ e, induction_on e (λ ⟨n, x⟩,
by { simp only [lift_on_mk, frobenius_mk], exact (quot.sound $ r.intro _ _).symm }),
pth_root_frobenius' := λ e, induction_on e (λ ⟨n, x⟩,
by { simp only [lift_on_mk, frobenius_mk], exact (quot.sound $ r.intro _ _).symm }) }
theorem eq_pth_root (x : ℕ × K) :
mk K p x = (pth_root (perfect_closure K p) p^[x.1] (of K p x.2)) :=
begin
rcases x with ⟨m, x⟩,
induction m with m ih, {refl},
rw [iterate_succ_apply', ← ih]; refl
end
/-- Given a field `K` of characteristic `p` and a perfect ring `L` of the same characteristic,
any homomorphism `K →+* L` can be lifted to `perfect_closure K p`. -/
def lift (L : Type v) [comm_semiring L] [char_p L p] [perfect_ring L p] :
(K →+* L) ≃ (perfect_closure K p →+* L) :=
begin
have := left_inverse_pth_root_frobenius.iterate,
refine_struct { .. },
field to_fun { intro f,
refine_struct { .. },
field to_fun { refine λ e, lift_on e (λ x, pth_root L p^[x.1] (f x.2)) _,
rintro a b ⟨n⟩,
simp only [f.map_frobenius, iterate_succ_apply, pth_root_frobenius] },
field map_one' { exact f.map_one },
field map_zero' { exact f.map_zero },
field map_mul' { rintro ⟨x⟩ ⟨y⟩,
simp only [quot_mk_eq_mk, lift_on_mk, mk_mul_mk, ring_hom.map_iterate_frobenius,
ring_hom.iterate_map_mul, ring_hom.map_mul],
rw [iterate_add_apply, this _ _, add_comm, iterate_add_apply, this _ _] },
field map_add' { rintro ⟨x⟩ ⟨y⟩,
simp only [quot_mk_eq_mk, lift_on_mk, mk_add_mk, ring_hom.map_iterate_frobenius,
ring_hom.iterate_map_add, ring_hom.map_add],
rw [iterate_add_apply, this _ _, add_comm x.1, iterate_add_apply, this _ _] } },
field inv_fun { exact λ f, f.comp (of K p) },
field left_inv { intro f, ext x, refl },
field right_inv { intro f, ext ⟨x⟩,
simp only [ring_hom.coe_mk, quot_mk_eq_mk, ring_hom.comp_apply, lift_on_mk],
rw [eq_pth_root, ring_hom.map_iterate_pth_root] }
end
end field
end perfect_closure
/-- A reduced ring with prime characteristic and surjective frobenius map is perfect. -/
noncomputable def perfect_ring.of_surjective (k : Type*) [comm_ring k] [is_reduced k] (p : ℕ)
[fact p.prime] [char_p k p] (h : function.surjective $ frobenius k p) :
perfect_ring k p :=
{ pth_root' := function.surj_inv h,
frobenius_pth_root' := function.surj_inv_eq h,
pth_root_frobenius' := λ x, frobenius_inj _ _ $ function.surj_inv_eq h _ }
|
71f488d9c8f17e8fd322ebb62ff70dc994540337 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/data/real/basic.lean | 54ce0a0a9a2c7acb2c33e4518696b2700103c329 | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 22,793 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import order.conditionally_complete_lattice
import data.real.cau_seq_completion
import algebra.archimedean
import algebra.star.basic
import algebra.bounds
/-!
# Real numbers from Cauchy sequences
This file defines `ℝ` as the type of equivalence classes of Cauchy sequences of rational numbers.
This choice is motivated by how easy it is to prove that `ℝ` is a commutative ring, by simply
lifting everything to `ℚ`.
-/
open_locale pointwise
/-- The type `ℝ` of real numbers constructed as equivalence classes of Cauchy sequences of rational
numbers. -/
structure real := of_cauchy ::
(cauchy : @cau_seq.completion.Cauchy ℚ _ _ _ abs _)
notation `ℝ` := real
attribute [pp_using_anonymous_constructor] real
namespace real
open cau_seq cau_seq.completion
variables {x y : ℝ}
lemma ext_cauchy_iff : ∀ {x y : real}, x = y ↔ x.cauchy = y.cauchy
| ⟨a⟩ ⟨b⟩ := by split; cc
lemma ext_cauchy {x y : real} : x.cauchy = y.cauchy → x = y :=
ext_cauchy_iff.2
/-- The real numbers are isomorphic to the quotient of Cauchy sequences on the rationals. -/
def equiv_Cauchy : ℝ ≃ cau_seq.completion.Cauchy :=
⟨real.cauchy, real.of_cauchy, λ ⟨_⟩, rfl, λ _, rfl⟩
-- irreducible doesn't work for instances: https://github.com/leanprover-community/lean/issues/511
@[irreducible] private def zero : ℝ := ⟨0⟩
@[irreducible] private def one : ℝ := ⟨1⟩
@[irreducible] private def add : ℝ → ℝ → ℝ | ⟨a⟩ ⟨b⟩ := ⟨a + b⟩
@[irreducible] private def neg : ℝ → ℝ | ⟨a⟩ := ⟨-a⟩
@[irreducible] private def mul : ℝ → ℝ → ℝ | ⟨a⟩ ⟨b⟩ := ⟨a * b⟩
instance : has_zero ℝ := ⟨zero⟩
instance : has_one ℝ := ⟨one⟩
instance : has_add ℝ := ⟨add⟩
instance : has_neg ℝ := ⟨neg⟩
instance : has_mul ℝ := ⟨mul⟩
lemma zero_cauchy : (⟨0⟩ : ℝ) = 0 := show _ = zero, by rw zero
lemma one_cauchy : (⟨1⟩ : ℝ) = 1 := show _ = one, by rw one
lemma add_cauchy {a b} : (⟨a⟩ + ⟨b⟩ : ℝ) = ⟨a + b⟩ := show add _ _ = _, by rw add
lemma neg_cauchy {a} : (-⟨a⟩ : ℝ) = ⟨-a⟩ := show neg _ = _, by rw neg
lemma mul_cauchy {a b} : (⟨a⟩ * ⟨b⟩ : ℝ) = ⟨a * b⟩ := show mul _ _ = _, by rw mul
instance : comm_ring ℝ :=
begin
refine_struct { zero := 0,
one := 1,
mul := (*),
add := (+),
neg := @has_neg.neg ℝ _,
sub := λ a b, a + (-b),
npow := @npow_rec _ ⟨1⟩ ⟨(*)⟩,
nsmul := @nsmul_rec _ ⟨0⟩ ⟨(+)⟩,
gsmul := @gsmul_rec _ ⟨0⟩ ⟨(+)⟩ ⟨@has_neg.neg ℝ _⟩ };
repeat { rintro ⟨_⟩, };
try { refl };
simp [← zero_cauchy, ← one_cauchy, add_cauchy, neg_cauchy, mul_cauchy];
apply add_assoc <|> apply add_comm <|> apply mul_assoc <|> apply mul_comm <|>
apply left_distrib <|> apply right_distrib <|> apply sub_eq_add_neg <|> skip
end
/-! Extra instances to short-circuit type class resolution.
These short-circuits have an additional property of ensuring that a computable path is found; if
`field ℝ` is found first, then decaying it to these typeclasses would result in a `noncomputable`
version of them. -/
instance : ring ℝ := by apply_instance
instance : comm_semiring ℝ := by apply_instance
instance : semiring ℝ := by apply_instance
instance : add_comm_group ℝ := by apply_instance
instance : add_group ℝ := by apply_instance
instance : add_comm_monoid ℝ := by apply_instance
instance : add_monoid ℝ := by apply_instance
instance : add_left_cancel_semigroup ℝ := by apply_instance
instance : add_right_cancel_semigroup ℝ := by apply_instance
instance : add_comm_semigroup ℝ := by apply_instance
instance : add_semigroup ℝ := by apply_instance
instance : comm_monoid ℝ := by apply_instance
instance : monoid ℝ := by apply_instance
instance : comm_semigroup ℝ := by apply_instance
instance : semigroup ℝ := by apply_instance
instance : has_sub ℝ := by apply_instance
instance : module ℝ ℝ := by apply_instance
instance : inhabited ℝ := ⟨0⟩
/-- The real numbers are a `*`-ring, with the trivial `*`-structure. -/
instance : star_ring ℝ := star_ring_of_comm
/-- Coercion `ℚ` → `ℝ` as a `ring_hom`. Note that this
is `cau_seq.completion.of_rat`, not `rat.cast`. -/
def of_rat : ℚ →+* ℝ :=
by refine_struct { to_fun := of_cauchy ∘ of_rat };
simp [of_rat_one, of_rat_zero, of_rat_mul, of_rat_add,
one_cauchy, zero_cauchy, ← mul_cauchy, ← add_cauchy]
lemma of_rat_apply (x : ℚ) : of_rat x = of_cauchy (cau_seq.completion.of_rat x) := rfl
/-- Make a real number from a Cauchy sequence of rationals (by taking the equivalence class). -/
def mk (x : cau_seq ℚ abs) : ℝ := ⟨cau_seq.completion.mk x⟩
theorem mk_eq {f g : cau_seq ℚ abs} : mk f = mk g ↔ f ≈ g :=
ext_cauchy_iff.trans mk_eq
@[irreducible]
private def lt : ℝ → ℝ → Prop | ⟨x⟩ ⟨y⟩ :=
quotient.lift_on₂ x y (<) $
λ f₁ g₁ f₂ g₂ hf hg, propext $
⟨λ h, lt_of_eq_of_lt (setoid.symm hf) (lt_of_lt_of_eq h hg),
λ h, lt_of_eq_of_lt hf (lt_of_lt_of_eq h (setoid.symm hg))⟩
instance : has_lt ℝ := ⟨lt⟩
lemma lt_cauchy {f g} : (⟨⟦f⟧⟩ : ℝ) < ⟨⟦g⟧⟩ ↔ f < g := show lt _ _ ↔ _, by rw lt; refl
@[simp] theorem mk_lt {f g : cau_seq ℚ abs} : mk f < mk g ↔ f < g :=
lt_cauchy
lemma mk_zero : mk 0 = 0 := by rw ← zero_cauchy; refl
lemma mk_one : mk 1 = 1 := by rw ← one_cauchy; refl
lemma mk_add {f g : cau_seq ℚ abs} : mk (f + g) = mk f + mk g := by simp [mk, add_cauchy]
lemma mk_mul {f g : cau_seq ℚ abs} : mk (f * g) = mk f * mk g := by simp [mk, mul_cauchy]
lemma mk_neg {f : cau_seq ℚ abs} : mk (-f) = -mk f := by simp [mk, neg_cauchy]
@[simp] theorem mk_pos {f : cau_seq ℚ abs} : 0 < mk f ↔ pos f :=
by rw [← mk_zero, mk_lt]; exact iff_of_eq (congr_arg pos (sub_zero f))
@[irreducible] private def le (x y : ℝ) : Prop := x < y ∨ x = y
instance : has_le ℝ := ⟨le⟩
private lemma le_def {x y : ℝ} : x ≤ y ↔ x < y ∨ x = y := show le _ _ ↔ _, by rw le
@[simp] theorem mk_le {f g : cau_seq ℚ abs} : mk f ≤ mk g ↔ f ≤ g :=
by simp [le_def, mk_eq]; refl
@[elab_as_eliminator]
protected lemma ind_mk {C : real → Prop} (x : real) (h : ∀ y, C (mk y)) : C x :=
begin
cases x with x,
induction x using quot.induction_on with x,
exact h x
end
theorem add_lt_add_iff_left {a b : ℝ} (c : ℝ) : c + a < c + b ↔ a < b :=
begin
induction a using real.ind_mk,
induction b using real.ind_mk,
induction c using real.ind_mk,
simp only [mk_lt, ← mk_add],
show pos _ ↔ pos _, rw add_sub_add_left_eq_sub
end
instance : partial_order ℝ :=
{ le := (≤), lt := (<),
lt_iff_le_not_le := λ a b, real.ind_mk a $ λ a, real.ind_mk b $ λ b,
by simpa using lt_iff_le_not_le,
le_refl := λ a, a.ind_mk (by intro a; rw mk_le),
le_trans := λ a b c, real.ind_mk a $ λ a, real.ind_mk b $ λ b, real.ind_mk c $ λ c,
by simpa using le_trans,
lt_iff_le_not_le := λ a b, real.ind_mk a $ λ a, real.ind_mk b $ λ b,
by simpa using lt_iff_le_not_le,
le_antisymm := λ a b, real.ind_mk a $ λ a, real.ind_mk b $ λ b,
by simpa [mk_eq] using @cau_seq.le_antisymm _ _ a b }
instance : preorder ℝ := by apply_instance
theorem of_rat_lt {x y : ℚ} : of_rat x < of_rat y ↔ x < y :=
begin
rw [mk_lt] {md := tactic.transparency.semireducible},
exact const_lt
end
protected theorem zero_lt_one : (0 : ℝ) < 1 :=
by convert of_rat_lt.2 zero_lt_one; simp
protected theorem mul_pos {a b : ℝ} : 0 < a → 0 < b → 0 < a * b :=
begin
induction a using real.ind_mk with a,
induction b using real.ind_mk with b,
simpa only [mk_lt, mk_pos, ← mk_mul] using cau_seq.mul_pos
end
instance : ordered_ring ℝ :=
{ add_le_add_left :=
begin
simp only [le_iff_eq_or_lt],
rintros a b ⟨rfl, h⟩,
{ simp },
{ exact λ c, or.inr ((add_lt_add_iff_left c).2 ‹_›) }
end,
zero_le_one := le_of_lt real.zero_lt_one,
mul_pos := @real.mul_pos,
.. real.comm_ring, .. real.partial_order, .. real.semiring }
instance : ordered_semiring ℝ := by apply_instance
instance : ordered_add_comm_group ℝ := by apply_instance
instance : ordered_cancel_add_comm_monoid ℝ := by apply_instance
instance : ordered_add_comm_monoid ℝ := by apply_instance
instance : nontrivial ℝ := ⟨⟨0, 1, ne_of_lt real.zero_lt_one⟩⟩
open_locale classical
noncomputable instance : linear_order ℝ :=
{ le_total := begin
intros a b,
induction a using real.ind_mk with a,
induction b using real.ind_mk with b,
simpa using le_total a b,
end,
decidable_le := by apply_instance,
.. real.partial_order }
noncomputable instance : linear_ordered_comm_ring ℝ :=
{ .. real.nontrivial, .. real.ordered_ring, .. real.comm_ring, .. real.linear_order }
/- Extra instances to short-circuit type class resolution -/
noncomputable instance : linear_ordered_ring ℝ := by apply_instance
noncomputable instance : linear_ordered_semiring ℝ := by apply_instance
instance : domain ℝ :=
{ .. real.nontrivial, .. real.comm_ring, .. linear_ordered_ring.to_domain }
/-- The real numbers are an ordered `*`-ring, with the trivial `*`-structure. -/
instance : star_ordered_ring ℝ :=
{ star_mul_self_nonneg := λ r, mul_self_nonneg r, }
@[irreducible] private noncomputable def inv' : ℝ → ℝ | ⟨a⟩ := ⟨a⁻¹⟩
noncomputable instance : has_inv ℝ := ⟨inv'⟩
lemma inv_cauchy {f} : (⟨f⟩ : ℝ)⁻¹ = ⟨f⁻¹⟩ := show inv' _ = _, by rw inv'
noncomputable instance : linear_ordered_field ℝ :=
{ inv := has_inv.inv,
mul_inv_cancel := begin
rintros ⟨a⟩ h,
rw mul_comm,
simp only [inv_cauchy, mul_cauchy, ← one_cauchy, ← zero_cauchy, ne.def] at *,
exact cau_seq.completion.inv_mul_cancel h,
end,
inv_zero := by simp [← zero_cauchy, inv_cauchy],
..real.linear_ordered_comm_ring,
..real.domain }
/- Extra instances to short-circuit type class resolution -/
noncomputable instance : linear_ordered_add_comm_group ℝ := by apply_instance
noncomputable instance field : field ℝ := by apply_instance
noncomputable instance : division_ring ℝ := by apply_instance
noncomputable instance : integral_domain ℝ := by apply_instance
noncomputable instance : distrib_lattice ℝ := by apply_instance
noncomputable instance : lattice ℝ := by apply_instance
noncomputable instance : semilattice_inf ℝ := by apply_instance
noncomputable instance : semilattice_sup ℝ := by apply_instance
noncomputable instance : has_inf ℝ := by apply_instance
noncomputable instance : has_sup ℝ := by apply_instance
noncomputable instance decidable_lt (a b : ℝ) : decidable (a < b) := by apply_instance
noncomputable instance decidable_le (a b : ℝ) : decidable (a ≤ b) := by apply_instance
noncomputable instance decidable_eq (a b : ℝ) : decidable (a = b) := by apply_instance
open rat
@[simp] theorem of_rat_eq_cast : ∀ x : ℚ, of_rat x = x :=
of_rat.eq_rat_cast
theorem le_mk_of_forall_le {f : cau_seq ℚ abs} :
(∃ i, ∀ j ≥ i, x ≤ f j) → x ≤ mk f :=
begin
intro h,
induction x using real.ind_mk with x,
apply le_of_not_lt,
rw mk_lt,
rintro ⟨K, K0, hK⟩,
obtain ⟨i, H⟩ := exists_forall_ge_and h
(exists_forall_ge_and hK (f.cauchy₃ $ half_pos K0)),
apply not_lt_of_le (H _ (le_refl _)).1,
rw ← of_rat_eq_cast,
rw [mk_lt] {md := tactic.transparency.semireducible},
refine ⟨_, half_pos K0, i, λ j ij, _⟩,
have := add_le_add (H _ ij).2.1
(le_of_lt (abs_lt.1 $ (H _ (le_refl _)).2.2 _ ij).1),
rwa [← sub_eq_add_neg, sub_self_div_two, sub_apply, sub_add_sub_cancel] at this
end
theorem mk_le_of_forall_le {f : cau_seq ℚ abs} {x : ℝ}
(h : ∃ i, ∀ j ≥ i, (f j : ℝ) ≤ x) : mk f ≤ x :=
begin
cases h with i H,
rw [← neg_le_neg_iff, ← mk_neg],
exact le_mk_of_forall_le ⟨i, λ j ij, by simp [H _ ij]⟩
end
theorem mk_near_of_forall_near {f : cau_seq ℚ abs} {x : ℝ} {ε : ℝ}
(H : ∃ i, ∀ j ≥ i, abs ((f j : ℝ) - x) ≤ ε) : abs (mk f - x) ≤ ε :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add'.2 $ mk_le_of_forall_le $
H.imp $ λ i h j ij, sub_le_iff_le_add'.1 (abs_sub_le_iff.1 $ h j ij).1,
sub_le.1 $ le_mk_of_forall_le $
H.imp $ λ i h j ij, sub_le.1 (abs_sub_le_iff.1 $ h j ij).2⟩
instance : archimedean ℝ :=
archimedean_iff_rat_le.2 $ λ x, real.ind_mk x $ λ f,
let ⟨M, M0, H⟩ := f.bounded' 0 in
⟨M, mk_le_of_forall_le ⟨0, λ i _,
rat.cast_le.2 $ le_of_lt (abs_lt.1 (H i)).2⟩⟩
noncomputable instance : floor_ring ℝ := archimedean.floor_ring _
theorem is_cau_seq_iff_lift {f : ℕ → ℚ} : is_cau_seq abs f ↔ is_cau_seq abs (λ i, (f i : ℝ)) :=
⟨λ H ε ε0,
let ⟨δ, δ0, δε⟩ := exists_pos_rat_lt ε0 in
(H _ δ0).imp $ λ i hi j ij, lt_trans
(by simpa using (@rat.cast_lt ℝ _ _ _).2 (hi _ ij)) δε,
λ H ε ε0, (H _ (rat.cast_pos.2 ε0)).imp $
λ i hi j ij, (@rat.cast_lt ℝ _ _ _).1 $ by simpa using hi _ ij⟩
theorem of_near (f : ℕ → ℚ) (x : ℝ)
(h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abs ((f j : ℝ) - x) < ε) :
∃ h', real.mk ⟨f, h'⟩ = x :=
⟨is_cau_seq_iff_lift.2 (of_near _ (const abs x) h),
sub_eq_zero.1 $ abs_eq_zero.1 $
eq_of_le_of_forall_le_of_dense (abs_nonneg _) $ λ ε ε0,
mk_near_of_forall_near $
(h _ ε0).imp (λ i h j ij, le_of_lt (h j ij))⟩
theorem exists_floor (x : ℝ) : ∃ (ub : ℤ), (ub:ℝ) ≤ x ∧
∀ (z : ℤ), (z:ℝ) ≤ x → z ≤ ub :=
int.exists_greatest_of_bdd
(let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h',
int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩)
(let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩)
theorem exists_is_lub (S : set ℝ) (hne : S.nonempty) (hbdd : bdd_above S) :
∃ x, is_lub S x :=
begin
rcases ⟨hne, hbdd⟩ with ⟨⟨L, hL⟩, ⟨U, hU⟩⟩,
have : ∀ d : ℕ, bdd_above {m : ℤ | ∃ y ∈ S, (m : ℝ) ≤ y * d},
{ cases exists_int_gt U with k hk,
refine λ d, ⟨k * d, λ z h, _⟩,
rcases h with ⟨y, yS, hy⟩,
refine int.cast_le.1 (hy.trans _),
push_cast,
exact mul_le_mul_of_nonneg_right ((hU yS).trans hk.le) d.cast_nonneg },
choose f hf using λ d : ℕ, int.exists_greatest_of_bdd (this d) ⟨⌊L * d⌋, L, hL, floor_le _⟩,
have hf₁ : ∀ n > 0, ∃ y ∈ S, ((f n / n:ℚ):ℝ) ≤ y := λ n n0,
let ⟨y, yS, hy⟩ := (hf n).1 in
⟨y, yS, by simpa using (div_le_iff ((nat.cast_pos.2 n0):((_:ℝ) < _))).2 hy⟩,
have hf₂ : ∀ (n > 0) (y ∈ S), (y - (n:ℕ)⁻¹ : ℝ) < (f n / n:ℚ),
{ intros n n0 y yS,
have := lt_of_lt_of_le (sub_one_lt_floor _)
(int.cast_le.2 $ (hf n).2 _ ⟨y, yS, floor_le _⟩),
simp [-sub_eq_add_neg],
rwa [lt_div_iff ((nat.cast_pos.2 n0):((_:ℝ) < _)), sub_mul, _root_.inv_mul_cancel],
exact ne_of_gt (nat.cast_pos.2 n0) },
have hg : is_cau_seq abs (λ n, f n / n : ℕ → ℚ),
{ intros ε ε0,
suffices : ∀ j k ≥ ⌈ε⁻¹⌉₊, (f j / j - f k / k : ℚ) < ε,
{ refine ⟨_, λ j ij, abs_lt.2 ⟨_, this _ _ ij (le_refl _)⟩⟩,
rw [neg_lt, neg_sub], exact this _ _ (le_refl _) ij },
intros j k ij ik,
replace ij := le_trans (le_nat_ceil _) (nat.cast_le.2 ij),
replace ik := le_trans (le_nat_ceil _) (nat.cast_le.2 ik),
have j0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 ε0) ij),
have k0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 ε0) ik),
rcases hf₁ _ j0 with ⟨y, yS, hy⟩,
refine lt_of_lt_of_le ((@rat.cast_lt ℝ _ _ _).1 _)
((inv_le ε0 (nat.cast_pos.2 k0)).1 ik),
simpa using sub_lt_iff_lt_add'.2
(lt_of_le_of_lt hy $ sub_lt_iff_lt_add.1 $ hf₂ _ k0 _ yS) },
let g : cau_seq ℚ abs := ⟨λ n, f n / n, hg⟩,
refine ⟨mk g, ⟨λ x xS, _, λ y h, _⟩⟩,
{ refine le_of_forall_ge_of_dense (λ z xz, _),
cases exists_nat_gt (x - z)⁻¹ with K hK,
refine le_mk_of_forall_le ⟨K, λ n nK, _⟩,
replace xz := sub_pos.2 xz,
replace hK := le_trans (le_of_lt hK) (nat.cast_le.2 nK),
have n0 : 0 < n := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 xz) hK),
refine le_trans _ (le_of_lt $ hf₂ _ n0 _ xS),
rwa [le_sub, inv_le ((nat.cast_pos.2 n0):((_:ℝ) < _)) xz] },
{ exact mk_le_of_forall_le ⟨1, λ n n1,
let ⟨x, xS, hx⟩ := hf₁ _ n1 in le_trans hx (h xS)⟩ }
end
noncomputable instance : has_Sup ℝ :=
⟨λ S, if h : S.nonempty ∧ bdd_above S then classical.some (exists_is_lub S h.1 h.2) else 0⟩
lemma Sup_def (S : set ℝ) :
Sup S = if h : S.nonempty ∧ bdd_above S
then classical.some (exists_is_lub S h.1 h.2) else 0 := rfl
protected theorem is_lub_Sup (S : set ℝ) (h₁ : S.nonempty) (h₂ : bdd_above S) : is_lub S (Sup S) :=
by { simp only [Sup_def, dif_pos (and.intro h₁ h₂)], apply classical.some_spec }
noncomputable instance : has_Inf ℝ := ⟨λ S, -Sup (-S)⟩
lemma Inf_def (S : set ℝ) : Inf S = -Sup (-S) := rfl
protected theorem is_glb_Inf (S : set ℝ) (h₁ : S.nonempty) (h₂ : bdd_below S) :
is_glb S (Inf S) :=
begin
rw [Inf_def, ← is_lub_neg', neg_neg],
exact real.is_lub_Sup _ h₁.neg h₂.neg
end
noncomputable instance : conditionally_complete_linear_order ℝ :=
{ Sup := has_Sup.Sup,
Inf := has_Inf.Inf,
le_cSup := λ s a hs ha, (real.is_lub_Sup s ⟨a, ha⟩ hs).1 ha,
cSup_le := λ s a hs ha, (real.is_lub_Sup s hs ⟨a, ha⟩).2 ha,
cInf_le := λ s a hs ha, (real.is_glb_Inf s ⟨a, ha⟩ hs).1 ha,
le_cInf := λ s a hs ha, (real.is_glb_Inf s hs ⟨a, ha⟩).2 ha,
..real.linear_order, ..real.lattice}
lemma lt_Inf_add_pos {s : set ℝ} (h : s.nonempty) {ε : ℝ} (hε : 0 < ε) :
∃ a ∈ s, a < Inf s + ε :=
exists_lt_of_cInf_lt h $ lt_add_of_pos_right _ hε
lemma add_neg_lt_Sup {s : set ℝ} (h : s.nonempty) {ε : ℝ} (hε : ε < 0) :
∃ a ∈ s, Sup s + ε < a :=
exists_lt_of_lt_cSup h $ add_lt_iff_neg_left.2 hε
lemma Inf_le_iff {s : set ℝ} (h : bdd_below s) (h' : s.nonempty) {a : ℝ} :
Inf s ≤ a ↔ ∀ ε, 0 < ε → ∃ x ∈ s, x < a + ε :=
begin
rw le_iff_forall_pos_lt_add,
split; intros H ε ε_pos,
{ exact exists_lt_of_cInf_lt h' (H ε ε_pos) },
{ rcases H ε ε_pos with ⟨x, x_in, hx⟩,
exact cInf_lt_of_lt h x_in hx }
end
lemma le_Sup_iff {s : set ℝ} (h : bdd_above s) (h' : s.nonempty) {a : ℝ} :
a ≤ Sup s ↔ ∀ ε, ε < 0 → ∃ x ∈ s, a + ε < x :=
begin
rw le_iff_forall_pos_lt_add,
refine ⟨λ H ε ε_neg, _, λ H ε ε_pos, _⟩,
{ exact exists_lt_of_lt_cSup h' (lt_sub_iff_add_lt.mp (H _ (neg_pos.mpr ε_neg))) },
{ rcases H _ (neg_lt_zero.mpr ε_pos) with ⟨x, x_in, hx⟩,
exact sub_lt_iff_lt_add.mp (lt_cSup_of_lt h x_in hx) }
end
@[simp] theorem Sup_empty : Sup (∅ : set ℝ) = 0 := dif_neg $ by simp
theorem Sup_of_not_bdd_above {s : set ℝ} (hs : ¬ bdd_above s) : Sup s = 0 :=
dif_neg $ assume h, hs h.2
theorem Sup_univ : Sup (@set.univ ℝ) = 0 :=
real.Sup_of_not_bdd_above $ λ ⟨x, h⟩, not_le_of_lt (lt_add_one _) $ h (set.mem_univ _)
@[simp] theorem Inf_empty : Inf (∅ : set ℝ) = 0 :=
by simp [Inf_def, Sup_empty]
theorem Inf_of_not_bdd_below {s : set ℝ} (hs : ¬ bdd_below s) : Inf s = 0 :=
neg_eq_zero.2 $ Sup_of_not_bdd_above $ mt bdd_above_neg.1 hs
/--
As `0` is the default value for `real.Sup` of the empty set or sets which are not bounded above, it
suffices to show that `S` is bounded below by `0` to show that `0 ≤ Inf S`.
-/
lemma Sup_nonneg (S : set ℝ) (hS : ∀ x ∈ S, (0:ℝ) ≤ x) : 0 ≤ Sup S :=
begin
rcases S.eq_empty_or_nonempty with rfl | ⟨y, hy⟩,
{ exact Sup_empty.ge },
{ apply dite _ (λ h, le_cSup_of_le h hy $ hS y hy) (λ h, (Sup_of_not_bdd_above h).ge) }
end
/--
As `0` is the default value for `real.Sup` of the empty set, it suffices to show that `S` is
bounded above by `0` to show that `Sup S ≤ 0`.
-/
lemma Sup_nonpos (S : set ℝ) (hS : ∀ x ∈ S, x ≤ (0:ℝ)) : Sup S ≤ 0 :=
begin
rcases S.eq_empty_or_nonempty with rfl | hS₂,
exacts [Sup_empty.le, cSup_le hS₂ hS],
end
/--
As `0` is the default value for `real.Inf` of the empty set, it suffices to show that `S` is
bounded below by `0` to show that `0 ≤ Inf S`.
-/
lemma Inf_nonneg (S : set ℝ) (hS : ∀ x ∈ S, (0:ℝ) ≤ x) : 0 ≤ Inf S :=
begin
rcases S.eq_empty_or_nonempty with rfl | hS₂,
exacts [Inf_empty.ge, le_cInf hS₂ hS]
end
/--
As `0` is the default value for `real.Inf` of the empty set or sets which are not bounded below, it
suffices to show that `S` is bounded above by `0` to show that `Inf S ≤ 0`.
-/
lemma Inf_nonpos (S : set ℝ) (hS : ∀ x ∈ S, x ≤ (0:ℝ)) : Inf S ≤ 0 :=
begin
rcases S.eq_empty_or_nonempty with rfl | ⟨y, hy⟩,
{ exact Inf_empty.le },
{ apply dite _ (λ h, cInf_le_of_le h hy $ hS y hy) (λ h, (Inf_of_not_bdd_below h).le) }
end
lemma Inf_le_Sup (s : set ℝ) (h₁ : bdd_below s) (h₂ : bdd_above s) : Inf s ≤ Sup s :=
begin
rcases s.eq_empty_or_nonempty with rfl | hne,
{ rw [Inf_empty, Sup_empty] },
{ exact cInf_le_cSup h₁ h₂ hne }
end
theorem cau_seq_converges (f : cau_seq ℝ abs) : ∃ x, f ≈ const abs x :=
begin
let S := {x : ℝ | const abs x < f},
have lb : ∃ x, x ∈ S := exists_lt f,
have ub' : ∀ x, f < const abs x → ∀ y ∈ S, y ≤ x :=
λ x h y yS, le_of_lt $ const_lt.1 $ cau_seq.lt_trans yS h,
have ub : ∃ x, ∀ y ∈ S, y ≤ x := (exists_gt f).imp ub',
refine ⟨Sup S,
((lt_total _ _).resolve_left (λ h, _)).resolve_right (λ h, _)⟩,
{ rcases h with ⟨ε, ε0, i, ih⟩,
refine (cSup_le lb (ub' _ _)).not_lt (sub_lt_self _ (half_pos ε0)),
refine ⟨_, half_pos ε0, i, λ j ij, _⟩,
rw [sub_apply, const_apply, sub_right_comm,
le_sub_iff_add_le, add_halves],
exact ih _ ij },
{ rcases h with ⟨ε, ε0, i, ih⟩,
refine (le_cSup ub _).not_lt ((lt_add_iff_pos_left _).2 (half_pos ε0)),
refine ⟨_, half_pos ε0, i, λ j ij, _⟩,
rw [sub_apply, const_apply, add_comm, ← sub_sub,
le_sub_iff_add_le, add_halves],
exact ih _ ij }
end
noncomputable instance : cau_seq.is_complete ℝ abs := ⟨cau_seq_converges⟩
end real
|
0d0aa5913dd4414ef419c79111da84ac39838601 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/nat/prime.lean | dab7a6f614ecdd03124baac2a4124dd8c4211cfb | [
"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 | 45,852 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import data.list.prime
import data.list.sort
import data.nat.gcd
import data.nat.sqrt_norm_num
import data.set.finite
import tactic.wlog
import algebra.parity
/-!
# Prime numbers
This file deals with prime numbers: natural numbers `p ≥ 2` whose only divisors are `p` and `1`.
## Important declarations
- `nat.prime`: the predicate that expresses that a natural number `p` is prime
- `nat.primes`: the subtype of natural numbers that are prime
- `nat.min_fac n`: the minimal prime factor of a natural number `n ≠ 1`
- `nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers.
This also appears as `nat.not_bdd_above_set_of_prime` and `nat.infinite_set_of_prime`.
- `nat.factors n`: the prime factorization of `n`
- `nat.factors_unique`: uniqueness of the prime factorisation
- `nat.prime_iff`: `nat.prime` coincides with the general definition of `prime`
- `nat.irreducible_iff_prime`: a non-unit natural number is only divisible by `1` iff it is prime
-/
open bool subtype
open_locale nat
namespace nat
/-- `prime p` means that `p` is a prime number, that is, a natural number
at least 2 whose only divisors are `p` and `1`. -/
@[pp_nodot]
def prime (p : ℕ) := _root_.irreducible p
theorem _root_.irreducible_iff_nat_prime (a : ℕ) : irreducible a ↔ nat.prime a := iff.rfl
theorem not_prime_zero : ¬ prime 0
| h := h.ne_zero rfl
theorem not_prime_one : ¬ prime 1
| h := h.ne_one rfl
theorem prime.ne_zero {n : ℕ} (h : prime n) : n ≠ 0 := irreducible.ne_zero h
theorem prime.pos {p : ℕ} (pp : prime p) : 0 < p := nat.pos_of_ne_zero pp.ne_zero
theorem prime.two_le : ∀ {p : ℕ}, prime p → 2 ≤ p
| 0 h := (not_prime_zero h).elim
| 1 h := (not_prime_one h).elim
| (n+2) _ := le_add_self
theorem prime.one_lt {p : ℕ} : prime p → 1 < p := prime.two_le
instance prime.one_lt' (p : ℕ) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := ⟨hp.1.one_lt⟩
lemma prime.ne_one {p : ℕ} (hp : p.prime) : p ≠ 1 :=
hp.one_lt.ne'
lemma prime.eq_one_or_self_of_dvd {p : ℕ} (pp : p.prime) (m : ℕ) (hm : m ∣ p) : m = 1 ∨ m = p :=
begin
obtain ⟨n, hn⟩ := hm,
have := pp.is_unit_or_is_unit hn,
rw [nat.is_unit_iff, nat.is_unit_iff] at this,
apply or.imp_right _ this,
rintro rfl,
rw [hn, mul_one]
end
theorem prime_def_lt'' {p : ℕ} : prime p ↔ 2 ≤ p ∧ ∀ m ∣ p, m = 1 ∨ m = p :=
begin
refine ⟨λ h, ⟨h.two_le, h.eq_one_or_self_of_dvd⟩, λ h, _⟩,
have h1 := one_lt_two.trans_le h.1,
refine ⟨mt nat.is_unit_iff.mp h1.ne', λ a b hab, _⟩,
simp only [nat.is_unit_iff],
apply or.imp_right _ (h.2 a _),
{ rintro rfl,
rw [←nat.mul_right_inj (pos_of_gt h1), ←hab, mul_one] },
{ rw hab,
exact dvd_mul_right _ _ }
end
theorem prime_def_lt {p : ℕ} : prime p ↔ 2 ≤ p ∧ ∀ m < p, m ∣ p → m = 1 :=
prime_def_lt''.trans $
and_congr_right $ λ p2, forall_congr $ λ m,
⟨λ h l d, (h d).resolve_right (ne_of_lt l),
λ h d, (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left (λ l, h l d)⟩
theorem prime_def_lt' {p : ℕ} : prime p ↔ 2 ≤ p ∧ ∀ m, 2 ≤ m → m < p → ¬ m ∣ p :=
prime_def_lt.trans $ and_congr_right $ λ p2, forall_congr $ λ m,
⟨λ h m2 l d, not_lt_of_ge m2 ((h l d).symm ▸ dec_trivial),
λ h l d, begin
rcases m with _|_|m,
{ rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },
{ refl },
{ exact (h dec_trivial l).elim d }
end⟩
theorem prime_def_le_sqrt {p : ℕ} : prime p ↔ 2 ≤ p ∧
∀ m, 2 ≤ m → m ≤ sqrt p → ¬ m ∣ p :=
prime_def_lt'.trans $ and_congr_right $ λ p2,
⟨λ a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,
λ a, have ∀ {m k}, m ≤ k → 1 < m → p ≠ m * k, from
λ m k mk m1 e, a m m1
(le_sqrt.2 (e.symm ▸ nat.mul_le_mul_left m mk)) ⟨k, e⟩,
λ m m2 l ⟨k, e⟩, begin
cases (le_total m k) with mk km,
{ exact this mk m2 e },
{ rw [mul_comm] at e,
refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,
rwa [one_mul, ← e] }
end⟩
theorem prime_of_coprime (n : ℕ) (h1 : 1 < n) (h : ∀ m < n, m ≠ 0 → n.coprime m) : prime n :=
begin
refine prime_def_lt.mpr ⟨h1, λ m mlt mdvd, _⟩,
have hm : m ≠ 0,
{ rintro rfl,
rw zero_dvd_iff at mdvd,
exact mlt.ne' mdvd },
exact (h m mlt hm).symm.eq_one_of_dvd mdvd,
end
section
/--
This instance is slower than the instance `decidable_prime` defined below,
but has the advantage that it works in the kernel for small values.
If you need to prove that a particular number is prime, in any case
you should not use `dec_trivial`, but rather `by norm_num`, which is
much faster.
-/
local attribute [instance]
def decidable_prime_1 (p : ℕ) : decidable (prime p) :=
decidable_of_iff' _ prime_def_lt'
theorem prime_two : prime 2 := dec_trivial
end
theorem prime.pred_pos {p : ℕ} (pp : prime p) : 0 < pred p :=
lt_pred_iff.2 pp.one_lt
theorem succ_pred_prime {p : ℕ} (pp : prime p) : succ (pred p) = p :=
succ_pred_eq_of_pos pp.pos
theorem dvd_prime {p m : ℕ} (pp : prime p) : m ∣ p ↔ m = 1 ∨ m = p :=
⟨λ d, pp.eq_one_or_self_of_dvd m d, λ h, h.elim (λ e, e.symm ▸ one_dvd _) (λ e, e.symm ▸ dvd_rfl)⟩
theorem dvd_prime_two_le {p m : ℕ} (pp : prime p) (H : 2 ≤ m) : m ∣ p ↔ m = p :=
(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H
theorem prime_dvd_prime_iff_eq {p q : ℕ} (pp : p.prime) (qp : q.prime) : p ∣ q ↔ p = q :=
dvd_prime_two_le qp (prime.two_le pp)
theorem prime.not_dvd_one {p : ℕ} (pp : prime p) : ¬ p ∣ 1 :=
pp.not_dvd_one
theorem not_prime_mul {a b : ℕ} (a1 : 1 < a) (b1 : 1 < b) : ¬ prime (a * b) :=
λ h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $
by simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)
lemma not_prime_mul' {a b n : ℕ} (h : a * b = n) (h₁ : 1 < a) (h₂ : 1 < b) : ¬ prime n :=
by { rw ← h, exact not_prime_mul h₁ h₂ }
lemma prime_mul_iff {a b : ℕ} :
nat.prime (a * b) ↔ (a.prime ∧ b = 1) ∨ (b.prime ∧ a = 1) :=
by simp only [iff_self, irreducible_mul_iff, ←irreducible_iff_nat_prime, nat.is_unit_iff]
lemma prime.dvd_iff_eq {p a : ℕ} (hp : p.prime) (a1 : a ≠ 1) : a ∣ p ↔ p = a :=
begin
refine ⟨_, by { rintro rfl, refl }⟩,
-- rintro ⟨j, rfl⟩ does not work, due to `nat.prime` depending on the class `irreducible`
rintro ⟨j, hj⟩,
rw hj at hp ⊢,
rcases prime_mul_iff.mp hp with ⟨h, rfl⟩ | ⟨h, rfl⟩,
{ exact mul_one _ },
{ exact (a1 rfl).elim }
end
section min_fac
lemma min_fac_lemma (n k : ℕ) (h : ¬ n < k * k) :
sqrt n - k < sqrt n + 2 - k :=
(tsub_lt_tsub_iff_right $ le_sqrt.2 $ le_of_not_gt h).2 $
nat.lt_add_of_pos_right dec_trivial
/-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.
Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.
If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/
def min_fac_aux (n : ℕ) : ℕ → ℕ
| k :=
if h : n < k * k then n else
if k ∣ n then k else
have _, from min_fac_lemma n k h,
min_fac_aux (k + 2)
using_well_founded {rel_tac :=
λ _ _, `[exact ⟨_, measure_wf (λ k, sqrt n + 2 - k)⟩]}
/-- Returns the smallest prime factor of `n ≠ 1`. -/
def min_fac : ℕ → ℕ
| 0 := 2
| 1 := 1
| (n+2) := if 2 ∣ n then 2 else min_fac_aux (n + 2) 3
@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl
@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl
theorem min_fac_eq : ∀ n, min_fac n = if 2 ∣ n then 2 else min_fac_aux n 3
| 0 := by simp
| 1 := by simp [show 2≠1, from dec_trivial]; rw min_fac_aux; refl
| (n+2) :=
have 2 ∣ n + 2 ↔ 2 ∣ n, from
(nat.dvd_add_iff_left (by refl)).symm,
by simp [min_fac, this]; congr
private def min_fac_prop (n k : ℕ) :=
2 ≤ k ∧ k ∣ n ∧ ∀ m, 2 ≤ m → m ∣ n → k ≤ m
theorem min_fac_aux_has_prop {n : ℕ} (n2 : 2 ≤ n) :
∀ k i, k = 2*i+3 → (∀ m, 2 ≤ m → m ∣ n → k ≤ m) → min_fac_prop n (min_fac_aux n k)
| k := λ i e a, begin
rw min_fac_aux,
by_cases h : n < k*k; simp [h],
{ have pp : prime n :=
prime_def_le_sqrt.2 ⟨n2, λ m m2 l d,
not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)⟩,
from ⟨n2, dvd_rfl, λ m m2 d, le_of_eq
((dvd_prime_two_le pp m2).1 d).symm⟩ },
have k2 : 2 ≤ k, { subst e, exact dec_trivial },
by_cases dk : k ∣ n; simp [dk],
{ exact ⟨k2, dk, a⟩ },
{ refine have _, from min_fac_lemma n k h,
min_fac_aux_has_prop (k+2) (i+1)
(by simp [e, left_distrib]) (λ m m2 d, _),
cases nat.eq_or_lt_of_le (a m m2 d) with me ml,
{ subst me, contradiction },
apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,
rw [← me, e] at d, change 2 * (i + 2) ∣ n at d,
have := a _ le_rfl (dvd_of_mul_right_dvd d),
rw e at this, exact absurd this dec_trivial }
end
using_well_founded {rel_tac :=
λ _ _, `[exact ⟨_, measure_wf (λ k, sqrt n + 2 - k)⟩]}
theorem min_fac_has_prop {n : ℕ} (n1 : n ≠ 1) :
min_fac_prop n (min_fac n) :=
begin
by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},
have n2 : 2 ≤ n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },
simp [min_fac_eq],
by_cases d2 : 2 ∣ n; simp [d2],
{ exact ⟨le_rfl, d2, λ k k2 d, k2⟩ },
{ refine min_fac_aux_has_prop n2 3 0 rfl
(λ m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),
exact λ e, e.symm ▸ d }
end
theorem min_fac_dvd (n : ℕ) : min_fac n ∣ n :=
if n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1
theorem min_fac_prime {n : ℕ} (n1 : n ≠ 1) : prime (min_fac n) :=
let ⟨f2, fd, a⟩ := min_fac_has_prop n1 in
prime_def_lt'.2 ⟨f2, λ m m2 l d, not_le_of_gt l (a m m2 (d.trans fd))⟩
theorem min_fac_le_of_dvd {n : ℕ} : ∀ {m : ℕ}, 2 ≤ m → m ∣ n → min_fac n ≤ m :=
by by_cases n1 : n = 1;
[exact λ m m2 d, n1.symm ▸ le_trans dec_trivial m2,
exact (min_fac_has_prop n1).2.2]
theorem min_fac_pos (n : ℕ) : 0 < min_fac n :=
by by_cases n1 : n = 1;
[exact n1.symm ▸ dec_trivial, exact (min_fac_prime n1).pos]
theorem min_fac_le {n : ℕ} (H : 0 < n) : min_fac n ≤ n :=
le_of_dvd H (min_fac_dvd n)
theorem le_min_fac {m n : ℕ} : n = 1 ∨ m ≤ min_fac n ↔ ∀ p, prime p → p ∣ n → m ≤ p :=
⟨λ h p pp d, h.elim
(by rintro rfl; cases pp.not_dvd_one d)
(λ h, le_trans h $ min_fac_le_of_dvd pp.two_le d),
λ H, or_iff_not_imp_left.2 $ λ n1, H _ (min_fac_prime n1) (min_fac_dvd _)⟩
theorem le_min_fac' {m n : ℕ} : n = 1 ∨ m ≤ min_fac n ↔ ∀ p, 2 ≤ p → p ∣ n → m ≤ p :=
⟨λ h p (pp:1<p) d, h.elim
(by rintro rfl; cases not_le_of_lt pp (le_of_dvd dec_trivial d))
(λ h, le_trans h $ min_fac_le_of_dvd pp d),
λ H, le_min_fac.2 (λ p pp d, H p pp.two_le d)⟩
theorem prime_def_min_fac {p : ℕ} : prime p ↔ 2 ≤ p ∧ min_fac p = p :=
⟨λ pp, ⟨pp.two_le,
let ⟨f2, fd, a⟩ := min_fac_has_prop $ ne_of_gt pp.one_lt in
((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)⟩,
λ ⟨p2, e⟩, e ▸ min_fac_prime (ne_of_gt p2)⟩
@[simp] lemma prime.min_fac_eq {p : ℕ} (hp : prime p) : min_fac p = p :=
(prime_def_min_fac.1 hp).2
/--
This instance is faster in the virtual machine than `decidable_prime_1`,
but slower in the kernel.
If you need to prove that a particular number is prime, in any case
you should not use `dec_trivial`, but rather `by norm_num`, which is
much faster.
-/
instance decidable_prime (p : ℕ) : decidable (prime p) :=
decidable_of_iff' _ prime_def_min_fac
theorem not_prime_iff_min_fac_lt {n : ℕ} (n2 : 2 ≤ n) : ¬ prime n ↔ min_fac n < n :=
(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $
(lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm
lemma min_fac_le_div {n : ℕ} (pos : 0 < n) (np : ¬ prime n) : min_fac n ≤ n / min_fac n :=
match min_fac_dvd n with
| ⟨0, h0⟩ := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial
| ⟨1, h1⟩ :=
begin
rw mul_one at h1,
rw [prime_def_min_fac, not_and_distrib, ← h1, eq_self_iff_true, not_true, or_false,
not_le] at np,
rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]
end
| ⟨(x+2), hx⟩ :=
begin
conv_rhs { congr, rw hx },
rw [nat.mul_div_cancel_left _ (min_fac_pos _)],
exact min_fac_le_of_dvd dec_trivial ⟨min_fac n, by rwa mul_comm⟩
end
end
/--
The square of the smallest prime factor of a composite number `n` is at most `n`.
-/
lemma min_fac_sq_le_self {n : ℕ} (w : 0 < n) (h : ¬ prime n) : (min_fac n)^2 ≤ n :=
have t : (min_fac n) ≤ (n/min_fac n) := min_fac_le_div w h,
calc
(min_fac n)^2 = (min_fac n) * (min_fac n) : sq (min_fac n)
... ≤ (n/min_fac n) * (min_fac n) : nat.mul_le_mul_right (min_fac n) t
... ≤ n : div_mul_le_self n (min_fac n)
@[simp]
lemma min_fac_eq_one_iff {n : ℕ} : min_fac n = 1 ↔ n = 1 :=
begin
split,
{ intro h,
by_contradiction hn,
have := min_fac_prime hn,
rw h at this,
exact not_prime_one this, },
{ rintro rfl, refl, }
end
@[simp]
lemma min_fac_eq_two_iff (n : ℕ) : min_fac n = 2 ↔ 2 ∣ n :=
begin
split,
{ intro h,
convert min_fac_dvd _,
rw h, },
{ intro h,
have ub := min_fac_le_of_dvd (le_refl 2) h,
have lb := min_fac_pos n,
apply ub.eq_or_lt.resolve_right (λ h', _),
have := le_antisymm (nat.succ_le_of_lt lb) (lt_succ_iff.mp h'),
rw [eq_comm, nat.min_fac_eq_one_iff] at this,
subst this,
exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two }
end
end min_fac
theorem exists_dvd_of_not_prime {n : ℕ} (n2 : 2 ≤ n) (np : ¬ prime n) :
∃ m, m ∣ n ∧ m ≠ 1 ∧ m ≠ n :=
⟨min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,
ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np⟩
theorem exists_dvd_of_not_prime2 {n : ℕ} (n2 : 2 ≤ n) (np : ¬ prime n) :
∃ m, m ∣ n ∧ 2 ≤ m ∧ m < n :=
⟨min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,
(not_prime_iff_min_fac_lt n2).1 np⟩
theorem exists_prime_and_dvd {n : ℕ} (hn : n ≠ 1) : ∃ p, prime p ∧ p ∣ n :=
⟨min_fac n, min_fac_prime hn, min_fac_dvd _⟩
/-- Euclid's theorem on the **infinitude of primes**.
Here given in the form: for every `n`, there exists a prime number `p ≥ n`. -/
theorem exists_infinite_primes (n : ℕ) : ∃ p, n ≤ p ∧ prime p :=
let p := min_fac (n! + 1) in
have f1 : n! + 1 ≠ 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,
have pp : prime p, from min_fac_prime f1,
have np : n ≤ p, from le_of_not_ge $ λ h,
have h₁ : p ∣ n!, from dvd_factorial (min_fac_pos _) h,
have h₂ : p ∣ 1, from (nat.dvd_add_iff_right h₁).2 (min_fac_dvd _),
pp.not_dvd_one h₂,
⟨p, np, pp⟩
/-- A version of `nat.exists_infinite_primes` using the `bdd_above` predicate. -/
lemma not_bdd_above_set_of_prime : ¬ bdd_above {p | prime p} :=
begin
rw not_bdd_above_iff,
intro n,
obtain ⟨p, hi, hp⟩ := exists_infinite_primes n.succ,
exact ⟨p, hp, hi⟩,
end
/-- A version of `nat.exists_infinite_primes` using the `set.infinite` predicate. -/
lemma infinite_set_of_prime : {p | prime p}.infinite :=
set.infinite_of_not_bdd_above not_bdd_above_set_of_prime
lemma prime.eq_two_or_odd {p : ℕ} (hp : prime p) : p = 2 ∨ p % 2 = 1 :=
p.mod_two_eq_zero_or_one.imp_left
(λ h, ((hp.eq_one_or_self_of_dvd 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)
lemma prime.eq_two_or_odd' {p : ℕ} (hp : prime p) : p = 2 ∨ odd p :=
or.imp_right (λ h, ⟨p / 2, (div_add_mod p 2).symm.trans (congr_arg _ h)⟩) hp.eq_two_or_odd
lemma prime.even_iff {p : ℕ} (hp : prime p) : even p ↔ p = 2 :=
by rw [even_iff_two_dvd, prime_dvd_prime_iff_eq prime_two hp, eq_comm]
/-- A prime `p` satisfies `p % 2 = 1` if and only if `p ≠ 2`. -/
lemma prime.mod_two_eq_one_iff_ne_two {p : ℕ} [fact p.prime] : p % 2 = 1 ↔ p ≠ 2 :=
begin
refine ⟨λ h hf, _, (nat.prime.eq_two_or_odd $ fact.out p.prime).resolve_left⟩,
rw hf at h,
simpa using h,
end
theorem coprime_of_dvd {m n : ℕ} (H : ∀ k, prime k → k ∣ m → ¬ k ∣ n) : coprime m n :=
begin
rw [coprime_iff_gcd_eq_one],
by_contra g2,
obtain ⟨p, hp, hpdvd⟩ := exists_prime_and_dvd g2,
apply H p hp; apply dvd_trans hpdvd,
{ exact gcd_dvd_left _ _ },
{ exact gcd_dvd_right _ _ }
end
theorem coprime_of_dvd' {m n : ℕ} (H : ∀ k, prime k → k ∣ m → k ∣ n → k ∣ 1) : coprime m n :=
coprime_of_dvd $ λk kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn
theorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=
div_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt
/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/
def factors : ℕ → list ℕ
| 0 := []
| 1 := []
| n@(k+2) :=
let m := min_fac n in have n / m < n := factors_lemma,
m :: factors (n / m)
@[simp] lemma factors_zero : factors 0 = [] := by rw factors
@[simp] lemma factors_one : factors 1 = [] := by rw factors
lemma prime_of_mem_factors : ∀ {n p}, p ∈ factors n → prime p
| 0 := by simp
| 1 := by simp
| n@(k+2) := λ p h,
let m := min_fac n in have n / m < n := factors_lemma,
have h₁ : p = m ∨ p ∈ (factors (n / m)) :=
(list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),
or.cases_on h₁ (λ h₂, h₂.symm ▸ min_fac_prime dec_trivial)
prime_of_mem_factors
lemma pos_of_mem_factors {n p : ℕ} (h : p ∈ factors n) : 0 < p :=
prime.pos (prime_of_mem_factors h)
lemma prod_factors : ∀ {n}, n ≠ 0 → list.prod (factors n) = n
| 0 := by simp
| 1 := by simp
| n@(k+2) := λ h,
let m := min_fac n in have n / m < n := factors_lemma,
show (factors n).prod = n, from
have h₁ : n / m ≠ 0 := λ h,
have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,
by rw zero_mul at this; exact (show k + 2 ≠ 0, from dec_trivial) this,
by rw [factors, list.prod_cons, prod_factors h₁, nat.mul_div_cancel' (min_fac_dvd _)]
lemma factors_prime {p : ℕ} (hp : nat.prime p) : p.factors = [p] :=
begin
have : p = (p - 2) + 2 := (tsub_eq_iff_eq_add_of_le hp.two_le).mp rfl,
rw [this, nat.factors],
simp only [eq.symm this],
have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,
split,
{ exact this, },
{ simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },
end
lemma factors_chain : ∀ {n a}, (∀ p, prime p → p ∣ n → a ≤ p) → list.chain (≤) a (factors n)
| 0 := λ a h, by simp
| 1 := λ a h, by simp
| n@(k+2) := λ a h,
let m := min_fac n in have n / m < n := factors_lemma,
begin
rw factors,
refine list.chain.cons ((le_min_fac.2 h).resolve_left dec_trivial) (factors_chain _),
exact λ p pp d, min_fac_le_of_dvd pp.two_le (d.trans $ div_dvd_of_dvd $ min_fac_dvd _),
end
lemma factors_chain_2 (n) : list.chain (≤) 2 (factors n) := factors_chain $ λ p pp _, pp.two_le
lemma factors_chain' (n) : list.chain' (≤) (factors n) :=
@list.chain'.tail _ _ (_::_) (factors_chain_2 _)
lemma factors_sorted (n : ℕ) : list.sorted (≤) (factors n) :=
list.chain'_iff_pairwise.1 (factors_chain' _)
/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/
lemma factors_add_two (n : ℕ) :
factors (n+2) = min_fac (n+2) :: factors ((n+2) / min_fac (n+2)) :=
by rw factors
@[simp]
lemma factors_eq_nil (n : ℕ) : n.factors = [] ↔ n = 0 ∨ n = 1 :=
begin
split; intro h,
{ rcases n with (_ | _ | n),
{ exact or.inl rfl },
{ exact or.inr rfl },
{ rw factors at h, injection h }, },
{ rcases h with (rfl | rfl),
{ exact factors_zero },
{ exact factors_one }, }
end
lemma eq_of_perm_factors {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : a.factors ~ b.factors) : a = b :=
by simpa [prod_factors ha, prod_factors hb] using list.perm.prod_eq h
theorem prime.coprime_iff_not_dvd {p n : ℕ} (pp : prime p) : coprime p n ↔ ¬ p ∣ n :=
⟨λ co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),
λ nd, coprime_of_dvd $ λ m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm ▸ nd⟩
theorem prime.dvd_iff_not_coprime {p n : ℕ} (pp : prime p) : p ∣ n ↔ ¬ coprime p n :=
iff_not_comm.2 pp.coprime_iff_not_dvd
theorem prime.not_coprime_iff_dvd {m n : ℕ} :
¬ coprime m n ↔ ∃p, prime p ∧ p ∣ m ∧ p ∣ n :=
begin
apply iff.intro,
{ intro h,
exact ⟨min_fac (gcd m n), min_fac_prime h,
((min_fac_dvd (gcd m n)).trans (gcd_dvd_left m n)),
((min_fac_dvd (gcd m n)).trans (gcd_dvd_right m n))⟩ },
{ intro h,
cases h with p hp,
apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }
end
theorem prime.dvd_mul {p m n : ℕ} (pp : prime p) : p ∣ m * n ↔ p ∣ m ∨ p ∣ n :=
⟨λ H, or_iff_not_imp_left.2 $ λ h,
(pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,
or.rec (λ h : p ∣ m, h.mul_right _) (λ h : p ∣ n, h.mul_left _)⟩
theorem prime.not_dvd_mul {p m n : ℕ} (pp : prime p)
(Hm : ¬ p ∣ m) (Hn : ¬ p ∣ n) : ¬ p ∣ m * n :=
mt pp.dvd_mul.1 $ by simp [Hm, Hn]
theorem prime_iff {p : ℕ} : p.prime ↔ _root_.prime p :=
⟨λ h, ⟨h.ne_zero, h.not_unit, λ a b, h.dvd_mul.mp⟩, prime.irreducible⟩
theorem irreducible_iff_prime {p : ℕ} : irreducible p ↔ _root_.prime p :=
by rw [←prime_iff, prime]
theorem prime.dvd_of_dvd_pow {p m n : ℕ} (pp : prime p) (h : p ∣ m^n) : p ∣ m :=
begin
induction n with n IH,
{ exact pp.not_dvd_one.elim h },
{ rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH }
end
lemma prime.pow_not_prime {x n : ℕ} (hn : 2 ≤ n) : ¬ (x ^ n).prime :=
λ hp, (hp.eq_one_or_self_of_dvd x $ dvd_trans ⟨x, sq _⟩ (pow_dvd_pow _ hn)).elim
(λ hx1, hp.ne_one $ hx1.symm ▸ one_pow _)
(λ hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm
... < x ^ n : nat.pow_right_strict_mono (hxn.symm ▸ hp.two_le) hn
... = x : hxn.symm)
lemma prime.pow_not_prime' {x : ℕ} : ∀ {n : ℕ}, n ≠ 1 → ¬ (x ^ n).prime
| 0 := λ _, not_prime_one
| 1 := λ h, (h rfl).elim
| (n+2) := λ _, prime.pow_not_prime le_add_self
lemma prime.eq_one_of_pow {x n : ℕ} (h : (x ^ n).prime) : n = 1 :=
not_imp_not.mp prime.pow_not_prime' h
lemma prime.pow_eq_iff {p a k : ℕ} (hp : p.prime) : a ^ k = p ↔ a = p ∧ k = 1 :=
begin
refine ⟨λ h, _, λ h, by rw [h.1, h.2, pow_one]⟩,
rw ←h at hp,
rw [←h, hp.eq_one_of_pow, eq_self_iff_true, and_true, pow_one],
end
lemma pow_min_fac {n k : ℕ} (hk : k ≠ 0) : (n^k).min_fac = n.min_fac :=
begin
rcases eq_or_ne n 1 with rfl | hn,
{ simp },
have hnk : n ^ k ≠ 1 := λ hk', hn ((pow_eq_one_iff hk).1 hk'),
apply (min_fac_le_of_dvd (min_fac_prime hn).two_le ((min_fac_dvd n).pow hk)).antisymm,
apply min_fac_le_of_dvd (min_fac_prime hnk).two_le
((min_fac_prime hnk).dvd_of_dvd_pow (min_fac_dvd _)),
end
lemma prime.pow_min_fac {p k : ℕ} (hp : p.prime) (hk : k ≠ 0) : (p^k).min_fac = p :=
by rw [pow_min_fac hk, hp.min_fac_eq]
lemma prime.mul_eq_prime_sq_iff {x y p : ℕ} (hp : p.prime) (hx : x ≠ 1) (hy : y ≠ 1) :
x * y = p ^ 2 ↔ x = p ∧ y = p :=
⟨λ h, have pdvdxy : p ∣ x * y, by rw h; simp [sq],
begin
wlog := hp.dvd_mul.1 pdvdxy using x y,
cases case with a ha,
have hap : a ∣ p, from ⟨y, by rwa [ha, sq,
mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at h⟩,
exact ((nat.dvd_prime hp).1 hap).elim
(λ _, by clear_aux_decl; simp [*, sq, nat.mul_right_inj hp.pos] at *
{contextual := tt})
(λ _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,
nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *
{contextual := tt})
end,
λ ⟨h₁, h₂⟩, h₁.symm ▸ h₂.symm ▸ (sq _).symm⟩
lemma prime.dvd_factorial : ∀ {n p : ℕ} (hp : prime p), p ∣ n! ↔ p ≤ n
| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)
| (n+1) p hp := begin
rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],
exact ⟨λ h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,
λ h, (_root_.lt_or_eq_of_le h).elim (or.inr ∘ le_of_lt_succ)
(λ h, or.inl $ by rw h)⟩
end
theorem prime.coprime_pow_of_not_dvd {p m a : ℕ} (pp : prime p) (h : ¬ p ∣ a) : coprime a (p^m) :=
(pp.coprime_iff_not_dvd.2 h).symm.pow_right _
theorem coprime_primes {p q : ℕ} (pp : prime p) (pq : prime q) : coprime p q ↔ p ≠ q :=
pp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le
theorem coprime_pow_primes {p q : ℕ} (n m : ℕ) (pp : prime p) (pq : prime q) (h : p ≠ q) :
coprime (p^n) (q^m) :=
((coprime_primes pp pq).2 h).pow _ _
theorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : ℕ) : coprime p i ∨ p ∣ i :=
by rw [pp.dvd_iff_not_coprime]; apply em
lemma coprime_of_lt_prime {n p} (n_pos : 0 < n) (hlt : n < p) (pp : prime p) :
coprime p n :=
(coprime_or_dvd_of_prime pp n).resolve_right $ λ h, lt_le_antisymm hlt (le_of_dvd n_pos h)
lemma eq_or_coprime_of_le_prime {n p} (n_pos : 0 < n) (hle : n ≤ p) (pp : prime p) :
p = n ∨ coprime p n :=
hle.eq_or_lt.imp eq.symm (λ h, coprime_of_lt_prime n_pos h pp)
theorem dvd_prime_pow {p : ℕ} (pp : prime p) {m i : ℕ} : i ∣ (p^m) ↔ ∃ k ≤ m, i = p^k :=
by simp_rw [dvd_prime_pow (prime_iff.mp pp) m, associated_eq_eq]
lemma prime.dvd_mul_of_dvd_ne {p1 p2 n : ℕ} (h_neq : p1 ≠ p2) (pp1 : prime p1) (pp2 : prime p2)
(h1 : p1 ∣ n) (h2 : p2 ∣ n) : (p1 * p2 ∣ n) :=
coprime.mul_dvd_of_dvd_of_dvd ((coprime_primes pp1 pp2).mpr h_neq) h1 h2
/--
If `p` is prime,
and `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`
then `a = p^(k+1)`.
-/
lemma eq_prime_pow_of_dvd_least_prime_pow
{a p k : ℕ} (pp : prime p) (h₁ : ¬(a ∣ p^k)) (h₂ : a ∣ p^(k+1)) :
a = p^(k+1) :=
begin
obtain ⟨l, ⟨h, rfl⟩⟩ := (dvd_prime_pow pp).1 h₂,
congr,
exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 h₁)),
end
lemma ne_one_iff_exists_prime_dvd : ∀ {n}, n ≠ 1 ↔ ∃ p : ℕ, p.prime ∧ p ∣ n
| 0 := by simpa using (Exists.intro 2 nat.prime_two)
| 1 := by simp [nat.not_prime_one]
| (n+2) :=
let a := n+2 in
let ha : a ≠ 1 := nat.succ_succ_ne_one n in
begin
simp only [true_iff, ne.def, not_false_iff, ha],
exact ⟨a.min_fac, nat.min_fac_prime ha, a.min_fac_dvd⟩,
end
lemma eq_one_iff_not_exists_prime_dvd {n : ℕ} : n = 1 ↔ ∀ p : ℕ, p.prime → ¬p ∣ n :=
by simpa using not_iff_not.mpr ne_one_iff_exists_prime_dvd
section
open list
lemma mem_factors_iff_dvd {n p : ℕ} (hn : n ≠ 0) (hp : prime p) : p ∈ factors n ↔ p ∣ n :=
⟨λ h, prod_factors hn ▸ list.dvd_prod h,
λ h, mem_list_primes_of_dvd_prod
(prime_iff.mp hp)
(λ p h, prime_iff.mp (prime_of_mem_factors h))
((prod_factors hn).symm ▸ h)⟩
lemma dvd_of_mem_factors {n p : ℕ} (h : p ∈ n.factors) : p ∣ n :=
begin
rcases n.eq_zero_or_pos with rfl | hn,
{ exact dvd_zero p },
{ rwa ←mem_factors_iff_dvd hn.ne' (prime_of_mem_factors h) }
end
lemma mem_factors {n p} (hn : n ≠ 0) : p ∈ factors n ↔ prime p ∧ p ∣ n :=
⟨λ h, ⟨prime_of_mem_factors h, dvd_of_mem_factors h⟩,
λ ⟨hprime, hdvd⟩, (mem_factors_iff_dvd hn hprime).mpr hdvd⟩
lemma le_of_mem_factors {n p : ℕ} (h : p ∈ n.factors) : p ≤ n :=
begin
rcases n.eq_zero_or_pos with rfl | hn,
{ rw factors_zero at h, cases h },
{ exact le_of_dvd hn (dvd_of_mem_factors h) },
end
/-- **Fundamental theorem of arithmetic**-/
lemma factors_unique {n : ℕ} {l : list ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, prime p) :
l ~ factors n :=
begin
refine perm_of_prod_eq_prod _ _ _,
{ rw h₁,
refine (prod_factors _).symm,
rintro rfl,
rw prod_eq_zero_iff at h₁,
exact prime.ne_zero (h₂ 0 h₁) rfl },
{ simp_rw ←prime_iff, exact h₂ },
{ simp_rw ←prime_iff, exact (λ p, prime_of_mem_factors) },
end
lemma prime.factors_pow {p : ℕ} (hp : p.prime) (n : ℕ) :
(p ^ n).factors = list.repeat p n :=
begin
symmetry,
rw ← list.repeat_perm,
apply nat.factors_unique (list.prod_repeat p n),
intros q hq,
rwa eq_of_mem_repeat hq,
end
lemma eq_prime_pow_of_unique_prime_dvd {n p : ℕ} (hpos : n ≠ 0)
(h : ∀ {d}, nat.prime d → d ∣ n → d = p) :
n = p ^ n.factors.length :=
begin
set k := n.factors.length,
rw [←prod_factors hpos, ←prod_repeat p k,
eq_repeat_of_mem (λ d hd, h (prime_of_mem_factors hd) (dvd_of_mem_factors hd))],
end
/-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/
lemma perm_factors_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
(a * b).factors ~ a.factors ++ b.factors :=
begin
refine (factors_unique _ _).symm,
{ rw [list.prod_append, prod_factors ha, prod_factors hb] },
{ intros p hp,
rw list.mem_append at hp,
cases hp;
exact prime_of_mem_factors hp },
end
/-- For coprime `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/
lemma perm_factors_mul_of_coprime {a b : ℕ} (hab : coprime a b) :
(a * b).factors ~ a.factors ++ b.factors :=
begin
rcases a.eq_zero_or_pos with rfl | ha,
{ simp [(coprime_zero_left _).mp hab] },
rcases b.eq_zero_or_pos with rfl | hb,
{ simp [(coprime_zero_right _).mp hab] },
exact perm_factors_mul ha.ne' hb.ne',
end
lemma factors_sublist_right {n k : ℕ} (h : k ≠ 0) : n.factors <+ (n * k).factors :=
begin
cases n,
{ rw zero_mul },
apply sublist_of_subperm_of_sorted _ (factors_sorted _) (factors_sorted _),
rw (perm_factors_mul n.succ_ne_zero h).subperm_left,
exact (sublist_append_left _ _).subperm,
end
lemma factors_sublist_of_dvd {n k : ℕ} (h : n ∣ k) (h' : k ≠ 0) : n.factors <+ k.factors :=
begin
obtain ⟨a, rfl⟩ := h,
exact factors_sublist_right (right_ne_zero_of_mul h'),
end
lemma factors_subset_right {n k : ℕ} (h : k ≠ 0) : n.factors ⊆ (n * k).factors :=
(factors_sublist_right h).subset
lemma factors_subset_of_dvd {n k : ℕ} (h : n ∣ k) (h' : k ≠ 0) : n.factors ⊆ k.factors :=
(factors_sublist_of_dvd h h').subset
lemma dvd_of_factors_subperm {a b : ℕ} (ha : a ≠ 0) (h : a.factors <+~ b.factors) : a ∣ b :=
begin
rcases b.eq_zero_or_pos with rfl | hb,
{ exact dvd_zero _ },
rcases a with (_|_|a),
{ exact (ha rfl).elim },
{ exact one_dvd _ },
use (b.factors.diff a.succ.succ.factors).prod,
nth_rewrite 0 ←nat.prod_factors ha,
rw [←list.prod_append,
list.perm.prod_eq $ list.subperm_append_diff_self_of_count_le $ list.subperm_ext_iff.mp h,
nat.prod_factors hb.ne']
end
end
lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : prime p) {m n k l : ℕ}
(hpm : p ^ k ∣ m) (hpn : p ^ l ∣ n) (hpmn : p ^ (k+l+1) ∣ m*n) :
p ^ (k+1) ∣ m ∨ p ^ (l+1) ∣ n :=
have hpd : p^(k+l)*p ∣ m*n, by rwa pow_succ' at hpmn,
have hpd2 : p ∣ (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,
have hpd3 : p ∣ (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,
have hpd4 : p ∣ (m / p^k) * (n / p^l), by simpa [nat.div_mul_div_comm hpm hpn] using hpd3,
have hpd5 : p ∣ (m / p^k) ∨ p ∣ (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,
suffices p^k*p ∣ m ∨ p^l*p ∣ n, by rwa [pow_succ', pow_succ'],
hpd5.elim
(assume : p ∣ m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)
(assume : p ∣ n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)
lemma prime_iff_prime_int {p : ℕ} : p.prime ↔ _root_.prime (p : ℤ) :=
⟨λ hp, ⟨int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt int.is_unit_iff_nat_abs_eq.1 hp.ne_one,
λ a b h, by rw [← int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;
rwa [← int.dvd_nat_abs, int.coe_nat_dvd, ← int.dvd_nat_abs, int.coe_nat_dvd]⟩,
λ hp, nat.prime_iff.2 ⟨int.coe_nat_ne_zero.1 hp.1,
mt nat.is_unit_iff.1 $ λ h, by simpa [h, not_prime_one] using hp,
λ a b, by simpa only [int.coe_nat_dvd, (int.coe_nat_mul _ _).symm] using hp.2.2 a b⟩⟩
/-- The type of prime numbers -/
def primes := {p : ℕ // p.prime}
namespace primes
instance : has_repr nat.primes := ⟨λ p, repr p.val⟩
instance inhabited_primes : inhabited primes := ⟨⟨2, prime_two⟩⟩
instance coe_nat : has_coe nat.primes ℕ := ⟨subtype.val⟩
theorem coe_nat_inj (p q : nat.primes) : (p : ℕ) = (q : ℕ) → p = q :=
λ h, subtype.eq h
end primes
instance monoid.prime_pow {α : Type*} [monoid α] : has_pow α primes := ⟨λ x p, x^p.val⟩
end nat
/-! ### Primality prover -/
open norm_num
namespace tactic
namespace norm_num
lemma is_prime_helper (n : ℕ)
(h₁ : 1 < n) (h₂ : nat.min_fac n = n) : nat.prime n :=
nat.prime_def_min_fac.2 ⟨h₁, h₂⟩
lemma min_fac_bit0 (n : ℕ) : nat.min_fac (bit0 n) = 2 :=
by simp [nat.min_fac_eq, show 2 ∣ bit0 n, by simp [bit0_eq_two_mul n]]
/-- A predicate representing partial progress in a proof of `min_fac`. -/
def min_fac_helper (n k : ℕ) : Prop :=
0 < k ∧ bit1 k ≤ nat.min_fac (bit1 n)
theorem min_fac_helper.n_pos {n k : ℕ} (h : min_fac_helper n k) : 0 < n :=
pos_iff_ne_zero.2 $ λ e,
by rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2
lemma min_fac_ne_bit0 {n k : ℕ} : nat.min_fac (bit1 n) ≠ bit0 k :=
begin
rw bit0_eq_two_mul,
refine (λ e, absurd ((nat.dvd_add_iff_right _).2
(dvd_trans ⟨_, e⟩ (nat.min_fac_dvd _))) _); simp
end
lemma min_fac_helper_0 (n : ℕ) (h : 0 < n) : min_fac_helper n 1 :=
begin
refine ⟨zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symm⟩,
rw nat.succ_le_iff,
refine lt_of_le_of_ne (nat.min_fac_pos _) (λ e, nat.not_prime_one _),
rw e,
exact nat.min_fac_prime (nat.bit1_lt h).ne',
end
lemma min_fac_helper_1 {n k k' : ℕ} (e : k + 1 = k')
(np : nat.min_fac (bit1 n) ≠ bit1 k)
(h : min_fac_helper n k) : min_fac_helper n k' :=
begin
rw ← e,
refine ⟨nat.succ_pos _,
(lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)
min_fac_ne_bit0.symm : bit0 (k+1) < _)⟩,
{ rw add_right_comm, exact h.2 },
{ rw add_right_comm, exact np.symm }
end
lemma min_fac_helper_2 (n k k' : ℕ) (e : k + 1 = k')
(np : ¬ nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=
begin
refine min_fac_helper_1 e _ h,
intro e₁, rw ← e₁ at np,
exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)
end
lemma min_fac_helper_3 (n k k' c : ℕ) (e : k + 1 = k')
(nc : bit1 n % bit1 k = c) (c0 : 0 < c)
(h : min_fac_helper n k) : min_fac_helper n k' :=
begin
refine min_fac_helper_1 e _ h,
refine mt _ (ne_of_gt c0), intro e₁,
rw [← nc, ← nat.dvd_iff_mod_eq_zero, ← e₁],
apply nat.min_fac_dvd
end
lemma min_fac_helper_4 (n k : ℕ) (hd : bit1 n % bit1 k = 0)
(h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=
by { rw ← nat.dvd_iff_mod_eq_zero at hd,
exact le_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2 }
lemma min_fac_helper_5 (n k k' : ℕ) (e : bit1 k * bit1 k = k')
(hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=
begin
refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2
⟨nat.bit1_lt h.n_pos, _⟩)).2,
rw ← e at hd,
intros m m2 hm md,
have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),
rw nat.le_sqrt at this,
exact not_le_of_lt hd this
end
/-- Given `e` a natural numeral and `d : nat` a factor of it, return `⊢ ¬ prime e`. -/
meta def prove_non_prime (e : expr) (n d₁ : ℕ) : tactic expr :=
do let e₁ := reflect d₁,
c ← mk_instance_cache `(nat),
(c, p₁) ← prove_lt_nat c `(1) e₁,
let d₂ := n / d₁, let e₂ := reflect d₂,
(c, e', p) ← prove_mul_nat c e₁ e₂,
guard (e' =ₐ e),
(c, p₂) ← prove_lt_nat c `(1) e₂,
return $ `(@nat.not_prime_mul').mk_app [e₁, e₂, e, p, p₁, p₂]
/-- Given `a`,`a1 := bit1 a`, `n1` the value of `a1`, `b` and `p : min_fac_helper a b`,
returns `(c, ⊢ min_fac a1 = c)`. -/
meta def prove_min_fac_aux (a a1 : expr) (n1 : ℕ) :
instance_cache → expr → expr → tactic (instance_cache × expr × expr)
| ic b p := do
k ← b.to_nat,
let k1 := bit1 k,
let b1 := `(bit1:ℕ→ℕ).mk_app [b],
if n1 < k1*k1 then do
(ic, e', p₁) ← prove_mul_nat ic b1 b1,
(ic, p₂) ← prove_lt_nat ic a1 e',
return (ic, a1, `(min_fac_helper_5).mk_app [a, b, e', p₁, p₂, p])
else let d := k1.min_fac in
if to_bool (d < k1) then do
let k' := k+1, let e' := reflect k',
(ic, p₁) ← prove_succ ic b e',
p₂ ← prove_non_prime b1 k1 d,
prove_min_fac_aux ic e' $ `(min_fac_helper_2).mk_app [a, b, e', p₁, p₂, p]
else do
let nc := n1 % k1,
(ic, c, pc) ← prove_div_mod ic a1 b1 tt,
if nc = 0 then
return (ic, b1, `(min_fac_helper_4).mk_app [a, b, pc, p])
else do
(ic, p₀) ← prove_pos ic c,
let k' := k+1, let e' := reflect k',
(ic, p₁) ← prove_succ ic b e',
prove_min_fac_aux ic e' $ `(min_fac_helper_3).mk_app [a, b, e', c, p₁, pc, p₀, p]
/-- Given `a` a natural numeral, returns `(b, ⊢ min_fac a = b)`. -/
meta def prove_min_fac (ic : instance_cache) (e : expr) : tactic (instance_cache × expr × expr) :=
match match_numeral e with
| match_numeral_result.zero := return (ic, `(2:ℕ), `(nat.min_fac_zero))
| match_numeral_result.one := return (ic, `(1:ℕ), `(nat.min_fac_one))
| match_numeral_result.bit0 e := return (ic, `(2), `(min_fac_bit0).mk_app [e])
| match_numeral_result.bit1 e := do
n ← e.to_nat,
c ← mk_instance_cache `(nat),
(c, p) ← prove_pos c e,
let a1 := `(bit1:ℕ→ℕ).mk_app [e],
prove_min_fac_aux e a1 (bit1 n) c `(1) (`(min_fac_helper_0).mk_app [e, p])
| _ := failed
end
/-- A partial proof of `factors`. Asserts that `l` is a sorted list of primes, lower bounded by a
prime `p`, which multiplies to `n`. -/
def factors_helper (n p : ℕ) (l : list ℕ) : Prop :=
p.prime → list.chain (≤) p l ∧ (∀ a ∈ l, nat.prime a) ∧ list.prod l = n
lemma factors_helper_nil (a : ℕ) : factors_helper 1 a [] :=
λ pa, ⟨list.chain.nil, by rintro _ ⟨⟩, list.prod_nil⟩
lemma factors_helper_cons' (n m a b : ℕ) (l : list ℕ)
(h₁ : b * m = n) (h₂ : a ≤ b) (h₃ : nat.min_fac b = b)
(H : factors_helper m b l) : factors_helper n a (b :: l) :=
λ pa,
have pb : b.prime, from nat.prime_def_min_fac.2 ⟨le_trans pa.two_le h₂, h₃⟩,
let ⟨f₁, f₂, f₃⟩ := H pb in
⟨list.chain.cons h₂ f₁, λ c h, h.elim (λ e, e.symm ▸ pb) (f₂ _),
by rw [list.prod_cons, f₃, h₁]⟩
lemma factors_helper_cons (n m a b : ℕ) (l : list ℕ)
(h₁ : b * m = n) (h₂ : a < b) (h₃ : nat.min_fac b = b)
(H : factors_helper m b l) : factors_helper n a (b :: l) :=
factors_helper_cons' _ _ _ _ _ h₁ h₂.le h₃ H
lemma factors_helper_sn (n a : ℕ) (h₁ : a < n) (h₂ : nat.min_fac n = n) : factors_helper n a [n] :=
factors_helper_cons _ _ _ _ _ (mul_one _) h₁ h₂ (factors_helper_nil _)
lemma factors_helper_same (n m a : ℕ) (l : list ℕ) (h : a * m = n)
(H : factors_helper m a l) : factors_helper n a (a :: l) :=
λ pa, factors_helper_cons' _ _ _ _ _ h le_rfl (nat.prime_def_min_fac.1 pa).2 H pa
lemma factors_helper_same_sn (a : ℕ) : factors_helper a a [a] :=
factors_helper_same _ _ _ _ (mul_one _) (factors_helper_nil _)
lemma factors_helper_end (n : ℕ) (l : list ℕ) (H : factors_helper n 2 l) : nat.factors n = l :=
let ⟨h₁, h₂, h₃⟩ := H nat.prime_two in
have _, from list.chain'_iff_pairwise.1 (@list.chain'.tail _ _ (_::_) h₁),
(list.eq_of_perm_of_sorted (nat.factors_unique h₃ h₂) this (nat.factors_sorted _)).symm
/-- Given `n` and `a` natural numerals, returns `(l, ⊢ factors_helper n a l)`. -/
meta def prove_factors_aux :
instance_cache → expr → expr → ℕ → ℕ → tactic (instance_cache × expr × expr)
| c en ea n a :=
let b := n.min_fac in
if b < n then do
let m := n / b,
(c, em) ← c.of_nat m,
if b = a then do
(c, _, p₁) ← prove_mul_nat c ea em,
(c, l, p₂) ← prove_factors_aux c em ea m a,
pure (c, `(%%ea::%%l:list ℕ), `(factors_helper_same).mk_app [en, em, ea, l, p₁, p₂])
else do
(c, eb) ← c.of_nat b,
(c, _, p₁) ← prove_mul_nat c eb em,
(c, p₂) ← prove_lt_nat c ea eb,
(c, _, p₃) ← prove_min_fac c eb,
(c, l, p₄) ← prove_factors_aux c em eb m b,
pure (c, `(%%eb::%%l : list ℕ),
`(factors_helper_cons).mk_app [en, em, ea, eb, l, p₁, p₂, p₃, p₄])
else if b = a then
pure (c, `([%%ea] : list ℕ), `(factors_helper_same_sn).mk_app [ea])
else do
(c, p₁) ← prove_lt_nat c ea en,
(c, _, p₂) ← prove_min_fac c en,
pure (c, `([%%en] : list ℕ), `(factors_helper_sn).mk_app [en, ea, p₁, p₂])
/-- Evaluates the `prime` and `min_fac` functions. -/
@[norm_num] meta def eval_prime : expr → tactic (expr × expr)
| `(nat.prime %%e) := do
n ← e.to_nat,
match n with
| 0 := false_intro `(nat.not_prime_zero)
| 1 := false_intro `(nat.not_prime_one)
| _ := let d₁ := n.min_fac in
if d₁ < n then prove_non_prime e n d₁ >>= false_intro
else do
let e₁ := reflect d₁,
c ← mk_instance_cache `(ℕ),
(c, p₁) ← prove_lt_nat c `(1) e₁,
(c, e₁, p) ← prove_min_fac c e,
true_intro $ `(is_prime_helper).mk_app [e, p₁, p]
end
| `(nat.min_fac %%e) := do
ic ← mk_instance_cache `(ℕ),
prod.snd <$> prove_min_fac ic e
| `(nat.factors %%e) := do
n ← e.to_nat,
match n with
| 0 := pure (`(@list.nil ℕ), `(nat.factors_zero))
| 1 := pure (`(@list.nil ℕ), `(nat.factors_one))
| _ := do
c ← mk_instance_cache `(ℕ),
(c, l, p) ← prove_factors_aux c e `(2) n 2,
pure (l, `(factors_helper_end).mk_app [e, l, p])
end
| _ := failed
end norm_num
end tactic
namespace nat
theorem prime_three : prime 3 := by norm_num
instance fact_prime_two : fact (prime 2) := ⟨prime_two⟩
instance fact_prime_three : fact (prime 3) := ⟨prime_three⟩
end nat
namespace nat
lemma mem_factors_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) {p : ℕ} :
p ∈ (a * b).factors ↔ p ∈ a.factors ∨ p ∈ b.factors :=
begin
rw [mem_factors (mul_ne_zero ha hb), mem_factors ha, mem_factors hb, ←and_or_distrib_left],
simpa only [and.congr_right_iff] using prime.dvd_mul
end
/-- If `a`, `b` are positive, the prime divisors of `a * b` are the union of those of `a` and `b` -/
lemma factors_mul_to_finset {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
(a * b).factors.to_finset = a.factors.to_finset ∪ b.factors.to_finset :=
(list.to_finset.ext $ λ x, (mem_factors_mul ha hb).trans list.mem_union.symm).trans $
list.to_finset_union _ _
lemma pow_succ_factors_to_finset (n k : ℕ) :
(n^(k+1)).factors.to_finset = n.factors.to_finset :=
begin
rcases eq_or_ne n 0 with rfl | hn,
{ simp },
induction k with k ih,
{ simp },
rw [pow_succ, factors_mul_to_finset hn (pow_ne_zero _ hn), ih, finset.union_idempotent]
end
lemma pow_factors_to_finset (n : ℕ) {k : ℕ} (hk : k ≠ 0) :
(n^k).factors.to_finset = n.factors.to_finset :=
begin
cases k,
{ simpa using hk },
rw pow_succ_factors_to_finset
end
/-- The only prime divisor of positive prime power `p^k` is `p` itself -/
lemma prime_pow_prime_divisor {p k : ℕ} (hk : k ≠ 0) (hp : prime p) :
(p^k).factors.to_finset = {p} :=
by simp [pow_factors_to_finset p hk, factors_prime hp]
/-- The sets of factors of coprime `a` and `b` are disjoint -/
lemma coprime_factors_disjoint {a b : ℕ} (hab : a.coprime b) : list.disjoint a.factors b.factors :=
begin
intros q hqa hqb,
apply not_prime_one,
rw ←(eq_one_of_dvd_coprimes hab (dvd_of_mem_factors hqa) (dvd_of_mem_factors hqb)),
exact prime_of_mem_factors hqa
end
lemma mem_factors_mul_of_coprime {a b : ℕ} (hab : coprime a b) (p : ℕ):
p ∈ (a * b).factors ↔ p ∈ a.factors ∪ b.factors :=
begin
rcases a.eq_zero_or_pos with rfl | ha,
{ simp [(coprime_zero_left _).mp hab] },
rcases b.eq_zero_or_pos with rfl | hb,
{ simp [(coprime_zero_right _).mp hab] },
rw [mem_factors_mul ha.ne' hb.ne', list.mem_union]
end
lemma factors_mul_to_finset_of_coprime {a b : ℕ} (hab : coprime a b) :
(a * b).factors.to_finset = a.factors.to_finset ∪ b.factors.to_finset :=
(list.to_finset.ext $ mem_factors_mul_of_coprime hab).trans $ list.to_finset_union _ _
open list
/-- If `p` is a prime factor of `a` then `p` is also a prime factor of `a * b` for any `b > 0` -/
lemma mem_factors_mul_left {p a b : ℕ} (hpa : p ∈ a.factors) (hb : b ≠ 0) : p ∈ (a*b).factors :=
begin
rcases eq_or_ne a 0 with rfl | ha,
{ simpa using hpa },
apply (mem_factors_mul ha hb).2 (or.inl hpa),
end
/-- If `p` is a prime factor of `b` then `p` is also a prime factor of `a * b` for any `a > 0` -/
lemma mem_factors_mul_right {p a b : ℕ} (hpb : p ∈ b.factors) (ha : a ≠ 0) : p ∈ (a*b).factors :=
by { rw mul_comm, exact mem_factors_mul_left hpb ha }
lemma eq_two_pow_or_exists_odd_prime_and_dvd (n : ℕ) :
(∃ k : ℕ, n = 2 ^ k) ∨ ∃ p, nat.prime p ∧ p ∣ n ∧ odd p :=
(eq_or_ne n 0).elim
(λ hn, (or.inr ⟨3, prime_three, hn.symm ▸ dvd_zero 3, ⟨1, rfl⟩⟩))
(λ hn, or_iff_not_imp_right.mpr
(λ H, ⟨n.factors.length, eq_prime_pow_of_unique_prime_dvd hn
(λ p hprime hdvd, hprime.eq_two_or_odd'.resolve_right
(λ hodd, H ⟨p, hprime, hdvd, hodd⟩))⟩))
end nat
namespace int
lemma prime_two : prime (2 : ℤ) := nat.prime_iff_prime_int.mp nat.prime_two
lemma prime_three : prime (3 : ℤ) := nat.prime_iff_prime_int.mp nat.prime_three
end int
|
cbb80dfe7d27cda3daa968c0be21f2b2ae445730 | bb31430994044506fa42fd667e2d556327e18dfe | /src/analysis/seminorm.lean | e939177b3737f49de11901e8bf30a5f8f52140da | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 40,487 | lean | /-
Copyright (c) 2019 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Yaël Dillies, Moritz Doll
-/
import data.real.pointwise
import analysis.convex.function
import analysis.locally_convex.basic
import analysis.normed.group.add_torsor
/-!
# Seminorms
This file defines seminorms.
A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and
subadditive. They are closely related to convex sets and a topological vector space is locally
convex if and only if its topology is induced by a family of seminorms.
## Main declarations
For a module over a normed ring:
* `seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and
subadditive.
* `norm_seminorm 𝕜 E`: The norm on `E` as a seminorm.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
seminorm, locally convex, LCTVS
-/
set_option old_structure_cmd true
open normed_field set
open_locale big_operators nnreal pointwise topological_space
variables {R R' 𝕜 𝕜₂ 𝕜₃ E E₂ E₃ F G ι : Type*}
/-- A seminorm on a module over a normed ring is a function to the reals that is positive
semidefinite, positive homogeneous, and subadditive. -/
structure seminorm (𝕜 : Type*) (E : Type*) [semi_normed_ring 𝕜] [add_group E] [has_smul 𝕜 E]
extends add_group_seminorm E :=
(smul' : ∀ (a : 𝕜) (x : E), to_fun (a • x) = ‖a‖ * to_fun x)
attribute [nolint doc_blame] seminorm.to_add_group_seminorm
/-- `seminorm_class F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module E.
You should extend this class when you extend `seminorm`. -/
class seminorm_class (F : Type*) (𝕜 E : out_param $ Type*) [semi_normed_ring 𝕜] [add_group E]
[has_smul 𝕜 E] extends add_group_seminorm_class F E ℝ :=
(map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x)
export seminorm_class (map_smul_eq_mul)
-- `𝕜` is an `out_param`, so this is a false positive.
attribute [nolint dangerous_instance] seminorm_class.to_add_group_seminorm_class
section of
/-- Alternative constructor for a `seminorm` on an `add_comm_group E` that is a module over a
`semi_norm_ring 𝕜`. -/
def seminorm.of [semi_normed_ring 𝕜] [add_comm_group E] [module 𝕜 E] (f : E → ℝ)
(add_le : ∀ (x y : E), f (x + y) ≤ f x + f y)
(smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) : seminorm 𝕜 E :=
{ to_fun := f,
map_zero' := by rw [←zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul],
add_le' := add_le,
smul' := smul,
neg' := λ x, by rw [←neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul] }
/-- Alternative constructor for a `seminorm` over a normed field `𝕜` that only assumes `f 0 = 0`
and an inequality for the scalar multiplication. -/
def seminorm.of_smul_le [normed_field 𝕜] [add_comm_group E] [module 𝕜 E] (f : E → ℝ)
(map_zero : f 0 = 0) (add_le : ∀ x y, f (x + y) ≤ f x + f y)
(smul_le : ∀ (r : 𝕜) x, f (r • x) ≤ ‖r‖ * f x) : seminorm 𝕜 E :=
seminorm.of f add_le
(λ r x, begin
refine le_antisymm (smul_le r x) _,
by_cases r = 0,
{ simp [h, map_zero] },
rw ←mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h)),
rw inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h),
specialize smul_le r⁻¹ (r • x),
rw norm_inv at smul_le,
convert smul_le,
simp [h],
end)
end of
namespace seminorm
section semi_normed_ring
variables [semi_normed_ring 𝕜]
section add_group
variables [add_group E]
section has_smul
variables [has_smul 𝕜 E]
instance seminorm_class : seminorm_class (seminorm 𝕜 E) 𝕜 E :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_zero := λ f, f.map_zero',
map_add_le_add := λ f, f.add_le',
map_neg_eq_map := λ f, f.neg',
map_smul_eq_mul := λ f, f.smul' }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`. -/
instance : has_coe_to_fun (seminorm 𝕜 E) (λ _, E → ℝ) := fun_like.has_coe_to_fun
@[ext] lemma ext {p q : seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q := fun_like.ext p q h
instance : has_zero (seminorm 𝕜 E) :=
⟨{ smul' := λ _ _, (mul_zero _).symm,
..add_group_seminorm.has_zero.zero }⟩
@[simp] lemma coe_zero : ⇑(0 : seminorm 𝕜 E) = 0 := rfl
@[simp] lemma zero_apply (x : E) : (0 : seminorm 𝕜 E) x = 0 := rfl
instance : inhabited (seminorm 𝕜 E) := ⟨0⟩
variables (p : seminorm 𝕜 E) (c : 𝕜) (x y : E) (r : ℝ)
/-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/
instance [has_smul R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ] :
has_smul R (seminorm 𝕜 E) :=
{ smul := λ r p,
{ to_fun := λ x, r • p x,
smul' := λ _ _, begin
simp only [←smul_one_smul ℝ≥0 r (_ : ℝ), nnreal.smul_def, smul_eq_mul],
rw [map_smul_eq_mul, mul_left_comm],
end,
..(r • p.to_add_group_seminorm) }}
instance [has_smul R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ]
[has_smul R' ℝ] [has_smul R' ℝ≥0] [is_scalar_tower R' ℝ≥0 ℝ]
[has_smul R R'] [is_scalar_tower R R' ℝ] :
is_scalar_tower R R' (seminorm 𝕜 E) :=
{ smul_assoc := λ r a p, ext $ λ x, smul_assoc r a (p x) }
lemma coe_smul [has_smul R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ]
(r : R) (p : seminorm 𝕜 E) : ⇑(r • p) = r • p := rfl
@[simp] lemma smul_apply [has_smul R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ]
(r : R) (p : seminorm 𝕜 E) (x : E) : (r • p) x = r • p x := rfl
instance : has_add (seminorm 𝕜 E) :=
{ add := λ p q,
{ to_fun := λ x, p x + q x,
smul' := λ a x, by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add],
..(p.to_add_group_seminorm + q.to_add_group_seminorm) }}
lemma coe_add (p q : seminorm 𝕜 E) : ⇑(p + q) = p + q := rfl
@[simp] lemma add_apply (p q : seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x := rfl
instance : add_monoid (seminorm 𝕜 E) :=
fun_like.coe_injective.add_monoid _ rfl coe_add (λ p n, coe_smul n p)
instance : ordered_cancel_add_comm_monoid (seminorm 𝕜 E) :=
fun_like.coe_injective.ordered_cancel_add_comm_monoid _ rfl coe_add (λ p n, coe_smul n p)
instance [monoid R] [mul_action R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ] :
mul_action R (seminorm 𝕜 E) :=
fun_like.coe_injective.mul_action _ coe_smul
variables (𝕜 E)
/-- `coe_fn` as an `add_monoid_hom`. Helper definition for showing that `seminorm 𝕜 E` is
a module. -/
@[simps]
def coe_fn_add_monoid_hom : add_monoid_hom (seminorm 𝕜 E) (E → ℝ) := ⟨coe_fn, coe_zero, coe_add⟩
lemma coe_fn_add_monoid_hom_injective : function.injective (coe_fn_add_monoid_hom 𝕜 E) :=
show @function.injective (seminorm 𝕜 E) (E → ℝ) coe_fn, from fun_like.coe_injective
variables {𝕜 E}
instance [monoid R] [distrib_mul_action R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ] :
distrib_mul_action R (seminorm 𝕜 E) :=
(coe_fn_add_monoid_hom_injective 𝕜 E).distrib_mul_action _ coe_smul
instance [semiring R] [module R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ] :
module R (seminorm 𝕜 E) :=
(coe_fn_add_monoid_hom_injective 𝕜 E).module R _ coe_smul
instance : has_sup (seminorm 𝕜 E) :=
{ sup := λ p q,
{ to_fun := p ⊔ q,
smul' := λ x v, (congr_arg2 max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans $
(mul_max_of_nonneg _ _ $ norm_nonneg x).symm,
..(p.to_add_group_seminorm ⊔ q.to_add_group_seminorm) } }
@[simp] lemma coe_sup (p q : seminorm 𝕜 E) : ⇑(p ⊔ q) = p ⊔ q := rfl
lemma sup_apply (p q : seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x := rfl
lemma smul_sup [has_smul R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ]
(r : R) (p q : seminorm 𝕜 E) :
r • (p ⊔ q) = r • p ⊔ r • q :=
have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y),
from λ x y, by simpa only [←smul_eq_mul, ←nnreal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)]
using mul_max_of_nonneg x y (r • 1 : ℝ≥0).prop,
ext $ λ x, real.smul_max _ _
instance : partial_order (seminorm 𝕜 E) :=
partial_order.lift _ fun_like.coe_injective
lemma le_def (p q : seminorm 𝕜 E) : p ≤ q ↔ (p : E → ℝ) ≤ q := iff.rfl
lemma lt_def (p q : seminorm 𝕜 E) : p < q ↔ (p : E → ℝ) < q := iff.rfl
instance : semilattice_sup (seminorm 𝕜 E) :=
function.injective.semilattice_sup _ fun_like.coe_injective coe_sup
end has_smul
end add_group
section module
variables [semi_normed_ring 𝕜₂] [semi_normed_ring 𝕜₃]
variables {σ₁₂ : 𝕜 →+* 𝕜₂} [ring_hom_isometric σ₁₂]
variables {σ₂₃ : 𝕜₂ →+* 𝕜₃} [ring_hom_isometric σ₂₃]
variables {σ₁₃ : 𝕜 →+* 𝕜₃} [ring_hom_isometric σ₁₃]
variables [add_comm_group E] [add_comm_group E₂] [add_comm_group E₃]
variables [add_comm_group F] [add_comm_group G]
variables [module 𝕜 E] [module 𝕜₂ E₂] [module 𝕜₃ E₃] [module 𝕜 F] [module 𝕜 G]
variables [has_smul R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ]
/-- Composition of a seminorm with a linear map is a seminorm. -/
def comp (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : seminorm 𝕜 E :=
{ to_fun := λ x, p (f x),
smul' := λ _ _, by rw [map_smulₛₗ, map_smul_eq_mul, ring_hom_isometric.is_iso],
..(p.to_add_group_seminorm.comp f.to_add_monoid_hom) }
lemma coe_comp (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f := rfl
@[simp] lemma comp_apply (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) :
(p.comp f) x = p (f x) := rfl
@[simp] lemma comp_id (p : seminorm 𝕜 E) : p.comp linear_map.id = p :=
ext $ λ _, rfl
@[simp] lemma comp_zero (p : seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 :=
ext $ λ _, map_zero p
@[simp] lemma zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : seminorm 𝕜₂ E₂).comp f = 0 :=
ext $ λ _, rfl
lemma comp_comp [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] (p : seminorm 𝕜₃ E₃)
(g : E₂ →ₛₗ[σ₂₃] E₃) (f : E →ₛₗ[σ₁₂] E₂) :
p.comp (g.comp f) = (p.comp g).comp f :=
ext $ λ _, rfl
lemma add_comp (p q : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : (p + q).comp f = p.comp f + q.comp f :=
ext $ λ _, rfl
lemma comp_add_le (p : seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) :
p.comp (f + g) ≤ p.comp f + p.comp g :=
λ _, map_add_le_add p _ _
lemma smul_comp (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) :
(c • p).comp f = c • (p.comp f) :=
ext $ λ _, rfl
lemma comp_mono {p q : seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) :
p.comp f ≤ q.comp f := λ _, hp _
/-- The composition as an `add_monoid_hom`. -/
@[simps] def pullback (f : E →ₛₗ[σ₁₂] E₂) : seminorm 𝕜₂ E₂ →+ seminorm 𝕜 E :=
⟨λ p, p.comp f, zero_comp f, λ p q, add_comp p q f⟩
instance : order_bot (seminorm 𝕜 E) := ⟨0, map_nonneg⟩
@[simp] lemma coe_bot : ⇑(⊥ : seminorm 𝕜 E) = 0 := rfl
lemma bot_eq_zero : (⊥ : seminorm 𝕜 E) = 0 := rfl
lemma smul_le_smul {p q : seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) :
a • p ≤ b • q :=
begin
simp_rw [le_def, pi.le_def, coe_smul],
intros x,
simp_rw [pi.smul_apply, nnreal.smul_def, smul_eq_mul],
exact mul_le_mul hab (hpq x) (map_nonneg p x) (nnreal.coe_nonneg b),
end
lemma finset_sup_apply (p : ι → seminorm 𝕜 E) (s : finset ι) (x : E) :
s.sup p x = ↑(s.sup (λ i, ⟨p i x, map_nonneg (p i) x⟩) : ℝ≥0) :=
begin
induction s using finset.cons_induction_on with a s ha ih,
{ rw [finset.sup_empty, finset.sup_empty, coe_bot, _root_.bot_eq_zero, pi.zero_apply,
nonneg.coe_zero] },
{ rw [finset.sup_cons, finset.sup_cons, coe_sup, sup_eq_max, pi.sup_apply, sup_eq_max,
nnreal.coe_max, subtype.coe_mk, ih] }
end
lemma finset_sup_le_sum (p : ι → seminorm 𝕜 E) (s : finset ι) : s.sup p ≤ ∑ i in s, p i :=
begin
classical,
refine finset.sup_le_iff.mpr _,
intros i hi,
rw [finset.sum_eq_sum_diff_singleton_add hi, le_add_iff_nonneg_left],
exact bot_le,
end
lemma finset_sup_apply_le {p : ι → seminorm 𝕜 E} {s : finset ι} {x : E} {a : ℝ} (ha : 0 ≤ a)
(h : ∀ i, i ∈ s → p i x ≤ a) : s.sup p x ≤ a :=
begin
lift a to ℝ≥0 using ha,
rw [finset_sup_apply, nnreal.coe_le_coe],
exact finset.sup_le h,
end
lemma finset_sup_apply_lt {p : ι → seminorm 𝕜 E} {s : finset ι} {x : E} {a : ℝ} (ha : 0 < a)
(h : ∀ i, i ∈ s → p i x < a) : s.sup p x < a :=
begin
lift a to ℝ≥0 using ha.le,
rw [finset_sup_apply, nnreal.coe_lt_coe, finset.sup_lt_iff],
{ exact h },
{ exact nnreal.coe_pos.mpr ha },
end
lemma norm_sub_map_le_sub (p : seminorm 𝕜 E) (x y : E) : ‖p x - p y‖ ≤ p (x - y) :=
abs_sub_map_le_sub p x y
end module
end semi_normed_ring
section semi_normed_comm_ring
variables [semi_normed_ring 𝕜] [semi_normed_comm_ring 𝕜₂]
variables {σ₁₂ : 𝕜 →+* 𝕜₂} [ring_hom_isometric σ₁₂]
variables [add_comm_group E] [add_comm_group E₂] [module 𝕜 E] [module 𝕜₂ E₂]
lemma comp_smul (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) :
p.comp (c • f) = ‖c‖₊ • p.comp f :=
ext $ λ _, by rw [comp_apply, smul_apply, linear_map.smul_apply, map_smul_eq_mul, nnreal.smul_def,
coe_nnnorm, smul_eq_mul, comp_apply]
lemma comp_smul_apply (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) (x : E) :
p.comp (c • f) x = ‖c‖ * p (f x) := map_smul_eq_mul p _ _
end semi_normed_comm_ring
section normed_field
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E] {p q : seminorm 𝕜 E} {x : E}
/-- Auxiliary lemma to show that the infimum of seminorms is well-defined. -/
lemma bdd_below_range_add : bdd_below (range $ λ u, p u + q (x - u)) :=
⟨0, by { rintro _ ⟨x, rfl⟩, dsimp, positivity }⟩
noncomputable instance : has_inf (seminorm 𝕜 E) :=
{ inf := λ p q,
{ to_fun := λ x, ⨅ u : E, p u + q (x-u),
smul' :=
begin
intros a x,
obtain rfl | ha := eq_or_ne a 0,
{ rw [norm_zero, zero_mul, zero_smul],
refine cinfi_eq_of_forall_ge_of_forall_gt_exists_lt (λ i, by positivity)
(λ x hx, ⟨0, by rwa [map_zero, sub_zero, map_zero, add_zero]⟩) },
simp_rw [real.mul_infi_of_nonneg (norm_nonneg a), mul_add, ←map_smul_eq_mul p,
←map_smul_eq_mul q, smul_sub],
refine function.surjective.infi_congr ((•) a⁻¹ : E → E) (λ u, ⟨a • u, inv_smul_smul₀ ha u⟩)
(λ u, _),
rw smul_inv_smul₀ ha
end,
..(p.to_add_group_seminorm ⊓ q.to_add_group_seminorm) }}
@[simp] lemma inf_apply (p q : seminorm 𝕜 E) (x : E) : (p ⊓ q) x = ⨅ u : E, p u + q (x-u) := rfl
noncomputable instance : lattice (seminorm 𝕜 E) :=
{ inf := (⊓),
inf_le_left := λ p q x, cinfi_le_of_le bdd_below_range_add x $
by simp only [sub_self, map_zero, add_zero],
inf_le_right := λ p q x, cinfi_le_of_le bdd_below_range_add 0 $
by simp only [sub_self, map_zero, zero_add, sub_zero],
le_inf := λ a b c hab hac x,
le_cinfi $ λ u, (le_map_add_map_sub a _ _).trans $ add_le_add (hab _) (hac _),
..seminorm.semilattice_sup }
lemma smul_inf [has_smul R ℝ] [has_smul R ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ]
(r : R) (p q : seminorm 𝕜 E) :
r • (p ⊓ q) = r • p ⊓ r • q :=
begin
ext,
simp_rw [smul_apply, inf_apply, smul_apply, ←smul_one_smul ℝ≥0 r (_ : ℝ), nnreal.smul_def,
smul_eq_mul, real.mul_infi_of_nonneg (subtype.prop _), mul_add],
end
section classical
open_locale classical
/-- We define the supremum of an arbitrary subset of `seminorm 𝕜 E` as follows:
* if `s` is `bdd_above` *as a set of functions `E → ℝ`* (that is, if `s` is pointwise bounded
above), we take the pointwise supremum of all elements of `s`, and we prove that it is indeed a
seminorm.
* otherwise, we take the zero seminorm `⊥`.
There are two things worth mentionning here:
* First, it is not trivial at first that `s` being bounded above *by a function* implies
being bounded above *as a seminorm*. We show this in `seminorm.bdd_above_iff` by using
that the `Sup s` as defined here is then a bounding seminorm for `s`. So it is important to make
the case disjunction on `bdd_above (coe_fn '' s : set (E → ℝ))` and not `bdd_above s`.
* Since the pointwise `Sup` already gives `0` at points where a family of functions is
not bounded above, one could hope that just using the pointwise `Sup` would work here, without the
need for an additional case disjunction. As discussed on Zulip, this doesn't work because this can
give a function which does *not* satisfy the seminorm axioms (typically sub-additivity).
-/
noncomputable instance : has_Sup (seminorm 𝕜 E) :=
{ Sup := λ s, if h : bdd_above (coe_fn '' s : set (E → ℝ)) then
{ to_fun := ⨆ p : s, ((p : seminorm 𝕜 E) : E → ℝ),
map_zero' :=
begin
rw [supr_apply, ← @real.csupr_const_zero s],
congrm ⨆ i, _,
exact map_zero i.1
end,
add_le' := λ x y,
begin
rcases h with ⟨q, hq⟩,
obtain rfl | h := s.eq_empty_or_nonempty,
{ simp [real.csupr_empty] },
haveI : nonempty ↥s := h.coe_sort,
simp only [supr_apply],
refine csupr_le (λ i, ((i : seminorm 𝕜 E).add_le' x y).trans $
add_le_add (le_csupr ⟨q x, _⟩ i) (le_csupr ⟨q y, _⟩ i));
rw [mem_upper_bounds, forall_range_iff];
exact λ j, hq (mem_image_of_mem _ j.2) _,
end,
neg' := λ x,
begin
simp only [supr_apply],
congrm ⨆ i, _,
exact i.1.neg' _
end,
smul' := λ a x,
begin
simp only [supr_apply],
rw [← smul_eq_mul, real.smul_supr_of_nonneg (norm_nonneg a) (λ i : s, (i : seminorm 𝕜 E) x)],
congrm ⨆ i, _,
exact i.1.smul' a x
end }
else ⊥ }
protected lemma coe_Sup_eq' {s : set $ seminorm 𝕜 E} (hs : bdd_above (coe_fn '' s : set (E → ℝ))) :
coe_fn (Sup s) = ⨆ p : s, p :=
congr_arg _ (dif_pos hs)
protected lemma bdd_above_iff {s : set $ seminorm 𝕜 E} :
bdd_above s ↔ bdd_above (coe_fn '' s : set (E → ℝ)) :=
⟨λ ⟨q, hq⟩, ⟨q, ball_image_of_ball $ λ p hp, hq hp⟩,
λ H, ⟨Sup s, λ p hp x,
begin
rw [seminorm.coe_Sup_eq' H, supr_apply],
rcases H with ⟨q, hq⟩,
exact le_csupr ⟨q x, forall_range_iff.mpr $ λ i : s, hq (mem_image_of_mem _ i.2) x⟩ ⟨p, hp⟩
end ⟩⟩
protected lemma coe_Sup_eq {s : set $ seminorm 𝕜 E} (hs : bdd_above s) :
coe_fn (Sup s) = ⨆ p : s, p :=
seminorm.coe_Sup_eq' (seminorm.bdd_above_iff.mp hs)
protected lemma coe_supr_eq {ι : Type*} {p : ι → seminorm 𝕜 E} (hp : bdd_above (range p)) :
coe_fn (⨆ i, p i) = ⨆ i, p i :=
by rw [← Sup_range, seminorm.coe_Sup_eq hp]; exact supr_range' (coe_fn : seminorm 𝕜 E → E → ℝ) p
private lemma seminorm.is_lub_Sup (s : set (seminorm 𝕜 E)) (hs₁ : bdd_above s) (hs₂ : s.nonempty) :
is_lub s (Sup s) :=
begin
refine ⟨λ p hp x, _, λ p hp x, _⟩;
haveI : nonempty ↥s := hs₂.coe_sort;
rw [seminorm.coe_Sup_eq hs₁, supr_apply],
{ rcases hs₁ with ⟨q, hq⟩,
exact le_csupr ⟨q x, forall_range_iff.mpr $ λ i : s, hq i.2 x⟩ ⟨p, hp⟩ },
{ exact csupr_le (λ q, hp q.2 x) }
end
/-- `seminorm 𝕜 E` is a conditionally complete lattice.
Note that, while `inf`, `sup` and `Sup` have good definitional properties (corresponding to
`seminorm.has_inf`, `seminorm.has_sup` and `seminorm.has_Sup` respectively), `Inf s` is just
defined as the supremum of the lower bounds of `s`, which is not really useful in practice. If you
need to use `Inf` on seminorms, then you should probably provide a more workable definition first,
but this is unlikely to happen so we keep the "bad" definition for now. -/
noncomputable instance : conditionally_complete_lattice (seminorm 𝕜 E) :=
conditionally_complete_lattice_of_lattice_of_Sup (seminorm 𝕜 E) seminorm.is_lub_Sup
end classical
end normed_field
/-! ### Seminorm ball -/
section semi_normed_ring
variables [semi_normed_ring 𝕜]
section add_comm_group
variables [add_comm_group E]
section has_smul
variables [has_smul 𝕜 E] (p : seminorm 𝕜 E)
/-- The ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with
`p (y - x) < r`. -/
def ball (x : E) (r : ℝ) := { y : E | p (y - x) < r }
/-- The closed ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y`
with `p (y - x) ≤ r`. -/
def closed_ball (x : E) (r : ℝ) := { y : E | p (y - x) ≤ r }
variables {x y : E} {r : ℝ}
@[simp] lemma mem_ball : y ∈ ball p x r ↔ p (y - x) < r := iff.rfl
@[simp] lemma mem_closed_ball : y ∈ closed_ball p x r ↔ p (y - x) ≤ r := iff.rfl
lemma mem_ball_self (hr : 0 < r) : x ∈ ball p x r := by simp [hr]
lemma mem_closed_ball_self (hr : 0 ≤ r) : x ∈ closed_ball p x r := by simp [hr]
lemma mem_ball_zero : y ∈ ball p 0 r ↔ p y < r := by rw [mem_ball, sub_zero]
lemma mem_closed_ball_zero : y ∈ closed_ball p 0 r ↔ p y ≤ r := by rw [mem_closed_ball, sub_zero]
lemma ball_zero_eq : ball p 0 r = { y : E | p y < r } := set.ext $ λ x, p.mem_ball_zero
lemma closed_ball_zero_eq : closed_ball p 0 r = { y : E | p y ≤ r } :=
set.ext $ λ x, p.mem_closed_ball_zero
lemma ball_subset_closed_ball (x r) : ball p x r ⊆ closed_ball p x r := λ y (hy : _ < _), hy.le
lemma closed_ball_eq_bInter_ball (x r) : closed_ball p x r = ⋂ ρ > r, ball p x ρ :=
by ext y; simp_rw [mem_closed_ball, mem_Inter₂, mem_ball, ← forall_lt_iff_le']
@[simp] lemma ball_zero' (x : E) (hr : 0 < r) : ball (0 : seminorm 𝕜 E) x r = set.univ :=
begin
rw [set.eq_univ_iff_forall, ball],
simp [hr],
end
@[simp] lemma closed_ball_zero' (x : E) (hr : 0 < r) :
closed_ball (0 : seminorm 𝕜 E) x r = set.univ :=
eq_univ_of_subset (ball_subset_closed_ball _ _ _) (ball_zero' x hr)
lemma ball_smul (p : seminorm 𝕜 E) {c : nnreal} (hc : 0 < c) (r : ℝ) (x : E) :
(c • p).ball x r = p.ball x (r / c) :=
by { ext, rw [mem_ball, mem_ball, smul_apply, nnreal.smul_def, smul_eq_mul, mul_comm,
lt_div_iff (nnreal.coe_pos.mpr hc)] }
lemma closed_ball_smul (p : seminorm 𝕜 E) {c : nnreal} (hc : 0 < c) (r : ℝ) (x : E) :
(c • p).closed_ball x r = p.closed_ball x (r / c) :=
by { ext, rw [mem_closed_ball, mem_closed_ball, smul_apply, nnreal.smul_def, smul_eq_mul, mul_comm,
le_div_iff (nnreal.coe_pos.mpr hc)] }
lemma ball_sup (p : seminorm 𝕜 E) (q : seminorm 𝕜 E) (e : E) (r : ℝ) :
ball (p ⊔ q) e r = ball p e r ∩ ball q e r :=
by simp_rw [ball, ←set.set_of_and, coe_sup, pi.sup_apply, sup_lt_iff]
lemma closed_ball_sup (p : seminorm 𝕜 E) (q : seminorm 𝕜 E) (e : E) (r : ℝ) :
closed_ball (p ⊔ q) e r = closed_ball p e r ∩ closed_ball q e r :=
by simp_rw [closed_ball, ←set.set_of_and, coe_sup, pi.sup_apply, sup_le_iff]
lemma ball_finset_sup' (p : ι → seminorm 𝕜 E) (s : finset ι) (H : s.nonempty) (e : E) (r : ℝ) :
ball (s.sup' H p) e r = s.inf' H (λ i, ball (p i) e r) :=
begin
induction H using finset.nonempty.cons_induction with a a s ha hs ih,
{ classical, simp },
{ rw [finset.sup'_cons hs, finset.inf'_cons hs, ball_sup, inf_eq_inter, ih] },
end
lemma closed_ball_finset_sup' (p : ι → seminorm 𝕜 E) (s : finset ι) (H : s.nonempty) (e : E)
(r : ℝ) : closed_ball (s.sup' H p) e r = s.inf' H (λ i, closed_ball (p i) e r) :=
begin
induction H using finset.nonempty.cons_induction with a a s ha hs ih,
{ classical, simp },
{ rw [finset.sup'_cons hs, finset.inf'_cons hs, closed_ball_sup, inf_eq_inter, ih] },
end
lemma ball_mono {p : seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) : p.ball x r₁ ⊆ p.ball x r₂ :=
λ _ (hx : _ < _), hx.trans_le h
lemma closed_ball_mono {p : seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) :
p.closed_ball x r₁ ⊆ p.closed_ball x r₂ :=
λ _ (hx : _ ≤ _), hx.trans h
lemma ball_antitone {p q : seminorm 𝕜 E} (h : q ≤ p) : p.ball x r ⊆ q.ball x r :=
λ _, (h _).trans_lt
lemma closed_ball_antitone {p q : seminorm 𝕜 E} (h : q ≤ p) :
p.closed_ball x r ⊆ q.closed_ball x r :=
λ _, (h _).trans
lemma ball_add_ball_subset (p : seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E):
p.ball (x₁ : E) r₁ + p.ball (x₂ : E) r₂ ⊆ p.ball (x₁ + x₂) (r₁ + r₂) :=
begin
rintros x ⟨y₁, y₂, hy₁, hy₂, rfl⟩,
rw [mem_ball, add_sub_add_comm],
exact (map_add_le_add p _ _).trans_lt (add_lt_add hy₁ hy₂),
end
lemma closed_ball_add_closed_ball_subset (p : seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E) :
p.closed_ball (x₁ : E) r₁ + p.closed_ball (x₂ : E) r₂ ⊆ p.closed_ball (x₁ + x₂) (r₁ + r₂) :=
begin
rintros x ⟨y₁, y₂, hy₁, hy₂, rfl⟩,
rw [mem_closed_ball, add_sub_add_comm],
exact (map_add_le_add p _ _).trans (add_le_add hy₁ hy₂)
end
lemma sub_mem_ball (p : seminorm 𝕜 E) (x₁ x₂ y : E) (r : ℝ) :
x₁ - x₂ ∈ p.ball y r ↔ x₁ ∈ p.ball (x₂ + y) r :=
by simp_rw [mem_ball, sub_sub]
/-- The image of a ball under addition with a singleton is another ball. -/
lemma vadd_ball (p : seminorm 𝕜 E) :
x +ᵥ p.ball y r = p.ball (x +ᵥ y) r :=
begin
letI := add_group_seminorm.to_seminormed_add_comm_group p.to_add_group_seminorm,
exact vadd_ball x y r,
end
/-- The image of a closed ball under addition with a singleton is another closed ball. -/
lemma vadd_closed_ball (p : seminorm 𝕜 E) :
x +ᵥ p.closed_ball y r = p.closed_ball (x +ᵥ y) r :=
begin
letI := add_group_seminorm.to_seminormed_add_comm_group p.to_add_group_seminorm,
exact vadd_closed_ball x y r,
end
end has_smul
section module
variables [module 𝕜 E]
variables [semi_normed_ring 𝕜₂] [add_comm_group E₂] [module 𝕜₂ E₂]
variables {σ₁₂ : 𝕜 →+* 𝕜₂} [ring_hom_isometric σ₁₂]
lemma ball_comp (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) :
(p.comp f).ball x r = f ⁻¹' (p.ball (f x) r) :=
begin
ext,
simp_rw [ball, mem_preimage, comp_apply, set.mem_set_of_eq, map_sub],
end
lemma closed_ball_comp (p : seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) :
(p.comp f).closed_ball x r = f ⁻¹' (p.closed_ball (f x) r) :=
begin
ext,
simp_rw [closed_ball, mem_preimage, comp_apply, set.mem_set_of_eq, map_sub],
end
variables (p : seminorm 𝕜 E)
lemma preimage_metric_ball {r : ℝ} :
p ⁻¹' (metric.ball 0 r) = {x | p x < r} :=
begin
ext x,
simp only [mem_set_of, mem_preimage, mem_ball_zero_iff, real.norm_of_nonneg (map_nonneg p _)]
end
lemma preimage_metric_closed_ball {r : ℝ} :
p ⁻¹' (metric.closed_ball 0 r) = {x | p x ≤ r} :=
begin
ext x,
simp only [mem_set_of, mem_preimage, mem_closed_ball_zero_iff,
real.norm_of_nonneg (map_nonneg p _)]
end
lemma ball_zero_eq_preimage_ball {r : ℝ} :
p.ball 0 r = p ⁻¹' (metric.ball 0 r) :=
by rw [ball_zero_eq, preimage_metric_ball]
lemma closed_ball_zero_eq_preimage_closed_ball {r : ℝ} :
p.closed_ball 0 r = p ⁻¹' (metric.closed_ball 0 r) :=
by rw [closed_ball_zero_eq, preimage_metric_closed_ball]
@[simp] lemma ball_bot {r : ℝ} (x : E) (hr : 0 < r) :
ball (⊥ : seminorm 𝕜 E) x r = set.univ :=
ball_zero' x hr
@[simp] lemma closed_ball_bot {r : ℝ} (x : E) (hr : 0 < r) :
closed_ball (⊥ : seminorm 𝕜 E) x r = set.univ :=
closed_ball_zero' x hr
/-- Seminorm-balls at the origin are balanced. -/
lemma balanced_ball_zero (r : ℝ) : balanced 𝕜 (ball p 0 r) :=
begin
rintro a ha x ⟨y, hy, hx⟩,
rw [mem_ball_zero, ←hx, map_smul_eq_mul],
calc _ ≤ p y : mul_le_of_le_one_left (map_nonneg p _) ha
... < r : by rwa mem_ball_zero at hy,
end
/-- Closed seminorm-balls at the origin are balanced. -/
lemma balanced_closed_ball_zero (r : ℝ) : balanced 𝕜 (closed_ball p 0 r) :=
begin
rintro a ha x ⟨y, hy, hx⟩,
rw [mem_closed_ball_zero, ←hx, map_smul_eq_mul],
calc _ ≤ p y : mul_le_of_le_one_left (map_nonneg p _) ha
... ≤ r : by rwa mem_closed_ball_zero at hy
end
lemma ball_finset_sup_eq_Inter (p : ι → seminorm 𝕜 E) (s : finset ι) (x : E) {r : ℝ} (hr : 0 < r) :
ball (s.sup p) x r = ⋂ (i ∈ s), ball (p i) x r :=
begin
lift r to nnreal using hr.le,
simp_rw [ball, Inter_set_of, finset_sup_apply, nnreal.coe_lt_coe,
finset.sup_lt_iff (show ⊥ < r, from hr), ←nnreal.coe_lt_coe, subtype.coe_mk],
end
lemma closed_ball_finset_sup_eq_Inter (p : ι → seminorm 𝕜 E) (s : finset ι) (x : E) {r : ℝ}
(hr : 0 ≤ r) : closed_ball (s.sup p) x r = ⋂ (i ∈ s), closed_ball (p i) x r :=
begin
lift r to nnreal using hr,
simp_rw [closed_ball, Inter_set_of, finset_sup_apply, nnreal.coe_le_coe,
finset.sup_le_iff, ←nnreal.coe_le_coe, subtype.coe_mk]
end
lemma ball_finset_sup (p : ι → seminorm 𝕜 E) (s : finset ι) (x : E) {r : ℝ} (hr : 0 < r) :
ball (s.sup p) x r = s.inf (λ i, ball (p i) x r) :=
begin
rw finset.inf_eq_infi,
exact ball_finset_sup_eq_Inter _ _ _ hr,
end
lemma closed_ball_finset_sup (p : ι → seminorm 𝕜 E) (s : finset ι) (x : E) {r : ℝ} (hr : 0 ≤ r) :
closed_ball (s.sup p) x r = s.inf (λ i, closed_ball (p i) x r) :=
begin
rw finset.inf_eq_infi,
exact closed_ball_finset_sup_eq_Inter _ _ _ hr,
end
lemma ball_smul_ball (p : seminorm 𝕜 E) (r₁ r₂ : ℝ) :
metric.ball (0 : 𝕜) r₁ • p.ball 0 r₂ ⊆ p.ball 0 (r₁ * r₂) :=
begin
rw set.subset_def,
intros x hx,
rw set.mem_smul at hx,
rcases hx with ⟨a, y, ha, hy, hx⟩,
rw [←hx, mem_ball_zero, map_smul_eq_mul],
exact mul_lt_mul'' (mem_ball_zero_iff.mp ha) (p.mem_ball_zero.mp hy) (norm_nonneg a)
(map_nonneg p y),
end
lemma closed_ball_smul_closed_ball (p : seminorm 𝕜 E) (r₁ r₂ : ℝ) :
metric.closed_ball (0 : 𝕜) r₁ • p.closed_ball 0 r₂ ⊆ p.closed_ball 0 (r₁ * r₂) :=
begin
rw set.subset_def,
intros x hx,
rw set.mem_smul at hx,
rcases hx with ⟨a, y, ha, hy, hx⟩,
rw [←hx, mem_closed_ball_zero, map_smul_eq_mul],
rw mem_closed_ball_zero_iff at ha,
exact mul_le_mul ha (p.mem_closed_ball_zero.mp hy) (map_nonneg _ y) ((norm_nonneg a).trans ha)
end
@[simp] lemma ball_eq_emptyset (p : seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r ≤ 0) : p.ball x r = ∅ :=
begin
ext,
rw [seminorm.mem_ball, set.mem_empty_iff_false, iff_false, not_lt],
exact hr.trans (map_nonneg p _),
end
@[simp] lemma closed_ball_eq_emptyset (p : seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r < 0) :
p.closed_ball x r = ∅ :=
begin
ext,
rw [seminorm.mem_closed_ball, set.mem_empty_iff_false, iff_false, not_le],
exact hr.trans_le (map_nonneg _ _),
end
end module
end add_comm_group
end semi_normed_ring
section normed_field
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E] (p : seminorm 𝕜 E) {A B : set E}
{a : 𝕜} {r : ℝ} {x : E}
lemma smul_ball_zero {p : seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : k ≠ 0) :
k • p.ball 0 r = p.ball 0 (‖k‖ * r) :=
begin
ext,
rw [mem_smul_set_iff_inv_smul_mem₀ hk, p.mem_ball_zero, p.mem_ball_zero, map_smul_eq_mul,
norm_inv, ← div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hk), mul_comm]
end
lemma ball_zero_absorbs_ball_zero (p : seminorm 𝕜 E) {r₁ r₂ : ℝ} (hr₁ : 0 < r₁) :
absorbs 𝕜 (p.ball 0 r₁) (p.ball 0 r₂) :=
begin
rcases exists_pos_lt_mul hr₁ r₂ with ⟨r, hr₀, hr⟩,
refine ⟨r, hr₀, λ a ha x hx, _⟩,
rw [smul_ball_zero (norm_pos_iff.1 $ hr₀.trans_le ha), p.mem_ball_zero],
rw p.mem_ball_zero at hx,
exact hx.trans (hr.trans_le $ mul_le_mul_of_nonneg_right ha hr₁.le)
end
/-- Seminorm-balls at the origin are absorbent. -/
protected lemma absorbent_ball_zero (hr : 0 < r) : absorbent 𝕜 (ball p (0 : E) r) :=
absorbent_iff_forall_absorbs_singleton.2 $ λ x, (p.ball_zero_absorbs_ball_zero hr).mono_right $
singleton_subset_iff.2 $ p.mem_ball_zero.2 $ lt_add_one _
/-- Closed seminorm-balls at the origin are absorbent. -/
protected lemma absorbent_closed_ball_zero (hr : 0 < r) : absorbent 𝕜 (closed_ball p (0 : E) r) :=
(p.absorbent_ball_zero hr).subset (p.ball_subset_closed_ball _ _)
/-- Seminorm-balls containing the origin are absorbent. -/
protected lemma absorbent_ball (hpr : p x < r) : absorbent 𝕜 (ball p x r) :=
begin
refine (p.absorbent_ball_zero $ sub_pos.2 hpr).subset (λ y hy, _),
rw p.mem_ball_zero at hy,
exact p.mem_ball.2 ((map_sub_le_add p _ _).trans_lt $ add_lt_of_lt_sub_right hy),
end
/-- Seminorm-balls containing the origin are absorbent. -/
protected lemma absorbent_closed_ball (hpr : p x < r) : absorbent 𝕜 (closed_ball p x r) :=
begin
refine (p.absorbent_closed_ball_zero $ sub_pos.2 hpr).subset (λ y hy, _),
rw p.mem_closed_ball_zero at hy,
exact p.mem_closed_ball.2 ((map_sub_le_add p _ _).trans $ add_le_of_le_sub_right hy),
end
lemma symmetric_ball_zero (r : ℝ) (hx : x ∈ ball p 0 r) : -x ∈ ball p 0 r :=
balanced_ball_zero p r (-1) (by rw [norm_neg, norm_one]) ⟨x, hx, by rw [neg_smul, one_smul]⟩
@[simp]
lemma neg_ball (p : seminorm 𝕜 E) (r : ℝ) (x : E) :
-ball p x r = ball p (-x) r :=
by { ext, rw [mem_neg, mem_ball, mem_ball, ←neg_add', sub_neg_eq_add, map_neg_eq_map] }
@[simp]
lemma smul_ball_preimage (p : seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) :
((•) a) ⁻¹' p.ball y r = p.ball (a⁻¹ • y) (r / ‖a‖) :=
set.ext $ λ _, by rw [mem_preimage, mem_ball, mem_ball,
lt_div_iff (norm_pos_iff.mpr ha), mul_comm, ←map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha]
end normed_field
section convex
variables [normed_field 𝕜] [add_comm_group E] [normed_space ℝ 𝕜] [module 𝕜 E]
section has_smul
variables [has_smul ℝ E] [is_scalar_tower ℝ 𝕜 E] (p : seminorm 𝕜 E)
/-- A seminorm is convex. Also see `convex_on_norm`. -/
protected lemma convex_on : convex_on ℝ univ p :=
begin
refine ⟨convex_univ, λ x _ y _ a b ha hb hab, _⟩,
calc p (a • x + b • y) ≤ p (a • x) + p (b • y) : map_add_le_add p _ _
... = ‖a • (1 : 𝕜)‖ * p x + ‖b • (1 : 𝕜)‖ * p y
: by rw [←map_smul_eq_mul p, ←map_smul_eq_mul p, smul_one_smul, smul_one_smul]
... = a * p x + b * p y
: by rw [norm_smul, norm_smul, norm_one, mul_one, mul_one, real.norm_of_nonneg ha,
real.norm_of_nonneg hb],
end
end has_smul
section module
variables [module ℝ E] [is_scalar_tower ℝ 𝕜 E] (p : seminorm 𝕜 E) (x : E) (r : ℝ)
/-- Seminorm-balls are convex. -/
lemma convex_ball : convex ℝ (ball p x r) :=
begin
convert (p.convex_on.translate_left (-x)).convex_lt r,
ext y,
rw [preimage_univ, sep_univ, p.mem_ball, sub_eq_add_neg],
refl,
end
/-- Closed seminorm-balls are convex. -/
lemma convex_closed_ball : convex ℝ (closed_ball p x r) :=
begin
rw closed_ball_eq_bInter_ball,
exact convex_Inter₂ (λ _ _, convex_ball _ _ _)
end
end module
end convex
section restrict_scalars
variables (𝕜) {𝕜' : Type*} [normed_field 𝕜] [semi_normed_ring 𝕜'] [normed_algebra 𝕜 𝕜']
[norm_one_class 𝕜'] [add_comm_group E] [module 𝕜' E] [has_smul 𝕜 E] [is_scalar_tower 𝕜 𝕜' E]
/-- Reinterpret a seminorm over a field `𝕜'` as a seminorm over a smaller field `𝕜`. This will
typically be used with `is_R_or_C 𝕜'` and `𝕜 = ℝ`. -/
protected def restrict_scalars (p : seminorm 𝕜' E) :
seminorm 𝕜 E :=
{ smul' := λ a x, by rw [← smul_one_smul 𝕜' a x, p.smul', norm_smul, norm_one, mul_one],
..p }
@[simp] lemma coe_restrict_scalars (p : seminorm 𝕜' E) :
(p.restrict_scalars 𝕜 : E → ℝ) = p :=
rfl
@[simp] lemma restrict_scalars_ball (p : seminorm 𝕜' E) :
(p.restrict_scalars 𝕜).ball = p.ball :=
rfl
end restrict_scalars
/-! ### Continuity criterions for seminorms -/
section continuity
variables [semi_normed_ring 𝕜] [add_comm_group E]
[module 𝕜 E]
lemma continuous_at_zero [norm_one_class 𝕜] [normed_algebra ℝ 𝕜] [module ℝ E]
[is_scalar_tower ℝ 𝕜 E] [topological_space E] [has_continuous_const_smul ℝ E] {p : seminorm 𝕜 E}
(hp : p.ball 0 1 ∈ (𝓝 0 : filter E)) :
continuous_at p 0 :=
begin
change continuous_at (p.restrict_scalars ℝ) 0,
rw ← p.restrict_scalars_ball ℝ at hp,
refine metric.nhds_basis_ball.tendsto_right_iff.mpr _,
intros ε hε,
rw map_zero,
suffices : (p.restrict_scalars ℝ).ball 0 ε ∈ (𝓝 0 : filter E),
{ rwa seminorm.ball_zero_eq_preimage_ball at this },
have := (set_smul_mem_nhds_zero_iff hε.ne.symm).mpr hp,
rwa [seminorm.smul_ball_zero hε.ne', real.norm_of_nonneg hε.le, mul_one] at this
end
protected lemma uniform_continuous_of_continuous_at_zero [uniform_space E] [uniform_add_group E]
{p : seminorm 𝕜 E} (hp : continuous_at p 0) :
uniform_continuous p :=
begin
have hp : filter.tendsto p (𝓝 0) (𝓝 0) := map_zero p ▸ hp,
rw [uniform_continuous, uniformity_eq_comap_nhds_zero_swapped,
metric.uniformity_eq_comap_nhds_zero, filter.tendsto_comap_iff],
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
(hp.comp filter.tendsto_comap) (λ xy, dist_nonneg) (λ xy, p.norm_sub_map_le_sub _ _)
end
protected lemma continuous_of_continuous_at_zero [topological_space E] [topological_add_group E]
{p : seminorm 𝕜 E} (hp : continuous_at p 0) :
continuous p :=
begin
letI := topological_add_group.to_uniform_space E,
haveI : uniform_add_group E := topological_add_comm_group_is_uniform,
exact (seminorm.uniform_continuous_of_continuous_at_zero hp).continuous
end
protected lemma uniform_continuous [norm_one_class 𝕜] [normed_algebra ℝ 𝕜] [module ℝ E]
[is_scalar_tower ℝ 𝕜 E] [uniform_space E] [uniform_add_group E] [has_continuous_const_smul ℝ E]
{p : seminorm 𝕜 E} (hp : p.ball 0 1 ∈ (𝓝 0 : filter E)) :
uniform_continuous p :=
seminorm.uniform_continuous_of_continuous_at_zero (continuous_at_zero hp)
protected lemma continuous [norm_one_class 𝕜] [normed_algebra ℝ 𝕜] [module ℝ E]
[is_scalar_tower ℝ 𝕜 E] [topological_space E] [topological_add_group E]
[has_continuous_const_smul ℝ E] {p : seminorm 𝕜 E} (hp : p.ball 0 1 ∈ (𝓝 0 : filter E)) :
continuous p :=
seminorm.continuous_of_continuous_at_zero (continuous_at_zero hp)
lemma continuous_of_le [norm_one_class 𝕜] [normed_algebra ℝ 𝕜] [module ℝ E]
[is_scalar_tower ℝ 𝕜 E] [topological_space E] [topological_add_group E]
[has_continuous_const_smul ℝ E] {p q : seminorm 𝕜 E} (hq : continuous q) (hpq : p ≤ q) :
continuous p :=
begin
refine seminorm.continuous (filter.mem_of_superset
(is_open.mem_nhds _ $ q.mem_ball_self zero_lt_one) (ball_antitone hpq)),
rw ball_zero_eq,
exact is_open_lt hq continuous_const
end
end continuity
end seminorm
/-! ### The norm as a seminorm -/
section norm_seminorm
variables (𝕜) (E) [normed_field 𝕜] [seminormed_add_comm_group E] [normed_space 𝕜 E] {r : ℝ}
/-- The norm of a seminormed group as a seminorm. -/
def norm_seminorm : seminorm 𝕜 E :=
{ smul' := norm_smul,
..(norm_add_group_seminorm E)}
@[simp] lemma coe_norm_seminorm : ⇑(norm_seminorm 𝕜 E) = norm := rfl
@[simp] lemma ball_norm_seminorm : (norm_seminorm 𝕜 E).ball = metric.ball :=
by { ext x r y, simp only [seminorm.mem_ball, metric.mem_ball, coe_norm_seminorm, dist_eq_norm] }
variables {𝕜 E} {x : E}
/-- Balls at the origin are absorbent. -/
lemma absorbent_ball_zero (hr : 0 < r) : absorbent 𝕜 (metric.ball (0 : E) r) :=
by { rw ←ball_norm_seminorm 𝕜, exact (norm_seminorm _ _).absorbent_ball_zero hr }
/-- Balls containing the origin are absorbent. -/
lemma absorbent_ball (hx : ‖x‖ < r) : absorbent 𝕜 (metric.ball x r) :=
by { rw ←ball_norm_seminorm 𝕜, exact (norm_seminorm _ _).absorbent_ball hx }
/-- Balls at the origin are balanced. -/
lemma balanced_ball_zero : balanced 𝕜 (metric.ball (0 : E) r) :=
by { rw ←ball_norm_seminorm 𝕜, exact (norm_seminorm _ _).balanced_ball_zero r }
end norm_seminorm
-- Guard against import creep.
assert_not_exists balanced_core
|
b3e6384b1463caa402bb7cbb2c308c66d8256a71 | 626e312b5c1cb2d88fca108f5933076012633192 | /src/algebra/group_ring_action.lean | 51b5932693a17c6dd42e35ab487f96257c74b42d | [
"Apache-2.0"
] | permissive | Bioye97/mathlib | 9db2f9ee54418d29dd06996279ba9dc874fd6beb | 782a20a27ee83b523f801ff34efb1a9557085019 | refs/heads/master | 1,690,305,956,488 | 1,631,067,774,000 | 1,631,067,774,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,331 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import group_theory.group_action.group
import data.equiv.ring
import ring_theory.subring
/-!
# Group action on rings
This file defines the typeclass of monoid acting on semirings `mul_semiring_action M R`,
and the corresponding typeclass of invariant subrings.
Note that `algebra` does not satisfy the axioms of `mul_semiring_action`.
## Implementation notes
There is no separate typeclass for group acting on rings, group acting on fields, etc.
They are all grouped under `mul_semiring_action`.
## Tags
group action, invariant subring
-/
universes u v
open_locale big_operators
/-- Typeclass for multiplicative actions by monoids on semirings. -/
class mul_semiring_action (M : Type u) [monoid M] (R : Type v) [semiring R]
extends distrib_mul_action M R :=
(smul_one : ∀ (g : M), (g • 1 : R) = 1)
(smul_mul : ∀ (g : M) (x y : R), g • (x * y) = (g • x) * (g • y))
export mul_semiring_action (smul_one)
section semiring
variables (M G : Type u) [monoid M] [group G]
variables (A R S F : Type v) [add_monoid A] [semiring R] [comm_semiring S] [field F]
variables {M R}
lemma smul_mul' [mul_semiring_action M R] (g : M) (x y : R) :
g • (x * y) = (g • x) * (g • y) :=
mul_semiring_action.smul_mul g x y
variables (M R)
/-- Each element of the group defines an additive monoid isomorphism. -/
@[simps]
def distrib_mul_action.to_add_equiv [distrib_mul_action G A] (x : G) : A ≃+ A :=
{ .. distrib_mul_action.to_add_monoid_hom A x,
.. mul_action.to_perm_hom G A x }
/-- Each element of the monoid defines a semiring homomorphism. -/
@[simps]
def mul_semiring_action.to_ring_hom [mul_semiring_action M R] (x : M) : R →+* R :=
{ map_one' := smul_one x,
map_mul' := smul_mul' x,
.. distrib_mul_action.to_add_monoid_hom R x }
theorem to_ring_hom_injective [mul_semiring_action M R] [has_faithful_scalar M R] :
function.injective (mul_semiring_action.to_ring_hom M R) :=
λ m₁ m₂ h, eq_of_smul_eq_smul $ λ r, ring_hom.ext_iff.1 h r
/-- Each element of the group defines a semiring isomorphism. -/
@[simps]
def mul_semiring_action.to_ring_equiv [mul_semiring_action G R] (x : G) : R ≃+* R :=
{ .. distrib_mul_action.to_add_equiv G R x,
.. mul_semiring_action.to_ring_hom G R x }
section
variables {M G R}
/-- A stronger version of `submonoid.distrib_mul_action`. -/
instance submonoid.mul_semiring_action [mul_semiring_action M R] (H : submonoid M) :
mul_semiring_action H R :=
{ smul := (•),
smul_one := λ h, smul_one (h : M),
smul_mul := λ h, smul_mul' (h : M),
.. H.distrib_mul_action }
/-- A stronger version of `subgroup.distrib_mul_action`. -/
instance subgroup.mul_semiring_action [mul_semiring_action G R] (H : subgroup G) :
mul_semiring_action H R :=
H.to_submonoid.mul_semiring_action
/-- A stronger version of `subsemiring.distrib_mul_action`. -/
instance subsemiring.mul_semiring_action {R'} [semiring R'] [mul_semiring_action R' R]
(H : subsemiring R') :
mul_semiring_action H R :=
H.to_submonoid.mul_semiring_action
/-- A stronger version of `subring.distrib_mul_action`. -/
instance subring.mul_semiring_action {R'} [ring R'] [mul_semiring_action R' R]
(H : subring R') :
mul_semiring_action H R :=
H.to_subsemiring.mul_semiring_action
end
section prod
variables [mul_semiring_action M R] [mul_semiring_action M S]
lemma list.smul_prod (g : M) (L : list R) : g • L.prod = (L.map $ (•) g).prod :=
(mul_semiring_action.to_ring_hom M R g).map_list_prod L
lemma multiset.smul_prod (g : M) (m : multiset S) : g • m.prod = (m.map $ (•) g).prod :=
(mul_semiring_action.to_ring_hom M S g).map_multiset_prod m
lemma smul_prod (g : M) {ι : Type*} (f : ι → S) (s : finset ι) :
g • ∏ i in s, f i = ∏ i in s, g • f i :=
(mul_semiring_action.to_ring_hom M S g).map_prod f s
end prod
section simp_lemmas
variables {M G A R}
attribute [simp] smul_one smul_mul' smul_zero smul_add
@[simp] lemma smul_inv' [mul_semiring_action M F] (x : M) (m : F) : x • m⁻¹ = (x • m)⁻¹ :=
(mul_semiring_action.to_ring_hom M F x).map_inv _
@[simp] lemma smul_pow [mul_semiring_action M R] (x : M) (m : R) (n : ℕ) :
x • m ^ n = (x • m) ^ n :=
begin
induction n with n ih,
{ rw [pow_zero, pow_zero], exact smul_one x },
{ rw [pow_succ, pow_succ], exact (smul_mul' x m (m ^ n)).trans (congr_arg _ ih) }
end
end simp_lemmas
end semiring
section ring
variables (M : Type u) [monoid M] {R : Type v} [ring R] [mul_semiring_action M R]
variables (S : subring R)
open mul_action
/-- A typeclass for subrings invariant under a `mul_semiring_action`. -/
class is_invariant_subring : Prop :=
(smul_mem : ∀ (m : M) {x : R}, x ∈ S → m • x ∈ S)
instance is_invariant_subring.to_mul_semiring_action [is_invariant_subring M S] :
mul_semiring_action M S :=
{ smul := λ m x, ⟨m • x, is_invariant_subring.smul_mem m x.2⟩,
one_smul := λ s, subtype.eq $ one_smul M s,
mul_smul := λ m₁ m₂ s, subtype.eq $ mul_smul m₁ m₂ s,
smul_add := λ m s₁ s₂, subtype.eq $ smul_add m s₁ s₂,
smul_zero := λ m, subtype.eq $ smul_zero m,
smul_one := λ m, subtype.eq $ smul_one m,
smul_mul := λ m s₁ s₂, subtype.eq $ smul_mul' m s₁ s₂ }
end ring
|
e51674640e999ec867954582d5c6750f6db3adcb | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/neg_precedence.lean | 08ceb34b62bbf62c19174eaf0900955d71c164d1 | [
"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 | 434 | lean | variables {α : Type} [has_neg α]
variables [has_add α] [has_sub α] [has_mul α] [has_div α] [has_pow α α]
variables (x y : α)
example : - x + y = (- x) + y := rfl
example : - x - y = (- x) - y := rfl
-- `- (x * y)` and `- (x / y)` would also be fine,
-- but breaks an annoyingly-large number of things in mathlib.
example : - x * y = (- x) * y := rfl
example : - x / y = (- x) / y := rfl
example : - x ^ y = - (x ^ y) := rfl
|
f88453378c1ffbb3c011ef058f6eb4a6df011af2 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/measure_theory/haar_measure_auto.lean | 029c1ff411ab5b05c56b6cbea17813ffe0f77e65 | [] | 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 | 26,329 | 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
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.measure_theory.content
import Mathlib.measure_theory.prod_group
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# Haar measure
In this file we prove the existence of Haar measure for a locally compact Hausdorff topological
group.
For the construction, we follow the write-up by Jonathan Gleason,
*Existence and Uniqueness of Haar Measure*.
This is essentially the same argument as in
https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets.
We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest)
number of left-translates of `U` are needed to cover `K` (`index` in the formalization).
Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`,
where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set
with nonempty interior. This function is `chaar` in the formalization, and we define the limit
formally using Tychonoff's theorem.
This function `h` forms a content, which we can extend to an outer measure `μ`
(`haar_outer_measure`), and obtain the Haar measure from that (`haar_measure`).
We normalize the Haar measure so that the measure of `K₀` is `1`.
We show that for second countable spaces any left invariant Borel measure is a scalar multiple of
the Haar measure.
Note that `μ` need not coincide with `h` on compact sets, according to
[halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`,
where `ᵒ` denotes the interior.
## Main Declarations
* `haar_measure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant
regular measure. It takes as argument a compact set of the group (with non-empty interior),
and is normalized so that the measure of the given set is 1.
* `haar_measure_self`: the Haar measure is normalized.
* `is_left_invariant_haar_measure`: the Haar measure is left invariant.
* `regular_haar_measure`: the Haar measure is a regular measure.
## References
* Paul Halmos (1950), Measure Theory, §53
* Jonathan Gleason, Existence and Uniqueness of Haar Measure
- Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact
sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11)
invalid.
* https://en.wikipedia.org/wiki/Haar_measure
-/
namespace measure_theory
namespace measure
/-! We put the internal functions in the construction of the Haar measure in a namespace,
so that the chosen names don't clash with other declarations.
We first define a couple of the functions before proving the properties (that require that `G`
is a topological group). -/
namespace haar
/-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`:
it is the smallest number of (left) translates of `V` that is necessary to cover `K`.
It is defined to be 0 if no finite number of translates cover `K`. -/
def index {G : Type u_1} [group G] (K : set G) (V : set G) : ℕ :=
Inf
(finset.card ''
set_of
fun (t : finset G) =>
K ⊆ set.Union fun (g : G) => set.Union fun (H : g ∈ t) => (fun (h : G) => g * h) ⁻¹' V)
theorem index_empty {G : Type u_1} [group G] {V : set G} : index ∅ V = 0 := sorry
/-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`.
In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`,
and `K` is any compact set.
The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an
element of `haar_product` (below). -/
def prehaar {G : Type u_1} [group G] [topological_space G] (K₀ : set G) (U : set G)
(K : topological_space.compacts G) : ℝ :=
↑(index (subtype.val K) U) / ↑(index K₀ U)
theorem prehaar_empty {G : Type u_1} [group G] [topological_space G]
(K₀ : topological_space.positive_compacts G) {U : set G} : prehaar (subtype.val K₀) U ⊥ = 0 :=
sorry
theorem prehaar_nonneg {G : Type u_1} [group G] [topological_space G]
(K₀ : topological_space.positive_compacts G) {U : set G} (K : topological_space.compacts G) :
0 ≤ prehaar (subtype.val K₀) U K :=
sorry
/-- `haar_product K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`.
For all `U`, we can show that `prehaar K₀ U ∈ haar_product K₀`. -/
def haar_product {G : Type u_1} [group G] [topological_space G] (K₀ : set G) :
set (topological_space.compacts G → ℝ) :=
set.pi set.univ fun (K : topological_space.compacts G) => set.Icc 0 ↑(index (subtype.val K) K₀)
@[simp] theorem mem_prehaar_empty {G : Type u_1} [group G] [topological_space G] {K₀ : set G}
{f : topological_space.compacts G → ℝ} :
f ∈ haar_product K₀ ↔
∀ (K : topological_space.compacts G), f K ∈ set.Icc 0 ↑(index (subtype.val K) K₀) :=
sorry
/-- The closure of the collection of elements of the form `prehaar K₀ U`,
for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space
`compacts G → ℝ`, with the topology of pointwise convergence.
We show that the intersection of all these sets is nonempty, and the Haar measure
on compact sets is defined to be an element in the closure of this intersection. -/
def cl_prehaar {G : Type u_1} [group G] [topological_space G] (K₀ : set G)
(V : topological_space.open_nhds_of 1) : set (topological_space.compacts G → ℝ) :=
closure (prehaar K₀ '' set_of fun (U : set G) => U ⊆ subtype.val V ∧ is_open U ∧ 1 ∈ U)
/-!
### Lemmas about `index`
-/
/-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined,
there is a finite set `t` satisfying the desired properties. -/
theorem index_defined {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K : set G} {V : set G} (hK : is_compact K) (hV : set.nonempty (interior V)) :
∃ (n : ℕ),
n ∈
finset.card ''
set_of
fun (t : finset G) =>
K ⊆
set.Union
fun (g : G) => set.Union fun (H : g ∈ t) => (fun (h : G) => g * h) ⁻¹' V :=
Exists.dcases_on (compact_covered_by_mul_left_translates hK hV)
fun (t : finset G)
(ht :
K ⊆ set.Union fun (g : G) => set.Union fun (H : g ∈ t) => (fun (h : G) => g * h) ⁻¹' V) =>
Exists.intro (finset.card t) (Exists.intro t { left := ht, right := rfl })
theorem index_elim {G : Type u_1} [group G] [topological_space G] [topological_group G] {K : set G}
{V : set G} (hK : is_compact K) (hV : set.nonempty (interior V)) :
∃ (t : finset G),
(K ⊆ set.Union fun (g : G) => set.Union fun (H : g ∈ t) => (fun (h : G) => g * h) ⁻¹' V) ∧
finset.card t = index K V :=
sorry
theorem le_index_mul {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) (K : topological_space.compacts G) {V : set G}
(hV : set.nonempty (interior V)) :
index (subtype.val K) V ≤ index (subtype.val K) (subtype.val K₀) * index (subtype.val K₀) V :=
sorry
theorem index_pos {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K : topological_space.positive_compacts G) {V : set G} (hV : set.nonempty (interior V)) :
0 < index (subtype.val K) V :=
sorry
theorem index_mono {G : Type u_1} [group G] [topological_space G] [topological_group G] {K : set G}
{K' : set G} {V : set G} (hK' : is_compact K') (h : K ⊆ K') (hV : set.nonempty (interior V)) :
index K V ≤ index K' V :=
sorry
theorem index_union_le {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₁ : topological_space.compacts G) (K₂ : topological_space.compacts G) {V : set G}
(hV : set.nonempty (interior V)) :
index (subtype.val K₁ ∪ subtype.val K₂) V ≤
index (subtype.val K₁) V + index (subtype.val K₂) V :=
sorry
theorem index_union_eq {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₁ : topological_space.compacts G) (K₂ : topological_space.compacts G) {V : set G}
(hV : set.nonempty (interior V))
(h : disjoint (subtype.val K₁ * (V⁻¹)) (subtype.val K₂ * (V⁻¹))) :
index (subtype.val K₁ ∪ subtype.val K₂) V =
index (subtype.val K₁) V + index (subtype.val K₂) V :=
sorry
theorem mul_left_index_le {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K : set G} (hK : is_compact K) {V : set G} (hV : set.nonempty (interior V)) (g : G) :
index ((fun (h : G) => g * h) '' K) V ≤ index K V :=
sorry
theorem is_left_invariant_index {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K : set G} (hK : is_compact K) (g : G) {V : set G} (hV : set.nonempty (interior V)) :
index ((fun (h : G) => g * h) '' K) V = index K V :=
sorry
/-!
### Lemmas about `prehaar`
-/
theorem prehaar_le_index {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) {U : set G} (K : topological_space.compacts G)
(hU : set.nonempty (interior U)) :
prehaar (subtype.val K₀) U K ≤ ↑(index (subtype.val K) (subtype.val K₀)) :=
sorry
theorem prehaar_pos {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) {U : set G} (hU : set.nonempty (interior U))
{K : set G} (h1K : is_compact K) (h2K : set.nonempty (interior K)) :
0 < prehaar (subtype.val K₀) U { val := K, property := h1K } :=
sorry
theorem prehaar_mono {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} {U : set G} (hU : set.nonempty (interior U))
{K₁ : topological_space.compacts G} {K₂ : topological_space.compacts G}
(h : subtype.val K₁ ⊆ subtype.val K₂) :
prehaar (subtype.val K₀) U K₁ ≤ prehaar (subtype.val K₀) U K₂ :=
sorry
theorem prehaar_self {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} {U : set G} (hU : set.nonempty (interior U)) :
prehaar (subtype.val K₀) U
{ val := subtype.val K₀, property := and.left (subtype.property K₀) } =
1 :=
sorry
theorem prehaar_sup_le {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} {U : set G} (K₁ : topological_space.compacts G)
(K₂ : topological_space.compacts G) (hU : set.nonempty (interior U)) :
prehaar (subtype.val K₀) U (K₁ ⊔ K₂) ≤
prehaar (subtype.val K₀) U K₁ + prehaar (subtype.val K₀) U K₂ :=
sorry
theorem prehaar_sup_eq {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} {U : set G} {K₁ : topological_space.compacts G}
{K₂ : topological_space.compacts G} (hU : set.nonempty (interior U))
(h : disjoint (subtype.val K₁ * (U⁻¹)) (subtype.val K₂ * (U⁻¹))) :
prehaar (subtype.val K₀) U (K₁ ⊔ K₂) =
prehaar (subtype.val K₀) U K₁ + prehaar (subtype.val K₀) U K₂ :=
sorry
theorem is_left_invariant_prehaar {G : Type u_1} [group G] [topological_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} {U : set G}
(hU : set.nonempty (interior U)) (g : G) (K : topological_space.compacts G) :
prehaar (subtype.val K₀) U
(topological_space.compacts.map (fun (b : G) => g * b) (continuous_mul_left g) K) =
prehaar (subtype.val K₀) U K :=
sorry
/-!
### Lemmas about `haar_product`
-/
theorem prehaar_mem_haar_product {G : Type u_1} [group G] [topological_space G]
[topological_group G] (K₀ : topological_space.positive_compacts G) {U : set G}
(hU : set.nonempty (interior U)) : prehaar (subtype.val K₀) U ∈ haar_product (subtype.val K₀) :=
sorry
theorem nonempty_Inter_cl_prehaar {G : Type u_1} [group G] [topological_space G]
[topological_group G] (K₀ : topological_space.positive_compacts G) :
set.nonempty
(haar_product (subtype.val K₀) ∩
set.Inter fun (V : topological_space.open_nhds_of 1) => cl_prehaar (subtype.val K₀) V) :=
sorry
/-!
### The Haar measure on compact sets
-/
/-- The Haar measure on compact sets, defined to be an arbitrary element in the intersection of
all the sets `cl_prehaar K₀ V` in `haar_product K₀`. -/
def chaar {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) (K : topological_space.compacts G) : ℝ :=
classical.some (nonempty_Inter_cl_prehaar K₀) K
theorem chaar_mem_haar_product {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) : chaar K₀ ∈ haar_product (subtype.val K₀) :=
and.left (classical.some_spec (nonempty_Inter_cl_prehaar K₀))
theorem chaar_mem_cl_prehaar {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) (V : topological_space.open_nhds_of 1) :
chaar K₀ ∈ cl_prehaar (subtype.val K₀) V :=
sorry
theorem chaar_nonneg {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) (K : topological_space.compacts G) :
0 ≤ chaar K₀ K :=
sorry
theorem chaar_empty {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) : chaar K₀ ⊥ = 0 :=
sorry
theorem chaar_self {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) :
chaar K₀ { val := subtype.val K₀, property := and.left (subtype.property K₀) } = 1 :=
sorry
theorem chaar_mono {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} {K₁ : topological_space.compacts G}
{K₂ : topological_space.compacts G} (h : subtype.val K₁ ⊆ subtype.val K₂) :
chaar K₀ K₁ ≤ chaar K₀ K₂ :=
sorry
theorem chaar_sup_le {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} (K₁ : topological_space.compacts G)
(K₂ : topological_space.compacts G) : chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂ :=
sorry
theorem chaar_sup_eq {G : Type u_1} [group G] [topological_space G] [topological_group G]
[t2_space G] {K₀ : topological_space.positive_compacts G} {K₁ : topological_space.compacts G}
{K₂ : topological_space.compacts G} (h : disjoint (subtype.val K₁) (subtype.val K₂)) :
chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂ :=
sorry
theorem is_left_invariant_chaar {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} (g : G) (K : topological_space.compacts G) :
chaar K₀ (topological_space.compacts.map (fun (b : G) => g * b) (continuous_mul_left g) K) =
chaar K₀ K :=
sorry
/-- The function `chaar` interpreted in `ennreal` -/
def echaar {G : Type u_1} [group G] [topological_space G] [topological_group G]
(K₀ : topological_space.positive_compacts G) (K : topological_space.compacts G) : ennreal :=
↑((fun (this : nnreal) => this) { val := chaar K₀ K, property := chaar_nonneg K₀ K })
/-! We only prove the properties for `echaar` that we use at least twice below. -/
/-- The variant of `chaar_sup_le` for `echaar` -/
theorem echaar_sup_le {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} (K₁ : topological_space.compacts G)
(K₂ : topological_space.compacts G) : echaar K₀ (K₁ ⊔ K₂) ≤ echaar K₀ K₁ + echaar K₀ K₂ :=
sorry
/-- The variant of `chaar_mono` for `echaar` -/
theorem echaar_mono {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} {K₁ : topological_space.compacts G}
{K₂ : topological_space.compacts G} (h : subtype.val K₁ ⊆ subtype.val K₂) :
echaar K₀ K₁ ≤ echaar K₀ K₂ :=
sorry
/-- The variant of `chaar_self` for `echaar` -/
theorem echaar_self {G : Type u_1} [group G] [topological_space G] [topological_group G]
{K₀ : topological_space.positive_compacts G} :
echaar K₀ { val := subtype.val K₀, property := and.left (subtype.property K₀) } = 1 :=
sorry
/-- The variant of `is_left_invariant_chaar` for `echaar` -/
theorem is_left_invariant_echaar {G : Type u_1} [group G] [topological_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} (g : G)
(K : topological_space.compacts G) :
echaar K₀ (topological_space.compacts.map (fun (b : G) => g * b) (continuous_mul_left g) K) =
echaar K₀ K :=
eq.mpr (id (Eq.trans (propext ennreal.coe_eq_coe) (propext (iff.symm nnreal.coe_eq))))
(eq.mp
(Eq.refl
(chaar K₀ (topological_space.compacts.map (Mul.mul g) (continuous_mul_left g) K) =
chaar K₀ K))
(is_left_invariant_chaar g K))
end haar
/-!
### The Haar outer measure
-/
/-- The Haar outer measure on `G`. It is not normalized, and is mainly used to construct
`haar_measure`, which is a normalized measure. -/
def haar_outer_measure {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] (K₀ : topological_space.positive_compacts G) : outer_measure G :=
outer_measure.of_content (haar.echaar K₀) sorry
theorem haar_outer_measure_eq_infi {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] (K₀ : topological_space.positive_compacts G) (A : set G) :
coe_fn (haar_outer_measure K₀) A =
infi
fun (U : set G) =>
infi
fun (hU : is_open U) =>
infi
fun (h : A ⊆ U) => inner_content (haar.echaar K₀) { val := U, property := hU } :=
outer_measure.of_content_eq_infi haar.echaar_sup_le A
theorem echaar_le_haar_outer_measure {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G}
(K : topological_space.compacts G) :
haar.echaar K₀ K ≤ coe_fn (haar_outer_measure K₀) (subtype.val K) :=
outer_measure.le_of_content_compacts haar.echaar_sup_le K
theorem haar_outer_measure_of_is_open {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} (U : set G)
(hU : is_open U) :
coe_fn (haar_outer_measure K₀) U =
inner_content (haar.echaar K₀) { val := U, property := hU } :=
outer_measure.of_content_opens haar.echaar_sup_le { val := U, property := hU }
theorem haar_outer_measure_le_echaar {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} {U : set G} (hU : is_open U)
(K : topological_space.compacts G) (h : U ⊆ subtype.val K) :
coe_fn (haar_outer_measure K₀) U ≤ haar.echaar K₀ K :=
outer_measure.of_content_le haar.echaar_sup_le haar.echaar_mono { val := U, property := hU } K h
theorem haar_outer_measure_exists_open {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} {A : set G}
(hA : coe_fn (haar_outer_measure K₀) A < ⊤) {ε : nnreal} (hε : 0 < ε) :
∃ (U : topological_space.opens G),
A ⊆ ↑U ∧ coe_fn (haar_outer_measure K₀) ↑U ≤ coe_fn (haar_outer_measure K₀) A + ↑ε :=
outer_measure.of_content_exists_open haar.echaar_sup_le hA hε
theorem haar_outer_measure_exists_compact {G : Type u_1} [group G] [topological_space G]
[t2_space G] [topological_group G] {K₀ : topological_space.positive_compacts G}
{U : topological_space.opens G} (hU : coe_fn (haar_outer_measure K₀) ↑U < ⊤) {ε : nnreal}
(hε : 0 < ε) :
∃ (K : topological_space.compacts G),
subtype.val K ⊆ ↑U ∧
coe_fn (haar_outer_measure K₀) ↑U ≤ coe_fn (haar_outer_measure K₀) (subtype.val K) + ↑ε :=
outer_measure.of_content_exists_compact haar.echaar_sup_le hU hε
theorem haar_outer_measure_caratheodory {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} (A : set G) :
measurable_space.is_measurable' (outer_measure.caratheodory (haar_outer_measure K₀)) A ↔
∀ (U : topological_space.opens G),
coe_fn (haar_outer_measure K₀) (↑U ∩ A) + coe_fn (haar_outer_measure K₀) (↑U \ A) ≤
coe_fn (haar_outer_measure K₀) ↑U :=
outer_measure.of_content_caratheodory haar.echaar_sup_le A
theorem one_le_haar_outer_measure_self {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} :
1 ≤ coe_fn (haar_outer_measure K₀) (subtype.val K₀) :=
sorry
theorem haar_outer_measure_pos_of_is_open {G : Type u_1} [group G] [topological_space G]
[t2_space G] [topological_group G] {K₀ : topological_space.positive_compacts G} {U : set G}
(hU : is_open U) (h2U : set.nonempty U) : 0 < coe_fn (haar_outer_measure K₀) U :=
sorry
theorem haar_outer_measure_self_pos {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] {K₀ : topological_space.positive_compacts G} :
0 < coe_fn (haar_outer_measure K₀) (subtype.val K₀) :=
has_lt.lt.trans_le
(haar_outer_measure_pos_of_is_open is_open_interior (and.right (subtype.property K₀)))
(outer_measure.mono (haar_outer_measure K₀) interior_subset)
theorem haar_outer_measure_lt_top_of_is_compact {G : Type u_1} [group G] [topological_space G]
[t2_space G] [topological_group G] [locally_compact_space G]
{K₀ : topological_space.positive_compacts G} {K : set G} (hK : is_compact K) :
coe_fn (haar_outer_measure K₀) K < ⊤ :=
sorry
theorem haar_caratheodory_measurable {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] [S : measurable_space G] [borel_space G]
(K₀ : topological_space.positive_compacts G) :
S ≤ outer_measure.caratheodory (haar_outer_measure K₀) :=
sorry
/-!
### The Haar measure
-/
/-- the Haar measure on `G`, scaled so that `haar_measure K₀ K₀ = 1`. -/
def haar_measure {G : Type u_1} [group G] [topological_space G] [t2_space G] [topological_group G]
[S : measurable_space G] [borel_space G] (K₀ : topological_space.positive_compacts G) :
measure G :=
coe_fn (haar_outer_measure K₀) (subtype.val K₀)⁻¹ •
outer_measure.to_measure (haar_outer_measure K₀) (haar_caratheodory_measurable K₀)
theorem haar_measure_apply {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] [S : measurable_space G] [borel_space G]
{K₀ : topological_space.positive_compacts G} {s : set G} (hs : is_measurable s) :
coe_fn (haar_measure K₀) s =
coe_fn (haar_outer_measure K₀) s / coe_fn (haar_outer_measure K₀) (subtype.val K₀) :=
sorry
theorem is_mul_left_invariant_haar_measure {G : Type u_1} [group G] [topological_space G]
[t2_space G] [topological_group G] [S : measurable_space G] [borel_space G]
(K₀ : topological_space.positive_compacts G) : is_mul_left_invariant ⇑(haar_measure K₀) :=
sorry
theorem haar_measure_self {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] [S : measurable_space G] [borel_space G] [locally_compact_space G]
{K₀ : topological_space.positive_compacts G} : coe_fn (haar_measure K₀) (subtype.val K₀) = 1 :=
sorry
theorem haar_measure_pos_of_is_open {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] [S : measurable_space G] [borel_space G] [locally_compact_space G]
{K₀ : topological_space.positive_compacts G} {U : set G} (hU : is_open U)
(h2U : set.nonempty U) : 0 < coe_fn (haar_measure K₀) U :=
sorry
theorem regular_haar_measure {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] [S : measurable_space G] [borel_space G] [locally_compact_space G]
{K₀ : topological_space.positive_compacts G} : regular (haar_measure K₀) :=
sorry
protected instance haar_measure.measure_theory.sigma_finite {G : Type u_1} [group G]
[topological_space G] [t2_space G] [topological_group G] [S : measurable_space G]
[borel_space G] [locally_compact_space G] [topological_space.separable_space G]
(K₀ : topological_space.positive_compacts G) : sigma_finite (haar_measure K₀) :=
regular.sigma_finite regular_haar_measure
/-- The Haar measure is unique up to scaling. More precisely: every σ-finite left invariant measure
is a scalar multiple of the Haar measure. -/
theorem haar_measure_unique {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] [S : measurable_space G] [borel_space G] [locally_compact_space G]
[topological_space.second_countable_topology G] {μ : measure G} [sigma_finite μ]
(hμ : is_mul_left_invariant ⇑μ) (K₀ : topological_space.positive_compacts G) :
μ = coe_fn μ (subtype.val K₀) • haar_measure K₀ :=
sorry
theorem regular_of_left_invariant {G : Type u_1} [group G] [topological_space G] [t2_space G]
[topological_group G] [S : measurable_space G] [borel_space G] [locally_compact_space G]
[topological_space.second_countable_topology G] {μ : measure G} [sigma_finite μ]
(hμ : is_mul_left_invariant ⇑μ) {K : set G} (hK : is_compact K)
(h2K : set.nonempty (interior K)) (hμK : coe_fn μ K < ⊤) : regular μ :=
sorry
end Mathlib |
6e8a031c9628c7fb425eea8302658c604234cdc0 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /tests/lean/run/forInUniv.lean | 0cca44ad60bccd48cc15b539dc119303034221d3 | [
"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 | 408 | lean |
universe u
def f {α : Type u} [BEq α] (xs : List α) (y : α) : α := do
for x in xs do
if x == y then
return x
return y
structure S :=
(key val : Nat)
instance : BEq S :=
⟨fun a b => a.key == b.key⟩
theorem ex1 : f (α := S) [⟨1, 2⟩, ⟨3, 4⟩, ⟨5, 6⟩] ⟨3, 0⟩ = ⟨3, 4⟩ :=
rfl
theorem ex2 : f (α := S) [⟨1, 2⟩, ⟨3, 4⟩, ⟨5, 6⟩] ⟨4, 10⟩ = ⟨4, 10⟩ :=
rfl
|
42fe8094725951af7e981c80588175e3e1e7704f | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/number_theory/pell_matiyasevic.lean | 0884c8773a3b16da54aa4e5885613fd89147e5a7 | [
"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 | 36,923 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import algebra.star.unitary
import data.nat.modeq
import number_theory.zsqrtd.basic
/-!
# Pell's equation and Matiyasevic's theorem
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1`
*in the special case that `d = a ^ 2 - 1`*.
This is then applied to prove Matiyasevic's theorem that the power
function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth
problem. For the definition of Diophantine function, see `number_theory.dioph.lean`.
For results on Pell's equation for arbitrary (positive, non-square) `d`, see
`number_theory.pell`.
## Main definition
* `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation
constructed recursively from the initial solution `(0, 1)`.
## Main statements
* `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell`
* `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if
the first variable is the `x`-component in a solution to Pell's equation - the key step towards
Hilbert's tenth problem in Davis' version of Matiyasevic's theorem.
* `eq_pow_of_pell` shows that the power function is Diophantine.
## Implementation notes
The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci
numbers but instead Davis' variant of using solutions to Pell's equation.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevič's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem
-/
namespace pell
open nat
section
variables {d : ℤ}
/-- The property of being a solution to the Pell equation, expressed
as a property of elements of `ℤ√d`. -/
def is_pell : ℤ√d → Prop | ⟨x, y⟩ := x*x - d*y*y = 1
theorem is_pell_norm : Π {b : ℤ√d}, is_pell b ↔ b * star b = 1
| ⟨x, y⟩ := by simp [zsqrtd.ext, is_pell, mul_comm]; ring_nf
theorem is_pell_iff_mem_unitary : Π {b : ℤ√d}, is_pell b ↔ b ∈ unitary ℤ√d
| ⟨x, y⟩ := by rw [unitary.mem_iff, is_pell_norm, mul_comm (star _), and_self]
theorem is_pell_mul {b c : ℤ√d} (hb : is_pell b) (hc : is_pell c) : is_pell (b * c) :=
is_pell_norm.2 (by simp [mul_comm, mul_left_comm, star_mul, is_pell_norm.1 hb, is_pell_norm.1 hc])
theorem is_pell_star : ∀ {b : ℤ√d}, is_pell b ↔ is_pell (star b) | ⟨x, y⟩ :=
by simp [is_pell, zsqrtd.star_mk]
end
section
parameters {a : ℕ} (a1 : 1 < a)
include a1
private def d := a*a - 1
@[simp] theorem d_pos : 0 < d :=
tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) dec_trivial dec_trivial : 1*1<a*a)
/-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where
`d = a ^ 2 - 1`, defined together in mutual recursion. -/
-- TODO(lint): Fix double namespace issue
@[nolint dup_namespace] def pell : ℕ → ℕ × ℕ :=
λn, nat.rec_on n (1, 0) (λn xy, (xy.1*a + d*xy.2, xy.1 + xy.2*a))
/-- The Pell `x` sequence. -/
def xn (n : ℕ) : ℕ := (pell n).1
/-- The Pell `y` sequence. -/
def yn (n : ℕ) : ℕ := (pell n).2
@[simp] theorem pell_val (n : ℕ) : pell n = (xn n, yn n) :=
show pell n = ((pell n).1, (pell n).2), from match pell n with (a, b) := rfl end
@[simp] theorem xn_zero : xn 0 = 1 := rfl
@[simp] theorem yn_zero : yn 0 = 0 := rfl
@[simp] theorem xn_succ (n : ℕ) : xn (n+1) = xn n * a + d * yn n := rfl
@[simp] theorem yn_succ (n : ℕ) : yn (n+1) = xn n + yn n * a := rfl
@[simp] theorem xn_one : xn 1 = a := by simp
@[simp] theorem yn_one : yn 1 = 1 := by simp
/-- The Pell `x` sequence, considered as an integer sequence.-/
def xz (n : ℕ) : ℤ := xn n
/-- The Pell `y` sequence, considered as an integer sequence.-/
def yz (n : ℕ) : ℤ := yn n
section
omit a1
/-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer.-/
def az : ℤ := a
end
theorem asq_pos : 0 < a*a :=
le_trans (le_of_lt a1) (by have := @nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa mul_one at this)
theorem dz_val : ↑d = az*az - 1 :=
have 1 ≤ a*a, from asq_pos,
show ↑(a*a - 1) = _, by rw int.coe_nat_sub this; refl
@[simp] theorem xz_succ (n : ℕ) : xz (n+1) = xz n * az + ↑d * yz n := rfl
@[simp] theorem yz_succ (n : ℕ) : yz (n+1) = xz n + yz n * az := rfl
/-- The Pell sequence can also be viewed as an element of `ℤ√d` -/
def pell_zd (n : ℕ) : ℤ√d := ⟨xn n, yn n⟩
@[simp] theorem pell_zd_re (n : ℕ) : (pell_zd n).re = xn n := rfl
@[simp] theorem pell_zd_im (n : ℕ) : (pell_zd n).im = yn n := rfl
theorem is_pell_nat {x y : ℕ} : is_pell (⟨x, y⟩ : ℤ√d) ↔ x*x - d*y*y = 1 :=
⟨λh, int.coe_nat_inj
(by rw int.coe_nat_sub (int.le_of_coe_nat_le_coe_nat $ int.le.intro_sub h); exact h),
λh, show ((x*x : ℕ) - (d*y*y:ℕ) : ℤ) = 1,
by rw [← int.coe_nat_sub $ le_of_lt $ nat.lt_of_sub_eq_succ h, h]; refl⟩
@[simp] theorem pell_zd_succ (n : ℕ) : pell_zd (n+1) = pell_zd n * ⟨a, 1⟩ :=
by simp [zsqrtd.ext]
theorem is_pell_one : is_pell (⟨a, 1⟩ : ℤ√d) :=
show az*az-d*1*1=1, by simp [dz_val]; ring
theorem is_pell_pell_zd : ∀ (n : ℕ), is_pell (pell_zd n)
| 0 := rfl
| (n+1) := let o := is_pell_one in by simp; exact pell.is_pell_mul (is_pell_pell_zd n) o
@[simp] theorem pell_eqz (n : ℕ) : xz n * xz n - d * yz n * yz n = 1 := is_pell_pell_zd n
@[simp] theorem pell_eq (n : ℕ) : xn n * xn n - d * yn n * yn n = 1 :=
let pn := pell_eqz n in
have h : (↑(xn n * xn n) : ℤ) - ↑(d * yn n * yn n) = 1,
by repeat {rw int.coe_nat_mul}; exact pn,
have hl : d * yn n * yn n ≤ xn n * xn n, from
int.le_of_coe_nat_le_coe_nat $ int.le.intro $ add_eq_of_eq_sub' $ eq.symm h,
int.coe_nat_inj (by rw int.coe_nat_sub hl; exact h)
instance dnsq : zsqrtd.nonsquare d := ⟨λn h,
have n*n + 1 = a*a, by rw ← h; exact nat.succ_pred_eq_of_pos (asq_pos a1),
have na : n < a, from nat.mul_self_lt_mul_self_iff.2 (by rw ← this; exact nat.lt_succ_self _),
have (n+1)*(n+1) ≤ n*n + 1, by rw this; exact nat.mul_self_le_mul_self na,
have n+n ≤ 0, from @nat.le_of_add_le_add_right (n*n + 1) _ _ (by ring_nf at this ⊢; assumption),
ne_of_gt d_pos $ by rwa nat.eq_zero_of_le_zero ((nat.le_add_left _ _).trans this) at h⟩
theorem xn_ge_a_pow : ∀ (n : ℕ), a^n ≤ xn n
| 0 := le_refl 1
| (n+1) := by simp [pow_succ']; exact le_trans
(nat.mul_le_mul_right _ (xn_ge_a_pow n)) (nat.le_add_right _ _)
theorem n_lt_a_pow : ∀ (n : ℕ), n < a^n
| 0 := nat.le_refl 1
| (n+1) := begin have IH := n_lt_a_pow n,
have : a^n + a^n ≤ a^n * a,
{ rw ← mul_two, exact nat.mul_le_mul_left _ a1 },
simp [pow_succ'], refine lt_of_lt_of_le _ this,
exact add_lt_add_of_lt_of_le IH (lt_of_le_of_lt (nat.zero_le _) IH)
end
theorem n_lt_xn (n) : n < xn n :=
lt_of_lt_of_le (n_lt_a_pow n) (xn_ge_a_pow n)
theorem x_pos (n) : 0 < xn n :=
lt_of_le_of_lt (nat.zero_le n) (n_lt_xn n)
lemma eq_pell_lem : ∀n (b:ℤ√d), 1 ≤ b → is_pell b → b ≤ pell_zd n → ∃n, b = pell_zd n
| 0 b := λh1 hp hl, ⟨0, @zsqrtd.le_antisymm _ dnsq _ _ hl h1⟩
| (n+1) b := λh1 hp h,
have a1p : (0:ℤ√d) ≤ ⟨a, 1⟩, from trivial,
have am1p : (0:ℤ√d) ≤ ⟨a, -1⟩, from show (_:nat) ≤ _, by simp; exact nat.pred_le _,
have a1m : (⟨a, 1⟩ * ⟨a, -1⟩ : ℤ√d) = 1, from is_pell_norm.1 is_pell_one,
if ha : (⟨↑a, 1⟩ : ℤ√d) ≤ b then
let ⟨m, e⟩ := eq_pell_lem n (b * ⟨a, -1⟩)
(by rw ← a1m; exact mul_le_mul_of_nonneg_right ha am1p)
(is_pell_mul hp (is_pell_star.1 is_pell_one))
(by have t := mul_le_mul_of_nonneg_right h am1p;
rwa [pell_zd_succ, mul_assoc, a1m, mul_one] at t) in
⟨m+1, by rw [show b = b * ⟨a, -1⟩ * ⟨a, 1⟩, by rw [mul_assoc, eq.trans (mul_comm _ _) a1m];
simp, pell_zd_succ, e]⟩
else
suffices ¬1 < b, from ⟨0, show b = 1, from (or.resolve_left (lt_or_eq_of_le h1) this).symm⟩,
λ h1l, by cases b with x y; exact
have bm : (_*⟨_,_⟩ :ℤ√(d a1)) = 1, from pell.is_pell_norm.1 hp,
have y0l : (0:ℤ√(d a1)) < ⟨x - x, y - -y⟩,
from sub_lt_sub h1l $ λ(hn : (1:ℤ√(d a1)) ≤ ⟨x, -y⟩),
by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1);
rw [bm, mul_one] at t; exact h1l t,
have yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩, from
show (⟨x, y⟩ - ⟨x, -y⟩ : ℤ√(d a1)) < ⟨a, 1⟩ - ⟨a, -1⟩, from
sub_lt_sub (by exact ha) $ λ(hn : (⟨x, -y⟩ : ℤ√(d a1)) ≤ ⟨a, -1⟩),
by have t := mul_le_mul_of_nonneg_right
(mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p;
rw [bm, one_mul, mul_assoc, eq.trans (mul_comm _ _) a1m, mul_one] at t; exact ha t,
by simp at y0l; simp at yl2; exact
match y, y0l, (yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩) with
| 0, y0l, yl2 := y0l (le_refl 0)
| (y+1 : ℕ), y0l, yl2 := yl2 (zsqrtd.le_of_le_le (le_refl 0)
(let t := int.coe_nat_le_coe_nat_of_le (nat.succ_pos y) in add_le_add t t))
| -[1+y], y0l, yl2 := y0l trivial
end
theorem eq_pell_zd (b : ℤ√d) (b1 : 1 ≤ b) (hp : is_pell b) : ∃n, b = pell_zd n :=
let ⟨n, h⟩ := @zsqrtd.le_arch d b in
eq_pell_lem n b b1 hp $ h.trans $ by rw zsqrtd.coe_nat_val; exact
zsqrtd.le_of_le_le
(int.coe_nat_le_coe_nat_of_le $ le_of_lt $ n_lt_xn _ _) (int.coe_zero_le _)
/-- Every solution to **Pell's equation** is recursively obtained from the initial solution
`(1,0)` using the recursion `pell`. -/
theorem eq_pell {x y : ℕ} (hp : x*x - d*y*y = 1) : ∃n, x = xn n ∧ y = yn n :=
have (1:ℤ√d) ≤ ⟨x, y⟩, from match x, hp with
| 0, (hp : 0 - _ = 1) := by rw zero_tsub at hp; contradiction
| (x+1), hp := zsqrtd.le_of_le_le (int.coe_nat_le_coe_nat_of_le $ nat.succ_pos x)
(int.coe_zero_le _)
end,
let ⟨m, e⟩ := eq_pell_zd ⟨x, y⟩ this (is_pell_nat.2 hp) in
⟨m, match x, y, e with ._, ._, rfl := ⟨rfl, rfl⟩ end⟩
theorem pell_zd_add (m) : ∀ n, pell_zd (m + n) = pell_zd m * pell_zd n
| 0 := (mul_one _).symm
| (n+1) := by rw[← add_assoc, pell_zd_succ, pell_zd_succ, pell_zd_add n, ← mul_assoc]
theorem xn_add (m n) : xn (m + n) = xn m * xn n + d * yn m * yn n :=
by injection (pell_zd_add _ m n) with h _;
repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem yn_add (m n) : yn (m + n) = xn m * yn n + yn m * xn n :=
by injection (pell_zd_add _ m n) with _ h;
repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem pell_zd_sub {m n} (h : n ≤ m) : pell_zd (m - n) = pell_zd m * star (pell_zd n) :=
let t := pell_zd_add n (m - n) in
by rw [add_tsub_cancel_of_le h] at t;
rw [t, mul_comm (pell_zd _ n) _, mul_assoc, is_pell_norm.1 (is_pell_pell_zd _ _), mul_one]
theorem xz_sub {m n} (h : n ≤ m) : xz (m - n) = xz m * xz n - d * yz m * yz n :=
by { rw [sub_eq_add_neg, ←mul_neg], exact congr_arg zsqrtd.re (pell_zd_sub a1 h) }
theorem yz_sub {m n} (h : n ≤ m) : yz (m - n) = xz n * yz m - xz m * yz n :=
by { rw [sub_eq_add_neg, ←mul_neg, mul_comm, add_comm],
exact congr_arg zsqrtd.im (pell_zd_sub a1 h) }
theorem xy_coprime (n) : (xn n).coprime (yn n) :=
nat.coprime_of_dvd' $ λk kp kx ky,
let p := pell_eq n in by rw ← p; exact
nat.dvd_sub (le_of_lt $ nat.lt_of_sub_eq_succ p)
(kx.mul_left _) (ky.mul_left _)
theorem strict_mono_y : strict_mono yn
| m 0 h := absurd h $ nat.not_lt_zero _
| m (n+1) h :=
have yn m ≤ yn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(λhl, le_of_lt $ strict_mono_y hl) (λe, by rw e),
by simp; refine lt_of_le_of_lt _ (nat.lt_add_of_pos_left $ x_pos a1 n);
rw ← mul_one (yn a1 m);
exact mul_le_mul this (le_of_lt a1) (nat.zero_le _) (nat.zero_le _)
theorem strict_mono_x : strict_mono xn
| m 0 h := absurd h $ nat.not_lt_zero _
| m (n+1) h :=
have xn m ≤ xn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(λhl, le_of_lt $ strict_mono_x hl) (λe, by rw e),
by simp; refine lt_of_lt_of_le (lt_of_le_of_lt this _) (nat.le_add_right _ _);
have t := nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n); rwa mul_one at t
theorem yn_ge_n : Π n, n ≤ yn n
| 0 := nat.zero_le _
| (n+1) := show n < yn (n+1), from lt_of_le_of_lt (yn_ge_n n) (strict_mono_y $ nat.lt_succ_self n)
theorem y_mul_dvd (n) : ∀k, yn n ∣ yn (n * k)
| 0 := dvd_zero _
| (k+1) := by rw [nat.mul_succ, yn_add]; exact
dvd_add (dvd_mul_left _ _) ((y_mul_dvd k).mul_right _)
theorem y_dvd_iff (m n) : yn m ∣ yn n ↔ m ∣ n :=
⟨λh, nat.dvd_of_mod_eq_zero $ (nat.eq_zero_or_pos _).resolve_right $ λhp,
have co : nat.coprime (yn m) (xn (m * (n / m))), from nat.coprime.symm $
(xy_coprime _).coprime_dvd_right (y_mul_dvd m (n / m)),
have m0 : 0 < m, from m.eq_zero_or_pos.resolve_left $
λe, by rw [e, nat.mod_zero] at hp; rw [e] at h; exact
ne_of_lt (strict_mono_y a1 hp) (eq_zero_of_zero_dvd h).symm,
by rw [← nat.mod_add_div n m, yn_add] at h; exact
not_le_of_gt (strict_mono_y _ $ nat.mod_lt n m0)
(nat.le_of_dvd (strict_mono_y _ hp) $ co.dvd_of_dvd_mul_right $
(nat.dvd_add_iff_right $ (y_mul_dvd _ _ _).mul_left _).2 h),
λ⟨k, e⟩, by rw e; apply y_mul_dvd⟩
theorem xy_modeq_yn (n) :
∀ k, xn (n * k) ≡ (xn n)^k [MOD (yn n)^2]
∧ yn (n * k) ≡ k * (xn n)^(k-1) * yn n [MOD (yn n)^3]
| 0 := by constructor; simp
| (k+1) :=
let ⟨hx, hy⟩ := xy_modeq_yn k in
have L : xn (n * k) * xn n + d * yn (n * k) * yn n ≡ xn n^k * xn n + 0 [MOD yn n^2], from
(hx.mul_right _ ).add $ modeq_zero_iff_dvd.2 $
by rw pow_succ'; exact
mul_dvd_mul_right (dvd_mul_of_dvd_right (modeq_zero_iff_dvd.1 $
(hy.of_dvd $ by simp [pow_succ']).trans $ modeq_zero_iff_dvd.2 $
by simp [-mul_comm, -mul_assoc]) _) _,
have R : xn (n * k) * yn n + yn (n * k) * xn n ≡
xn n^k * yn n + k * xn n^k * yn n [MOD yn n^3], from
modeq.add (by { rw pow_succ', exact hx.mul_right' _ }) $
have k * xn n^(k - 1) * yn n * xn n = k * xn n^k * yn n,
by clear _let_match; cases k with k; simp [pow_succ', mul_comm, mul_left_comm],
by { rw ← this, exact hy.mul_right _ },
by { rw [add_tsub_cancel_right, nat.mul_succ, xn_add, yn_add, pow_succ' (xn _ n),
nat.succ_mul, add_comm (k * xn _ n^k) (xn _ n^k), right_distrib],
exact ⟨L, R⟩ }
theorem ysq_dvd_yy (n) : yn n * yn n ∣ yn (n * yn n) :=
modeq_zero_iff_dvd.1 $
((xy_modeq_yn n (yn n)).right.of_dvd $ by simp [pow_succ]).trans
(modeq_zero_iff_dvd.2 $ by simp [mul_dvd_mul_left, mul_assoc])
theorem dvd_of_ysq_dvd {n t} (h : yn n * yn n ∣ yn t) : yn n ∣ t :=
have nt : n ∣ t, from (y_dvd_iff n t).1 $ dvd_of_mul_left_dvd h,
n.eq_zero_or_pos.elim (λ n0, by rwa n0 at ⊢ nt) $ λ (n0l : 0 < n),
let ⟨k, ke⟩ := nt in
have yn n ∣ k * (xn n)^(k-1), from
nat.dvd_of_mul_dvd_mul_right (strict_mono_y n0l) $ modeq_zero_iff_dvd.1 $
by have xm := (xy_modeq_yn a1 n k).right; rw ← ke at xm; exact
(xm.of_dvd $ by simp [pow_succ]).symm.trans h.modeq_zero_nat,
by rw ke; exact dvd_mul_of_dvd_right
(((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _
theorem pell_zd_succ_succ (n) : pell_zd (n + 2) + pell_zd n = (2 * a : ℕ) * pell_zd (n + 1) :=
have (1:ℤ√d) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a),
by { rw zsqrtd.coe_nat_val, change (⟨_,_⟩:ℤ√(d a1))=⟨_,_⟩,
rw dz_val, dsimp [az], rw zsqrtd.ext, dsimp, split; ring },
by simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (* pell_zd a1 n) this
theorem xy_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) ∧
yn (n + 2) + yn n = (2 * a) * yn (n + 1) := begin
have := pell_zd_succ_succ a1 n, unfold pell_zd at this,
erw [zsqrtd.smul_val (2 * a : ℕ)] at this,
injection this with h₁ h₂,
split; apply int.coe_nat_inj; [simpa using h₁, simpa using h₂]
end
theorem xn_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) := (xy_succ_succ n).1
theorem yn_succ_succ (n) : yn (n + 2) + yn n = (2 * a) * yn (n + 1) := (xy_succ_succ n).2
theorem xz_succ_succ (n) : xz (n + 2) = (2 * a : ℕ) * xz (n + 1) - xz n :=
eq_sub_of_add_eq $ by delta xz; rw [← int.coe_nat_add, ← int.coe_nat_mul, xn_succ_succ]
theorem yz_succ_succ (n) : yz (n + 2) = (2 * a : ℕ) * yz (n + 1) - yz n :=
eq_sub_of_add_eq $ by delta yz; rw [← int.coe_nat_add, ← int.coe_nat_mul, yn_succ_succ]
theorem yn_modeq_a_sub_one : ∀ n, yn n ≡ n [MOD a-1]
| 0 := by simp
| 1 := by simp
| (n+2) := (yn_modeq_a_sub_one n).add_right_cancel $
begin
rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))],
exact ((modeq_sub a1.le).mul_left 2).mul (yn_modeq_a_sub_one (n+1)),
end
theorem yn_modeq_two : ∀ n, yn n ≡ n [MOD 2]
| 0 := by simp
| 1 := by simp
| (n+2) := (yn_modeq_two n).add_right_cancel $
begin
rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))],
exact (dvd_mul_right 2 _).modeq_zero_nat.trans (dvd_mul_right 2 _).zero_modeq_nat,
end
section
omit a1
lemma x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) :
(a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) =
y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring
end
theorem x_sub_y_dvd_pow (y : ℕ) :
∀ n, (2*a*y - y*y - 1 : ℤ) ∣ yz n * (a - y) + ↑(y^n) - xz n
| 0 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| 1 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| (n+2) :=
have (2*a*y - y*y - 1 : ℤ) ∣ ↑(y^(n + 2)) - ↑(2 * a) * ↑(y^(n + 1)) + ↑(y^n), from
⟨-↑(y^n), by { simp [pow_succ, mul_add, int.coe_nat_mul,
show ((2:ℕ):ℤ) = 2, from rfl, mul_comm, mul_left_comm], ring }⟩,
by { rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem ↑(y^(n+2)) ↑(y^(n+1)) ↑(y^n)],
exact
dvd_sub (dvd_add this $ (x_sub_y_dvd_pow (n+1)).mul_left _) (x_sub_y_dvd_pow n) }
theorem xn_modeq_x2n_add_lem (n j) : xn n ∣ d * yn n * (yn n * xn j) + xn j :=
have h1 : d * yn n * (yn n * xn j) + xn j = (d * yn n * yn n + 1) * xn j,
by simp [add_mul, mul_assoc],
have h2 : d * yn n * yn n + 1 = xn n * xn n, by apply int.coe_nat_inj;
repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul}; exact
add_eq_of_eq_sub' (eq.symm $ pell_eqz _ _),
by rw h2 at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _
theorem xn_modeq_x2n_add (n j) : xn (2 * n + j) + xn j ≡ 0 [MOD xn n] :=
begin
rw [two_mul, add_assoc, xn_add, add_assoc, ←zero_add 0],
refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modeq_zero_nat.add _,
rw [yn_add, left_distrib, add_assoc, ←zero_add 0],
exact ((dvd_mul_right _ _).mul_left _).modeq_zero_nat.add
(xn_modeq_x2n_add_lem _ _ _).modeq_zero_nat,
end
lemma xn_modeq_x2n_sub_lem {n j} (h : j ≤ n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] :=
have h1 : xz n ∣ ↑d * yz n * yz (n - j) + xz j,
by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub]; exact
dvd_sub
(by delta xz; delta yz;
repeat {rw ← int.coe_nat_add <|> rw ← int.coe_nat_mul}; rw mul_comm (xn a1 j) (yn a1 n);
exact int.coe_nat_dvd.2 (xn_modeq_x2n_add_lem _ _ _))
((dvd_mul_right _ _).mul_left _),
begin
rw [two_mul, add_tsub_assoc_of_le h, xn_add, add_assoc, ←zero_add 0],
exact (dvd_mul_right _ _).modeq_zero_nat.add
(int.coe_nat_dvd.1 $ by simpa [xz, yz] using h1).modeq_zero_nat,
end
theorem xn_modeq_x2n_sub {n j} (h : j ≤ 2 * n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] :=
(le_total j n).elim xn_modeq_x2n_sub_lem
(λjn, have 2 * n - j + j ≤ n + j, by rw [tsub_add_cancel_of_le h, two_mul];
exact nat.add_le_add_left jn _,
let t := xn_modeq_x2n_sub_lem (nat.le_of_add_le_add_right this) in
by rwa [tsub_tsub_cancel_of_le h, add_comm] at t)
theorem xn_modeq_x4n_add (n j) : xn (4 * n + j) ≡ xn j [MOD xn n] :=
modeq.add_right_cancel' (xn (2 * n + j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_add _ _ _).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, add_assoc]; apply xn_modeq_x2n_add
theorem xn_modeq_x4n_sub {n j} (h : j ≤ 2 * n) : xn (4 * n - j) ≡ xn j [MOD xn n] :=
have h' : j ≤ 2*n, from le_trans h (by rw nat.succ_mul; apply nat.le_add_left),
modeq.add_right_cancel' (xn (2 * n - j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_sub _ h).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, add_tsub_assoc_of_le h'];
apply xn_modeq_x2n_add
theorem eq_of_xn_modeq_lem1 {i n} : Π {j}, i < j → j < n → xn i % xn n < xn j % xn n
| 0 ij _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij jn :=
suffices xn j % xn n < xn (j + 1) % xn n, from
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(λh, lt_trans (eq_of_xn_modeq_lem1 h (le_of_lt jn)) this)
(λh, by rw h; exact this),
by rw [nat.mod_eq_of_lt (strict_mono_x _ (nat.lt_of_succ_lt jn)),
nat.mod_eq_of_lt (strict_mono_x _ jn)];
exact strict_mono_x _ (nat.lt_succ_self _)
theorem eq_of_xn_modeq_lem2 {n} (h : 2 * xn n = xn (n + 1)) : a = 2 ∧ n = 0 :=
by rw [xn_succ, mul_comm] at h; exact
have n = 0, from n.eq_zero_or_pos.resolve_right $ λnp,
ne_of_lt (lt_of_le_of_lt (nat.mul_le_mul_left _ a1)
(nat.lt_add_of_pos_right $ mul_pos (d_pos a1) (strict_mono_y a1 np))) h,
by cases this; simp at h; exact ⟨h.symm, rfl⟩
theorem eq_of_xn_modeq_lem3 {i n} (npos : 0 < n) :
Π {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → xn i % xn n < xn j % xn n
| 0 ij _ _ _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij j2n jnn ntriv :=
have lem2 : ∀k > n, k ≤ 2*n → (↑(xn k % xn n) : ℤ) = xn n - xn (2 * n - k), from λk kn k2n,
let k2nl := lt_of_add_lt_add_right $ show 2*n-k+k < n+k, by
{rw tsub_add_cancel_of_le, rw two_mul; exact (add_lt_add_left kn n), exact k2n } in
have xle : xn (2 * n - k) ≤ xn n, from le_of_lt $ strict_mono_x k2nl,
suffices xn k % xn n = xn n - xn (2 * n - k), by rw [this, int.coe_nat_sub xle],
by
{ rw ← nat.mod_eq_of_lt (nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k))),
apply modeq.add_right_cancel' (xn a1 (2 * n - k)),
rw [tsub_add_cancel_of_le xle],
have t := xn_modeq_x2n_sub_lem a1 k2nl.le,
rw tsub_tsub_cancel_of_le k2n at t,
exact t.trans dvd_rfl.zero_modeq_nat },
(lt_trichotomy j n).elim
(λ (jn : j < n), eq_of_xn_modeq_lem1 ij (lt_of_le_of_ne jn jnn)) $ λ o, o.elim
(λ (jn : j = n), by
{ cases jn,
apply int.lt_of_coe_nat_lt_coe_nat,
rw [lem2 (n+1) (nat.lt_succ_self _) j2n,
show 2 * n - (n + 1) = n - 1, by rw[two_mul, tsub_add_eq_tsub_tsub, add_tsub_cancel_right]],
refine lt_sub_left_of_add_lt (int.coe_nat_lt_coe_nat_of_lt _),
cases (lt_or_eq_of_le $ nat.le_of_succ_le_succ ij) with lin ein,
{ rw nat.mod_eq_of_lt (strict_mono_x _ lin),
have ll : xn a1 (n-1) + xn a1 (n-1) ≤ xn a1 n,
{ rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n-1+1),
by rw [tsub_add_cancel_of_le (succ_le_of_lt npos)], xn_succ],
exact le_trans (nat.mul_le_mul_left _ a1) (nat.le_add_right _ _) },
have npm : (n-1).succ = n := nat.succ_pred_eq_of_pos npos,
have il : i ≤ n - 1, { apply nat.le_of_succ_le_succ, rw npm, exact lin },
cases lt_or_eq_of_le il with ill ile,
{ exact lt_of_lt_of_le (nat.add_lt_add_left (strict_mono_x a1 ill) _) ll },
{ rw ile,
apply lt_of_le_of_ne ll,
rw ← two_mul,
exact λe, ntriv $
let ⟨a2, s1⟩ := @eq_of_xn_modeq_lem2 _ a1 (n-1)
(by rwa [tsub_add_cancel_of_le (succ_le_of_lt npos)]) in
have n1 : n = 1, from le_antisymm (tsub_eq_zero_iff_le.mp s1) npos,
by rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩ } },
{ rw [ein, nat.mod_self, add_zero],
exact strict_mono_x _ (nat.pred_lt npos.ne') } })
(λ (jn : j > n),
have lem1 : j ≠ n → xn j % xn n < xn (j + 1) % xn n → xn i % xn n < xn (j + 1) % xn n,
from λjn s,
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(λh, lt_trans (eq_of_xn_modeq_lem3 h (le_of_lt j2n) jn $ λ⟨a1, n1, i0, j2⟩,
by rw [n1, j2] at j2n; exact absurd j2n dec_trivial) s)
(λh, by rw h; exact s),
lem1 (ne_of_gt jn) $ int.lt_of_coe_nat_lt_coe_nat $ by
{ rw [lem2 j jn (le_of_lt j2n), lem2 (j+1) (nat.le_succ_of_le jn) j2n],
refine sub_lt_sub_left (int.coe_nat_lt_coe_nat_of_lt $ strict_mono_x _ _) _,
rw [nat.sub_succ],
exact nat.pred_lt (ne_of_gt $ tsub_pos_of_lt j2n) })
theorem eq_of_xn_modeq_le {i j n} (ij : i ≤ j) (j2n : j ≤ 2 * n)
(h : xn i ≡ xn j [MOD xn n]) (ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j :=
if npos : n = 0 then by simp [*] at * else
(lt_or_eq_of_le ij).resolve_left $ λij',
if jn : j = n then by
{ refine ne_of_gt _ h,
rw [jn, nat.mod_self],
have x0 : 0 < xn a1 0 % xn a1 n :=
by rw [nat.mod_eq_of_lt (strict_mono_x a1 (nat.pos_of_ne_zero npos))]; exact dec_trivial,
cases i with i, exact x0,
rw jn at ij',
exact x0.trans (eq_of_xn_modeq_lem3 _ (nat.pos_of_ne_zero npos) (nat.succ_pos _)
(le_trans ij j2n) (ne_of_lt ij') $
λ⟨a1, n1, _, i2⟩, by rw [n1, i2] at ij'; exact absurd ij' dec_trivial) }
else ne_of_lt (eq_of_xn_modeq_lem3 (nat.pos_of_ne_zero npos) ij' j2n jn ntriv) h
theorem eq_of_xn_modeq {i j n} (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n)
(h : xn i ≡ xn j [MOD xn n]) (ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) :
i = j :=
(le_total i j).elim
(λij, eq_of_xn_modeq_le ij j2n h $ λ⟨a2, n1, i0, j2⟩, (ntriv a2 n1).left i0 j2)
(λij, (eq_of_xn_modeq_le ij i2n h.symm $ λ⟨a2, n1, j0, i2⟩,
(ntriv a2 n1).right i2 j0).symm)
theorem eq_of_xn_modeq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n)
(h : xn j ≡ xn i [MOD xn n]) : j = i ∨ j + i = 4 * n :=
have i2n : i ≤ 2*n, by apply le_trans hin; rw two_mul; apply nat.le_add_left,
(le_or_gt j (2 * n)).imp
(λj2n : j ≤ 2 * n, eq_of_xn_modeq j2n i2n h $
λa2 n1, ⟨λj0 i2, by rw [n1, i2] at hin; exact absurd hin dec_trivial,
λj2 i0, ne_of_gt ipos i0⟩)
(λj2n : 2 * n < j, suffices i = 4*n - j, by rw [this, add_tsub_cancel_of_le j4n],
have j42n : 4*n - j ≤ 2*n, from @nat.le_of_add_le_add_right j _ _ $
by rw [tsub_add_cancel_of_le j4n, show 4*n = 2*n + 2*n, from right_distrib 2 2 n];
exact nat.add_le_add_left (le_of_lt j2n) _,
eq_of_xn_modeq i2n j42n
(h.symm.trans $ let t := xn_modeq_x4n_sub j42n in by rwa [tsub_tsub_cancel_of_le j4n] at t)
(λa2 n1, ⟨λi0, absurd i0 (ne_of_gt ipos), λi2, by { rw [n1, i2] at hin,
exact absurd hin dec_trivial }⟩))
theorem modeq_of_xn_modeq {i j n} (ipos : 0 < i) (hin : i ≤ n) (h : xn j ≡ xn i [MOD xn n]) :
j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] :=
let j' := j % (4 * n) in
have n4 : 0 < 4 * n, from mul_pos dec_trivial (ipos.trans_le hin),
have jl : j' < 4 * n, from nat.mod_lt _ n4,
have jj : j ≡ j' [MOD 4 * n], by delta modeq; rw nat.mod_eq_of_lt jl,
have ∀j q, xn (j + 4 * n * q) ≡ xn j [MOD xn n], begin
intros j q, induction q with q IH, { simp },
rw [nat.mul_succ, ← add_assoc, add_comm],
exact (xn_modeq_x4n_add _ _ _).trans IH
end,
or.imp
(λ(ji : j' = i), by rwa ← ji)
(λ(ji : j' + i = 4 * n), (jj.add_right _).trans $
by { rw ji, exact dvd_rfl.modeq_zero_nat })
(eq_of_xn_modeq' ipos hin jl.le $
(h.symm.trans $ by { rw ← nat.mod_add_div j (4*n), exact this j' _ }).symm)
end
theorem xy_modeq_of_modeq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) :
∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c]
| 0 := by constructor; refl
| 1 := by simp; exact ⟨h, modeq.refl 1⟩
| (n+2) := ⟨
(xy_modeq_of_modeq n).left.add_right_cancel $
by { rw [xn_succ_succ a1, xn_succ_succ b1], exact
(h.mul_left _ ).mul (xy_modeq_of_modeq (n+1)).left },
(xy_modeq_of_modeq n).right.add_right_cancel $
by { rw [yn_succ_succ a1, yn_succ_succ b1], exact
(h.mul_left _ ).mul (xy_modeq_of_modeq (n+1)).right }⟩
theorem matiyasevic {a k x y} : (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔
1 < a ∧ k ≤ y ∧
(x = 1 ∧ y = 0 ∨
∃ (u v s t b : ℕ),
x * x - (a * a - 1) * y * y = 1 ∧
u * u - (a * a - 1) * v * v = 1 ∧
s * s - (b * b - 1) * t * t = 1 ∧
1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧
0 < v ∧ y * y ∣ v ∧
s ≡ x [MOD u] ∧
t ≡ k [MOD 4 * y]) :=
⟨λ⟨a1, hx, hy⟩, by rw [← hx, ← hy];
refine ⟨a1, (nat.eq_zero_or_pos k).elim
(λk0, by rw k0; exact ⟨le_rfl, or.inl ⟨rfl, rfl⟩⟩) (λkpos, _)⟩; exact
let x := xn a1 k, y := yn a1 k,
m := 2 * (k * y),
u := xn a1 m, v := yn a1 m in
have ky : k ≤ y, from yn_ge_n a1 k,
have yv : y * y ∣ v, from (ysq_dvd_yy a1 k).trans $ (y_dvd_iff _ _ _).2 $ dvd_mul_left _ _,
have uco : nat.coprime u (4 * y), from
have 2 ∣ v, from modeq_zero_iff_dvd.1 $ (yn_modeq_two _ _).trans
(dvd_mul_right _ _).modeq_zero_nat,
have nat.coprime u 2, from
(xy_coprime a1 m).coprime_dvd_right this,
(this.mul_right this).mul_right $
(xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv),
let ⟨b, ba, bm1⟩ := chinese_remainder uco a 1 in
have m1 : 1 < m, from
have 0 < k * y, from mul_pos kpos (strict_mono_y a1 kpos),
nat.mul_le_mul_left 2 this,
have vp : 0 < v, from strict_mono_y a1 (lt_trans zero_lt_one m1),
have b1 : 1 < b, from
have xn a1 1 < u, from strict_mono_x a1 m1,
have a < u, by simp at this; exact this,
lt_of_lt_of_le a1 $ by delta modeq at ba;
rw nat.mod_eq_of_lt this at ba; rw ← ba; apply nat.mod_le,
let s := xn b1 k, t := yn b1 k in
have sx : s ≡ x [MOD u], from (xy_modeq_of_modeq b1 a1 ba k).left,
have tk : t ≡ k [MOD 4 * y], from
have 4 * y ∣ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1);
exact bm1.symm.dvd,
(yn_modeq_a_sub_one _ _).of_dvd this,
⟨ky, or.inr ⟨u, v, s, t, b,
pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tk⟩⟩,
λ⟨a1, ky, o⟩, ⟨a1, match o with
| or.inl ⟨x1, y0⟩ := by rw y0 at ky; rw [nat.eq_zero_of_le_zero ky, x1, y0]; exact ⟨rfl, rfl⟩
| or.inr ⟨u, v, s, t, b, xy, uv, st, b1, rem⟩ :=
match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with
| ._, ._, ⟨i, rfl, rfl⟩, ._, ._, ⟨n, rfl, rfl⟩, ._, ._, ⟨j, rfl, rfl⟩,
⟨(bm1 : b ≡ 1 [MOD 4 * yn a1 i]),
(ba : b ≡ a [MOD xn a1 n]),
(vp : 0 < yn a1 n),
(yv : yn a1 i * yn a1 i ∣ yn a1 n),
(sx : xn b1 j ≡ xn a1 i [MOD xn a1 n]),
(tk : yn b1 j ≡ k [MOD 4 * yn a1 i])⟩,
(ky : k ≤ yn a1 i) :=
(nat.eq_zero_or_pos i).elim
(λi0, by simp [i0] at ky; rw [i0, ky]; exact ⟨rfl, rfl⟩) $ λipos,
suffices i = k, by rw this; exact ⟨rfl, rfl⟩,
by clear _x o rem xy uv st _match _match _fun_match; exact
have iln : i ≤ n, from le_of_not_gt $ λhin,
not_lt_of_ge (nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (strict_mono_y a1 hin),
have yd : 4 * yn a1 i ∣ 4 * n, from mul_dvd_mul_left _ $ dvd_of_ysq_dvd a1 yv,
have jk : j ≡ k [MOD 4 * yn a1 i], from
have 4 * yn a1 i ∣ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1); exact bm1.symm.dvd,
((yn_modeq_a_sub_one b1 _).of_dvd this).symm.trans tk,
have ki : k + i < 4 * yn a1 i, from
lt_of_le_of_lt (add_le_add ky (yn_ge_n a1 i)) $
by rw ← two_mul; exact nat.mul_lt_mul_of_pos_right dec_trivial (strict_mono_y a1 ipos),
have ji : j ≡ i [MOD 4 * n], from
have xn a1 j ≡ xn a1 i [MOD xn a1 n], from (xy_modeq_of_modeq b1 a1 ba j).left.symm.trans sx,
(modeq_of_xn_modeq a1 ipos iln this).resolve_right $ λ (ji : j + i ≡ 0 [MOD 4 * n]),
not_le_of_gt ki $ nat.le_of_dvd (lt_of_lt_of_le ipos $ nat.le_add_left _ _) $
modeq_zero_iff_dvd.1 $ (jk.symm.add_right i).trans $
ji.of_dvd yd,
by have : i % (4 * yn a1 i) = k % (4 * yn a1 i) :=
(ji.of_dvd yd).symm.trans jk;
rwa [nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_left _ _) ki),
nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_right _ _) ki)] at this
end
end⟩⟩
lemma eq_pow_of_pell_lem {a y k} (hy0 : y ≠ 0) (hk0 : k ≠ 0) (hyk : y^k < a) :
(↑(y^k) : ℤ) < 2*a*y - y*y - 1 :=
have hya : y < a, from (nat.le_self_pow hk0 _).trans_lt hyk,
calc (↑(y ^ k) : ℤ) < a : nat.cast_lt.2 hyk
... ≤ a ^ 2 - (a - 1) ^ 2 - 1 :
begin
rw [sub_sq, mul_one, one_pow, sub_add, sub_sub_cancel, two_mul, sub_sub, ← add_sub,
le_add_iff_nonneg_right, ← bit0, sub_nonneg, ← nat.cast_two, nat.cast_le, nat.succ_le_iff],
exact (one_le_iff_ne_zero.2 hy0).trans_lt hya
end
... ≤ a ^ 2 - (a - y) ^ 2 - 1 : have _ := hya.le,
by { mono*; simpa only [sub_nonneg, nat.cast_le, nat.one_le_cast, nat.one_le_iff_ne_zero] }
... = 2*a*y - y*y - 1 : by ring
theorem eq_pow_of_pell {m n k} : n^k = m ↔
k = 0 ∧ m = 1 ∨
0 < k ∧ (n = 0 ∧ m = 0 ∨
0 < n ∧ ∃ (w a t z : ℕ) (a1 : 1 < a),
xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧
2 * a * n = t + (n * n + 1) ∧
m < t ∧ n ≤ w ∧ k ≤ w ∧
a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1) :=
begin
split,
{ rintro rfl,
refine k.eq_zero_or_pos.imp (λ k0, k0.symm ▸ ⟨rfl, rfl⟩) (λ hk, ⟨hk, _⟩),
refine n.eq_zero_or_pos.imp (λ n0, n0.symm ▸ ⟨rfl, zero_pow hk⟩) (λ hn, ⟨hn, _⟩),
set w := max n k,
have nw : n ≤ w, from le_max_left _ _,
have kw : k ≤ w, from le_max_right _ _,
have wpos : 0 < w, from hn.trans_le nw,
have w1 : 1 < w + 1, from nat.succ_lt_succ wpos,
set a := xn w1 w,
have a1 : 1 < a, from strict_mono_x w1 wpos,
have na : n ≤ a, from nw.trans (n_lt_xn w1 w).le,
set x := xn a1 k, set y := yn a1 k,
obtain ⟨z, ze⟩ : w ∣ yn w1 w,
from modeq_zero_iff_dvd.1 ((yn_modeq_a_sub_one w1 w).trans dvd_rfl.modeq_zero_nat),
have nt : (↑(n^k) : ℤ) < 2 * a * n - n * n - 1,
{ refine eq_pow_of_pell_lem hn.ne' hk.ne' _,
calc n^k ≤ n^w : nat.pow_le_pow_of_le_right hn kw
... < (w + 1)^w : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) wpos
... ≤ a : xn_ge_a_pow w1 w },
lift (2 * a * n - n * n - 1 : ℤ) to ℕ using ((nat.cast_nonneg _).trans nt.le) with t te,
have tm : x ≡ y * (a - n) + n^k [MOD t],
{ apply modeq_of_dvd,
rw [int.coe_nat_add, int.coe_nat_mul, int.coe_nat_sub na, te],
exact x_sub_y_dvd_pow a1 n k },
have ta : 2 * a * n = t + (n * n + 1),
{ rw [← @nat.cast_inj ℤ, int.coe_nat_add, te, sub_sub],
repeat { rw nat.cast_add <|> rw nat.cast_mul },
rw [nat.cast_one, sub_add_cancel, nat.cast_two] },
have zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1,
from ze ▸ pell_eq w1 w,
exact ⟨w, a, t, z, a1, tm, ta, nat.cast_lt.1 nt, nw, kw, zp⟩ },
{ rintro (⟨rfl, rfl⟩ | ⟨hk0, ⟨rfl, rfl⟩ | ⟨hn0, w, a, t, z, a1, tm, ta, mt, nw, kw, zp⟩⟩),
{ exact pow_zero n }, { exact zero_pow hk0 },
have hw0 : 0 < w, from hn0.trans_le nw,
have hw1 : 1 < w + 1, from nat.succ_lt_succ hw0,
rcases eq_pell hw1 zp with ⟨j, rfl, yj⟩,
have hj0 : 0 < j,
{ apply nat.pos_of_ne_zero,
rintro rfl,
exact lt_irrefl 1 a1 },
have wj : w ≤ j := nat.le_of_dvd hj0 (modeq_zero_iff_dvd.1 $
(yn_modeq_a_sub_one hw1 j).symm.trans $ modeq_zero_iff_dvd.2 ⟨z, yj.symm⟩),
have hnka : n ^ k < xn hw1 j,
calc n^k ≤ n^j : nat.pow_le_pow_of_le_right hn0 (le_trans kw wj)
... < (w + 1)^j : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) hj0
... ≤ xn hw1 j : xn_ge_a_pow hw1 j,
have nt : (↑(n^k) : ℤ) < 2 * xn hw1 j * n - n * n - 1,
from eq_pow_of_pell_lem hn0.ne' hk0.ne' hnka,
have na : n ≤ xn hw1 j, from (nat.le_self_pow hk0.ne' _).trans hnka.le,
have te : (t : ℤ) = 2 * xn hw1 j * n - n * n - 1,
{ rw [sub_sub, eq_sub_iff_add_eq],
exact_mod_cast ta.symm },
have : xn a1 k ≡ yn a1 k * (xn hw1 j - n) + n^k [MOD t],
{ apply modeq_of_dvd,
rw [te, nat.cast_add, nat.cast_mul, int.coe_nat_sub na],
exact x_sub_y_dvd_pow a1 n k },
have : n^k % t = m % t, from (this.symm.trans tm).add_left_cancel' _,
rw [← te] at nt,
rwa [nat.mod_eq_of_lt (nat.cast_lt.1 nt), nat.mod_eq_of_lt mt] at this }
end
end pell
|
7c74cbdca49427fbba7a3bcd903eb1624e66a17e | acc85b4be2c618b11fc7cb3005521ae6858a8d07 | /data/set/default.lean | 3a4fb36ddf3bf8499bf8ab15ae41ab0802a7ffe0 | [
"Apache-2.0"
] | permissive | linpingchuan/mathlib | d49990b236574df2a45d9919ba43c923f693d341 | 5ad8020f67eb13896a41cc7691d072c9331b1f76 | refs/heads/master | 1,626,019,377,808 | 1,508,048,784,000 | 1,508,048,784,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 73 | lean | import data.set.lattice data.set.finite data.set.prod data.set.intervals
|
24136e349b8cf5cef51e9d2329a5c191480bae09 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/format_macro.lean | 37d72e2f92385dfc1195d2b2df16c76ca91e8d55 | [
"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 | 402 | lean | #eval to_string $ format!"hi"
#eval to_string $ format! "hi"
#eval to_string $ format!"hi\nhi"
#eval to_string $ format!"{1}+{1}"
#eval to_string $ format!"{1+1}"
#eval to_string $ format!"{{{1+1}}"
#eval to_string $ format!"a{1}"
#eval to_string $ format!"{1}a"
#eval to_string $ format!"}"
#check λ α, format!"{α}"
#eval format!"{"
#eval format!"{}"
#eval format!"{1+}"
#eval sformat!"a{'b'}c"
|
cfd4af33cc6235361cc63c5bf46d4977dbf65b79 | 649957717d58c43b5d8d200da34bf374293fe739 | /src/linear_algebra/dimension.lean | 31a2983fcfeb631a9d195d59a1f0732985ed14d1 | [
"Apache-2.0"
] | permissive | Vtec234/mathlib | b50c7b21edea438df7497e5ed6a45f61527f0370 | fb1848bbbfce46152f58e219dc0712f3289d2b20 | refs/heads/master | 1,592,463,095,113 | 1,562,737,749,000 | 1,562,737,749,000 | 196,202,858 | 0 | 0 | Apache-2.0 | 1,562,762,338,000 | 1,562,762,337,000 | null | UTF-8 | Lean | false | false | 16,646 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro, Johannes Hölzl, Sander Dahmen
Dimension of modules and vector spaces.
-/
import linear_algebra.basis
import set_theory.ordinal
noncomputable theory
universes u v v' w w'
variables {α : Type u} {β γ δ ε : Type v}
variables {ι : Type w} {ι' : Type w'} {η : Type u} {φ : η → Type u}
-- TODO: relax these universe constraints
section vector_space
variables [decidable_eq ι] [decidable_eq ι'] [discrete_field α] [add_comm_group β] [vector_space α β]
include α
open submodule lattice function set
variables (α β)
def vector_space.dim : cardinal :=
cardinal.min
(nonempty_subtype.2 (@exists_is_basis α β _ (classical.dec_eq _) _ _ _))
(λ b, cardinal.mk b.1)
variables {α β}
open vector_space
section
set_option class.instance_max_depth 50
theorem is_basis.le_span (zero_ne_one : (0 : α) ≠ 1) [decidable_eq β] {v : ι → β} {J : set β} (hv : is_basis α v)
(hJ : span α J = ⊤) : cardinal.mk (range v) ≤ cardinal.mk J :=
begin
cases le_or_lt cardinal.omega (cardinal.mk J) with oJ oJ,
{ have := cardinal.mk_range_eq_of_inj (linear_independent.injective zero_ne_one hv.1),
let S : J → set ι := λ j, (is_basis.repr hv j).support.to_set,
let S' : J → set β := λ j, v '' S j,
have hs : range v ⊆ ⋃ j, S' j,
{ intros b hb,
rcases mem_range.1 hb with ⟨i, hi⟩,
have : span α J ≤ comap hv.repr (finsupp.supported α α (⋃ j, S j)) :=
span_le.2 (λ j hj x hx, ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩),
rw hJ at this,
replace : hv.repr (v i) ∈ (finsupp.supported α α (⋃ j, S j)) := this trivial,
rw [hv.repr_eq_single, finsupp.mem_supported, finsupp.support_single_ne_zero zero_ne_one.symm] at this,
rw ← hi,
apply mem_Union.2,
rcases mem_Union.1 (this (mem_singleton _)) with ⟨j, hj⟩,
use j,
rw mem_image,
use i,
exact ⟨hj, rfl⟩ },
refine le_of_not_lt (λ IJ, _),
suffices : cardinal.mk (⋃ j, S' j) < cardinal.mk (range v),
{ exact not_le_of_lt this ⟨set.embedding_of_subset hs⟩ },
refine lt_of_le_of_lt (le_trans cardinal.mk_Union_le_sum_mk
(cardinal.sum_le_sum _ (λ _, cardinal.omega) _)) _,
{ exact λ j, le_of_lt (cardinal.lt_omega_iff_finite.2 $ finite_image _ (finset.finite_to_set _)) },
{ rwa [cardinal.sum_const, cardinal.mul_eq_max oJ (le_refl _), max_eq_left oJ] } },
{ rcases exists_finite_card_le_of_finite_of_linear_independent_of_span
(cardinal.lt_omega_iff_finite.1 oJ) hv.1.to_subtype_range _ with ⟨fI, hi⟩,
{ rwa [← cardinal.nat_cast_le, cardinal.finset_card, finset.coe_to_finset,
cardinal.finset_card, finset.coe_to_finset] at hi, },
{ rw hJ, apply set.subset_univ } },
end
end
/-- dimension theorem -/
theorem mk_eq_mk_of_basis [decidable_eq β] {v : ι → β} {v' : ι' → β}
(hv : is_basis α v) (hv' : is_basis α v') :
cardinal.lift.{w w'} (cardinal.mk ι) = cardinal.lift.{w' w} (cardinal.mk ι') :=
begin
rw ←cardinal.lift_inj.{(max w w') v},
rw [cardinal.lift_lift, cardinal.lift_lift],
apply le_antisymm,
{ convert cardinal.lift_le.{v (max w w')}.2 (hv.le_span zero_ne_one hv'.2),
{ rw cardinal.lift_max.{w v w'},
apply (cardinal.mk_range_eq_of_inj (hv.injective zero_ne_one)).symm, },
{ rw cardinal.lift_max.{w' v w},
apply (cardinal.mk_range_eq_of_inj (hv'.injective zero_ne_one)).symm, }, },
{ convert cardinal.lift_le.{v (max w w')}.2 (hv'.le_span zero_ne_one hv.2),
{ rw cardinal.lift_max.{w' v w},
apply (cardinal.mk_range_eq_of_inj (hv'.injective zero_ne_one)).symm, },
{ rw cardinal.lift_max.{w v w'},
apply (cardinal.mk_range_eq_of_inj (hv.injective zero_ne_one)).symm, }, }
end
theorem is_basis.mk_range_eq_dim [decidable_eq β] {v : ι → β} (h : is_basis α v) :
cardinal.mk (range v) = dim α β :=
begin
have := show ∃ v', dim α β = _, from cardinal.min_eq _ _,
rcases this with ⟨v', e⟩,
rw e,
apply cardinal.lift_inj.1,
rw cardinal.mk_range_eq_of_inj (h.injective zero_ne_one),
convert @mk_eq_mk_of_basis _ _ _ _ _ (id _) _ _ _ (id _) _ _ h v'.property
end
theorem is_basis.mk_eq_dim [decidable_eq β] {v : ι → β} (h : is_basis α v) :
cardinal.lift.{w v} (cardinal.mk ι) = cardinal.lift.{v w} (dim α β) :=
by rw [←h.mk_range_eq_dim, cardinal.mk_range_eq_of_inj (h.injective zero_ne_one)]
variables [add_comm_group γ] [vector_space α γ]
theorem linear_equiv.dim_eq (f : β ≃ₗ[α] γ) :
dim α β = dim α γ :=
by letI := classical.dec_eq β;
letI := classical.dec_eq γ; exact
let ⟨b, hb⟩ := exists_is_basis α β in
cardinal.lift_inj.1 $ hb.mk_eq_dim.symm.trans (f.is_basis hb).mk_eq_dim
lemma dim_bot : dim α (⊥ : submodule α β) = 0 :=
by letI := classical.dec_eq β;
rw [← cardinal.lift_inj, ← (@is_basis_empty_bot pempty α β _ _ _ _ _ _ nonempty_pempty).mk_eq_dim,
cardinal.mk_pempty]
lemma dim_of_field (α : Type*) [discrete_field α] : dim α α = 1 :=
by rw [←cardinal.lift_inj, ← (@is_basis_singleton_one punit _ α _ _ _).mk_eq_dim, cardinal.mk_punit]
lemma dim_span [decidable_eq β] {v : ι → β} (hv : linear_independent α v) :
dim α ↥(span α (range v)) = cardinal.mk (range v) :=
by rw [←cardinal.lift_inj, ← (is_basis_span hv).mk_eq_dim,
cardinal.mk_range_eq_of_inj (@linear_independent.injective ι α β v _ _ _ _ _ _ zero_ne_one hv)]
lemma dim_span_set [decidable_eq β] {s : set β} (hs : linear_independent α (λ x, x : s → β)) :
dim α ↥(span α s) = cardinal.mk s :=
by rw [← @set_of_mem_eq _ s, ← subtype.val_range]; exact dim_span hs
lemma dim_span_le (s : set β) : dim α (span α s) ≤ cardinal.mk s :=
begin
classical,
rcases
exists_linear_independent linear_independent_empty (set.empty_subset s)
with ⟨b, hb, _, hsb, hlib⟩,
have hsab : span α s = span α b,
from span_eq_of_le _ hsb (span_le.2 (λ x hx, subset_span (hb hx))),
convert cardinal.mk_le_mk_of_subset hb,
rw [hsab, dim_span_set hlib]
end
lemma dim_span_of_finset (s : finset β) :
dim α (span α (↑s : set β)) < cardinal.omega :=
calc dim α (span α (↑s : set β)) ≤ cardinal.mk (↑s : set β) : dim_span_le ↑s
... = s.card : by rw ←cardinal.finset_card
... < cardinal.omega : cardinal.nat_lt_omega _
theorem dim_prod : dim α (β × γ) = dim α β + dim α γ :=
begin
letI := classical.dec_eq β,
letI := classical.dec_eq γ,
rcases exists_is_basis α β with ⟨b, hb⟩,
rcases exists_is_basis α γ with ⟨c, hc⟩,
rw [← cardinal.lift_inj,
← @is_basis.mk_eq_dim α (β × γ) _ _ _ _ _ _ _ (is_basis_inl_union_inr hb hc),
cardinal.lift_add, cardinal.lift_mk,
← hb.mk_eq_dim, ← hc.mk_eq_dim,
cardinal.lift_mk, cardinal.lift_mk,
cardinal.add_def (ulift b) (ulift c)],
exact cardinal.lift_inj.1 (cardinal.lift_mk_eq.2
⟨equiv.ulift.trans (equiv.sum_congr (@equiv.ulift b) (@equiv.ulift c)).symm ⟩),
end
theorem dim_quotient (p : submodule α β) [decidable_eq p.quotient]:
dim α p.quotient + dim α p = dim α β :=
by classical; exact let ⟨f⟩ := quotient_prod_linear_equiv p in dim_prod.symm.trans f.dim_eq
/-- rank-nullity theorem -/
theorem dim_range_add_dim_ker (f : β →ₗ[α] γ) : dim α f.range + dim α f.ker = dim α β :=
begin
haveI := λ (p : submodule α β), classical.dec_eq p.quotient,
rw [← f.quot_ker_equiv_range.dim_eq, dim_quotient]
end
lemma dim_range_le (f : β →ₗ[α] γ) : dim α f.range ≤ dim α β :=
by rw ← dim_range_add_dim_ker f; exact le_add_right (le_refl _)
lemma dim_map_le (f : β →ₗ γ) (p : submodule α β) : dim α (p.map f) ≤ dim α p :=
begin
have h := dim_range_le (f.comp (submodule.subtype p)),
rwa [linear_map.range_comp, range_subtype] at h,
end
lemma dim_range_of_surjective (f : β →ₗ[α] γ) (h : surjective f) : dim α f.range = dim α γ :=
begin
refine linear_equiv.dim_eq (linear_equiv.of_bijective (submodule.subtype _) _ _),
exact linear_map.ker_eq_bot.2 subtype.val_injective,
rwa [range_subtype, linear_map.range_eq_top]
end
lemma dim_eq_surjective (f : β →ₗ[α] γ) (h : surjective f) : dim α β = dim α γ + dim α f.ker :=
by rw [← dim_range_add_dim_ker f, ← dim_range_of_surjective f h]
lemma dim_le_surjective (f : β →ₗ[α] γ) (h : surjective f) : dim α γ ≤ dim α β :=
by rw [dim_eq_surjective f h]; refine le_add_right (le_refl _)
lemma dim_eq_injective (f : β →ₗ[α] γ) (h : injective f) : dim α β = dim α f.range :=
by rw [← dim_range_add_dim_ker f, linear_map.ker_eq_bot.2 h]; simp [dim_bot]
set_option class.instance_max_depth 37
lemma dim_submodule_le (s : submodule α β) : dim α s ≤ dim α β :=
begin
letI := classical.dec_eq β,
rcases exists_is_basis α s with ⟨bs, hbs⟩,
have : linear_independent α (λ (i : bs), submodule.subtype s i.val) :=
(linear_independent.image hbs.1) (linear_map.disjoint_ker'.2
(λ _ _ _ _ h, subtype.val_injective h)),
rcases exists_subset_is_basis (this.to_subtype_range) with ⟨b, hbs_b, hb⟩,
rw [←cardinal.lift_le, ← is_basis.mk_eq_dim hbs, ← is_basis.mk_eq_dim hb, cardinal.lift_le],
have : subtype.val '' bs ⊆ b,
{ convert hbs_b,
rw [@range_comp _ _ _ (λ (i : bs), (i.val)) (submodule.subtype s),
←image_univ, submodule.subtype],
simp only [subtype.val_image_univ],
refl },
calc cardinal.mk ↥bs = cardinal.mk ((subtype.val : s → β) '' bs) :
(cardinal.mk_image_eq $ subtype.val_injective).symm
... ≤ cardinal.mk ↥b :
nonempty.intro (embedding_of_subset this),
end
set_option class.instance_max_depth 32
lemma dim_le_injective (f : β →ₗ[α] γ) (h : injective f) :
dim α β ≤ dim α γ :=
by rw [dim_eq_injective f h]; exact dim_submodule_le _
lemma dim_le_of_submodule (s t : submodule α β) (h : s ≤ t) : dim α s ≤ dim α t :=
dim_le_injective (of_le h) $ assume ⟨x, hx⟩ ⟨y, hy⟩ eq,
subtype.eq $ show x = y, from subtype.ext.1 eq
section
variables [add_comm_group δ] [vector_space α δ]
variables [add_comm_group ε] [vector_space α ε]
set_option class.instance_max_depth 70
open linear_map
/-- This is mostly an auxiliary lemma for `dim_sup_add_dim_inf_eq` -/
lemma dim_add_dim_split
(db : δ →ₗ[α] β) (eb : ε →ₗ[α] β) (cd : γ →ₗ[α] δ) (ce : γ →ₗ[α] ε)
(hde : ⊤ ≤ db.range ⊔ eb.range)
(hgd : ker cd = ⊥)
(eq : db.comp cd = eb.comp ce)
(eq₂ : ∀d e, db d = eb e → (∃c, cd c = d ∧ ce c = e)) :
dim α β + dim α γ = dim α δ + dim α ε :=
have hf : surjective (copair db eb),
begin
refine (range_eq_top.1 $ top_unique $ _),
rwa [← map_top, ← prod_top, map_copair_prod]
end,
begin
conv {to_rhs, rw [← dim_prod, dim_eq_surjective _ hf] },
congr' 1,
apply linear_equiv.dim_eq,
fapply linear_equiv.of_bijective,
{ refine cod_restrict _ (pair cd (- ce)) _,
{ assume c,
simp [add_eq_zero_iff_eq_neg],
exact linear_map.ext_iff.1 eq c } },
{ rw [ker_cod_restrict, ker_pair, hgd, bot_inf_eq] },
{ rw [eq_top_iff, range_cod_restrict, ← map_le_iff_le_comap, map_top, range_subtype],
rintros ⟨d, e⟩,
have h := eq₂ d (-e),
simp [add_eq_zero_iff_eq_neg] at ⊢ h,
assume hde,
rcases h hde with ⟨c, h₁, h₂⟩,
refine ⟨c, h₁, _⟩,
rw [h₂, _root_.neg_neg] }
end
lemma dim_sup_add_dim_inf_eq (s t : submodule α β) :
dim α (s ⊔ t : submodule α β) + dim α (s ⊓ t : submodule α β) = dim α s + dim α t :=
dim_add_dim_split (of_le le_sup_left) (of_le le_sup_right) (of_le inf_le_left) (of_le inf_le_right)
begin
rw [← map_le_map_iff (ker_subtype $ s ⊔ t), map_sup, map_top,
← linear_map.range_comp, ← linear_map.range_comp, subtype_comp_of_le, subtype_comp_of_le,
range_subtype, range_subtype, range_subtype],
exact le_refl _
end
(ker_of_le _ _ _)
begin ext ⟨x, hx⟩, refl end
begin
rintros ⟨b₁, hb₁⟩ ⟨b₂, hb₂⟩ eq,
have : b₁ = b₂ := congr_arg subtype.val eq,
subst this,
exact ⟨⟨b₁, hb₁, hb₂⟩, rfl, rfl⟩
end
lemma dim_add_le_dim_add_dim (s t : submodule α β) :
dim α (s ⊔ t : submodule α β) ≤ dim α s + dim α t :=
by rw [← dim_sup_add_dim_inf_eq]; exact le_add_right (le_refl _)
end
section fintype
variable [fintype η]
variables [∀i, add_comm_group (φ i)] [∀i, vector_space α (φ i)]
open linear_map
lemma dim_pi : vector_space.dim α (Πi, φ i) = cardinal.sum (λi, vector_space.dim α (φ i)) :=
begin
letI := λ i, classical.dec_eq (φ i),
choose b hb using assume i, exists_is_basis α (φ i),
haveI := classical.dec_eq η,
have : is_basis α (λ (ji : Σ j, b j), std_basis α (λ j, φ j) ji.fst ji.snd.val),
by apply pi.is_basis_std_basis _ hb,
rw [←cardinal.lift_inj, ← this.mk_eq_dim],
simp [λ i, (hb i).mk_range_eq_dim.symm, cardinal.sum_mk]
end
lemma dim_fun {β : Type u} [add_comm_group β] [vector_space α β] :
vector_space.dim α (η → β) = fintype.card η * vector_space.dim α β :=
by rw [dim_pi, cardinal.sum_const, cardinal.fintype_card]
lemma dim_fun' : vector_space.dim α (η → α) = fintype.card η :=
by rw [dim_fun, dim_of_field α, mul_one]
end fintype
lemma exists_mem_ne_zero_of_ne_bot {s : submodule α β} (h : s ≠ ⊥) : ∃ b : β, b ∈ s ∧ b ≠ 0 :=
begin
classical,
by_contradiction hex,
have : ∀x∈s, (x:β) = 0, { simpa only [not_exists, not_and, not_not, ne.def] using hex },
exact (h $ bot_unique $ assume s hs, (submodule.mem_bot α).2 $ this s hs)
end
lemma exists_mem_ne_zero_of_dim_pos {s : submodule α β} (h : vector_space.dim α s > 0) :
∃ b : β, b ∈ s ∧ b ≠ 0 :=
exists_mem_ne_zero_of_ne_bot $ assume eq, by rw [(>), eq, dim_bot] at h; exact lt_irrefl _ h
lemma exists_is_basis_fintype [decidable_eq β] (h : dim α β < cardinal.omega) :
∃ s : (set β), (is_basis α (subtype.val : s → β)) ∧ nonempty (fintype s) :=
begin
cases exists_is_basis α β with s hs,
rw [←cardinal.lift_lt, ← is_basis.mk_eq_dim hs, cardinal.lift_lt,
cardinal.lt_omega_iff_fintype] at h,
exact ⟨s, hs, h⟩
end
section rank
def rank (f : β →ₗ[α] γ) : cardinal := dim α f.range
lemma rank_le_domain (f : β →ₗ[α] γ) : rank f ≤ dim α β :=
by rw [← dim_range_add_dim_ker f]; exact le_add_right (le_refl _)
lemma rank_le_range (f : β →ₗ[α] γ) : rank f ≤ dim α γ :=
dim_submodule_le _
lemma rank_add_le (f g : β →ₗ[α] γ) : rank (f + g) ≤ rank f + rank g :=
calc rank (f + g) ≤ dim α (f.range ⊔ g.range : submodule α γ) :
begin
refine dim_le_of_submodule _ _ _,
exact (linear_map.range_le_iff_comap.2 $ eq_top_iff'.2 $
assume x, show f x + g x ∈ (f.range ⊔ g.range : submodule α γ), from
mem_sup.2 ⟨_, mem_image_of_mem _ (mem_univ _), _, mem_image_of_mem _ (mem_univ _), rfl⟩)
end
... ≤ rank f + rank g : dim_add_le_dim_add_dim _ _
@[simp] lemma rank_zero : rank (0 : β →ₗ[α] γ) = 0 :=
by rw [rank, linear_map.range_zero, dim_bot]
lemma rank_finset_sum_le {η} (s : finset η) (f : η → β →ₗ[α] γ) :
rank (s.sum f) ≤ s.sum (λ d, rank (f d)) :=
@finset.sum_hom_rel _ _ _ _ _ (λa b, rank a ≤ b) f (λ d, rank (f d)) s (le_of_eq rank_zero)
(λ i g c h, le_trans (rank_add_le _ _) (add_le_add_left' h))
variables [add_comm_group δ] [vector_space α δ]
lemma rank_comp_le1 (g : β →ₗ[α] γ) (f : γ →ₗ[α] δ) : rank (f.comp g) ≤ rank f :=
begin
refine dim_le_of_submodule _ _ _,
rw [linear_map.range_comp],
exact image_subset _ (subset_univ _)
end
lemma rank_comp_le2 (g : β →ₗ[α] γ) (f : γ →ₗ δ) : rank (f.comp g) ≤ rank g :=
by rw [rank, rank, linear_map.range_comp]; exact dim_map_le _ _
end rank
end vector_space
section unconstrained_universes
variables {γ' : Type v'}
variables [discrete_field α] [add_comm_group β] [vector_space α β]
[add_comm_group γ'] [vector_space α γ']
open vector_space
/-- Version of linear_equiv.dim_eq without universe constraints. -/
theorem linear_equiv.dim_eq_lift [decidable_eq β] [decidable_eq γ'] (f : β ≃ₗ[α] γ') :
cardinal.lift.{v v'} (dim α β) = cardinal.lift.{v' v} (dim α γ') :=
begin
cases exists_is_basis α β with b hb,
rw [← cardinal.lift_inj.1 hb.mk_eq_dim, ← (f.is_basis hb).mk_eq_dim, cardinal.lift_mk],
end
end unconstrained_universes
|
19c92f0f70ac151fa594b912dc3ddd8edd837700 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /src/Lean/Compiler/ImplementedByAttr.lean | 43a4eb81bed1272345fb4fcb16069f12b7d2f53d | [
"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 | 1,508 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Attributes
import Lean.MonadEnv
namespace Lean.Compiler
builtin_initialize implementedByAttr : ParametricAttribute Name ← registerParametricAttribute {
name := `implementedBy,
descr := "name of the Lean (probably unsafe) function that implements opaque constant",
getParam := fun declName stx => do
let decl ← getConstInfo declName
match attrParamSyntaxToIdentifier stx with
| some fnName =>
let fnName ← resolveGlobalConstNoOverload fnName
let fnDecl ← getConstInfo fnName
if decl.type == fnDecl.type then pure fnName
else throwError! "invalid function '{fnName}' type mismatch"
| _ => throwError "expected identifier",
}
@[export lean_get_implemented_by]
def getImplementedBy (env : Environment) (declName : Name) : Option Name :=
implementedByAttr.getParam env declName
def setImplementedBy (env : Environment) (declName : Name) (impName : Name) : Except String Environment :=
implementedByAttr.setParam env declName impName
end Compiler
def setImplementedBy {m} [Monad m] [MonadEnv m] [MonadExceptOf Exception m] [Ref m] [AddErrorMessageContext m]
(declName : Name) (impName : Name) : m Unit := do
let env ← getEnv
match Compiler.setImplementedBy env declName impName with
| Except.ok env => setEnv env
| Except.error ex => throwError ex
end Lean
|
07cbb8747a3daf490ef74a9e6984586556eb7cf2 | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/algebra/lie_algebra.lean | b4669d5b69e8e42137311db1e61cd18edbbaea04 | [
"Apache-2.0"
] | permissive | kmill/mathlib | ea5a007b67ae4e9e18dd50d31d8aa60f650425ee | 1a419a9fea7b959317eddd556e1bb9639f4dcc05 | refs/heads/master | 1,668,578,197,719 | 1,593,629,163,000 | 1,593,629,163,000 | 276,482,939 | 0 | 0 | null | 1,593,637,960,000 | 1,593,637,959,000 | null | UTF-8 | Lean | false | false | 39,953 | lean | /-
Copyright (c) 2019 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import ring_theory.algebra
import linear_algebra.linear_action
import linear_algebra.bilinear_form
import tactic.noncomm_ring
/-!
# Lie algebras
This file defines Lie rings, and Lie algebras over a commutative ring. It shows how these arise from
associative rings and algebras via the ring commutator. In particular it defines the Lie algebra
of endomorphisms of a module as well as of the algebra of square matrices over a commutative ring.
It also includes definitions of morphisms of Lie algebras, Lie subalgebras, Lie modules, Lie
submodules, and the quotient of a Lie algebra by an ideal.
## Notations
We introduce the notation ⁅x, y⁆ for the Lie bracket. Note that these are the Unicode "square with
quill" brackets rather than the usual square brackets.
We also introduce the notations L →ₗ⁅R⁆ L' for a morphism of Lie algebras over a commutative ring R,
and L →ₗ⁅⁆ L' for the same, when the ring is implicit.
## Implementation notes
Lie algebras are defined as modules with a compatible Lie ring structure, and thus are partially
unbundled. Since they extend Lie rings, these are also partially unbundled.
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*][bourbaki1975]
## Tags
lie bracket, ring commutator, jacobi identity, lie ring, lie algebra
-/
universes u v w w₁
/--
A binary operation, intended use in Lie algebras and similar structures.
-/
class has_bracket (L : Type v) := (bracket : L → L → L)
notation `⁅`x`,` y`⁆` := has_bracket.bracket x y
/-- An Abelian Lie algebra is one in which all brackets vanish. Arguably this class belongs in the
`has_bracket` namespace but it seems much more user-friendly to compromise slightly and put it in
the `lie_algebra` namespace. -/
class lie_algebra.is_abelian (L : Type v) [has_bracket L] [has_zero L] : Prop :=
(abelian : ∀ (x y : L), ⁅x, y⁆ = 0)
namespace ring_commutator
variables {A : Type v} [ring A]
/--
The ring commutator captures the extent to which a ring is commutative. It is identically zero
exactly when the ring is commutative.
-/
def commutator (x y : A) := x*y - y*x
local notation `⁅`x`,` y`⁆` := commutator x y
@[simp] lemma add_left (x y z : A) :
⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆ :=
by simp [commutator, right_distrib, left_distrib, sub_eq_add_neg, add_comm, add_left_comm]
@[simp] lemma add_right (x y z : A) :
⁅z, x + y⁆ = ⁅z, x⁆ + ⁅z, y⁆ :=
by simp [commutator, right_distrib, left_distrib, sub_eq_add_neg, add_comm, add_left_comm]
@[simp] lemma alternate (x : A) :
⁅x, x⁆ = 0 :=
by simp [commutator]
lemma jacobi (x y z : A) :
⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 :=
by { unfold commutator, noncomm_ring, }
end ring_commutator
section prio
set_option default_priority 100 -- see Note [default priority]
/--
A Lie ring is an additive group with compatible product, known as the bracket, satisfying the
Jacobi identity. The bracket is not associative unless it is identically zero.
-/
@[protect_proj] class lie_ring (L : Type v) extends add_comm_group L, has_bracket L :=
(add_lie : ∀ (x y z : L), ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆)
(lie_add : ∀ (x y z : L), ⁅z, x + y⁆ = ⁅z, x⁆ + ⁅z, y⁆)
(lie_self : ∀ (x : L), ⁅x, x⁆ = 0)
(jacobi : ∀ (x y z : L), ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0)
end prio
section lie_ring
variables {L : Type v} [lie_ring L]
@[simp] lemma add_lie (x y z : L) : ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆ := lie_ring.add_lie x y z
@[simp] lemma lie_add (x y z : L) : ⁅z, x + y⁆ = ⁅z, x⁆ + ⁅z, y⁆ := lie_ring.lie_add x y z
@[simp] lemma lie_self (x : L) : ⁅x, x⁆ = 0 := lie_ring.lie_self x
@[simp] lemma lie_skew (x y : L) :
-⁅y, x⁆ = ⁅x, y⁆ :=
begin
symmetry,
rw [←sub_eq_zero_iff_eq, sub_neg_eq_add],
have H : ⁅x + y, x + y⁆ = 0, from lie_self _,
rw add_lie at H,
simpa using H,
end
@[simp] lemma lie_zero (x : L) :
⁅x, 0⁆ = 0 :=
begin
have H : ⁅x, 0⁆ + ⁅x, 0⁆ = ⁅x, 0⁆ + 0 := by { rw ←lie_add, simp, },
exact add_left_cancel H,
end
@[simp] lemma zero_lie (x : L) :
⁅0, x⁆ = 0 := by { rw [←lie_skew, lie_zero], simp, }
@[simp] lemma neg_lie (x y : L) :
⁅-x, y⁆ = -⁅x, y⁆ := by { rw [←sub_eq_zero_iff_eq, sub_neg_eq_add, ←add_lie], simp, }
@[simp] lemma lie_neg (x y : L) :
⁅x, -y⁆ = -⁅x, y⁆ := by { rw [←lie_skew, ←lie_skew], simp, }
@[simp] lemma gsmul_lie (x y : L) (n : ℤ) :
⁅n • x, y⁆ = n • ⁅x, y⁆ :=
add_monoid_hom.map_gsmul ⟨λ x, ⁅x, y⁆, zero_lie y, λ _ _, add_lie _ _ _⟩ _ _
@[simp] lemma lie_gsmul (x y : L) (n : ℤ) :
⁅x, n • y⁆ = n • ⁅x, y⁆ :=
begin
rw [←lie_skew, ←lie_skew x, gsmul_lie],
unfold has_scalar.smul, rw gsmul_neg,
end
/--
An associative ring gives rise to a Lie ring by taking the bracket to be the ring commutator.
-/
def lie_ring.of_associative_ring (A : Type v) [ring A] : lie_ring A :=
{ bracket := ring_commutator.commutator,
add_lie := ring_commutator.add_left,
lie_add := ring_commutator.add_right,
lie_self := ring_commutator.alternate,
jacobi := ring_commutator.jacobi }
local attribute [instance] lie_ring.of_associative_ring
lemma lie_ring.of_associative_ring_bracket (A : Type v) [ring A] (x y : A) :
⁅x, y⁆ = x*y - y*x := rfl
lemma commutative_ring_iff_abelian_lie_ring (A : Type v) [ring A] :
is_commutative A (*) ↔ lie_algebra.is_abelian A :=
begin
have h₁ : is_commutative A (*) ↔ ∀ (a b : A), a * b = b * a := ⟨λ h, h.1, λ h, ⟨h⟩⟩,
have h₂ : lie_algebra.is_abelian A ↔ ∀ (a b : A), ⁅a, b⁆ = 0 := ⟨λ h, h.1, λ h, ⟨h⟩⟩,
simp only [h₁, h₂, lie_ring.of_associative_ring_bracket, sub_eq_zero],
end
end lie_ring
section prio
set_option default_priority 100 -- see Note [default priority]
/--
A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi
identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring.
-/
class lie_algebra (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] extends semimodule R L :=
(lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆)
end prio
@[simp] lemma lie_smul (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L]
(t : R) (x y : L) : ⁅x, t • y⁆ = t • ⁅x, y⁆ :=
lie_algebra.lie_smul t x y
@[simp] lemma smul_lie (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L]
(t : R) (x y : L) : ⁅t • x, y⁆ = t • ⁅x, y⁆ :=
by { rw [←lie_skew, ←lie_skew x y], simp [-lie_skew], }
namespace lie_algebra
set_option old_structure_cmd true
/-- A morphism of Lie algebras is a linear map respecting the bracket operations. -/
structure morphism (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends linear_map R L L' :=
(map_lie : ∀ {x y : L}, to_fun ⁅x, y⁆ = ⁅to_fun x, to_fun y⁆)
attribute [nolint doc_blame] lie_algebra.morphism.to_linear_map
infixr ` →ₗ⁅⁆ `:25 := morphism _
notation L ` →ₗ⁅`:25 R:25 `⁆ `:0 L':0 := morphism R L L'
section morphism_properties
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_ring L₃]
variables [lie_algebra R L₁] [lie_algebra R L₂] [lie_algebra R L₃]
instance : has_coe (L₁ →ₗ⁅R⁆ L₂) (L₁ →ₗ[R] L₂) := ⟨morphism.to_linear_map⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ →ₗ⁅R⁆ L₂) := ⟨_, morphism.to_fun⟩
@[simp] lemma map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := morphism.map_lie f
/-- The constant 0 map is a Lie algebra morphism. -/
instance : has_zero (L₁ →ₗ⁅R⁆ L₂) := ⟨{ map_lie := by simp, ..(0 : L₁ →ₗ[R] L₂)}⟩
/-- The identity map is a Lie algebra morphism. -/
instance : has_one (L₁ →ₗ⁅R⁆ L₁) := ⟨{ map_lie := by simp, ..(1 : L₁ →ₗ[R] L₁)}⟩
instance : inhabited (L₁ →ₗ⁅R⁆ L₂) := ⟨0⟩
/-- The composition of morphisms is a morphism. -/
def morphism.comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ⁅R⁆ L₃ :=
{ map_lie := λ x y, by { change f (g ⁅x, y⁆) = ⁅f (g x), f (g y)⁆, rw [map_lie, map_lie], },
..linear_map.comp f.to_linear_map g.to_linear_map }
lemma morphism.comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) :
f.comp g x = f (g x) := rfl
/-- The inverse of a bijective morphism is a morphism. -/
def morphism.inverse (f : L₁ →ₗ⁅R⁆ L₂) (g : L₂ → L₁)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : L₂ →ₗ⁅R⁆ L₁ :=
{ map_lie := λ x y, by {
calc g ⁅x, y⁆ = g ⁅f (g x), f (g y)⁆ : by { conv_lhs { rw [←h₂ x, ←h₂ y], }, }
... = g (f ⁅g x, g y⁆) : by rw map_lie
... = ⁅g x, g y⁆ : (h₁ _), },
..linear_map.inverse f.to_linear_map g h₁ h₂ }
end morphism_properties
/-- An equivalence of Lie algebras is a morphism which is also a linear equivalence. We could
instead define an equivalence to be a morphism which is also a (plain) equivalence. However it is
more convenient to define via linear equivalence to get `.to_linear_equiv` for free. -/
structure equiv (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends L →ₗ⁅R⁆ L', L ≃ₗ[R] L'
attribute [nolint doc_blame] lie_algebra.equiv.to_morphism
attribute [nolint doc_blame] lie_algebra.equiv.to_linear_equiv
notation L ` ≃ₗ⁅`:50 R `⁆ ` L' := equiv R L L'
namespace equiv
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_ring L₃]
variables [lie_algebra R L₁] [lie_algebra R L₂] [lie_algebra R L₃]
instance has_coe_to_lie_hom : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ →ₗ⁅R⁆ L₂) := ⟨to_morphism⟩
instance has_coe_to_linear_equiv : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ ≃ₗ[R] L₂) := ⟨to_linear_equiv⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ ≃ₗ⁅R⁆ L₂) := ⟨_, to_fun⟩
@[simp, norm_cast] lemma coe_to_lie_equiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = e :=
rfl
@[simp, norm_cast] lemma coe_to_linear_equiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ((e : L₁ ≃ₗ[R] L₂) : L₁ → L₂) = e :=
rfl
instance : has_one (L₁ ≃ₗ⁅R⁆ L₁) :=
⟨{ map_lie := λ x y, by { change ((1 : L₁→ₗ[R] L₁) ⁅x, y⁆) = ⁅(1 : L₁→ₗ[R] L₁) x, (1 : L₁→ₗ[R] L₁) y⁆, simp, },
..(1 : L₁ ≃ₗ[R] L₁)}⟩
@[simp] lemma one_apply (x : L₁) : (1 : (L₁ ≃ₗ⁅R⁆ L₁)) x = x := rfl
instance : inhabited (L₁ ≃ₗ⁅R⁆ L₁) := ⟨1⟩
/-- Lie algebra equivalences are reflexive. -/
@[refl]
def refl : L₁ ≃ₗ⁅R⁆ L₁ := 1
@[simp] lemma refl_apply (x : L₁) : (refl : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl
/-- Lie algebra equivalences are symmetric. -/
@[symm]
def symm (e : L₁ ≃ₗ⁅R⁆ L₂) : L₂ ≃ₗ⁅R⁆ L₁ :=
{ ..morphism.inverse e.to_morphism e.inv_fun e.left_inv e.right_inv,
..e.to_linear_equiv.symm }
@[simp] lemma symm_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.symm = e :=
by { cases e, refl, }
@[simp] lemma apply_symm_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e (e.symm x) = x :=
e.to_linear_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e.symm (e x) = x :=
e.to_linear_equiv.symm_apply_apply
/-- Lie algebra equivalences are transitive. -/
@[trans]
def trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) : L₁ ≃ₗ⁅R⁆ L₃ :=
{ ..morphism.comp e₂.to_morphism e₁.to_morphism,
..linear_equiv.trans e₁.to_linear_equiv e₂.to_linear_equiv }
@[simp] lemma trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₁) :
(e₁.trans e₂) x = e₂ (e₁ x) := rfl
@[simp] lemma symm_trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₃) :
(e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl
end equiv
namespace direct_sum
open dfinsupp
variables {R : Type u} [comm_ring R]
variables {ι : Type v} [decidable_eq ι] {L : ι → Type w}
variables [Π i, lie_ring (L i)] [Π i, lie_algebra R (L i)]
/-- The direct sum of Lie rings carries a natural Lie ring structure. -/
instance : lie_ring (direct_sum ι L) := {
bracket := zip_with (λ i, λ x y, ⁅x, y⁆) (λ i, lie_zero 0),
add_lie := λ x y z, by { ext, simp only [zip_with_apply, add_apply, add_lie], },
lie_add := λ x y z, by { ext, simp only [zip_with_apply, add_apply, lie_add], },
lie_self := λ x, by { ext, simp only [zip_with_apply, add_apply, lie_self, zero_apply], },
jacobi := λ x y z, by { ext, simp only [zip_with_apply, add_apply, lie_ring.jacobi, zero_apply], },
..(infer_instance : add_comm_group _) }
@[simp] lemma bracket_apply {x y : direct_sum ι L} {i : ι} :
⁅x, y⁆ i = ⁅x i, y i⁆ := zip_with_apply
/-- The direct sum of Lie algebras carries a natural Lie algebra structure. -/
instance : lie_algebra R (direct_sum ι L) :=
{ lie_smul := λ c x y, by { ext, simp only [zip_with_apply, smul_apply, bracket_apply, lie_smul], },
..(infer_instance : module R _) }
end direct_sum
variables {R : Type u} {L : Type v} [comm_ring R] [lie_ring L] [lie_algebra R L]
/--
An associative algebra gives rise to a Lie algebra by taking the bracket to be the ring commutator.
-/
def of_associative_algebra (A : Type v) [ring A] [algebra R A] :
@lie_algebra R A _ (lie_ring.of_associative_ring _) :=
{ lie_smul := λ t x y,
by rw [lie_ring.of_associative_ring_bracket, lie_ring.of_associative_ring_bracket,
algebra.mul_smul_comm, algebra.smul_mul_assoc, smul_sub], }
instance (M : Type v) [add_comm_group M] [module R M] : lie_ring (module.End R M) :=
lie_ring.of_associative_ring _
local attribute [instance] lie_ring.of_associative_ring
local attribute [instance] lie_algebra.of_associative_algebra
/-- The map `of_associative_algebra` associating a Lie algebra to an associative algebra is
functorial. -/
def of_associative_algebra_hom {R : Type u} {A : Type v} {B : Type w}
[comm_ring R] [ring A] [ring B] [algebra R A] [algebra R B] (f : A →ₐ[R] B) : A →ₗ⁅R⁆ B :=
{ map_lie := λ x y, show f ⁅x,y⁆ = ⁅f x,f y⁆,
by simp only [lie_ring.of_associative_ring_bracket, alg_hom.map_sub, alg_hom.map_mul],
..f.to_linear_map, }
@[simp] lemma of_associative_algebra_hom_id {R : Type u} {A : Type v} [comm_ring R] [ring A] [algebra R A] :
of_associative_algebra_hom (alg_hom.id R A) = 1 := rfl
@[simp] lemma of_associative_algebra_hom_comp {R : Type u} {A : Type v} {B : Type w} {C : Type w₁}
[comm_ring R] [ring A] [ring B] [ring C] [algebra R A] [algebra R B] [algebra R C]
(f : A →ₐ[R] B) (g : B →ₐ[R] C) :
of_associative_algebra_hom (g.comp f) = (of_associative_algebra_hom g).comp (of_associative_algebra_hom f) := rfl
/--
An important class of Lie algebras are those arising from the associative algebra structure on
module endomorphisms.
-/
instance of_endomorphism_algebra (M : Type v) [add_comm_group M] [module R M] :
lie_algebra R (module.End R M) :=
of_associative_algebra (module.End R M)
lemma endo_algebra_bracket (M : Type v) [add_comm_group M] [module R M] (f g : module.End R M) :
⁅f, g⁆ = f.comp g - g.comp f := rfl
/--
The adjoint action of a Lie algebra on itself.
-/
def Ad : L →ₗ⁅R⁆ module.End R L :=
{ to_fun := λ x,
{ to_fun := has_bracket.bracket x,
map_add' := by { intros, apply lie_add, },
map_smul' := by { intros, apply lie_smul, } },
map_add' := by { intros, ext, simp, },
map_smul' := by { intros, ext, simp, },
map_lie := by {
intros x y, ext z,
rw endo_algebra_bracket,
suffices : ⁅⁅x, y⁆, z⁆ = ⁅x, ⁅y, z⁆⁆ + ⁅⁅x, z⁆, y⁆, by simpa [sub_eq_add_neg],
rw [eq_comm, ←lie_skew ⁅x, y⁆ z, ←lie_skew ⁅x, z⁆ y, ←lie_skew x z, lie_neg, neg_neg,
←sub_eq_zero_iff_eq, sub_neg_eq_add, lie_ring.jacobi], } }
end lie_algebra
section lie_subalgebra
variables (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L]
set_option old_structure_cmd true
/--
A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie algebra.
-/
structure lie_subalgebra extends submodule R L :=
(lie_mem : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier)
attribute [nolint doc_blame] lie_subalgebra.to_submodule
/-- The zero algebra is a subalgebra of any Lie algebra. -/
instance : has_zero (lie_subalgebra R L) :=
⟨{ lie_mem := λ x y hx hy, by { rw [((submodule.mem_bot R).1 hx), zero_lie],
exact submodule.zero_mem (0 : submodule R L), },
..(0 : submodule R L) }⟩
instance : inhabited (lie_subalgebra R L) := ⟨0⟩
instance : has_coe (lie_subalgebra R L) (set L) := ⟨lie_subalgebra.carrier⟩
instance : has_mem L (lie_subalgebra R L) := ⟨λ x L', x ∈ (L' : set L)⟩
instance lie_subalgebra_coe_submodule : has_coe (lie_subalgebra R L) (submodule R L) :=
⟨lie_subalgebra.to_submodule⟩
/-- A Lie subalgebra forms a new Lie ring. -/
instance lie_subalgebra_lie_ring (L' : lie_subalgebra R L) : lie_ring L' := {
bracket := λ x y, ⟨⁅x.val, y.val⁆, L'.lie_mem x.property y.property⟩,
lie_add := by { intros, apply set_coe.ext, apply lie_add, },
add_lie := by { intros, apply set_coe.ext, apply add_lie, },
lie_self := by { intros, apply set_coe.ext, apply lie_self, },
jacobi := by { intros, apply set_coe.ext, apply lie_ring.jacobi, } }
/-- A Lie subalgebra forms a new Lie algebra. -/
instance lie_subalgebra_lie_algebra (L' : lie_subalgebra R L) :
@lie_algebra R L' _ (lie_subalgebra_lie_ring _ _ _) :=
{ lie_smul := by { intros, apply set_coe.ext, apply lie_smul } }
@[simp] lemma lie_subalgebra.mem_coe {L' : lie_subalgebra R L} {x : L} :
x ∈ (L' : set L) ↔ x ∈ L' := iff.rfl
@[simp] lemma lie_subalgebra.mem_coe' {L' : lie_subalgebra R L} {x : L} :
x ∈ (L' : submodule R L) ↔ x ∈ L' := iff.rfl
@[simp, norm_cast] lemma lie_subalgebra.coe_bracket (L' : lie_subalgebra R L) (x y : L') :
(↑⁅x, y⁆ : L) = ⁅↑x, ↑y⁆ := rfl
@[ext] lemma lie_subalgebra.ext (L₁' L₂' : lie_subalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') :
L₁' = L₂' :=
by { cases L₁', cases L₂', simp only [], ext x, exact h x, }
lemma lie_subalgebra.ext_iff (L₁' L₂' : lie_subalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' :=
⟨λ h x, by rw h, lie_subalgebra.ext R L L₁' L₂'⟩
local attribute [instance] lie_ring.of_associative_ring
local attribute [instance] lie_algebra.of_associative_algebra
/-- A subalgebra of an associative algebra is a Lie subalgebra of the associated Lie algebra. -/
def lie_subalgebra_of_subalgebra (A : Type v) [ring A] [algebra R A]
(A' : subalgebra R A) : lie_subalgebra R A :=
{ lie_mem := λ x y hx hy, by {
change ⁅x, y⁆ ∈ A', change x ∈ A' at hx, change y ∈ A' at hy,
rw lie_ring.of_associative_ring_bracket,
have hxy := subalgebra.mul_mem A' x y hx hy,
have hyx := subalgebra.mul_mem A' y x hy hx,
exact submodule.sub_mem A'.to_submodule hxy hyx, },
..A'.to_submodule }
variables {R L} {L₂ : Type w} [lie_ring L₂] [lie_algebra R L₂]
/-- The embedding of a Lie subalgebra into the ambient space as a Lie morphism. -/
def lie_subalgebra.incl (L' : lie_subalgebra R L) : L' →ₗ⁅R⁆ L :=
{ map_lie := λ x y, by { rw [linear_map.to_fun_eq_coe, submodule.subtype_apply], refl, },
..L'.to_submodule.subtype }
/-- The range of a morphism of Lie algebras is a Lie subalgebra. -/
def lie_algebra.morphism.range (f : L →ₗ⁅R⁆ L₂) : lie_subalgebra R L₂ :=
{ lie_mem := λ x y,
show x ∈ f.to_linear_map.range → y ∈ f.to_linear_map.range → ⁅x, y⁆ ∈ f.to_linear_map.range,
by { repeat { rw linear_map.mem_range }, rintros ⟨x', hx⟩ ⟨y', hy⟩, refine ⟨⁅x', y'⁆, _⟩,
rw [←hx, ←hy], change f ⁅x', y'⁆ = ⁅f x', f y'⁆, rw lie_algebra.map_lie, },
..f.to_linear_map.range }
@[simp] lemma lie_algebra.morphism.range_bracket (f : L →ₗ⁅R⁆ L₂) (x y : f.range) :
(↑⁅x, y⁆ : L₂) = ⁅↑x, ↑y⁆ := rfl
/-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the
codomain. -/
def lie_subalgebra.map (f : L →ₗ⁅R⁆ L₂) (L' : lie_subalgebra R L) : lie_subalgebra R L₂ :=
{ lie_mem := λ x y hx hy, by {
erw submodule.mem_map at hx, rcases hx with ⟨x', hx', hx⟩, rw ←hx,
erw submodule.mem_map at hy, rcases hy with ⟨y', hy', hy⟩, rw ←hy,
erw submodule.mem_map,
exact ⟨⁅x', y'⁆, L'.lie_mem hx' hy', lie_algebra.map_lie f x' y'⟩, },
..((L' : submodule R L).map (f : L →ₗ[R] L₂))}
@[simp] lemma lie_subalgebra.mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (L' : lie_subalgebra R L) (x : L₂) :
x ∈ L'.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (L' : submodule R L).map (e : L →ₗ[R] L₂) :=
by refl
end lie_subalgebra
namespace lie_algebra
variables {R : Type u} {L₁ : Type v} {L₂ : Type w}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_algebra R L₁] [lie_algebra R L₂]
namespace equiv
/-- An injective Lie algebra morphism is an equivalence onto its range. -/
noncomputable def of_injective (f : L₁ →ₗ⁅R⁆ L₂) (h : function.injective f) :
L₁ ≃ₗ⁅R⁆ f.range :=
have h' : (f : L₁ →ₗ[R] L₂).ker = ⊥ := linear_map.ker_eq_bot_of_injective h,
{ map_lie := λ x y, by { apply set_coe.ext,
simp only [linear_equiv.of_injective_apply, lie_algebra.morphism.range_bracket],
apply f.map_lie, },
..(linear_equiv.of_injective ↑f h')}
@[simp] lemma of_injective_apply (f : L₁ →ₗ⁅R⁆ L₂) (h : function.injective f) (x : L₁) :
↑(of_injective f h x) = f x := rfl
variables (L₁' L₁'' : lie_subalgebra R L₁) (L₂' : lie_subalgebra R L₂)
/-- Lie subalgebras that are equal as sets are equivalent as Lie algebras. -/
def of_eq (h : (L₁' : set L₁) = L₁'') : L₁' ≃ₗ⁅R⁆ L₁'' :=
{ map_lie := λ x y, by { apply set_coe.ext, simp, },
..(linear_equiv.of_eq ↑L₁' ↑L₁''
(by {ext x, change x ∈ (L₁' : set L₁) ↔ x ∈ (L₁'' : set L₁), rw h, } )) }
@[simp] lemma of_eq_apply (L L' : lie_subalgebra R L₁) (h : (L : set L₁) = L') (x : L) :
(↑(of_eq L L' h x) : L₁) = x := rfl
variables (e : L₁ ≃ₗ⁅R⁆ L₂)
/-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its
image. -/
def of_subalgebra : L₁'' ≃ₗ⁅R⁆ (L₁''.map e : lie_subalgebra R L₂) :=
{ map_lie := λ x y, by { apply set_coe.ext, exact lie_algebra.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y, }
..(linear_equiv.of_submodule (e : L₁ ≃ₗ[R] L₂) ↑L₁'') }
@[simp] lemma of_subalgebra_apply (x : L₁'') : ↑(e.of_subalgebra _ x) = e x := rfl
/-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its
image. -/
def of_subalgebras (h : L₁'.map ↑e = L₂') : L₁' ≃ₗ⁅R⁆ L₂' :=
{ map_lie := λ x y, by { apply set_coe.ext, exact lie_algebra.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y, },
..(linear_equiv.of_submodules (e : L₁ ≃ₗ[R] L₂) ↑L₁' ↑L₂' (by { rw ←h, refl, })) }
@[simp] lemma of_subalgebras_apply (h : L₁'.map ↑e = L₂') (x : L₁') :
↑(e.of_subalgebras _ _ h x) = e x := rfl
@[simp] lemma of_subalgebras_symm_apply (h : L₁'.map ↑e = L₂') (x : L₂') :
↑((e.of_subalgebras _ _ h).symm x) = e.symm x := rfl
end equiv
end lie_algebra
section lie_module
variables (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L]
variables (M : Type v) [add_comm_group M] [module R M]
section prio
set_option default_priority 100 -- see Note [default priority]
/--
A Lie module is a module over a commutative ring, together with a linear action of a Lie algebra
on this module, such that the Lie bracket acts as the commutator of endomorphisms.
-/
class lie_module extends linear_action R L M :=
(lie_act : ∀ (l l' : L) (m : M), act ⁅l, l'⁆ m = act l (act l' m) - act l' (act l m))
end prio
@[simp] lemma lie_act [lie_module R L M]
(l l' : L) (m : M) : linear_action.act R ⁅l, l'⁆ m =
linear_action.act R l (linear_action.act R l' m) -
linear_action.act R l' (linear_action.act R l m) :=
lie_module.lie_act l l' m
protected lemma of_endo_map_action (α : L →ₗ⁅R⁆ module.End R M) (x : L) (m : M) :
@linear_action.act R _ _ _ _ _ _ _ (linear_action.of_endo_map R L M α) x m = α x m := rfl
/--
A Lie morphism from a Lie algebra to the endomorphism algebra of a module yields
a Lie module structure.
-/
def lie_module.of_endo_morphism (α : L →ₗ⁅R⁆ module.End R M) : lie_module R L M := {
lie_act := by { intros x y m, rw [of_endo_map_action, lie_algebra.map_lie,
lie_algebra.endo_algebra_bracket], refl, },
..(linear_action.of_endo_map R L M α) }
/--
Every Lie algebra is a module over itself.
-/
instance lie_algebra_self_module : lie_module R L L :=
lie_module.of_endo_morphism R L L lie_algebra.Ad
/--
A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie module.
-/
structure lie_submodule [lie_module R L M] extends submodule R M :=
(lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → linear_action.act R x m ∈ carrier)
/-- The zero module is a Lie submodule of any Lie module. -/
instance [lie_module R L M] : has_zero (lie_submodule R L M) :=
⟨{ lie_mem := λ x m h, by { rw [((submodule.mem_bot R).1 h), linear_action_zero],
exact submodule.zero_mem (0 : submodule R M), },
..(0 : submodule R M)}⟩
instance [lie_module R L M] : inhabited (lie_submodule R L M) := ⟨0⟩
instance lie_submodule_coe_submodule [lie_module R L M] :
has_coe (lie_submodule R L M) (submodule R M) := ⟨lie_submodule.to_submodule⟩
instance lie_submodule_has_mem [lie_module R L M] :
has_mem M (lie_submodule R L M) := ⟨λ x N, x ∈ (N : set M)⟩
instance lie_submodule_lie_module [lie_module R L M] (N : lie_submodule R L M) :
lie_module R L N := {
act := λ x m, ⟨linear_action.act R x m.val, N.lie_mem m.property⟩,
add_act := by { intros x y m, apply set_coe.ext, apply linear_action.add_act, },
act_add := by { intros x m n, apply set_coe.ext, apply linear_action.act_add, },
act_smul := by { intros r x y, apply set_coe.ext, apply linear_action.act_smul, },
smul_act := by { intros r x y, apply set_coe.ext, apply linear_action.smul_act, },
lie_act := by { intros x y m, apply set_coe.ext, apply lie_module.lie_act, } }
/--
An ideal of a Lie algebra is a Lie submodule of the Lie algebra as a Lie module over itself.
-/
abbreviation lie_ideal := lie_submodule R L L
lemma lie_mem_right (I : lie_ideal R L) (x y : L) (h : y ∈ I) : ⁅x, y⁆ ∈ I := I.lie_mem h
lemma lie_mem_left (I : lie_ideal R L) (x y : L) (h : x ∈ I) : ⁅x, y⁆ ∈ I := by {
rw [←lie_skew, ←neg_lie], apply lie_mem_right, assumption, }
/--
An ideal of a Lie algebra is a Lie subalgebra.
-/
def lie_ideal_subalgebra (I : lie_ideal R L) : lie_subalgebra R L := {
lie_mem := by { intros x y hx hy, apply lie_mem_right, exact hy, },
..I.to_submodule, }
/-- A Lie module is irreducible if its only non-trivial Lie submodule is itself. -/
class lie_module.is_irreducible [lie_module R L M] : Prop :=
(irreducible : ∀ (M' : lie_submodule R L M), (∃ (m : M'), m ≠ 0) → (∀ (m : M), m ∈ M'))
/-- A Lie algebra is simple if it is irreducible as a Lie module over itself via the adjoint
action, and it is non-Abelian. -/
class lie_algebra.is_simple : Prop :=
(simple : lie_module.is_irreducible R L L ∧ ¬lie_algebra.is_abelian L)
end lie_module
namespace lie_submodule
variables {R : Type u} {L : Type v} [comm_ring R] [lie_ring L] [lie_algebra R L]
variables {M : Type v} [add_comm_group M] [module R M] [α : lie_module R L M]
variables (N : lie_submodule R L M) (I : lie_ideal R L)
/--
The quotient of a Lie module by a Lie submodule. It is a Lie module.
-/
abbreviation quotient := N.to_submodule.quotient
namespace quotient
variables {N I}
/--
Map sending an element of `M` to the corresponding element of `M/N`, when `N` is a lie_submodule of
the lie_module `N`.
-/
abbreviation mk : M → N.quotient := submodule.quotient.mk
lemma is_quotient_mk (m : M) :
quotient.mk' m = (mk m : N.quotient) := rfl
/-- Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M`, there
is a natural linear map from `L` to the endomorphisms of `M` leaving `N` invariant. -/
def lie_submodule_invariant : L →ₗ[R] submodule.compatible_maps N.to_submodule N.to_submodule :=
linear_map.cod_restrict _ (α.to_linear_action.to_endo_map _ _ _) N.lie_mem
instance lie_quotient_action : linear_action R L N.quotient :=
linear_action.of_endo_map _ _ _ (linear_map.comp (submodule.mapq_linear N N) lie_submodule_invariant)
lemma lie_quotient_action_apply (z : L) (m : M) :
linear_action.act R z (mk m : N.quotient) = mk (linear_action.act R z m) := rfl
/-- The quotient of a Lie module by a Lie submodule, is a Lie module. -/
instance lie_quotient_lie_module : lie_module R L N.quotient :=
{ lie_act := λ x y m', by { apply quotient.induction_on' m', intros m, rw is_quotient_mk,
repeat { rw lie_quotient_action_apply, }, rw lie_act, refl, },
..quotient.lie_quotient_action, }
instance lie_quotient_has_bracket : has_bracket (quotient I) := ⟨by {
intros x y,
apply quotient.lift_on₂' x y (λ x' y', mk ⁅x', y'⁆),
intros x₁ x₂ y₁ y₂ h₁ h₂,
apply (submodule.quotient.eq I.to_submodule).2,
have h : ⁅x₁, x₂⁆ - ⁅y₁, y₂⁆ = ⁅x₁, x₂ - y₂⁆ + ⁅x₁ - y₁, y₂⁆ := by simp [-lie_skew, sub_eq_add_neg, add_assoc],
rw h,
apply submodule.add_mem,
{ apply lie_mem_right R L I x₁ (x₂ - y₂) h₂, },
{ apply lie_mem_left R L I (x₁ - y₁) y₂ h₁, }, }⟩
@[simp] lemma mk_bracket (x y : L) :
(mk ⁅x, y⁆ : quotient I) = ⁅mk x, mk y⁆ := rfl
instance lie_quotient_lie_ring : lie_ring (quotient I) := {
add_lie := by { intros x' y' z', apply quotient.induction_on₃' x' y' z', intros x y z,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_add, },
apply congr_arg, apply add_lie, },
lie_add := by { intros x' y' z', apply quotient.induction_on₃' x' y' z', intros x y z,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_add, },
apply congr_arg, apply lie_add, },
lie_self := by { intros x', apply quotient.induction_on' x', intros x,
rw [is_quotient_mk, ←mk_bracket],
apply congr_arg, apply lie_self, },
jacobi := by { intros x' y' z', apply quotient.induction_on₃' x' y' z', intros x y z,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_add, },
apply congr_arg, apply lie_ring.jacobi, } }
instance lie_quotient_lie_algebra : lie_algebra R (quotient I) := {
lie_smul := by { intros t x' y', apply quotient.induction_on₂' x' y', intros x y,
repeat { rw is_quotient_mk <|>
rw ←mk_bracket <|>
rw ←submodule.quotient.mk_smul, },
apply congr_arg, apply lie_smul, } }
end quotient
end lie_submodule
namespace linear_equiv
variables {R : Type u} {M₁ : Type v} {M₂ : Type w}
variables [comm_ring R] [add_comm_group M₁] [module R M₁] [add_comm_group M₂] [module R M₂]
variables (e : M₁ ≃ₗ[R] M₂)
/-- A linear equivalence of two modules induces a Lie algebra equivalence of their endomorphisms. -/
def lie_conj : module.End R M₁ ≃ₗ⁅R⁆ module.End R M₂ :=
{ map_lie := λ f g, show e.conj ⁅f, g⁆ = ⁅e.conj f, e.conj g⁆,
by simp only [lie_algebra.endo_algebra_bracket, e.conj_comp, linear_equiv.map_sub],
..e.conj }
@[simp] lemma lie_conj_apply (f : module.End R M₁) : e.lie_conj f = e.conj f := rfl
@[simp] lemma lie_conj_symm : e.lie_conj.symm = e.symm.lie_conj := rfl
end linear_equiv
section matrices
open_locale matrix
variables {R : Type u} [comm_ring R]
variables {n : Type w} [fintype n] [decidable_eq n]
/-- An important class of Lie rings are those arising from the associative algebra structure on
square matrices over a commutative ring. -/
def matrix.lie_ring : lie_ring (matrix n n R) :=
lie_ring.of_associative_ring (matrix n n R)
local attribute [instance] matrix.lie_ring
/-- An important class of Lie algebras are those arising from the associative algebra structure on
square matrices over a commutative ring. -/
def matrix.lie_algebra : lie_algebra R (matrix n n R) :=
lie_algebra.of_associative_algebra (matrix n n R)
local attribute [instance] matrix.lie_algebra
/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices
is compatible with the Lie algebra structures. -/
def lie_equiv_matrix' : module.End R (n → R) ≃ₗ⁅R⁆ matrix n n R :=
{ map_lie := λ T S,
begin
let f := @linear_map.to_matrixₗ n n _ _ R _ _,
change f (T.comp S - S.comp T) = (f T) * (f S) - (f S) * (f T),
have h : ∀ (T S : module.End R _), f (T.comp S) = (f T) ⬝ (f S) := matrix.comp_to_matrix_mul,
rw [linear_map.map_sub, h, h, matrix.mul_eq_mul, matrix.mul_eq_mul],
end,
..linear_equiv_matrix' }
@[simp] lemma lie_equiv_matrix'_apply (f : module.End R (n → R)) :
lie_equiv_matrix' f = f.to_matrix := rfl
@[simp] lemma lie_equiv_matrix'_symm_apply (A : matrix n n R) :
(@lie_equiv_matrix' R _ n _ _).symm A = A.to_lin := rfl
/-- An invertible matrix induces a Lie algebra equivalence from the space of matrices to itself. -/
noncomputable def matrix.lie_conj (P : matrix n n R) (h : is_unit P) :
matrix n n R ≃ₗ⁅R⁆ matrix n n R :=
((@lie_equiv_matrix' R _ n _ _).symm.trans (P.to_linear_equiv h).lie_conj).trans lie_equiv_matrix'
@[simp] lemma matrix.lie_conj_apply (P A : matrix n n R) (h : is_unit P) :
P.lie_conj h A = P ⬝ A ⬝ P⁻¹ :=
by simp [linear_equiv.conj_apply, matrix.lie_conj, matrix.comp_to_matrix_mul, to_lin_to_matrix]
@[simp] lemma matrix.lie_conj_symm_apply (P A : matrix n n R) (h : is_unit P) :
(P.lie_conj h).symm A = P⁻¹ ⬝ A ⬝ P :=
by simp [linear_equiv.symm_conj_apply, matrix.lie_conj, matrix.comp_to_matrix_mul, to_lin_to_matrix]
end matrices
section skew_adjoint_endomorphisms
open bilin_form
variables {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M]
variables (B : bilin_form R M)
lemma bilin_form.is_skew_adjoint_bracket (f g : module.End R M)
(hf : f ∈ B.skew_adjoint_submodule) (hg : g ∈ B.skew_adjoint_submodule) :
⁅f, g⁆ ∈ B.skew_adjoint_submodule :=
begin
rw mem_skew_adjoint_submodule at *,
have hfg : is_adjoint_pair B B (f * g) (g * f), { rw ←neg_mul_neg g f, exact hf.mul hg, },
have hgf : is_adjoint_pair B B (g * f) (f * g), { rw ←neg_mul_neg f g, exact hg.mul hf, },
change bilin_form.is_adjoint_pair B B (f * g - g * f) (-(f * g - g * f)), rw neg_sub,
exact hfg.sub hgf,
end
/-- Given an `R`-module `M`, equipped with a bilinear form, the skew-adjoint endomorphisms form a
Lie subalgebra of the Lie algebra of endomorphisms. -/
def skew_adjoint_lie_subalgebra : lie_subalgebra R (module.End R M) :=
{ lie_mem := B.is_skew_adjoint_bracket, ..B.skew_adjoint_submodule }
variables {N : Type w} [add_comm_group N] [module R N] (e : N ≃ₗ[R] M)
/-- An equivalence of modules with bilinear forms gives equivalence of Lie algebras of skew-adjoint
endomorphisms. -/
def skew_adjoint_lie_subalgebra_equiv :
skew_adjoint_lie_subalgebra (B.comp (↑e : N →ₗ[R] M) ↑e) ≃ₗ⁅R⁆ skew_adjoint_lie_subalgebra B :=
begin
apply lie_algebra.equiv.of_subalgebras _ _ e.lie_conj,
ext f,
simp only [lie_subalgebra.mem_coe, submodule.mem_map_equiv, lie_subalgebra.mem_map_submodule,
coe_coe],
exact (bilin_form.is_pair_self_adjoint_equiv (-B) B e f).symm,
end
@[simp] lemma skew_adjoint_lie_subalgebra_equiv_apply
(f : skew_adjoint_lie_subalgebra (B.comp ↑e ↑e)) :
↑(skew_adjoint_lie_subalgebra_equiv B e f) = e.lie_conj f :=
by simp [skew_adjoint_lie_subalgebra_equiv]
@[simp] lemma skew_adjoint_lie_subalgebra_equiv_symm_apply (f : skew_adjoint_lie_subalgebra B) :
↑((skew_adjoint_lie_subalgebra_equiv B e).symm f) = e.symm.lie_conj f :=
by simp [skew_adjoint_lie_subalgebra_equiv]
end skew_adjoint_endomorphisms
section skew_adjoint_matrices
open_locale matrix
variables {R : Type u} {n : Type w} [comm_ring R] [fintype n] [decidable_eq n]
variables (J : matrix n n R)
local attribute [instance] matrix.lie_ring
local attribute [instance] matrix.lie_algebra
lemma matrix.lie_transpose (A B : matrix n n R) : ⁅A, B⁆ᵀ = ⁅Bᵀ, Aᵀ⁆ :=
show (A * B - B * A)ᵀ = (Bᵀ * Aᵀ - Aᵀ * Bᵀ), by simp
lemma matrix.is_skew_adjoint_bracket (A B : matrix n n R)
(hA : A ∈ skew_adjoint_matrices_submodule J) (hB : B ∈ skew_adjoint_matrices_submodule J) :
⁅A, B⁆ ∈ skew_adjoint_matrices_submodule J :=
begin
simp only [mem_skew_adjoint_matrices_submodule] at *,
change ⁅A, B⁆ᵀ ⬝ J = J ⬝ -⁅A, B⁆, change Aᵀ ⬝ J = J ⬝ -A at hA, change Bᵀ ⬝ J = J ⬝ -B at hB,
simp only [←matrix.mul_eq_mul] at *,
rw [matrix.lie_transpose, lie_ring.of_associative_ring_bracket, lie_ring.of_associative_ring_bracket,
sub_mul, mul_assoc, mul_assoc, hA, hB, ←mul_assoc, ←mul_assoc, hA, hB],
noncomm_ring,
end
/-- The Lie subalgebra of skew-adjoint square matrices corresponding to a square matrix `J`. -/
def skew_adjoint_matrices_lie_subalgebra : lie_subalgebra R (matrix n n R) :=
{ lie_mem := J.is_skew_adjoint_bracket, ..(skew_adjoint_matrices_submodule J) }
/-- An invertible matrix `P` gives a Lie algebra equivalence between those endomorphisms that are
skew-adjoint with respect to a square matrix `J` and those with respect to `PᵀJP`. -/
noncomputable def skew_adjoint_matrices_lie_subalgebra_equiv (P : matrix n n R) (h : is_unit P) :
skew_adjoint_matrices_lie_subalgebra J ≃ₗ⁅R⁆ skew_adjoint_matrices_lie_subalgebra (Pᵀ ⬝ J ⬝ P) :=
lie_algebra.equiv.of_subalgebras _ _ (P.lie_conj h).symm
begin
ext A,
suffices : P.lie_conj h A ∈ skew_adjoint_matrices_submodule J ↔
A ∈ skew_adjoint_matrices_submodule (Pᵀ ⬝ J ⬝ P),
{ simp only [lie_subalgebra.mem_coe, submodule.mem_map_equiv, lie_subalgebra.mem_map_submodule,
coe_coe], exact this, },
simp [matrix.is_skew_adjoint, J.is_adjoint_pair_equiv _ _ P h],
end
lemma skew_adjoint_matrices_lie_subalgebra_equiv_apply
(P : matrix n n R) (h : is_unit P) (A : skew_adjoint_matrices_lie_subalgebra J) :
↑(skew_adjoint_matrices_lie_subalgebra_equiv J P h A) = P⁻¹ ⬝ ↑A ⬝ P :=
by simp [skew_adjoint_matrices_lie_subalgebra_equiv]
end skew_adjoint_matrices
|
240cb0313fcf4de62d2176510273fbc7a4363bcb | 1abd1ed12aa68b375cdef28959f39531c6e95b84 | /src/algebra/module/linear_map.lean | df0ccba031503fcc85aea95b47ea7788d4af2820 | [
"Apache-2.0"
] | permissive | jumpy4/mathlib | d3829e75173012833e9f15ac16e481e17596de0f | af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13 | refs/heads/master | 1,693,508,842,818 | 1,636,203,271,000 | 1,636,203,271,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,269 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne Baanen,
Frédéric Dupuis, Heather Macbeth
-/
import algebra.group.hom
import algebra.module.basic
import algebra.module.pi
import algebra.group_action_hom
import algebra.ring.comp_typeclasses
/-!
# (Semi)linear maps
In this file we define
* `linear_map σ M M₂`, `M →ₛₗ[σ] M₂` : a semilinear map between two `module`s. Here,
`σ` is a `ring_hom` from `R` to `R₂` and an `f : M →ₛₗ[σ] M₂` satisfies
`f (c • x) = (σ c) • (f x)`. We recover plain linear maps by choosing `σ` to be `ring_hom.id R`.
This is denoted by `M →ₗ[R] M₂`. We also add the notation `M →ₗ⋆[R] M₂` for star-linear maps.
* `is_linear_map R f` : predicate saying that `f : M → M₂` is a linear map. (Note that this
was not generalized to semilinear maps.)
We then provide `linear_map` with the following instances:
* `linear_map.add_comm_monoid` and `linear_map.add_comm_group`: the elementwise addition structures
corresponding to addition in the codomain
* `linear_map.distrib_mul_action` and `linear_map.module`: the elementwise scalar action structures
corresponding to applying the action in the codomain.
* `module.End.semiring` and `module.End.ring`: the (semi)ring of endomorphisms formed by taking the
additive structure above with composition as multiplication.
## Implementation notes
To ensure that composition works smoothly for semilinear maps, we use the typeclasses
`ring_hom_comp_triple`, `ring_hom_inv_pair` and `ring_hom_surjective` from
`algebra/ring/comp_typeclasses`.
## Notation
* Throughout the file, we denote regular linear maps by `fₗ`, `gₗ`, etc, and semilinear maps
by `f`, `g`, etc.
## TODO
* Parts of this file have not yet been generalized to semilinear maps (i.e. `compatible_smul`)
## Tags
linear map
-/
open function
open_locale big_operators
universes u u' v w x y z
variables {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*}
variables {k : Type*} {S : Type*} {T : Type*}
variables {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
variables {N₁ : Type*} {N₂ : Type*} {N₃ : Type*} {ι : Type*}
/-- A map `f` between modules over a semiring is linear if it satisfies the two properties
`f (x + y) = f x + f y` and `f (c • x) = c • f x`. The predicate `is_linear_map R f` asserts this
property. A bundled version is available with `linear_map`, and should be favored over
`is_linear_map` most of the time. -/
structure is_linear_map (R : Type u) {M : Type v} {M₂ : Type w}
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module R M₂]
(f : M → M₂) : Prop :=
(map_add : ∀ x y, f (x + y) = f x + f y)
(map_smul : ∀ (c : R) x, f (c • x) = c • f x)
section
set_option old_structure_cmd true
/-- A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S`
is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and
`f (c • x) = (σ c) • f x`. Elements of `linear_map σ M M₂` (available under the notation
`M →ₛₗ[σ] M₂`) are bundled versions of such maps. For plain linear maps (i.e. for which
`σ = ring_hom.id R`), the notation `M →ₗ[R] M₂` is available. An unbundled version of plain linear
maps is available with the predicate `is_linear_map`, but it should be avoided most of the time. -/
structure linear_map {R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
(M : Type*) (M₂ : Type*)
[add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module S M₂]
extends add_hom M M₂ :=
(map_smul' : ∀ (r : R) (x : M), to_fun (r • x) = (σ r) • to_fun x)
end
/-- The `add_hom` underlying a `linear_map`. -/
add_decl_doc linear_map.to_add_hom
notation M ` →ₛₗ[`:25 σ:25 `] `:0 M₂:0 := linear_map σ M M₂
notation M ` →ₗ[`:25 R:25 `] `:0 M₂:0 := linear_map (ring_hom.id R) M M₂
notation M ` →ₗ⋆[`:25 R:25 `] `:0 M₂:0 := linear_map (@star_ring_aut R _ _ : R →+* R) M M₂
namespace linear_map
section add_comm_monoid
variables [semiring R] [semiring S]
section
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [add_comm_monoid N₁] [add_comm_monoid N₂] [add_comm_monoid N₃]
variables [module R M] [module R M₂] [module S M₃]
/-- The `distrib_mul_action_hom` underlying a `linear_map`. -/
def to_distrib_mul_action_hom (f : M →ₗ[R] M₂) : distrib_mul_action_hom R M M₂ :=
{ map_zero' := zero_smul R (0 : M) ▸ zero_smul R (f.to_fun 0) ▸ f.map_smul' 0 0, ..f }
instance {σ : R →+* S} : has_coe_to_fun (M →ₛₗ[σ] M₃) (λ _, M → M₃) := ⟨linear_map.to_fun⟩
initialize_simps_projections linear_map (to_fun → apply)
@[simp] lemma coe_mk {σ : R →+* S} (f : M → M₃) (h₁ h₂) :
((linear_map.mk f h₁ h₂ : M →ₛₗ[σ] M₃) : M → M₃) = f := rfl
/-- Identity map as a `linear_map` -/
def id : M →ₗ[R] M :=
{ to_fun := id, ..distrib_mul_action_hom.id R }
lemma id_apply (x : M) :
@id R M _ _ _ x = x := rfl
@[simp, norm_cast] lemma id_coe : ((linear_map.id : M →ₗ[R] M) : M → M) = _root_.id :=
by { ext x, refl }
end
section
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [add_comm_monoid N₁] [add_comm_monoid N₂] [add_comm_monoid N₃]
variables [module R M] [module R M₂] [module S M₃]
variables (σ : R →+* S)
variables (fₗ gₗ : M →ₗ[R] M₂) (f g : M →ₛₗ[σ] M₃)
@[simp] lemma to_fun_eq_coe : f.to_fun = ⇑f := rfl
theorem is_linear : is_linear_map R fₗ := ⟨fₗ.map_add', fₗ.map_smul'⟩
variables {fₗ gₗ f g σ}
theorem coe_injective : @injective (M →ₛₗ[σ] M₃) (M → M₃) coe_fn :=
by rintro ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩; congr
@[ext] theorem ext (H : ∀ x, f x = g x) : f = g :=
coe_injective $ funext H
protected lemma congr_arg : Π {x x' : M}, x = x' → f x = f x'
| _ _ rfl := rfl
/-- If two linear maps are equal, they are equal at each point. -/
protected lemma congr_fun (h : f = g) (x : M) : f x = g x := h ▸ rfl
theorem ext_iff : f = g ↔ ∀ x, f x = g x :=
⟨by { rintro rfl x, refl }, ext⟩
@[simp] lemma mk_coe (f : M →ₛₗ[σ] M₃) (h₁ h₂) :
(linear_map.mk f h₁ h₂ : M →ₛₗ[σ] M₃) = f := ext $ λ _, rfl
variables (fₗ gₗ f g)
@[simp] lemma map_add (x y : M) : f (x + y) = f x + f y := f.map_add' x y
@[simp] lemma map_smulₛₗ (c : R) (x : M) : f (c • x) = (σ c) • f x := f.map_smul' c x
lemma map_smul (c : R) (x : M) : fₗ (c • x) = c • fₗ x := fₗ.map_smul' c x
lemma map_smul_inv {σ' : S →+* R} [ring_hom_inv_pair σ σ'] (c : S) (x : M) :
c • f x = f (σ' c • x) :=
by simp
@[simp] lemma map_zero : f 0 = 0 :=
by { rw [←zero_smul R (0 : M), map_smulₛₗ], simp }
@[simp] lemma map_eq_zero_iff (h : function.injective f) {x : M} : f x = 0 ↔ x = 0 :=
⟨λ w, by { apply h, simp [w], }, λ w, by { subst w, simp, }⟩
variables (M M₂)
/--
A typeclass for `has_scalar` structures which can be moved through a `linear_map`.
This typeclass is generated automatically from a `is_scalar_tower` instance, but exists so that
we can also add an instance for `add_comm_group.int_module`, allowing `z •` to be moved even if
`R` does not support negation.
-/
class compatible_smul (R S : Type*) [semiring S] [has_scalar R M]
[module S M] [has_scalar R M₂] [module S M₂] :=
(map_smul : ∀ (fₗ : M →ₗ[S] M₂) (c : R) (x : M), fₗ (c • x) = c • fₗ x)
variables {M M₂}
@[priority 100]
instance is_scalar_tower.compatible_smul
{R S : Type*} [semiring S] [has_scalar R S]
[has_scalar R M] [module S M] [is_scalar_tower R S M]
[has_scalar R M₂] [module S M₂] [is_scalar_tower R S M₂] : compatible_smul M M₂ R S :=
⟨λ fₗ c x, by rw [← smul_one_smul S c x, ← smul_one_smul S c (fₗ x), map_smul]⟩
@[simp, priority 900]
lemma map_smul_of_tower {R S : Type*} [semiring S] [has_scalar R M]
[module S M] [has_scalar R M₂] [module S M₂]
[compatible_smul M M₂ R S] (fₗ : M →ₗ[S] M₂) (c : R) (x : M) :
fₗ (c • x) = c • fₗ x :=
compatible_smul.map_smul fₗ c x
/-- convert a linear map to an additive map -/
def to_add_monoid_hom : M →+ M₃ :=
{ to_fun := f,
map_zero' := f.map_zero,
map_add' := f.map_add }
@[simp] lemma to_add_monoid_hom_coe : ⇑f.to_add_monoid_hom = f := rfl
section restrict_scalars
variables (R) [module S M] [module S M₂] [compatible_smul M M₂ R S]
/-- If `M` and `M₂` are both `R`-modules and `S`-modules and `R`-module structures
are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear
map from `M` to `M₂` is `R`-linear.
See also `linear_map.map_smul_of_tower`. -/
@[simps]
def restrict_scalars (fₗ : M →ₗ[S] M₂) : M →ₗ[R] M₂ :=
{ to_fun := fₗ,
map_add' := fₗ.map_add,
map_smul' := fₗ.map_smul_of_tower }
lemma restrict_scalars_injective :
function.injective (restrict_scalars R : (M →ₗ[S] M₂) → (M →ₗ[R] M₂)) :=
λ fₗ gₗ h, ext (linear_map.congr_fun h : _)
@[simp]
lemma restrict_scalars_inj (fₗ gₗ : M →ₗ[S] M₂) :
fₗ.restrict_scalars R = gₗ.restrict_scalars R ↔ fₗ = gₗ :=
(restrict_scalars_injective R).eq_iff
end restrict_scalars
variable {R}
@[simp] lemma map_sum {ι} {t : finset ι} {g : ι → M} :
f (∑ i in t, g i) = (∑ i in t, f (g i)) :=
f.to_add_monoid_hom.map_sum _ _
theorem to_add_monoid_hom_injective :
function.injective (to_add_monoid_hom : (M →ₛₗ[σ] M₃) → (M →+ M₃)) :=
λ f g h, ext $ add_monoid_hom.congr_fun h
/-- If two `σ`-linear maps from `R` are equal on `1`, then they are equal. -/
@[ext] theorem ext_ring {f g : R →ₛₗ[σ] M₃} (h : f 1 = g 1) : f = g :=
ext $ λ x, by rw [← mul_one x, ← smul_eq_mul, f.map_smulₛₗ, g.map_smulₛₗ, h]
theorem ext_ring_iff {σ : R →+* R} {f g : R →ₛₗ[σ] M} : f = g ↔ f 1 = g 1 :=
⟨λ h, h ▸ rfl, ext_ring⟩
end
section
variables [semiring R₁] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables {module_M₁ : module R₁ M₁} {module_M₂ : module R₂ M₂} {module_M₃ : module R₃ M₃}
variables {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃}
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₂] M₂)
include module_M₁ module_M₂ module_M₃
/-- Composition of two linear maps is a linear map -/
def comp : M₁ →ₛₗ[σ₁₃] M₃ :=
{ to_fun := f ∘ g,
map_add' := by simp only [map_add, forall_const, eq_self_iff_true, comp_app],
map_smul' := λ r x, by rw [comp_app, map_smulₛₗ, map_smulₛₗ, ring_hom_comp_triple.comp_apply] }
omit module_M₁ module_M₂ module_M₃
infixr ` ∘ₗ `:80 := @linear_map.comp _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
(ring_hom.id _) (ring_hom.id _) (ring_hom.id _) ring_hom_comp_triple.ids
include σ₁₃
lemma comp_apply (x : M₁) : f.comp g x = f (g x) := rfl
omit σ₁₃
include σ₁₃
@[simp, norm_cast] lemma coe_comp : (f.comp g : M₁ → M₃) = f ∘ g := rfl
omit σ₁₃
@[simp] theorem comp_id : f.comp id = f :=
linear_map.ext $ λ x, rfl
@[simp] theorem id_comp : id.comp f = f :=
linear_map.ext $ λ x, rfl
end
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₃]
/-- If a function `g` is a left and right inverse of a linear map `f`, then `g` is linear itself. -/
def inverse [module R M] [module S M₂] {σ : R →+* S} {σ' : S →+* R} [ring_hom_inv_pair σ σ']
(f : M →ₛₗ[σ] M₂) (g : M₂ → M) (h₁ : left_inverse g f) (h₂ : right_inverse g f) :
M₂ →ₛₗ[σ'] M :=
by dsimp [left_inverse, function.right_inverse] at h₁ h₂; exact
{ to_fun := g,
map_add' := λ x y, by { rw [← h₁ (g (x + y)), ← h₁ (g x + g y)]; simp [h₂] },
map_smul' := λ a b, by { rw [← h₁ (g (a • b)), ← h₁ ((σ' a) • g b)], simp [h₂] } }
end add_comm_monoid
section add_comm_group
variables [semiring R] [semiring S] [add_comm_group M] [add_comm_group M₂]
variables {module_M : module R M} {module_M₂ : module S M₂} {σ : R →+* S}
variables (f : M →ₛₗ[σ] M₂)
@[simp] lemma map_neg (x : M) : f (- x) = - f x :=
f.to_add_monoid_hom.map_neg x
@[simp] lemma map_sub (x y : M) : f (x - y) = f x - f y :=
f.to_add_monoid_hom.map_sub x y
instance compatible_smul.int_module
{S : Type*} [semiring S] [module S M] [module S M₂] : compatible_smul M M₂ ℤ S :=
⟨λ fₗ c x, begin
induction c using int.induction_on,
case hz : { simp },
case hp : n ih { simp [add_smul, ih] },
case hn : n ih { simp [sub_smul, ih] }
end⟩
instance compatible_smul.units {R S : Type*}
[monoid R] [mul_action R M] [mul_action R M₂] [semiring S] [module S M] [module S M₂]
[compatible_smul M M₂ R S] :
compatible_smul M M₂ (units R) S :=
⟨λ fₗ c x, (compatible_smul.map_smul fₗ (c : R) x : _)⟩
end add_comm_group
end linear_map
namespace module
/-- `g : R →+* S` is `R`-linear when the module structure on `S` is `module.comp_hom S g` . -/
@[simps]
def comp_hom.to_linear_map {R S : Type*} [semiring R] [semiring S] (g : R →+* S) :
(by haveI := comp_hom S g; exact (R →ₗ[R] S)) :=
by exact {
to_fun := (g : R → S),
map_add' := g.map_add,
map_smul' := g.map_mul }
end module
namespace distrib_mul_action_hom
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module R M₂]
/-- A `distrib_mul_action_hom` between two modules is a linear map. -/
def to_linear_map (fₗ : M →+[R] M₂) : M →ₗ[R] M₂ := { ..fₗ }
instance : has_coe (M →+[R] M₂) (M →ₗ[R] M₂) := ⟨to_linear_map⟩
@[simp] lemma to_linear_map_eq_coe (f : M →+[R] M₂) :
f.to_linear_map = ↑f :=
rfl
@[simp, norm_cast] lemma coe_to_linear_map (f : M →+[R] M₂) :
((f : M →ₗ[R] M₂) : M → M₂) = f :=
rfl
lemma to_linear_map_injective {f g : M →+[R] M₂} (h : (f : M →ₗ[R] M₂) = (g : M →ₗ[R] M₂)) :
f = g :=
by { ext m, exact linear_map.congr_fun h m, }
end distrib_mul_action_hom
namespace is_linear_map
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
variables [module R M] [module R M₂]
include R
/-- Convert an `is_linear_map` predicate to a `linear_map` -/
def mk' (f : M → M₂) (H : is_linear_map R f) : M →ₗ[R] M₂ :=
{ to_fun := f, map_add' := H.1, map_smul' := H.2 }
@[simp] theorem mk'_apply {f : M → M₂} (H : is_linear_map R f) (x : M) :
mk' f H x = f x := rfl
lemma is_linear_map_smul {R M : Type*} [comm_semiring R] [add_comm_monoid M] [module R M]
(c : R) :
is_linear_map R (λ (z : M), c • z) :=
begin
refine is_linear_map.mk (smul_add c) _,
intros _ _,
simp only [smul_smul, mul_comm]
end
lemma is_linear_map_smul' {R M : Type*} [semiring R] [add_comm_monoid M] [module R M] (a : M) :
is_linear_map R (λ (c : R), c • a) :=
is_linear_map.mk (λ x y, add_smul x y a) (λ x y, mul_smul x y a)
variables {f : M → M₂} (lin : is_linear_map R f)
include M M₂ lin
lemma map_zero : f (0 : M) = (0 : M₂) := (lin.mk' f).map_zero
end add_comm_monoid
section add_comm_group
variables [semiring R] [add_comm_group M] [add_comm_group M₂]
variables [module R M] [module R M₂]
include R
lemma is_linear_map_neg :
is_linear_map R (λ (z : M), -z) :=
is_linear_map.mk neg_add (λ x y, (smul_neg x y).symm)
variables {f : M → M₂} (lin : is_linear_map R f)
include M M₂ lin
lemma map_neg (x : M) : f (- x) = - f x := (lin.mk' f).map_neg x
lemma map_sub (x y) : f (x - y) = f x - f y := (lin.mk' f).map_sub x y
end add_comm_group
end is_linear_map
/-- Linear endomorphisms of a module, with associated ring structure
`module.End.semiring` and algebra structure `module.End.algebra`. -/
abbreviation module.End (R : Type u) (M : Type v)
[semiring R] [add_comm_monoid M] [module R M] := M →ₗ[R] M
/-- Reinterpret an additive homomorphism as a `ℕ`-linear map. -/
def add_monoid_hom.to_nat_linear_map [add_comm_monoid M] [add_comm_monoid M₂] (f : M →+ M₂) :
M →ₗ[ℕ] M₂ :=
{ to_fun := f, map_add' := f.map_add, map_smul' := f.map_nat_module_smul }
lemma add_monoid_hom.to_nat_linear_map_injective [add_comm_monoid M] [add_comm_monoid M₂] :
function.injective (@add_monoid_hom.to_nat_linear_map M M₂ _ _) :=
by { intros f g h, ext, exact linear_map.congr_fun h x }
/-- Reinterpret an additive homomorphism as a `ℤ`-linear map. -/
def add_monoid_hom.to_int_linear_map [add_comm_group M] [add_comm_group M₂] (f : M →+ M₂) :
M →ₗ[ℤ] M₂ :=
{ to_fun := f, map_add' := f.map_add, map_smul' := f.map_int_module_smul }
lemma add_monoid_hom.to_int_linear_map_injective [add_comm_group M] [add_comm_group M₂] :
function.injective (@add_monoid_hom.to_int_linear_map M M₂ _ _) :=
by { intros f g h, ext, exact linear_map.congr_fun h x }
@[simp] lemma add_monoid_hom.coe_to_int_linear_map [add_comm_group M] [add_comm_group M₂]
(f : M →+ M₂) :
⇑f.to_int_linear_map = f := rfl
/-- Reinterpret an additive homomorphism as a `ℚ`-linear map. -/
def add_monoid_hom.to_rat_linear_map [add_comm_group M] [module ℚ M]
[add_comm_group M₂] [module ℚ M₂] (f : M →+ M₂) :
M →ₗ[ℚ] M₂ :=
{ map_smul' := f.map_rat_module_smul, ..f }
lemma add_monoid_hom.to_rat_linear_map_injective
[add_comm_group M] [module ℚ M] [add_comm_group M₂] [module ℚ M₂] :
function.injective (@add_monoid_hom.to_rat_linear_map M M₂ _ _ _ _) :=
by { intros f g h, ext, exact linear_map.congr_fun h x }
@[simp] lemma add_monoid_hom.coe_to_rat_linear_map [add_comm_group M] [module ℚ M]
[add_comm_group M₂] [module ℚ M₂] (f : M →+ M₂) :
⇑f.to_rat_linear_map = f := rfl
namespace linear_map
/-! ### Arithmetic on the codomain -/
section arithmetic
variables [semiring R₁] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [add_comm_group N₁] [add_comm_group N₂] [add_comm_group N₃]
variables [module R₁ M] [module R₂ M₂] [module R₃ M₃]
variables [module R₁ N₁] [module R₂ N₂] [module R₃ N₃]
variables {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
/-- The constant 0 map is linear. -/
instance : has_zero (M →ₛₗ[σ₁₂] M₂) :=
⟨{ to_fun := 0, map_add' := by simp, map_smul' := by simp }⟩
@[simp] lemma zero_apply (x : M) : (0 : M →ₛₗ[σ₁₂] M₂) x = 0 := rfl
@[simp] theorem comp_zero (g : M₂ →ₛₗ[σ₂₃] M₃) : (g.comp (0 : M →ₛₗ[σ₁₂] M₂) : M →ₛₗ[σ₁₃] M₃) = 0 :=
ext $ assume c, by rw [comp_apply, zero_apply, zero_apply, g.map_zero]
@[simp] theorem zero_comp (f : M →ₛₗ[σ₁₂] M₂) : ((0 : M₂ →ₛₗ[σ₂₃] M₃).comp f : M →ₛₗ[σ₁₃] M₃) = 0 :=
rfl
instance : inhabited (M →ₛₗ[σ₁₂] M₂) := ⟨0⟩
@[simp] lemma default_def : default (M →ₛₗ[σ₁₂] M₂) = 0 := rfl
/-- The sum of two linear maps is linear. -/
instance : has_add (M →ₛₗ[σ₁₂] M₂) :=
⟨λ f g, { to_fun := f + g,
map_add' := by simp [add_comm, add_left_comm], map_smul' := by simp [smul_add] }⟩
@[simp] lemma add_apply (f g : M →ₛₗ[σ₁₂] M₂) (x : M) : (f + g) x = f x + g x := rfl
lemma add_comp (f : M →ₛₗ[σ₁₂] M₂) (g h : M₂ →ₛₗ[σ₂₃] M₃) :
((h + g).comp f : M →ₛₗ[σ₁₃] M₃) = h.comp f + g.comp f := rfl
lemma comp_add (f g : M →ₛₗ[σ₁₂] M₂) (h : M₂ →ₛₗ[σ₂₃] M₃) :
(h.comp (f + g) : M →ₛₗ[σ₁₃] M₃) = h.comp f + h.comp g :=
ext $ λ _, h.map_add _ _
/-- The type of linear maps is an additive monoid. -/
instance : add_comm_monoid (M →ₛₗ[σ₁₂] M₂) :=
{ zero := 0,
add := (+),
add_assoc := λ f g h, linear_map.ext $ λ x, add_assoc _ _ _,
zero_add := λ f, linear_map.ext $ λ x, zero_add _,
add_zero := λ f, linear_map.ext $ λ x, add_zero _,
add_comm := λ f g, linear_map.ext $ λ x, add_comm _ _,
nsmul := λ n f,
{ to_fun := λ x, n • (f x),
map_add' := λ x y, by rw [f.map_add, smul_add],
map_smul' := λ c x,
begin
rw [f.map_smulₛₗ],
simp [smul_comm n (σ₁₂ c) (f x)],
end },
nsmul_zero' := λ f, linear_map.ext $ λ x, add_comm_monoid.nsmul_zero' _,
nsmul_succ' := λ n f, linear_map.ext $ λ x, add_comm_monoid.nsmul_succ' _ _ }
/-- The negation of a linear map is linear. -/
instance : has_neg (M →ₛₗ[σ₁₂] N₂) :=
⟨λ f, { to_fun := -f, map_add' := by simp [add_comm], map_smul' := by simp }⟩
@[simp] lemma neg_apply (f : M →ₛₗ[σ₁₂] N₂) (x : M) : (- f) x = - f x := rfl
include σ₁₃
@[simp] lemma neg_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] N₃) : (- g).comp f = - g.comp f := rfl
@[simp] lemma comp_neg (f : M →ₛₗ[σ₁₂] N₂) (g : N₂ →ₛₗ[σ₂₃] N₃) : g.comp (- f) = - g.comp f :=
ext $ λ _, g.map_neg _
omit σ₁₃
/-- The negation of a linear map is linear. -/
instance : has_sub (M →ₛₗ[σ₁₂] N₂) :=
⟨λ f g, { to_fun := f - g,
map_add' := λ x y, by simp only [pi.sub_apply, map_add, add_sub_comm],
map_smul' := λ r x, by simp [pi.sub_apply, map_smul, smul_sub] }⟩
@[simp] lemma sub_apply (f g : M →ₛₗ[σ₁₂] N₂) (x : M) : (f - g) x = f x - g x := rfl
include σ₁₃
lemma sub_comp (f : M →ₛₗ[σ₁₂] M₂) (g h : M₂ →ₛₗ[σ₂₃] N₃) :
(g - h).comp f = g.comp f - h.comp f := rfl
lemma comp_sub (f g : M →ₛₗ[σ₁₂] N₂) (h : N₂ →ₛₗ[σ₂₃] N₃) :
h.comp (g - f) = h.comp g - h.comp f :=
ext $ λ _, h.map_sub _ _
omit σ₁₃
/-- The type of linear maps is an additive group. -/
instance : add_comm_group (M →ₛₗ[σ₁₂] N₂) :=
{ zero := 0,
add := (+),
neg := has_neg.neg,
sub := has_sub.sub,
sub_eq_add_neg := λ f g, linear_map.ext $ λ m, sub_eq_add_neg _ _,
add_left_neg := λ f, linear_map.ext $ λ m, add_left_neg _,
nsmul := λ n f, {
to_fun := λ x, n • (f x),
map_add' := λ x y, by rw [f.map_add, smul_add],
map_smul' := λ c x, by rw [f.map_smulₛₗ, smul_comm n (σ₁₂ c) (f x)] },
zsmul := λ n f, {
to_fun := λ x, n • (f x),
map_add' := λ x y, by rw [f.map_add, smul_add],
map_smul' := λ c x, by rw [f.map_smulₛₗ, smul_comm n (σ₁₂ c) (f x)] },
zsmul_zero' := λ a, linear_map.ext $ λ m, zero_smul _ _,
zsmul_succ' := λ n a, linear_map.ext $ λ m, add_comm_group.zsmul_succ' n _,
zsmul_neg' := λ n a, linear_map.ext $ λ m, add_comm_group.zsmul_neg' n _,
.. linear_map.add_comm_monoid }
end arithmetic
-- TODO: generalize this section to semilinear maps where possible
section actions
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [module R M] [module R M₂] [module R M₃]
section has_scalar
variables [monoid S] [distrib_mul_action S M₂] [smul_comm_class R S M₂]
variables [monoid T] [distrib_mul_action T M₂] [smul_comm_class R T M₂]
instance : has_scalar S (M →ₗ[R] M₂) :=
⟨λ a f, { to_fun := a • f,
map_add' := λ x y, by simp only [pi.smul_apply, f.map_add, smul_add],
map_smul' := λ c x, by simp [pi.smul_apply, f.map_smul, smul_comm c] }⟩
@[simp] lemma smul_apply (a : S) (f : M →ₗ[R] M₂) (x : M) : (a • f) x = a • f x := rfl
instance [smul_comm_class S T M₂] : smul_comm_class S T (M →ₗ[R] M₂) :=
⟨λ a b f, ext $ λ x, smul_comm _ _ _⟩
-- example application of this instance: if S -> T -> R are homomorphisms of commutative rings and
-- M and M₂ are R-modules then the S-module and T-module structures on Hom_R(M,M₂) are compatible.
instance [has_scalar S T] [is_scalar_tower S T M₂] : is_scalar_tower S T (M →ₗ[R] M₂) :=
{ smul_assoc := λ _ _ _, ext $ λ _, smul_assoc _ _ _ }
instance : distrib_mul_action S (M →ₗ[R] M₂) :=
{ one_smul := λ f, ext $ λ _, one_smul _ _,
mul_smul := λ c c' f, ext $ λ _, mul_smul _ _ _,
smul_add := λ c f g, ext $ λ x, smul_add _ _ _,
smul_zero := λ c, ext $ λ x, smul_zero _ }
theorem smul_comp (a : S) (g : M₃ →ₗ[R] M₂) (f : M →ₗ[R] M₃) : (a • g).comp f = a • (g.comp f) :=
rfl
theorem comp_smul [distrib_mul_action S M₃] [smul_comm_class R S M₃] [compatible_smul M₃ M₂ S R]
(g : M₃ →ₗ[R] M₂) (a : S) (f : M →ₗ[R] M₃) : g.comp (a • f) = a • (g.comp f) :=
ext $ λ x, g.map_smul_of_tower _ _
end has_scalar
section module
variables [semiring S] [module S M₂] [smul_comm_class R S M₂]
instance : module S (M →ₗ[R] M₂) :=
{ add_smul := λ a b f, ext $ λ x, add_smul _ _ _,
zero_smul := λ f, ext $ λ x, zero_smul _ _ }
end module
end actions
/-!
### Monoid structure of endomorphisms
Lemmas about `pow` such as `linear_map.pow_apply` appear in later files.
-/
section endomorphisms
variables [semiring R] [add_comm_monoid M] [add_comm_group N₁] [module R M] [module R N₁]
instance : has_one (module.End R M) := ⟨linear_map.id⟩
instance : has_mul (module.End R M) := ⟨linear_map.comp⟩
lemma one_eq_id : (1 : module.End R M) = id := rfl
lemma mul_eq_comp (f g : module.End R M) : f * g = f.comp g := rfl
@[simp] lemma one_apply (x : M) : (1 : module.End R M) x = x := rfl
@[simp] lemma mul_apply (f g : module.End R M) (x : M) : (f * g) x = f (g x) := rfl
lemma coe_one : ⇑(1 : module.End R M) = _root_.id := rfl
lemma coe_mul (f g : module.End R M) : ⇑(f * g) = f ∘ g := rfl
instance _root_.module.End.monoid : monoid (module.End R M) :=
{ mul := (*),
one := (1 : M →ₗ[R] M),
mul_assoc := λ f g h, linear_map.ext $ λ x, rfl,
mul_one := comp_id,
one_mul := id_comp }
instance _root_.module.End.semiring : semiring (module.End R M) :=
{ mul := (*),
one := (1 : M →ₗ[R] M),
zero := 0,
add := (+),
npow := @npow_rec _ ⟨(1 : M →ₗ[R] M)⟩ ⟨(*)⟩,
mul_zero := comp_zero,
zero_mul := zero_comp,
left_distrib := λ f g h, comp_add _ _ _,
right_distrib := λ f g h, add_comp _ _ _,
.. _root_.module.End.monoid,
.. linear_map.add_comm_monoid }
instance _root_.module.End.ring : ring (module.End R N₁) :=
{ ..module.End.semiring, ..linear_map.add_comm_group }
section
variables [monoid S] [distrib_mul_action S M] [smul_comm_class R S M]
instance _root_.module.End.is_scalar_tower :
is_scalar_tower S (module.End R M) (module.End R M) := ⟨smul_comp⟩
instance _root_.module.End.smul_comm_class [has_scalar S R] [is_scalar_tower S R M] :
smul_comm_class S (module.End R M) (module.End R M) :=
⟨λ s _ _, (comp_smul _ s _).symm⟩
instance _root_.module.End.smul_comm_class' [has_scalar S R] [is_scalar_tower S R M] :
smul_comm_class (module.End R M) S (module.End R M) :=
smul_comm_class.symm _ _ _
end
/-! ### Action by a module endomorphism. -/
/-- The tautological action by `module.End R M` (aka `M →ₗ[R] M`) on `M`.
This generalizes `function.End.apply_mul_action`. -/
instance apply_module : module (module.End R M) M :=
{ smul := ($),
smul_zero := linear_map.map_zero,
smul_add := linear_map.map_add,
add_smul := linear_map.add_apply,
zero_smul := (linear_map.zero_apply : ∀ m, (0 : M →ₗ[R] M) m = 0),
one_smul := λ _, rfl,
mul_smul := λ _ _ _, rfl }
@[simp] protected lemma smul_def (f : module.End R M) (a : M) : f • a = f a := rfl
/-- `linear_map.apply_module` is faithful. -/
instance apply_has_faithful_scalar : has_faithful_scalar (module.End R M) M :=
⟨λ _ _, linear_map.ext⟩
instance apply_smul_comm_class : smul_comm_class R (module.End R M) M :=
{ smul_comm := λ r e m, (e.map_smul r m).symm }
instance apply_smul_comm_class' : smul_comm_class (module.End R M) R M :=
{ smul_comm := linear_map.map_smul }
end endomorphisms
end linear_map
|
000036f2cfbbace5d47d6fe0e88ec30c9ccc232d | c8af905dcd8475f414868d303b2eb0e9d3eb32f9 | /src/data/cpi/species/congruence_prime.lean | 033be5ae3abbf72389ee66a9c9b76e0743ee05e9 | [
"BSD-3-Clause"
] | permissive | continuouspi/lean-cpi | 81480a13842d67ff5f3698643210d8ed5dd08de4 | 443bf2cb236feadc45a01387099c236ab2b78237 | refs/heads/master | 1,650,307,316,582 | 1,587,033,364,000 | 1,587,033,364,000 | 207,499,661 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,009 | lean | import data.cpi.species.congruence data.cpi.species.prime
namespace cpi
namespace species
namespace equiv
variables {ℍ : Type} {ω : context}
open_locale congruence
section depth
private def depth : ∀ {Γ}, species ℍ ω Γ → ℕ
| _ nil := 0
| _ (apply _ _) := 1
| _ (Σ# _) := 1
| _ (A |ₛ B) := depth A + depth B
| Γ (ν(_) A) := depth A
using_well_founded {
rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ x, whole.sizeof ℍ ω kind.species x.fst x.snd ) ⟩ ],
dec_tac := tactic.fst_dec_tac,
}
private lemma depth_rename : ∀ {Γ Δ} (ρ : name Γ → name Δ) (A : species ℍ ω Γ), depth (rename ρ A) = depth A
| _ _ ρ nil := by simp only [rename.nil, depth]
| _ _ ρ (apply _ _) := by simp only [rename.invoke, depth]
| _ _ ρ (Σ# _) := by simp only [rename.choice, depth]
| _ _ ρ (A |ₛ B) := begin
simp only [rename.parallel, depth],
rw [depth_rename ρ A, depth_rename ρ B],
end
| _ _ ρ (ν(_) A) := begin
simp only [rename.restriction, depth],
from depth_rename (name.ext ρ) A,
end
using_well_founded {
rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ x, whole.sizeof ℍ ω kind.species x.1 x.2.2.2 ) ⟩ ],
dec_tac := tactic.fst_dec_tac,
}
private lemma depth_eq : ∀ {Γ} {A B : species ℍ ω Γ}, A ≈ B → depth A = depth B
| Γ A B ⟨ eq ⟩ := begin
induction eq,
case equivalent.refl { from rfl },
case equivalent.trans : _ A' B' C' ab bc ihab ihbc { from trans ihab ihbc },
case equivalent.ξ_parallel₁ : _ A' A'' B eq ih { unfold depth, rw ih },
case equivalent.ξ_parallel₂ : _ A B' B' eq ih { unfold depth, rw ih },
case equivalent.ξ_restriction : _ M A A' eq ih { unfold depth, rw ih },
all_goals { repeat { unfold depth <|> simp only [add_zero, zero_add, add_comm, add_assoc, depth_rename] } },
end
private lemma depth_nil : ∀ {Γ} {A : species ℍ ω Γ}, A ≈ nil → depth A = 0
| Γ A eq := by { have eq := depth_eq eq, unfold depth at eq, from eq }
private lemma depth_nil_rev : ∀ {Γ} {A : species ℍ ω Γ}, depth A = 0 → A ≈ nil
| _ nil eq := refl _
| _ (apply _ _) eq := by { unfold depth at eq, contradiction }
| _ (Σ# _) eq:= by { unfold depth at eq, contradiction }
| _ (A |ₛ B) eq := begin
unfold depth at eq,
calc (A |ₛ B)
≈ (A |ₛ nil) : equiv.ξ_parallel₂ (depth_nil_rev (nat.eq_zero_of_add_eq_zero_left eq))
... ≈ A : equiv.parallel_nil₁
... ≈ nil : depth_nil_rev (nat.eq_zero_of_add_eq_zero_right eq)
end
| _ (ν(M) A) eq := begin
unfold depth at eq,
calc (ν(M) A)
≈ (ν(M) nil) : equiv.ξ_restriction M (depth_nil_rev eq)
... ≈ (ν(M) species.rename name.extend nil) : by simp only [rename.nil]
... ≈ nil : equiv.ν_drop₁ M
end
using_well_founded {
rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ x, whole.sizeof ℍ ω kind.species x.1 x.2.1 ) ⟩ ],
dec_tac := tactic.fst_dec_tac,
}
end depth
open_locale classical
/-- A procecure to compute the prime decomposition of a species using classical
logic. This is sound, but non-computable. -/
noncomputable def do_prime_decompose {Γ} :
∀ (A : species ℍ ω Γ)
, Σ' (As : list (prime_species ℍ ω Γ))
, A ≈ parallel.from_list (list.map subtype.val As)
| A :=
if is_nil : A ≈ nil then
⟨ [], is_nil ⟩
else if has_decomp : ∃ B C, ¬ B ≈ nil ∧ ¬ C ≈ nil ∧ A ≈ (B |ₛ C) then
let B := classical.some has_decomp in
let C := classical.some (classical.some_spec has_decomp) in
have h : ¬B ≈ nil ∧ ¬C ≈ nil ∧ A ≈ (B |ₛ C) := classical.some_spec (classical.some_spec has_decomp),
have lB : depth B < depth A := begin
have : depth A = depth (B |ₛ C) := depth_eq h.2.2, rw this, unfold depth,
from lt_add_of_pos_right _ (nat.pos_of_ne_zero (λ x, h.2.1 (depth_nil_rev x)))
end,
have lC : depth C < depth A := begin
have : depth A = depth (B |ₛ C) := depth_eq h.2.2, rw this, unfold depth,
from lt_add_of_pos_left _ (nat.pos_of_ne_zero (λ x, h.1 (depth_nil_rev x)))
end,
let Bs := do_prime_decompose B in
let Cs := do_prime_decompose C in
suffices this : A ≈ parallel.from_list (list.map subtype.val (Bs.1 ++ Cs.1)),
from ⟨ Bs.1 ++ Cs.1, this ⟩,
calc A
≈ (B |ₛ C) : h.2.2
... ≈ (parallel.from_list (list.map subtype.val Bs.1) |ₛ parallel.from_list (list.map subtype.val Cs.1))
: trans (equiv.ξ_parallel₁ Bs.2) (equiv.ξ_parallel₂ Cs.2)
... ≈ parallel.from_list (list.map subtype.val Bs.1 ++ list.map subtype.val Cs.1)
: (parallel.from_append _ _).symm
... ≈ parallel.from_list (list.map subtype.val (Bs.1 ++ Cs.1)) : by rw list.map_append
else
suffices this : prime A, from ⟨ [ ⟨ A, this ⟩ ], refl _ ⟩,
⟨ is_nil, λ B C eq,
if nilB : B ≈ nil then or.inl nilB else
if nilC : C ≈ nil then or.inr nilC else
false.elim (has_decomp ⟨ B, C, nilB, nilC, eq ⟩) ⟩
using_well_founded {
rel_tac := λ _ _, `[exact ⟨_, measure_wf depth ⟩ ],
dec_tac := tactic.fst_dec_tac',
}
/-- Decompose a species into its constituent primes. -/
noncomputable def prime_decompose {Γ} (A : species ℍ ω Γ) : multiset (prime_species ℍ ω Γ)
:= ⟦ (do_prime_decompose A).1 ⟧
lemma prime_decompose_nil {Γ} : prime_decompose (@nil ℍ ω Γ) = 0 := begin
unfold prime_decompose do_prime_decompose,
simpa only [dif_pos (refl nil)],
end
lemma prime_decompose_prime {Γ} : ∀ (A : prime_species ℍ ω Γ), prime_decompose A.val = [ A ]
| ⟨ A, ⟨ n_nil, n_decompose ⟩ ⟩ := begin
have n_exist : ¬ ∃ (B C : whole ℍ ω kind.species Γ), ¬B ≈ nil ∧ ¬C ≈ nil ∧ A ≈ (B |ₛ C),
{ rintros ⟨ B, C, nB, nC, r ⟩, from or.elim (n_decompose B C r) nB nC },
unfold prime_decompose do_prime_decompose,
simpa only [dif_neg n_nil, dif_neg n_exist],
end
end equiv
end species
end cpi
#lint-
|
4ae314346326c467fdab014756f5a0c117d0b856 | 874a8d2247ab9a4516052498f80da2e32d0e3a48 | /root2.lean | 2b16f64c6cdfde0c81d952c589e137494e0d6524 | [] | no_license | AlexKontorovich/Spring2020Math492 | 378b36c643ee029f5ab91c1677889baa591f5e85 | 659108c5d864ff5c75b9b3b13b847aa5cff4348a | refs/heads/master | 1,610,780,595,457 | 1,588,174,859,000 | 1,588,174,859,000 | 243,017,788 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 1,496 | lean | /- Very unfinished, Will finish by end of term -/
import data.rat.basic
import data.nat.prime
import data.real.basic
open nat algebra
variables a b : ℕ
variable x : ℝ
def root2 (x : ℝ) := (x^2 = 2)
def is_rat (x : ℝ) Prop := ∃ a : ℕ ∃ b : ℤ, x = a / b
/-
theorem root2_irrat (rt : root2 x) (a b : ℕ): ¬ is_rat x :=
assume is_rat x,
exists.elim h (fun (a b: ℕ) (hw1 : x = a / b),
begin
sorry
end
)
-/
def even (n : ℕ) : Prop := ∃ m, n = 2 * m
def odd (n : ℕ) : Prop := ∃ m, n = 2 * m + 1
lemma not_even_and_odd (n : ℕ) : ¬((even n) ∧ (odd n)) :=
sorry
lemma not_even_and_odd (n : ℕ) : ¬((even n) ∧ (odd n)) :=
assume (h : even n ∧ odd n),
have he: even n, from h.left,
have ho: odd n, from h.right,
have ev: ∃ m, n = 2 * m, from he,
have od: ∃ m, n = 2 * m + 1, from ho,
exists.elim ev (fun (m1 : ℕ) (h1 : n = 2 * m1),
exists.elim od (fun (m2 : ℕ) (h2 : n = 2 * m2 + 1),
begin
eq.trans (eq.symm h1) h2
end
))
lemma even_square_even_root {n m: ℕ} (n = m^2) (e: even n) : even m :=
exists.elim e (assume m1, assume hw1 : n = 2 * m1,
begin
/- Requires prime number theory or claim that not even = odd-/
sorry
end)
theorem root2_irrat {a b asq bsq : ℕ} (gcd_1 : gcd a b = 1) (p: asq = a^2) (q: bsq = b^2): asq ≠ 2 * bsq :=
assume (h : asq = 2 * bsq),
have evasq : even asq :=
begin
rw even,
/- exists.elim bsq -/
sorry
end,
have eva : even a :=
begin
/- apply even_square_even_root asq p -/
sorry
end,
|
66d8bcaa5c00be6b11e67b63b55f6077714718c0 | 28d9ae48dddad2ebe8cb28027b15e9c9d996e0ed | /src/cs.lean | 6797987654f1e744d5c87b9b3c9dddf149e1d869 | [] | no_license | ImperialCollegeLondon/british-natural-number-game | 0f76ac920488db62b3d391bd60d650e725f90938 | 593dede2c911e0651b8d177365180b659d7b2acf | refs/heads/master | 1,669,990,486,571 | 1,596,886,731,000 | 1,596,886,731,000 | 285,931,256 | 4 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 634 | lean | import pos_num
namespace xena
namespace pos_num
def bit (b : bool) : ℙ → ℙ := cond b bit1 bit0
def is_one : ℙ → bool
| 1 := tt
| _ := ff
def nat_size : ℙ → nat
| 1 := 1
| (bit0 n) := nat.succ (nat_size n)
| (bit1 n) := nat.succ (nat_size n)
open ordering
def cmp : ℙ → ℙ → ordering
| 1 1 := eq
| _ 1 := gt
| 1 _ := lt
| (bit0 a) (bit0 b) := cmp a b
| (bit0 a) (bit1 b) := ordering.cases_on (cmp a b) lt lt gt
| (bit1 a) (bit0 b) := ordering.cases_on (cmp a b) lt gt gt
| (bit1 a) (bit1 b) := cmp a b
end pos_num
end xena
|
83bab43c7ab56ed6eba7047f9c9ac24d7b8b1acf | 19cc34575500ee2e3d4586c15544632aa07a8e66 | /src/topology/algebra/group.lean | 135ece1c0c1996730fe2f9cc210a25781acfe9eb | [
"Apache-2.0"
] | permissive | LibertasSpZ/mathlib | b9fcd46625eb940611adb5e719a4b554138dade6 | 33f7870a49d7cc06d2f3036e22543e6ec5046e68 | refs/heads/master | 1,672,066,539,347 | 1,602,429,158,000 | 1,602,429,158,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,103 | 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
Theory of topological groups.
-/
import order.filter.pointwise
import group_theory.quotient_group
import topology.algebra.monoid
import topology.homeomorph
open classical set filter topological_space
open_locale classical topological_space filter
universes u v w x
variables {α : Type u} {β : Type v} {G : Type w} {H : Type x}
section topological_group
/-- 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 (λa:G, a⁻¹))
variables [topological_space G] [group G]
@[to_additive]
lemma continuous_inv [topological_group G] : continuous (λx:G, x⁻¹) :=
topological_group.continuous_inv
@[to_additive, continuity]
lemma continuous.inv [topological_group G] [topological_space α] {f : α → G}
(hf : continuous f) : continuous (λx, (f x)⁻¹) :=
continuous_inv.comp hf
attribute [continuity] continuous.neg
@[to_additive]
lemma continuous_on_inv [topological_group G] {s : set G} : continuous_on (λx:G, x⁻¹) s :=
continuous_inv.continuous_on
@[to_additive]
lemma continuous_on.inv [topological_group G] [topological_space α] {f : α → G} {s : set α}
(hf : continuous_on f s) : continuous_on (λx, (f x)⁻¹) s :=
continuous_inv.comp_continuous_on hf
@[to_additive]
lemma tendsto_inv {G : Type*} [group G]
[topological_space G] [topological_group G] (a : G) :
tendsto (λ x, x⁻¹) (nhds a) (nhds (a⁻¹)) :=
continuous_inv.tendsto a
/-- 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 [topological_group G] {f : α → G} {x : filter α} {a : G}
(hf : tendsto f x (𝓝 a)) : tendsto (λx, (f x)⁻¹) x (𝓝 a⁻¹) :=
tendsto.comp (continuous_iff_continuous_at.mp topological_group.continuous_inv a) hf
@[to_additive]
lemma continuous_at.inv [topological_group G] [topological_space α] {f : α → G} {x : α}
(hf : continuous_at f x) : continuous_at (λx, (f x)⁻¹) x :=
hf.inv
@[to_additive]
lemma continuous_within_at.inv [topological_group G] [topological_space α] {f : α → G}
{s : set α} {x : α} (hf : continuous_within_at f s x) :
continuous_within_at (λx, (f x)⁻¹) s x :=
hf.inv
@[to_additive]
instance [topological_group G] [topological_space H] [group H] [topological_group H] :
topological_group (G × H) :=
{ continuous_inv := continuous_fst.inv.prod_mk continuous_snd.inv }
attribute [instance] prod.topological_add_group
/-- 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 [topological_group G] (a : G) : G ≃ₜ G :=
{ continuous_to_fun := continuous_const.mul continuous_id,
continuous_inv_fun := continuous_const.mul continuous_id,
.. equiv.mul_left a }
@[to_additive]
lemma is_open_map_mul_left [topological_group G] (a : G) : is_open_map (λ x, a * x) :=
(homeomorph.mul_left a).is_open_map
@[to_additive]
lemma is_closed_map_mul_left [topological_group G] (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
{G : Type*} [topological_space G] [group G] [topological_group G] (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 [topological_group G] (a : G) : is_open_map (λ x, x * a) :=
(homeomorph.mul_right a).is_open_map
@[to_additive]
lemma is_closed_map_mul_right [topological_group G] (a : G) : is_closed_map (λ x, x * a) :=
(homeomorph.mul_right a).is_closed_map
/-- Inversion in a topological group as a homeomorphism.-/
@[to_additive "Negation in a topological group as a homeomorphism."]
protected def homeomorph.inv (G : Type*) [topological_space G] [group G] [topological_group G] :
G ≃ₜ G :=
{ continuous_to_fun := continuous_inv,
continuous_inv_fun := continuous_inv,
.. equiv.inv G }
@[to_additive exists_nhds_half_neg]
lemma exists_nhds_split_inv [topological_group G] {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 [nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage]
section
variable (G)
@[to_additive]
lemma nhds_one_symm [topological_group G] : comap (λr:G, r⁻¹) (𝓝 (1 : G)) = 𝓝 (1 : G) :=
begin
have lim : tendsto (λr:G, r⁻¹) (𝓝 1) (𝓝 1),
{ simpa using (@tendsto_id G (𝓝 1)).inv },
refine comap_eq_of_inverse _ _ lim lim,
{ funext x, simp },
end
end
@[to_additive]
lemma nhds_translation_mul_inv [topological_group G] (x : G) :
comap (λy:G, y * x⁻¹) (𝓝 1) = 𝓝 x :=
begin
refine comap_eq_of_inverse (λy:G, y * x) _ _ _,
{ funext x; simp },
{ suffices : tendsto (λy:G, y * x⁻¹) (𝓝 x) (𝓝 (x * x⁻¹)), { simpa },
exact tendsto_id.mul tendsto_const_nhds },
{ suffices : tendsto (λy:G, y * x) (𝓝 1) (𝓝 (1 * x)), { simpa },
exact tendsto_id.mul tendsto_const_nhds }
end
@[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]
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 u} [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, is_open_map_mul_right n s s_op)
end
@[to_additive]
instance topological_group_quotient (n : 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
apply continuous_quotient_lift,
change continuous ((coe : G → quotient N) ∘ (λ (a : G), a⁻¹)),
exact continuous_quot_mk.comp continuous_inv
end }
attribute [instance] topological_add_group_quotient
end quotient_topological_group
section topological_add_group
variables [topological_space G] [add_group G]
@[continuity] lemma continuous.sub [topological_add_group G] [topological_space α] {f : α → G} {g : α → G}
(hf : continuous f) (hg : continuous g) : continuous (λx, f x - g x) :=
by simp [sub_eq_add_neg]; exact hf.add hg.neg
lemma continuous_sub [topological_add_group G] : continuous (λp:G×G, p.1 - p.2) :=
continuous_fst.sub continuous_snd
lemma continuous_on.sub [topological_add_group G] [topological_space α] {f : α → G} {g : α → G} {s : set α}
(hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (λx, f x - g x) s :=
continuous_sub.comp_continuous_on (hf.prod hg)
lemma filter.tendsto.sub [topological_add_group G] {f : α → G} {g : α → G} {x : filter α} {a b : G}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) : tendsto (λx, f x - g x) x (𝓝 (a - b)) :=
by simp [sub_eq_add_neg]; exact hf.add hg.neg
lemma nhds_translation [topological_add_group G] (x : G) : comap (λy:G, y - x) (𝓝 0) = 𝓝 x :=
nhds_translation_add_neg x
end topological_add_group
/-- 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)
namespace add_group_with_zero_nhd
variables (G) [add_group_with_zero_nhd G]
local notation `Z` := add_group_with_zero_nhd.Z
@[priority 100] -- see Note [lower instance priority]
instance : topological_space G :=
topological_space.mk_of_nhds $ λa, map (λx, x + a) (Z G)
variables {G}
lemma neg_Z : tendsto (λa:G, - a) (Z G) (Z G) :=
have tendsto (λa, (0:G)) (Z G) (Z G),
by refine le_trans (assume h, _) zero_Z; simp [univ_mem_sets'] {contextual := tt},
have tendsto (λa:G, 0 - a) (Z G) (Z G), from
sub_Z.comp (tendsto.prod_mk this tendsto_id),
by simpa
lemma add_Z : tendsto (λp:G×G, p.1 + p.2) (Z G ×ᶠ Z G) (Z G) :=
suffices tendsto (λp:G×G, p.1 - -p.2) (Z G ×ᶠ Z G) (Z G),
by simpa [sub_eq_add_neg],
sub_Z.comp (tendsto.prod_mk tendsto_fst (neg_Z.comp tendsto_snd))
lemma exists_Z_half {s : set G} (hs : s ∈ Z G) : ∃ V ∈ Z G, ∀ (v ∈ V) (w ∈ V), v + w ∈ s :=
begin
have : ((λa:G×G, a.1 + a.2) ⁻¹' s) ∈ Z G ×ᶠ Z G := add_Z (by simpa using hs),
rcases mem_prod_self_iff.1 this with ⟨V, H, H'⟩,
exact ⟨V, H, prod_subset_iff.1 H'⟩
end
lemma nhds_eq (a : G) : 𝓝 a = map (λx, x + a) (Z G) :=
topological_space.nhds_mk_of_nhds _ _
(assume a, calc pure a = map (λx, x + a) (pure 0) : by simp
... ≤ _ : map_mono zero_Z)
(assume b s hs,
let ⟨t, ht, eqt⟩ := exists_Z_half hs in
have t0 : (0:G) ∈ t, by simpa using zero_Z ht,
begin
refine ⟨(λx:G, x + b) '' t, image_mem_map ht, _, _⟩,
{ refine set.image_subset_iff.2 (assume b hbt, _),
simpa using eqt 0 t0 b hbt },
{ rintros _ ⟨c, hb, rfl⟩,
refine (Z G).sets_of_superset ht (assume x hxt, _),
simpa [add_assoc] using eqt _ hxt _ hb }
end)
lemma nhds_zero_eq_Z : 𝓝 0 = Z G := by simp [nhds_eq]; exact filter.map_id
@[priority 100] -- see Note [lower instance priority]
instance : has_continuous_add G :=
⟨ continuous_iff_continuous_at.2 $ assume ⟨a, b⟩,
begin
rw [continuous_at, nhds_prod_eq, nhds_eq, nhds_eq, nhds_eq, filter.prod_map_map_eq,
tendsto_map'_iff],
suffices : tendsto ((λx:G, (a + b) + x) ∘ (λp:G×G,p.1 + p.2)) (Z G ×ᶠ Z G)
(map (λx:G, (a + b) + x) (Z G)),
{ simpa [(∘), add_comm, add_left_comm] },
exact tendsto_map.comp add_Z
end ⟩
@[priority 100] -- see Note [lower instance priority]
instance : topological_add_group G :=
⟨continuous_iff_continuous_at.2 $ assume a,
begin
rw [continuous_at, nhds_eq, nhds_eq, tendsto_map'_iff],
suffices : tendsto ((λx:G, x - a) ∘ (λx:G, -x)) (Z G) (map (λx:G, x - a) (Z G)),
{ simpa [(∘), add_comm, sub_eq_add_neg] using this },
exact tendsto_map.comp neg_Z
end⟩
end add_group_with_zero_nhd
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, apply is_open_map_mul_left, exact 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)
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 }⟩
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 (hf _ (is_open_compl_iff.2 hs)) a (1:G) (by simpa [f]) in
begin
use [s * t₂, is_open_mul_left ht₂, λ x hx, ⟨x, 1, hx, one_mem_t₂, mul_one _⟩],
apply inf_principal_eq_bot,
rw mem_nhds_sets_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
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, continuous_mul_left x U hU,
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 (mem_nhds_sets (h1W x) (h2W x.1 x.2)),
let X : K → set G := λ x, (λ y, (x : G)⁻¹ * y) ⁻¹' (V x),
cases hK.elim_finite_subcover X (λ x, continuous_mul_left x⁻¹ (V x) (hV x).1) _ with t ht, swap,
{ 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
cases hV with g₀ hg₀,
rcases is_compact.elim_finite_subcover hK (λ x : G, interior $ (λ h, x * h) ⁻¹' V) _ _ with ⟨t, ht⟩,
{ refine ⟨t, subset.trans ht _⟩,
apply Union_subset_Union, intro g, apply Union_subset_Union, intro hg, apply interior_subset },
{ intro g, apply is_open_interior },
{ intros g hg, rw [mem_Union], use g₀ * g⁻¹,
apply preimage_interior_subset_interior_preimage, exact continuous_const.mul continuous_id,
rwa [mem_preimage, inv_mul_cancel_right] }
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_sets 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_nhds hd },
{ simp only [inv_mul_cancel_right] } }
end
@[to_additive]
lemma nhds_is_mul_hom : is_mul_hom (λx:G, 𝓝 x) := ⟨λ_ _, nhds_mul _ _⟩
end
end filter_mul
|
50f080bfc8c51b61ea8cb4502e924c6892204fe7 | 30b012bb72d640ec30c8fdd4c45fdfa67beb012c | /algebra/group_power.lean | 5c1b924182e251a78e6d0eea6ca5e0aeca72cbbd | [
"Apache-2.0"
] | permissive | kckennylau/mathlib | 21fb810b701b10d6606d9002a4004f7672262e83 | 47b3477e20ffb5a06588dd3abb01fe0fe3205646 | refs/heads/master | 1,634,976,409,281 | 1,542,042,832,000 | 1,542,319,733,000 | 109,560,458 | 0 | 0 | Apache-2.0 | 1,542,369,208,000 | 1,509,867,494,000 | Lean | UTF-8 | Lean | false | false | 23,366 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
The power operation on monoids and groups. We separate this from group, because it depends on
nat, which in turn depends on other parts of algebra.
We have "pow a n" for natural number powers, and "gpow a i" for integer powers. The notation
a^n is used for the first, but users can locally redefine it to gpow when needed.
Note: power adopts the convention that 0^0=1.
-/
import algebra.char_zero algebra.group algebra.ordered_field
import data.int.basic data.list.basic
universes u v
variable {α : Type u}
@[simp] theorem inv_one [division_ring α] : (1⁻¹ : α) = 1 := by rw [inv_eq_one_div, one_div_one]
@[simp] theorem inv_inv' [discrete_field α] {a:α} : a⁻¹⁻¹ = a :=
by rw [inv_eq_one_div, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_one]
/-- The power operation in a monoid. `a^n = a*a*...*a` n times. -/
def monoid.pow [monoid α] (a : α) : ℕ → α
| 0 := 1
| (n+1) := a * monoid.pow n
def add_monoid.smul [add_monoid α] (n : ℕ) (a : α) : α :=
@monoid.pow (multiplicative α) _ a n
precedence `•`:70
local infix ` • ` := add_monoid.smul
@[priority 5] instance monoid.has_pow [monoid α] : has_pow α ℕ := ⟨monoid.pow⟩
/- monoid -/
section monoid
variables [monoid α] {β : Type u} [add_monoid β]
@[simp] theorem pow_zero (a : α) : a^0 = 1 := rfl
@[simp] theorem add_monoid.zero_smul (a : β) : 0 • a = 0 := rfl
attribute [to_additive add_monoid.zero_smul] pow_zero
theorem pow_succ (a : α) (n : ℕ) : a^(n+1) = a * a^n := rfl
theorem succ_smul (a : β) (n : ℕ) : (n+1)•a = a + n•a := rfl
attribute [to_additive succ_smul] pow_succ
@[simp] theorem pow_one (a : α) : a^1 = a := mul_one _
@[simp] theorem add_monoid.one_smul (a : β) : 1•a = a := add_zero _
attribute [to_additive add_monoid.one_smul] pow_one
theorem pow_mul_comm' (a : α) (n : ℕ) : a^n * a = a * a^n :=
by induction n with n ih; [rw [pow_zero, one_mul, mul_one],
rw [pow_succ, mul_assoc, ih]]
theorem smul_add_comm' : ∀ (a : β) (n : ℕ), n•a + a = a + n•a :=
@pow_mul_comm' (multiplicative β) _
theorem pow_succ' (a : α) (n : ℕ) : a^(n+1) = a^n * a :=
by rw [pow_succ, pow_mul_comm']
theorem succ_smul' (a : β) (n : ℕ) : (n+1)•a = n•a + a :=
by rw [succ_smul, smul_add_comm']
attribute [to_additive succ_smul'] pow_succ'
theorem pow_two (a : α) : a^2 = a * a :=
show a*(a*1)=a*a, by rw mul_one
theorem two_smul (a : β) : 2•a = a + a :=
show a+(a+0)=a+a, by rw add_zero
attribute [to_additive two_smul] pow_two
theorem pow_add (a : α) (m n : ℕ) : a^(m + n) = a^m * a^n :=
by induction n with n ih; [rw [add_zero, pow_zero, mul_one],
rw [pow_succ, ← pow_mul_comm', ← mul_assoc, ← ih, ← pow_succ']]; refl
theorem add_monoid.add_smul : ∀ (a : β) (m n : ℕ), (m + n)•a = m•a + n•a :=
@pow_add (multiplicative β) _
attribute [to_additive add_monoid.add_smul] pow_add
@[simp] theorem one_pow (n : ℕ) : (1 : α)^n = (1:α) :=
by induction n with n ih; [refl, rw [pow_succ, ih, one_mul]]
@[simp] theorem add_monoid.smul_zero (n : ℕ) : n•(0 : β) = (0:β) :=
by induction n with n ih; [refl, rw [succ_smul, ih, zero_add]]
attribute [to_additive add_monoid.smul_zero] one_pow
theorem pow_mul (a : α) (m n : ℕ) : a^(m * n) = (a^m)^n :=
by induction n with n ih; [rw mul_zero, rw [nat.mul_succ, pow_add, pow_succ', ih]]; refl
theorem add_monoid.mul_smul' : ∀ (a : β) (m n : ℕ), m * n • a = n•(m•a) :=
@pow_mul (multiplicative β) _
attribute [to_additive add_monoid.mul_smul'] pow_mul
theorem pow_mul' (a : α) (m n : ℕ) : a^(m * n) = (a^n)^m :=
by rw [mul_comm, pow_mul]
theorem add_monoid.mul_smul (a : β) (m n : ℕ) : m * n • a = m•(n•a) :=
by rw [mul_comm, add_monoid.mul_smul']
attribute [to_additive add_monoid.mul_smul] pow_mul'
@[simp] theorem add_monoid.smul_one [has_one β] : ∀ n : ℕ, n • (1 : β) = n :=
nat.eq_cast _ (add_monoid.zero_smul _) (add_monoid.one_smul _) (add_monoid.add_smul _)
theorem pow_bit0 (a : α) (n : ℕ) : a ^ bit0 n = a^n * a^n := pow_add _ _ _
theorem bit0_smul (a : β) (n : ℕ) : bit0 n • a = n•a + n•a := add_monoid.add_smul _ _ _
attribute [to_additive bit0_smul] pow_bit0
theorem pow_bit1 (a : α) (n : ℕ) : a ^ bit1 n = a^n * a^n * a :=
by rw [bit1, pow_succ', pow_bit0]
theorem bit1_smul : ∀ (a : β) (n : ℕ), bit1 n • a = n•a + n•a + a :=
@pow_bit1 (multiplicative β) _
attribute [to_additive bit1_smul] pow_bit1
theorem pow_mul_comm (a : α) (m n : ℕ) : a^m * a^n = a^n * a^m :=
by rw [←pow_add, ←pow_add, add_comm]
theorem smul_add_comm : ∀ (a : β) (m n : ℕ), m•a + n•a = n•a + m•a :=
@pow_mul_comm (multiplicative β) _
attribute [to_additive smul_add_comm] pow_mul_comm
@[simp] theorem list.prod_repeat (a : α) (n : ℕ) : (list.repeat a n).prod = a ^ n :=
by induction n with n ih; [refl, rw [list.repeat_succ, list.prod_cons, ih]]; refl
@[simp] theorem list.sum_repeat : ∀ (a : β) (n : ℕ), (list.repeat a n).sum = n • a :=
@list.prod_repeat (multiplicative β) _
attribute [to_additive list.sum_repeat] list.prod_repeat
@[simp] lemma units.coe_pow (u : units α) (n : ℕ) : ((u ^ n : units α) : α) = u ^ n :=
by induction n; simp [*, pow_succ]
end monoid
@[simp] theorem nat.pow_eq_pow (p q : ℕ) :
@has_pow.pow _ _ monoid.has_pow p q = p ^ q :=
by induction q with q ih; [refl, rw [nat.pow_succ, pow_succ, mul_comm, ih]]
@[simp] theorem nat.smul_eq_mul (m n : ℕ) : m • n = m * n :=
by induction m with m ih; [rw [add_monoid.zero_smul, zero_mul],
rw [succ_smul', ih, nat.succ_mul]]
/- commutative monoid -/
section comm_monoid
variables [comm_monoid α] {β : Type*} [add_comm_monoid β]
theorem mul_pow (a b : α) (n : ℕ) : (a * b)^n = a^n * b^n :=
by induction n with n ih; [exact (mul_one _).symm,
simp only [pow_succ, ih, mul_assoc, mul_left_comm]]
theorem add_monoid.smul_add : ∀ (a b : β) (n : ℕ), n•(a + b) = n•a + n•b :=
@mul_pow (multiplicative β) _
attribute [to_additive add_monoid.add_smul] mul_pow
end comm_monoid
section group
variables [group α] {β : Type*} [add_group β]
section nat
@[simp] theorem inv_pow (a : α) (n : ℕ) : (a⁻¹)^n = (a^n)⁻¹ :=
by induction n with n ih; [exact one_inv.symm,
rw [pow_succ', pow_succ, ih, mul_inv_rev]]
@[simp] theorem add_monoid.neg_smul : ∀ (a : β) (n : ℕ), n•(-a) = -(n•a) :=
@inv_pow (multiplicative β) _
attribute [to_additive add_monoid.neg_smul] inv_pow
theorem pow_sub (a : α) {m n : ℕ} (h : m ≥ n) : a^(m - n) = a^m * (a^n)⁻¹ :=
have h1 : m - n + n = m, from nat.sub_add_cancel h,
have h2 : a^(m - n) * a^n = a^m, by rw [←pow_add, h1],
eq_mul_inv_of_mul_eq h2
theorem add_monoid.smul_sub : ∀ (a : β) {m n : ℕ}, m ≥ n → (m - n)•a = m•a - n•a :=
@pow_sub (multiplicative β) _
attribute [to_additive add_monoid.smul_sub] inv_pow
theorem pow_inv_comm (a : α) (m n : ℕ) : (a⁻¹)^m * a^n = a^n * (a⁻¹)^m :=
by rw inv_pow; exact inv_comm_of_comm (pow_mul_comm _ _ _)
theorem add_monoid.smul_neg_comm : ∀ (a : β) (m n : ℕ), m•(-a) + n•a = n•a + m•(-a) :=
@pow_inv_comm (multiplicative β) _
attribute [to_additive add_monoid.smul_neg_comm] pow_inv_comm
end nat
open int
/--
The power operation in a group. This extends `monoid.pow` to negative integers
with the definition `a^(-n) = (a^n)⁻¹`.
-/
def gpow (a : α) : ℤ → α
| (of_nat n) := a^n
| -[1+n] := (a^(nat.succ n))⁻¹
def gsmul (n : ℤ) (a : β) : β :=
@gpow (multiplicative β) _ a n
@[priority 10] instance group.has_pow : has_pow α ℤ := ⟨gpow⟩
local infix ` • `:70 := gsmul
local infix ` •ℕ `:70 := add_monoid.smul
@[simp] theorem gpow_coe_nat (a : α) (n : ℕ) : a ^ (n:ℤ) = a ^ n := rfl
@[simp] theorem gsmul_coe_nat (a : β) (n : ℕ) : (n:ℤ) • a = n •ℕ a := rfl
attribute [to_additive gsmul_coe_nat] gpow_coe_nat
@[simp] theorem gpow_of_nat (a : α) (n : ℕ) : a ^ of_nat n = a ^ n := rfl
@[simp] theorem gsmul_of_nat (a : β) (n : ℕ) : of_nat n • a = n •ℕ a := rfl
attribute [to_additive gsmul_of_nat] gpow_of_nat
@[simp] theorem gpow_neg_succ (a : α) (n : ℕ) : a ^ -[1+n] = (a ^ n.succ)⁻¹ := rfl
@[simp] theorem gsmul_neg_succ (a : β) (n : ℕ) : -[1+n] • a = - (n.succ •ℕ a) := rfl
attribute [to_additive gsmul_neg_succ] gpow_neg_succ
local attribute [ematch] le_of_lt
open nat
@[simp] theorem gpow_zero (a : α) : a ^ (0:ℤ) = 1 := rfl
@[simp] theorem zero_gsmul (a : β) : (0:ℤ) • a = 0 := rfl
attribute [to_additive zero_gsmul] gpow_zero
@[simp] theorem gpow_one (a : α) : a ^ (1:ℤ) = a := mul_one _
@[simp] theorem one_gsmul (a : β) : (1:ℤ) • a = a := add_zero _
attribute [to_additive one_gsmul] gpow_one
@[simp] theorem one_gpow : ∀ (n : ℤ), (1 : α) ^ n = 1
| (n : ℕ) := one_pow _
| -[1+ n] := show _⁻¹=(1:α), by rw [_root_.one_pow, one_inv]
@[simp] theorem gsmul_zero : ∀ (n : ℤ), n • (0 : β) = 0 :=
@one_gpow (multiplicative β) _
attribute [to_additive gsmul_zero] one_gpow
@[simp] theorem gpow_neg (a : α) : ∀ (n : ℤ), a ^ -n = (a ^ n)⁻¹
| (n+1:ℕ) := rfl
| 0 := one_inv.symm
| -[1+ n] := (inv_inv _).symm
@[simp] theorem neg_gsmul : ∀ (a : β) (n : ℤ), -n • a = -(n • a) :=
@gpow_neg (multiplicative β) _
attribute [to_additive neg_gsmul] gpow_neg
theorem gpow_neg_one (x : α) : x ^ (-1:ℤ) = x⁻¹ := congr_arg has_inv.inv $ pow_one x
theorem neg_one_gsmul (x : β) : (-1:ℤ) • x = -x := congr_arg has_neg.neg $ add_monoid.one_smul x
attribute [to_additive neg_one_gsmul] gpow_neg_one
theorem inv_gpow (a : α) : ∀n:ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) := inv_pow a n
| -[1+ n] := congr_arg has_inv.inv $ inv_pow a (n+1)
private lemma gpow_add_aux (a : α) (m n : nat) :
a ^ ((of_nat m) + -[1+n]) = a ^ of_nat m * a ^ -[1+n] :=
or.elim (nat.lt_or_ge m (nat.succ n))
(assume h1 : m < succ n,
have h2 : m ≤ n, from le_of_lt_succ h1,
suffices a ^ -[1+ n-m] = a ^ of_nat m * a ^ -[1+n],
by rwa [of_nat_add_neg_succ_of_nat_of_lt h1],
show (a ^ nat.succ (n - m))⁻¹ = a ^ of_nat m * a ^ -[1+n],
by rw [← succ_sub h2, pow_sub _ (le_of_lt h1), mul_inv_rev, inv_inv]; refl)
(assume : m ≥ succ n,
suffices a ^ (of_nat (m - succ n)) = (a ^ (of_nat m)) * (a ^ -[1+ n]),
by rw [of_nat_add_neg_succ_of_nat_of_ge]; assumption,
suffices a ^ (m - succ n) = a ^ m * (a ^ n.succ)⁻¹, from this,
by rw pow_sub; assumption)
theorem gpow_add (a : α) : ∀ (i j : ℤ), a ^ (i + j) = a ^ i * a ^ j
| (of_nat m) (of_nat n) := pow_add _ _ _
| (of_nat m) -[1+n] := gpow_add_aux _ _ _
| -[1+m] (of_nat n) := by rw [add_comm, gpow_add_aux,
gpow_neg_succ, gpow_of_nat, ← inv_pow, ← pow_inv_comm]
| -[1+m] -[1+n] :=
suffices (a ^ (m + succ (succ n)))⁻¹ = (a ^ m.succ)⁻¹ * (a ^ n.succ)⁻¹, from this,
by rw [← succ_add_eq_succ_add, add_comm, _root_.pow_add, mul_inv_rev]
theorem add_gsmul : ∀ (a : β) (i j : ℤ), (i + j) • a = i • a + j • a :=
@gpow_add (multiplicative β) _
theorem gpow_mul_comm (a : α) (i j : ℤ) : a ^ i * a ^ j = a ^ j * a ^ i :=
by rw [← gpow_add, ← gpow_add, add_comm]
theorem gsmul_add_comm : ∀ (a : β) (i j), i • a + j • a = j • a + i • a :=
@gpow_mul_comm (multiplicative β) _
attribute [to_additive gsmul_add_comm] gpow_mul_comm
theorem gpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ) (n : ℕ) := pow_mul _ _ _
| (m : ℕ) -[1+ n] := (gpow_neg _ (m * succ n)).trans $
show (a ^ (m * succ n))⁻¹ = _, by rw pow_mul; refl
| -[1+ m] (n : ℕ) := (gpow_neg _ (succ m * n)).trans $
show (a ^ (m.succ * n))⁻¹ = _, by rw [pow_mul, ← inv_pow]; refl
| -[1+ m] -[1+ n] := (pow_mul a (succ m) (succ n)).trans $
show _ = (_⁻¹^_)⁻¹, by rw [inv_pow, inv_inv]
theorem gsmul_mul' : ∀ (a : β) (m n : ℤ), m * n • a = n • (m • a) :=
@gpow_mul (multiplicative β) _
attribute [to_additive gsmul_mul'] gpow_mul
theorem gpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m :=
by rw [mul_comm, gpow_mul]
theorem gsmul_mul (a : β) (m n : ℤ) : m * n • a = m • (n • a) :=
by rw [mul_comm, gsmul_mul']
attribute [to_additive gsmul_mul] gpow_mul'
theorem gpow_bit0 (a : α) (n : ℤ) : a ^ bit0 n = a ^ n * a ^ n := gpow_add _ _ _
theorem bit0_gsmul (a : β) (n : ℤ) : bit0 n • a = n • a + n • a := gpow_add _ _ _
attribute [to_additive bit0_gsmul] gpow_bit0
theorem gpow_bit1 (a : α) (n : ℤ) : a ^ bit1 n = a ^ n * a ^ n * a :=
by rw [bit1, gpow_add]; simp [gpow_bit0]
theorem bit1_gsmul : ∀ (a : β) (n : ℤ), bit1 n • a = n • a + n • a + a :=
@gpow_bit1 (multiplicative β) _
attribute [to_additive bit1_gsmul] gpow_bit1
theorem gsmul_neg (a : β) (n : ℤ) : gsmul n (- a) = - gsmul n a :=
begin
induction n using int.induction_on with z ih z ih,
{ simp },
{ rw [add_comm] {occs := occurrences.pos [1]}, simp [add_gsmul, ih, -add_comm] },
{ rw [sub_eq_add_neg, add_comm] {occs := occurrences.pos [1]},
simp [ih, add_gsmul, neg_gsmul, -add_comm] }
end
attribute [to_additive gsmul_neg] gpow_neg
end group
namespace is_group_hom
variables {β : Type v} [group α] [group β] (f : α → β) [is_group_hom f]
theorem pow (a : α) (n : ℕ) : f (a ^ n) = f a ^ n :=
by induction n with n ih; [exact is_group_hom.one f,
rw [pow_succ, is_group_hom.mul f, ih]]; refl
theorem gpow (a : α) (n : ℤ) : f (a ^ n) = f a ^ n :=
by cases n; [exact is_group_hom.pow f _ _,
exact (is_group_hom.inv f _).trans (congr_arg _ $ is_group_hom.pow f _ _)]
end is_group_hom
namespace is_add_group_hom
variables {β : Type v} [add_group α] [add_group β] (f : α → β) [is_add_group_hom f]
theorem smul (a : α) (n : ℕ) : f (n • a) = n • f a :=
by induction n with n ih; [exact is_add_group_hom.zero f,
rw [succ_smul, is_add_group_hom.add f, ih]]; refl
theorem gsmul (a : α) (n : ℤ) : f (gsmul n a) = gsmul n (f a) :=
begin
induction n using int.induction_on with z ih z ih,
{ simp [is_add_group_hom.zero f] },
{ simp [is_add_group_hom.add f, add_gsmul, ih] },
{ simp [is_add_group_hom.add f, is_add_group_hom.neg f, add_gsmul, ih] }
end
end is_add_group_hom
local infix ` •ℤ `:70 := gsmul
section comm_monoid
variables [comm_group α] {β : Type*} [add_comm_group β]
theorem mul_gpow (a b : α) : ∀ n:ℤ, (a * b)^n = a^n * b^n
| (n : ℕ) := mul_pow a b n
| -[1+ n] := show _⁻¹=_⁻¹*_⁻¹, by rw [mul_pow, mul_inv_rev, mul_comm]
theorem gsmul_add : ∀ (a b : β) (n : ℤ), n •ℤ (a + b) = n •ℤ a + n •ℤ b :=
@mul_gpow (multiplicative β) _
attribute [to_additive gsmul_add] mul_gpow
theorem gsmul_sub : ∀ (a b : β) (n : ℤ), gsmul n (a - b) = gsmul n a - gsmul n b :=
by simp [gsmul_add, gsmul_neg]
end comm_monoid
section group
@[instance]
theorem is_add_group_hom_gsmul
{α β} [add_group α] [add_comm_group β] (f : α → β) [is_add_group_hom f] (z : ℤ) :
is_add_group_hom (λa, gsmul z (f a)) :=
⟨assume a b, by rw [is_add_group_hom.add f, gsmul_add]⟩
end group
theorem add_monoid.smul_eq_mul' [semiring α] (a : α) (n : ℕ) : n • a = a * n :=
by induction n with n ih; [rw [add_monoid.zero_smul, nat.cast_zero, mul_zero],
rw [succ_smul', ih, nat.cast_succ, mul_add, mul_one]]
theorem add_monoid.smul_eq_mul [semiring α] (n : ℕ) (a : α) : n • a = n * a :=
by rw [add_monoid.smul_eq_mul', nat.mul_cast_comm]
theorem add_monoid.mul_smul_left [semiring α] (a b : α) (n : ℕ) : n • (a * b) = a * (n • b) :=
by rw [add_monoid.smul_eq_mul', add_monoid.smul_eq_mul', mul_assoc]
theorem add_monoid.mul_smul_assoc [semiring α] (a b : α) (n : ℕ) : n • (a * b) = n • a * b :=
by rw [add_monoid.smul_eq_mul, add_monoid.smul_eq_mul, mul_assoc]
lemma zero_pow [semiring α] : ∀ {n : ℕ}, 0 < n → (0 : α) ^ n = 0
| (n+1) _ := zero_mul _
@[simp] theorem nat.cast_pow [semiring α] (n m : ℕ) : (↑(n ^ m) : α) = ↑n ^ m :=
by induction m with m ih; [exact nat.cast_one, rw [nat.pow_succ, pow_succ', nat.cast_mul, ih]]
@[simp] theorem int.coe_nat_pow (n m : ℕ) : ((n ^ m : ℕ) : ℤ) = n ^ m :=
by induction m with m ih; [exact int.coe_nat_one, rw [nat.pow_succ, pow_succ', int.coe_nat_mul, ih]]
theorem int.nat_abs_pow (n : ℤ) (k : ℕ) : int.nat_abs (n ^ k) = (int.nat_abs n) ^ k :=
by induction k with k ih; [refl, rw [pow_succ', int.nat_abs_mul, nat.pow_succ, ih]]
theorem is_semiring_hom.map_pow {β} [semiring α] [semiring β]
(f : α → β) [is_semiring_hom f] (x : α) (n : ℕ) : f (x ^ n) = f x ^ n :=
by induction n with n ih; [exact is_semiring_hom.map_one f,
rw [pow_succ, pow_succ, is_semiring_hom.map_mul f, ih]]
theorem neg_one_pow_eq_or {R} [ring R] : ∀ n : ℕ, (-1 : R)^n = 1 ∨ (-1 : R)^n = -1
| 0 := or.inl rfl
| (n+1) := (neg_one_pow_eq_or n).swap.imp
(λ h, by rw [pow_succ, h, neg_one_mul, neg_neg])
(λ h, by rw [pow_succ, h, mul_one])
theorem gsmul_eq_mul [ring α] (a : α) : ∀ n, n •ℤ a = n * a
| (n : ℕ) := add_monoid.smul_eq_mul _ _
| -[1+ n] := show -(_•_)=-_*_, by rw [neg_mul_eq_neg_mul_symm, add_monoid.smul_eq_mul, nat.cast_succ]
theorem gsmul_eq_mul' [ring α] (a : α) (n : ℤ) : n •ℤ a = a * n :=
by rw [gsmul_eq_mul, int.mul_cast_comm]
theorem mul_gsmul_left [ring α] (a b : α) (n : ℤ) : n •ℤ (a * b) = a * (n •ℤ b) :=
by rw [gsmul_eq_mul', gsmul_eq_mul', mul_assoc]
theorem mul_gsmul_assoc [ring α] (a b : α) (n : ℤ) : n •ℤ (a * b) = n •ℤ a * b :=
by rw [gsmul_eq_mul, gsmul_eq_mul, mul_assoc]
@[simp] theorem int.cast_pow [ring α] (n : ℤ) (m : ℕ) : (↑(n ^ m) : α) = ↑n ^ m :=
by induction m with m ih; [exact int.cast_one,
rw [pow_succ, pow_succ, int.cast_mul, ih]]
lemma neg_one_pow_eq_pow_mod_two [ring α] {n : ℕ} : (-1 : α) ^ n = -1 ^ (n % 2) :=
by rw [← nat.mod_add_div n 2, pow_add, pow_mul]; simp [pow_two]
theorem pow_eq_zero [domain α] {x : α} {n : ℕ} (H : x^n = 0) : x = 0 :=
begin
induction n with n ih,
{ rw pow_zero at H,
rw [← mul_one x, H, mul_zero] },
exact or.cases_on (mul_eq_zero.1 H) id ih
end
theorem pow_ne_zero [domain α] {a : α} (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 :=
mt pow_eq_zero h
@[simp] theorem one_div_pow [division_ring α] {a : α} (ha : a ≠ 0) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n :=
by induction n with n ih; [exact (div_one _).symm,
rw [pow_succ', ih, division_ring.one_div_mul_one_div (pow_ne_zero _ ha) ha]]; refl
@[simp] theorem division_ring.inv_pow [division_ring α] {a : α} (ha : a ≠ 0) (n : ℕ) : a⁻¹ ^ n = (a ^ n)⁻¹ :=
by simpa only [inv_eq_one_div] using one_div_pow ha n
@[simp] theorem div_pow [field α] (a : α) {b : α} (hb : b ≠ 0) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n :=
by rw [div_eq_mul_one_div, mul_pow, one_div_pow hb, ← div_eq_mul_one_div]
theorem add_monoid.smul_nonneg [ordered_comm_monoid α] {a : α} (H : 0 ≤ a) : ∀ n : ℕ, 0 ≤ n • a
| 0 := le_refl _
| (n+1) := add_nonneg' H (add_monoid.smul_nonneg n)
lemma pow_abs [decidable_linear_ordered_comm_ring α] (a : α) (n : ℕ) : (abs a)^n = abs (a^n) :=
by induction n with n ih; [exact (abs_one).symm,
rw [pow_succ, pow_succ, ih, abs_mul]]
lemma inv_pow' [discrete_field α] (a : α) (n : ℕ) : (a ^ n)⁻¹ = a⁻¹ ^ n :=
by induction n; simp [*, pow_succ, mul_inv', mul_comm]
lemma pow_inv [division_ring α] (a : α) : ∀ n : ℕ, a ≠ 0 → (a^n)⁻¹ = (a⁻¹)^n
| 0 ha := inv_one
| (n+1) ha := by rw [pow_succ, pow_succ', mul_inv_eq (pow_ne_zero _ ha) ha, pow_inv _ ha]
section linear_ordered_semiring
variable [linear_ordered_semiring α]
theorem pow_pos {a : α} (H : 0 < a) : ∀ (n : ℕ), 0 < a ^ n
| 0 := zero_lt_one
| (n+1) := mul_pos H (pow_pos _)
theorem pow_nonneg {a : α} (H : 0 ≤ a) : ∀ (n : ℕ), 0 ≤ a ^ n
| 0 := zero_le_one
| (n+1) := mul_nonneg H (pow_nonneg _)
theorem one_le_pow_of_one_le {a : α} (H : 1 ≤ a) : ∀ (n : ℕ), 1 ≤ a ^ n
| 0 := le_refl _
| (n+1) := by simpa only [mul_one] using mul_le_mul H (one_le_pow_of_one_le n)
zero_le_one (le_trans zero_le_one H)
theorem pow_ge_one_add_mul {a : α} (H : a ≥ 0) :
∀ (n : ℕ), 1 + n • a ≤ (1 + a) ^ n
| 0 := le_of_eq $ add_zero _
| (n+1) := begin
rw [pow_succ', succ_smul'],
refine le_trans _ (mul_le_mul_of_nonneg_right
(pow_ge_one_add_mul n) (add_nonneg zero_le_one H)),
rw [mul_add, mul_one, ← add_assoc, add_le_add_iff_left],
simpa only [one_mul] using mul_le_mul_of_nonneg_right
((le_add_iff_nonneg_right 1).2 (add_monoid.smul_nonneg H n)) H
end
theorem pow_le_pow {a : α} {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m :=
let ⟨k, hk⟩ := nat.le.dest h in
calc a ^ n = a ^ n * 1 : (mul_one _).symm
... ≤ a ^ n * a ^ k : mul_le_mul_of_nonneg_left
(one_le_pow_of_one_le ha _)
(pow_nonneg (le_trans zero_le_one ha) _)
... = a ^ m : by rw [←hk, pow_add]
lemma pow_le_pow_of_le_left {a b : α} (ha : 0 ≤ a) (hab : a ≤ b) : ∀ i : ℕ, a^i ≤ b^i
| 0 := by simp
| (k+1) := mul_le_mul hab (pow_le_pow_of_le_left _) (pow_nonneg ha _) (le_trans ha hab)
private lemma pow_lt_pow_of_lt_one_aux {a : α} (h : 0 < a) (ha : a < 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k + 1) < a ^ i
| 0 := begin simp, rw ←one_mul (a^i), exact mul_lt_mul ha (le_refl _) (pow_pos h _) zero_le_one end
| (k+1) :=
begin
rw ←one_mul (a^i),
apply mul_lt_mul ha _ _ zero_le_one,
{ apply le_of_lt, apply pow_lt_pow_of_lt_one_aux },
{ show 0 < a ^ (i + (k + 1) + 0), apply pow_pos h }
end
private lemma pow_le_pow_of_le_one_aux {a : α} (h : 0 ≤ a) (ha : a ≤ 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k) ≤ a ^ i
| 0 := by simp
| (k+1) := by rw [←add_assoc, ←one_mul (a^i)];
exact mul_le_mul ha (pow_le_pow_of_le_one_aux _) (pow_nonneg h _) zero_le_one
lemma pow_lt_pow_of_lt_one {a : α} (h : 0 < a) (ha : a < 1)
{i j : ℕ} (hij : i < j) : a ^ j < a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_lt hij in
by rw hk; exact pow_lt_pow_of_lt_one_aux h ha _ _
lemma pow_le_pow_of_le_one {a : α} (h : 0 ≤ a) (ha : a ≤ 1)
{i j : ℕ} (hij : i ≤ j) : a ^ j ≤ a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_le hij in
by rw hk; exact pow_le_pow_of_le_one_aux h ha _ _
lemma pow_le_one {x : α} : ∀ (n : ℕ) (h0 : 0 ≤ x) (h1 : x ≤ 1), x ^ n ≤ 1
| 0 h0 h1 := le_refl (1 : α)
| (n+1) h0 h1 := mul_le_one h1 (pow_nonneg h0 _) (pow_le_one n h0 h1)
end linear_ordered_semiring
theorem pow_two_nonneg [linear_ordered_ring α] (a : α) : 0 ≤ a ^ 2 :=
by rw pow_two; exact mul_self_nonneg _
theorem pow_ge_one_add_sub_mul [linear_ordered_ring α]
{a : α} (H : a ≥ 1) (n : ℕ) : 1 + n • (a - 1) ≤ a ^ n :=
by simpa only [add_sub_cancel'_right] using pow_ge_one_add_mul (sub_nonneg.2 H) n
namespace int
lemma units_pow_two (u : units ℤ) : u ^ 2 = 1 :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
lemma units_pow_eq_pow_mod_two (u : units ℤ) (n : ℕ) : u ^ n = u ^ (n % 2) :=
by conv {to_lhs, rw ← nat.mod_add_div n 2}; rw [pow_add, pow_mul, units_pow_two, one_pow, mul_one]
end int
@[simp] lemma neg_square {α} [ring α] (z : α) : (-z)^2 = z^2 :=
by simp [pow, monoid.pow]
lemma div_sq_cancel {α} [field α] {a : α} (ha : a ≠ 0) (b : α) : a^2 * b / a = a * b :=
by rw [pow_two, mul_assoc, mul_div_cancel_left _ ha]
|
c545a7025ecb12f3d0d5934a6ecf08aec4a000de | 367134ba5a65885e863bdc4507601606690974c1 | /src/control/bifunctor.lean | e1810f4c9be851398523449674256669b4106693 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 4,333 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
Functors with two arguments
-/
import logic.function.basic
import control.functor
import tactic.core
universes u₀ u₁ u₂ v₀ v₁ v₂
open function
class bifunctor (F : Type u₀ → Type u₁ → Type u₂) :=
(bimap : Π {α α' β β'}, (α → α') → (β → β') → F α β → F α' β')
export bifunctor ( bimap )
class is_lawful_bifunctor (F : Type u₀ → Type u₁ → Type u₂) [bifunctor F] :=
(id_bimap : Π {α β} (x : F α β), bimap id id x = x)
(bimap_bimap : Π {α₀ α₁ α₂ β₀ β₁ β₂} (f : α₀ → α₁) (f' : α₁ → α₂)
(g : β₀ → β₁) (g' : β₁ → β₂) (x : F α₀ β₀),
bimap f' g' (bimap f g x) = bimap (f' ∘ f) (g' ∘ g) x)
export is_lawful_bifunctor (id_bimap bimap_bimap)
attribute [higher_order bimap_id_id] id_bimap
attribute [higher_order bimap_comp_bimap] bimap_bimap
export is_lawful_bifunctor (bimap_id_id bimap_comp_bimap)
variables {F : Type u₀ → Type u₁ → Type u₂} [bifunctor F]
namespace bifunctor
@[reducible]
def fst {α α' β} (f : α → α') : F α β → F α' β :=
bimap f id
@[reducible]
def snd {α β β'} (f : β → β') : F α β → F α β' :=
bimap id f
variable [is_lawful_bifunctor F]
@[higher_order fst_id]
lemma id_fst : Π {α β} (x : F α β), fst id x = x :=
@id_bimap _ _ _
@[higher_order snd_id]
lemma id_snd : Π {α β} (x : F α β), snd id x = x :=
@id_bimap _ _ _
@[higher_order fst_comp_fst]
lemma comp_fst {α₀ α₁ α₂ β}
(f : α₀ → α₁) (f' : α₁ → α₂) (x : F α₀ β) :
fst f' (fst f x) = fst (f' ∘ f) x :=
by simp [fst,bimap_bimap]
@[higher_order fst_comp_snd]
lemma fst_snd {α₀ α₁ β₀ β₁}
(f : α₀ → α₁) (f' : β₀ → β₁) (x : F α₀ β₀) :
fst f (snd f' x) = bimap f f' x :=
by simp [fst,bimap_bimap]
@[higher_order snd_comp_fst]
lemma snd_fst {α₀ α₁ β₀ β₁}
(f : α₀ → α₁) (f' : β₀ → β₁) (x : F α₀ β₀) :
snd f' (fst f x) = bimap f f' x :=
by simp [snd,bimap_bimap]
@[higher_order snd_comp_snd]
lemma comp_snd {α β₀ β₁ β₂}
(g : β₀ → β₁) (g' : β₁ → β₂) (x : F α β₀) :
snd g' (snd g x) = snd (g' ∘ g) x :=
by simp [snd,bimap_bimap]
attribute [functor_norm] bimap_bimap comp_snd comp_fst
snd_comp_snd snd_comp_fst fst_comp_snd fst_comp_fst bimap_comp_bimap
bimap_id_id fst_id snd_id
end bifunctor
open functor
instance : bifunctor prod :=
{ bimap := @prod.map }
instance : is_lawful_bifunctor prod :=
by refine { .. }; intros; cases x; refl
instance bifunctor.const : bifunctor const :=
{ bimap := (λ α α' β β f _, f) }
instance is_lawful_bifunctor.const : is_lawful_bifunctor const :=
by refine { .. }; intros; refl
instance bifunctor.flip : bifunctor (flip F) :=
{ bimap := (λ α α' β β' f f' x, (bimap f' f x : F β' α')) }
instance is_lawful_bifunctor.flip [is_lawful_bifunctor F] : is_lawful_bifunctor (flip F) :=
by refine { .. }; intros; simp [bimap] with functor_norm
instance : bifunctor sum :=
{ bimap := @sum.map }
instance : is_lawful_bifunctor sum :=
by refine { .. }; intros; cases x; refl
open bifunctor functor
@[priority 10]
instance bifunctor.functor {α} : functor (F α) :=
{ map := λ _ _, snd }
@[priority 10]
instance bifunctor.is_lawful_functor [is_lawful_bifunctor F] {α} : is_lawful_functor (F α) :=
by refine {..}; intros; simp [functor.map] with functor_norm
section bicompl
variables (G : Type* → Type u₀) (H : Type* → Type u₁) [functor G] [functor H]
instance : bifunctor (bicompl F G H) :=
{ bimap := λ α α' β β' f f' x, (bimap (map f) (map f') x : F (G α') (H β')) }
instance [is_lawful_functor G] [is_lawful_functor H] [is_lawful_bifunctor F] :
is_lawful_bifunctor (bicompl F G H) :=
by constructor; intros; simp [bimap,map_id,map_comp_map] with functor_norm
end bicompl
section bicompr
variables (G : Type u₂ → Type*) [functor G]
instance : bifunctor (bicompr G F) :=
{ bimap := λ α α' β β' f f' x, (map (bimap f f') x : G (F α' β')) }
instance [is_lawful_functor G] [is_lawful_bifunctor F] :
is_lawful_bifunctor (bicompr G F) :=
by constructor; intros; simp [bimap] with functor_norm
end bicompr
|
24683a649e079ca3253ff5c2b8167f3b1aadd9dc | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0704.lean | 093b0a0720560b3414aa2f70ad4d692148c93c69 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 595 | lean | variables (w x y z : ℕ) (p : ℕ → Prop)
local attribute [simp] mul_comm mul_assoc mul_left_comm
example (h : p (x * y + z * w * x)) : p (x * w * z + y * x) :=
by { simp [add_comm] at *, assumption }
-- lean 3.6 removes simp attributes from add_comm
-- i.e., now it is required to provide that lemma to solve this example.
example (h₁ : p (1 * x + y)) (h₂ : p (x * z * 1)) :
p (y + 0 + x) ∧ p (z * x) :=
by { simp [add_comm] at *, split; assumption }
-- lean 3.6 removes simp attributes from add_comm
-- i.e., now it is required to provide that lemma to solve this example.
|
cd4e553a83b77fa960709b8069cc47b8b447f743 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/order/rearrangement.lean | 33d66aabb7ec4813a807e8a89e1d15a9466fb74a | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 9,798 | lean | /-
Copyright (c) 2022 Mantas Bakšys. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mantas Bakšys
-/
import algebra.order.module
import group_theory.perm.support
import order.lexicographic
import order.monovary
import tactic.abel
/-!
# Rearrangement inequality
This file proves the rearrangement inequality.
The rearrangement inequality tells you that for two functions `f g : ι → α`, the sum
`∑ i, f i * g (σ i)` is maximized over all `σ : perm ι` when `g ∘ σ` monovaries with `f` and
minimized when `g ∘ σ` antivaries with `f`.
## Implementation notes
In fact, we don't need much compatibility between the addition and multiplication of `α`, so we can
actually decouple them by replacing multiplication with scalar multiplication and making `f` and `g`
land in different types.
As a bonus, this makes the dual statement trivial. The multiplication versions are provided for
convenience.
The case for `monotone`/`antitone` pairs of functions over a `linear_order` is not deduced in this
file because it is easily deducible from the `monovary` API.
-/
open equiv equiv.perm finset order_dual
open_locale big_operators
variables {ι α β : Type*}
/-! ### Scalar multiplication versions -/
section smul
variables [linear_ordered_ring α] [linear_ordered_add_comm_group β] [module α β]
[ordered_smul α β] {s : finset ι} {σ : perm ι} {f : ι → α} {g : ι → β}
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` vary together. Stated by permuting the entries of `g`. -/
lemma monovary_on.sum_smul_comp_perm_le_sum_smul (hfg : monovary_on f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f i • g (σ i) ≤ ∑ i in s, f i • g i :=
begin
classical,
revert hσ σ hfg,
apply finset.induction_on_max_value (λ i, to_lex (g i, f i)) s,
{ simp only [le_rfl, finset.sum_empty, implies_true_iff] },
intros a s has hamax hind σ hfg hσ,
set τ : perm ι := σ.trans (swap a (σ a)) with hτ,
have hτs : {x | τ x ≠ x} ⊆ s,
{ intros x hx,
simp only [ne.def, set.mem_set_of_eq, equiv.coe_trans, equiv.swap_comp_apply] at hx,
split_ifs at hx with h₁ h₂ h₃,
{ obtain rfl | hax := eq_or_ne x a,
{ contradiction },
{ exact mem_of_mem_insert_of_ne (hσ $ λ h, hax $ h.symm.trans h₁) hax } },
{ exact (hx $ σ.injective h₂.symm).elim },
{ exact mem_of_mem_insert_of_ne (hσ hx) (ne_of_apply_ne _ h₂) } },
specialize hind (hfg.subset $ subset_insert _ _) hτs,
simp_rw sum_insert has,
refine le_trans _ (add_le_add_left hind _),
obtain hσa | hσa := eq_or_ne a (σ a),
{ rw [←hσa, swap_self, trans_refl] at hτ,
rw [←hσa, hτ] },
have h1s : σ⁻¹ a ∈ s,
{ rw [ne.def, ←inv_eq_iff_eq] at hσa,
refine mem_of_mem_insert_of_ne (hσ $ λ h, hσa _) hσa,
rwa [apply_inv_self, eq_comm] at h },
simp only [← s.sum_erase_add _ h1s, add_comm],
rw [← add_assoc, ← add_assoc],
refine add_le_add _ (sum_congr rfl $ λ x hx, _).le,
{ simp only [hτ, swap_apply_left, function.comp_app, equiv.coe_trans, apply_inv_self],
suffices : 0 ≤ (f a - f (σ⁻¹ a)) • (g a - g (σ a)),
{ rw ← sub_nonneg,
convert this,
simp only [smul_sub, sub_smul],
abel },
refine smul_nonneg (sub_nonneg_of_le _) (sub_nonneg_of_le _),
{ specialize hamax (σ⁻¹ a) h1s,
rw prod.lex.le_iff at hamax,
cases hamax,
{ exact hfg (mem_insert_of_mem h1s) (mem_insert_self _ _) hamax },
{ exact hamax.2 } },
{ specialize hamax (σ a) (mem_of_mem_insert_of_ne (hσ $ σ.injective.ne hσa.symm) hσa.symm),
rw prod.lex.le_iff at hamax,
cases hamax,
{ exact hamax.le },
{ exact hamax.1.le } } },
{ congr' 2,
rw [eq_comm, hτ],
rw [mem_erase, ne.def, eq_inv_iff_eq] at hx,
refine swap_apply_of_ne_of_ne hx.1 (σ.injective.ne _),
rintro rfl,
exact has hx.2 }
end
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` vary together. Stated by permuting the entries of `f`. -/
lemma monovary_on.sum_comp_perm_smul_le_sum_smul (hfg : monovary_on f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f (σ i) • g i ≤ ∑ i in s, f i • g i :=
begin
convert hfg.sum_smul_comp_perm_le_sum_smul
(show {x | σ⁻¹ x ≠ x} ⊆ s, by simp only [set_support_inv_eq, hσ]) using 1,
exact σ.sum_comp' s (λ i j, f i • g j) hσ,
end
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `g`.-/
lemma antivary_on.sum_smul_le_sum_smul_comp_perm (hfg : antivary_on f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f i • g i ≤ ∑ i in s, f i • g (σ i) :=
hfg.dual_right.sum_smul_comp_perm_le_sum_smul hσ
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `f`. -/
lemma antivary_on.sum_smul_le_sum_comp_perm_smul (hfg : antivary_on f g s)
(hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f i • g i ≤ ∑ i in s, f (σ i) • g i :=
hfg.dual_right.sum_comp_perm_smul_le_sum_smul hσ
variables [fintype ι]
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` vary together. Stated by permuting the entries of `g`. -/
lemma monovary.sum_smul_comp_perm_le_sum_smul (hfg : monovary f g) :
∑ i, f i • g (σ i) ≤ ∑ i, f i • g i :=
(hfg.monovary_on _).sum_smul_comp_perm_le_sum_smul $ λ i _, mem_univ _
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when
`f` and `g` vary together. Stated by permuting the entries of `f`. -/
lemma monovary.sum_comp_perm_smul_le_sum_smul (hfg : monovary f g) :
∑ i, f (σ i) • g i ≤ ∑ i, f i • g i :=
(hfg.monovary_on _).sum_comp_perm_smul_le_sum_smul $ λ i _, mem_univ _
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `g`.-/
lemma antivary.sum_smul_le_sum_smul_comp_perm (hfg : antivary f g) :
∑ i, f i • g i ≤ ∑ i, f i • g (σ i) :=
(hfg.antivary_on _).sum_smul_le_sum_smul_comp_perm $ λ i _, mem_univ _
/-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when
`f` and `g` antivary together. Stated by permuting the entries of `f`. -/
lemma antivary.sum_smul_le_sum_comp_perm_smul (hfg : antivary f g) :
∑ i, f i • g i ≤ ∑ i, f (σ i) • g i :=
(hfg.antivary_on _).sum_smul_le_sum_comp_perm_smul $ λ i _, mem_univ _
end smul
/-!
### Multiplication versions
Special cases of the above when scalar multiplication is actually multiplication.
-/
section mul
variables [linear_ordered_ring α] {s : finset ι} {σ : perm ι} {f g : ι → α}
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` vary together. Stated by permuting the entries of `g`. -/
lemma monovary_on.sum_mul_comp_perm_le_sum_mul (hfg : monovary_on f g s) (hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f i * g (σ i) ≤ ∑ i in s, f i * g i :=
hfg.sum_smul_comp_perm_le_sum_smul hσ
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` vary together. Stated by permuting the entries of `f`. -/
lemma monovary_on.sum_comp_perm_mul_le_sum_mul (hfg : monovary_on f g s) (hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f (σ i) * g i ≤ ∑ i in s, f i * g i :=
hfg.sum_comp_perm_smul_le_sum_smul hσ
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `g`.-/
lemma antivary_on.sum_mul_le_sum_mul_comp_perm (hfg : antivary_on f g s) (hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f i * g i ≤ ∑ i in s, f i * g (σ i) :=
hfg.sum_smul_le_sum_smul_comp_perm hσ
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `f`. -/
lemma antivary_on.sum_mul_le_sum_comp_perm_mul (hfg : antivary_on f g s) (hσ : {x | σ x ≠ x} ⊆ s) :
∑ i in s, f i * g i ≤ ∑ i in s, f (σ i) * g i :=
hfg.sum_smul_le_sum_comp_perm_smul hσ
variables [fintype ι]
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` vary together. Stated by permuting the entries of `g`. -/
lemma monovary.sum_mul_comp_perm_le_sum_mul (hfg : monovary f g) :
∑ i, f i * g (σ i) ≤ ∑ i, f i * g i :=
hfg.sum_smul_comp_perm_le_sum_smul
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is maximized when `f` and
`g` vary together. Stated by permuting the entries of `f`. -/
lemma monovary.sum_comp_perm_mul_le_sum_mul (hfg : monovary f g) :
∑ i, f (σ i) * g i ≤ ∑ i, f i * g i :=
hfg.sum_comp_perm_smul_le_sum_smul
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `g`.-/
lemma antivary.sum_mul_le_sum_mul_comp_perm (hfg : antivary f g) :
∑ i, f i * g i ≤ ∑ i, f i * g (σ i) :=
hfg.sum_smul_le_sum_smul_comp_perm
/-- **Rearrangement Inequality**: Pointwise multiplication of `f` and `g` is minimized when `f` and
`g` antivary together. Stated by permuting the entries of `f`. -/
lemma antivary.sum_mul_le_sum_comp_perm_mul (hfg : antivary f g) :
∑ i, f i * g i ≤ ∑ i, f (σ i) * g i :=
hfg.sum_smul_le_sum_comp_perm_smul
end mul
|
79fdddf05a35b089f8209073f6982869fba8f007 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /src/Lean/Compiler/ExternAttr.lean | e053a1bf18a3531874156d93f143f7d6a0c30d5b | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,861 | 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.Expr
import Lean.Environment
import Lean.Attributes
import Lean.ProjFns
import Lean.Meta.Basic
namespace Lean
inductive ExternEntry :=
| adhoc (backend : Name)
| inline (backend : Name) (pattern : String)
| standard (backend : Name) (fn : String)
| foreign (backend : Name) (fn : String)
/-
- `@[extern]`
encoding: ```.entries = [adhoc `all]```
- `@[extern "level_hash"]`
encoding: ```.entries = [standard `all "levelHash"]```
- `@[extern cpp "lean::string_size" llvm "lean_str_size"]`
encoding: ```.entries = [standard `cpp "lean::string_size", standard `llvm "leanStrSize"]```
- `@[extern cpp inline "#1 + #2"]`
encoding: ```.entries = [inline `cpp "#1 + #2"]```
- `@[extern cpp "foo" llvm adhoc]`
encoding: ```.entries = [standard `cpp "foo", adhoc `llvm]```
- `@[extern 2 cpp "io_prim_println"]`
encoding: ```.arity? = 2, .entries = [standard `cpp "ioPrimPrintln"]```
-/
structure ExternAttrData :=
(arity? : Option Nat := none)
(entries : List ExternEntry)
instance : Inhabited ExternAttrData := ⟨{ entries := [] }⟩
private partial def syntaxToExternEntries (a : Array Syntax) (i : Nat) (entries : List ExternEntry) : Except String (List ExternEntry) :=
if i == a.size then Except.ok entries
else match a[i] with
| Syntax.ident _ _ backend _ =>
let i := i + 1
if i == a.size then Except.error "string or identifier expected"
else match a[i].isIdOrAtom? with
| some "adhoc" => syntaxToExternEntries a (i+1) (ExternEntry.adhoc backend :: entries)
| some "inline" =>
let i := i + 1
match a[i].isStrLit? with
| some pattern => syntaxToExternEntries a (i+1) (ExternEntry.inline backend pattern :: entries)
| none => Except.error "string literal expected"
| _ => match a[i].isStrLit? with
| some fn => syntaxToExternEntries a (i+1) (ExternEntry.standard backend fn :: entries)
| none => Except.error "string literal expected"
| _ => Except.error "identifier expected"
private def syntaxToExternAttrData (s : Syntax) : ExceptT String Id ExternAttrData :=
match s with
| Syntax.missing => Except.ok { entries := [ ExternEntry.adhoc `all ] }
| Syntax.node _ args =>
if args.size == 0 then Except.error "unexpected kind of argument"
else
let (arity, i) : Option Nat × Nat := match args[0].isNatLit? with
| some arity => (some arity, 1)
| none => (none, 0)
match args[i].isStrLit? with
| some str =>
if args.size == i+1 then
Except.ok { arity? := arity, entries := [ ExternEntry.standard `all str ] }
else
Except.error "invalid extern attribute"
| none => match syntaxToExternEntries args i [] with
| Except.ok entries => Except.ok { arity? := arity, entries := entries }
| Except.error msg => Except.error msg
| _ => Except.error "unexpected kind of argument"
@[extern "lean_add_extern"]
constant addExtern (env : Environment) (n : Name) : ExceptT String Id Environment
builtin_initialize externAttr : ParametricAttribute ExternAttrData ←
registerParametricAttribute {
name := `extern,
descr := "builtin and foreign functions",
getParam := fun _ stx => ofExcept $ syntaxToExternAttrData stx,
afterSet := fun declName _ => do
let mut env ← getEnv
if env.isProjectionFn declName || env.isConstructor declName then do
env ← ofExcept $ addExtern env declName
setEnv env
else
pure (),
}
@[export lean_get_extern_attr_data]
def getExternAttrData (env : Environment) (n : Name) : Option ExternAttrData :=
externAttr.getParam env n
private def parseOptNum : Nat → String.Iterator → Nat → String.Iterator × Nat
| 0, it, r => (it, r)
| n+1, it, r =>
if !it.hasNext then (it, r)
else
let c := it.curr
if '0' <= c && c <= '9'
then parseOptNum n it.next (r*10 + (c.toNat - '0'.toNat))
else (it, r)
def expandExternPatternAux (args : List String) : Nat → String.Iterator → String → String
| 0, it, r => r
| i+1, it, r =>
if ¬ it.hasNext then r
else let c := it.curr
if c ≠ '#' then expandExternPatternAux args i it.next (r.push c)
else
let it := it.next
let (it, j) := parseOptNum it.remainingBytes it 0
let j := j-1
expandExternPatternAux args i it (r ++ args.getD j "")
def expandExternPattern (pattern : String) (args : List String) : String :=
expandExternPatternAux args pattern.length pattern.mkIterator ""
def mkSimpleFnCall (fn : String) (args : List String) : String :=
fn ++ "(" ++ ((args.intersperse ", ").foldl Append.append "") ++ ")"
def ExternEntry.backend : ExternEntry → Name
| ExternEntry.adhoc n => n
| ExternEntry.inline n _ => n
| ExternEntry.standard n _ => n
| ExternEntry.foreign n _ => n
def getExternEntryForAux (backend : Name) : List ExternEntry → Option ExternEntry
| [] => none
| e::es =>
if e.backend == `all then some e
else if e.backend == backend then some e
else getExternEntryForAux backend es
def getExternEntryFor (d : ExternAttrData) (backend : Name) : Option ExternEntry :=
getExternEntryForAux backend d.entries
def isExtern (env : Environment) (fn : Name) : Bool :=
getExternAttrData env fn |>.isSome
/- We say a Lean function marked as `[extern "<c_fn_nane>"]` is for all backends, and it is implemented using `extern "C"`.
Thus, there is no name mangling. -/
def isExternC (env : Environment) (fn : Name) : Bool :=
match getExternAttrData env fn with
| some { entries := [ ExternEntry.standard `all _ ], .. } => true
| _ => false
def getExternNameFor (env : Environment) (backend : Name) (fn : Name) : Option String := do
let data ← getExternAttrData env fn
let entry ← getExternEntryFor data backend
match entry with
| ExternEntry.standard _ n => pure n
| ExternEntry.foreign _ n => pure n
| _ => failure
def getExternConstArity (declName : Name) : CoreM (Option Nat) := do
let env ← getEnv
match getExternAttrData env declName with
| none => pure none
| some data => match data.arity? with
| some arity => pure arity
| none =>
let cinfo ← getConstInfo declName
let (arity, _) ← (Meta.forallTelescopeReducing cinfo.type fun xs _ => pure xs.size : MetaM Nat).run
pure (some arity)
@[export lean_get_extern_const_arity]
def getExternConstArityExport (env : Environment) (declName : Name) : IO (Option Nat) := do
try
let (arity?, _) ← (getExternConstArity declName).toIO {} { env := env }
pure arity?
catch _ =>
pure none
end Lean
|
88017a83d47ba7e70ba4ebc9bad5ed5d1f5d2358 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/special_functions/trigonometric/basic.lean | 2473599ce5a677655555f664c422084699de1b4a | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 41,758 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.exp
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `π`.
See also `analysis.special_functions.trigonometric.inverse` and
`analysis.special_functions.trigonometric.arctan` for the inverse trigonometric functions.
See also `analysis.special_functions.complex.arg` and
`analysis.special_functions.complex.log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`analysis.special_functions.trigonometric.complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `analysis.special_functions.trigonometric.chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable theory
open_locale classical topology filter
open set filter
namespace complex
@[continuity] lemma continuous_sin : continuous sin :=
by { change continuous (λ z, ((exp (-z * I) - exp (z * I)) * I) / 2), continuity, }
lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on
@[continuity] lemma continuous_cos : continuous cos :=
by { change continuous (λ z, (exp (z * I) + exp (-z * I)) / 2), continuity, }
lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on
@[continuity] lemma continuous_sinh : continuous sinh :=
by { change continuous (λ z, (exp z - exp (-z)) / 2), continuity, }
@[continuity] lemma continuous_cosh : continuous cosh :=
by { change continuous (λ z, (exp z + exp (-z)) / 2), continuity, }
end complex
namespace real
variables {x y z : ℝ}
@[continuity] lemma continuous_sin : continuous sin :=
complex.continuous_re.comp (complex.continuous_sin.comp complex.continuous_of_real)
lemma continuous_on_sin {s} : continuous_on sin s :=
continuous_sin.continuous_on
@[continuity] lemma continuous_cos : continuous cos :=
complex.continuous_re.comp (complex.continuous_cos.comp complex.continuous_of_real)
lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on
@[continuity] lemma continuous_sinh : continuous sinh :=
complex.continuous_re.comp (complex.continuous_sinh.comp complex.continuous_of_real)
@[continuity] lemma continuous_cosh : continuous cosh :=
complex.continuous_re.comp (complex.continuous_cosh.comp complex.continuous_of_real)
end real
namespace real
lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuous_on_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `data.real.pi.bounds`. -/
protected noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation (name := real.pi) `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 :=
by rw [real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : π / 2 ≤ 2 :=
by rw [real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(by rw div_self (two_ne_zero' ℝ); exact one_le_pi_div_two)
lemma pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(calc π / 2 ≤ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_ne_zero : π ≠ 0 :=
ne_of_gt pi_pos
lemma pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * π :=
by linarith [pi_pos]
end real
namespace nnreal
open real
open_locale real nnreal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 := ⟨π, real.pi_pos.le⟩
@[simp] lemma coe_real_pi : (pi : ℝ) = π := rfl
lemma pi_pos : 0 < pi := by exact_mod_cast real.pi_pos
lemma pi_ne_zero : pi ≠ 0 := pi_pos.ne'
end nnreal
namespace real
open_locale real
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left π (two_ne_zero' ℝ), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← mul_div_cancel_left π (two_ne_zero' ℝ), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_antiperiodic : function.antiperiodic sin π :=
by simp [sin_add]
lemma sin_periodic : function.periodic sin (2 * π) :=
sin_antiperiodic.periodic
@[simp] lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
@[simp] lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
@[simp] lemma sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
@[simp] lemma sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
@[simp] lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
@[simp] lemma sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
@[simp] lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
@[simp] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
@[simp] lemma sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
@[simp] lemma sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
@[simp] lemma sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
@[simp] lemma sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
@[simp] lemma sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
@[simp] lemma sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
lemma cos_antiperiodic : function.antiperiodic cos π :=
by simp [cos_add]
lemma cos_periodic : function.periodic cos (2 * π) :=
cos_antiperiodic.periodic
@[simp] lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
@[simp] lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
@[simp] lemma cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
@[simp] lemma cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
@[simp] lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
@[simp] lemma cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
@[simp] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
@[simp] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
@[simp] lemma cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
@[simp] lemma cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
@[simp] lemma cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
@[simp] lemma cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
@[simp] lemma cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
@[simp] lemma cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
@[simp] lemma cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : ℝ) + 2 = 4, from rfl,
have π - x ≤ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
lemma sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x :=
begin
rw ← closure_Ioo pi_ne_zero.symm at hx,
exact closure_lt_subset_le continuous_const continuous_sin
(closure_mono (λ y, sin_pos_of_mem_Ioo) hx)
end
lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
have sin (π / 2) = 1 ∨ sin (π / 2) = -1 :=
by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2),
this.resolve_right
(λ h, (show ¬(0 : ℝ) < -1, by norm_num) $
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
lemma sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = sqrt (1 - cos x ^ 2) :=
by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
lemma cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = sqrt (1 - sin x ^ 2) :=
by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) :
sin x = 0 ↔ x = 0 :=
⟨λ h, le_antisymm
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂
... = 0 : h))
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)),
λ h, by simp [h]⟩
lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (int.sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃,
(sin_pos_of_pos_of_lt_pi h₃ (int.sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
lemma sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x,
sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
(λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [← hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))⟩,
λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩
lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨λ h,
begin
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩,
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁,
norm_cast at hx₁ hx₂,
obtain rfl : n = 0 := le_antisymm (by linarith) (by linarith),
simp
end,
λ h, by simp [h]⟩
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) :
cos y < cos x :=
begin
rw [← sub_lt_zero, cos_sub_cos],
have : 0 < sin ((y + x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
have : 0 < sin ((y - x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
nlinarith,
end
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x :=
match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_mem_Ioo ⟨by linarith, hx⟩)
(λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma strict_anti_on_cos : strict_anti_on cos (Icc 0 π) :=
λ x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strict_anti_on_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
lemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y :=
by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma strict_mono_on_sin : strict_mono_on sin (Icc (-(π / 2)) (π / 2)) :=
λ x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y :=
(strict_mono_on_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
lemma inj_on_sin : inj_on sin (Icc (-(π / 2)) (π / 2)) :=
strict_mono_on_sin.inj_on
lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_anti_on_cos.inj_on
lemma surj_on_sin : surj_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
by simpa only [sin_neg, sin_pi_div_two]
using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on
lemma surj_on_cos : surj_on cos (Icc 0 π) (Icc (-1) 1) :=
by simpa only [cos_zero, cos_pi]
using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on
lemma sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩
lemma cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩
lemma maps_to_sin (s : set ℝ) : maps_to sin s (Icc (-1 : ℝ) 1) := λ x _, sin_mem_Icc x
lemma maps_to_cos (s : set ℝ) : maps_to cos s (Icc (-1 : ℝ) 1) := λ x _, cos_mem_Icc x
lemma bij_on_sin : bij_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨maps_to_sin _, inj_on_sin, surj_on_sin⟩
lemma bij_on_cos : bij_on cos (Icc 0 π) (Icc (-1) 1) :=
⟨maps_to_cos _, inj_on_cos, surj_on_cos⟩
@[simp] lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range
@[simp] lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range
lemma range_cos_infinite : (range real.cos).infinite :=
by { rw real.range_cos, exact Icc_infinite (by norm_num) }
lemma range_sin_infinite : (range real.sin).infinite :=
by { rw real.range_sin, exact Icc_infinite (by norm_num) }
section cos_div_sq
variable (x : ℝ)
/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`
-/
@[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ
| 0 := x
| (n+1) := sqrt (2 + sqrt_two_add_series n)
lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp
lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp
lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp
lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n
| 0 := le_refl 0
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n
| 0 := h
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2
| 0 := by norm_num
| (n+1) :=
begin
refine lt_of_lt_of_le _ (sqrt_sq zero_lt_two.le).le,
rw [sqrt_two_add_series, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'],
{ refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num },
{ exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) }
end
lemma sqrt_two_add_series_succ (x : ℝ) :
∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n
| 0 := rfl
| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]
lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) :
∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n
| 0 := h
| (n+1) :=
begin
rw [sqrt_two_add_series, sqrt_two_add_series],
exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _)
end
@[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (π / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2
| 0 := by simp
| (n+1) :=
begin
have : (2 : ℝ) ≠ 0 := two_ne_zero,
symmetry, rw [div_eq_iff_mul_eq this], symmetry,
rw [sqrt_two_add_series, sqrt_eq_iff_sq_eq, mul_pow, cos_sq, ←mul_div_assoc,
nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul],
congr, { norm_num },
rw [mul_comm, sq, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc,
mul_div_cancel_left]; try { exact this },
apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,
apply le_of_lt, apply cos_pos_of_mem_Ioo ⟨_, _⟩,
{ transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos,
apply div_pos pi_pos, apply pow_pos, norm_num },
apply div_lt_div' (le_refl π) _ pi_pos _,
refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}
end
lemma sin_sq_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_sq, cos_pi_over_two_pow]
lemma sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_sq_pi_over_two_pow, sqrt_two_add_series, div_pow, sq_sqrt, add_div, ←sub_sub],
congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,
end
@[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_eq_iff_sq_eq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul],
{ congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },
{ rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },
apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],
refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,
apply pow_pos, all_goals {norm_num}
end
@[simp] lemma cos_pi_div_four : cos (π / 4) = sqrt 2 / 2 :=
by { transitivity cos (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma sin_pi_div_four : sin (π / 4) = sqrt 2 / 2 :=
by { transitivity sin (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma cos_pi_div_eight : cos (π / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma sin_pi_div_eight : sin (π / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma cos_pi_div_sixteen : cos (π / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma sin_pi_div_sixteen : sin (π / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma cos_pi_div_thirty_two : cos (π / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (π / 2 ^ 5), congr, norm_num, simp }
@[simp] lemma sin_pi_div_thirty_two : sin (π / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (π / 2 ^ 5), congr, norm_num, simp }
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp] lemma cos_pi_div_three : cos (π / 3) = 1 / 2 :=
begin
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0,
{ have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring },
linarith [cos_pi, cos_three_mul (π / 3)] },
cases mul_eq_zero.mp h₁ with h h,
{ linarith [pow_eq_zero h] },
{ have : cos π < cos (π / 3),
{ refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _;
linarith [pi_pos] },
linarith [cos_pi] }
end
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 :=
begin
have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,
{ convert cos_sq (π / 6),
have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms,
rw [h2, cos_pi_div_three] },
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring
end
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp] lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 :=
begin
suffices : sqrt 3 = cos (π / 6) * 2,
{ field_simp [(by norm_num : 0 ≠ 2)], exact this.symm },
rw sqrt_eq_iff_sq_eq,
{ have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr sq_cos_pi_div_six,
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring },
{ norm_num },
{ have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] },
linarith },
end
/-- The sine of `π / 6` is `1 / 2`. -/
@[simp] lemma sin_pi_div_six : sin (π / 6) = 1 / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_three],
congr,
ring
end
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 :=
begin
rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six],
congr,
ring
end
/-- The sine of `π / 3` is `√3 / 2`. -/
@[simp] lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_six],
congr,
ring
end
end cos_div_sq
/-- `real.sin` as an `order_iso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/
def sin_order_iso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1:ℝ) 1 :=
(strict_mono_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq
@[simp] lemma coe_sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
(sin_order_iso x : ℝ) = sin x := rfl
lemma sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
sin_order_iso x = ⟨sin x, sin_mem_Icc x⟩ := rfl
@[simp] lemma tan_pi_div_four : tan (π / 4) = 1 :=
begin
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four],
have h : (sqrt 2) / 2 > 0 := by cancel_denoms,
exact div_self (ne_of_gt h),
end
@[simp] lemma tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos]
lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x :=
by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩)
lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]
| or.inr hx0, _ := by simp [hx0.symm]
end
lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) :
tan x ≤ 0 :=
neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))
lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ}
(hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) :
tan x < tan y :=
begin
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],
exact div_lt_div
(sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy)
(cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩)
end
lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x)
(hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y :=
match le_total x 0, le_total y 0 with
| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact
tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0)
(neg_lt.2 hx₁) (neg_lt_neg hxy)
| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim
(λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁)
... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂)
(λ hy0, by rw [← hy0, tan_zero]; exact
tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁)
| or.inr hx0, or.inl hy0 := by linarith
| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy
end
lemma strict_mono_on_tan : strict_mono_on tan (Ioo (-(π / 2)) (π / 2)) :=
λ x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2
lemma inj_on_tan : inj_on tan (Ioo (-(π / 2)) (π / 2)) :=
strict_mono_on_tan.inj_on
lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y :=
inj_on_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy
lemma tan_periodic : function.periodic tan π :=
by simpa only [function.periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
lemma tan_add_pi (x : ℝ) : tan (x + π) = tan x :=
tan_periodic x
lemma tan_sub_pi (x : ℝ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
lemma tan_pi_sub (x : ℝ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
lemma tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ :=
by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
lemma tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
lemma tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
lemma tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
lemma tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
lemma tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
lemma tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
lemma tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[<] (π/2)) (𝓝 1) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[<] (π/2)) (𝓝[>] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (neg_lt_self pi_div_two_pos))]
with x hx using cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[<] (π/2)) at_top :=
begin
convert tendsto_cos_pi_div_two.inv_tendsto_zero.at_top_mul zero_lt_one
tendsto_sin_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
lemma tendsto_sin_neg_pi_div_two : tendsto sin (𝓝[>] (-(π/2))) (𝓝 (-1)) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[>] (-(π/2))) (𝓝[>] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Ioi (left_mem_Ico.mpr (neg_lt_self pi_div_two_pos))]
with x hx using cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[>] (-(π/2))) at_bot :=
begin
convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.at_top_mul_neg (by norm_num)
tendsto_sin_neg_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
end real
namespace complex
open_locale real
lemma sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp
... = 0 : by simp
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp
... = 1 : by simp
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← of_real_sin, real.sin_pi]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← of_real_cos, real.cos_pi]; simp
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_antiperiodic : function.antiperiodic sin π :=
by simp [sin_add]
lemma sin_periodic : function.periodic sin (2 * π) :=
sin_antiperiodic.periodic
lemma sin_add_pi (x : ℂ) : sin (x + π) = -sin x :=
sin_antiperiodic x
lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x :=
sin_periodic x
lemma sin_sub_pi (x : ℂ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
lemma sin_sub_two_pi (x : ℂ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
lemma sin_two_pi_sub (x : ℂ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
lemma sin_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
lemma sin_add_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
lemma sin_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
lemma sin_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
lemma sin_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
lemma sin_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
lemma cos_antiperiodic : function.antiperiodic cos π :=
by simp [cos_add]
lemma cos_periodic : function.periodic cos (2 * π) :=
cos_antiperiodic.periodic
lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x :=
cos_antiperiodic x
lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x :=
cos_periodic x
lemma cos_sub_pi (x : ℂ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
lemma cos_sub_two_pi (x : ℂ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
lemma cos_two_pi_sub (x : ℂ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
lemma cos_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
lemma cos_add_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
lemma cos_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
lemma cos_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
lemma cos_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
lemma cos_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
lemma cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
lemma cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
lemma cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
lemma sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma tan_periodic : function.periodic tan π :=
by simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
lemma tan_add_pi (x : ℂ) : tan (x + π) = tan x :=
tan_periodic x
lemma tan_sub_pi (x : ℂ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
lemma tan_pi_sub (x : ℂ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
lemma tan_pi_div_two_sub (x : ℂ) : tan (π / 2 - x) = (tan x)⁻¹ :=
by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
lemma tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
lemma tan_add_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
lemma tan_add_int_mul_pi (x : ℂ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
lemma tan_sub_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
lemma tan_sub_int_mul_pi (x : ℂ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
lemma tan_nat_mul_pi_sub (x : ℂ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
lemma tan_int_mul_pi_sub (x : ℂ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
lemma exp_antiperiodic : function.antiperiodic exp (π * I) :=
by simp [exp_add, exp_mul_I]
lemma exp_periodic : function.periodic exp (2 * π * I) :=
(mul_assoc (2:ℂ) π I).symm ▸ exp_antiperiodic.periodic
lemma exp_mul_I_antiperiodic : function.antiperiodic (λ x, exp (x * I)) π :=
by simpa only [mul_inv_cancel_right₀ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero
lemma exp_mul_I_periodic : function.periodic (λ x, exp (x * I)) (2 * π) :=
exp_mul_I_antiperiodic.periodic
@[simp] lemma exp_pi_mul_I : exp (π * I) = -1 :=
exp_zero ▸ exp_antiperiodic.eq
@[simp] lemma exp_two_pi_mul_I : exp (2 * π * I) = 1 :=
exp_periodic.eq.trans exp_zero
@[simp] lemma exp_nat_mul_two_pi_mul_I (n : ℕ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.nat_mul_eq n).trans exp_zero
@[simp] lemma exp_int_mul_two_pi_mul_I (n : ℤ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.int_mul_eq n).trans exp_zero
@[simp] lemma exp_add_pi_mul_I (z : ℂ) : exp (z + π * I) = -exp z :=
exp_antiperiodic z
@[simp] lemma exp_sub_pi_mul_I (z : ℂ) : exp (z - π * I) = -exp z :=
exp_antiperiodic.sub_eq z
/-- A supporting lemma for the **Phragmen-Lindelöf principle** in a horizontal strip. If `z : ℂ`
belongs to a horizontal strip `|complex.im z| ≤ b`, `b ≤ π / 2`, and `a ≤ 0`, then
$$\left|exp^{a\left(e^{z}+e^{-z}\right)}\right| \le e^{a\cos b \exp^{|re z|}}.$$
-/
lemma abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le {a b : ℝ} (ha : a ≤ 0)
{z : ℂ} (hz : |z.im| ≤ b) (hb : b ≤ π / 2) :
abs (exp (a * (exp z + exp (-z)))) ≤ real.exp (a * real.cos b * real.exp (|z.re|)) :=
begin
simp only [abs_exp, real.exp_le_exp, of_real_mul_re, add_re, exp_re, neg_im, real.cos_neg,
← add_mul, mul_assoc, mul_comm (real.cos b), neg_re, ← real.cos_abs z.im],
have : real.exp (|z.re|) ≤ real.exp z.re + real.exp (-z.re),
from apply_abs_le_add_of_nonneg (λ x, (real.exp_pos x).le) z.re,
refine mul_le_mul_of_nonpos_left (mul_le_mul this _ _ ((real.exp_pos _).le.trans this)) ha,
{ exact real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _)
(hb.trans $ half_le_self $ real.pi_pos.le) hz },
{ refine real.cos_nonneg_of_mem_Icc ⟨_, hb⟩,
exact (neg_nonpos.2 $ real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz) }
end
end complex
|
c06797a8e5adb22832577e519f4bac3c410abcbf | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/num.lean | 5c58f8b32b34ccba22ec13b3a8fd86d0cdab5918 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 127 | lean | import data.num
check 10
check 20
check 3
check 1
check 0
check 12
check 13
check 12138
check 1221
check 11
check 5
check 21
|
0b80b6ad8d13a8ddf756ee6b94ac3e387bf583b5 | 4fa161becb8ce7378a709f5992a594764699e268 | /src/algebra/invertible.lean | 01f1b71511f927745e72442011eaa91d6ba9cf18 | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 7,180 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Anne Baanen
A typeclass for the two-sided multiplicative inverse.
-/
import algebra.char_zero
import algebra.char_p
/-!
# Invertible elements
This file defines a typeclass `invertible a` for elements `a` with a
multiplicative inverse.
The intent of the typeclass is to provide a way to write e.g. `⅟2` in a ring
like `ℤ[1/2]` where some inverses exist but there is no general `⁻¹` operator;
or to specify that a field has characteristic `≠ 2`.
It is the `Type`-valued analogue to the `Prop`-valued `is_unit`.
This file also includes some instances of `invertible` for specific numbers in
characteristic zero. Some more cases are given as a `def`, to be included only
when needed. To construct instances for concrete numbers,
`invertible_of_nonzero` is a useful definition.
## Notation
* `⅟a` is `invertible.inv_of a`, the inverse of `a`
## Implementation notes
The `invertible` class lives in `Type`, not `Prop`, to make computation easier.
If multiplication is associative, `invertible` is a subsingleton anyway.
The `simp` normal form tries to normalize `⅟a` to `a ⁻¹`. Otherwise, it pushes
`⅟` inside the expression as much as possible.
## Tags
invertible, inverse element, inv_of, a half, one half, a third, one third, ½, ⅓
-/
universes u
variables {α : Type u}
/-- `invertible a` gives a two-sided multiplicative inverse of `a`. -/
class invertible [has_mul α] [has_one α] (a : α) : Type u :=
(inv_of : α) (inv_of_mul_self : inv_of * a = 1) (mul_inv_of_self : a * inv_of = 1)
-- This notation has the same precedence as `has_inv.inv`.
notation `⅟`:1034 := invertible.inv_of
@[simp]
lemma inv_of_mul_self [has_mul α] [has_one α] (a : α) [invertible a] : ⅟a * a = 1 :=
invertible.inv_of_mul_self
@[simp]
lemma mul_inv_of_self [has_mul α] [has_one α] (a : α) [invertible a] : a * ⅟a = 1 :=
invertible.mul_inv_of_self
@[simp]
lemma mul_inv_of_mul_self_cancel [monoid α] (a b : α) [invertible b] : a * ⅟b * b = a :=
by simp [mul_assoc]
@[simp]
lemma mul_mul_inv_of_self_cancel [monoid α] (a b : α) [invertible b] : a * b * ⅟b = a :=
by simp [mul_assoc]
lemma inv_of_eq_right_inv [monoid α] {a b : α} [invertible a] (hac : a * b = 1) : ⅟a = b :=
left_inv_eq_right_inv (inv_of_mul_self _) hac
instance [monoid α] (a : α) : subsingleton (invertible a) :=
⟨ λ ⟨b, hba, hab⟩ ⟨c, hca, hac⟩, by { congr, exact left_inv_eq_right_inv hba hac } ⟩
lemma is_unit_of_invertible [monoid α] (a : α) [invertible a] : is_unit a :=
⟨⟨a, ⅟a, mul_inv_of_self a, inv_of_mul_self a⟩, rfl⟩
/-- Each element of a group is invertible. -/
def invertible_of_group [group α] (a : α) : invertible a :=
⟨a⁻¹, inv_mul_self a, mul_inv_self a⟩
@[simp] lemma inv_of_eq_group_inv [group α] (a : α) [invertible a] : ⅟a = a⁻¹ :=
inv_of_eq_right_inv (mul_inv_self a)
/-- `1` is the inverse of itself -/
def invertible_one [monoid α] : invertible (1 : α) :=
⟨ 1, mul_one _, one_mul _ ⟩
@[simp] lemma inv_of_one [monoid α] [invertible (1 : α)] : ⅟(1 : α) = 1 :=
inv_of_eq_right_inv (mul_one _)
/-- `-⅟a` is the inverse of `-a` -/
def invertible_neg [ring α] (a : α) [invertible a] : invertible (-a) :=
⟨ -⅟a, by simp, by simp ⟩
@[simp] lemma inv_of_neg [ring α] (a : α) [invertible a] [invertible (-a)] : ⅟(-a) = -⅟a :=
inv_of_eq_right_inv (by simp)
/-- `a` is the inverse of `⅟a`. -/
def invertible_inv_of [has_one α] [has_mul α] {a : α} [invertible a] : invertible (⅟a) :=
⟨ a, mul_inv_of_self a, inv_of_mul_self a ⟩
@[simp] lemma inv_of_inv_of [monoid α] {a : α} [invertible a] [invertible (⅟a)] :
⅟(⅟a) = a :=
inv_of_eq_right_inv (inv_of_mul_self _)
/-- `⅟b * ⅟a` is the inverse of `a * b` -/
def invertible_mul [monoid α] (a b : α) [invertible a] [invertible b] : invertible (a * b) :=
⟨ ⅟b * ⅟a, by simp [←mul_assoc], by simp [←mul_assoc] ⟩
@[simp]
lemma inv_of_mul [monoid α] (a b : α) [invertible a] [invertible b] [invertible (a * b)] :
⅟(a * b) = ⅟b * ⅟a :=
inv_of_eq_right_inv (by simp [←mul_assoc])
section group_with_zero
variable [group_with_zero α]
lemma nonzero_of_invertible (a : α) [invertible a] : a ≠ 0 :=
λ ha, zero_ne_one $ calc 0 = ⅟a * a : by simp [ha]
... = 1 : inv_of_mul_self a
/-- `a⁻¹` is an inverse of `a` if `a ≠ 0` -/
def invertible_of_nonzero {a : α} (h : a ≠ 0) : invertible a :=
⟨ a⁻¹, inv_mul_cancel h, mul_inv_cancel h ⟩
@[simp] lemma inv_of_eq_inv (a : α) [invertible a] : ⅟a = a⁻¹ :=
inv_of_eq_right_inv (mul_inv_cancel (nonzero_of_invertible a))
@[simp] lemma inv_mul_cancel_of_invertible (a : α) [invertible a] : a⁻¹ * a = 1 :=
inv_mul_cancel (nonzero_of_invertible a)
@[simp] lemma mul_inv_cancel_of_invertible (a : α) [invertible a] : a * a⁻¹ = 1 :=
mul_inv_cancel (nonzero_of_invertible a)
@[simp] lemma div_mul_cancel_of_invertible (a b : α) [invertible b] : a / b * b = a :=
div_mul_cancel a (nonzero_of_invertible b)
@[simp] lemma mul_div_cancel_of_invertible (a b : α) [invertible b] : a * b / b = a :=
mul_div_cancel a (nonzero_of_invertible b)
@[simp] lemma div_self_of_invertible (a : α) [invertible a] : a / a = 1 :=
div_self (nonzero_of_invertible a)
/-- `b / a` is the inverse of `a / b` -/
def invertible_div (a b : α) [invertible a] [invertible b] : invertible (a / b) :=
⟨b / a, by simp [←mul_div_assoc], by simp [←mul_div_assoc]⟩
@[simp] lemma inv_of_div (a b : α) [invertible a] [invertible b] [invertible (a / b)] :
⅟(a / b) = b / a :=
inv_of_eq_right_inv (by simp [←mul_div_assoc])
/-- `a` is the inverse of `a⁻¹` -/
def invertible_inv {a : α} [invertible a] : invertible (a⁻¹) :=
⟨ a, by simp, by simp ⟩
end group_with_zero
section ring_char
/-- A natural number `t` is invertible in a field `K` if the charactistic of `K` does not divide `t`. -/
def invertible_of_ring_char_not_dvd {K : Type*} [field K]
{t : ℕ} (not_dvd : ¬(ring_char K ∣ t)) : invertible (t : K) :=
invertible_of_nonzero (λ h, not_dvd ((ring_char.spec K t).mp h))
end ring_char
section char_p
/-- A natural number `t` is invertible in a field `K` of charactistic `p` if `p` does not divide `t`. -/
def invertible_of_char_p_not_dvd {K : Type*} [field K] {p : ℕ} [char_p K p]
{t : ℕ} (not_dvd : ¬(p ∣ t)) : invertible (t : K) :=
invertible_of_nonzero (λ h, not_dvd ((char_p.cast_eq_zero_iff K p t).mp h))
end char_p
section division_ring
variable [division_ring α]
instance invertible_succ [char_zero α] (n : ℕ) : invertible (n.succ : α) :=
invertible_of_nonzero (nat.cast_ne_zero.mpr (nat.succ_ne_zero _))
/-!
A few `invertible n` instances for small numerals `n`. Feel free to add your own
number when you need its inverse.
-/
instance invertible_two [char_zero α] : invertible (2 : α) :=
invertible_of_nonzero (by exact_mod_cast (dec_trivial : 2 ≠ 0))
instance invertible_three [char_zero α] : invertible (3 : α) :=
invertible_of_nonzero (by exact_mod_cast (dec_trivial : 3 ≠ 0))
end division_ring
|
3f7b2aa28e5983e7aca5a571616567d4af645158 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/topology/algebra/ring.lean | d2b61d1e2c0155e4aac5ebf0da0840913f3eec21 | [
"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 | 4,351 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
Theory of topological rings.
-/
import topology.algebra.group
import ring_theory.ideal.basic
open classical set filter topological_space
open_locale classical
section topological_ring
universes u v w
variables (α : Type u) [topological_space α]
/-- A topological semiring is a semiring where addition and multiplication are continuous. -/
class topological_semiring [semiring α]
extends has_continuous_add α, has_continuous_mul α : Prop
variables [ring α]
/-- A topological ring is a ring where the ring operations are continuous. -/
class topological_ring extends has_continuous_add α, has_continuous_mul α : Prop :=
(continuous_neg : continuous (λa:α, -a))
variables [t : topological_ring α]
@[priority 100] -- see Note [lower instance priority]
instance topological_ring.to_topological_semiring : topological_semiring α := {..t}
@[priority 100] -- see Note [lower instance priority]
instance topological_ring.to_topological_add_group : topological_add_group α := {..t}
variables {α} [topological_ring α]
/-- In a topological ring, the left-multiplication `add_monoid_hom` is continuous. -/
lemma mul_left_continuous (x : α) : continuous (add_monoid_hom.mul_left x) :=
continuous_const.mul continuous_id
/-- In a topological ring, the right-multiplication `add_monoid_hom` is continuous. -/
lemma mul_right_continuous (x : α) : continuous (add_monoid_hom.mul_right x) :=
continuous_id.mul continuous_const
end topological_ring
section topological_comm_ring
variables {α : Type*} [topological_space α] [comm_ring α] [topological_ring α]
/-- The closure of an ideal in a topological ring as an ideal. -/
def ideal.closure (S : ideal α) : ideal α :=
{ carrier := closure S,
zero_mem' := subset_closure S.zero_mem,
add_mem' := assume x y hx hy,
mem_closure2 continuous_add hx hy $ assume a b, S.add_mem,
smul_mem' := assume c x hx,
have continuous (λx:α, c * x) := continuous_const.mul continuous_id,
mem_closure this hx $ assume a, S.mul_mem_left }
@[simp] lemma ideal.coe_closure (S : ideal α) :
(S.closure : set α) = closure S := rfl
end topological_comm_ring
section topological_ring
variables {α : Type*} [topological_space α] [comm_ring α] (N : ideal α)
open ideal.quotient
instance topological_ring_quotient_topology : topological_space N.quotient :=
by dunfold ideal.quotient submodule.quotient; apply_instance
lemma quotient_ring_saturate {α : Type*} [comm_ring α] (N : ideal α) (s : set α) :
mk N ⁻¹' (mk N '' s) = (⋃ x : N, (λ y, x.1 + y) '' s) :=
begin
ext x,
simp only [mem_preimage, mem_image, mem_Union, ideal.quotient.eq],
split,
{ exact assume ⟨a, a_in, h⟩, ⟨⟨_, N.neg_mem h⟩, a, a_in, by simp⟩ },
{ exact assume ⟨⟨i, hi⟩, a, ha, eq⟩, ⟨a, ha,
by rw [← eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub];
exact N.neg_mem hi⟩ }
end
variable [topological_ring α]
lemma quotient_ring.is_open_map_coe : is_open_map (mk N) :=
begin
assume s s_op,
show is_open (mk N ⁻¹' (mk N '' s)),
rw quotient_ring_saturate N s,
exact is_open_Union (assume ⟨n, _⟩, is_open_map_add_left n s s_op)
end
lemma quotient_ring.quotient_map_coe_coe : quotient_map (λ p : α × α, (mk N p.1, mk N p.2)) :=
begin
apply is_open_map.to_quotient_map,
{ exact (quotient_ring.is_open_map_coe N).prod (quotient_ring.is_open_map_coe N) },
{ exact (continuous_quot_mk.comp continuous_fst).prod_mk
(continuous_quot_mk.comp continuous_snd) },
{ rintro ⟨⟨x⟩, ⟨y⟩⟩,
exact ⟨(x, y), rfl⟩ }
end
instance topological_ring_quotient : topological_ring N.quotient :=
{ continuous_add :=
have cont : continuous (mk N ∘ (λ (p : α × α), p.fst + p.snd)) :=
continuous_quot_mk.comp continuous_add,
(quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).2 cont,
continuous_neg := continuous_quotient_lift _ (continuous_quot_mk.comp continuous_neg),
continuous_mul :=
have cont : continuous (mk N ∘ (λ (p : α × α), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul,
(quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).2 cont }
end topological_ring
|
0ee0bc4cec9646bcb22909417dcf2718f1446e8a | f3a5af2927397cf346ec0e24312bfff077f00425 | /src/game/world3/level4.lean | 5cd6b6e53676d2e1f8a2144aef8bd7cabc1f62b0 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/natural_number_game | 05c39e1586408cfb563d1a12e1085a90726ab655 | f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd | refs/heads/master | 1,688,570,964,990 | 1,636,908,242,000 | 1,636,908,242,000 | 195,403,790 | 277 | 84 | Apache-2.0 | 1,694,547,955,000 | 1,562,328,792,000 | Lean | UTF-8 | Lean | false | false | 1,389 | lean | import game.world3.level3 -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 4: `mul_add`
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 "left distributivity of
multiplication over addition" (there is also right distributivity,
which we'll get to later).
Note the name of this proof -- `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 "left_distrib",
an alternative name for the proof of this lemma.
-/
/- 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 [nat_num_game]
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 -- the "proper" name for this lemma
-- I just don't instinctively know what left_distrib means -- hide
end mynat -- hide
|
e4a2b61c053adcfe284d555fe72aef29dd9e4126 | fecda8e6b848337561d6467a1e30cf23176d6ad0 | /src/ring_theory/principal_ideal_domain.lean | e01f0b707c2769cc173565c0c6a7d5f020345f56 | [
"Apache-2.0"
] | permissive | spolu/mathlib | bacf18c3d2a561d00ecdc9413187729dd1f705ed | 480c92cdfe1cf3c2d083abded87e82162e8814f4 | refs/heads/master | 1,671,684,094,325 | 1,600,736,045,000 | 1,600,736,045,000 | 297,564,749 | 1 | 0 | null | 1,600,758,368,000 | 1,600,758,367,000 | null | UTF-8 | Lean | false | false | 9,324 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Chris Hughes, Morenikeji Neri
-/
import ring_theory.noetherian
import ring_theory.unique_factorization_domain
/-!
# Principal ideal rings and principal ideal domains
A principal ideal ring (PIR) is a commutative ring in which all ideals are principal. A
principal ideal domain (PID) is an integral domain which is a principal ideal ring.
# Main definitions
Note that for principal ideal domains, one should use
`[integral domain R] [is_principal_ideal_ring R]`. There is no explicit definition of a PID.
Theorems about PID's are in the `principal_ideal_ring` namespace.
- `is_principal_ideal_ring`: a predicate on commutative rings, saying that every
ideal is principal.
- `generator`: a generator of a principal ideal (or more generally submodule)
- `to_unique_factorization_domain`: a noncomputable definition, putting a UFD structure on a PID.
Note that the definition of a UFD is currently not a predicate, as it contains data
of factorizations of non-zero elements.
# Main results
- `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.
- `euclidean_domain.to_principal_ideal_domain` : a Euclidean domain is a PID.
-/
universes u v
variables {R : Type u} {M : Type v}
open set function
open submodule
open_locale classical
/-- An `R`-submodule of `M` is principal if it is generated by one element. -/
class submodule.is_principal [ring R] [add_comm_group M] [module R M] (S : submodule R M) : Prop :=
(principal [] : ∃ a, S = span R {a})
/-- A commutative ring is a principal ideal ring if all ideals are principal. -/
class is_principal_ideal_ring (R : Type u) [comm_ring R] : Prop :=
(principal : ∀ (S : ideal R), S.is_principal)
attribute [instance] is_principal_ideal_ring.principal
namespace submodule.is_principal
variables [comm_ring R] [add_comm_group M] [module R M]
/-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/
noncomputable def generator (S : submodule R M) [S.is_principal] : M :=
classical.some (principal S)
lemma span_singleton_generator (S : submodule R M) [S.is_principal] : span R {generator S} = S :=
eq.symm (classical.some_spec (principal S))
@[simp] lemma generator_mem (S : submodule R M) [S.is_principal] : generator S ∈ S :=
by { conv_rhs { rw ← span_singleton_generator S }, exact subset_span (mem_singleton _) }
lemma mem_iff_eq_smul_generator (S : submodule R M) [S.is_principal] {x : M} :
x ∈ S ↔ ∃ s : R, x = s • generator S :=
by simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator]
lemma mem_iff_generator_dvd (S : ideal R) [S.is_principal] {x : R} : x ∈ S ↔ generator S ∣ x :=
(mem_iff_eq_smul_generator S).trans (exists_congr (λ a, by simp only [mul_comm, smul_eq_mul]))
lemma eq_bot_iff_generator_eq_zero (S : submodule R M) [S.is_principal] :
S = ⊥ ↔ generator S = 0 :=
by rw [← @span_singleton_eq_bot R M, span_singleton_generator]
end submodule.is_principal
namespace is_prime
open submodule.is_principal ideal
-- TODO -- for a non-ID one could perhaps prove that if p < q are prime then q maximal;
-- 0 isn't prime in a non-ID PIR but the Krull dimension is still <= 1.
-- The below result follows from this, but we could also use the below result to
-- prove this (quotient out by p).
lemma to_maximal_ideal [integral_domain R] [is_principal_ideal_ring R] {S : ideal R}
[hpi : is_prime S] (hS : S ≠ ⊥) : is_maximal S :=
is_maximal_iff.2 ⟨(ne_top_iff_one S).1 hpi.1, begin
assume T x hST hxS hxT,
cases (mem_iff_generator_dvd _).1 (hST $ generator_mem S) with z hz,
cases hpi.2 (show generator T * z ∈ S, from hz ▸ generator_mem S),
{ have hTS : T ≤ S, rwa [← span_singleton_generator T, submodule.span_le, singleton_subset_iff],
exact (hxS $ hTS hxT).elim },
cases (mem_iff_generator_dvd _).1 h with y hy,
have : generator S ≠ 0 := mt (eq_bot_iff_generator_eq_zero _).2 hS,
rw [← mul_one (generator S), hy, mul_left_comm, mul_right_inj' this] at hz,
exact hz.symm ▸ ideal.mul_mem_right _ (generator_mem T)
end⟩
end is_prime
section
open euclidean_domain
variable [euclidean_domain R]
lemma mod_mem_iff {S : ideal R} {x y : R} (hy : y ∈ S) : x % y ∈ S ↔ x ∈ S :=
⟨λ hxy, div_add_mod x y ▸ ideal.add_mem S (ideal.mul_mem_right S hy) hxy,
λ hx, (mod_eq_sub_mul_div x y).symm ▸ ideal.sub_mem S hx (ideal.mul_mem_right S hy)⟩
@[priority 100] -- see Note [lower instance priority]
instance euclidean_domain.to_principal_ideal_domain : is_principal_ideal_ring R :=
{ principal := λ S, by exactI
⟨if h : {x : R | x ∈ S ∧ x ≠ 0}.nonempty
then
have wf : well_founded (euclidean_domain.r : R → R → Prop) := euclidean_domain.r_well_founded,
have hmin : well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h ∈ S ∧
well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h ≠ 0,
from well_founded.min_mem wf {x : R | x ∈ S ∧ x ≠ 0} h,
⟨well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h,
submodule.ext $ λ x,
⟨λ hx, div_add_mod x (well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h) ▸
(ideal.mem_span_singleton.2 $ dvd_add (dvd_mul_right _ _) $
have (x % (well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h) ∉ {x : R | x ∈ S ∧ x ≠ 0}),
from λ h₁, well_founded.not_lt_min wf _ h h₁ (mod_lt x hmin.2),
have x % well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h = 0, by finish [(mod_mem_iff hmin.1).2 hx],
by simp *),
λ hx, let ⟨y, hy⟩ := ideal.mem_span_singleton.1 hx in hy.symm ▸ ideal.mul_mem_right _ hmin.1⟩⟩
else ⟨0, submodule.ext $ λ a, by rw [← @submodule.bot_coe R R _ _ _, span_eq, submodule.mem_bot]; exact
⟨λ haS, by_contradiction $ λ ha0, h ⟨a, ⟨haS, ha0⟩⟩,
λ h₁, h₁.symm ▸ S.zero_mem⟩⟩⟩ }
end
namespace principal_ideal_ring
open is_principal_ideal_ring
variables [integral_domain R] [is_principal_ideal_ring R]
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian_ring : is_noetherian_ring R :=
⟨assume s : ideal R,
begin
rcases (is_principal_ideal_ring.principal s).principal with ⟨a, rfl⟩,
rw [← finset.coe_singleton],
exact ⟨{a}, submodule.coe_injective rfl⟩
end⟩
lemma is_maximal_of_irreducible {p : R} (hp : irreducible p) :
ideal.is_maximal (span R ({p} : set R)) :=
⟨mt ideal.span_singleton_eq_top.1 hp.1, λ I hI, begin
rcases principal I with ⟨a, rfl⟩,
erw ideal.span_singleton_eq_top,
unfreezingI { rcases ideal.span_singleton_le_span_singleton.1 (le_of_lt hI) with ⟨b, rfl⟩ },
refine (of_irreducible_mul hp).resolve_right (mt (λ hb, _) (not_le_of_lt hI)),
erw [ideal.span_singleton_le_span_singleton, is_unit.mul_right_dvd hb]
end⟩
lemma irreducible_iff_prime {p : R} : irreducible p ↔ prime p :=
⟨λ hp, (ideal.span_singleton_prime hp.ne_zero).1 $
(is_maximal_of_irreducible hp).is_prime,
irreducible_of_prime⟩
lemma associates_irreducible_iff_prime : ∀{p : associates R}, irreducible p ↔ prime p :=
associates.irreducible_iff_prime_iff.1 (λ _, irreducible_iff_prime)
section
open_locale classical
/-- `factors a` is a multiset of irreducible elements whose product is `a`, up to units -/
noncomputable def factors (a : R) : multiset R :=
if h : a = 0 then ∅ else classical.some (wf_dvd_monoid.exists_factors a h)
lemma factors_spec (a : R) (h : a ≠ 0) :
(∀b∈factors a, irreducible b) ∧ associated a (factors a).prod :=
begin
unfold factors, rw [dif_neg h],
exact classical.some_spec (wf_dvd_monoid.exists_factors a h)
end
lemma ne_zero_of_mem_factors {R : Type v} [integral_domain R] [is_principal_ideal_ring R] {a b : R}
(ha : a ≠ 0) (hb : b ∈ factors a) : b ≠ 0 := irreducible.ne_zero ((factors_spec a ha).1 b hb)
lemma mem_submonoid_of_factors_subset_of_units_subset (s : submonoid R)
{a : R} (ha : a ≠ 0) (hfac : ∀ b ∈ factors a, b ∈ s) (hunit : ∀ c : units R, (c : R) ∈ s) :
a ∈ s :=
begin
rcases ((factors_spec a ha).2).symm with ⟨c, hc⟩,
rw [← hc],
exact submonoid.mul_mem _ (submonoid.multiset_prod_mem _ _ hfac) (hunit _),
end
/-- If a `ring_hom` maps all units and all factors of an element `a` into a submonoid `s`, then it
also maps `a` into that submonoid. -/
lemma ring_hom_mem_submonoid_of_factors_subset_of_units_subset {R S : Type*}
[integral_domain R] [is_principal_ideal_ring R] [semiring S]
(f : R →+* S) (s : submonoid S) (a : R) (ha : a ≠ 0)
(h : ∀ b ∈ factors a, f b ∈ s) (hf: ∀ c : units R, f c ∈ s) :
f a ∈ s :=
mem_submonoid_of_factors_subset_of_units_subset (s.comap f.to_monoid_hom) ha h hf
/-- The unique factorization domain structure given by the principal ideal domain.
This is not added as type class instance, since the `factors` might be computed in a different way.
E.g. factors could return normalized values.
-/
noncomputable def to_unique_factorization_domain : unique_factorization_domain R :=
{ factors := factors,
factors_prod := assume a ha, associated.symm (factors_spec a ha).2,
prime_factors := assume a ha, by simpa [irreducible_iff_prime] using (factors_spec a ha).1 }
end
end principal_ideal_ring
|
368f412073d9e2221b9ee7faf1a60418bc9bc5a7 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/data/set/intervals/disjoint.lean | 7233e21e48990dbd4a28d2fb8b8b7d697376f14f | [
"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 | 2,134 | lean | /-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yury Kudryashov
-/
import data.set.lattice
/-!
# Extra lemmas about intervals
This file contains lemmas about intervals that cannot be included into `data.set.intervals.basic`
because this would create an `import` cycle. Namely, lemmas in this file can use definitions
from `data.set.lattice`, including `disjoint`.
-/
universe u
variables {α : Type u}
namespace set
section preorder
variables [preorder α] {a b c : α}
@[simp] lemma Iic_disjoint_Ioi (h : a ≤ b) : disjoint (Iic a) (Ioi b) :=
λ x ⟨ha, hb⟩, not_le_of_lt (h.trans_lt hb) ha
@[simp] lemma Iic_disjoint_Ioc (h : a ≤ b) : disjoint (Iic a) (Ioc b c) :=
(Iic_disjoint_Ioi h).mono (le_refl _) (λ _, and.left)
@[simp] lemma Ioc_disjoint_Ioc_same {a b c : α} : disjoint (Ioc a b) (Ioc b c) :=
(Iic_disjoint_Ioc (le_refl b)).mono (λ _, and.right) (le_refl _)
@[simp] lemma Ico_disjoint_Ico_same {a b c : α} : disjoint (Ico a b) (Ico b c) :=
λ x hx, not_le_of_lt hx.1.2 hx.2.1
end preorder
section linear_order
variables [linear_order α] {a₁ a₂ b₁ b₂ : α}
@[simp] lemma Ico_disjoint_Ico : disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ :=
by simp_rw [set.disjoint_iff_inter_eq_empty, Ico_inter_Ico, Ico_eq_empty_iff,
inf_eq_min, sup_eq_max, not_lt]
@[simp] lemma Ioc_disjoint_Ioc : disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ :=
by simpa only [dual_Ico] using @Ico_disjoint_Ico (order_dual α) _ a₂ a₁ b₂ b₁
/-- If two half-open intervals are disjoint and the endpoint of one lies in the other,
then it must be equal to the endpoint of the other. -/
lemma eq_of_Ico_disjoint {x₁ x₂ y₁ y₂ : α}
(h : disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂) (h2 : x₂ ∈ Ico y₁ y₂) :
y₁ = x₂ :=
begin
rw [Ico_disjoint_Ico, min_eq_left (le_of_lt h2.2), le_max_iff] at h,
apply le_antisymm h2.1,
exact h.elim (λ h, absurd hx (not_lt_of_le h)) id
end
end linear_order
end set
|
10461518feab0475db6e8dd5a4e82e3b67ab0834 | dfd42d30132c2867977fefe7edae98b6dc703aeb | /src/conformal.lean | be1bcfb7697ad703259a408ff4eadf5bd138852f | [] | 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 | 7,305 | lean | import analysis.normed_space.conformal_linear_map
import complex_conformal_prep
/-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang
-/
/-!
# Complex Conformal Maps
We prove the sufficient and necessary conditions for a complex function to be conformal.
## Main results
* `is_complex_or_conj_complex_linear_iff_is_conformal_map`: the main theorem for linear maps.
* `conformal_at_iff_holomorphic_or_antiholomorphic_at`: the main theorem for complex functions.
## Warning
Antiholomorphic functions such as the complex conjugate are considered as conformal functions in
this file.
-/
noncomputable theory
open complex linear_isometry linear_isometry_equiv continuous_linear_map
finite_dimensional linear_map
section complex_normed_space
variables {E : Type*} [normed_group E] [normed_space ℝ E] [normed_space ℂ E]
[is_scalar_tower ℝ ℂ E] {z : ℂ} {g : ℂ →L[ℝ] E} {f : ℂ → E}
lemma is_conformal_map_of_eq_complex_linear (nonzero : g ≠ 0)
(H : ∃ (map : ℂ →L[ℂ] E), map.restrict_scalars ℝ = g) : is_conformal_map g :=
begin
rcases H with ⟨map, h⟩,
have minor₀ : ∀ x, g x = x • g 1,
{ intro x,
nth_rewrite 0 ← mul_one x,
rw [← smul_eq_mul, ← h, coe_restrict_scalars', map.map_smul], },
have minor₁ : ∥g 1∥ ≠ 0,
{ contrapose! nonzero with w,
ext1 x,
rw [continuous_linear_map.zero_apply, minor₀ x, norm_eq_zero.mp w, smul_zero], },
refine ⟨∥g 1∥, minor₁, _⟩,
let li' := ∥g 1∥⁻¹ • g,
have key : ∀ (x : ℂ), ∥li' x∥ = ∥x∥,
{ intros x,
simp only [li', continuous_linear_map.smul_apply, minor₀ x,
norm_smul, normed_field.norm_inv, norm_norm],
field_simp [minor₁], },
let li : ℂ →ₗᵢ[ℝ] E := ⟨li', key⟩,
have minor₂ : (li : ℂ → E) = li' := rfl,
refine ⟨li, _⟩,
ext1,
simp only [minor₂, li', pi.smul_apply, continuous_linear_map.smul_apply, smul_smul],
field_simp [minor₁],
end
lemma is_conformal_map_of_eq_linear_conj (nonzero : g ≠ 0)
(h : ∃ (map : ℂ →L[ℂ] E), map.restrict_scalars ℝ = g.comp conj_cle.to_continuous_linear_map) :
is_conformal_map g :=
begin
have nonzero' : g.comp conj_cle.to_continuous_linear_map ≠ 0,
{ contrapose! nonzero with w,
simp only [continuous_linear_map.ext_iff, continuous_linear_map.zero_apply,
continuous_linear_map.coe_comp', function.comp_app,
continuous_linear_equiv.coe_def_rev, continuous_linear_equiv.coe_apply,
conj_cle_apply] at w,
ext1,
rw [← conj_conj x, w, continuous_linear_map.zero_apply], },
rcases is_conformal_map_of_eq_complex_linear nonzero' h with ⟨c, hc, li, hg'⟩,
refine ⟨c, hc, li.comp conj_lie.to_linear_isometry, _⟩,
have key : (g : ℂ → E) = (c • li) ∘ conj_lie,
{ rw ← hg',
funext,
simp only [continuous_linear_map.coe_comp',function.comp_app,
continuous_linear_equiv.coe_def_rev, continuous_linear_equiv.coe_apply,
conj_lie_apply, conj_cle_apply, conj_conj], },
funext,
simp only [conj_cle_apply, pi.smul_apply,
linear_isometry.coe_comp, coe_to_linear_isometry],
rw [key, function.comp_app, pi.smul_apply],
end
/-- A real differentiable function of the complex plane into some complex normed space `E` is
conformal at a point `z` if it is holomorphic or antiholomorphic at that point -/
lemma conformal_at_of_holomorph_or_antiholomorph_at_aux
(hf : differentiable_at ℝ f z) (hf' : fderiv ℝ f z ≠ 0)
(h : differentiable_at ℂ f z ∨ differentiable_at ℂ (f ∘ conj) (conj z)) :
conformal_at f z :=
begin
rw [conformal_at_iff_is_conformal_map_fderiv],
rw [differentiable_at_iff_exists_linear_map hf,
antiholomorph_at_iff_exists_complex_linear_conj hf] at h,
cases h,
{ exact is_conformal_map_of_eq_complex_linear hf' h, },
{ exact is_conformal_map_of_eq_linear_conj hf' h, },
end
end complex_normed_space
section complex_conformal_linear_map
variables {f : ℂ → ℂ} {z : ℂ} {g : ℂ →L[ℝ] ℂ}
lemma is_complex_or_conj_complex_linear (h : is_conformal_map g) :
(∃ (map : ℂ →L[ℂ] ℂ), map.restrict_scalars ℝ = g) ∨
(∃ (map : ℂ →L[ℂ] ℂ), map.restrict_scalars ℝ = g.comp conj_cle.to_continuous_linear_map) :=
begin
rcases h with ⟨c, hc, li, hg⟩,
rcases linear_isometry_complex (li.to_linear_isometry_equiv rfl) with ⟨a, ha⟩,
cases ha,
{ refine or.intro_left _ ⟨c • rotation_clm a, _⟩,
ext1,
simp only [coe_restrict_scalars', continuous_linear_map.smul_apply, coe_rotation_clm, ← ha,
li.coe_to_linear_isometry_equiv, hg, pi.smul_apply], },
{ let map := c • (rotation_clm a),
refine or.intro_right _ ⟨map, _⟩,
ext1,
rw [continuous_linear_map.coe_comp', hg, ← li.coe_to_linear_isometry_equiv, ha],
simp only [coe_restrict_scalars', function.comp_app, pi.smul_apply,
linear_isometry_equiv.coe_trans, conj_lie_apply,
rotation_apply, map, continuous_linear_equiv.coe_def_rev,
continuous_linear_equiv.coe_apply, conj_cle_apply],
simp only [smul_coe, smul_eq_mul, function.comp_app, continuous_linear_map.smul_apply,
rotation_clm_apply, linear_map.coe_to_continuous_linear_map',
rotation_apply, conj.map_mul, conj_conj], },
end
/-- A real continuous linear map on the complex plane is conformal if and only if the map or its
conjugate is complex linear, and the map is nonvanishing. -/
lemma is_complex_or_conj_complex_linear_iff_is_conformal_map :
((∃ (map : ℂ →L[ℂ] ℂ), map.restrict_scalars ℝ = g) ∨
(∃ (map : ℂ →L[ℂ] ℂ), map.restrict_scalars ℝ = g.comp conj_cle.to_continuous_linear_map))
∧ g ≠ 0 ↔ is_conformal_map g :=
iff.intro
(λ h, h.1.rec_on
(is_conformal_map_of_eq_complex_linear h.2)
$ is_conformal_map_of_eq_linear_conj h.2)
(λ h, ⟨is_complex_or_conj_complex_linear h, h.ne_zero⟩)
end complex_conformal_linear_map
section complex_conformal_map
variables {f : ℂ → ℂ} {z : ℂ}
lemma conformal_at_iff_holomorphic_or_antiholomorph_at_aux (hf : differentiable_at ℝ f z) :
conformal_at f z ↔
(differentiable_at ℂ f z ∨ differentiable_at ℂ (f ∘ conj) (conj z)) ∧ fderiv ℝ f z ≠ 0 :=
by rw [conformal_at_iff_is_conformal_map_fderiv,
← is_complex_or_conj_complex_linear_iff_is_conformal_map,
differentiable_at_iff_exists_linear_map hf,
antiholomorph_at_iff_exists_complex_linear_conj hf]
/-- A complex function is conformal if and only if the function is holomorphic or antiholomorphic
with a nonvanishing differential. -/
lemma conformal_at_iff_holomorphic_or_antiholomorphic_at :
conformal_at f z ↔
(differentiable_at ℂ f z ∨ differentiable_at ℂ (f ∘ conj) (conj z)) ∧ fderiv ℝ f z ≠ 0 :=
iff.intro
(λ h, (conformal_at_iff_holomorphic_or_antiholomorph_at_aux h.differentiable_at).mp h)
(λ h, by
{ have : differentiable_at ℝ f z :=
by_contra (λ w, h.2 $ fderiv_zero_of_not_differentiable_at w),
exact (conformal_at_iff_holomorphic_or_antiholomorph_at_aux this).mpr h, } )
end complex_conformal_map |
9b0a97bc4e3136b22e1f3925a73ac539904c68c8 | 367134ba5a65885e863bdc4507601606690974c1 | /src/analysis/special_functions/trigonometric.lean | bf7a056d42c5cd59e02594191204c6e98802a434 | [
"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 | 139,217 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.exp_log
import data.set.intervals.infinite
import algebra.quadratic_discriminant
import ring_theory.polynomial.chebyshev
import analysis.calculus.times_cont_diff
/-!
# Trigonometric functions
## Main definitions
This file contains the following definitions:
* π, arcsin, arccos, arctan
* argument of a complex number
* logarithm on complex numbers
## Main statements
Many basic inequalities on trigonometric functions are established.
The continuity and differentiability of the usual trigonometric functions are proved, and their
derivatives are computed.
* `polynomial.chebyshev.T_complex_cos`: the `n`-th Chebyshev polynomial evaluates on `complex.cos θ`
to the value `n * complex.cos θ`.
## Tags
log, sin, cos, tan, arcsin, arccos, arctan, angle, argument
-/
noncomputable theory
open_locale classical topological_space filter
open set filter
namespace complex
/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/
lemma has_strict_deriv_at_sin (x : ℂ) : has_strict_deriv_at sin (cos x) x :=
begin
simp only [cos, div_eq_mul_inv],
convert ((((has_strict_deriv_at_id x).neg.mul_const I).cexp.sub
((has_strict_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
end
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x :=
(has_strict_deriv_at_sin x).has_deriv_at
lemma times_cont_diff_sin {n} : times_cont_diff ℂ n sin :=
(((times_cont_diff_neg.mul times_cont_diff_const).cexp.sub
(times_cont_diff_id.mul times_cont_diff_const).cexp).mul times_cont_diff_const).div_const
lemma differentiable_sin : differentiable ℂ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
@[continuity]
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on
lemma measurable_sin : measurable sin := continuous_sin.measurable
/-- The complex cosine function is everywhere strictly differentiable, with the derivative
`-sin x`. -/
lemma has_strict_deriv_at_cos (x : ℂ) : has_strict_deriv_at cos (-sin x) x :=
begin
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],
convert (((has_strict_deriv_at_id x).mul_const I).cexp.add
((has_strict_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
ring
end
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x :=
(has_strict_deriv_at_cos x).has_deriv_at
lemma times_cont_diff_cos {n} : times_cont_diff ℂ n cos :=
((times_cont_diff_id.mul times_cont_diff_const).cexp.add
(times_cont_diff_neg.mul times_cont_diff_const).cexp).div_const
lemma differentiable_cos : differentiable ℂ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
lemma deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) :=
funext $ λ x, deriv_cos
@[continuity]
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative
`cosh x`. -/
lemma has_strict_deriv_at_sinh (x : ℂ) : has_strict_deriv_at sinh (cosh x) x :=
begin
simp only [cosh, div_eq_mul_inv],
convert ((has_strict_deriv_at_exp x).sub (has_strict_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]
end
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative
`cosh x`. -/
lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x :=
(has_strict_deriv_at_sinh x).has_deriv_at
lemma times_cont_diff_sinh {n} : times_cont_diff ℂ n sinh :=
(times_cont_diff_exp.sub times_cont_diff_neg.cexp).div_const
lemma differentiable_sinh : differentiable ℂ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
@[continuity]
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the
derivative `sinh x`. -/
lemma has_strict_deriv_at_cosh (x : ℂ) : has_strict_deriv_at cosh (sinh x) x :=
begin
simp only [sinh, div_eq_mul_inv],
convert ((has_strict_deriv_at_exp x).add (has_strict_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, sub_eq_add_neg]
end
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative
`sinh x`. -/
lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x :=
(has_strict_deriv_at_cosh x).has_deriv_at
lemma times_cont_diff_cosh {n} : times_cont_diff ℂ n cosh :=
(times_cont_diff_exp.add times_cont_diff_neg.cexp).div_const
lemma differentiable_cosh : differentiable ℂ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
@[continuity]
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
end complex
section
/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : ℂ → ℂ` -/
variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
/-! #### `complex.cos` -/
lemma measurable.ccos {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.cos (f x)) :=
complex.measurable_cos.comp hf
lemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_strict_deriv_at_cos (f x)).comp x hf
lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccos (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccos.deriv_within hxs
@[simp] lemma deriv_ccos (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=
hc.has_deriv_at.ccos.deriv
/-! #### `complex.sin` -/
lemma measurable.csin {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.sin (f x)) :=
complex.measurable_sin.comp hf
lemma has_strict_deriv_at.csin (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_strict_deriv_at_sin (f x)).comp x hf
lemma has_deriv_at.csin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csin (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csin.deriv_within hxs
@[simp] lemma deriv_csin (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=
hc.has_deriv_at.csin.deriv
/-! #### `complex.cosh` -/
lemma measurable.ccosh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.cosh (f x)) :=
complex.measurable_cosh.comp hf
lemma has_strict_deriv_at.ccosh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_strict_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccosh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccosh.deriv_within hxs
@[simp] lemma deriv_ccosh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.ccosh.deriv
/-! #### `complex.sinh` -/
lemma measurable.csinh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.sinh (f x)) :=
complex.measurable_sinh.comp hf
lemma has_strict_deriv_at.csinh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_strict_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csinh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csinh.deriv_within hxs
@[simp] lemma deriv_csinh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.csinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : E → ℂ` -/
variables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ}
{x : E} {s : set E}
/-! #### `complex.cos` -/
lemma has_strict_fderiv_at.ccos (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') x :=
(complex.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccos (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cos (f x)) s x :=
hf.has_fderiv_within_at.ccos.differentiable_within_at
@[simp] lemma differentiable_at.ccos (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cos (f x)) x :=
hc.has_fderiv_at.ccos.differentiable_at
lemma differentiable_on.ccos (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cos (f x)) s :=
λx h, (hc x h).ccos
@[simp] lemma differentiable.ccos (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cos (f x)) :=
λx, (hc x).ccos
lemma fderiv_within_ccos (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.cos (f x)) s x = - complex.sin (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.ccos.fderiv_within hxs
@[simp] lemma fderiv_ccos (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.cos (f x)) x = - complex.sin (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.ccos.fderiv
lemma times_cont_diff.ccos {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.cos (f x)) :=
complex.times_cont_diff_cos.comp h
lemma times_cont_diff_at.ccos {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.cos (f x)) x :=
complex.times_cont_diff_cos.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.ccos {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.cos (f x)) s :=
complex.times_cont_diff_cos.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.ccos {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.cos (f x)) s x :=
complex.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.sin` -/
lemma has_strict_fderiv_at.csin (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') x :=
(complex.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csin (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sin (f x)) s x :=
hf.has_fderiv_within_at.csin.differentiable_within_at
@[simp] lemma differentiable_at.csin (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sin (f x)) x :=
hc.has_fderiv_at.csin.differentiable_at
lemma differentiable_on.csin (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sin (f x)) s :=
λx h, (hc x h).csin
@[simp] lemma differentiable.csin (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sin (f x)) :=
λx, (hc x).csin
lemma fderiv_within_csin (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.sin (f x)) s x = complex.cos (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.csin.fderiv_within hxs
@[simp] lemma fderiv_csin (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.sin (f x)) x = complex.cos (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.csin.fderiv
lemma times_cont_diff.csin {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.sin (f x)) :=
complex.times_cont_diff_sin.comp h
lemma times_cont_diff_at.csin {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.sin (f x)) x :=
complex.times_cont_diff_sin.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.csin {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.sin (f x)) s :=
complex.times_cont_diff_sin.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.csin {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.sin (f x)) s x :=
complex.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.cosh` -/
lemma has_strict_fderiv_at.ccosh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') x :=
(complex.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccosh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cosh (f x)) s x :=
hf.has_fderiv_within_at.ccosh.differentiable_within_at
@[simp] lemma differentiable_at.ccosh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cosh (f x)) x :=
hc.has_fderiv_at.ccosh.differentiable_at
lemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cosh (f x)) s :=
λx h, (hc x h).ccosh
@[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cosh (f x)) :=
λx, (hc x).ccosh
lemma fderiv_within_ccosh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.cosh (f x)) s x = complex.sinh (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.ccosh.fderiv_within hxs
@[simp] lemma fderiv_ccosh (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.cosh (f x)) x = complex.sinh (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.ccosh.fderiv
lemma times_cont_diff.ccosh {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.cosh (f x)) :=
complex.times_cont_diff_cosh.comp h
lemma times_cont_diff_at.ccosh {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.cosh (f x)) x :=
complex.times_cont_diff_cosh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.ccosh {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.cosh (f x)) s :=
complex.times_cont_diff_cosh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.ccosh {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.cosh (f x)) s x :=
complex.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.sinh` -/
lemma has_strict_fderiv_at.csinh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') x :=
(complex.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csinh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sinh (f x)) s x :=
hf.has_fderiv_within_at.csinh.differentiable_within_at
@[simp] lemma differentiable_at.csinh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sinh (f x)) x :=
hc.has_fderiv_at.csinh.differentiable_at
lemma differentiable_on.csinh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sinh (f x)) s :=
λx h, (hc x h).csinh
@[simp] lemma differentiable.csinh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sinh (f x)) :=
λx, (hc x).csinh
lemma fderiv_within_csinh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.sinh (f x)) s x = complex.cosh (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.csinh.fderiv_within hxs
@[simp] lemma fderiv_csinh (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.sinh (f x)) x = complex.cosh (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.csinh.fderiv
lemma times_cont_diff.csinh {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.sinh (f x)) :=
complex.times_cont_diff_sinh.comp h
lemma times_cont_diff_at.csinh {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.sinh (f x)) x :=
complex.times_cont_diff_sinh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.csinh {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.sinh (f x)) s :=
complex.times_cont_diff_sinh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.csinh {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.sinh (f x)) s x :=
complex.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
end
namespace real
variables {x y z : ℝ}
lemma has_strict_deriv_at_sin (x : ℝ) : has_strict_deriv_at sin (cos x) x :=
(complex.has_strict_deriv_at_sin x).real_of_complex
lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x :=
(has_strict_deriv_at_sin x).has_deriv_at
lemma times_cont_diff_sin {n} : times_cont_diff ℝ n sin :=
complex.times_cont_diff_sin.real_of_complex
lemma differentiable_sin : differentiable ℝ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin : differentiable_at ℝ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
@[continuity]
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma continuous_on_sin {s} : continuous_on sin s :=
continuous_sin.continuous_on
lemma measurable_sin : measurable sin := continuous_sin.measurable
lemma has_strict_deriv_at_cos (x : ℝ) : has_strict_deriv_at cos (-sin x) x :=
(complex.has_strict_deriv_at_cos x).real_of_complex
lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x :=
(complex.has_deriv_at_cos x).real_of_complex
lemma times_cont_diff_cos {n} : times_cont_diff ℝ n cos :=
complex.times_cont_diff_cos.real_of_complex
lemma differentiable_cos : differentiable ℝ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos : differentiable_at ℝ cos x :=
differentiable_cos x
lemma deriv_cos : deriv cos x = - sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) :=
funext $ λ _, deriv_cos
@[continuity]
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
lemma has_strict_deriv_at_sinh (x : ℝ) : has_strict_deriv_at sinh (cosh x) x :=
(complex.has_strict_deriv_at_sinh x).real_of_complex
lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x :=
(complex.has_deriv_at_sinh x).real_of_complex
lemma times_cont_diff_sinh {n} : times_cont_diff ℝ n sinh :=
complex.times_cont_diff_sinh.real_of_complex
lemma differentiable_sinh : differentiable ℝ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh : differentiable_at ℝ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
@[continuity]
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
lemma has_strict_deriv_at_cosh (x : ℝ) : has_strict_deriv_at cosh (sinh x) x :=
(complex.has_strict_deriv_at_cosh x).real_of_complex
lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x :=
(complex.has_deriv_at_cosh x).real_of_complex
lemma times_cont_diff_cosh {n} : times_cont_diff ℝ n cosh :=
complex.times_cont_diff_cosh.real_of_complex
lemma differentiable_cosh : differentiable ℝ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh : differentiable_at ℝ cosh x :=
differentiable_cosh x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
@[continuity]
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
/-- `sinh` is strictly monotone. -/
lemma sinh_strict_mono : strict_mono sinh :=
strict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos })
end real
section
/-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : ℝ → ℝ` -/
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
/-! #### `real.cos` -/
lemma measurable.cos {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.cos (f x)) :=
real.measurable_cos.comp hf
lemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_strict_deriv_at_cos (f x)).comp x hf
lemma has_deriv_at.cos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cos (f x)) (- real.sin (f x) * f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cos (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cos.deriv_within hxs
@[simp] lemma deriv_cos (hc : differentiable_at ℝ f x) :
deriv (λx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=
hc.has_deriv_at.cos.deriv
/-! #### `real.sin` -/
lemma measurable.sin {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.sin (f x)) :=
real.measurable_sin.comp hf
lemma has_strict_deriv_at.sin (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_strict_deriv_at_sin (f x)).comp x hf
lemma has_deriv_at.sin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sin (f x)) (real.cos (f x) * f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sin (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sin.deriv_within hxs
@[simp] lemma deriv_sin (hc : differentiable_at ℝ f x) :
deriv (λx, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=
hc.has_deriv_at.sin.deriv
/-! #### `real.cosh` -/
lemma measurable.cosh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.cosh (f x)) :=
real.measurable_cosh.comp hf
lemma has_strict_deriv_at.cosh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_strict_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cosh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cosh.deriv_within hxs
@[simp] lemma deriv_cosh (hc : differentiable_at ℝ f x) :
deriv (λx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.cosh.deriv
/-! #### `real.sinh` -/
lemma measurable.sinh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.sinh (f x)) :=
real.measurable_sinh.comp hf
lemma has_strict_deriv_at.sinh (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_strict_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sinh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sinh.deriv_within hxs
@[simp] lemma deriv_sinh (hc : differentiable_at ℝ f x) :
deriv (λx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.sinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : E → ℝ` -/
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ}
{x : E} {s : set E}
/-! #### `real.cos` -/
lemma has_strict_fderiv_at.cos (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.cos (f x)) (- real.sin (f x) • f') x :=
(real.has_strict_deriv_at_cos (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.cos (f x)) (- real.sin (f x) • f') x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.cos (f x)) (- real.sin (f x) • f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cos (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cos (f x)) s x :=
hf.has_fderiv_within_at.cos.differentiable_within_at
@[simp] lemma differentiable_at.cos (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cos (f x)) x :=
hc.has_fderiv_at.cos.differentiable_at
lemma differentiable_on.cos (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cos (f x)) s :=
λx h, (hc x h).cos
@[simp] lemma differentiable.cos (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cos (f x)) :=
λx, (hc x).cos
lemma fderiv_within_cos (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.cos (f x)) s x = - real.sin (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.cos.fderiv_within hxs
@[simp] lemma fderiv_cos (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.cos (f x)) x = - real.sin (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.cos.fderiv
lemma times_cont_diff.cos {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.cos (f x)) :=
real.times_cont_diff_cos.comp h
lemma times_cont_diff_at.cos {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.cos (f x)) x :=
real.times_cont_diff_cos.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.cos {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.cos (f x)) s :=
real.times_cont_diff_cos.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.cos {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.cos (f x)) s x :=
real.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.sin` -/
lemma has_strict_fderiv_at.sin (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.sin (f x)) (real.cos (f x) • f') x :=
(real.has_strict_deriv_at_sin (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.sin (f x)) (real.cos (f x) • f') x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.sin (f x)) (real.cos (f x) • f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sin (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sin (f x)) s x :=
hf.has_fderiv_within_at.sin.differentiable_within_at
@[simp] lemma differentiable_at.sin (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sin (f x)) x :=
hc.has_fderiv_at.sin.differentiable_at
lemma differentiable_on.sin (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sin (f x)) s :=
λx h, (hc x h).sin
@[simp] lemma differentiable.sin (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sin (f x)) :=
λx, (hc x).sin
lemma fderiv_within_sin (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.sin (f x)) s x = real.cos (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.sin.fderiv_within hxs
@[simp] lemma fderiv_sin (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.sin (f x)) x = real.cos (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.sin.fderiv
lemma times_cont_diff.sin {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.sin (f x)) :=
real.times_cont_diff_sin.comp h
lemma times_cont_diff_at.sin {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.sin (f x)) x :=
real.times_cont_diff_sin.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.sin {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.sin (f x)) s :=
real.times_cont_diff_sin.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.sin {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.sin (f x)) s x :=
real.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.cosh` -/
lemma has_strict_fderiv_at.cosh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') x :=
(real.has_strict_deriv_at_cosh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cosh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cosh (f x)) s x :=
hf.has_fderiv_within_at.cosh.differentiable_within_at
@[simp] lemma differentiable_at.cosh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cosh (f x)) x :=
hc.has_fderiv_at.cosh.differentiable_at
lemma differentiable_on.cosh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cosh (f x)) s :=
λx h, (hc x h).cosh
@[simp] lemma differentiable.cosh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cosh (f x)) :=
λx, (hc x).cosh
lemma fderiv_within_cosh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.cosh (f x)) s x = real.sinh (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.cosh.fderiv_within hxs
@[simp] lemma fderiv_cosh (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.cosh (f x)) x = real.sinh (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.cosh.fderiv
lemma times_cont_diff.cosh {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.cosh (f x)) :=
real.times_cont_diff_cosh.comp h
lemma times_cont_diff_at.cosh {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.cosh (f x)) x :=
real.times_cont_diff_cosh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.cosh {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.cosh (f x)) s :=
real.times_cont_diff_cosh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.cosh {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.cosh (f x)) s x :=
real.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.sinh` -/
lemma has_strict_fderiv_at.sinh (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') x :=
(real.has_strict_deriv_at_sinh (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sinh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sinh (f x)) s x :=
hf.has_fderiv_within_at.sinh.differentiable_within_at
@[simp] lemma differentiable_at.sinh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sinh (f x)) x :=
hc.has_fderiv_at.sinh.differentiable_at
lemma differentiable_on.sinh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sinh (f x)) s :=
λx h, (hc x h).sinh
@[simp] lemma differentiable.sinh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sinh (f x)) :=
λx, (hc x).sinh
lemma fderiv_within_sinh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.sinh (f x)) s x = real.cosh (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.sinh.fderiv_within hxs
@[simp] lemma fderiv_sinh (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.sinh (f x)) x = real.cosh (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.sinh.fderiv
lemma times_cont_diff.sinh {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.sinh (f x)) :=
real.times_cont_diff_sinh.comp h
lemma times_cont_diff_at.sinh {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.sinh (f x)) x :=
real.times_cont_diff_sinh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.sinh {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.sinh (f x)) s :=
real.times_cont_diff_sinh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.sinh {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.sinh (f x)) s x :=
real.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
end
namespace real
lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuous_on_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `data.real.pi`. -/
protected noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : π / 2 ≤ 2 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two)
lemma pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(calc π / 2 ≤ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_ne_zero : π ≠ 0 :=
ne_of_gt pi_pos
lemma pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * π :=
by linarith [pi_pos]
end real
namespace nnreal
open real
open_locale real nnreal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 := ⟨π, real.pi_pos.le⟩
@[simp] lemma coe_real_pi : (pi : ℝ) = π := rfl
lemma pi_pos : 0 < pi := by exact_mod_cast real.pi_pos
lemma pi_ne_zero : pi ≠ 0 := pi_pos.ne'
end nnreal
namespace real
open_locale real
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left π (@two_ne_zero ℝ _ _), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← mul_div_cancel_left π (@two_ne_zero ℝ _ _), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
by simp [cos_sub]
lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
by simp [cos_sub]
lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : ℝ) + 2 = 4, from rfl,
have π - x ≤ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
lemma sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x :=
begin
rw ← closure_Ioo pi_pos at hx,
exact closure_lt_subset_le continuous_const continuous_sin
(closure_mono (λ y, sin_pos_of_mem_Ioo) hx)
end
lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
have sin (π / 2) = 1 ∨ sin (π / 2) = -1 :=
by simpa [pow_two, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2),
this.resolve_right
(λ h, (show ¬(0 : ℝ) < -1, by norm_num) $
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) :
sin x = 0 ↔ x = 0 :=
⟨λ h, le_antisymm
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂
... = 0 : h))
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)),
λ h, by simp [h]⟩
lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃,
(sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
lemma sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x,
pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
(λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [← hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))⟩,
λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩
lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨λ h,
begin
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩,
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁,
norm_cast at hx₁ hx₂,
obtain rfl : n = 0 := le_antisymm (by linarith) (by linarith),
simp
end,
λ h, by simp [h]⟩
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) :
cos y < cos x :=
begin
rw [← sub_lt_zero, cos_sub_cos],
have : 0 < sin ((y + x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
have : 0 < sin ((y - x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
nlinarith,
end
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x :=
match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_mem_Ioo ⟨by linarith, hx⟩)
(λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma strict_mono_decr_on_cos : strict_mono_decr_on cos (Icc 0 π) :=
λ x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strict_mono_decr_on_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
lemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y :=
by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma strict_mono_incr_on_sin : strict_mono_incr_on sin (Icc (-(π / 2)) (π / 2)) :=
λ x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y :=
(strict_mono_incr_on_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
lemma inj_on_sin : inj_on sin (Icc (-(π / 2)) (π / 2)) :=
strict_mono_incr_on_sin.inj_on
lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_mono_decr_on_cos.inj_on
lemma surj_on_sin : surj_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
by simpa only [sin_neg, sin_pi_div_two]
using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on
lemma surj_on_cos : surj_on cos (Icc 0 π) (Icc (-1) 1) :=
by simpa only [cos_zero, cos_pi]
using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on
lemma sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩
lemma cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩
lemma maps_to_sin (s : set ℝ) : maps_to sin s (Icc (-1 : ℝ) 1) := λ x _, sin_mem_Icc x
lemma maps_to_cos (s : set ℝ) : maps_to cos s (Icc (-1 : ℝ) 1) := λ x _, cos_mem_Icc x
lemma bij_on_sin : bij_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨maps_to_sin _, inj_on_sin, surj_on_sin⟩
lemma bij_on_cos : bij_on cos (Icc 0 π) (Icc (-1) 1) :=
⟨maps_to_cos _, inj_on_cos, surj_on_cos⟩
@[simp] lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range
@[simp] lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range
lemma range_cos_infinite : (range real.cos).infinite :=
by { rw real.range_cos, exact Icc.infinite (by norm_num) }
lemma range_sin_infinite : (range real.sin).infinite :=
by { rw real.range_sin, exact Icc.infinite (by norm_num) }
lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x :=
begin
cases le_or_gt x 1 with h' h',
{ have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.2, rw [sub_le_iff_le_add', hx] at this,
apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),
apply sub_lt_sub_left, rw [sub_pos, div_eq_mul_inv (x ^ 3)], apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h },
exact lt_of_le_of_lt (sin_le_one x) h'
end
/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.
note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/
lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x :=
begin
have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.1, rw [le_sub_iff_add_le, hx] at this,
refine lt_of_lt_of_le _ this,
rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,
apply add_lt_of_lt_sub_left,
rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12⁻¹,
by simp [div_eq_mul_inv, ← mul_sub]; norm_num),
apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h
end
section cos_div_pow_two
variable (x : ℝ)
/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`
-/
@[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ
| 0 := x
| (n+1) := sqrt (2 + sqrt_two_add_series n)
lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp
lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp
lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp
lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n
| 0 := le_refl 0
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n
| 0 := h
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2
| 0 := by norm_num
| (n+1) :=
begin
refine lt_of_lt_of_le _ (le_of_eq $ sqrt_sqr $ le_of_lt zero_lt_two),
rw [sqrt_two_add_series, sqrt_lt, ← lt_sub_iff_add_lt'],
{ refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num },
{ exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) }
end
lemma sqrt_two_add_series_succ (x : ℝ) :
∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n
| 0 := rfl
| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]
lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) :
∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n
| 0 := h
| (n+1) :=
begin
rw [sqrt_two_add_series, sqrt_two_add_series],
exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _)
end
@[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (π / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2
| 0 := by simp
| (n+1) :=
begin
have : (2 : ℝ) ≠ 0 := two_ne_zero,
symmetry, rw [div_eq_iff_mul_eq this], symmetry,
rw [sqrt_two_add_series, sqrt_eq_iff_sqr_eq, mul_pow, cos_square, ←mul_div_assoc,
nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul],
congr, { norm_num },
rw [mul_comm, pow_two, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc,
mul_div_cancel_left]; try { exact this },
apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,
apply le_of_lt, apply cos_pos_of_mem_Ioo ⟨_, _⟩,
{ transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos,
apply div_pos pi_pos, apply pow_pos, norm_num },
apply div_lt_div' (le_refl π) _ pi_pos _,
refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}
end
lemma sin_square_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_square, cos_pi_over_two_pow]
lemma sin_square_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_square_pi_over_two_pow, sqrt_two_add_series, div_pow, sqr_sqrt, add_div, ←sub_sub],
congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,
end
@[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_eq_iff_sqr_eq, mul_pow, sin_square_pi_over_two_pow_succ, sub_mul],
{ congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },
{ rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },
apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],
refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,
apply pow_pos, all_goals {norm_num}
end
@[simp] lemma cos_pi_div_four : cos (π / 4) = sqrt 2 / 2 :=
by { transitivity cos (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma sin_pi_div_four : sin (π / 4) = sqrt 2 / 2 :=
by { transitivity sin (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma cos_pi_div_eight : cos (π / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma sin_pi_div_eight : sin (π / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma cos_pi_div_sixteen : cos (π / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma sin_pi_div_sixteen : sin (π / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma cos_pi_div_thirty_two : cos (π / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (π / 2 ^ 5), congr, norm_num, simp }
@[simp] lemma sin_pi_div_thirty_two : sin (π / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (π / 2 ^ 5), congr, norm_num, simp }
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp] lemma cos_pi_div_three : cos (π / 3) = 1 / 2 :=
begin
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0,
{ have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring },
linarith [cos_pi, cos_three_mul (π / 3)] },
cases mul_eq_zero.mp h₁ with h h,
{ linarith [pow_eq_zero h] },
{ have : cos π < cos (π / 3),
{ refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _;
linarith [pi_pos] },
linarith [cos_pi] }
end
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma square_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 :=
begin
have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,
{ convert cos_square (π / 6),
have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms,
rw [h2, cos_pi_div_three] },
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring
end
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp] lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 :=
begin
suffices : sqrt 3 = cos (π / 6) * 2,
{ field_simp [(by norm_num : 0 ≠ 2)], exact this.symm },
rw sqrt_eq_iff_sqr_eq,
{ have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr square_cos_pi_div_six,
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring },
{ norm_num },
{ have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] },
linarith },
end
/-- The sine of `π / 6` is `1 / 2`. -/
@[simp] lemma sin_pi_div_six : sin (π / 6) = 1 / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_three],
congr,
ring
end
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma square_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 :=
begin
rw [← cos_pi_div_two_sub, ← square_cos_pi_div_six],
congr,
ring
end
/-- The sine of `π / 3` is `√3 / 2`. -/
@[simp] lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_six],
congr,
ring
end
end cos_div_pow_two
/-- The type of angles -/
def angle : Type :=
quotient_add_group.quotient (add_subgroup.gmultiples (2 * π))
namespace angle
instance angle.add_comm_group : add_comm_group angle :=
quotient_add_group.add_comm_group _
instance : inhabited angle := ⟨0⟩
instance angle.has_coe : has_coe ℝ angle :=
⟨quotient.mk'⟩
@[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl
@[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl
@[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl
@[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) :=
by rw [sub_eq_add_neg, sub_eq_add_neg, coe_add, coe_neg]
@[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : ℝ) (n : ℕ) :
↑((n : ℝ) * x) = n •ℕ (↑x : angle) :=
by simpa using add_monoid_hom.map_nsmul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : ℝ) (n : ℤ) :
↑((n : ℝ) * x : ℝ) = n •ℤ (↑x : angle) :=
by simpa using add_monoid_hom.map_gsmul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) :=
quotient.sound' ⟨-1, show (-1 : ℤ) •ℤ (2 * π) = _, by rw [neg_one_gsmul, add_zero]⟩
lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k :=
by simp only [quotient_add_group.eq, add_subgroup.gmultiples_eq_closure,
add_subgroup.mem_closure_singleton, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ :=
begin
split,
{ intro Hcos,
rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,
eq_false_intro two_ne_zero, false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos,
rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩,
{ right,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), ← sub_eq_iff_eq_add] at hn,
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] },
{ left,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), eq_sub_iff_add_eq] at hn,
rw [← hn, coe_add, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] },
apply_instance, },
{ rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero_iff_eq, cos_sub_cos, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero],
rw [← sub_eq_zero_iff_eq, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul] }
end
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : ℝ} :
sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π :=
begin
split,
{ intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin,
cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h,
{ left, rw [coe_sub, coe_sub] at h, exact sub_right_inj.1 h },
right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub,
sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h,
exact h.symm },
{ rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero_iff_eq, sin_sub_sin, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul],
have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add,
mul_assoc, mul_comm π _, ←mul_assoc] at H,
rw [← sub_eq_zero_iff_eq, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,
mul_zero] }
end
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ :=
begin
cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc },
cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs },
rw [eq_neg_iff_add_eq_zero, hs] at hc,
cases quotient.exact' hc with n hn, change n •ℤ _ = _ at hn,
rw [← neg_one_mul, add_zero, ← sub_eq_zero_iff_eq, gsmul_eq_mul, ← mul_assoc, ← sub_mul,
mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add,
← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add,
int.cast_inj] at hn,
have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn,
rw [add_comm, int.add_mul_mod_self] at this,
exact absurd this one_ne_zero
end
end angle
/-- `real.sin` as an `order_iso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/
def sin_order_iso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1:ℝ) 1 :=
(strict_mono_incr_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq
@[simp] lemma coe_sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
(sin_order_iso x : ℝ) = sin x := rfl
lemma sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
sin_order_iso x = ⟨sin x, sin_mem_Icc x⟩ := rfl
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.
It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/
@[pp_nodot] noncomputable def arcsin : ℝ → ℝ :=
coe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm
lemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _
@[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) :=
by { rw [arcsin, range_comp coe], simp [Icc] }
lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2
lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1
lemma arcsin_proj_Icc (x : ℝ) :
arcsin (proj_Icc (-1) 1 (neg_le_self $ @zero_le_one ℝ _) x) = arcsin x :=
by rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend]
lemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x :=
by simpa [arcsin, Icc_extend_of_mem _ _ hx, -order_iso.apply_symm_apply]
using subtype.ext_iff.1 (sin_order_iso.apply_symm_apply ⟨x, hx⟩)
lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
sin_arcsin' ⟨hx₁, hx₂⟩
lemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x :=
inj_on_sin (arcsin_mem_Icc _) hx $ by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]
lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
arcsin_sin' ⟨hx₁, hx₂⟩
lemma strict_mono_incr_on_arcsin : strict_mono_incr_on arcsin (Icc (-1) 1) :=
(subtype.strict_mono_coe _).comp_strict_mono_incr_on $
sin_order_iso.symm.strict_mono.strict_mono_incr_on_Icc_extend _
lemma monotone_arcsin : monotone arcsin :=
(subtype.mono_coe _).comp $ sin_order_iso.symm.monotone.Icc_extend _
lemma inj_on_arcsin : inj_on arcsin (Icc (-1) 1) := strict_mono_incr_on_arcsin.inj_on
lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arcsin x = arcsin y ↔ x = y :=
inj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[continuity]
lemma continuous_arcsin : continuous arcsin :=
continuous_subtype_coe.comp sin_order_iso.symm.continuous.Icc_extend
lemma continuous_at_arcsin {x : ℝ} : continuous_at arcsin x :=
continuous_arcsin.continuous_at
lemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :
arcsin y = x :=
begin
subst y,
exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))
end
@[simp] lemma arcsin_zero : arcsin 0 = 0 :=
arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩
@[simp] lemma arcsin_one : arcsin 1 = π / 2 :=
arcsin_eq_of_sin_eq sin_pi_div_two $ right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
lemma arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 :=
by rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one]
lemma arcsin_neg_one : arcsin (-1) = -(π / 2) :=
arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) $
left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
lemma arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) :=
by rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one]
@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=
begin
cases le_total x (-1) with hx₁ hx₁,
{ rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] },
cases le_total 1 x with hx₂ hx₂,
{ rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] },
refine arcsin_eq_of_sin_eq _ _,
{ rw [sin_neg, sin_arcsin hx₁ hx₂] },
{ exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ }
end
lemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y :=
by rw [← arcsin_sin' hy, strict_mono_incr_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]
lemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y :=
begin
cases le_total x (-1) with hx₁ hx₁,
{ simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] },
cases lt_or_le 1 x with hx₂ hx₂,
{ simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] },
exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)
end
lemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x ≤ arcsin y ↔ sin x ≤ y :=
by rw [← neg_le_neg_iff, ← arcsin_neg,
arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
lemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :
x ≤ arcsin y ↔ sin x ≤ y :=
by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
lemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le hy hx).trans not_le
lemma arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans $ (not_congr $ le_arcsin_iff_sin_le' hy).trans not_le
lemma lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin hy hx).trans not_le
lemma lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans $ (not_congr $ arcsin_le_iff_le_sin' hx).trans not_le
lemma arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :
arcsin x = y ↔ x = sin y :=
by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),
le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]
@[simp] lemma arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=
(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero]
@[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=
neg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg
@[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 :=
by simp [le_antisymm_iff]
@[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=
eq_comm.trans arcsin_eq_zero_iff
@[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le arcsin_nonpos
@[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=
lt_iff_lt_of_le_iff_le arcsin_nonneg
@[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 :=
(arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 $ neg_lt_self pi_div_two_pos)).trans $
by rw sin_pi_div_two
@[simp] lemma neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x :=
(lt_arcsin_iff_sin_lt' $ left_mem_Ico.2 $ neg_lt_self pi_div_two_pos).trans $
by rw [sin_neg, sin_pi_div_two]
@[simp] lemma arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=
⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩
@[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=
eq_comm.trans arcsin_eq_pi_div_two
@[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x :=
(arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin
@[simp] lemma arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=
⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩
@[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=
eq_comm.trans arcsin_eq_neg_pi_div_two
@[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=
(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two
lemma maps_to_sin_Ioo : maps_to sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) :=
λ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin,
arcsin_sin h.1.le h.2.le]
/-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/
@[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ :=
{ to_fun := sin,
inv_fun := arcsin,
source := Ioo (-(π / 2)) (π / 2),
target := Ioo (-1) 1,
map_source' := maps_to_sin_Ioo,
map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩,
left_inv' := λ x hx, arcsin_sin hx.1.le hx.2.le,
right_inv' := λ y hy, sin_arcsin hy.1.le hy.2.le,
open_source := is_open_Ioo,
open_target := is_open_Ioo,
continuous_to_fun := continuous_sin.continuous_on,
continuous_inv_fun := continuous_arcsin.continuous_on }
lemma cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
lemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) :=
have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x),
begin
rw [← eq_sub_iff_add_eq', ← sqrt_inj (pow_two_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))),
pow_two, sqrt_mul_self (cos_arcsin_nonneg _)] at this,
rw [this, sin_arcsin hx₁ hx₂],
end
lemma deriv_arcsin_aux {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x ∧ times_cont_diff_at ℝ ⊤ arcsin x :=
begin
cases h₁.lt_or_lt with h₁ h₁,
{ have : 1 - x ^ 2 < 0, by nlinarith [h₁],
rw [sqrt_eq_zero'.2 this.le, div_zero],
have : arcsin =ᶠ[𝓝 x] λ _, -(π / 2) :=
(gt_mem_nhds h₁).mono (λ y hy, arcsin_of_le_neg_one hy.le),
exact ⟨(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,
times_cont_diff_at_const.congr_of_eventually_eq this⟩ },
cases h₂.lt_or_lt with h₂ h₂,
{ have : 0 < sqrt (1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, h₂]),
simp only [← cos_arcsin h₁.le h₂.le, one_div] at this ⊢,
exact ⟨sin_local_homeomorph.has_strict_deriv_at_symm ⟨h₁, h₂⟩ this.ne'
(has_strict_deriv_at_sin _),
sin_local_homeomorph.times_cont_diff_at_symm_deriv this.ne' ⟨h₁, h₂⟩
(has_deriv_at_sin _) times_cont_diff_sin.times_cont_diff_at⟩ },
{ have : 1 - x ^ 2 < 0, by nlinarith [h₂],
rw [sqrt_eq_zero'.2 this.le, div_zero],
have : arcsin =ᶠ[𝓝 x] λ _, π / 2 := (lt_mem_nhds h₂).mono (λ y hy, arcsin_of_one_le hy.le),
exact ⟨(has_strict_deriv_at_const _ _).congr_of_eventually_eq this.symm,
times_cont_diff_at_const.congr_of_eventually_eq this⟩ }
end
lemma has_strict_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=
(deriv_arcsin_aux h₁ h₂).1
lemma has_deriv_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_deriv_at arcsin (1 / sqrt (1 - x ^ 2)) x :=
(has_strict_deriv_at_arcsin h₁ h₂).has_deriv_at
lemma times_cont_diff_at_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} :
times_cont_diff_at ℝ n arcsin x :=
(deriv_arcsin_aux h₁ h₂).2.of_le le_top
lemma has_deriv_within_at_arcsin_Ici {x : ℝ} (h : x ≠ -1) :
has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Ici x) x :=
begin
rcases em (x = 1) with (rfl|h'),
{ convert (has_deriv_within_at_const _ _ (π / 2)).congr _ _;
simp [arcsin_of_one_le] { contextual := tt } },
{ exact (has_deriv_at_arcsin h h').has_deriv_within_at }
end
lemma has_deriv_within_at_arcsin_Iic {x : ℝ} (h : x ≠ 1) :
has_deriv_within_at arcsin (1 / sqrt (1 - x ^ 2)) (Iic x) x :=
begin
rcases em (x = -1) with (rfl|h'),
{ convert (has_deriv_within_at_const _ _ (-(π / 2))).congr _ _;
simp [arcsin_of_le_neg_one] { contextual := tt } },
{ exact (has_deriv_at_arcsin h' h).has_deriv_within_at }
end
lemma differentiable_within_at_arcsin_Ici {x : ℝ} :
differentiable_within_at ℝ arcsin (Ici x) x ↔ x ≠ -1 :=
begin
refine ⟨_, λ h, (has_deriv_within_at_arcsin_Ici h).differentiable_within_at⟩,
rintro h rfl,
have : sin ∘ arcsin =ᶠ[𝓝[Ici (-1:ℝ)] (-1)] id,
{ filter_upwards [Icc_mem_nhds_within_Ici ⟨le_rfl, neg_lt_self (@zero_lt_one ℝ _ _)⟩],
exact λ x, sin_arcsin' },
have := h.has_deriv_within_at.sin.congr_of_eventually_eq this.symm (by simp),
simpa using (unique_diff_on_Ici _ _ left_mem_Ici).eq_deriv _ this (has_deriv_within_at_id _ _)
end
lemma differentiable_within_at_arcsin_Iic {x : ℝ} :
differentiable_within_at ℝ arcsin (Iic x) x ↔ x ≠ 1 :=
begin
refine ⟨λ h, _, λ h, (has_deriv_within_at_arcsin_Iic h).differentiable_within_at⟩,
rw [← neg_neg x, ← image_neg_Ici] at h,
have := (h.comp (-x) differentiable_within_at_id.neg (maps_to_image _ _)).neg,
simpa [(∘), differentiable_within_at_arcsin_Ici] using this
end
lemma differentiable_at_arcsin {x : ℝ} :
differentiable_at ℝ arcsin x ↔ x ≠ -1 ∧ x ≠ 1 :=
⟨λ h, ⟨differentiable_within_at_arcsin_Ici.1 h.differentiable_within_at,
differentiable_within_at_arcsin_Iic.1 h.differentiable_within_at⟩,
λ h, (has_deriv_at_arcsin h.1 h.2).differentiable_at⟩
@[simp] lemma deriv_arcsin : deriv arcsin = λ x, 1 / sqrt (1 - x ^ 2) :=
begin
funext x,
by_cases h : x ≠ -1 ∧ x ≠ 1,
{ exact (has_deriv_at_arcsin h.1 h.2).deriv },
{ rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_arcsin.1 h)],
simp only [not_and_distrib, ne.def, not_not] at h,
rcases h with (rfl|rfl); simp }
end
lemma differentiable_on_arcsin : differentiable_on ℝ arcsin {-1, 1}ᶜ :=
λ x hx, (differentiable_at_arcsin.2
⟨λ h, hx (or.inl h), λ h, hx (or.inr h)⟩).differentiable_within_at
lemma times_cont_diff_on_arcsin {n : with_top ℕ} :
times_cont_diff_on ℝ n arcsin {-1, 1}ᶜ :=
λ x hx, (times_cont_diff_at_arcsin (mt or.inl hx) (mt or.inr hx)).times_cont_diff_within_at
lemma times_cont_diff_at_arcsin_iff {x : ℝ} {n : with_top ℕ} :
times_cont_diff_at ℝ n arcsin x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) :=
⟨λ h, or_iff_not_imp_left.2 $ λ hn, differentiable_at_arcsin.1 $ h.differentiable_at $
with_top.one_le_iff_pos.2 (pos_iff_ne_zero.2 hn),
λ h, h.elim (λ hn, hn.symm ▸ (times_cont_diff_zero.2 continuous_arcsin).times_cont_diff_at) $
λ hx, times_cont_diff_at_arcsin hx.1 hx.2⟩
lemma measurable_arcsin : measurable arcsin := continuous_arcsin.measurable
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
If the argument is not between `-1` and `1` it defaults to `π / 2` -/
@[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
lemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl
lemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=
by simp [arccos]
lemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=
by unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
lemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=
by unfold arccos; linarith [arcsin_le_pi_div_two x]
lemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=
by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
lemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=
by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma strict_mono_decr_on_arccos : strict_mono_decr_on arccos (Icc (-1) 1) :=
λ x hx y hy h, sub_lt_sub_left (strict_mono_incr_on_arcsin hx hy h) _
lemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_mono_decr_on_arccos.inj_on
lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arccos x = arccos y ↔ x = y :=
arccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[simp] lemma arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp] lemma arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
@[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x :=
by simp [arccos, sub_eq_zero]
@[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 :=
by simp [arccos, sub_eq_iff_eq_add]
@[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 :=
by rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]
lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=
by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]
lemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arccos x) = sqrt (1 - x ^ 2) :=
by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx₁ hx₂]
@[continuity]
lemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin
lemma has_strict_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_strict_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=
(has_strict_deriv_at_arcsin h₁ h₂).const_sub (π / 2)
lemma has_deriv_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
has_deriv_at arccos (-(1 / sqrt (1 - x ^ 2))) x :=
(has_deriv_at_arcsin h₁ h₂).const_sub (π / 2)
lemma times_cont_diff_at_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : with_top ℕ} :
times_cont_diff_at ℝ n arccos x :=
times_cont_diff_at_const.sub (times_cont_diff_at_arcsin h₁ h₂)
lemma has_deriv_within_at_arccos_Ici {x : ℝ} (h : x ≠ -1) :
has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Ici x) x :=
(has_deriv_within_at_arcsin_Ici h).const_sub _
lemma has_deriv_within_at_arccos_Iic {x : ℝ} (h : x ≠ 1) :
has_deriv_within_at arccos (-(1 / sqrt (1 - x ^ 2))) (Iic x) x :=
(has_deriv_within_at_arcsin_Iic h).const_sub _
lemma differentiable_within_at_arccos_Ici {x : ℝ} :
differentiable_within_at ℝ arccos (Ici x) x ↔ x ≠ -1 :=
(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Ici
lemma differentiable_within_at_arccos_Iic {x : ℝ} :
differentiable_within_at ℝ arccos (Iic x) x ↔ x ≠ 1 :=
(differentiable_within_at_const_sub_iff _).trans differentiable_within_at_arcsin_Iic
lemma differentiable_at_arccos {x : ℝ} :
differentiable_at ℝ arccos x ↔ x ≠ -1 ∧ x ≠ 1 :=
(differentiable_at_const_sub_iff _).trans differentiable_at_arcsin
@[simp] lemma deriv_arccos : deriv arccos = λ x, -(1 / sqrt (1 - x ^ 2)) :=
funext $ λ x, (deriv_const_sub _).trans $ by simp only [deriv_arcsin]
lemma differentiable_on_arccos : differentiable_on ℝ arccos {-1, 1}ᶜ :=
differentiable_on_arcsin.const_sub _
lemma times_cont_diff_on_arccos {n : with_top ℕ} :
times_cont_diff_on ℝ n arccos {-1, 1}ᶜ :=
times_cont_diff_on_const.sub times_cont_diff_on_arcsin
lemma times_cont_diff_at_arccos_iff {x : ℝ} {n : with_top ℕ} :
times_cont_diff_at ℝ n arccos x ↔ n = 0 ∨ (x ≠ -1 ∧ x ≠ 1) :=
by refine iff.trans ⟨λ h, _, λ h, _⟩ times_cont_diff_at_arcsin_iff;
simpa [arccos] using (@times_cont_diff_at_const _ _ _ _ _ _ _ _ _ _ (π / 2)).sub h
lemma measurable_arccos : measurable arccos := continuous_arccos.measurable
@[simp] lemma tan_pi_div_four : tan (π / 4) = 1 :=
begin
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four],
have h : (sqrt 2) / 2 > 0 := by cancel_denoms,
exact div_self (ne_of_gt h),
end
@[simp] lemma tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos]
lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x :=
by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩)
lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]
| or.inr hx0, _ := by simp [hx0.symm]
end
lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) :
tan x ≤ 0 :=
neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))
lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ}
(hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) :
tan x < tan y :=
begin
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],
exact div_lt_div
(sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy)
(cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩)
end
lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x)
(hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y :=
match le_total x 0, le_total y 0 with
| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact
tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0)
(neg_lt.2 hx₁) (neg_lt_neg hxy)
| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim
(λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁)
... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂)
(λ hy0, by rw [← hy0, tan_zero]; exact
tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁)
| or.inr hx0, or.inl hy0 := by linarith
| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy
end
lemma strict_mono_incr_on_tan : strict_mono_incr_on tan (Ioo (-(π / 2)) (π / 2)) :=
λ x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2
lemma inj_on_tan : inj_on tan (Ioo (-(π / 2)) (π / 2)) :=
strict_mono_incr_on_tan.inj_on
lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y :=
inj_on_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy
end real
namespace complex
open_locale real
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re
then real.arcsin (x.im / x.abs)
else if 0 ≤ x.im
then real.arcsin ((-x).im / x.abs) + π
else real.arcsin ((-x).im / x.abs) - π
lemma measurable_arg : measurable arg :=
have A : measurable (λ x : ℂ, real.arcsin (x.im / x.abs)),
from real.measurable_arcsin.comp (measurable_im.div measurable_norm),
have B : measurable (λ x : ℂ, real.arcsin ((-x).im / x.abs)),
from real.measurable_arcsin.comp ((measurable_im.comp measurable_neg).div measurable_norm),
measurable.ite (is_closed_le continuous_const continuous_re).measurable_set A $
measurable.ite (is_closed_le continuous_const continuous_im).measurable_set
(B.add_const _) (B.sub_const _)
lemma arg_le_pi (x : ℂ) : arg x ≤ π :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos))
else
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂, ← le_sub_iff_add_le, sub_self, real.arcsin_nonpos,
neg_im, neg_div, neg_nonpos];
exact div_nonneg hx₂ (abs_nonneg _)
else by rw [arg, if_neg hx₁, if_neg hx₂];
exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _)
(by linarith [real.pi_pos]))
lemma neg_pi_lt_arg (x : ℂ) : -π < arg x :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _)
else
have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁,
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂, ← sub_lt_iff_lt_add];
exact (lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _))
else by rw [arg, if_neg hx₁, if_neg hx₂, lt_sub_iff_add_lt, neg_add_self, real.arcsin_pos,
neg_im];
exact div_pos (neg_pos.2 (lt_of_not_ge hx₂)) (abs_pos.2 hx)
lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : 0 ≤ x.im) :
arg x = arg (-x) + π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg]
lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : x.im < 0) :
arg x = arg (-x) - π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg]
@[simp] lemma arg_zero : arg 0 = 0 :=
by simp [arg, le_refl]
@[simp] lemma arg_one : arg 1 = 0 :=
by simp [arg, zero_le_one]
@[simp] lemma arg_neg_one : arg (-1) = π :=
by simp [arg, le_refl, not_le.2 (@zero_lt_one ℝ _ _)]
@[simp] lemma arg_I : arg I = π / 2 :=
by simp [arg, le_refl]
@[simp] lemma arg_neg_I : arg (-I) = -(π / 2) :=
by simp [arg, le_refl]
lemma sin_arg (x : ℂ) : real.sin (arg x) = x.im / x.abs :=
by unfold arg; split_ifs;
simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg,
real.sin_neg]
private lemma cos_arg_of_re_nonneg {x : ℂ} (hx : x ≠ 0) (hxr : 0 ≤ x.re) :
real.cos (arg x) = x.re / x.abs :=
have 0 ≤ 1 - (x.im / abs x) ^ 2,
from sub_nonneg.2 $ by rw [pow_two, ← _root_.abs_mul_self, _root_.abs_mul, ← pow_two];
exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _),
by rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), ← real.mul_self_sqrt (abs_nonneg x),
arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, ← real.sqrt_mul (abs_nonneg _), ← real.sqrt_mul this,
sub_mul, div_pow, ← pow_two, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)),
one_mul, pow_two, mul_self_abs, norm_sq_apply, pow_two, add_sub_cancel, real.sqrt_mul_self hxr]
lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs :=
if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr
else
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
if hxi : 0 ≤ x.im
then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi,
cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this];
simp [neg_div]
else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)];
simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]
lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re :=
begin
by_cases h : x = 0,
{ simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },
rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
div_div_div_cancel_right _ (mt abs_eq_zero.1 h)]
end
lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) :
arg (cos x + sin x * I) = x :=
if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2
then
have hx₄ : 0 ≤ (cos x + sin x * I).re,
by simp; exact real.cos_nonneg_of_mem_Icc hx₃,
by rw [arg, if_pos hx₄];
simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2]
else if hx₄ : x < -(π / 2)
then
have hx₅ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬ 0 ≤ real.cos x, by simpa,
not_le.2 $ by rw ← real.cos_neg;
apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im :=
suffices real.sin x < 0, by simpa,
by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith,
suffices -π + -real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₅, if_neg hx₆];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]};
linarith
else
have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith,
have hx₆ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬0 ≤ real.cos x, by simpa,
not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₇ : 0 ≤ (cos x + sin x * I).im :=
suffices 0 ≤ real.sin x, by simpa,
by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith,
suffices π - real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₆, if_pos hx₇];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (abs y / abs x : ℂ) * x = y :=
have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx),
have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy),
⟨λ h,
begin
have hcos := congr_arg real.cos h,
rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos,
have hsin := congr_arg real.sin h,
rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin,
apply complex.ext,
{ rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm,
← mul_div_assoc, hcos, mul_div_cancel _ hax] },
{ rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero,
mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] }
end,
λ h,
have hre : abs (y / x) * x.re = y.re,
by rw ← of_real_div at h;
simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg re h,
have hre' : abs (x / y) * y.re = x.re,
by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have him : abs (y / x) * x.im = y.im,
by rw ← of_real_div at h;
simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg im h,
have him' : abs (x / y) * y.im = x.im,
by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have hxya : x.im / abs x = y.im / abs y,
by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay],
have hnxya : (-x).im / abs x = (-y).im / abs y,
by rw [neg_im, neg_im, neg_div, neg_div, hxya],
if hxr : 0 ≤ x.re
then
have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr,
by simp [arg, *] at *
else
have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr,
if hxi : 0 ≤ x.im
then
have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi,
by simp [arg, *] at *
else
have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi,
by simp [arg, *] at *⟩
lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x :=
if hx : x = 0 then by simp [hx]
else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $
by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc,
of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul,
div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm),
div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul]
lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y :=
if hy : y = 0 then by simp * at *
else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *,
by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul]
at h₂
lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 :=
by simp [arg, hx]
lemma arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 :=
begin
by_cases h₀ : z = 0, { simp [h₀, lt_irrefl, real.pi_ne_zero.symm] },
have h₀' : (abs z : ℂ) ≠ 0, by simpa,
rw [← arg_neg_one, arg_eq_arg_iff h₀ (neg_ne_zero.2 one_ne_zero), abs_neg, abs_one,
of_real_one, one_div, ← div_eq_inv_mul, div_eq_iff_mul_eq h₀', neg_one_mul,
ext_iff, neg_im, of_real_im, neg_zero, @eq_comm _ z.im, and.congr_left_iff],
rcases z with ⟨x, y⟩, simp only,
rintro rfl,
simp only [← of_real_def, of_real_eq_zero] at *,
simp [← ne.le_iff_lt h₀, @neg_eq_iff_neg_eq _ _ _ x, @eq_comm _ (-x)]
end
lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π :=
arg_eq_pi_iff.2 ⟨hx, rfl⟩
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`.
`log 0 = 0`-/
@[pp_nodot] noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I
lemma measurable_log : measurable log :=
(measurable_of_real.comp $ real.measurable_log.comp measurable_norm).add $
(measurable_of_real.comp measurable_arg).mul_const I
lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log]
lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log]
lemma neg_pi_lt_log_im (x : ℂ) : -π < (log x).im := by simp only [log_im, neg_pi_lt_arg]
lemma log_im_le_pi (x : ℂ) : (log x).im ≤ π := by simp only [log_im, arg_le_pi]
lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x :=
by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx,
← of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), ← mul_assoc,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]
lemma range_exp : range exp = {x | x ≠ 0} :=
set.ext $ λ x, ⟨by { rintro ⟨x, rfl⟩, exact exp_ne_zero x }, λ hx, ⟨log x, exp_log hx⟩⟩
lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π)
(hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y :=
by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy;
exact complex.ext
(real.exp_injective $
by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy)
(by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _),
arg_cos_add_sin_mul_I hx₁ hx₂, arg_cos_add_sin_mul_I hy₁ hy₂] using congr_arg arg hxy)
lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x :=
exp_inj_of_neg_pi_lt_of_le_pi
(by rw log_im; exact neg_pi_lt_arg _)
(by rw log_im; exact arg_le_pi _)
hx₁ hx₂ (by rw [exp_log (exp_ne_zero _)])
lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x :=
complex.ext
(by rw [log_re, of_real_re, abs_of_nonneg hx])
(by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])
lemma log_of_real_re (x : ℝ) : (log (x : ℂ)).re = real.log x := by simp [log_re]
@[simp] lemma log_zero : log 0 = 0 := by simp [log]
@[simp] lemma log_one : log 1 = 0 := by simp [log]
lemma log_neg_one : log (-1) = π * I := by simp [log]
lemma log_I : log I = π / 2 * I := by simp [log]
lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log]
lemma exists_pow_nat_eq (x : ℂ) {n : ℕ} (hn : 0 < n) : ∃ z, z ^ n = x :=
begin
by_cases hx : x = 0,
{ use 0, simp only [hx, zero_pow_eq_zero, hn] },
{ use exp (log x / n),
rw [← exp_nat_mul, mul_div_cancel', exp_log hx],
exact_mod_cast (pos_iff_ne_zero.mp hn) }
end
lemma exists_eq_mul_self (x : ℂ) : ∃ z, x = z * z :=
begin
obtain ⟨z, rfl⟩ := exists_pow_nat_eq x zero_lt_two,
exact ⟨z, pow_two z⟩
end
lemma two_pi_I_ne_zero : (2 * π * I : ℂ) ≠ 0 :=
by norm_num [real.pi_ne_zero, I_ne_zero]
lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :=
have real.exp (x.re) * real.cos (x.im) = 1 → real.cos x.im ≠ -1,
from λ h₁ h₂, begin
rw [h₂, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h₁,
have := real.exp_pos x.re,
rw ← h₁ at this,
exact absurd this (by norm_num)
end,
calc exp x = 1 ↔ (exp x).re = 1 ∧ (exp x).im = 0 : by simp [complex.ext_iff]
... ↔ real.cos x.im = 1 ∧ real.sin x.im = 0 ∧ x.re = 0 :
begin
rw exp_eq_exp_re_mul_sin_add_cos,
simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re,
real.exp_ne_zero],
split; finish [real.sin_eq_zero_iff_cos_eq]
end
... ↔ (∃ n : ℤ, ↑n * (2 * π) = x.im) ∧ (∃ n : ℤ, ↑n * π = x.im) ∧ x.re = 0 :
by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff]
... ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :
⟨λ ⟨⟨n, hn⟩, ⟨m, hm⟩, h⟩, ⟨n, by simp [complex.ext_iff, hn.symm, h]⟩,
λ ⟨n, hn⟩, ⟨⟨n, by simp [hn]⟩, ⟨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]⟩,
by simp [hn]⟩⟩
lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 :=
by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]
lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) :=
by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
/-- `complex.exp` as a `local_homeomorph` with `source = {z | -π < im z < π}` and
`target = {z | 0 < re z} ∪ {z | im z ≠ 0}`. This definition is used to prove that `complex.log`
is complex differentiable at all points but the negative real semi-axis. -/
def exp_local_homeomorph : local_homeomorph ℂ ℂ :=
local_homeomorph.of_continuous_open
{ to_fun := exp,
inv_fun := log,
source := {z : ℂ | z.im ∈ Ioo (- π) π},
target := {z : ℂ | 0 < z.re} ∪ {z : ℂ | z.im ≠ 0},
map_source' :=
begin
rintro ⟨x, y⟩ ⟨h₁ : -π < y, h₂ : y < π⟩,
refine (not_or_of_imp $ λ hz, _).symm,
obtain rfl : y = 0,
{ rw exp_im at hz,
simpa [(real.exp_pos _).ne', real.sin_eq_zero_iff_of_lt_of_lt h₁ h₂] using hz },
rw [mem_set_of_eq, ← of_real_def, exp_of_real_re],
exact real.exp_pos x
end,
map_target' := λ z h,
suffices 0 ≤ z.re ∨ z.im ≠ 0,
by simpa [log_im, neg_pi_lt_arg, (arg_le_pi _).lt_iff_ne, arg_eq_pi_iff, not_and_distrib],
h.imp (λ h, le_of_lt h) id,
left_inv' := λ x hx, log_exp hx.1 (le_of_lt hx.2),
right_inv' := λ x hx, exp_log $ by { rintro rfl, simpa [lt_irrefl] using hx } }
continuous_exp.continuous_on is_open_map_exp (is_open_Ioo.preimage continuous_im)
lemma has_strict_deriv_at_log {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) :
has_strict_deriv_at log x⁻¹ x :=
have h0 : x ≠ 0, by { rintro rfl, simpa [lt_irrefl] using h },
exp_local_homeomorph.has_strict_deriv_at_symm h h0 $
by simpa [exp_log h0] using has_strict_deriv_at_exp (log x)
lemma times_cont_diff_at_log {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) {n : with_top ℕ} :
times_cont_diff_at ℂ n log x :=
exp_local_homeomorph.times_cont_diff_at_symm_deriv (exp_ne_zero $ log x) h
(has_deriv_at_exp _) times_cont_diff_exp.times_cont_diff_at
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp
... = 0 : by simp
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp
... = 1 : by simp
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← of_real_sin, real.sin_pi]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← of_real_cos, real.cos_pi]; simp
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_add_pi (x : ℂ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x :=
by simp [sin_add]
lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x :=
by simp [cos_add]
lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
lemma sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma exp_pi_mul_I : exp (π * I) = -1 :=
by rw exp_mul_I; simp
theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 :=
begin
have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1,
{ rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 two_ne_zero', zero_mul,
add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, ← div_eq_iff (exp_ne_zero _), ← exp_sub],
field_simp only, congr' 3, ring },
rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm],
refine exists_congr (λ x, _),
refine (iff_of_eq $ congr_arg _ _).trans (mul_right_inj' $ mul_ne_zero two_ne_zero' I_ne_zero),
ring,
end
theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π :=
begin
rw [← complex.cos_sub_pi_div_two, cos_eq_zero_iff],
split,
{ rintros ⟨k, hk⟩,
use k + 1,
field_simp [eq_add_of_sub_eq hk],
ring },
{ rintros ⟨k, rfl⟩,
use k - 1,
field_simp,
ring }
end
theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, pow_two, pow_two, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma tan_eq_zero_iff {θ : ℂ} : tan θ = 0 ↔ ∃ k : ℤ, θ = k * π / 2 :=
begin
have h := (sin_two_mul θ).symm,
rw mul_assoc at h,
rw [tan, div_eq_zero_iff, ← mul_eq_zero, ← zero_mul ((1/2):ℂ), mul_one_div,
cancel_factors.cancel_factors_eq_div h two_ne_zero', mul_comm],
simpa only [zero_div, zero_mul, ne.def, not_false_iff] with field_simps using sin_eq_zero_iff,
end
lemma tan_ne_zero_iff {θ : ℂ} : tan θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π / 2 :=
by rw [← not_exists, not_iff_not, tan_eq_zero_iff]
lemma tan_int_mul_pi_div_two (n : ℤ) : tan (n * π/2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
by simp [tan, add_mul, sin_add, sin_int_mul_pi]
lemma cos_eq_cos_iff {x y : ℂ} :
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
calc cos x = cos y ↔ cos x - cos y = 0 : sub_eq_zero.symm
... ↔ -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos
... ↔ sin((x + y)/2) = 0 ∨ sin((x - y)/2) = 0 : by simp [(by norm_num : (2:ℂ) ≠ 0)]
... ↔ sin((x - y)/2) = 0 ∨ sin((x + y)/2) = 0 : or.comm
... ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ (∃ k :ℤ, y = 2 * k * π - x) :
begin
apply or_congr;
field_simp [sin_eq_zero_iff, (by norm_num : -(2:ℂ) ≠ 0), eq_sub_iff_add_eq',
sub_eq_iff_eq_add, mul_comm (2:ℂ), mul_right_comm _ (2:ℂ)],
split; { rintros ⟨k, rfl⟩, use -k, simp, },
end
... ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x : exists_or_distrib.symm
lemma sin_eq_sin_iff {x y : ℂ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
begin
simp only [← complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add],
refine exists_congr (λ k, or_congr _ _); refine eq.congr rfl _; field_simp; ring
end
lemma tan_add {x y : ℂ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
begin
rcases h with ⟨h1, h2⟩ | ⟨⟨k, rfl⟩, ⟨l, rfl⟩⟩,
{ rw [tan, sin_add, cos_add,
← div_div_div_cancel_right (sin x * cos y + cos x * sin y)
(mul_ne_zero (cos_ne_zero_iff.mpr h1) (cos_ne_zero_iff.mpr h2)),
add_div, sub_div],
simp only [←div_mul_div, ←tan, mul_one, one_mul,
div_self (cos_ne_zero_iff.mpr h1), div_self (cos_ne_zero_iff.mpr h2)] },
{ obtain ⟨t, hx, hy, hxy⟩ := ⟨tan_int_mul_pi_div_two, t (2*k+1), t (2*l+1), t (2*k+1+(2*l+1))⟩,
simp only [int.cast_add, int.cast_bit0, int.cast_mul, int.cast_one, hx, hy] at hx hy hxy,
rw [hx, hy, add_zero, zero_div,
mul_div_assoc, mul_div_assoc, ← add_mul (2*(k:ℂ)+1) (2*l+1) (π/2), ← mul_div_assoc, hxy] },
end
lemma tan_add' {x y : ℂ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (or.inl h)
lemma tan_two_mul {z : ℂ} : tan (2 * z) = 2 * tan z / (1 - tan z ^ 2) :=
begin
by_cases h : ∀ k : ℤ, z ≠ (2 * k + 1) * π / 2,
{ rw [two_mul, two_mul, pow_two, tan_add (or.inl ⟨h, h⟩)] },
{ rw not_forall_not at h,
rw [two_mul, two_mul, pow_two, tan_add (or.inr ⟨h, h⟩)] },
end
lemma tan_add_mul_I {x y : ℂ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y * I ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y * I = (2 * l + 1) * π / 2)) :
tan (x + y*I) = (tan x + tanh y * I) / (1 - tan x * tanh y * I) :=
by rw [tan_add h, tan_mul_I, mul_assoc]
lemma tan_eq {z : ℂ}
(h : ((∀ k : ℤ, (z.re:ℂ) ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, (z.im:ℂ) * I ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, (z.re:ℂ) = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, (z.im:ℂ) * I = (2 * l + 1) * π / 2)) :
tan z = (tan z.re + tanh z.im * I) / (1 - tan z.re * tanh z.im * I) :=
by convert tan_add_mul_I h; exact (re_add_im z).symm
lemma has_strict_deriv_at_tan {x : ℂ} (h : cos x ≠ 0) :
has_strict_deriv_at tan (1 / (cos x)^2) x :=
begin
convert (has_strict_deriv_at_sin x).div (has_strict_deriv_at_cos x) h,
rw ← sin_sq_add_cos_sq x,
ring,
end
lemma has_deriv_at_tan {x : ℂ} (h : cos x ≠ 0) :
has_deriv_at tan (1 / (cos x)^2) x :=
(has_strict_deriv_at_tan h).has_deriv_at
lemma tendsto_abs_tan_of_cos_eq_zero {x : ℂ} (hx : cos x = 0) :
tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top :=
begin
simp only [tan_eq_sin_div_cos, ← norm_eq_abs, normed_field.norm_div],
have A : sin x ≠ 0 := λ h, by simpa [*, pow_two] using sin_sq_add_cos_sq x,
have B : tendsto cos (𝓝[{x}ᶜ] (x)) (𝓝[{0}ᶜ] 0),
{ refine tendsto_inf.2 ⟨tendsto.mono_left _ inf_le_left, tendsto_principal.2 _⟩,
exacts [continuous_cos.tendsto' x 0 hx,
hx ▸ (has_deriv_at_cos _).eventually_ne (neg_ne_zero.2 A)] },
exact continuous_sin.continuous_within_at.norm.mul_at_top (norm_pos_iff.2 A)
(tendsto_norm_nhds_within_zero.comp B).inv_tendsto_zero,
end
lemma tendsto_abs_tan_at_top (k : ℤ) :
tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top :=
tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩
@[simp] lemma continuous_at_tan {x : ℂ} : continuous_at tan x ↔ cos x ≠ 0 :=
begin
refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩,
exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _
(hc.norm.tendsto.mono_left inf_le_left)
end
@[simp] lemma differentiable_at_tan {x : ℂ} : differentiable_at ℂ tan x ↔ cos x ≠ 0:=
⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩
@[simp] lemma deriv_tan (x : ℂ) : deriv tan x = 1 / (cos x)^2 :=
if h : cos x = 0 then
have ¬differentiable_at ℂ tan x := mt differentiable_at_tan.1 (not_not.2 h),
by simp [deriv_zero_of_not_differentiable_at this, h, pow_two]
else (has_deriv_at_tan h).deriv
lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} :=
continuous_on_sin.div continuous_on_cos $ λ x, id
@[continuity]
lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) :=
continuous_on_iff_continuous_restrict.1 continuous_on_tan
@[simp] lemma times_cont_diff_at_tan {x : ℂ} {n : with_top ℕ} :
times_cont_diff_at ℂ n tan x ↔ cos x ≠ 0 :=
⟨λ h, continuous_at_tan.1 h.continuous_at,
times_cont_diff_sin.times_cont_diff_at.div times_cont_diff_cos.times_cont_diff_at⟩
lemma cos_eq_iff_quadratic {z w : ℂ} :
cos z = w ↔ (exp (z * I)) ^ 2 - 2 * w * exp (z * I) + 1 = 0 :=
begin
rw ← sub_eq_zero,
field_simp [cos, exp_neg, exp_ne_zero],
refine eq.congr _ rfl,
ring
end
lemma cos_surjective : function.surjective cos :=
begin
intro x,
obtain ⟨w, w₀, hw⟩ : ∃ w ≠ 0, 1 * w * w + (-2 * x) * w + 1 = 0,
{ rcases exists_quadratic_eq_zero one_ne_zero (exists_eq_mul_self _) with ⟨w, hw⟩,
refine ⟨w, _, hw⟩,
rintro rfl,
simpa only [zero_add, one_ne_zero, mul_zero] using hw },
refine ⟨log w / I, cos_eq_iff_quadratic.2 _⟩,
rw [div_mul_cancel _ I_ne_zero, exp_log w₀],
convert hw,
ring
end
@[simp] lemma range_cos : range cos = set.univ :=
cos_surjective.range_eq
lemma sin_surjective : function.surjective sin :=
begin
intro x,
rcases cos_surjective x with ⟨z, rfl⟩,
exact ⟨z + π / 2, sin_add_pi_div_two z⟩
end
@[simp] lemma range_sin : range sin = set.univ :=
sin_surjective.range_eq
end complex
section log_deriv
open complex
variables {α : Type*}
lemma measurable.carg [measurable_space α] {f : α → ℂ} (h : measurable f) :
measurable (λ x, arg (f x)) :=
measurable_arg.comp h
lemma measurable.clog [measurable_space α] {f : α → ℂ} (h : measurable f) :
measurable (λ x, log (f x)) :=
measurable_log.comp h
lemma filter.tendsto.clog {l : filter α} {f : α → ℂ} {x : ℂ} (h : tendsto f l (𝓝 x))
(hx : 0 < x.re ∨ x.im ≠ 0) :
tendsto (λ t, log (f t)) l (𝓝 $ log x) :=
(has_strict_deriv_at_log hx).continuous_at.tendsto.comp h
variables [topological_space α]
lemma continuous_at.clog {f : α → ℂ} {x : α} (h₁ : continuous_at f x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_at (λ t, log (f t)) x :=
h₁.clog h₂
lemma continuous_within_at.clog {f : α → ℂ} {s : set α} {x : α} (h₁ : continuous_within_at f s x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_within_at (λ t, log (f t)) s x :=
h₁.clog h₂
lemma continuous_on.clog {f : α → ℂ} {s : set α} (h₁ : continuous_on f s)
(h₂ : ∀ x ∈ s, 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_on (λ t, log (f t)) s :=
λ x hx, (h₁ x hx).clog (h₂ x hx)
lemma continuous.clog {f : α → ℂ} (h₁ : continuous f) (h₂ : ∀ x, 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous (λ t, log (f t)) :=
continuous_iff_continuous_at.2 $ λ x, h₁.continuous_at.clog (h₂ x)
variables {E : Type*} [normed_group E] [normed_space ℂ E]
lemma has_strict_fderiv_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
(h₁ : has_strict_fderiv_at f f' x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_fderiv_at (λ t, log (f t)) ((f x)⁻¹ • f') x :=
(has_strict_deriv_at_log h₂).comp_has_strict_fderiv_at x h₁
lemma has_strict_deriv_at.clog {f : ℂ → ℂ} {f' x : ℂ} (h₁ : has_strict_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_deriv_at (λ t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h₂).comp x h₁ }
lemma has_fderiv_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
(h₁ : has_fderiv_at f f' x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_at (λ t, log (f t)) ((f x)⁻¹ • f') x :=
(has_strict_deriv_at_log h₂).has_deriv_at.comp_has_fderiv_at x h₁
lemma has_deriv_at.clog {f : ℂ → ℂ} {f' x : ℂ} (h₁ : has_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_at (λ t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h₂).has_deriv_at.comp x h₁ }
lemma differentiable_at.clog {f : E → ℂ} {x : E} (h₁ : differentiable_at ℂ f x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_at ℂ (λ t, log (f t)) x :=
(h₁.has_fderiv_at.clog h₂).differentiable_at
lemma has_fderiv_within_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {s : set E} {x : E}
(h₁ : has_fderiv_within_at f f' s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_within_at (λ t, log (f t)) ((f x)⁻¹ • f') s x :=
(has_strict_deriv_at_log h₂).has_deriv_at.comp_has_fderiv_within_at x h₁
lemma has_deriv_within_at.clog {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
(h₁ : has_deriv_within_at f f' s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_within_at (λ t, log (f t)) (f' / f x) s x :=
by { rw div_eq_inv_mul,
exact (has_strict_deriv_at_log h₂).has_deriv_at.comp_has_deriv_within_at x h₁ }
lemma differentiable_within_at.clog {f : E → ℂ} {s : set E} {x : E}
(h₁ : differentiable_within_at ℂ f s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_within_at ℂ (λ t, log (f t)) s x :=
(h₁.has_fderiv_within_at.clog h₂).differentiable_within_at
lemma differentiable_on.clog {f : E → ℂ} {s : set E}
(h₁ : differentiable_on ℂ f s) (h₂ : ∀ x ∈ s, 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_on ℂ (λ t, log (f t)) s :=
λ x hx, (h₁ x hx).clog (h₂ x hx)
lemma differentiable.clog {f : E → ℂ} (h₁ : differentiable ℂ f)
(h₂ : ∀ x, 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable ℂ (λ t, log (f t)) :=
λ x, (h₁ x).clog (h₂ x)
end log_deriv
namespace polynomial.chebyshev
open polynomial complex
/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the
value `cos (n * θ)`. -/
lemma T_complex_cos (θ : ℂ) :
∀ n, (T ℂ n).eval (cos θ) = cos (n * θ)
| 0 := by simp only [T_zero, eval_one, nat.cast_zero, zero_mul, cos_zero]
| 1 := by simp only [eval_X, one_mul, T_one, nat.cast_one]
| (n + 2) :=
begin
simp only [eval_X, eval_one, T_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul],
rw [T_complex_cos (n + 1), T_complex_cos n],
have aux : sin θ * sin θ = 1 - cos θ * cos θ,
{ rw ← sin_sq_add_cos_sq θ, ring, },
simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux],
ring,
end
/-- `cos (n * θ)` is equal to the `n`-th Chebyshev polynomial of the first kind evaluated
on `cos θ`. -/
lemma cos_nat_mul (n : ℕ) (θ : ℂ) :
cos (n * θ) = (T ℂ n).eval (cos θ) :=
(T_complex_cos θ n).symm
/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the
value `sin ((n+1) * θ) / sin θ`. -/
lemma U_complex_cos (θ : ℂ) (n : ℕ) :
(U ℂ n).eval (cos θ) * sin θ = sin ((n+1) * θ) :=
begin
induction n with d hd,
{ simp only [U_zero, nat.cast_zero, eval_one, mul_one, zero_add, one_mul] },
{ rw U_eq_X_mul_U_add_T,
simp only [eval_add, eval_mul, eval_X, T_complex_cos, add_mul, mul_assoc, hd, one_mul],
conv_rhs { rw [sin_add, mul_comm] },
push_cast,
simp only [add_mul, one_mul] }
end
/-- `sin ((n + 1) * θ)` is equal to `sin θ` multiplied with the `n`-th Chebyshev polynomial of the
second kind evaluated on `cos θ`. -/
lemma sin_nat_succ_mul (n : ℕ) (θ : ℂ) :
sin ((n + 1) * θ) = (U ℂ n).eval (cos θ) * sin θ :=
(U_complex_cos θ n).symm
end polynomial.chebyshev
namespace real
open_locale real
lemma tan_add {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)
∨ ((∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
by simpa only [← complex.of_real_inj, complex.of_real_sub, complex.of_real_add, complex.of_real_div,
complex.of_real_mul, complex.of_real_tan]
using @complex.tan_add (x:ℂ) (y:ℂ) (by convert h; norm_cast)
lemma tan_add' {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2)) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (or.inl h)
lemma tan_two_mul {x:ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) :=
by simpa only [← complex.of_real_inj, complex.of_real_sub, complex.of_real_div, complex.of_real_pow,
complex.of_real_mul, complex.of_real_tan, complex.of_real_bit0, complex.of_real_one]
using complex.tan_two_mul
theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 :=
by exact_mod_cast @complex.cos_eq_zero_iff θ
theorem cos_ne_zero_iff {θ : ℝ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
lemma tan_ne_zero_iff {θ : ℝ} : tan θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π / 2 :=
by rw [← complex.of_real_ne_zero, complex.of_real_tan, complex.tan_ne_zero_iff]; norm_cast
lemma tan_eq_zero_iff {θ : ℝ} : tan θ = 0 ↔ ∃ k : ℤ, θ = k * π / 2 :=
by rw [← not_iff_not, not_exists, ← ne, tan_ne_zero_iff]
lemma tan_int_mul_pi_div_two (n : ℤ) : tan (n * π/2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
by rw tan_eq_zero_iff; use (2*n); field_simp [mul_comm ((n:ℝ)*(π:ℝ)) 2, ← mul_assoc]
lemma cos_eq_cos_iff {x y : ℝ} :
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
by exact_mod_cast @complex.cos_eq_cos_iff x y
lemma sin_eq_sin_iff {x y : ℝ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
by exact_mod_cast @complex.sin_eq_sin_iff x y
lemma has_strict_deriv_at_tan {x : ℝ} (h : cos x ≠ 0) :
has_strict_deriv_at tan (1 / (cos x)^2) x :=
by exact_mod_cast (complex.has_strict_deriv_at_tan (by exact_mod_cast h)).real_of_complex
lemma has_deriv_at_tan {x : ℝ} (h : cos x ≠ 0) :
has_deriv_at tan (1 / (cos x)^2) x :=
by exact_mod_cast (complex.has_deriv_at_tan (by exact_mod_cast h)).real_of_complex
lemma tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) :
tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top :=
begin
have hx : complex.cos x = 0, by exact_mod_cast hx,
simp only [← complex.abs_of_real, complex.of_real_tan],
refine (complex.tendsto_abs_tan_of_cos_eq_zero hx).comp _,
refine tendsto.inf complex.continuous_of_real.continuous_at _,
exact tendsto_principal_principal.2 (λ y, mt complex.of_real_inj.1)
end
lemma tendsto_abs_tan_at_top (k : ℤ) :
tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top :=
tendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩
lemma continuous_at_tan {x : ℝ} : continuous_at tan x ↔ cos x ≠ 0 :=
begin
refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩,
exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _
(hc.norm.tendsto.mono_left inf_le_left)
end
lemma differentiable_at_tan {x : ℝ} : differentiable_at ℝ tan x ↔ cos x ≠ 0 :=
⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩
@[simp] lemma deriv_tan (x : ℝ) : deriv tan x = 1 / (cos x)^2 :=
if h : cos x = 0 then
have ¬differentiable_at ℝ tan x := mt differentiable_at_tan.1 (not_not.2 h),
by simp [deriv_zero_of_not_differentiable_at this, h, pow_two]
else (has_deriv_at_tan h).deriv
@[simp] lemma times_cont_diff_at_tan {n x} : times_cont_diff_at ℝ n tan x ↔ cos x ≠ 0 :=
⟨λ h, continuous_at_tan.1 h.continuous_at,
λ h, (complex.times_cont_diff_at_tan.2 $ by exact_mod_cast h).real_of_complex⟩
lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} :=
λ x hx, (continuous_at_tan.2 hx).continuous_within_at
@[continuity]
lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) :=
continuous_on_iff_continuous_restrict.1 continuous_on_tan
lemma has_deriv_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) :
has_deriv_at tan (1 / (cos x)^2) x :=
has_deriv_at_tan (cos_pos_of_mem_Ioo h).ne'
lemma differentiable_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) :
differentiable_at ℝ tan x :=
(has_deriv_at_tan_of_mem_Ioo h).differentiable_at
lemma continuous_on_tan_Ioo : continuous_on tan (Ioo (-(π/2)) (π/2)) :=
λ x hx, (differentiable_at_tan_of_mem_Ioo hx).continuous_at.continuous_within_at
lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[Iio (π/2)] (π/2)) (𝓝 1) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[Iio (π/2)] (π/2)) (𝓝[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[Iio (π/2)] (π/2)) at_top :=
begin
convert tendsto_cos_pi_div_two.inv_tendsto_zero.at_top_mul zero_lt_one
tendsto_sin_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
lemma tendsto_sin_neg_pi_div_two : tendsto sin (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝 (-1)) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Ioi (left_mem_Ico.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[Ioi (-(π/2))] (-(π/2))) at_bot :=
begin
convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.at_top_mul_neg (by norm_num)
tendsto_sin_neg_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
lemma surj_on_tan : surj_on tan (Ioo (-(π / 2)) (π / 2)) univ :=
have _ := neg_lt_self pi_div_two_pos,
continuous_on_tan_Ioo.surj_on_of_tendsto (nonempty_Ioo.2 this)
(by simp [tendsto_tan_neg_pi_div_two, this]) (by simp [tendsto_tan_pi_div_two, this])
lemma tan_surjective : function.surjective tan :=
λ x, surj_on_tan.subset_range trivial
lemma image_tan_Ioo : tan '' (Ioo (-(π / 2)) (π / 2)) = univ :=
univ_subset_iff.1 surj_on_tan
/-- `real.tan` as an `order_iso` between `(-(π / 2), π / 2)` and `ℝ`. -/
def tan_order_iso : Ioo (-(π / 2)) (π / 2) ≃o ℝ :=
(strict_mono_incr_on_tan.order_iso _ _).trans $ (order_iso.set_congr _ _ image_tan_Ioo).trans
order_iso.set.univ
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and
`arctan x < π / 2` -/
@[pp_nodot] noncomputable def arctan (x : ℝ) : ℝ :=
tan_order_iso.symm x
@[simp] lemma tan_arctan (x : ℝ) : tan (arctan x) = x :=
tan_order_iso.apply_symm_apply x
lemma arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) :=
subtype.coe_prop _
lemma arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
subtype.ext_iff.1 $ tan_order_iso.symm_apply_apply ⟨x, hx₁, hx₂⟩
lemma cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) :=
cos_pos_of_mem_Ioo $ arctan_mem_Ioo x
lemma cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) :=
by rw [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan]
lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) :=
by rw [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) :=
by rw [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
(arctan_mem_Ioo x).2
lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
(arctan_mem_Ioo x).1
lemma arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / sqrt (1 + x ^ 2)) :=
eq.symm $ arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo $ arctan_mem_Ioo x)
lemma arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1:ℝ)) 1) :
arcsin x = arctan (x / sqrt (1 - x ^ 2)) :=
begin
rw [arctan_eq_arcsin, div_pow, sqr_sqrt, one_add_div, div_div_eq_div_mul,
← sqrt_mul, mul_div_cancel', sub_add_cancel, sqrt_one, div_one];
nlinarith [h.1, h.2],
end
@[simp] lemma arctan_zero : arctan 0 = 0 :=
by simp [arctan_eq_arcsin]
lemma arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) :
arctan y = x :=
inj_on_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h])
@[simp] lemma arctan_one : arctan 1 = π / 4 :=
arctan_eq_of_tan_eq tan_pi_div_four $ by split; linarith [pi_pos]
@[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x :=
by simp [arctan_eq_arcsin, neg_div]
@[continuity]
lemma continuous_arctan : continuous arctan :=
continuous_subtype_coe.comp tan_order_iso.to_homeomorph.continuous_inv_fun
lemma continuous_at_arctan {x : ℝ} : continuous_at arctan x := continuous_arctan.continuous_at
/-- `real.tan` as a `local_homeomorph` between `(-(π / 2), π / 2)` and the whole line. -/
def tan_local_homeomorph : local_homeomorph ℝ ℝ :=
{ to_fun := tan,
inv_fun := arctan,
source := Ioo (-(π / 2)) (π / 2),
target := univ,
map_source' := maps_to_univ _ _,
map_target' := λ y hy, arctan_mem_Ioo y,
left_inv' := λ x hx, arctan_tan hx.1 hx.2,
right_inv' := λ y hy, tan_arctan y,
open_source := is_open_Ioo,
open_target := is_open_univ,
continuous_to_fun := continuous_on_tan_Ioo,
continuous_inv_fun := continuous_arctan.continuous_on }
@[simp] lemma coe_tan_local_homeomorph : ⇑tan_local_homeomorph = tan := rfl
@[simp] lemma coe_tan_local_homeomorph_symm : ⇑tan_local_homeomorph.symm = arctan := rfl
lemma has_strict_deriv_at_arctan (x : ℝ) : has_strict_deriv_at arctan (1 / (1 + x^2)) x :=
have A : cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne',
by simpa [cos_sq_arctan]
using tan_local_homeomorph.has_strict_deriv_at_symm trivial (by simpa) (has_strict_deriv_at_tan A)
lemma has_deriv_at_arctan (x : ℝ) : has_deriv_at arctan (1 / (1 + x^2)) x :=
(has_strict_deriv_at_arctan x).has_deriv_at
lemma differentiable_at_arctan (x : ℝ) : differentiable_at ℝ arctan x :=
(has_deriv_at_arctan x).differentiable_at
lemma differentiable_arctan : differentiable ℝ arctan := differentiable_at_arctan
@[simp] lemma deriv_arctan : deriv arctan = (λ x, 1 / (1 + x^2)) :=
funext $ λ x, (has_deriv_at_arctan x).deriv
lemma times_cont_diff_arctan {n : with_top ℕ} : times_cont_diff ℝ n arctan :=
times_cont_diff_iff_times_cont_diff_at.2 $ λ x,
have cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne',
tan_local_homeomorph.times_cont_diff_at_symm_deriv (by simpa) trivial (has_deriv_at_tan this)
(times_cont_diff_at_tan.2 this)
lemma measurable_arctan : measurable arctan := continuous_arctan.measurable
end real
section
/-!
### Lemmas for derivatives of the composition of `real.arctan` with a differentiable function
In this section we register lemmas for the derivatives of the composition of `real.arctan` with a
differentiable function, for standalone use and use with `simp`. -/
open real
lemma measurable.arctan {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, arctan (f x)) :=
measurable_arctan.comp hf
section deriv
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
lemma has_strict_deriv_at.arctan (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=
(real.has_strict_deriv_at_arctan (f x)).comp x hf
lemma has_deriv_at.arctan (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=
(real.has_deriv_at_arctan (f x)).comp x hf
lemma has_deriv_within_at.arctan (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) * f') s x :=
(real.has_deriv_at_arctan (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_arctan (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λ x, arctan (f x)) s x = (1 / (1 + (f x)^2)) * (deriv_within f s x) :=
hf.has_deriv_within_at.arctan.deriv_within hxs
@[simp] lemma deriv_arctan (hc : differentiable_at ℝ f x) :
deriv (λ x, arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) :=
hc.has_deriv_at.arctan.deriv
end deriv
section fderiv
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E}
{s : set E} {n : with_top ℕ}
lemma has_strict_fderiv_at.arctan (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') x :=
(has_strict_deriv_at_arctan (f x)).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.arctan (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') x :=
(has_deriv_at_arctan (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.arctan (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, arctan (f x)) ((1 / (1 + (f x)^2)) • f') s x :=
(has_deriv_at_arctan (f x)).comp_has_fderiv_within_at x hf
lemma fderiv_within_arctan (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λ x, arctan (f x)) s x = (1 / (1 + (f x)^2)) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.arctan.fderiv_within hxs
@[simp] lemma fderiv_arctan (hc : differentiable_at ℝ f x) :
fderiv ℝ (λ x, arctan (f x)) x = (1 / (1 + (f x)^2)) • (fderiv ℝ f x) :=
hc.has_fderiv_at.arctan.fderiv
lemma differentiable_within_at.arctan (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.arctan (f x)) s x :=
hf.has_fderiv_within_at.arctan.differentiable_within_at
@[simp] lemma differentiable_at.arctan (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λ x, arctan (f x)) x :=
hc.has_fderiv_at.arctan.differentiable_at
lemma differentiable_on.arctan (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λ x, arctan (f x)) s :=
λ x h, (hc x h).arctan
@[simp] lemma differentiable.arctan (hc : differentiable ℝ f) :
differentiable ℝ (λ x, arctan (f x)) :=
λ x, (hc x).arctan
lemma times_cont_diff_at.arctan (h : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, arctan (f x)) x :=
times_cont_diff_arctan.times_cont_diff_at.comp x h
lemma times_cont_diff.arctan (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, arctan (f x)) :=
times_cont_diff_arctan.comp h
lemma times_cont_diff_within_at.arctan (h : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, arctan (f x)) s x :=
times_cont_diff_arctan.comp_times_cont_diff_within_at h
lemma times_cont_diff_on.arctan (h : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, arctan (f x)) s :=
times_cont_diff_arctan.comp_times_cont_diff_on h
end fderiv
end
|
8d0f1f75800bcab7b9e7702c3d556973c78cf832 | 05d69962fb9deab19838de9bbcf33ebdbf8faa57 | /proto.lean | 27d7df3ed38b4a1d6cecc363c1170a9be8986dc1 | [] | no_license | pj0y1/polynom | 6eb7c96dbf34960be5721a232a67f7a592aedf7a | 9e198cc9104017fae7774574f141197bb295ee66 | refs/heads/master | 1,611,193,417,139 | 1,501,472,138,000 | 1,501,472,138,000 | 64,856,946 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,316 | lean | /- ℕ is a add_comm_cancel_monoid
(Π A B:Type , A -> B) shares the same algebra structure with B,
thus monomial:A -> ℕ is add_comm_cancel_monoid, hence proved
comm_cancel_monoid A -> semiring B, is euqivalent as proving
polynomial property
-/
import mul_aux
open classical -- for ite
open set function subtype
open function_aux
set_option unifier.max_steps 180000
definition proto (A B:Type)[has_zero B]: Type :=
subtype (λf: A-> B, finite (supp f))
namespace proto -- prototype for both monomials and polynomials
variables {A B:Type}
definition add [add_monoid B](f g: proto A B): proto A B :=
tag (elt_of f + elt_of g)
(@add_finite_supp _ _ _ _ _ (has_property f)(has_property g))
-- notation f `**` g := add f g
theorem add_comm [add_comm_monoid B](f g:proto A B): add f g = add g f :=
by apply subtype.eq; apply function.add_comm
theorem add_assoc [add_monoid B](f g h:proto A B): add (add f g) h = add f (add g h):=
by apply subtype.eq; apply function.add_assoc
definition zero [add_monoid B]: proto A B :=
tag (function.zero)
(by rewrite zero_empty_supp;apply finite_empty)
theorem zero_add [add_monoid B](f: proto A B): add zero f = f :=
by apply subtype.eq; apply function.zero_add
theorem add_zero [add_monoid B](f: proto A B): add f zero = f :=
by apply subtype.eq; apply function.add_zero
definition to_comm_monoid[instance][add_comm_monoid B]: comm_monoid (proto A B):=
{| comm_monoid,
mul := add,
mul_comm := add_comm,
mul_assoc := add_assoc,
one := zero,
one_mul := zero_add,
mul_one := add_zero
|}
definition to_monoid[instance][add_monoid B]: monoid (proto A B):=
{| monoid,
mul := add,
mul_assoc := add_assoc,
one := zero,
one_mul := zero_add,
mul_one := add_zero
|}
theorem add_left_cancel [add_left_cancel_monoid B] (f g h: proto A B)
(H: add f g = add f h): g = h :=
have elt_of f + elt_of g = elt_of f + elt_of h, from congr (eq.refl elt_of) H,
by apply subtype.eq; apply function.add_left_cancel (elt_of f);exact this
theorem add_right_cancel [add_right_cancel_monoid B]{f g h: proto A B}
(H: add g f= add h f): g = h :=
have elt_of g + elt_of f = elt_of h + elt_of f, from congr (eq.refl elt_of) H,
by apply subtype.eq; apply function.add_right_cancel (elt_of f);exact this
/-This is exactly ℕ (without considering order)-/
definition to_comm_cancel_monoid [instance][add_comm_cancel_monoid B]: comm_cancel_monoid (proto A B):=
{| comm_cancel_monoid,
mul := add,
one := zero,
mul_assoc := add_assoc,
mul_comm := add_comm,
mul_one := add_zero,
one_mul := zero_add,
mul_left_cancel := add_left_cancel |}
definition inv [add_group B](f: proto A B): proto A B :=
tag (neg (elt_of f)) (@neg_finite_supp _ _ _ _ (has_property f))
theorem add_left_inv [add_group B](f: proto A B): add (inv f) f = zero :=
by apply subtype.eq; apply function.add_left_inv
definition to_group [instance][add_group B]: group (proto A B) :=
{| group,
mul := add,
one := zero,
mul_assoc := add_assoc,
one_mul := zero_add,
mul_one := add_zero,
mul_left_inv := add_left_inv|}
definition to_comm_group [instance][add_comm_group B]: comm_group (proto A B):=
{|comm_group,
mul := add,
one := zero,
mul_assoc := add_assoc,
mul_comm := add_comm,
one_mul := zero_add,
mul_one := add_zero,
mul_left_inv := add_left_inv|}
section
variable [semiring B]
noncomputable definition mul[has_mul A](f g: proto A B):
proto A B :=
tag (function.mul (elt_of f) (elt_of g))
(@mul_finite_supp _ _ _ _ _ _ (has_property f) (has_property g))
theorem mul_assoc [comm_cancel_monoid A](f g k:proto A B):
mul (mul f g) k = mul f (mul g k) :=
have finite (supp (elt_of f)), from has_property f,
have finite (supp (elt_of g)), from has_property g,
have finite (supp (elt_of k)), from has_property k,
by apply subtype.eq; apply function_aux.mul_assoc
noncomputable definition one [monoid A]: proto A B :=
tag (@function.one A B _ _)(one_finite_supp)
theorem mul_one [monoid A](f:proto A B):
mul f one = f :=
have finite (supp (elt_of f)), from has_property f,
by apply subtype.eq; apply function_aux.mul_one
theorem one_mul [monoid A](f:proto A B):
mul one f = f :=
have finite (supp (elt_of f)), from has_property f,
by apply subtype.eq ; apply function_aux.one_mul
theorem mul_zero [has_mul A](f:proto A B):
mul f proto.zero = proto.zero :=
have finite (supp (elt_of f)), from has_property f,
by apply subtype.eq; apply function_aux.mul_zero
theorem zero_mul [monoid A](f:proto A B):
mul zero f = zero :=
have finite (supp (elt_of f)), from has_property f,
by apply subtype.eq; apply function_aux.zero_mul
theorem mul_left_distrib [has_mul A](f g k:proto A B):
mul f (add g k) = add (mul f g) (mul f k) :=
have finite (supp (elt_of f)), from has_property f,
have finite (supp (elt_of g)), from has_property g,
have finite (supp (elt_of k)), from has_property k,
by apply subtype.eq; apply function_aux.mul_left_distrib
theorem mul_right_distrib [has_mul A](f g k:proto A B):
mul (add f g) k = add (mul f k) (mul g k) :=
have finite (supp (elt_of f)), from has_property f,
have finite (supp (elt_of g)), from has_property g,
have finite (supp (elt_of k)), from has_property k,
by apply subtype.eq; apply function_aux.mul_right_distrib
noncomputable definition to_semiring [instance][comm_cancel_monoid A]:
semiring (proto A B):=
{| semiring,
add := add,
add_comm := add_comm,
add_assoc := add_assoc,
zero := zero,
add_zero := add_zero,
zero_add := zero_add,
mul := mul,
mul_assoc := mul_assoc,
mul_zero := mul_zero,
zero_mul := zero_mul,
one := one,
mul_one := mul_one,
one_mul := one_mul,
left_distrib := mul_left_distrib,
right_distrib := mul_right_distrib |}
end
section
variable [comm_semiring B]
theorem mul_comm[comm_semigroup A](f g : proto A B):
mul f g = mul g f :=
have finite (supp (elt_of f)), from has_property f,
have finite (supp (elt_of g)), from has_property g,
by apply subtype.eq; apply function_aux.mul_comm
noncomputable definition to_comm_semiring [instance][comm_cancel_monoid A]:
comm_semiring (proto A B):=
{| comm_semiring,
add := add,
add_comm := add_comm,
add_assoc := add_assoc,
zero := zero,
add_zero := add_zero,
zero_add := zero_add,
mul := mul,
mul_assoc := mul_assoc,
mul_zero := mul_zero,
zero_mul := zero_mul,
one := one,
mul_one := mul_one,
one_mul := one_mul,
left_distrib := mul_left_distrib,
right_distrib := mul_right_distrib,
mul_comm := mul_comm|}
end
section
variable [ring B]
noncomputable definition to_ring [instance][comm_cancel_monoid A]:
ring (proto A B) :=
{| ring,
add := add,
add_comm := add_comm,
add_assoc := add_assoc,
zero := zero,
add_zero := add_zero,
zero_add := zero_add,
neg := inv,
add_left_inv := add_left_inv,
mul := mul,
mul_assoc := mul_assoc,
one := one,
mul_one := mul_one,
one_mul := one_mul,
left_distrib := mul_left_distrib,
right_distrib := mul_right_distrib |}
end
section
variable [comm_ring B]
noncomputable definition to_comm_ring [instance][comm_cancel_monoid A]:
comm_ring (proto A B) :=
{| comm_ring,
add := add,
add_comm := add_comm,
add_assoc := add_assoc,
zero := zero,
add_zero := add_zero,
zero_add := zero_add,
neg := inv,
add_left_inv := add_left_inv,
mul := mul,
mul_comm := mul_comm,
mul_assoc := mul_assoc,
one := one,
mul_one := mul_one,
one_mul := one_mul,
left_distrib := mul_left_distrib,
right_distrib := mul_right_distrib |}
end
end proto
|
5d2149131e7b1fed7a56b1a219fb812b132719cb | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /hott/hit/pushout.hlean | 5608a3ccc8328ca811ba65324ee98e668c12439b | [
"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,093 | 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 pushout
-/
import .quotient cubical.square
open quotient eq sum equiv equiv.ops
namespace pushout
section
parameters {TL BL TR : Type} (f : TL → BL) (g : TL → TR)
local abbreviation A := BL + TR
inductive pushout_rel : A → A → Type :=
| Rmk : Π(x : TL), pushout_rel (inl (f x)) (inr (g x))
open pushout_rel
local abbreviation R := pushout_rel
definition pushout : Type := quotient R -- TODO: define this in root namespace
parameters {f g}
definition inl (x : BL) : pushout :=
class_of R (inl x)
definition inr (x : TR) : pushout :=
class_of R (inr x)
definition glue (x : TL) : inl (f x) = inr (g x) :=
eq_of_rel pushout_rel (Rmk f g x)
protected definition rec {P : pushout → Type} (Pinl : Π(x : BL), P (inl x))
(Pinr : Π(x : TR), P (inr x)) (Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x))
(y : pushout) : P y :=
begin
induction y,
{ cases a,
apply Pinl,
apply Pinr},
{ cases H, apply Pglue}
end
protected definition rec_on [reducible] {P : pushout → Type} (y : pushout)
(Pinl : Π(x : BL), P (inl x)) (Pinr : Π(x : TR), P (inr x))
(Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x)) : P y :=
rec Pinl Pinr Pglue y
theorem rec_glue {P : pushout → Type} (Pinl : Π(x : BL), P (inl x))
(Pinr : Π(x : TR), P (inr x)) (Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x))
(x : TL) : apdo (rec Pinl Pinr Pglue) (glue x) = Pglue x :=
!rec_eq_of_rel
protected definition elim {P : Type} (Pinl : BL → P) (Pinr : TR → P)
(Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) (y : pushout) : P :=
rec Pinl Pinr (λx, pathover_of_eq (Pglue x)) y
protected definition elim_on [reducible] {P : Type} (y : pushout) (Pinl : BL → P)
(Pinr : TR → P) (Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) : P :=
elim Pinl Pinr Pglue y
theorem elim_glue {P : Type} (Pinl : BL → P) (Pinr : TR → P)
(Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) (x : TL)
: ap (elim Pinl Pinr Pglue) (glue x) = Pglue x :=
begin
apply eq_of_fn_eq_fn_inv !(pathover_constant (glue x)),
rewrite [▸*,-apdo_eq_pathover_of_eq_ap,↑pushout.elim,rec_glue],
end
protected definition elim_type (Pinl : BL → Type) (Pinr : TR → Type)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) (y : pushout) : Type :=
elim Pinl Pinr (λx, ua (Pglue x)) y
protected definition elim_type_on [reducible] (y : pushout) (Pinl : BL → Type)
(Pinr : TR → Type) (Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) : Type :=
elim_type Pinl Pinr Pglue y
theorem elim_type_glue (Pinl : BL → Type) (Pinr : TR → Type)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) (x : TL)
: transport (elim_type Pinl Pinr Pglue) (glue x) = Pglue x :=
by rewrite [tr_eq_cast_ap_fn,↑elim_type,elim_glue];apply cast_ua_fn
end
end pushout
attribute pushout.inl pushout.inr [constructor]
attribute pushout.rec pushout.elim [unfold 10] [recursor 10]
attribute pushout.elim_type [unfold 9]
attribute pushout.rec_on pushout.elim_on [unfold 7]
attribute pushout.elim_type_on [unfold 6]
open sigma
namespace pushout
variables {TL BL TR : Type} (f : TL → BL) (g : TL → TR)
/- The non-dependent universal property -/
definition pushout_arrow_equiv (C : Type)
: (pushout f g → C) ≃ (Σ(i : BL → C) (j : TR → C), Πc, i (f c) = j (g c)) :=
begin
fapply equiv.MK,
{ intro f, exact ⟨λx, f (inl x), λx, f (inr x), λx, ap f (glue x)⟩},
{ intro v x, induction v with i w, induction w with j p, induction x,
exact (i a), exact (j a), exact (p x)},
{ intro v, induction v with i w, induction w with j p, esimp,
apply ap (λp, ⟨i, j, p⟩), apply eq_of_homotopy, intro x, apply elim_glue},
{ intro f, apply eq_of_homotopy, intro x, induction x: esimp,
apply eq_pathover, apply hdeg_square, esimp, apply elim_glue},
end
end pushout
|
5d72a93e743123036e57a9f6c0069cc8ff55afbb | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/topology/algebra/mul_action2.lean | 1e611c90f903a2ba45653782767cd777b1c8c617 | [
"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 | 7,646 | lean | /-
Copyright (c) 2021 Alex Kontorovich, Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, Heather Macbeth
-/
import topology.homeomorph
import group_theory.group_action.basic
/-!
# Monoid actions continuous in the second variable
In this file we define class `has_continuous_smul₂`. We say `has_continuous_smul₂ Γ T` if `Γ` acts
on `T` and for each `γ`, the map `x ↦ γ • x` is continuous. (This differs from
`has_continuous_smul`, which requires simultaneous continuity in both variables.)
## Main definitions
* `has_continuous_smul₂ Γ T` : typeclass saying that the map `x ↦ γ • x` is continuous on `T`;
* `properly_discontinuous_smul`: says that the scalar multiplication `(•) : Γ → T → T`
is properly discontinuous, that is, for any pair of compact sets `K, L` in `T`, only finitely
many `γ:Γ` move `K` to have nontrivial intersection with `L`.
* `homeomorph.smul`: scalar multiplication by an element of a group `Γ` acting on `T`
is a homeomorphism of `T`.
## Main results
* `is_open_map_quotient_mk_mul` : The quotient map by a group action is open.
* `t2_space_of_properly_discontinuous_smul_of_t2_space` : The quotient by a discontinuous group
action of a locally compact t2 space is t2.
## Tags
Hausdorff, discrete group, properly discontinuous, quotient space
-/
open_locale topological_space
open filter set
local attribute [instance] mul_action.orbit_rel
/-- Class `has_continuous_smul₂ Γ T` says that the scalar multiplication `(•) : Γ → T → T`
is continuous in the second argument. We use the same class for all kinds of multiplicative
actions, including (semi)modules and algebras.
-/
class has_continuous_smul₂ (Γ : Type*) (T : Type*) [topological_space T] [has_scalar Γ T]
: Prop :=
(continuous_smul₂ : ∀ γ : Γ, continuous (λ x : T, γ • x))
/-- Class `has_continuous_vadd₂ Γ T` says that the additive action `(+ᵥ) : Γ → T → T`
is continuous in the second argument. We use the same class for all kinds of additive actions,
including (semi)modules and algebras.
-/
class has_continuous_vadd₂ (Γ : Type*) (T : Type*) [topological_space T]
[has_vadd Γ T] : Prop :=
(continuous_vadd₂ : ∀ γ : Γ, continuous (λ x : T, γ +ᵥ x))
attribute [to_additive has_continuous_vadd₂] has_continuous_smul₂
export has_continuous_smul₂ (continuous_smul₂)
export has_continuous_vadd₂ (continuous_vadd₂)
/-- Class `properly_discontinuous_smul Γ T` says that the scalar multiplication `(•) : Γ → T → T`
is properly discontinuous, that is, for any pair of compact sets `K, L` in `T`, only finitely many
`γ:Γ` move `K` to have nontrivial intersection with `L`.
-/
class properly_discontinuous_smul (Γ : Type*) (T : Type*) [topological_space T]
[has_scalar Γ T] : Prop :=
(finite_disjoint_inter_image : ∀ {K L : set T}, is_compact K → is_compact L →
set.finite {γ : Γ | (((•) γ) '' K) ∩ L ≠ ∅ })
/-- Class `properly_discontinuous_vadd Γ T` says that the additive action `(+ᵥ) : Γ → T → T`
is properly discontinuous, that is, for any pair of compact sets `K, L` in `T`, only finitely many
`γ:Γ` move `K` to have nontrivial intersection with `L`.
-/
class properly_discontinuous_vadd (Γ : Type*) (T : Type*) [topological_space T]
[has_vadd Γ T] : Prop :=
(finite_disjoint_inter_image : ∀ {K L : set T}, is_compact K → is_compact L →
set.finite {γ : Γ | (((+ᵥ) γ) '' K) ∩ L ≠ ∅ })
attribute [to_additive] properly_discontinuous_smul
variables {Γ : Type*} [group Γ] {T : Type*} [topological_space T] [mul_action Γ T]
/-- A finite group action is always properly discontinuous
-/
@[priority 100, to_additive] instance fintype.properly_discontinuous_smul [fintype Γ] :
properly_discontinuous_smul Γ T :=
{ finite_disjoint_inter_image := λ _ _ _ _, set.finite.of_fintype _}
export properly_discontinuous_smul (finite_disjoint_inter_image)
export properly_discontinuous_vadd (finite_disjoint_inter_image)
/-- The homeomorphism given by scalar multiplication by a given element of a group `Γ` acting on
`T` is a homeomorphism from `T` to itself. -/
def homeomorph.smul {T : Type*} [topological_space T] {Γ : Type*} [group Γ]
[mul_action Γ T] [has_continuous_smul₂ Γ T] (γ : Γ) :
T ≃ₜ T :=
{ to_equiv := mul_action.to_perm_hom Γ T γ,
continuous_to_fun := continuous_smul₂ γ,
continuous_inv_fun := continuous_smul₂ γ⁻¹ }
/-- The homeomorphism given by affine-addition by an element of an additive group `Γ` acting on
`T` is a homeomorphism from `T` to itself. -/
def homeomorph.vadd {T : Type*} [topological_space T] {Γ : Type*} [add_group Γ]
[add_action Γ T] [has_continuous_vadd₂ Γ T] (γ : Γ) :
T ≃ₜ T :=
{ to_equiv := add_action.to_perm_hom T Γ γ,
continuous_to_fun := continuous_vadd₂ γ,
continuous_inv_fun := continuous_vadd₂ (-γ) }
attribute [to_additive homeomorph.vadd] homeomorph.smul
/-- The quotient map by a group action is open. -/
@[to_additive]
lemma is_open_map_quotient_mk_mul [has_continuous_smul₂ Γ T] :
is_open_map (quotient.mk : T → quotient (mul_action.orbit_rel Γ T)) :=
begin
intros U hU,
rw [is_open_coinduced, mul_action.quotient_preimage_image_eq_union_mul U],
exact is_open_Union (λ γ, (homeomorph.smul γ).is_open_map U hU)
end
/-- The quotient by a discontinuous group action of a locally compact t2 space is t2. -/
@[priority 100, to_additive] instance t2_space_of_properly_discontinuous_smul_of_t2_space
[t2_space T] [locally_compact_space T] [has_continuous_smul₂ Γ T]
[properly_discontinuous_smul Γ T] : t2_space (quotient (mul_action.orbit_rel Γ T)) :=
begin
set Q := quotient (mul_action.orbit_rel Γ T),
rw t2_space_iff_nhds,
let f : T → Q := quotient.mk,
have f_op : is_open_map f := is_open_map_quotient_mk_mul,
rintros ⟨x₀⟩ ⟨y₀⟩ (hxy : f x₀ ≠ f y₀),
show ∃ (U ∈ 𝓝 (f x₀)) (V ∈ 𝓝 (f y₀)), U ∩ V = ∅,
have hx₀y₀ : x₀ ≠ y₀ := ne_of_apply_ne _ hxy,
have hγx₀y₀ : ∀ γ : Γ, γ • x₀ ≠ y₀ := not_exists.mp (mt quotient.sound hxy.symm : _),
obtain ⟨K₀, L₀, K₀_in, L₀_in, hK₀, hL₀, hK₀L₀⟩ := t2_separation_compact_nhds hx₀y₀,
let bad_Γ_set := {γ : Γ | (((•) γ) '' K₀) ∩ L₀ ≠ ∅ },
have bad_Γ_finite : bad_Γ_set.finite := finite_disjoint_inter_image hK₀ hL₀,
choose u v hu hv u_v_disjoint using λ γ, t2_separation_nhds (hγx₀y₀ γ),
let U₀₀ := ⋂ γ ∈ bad_Γ_set, ((•) γ) ⁻¹' (u γ),
let U₀ := U₀₀ ∩ K₀,
let V₀₀ := ⋂ γ ∈ bad_Γ_set, v γ,
let V₀ := V₀₀ ∩ L₀,
have U_nhds : f '' U₀ ∈ 𝓝 (f x₀),
{ apply f_op.image_mem_nhds (inter_mem ((bInter_mem bad_Γ_finite).mpr $ λ γ hγ, _) K₀_in),
exact (has_continuous_smul₂.continuous_smul₂ γ).continuous_at (hu γ) },
have V_nhds : f '' V₀ ∈ 𝓝 (f y₀),
from f_op.image_mem_nhds (inter_mem ((bInter_mem bad_Γ_finite).mpr $ λ γ hγ, hv γ) L₀_in),
refine ⟨f '' U₀, U_nhds, f '' V₀, V_nhds, _⟩,
rw mul_action.image_inter_image_iff,
rintros x ⟨x_in_U₀₀, x_in_K₀⟩ γ,
by_cases H : γ ∈ bad_Γ_set,
{ rintros ⟨h, -⟩,
exact eq_empty_iff_forall_not_mem.mp (u_v_disjoint γ) (γ • x)
⟨(mem_Inter₂.mp x_in_U₀₀ γ H : _), mem_Inter₂.mp h γ H⟩ },
{ rintros ⟨-, h'⟩,
simp only [image_smul, not_not, mem_set_of_eq, ne.def] at H,
exact eq_empty_iff_forall_not_mem.mp H (γ • x) ⟨mem_image_of_mem _ x_in_K₀, h'⟩ },
end
|
5c75360a91f9cc678275caa21cec2ac3d17228cf | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/empty.lean | 115db4ea5546bbdc8aa617a7f3a110f6df1d276e | [
"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 | 180 | lean | --
open inhabited nonempty classical
noncomputable definition v1 : Prop := epsilon (λ x, true)
inductive Empty : Type
noncomputable definition v2 : Empty := epsilon (λ x, true)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.