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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
83772f1c303b6e932bba6188e66e71ed845094e0 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/data/padics/padic_integers.lean | b5e9dabfcac58714a078babeac2b86c096e9261a | [
"Apache-2.0"
] | permissive | vaibhavkarve/mathlib | a574aaf68c0a431a47fa82ce0637f0f769826bfe | 17f8340912468f49bdc30acdb9a9fa02eeb0473a | refs/heads/master | 1,621,263,802,637 | 1,585,399,588,000 | 1,585,399,588,000 | 250,833,447 | 0 | 0 | Apache-2.0 | 1,585,410,341,000 | 1,585,410,341,000 | null | UTF-8 | Lean | false | false | 10,731 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Mario Carneiro
-/
import data.int.modeq data.padics.padic_numbers ring_theory.ideals ring_theory.algebra
/-!
# p-adic integers
This file defines the p-adic integers ℤ_p as the subtype of ℚ_p with norm ≤ 1. We show that ℤ_p is a
complete nonarchimedean normed local ring.
## Important definitions
* `padic_int` : the type of p-adic numbers
## Notation
We introduce the notation ℤ_[p] for the p-adic integers.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking (prime p) as a type class argument.
Coercions into ℤ_p are set up to work with the `norm_cast` tactic.
## References
* [F. Q. Gouêva, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, p-adic integer
-/
open nat padic metric
noncomputable theory
open_locale classical
/-- The p-adic integers ℤ_p are the p-adic numbers with norm ≤ 1. -/
def padic_int (p : ℕ) [p.prime] := {x : ℚ_[p] // ∥x∥ ≤ 1}
notation `ℤ_[`p`]` := padic_int p
namespace padic_int
variables {p : ℕ} [nat.prime p]
/-- Addition on ℤ_p is inherited from ℚ_p. -/
def add : ℤ_[p] → ℤ_[p] → ℤ_[p]
| ⟨x, hx⟩ ⟨y, hy⟩ := ⟨x+y,
le_trans (padic_norm_e.nonarchimedean _ _) (max_le_iff.2 ⟨hx,hy⟩)⟩
/-- Multiplication on ℤ_p is inherited from ℚ_p. -/
def mul : ℤ_[p] → ℤ_[p] → ℤ_[p]
| ⟨x, hx⟩ ⟨y, hy⟩ := ⟨x*y,
begin rw padic_norm_e.mul, apply mul_le_one; {assumption <|> apply norm_nonneg} end⟩
/-- Negation on ℤ_p is inherited from ℚ_p. -/
def neg : ℤ_[p] → ℤ_[p]
| ⟨x, hx⟩ := ⟨-x, by simpa⟩
instance : ring ℤ_[p] :=
begin
refine { add := add,
mul := mul,
neg := neg,
zero := ⟨0, by simp [zero_le_one]⟩,
one := ⟨1, by simp⟩,
.. };
{ repeat {rintro ⟨_, _⟩},
simp [add_comm, add_left_comm, mul_assoc, left_distrib, right_distrib, add, mul, neg] }
end
instance : inhabited ℤ_[p] := ⟨0⟩
lemma zero_def : ∀ x : ℤ_[p], x = 0 ↔ x.val = 0
| ⟨x, _⟩ := ⟨subtype.mk.inj, λ h, by simp at h; simp only [h]; refl⟩
lemma add_def : ∀ (x y : ℤ_[p]), (x+y).val = x.val + y.val
| ⟨x, hx⟩ ⟨y, hy⟩ := rfl
lemma mul_def : ∀ (x y : ℤ_[p]), (x*y).val = x.val * y.val
| ⟨x, hx⟩ ⟨y, hy⟩ := rfl
@[simp] lemma mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl
instance : has_coe ℤ_[p] ℚ_[p] := ⟨subtype.val⟩
@[simp] lemma val_eq_coe (z : ℤ_[p]) : z.val = ↑z := rfl
@[simp, move_cast] lemma coe_add : ∀ (z1 z2 : ℤ_[p]), (↑(z1 + z2) : ℚ_[p]) = ↑z1 + ↑z2
| ⟨_, _⟩ ⟨_, _⟩ := rfl
@[simp, move_cast] lemma coe_mul : ∀ (z1 z2 : ℤ_[p]), (↑(z1 * z2) : ℚ_[p]) = ↑z1 * ↑z2
| ⟨_, _⟩ ⟨_, _⟩ := rfl
@[simp, move_cast] lemma coe_neg : ∀ (z1 : ℤ_[p]), (↑(-z1) : ℚ_[p]) = -↑z1
| ⟨_, _⟩ := rfl
@[simp, move_cast] lemma coe_sub : ∀ (z1 z2 : ℤ_[p]), (↑(z1 - z2) : ℚ_[p]) = ↑z1 - ↑z2
| ⟨_, _⟩ ⟨_, _⟩ := rfl
@[simp, squash_cast] lemma coe_one : (↑(1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl
@[simp, squash_cast] lemma coe_coe : ∀ n : ℕ, (↑(↑n : ℤ_[p]) : ℚ_[p]) = (↑n : ℚ_[p])
| 0 := rfl
| (k+1) := by simp [coe_coe]
@[simp, squash_cast] lemma coe_zero : (↑(0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl
@[simp, move_cast] lemma cast_pow (x : ℤ_[p]) : ∀ (n : ℕ), (↑(x^n) : ℚ_[p]) = (↑x : ℚ_[p])^n
| 0 := by simp
| (k+1) := by simp [monoid.pow, pow]; congr; apply cast_pow
lemma mk_coe : ∀ (k : ℤ_[p]), (⟨↑k, k.2⟩ : ℤ_[p]) = k
| ⟨_, _⟩ := rfl
/-- The inverse of a p-adic integer with norm equal to 1 is also a p-adic integer. Otherwise, the
inverse is defined to be 0. -/
def inv : ℤ_[p] → ℤ_[p]
| ⟨k, _⟩ := if h : ∥k∥ = 1 then ⟨1/k, by simp [h]⟩ else 0
end padic_int
section instances
variables {p : ℕ} [nat.prime p]
@[reducible] def padic_norm_z (z : ℤ_[p]) : ℝ := ∥z.val∥
instance : metric_space ℤ_[p] := subtype.metric_space
instance : has_norm ℤ_[p] := ⟨padic_norm_z⟩
instance : normed_ring ℤ_[p] :=
{ dist_eq := λ ⟨_, _⟩ ⟨_, _⟩, rfl,
norm_mul := λ ⟨_, _⟩ ⟨_, _⟩, norm_mul_le _ _ }
instance padic_norm_z.is_absolute_value : is_absolute_value (λ z : ℤ_[p], ∥z∥) :=
{ abv_nonneg := norm_nonneg,
abv_eq_zero := λ ⟨_, _⟩, by simp [norm_eq_zero, padic_int.zero_def],
abv_add := λ ⟨_,_⟩ ⟨_, _⟩, norm_add_le _ _,
abv_mul := λ _ _, by unfold norm; simp [padic_norm_z] }
protected lemma padic_int.pmul_comm : ∀ z1 z2 : ℤ_[p], z1*z2 = z2*z1
| ⟨q1, h1⟩ ⟨q2, h2⟩ := show (⟨q1*q2, _⟩ : ℤ_[p]) = ⟨q2*q1, _⟩, by simp [mul_comm]
instance : comm_ring ℤ_[p] :=
{ mul_comm := padic_int.pmul_comm,
..padic_int.ring }
protected lemma padic_int.zero_ne_one : (0 : ℤ_[p]) ≠ 1 :=
show (⟨(0 : ℚ_[p]), _⟩ : ℤ_[p]) ≠ ⟨(1 : ℚ_[p]), _⟩, from mt subtype.ext.1 zero_ne_one
protected lemma padic_int.eq_zero_or_eq_zero_of_mul_eq_zero :
∀ (a b : ℤ_[p]), a * b = 0 → a = 0 ∨ b = 0
| ⟨a, ha⟩ ⟨b, hb⟩ := λ h : (⟨a * b, _⟩ : ℤ_[p]) = ⟨0, _⟩,
have a * b = 0, from subtype.ext.1 h,
(mul_eq_zero_iff_eq_zero_or_eq_zero.1 this).elim
(λ h1, or.inl (by simp [h1]; refl))
(λ h2, or.inr (by simp [h2]; refl))
instance : integral_domain ℤ_[p] :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := padic_int.eq_zero_or_eq_zero_of_mul_eq_zero,
zero_ne_one := padic_int.zero_ne_one,
..padic_int.comm_ring }
end instances
namespace padic_norm_z
variables {p : ℕ} [nat.prime p]
lemma le_one : ∀ z : ℤ_[p], ∥z∥ ≤ 1
| ⟨_, h⟩ := h
@[simp] lemma one : ∥(1 : ℤ_[p])∥ = 1 := by simp [norm, padic_norm_z]
@[simp] lemma mul (z1 z2 : ℤ_[p]) : ∥z1 * z2∥ = ∥z1∥ * ∥z2∥ :=
by unfold norm; simp [padic_norm_z]
@[simp] lemma pow (z : ℤ_[p]) : ∀ n : ℕ, ∥z^n∥ = ∥z∥^n
| 0 := by simp
| (k+1) := show ∥z*z^k∥ = ∥z∥*∥z∥^k, by {rw mul, congr, apply pow}
theorem nonarchimedean : ∀ (q r : ℤ_[p]), ∥q + r∥ ≤ max (∥q∥) (∥r∥)
| ⟨_, _⟩ ⟨_, _⟩ := padic_norm_e.nonarchimedean _ _
theorem add_eq_max_of_ne : ∀ {q r : ℤ_[p]}, ∥q∥ ≠ ∥r∥ → ∥q+r∥ = max (∥q∥) (∥r∥)
| ⟨_, _⟩ ⟨_, _⟩ := padic_norm_e.add_eq_max_of_ne
lemma norm_one : ∥(1 : ℤ_[p])∥ = 1 := normed_field.norm_one
lemma eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]}
(h : ∥z1 + z2∥ < ∥z2∥) : ∥z1∥ = ∥z2∥ :=
by_contradiction $ λ hne,
not_lt_of_ge (by rw padic_norm_z.add_eq_max_of_ne hne; apply le_max_right) h
lemma eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]}
(h : ∥z1 + z2∥ < ∥z1∥) : ∥z1∥ = ∥z2∥ :=
by_contradiction $ λ hne,
not_lt_of_ge (by rw padic_norm_z.add_eq_max_of_ne hne; apply le_max_left) h
@[simp] lemma padic_norm_e_of_padic_int (z : ℤ_[p]) : ∥(↑z : ℚ_[p])∥ = ∥z∥ :=
by simp [norm, padic_norm_z]
@[simp] lemma padic_norm_z_eq_padic_norm_e {q : ℚ_[p]} (hq : ∥q∥ ≤ 1) :
@norm ℤ_[p] _ ⟨q, hq⟩ = ∥q∥ := rfl
end padic_norm_z
private lemma mul_lt_one {α} [decidable_linear_ordered_comm_ring α] {a b : α} (hbz : 0 < b)
(ha : a < 1) (hb : b < 1) : a * b < 1 :=
suffices a*b < 1*1, by simpa,
mul_lt_mul ha (le_of_lt hb) hbz zero_le_one
private lemma mul_lt_one_of_le_of_lt {α} [decidable_linear_ordered_comm_ring α] {a b : α} (ha : a ≤ 1)
(hbz : 0 ≤ b) (hb : b < 1) : a * b < 1 :=
if hb' : b = 0 then by simpa [hb'] using zero_lt_one
else if ha' : a = 1 then by simpa [ha']
else mul_lt_one (lt_of_le_of_ne hbz (ne.symm hb')) (lt_of_le_of_ne ha ha') hb
namespace padic_int
variables {p : ℕ} [nat.prime p]
local attribute [reducible] padic_int
lemma mul_inv : ∀ {z : ℤ_[p]}, ∥z∥ = 1 → z * z.inv = 1
| ⟨k, _⟩ h :=
begin
have hk : k ≠ 0, from λ h', @zero_ne_one ℚ_[p] _ (by simpa [h'] using h),
unfold padic_int.inv, split_ifs,
{ change (⟨k * (1/k), _⟩ : ℤ_[p]) = 1,
simp [hk], refl },
{ apply subtype.ext.2, simp [mul_inv_cancel hk] }
end
lemma inv_mul {z : ℤ_[p]} (hz : ∥z∥ = 1) : z.inv * z = 1 :=
by rw [mul_comm, mul_inv hz]
lemma is_unit_iff {z : ℤ_[p]} : is_unit z ↔ ∥z∥ = 1 :=
⟨λ h, begin
rcases is_unit_iff_dvd_one.1 h with ⟨w, eq⟩,
refine le_antisymm (padic_norm_z.le_one _) _,
have := mul_le_mul_of_nonneg_left (padic_norm_z.le_one w) (norm_nonneg z),
rwa [mul_one, ← padic_norm_z.mul, ← eq, padic_norm_z.one] at this
end, λ h, ⟨⟨z, z.inv, mul_inv h, inv_mul h⟩, rfl⟩⟩
lemma norm_lt_one_add {z1 z2 : ℤ_[p]} (hz1 : ∥z1∥ < 1) (hz2 : ∥z2∥ < 1) : ∥z1 + z2∥ < 1 :=
lt_of_le_of_lt (padic_norm_z.nonarchimedean _ _) (max_lt hz1 hz2)
lemma norm_lt_one_mul {z1 z2 : ℤ_[p]} (hz2 : ∥z2∥ < 1) : ∥z1 * z2∥ < 1 :=
calc ∥z1 * z2∥ = ∥z1∥ * ∥z2∥ : by simp
... < 1 : mul_lt_one_of_le_of_lt (padic_norm_z.le_one _) (norm_nonneg _) hz2
@[simp] lemma mem_nonunits {z : ℤ_[p]} : z ∈ nonunits ℤ_[p] ↔ ∥z∥ < 1 :=
by rw lt_iff_le_and_ne; simp [padic_norm_z.le_one z, nonunits, is_unit_iff]
instance : local_ring ℤ_[p] :=
local_of_nonunits_ideal zero_ne_one $ λ x y, by simp; exact norm_lt_one_add
private def cau_seq_to_rat_cau_seq (f : cau_seq ℤ_[p] norm) :
cau_seq ℚ_[p] (λ a, ∥a∥) :=
⟨ λ n, f n,
λ _ hε, by simpa [norm, padic_norm_z] using f.cauchy hε ⟩
instance complete : cau_seq.is_complete ℤ_[p] norm :=
⟨ λ f,
have hqn : ∥cau_seq.lim (cau_seq_to_rat_cau_seq f)∥ ≤ 1,
from padic_norm_e_lim_le zero_lt_one (λ _, padic_norm_z.le_one _),
⟨ ⟨_, hqn⟩,
λ ε, by simpa [norm, padic_norm_z] using cau_seq.equiv_lim (cau_seq_to_rat_cau_seq f) ε⟩⟩
instance is_ring_hom_coe : is_ring_hom (coe : ℤ_[p] → ℚ_[p]) :=
{ map_one := rfl,
map_mul := coe_mul,
map_add := coe_add }
instance : algebra ℤ_[p] ℚ_[p] :=
@algebra.of_ring_hom ℤ_[p] _ _ _ (coe) padic_int.is_ring_hom_coe
end padic_int
namespace padic_norm_z
variables {p : ℕ} [nat.prime p]
lemma padic_val_of_cong_pow_p {z1 z2 : ℤ} {n : ℕ} (hz : z1 ≡ z2 [ZMOD ↑(p^n)]) :
∥(z1 - z2 : ℚ_[p])∥ ≤ ↑(↑p ^ (-n : ℤ) : ℚ) :=
have hdvd : ↑(p^n) ∣ z2 - z1, from int.modeq.modeq_iff_dvd.1 hz,
have (z2 - z1 : ℚ_[p]) = ↑(↑(z2 - z1) : ℚ), by norm_cast,
begin
rw [norm_sub_rev, this, padic_norm_e.eq_padic_norm],
exact_mod_cast padic_norm.le_of_dvd p hdvd
end
end padic_norm_z
|
bdfc07f89cdc255e5e8a8e211c54f656d9f7552a | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/rat/meta_defs_auto.lean | 0967ddb56202f0bc285ee80d0159ac0d02102ea1 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,433 | lean | /-
Copyright (c) 2019 Robert Y. Lewis . All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.rat.basic
import Mathlib.tactic.core
import Mathlib.PostPort
namespace Mathlib
/-!
# Meta operations on ℚ
This file defines functions for dealing with rational numbers as expressions.
They are not defined earlier in the hierarchy, in the `tactic` or `meta` folders, since we do not
want to import `data.rat.basic` there.
## Main definitions
* `rat.mk_numeral` embeds a rational `q` as a numeral expression into a type supporting the needed
operations. It does not need a tactic state.
* `rat.reflect` specializes `rat.mk_numeral` to `ℚ`.
* `expr.of_rat` behaves like `rat.mk_numeral`, but uses the tactic state to infer the needed
structure on the target type.
* `expr.to_rat` evaluates a normal numeral expression as a rat.
* `expr.eval_rat` evaluates a numeral expression with arithmetic operations as a rat.
-/
/--
`rat.mk_numeral q` embeds `q` as a numeral expression inside a type with 0, 1, +, -, and /
`type`: an expression representing the target type. This must live in Type 0.
`has_zero`, `has_one`, `has_add`: expressions of the type `has_zero %%type`, etc.
This function is similar to `expr.of_rat` but takes more hypotheses and is not tactic valued.
-/
end Mathlib |
5432cf923f9f1f8da957d82c087e6a0206195f16 | 94637389e03c919023691dcd05bd4411b1034aa5 | /src/zzz_junk/04_type_library_copy/00_empty.lean | 84828f025dc5e1807493500def2a94a528e53645 | [] | no_license | kevinsullivan/complogic-s21 | 7c4eef2105abad899e46502270d9829d913e8afc | 99039501b770248c8ceb39890be5dfe129dc1082 | refs/heads/master | 1,682,985,669,944 | 1,621,126,241,000 | 1,621,126,241,000 | 335,706,272 | 0 | 38 | null | 1,618,325,669,000 | 1,612,374,118,000 | Lean | UTF-8 | Lean | false | false | 536 | lean | namespace hidden
/-
The empty data type has no
values/constructors at all.
This fact becomes interesting
and useful when one performs
a case analysis on values of
this type, as there are no
cases to consider.
-/
inductive empty : Type
/-
Exercise: Show that you can
implement a function, e2n, that
takes (assumes it's given) an
argument, e, of type empty and
that then uses match/with/end
to "eliminate" e and to return
without returning any particular
value of type nat.
-/
/-
Lean's "match...with...end"
function.
-/
end hidden |
bbdff882a29b0c2e9e1139a486c452a8eec9adcf | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/limits/constructions/epi_mono.lean | 1e39511d238e98e7874c73e154654a6ec19e9314 | [
"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,459 | lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.shapes.pullbacks
import category_theory.limits.shapes.binary_products
import category_theory.limits.preserves.shapes.pullbacks
/-!
# Relating monomorphisms and epimorphisms to limits and colimits
If `F` preserves (resp. reflects) pullbacks, then it preserves (resp. reflects) monomorphisms.
## TODO
Dualise and apply to functor categories.
-/
universes v u₁ u₂
namespace category_theory
open category limits
variables {C : Type u₁} {D : Type u₂} [category.{v} C] [category.{v} D]
variables (F : C ⥤ D)
/-- If `F` preserves pullbacks, then it preserves monomorphisms. -/
instance preserves_mono {X Y : C} (f : X ⟶ Y) [preserves_limit (cospan f f) F] [mono f] :
mono (F.map f) :=
begin
have := is_limit_pullback_cone_map_of_is_limit F _ (pullback_cone.is_limit_mk_id_id f),
simp_rw [F.map_id] at this,
apply pullback_cone.mono_of_is_limit_mk_id_id _ this,
end
/-- If `F` reflects pullbacks, then it reflects monomorphisms. -/
lemma reflects_mono {X Y : C} (f : X ⟶ Y) [reflects_limit (cospan f f) F] [mono (F.map f)] :
mono f :=
begin
have := pullback_cone.is_limit_mk_id_id (F.map f),
simp_rw [←F.map_id] at this,
apply pullback_cone.mono_of_is_limit_mk_id_id _ (is_limit_of_is_limit_pullback_cone_map F _ this),
end
end category_theory
|
626bf77a1367fac758514bea38e00006ee0d663a | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /stage0/src/Lean/Util.lean | e574e39ae6e0c3e843ac495c6a87474286d3ffe5 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 733 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Util.CollectFVars
import Lean.Util.CollectLevelParams
import Lean.Util.CollectMVars
import Lean.Util.FindMVar
import Lean.Util.FindLevelMVar
import Lean.Util.MonadCache
import Lean.Util.PPExt
import Lean.Util.Path
import Lean.Util.Profile
import Lean.Util.RecDepth
import Lean.Util.Sorry
import Lean.Util.Trace
import Lean.Util.FindExpr
import Lean.Util.ReplaceExpr
import Lean.Util.ForEachExpr
import Lean.Util.ReplaceLevel
import Lean.Util.FoldConsts
import Lean.Util.SCC
import Lean.Util.OccursCheck
import Lean.Util.Paths
import Lean.Util.HasConstCache
|
0c474cf8031bddb0239a6d4441cf3b2b62c67ad4 | 0533ebfa09b11cf8a29da118dd1b86b94949511e | /src/basic.lean | 356166fd3e5ae3643ed9e0f2a77caee1ab0d90ab | [
"MIT"
] | permissive | wudcscheme/Lean-RH | 89e9055aac68703876e750c23fb5327979a09822 | 870f78cc7c0715d03466d1211b0f032b425ec984 | refs/heads/main | 1,679,188,429,923 | 1,602,701,790,000 | 1,602,701,790,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 37,103 | lean | /- ------------------------------------------------------------------------- -|
| @project: riemann_hypothesis |
| @file: basic.lean |
| @author: Brandon H. Gomes and Alex Kontorovich |
| @affil: Rutgers University |
|- ------------------------------------------------------------------------- -/
/-!
-/
namespace riemann_hypothesis --——————————————————————————————————————————————————————————--
variables {α : Type*} {β : Type*}
/--
-/
def const (b : β)
:= λ _ : α, b
notation `↓`:max b:max := const b
section pointwise_classes --—————————————————————————————————————————————————————————————--
/--
-/
instance pointwise.has_le [has_le β] : has_le (α → β)
:= ⟨λ f g, Π x, f x ≤ g x⟩
/--
-/
instance pointwise.has_zero [has_zero β] : has_zero (α → β)
:= ⟨↓0⟩
end pointwise_classes --—————————————————————————————————————————————————————————————————--
namespace algebra --—————————————————————————————————————————————————————————————————————--
variables (α) (β)
/--
-/
class has_left_add_distributivity [has_add α] [has_mul α]
:= (eq : Π x y z : α, x * (y + z) = x * y + x * z)
/--
-/
class has_right_add_distributivity [has_add α] [has_mul α]
:= (eq : Π x y z : α, (y + z) * x = y * x + z * x)
/--
-/
class has_left_sub_distributivity [has_sub α] [has_mul α]
:= (eq : Π x y z : α, x * (y - z) = x * y - x * z)
/--
-/
class has_right_sub_distributivity [has_sub α] [has_mul α]
:= (eq : Π x y z : α, (y - z) * x = y * x - z * x)
/--
-/
class has_lift_add_comm [has_lift_t α β] [has_add α] [has_add β]
:= (eq : Π x y : α, (↑(x + y) : β) = ↑x + ↑y)
/--
-/
class has_lift_sub_comm [has_lift_t α β] [has_sub α] [has_sub β]
:= (eq : Π x y : α, (↑(x - y) : β) = ↑x - ↑y)
/--
-/
class has_lift_mul_comm [has_lift_t α β] [has_mul α] [has_mul β]
:= (eq : Π x y : α, (↑(x * y) : β) = ↑x * ↑y)
/--
-/
class has_lift_inv_comm [has_lift_t α β] [has_inv α] [has_inv β]
:= (eq : Π a : α, (↑(a⁻¹) : β) = (↑a)⁻¹)
/--
-/
class has_right_unit [has_one α] [has_mul α]
:= (eq : Π a : α, a * 1 = a)
/--
-/
class has_left_unit [has_one α] [has_mul α]
:= (eq : Π a : α, 1 * a = a)
/--
-/
class has_add_le_add [has_le α] [has_add α]
:= (le : Π {a b c d : α}, a ≤ b → c ≤ d → a + c ≤ b + d)
/--
-/
class has_add_lt_add [has_lt α] [has_add α]
:= (lt : Π {a b c d : α}, a < b → c < d → a + c < b + d)
/--
-/
class has_le_add_of_nonneg_of_le [has_le α] [has_zero α] [has_add α]
:= (le : Π {a b c : α}, 0 ≤ a → b ≤ c → b ≤ a + c)
/--
-/
class has_lt_add_of_le_of_pos [has_le α] [has_lt α] [has_zero α] [has_add α]
:= (lt : Π {a b c : α}, 0 < a → b ≤ c → b < a + c)
/--
-/
class has_add_nonneg [has_le α] [has_zero α] [has_add α]
:= (le : Π {a b : α}, 0 ≤ a → 0 ≤ b → 0 ≤ a + b)
/--
-/
class has_zero_mul_is_zero [has_zero α] [has_mul α]
:= (eq : Π a : α, 0 * a = 0)
/--
-/
class has_mul_zero_is_zero [has_zero α] [has_mul α]
:= (eq : Π a : α, a * 0 = 0)
/--
-/
class has_lift_zero_same [has_lift_t α β] [has_zero α] [has_zero β]
:= (eq : ↑(0 : α) = (0 : β))
/--
-/
class has_lift_one_same [has_lift_t α β] [has_one α] [has_one β]
:= (eq : ↑(1 : α) = (1 : β))
/--
-/
class has_zero_right_add_cancel [has_zero α] [has_add α]
:= (eq : Π a : α, a + 0 = a)
/--
-/
class has_zero_left_add_cancel [has_zero α] [has_add α]
:= (eq : Π a : α, 0 + a = a)
/--
-/
class has_sub_self_is_zero [has_zero α] [has_sub α]
:= (eq : Π a : α, a - a = 0)
/--
-/
class has_mul_assoc [has_mul α]
:= (eq : Π a b c : α, (a * b) * c = a * (b * c))
/--
-/
class has_add_sub_assoc [has_add α] [has_sub α]
:= (eq : Π a b c : α, (a + b) - c = a + (b - c))
/--
-/
class has_le_sub_add_le [has_le α] [has_sub α] [has_add α]
:= (le : Π {a b c : α}, a ≤ c - b → a + b ≤ c)
/--
-/
class has_le_pos_mul_preserves_right [has_lt α] [has_le α] [has_zero α] [has_mul α]
:= (le : Π {a b c : α}, 0 < c → a ≤ b → a * c ≤ b * c)
/--
-/
class has_le_pos_mul_preserves_left [has_lt α] [has_le α] [has_zero α] [has_mul α]
:= (le : Π {a b c : α}, 0 < c → a ≤ b → c * a ≤ c * b)
/--
-/
class has_lt_pos_mul_preserves_right [has_lt α] [has_zero α] [has_mul α]
:= (lt : Π {a b c : α}, 0 < c → a < b → a * c < b * c)
/--
-/
class has_le_nonneg_mul_preserves_left [has_lt α] [has_le α] [has_zero α] [has_mul α]
:= (le : Π {a b c : α}, 0 ≤ c → a ≤ b → c * a ≤ c * b)
/--
-/
class has_le_nonneg_mul_preserves_right [has_lt α] [has_le α] [has_zero α] [has_mul α]
:= (le : Π {a b c : α}, 0 ≤ c → a ≤ b → a * c ≤ b * c)
/--
-/
class has_lift_le_comm [has_lift_t α β] [has_le α] [has_le β]
:= (le : Π {x y : α}, x ≤ y → ↑x ≤ (↑y : β))
/--
-/
class has_lift_lt_comm [has_lift_t α β] [has_lt α] [has_lt β]
:= (lt : Π {x y : α}, x < y → ↑x < (↑y : β))
/--
-/
class has_lift_ne_comm [has_lift_t α β]
:= (ne : Π {x y : α}, x ≠ y → ↑x ≠ (↑y : β))
/--
-/
class has_sub_add_sub_cancel [has_sub α] [has_add α]
:= (eq : Π a b c : α, a - b + (b - c) = a - c)
/--
-/
class has_double_sub_cancel [has_sub α]
:= (eq : Π a b : α, a - (a - b) = b)
/--
-/
class has_inv_mul_right_cancel_self [has_zero α] [has_one α] [has_inv α] [has_mul α]
:= (eq : Π a : α, a ≠ 0 → a * a⁻¹ = 1)
/--
-/
class has_inv_mul_left_cancel_self [has_zero α] [has_one α] [has_inv α] [has_mul α]
:= (eq : Π a : α, a ≠ 0 → a⁻¹ * a = 1)
/--
-/
class has_add_sub_exchange [has_add α] [has_sub α]
:= (eq : Π a b c d : α, (a - b) + (c - d) = (c - b) + (a - d))
/--
-/
class has_zero_sub_is_neg [has_zero α] [has_neg α] [has_sub α]
:= (eq : Π a : α, 0 - a = -a)
/--
-/
class has_inv_right_mul_lt_pos [has_lt α] [has_zero α] [has_mul α] [has_inv α]
:= (lt : Π {a b c : α}, 0 < b → a < c * b → a * b⁻¹ < c)
/--
-/
class has_right_mul_inv_lt_pos [has_lt α] [has_zero α] [has_mul α] [has_inv α]
:= (lt : Π {a b c : α}, 0 < b → c < b⁻¹ * a → b * c < a)
/--
-/
class has_left_mul_inv_lt_pos [has_lt α] [has_zero α] [has_mul α] [has_inv α]
:= (lt : Π {a b c : α}, 0 < b → c < a * b⁻¹ → c * b < a)
/--
-/
class has_left_mul_inv_lt_neg [has_lt α] [has_zero α] [has_mul α] [has_inv α]
:= (lt : Π {a b c : α}, b < 0 → a * b⁻¹ < c → b * c < a)
/--
-/
class has_sub_ne_zero_of_ne [has_zero α] [has_sub α]
:= (ne : Π {a b : α}, a ≠ b → a - b ≠ 0)
/--
-/
class has_lt_sub_neg [has_lt α] [has_zero α] [has_sub α]
:= (lt : Π {a b : α}, a < b → a - b < 0)
/--
-/
class has_zero_lt_one [has_lt α] [has_zero α] [has_one α]
:= (lt : 0 < (1 : α))
/--
-/
class has_pos_mul_neg_is_neg [has_lt α] [has_zero α] [has_mul α]
:= (lt : Π {a b : α}, 0 < a → b < 0 → a * b < 0)
/--
-/
class has_nonneg_mul_nonneg_is_nonneg [has_le α] [has_zero α] [has_mul α]
:= (le : Π {a b : α}, 0 ≤ a → 0 ≤ b → 0 ≤ a * b)
/--
-/
class has_squared_le_monotonic [has_le α] [has_zero α] [has_mul α]
:= (le : Π {a b : α}, 0 ≤ a → a ≤ b → a * a ≤ b * b)
/--
-/
class has_sub_pos [has_lt α] [has_zero α] [has_sub α]
:= (lt : Π {a b : α}, a < b → 0 < b - a)
/--
-/
class has_sub_sub [has_add α] [has_sub α]
:= (eq : Π a b c : α, a - (b - c) = (a - b) + c)
/--
-/
class has_add_left_lt [has_lt α] [has_add α]
:= (lt : Π a b c : α, a < b → c + a < c + b)
/--
-/
class has_left_inv_pos_lt [has_lt α] [has_zero α] [has_mul α] [has_inv α]
:= (lt : Π {a b c : α}, 0 < c → a < b → c⁻¹ * a < c⁻¹ * b)
/--
-/
class has_right_inv_pos_lt [has_lt α] [has_zero α] [has_mul α] [has_inv α]
:= (lt : Π {a b c : α}, 0 < c → a < b → a * c⁻¹ < b * c⁻¹)
/--
-/
class has_mul_pos [has_lt α] [has_zero α] [has_mul α]
:= (lt : Π {a b : α}, 0 < a → 0 < b → 0 < a * b)
/--
-/
class has_inv_pos [has_lt α] [has_zero α] [has_inv α]
:= (lt : Π {a : α}, 0 < a → 0 < a⁻¹)
/--
-/
class has_inv_reverses_le [has_le α] [has_inv α]
:= (le : Π {a b : α}, a ≤ b → b⁻¹ ≤ a⁻¹)
/--
-/
class has_inv_reverses_lt [has_lt α] [has_inv α]
:= (lt : Π {a b : α}, a < b → b⁻¹ < a⁻¹)
/--
-/
class has_inv_mul_reverse [has_inv α] [has_mul α]
:= (eq : Π a b : α, (a * b)⁻¹ = b⁻¹ * a⁻¹)
/--
-/
structure Half [has_lt α] [has_zero α] [has_add α]
:= (map : α → α)
(preserve_pos : Π {x}, 0 < x → 0 < map x)
(doubled_inv : Π (x), map x + map x = x)
/--
-/
structure LiftCeil [has_lift_t nat α] [has_lt α]
:= (map : α → nat)
(lift_lt : Π {a n}, map a < n → a < ↑n)
section lemmas --————————————————————————————————————————————————————————————————————————--
variables {α β}
/--
-/
def inv_sub_inv_lemma
[has_zero α]
[has_one α]
[has_inv α]
[has_mul α]
[has_sub α]
[has_right_unit α]
[has_left_unit α]
[has_inv_mul_right_cancel_self α]
[has_mul_assoc α]
[has_right_sub_distributivity α]
{a b : α}
(a_ne_0 : a ≠ 0)
: a⁻¹ - b⁻¹ = (1 - b⁻¹ * a) * a⁻¹ :=
begin
rw has_right_sub_distributivity.eq,
rw has_mul_assoc.eq,
rw has_inv_mul_right_cancel_self.eq _ a_ne_0,
rw has_left_unit.eq,
rw has_right_unit.eq,
end
/--
-/
def inv_sub_inv_lemma'
[has_zero α]
[has_one α]
[has_inv α]
[has_mul α]
[has_sub α]
[has_right_unit α]
[has_left_unit α]
[has_inv_mul_left_cancel_self α]
[has_mul_assoc α]
[has_left_sub_distributivity α]
{a b : α}
(a_ne_0 : a ≠ 0)
: a⁻¹ - b⁻¹ = a⁻¹ * (1 - a * b⁻¹) :=
begin
rw has_left_sub_distributivity.eq,
rw ← has_mul_assoc.eq,
rw has_inv_mul_left_cancel_self.eq _ a_ne_0,
rw has_left_unit.eq,
rw has_right_unit.eq,
end
/--
-/
def mul_inv_add_one_lemma
[has_lift_t nat α]
[has_zero α]
[has_one α]
[has_sub α]
[has_mul α]
[has_inv α]
[has_left_unit α]
[has_inv_mul_right_cancel_self α]
[has_right_sub_distributivity α]
[has_lift_zero_same nat α]
[has_lift_one_same nat α]
[has_lift_sub_comm nat α]
[has_lift_ne_comm nat α]
(n : nat)
: (↑n : α) * (↑n.succ)⁻¹ = 1 - (↑n.succ)⁻¹ :=
begin
rw ← has_left_unit.eq (↑n.succ : α)⁻¹,
have succ_non_zero : ↑n.succ ≠ (0 : α),
rw (_ : 0 = (↑0 : α)),
refine has_lift_ne_comm.ne (nat.succ_ne_zero _),
rw has_lift_zero_same.eq,
rw ← has_inv_mul_right_cancel_self.eq _ succ_non_zero,
rw ← has_right_sub_distributivity.eq,
rw has_inv_mul_right_cancel_self.eq _ succ_non_zero,
rw has_left_unit.eq,
rw (_ : 1 = (↑1 : α)),
rw ← has_lift_sub_comm.eq,
rw nat.succ_sub_one,
rw has_lift_one_same.eq,
end
/--
-/
def two_mul_lemma
[has_one α]
[has_add α]
[has_mul α]
[has_right_add_distributivity α]
[has_left_unit α]
(a : α)
: 2 * a = a + a :=
begin
refine (has_right_add_distributivity.eq _ _ _).trans _,
rw has_left_unit.eq,
end
/--
-/
def two_mul_lemma'
[has_one α]
[has_add α]
[has_mul α]
[has_left_add_distributivity α]
[has_right_unit α]
(a : α)
: a * 2 = a + a :=
begin
refine (has_left_add_distributivity.eq _ _ _).trans _,
rw has_right_unit.eq,
end
/--
-/
def two_squares_is_four_lemma
[has_one α]
[has_add α] [has_mul α]
[has_left_unit α]
[has_left_add_distributivity α] [has_right_add_distributivity α]
[has_mul_assoc α]
(a : α)
: 4 * (a * a) = (a + a) * (a + a) :=
begin
rw has_left_add_distributivity.eq,
rw has_right_add_distributivity.eq,
rw ← two_mul_lemma,
rw ← two_mul_lemma,
rw ← has_mul_assoc.eq,
rw ← has_mul_assoc.eq,
rw two_mul_lemma,
rw has_mul_assoc.eq,
refine rfl,
end
/--
-/
def two_squares_is_four_lemma'
[has_one α]
[has_add α] [has_mul α]
[has_right_unit α]
[has_left_add_distributivity α] [has_right_add_distributivity α]
[has_mul_assoc α]
(a : α)
: (a * a) * 4 = (a + a) * (a + a) :=
begin
rw has_right_add_distributivity.eq,
rw has_left_add_distributivity.eq,
rw ← two_mul_lemma',
rw ← two_mul_lemma',
rw has_mul_assoc.eq,
rw has_mul_assoc.eq,
rw two_mul_lemma',
rw has_mul_assoc.eq,
refine rfl,
end
/--
-/
def nat_mul_commute_lemma
[has_zero α]
[has_one α]
[has_add α]
[has_mul α]
[has_zero_mul_is_zero α]
[has_mul_zero_is_zero α]
[has_right_unit α]
[has_left_unit α]
[has_left_add_distributivity α]
[has_right_add_distributivity α]
[has_lift_t nat α]
[has_lift_zero_same nat α]
[has_lift_one_same nat α]
[has_lift_add_comm nat α]
(a : α) (n : nat)
: a * ↑n = ↑n * a :=
begin
induction n with n hn,
rw has_lift_zero_same.eq,
rw has_zero_mul_is_zero.eq,
rw has_mul_zero_is_zero.eq,
rw nat.succ_eq_add_one,
rw has_lift_add_comm.eq,
rw has_left_add_distributivity.eq,
rw has_right_add_distributivity.eq,
rw hn,
rw has_lift_one_same.eq,
rw has_left_unit.eq,
rw has_right_unit.eq,
end
section lifted_lemmas --—————————————————————————————————————————————————————————————————--
variables (α β)
/--
-/
def zero_is_lifted_zero_lemma
[has_zero α] [has_zero β] [has_lift_t α β] [has_lift_zero_same α β]
: (0 : β) = ↑(0 : α)
:= by rw has_lift_zero_same.eq
--———————————————————————————————————————————————————————————————————————————————————————--
variables [has_one α] [has_one β] [has_lift_t α β] [has_lift_one_same α β]
/--
-/
def one_is_lifted_one_lemma
: (1 : β) = ↑(1 : α)
:= by rw has_lift_one_same.eq
--———————————————————————————————————————————————————————————————————————————————————————--
variables [has_add α] [has_add β] [has_lift_add_comm α β]
/--
-/
def two_is_lifted_two_lemma : (2 : β) = ↑(2 : α) :=
begin
rw (_ : (2 : β) = ↑(1 : α) + ↑(1 : α)),
rw ← has_lift_add_comm.eq,
refine rfl,
rw has_lift_one_same.eq,
refine rfl,
end
/--
-/
def three_is_lifted_three_lemma : (3 : β) = ↑(3 : α) :=
begin
rw (_ : (3 : β) = ↑(1 : α) + ↑(1 : α) + ↑(1 : α)),
rw [← has_lift_add_comm.eq, ← has_lift_add_comm.eq],
refine rfl,
rw has_lift_one_same.eq,
refine rfl,
end
/--
-/
def four_is_lifted_four_lemma : (4 : β) = ↑(4 : α) :=
begin
rw (_ : (4 : β) = ↑(1 : α) + ↑(1 : α) + (↑(1 : α) + ↑(1 : α))),
rw [← has_lift_add_comm.eq, ← has_lift_add_comm.eq],
refine rfl,
rw has_lift_one_same.eq,
refine rfl,
end
end lifted_lemmas --—————————————————————————————————————————————————————————————————————--
end lemmas --————————————————————————————————————————————————————————————————————————————--
end algebra --———————————————————————————————————————————————————————————————————————————--
open algebra
namespace nat --—————————————————————————————————————————————————————————————————————————--
/--
-/
def of_le_succ {n m : nat} (n_le_m_succ : n ≤ m.succ) : n ≤ m ∨ n = m.succ
:= (lt_or_eq_of_le n_le_m_succ).imp nat.le_of_lt_succ id
/--
-/
def sub_sub_sub_cancel_right {a b c} (c_le_b : c ≤ b) : a - c - (b - c) = a - b
:= by rw [nat.sub_sub, ← nat.add_sub_assoc c_le_b, nat.add_sub_cancel_left]
/--
-/
def le_sub_right_of_add_le {m n k} : m + k ≤ n → m ≤ n - k :=
begin
intros h,
rw ← nat.add_sub_cancel m k,
refine nat.sub_le_sub_right h _,
end
/--
-/
def le_sub_left_of_add_le {k m n} (h : k + m ≤ n) : m ≤ n - k
:= le_sub_right_of_add_le (by { rw ← nat.add_comm, refine h })
/--
-/
def le_add_of_sub_le_right {k m n} : n - k ≤ m → n ≤ m + k :=
begin
intros h,
rw ← nat.add_sub_cancel m k at h,
refine (nat.sub_le_sub_right_iff _ _ _ (nat.le_add_left _ _)).mp h,
end
/--
-/
def add_lt_add_of_le_of_lt {a b c d} (h₁ : a ≤ b) (h₂ : c < d) : a + c < b + d
:= lt_of_le_of_lt (nat.add_le_add_right h₁ c) (nat.add_lt_add_left h₂ b)
/--
-/
def lt_add_of_le_of_pos {a b c} (b_le_c : b ≤ c) (zero_lt_a : 0 < a) : b < c + a
:= nat.add_zero b ▸ nat.add_lt_add_of_le_of_lt b_le_c zero_lt_a
/--
-/
def neg_right_swap {a b c} (c_le_b : c ≤ b) : a - (b - c) = (a + c) - b :=
begin
rw ← nat.add_sub_cancel a _,
rw nat.sub_sub_sub_cancel_right c_le_b,
rw nat.add_sub_assoc (le_refl _),
rw nat.sub_self,
rw nat.add_zero,
end
/--
-/
def sub_mono_left_strict {x y z : nat} (z_le_x : z ≤ x) (x_lt_y : x < y)
: x - z < y - z :=
begin
refine @nat.lt_of_add_lt_add_left z _ _ _,
rw nat.add_sub_of_le (le_trans z_le_x (le_of_lt x_lt_y)),
rw nat.add_sub_of_le z_le_x,
refine x_lt_y,
end
/--
-/
def mul_two (n) : n * 2 = n + n :=
begin
refine (nat.left_distrib _ _ _).trans _,
rw nat.mul_one,
end
/--
-/
def pow_two_ge_one (n : nat) : 1 ≤ 2 ^ n :=
begin
induction n with n hn,
refine le_refl _,
refine le_trans hn (nat.le_add_left _ _),
end
/--
-/
def pow_two_monotonic (n : nat) : 2 ^ n < 2 ^ n.succ
:= lt_add_of_le_of_pos (nat.le_add_left _ _) (pow_two_ge_one _)
/--
-/
def smallest_positive_even (n : nat)
: 2 ≤ 2 * n.succ :=
begin
induction n with n hn,
rw nat.mul_one,
refine le_trans hn (nat.le.intro rfl),
end
/--
-/
def successive_difference (u : nat → nat) (n : nat)
:= u n.succ - u n
/--
-/
def power [has_one α] [has_mul α] (a : α) : nat → α
| (nat.zero ) := 1
| (nat.succ n) := power n * a
namespace power --———————————————————————————————————————————————————————————————————————--
variables [has_one α] [has_mul α]
/--
-/
def mul_commute
[has_one β] [has_mul β]
(map : α → β)
(map_one : map 1 = 1)
(map_mul : Π x y, map (x * y) = map x * map y)
(a : α) (n)
: map (power a n) = power (map a) n :=
begin
induction n with n hn,
rw [power, power],
rw map_one,
rw [power, power],
rw map_mul,
rw hn,
end
end power --—————————————————————————————————————————————————————————————————————————————--
namespace lift --————————————————————————————————————————————————————————————————————————--
variables (α)
/--
-/
def succ_pos
[has_lt α]
[has_zero α]
[has_lift_t nat α]
[has_lift_zero_same nat α]
[has_lift_lt_comm nat α]
(n : nat)
: 0 < (↑n.succ : α) :=
begin
rw zero_is_lifted_zero_lemma nat α,
refine has_lift_lt_comm.lt (nat.succ_pos _),
end
/--
-/
def succ_nonzero
[preorder α]
[has_zero α]
[has_lift_t nat α]
[has_lift_zero_same nat α]
[has_lift_lt_comm nat α]
(n : nat)
: (↑n.succ : α) ≠ 0
:= (ne_of_gt (nat.lift.succ_pos α _))
/--
-/
def zero_lt_one
[has_lt α]
[has_zero α]
[has_one α]
[has_lift_t nat α]
[has_lift_zero_same nat α]
[has_lift_one_same nat α]
[has_lift_lt_comm nat α]
: (0 : α) < 1 :=
begin
rw one_is_lifted_one_lemma nat α,
refine nat.lift.succ_pos α _,
end
/--
-/
instance zero_lt_one_instance
[has_lt α]
[has_zero α]
[has_one α]
[has_lift_t nat α]
[has_lift_zero_same nat α]
[has_lift_one_same nat α]
[has_lift_lt_comm nat α]
: has_zero_lt_one α
:= ⟨zero_lt_one α⟩
end lift --——————————————————————————————————————————————————————————————————————————————--
end nat --———————————————————————————————————————————————————————————————————————————————--
section sequences --—————————————————————————————————————————————————————————————————————--
/--
-/
def strictly_increasing
[has_lt α]
(seq : nat → α)
:= Π n, seq n < seq n.succ
/--
-/
def increasing
[has_le α]
(seq : nat → α)
:= Π n, seq n ≤ seq n.succ
/--
-/
def strictly_increasing.as_increasing
[preorder α]
(seq : nat → α)
: strictly_increasing seq → increasing seq :=
begin
intros sinc _,
refine le_of_lt (sinc _),
end
/--
-/
def increasing_strong
[has_le α]
(seq : nat → α)
:= Π i j, i ≤ j → seq i ≤ seq j
/--
-/
def increasing.as_increasing_strong
[preorder α]
(seq : nat → α)
: increasing seq → increasing_strong seq :=
begin
intros inc i j i_le_j,
induction j with j hj,
cases i_le_j,
refine le_refl _,
cases nat.of_le_succ i_le_j,
refine le_trans (hj h) (inc _),
rw h,
end
/--
-/
def strictly_increasing.as_increasing_strong
[preorder α]
(seq : nat → α)
: strictly_increasing seq → increasing_strong seq
:= λ s, increasing.as_increasing_strong _ (strictly_increasing.as_increasing _ s)
/--
-/
def non_increasing
[has_le α]
(seq : nat → α)
:= Π n, seq (nat.succ n) ≤ seq n
/--
-/
def non_increasing_strong
[has_le α]
(seq : nat → α) (k)
:= Π n, seq (n + k) ≤ seq n
/--
-/
def non_increasing.as_non_increasing_strong
[preorder α]
(seq : nat → α)
: non_increasing seq → Π k, non_increasing_strong seq k :=
begin
intros noninc k _,
induction k with k hk,
refine le_refl _,
refine le_trans (noninc _) hk,
end
/--
-/
def strictly_increasing.ge_index
(seq) (sinc : strictly_increasing seq)
(k)
: k ≤ seq k :=
begin
induction k with _ hk,
refine nat.zero_le _,
rw nat.succ_eq_add_one,
refine le_trans (nat.add_le_add hk (le_refl _)) (sinc _),
end
/--
-/
def nonneg_compose_preserve
[has_zero α] [has_le α]
(seq : nat → α) (φ : nat → nat)
: 0 ≤ seq → 0 ≤ seq ∘ φ
:= λ p _, p (φ _)
/--
-/
def translate
(seq : nat → α)
(k)
(n)
:= seq (k + n)
/--
-/
def translate.preserve_nonneg
[has_zero α] [has_le α]
(seq : nat → α)
: 0 ≤ seq → 0 ≤ translate seq
:= λ p _ _, p _
/--
-/
def translate.monotonicity
[has_le α]
{a b : nat → α}
: a ≤ b → translate a ≤ translate b
:= λ p _ _, p _
/--
-/
def translate.combine
(seq : nat → α)
(i j)
: translate (translate seq i) j = translate seq (i + j)
:= funext (λ _, by rw [translate, translate, translate, nat.add_assoc])
/--
-/
def translate.compose_commute
(seq : nat → α)
(f : α → β)
(n k)
: f (translate seq n k) = translate (f ∘ seq) n k
:= by rw [translate, translate]
/--
-/
def translate.compose_commute.funext
(seq : nat → α)
(f : α → β)
(n)
: f ∘ (translate seq n) = translate (f ∘ seq) n
:= funext (translate.compose_commute seq f n)
end sequences --—————————————————————————————————————————————————————————————————————————--
section series --————————————————————————————————————————————————————————————————————————--
variables [has_zero α] [has_add α]
/--
-/
def partial_sum (seq : nat → α) : nat → α
| (nat.zero ) := 0
| (nat.succ n) := seq n + partial_sum n
/--
-/
def partial_sum.preserve_nonneg
[preorder α] [has_add_nonneg α]
(seq : nat → α)
: 0 ≤ seq → 0 ≤ partial_sum seq :=
begin
intros nonneg k,
induction k with k hk,
refine le_refl _,
refine has_add_nonneg.le (nonneg _) hk,
end
/--
-/
def partial_sum.left_mul_commute
[has_mul α] [has_mul_zero_is_zero α] [has_left_add_distributivity α]
(seq : nat → α)
(C)
: partial_sum (λ k, C * seq k) = λ n, C * partial_sum seq n :=
begin
refine funext _,
intros n,
induction n with n hn,
rw partial_sum,
rw partial_sum,
rw has_mul_zero_is_zero.eq,
rw partial_sum,
rw partial_sum,
rw hn,
rw has_left_add_distributivity.eq,
end
/--
-/
def partial_sum.right_mul_commute
[has_mul α] [has_zero_mul_is_zero α] [has_right_add_distributivity α]
(seq : nat → α)
(C)
: partial_sum (λ k, seq k * C) = λ n, partial_sum seq n * C :=
begin
refine funext _,
intros n,
induction n with n hn,
rw partial_sum,
rw partial_sum,
rw has_zero_mul_is_zero.eq,
rw partial_sum,
rw partial_sum,
rw hn,
rw has_right_add_distributivity.eq,
end
/--
-/
def partial_sum.from_mul
[has_one α]
[has_mul α]
[has_zero_mul_is_zero α]
[has_left_unit α]
[has_right_add_distributivity α]
[has_lift_t nat α]
[has_lift_zero_same nat α]
[has_lift_one_same nat α]
[has_lift_add_comm nat α]
(a : α)
(n : nat)
: ↑n * a = partial_sum ↓a n :=
begin
induction n with n hn,
rw partial_sum,
rw has_lift_zero_same.eq,
rw has_zero_mul_is_zero.eq,
rw partial_sum,
rw nat.succ_eq_add_one,
rw nat.add_comm,
rw has_lift_add_comm.eq,
rw has_right_add_distributivity.eq,
rw has_lift_one_same.eq,
rw has_left_unit.eq,
rw hn,
rw const,
end
/--
-/
def partial_sum.from_mul'
[has_one α]
[has_mul α]
[has_mul_zero_is_zero α]
[has_right_unit α]
[has_left_add_distributivity α]
[has_lift_t nat α]
[has_lift_zero_same nat α]
[has_lift_one_same nat α]
[has_lift_add_comm nat α]
(a : α)
(n : nat)
: a * ↑n = partial_sum ↓a n :=
begin
induction n with n hn,
rw partial_sum,
rw has_lift_zero_same.eq,
rw has_mul_zero_is_zero.eq,
rw partial_sum,
rw nat.succ_eq_add_one,
rw nat.add_comm,
rw has_lift_add_comm.eq,
rw has_left_add_distributivity.eq,
rw has_lift_one_same.eq,
rw has_right_unit.eq,
rw hn,
rw const,
end
/--
-/
def partial_sum.monotonicity
[preorder α] [has_add_le_add α]
{a b : nat → α}
: a ≤ b → partial_sum a ≤ partial_sum b :=
begin
intros a_le_b n,
induction n with _ hn,
refine le_refl _,
refine has_add_le_add.le (a_le_b _) hn,
end
/--
-/
def partial_sum.index_monotonicity
[preorder α] [has_le_add_of_nonneg_of_le α]
(seq : nat → α) (nonneg : 0 ≤ seq)
{m n}
: m ≤ n → partial_sum seq m ≤ partial_sum seq n :=
begin
intros m_le_n,
induction n with n hn,
cases m_le_n,
refine le_refl _,
cases nat.of_le_succ m_le_n,
refine has_le_add_of_nonneg_of_le.le (nonneg _) (hn h),
rw ← h,
end
/--
-/
def partial_sum.double_monotonicity
[preorder α] [has_le_add_of_nonneg_of_le α] [has_add_le_add α]
(a : nat → α) (na)
(b : nat → α) (nb)
: 0 ≤ a → a ≤ b → na ≤ nb → partial_sum a na ≤ partial_sum b nb :=
begin
intros zero_le_a a_le_b na_le_nb,
induction nb with _ hnb,
cases na_le_nb,
refine le_refl _,
cases nat.of_le_succ na_le_nb,
refine has_le_add_of_nonneg_of_le.le
(le_trans (zero_le_a _) (a_le_b _)) (hnb h),
rw h,
refine has_add_le_add.le
(a_le_b _) (partial_sum.monotonicity a_le_b _),
end
/--
-/
def partial_sum.sub_as_translate
[has_sub α] [has_sub_self_is_zero α] [has_add_sub_assoc α]
(seq : nat → α)
{m n} (m_le_n : m ≤ n)
: partial_sum seq n - partial_sum seq m = partial_sum (translate seq m) (n - m) :=
begin
induction n with n hn,
cases m_le_n,
refine has_sub_self_is_zero.eq _,
cases m_le_n with _ m_le_n,
rw has_sub_self_is_zero.eq,
rw nat.sub_self,
rw partial_sum,
rw partial_sum,
rw has_add_sub_assoc.eq,
rw hn m_le_n,
rw nat.succ_sub m_le_n,
rw partial_sum,
rw translate,
rw nat.add_sub_of_le m_le_n,
end
/--
-/
def partial_sum.lower_differences.bottom
[has_sub α]
[has_add_sub_assoc α]
[has_sub_self_is_zero α]
[preorder α]
[has_le_add_of_nonneg_of_le α]
(seq : nat → α) (nonneg : 0 ≤ seq)
{m n} (m_le_n : m ≤ n)
: 0 ≤ partial_sum seq n - partial_sum seq m :=
begin
induction n with n hn,
cases m_le_n,
rw has_sub_self_is_zero.eq,
cases nat.of_le_succ m_le_n,
rw partial_sum,
rw has_add_sub_assoc.eq,
refine has_le_add_of_nonneg_of_le.le (nonneg _) (hn h),
rw ← h,
rw has_sub_self_is_zero.eq,
end
/--
-/
def partial_sum.lower_differences
[has_sub α]
[has_sub_self_is_zero α]
[has_add_sub_assoc α]
[preorder α]
[has_add_le_add α]
[has_le_add_of_nonneg_of_le α]
(seq : nat → α) (nonneg : 0 ≤ seq)
{k m n} (k_le_m : k ≤ m) (m_le_n : m ≤ n)
: partial_sum seq n - partial_sum seq m ≤ partial_sum seq n - partial_sum seq k :=
begin
induction n with n hn,
cases m_le_n,
cases k_le_m,
refine le_refl _,
cases nat.of_le_succ m_le_n,
rw partial_sum,
rw has_add_sub_assoc.eq,
rw has_add_sub_assoc.eq,
refine has_add_le_add.le (le_refl _) (hn h),
rw ← h,
rw has_sub_self_is_zero.eq,
refine partial_sum.lower_differences.bottom _ nonneg k_le_m,
end
--———————————————————————————————————————————————————————————————————————————————————————--
variables [has_sub α]
/--
-/
def shape_sum (seq : nat → α) (φ : nat → nat) (n : nat)
:= partial_sum seq (φ n.succ) - partial_sum seq (φ n)
/--
-/
def shape_sum.unfold
[has_sub_self_is_zero α]
[has_add_sub_assoc α]
[has_sub_add_sub_cancel α]
(seq : nat → α)
(φ) (sinc_φ : strictly_increasing φ)
{m n} (m_le_n : m ≤ n)
: partial_sum (translate (shape_sum seq φ) m) (n - m)
= partial_sum (translate seq (φ m)) (φ n - φ m) :=
begin
let strong_inc := strictly_increasing.as_increasing_strong _ sinc_φ,
induction n with n hn,
cases m_le_n,
rw [nat.sub_self, nat.sub_self, partial_sum, partial_sum],
cases nat.of_le_succ m_le_n,
rw nat.succ_sub h,
rw partial_sum,
rw hn h,
rw translate,
rw nat.add_sub_of_le h,
rw shape_sum,
rw ← partial_sum.sub_as_translate seq (strong_inc _ _ h),
rw ← partial_sum.sub_as_translate seq (strong_inc _ _ m_le_n),
rw has_sub_add_sub_cancel.eq,
rw h,
rw [nat.sub_self, nat.sub_self, partial_sum, partial_sum],
end
end series --————————————————————————————————————————————————————————————————————————————--
section absolute_value --————————————————————————————————————————————————————————————————--
variables [has_zero α] [has_add α]
/--
-/
def triangle_inequality
[has_zero β] [has_add β] [preorder β] [has_add_le_add β]
(abs : α → β)
(abs_zero : abs 0 = 0)
(abs_triangle : Π x y, abs (x + y) ≤ abs x + abs y)
(seq) (n)
: abs (partial_sum seq n) ≤ partial_sum (abs ∘ seq) n :=
begin
induction n with _ hn,
rw [partial_sum, partial_sum],
rw abs_zero,
refine le_trans (abs_triangle _ _) (has_add_le_add.le (le_refl _) hn),
end
/--
-/
def triangle_equality
[preorder α] [has_add_nonneg α]
(abs : α → α)
(nonneg_to_abs : Π z, 0 ≤ z → abs z = z)
(seq nonneg) (n)
: abs (partial_sum seq n) = partial_sum seq n
:= nonneg_to_abs _ (partial_sum.preserve_nonneg _ nonneg _)
end absolute_value --————————————————————————————————————————————————————————————————————--
end riemann_hypothesis --————————————————————————————————————————————————————————————————--
|
a06416c52233b5c91b7053901d82be5d1b08ac9a | 4727251e0cd73359b15b664c3170e5d754078599 | /src/set_theory/cardinal/divisibility.lean | 0abd61ae6e5bad5ead96eff4c5fd697a8194d378 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 5,181 | lean | /-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import algebra.is_prime_pow
import set_theory.cardinal.ordinal
/-!
# Cardinal Divisibility
We show basic results about divisibility in the cardinal numbers. This relation can be characterised
in the following simple way: if `a` and `b` are both less than `ω`, then `a ∣ b` iff they are
divisible as natural numbers. If `b` is greater than `ω`, then `a ∣ b` iff `a ≤ b`. This furthermore
shows that all infinite cardinals are prime; recall that `a * b = max a b` if `ω ≤ a * b`; therefore
`a ∣ b * c = a ∣ max b c` and therefore clearly either `a ∣ b` or `a ∣ c`. Note furthermore that
no infinite cardinal is irreducible (`cardinal.not_irreducible_of_omega_le`), showing that the
cardinal numbers do not form a `comm_cancel_monoid_with_zero`.
## Main results
* `cardinal.prime_of_omega_le`: a `cardinal` is prime if it is infinite.
* `cardinal.is_prime_iff`: a `cardinal` is prime iff it is infinite or a prime natural number.
* `cardinal.is_prime_pow_iff`: a `cardinal` is a prime power iff it is infinite or a natural number
which is itself a prime power.
-/
namespace cardinal
open_locale cardinal
universe u
variables {a b : cardinal.{u}} {n m : ℕ}
@[simp] lemma is_unit_iff : is_unit a ↔ a = 1 :=
begin
refine ⟨λ h, _, by { rintro rfl, exact is_unit_one }⟩,
rcases eq_or_ne a 0 with rfl | ha,
{ exact (not_is_unit_zero h).elim },
rw is_unit_iff_forall_dvd at h,
cases h 1 with t ht,
rw [eq_comm, mul_eq_one_iff'] at ht,
{ exact ht.1 },
all_goals { rwa one_le_iff_ne_zero },
{ rintro rfl,
rw mul_zero at ht,
exact zero_ne_one ht }
end
instance : unique cardinal.{u}ˣ :=
{ default := 1,
uniq := λ a, units.coe_eq_one.mp $ is_unit_iff.mp a.is_unit }
theorem le_of_dvd : ∀ {a b : cardinal}, b ≠ 0 → a ∣ b → a ≤ b
| a _ b0 ⟨b, rfl⟩ := by simpa only [mul_one] using mul_le_mul_left'
(one_le_iff_ne_zero.2 (λ h : b = 0, by simpa only [h, mul_zero] using b0)) a
lemma dvd_of_le_of_omega_le (ha : a ≠ 0) (h : a ≤ b) (hb : ω ≤ b) : a ∣ b :=
⟨b, (mul_eq_right hb h ha).symm⟩
@[simp] lemma prime_of_omega_le (ha : ω ≤ a) : prime a :=
begin
refine ⟨(omega_pos.trans_le ha).ne', _, λ b c hbc, _⟩,
{ rw is_unit_iff,
exact (one_lt_omega.trans_le ha).ne' },
cases eq_or_ne (b * c) 0 with hz hz,
{ rcases mul_eq_zero.mp hz with rfl | rfl; simp },
wlog h : c ≤ b,
left,
have habc := le_of_dvd hz hbc,
rwa [mul_eq_max' $ ha.trans $ habc, max_def, if_pos h] at hbc
end
lemma not_irreducible_of_omega_le (ha : ω ≤ a) : ¬irreducible a :=
begin
rw [irreducible_iff, not_and_distrib],
refine or.inr (λ h, _),
simpa [mul_omega_eq ha, is_unit_iff, (one_lt_omega.trans_le ha).ne', one_lt_omega.ne'] using h a ω
end
@[simp, norm_cast] lemma nat_coe_dvd_iff : (n : cardinal) ∣ m ↔ n ∣ m :=
begin
refine ⟨_, λ ⟨h, ht⟩, ⟨h, by exact_mod_cast ht⟩⟩,
rintro ⟨k, hk⟩,
have : ↑m < ω := nat_lt_omega m,
rw [hk, mul_lt_omega_iff] at this,
rcases this with h | h | ⟨-, hk'⟩,
iterate 2 { simp only [h, mul_zero, zero_mul, nat.cast_eq_zero] at hk, simp [hk] },
lift k to ℕ using hk',
exact ⟨k, by exact_mod_cast hk⟩
end
@[simp] lemma nat_is_prime_iff : prime (n : cardinal) ↔ n.prime :=
begin
simp only [prime, nat.prime_iff],
refine and_congr (by simp) (and_congr _ ⟨λ h b c hbc, _, λ h b c hbc, _⟩),
{ simp only [is_unit_iff, nat.is_unit_iff],
exact_mod_cast iff.rfl },
{ exact_mod_cast h b c (by exact_mod_cast hbc) },
cases lt_or_le (b * c) ω with h' h',
{ rcases mul_lt_omega_iff.mp h' with rfl | rfl | ⟨hb, hc⟩,
{ simp },
{ simp },
lift b to ℕ using hb,
lift c to ℕ using hc,
exact_mod_cast h b c (by exact_mod_cast hbc) },
rcases omega_le_mul_iff.mp h' with ⟨hb, hc, hω⟩,
have hn : (n : cardinal) ≠ 0,
{ intro h,
rw [h, zero_dvd_iff, mul_eq_zero] at hbc,
cases hbc; contradiction },
wlog hω : ω ≤ b := hω using [b c],
exact or.inl (dvd_of_le_of_omega_le hn ((nat_lt_omega n).le.trans hω) hω),
end
lemma is_prime_iff {a : cardinal} : prime a ↔ ω ≤ a ∨ ∃ p : ℕ, a = p ∧ p.prime :=
begin
cases le_or_lt ω a with h h,
{ simp [h] },
lift a to ℕ using id h,
simp [not_le.mpr h]
end
lemma is_prime_pow_iff {a : cardinal} : is_prime_pow a ↔ ω ≤ a ∨ ∃ n : ℕ, a = n ∧ is_prime_pow n :=
begin
by_cases h : ω ≤ a,
{ simp [h, (prime_of_omega_le h).is_prime_pow] },
lift a to ℕ using not_le.mp h,
simp only [h, nat.cast_inj, exists_eq_left', false_or, is_prime_pow_nat_iff],
rw is_prime_pow_def,
refine ⟨_, λ ⟨p, k, hp, hk, h⟩, ⟨p, k, nat_is_prime_iff.2 hp, by exact_mod_cast and.intro hk h⟩⟩,
rintro ⟨p, k, hp, hk, hpk⟩,
have key : _ ≤ p ^ k :=
power_le_power_left hp.ne_zero (show (1 : cardinal) ≤ k, by exact_mod_cast hk),
rw [power_one, hpk] at key,
lift p to ℕ using key.trans_lt (nat_lt_omega a),
exact ⟨p, k, nat_is_prime_iff.mp hp, hk, by exact_mod_cast hpk⟩
end
end cardinal
|
f766b79fb01087ea081685be655af63e580e96a1 | cf39355caa609c0f33405126beee2739aa3cb77e | /leanpkg/leanpkg/proc.lean | 921e71b2f6f1379efd34550f0e785c9db7b5397f | [
"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 | 699 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Gabriel Ebner
-/
import system.io leanpkg.toml
open io io.proc
namespace leanpkg
def exec_cmd (args : io.process.spawn_args) : io unit := do
let cmdstr := join " " (args.cmd :: args.args),
io.put_str_ln $ "> " ++
match args.cwd with
| some cwd := cmdstr ++ " # in directory " ++ cwd
| none := cmdstr
end,
ch ← spawn args,
exitv ← wait ch,
when (exitv ≠ 0) $ io.fail $
"external command exited with status " ++ repr exitv
def change_dir (dir : string) : io unit := do
io.put_str_ln sformat!"> cd {dir}",
io.env.set_cwd dir
end leanpkg
|
0f31ed28893e1940e64dad29ccb06a47a39d5c0d | 22e97a5d648fc451e25a06c668dc03ac7ed7bc25 | /src/data/complex/module.lean | c984ba2e819abf1180e26b6142c5945853e14ea6 | [
"Apache-2.0"
] | permissive | keeferrowan/mathlib | f2818da875dbc7780830d09bd4c526b0764a4e50 | aad2dfc40e8e6a7e258287a7c1580318e865817e | refs/heads/master | 1,661,736,426,952 | 1,590,438,032,000 | 1,590,438,032,000 | 266,892,663 | 0 | 0 | Apache-2.0 | 1,590,445,835,000 | 1,590,445,835,000 | null | UTF-8 | Lean | false | false | 842 | lean | /-
Copyright (c) 2020 Alexander Bentkamp, Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Sébastien Gouëzel
-/
import data.complex.basic
import ring_theory.algebra
/-!
This file contains two instance, the fact the ℂ is an ℝ algebra,
and an instance to view any complex vector space as a
real vector space
-/
noncomputable theory
namespace complex
instance algebra_over_reals : algebra ℝ ℂ := (ring_hom.of coe).to_algebra
end complex
/- Register as an instance (with low priority) the fact that a complex vector space is also a real
vector space. -/
instance module.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E] : module ℝ E :=
module.restrict_scalars ℝ ℂ E
attribute [instance, priority 900] module.complex_to_real
|
32f7a979101d1d118d73bd0125598aa95611a85a | e514e8b939af519a1d5e9b30a850769d058df4e9 | /src/lib_unused/interaction_monad.lean | c1ed1290c4bfe604c8ba4abaa44f1768f28b738e | [] | no_license | semorrison/lean-rewrite-search | dca317c5a52e170fb6ffc87c5ab767afb5e3e51a | e804b8f2753366b8957be839908230ee73f9e89f | refs/heads/master | 1,624,051,754,485 | 1,614,160,817,000 | 1,614,160,817,000 | 162,660,605 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 725 | lean | -- universes u v
-- variable {state : Type}
-- variables {α : Type u} {β : Type v}
-- local notation `m` := interaction_monad state
-- meta def interaction_monad_orelse_intercept_safe {α : Type u} (t₁ : m α) (t₂ : option (unit → format) → option pos → m α) (fallback : α) : m α :=
-- let t₃ : m α := do return fallback in
-- λ s, interaction_monad.result.cases_on (t₁ s)
-- interaction_monad.result.success
-- (λ e₁ ref₁ s', interaction_monad.result.cases_on (t₂ e₁ ref₁ s)
-- interaction_monad.result.success
-- (λ e₂ ref₂ s'', interaction_monad.result.cases_on (t₃ s)
-- interaction_monad.result.success
-- interaction_monad.result.exception
-- )
-- ) |
ddad4e3b59f59189e3992ea699d98e9c6a16760f | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/app_builder_tac1.lean | fd3c0b5cb4300d3ff64df5f5aef2295bb083e647 | [
"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 | 544 | lean | open tactic list nat name
set_option trace.app_builder true
set_option pp.all true
meta definition mk_ite (c a b : expr) : tactic expr :=
mk_mapp `ite [none, some c, none, some a, some b]
example (a b : nat) : nat :=
by do a ← get_local `a,
b ← get_local `b,
mk_app `has_add.add [a, b] >>= trace,
mk_app `has_mul.mul [a, b] >>= trace,
mk_app `has_sub.sub [a, b] >>= trace,
c ← mk_app `eq [a, b],
trace c,
mk_ite c a b >>= trace,
mk_ite c b a >>= trace,
assumption,
return ()
|
6d75bbcd908fe33bcde475478db869f5a675bfa2 | 48eee836fdb5c613d9a20741c17db44c8e12e61c | /src/util/meta/default.lean | 4646e25009fbf720941301a6fc64e75b01a6504f | [
"Apache-2.0"
] | permissive | fgdorais/lean-universal | 06430443a4abe51e303e602684c2977d1f5c0834 | 9259b0f7fb3aa83a9e0a7a3eaa44c262e42cc9b1 | refs/heads/master | 1,592,479,744,136 | 1,589,473,399,000 | 1,589,473,399,000 | 196,287,552 | 1 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 259 | lean | -- Copyright © 2019 François G. Dorais. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
import .exceptional
import .expr
import .expr_ctx
import .format
import .ind_utils
import .level
import .name
import .parser |
eace03d560beac775279257eb8b52801de685e16 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/data/holor.lean | cd3e35828d22c69fb53019e824a086d5c7a995d7 | [
"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 | 14,178 | lean | /-
Copyright (c) 2018 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import algebra.module.pi algebra.big_operators.basic
/-!
# Basic properties of holors
Holors are indexed collections of tensor coefficients. Confusingly,
they are often called tensors in physics and in the neural network
community.
A holor is simply a multidimensional array of values. The size of a
holor is specified by a `list ℕ`, whose length is called the dimension
of the holor.
The tensor product of `x₁ : holor α ds₁` and `x₂ : holor α ds₂` is the
holor given by `(x₁ ⊗ x₂) (i₁ ++ i₂) = x₁ i₁ * x₂ i₂`. A holor is "of
rank at most 1" if it is a tensor product of one-dimensional holors.
The CP rank of a holor `x` is the smallest N such that `x` is the sum
of N holors of rank at most 1.
Based on the tensor library found in <https://www.isa-afp.org/entries/Deep_Learning.html>
## References
* <https://en.wikipedia.org/wiki/Tensor_rank_decomposition>
-/
universes u
open list
open_locale big_operators
/-- `holor_index ds` is the type of valid index tuples to identify an entry of a holor of dimensions `ds` -/
def holor_index (ds : list ℕ) : Type := { is : list ℕ // forall₂ (<) is ds}
namespace holor_index
variables {ds₁ ds₂ ds₃ : list ℕ}
def take : Π {ds₁ : list ℕ}, holor_index (ds₁ ++ ds₂) → holor_index ds₁
| ds is := ⟨ list.take (length ds) is.1, forall₂_take_append is.1 ds ds₂ is.2 ⟩
def drop : Π {ds₁ : list ℕ}, holor_index (ds₁ ++ ds₂) → holor_index ds₂
| ds is := ⟨ list.drop (length ds) is.1, forall₂_drop_append is.1 ds ds₂ is.2 ⟩
lemma cast_type (is : list ℕ) (eq : ds₁ = ds₂) (h : forall₂ (<) is ds₁) :
(cast (congr_arg holor_index eq) ⟨is, h⟩).val = is :=
by subst eq; refl
def assoc_right :
holor_index (ds₁ ++ ds₂ ++ ds₃) → holor_index (ds₁ ++ (ds₂ ++ ds₃)) :=
cast (congr_arg holor_index (append_assoc ds₁ ds₂ ds₃))
def assoc_left :
holor_index (ds₁ ++ (ds₂ ++ ds₃)) → holor_index (ds₁ ++ ds₂ ++ ds₃) :=
cast (congr_arg holor_index (append_assoc ds₁ ds₂ ds₃).symm)
lemma take_take :
∀ t : holor_index (ds₁ ++ ds₂ ++ ds₃),
t.assoc_right.take = t.take.take
| ⟨ is , h ⟩ := subtype.eq (by simp [assoc_right,take, cast_type, list.take_take, nat.le_add_right, min_eq_left])
lemma drop_take :
∀ t : holor_index (ds₁ ++ ds₂ ++ ds₃),
t.assoc_right.drop.take = t.take.drop
| ⟨ is , h ⟩ := subtype.eq (by simp [assoc_right, take, drop, cast_type, list.drop_take])
lemma drop_drop :
∀ t : holor_index (ds₁ ++ ds₂ ++ ds₃),
t.assoc_right.drop.drop = t.drop
| ⟨ is , h ⟩ := subtype.eq (by simp [add_comm, assoc_right, drop, cast_type, list.drop_drop])
end holor_index
/-- Holor (indexed collections of tensor coefficients) -/
def holor (α : Type u) (ds:list ℕ) := holor_index ds → α
namespace holor
variables {α : Type} {d : ℕ} {ds : list ℕ} {ds₁ : list ℕ} {ds₂ : list ℕ} {ds₃ : list ℕ}
instance [inhabited α] : inhabited (holor α ds) := ⟨λ t, default α⟩
instance [has_zero α] : has_zero (holor α ds) := ⟨λ t, 0⟩
instance [has_add α] : has_add (holor α ds) := ⟨λ x y t, x t + y t⟩
instance [has_neg α] : has_neg (holor α ds) := ⟨λ a t, - a t⟩
instance [add_semigroup α] : add_semigroup (holor α ds) := by pi_instance
instance [add_comm_semigroup α] : add_comm_semigroup (holor α ds) := by pi_instance
instance [add_monoid α] : add_monoid (holor α ds) := by pi_instance
instance [add_comm_monoid α] : add_comm_monoid (holor α ds) := by pi_instance
instance [add_group α] : add_group (holor α ds) := by pi_instance
instance [add_comm_group α] : add_comm_group (holor α ds) := by pi_instance
/- scalar product -/
instance [has_mul α] : has_scalar α (holor α ds) :=
⟨λ a x, λ t, a * x t⟩
instance [semiring α] : semimodule α (holor α ds) := pi.semimodule _ _ _
/-- The tensor product of two holors. -/
def mul [s : has_mul α] (x : holor α ds₁) (y : holor α ds₂) : holor α (ds₁ ++ ds₂) :=
λ t, x (t.take) * y (t.drop)
local infix ` ⊗ ` : 70 := mul
lemma cast_type (eq : ds₁ = ds₂) (a : holor α ds₁) :
cast (congr_arg (holor α) eq) a = (λ t, a (cast (congr_arg holor_index eq.symm) t)) :=
by subst eq; refl
def assoc_right :
holor α (ds₁ ++ ds₂ ++ ds₃) → holor α (ds₁ ++ (ds₂ ++ ds₃)) :=
cast (congr_arg (holor α) (append_assoc ds₁ ds₂ ds₃))
def assoc_left :
holor α (ds₁ ++ (ds₂ ++ ds₃)) → holor α (ds₁ ++ ds₂ ++ ds₃) :=
cast (congr_arg (holor α) (append_assoc ds₁ ds₂ ds₃).symm)
lemma mul_assoc0 [semigroup α] (x : holor α ds₁) (y : holor α ds₂) (z : holor α ds₃) :
x ⊗ y ⊗ z = (x ⊗ (y ⊗ z)).assoc_left :=
funext (assume t : holor_index (ds₁ ++ ds₂ ++ ds₃),
begin
rw assoc_left,
unfold mul,
rw mul_assoc,
rw [←holor_index.take_take, ←holor_index.drop_take, ←holor_index.drop_drop],
rw cast_type,
refl,
rw append_assoc
end)
lemma mul_assoc [semigroup α] (x : holor α ds₁) (y : holor α ds₂) (z : holor α ds₃) :
mul (mul x y) z == (mul x (mul y z)) :=
by simp [cast_heq, mul_assoc0, assoc_left].
lemma mul_left_distrib [distrib α] (x : holor α ds₁) (y : holor α ds₂) (z : holor α ds₂) :
x ⊗ (y + z) = x ⊗ y + x ⊗ z :=
funext (λt, left_distrib (x (holor_index.take t)) (y (holor_index.drop t)) (z (holor_index.drop t)))
lemma mul_right_distrib [distrib α] (x : holor α ds₁) (y : holor α ds₁) (z : holor α ds₂) :
(x + y) ⊗ z = x ⊗ z + y ⊗ z :=
funext (λt, right_distrib (x (holor_index.take t)) (y (holor_index.take t)) (z (holor_index.drop t)))
@[simp] lemma zero_mul {α : Type} [ring α] (x : holor α ds₂) :
(0 : holor α ds₁) ⊗ x = 0 :=
funext (λ t, zero_mul (x (holor_index.drop t)))
@[simp] lemma mul_zero {α : Type} [ring α] (x : holor α ds₁) :
x ⊗ (0 :holor α ds₂) = 0 :=
funext (λ t, mul_zero (x (holor_index.take t)))
lemma mul_scalar_mul [monoid α] (x : holor α []) (y : holor α ds) :
x ⊗ y = x ⟨[], forall₂.nil⟩ • y :=
by simp [mul, has_scalar.smul, holor_index.take, holor_index.drop]
/- holor slices -/
/-- A slice is a subholor consisting of all entries with initial index i. -/
def slice (x : holor α (d :: ds)) (i : ℕ) (h : i < d) : holor α ds :=
(λ is : holor_index ds, x ⟨ i :: is.1, forall₂.cons h is.2⟩)
/-- The 1-dimensional "unit" holor with 1 in the `j`th position. -/
def unit_vec [monoid α] [add_monoid α] (d : ℕ) (j : ℕ) : holor α [d] :=
λ ti, if ti.1 = [j] then 1 else 0
lemma holor_index_cons_decomp (p: holor_index (d :: ds) → Prop) :
Π (t : holor_index (d :: ds)),
(∀ i is, Π h : t.1 = i :: is, p ⟨ i :: is, begin rw [←h], exact t.2 end ⟩ ) → p t
| ⟨[], hforall₂⟩ hp := absurd (forall₂_nil_left_iff.1 hforall₂) (cons_ne_nil d ds)
| ⟨(i :: is), hforall₂⟩ hp := hp i is rfl
/-- Two holors are equal if all their slices are equal. -/
lemma slice_eq (x : holor α (d :: ds)) (y : holor α (d :: ds))
(h : slice x = slice y) : x = y :=
funext $ λ t : holor_index (d :: ds), holor_index_cons_decomp (λ t, x t = y t) t $ λ i is hiis,
have hiisdds: forall₂ (<) (i :: is) (d :: ds), begin rw [←hiis], exact t.2 end,
have hid: i<d, from (forall₂_cons.1 hiisdds).1,
have hisds: forall₂ (<) is ds, from (forall₂_cons.1 hiisdds).2,
calc
x ⟨i :: is, _⟩ = slice x i hid ⟨is, hisds⟩ : congr_arg (λ t, x t) (subtype.eq rfl)
... = slice y i hid ⟨is, hisds⟩ : by rw h
... = y ⟨i :: is, _⟩ : congr_arg (λ t, y t) (subtype.eq rfl)
lemma slice_unit_vec_mul [ring α] {i : ℕ} {j : ℕ}
(hid : i < d) (x : holor α ds) :
slice (unit_vec d j ⊗ x) i hid = if i=j then x else 0 :=
funext $ λ t : holor_index ds, if h : i = j
then by simp [slice, mul, holor_index.take, unit_vec, holor_index.drop, h]
else by simp [slice, mul, holor_index.take, unit_vec, holor_index.drop, h]; refl
lemma slice_add [has_add α] (i : ℕ) (hid : i < d) (x : holor α (d :: ds)) (y : holor α (d :: ds)) :
slice x i hid + slice y i hid = slice (x + y) i hid := funext (λ t, by simp [slice,(+)])
lemma slice_zero [has_zero α] (i : ℕ) (hid : i < d) :
slice (0 : holor α (d :: ds)) i hid = 0 := funext (λ t, by simp [slice]; refl)
lemma slice_sum [add_comm_monoid α] {β : Type}
(i : ℕ) (hid : i < d) (s : finset β) (f : β → holor α (d :: ds)) :
∑ x in s, slice (f x) i hid = slice (∑ x in s, f x) i hid :=
begin
letI := classical.dec_eq β,
refine finset.induction_on s _ _,
{ simp [slice_zero] },
{ intros _ _ h_not_in ih,
rw [finset.sum_insert h_not_in, ih, slice_add, finset.sum_insert h_not_in] }
end
/-- The original holor can be recovered from its slices by multiplying with unit vectors and summing up. -/
@[simp] lemma sum_unit_vec_mul_slice [ring α] (x : holor α (d :: ds)) :
∑ i in (finset.range d).attach,
unit_vec d i ⊗ slice x i (nat.succ_le_of_lt (finset.mem_range.1 i.prop)) = x :=
begin
apply slice_eq _ _ _,
ext i hid,
rw [←slice_sum],
simp only [slice_unit_vec_mul hid],
rw finset.sum_eq_single (subtype.mk i $ finset.mem_range.2 hid),
{ simp },
{ assume (b : {x // x ∈ finset.range d}) (hb : b ∈ (finset.range d).attach) (hbi : b ≠ ⟨i, _⟩),
have hbi' : i ≠ b,
{ simpa only [ne.def, subtype.ext_iff, subtype.coe_mk] using hbi.symm },
simp [hbi'] },
{ assume hid' : subtype.mk i _ ∉ finset.attach (finset.range d),
exfalso,
exact absurd (finset.mem_attach _ _) hid'
}
end
/- CP rank -/
/-- `cprank_max1 x` means `x` has CP rank at most 1, that is,
it is the tensor product of 1-dimensional holors. -/
inductive cprank_max1 [has_mul α]: Π {ds}, holor α ds → Prop
| nil (x : holor α []) :
cprank_max1 x
| cons {d} {ds} (x : holor α [d]) (y : holor α ds) :
cprank_max1 y → cprank_max1 (x ⊗ y)
/-- `cprank_max N x` means `x` has CP rank at most `N`, that is,
it can be written as the sum of N holors of rank at most 1. -/
inductive cprank_max [has_mul α] [add_monoid α] : ℕ → Π {ds}, holor α ds → Prop
| zero {ds} :
cprank_max 0 (0 : holor α ds)
| succ n {ds} (x : holor α ds) (y : holor α ds) :
cprank_max1 x → cprank_max n y → cprank_max (n+1) (x + y)
lemma cprank_max_nil [monoid α] [add_monoid α] (x : holor α nil) : cprank_max 1 x :=
have h : _, from cprank_max.succ 0 x 0 (cprank_max1.nil x) (cprank_max.zero),
by rwa [add_zero x, zero_add] at h
lemma cprank_max_1 [monoid α] [add_monoid α] {x : holor α ds}
(h : cprank_max1 x) : cprank_max 1 x :=
have h' : _, from cprank_max.succ 0 x 0 h cprank_max.zero,
by rwa [zero_add, add_zero] at h'
lemma cprank_max_add [monoid α] [add_monoid α]:
∀ {m : ℕ} {n : ℕ} {x : holor α ds} {y : holor α ds},
cprank_max m x → cprank_max n y → cprank_max (m + n) (x + y)
| 0 n x y (cprank_max.zero) hy := by simp [hy]
| (m+1) n _ y (cprank_max.succ k x₁ x₂ hx₁ hx₂) hy :=
begin
simp only [add_comm, add_assoc],
apply cprank_max.succ,
{ assumption },
{ exact cprank_max_add hx₂ hy }
end
lemma cprank_max_mul [ring α] :
∀ (n : ℕ) (x : holor α [d]) (y : holor α ds), cprank_max n y → cprank_max n (x ⊗ y)
| 0 x _ (cprank_max.zero) := by simp [mul_zero x, cprank_max.zero]
| (n+1) x _ (cprank_max.succ k y₁ y₂ hy₁ hy₂) :=
begin
rw mul_left_distrib,
rw nat.add_comm,
apply cprank_max_add,
{ exact cprank_max_1 (cprank_max1.cons _ _ hy₁) },
{ exact cprank_max_mul k x y₂ hy₂ }
end
lemma cprank_max_sum [ring α] {β} {n : ℕ} (s : finset β) (f : β → holor α ds) :
(∀ x ∈ s, cprank_max n (f x)) → cprank_max (s.card * n) (∑ x in s, f x) :=
by letI := classical.dec_eq β;
exact finset.induction_on s
(by simp [cprank_max.zero])
(begin
assume x s (h_x_notin_s : x ∉ s) ih h_cprank,
simp only [finset.sum_insert h_x_notin_s,finset.card_insert_of_not_mem h_x_notin_s],
rw nat.right_distrib,
simp only [nat.one_mul, nat.add_comm],
have ih' : cprank_max (finset.card s * n) (∑ x in s, f x),
{
apply ih,
assume (x : β) (h_x_in_s: x ∈ s),
simp only [h_cprank, finset.mem_insert_of_mem, h_x_in_s]
},
exact (cprank_max_add (h_cprank x (finset.mem_insert_self x s)) ih')
end)
lemma cprank_max_upper_bound [ring α] : Π {ds}, ∀ x : holor α ds, cprank_max ds.prod x
| [] x := cprank_max_nil x
| (d :: ds) x :=
have h_summands : Π (i : {x // x ∈ finset.range d}),
cprank_max ds.prod (unit_vec d i.1 ⊗ slice x i.1 (mem_range.1 i.2)),
from λ i, cprank_max_mul _ _ _ (cprank_max_upper_bound (slice x i.1 (mem_range.1 i.2))),
have h_dds_prod : (list.cons d ds).prod = finset.card (finset.range d) * prod ds,
by simp [finset.card_range],
have cprank_max (finset.card (finset.attach (finset.range d)) * prod ds)
(∑ i in finset.attach (finset.range d), unit_vec d (i.val)⊗slice x (i.val) (mem_range.1 i.2)),
from cprank_max_sum (finset.range d).attach _ (λ i _, h_summands i),
have h_cprank_max_sum : cprank_max (finset.card (finset.range d) * prod ds)
(∑ i in finset.attach (finset.range d), unit_vec d (i.val)⊗slice x (i.val) (mem_range.1 i.2)),
by rwa [finset.card_attach] at this,
begin
rw [←sum_unit_vec_mul_slice x],
rw [h_dds_prod],
exact h_cprank_max_sum,
end
/-- The CP rank of a holor `x`: the smallest N such that
`x` can be written as the sum of N holors of rank at most 1. -/
noncomputable def cprank [ring α] (x : holor α ds) : nat :=
@nat.find (λ n, cprank_max n x) (classical.dec_pred _) ⟨ds.prod, cprank_max_upper_bound x⟩
lemma cprank_upper_bound [ring α] :
Π {ds}, ∀ x : holor α ds, cprank x ≤ ds.prod :=
λ ds (x : holor α ds),
by letI := classical.dec_pred (λ (n : ℕ), cprank_max n x);
exact nat.find_min'
⟨ds.prod, show (λ n, cprank_max n x) ds.prod, from cprank_max_upper_bound x⟩
(cprank_max_upper_bound x)
end holor
|
37ae711f99173c2bceac34a1f6289326b8c91e89 | 01ae0d022f2e2fefdaaa898938c1ac1fbce3b3ab | /categories/universal/universal.lean | 3e44d8b55b5b86085810d4aac6cd8937fb651eaa | [] | no_license | PatrickMassot/lean-category-theory | 0f56a83464396a253c28a42dece16c93baf8ad74 | ef239978e91f2e1c3b8e88b6e9c64c155dc56c99 | refs/heads/master | 1,629,739,187,316 | 1,512,422,659,000 | 1,512,422,659,000 | 113,098,786 | 0 | 0 | null | 1,512,424,022,000 | 1,512,424,022,000 | null | UTF-8 | Lean | false | false | 5,796 | 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 .cones
import ..util.hlist
import ..util.finite
open categories
open categories.functor
open categories.isomorphism
open categories.initial
open categories.types
open categories.util
open categories.util.finite
namespace categories.universal
structure Equalizer { C : Category } { X Y : C.Obj } ( f g : C.Hom X Y ) :=
( equalizer : C.Obj )
( inclusion : C.Hom equalizer X )
( witness : C.compose inclusion f = C.compose inclusion g )
( map : ∀ { Z : C.Obj } ( k : C.Hom Z X ) ( w : C.compose k f = C.compose k g ), C.Hom Z equalizer )
( factorisation : ∀ { Z : C.Obj } ( k : C.Hom Z X ) ( w : C.compose k f = C.compose k g ), C.compose (map k w) inclusion = k )
( uniqueness : ∀ { Z : C.Obj } ( a b : C.Hom Z equalizer ) ( witness : C.compose a inclusion = C.compose b inclusion ), a = b )
-- Or should we write out yet another structure, and prove it agrees with the equalizer?
definition Kernel { C : Category } [ Z : ZeroObject C ] { X Y : C.Obj } ( f : C.Hom X Y ) := Equalizer f ( Z.zero_morphism X Y )
attribute [simp,ematch] Equalizer.factorisation
attribute [applicable] Equalizer.inclusion Equalizer.map
attribute [applicable] Equalizer.uniqueness
structure BinaryProduct { C : Category } ( X Y : C.Obj ) :=
( product : C.Obj )
( left_projection : C.Hom product X )
( right_projection : C.Hom product Y )
( map : ∀ { Z : C.Obj } ( f : C.Hom Z X ) ( g : C.Hom Z Y ), C.Hom Z product )
( left_factorisation : ∀ { Z : C.Obj } ( f : C.Hom Z X ) ( g : C.Hom Z Y ), C.compose (map f g) left_projection = f )
( right_factorisation : ∀ { Z : C.Obj } ( f : C.Hom Z X ) ( g : C.Hom Z Y ), C.compose (map f g) right_projection = g )
( uniqueness : ∀ { Z : C.Obj } ( f g : C.Hom Z product )
( left_witness : C.compose f left_projection = C.compose g left_projection )
( right_witness : C.compose f right_projection = C.compose g right_projection ), f = g )
attribute [simp,ematch] BinaryProduct.left_factorisation BinaryProduct.right_factorisation
attribute [applicable] BinaryProduct.left_projection BinaryProduct.right_projection BinaryProduct.map
attribute [applicable] BinaryProduct.uniqueness
structure Product { C : Category } { I : Type } ( F : I → C.Obj ) :=
( product : C.Obj )
( projection : Π i : I, C.Hom product (F i) )
( map : ∀ { Z : C.Obj } ( f : Π i : I, C.Hom Z (F i) ), C.Hom Z product )
( factorisation : ∀ { Z : C.Obj } ( f : Π i : I, C.Hom Z (F i) ) ( i : I ), C.compose (map f) (projection i) = f i )
( uniqueness : ∀ { Z : C.Obj } ( f g : C.Hom Z product ) ( witness : ∀ i : I, C.compose f (projection i) = C.compose g (projection i)), f = g )
attribute [simp,ematch] Product.factorisation
attribute [applicable] Product.projection Product.map
attribute [applicable] Product.uniqueness
structure Coequalizer { C : Category } { X Y : C.Obj } ( f g : C.Hom X Y ) :=
( coequalizer : C.Obj )
( projection : C.Hom Y coequalizer )
( witness : C.compose f projection = C.compose g projection )
( map : ∀ { Z : C.Obj } ( k : C.Hom Y Z ) ( w : C.compose f k = C.compose g k ), C.Hom coequalizer Z )
( factorisation : ∀ { Z : C.Obj } ( k : C.Hom Y Z ) ( w : C.compose f k = C.compose g k ), C.compose projection (map k w) = k )
( uniqueness : ∀ { Z : C.Obj } ( a b : C.Hom coequalizer Z ) ( witness : C.compose projection a = C.compose projection b ), a = b )
attribute [simp,ematch] Coequalizer.factorisation
attribute [applicable] Coequalizer.projection Coequalizer.map
attribute [applicable] Coequalizer.uniqueness
definition Cokernel { C : Category } [ Z : ZeroObject C ] { X Y : C.Obj } ( f : C.Hom X Y ) := Coequalizer f ( Z.zero_morphism X Y )
structure BinaryCoproduct { C : Category } ( X Y : C.Obj ) :=
( coproduct : C.Obj )
( left_inclusion : C.Hom X coproduct )
( right_inclusion : C.Hom Y coproduct )
( map : ∀ { Z : C.Obj } ( f : C.Hom X Z ) ( g : C.Hom Y Z ), C.Hom coproduct Z )
( left_factorisation : ∀ { Z : C.Obj } ( f : C.Hom X Z ) ( g : C.Hom Y Z ), C.compose left_inclusion (map f g) = f )
( right_factorisation : ∀ { Z : C.Obj } ( f : C.Hom X Z ) ( g : C.Hom Y Z ), C.compose right_inclusion(map f g) = g )
( uniqueness : ∀ { Z : C.Obj } ( f g : C.Hom coproduct Z )
( left_witness : C.compose left_inclusion f = C.compose left_inclusion g )
( right_witness : C.compose right_inclusion f = C.compose right_inclusion g ), f = g )
attribute [simp,ematch] BinaryCoproduct.left_factorisation BinaryCoproduct.right_factorisation
attribute [applicable] BinaryCoproduct.left_inclusion BinaryCoproduct.right_inclusion BinaryCoproduct.map
attribute [applicable] BinaryCoproduct.uniqueness
structure Coproduct { C : Category } { I : Type } ( X : I → C.Obj ) :=
( coproduct : C.Obj )
( inclusion : Π i : I, C.Hom (X i) coproduct )
( map : ∀ { Z : C.Obj } ( f : Π i : I, C.Hom (X i) Z ), C.Hom coproduct Z )
( factorisation : ∀ { Z : C.Obj } ( f : Π i : I, C.Hom (X i) Z ) ( i : I ), C.compose (inclusion i) (map f) = f i )
( uniqueness : ∀ { Z : C.Obj } ( f g : C.Hom coproduct Z ) ( witness : ∀ i : I, C.compose (inclusion i) f = C.compose (inclusion i) g), f = g )
@[reducible] definition {u} unique_up_to_isomorphism ( α : Type u ) { C : Category } ( f : α → C.Obj ) := Π X Y : α, Isomorphism C (f X) (f Y)
end categories.universal
|
ec7cd369f310183b512852cab3a825cfd71fe9e3 | d1a52c3f208fa42c41df8278c3d280f075eb020c | /stage0/src/Leanpkg/Resolve.lean | 57f76c1b02c79ad9b293478dd3e92b0dd18a9e13 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 3,114 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sebastian Ullrich
-/
import Leanpkg.Manifest
import Leanpkg.Proc
import Leanpkg.Git
open System
namespace Leanpkg
def Assignment := List (String × FilePath)
namespace Assignment
def empty : Assignment := []
def contains (a : Assignment) (s : String) : Bool :=
(a.lookup s).isSome
def insert (a : Assignment) (k : String) (v : FilePath) : Assignment :=
if a.contains k then a else (k, v) :: a
def fold {α} (i : α) (f : α → String → FilePath → α) : Assignment → α :=
List.foldl (fun a ⟨k, v⟩ => f a k v) i
end Assignment
abbrev Solver := StateT Assignment IO
def notYetAssigned (d : String) : Solver Bool := do
¬ (← get).contains d
def resolvedPath (d : String) : Solver FilePath := do
let some path ← pure ((← get).lookup d) | unreachable!
path
def materialize (relpath : FilePath) (dep : Dependency) : Solver Unit :=
match dep.src with
| Source.path dir => do
let depdir := dir / relpath
IO.eprintln s!"{dep.name}: using local path {depdir}"
modify (·.insert dep.name depdir)
| Source.git url rev branch => do
let depdir := FilePath.mk "build" / "deps" / dep.name
if ← depdir.isDir then
IO.eprint s!"{dep.name}: trying to update {depdir} to revision {rev}"
IO.eprintln (match branch with | none => "" | some branch => "@" ++ branch)
let hash ← gitParseOriginRevision depdir rev
let revEx ← gitRevisionExists depdir hash
unless revEx do
execCmd {cmd := "git", args := #["fetch"], cwd := depdir}
else
IO.eprintln s!"{dep.name}: cloning {url} to {depdir}"
execCmd {cmd := "git", args := #["clone", url, depdir.toString]}
let hash ← gitParseOriginRevision depdir rev
execCmd {cmd := "git", args := #["checkout", "--detach", hash], cwd := depdir}
modify (·.insert dep.name depdir)
def solveDepsCore (relPath : FilePath) (d : Manifest) : (maxDepth : Nat) → Solver Unit
| 0 => throw <| IO.userError "maximum dependency resolution depth reached"
| maxDepth + 1 => do
let deps ← d.dependencies.filterM (notYetAssigned ·.name)
deps.forM (materialize relPath)
for dep in deps do
let p ← resolvedPath dep.name
let d' ← Manifest.fromFile $ p / "leanpkg.toml"
unless d'.name = dep.name do
throw <| IO.userError s!"{d.name} (in {relPath}) depends on {d'.name}, but resolved dependency has name {dep.name} (in {p})"
solveDepsCore p d' maxDepth
def solveDeps (d : Manifest) : IO Assignment := do
let (_, assg) ← (solveDepsCore ⟨"."⟩ d 1024).run <| Assignment.empty.insert d.name ⟨"."⟩
assg
def constructPathCore (depname : String) (dirname : FilePath) : IO FilePath := do
let path ← Manifest.effectivePath (← Manifest.fromFile <| dirname / leanpkgTomlFn)
return dirname / path
def constructPath (assg : Assignment) : IO (List FilePath) := do
assg.reverse.mapM fun ⟨depname, dirname⟩ => constructPathCore depname dirname
end Leanpkg
|
a01cd568c4061c80863985fc22d9c5f091f47eec | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/order/filter/at_top_bot.lean | e2a9244bc9fb7449866396d702c21b529431ffc0 | [
"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 | 61,673 | 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, Jeremy Avigad, Yury Kudryashov, Patrick Massot
-/
import order.filter.bases
import data.finset.preimage
/-!
# `at_top` and `at_bot` filters on preorded sets, monoids and groups.
In this file we define the filters
* `at_top`: corresponds to `n → +∞`;
* `at_bot`: corresponds to `n → -∞`.
Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”.
-/
variables {ι ι' α β γ : Type*}
open set
open_locale classical filter big_operators
namespace filter
/-- `at_top` is the filter representing the limit `→ ∞` on an ordered set.
It is generated by the collection of up-sets `{b | a ≤ b}`.
(The preorder need not have a top element for this to be well defined,
and indeed is trivial when a top element exists.) -/
def at_top [preorder α] : filter α := ⨅ a, 𝓟 (Ici a)
/-- `at_bot` is the filter representing the limit `→ -∞` on an ordered set.
It is generated by the collection of down-sets `{b | b ≤ a}`.
(The preorder need not have a bottom element for this to be well defined,
and indeed is trivial when a bottom element exists.) -/
def at_bot [preorder α] : filter α := ⨅ a, 𝓟 (Iic a)
lemma mem_at_top [preorder α] (a : α) : {b : α | a ≤ b} ∈ @at_top α _ :=
mem_infi_of_mem a $ subset.refl _
lemma Ioi_mem_at_top [preorder α] [no_top_order α] (x : α) : Ioi x ∈ (at_top : filter α) :=
let ⟨z, hz⟩ := no_top x in mem_of_superset (mem_at_top z) $ λ y h, lt_of_lt_of_le hz h
lemma mem_at_bot [preorder α] (a : α) : {b : α | b ≤ a} ∈ @at_bot α _ :=
mem_infi_of_mem a $ subset.refl _
lemma Iio_mem_at_bot [preorder α] [no_bot_order α] (x : α) : Iio x ∈ (at_bot : filter α) :=
let ⟨z, hz⟩ := no_bot x in mem_of_superset (mem_at_bot z) $ λ y h, lt_of_le_of_lt h hz
lemma at_top_basis [nonempty α] [semilattice_sup α] :
(@at_top α _).has_basis (λ _, true) Ici :=
has_basis_infi_principal (directed_of_sup $ λ a b, Ici_subset_Ici.2)
lemma at_top_basis' [semilattice_sup α] (a : α) :
(@at_top α _).has_basis (λ x, a ≤ x) Ici :=
⟨λ t, (@at_top_basis α ⟨a⟩ _).mem_iff.trans
⟨λ ⟨x, _, hx⟩, ⟨x ⊔ a, le_sup_right, λ y hy, hx (le_trans le_sup_left hy)⟩,
λ ⟨x, _, hx⟩, ⟨x, trivial, hx⟩⟩⟩
lemma at_bot_basis [nonempty α] [semilattice_inf α] :
(@at_bot α _).has_basis (λ _, true) Iic :=
@at_top_basis (order_dual α) _ _
lemma at_bot_basis' [semilattice_inf α] (a : α) :
(@at_bot α _).has_basis (λ x, x ≤ a) Iic :=
@at_top_basis' (order_dual α) _ _
@[instance]
lemma at_top_ne_bot [nonempty α] [semilattice_sup α] : ne_bot (at_top : filter α) :=
at_top_basis.ne_bot_iff.2 $ λ a _, nonempty_Ici
@[instance]
lemma at_bot_ne_bot [nonempty α] [semilattice_inf α] : ne_bot (at_bot : filter α) :=
@at_top_ne_bot (order_dual α) _ _
@[simp]
lemma mem_at_top_sets [nonempty α] [semilattice_sup α] {s : set α} :
s ∈ (at_top : filter α) ↔ ∃a:α, ∀b≥a, b ∈ s :=
at_top_basis.mem_iff.trans $ exists_congr $ λ _, exists_const _
@[simp]
lemma mem_at_bot_sets [nonempty α] [semilattice_inf α] {s : set α} :
s ∈ (at_bot : filter α) ↔ ∃a:α, ∀b≤a, b ∈ s :=
@mem_at_top_sets (order_dual α) _ _ _
@[simp]
lemma eventually_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} :
(∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ b ≥ a, p b) :=
mem_at_top_sets
@[simp]
lemma eventually_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} :
(∀ᶠ x in at_bot, p x) ↔ (∃ a, ∀ b ≤ a, p b) :=
mem_at_bot_sets
lemma eventually_ge_at_top [preorder α] (a : α) : ∀ᶠ x in at_top, a ≤ x := mem_at_top a
lemma eventually_le_at_bot [preorder α] (a : α) : ∀ᶠ x in at_bot, x ≤ a := mem_at_bot a
lemma eventually_gt_at_top [preorder α] [no_top_order α] (a : α) :
∀ᶠ x in at_top, a < x :=
Ioi_mem_at_top a
lemma eventually_lt_at_bot [preorder α] [no_bot_order α] (a : α) :
∀ᶠ x in at_bot, x < a :=
Iio_mem_at_bot a
lemma at_top_basis_Ioi [nonempty α] [semilattice_sup α] [no_top_order α] :
(@at_top α _).has_basis (λ _, true) Ioi :=
at_top_basis.to_has_basis (λ a ha, ⟨a, ha, Ioi_subset_Ici_self⟩) $
λ a ha, (no_top a).imp $ λ b hb, ⟨ha, Ici_subset_Ioi.2 hb⟩
lemma at_top_countable_basis [nonempty α] [semilattice_sup α] [encodable α] :
has_countable_basis (at_top : filter α) (λ _, true) Ici :=
{ countable := countable_encodable _,
.. at_top_basis }
lemma at_bot_countable_basis [nonempty α] [semilattice_inf α] [encodable α] :
has_countable_basis (at_bot : filter α) (λ _, true) Iic :=
{ countable := countable_encodable _,
.. at_bot_basis }
lemma is_countably_generated_at_top [nonempty α] [semilattice_sup α] [encodable α] :
(at_top : filter $ α).is_countably_generated :=
at_top_countable_basis.is_countably_generated
lemma is_countably_generated_at_bot [nonempty α] [semilattice_inf α] [encodable α] :
(at_bot : filter $ α).is_countably_generated :=
at_bot_countable_basis.is_countably_generated
lemma order_top.at_top_eq (α) [order_top α] : (at_top : filter α) = pure ⊤ :=
le_antisymm (le_pure_iff.2 $ (eventually_ge_at_top ⊤).mono $ λ b, top_unique)
(le_infi $ λ b, le_principal_iff.2 le_top)
lemma order_bot.at_bot_eq (α) [order_bot α] : (at_bot : filter α) = pure ⊥ :=
@order_top.at_top_eq (order_dual α) _
@[nontriviality]
lemma subsingleton.at_top_eq (α) [subsingleton α] [preorder α] : (at_top : filter α) = ⊤ :=
begin
refine top_unique (λ s hs x, _),
letI : unique α := ⟨⟨x⟩, λ y, subsingleton.elim y x⟩,
rw [at_top, infi_unique, unique.default_eq x, mem_principal] at hs,
exact hs left_mem_Ici
end
@[nontriviality]
lemma subsingleton.at_bot_eq (α) [subsingleton α] [preorder α] : (at_bot : filter α) = ⊤ :=
@subsingleton.at_top_eq (order_dual α) _ _
lemma tendsto_at_top_pure [order_top α] (f : α → β) :
tendsto f at_top (pure $ f ⊤) :=
(order_top.at_top_eq α).symm ▸ tendsto_pure_pure _ _
lemma tendsto_at_bot_pure [order_bot α] (f : α → β) :
tendsto f at_bot (pure $ f ⊥) :=
@tendsto_at_top_pure (order_dual α) _ _ _
lemma eventually.exists_forall_of_at_top [semilattice_sup α] [nonempty α] {p : α → Prop}
(h : ∀ᶠ x in at_top, p x) : ∃ a, ∀ b ≥ a, p b :=
eventually_at_top.mp h
lemma eventually.exists_forall_of_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop}
(h : ∀ᶠ x in at_bot, p x) : ∃ a, ∀ b ≤ a, p b :=
eventually_at_bot.mp h
lemma frequently_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} :
(∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b ≥ a, p b) :=
by simp [at_top_basis.frequently_iff]
lemma frequently_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} :
(∃ᶠ x in at_bot, p x) ↔ (∀ a, ∃ b ≤ a, p b) :=
@frequently_at_top (order_dual α) _ _ _
lemma frequently_at_top' [semilattice_sup α] [nonempty α] [no_top_order α] {p : α → Prop} :
(∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b > a, p b) :=
by simp [at_top_basis_Ioi.frequently_iff]
lemma frequently_at_bot' [semilattice_inf α] [nonempty α] [no_bot_order α] {p : α → Prop} :
(∃ᶠ x in at_bot, p x) ↔ (∀ a, ∃ b < a, p b) :=
@frequently_at_top' (order_dual α) _ _ _ _
lemma frequently.forall_exists_of_at_top [semilattice_sup α] [nonempty α] {p : α → Prop}
(h : ∃ᶠ x in at_top, p x) : ∀ a, ∃ b ≥ a, p b :=
frequently_at_top.mp h
lemma frequently.forall_exists_of_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop}
(h : ∃ᶠ x in at_bot, p x) : ∀ a, ∃ b ≤ a, p b :=
frequently_at_bot.mp h
lemma map_at_top_eq [nonempty α] [semilattice_sup α] {f : α → β} :
at_top.map f = (⨅a, 𝓟 $ f '' {a' | a ≤ a'}) :=
(at_top_basis.map _).eq_infi
lemma map_at_bot_eq [nonempty α] [semilattice_inf α] {f : α → β} :
at_bot.map f = (⨅a, 𝓟 $ f '' {a' | a' ≤ a}) :=
@map_at_top_eq (order_dual α) _ _ _ _
lemma tendsto_at_top [preorder β] {m : α → β} {f : filter α} :
tendsto m f at_top ↔ (∀b, ∀ᶠ a in f, b ≤ m a) :=
by simp only [at_top, tendsto_infi, tendsto_principal, mem_Ici]
lemma tendsto_at_bot [preorder β] {m : α → β} {f : filter α} :
tendsto m f at_bot ↔ (∀b, ∀ᶠ a in f, m a ≤ b) :=
@tendsto_at_top α (order_dual β) _ m f
lemma tendsto_at_top_mono' [preorder β] (l : filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) :
tendsto f₁ l at_top → tendsto f₂ l at_top :=
assume h₁, tendsto_at_top.2 $ λ b, mp_mem (tendsto_at_top.1 h₁ b)
(monotone_mem (λ a ha ha₁, le_trans ha₁ ha) h)
lemma tendsto_at_bot_mono' [preorder β] (l : filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) :
tendsto f₂ l at_bot → tendsto f₁ l at_bot :=
@tendsto_at_top_mono' _ (order_dual β) _ _ _ _ h
lemma tendsto_at_top_mono [preorder β] {l : filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :
tendsto f l at_top → tendsto g l at_top :=
tendsto_at_top_mono' l $ eventually_of_forall h
lemma tendsto_at_bot_mono [preorder β] {l : filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :
tendsto g l at_bot → tendsto f l at_bot :=
@tendsto_at_top_mono _ (order_dual β) _ _ _ _ h
/-!
### Sequences
-/
lemma inf_map_at_top_ne_bot_iff [semilattice_sup α] [nonempty α] {F : filter β} {u : α → β} :
ne_bot (F ⊓ (map u at_top)) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U :=
by simp_rw [inf_ne_bot_iff_frequently_left, frequently_map, frequently_at_top]; refl
lemma inf_map_at_bot_ne_bot_iff [semilattice_inf α] [nonempty α] {F : filter β} {u : α → β} :
ne_bot (F ⊓ (map u at_bot)) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U :=
@inf_map_at_top_ne_bot_iff (order_dual α) _ _ _ _ _
lemma extraction_of_frequently_at_top' {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=
begin
choose u hu using h,
cases forall_and_distrib.mp hu with hu hu',
exact ⟨u ∘ (nat.rec 0 (λ n v, u v)), strict_mono_nat_of_lt_succ (λ n, hu _), λ n, hu' _⟩,
end
lemma extraction_of_frequently_at_top {P : ℕ → Prop} (h : ∃ᶠ n in at_top, P n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=
begin
rw frequently_at_top' at h,
exact extraction_of_frequently_at_top' h,
end
lemma extraction_of_eventually_at_top {P : ℕ → Prop} (h : ∀ᶠ n in at_top, P n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=
extraction_of_frequently_at_top h.frequently
lemma extraction_forall_of_frequently {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ᶠ k in at_top, P n k) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P n (φ n) :=
begin
simp only [frequently_at_top'] at h,
choose u hu hu' using h,
use (λ n, nat.rec_on n (u 0 0) (λ n v, u (n+1) v) : ℕ → ℕ),
split,
{ apply strict_mono_nat_of_lt_succ,
intro n,
apply hu },
{ intros n,
cases n ; simp [hu'] },
end
lemma extraction_forall_of_eventually {P : ℕ → ℕ → Prop} (h : ∀ n, ∀ᶠ k in at_top, P n k) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_frequently (λ n, (h n).frequently)
lemma extraction_forall_of_eventually' {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ N, ∀ k ≥ N, P n k) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_eventually (by simp [eventually_at_top, h])
lemma exists_le_of_tendsto_at_top [semilattice_sup α] [preorder β] {u : α → β}
(h : tendsto u at_top at_top) (a : α) (b : β) : ∃ a' ≥ a, b ≤ u a' :=
begin
have : ∀ᶠ x in at_top, a ≤ x ∧ b ≤ u x :=
(eventually_ge_at_top a).and (h.eventually $ eventually_ge_at_top b),
haveI : nonempty α := ⟨a⟩,
rcases this.exists with ⟨a', ha, hb⟩,
exact ⟨a', ha, hb⟩
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma exists_le_of_tendsto_at_bot [semilattice_sup α] [preorder β] {u : α → β}
(h : tendsto u at_top at_bot) : ∀ a b, ∃ a' ≥ a, u a' ≤ b :=
@exists_le_of_tendsto_at_top _ (order_dual β) _ _ _ h
lemma exists_lt_of_tendsto_at_top [semilattice_sup α] [preorder β] [no_top_order β]
{u : α → β} (h : tendsto u at_top at_top) (a : α) (b : β) : ∃ a' ≥ a, b < u a' :=
begin
cases no_top b with b' hb',
rcases exists_le_of_tendsto_at_top h a b' with ⟨a', ha', ha''⟩,
exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma exists_lt_of_tendsto_at_bot [semilattice_sup α] [preorder β] [no_bot_order β]
{u : α → β} (h : tendsto u at_top at_bot) : ∀ a b, ∃ a' ≥ a, u a' < b :=
@exists_lt_of_tendsto_at_top _ (order_dual β) _ _ _ _ h
/--
If `u` is a sequence which is unbounded above,
then after any point, it reaches a value strictly greater than all previous values.
-/
lemma high_scores [linear_order β] [no_top_order β] {u : ℕ → β}
(hu : tendsto u at_top at_top) : ∀ N, ∃ n ≥ N, ∀ k < n, u k < u n :=
begin
intros N,
obtain ⟨k : ℕ, hkn : k ≤ N, hku : ∀ l ≤ N, u l ≤ u k⟩ : ∃ k ≤ N, ∀ l ≤ N, u l ≤ u k,
from exists_max_image _ u (finite_le_nat N) ⟨N, le_refl N⟩,
have ex : ∃ n ≥ N, u k < u n,
from exists_lt_of_tendsto_at_top hu _ _,
obtain ⟨n : ℕ, hnN : n ≥ N, hnk : u k < u n, hn_min : ∀ m, m < n → N ≤ m → u m ≤ u k⟩ :
∃ n ≥ N, u k < u n ∧ ∀ m, m < n → N ≤ m → u m ≤ u k,
{ rcases nat.find_x ex with ⟨n, ⟨hnN, hnk⟩, hn_min⟩,
push_neg at hn_min,
exact ⟨n, hnN, hnk, hn_min⟩ },
use [n, hnN],
rintros (l : ℕ) (hl : l < n),
have hlk : u l ≤ u k,
{ cases (le_total l N : l ≤ N ∨ N ≤ l) with H H,
{ exact hku l H },
{ exact hn_min l hl H } },
calc u l ≤ u k : hlk
... < u n : hnk
end
/--
If `u` is a sequence which is unbounded below,
then after any point, it reaches a value strictly smaller than all previous values.
-/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma low_scores [linear_order β] [no_bot_order β] {u : ℕ → β}
(hu : tendsto u at_top at_bot) : ∀ N, ∃ n ≥ N, ∀ k < n, u n < u k :=
@high_scores (order_dual β) _ _ _ hu
/--
If `u` is a sequence which is unbounded above,
then it `frequently` reaches a value strictly greater than all previous values.
-/
lemma frequently_high_scores [linear_order β] [no_top_order β] {u : ℕ → β}
(hu : tendsto u at_top at_top) : ∃ᶠ n in at_top, ∀ k < n, u k < u n :=
by simpa [frequently_at_top] using high_scores hu
/--
If `u` is a sequence which is unbounded below,
then it `frequently` reaches a value strictly smaller than all previous values.
-/
lemma frequently_low_scores [linear_order β] [no_bot_order β] {u : ℕ → β}
(hu : tendsto u at_top at_bot) : ∃ᶠ n in at_top, ∀ k < n, u n < u k :=
@frequently_high_scores (order_dual β) _ _ _ hu
lemma strict_mono_subseq_of_tendsto_at_top
{β : Type*} [linear_order β] [no_top_order β]
{u : ℕ → β} (hu : tendsto u at_top at_top) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) :=
let ⟨φ, h, h'⟩ := extraction_of_frequently_at_top (frequently_high_scores hu) in
⟨φ, h, λ n m hnm, h' m _ (h hnm)⟩
lemma strict_mono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) :=
strict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono hu tendsto_id)
lemma _root_.strict_mono.tendsto_at_top {φ : ℕ → ℕ} (h : strict_mono φ) :
tendsto φ at_top at_top :=
tendsto_at_top_mono h.id_le tendsto_id
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid β] {l : filter α} {f g : α → β}
lemma tendsto_at_top_add_nonneg_left' (hf : ∀ᶠ x in l, 0 ≤ f x) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_mono' l (hf.mono (λ x, le_add_of_nonneg_left)) hg
lemma tendsto_at_bot_add_nonpos_left' (hf : ∀ᶠ x in l, f x ≤ 0) (hg : tendsto g l at_bot) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_nonneg_left' _ (order_dual β) _ _ _ _ hf hg
lemma tendsto_at_top_add_nonneg_left (hf : ∀ x, 0 ≤ f x) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_nonneg_left' (eventually_of_forall hf) hg
lemma tendsto_at_bot_add_nonpos_left (hf : ∀ x, f x ≤ 0) (hg : tendsto g l at_bot) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_nonneg_left _ (order_dual β) _ _ _ _ hf hg
lemma tendsto_at_top_add_nonneg_right' (hf : tendsto f l at_top) (hg : ∀ᶠ x in l, 0 ≤ g x) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_mono' l (monotone_mem (λ x, le_add_of_nonneg_right) hg) hf
lemma tendsto_at_bot_add_nonpos_right' (hf : tendsto f l at_bot) (hg : ∀ᶠ x in l, g x ≤ 0) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_nonneg_right' _ (order_dual β) _ _ _ _ hf hg
lemma tendsto_at_top_add_nonneg_right (hf : tendsto f l at_top) (hg : ∀ x, 0 ≤ g x) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_nonneg_right' hf (eventually_of_forall hg)
lemma tendsto_at_bot_add_nonpos_right (hf : tendsto f l at_bot) (hg : ∀ x, g x ≤ 0) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_nonneg_right _ (order_dual β) _ _ _ _ hf hg
lemma tendsto_at_top_add (hf : tendsto f l at_top) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_nonneg_left' (tendsto_at_top.mp hf 0) hg
lemma tendsto_at_bot_add (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add _ (order_dual β) _ _ _ _ hf hg
lemma tendsto.nsmul_at_top (hf : tendsto f l at_top) {n : ℕ} (hn : 0 < n) :
tendsto (λ x, n • f x) l at_top :=
tendsto_at_top.2 $ λ y, (tendsto_at_top.1 hf y).mp $ (tendsto_at_top.1 hf 0).mono $ λ x h₀ hy,
calc y ≤ f x : hy
... = 1 • f x : (one_nsmul _).symm
... ≤ n • f x : nsmul_le_nsmul h₀ hn
lemma tendsto.nsmul_at_bot (hf : tendsto f l at_bot) {n : ℕ} (hn : 0 < n) :
tendsto (λ x, n • f x) l at_bot :=
@tendsto.nsmul_at_top α (order_dual β) _ l f hf n hn
lemma tendsto_bit0_at_top : tendsto bit0 (at_top : filter β) at_top :=
tendsto_at_top_add tendsto_id tendsto_id
lemma tendsto_bit0_at_bot : tendsto bit0 (at_bot : filter β) at_bot :=
tendsto_at_bot_add tendsto_id tendsto_id
end ordered_add_comm_monoid
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid β] {l : filter α} {f g : α → β}
lemma tendsto_at_top_of_add_const_left (C : β) (hf : tendsto (λ x, C + f x) l at_top) :
tendsto f l at_top :=
tendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (C + b)).mono (λ x, le_of_add_le_add_left)
lemma tendsto_at_bot_of_add_const_left (C : β) (hf : tendsto (λ x, C + f x) l at_bot) :
tendsto f l at_bot :=
@tendsto_at_top_of_add_const_left _ (order_dual β) _ _ _ C hf
lemma tendsto_at_top_of_add_const_right (C : β) (hf : tendsto (λ x, f x + C) l at_top) :
tendsto f l at_top :=
tendsto_at_top.2 $ assume b, (tendsto_at_top.1 hf (b + C)).mono (λ x, le_of_add_le_add_right)
lemma tendsto_at_bot_of_add_const_right (C : β) (hf : tendsto (λ x, f x + C) l at_bot) :
tendsto f l at_bot :=
@tendsto_at_top_of_add_const_right _ (order_dual β) _ _ _ C hf
lemma tendsto_at_top_of_add_bdd_above_left' (C) (hC : ∀ᶠ x in l, f x ≤ C)
(h : tendsto (λ x, f x + g x) l at_top) :
tendsto g l at_top :=
tendsto_at_top_of_add_const_left C
(tendsto_at_top_mono' l (hC.mono (λ x hx, add_le_add_right hx (g x))) h)
lemma tendsto_at_bot_of_add_bdd_below_left' (C) (hC : ∀ᶠ x in l, C ≤ f x)
(h : tendsto (λ x, f x + g x) l at_bot) :
tendsto g l at_bot :=
@tendsto_at_top_of_add_bdd_above_left' _ (order_dual β) _ _ _ _ C hC h
lemma tendsto_at_top_of_add_bdd_above_left (C) (hC : ∀ x, f x ≤ C) :
tendsto (λ x, f x + g x) l at_top → tendsto g l at_top :=
tendsto_at_top_of_add_bdd_above_left' C (univ_mem' hC)
lemma tendsto_at_bot_of_add_bdd_below_left (C) (hC : ∀ x, C ≤ f x) :
tendsto (λ x, f x + g x) l at_bot → tendsto g l at_bot :=
@tendsto_at_top_of_add_bdd_above_left _ (order_dual β) _ _ _ _ C hC
lemma tendsto_at_top_of_add_bdd_above_right' (C) (hC : ∀ᶠ x in l, g x ≤ C)
(h : tendsto (λ x, f x + g x) l at_top) :
tendsto f l at_top :=
tendsto_at_top_of_add_const_right C
(tendsto_at_top_mono' l (hC.mono (λ x hx, add_le_add_left hx (f x))) h)
lemma tendsto_at_bot_of_add_bdd_below_right' (C) (hC : ∀ᶠ x in l, C ≤ g x)
(h : tendsto (λ x, f x + g x) l at_bot) :
tendsto f l at_bot :=
@tendsto_at_top_of_add_bdd_above_right' _ (order_dual β) _ _ _ _ C hC h
lemma tendsto_at_top_of_add_bdd_above_right (C) (hC : ∀ x, g x ≤ C) :
tendsto (λ x, f x + g x) l at_top → tendsto f l at_top :=
tendsto_at_top_of_add_bdd_above_right' C (univ_mem' hC)
lemma tendsto_at_bot_of_add_bdd_below_right (C) (hC : ∀ x, C ≤ g x) :
tendsto (λ x, f x + g x) l at_bot → tendsto f l at_bot :=
@tendsto_at_top_of_add_bdd_above_right _ (order_dual β) _ _ _ _ C hC
end ordered_cancel_add_comm_monoid
section ordered_group
variables [ordered_add_comm_group β] (l : filter α) {f g : α → β}
lemma tendsto_at_top_add_left_of_le' (C : β) (hf : ∀ᶠ x in l, C ≤ f x) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
@tendsto_at_top_of_add_bdd_above_left' _ _ _ l (λ x, -(f x)) (λ x, f x + g x) (-C)
(by simpa) (by simpa)
lemma tendsto_at_bot_add_left_of_ge' (C : β) (hf : ∀ᶠ x in l, f x ≤ C) (hg : tendsto g l at_bot) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_left_of_le' _ (order_dual β) _ _ _ _ C hf hg
lemma tendsto_at_top_add_left_of_le (C : β) (hf : ∀ x, C ≤ f x) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_left_of_le' l C (univ_mem' hf) hg
lemma tendsto_at_bot_add_left_of_ge (C : β) (hf : ∀ x, f x ≤ C) (hg : tendsto g l at_bot) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_left_of_le _ (order_dual β) _ _ _ _ C hf hg
lemma tendsto_at_top_add_right_of_le' (C : β) (hf : tendsto f l at_top) (hg : ∀ᶠ x in l, C ≤ g x) :
tendsto (λ x, f x + g x) l at_top :=
@tendsto_at_top_of_add_bdd_above_right' _ _ _ l (λ x, f x + g x) (λ x, -(g x)) (-C)
(by simp [hg]) (by simp [hf])
lemma tendsto_at_bot_add_right_of_ge' (C : β) (hf : tendsto f l at_bot) (hg : ∀ᶠ x in l, g x ≤ C) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_right_of_le' _ (order_dual β) _ _ _ _ C hf hg
lemma tendsto_at_top_add_right_of_le (C : β) (hf : tendsto f l at_top) (hg : ∀ x, C ≤ g x) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_right_of_le' l C hf (univ_mem' hg)
lemma tendsto_at_bot_add_right_of_ge (C : β) (hf : tendsto f l at_bot) (hg : ∀ x, g x ≤ C) :
tendsto (λ x, f x + g x) l at_bot :=
@tendsto_at_top_add_right_of_le _ (order_dual β) _ _ _ _ C hf hg
lemma tendsto_at_top_add_const_left (C : β) (hf : tendsto f l at_top) :
tendsto (λ x, C + f x) l at_top :=
tendsto_at_top_add_left_of_le' l C (univ_mem' $ λ _, le_refl C) hf
lemma tendsto_at_bot_add_const_left (C : β) (hf : tendsto f l at_bot) :
tendsto (λ x, C + f x) l at_bot :=
@tendsto_at_top_add_const_left _ (order_dual β) _ _ _ C hf
lemma tendsto_at_top_add_const_right (C : β) (hf : tendsto f l at_top) :
tendsto (λ x, f x + C) l at_top :=
tendsto_at_top_add_right_of_le' l C hf (univ_mem' $ λ _, le_refl C)
lemma tendsto_at_bot_add_const_right (C : β) (hf : tendsto f l at_bot) :
tendsto (λ x, f x + C) l at_bot :=
@tendsto_at_top_add_const_right _ (order_dual β) _ _ _ C hf
lemma tendsto_neg_at_top_at_bot : tendsto (has_neg.neg : β → β) at_top at_bot :=
begin
simp only [tendsto_at_bot, neg_le],
exact λ b, eventually_ge_at_top _
end
lemma tendsto_neg_at_bot_at_top : tendsto (has_neg.neg : β → β) at_bot at_top :=
@tendsto_neg_at_top_at_bot (order_dual β) _
end ordered_group
section ordered_semiring
variables [ordered_semiring α] {l : filter β} {f g : β → α}
lemma tendsto_bit1_at_top : tendsto bit1 (at_top : filter α) at_top :=
tendsto_at_top_add_nonneg_right tendsto_bit0_at_top (λ _, zero_le_one)
lemma tendsto.at_top_mul_at_top (hf : tendsto f l at_top) (hg : tendsto g l at_top) :
tendsto (λ x, f x * g x) l at_top :=
begin
refine tendsto_at_top_mono' _ _ hg,
filter_upwards [hg.eventually (eventually_ge_at_top 0), hf.eventually (eventually_ge_at_top 1)],
exact λ x, le_mul_of_one_le_left
end
lemma tendsto_mul_self_at_top : tendsto (λ x : α, x * x) at_top at_top :=
tendsto_id.at_top_mul_at_top tendsto_id
/-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`.
A version for positive real powers exists as `tendsto_rpow_at_top`. -/
lemma tendsto_pow_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ n) at_top at_top :=
begin
refine tendsto_at_top_mono' _ ((eventually_ge_at_top 1).mono $ λ x hx, _) tendsto_id,
simpa only [pow_one] using pow_le_pow hx hn
end
end ordered_semiring
lemma zero_pow_eventually_eq [monoid_with_zero α] :
(λ n : ℕ, (0 : α) ^ n) =ᶠ[at_top] (λ n, 0) :=
eventually_at_top.2 ⟨1, λ n hn, zero_pow (zero_lt_one.trans_le hn)⟩
section ordered_ring
variables [ordered_ring α] {l : filter β} {f g : β → α}
lemma tendsto.at_top_mul_at_bot (hf : tendsto f l at_top) (hg : tendsto g l at_bot) :
tendsto (λ x, f x * g x) l at_bot :=
have _ := (hf.at_top_mul_at_top $ tendsto_neg_at_bot_at_top.comp hg),
by simpa only [(∘), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp this
lemma tendsto.at_bot_mul_at_top (hf : tendsto f l at_bot) (hg : tendsto g l at_top) :
tendsto (λ x, f x * g x) l at_bot :=
have tendsto (λ x, (-f x) * g x) l at_top :=
( (tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top hg),
by simpa only [(∘), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_at_top_at_bot.comp this
lemma tendsto.at_bot_mul_at_bot (hf : tendsto f l at_bot) (hg : tendsto g l at_bot) :
tendsto (λ x, f x * g x) l at_top :=
have tendsto (λ x, (-f x) * (-g x)) l at_top :=
(tendsto_neg_at_bot_at_top.comp hf).at_top_mul_at_top (tendsto_neg_at_bot_at_top.comp hg),
by simpa only [neg_mul_neg] using this
end ordered_ring
section linear_ordered_add_comm_group
variables [linear_ordered_add_comm_group α]
/-- $\lim_{x\to+\infty}|x|=+\infty$ -/
lemma tendsto_abs_at_top_at_top : tendsto (abs : α → α) at_top at_top :=
tendsto_at_top_mono le_abs_self tendsto_id
/-- $\lim_{x\to-\infty}|x|=+\infty$ -/
lemma tendsto_abs_at_bot_at_top : tendsto (abs : α → α) at_bot at_top :=
tendsto_at_top_mono neg_le_abs_self tendsto_neg_at_bot_at_top
end linear_ordered_add_comm_group
section linear_ordered_semiring
variables [linear_ordered_semiring α] {l : filter β} {f : β → α}
lemma tendsto.at_top_of_const_mul {c : α} (hc : 0 < c) (hf : tendsto (λ x, c * f x) l at_top) :
tendsto f l at_top :=
tendsto_at_top.2 $ λ b, (tendsto_at_top.1 hf (c * b)).mono $ λ x hx, le_of_mul_le_mul_left hx hc
lemma tendsto.at_top_of_mul_const {c : α} (hc : 0 < c) (hf : tendsto (λ x, f x * c) l at_top) :
tendsto f l at_top :=
tendsto_at_top.2 $ λ b, (tendsto_at_top.1 hf (b * c)).mono $ λ x hx, le_of_mul_le_mul_right hx hc
end linear_ordered_semiring
lemma nonneg_of_eventually_pow_nonneg [linear_ordered_ring α] {a : α}
(h : ∀ᶠ n in at_top, 0 ≤ a ^ (n : ℕ)) : 0 ≤ a :=
let ⟨n, hn⟩ := (tendsto_bit1_at_top.eventually h).exists in pow_bit1_nonneg_iff.1 hn
section linear_ordered_field
variables [linear_ordered_field α] {l : filter β} {f : β → α} {r : α}
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`filter.tendsto.const_mul_at_top'` instead. -/
lemma tendsto.const_mul_at_top (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, r * f x) l at_top :=
tendsto.at_top_of_const_mul (inv_pos.2 hr) $ by simpa only [inv_mul_cancel_left₀ hr.ne']
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`filter.tendsto.at_top_mul_const'` instead. -/
lemma tendsto.at_top_mul_const (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, f x * r) l at_top :=
by simpa only [mul_comm] using hf.const_mul_at_top hr
/-- If a function tends to infinity along a filter, then this function divided by a positive
constant also tends to infinity. -/
lemma tendsto.at_top_div_const (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, f x / r) l at_top :=
by simpa only [div_eq_mul_inv] using hf.at_top_mul_const (inv_pos.2 hr)
/-- If a function tends to infinity along a filter, then this function multiplied by a negative
constant (on the left) tends to negative infinity. -/
lemma tendsto.neg_const_mul_at_top (hr : r < 0) (hf : tendsto f l at_top) :
tendsto (λ x, r * f x) l at_bot :=
by simpa only [(∘), neg_mul_eq_neg_mul, neg_neg]
using tendsto_neg_at_top_at_bot.comp (hf.const_mul_at_top (neg_pos.2 hr))
/-- If a function tends to infinity along a filter, then this function multiplied by a negative
constant (on the right) tends to negative infinity. -/
lemma tendsto.at_top_mul_neg_const (hr : r < 0) (hf : tendsto f l at_top) :
tendsto (λ x, f x * r) l at_bot :=
by simpa only [mul_comm] using hf.neg_const_mul_at_top hr
/-- If a function tends to negative infinity along a filter, then this function multiplied by
a positive constant (on the left) also tends to negative infinity. -/
lemma tendsto.const_mul_at_bot (hr : 0 < r) (hf : tendsto f l at_bot) :
tendsto (λx, r * f x) l at_bot :=
by simpa only [(∘), neg_mul_eq_mul_neg, neg_neg]
using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).const_mul_at_top hr)
/-- If a function tends to negative infinity along a filter, then this function multiplied by
a positive constant (on the right) also tends to negative infinity. -/
lemma tendsto.at_bot_mul_const (hr : 0 < r) (hf : tendsto f l at_bot) :
tendsto (λx, f x * r) l at_bot :=
by simpa only [mul_comm] using hf.const_mul_at_bot hr
/-- If a function tends to negative infinity along a filter, then this function divided by
a positive constant also tends to negative infinity. -/
lemma tendsto.at_bot_div_const (hr : 0 < r) (hf : tendsto f l at_bot) :
tendsto (λx, f x / r) l at_bot :=
by simpa only [div_eq_mul_inv] using hf.at_bot_mul_const (inv_pos.2 hr)
/-- If a function tends to negative infinity along a filter, then this function multiplied by
a negative constant (on the left) tends to positive infinity. -/
lemma tendsto.neg_const_mul_at_bot (hr : r < 0) (hf : tendsto f l at_bot) :
tendsto (λ x, r * f x) l at_top :=
by simpa only [(∘), neg_mul_eq_neg_mul, neg_neg]
using tendsto_neg_at_bot_at_top.comp (hf.const_mul_at_bot (neg_pos.2 hr))
/-- If a function tends to negative infinity along a filter, then this function multiplied by
a negative constant (on the right) tends to positive infinity. -/
lemma tendsto.at_bot_mul_neg_const (hr : r < 0) (hf : tendsto f l at_bot) :
tendsto (λ x, f x * r) l at_top :=
by simpa only [mul_comm] using hf.neg_const_mul_at_bot hr
lemma tendsto_const_mul_pow_at_top {c : α} {n : ℕ}
(hn : 1 ≤ n) (hc : 0 < c) : tendsto (λ x, c * x^n) at_top at_top :=
tendsto.const_mul_at_top hc (tendsto_pow_at_top hn)
lemma tendsto_const_mul_pow_at_top_iff (c : α) (n : ℕ) :
tendsto (λ x, c * x^n) at_top at_top ↔ 1 ≤ n ∧ 0 < c :=
begin
refine ⟨λ h, _, λ h, tendsto_const_mul_pow_at_top h.1 h.2⟩,
simp only [tendsto_at_top, eventually_at_top] at h,
have : 0 < c := let ⟨x, hx⟩ := h 1 in
pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one (hx (max x 1) (le_max_left x 1)))
(pow_nonneg (le_trans zero_le_one (le_max_right x 1)) n),
refine ⟨nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (λ hn, _))), this⟩,
obtain ⟨x, hx⟩ := h (c + 1),
specialize hx x le_rfl,
rw [hn, pow_zero, mul_one, add_le_iff_nonpos_right] at hx,
exact absurd hx (not_le.mpr zero_lt_one),
end
lemma tendsto_neg_const_mul_pow_at_top {c : α} {n : ℕ}
(hn : 1 ≤ n) (hc : c < 0) : tendsto (λ x, c * x^n) at_top at_bot :=
tendsto.neg_const_mul_at_top hc (tendsto_pow_at_top hn)
lemma tendsto_neg_const_mul_pow_at_top_iff (c : α) (n : ℕ) :
tendsto (λ x, c * x^n) at_top at_bot ↔ 1 ≤ n ∧ c < 0 :=
begin
refine ⟨λ h, _, λ h, tendsto_neg_const_mul_pow_at_top h.1 h.2⟩,
simp only [tendsto_at_bot, eventually_at_top] at h,
have : c < 0 := let ⟨x, hx⟩ := h (-1) in
neg_of_mul_neg_right (lt_of_le_of_lt (hx (max x 1) (le_max_left x 1)) (by simp [zero_lt_one]))
(pow_nonneg (le_trans zero_le_one (le_max_right x 1)) n),
refine ⟨nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (λ hn, _))), this⟩,
obtain ⟨x, hx⟩ := h (c - 1),
specialize hx x le_rfl,
rw [hn, pow_zero, mul_one, le_sub, sub_self] at hx,
exact absurd hx (not_le.mpr zero_lt_one),
end
end linear_ordered_field
open_locale filter
lemma tendsto_at_top' [nonempty α] [semilattice_sup α] {f : α → β} {l : filter β} :
tendsto f at_top l ↔ (∀s ∈ l, ∃a, ∀b≥a, f b ∈ s) :=
by simp only [tendsto_def, mem_at_top_sets]; refl
lemma tendsto_at_bot' [nonempty α] [semilattice_inf α] {f : α → β} {l : filter β} :
tendsto f at_bot l ↔ (∀s ∈ l, ∃a, ∀b≤a, f b ∈ s) :=
@tendsto_at_top' (order_dual α) _ _ _ _ _
theorem tendsto_at_top_principal [nonempty β] [semilattice_sup β] {f : β → α} {s : set α} :
tendsto f at_top (𝓟 s) ↔ ∃N, ∀n≥N, f n ∈ s :=
by rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl
theorem tendsto_at_bot_principal [nonempty β] [semilattice_inf β] {f : β → α} {s : set α} :
tendsto f at_bot (𝓟 s) ↔ ∃N, ∀n≤N, f n ∈ s :=
@tendsto_at_top_principal _ (order_dual β) _ _ _ _
/-- A function `f` grows to `+∞` independent of an order-preserving embedding `e`. -/
lemma tendsto_at_top_at_top [nonempty α] [semilattice_sup α] [preorder β] {f : α → β} :
tendsto f at_top at_top ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a :=
iff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal
lemma tendsto_at_top_at_bot [nonempty α] [semilattice_sup α] [preorder β] {f : α → β} :
tendsto f at_top at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), i ≤ a → f a ≤ b :=
@tendsto_at_top_at_top α (order_dual β) _ _ _ f
lemma tendsto_at_bot_at_top [nonempty α] [semilattice_inf α] [preorder β] {f : α → β} :
tendsto f at_bot at_top ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), a ≤ i → b ≤ f a :=
@tendsto_at_top_at_top (order_dual α) β _ _ _ f
lemma tendsto_at_bot_at_bot [nonempty α] [semilattice_inf α] [preorder β] {f : α → β} :
tendsto f at_bot at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), a ≤ i → f a ≤ b :=
@tendsto_at_top_at_top (order_dual α) (order_dual β) _ _ _ f
lemma tendsto_at_top_at_top_of_monotone [preorder α] [preorder β] {f : α → β} (hf : monotone f)
(h : ∀ b, ∃ a, b ≤ f a) :
tendsto f at_top at_top :=
tendsto_infi.2 $ λ b, tendsto_principal.2 $ let ⟨a, ha⟩ := h b in
mem_of_superset (mem_at_top a) $ λ a' ha', le_trans ha (hf ha')
lemma tendsto_at_bot_at_bot_of_monotone [preorder α] [preorder β] {f : α → β} (hf : monotone f)
(h : ∀ b, ∃ a, f a ≤ b) :
tendsto f at_bot at_bot :=
tendsto_infi.2 $ λ b, tendsto_principal.2 $ let ⟨a, ha⟩ := h b in
mem_of_superset (mem_at_bot a) $ λ a' ha', le_trans (hf ha') ha
lemma tendsto_at_top_at_top_iff_of_monotone [nonempty α] [semilattice_sup α] [preorder β]
{f : α → β} (hf : monotone f) :
tendsto f at_top at_top ↔ ∀ b : β, ∃ a : α, b ≤ f a :=
tendsto_at_top_at_top.trans $ forall_congr $ λ b, exists_congr $ λ a,
⟨λ h, h a (le_refl a), λ h a' ha', le_trans h $ hf ha'⟩
lemma tendsto_at_bot_at_bot_iff_of_monotone [nonempty α] [semilattice_inf α] [preorder β]
{f : α → β} (hf : monotone f) :
tendsto f at_bot at_bot ↔ ∀ b : β, ∃ a : α, f a ≤ b :=
tendsto_at_bot_at_bot.trans $ forall_congr $ λ b, exists_congr $ λ a,
⟨λ h, h a (le_refl a), λ h a' ha', le_trans (hf ha') h⟩
alias tendsto_at_top_at_top_of_monotone ← monotone.tendsto_at_top_at_top
alias tendsto_at_bot_at_bot_of_monotone ← monotone.tendsto_at_bot_at_bot
alias tendsto_at_top_at_top_iff_of_monotone ← monotone.tendsto_at_top_at_top_iff
alias tendsto_at_bot_at_bot_iff_of_monotone ← monotone.tendsto_at_bot_at_bot_iff
lemma tendsto_at_top_embedding [preorder β] [preorder γ]
{f : α → β} {e : β → γ} {l : filter α}
(hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, c ≤ e b) :
tendsto (e ∘ f) l at_top ↔ tendsto f l at_top :=
begin
refine ⟨_, (tendsto_at_top_at_top_of_monotone (λ b₁ b₂, (hm b₁ b₂).2) hu).comp⟩,
rw [tendsto_at_top, tendsto_at_top],
exact λ hc b, (hc (e b)).mono (λ a, (hm b (f a)).1)
end
/-- A function `f` goes to `-∞` independent of an order-preserving embedding `e`. -/
lemma tendsto_at_bot_embedding [preorder β] [preorder γ]
{f : α → β} {e : β → γ} {l : filter α}
(hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, e b ≤ c) :
tendsto (e ∘ f) l at_bot ↔ tendsto f l at_bot :=
@tendsto_at_top_embedding α (order_dual β) (order_dual γ) _ _ f e l (function.swap hm) hu
lemma tendsto_finset_range : tendsto finset.range at_top at_top :=
finset.range_mono.tendsto_at_top_at_top finset.exists_nat_subset_range
lemma at_top_finset_eq_infi : (at_top : filter $ finset α) = ⨅ x : α, 𝓟 (Ici {x}) :=
begin
refine le_antisymm (le_infi (λ i, le_principal_iff.2 $ mem_at_top {i})) _,
refine le_infi (λ s, le_principal_iff.2 $ mem_infi_of_Inter s.finite_to_set
(λ i, mem_principal_self _) _),
simp only [subset_def, mem_Inter, set_coe.forall, mem_Ici, finset.le_iff_subset,
finset.mem_singleton, finset.subset_iff, forall_eq], dsimp,
exact λ t, id
end
/-- If `f` is a monotone sequence of `finset`s and each `x` belongs to one of `f n`, then
`tendsto f at_top at_top`. -/
lemma tendsto_at_top_finset_of_monotone [preorder β]
{f : β → finset α} (h : monotone f) (h' : ∀ x : α, ∃ n, x ∈ f n) :
tendsto f at_top at_top :=
begin
simp only [at_top_finset_eq_infi, tendsto_infi, tendsto_principal],
intro a,
rcases h' a with ⟨b, hb⟩,
exact eventually.mono (mem_at_top b)
(λ b' hb', le_trans (finset.singleton_subset_iff.2 hb) (h hb')),
end
alias tendsto_at_top_finset_of_monotone ← monotone.tendsto_at_top_finset
lemma tendsto_finset_image_at_top_at_top {i : β → γ} {j : γ → β} (h : function.left_inverse j i) :
tendsto (finset.image j) at_top at_top :=
(finset.image_mono j).tendsto_at_top_finset $ assume a,
⟨{i a}, by simp only [finset.image_singleton, h a, finset.mem_singleton]⟩
lemma tendsto_finset_preimage_at_top_at_top {f : α → β} (hf : function.injective f) :
tendsto (λ s : finset β, s.preimage f (hf.inj_on _)) at_top at_top :=
(finset.monotone_preimage hf).tendsto_at_top_finset $
λ x, ⟨{f x}, finset.mem_preimage.2 $ finset.mem_singleton_self _⟩
lemma prod_at_top_at_top_eq {β₁ β₂ : Type*} [semilattice_sup β₁] [semilattice_sup β₂] :
(at_top : filter β₁) ×ᶠ (at_top : filter β₂) = (at_top : filter (β₁ × β₂)) :=
begin
casesI (is_empty_or_nonempty β₁).symm,
casesI (is_empty_or_nonempty β₂).symm,
{ simp [at_top, prod_infi_left, prod_infi_right, infi_prod],
exact infi_comm, },
{ simp only [at_top.filter_eq_bot_of_is_empty, prod_bot] },
{ simp only [at_top.filter_eq_bot_of_is_empty, bot_prod] },
end
lemma prod_at_bot_at_bot_eq {β₁ β₂ : Type*} [semilattice_inf β₁] [semilattice_inf β₂] :
(at_bot : filter β₁) ×ᶠ (at_bot : filter β₂) = (at_bot : filter (β₁ × β₂)) :=
@prod_at_top_at_top_eq (order_dual β₁) (order_dual β₂) _ _
lemma prod_map_at_top_eq {α₁ α₂ β₁ β₂ : Type*} [semilattice_sup β₁] [semilattice_sup β₂]
(u₁ : β₁ → α₁) (u₂ : β₂ → α₂) :
(map u₁ at_top) ×ᶠ (map u₂ at_top) = map (prod.map u₁ u₂) at_top :=
by rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def]
lemma prod_map_at_bot_eq {α₁ α₂ β₁ β₂ : Type*} [semilattice_inf β₁] [semilattice_inf β₂]
(u₁ : β₁ → α₁) (u₂ : β₂ → α₂) :
(map u₁ at_bot) ×ᶠ (map u₂ at_bot) = map (prod.map u₁ u₂) at_bot :=
@prod_map_at_top_eq _ _ (order_dual β₁) (order_dual β₂) _ _ _ _
lemma tendsto.subseq_mem {F : filter α} {V : ℕ → set α} (h : ∀ n, V n ∈ F) {u : ℕ → α}
(hu : tendsto u at_top F) : ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, u (φ n) ∈ V n :=
extraction_forall_of_eventually' (λ n, tendsto_at_top'.mp hu _ (h n) : ∀ n, ∃ N, ∀ k ≥ N, u k ∈ V n)
lemma tendsto_at_bot_diagonal [semilattice_inf α] : tendsto (λ a : α, (a, a)) at_bot at_bot :=
by { rw ← prod_at_bot_at_bot_eq, exact tendsto_id.prod_mk tendsto_id }
lemma tendsto_at_top_diagonal [semilattice_sup α] : tendsto (λ a : α, (a, a)) at_top at_top :=
by { rw ← prod_at_top_at_top_eq, exact tendsto_id.prod_mk tendsto_id }
lemma tendsto.prod_map_prod_at_bot [semilattice_inf γ] {F : filter α} {G : filter β}
{f : α → γ} {g : β → γ} (hf : tendsto f F at_bot) (hg : tendsto g G at_bot) :
tendsto (prod.map f g) (F ×ᶠ G) at_bot :=
by { rw ← prod_at_bot_at_bot_eq, exact hf.prod_map hg, }
lemma tendsto.prod_map_prod_at_top [semilattice_sup γ] {F : filter α} {G : filter β}
{f : α → γ} {g : β → γ} (hf : tendsto f F at_top) (hg : tendsto g G at_top) :
tendsto (prod.map f g) (F ×ᶠ G) at_top :=
by { rw ← prod_at_top_at_top_eq, exact hf.prod_map hg, }
lemma tendsto.prod_at_bot [semilattice_inf α] [semilattice_inf γ]
{f g : α → γ} (hf : tendsto f at_bot at_bot) (hg : tendsto g at_bot at_bot) :
tendsto (prod.map f g) at_bot at_bot :=
by { rw ← prod_at_bot_at_bot_eq, exact hf.prod_map_prod_at_bot hg, }
lemma tendsto.prod_at_top [semilattice_sup α] [semilattice_sup γ]
{f g : α → γ} (hf : tendsto f at_top at_top) (hg : tendsto g at_top at_top) :
tendsto (prod.map f g) at_top at_top :=
by { rw ← prod_at_top_at_top_eq, exact hf.prod_map_prod_at_top hg, }
lemma eventually_at_bot_prod_self [semilattice_inf α] [nonempty α] {p : α × α → Prop} :
(∀ᶠ x in at_bot, p x) ↔ (∃ a, ∀ k l, k ≤ a → l ≤ a → p (k, l)) :=
by simp [← prod_at_bot_at_bot_eq, at_bot_basis.prod_self.eventually_iff]
lemma eventually_at_top_prod_self [semilattice_sup α] [nonempty α] {p : α × α → Prop} :
(∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ k l, a ≤ k → a ≤ l → p (k, l)) :=
by simp [← prod_at_top_at_top_eq, at_top_basis.prod_self.eventually_iff]
lemma eventually_at_bot_prod_self' [semilattice_inf α] [nonempty α] {p : α × α → Prop} :
(∀ᶠ x in at_bot, p x) ↔ (∃ a, ∀ k ≤ a, ∀ l ≤ a, p (k, l)) :=
begin
rw filter.eventually_at_bot_prod_self,
apply exists_congr,
tauto,
end
lemma eventually_at_top_prod_self' [semilattice_sup α] [nonempty α] {p : α × α → Prop} :
(∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ k ≥ a, ∀ l ≥ a, p (k, l)) :=
begin
rw filter.eventually_at_top_prod_self,
apply exists_congr,
tauto,
end
/-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a
Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an
insertion and a connetion above `b'`. -/
lemma map_at_top_eq_of_gc [semilattice_sup α] [semilattice_sup β] {f : α → β} (g : β → α) (b' : β)
(hf : monotone f) (gc : ∀a, ∀b≥b', f a ≤ b ↔ a ≤ g b) (hgi : ∀b≥b', b ≤ f (g b)) :
map f at_top = at_top :=
begin
refine le_antisymm
(hf.tendsto_at_top_at_top $ λ b, ⟨g (b ⊔ b'), le_sup_left.trans $ hgi _ le_sup_right⟩) _,
rw [@map_at_top_eq _ _ ⟨g b'⟩],
refine le_infi (λ a, infi_le_of_le (f a ⊔ b') $ principal_mono.2 $ λ b hb, _),
rw [mem_Ici, sup_le_iff] at hb,
exact ⟨g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 (le_refl _)) (hgi _ hb.2)⟩
end
lemma map_at_bot_eq_of_gc [semilattice_inf α] [semilattice_inf β] {f : α → β} (g : β → α) (b' : β)
(hf : monotone f) (gc : ∀a, ∀b≤b', b ≤ f a ↔ g b ≤ a) (hgi : ∀b≤b', f (g b) ≤ b) :
map f at_bot = at_bot :=
@map_at_top_eq_of_gc (order_dual α) (order_dual β) _ _ _ _ _ hf.dual gc hgi
lemma map_coe_at_top_of_Ici_subset [semilattice_sup α] {a : α} {s : set α} (h : Ici a ⊆ s) :
map (coe : s → α) at_top = at_top :=
begin
have : directed (≥) (λ x : s, 𝓟 (Ici x)),
{ intros x y,
use ⟨x ⊔ y ⊔ a, h le_sup_right⟩,
simp only [ge_iff_le, principal_mono, Ici_subset_Ici, ← subtype.coe_le_coe, subtype.coe_mk],
exact ⟨le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left⟩ },
haveI : nonempty s := ⟨⟨a, h le_rfl⟩⟩,
simp only [le_antisymm_iff, at_top, le_infi_iff, le_principal_iff, mem_map, mem_set_of_eq,
map_infi_eq this, map_principal],
split,
{ intro x,
refine mem_of_superset (mem_infi_of_mem ⟨x ⊔ a, h le_sup_right⟩ (mem_principal_self _)) _,
rintro _ ⟨y, hy, rfl⟩,
exact le_trans le_sup_left (subtype.coe_le_coe.2 hy) },
{ intro x,
filter_upwards [mem_at_top (↑x ⊔ a)],
intros b hb,
exact ⟨⟨b, h $ le_sup_right.trans hb⟩, subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl⟩ }
end
/-- The image of the filter `at_top` on `Ici a` under the coercion equals `at_top`. -/
@[simp] lemma map_coe_Ici_at_top [semilattice_sup α] (a : α) :
map (coe : Ici a → α) at_top = at_top :=
map_coe_at_top_of_Ici_subset (subset.refl _)
/-- The image of the filter `at_top` on `Ioi a` under the coercion equals `at_top`. -/
@[simp] lemma map_coe_Ioi_at_top [semilattice_sup α] [no_top_order α] (a : α) :
map (coe : Ioi a → α) at_top = at_top :=
begin
rcases no_top a with ⟨b, hb⟩,
exact map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb)
end
/-- The `at_top` filter for an open interval `Ioi a` comes from the `at_top` filter in the ambient
order. -/
lemma at_top_Ioi_eq [semilattice_sup α] (a : α) :
at_top = comap (coe : Ioi a → α) at_top :=
begin
nontriviality,
rcases nontrivial_iff_nonempty.1 ‹_› with ⟨b, hb⟩,
rw [← map_coe_at_top_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map subtype.coe_injective]
end
/-- The `at_top` filter for an open interval `Ici a` comes from the `at_top` filter in the ambient
order. -/
lemma at_top_Ici_eq [semilattice_sup α] (a : α) :
at_top = comap (coe : Ici a → α) at_top :=
by rw [← map_coe_Ici_at_top a, comap_map subtype.coe_injective]
/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient
order. -/
@[simp] lemma map_coe_Iio_at_bot [semilattice_inf α] [no_bot_order α] (a : α) :
map (coe : Iio a → α) at_bot = at_bot :=
@map_coe_Ioi_at_top (order_dual α) _ _ _
/-- The `at_bot` filter for an open interval `Iio a` comes from the `at_bot` filter in the ambient
order. -/
lemma at_bot_Iio_eq [semilattice_inf α] (a : α) :
at_bot = comap (coe : Iio a → α) at_bot :=
@at_top_Ioi_eq (order_dual α) _ _
/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient
order. -/
@[simp] lemma map_coe_Iic_at_bot [semilattice_inf α] (a : α) :
map (coe : Iic a → α) at_bot = at_bot :=
@map_coe_Ici_at_top (order_dual α) _ _
/-- The `at_bot` filter for an open interval `Iic a` comes from the `at_bot` filter in the ambient
order. -/
lemma at_bot_Iic_eq [semilattice_inf α] (a : α) :
at_bot = comap (coe : Iic a → α) at_bot :=
@at_top_Ici_eq (order_dual α) _ _
lemma tendsto_Ioi_at_top [semilattice_sup α] {a : α} {f : β → Ioi a}
{l : filter β} :
tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l at_top :=
by rw [at_top_Ioi_eq, tendsto_comap_iff]
lemma tendsto_Iio_at_bot [semilattice_inf α] {a : α} {f : β → Iio a}
{l : filter β} :
tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l at_bot :=
by rw [at_bot_Iio_eq, tendsto_comap_iff]
lemma tendsto_Ici_at_top [semilattice_sup α] {a : α} {f : β → Ici a} {l : filter β} :
tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l at_top :=
by rw [at_top_Ici_eq, tendsto_comap_iff]
lemma tendsto_Iic_at_bot [semilattice_inf α] {a : α} {f : β → Iic a} {l : filter β} :
tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l at_bot :=
by rw [at_bot_Iic_eq, tendsto_comap_iff]
@[simp] lemma tendsto_comp_coe_Ioi_at_top [semilattice_sup α] [no_top_order α] {a : α}
{f : α → β} {l : filter β} :
tendsto (λ x : Ioi a, f x) at_top l ↔ tendsto f at_top l :=
by rw [← map_coe_Ioi_at_top a, tendsto_map'_iff]
@[simp] lemma tendsto_comp_coe_Ici_at_top [semilattice_sup α] {a : α}
{f : α → β} {l : filter β} :
tendsto (λ x : Ici a, f x) at_top l ↔ tendsto f at_top l :=
by rw [← map_coe_Ici_at_top a, tendsto_map'_iff]
@[simp] lemma tendsto_comp_coe_Iio_at_bot [semilattice_inf α] [no_bot_order α] {a : α}
{f : α → β} {l : filter β} :
tendsto (λ x : Iio a, f x) at_bot l ↔ tendsto f at_bot l :=
by rw [← map_coe_Iio_at_bot a, tendsto_map'_iff]
@[simp] lemma tendsto_comp_coe_Iic_at_bot [semilattice_inf α] {a : α}
{f : α → β} {l : filter β} :
tendsto (λ x : Iic a, f x) at_bot l ↔ tendsto f at_bot l :=
by rw [← map_coe_Iic_at_bot a, tendsto_map'_iff]
lemma map_add_at_top_eq_nat (k : ℕ) : map (λa, a + k) at_top = at_top :=
map_at_top_eq_of_gc (λa, a - k) k
(assume a b h, add_le_add_right h k)
(assume a b h, (le_sub_iff_right h).symm)
(assume a h, by rw [nat.sub_add_cancel h])
lemma map_sub_at_top_eq_nat (k : ℕ) : map (λa, a - k) at_top = at_top :=
map_at_top_eq_of_gc (λa, a + k) 0
(assume a b h, nat.sub_le_sub_right h _)
(assume a b _, sub_le_iff_right)
(assume b _, by rw [nat.add_sub_cancel])
lemma tendsto_add_at_top_nat (k : ℕ) : tendsto (λa, a + k) at_top at_top :=
le_of_eq (map_add_at_top_eq_nat k)
lemma tendsto_sub_at_top_nat (k : ℕ) : tendsto (λa, a - k) at_top at_top :=
le_of_eq (map_sub_at_top_eq_nat k)
lemma tendsto_add_at_top_iff_nat {f : ℕ → α} {l : filter α} (k : ℕ) :
tendsto (λn, f (n + k)) at_top l ↔ tendsto f at_top l :=
show tendsto (f ∘ (λn, n + k)) at_top l ↔ tendsto f at_top l,
by rw [← tendsto_map'_iff, map_add_at_top_eq_nat]
lemma map_div_at_top_eq_nat (k : ℕ) (hk : 0 < k) : map (λa, a / k) at_top = at_top :=
map_at_top_eq_of_gc (λb, b * k + (k - 1)) 1
(assume a b h, nat.div_le_div_right h)
(assume a b _,
calc a / k ≤ b ↔ a / k < b + 1 : by rw [← nat.succ_eq_add_one, nat.lt_succ_iff]
... ↔ a < (b + 1) * k : nat.div_lt_iff_lt_mul _ _ hk
... ↔ _ :
begin
cases k,
exact (lt_irrefl _ hk).elim,
rw [add_mul, one_mul, nat.succ_sub_succ_eq_sub,
nat.sub_zero, nat.add_succ, nat.lt_succ_iff],
end)
(assume b _,
calc b = (b * k) / k : by rw [nat.mul_div_cancel b hk]
... ≤ (b * k + (k - 1)) / k : nat.div_le_div_right $ nat.le_add_right _ _)
/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded
above, then `tendsto u at_top at_top`. -/
lemma tendsto_at_top_at_top_of_monotone' [preorder ι] [linear_order α]
{u : ι → α} (h : monotone u) (H : ¬bdd_above (range u)) :
tendsto u at_top at_top :=
begin
apply h.tendsto_at_top_at_top,
intro b,
rcases not_bdd_above_iff.1 H b with ⟨_, ⟨N, rfl⟩, hN⟩,
exact ⟨N, le_of_lt hN⟩,
end
/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded
below, then `tendsto u at_bot at_bot`. -/
lemma tendsto_at_bot_at_bot_of_monotone' [preorder ι] [linear_order α]
{u : ι → α} (h : monotone u) (H : ¬bdd_below (range u)) :
tendsto u at_bot at_bot :=
@tendsto_at_top_at_top_of_monotone' (order_dual ι) (order_dual α) _ _ _ h.dual H
lemma unbounded_of_tendsto_at_top [nonempty α] [semilattice_sup α] [preorder β] [no_top_order β]
{f : α → β} (h : tendsto f at_top at_top) :
¬ bdd_above (range f) :=
begin
rintros ⟨M, hM⟩,
cases mem_at_top_sets.mp (h $ Ioi_mem_at_top M) with a ha,
apply lt_irrefl M,
calc
M < f a : ha a (le_refl _)
... ≤ M : hM (set.mem_range_self a)
end
lemma unbounded_of_tendsto_at_bot [nonempty α] [semilattice_sup α] [preorder β] [no_bot_order β]
{f : α → β} (h : tendsto f at_top at_bot) :
¬ bdd_below (range f) :=
@unbounded_of_tendsto_at_top _ (order_dual β) _ _ _ _ _ h
lemma unbounded_of_tendsto_at_top' [nonempty α] [semilattice_inf α] [preorder β] [no_top_order β]
{f : α → β} (h : tendsto f at_bot at_top) :
¬ bdd_above (range f) :=
@unbounded_of_tendsto_at_top (order_dual α) _ _ _ _ _ _ h
lemma unbounded_of_tendsto_at_bot' [nonempty α] [semilattice_inf α] [preorder β] [no_bot_order β]
{f : α → β} (h : tendsto f at_bot at_bot) :
¬ bdd_below (range f) :=
@unbounded_of_tendsto_at_top (order_dual α) (order_dual β) _ _ _ _ _ h
/-- If a monotone function `u : ι → α` tends to `at_top` along *some* non-trivial filter `l`, then
it tends to `at_top` along `at_top`. -/
lemma tendsto_at_top_of_monotone_of_filter [preorder ι] [preorder α] {l : filter ι}
{u : ι → α} (h : monotone u) [ne_bot l] (hu : tendsto u l at_top) :
tendsto u at_top at_top :=
h.tendsto_at_top_at_top $ λ b, (hu.eventually (mem_at_top b)).exists
/-- If a monotone function `u : ι → α` tends to `at_bot` along *some* non-trivial filter `l`, then
it tends to `at_bot` along `at_bot`. -/
lemma tendsto_at_bot_of_monotone_of_filter [preorder ι] [preorder α] {l : filter ι}
{u : ι → α} (h : monotone u) [ne_bot l] (hu : tendsto u l at_bot) :
tendsto u at_bot at_bot :=
@tendsto_at_top_of_monotone_of_filter (order_dual ι) (order_dual α) _ _ _ _ h.dual _ hu
lemma tendsto_at_top_of_monotone_of_subseq [preorder ι] [preorder α] {u : ι → α}
{φ : ι' → ι} (h : monotone u) {l : filter ι'} [ne_bot l]
(H : tendsto (u ∘ φ) l at_top) :
tendsto u at_top at_top :=
tendsto_at_top_of_monotone_of_filter h (tendsto_map' H)
lemma tendsto_at_bot_of_monotone_of_subseq [preorder ι] [preorder α] {u : ι → α}
{φ : ι' → ι} (h : monotone u) {l : filter ι'} [ne_bot l]
(H : tendsto (u ∘ φ) l at_bot) :
tendsto u at_bot at_bot :=
tendsto_at_bot_of_monotone_of_filter h (tendsto_map' H)
/-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient
condition for comparison of the filter `at_top.map (λ s, ∏ b in s, f b)` with
`at_top.map (λ s, ∏ b in s, g b)`. This is useful to compare the set of limit points of
`Π b in s, f b` as `s → at_top` with the similar set for `g`. -/
@[to_additive]
lemma map_at_top_finset_prod_le_of_prod_eq [comm_monoid α] {f : β → α} {g : γ → α}
(h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∏ x in u', g x = ∏ b in v', f b) :
at_top.map (λs:finset β, ∏ b in s, f b) ≤ at_top.map (λs:finset γ, ∏ x in s, g x) :=
by rw [map_at_top_eq, map_at_top_eq];
from (le_infi $ assume b, let ⟨v, hv⟩ := h_eq b in infi_le_of_le v $
by simp [set.image_subset_iff]; exact hv)
lemma has_antitone_basis.tendsto [semilattice_sup ι] [nonempty ι] {l : filter α}
{p : ι → Prop} {s : ι → set α} (hl : l.has_antitone_basis p s) {φ : ι → α}
(h : ∀ i : ι, φ i ∈ s i) : tendsto φ at_top l :=
(at_top_basis.tendsto_iff hl.to_has_basis).2 $ assume i hi,
⟨i, trivial, λ j hij, hl.decreasing hi (hl.mono hij hi) hij (h j)⟩
namespace is_countably_generated
/-- An abstract version of continuity of sequentially continuous functions on metric spaces:
if a filter `k` is countably generated then `tendsto f k l` iff for every sequence `u`
converging to `k`, `f ∘ u` tends to `l`. -/
lemma tendsto_iff_seq_tendsto {f : α → β} {k : filter α} {l : filter β}
(hcb : k.is_countably_generated) :
tendsto f k l ↔ (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) :=
suffices (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) → tendsto f k l,
from ⟨by intros; apply tendsto.comp; assumption, by assumption⟩,
begin
obtain ⟨g, gbasis, gmon, -⟩ := hcb.exists_antitone_basis,
contrapose,
simp only [not_forall, gbasis.tendsto_left_iff, exists_const, not_exists, not_imp],
rintro ⟨B, hBl, hfBk⟩,
choose x h using hfBk,
use x, split,
{ exact (at_top_basis.tendsto_iff gbasis).2
(λ i _, ⟨i, trivial, λ j hj, gmon trivial trivial hj (h j).1⟩) },
{ simp only [tendsto_at_top', (∘), not_forall, not_exists],
use [B, hBl],
intro i, use [i, (le_refl _)],
apply (h i).right },
end
lemma tendsto_of_seq_tendsto {f : α → β} {k : filter α} {l : filter β}
(hcb : k.is_countably_generated) :
(∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) → tendsto f k l :=
hcb.tendsto_iff_seq_tendsto.2
lemma subseq_tendsto {f : filter α} (hf : is_countably_generated f)
{u : ℕ → α}
(hx : ne_bot (f ⊓ map u at_top)) :
∃ (θ : ℕ → ℕ), (strict_mono θ) ∧ (tendsto (u ∘ θ) at_top f) :=
begin
obtain ⟨B, h⟩ := hf.exists_antitone_basis,
have : ∀ N, ∃ n ≥ N, u n ∈ B N,
from λ N, filter.inf_map_at_top_ne_bot_iff.mp hx _ (h.to_has_basis.mem_of_mem trivial) N,
choose φ hφ using this,
cases forall_and_distrib.mp hφ with φ_ge φ_in,
have lim_uφ : tendsto (u ∘ φ) at_top f,
from h.tendsto φ_in,
have lim_φ : tendsto φ at_top at_top,
from (tendsto_at_top_mono φ_ge tendsto_id),
obtain ⟨ψ, hψ, hψφ⟩ : ∃ ψ : ℕ → ℕ, strict_mono ψ ∧ strict_mono (φ ∘ ψ),
from strict_mono_subseq_of_tendsto_at_top lim_φ,
exact ⟨φ ∘ ψ, hψφ, lim_uφ.comp hψ.tendsto_at_top⟩,
end
end is_countably_generated
end filter
open filter finset
section
variables {R : Type*} [linear_ordered_semiring R]
lemma exists_lt_mul_self (a : R) : ∃ x ≥ 0, a < x * x :=
let ⟨x, hxa, hx0⟩ :=((tendsto_mul_self_at_top.eventually (eventually_gt_at_top a)).and
(eventually_ge_at_top 0)).exists
in ⟨x, hx0, hxa⟩
lemma exists_le_mul_self (a : R) : ∃ x ≥ 0, a ≤ x * x :=
let ⟨x, hx0, hxa⟩ := exists_lt_mul_self a in ⟨x, hx0, hxa.le⟩
end
namespace order_iso
variables [preorder α] [preorder β]
@[simp] lemma comap_at_top (e : α ≃o β) : comap e at_top = at_top :=
by simp [at_top, ← e.surjective.infi_comp]
@[simp] lemma comap_at_bot (e : α ≃o β) : comap e at_bot = at_bot :=
e.dual.comap_at_top
@[simp] lemma map_at_top (e : α ≃o β) : map ⇑e at_top = at_top :=
by rw [← e.comap_at_top, map_comap_of_surjective e.surjective]
@[simp] lemma map_at_bot (e : α ≃o β) : map ⇑e at_bot = at_bot :=
e.dual.map_at_top
lemma tendsto_at_top (e : α ≃o β) : tendsto e at_top at_top :=
e.map_at_top.le
lemma tendsto_at_bot (e : α ≃o β) : tendsto e at_bot at_bot :=
e.map_at_bot.le
@[simp] lemma tendsto_at_top_iff {l : filter γ} {f : γ → α} (e : α ≃o β) :
tendsto (λ x, e (f x)) l at_top ↔ tendsto f l at_top :=
by rw [← e.comap_at_top, tendsto_comap_iff]
@[simp] lemma tendsto_at_bot_iff {l : filter γ} {f : γ → α} (e : α ≃o β) :
tendsto (λ x, e (f x)) l at_bot ↔ tendsto f l at_bot :=
e.dual.tendsto_at_top_iff
end order_iso
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`at_top.map (λ s, ∏ i in s, f (g i))` and `at_top.map (λ s, ∏ i in s, f i)` coincide.
The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
lemma function.injective.map_at_top_finset_prod_eq [comm_monoid α] {g : γ → β}
(hg : function.injective g) {f : β → α} (hf : ∀ x ∉ set.range g, f x = 1) :
map (λ s, ∏ i in s, f (g i)) at_top = map (λ s, ∏ i in s, f i) at_top :=
begin
apply le_antisymm; refine map_at_top_finset_prod_le_of_prod_eq (λ s, _),
{ refine ⟨s.preimage g (hg.inj_on _), λ t ht, _⟩,
refine ⟨t.image g ∪ s, finset.subset_union_right _ _, _⟩,
rw [← finset.prod_image (hg.inj_on _)],
refine (prod_subset (subset_union_left _ _) _).symm,
simp only [finset.mem_union, finset.mem_image],
refine λ y hy hyt, hf y (mt _ hyt),
rintros ⟨x, rfl⟩,
exact ⟨x, ht (finset.mem_preimage.2 $ hy.resolve_left hyt), rfl⟩ },
{ refine ⟨s.image g, λ t ht, _⟩,
simp only [← prod_preimage _ _ (hg.inj_on _) _ (λ x _, hf x)],
exact ⟨_, (image_subset_iff_subset_preimage _).1 ht, rfl⟩ }
end
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to an additive commutative monoid. Suppose that `f x = 0` outside of the range of `g`. Then the
filters `at_top.map (λ s, ∑ i in s, f (g i))` and `at_top.map (λ s, ∑ i in s, f i)` coincide.
This lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
add_decl_doc function.injective.map_at_top_finset_sum_eq
|
640691fcb380216e0be613fe53d759ce8d827e4b | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/nat/cast.lean | 278ac9295dfef59ec099b91a93fbd95ec3b5c566 | [
"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 | 10,582 | lean | /-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Natural homomorphism from the natural numbers into a monoid with one.
-/
import algebra.ordered_field
import data.nat.basic
namespace nat
variables {α : Type*}
section
variables [has_zero α] [has_one α] [has_add α]
/-- Canonical homomorphism from `ℕ` to a type `α` with `0`, `1` and `+`. -/
protected def cast : ℕ → α
| 0 := 0
| (n+1) := cast n + 1
/-- Computationally friendlier cast than `nat.cast`, using binary representation. -/
protected def bin_cast (n : ℕ) : α :=
@nat.binary_rec (λ _, α) 0 (λ odd k a, cond odd (a + a + 1) (a + a)) n
/--
Coercions such as `nat.cast_coe` that go from a concrete structure such as
`ℕ` to an arbitrary ring `α` should be set up as follows:
```lean
@[priority 900] instance : has_coe_t ℕ α := ⟨...⟩
```
It needs to be `has_coe_t` instead of `has_coe` because otherwise type-class
inference would loop when constructing the transitive coercion `ℕ → ℕ → ℕ → ...`.
The reduced priority is necessary so that it doesn't conflict with instances
such as `has_coe_t α (option α)`.
For this to work, we reduce the priority of the `coe_base` and `coe_trans`
instances because we want the instances for `has_coe_t` to be tried in the
following order:
1. `has_coe_t` instances declared in mathlib (such as `has_coe_t α (with_top α)`, etc.)
2. `coe_base`, which contains instances such as `has_coe (fin n) n`
3. `nat.cast_coe : has_coe_t ℕ α` etc.
4. `coe_trans`
If `coe_trans` is tried first, then `nat.cast_coe` doesn't get a chance to apply.
-/
library_note "coercion into rings"
attribute [instance, priority 950] coe_base
attribute [instance, priority 500] coe_trans
-- see note [coercion into rings]
@[priority 900] instance cast_coe : has_coe_t ℕ α := ⟨nat.cast⟩
@[simp, norm_cast] theorem cast_zero : ((0 : ℕ) : α) = 0 := rfl
theorem cast_add_one (n : ℕ) : ((n + 1 : ℕ) : α) = n + 1 := rfl
@[simp, norm_cast, priority 500]
theorem cast_succ (n : ℕ) : ((succ n : ℕ) : α) = n + 1 := rfl
@[simp, norm_cast] theorem cast_ite (P : Prop) [decidable P] (m n : ℕ) :
(((ite P m n) : ℕ) : α) = ite P (m : α) (n : α) :=
by { split_ifs; refl, }
end
@[simp, norm_cast] theorem cast_one [add_monoid α] [has_one α] : ((1 : ℕ) : α) = 1 := zero_add _
@[simp, norm_cast] theorem cast_add [add_monoid α] [has_one α] (m) : ∀ n, ((m + n : ℕ) : α) = m + n
| 0 := (add_zero _).symm
| (n+1) := show ((m + n : ℕ) : α) + 1 = m + (n + 1), by rw [cast_add n, add_assoc]
@[simp] lemma bin_cast_eq [add_monoid α] [has_one α] (n : ℕ) :
(nat.bin_cast n : α) = ((n : ℕ) : α) :=
begin
rw nat.bin_cast,
apply binary_rec _ _ n,
{ rw [binary_rec_zero, cast_zero] },
{ intros b k h,
rw [binary_rec_eq, h],
{ cases b; simp [bit, bit0, bit1] },
{ simp } },
end
/-- `coe : ℕ → α` as an `add_monoid_hom`. -/
def cast_add_monoid_hom (α : Type*) [add_monoid α] [has_one α] : ℕ →+ α :=
{ to_fun := coe,
map_add' := cast_add,
map_zero' := cast_zero }
@[simp] lemma coe_cast_add_monoid_hom [add_monoid α] [has_one α] :
(cast_add_monoid_hom α : ℕ → α) = coe := rfl
@[simp, norm_cast] theorem cast_bit0 [add_monoid α] [has_one α] (n : ℕ) :
((bit0 n : ℕ) : α) = bit0 n := cast_add _ _
@[simp, norm_cast] theorem cast_bit1 [add_monoid α] [has_one α] (n : ℕ) :
((bit1 n : ℕ) : α) = bit1 n :=
by rw [bit1, cast_add_one, cast_bit0]; refl
lemma cast_two {α : Type*} [add_monoid α] [has_one α] : ((2 : ℕ) : α) = 2 := by simp
@[simp, norm_cast] theorem cast_pred [add_group α] [has_one α] :
∀ {n}, 0 < n → ((n - 1 : ℕ) : α) = n - 1
| (n+1) h := (add_sub_cancel (n:α) 1).symm
@[simp, norm_cast] theorem cast_sub [add_group α] [has_one α] {m n} (h : m ≤ n) :
((n - m : ℕ) : α) = n - m :=
eq_sub_of_add_eq $ by rw [← cast_add, nat.sub_add_cancel h]
@[simp, norm_cast] theorem cast_mul [semiring α] (m) : ∀ n, ((m * n : ℕ) : α) = m * n
| 0 := (mul_zero _).symm
| (n+1) := (cast_add _ _).trans $
show ((m * n : ℕ) : α) + m = m * (n + 1), by rw [cast_mul n, left_distrib, mul_one]
@[simp] theorem cast_dvd {α : Type*} [field α] {m n : ℕ} (n_dvd : n ∣ m) (n_nonzero : (n:α) ≠ 0) :
((m / n : ℕ) : α) = m / n :=
begin
rcases n_dvd with ⟨k, rfl⟩,
have : n ≠ 0, {rintro rfl, simpa using n_nonzero},
rw nat.mul_div_cancel_left _ (pos_iff_ne_zero.2 this),
rw [nat.cast_mul, mul_div_cancel_left _ n_nonzero],
end
/-- `coe : ℕ → α` as a `ring_hom` -/
def cast_ring_hom (α : Type*) [semiring α] : ℕ →+* α :=
{ to_fun := coe,
map_one' := cast_one,
map_mul' := cast_mul,
.. cast_add_monoid_hom α }
@[simp] lemma coe_cast_ring_hom [semiring α] : (cast_ring_hom α : ℕ → α) = coe := rfl
lemma cast_commute [semiring α] (n : ℕ) (x : α) : commute ↑n x :=
nat.rec_on n (commute.zero_left x) $ λ n ihn, ihn.add_left $ commute.one_left x
lemma cast_comm [semiring α] (n : ℕ) (x : α) : (n : α) * x = x * n :=
(cast_commute n x).eq
lemma commute_cast [semiring α] (x : α) (n : ℕ) : commute x n :=
(n.cast_commute x).symm
section
variables [ordered_semiring α]
@[simp] theorem cast_nonneg : ∀ n : ℕ, 0 ≤ (n : α)
| 0 := le_refl _
| (n+1) := add_nonneg (cast_nonneg n) zero_le_one
theorem mono_cast : monotone (coe : ℕ → α) :=
λ m n h, let ⟨k, hk⟩ := le_iff_exists_add.1 h in by simp [hk]
variable [nontrivial α]
theorem strict_mono_cast : strict_mono (coe : ℕ → α) :=
λ m n h, nat.le_induction (lt_add_of_pos_right _ zero_lt_one)
(λ n _ h, lt_add_of_lt_of_pos h zero_lt_one) _ h
@[simp, norm_cast] theorem cast_le {m n : ℕ} :
(m : α) ≤ n ↔ m ≤ n :=
strict_mono_cast.le_iff_le
@[simp, norm_cast] theorem cast_lt {m n : ℕ} : (m : α) < n ↔ m < n :=
strict_mono_cast.lt_iff_lt
@[simp] theorem cast_pos {n : ℕ} : (0 : α) < n ↔ 0 < n :=
by rw [← cast_zero, cast_lt]
lemma cast_add_one_pos (n : ℕ) : 0 < (n : α) + 1 :=
add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one
@[simp, norm_cast] theorem one_lt_cast {n : ℕ} : 1 < (n : α) ↔ 1 < n :=
by rw [← cast_one, cast_lt]
@[simp, norm_cast] theorem one_le_cast {n : ℕ} : 1 ≤ (n : α) ↔ 1 ≤ n :=
by rw [← cast_one, cast_le]
@[simp, norm_cast] theorem cast_lt_one {n : ℕ} : (n : α) < 1 ↔ n = 0 :=
by rw [← cast_one, cast_lt, lt_succ_iff, le_zero_iff]
@[simp, norm_cast] theorem cast_le_one {n : ℕ} : (n : α) ≤ 1 ↔ n ≤ 1 :=
by rw [← cast_one, cast_le]
end
@[simp, norm_cast] theorem cast_min [linear_ordered_semiring α] {a b : ℕ} :
(↑(min a b) : α) = min a b :=
by by_cases a ≤ b; simp [h, min]
@[simp, norm_cast] theorem cast_max [linear_ordered_semiring α] {a b : ℕ} :
(↑(max a b) : α) = max a b :=
by by_cases a ≤ b; simp [h, max]
@[simp, norm_cast] theorem abs_cast [linear_ordered_ring α] (a : ℕ) :
abs (a : α) = a :=
abs_of_nonneg (cast_nonneg a)
lemma coe_nat_dvd [comm_semiring α] {m n : ℕ} (h : m ∣ n) :
(m : α) ∣ (n : α) :=
ring_hom.map_dvd (nat.cast_ring_hom α) h
alias coe_nat_dvd ← has_dvd.dvd.nat_cast
section linear_ordered_field
variables [linear_ordered_field α]
lemma inv_pos_of_nat {n : ℕ} : 0 < ((n : α) + 1)⁻¹ :=
inv_pos.2 $ add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one
lemma one_div_pos_of_nat {n : ℕ} : 0 < 1 / ((n : α) + 1) :=
by { rw one_div, exact inv_pos_of_nat }
lemma one_div_le_one_div {n m : ℕ} (h : n ≤ m) : 1 / ((m : α) + 1) ≤ 1 / ((n : α) + 1) :=
by { refine one_div_le_one_div_of_le _ _, exact nat.cast_add_one_pos _, simpa }
lemma one_div_lt_one_div {n m : ℕ} (h : n < m) : 1 / ((m : α) + 1) < 1 / ((n : α) + 1) :=
by { refine one_div_lt_one_div_of_lt _ _, exact nat.cast_add_one_pos _, simpa }
end linear_ordered_field
end nat
namespace add_monoid_hom
variables {A B : Type*} [add_monoid A]
@[ext] lemma ext_nat {f g : ℕ →+ A} (h : f 1 = g 1) : f = g :=
ext $ λ n, nat.rec_on n (f.map_zero.trans g.map_zero.symm) $ λ n ihn,
by simp only [nat.succ_eq_add_one, *, map_add]
variables [has_one A] [add_monoid B] [has_one B]
lemma eq_nat_cast (f : ℕ →+ A) (h1 : f 1 = 1) :
∀ n : ℕ, f n = n :=
congr_fun $ show f = nat.cast_add_monoid_hom A, from ext_nat (h1.trans nat.cast_one.symm)
lemma map_nat_cast (f : A →+ B) (h1 : f 1 = 1) (n : ℕ) : f n = n :=
(f.comp (nat.cast_add_monoid_hom A)).eq_nat_cast (by simp [h1]) _
end add_monoid_hom
namespace ring_hom
variables {R : Type*} {S : Type*} [semiring R] [semiring S]
@[simp] lemma eq_nat_cast (f : ℕ →+* R) (n : ℕ) : f n = n :=
f.to_add_monoid_hom.eq_nat_cast f.map_one n
@[simp] lemma map_nat_cast (f : R →+* S) (n : ℕ) :
f n = n :=
(f.comp (nat.cast_ring_hom R)).eq_nat_cast n
lemma ext_nat (f g : ℕ →+* R) : f = g :=
coe_add_monoid_hom_injective $ add_monoid_hom.ext_nat $ f.map_one.trans g.map_one.symm
end ring_hom
@[simp, norm_cast] theorem nat.cast_id (n : ℕ) : ↑n = n :=
((ring_hom.id ℕ).eq_nat_cast n).symm
@[simp] theorem nat.cast_with_bot : ∀ (n : ℕ),
@coe ℕ (with_bot ℕ) (@coe_to_lift _ _ nat.cast_coe) n = n
| 0 := rfl
| (n+1) := by rw [with_bot.coe_add, nat.cast_add, nat.cast_with_bot n]; refl
instance nat.subsingleton_ring_hom {R : Type*} [semiring R] : subsingleton (ℕ →+* R) :=
⟨ring_hom.ext_nat⟩
namespace with_top
variables {α : Type*}
variables [has_zero α] [has_one α] [has_add α]
@[simp, norm_cast] lemma coe_nat : ∀(n : nat), ((n : α) : with_top α) = n
| 0 := rfl
| (n+1) := by { push_cast, rw [coe_nat n] }
@[simp] lemma nat_ne_top (n : nat) : (n : with_top α) ≠ ⊤ :=
by { rw [←coe_nat n], apply coe_ne_top }
@[simp] lemma top_ne_nat (n : nat) : (⊤ : with_top α) ≠ n :=
by { rw [←coe_nat n], apply top_ne_coe }
lemma add_one_le_of_lt {i n : with_top ℕ} (h : i < n) : i + 1 ≤ n :=
begin
cases n, { exact le_top },
cases i, { exact (not_le_of_lt h le_top).elim },
exact with_top.coe_le_coe.2 (with_top.coe_lt_coe.1 h)
end
lemma one_le_iff_pos {n : with_top ℕ} : 1 ≤ n ↔ 0 < n :=
⟨λ h, (coe_lt_coe.2 zero_lt_one).trans_le h,
λ h, by simpa only [zero_add] using add_one_le_of_lt h⟩
@[elab_as_eliminator]
lemma nat_induction {P : with_top ℕ → Prop} (a : with_top ℕ)
(h0 : P 0) (hsuc : ∀n:ℕ, P n → P n.succ) (htop : (∀n : ℕ, P n) → P ⊤) : P a :=
begin
have A : ∀n:ℕ, P n := λ n, nat.rec_on n h0 hsuc,
cases a,
{ exact htop A },
{ exact A a }
end
end with_top
|
18fd6c549d4d65582bcc87536d363aa513c8aea1 | c8af905dcd8475f414868d303b2eb0e9d3eb32f9 | /src/algebra/half_ring.lean | fee44653d97d19f1d68c697d300947bf4924ff84 | [
"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 | 453 | lean | import algebra.ring
universe u
/-- Some comm_ring which has a constant "half", where two halves add to 1. -/
class half_ring (α : Type u) extends comm_ring α :=
(half : α)
(one_is_two_halves : 1 = half + half)
@[priority 100]
instance linear_ordered_field.to_half_ring (α : Type u) [linear_ordered_field α] : half_ring α :=
{ half := (1 : α) / 2,
one_is_two_halves := symm (add_halves 1) }
notation `½` := half_ring.half _
#lint-
|
82e2996d90f0e7c23111bc324a05206f78e3df5d | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/data/set/lattice.lean | 55f9de4ba217a3bdc92038830fae8374334a87e0 | [
"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 | 35,406 | 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, Johannes Hölzl, Mario Carneiro
-- QUESTION: can make the first argument in ∀ x ∈ a, ... implicit?
-/
import logic.basic data.set.basic data.equiv.basic
import order.complete_boolean_algebra category.basic
import tactic.finish data.sigma.basic order.galois_connection
open function tactic set lattice auto
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
namespace set
instance lattice_set : complete_lattice (set α) :=
{ lattice.complete_lattice .
le := (⊆),
le_refl := subset.refl,
le_trans := assume a b c, subset.trans,
le_antisymm := assume a b, subset.antisymm,
lt := λ x y, x ⊆ y ∧ ¬ y ⊆ x,
lt_iff_le_not_le := λ x y, iff.rfl,
sup := (∪),
le_sup_left := subset_union_left,
le_sup_right := subset_union_right,
sup_le := assume a b c, union_subset,
inf := (∩),
inf_le_left := inter_subset_left,
inf_le_right := inter_subset_right,
le_inf := assume a b c, subset_inter,
top := {a | true },
le_top := assume s a h, trivial,
bot := ∅,
bot_le := assume s a, false.elim,
Sup := λs, {a | ∃ t ∈ s, a ∈ t },
le_Sup := assume s t t_in a a_in, ⟨t, ⟨t_in, a_in⟩⟩,
Sup_le := assume s t h a ⟨t', ⟨t'_in, a_in⟩⟩, h t' t'_in a_in,
Inf := λs, {a | ∀ t ∈ s, a ∈ t },
le_Inf := assume s t h a a_in t' t'_in, h t' t'_in a_in,
Inf_le := assume s t t_in a h, h _ t_in }
instance : distrib_lattice (set α) :=
{ le_sup_inf := λ s t u x, or_and_distrib_left.2, ..set.lattice_set }
lemma monotone_image {f : α → β} : monotone (image f) :=
assume s t, assume h : s ⊆ t, image_subset _ h
theorem monotone_inter [preorder β] {f g : β → set α}
(hf : monotone f) (hg : monotone g) : monotone (λx, f x ∩ g x) :=
assume b₁ b₂ h, inter_subset_inter (hf h) (hg h)
theorem monotone_union [preorder β] {f g : β → set α}
(hf : monotone f) (hg : monotone g) : monotone (λx, f x ∪ g x) :=
assume b₁ b₂ h, union_subset_union (hf h) (hg h)
theorem monotone_set_of [preorder α] {p : α → β → Prop}
(hp : ∀b, monotone (λa, p a b)) : monotone (λa, {b | p a b}) :=
assume a a' h b, hp b h
section galois_connection
variables {f : α → β}
protected lemma image_preimage : galois_connection (image f) (preimage f) :=
assume a b, image_subset_iff
def kern_image (f : α → β) (s : set α) : set β := {y | ∀x, f x = y → x ∈ s}
protected lemma preimage_kern_image : galois_connection (preimage f) (kern_image f) :=
assume a b,
⟨ assume h x hx y hy, have f y ∈ a, from hy.symm ▸ hx, h this,
assume h x (hx : f x ∈ a), h hx x rfl⟩
end galois_connection
/- union and intersection over a family of sets indexed by a type -/
/-- Indexed union of a family of sets -/
@[reducible] def Union (s : ι → set β) : set β := supr s
/-- Indexed intersection of a family of sets -/
@[reducible] def Inter (s : ι → set β) : set β := infi s
notation `⋃` binders `, ` r:(scoped f, Union f) := r
notation `⋂` binders `, ` r:(scoped f, Inter f) := r
@[simp] theorem mem_Union {x : β} {s : ι → set β} : x ∈ Union s ↔ ∃ i, x ∈ s i :=
⟨assume ⟨t, ⟨⟨a, (t_eq : s a = t)⟩, (h : x ∈ t)⟩⟩, ⟨a, t_eq.symm ▸ h⟩,
assume ⟨a, h⟩, ⟨s a, ⟨⟨a, rfl⟩, h⟩⟩⟩
/- alternative proof: dsimp [Union, supr, Sup]; simp -/
-- TODO: more rewrite rules wrt forall / existentials and logical connectives
-- TODO: also eliminate ∃i, ... ∧ i = t ∧ ...
@[simp] theorem mem_Inter {x : β} {s : ι → set β} : x ∈ Inter s ↔ ∀ i, x ∈ s i :=
⟨assume (h : ∀a ∈ {a : set β | ∃i, s i = a}, x ∈ a) a, h (s a) ⟨a, rfl⟩,
assume h t ⟨a, (eq : s a = t)⟩, eq ▸ h a⟩
theorem Union_subset {s : ι → set β} {t : set β} (h : ∀ i, s i ⊆ t) : (⋃ i, s i) ⊆ t :=
-- TODO: should be simpler when sets' order is based on lattices
@supr_le (set β) _ set.lattice_set _ _ h
theorem Union_subset_iff {α : Sort u} {s : α → set β} {t : set β} : (⋃ i, s i) ⊆ t ↔ (∀ i, s i ⊆ t) :=
⟨assume h i, subset.trans (le_supr s _) h, Union_subset⟩
theorem mem_Inter_of_mem {α : Sort u} {x : β} {s : α → set β} : (∀ i, x ∈ s i) → (x ∈ ⋂ i, s i) :=
mem_Inter.2
theorem subset_Inter {t : set β} {s : α → set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i :=
-- TODO: should be simpler when sets' order is based on lattices
@le_infi (set β) _ set.lattice_set _ _ h
theorem subset_Union : ∀ (s : ι → set β) (i : ι), s i ⊆ (⋃ i, s i) := le_supr
theorem Inter_subset : ∀ (s : ι → set β) (i : ι), (⋂ i, s i) ⊆ s i := infi_le
theorem Union_const [inhabited ι] (s : set β) : (⋃ i:ι, s) = s :=
ext $ by simp
theorem Inter_const [inhabited ι] (s : set β) : (⋂ i:ι, s) = s :=
ext $ by simp
@[simp] -- complete_boolean_algebra
theorem compl_Union (s : ι → set β) : - (⋃ i, s i) = (⋂ i, - s i) :=
ext (by simp)
-- classical -- complete_boolean_algebra
theorem compl_Inter (s : ι → set β) : -(⋂ i, s i) = (⋃ i, - s i) :=
ext (λ x, by simp [classical.not_forall])
-- classical -- complete_boolean_algebra
theorem Union_eq_comp_Inter_comp (s : ι → set β) : (⋃ i, s i) = - (⋂ i, - s i) :=
by simp [compl_Inter, compl_compl]
-- classical -- complete_boolean_algebra
theorem Inter_eq_comp_Union_comp (s : ι → set β) : (⋂ i, s i) = - (⋃ i, -s i) :=
by simp [compl_compl]
theorem inter_Union (s : set β) (t : ι → set β) :
s ∩ (⋃ i, t i) = ⋃ i, s ∩ t i :=
ext $ by simp
theorem Union_inter (s : set β) (t : ι → set β) :
(⋃ i, t i) ∩ s = ⋃ i, t i ∩ s :=
ext $ by simp
theorem Union_union_distrib (s : ι → set β) (t : ι → set β) :
(⋃ i, s i ∪ t i) = (⋃ i, s i) ∪ (⋃ i, t i) :=
ext $ by simp [exists_or_distrib]
theorem Inter_inter_distrib (s : ι → set β) (t : ι → set β) :
(⋂ i, s i ∩ t i) = (⋂ i, s i) ∩ (⋂ i, t i) :=
ext $ by simp [forall_and_distrib]
theorem union_Union [inhabited ι] (s : set β) (t : ι → set β) :
s ∪ (⋃ i, t i) = ⋃ i, s ∪ t i :=
by rw [Union_union_distrib, Union_const]
theorem Union_union [inhabited ι] (s : set β) (t : ι → set β) :
(⋃ i, t i) ∪ s = ⋃ i, t i ∪ s :=
by rw [Union_union_distrib, Union_const]
theorem inter_Inter [inhabited ι] (s : set β) (t : ι → set β) :
s ∩ (⋂ i, t i) = ⋂ i, s ∩ t i :=
by rw [Inter_inter_distrib, Inter_const]
theorem Inter_inter [inhabited ι] (s : set β) (t : ι → set β) :
(⋂ i, t i) ∩ s = ⋂ i, t i ∩ s :=
by rw [Inter_inter_distrib, Inter_const]
-- classical
theorem union_Inter (s : set β) (t : ι → set β) :
s ∪ (⋂ i, t i) = ⋂ i, s ∪ t i :=
ext $ assume x, by simp [classical.forall_or_distrib_left]
theorem Union_diff (s : set β) (t : ι → set β) :
(⋃ i, t i) \ s = ⋃ i, t i \ s :=
Union_inter _ _
theorem diff_Union [inhabited ι] (s : set β) (t : ι → set β) :
s \ (⋃ i, t i) = ⋂ i, s \ t i :=
by rw [diff_eq, compl_Union, inter_Inter]; refl
theorem diff_Inter (s : set β) (t : ι → set β) :
s \ (⋂ i, t i) = ⋃ i, s \ t i :=
by rw [diff_eq, compl_Inter, inter_Union]; refl
/- bounded unions and intersections -/
theorem mem_bUnion_iff {s : set α} {t : α → set β} {y : β} :
y ∈ (⋃ x ∈ s, t x) ↔ ∃ x, x ∈ s ∧ y ∈ t x := by simp
theorem mem_bInter_iff {s : set α} {t : α → set β} {y : β} :
y ∈ (⋂ x ∈ s, t x) ↔ ∀ x ∈ s, y ∈ t x := by simp
theorem mem_bUnion {s : set α} {t : α → set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) :
y ∈ ⋃ x ∈ s, t x :=
by simp; exact ⟨x, ⟨xs, ytx⟩⟩
theorem mem_bInter {s : set α} {t : α → set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) :
y ∈ ⋂ x ∈ s, t x :=
by simp; assumption
theorem bUnion_subset {s : set α} {t : set β} {u : α → set β} (h : ∀ x ∈ s, u x ⊆ t) :
(⋃ x ∈ s, u x) ⊆ t :=
show (⨆ x ∈ s, u x) ≤ t, -- TODO: should not be necessary when sets' order is based on lattices
from supr_le $ assume x, supr_le (h x)
theorem subset_bInter {s : set α} {t : set β} {u : α → set β} (h : ∀ x ∈ s, t ⊆ u x) :
t ⊆ (⋂ x ∈ s, u x) :=
show t ≤ (⨅ x ∈ s, u x), -- TODO: should not be necessary when sets' order is based on lattices
from le_infi $ assume x, le_infi (h x)
theorem subset_bUnion_of_mem {s : set α} {u : α → set β} {x : α} (xs : x ∈ s) :
u x ⊆ (⋃ x ∈ s, u x) :=
show u x ≤ (⨆ x ∈ s, u x),
from le_supr_of_le x $ le_supr _ xs
theorem bInter_subset_of_mem {s : set α} {t : α → set β} {x : α} (xs : x ∈ s) :
(⋂ x ∈ s, t x) ⊆ t x :=
show (⨅x ∈ s, t x) ≤ t x,
from infi_le_of_le x $ infi_le _ xs
theorem bUnion_subset_bUnion_left {s s' : set α} {t : α → set β}
(h : s ⊆ s') : (⋃ x ∈ s, t x) ⊆ (⋃ x ∈ s', t x) :=
bUnion_subset (λ x xs, subset_bUnion_of_mem (h xs))
theorem bInter_subset_bInter_left {s s' : set α} {t : α → set β}
(h : s' ⊆ s) : (⋂ x ∈ s, t x) ⊆ (⋂ x ∈ s', t x) :=
subset_bInter (λ x xs, bInter_subset_of_mem (h xs))
theorem bUnion_subset_bUnion_right {s : set α} {t1 t2 : α → set β}
(h : ∀ x ∈ s, t1 x ⊆ t2 x) : (⋃ x ∈ s, t1 x) ⊆ (⋃ x ∈ s, t2 x) :=
bUnion_subset (λ x xs, subset.trans (h x xs) (subset_bUnion_of_mem xs))
theorem bInter_subset_bInter_right {s : set α} {t1 t2 : α → set β}
(h : ∀ x ∈ s, t1 x ⊆ t2 x) : (⋂ x ∈ s, t1 x) ⊆ (⋂ x ∈ s, t2 x) :=
subset_bInter (λ x xs, subset.trans (bInter_subset_of_mem xs) (h x xs))
theorem bUnion_eq_Union (s : set α) (t : α → set β) : (⋃ x ∈ s, t x) = (⋃ x : s, t x.1) :=
set.ext $ by simp
theorem bInter_eq_Inter (s : set α) (t : α → set β) : (⋂ x ∈ s, t x) = (⋂ x : s, t x.1) :=
set.ext $ by simp
@[simp] theorem bInter_empty (u : α → set β) : (⋂ x ∈ (∅ : set α), u x) = univ :=
show (⨅x ∈ (∅ : set α), u x) = ⊤, -- simplifier should be able to rewrite x ∈ ∅ to false.
from infi_emptyset
@[simp] theorem bInter_univ (u : α → set β) : (⋂ x ∈ @univ α, u x) = ⋂ x, u x :=
infi_univ
-- TODO(Jeremy): here is an artifact of the the encoding of bounded intersection:
-- without dsimp, the next theorem fails to type check, because there is a lambda
-- in a type that needs to be contracted. Using simp [eq_of_mem_singleton xa] also works.
@[simp] theorem bInter_singleton (a : α) (s : α → set β) : (⋂ x ∈ ({a} : set α), s x) = s a :=
show (⨅ x ∈ ({a} : set α), s x) = s a, by simp
theorem bInter_union (s t : set α) (u : α → set β) :
(⋂ x ∈ s ∪ t, u x) = (⋂ x ∈ s, u x) ∩ (⋂ x ∈ t, u x) :=
show (⨅ x ∈ s ∪ t, u x) = (⨅ x ∈ s, u x) ⊓ (⨅ x ∈ t, u x),
from infi_union
-- TODO(Jeremy): simp [insert_eq, bInter_union] doesn't work
@[simp] theorem bInter_insert (a : α) (s : set α) (t : α → set β) :
(⋂ x ∈ insert a s, t x) = t a ∩ (⋂ x ∈ s, t x) :=
begin rw insert_eq, simp [bInter_union] end
-- TODO(Jeremy): another example of where an annotation is needed
theorem bInter_pair (a b : α) (s : α → set β) :
(⋂ x ∈ ({a, b} : set α), s x) = s a ∩ s b :=
by rw insert_of_has_insert; simp [inter_comm]
@[simp] theorem bUnion_empty (s : α → set β) : (⋃ x ∈ (∅ : set α), s x) = ∅ :=
supr_emptyset
@[simp] theorem bUnion_univ (s : α → set β) : (⋃ x ∈ @univ α, s x) = ⋃ x, s x :=
supr_univ
@[simp] theorem bUnion_singleton (a : α) (s : α → set β) : (⋃ x ∈ ({a} : set α), s x) = s a :=
supr_singleton
@[simp] theorem bUnion_of_singleton (s : set α) : (⋃ x ∈ s, {x}) = s :=
ext $ by simp
theorem bUnion_union (s t : set α) (u : α → set β) :
(⋃ x ∈ s ∪ t, u x) = (⋃ x ∈ s, u x) ∪ (⋃ x ∈ t, u x) :=
supr_union
-- TODO(Jeremy): once again, simp doesn't do it alone.
@[simp] theorem bUnion_insert (a : α) (s : set α) (t : α → set β) :
(⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) :=
begin rw [insert_eq], simp [bUnion_union] end
theorem bUnion_pair (a b : α) (s : α → set β) :
(⋃ x ∈ ({a, b} : set α), s x) = s a ∪ s b :=
by rw insert_of_has_insert; simp [union_comm]
@[simp] -- complete_boolean_algebra
theorem compl_bUnion (s : set α) (t : α → set β) : - (⋃ i ∈ s, t i) = (⋂ i ∈ s, - t i) :=
ext (λ x, by simp)
-- classical -- complete_boolean_algebra
theorem compl_bInter (s : set α) (t : α → set β) : -(⋂ i ∈ s, t i) = (⋃ i ∈ s, - t i) :=
ext (λ x, by simp [classical.not_forall])
theorem inter_bUnion (s : set α) (t : α → set β) (u : set β) :
u ∩ (⋃ i ∈ s, t i) = ⋃ i ∈ s, u ∩ t i :=
begin
ext x,
simp only [exists_prop, mem_Union, mem_inter_eq],
exact ⟨λ ⟨hx, ⟨i, is, xi⟩⟩, ⟨i, is, hx, xi⟩, λ ⟨i, is, hx, xi⟩, ⟨hx, ⟨i, is, xi⟩⟩⟩
end
theorem bUnion_inter (s : set α) (t : α → set β) (u : set β) :
(⋃ i ∈ s, t i) ∩ u = (⋃ i ∈ s, t i ∩ u) :=
by simp [@inter_comm _ _ u, inter_bUnion]
/-- Intersection of a set of sets. -/
@[reducible] def sInter (S : set (set α)) : set α := Inf S
prefix `⋂₀`:110 := sInter
theorem mem_sUnion_of_mem {x : α} {t : set α} {S : set (set α)} (hx : x ∈ t) (ht : t ∈ S) :
x ∈ ⋃₀ S :=
⟨t, ⟨ht, hx⟩⟩
@[simp] theorem mem_sUnion {x : α} {S : set (set α)} : x ∈ ⋃₀ S ↔ ∃t ∈ S, x ∈ t := iff.rfl
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : α} {t : set α} {S : set (set α)}
(hx : x ∉ ⋃₀ S) (ht : t ∈ S) : x ∉ t :=
λ h, hx ⟨t, ht, h⟩
@[simp] theorem mem_sInter {x : α} {S : set (set α)} : x ∈ ⋂₀ S ↔ ∀ t ∈ S, x ∈ t := iff.rfl
theorem sInter_subset_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : ⋂₀ S ⊆ t :=
Inf_le tS
theorem subset_sUnion_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : t ⊆ ⋃₀ S :=
le_Sup tS
lemma subset_sUnion_of_subset {s : set α} (t : set (set α)) (u : set α) (h₁ : s ⊆ u)
(h₂ : u ∈ t) : s ⊆ ⋃₀ t :=
subset.trans h₁ (subset_sUnion_of_mem h₂)
theorem sUnion_subset {S : set (set α)} {t : set α} (h : ∀t' ∈ S, t' ⊆ t) : (⋃₀ S) ⊆ t :=
Sup_le h
theorem sUnion_subset_iff {s : set (set α)} {t : set α} : ⋃₀ s ⊆ t ↔ ∀t' ∈ s, t' ⊆ t :=
⟨assume h t' ht', subset.trans (subset_sUnion_of_mem ht') h, sUnion_subset⟩
theorem subset_sInter {S : set (set α)} {t : set α} (h : ∀t' ∈ S, t ⊆ t') : t ⊆ (⋂₀ S) :=
le_Inf h
theorem sUnion_subset_sUnion {S T : set (set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T :=
sUnion_subset $ λ s hs, subset_sUnion_of_mem (h hs)
theorem sInter_subset_sInter {S T : set (set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S :=
subset_sInter $ λ s hs, sInter_subset_of_mem (h hs)
@[simp] theorem sUnion_empty : ⋃₀ ∅ = (∅ : set α) := Sup_empty
@[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : set α) := Inf_empty
@[simp] theorem sUnion_singleton (s : set α) : ⋃₀ {s} = s := Sup_singleton
@[simp] theorem sInter_singleton (s : set α) : ⋂₀ {s} = s := Inf_singleton
theorem sUnion_union (S T : set (set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T := Sup_union
theorem sInter_union (S T : set (set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := Inf_union
@[simp] theorem sUnion_insert (s : set α) (T : set (set α)) : ⋃₀ (insert s T) = s ∪ ⋃₀ T := Sup_insert
@[simp] theorem sInter_insert (s : set α) (T : set (set α)) : ⋂₀ (insert s T) = s ∩ ⋂₀ T := Inf_insert
theorem sUnion_pair (s t : set α) : ⋃₀ {s, t} = s ∪ t :=
(sUnion_insert _ _).trans $ by rw [union_comm, sUnion_singleton]
theorem sInter_pair (s t : set α) : ⋂₀ {s, t} = s ∩ t :=
(sInter_insert _ _).trans $ by rw [inter_comm, sInter_singleton]
@[simp] theorem sUnion_image (f : α → set β) (s : set α) : ⋃₀ (f '' s) = ⋃ x ∈ s, f x := Sup_image
@[simp] theorem sInter_image (f : α → set β) (s : set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := Inf_image
@[simp] theorem sUnion_range (f : ι → set β) : ⋃₀ (range f) = ⋃ x, f x := Sup_range
@[simp] theorem sInter_range (f : ι → set β) : ⋂₀ (range f) = ⋂ x, f x := Inf_range
lemma sUnion_eq_univ_iff {c : set (set α)} :
⋃₀ c = @set.univ α ↔ ∀ a, ∃ b ∈ c, a ∈ b :=
⟨λ H a, let ⟨b, hm, hb⟩ := mem_sUnion.1 $ by rw H; exact mem_univ a in ⟨b, hm, hb⟩,
λ H, set.univ_subset_iff.1 $ λ x hx, let ⟨b, hm, hb⟩ := H x in set.mem_sUnion_of_mem hb hm⟩
theorem compl_sUnion (S : set (set α)) :
- ⋃₀ S = ⋂₀ (compl '' S) :=
set.ext $ assume x,
⟨assume : ¬ (∃s∈S, x ∈ s), assume s h,
match s, h with
._, ⟨t, hs, rfl⟩ := assume h, this ⟨t, hs, h⟩
end,
assume : ∀s, s ∈ compl '' S → x ∈ s,
assume ⟨t, tS, xt⟩, this (compl t) (mem_image_of_mem _ tS) xt⟩
-- classical
theorem sUnion_eq_compl_sInter_compl (S : set (set α)) :
⋃₀ S = - ⋂₀ (compl '' S) :=
by rw [←compl_compl (⋃₀ S), compl_sUnion]
-- classical
theorem compl_sInter (S : set (set α)) :
- ⋂₀ S = ⋃₀ (compl '' S) :=
by rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
-- classical
theorem sInter_eq_comp_sUnion_compl (S : set (set α)) :
⋂₀ S = -(⋃₀ (compl '' S)) :=
by rw [←compl_compl (⋂₀ S), compl_sInter]
theorem inter_empty_of_inter_sUnion_empty {s t : set α} {S : set (set α)} (hs : t ∈ S)
(h : s ∩ ⋃₀ S = ∅) :
s ∩ t = ∅ :=
eq_empty_of_subset_empty $ by rw ← h; exact
inter_subset_inter_right _ (subset_sUnion_of_mem hs)
theorem Union_eq_sUnion_range (s : α → set β) : (⋃ i, s i) = ⋃₀ (range s) :=
by rw [← image_univ, sUnion_image]; simp
theorem Inter_eq_sInter_range {α I : Type} (s : I → set α) : (⋂ i, s i) = ⋂₀ (range s) :=
by rw [← image_univ, sInter_image]; simp
theorem range_sigma_eq_Union_range {γ : α → Type*} (f : sigma γ → β) :
range f = ⋃ a, range (λ b, f ⟨a, b⟩) :=
set.ext $ by simp
theorem Union_eq_range_sigma (s : α → set β) : (⋃ i, s i) = range (λ a : Σ i, s i, a.2) :=
by simp [set.ext_iff]
theorem Union_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : set (sigma σ)) :
(⋃ i, sigma.mk i '' (sigma.mk i ⁻¹' s)) = s :=
begin
ext x,
simp only [mem_Union, mem_image, mem_preimage],
split,
{ rintros ⟨i, a, h, rfl⟩, exact h },
{ intro h, cases x with i a, exact ⟨i, a, h, rfl⟩ }
end
lemma sUnion_mono {s t : set (set α)} (h : s ⊆ t) : (⋃₀ s) ⊆ (⋃₀ t) :=
sUnion_subset $ assume t' ht', subset_sUnion_of_mem $ h ht'
lemma Union_subset_Union {s t : ι → set α} (h : ∀i, s i ⊆ t i) : (⋃i, s i) ⊆ (⋃i, t i) :=
@supr_le_supr (set α) ι _ s t h
lemma Union_subset_Union2 {ι₂ : Sort*} {s : ι → set α} {t : ι₂ → set α} (h : ∀i, ∃j, s i ⊆ t j) :
(⋃i, s i) ⊆ (⋃i, t i) :=
@supr_le_supr2 (set α) ι ι₂ _ s t h
lemma Union_subset_Union_const {ι₂ : Sort x} {s : set α} (h : ι → ι₂) : (⋃ i:ι, s) ⊆ (⋃ j:ι₂, s) :=
@supr_le_supr_const (set α) ι ι₂ _ s h
@[simp] lemma Union_of_singleton (α : Type u) : (⋃(x : α), {x}) = @set.univ α :=
ext $ λ x, ⟨λ h, ⟨⟩, λ h, ⟨{x}, ⟨⟨x, rfl⟩, mem_singleton x⟩⟩⟩
theorem bUnion_subset_Union (s : set α) (t : α → set β) :
(⋃ x ∈ s, t x) ⊆ (⋃ x, t x) :=
Union_subset_Union $ λ i, Union_subset $ λ h, by refl
lemma sUnion_eq_bUnion {s : set (set α)} : (⋃₀ s) = (⋃ (i : set α) (h : i ∈ s), i) :=
set.ext $ by simp
lemma sInter_eq_bInter {s : set (set α)} : (⋂₀ s) = (⋂ (i : set α) (h : i ∈ s), i) :=
set.ext $ by simp
lemma sUnion_eq_Union {s : set (set α)} : (⋃₀ s) = (⋃ (i : s), i.1) :=
set.ext $ λ x, by simp
lemma sInter_eq_Inter {s : set (set α)} : (⋂₀ s) = (⋂ (i : s), i.1) :=
set.ext $ λ x, by simp
lemma union_eq_Union {s₁ s₂ : set α} : s₁ ∪ s₂ = ⋃ b : bool, cond b s₁ s₂ :=
set.ext $ λ x, by simp [bool.exists_bool, or_comm]
lemma inter_eq_Inter {s₁ s₂ : set α} : s₁ ∩ s₂ = ⋂ b : bool, cond b s₁ s₂ :=
set.ext $ λ x, by simp [bool.forall_bool, and_comm]
instance : complete_boolean_algebra (set α) :=
{ neg := compl,
sub := (\),
inf_neg_eq_bot := assume s, ext $ assume x, ⟨assume ⟨h, nh⟩, nh h, false.elim⟩,
sup_neg_eq_top := assume s, ext $ assume x, ⟨assume h, trivial, assume _, classical.em $ x ∈ s⟩,
le_sup_inf := distrib_lattice.le_sup_inf,
sub_eq := assume x y, rfl,
infi_sup_le_sup_Inf := assume s t x, show x ∈ (⋂ b ∈ t, s ∪ b) → x ∈ s ∪ (⋂₀ t),
by simp; exact assume h,
or.imp_right
(assume hn : x ∉ s, assume i hi, or.resolve_left (h i hi) hn)
(classical.em $ x ∈ s),
inf_Sup_le_supr_inf := assume s t x, show x ∈ s ∩ (⋃₀ t) → x ∈ (⋃ b ∈ t, s ∩ b),
by simp [-and_imp, and.left_comm],
..set.lattice_set }
lemma sInter_union_sInter {S T : set (set α)} :
(⋂₀S) ∪ (⋂₀T) = (⋂p ∈ set.prod S T, (p : (set α) × (set α)).1 ∪ p.2) :=
Inf_sup_Inf
lemma sUnion_inter_sUnion {s t : set (set α)} :
(⋃₀s) ∩ (⋃₀t) = (⋃p ∈ set.prod s t, (p : (set α) × (set α )).1 ∩ p.2) :=
Sup_inf_Sup
lemma sInter_bUnion {S : set (set α)} {T : set α → set (set α)} (hT : ∀s∈S, s = ⋂₀ T s) :
⋂₀ (⋃s∈S, T s) = ⋂₀ S :=
begin
ext,
simp only [and_imp, exists_prop, set.mem_sInter, set.mem_Union, exists_imp_distrib],
split,
{ assume H s sS,
rw [hT s sS, mem_sInter],
assume t tTs,
apply H t s sS tTs },
{ assume H t s sS tTs,
have xs : x ∈ s := H s sS,
have : s ⊆ t,
{ have Z := hT s sS,
rw sInter_eq_bInter at Z,
rw Z, apply bInter_subset_of_mem,
exact tTs },
exact this xs }
end
lemma sUnion_bUnion {S : set (set α)} {T : set α → set (set α)} (hT : ∀s∈S, s = ⋃₀ T s) :
⋃₀ (⋃s∈S, T s) = ⋃₀ S :=
begin
ext,
simp only [exists_prop, set.mem_Union, set.mem_set_of_eq],
split,
{ rintros ⟨t, ⟨⟨s, ⟨sS, tTs⟩⟩, xt⟩⟩,
refine ⟨s, ⟨sS, _⟩⟩,
rw hT s sS,
exact subset_sUnion_of_mem tTs xt },
{ rintros ⟨s, ⟨sS, xs⟩⟩,
rw hT s sS at xs,
rcases mem_sUnion.1 xs with ⟨t, tTs, xt⟩,
exact ⟨t, ⟨⟨s, ⟨sS, tTs⟩⟩, xt⟩⟩ }
end
lemma Union_range_eq_sUnion {α β : Type*} (C : set (set α))
{f : ∀(s : C), β → s} (hf : ∀(s : C), surjective (f s)) :
(⋃(y : β), range (λ(s : C), (f s y).val)) = ⋃₀ C :=
begin
ext x, split,
{ rintro ⟨s, ⟨y, rfl⟩, ⟨⟨s, hs⟩, rfl⟩⟩, refine ⟨_, hs, _⟩, exact (f ⟨s, hs⟩ y).2 },
{ rintro ⟨s, hs, hx⟩, cases hf ⟨s, hs⟩ ⟨x, hx⟩ with y hy, refine ⟨_, ⟨y, rfl⟩, ⟨⟨s, hs⟩, _⟩⟩,
exact congr_arg subtype.val hy }
end
lemma Union_range_eq_Union {ι α β : Type*} (C : ι → set α)
{f : ∀(x : ι), β → C x} (hf : ∀(x : ι), surjective (f x)) :
(⋃(y : β), range (λ(x : ι), (f x y).val)) = ⋃x, C x :=
begin
ext x, rw [mem_Union, mem_Union], split,
{ rintro ⟨y, ⟨i, rfl⟩⟩, exact ⟨i, (f i y).2⟩ },
{ rintro ⟨i, hx⟩, cases hf i ⟨x, hx⟩ with y hy, refine ⟨y, ⟨i, congr_arg subtype.val hy⟩⟩ }
end
@[simp] theorem sub_eq_diff (s t : set α) : s - t = s \ t := rfl
section
variables {p : Prop} {μ : p → set α}
@[simp] lemma Inter_pos (hp : p) : (⋂h:p, μ h) = μ hp := infi_pos hp
@[simp] lemma Inter_neg (hp : ¬ p) : (⋂h:p, μ h) = univ := infi_neg hp
@[simp] lemma Union_pos (hp : p) : (⋃h:p, μ h) = μ hp := supr_pos hp
@[simp] lemma Union_neg (hp : ¬ p) : (⋃h:p, μ h) = ∅ := supr_neg hp
@[simp] lemma Union_empty {ι : Sort*} : (⋃i:ι, ∅:set α) = ∅ := supr_bot
@[simp] lemma Inter_univ {ι : Sort*} : (⋂i:ι, univ:set α) = univ := infi_top
end
section image
lemma image_Union {f : α → β} {s : ι → set α} : f '' (⋃ i, s i) = (⋃i, f '' s i) :=
begin
apply set.ext, intro x,
simp [image, exists_and_distrib_right.symm, -exists_and_distrib_right],
exact exists_swap
end
lemma univ_subtype {p : α → Prop} : (univ : set (subtype p)) = (⋃x (h : p x), {⟨x, h⟩}) :=
set.ext $ assume ⟨x, h⟩, by simp [h]
lemma range_eq_Union {ι} (f : ι → α) : range f = (⋃i, {f i}) :=
set.ext $ assume a, by simp [@eq_comm α a]
lemma image_eq_Union (f : α → β) (s : set α) : f '' s = (⋃i∈s, {f i}) :=
set.ext $ assume b, by simp [@eq_comm β b]
lemma bUnion_range {f : ι → α} {g : α → set β} : (⋃x ∈ range f, g x) = (⋃y, g (f y)) :=
by rw [← sUnion_image, ← range_comp, sUnion_range]
lemma bInter_range {f : ι → α} {g : α → set β} : (⋂x ∈ range f, g x) = (⋂y, g (f y)) :=
by rw [← sInter_image, ← range_comp, sInter_range]
variables {s : set γ} {f : γ → α} {g : α → set β}
lemma bUnion_image : (⋃x∈ (f '' s), g x) = (⋃y ∈ s, g (f y)) :=
by rw [← sUnion_image, ← image_comp, sUnion_image]
lemma bInter_image : (⋂x∈ (f '' s), g x) = (⋂y ∈ s, g (f y)) :=
by rw [← sInter_image, ← image_comp, sInter_image]
end image
section preimage
theorem monotone_preimage {f : α → β} : monotone (preimage f) := assume a b h, preimage_mono h
@[simp] theorem preimage_Union {ι : Sort w} {f : α → β} {s : ι → set β} :
preimage f (⋃i, s i) = (⋃i, preimage f (s i)) :=
set.ext $ by simp [preimage]
theorem preimage_bUnion {ι} {f : α → β} {s : set ι} {t : ι → set β} :
preimage f (⋃i ∈ s, t i) = (⋃i ∈ s, preimage f (t i)) :=
by simp
@[simp] theorem preimage_sUnion {f : α → β} {s : set (set β)} :
preimage f (⋃₀ s) = (⋃t ∈ s, preimage f t) :=
set.ext $ by simp [preimage]
lemma preimage_Inter {ι : Sort*} {s : ι → set β} {f : α → β} :
f ⁻¹' (⋂ i, s i) = (⋂ i, f ⁻¹' s i) :=
by ext; simp
lemma preimage_bInter {s : γ → set β} {t : set γ} {f : α → β} :
f ⁻¹' (⋂ i∈t, s i) = (⋂ i∈t, f ⁻¹' s i) :=
by ext; simp
end preimage
section seq
def seq (s : set (α → β)) (t : set α) : set β := {b | ∃f∈s, ∃a∈t, (f : α → β) a = b}
lemma seq_def {s : set (α → β)} {t : set α} : seq s t = ⋃f∈s, f '' t :=
set.ext $ by simp [seq]
@[simp] lemma mem_seq_iff {s : set (α → β)} {t : set α} {b : β} :
b ∈ seq s t ↔ ∃ (f ∈ s) (a ∈ t), (f : α → β) a = b :=
iff.rfl
lemma seq_subset {s : set (α → β)} {t : set α} {u : set β} :
seq s t ⊆ u ↔ (∀f∈s, ∀a∈t, (f : α → β) a ∈ u) :=
iff.intro
(assume h f hf a ha, h ⟨f, hf, a, ha, rfl⟩)
(assume h b ⟨f, hf, a, ha, eq⟩, eq ▸ h f hf a ha)
lemma seq_mono {s₀ s₁ : set (α → β)} {t₀ t₁ : set α} (hs : s₀ ⊆ s₁) (ht : t₀ ⊆ t₁) :
seq s₀ t₀ ⊆ seq s₁ t₁ :=
assume b ⟨f, hf, a, ha, eq⟩, ⟨f, hs hf, a, ht ha, eq⟩
lemma singleton_seq {f : α → β} {t : set α} : set.seq {f} t = f '' t :=
set.ext $ by simp
lemma seq_singleton {s : set (α → β)} {a : α} : set.seq s {a} = (λf:α→β, f a) '' s :=
set.ext $ by simp
lemma seq_seq {s : set (β → γ)} {t : set (α → β)} {u : set α} :
seq s (seq t u) = seq (seq ((∘) '' s) t) u :=
begin
refine set.ext (assume c, iff.intro _ _),
{ rintros ⟨f, hfs, b, ⟨g, hg, a, hau, rfl⟩, rfl⟩,
exact ⟨f ∘ g, ⟨(∘) f, mem_image_of_mem _ hfs, g, hg, rfl⟩, a, hau, rfl⟩ },
{ rintros ⟨fg, ⟨fc, ⟨f, hfs, rfl⟩, g, hgt, rfl⟩, a, ha, rfl⟩,
exact ⟨f, hfs, g a, ⟨g, hgt, a, ha, rfl⟩, rfl⟩ }
end
lemma image_seq {f : β → γ} {s : set (α → β)} {t : set α} :
f '' seq s t = seq ((∘) f '' s) t :=
by rw [← singleton_seq, ← singleton_seq, seq_seq, image_singleton]
lemma prod_eq_seq {s : set α} {t : set β} : set.prod s t = (prod.mk '' s).seq t :=
begin
ext ⟨a, b⟩,
split,
{ rintros ⟨ha, hb⟩, exact ⟨prod.mk a, ⟨a, ha, rfl⟩, b, hb, rfl⟩ },
{ rintros ⟨f, ⟨x, hx, rfl⟩, y, hy, eq⟩, rw ← eq, exact ⟨hx, hy⟩ }
end
lemma prod_image_seq_comm (s : set α) (t : set β) :
(prod.mk '' s).seq t = seq ((λb a, (a, b)) '' t) s :=
by rw [← prod_eq_seq, ← image_swap_prod, prod_eq_seq, image_seq, ← image_comp]
end seq
theorem monotone_prod [preorder α] {f : α → set β} {g : α → set γ}
(hf : monotone f) (hg : monotone g) : monotone (λx, set.prod (f x) (g x)) :=
assume a b h, prod_mono (hf h) (hg h)
instance : monad set :=
{ pure := λ(α : Type u) a, {a},
bind := λ(α β : Type u) s f, ⋃i∈s, f i,
seq := λ(α β : Type u), set.seq,
map := λ(α β : Type u), set.image }
instance : is_lawful_monad set :=
{ pure_bind := assume α β x f, by simp,
bind_assoc := assume α β γ s f g, set.ext $ assume a,
by simp [exists_and_distrib_right.symm, -exists_and_distrib_right,
exists_and_distrib_left.symm, -exists_and_distrib_left, and_assoc];
exact exists_swap,
id_map := assume α, id_map,
bind_pure_comp_eq_map := assume α β f s, set.ext $ by simp [set.image, eq_comm],
bind_map_eq_seq := assume α β s t, by simp [seq_def] }
instance : is_comm_applicative (set : Type u → Type u) :=
⟨ assume α β s t, prod_image_seq_comm s t ⟩
section monad
variables {α' β' : Type u} {s : set α'} {f : α' → set β'} {g : set (α' → β')}
@[simp] lemma bind_def : s >>= f = ⋃i∈s, f i := rfl
@[simp] lemma fmap_eq_image (f : α' → β') : f <$> s = f '' s := rfl
@[simp] lemma seq_eq_set_seq {α β : Type*} (s : set (α → β)) (t : set α) : s <*> t = s.seq t := rfl
@[simp] lemma pure_def (a : α) : (pure a : set α) = {a} := rfl
end monad
section pi
lemma pi_def {α : Type*} {π : α → Type*} (i : set α) (s : Πa, set (π a)) :
pi i s = (⋂ a∈i, ((λf:(Πa, π a), f a) ⁻¹' (s a))) :=
by ext; simp [pi]
end pi
end set
/- disjoint sets -/
section disjoint
variable [semilattice_inf_bot α]
/-- Two elements of a lattice are disjoint if their inf is the bottom element.
(This generalizes disjoint sets, viewed as members of the subset lattice.) -/
def disjoint (a b : α) : Prop := a ⊓ b ≤ ⊥
theorem disjoint.eq_bot {a b : α} (h : disjoint a b) : a ⊓ b = ⊥ :=
eq_bot_iff.2 h
theorem disjoint_iff {a b : α} : disjoint a b ↔ a ⊓ b = ⊥ :=
eq_bot_iff.symm
theorem disjoint.comm {a b : α} : disjoint a b ↔ disjoint b a :=
by rw [disjoint, disjoint, inf_comm]
theorem disjoint.symm {a b : α} : disjoint a b → disjoint b a :=
disjoint.comm.1
@[simp] theorem disjoint_bot_left {a : α} : disjoint ⊥ a := disjoint_iff.2 bot_inf_eq
@[simp] theorem disjoint_bot_right {a : α} : disjoint a ⊥ := disjoint_iff.2 inf_bot_eq
theorem disjoint_mono {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) :
disjoint b d → disjoint a c := le_trans (inf_le_inf h₁ h₂)
theorem disjoint_mono_left {a b c : α} (h : a ≤ b) : disjoint b c → disjoint a c :=
disjoint_mono h (le_refl _)
theorem disjoint_mono_right {a b c : α} (h : b ≤ c) : disjoint a c → disjoint a b :=
disjoint_mono (le_refl _) h
@[simp] lemma disjoint_self {a : α} : disjoint a a ↔ a = ⊥ :=
by simp [disjoint]
lemma ne_of_disjoint {a b : α} (ha : a ≠ ⊥) (hab : disjoint a b) : a ≠ b :=
by { intro h, rw [←h, disjoint_self] at hab, exact ha hab }
end disjoint
namespace set
protected theorem disjoint_iff {s t : set α} : disjoint s t ↔ s ∩ t ⊆ ∅ := iff.rfl
lemma not_disjoint_iff {s t : set α} : ¬disjoint s t ↔ ∃x, x ∈ s ∧ x ∈ t :=
by { rw [set.disjoint_iff, subset_empty_iff], apply ne_empty_iff_exists_mem }
lemma disjoint_left {s t : set α} : disjoint s t ↔ ∀ {a}, a ∈ s → a ∉ t :=
show (∀ x, ¬(x ∈ s ∩ t)) ↔ _, from ⟨λ h a, not_and.1 $ h a, λ h a, not_and.2 $ h a⟩
theorem disjoint_right {s t : set α} : disjoint s t ↔ ∀ {a}, a ∈ t → a ∉ s :=
by rw [disjoint.comm, disjoint_left]
theorem disjoint_diff {a b : set α} : disjoint a (b \ a) :=
disjoint_iff.2 (inter_diff_self _ _)
theorem disjoint_compl (s : set α) : disjoint s (-s) := assume a ⟨h₁, h₂⟩, h₂ h₁
theorem disjoint_singleton_left {a : α} {s : set α} : disjoint {a} s ↔ a ∉ s :=
by simp [set.disjoint_iff, subset_def]; exact iff.rfl
theorem disjoint_singleton_right {a : α} {s : set α} : disjoint s {a} ↔ a ∉ s :=
by rw [disjoint.comm]; exact disjoint_singleton_left
theorem disjoint_image_image {f : β → α} {g : γ → α} {s : set β} {t : set γ}
(h : ∀b∈s, ∀c∈t, f b ≠ g c) : disjoint (f '' s) (g '' t) :=
by rintros a ⟨⟨b, hb, eq⟩, ⟨c, hc, rfl⟩⟩; exact h b hb c hc eq
def pairwise_disjoint (s : set (set α)) : Prop :=
pairwise_on s disjoint
lemma pairwise_disjoint_subset {s t : set (set α)} (h : s ⊆ t)
(ht : pairwise_disjoint t) : pairwise_disjoint s :=
pairwise_on.mono h ht
lemma pairwise_disjoint_range {s : set (set α)} (f : s → set α) (hf : ∀(x : s), f x ⊆ x.1)
(ht : pairwise_disjoint s) : pairwise_disjoint (range f) :=
begin
rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ hxy, refine disjoint_mono (hf x) (hf y) (ht _ x.2 _ y.2 _),
intro h, apply hxy, apply congr_arg f, exact subtype.eq h
end
/- warning: classical -/
lemma pairwise_disjoint_elim {s : set (set α)} (h : pairwise_disjoint s) {x y : set α}
(hx : x ∈ s) (hy : y ∈ s) (z : α) (hzx : z ∈ x) (hzy : z ∈ y) : x = y :=
begin
haveI := classical.prop_decidable, by_contra,
have : x ∩ y ≠ ∅, { rw [ne_empty_iff_exists_mem], exact ⟨z, ⟨hzx, hzy⟩⟩ },
apply this, exact disjoint_iff.mp (h x hx y hy a),
end
end set
namespace set
variables (t : α → set β)
def sigma_to_Union (x : Σi, t i) : (⋃i, t i) := ⟨x.2, mem_Union.2 ⟨x.1, x.2.2⟩⟩
lemma surjective_sigma_to_Union : surjective (sigma_to_Union t)
| ⟨b, hb⟩ := have ∃a, b ∈ t a, by simpa using hb, let ⟨a, hb⟩ := this in ⟨⟨a, ⟨b, hb⟩⟩, rfl⟩
lemma injective_sigma_to_Union (h : ∀i j, i ≠ j → disjoint (t i) (t j)) :
injective (sigma_to_Union t)
| ⟨a₁, ⟨b₁, h₁⟩⟩ ⟨a₂, ⟨b₂, h₂⟩⟩ eq :=
have b_eq : b₁ = b₂, from congr_arg subtype.val eq,
have a_eq : a₁ = a₂, from classical.by_contradiction $ assume ne,
have b₁ ∈ t a₁ ∩ t a₂, from ⟨h₁, b_eq.symm ▸ h₂⟩,
h _ _ ne this,
sigma.eq a_eq $ subtype.eq $ by subst b_eq; subst a_eq
lemma bijective_sigma_to_Union (h : ∀i j, i ≠ j → disjoint (t i) (t j)) :
bijective (sigma_to_Union t) :=
⟨injective_sigma_to_Union t h, surjective_sigma_to_Union t⟩
noncomputable def Union_eq_sigma_of_disjoint {t : α → set β}
(h : ∀i j, i ≠ j → disjoint (t i) (t j)) : (⋃i, t i) ≃ (Σi, t i) :=
(equiv.of_bijective $ bijective_sigma_to_Union t h).symm
noncomputable def bUnion_eq_sigma_of_disjoint {s : set α} {t : α → set β}
(h : pairwise_on s (disjoint on t)) : (⋃i∈s, t i) ≃ (Σi:s, t i.val) :=
equiv.trans (equiv.set_congr (bUnion_eq_Union _ _)) $ Union_eq_sigma_of_disjoint $
assume ⟨i, hi⟩ ⟨j, hj⟩ ne, h _ hi _ hj $ assume eq, ne $ subtype.eq eq
end set
|
01cb0fffece6d2e640aa42527f87f9f6d6f470dc | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/category/omega_complete_partial_order.lean | 15b627c09c36761ce0ad0b2636ef671a8cd97771 | [
"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,334 | lean | /-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import order.omega_complete_partial_order
import category_theory.limits.shapes.products
import category_theory.limits.shapes.equalizers
import category_theory.limits.constructions.limits_of_products_and_equalizers
import category_theory.concrete_category.bundled_hom
/-!
# Category of types with a omega complete partial order
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file, we bundle the class `omega_complete_partial_order` into a
concrete category and prove that continuous functions also form
a `omega_complete_partial_order`.
## Main definitions
* `ωCPO`
* an instance of `category` and `concrete_category`
-/
open category_theory
universes u v
/-- The category of types with a omega complete partial order. -/
def ωCPO : Type (u+1) := bundled omega_complete_partial_order
namespace ωCPO
open omega_complete_partial_order
instance : bundled_hom @continuous_hom :=
{ to_fun := @continuous_hom.simps.apply,
id := @continuous_hom.id,
comp := @continuous_hom.comp,
hom_ext := @continuous_hom.coe_inj }
attribute [derive [large_category, concrete_category]] ωCPO
instance : has_coe_to_sort ωCPO Type* := bundled.has_coe_to_sort
/-- Construct a bundled ωCPO from the underlying type and typeclass. -/
def of (α : Type*) [omega_complete_partial_order α] : ωCPO := bundled.of α
@[simp] lemma coe_of (α : Type*) [omega_complete_partial_order α] : ↥(of α) = α := rfl
instance : inhabited ωCPO := ⟨of punit⟩
instance (α : ωCPO) : omega_complete_partial_order α := α.str
section
open category_theory.limits
namespace has_products
/-- The pi-type gives a cone for a product. -/
def product {J : Type v} (f : J → ωCPO.{v}) : fan f :=
fan.mk (of (Π j, f j)) (λ j, continuous_hom.of_mono (pi.eval_order_hom j) (λ c, rfl))
/-- The pi-type is a limit cone for the product. -/
def is_product (J : Type v) (f : J → ωCPO) : is_limit (product f) :=
{ lift := λ s,
⟨⟨λ t j, s.π.app ⟨j⟩ t, λ x y h j, (s.π.app ⟨j⟩).monotone h⟩,
λ x, funext (λ j, (s.π.app ⟨j⟩).continuous x)⟩,
uniq' := λ s m w,
begin
ext t j,
change m t j = s.π.app ⟨j⟩ t,
rw ← w ⟨j⟩,
refl,
end,
fac' := λ s j, by { cases j, tidy, } }.
instance (J : Type v) (f : J → ωCPO.{v}) : has_product f :=
has_limit.mk ⟨_, is_product _ f⟩
end has_products
instance omega_complete_partial_order_equalizer
{α β : Type*} [omega_complete_partial_order α] [omega_complete_partial_order β]
(f g : α →𝒄 β) : omega_complete_partial_order {a : α // f a = g a} :=
omega_complete_partial_order.subtype _ $ λ c hc,
begin
rw [f.continuous, g.continuous],
congr' 1,
ext,
apply hc _ ⟨_, rfl⟩,
end
namespace has_equalizers
/-- The equalizer inclusion function as a `continuous_hom`. -/
def equalizer_ι {α β : Type*} [omega_complete_partial_order α] [omega_complete_partial_order β]
(f g : α →𝒄 β) :
{a : α // f a = g a} →𝒄 α :=
continuous_hom.of_mono (order_hom.subtype.val _) (λ c, rfl)
/-- A construction of the equalizer fork. -/
def equalizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) :
fork f g :=
@fork.of_ι _ _ _ _ _ _ (ωCPO.of {a // f a = g a}) (equalizer_ι f g)
(continuous_hom.ext _ _ (λ x, x.2))
/-- The equalizer fork is a limit. -/
def is_equalizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) : is_limit (equalizer f g) :=
fork.is_limit.mk' _ $ λ s,
⟨{ to_fun := λ x, ⟨s.ι x, by apply continuous_hom.congr_fun s.condition⟩,
monotone' := λ x y h, s.ι.monotone h,
cont := λ x, subtype.ext (s.ι.continuous x) },
by { ext, refl },
λ m hm,
begin
ext,
apply continuous_hom.congr_fun hm,
end⟩
end has_equalizers
instance : has_products.{v} ωCPO.{v} :=
λ J, { has_limit := λ F, has_limit_of_iso discrete.nat_iso_functor.symm }
instance {X Y : ωCPO.{v}} (f g : X ⟶ Y) : has_limit (parallel_pair f g) :=
has_limit.mk ⟨_, has_equalizers.is_equalizer f g⟩
instance : has_equalizers ωCPO.{v} := has_equalizers_of_has_limit_parallel_pair _
instance : has_limits ωCPO.{v} := has_limits_of_has_equalizers_and_products
end
end ωCPO
|
1806f3404fa263716766f1584eea6e7c6c7fc38a | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/algebra/functions_auto.lean | 8dd631cf334e850fc520b64e82625353e88bdea2 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,405 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.algebra.order
import Mathlib.Lean3Lib.init.meta.default
universes u
namespace Mathlib
def min {α : Type u} [linear_order α] (a : α) (b : α) : α := ite (a ≤ b) a b
def max {α : Type u} [linear_order α] (a : α) (b : α) : α := ite (b ≤ a) a b
theorem min_le_left {α : Type u} [linear_order α] (a : α) (b : α) : min a b ≤ a := sorry
theorem min_le_right {α : Type u} [linear_order α] (a : α) (b : α) : min a b ≤ b := sorry
theorem le_min {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) :
c ≤ min a b :=
sorry
theorem le_max_left {α : Type u} [linear_order α] (a : α) (b : α) : a ≤ max a b := sorry
theorem le_max_right {α : Type u} [linear_order α] (a : α) (b : α) : b ≤ max a b := sorry
theorem max_le {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) :
max a b ≤ c :=
sorry
theorem eq_min {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h₁ : c ≤ a) (h₂ : c ≤ b)
(h₃ : ∀ {d : α}, d ≤ a → d ≤ b → d ≤ c) : c = min a b :=
le_antisymm (le_min h₁ h₂) (h₃ (min_le_left a b) (min_le_right a b))
theorem min_comm {α : Type u} [linear_order α] (a : α) (b : α) : min a b = min b a :=
eq_min (min_le_right a b) (min_le_left a b) fun (c : α) (h₁ : c ≤ b) (h₂ : c ≤ a) => le_min h₂ h₁
theorem min_assoc {α : Type u} [linear_order α] (a : α) (b : α) (c : α) :
min (min a b) c = min a (min b c) :=
sorry
theorem min_left_comm {α : Type u} [linear_order α] (a : α) (b : α) (c : α) :
min a (min b c) = min b (min a c) :=
left_comm min min_comm min_assoc
@[simp] theorem min_self {α : Type u} [linear_order α] (a : α) : min a a = a := sorry
theorem min_eq_left {α : Type u} [linear_order α] {a : α} {b : α} (h : a ≤ b) : min a b = a :=
Eq.symm (eq_min (le_refl a) h fun (d : α) (ᾰ : d ≤ a) (ᾰ_1 : d ≤ b) => ᾰ)
theorem min_eq_right {α : Type u} [linear_order α] {a : α} {b : α} (h : b ≤ a) : min a b = b :=
min_comm b a ▸ min_eq_left h
theorem eq_max {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h₁ : a ≤ c) (h₂ : b ≤ c)
(h₃ : ∀ {d : α}, a ≤ d → b ≤ d → c ≤ d) : c = max a b :=
le_antisymm (h₃ (le_max_left a b) (le_max_right a b)) (max_le h₁ h₂)
theorem max_comm {α : Type u} [linear_order α] (a : α) (b : α) : max a b = max b a :=
eq_max (le_max_right a b) (le_max_left a b) fun (c : α) (h₁ : b ≤ c) (h₂ : a ≤ c) => max_le h₂ h₁
theorem max_assoc {α : Type u} [linear_order α] (a : α) (b : α) (c : α) :
max (max a b) c = max a (max b c) :=
sorry
theorem max_left_comm {α : Type u} [linear_order α] (a : α) (b : α) (c : α) :
max a (max b c) = max b (max a c) :=
left_comm max max_comm max_assoc
@[simp] theorem max_self {α : Type u} [linear_order α] (a : α) : max a a = a := sorry
theorem max_eq_left {α : Type u} [linear_order α] {a : α} {b : α} (h : b ≤ a) : max a b = a :=
Eq.symm (eq_max (le_refl a) h fun (d : α) (ᾰ : a ≤ d) (ᾰ_1 : b ≤ d) => ᾰ)
theorem max_eq_right {α : Type u} [linear_order α] {a : α} {b : α} (h : a ≤ b) : max a b = b :=
max_comm b a ▸ max_eq_left h
/- these rely on lt_of_lt -/
theorem min_eq_left_of_lt {α : Type u} [linear_order α] {a : α} {b : α} (h : a < b) : min a b = a :=
min_eq_left (le_of_lt h)
theorem min_eq_right_of_lt {α : Type u} [linear_order α] {a : α} {b : α} (h : b < a) :
min a b = b :=
min_eq_right (le_of_lt h)
theorem max_eq_left_of_lt {α : Type u} [linear_order α] {a : α} {b : α} (h : b < a) : max a b = a :=
max_eq_left (le_of_lt h)
theorem max_eq_right_of_lt {α : Type u} [linear_order α] {a : α} {b : α} (h : a < b) :
max a b = b :=
max_eq_right (le_of_lt h)
/- these use the fact that it is a linear ordering -/
theorem lt_min {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h₁ : a < b) (h₂ : a < c) :
a < min b c :=
sorry
theorem max_lt {α : Type u} [linear_order α] {a : α} {b : α} {c : α} (h₁ : a < c) (h₂ : b < c) :
max a b < c :=
sorry
end Mathlib |
4c0ed602123083ebfc14944680de2cb6ac59ebea | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Elab/Inductive.lean | f3d98d0587b2cedffd9fdc80bb8e6bc47b747df7 | [
"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 | 40,101 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Util.ForEachExprWhere
import Lean.Util.ReplaceLevel
import Lean.Util.ReplaceExpr
import Lean.Util.CollectLevelParams
import Lean.Meta.Constructions
import Lean.Meta.CollectFVars
import Lean.Meta.SizeOf
import Lean.Meta.Injective
import Lean.Meta.IndPredBelow
import Lean.Elab.Command
import Lean.Elab.ComputedFields
import Lean.Elab.DefView
import Lean.Elab.DeclUtil
import Lean.Elab.Deriving.Basic
namespace Lean.Elab.Command
open Meta
builtin_initialize
registerTraceClass `Elab.inductive
def checkValidInductiveModifier [Monad m] [MonadError m] (modifiers : Modifiers) : m Unit := do
if modifiers.isNoncomputable then
throwError "invalid use of 'noncomputable' in inductive declaration"
if modifiers.isPartial then
throwError "invalid use of 'partial' in inductive declaration"
def checkValidCtorModifier [Monad m] [MonadError m] (modifiers : Modifiers) : m Unit := do
if modifiers.isNoncomputable then
throwError "invalid use of 'noncomputable' in constructor declaration"
if modifiers.isPartial then
throwError "invalid use of 'partial' in constructor declaration"
if modifiers.isUnsafe then
throwError "invalid use of 'unsafe' in constructor declaration"
if modifiers.attrs.size != 0 then
throwError "invalid use of attributes in constructor declaration"
structure CtorView where
ref : Syntax
modifiers : Modifiers
declName : Name
binders : Syntax
type? : Option Syntax
deriving Inhabited
structure ComputedFieldView where
ref : Syntax
modifiers : Syntax
fieldId : Name
type : Syntax.Term
matchAlts : TSyntax ``Parser.Term.matchAlts
structure InductiveView where
ref : Syntax
declId : Syntax
modifiers : Modifiers
shortDeclName : Name
declName : Name
levelNames : List Name
binders : Syntax
type? : Option Syntax
ctors : Array CtorView
derivingClasses : Array DerivingClassView
computedFields : Array ComputedFieldView
deriving Inhabited
structure ElabHeaderResult where
view : InductiveView
lctx : LocalContext
localInsts : LocalInstances
params : Array Expr
type : Expr
deriving Inhabited
private partial def elabHeaderAux (views : Array InductiveView) (i : Nat) (acc : Array ElabHeaderResult) : TermElabM (Array ElabHeaderResult) :=
Term.withAutoBoundImplicitForbiddenPred (fun n => views.any (·.shortDeclName == n)) do
if h : i < views.size then
let view := views.get ⟨i, h⟩
let acc ← Term.withAutoBoundImplicit <| Term.elabBinders view.binders.getArgs fun params => do
match view.type? with
| none =>
let u ← mkFreshLevelMVar
let type := mkSort u
Term.synthesizeSyntheticMVarsNoPostponing
Term.addAutoBoundImplicits' params type fun params type => do
return acc.push { lctx := (← getLCtx), localInsts := (← getLocalInstances), params, type, view }
| some typeStx =>
let (type, _) ← Term.withAutoBoundImplicit do
let type ← Term.elabType typeStx
unless (← isTypeFormerType type) do
throwErrorAt typeStx "invalid inductive type, resultant type is not a sort"
Term.synthesizeSyntheticMVarsNoPostponing
let indices ← Term.addAutoBoundImplicits #[]
return (← mkForallFVars indices type, indices.size)
Term.addAutoBoundImplicits' params type fun params type => do
trace[Elab.inductive] "header params: {params}, type: {type}"
return acc.push { lctx := (← getLCtx), localInsts := (← getLocalInstances), params, type, view }
elabHeaderAux views (i+1) acc
else
return acc
private def checkNumParams (rs : Array ElabHeaderResult) : TermElabM Nat := do
let numParams := rs[0]!.params.size
for r in rs do
unless r.params.size == numParams do
throwErrorAt r.view.ref "invalid inductive type, number of parameters mismatch in mutually inductive datatypes"
return numParams
private def checkUnsafe (rs : Array ElabHeaderResult) : TermElabM Unit := do
let isUnsafe := rs[0]!.view.modifiers.isUnsafe
for r in rs do
unless r.view.modifiers.isUnsafe == isUnsafe do
throwErrorAt r.view.ref "invalid inductive type, cannot mix unsafe and safe declarations in a mutually inductive datatypes"
private def checkLevelNames (views : Array InductiveView) : TermElabM Unit := do
if views.size > 1 then
let levelNames := views[0]!.levelNames
for view in views do
unless view.levelNames == levelNames do
throwErrorAt view.ref "invalid inductive type, universe parameters mismatch in mutually inductive datatypes"
private def mkTypeFor (r : ElabHeaderResult) : TermElabM Expr := do
withLCtx r.lctx r.localInsts do
mkForallFVars r.params r.type
private def throwUnexpectedInductiveType : TermElabM α :=
throwError "unexpected inductive resulting type"
private def eqvFirstTypeResult (firstType type : Expr) : MetaM Bool :=
forallTelescopeReducing firstType fun _ firstTypeResult => isDefEq firstTypeResult type
-- Auxiliary function for checking whether the types in mutually inductive declaration are compatible.
private partial def checkParamsAndResultType (type firstType : Expr) (numParams : Nat) : TermElabM Unit := do
try
forallTelescopeCompatible type firstType numParams fun _ type firstType =>
forallTelescopeReducing type fun _ type =>
forallTelescopeReducing firstType fun _ firstType => do
let type ← whnfD type
match type with
| .sort .. =>
unless (← isDefEq firstType type) do
throwError "resulting universe mismatch, given{indentExpr type}\nexpected type{indentExpr firstType}"
| _ =>
throwError "unexpected inductive resulting type"
catch
| Exception.error ref msg => throw (Exception.error ref m!"invalid mutually inductive types, {msg}")
| ex => throw ex
-- Auxiliary function for checking whether the types in mutually inductive declaration are compatible.
private def checkHeader (r : ElabHeaderResult) (numParams : Nat) (firstType? : Option Expr) : TermElabM Expr := do
let type ← mkTypeFor r
match firstType? with
| none => return type
| some firstType =>
withRef r.view.ref <| checkParamsAndResultType type firstType numParams
return firstType
-- Auxiliary function for checking whether the types in mutually inductive declaration are compatible.
private partial def checkHeaders (rs : Array ElabHeaderResult) (numParams : Nat) (i : Nat) (firstType? : Option Expr) : TermElabM Unit := do
if i < rs.size then
let type ← checkHeader rs[i]! numParams firstType?
checkHeaders rs numParams (i+1) type
private def elabHeader (views : Array InductiveView) : TermElabM (Array ElabHeaderResult) := do
let rs ← elabHeaderAux views 0 #[]
if rs.size > 1 then
checkUnsafe rs
let numParams ← checkNumParams rs
checkHeaders rs numParams 0 none
return rs
/-- Create a local declaration for each inductive type in `rs`, and execute `x params indFVars`, where `params` are the inductive type parameters and
`indFVars` are the new local declarations.
We use the local context/instances and parameters of rs[0].
Note that this method is executed after we executed `checkHeaders` and established all
parameters are compatible. -/
private partial def withInductiveLocalDecls (rs : Array ElabHeaderResult) (x : Array Expr → Array Expr → TermElabM α) : TermElabM α := do
let namesAndTypes ← rs.mapM fun r => do
let type ← mkTypeFor r
pure (r.view.declName, r.view.shortDeclName, type)
let r0 := rs[0]!
let params := r0.params
withLCtx r0.lctx r0.localInsts <| withRef r0.view.ref do
let rec loop (i : Nat) (indFVars : Array Expr) := do
if h : i < namesAndTypes.size then
let (declName, shortDeclName, type) := namesAndTypes.get ⟨i, h⟩
Term.withAuxDecl shortDeclName type declName fun indFVar => loop (i+1) (indFVars.push indFVar)
else
x params indFVars
loop 0 #[]
private def isInductiveFamily (numParams : Nat) (indFVar : Expr) : TermElabM Bool := do
let indFVarType ← inferType indFVar
forallTelescopeReducing indFVarType fun xs _ =>
return xs.size > numParams
private def getArrowBinderNames (type : Expr) : Array Name :=
go type #[]
where
go (type : Expr) (acc : Array Name) : Array Name :=
match type with
| .forallE n _ b _ => go b (acc.push n)
| .mdata _ b => go b acc
| _ => acc
/--
Replace binder names in `type` with `newNames`.
Remark: we only replace the names for binder containing macroscopes.
-/
private def replaceArrowBinderNames (type : Expr) (newNames : Array Name) : Expr :=
go type 0
where
go (type : Expr) (i : Nat) : Expr :=
if i < newNames.size then
match type with
| .forallE n d b bi =>
if n.hasMacroScopes then
mkForall newNames[i]! bi d (go b (i+1))
else
mkForall n bi d (go b (i+1))
| _ => type
else
type
/--
Reorder contructor arguments to improve the effectiveness of the `fixedIndicesToParams` method.
The idea is quite simple. Given a constructor type of the form
```
(a₁ : A₁) → ... → (aₙ : Aₙ) → C b₁ ... bₘ
```
We try to find the longest prefix `b₁ ... bᵢ`, `i ≤ m` s.t.
- each `bₖ` is in `{a₁, ..., aₙ}`
- each `bₖ` only depends on variables in `{b₁, ..., bₖ₋₁}`
Then, it moves this prefix `b₁ ... bᵢ` to the front.
Remark: We only reorder implicit arguments that have macroscopes. See issue #1156.
The macroscope test is an approximation, we could have restricted ourselves to auto-implicit arguments.
-/
private def reorderCtorArgs (ctorType : Expr) : MetaM Expr := do
forallTelescopeReducing ctorType fun as type => do
/- `type` is of the form `C ...` where `C` is the inductive datatype being defined. -/
let bs := type.getAppArgs
let mut as := as
let mut bsPrefix := #[]
for b in bs do
unless b.isFVar && as.contains b do
break
let localDecl ← getFVarLocalDecl b
if localDecl.binderInfo.isExplicit then
break
unless localDecl.userName.hasMacroScopes do
break
if (← localDeclDependsOnPred localDecl fun fvarId => as.any fun p => p.fvarId! == fvarId) then
break
bsPrefix := bsPrefix.push b
as := as.erase b
if bsPrefix.isEmpty then
return ctorType
else
let r ← mkForallFVars (bsPrefix ++ as) type
/- `r` already contains the resulting type.
To be able to produce more better error messages, we copy the first `bsPrefix.size` binder names from `C` to `r`.
This is important when some of contructor parameters were inferred using the auto-bound implicit feature.
For example, in the following declaration.
```
inductive Member : α → List α → Type u
| head : Member a (a::as)
| tail : Member a bs → Member a (b::bs)
```
if we do not copy the binder names
```
#check @Member.head
```
produces `@Member.head : {x : Type u_1} → {a : x} → {as : List x} → Member a (a :: as)`
which is correct, but a bit confusing. By copying the binder names, we obtain
`@Member.head : {α : Type u_1} → {a : α} → {as : List α} → Member a (a :: as)`
-/
let C := type.getAppFn
let binderNames := getArrowBinderNames (← instantiateMVars (← inferType C))
return replaceArrowBinderNames r binderNames[:bsPrefix.size]
/--
Execute `k` with updated binder information for `xs`. Any `x` that is explicit becomes implicit.
-/
private def withExplicitToImplicit (xs : Array Expr) (k : TermElabM α) : TermElabM α := do
let mut toImplicit := #[]
for x in xs do
if (← getFVarLocalDecl x).binderInfo.isExplicit then
toImplicit := toImplicit.push (x.fvarId!, BinderInfo.implicit)
withNewBinderInfos toImplicit k
/--
Elaborate constructor types.
Remark: we check whether the resulting type is correct, and the parameter occurrences are consistent, but
we currently do not check for:
- Positivity (it is a rare failure, and the kernel already checks for it).
- Universe constraints (the kernel checks for it).
-/
private def elabCtors (indFVars : Array Expr) (indFVar : Expr) (params : Array Expr) (r : ElabHeaderResult) : TermElabM (List Constructor) := withRef r.view.ref do
let indFamily ← isInductiveFamily params.size indFVar
r.view.ctors.toList.mapM fun ctorView =>
Term.withAutoBoundImplicit <| Term.elabBinders ctorView.binders.getArgs fun ctorParams =>
withRef ctorView.ref do
let rec elabCtorType (k : Expr → TermElabM Constructor) : TermElabM Constructor := do
match ctorView.type? with
| none =>
if indFamily then
throwError "constructor resulting type must be specified in inductive family declaration"
k <| mkAppN indFVar params
| some ctorType =>
let type ← Term.elabType ctorType
trace[Elab.inductive] "elabType {ctorView.declName} : {type} "
Term.synthesizeSyntheticMVars (mayPostpone := true)
let type ← instantiateMVars type
let type ← checkParamOccs type
forallTelescopeReducing type fun _ resultingType => do
unless resultingType.getAppFn == indFVar do
throwError "unexpected constructor resulting type{indentExpr resultingType}"
unless (← isType resultingType) do
throwError "unexpected constructor resulting type, type expected{indentExpr resultingType}"
k type
elabCtorType fun type => do
Term.synthesizeSyntheticMVarsNoPostponing
let ctorParams ← Term.addAutoBoundImplicits ctorParams
let except (mvarId : MVarId) := ctorParams.any fun ctorParam => ctorParam.isMVar && ctorParam.mvarId! == mvarId
/-
We convert metavariables in the resulting type info extra parameters. Otherwise, we would not be able to elaborate
declarations such as
```
inductive Palindrome : List α → Prop where
| nil : Palindrome [] -- We would get an error here saying "failed to synthesize implicit argument" at `@List.nil ?m`
| single : (a : α) → Palindrome [a]
| sandwich : (a : α) → Palindrome as → Palindrome ([a] ++ as ++ [a])
```
We used to also collect unassigned metavariables on `ctorParams`, but it produced counterintuitive behavior.
For example, the following declaration used to be accepted.
```
inductive Foo
| bar (x)
#check Foo.bar
-- @Foo.bar : {x : Sort u_1} → x → Foo
```
which is also inconsistent with the behavior of auto implicits in definitions. For example, the following example was never accepted.
```
def bar (x) := 1
```
-/
let extraCtorParams ← Term.collectUnassignedMVars (← instantiateMVars type) #[] except
trace[Elab.inductive] "extraCtorParams: {extraCtorParams}"
/- We must abstract `extraCtorParams` and `ctorParams` simultaneously to make
sure we do not create auxiliary metavariables. -/
let type ← mkForallFVars (extraCtorParams ++ ctorParams) type
let type ← reorderCtorArgs type
let type ← mkForallFVars params type
trace[Elab.inductive] "{ctorView.declName} : {type}"
return { name := ctorView.declName, type }
where
checkParamOccs (ctorType : Expr) : MetaM Expr :=
let visit (e : Expr) : MetaM TransformStep := do
let f := e.getAppFn
if indFVars.contains f then
let mut args := e.getAppArgs
unless args.size ≥ params.size do
throwError "unexpected inductive type occurrence{indentExpr e}"
for i in [:params.size] do
let param := params[i]!
let arg := args[i]!
unless (← isDefEq param arg) do
throwError "inductive datatype parameter mismatch{indentExpr arg}\nexpected{indentExpr param}"
args := args.set! i param
return TransformStep.done (mkAppN f args)
else
return .continue
transform ctorType (pre := visit)
private def getResultingUniverse : List InductiveType → TermElabM Level
| [] => throwError "unexpected empty inductive declaration"
| indType :: _ => forallTelescopeReducing indType.type fun _ r => do
let r ← whnfD r
match r with
| Expr.sort u => return u
| _ => throwError "unexpected inductive type resulting type{indentExpr r}"
/--
Return `some ?m` if `u` is of the form `?m + k`.
Return none if `u` does not contain universe metavariables.
Throw exception otherwise. -/
def shouldInferResultUniverse (u : Level) : TermElabM (Option LMVarId) := do
let u ← instantiateLevelMVars u
if u.hasMVar then
match u.getLevelOffset with
| Level.mvar mvarId => return some mvarId
| _ =>
throwError "cannot infer resulting universe level of inductive datatype, given level contains metavariables {mkSort u}, provide universe explicitly"
else
return none
/--
Convert universe metavariables into new parameters. It skips `univToInfer?` (the inductive datatype resulting universe) because
it should be inferred later using `inferResultingUniverse`.
-/
private def levelMVarToParam (indTypes : List InductiveType) (univToInfer? : Option LMVarId) : TermElabM (List InductiveType) :=
indTypes.mapM fun indType => do
let type ← levelMVarToParam' indType.type
let ctors ← indType.ctors.mapM fun ctor => do
let ctorType ← levelMVarToParam' ctor.type
return { ctor with type := ctorType }
return { indType with ctors, type }
where
levelMVarToParam' (type : Expr) : TermElabM Expr := do
Term.levelMVarToParam type (except := fun mvarId => univToInfer? == some mvarId)
def mkResultUniverse (us : Array Level) (rOffset : Nat) : Level :=
if us.isEmpty && rOffset == 0 then
levelOne
else
let r := Level.mkNaryMax us.toList
if rOffset == 0 && !r.isZero && !r.isNeverZero then
mkLevelMax r levelOne |>.normalize
else
r.normalize
/--
Auxiliary function for `updateResultingUniverse`
`accLevel u r rOffset` add `u` to state if it is not already there and
it is different from the resulting universe level `r+rOffset`.
If `u` is a `max`, then its components are recursively processed.
If `u` is a `succ` and `rOffset > 0`, we process the `u`s child using `rOffset-1`.
This method is used to infer the resulting universe level of an inductive datatype.
-/
def accLevel (u : Level) (r : Level) (rOffset : Nat) : OptionT (StateT (Array Level) Id) Unit := do
go u rOffset
where
go (u : Level) (rOffset : Nat) : OptionT (StateT (Array Level) Id) Unit := do
match u, rOffset with
| .max u v, rOffset => go u rOffset; go v rOffset
| .imax u v, rOffset => go u rOffset; go v rOffset
| .zero, _ => return ()
| .succ u, rOffset+1 => go u rOffset
| u, rOffset =>
if rOffset == 0 && u == r then
return ()
else if r.occurs u then
failure
else if rOffset > 0 then
failure
else if (← get).contains u then
return ()
else
modify fun us => us.push u
/--
Auxiliary function for `updateResultingUniverse`
`accLevelAtCtor ctor ctorParam r rOffset` add `u` (`ctorParam`'s universe) to state if it is not already there and
it is different from the resulting universe level `r+rOffset`.
See `accLevel`.
-/
def accLevelAtCtor (ctor : Constructor) (ctorParam : Expr) (r : Level) (rOffset : Nat) : StateRefT (Array Level) TermElabM Unit := do
let type ← inferType ctorParam
let u ← instantiateLevelMVars (← getLevel type)
match (← modifyGet fun s => accLevel u r rOffset |>.run |>.run s) with
| some _ => pure ()
| none =>
let typeType ← inferType type
let mut msg := m!"failed to compute resulting universe level of inductive datatype, constructor '{ctor.name}' has type{indentExpr ctor.type}\nparameter"
let localDecl ← getFVarLocalDecl ctorParam
unless localDecl.userName.hasMacroScopes do
msg := msg ++ m!" '{ctorParam}'"
msg := msg ++ m!" has type{indentD m!"{type} : {typeType}"}\ninductive type resulting type{indentExpr (mkSort (r.addOffset rOffset))}"
if r.isMVar then
msg := msg ++ "\nrecall that Lean only infers the resulting universe level automatically when there is a unique solution for the universe level constraints, consider explicitly providing the inductive type resulting universe level"
throwError msg
/--
Execute `k` using the `Syntax` reference associated with constructor `ctorName`.
-/
def withCtorRef [Monad m] [MonadRef m] (views : Array InductiveView) (ctorName : Name) (k : m α) : m α := do
for view in views do
for ctorView in view.ctors do
if ctorView.declName == ctorName then
return (← withRef ctorView.ref k)
k
/-- Auxiliary function for `updateResultingUniverse` -/
private partial def collectUniverses (views : Array InductiveView) (r : Level) (rOffset : Nat) (numParams : Nat) (indTypes : List InductiveType) : TermElabM (Array Level) := do
let (_, us) ← go |>.run #[]
return us
where
go : StateRefT (Array Level) TermElabM Unit :=
indTypes.forM fun indType => indType.ctors.forM fun ctor =>
withCtorRef views ctor.name do
forallTelescopeReducing ctor.type fun ctorParams _ =>
for ctorParam in ctorParams[numParams:] do
accLevelAtCtor ctor ctorParam r rOffset
private def updateResultingUniverse (views : Array InductiveView) (numParams : Nat) (indTypes : List InductiveType) : TermElabM (List InductiveType) := do
let r ← getResultingUniverse indTypes
let rOffset : Nat := r.getOffset
let r : Level := r.getLevelOffset
unless r.isMVar do
throwError "failed to compute resulting universe level of inductive datatype, provide universe explicitly: {r}"
let us ← collectUniverses views r rOffset numParams indTypes
trace[Elab.inductive] "updateResultingUniverse us: {us}, r: {r}, rOffset: {rOffset}"
let rNew := mkResultUniverse us rOffset
assignLevelMVar r.mvarId! rNew
indTypes.mapM fun indType => do
let type ← instantiateMVars indType.type
let ctors ← indType.ctors.mapM fun ctor => return { ctor with type := (← instantiateMVars ctor.type) }
return { indType with type, ctors }
register_builtin_option bootstrap.inductiveCheckResultingUniverse : Bool := {
defValue := true,
group := "bootstrap",
descr := "by default the `inductive/structure commands report an error if the resulting universe is not zero, but may be zero for some universe parameters. Reason: unless this type is a subsingleton, it is hardly what the user wants since it can only eliminate into `Prop`. In the `Init` package, we define subsingletons, and we use this option to disable the check. This option may be deleted in the future after we improve the validator"
}
def checkResultingUniverse (u : Level) : TermElabM Unit := do
if bootstrap.inductiveCheckResultingUniverse.get (← getOptions) then
let u ← instantiateLevelMVars u
if !u.isZero && !u.isNeverZero then
throwError "invalid universe polymorphic type, the resultant universe is not Prop (i.e., 0), but it may be Prop for some parameter values (solution: use 'u+1' or 'max 1 u'{indentD u}"
private def checkResultingUniverses (views : Array InductiveView) (numParams : Nat) (indTypes : List InductiveType) : TermElabM Unit := do
let u := (← instantiateLevelMVars (← getResultingUniverse indTypes)).normalize
checkResultingUniverse u
unless u.isZero do
indTypes.forM fun indType => indType.ctors.forM fun ctor =>
forallTelescopeReducing ctor.type fun ctorArgs _ => do
for ctorArg in ctorArgs[numParams:] do
let type ← inferType ctorArg
let v := (← instantiateLevelMVars (← getLevel type)).normalize
let rec check (v' : Level) (u' : Level) : TermElabM Unit :=
match v', u' with
| .succ v', .succ u' => check v' u'
| .mvar id, .param .. =>
/- Special case:
The constructor parameter `v` is at unverse level `?v+k` and
the resulting inductive universe level is `u'+k`, where `u'` is a parameter (or zero).
Thus, `?v := u'` is the only choice for satisfying the universe contraint `?v+k <= u'+k`.
Note that, we still generate an error for cases where there is more than one of satisfying the constraint.
Examples:
-----------------------------------------------------------
| ctor universe level | inductive datatype universe level |
-----------------------------------------------------------
| ?v | max u w |
-----------------------------------------------------------
| ?v | u + 1 |
-----------------------------------------------------------
-/
assignLevelMVar id u'
| .mvar id, .zero => assignLevelMVar id u' -- TODO: merge with previous case
| _, _ =>
unless u.geq v do
let mut msg := m!"invalid universe level in constructor '{ctor.name}', parameter"
let localDecl ← getFVarLocalDecl ctorArg
unless localDecl.userName.hasMacroScopes do
msg := msg ++ m!" '{ctorArg}'"
msg := msg ++ m!" has type{indentExpr type}"
msg := msg ++ m!"\nat universe level{indentD v}"
msg := msg ++ m!"\nit must be smaller than or equal to the inductive datatype universe level{indentD u}"
withCtorRef views ctor.name <| throwError msg
check v u
private def collectUsed (indTypes : List InductiveType) : StateRefT CollectFVars.State MetaM Unit := do
indTypes.forM fun indType => do
indType.type.collectFVars
indType.ctors.forM fun ctor =>
ctor.type.collectFVars
private def removeUnused (vars : Array Expr) (indTypes : List InductiveType) : TermElabM (LocalContext × LocalInstances × Array Expr) := do
let (_, used) ← (collectUsed indTypes).run {}
Meta.removeUnused vars used
private def withUsed {α} (vars : Array Expr) (indTypes : List InductiveType) (k : Array Expr → TermElabM α) : TermElabM α := do
let (lctx, localInsts, vars) ← removeUnused vars indTypes
withLCtx lctx localInsts <| k vars
private def updateParams (vars : Array Expr) (indTypes : List InductiveType) : TermElabM (List InductiveType) :=
indTypes.mapM fun indType => do
let type ← mkForallFVars vars indType.type
let ctors ← indType.ctors.mapM fun ctor => do
let ctorType ← withExplicitToImplicit vars (mkForallFVars vars ctor.type)
return { ctor with type := ctorType }
return { indType with type, ctors }
private def collectLevelParamsInInductive (indTypes : List InductiveType) : Array Name := Id.run do
let mut usedParams : CollectLevelParams.State := {}
for indType in indTypes do
usedParams := collectLevelParams usedParams indType.type
for ctor in indType.ctors do
usedParams := collectLevelParams usedParams ctor.type
return usedParams.params
private def mkIndFVar2Const (views : Array InductiveView) (indFVars : Array Expr) (levelNames : List Name) : ExprMap Expr := Id.run do
let levelParams := levelNames.map mkLevelParam;
let mut m : ExprMap Expr := {}
for i in [:views.size] do
let view := views[i]!
let indFVar := indFVars[i]!
m := m.insert indFVar (mkConst view.declName levelParams)
return m
/-- Remark: `numVars <= numParams`. `numVars` is the number of context `variables` used in the inductive declaration,
and `numParams` is `numVars` + number of explicit parameters provided in the declaration. -/
private def replaceIndFVarsWithConsts (views : Array InductiveView) (indFVars : Array Expr) (levelNames : List Name)
(numVars : Nat) (numParams : Nat) (indTypes : List InductiveType) : TermElabM (List InductiveType) :=
let indFVar2Const := mkIndFVar2Const views indFVars levelNames
indTypes.mapM fun indType => do
let ctors ← indType.ctors.mapM fun ctor => do
let type ← forallBoundedTelescope ctor.type numParams fun params type => do
let type := type.replace fun e =>
if !e.isFVar then
none
else match indFVar2Const.find? e with
| none => none
| some c => mkAppN c (params.extract 0 numVars)
instantiateMVars (← mkForallFVars params type)
return { ctor with type }
return { indType with ctors }
private def mkAuxConstructions (views : Array InductiveView) : TermElabM Unit := do
let env ← getEnv
let hasEq := env.contains ``Eq
let hasHEq := env.contains ``HEq
let hasUnit := env.contains ``PUnit
let hasProd := env.contains ``Prod
for view in views do
let n := view.declName
mkRecOn n
if hasUnit then mkCasesOn n
if hasUnit && hasEq && hasHEq then mkNoConfusion n
if hasUnit && hasProd then mkBelow n
if hasUnit && hasProd then mkIBelow n
for view in views do
let n := view.declName;
if hasUnit && hasProd then mkBRecOn n
if hasUnit && hasProd then mkBInductionOn n
private def getArity (indType : InductiveType) : MetaM Nat :=
forallTelescopeReducing indType.type fun xs _ => return xs.size
private def resetMaskAt (mask : Array Bool) (i : Nat) : Array Bool :=
if h : i < mask.size then
mask.set ⟨i, h⟩ false
else
mask
/--
Compute a bit-mask that for `indType`. The size of the resulting array `result` is the arity of `indType`.
The first `numParams` elements are `false` since they are parameters.
For `i ∈ [numParams, arity)`, we have that `result[i]` if this index of the inductive family is fixed.
-/
private def computeFixedIndexBitMask (numParams : Nat) (indType : InductiveType) (indFVars : Array Expr) : MetaM (Array Bool) := do
let arity ← getArity indType
if arity ≤ numParams then
return mkArray arity false
else
let maskRef ← IO.mkRef (mkArray numParams false ++ mkArray (arity - numParams) true)
let rec go (ctors : List Constructor) : MetaM (Array Bool) := do
match ctors with
| [] => maskRef.get
| ctor :: ctors =>
forallTelescopeReducing ctor.type fun xs type => do
let typeArgs := type.getAppArgs
for i in [numParams:arity] do
unless i < xs.size && xs[i]! == typeArgs[i]! do -- Remark: if we want to allow arguments to be rearranged, this test should be xs.contains typeArgs[i]
maskRef.modify fun mask => mask.set! i false
for x in xs[numParams:] do
let xType ← inferType x
let cond (e : Expr) := indFVars.any (fun indFVar => e.getAppFn == indFVar) && e.getAppNumArgs > numParams
xType.forEachWhere cond fun e => do
let eArgs := e.getAppArgs
for i in [numParams:eArgs.size] do
if i >= typeArgs.size then
maskRef.modify (resetMaskAt · i)
else
unless eArgs[i]! == typeArgs[i]! do
maskRef.modify (resetMaskAt · i)
go ctors
go indType.ctors
/-- Return true iff `arrowType` is an arrow and its domain is defeq to `type` -/
private def isDomainDefEq (arrowType : Expr) (type : Expr) : MetaM Bool := do
if !arrowType.isForall then
return false
else
/-
We used to use `withNewMCtxDepth` to make sure we do not assign universe metavariables,
but it was not satisfactory. For example, in declarations such as
```
inductive Eq : α → α → Prop where
| refl (a : α) : Eq a a
```
We want the first two indices to be promoted to parameters, and this will only
happen if we can assign universe metavariables.
-/
isDefEq arrowType.bindingDomain! type
/--
Convert fixed indices to parameters.
-/
private partial def fixedIndicesToParams (numParams : Nat) (indTypes : Array InductiveType) (indFVars : Array Expr) : MetaM Nat := do
let masks ← indTypes.mapM (computeFixedIndexBitMask numParams · indFVars)
if masks.all fun mask => !mask.contains true then
return numParams
trace[Elab.inductive] "masks: {masks}"
-- We process just a non-fixed prefix of the indices for now. Reason: we don't want to change the order.
-- TODO: extend it in the future. For example, it should be reasonable to change
-- the order of indices generated by the auto implicit feature.
let mask := masks[0]!
forallBoundedTelescope indTypes[0]!.type numParams fun params type => do
let otherTypes ← indTypes[1:].toArray.mapM fun indType => do whnfD (← instantiateForall indType.type params)
let ctorTypes ← indTypes.toList.mapM fun indType => indType.ctors.mapM fun ctor => do whnfD (← instantiateForall ctor.type params)
let typesToCheck := otherTypes.toList ++ ctorTypes.join
let rec go (i : Nat) (type : Expr) (typesToCheck : List Expr) : MetaM Nat := do
if i < mask.size then
if !masks.all fun mask => i < mask.size && mask[i]! then
return i
if !type.isForall then
return i
let paramType := type.bindingDomain!
if !(← typesToCheck.allM fun type => isDomainDefEq type paramType) then
trace[Elab.inductive] "domain not def eq: {i}, {type} =?= {paramType}"
return i
withLocalDeclD `a paramType fun paramNew => do
let typesToCheck ← typesToCheck.mapM fun type => whnfD (type.bindingBody!.instantiate1 paramNew)
go (i+1) (type.bindingBody!.instantiate1 paramNew) typesToCheck
else
return i
go numParams type typesToCheck
private def mkInductiveDecl (vars : Array Expr) (views : Array InductiveView) : TermElabM Unit := Term.withoutSavingRecAppSyntax do
let view0 := views[0]!
let scopeLevelNames ← Term.getLevelNames
checkLevelNames views
let allUserLevelNames := view0.levelNames
let isUnsafe := view0.modifiers.isUnsafe
withRef view0.ref <| Term.withLevelNames allUserLevelNames do
let rs ← elabHeader views
withInductiveLocalDecls rs fun params indFVars => do
trace[Elab.inductive] "indFVars: {indFVars}"
let mut indTypesArray := #[]
for i in [:views.size] do
let indFVar := indFVars[i]!
Term.addLocalVarInfo views[i]!.declId indFVar
let r := rs[i]!
let type ← mkForallFVars params r.type
let ctors ← withExplicitToImplicit params (elabCtors indFVars indFVar params r)
indTypesArray := indTypesArray.push { name := r.view.declName, type, ctors }
Term.synthesizeSyntheticMVarsNoPostponing
let numExplicitParams ← fixedIndicesToParams params.size indTypesArray indFVars
trace[Elab.inductive] "numExplicitParams: {numExplicitParams}"
let indTypes := indTypesArray.toList
let u ← getResultingUniverse indTypes
let univToInfer? ← shouldInferResultUniverse u
withUsed vars indTypes fun vars => do
let numVars := vars.size
let numParams := numVars + numExplicitParams
let indTypes ← updateParams vars indTypes
let indTypes ← if let some univToInfer := univToInfer? then
updateResultingUniverse views numParams (← levelMVarToParam indTypes univToInfer)
else
checkResultingUniverses views numParams indTypes
levelMVarToParam indTypes none
let usedLevelNames := collectLevelParamsInInductive indTypes
match sortDeclLevelParams scopeLevelNames allUserLevelNames usedLevelNames with
| .error msg => throwError msg
| .ok levelParams => do
let indTypes ← replaceIndFVarsWithConsts views indFVars levelParams numVars numParams indTypes
let decl := Declaration.inductDecl levelParams numParams indTypes isUnsafe
Term.ensureNoUnassignedMVars decl
addDecl decl
mkAuxConstructions views
withSaveInfoContext do -- save new env
for view in views do
Term.addTermInfo' view.ref[1] (← mkConstWithLevelParams view.declName) (isBinder := true)
for ctor in view.ctors do
Term.addTermInfo' ctor.ref[3] (← mkConstWithLevelParams ctor.declName) (isBinder := true)
-- We need to invoke `applyAttributes` because `class` is implemented as an attribute.
Term.applyAttributesAt view.declName view.modifiers.attrs .afterTypeChecking
private def applyDerivingHandlers (views : Array InductiveView) : CommandElabM Unit := do
let mut processed : NameSet := {}
for view in views do
for classView in view.derivingClasses do
let className := classView.className
unless processed.contains className do
processed := processed.insert className
let mut declNames := #[]
for view in views do
if view.derivingClasses.any fun classView => classView.className == className then
declNames := declNames.push view.declName
classView.applyHandlers declNames
private def applyComputedFields (indViews : Array InductiveView) : CommandElabM Unit := do
if indViews.all (·.computedFields.isEmpty) then return
let mut computedFields := #[]
let mut computedFieldDefs := #[]
for indView@{declName, ..} in indViews do
for {ref, fieldId, type, matchAlts, modifiers, ..} in indView.computedFields do
computedFieldDefs := computedFieldDefs.push <| ← do
let modifiers ← match modifiers with
| `(Lean.Parser.Command.declModifiersT| $[$doc:docComment]? $[$attrs:attributes]? $[$vis]? $[noncomputable]?) =>
`(Lean.Parser.Command.declModifiersT| $[$doc]? $[$attrs]? $[$vis]? noncomputable)
| _ => do
withRef modifiers do logError "unsupported modifiers for computed field"
`(Parser.Command.declModifiersT| noncomputable)
`($(⟨modifiers⟩):declModifiers
def%$ref $(mkIdent <| `_root_ ++ declName ++ fieldId):ident : $type $matchAlts:matchAlts)
let computedFieldNames := indView.computedFields.map fun {fieldId, ..} => declName ++ fieldId
computedFields := computedFields.push (declName, computedFieldNames)
withScope (fun scope => { scope with
opts := scope.opts
|>.setBool `bootstrap.genMatcherCode false
|>.setBool `elaboratingComputedFields true}) <|
elabCommand <| ← `(mutual $computedFieldDefs* end)
liftTermElabM do Term.withDeclName indViews[0]!.declName do
ComputedFields.setComputedFields computedFields
def elabInductiveViews (views : Array InductiveView) : CommandElabM Unit := do
let view0 := views[0]!
let ref := view0.ref
runTermElabM fun vars => Term.withDeclName view0.declName do withRef ref do
mkInductiveDecl vars views
mkSizeOfInstances view0.declName
Lean.Meta.IndPredBelow.mkBelow view0.declName
for view in views do
mkInjectiveTheorems view.declName
applyComputedFields views -- NOTE: any generated code before this line is invalid
applyDerivingHandlers views
runTermElabM fun _ => Term.withDeclName view0.declName do withRef ref do
for view in views do
Term.applyAttributesAt view.declName view.modifiers.attrs .afterCompilation
end Lean.Elab.Command
|
993c9111af8fd42c5d35053c1a8274b90df0e5b9 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/nat_bug4.lean | db3c094f3515a3d2a63711d339cb56beffdbf268 | [
"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 | 489 | lean | import logic
open eq.ops
namespace experiment
inductive nat : Type :=
| zero : nat
| succ : nat → nat
namespace nat
definition add (x y : nat) : nat := nat.rec x (λn r, succ r) y
infixl `+` := add
definition mul (n m : nat) := nat.rec zero (fun m x, x + n) m
infixl `*` := mul
axiom mul_succ_right (n m : nat) : n * succ m = n * m + n
open eq
theorem small2 (n m l : nat) : n * succ l + m = n * l + n + m
:= subst (mul_succ_right _ _) (eq.refl (n * succ l + m))
end nat
end experiment
|
33142eb589a5d6aa603a0c63b596619690364378 | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/tactic/equiv_rw.lean | cdb126215d85b48f1c747bc4d6fdc304ca716681 | [
"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 | 11,308 | 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.equiv_functor
/-!
# The `equiv_rw` tactic transports goals or hypotheses along equivalences.
The basic syntax is `equiv_rw e`, where `e : α ≃ β` is an equivalence.
This will try to replace occurrences of `α` in the goal with `β`, for example
transforming
* `⊢ α` to `⊢ β`,
* `⊢ option α` to `⊢ option β`
* `⊢ {a // P}` to `{b // P (⇑(equiv.symm e) b)}`
The tactic can also be used to rewrite hypotheses, using the syntax `equiv_rw e at h`.
## Implementation details
The main internal function is `equiv_rw_type e t`,
which attempts to turn an expression `e : α ≃ β` into a new equivalence with left hand side `t`.
As an example, with `t = option α`, it will generate `functor.map_equiv option e`.
This is achieved by generating a new synthetic goal `%%t ≃ _`,
and calling `solve_by_elim` with an appropriate set of congruence lemmas.
To avoid having to specify the relevant congruence lemmas by hand,
we mostly rely on `equiv_functor.map_equiv` and `bifunctor.map_equiv`
along with some structural congruence lemmas such as
* `equiv.arrow_congr'`,
* `equiv.subtype_equiv_of_subtype'`,
* `equiv.sigma_congr_left'`, and
* `equiv.Pi_congr_left'`.
The main `equiv_rw` function, when operating on the goal, simply generates a new equivalence `e'`
with left hand side matching the target, and calls `apply e'.inv_fun`.
When operating on a hypothesis `x : α`, we introduce a new fact `h : x = e.symm (e x)`,
revert this, and then attempt to `generalize`, replacing all occurrences of `e x` with a new constant `y`,
before `intro`ing and `subst`ing `h`, and renaming `y` back to `x`.
## Future improvements
In a future PR I anticipate that `derive equiv_functor` should work on many examples,
(internally using `transport`, which is in turn based on `equiv_rw`)
and we can incrementally bootstrap the strength of `equiv_rw`.
An ambitious project might be to add `equiv_rw!`,
a tactic which, when failing to find appropriate `equiv_functor` instances,
attempts to `derive` them on the spot.
For now `equiv_rw` is entirely based on `equiv`,
but the framework can readily be generalised to also work with other types of equivalences,
for example specific notations such as ring equivalence (`≃+*`),
or general categorical isomorphisms (`≅`).
This will allow us to transport across more general types of equivalences,
but this will wait for another subsequent PR.
-/
namespace tactic
/-- A list of lemmas used for constructing congruence equivalences. -/
-- Although this looks 'hard-coded', in fact the lemma `equiv_functor.map_equiv`
-- allows us to extend `equiv_rw` simply by constructing new instance so `equiv_functor`.
-- TODO: We should also use `category_theory.functorial` and `category_theory.hygienic` instances.
-- (example goal: we could rewrite along an isomorphism of rings (either as `R ≅ S` or `R ≃+* S`)
-- and turn an `x : mv_polynomial σ R` into an `x : mv_polynomial σ S`.).
meta def equiv_congr_lemmas : tactic (list expr) :=
do exprs ←
[
`equiv.of_iff,
-- TODO decide what to do with this; it's an equiv_bifunctor?
`equiv.equiv_congr,
-- The function arrow is technically a bifunctor `Typeᵒᵖ → Type → Type`,
-- but the pattern matcher will never see this.
`equiv.arrow_congr',
-- Allow rewriting in subtypes:
`equiv.subtype_equiv_of_subtype',
-- Allow rewriting in the first component of a sigma-type:
`equiv.sigma_congr_left',
-- Allow rewriting ∀s:
-- (You might think that repeated application of `equiv.forall_congr'
-- would handle the higher arity cases, but unfortunately unification is not clever enough.)
`equiv.forall₃_congr',
`equiv.forall₂_congr',
`equiv.forall_congr',
-- Allow rewriting in argument of Pi types:
`equiv.Pi_congr_left',
-- Handles `sum` and `prod`, and many others:
`bifunctor.map_equiv,
-- Handles `list`, `option`, `unique`, and many others:
`equiv_functor.map_equiv,
-- We have to filter results to ensure we don't cheat and use exclusively `equiv.refl` and `iff.refl`!
`equiv.refl,
`iff.refl
].mmap (λ n, try_core (mk_const n)),
return (exprs.map option.to_list).join -- TODO: implement `.mfilter_map mk_const`?
declare_trace equiv_rw_type
/--
Configuration structure for `equiv_rw`.
* `max_depth` bounds the search depth for equivalences to rewrite along.
The default value is 10.
(e.g., if you're rewriting along `e : α ≃ β`, and `max_depth := 2`,
you can rewrite `option (option α))` but not `option (option (option α))`.
-/
meta structure equiv_rw_cfg :=
(max_depth : ℕ := 10)
/--
Implementation of `equiv_rw_type`, using `solve_by_elim`.
Expects a goal of the form `t ≃ _`,
and tries to solve it using `eq : α ≃ β` and congruence lemmas.
-/
meta def equiv_rw_type_core (eq : expr) (cfg : equiv_rw_cfg) : tactic unit :=
do
-- Assemble the relevant lemmas.
equiv_congr_lemmas ← equiv_congr_lemmas,
/-
We now call `solve_by_elim` to try to generate the requested equivalence.
There are a few subtleties!
* We make sure that `eq` is the first lemma, so it is applied whenever possible.
* In `equiv_congr_lemmas`, we put `equiv.refl` last so it is only used when it is not possible
to descend further.
* Since some congruence lemmas generate subgoals with `∀` statements,
we use the `pre_apply` subtactic of `solve_by_elim` to preprocess each new goal with `intros`.
-/
solve_by_elim
{ use_symmetry := false,
use_exfalso := false,
lemmas := some (eq :: equiv_congr_lemmas),
max_depth := cfg.max_depth,
-- Subgoals may contain function types,
-- and we want to continue trying to construct equivalences after the binders.
pre_apply := tactic.intros >> skip,
-- If solve_by_elim gets stuck, make sure it isn't because there's a later `≃` or `↔` goal
-- that we should still attempt.
discharger := `[show _ ≃ _] <|> `[show _ ↔ _] <|>
trace_if_enabled `equiv_rw_type "Failed, no congruence lemma applied!" >> failed,
-- We use the `accept` tactic in `solve_by_elim` to provide tracing.
accept := λ goals, lock_tactic_state (do
when_tracing `equiv_rw_type (do
goals.mmap pp >>= λ goals, trace format!"So far, we've built: {goals}"),
done <|>
when_tracing `equiv_rw_type (do
gs ← get_goals,
gs ← gs.mmap (λ g, infer_type g >>= pp),
trace format!"Attempting to adapt to {gs}")) }
/--
`equiv_rw_type e t` rewrites the type `t` using the equivalence `e : α ≃ β`,
returning a new equivalence `t ≃ t'`.
-/
meta def equiv_rw_type (eqv : expr) (ty : expr) (cfg : equiv_rw_cfg) : tactic expr :=
do
when_tracing `equiv_rw_type (do
ty_pp ← pp ty,
eqv_pp ← pp eqv,
eqv_ty_pp ← infer_type eqv >>= pp,
trace format!"Attempting to rewrite the type `{ty_pp}` using `{eqv_pp} : {eqv_ty_pp}`."),
`(_ ≃ _) ← infer_type eqv | fail format!"{eqv} must be an `equiv`",
-- We prepare a synthetic goal of type `(%%ty ≃ _)`, for some placeholder right hand side.
equiv_ty ← to_expr ``(%%ty ≃ _),
-- Now call `equiv_rw_type_core`.
new_eqv ← prod.snd <$> (solve_aux equiv_ty $ equiv_rw_type_core eqv cfg),
-- Check that we actually used the equivalence `eq`
-- (`equiv_rw_type_core` will always find `equiv.refl`, but hopefully only after all other possibilities)
new_eqv ← instantiate_mvars new_eqv,
guard (eqv.occurs new_eqv) <|> (do
eqv_pp ← pp eqv,
ty_pp ← pp ty,
fail format!"Could not construct an equivalence from {eqv_pp} of the form: {ty_pp} ≃ _"),
-- Finally we simplify the resulting equivalence,
-- to compress away some `map_equiv equiv.refl` subexpressions.
prod.fst <$> new_eqv.simp {fail_if_unchanged := ff}
/--
Attempt to replace the hypothesis with name `x`
by transporting it along the equivalence in `e : α ≃ β`.
-/
meta def equiv_rw_hyp (x : name) (e : expr) (cfg : equiv_rw_cfg := {}) : tactic unit :=
do
x' ← get_local x,
x_ty ← infer_type x',
-- Adapt `e` to an equivalence with left-hand-sidee `x_ty`.
e ← equiv_rw_type e x_ty cfg,
eq ← to_expr ``(%%x' = equiv.symm %%e (equiv.to_fun %%e %%x')),
prf ← to_expr ``((equiv.symm_apply_apply %%e %%x').symm),
h ← assertv_fresh eq prf,
-- Revert the new hypothesis, so it is also part of the goal.
revert h,
ex ← to_expr ``(equiv.to_fun %%e %%x'),
-- Now call `generalize`,
-- attempting to replace all occurrences of `e x`,
-- calling it for now `j : β`, with `k : x = e.symm j`.
generalize ex (by apply_opt_param) transparency.none,
-- Reintroduce `x` (now of type `b`).
intro x,
k ← mk_fresh_name,
-- Finally, we subst along `k`, hopefully removing all the occurrences of the original `x`,
intro k >>= (λ k, subst k <|> unfreeze_local_instances >> subst k),
`[try { simp only [equiv.symm_symm, equiv.apply_symm_apply, equiv.symm_apply_apply] }],
skip
/-- Rewrite the goal using an equiv `e`. -/
meta def equiv_rw_target (e : expr) (cfg : equiv_rw_cfg := {}) : tactic unit :=
do
t ← target,
e ← equiv_rw_type e t cfg,
s ← to_expr ``(equiv.inv_fun %%e),
tactic.eapply s,
skip
end tactic
namespace tactic.interactive
open lean.parser
open interactive interactive.types
open tactic
local postfix `?`:9001 := optional
/--
`equiv_rw e at h`, where `h : α` is a hypothesis, and `e : α ≃ β`,
will attempt to transport `h` along `e`, producing a new hypothesis `h : β`,
with all occurrences of `h` in other hypotheses and the goal replaced with `e.symm h`.
`equiv_rw e` will attempt to transport the goal along an equivalence `e : α ≃ β`.
In its minimal form it replaces the goal `⊢ α` with `⊢ β` by calling `apply e.inv_fun`.
`equiv_rw` will also try rewriting under (equiv_)functors, so can turn
a hypothesis `h : list α` into `h : list β` or
a goal `⊢ unique α` into `⊢ unique β`.
The maximum search depth for rewriting in subexpressions is controlled by
`equiv_rw e {max_depth := n}`.
-/
meta def equiv_rw (e : parse texpr) (loc : parse $ (tk "at" *> ident)?) (cfg : equiv_rw_cfg := {}) : itactic :=
do e ← to_expr e,
match loc with
| (some hyp) := equiv_rw_hyp hyp e cfg
| none := equiv_rw_target e cfg
end
add_tactic_doc
{ name := "equiv_rw",
category := doc_category.tactic,
decl_names := [`tactic.interactive.equiv_rw],
tags := ["rewriting", "equiv", "transport"] }
/--
Solve a goal of the form `t ≃ _`,
by constructing an equivalence from `e : α ≃ β`.
This is the same equivalence that `equiv_rw` would use to rewrite a term of type `t`.
A typical usage might be:
```
have e' : option α ≃ option β := by equiv_rw_type e
```
-/
meta def equiv_rw_type (e : parse texpr) (cfg : equiv_rw_cfg := {}) : itactic :=
do
`(%%t ≃ _) ← target | fail "`equiv_rw_type` solves goals of the form `t ≃ _`.",
e ← to_expr e,
tactic.equiv_rw_type e t cfg >>= tactic.exact
add_tactic_doc
{ name := "equiv_rw_type",
category := doc_category.tactic,
decl_names := [`tactic.interactive.equiv_rw_type],
tags := ["rewriting", "equiv", "transport"] }
end tactic.interactive
|
346758bf274e65bd34bcd26c08381aa54ad7f414 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/data/setoid/partition.lean | 279e8a17421affc1bdcff102c7f56da18368db16 | [
"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 | 16,769 | lean | /-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Bryan Gin-ge Chen, Patrick Massot
-/
import data.fintype.basic
import data.set.finite
import data.setoid.basic
import order.partition.finpartition
/-!
# Equivalence relations: partitions
This file comprises properties of equivalence relations viewed as partitions.
There are two implementations of partitions here:
* A collection `c : set (set α)` of sets is a partition of `α` if `∅ ∉ c` and each element `a : α`
belongs to a unique set `b ∈ c`. This is expressed as `is_partition c`
* An indexed partition is a map `s : ι → α` whose image is a partition. This is
expressed as `indexed_partition s`.
Of course both implementations are related to `quotient` and `setoid`.
`setoid.is_partition.partition` and `finpartition.is_partition_parts` furnish
a link between `setoid.is_partition` and `finpartition`.
## TODO
Could the design of `finpartition` inform the one of `setoid.is_partition`? Maybe bundling it and
changing it from `set (set α)` to `set α` where `[lattice α] [order_bot α]` would make it more
usable.
## Tags
setoid, equivalence, iseqv, relation, equivalence relation, partition, equivalence class
-/
namespace setoid
variables {α : Type*}
/-- If x ∈ α is in 2 elements of a set of sets partitioning α, those 2 sets are equal. -/
lemma eq_of_mem_eqv_class {c : set (set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b)
{x b b'} (hc : b ∈ c) (hb : x ∈ b) (hc' : b' ∈ c) (hb' : x ∈ b') :
b = b' :=
(H x).unique2 hc hb hc' hb'
/-- Makes an equivalence relation from a set of sets partitioning α. -/
def mk_classes (c : set (set α)) (H : ∀ a, ∃! b ∈ c, a ∈ b) :
setoid α :=
⟨λ x y, ∀ s ∈ c, x ∈ s → y ∈ s, ⟨λ _ _ _ hx, hx,
λ x y h s hs hy, (H x).elim2 $ λ t ht hx _,
have s = t, from eq_of_mem_eqv_class H hs hy ht (h t ht hx),
this.symm ▸ hx,
λ x y z h1 h2 s hs hx, (H y).elim2 $ λ t ht hy _, (H z).elim2 $ λ t' ht' hz _,
have hst : s = t, from eq_of_mem_eqv_class H hs (h1 _ hs hx) ht hy,
have htt' : t = t', from eq_of_mem_eqv_class H ht (h2 _ ht hy) ht' hz,
(hst.trans htt').symm ▸ hz⟩⟩
/-- Makes the equivalence classes of an equivalence relation. -/
def classes (r : setoid α) : set (set α) :=
{s | ∃ y, s = {x | r.rel x y}}
lemma mem_classes (r : setoid α) (y) : {x | r.rel x y} ∈ r.classes := ⟨y, rfl⟩
lemma classes_ker_subset_fiber_set {β : Type*} (f : α → β) :
(setoid.ker f).classes ⊆ set.range (λ y, {x | f x = y}) :=
by { rintro s ⟨x, rfl⟩, rw set.mem_range, exact ⟨f x, rfl⟩ }
lemma nonempty_fintype_classes_ker {α β : Type*} [fintype β] (f : α → β) :
nonempty (fintype (setoid.ker f).classes) :=
by { classical, exact ⟨set.fintype_subset _ (classes_ker_subset_fiber_set f)⟩ }
lemma card_classes_ker_le {α β : Type*} [fintype β]
(f : α → β) [fintype (setoid.ker f).classes] :
fintype.card (setoid.ker f).classes ≤ fintype.card β :=
begin
classical,
exact le_trans (set.card_le_of_subset (classes_ker_subset_fiber_set f)) (fintype.card_range_le _)
end
/-- Two equivalence relations are equal iff all their equivalence classes are equal. -/
lemma eq_iff_classes_eq {r₁ r₂ : setoid α} :
r₁ = r₂ ↔ ∀ x, {y | r₁.rel x y} = {y | r₂.rel x y} :=
⟨λ h x, h ▸ rfl, λ h, ext' $ λ x, set.ext_iff.1 $ h x⟩
lemma rel_iff_exists_classes (r : setoid α) {x y} :
r.rel x y ↔ ∃ c ∈ r.classes, x ∈ c ∧ y ∈ c :=
⟨λ h, ⟨_, r.mem_classes y, h, r.refl' y⟩,
λ ⟨c, ⟨z, hz⟩, hx, hy⟩, by { subst c, exact r.trans' hx (r.symm' hy) }⟩
/-- Two equivalence relations are equal iff their equivalence classes are equal. -/
lemma classes_inj {r₁ r₂ : setoid α} :
r₁ = r₂ ↔ r₁.classes = r₂.classes :=
⟨λ h, h ▸ rfl, λ h, ext' $ λ a b, by simp only [rel_iff_exists_classes, exists_prop, h] ⟩
/-- The empty set is not an equivalence class. -/
lemma empty_not_mem_classes {r : setoid α} : ∅ ∉ r.classes :=
λ ⟨y, hy⟩, set.not_mem_empty y $ hy.symm ▸ r.refl' y
/-- Equivalence classes partition the type. -/
lemma classes_eqv_classes {r : setoid α} (a) : ∃! b ∈ r.classes, a ∈ b :=
exists_unique.intro2 {x | r.rel x a} (r.mem_classes a) (r.refl' _) $
begin
rintros _ ⟨y, rfl⟩ ha,
ext x,
exact ⟨λ hx, r.trans' hx (r.symm' ha), λ hx, r.trans' hx ha⟩
end
/-- If x ∈ α is in 2 equivalence classes, the equivalence classes are equal. -/
lemma eq_of_mem_classes {r : setoid α} {x b} (hc : b ∈ r.classes)
(hb : x ∈ b) {b'} (hc' : b' ∈ r.classes) (hb' : x ∈ b') : b = b' :=
eq_of_mem_eqv_class classes_eqv_classes hc hb hc' hb'
/-- The elements of a set of sets partitioning α are the equivalence classes of the
equivalence relation defined by the set of sets. -/
lemma eq_eqv_class_of_mem {c : set (set α)}
(H : ∀ a, ∃! b ∈ c, a ∈ b) {s y} (hs : s ∈ c) (hy : y ∈ s) :
s = {x | (mk_classes c H).rel x y} :=
set.ext $ λ x,
⟨λ hs', symm' (mk_classes c H) $ λ b' hb' h', eq_of_mem_eqv_class H hs hy hb' h' ▸ hs',
λ hx, (H x).elim2 $ λ b' hc' hb' h',
(eq_of_mem_eqv_class H hs hy hc' $ hx b' hc' hb').symm ▸ hb'⟩
/-- The equivalence classes of the equivalence relation defined by a set of sets
partitioning α are elements of the set of sets. -/
lemma eqv_class_mem {c : set (set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) {y} :
{x | (mk_classes c H).rel x y} ∈ c :=
(H y).elim2 $ λ b hc hy hb, eq_eqv_class_of_mem H hc hy ▸ hc
lemma eqv_class_mem' {c : set (set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) {x} :
{y : α | (mk_classes c H).rel x y} ∈ c :=
by { convert setoid.eqv_class_mem H, ext, rw setoid.comm' }
/-- Distinct elements of a set of sets partitioning α are disjoint. -/
lemma eqv_classes_disjoint {c : set (set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) :
c.pairwise_disjoint id :=
λ b₁ h₁ b₂ h₂ h, set.disjoint_left.2 $
λ x hx1 hx2, (H x).elim2 $ λ b hc hx hb, h $ eq_of_mem_eqv_class H h₁ hx1 h₂ hx2
/-- A set of disjoint sets covering α partition α (classical). -/
lemma eqv_classes_of_disjoint_union {c : set (set α)}
(hu : set.sUnion c = @set.univ α) (H : c.pairwise_disjoint id) (a) :
∃! b ∈ c, a ∈ b :=
let ⟨b, hc, ha⟩ := set.mem_sUnion.1 $ show a ∈ _, by rw hu; exact set.mem_univ a in
exists_unique.intro2 b hc ha $ λ b' hc' ha', H.elim_set hc' hc a ha' ha
/-- Makes an equivalence relation from a set of disjoints sets covering α. -/
def setoid_of_disjoint_union {c : set (set α)} (hu : set.sUnion c = @set.univ α)
(H : c.pairwise_disjoint id) : setoid α :=
setoid.mk_classes c $ eqv_classes_of_disjoint_union hu H
/-- The equivalence relation made from the equivalence classes of an equivalence
relation r equals r. -/
theorem mk_classes_classes (r : setoid α) :
mk_classes r.classes classes_eqv_classes = r :=
ext' $ λ x y, ⟨λ h, r.symm' (h {z | r.rel z x} (r.mem_classes x) $ r.refl' x),
λ h b hb hx, eq_of_mem_classes (r.mem_classes x) (r.refl' x) hb hx ▸ r.symm' h⟩
@[simp] theorem sUnion_classes (r : setoid α) : ⋃₀ r.classes = set.univ :=
set.eq_univ_of_forall $ λ x, set.mem_sUnion.2 ⟨{ y | r.rel y x }, ⟨x, rfl⟩, setoid.refl _⟩
section partition
/-- A collection `c : set (set α)` of sets is a partition of `α` into pairwise
disjoint sets if `∅ ∉ c` and each element `a : α` belongs to a unique set `b ∈ c`. -/
def is_partition (c : set (set α)) :=
∅ ∉ c ∧ ∀ a, ∃! b ∈ c, a ∈ b
/-- A partition of `α` does not contain the empty set. -/
lemma nonempty_of_mem_partition {c : set (set α)} (hc : is_partition c) {s} (h : s ∈ c) :
s.nonempty :=
set.ne_empty_iff_nonempty.1 $ λ hs0, hc.1 $ hs0 ▸ h
lemma is_partition_classes (r : setoid α) : is_partition r.classes :=
⟨empty_not_mem_classes, classes_eqv_classes⟩
lemma is_partition.pairwise_disjoint {c : set (set α)} (hc : is_partition c) :
c.pairwise_disjoint id :=
eqv_classes_disjoint hc.2
lemma is_partition.sUnion_eq_univ {c : set (set α)} (hc : is_partition c) :
⋃₀ c = set.univ :=
set.eq_univ_of_forall $ λ x, set.mem_sUnion.2 $
let ⟨t, ht⟩ := hc.2 x in ⟨t, by { simp only [exists_unique_iff_exists] at ht, tauto }⟩
/-- All elements of a partition of α are the equivalence class of some y ∈ α. -/
lemma exists_of_mem_partition {c : set (set α)} (hc : is_partition c) {s} (hs : s ∈ c) :
∃ y, s = {x | (mk_classes c hc.2).rel x y} :=
let ⟨y, hy⟩ := nonempty_of_mem_partition hc hs in
⟨y, eq_eqv_class_of_mem hc.2 hs hy⟩
/-- The equivalence classes of the equivalence relation defined by a partition of α equal
the original partition. -/
theorem classes_mk_classes (c : set (set α)) (hc : is_partition c) :
(mk_classes c hc.2).classes = c :=
set.ext $ λ s,
⟨λ ⟨y, hs⟩, (hc.2 y).elim2 $ λ b hm hb hy,
by rwa (show s = b, from hs.symm ▸ set.ext
(λ x, ⟨λ hx, symm' (mk_classes c hc.2) hx b hm hb,
λ hx b' hc' hx', eq_of_mem_eqv_class hc.2 hm hx hc' hx' ▸ hb⟩)),
exists_of_mem_partition hc⟩
/-- Defining `≤` on partitions as the `≤` defined on their induced equivalence relations. -/
instance partition.le : has_le (subtype (@is_partition α)) :=
⟨λ x y, mk_classes x.1 x.2.2 ≤ mk_classes y.1 y.2.2⟩
/-- Defining a partial order on partitions as the partial order on their induced
equivalence relations. -/
instance partition.partial_order : partial_order (subtype (@is_partition α)) :=
{ le := (≤),
lt := λ x y, x ≤ y ∧ ¬y ≤ x,
le_refl := λ _, @le_refl (setoid α) _ _,
le_trans := λ _ _ _, @le_trans (setoid α) _ _ _ _,
lt_iff_le_not_le := λ _ _, iff.rfl,
le_antisymm := λ x y hx hy, let h := @le_antisymm (setoid α) _ _ _ hx hy in by
rw [subtype.ext_iff_val, ←classes_mk_classes x.1 x.2, ←classes_mk_classes y.1 y.2, h] }
variables (α)
/-- The order-preserving bijection between equivalence relations on a type `α`, and
partitions of `α` into subsets. -/
protected def partition.order_iso :
setoid α ≃o {C : set (set α) // is_partition C} :=
{ to_fun := λ r, ⟨r.classes, empty_not_mem_classes, classes_eqv_classes⟩,
inv_fun := λ C, mk_classes C.1 C.2.2,
left_inv := mk_classes_classes,
right_inv := λ C, by rw [subtype.ext_iff_val, ←classes_mk_classes C.1 C.2],
map_rel_iff' := λ r s,
by { conv_rhs { rw [←mk_classes_classes r, ←mk_classes_classes s] }, refl } }
variables {α}
/-- A complete lattice instance for partitions; there is more infrastructure for the
equivalent complete lattice on equivalence relations. -/
instance partition.complete_lattice : complete_lattice (subtype (@is_partition α)) :=
galois_insertion.lift_complete_lattice $ @order_iso.to_galois_insertion
_ (subtype (@is_partition α)) _ (partial_order.to_preorder _) $ partition.order_iso α
end partition
/-- A finite setoid partition furnishes a finpartition -/
@[simps]
def is_partition.finpartition {c : finset (set α)}
(hc : setoid.is_partition (c : set (set α))) : finpartition (set.univ : set α) :=
{ parts := c,
sup_indep := finset.sup_indep_iff_pairwise_disjoint.mpr $ eqv_classes_disjoint hc.2,
sup_parts := c.sup_id_set_eq_sUnion.trans hc.sUnion_eq_univ,
not_bot_mem := hc.left }
end setoid
/-- A finpartition gives rise to a setoid partition -/
theorem finpartition.is_partition_parts {α} (f : finpartition (set.univ : set α)) :
setoid.is_partition (f.parts : set (set α)) :=
⟨f.not_bot_mem, setoid.eqv_classes_of_disjoint_union
(f.parts.sup_id_set_eq_sUnion.symm.trans f.sup_parts) f.sup_indep.pairwise_disjoint⟩
/-- Constructive information associated with a partition of a type `α` indexed by another type `ι`,
`s : ι → set α`.
`indexed_partition.index` sends an element to its index, while `indexed_partition.some` sends
an index to an element of the corresponding set.
This type is primarily useful for definitional control of `s` - if this is not needed, then
`setoid.ker index` by itself may be sufficient. -/
structure indexed_partition {ι α : Type*} (s : ι → set α) :=
(eq_of_mem : ∀ {x i j}, x ∈ s i → x ∈ s j → i = j)
(some : ι → α)
(some_mem : ∀ i, some i ∈ s i)
(index : α → ι)
(mem_index : ∀ x, x ∈ s (index x))
/-- The non-constructive constructor for `indexed_partition`. -/
noncomputable
def indexed_partition.mk' {ι α : Type*} (s : ι → set α) (dis : ∀ i j, i ≠ j → disjoint (s i) (s j))
(nonempty : ∀ i, (s i).nonempty) (ex : ∀ x, ∃ i, x ∈ s i) : indexed_partition s :=
{ eq_of_mem := λ x i j hxi hxj, classical.by_contradiction $ λ h, dis _ _ h ⟨hxi, hxj⟩,
some := λ i, (nonempty i).some,
some_mem := λ i, (nonempty i).some_spec,
index := λ x, (ex x).some,
mem_index := λ x, (ex x).some_spec }
namespace indexed_partition
open set
variables {ι α : Type*} {s : ι → set α} (hs : indexed_partition s)
/-- On a unique index set there is the obvious trivial partition -/
instance [unique ι] [inhabited α] :
inhabited (indexed_partition (λ i : ι, (set.univ : set α))) :=
⟨{ eq_of_mem := λ x i j hi hj, subsingleton.elim _ _,
some := default,
some_mem := set.mem_univ,
index := default,
mem_index := set.mem_univ }⟩
attribute [simp] some_mem mem_index
include hs
lemma exists_mem (x : α) : ∃ i, x ∈ s i := ⟨hs.index x, hs.mem_index x⟩
lemma Union : (⋃ i, s i) = univ :=
by { ext x, simp [hs.exists_mem x] }
lemma disjoint : ∀ {i j}, i ≠ j → disjoint (s i) (s j) :=
λ i j h x ⟨hxi, hxj⟩, h (hs.eq_of_mem hxi hxj)
lemma mem_iff_index_eq {x i} : x ∈ s i ↔ hs.index x = i :=
⟨λ hxi, (hs.eq_of_mem hxi (hs.mem_index x)).symm, λ h, h ▸ hs.mem_index _⟩
lemma eq (i) : s i = {x | hs.index x = i} :=
set.ext $ λ _, hs.mem_iff_index_eq
/-- The equivalence relation associated to an indexed partition. Two
elements are equivalent if they belong to the same set of the partition. -/
protected abbreviation setoid (hs : indexed_partition s) : setoid α :=
setoid.ker hs.index
@[simp] lemma index_some (i : ι) : hs.index (hs.some i) = i :=
(mem_iff_index_eq _).1 $ hs.some_mem i
lemma some_index (x : α) : hs.setoid.rel (hs.some (hs.index x)) x :=
hs.index_some (hs.index x)
/-- The quotient associated to an indexed partition. -/
protected def quotient := quotient hs.setoid
/-- The projection onto the quotient associated to an indexed partition. -/
def proj : α → hs.quotient := quotient.mk'
instance [inhabited α] : inhabited (hs.quotient) := ⟨hs.proj default⟩
lemma proj_eq_iff {x y : α} : hs.proj x = hs.proj y ↔ hs.index x = hs.index y :=
quotient.eq_rel
@[simp] lemma proj_some_index (x : α) : hs.proj (hs.some (hs.index x)) = hs.proj x :=
quotient.eq'.2 (hs.some_index x)
/-- The obvious equivalence between the quotient associated to an indexed partition and
the indexing type. -/
def equiv_quotient : ι ≃ hs.quotient :=
(setoid.quotient_ker_equiv_of_right_inverse hs.index hs.some $ hs.index_some).symm
@[simp] lemma equiv_quotient_index_apply (x : α) : hs.equiv_quotient (hs.index x) = hs.proj x :=
hs.proj_eq_iff.mpr (some_index hs x)
@[simp] lemma equiv_quotient_symm_proj_apply (x : α) :
hs.equiv_quotient.symm (hs.proj x) = hs.index x :=
rfl
lemma equiv_quotient_index : hs.equiv_quotient ∘ hs.index = hs.proj :=
funext hs.equiv_quotient_index_apply
/-- A map choosing a representative for each element of the quotient associated to an indexed
partition. This is a computable version of `quotient.out'` using `indexed_partition.some`. -/
def out : hs.quotient ↪ α :=
hs.equiv_quotient.symm.to_embedding.trans ⟨hs.some, function.left_inverse.injective hs.index_some⟩
/-- This lemma is analogous to `quotient.mk_out'`. -/
@[simp]
lemma out_proj (x : α) : hs.out (hs.proj x) = hs.some (hs.index x) :=
rfl
/-- The indices of `quotient.out'` and `indexed_partition.out` are equal. -/
lemma index_out' (x : hs.quotient) : hs.index (x.out') = hs.index (hs.out x) :=
quotient.induction_on' x $ λ x, (setoid.ker_apply_mk_out' x).trans (hs.index_some _).symm
/-- This lemma is analogous to `quotient.out_eq'`. -/
@[simp] lemma proj_out (x : hs.quotient) : hs.proj (hs.out x) = x :=
quotient.induction_on' x $ λ x, quotient.sound' $ hs.some_index x
lemma class_of {x : α} : set_of (hs.setoid.rel x) = s (hs.index x) :=
set.ext $ λ y, eq_comm.trans hs.mem_iff_index_eq.symm
lemma proj_fiber (x : hs.quotient) : hs.proj ⁻¹' {x} = s (hs.equiv_quotient.symm x) :=
quotient.induction_on' x $ λ x, begin
ext y,
simp only [set.mem_preimage, set.mem_singleton_iff, hs.mem_iff_index_eq],
exact quotient.eq',
end
end indexed_partition
|
6f90d24f46c7baa0506d174f9f71198fee550ed2 | efce24474b28579aba3272fdb77177dc2b11d7aa | /src/homotopy_theory/topological_spaces/disk_sphere.lean | 4ba24742a59db25356c26d96c5e008cae78f9a75 | [
"Apache-2.0"
] | permissive | rwbarton/lean-homotopy-theory | cff499f24268d60e1c546e7c86c33f58c62888ed | 39e1b4ea1ed1b0eca2f68bc64162dde6a6396dee | refs/heads/lean-3.4.2 | 1,622,711,883,224 | 1,598,550,958,000 | 1,598,550,958,000 | 136,023,667 | 12 | 6 | Apache-2.0 | 1,573,187,573,000 | 1,528,116,262,000 | Lean | UTF-8 | Lean | false | false | 1,191 | lean | import .pair
import .precofibration_category
noncomputable theory
namespace homotopy_theory.topological_spaces
open homotopy_theory.cylinder
-- (Provisional?) inductive definition of the disk/sphere pair using cubes.
def unit_pair : pair := pair.mk (*) ∅
def disk_sphere_pair (n : ℕ) : pair := nat.rec unit_pair (λ _ P, pair.prod P I_01) n
def disk (n : ℕ) : Top := (disk_sphere_pair n).space
def sphere_minus_one (n : ℕ) : Top := (disk_sphere_pair n).subspace
notation `D[` n `]` := disk n
notation `S[` n `-1]` := sphere_minus_one n
def sphere_disk_incl (n : ℕ) : S[n-1] ⟶ D[n] := pair.incl _
-- It's a cofibration.
lemma sphere_disk_closed : ∀ n, is_closed (disk_sphere_pair n).subset
| 0 := is_closed_empty
| (n+1) := pair.prod.is_closed (sphere_disk_closed n) I_01.is_closed
lemma sphere_disk_cofibered : ∀ n, (disk_sphere_pair n).cofibered
| 0 := pair.empty_cofibered _
| (n+1) := prod_I_01_cofibered _ (sphere_disk_closed n) (sphere_disk_cofibered n)
lemma sphere_disk_cofibration (n : ℕ) : closed_cofibration (sphere_disk_incl n) :=
closed_cofibration_incl_iff.mpr ⟨sphere_disk_cofibered n, sphere_disk_closed n⟩
end homotopy_theory.topological_spaces
|
4527daf2a021e4bfc4e87e9b7a8694d276216dfb | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/category/PartialFun.lean | bef9af2a87470ef3a9a3a562df0b0d13d96a5e43 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 6,376 | 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 category_theory.category.Pointed
import data.pfun
/-!
# The category of types with partial functions
This defines `PartialFun`, the category of types equipped with partial functions.
This category is classically equivalent to the category of pointed types. The reason it doesn't hold
constructively stems from the difference between `part` and `option`. Both can model partial
functions, but the latter forces a decidable domain.
Precisely, `PartialFun_to_Pointed` turns a partial function `α →. β` into a function
`option α → option β` by sending to `none` the undefined values (and `none` to `none`). But being
defined is (generally) undecidable while being sent to `none` is decidable. So it can't be
constructive.
## References
* [nLab, *The category of sets and partial functions*]
(https://ncatlab.org/nlab/show/partial+function)
-/
open category_theory option
universes u
variables {α β : Type*}
/-- The category of types equipped with partial functions. -/
def PartialFun : Type* := Type*
namespace PartialFun
instance : has_coe_to_sort PartialFun Type* := ⟨id⟩
/-- Turns a type into a `PartialFun`. -/
@[nolint has_nonempty_instance] def of : Type* → PartialFun := id
@[simp] lemma coe_of (X : Type*) : ↥(of X) = X := rfl
instance : inhabited PartialFun := ⟨Type*⟩
instance large_category : large_category.{u} PartialFun :=
{ hom := pfun,
id := pfun.id,
comp := λ X Y Z f g, g.comp f,
id_comp' := @pfun.comp_id,
comp_id' := @pfun.id_comp,
assoc' := λ W X Y Z _ _ _, (pfun.comp_assoc _ _ _).symm }
/-- Constructs a partial function isomorphism between types from an equivalence between them. -/
@[simps] def iso.mk {α β : PartialFun.{u}} (e : α ≃ β) : α ≅ β :=
{ hom := e,
inv := e.symm,
hom_inv_id' := (pfun.coe_comp _ _).symm.trans $ congr_arg coe e.symm_comp_self,
inv_hom_id' := (pfun.coe_comp _ _).symm.trans $ congr_arg coe e.self_comp_symm }
end PartialFun
/-- The forgetful functor from `Type` to `PartialFun` which forgets that the maps are total. -/
def Type_to_PartialFun : Type.{u} ⥤ PartialFun :=
{ obj := id,
map := @pfun.lift,
map_comp' := λ _ _ _ _ _, pfun.coe_comp _ _ }
instance : faithful Type_to_PartialFun := ⟨λ X Y, pfun.coe_injective⟩
/-- The functor which deletes the point of a pointed type. In return, this makes the maps partial.
This the computable part of the equivalence `PartialFun_equiv_Pointed`. -/
@[simps map] def Pointed_to_PartialFun : Pointed.{u} ⥤ PartialFun :=
{ obj := λ X, {x : X // x ≠ X.point},
map := λ X Y f, pfun.to_subtype _ f.to_fun ∘ subtype.val,
map_id' := λ X, pfun.ext $ λ a b,
pfun.mem_to_subtype_iff.trans (subtype.coe_inj.trans part.mem_some_iff.symm),
map_comp' := λ X Y Z f g, pfun.ext $ λ a c, begin
refine (pfun.mem_to_subtype_iff.trans _).trans part.mem_bind_iff.symm,
simp_rw [pfun.mem_to_subtype_iff, subtype.exists],
refine ⟨λ h, ⟨f.to_fun a, λ ha, c.2 $ h.trans
((congr_arg g.to_fun ha : g.to_fun _ = _).trans g.map_point), rfl, h⟩, _⟩,
rintro ⟨b, _, (rfl : b = _), h⟩,
exact h,
end }
/-- The functor which maps undefined values to a new point. This makes the maps total and creates
pointed types. This the noncomputable part of the equivalence `PartialFun_equiv_Pointed`. It can't
be computable because `= option.none` is decidable while the domain of a general `part` isn't. -/
@[simps map] noncomputable def PartialFun_to_Pointed : PartialFun ⥤ Pointed :=
by classical; exact
{ obj := λ X, ⟨option X, none⟩,
map := λ X Y f, ⟨option.elim none (λ a, (f a).to_option), rfl⟩,
map_id' := λ X, Pointed.hom.ext _ _ $ funext $ λ o,
option.rec_on o rfl $ λ a, part.some_to_option _,
map_comp' := λ X Y Z f g, Pointed.hom.ext _ _ $ funext $ λ o, option.rec_on o rfl $ λ a,
part.bind_to_option _ _ }
/-- The equivalence induced by `PartialFun_to_Pointed` and `Pointed_to_PartialFun`.
`part.equiv_option` made functorial. -/
@[simps] noncomputable def PartialFun_equiv_Pointed : PartialFun.{u} ≌ Pointed :=
by classical; exact
equivalence.mk PartialFun_to_Pointed Pointed_to_PartialFun
(nat_iso.of_components (λ X, PartialFun.iso.mk
{ to_fun := λ a, ⟨some a, some_ne_none a⟩,
inv_fun := λ a, get $ ne_none_iff_is_some.1 a.2,
left_inv := λ a, get_some _ _,
right_inv := λ a, by simp only [subtype.val_eq_coe, some_get, subtype.coe_eta] }) $ λ X Y f,
pfun.ext $ λ a b, begin
unfold_projs,
dsimp,
rw part.bind_some,
refine (part.mem_bind_iff.trans _).trans pfun.mem_to_subtype_iff.symm,
obtain ⟨b | b, hb⟩ := b,
{ exact (hb rfl).elim },
dsimp,
simp_rw [part.mem_some_iff, subtype.mk_eq_mk, exists_prop, some_inj, exists_eq_right'],
refine part.mem_to_option.symm.trans _,
exact eq_comm,
end)
(nat_iso.of_components (λ X, Pointed.iso.mk
{ to_fun := option.elim X.point subtype.val,
inv_fun := λ a, if h : a = X.point then none else some ⟨_, h⟩,
left_inv := λ a, option.rec_on a (dif_pos rfl) $ λ a, (dif_neg a.2).trans $
by simp only [option.elim, subtype.val_eq_coe, subtype.coe_eta],
right_inv := λ a, begin
change option.elim _ _ (dite _ _ _) = _,
split_ifs,
{ rw h, refl },
{ refl }
end } rfl) $ λ X Y f, Pointed.hom.ext _ _ $ funext $ λ a, option.rec_on a f.map_point.symm $
λ a, begin
unfold_projs,
dsimp,
change option.elim _ _ _ = _,
rw part.elim_to_option,
split_ifs,
{ refl },
{ exact eq.symm (of_not_not h) }
end)
/-- Forgetting that maps are total and making them total again by adding a point is the same as just
adding a point. -/
@[simps] noncomputable def Type_to_PartialFun_iso_PartialFun_to_Pointed :
Type_to_PartialFun ⋙ PartialFun_to_Pointed ≅ Type_to_Pointed :=
nat_iso.of_components (λ X, { hom := ⟨id, rfl⟩,
inv := ⟨id, rfl⟩,
hom_inv_id' := rfl,
inv_hom_id' := rfl }) $ λ X Y f,
Pointed.hom.ext _ _ $ funext $ λ a, option.rec_on a rfl $ λ a, by convert part.some_to_option _
|
10662b4f4681196be59d09fc42dc1ef07f4aadc5 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/set/pairwise.lean | 251ba470614af63266e82647be2c669fa21deb7a | [
"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 | 17,116 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import logic.relation
import logic.pairwise
import data.set.lattice
/-!
# Relations holding pairwise
This file develops pairwise relations and defines pairwise disjoint indexed sets.
We also prove many basic facts about `pairwise`. It is possible that an intermediate file,
with more imports than `logic.pairwise` but not importing `data.set.lattice` would be appropriate
to hold many of these basic facts.
## Main declarations
* `set.pairwise_disjoint`: `s.pairwise_disjoint f` states that images under `f` of distinct elements
of `s` are either equal or `disjoint`.
## Notes
The spelling `s.pairwise_disjoint id` is preferred over `s.pairwise disjoint` to permit dot notation
on `set.pairwise_disjoint`, even though the latter unfolds to something nicer.
-/
open set function
variables {α β γ ι ι' : Type*} {r p q : α → α → Prop}
section pairwise
variables {f g : ι → α} {s t u : set α} {a b : α}
lemma pairwise_on_bool (hr : symmetric r) {a b : α} : pairwise (r on (λ c, cond c a b)) ↔ r a b :=
by simpa [pairwise, function.on_fun] using @hr a b
lemma pairwise_disjoint_on_bool [semilattice_inf α] [order_bot α] {a b : α} :
pairwise (disjoint on (λ c, cond c a b)) ↔ disjoint a b :=
pairwise_on_bool disjoint.symm
lemma symmetric.pairwise_on [linear_order ι] (hr : symmetric r) (f : ι → α) :
pairwise (r on f) ↔ ∀ ⦃m n⦄, m < n → r (f m) (f n) :=
⟨λ h m n hmn, h hmn.ne, λ h m n hmn, hmn.lt_or_lt.elim (@h _ _) (λ h', hr (h h'))⟩
lemma pairwise_disjoint_on [semilattice_inf α] [order_bot α] [linear_order ι] (f : ι → α) :
pairwise (disjoint on f) ↔ ∀ ⦃m n⦄, m < n → disjoint (f m) (f n) :=
symmetric.pairwise_on disjoint.symm f
lemma pairwise_disjoint.mono [semilattice_inf α] [order_bot α]
(hs : pairwise (disjoint on f)) (h : g ≤ f) : pairwise (disjoint on g) :=
hs.mono (λ i j hij, disjoint.mono (h i) (h j) hij)
alias function.injective_iff_pairwise_ne ↔ function.injective.pairwise_ne _
namespace set
lemma pairwise.mono (h : t ⊆ s) (hs : s.pairwise r) : t.pairwise r :=
λ x xt y yt, hs (h xt) (h yt)
lemma pairwise.mono' (H : r ≤ p) (hr : s.pairwise r) : s.pairwise p := hr.imp H
lemma pairwise_top (s : set α) : s.pairwise ⊤ := pairwise_of_forall s _ (λ a b, trivial)
protected lemma subsingleton.pairwise (h : s.subsingleton) (r : α → α → Prop) :
s.pairwise r :=
λ x hx y hy hne, (hne (h hx hy)).elim
@[simp] lemma pairwise_empty (r : α → α → Prop) : (∅ : set α).pairwise r :=
subsingleton_empty.pairwise r
@[simp] lemma pairwise_singleton (a : α) (r : α → α → Prop) : set.pairwise {a} r :=
subsingleton_singleton.pairwise r
lemma pairwise_iff_of_refl [is_refl α r] : s.pairwise r ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → r a b :=
forall₄_congr $ λ a _ b _, or_iff_not_imp_left.symm.trans $ or_iff_right_of_imp of_eq
alias pairwise_iff_of_refl ↔ pairwise.of_refl _
lemma nonempty.pairwise_iff_exists_forall [is_equiv α r] {s : set ι} (hs : s.nonempty) :
(s.pairwise (r on f)) ↔ ∃ z, ∀ x ∈ s, r (f x) z :=
begin
fsplit,
{ rcases hs with ⟨y, hy⟩,
refine λ H, ⟨f y, λ x hx, _⟩,
rcases eq_or_ne x y with rfl|hne,
{ apply is_refl.refl },
{ exact H hx hy hne } },
{ rintro ⟨z, hz⟩ x hx y hy hne,
exact @is_trans.trans α r _ (f x) z (f y) (hz _ hx) (is_symm.symm _ _ $ hz _ hy) }
end
/-- For a nonempty set `s`, a function `f` takes pairwise equal values on `s` if and only if
for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also
`set.pairwise_eq_iff_exists_eq` for a version that assumes `[nonempty ι]` instead of
`set.nonempty s`. -/
lemma nonempty.pairwise_eq_iff_exists_eq {s : set α} (hs : s.nonempty) {f : α → ι} :
(s.pairwise (λ x y, f x = f y)) ↔ ∃ z, ∀ x ∈ s, f x = z :=
hs.pairwise_iff_exists_forall
lemma pairwise_iff_exists_forall [nonempty ι] (s : set α) (f : α → ι) {r : ι → ι → Prop}
[is_equiv ι r] :
(s.pairwise (r on f)) ↔ ∃ z, ∀ x ∈ s, r (f x) z :=
begin
rcases s.eq_empty_or_nonempty with rfl|hne,
{ simp },
{ exact hne.pairwise_iff_exists_forall }
end
/-- A function `f : α → ι` with nonempty codomain takes pairwise equal values on a set `s` if and
only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also
`set.nonempty.pairwise_eq_iff_exists_eq` for a version that assumes `set.nonempty s` instead of
`[nonempty ι]`. -/
lemma pairwise_eq_iff_exists_eq [nonempty ι] (s : set α) (f : α → ι) :
(s.pairwise (λ x y, f x = f y)) ↔ ∃ z, ∀ x ∈ s, f x = z :=
pairwise_iff_exists_forall s f
lemma pairwise_union :
(s ∪ t).pairwise r ↔
s.pairwise r ∧ t.pairwise r ∧ ∀ (a ∈ s) (b ∈ t), a ≠ b → r a b ∧ r b a :=
begin
simp only [set.pairwise, mem_union, or_imp_distrib, forall_and_distrib],
exact ⟨λ H, ⟨H.1.1, H.2.2, H.2.1, λ x hx y hy hne, H.1.2 y hy x hx hne.symm⟩,
λ H, ⟨⟨H.1, λ x hx y hy hne, H.2.2.2 y hy x hx hne.symm⟩, H.2.2.1, H.2.1⟩⟩
end
lemma pairwise_union_of_symmetric (hr : symmetric r) :
(s ∪ t).pairwise r ↔
s.pairwise r ∧ t.pairwise r ∧ ∀ (a ∈ s) (b ∈ t), a ≠ b → r a b :=
pairwise_union.trans $ by simp only [hr.iff, and_self]
lemma pairwise_insert :
(insert a s).pairwise r ↔ s.pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b ∧ r b a :=
by simp only [insert_eq, pairwise_union, pairwise_singleton, true_and,
mem_singleton_iff, forall_eq]
lemma pairwise.insert (hs : s.pairwise r) (h : ∀ b ∈ s, a ≠ b → r a b ∧ r b a) :
(insert a s).pairwise r :=
pairwise_insert.2 ⟨hs, h⟩
lemma pairwise_insert_of_symmetric (hr : symmetric r) :
(insert a s).pairwise r ↔ s.pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b :=
by simp only [pairwise_insert, hr.iff a, and_self]
lemma pairwise.insert_of_symmetric (hs : s.pairwise r) (hr : symmetric r)
(h : ∀ b ∈ s, a ≠ b → r a b) :
(insert a s).pairwise r :=
(pairwise_insert_of_symmetric hr).2 ⟨hs, h⟩
lemma pairwise_pair : set.pairwise {a, b} r ↔ (a ≠ b → r a b ∧ r b a) :=
by simp [pairwise_insert]
lemma pairwise_pair_of_symmetric (hr : symmetric r) : set.pairwise {a, b} r ↔ (a ≠ b → r a b) :=
by simp [pairwise_insert_of_symmetric hr]
lemma pairwise_univ : (univ : set α).pairwise r ↔ pairwise r :=
by simp only [set.pairwise, pairwise, mem_univ, forall_const]
@[simp] lemma pairwise_bot_iff : s.pairwise (⊥ : α → α → Prop) ↔ (s : set α).subsingleton :=
⟨λ h a ha b hb, h.eq ha hb id, λ h, h.pairwise _⟩
alias pairwise_bot_iff ↔ pairwise.subsingleton _
lemma inj_on.pairwise_image {s : set ι} (h : s.inj_on f) :
(f '' s).pairwise r ↔ s.pairwise (r on f) :=
by simp [h.eq_iff, set.pairwise] {contextual := tt}
lemma pairwise_Union {f : ι → set α} (h : directed (⊆) f) :
(⋃ n, f n).pairwise r ↔ ∀ n, (f n).pairwise r :=
begin
split,
{ assume H n,
exact pairwise.mono (subset_Union _ _) H },
{ assume H i hi j hj hij,
rcases mem_Union.1 hi with ⟨m, hm⟩,
rcases mem_Union.1 hj with ⟨n, hn⟩,
rcases h m n with ⟨p, mp, np⟩,
exact H p (mp hm) (np hn) hij }
end
lemma pairwise_sUnion {r : α → α → Prop} {s : set (set α)} (h : directed_on (⊆) s) :
(⋃₀ s).pairwise r ↔ (∀ a ∈ s, set.pairwise a r) :=
by { rw [sUnion_eq_Union, pairwise_Union (h.directed_coe), set_coe.forall], refl }
end set
end pairwise
lemma pairwise_subtype_iff_pairwise_set (s : set α) (r : α → α → Prop) :
pairwise (λ (x : s) (y : s), r x y) ↔ s.pairwise r :=
by simp only [pairwise, set.pairwise, set_coe.forall, ne.def, subtype.ext_iff, subtype.coe_mk]
alias pairwise_subtype_iff_pairwise_set ↔ pairwise.set_of_subtype set.pairwise.subtype
namespace set
section partial_order_bot
variables [partial_order α] [order_bot α] {s t : set ι} {f g : ι → α}
/-- A set is `pairwise_disjoint` under `f`, if the images of any distinct two elements under `f`
are disjoint.
`s.pairwise disjoint` is (definitionally) the same as `s.pairwise_disjoint id`. We prefer the latter
in order to allow dot notation on `set.pairwise_disjoint`, even though the former unfolds more
nicely. -/
def pairwise_disjoint (s : set ι) (f : ι → α) : Prop := s.pairwise (disjoint on f)
lemma pairwise_disjoint.subset (ht : t.pairwise_disjoint f) (h : s ⊆ t) : s.pairwise_disjoint f :=
pairwise.mono h ht
lemma pairwise_disjoint.mono_on (hs : s.pairwise_disjoint f) (h : ∀ ⦃i⦄, i ∈ s → g i ≤ f i) :
s.pairwise_disjoint g :=
λ a ha b hb hab, (hs ha hb hab).mono (h ha) (h hb)
lemma pairwise_disjoint.mono (hs : s.pairwise_disjoint f) (h : g ≤ f) : s.pairwise_disjoint g :=
hs.mono_on (λ i _, h i)
@[simp] lemma pairwise_disjoint_empty : (∅ : set ι).pairwise_disjoint f := pairwise_empty _
@[simp] lemma pairwise_disjoint_singleton (i : ι) (f : ι → α) : pairwise_disjoint {i} f :=
pairwise_singleton i _
lemma pairwise_disjoint_insert {i : ι} :
(insert i s).pairwise_disjoint f
↔ s.pairwise_disjoint f ∧ ∀ j ∈ s, i ≠ j → disjoint (f i) (f j) :=
set.pairwise_insert_of_symmetric $ symmetric_disjoint.comap f
lemma pairwise_disjoint.insert (hs : s.pairwise_disjoint f) {i : ι}
(h : ∀ j ∈ s, i ≠ j → disjoint (f i) (f j)) :
(insert i s).pairwise_disjoint f :=
set.pairwise_disjoint_insert.2 ⟨hs, h⟩
lemma pairwise_disjoint.image_of_le (hs : s.pairwise_disjoint f) {g : ι → ι} (hg : f ∘ g ≤ f) :
(g '' s).pairwise_disjoint f :=
begin
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ h,
exact (hs ha hb $ ne_of_apply_ne _ h).mono (hg a) (hg b),
end
lemma inj_on.pairwise_disjoint_image {g : ι' → ι} {s : set ι'} (h : s.inj_on g) :
(g '' s).pairwise_disjoint f ↔ s.pairwise_disjoint (f ∘ g) :=
h.pairwise_image
lemma pairwise_disjoint.range (g : s → ι) (hg : ∀ (i : s), f (g i) ≤ f i)
(ht : s.pairwise_disjoint f) :
(range g).pairwise_disjoint f :=
begin
rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ hxy,
exact (ht x.2 y.2 $ λ h, hxy $ congr_arg g $ subtype.ext h).mono (hg x) (hg y),
end
lemma pairwise_disjoint_union :
(s ∪ t).pairwise_disjoint f ↔ s.pairwise_disjoint f ∧ t.pairwise_disjoint f ∧
∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ t → i ≠ j → disjoint (f i) (f j) :=
pairwise_union_of_symmetric $ symmetric_disjoint.comap f
lemma pairwise_disjoint.union (hs : s.pairwise_disjoint f) (ht : t.pairwise_disjoint f)
(h : ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ t → i ≠ j → disjoint (f i) (f j)) :
(s ∪ t).pairwise_disjoint f :=
pairwise_disjoint_union.2 ⟨hs, ht, h⟩
lemma pairwise_disjoint_Union {g : ι' → set ι} (h : directed (⊆) g) :
(⋃ n, g n).pairwise_disjoint f ↔ ∀ ⦃n⦄, (g n).pairwise_disjoint f :=
pairwise_Union h
lemma pairwise_disjoint_sUnion {s : set (set ι)} (h : directed_on (⊆) s) :
(⋃₀ s).pairwise_disjoint f ↔ ∀ ⦃a⦄, a ∈ s → set.pairwise_disjoint a f :=
pairwise_sUnion h
-- classical
lemma pairwise_disjoint.elim (hs : s.pairwise_disjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s)
(h : ¬ disjoint (f i) (f j)) :
i = j :=
hs.eq hi hj h
end partial_order_bot
section semilattice_inf_bot
variables [semilattice_inf α] [order_bot α] {s t : set ι} {f g : ι → α}
-- classical
lemma pairwise_disjoint.elim' (hs : s.pairwise_disjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s)
(h : f i ⊓ f j ≠ ⊥) :
i = j :=
hs.elim hi hj $ λ hij, h hij.eq_bot
lemma pairwise_disjoint.eq_of_le (hs : s.pairwise_disjoint f) {i j : ι} (hi : i ∈ s) (hj : j ∈ s)
(hf : f i ≠ ⊥) (hij : f i ≤ f j) :
i = j :=
hs.elim' hi hj $ λ h, hf $ (inf_of_le_left hij).symm.trans h
end semilattice_inf_bot
section complete_lattice
variables [complete_lattice α]
/-- Bind operation for `set.pairwise_disjoint`. If you want to only consider finsets of indices, you
can use `set.pairwise_disjoint.bUnion_finset`. -/
lemma pairwise_disjoint.bUnion {s : set ι'} {g : ι' → set ι} {f : ι → α}
(hs : s.pairwise_disjoint (λ i' : ι', ⨆ i ∈ g i', f i))
(hg : ∀ i ∈ s, (g i).pairwise_disjoint f) :
(⋃ i ∈ s, g i).pairwise_disjoint f :=
begin
rintro a ha b hb hab,
simp_rw set.mem_Union at ha hb,
obtain ⟨c, hc, ha⟩ := ha,
obtain ⟨d, hd, hb⟩ := hb,
obtain hcd | hcd := eq_or_ne (g c) (g d),
{ exact hg d hd (hcd.subst ha) hb hab },
{ exact (hs hc hd $ ne_of_apply_ne _ hcd).mono (le_supr₂ a ha) (le_supr₂ b hb) }
end
end complete_lattice
/-! ### Pairwise disjoint set of sets -/
lemma pairwise_disjoint_range_singleton :
(set.range (singleton : ι → set ι)).pairwise_disjoint id :=
begin
rintro _ ⟨a, rfl⟩ _ ⟨b, rfl⟩ h,
exact disjoint_singleton.2 (ne_of_apply_ne _ h),
end
lemma pairwise_disjoint_fiber (f : ι → α) (s : set α) : s.pairwise_disjoint (λ a, f ⁻¹' {a}) :=
λ a _ b _ h, disjoint_iff_inf_le.mpr $ λ i ⟨hia, hib⟩, h $ (eq.symm hia).trans hib
-- classical
lemma pairwise_disjoint.elim_set {s : set ι} {f : ι → set α} (hs : s.pairwise_disjoint f) {i j : ι}
(hi : i ∈ s) (hj : j ∈ s) (a : α) (hai : a ∈ f i) (haj : a ∈ f j) : i = j :=
hs.elim hi hj $ not_disjoint_iff.2 ⟨a, hai, haj⟩
lemma bUnion_diff_bUnion_eq {s t : set ι} {f : ι → set α} (h : (s ∪ t).pairwise_disjoint f) :
(⋃ i ∈ s, f i) \ (⋃ i ∈ t, f i) = (⋃ i ∈ s \ t, f i) :=
begin
refine (bUnion_diff_bUnion_subset f s t).antisymm
(Union₂_subset $ λ i hi a ha, (mem_diff _).2 ⟨mem_bUnion hi.1 ha, _⟩),
rw mem_Union₂, rintro ⟨j, hj, haj⟩,
exact (h (or.inl hi.1) (or.inr hj) (ne_of_mem_of_not_mem hj hi.2).symm).le_bot ⟨ha, haj⟩,
end
/-- Equivalence between a disjoint bounded union and a dependent sum. -/
noncomputable def bUnion_eq_sigma_of_disjoint {s : set ι} {f : ι → set α}
(h : s.pairwise_disjoint f) :
(⋃ i ∈ s, f i) ≃ (Σ i : s, f i) :=
(equiv.set_congr (bUnion_eq_Union _ _)).trans $ Union_eq_sigma_of_disjoint $
λ ⟨i, hi⟩ ⟨j, hj⟩ ne, h hi hj $ λ eq, ne $ subtype.eq eq
/-- The partial images of a binary function `f` whose partial evaluations are injective are pairwise
disjoint iff `f` is injective . -/
lemma pairwise_disjoint_image_right_iff {f : α → β → γ} {s : set α} {t : set β}
(hf : ∀ a ∈ s, injective (f a)) :
s.pairwise_disjoint (λ a, f a '' t) ↔ (s ×ˢ t).inj_on (λ p, f p.1 p.2) :=
begin
refine ⟨λ hs x hx y hy (h : f _ _ = _), _, λ hs x hx y hy h, _⟩,
{ suffices : x.1 = y.1,
{ exact prod.ext this (hf _ hx.1 $ h.trans $ by rw this) },
refine hs.elim hx.1 hy.1 (not_disjoint_iff.2 ⟨_, mem_image_of_mem _ hx.2, _⟩),
rw h,
exact mem_image_of_mem _ hy.2 },
{ refine disjoint_iff_inf_le.mpr _,
rintro _ ⟨⟨a, ha, hab⟩, b, hb, rfl⟩,
exact h (congr_arg prod.fst $ hs (mk_mem_prod hx ha) (mk_mem_prod hy hb) hab) }
end
/-- The partial images of a binary function `f` whose partial evaluations are injective are pairwise
disjoint iff `f` is injective . -/
lemma pairwise_disjoint_image_left_iff {f : α → β → γ} {s : set α} {t : set β}
(hf : ∀ b ∈ t, injective (λ a, f a b)) :
t.pairwise_disjoint (λ b, (λ a, f a b) '' s) ↔ (s ×ˢ t).inj_on (λ p, f p.1 p.2) :=
begin
refine ⟨λ ht x hx y hy (h : f _ _ = _), _, λ ht x hx y hy h, _⟩,
{ suffices : x.2 = y.2,
{ exact prod.ext (hf _ hx.2 $ h.trans $ by rw this) this },
refine ht.elim hx.2 hy.2 (not_disjoint_iff.2 ⟨_, mem_image_of_mem _ hx.1, _⟩),
rw h,
exact mem_image_of_mem _ hy.1 },
{ refine disjoint_iff_inf_le.mpr _,
rintro _ ⟨⟨a, ha, hab⟩, b, hb, rfl⟩,
exact h (congr_arg prod.snd $ ht (mk_mem_prod ha hx) (mk_mem_prod hb hy) hab) }
end
end set
lemma pairwise_disjoint_fiber (f : ι → α) : pairwise (disjoint on (λ a : α, f ⁻¹' {a})) :=
set.pairwise_univ.1 $ set.pairwise_disjoint_fiber f univ
section
variables {f : ι → set α} {s t : set ι}
lemma set.pairwise_disjoint.subset_of_bUnion_subset_bUnion (h₀ : (s ∪ t).pairwise_disjoint f)
(h₁ : ∀ i ∈ s, (f i).nonempty) (h : (⋃ i ∈ s, f i) ⊆ ⋃ i ∈ t, f i) :
s ⊆ t :=
begin
rintro i hi,
obtain ⟨a, hai⟩ := h₁ i hi,
obtain ⟨j, hj, haj⟩ := mem_Union₂.1 (h $ mem_Union₂_of_mem hi hai),
rwa h₀.eq (subset_union_left _ _ hi) (subset_union_right _ _ hj)
(not_disjoint_iff.2 ⟨a, hai, haj⟩),
end
lemma pairwise.subset_of_bUnion_subset_bUnion (h₀ : pairwise (disjoint on f))
(h₁ : ∀ i ∈ s, (f i).nonempty) (h : (⋃ i ∈ s, f i) ⊆ ⋃ i ∈ t, f i) :
s ⊆ t :=
set.pairwise_disjoint.subset_of_bUnion_subset_bUnion (h₀.set_pairwise _) h₁ h
lemma pairwise.bUnion_injective (h₀ : pairwise (disjoint on f)) (h₁ : ∀ i, (f i).nonempty) :
injective (λ s : set ι, ⋃ i ∈ s, f i) :=
λ s t h, (h₀.subset_of_bUnion_subset_bUnion (λ _ _, h₁ _) $ h.subset).antisymm $
h₀.subset_of_bUnion_subset_bUnion (λ _ _, h₁ _) $ h.superset
end
|
116eb7b2b0054ac4283a9c54a019ea0d63e0498e | 618003631150032a5676f229d13a079ac875ff77 | /src/tactic/omega/int/form.lean | 32b36b7a6977dd9d358581eb36cb6cd490beac54 | [
"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 | 4,172 | lean | /- Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
Linear integer arithmetic formulas in pre-normalized form. -/
import tactic.omega.int.preterm
namespace omega
namespace int
/-- Intermediate shadow syntax for LNA formulas that includes unreified exprs -/
meta inductive exprform
| eq : exprterm → exprterm → exprform
| le : exprterm → exprterm → exprform
| not : exprform → exprform
| or : exprform → exprform → exprform
| and : exprform → exprform → exprform
/-- Intermediate shadow syntax for LIA formulas that includes non-canonical terms -/
@[derive has_reflect, derive inhabited]
inductive preform
| eq : preterm → preterm → preform
| le : preterm → preterm → preform
| not : preform → preform
| or : preform → preform → preform
| and : preform → preform → preform
localized "notation x ` =* ` y := omega.int.preform.eq x y" in omega.int
localized "notation x ` ≤* ` y := omega.int.preform.le x y" in omega.int
localized "notation `¬* ` p := omega.int.preform.not p" in omega.int
localized "notation p ` ∨* ` q := omega.int.preform.or p q" in omega.int
localized "notation p ` ∧* ` q := omega.int.preform.and p q" in omega.int
namespace preform
/-- Evaluate a preform into prop using the valuation v. -/
@[simp] def holds (v : nat → int) : preform → Prop
| (t =* s) := t.val v = s.val v
| (t ≤* s) := t.val v ≤ s.val v
| (¬* p) := ¬ p.holds
| (p ∨* q) := p.holds ∨ q.holds
| (p ∧* q) := p.holds ∧ q.holds
end preform
/-- univ_close p n := p closed by prepending n universal quantifiers -/
@[simp] def univ_close (p : preform) : (nat → int) → nat → Prop
| v 0 := p.holds v
| v (k+1) := ∀ i : int, univ_close (update_zero i v) k
namespace preform
/-- Fresh de Brujin index not used by any variable in argument -/
def fresh_index : preform → nat
| (t =* s) := max t.fresh_index s.fresh_index
| (t ≤* s) := max t.fresh_index s.fresh_index
| (¬* p) := p.fresh_index
| (p ∨* q) := max p.fresh_index q.fresh_index
| (p ∧* q) := max p.fresh_index q.fresh_index
/-- All valuations satisfy argument -/
def valid (p : preform) : Prop :=
∀ v, holds v p
/-- There exists some valuation that satisfies argument -/
def sat (p : preform) : Prop :=
∃ v, holds v p
/-- implies p q := under any valuation, q holds if p holds -/
def implies (p q : preform) : Prop :=
∀ v, (holds v p → holds v q)
/-- equiv p q := under any valuation, p holds iff q holds -/
def equiv (p q : preform) : Prop :=
∀ v, (holds v p ↔ holds v q)
lemma sat_of_implies_of_sat {p q : preform} :
implies p q → sat p → sat q :=
begin intros h1 h2, apply exists_imp_exists h1 h2 end
lemma sat_or {p q : preform} :
sat (p ∨* q) ↔ sat p ∨ sat q :=
begin
constructor; intro h1,
{ cases h1 with v h1, cases h1 with h1 h1;
[left,right]; refine ⟨v,_⟩; assumption },
{ cases h1 with h1 h1; cases h1 with v h1;
refine ⟨v,_⟩; [left,right]; assumption }
end
/-- There does not exist any valuation that satisfies argument -/
def unsat (p : preform) : Prop := ¬ sat p
def repr : preform → string
| (t =* s) := "(" ++ t.repr ++ " = " ++ s.repr ++ ")"
| (t ≤* s) := "(" ++ t.repr ++ " ≤ " ++ s.repr ++ ")"
| (¬* p) := "¬" ++ p.repr
| (p ∨* q) := "(" ++ p.repr ++ " ∨ " ++ q.repr ++ ")"
| (p ∧* q) := "(" ++ p.repr ++ " ∧ " ++ q.repr ++ ")"
instance has_repr : has_repr preform := ⟨repr⟩
meta instance has_to_format : has_to_format preform := ⟨λ x, x.repr⟩
end preform
lemma univ_close_of_valid {p : preform} :
∀ {m v}, p.valid → univ_close p v m
| 0 v h1 := h1 _
| (m+1) v h1 := λ i, univ_close_of_valid h1
lemma valid_of_unsat_not {p : preform} : (¬*p).unsat → p.valid :=
begin
simp only [preform.sat, preform.unsat, preform.valid, preform.holds],
rw classical.not_exists_not, intro h, assumption
end
/-- Tactic for setting up proof by induction over preforms. -/
meta def preform.induce (t : tactic unit := tactic.skip) : tactic unit :=
`[ intro p, induction p with t s t s p ih p q ihp ihq p q ihp ihq; t]
end int
end omega
|
66de935fdf03d8122d916ccb315760d5c00a27f5 | eb26130db204786b069bd0025a0fc00ed6a75a37 | /src/PFA1.lean | f55bc47e7379f5b08f129c05650f7b5a14f3ac6a | [] | no_license | ADedecker/functional-compare | 2c8278552a88619e69c7f5fd7c6175f09eff5f7f | 1683669a9a1fe81b058d2cc6e000a7144626e80d | refs/heads/master | 1,671,063,268,800 | 1,599,641,367,000 | 1,599,641,367,000 | 293,919,218 | 0 | 1 | null | 1,599,641,369,000 | 1,599,596,672,000 | Lean | UTF-8 | Lean | false | false | 899 | lean | -- **Déclaration globale d'une constante**
def x := 2
def y := x + 4
-- Attention, par défaut Lean voit *toujours* un entier naturel.
-- Pour définir autre chose, il faut spécifier un type
def z : ℤ := -4
-- **Déclaration globale d'une fonction**
-- Directement :
def square (n : ℤ) := n*n
-- En utilisant une fonction anonyme :
def cube := λ n : ℤ, n*n*n
-- **Fonction à plusieurs arguments, if-then-else**
def my_min (a b : ℤ) := if a < b then a else b
-- **Déclarations locales**
def add_min (a b c : ℤ) := let x := my_min b c in a + x
-- **Fonctions récursives**
-- Méthode 1, avec un `if`. Ici, on dit à Lean de ne pas vérifier la terminaison
meta def fac1 : ℕ → ℕ := λ n, if n = 0 then 1 else n * fac1 (n-1)
-- Méthode 2, avec du "pattern matching". Ici, Lean génère une preuve de terminaison !
def fac2 : ℕ → ℕ
| 0 := 1
| (n+1) := (n+1) * fac2 n |
37eb271e61b4e51a658c8cb062f73dd4e1da6873 | 93b17e1ec33b7fd9fb0d8f958cdc9f2214b131a2 | /src/sep/quot.lean | c33c9b56b4c82fd43bb264e04a9eb81d6cc37449 | [] | no_license | intoverflow/timesink | 93f8535cd504bc128ba1b57ce1eda4efc74e5136 | c25be4a2edb866ad0a9a87ee79e209afad6ab303 | refs/heads/master | 1,620,033,920,087 | 1,524,995,105,000 | 1,524,995,105,000 | 120,576,102 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 661 | lean | /- Quotient algebras
-
-/
import .basic
namespace Sep
universe ℓ
-- Quotient by an ideal
def QuotAlg (A : Alg.{ℓ}) {I : Set A} (Iideal : I.Ideal) : Alg
:= { τ := {a // ¬ a ∈ I}
, join := λ x₁ x₂ x₃, A.join x₁.1 x₂.1 x₃.1
, comm := λ x₁ x₂ x₃ H, A.comm H
, assoc := λ x₁ x₂ x₃ x₁x₂ x₁x₂x₃ H₁₂ H₁₂₃
, A.assoc H₁₂ H₁₂₃
(λ a P C, C { x := ⟨ a.x, (λ Q, x₁x₂x₃.2 (Iideal Q (A.comm a.J₂))) ⟩
, J₁ := a.J₁
, J₂ := a.J₂
})
}
end Sep
|
2fbc1e687de07e74ec5ead6da6b98bafb6a7aeb1 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/funext.lean | e9e166186a652f26081260212b699ccc5476ae32 | [] | 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,019 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Extensional equality for functions, and a proof of function extensionality from quotients.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.quot
import Mathlib.Lean3Lib.init.logic
universes u v
namespace Mathlib
namespace function
protected def equiv {α : Sort u} {β : α → Sort v} (f₁ : (x : α) → β x) (f₂ : (x : α) → β x) :=
∀ (x : α), f₁ x = f₂ x
protected theorem equiv.refl {α : Sort u} {β : α → Sort v} (f : (x : α) → β x) : function.equiv f f :=
fun (x : α) => rfl
protected theorem equiv.symm {α : Sort u} {β : α → Sort v} {f₁ : (x : α) → β x} {f₂ : (x : α) → β x} : function.equiv f₁ f₂ → function.equiv f₂ f₁ :=
fun (h : function.equiv f₁ f₂) (x : α) => Eq.symm (h x)
protected theorem equiv.trans {α : Sort u} {β : α → Sort v} {f₁ : (x : α) → β x} {f₂ : (x : α) → β x} {f₃ : (x : α) → β x} : function.equiv f₁ f₂ → function.equiv f₂ f₃ → function.equiv f₁ f₃ :=
fun (h₁ : function.equiv f₁ f₂) (h₂ : function.equiv f₂ f₃) (x : α) => Eq.trans (h₁ x) (h₂ x)
protected theorem equiv.is_equivalence (α : Sort u) (β : α → Sort v) : equivalence function.equiv :=
mk_equivalence function.equiv equiv.refl equiv.symm equiv.trans
end function
theorem funext {α : Sort u} {β : α → Sort v} {f₁ : (x : α) → β x} {f₂ : (x : α) → β x} (h : ∀ (x : α), f₁ x = f₂ x) : f₁ = f₂ :=
(fun (this : extfun_app (quotient.mk f₁) = extfun_app (quotient.mk f₂)) => this)
(congr_arg extfun_app (quotient.sound h))
protected instance pi.subsingleton {α : Sort u} {β : α → Sort v} [∀ (a : α), subsingleton (β a)] : subsingleton ((a : α) → β a) :=
subsingleton.intro fun (f₁ f₂ : (a : α) → β a) => funext fun (a : α) => subsingleton.elim (f₁ a) (f₂ a)
|
c8912d297cbdf92c155a6366c6f4c85c47c165ac | 85a51a7a118db552510ddb311e53e7a8bba7b477 | /src/for_mathlib/filter_basic.lean | e9599b1e0d7a96563e372106454d1520045a1ed4 | [] | no_license | ADedecker/nonstandard | f0c1cac7482bb0dd48d2f2eb092f5262ff0fa2dc | c32f5e1d87cc9e6410d66cf3080fd8c4a47cf5e4 | refs/heads/master | 1,686,549,196,023 | 1,626,129,788,000 | 1,626,129,788,000 | 382,594,533 | 3 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 465 | lean | import order.filter.basic
namespace filter
lemma eventually.choice {α β : Type*} {r : α → β → Prop} {l : filter α}
[l.ne_bot] (h : ∀ᶠ x in l, ∃ y, r x y) : ∃ f : α → β, ∀ᶠ x in l, r x (f x) :=
begin
classical,
use (λ x, if hx : ∃ y, r x y then classical.some hx
else classical.some (classical.some_spec h.exists)),
filter_upwards [h],
intros x hx,
rw dif_pos hx,
exact classical.some_spec hx
end
end filter |
789ca24cf9b37727c203fc87c61e87c8312b4142 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/algebra/category/Module/basic.lean | 0cfad71ec2d2cd603eca1952fcd7a2d773e2d76f | [
"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 | 5,616 | lean | /-
Copyright (c) 2019 Robert A. Spencer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert A. Spencer, Markus Himmel
-/
import algebra.category.Group.basic
import category_theory.concrete_category
import category_theory.limits.shapes.kernels
import category_theory.preadditive
import linear_algebra.basic
open category_theory
open category_theory.limits
open category_theory.limits.walking_parallel_pair
universes v u
variables (R : Type u) [ring R]
/-- The category of R-modules and their morphisms. -/
structure Module :=
(carrier : Type v)
[is_add_comm_group : add_comm_group carrier]
[is_module : module R carrier]
attribute [instance] Module.is_add_comm_group Module.is_module
namespace Module
-- TODO revisit this after #1438 merges, to check coercions and instances are handled consistently
instance : has_coe_to_sort (Module.{v} R) :=
{ S := Type v, coe := Module.carrier }
instance : category (Module.{v} R) :=
{ hom := λ M N, M →ₗ[R] N,
id := λ M, 1,
comp := λ A B C f g, g.comp f }
instance : concrete_category.{v} (Module.{v} R) :=
{ forget := { obj := λ R, R, map := λ R S f, (f : R → S) },
forget_faithful := { } }
instance has_forget_to_AddCommGroup : has_forget₂ (Module R) AddCommGroup :=
{ forget₂ :=
{ obj := λ M, AddCommGroup.of M,
map := λ M₁ M₂ f, linear_map.to_add_monoid_hom f } }
/-- The object in the category of R-modules associated to an R-module -/
def of (X : Type v) [add_comm_group X] [module R X] : Module R := ⟨X⟩
instance : inhabited (Module R) := ⟨of R punit⟩
@[simp]
lemma coe_of (X : Type u) [add_comm_group X] [module R X] : (of R X : Type u) = X := rfl
variables {R}
/-- Forgetting to the underlying type and then building the bundled object returns the original module. -/
@[simps]
def of_self_iso (M : Module R) : Module.of R M ≅ M :=
{ hom := 𝟙 M, inv := 𝟙 M }
instance : subsingleton (of R punit) :=
by { rw coe_of R punit, apply_instance }
instance : has_zero_object (Module.{v} R) :=
{ zero := of R punit,
unique_to := λ X,
{ default := (0 : punit →ₗ[R] X),
uniq := λ _, linear_map.ext $ λ x,
have h : x = 0, from dec_trivial,
by simp only [h, linear_map.map_zero]},
unique_from := λ X,
{ default := (0 : X →ₗ[R] punit),
uniq := λ _, linear_map.ext $ λ x, dec_trivial } }
variables {R} {M N U : Module.{v} R}
@[simp] lemma id_apply (m : M) : (𝟙 M : M → M) m = m := rfl
@[simp] lemma coe_comp (f : M ⟶ N) (g : N ⟶ U) :
((f ≫ g) : M → U) = g ∘ f := rfl
end Module
variables {R}
variables {X₁ X₂ : Type v}
/-- Reinterpreting a linear map in the category of `R`-modules. -/
def Module.as_hom [add_comm_group X₁] [module R X₁] [add_comm_group X₂] [module R X₂] :
(X₁ →ₗ[R] X₂) → (Module.of R X₁ ⟶ Module.of R X₂) := id
/-- Build an isomorphism in the category `Module R` from a `linear_equiv` between `module`s. -/
@[simps]
def linear_equiv.to_Module_iso
{g₁ : add_comm_group X₁} {g₂ : add_comm_group X₂} {m₁ : module R X₁} {m₂ : module R X₂} (e : X₁ ≃ₗ[R] X₂) :
Module.of R X₁ ≅ Module.of R X₂ :=
{ hom := (e : X₁ →ₗ[R] X₂),
inv := (e.symm : X₂ →ₗ[R] X₁),
hom_inv_id' := begin ext, exact e.left_inv x, end,
inv_hom_id' := begin ext, exact e.right_inv x, end, }
/--
Build an isomorphism in the category `Module R` from a `linear_equiv` between `module`s.
This version is better than `linear_equiv_to_Module_iso` when applicable, because Lean can't see `Module.of R M` is defeq to `M` when `M : Module R`.
-/
@[simps]
def linear_equiv.to_Module_iso' {M N : Module.{v} R} (i : M ≃ₗ[R] N) : M ≅ N :=
{ hom := i,
inv := i.symm,
hom_inv_id' := linear_map.ext $ λ x, by simp,
inv_hom_id' := linear_map.ext $ λ x, by simp }
namespace category_theory.iso
/-- Build a `linear_equiv` from an isomorphism in the category `Module R`. -/
@[simps]
def to_linear_equiv {X Y : Module R} (i : X ≅ Y) : X ≃ₗ[R] Y :=
{ to_fun := i.hom,
inv_fun := i.inv,
left_inv := by tidy,
right_inv := by tidy,
map_add' := by tidy,
map_smul' := by tidy, }.
end category_theory.iso
/-- linear equivalences between `module`s are the same as (isomorphic to) isomorphisms in `Module` -/
@[simps]
def linear_equiv_iso_Module_iso {X Y : Type u} [add_comm_group X] [add_comm_group Y] [module R X] [module R Y] :
(X ≃ₗ[R] Y) ≅ (Module.of R X ≅ Module.of R Y) :=
{ hom := λ e, e.to_Module_iso,
inv := λ i, i.to_linear_equiv, }
namespace Module
section preadditive
instance : preadditive (Module.{v} R) :=
{ add_comp' := λ P Q R f f' g,
show (f + f') ≫ g = f ≫ g + f' ≫ g, by { ext, simp },
comp_add' := λ P Q R f g g',
show f ≫ (g + g') = f ≫ g + f ≫ g', by { ext, simp } }
end preadditive
section epi_mono
variables {M N : Module.{v} R} (f : M ⟶ N)
lemma ker_eq_bot_of_mono [mono f] : f.ker = ⊥ :=
linear_map.ker_eq_bot_of_cancel $ λ u v, (@cancel_mono _ _ _ _ _ f _ (as_hom u) (as_hom v)).1
lemma range_eq_top_of_epi [epi f] : f.range = ⊤ :=
linear_map.range_eq_top_of_cancel $ λ u v, (@cancel_epi _ _ _ _ _ f _ (as_hom u) (as_hom v)).1
lemma mono_of_ker_eq_bot (hf : f.ker = ⊥) : mono f :=
concrete_category.mono_of_injective _ $ linear_map.ker_eq_bot.1 hf
lemma epi_of_range_eq_top (hf : f.range = ⊤) : epi f :=
concrete_category.epi_of_surjective _ $ linear_map.range_eq_top.1 hf
end epi_mono
end Module
instance (M : Type u) [add_comm_group M] [module R M] : has_coe (submodule R M) (Module R) :=
⟨ λ N, Module.of R N ⟩
|
4752a994b90589fb54202cf1ae51ab3ff316f488 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/541a.lean | 4cce67376bba434df6298870b9542ce9e9c5d4b0 | [
"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 | 805 | lean | import data.list data.nat
open nat list eq.ops
section
variable {Q : Type}
definition f : list Q → ℕ -- default if l is empty, else max l
| [] := 0
| (h :: t) := f t + 1
theorem f_foo : ∀{l : list Q}, ∀{q : Q}, q ∈ l → f l ≥ 1
| [] := take q, assume Hq, absurd Hq !not_mem_nil
| [h] := take q, assume Hq, nat.le_of_eq !rfl
| (h :: (h' :: t)) := take q, assume Hq,
have Hor : q = h ∨ q ∈ (h' :: t), from iff.mp !mem_cons_iff Hq,
have H : f (h' :: t) ≥ 1, from f_foo (mem_cons h' t),
have H1 : 1 + 1 ≤ f (h' :: t) + 1, from nat.add_le_add_right H 1,
calc
f (h :: h' :: t) = f (h' :: t) + 1 : rfl
... ≥ 1 + 1 : H1
... = 1 : sorry
end
|
566b3769c0c53785adaa59ed25f8844e9ee1c713 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /hott/homotopy/hopf.hlean | 5300e9c3c39db89b57b4388e72b6d39f731eb977 | [
"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 | 6,787 | hlean | /-
Copyright (c) 2016 Ulrik Buchholtz and Egbert Rijke. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ulrik Buchholtz, Egbert Rijke
H-spaces and the Hopf construction
-/
import types.equiv .wedge .join
open eq eq.ops equiv is_equiv is_conn is_trunc trunc susp join
namespace hopf
structure h_space [class] (A : Type) extends has_mul A, has_one A :=
(one_mul : ∀a, mul one a = a) (mul_one : ∀a, mul a one = a)
section
variable {A : Type}
variable [H : h_space A]
include H
definition one_mul (a : A) : 1 * a = a := !h_space.one_mul
definition mul_one (a : A) : a * 1 = a := !h_space.mul_one
definition h_space_equiv_closed {B : Type} (f : A ≃ B) : h_space B :=
⦃ h_space, one := f 1, mul := (λb b', f (f⁻¹ b * f⁻¹ b')),
one_mul := by intro b; rewrite [to_left_inv,one_mul,to_right_inv],
mul_one := by intro b; rewrite [to_left_inv,mul_one,to_right_inv] ⦄
/- Lemma 8.5.5.
If A is 0-connected, then left and right multiplication are equivalences -/
variable [K : is_conn 0 A]
include K
definition is_equiv_mul_left [instance] : Π(a : A), is_equiv (λx, a * x) :=
begin
apply is_conn_fun.elim -1 (is_conn_fun_from_unit -1 A 1)
(λa, trunctype.mk' -1 (is_equiv (λx, a * x))),
intro z, change is_equiv (λx : A, 1 * x), apply is_equiv.homotopy_closed id,
intro x, apply inverse, apply one_mul
end
definition is_equiv_mul_right [instance] : Π(a : A), is_equiv (λx, x * a) :=
begin
apply is_conn_fun.elim -1 (is_conn_fun_from_unit -1 A 1)
(λa, trunctype.mk' -1 (is_equiv (λx, x * a))),
intro z, change is_equiv (λx : A, x * 1), apply is_equiv.homotopy_closed id,
intro x, apply inverse, apply mul_one
end
end
section
variable (A : Type)
variables [H : h_space A] [K : is_conn 0 A]
include H K
definition hopf [unfold 4] : susp A → Type :=
susp.elim_type A A (λa, equiv.mk (λx, a * x) !is_equiv_mul_left)
/- Lemma 8.5.7. The total space is A * A -/
open prod prod.ops
protected definition total : sigma (hopf A) ≃ join A A :=
begin
apply equiv.trans (susp.flattening A A A _), unfold join,
apply equiv.trans (pushout.symm pr₂ (λz : A × A, z.1 * z.2)),
fapply pushout.equiv,
{ fapply equiv.MK
(λz : A × A, (z.1 * z.2, z.2))
(λz : A × A, ((λx, x * z.2)⁻¹ z.1, z.2)),
{ intro z, induction z with u v, esimp,
exact prod_eq (right_inv (λx, x * v) u) idp },
{ intro z, induction z with a b, esimp,
exact prod_eq (left_inv (λx, x * b) a) idp } },
{ reflexivity },
{ reflexivity },
{ reflexivity },
{ reflexivity }
end
end
/- If A is a K(G,1), then A is deloopable.
Main lemma of Licata-Finster. -/
section
parameters (A : Type) [T : is_trunc 1 A] [K : is_conn 0 A] [H : h_space A]
(coh : one_mul 1 = mul_one 1 :> (1 * 1 = 1 :> A))
definition P [reducible] : susp A → Type :=
λx, trunc 1 (north = x)
include K H T
local abbreviation codes [reducible] : susp A → Type := hopf A
definition transport_codes_merid (a a' : A)
: transport codes (merid a) a' = a * a' :> A :=
by krewrite elim_type_merid
definition is_trunc_codes [instance] (x : susp A) : is_trunc 1 (codes x) :=
begin
induction x with a, do 2 apply T, apply is_prop.elimo
end
definition encode₀ {x : susp A} : north = x → codes x :=
λp, transport codes p (by change A; exact 1)
definition encode {x : susp A} : P x → codes x :=
λp, trunc.elim encode₀ p
definition decode' : A → P (@north A) :=
λa, tr (merid a ⬝ (merid 1)⁻¹)
definition transport_codes_merid_one_inv (a : A)
: transport codes (merid 1)⁻¹ a = a :=
begin
rewrite tr_inv,
apply @inv_eq_of_eq A A (transport codes (merid 1)) _ a a,
krewrite elim_type_merid,
change a = 1 * a,
rewrite one_mul
end
proposition encode_decode' (a : A) : encode (decode' a) = a :=
begin
unfold decode', unfold encode, unfold encode₀,
rewrite [con_tr,transport_codes_merid,mul_one,tr_inv],
apply transport_codes_merid_one_inv
end
include coh
open pointed
proposition homomorphism : Πa a' : A,
tr (merid (a * a')) = tr (merid a' ⬝ (merid 1)⁻¹ ⬝ merid a)
:> trunc 1 (@north A = @south A) :=
begin
fapply @wedge_extension.ext (pointed.MK A 1) (pointed.MK A 1) 0 0 K K
(λa a' : A, tr (merid (a * a')) = tr (merid a' ⬝ (merid 1)⁻¹ ⬝ merid a)),
{ intros a a', apply is_trunc_eq, apply is_trunc_trunc },
{ change Πa : A,
tr (merid (a * 1)) = tr (merid 1 ⬝ (merid 1)⁻¹ ⬝ merid a)
:> trunc 1 (@north A = @south A),
intro a, apply ap tr,
exact calc
merid (a * 1) = merid a : ap merid (mul_one a)
... = merid 1 ⬝ (merid 1)⁻¹ ⬝ merid a
: (idp_con (merid a))⁻¹
⬝ ap (λw, w ⬝ merid a) (con.right_inv (merid 1))⁻¹ },
{ change Πa' : A,
tr (merid (1 * a')) = tr (merid a' ⬝ (merid 1)⁻¹ ⬝ merid 1)
:> trunc 1 (@north A = @south A),
intro a', apply ap tr,
exact calc
merid (1 * a') = merid a' : ap merid (one_mul a')
... = merid a' ⬝ (merid 1)⁻¹ ⬝ merid 1
: ap (λw, merid a' ⬝ w) (con.left_inv (merid 1))⁻¹
⬝ (con.assoc' (merid a') (merid 1)⁻¹ (merid 1)) },
{ apply ap02 tr, esimp, fapply concat2,
{ apply ap02 merid, exact coh⁻¹ },
{ assert e : Π(X : Type)(x y : X)(p : x = y),
(idp_con p)⁻¹ ⬝ ap (λw : x = x, w ⬝ p) (con.right_inv p)⁻¹
= ap (concat p) (con.left_inv p)⁻¹ ⬝ con.assoc' p p⁻¹ p,
{ intros X x y p, cases p, reflexivity },
apply e } }
end
definition decode {x : susp A} : codes x → P x :=
begin
induction x,
{ exact decode' },
{ exact (λa, tr (merid a)) },
{ apply pi.arrow_pathover_left, esimp, intro a',
apply pathover_of_tr_eq, krewrite susp.elim_type_merid, esimp,
krewrite [trunc_transport,transport_eq_r], apply inverse,
apply homomorphism }
end
proposition decode_encode {x : susp A} : Πt : P x, decode (encode t) = t :=
begin
apply trunc.rec, intro p, cases p, apply ap tr, apply con.right_inv
end
definition main_lemma : trunc 1 (north = north :> susp A) ≃ A :=
equiv.MK encode decode' encode_decode' decode_encode
definition main_lemma_point
: ptrunc 1 (Ω(psusp A)) ≃* pointed.MK A 1 :=
pointed.pequiv_of_equiv main_lemma idp
protected definition delooping : Ω (ptrunc 2 (psusp A)) ≃* pointed.MK A 1 :=
loop_ptrunc_pequiv 1 (psusp A) ⬝e* main_lemma_point
end
end hopf
|
28230da916d9df7914f445811e15c2816cc658f6 | 28be2ab6091504b6ba250b367205fb94d50ab284 | /src/game/world8/level5.lean | 1e164cc00a0d9c22ce55031745b82a57b7a8db56 | [
"Apache-2.0"
] | permissive | postmasters/natural_number_game | 87304ac22e5e1c5ac2382d6e523d6914dd67a92d | 38a7adcdfdb18c49c87b37831736c8f15300d821 | refs/heads/master | 1,649,856,819,031 | 1,586,444,676,000 | 1,586,444,676,000 | 255,006,061 | 0 | 0 | Apache-2.0 | 1,586,664,599,000 | 1,586,664,598,000 | null | UTF-8 | Lean | false | false | 954 | lean | import mynat.definition -- hide
import mynat.add -- hide
import game.world8.level4 -- hide
namespace mynat -- hide
/-
# Advanced Addition World
## Level 5: `add_right_cancel`
The theorem `add_right_cancel` is the theorem that you can cancel on the left
when you're doing addition -- if `a + t = b + t` then `a = b`. After `intro h`
I'd recommend induction on `t`. Don't forget that `rw add_zero at h` can be used
to do rewriting of hypotheses rather than the goal.
-/
/- Theorem
On the set of natural numbers, addition has the right cancellation property.
In other words, if there are natural numbers $a, b$ and $c$ such that
$$ a + t = b + t, $$
then we have $a = b$.
-/
theorem add_right_cancel (a t b : mynat) : a + t = b + t → a = b :=
begin [nat_num_game]
intro h,
induction t with d hd,
rw add_zero at h,
rw add_zero at h,
exact h,
apply hd,
rw add_succ at h,
rw add_succ at h,
exact succ_inj(h),
end
end mynat -- hide
|
1d0f6d29535540f821d4b3ddf3594ddc41f1ae1a | 205f0fc16279a69ea36e9fd158e3a97b06834ce2 | /src/01_Equality/07_tactics.lean | 4ab9649269b1a45cf8d5d4ba499ff8423424a6b2 | [] | no_license | kevinsullivan/cs-dm-lean | b21d3ca1a9b2a0751ba13fcb4e7b258010a5d124 | a06a94e98be77170ca1df486c8189338b16cf6c6 | refs/heads/master | 1,585,948,743,595 | 1,544,339,346,000 | 1,544,339,346,000 | 155,570,767 | 1 | 3 | null | 1,541,540,372,000 | 1,540,995,993,000 | Lean | UTF-8 | Lean | false | false | 3,190 | lean | /-
We've already seen that we can assert
that a proposition is true by defining
a variable to have that proposition as
its type, and we can prove the proposition
by assigning a proof term to the variable.
-/
lemma zeqz : 0 = 0 := eq.refl 0
/-
Sometimes it's harder to write an exact
proof term (here, eq.refl 0). In these
cases it can help to figure out a proof
term step by step. Lean supports step
by step development of proof terms with
what are called tactic-based proving.
Here's an equivalent tactic-based proof.
-/
lemma zeqz' : 0 = 0 :=
begin
apply eq.refl 0,
end
/-
In this case, the proof is so simple
that writing a script is more work.
The key thing to see here, though, is
the "apply" tactic. It applies some
already known rule, here eq.refl, to
move from a state in which something
is to be proved to a state in which
something new has been proved.
-/
/-
Now open the Lean Messages panel by typing
control-shift-enter or command-shift-enter
(Windows/Mac). Now place your cursor first
at the start of the "apply". The message
window will display the "tactic state" at
this point in the script. The state say
that nothing is assumed and the remaining
goal to be proved is 0 = 0. Now move your
cursor to the next line, before the "end."
The tactic state is empty, nothing is left
to be proved, QED.
-/
/-
EXERCISE. Define zeqz'' as also
being of type 0 = 0, but after the :=,
just write begin on the next line and
then an end on the following line. You
need to type the begin and end lines
before continuing.
-/
/-
HOW TO SOLVE IT:
Initially there will be an error. Hover
over the red squiggle under the "end."
It tells you that you haven't yet proved
something that remains to be proved, and
it tells you what remains to be proved.
Insert a blank line between the begin and
end. The tactic state tells you what is
known at a given point in a tactic script
(before the turnstile character, ⊢, and
what remains to be proved, after. Here,
the goal that remains is 0 = 0.
If you then click on the next line, end,
Lean tells you that the proof-generating
tactic script between the begin and end
lines failed because some goal remains to
be proved.
In general, a tactic will only partially
prove a goal, leaving some parts still to
be proved. In such cases, more tactics
are then used to finish the construction
of the required proof. Tactic commands
are separated by commas. We'll see more
later.
Go ahead and type the required tactic
between begin and end. Click on the
line with the tactic, then on the end. Watch how the tactic state changes as
you go from line to line.
-/
/-
You might have noticed that while "apply
eq.refl 0" finishes the proof, so does
just "apply eq.refl". In this case, Lean
infers both arguments to eq.refl from
context. That, in fact, is what rfl does.
It's not technically a tactic. It is just
using type inference to infer both of the
arguments needed for eq.refl!
Some people refer to such a script as a
proof. A better way to think about it is
as a step-by-step recipe for building a
proof. The actual proof at the end of the
day is the proof object that the script
constructs: eq.refl 0, in this case.
-/
|
b3ecb9f49ac670ae9dc2298dd4f1dab582b44021 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/MultGroup.lean | aa1ae2da8fef4938d38cd22ce407041f15395182 | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,582 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section MultGroup
structure MultGroup (A : Type) : Type :=
(times : (A → (A → A)))
(one : A)
(lunit_one : (∀ {x : A} , (times one x) = x))
(runit_one : (∀ {x : A} , (times x one) = x))
(associative_times : (∀ {x y z : A} , (times (times x y) z) = (times x (times y z))))
(inv : (A → A))
(leftInverse_inv_op_one : (∀ {x : A} , (times x (inv x)) = one))
(rightInverse_inv_op_one : (∀ {x : A} , (times (inv x) x) = one))
open MultGroup
structure Sig (AS : Type) : Type :=
(timesS : (AS → (AS → AS)))
(oneS : AS)
(invS : (AS → AS))
structure Product (A : Type) : Type :=
(timesP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(oneP : (Prod A A))
(invP : ((Prod A A) → (Prod A A)))
(lunit_1P : (∀ {xP : (Prod A A)} , (timesP oneP xP) = xP))
(runit_1P : (∀ {xP : (Prod A A)} , (timesP xP oneP) = xP))
(associative_timesP : (∀ {xP yP zP : (Prod A A)} , (timesP (timesP xP yP) zP) = (timesP xP (timesP yP zP))))
(leftInverse_inv_op_1P : (∀ {xP : (Prod A A)} , (timesP xP (invP xP)) = oneP))
(rightInverse_inv_op_1P : (∀ {xP : (Prod A A)} , (timesP (invP xP) xP) = oneP))
structure Hom {A1 : Type} {A2 : Type} (Mu1 : (MultGroup A1)) (Mu2 : (MultGroup A2)) : Type :=
(hom : (A1 → A2))
(pres_times : (∀ {x1 x2 : A1} , (hom ((times Mu1) x1 x2)) = ((times Mu2) (hom x1) (hom x2))))
(pres_one : (hom (one Mu1)) = (one Mu2))
(pres_inv : (∀ {x1 : A1} , (hom ((inv Mu1) x1)) = ((inv Mu2) (hom x1))))
structure RelInterp {A1 : Type} {A2 : Type} (Mu1 : (MultGroup A1)) (Mu2 : (MultGroup A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_times : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((times Mu1) x1 x2) ((times Mu2) y1 y2))))))
(interp_one : (interp (one Mu1) (one Mu2)))
(interp_inv : (∀ {x1 : A1} {y1 : A2} , ((interp x1 y1) → (interp ((inv Mu1) x1) ((inv Mu2) y1)))))
inductive MultGroupTerm : Type
| timesL : (MultGroupTerm → (MultGroupTerm → MultGroupTerm))
| oneL : MultGroupTerm
| invL : (MultGroupTerm → MultGroupTerm)
open MultGroupTerm
inductive ClMultGroupTerm (A : Type) : Type
| sing : (A → ClMultGroupTerm)
| timesCl : (ClMultGroupTerm → (ClMultGroupTerm → ClMultGroupTerm))
| oneCl : ClMultGroupTerm
| invCl : (ClMultGroupTerm → ClMultGroupTerm)
open ClMultGroupTerm
inductive OpMultGroupTerm (n : ℕ) : Type
| v : ((fin n) → OpMultGroupTerm)
| timesOL : (OpMultGroupTerm → (OpMultGroupTerm → OpMultGroupTerm))
| oneOL : OpMultGroupTerm
| invOL : (OpMultGroupTerm → OpMultGroupTerm)
open OpMultGroupTerm
inductive OpMultGroupTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpMultGroupTerm2)
| sing2 : (A → OpMultGroupTerm2)
| timesOL2 : (OpMultGroupTerm2 → (OpMultGroupTerm2 → OpMultGroupTerm2))
| oneOL2 : OpMultGroupTerm2
| invOL2 : (OpMultGroupTerm2 → OpMultGroupTerm2)
open OpMultGroupTerm2
def simplifyCl {A : Type} : ((ClMultGroupTerm A) → (ClMultGroupTerm A))
| (timesCl oneCl x) := x
| (timesCl x oneCl) := x
| (timesCl x1 x2) := (timesCl (simplifyCl x1) (simplifyCl x2))
| oneCl := oneCl
| (invCl x1) := (invCl (simplifyCl x1))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpMultGroupTerm n) → (OpMultGroupTerm n))
| (timesOL oneOL x) := x
| (timesOL x oneOL) := x
| (timesOL x1 x2) := (timesOL (simplifyOpB x1) (simplifyOpB x2))
| oneOL := oneOL
| (invOL x1) := (invOL (simplifyOpB x1))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpMultGroupTerm2 n A) → (OpMultGroupTerm2 n A))
| (timesOL2 oneOL2 x) := x
| (timesOL2 x oneOL2) := x
| (timesOL2 x1 x2) := (timesOL2 (simplifyOp x1) (simplifyOp x2))
| oneOL2 := oneOL2
| (invOL2 x1) := (invOL2 (simplifyOp x1))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((MultGroup A) → (MultGroupTerm → A))
| Mu (timesL x1 x2) := ((times Mu) (evalB Mu x1) (evalB Mu x2))
| Mu oneL := (one Mu)
| Mu (invL x1) := ((inv Mu) (evalB Mu x1))
def evalCl {A : Type} : ((MultGroup A) → ((ClMultGroupTerm A) → A))
| Mu (sing x1) := x1
| Mu (timesCl x1 x2) := ((times Mu) (evalCl Mu x1) (evalCl Mu x2))
| Mu oneCl := (one Mu)
| Mu (invCl x1) := ((inv Mu) (evalCl Mu x1))
def evalOpB {A : Type} {n : ℕ} : ((MultGroup A) → ((vector A n) → ((OpMultGroupTerm n) → A)))
| Mu vars (v x1) := (nth vars x1)
| Mu vars (timesOL x1 x2) := ((times Mu) (evalOpB Mu vars x1) (evalOpB Mu vars x2))
| Mu vars oneOL := (one Mu)
| Mu vars (invOL x1) := ((inv Mu) (evalOpB Mu vars x1))
def evalOp {A : Type} {n : ℕ} : ((MultGroup A) → ((vector A n) → ((OpMultGroupTerm2 n A) → A)))
| Mu vars (v2 x1) := (nth vars x1)
| Mu vars (sing2 x1) := x1
| Mu vars (timesOL2 x1 x2) := ((times Mu) (evalOp Mu vars x1) (evalOp Mu vars x2))
| Mu vars oneOL2 := (one Mu)
| Mu vars (invOL2 x1) := ((inv Mu) (evalOp Mu vars x1))
def inductionB {P : (MultGroupTerm → Type)} : ((∀ (x1 x2 : MultGroupTerm) , ((P x1) → ((P x2) → (P (timesL x1 x2))))) → ((P oneL) → ((∀ (x1 : MultGroupTerm) , ((P x1) → (P (invL x1)))) → (∀ (x : MultGroupTerm) , (P x)))))
| ptimesl p1l pinvl (timesL x1 x2) := (ptimesl _ _ (inductionB ptimesl p1l pinvl x1) (inductionB ptimesl p1l pinvl x2))
| ptimesl p1l pinvl oneL := p1l
| ptimesl p1l pinvl (invL x1) := (pinvl _ (inductionB ptimesl p1l pinvl x1))
def inductionCl {A : Type} {P : ((ClMultGroupTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClMultGroupTerm A)) , ((P x1) → ((P x2) → (P (timesCl x1 x2))))) → ((P oneCl) → ((∀ (x1 : (ClMultGroupTerm A)) , ((P x1) → (P (invCl x1)))) → (∀ (x : (ClMultGroupTerm A)) , (P x))))))
| psing ptimescl p1cl pinvcl (sing x1) := (psing x1)
| psing ptimescl p1cl pinvcl (timesCl x1 x2) := (ptimescl _ _ (inductionCl psing ptimescl p1cl pinvcl x1) (inductionCl psing ptimescl p1cl pinvcl x2))
| psing ptimescl p1cl pinvcl oneCl := p1cl
| psing ptimescl p1cl pinvcl (invCl x1) := (pinvcl _ (inductionCl psing ptimescl p1cl pinvcl x1))
def inductionOpB {n : ℕ} {P : ((OpMultGroupTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpMultGroupTerm n)) , ((P x1) → ((P x2) → (P (timesOL x1 x2))))) → ((P oneOL) → ((∀ (x1 : (OpMultGroupTerm n)) , ((P x1) → (P (invOL x1)))) → (∀ (x : (OpMultGroupTerm n)) , (P x))))))
| pv ptimesol p1ol pinvol (v x1) := (pv x1)
| pv ptimesol p1ol pinvol (timesOL x1 x2) := (ptimesol _ _ (inductionOpB pv ptimesol p1ol pinvol x1) (inductionOpB pv ptimesol p1ol pinvol x2))
| pv ptimesol p1ol pinvol oneOL := p1ol
| pv ptimesol p1ol pinvol (invOL x1) := (pinvol _ (inductionOpB pv ptimesol p1ol pinvol x1))
def inductionOp {n : ℕ} {A : Type} {P : ((OpMultGroupTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpMultGroupTerm2 n A)) , ((P x1) → ((P x2) → (P (timesOL2 x1 x2))))) → ((P oneOL2) → ((∀ (x1 : (OpMultGroupTerm2 n A)) , ((P x1) → (P (invOL2 x1)))) → (∀ (x : (OpMultGroupTerm2 n A)) , (P x)))))))
| pv2 psing2 ptimesol2 p1ol2 pinvol2 (v2 x1) := (pv2 x1)
| pv2 psing2 ptimesol2 p1ol2 pinvol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 ptimesol2 p1ol2 pinvol2 (timesOL2 x1 x2) := (ptimesol2 _ _ (inductionOp pv2 psing2 ptimesol2 p1ol2 pinvol2 x1) (inductionOp pv2 psing2 ptimesol2 p1ol2 pinvol2 x2))
| pv2 psing2 ptimesol2 p1ol2 pinvol2 oneOL2 := p1ol2
| pv2 psing2 ptimesol2 p1ol2 pinvol2 (invOL2 x1) := (pinvol2 _ (inductionOp pv2 psing2 ptimesol2 p1ol2 pinvol2 x1))
def stageB : (MultGroupTerm → (Staged MultGroupTerm))
| (timesL x1 x2) := (stage2 timesL (codeLift2 timesL) (stageB x1) (stageB x2))
| oneL := (Now oneL)
| (invL x1) := (stage1 invL (codeLift1 invL) (stageB x1))
def stageCl {A : Type} : ((ClMultGroupTerm A) → (Staged (ClMultGroupTerm A)))
| (sing x1) := (Now (sing x1))
| (timesCl x1 x2) := (stage2 timesCl (codeLift2 timesCl) (stageCl x1) (stageCl x2))
| oneCl := (Now oneCl)
| (invCl x1) := (stage1 invCl (codeLift1 invCl) (stageCl x1))
def stageOpB {n : ℕ} : ((OpMultGroupTerm n) → (Staged (OpMultGroupTerm n)))
| (v x1) := (const (code (v x1)))
| (timesOL x1 x2) := (stage2 timesOL (codeLift2 timesOL) (stageOpB x1) (stageOpB x2))
| oneOL := (Now oneOL)
| (invOL x1) := (stage1 invOL (codeLift1 invOL) (stageOpB x1))
def stageOp {n : ℕ} {A : Type} : ((OpMultGroupTerm2 n A) → (Staged (OpMultGroupTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (timesOL2 x1 x2) := (stage2 timesOL2 (codeLift2 timesOL2) (stageOp x1) (stageOp x2))
| oneOL2 := (Now oneOL2)
| (invOL2 x1) := (stage1 invOL2 (codeLift1 invOL2) (stageOp x1))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(timesT : ((Repr A) → ((Repr A) → (Repr A))))
(oneT : (Repr A))
(invT : ((Repr A) → (Repr A)))
end MultGroup |
fbe4a7e14463079c2bf19f71f52f80a8065174be | fcf3ffa92a3847189ca669cb18b34ef6b2ec2859 | /src/world8/level6.lean | 9a8f4831a7f9127d004fd076b44828645de162e6 | [
"Apache-2.0"
] | permissive | nomoid/lean-proofs | 4a80a97888699dee42b092b7b959b22d9aa0c066 | b9f03a24623d1a1d111d6c2bbf53c617e2596d6a | refs/heads/master | 1,674,955,317,080 | 1,607,475,706,000 | 1,607,475,706,000 | 314,104,281 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 281 | lean | import mynat.definition
import mynat.add
import world2.level4
import world8.level5
namespace mynat
theorem add_left_cancel (a t b : mynat) : t + a = t + b → a = b :=
begin [nat_num_game]
rw add_comm t a,
rw add_comm t b,
exact add_right_cancel a t b,
end
end mynat |
b29d2a96c55f6b9a8741d1d45adf0c0c4ecd8679 | 4dbc106f944ae08d9082a937156fe53f8241336c | /src/data/finmap.lean | d979a55fcc495dc4a9a17baba54aa242f7303540 | [] | no_license | spl/lean-finmap | feff7ee53811b172531f84b20c02e50c787fe6fc | 936d9caeb27631e3c6cf20e972de4837c9fe98fa | refs/heads/master | 1,584,501,090,642 | 1,537,511,660,000 | 1,537,515,626,000 | 134,227,269 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,204 | lean | import data.finset data.multiset.dict data.pfun logic.function
local attribute [-simp] sigma.forall sigma.exists
universes u v
/-- Finite map: a multiset of dependent pairs with no duplicate keys -/
structure finmap (α : Type u) (β : α → Type v) : Type (max u v) :=
(val : multiset (sigma β))
(nodupkeys : val.nodupkeys)
namespace finmap
open multiset
section αβ
variables {α : Type u} {β : α → Type v}
/- equality -/
theorem eq_of_veq : ∀ {f g : finmap α β}, f.val = g.val → f = g
| ⟨s, _⟩ ⟨t, _⟩ h := by congr; exact h
@[simp] theorem val_inj {f g : finmap α β} : f.val = g.val ↔ f = g :=
⟨eq_of_veq, congr_arg _⟩
instance has_decidable_eq [decidable_eq α] [∀ a, decidable_eq (β a)] : decidable_eq (finmap α β)
| f g := decidable_of_iff _ val_inj
/- recursors -/
section rec
open function
/-- Dependent recursor on a finmap for a list -/
protected def lrec_on {γ : Sort*} (f : finmap α β)
(φ : ∀ {l : list (sigma β)}, l.nodupkeys → γ)
(c : ∀ {l₁ l₂} (p : l₁ ~ l₂) d₁ d₂, φ d₁ = φ d₂) : γ :=
@quotient.hrec_on _ _ (λ (m : multiset (sigma β)), m.nodupkeys → γ)
f.val
(λ l (d : l.nodupkeys), φ d)
(λ l₁ l₂ p, hfunext (by rw list.perm_nodupkeys p) $ λ d₁ d₂ _, heq_of_eq $ c p d₁ d₂)
f.nodupkeys
/-- Dependent recursor on two finmaps for lists -/
protected def lrec_on₂ {γ : Sort*} (f g : finmap α β)
(φ : ∀ {l₁ l₂ : list (sigma β)}, l₁.nodupkeys → l₂.nodupkeys → γ)
(c : ∀ {l₁ l₂ l₃ l₄} (p₁₃ : l₁ ~ l₃) (p₂₄ : l₂ ~ l₄) d₁ d₂ d₃ d₄, φ d₁ d₂ = φ d₃ d₄) : γ :=
@quotient.hrec_on₂ _ _ _ _
(λ (m₁ m₂ : multiset (sigma β)), m₁.nodupkeys → m₂.nodupkeys → γ)
f.val g.val
(λ l₁ l₂ (d₁ : l₁.nodupkeys) (d₂ : l₂.nodupkeys), φ d₁ d₂)
(λ l₁ l₂ l₃ l₄ p₁₃ p₂₄, hfunext (by rw list.perm_nodupkeys p₁₃) $
λ d₁ d₃ _, hfunext (by rw list.perm_nodupkeys p₂₄) $
λ d₂ d₄ _, heq_of_eq $ c p₁₃ p₂₄ d₁ d₂ d₃ d₄)
f.nodupkeys g.nodupkeys
/-- Lift a function on 2 lists to a function on 2 finmaps -/
protected def lift_on₂ {γ : Type*} (f g : finmap α β)
(φ : ∀ {l₁ l₂ : list (sigma β)}, l₁.nodupkeys → l₂.nodupkeys → γ)
(c : ∀ {l₁ l₂ l₃ l₄} (p₁₃ : l₁ ~ l₃) (p₂₄ : l₂ ~ l₄) d₁ d₂ d₃ d₄, φ d₁ d₂ = φ d₃ d₄) :
roption γ :=
quotient.lift_on₂ f.val g.val
(λ l₁ l₂, roption.mk (l₁.nodupkeys ∧ l₂.nodupkeys) (λ ⟨d₁, d₂⟩, φ d₁ d₂))
(λ l₁ l₂ l₃ l₄ p₁₃ p₂₄, roption.ext'
(and_congr (list.perm_nodupkeys p₁₃) (list.perm_nodupkeys p₂₄))
(λ ⟨d₁, d₂⟩ ⟨d₃, d₄⟩, c p₁₃ p₂₄ d₁ d₂ d₃ d₄))
end rec
/- membership -/
section mem
variables {s : sigma β} {m : multiset (sigma β)} {d : m.nodupkeys} {f : finmap α β}
instance : has_mem (sigma β) (finmap α β) :=
⟨λ s f, s ∈ f.val⟩
theorem mem_def : s ∈ f ↔ s ∈ f.val :=
iff.rfl
@[simp] theorem mem_mk : @has_mem.mem _ (finmap α β) _ s (finmap.mk m d) ↔ s ∈ m :=
iff.rfl
instance decidable_mem [decidable_eq α] [∀ a, decidable_eq (β a)] (s : sigma β) (f : finmap α β) :
decidable (s ∈ f) :=
multiset.decidable_mem _ _
end mem
/- set coercion -/
section set
variables {s : sigma β} {f : finmap α β}
def to_set (f : finmap α β) : set (sigma β) :=
{x | x ∈ f}
instance has_lift_set : has_lift (finmap α β) (set (sigma β)) :=
⟨to_set⟩
@[simp] theorem mem_set_coe : s ∈ (↑f : set (sigma β)) ↔ s ∈ f :=
iff.rfl
end set
/- finset coercion -/
section finset
variables {s : sigma β} {f : finmap α β}
def to_finset (f : finmap α β) : finset (sigma β) :=
⟨f.val, nodup_of_nodupkeys f.nodupkeys⟩
instance has_lift_finset : has_lift (finmap α β) (finset (sigma β)) :=
⟨to_finset⟩
@[simp] theorem mem_finset_coe : s ∈ (↑f : finset (sigma β)) ↔ s ∈ f :=
iff.rfl
end finset
/- extensionality -/
section ext
variables {f g : finmap α β}
theorem ext : f = g ↔ ∀ s, s ∈ f ↔ s ∈ g :=
val_inj.symm.trans $ nodup_ext
(nodup_of_nodupkeys f.nodupkeys)
(nodup_of_nodupkeys g.nodupkeys)
@[extensionality]
theorem ext' : (∀ s, s ∈ f ↔ s ∈ g) → f = g :=
ext.mpr
end ext
/- subset -/
section subset
variables {s : sigma β} {f g h : finmap α β}
instance : has_subset (finmap α β) :=
⟨λ f g, ∀ ⦃s : sigma β⦄, s ∈ f → s ∈ g⟩
theorem subset_def : f ⊆ g ↔ f.val ⊆ g.val :=
iff.rfl
@[simp] theorem subset.refl (f : finmap α β) : f ⊆ f :=
subset.refl _
theorem subset.trans : f ⊆ g → g ⊆ h → f ⊆ h :=
subset.trans
theorem mem_of_subset : f ⊆ g → s ∈ f → s ∈ g :=
mem_of_subset
theorem subset.antisymm (H₁ : f ⊆ g) (H₂ : g ⊆ f) : f = g :=
ext' $ λ a, ⟨@H₁ a, @H₂ a⟩
theorem subset_iff : f ⊆ g ↔ ∀ ⦃x⦄, x ∈ f → x ∈ g :=
iff.rfl
@[simp] theorem coe_subset_set : (↑f : set (sigma β)) ⊆ ↑g ↔ f ⊆ g :=
iff.rfl
@[simp] theorem coe_subset_finset : (↑f : finset (sigma β)) ⊆ ↑g ↔ f ⊆ g :=
iff.rfl
@[simp] theorem val_le_iff : f.val ≤ g.val ↔ f ⊆ g :=
le_iff_subset (nodup_of_nodupkeys f.nodupkeys)
instance : has_ssubset (finmap α β) :=
⟨λa b, a ⊆ b ∧ ¬ b ⊆ a⟩
instance : partial_order (finmap α β) :=
{ le := (⊆),
lt := (⊂),
le_refl := subset.refl,
le_trans := @subset.trans _ _,
le_antisymm := @subset.antisymm _ _ }
@[simp] theorem le_iff_subset : f ≤ g ↔ f ⊆ g := iff.rfl
@[simp] theorem lt_iff_ssubset : f < g ↔ f ⊂ g := iff.rfl
@[simp] theorem val_lt_iff : f.val < g.val ↔ f ⊂ g :=
and_congr val_le_iff $ not_congr val_le_iff
end subset
/- empty -/
section empty
variables {s : sigma β} {f : finmap α β}
instance : has_emptyc (finmap α β) :=
⟨⟨_, nodupkeys_zero⟩⟩
instance : inhabited (finmap α β) :=
⟨∅⟩
@[simp] theorem empty_val : (∅ : finmap α β).val = 0 :=
rfl
@[simp] theorem not_mem_empty (s : sigma β) : s ∉ (∅ : finmap α β) :=
id
@[simp] theorem ne_empty_of_mem (h : s ∈ f) : f ≠ ∅
| e := not_mem_empty s $ e ▸ h
@[simp] theorem empty_subset (f : finmap α β) : ∅ ⊆ f :=
zero_subset _
theorem eq_empty_of_forall_not_mem (H : ∀x, x ∉ f) : f = ∅ :=
eq_of_veq (eq_zero_of_forall_not_mem H)
@[simp] theorem val_eq_zero : f.val = 0 ↔ f = ∅ :=
@val_inj _ _ f ∅
theorem subset_empty : f ⊆ ∅ ↔ f = ∅ :=
subset_zero.trans val_eq_zero
theorem exists_mem_of_ne_empty (h : f ≠ ∅) : ∃ s : sigma β, s ∈ f :=
exists_mem_of_ne_zero (mt val_eq_zero.mp h)
@[simp] theorem coe_empty_set : ↑(∅ : finmap α β) = (∅ : set (sigma β)) :=
by simp [set.ext_iff]
@[simp] theorem coe_empty_finset : ↑(∅ : finmap α β) = (∅ : finset (sigma β)) :=
by simp [finset.ext]
end empty
/- singleton -/
section singleton
variables {s₁ s₂ : sigma β}
/-- `singleton s` is the set `{s}` containing `s` and nothing else. -/
def singleton (s : sigma β) : finmap α β :=
⟨⟦[s]⟧, nodupkeys_singleton s⟩
@[simp] theorem singleton_val (s : sigma β) : (singleton s).val = s :: 0 :=
rfl
@[simp] theorem mem_singleton : s₁ ∈ singleton s₂ ↔ s₁ = s₂ :=
by simp [singleton]
theorem not_mem_singleton : s₁ ∉ singleton s₂ ↔ s₁ ≠ s₂ := by simp
theorem mem_singleton_self (s : sigma β) : s ∈ singleton s := by simp
theorem singleton_inj : singleton s₁ = singleton s₂ ↔ s₁ = s₂ :=
⟨λ h, mem_singleton.mp (h ▸ mem_singleton_self _), congr_arg _⟩
@[simp] theorem singleton_ne_empty (s : sigma β) : singleton s ≠ ∅ :=
ne_empty_of_mem (mem_singleton_self _)
@[simp] theorem coe_singleton_set (s : sigma β) : ↑(singleton s) = ({s} : set (sigma β)) :=
by simp [set.ext_iff]
@[simp] theorem coe_singleton_finset (s : sigma β) : ↑(singleton s) = finset.singleton s :=
by simp [finset.ext]
end singleton
/- keys -/
section keys
variables {a a₁ a₂ : α} {s : sigma β} {f : finmap α β}
def keys (f : finmap α β) : finset α :=
⟨f.val.keys, nodupkeys_iff.mpr f.nodupkeys⟩
@[simp] theorem keys_val (f : finmap α β) : f.keys.val = f.val.keys :=
rfl
@[simp] theorem keys_empty : keys (∅ : finmap α β) = ∅ :=
rfl
@[simp] theorem keys_singleton : keys (singleton s) = finset.singleton s.1 :=
rfl
theorem mem_keys_of_mem : s ∈ f → s.1 ∈ f.keys :=
mem_keys_of_mem
theorem exists_mem_of_mem_keys : a ∈ f.keys → ∃ (b : β a), sigma.mk a b ∈ f :=
exists_mem_of_mem_keys
@[simp] theorem mem_keys_singleton : a ∈ (singleton s).keys ↔ a = s.1 :=
by simp
@[simp] theorem mem_insert_keys [decidable_eq α] :
a₁ ∈ insert a₂ f.keys ↔ a₁ = a₂ ∨ a₁ ∈ f.keys :=
by simp
end keys
section decidable_eq_α
variables [decidable_eq α]
/- erase -/
section erase
variables {s : sigma β} {a a₁ a₂ : α} {f g : finmap α β}
def erase (f : finmap α β) (a : α) : finmap α β :=
⟨kerase a f.nodupkeys, nodupkeys_kerase a f.nodupkeys⟩
@[simp] theorem erase_val (f : finmap α β) (a : α) : (f.erase a).val = kerase a f.nodupkeys :=
rfl
@[simp] theorem mem_erase : s ∈ f.erase a ↔ s.1 ≠ a ∧ s ∈ f :=
mem_kerase f.nodupkeys
theorem not_mem_erase (a : α) (b : β a) (f : finmap α β) : sigma.mk a b ∉ f.erase a :=
by simp
@[simp] theorem mem_keys_erase : a₁ ∈ (f.erase a₂).keys ↔ a₁ ≠ a₂ ∧ a₁ ∈ f.keys :=
by simp [keys]
@[simp] theorem erase_empty (β : α → Type v) (a) : erase ∅ a = (∅ : finmap α β) :=
rfl
theorem ne_of_mem_erase : s ∈ f.erase a → s.1 ≠ a :=
by simp {contextual := tt}
theorem erase_subset_erase (a : α) (h : f ⊆ g) : f.erase a ⊆ g.erase a :=
val_le_iff.mp $ kerase_le_kerase _ (val_le_iff.mpr h) _ _
theorem erase_subset (a : α) : f.erase a ⊆ f :=
kerase_subset a f.nodupkeys
end erase
/- insert -/
section insert
variables {a : α} {s : sigma β} {f g : finmap α β}
instance : has_insert (sigma β) (finmap α β) :=
⟨λ s f, ⟨kinsert s f.nodupkeys, nodupkeys_kinsert s f.nodupkeys⟩⟩
theorem insert_def (s : sigma β) (f : finmap α β) :
insert s f = mk (kinsert s f.nodupkeys) (nodupkeys_kinsert s f.nodupkeys) :=
rfl
@[simp] theorem insert_val (s : sigma β) (f : finmap α β) :
(insert s f).val = kinsert s f.nodupkeys :=
rfl
@[simp] theorem insert_empty (s : sigma β) : insert s (∅ : finmap α β) = {s} :=
rfl
@[simp] theorem mem_insert (s₁ s₂ : sigma β) (f : finmap α β) :
s₁ ∈ insert s₂ f ↔ s₁ = s₂ ∨ s₁ ∈ f.erase s₂.1 :=
mem_kinsert f.nodupkeys
@[simp] theorem mem_keys_insert : a ∈ (insert s f).keys ↔ a = s.1 ∨ a ∈ f.keys :=
by simp [keys]
@[simp] theorem insert_keys : (insert s f).keys = insert s.1 f.keys :=
finset.ext' $ by simp
@[simp] theorem disjoint_keys_insert_left :
disjoint (insert s f).keys g.keys ↔ s.1 ∉ g.keys ∧ disjoint f.keys g.keys :=
by simp
@[simp] theorem disjoint_keys_insert_right :
disjoint f.keys (insert s g).keys ↔ s.1 ∉ f.keys ∧ disjoint f.keys g.keys :=
by simp
end insert
/- lookup -/
section lookup
/-- Look up a key in a finmap to find the value, if it exists -/
def lookup (a : α) (f : finmap α β) : option (β a) :=
klookup a f.nodupkeys
/-- Treat a finmap as the function `∀ a, option (β a)` -/
def to_fun (f : finmap α β) (a : α) : option (β a) :=
f.lookup a
/-- Treat a finmap as the partial function `∀ a, roption (β a)` -/
def to_pfun (f : finmap α β) (a : α) : roption (β a) :=
roption.of_option (f.to_fun a)
theorem lookup_empty (β : α → Type v) (a) : lookup a (∅ : finmap α β) = none :=
rfl
end lookup
/- replace -/
section replace
def replace (s : sigma β) (f : finmap α β) : finmap α β :=
⟨kreplace s f.nodupkeys, nodupkeys_kreplace s f.nodupkeys⟩
@[simp] theorem replace_empty (s : sigma β) : replace s ∅ = ∅ :=
rfl
end replace
/- union -/
section union
variables {a : α} {s : sigma β} {f g h : finmap α β}
protected def union (f : finmap α β) (g : finmap α β) : finmap α β :=
⟨kunion f.nodupkeys g.nodupkeys, nodupkeys_kunion f.nodupkeys g.nodupkeys⟩
instance : has_union (finmap α β) :=
⟨finmap.union⟩
@[simp] theorem union_val : (f ∪ g).val = kunion f.nodupkeys g.nodupkeys :=
rfl
@[simp] theorem empty_union (f : finmap α β) : ∅ ∪ f = f :=
eq_of_veq $ by simp [zero_kunion f.nodupkeys]
@[simp] theorem union_empty (f : finmap α β) : f ∪ ∅ = f :=
eq_of_veq $ kunion_zero f.nodupkeys
@[simp] theorem insert_union : insert s f ∪ g = insert s (f ∪ g) :=
eq_of_veq $ kinsert_kunion f.nodupkeys g.nodupkeys
theorem mem_of_mem_union : s ∈ f ∪ g → s ∈ f ∨ s ∈ g :=
mem_of_mem_kunion f.nodupkeys g.nodupkeys
theorem mem_union_left (g : finmap α β) : s ∈ f → s ∈ f ∪ g :=
mem_kunion_left f.nodupkeys g.nodupkeys
theorem mem_union_right : s.1 ∉ f.keys → s ∈ g → s ∈ f ∪ g :=
mem_kunion_right f.nodupkeys g.nodupkeys
@[simp] theorem mem_union (dk : disjoint f.keys g.keys) : s ∈ f ∪ g ↔ s ∈ f ∨ s ∈ g :=
mem_kunion f.nodupkeys g.nodupkeys (finset.disjoint_val.mp dk)
theorem union_comm (dk : disjoint f.keys g.keys) : f ∪ g = g ∪ f :=
by simp [ext, or_comm, dk, dk.symm]
@[simp] theorem mem_keys_union : a ∈ (f ∪ g).keys ↔ a ∈ f.keys ∨ a ∈ g.keys :=
mem_keys_kunion f.nodupkeys g.nodupkeys
@[simp] theorem union_keys : (f ∪ g).keys = f.keys ∪ g.keys :=
finset.ext' $ by simp
theorem disjoint_keys_union_left :
disjoint (f ∪ g).keys h.keys ↔ disjoint f.keys h.keys ∧ disjoint g.keys h.keys :=
by simp
theorem disjoint_keys_union_right :
disjoint f.keys (g ∪ h).keys ↔ disjoint f.keys g.keys ∧ disjoint f.keys h.keys :=
by simp
@[simp] theorem union_assoc (dk_fg : disjoint f.keys g.keys) (dk_gh : disjoint g.keys h.keys)
(dk_fh : disjoint f.keys h.keys) : (f ∪ g) ∪ h = f ∪ (g ∪ h) :=
have disjoint (f ∪ g).keys h.keys := disjoint_keys_union_left.mpr ⟨dk_fh, dk_gh⟩,
have disjoint f.keys (g ∪ h).keys := disjoint_keys_union_right.mpr ⟨dk_fg, dk_fh⟩,
by simp [ext, or_comm, or.left_comm, *]
theorem mem_union_middle_left (dk_fh : disjoint f.keys h.keys) (dk_gh : disjoint g.keys h.keys)
(p : s ∈ f ∪ h) : s ∈ f ∪ g ∪ h :=
match mem_of_mem_union p with
| or.inl p := mem_union_left _ (mem_union_left _ p)
| or.inr p := mem_union_right
(finset.disjoint_right.mp (disjoint_keys_union_left.mpr ⟨dk_fh, dk_gh⟩) (mem_keys_of_mem p)) p
end
theorem mem_union_middle_right (dk_fh : disjoint f.keys h.keys) (dk_gh : disjoint g.keys h.keys)
(p : s ∈ f ∪ h) : s ∈ f ∪ (g ∪ h) :=
match mem_of_mem_union p with
| or.inl p := mem_union_left _ p
| or.inr p :=
have s.1 ∈ h.keys := mem_keys_of_mem p,
mem_union_right
(finset.disjoint_right.mp dk_fh this)
(mem_union_right (finset.disjoint_right.mp dk_gh this) p)
end
end union
end decidable_eq_α
end αβ
section α₁α₂α₃β₁β₂β₃
variables {α₁ α₂ α₃ : Type u} {β₁ : α₁ → Type v} {β₂ : α₂ → Type v} {β₃ : α₃ → Type v}
section map
variables {p : β₁ s↪ β₂} {q : β₂ s↪ β₃} {s₁ : sigma β₁} {s₂ : sigma β₂} {f g : finmap α₁ β₁}
def map (p : β₁ s↪ β₂) (f : finmap α₁ β₁) : finmap α₂ β₂ :=
⟨f.val.map p, nodupkeys_map p.fst_inj f.nodupkeys⟩
@[simp] theorem map_val (p : β₁ s↪ β₂) (f : finmap α₁ β₁) : (f.map p).val = f.val.map p :=
rfl
@[simp] theorem map_mk {m₁ : multiset (sigma β₁)} {m₂ : multiset (sigma β₂)} {p : β₁ s↪ β₂}
(d₁ : m₁.nodupkeys) (d₂ : m₂.nodupkeys) : (mk m₁ d₁).map p = mk m₂ d₂ ↔ m₁.map p = m₂ :=
by simp [map]
@[simp] theorem map_empty (p : β₁ s↪ β₂) : map p ∅ = ∅ :=
rfl
@[simp] theorem mem_map : s₂ ∈ f.map p ↔ ∃ s₁ ∈ f, p s₁ = s₂ :=
by simp [mem_def]
@[simp] theorem mem_map_of_mem (h : s₁ ∈ f) : p s₁ ∈ f.map p :=
mem_map.mpr ⟨_, h, rfl⟩
theorem map_refl : f.map (sigma.embedding.refl _) = f :=
ext' $ by simp [sigma.embedding.refl]
theorem map_map : (f.map p).map q = f.map (p.trans q) :=
eq_of_veq $ by simp [erase_dup_map_erase_dup_eq]
theorem map_subset_map (h : f ⊆ g) : f.map p ⊆ g.map p :=
by simp [subset_def, map_subset_map h]
theorem mem_keys_map (pf : sigma.fst_functional p) :
s₁.1 ∈ f.keys → (p s₁).1 ∈ (f.map p).keys :=
mem_keys_map pf
theorem mem_keys_of_mem_keys_map : (p s₁).1 ∈ (f.map p).keys → s₁.1 ∈ f.keys :=
mem_keys_of_mem_keys_map p.fst_inj
theorem mem_keys_map_iff (pf : sigma.fst_functional p) :
(p s₁).1 ∈ (f.map p).keys ↔ s₁.1 ∈ f.keys :=
⟨mem_keys_of_mem_keys_map, mem_keys_map pf⟩
theorem map_disjoint_keys [decidable_eq α₁] [decidable_eq α₂] (pf : sigma.fst_functional p) :
disjoint (f.map p).keys (g.map p).keys ↔ disjoint f.keys g.keys :=
by simp only [finset.disjoint_val]; exact multiset.map_disjoint_keys pf p.fst_inj
theorem map_union [decidable_eq α₁] [decidable_eq α₂] (pf : sigma.fst_functional p)
(dk : disjoint f.keys g.keys) : (f ∪ g).map p = f.map p ∪ g.map p :=
ext' $ by simp [dk, map_disjoint_keys pf, or_and_distrib_right, exists_or_distrib]
section decidable_eq_α₁α₂
variables [decidable_eq α₁] [decidable_eq α₂]
@[simp] theorem map_erase (pf : sigma.fst_functional p) :
(f.erase s₁.1).map p = (f.map p).erase (p s₁).1 :=
by simp [erase, map_kerase pf p.fst_inj f.nodupkeys]
@[simp] theorem map_insert (pf : sigma.fst_functional p) :
(insert s₁ f).map p = insert (p s₁) (f.map p) :=
by simp [insert_def, map_kinsert pf p.fst_inj f.nodupkeys]
end decidable_eq_α₁α₂
end map
end α₁α₂α₃β₁β₂β₃
section αβ₁β₂
variables {α : Type u} {β₁ β₂ : α → Type v}
section map_id
variables {s : sigma β₁} {f : finmap α β₁}
@[simp] theorem map_id_val (p : ∀ a, β₁ a → β₂ a) (f : finmap α β₁) :
(f.map (sigma.embedding.mk₂ p)).val = f.val.map (sigma.map id p) :=
rfl
@[simp] theorem map_id_keys (p : ∀ a, β₁ a → β₂ a) : (f.map (sigma.embedding.mk₂ p)).keys = f.keys :=
finset.val_inj.mp $ by simp
end map_id
end αβ₁β₂
end finmap
|
182beb9c2d63ec11c04259eb621248e22c1344d3 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/linear_algebra/matrix/basis.lean | 6064a764e2492a504d76111c09dd873f707d9a2c | [
"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 | 9,889 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.matrix.reindex
import linear_algebra.matrix.to_lin
/-!
# Bases and matrices
This file defines the map `basis.to_matrix` that sends a family of vectors to
the matrix of their coordinates with respect to some basis.
## Main definitions
* `basis.to_matrix e v` is the matrix whose `i, j`th entry is `e.repr (v j) i`
* `basis.to_matrix_equiv` is `basis.to_matrix` bundled as a linear equiv
## Main results
* `linear_map.to_matrix_id_eq_basis_to_matrix`: `linear_map.to_matrix b c id`
is equal to `basis.to_matrix b c`
* `basis.to_matrix_mul_to_matrix`: multiplying `basis.to_matrix` with another
`basis.to_matrix` gives a `basis.to_matrix`
## Tags
matrix, basis
-/
noncomputable theory
open linear_map matrix set submodule
open_locale big_operators
open_locale matrix
section basis_to_matrix
variables {ι ι' κ κ' : Type*}
variables {R M : Type*} [comm_semiring R] [add_comm_monoid M] [module R M]
variables {R₂ M₂ : Type*} [comm_ring R₂] [add_comm_group M₂] [module R₂ M₂]
open function matrix
/-- From a basis `e : ι → M` and a family of vectors `v : ι' → M`, make the matrix whose columns
are the vectors `v i` written in the basis `e`. -/
def basis.to_matrix (e : basis ι R M) (v : ι' → M) : matrix ι ι' R :=
λ i j, e.repr (v j) i
variables (e : basis ι R M) (v : ι' → M) (i : ι) (j : ι')
namespace basis
lemma to_matrix_apply : e.to_matrix v i j = e.repr (v j) i :=
rfl
lemma to_matrix_transpose_apply : (e.to_matrix v)ᵀ j = e.repr (v j) :=
funext $ (λ _, rfl)
lemma to_matrix_eq_to_matrix_constr [fintype ι] [decidable_eq ι] (v : ι → M) :
e.to_matrix v = linear_map.to_matrix e e (e.constr ℕ v) :=
by { ext, rw [basis.to_matrix_apply, linear_map.to_matrix_apply, basis.constr_basis] }
-- TODO (maybe) Adjust the definition of `basis.to_matrix` to eliminate the transpose.
lemma coe_pi_basis_fun.to_matrix_eq_transpose [fintype ι] :
((pi.basis_fun R ι).to_matrix : matrix ι ι R → matrix ι ι R) = matrix.transpose :=
by { ext M i j, refl, }
@[simp] lemma to_matrix_self [decidable_eq ι] : e.to_matrix e = 1 :=
begin
rw basis.to_matrix,
ext i j,
simp [basis.equiv_fun, matrix.one_apply, finsupp.single_apply, eq_comm]
end
lemma to_matrix_update [decidable_eq ι'] (x : M) :
e.to_matrix (function.update v j x) = matrix.update_column (e.to_matrix v) j (e.repr x) :=
begin
ext i' k,
rw [basis.to_matrix, matrix.update_column_apply, e.to_matrix_apply],
split_ifs,
{ rw [h, update_same j x v] },
{ rw update_noteq h },
end
/-- The basis constructed by `units_smul` has vectors given by a diagonal matrix. -/
@[simp] lemma to_matrix_units_smul [decidable_eq ι] (e : basis ι R₂ M₂) (w : ι → R₂ˣ) :
e.to_matrix (e.units_smul w) = diagonal (coe ∘ w) :=
begin
ext i j,
by_cases h : i = j,
{ simp [h, to_matrix_apply, units_smul_apply, units.smul_def] },
{ simp [h, to_matrix_apply, units_smul_apply, units.smul_def, ne.symm h] }
end
/-- The basis constructed by `is_unit_smul` has vectors given by a diagonal matrix. -/
@[simp] lemma to_matrix_is_unit_smul [decidable_eq ι] (e : basis ι R₂ M₂) {w : ι → R₂}
(hw : ∀ i, is_unit (w i)) :
e.to_matrix (e.is_unit_smul hw) = diagonal w :=
e.to_matrix_units_smul _
@[simp] lemma sum_to_matrix_smul_self [fintype ι] : ∑ (i : ι), e.to_matrix v i j • e i = v j :=
by simp_rw [e.to_matrix_apply, e.sum_repr]
lemma to_matrix_map_vec_mul {S : Type*} [ring S] [algebra R S] [fintype ι]
(b : basis ι R S) (v : ι' → S) :
((b.to_matrix v).map $ algebra_map R S).vec_mul b = v :=
begin
ext i,
simp_rw [vec_mul, dot_product, matrix.map_apply, ← algebra.commutes, ← algebra.smul_def,
sum_to_matrix_smul_self],
end
@[simp] lemma to_lin_to_matrix [fintype ι] [fintype ι'] [decidable_eq ι'] (v : basis ι' R M) :
matrix.to_lin v e (e.to_matrix v) = id :=
v.ext (λ i, by rw [to_lin_self, id_apply, e.sum_to_matrix_smul_self])
/-- From a basis `e : ι → M`, build a linear equivalence between families of vectors `v : ι → M`,
and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/
def to_matrix_equiv [fintype ι] (e : basis ι R M) : (ι → M) ≃ₗ[R] matrix ι ι R :=
{ to_fun := e.to_matrix,
map_add' := λ v w, begin
ext i j,
change _ = _ + _,
rw [e.to_matrix_apply, pi.add_apply, linear_equiv.map_add],
refl
end,
map_smul' := begin
intros c v,
ext i j,
rw [e.to_matrix_apply, pi.smul_apply, linear_equiv.map_smul],
refl
end,
inv_fun := λ m j, ∑ i, (m i j) • e i,
left_inv := begin
intro v,
ext j,
exact e.sum_to_matrix_smul_self v j
end,
right_inv := begin
intros m,
ext k l,
simp only [e.to_matrix_apply, ← e.equiv_fun_apply, ← e.equiv_fun_symm_apply,
linear_equiv.apply_symm_apply],
end }
end basis
section mul_linear_map_to_matrix
variables {N : Type*} [add_comm_monoid N] [module R N]
variables (b : basis ι R M) (b' : basis ι' R M) (c : basis κ R N) (c' : basis κ' R N)
variables (f : M →ₗ[R] N)
open linear_map
section fintype
variables [fintype ι'] [fintype κ] [fintype κ']
@[simp] lemma basis_to_matrix_mul_linear_map_to_matrix [decidable_eq ι'] :
c.to_matrix c' ⬝ linear_map.to_matrix b' c' f = linear_map.to_matrix b' c f :=
(matrix.to_lin b' c).injective
(by haveI := classical.dec_eq κ';
rw [to_lin_to_matrix, to_lin_mul b' c' c, to_lin_to_matrix, c.to_lin_to_matrix, id_comp])
variable [fintype ι]
@[simp] lemma linear_map_to_matrix_mul_basis_to_matrix [decidable_eq ι] [decidable_eq ι'] :
linear_map.to_matrix b' c' f ⬝ b'.to_matrix b = linear_map.to_matrix b c' f :=
(matrix.to_lin b c').injective
(by rw [to_lin_to_matrix, to_lin_mul b b' c', to_lin_to_matrix, b'.to_lin_to_matrix, comp_id])
lemma basis_to_matrix_mul_linear_map_to_matrix_mul_basis_to_matrix
[decidable_eq ι] [decidable_eq ι'] :
c.to_matrix c' ⬝ linear_map.to_matrix b' c' f ⬝ b'.to_matrix b = linear_map.to_matrix b c f :=
by rw [basis_to_matrix_mul_linear_map_to_matrix, linear_map_to_matrix_mul_basis_to_matrix]
lemma basis_to_matrix_mul [decidable_eq κ]
(b₁ : basis ι R M) (b₂ : basis ι' R M) (b₃ : basis κ R N) (A : matrix ι' κ R) :
b₁.to_matrix b₂ ⬝ A = linear_map.to_matrix b₃ b₁ (to_lin b₃ b₂ A) :=
begin
have := basis_to_matrix_mul_linear_map_to_matrix b₃ b₁ b₂ (matrix.to_lin b₃ b₂ A),
rwa [linear_map.to_matrix_to_lin] at this
end
lemma mul_basis_to_matrix [decidable_eq ι] [decidable_eq ι']
(b₁ : basis ι R M) (b₂ : basis ι' R M) (b₃ : basis κ R N) (A : matrix κ ι R) :
A ⬝ b₁.to_matrix b₂ = linear_map.to_matrix b₂ b₃ (to_lin b₁ b₃ A) :=
begin
have := linear_map_to_matrix_mul_basis_to_matrix b₂ b₁ b₃ (matrix.to_lin b₁ b₃ A),
rwa [linear_map.to_matrix_to_lin] at this
end
lemma basis_to_matrix_basis_fun_mul (b : basis ι R (ι → R)) (A : matrix ι ι R) :
b.to_matrix (pi.basis_fun R ι) ⬝ A = of (λ i j, b.repr (Aᵀ j) i) :=
begin
classical,
simp only [basis_to_matrix_mul _ _ (pi.basis_fun R ι), matrix.to_lin_eq_to_lin'],
ext i j,
rw [linear_map.to_matrix_apply, matrix.to_lin'_apply, pi.basis_fun_apply,
matrix.mul_vec_std_basis_apply, matrix.of_apply]
end
/-- A generalization of `linear_map.to_matrix_id`. -/
@[simp] lemma linear_map.to_matrix_id_eq_basis_to_matrix [decidable_eq ι] :
linear_map.to_matrix b b' id = b'.to_matrix b :=
by { haveI := classical.dec_eq ι',
rw [←@basis_to_matrix_mul_linear_map_to_matrix _ _ ι, to_matrix_id, matrix.mul_one] }
/-- See also `basis.to_matrix_reindex` which gives the `simp` normal form of this result. -/
lemma basis.to_matrix_reindex' [decidable_eq ι] [decidable_eq ι']
(b : basis ι R M) (v : ι' → M) (e : ι ≃ ι') :
(b.reindex e).to_matrix v = matrix.reindex_alg_equiv _ e (b.to_matrix (v ∘ e)) :=
by { ext, simp only [basis.to_matrix_apply, basis.reindex_repr, matrix.reindex_alg_equiv_apply,
matrix.reindex_apply, matrix.submatrix_apply, function.comp_app, e.apply_symm_apply] }
end fintype
/-- A generalization of `basis.to_matrix_self`, in the opposite direction. -/
@[simp] lemma basis.to_matrix_mul_to_matrix {ι'' : Type*} [fintype ι'] (b'' : ι'' → M) :
b.to_matrix b' ⬝ b'.to_matrix b'' = b.to_matrix b'' :=
begin
have := classical.dec_eq ι,
have := classical.dec_eq ι',
haveI := classical.dec_eq ι'',
ext i j,
simp only [matrix.mul_apply, basis.to_matrix_apply, basis.sum_repr_mul_repr],
end
/-- `b.to_matrix b'` and `b'.to_matrix b` are inverses. -/
lemma basis.to_matrix_mul_to_matrix_flip [decidable_eq ι] [fintype ι'] :
b.to_matrix b' ⬝ b'.to_matrix b = 1 :=
by rw [basis.to_matrix_mul_to_matrix, basis.to_matrix_self]
/-- A matrix whose columns form a basis `b'`, expressed w.r.t. a basis `b`, is invertible. -/
def basis.invertible_to_matrix [decidable_eq ι] [fintype ι] (b b' : basis ι R₂ M₂) :
invertible (b.to_matrix b') :=
matrix.invertible_of_left_inverse _ _ (basis.to_matrix_mul_to_matrix_flip _ _)
@[simp]
lemma basis.to_matrix_reindex
(b : basis ι R M) (v : ι' → M) (e : ι ≃ ι') :
(b.reindex e).to_matrix v = (b.to_matrix v).submatrix e.symm id :=
by { ext, simp only [basis.to_matrix_apply, basis.reindex_repr, matrix.submatrix_apply, id.def] }
@[simp]
lemma basis.to_matrix_map (b : basis ι R M) (f : M ≃ₗ[R] N) (v : ι → N) :
(b.map f).to_matrix v = b.to_matrix (f.symm ∘ v) :=
by { ext, simp only [basis.to_matrix_apply, basis.map, linear_equiv.trans_apply] }
end mul_linear_map_to_matrix
end basis_to_matrix
|
f2a566108696d9467a9c2a23d44216f6d664ce84 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/geometry/manifold/cont_mdiff.lean | 9839fc53ae3ba91f6ad9b9c528895cb9c32d6372 | [
"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 | 83,343 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import geometry.manifold.mfderiv
import geometry.manifold.local_invariant_properties
/-!
# Smooth functions between smooth manifolds
We define `Cⁿ` functions between smooth manifolds, as functions which are `Cⁿ` in charts, and prove
basic properties of these notions.
## Main definitions and statements
Let `M ` and `M'` be two smooth manifolds, with respect to model with corners `I` and `I'`. Let
`f : M → M'`.
* `cont_mdiff_within_at I I' n f s x` states that the function `f` is `Cⁿ` within the set `s`
around the point `x`.
* `cont_mdiff_at I I' n f x` states that the function `f` is `Cⁿ` around `x`.
* `cont_mdiff_on I I' n f s` states that the function `f` is `Cⁿ` on the set `s`
* `cont_mdiff I I' n f` states that the function `f` is `Cⁿ`.
* `cont_mdiff_on.comp` gives the invariance of the `Cⁿ` property under composition
* `cont_mdiff_on.cont_mdiff_on_tangent_map_within` states that the bundled derivative
of a `Cⁿ` function in a domain is `Cᵐ` when `m + 1 ≤ n`.
* `cont_mdiff.cont_mdiff_tangent_map` states that the bundled derivative
of a `Cⁿ` function is `Cᵐ` when `m + 1 ≤ n`.
* `cont_mdiff_iff_cont_diff` states that, for functions between vector spaces,
manifold-smoothness is equivalent to usual smoothness.
We also give many basic properties of smooth functions between manifolds, following the API of
smooth functions between vector spaces.
## Implementation details
Many properties follow for free from the corresponding properties of functions in vector spaces,
as being `Cⁿ` is a local property invariant under the smooth groupoid. We take advantage of the
general machinery developed in `local_invariant_properties.lean` to get these properties
automatically. For instance, the fact that being `Cⁿ` does not depend on the chart one considers
is given by `lift_prop_within_at_indep_chart`.
For this to work, the definition of `cont_mdiff_within_at` and friends has to
follow definitionally the setup of local invariant properties. Still, we recast the definition
in terms of extended charts in `cont_mdiff_on_iff` and `cont_mdiff_iff`.
-/
open set function filter charted_space smooth_manifold_with_corners
open_locale topological_space manifold
/-! ### Definition of smooth functions between manifolds -/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
-- declare a smooth manifold `M` over the pair `(E, H)`.
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M] [Is : smooth_manifold_with_corners I M]
-- declare a smooth manifold `M'` over the pair `(E', H')`.
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H' : Type*} [topological_space H'] (I' : model_with_corners 𝕜 E' H')
{M' : Type*} [topological_space M'] [charted_space H' M'] [I's : smooth_manifold_with_corners I' M']
-- declare a smooth manifold `N` over the pair `(F, G)`.
{F : Type*} [normed_group F] [normed_space 𝕜 F]
{G : Type*} [topological_space G] {J : model_with_corners 𝕜 F G}
{N : Type*} [topological_space N] [charted_space G N] [Js : smooth_manifold_with_corners J N]
-- declare a smooth manifold `N'` over the pair `(F', G')`.
{F' : Type*} [normed_group F'] [normed_space 𝕜 F']
{G' : Type*} [topological_space G'] {J' : model_with_corners 𝕜 F' G'}
{N' : Type*} [topological_space N'] [charted_space G' N'] [J's : smooth_manifold_with_corners J' N']
-- declare functions, sets, points and smoothness indices
{f f₁ : M → M'} {s s₁ t : set M} {x : M} {m n : with_top ℕ}
/-- Property in the model space of a model with corners of being `C^n` within at set at a point,
when read in the model vector space. This property will be lifted to manifolds to define smooth
functions between manifolds. -/
def cont_diff_within_at_prop (n : with_top ℕ) (f s x) : Prop :=
cont_diff_within_at 𝕜 n (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) (I x)
/-- Being `Cⁿ` in the model space is a local property, invariant under smooth maps. Therefore,
it will lift nicely to manifolds. -/
lemma cont_diff_within_at_local_invariant_prop (n : with_top ℕ) :
(cont_diff_groupoid ∞ I).local_invariant_prop (cont_diff_groupoid ∞ I')
(cont_diff_within_at_prop I I' n) :=
{ is_local :=
begin
assume s x u f u_open xu,
have : range I ∩ I.symm ⁻¹' (s ∩ u) = (range I ∩ I.symm ⁻¹' s) ∩ I.symm ⁻¹' u,
by simp only [inter_assoc, preimage_inter],
rw [cont_diff_within_at_prop, cont_diff_within_at_prop, this],
symmetry,
apply cont_diff_within_at_inter,
have : u ∈ 𝓝 (I.symm (I x)),
by { rw [model_with_corners.left_inv], exact is_open.mem_nhds u_open xu },
apply continuous_at.preimage_mem_nhds I.continuous_symm.continuous_at this,
end,
right_invariance :=
begin
assume s x f e he hx h,
rw cont_diff_within_at_prop at h ⊢,
have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)), by simp only [hx] with mfld_simps,
rw this at h,
have : I (e x) ∈ (I.symm) ⁻¹' e.target ∩ range ⇑I, by simp only [hx] with mfld_simps,
have := ((mem_groupoid_of_pregroupoid.2 he).2.cont_diff_within_at this).of_le le_top,
convert h.comp' _ this using 1,
{ ext y, simp only with mfld_simps },
{ mfld_set_tac }
end,
congr :=
begin
assume s x f g h hx hf,
apply hf.congr,
{ assume y hy,
simp only with mfld_simps at hy,
simp only [h, hy] with mfld_simps },
{ simp only [hx] with mfld_simps }
end,
left_invariance :=
begin
assume s x f e' he' hs hx h,
rw cont_diff_within_at_prop at h ⊢,
have A : (I' ∘ f ∘ I.symm) (I x) ∈ (I'.symm ⁻¹' e'.source ∩ range I'),
by simp only [hx] with mfld_simps,
have := ((mem_groupoid_of_pregroupoid.2 he').1.cont_diff_within_at A).of_le le_top,
convert this.comp _ h _,
{ ext y, simp only with mfld_simps },
{ assume y hy, simp only with mfld_simps at hy, simpa only [hy] with mfld_simps using hs hy.2 }
end }
lemma cont_diff_within_at_local_invariant_prop_mono (n : with_top ℕ)
⦃s x t⦄ ⦃f : H → H'⦄ (hts : t ⊆ s) (h : cont_diff_within_at_prop I I' n f s x) :
cont_diff_within_at_prop I I' n f t x :=
begin
apply h.mono (λ y hy, _),
simp only with mfld_simps at hy,
simp only [hy, hts _] with mfld_simps
end
lemma cont_diff_within_at_local_invariant_prop_id (x : H) :
cont_diff_within_at_prop I I ∞ id univ x :=
begin
simp [cont_diff_within_at_prop],
have : cont_diff_within_at 𝕜 ∞ id (range I) (I x) :=
cont_diff_id.cont_diff_at.cont_diff_within_at,
apply this.congr (λ y hy, _),
{ simp only with mfld_simps },
{ simp only [model_with_corners.right_inv I hy] with mfld_simps }
end
/-- A function is `n` times continuously differentiable within a set at a point in a manifold if
it is continuous and it is `n` times continuously differentiable in this set around this point, when
read in the preferred chart at this point. -/
def cont_mdiff_within_at (n : with_top ℕ) (f : M → M') (s : set M) (x : M) :=
lift_prop_within_at (cont_diff_within_at_prop I I' n) f s x
/-- Abbreviation for `cont_mdiff_within_at I I' ⊤ f s x`. See also documentation for `smooth`.
-/
@[reducible] def smooth_within_at (f : M → M') (s : set M) (x : M) :=
cont_mdiff_within_at I I' ⊤ f s x
/-- A function is `n` times continuously differentiable at a point in a manifold if
it is continuous and it is `n` times continuously differentiable around this point, when
read in the preferred chart at this point. -/
def cont_mdiff_at (n : with_top ℕ) (f : M → M') (x : M) :=
cont_mdiff_within_at I I' n f univ x
/-- Abbreviation for `cont_mdiff_at I I' ⊤ f x`. See also documentation for `smooth`. -/
@[reducible] def smooth_at (f : M → M') (x : M) := cont_mdiff_at I I' ⊤ f x
/-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable on this set in the charts
around these points. -/
def cont_mdiff_on (n : with_top ℕ) (f : M → M') (s : set M) :=
∀ x ∈ s, cont_mdiff_within_at I I' n f s x
/-- Abbreviation for `cont_mdiff_on I I' ⊤ f s`. See also documentation for `smooth`. -/
@[reducible] def smooth_on (f : M → M') (s : set M) := cont_mdiff_on I I' ⊤ f s
/-- A function is `n` times continuously differentiable in a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable in the charts
around these points. -/
def cont_mdiff (n : with_top ℕ) (f : M → M') :=
∀ x, cont_mdiff_at I I' n f x
/-- Abbreviation for `cont_mdiff I I' ⊤ f`.
Short note to work with these abbreviations: a lemma of the form `cont_mdiff_foo.bar` will
apply fine to an assumption `smooth_foo` using dot notation or normal notation.
If the consequence `bar` of the lemma involves `cont_diff`, it is still better to restate
the lemma replacing `cont_diff` with `smooth` both in the assumption and in the conclusion,
to make it possible to use `smooth` consistently.
This also applies to `smooth_at`, `smooth_on` and `smooth_within_at`.-/
@[reducible] def smooth (f : M → M') := cont_mdiff I I' ⊤ f
/-! ### Basic properties of smooth functions between manifolds -/
variables {I I'}
lemma cont_mdiff.smooth (h : cont_mdiff I I' ⊤ f) : smooth I I' f := h
lemma smooth.cont_mdiff (h : smooth I I' f) : cont_mdiff I I' ⊤ f := h
lemma cont_mdiff_on.smooth_on (h : cont_mdiff_on I I' ⊤ f s) : smooth_on I I' f s := h
lemma smooth_on.cont_mdiff_on (h : smooth_on I I' f s) : cont_mdiff_on I I' ⊤ f s := h
lemma cont_mdiff_at.smooth_at (h : cont_mdiff_at I I' ⊤ f x) : smooth_at I I' f x := h
lemma smooth_at.cont_mdiff_at (h : smooth_at I I' f x) : cont_mdiff_at I I' ⊤ f x := h
lemma cont_mdiff_within_at.smooth_within_at (h : cont_mdiff_within_at I I' ⊤ f s x) :
smooth_within_at I I' f s x := h
lemma smooth_within_at.cont_mdiff_within_at (h : smooth_within_at I I' f s x) :
cont_mdiff_within_at I I' ⊤ f s x := h
lemma cont_mdiff.cont_mdiff_at (h : cont_mdiff I I' n f) :
cont_mdiff_at I I' n f x :=
h x
lemma smooth.smooth_at (h : smooth I I' f) :
smooth_at I I' f x := cont_mdiff.cont_mdiff_at h
lemma cont_mdiff_within_at_univ :
cont_mdiff_within_at I I' n f univ x ↔ cont_mdiff_at I I' n f x :=
iff.rfl
lemma smooth_at_univ :
smooth_within_at I I' f univ x ↔ smooth_at I I' f x := cont_mdiff_within_at_univ
lemma cont_mdiff_on_univ :
cont_mdiff_on I I' n f univ ↔ cont_mdiff I I' n f :=
by simp only [cont_mdiff_on, cont_mdiff, cont_mdiff_within_at_univ,
forall_prop_of_true, mem_univ]
lemma smooth_on_univ :
smooth_on I I' f univ ↔ smooth I I' f := cont_mdiff_on_univ
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in the corresponding extended chart. -/
lemma cont_mdiff_within_at_iff :
cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧
cont_diff_within_at 𝕜 n ((ext_chart_at I' (f x)) ∘ f ∘ (ext_chart_at I x).symm)
((ext_chart_at I x).target ∩
(ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source))
(ext_chart_at I x x) :=
begin
rw [cont_mdiff_within_at, lift_prop_within_at, cont_diff_within_at_prop],
congr' 3,
mfld_set_tac
end
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in the corresponding extended chart. This form states smoothness of `f`
written in the `ext_chart_at`s within the set `(ext_chart_at I x).symm ⁻¹' s ∩ range I`. This set
is larger than the set
`(ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source)`
used in `cont_mdiff_within_at_iff` but their germs at `ext_chart_at I x x` are equal. It may
be useful to rewrite using `cont_mdiff_within_at_iff''` in the *assumptions* of a lemma and
using `cont_mdiff_within_at_iff` in the goal. -/
lemma cont_mdiff_within_at_iff'' :
cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧
cont_diff_within_at 𝕜 n (written_in_ext_chart_at I I' x f)
((ext_chart_at I x).symm ⁻¹' s ∩ range I) (ext_chart_at I x x) :=
begin
rw [cont_mdiff_within_at_iff, and.congr_right_iff],
set e := ext_chart_at I x, set e' := ext_chart_at I' (f x),
refine λ hc, cont_diff_within_at_congr_nhds _,
rw [← e.image_source_inter_eq', ← ext_chart_at_map_nhds_within_eq_image,
← ext_chart_at_map_nhds_within, inter_comm, nhds_within_inter_of_mem],
exact hc (ext_chart_at_source_mem_nhds _ _)
end
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in the corresponding extended chart in the target. -/
lemma cont_mdiff_within_at_iff_target :
cont_mdiff_within_at I I' n f s x ↔ continuous_within_at f s x ∧
cont_mdiff_within_at I 𝓘(𝕜, E') n ((ext_chart_at I' (f x)) ∘ f)
(s ∩ f ⁻¹' (ext_chart_at I' (f x)).source) x :=
begin
rw [cont_mdiff_within_at, cont_mdiff_within_at, lift_prop_within_at,
lift_prop_within_at, ← and_assoc],
have cont : (continuous_within_at f s x ∧
continuous_within_at ((I' ∘ (chart_at H' (f x))) ∘ f)
(s ∩ f ⁻¹' (chart_at H' (f x)).to_local_equiv.source) x) ↔
continuous_within_at f s x,
{ refine ⟨λ h, h.1, λ h, ⟨h, _⟩⟩,
have h₁ : continuous_within_at _ univ ((chart_at H' (f x)) (f x)),
{ exact (model_with_corners.continuous I').continuous_within_at },
have h₂ := (chart_at H' (f x)).continuous_to_fun.continuous_within_at (mem_chart_source _ _),
convert (h₁.comp' h₂).comp' h,
simp },
simp [cont, cont_diff_within_at_prop]
end
lemma smooth_within_at_iff :
smooth_within_at I I' f s x ↔ continuous_within_at f s x ∧
cont_diff_within_at 𝕜 ∞ ((ext_chart_at I' (f x)) ∘ f ∘ (ext_chart_at I x).symm)
((ext_chart_at I x).target ∩
(ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' (f x)).source))
(ext_chart_at I x x) :=
cont_mdiff_within_at_iff
lemma smooth_within_at_iff_target :
smooth_within_at I I' f s x ↔ continuous_within_at f s x ∧
smooth_within_at I 𝓘(𝕜, E') ((ext_chart_at I' (f x)) ∘ f)
(s ∩ f ⁻¹' (ext_chart_at I' (f x)).source) x :=
cont_mdiff_within_at_iff_target
lemma cont_mdiff_at_ext_chart_at :
cont_mdiff_at I 𝓘(𝕜, E) n (ext_chart_at I x) x :=
begin
rw [cont_mdiff_at, cont_mdiff_within_at_iff],
refine ⟨(ext_chart_at_continuous_at _ _).continuous_within_at, _⟩,
refine cont_diff_within_at_id.congr _ _;
simp only with mfld_simps { contextual := tt }
end
include Is I's
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in the corresponding extended chart. -/
lemma cont_mdiff_within_at_iff' {x' : M} {y : M'} (hx : x' ∈ (chart_at H x).source)
(hy : f x' ∈ (chart_at H' y).source) :
cont_mdiff_within_at I I' n f s x' ↔ continuous_within_at f s x' ∧
cont_diff_within_at 𝕜 n ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm)
((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source))
(ext_chart_at I x x') :=
begin
refine ((cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_indep_chart
(structure_groupoid.chart_mem_maximal_atlas _ x) hx
(structure_groupoid.chart_mem_maximal_atlas _ y) hy).trans _,
rw [cont_diff_within_at_prop, iff_eq_eq],
congr' 2,
mfld_set_tac
end
omit I's
lemma cont_mdiff_at_ext_chart_at' {x' : M} (h : x' ∈ (chart_at H x).source) :
cont_mdiff_at I 𝓘(𝕜, E) n (ext_chart_at I x) x' :=
begin
refine (cont_mdiff_within_at_iff' h (mem_chart_source _ _)).2 _,
refine ⟨(ext_chart_at_continuous_at' _ _ _).continuous_within_at, _⟩,
{ rwa ext_chart_at_source },
refine cont_diff_within_at_id.congr' _ _;
simp only [h] with mfld_simps { contextual := tt }
end
include I's
/-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any
extended chart. -/
lemma cont_mdiff_on_iff :
cont_mdiff_on I I' n f s ↔ continuous_on f s ∧
∀ (x : M) (y : M'), cont_diff_on 𝕜 n ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm)
((ext_chart_at I x).target ∩
(ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) :=
begin
split,
{ assume h,
refine ⟨λ x hx, (h x hx).1, λ x y z hz, _⟩,
simp only with mfld_simps at hz,
let w := (ext_chart_at I x).symm z,
have : w ∈ s, by simp only [w, hz] with mfld_simps,
specialize h w this,
have w1 : w ∈ (chart_at H x).source, by simp only [w, hz] with mfld_simps,
have w2 : f w ∈ (chart_at H' y).source, by simp only [w, hz] with mfld_simps,
convert
(((cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_indep_chart
(structure_groupoid.chart_mem_maximal_atlas _ x) w1
(structure_groupoid.chart_mem_maximal_atlas _ y) w2).1 h).2 using 1,
{ mfld_set_tac },
{ simp only [w, hz] with mfld_simps } },
{ rintros ⟨hcont, hdiff⟩ x hx,
refine ⟨hcont x hx, _⟩,
have Z := hdiff x (f x) (ext_chart_at I x x) (by simp only [hx] with mfld_simps),
dsimp [cont_diff_within_at_prop],
convert Z using 1,
mfld_set_tac }
end
/-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any
extended chart in the target. -/
lemma cont_mdiff_on_iff_target :
cont_mdiff_on I I' n f s ↔ continuous_on f s ∧ ∀ (y : M'),
cont_mdiff_on I 𝓘(𝕜, E') n ((ext_chart_at I' y) ∘ f)
(s ∩ f ⁻¹' (ext_chart_at I' y).source) :=
begin
inhabit E',
simp only [cont_mdiff_on_iff, model_with_corners.source_eq, chart_at_self_eq,
local_homeomorph.refl_local_equiv, local_equiv.refl_trans, ext_chart_at.equations._eqn_1,
set.preimage_univ, set.inter_univ, and.congr_right_iff],
intros h,
split,
{ refine λ h' y, ⟨_, λ x _, h' x y⟩,
have h'' : continuous_on _ univ := (model_with_corners.continuous I').continuous_on,
convert (h''.comp' (chart_at H' y).continuous_to_fun).comp' h,
simp },
{ exact λ h' x y, (h' y).2 x default }
end
lemma smooth_on_iff :
smooth_on I I' f s ↔ continuous_on f s ∧
∀ (x : M) (y : M'), cont_diff_on 𝕜 ⊤ ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm)
((ext_chart_at I x).target ∩
(ext_chart_at I x).symm ⁻¹' (s ∩ f ⁻¹' (ext_chart_at I' y).source)) :=
cont_mdiff_on_iff
lemma smooth_on_iff_target :
smooth_on I I' f s ↔ continuous_on f s ∧ ∀ (y : M'),
smooth_on I 𝓘(𝕜, E') ((ext_chart_at I' y) ∘ f)
(s ∩ f ⁻¹' (ext_chart_at I' y).source) :=
cont_mdiff_on_iff_target
/-- One can reformulate smoothness as continuity and smoothness in any extended chart. -/
lemma cont_mdiff_iff :
cont_mdiff I I' n f ↔ continuous f ∧
∀ (x : M) (y : M'), cont_diff_on 𝕜 n ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm)
((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (f ⁻¹' (ext_chart_at I' y).source)) :=
by simp [← cont_mdiff_on_univ, cont_mdiff_on_iff, continuous_iff_continuous_on_univ]
/-- One can reformulate smoothness as continuity and smoothness in any extended chart in the
target. -/
lemma cont_mdiff_iff_target :
cont_mdiff I I' n f ↔ continuous f ∧
∀ (y : M'), cont_mdiff_on I 𝓘(𝕜, E') n ((ext_chart_at I' y) ∘ f)
(f ⁻¹' (ext_chart_at I' y).source) :=
begin
rw [← cont_mdiff_on_univ, cont_mdiff_on_iff_target],
simp [continuous_iff_continuous_on_univ]
end
lemma smooth_iff :
smooth I I' f ↔ continuous f ∧
∀ (x : M) (y : M'), cont_diff_on 𝕜 ⊤ ((ext_chart_at I' y) ∘ f ∘ (ext_chart_at I x).symm)
((ext_chart_at I x).target ∩ (ext_chart_at I x).symm ⁻¹' (f ⁻¹' (ext_chart_at I' y).source)) :=
cont_mdiff_iff
lemma smooth_iff_target :
smooth I I' f ↔ continuous f ∧ ∀ (y : M'), smooth_on I 𝓘(𝕜, E') ((ext_chart_at I' y) ∘ f)
(f ⁻¹' (ext_chart_at I' y).source) :=
cont_mdiff_iff_target
omit Is I's
/-! ### Deducing smoothness from higher smoothness -/
lemma cont_mdiff_within_at.of_le (hf : cont_mdiff_within_at I I' n f s x) (le : m ≤ n) :
cont_mdiff_within_at I I' m f s x :=
⟨hf.1, hf.2.of_le le⟩
lemma cont_mdiff_at.of_le (hf : cont_mdiff_at I I' n f x) (le : m ≤ n) :
cont_mdiff_at I I' m f x :=
cont_mdiff_within_at.of_le hf le
lemma cont_mdiff_on.of_le (hf : cont_mdiff_on I I' n f s) (le : m ≤ n) :
cont_mdiff_on I I' m f s :=
λ x hx, (hf x hx).of_le le
lemma cont_mdiff.of_le (hf : cont_mdiff I I' n f) (le : m ≤ n) :
cont_mdiff I I' m f :=
λ x, (hf x).of_le le
/-! ### Deducing smoothness from smoothness one step beyond -/
lemma cont_mdiff_within_at.of_succ {n : ℕ}
(h : cont_mdiff_within_at I I' n.succ f s x) :
cont_mdiff_within_at I I' n f s x :=
h.of_le (with_top.coe_le_coe.2 (nat.le_succ n))
lemma cont_mdiff_at.of_succ {n : ℕ} (h : cont_mdiff_at I I' n.succ f x) :
cont_mdiff_at I I' n f x :=
cont_mdiff_within_at.of_succ h
lemma cont_mdiff_on.of_succ {n : ℕ} (h : cont_mdiff_on I I' n.succ f s) :
cont_mdiff_on I I' n f s :=
λ x hx, (h x hx).of_succ
lemma cont_mdiff.of_succ {n : ℕ} (h : cont_mdiff I I' n.succ f) :
cont_mdiff I I' n f :=
λ x, (h x).of_succ
/-! ### Deducing continuity from smoothness-/
lemma cont_mdiff_within_at.continuous_within_at
(hf : cont_mdiff_within_at I I' n f s x) : continuous_within_at f s x :=
hf.1
lemma cont_mdiff_at.continuous_at
(hf : cont_mdiff_at I I' n f x) : continuous_at f x :=
(continuous_within_at_univ _ _ ).1 $ cont_mdiff_within_at.continuous_within_at hf
lemma cont_mdiff_on.continuous_on
(hf : cont_mdiff_on I I' n f s) : continuous_on f s :=
λ x hx, (hf x hx).continuous_within_at
lemma cont_mdiff.continuous (hf : cont_mdiff I I' n f) :
continuous f :=
continuous_iff_continuous_at.2 $ λ x, (hf x).continuous_at
/-! ### Deducing differentiability from smoothness -/
lemma cont_mdiff_within_at.mdifferentiable_within_at
(hf : cont_mdiff_within_at I I' n f s x) (hn : 1 ≤ n) :
mdifferentiable_within_at I I' f s x :=
begin
suffices h : mdifferentiable_within_at I I' f (s ∩ (f ⁻¹' (ext_chart_at I' (f x)).source)) x,
{ rwa mdifferentiable_within_at_inter' at h,
apply (hf.1).preimage_mem_nhds_within,
exact is_open.mem_nhds (ext_chart_at_open_source I' (f x)) (mem_ext_chart_source I' (f x)) },
rw mdifferentiable_within_at_iff,
exact ⟨hf.1.mono (inter_subset_left _ _),
(hf.2.differentiable_within_at hn).mono (by mfld_set_tac)⟩,
end
lemma cont_mdiff_at.mdifferentiable_at (hf : cont_mdiff_at I I' n f x) (hn : 1 ≤ n) :
mdifferentiable_at I I' f x :=
mdifferentiable_within_at_univ.1 $ cont_mdiff_within_at.mdifferentiable_within_at hf hn
lemma cont_mdiff_on.mdifferentiable_on (hf : cont_mdiff_on I I' n f s) (hn : 1 ≤ n) :
mdifferentiable_on I I' f s :=
λ x hx, (hf x hx).mdifferentiable_within_at hn
lemma cont_mdiff.mdifferentiable (hf : cont_mdiff I I' n f) (hn : 1 ≤ n) :
mdifferentiable I I' f :=
λ x, (hf x).mdifferentiable_at hn
lemma smooth.mdifferentiable (hf : smooth I I' f) : mdifferentiable I I' f :=
cont_mdiff.mdifferentiable hf le_top
lemma smooth.mdifferentiable_at (hf : smooth I I' f) : mdifferentiable_at I I' f x :=
hf.mdifferentiable x
lemma smooth.mdifferentiable_within_at (hf : smooth I I' f) :
mdifferentiable_within_at I I' f s x :=
hf.mdifferentiable_at.mdifferentiable_within_at
/-! ### `C^∞` smoothness -/
lemma cont_mdiff_within_at_top :
smooth_within_at I I' f s x ↔ (∀n:ℕ, cont_mdiff_within_at I I' n f s x) :=
⟨λ h n, ⟨h.1, cont_diff_within_at_top.1 h.2 n⟩,
λ H, ⟨(H 0).1, cont_diff_within_at_top.2 (λ n, (H n).2)⟩⟩
lemma cont_mdiff_at_top :
smooth_at I I' f x ↔ (∀n:ℕ, cont_mdiff_at I I' n f x) :=
cont_mdiff_within_at_top
lemma cont_mdiff_on_top :
smooth_on I I' f s ↔ (∀n:ℕ, cont_mdiff_on I I' n f s) :=
⟨λ h n, h.of_le le_top, λ h x hx, cont_mdiff_within_at_top.2 (λ n, h n x hx)⟩
lemma cont_mdiff_top :
smooth I I' f ↔ (∀n:ℕ, cont_mdiff I I' n f) :=
⟨λ h n, h.of_le le_top, λ h x, cont_mdiff_within_at_top.2 (λ n, h n x)⟩
lemma cont_mdiff_within_at_iff_nat :
cont_mdiff_within_at I I' n f s x ↔
(∀m:ℕ, (m : with_top ℕ) ≤ n → cont_mdiff_within_at I I' m f s x) :=
begin
refine ⟨λ h m hm, h.of_le hm, λ h, _⟩,
cases n,
{ exact cont_mdiff_within_at_top.2 (λ n, h n le_top) },
{ exact h n le_rfl }
end
/-! ### Restriction to a smaller set -/
lemma cont_mdiff_within_at.mono (hf : cont_mdiff_within_at I I' n f s x) (hts : t ⊆ s) :
cont_mdiff_within_at I I' n f t x :=
structure_groupoid.local_invariant_prop.lift_prop_within_at_mono
(cont_diff_within_at_local_invariant_prop_mono I I' n) hf hts
lemma cont_mdiff_at.cont_mdiff_within_at (hf : cont_mdiff_at I I' n f x) :
cont_mdiff_within_at I I' n f s x :=
cont_mdiff_within_at.mono hf (subset_univ _)
lemma smooth_at.smooth_within_at (hf : smooth_at I I' f x) :
smooth_within_at I I' f s x :=
cont_mdiff_at.cont_mdiff_within_at hf
lemma cont_mdiff_on.mono (hf : cont_mdiff_on I I' n f s) (hts : t ⊆ s) :
cont_mdiff_on I I' n f t :=
λ x hx, (hf x (hts hx)).mono hts
lemma cont_mdiff.cont_mdiff_on (hf : cont_mdiff I I' n f) :
cont_mdiff_on I I' n f s :=
λ x hx, (hf x).cont_mdiff_within_at
lemma smooth.smooth_on (hf : smooth I I' f) :
smooth_on I I' f s :=
cont_mdiff.cont_mdiff_on hf
lemma cont_mdiff_within_at_inter' (ht : t ∈ 𝓝[s] x) :
cont_mdiff_within_at I I' n f (s ∩ t) x ↔ cont_mdiff_within_at I I' n f s x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_inter' ht
lemma cont_mdiff_within_at_inter (ht : t ∈ 𝓝 x) :
cont_mdiff_within_at I I' n f (s ∩ t) x ↔ cont_mdiff_within_at I I' n f s x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_inter ht
lemma cont_mdiff_within_at.cont_mdiff_at
(h : cont_mdiff_within_at I I' n f s x) (ht : s ∈ 𝓝 x) :
cont_mdiff_at I I' n f x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_of_lift_prop_within_at h ht
lemma smooth_within_at.smooth_at
(h : smooth_within_at I I' f s x) (ht : s ∈ 𝓝 x) :
smooth_at I I' f x :=
cont_mdiff_within_at.cont_mdiff_at h ht
include Is
lemma cont_mdiff_on_ext_chart_at :
cont_mdiff_on I 𝓘(𝕜, E) n (ext_chart_at I x) (chart_at H x).source :=
λ x' hx', (cont_mdiff_at_ext_chart_at' hx').cont_mdiff_within_at
include I's
/-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on
a neighborhood of this point. -/
lemma cont_mdiff_within_at_iff_cont_mdiff_on_nhds {n : ℕ} :
cont_mdiff_within_at I I' n f s x ↔
∃ u ∈ 𝓝[insert x s] x, cont_mdiff_on I I' n f u :=
begin
split,
{ assume h,
-- the property is true in charts. We will pull such a good neighborhood in the chart to the
-- manifold. For this, we need to restrict to a small enough set where everything makes sense
obtain ⟨o, o_open, xo, ho, h'o⟩ : ∃ (o : set M),
is_open o ∧ x ∈ o ∧ o ⊆ (chart_at H x).source ∧ o ∩ s ⊆ f ⁻¹' (chart_at H' (f x)).source,
{ have : (chart_at H' (f x)).source ∈ 𝓝 (f x) :=
is_open.mem_nhds (local_homeomorph.open_source _) (mem_chart_source H' (f x)),
rcases mem_nhds_within.1 (h.1.preimage_mem_nhds_within this) with ⟨u, u_open, xu, hu⟩,
refine ⟨u ∩ (chart_at H x).source, _, ⟨xu, mem_chart_source _ _⟩, _, _⟩,
{ exact is_open.inter u_open (local_homeomorph.open_source _) },
{ assume y hy, exact hy.2 },
{ assume y hy, exact hu ⟨hy.1.1, hy.2⟩ } },
have h' : cont_mdiff_within_at I I' n f (s ∩ o) x := h.mono (inter_subset_left _ _),
simp only [cont_mdiff_within_at, lift_prop_within_at, cont_diff_within_at_prop]
at h',
-- let `u` be a good neighborhood in the chart where the function is smooth
rcases h.2.cont_diff_on le_rfl with ⟨u, u_nhds, u_subset, hu⟩,
-- pull it back to the manifold, and intersect with a suitable neighborhood of `x`, to get the
-- desired good neighborhood `v`.
let v := ((insert x s) ∩ o) ∩ (ext_chart_at I x) ⁻¹' u,
have v_incl : v ⊆ (chart_at H x).source := λ y hy, ho hy.1.2,
have v_incl' : ∀ y ∈ v, f y ∈ (chart_at H' (f x)).source,
{ assume y hy,
rcases hy.1.1 with rfl|h',
{ simp only with mfld_simps },
{ apply h'o ⟨hy.1.2, h'⟩ } },
refine ⟨v, _, _⟩,
show v ∈ 𝓝[insert x s] x,
{ rw nhds_within_restrict _ xo o_open,
refine filter.inter_mem self_mem_nhds_within _,
suffices : u ∈ 𝓝[(ext_chart_at I x) '' (insert x s ∩ o)] (ext_chart_at I x x),
from (ext_chart_at_continuous_at I x).continuous_within_at.preimage_mem_nhds_within' this,
apply nhds_within_mono _ _ u_nhds,
rw image_subset_iff,
assume y hy,
rcases hy.1 with rfl|h',
{ simp only [mem_insert_iff] with mfld_simps },
{ simp only [mem_insert_iff, ho hy.2, h', h'o ⟨hy.2, h'⟩] with mfld_simps } },
show cont_mdiff_on I I' n f v,
{ assume y hy,
apply
(((cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_indep_chart
(structure_groupoid.chart_mem_maximal_atlas _ x) (v_incl hy)
(structure_groupoid.chart_mem_maximal_atlas _ (f x)) (v_incl' y hy))).2,
split,
{ apply (((ext_chart_at_continuous_on_symm I' (f x) _ _).comp'
(hu _ hy.2).continuous_within_at).comp' (ext_chart_at_continuous_on I x _ _)).congr_mono,
{ assume z hz,
simp only [v_incl hz, v_incl' z hz] with mfld_simps },
{ assume z hz,
simp only [v_incl hz, v_incl' z hz] with mfld_simps,
exact hz.2 },
{ simp only [v_incl hy, v_incl' y hy] with mfld_simps },
{ simp only [v_incl hy, v_incl' y hy] with mfld_simps },
{ simp only [v_incl hy] with mfld_simps } },
{ apply hu.mono,
{ assume z hz,
simp only [v] with mfld_simps at hz,
have : I ((chart_at H x) (((chart_at H x).symm) (I.symm z))) ∈ u, by simp only [hz],
simpa only [hz] with mfld_simps using this },
{ have exty : I (chart_at H x y) ∈ u := hy.2,
simp only [v_incl hy, v_incl' y hy, exty, hy.1.1, hy.1.2] with mfld_simps } } } },
{ rintros ⟨u, u_nhds, hu⟩,
have : cont_mdiff_within_at I I' ↑n f (insert x s ∩ u) x,
{ have : x ∈ insert x s := mem_insert x s,
exact hu.mono (inter_subset_right _ _) _ ⟨this, mem_of_mem_nhds_within this u_nhds⟩ },
rw cont_mdiff_within_at_inter' u_nhds at this,
exact this.mono (subset_insert x s) }
end
/-- A function is `C^n` at a point, for `n : ℕ`, if and only if it is `C^n` on
a neighborhood of this point. -/
lemma cont_mdiff_at_iff_cont_mdiff_on_nhds {n : ℕ} :
cont_mdiff_at I I' n f x ↔ ∃ u ∈ 𝓝 x, cont_mdiff_on I I' n f u :=
by simp [← cont_mdiff_within_at_univ, cont_mdiff_within_at_iff_cont_mdiff_on_nhds,
nhds_within_univ]
omit Is I's
/-! ### Congruence lemmas -/
lemma cont_mdiff_within_at.congr
(h : cont_mdiff_within_at I I' n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : f₁ x = f x) : cont_mdiff_within_at I I' n f₁ s x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr h h₁ hx
lemma cont_mdiff_within_at_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) :
cont_mdiff_within_at I I' n f₁ s x ↔ cont_mdiff_within_at I I' n f s x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr_iff h₁ hx
lemma cont_mdiff_within_at.congr_of_eventually_eq
(h : cont_mdiff_within_at I I' n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f)
(hx : f₁ x = f x) : cont_mdiff_within_at I I' n f₁ s x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_within_at_congr_of_eventually_eq
h h₁ hx
lemma filter.eventually_eq.cont_mdiff_within_at_iff
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
cont_mdiff_within_at I I' n f₁ s x ↔ cont_mdiff_within_at I I' n f s x :=
(cont_diff_within_at_local_invariant_prop I I' n)
.lift_prop_within_at_congr_iff_of_eventually_eq h₁ hx
lemma cont_mdiff_at.congr_of_eventually_eq
(h : cont_mdiff_at I I' n f x) (h₁ : f₁ =ᶠ[𝓝 x] f) :
cont_mdiff_at I I' n f₁ x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_congr_of_eventually_eq h h₁
lemma filter.eventually_eq.cont_mdiff_at_iff (h₁ : f₁ =ᶠ[𝓝 x] f) :
cont_mdiff_at I I' n f₁ x ↔ cont_mdiff_at I I' n f x :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_at_congr_iff_of_eventually_eq h₁
lemma cont_mdiff_on.congr (h : cont_mdiff_on I I' n f s) (h₁ : ∀ y ∈ s, f₁ y = f y) :
cont_mdiff_on I I' n f₁ s :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_congr h h₁
lemma cont_mdiff_on_congr (h₁ : ∀ y ∈ s, f₁ y = f y) :
cont_mdiff_on I I' n f₁ s ↔ cont_mdiff_on I I' n f s :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_congr_iff h₁
/-! ### Locality -/
/-- Being `C^n` is a local property. -/
lemma cont_mdiff_on_of_locally_cont_mdiff_on
(h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ cont_mdiff_on I I' n f (s ∩ u)) :
cont_mdiff_on I I' n f s :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_on_of_locally_lift_prop_on h
lemma cont_mdiff_of_locally_cont_mdiff_on
(h : ∀x, ∃u, is_open u ∧ x ∈ u ∧ cont_mdiff_on I I' n f u) :
cont_mdiff I I' n f :=
(cont_diff_within_at_local_invariant_prop I I' n).lift_prop_of_locally_lift_prop_on h
/-! ### Smoothness of the composition of smooth functions between manifolds -/
section composition
variables {E'' : Type*} [normed_group E''] [normed_space 𝕜 E'']
{H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''}
{M'' : Type*} [topological_space M''] [charted_space H'' M'']
/-- The composition of `C^n` functions within domains at points is `C^n`. -/
lemma cont_mdiff_within_at.comp {t : set M'} {g : M' → M''} (x : M)
(hg : cont_mdiff_within_at I' I'' n g t (f x))
(hf : cont_mdiff_within_at I I' n f s x)
(st : maps_to f s t) : cont_mdiff_within_at I I'' n (g ∘ f) s x :=
begin
rw cont_mdiff_within_at_iff'' at hg hf ⊢,
refine ⟨hg.1.comp hf.1 st, _⟩,
set e := ext_chart_at I x,
set e' := ext_chart_at I' (f x),
set e'' := ext_chart_at I'' (g (f x)),
have : e' (f x) = (written_in_ext_chart_at I I' x f) (e x),
by simp only [e, e'] with mfld_simps,
rw this at hg,
have A : ∀ᶠ y in 𝓝[e.symm ⁻¹' s ∩ range I] e x,
y ∈ e.target ∧ f (e.symm y) ∈ t ∧ f (e.symm y) ∈ e'.source ∧ g (f (e.symm y)) ∈ e''.source,
{ simp only [← ext_chart_at_map_nhds_within, eventually_map],
filter_upwards [hf.1.tendsto (ext_chart_at_source_mem_nhds I' (f x)),
(hg.1.comp hf.1 st).tendsto (ext_chart_at_source_mem_nhds I'' (g (f x))),
(inter_mem_nhds_within s (ext_chart_at_source_mem_nhds I x))],
rintros x' (hfx' : f x' ∈ _) (hgfx' : g (f x') ∈ _) ⟨hx's, hx'⟩,
simp only [e.map_source hx', true_and, e.left_inv hx', st hx's, *] },
refine ((hg.2.comp _ (hf.2.mono (inter_subset_right _ _)) (inter_subset_left _ _)).mono_of_mem
(inter_mem _ self_mem_nhds_within)).congr_of_eventually_eq _ _,
{ filter_upwards [A],
rintro x' ⟨hx', ht, hfx', hgfx'⟩,
simp only [*, mem_preimage, written_in_ext_chart_at, (∘), mem_inter_eq, e'.left_inv, true_and],
exact mem_range_self _ },
{ filter_upwards [A],
rintro x' ⟨hx', ht, hfx', hgfx'⟩,
simp only [*, (∘), written_in_ext_chart_at, e'.left_inv] },
{ simp only [written_in_ext_chart_at, (∘), mem_ext_chart_source, e.left_inv, e'.left_inv] }
end
/-- The composition of `C^n` functions on domains is `C^n`. -/
lemma cont_mdiff_on.comp {t : set M'} {g : M' → M''}
(hg : cont_mdiff_on I' I'' n g t) (hf : cont_mdiff_on I I' n f s)
(st : s ⊆ f ⁻¹' t) : cont_mdiff_on I I'' n (g ∘ f) s :=
λ x hx, (hg _ (st hx)).comp x (hf x hx) st
/-- The composition of `C^n` functions on domains is `C^n`. -/
lemma cont_mdiff_on.comp' {t : set M'} {g : M' → M''}
(hg : cont_mdiff_on I' I'' n g t) (hf : cont_mdiff_on I I' n f s) :
cont_mdiff_on I I'' n (g ∘ f) (s ∩ f ⁻¹' t) :=
hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
/-- The composition of `C^n` functions is `C^n`. -/
lemma cont_mdiff.comp {g : M' → M''}
(hg : cont_mdiff I' I'' n g) (hf : cont_mdiff I I' n f) :
cont_mdiff I I'' n (g ∘ f) :=
begin
rw ← cont_mdiff_on_univ at hf hg ⊢,
exact hg.comp hf subset_preimage_univ,
end
/-- The composition of `C^n` functions within domains at points is `C^n`. -/
lemma cont_mdiff_within_at.comp' {t : set M'} {g : M' → M''} (x : M)
(hg : cont_mdiff_within_at I' I'' n g t (f x))
(hf : cont_mdiff_within_at I I' n f s x) :
cont_mdiff_within_at I I'' n (g ∘ f) (s ∩ f⁻¹' t) x :=
hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
/-- `g ∘ f` is `C^n` within `s` at `x` if `g` is `C^n` at `f x` and
`f` is `C^n` within `s` at `x`. -/
lemma cont_mdiff_at.comp_cont_mdiff_within_at {g : M' → M''} (x : M)
(hg : cont_mdiff_at I' I'' n g (f x)) (hf : cont_mdiff_within_at I I' n f s x) :
cont_mdiff_within_at I I'' n (g ∘ f) s x :=
hg.comp x hf (maps_to_univ _ _)
/-- The composition of `C^n` functions at points is `C^n`. -/
lemma cont_mdiff_at.comp {g : M' → M''} (x : M)
(hg : cont_mdiff_at I' I'' n g (f x)) (hf : cont_mdiff_at I I' n f x) :
cont_mdiff_at I I'' n (g ∘ f) x :=
hg.comp x hf (maps_to_univ _ _)
lemma cont_mdiff.comp_cont_mdiff_on {f : M → M'} {g : M' → M''} {s : set M}
(hg : cont_mdiff I' I'' n g) (hf : cont_mdiff_on I I' n f s) :
cont_mdiff_on I I'' n (g ∘ f) s :=
hg.cont_mdiff_on.comp hf set.subset_preimage_univ
lemma smooth.comp_smooth_on {f : M → M'} {g : M' → M''} {s : set M}
(hg : smooth I' I'' g) (hf : smooth_on I I' f s) :
smooth_on I I'' (g ∘ f) s :=
hg.smooth_on.comp hf set.subset_preimage_univ
end composition
/-! ### Atlas members are smooth -/
section atlas
variables {e : local_homeomorph M H}
include Is
/-- An atlas member is `C^n` for any `n`. -/
lemma cont_mdiff_on_of_mem_maximal_atlas
(h : e ∈ maximal_atlas I M) : cont_mdiff_on I I n e e.source :=
cont_mdiff_on.of_le
((cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_on_of_mem_maximal_atlas
(cont_diff_within_at_local_invariant_prop_id I) h) le_top
/-- The inverse of an atlas member is `C^n` for any `n`. -/
lemma cont_mdiff_on_symm_of_mem_maximal_atlas
(h : e ∈ maximal_atlas I M) : cont_mdiff_on I I n e.symm e.target :=
cont_mdiff_on.of_le
((cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_on_symm_of_mem_maximal_atlas
(cont_diff_within_at_local_invariant_prop_id I) h) le_top
lemma cont_mdiff_on_chart :
cont_mdiff_on I I n (chart_at H x) (chart_at H x).source :=
cont_mdiff_on_of_mem_maximal_atlas
((cont_diff_groupoid ⊤ I).chart_mem_maximal_atlas x)
lemma cont_mdiff_on_chart_symm :
cont_mdiff_on I I n (chart_at H x).symm (chart_at H x).target :=
cont_mdiff_on_symm_of_mem_maximal_atlas
((cont_diff_groupoid ⊤ I).chart_mem_maximal_atlas x)
end atlas
/-! ### The identity is smooth -/
section id
lemma cont_mdiff_id : cont_mdiff I I n (id : M → M) :=
cont_mdiff.of_le ((cont_diff_within_at_local_invariant_prop I I ∞).lift_prop_id
(cont_diff_within_at_local_invariant_prop_id I)) le_top
lemma smooth_id : smooth I I (id : M → M) := cont_mdiff_id
lemma cont_mdiff_on_id : cont_mdiff_on I I n (id : M → M) s :=
cont_mdiff_id.cont_mdiff_on
lemma smooth_on_id : smooth_on I I (id : M → M) s := cont_mdiff_on_id
lemma cont_mdiff_at_id : cont_mdiff_at I I n (id : M → M) x :=
cont_mdiff_id.cont_mdiff_at
lemma smooth_at_id : smooth_at I I (id : M → M) x := cont_mdiff_at_id
lemma cont_mdiff_within_at_id : cont_mdiff_within_at I I n (id : M → M) s x :=
cont_mdiff_at_id.cont_mdiff_within_at
lemma smooth_within_at_id : smooth_within_at I I (id : M → M) s x := cont_mdiff_within_at_id
end id
/-! ### Constants are smooth -/
section id
variable {c : M'}
lemma cont_mdiff_const : cont_mdiff I I' n (λ (x : M), c) :=
begin
assume x,
refine ⟨continuous_within_at_const, _⟩,
simp only [cont_diff_within_at_prop, (∘)],
exact cont_diff_within_at_const,
end
@[to_additive]
lemma cont_mdiff_one [has_one M'] : cont_mdiff I I' n (1 : M → M') :=
by simp only [pi.one_def, cont_mdiff_const]
lemma smooth_const : smooth I I' (λ (x : M), c) := cont_mdiff_const
@[to_additive]
lemma smooth_one [has_one M'] : smooth I I' (1 : M → M') :=
by simp only [pi.one_def, smooth_const]
lemma cont_mdiff_on_const : cont_mdiff_on I I' n (λ (x : M), c) s :=
cont_mdiff_const.cont_mdiff_on
@[to_additive]
lemma cont_mdiff_on_one [has_one M'] : cont_mdiff_on I I' n (1 : M → M') s :=
cont_mdiff_one.cont_mdiff_on
lemma smooth_on_const : smooth_on I I' (λ (x : M), c) s :=
cont_mdiff_on_const
@[to_additive]
lemma smooth_on_one [has_one M'] : smooth_on I I' (1 : M → M') s :=
cont_mdiff_on_one
lemma cont_mdiff_at_const : cont_mdiff_at I I' n (λ (x : M), c) x :=
cont_mdiff_const.cont_mdiff_at
@[to_additive]
lemma cont_mdiff_at_one [has_one M'] : cont_mdiff_at I I' n (1 : M → M') x :=
cont_mdiff_one.cont_mdiff_at
lemma smooth_at_const : smooth_at I I' (λ (x : M), c) x :=
cont_mdiff_at_const
@[to_additive]
lemma smooth_at_one [has_one M'] : smooth_at I I' (1 : M → M') x :=
cont_mdiff_at_one
lemma cont_mdiff_within_at_const : cont_mdiff_within_at I I' n (λ (x : M), c) s x :=
cont_mdiff_at_const.cont_mdiff_within_at
@[to_additive]
lemma cont_mdiff_within_at_one [has_one M'] :
cont_mdiff_within_at I I' n (1 : M → M') s x :=
cont_mdiff_at_const.cont_mdiff_within_at
lemma smooth_within_at_const : smooth_within_at I I' (λ (x : M), c) s x :=
cont_mdiff_within_at_const
@[to_additive]
lemma smooth_within_at_one [has_one M'] : smooth_within_at I I' (1 : M → M') s x :=
cont_mdiff_within_at_one
end id
lemma cont_mdiff_of_support {f : M → F}
(hf : ∀ x ∈ tsupport f, cont_mdiff_at I 𝓘(𝕜, F) n f x) :
cont_mdiff I 𝓘(𝕜, F) n f :=
begin
intro x,
by_cases hx : x ∈ tsupport f,
{ exact hf x hx },
{ refine cont_mdiff_at.congr_of_eventually_eq _ (eventually_eq_zero_nhds.2 hx),
exact cont_mdiff_at_const }
end
/-! ### Equivalence with the basic definition for functions between vector spaces -/
section module
lemma cont_mdiff_within_at_iff_cont_diff_within_at {f : E → E'} {s : set E} {x : E} :
cont_mdiff_within_at 𝓘(𝕜, E) 𝓘(𝕜, E') n f s x
↔ cont_diff_within_at 𝕜 n f s x :=
begin
simp only [cont_mdiff_within_at, lift_prop_within_at, cont_diff_within_at_prop,
iff_def] with mfld_simps {contextual := tt},
exact cont_diff_within_at.continuous_within_at
end
alias cont_mdiff_within_at_iff_cont_diff_within_at ↔
cont_mdiff_within_at.cont_diff_within_at
cont_diff_within_at.cont_mdiff_within_at
lemma cont_mdiff_at_iff_cont_diff_at {f : E → E'} {x : E} :
cont_mdiff_at 𝓘(𝕜, E) 𝓘(𝕜, E') n f x
↔ cont_diff_at 𝕜 n f x :=
by rw [← cont_mdiff_within_at_univ,
cont_mdiff_within_at_iff_cont_diff_within_at, cont_diff_within_at_univ]
alias cont_mdiff_at_iff_cont_diff_at ↔
cont_mdiff_at.cont_diff_at cont_diff_at.cont_mdiff_at
lemma cont_mdiff_on_iff_cont_diff_on {f : E → E'} {s : set E} :
cont_mdiff_on 𝓘(𝕜, E) 𝓘(𝕜, E') n f s
↔ cont_diff_on 𝕜 n f s :=
forall_congr $ by simp [cont_mdiff_within_at_iff_cont_diff_within_at]
alias cont_mdiff_on_iff_cont_diff_on ↔
cont_mdiff_on.cont_diff_on cont_diff_on.cont_mdiff_on
lemma cont_mdiff_iff_cont_diff {f : E → E'} :
cont_mdiff 𝓘(𝕜, E) 𝓘(𝕜, E') n f
↔ cont_diff 𝕜 n f :=
by rw [← cont_diff_on_univ, ← cont_mdiff_on_univ,
cont_mdiff_on_iff_cont_diff_on]
alias cont_mdiff_iff_cont_diff ↔
cont_mdiff.cont_diff cont_diff.cont_mdiff
end module
/-! ### The tangent map of a smooth function is smooth -/
section tangent_map
/-- If a function is `C^n` with `1 ≤ n` on a domain with unique derivatives, then its bundled
derivative is continuous. In this auxiliary lemma, we prove this fact when the source and target
space are model spaces in models with corners. The general fact is proved in
`cont_mdiff_on.continuous_on_tangent_map_within`-/
lemma cont_mdiff_on.continuous_on_tangent_map_within_aux
{f : H → H'} {s : set H}
(hf : cont_mdiff_on I I' n f s) (hn : 1 ≤ n) (hs : unique_mdiff_on I s) :
continuous_on (tangent_map_within I I' f s) ((tangent_bundle.proj I H) ⁻¹' s) :=
begin
suffices h : continuous_on (λ (p : H × E), (f p.fst,
(fderiv_within 𝕜 (written_in_ext_chart_at I I' p.fst f) (I.symm ⁻¹' s ∩ range I)
((ext_chart_at I p.fst) p.fst) : E →L[𝕜] E') p.snd)) (prod.fst ⁻¹' s),
{ have A := (tangent_bundle_model_space_homeomorph H I).continuous,
rw continuous_iff_continuous_on_univ at A,
have B := ((tangent_bundle_model_space_homeomorph H' I').symm.continuous.comp_continuous_on h)
.comp' A,
have : (univ ∩ ⇑(tangent_bundle_model_space_homeomorph H I) ⁻¹' (prod.fst ⁻¹' s)) =
tangent_bundle.proj I H ⁻¹' s,
by { ext ⟨x, v⟩, simp only with mfld_simps },
rw this at B,
apply B.congr,
rintros ⟨x, v⟩ hx,
dsimp [tangent_map_within],
ext, { refl },
simp only with mfld_simps,
apply congr_fun,
apply congr_arg,
rw mdifferentiable_within_at.mfderiv_within (hf.mdifferentiable_on hn x hx),
refl },
suffices h : continuous_on (λ (p : H × E), (fderiv_within 𝕜 (I' ∘ f ∘ I.symm)
(I.symm ⁻¹' s ∩ range I) (I p.fst) : E →L[𝕜] E') p.snd) (prod.fst ⁻¹' s),
{ dsimp [written_in_ext_chart_at, ext_chart_at],
apply continuous_on.prod
(continuous_on.comp hf.continuous_on continuous_fst.continuous_on (subset.refl _)),
apply h.congr,
assume p hp,
refl },
suffices h : continuous_on (fderiv_within 𝕜 (I' ∘ f ∘ I.symm)
(I.symm ⁻¹' s ∩ range I)) (I '' s),
{ have C := continuous_on.comp h I.continuous_to_fun.continuous_on (subset.refl _),
have A : continuous (λq : (E →L[𝕜] E') × E, q.1 q.2) :=
is_bounded_bilinear_map_apply.continuous,
have B : continuous_on (λp : H × E,
(fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I)
(I p.1), p.2)) (prod.fst ⁻¹' s),
{ apply continuous_on.prod _ continuous_snd.continuous_on,
refine (continuous_on.comp C continuous_fst.continuous_on _ : _),
exact preimage_mono (subset_preimage_image _ _) },
exact A.comp_continuous_on B },
rw cont_mdiff_on_iff at hf,
let x : H := I.symm (0 : E),
let y : H' := I'.symm (0 : E'),
have A := hf.2 x y,
simp only [I.image_eq, inter_comm] with mfld_simps at A ⊢,
apply A.continuous_on_fderiv_within _ hn,
convert hs.unique_diff_on_target_inter x using 1,
simp only [inter_comm] with mfld_simps
end
/-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is
`C^m` when `m+1 ≤ n`. In this auxiliary lemma, we prove this fact when the source and target space
are model spaces in models with corners. The general fact is proved in
`cont_mdiff_on.cont_mdiff_on_tangent_map_within` -/
lemma cont_mdiff_on.cont_mdiff_on_tangent_map_within_aux
{f : H → H'} {s : set H}
(hf : cont_mdiff_on I I' n f s) (hmn : m + 1 ≤ n) (hs : unique_mdiff_on I s) :
cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s)
((tangent_bundle.proj I H) ⁻¹' s) :=
begin
have m_le_n : m ≤ n,
{ apply le_trans _ hmn,
have : m + 0 ≤ m + 1 := add_le_add_left (zero_le _) _,
simpa only [add_zero] using this },
have one_le_n : 1 ≤ n,
{ apply le_trans _ hmn,
change 0 + 1 ≤ m + 1,
exact add_le_add_right (zero_le _) _ },
have U': unique_diff_on 𝕜 (range I ∩ I.symm ⁻¹' s),
{ assume y hy,
simpa only [unique_mdiff_on, unique_mdiff_within_at, hy.1, inter_comm] with mfld_simps
using hs (I.symm y) hy.2 },
have U : unique_diff_on 𝕜 ((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)) :=
U'.prod unique_diff_on_univ,
rw cont_mdiff_on_iff,
refine ⟨hf.continuous_on_tangent_map_within_aux one_le_n hs, λp q, _⟩,
have A : range I ×ˢ (univ : set E) ∩
((equiv.sigma_equiv_prod H E).symm ∘ λ (p : E × E), ((I.symm) p.fst, p.snd)) ⁻¹'
(tangent_bundle.proj I H ⁻¹' s)
= (range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E),
by { ext ⟨x, v⟩, simp only with mfld_simps },
suffices h : cont_diff_on 𝕜 m (((λ (p : H' × E'), (I' p.fst, p.snd)) ∘
(equiv.sigma_equiv_prod H' E')) ∘ tangent_map_within I I' f s ∘
((equiv.sigma_equiv_prod H E).symm) ∘ λ (p : E × E), (I.symm p.fst, p.snd))
((range ⇑I ∩ ⇑(I.symm) ⁻¹' s) ×ˢ (univ : set E)),
by simpa [A] using h,
change cont_diff_on 𝕜 m (λ (p : E × E),
((I' (f (I.symm p.fst)), ((mfderiv_within I I' f s (I.symm p.fst)) : E → E') p.snd) : E' × E'))
((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)),
-- check that all bits in this formula are `C^n`
have hf' := cont_mdiff_on_iff.1 hf,
have A : cont_diff_on 𝕜 m (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) :=
by simpa only with mfld_simps using (hf'.2 (I.symm 0) (I'.symm 0)).of_le m_le_n,
have B : cont_diff_on 𝕜 m ((I' ∘ f ∘ I.symm) ∘ prod.fst)
((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)) :=
A.comp (cont_diff_fst.cont_diff_on) (prod_subset_preimage_fst _ _),
suffices C : cont_diff_on 𝕜 m (λ (p : E × E),
((fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) p.1 : _) p.2))
((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : set E)),
{ apply cont_diff_on.prod B _,
apply C.congr (λp hp, _),
simp only with mfld_simps at hp,
simp only [mfderiv_within, hf.mdifferentiable_on one_le_n _ hp.2, hp.1, dif_pos]
with mfld_simps },
have D : cont_diff_on 𝕜 m (λ x,
(fderiv_within 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) x))
(range I ∩ I.symm ⁻¹' s),
{ have : cont_diff_on 𝕜 n (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) :=
by simpa only with mfld_simps using (hf'.2 (I.symm 0) (I'.symm 0)),
simpa only [inter_comm] using this.fderiv_within U' hmn },
have := D.comp (cont_diff_fst.cont_diff_on) (prod_subset_preimage_fst _ _),
have := cont_diff_on.prod this (cont_diff_snd.cont_diff_on),
exact is_bounded_bilinear_map_apply.cont_diff.comp_cont_diff_on this,
end
include Is I's
/-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative
is `C^m` when `m+1 ≤ n`. -/
theorem cont_mdiff_on.cont_mdiff_on_tangent_map_within
(hf : cont_mdiff_on I I' n f s) (hmn : m + 1 ≤ n) (hs : unique_mdiff_on I s) :
cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s)
((tangent_bundle.proj I M) ⁻¹' s) :=
begin
/- The strategy of the proof is to avoid unfolding the definitions, and reduce by functoriality
to the case of functions on the model spaces, where we have already proved the result.
Let `l` and `r` be the charts to the left and to the right, so that we have
```
l^{-1} f r
H --------> M ---> M' ---> H'
```
Then the tangent map `T(r ∘ f ∘ l)` is smooth by a previous result. Consider the composition
```
Tl T(r ∘ f ∘ l^{-1}) Tr^{-1}
TM -----> TH -------------------> TH' ---------> TM'
```
where `Tr^{-1}` and `Tl` are the tangent maps of `r^{-1}` and `l`. Writing `Tl` and `Tr^{-1}` as
composition of charts (called `Dl` and `il` for `l` and `Dr` and `ir` in the proof below), it
follows that they are smooth. The composition of all these maps is `Tf`, and is therefore smooth
as a composition of smooth maps.
-/
have m_le_n : m ≤ n,
{ apply le_trans _ hmn,
have : m + 0 ≤ m + 1 := add_le_add_left (zero_le _) _,
simpa only [add_zero] },
have one_le_n : 1 ≤ n,
{ apply le_trans _ hmn,
change 0 + 1 ≤ m + 1,
exact add_le_add_right (zero_le _) _ },
/- First step: local reduction on the space, to a set `s'` which is contained in chart domains. -/
refine cont_mdiff_on_of_locally_cont_mdiff_on (λp hp, _),
have hf' := cont_mdiff_on_iff.1 hf,
simp [tangent_bundle.proj] at hp,
let l := chart_at H p.1,
set Dl := chart_at (model_prod H E) p with hDl,
let r := chart_at H' (f p.1),
let Dr := chart_at (model_prod H' E') (tangent_map_within I I' f s p),
let il := chart_at (model_prod H E) (tangent_map I I l p),
let ir := chart_at (model_prod H' E') (tangent_map I I' (r ∘ f) p),
let s' := f ⁻¹' r.source ∩ s ∩ l.source,
let s'_lift := (tangent_bundle.proj I M)⁻¹' s',
let s'l := l.target ∩ l.symm ⁻¹' s',
let s'l_lift := (tangent_bundle.proj I H) ⁻¹' s'l,
rcases continuous_on_iff'.1 hf'.1 r.source r.open_source with ⟨o, o_open, ho⟩,
suffices h : cont_mdiff_on I.tangent I'.tangent m (tangent_map_within I I' f s) s'_lift,
{ refine ⟨(tangent_bundle.proj I M)⁻¹' (o ∩ l.source), _, _, _⟩,
show is_open ((tangent_bundle.proj I M)⁻¹' (o ∩ l.source)), from
(is_open.inter o_open l.open_source).preimage (tangent_bundle_proj_continuous _ _) ,
show p ∈ tangent_bundle.proj I M ⁻¹' (o ∩ l.source),
{ simp [tangent_bundle.proj] at ⊢,
have : p.1 ∈ f ⁻¹' r.source ∩ s, by simp [hp],
rw ho at this,
exact this.1 },
{ have : tangent_bundle.proj I M ⁻¹' s ∩ tangent_bundle.proj I M ⁻¹' (o ∩ l.source) = s'_lift,
{ dsimp only [s'_lift, s'], rw [ho], mfld_set_tac },
rw this,
exact h } },
/- Second step: check that all functions are smooth, and use the chain rule to write the bundled
derivative as a composition of a function between model spaces and of charts.
Convention: statements about the differentiability of `a ∘ b ∘ c` are named `diff_abc`. Statements
about differentiability in the bundle have a `_lift` suffix. -/
have U' : unique_mdiff_on I s',
{ apply unique_mdiff_on.inter _ l.open_source,
rw [ho, inter_comm],
exact hs.inter o_open },
have U'l : unique_mdiff_on I s'l :=
U'.unique_mdiff_on_preimage (mdifferentiable_chart _ _),
have diff_f : cont_mdiff_on I I' n f s' :=
hf.mono (by mfld_set_tac),
have diff_r : cont_mdiff_on I' I' n r r.source :=
cont_mdiff_on_chart,
have diff_rf : cont_mdiff_on I I' n (r ∘ f) s',
{ apply cont_mdiff_on.comp diff_r diff_f (λx hx, _),
simp only [s'] with mfld_simps at hx, simp only [hx] with mfld_simps },
have diff_l : cont_mdiff_on I I n l.symm s'l,
{ have A : cont_mdiff_on I I n l.symm l.target :=
cont_mdiff_on_chart_symm,
exact A.mono (by mfld_set_tac) },
have diff_rfl : cont_mdiff_on I I' n (r ∘ f ∘ l.symm) s'l,
{ apply cont_mdiff_on.comp diff_rf diff_l,
mfld_set_tac },
have diff_rfl_lift : cont_mdiff_on I.tangent I'.tangent m
(tangent_map_within I I' (r ∘ f ∘ l.symm) s'l) s'l_lift :=
diff_rfl.cont_mdiff_on_tangent_map_within_aux hmn U'l,
have diff_irrfl_lift : cont_mdiff_on I.tangent I'.tangent m
(ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l)) s'l_lift,
{ have A : cont_mdiff_on I'.tangent I'.tangent m ir ir.source := cont_mdiff_on_chart,
exact cont_mdiff_on.comp A diff_rfl_lift (λp hp, by simp only [ir] with mfld_simps) },
have diff_Drirrfl_lift : cont_mdiff_on I.tangent I'.tangent m
(Dr.symm ∘ (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l))) s'l_lift,
{ have A : cont_mdiff_on I'.tangent I'.tangent m Dr.symm Dr.target :=
cont_mdiff_on_chart_symm,
apply cont_mdiff_on.comp A diff_irrfl_lift (λp hp, _),
simp only [s'l_lift, tangent_bundle.proj] with mfld_simps at hp,
simp only [ir, @local_equiv.refl_coe (model_prod H' E'), hp] with mfld_simps },
-- conclusion of this step: the composition of all the maps above is smooth
have diff_DrirrflilDl : cont_mdiff_on I.tangent I'.tangent m
(Dr.symm ∘ (ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l)) ∘
(il.symm ∘ Dl)) s'_lift,
{ have A : cont_mdiff_on I.tangent I.tangent m Dl Dl.source := cont_mdiff_on_chart,
have A' : cont_mdiff_on I.tangent I.tangent m Dl s'_lift,
{ apply A.mono (λp hp, _),
simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hp,
simp only [Dl, hp] with mfld_simps },
have B : cont_mdiff_on I.tangent I.tangent m il.symm il.target :=
cont_mdiff_on_chart_symm,
have C : cont_mdiff_on I.tangent I.tangent m (il.symm ∘ Dl) s'_lift :=
cont_mdiff_on.comp B A' (λp hp, by simp only [il] with mfld_simps),
apply cont_mdiff_on.comp diff_Drirrfl_lift C (λp hp, _),
simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hp,
simp only [il, s'l_lift, hp, tangent_bundle.proj] with mfld_simps },
/- Third step: check that the composition of all the maps indeed coincides with the derivative we
are looking for -/
have eq_comp : ∀q ∈ s'_lift, tangent_map_within I I' f s q =
(Dr.symm ∘ ir ∘ (tangent_map_within I I' (r ∘ f ∘ l.symm) s'l) ∘
(il.symm ∘ Dl)) q,
{ assume q hq,
simp only [s'_lift, tangent_bundle.proj] with mfld_simps at hq,
have U'q : unique_mdiff_within_at I s' q.1,
by { apply U', simp only [hq, s'] with mfld_simps },
have U'lq : unique_mdiff_within_at I s'l (Dl q).1,
by { apply U'l, simp only [hq, s'l] with mfld_simps },
have A : tangent_map_within I I' ((r ∘ f) ∘ l.symm) s'l (il.symm (Dl q)) =
tangent_map_within I I' (r ∘ f) s' (tangent_map_within I I l.symm s'l (il.symm (Dl q))),
{ refine tangent_map_within_comp_at (il.symm (Dl q)) _ _ (λp hp, _) U'lq,
{ apply diff_rf.mdifferentiable_on one_le_n,
simp only [hq] with mfld_simps },
{ apply diff_l.mdifferentiable_on one_le_n,
simp only [s'l, hq] with mfld_simps },
{ simp only with mfld_simps at hp, simp only [hp] with mfld_simps } },
have B : tangent_map_within I I l.symm s'l (il.symm (Dl q)) = q,
{ have : tangent_map_within I I l.symm s'l (il.symm (Dl q))
= tangent_map I I l.symm (il.symm (Dl q)),
{ refine tangent_map_within_eq_tangent_map U'lq _,
refine mdifferentiable_at_atlas_symm _ (chart_mem_atlas _ _) _,
simp only [hq] with mfld_simps },
rw [this, tangent_map_chart_symm, hDl],
{ simp only [hq] with mfld_simps,
have : q ∈ (chart_at (model_prod H E) p).source, by simp only [hq] with mfld_simps,
exact (chart_at (model_prod H E) p).left_inv this },
{ simp only [hq] with mfld_simps } },
have C : tangent_map_within I I' (r ∘ f) s' q
= tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q),
{ refine tangent_map_within_comp_at q _ _ (λr hr, _) U'q,
{ apply diff_r.mdifferentiable_on one_le_n,
simp only [hq] with mfld_simps },
{ apply diff_f.mdifferentiable_on one_le_n,
simp only [hq] with mfld_simps },
{ simp only [s'] with mfld_simps at hr,
simp only [hr] with mfld_simps } },
have D : Dr.symm (ir (tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q)))
= tangent_map_within I I' f s' q,
{ have A : tangent_map_within I' I' r r.source (tangent_map_within I I' f s' q) =
tangent_map I' I' r (tangent_map_within I I' f s' q),
{ apply tangent_map_within_eq_tangent_map,
{ apply is_open.unique_mdiff_within_at _ r.open_source, simp [hq] },
{ refine mdifferentiable_at_atlas _ (chart_mem_atlas _ _) _,
simp only [hq] with mfld_simps } },
have : f p.1 = (tangent_map_within I I' f s p).1 := rfl,
rw [A],
dsimp [r, Dr],
rw [this, tangent_map_chart],
{ simp only [hq] with mfld_simps,
have : tangent_map_within I I' f s' q ∈
(chart_at (model_prod H' E') (tangent_map_within I I' f s p)).source,
by simp only [hq] with mfld_simps,
exact (chart_at (model_prod H' E') (tangent_map_within I I' f s p)).left_inv this },
{ simp only [hq] with mfld_simps } },
have E : tangent_map_within I I' f s' q = tangent_map_within I I' f s q,
{ refine tangent_map_within_subset (by mfld_set_tac) U'q _,
apply hf.mdifferentiable_on one_le_n,
simp only [hq] with mfld_simps },
simp only [(∘), A, B, C, D, E.symm] },
exact diff_DrirrflilDl.congr eq_comp,
end
/-- If a function is `C^n` on a domain with unique derivatives, with `1 ≤ n`, then its bundled
derivative is continuous there. -/
theorem cont_mdiff_on.continuous_on_tangent_map_within
(hf : cont_mdiff_on I I' n f s) (hmn : 1 ≤ n) (hs : unique_mdiff_on I s) :
continuous_on (tangent_map_within I I' f s) ((tangent_bundle.proj I M) ⁻¹' s) :=
begin
have : cont_mdiff_on I.tangent I'.tangent 0 (tangent_map_within I I' f s)
((tangent_bundle.proj I M) ⁻¹' s) :=
hf.cont_mdiff_on_tangent_map_within hmn hs,
exact this.continuous_on
end
/-- If a function is `C^n`, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/
theorem cont_mdiff.cont_mdiff_tangent_map
(hf : cont_mdiff I I' n f) (hmn : m + 1 ≤ n) :
cont_mdiff I.tangent I'.tangent m (tangent_map I I' f) :=
begin
rw ← cont_mdiff_on_univ at hf ⊢,
convert hf.cont_mdiff_on_tangent_map_within hmn unique_mdiff_on_univ,
rw tangent_map_within_univ
end
/-- If a function is `C^n`, with `1 ≤ n`, then its bundled derivative is continuous. -/
theorem cont_mdiff.continuous_tangent_map
(hf : cont_mdiff I I' n f) (hmn : 1 ≤ n) :
continuous (tangent_map I I' f) :=
begin
rw ← cont_mdiff_on_univ at hf,
rw continuous_iff_continuous_on_univ,
convert hf.continuous_on_tangent_map_within hmn unique_mdiff_on_univ,
rw tangent_map_within_univ
end
end tangent_map
/-! ### Smoothness of the projection in a basic smooth bundle -/
namespace basic_smooth_vector_bundle_core
variables (Z : basic_smooth_vector_bundle_core I M E')
lemma cont_mdiff_proj :
cont_mdiff ((I.prod 𝓘(𝕜, E'))) I n
Z.to_topological_vector_bundle_core.proj :=
begin
assume x,
rw [cont_mdiff_at, cont_mdiff_within_at_iff],
refine ⟨Z.to_topological_vector_bundle_core.continuous_proj.continuous_within_at, _⟩,
simp only [(∘), chart_at, chart] with mfld_simps,
apply cont_diff_within_at_fst.congr,
{ rintros ⟨a, b⟩ hab,
simp only with mfld_simps at hab,
simp only [hab] with mfld_simps },
{ simp only with mfld_simps }
end
lemma smooth_proj :
smooth ((I.prod 𝓘(𝕜, E'))) I Z.to_topological_vector_bundle_core.proj :=
cont_mdiff_proj Z
lemma cont_mdiff_on_proj {s : set (Z.to_topological_vector_bundle_core.total_space)} :
cont_mdiff_on ((I.prod 𝓘(𝕜, E'))) I n
Z.to_topological_vector_bundle_core.proj s :=
Z.cont_mdiff_proj.cont_mdiff_on
lemma smooth_on_proj {s : set (Z.to_topological_vector_bundle_core.total_space)} :
smooth_on ((I.prod 𝓘(𝕜, E'))) I Z.to_topological_vector_bundle_core.proj s :=
cont_mdiff_on_proj Z
lemma cont_mdiff_at_proj {p : Z.to_topological_vector_bundle_core.total_space} :
cont_mdiff_at ((I.prod 𝓘(𝕜, E'))) I n
Z.to_topological_vector_bundle_core.proj p :=
Z.cont_mdiff_proj.cont_mdiff_at
lemma smooth_at_proj {p : Z.to_topological_vector_bundle_core.total_space} :
smooth_at ((I.prod 𝓘(𝕜, E'))) I Z.to_topological_vector_bundle_core.proj p :=
Z.cont_mdiff_at_proj
lemma cont_mdiff_within_at_proj
{s : set (Z.to_topological_vector_bundle_core.total_space)}
{p : Z.to_topological_vector_bundle_core.total_space} :
cont_mdiff_within_at ((I.prod 𝓘(𝕜, E'))) I n
Z.to_topological_vector_bundle_core.proj s p :=
Z.cont_mdiff_at_proj.cont_mdiff_within_at
lemma smooth_within_at_proj
{s : set (Z.to_topological_vector_bundle_core.total_space)}
{p : Z.to_topological_vector_bundle_core.total_space} :
smooth_within_at ((I.prod 𝓘(𝕜, E'))) I
Z.to_topological_vector_bundle_core.proj s p :=
Z.cont_mdiff_within_at_proj
/-- If an element of `E'` is invariant under all coordinate changes, then one can define a
corresponding section of the fiber bundle, which is smooth. This applies in particular to the
zero section of a vector bundle. Another example (not yet defined) would be the identity
section of the endomorphism bundle of a vector bundle. -/
lemma smooth_const_section (v : E')
(h : ∀ (i j : atlas H M), ∀ x ∈ i.1.source ∩ j.1.source, Z.coord_change i j (i.1 x) v = v) :
smooth I ((I.prod 𝓘(𝕜, E')))
(show M → Z.to_topological_vector_bundle_core.total_space, from λ x, ⟨x, v⟩) :=
begin
assume x,
rw [cont_mdiff_at, cont_mdiff_within_at_iff],
split,
{ apply continuous.continuous_within_at,
apply topological_fiber_bundle_core.continuous_const_section,
assume i j y hy,
exact h _ _ _ hy },
{ have : cont_diff 𝕜 ⊤ (λ (y : E), (y, v)) := cont_diff_id.prod cont_diff_const,
apply this.cont_diff_within_at.congr,
{ assume y hy,
simp only with mfld_simps at hy,
simp only [chart, hy, chart_at, prod.mk.inj_iff, to_topological_vector_bundle_core]
with mfld_simps,
apply h,
simp only [hy, subtype.val_eq_coe] with mfld_simps,
exact mem_chart_source H (((chart_at H x).symm) ((model_with_corners.symm I) y)) },
{ simp only [chart, chart_at, prod.mk.inj_iff, to_topological_vector_bundle_core]
with mfld_simps,
apply h,
simp only [subtype.val_eq_coe] with mfld_simps,
exact mem_chart_source H x, } }
end
end basic_smooth_vector_bundle_core
/-! ### Smoothness of the tangent bundle projection -/
namespace tangent_bundle
include Is
lemma cont_mdiff_proj :
cont_mdiff I.tangent I n (proj I M) :=
basic_smooth_vector_bundle_core.cont_mdiff_proj _
lemma smooth_proj : smooth I.tangent I (proj I M) :=
basic_smooth_vector_bundle_core.smooth_proj _
lemma cont_mdiff_on_proj {s : set (tangent_bundle I M)} :
cont_mdiff_on I.tangent I n (proj I M) s :=
basic_smooth_vector_bundle_core.cont_mdiff_on_proj _
lemma smooth_on_proj {s : set (tangent_bundle I M)} :
smooth_on I.tangent I (proj I M) s :=
basic_smooth_vector_bundle_core.smooth_on_proj _
lemma cont_mdiff_at_proj {p : tangent_bundle I M} :
cont_mdiff_at I.tangent I n
(proj I M) p :=
basic_smooth_vector_bundle_core.cont_mdiff_at_proj _
lemma smooth_at_proj {p : tangent_bundle I M} :
smooth_at I.tangent I (proj I M) p :=
basic_smooth_vector_bundle_core.smooth_at_proj _
lemma cont_mdiff_within_at_proj
{s : set (tangent_bundle I M)} {p : tangent_bundle I M} :
cont_mdiff_within_at I.tangent I n
(proj I M) s p :=
basic_smooth_vector_bundle_core.cont_mdiff_within_at_proj _
lemma smooth_within_at_proj
{s : set (tangent_bundle I M)} {p : tangent_bundle I M} :
smooth_within_at I.tangent I
(proj I M) s p :=
basic_smooth_vector_bundle_core.smooth_within_at_proj _
variables (I M)
/-- The zero section of the tangent bundle -/
def zero_section : M → tangent_bundle I M := λ x, ⟨x, 0⟩
variables {I M}
lemma smooth_zero_section : smooth I I.tangent (zero_section I M) :=
begin
apply basic_smooth_vector_bundle_core.smooth_const_section (tangent_bundle_core I M) 0,
assume i j x hx,
simp only [tangent_bundle_core, continuous_linear_map.map_zero, continuous_linear_map.coe_coe]
with mfld_simps,
end
open bundle
/-- The derivative of the zero section of the tangent bundle maps `⟨x, v⟩` to `⟨⟨x, 0⟩, ⟨v, 0⟩⟩`.
Note that, as currently framed, this is a statement in coordinates, thus reliant on the choice
of the coordinate system we use on the tangent bundle.
However, the result itself is coordinate-dependent only to the extent that the coordinates
determine a splitting of the tangent bundle. Moreover, there is a canonical splitting at each
point of the zero section (since there is a canonical horizontal space there, the tangent space
to the zero section, in addition to the canonical vertical space which is the kernel of the
derivative of the projection), and this canonical splitting is also the one that comes from the
coordinates on the tangent bundle in our definitions. So this statement is not as crazy as it
may seem.
TODO define splittings of vector bundles; state this result invariantly. -/
lemma tangent_map_tangent_bundle_pure (p : tangent_bundle I M) :
tangent_map I I.tangent (tangent_bundle.zero_section I M) p = ⟨⟨p.1, 0⟩, ⟨p.2, 0⟩⟩ :=
begin
rcases p with ⟨x, v⟩,
have N : I.symm ⁻¹' (chart_at H x).target ∈ 𝓝 (I ((chart_at H x) x)),
{ apply is_open.mem_nhds,
apply (local_homeomorph.open_target _).preimage I.continuous_inv_fun,
simp only with mfld_simps },
have A : mdifferentiable_at I I.tangent (λ (x : M), total_space_mk (tangent_space I) x 0) x :=
tangent_bundle.smooth_zero_section.mdifferentiable_at,
have B : fderiv_within 𝕜 (λ (x_1 : E), (x_1, (0 : E))) (set.range ⇑I) (I ((chart_at H x) x)) v
= (v, 0),
{ rw [fderiv_within_eq_fderiv, differentiable_at.fderiv_prod],
{ simp },
{ exact differentiable_at_id' },
{ exact differentiable_at_const _ },
{ exact model_with_corners.unique_diff_at_image I },
{ exact differentiable_at_id'.prod (differentiable_at_const _) } },
simp only [tangent_bundle.zero_section, tangent_map, mfderiv,
A, dif_pos, chart_at, basic_smooth_vector_bundle_core.chart,
basic_smooth_vector_bundle_core.to_topological_vector_bundle_core, tangent_bundle_core,
function.comp, continuous_linear_map.map_zero] with mfld_simps,
rw ← fderiv_within_inter N (I.unique_diff (I ((chart_at H x) x)) (set.mem_range_self _)) at B,
rw [← fderiv_within_inter N (I.unique_diff (I ((chart_at H x) x)) (set.mem_range_self _)), ← B],
congr' 2,
apply fderiv_within_congr _ (λ y hy, _),
{ simp only [prod.mk.inj_iff] with mfld_simps,
exact ((tangent_bundle_core I M).to_topological_vector_bundle_core.coord_change
((tangent_bundle_core I M).to_topological_vector_bundle_core.index_at (((chart_at H x).symm)
(I.symm (I ((chart_at H x) x))))) ⟨chart_at H x, _⟩ (((chart_at H x).symm)
(I.symm (I ((chart_at H x) x))))).map_zero, },
{ apply unique_diff_within_at.inter (I.unique_diff _ _) N,
simp only with mfld_simps },
{ simp only with mfld_simps at hy,
simp only [hy, prod.mk.inj_iff] with mfld_simps,
exact ((tangent_bundle_core I M).to_topological_vector_bundle_core.coord_change
((tangent_bundle_core I M).to_topological_vector_bundle_core.index_at (((chart_at H x).symm)
(I.symm y))) ⟨chart_at H x, _⟩ (((chart_at H x).symm) (I.symm y))).map_zero, },
end
end tangent_bundle
/-! ### Smoothness of standard maps associated to the product of manifolds -/
section prod_mk
lemma cont_mdiff_within_at.prod_mk {f : M → M'} {g : M → N'}
(hf : cont_mdiff_within_at I I' n f s x) (hg : cont_mdiff_within_at I J' n g s x) :
cont_mdiff_within_at I (I'.prod J') n (λ x, (f x, g x)) s x :=
begin
rw cont_mdiff_within_at_iff'' at *,
exact ⟨hf.1.prod hg.1, hf.2.prod hg.2⟩,
end
lemma cont_mdiff_within_at.prod_mk_space {f : M → E'} {g : M → F'}
(hf : cont_mdiff_within_at I 𝓘(𝕜, E') n f s x)
(hg : cont_mdiff_within_at I 𝓘(𝕜, F') n g s x) :
cont_mdiff_within_at I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) s x :=
begin
rw cont_mdiff_within_at_iff'' at *,
exact ⟨hf.1.prod hg.1, hf.2.prod hg.2⟩,
end
lemma cont_mdiff_at.prod_mk {f : M → M'} {g : M → N'}
(hf : cont_mdiff_at I I' n f x) (hg : cont_mdiff_at I J' n g x) :
cont_mdiff_at I (I'.prod J') n (λ x, (f x, g x)) x :=
hf.prod_mk hg
lemma cont_mdiff_at.prod_mk_space {f : M → E'} {g : M → F'}
(hf : cont_mdiff_at I 𝓘(𝕜, E') n f x) (hg : cont_mdiff_at I 𝓘(𝕜, F') n g x) :
cont_mdiff_at I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) x :=
hf.prod_mk_space hg
lemma cont_mdiff_on.prod_mk {f : M → M'} {g : M → N'}
(hf : cont_mdiff_on I I' n f s) (hg : cont_mdiff_on I J' n g s) :
cont_mdiff_on I (I'.prod J') n (λ x, (f x, g x)) s :=
λ x hx, (hf x hx).prod_mk (hg x hx)
lemma cont_mdiff_on.prod_mk_space {f : M → E'} {g : M → F'}
(hf : cont_mdiff_on I 𝓘(𝕜, E') n f s) (hg : cont_mdiff_on I 𝓘(𝕜, F') n g s) :
cont_mdiff_on I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) s :=
λ x hx, (hf x hx).prod_mk_space (hg x hx)
lemma cont_mdiff.prod_mk {f : M → M'} {g : M → N'}
(hf : cont_mdiff I I' n f) (hg : cont_mdiff I J' n g) :
cont_mdiff I (I'.prod J') n (λ x, (f x, g x)) :=
λ x, (hf x).prod_mk (hg x)
lemma cont_mdiff.prod_mk_space {f : M → E'} {g : M → F'}
(hf : cont_mdiff I 𝓘(𝕜, E') n f) (hg : cont_mdiff I 𝓘(𝕜, F') n g) :
cont_mdiff I 𝓘(𝕜, E' × F') n (λ x, (f x, g x)) :=
λ x, (hf x).prod_mk_space (hg x)
lemma smooth_within_at.prod_mk {f : M → M'} {g : M → N'}
(hf : smooth_within_at I I' f s x) (hg : smooth_within_at I J' g s x) :
smooth_within_at I (I'.prod J') (λ x, (f x, g x)) s x :=
hf.prod_mk hg
lemma smooth_within_at.prod_mk_space {f : M → E'} {g : M → F'}
(hf : smooth_within_at I 𝓘(𝕜, E') f s x) (hg : smooth_within_at I 𝓘(𝕜, F') g s x) :
smooth_within_at I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) s x :=
hf.prod_mk_space hg
lemma smooth_at.prod_mk {f : M → M'} {g : M → N'}
(hf : smooth_at I I' f x) (hg : smooth_at I J' g x) :
smooth_at I (I'.prod J') (λ x, (f x, g x)) x :=
hf.prod_mk hg
lemma smooth_at.prod_mk_space {f : M → E'} {g : M → F'}
(hf : smooth_at I 𝓘(𝕜, E') f x) (hg : smooth_at I 𝓘(𝕜, F') g x) :
smooth_at I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) x :=
hf.prod_mk_space hg
lemma smooth_on.prod_mk {f : M → M'} {g : M → N'}
(hf : smooth_on I I' f s) (hg : smooth_on I J' g s) :
smooth_on I (I'.prod J') (λ x, (f x, g x)) s :=
hf.prod_mk hg
lemma smooth_on.prod_mk_space {f : M → E'} {g : M → F'}
(hf : smooth_on I 𝓘(𝕜, E') f s) (hg : smooth_on I 𝓘(𝕜, F') g s) :
smooth_on I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) s :=
hf.prod_mk_space hg
lemma smooth.prod_mk {f : M → M'} {g : M → N'}
(hf : smooth I I' f) (hg : smooth I J' g) :
smooth I (I'.prod J') (λ x, (f x, g x)) :=
hf.prod_mk hg
lemma smooth.prod_mk_space {f : M → E'} {g : M → F'}
(hf : smooth I 𝓘(𝕜, E') f) (hg : smooth I 𝓘(𝕜, F') g) :
smooth I 𝓘(𝕜, E' × F') (λ x, (f x, g x)) :=
hf.prod_mk_space hg
end prod_mk
section projections
lemma cont_mdiff_within_at_fst {s : set (M × N)} {p : M × N} :
cont_mdiff_within_at (I.prod J) I n prod.fst s p :=
begin
rw cont_mdiff_within_at_iff,
refine ⟨continuous_within_at_fst, _⟩,
refine cont_diff_within_at_fst.congr (λ y hy, _) _,
{ simp only with mfld_simps at hy,
simp only [hy] with mfld_simps },
{ simp only with mfld_simps }
end
lemma cont_mdiff_at_fst {p : M × N} :
cont_mdiff_at (I.prod J) I n prod.fst p :=
cont_mdiff_within_at_fst
lemma cont_mdiff_on_fst {s : set (M × N)} :
cont_mdiff_on (I.prod J) I n prod.fst s :=
λ x hx, cont_mdiff_within_at_fst
lemma cont_mdiff_fst :
cont_mdiff (I.prod J) I n (@prod.fst M N) :=
λ x, cont_mdiff_at_fst
lemma smooth_within_at_fst {s : set (M × N)} {p : M × N} :
smooth_within_at (I.prod J) I prod.fst s p :=
cont_mdiff_within_at_fst
lemma smooth_at_fst {p : M × N} :
smooth_at (I.prod J) I prod.fst p :=
cont_mdiff_at_fst
lemma smooth_on_fst {s : set (M × N)} :
smooth_on (I.prod J) I prod.fst s :=
cont_mdiff_on_fst
lemma smooth_fst :
smooth (I.prod J) I (@prod.fst M N) :=
cont_mdiff_fst
lemma cont_mdiff_within_at_snd {s : set (M × N)} {p : M × N} :
cont_mdiff_within_at (I.prod J) J n prod.snd s p :=
begin
rw cont_mdiff_within_at_iff,
refine ⟨continuous_within_at_snd, _⟩,
refine cont_diff_within_at_snd.congr (λ y hy, _) _,
{ simp only with mfld_simps at hy,
simp only [hy] with mfld_simps },
{ simp only with mfld_simps }
end
lemma cont_mdiff_at_snd {p : M × N} :
cont_mdiff_at (I.prod J) J n prod.snd p :=
cont_mdiff_within_at_snd
lemma cont_mdiff_on_snd {s : set (M × N)} :
cont_mdiff_on (I.prod J) J n prod.snd s :=
λ x hx, cont_mdiff_within_at_snd
lemma cont_mdiff_snd :
cont_mdiff (I.prod J) J n (@prod.snd M N) :=
λ x, cont_mdiff_at_snd
lemma smooth_within_at_snd {s : set (M × N)} {p : M × N} :
smooth_within_at (I.prod J) J prod.snd s p :=
cont_mdiff_within_at_snd
lemma smooth_at_snd {p : M × N} :
smooth_at (I.prod J) J prod.snd p :=
cont_mdiff_at_snd
lemma smooth_on_snd {s : set (M × N)} :
smooth_on (I.prod J) J prod.snd s :=
cont_mdiff_on_snd
lemma smooth_snd :
smooth (I.prod J) J (@prod.snd M N) :=
cont_mdiff_snd
lemma smooth_iff_proj_smooth {f : M → M' × N'} :
(smooth I (I'.prod J') f) ↔ (smooth I I' (prod.fst ∘ f)) ∧ (smooth I J' (prod.snd ∘ f)) :=
begin
split,
{ intro h, exact ⟨smooth_fst.comp h, smooth_snd.comp h⟩ },
{ rintro ⟨h_fst, h_snd⟩, simpa only [prod.mk.eta] using h_fst.prod_mk h_snd, }
end
end projections
section prod_map
variables {g : N → N'} {r : set N} {y : N}
/-- The product map of two `C^n` functions within a set at a point is `C^n`
within the product set at the product point. -/
lemma cont_mdiff_within_at.prod_map' {p : M × N}
(hf : cont_mdiff_within_at I I' n f s p.1)
(hg : cont_mdiff_within_at J J' n g r p.2) :
cont_mdiff_within_at (I.prod J) (I'.prod J') n (prod.map f g) (s ×ˢ r) p :=
(hf.comp p cont_mdiff_within_at_fst (prod_subset_preimage_fst _ _)).prod_mk $
hg.comp p cont_mdiff_within_at_snd (prod_subset_preimage_snd _ _)
lemma cont_mdiff_within_at.prod_map
(hf : cont_mdiff_within_at I I' n f s x) (hg : cont_mdiff_within_at J J' n g r y) :
cont_mdiff_within_at (I.prod J) (I'.prod J') n (prod.map f g) (s ×ˢ r) (x, y) :=
cont_mdiff_within_at.prod_map' hf hg
lemma cont_mdiff_at.prod_map
(hf : cont_mdiff_at I I' n f x) (hg : cont_mdiff_at J J' n g y) :
cont_mdiff_at (I.prod J) (I'.prod J') n (prod.map f g) (x, y) :=
begin
rw ← cont_mdiff_within_at_univ at *,
convert hf.prod_map hg,
exact univ_prod_univ.symm
end
lemma cont_mdiff_at.prod_map' {p : M × N}
(hf : cont_mdiff_at I I' n f p.1) (hg : cont_mdiff_at J J' n g p.2) :
cont_mdiff_at (I.prod J) (I'.prod J') n (prod.map f g) p :=
begin
rcases p,
exact hf.prod_map hg
end
lemma cont_mdiff_on.prod_map
(hf : cont_mdiff_on I I' n f s) (hg : cont_mdiff_on J J' n g r) :
cont_mdiff_on (I.prod J) (I'.prod J') n (prod.map f g) (s ×ˢ r) :=
(hf.comp cont_mdiff_on_fst (prod_subset_preimage_fst _ _)).prod_mk $
hg.comp (cont_mdiff_on_snd) (prod_subset_preimage_snd _ _)
lemma cont_mdiff.prod_map
(hf : cont_mdiff I I' n f) (hg : cont_mdiff J J' n g) :
cont_mdiff (I.prod J) (I'.prod J') n (prod.map f g) :=
begin
assume p,
exact (hf p.1).prod_map' (hg p.2)
end
lemma smooth_within_at.prod_map
(hf : smooth_within_at I I' f s x) (hg : smooth_within_at J J' g r y) :
smooth_within_at (I.prod J) (I'.prod J') (prod.map f g) (s ×ˢ r) (x, y) :=
hf.prod_map hg
lemma smooth_at.prod_map
(hf : smooth_at I I' f x) (hg : smooth_at J J' g y) :
smooth_at (I.prod J) (I'.prod J') (prod.map f g) (x, y) :=
hf.prod_map hg
lemma smooth_on.prod_map
(hf : smooth_on I I' f s) (hg : smooth_on J J' g r) :
smooth_on (I.prod J) (I'.prod J') (prod.map f g) (s ×ˢ r) :=
hf.prod_map hg
lemma smooth.prod_map
(hf : smooth I I' f) (hg : smooth J J' g) :
smooth (I.prod J) (I'.prod J') (prod.map f g) :=
hf.prod_map hg
end prod_map
section pi_space
/-!
### Smoothness of functions with codomain `Π i, F i`
We have no `model_with_corners.pi` yet, so we prove lemmas about functions `f : M → Π i, F i` and
use `𝓘(𝕜, Π i, F i)` as the model space.
-/
variables {ι : Type*} [fintype ι] {Fi : ι → Type*} [Π i, normed_group (Fi i)]
[Π i, normed_space 𝕜 (Fi i)] {φ : M → Π i, Fi i}
lemma cont_mdiff_within_at_pi_space :
cont_mdiff_within_at I (𝓘(𝕜, Π i, Fi i)) n φ s x ↔
∀ i, cont_mdiff_within_at I (𝓘(𝕜, Fi i)) n (λ x, φ x i) s x :=
by simp only [cont_mdiff_within_at_iff'', continuous_within_at_pi,
cont_diff_within_at_pi, forall_and_distrib, written_in_ext_chart_at,
ext_chart_model_space_eq_id, (∘), local_equiv.refl_coe, id]
lemma cont_mdiff_on_pi_space :
cont_mdiff_on I (𝓘(𝕜, Π i, Fi i)) n φ s ↔
∀ i, cont_mdiff_on I (𝓘(𝕜, Fi i)) n (λ x, φ x i) s :=
⟨λ h i x hx, cont_mdiff_within_at_pi_space.1 (h x hx) i,
λ h x hx, cont_mdiff_within_at_pi_space.2 (λ i, h i x hx)⟩
lemma cont_mdiff_at_pi_space :
cont_mdiff_at I (𝓘(𝕜, Π i, Fi i)) n φ x ↔
∀ i, cont_mdiff_at I (𝓘(𝕜, Fi i)) n (λ x, φ x i) x :=
cont_mdiff_within_at_pi_space
lemma cont_mdiff_pi_space :
cont_mdiff I (𝓘(𝕜, Π i, Fi i)) n φ ↔
∀ i, cont_mdiff I (𝓘(𝕜, Fi i)) n (λ x, φ x i) :=
⟨λ h i x, cont_mdiff_at_pi_space.1 (h x) i,
λ h x, cont_mdiff_at_pi_space.2 (λ i, h i x)⟩
lemma smooth_within_at_pi_space :
smooth_within_at I (𝓘(𝕜, Π i, Fi i)) φ s x ↔
∀ i, smooth_within_at I (𝓘(𝕜, Fi i)) (λ x, φ x i) s x :=
cont_mdiff_within_at_pi_space
lemma smooth_on_pi_space :
smooth_on I (𝓘(𝕜, Π i, Fi i)) φ s ↔ ∀ i, smooth_on I (𝓘(𝕜, Fi i)) (λ x, φ x i) s :=
cont_mdiff_on_pi_space
lemma smooth_at_pi_space :
smooth_at I (𝓘(𝕜, Π i, Fi i)) φ x ↔ ∀ i, smooth_at I (𝓘(𝕜, Fi i)) (λ x, φ x i) x :=
cont_mdiff_at_pi_space
lemma smooth_pi_space :
smooth I (𝓘(𝕜, Π i, Fi i)) φ ↔ ∀ i, smooth I (𝓘(𝕜, Fi i)) (λ x, φ x i) :=
cont_mdiff_pi_space
end pi_space
/-! ### Linear maps between normed spaces are smooth -/
lemma continuous_linear_map.cont_mdiff (L : E →L[𝕜] F) :
cont_mdiff 𝓘(𝕜, E) 𝓘(𝕜, F) n L :=
L.cont_diff.cont_mdiff
/-! ### Smoothness of standard operations -/
variables {V : Type*} [normed_group V] [normed_space 𝕜 V]
/-- On any vector space, multiplication by a scalar is a smooth operation. -/
lemma smooth_smul : smooth (𝓘(𝕜).prod 𝓘(𝕜, V)) 𝓘(𝕜, V) (λp : 𝕜 × V, p.1 • p.2) :=
smooth_iff.2 ⟨continuous_smul, λ x y, cont_diff_smul.cont_diff_on⟩
lemma smooth.smul {N : Type*} [topological_space N] [charted_space H N]
{f : N → 𝕜} {g : N → V} (hf : smooth I 𝓘(𝕜) f) (hg : smooth I 𝓘(𝕜, V) g) :
smooth I 𝓘(𝕜, V) (λ p, f p • g p) :=
smooth_smul.comp (hf.prod_mk hg)
lemma smooth_on.smul {N : Type*} [topological_space N] [charted_space H N]
{f : N → 𝕜} {g : N → V} {s : set N} (hf : smooth_on I 𝓘(𝕜) f s) (hg : smooth_on I 𝓘(𝕜, V) g s) :
smooth_on I 𝓘(𝕜, V) (λ p, f p • g p) s :=
smooth_smul.comp_smooth_on (hf.prod_mk hg)
lemma smooth_at.smul {N : Type*} [topological_space N] [charted_space H N]
{f : N → 𝕜} {g : N → V} {x : N} (hf : smooth_at I 𝓘(𝕜) f x) (hg : smooth_at I 𝓘(𝕜, V) g x) :
smooth_at I 𝓘(𝕜, V) (λ p, f p • g p) x :=
smooth_smul.smooth_at.comp _ (hf.prod_mk hg)
|
7501b4310a984219c08d035352714736d6a7467d | 0c1546a496eccfb56620165cad015f88d56190c5 | /library/init/algebra/ac.lean | 76c644b44904d26c7c9f2055ff44d424f1d34340 | [
"Apache-2.0"
] | permissive | Solertis/lean | 491e0939957486f664498fbfb02546e042699958 | 84188c5aa1673fdf37a082b2de8562dddf53df3f | refs/heads/master | 1,610,174,257,606 | 1,486,263,620,000 | 1,486,263,620,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 422 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic
universe variables u
class is_associative (α : Type u) (op : α → α → α) :=
(assoc : ∀ a b c, op (op a b) c = op a (op b c))
class is_commutative (α : Type u) (op : α → α → α) :=
(comm : ∀ a b, op a b = op b a)
|
50914a4633af85a5c447874165535507517a4004 | 618003631150032a5676f229d13a079ac875ff77 | /src/topology/algebra/infinite_sum.lean | cef208725e4cc2c5b999d2144f759cdb94e01aec | [
"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 | 35,430 | 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
Infinite sum over a topological monoid
This sum is known as unconditionally convergent, as it sums to the same value under all possible
permutations. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute
convergence.
Note: There are summable sequences which are not unconditionally convergent! The other way holds
generally, see `has_sum.tendsto_sum_nat`.
Reference:
* Bourbaki: General Topology (1995), Chapter 3 §5 (Infinite sums in commutative groups)
-/
import topology.instances.real
noncomputable theory
open finset filter function classical
open_locale topological_space classical big_operators
variables {α : Type*} {β : Type*} {γ : Type*}
section has_sum
variables [add_comm_monoid α] [topological_space α]
/-- Infinite sum on a topological monoid
The `at_top` filter on `finset α` is the limit of all finite sets towards the entire type. So we sum
up bigger and bigger sets. This sum operation is still invariant under reordering, and a absolute
sum operator.
This is based on Mario Carneiro's infinite sum in Metamath.
For the definition or many statements, α does not need to be a topological monoid. We only add
this assumption later, for the lemmas where it is relevant.
-/
def has_sum (f : β → α) (a : α) : Prop := tendsto (λs:finset β, s.sum f) at_top (𝓝 a)
/-- `summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/
def summable (f : β → α) : Prop := ∃a, has_sum f a
/-- `tsum f` is the sum of `f` it exists, or 0 otherwise -/
def tsum (f : β → α) := if h : summable f then classical.some h else 0
notation `∑'` binders `, ` r:(scoped f, tsum f) := r
variables {f g : β → α} {a b : α} {s : finset β}
lemma summable.has_sum (ha : summable f) : has_sum f (∑'b, f b) :=
by simp [ha, tsum]; exact some_spec ha
lemma has_sum.summable (h : has_sum f a) : summable f := ⟨a, h⟩
/-- Constant zero function has sum `0` -/
lemma has_sum_zero : has_sum (λb, 0 : β → α) 0 :=
by simp [has_sum, tendsto_const_nhds]
lemma summable_zero : summable (λb, 0 : β → α) := has_sum_zero.summable
lemma tsum_eq_zero_of_not_summable (h : ¬ summable f) : (∑'b, f b) = 0 :=
by simp [tsum, h]
/-- If a function `f` vanishes outside of a finite set `s`, then it `has_sum` `s.sum f`. -/
lemma has_sum_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : has_sum f (s.sum f) :=
tendsto_infi' s $ tendsto.congr'
(assume t (ht : s ⊆ t), show s.sum f = t.sum f, from sum_subset ht $ assume x _, hf _)
tendsto_const_nhds
lemma has_sum_fintype [fintype β] (f : β → α) : has_sum f (finset.univ.sum f) :=
has_sum_sum_of_ne_finset_zero $ λ a h, h.elim (mem_univ _)
lemma summable_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : summable f :=
(has_sum_sum_of_ne_finset_zero hf).summable
lemma has_sum_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) :
has_sum f (f b) :=
suffices has_sum f (({b} : finset β).sum f),
by simpa using this,
has_sum_sum_of_ne_finset_zero $ by simpa [hf]
lemma has_sum_ite_eq (b : β) (a : α) : has_sum (λb', if b' = b then a else 0) a :=
begin
convert has_sum_single b _,
{ exact (if_pos rfl).symm },
assume b' hb',
exact if_neg hb'
end
lemma has_sum_of_iso {j : γ → β} {i : β → γ}
(hf : has_sum f a) (h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) : has_sum (f ∘ j) a :=
have ∀x y, j x = j y → x = y,
from assume x y h,
have i (j x) = i (j y), by rw [h],
by rwa [h₁, h₁] at this,
have (λs:finset γ, s.sum (f ∘ j)) = (λs:finset β, s.sum f) ∘ (λs:finset γ, s.image j),
from funext $ assume s, (sum_image $ assume x _ y _, this x y).symm,
show tendsto (λs:finset γ, s.sum (f ∘ j)) at_top (𝓝 a),
by rw [this]; apply hf.comp (tendsto_finset_image_at_top_at_top h₂)
lemma has_sum_iff_has_sum_of_iso {j : γ → β} (i : β → γ)
(h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) :
has_sum (f ∘ j) a ↔ has_sum f a :=
iff.intro
(assume hfj,
have has_sum ((f ∘ j) ∘ i) a, from has_sum_of_iso hfj h₂ h₁,
by simp [(∘), h₂] at this; assumption)
(assume hf, has_sum_of_iso hf h₁ h₂)
lemma equiv.has_sum_iff (e : γ ≃ β) :
has_sum (f ∘ e) a ↔ has_sum f a :=
has_sum_iff_has_sum_of_iso e.symm e.left_inv e.right_inv
lemma equiv.summable_iff (e : γ ≃ β) :
summable (f ∘ e) ↔ summable f :=
⟨λ H, (e.has_sum_iff.1 H.has_sum).summable, λ H, (e.has_sum_iff.2 H.has_sum).summable⟩
lemma has_sum_hom (g : α → γ) [add_comm_monoid γ] [topological_space γ]
[is_add_monoid_hom g] (h₃ : continuous g) (hf : has_sum f a) :
has_sum (g ∘ f) (g a) :=
have (λs:finset β, s.sum (g ∘ f)) = g ∘ (λs:finset β, s.sum f),
from funext $ assume s, s.sum_hom g,
show tendsto (λs:finset β, s.sum (g ∘ f)) at_top (𝓝 (g a)),
by rw [this]; exact tendsto.comp (continuous_iff_continuous_at.mp h₃ a) hf
/-- If `f : ℕ → α` has sum `a`, then the partial sums `∑_{i=0}^{n-1} f i` converge to `a`. -/
lemma has_sum.tendsto_sum_nat {f : ℕ → α} (h : has_sum f a) :
tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) :=
@tendsto.comp _ _ _ finset.range (λ s : finset ℕ, s.sum f) _ _ _ h tendsto_finset_range
lemma has_sum_unique {a₁ a₂ : α} [t2_space α] : has_sum f a₁ → has_sum f a₂ → a₁ = a₂ :=
tendsto_nhds_unique at_top_ne_bot
lemma has_sum_iff_tendsto_nat_of_summable [t2_space α] {f : ℕ → α} {a : α} (hf : summable f) :
has_sum f a ↔ tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) :=
begin
refine ⟨λ h, h.tendsto_sum_nat, λ h, _⟩,
rw tendsto_nhds_unique at_top_ne_bot h hf.has_sum.tendsto_sum_nat,
exact hf.has_sum
end
variable [topological_add_monoid α]
lemma has_sum.add (hf : has_sum f a) (hg : has_sum g b) : has_sum (λb, f b + g b) (a + b) :=
by simp [has_sum, sum_add_distrib]; exact hf.add hg
lemma summable.add (hf : summable f) (hg : summable g) : summable (λb, f b + g b) :=
(hf.has_sum.add hg.has_sum).summable
lemma has_sum_sum {f : γ → β → α} {a : γ → α} {s : finset γ} :
(∀i∈s, has_sum (f i) (a i)) → has_sum (λb, s.sum $ λi, f i b) (s.sum a) :=
finset.induction_on s (by simp [has_sum_zero]) (by simp [has_sum.add] {contextual := tt})
lemma summable_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) :
summable (λb, s.sum $ λi, f i b) :=
(has_sum_sum $ assume i hi, (hf i hi).has_sum).summable
lemma has_sum.sigma [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α}
(ha : has_sum f a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) : has_sum g a :=
assume s' hs',
let
⟨s, hs, hss', hsc⟩ := nhds_is_closed hs',
⟨u, hu⟩ := mem_at_top_sets.mp $ ha hs,
fsts := u.image sigma.fst,
snds := λb, u.bind (λp, (if h : p.1 = b then {cast (congr_arg γ h) p.2} else ∅ : finset (γ b)))
in
have u_subset : u ⊆ fsts.sigma snds,
from subset_iff.mpr $ assume ⟨b, c⟩ hu,
have hb : b ∈ fsts, from finset.mem_image.mpr ⟨_, hu, rfl⟩,
have hc : c ∈ snds b, from mem_bind.mpr ⟨_, hu, by simp; refl⟩,
by simp [mem_sigma, hb, hc] ,
mem_at_top_sets.mpr $ exists.intro fsts $ assume bs (hbs : fsts ⊆ bs),
have h : ∀cs : Π b ∈ bs, finset (γ b),
((⋂b (hb : b ∈ bs), (λp:Πb, finset (γ b), p b) ⁻¹' {cs' | cs b hb ⊆ cs' }) ∩
(λp, bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩))) ⁻¹' s).nonempty,
from assume cs,
let cs' := λb, (if h : b ∈ bs then cs b h else ∅) ∪ snds b in
have sum_eq : bs.sum (λb, (cs' b).sum (λc, f ⟨b, c⟩)) = (bs.sigma cs').sum f,
from sum_sigma.symm,
have (bs.sigma cs').sum f ∈ s,
from hu _ $ finset.subset.trans u_subset $ sigma_mono hbs $
assume b, @finset.subset_union_right (γ b) _ _ _,
exists.intro cs' $
by simp [sum_eq, this]; { intros b hb, simp [cs', hb, finset.subset_union_left] },
have tendsto (λp:(Πb:β, finset (γ b)), bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩)))
(⨅b (h : b ∈ bs), at_top.comap (λp, p b)) (𝓝 (bs.sum g)),
from tendsto_finset_sum bs $
assume c hc, tendsto_infi' c $ tendsto_infi' hc $ by apply tendsto.comp (hf c) tendsto_comap,
have bs.sum g ∈ s,
from mem_of_closed_of_tendsto' this hsc $ forall_sets_nonempty_iff_ne_bot.mp $
begin
simp only [mem_inf_sets, exists_imp_distrib, forall_and_distrib, and_imp,
filter.mem_infi_sets_finset, mem_comap_sets, mem_at_top_sets, and_comm,
mem_principal_sets, set.preimage_subset_iff, exists_prop, skolem],
intros s₁ s₂ s₃ hs₁ hs₃ p hs₂ p' hp cs hp',
have : (⋂b (h : b ∈ bs), (λp:(Πb, finset (γ b)), p b) ⁻¹' {cs' | cs b h ⊆ cs' }) ≤ (⨅b∈bs, p b),
from (infi_le_infi $ assume b, infi_le_infi $ assume hb,
le_trans (set.preimage_mono $ hp' b hb) (hp b hb)),
exact (h _).mono (set.subset.trans (set.inter_subset_inter (le_trans this hs₂) hs₃) hs₁)
end,
hss' this
lemma summable.sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) (hf : ∀b, summable (λc, f ⟨b, c⟩)) : summable (λb, ∑'c, f ⟨b, c⟩) :=
(ha.has_sum.sigma (assume b, (hf b).has_sum)).summable
lemma has_sum.sigma_of_has_sum [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α}
(ha : has_sum g a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) (hf' : summable f) : has_sum f a :=
by simpa [has_sum_unique (hf'.has_sum.sigma hf) ha] using hf'.has_sum
end has_sum
section has_sum_iff_has_sum_of_iso_ne_zero
variables [add_comm_monoid α] [topological_space α]
variables {f : β → α} {g : γ → α} {a : α}
lemma has_sum.has_sum_of_sum_eq
(h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ u'.sum g = v'.sum f)
(hf : has_sum g a) : has_sum f a :=
suffices at_top.map (λs:finset β, s.sum f) ≤ at_top.map (λs:finset γ, s.sum g),
from le_trans this hf,
by rw [map_at_top_eq, map_at_top_eq];
from (le_infi $ assume b, let ⟨v, hv⟩ := h_eq b in infi_le_of_le v $
by simp [set.image_subset_iff]; exact hv)
lemma has_sum_iff_has_sum
(h₁ : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ u'.sum g = v'.sum f)
(h₂ : ∀v:finset β, ∃u:finset γ, ∀u', u ⊆ u' → ∃v', v ⊆ v' ∧ v'.sum f = u'.sum g) :
has_sum f a ↔ has_sum g a :=
⟨has_sum.has_sum_of_sum_eq h₂, has_sum.has_sum_of_sum_eq h₁⟩
variables
(i : Π⦃c⦄, g c ≠ 0 → β) (hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0)
(j : Π⦃b⦄, f b ≠ 0 → γ) (hj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0)
(hji : ∀⦃c⦄ (h : g c ≠ 0), j (hi h) = c)
(hij : ∀⦃b⦄ (h : f b ≠ 0), i (hj h) = b)
(hgj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) = f b)
include hi hj hji hij hgj
-- FIXME this causes a deterministic timeout with `-T50000`
lemma has_sum.has_sum_ne_zero : has_sum g a → has_sum f a :=
have j_inj : ∀x y (hx : f x ≠ 0) (hy : f y ≠ 0), (j hx = j hy ↔ x = y),
from assume x y hx hy,
⟨assume h,
have i (hj hx) = i (hj hy), by simp [h],
by rwa [hij, hij] at this; assumption,
by simp {contextual := tt}⟩,
let ii : finset γ → finset β := λu, u.bind $ λc, if h : g c = 0 then ∅ else {i h} in
let jj : finset β → finset γ := λv, v.bind $ λb, if h : f b = 0 then ∅ else {j h} in
has_sum.has_sum_of_sum_eq $ assume u, exists.intro (ii u) $
assume v hv, exists.intro (u ∪ jj v) $ and.intro (subset_union_left _ _) $
have ∀c:γ, c ∈ u ∪ jj v → c ∉ jj v → g c = 0,
from assume c hc hnc, classical.by_contradiction $ assume h : g c ≠ 0,
have c ∈ u,
from (finset.mem_union.1 hc).resolve_right hnc,
have i h ∈ v,
from hv $ by simp [mem_bind]; existsi c; simp [h, this],
have j (hi h) ∈ jj v,
by simp [mem_bind]; existsi i h; simp [h, hi, this],
by rw [hji h] at this; exact hnc this,
calc (u ∪ jj v).sum g = (jj v).sum g : (sum_subset (subset_union_right _ _) this).symm
... = v.sum _ : sum_bind $ by intros x _ y _ _; by_cases f x = 0; by_cases f y = 0; simp [*]; cc
... = v.sum f : sum_congr rfl $ by intros x hx; by_cases f x = 0; simp [*]
lemma has_sum_iff_has_sum_of_ne_zero : has_sum f a ↔ has_sum g a :=
iff.intro
(has_sum.has_sum_ne_zero j hj i hi hij hji $ assume b hb, by rw [←hgj (hi _), hji])
(has_sum.has_sum_ne_zero i hi j hj hji hij hgj)
lemma summable_iff_summable_ne_zero : summable g ↔ summable f :=
exists_congr $
assume a, has_sum_iff_has_sum_of_ne_zero j hj i hi hij hji $
assume b hb, by rw [←hgj (hi _), hji]
end has_sum_iff_has_sum_of_iso_ne_zero
section has_sum_iff_has_sum_of_bij_ne_zero
variables [add_comm_monoid α] [topological_space α]
variables {f : β → α} {g : γ → α} {a : α}
(i : Π⦃c⦄, g c ≠ 0 → β)
(h₁ : ∀⦃c₁ c₂⦄ (h₁ : g c₁ ≠ 0) (h₂ : g c₂ ≠ 0), i h₁ = i h₂ → c₁ = c₂)
(h₂ : ∀⦃b⦄, f b ≠ 0 → ∃c (h : g c ≠ 0), i h = b)
(h₃ : ∀⦃c⦄ (h : g c ≠ 0), f (i h) = g c)
include i h₁ h₂ h₃
lemma has_sum_iff_has_sum_of_ne_zero_bij : has_sum f a ↔ has_sum g a :=
have hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0,
from assume c h, by simp [h₃, h],
let j : Π⦃b⦄, f b ≠ 0 → γ := λb h, some $ h₂ h in
have hj : ∀⦃b⦄ (h : f b ≠ 0), ∃(h : g (j h) ≠ 0), i h = b,
from assume b h, some_spec $ h₂ h,
have hj₁ : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0,
from assume b h, let ⟨h₁, _⟩ := hj h in h₁,
have hj₂ : ∀⦃b⦄ (h : f b ≠ 0), i (hj₁ h) = b,
from assume b h, let ⟨h₁, h₂⟩ := hj h in h₂,
has_sum_iff_has_sum_of_ne_zero i hi j hj₁
(assume c h, h₁ (hj₁ _) h $ hj₂ _) hj₂ (assume b h, by rw [←h₃ (hj₁ _), hj₂])
lemma summable_iff_summable_ne_zero_bij : summable f ↔ summable g :=
exists_congr $
assume a, has_sum_iff_has_sum_of_ne_zero_bij @i h₁ h₂ h₃
end has_sum_iff_has_sum_of_bij_ne_zero
section subtype
variables [add_comm_monoid α] [topological_space α] {s : finset β} {f : β → α} {a : α}
lemma has_sum_subtype_iff_of_eq_zero (h : ∀ x ∈ s, f x = 0) :
has_sum (λ b : {b // b ∉ s}, f b) a ↔ has_sum f a :=
begin
symmetry,
apply has_sum_iff_has_sum_of_ne_zero_bij (λ (b : {b // b ∉ s}) hb, (b : β)),
{ exact λ c₁ c₂ h₁ h₂ H, subtype.eq H },
{ assume b hb,
have : b ∉ s := λ H, hb (h b H),
exact ⟨⟨b, this⟩, hb, rfl⟩ },
{ dsimp, simp }
end
end subtype
section tsum
variables [add_comm_monoid α] [topological_space α] [t2_space α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma tsum_eq_has_sum (ha : has_sum f a) : (∑'b, f b) = a :=
has_sum_unique (summable.has_sum ⟨a, ha⟩) ha
lemma summable.has_sum_iff (h : summable f) : has_sum f a ↔ (∑'b, f b) = a :=
iff.intro tsum_eq_has_sum (assume eq, eq ▸ h.has_sum)
@[simp] lemma tsum_zero : (∑'b:β, 0:α) = 0 := tsum_eq_has_sum has_sum_zero
lemma tsum_eq_sum {f : β → α} {s : finset β} (hf : ∀b∉s, f b = 0) :
(∑'b, f b) = s.sum f :=
tsum_eq_has_sum $ has_sum_sum_of_ne_finset_zero hf
lemma tsum_fintype [fintype β] (f : β → α) : (∑'b, f b) = finset.univ.sum f :=
tsum_eq_has_sum $ has_sum_fintype f
lemma tsum_eq_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) :
(∑'b, f b) = f b :=
tsum_eq_has_sum $ has_sum_single b hf
@[simp] lemma tsum_ite_eq (b : β) (a : α) : (∑'b', if b' = b then a else 0) = a :=
tsum_eq_has_sum (has_sum_ite_eq b a)
lemma tsum_eq_tsum_of_has_sum_iff_has_sum {f : β → α} {g : γ → α}
(h : ∀{a}, has_sum f a ↔ has_sum g a) : (∑'b, f b) = (∑'c, g c) :=
by_cases
(assume : ∃a, has_sum f a,
let ⟨a, hfa⟩ := this in
have hga : has_sum g a, from h.mp hfa,
by rw [tsum_eq_has_sum hfa, tsum_eq_has_sum hga])
(assume hf : ¬ summable f,
have hg : ¬ summable g, from assume ⟨a, hga⟩, hf ⟨a, h.mpr hga⟩,
by simp [tsum, hf, hg])
lemma tsum_eq_tsum_of_ne_zero {f : β → α} {g : γ → α}
(i : Π⦃c⦄, g c ≠ 0 → β) (hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0)
(j : Π⦃b⦄, f b ≠ 0 → γ) (hj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0)
(hji : ∀⦃c⦄ (h : g c ≠ 0), j (hi h) = c)
(hij : ∀⦃b⦄ (h : f b ≠ 0), i (hj h) = b)
(hgj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) = f b) :
(∑'i, f i) = (∑'j, g j) :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_ne_zero i hi j hj hji hij hgj
lemma tsum_eq_tsum_of_ne_zero_bij {f : β → α} {g : γ → α}
(i : Π⦃c⦄, g c ≠ 0 → β)
(h₁ : ∀⦃c₁ c₂⦄ (h₁ : g c₁ ≠ 0) (h₂ : g c₂ ≠ 0), i h₁ = i h₂ → c₁ = c₂)
(h₂ : ∀⦃b⦄, f b ≠ 0 → ∃c (h : g c ≠ 0), i h = b)
(h₃ : ∀⦃c⦄ (h : g c ≠ 0), f (i h) = g c) :
(∑'i, f i) = (∑'j, g j) :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_ne_zero_bij i h₁ h₂ h₃
lemma tsum_eq_tsum_of_iso (j : γ → β) (i : β → γ)
(h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) :
(∑'c, f (j c)) = (∑'b, f b) :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_iso i h₁ h₂
lemma tsum_equiv (j : γ ≃ β) : (∑'c, f (j c)) = (∑'b, f b) :=
tsum_eq_tsum_of_iso j j.symm (by simp) (by simp)
variable [topological_add_monoid α]
lemma tsum_add (hf : summable f) (hg : summable g) : (∑'b, f b + g b) = (∑'b, f b) + (∑'b, g b) :=
tsum_eq_has_sum $ hf.has_sum.add hg.has_sum
lemma tsum_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) :
(∑'b, s.sum (λi, f i b)) = s.sum (λi, ∑'b, f i b) :=
tsum_eq_has_sum $ has_sum_sum $ assume i hi, (hf i hi).has_sum
lemma tsum_sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(h₁ : ∀b, summable (λc, f ⟨b, c⟩)) (h₂ : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) :=
(tsum_eq_has_sum $ h₂.has_sum.sigma (assume b, (h₁ b).has_sum)).symm
end tsum
section topological_group
variables [add_comm_group α] [topological_space α] [topological_add_group α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum.neg : has_sum f a → has_sum (λb, - f b) (- a) :=
has_sum_hom has_neg.neg continuous_neg
lemma summable.neg (hf : summable f) : summable (λb, - f b) :=
hf.has_sum.neg.summable
lemma has_sum.sub (hf : has_sum f a₁) (hg : has_sum g a₂) : has_sum (λb, f b - g b) (a₁ - a₂) :=
by { simp [sub_eq_add_neg], exact hf.add hg.neg }
lemma summable.sub (hf : summable f) (hg : summable g) : summable (λb, f b - g b) :=
(hf.has_sum.sub hg.has_sum).summable
section tsum
variables [t2_space α]
lemma tsum_neg (hf : summable f) : (∑'b, - f b) = - (∑'b, f b) :=
tsum_eq_has_sum $ hf.has_sum.neg
lemma tsum_sub (hf : summable f) (hg : summable g) : (∑'b, f b - g b) = (∑'b, f b) - (∑'b, g b) :=
tsum_eq_has_sum $ hf.has_sum.sub hg.has_sum
lemma tsum_eq_zero_add {f : ℕ → α} (hf : summable f) : (∑'b, f b) = f 0 + (∑'b, f (b + 1)) :=
begin
let f₁ : ℕ → α := λ n, nat.rec (f 0) (λ _ _, 0) n,
let f₂ : ℕ → α := λ n, nat.rec 0 (λ k _, f (k+1)) n,
have : f = λ n, f₁ n + f₂ n, { ext n, symmetry, cases n, apply add_zero, apply zero_add },
have hf₁ : summable f₁,
{ fapply summable_sum_of_ne_finset_zero,
{ exact {0} },
{ rintros (_ | n) hn,
{ exfalso,
apply hn,
apply finset.mem_singleton_self },
{ refl } } },
have hf₂ : summable f₂,
{ have : f₂ = λ n, f n - f₁ n, ext, rw [eq_sub_iff_add_eq', this],
rw [this], apply hf.sub hf₁ },
conv_lhs { rw [this] },
rw [tsum_add hf₁ hf₂, tsum_eq_single 0],
{ congr' 1,
fapply tsum_eq_tsum_of_ne_zero_bij (λ n _, n + 1),
{ intros _ _ _ _, exact nat.succ_inj },
{ rintros (_ | n) h,
{ contradiction },
{ exact ⟨n, h, rfl⟩ } },
{ intros, refl },
{ apply_instance } },
{ rintros (_ | n) hn,
{ contradiction },
{ refl } },
{ apply_instance }
end
end tsum
/-!
### Sums on subtypes
If `s` is a finset of `α`, we show that the summability of `f` in the whole space and on the subtype
`univ - s` are equivalent, and relate their sums. For a function defined on `ℕ`, we deduce the
formula `(∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i)`, in `sum_add_tsum_nat_add`.
-/
section subtype
variables {s : finset β}
lemma has_sum_subtype_iff :
has_sum (λ b : {b // b ∉ s}, f b) a ↔ has_sum f (a + ∑ b in s, f b) :=
begin
let gs := λ b, if b ∈ s then f b else 0,
let g := λ b, if b ∉ s then f b else 0,
have f_sum_iff : has_sum f (a + ∑ b in s, f b) = has_sum (λ b, g b + gs b) (a + ∑ b in s, f b),
{ congr,
ext i,
simp [gs, g],
split_ifs;
simp },
have g_zero : ∀ b ∈ s, g b = 0,
{ assume b hb,
dsimp [g],
split_ifs,
refl },
have gs_sum : has_sum gs (∑ b in s, f b),
{ have : (∑ b in s, f b) = (∑ b in s, gs b),
{ apply sum_congr rfl (λ b hb, _),
dsimp [gs],
split_ifs,
{ refl },
{ exact false.elim (h hb) } },
rw this,
apply has_sum_sum_of_ne_finset_zero (λ b hb, _),
dsimp [gs],
split_ifs,
{ exact false.elim (hb h) },
{ refl } },
have : (λ b : {b // b ∉ s}, f b) = (λ b : {b // b ∉ s}, g b),
{ ext i,
simp [g],
split_ifs,
{ exact false.elim (i.2 h) },
{ refl } },
rw [this, has_sum_subtype_iff_of_eq_zero g_zero, f_sum_iff],
exact ⟨λ H, H.add gs_sum, λ H, by simpa using H.sub gs_sum⟩,
end
lemma has_sum_subtype_iff' :
has_sum (λ b : {b // b ∉ s}, f b) (a - ∑ b in s, f b) ↔ has_sum f a :=
by simp [has_sum_subtype_iff]
lemma summable_subtype_iff (s : finset β):
summable (λ b : {b // b ∉ s}, f b) ↔ summable f :=
⟨λ H, (has_sum_subtype_iff.1 H.has_sum).summable, λ H, (has_sum_subtype_iff'.2 H.has_sum).summable⟩
lemma sum_add_tsum_subtype [t2_space α] (s : finset β) (h : summable f) :
(∑ b in s, f b) + (∑' (b : {b // b ∉ s}), f b) = (∑' b, f b) :=
by simpa [add_comm] using
has_sum_unique (has_sum_subtype_iff.1 ((summable_subtype_iff s).2 h).has_sum) h.has_sum
lemma summable_nat_add_iff {f : ℕ → α} (k : ℕ) : summable (λ n, f (n + k)) ↔ summable f :=
begin
refine iff.trans _ (summable_subtype_iff (range k)),
rw [← (not_mem_range_equiv k).symm.summable_iff],
refl
end
lemma has_sum_nat_add_iff {f : ℕ → α} (k : ℕ) {a : α} :
has_sum (λ n, f (n + k)) a ↔ has_sum f (a + ∑ i in range k, f i) :=
begin
refine iff.trans _ has_sum_subtype_iff,
rw [← (not_mem_range_equiv k).symm.has_sum_iff],
refl
end
lemma has_sum_nat_add_iff' {f : ℕ → α} (k : ℕ) {a : α} :
has_sum (λ n, f (n + k)) (a - ∑ i in range k, f i) ↔ has_sum f a :=
by simp [has_sum_nat_add_iff]
lemma sum_add_tsum_nat_add [t2_space α] {f : ℕ → α} (k : ℕ) (h : summable f) :
(∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i) :=
by simpa [add_comm] using
has_sum_unique ((has_sum_nat_add_iff k).1 ((summable_nat_add_iff k).2 h).has_sum) h.has_sum
end subtype
end topological_group
section topological_semiring
variables [semiring α] [topological_space α] [topological_semiring α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum.mul_left (a₂) : has_sum f a₁ → has_sum (λb, a₂ * f b) (a₂ * a₁) :=
has_sum_hom _ (continuous_const.mul continuous_id)
lemma has_sum.mul_right (a₂) (hf : has_sum f a₁) : has_sum (λb, f b * a₂) (a₁ * a₂) :=
@has_sum_hom _ _ _ _ _ f a₁ (λa, a * a₂) _ _ _
(continuous_id.mul continuous_const) hf
lemma summable.mul_left (a) (hf : summable f) : summable (λb, a * f b) :=
(hf.has_sum.mul_left _).summable
lemma summable.mul_right (a) (hf : summable f) : summable (λb, f b * a) :=
(hf.has_sum.mul_right _).summable
section tsum
variables [t2_space α]
lemma tsum_mul_left (a) (hf : summable f) : (∑'b, a * f b) = a * (∑'b, f b) :=
tsum_eq_has_sum $ hf.has_sum.mul_left _
lemma tsum_mul_right (a) (hf : summable f) : (∑'b, f b * a) = (∑'b, f b) * a :=
tsum_eq_has_sum $ hf.has_sum.mul_right _
end tsum
end topological_semiring
section field
variables [field α] [topological_space α] [topological_semiring α]
{f g : β → α} {a a₁ a₂ : α}
lemma has_sum_mul_left_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, a₂ * f b) (a₂ * a₁) :=
⟨has_sum.mul_left _, λ H, by simpa [← mul_assoc, inv_mul_cancel h] using H.mul_left a₂⁻¹⟩
lemma has_sum_mul_right_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, f b * a₂) (a₁ * a₂) :=
by { simp only [mul_comm _ a₂], exact has_sum_mul_left_iff h }
lemma summable_mul_left_iff (h : a ≠ 0) : summable f ↔ summable (λb, a * f b) :=
⟨λ H, H.mul_left _, λ H, by simpa [← mul_assoc, inv_mul_cancel h] using H.mul_left a⁻¹⟩
lemma summable_mul_right_iff (h : a ≠ 0) : summable f ↔ summable (λb, f b * a) :=
by { simp only [mul_comm _ a], exact summable_mul_left_iff h }
end field
section order_topology
variables [ordered_add_comm_monoid α] [topological_space α] [order_closed_topology α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum_le (h : ∀b, f b ≤ g b) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto' at_top_ne_bot hf hg $ assume s, sum_le_sum $ assume b _, h b
lemma has_sum_le_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c)
(h : ∀b, f b ≤ g (i b)) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ :=
have has_sum (λc, (partial_inv i c).cases_on' 0 f) a₁,
begin
refine (has_sum_iff_has_sum_of_ne_zero_bij (λb _, i b) _ _ _).2 hf,
{ assume c₁ c₂ h₁ h₂ eq, exact hi eq },
{ assume c hc,
cases eq : partial_inv i c with b; rw eq at hc,
{ contradiction },
{ rw [partial_inv_of_injective hi] at eq,
exact ⟨b, hc, eq⟩ } },
{ assume c hc, rw [partial_inv_left hi, option.cases_on'] }
end,
begin
refine has_sum_le (assume c, _) this hg,
by_cases c ∈ set.range i,
{ rcases h with ⟨b, rfl⟩,
rw [partial_inv_left hi, option.cases_on'],
exact h _ },
{ have : partial_inv i c = none := dif_neg h,
rw [this, option.cases_on'],
exact hs _ h }
end
lemma tsum_le_tsum_of_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c)
(h : ∀b, f b ≤ g (i b)) (hf : summable f) (hg : summable g) : tsum f ≤ tsum g :=
has_sum_le_inj i hi hs h hf.has_sum hg.has_sum
lemma sum_le_has_sum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : has_sum f a) :
s.sum f ≤ a :=
ge_of_tendsto at_top_ne_bot hf (eventually_at_top.2 ⟨s, λ t hst,
sum_le_sum_of_subset_of_nonneg hst $ λ b hbt hbs, hs b hbs⟩)
lemma sum_le_tsum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : summable f) :
s.sum f ≤ tsum f :=
sum_le_has_sum s hs hf.has_sum
lemma tsum_le_tsum (h : ∀b, f b ≤ g b) (hf : summable f) (hg : summable g) : (∑'b, f b) ≤ (∑'b, g b) :=
has_sum_le h hf.has_sum hg.has_sum
lemma tsum_nonneg (h : ∀ b, 0 ≤ g b) : 0 ≤ (∑'b, g b) :=
begin
by_cases hg : summable g,
{ simpa using tsum_le_tsum h summable_zero hg },
{ simp [tsum_eq_zero_of_not_summable hg] }
end
lemma tsum_nonpos (h : ∀ b, f b ≤ 0) : (∑'b, f b) ≤ 0 :=
begin
by_cases hf : summable f,
{ simpa using tsum_le_tsum h hf summable_zero},
{ simp [tsum_eq_zero_of_not_summable hf] }
end
end order_topology
section uniform_group
variables [add_comm_group α] [uniform_space α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma summable_iff_cauchy_seq_finset [complete_space α] :
summable f ↔ cauchy_seq (λ (s : finset β), s.sum f) :=
(cauchy_map_iff_exists_tendsto at_top_ne_bot).symm
variable [uniform_add_group α]
lemma cauchy_seq_finset_iff_vanishing :
cauchy_seq (λ (s : finset β), s.sum f)
↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → t.sum f ∈ e) :=
begin
simp only [cauchy_seq, cauchy_map_iff, and_iff_right at_top_ne_bot,
prod_at_top_at_top_eq, uniformity_eq_comap_nhds_zero α, tendsto_comap_iff, (∘)],
rw [tendsto_at_top' (_ : finset β × finset β → α)],
split,
{ assume h e he,
rcases h e he with ⟨⟨s₁, s₂⟩, h⟩,
use [s₁ ∪ s₂],
assume t ht,
specialize h (s₁ ∪ s₂, (s₁ ∪ s₂) ∪ t) ⟨le_sup_left, le_sup_left_of_le le_sup_right⟩,
simpa only [finset.sum_union ht.symm, add_sub_cancel'] using h },
{ assume h e he,
rcases exists_nhds_half_neg he with ⟨d, hd, hde⟩,
rcases h d hd with ⟨s, h⟩,
use [(s, s)],
rintros ⟨t₁, t₂⟩ ⟨ht₁, ht₂⟩,
have : t₂.sum f - t₁.sum f = (t₂ \ s).sum f - (t₁ \ s).sum f,
{ simp only [(finset.sum_sdiff ht₁).symm, (finset.sum_sdiff ht₂).symm,
add_sub_add_right_eq_sub] },
simp only [this],
exact hde _ _ (h _ finset.sdiff_disjoint) (h _ finset.sdiff_disjoint) }
end
variable [complete_space α]
lemma summable_iff_vanishing :
summable f ↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → t.sum f ∈ e) :=
by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing]
/- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` -/
lemma summable.summable_of_eq_zero_or_self (hf : summable f) (h : ∀b, g b = 0 ∨ g b = f b) : summable g :=
summable_iff_vanishing.2 $
assume e he,
let ⟨s, hs⟩ := summable_iff_vanishing.1 hf e he in
⟨s, assume t ht,
have eq : (t.filter (λb, g b = f b)).sum f = t.sum g :=
calc (t.filter (λb, g b = f b)).sum f = (t.filter (λb, g b = f b)).sum g :
finset.sum_congr rfl (assume b hb, (finset.mem_filter.1 hb).2.symm)
... = t.sum g :
begin
refine finset.sum_subset (finset.filter_subset _) _,
assume b hbt hb,
simp only [(∉), finset.mem_filter, and_iff_right hbt] at hb,
exact (h b).resolve_right hb
end,
eq ▸ hs _ $ finset.disjoint_of_subset_left (finset.filter_subset _) ht⟩
lemma summable.summable_comp_of_injective {i : γ → β} (hf : summable f) (hi : injective i) :
summable (f ∘ i) :=
suffices summable (λb, if b ∈ set.range i then f b else 0),
begin
refine (summable_iff_summable_ne_zero_bij (λc _, i c) _ _ _).1 this,
{ assume c₁ c₂ hc₁ hc₂ eq, exact hi eq },
{ assume b hb,
split_ifs at hb,
{ rcases h with ⟨c, rfl⟩,
exact ⟨c, hb, rfl⟩ },
{ contradiction } },
{ assume c hc, exact if_pos (set.mem_range_self _) }
end,
hf.summable_of_eq_zero_or_self $ assume b, by by_cases b ∈ set.range i; simp [h]
lemma summable.sigma_factor {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) (b : β) : summable (λc, f ⟨b, c⟩) :=
ha.summable_comp_of_injective (λ x y hxy, by simpa using hxy)
lemma summable.sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) : summable (λb, ∑'c, f ⟨b, c⟩) :=
ha.sigma (λ b, ha.sigma_factor b)
lemma tsum_sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) :=
tsum_sigma (λ b, ha.sigma_factor b) ha
end uniform_group
section cauchy_seq
open finset.Ico filter
/-- If the extended distance between consequent points of a sequence is estimated
by a summable series of `nnreal`s, then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_edist_le_of_summable [emetric_space α] {f : ℕ → α} (d : ℕ → nnreal)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f :=
begin
refine emetric.cauchy_seq_iff_nnreal.2 (λ ε εpos, _),
-- Actually we need partial sums of `d` to be a Cauchy sequence
replace hd : cauchy_seq (λ (n : ℕ), (range n).sum d) :=
let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat,
-- Now we take the same `N` as in one of the definitions of a Cauchy sequence
refine (metric.cauchy_seq_iff'.1 hd ε (nnreal.coe_pos.2 εpos)).imp (λ N hN n hn, _),
have hsum := hN n hn,
-- We simplify the known inequality
rw [dist_nndist, nnreal.nndist_eq, ← sum_range_add_sum_Ico _ hn, nnreal.add_sub_cancel'] at hsum,
norm_cast at hsum,
replace hsum := lt_of_le_of_lt (le_max_left _ _) hsum,
rw edist_comm,
-- Then use `hf` to simplify the goal to the same form
apply lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn (λ k _ _, hf k)),
assumption_mod_cast
end
/-- If the distance between consequent points of a sequence is estimated by a summable series,
then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_dist_le_of_summable [metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f :=
begin
refine metric.cauchy_seq_iff'.2 (λε εpos, _),
replace hd : cauchy_seq (λ (n : ℕ), (range n).sum d) :=
let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat,
refine (metric.cauchy_seq_iff'.1 hd ε εpos).imp (λ N hN n hn, _),
have hsum := hN n hn,
rw [real.dist_eq, ← sum_Ico_eq_sub _ hn] at hsum,
calc dist (f n) (f N) = dist (f N) (f n) : dist_comm _ _
... ≤ (Ico N n).sum d : dist_le_Ico_sum_of_dist_le hn (λ k _ _, hf k)
... ≤ abs ((Ico N n).sum d) : le_abs_self _
... < ε : hsum
end
lemma cauchy_seq_of_summable_dist [metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ (λ _, le_refl _) h
lemma dist_le_tsum_of_dist_le_of_tendsto [metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a))
(n : ℕ) :
dist (f n) a ≤ ∑' m, d (n + m) :=
begin
refine le_of_tendsto at_top_ne_bot (tendsto_const_nhds.dist ha)
(eventually_at_top.2 ⟨n, λ m hnm, _⟩),
refine le_trans (dist_le_Ico_sum_of_dist_le hnm (λ k _ _, hf k)) _,
rw [sum_Ico_eq_sum_range],
refine sum_le_tsum (range _) (λ _ _, le_trans dist_nonneg (hf _)) _,
exact hd.summable_comp_of_injective (add_right_injective n)
end
lemma dist_le_tsum_of_dist_le_of_tendsto₀ [metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ tsum d :=
by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0
lemma dist_le_tsum_dist_of_tendsto [metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) (n) :
dist (f n) a ≤ ∑' m, dist (f (n+m)) (f (n+m).succ) :=
show dist (f n) a ≤ ∑' m, (λx, dist (f x) (f x.succ)) (n + m), from
dist_le_tsum_of_dist_le_of_tendsto (λ n, dist (f n) (f n.succ)) (λ _, le_refl _) h ha n
lemma dist_le_tsum_dist_of_tendsto₀ [metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ ∑' n, dist (f n) (f n.succ) :=
by simpa only [zero_add] using dist_le_tsum_dist_of_tendsto h ha 0
end cauchy_seq
|
470f40430f026099612f90a804ff5f812ac528fd | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/inner_product_space/calculus.lean | 74af70e275aee63c43cfde7969e3263e83e953dc | [
"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 | 15,743 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.inner_product_space.pi_L2
import analysis.special_functions.sqrt
/-!
# Calculus in inner product spaces
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we prove that the inner product and square of the norm in an inner space are
infinitely `ℝ`-smooth. In order to state these results, we need a `normed_space ℝ E`
instance. Though we can deduce this structure from `inner_product_space 𝕜 E`, this instance may be
not definitionally equal to some other “natural” instance. So, we assume `[normed_space ℝ E]`.
We also prove that functions to a `euclidean_space` are (higher) differentiable if and only if
their components are. This follows from the corresponding fact for finite product of normed spaces,
and from the equivalence of norms in finite dimensions.
## TODO
The last part of the file should be generalized to `pi_Lp`.
-/
noncomputable theory
open is_R_or_C real filter
open_locale big_operators classical topology
section deriv_inner
variables {𝕜 E F : Type*} [is_R_or_C 𝕜]
variables [normed_add_comm_group E] [inner_product_space 𝕜 E]
variables [normed_add_comm_group F] [inner_product_space ℝ F]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
variables (𝕜) [normed_space ℝ E]
/-- Derivative of the inner product. -/
def fderiv_inner_clm (p : E × E) : E × E →L[ℝ] 𝕜 := is_bounded_bilinear_map_inner.deriv p
@[simp] lemma fderiv_inner_clm_apply (p x : E × E) :
fderiv_inner_clm 𝕜 p x = ⟪p.1, x.2⟫ + ⟪x.1, p.2⟫ := rfl
lemma cont_diff_inner {n} : cont_diff ℝ n (λ p : E × E, ⟪p.1, p.2⟫) :=
is_bounded_bilinear_map_inner.cont_diff
lemma cont_diff_at_inner {p : E × E} {n} :
cont_diff_at ℝ n (λ p : E × E, ⟪p.1, p.2⟫) p :=
cont_diff_inner.cont_diff_at
lemma differentiable_inner : differentiable ℝ (λ p : E × E, ⟪p.1, p.2⟫) :=
is_bounded_bilinear_map_inner.differentiable_at
variables {G : Type*} [normed_add_comm_group G] [normed_space ℝ G]
{f g : G → E} {f' g' : G →L[ℝ] E} {s : set G} {x : G} {n : ℕ∞}
include 𝕜
lemma cont_diff_within_at.inner (hf : cont_diff_within_at ℝ n f s x)
(hg : cont_diff_within_at ℝ n g s x) :
cont_diff_within_at ℝ n (λ x, ⟪f x, g x⟫) s x :=
cont_diff_at_inner.comp_cont_diff_within_at x (hf.prod hg)
lemma cont_diff_at.inner (hf : cont_diff_at ℝ n f x)
(hg : cont_diff_at ℝ n g x) :
cont_diff_at ℝ n (λ x, ⟪f x, g x⟫) x :=
hf.inner 𝕜 hg
lemma cont_diff_on.inner (hf : cont_diff_on ℝ n f s) (hg : cont_diff_on ℝ n g s) :
cont_diff_on ℝ n (λ x, ⟪f x, g x⟫) s :=
λ x hx, (hf x hx).inner 𝕜 (hg x hx)
lemma cont_diff.inner (hf : cont_diff ℝ n f) (hg : cont_diff ℝ n g) :
cont_diff ℝ n (λ x, ⟪f x, g x⟫) :=
cont_diff_inner.comp (hf.prod hg)
lemma has_fderiv_within_at.inner (hf : has_fderiv_within_at f f' s x)
(hg : has_fderiv_within_at g g' s x) :
has_fderiv_within_at (λ t, ⟪f t, g t⟫) ((fderiv_inner_clm 𝕜 (f x, g x)).comp $ f'.prod g') s x :=
(is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp_has_fderiv_within_at x (hf.prod hg)
lemma has_strict_fderiv_at.inner (hf : has_strict_fderiv_at f f' x)
(hg : has_strict_fderiv_at g g' x) :
has_strict_fderiv_at (λ t, ⟪f t, g t⟫) ((fderiv_inner_clm 𝕜 (f x, g x)).comp $ f'.prod g') x :=
(is_bounded_bilinear_map_inner.has_strict_fderiv_at (f x, g x)).comp x (hf.prod hg)
lemma has_fderiv_at.inner (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :
has_fderiv_at (λ t, ⟪f t, g t⟫) ((fderiv_inner_clm 𝕜 (f x, g x)).comp $ f'.prod g') x :=
(is_bounded_bilinear_map_inner.has_fderiv_at (f x, g x)).comp x (hf.prod hg)
lemma has_deriv_within_at.inner {f g : ℝ → E} {f' g' : E} {s : set ℝ} {x : ℝ}
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ t, ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) s x :=
by simpa using (hf.has_fderiv_within_at.inner 𝕜 hg.has_fderiv_within_at).has_deriv_within_at
lemma has_deriv_at.inner {f g : ℝ → E} {f' g' : E} {x : ℝ} :
has_deriv_at f f' x → has_deriv_at g g' x →
has_deriv_at (λ t, ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) x :=
by simpa only [← has_deriv_within_at_univ] using has_deriv_within_at.inner 𝕜
lemma differentiable_within_at.inner (hf : differentiable_within_at ℝ f s x)
(hg : differentiable_within_at ℝ g s x) :
differentiable_within_at ℝ (λ x, ⟪f x, g x⟫) s x :=
((differentiable_inner _).has_fderiv_at.comp_has_fderiv_within_at x
(hf.prod hg).has_fderiv_within_at).differentiable_within_at
lemma differentiable_at.inner (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) :
differentiable_at ℝ (λ x, ⟪f x, g x⟫) x :=
(differentiable_inner _).comp x (hf.prod hg)
lemma differentiable_on.inner (hf : differentiable_on ℝ f s) (hg : differentiable_on ℝ g s) :
differentiable_on ℝ (λ x, ⟪f x, g x⟫) s :=
λ x hx, (hf x hx).inner 𝕜 (hg x hx)
lemma differentiable.inner (hf : differentiable ℝ f) (hg : differentiable ℝ g) :
differentiable ℝ (λ x, ⟪f x, g x⟫) :=
λ x, (hf x).inner 𝕜 (hg x)
lemma fderiv_inner_apply (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x) (y : G) :
fderiv ℝ (λ t, ⟪f t, g t⟫) x y = ⟪f x, fderiv ℝ g x y⟫ + ⟪fderiv ℝ f x y, g x⟫ :=
by { rw [(hf.has_fderiv_at.inner 𝕜 hg.has_fderiv_at).fderiv], refl }
lemma deriv_inner_apply {f g : ℝ → E} {x : ℝ} (hf : differentiable_at ℝ f x)
(hg : differentiable_at ℝ g x) :
deriv (λ t, ⟪f t, g t⟫) x = ⟪f x, deriv g x⟫ + ⟪deriv f x, g x⟫ :=
(hf.has_deriv_at.inner 𝕜 hg.has_deriv_at).deriv
lemma cont_diff_norm_sq : cont_diff ℝ n (λ x : E, ‖x‖ ^ 2) :=
begin
simp only [sq, ← @inner_self_eq_norm_mul_norm 𝕜],
exact (re_clm : 𝕜 →L[ℝ] ℝ).cont_diff.comp (cont_diff_id.inner 𝕜 cont_diff_id)
end
lemma cont_diff.norm_sq (hf : cont_diff ℝ n f) :
cont_diff ℝ n (λ x, ‖f x‖ ^ 2) :=
(cont_diff_norm_sq 𝕜).comp hf
lemma cont_diff_within_at.norm_sq (hf : cont_diff_within_at ℝ n f s x) :
cont_diff_within_at ℝ n (λ y, ‖f y‖ ^ 2) s x :=
(cont_diff_norm_sq 𝕜).cont_diff_at.comp_cont_diff_within_at x hf
lemma cont_diff_at.norm_sq (hf : cont_diff_at ℝ n f x) :
cont_diff_at ℝ n (λ y, ‖f y‖ ^ 2) x :=
hf.norm_sq 𝕜
lemma cont_diff_at_norm {x : E} (hx : x ≠ 0) : cont_diff_at ℝ n norm x :=
have ‖id x‖ ^ 2 ≠ 0, from pow_ne_zero _ (norm_pos_iff.2 hx).ne',
by simpa only [id, sqrt_sq, norm_nonneg] using (cont_diff_at_id.norm_sq 𝕜).sqrt this
lemma cont_diff_at.norm (hf : cont_diff_at ℝ n f x) (h0 : f x ≠ 0) :
cont_diff_at ℝ n (λ y, ‖f y‖) x :=
(cont_diff_at_norm 𝕜 h0).comp x hf
lemma cont_diff_at.dist (hf : cont_diff_at ℝ n f x) (hg : cont_diff_at ℝ n g x)
(hne : f x ≠ g x) :
cont_diff_at ℝ n (λ y, dist (f y) (g y)) x :=
by { simp only [dist_eq_norm], exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) }
lemma cont_diff_within_at.norm (hf : cont_diff_within_at ℝ n f s x) (h0 : f x ≠ 0) :
cont_diff_within_at ℝ n (λ y, ‖f y‖) s x :=
(cont_diff_at_norm 𝕜 h0).comp_cont_diff_within_at x hf
lemma cont_diff_within_at.dist (hf : cont_diff_within_at ℝ n f s x)
(hg : cont_diff_within_at ℝ n g s x) (hne : f x ≠ g x) :
cont_diff_within_at ℝ n (λ y, dist (f y) (g y)) s x :=
by { simp only [dist_eq_norm], exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) }
lemma cont_diff_on.norm_sq (hf : cont_diff_on ℝ n f s) :
cont_diff_on ℝ n (λ y, ‖f y‖ ^ 2) s :=
(λ x hx, (hf x hx).norm_sq 𝕜)
lemma cont_diff_on.norm (hf : cont_diff_on ℝ n f s) (h0 : ∀ x ∈ s, f x ≠ 0) :
cont_diff_on ℝ n (λ y, ‖f y‖) s :=
λ x hx, (hf x hx).norm 𝕜 (h0 x hx)
lemma cont_diff_on.dist (hf : cont_diff_on ℝ n f s)
(hg : cont_diff_on ℝ n g s) (hne : ∀ x ∈ s, f x ≠ g x) :
cont_diff_on ℝ n (λ y, dist (f y) (g y)) s :=
λ x hx, (hf x hx).dist 𝕜 (hg x hx) (hne x hx)
lemma cont_diff.norm (hf : cont_diff ℝ n f) (h0 : ∀ x, f x ≠ 0) :
cont_diff ℝ n (λ y, ‖f y‖) :=
cont_diff_iff_cont_diff_at.2 $ λ x, hf.cont_diff_at.norm 𝕜 (h0 x)
lemma cont_diff.dist (hf : cont_diff ℝ n f) (hg : cont_diff ℝ n g)
(hne : ∀ x, f x ≠ g x) :
cont_diff ℝ n (λ y, dist (f y) (g y)) :=
cont_diff_iff_cont_diff_at.2 $
λ x, hf.cont_diff_at.dist 𝕜 hg.cont_diff_at (hne x)
omit 𝕜
lemma has_strict_fderiv_at_norm_sq (x : F) :
has_strict_fderiv_at (λ x, ‖x‖ ^ 2) (bit0 (innerSL ℝ x)) x :=
begin
simp only [sq, ← @inner_self_eq_norm_mul_norm ℝ],
convert (has_strict_fderiv_at_id x).inner ℝ (has_strict_fderiv_at_id x),
ext y,
simp [bit0, real_inner_comm],
end
include 𝕜
lemma differentiable_at.norm_sq (hf : differentiable_at ℝ f x) :
differentiable_at ℝ (λ y, ‖f y‖ ^ 2) x :=
((cont_diff_at_id.norm_sq 𝕜).differentiable_at le_rfl).comp x hf
lemma differentiable_at.norm (hf : differentiable_at ℝ f x) (h0 : f x ≠ 0) :
differentiable_at ℝ (λ y, ‖f y‖) x :=
((cont_diff_at_norm 𝕜 h0).differentiable_at le_rfl).comp x hf
lemma differentiable_at.dist (hf : differentiable_at ℝ f x) (hg : differentiable_at ℝ g x)
(hne : f x ≠ g x) :
differentiable_at ℝ (λ y, dist (f y) (g y)) x :=
by { simp only [dist_eq_norm], exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) }
lemma differentiable.norm_sq (hf : differentiable ℝ f) : differentiable ℝ (λ y, ‖f y‖ ^ 2) :=
λ x, (hf x).norm_sq 𝕜
lemma differentiable.norm (hf : differentiable ℝ f) (h0 : ∀ x, f x ≠ 0) :
differentiable ℝ (λ y, ‖f y‖) :=
λ x, (hf x).norm 𝕜 (h0 x)
lemma differentiable.dist (hf : differentiable ℝ f) (hg : differentiable ℝ g)
(hne : ∀ x, f x ≠ g x) :
differentiable ℝ (λ y, dist (f y) (g y)) :=
λ x, (hf x).dist 𝕜 (hg x) (hne x)
lemma differentiable_within_at.norm_sq (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ y, ‖f y‖ ^ 2) s x :=
((cont_diff_at_id.norm_sq 𝕜).differentiable_at le_rfl).comp_differentiable_within_at x hf
lemma differentiable_within_at.norm (hf : differentiable_within_at ℝ f s x) (h0 : f x ≠ 0) :
differentiable_within_at ℝ (λ y, ‖f y‖) s x :=
((cont_diff_at_id.norm 𝕜 h0).differentiable_at le_rfl).comp_differentiable_within_at x hf
lemma differentiable_within_at.dist (hf : differentiable_within_at ℝ f s x)
(hg : differentiable_within_at ℝ g s x) (hne : f x ≠ g x) :
differentiable_within_at ℝ (λ y, dist (f y) (g y)) s x :=
by { simp only [dist_eq_norm], exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) }
lemma differentiable_on.norm_sq (hf : differentiable_on ℝ f s) :
differentiable_on ℝ (λ y, ‖f y‖ ^ 2) s :=
λ x hx, (hf x hx).norm_sq 𝕜
lemma differentiable_on.norm (hf : differentiable_on ℝ f s) (h0 : ∀ x ∈ s, f x ≠ 0) :
differentiable_on ℝ (λ y, ‖f y‖) s :=
λ x hx, (hf x hx).norm 𝕜 (h0 x hx)
lemma differentiable_on.dist (hf : differentiable_on ℝ f s) (hg : differentiable_on ℝ g s)
(hne : ∀ x ∈ s, f x ≠ g x) :
differentiable_on ℝ (λ y, dist (f y) (g y)) s :=
λ x hx, (hf x hx).dist 𝕜 (hg x hx) (hne x hx)
end deriv_inner
section pi_like
open continuous_linear_map
variables {𝕜 ι H : Type*} [is_R_or_C 𝕜] [normed_add_comm_group H] [normed_space 𝕜 H]
[fintype ι] {f : H → euclidean_space 𝕜 ι} {f' : H →L[𝕜] euclidean_space 𝕜 ι} {t : set H} {y : H}
lemma differentiable_within_at_euclidean :
differentiable_within_at 𝕜 f t y ↔ ∀ i, differentiable_within_at 𝕜 (λ x, f x i) t y :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_differentiable_within_at_iff, differentiable_within_at_pi],
refl
end
lemma differentiable_at_euclidean :
differentiable_at 𝕜 f y ↔ ∀ i, differentiable_at 𝕜 (λ x, f x i) y :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_differentiable_at_iff, differentiable_at_pi],
refl
end
lemma differentiable_on_euclidean :
differentiable_on 𝕜 f t ↔ ∀ i, differentiable_on 𝕜 (λ x, f x i) t :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_differentiable_on_iff, differentiable_on_pi],
refl
end
lemma differentiable_euclidean :
differentiable 𝕜 f ↔ ∀ i, differentiable 𝕜 (λ x, f x i) :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_differentiable_iff, differentiable_pi],
refl
end
lemma has_strict_fderiv_at_euclidean :
has_strict_fderiv_at f f' y ↔ ∀ i, has_strict_fderiv_at (λ x, f x i)
(euclidean_space.proj i ∘L f') y :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_has_strict_fderiv_at_iff, has_strict_fderiv_at_pi'],
refl
end
lemma has_fderiv_within_at_euclidean :
has_fderiv_within_at f f' t y ↔ ∀ i, has_fderiv_within_at (λ x, f x i)
(euclidean_space.proj i ∘L f') t y :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_has_fderiv_within_at_iff, has_fderiv_within_at_pi'],
refl
end
lemma cont_diff_within_at_euclidean {n : ℕ∞} :
cont_diff_within_at 𝕜 n f t y ↔ ∀ i, cont_diff_within_at 𝕜 n (λ x, f x i) t y :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_cont_diff_within_at_iff, cont_diff_within_at_pi],
refl
end
lemma cont_diff_at_euclidean {n : ℕ∞} :
cont_diff_at 𝕜 n f y ↔ ∀ i, cont_diff_at 𝕜 n (λ x, f x i) y :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_cont_diff_at_iff, cont_diff_at_pi],
refl
end
lemma cont_diff_on_euclidean {n : ℕ∞} :
cont_diff_on 𝕜 n f t ↔ ∀ i, cont_diff_on 𝕜 n (λ x, f x i) t :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_cont_diff_on_iff, cont_diff_on_pi],
refl
end
lemma cont_diff_euclidean {n : ℕ∞} :
cont_diff 𝕜 n f ↔ ∀ i, cont_diff 𝕜 n (λ x, f x i) :=
begin
rw [← (euclidean_space.equiv ι 𝕜).comp_cont_diff_iff, cont_diff_pi],
refl
end
end pi_like
section diffeomorph_unit_ball
open metric (hiding mem_nhds_iff)
variables {n : ℕ∞} {E : Type*} [normed_add_comm_group E] [inner_product_space ℝ E]
lemma cont_diff_homeomorph_unit_ball :
cont_diff ℝ n $ λ (x : E), (homeomorph_unit_ball x : E) :=
begin
suffices : cont_diff ℝ n (λ x, (1 + ‖x‖^2).sqrt⁻¹), { exact this.smul cont_diff_id, },
have h : ∀ (x : E), 0 < 1 + ‖x‖ ^ 2 := λ x, by positivity,
refine cont_diff.inv _ (λ x, real.sqrt_ne_zero'.mpr (h x)),
exact (cont_diff_const.add $ cont_diff_norm_sq ℝ).sqrt (λ x, (h x).ne.symm),
end
lemma cont_diff_on_homeomorph_unit_ball_symm
{f : E → E} (h : ∀ y (hy : y ∈ ball (0 : E) 1), f y = homeomorph_unit_ball.symm ⟨y, hy⟩) :
cont_diff_on ℝ n f $ ball 0 1 :=
begin
intros y hy,
apply cont_diff_at.cont_diff_within_at,
have hf : f =ᶠ[𝓝 y] λ y, (1 - ‖(y : E)‖^2).sqrt⁻¹ • (y : E),
{ rw eventually_eq_iff_exists_mem,
refine ⟨ball (0 : E) 1, mem_nhds_iff.mpr ⟨ball (0 : E) 1, set.subset.refl _, is_open_ball, hy⟩,
λ z hz, _⟩,
rw h z hz,
refl, },
refine cont_diff_at.congr_of_eventually_eq _ hf,
suffices : cont_diff_at ℝ n (λy, (1 - ‖(y : E)‖^2).sqrt⁻¹) y, { exact this.smul cont_diff_at_id },
have h : 0 < 1 - ‖(y : E)‖^2, by rwa [mem_ball_zero_iff, ← _root_.abs_one, ← abs_norm,
← sq_lt_sq, one_pow, ← sub_pos] at hy,
refine cont_diff_at.inv _ (real.sqrt_ne_zero'.mpr h),
refine cont_diff_at.comp _ (cont_diff_at_sqrt h.ne.symm) _,
exact cont_diff_at_const.sub (cont_diff_norm_sq ℝ).cont_diff_at,
end
end diffeomorph_unit_ball
|
00b543c0cad8a54ba07def01eefb54bc2582d14c | ccb7cdf8ebc2d015a000e8e7904952a36b910425 | /src/example.lean | 9aba2f52171e92372430ceead8f797fea93b3da8 | [] | no_license | cipher1024/lean-pl | f7258bda55606b75e3e39deaf7ce8928ed177d66 | 829680605ac17e91038d793c0188e9614353ca25 | refs/heads/master | 1,592,558,951,987 | 1,565,043,356,000 | 1,565,043,531,000 | 196,661,367 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 19,275 | lean |
import spec
namespace examples
namespace circular_buffer
export memory (ptr)
open separation separation.hProp
def val := ptr
@[reducible] def IO (α : Type) := ST val punit α
open function list
instance ptr.storable : is_record val ptr :=
separation.separation.is_record
instance tptr.storable {α} : is_record val (tptr α) :=
equiv.is_record tptr.get (tptr.mk _) (λ x, rfl)
instance unsigned.storable : is_record val ℕ :=
separation.separation.is_record
structure buffer_node (α : Type*) [fixed_storable val α] :=
(repr tail marker : tptr (list $ word val α))
(head : tptr (list α))
(size count : ℕ)
open separation (renaming rec_entry.mk_ -> mk_)
instance buffer_node.storable {α} [fixed_storable val α] : fixed_storable val (buffer_node α) :=
{ repr := λ p v, p.get ↦ rec_bytes' [mk_ val v.repr, mk_ val v.tail, mk_ val v.marker, mk_ val v.head, mk_ val v.size, mk_ val v.count],
fixed_size := 6,
pos_size := by norm_num }
def buffer_node.abstr {α} [fixed_storable val α] : word val (buffer_node α) → buffer_node α
| ⟨[a,b,c,d,e,f],rfl⟩ := ⟨abstr ⟨[a], rfl⟩,abstr ⟨[b], rfl⟩,abstr ⟨[c], rfl⟩,abstr ⟨[d], rfl⟩,abstr ⟨[e], rfl⟩,abstr ⟨[f], rfl⟩⟩
lemma buffer_node.abstr_list {α} [fixed_storable val α] {a b c d e f : val} (h) :
buffer_node.abstr ⟨[a,b,c,d,e,f],h⟩ = (⟨abstr ⟨[a],rfl⟩,abstr ⟨[b],rfl⟩,abstr ⟨[c],rfl⟩,abstr ⟨[d],rfl⟩,abstr ⟨[e],rfl⟩,abstr ⟨[f],rfl⟩⟩ : buffer_node α) :=
rfl
lemma val.abstr_def {a : val} (h) : abstr ⟨[a],h⟩ = a := rfl
lemma tptr.abstr_def {α} {a : val} (h) : abstr ⟨[a],h⟩ = tptr.mk α a := rfl
instance buffer_node.is_record {α} [fixed_storable val α] : is_record val (buffer_node α) :=
{ bytes := λ v, ⟨rec_bytes' [mk_ val v.repr, mk_ val v.tail, mk_ val v.marker, mk_ val v.head, mk_ val v.size, mk_ val v.count], rfl⟩,
abstr := buffer_node.abstr,
right_inverse := λ ⟨a,ha⟩, by { dsimp [fixed_storable.fixed_size] at ha ⊢, congr, vec_cases ha with repr tl hd sz count, refl },
raw_bytes_conversion := λ p a, rfl
}
section setters
open separation
variables {α : Type*} [fixed_storable val α] (p : tptr (buffer_node α))
def get_repr : IO (tptr (list $ word val α)) := (tptr.mk _) <$> read p.get
def get_head : IO (tptr (list α)) := (tptr.mk _) <$> read (p.get+1)
def get_marker : IO (tptr (list $ word val α)) := (tptr.mk _) <$> read (p.get+2)
def get_tail : IO (tptr (list $ word val α)) := (tptr.mk _) <$> read (p.get+3)
def get_size : IO ℕ := read (p.get+4)
def get_count : IO ℕ := read (p.get+5)
section getters
variables (x y w : tptr (list $ word val α)) (z : tptr (list α)) (sz count : ℕ)
@[spec]
lemma get_repr_spec :
spec unit (p ⤇ ⟨x,y,w,z,sz,count⟩)
(get_repr p)
(λ r, [| r = x |] ⊛ p ⤇ ⟨x,y,w,z,sz,count⟩) :=
sorry
@[spec]
lemma get_head_spec :
spec unit (p ⤇ ⟨x,y,w,z,sz,count⟩)
(get_head p)
(λ r, [| r = z |] ⊛ p ⤇ ⟨x,y,w,z,sz,count⟩) :=
sorry
@[spec]
lemma get_marker_spec :
spec unit (p ⤇ ⟨x,y,w,z,sz,count⟩)
(get_marker p)
(λ r, [| r = w |] ⊛ p ⤇ ⟨x,y,w,z,sz,count⟩) :=
sorry
@[spec]
lemma get_tail_spec :
spec unit (p ⤇ ⟨x,y,w,z,sz,count⟩)
(get_tail p)
(λ r, [| r = y |] ⊛ p ⤇ ⟨x,y,w,z,sz,count⟩) :=
sorry
@[spec]
lemma get_size_spec :
spec unit (p ⤇ ⟨x,y,w,z,sz,count⟩)
(get_size p)
(λ r, [| r = sz |] ⊛ p ⤇ ⟨x,y,w,z,sz,count⟩) :=
sorry
@[spec]
lemma get_count_spec :
spec unit (p ⤇ ⟨x,y,w,z,sz,count⟩)
(get_count p)
(λ r, [| r = count |] ⊛ p ⤇ ⟨x,y,w,z,sz,count⟩) :=
sorry
end getters
def set_repr (x : tptr (list $ word val α)) : IO unit := assign p.get x.get
def set_head (x : tptr (list α)) : IO unit := assign (p.get+1) x.get
def set_marker (x : tptr (list $ word val α)) : IO unit := assign (p.get+2) x.get
def set_tail (x : tptr (list $ word val α)) : IO unit := assign (p.get+3) x.get
def set_size (sz : ℕ) : IO unit := assign (p.get+4) sz
def set_count (count : ℕ) : IO unit := assign (p.get+5) count
variables (r : buffer_node α)
@[spec]
lemma set_repr_spec (x' : tptr (list $ word val α)) :
spec' unit (p ⤇ r)
(set_repr p x')
(p ⤇ { repr := x', .. r }) :=
sorry
@[spec]
lemma set_tail_spec (y' : tptr (list $ word val α)) :
spec' unit (p ⤇ r)
(set_tail p y')
(p ⤇ { tail := y', .. r }) :=
sorry
@[spec]
lemma set_marker_spec (w' : tptr (list $ word val α)) :
spec' unit (p ⤇ r)
(set_marker p w')
(p ⤇ { marker := w', .. r }) :=
sorry
@[spec]
lemma set_head_spec (z' : tptr (list α)) :
spec' unit (p ⤇ r)
(set_head p z')
(p ⤇ { head := z', .. r }) :=
sorry
@[spec]
lemma set_size_spec (sz' : ℕ) :
spec' unit (p ⤇ r)
(set_size p sz')
(p ⤇ { size := sz', .. r }) :=
sorry
@[spec]
lemma set_count_spec (count' : ℕ) :
spec' unit (p ⤇ r)
(set_count p count')
(p ⤇ { count := count', .. r }) :=
sorry
end setters
structure buffer_inv {α : Type} [fixed_storable val α] (b : buffer_node α) : Prop :=
(marker_loc : b.marker = b.repr +. b.size * fixed_storable.fixed_size val α)
(tail_no_lingering : b.marker ≠ b.tail)
(head_no_lingering : b.marker ≠ b.head.recast)
(pos_size : b.size > 0)
lemma marker_ne_repr {α : Type} [fixed_storable val α] {b : buffer_node α} (h : buffer_inv b) :
b.marker ≠ b.repr :=
begin
cases h, rw h_marker_loc,
apply offset_ne, apply mul_pos ‹ _ › (fixed_storable.pos_size _ _),
end
def cycle {α} [fixed_storable val α] (ls : buffer_node α) (qe : list α) : hProp val :=
( ∃∃ pre post : ℕ,
unused ls.repr pre ls.head ⊛
list_repr' val ls.head qe ls.tail ⊛
unused ls.tail post ls.marker ) ⋁
( ∃∃ first last (mid : ℕ),
[| first ++ last = qe |] ⊛
list_repr' val ls.repr.recast last ls.tail ⊛
unused ls.tail mid ls.head ⊛
list_repr' val ls.head first ls.marker )
-- instance buffer.storable {α} [fixed_storable val α] : fixed_storable val (buffer α) :=
-- { repr := λ p v, p.recast ⤇ v.to_buffer_node ⊛ cycle v.to_buffer_node v.queue,
-- fixed_size := 4,
-- pos_size := by norm_num }
def queue (α : Type) := list α
def queue.mk {α} (vs : list α) : queue α := vs
instance queue.storable {α} [fixed_storable val α] : fixed_storable val (queue α) :=
{ repr := λ p v, ∃∃ b : buffer_node α, [| buffer_inv b |] ⊛ p.recast ⤇ b ⊛ cycle b v,
-- bytes := λ p, bytes _,
fixed_size := 4,
pos_size := by norm_num }
-- @[simp]
-- lemma buffer_repr {α} [fixed_storable val α] (p : tptr (buffer α)) (b : buffer α) :
-- (p ⤇ b : hProp val) = p.recast ⤇ b.to_buffer_node ⊛ cycle b.to_buffer_node b.queue :=
-- rfl
run_cmd mk_simp_attr `abstr
@[abstr]
lemma queue_repr {α} [fixed_storable val α] (p : tptr (queue α)) (vs : list α) :
(p ⤇ queue.mk vs : hProp val) = ∃∃ b : buffer_node α, [| buffer_inv b |] ⊛ p.recast ⤇ b ⊛ cycle b vs :=
rfl
def mk_buffer (α) [fixed_storable val α] (sz : ℕ) : IO (tptr $ queue α) :=
do let sz' := max 1 sz,
p ← ralloc val (word val α) sz',
r ← ralloc1 val (buffer_node α),
set_head r p.recast,
set_tail r p,
set_repr r p,
set_size r sz',
set_marker r (p +. sz' * fixed_storable.fixed_size val α),
set_count r 0,
pure r.recast
-- set_option trace.app_builder true
-- set_option pp.all true
-- #exit
@[spec]
lemma mk_buffer_spec {α} [is_record val α] (sz : ℕ) :
spec _ emp
(mk_buffer α sz)
(λ p : tptr (queue α), p ⤇ queue.mk ([] : list α)) :=
begin
simp only with abstr,
verify_proc!,
have : p +. nat.mul (max 1 sz) (fixed_size val α) ≠ p,
{ cases p, dsimp [tptr.add], rw tptr.mk.inj_eq, apply ne_of_gt,
apply nat.lt_add_of_pos_right,
rw ← nat.mul_zero 0, apply mul_pos,
apply lt_max_iff.mpr, left, norm_num,
apply fixed_storable.pos_size },
{ apply impl_lift_and, swap,
{ dsimp [cycle], apply impl_or_left, apply impl_exists 0, apply impl_exists x.length,
simp [a,unused,queue.mk,list_repr',storable.repr,fixed_storable.fixed_size],
rw [unused_iff_exists], apply impl_exists x, apply impl_lift_and a,
simp [list_repr'_eq_list_repr,a] },
constructor,
refl, exact this, simp, exact this,
simp, apply lt_max_iff.mpr, norm_num },
end
#check @get_size
def buffer_size {α} [fixed_storable val α] (p : tptr (queue α)) : IO ℕ :=
get_size (p.recast : tptr (buffer_node α))
@[spec]
lemma buffer_size_spec {α} [fixed_storable val α] (p : tptr (queue α)) (vs : list α) :
spec _ (p ⤇ queue.mk vs)
(buffer_size p)
(λ r, [| r = length vs |] ⊛ p ⤇ queue.mk vs) :=
sorry
open separation.is_object
instance {α} : decidable_eq (tptr α)
| ⟨_,p⟩ ⟨_,q⟩ := decidable_of_iff (p = q) (by rw tptr.mk.inj_eq)
def remove {α} [is_object val unit α] (p : tptr (queue α)) : IO unit :=
do let p' : tptr (buffer_node α) := p.recast,
sz ← buffer_size p,
if sz = 0 then pure ()
else do
hd ← get_head p',
mark ← get_marker p',
delete val _ (hd.recast : tptr α),
set_head p' (hd +. fixed_size val α),
hd ← get_head p',
repr ← get_repr p',
when (mark = hd.recast) (set_head p' repr.recast)
section tactic
open tactic
@[tactic.entailment]
meta def entailment' : tactic unit :=
do trace_state,
focus1 $
assumption <|>
do intros,
`[simp [hProp.and_p_exists_distrib_left,hProp.and_p_exists_distrib_right]
{ fail_if_unchanged := ff } ],
iterate_at_most 10 $ do
{ `(_ =*> p_exists _) ← target,
applyc ``impl_exists },
done <|>
ac_refl' <|>
s_shrink <|>
assumption
-- (try (applyc ``impl_of_eq); ac_refl) <|>
end tactic
@[spec]
lemma delete_cycle_spec {α} [is_object val unit α] (v : α) (vs : list α)
(b : buffer_node α) (H : buffer_inv b) :
spec' _ (cycle b (v :: vs))
(delete val punit (b.head.recast : tptr α))
(cycle { head := b.head +. fixed_size val α, .. b } vs) :=
begin
dsimp [cycle],
apply or_left_right_spec,
{ s_intros, dsimp [list_repr'],
verify_proc,
simp [fixed_storable.is_fixed],
s_shrink,
rintro ⟨ ⟩, },
end
-- set_option trace.separation.failed_spec true
@[spec]
lemma remove_spec {α} [is_object val unit α] (p : tptr (queue α)) (v : α) (vs : list α) :
spec' _ (p ⤇ queue.mk (v :: vs)) (remove p) (p ⤇ queue.mk vs) :=
begin
verify_proc!,
{ simp only [queue_repr,when],
s_intros x Hsz Hx, rw if_neg,
verify_proc,
split_ifs ; verify_proc,
{ have H := marker_ne_repr Hx, cases Hx,
apply impl_lift_and,
constructor; try { assumption }, dsimp,
simp only [tptr.recast_eq], exact H, simp only [cycle],
apply or_impl,
{ s_intros pre post,
-- apply hProp.impl_or_right,
-- simp only [unused_iff_exists],
s_intros,
s_assert : x.marker = x.tail,
{ s_apply [list_repr_impl_le' x_3,list_repr_impl_le _ _ vs],
prop h₀ h₁, apply le_antisymm _ h₁, rw [h,recast_le_iff_le_recast],
apply h₀ },
contradiction },
{ s_intros first last mid Hvs,
rw h,
s_assert : first = [],
{ s_apply list_repr_self_impl_eq_nul', },
subst first, rw ← Hvs,
apply hProp.impl_or_left,
s_existsi [0,mid], simp [unused,list_repr',- recast_offset] } },
{ rw lift_eq_emp,
have H := marker_ne_repr Hx, cases Hx,
constructor; dsimp; try { assumption } },
rw [Hsz,length,nat.add_one], contradiction },
end
def wipe_buffer {α} [is_object val unit α] (p : tptr (queue α)) : IO unit :=
do sz ← buffer_size p,
for' 0 sz $ λ i, remove p
@[spec]
lemma wipe_buffer_spec {α} [is_object val unit α] (p : tptr (queue α)) (vs : list α) :
spec' _ (p ⤇ queue.mk vs) (wipe_buffer p) (p ⤇ queue.mk []) :=
begin
verify_proc!, s_intro h, generalize : 0 = k,
induction sz generalizing vs k; dsimp [for'],
{ cases vs, verify_proc, cases h },
{ cases vs, cases h, specialize sz_ih vs_tl,
verify_proc, apply nat.succ_inj h }
end
def del_buffer {α} [is_object val unit α] (p : tptr (queue α)) : IO unit :=
do wipe_buffer p,
let p' : tptr $ buffer_node α := p.recast,
r ← get_repr p',
sz ← get_size p',
rfree _ p',
free _ r (sz * fixed_size val α)
lemma cycle_nil_impl_p_exists {α} [fixed_storable val α] (buf : buffer_node α)
(Hmark : buf.marker = buf.repr +. buf.size * fixed_size val α) :
cycle buf [] =*>
∃∃ trash, [| length trash = buf.size * fixed_size val α |] ⊛ buf.repr ⤇ trash :=
begin
rcases buf with ⟨repr,tail,mark,head,size,count⟩, dsimp at *,
simp [cycle], apply or_impl,
{ s_intros pre post,
apply exists_impl, intro pre,
apply exists_impl, intro post,
-- simp
-- apply impl_exists (pre + post),
simp [list_repr',queue.mk], rw [refinement.and_comm, refinement.and_assoc],
apply lift_and_impl, intro Hhd,
rw [Hhd,refinement.and_comm,list_repr_recast],
transitivity', apply list_repr_and_list_repr_impl_list_repr'_concat,
rw [Hmark,list_repr_offset,length_append] },
{ apply exists_impl, intro first,
apply exists_impl, intro last,
apply exists_impl, intro mid,
apply lift_and_impl, rintro ⟨H₀,H₁⟩, subst H₀, subst H₁,
simp [list_repr',recast_inj], apply lift_and_impl, intro Htail,
rw [← Htail,refinement.and_comm], apply lift_and_impl, intro Hhead,
rw [Hhead,list_repr_recast,Hmark,list_repr_offset],
apply impl_exists mid, refl },
end
-- lemma list_repr_queue {α β} [storable val α] {vs : list α}
-- (p : tptr (list α)) (q : tptr β) :
-- list_repr' p (queue.mk vs) q = list_repr' p (rec_bytes vs) q := _
lemma del_buffer_spec {α} [is_object val unit α] (p : tptr (queue α)) (vs : list α) :
spec' _ (p ⤇ queue.mk vs) (del_buffer p) emp :=
begin
verify_proc,
dsimp [del_buffer],
apply and_then_spec _ _ _ (wipe_buffer_spec _ _), rintro ⟨ ⟩,
apply p_exists_intro_left, rintro ⟨repr,tl,mrk,hd,sz⟩,
apply lift_intro, intro Hqueue,
-- apply p_exists_intro_left, intro Hmarker,
dsimp at *,
apply bind_spec _ (frame_rule _ _ _ _ (get_repr_spec _ _ _ _ _ _ _)), intro repr,
simp [refinement.and_assoc], apply lift_intro, intro h, subst h,
apply bind_spec _ (frame_rule _ _ _ _ (get_size_spec _ _ _ _ _ _ _)), intro size,
simp [refinement.and_assoc], apply lift_intro, intro h, subst h,
apply and_then_spec _ _ _ (frame_rule _ _ _ _ (rfree_spec _ _)), rintro ⟨ ⟩,
simp [queue.mk],
apply precondition_impl _ (cycle_nil_impl_p_exists _ _),
apply p_exists_intro_left, intro trash,
dsimp, apply lift_intro, intro Htrash,
rw ← Htrash, apply free_spec, apply Hqueue.marker_loc,
end
open separation.is_object
def buffer_put {α} [is_object val punit α] (p : tptr (queue α)) (v : tptr α) : IO bool :=
do let p' : tptr (buffer_node α) := p.recast,
count ← get_count p',
size ← get_size p',
if count = size then
pure ff
else do
tl ← get_tail p',
mrk ← get_marker p',
move val punit tl.recast v,
if tl +. 1 = mrk then
get_repr p' >>= set_tail p'
else set_tail p' $ tl +. 1,
pure tt
lemma move_to_cycle {α} [is_object val punit α] (v : tptr α) (arg : α)
(buf : buffer_node α) (qe : list α) :
spec' _ (v ⤇ arg ⊛ cycle buf qe)
(move val unit buf.tail.recast v)
(trashed val v ⊛ cycle { tail := buf.tail +. fixed_size val α, .. buf } (qe ++ [arg])) :=
begin
simp [cycle,p_and_or_distrib_left,and_p_exists_distrib_left],
apply or_left_right_spec,
{ simp [list_repr_append], apply p_exists_intro_left, intro pre,
apply p_exists_intro_left, intro post,
apply p_exists_intro pre,
cases post with hd post, { admit },
apply p_exists_intro post, frame,
dsimp [list_repr'],
have : (buf.head +. storable.size val qe) = buf.tail.recast, admit,
simp [this,list_repr_recast],
frame,
frame,
trace "FOO",
frame' },
end
#exit
lemma tail_wrap_around {α} [fixed_storable val α] {a c d e f} (ls : list α) :
cycle ⟨a,c,c,d,e,f⟩ ls = cycle ⟨a,a,c,d,e,f⟩ ls :=
sorry
lemma buffer_put_spec {α} [is_object val punit α] (p : tptr (queue α)) (v : tptr α) (arg : α) (vs : list α) :
spec _ (v ⤇ arg ⊛ p ⤇ queue.mk vs)
(buffer_put p v)
(λ r, if r then trashed val v ⊛ p ⤇ queue.mk (vs ++ [arg])
else v ⤇ arg ⊛ p ⤇ queue.mk vs ) :=
begin
rw refinement.and_comm,
simp [buffer_put,and_p_exists_distrib_right,refinement.and_assoc],
apply p_exists_intro_left, rintro ⟨repr,tl,mark,hd,size,count⟩,
dsimp at *, apply lift_intro,
intro H, have H' := marker_ne_repr H,
rcases H with ⟨H₀,H₁,H₂⟩, dsimp at *,
apply bind_spec _ (frame_rule _ _ _ _ (get_count_spec _ _ _ _ _ _ _)), intro count,
simp [refinement.and_assoc], apply lift_intro, intro h, subst h,
apply bind_spec _ (frame_rule _ _ _ _ (get_size_spec _ _ _ _ _ _ _)), intro size,
simp [refinement.and_assoc], apply lift_intro, intro h, subst h,
split_ifs,
{ apply pure_spec, simp [and_p_exists_distrib_left],
apply impl_exists, apply impl_lift_and _, refl,
constructor; assumption, },
{ apply bind_spec _ (frame_rule _ _ _ _ (get_tail_spec _ _ _ _ _ _ _)), intro tail,
simp [refinement.and_assoc], apply lift_intro, intro h, subst h,
apply bind_spec _ (frame_rule _ _ _ _ (get_marker_spec _ _ _ _ _ _ _)), intro marker,
simp [refinement.and_assoc], apply lift_intro, intro h, subst h,
rw refinement.and_comm _ (v ⤇ arg),
apply and_then_spec _ _ _ (frame_rule' _ _ _ _ (move_to_cycle _ _ _ _)), intro,
split_ifs,
{ rw bind_assoc,
apply bind_spec _ (frame_rule _ _ _ _ (get_repr_spec p.recast _ _ _ _ _ _)), intro repr',
simp [refinement.and_assoc], apply lift_intro, intro h, subst repr',
apply bind_spec _ (frame_rule _ _ _ _ (set_tail_spec p.recast _ _ _ _ _ _ _)), rintro ⟨ ⟩,
apply pure_spec, dsimp, simp [tail_wrap_around,h_1,and_p_exists_distrib_left],
apply impl_exists, ac_mono, rw refinement.and_assoc,
apply impl_lift_and _, refl, constructor; assumption },
{ apply bind_spec _ (frame_rule _ _ _ _ (set_tail_spec _ _ _ _ _ _ _ _)), rintro ⟨ ⟩,
apply pure_spec, simp, ac_mono, apply impl_exists, apply impl_lift_and _, refl,
replace h_1 := ne.symm h_1,
constructor; try { assumption }, } }
end
def buffer_take {α} (p : tptr (queue α)) : IO (option (tptr α)) := sorry
lemma buffer_take_spec {α} [fixed_storable val α] (p : tptr (queue α)) (v : α) (vs : list α) :
spec _ (p ⤇ queue.mk (v :: vs))
(buffer_take p)
(λ r, ∃∃ r', [|r = some r'|] ⊛ p ⤇ queue.mk vs) :=
sorry
lemma buffer_take_spec' {α} [fixed_storable val α] (p : tptr (queue α)) :
spec _ (p ⤇ queue.mk [])
(buffer_take p)
(λ r, [| r = none |] ⊛ p ⤇ queue.mk []) :=
sorry
end circular_buffer
end examples
|
5b5444fbe13d7b47aa938a2cbe610ccaae7bbc44 | 5e3548e65f2c037cb94cd5524c90c623fbd6d46a | /src_icannos_totilas/applications_lineaires/cpge_applin_5_b.lean | 0cb2ec5250931cdc2d66540bda9e9569fa693fbd | [] | no_license | ahayat16/lean_exos | d4f08c30adb601a06511a71b5ffb4d22d12ef77f | 682f2552d5b04a8c8eb9e4ab15f875a91b03845c | refs/heads/main | 1,693,101,073,585 | 1,636,479,336,000 | 1,636,479,336,000 | 415,000,441 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 404 | lean | import algebra.module.linear_map
import linear_algebra.basic
import data.real.basic
theorem cpge_applin_5_b
(R : Type*) (M : Type*) (X : Type*)
[field R] [add_comm_group M] [module R M] [set X]
[add_comm_group (X -> M)] [module R (X -> M)] :
∀ (a : X), ∃ g : linear_map R (X->M) M, ((λf : X -> M, f a) = g ∧ (g.ker.carrier = {f : X -> M| f a = 0}) (⊤ : submodule R M).map g = M)
:= sorry
|
dab862b06698334f96a956fccb4ee04ffeecc9ce | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /stage0/src/Lean/Elab/Util.lean | 3f9d4f7136e5f758e8aa7e741feb010bb405fade | [
"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 | 7,733 | 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.Util.Trace
import Lean.Parser.Syntax
import Lean.Parser.Extension
import Lean.KeyedDeclsAttribute
import Lean.Elab.Exception
namespace Lean
def Syntax.prettyPrint (stx : Syntax) : Format :=
match stx.unsetTrailing.reprint with -- TODO use syntax pretty printer
| some str => format str.toFormat
| none => format stx
def MacroScopesView.format (view : MacroScopesView) (mainModule : Name) : Format :=
fmt $
if view.scopes.isEmpty then
view.name
else if view.mainModule == mainModule then
view.scopes.foldl Name.mkNum (view.name ++ view.imported)
else
view.scopes.foldl Name.mkNum (view.name ++ view.imported ++ view.mainModule)
namespace Elab
def expandOptNamedPrio (stx : Syntax) : MacroM Nat :=
if stx.isNone then
return eval_prio default
else match stx[0] with
| `(Parser.Command.namedPrio| (priority := $prio)) => evalPrio prio
| _ => Macro.throwUnsupported
structure MacroStackElem where
before : Syntax
after : Syntax
abbrev MacroStack := List MacroStackElem
/- If `ref` does not have position information, then try to use macroStack -/
def getBetterRef (ref : Syntax) (macroStack : MacroStack) : Syntax :=
match ref.getPos? with
| some _ => ref
| none =>
match macroStack.find? (·.before.getPos? != none) with
| some elem => elem.before
| none => ref
register_builtin_option pp.macroStack : Bool := {
defValue := false
group := "pp"
descr := "dispaly macro expansion stack"
}
def addMacroStack {m} [Monad m] [MonadOptions m] (msgData : MessageData) (macroStack : MacroStack) : m MessageData := do
if !pp.macroStack.get (← getOptions) then pure msgData else
match macroStack with
| [] => pure msgData
| stack@(top::_) =>
let msgData := msgData ++ Format.line ++ "with resulting expansion" ++ indentD top.after
pure $ stack.foldl
(fun (msgData : MessageData) (elem : MacroStackElem) =>
msgData ++ Format.line ++ "while expanding" ++ indentD elem.before)
msgData
def checkSyntaxNodeKind [Monad m] [MonadEnv m] [MonadError m] (k : Name) : m Name := do
if Parser.isValidSyntaxNodeKind (← getEnv) k then pure k
else throwError "failed"
def checkSyntaxNodeKindAtNamespaces [Monad m] [MonadEnv m] [MonadError m] (k : Name) : Name → m Name
| n@(Name.str p _ _) => checkSyntaxNodeKind (n ++ k) <|> checkSyntaxNodeKindAtNamespaces k p
| Name.anonymous => checkSyntaxNodeKind k
| _ => throwError "failed"
def checkSyntaxNodeKindAtCurrentNamespaces (k : Name) : AttrM Name := do
let ctx ← read
checkSyntaxNodeKindAtNamespaces k ctx.currNamespace
def syntaxNodeKindOfAttrParam (defaultParserNamespace : Name) (stx : Syntax) : AttrM SyntaxNodeKind := do
let k ← Attribute.Builtin.getId stx
checkSyntaxNodeKindAtCurrentNamespaces k
<|>
checkSyntaxNodeKind (defaultParserNamespace ++ k)
<|>
throwError "invalid syntax node kind '{k}'"
private unsafe def evalSyntaxConstantUnsafe (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax :=
env.evalConstCheck Syntax opts `Lean.Syntax constName
@[implementedBy evalSyntaxConstantUnsafe]
constant evalSyntaxConstant (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax := throw ""
unsafe def mkElabAttribute (γ) (attrDeclName attrBuiltinName attrName : Name) (parserNamespace : Name) (typeName : Name) (kind : String)
: IO (KeyedDeclsAttribute γ) :=
KeyedDeclsAttribute.init {
builtinName := attrBuiltinName
name := attrName
descr := kind ++ " elaborator"
valueTypeName := typeName
evalKey := fun _ stx => syntaxNodeKindOfAttrParam parserNamespace stx
} attrDeclName
unsafe def mkMacroAttributeUnsafe : IO (KeyedDeclsAttribute Macro) :=
mkElabAttribute Macro `Lean.Elab.macroAttribute `builtinMacro `macro Name.anonymous `Lean.Macro "macro"
@[implementedBy mkMacroAttributeUnsafe]
constant mkMacroAttribute : IO (KeyedDeclsAttribute Macro)
builtin_initialize macroAttribute : KeyedDeclsAttribute Macro ← mkMacroAttribute
/--
Try to expand macro at syntax tree root and return macro declaration name and new syntax if successful.
Return none if all macros threw `Macro.Exception.unsupportedSyntax`.
-/
def expandMacroImpl? (env : Environment) : Syntax → MacroM (Option (Name × Syntax)) := fun stx => do
for e in macroAttribute.getEntries env stx.getKind do
try
let stx' ← e.value stx
return (e.decl, stx')
catch
| Macro.Exception.unsupportedSyntax => pure ()
| ex => throw ex
return none
class MonadMacroAdapter (m : Type → Type) where
getCurrMacroScope : m MacroScope
getNextMacroScope : m MacroScope
setNextMacroScope : MacroScope → m Unit
instance (m n) [MonadLift m n] [MonadMacroAdapter m] : MonadMacroAdapter n := {
getCurrMacroScope := liftM (MonadMacroAdapter.getCurrMacroScope : m _),
getNextMacroScope := liftM (MonadMacroAdapter.getNextMacroScope : m _),
setNextMacroScope := fun s => liftM (MonadMacroAdapter.setNextMacroScope s : m _)
}
def liftMacroM {α} {m : Type → Type} [Monad m] [MonadMacroAdapter m] [MonadEnv m] [MonadRecDepth m] [MonadError m] [MonadResolveName m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] (x : MacroM α) : m α := do
let env ← getEnv
let currNamespace ← getCurrNamespace
let openDecls ← getOpenDecls
let methods := Macro.mkMethods {
-- TODO: record recursive expansions in info tree?
expandMacro? := fun stx => do
match (← expandMacroImpl? env stx) with
| some (_, stx) => some stx
| none => none
hasDecl := fun declName => return env.contains declName
getCurrNamespace := return currNamespace
resolveNamespace? := fun n => return ResolveName.resolveNamespace? env currNamespace openDecls n
resolveGlobalName := fun n => return ResolveName.resolveGlobalName env currNamespace openDecls n
}
match x { methods := methods
ref := ← getRef
currMacroScope := ← MonadMacroAdapter.getCurrMacroScope
mainModule := env.mainModule
currRecDepth := ← MonadRecDepth.getRecDepth
maxRecDepth := ← MonadRecDepth.getMaxRecDepth
} { macroScope := (← MonadMacroAdapter.getNextMacroScope) } with
| EStateM.Result.error Macro.Exception.unsupportedSyntax _ => throwUnsupportedSyntax
| EStateM.Result.error (Macro.Exception.error ref msg) _ => throwErrorAt ref msg
| EStateM.Result.ok a s =>
MonadMacroAdapter.setNextMacroScope s.macroScope
s.traceMsgs.reverse.forM fun (clsName, msg) => trace clsName fun _ => msg
pure a
@[inline] def adaptMacro {m : Type → Type} [Monad m] [MonadMacroAdapter m] [MonadEnv m] [MonadRecDepth m] [MonadError m] [MonadResolveName m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] (x : Macro) (stx : Syntax) : m Syntax :=
liftMacroM (x stx)
partial def mkUnusedBaseName (baseName : Name) : MacroM Name := do
let currNamespace ← Macro.getCurrNamespace
if ← Macro.hasDecl (currNamespace ++ baseName) then
let rec loop (idx : Nat) := do
let name := baseName.appendIndexAfter idx
if ← Macro.hasDecl (currNamespace ++ name) then
loop (idx+1)
else
name
loop 1
else
return baseName
builtin_initialize
registerTraceClass `Elab
registerTraceClass `Elab.step
end Lean.Elab
|
f6a444c1abb005367c19f4b25fe0d8e3ce9f9173 | 5756a081670ba9c1d1d3fca7bd47cb4e31beae66 | /Mathport/Syntax/Transform/Tactic.lean | e88f8c225e2bccb57e790b2a0861b44923b14e35 | [
"Apache-2.0"
] | permissive | leanprover-community/mathport | 2c9bdc8292168febf59799efdc5451dbf0450d4a | 13051f68064f7638970d39a8fecaede68ffbf9e1 | refs/heads/master | 1,693,841,364,079 | 1,693,813,111,000 | 1,693,813,111,000 | 379,357,010 | 27 | 10 | Apache-2.0 | 1,691,309,132,000 | 1,624,384,521,000 | Lean | UTF-8 | Lean | false | false | 5,489 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import Mathport.Syntax.Transform.Basic
import Lean
namespace Mathport
namespace Transform
open Lean Elab Mathlib.Tactic
def trHaveArgs (id : TSyntax ``optBinderIdent) (bs : TSyntaxArray ``Parser.Term.letIdBinder)
(ty : Option Term) (val : Term) : M (TSyntax ``Parser.Term.haveIdDecl) :=
match id with
| `(optBinderIdent| $id:ident) => `(Parser.Term.haveIdDecl| $id:ident $bs* $[: $ty]? := $val)
| `(optBinderIdent| _%$id) => `(Parser.Term.haveIdDecl| _%$id $bs* $[: $ty]? := $val)
| `(optBinderIdent| $id:hygieneInfo) =>
`(Parser.Term.haveIdDecl| $id:hygieneInfo $bs* $[: $ty]? := $val)
| _ => throwUnsupported
def transformConsecutiveTactics : Syntax.Tactic → Syntax.Tactic → M Syntax.Tactic
| `(tactic| suffices : $ty), `(tactic|· $tacs*) =>
`(tactic| suffices $ty by $tacs*)
| `(tactic| have $id:optBinderIdent $bs* $[: $ty]?), `(tactic|· $tacs*) => do
`(tactic| have $(← trHaveArgs id bs ty <|← `(by $tacs*)):haveIdDecl)
| `(tactic| have $id:optBinderIdent $bs* $[: $ty]?), `(tactic|exact $t) => do
`(tactic| have $(← trHaveArgs id bs ty t):haveIdDecl)
| `(tactic| let $id:ident $bs* $[: $ty]?), `(tactic|· $tacs*) =>
`(tactic| let $id:ident $bs* $[: $ty]? := by $tacs*)
| `(tactic| let _%$id $bs* $[: $ty]?), `(tactic|· $tacs*) =>
`(tactic| let _%$id $bs* $[: $ty]? := by $tacs*)
| `(tactic| let $bs:letIdBinder* $[: $ty]?), `(tactic|· $tacs*) =>
`(tactic| let this $bs* $[: $ty]? := by $tacs*)
| `(tactic| obtain $(pat)? $[: $ty]?), `(tactic|· $tacs*) =>
`(tactic| obtain $(pat)? $[: $ty]? := by $tacs*)
| _, _ => throwUnsupported
def transformConsecutiveTacticsArray (tacAndSeps : Array Syntax) : M (Array Syntax) := do
for i in [1:(tacAndSeps.size+1)/2] do
if let some tac' ← catchUnsupportedSyntax do withRef tacAndSeps[2*(i-1)]! do
transformConsecutiveTactics ⟨tacAndSeps[2*(i-1)]!⟩ ⟨tacAndSeps[2*i]!⟩ then
return tacAndSeps[:2*(i-1)] ++ #[tac'] ++ tacAndSeps[2*i+1:]
throwUnsupported
-- expand `by (skip; skip)` to `by skip; skip`
def transformInlineTactics (tacAndSeps : Array Syntax) : M (Array Syntax) := do
let mut tacs' := #[]
let mut modified := false
for i in [:(tacAndSeps.size+1)/2] do
let tac := tacAndSeps[2*i]!
match tac with
| `(tactic| ($seq:tacticSeq1Indented)) =>
tacs' := tacs' ++ seq.1[0].getArgs
modified := true
| _ => tacs' := tacs'.push tac
if let some sep := tacAndSeps[2*i+1]? then
tacs' := tacs'.push sep
unless modified do throwUnsupported
pure tacs'
def transformInlineConvs (tacs : Array Syntax.Conv) : M (Array Syntax.Conv) := do
let mut tacs' := #[]
let mut modified := false
for tac in tacs do
match tac.1 with
| `(conv| ($[$seq:conv]*)) =>
tacs' := tacs' ++ seq
modified := true
| _ => tacs' := tacs'.push tac
unless modified do throwUnsupported
pure tacs'
def transformTacticsArray (tacAndSeps : Array Syntax) : M (Array Syntax) := do
for fn in #[transformConsecutiveTacticsArray, transformInlineTactics] do
if let some tacs' ← catchUnsupportedSyntax <| fn tacAndSeps then
return tacs'
throwUnsupported
open Parser.Tactic TSyntax.Compat in
mathport_rules
| stx@`(tacticSeq1Indented| $[$_:tactic]*) => do
(stx.setArg 0 ∘ stx[0].setArgs) <$> transformTacticsArray stx[0].getArgs
| `(tactic| · $stx:tacticSeq1Indented) => do
let args ← transformTacticsArray stx.1[0].getArgs
`(tactic| · $(stx.1.setArg 0 <| stx.1[0].setArgs args):tacticSeq1Indented)
| `(Conv.convSeq| $[$tac:conv]*) => do
`(Conv.convSeq| $[$(← transformInlineConvs tac):conv]*)
-- common obsolete patterns from haveI
mathport_rules
| `(by have $hd:haveDecl; exact $t) =>
`(haveI $hd:haveDecl
$t)
| `(by have $hd:haveDecl <;> exact $t) =>
`(haveI $hd:haveDecl
$t)
| `(by haveI $hd:haveDecl; exact $t) =>
`(haveI $hd:haveDecl
$t)
| `(by haveI $hd:haveDecl <;> exact $t) =>
`(haveI $hd:haveDecl
$t)
| `(by letI $hd:haveDecl; exact $t) =>
`(letI $hd:haveDecl
$t)
| `(by letI $hd:haveDecl <;> exact $t) =>
`(letI $hd:haveDecl
$t)
-- used in Lean 3 to postpone elaboration, now happens by default
mathport_rules | `(by exact $t) => pure t
mathport_rules
| `(tactic| · · $seq:tacticSeq) => `(tactic| · $seq:tacticSeq)
| `(conv| · · $seq:convSeq) => `(conv| · $seq:convSeq)
mathport_rules | `(by · $seq:tactic*) => `(by $seq:tactic*)
mathport_rules
| `(Parser.Term.binderTactic| := by · $seq:tactic*) =>
`(Parser.Term.binderTactic| := by $seq:tactic*)
mathport_rules
| `(show $ty:term from by $seq:tacticSeq) =>
`(show $ty:term by $seq:tacticSeq)
| `(suffices $ty:term from by $seq:tacticSeq; $t:term) =>
`(suffices $ty:term by $seq:tacticSeq
$t)
| `(tactic| suffices $ty:term from by $seq:tacticSeq) =>
`(tactic| suffices $ty:term by $seq:tacticSeq)
-- push `by` before `have`, `let`, `suffices` so that it can be formatted at the end of a line
mathport_rules
| `(have $hd:haveDecl; by $seq:tactic*) =>
`(by have $hd:haveDecl
$[$seq:tactic]*)
| `(let $ld:letDecl; by $seq:tactic*) =>
`(by let $ld:letDecl
$seq:tactic*)
| `(suffices $sd:sufficesDecl; by $seq:tactic*) =>
`(by suffices $sd:sufficesDecl
$seq:tactic*)
|
547f957fa84d766a0ecba33d51dd04646e8bed31 | 737dc4b96c97368cb66b925eeea3ab633ec3d702 | /tests/lean/hidingInaccessibleNames.lean | fffa3cbb52643c638884d1b6cb6476a10d3e7563 | [
"Apache-2.0"
] | permissive | Bioye97/lean4 | 1ace34638efd9913dc5991443777b01a08983289 | bc3900cbb9adda83eed7e6affeaade7cfd07716d | refs/heads/master | 1,690,589,820,211 | 1,631,051,000,000 | 1,631,067,598,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 688 | lean | def f : (xs : List Nat) → Nat → xs ≠ [] → Nat
| [], _, _ => _
| [a,b], _, _ => _
| _, _, _ => _
set_option pp.inaccessibleNames true in
def f' : (xs : List Nat) → Nat → xs ≠ [] → Nat
| [], _, _ => _ -- TODO: figure out why hyp `Ne (α := List Nat) x✝² []` needs α
| [a,b], _, _ => _
| _, _, _ => _
theorem ex1 : p ∨ q → q ∨ p := by
intro h
cases h
traceState
apply Or.inr
assumption
apply Or.inl
assumption
done
theorem ex2 : {p : Prop} → [Decidable p] → p → decide p = true
| _, isTrue _, _ => _
| _, isFalse h₁, h₂ => absurd h₂ h₁
theorem ex3 : ∀ {c d : Char}, c = d → c.val = d.val
| _, _, rfl => _
|
05845c7f64f3971dd3361af9afb9724c8940d325 | 4e0d7c3132ce31edc5829849735dd25db406b144 | /lean/love03_forward_proofs_exercise_sheet.lean | 860b8f1c7799615e1cbd140b3b589d65b9752673 | [] | no_license | gonzalgu/logical_verification_2020 | a0013a6c22ea254e9f4d245f2948f0f4d44df4bb | 724d0457dff2c3ff10f9ab2170388f4c5e958b75 | refs/heads/master | 1,660,886,374,533 | 1,589,859,641,000 | 1,589,859,641,000 | 256,069,971 | 0 | 0 | null | 1,586,997,430,000 | 1,586,997,429,000 | null | UTF-8 | Lean | false | false | 4,020 | lean | import .lovelib
/-! # LoVe Exercise 3: Forward Proofs -/
set_option pp.beta true
namespace LoVe
/-! ## Question 1: Connectives and Quantifiers
1.1. Supply structured proofs of the following lemmas. -/
lemma I (a : Prop) :
a → a :=
assume ha : a,
show a, from ha
lemma K (a b : Prop) :
a → b → b :=
assume ha : a,
assume hb : b,
show b,
from hb
lemma C (a b c : Prop) :
(a → b → c) → b → a → c :=
assume f : (a → b → c),
assume hb : b,
assume ha : a,
show c,
from f ha hb
lemma proj_1st (a : Prop) :
a → a → a :=
assume ha₁ : a,
assume ha₂ : a,
show a,
from ha₁
/-! Please give a different answer than for `proj_1st`. -/
lemma proj_2nd (a : Prop) :
a → a → a :=
assume ha₁ : a,
assume ha₂ : a,
show a,
from ha₂
lemma some_nonsense (a b c : Prop) :
(a → b → c) → a → (a → c) → b → c :=
assume f : a → b → c,
assume ha : a,
assume g : a → c,
assume hb : b,
show c,
from f ha hb
/-! 1.2. Supply a structured proof of the contraposition rule. -/
lemma contrapositive (a b : Prop) :
(a → b) → ¬ b → ¬ a :=
assume f : a → b,
assume hnb : ¬b,
assume ha : a,
have hb : b, from f ha,
show false,
from hnb hb
/-! 1.3. Supply a structured proof of the distributivity of `∀` over `∧`. -/
lemma forall_and {α : Type} (p q : α → Prop) :
(∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=
iff.intro
(assume hpq : ∀ x, p x ∧ q x,
show (∀ x, p x) ∧ (∀ x, q x),
from ⟨λ z, (hpq z).left, λ z, (hpq z).right⟩ )
(assume hpandq : (∀ x, p x) ∧ (∀ x, q x),
show ∀ x, p x ∧ q x,
from λ z, ⟨ hpandq.left z, hpandq.right z⟩ )
/-! 1.4. Reuse, if possible, the lemma `forall_and` you proved above to prove
the following instance of the lemma. -/
lemma forall_and_inst {α : Type} (r s : α → α → Prop) :
(∀x, r x x ∧ s x x) ↔ (∀x, r x x) ∧ (∀x, s x x) :=
iff.intro
(assume hrs : ∀ x, r x x ∧ s x x,
show (∀ x, r x x) ∧ (∀ x, s x x),
from ⟨ λ x, (hrs x).left, λ x, (hrs x).right⟩ )
(assume hrands : (∀ x, r x x) ∧ (∀ x, s x x),
show ∀ x, r x x ∧ s x x,
from λ x, ⟨ hrands.left x, hrands.right x ⟩ )
/-! ## Question 2: Chain of Equalities
2.1. Write the following proof using `calc`.
`(a + b) * (a + b)`
`= a * (a + b) + b * (a + b)`
`= a * a + a * b + b * a + b * b`
`= a * a + a * b + a * b + b * b`
`= a * a + 2 * a * b + b * b`
Hint: You might need the tactics `simp` and `cc` and the lemmas `mul_add`,
`add_mul`, and `two_mul`. -/
lemma binomial_square (a b : ℕ) :
(a + b) * (a + b) = a * a + 2 * a * b + b * b :=
calc (a + b) * (a + b) = a * (a + b) + b * (a + b) : by rw add_mul
... = a * a + a * b + b * a + b * b : by simp [mul_add,add_mul]
... = a * a + a * b + a * b + b * b : by cc
... = a * a + 2 * a * b + b * b : by simp[mul_add,add_mul,two_mul]
/-! 2.2. Prove the same argument again, this time as a structured proof. Try to
reuse as much of the above proof idea as possible. -/
lemma binomial_square₂ (a b : ℕ) :
(a + b) * (a + b) = a * a + 2 * a * b + b * b :=
sorry
/-! 2.3. Prove the same lemma again, this time using tactics. -/
lemma binomial_square₃ (a b : ℕ) :
(a + b) * (a + b) = a * a + 2 * a * b + b * b :=
begin
sorry
end
/-! ## Question 3 (**optional**): One-Point Rules
3.1 (**optional**). Prove that the following wrong formulation of the one-point
rule for `∀` is inconsistent, using a structured proof. -/
axiom forall.one_point_wrong {α : Type} {t : α} {p : α → Prop} :
(∀x : α, x = t ∧ p x) ↔ p t
lemma proof_of_false :
false :=
sorry
/-! 3.2 (**optional**). Prove that the following wrong formulation of the
one-point rule for `∃` is inconsistent, using a tactical or structured proof. -/
axiom exists.one_point_wrong {α : Type} {t : α} {p : α → Prop} :
(∃x : α, x = t → p x) ↔ p t
lemma proof_of_false₂ :
false :=
sorry
end LoVe
|
6454a052fa1c1d38917ce7f1dfe5437e5969ccf3 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/linear_algebra/direct_sum/finsupp.lean | e3f7e6ddc13a7798a46aacb4cd1232631c1b0633 | [
"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 | 3,664 | 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
-/
import algebra.direct_sum.finsupp
import linear_algebra.finsupp
import linear_algebra.direct_sum.tensor_product
import data.finsupp.to_dfinsupp
/-!
# Results on finitely supported functions.
The tensor product of ι →₀ M and κ →₀ N is linearly equivalent to (ι × κ) →₀ (M ⊗ N).
-/
universes u v w
noncomputable theory
open_locale direct_sum
open set linear_map submodule
variables {R : Type u} {M : Type v} {N : Type w} [ring R] [add_comm_group M] [module R M]
[add_comm_group N] [module R N]
section tensor_product
open tensor_product
open_locale tensor_product classical
/-- The tensor product of ι →₀ M and κ →₀ N is linearly equivalent to (ι × κ) →₀ (M ⊗ N). -/
def finsupp_tensor_finsupp (R M N ι κ : Sort*) [comm_ring R]
[add_comm_group M] [module R M] [add_comm_group N] [module R N] :
(ι →₀ M) ⊗[R] (κ →₀ N) ≃ₗ[R] (ι × κ) →₀ (M ⊗[R] N) :=
(tensor_product.congr (finsupp_lequiv_direct_sum R M ι) (finsupp_lequiv_direct_sum R N κ))
≪≫ₗ ((tensor_product.direct_sum R ι κ (λ _, M) (λ _, N))
≪≫ₗ (finsupp_lequiv_direct_sum R (M ⊗[R] N) (ι × κ)).symm)
@[simp] theorem finsupp_tensor_finsupp_single (R M N ι κ : Sort*) [comm_ring R]
[add_comm_group M] [module R M] [add_comm_group N] [module R N]
(i : ι) (m : M) (k : κ) (n : N) :
finsupp_tensor_finsupp R M N ι κ (finsupp.single i m ⊗ₜ finsupp.single k n) =
finsupp.single (i, k) (m ⊗ₜ n) :=
by simp [finsupp_tensor_finsupp]
@[simp] theorem finsupp_tensor_finsupp_apply (R M N ι κ : Sort*) [comm_ring R]
[add_comm_group M] [module R M] [add_comm_group N] [module R N]
(f : ι →₀ M) (g : κ →₀ N) (i : ι) (k : κ) :
finsupp_tensor_finsupp R M N ι κ (f ⊗ₜ g) (i, k) = f i ⊗ₜ g k :=
begin
apply finsupp.induction_linear f,
{ simp, },
{ intros f₁ f₂ hf₁ hf₂, simp [add_tmul, hf₁, hf₂], },
{ intros i' m,
apply finsupp.induction_linear g,
{ simp, },
{ intros g₁ g₂ hg₁ hg₂, simp [tmul_add, hg₁, hg₂], },
{ intros k' n,
simp only [finsupp_tensor_finsupp_single],
simp only [finsupp.single, finsupp.coe_mk],
split_ifs; finish, } }
end
@[simp] theorem finsupp_tensor_finsupp_symm_single (R M N ι κ : Sort*) [comm_ring R]
[add_comm_group M] [module R M] [add_comm_group N] [module R N]
(i : ι × κ) (m : M) (n : N) :
(finsupp_tensor_finsupp R M N ι κ).symm (finsupp.single i (m ⊗ₜ n)) =
(finsupp.single i.1 m ⊗ₜ finsupp.single i.2 n) :=
prod.cases_on i $ λ i k, (linear_equiv.symm_apply_eq _).2
(finsupp_tensor_finsupp_single _ _ _ _ _ _ _ _ _).symm
variables (S : Type*) [comm_ring S] (α β : Type*)
/--
A variant of `finsupp_tensor_finsupp` where both modules are the ground ring.
-/
def finsupp_tensor_finsupp' : ((α →₀ S) ⊗[S] (β →₀ S)) ≃ₗ[S] (α × β →₀ S) :=
(finsupp_tensor_finsupp S S S α β).trans (finsupp.lcongr (equiv.refl _) (tensor_product.lid S S))
@[simp] lemma finsupp_tensor_finsupp'_apply_apply (f : α →₀ S) (g : β →₀ S) (a : α) (b : β) :
finsupp_tensor_finsupp' S α β (f ⊗ₜ[S] g) (a, b) = f a * g b :=
by simp [finsupp_tensor_finsupp']
@[simp] lemma finsupp_tensor_finsupp'_single_tmul_single (a : α) (b : β) (r₁ r₂ : S) :
finsupp_tensor_finsupp' S α β (finsupp.single a r₁ ⊗ₜ[S] finsupp.single b r₂) =
finsupp.single (a, b) (r₁ * r₂) :=
by { ext ⟨a', b'⟩, simp [finsupp.single], split_ifs; finish }
end tensor_product
|
b7c420d53f9626f14457f8c4138ebb424606260e | 5df84495ec6c281df6d26411cc20aac5c941e745 | /src/formal_ml/classical.lean | 181362b07797273f5e26ca8a8529352828857fb1 | [
"Apache-2.0"
] | permissive | eric-wieser/formal-ml | e278df5a8df78aa3947bc8376650419e1b2b0a14 | 630011d19fdd9539c8d6493a69fe70af5d193590 | refs/heads/master | 1,681,491,589,256 | 1,612,642,743,000 | 1,612,642,743,000 | 360,114,136 | 0 | 0 | Apache-2.0 | 1,618,998,189,000 | 1,618,998,188,000 | null | UTF-8 | Lean | false | false | 1,151 | lean | /-
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import data.set.disjointed data.set.countable
import data.set.lattice data.set.finite
import formal_ml.nat
/-
Although the entire repo is unapologetically classical, these results are very
directly classical.
-/
noncomputable def classical_set (T:Type*) (S:set T):(@decidable_pred T S) :=
λ t, classical.prop_decidable (S t)
noncomputable def classical.decidable_pred {β:Type*} (P:β → Prop):decidable_pred P:=
(λ b:β, classical.prop_decidable (P b))
noncomputable def classical.decidable_eq (β:Type*):decidable_eq β:=
(λ b c:β, classical.prop_decidable (b=c))
|
adb574701eeb221ea6c8058cb70eb7f68e0be9b0 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/idempotents/karoubi.lean | 7913e1a3cc043887b0338d205f0f8b8f2218e887 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 9,332 | lean | /-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import category_theory.idempotents.basic
import category_theory.preadditive.additive_functor
import category_theory.equivalence
/-!
# The Karoubi envelope of a category
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file, we define the Karoubi envelope `karoubi C` of a category `C`.
## Main constructions and definitions
- `karoubi C` is the Karoubi envelope of a category `C`: it is an idempotent
complete category. It is also preadditive when `C` is preadditive.
- `to_karoubi C : C ⥤ karoubi C` is a fully faithful functor, which is an equivalence
(`to_karoubi_is_equivalence`) when `C` is idempotent complete.
-/
noncomputable theory
open category_theory.category
open category_theory.preadditive
open category_theory.limits
open_locale big_operators
namespace category_theory
variables (C : Type*) [category C]
namespace idempotents
/-- In a preadditive category `C`, when an object `X` decomposes as `X ≅ P ⨿ Q`, one may
consider `P` as a direct factor of `X` and up to unique isomorphism, it is determined by the
obvious idempotent `X ⟶ P ⟶ X` which is the projection onto `P` with kernel `Q`. More generally,
one may define a formal direct factor of an object `X : C` : it consists of an idempotent
`p : X ⟶ X` which is thought as the "formal image" of `p`. The type `karoubi C` shall be the
type of the objects of the karoubi enveloppe of `C`. It makes sense for any category `C`. -/
@[nolint has_nonempty_instance]
structure karoubi := (X : C) (p : X ⟶ X) (idem : p ≫ p = p)
namespace karoubi
variables {C}
attribute [simp, reassoc] idem
@[ext]
lemma ext {P Q : karoubi C} (h_X : P.X = Q.X)
(h_p : P.p ≫ eq_to_hom h_X = eq_to_hom h_X ≫ Q.p) : P = Q :=
begin
cases P,
cases Q,
dsimp at h_X h_p,
subst h_X,
simpa only [true_and, eq_self_iff_true, id_comp, eq_to_hom_refl,
heq_iff_eq, comp_id] using h_p,
end
/-- A morphism `P ⟶ Q` in the category `karoubi C` is a morphism in the underlying category
`C` which satisfies a relation, which in the preadditive case, expresses that it induces a
map between the corresponding "formal direct factors" and that it vanishes on the complement
formal direct factor. -/
@[ext]
structure hom (P Q : karoubi C) := (f : P.X ⟶ Q.X) (comm : f = P.p ≫ f ≫ Q.p)
instance [preadditive C] (P Q : karoubi C) : inhabited (hom P Q) :=
⟨⟨0, by rw [zero_comp, comp_zero]⟩⟩
@[simp]
lemma hom_ext {P Q : karoubi C} {f g : hom P Q} : f = g ↔ f.f = g.f :=
begin
split,
{ intro h, rw h, },
{ ext, }
end
@[simp, reassoc]
lemma p_comp {P Q : karoubi C} (f : hom P Q) : P.p ≫ f.f = f.f :=
by rw [f.comm, ← assoc, P.idem]
@[simp, reassoc]
lemma comp_p {P Q : karoubi C} (f : hom P Q) : f.f ≫ Q.p = f.f :=
by rw [f.comm, assoc, assoc, Q.idem]
lemma p_comm {P Q : karoubi C} (f : hom P Q) : P.p ≫ f.f = f.f ≫ Q.p :=
by rw [p_comp, comp_p]
lemma comp_proof {P Q R : karoubi C} (g : hom Q R) (f : hom P Q) :
f.f ≫ g.f = P.p ≫ (f.f ≫ g.f) ≫ R.p :=
by rw [assoc, comp_p, ← assoc, p_comp]
/-- The category structure on the karoubi envelope of a category. -/
instance : category (karoubi C) :=
{ hom := karoubi.hom,
id := λ P, ⟨P.p, by { repeat { rw P.idem, }, }⟩,
comp := λ P Q R f g, ⟨f.f ≫ g.f, karoubi.comp_proof g f⟩, }
@[simp]
lemma comp_f {P Q R : karoubi C} (f : P ⟶ Q) (g : Q ⟶ R) :
(f ≫ g).f = f.f ≫ g.f := by refl
@[simp]
lemma id_eq {P : karoubi C} : 𝟙 P = ⟨P.p, by repeat { rw P.idem, }⟩ := by refl
/-- It is possible to coerce an object of `C` into an object of `karoubi C`.
See also the functor `to_karoubi`. -/
instance coe : has_coe_t C (karoubi C) := ⟨λ X, ⟨X, 𝟙 X, by rw comp_id⟩⟩
@[simp]
lemma coe_X (X : C) : (X : karoubi C).X = X := by refl
@[simp]
lemma coe_p (X : C) : (X : karoubi C).p = 𝟙 X := by refl
@[simp]
lemma eq_to_hom_f {P Q : karoubi C} (h : P = Q) :
karoubi.hom.f (eq_to_hom h) = P.p ≫ eq_to_hom (congr_arg karoubi.X h) :=
by { subst h, simp only [eq_to_hom_refl, karoubi.id_eq, comp_id], }
end karoubi
/-- The obvious fully faithful functor `to_karoubi` sends an object `X : C` to the obvious
formal direct factor of `X` given by `𝟙 X`. -/
@[simps]
def to_karoubi : C ⥤ karoubi C :=
{ obj := λ X, ⟨X, 𝟙 X, by rw comp_id⟩,
map := λ X Y f, ⟨f, by simp only [comp_id, id_comp]⟩ }
instance : full (to_karoubi C) :=
{ preimage := λ X Y f, f.f, }
instance : faithful (to_karoubi C) := { }
variables {C}
@[simps]
instance [preadditive C] {P Q : karoubi C} : add_comm_group (P ⟶ Q) :=
{ add := λ f g, ⟨f.f+g.f, begin
rw [add_comp, comp_add],
congr',
exacts [f.comm, g.comm],
end⟩,
zero := ⟨0, by simp only [comp_zero, zero_comp]⟩,
zero_add := λ f, by { ext, simp only [zero_add], },
add_zero := λ f, by { ext, simp only [add_zero], },
add_assoc := λ f g h', by simp only [add_assoc],
add_comm := λ f g, by { ext, apply_rules [add_comm], },
neg := λ f, ⟨-f.f, by simpa only [neg_comp, comp_neg, neg_inj] using f.comm⟩,
add_left_neg := λ f, by { ext, apply_rules [add_left_neg], }, }
namespace karoubi
lemma hom_eq_zero_iff [preadditive C] {P Q : karoubi C} {f : hom P Q} : f = 0 ↔ f.f = 0 := hom_ext
/-- The map sending `f : P ⟶ Q` to `f.f : P.X ⟶ Q.X` is additive. -/
@[simps]
def inclusion_hom [preadditive C] (P Q : karoubi C) : add_monoid_hom (P ⟶ Q) (P.X ⟶ Q.X) :=
{ to_fun := λ f, f.f,
map_zero' := rfl,
map_add' := λ f g, rfl }
@[simp]
lemma sum_hom [preadditive C] {P Q : karoubi C} {α : Type*} (s : finset α) (f : α → (P ⟶ Q)) :
(∑ x in s, f x).f = ∑ x in s, (f x).f :=
add_monoid_hom.map_sum (inclusion_hom P Q) f s
end karoubi
/-- The category `karoubi C` is preadditive if `C` is. -/
instance [preadditive C] : preadditive (karoubi C) :=
{ hom_group := λ P Q, by apply_instance, }
instance [preadditive C] : functor.additive (to_karoubi C) := { }
open karoubi
variables (C)
instance : is_idempotent_complete (karoubi C) :=
begin
refine ⟨_⟩,
intros P p hp,
have hp' := hom_ext.mp hp,
simp only [comp_f] at hp',
use ⟨P.X, p.f, hp'⟩,
use ⟨p.f, by rw [comp_p p, hp']⟩,
use ⟨p.f, by rw [hp', p_comp p]⟩,
split; simpa only [hom_ext] using hp',
end
instance [is_idempotent_complete C] : ess_surj (to_karoubi C) := ⟨λ P, begin
have h : is_idempotent_complete C := infer_instance,
rcases is_idempotent_complete.idempotents_split P.X P.p P.idem
with ⟨Y,i,e,⟨h₁,h₂⟩⟩,
use Y,
exact nonempty.intro
{ hom := ⟨i, by erw [id_comp, ← h₂, ← assoc, h₁, id_comp]⟩,
inv := ⟨e, by erw [comp_id, ← h₂, assoc, h₁, comp_id]⟩, },
end⟩
/-- If `C` is idempotent complete, the functor `to_karoubi : C ⥤ karoubi C` is an equivalence. -/
def to_karoubi_is_equivalence [is_idempotent_complete C] :
is_equivalence (to_karoubi C) :=
equivalence.of_fully_faithfully_ess_surj (to_karoubi C)
/-- The equivalence `C ≅ karoubi C` when `C` is idempotent complete. -/
def to_karoubi_equivalence [is_idempotent_complete C] : C ≌ karoubi C :=
by { haveI := to_karoubi_is_equivalence C, exact functor.as_equivalence (to_karoubi C), }
instance to_karoubi_equivalence_functor_additive
[preadditive C] [is_idempotent_complete C] :
(to_karoubi_equivalence C).functor.additive := (infer_instance : (to_karoubi C).additive)
namespace karoubi
variables {C}
/-- The split mono which appears in the factorisation `decomp_id P`. -/
@[simps]
def decomp_id_i (P : karoubi C) : P ⟶ P.X := ⟨P.p, by erw [coe_p, comp_id, P.idem]⟩
/-- The split epi which appears in the factorisation `decomp_id P`. -/
@[simps]
def decomp_id_p (P : karoubi C) : (P.X : karoubi C) ⟶ P :=
⟨P.p, by erw [coe_p, id_comp, P.idem]⟩
/-- The formal direct factor of `P.X` given by the idempotent `P.p` in the category `C`
is actually a direct factor in the category `karoubi C`. -/
lemma decomp_id (P : karoubi C) :
𝟙 P = (decomp_id_i P) ≫ (decomp_id_p P) :=
by { ext, simp only [comp_f, id_eq, P.idem, decomp_id_i, decomp_id_p], }
lemma decomp_p (P : karoubi C) :
(to_karoubi C).map P.p = (decomp_id_p P) ≫ (decomp_id_i P) :=
by { ext, simp only [comp_f, decomp_id_p_f, decomp_id_i_f, P.idem, to_karoubi_map_f], }
lemma decomp_id_i_to_karoubi (X : C) : decomp_id_i ((to_karoubi C).obj X) = 𝟙 _ :=
by { ext, refl, }
lemma decomp_id_p_to_karoubi (X : C) : decomp_id_p ((to_karoubi C).obj X) = 𝟙 _ :=
by { ext, refl, }
lemma decomp_id_i_naturality {P Q : karoubi C} (f : P ⟶ Q) : f ≫ decomp_id_i _ =
decomp_id_i _ ≫ ⟨f.f, by erw [comp_id, id_comp]⟩ :=
by { ext, simp only [comp_f, decomp_id_i_f, karoubi.comp_p, karoubi.p_comp], }
lemma decomp_id_p_naturality {P Q : karoubi C} (f : P ⟶ Q) : decomp_id_p P ≫ f =
(⟨f.f, by erw [comp_id, id_comp]⟩ : (P.X : karoubi C) ⟶ Q.X) ≫ decomp_id_p Q :=
by { ext, simp only [comp_f, decomp_id_p_f, karoubi.comp_p, karoubi.p_comp], }
@[simp]
lemma zsmul_hom [preadditive C] {P Q : karoubi C} (n : ℤ) (f : P ⟶ Q) :
(n • f).f = n • f.f :=
map_zsmul (inclusion_hom P Q) n f
end karoubi
end idempotents
end category_theory
|
d807997c055b45b73715e6a67f15cd78f26e577a | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/calculus/deriv/linear.lean | 45198e21eb2b0c3af9f9f1bbbdea9ec1007fb90e | [
"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,762 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Yury Kudryashov
-/
import analysis.calculus.deriv.basic
import analysis.calculus.fderiv.linear
/-!
# Derivatives of continuous linear maps from the base field
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we prove that `f : 𝕜 →L[𝕜] E` (or `f : 𝕜 →ₗ[𝕜] E`) has derivative `f 1`.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## Keywords
derivative, linear map
-/
universes u v w
open_locale topology filter
open filter asymptotics set
variables {𝕜 : Type u} [nontrivially_normed_field 𝕜]
variables {F : Type v} [normed_add_comm_group F] [normed_space 𝕜 F]
variables {E : Type w} [normed_add_comm_group E] [normed_space 𝕜 E]
variables {x : 𝕜}
variables {s : set 𝕜}
variables {L : filter 𝕜}
section continuous_linear_map
/-! ### Derivative of continuous linear maps -/
variables (e : 𝕜 →L[𝕜] F)
protected lemma continuous_linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.has_fderiv_at_filter.has_deriv_at_filter
protected lemma continuous_linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.has_strict_fderiv_at.has_strict_deriv_at
protected lemma continuous_linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
protected lemma continuous_linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] protected lemma continuous_linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
protected lemma continuous_linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end continuous_linear_map
section linear_map
/-! ### Derivative of bundled linear maps -/
variables (e : 𝕜 →ₗ[𝕜] F)
protected lemma linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.to_continuous_linear_map₁.has_deriv_at_filter
protected lemma linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.to_continuous_linear_map₁.has_strict_deriv_at
protected lemma linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
protected lemma linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] protected lemma linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
protected lemma linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end linear_map
|
34cd4c2403d1c0be88970680c6a3f730ef86825b | a047a4718edfa935d17231e9e6ecec8c7b701e05 | /src/data/setoid/basic.lean | 32be4b9f1fc73b9b40b97842867fdb30c2ecc3c9 | [
"Apache-2.0"
] | permissive | utensil-contrib/mathlib | bae0c9fafe5e2bdb516efc89d6f8c1502ecc9767 | b91909e77e219098a2f8cc031f89d595fe274bd2 | refs/heads/master | 1,668,048,976,965 | 1,592,442,701,000 | 1,592,442,701,000 | 273,197,855 | 0 | 0 | null | 1,592,472,812,000 | 1,592,472,811,000 | null | UTF-8 | Lean | false | false | 16,458 | lean | /-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Bryan Gin-ge Chen
-/
import order.galois_connection
/-!
# Equivalence relations
This file defines the complete lattice of equivalence relations on a type, results about the
inductively defined equivalence closure of a binary relation, and the analogues of some isomorphism
theorems for quotients of arbitrary types.
## Implementation notes
The function `rel` and lemmas ending in ' make it easier to talk about different
equivalence relations on the same type.
The complete lattice instance for equivalence relations could have been defined by lifting
the Galois insertion of equivalence relations on α into binary relations on α, and then using
`complete_lattice.copy` to define a complete lattice instance with more appropriate
definitional equalities (a similar example is `filter.complete_lattice` in
`order/filter/basic.lean`). This does not save space, however, and is less clear.
Partitions are not defined as a separate structure here; users are encouraged to
reason about them using the existing `setoid` and its infrastructure.
## Tags
setoid, equivalence, iseqv, relation, equivalence relation
-/
variables {α : Type*} {β : Type*}
/-- A version of `setoid.r` that takes the equivalence relation as an explicit argument. -/
def setoid.rel (r : setoid α) : α → α → Prop := @setoid.r _ r
/-- A version of `quotient.eq'` compatible with `setoid.rel`, to make rewriting possible. -/
lemma quotient.eq_rel {r : setoid α} {x y} : ⟦x⟧ = ⟦y⟧ ↔ r.rel x y := quotient.eq'
namespace setoid
@[ext] lemma ext' {r s : setoid α} (H : ∀ a b, r.rel a b ↔ s.rel a b) :
r = s := ext H
lemma ext_iff {r s : setoid α} : r = s ↔ ∀ a b, r.rel a b ↔ s.rel a b :=
⟨λ h a b, h ▸ iff.rfl, ext'⟩
/-- Two equivalence relations are equal iff their underlying binary operations are equal. -/
theorem eq_iff_rel_eq {r₁ r₂ : setoid α} : r₁ = r₂ ↔ r₁.rel = r₂.rel :=
⟨λ h, h ▸ rfl, λ h, setoid.ext' $ λ x y, h ▸ iff.rfl⟩
/-- Defining `≤` for equivalence relations. -/
instance : has_le (setoid α) := ⟨λ r s, ∀ ⦃x y⦄, r.rel x y → s.rel x y⟩
theorem le_def {r s : setoid α} : r ≤ s ↔ ∀ {x y}, r.rel x y → s.rel x y := iff.rfl
@[refl] lemma refl' (r : setoid α) (x) : r.rel x x := r.2.1 x
@[symm] lemma symm' (r : setoid α) : ∀ {x y}, r.rel x y → r.rel y x := λ _ _ h, r.2.2.1 h
@[trans] lemma trans' (r : setoid α) : ∀ {x y z}, r.rel x y → r.rel y z → r.rel x z :=
λ _ _ _ hx, r.2.2.2 hx
/-- The kernel of a function is an equivalence relation. -/
def ker (f : α → β) : setoid α :=
⟨λ x y, f x = f y, ⟨λ _, rfl, λ _ _ h, h.symm, λ _ _ _ h, h.trans⟩⟩
/-- The kernel of the quotient map induced by an equivalence relation r equals r. -/
@[simp] lemma ker_mk_eq (r : setoid α) : ker (@quotient.mk _ r) = r :=
ext' $ λ x y, quotient.eq
lemma ker_def {f : α → β} {x y : α} : (ker f).rel x y ↔ f x = f y := iff.rfl
/-- Given types `α`, `β`, the product of two equivalence relations `r` on `α` and `s` on `β`:
`(x₁, x₂), (y₁, y₂) ∈ α × β` are related by `r.prod s` iff `x₁` is related to `y₁`
by `r` and `x₂` is related to `y₂` by `s`. -/
protected def prod (r : setoid α) (s : setoid β) : setoid (α × β) :=
{ r := λ x y, r.rel x.1 y.1 ∧ s.rel x.2 y.2,
iseqv := ⟨λ x, ⟨r.refl' x.1, s.refl' x.2⟩, λ _ _ h, ⟨r.symm' h.1, s.symm' h.2⟩,
λ _ _ _ h1 h2, ⟨r.trans' h1.1 h2.1, s.trans' h1.2 h2.2⟩⟩ }
/-- The infimum of two equivalence relations. -/
instance : has_inf (setoid α) :=
⟨λ r s, ⟨λ x y, r.rel x y ∧ s.rel x y, ⟨λ x, ⟨r.refl' x, s.refl' x⟩,
λ _ _ h, ⟨r.symm' h.1, s.symm' h.2⟩,
λ _ _ _ h1 h2, ⟨r.trans' h1.1 h2.1, s.trans' h1.2 h2.2⟩⟩⟩⟩
/-- The infimum of 2 equivalence relations r and s is the same relation as the infimum
of the underlying binary operations. -/
lemma inf_def {r s : setoid α} : (r ⊓ s).rel = r.rel ⊓ s.rel := rfl
theorem inf_iff_and {r s : setoid α} {x y} :
(r ⊓ s).rel x y ↔ r.rel x y ∧ s.rel x y := iff.rfl
/-- The infimum of a set of equivalence relations. -/
instance : has_Inf (setoid α) :=
⟨λ S, ⟨λ x y, ∀ r ∈ S, rel r x y,
⟨λ x r hr, r.refl' x, λ _ _ h r hr, r.symm' $ h r hr,
λ _ _ _ h1 h2 r hr, r.trans' (h1 r hr) $ h2 r hr⟩⟩⟩
/-- The underlying binary operation of the infimum of a set of equivalence relations
is the infimum of the set's image under the map to the underlying binary operation. -/
theorem Inf_def {s : set (setoid α)} : (Inf s).rel = Inf (rel '' s) :=
by { ext, simp only [Inf_image, infi_apply, infi_Prop_eq], refl }
instance : partial_order (setoid α) :=
{ le := (≤),
lt := λ r s, r ≤ s ∧ ¬s ≤ r,
le_refl := λ _ _ _, id,
le_trans := λ _ _ _ hr hs _ _ h, hs $ hr h,
lt_iff_le_not_le := λ _ _, iff.rfl,
le_antisymm := λ r s h1 h2, setoid.ext' $ λ x y, ⟨λ h, h1 h, λ h, h2 h⟩ }
/-- The complete lattice of equivalence relations on a type, with bottom element `=`
and top element the trivial equivalence relation. -/
instance complete_lattice : complete_lattice (setoid α) :=
{ inf := has_inf.inf,
inf_le_left := λ _ _ _ _ h, h.1,
inf_le_right := λ _ _ _ _ h, h.2,
le_inf := λ _ _ _ h1 h2 _ _ h, ⟨h1 h, h2 h⟩,
top := ⟨λ _ _, true, ⟨λ _, trivial, λ _ _ h, h, λ _ _ _ h1 h2, h1⟩⟩,
le_top := λ _ _ _ _, trivial,
bot := ⟨(=), ⟨λ _, rfl, λ _ _ h, h.symm, λ _ _ _ h1 h2, h1.trans h2⟩⟩,
bot_le := λ r x y h, h ▸ r.2.1 x,
.. complete_lattice_of_Inf (setoid α) $ assume s,
⟨λ r hr x y h, h _ hr, λ r hr x y h r' hr', hr hr' h⟩ }
/-- The inductively defined equivalence closure of a binary relation r is the infimum
of the set of all equivalence relations containing r. -/
theorem eqv_gen_eq (r : α → α → Prop) :
eqv_gen.setoid r = Inf {s : setoid α | ∀ ⦃x y⦄, r x y → s.rel x y} :=
le_antisymm
(λ _ _ H, eqv_gen.rec (λ _ _ h _ hs, hs h) (refl' _)
(λ _ _ _, symm' _) (λ _ _ _ _ _, trans' _) H)
(Inf_le $ λ _ _ h, eqv_gen.rel _ _ h)
/-- The supremum of two equivalence relations r and s is the equivalence closure of the binary
relation `x is related to y by r or s`. -/
lemma sup_eq_eqv_gen (r s : setoid α) :
r ⊔ s = eqv_gen.setoid (λ x y, r.rel x y ∨ s.rel x y) :=
begin
rw eqv_gen_eq,
apply congr_arg Inf,
simp only [le_def, or_imp_distrib, ← forall_and_distrib]
end
/-- The supremum of 2 equivalence relations r and s is the equivalence closure of the
supremum of the underlying binary operations. -/
lemma sup_def {r s : setoid α} : r ⊔ s = eqv_gen.setoid (r.rel ⊔ s.rel) :=
by rw sup_eq_eqv_gen; refl
/-- The supremum of a set S of equivalence relations is the equivalence closure of the binary
relation `there exists r ∈ S relating x and y`. -/
lemma Sup_eq_eqv_gen (S : set (setoid α)) :
Sup S = eqv_gen.setoid (λ x y, ∃ r : setoid α, r ∈ S ∧ r.rel x y) :=
begin
rw eqv_gen_eq,
apply congr_arg Inf,
simp only [upper_bounds, le_def, and_imp, exists_imp_distrib],
ext,
exact ⟨λ H x y r hr, H hr, λ H r hr x y, H r hr⟩
end
/-- The supremum of a set of equivalence relations is the equivalence closure of the
supremum of the set's image under the map to the underlying binary operation. -/
lemma Sup_def {s : set (setoid α)} : Sup s = eqv_gen.setoid (Sup (rel '' s)) :=
begin
rw Sup_eq_eqv_gen,
congr,
ext x y,
erw [Sup_image, supr_apply, supr_apply, supr_Prop_eq],
simp only [Sup_image, supr_Prop_eq, supr_apply, supr_Prop_eq, exists_prop]
end
/-- The equivalence closure of an equivalence relation r is r. -/
@[simp] lemma eqv_gen_of_setoid (r : setoid α) : eqv_gen.setoid r.r = r :=
le_antisymm (by rw eqv_gen_eq; exact Inf_le (λ _ _, id)) eqv_gen.rel
/-- Equivalence closure is idempotent. -/
@[simp] lemma eqv_gen_idem (r : α → α → Prop) :
eqv_gen.setoid (eqv_gen.setoid r).rel = eqv_gen.setoid r :=
eqv_gen_of_setoid _
/-- The equivalence closure of a binary relation r is contained in any equivalence
relation containing r. -/
theorem eqv_gen_le {r : α → α → Prop} {s : setoid α} (h : ∀ x y, r x y → s.rel x y) :
eqv_gen.setoid r ≤ s :=
by rw eqv_gen_eq; exact Inf_le h
/-- Equivalence closure of binary relations is monotonic. -/
theorem eqv_gen_mono {r s : α → α → Prop} (h : ∀ x y, r x y → s x y) :
eqv_gen.setoid r ≤ eqv_gen.setoid s :=
eqv_gen_le $ λ _ _ hr, eqv_gen.rel _ _ $ h _ _ hr
/-- There is a Galois insertion of equivalence relations on α into binary relations
on α, with equivalence closure the lower adjoint. -/
def gi : @galois_insertion (α → α → Prop) (setoid α) _ _ eqv_gen.setoid rel :=
{ choice := λ r h, eqv_gen.setoid r,
gc := λ r s, ⟨λ H _ _ h, H $ eqv_gen.rel _ _ h, λ H, eqv_gen_of_setoid s ▸ eqv_gen_mono H⟩,
le_l_u := λ x, (eqv_gen_of_setoid x).symm ▸ le_refl x,
choice_eq := λ _ _, rfl }
open function
/-- A function from α to β is injective iff its kernel is the bottom element of the complete lattice
of equivalence relations on α. -/
theorem injective_iff_ker_bot (f : α → β) :
injective f ↔ ker f = ⊥ :=
(@eq_bot_iff (setoid α) _ (ker f)).symm
/-- The elements related to x ∈ α by the kernel of f are those in the preimage of f(x) under f. -/
lemma ker_iff_mem_preimage {f : α → β} {x y} : (ker f).rel x y ↔ x ∈ f ⁻¹' {f y} :=
iff.rfl
/-- Equivalence between functions `α → β` such that `r x y → f x = f y` and functions
`quotient r → β`. -/
def lift_equiv (r : setoid α) : {f : α → β // r ≤ ker f} ≃ (quotient r → β) :=
{ to_fun := λ f, quotient.lift (f : α → β) f.2,
inv_fun := λ f, ⟨f ∘ quotient.mk, λ x y h, by simp [ker_def, quotient.sound h]⟩,
left_inv := λ ⟨f, hf⟩, subtype.eq $ funext $ λ x, rfl,
right_inv := λ f, funext $ λ x, quotient.induction_on' x $ λ x, rfl }
/-- The uniqueness part of the universal property for quotients of an arbitrary type. -/
theorem lift_unique {r : setoid α} {f : α → β} (H : r ≤ ker f) (g : quotient r → β)
(Hg : f = g ∘ quotient.mk) : quotient.lift f H = g :=
begin
ext ⟨x⟩,
erw [quotient.lift_beta f H, Hg],
refl
end
/-- Given a map f from α to β, the natural map from the quotient of α by the kernel of f is
injective. -/
lemma injective_ker_lift (f : α → β) : injective (@quotient.lift _ _ (ker f) f (λ _ _ h, h)) :=
λ x y, quotient.induction_on₂' x y $ λ a b h, quotient.sound' h
/-- Given a map f from α to β, the kernel of f is the unique equivalence relation on α whose
induced map from the quotient of α to β is injective. -/
lemma ker_eq_lift_of_injective {r : setoid α} (f : α → β) (H : ∀ x y, r.rel x y → f x = f y)
(h : injective (quotient.lift f H)) : ker f = r :=
le_antisymm
(λ x y hk, quotient.exact $ h $ show quotient.lift f H ⟦x⟧ = quotient.lift f H ⟦y⟧, from hk)
H
variables (r : setoid α) (f : α → β)
/-- The first isomorphism theorem for sets: the quotient of α by the kernel of a function f
bijects with f's image. -/
noncomputable def quotient_ker_equiv_range :
quotient (ker f) ≃ set.range f :=
equiv.of_bijective (@quotient.lift _ (set.range f) (ker f)
(λ x, ⟨f x, set.mem_range_self x⟩) $ λ _ _ h, subtype.eq' h)
⟨λ x y h, injective_ker_lift f $ by rcases x; rcases y; injections,
λ ⟨w, z, hz⟩, ⟨@quotient.mk _ (ker f) z, by rw quotient.lift_beta; exact subtype.ext.2 hz⟩⟩
/-- The quotient of α by the kernel of a surjective function f bijects with f's codomain. -/
noncomputable def quotient_ker_equiv_of_surjective (hf : surjective f) :
quotient (ker f) ≃ β :=
(quotient_ker_equiv_range f).trans $ equiv.subtype_univ_equiv hf
variables {r f}
/-- Given a function `f : α → β` and equivalence relation `r` on `α`, the equivalence
closure of the relation on `f`'s image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are
related to the elements of `f⁻¹(y)` by `r`.' -/
def map (r : setoid α) (f : α → β) : setoid β :=
eqv_gen.setoid $ λ x y, ∃ a b, f a = x ∧ f b = y ∧ r.rel a b
/-- Given a surjective function f whose kernel is contained in an equivalence relation r, the
equivalence relation on f's codomain defined by x ≈ y ↔ the elements of f⁻¹(x) are related to
the elements of f⁻¹(y) by r. -/
def map_of_surjective (r) (f : α → β) (h : ker f ≤ r) (hf : surjective f) :
setoid β :=
⟨λ x y, ∃ a b, f a = x ∧ f b = y ∧ r.rel a b,
⟨λ x, let ⟨y, hy⟩ := hf x in ⟨y, y, hy, hy, r.refl' y⟩,
λ _ _ ⟨x, y, hx, hy, h⟩, ⟨y, x, hy, hx, r.symm' h⟩,
λ _ _ _ ⟨x, y, hx, hy, h₁⟩ ⟨y', z, hy', hz, h₂⟩,
⟨x, z, hx, hz, r.trans' h₁ $ r.trans' (h $ by rwa ←hy' at hy) h₂⟩⟩⟩
/-- A special case of the equivalence closure of an equivalence relation r equalling r. -/
lemma map_of_surjective_eq_map (h : ker f ≤ r) (hf : surjective f) :
map r f = map_of_surjective r f h hf :=
by rw ←eqv_gen_of_setoid (map_of_surjective r f h hf); refl
/-- Given a function `f : α → β`, an equivalence relation `r` on `β` induces an equivalence
relation on `α` defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `r`'. -/
def comap (f : α → β) (r : setoid β) : setoid α :=
⟨λ x y, r.rel (f x) (f y), ⟨λ _, r.refl' _, λ _ _ h, r.symm' h, λ _ _ _ h1, r.trans' h1⟩⟩
/-- Given a map `f : N → M` and an equivalence relation `r` on `β`, the equivalence relation
induced on `α` by `f` equals the kernel of `r`'s quotient map composed with `f`. -/
lemma comap_eq {f : α → β} {r : setoid β} : comap f r = ker (@quotient.mk _ r ∘ f) :=
ext $ λ x y, show _ ↔ ⟦_⟧ = ⟦_⟧, by rw quotient.eq; refl
/-- The second isomorphism theorem for sets. -/
noncomputable def comap_quotient_equiv (f : α → β) (r : setoid β) :
quotient (comap f r) ≃ set.range (@quotient.mk _ r ∘ f) :=
(quotient.congr_right $ ext_iff.1 comap_eq).trans $ quotient_ker_equiv_range $ quotient.mk ∘ f
variables (r f)
/-- The third isomorphism theorem for sets. -/
def quotient_quotient_equiv_quotient (s : setoid α) (h : r ≤ s) :
quotient (ker (quot.map_right h)) ≃ quotient s :=
{ to_fun := λ x, quotient.lift_on' x (λ w, quotient.lift_on' w (@quotient.mk _ s) $
λ x y H, quotient.sound $ h H) $ λ x y, quotient.induction_on₂' x y $ λ w z H,
show @quot.mk _ _ _ = @quot.mk _ _ _, from H,
inv_fun := λ x, quotient.lift_on' x
(λ w, @quotient.mk _ (ker $ quot.map_right h) $ @quotient.mk _ r w) $
λ x y H, quotient.sound' $ show @quot.mk _ _ _ = @quot.mk _ _ _, from quotient.sound H,
left_inv := λ x, quotient.induction_on' x $ λ y, quotient.induction_on' y $
λ w, by show ⟦_⟧ = _; refl,
right_inv := λ x, quotient.induction_on' x $ λ y, by show ⟦_⟧ = _; refl }
variables {r f}
open quotient
/-- Given an equivalence relation r on α, the order-preserving bijection between the set of
equivalence relations containing r and the equivalence relations on the quotient of α by r. -/
def correspondence (r : setoid α) : ((≤) : {s // r ≤ s} → {s // r ≤ s} → Prop) ≃o
((≤) : setoid (quotient r) → setoid (quotient r) → Prop) :=
{ to_fun := λ s, map_of_surjective s.1 quotient.mk ((ker_mk_eq r).symm ▸ s.2) exists_rep,
inv_fun := λ s, ⟨comap quotient.mk s, λ x y h, show s.rel ⟦x⟧ ⟦y⟧, by rw eq_rel.2 h⟩,
left_inv := λ s, subtype.ext.2 $ ext' $ λ _ _,
⟨λ h, let ⟨a, b, hx, hy, H⟩ := h in
s.1.trans' (s.1.symm' $ s.2 $ eq_rel.1 hx) $ s.1.trans' H $ s.2 $ eq_rel.1 hy,
λ h, ⟨_, _, rfl, rfl, h⟩⟩,
right_inv := λ s, let Hm : ker quotient.mk ≤ comap quotient.mk s :=
λ x y h, show s.rel ⟦x⟧ ⟦y⟧, by rw (@eq_rel _ r x y).2 ((ker_mk_eq r) ▸ h) in
ext' $ λ x y, ⟨λ h, let ⟨a, b, hx, hy, H⟩ := h in hx ▸ hy ▸ H,
quotient.induction_on₂ x y $ λ w z h, ⟨w, z, rfl, rfl, h⟩⟩,
ord' := λ s t, ⟨λ h x y hs, let ⟨a, b, hx, hy, Hs⟩ := hs in ⟨a, b, hx, hy, h Hs⟩,
λ h x y hs, let ⟨a, b, hx, hy, ht⟩ := h ⟨x, y, rfl, rfl, hs⟩ in
t.1.trans' (t.1.symm' $ t.2 $ eq_rel.1 hx) $ t.1.trans' ht $ t.2 $ eq_rel.1 hy⟩ }
end setoid
|
efdb80ac52738c085fe156118d7f70b8982eabc0 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/algebra/lie/submodule.lean | 41df037476c8d4b941f3a24714498fbed3f7d8c1 | [
"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 | 38,419 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.subalgebra
import ring_theory.noetherian
/-!
# Lie submodules of a Lie algebra
In this file we define Lie submodules and Lie ideals, we construct the lattice structure on Lie
submodules and we use it to define various important operations, notably the Lie span of a subset
of a Lie module.
## Main definitions
* `lie_submodule`
* `lie_submodule.well_founded_of_noetherian`
* `lie_submodule.lie_span`
* `lie_submodule.map`
* `lie_submodule.comap`
* `lie_ideal`
* `lie_ideal.map`
* `lie_ideal.comap`
## Tags
lie algebra, lie submodule, lie ideal, lattice structure
-/
universes u v w w₁ w₂
section lie_submodule
variables (R : Type u) (L : Type v) (M : Type w)
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
set_option old_structure_cmd true
/-- 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 extends submodule R M :=
(lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier)
attribute [nolint doc_blame] lie_submodule.to_submodule
namespace lie_submodule
variables {R L M} (N N' : lie_submodule R L M)
instance : set_like (lie_submodule R L M) M :=
{ coe := carrier,
coe_injective' := λ N O h, by cases N; cases O; congr' }
instance : add_subgroup_class (lie_submodule R L M) M :=
{ add_mem := λ N, N.add_mem',
zero_mem := λ N, N.zero_mem',
neg_mem := λ N x hx, show -x ∈ N.to_submodule, from neg_mem hx }
/-- The zero module is a Lie submodule of any Lie module. -/
instance : has_zero (lie_submodule R L M) :=
⟨{ lie_mem := λ x m h, by { rw ((submodule.mem_bot R).1 h), apply lie_zero, },
..(0 : submodule R M)}⟩
instance : inhabited (lie_submodule R L M) := ⟨0⟩
instance coe_submodule : has_coe (lie_submodule R L M) (submodule R M) := ⟨to_submodule⟩
@[simp] lemma to_submodule_eq_coe : N.to_submodule = N := rfl
@[norm_cast]
lemma coe_to_submodule : ((N : submodule R M) : set M) = N := rfl
@[simp] lemma mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : set M) :=
iff.rfl
@[simp] lemma mem_mk_iff (S : set M) (h₁ h₂ h₃ h₄) {x : M} :
x ∈ (⟨S, h₁, h₂, h₃, h₄⟩ : lie_submodule R L M) ↔ x ∈ S :=
iff.rfl
@[simp] lemma mem_coe_submodule {x : M} : x ∈ (N : submodule R M) ↔ x ∈ N := iff.rfl
lemma mem_coe {x : M} : x ∈ (N : set M) ↔ x ∈ N := iff.rfl
@[simp] protected lemma zero_mem : (0 : M) ∈ N := zero_mem N
@[simp] lemma mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 := subtype.ext_iff_val
@[simp] lemma coe_to_set_mk (S : set M) (h₁ h₂ h₃ h₄) :
((⟨S, h₁, h₂, h₃, h₄⟩ : lie_submodule R L M) : set M) = S := rfl
@[simp] lemma coe_to_submodule_mk (p : submodule R M) (h) :
(({lie_mem := h, ..p} : lie_submodule R L M) : submodule R M) = p :=
by { cases p, refl, }
lemma coe_submodule_injective :
function.injective (to_submodule : lie_submodule R L M → submodule R M) :=
λ x y h, by { cases x, cases y, congr, injection h }
@[ext] lemma ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' := set_like.ext h
@[simp] lemma coe_to_submodule_eq_iff : (N : submodule R M) = (N' : submodule R M) ↔ N = N' :=
coe_submodule_injective.eq_iff
/-- Copy of a lie_submodule with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (s : set M) (hs : s = ↑N) : lie_submodule R L M :=
{ carrier := s,
zero_mem' := hs.symm ▸ N.zero_mem',
add_mem' := hs.symm ▸ N.add_mem',
smul_mem' := hs.symm ▸ N.smul_mem',
lie_mem := hs.symm ▸ N.lie_mem, }
@[simp] lemma coe_copy (S : lie_submodule R L M) (s : set M) (hs : s = ↑S) :
(S.copy s hs : set M) = s := rfl
lemma copy_eq (S : lie_submodule R L M) (s : set M) (hs : s = ↑S) : S.copy s hs = S :=
coe_submodule_injective (set_like.coe_injective hs)
instance : lie_ring_module L N :=
{ bracket := λ (x : L) (m : N), ⟨⁅x, m.val⁆, N.lie_mem m.property⟩,
add_lie := by { intros x y m, apply set_coe.ext, apply add_lie, },
lie_add := by { intros x m n, apply set_coe.ext, apply lie_add, },
leibniz_lie := by { intros x y m, apply set_coe.ext, apply leibniz_lie, }, }
instance module' {S : Type*} [semiring S] [has_smul S R] [module S M] [is_scalar_tower S R M] :
module S N :=
N.to_submodule.module'
instance : module R N := N.to_submodule.module
instance {S : Type*} [semiring S] [has_smul S R] [has_smul Sᵐᵒᵖ R] [module S M] [module Sᵐᵒᵖ M]
[is_scalar_tower S R M] [is_scalar_tower Sᵐᵒᵖ R M] [is_central_scalar S M] :
is_central_scalar S N :=
N.to_submodule.is_central_scalar
instance : lie_module R L N :=
{ lie_smul := by { intros t x y, apply set_coe.ext, apply lie_smul, },
smul_lie := by { intros t x y, apply set_coe.ext, apply smul_lie, }, }
@[simp, norm_cast] lemma coe_zero : ((0 : N) : M) = (0 : M) := rfl
@[simp, norm_cast] lemma coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) := rfl
@[simp, norm_cast] lemma coe_neg (m : N) : (↑(-m) : M) = -(m : M) := rfl
@[simp, norm_cast] lemma coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) := rfl
@[simp, norm_cast] lemma coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) := rfl
@[simp, norm_cast] lemma coe_bracket (x : L) (m : N) : (↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ := rfl
end lie_submodule
section lie_ideal
variables (L)
/-- 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, }
instance : has_coe (lie_ideal R L) (lie_subalgebra R L) := ⟨λ I, lie_ideal_subalgebra R L I⟩
@[norm_cast] lemma lie_ideal.coe_to_subalgebra (I : lie_ideal R L) :
((I : lie_subalgebra R L) : set L) = I := rfl
@[norm_cast] lemma lie_ideal.coe_to_lie_subalgebra_to_submodule (I : lie_ideal R L) :
((I : lie_subalgebra R L) : submodule R L) = I := rfl
/-- An ideal of `L` is a Lie subalgebra of `L`, so it is a Lie ring. -/
instance lie_ideal.lie_ring (I : lie_ideal R L) : lie_ring I := lie_subalgebra.lie_ring R L ↑I
/-- Transfer the `lie_algebra` instance from the coercion `lie_ideal → lie_subalgebra`. -/
instance lie_ideal.lie_algebra (I : lie_ideal R L) : lie_algebra R I :=
lie_subalgebra.lie_algebra R L ↑I
/-- Transfer the `lie_module` instance from the coercion `lie_ideal → lie_subalgebra`. -/
instance lie_ideal.lie_ring_module {R L : Type*} [comm_ring R] [lie_ring L] [lie_algebra R L]
(I : lie_ideal R L) [lie_ring_module L M] : lie_ring_module I M :=
lie_subalgebra.lie_ring_module (I : lie_subalgebra R L)
@[simp]
theorem lie_ideal.coe_bracket_of_module {R L : Type*} [comm_ring R] [lie_ring L] [lie_algebra R L]
(I : lie_ideal R L) [lie_ring_module L M] (x : I) (m : M) :
⁅x,m⁆ = ⁅(↑x : L),m⁆ :=
lie_subalgebra.coe_bracket_of_module (I : lie_subalgebra R L) x m
/-- Transfer the `lie_module` instance from the coercion `lie_ideal → lie_subalgebra`. -/
instance lie_ideal.lie_module (I : lie_ideal R L) : lie_module R I M :=
lie_subalgebra.lie_module (I : lie_subalgebra R L)
end lie_ideal
variables {R M}
lemma submodule.exists_lie_submodule_coe_eq_iff (p : submodule R M) :
(∃ (N : lie_submodule R L M), ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p :=
begin
split,
{ rintros ⟨N, rfl⟩, exact N.lie_mem, },
{ intros h, use { lie_mem := h, ..p }, exact lie_submodule.coe_to_submodule_mk p _, },
end
namespace lie_subalgebra
variables {L} (K : lie_subalgebra R L)
/-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains
a distinguished Lie submodule for the action of `K`, namely `K` itself. -/
def to_lie_submodule : lie_submodule R K L :=
{ lie_mem := λ x y hy, K.lie_mem x.property hy,
.. (K : submodule R L) }
@[simp] lemma coe_to_lie_submodule :
(K.to_lie_submodule : submodule R L) = K :=
by { rcases K with ⟨⟨⟩⟩, refl, }
variables {K}
@[simp] lemma mem_to_lie_submodule (x : L) :
x ∈ K.to_lie_submodule ↔ x ∈ K :=
iff.rfl
lemma exists_lie_ideal_coe_eq_iff :
(∃ (I : lie_ideal R L), ↑I = K) ↔ ∀ (x y : L), y ∈ K → ⁅x, y⁆ ∈ K :=
begin
simp only [← coe_to_submodule_eq_iff, lie_ideal.coe_to_lie_subalgebra_to_submodule,
submodule.exists_lie_submodule_coe_eq_iff L],
exact iff.rfl,
end
lemma exists_nested_lie_ideal_coe_eq_iff {K' : lie_subalgebra R L} (h : K ≤ K') :
(∃ (I : lie_ideal R K'), ↑I = of_le h) ↔ ∀ (x y : L), x ∈ K' → y ∈ K → ⁅x, y⁆ ∈ K :=
begin
simp only [exists_lie_ideal_coe_eq_iff, coe_bracket, mem_of_le],
split,
{ intros h' x y hx hy, exact h' ⟨x, hx⟩ ⟨y, h hy⟩ hy, },
{ rintros h' ⟨x, hx⟩ ⟨y, hy⟩ hy', exact h' x y hx hy', },
end
end lie_subalgebra
end lie_submodule
namespace lie_submodule
variables {R : Type u} {L : Type v} {M : Type w}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
variables [lie_ring_module L M] [lie_module R L M]
variables (N N' : lie_submodule R L M) (I J : lie_ideal R L)
section lattice_structure
open set
lemma coe_injective : function.injective (coe : lie_submodule R L M → set M) :=
set_like.coe_injective
@[simp, norm_cast] lemma coe_submodule_le_coe_submodule : (N : submodule R M) ≤ N' ↔ N ≤ N' :=
iff.rfl
instance : has_bot (lie_submodule R L M) := ⟨0⟩
@[simp] lemma bot_coe : ((⊥ : lie_submodule R L M) : set M) = {0} := rfl
@[simp] lemma bot_coe_submodule : ((⊥ : lie_submodule R L M) : submodule R M) = ⊥ := rfl
@[simp] lemma mem_bot (x : M) : x ∈ (⊥ : lie_submodule R L M) ↔ x = 0 := mem_singleton_iff
instance : has_top (lie_submodule R L M) :=
⟨{ lie_mem := λ x m h, mem_univ ⁅x, m⁆,
..(⊤ : submodule R M) }⟩
@[simp] lemma top_coe : ((⊤ : lie_submodule R L M) : set M) = univ := rfl
@[simp] lemma top_coe_submodule : ((⊤ : lie_submodule R L M) : submodule R M) = ⊤ := rfl
@[simp] lemma mem_top (x : M) : x ∈ (⊤ : lie_submodule R L M) := mem_univ x
instance : has_inf (lie_submodule R L M) :=
⟨λ N N', { lie_mem := λ x m h, mem_inter (N.lie_mem h.1) (N'.lie_mem h.2),
..(N ⊓ N' : submodule R M) }⟩
instance : has_Inf (lie_submodule R L M) :=
⟨λ S, { lie_mem := λ x m h, by
{ simp only [submodule.mem_carrier, mem_Inter, submodule.Inf_coe, mem_set_of_eq,
forall_apply_eq_imp_iff₂, exists_imp_distrib] at *,
intros N hN, apply N.lie_mem (h N hN), },
..Inf {(s : submodule R M) | s ∈ S} }⟩
@[simp] theorem inf_coe : (↑(N ⊓ N') : set M) = N ∩ N' := rfl
@[simp] lemma Inf_coe_to_submodule (S : set (lie_submodule R L M)) :
(↑(Inf S) : submodule R M) = Inf {(s : submodule R M) | s ∈ S} := rfl
@[simp] lemma Inf_coe (S : set (lie_submodule R L M)) : (↑(Inf S) : set M) = ⋂ s ∈ S, (s : set M) :=
begin
rw [← lie_submodule.coe_to_submodule, Inf_coe_to_submodule, submodule.Inf_coe],
ext m,
simpa only [mem_Inter, mem_set_of_eq, forall_apply_eq_imp_iff₂, exists_imp_distrib],
end
lemma Inf_glb (S : set (lie_submodule R L M)) : is_glb S (Inf S) :=
begin
have h : ∀ (N N' : lie_submodule R L M), (N : set M) ≤ N' ↔ N ≤ N', { intros, refl },
apply is_glb.of_image h,
simp only [Inf_coe],
exact is_glb_binfi
end
/-- The set of Lie submodules of a Lie module form a complete lattice.
We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions
than we would otherwise obtain from `complete_lattice_of_Inf`. -/
instance : complete_lattice (lie_submodule R L M) :=
{ le := (≤),
lt := (<),
bot := ⊥,
bot_le := λ N _ h, by { rw mem_bot at h, rw h, exact N.zero_mem', },
top := ⊤,
le_top := λ _ _ _, trivial,
inf := (⊓),
le_inf := λ N₁ N₂ N₃ h₁₂ h₁₃ m hm, ⟨h₁₂ hm, h₁₃ hm⟩,
inf_le_left := λ _ _ _, and.left,
inf_le_right := λ _ _ _, and.right,
..set_like.partial_order,
..complete_lattice_of_Inf _ Inf_glb }
instance : add_comm_monoid (lie_submodule R L M) :=
{ add := (⊔),
add_assoc := λ _ _ _, sup_assoc,
zero := ⊥,
zero_add := λ _, bot_sup_eq,
add_zero := λ _, sup_bot_eq,
add_comm := λ _ _, sup_comm, }
@[simp] lemma add_eq_sup : N + N' = N ⊔ N' := rfl
@[norm_cast, simp] lemma sup_coe_to_submodule :
(↑(N ⊔ N') : submodule R M) = (N : submodule R M) ⊔ (N' : submodule R M) :=
begin
have aux : ∀ (x : L) m, m ∈ (N ⊔ N' : submodule R M) → ⁅x,m⁆ ∈ (N ⊔ N' : submodule R M),
{ simp only [submodule.mem_sup],
rintro x m ⟨y, hy, z, hz, rfl⟩,
refine ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ },
refine le_antisymm (Inf_le ⟨{ lie_mem := aux, ..(N ⊔ N' : submodule R M) }, _⟩) _,
{ simp only [exists_prop, and_true, mem_set_of_eq, eq_self_iff_true, coe_to_submodule_mk,
← coe_submodule_le_coe_submodule, and_self, le_sup_left, le_sup_right] },
{ simp, },
end
@[norm_cast, simp] lemma inf_coe_to_submodule :
(↑(N ⊓ N') : submodule R M) = (N : submodule R M) ⊓ (N' : submodule R M) := rfl
@[simp] lemma mem_inf (x : M) : x ∈ N ⊓ N' ↔ x ∈ N ∧ x ∈ N' :=
by rw [← mem_coe_submodule, ← mem_coe_submodule, ← mem_coe_submodule, inf_coe_to_submodule,
submodule.mem_inf]
lemma mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ (y ∈ N) (z ∈ N'), y + z = x :=
by { rw [← mem_coe_submodule, sup_coe_to_submodule, submodule.mem_sup], exact iff.rfl, }
lemma eq_bot_iff : N = ⊥ ↔ ∀ (m : M), m ∈ N → m = 0 :=
by { rw eq_bot_iff, exact iff.rfl, }
instance subsingleton_of_bot : subsingleton (lie_submodule R L ↥(⊥ : lie_submodule R L M)) :=
begin
apply subsingleton_of_bot_eq_top,
ext ⟨x, hx⟩, change x ∈ ⊥ at hx, rw lie_submodule.mem_bot at hx, subst hx,
simp only [true_iff, eq_self_iff_true, submodule.mk_eq_zero, lie_submodule.mem_bot],
end
instance : is_modular_lattice (lie_submodule R L M) :=
{ sup_inf_le_assoc_of_le := λ N₁ N₂ N₃,
by { simp only [← coe_submodule_le_coe_submodule, sup_coe_to_submodule, inf_coe_to_submodule],
exact is_modular_lattice.sup_inf_le_assoc_of_le ↑N₂, }, }
variables (R L M)
lemma well_founded_of_noetherian [is_noetherian R M] :
well_founded ((>) : lie_submodule R L M → lie_submodule R L M → Prop) :=
let f : ((>) : lie_submodule R L M → lie_submodule R L M → Prop) →r
((>) : submodule R M → submodule R M → Prop) :=
{ to_fun := coe,
map_rel' := λ N N' h, h, }
in rel_hom_class.well_founded f (is_noetherian_iff_well_founded.mp infer_instance)
@[simp] lemma subsingleton_iff : subsingleton (lie_submodule R L M) ↔ subsingleton M :=
have h : subsingleton (lie_submodule R L M) ↔ subsingleton (submodule R M),
{ rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← coe_to_submodule_eq_iff,
top_coe_submodule, bot_coe_submodule], },
h.trans $ submodule.subsingleton_iff R
@[simp] lemma nontrivial_iff : nontrivial (lie_submodule R L M) ↔ nontrivial M :=
not_iff_not.mp (
(not_nontrivial_iff_subsingleton.trans $ subsingleton_iff R L M).trans
not_nontrivial_iff_subsingleton.symm)
instance [nontrivial M] : nontrivial (lie_submodule R L M) := (nontrivial_iff R L M).mpr ‹_›
lemma nontrivial_iff_ne_bot {N : lie_submodule R L M} : nontrivial N ↔ N ≠ ⊥ :=
begin
split;
contrapose!,
{ rintros rfl ⟨⟨m₁, h₁ : m₁ ∈ (⊥ : lie_submodule R L M)⟩,
⟨m₂, h₂ : m₂ ∈ (⊥ : lie_submodule R L M)⟩, h₁₂⟩,
simpa [(lie_submodule.mem_bot _).mp h₁, (lie_submodule.mem_bot _).mp h₂] using h₁₂, },
{ rw [not_nontrivial_iff_subsingleton, lie_submodule.eq_bot_iff],
rintros ⟨h⟩ m hm,
simpa using h ⟨m, hm⟩ ⟨_, N.zero_mem⟩, },
end
variables {R L M}
section inclusion_maps
/-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/
def incl : N →ₗ⁅R,L⁆ M :=
{ map_lie' := λ x m, rfl,
..submodule.subtype (N : submodule R M) }
@[simp] lemma incl_coe : (N.incl : N →ₗ[R] M) = (N : submodule R M).subtype := rfl
@[simp] lemma incl_apply (m : N) : N.incl m = m := rfl
lemma incl_eq_val : (N.incl : N → M) = subtype.val := rfl
variables {N N'} (h : N ≤ N')
/-- Given two nested Lie submodules `N ⊆ N'`, the inclusion `N ↪ N'` is a morphism of Lie modules.-/
def hom_of_le : N →ₗ⁅R,L⁆ N' :=
{ map_lie' := λ x m, rfl,
..submodule.of_le (show N.to_submodule ≤ N'.to_submodule, from h) }
@[simp] lemma coe_hom_of_le (m : N) : (hom_of_le h m : M) = m := rfl
lemma hom_of_le_apply (m : N) : hom_of_le h m = ⟨m.1, h m.2⟩ := rfl
lemma hom_of_le_injective : function.injective (hom_of_le h) :=
λ x y, by simp only [hom_of_le_apply, imp_self, subtype.mk_eq_mk, set_like.coe_eq_coe,
subtype.val_eq_coe]
end inclusion_maps
section lie_span
variables (R L) (s : set M)
/-- The `lie_span` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/
def lie_span : lie_submodule R L M := Inf {N | s ⊆ N}
variables {R L s}
lemma mem_lie_span {x : M} : x ∈ lie_span R L s ↔ ∀ N : lie_submodule R L M, s ⊆ N → x ∈ N :=
by { change x ∈ (lie_span R L s : set M) ↔ _, erw Inf_coe, exact mem_Inter₂, }
lemma subset_lie_span : s ⊆ lie_span R L s :=
by { intros m hm, erw mem_lie_span, intros N hN, exact hN hm, }
lemma submodule_span_le_lie_span : submodule.span R s ≤ lie_span R L s :=
by { rw submodule.span_le, apply subset_lie_span, }
lemma lie_span_le {N} : lie_span R L s ≤ N ↔ s ⊆ N :=
begin
split,
{ exact subset.trans subset_lie_span, },
{ intros hs m hm, rw mem_lie_span at hm, exact hm _ hs, },
end
lemma lie_span_mono {t : set M} (h : s ⊆ t) : lie_span R L s ≤ lie_span R L t :=
by { rw lie_span_le, exact subset.trans h subset_lie_span, }
lemma lie_span_eq : lie_span R L (N : set M) = N :=
le_antisymm (lie_span_le.mpr rfl.subset) subset_lie_span
lemma coe_lie_span_submodule_eq_iff {p : submodule R M} :
(lie_span R L (p : set M) : submodule R M) = p ↔ ∃ (N : lie_submodule R L M), ↑N = p :=
begin
rw p.exists_lie_submodule_coe_eq_iff L, split; intros h,
{ intros x m hm, rw [← h, mem_coe_submodule], exact lie_mem _ (subset_lie_span hm), },
{ rw [← coe_to_submodule_mk p h, coe_to_submodule, coe_to_submodule_eq_iff, lie_span_eq], },
end
variables (R L M)
/-- `lie_span` forms a Galois insertion with the coercion from `lie_submodule` to `set`. -/
protected def gi : galois_insertion (lie_span R L : set M → lie_submodule R L M) coe :=
{ choice := λ s _, lie_span R L s,
gc := λ s t, lie_span_le,
le_l_u := λ s, subset_lie_span,
choice_eq := λ s h, rfl }
@[simp] lemma span_empty : lie_span R L (∅ : set M) = ⊥ :=
(lie_submodule.gi R L M).gc.l_bot
@[simp] lemma span_univ : lie_span R L (set.univ : set M) = ⊤ :=
eq_top_iff.2 $ set_like.le_def.2 $ subset_lie_span
lemma lie_span_eq_bot_iff : lie_span R L s = ⊥ ↔ ∀ (m ∈ s), m = (0 : M) :=
by rw [_root_.eq_bot_iff, lie_span_le, bot_coe, subset_singleton_iff]
variables {M}
lemma span_union (s t : set M) : lie_span R L (s ∪ t) = lie_span R L s ⊔ lie_span R L t :=
(lie_submodule.gi R L M).gc.l_sup
lemma span_Union {ι} (s : ι → set M) : lie_span R L (⋃ i, s i) = ⨆ i, lie_span R L (s i) :=
(lie_submodule.gi R L M).gc.l_supr
end lie_span
end lattice_structure
end lie_submodule
section lie_submodule_map_and_comap
variables {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁}
variables [comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
variables [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
variables [add_comm_group M'] [module R M'] [lie_ring_module L M'] [lie_module R L M']
namespace lie_submodule
variables (f : M →ₗ⁅R,L⁆ M') (N N₂ : lie_submodule R L M) (N' : lie_submodule R L M')
/-- A morphism of Lie modules `f : M → M'` pushes forward Lie submodules of `M` to Lie submodules
of `M'`. -/
def map : lie_submodule R L M' :=
{ lie_mem := λ x m' h, by
{ rcases h with ⟨m, hm, hfm⟩, use ⁅x, m⁆, split,
{ apply N.lie_mem hm, },
{ norm_cast at hfm, simp [hfm], }, },
..(N : submodule R M).map (f : M →ₗ[R] M') }
@[simp] lemma coe_submodule_map :
(N.map f : submodule R M') = (N : submodule R M).map (f : M →ₗ[R] M') :=
rfl
/-- A morphism of Lie modules `f : M → M'` pulls back Lie submodules of `M'` to Lie submodules of
`M`. -/
def comap : lie_submodule R L M :=
{ lie_mem := λ x m h, by { suffices : ⁅x, f m⁆ ∈ N', { simp [this], }, apply N'.lie_mem h, },
..(N' : submodule R M').comap (f : M →ₗ[R] M') }
@[simp] lemma coe_submodule_comap :
(N'.comap f : submodule R M) = (N' : submodule R M').comap (f : M →ₗ[R] M') :=
rfl
variables {f N N₂ N'}
lemma map_le_iff_le_comap : map f N ≤ N' ↔ N ≤ comap f N' :=
set.image_subset_iff
variables (f)
lemma gc_map_comap : galois_connection (map f) (comap f) :=
λ N N', map_le_iff_le_comap
variables {f}
@[simp] lemma map_sup : (N ⊔ N₂).map f = N.map f ⊔ N₂.map f :=
(gc_map_comap f).l_sup
lemma mem_map (m' : M') : m' ∈ N.map f ↔ ∃ m, m ∈ N ∧ f m = m' :=
submodule.mem_map
@[simp] lemma mem_comap {m : M} : m ∈ comap f N' ↔ f m ∈ N' := iff.rfl
lemma comap_incl_eq_top : N₂.comap N.incl = ⊤ ↔ N ≤ N₂ :=
by simpa only [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.coe_submodule_comap,
lie_submodule.incl_coe, lie_submodule.top_coe_submodule, submodule.comap_subtype_eq_top]
lemma comap_incl_eq_bot : N₂.comap N.incl = ⊥ ↔ N ⊓ N₂ = ⊥ :=
by simpa only [_root_.eq_bot_iff, ← lie_submodule.coe_to_submodule_eq_iff,
lie_submodule.coe_submodule_comap, lie_submodule.incl_coe, lie_submodule.bot_coe_submodule,
← submodule.disjoint_iff_comap_eq_bot]
end lie_submodule
namespace lie_ideal
variables (f : L →ₗ⁅R⁆ L') (I I₂ : lie_ideal R L) (J : lie_ideal R L')
@[simp] lemma top_coe_lie_subalgebra : ((⊤ : lie_ideal R L) : lie_subalgebra R L) = ⊤ := rfl
/-- A morphism of Lie algebras `f : L → L'` pushes forward Lie ideals of `L` to Lie ideals of `L'`.
Note that unlike `lie_submodule.map`, we must take the `lie_span` of the image. Mathematically
this is because although `f` makes `L'` into a Lie module over `L`, in general the `L` submodules of
`L'` are not the same as the ideals of `L'`. -/
def map : lie_ideal R L' := lie_submodule.lie_span R L' $ (I : submodule R L).map (f : L →ₗ[R] L')
/-- A morphism of Lie algebras `f : L → L'` pulls back Lie ideals of `L'` to Lie ideals of `L`.
Note that `f` makes `L'` into a Lie module over `L` (turning `f` into a morphism of Lie modules)
and so this is a special case of `lie_submodule.comap` but we do not exploit this fact. -/
def comap : lie_ideal R L :=
{ lie_mem := λ x y h, by { suffices : ⁅f x, f y⁆ ∈ J, { simp [this], }, apply J.lie_mem h, },
..(J : submodule R L').comap (f : L →ₗ[R] L') }
@[simp] lemma map_coe_submodule (h : ↑(map f I) = f '' I) :
(map f I : submodule R L') = (I : submodule R L).map (f : L →ₗ[R] L') :=
by { rw [set_like.ext'_iff, lie_submodule.coe_to_submodule, h, submodule.map_coe], refl, }
@[simp] lemma comap_coe_submodule :
(comap f J : submodule R L) = (J : submodule R L').comap (f : L →ₗ[R] L') := rfl
lemma map_le : map f I ≤ J ↔ f '' I ⊆ J := lie_submodule.lie_span_le
variables {f I I₂ J}
lemma mem_map {x : L} (hx : x ∈ I) : f x ∈ map f I :=
by { apply lie_submodule.subset_lie_span, use x, exact ⟨hx, rfl⟩, }
@[simp] lemma mem_comap {x : L} : x ∈ comap f J ↔ f x ∈ J := iff.rfl
lemma map_le_iff_le_comap : map f I ≤ J ↔ I ≤ comap f J :=
by { rw map_le, exact set.image_subset_iff, }
variables (f)
lemma gc_map_comap : galois_connection (map f) (comap f) :=
λ I I', map_le_iff_le_comap
variables {f}
@[simp] lemma map_sup : (I ⊔ I₂).map f = I.map f ⊔ I₂.map f :=
(gc_map_comap f).l_sup
lemma map_comap_le : map f (comap f J) ≤ J :=
by { rw map_le_iff_le_comap, exact le_rfl, }
/-- See also `lie_ideal.map_comap_eq`. -/
lemma comap_map_le : I ≤ comap f (map f I) :=
by { rw ← map_le_iff_le_comap, exact le_rfl, }
@[mono] lemma map_mono : monotone (map f) :=
λ I₁ I₂ h,
by { rw set_like.le_def at h, apply lie_submodule.lie_span_mono (set.image_subset ⇑f h), }
@[mono] lemma comap_mono : monotone (comap f) :=
λ J₁ J₂ h, by { rw ← set_like.coe_subset_coe at h ⊢, exact set.preimage_mono h, }
lemma map_of_image (h : f '' I = J) : I.map f = J :=
begin
apply le_antisymm,
{ erw [lie_submodule.lie_span_le, submodule.map_coe, h], },
{ rw [← set_like.coe_subset_coe, ← h], exact lie_submodule.subset_lie_span, },
end
/-- Note that this is not a special case of `lie_submodule.subsingleton_of_bot`. Indeed, given
`I : lie_ideal R L`, in general the two lattices `lie_ideal R I` and `lie_submodule R L I` are
different (though the latter does naturally inject into the former).
In other words, in general, ideals of `I`, regarded as a Lie algebra in its own right, are not the
same as ideals of `L` contained in `I`. -/
instance subsingleton_of_bot : subsingleton (lie_ideal R (⊥ : lie_ideal R L)) :=
begin
apply subsingleton_of_bot_eq_top,
ext ⟨x, hx⟩, change x ∈ ⊥ at hx, rw lie_submodule.mem_bot at hx, subst hx,
simp only [true_iff, eq_self_iff_true, submodule.mk_eq_zero, lie_submodule.mem_bot],
end
end lie_ideal
namespace lie_hom
variables (f : L →ₗ⁅R⁆ L') (I : lie_ideal R L) (J : lie_ideal R L')
/-- The kernel of a morphism of Lie algebras, as an ideal in the domain. -/
def ker : lie_ideal R L := lie_ideal.comap f ⊥
/-- The range of a morphism of Lie algebras as an ideal in the codomain. -/
def ideal_range : lie_ideal R L' := lie_submodule.lie_span R L' f.range
lemma ideal_range_eq_lie_span_range :
f.ideal_range = lie_submodule.lie_span R L' f.range := rfl
lemma ideal_range_eq_map :
f.ideal_range = lie_ideal.map f ⊤ :=
by { ext, simp only [ideal_range, range_eq_map], refl }
/-- The condition that the image of a morphism of Lie algebras is an ideal. -/
def is_ideal_morphism : Prop := (f.ideal_range : lie_subalgebra R L') = f.range
@[simp] lemma is_ideal_morphism_def :
f.is_ideal_morphism ↔ (f.ideal_range : lie_subalgebra R L') = f.range := iff.rfl
lemma is_ideal_morphism_iff :
f.is_ideal_morphism ↔ ∀ (x : L') (y : L), ∃ (z : L), ⁅x, f y⁆ = f z :=
begin
simp only [is_ideal_morphism_def, ideal_range_eq_lie_span_range,
← lie_subalgebra.coe_to_submodule_eq_iff, ← f.range.coe_to_submodule,
lie_ideal.coe_to_lie_subalgebra_to_submodule, lie_submodule.coe_lie_span_submodule_eq_iff,
lie_subalgebra.mem_coe_submodule, mem_range, exists_imp_distrib,
submodule.exists_lie_submodule_coe_eq_iff],
split,
{ intros h x y, obtain ⟨z, hz⟩ := h x (f y) y rfl, use z, exact hz.symm, },
{ intros h x y z hz, obtain ⟨w, hw⟩ := h x z, use w, rw [← hw, hz], },
end
lemma range_subset_ideal_range : (f.range : set L') ⊆ f.ideal_range := lie_submodule.subset_lie_span
lemma map_le_ideal_range : I.map f ≤ f.ideal_range :=
begin
rw f.ideal_range_eq_map,
exact lie_ideal.map_mono le_top,
end
lemma ker_le_comap : f.ker ≤ J.comap f := lie_ideal.comap_mono bot_le
@[simp] lemma ker_coe_submodule : (ker f : submodule R L) = (f : L →ₗ[R] L').ker := rfl
@[simp] lemma mem_ker {x : L} : x ∈ ker f ↔ f x = 0 :=
show x ∈ (f.ker : submodule R L) ↔ _,
by simp only [ker_coe_submodule, linear_map.mem_ker, coe_to_linear_map]
lemma mem_ideal_range {x : L} : f x ∈ ideal_range f :=
begin
rw ideal_range_eq_map,
exact lie_ideal.mem_map (lie_submodule.mem_top x)
end
@[simp] lemma mem_ideal_range_iff (h : is_ideal_morphism f) {y : L'} :
y ∈ ideal_range f ↔ ∃ (x : L), f x = y :=
begin
rw f.is_ideal_morphism_def at h,
rw [← lie_submodule.mem_coe, ← lie_ideal.coe_to_subalgebra, h, f.range_coe, set.mem_range],
end
lemma le_ker_iff : I ≤ f.ker ↔ ∀ x, x ∈ I → f x = 0 :=
begin
split; intros h x hx,
{ specialize h hx, rw mem_ker at h, exact h, },
{ rw mem_ker, apply h x hx, },
end
lemma ker_eq_bot : f.ker = ⊥ ↔ function.injective f :=
by rw [← lie_submodule.coe_to_submodule_eq_iff, ker_coe_submodule, lie_submodule.bot_coe_submodule,
linear_map.ker_eq_bot, coe_to_linear_map]
@[simp] lemma range_coe_submodule : (f.range : submodule R L') = (f : L →ₗ[R] L').range := rfl
lemma range_eq_top : f.range = ⊤ ↔ function.surjective f :=
begin
rw [← lie_subalgebra.coe_to_submodule_eq_iff, range_coe_submodule,
lie_subalgebra.top_coe_submodule],
exact linear_map.range_eq_top,
end
@[simp] lemma ideal_range_eq_top_of_surjective (h : function.surjective f) : f.ideal_range = ⊤ :=
begin
rw ← f.range_eq_top at h,
rw [ideal_range_eq_lie_span_range, h, ← lie_subalgebra.coe_to_submodule,
← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule,
lie_subalgebra.top_coe_submodule, lie_submodule.coe_lie_span_submodule_eq_iff],
use ⊤,
exact lie_submodule.top_coe_submodule,
end
lemma is_ideal_morphism_of_surjective (h : function.surjective f) : f.is_ideal_morphism :=
by rw [is_ideal_morphism_def, f.ideal_range_eq_top_of_surjective h, f.range_eq_top.mpr h,
lie_ideal.top_coe_lie_subalgebra]
end lie_hom
namespace lie_ideal
variables {f : L →ₗ⁅R⁆ L'} {I : lie_ideal R L} {J : lie_ideal R L'}
@[simp] lemma map_eq_bot_iff : I.map f = ⊥ ↔ I ≤ f.ker :=
by { rw ← le_bot_iff, exact lie_ideal.map_le_iff_le_comap }
lemma coe_map_of_surjective (h : function.surjective f) :
(I.map f : submodule R L') = (I : submodule R L).map (f : L →ₗ[R] L') :=
begin
let J : lie_ideal R L' :=
{ lie_mem := λ x y hy,
begin
have hy' : ∃ (x : L), x ∈ I ∧ f x = y, { simpa [hy], },
obtain ⟨z₂, hz₂, rfl⟩ := hy',
obtain ⟨z₁, rfl⟩ := h x,
simp only [lie_hom.coe_to_linear_map, set_like.mem_coe, set.mem_image,
lie_submodule.mem_coe_submodule, submodule.mem_carrier, submodule.map_coe],
use ⁅z₁, z₂⁆,
exact ⟨I.lie_mem hz₂, f.map_lie z₁ z₂⟩,
end,
..(I : submodule R L).map (f : L →ₗ[R] L'), },
erw lie_submodule.coe_lie_span_submodule_eq_iff,
use J,
apply lie_submodule.coe_to_submodule_mk,
end
lemma mem_map_of_surjective {y : L'} (h₁ : function.surjective f) (h₂ : y ∈ I.map f) :
∃ (x : I), f x = y :=
begin
rw [← lie_submodule.mem_coe_submodule, coe_map_of_surjective h₁, submodule.mem_map] at h₂,
obtain ⟨x, hx, rfl⟩ := h₂,
use ⟨x, hx⟩,
refl,
end
lemma bot_of_map_eq_bot {I : lie_ideal R L} (h₁ : function.injective f) (h₂ : I.map f = ⊥) :
I = ⊥ :=
begin
rw ← f.ker_eq_bot at h₁, change comap f ⊥ = ⊥ at h₁,
rw [eq_bot_iff, map_le_iff_le_comap, h₁] at h₂,
rw eq_bot_iff, exact h₂,
end
/-- Given two nested Lie ideals `I₁ ⊆ I₂`, the inclusion `I₁ ↪ I₂` is a morphism of Lie algebras. -/
def hom_of_le {I₁ I₂ : lie_ideal R L} (h : I₁ ≤ I₂) : I₁ →ₗ⁅R⁆ I₂ :=
{ map_lie' := λ x y, rfl,
..submodule.of_le (show I₁.to_submodule ≤ I₂.to_submodule, from h), }
@[simp] lemma coe_hom_of_le {I₁ I₂ : lie_ideal R L} (h : I₁ ≤ I₂) (x : I₁) :
(hom_of_le h x : L) = x := rfl
lemma hom_of_le_apply {I₁ I₂ : lie_ideal R L} (h : I₁ ≤ I₂) (x : I₁) :
hom_of_le h x = ⟨x.1, h x.2⟩ := rfl
lemma hom_of_le_injective {I₁ I₂ : lie_ideal R L} (h : I₁ ≤ I₂) :
function.injective (hom_of_le h) :=
λ x y, by simp only [hom_of_le_apply, imp_self, subtype.mk_eq_mk, set_like.coe_eq_coe,
subtype.val_eq_coe]
@[simp] lemma map_sup_ker_eq_map : lie_ideal.map f (I ⊔ f.ker) = lie_ideal.map f I :=
begin
suffices : lie_ideal.map f (I ⊔ f.ker) ≤ lie_ideal.map f I,
{ exact le_antisymm this (lie_ideal.map_mono le_sup_left), },
apply lie_submodule.lie_span_mono,
rintros x ⟨y, hy₁, hy₂⟩, rw ← hy₂,
erw lie_submodule.mem_sup at hy₁, obtain ⟨z₁, hz₁, z₂, hz₂, hy⟩ := hy₁, rw ← hy,
rw [f.coe_to_linear_map, f.map_add, f.mem_ker.mp hz₂, add_zero], exact ⟨z₁, hz₁, rfl⟩,
end
@[simp] lemma map_comap_eq (h : f.is_ideal_morphism) : map f (comap f J) = f.ideal_range ⊓ J :=
begin
apply le_antisymm,
{ rw le_inf_iff, exact ⟨f.map_le_ideal_range _, map_comap_le⟩, },
{ rw f.is_ideal_morphism_def at h,
rw [← set_like.coe_subset_coe, lie_submodule.inf_coe, ← coe_to_subalgebra, h],
rintros y ⟨⟨x, h₁⟩, h₂⟩, rw ← h₁ at h₂ ⊢, exact mem_map h₂, },
end
@[simp] lemma comap_map_eq (h : ↑(map f I) = f '' I) : comap f (map f I) = I ⊔ f.ker :=
by rw [← lie_submodule.coe_to_submodule_eq_iff, comap_coe_submodule, I.map_coe_submodule f h,
lie_submodule.sup_coe_to_submodule, f.ker_coe_submodule, submodule.comap_map_eq]
variables (f I J)
/-- Regarding an ideal `I` as a subalgebra, the inclusion map into its ambient space is a morphism
of Lie algebras. -/
def incl : I →ₗ⁅R⁆ L := (I : lie_subalgebra R L).incl
@[simp] lemma incl_range : I.incl.range = I := (I : lie_subalgebra R L).incl_range
@[simp] lemma incl_apply (x : I) : I.incl x = x := rfl
@[simp] lemma incl_coe : (I.incl : I →ₗ[R] L) = (I : submodule R L).subtype := rfl
@[simp] lemma comap_incl_self : comap I.incl I = ⊤ :=
by rw [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule,
lie_ideal.comap_coe_submodule, lie_ideal.incl_coe, submodule.comap_subtype_self]
@[simp] lemma ker_incl : I.incl.ker = ⊥ :=
by rw [← lie_submodule.coe_to_submodule_eq_iff, I.incl.ker_coe_submodule,
lie_submodule.bot_coe_submodule, incl_coe, submodule.ker_subtype]
@[simp] lemma incl_ideal_range : I.incl.ideal_range = I :=
begin
rw [lie_hom.ideal_range_eq_lie_span_range, ← lie_subalgebra.coe_to_submodule,
← lie_submodule.coe_to_submodule_eq_iff, incl_range, coe_to_lie_subalgebra_to_submodule,
lie_submodule.coe_lie_span_submodule_eq_iff],
use I,
end
lemma incl_is_ideal_morphism : I.incl.is_ideal_morphism :=
begin
rw [I.incl.is_ideal_morphism_def, incl_ideal_range],
exact (I : lie_subalgebra R L).incl_range.symm,
end
end lie_ideal
end lie_submodule_map_and_comap
namespace lie_module_hom
variables {R : Type u} {L : Type v} {M : Type w} {N : Type w₁}
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
variables [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
variables [add_comm_group N] [module R N] [lie_ring_module L N] [lie_module R L N]
variables (f : M →ₗ⁅R,L⁆ N)
/-- The kernel of a morphism of Lie algebras, as an ideal in the domain. -/
def ker : lie_submodule R L M := lie_submodule.comap f ⊥
@[simp] lemma ker_coe_submodule : (f.ker : submodule R M) = (f : M →ₗ[R] N).ker := rfl
lemma ker_eq_bot : f.ker = ⊥ ↔ function.injective f :=
by rw [← lie_submodule.coe_to_submodule_eq_iff, ker_coe_submodule, lie_submodule.bot_coe_submodule,
linear_map.ker_eq_bot, coe_to_linear_map]
variables {f}
@[simp] lemma mem_ker (m : M) : m ∈ f.ker ↔ f m = 0 := iff.rfl
@[simp] lemma ker_id : (lie_module_hom.id : M →ₗ⁅R,L⁆ M).ker = ⊥ := rfl
@[simp] lemma comp_ker_incl : f.comp f.ker.incl = 0 :=
by { ext ⟨m, hm⟩, exact (mem_ker m).mp hm, }
lemma le_ker_iff_map (M' : lie_submodule R L M) :
M' ≤ f.ker ↔ lie_submodule.map f M' = ⊥ :=
by rw [ker, eq_bot_iff, lie_submodule.map_le_iff_le_comap]
variables (f)
/-- The range of a morphism of Lie modules `f : M → N` is a Lie submodule of `N`.
See Note [range copy pattern]. -/
def range : lie_submodule R L N :=
(lie_submodule.map f ⊤).copy (set.range f) set.image_univ.symm
@[simp] lemma coe_range : (f.range : set N) = set.range f := rfl
@[simp] lemma coe_submodule_range : (f.range : submodule R N) = (f : M →ₗ[R] N).range := rfl
@[simp] lemma mem_range (n : N) : n ∈ f.range ↔ ∃ m, f m = n :=
iff.rfl
lemma map_top : lie_submodule.map f ⊤ = f.range :=
by { ext, simp [lie_submodule.mem_map], }
end lie_module_hom
namespace lie_submodule
variables {R : Type u} {L : Type v} {M : Type w}
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
variables [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
variables (N : lie_submodule R L M)
@[simp] lemma ker_incl : N.incl.ker = ⊥ :=
by simp [← lie_submodule.coe_to_submodule_eq_iff]
@[simp] lemma range_incl : N.incl.range = N :=
by simp [← lie_submodule.coe_to_submodule_eq_iff]
@[simp] lemma comap_incl_self : comap N.incl N = ⊤ :=
by simp [← lie_submodule.coe_to_submodule_eq_iff]
end lie_submodule
section top_equiv
variables {R : Type u} {L : Type v}
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
/-- The natural equivalence between the 'top' Lie subalgebra and the enclosing Lie algebra.
This is the Lie subalgebra version of `submodule.top_equiv`. -/
def lie_subalgebra.top_equiv : (⊤ : lie_subalgebra R L) ≃ₗ⁅R⁆ L :=
{ inv_fun := λ x, ⟨x, set.mem_univ x⟩,
left_inv := λ x, by { ext, refl, },
right_inv := λ x, rfl,
..(⊤ : lie_subalgebra R L).incl, }
@[simp] lemma lie_subalgebra.top_equiv_apply (x : (⊤ : lie_subalgebra R L)) :
lie_subalgebra.top_equiv x = x := rfl
/-- The natural equivalence between the 'top' Lie ideal and the enclosing Lie algebra.
This is the Lie ideal version of `submodule.top_equiv`. -/
def lie_ideal.top_equiv : (⊤ : lie_ideal R L) ≃ₗ⁅R⁆ L :=
lie_subalgebra.top_equiv
@[simp] lemma lie_ideal.top_equiv_apply (x : (⊤ : lie_ideal R L)) :
lie_ideal.top_equiv x = x := rfl
end top_equiv
|
a89c44e5afc16c6b2c0a88cb1133e3e2a4218980 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /test/instance_cache.lean | 8a2dd531378dbe6957a986e2366fa0a49575dc5c | [
"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,333 | lean | import tactic.cache
meta def assert_frozen_instances : tactic unit := do
frozen ← tactic.frozen_local_instances,
when frozen.is_none $ tactic.fail "instances are not frozen"
example (α) (a : α) :=
begin
haveI h : inhabited α := ⟨a⟩,
assert_frozen_instances,
exact (default : α)
end
example (α) (a : α) :=
begin
haveI h := inhabited.mk a,
assert_frozen_instances,
exact (default : α)
end
example (α) (a : α) :=
begin
letI h : inhabited α := ⟨a⟩,
assert_frozen_instances,
exact (default : α)
end
example (α) (a : α) :=
begin
letI h : inhabited α,
all_goals { assert_frozen_instances },
exact ⟨a⟩,
exact (default : α)
end
example (α) (a : α) :=
begin
letI h := inhabited.mk a,
exact (default : α)
end
example (α) : inhabited α → α :=
by intro a; exactI default
example (α) : inhabited α → α :=
begin
introsI a,
assert_frozen_instances,
exact default
end
example (α β) (h : α = β) [inhabited α] : β :=
begin
substI h,
assert_frozen_instances,
exact default
end
example (α β) (h : α = β) [inhabited α] : β :=
begin
unfreezingI { cases _inst_1 },
assert_frozen_instances,
subst h, assumption
end
example (α β) (h : α = β) [inhabited α] : β :=
begin
casesI _inst_1,
assert_frozen_instances,
subst h, assumption
end
|
c843ec6bd1ff893dd5d2a3968446907ef2e17be7 | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/data/polynomial/degree/definitions.lean | 4b8522c523db61e7fb83450e9e972ea66deefb23 | [
"Apache-2.0"
] | permissive | hamdysalah1/mathlib | b915f86b2503feeae268de369f1b16932321f097 | 95454452f6b3569bf967d35aab8d852b1ddf8017 | refs/heads/master | 1,677,154,116,545 | 1,611,797,994,000 | 1,611,797,994,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 36,635 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.coeff
import data.nat.with_bot
/-!
# Theory of univariate polynomials
The definitions include
`degree`, `monic`, `leading_coeff`
Results include
- `degree_mul` : The degree of the product is the sum of degrees
- `leading_coeff_add_of_degree_eq` and `leading_coeff_add_of_degree_lt` :
The leading_coefficient of a sum is determined by the leading coefficients and degrees
-/
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
open finsupp finset
open_locale big_operators
namespace polynomial
universes u v
variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
section semiring
variables [semiring R] {p q r : polynomial R}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : polynomial R) : with_bot ℕ := p.support.sup some
lemma degree_lt_wf : well_founded (λp q : polynomial R, degree p < degree q) :=
inv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)
instance : has_well_founded (polynomial R) := ⟨_, degree_lt_wf⟩
/-- `nat_degree p` forces `degree p` to ℕ, by defining nat_degree 0 = 0. -/
def nat_degree (p : polynomial R) : ℕ := (degree p).get_or_else 0
/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/
def leading_coeff (p : polynomial R) : R := coeff p (nat_degree p)
/-- a polynomial is `monic` if its leading coefficient is 1 -/
def monic (p : polynomial R) := leading_coeff p = (1 : R)
@[nontriviality] lemma monic_of_subsingleton [subsingleton R] (p : polynomial R) : monic p :=
subsingleton.elim _ _
lemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl
instance monic.decidable [decidable_eq R] : decidable (monic p) :=
by unfold monic; apply_instance
@[simp] lemma monic.leading_coeff {p : polynomial R} (hp : p.monic) :
leading_coeff p = 1 := hp
lemma monic.coeff_nat_degree {p : polynomial R} (hp : p.monic) : p.coeff p.nat_degree = 1 := hp
@[simp] lemma degree_zero : degree (0 : polynomial R) = ⊥ := rfl
@[simp] lemma nat_degree_zero : nat_degree (0 : polynomial R) = 0 := rfl
@[simp] lemma coeff_nat_degree : coeff p (nat_degree p) = leading_coeff p := rfl
lemma degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h;
exact support_eq_empty.1 (max_eq_none.1 h),
λ h, h.symm ▸ rfl⟩
@[nontriviality] lemma degree_of_subsingleton [subsingleton R] : degree p = ⊥ :=
by rw [subsingleton.elim p 0, degree_zero]
@[nontriviality] lemma nat_degree_of_subsingleton [subsingleton R] : nat_degree p = 0 :=
by rw [subsingleton.elim p 0, nat_degree_zero]
lemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) :=
let ⟨n, hn⟩ :=
not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in
have hn : degree p = some n := not_not.1 hn,
by rw [nat_degree, hn]; refl
lemma degree_eq_iff_nat_degree_eq {p : polynomial R} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.nat_degree = n :=
by rw [degree_eq_nat_degree hp, with_bot.coe_eq_coe]
lemma degree_eq_iff_nat_degree_eq_of_pos {p : polynomial R} {n : ℕ} (hn : 0 < n) :
p.degree = n ↔ p.nat_degree = n :=
begin
split,
{ intro H, rwa ← degree_eq_iff_nat_degree_eq, rintro rfl,
rw degree_zero at H, exact option.no_confusion H },
{ intro H, rwa degree_eq_iff_nat_degree_eq, rintro rfl,
rw nat_degree_zero at H, rw H at hn, exact lt_irrefl _ hn }
end
lemma nat_degree_eq_of_degree_eq_some {p : polynomial R} {n : ℕ}
(h : degree p = n) : nat_degree p = n :=
have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,
option.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n,
by rwa [← degree_eq_nat_degree hp0]
@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=
with_bot.gi_get_or_else_bot.gc.le_u_l _
lemma nat_degree_eq_of_degree_eq [semiring S] {q : polynomial S} (h : degree p = degree q) :
nat_degree p = nat_degree q :=
by unfold nat_degree; rw h
lemma le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : with_bot ℕ) ≤ degree p :=
show @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ),
from finset.le_sup (finsupp.mem_support_iff.2 h)
lemma le_nat_degree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ nat_degree p :=
begin
rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],
exact le_degree_of_ne_zero h,
{ assume h, subst h, exact h rfl }
end
lemma le_nat_degree_of_mem_supp (a : ℕ) :
a ∈ p.support → a ≤ nat_degree p:=
le_nat_degree_of_ne_zero ∘ mem_support_iff_coeff_ne_zero.mp
lemma supp_subset_range (h : nat_degree p < m) : p.support ⊆ finset.range m :=
λ n hn, mem_range.2 $ (le_nat_degree_of_mem_supp _ hn).trans_lt h
lemma supp_subset_range_nat_degree_succ : p.support ⊆ finset.range (nat_degree p + 1) :=
supp_subset_range (nat.lt_succ_self _)
lemma degree_le_degree (h : coeff q (nat_degree p) ≠ 0) : degree p ≤ degree q :=
begin
by_cases hp : p = 0,
{ rw hp, exact bot_le },
{ rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h }
end
lemma degree_ne_of_nat_degree_ne {n : ℕ} :
p.nat_degree ≠ n → degree p ≠ n :=
mt $ λ h, by rw [nat_degree, h, option.get_or_else_coe]
theorem nat_degree_le_iff_degree_le {n : ℕ} : nat_degree p ≤ n ↔ degree p ≤ n :=
with_bot.get_or_else_bot_le_iff
alias polynomial.nat_degree_le_iff_degree_le ↔ . .
lemma nat_degree_le_nat_degree (hpq : p.degree ≤ q.degree) : p.nat_degree ≤ q.nat_degree :=
with_bot.gi_get_or_else_bot.gc.monotone_l hpq
@[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) :=
show sup (ite (a = 0) ∅ {0}) some = 0, by rw if_neg ha; refl
lemma degree_C_le : degree (C a) ≤ (0 : with_bot ℕ) :=
by by_cases h : a = 0; [rw [h, C_0], rw [degree_C h]]; [exact bot_le, exact le_refl _]
lemma degree_one_le : degree (1 : polynomial R) ≤ (0 : with_bot ℕ) :=
by rw [← C_1]; exact degree_C_le
@[simp] lemma nat_degree_C (a : R) : nat_degree (C a) = 0 :=
begin
by_cases ha : a = 0,
{ have : C a = 0, { rw [ha, C_0] },
rw [nat_degree, degree_eq_bot.2 this],
refl },
{ rw [nat_degree, degree_C ha], refl }
end
@[simp] lemma nat_degree_one : nat_degree (1 : polynomial R) = 0 := nat_degree_C 1
@[simp] lemma nat_degree_nat_cast (n : ℕ) : nat_degree (n : polynomial R) = 0 :=
by simp only [←C_eq_nat_cast, nat_degree_C]
@[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n :=
by rw [degree, support_monomial _ _ ha]; refl
@[simp] lemma degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n :=
by rw [← single_eq_C_mul_X, degree_monomial n ha]
lemma degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=
if h : a = 0 then by rw [h, (monomial n).map_zero]; exact bot_le else le_of_eq (degree_monomial n h)
lemma degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n :=
by { rw C_mul_X_pow_eq_monomial, apply degree_monomial_le }
@[simp] lemma nat_degree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : nat_degree (C a * X ^ n) = n :=
nat_degree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)
@[simp] lemma nat_degree_C_mul_X (a : R) (ha : a ≠ 0) : nat_degree (C a * X) = 1 :=
by simpa only [pow_one] using nat_degree_C_mul_X_pow 1 a ha
@[simp] lemma nat_degree_monomial (i : ℕ) (r : R) (hr : r ≠ 0) :
nat_degree (monomial i r) = i :=
by rw [← C_mul_X_pow_eq_monomial, nat_degree_C_mul_X_pow i r hr]
lemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=
not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))
lemma coeff_eq_zero_of_nat_degree_lt {p : polynomial R} {n : ℕ} (h : p.nat_degree < n) :
p.coeff n = 0 :=
begin
apply coeff_eq_zero_of_degree_lt,
by_cases hp : p = 0,
{ subst hp, exact with_bot.bot_lt_coe n },
{ rwa [degree_eq_nat_degree hp, with_bot.coe_lt_coe] }
end
@[simp] lemma coeff_nat_degree_succ_eq_zero {p : polynomial R} : p.coeff (p.nat_degree + 1) = 0 :=
coeff_eq_zero_of_nat_degree_lt (lt_add_one _)
-- We need the explicit `decidable` argument here because an exotic one shows up in a moment!
lemma ite_le_nat_degree_coeff (p : polynomial R) (n : ℕ) (I : decidable (n < 1 + nat_degree p)) :
@ite (n < 1 + nat_degree p) I _ (coeff p n) 0 = coeff p n :=
begin
split_ifs,
{ refl },
{ exact (coeff_eq_zero_of_nat_degree_lt (not_le.1 (λ w, h (nat.lt_one_add_iff.2 w)))).symm, }
end
lemma as_sum_support (p : polynomial R) :
p = ∑ i in p.support, monomial i (p.coeff i) :=
p.sum_single.symm
lemma as_sum_support_C_mul_X_pow (p : polynomial R) :
p = ∑ i in p.support, C (p.coeff i) * X^i :=
trans p.as_sum_support $ by simp only [C_mul_X_pow_eq_monomial]
/--
We can reexpress a sum over `p.support` as a sum over `range n`,
for any `n` satisfying `p.nat_degree < n`.
-/
lemma sum_over_range' [add_comm_monoid S] (p : polynomial R) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0)
(n : ℕ) (w : p.nat_degree < n) :
p.sum f = ∑ (a : ℕ) in range n, f a (coeff p a) :=
finsupp.sum_of_support_subset _ (supp_subset_range w) _ $ λ n hn, h n
/--
We can reexpress a sum over `p.support` as a sum over `range (p.nat_degree + 1)`.
-/
lemma sum_over_range [add_comm_monoid S] (p : polynomial R) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) :
p.sum f = ∑ (a : ℕ) in range (p.nat_degree + 1), f a (coeff p a) :=
sum_over_range' p h (p.nat_degree + 1) (lt_add_one _)
lemma as_sum_range' (p : polynomial R) (n : ℕ) (w : p.nat_degree < n) :
p = ∑ i in range n, monomial i (coeff p i) :=
p.sum_single.symm.trans $ p.sum_over_range' (λ n, single_zero) _ w
lemma as_sum_range (p : polynomial R) :
p = ∑ i in range (p.nat_degree + 1), monomial i (coeff p i) :=
p.sum_single.symm.trans $ p.sum_over_range $ λ n, single_zero
lemma as_sum_range_C_mul_X_pow (p : polynomial R) :
p = ∑ i in range (p.nat_degree + 1), C (coeff p i) * X ^ i :=
p.as_sum_range.trans $ by simp only [C_mul_X_pow_eq_monomial]
lemma coeff_ne_zero_of_eq_degree (hn : degree p = n) :
coeff p n ≠ 0 :=
λ h, mem_support_iff.mp (mem_of_max hn) h
lemma eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) :
p = C (p.coeff 1) * X + C (p.coeff 0) :=
ext (λ n, nat.cases_on n (by simp)
(λ n, nat.cases_on n (by simp [coeff_C])
(λ m, have degree p < m.succ.succ, from lt_of_le_of_lt h dec_trivial,
by simp [coeff_eq_zero_of_degree_lt this, coeff_C, nat.succ_ne_zero, coeff_X,
nat.succ_inj', @eq_comm ℕ 0])))
lemma eq_X_add_C_of_degree_eq_one (h : degree p = 1) :
p = C (p.leading_coeff) * X + C (p.coeff 0) :=
(eq_X_add_C_of_degree_le_one (show degree p ≤ 1, from h ▸ le_refl _)).trans
(by simp [leading_coeff, nat_degree_eq_of_degree_eq_some h])
lemma eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :
p = C (p.coeff 1) * X + C (p.coeff 0) :=
eq_X_add_C_of_degree_le_one $ degree_le_of_nat_degree_le h
lemma exists_eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :
∃ a b, p = C a * X + C b :=
⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_nat_degree_le_one h⟩
theorem degree_X_pow_le (n : ℕ) : degree (X^n : polynomial R) ≤ n :=
by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1:R)
theorem degree_X_le : degree (X : polynomial R) ≤ 1 :=
degree_monomial_le _ _
lemma nat_degree_X_le : (X : polynomial R).nat_degree ≤ 1 :=
nat_degree_le_of_degree_le degree_X_le
lemma support_C_mul_X_pow (c : R) (n : ℕ) : (C c * X ^ n).support ⊆ singleton n :=
begin
rw [C_mul_X_pow_eq_monomial],
exact support_single_subset
end
lemma mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ (C c * X ^ n).support) : a = n :=
mem_singleton.1 $ support_C_mul_X_pow _ _ h
lemma card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : (C c * X ^ n).support.card ≤ 1 :=
begin
rw ← card_singleton n,
apply card_le_of_subset (support_C_mul_X_pow c n),
end
lemma card_supp_le_succ_nat_degree (p : polynomial R) : p.support.card ≤ p.nat_degree + 1 :=
begin
rw ← finset.card_range (p.nat_degree + 1),
exact finset.card_le_of_subset supp_subset_range_nat_degree_succ,
end
lemma le_degree_of_mem_supp (a : ℕ) :
a ∈ p.support → ↑a ≤ degree p :=
le_degree_of_ne_zero ∘ mem_support_iff_coeff_ne_zero.mp
lemma nonempty_support_iff : p.support.nonempty ↔ p ≠ 0 :=
by rw [ne.def, nonempty_iff_ne_empty, ne.def, ← support_eq_empty]
lemma support_C_mul_X_pow_nonzero {c : R} {n : ℕ} (h : c ≠ 0) :
(C c * X ^ n).support = singleton n :=
begin
rw [C_mul_X_pow_eq_monomial],
exact support_single_ne_zero h
end
end semiring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : polynomial R}
@[simp] lemma degree_one : degree (1 : polynomial R) = (0 : with_bot ℕ) :=
degree_C (show (1 : R) ≠ 0, from zero_ne_one.symm)
@[simp] lemma degree_X : degree (X : polynomial R) = 1 :=
degree_monomial _ one_ne_zero
@[simp] lemma nat_degree_X : (X : polynomial R).nat_degree = 1 :=
nat_degree_eq_of_degree_eq_some degree_X
end nonzero_semiring
section ring
variables [ring R]
lemma coeff_mul_X_sub_C {p : polynomial R} {r : R} {a : ℕ} :
coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r :=
by simp [mul_sub]
lemma C_eq_int_cast (n : ℤ) : C (n : R) = n :=
(C : R →+* _).map_int_cast n
@[simp] lemma degree_neg (p : polynomial R) : degree (-p) = degree p :=
by unfold degree; rw support_neg
@[simp] lemma nat_degree_neg (p : polynomial R) : nat_degree (-p) = nat_degree p :=
by simp [nat_degree]
@[simp] lemma nat_degree_int_cast (n : ℤ) : nat_degree (n : polynomial R) = 0 :=
by simp only [←C_eq_int_cast, nat_degree_C]
end ring
section semiring
variables [semiring R]
/-- The second-highest coefficient, or 0 for constants -/
def next_coeff (p : polynomial R) : R :=
if p.nat_degree = 0 then 0 else p.coeff (p.nat_degree - 1)
@[simp]
lemma next_coeff_C_eq_zero (c : R) :
next_coeff (C c) = 0 := by { rw next_coeff, simp }
lemma next_coeff_of_pos_nat_degree (p : polynomial R) (hp : 0 < p.nat_degree) :
next_coeff p = p.coeff (p.nat_degree - 1) :=
by { rw [next_coeff, if_neg], contrapose! hp, simpa }
end semiring
section semiring
variables [semiring R] {p q : polynomial R} {ι : Type*}
lemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) :
coeff p (nat_degree q) = 0 :=
coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)
lemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 :=
mt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))
lemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) :=
begin
ext (_|n), { simp },
rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt],
exact h.trans_lt (with_bot.some_lt_some.2 n.succ_pos),
end
lemma eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero (h ▸ le_refl _)
lemma degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) :=
⟨eq_C_of_degree_le_zero, λ h, h.symm ▸ degree_C_le⟩
lemma degree_add_le (p q : polynomial R) : degree (p + q) ≤ max (degree p) (degree q) :=
calc degree (p + q) = ((p + q).support).sup some : rfl
... ≤ (p.support ∪ q.support).sup some : by convert sup_mono support_add
... = p.support.sup some ⊔ q.support.sup some : by convert sup_union
... = _ : with_bot.sup_eq_max _ _
@[simp] lemma leading_coeff_zero : leading_coeff (0 : polynomial R) = 0 := rfl
@[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 :=
⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1
(not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)),
λ h, h.symm ▸ leading_coeff_zero⟩
lemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = ⊥ :=
by rw [leading_coeff_eq_zero, degree_eq_bot]
lemma nat_degree_mem_support_of_nonzero (H : p ≠ 0) : p.nat_degree ∈ p.support :=
(p.mem_support_to_fun p.nat_degree).mpr ((not_congr leading_coeff_eq_zero).mpr H)
lemma nat_degree_eq_support_max' (h : p ≠ 0) :
p.nat_degree = p.support.max' (nonempty_support_iff.mpr h) :=
begin
apply le_antisymm,
{ apply finset.le_max',
rw mem_support_iff_coeff_ne_zero,
exact (not_congr leading_coeff_eq_zero).mpr h, },
{ apply max'_le,
refine le_nat_degree_of_mem_supp, },
end
lemma nat_degree_C_mul_X_pow_le (a : R) (n : ℕ) : nat_degree (C a * X ^ n) ≤ n :=
nat_degree_le_iff_degree_le.2 $ degree_C_mul_X_pow_le _ _
lemma degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p :=
le_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $
begin
rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, add_zero],
exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h)
end
lemma degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q :=
by rw [add_comm, degree_add_eq_left_of_degree_lt h]
lemma degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p :=
add_comm (C a) p ▸ degree_add_eq_right_of_degree_lt $ lt_of_le_of_lt degree_C_le hp
lemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) :
degree (p + q) = max p.degree q.degree :=
le_antisymm (degree_add_le _ _) $
match lt_trichotomy (degree p) (degree q) with
| or.inl hlt :=
by rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_refl _
| or.inr (or.inl heq) :=
le_of_not_gt $
assume hlt : max (degree p) (degree q) > degree (p + q),
h $ show leading_coeff p + leading_coeff q = 0,
begin
rw [heq, max_self] at hlt,
rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add],
exact coeff_nat_degree_eq_zero_of_degree_lt hlt
end
| or.inr (or.inr hlt) :=
by rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_refl _
end
lemma degree_erase_le (p : polynomial R) (n : ℕ) : degree (p.erase n) ≤ degree p :=
by convert sup_mono (erase_subset _ _)
lemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p :=
lt_of_le_of_ne (degree_erase_le _ _) $
(degree_eq_nat_degree hp).symm ▸ (by convert λ h, not_mem_erase _ _ (mem_of_max h))
lemma degree_sum_le (s : finset ι) (f : ι → polynomial R) :
degree (∑ i in s, f i) ≤ s.sup (λ b, degree (f b)) :=
finset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $
assume a s has ih,
calc degree (∑ i in insert a s, f i) ≤ max (degree (f a)) (degree (∑ i in s, f i)) :
by rw sum_insert has; exact degree_add_le _ _
... ≤ _ : by rw [sup_insert, with_bot.sup_eq_max]; exact max_le_max (le_refl _) ih
lemma degree_mul_le (p q : polynomial R) : degree (p * q) ≤ degree p + degree q :=
calc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (coeff p i * a) * X ^ (i + j)))) :
by simp only [single_eq_C_mul_X.symm]; exact degree_sum_le _ _
... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) :
finset.sup_mono_fun (assume i hi, degree_sum_le _ _)
... ≤ degree p + degree q :
begin
refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_C_mul_X_pow_le _ _) _)),
rw [with_bot.coe_add],
rw mem_support_iff at ha hb,
exact add_le_add (le_degree_of_ne_zero ha) (le_degree_of_ne_zero hb)
end
lemma degree_pow_le (p : polynomial R) : ∀ n, degree (p ^ n) ≤ n •ℕ (degree p)
| 0 := by rw [pow_zero, zero_nsmul]; exact degree_one_le
| (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) :
by rw pow_succ; exact degree_mul_le _ _
... ≤ _ : by rw succ_nsmul; exact add_le_add (le_refl _) (degree_pow_le _)
@[simp] lemma leading_coeff_monomial (a : R) (n : ℕ) : leading_coeff (monomial n a) = a :=
begin
by_cases ha : a = 0,
{ simp only [ha, (monomial n).map_zero, leading_coeff_zero] },
{ rw [leading_coeff, nat_degree_monomial _ _ ha],
exact @finsupp.single_eq_same _ _ _ n a }
end
lemma leading_coeff_C_mul_X_pow (a : R) (n : ℕ) : leading_coeff (C a * X ^ n) = a :=
by rw [C_mul_X_pow_eq_monomial, leading_coeff_monomial]
@[simp] lemma leading_coeff_C (a : R) : leading_coeff (C a) = a :=
leading_coeff_monomial a 0
@[simp] lemma leading_coeff_X_pow (n : ℕ) : leading_coeff ((X : polynomial R) ^ n) = 1 :=
by simpa only [C_1, one_mul] using leading_coeff_C_mul_X_pow (1 : R) n
@[simp] lemma leading_coeff_X : leading_coeff (X : polynomial R) = 1 :=
by simpa only [pow_one] using @leading_coeff_X_pow R _ 1
@[simp] lemma monic_X_pow (n : ℕ) : monic (X ^ n : polynomial R) := leading_coeff_X_pow n
@[simp] lemma monic_X : monic (X : polynomial R) := leading_coeff_X
@[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial R) = 1 :=
leading_coeff_C 1
@[simp] lemma monic_one : monic (1 : polynomial R) := leading_coeff_C _
lemma monic.ne_zero {R : Type*} [semiring R] [nontrivial R] {p : polynomial R} (hp : p.monic) :
p ≠ 0 :=
by { rintro rfl, simpa [monic] using hp }
lemma monic.ne_zero_of_ne (h : (0:R) ≠ 1) {p : polynomial R} (hp : p.monic) :
p ≠ 0 :=
by { nontriviality R, exact hp.ne_zero }
lemma monic.ne_zero_of_polynomial_ne {r} (hp : monic p) (hne : q ≠ r) : p ≠ 0 :=
by { haveI := nontrivial.of_polynomial_ne hne, exact hp.ne_zero }
lemma leading_coeff_add_of_degree_lt (h : degree p < degree q) :
leading_coeff (p + q) = leading_coeff q :=
have coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h,
by simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h),
this, coeff_add, zero_add]
lemma leading_coeff_add_of_degree_eq (h : degree p = degree q)
(hlc : leading_coeff p + leading_coeff q ≠ 0) :
leading_coeff (p + q) = leading_coeff p + leading_coeff q :=
have nat_degree (p + q) = nat_degree p,
by apply nat_degree_eq_of_degree_eq;
rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self],
by simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add]
@[simp] lemma coeff_mul_degree_add_degree (p q : polynomial R) :
coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q :=
calc coeff (p * q) (nat_degree p + nat_degree q) =
∑ x in nat.antidiagonal (nat_degree p + nat_degree q),
coeff p x.1 * coeff q x.2 : coeff_mul _ _ _
... = coeff p (nat_degree p) * coeff q (nat_degree q) :
begin
refine finset.sum_eq_single (nat_degree p, nat_degree q) _ _,
{ rintro ⟨i,j⟩ h₁ h₂, rw nat.mem_antidiagonal at h₁,
by_cases H : nat_degree p < i,
{ rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 H)), zero_mul] },
{ rw not_lt_iff_eq_or_lt at H, cases H,
{ subst H, rw add_left_cancel_iff at h₁, dsimp at h₁, subst h₁, exfalso, exact h₂ rfl },
{ suffices : nat_degree q < j,
{ rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 this)), mul_zero] },
{ by_contra H', rw not_lt at H',
exact ne_of_lt (nat.lt_of_lt_of_le
(nat.add_lt_add_right H j) (nat.add_le_add_left H' _)) h₁ } } } },
{ intro H, exfalso, apply H, rw nat.mem_antidiagonal }
end
lemma degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
degree (p * q) = degree p + degree q :=
have hp : p ≠ 0 := by refine mt _ h; exact λ hp, by rw [hp, leading_coeff_zero, zero_mul],
have hq : q ≠ 0 := by refine mt _ h; exact λ hq, by rw [hq, leading_coeff_zero, mul_zero],
le_antisymm (degree_mul_le _ _)
begin
rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq],
refine le_degree_of_ne_zero _,
rwa coeff_mul_degree_add_degree
end
lemma degree_mul_monic (hq : monic q) : degree (p * q) = degree p + degree q :=
if hp : p = 0 then by simp [hp]
else degree_mul' $ by rwa [hq.leading_coeff, mul_one, ne.def, leading_coeff_eq_zero]
lemma nat_degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
nat_degree (p * q) = nat_degree p + nat_degree q :=
have hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, zero_mul]),
have hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, mul_zero]),
nat_degree_eq_of_degree_eq_some $
by rw [degree_mul' h, with_bot.coe_add, degree_eq_nat_degree hp, degree_eq_nat_degree hq]
lemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
leading_coeff (p * q) = leading_coeff p * leading_coeff q :=
begin
unfold leading_coeff,
rw [nat_degree_mul' h, coeff_mul_degree_add_degree],
refl
end
lemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 →
leading_coeff (p ^ n) = leading_coeff p ^ n :=
nat.rec_on n (by simp) $
λ n ih h,
have h₁ : leading_coeff p ^ n ≠ 0 :=
λ h₁, h $ by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← ih h₁] at h,
by rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁]
lemma degree_pow' : ∀ {n}, leading_coeff p ^ n ≠ 0 →
degree (p ^ n) = n •ℕ (degree p)
| 0 := λ h, by rw [pow_zero, ← C_1] at *;
rw [degree_C h, zero_nsmul]
| (n+1) := λ h,
have h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $
by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← leading_coeff_pow' h₁] at h,
by rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁]
lemma nat_degree_pow' {n : ℕ} (h : leading_coeff p ^ n ≠ 0) :
nat_degree (p ^ n) = n * nat_degree p :=
if hp0 : p = 0 then
if hn0 : n = 0 then by simp *
else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp
else
have hpn : p ^ n ≠ 0, from λ hpn0, have h1 : _ := h,
by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h;
exact h rfl,
option.some_inj.1 $ show (nat_degree (p ^ n) : with_bot ℕ) = (n * nat_degree p : ℕ),
by rw [← degree_eq_nat_degree hpn, degree_pow' h, degree_eq_nat_degree hp0,
← with_bot.coe_nsmul]; simp
theorem leading_coeff_mul_monic {p q : polynomial R} (hq : monic q) :
leading_coeff (p * q) = leading_coeff p :=
decidable.by_cases
(λ H : leading_coeff p = 0, by rw [H, leading_coeff_eq_zero.1 H, zero_mul, leading_coeff_zero])
(λ H : leading_coeff p ≠ 0,
by rw [leading_coeff_mul', hq.leading_coeff, mul_one];
rwa [hq.leading_coeff, mul_one])
@[simp] theorem leading_coeff_mul_X_pow {p : polynomial R} {n : ℕ} :
leading_coeff (p * X ^ n) = leading_coeff p :=
leading_coeff_mul_monic (monic_X_pow n)
@[simp] theorem leading_coeff_mul_X {p : polynomial R} :
leading_coeff (p * X) = leading_coeff p :=
leading_coeff_mul_monic monic_X
lemma nat_degree_mul_le {p q : polynomial R} : nat_degree (p * q) ≤ nat_degree p + nat_degree q :=
begin
apply nat_degree_le_of_degree_le,
apply le_trans (degree_mul_le p q),
rw with_bot.coe_add,
refine add_le_add _ _; apply degree_le_nat_degree,
end
lemma subsingleton_of_monic_zero (h : monic (0 : polynomial R)) :
(∀ p q : polynomial R, p = q) ∧ (∀ a b : R, a = b) :=
by rw [monic.def, leading_coeff_zero] at h;
exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero],
λ a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩
lemma zero_le_degree_iff {p : polynomial R} : 0 ≤ degree p ↔ p ≠ 0 :=
by rw [ne.def, ← degree_eq_bot];
cases degree p; exact dec_trivial
lemma degree_nonneg_iff_ne_zero : 0 ≤ degree p ↔ p ≠ 0 :=
⟨λ h0p hp0, absurd h0p (by rw [hp0, degree_zero]; exact dec_trivial),
λ hp0, le_of_not_gt (λ h, by simp [gt, degree_eq_bot, *] at *)⟩
lemma nat_degree_eq_zero_iff_degree_le_zero : p.nat_degree = 0 ↔ p.degree ≤ 0 :=
by rw [← nonpos_iff_eq_zero, nat_degree_le_iff_degree_le, with_bot.coe_zero]
theorem degree_le_iff_coeff_zero (f : polynomial R) (n : with_bot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 :=
⟨λ (H : finset.sup (f.support) some ≤ n) m (Hm : n < (m : with_bot ℕ)), decidable.of_not_not $ λ H4,
have H1 : m ∉ f.support,
from λ H2, not_lt_of_ge ((finset.sup_le_iff.1 H) m H2 : ((m : with_bot ℕ) ≤ n)) Hm,
H1 $ (finsupp.mem_support_to_fun f m).2 H4,
λ H, finset.sup_le $ λ b Hb, decidable.of_not_not $ λ Hn,
(finsupp.mem_support_to_fun f b).1 Hb $ H b $ lt_of_not_ge Hn⟩
theorem degree_lt_iff_coeff_zero (f : polynomial R) (n : ℕ) :
degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 :=
begin
refine ⟨λ hf m hm, coeff_eq_zero_of_degree_lt (lt_of_lt_of_le hf (with_bot.coe_le_coe.2 hm)), _⟩,
simp only [degree, finset.sup_lt_iff (with_bot.bot_lt_coe n), mem_support_iff,
with_bot.some_eq_coe, with_bot.coe_lt_coe, ← @not_le ℕ],
exact λ h m, mt (h m),
end
lemma degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree :=
by haveI := nontrivial.of_polynomial_ne hp; exact
have leading_coeff p * leading_coeff X ≠ 0, by simpa,
by erw [degree_mul' this, degree_eq_nat_degree hp,
degree_X, ← with_bot.coe_one, ← with_bot.coe_add, with_bot.coe_lt_coe];
exact nat.lt_succ_self _
lemma nat_degree_pos_iff_degree_pos {p : polynomial R} :
0 < nat_degree p ↔ 0 < degree p :=
lt_iff_lt_of_le_iff_le nat_degree_le_iff_degree_le
lemma eq_C_of_nat_degree_le_zero {p : polynomial R} (h : nat_degree p ≤ 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero $ degree_le_of_nat_degree_le h
lemma eq_C_of_nat_degree_eq_zero {p : polynomial R} (h : nat_degree p = 0) : p = C (coeff p 0) :=
eq_C_of_nat_degree_le_zero h.le
end semiring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : polynomial R}
@[simp] lemma degree_X_pow (n : ℕ) : degree ((X : polynomial R) ^ n) = n :=
by rw [X_pow_eq_monomial, degree_monomial _ (@one_ne_zero R _ _)]
@[simp] lemma nat_degree_X_pow (n : ℕ) : nat_degree ((X : polynomial R) ^ n) = n :=
nat_degree_eq_of_degree_eq_some (degree_X_pow n)
theorem not_is_unit_X : ¬ is_unit (X : polynomial R) :=
λ ⟨⟨_, g, hfg, hgf⟩, rfl⟩, @zero_ne_one R _ _ $ by { rw [← coeff_one_zero, ← hgf], simp }
@[simp] lemma degree_mul_X : degree (p * X) = degree p + 1 := by simp [degree_mul_monic monic_X]
@[simp] lemma degree_mul_X_pow : degree (p * X ^ n) = degree p + n :=
by simp [degree_mul_monic (monic_X_pow n)]
end nonzero_semiring
section ring
variables [ring R] {p q : polynomial R}
lemma degree_sub_le (p q : polynomial R) : degree (p - q) ≤ max (degree p) (degree q) :=
by simpa only [sub_eq_add_neg, degree_neg q] using degree_add_le p (-q)
lemma degree_sub_lt (hd : degree p = degree q)
(hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) :
degree (p - q) < degree p :=
have hp : single (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p :=
finsupp.single_add_erase _ _,
have hq : single (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q :=
finsupp.single_add_erase _ _,
have hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd,
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0),
calc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) :
by conv {to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]}
... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q))
: degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _
... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
lemma nat_degree_X_sub_C_le {r : R} : (X - C r).nat_degree ≤ 1 :=
nat_degree_le_iff_degree_le.2 $ le_trans (degree_sub_le _ _) $ max_le degree_X_le $
le_trans degree_C_le $ with_bot.coe_le_coe.2 zero_le_one
lemma degree_sum_fin_lt {n : ℕ} (f : fin n → R) :
degree (∑ i : fin n, C (f i) * X ^ (i : ℕ)) < n :=
begin
haveI : is_commutative (with_bot ℕ) max := ⟨max_comm⟩,
haveI : is_associative (with_bot ℕ) max := ⟨max_assoc⟩,
calc (∑ i, C (f i) * X ^ (i : ℕ)).degree
≤ finset.univ.fold (⊔) ⊥ (λ i, (C (f i) * X ^ (i : ℕ)).degree) : degree_sum_le _ _
... = finset.univ.fold max ⊥ (λ i, (C (f i) * X ^ (i : ℕ)).degree) :
(@finset.fold_hom _ _ _ (⊔) _ _ _ ⊥ finset.univ _ _ _ id (with_bot.sup_eq_max)).symm
... < n : (finset.fold_max_lt (n : with_bot ℕ)).mpr ⟨with_bot.bot_lt_some _, _⟩,
rintros ⟨i, hi⟩ -,
calc (C (f ⟨i, hi⟩) * X ^ i).degree
≤ (C _).degree + (X ^ i).degree : degree_mul_le _ _
... ≤ 0 + i : add_le_add degree_C_le (degree_X_pow_le i)
... = i : zero_add _
... < n : with_bot.some_lt_some.mpr hi,
end
lemma degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p :=
by { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h] }
lemma degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q :=
by { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg] }
end ring
section nonzero_ring
variables [nontrivial R] [ring R]
@[simp] lemma degree_X_sub_C (a : R) : degree (X - C a) = 1 :=
have degree (C a) < degree (X : polynomial R),
from calc degree (C a) ≤ 0 : degree_C_le
... < 1 : with_bot.some_lt_some.mpr zero_lt_one
... = degree X : degree_X.symm,
by rw [degree_sub_eq_left_of_degree_lt this, degree_X]
@[simp] lemma nat_degree_X_sub_C (x : R) : (X - C x).nat_degree = 1 :=
nat_degree_eq_of_degree_eq_some $ degree_X_sub_C x
@[simp]
lemma next_coeff_X_sub_C (c : R) : next_coeff (X - C c) = - c :=
by simp [next_coeff_of_pos_nat_degree]
lemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
degree ((X : polynomial R) ^ n - C a) = n :=
have degree (C a) < degree ((X : polynomial R) ^ n),
from calc degree (C a) ≤ 0 : degree_C_le
... < degree ((X : polynomial R) ^ n) : by rwa [degree_X_pow];
exact with_bot.coe_lt_coe.2 hn,
by rw [degree_sub_eq_left_of_degree_lt this, degree_X_pow]
lemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) :
(X : polynomial R) ^ n - C a ≠ 0 :=
mt degree_eq_bot.2 (show degree ((X : polynomial R) ^ n - C a) ≠ ⊥,
by rw degree_X_pow_sub_C hn a; exact dec_trivial)
theorem X_sub_C_ne_zero (r : R) : X - C r ≠ 0 :=
pow_one (X : polynomial R) ▸ X_pow_sub_C_ne_zero zero_lt_one r
lemma nat_degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) {r : R} :
(X ^ n - C r).nat_degree = n :=
by { apply nat_degree_eq_of_degree_eq_some, simp [degree_X_pow_sub_C hn], }
end nonzero_ring
section no_zero_divisors
variables [comm_semiring R] [no_zero_divisors R] {p q : polynomial R}
@[simp] lemma degree_mul : degree (p * q) = degree p + degree q :=
if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add]
else if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot]
else degree_mul' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)
(mt leading_coeff_eq_zero.1 hq0)
@[simp] lemma degree_pow [nontrivial R] (p : polynomial R) (n : ℕ) :
degree (p ^ n) = n •ℕ (degree p) :=
by induction n; [simp only [pow_zero, degree_one, zero_nsmul],
simp only [*, pow_succ, succ_nsmul, degree_mul]]
@[simp] lemma leading_coeff_mul (p q : polynomial R) : leading_coeff (p * q) =
leading_coeff p * leading_coeff q :=
begin
by_cases hp : p = 0,
{ simp only [hp, zero_mul, leading_coeff_zero] },
{ by_cases hq : q = 0,
{ simp only [hq, mul_zero, leading_coeff_zero] },
{ rw [leading_coeff_mul'],
exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } }
end
@[simp] lemma leading_coeff_X_add_C [nontrivial R] (a b : R) (ha : a ≠ 0):
leading_coeff (C a * X + C b) = a :=
begin
rw [add_comm, leading_coeff_add_of_degree_lt],
{ simp },
{ simpa [degree_C ha] using lt_of_le_of_lt degree_C_le (with_bot.coe_lt_coe.2 zero_lt_one)}
end
/-- `polynomial.leading_coeff` bundled as a `monoid_hom` when `R` has `no_zero_divisors`, and thus
`leading_coeff` is multiplicative -/
def leading_coeff_hom : polynomial R →* R :=
{ to_fun := leading_coeff,
map_one' := by simp,
map_mul' := leading_coeff_mul }
@[simp] lemma leading_coeff_hom_apply (p : polynomial R) :
leading_coeff_hom p = leading_coeff p := rfl
@[simp] lemma leading_coeff_pow (p : polynomial R) (n : ℕ) :
leading_coeff (p ^ n) = leading_coeff p ^ n :=
leading_coeff_hom.map_pow p n
end no_zero_divisors
end polynomial
|
5e0ffc95b517a0307396d66c3f587951619bbac2 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/ring_theory/polynomial/eisenstein.lean | 096d48fa5725161227460809c15e25079f7967b1 | [
"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 | 28,673 | lean | /-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import ring_theory.eisenstein_criterion
import ring_theory.integrally_closed
import ring_theory.norm
import ring_theory.polynomial.cyclotomic.basic
/-!
# Eisenstein polynomials
Given an ideal `𝓟` of a commutative semiring `R`, we say that a polynomial `f : R[X]` is
*Eisenstein at `𝓟`* if `f.leading_coeff ∉ 𝓟`, `∀ n, n < f.nat_degree → f.coeff n ∈ 𝓟` and
`f.coeff 0 ∉ 𝓟 ^ 2`. In this file we gather miscellaneous results about Eisenstein polynomials.
## Main definitions
* `polynomial.is_eisenstein_at f 𝓟`: the property of being Eisenstein at `𝓟`.
## Main results
* `polynomial.is_eisenstein_at.irreducible`: if a primitive `f` satisfies `f.is_eisenstein_at 𝓟`,
where `𝓟.is_prime`, then `f` is irreducible.
* `mem_adjoin_of_smul_prime_pow_smul_of_minpoly_is_eiseinstein_at`: let `K` be the field of fraction
of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an
integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given
`z : L` integral over `R`, if `p ^ n • z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`.
Together with `algebra.discr_mul_is_integral_mem_adjoin` this result often allows to compute the
ring of integers of `L`.
## Implementation details
We also define a notion `is_weakly_eisenstein_at` requiring only that
`∀ n < f.nat_degree → f.coeff n ∈ 𝓟`. This makes certain results slightly more general and it is
useful since it is sometimes better behaved (for example it is stable under `polynomial.map`).
-/
universes u v w z
variables {R : Type u}
open ideal algebra finset
open_locale big_operators polynomial
namespace polynomial
/-- Given an ideal `𝓟` of a commutative semiring `R`, we say that a polynomial `f : R[X]`
is *weakly Eisenstein at `𝓟`* if `∀ n, n < f.nat_degree → f.coeff n ∈ 𝓟`. -/
@[mk_iff] structure is_weakly_eisenstein_at [comm_semiring R] (f : R[X]) (𝓟 : ideal R) :
Prop := (mem : ∀ {n}, n < f.nat_degree → f.coeff n ∈ 𝓟)
/-- Given an ideal `𝓟` of a commutative semiring `R`, we say that a polynomial `f : R[X]`
is *Eisenstein at `𝓟`* if `f.leading_coeff ∉ 𝓟`, `∀ n, n < f.nat_degree → f.coeff n ∈ 𝓟` and
`f.coeff 0 ∉ 𝓟 ^ 2`. -/
@[mk_iff] structure is_eisenstein_at [comm_semiring R] (f : R[X]) (𝓟 : ideal R) : Prop :=
(leading : f.leading_coeff ∉ 𝓟)
(mem : ∀ {n}, n < f.nat_degree → f.coeff n ∈ 𝓟)
(not_mem : f.coeff 0 ∉ 𝓟 ^ 2)
namespace is_weakly_eisenstein_at
section comm_semiring
variables [comm_semiring R] {𝓟 : ideal R} {f : R[X]} (hf : f.is_weakly_eisenstein_at 𝓟)
include hf
lemma map {A : Type v} [comm_ring A] (φ : R →+* A) : (f.map φ).is_weakly_eisenstein_at (𝓟.map φ) :=
begin
refine (is_weakly_eisenstein_at_iff _ _).2 (λ n hn, _),
rw [coeff_map],
exact mem_map_of_mem _ (hf.mem (lt_of_lt_of_le hn (nat_degree_map_le _ _)))
end
end comm_semiring
section comm_ring
variables [comm_ring R] {𝓟 : ideal R} {f : R[X]} (hf : f.is_weakly_eisenstein_at 𝓟)
variables {S : Type v} [comm_ring S] [algebra R S]
section principal
variable {p : R}
local notation `P` := submodule.span R {p}
lemma exists_mem_adjoin_mul_eq_pow_nat_degree {x : S} (hx : aeval x f = 0)
(hmo : f.monic) (hf : f.is_weakly_eisenstein_at P) : ∃ y ∈ adjoin R ({x} : set S),
(algebra_map R S) p * y = x ^ (f.map (algebra_map R S)).nat_degree :=
begin
rw [aeval_def, polynomial.eval₂_eq_eval_map, eval_eq_sum_range, range_add_one,
sum_insert not_mem_range_self, sum_range, (hmo.map
(algebra_map R S)).coeff_nat_degree, one_mul] at hx,
replace hx := eq_neg_of_add_eq_zero_left hx,
have : ∀ n < f.nat_degree, p ∣ f.coeff n,
{ intros n hn,
refine mem_span_singleton.1 (by simpa using hf.mem hn) },
choose! φ hφ using this,
conv_rhs at hx { congr, congr, skip, funext,
rw [fin.coe_eq_val, coeff_map, hφ i.1 (lt_of_lt_of_le i.2 (nat_degree_map_le _ _)),
ring_hom.map_mul, mul_assoc] },
rw [hx, ← mul_sum, neg_eq_neg_one_mul, ← mul_assoc (-1 : S), mul_comm (-1 : S), mul_assoc],
refine ⟨-1 * ∑ (i : fin (f.map (algebra_map R S)).nat_degree),
(algebra_map R S) (φ i.1) * x ^ i.1, _, rfl⟩,
exact subalgebra.mul_mem _ (subalgebra.neg_mem _ (subalgebra.one_mem _))
(subalgebra.sum_mem _ (λ i hi, subalgebra.mul_mem _ (subalgebra.algebra_map_mem _ _)
(subalgebra.pow_mem _ (subset_adjoin (set.mem_singleton x)) _)))
end
lemma exists_mem_adjoin_mul_eq_pow_nat_degree_le {x : S} (hx : aeval x f = 0)
(hmo : f.monic) (hf : f.is_weakly_eisenstein_at P) :
∀ i, (f.map (algebra_map R S)).nat_degree ≤ i →
∃ y ∈ adjoin R ({x} : set S), (algebra_map R S) p * y = x ^ i :=
begin
intros i hi,
obtain ⟨k, hk⟩ := exists_add_of_le hi,
rw [hk, pow_add],
obtain ⟨y, hy, H⟩ := exists_mem_adjoin_mul_eq_pow_nat_degree hx hmo hf,
refine ⟨y * x ^ k, _, _⟩,
{ exact subalgebra.mul_mem _ hy (subalgebra.pow_mem _ (subset_adjoin (set.mem_singleton x)) _) },
{ rw [← mul_assoc _ y, H] }
end
end principal
include hf
lemma pow_nat_degree_le_of_root_of_monic_mem {x : R} (hroot : is_root f x) (hmo : f.monic) :
∀ i, f.nat_degree ≤ i → x ^ i ∈ 𝓟 :=
begin
intros i hi,
obtain ⟨k, hk⟩ := exists_add_of_le hi,
rw [hk, pow_add],
suffices : x ^ f.nat_degree ∈ 𝓟,
{ exact mul_mem_right (x ^ k) 𝓟 this },
rw [is_root.def, eval_eq_sum_range, finset.range_add_one, finset.sum_insert
finset.not_mem_range_self, finset.sum_range, hmo.coeff_nat_degree, one_mul] at hroot,
rw [eq_neg_of_add_eq_zero_left hroot, neg_mem_iff],
refine submodule.sum_mem _ (λ i hi, mul_mem_right _ _ (hf.mem (fin.is_lt i)))
end
lemma pow_nat_degree_le_of_aeval_zero_of_monic_mem_map {x : S} (hx : aeval x f = 0)
(hmo : f.monic) :
∀ i, (f.map (algebra_map R S)).nat_degree ≤ i → x ^ i ∈ 𝓟.map (algebra_map R S) :=
begin
suffices : x ^ (f.map (algebra_map R S)).nat_degree ∈ 𝓟.map (algebra_map R S),
{ intros i hi,
obtain ⟨k, hk⟩ := exists_add_of_le hi,
rw [hk, pow_add],
refine mul_mem_right _ _ this },
rw [aeval_def, eval₂_eq_eval_map, ← is_root.def] at hx,
refine pow_nat_degree_le_of_root_of_monic_mem (hf.map _) hx (hmo.map _) _ rfl.le
end
end comm_ring
end is_weakly_eisenstein_at
section scale_roots
variables {A : Type*} [comm_ring R] [comm_ring A]
lemma scale_roots.is_weakly_eisenstein_at (p : R[X]) {x : R}
{P : ideal R} (hP : x ∈ P) : (scale_roots p x).is_weakly_eisenstein_at P :=
begin
refine ⟨λ i hi, _⟩,
rw coeff_scale_roots,
rw [nat_degree_scale_roots, ← tsub_pos_iff_lt] at hi,
exact ideal.mul_mem_left _ _ (ideal.pow_mem_of_mem P hP _ hi)
end
lemma dvd_pow_nat_degree_of_eval₂_eq_zero {f : R →+* A}
(hf : function.injective f) {p : R[X]} (hp : p.monic) (x y : R) (z : A)
(h : p.eval₂ f z = 0) (hz : f x * z = f y) : x ∣ y ^ p.nat_degree :=
begin
rw [← nat_degree_scale_roots p x, ← ideal.mem_span_singleton],
refine (scale_roots.is_weakly_eisenstein_at _ (ideal.mem_span_singleton.mpr $ dvd_refl x))
.pow_nat_degree_le_of_root_of_monic_mem _ ((monic_scale_roots_iff x).mpr hp) _ le_rfl,
rw injective_iff_map_eq_zero' at hf,
have := scale_roots_eval₂_eq_zero f h,
rwa [hz, polynomial.eval₂_at_apply, hf] at this
end
lemma dvd_pow_nat_degree_of_aeval_eq_zero [algebra R A] [nontrivial A]
[no_zero_smul_divisors R A] {p : R[X]} (hp : p.monic) (x y : R) (z : A)
(h : polynomial.aeval z p = 0) (hz : z * algebra_map R A x = algebra_map R A y) :
x ∣ y ^ p.nat_degree :=
dvd_pow_nat_degree_of_eval₂_eq_zero (no_zero_smul_divisors.algebra_map_injective R A)
hp x y z h ((mul_comm _ _).trans hz)
end scale_roots
namespace is_eisenstein_at
section comm_semiring
variables [comm_semiring R] {𝓟 : ideal R} {f : R[X]} (hf : f.is_eisenstein_at 𝓟)
lemma _root_.polynomial.monic.leading_coeff_not_mem (hf : f.monic) (h : 𝓟 ≠ ⊤) :
¬f.leading_coeff ∈ 𝓟 :=
hf.leading_coeff.symm ▸ (ideal.ne_top_iff_one _).1 h
lemma _root_.polynomial.monic.is_eisenstein_at_of_mem_of_not_mem (hf : f.monic) (h : 𝓟 ≠ ⊤)
(hmem : ∀ {n}, n < f.nat_degree → f.coeff n ∈ 𝓟) (hnot_mem : f.coeff 0 ∉ 𝓟 ^ 2) :
f.is_eisenstein_at 𝓟 :=
{ leading := hf.leading_coeff_not_mem h,
mem := λ n hn, hmem hn,
not_mem := hnot_mem }
include hf
lemma is_weakly_eisenstein_at : is_weakly_eisenstein_at f 𝓟 := ⟨λ _, hf.mem⟩
lemma coeff_mem {n : ℕ} (hn : n ≠ f.nat_degree) : f.coeff n ∈ 𝓟 :=
begin
cases ne_iff_lt_or_gt.1 hn,
{ exact hf.mem h },
{ rw [coeff_eq_zero_of_nat_degree_lt h],
exact ideal.zero_mem _}
end
end comm_semiring
section is_domain
variables [comm_ring R] [is_domain R] {𝓟 : ideal R} {f : R[X]} (hf : f.is_eisenstein_at 𝓟)
/-- If a primitive `f` satisfies `f.is_eisenstein_at 𝓟`, where `𝓟.is_prime`, then `f` is
irreducible. -/
lemma irreducible (hprime : 𝓟.is_prime) (hu : f.is_primitive)
(hfd0 : 0 < f.nat_degree) : irreducible f :=
irreducible_of_eisenstein_criterion hprime hf.leading (λ n hn, hf.mem (coe_lt_degree.1 hn))
(nat_degree_pos_iff_degree_pos.1 hfd0) hf.not_mem hu
end is_domain
end is_eisenstein_at
end polynomial
section cyclotomic
variables (p : ℕ)
local notation `𝓟` := submodule.span ℤ {p}
open polynomial
lemma cyclotomic_comp_X_add_one_is_eisenstein_at [hp : fact p.prime] :
((cyclotomic p ℤ).comp (X + 1)).is_eisenstein_at 𝓟 :=
begin
refine monic.is_eisenstein_at_of_mem_of_not_mem _
(ideal.is_prime.ne_top $(ideal.span_singleton_prime (by exact_mod_cast hp.out.ne_zero)).2 $
nat.prime_iff_prime_int.1 hp.out) (λ i hi, _) _,
{ rw [show (X + 1 : ℤ[X]) = X + C 1, by simp],
refine ((cyclotomic.monic p ℤ).comp (monic_X_add_C 1) (λ h, _)),
rw [nat_degree_X_add_C] at h,
exact zero_ne_one h.symm },
{ rw [cyclotomic_eq_geom_sum hp.out, geom_sum_X_comp_X_add_one_eq_sum, ← lcoeff_apply,
linear_map.map_sum],
conv { congr, congr, skip, funext,
rw [lcoeff_apply, ← C_eq_nat_cast, ← monomial_eq_C_mul_X, coeff_monomial] },
rw [nat_degree_comp, show (X + 1 : ℤ[X]) = X + C 1, by simp, nat_degree_X_add_C, mul_one,
nat_degree_cyclotomic, nat.totient_prime hp.out] at hi,
simp only [lt_of_lt_of_le hi (nat.sub_le _ _), sum_ite_eq', mem_range,
if_true, ideal.submodule_span_eq, ideal.mem_span_singleton],
exact int.coe_nat_dvd.2
(nat.prime.dvd_choose_self (nat.succ_pos i) (lt_tsub_iff_right.1 hi) hp.out) },
{ rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_eq_geom_sum hp.out, eval_add, eval_X,
eval_one, zero_add, eval_geom_sum, one_geom_sum,
ideal.submodule_span_eq, ideal.span_singleton_pow, ideal.mem_span_singleton],
intro h,
obtain ⟨k, hk⟩ := int.coe_nat_dvd.1 h,
rw [← mul_assoc, mul_one, mul_assoc] at hk,
nth_rewrite 0 [← nat.mul_one p] at hk,
rw [nat.mul_right_inj hp.out.pos] at hk,
exact nat.prime.not_dvd_one hp.out (dvd.intro k (hk.symm)) }
end
lemma cyclotomic_prime_pow_comp_X_add_one_is_eisenstein_at [hp : fact p.prime] (n : ℕ) :
((cyclotomic (p ^ (n + 1)) ℤ).comp (X + 1)).is_eisenstein_at 𝓟 :=
begin
refine monic.is_eisenstein_at_of_mem_of_not_mem _
(ideal.is_prime.ne_top $(ideal.span_singleton_prime (by exact_mod_cast hp.out.ne_zero)).2 $
nat.prime_iff_prime_int.1 hp.out) _ _,
{ rw [show (X + 1 : ℤ[X]) = X + C 1, by simp],
refine ((cyclotomic.monic _ ℤ).comp (monic_X_add_C 1) (λ h, _)),
rw [nat_degree_X_add_C] at h,
exact zero_ne_one h.symm },
{ induction n with n hn,
{ intros i hi,
rw [zero_add, pow_one] at hi ⊢,
exact (cyclotomic_comp_X_add_one_is_eisenstein_at p).mem hi },
{ intros i hi,
rw [ideal.submodule_span_eq, ideal.mem_span_singleton, ← zmod.int_coe_zmod_eq_zero_iff_dvd,
← int.coe_cast_ring_hom, ← coeff_map, map_comp, map_cyclotomic, polynomial.map_add, map_X,
polynomial.map_one, pow_add, pow_one, cyclotomic_mul_prime_dvd_eq_pow, pow_comp,
← zmod.expand_card, coeff_expand hp.out.pos],
{ simp only [ite_eq_right_iff],
rintro ⟨k, hk⟩,
rw [nat_degree_comp, show (X + 1 : ℤ[X]) = X + C 1, by simp, nat_degree_X_add_C,
mul_one, nat_degree_cyclotomic, nat.totient_prime_pow hp.out (nat.succ_pos _),
nat.succ_sub_one] at hn hi,
rw [hk, pow_succ, mul_assoc] at hi,
rw [hk, mul_comm, nat.mul_div_cancel _ hp.out.pos],
replace hn := hn (lt_of_mul_lt_mul_left' hi),
rw [ideal.submodule_span_eq, ideal.mem_span_singleton,
← zmod.int_coe_zmod_eq_zero_iff_dvd, ← int.coe_cast_ring_hom, ← coeff_map] at hn,
simpa [map_comp] using hn },
{ exact ⟨p ^ n, by rw [pow_succ]⟩ } } },
{ rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime_pow_eq_geom_sum hp.out, eval_add,
eval_X, eval_one, zero_add, eval_finset_sum],
simp only [eval_pow, eval_X, one_pow, sum_const, card_range, nat.smul_one_eq_coe,
submodule_span_eq, ideal.submodule_span_eq,
ideal.span_singleton_pow, ideal.mem_span_singleton],
intro h,
obtain ⟨k, hk⟩ := int.coe_nat_dvd.1 h,
rw [← mul_assoc, mul_one, mul_assoc] at hk,
nth_rewrite 0 [← nat.mul_one p] at hk,
rw [nat.mul_right_inj hp.out.pos] at hk,
exact nat.prime.not_dvd_one hp.out (dvd.intro k (hk.symm)) }
end
end cyclotomic
section is_integral
variables {K : Type v} {L : Type z} {p : R} [comm_ring R] [field K] [field L]
variables [algebra K L] [algebra R L] [algebra R K] [is_scalar_tower R K L] [is_separable K L]
variables [is_domain R] [normalized_gcd_monoid R] [is_fraction_ring R K] [is_integrally_closed R]
local notation `𝓟` := submodule.span R {p}
open is_integrally_closed power_basis nat polynomial is_scalar_tower
/-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable
extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of
`B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `Q : polynomial R` is such that
`aeval B.gen Q = p • z`, then `p ∣ Q.coeff 0`. -/
lemma dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_is_eiseinstein_at {B : power_basis K L}
(hp : prime p) (hBint : is_integral R B.gen) {z : L} {Q : polynomial R}
(hQ : aeval B.gen Q = p • z) (hzint : is_integral R z)
(hei : (minpoly R B.gen).is_eisenstein_at 𝓟) : p ∣ Q.coeff 0 :=
begin
-- First define some abbreviations.
letI := B.finite_dimensional,
let P := minpoly R B.gen,
obtain ⟨n , hn⟩ := nat.exists_eq_succ_of_ne_zero B.dim_pos.ne',
have finrank_K_L : finite_dimensional.finrank K L = B.dim := B.finrank,
have deg_K_P : (minpoly K B.gen).nat_degree = B.dim := B.nat_degree_minpoly,
have deg_R_P : P.nat_degree = B.dim,
{ rw [← deg_K_P, minpoly.gcd_domain_eq_field_fractions' K hBint,
(minpoly.monic hBint).nat_degree_map (algebra_map R K)] },
choose! f hf using hei.is_weakly_eisenstein_at.exists_mem_adjoin_mul_eq_pow_nat_degree_le
(minpoly.aeval R B.gen) (minpoly.monic hBint),
simp only [(minpoly.monic hBint).nat_degree_map, deg_R_P] at hf,
-- The Eisenstein condition shows that `p` divides `Q.coeff 0`
-- if `p^n.succ` divides the following multiple of `Q.coeff 0^n.succ`:
suffices : p ^ n.succ ∣
(Q.coeff 0 ^ n.succ * ((-1) ^ (n.succ * n) * (minpoly R B.gen).coeff 0 ^ n)),
{ have hndiv : ¬ p ^ 2 ∣ ((minpoly R B.gen)).coeff 0 := λ h,
hei.not_mem ((span_singleton_pow p 2).symm ▸ (ideal.mem_span_singleton.2 h)),
refine prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd hp ((_ : _ ^ n.succ ∣ _)) hndiv,
convert (is_unit.dvd_mul_right ⟨(-1) ^ (n.succ * n), rfl⟩).mpr this using 1,
push_cast,
ring_nf, simp [pow_right_comm _ _ 2] },
-- We claim the quotient of `Q^n * _` by `p^n` is the following `r`:
have aux : ∀ i ∈ (range (Q.nat_degree + 1)).erase 0, B.dim ≤ i + n,
{ intros i hi,
simp only [mem_range, mem_erase] at hi,
rw [hn],
exact le_add_pred_of_pos _ hi.1 },
have hintsum : is_integral R (z * B.gen ^ n -
∑ (x : ℕ) in (range (Q.nat_degree + 1)).erase 0, Q.coeff x • f (x + n)),
{ refine is_integral_sub (is_integral_mul hzint (is_integral.pow hBint _))
(is_integral.sum _ (λ i hi, (is_integral_smul _ _))),
exact adjoin_le_integral_closure hBint (hf _ (aux i hi)).1 },
obtain ⟨r, hr⟩ := is_integral_iff.1 (is_integral_norm K hintsum),
use r,
-- Do the computation in `K` so we can work in terms of `z` instead of `r`.
apply is_fraction_ring.injective R K,
simp only [_root_.map_mul, _root_.map_pow, _root_.map_neg, _root_.map_one],
-- Both sides are actually norms:
calc _ = norm K (Q.coeff 0 • B.gen ^ n) : _
... = norm K (p • (z * B.gen ^ n) - ∑ (x : ℕ) in (range (Q.nat_degree + 1)).erase 0,
p • Q.coeff x • f (x + n))
: congr_arg (norm K) (eq_sub_of_add_eq _)
... = _ : _,
{ simp only [algebra.smul_def, algebra_map_apply R K L, algebra.norm_algebra_map, _root_.map_mul,
_root_.map_pow, finrank_K_L, power_basis.norm_gen_eq_coeff_zero_minpoly,
minpoly.gcd_domain_eq_field_fractions' K hBint, coeff_map, ← hn],
ring_exp },
swap, { simp_rw [← smul_sum, ← smul_sub, algebra.smul_def p, algebra_map_apply R K L,
_root_.map_mul, algebra.norm_algebra_map, finrank_K_L, hr, ← hn] },
calc _ = (Q.coeff 0 • 1 + ∑ (x : ℕ) in (range (Q.nat_degree + 1)).erase 0,
Q.coeff x • B.gen ^ x) * B.gen ^ n : _
... = (Q.coeff 0 • B.gen ^ 0 + ∑ (x : ℕ) in (range (Q.nat_degree + 1)).erase 0,
Q.coeff x • B.gen ^ x) * B.gen ^ n : by rw pow_zero
... = (aeval B.gen Q) * B.gen ^ n : _
... = _ : by rw [hQ, algebra.smul_mul_assoc],
{ have : ∀ i ∈ (range (Q.nat_degree + 1)).erase 0,
Q.coeff i • (B.gen ^ i * B.gen ^ n) =
p • Q.coeff i • f (i + n),
{ intros i hi,
rw [←pow_add, ←(hf _ (aux i hi)).2, ←algebra.smul_def, smul_smul, mul_comm _ p, smul_smul] },
simp only [add_mul, smul_mul_assoc, one_mul, sum_mul, sum_congr rfl this] },
{ rw [aeval_eq_sum_range,
finset.add_sum_erase (range (Q.nat_degree + 1)) (λ i, Q.coeff i • B.gen ^ i)],
simp },
end
lemma mem_adjoin_of_dvd_coeff_of_dvd_aeval {A B : Type*} [comm_semiring A] [comm_ring B]
[algebra A B] [no_zero_smul_divisors A B] {Q : polynomial A} {p : A} {x z : B} (hp : p ≠ 0)
(hQ : ∀ i ∈ range (Q.nat_degree + 1), p ∣ Q.coeff i) (hz : aeval x Q = p • z) :
z ∈ adjoin A ({x} : set B) :=
begin
choose! f hf using hQ,
rw [aeval_eq_sum_range, sum_range] at hz,
conv_lhs at hz { congr, skip, funext,
rw [hf i (mem_range.2 (fin.is_lt i)), ← smul_smul] },
rw [← smul_sum] at hz,
rw [← smul_right_injective _ hp hz],
exact subalgebra.sum_mem _ (λ _ _, subalgebra.smul_mem _
(subalgebra.pow_mem _ (subset_adjoin (set.mem_singleton _)) _) _)
end
/-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable
extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of
`B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p • z ∈ adjoin R {B.gen}`, then
`z ∈ adjoin R {B.gen}`. -/
lemma mem_adjoin_of_smul_prime_smul_of_minpoly_is_eiseinstein_at {B : power_basis K L}
(hp : prime p) (hBint : is_integral R B.gen) {z : L} (hzint : is_integral R z)
(hz : p • z ∈ adjoin R ({B.gen} : set L)) (hei : (minpoly R B.gen).is_eisenstein_at 𝓟) :
z ∈ adjoin R ({B.gen} : set L) :=
begin
-- First define some abbreviations.
have hndiv : ¬ p ^ 2 ∣ ((minpoly R B.gen)).coeff 0 := λ h,
hei.not_mem ((span_singleton_pow p 2).symm ▸ (ideal.mem_span_singleton.2 h)),
letI := finite_dimensional B,
set P := minpoly R B.gen with hP,
obtain ⟨n , hn⟩ := nat.exists_eq_succ_of_ne_zero B.dim_pos.ne',
haveI : no_zero_smul_divisors R L := no_zero_smul_divisors.trans R K L,
let P₁ := P.map (algebra_map R L),
-- There is a polynomial `Q` such that `p • z = aeval B.gen Q`. We can assume that
-- `Q.degree < P.degree` and `Q ≠ 0`.
rw [adjoin_singleton_eq_range_aeval] at hz,
obtain ⟨Q₁, hQ⟩ := hz,
set Q := Q₁ %ₘ P with hQ₁,
replace hQ : aeval B.gen Q = p • z,
{ rw [← mod_by_monic_add_div Q₁ (minpoly.monic hBint)] at hQ,
simpa using hQ },
by_cases hQzero : Q = 0,
{ simp only [hQzero, algebra.smul_def, zero_eq_mul, aeval_zero] at hQ,
cases hQ with H H₁,
{ have : function.injective (algebra_map R L),
{ rw [algebra_map_eq R K L],
exact (algebra_map K L).injective.comp (is_fraction_ring.injective R K) }, exfalso,
exact hp.ne_zero ((injective_iff_map_eq_zero _).1 this _ H) },
{ rw [H₁],
exact subalgebra.zero_mem _ } },
-- It is enough to prove that all coefficients of `Q` are divisible by `p`, by induction.
-- The base case is `dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_is_eiseinstein_at`.
refine mem_adjoin_of_dvd_coeff_of_dvd_aeval hp.ne_zero (λ i, _) hQ,
refine nat.case_strong_induction_on i _ (λ j hind, _),
{ intro H,
exact dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_is_eiseinstein_at
hp hBint hQ hzint hei },
{ intro hj,
refine hp.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd _ hndiv,
exact n,
-- Two technical results we will need about `P.nat_degree` and `Q.nat_degree`.
have H := degree_mod_by_monic_lt Q₁ (minpoly.monic hBint),
rw [← hQ₁, ← hP] at H,
replace H:= nat.lt_iff_add_one_le.1 (lt_of_lt_of_le (lt_of_le_of_lt
(nat.lt_iff_add_one_le.1 (nat.lt_of_succ_lt_succ (mem_range.1 hj))) (lt_succ_self _))
(nat.lt_iff_add_one_le.1 (((nat_degree_lt_nat_degree_iff hQzero).2 H)))),
rw [add_assoc] at H,
have Hj : Q.nat_degree + 1 = j + 1 + (Q.nat_degree - j),
{ rw [← add_comm 1, ← add_comm 1, add_assoc, add_right_inj, ← nat.add_sub_assoc
(nat.lt_of_succ_lt_succ (mem_range.1 hj)).le, add_comm, nat.add_sub_cancel] },
-- By induction hypothesis we can find `g : ℕ → R` such that
-- `k ∈ range (j + 1) → Q.coeff k • B.gen ^ k = (algebra_map R L) p * g k • B.gen ^ k`-
choose! g hg using hind,
replace hg : ∀ k ∈ range (j + 1), Q.coeff k • B.gen ^ k =
(algebra_map R L p) * (g k • B.gen ^ k),
{ intros k hk,
rw [hg k (mem_range_succ_iff.1 hk) (mem_range_succ_iff.2 (le_trans (mem_range_succ_iff.1 hk)
(succ_le_iff.1 (mem_range_succ_iff.1 hj)).le)), algebra.smul_def, algebra.smul_def,
ring_hom.map_mul, mul_assoc] },
-- Since `minpoly R B.gen` is Eiseinstein, we can find `f : ℕ → L` such that
-- `(map (algebra_map R L) (minpoly R B.gen)).nat_degree ≤ i` implies `f i ∈ adjoin R {B.gen}`
-- and `(algebra_map R L) p * f i = B.gen ^ i`. We will also need `hf₁`, a reformulation of this
-- property.
choose! f hf using (is_weakly_eisenstein_at.exists_mem_adjoin_mul_eq_pow_nat_degree_le
(minpoly.aeval R B.gen) (minpoly.monic hBint) hei.is_weakly_eisenstein_at),
have hf₁ : ∀ k ∈ (range (Q.nat_degree - j)).erase 0,
Q.coeff (j + 1 + k) • B.gen ^ (j + 1 + k) * B.gen ^ (P.nat_degree - (j + 2)) =
(algebra_map R L) p * Q.coeff (j + 1 + k) • f (k + P.nat_degree - 1),
{ intros k hk,
rw [smul_mul_assoc, ← pow_add, ← nat.add_sub_assoc H, ← add_assoc j 1 1,
add_comm (j + 1) 1, add_assoc (j + 1), add_comm _ (k + P.nat_degree),
nat.add_sub_add_right, ← (hf (k + P.nat_degree - 1) _).2, mul_smul_comm],
rw [(minpoly.monic hBint).nat_degree_map, add_comm, nat.add_sub_assoc,
le_add_iff_nonneg_right],
{ exact nat.zero_le _ },
{ refine one_le_iff_ne_zero.2 (λ h, _),
rw [h] at hk,
simpa using hk },
{ apply_instance } },
-- The Eisenstein condition shows that `p` divides `Q.coeff j`
-- if `p^n.succ` divides the following multiple of `Q.coeff (succ j)^n.succ`:
suffices : p ^ n.succ ∣
Q.coeff (succ j) ^ n.succ * (minpoly R B.gen).coeff 0 ^ (succ j + (P.nat_degree - (j + 2))),
{ convert this,
rw [nat.succ_eq_add_one, add_assoc, ← nat.add_sub_assoc H, ← add_assoc, add_comm (j + 1),
nat.add_sub_add_left, ← nat.add_sub_assoc, nat.add_sub_add_left, hP,
← (minpoly.monic hBint).nat_degree_map (algebra_map R K),
← minpoly.gcd_domain_eq_field_fractions' K hBint, nat_degree_minpoly, hn, nat.sub_one,
nat.pred_succ],
linarith },
-- Using `hQ : aeval B.gen Q = p • z`, we write `p • z` as a sum of terms of degree less than
-- `j+1`, that are multiples of `p` by induction, and terms of degree at least `j+1`.
rw [aeval_eq_sum_range, Hj, range_add, sum_union (disjoint_range_add_left_embedding _ _),
sum_congr rfl hg, add_comm] at hQ,
-- We multiply this equality by `B.gen ^ (P.nat_degree-(j+2))`, so we can use `hf₁` on the terms
-- we didn't know were multiples of `p`, and we take the norm on both sides.
replace hQ := congr_arg (λ x, x * B.gen ^ (P.nat_degree - (j + 2))) hQ,
simp_rw [sum_map, add_left_embedding_apply, add_mul, sum_mul, mul_assoc] at hQ,
rw [← insert_erase (mem_range.2 (tsub_pos_iff_lt.2 $ nat.lt_of_succ_lt_succ $ mem_range.1 hj)),
sum_insert (not_mem_erase 0 _), add_zero, sum_congr rfl hf₁, ← mul_sum, ← mul_sum,
add_assoc, ← mul_add, smul_mul_assoc, ← pow_add, algebra.smul_def] at hQ,
replace hQ := congr_arg (norm K) (eq_sub_of_add_eq hQ),
-- We obtain an equality of elements of `K`, but everything is integral, so we can move to `R`
-- and simplify `hQ`.
have hintsum : is_integral R (z * B.gen ^ (P.nat_degree - (j + 2)) -
(∑ (x : ℕ) in (range (Q.nat_degree - j)).erase 0, Q.coeff (j + 1 + x) •
f (x + P.nat_degree - 1) +
∑ (x : ℕ) in range (j + 1), g x • B.gen ^ x * B.gen ^ (P.nat_degree - (j + 2)))),
{ refine is_integral_sub (is_integral_mul hzint (is_integral.pow hBint _))
(is_integral_add (is_integral.sum _ (λ k hk, is_integral_smul _ _))
(is_integral.sum _ (λ k hk, is_integral_mul (is_integral_smul _ (is_integral.pow hBint _))
((is_integral.pow hBint _))))),
refine adjoin_le_integral_closure hBint (hf _ _).1,
rw [(minpoly.monic hBint).nat_degree_map (algebra_map R L)],
rw [add_comm, nat.add_sub_assoc, le_add_iff_nonneg_right],
{ exact zero_le _ },
{ refine one_le_iff_ne_zero.2 (λ h, _),
rw [h] at hk,
simpa using hk } },
obtain ⟨r, hr⟩ := is_integral_iff.1 (is_integral_norm K hintsum),
rw [algebra.smul_def, mul_assoc, ← mul_sub, _root_.map_mul, algebra_map_apply R K L, map_pow,
algebra.norm_algebra_map, _root_.map_mul, algebra_map_apply R K L, algebra.norm_algebra_map,
finrank B, ← hr,
power_basis.norm_gen_eq_coeff_zero_minpoly, minpoly.gcd_domain_eq_field_fractions' K hBint,
coeff_map, show (-1 : K) = algebra_map R K (-1), by simp, ← map_pow, ← map_pow,
← _root_.map_mul, ← map_pow, ← _root_.map_mul, ← map_pow, ← _root_.map_mul] at hQ,
-- We can now finish the proof.
have hppdiv : p ^ B.dim ∣ p ^ B.dim * r := dvd_mul_of_dvd_left dvd_rfl _,
rwa [← is_fraction_ring.injective R K hQ, mul_comm, ← units.coe_neg_one, mul_pow,
← units.coe_pow, ← units.coe_pow, mul_assoc, is_unit.dvd_mul_left _ _ _ ⟨_, rfl⟩, mul_comm,
← nat.succ_eq_add_one, hn] at hppdiv }
end
/-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable
extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of
`B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p ^ n • z ∈ adjoin R {B.gen}`,
then `z ∈ adjoin R {B.gen}`. Together with `algebra.discr_mul_is_integral_mem_adjoin` this result
often allows to compute the ring of integers of `L`. -/
lemma mem_adjoin_of_smul_prime_pow_smul_of_minpoly_is_eiseinstein_at {B : power_basis K L}
(hp : prime p) (hBint : is_integral R B.gen) {n : ℕ} {z : L} (hzint : is_integral R z)
(hz : p ^ n • z ∈ adjoin R ({B.gen} : set L)) (hei : (minpoly R B.gen).is_eisenstein_at 𝓟) :
z ∈ adjoin R ({B.gen} : set L) :=
begin
induction n with n hn,
{ simpa using hz },
{ rw [pow_succ, mul_smul] at hz,
exact hn (mem_adjoin_of_smul_prime_smul_of_minpoly_is_eiseinstein_at
hp hBint (is_integral_smul _ hzint) hz hei) }
end
end is_integral
|
567c5a9598b90ed9789fe5d6d3ce7a0563429655 | 22e97a5d648fc451e25a06c668dc03ac7ed7bc25 | /src/analysis/calculus/inverse.lean | 7c16c32bba91a43a5a1b22981c717a45e7b97b9f | [
"Apache-2.0"
] | permissive | keeferrowan/mathlib | f2818da875dbc7780830d09bd4c526b0764a4e50 | aad2dfc40e8e6a7e258287a7c1580318e865817e | refs/heads/master | 1,661,736,426,952 | 1,590,438,032,000 | 1,590,438,032,000 | 266,892,663 | 0 | 0 | Apache-2.0 | 1,590,445,835,000 | 1,590,445,835,000 | null | UTF-8 | Lean | false | false | 21,344 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov.
-/
import analysis.calculus.deriv
import topology.local_homeomorph
import topology.metric_space.contracting
/-!
# Inverse function theorem
In this file we prove the inverse function theorem. It says that if a map `f : E → F`
has an invertible strict derivative `f'` at `a`, then it is locally invertible,
and the inverse function has derivative `f' ⁻¹`.
We define `has_strict_deriv_at.to_local_homeomorph` that repacks a function `f`
with a `hf : has_strict_fderiv_at f f' a`, `f' : E ≃L[𝕜] F`, into a `local_homeomorph`.
The `to_fun` of this `local_homeomorph` is `defeq` to `f`, so one can apply theorems
about `local_homeomorph` to `hf.to_local_homeomorph f`, and get statements about `f`.
Then we define `has_strict_fderiv_at.local_inverse` to be the `inv_fun` of this `local_homeomorph`,
and prove two versions of the inverse function theorem:
* `has_strict_fderiv_at.to_local_inverse`: if `f` has an invertible derivative `f'` at `a` in the
strict sense (`hf`), then `hf.local_inverse f f' a` has derivative `f'.symm` at `f a` in the
strict sense;
* `has_strict_fderiv_at.to_local_left_inverse`: if `f` has an invertible derivative `f'` at `a` in
the strict sense and `g` is locally left inverse to `f` near `a`, then `g` has derivative
`f'.symm` at `f a` in the strict sense.
In the one-dimensional case we reformulate these theorems in terms of `has_strict_deriv_at` and
`f'⁻¹`. Some other versions of the theorem assuming that we already know the inverse function are
formulated in `fderiv.lean` and `deriv.lean`
## Notations
In the section about `approximates_linear_on` we introduce some `local notation` to make formulas
shorter:
* by `N` we denote `∥f'⁻¹∥`;
* by `g` we denote the auxiliary contracting map `x ↦ x + f'.symm (y - f x)` used to prove that
`{x | f x = y}` is nonempty.
## Tags
derivative, strictly differentiable, inverse function
-/
open function set filter metric
open_locale topological_space classical nnreal
noncomputable theory
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
variables {E : Type*} [normed_group E] [normed_space 𝕜 E]
variables {F : Type*} [normed_group F] [normed_space 𝕜 F]
variables {G : Type*} [normed_group G] [normed_space 𝕜 G]
variables {G' : Type*} [normed_group G'] [normed_space 𝕜 G']
open asymptotics filter metric set
open continuous_linear_map (id)
/-!
### Non-linear maps approximating close to affine maps
In this section we study a map `f` such that `∥f x - f y - f' (x - y)∥ ≤ c * ∥x - y∥` on an open set
`s`, where `f' : E ≃L[𝕜] F` is a continuous linear equivalence and `c < ∥f'⁻¹∥`. Maps of this type
behave like `f a + f' (x - a)` near each `a ∈ s`.
If `E` is a complete space, we prove that the image `f '' s` is open, and `f` is a homeomorphism
between `s` and `f '' s`. More precisely, we define `approximates_linear_on.to_local_homeomorph` to
be a `local_homeomorph` with `to_fun = f`, `source = s`, and `target = f '' s`.
Maps of this type naturally appear in the proof of the inverse function theorem (see next section),
and `approximates_linear_on.to_local_homeomorph` will imply that the locally inverse function
exists.
We define this auxiliary notion to split the proof of the inverse function theorem into small
lemmas. This approach makes it possible
- to prove a lower estimate on the size of the domain of the inverse function;
- to reuse parts of the proofs in the case if a function is not strictly differentiable. E.g., for a
function `f : E × F → G` with estimates on `f x y₁ - f x y₂` but not on `f x₁ y - f x₂ y`.
-/
/-- We say that `f` approximates a continuous linear map `f'` on `s` with constant `c`,
if `∥f x - f y - f' (x - y)∥ ≤ c * ∥x - y∥` whenever `x, y ∈ s`.
This predicate is defined to facilitate the splitting of the inverse function theorem into small
lemmas. Some of these lemmas can be useful, e.g., to prove that the inverse function is defined
on a specific set. -/
def approximates_linear_on (f : E → F) (f' : E →L[𝕜] F) (s : set E) (c : ℝ≥0) : Prop :=
∀ (x ∈ s) (y ∈ s), ∥f x - f y - f' (x - y)∥ ≤ c * ∥x - y∥
namespace approximates_linear_on
variables [cs : complete_space E] {f : E → F}
/-! First we prove some properties of a function that `approximates_linear_on` a (not necessarily
invertible) continuous linear map. -/
section
variables {f' : E →L[𝕜] F} {s t : set E} {c c' : ℝ≥0}
theorem mono_num (hc : c ≤ c') (hf : approximates_linear_on f f' s c) :
approximates_linear_on f f' s c' :=
λ x hx y hy, le_trans (hf x hx y hy) (mul_le_mul_of_nonneg_right hc $ norm_nonneg _)
theorem mono_set (hst : s ⊆ t) (hf : approximates_linear_on f f' t c) :
approximates_linear_on f f' s c :=
λ x hx y hy, hf x (hst hx) y (hst hy)
lemma lipschitz_sub (hf : approximates_linear_on f f' s c) :
lipschitz_with c (λ x : s, f x - f' x) :=
begin
refine lipschitz_with.of_dist_le_mul (λ x y, _),
rw [dist_eq_norm, subtype.dist_eq, dist_eq_norm],
convert hf x x.2 y y.2 using 2,
rw [f'.map_sub], abel
end
protected lemma lipschitz (hf : approximates_linear_on f f' s c) :
lipschitz_with (nnnorm f' + c) (s.restrict f) :=
by simpa only [restrict_apply, add_sub_cancel'_right]
using (f'.lipschitz.restrict s).add hf.lipschitz_sub
protected lemma continuous (hf : approximates_linear_on f f' s c) :
continuous (s.restrict f) :=
hf.lipschitz.continuous
protected lemma continuous_on (hf : approximates_linear_on f f' s c) :
continuous_on f s :=
continuous_on_iff_continuous_restrict.2 hf.continuous
end
/-!
From now on we assume that `f` approximates an invertible continuous linear map `f : E ≃L[𝕜] F`.
We also assume that either `E = {0}`, or `c < ∥f'⁻¹∥⁻¹`. We use `N` as an abbreviation for `∥f'⁻¹∥`.
-/
variables {f' : E ≃L[𝕜] F} {s : set E} {c : ℝ≥0}
local notation `N` := nnnorm (f'.symm : F →L[𝕜] E)
protected lemma antilipschitz (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
antilipschitz_with (N⁻¹ - c)⁻¹ (s.restrict f) :=
begin
cases hc with hE hc,
{ haveI : subsingleton s := ⟨λ x y, subtype.eq $ @subsingleton.elim _ hE _ _⟩,
exact antilipschitz_with.of_subsingleton },
convert (f'.antilipschitz.restrict s).add_lipschitz_with hf.lipschitz_sub hc,
simp [restrict]
end
protected lemma injective (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
injective (s.restrict f) :=
(hf.antilipschitz hc).injective
protected lemma inj_on (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
inj_on f s :=
inj_on_iff_injective.2 $ hf.injective hc
/-- A map approximating a linear equivalence on a set defines a local equivalence on this set.
Should not be used outside of this file, because it is superseded by `to_local_homeomorph` below.
This is a first step towards the inverse function. -/
def to_local_equiv (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) : local_equiv E F :=
(hf.inj_on hc).to_local_equiv _ _
/-- The inverse function is continuous on `f '' s`. Use properties of `local_homeomorph` instead. -/
lemma inverse_continuous_on (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
continuous_on (hf.to_local_equiv hc).symm (f '' s) :=
begin
apply continuous_on_iff_continuous_restrict.2,
refine ((hf.antilipschitz hc).to_right_inv_on' _ (hf.to_local_equiv hc).right_inv').continuous,
exact (λ x hx, (hf.to_local_equiv hc).map_target hx)
end
/-!
Now we prove that `f '' s` is an open set. This follows from the fact that the restriction of `f`
on `s` is an open map. More precisely, we show that the image of a closed ball $$\bar B(a, ε) ⊆ s$$
under `f` includes the closed ball $$\bar B\left(f(a), \frac{ε}{∥{f'}⁻¹∥⁻¹-c}\right)$$.
In order to do this, we introduce an auxiliary map $$g_y(x) = x + {f'}⁻¹ (y - f x)$$. Provided that
$$∥y - f a∥ ≤ \frac{ε}{∥{f'}⁻¹∥⁻¹-c}$$, we prove that $$g_y$$ contracts in $$\bar B(a, ε)$$ and `f`
sends the fixed point of $$g_y$$ to `y`.
-/
section
variables (f f')
/-- Iterations of this map converge to `f⁻¹ y`. The formula is very similar to the one
used in Newton's method, but we use the same `f'.symm` for all `y` instead of evaluating
the derivative at each point along the orbit. -/
def inverse_approx_map (y : F) (x : E) : E := x + f'.symm (y - f x)
end
section inverse_approx_map
variables (y : F) {x x' : E} {ε : ℝ}
local notation `g` := inverse_approx_map f f' y
lemma inverse_approx_map_sub (x x' : E) : g x - g x' = (x - x') - f'.symm (f x - f x') :=
by { simp only [inverse_approx_map, f'.symm.map_sub], abel }
lemma inverse_approx_map_dist_self (x : E) :
dist (g x) x = dist (f'.symm $ f x) (f'.symm y) :=
by simp only [inverse_approx_map, dist_eq_norm, f'.symm.map_sub, add_sub_cancel', norm_sub_rev]
lemma inverse_approx_map_dist_self_le (x : E) :
dist (g x) x ≤ N * dist (f x) y :=
by { rw inverse_approx_map_dist_self, exact f'.symm.lipschitz.dist_le_mul (f x) y }
lemma inverse_approx_map_fixed_iff {x : E} :
g x = x ↔ f x = y :=
by rw [← dist_eq_zero, inverse_approx_map_dist_self, dist_eq_zero, f'.symm.injective.eq_iff]
lemma inverse_approx_map_contracts_on (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
{x x'} (hx : x ∈ s) (hx' : x' ∈ s) :
dist (g x) (g x') ≤ N * c * dist x x' :=
begin
rw [dist_eq_norm, dist_eq_norm, inverse_approx_map_sub, norm_sub_rev],
suffices : ∥f'.symm (f x - f x' - f' (x - x'))∥ ≤ N * (c * ∥x - x'∥),
by simpa only [f'.symm.map_sub, f'.symm_apply_apply, mul_assoc] using this,
exact (f'.symm : F →L[𝕜] E).le_op_norm_of_le (hf x hx x' hx')
end
variable {y}
lemma inverse_approx_map_maps_to (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) {b : E} (hb : b ∈ s) (hε : closed_ball b ε ⊆ s)
(hy : y ∈ closed_ball (f b) ((N⁻¹ - c) * ε)) :
maps_to g (closed_ball b ε) (closed_ball b ε) :=
begin
cases hc with hE hc,
{ exactI λ x hx, mem_preimage.2 (subsingleton.elim x (g x) ▸ hx) },
assume x hx,
simp only [subset_def, mem_closed_ball, mem_preimage] at hx hy ⊢,
rw [dist_comm] at hy,
calc dist (inverse_approx_map f f' y x) b ≤
dist (inverse_approx_map f f' y x) (inverse_approx_map f f' y b) +
dist (inverse_approx_map f f' y b) b : dist_triangle _ _ _
... ≤ N * c * dist x b + N * dist (f b) y :
add_le_add (hf.inverse_approx_map_contracts_on y (hε hx) hb)
(inverse_approx_map_dist_self_le _ _)
... ≤ N * c * ε + N * ((N⁻¹ - c) * ε) :
add_le_add (mul_le_mul_of_nonneg_left hx (mul_nonneg (nnreal.coe_nonneg _) c.coe_nonneg))
(mul_le_mul_of_nonneg_left hy (nnreal.coe_nonneg _))
... = N * (c + (N⁻¹ - c)) * ε : by simp only [mul_add, add_mul, mul_assoc]
... = ε : by { rw [add_sub_cancel'_right, mul_inv_cancel, one_mul],
exact ne_of_gt (inv_pos.1 $ lt_of_le_of_lt c.coe_nonneg hc) }
end
end inverse_approx_map
include cs
variable {ε : ℝ}
theorem surj_on_closed_ball (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) {b : E} (ε0 : 0 ≤ ε) (hε : closed_ball b ε ⊆ s) :
surj_on f (closed_ball b ε) (closed_ball (f b) ((N⁻¹ - c) * ε)) :=
begin
cases hc with hE hc,
{ resetI,
haveI hF : subsingleton F := f'.symm.to_linear_equiv.to_equiv.subsingleton,
intros y hy,
exact ⟨b, mem_closed_ball_self ε0, subsingleton.elim _ _⟩ },
intros y hy,
have : contracting_with (N * c) ((hf.inverse_approx_map_maps_to (or.inr hc)
(hε $ mem_closed_ball_self ε0) hε hy).restrict _ _ _),
{ split,
{ rwa [mul_comm, ← nnreal.lt_inv_iff_mul_lt],
exact ne_of_gt (inv_pos.1 $ lt_of_le_of_lt c.coe_nonneg hc) },
{ exact lipschitz_with.of_dist_le_mul (λ x x', hf.inverse_approx_map_contracts_on
y (hε x.mem) (hε x'.mem)) } },
refine ⟨this.efixed_point' _ _ _ b (mem_closed_ball_self ε0) (edist_lt_top _ _), _, _⟩,
{ exact is_complete_of_is_closed is_closed_ball },
{ apply contracting_with.efixed_point_mem' },
{ exact (inverse_approx_map_fixed_iff y).1 (this.efixed_point_is_fixed' _ _ _ _) }
end
section
variables (f s)
/-- Given a function `f` that approximates a linear equivalence on an open set `s`,
returns a local homeomorph with `to_fun = f` and `source = s`. -/
def to_local_homeomorph (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) : local_homeomorph E F :=
{ to_local_equiv := hf.to_local_equiv hc,
open_source := hs,
open_target :=
begin
cases hc with hE hc,
{ resetI,
haveI hF : subsingleton F := f'.to_linear_equiv.to_equiv.symm.subsingleton,
apply is_open_discrete },
change is_open (f '' s),
simp only [is_open_iff_mem_nhds, nhds_basis_closed_ball.mem_iff, ball_image_iff] at hs ⊢,
intros x hx,
rcases hs x hx with ⟨ε, ε0, hε⟩,
refine ⟨(N⁻¹ - c) * ε, mul_pos (sub_pos.2 hc) ε0, _⟩,
exact (hf.surj_on_closed_ball (or.inr hc) (le_of_lt ε0) hε).mono hε (subset.refl _)
end,
continuous_to_fun := hf.continuous_on,
continuous_inv_fun := hf.inverse_continuous_on hc }
end
@[simp] lemma to_local_homeomorph_coe (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) :
(hf.to_local_homeomorph f s hc hs : E → F) = f := rfl
@[simp] lemma to_local_homeomorph_source (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) :
(hf.to_local_homeomorph f s hc hs).source = s := rfl
@[simp] lemma to_local_homeomorph_target (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) :
(hf.to_local_homeomorph f s hc hs).target = f '' s := rfl
lemma closed_ball_subset_target (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) {b : E} (ε0 : 0 ≤ ε) (hε : closed_ball b ε ⊆ s) :
closed_ball (f b) ((N⁻¹ - c) * ε) ⊆ (hf.to_local_homeomorph f s hc hs).target :=
(hf.surj_on_closed_ball hc ε0 hε).mono hε (subset.refl _)
end approximates_linear_on
/-!
### Inverse function theorem
Now we prove the inverse function theorem. Let `f : E → F` be a map defined on a complete vector
space `E`. Assume that `f` has an invertible derivative `f' : E ≃L[𝕜] F` at `a : E` in the strict
sense. Then `f` approximates `f'` in the sense of `approximates_linear_on` on an open neighborhood
of `a`, and we can apply `approximates_linear_on.to_local_homeomorph` to construct the inverse
function. -/
namespace has_strict_fderiv_at
/-- If `f` has derivative `f'` at `a` in the strict sense and `c > 0`, then `f` approximates `f'`
with constant `c` on some neighborhood of `a`. -/
lemma approximates_deriv_on_nhds {f : E → F} {f' : E →L[𝕜] F} {a : E}
(hf : has_strict_fderiv_at f f' a) {c : ℝ≥0} (hc : subsingleton E ∨ 0 < c) :
∃ s ∈ 𝓝 a, approximates_linear_on f f' s c :=
begin
cases hc with hE hc,
{ refine ⟨univ, mem_nhds_sets is_open_univ trivial, λ x hx y hy, _⟩,
simp [@subsingleton.elim E hE x y] },
have := hf.def hc,
rw [nhds_prod_eq, filter.eventually, mem_prod_same_iff] at this,
rcases this with ⟨s, has, hs⟩,
exact ⟨s, has, λ x hx y hy, hs (mk_mem_prod hx hy)⟩
end
variables [cs : complete_space E] {f : E → F} {f' : E ≃L[𝕜] F} {a : E}
lemma approximates_deriv_on_open_nhds (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
∃ (s : set E) (hs : a ∈ s ∧ is_open s),
approximates_linear_on f (f' : E →L[𝕜] F) s ((nnnorm (f'.symm : F →L[𝕜] E))⁻¹ / 2) :=
begin
refine ((nhds_basis_opens a).exists_iff _).1 _,
exact (λ s t, approximates_linear_on.mono_set),
exact (hf.approximates_deriv_on_nhds $ f'.subsingleton_or_nnnorm_symm_pos.imp id $
λ hf', nnreal.half_pos $ nnreal.inv_pos.2 $ hf')
end
include cs
variable (f)
/-- Given a function with an invertible strict derivative at `a`, returns a `local_homeomorph`
with `to_fun = f` and `a ∈ source`. This is a part of the inverse function theorem.
The other part `has_strict_fderiv_at.to_local_inverse` states that the inverse function
of this `local_homeomorph` has derivative `f'.symm`. -/
def to_local_homeomorph (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) : local_homeomorph E F :=
approximates_linear_on.to_local_homeomorph f
(classical.some hf.approximates_deriv_on_open_nhds)
(classical.some_spec hf.approximates_deriv_on_open_nhds).snd
(f'.subsingleton_or_nnnorm_symm_pos.imp id $ λ hf', nnreal.half_lt_self $ ne_of_gt $
nnreal.inv_pos.2 $ hf')
(classical.some_spec hf.approximates_deriv_on_open_nhds).fst.2
variable {f}
@[simp] lemma to_local_homeomorph_coe (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
(hf.to_local_homeomorph f : E → F) = f := rfl
lemma mem_to_local_homeomorph_source (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
a ∈ (hf.to_local_homeomorph f).source :=
(classical.some_spec hf.approximates_deriv_on_open_nhds).fst.1
lemma image_mem_to_local_homeomorph_target (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
f a ∈ (hf.to_local_homeomorph f).target :=
(hf.to_local_homeomorph f).map_source hf.mem_to_local_homeomorph_source
variables (f f' a)
/-- Given a function `f` with an invertible derivative, returns a function that is locally inverse
to `f`. -/
def local_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) : F → E :=
(hf.to_local_homeomorph f).symm
variables {f f' a}
lemma eventually_left_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
∀ᶠ x in 𝓝 a, hf.local_inverse f f' a (f x) = x :=
(hf.to_local_homeomorph f).eventually_left_inverse hf.mem_to_local_homeomorph_source
lemma local_inverse_apply_image (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
hf.local_inverse f f' a (f a) = a :=
hf.eventually_left_inverse.self_of_nhds
lemma eventually_right_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
∀ᶠ y in 𝓝 (f a), f (hf.local_inverse f f' a y) = y :=
(hf.to_local_homeomorph f).eventually_right_inverse' hf.mem_to_local_homeomorph_source
lemma local_inverse_continuous_at (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
continuous_at (hf.local_inverse f f' a) (f a) :=
(hf.to_local_homeomorph f).continuous_at_symm hf.image_mem_to_local_homeomorph_target
/-- If `f` has an invertible derivative `f'` at `a` in the sense of strict differentiability `(hf)`,
then the inverse function `hf.local_inverse f` has derivative `f'.symm` at `f a`. -/
theorem to_local_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
has_strict_fderiv_at (hf.local_inverse f f' a) (f'.symm : F →L[𝕜] E) (f a) :=
begin
have : has_strict_fderiv_at f (f' : E →L[𝕜] F) (hf.local_inverse f f' a (f a)),
{ rwa hf.local_inverse_apply_image },
exact this.of_local_left_inverse hf.local_inverse_continuous_at hf.eventually_right_inverse
end
/-- If `f : E → F` has an invertible derivative `f'` at `a` in the sense of strict differentiability
and `g (f x) = x` in a neighborhood of `a`, then `g` has derivative `f'.symm` at `f a`.
For a version assuming `f (g y) = y` and continuity of `g` at `f a` but not `[complete_space E]`
see `of_local_left_inverse`. -/
theorem to_local_left_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) {g : F → E}
(hg : ∀ᶠ x in 𝓝 a, g (f x) = x) :
has_strict_fderiv_at g (f'.symm : F →L[𝕜] E) (f a) :=
begin
apply hf.to_local_inverse.congr_of_mem_sets,
have := ((hf.to_local_homeomorph f).tendsto_symm
hf.mem_to_local_homeomorph_source).eventually hg,
refine this.mp (hf.eventually_right_inverse.mono $ λ y hy hy', _),
exact hy'.symm.trans (congr_arg g hy)
end
end has_strict_fderiv_at
/-!
### Inverse function theorem, 1D case
In this case we prove a version of the inverse function theorem for maps `f : 𝕜 → 𝕜`.
We use `continuous_linear_equiv.units_equiv_aut` to translate `has_strict_deriv_at f f' a` and
`f' ≠ 0` into `has_strict_fderiv_at f (_ : 𝕜 ≃L[𝕜] 𝕜) a`.
-/
namespace has_strict_deriv_at
variables [cs : complete_space 𝕜] {f : 𝕜 → 𝕜} {f' a : 𝕜} (hf : has_strict_deriv_at f f' a)
(hf' : f' ≠ 0)
include cs
variables (f f' a)
/-- A function that is inverse to `f` near `a`. -/
@[reducible] def local_inverse : 𝕜 → 𝕜 :=
(hf.has_strict_fderiv_at_equiv hf').local_inverse _ _ _
variables {f f' a}
theorem to_local_inverse : has_strict_deriv_at (hf.local_inverse f f' a hf') f'⁻¹ (f a) :=
(hf.has_strict_fderiv_at_equiv hf').to_local_inverse
theorem to_local_left_inverse {g : 𝕜 → 𝕜} (hg : ∀ᶠ x in 𝓝 a, g (f x) = x) :
has_strict_deriv_at g f'⁻¹ (f a) :=
(hf.has_strict_fderiv_at_equiv hf').to_local_left_inverse hg
end has_strict_deriv_at
|
19a6184b5a42a3b5fe378d0b1975fda351786226 | de91c42b87530c3bdcc2b138ef1a3c3d9bee0d41 | /expressions/expr_base.lean | 4e26a090b8fa4803295869038ae2f886c42b31b9 | [] | no_license | kevinsullivan/lang | d3e526ba363dc1ddf5ff1c2f36607d7f891806a7 | e9d869bff94fb13ad9262222a6f3c4aafba82d5e | refs/heads/master | 1,687,840,064,795 | 1,628,047,969,000 | 1,628,047,969,000 | 282,210,749 | 0 | 1 | null | 1,608,153,830,000 | 1,595,592,637,000 | Lean | UTF-8 | Lean | false | false | 30 | lean | structure var := (nm : string) |
5a2f1fda49481cf99ec925ee41ebdae25b8f1d4f | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/bench/rbmap4.lean | 91770084467a7000aacf0cd6f3d80ede95f74704 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 2,845 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.coe init.data.option.basic init.system.io
universes u v w w'
inductive color
| Red | Black
inductive Tree
| Leaf {} : Tree
| Node (color : color) (lchild : Tree) (key : Nat) (val : Bool) (rchild : Tree) : Tree
variables {σ : Type w}
open color Nat Tree
def fold (f : Nat → Bool → σ → σ) : Tree → σ → σ
| Leaf, b => b
| Node _ l k v r, b => fold r (f k v (fold l b))
@[inline]
def balance1 : Nat → Bool → Tree → Tree → Tree
| kv, vv, t, Node _ (Node Red l kx vx r₁) ky vy r₂ => Node Red (Node Black l kx vx r₁) ky vy (Node Black r₂ kv vv t)
| kv, vv, t, Node _ l₁ ky vy (Node Red l₂ kx vx r) => Node Red (Node Black l₁ ky vy l₂) kx vx (Node Black r kv vv t)
| kv, vv, t, Node _ l ky vy r => Node Black (Node Red l ky vy r) kv vv t
| _, _, _, _ => Leaf
@[inline]
def balance2 : Tree → Nat → Bool → Tree → Tree
| t, kv, vv, Node _ (Node Red l kx₁ vx₁ r₁) ky vy r₂ => Node Red (Node Black t kv vv l) kx₁ vx₁ (Node Black r₁ ky vy r₂)
| t, kv, vv, Node _ l₁ ky vy (Node Red l₂ kx₂ vx₂ r₂) => Node Red (Node Black t kv vv l₁) ky vy (Node Black l₂ kx₂ vx₂ r₂)
| t, kv, vv, Node _ l ky vy r => Node Black t kv vv (Node Red l ky vy r)
| _, _, _, _ => Leaf
def isRed : Tree → Bool
| Node Red _ _ _ _ => true
| _ => false
def ins : Tree → Nat → Bool → Tree
| Leaf, kx, vx => Node Red Leaf kx vx Leaf
| Node Red a ky vy b, kx, vx =>
(if kx < ky then Node Red (ins a kx vx) ky vy b
else if kx = ky then Node Red a kx vx b
else Node Red a ky vy (ins b kx vx))
| Node Black a ky vy b, kx, vx =>
if kx < ky then
(if isRed a then balance1 ky vy b (ins a kx vx)
else Node Black (ins a kx vx) ky vy b)
else if kx = ky then Node Black a kx vx b
else if isRed b then balance2 a ky vy (ins b kx vx)
else Node Black a ky vy (ins b kx vx)
def setBlack : Tree → Tree
| Node _ l k v r => Node Black l k v r
| e => e
def insert (t : Tree) (k : Nat) (v : Bool) : Tree :=
if isRed t then setBlack (ins t k v)
else ins t k v
def mkMapAux : Nat → Tree → Tree
| 0, m => m
| n+1, m => mkMapAux n (insert m n (n % 10 = 0))
def mkMap (n : Nat) :=
mkMapAux n Leaf
def main (xs : List String) : IO UInt32 :=
let m := mkMap xs.head.toNat;
let v := fold (fun (k : Nat) (v : Bool) (r : Nat) => if v then r + 1 else r) m 0;
IO.println (toString v) *>
pure 0
|
882985587a8169eca6b51248f26d053bbbaf33e7 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebraic_geometry/Scheme.lean | 64bd4103cb64943aadee4400a415e4625c9aed32 | [
"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 | 3,767 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebraic_geometry.Spec
/-!
# The category of schemes
A scheme is a locally ringed space such that every point is contained in some open set
where there is an isomorphism of presheaves between the restriction to that open set,
and the structure sheaf of `Spec R`, for some commutative ring `R`.
A morphism of schemes is just a morphism of the underlying locally ringed spaces.
-/
noncomputable theory
open topological_space
open category_theory
open Top
open opposite
namespace algebraic_geometry
/--
We define `Scheme` as a `X : LocallyRingedSpace`,
along with a proof that every point has an open neighbourhood `U`
so that that the restriction of `X` to `U` is isomorphic,
as a locally ringed space, to `Spec.to_LocallyRingedSpace.obj (op R)`
for some `R : CommRing`.
-/
structure Scheme extends X : LocallyRingedSpace :=
(local_affine : ∀ x : X, ∃ (U : open_nhds x) (R : CommRing),
nonempty (X.restrict U.open_embedding ≅ Spec.to_LocallyRingedSpace.obj (op R)))
namespace Scheme
/--
Every `Scheme` is a `LocallyRingedSpace`.
-/
-- (This parent projection is apparently not automatically generated because
-- we used the `extends X : LocallyRingedSpace` syntax.)
def to_LocallyRingedSpace (S : Scheme) : LocallyRingedSpace := { ..S }
/--
Schemes are a full subcategory of locally ringed spaces.
-/
instance : category Scheme :=
induced_category.category Scheme.to_LocallyRingedSpace
/--
The spectrum of a commutative ring, as a scheme.
-/
def Spec_obj (R : CommRing) : Scheme :=
{ local_affine := λ x,
⟨⟨⊤, trivial⟩, R, ⟨(Spec.to_LocallyRingedSpace.obj (op R)).restrict_top_iso⟩⟩,
.. Spec.LocallyRingedSpace_obj R }
@[simp] lemma Spec_obj_to_LocallyRingedSpace (R : CommRing) :
(Spec_obj R).to_LocallyRingedSpace = Spec.LocallyRingedSpace_obj R := rfl
/--
The induced map of a ring homomorphism on the ring spectra, as a morphism of schemes.
-/
def Spec_map {R S : CommRing} (f : R ⟶ S) :
Spec_obj S ⟶ Spec_obj R :=
(Spec.LocallyRingedSpace_map f : Spec.LocallyRingedSpace_obj S ⟶ Spec.LocallyRingedSpace_obj R)
@[simp] lemma Spec_map_id (R : CommRing) :
Spec_map (𝟙 R) = 𝟙 (Spec_obj R) :=
Spec.LocallyRingedSpace_map_id R
lemma Spec_map_comp {R S T : CommRing} (f : R ⟶ S) (g : S ⟶ T) :
Spec_map (f ≫ g) = Spec_map g ≫ Spec_map f :=
Spec.LocallyRingedSpace_map_comp f g
/--
The spectrum, as a contravariant functor from commutative rings to schemes.
-/
@[simps] def Spec : CommRingᵒᵖ ⥤ Scheme :=
{ obj := λ R, Spec_obj (unop R),
map := λ R S f, Spec_map f.unop,
map_id' := λ R, by rw [unop_id, Spec_map_id],
map_comp' := λ R S T f g, by rw [unop_comp, Spec_map_comp] }
/--
The empty scheme, as `Spec 0`.
-/
def empty : Scheme :=
Spec_obj (CommRing.of punit)
instance : has_emptyc Scheme := ⟨empty⟩
instance : inhabited Scheme := ⟨∅⟩
/--
The global sections, notated Gamma.
-/
def Γ : Schemeᵒᵖ ⥤ CommRing :=
(induced_functor Scheme.to_LocallyRingedSpace).op ⋙ LocallyRingedSpace.Γ
lemma Γ_def : Γ = (induced_functor Scheme.to_LocallyRingedSpace).op ⋙ LocallyRingedSpace.Γ := rfl
@[simp] lemma Γ_obj (X : Schemeᵒᵖ) : Γ.obj X = (unop X).presheaf.obj (op ⊤) := rfl
lemma Γ_obj_op (X : Scheme) : Γ.obj (op X) = X.presheaf.obj (op ⊤) := rfl
@[simp] lemma Γ_map {X Y : Schemeᵒᵖ} (f : X ⟶ Y) :
Γ.map f = f.unop.1.c.app (op ⊤) := rfl
lemma Γ_map_op {X Y : Scheme} (f : X ⟶ Y) :
Γ.map f.op = f.1.c.app (op ⊤) := rfl
-- PROJECTS:
-- 1. Construct `Spec ≫ Γ ≅ functor.id _`.
-- 2. Adjunction between `Γ` and `Spec`.
--
end Scheme
end algebraic_geometry
|
5af13a1b1c8a164e1c39b96219bb057793570bb6 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/monad/limits.lean | 31bac6c46e2d7419ebe02d48930812df5d6e46fc | [
"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 | 15,339 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import category_theory.monad.adjunction
import category_theory.adjunction.limits
import category_theory.limits.shapes.terminal
/-!
# Limits and colimits in the category of algebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file shows that the forgetful functor `forget T : algebra T ⥤ C` for a monad `T : C ⥤ C`
creates limits and creates any colimits which `T` preserves.
This is used to show that `algebra T` has any limits which `C` has, and any colimits which `C` has
and `T` preserves.
This is generalised to the case of a monadic functor `D ⥤ C`.
## TODO
Dualise for the category of coalgebras and comonadic left adjoints.
-/
namespace category_theory
open category
open category_theory.limits
universes v u v₁ v₂ u₁ u₂
-- morphism levels before object levels. See note [category_theory universes].
namespace monad
variables {C : Type u₁} [category.{v₁} C]
variables {T : monad C}
variables {J : Type u} [category.{v} J]
namespace forget_creates_limits
variables (D : J ⥤ algebra T) (c : cone (D ⋙ T.forget)) (t : is_limit c)
/-- (Impl) The natural transformation used to define the new cone -/
@[simps] def γ : (D ⋙ T.forget ⋙ ↑T) ⟶ D ⋙ T.forget := { app := λ j, (D.obj j).a }
/-- (Impl) This new cone is used to construct the algebra structure -/
@[simps π_app] def new_cone : cone (D ⋙ forget T) :=
{ X := T.obj c.X,
π := (functor.const_comp _ _ ↑T).inv ≫ whisker_right c.π T ≫ γ D }
/-- The algebra structure which will be the apex of the new limit cone for `D`. -/
@[simps] def cone_point : algebra T :=
{ A := c.X,
a := t.lift (new_cone D c),
unit' := t.hom_ext $ λ j,
begin
rw [category.assoc, t.fac, new_cone_π_app, ←T.η.naturality_assoc, functor.id_map,
(D.obj j).unit],
dsimp, simp -- See library note [dsimp, simp]
end,
assoc' := t.hom_ext $ λ j,
begin
rw [category.assoc, category.assoc, t.fac (new_cone D c), new_cone_π_app,
←functor.map_comp_assoc, t.fac (new_cone D c), new_cone_π_app, ←T.μ.naturality_assoc,
(D.obj j).assoc, functor.map_comp, category.assoc],
refl,
end }
/-- (Impl) Construct the lifted cone in `algebra T` which will be limiting. -/
@[simps] def lifted_cone : cone D :=
{ X := cone_point D c t,
π := { app := λ j, { f := c.π.app j },
naturality' := λ X Y f, by { ext1, dsimp, erw c.w f, simp } } }
/-- (Impl) Prove that the lifted cone is limiting. -/
@[simps]
def lifted_cone_is_limit : is_limit (lifted_cone D c t) :=
{ lift := λ s,
{ f := t.lift ((forget T).map_cone s),
h' := t.hom_ext $ λ j,
begin
dsimp,
rw [category.assoc, category.assoc, t.fac, new_cone_π_app, ←functor.map_comp_assoc, t.fac,
functor.map_cone_π_app],
apply (s.π.app j).h,
end },
uniq' := λ s m J,
begin
ext1,
apply t.hom_ext,
intro j,
simpa [t.fac ((forget T).map_cone s) j] using congr_arg algebra.hom.f (J j),
end }
end forget_creates_limits
-- Theorem 5.6.5 from [Riehl][riehl2017]
/-- The forgetful functor from the Eilenberg-Moore category creates limits. -/
noncomputable
instance forget_creates_limits : creates_limits_of_size (forget T) :=
{ creates_limits_of_shape := λ J 𝒥, by exactI
{ creates_limit := λ D,
creates_limit_of_reflects_iso (λ c t,
{ lifted_cone := forget_creates_limits.lifted_cone D c t,
valid_lift := cones.ext (iso.refl _) (λ j, (id_comp _).symm),
makes_limit := forget_creates_limits.lifted_cone_is_limit _ _ _ } ) } }
/-- `D ⋙ forget T` has a limit, then `D` has a limit. -/
lemma has_limit_of_comp_forget_has_limit (D : J ⥤ algebra T) [has_limit (D ⋙ forget T)] :
has_limit D :=
has_limit_of_created D (forget T)
namespace forget_creates_colimits
-- Let's hide the implementation details in a namespace
variables {D : J ⥤ algebra T} (c : cocone (D ⋙ forget T)) (t : is_colimit c)
-- We have a diagram D of shape J in the category of algebras, and we assume that we are given a
-- colimit for its image D ⋙ forget T under the forgetful functor, say its apex is L.
-- We'll construct a colimiting coalgebra for D, whose carrier will also be L.
-- To do this, we must find a map TL ⟶ L. Since T preserves colimits, TL is also a colimit.
-- In particular, it is a colimit for the diagram `(D ⋙ forget T) ⋙ T`
-- so to construct a map TL ⟶ L it suffices to show that L is the apex of a cocone for this diagram.
-- In other words, we need a natural transformation from const L to `(D ⋙ forget T) ⋙ T`.
-- But we already know that L is the apex of a cocone for the diagram `D ⋙ forget T`, so it
-- suffices to give a natural transformation `((D ⋙ forget T) ⋙ T) ⟶ (D ⋙ forget T)`:
/--
(Impl)
The natural transformation given by the algebra structure maps, used to construct a cocone `c` with
apex `colimit (D ⋙ forget T)`.
-/
@[simps] def γ : ((D ⋙ forget T) ⋙ ↑T) ⟶ (D ⋙ forget T) := { app := λ j, (D.obj j).a }
/--
(Impl)
A cocone for the diagram `(D ⋙ forget T) ⋙ T` found by composing the natural transformation `γ`
with the colimiting cocone for `D ⋙ forget T`.
-/
@[simps]
def new_cocone : cocone ((D ⋙ forget T) ⋙ ↑T) :=
{ X := c.X,
ι := γ ≫ c.ι }
variables [preserves_colimit (D ⋙ forget T) (T : C ⥤ C)]
/--
(Impl)
Define the map `λ : TL ⟶ L`, which will serve as the structure of the coalgebra on `L`, and
we will show is the colimiting object. We use the cocone constructed by `c` and the fact that
`T` preserves colimits to produce this morphism.
-/
@[reducible]
def lambda : ((T : C ⥤ C).map_cocone c).X ⟶ c.X :=
(is_colimit_of_preserves _ t).desc (new_cocone c)
/-- (Impl) The key property defining the map `λ : TL ⟶ L`. -/
lemma commuting (j : J) :
(T : C ⥤ C).map (c.ι.app j) ≫ lambda c t = (D.obj j).a ≫ c.ι.app j :=
(is_colimit_of_preserves _ t).fac (new_cocone c) j
variables [preserves_colimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)]
/--
(Impl)
Construct the colimiting algebra from the map `λ : TL ⟶ L` given by `lambda`. We are required to
show it satisfies the two algebra laws, which follow from the algebra laws for the image of `D` and
our `commuting` lemma.
-/
@[simps] def cocone_point :
algebra T :=
{ A := c.X,
a := lambda c t,
unit' :=
begin
apply t.hom_ext,
intro j,
rw [(show c.ι.app j ≫ T.η.app c.X ≫ _ = T.η.app (D.obj j).A ≫ _ ≫ _,
from T.η.naturality_assoc _ _), commuting, algebra.unit_assoc (D.obj j)],
dsimp, simp -- See library note [dsimp, simp]
end,
assoc' :=
begin
refine (is_colimit_of_preserves _ (is_colimit_of_preserves _ t)).hom_ext (λ j, _),
rw [functor.map_cocone_ι_app, functor.map_cocone_ι_app,
(show (T : C ⥤ C).map ((T : C ⥤ C).map _) ≫ _ ≫ _ = _, from T.μ.naturality_assoc _ _),
←functor.map_comp_assoc, commuting, functor.map_comp, category.assoc, commuting],
apply (D.obj j).assoc_assoc _,
end }
/-- (Impl) Construct the lifted cocone in `algebra T` which will be colimiting. -/
@[simps] def lifted_cocone : cocone D :=
{ X := cocone_point c t,
ι := { app := λ j, { f := c.ι.app j, h' := commuting _ _ _ },
naturality' := λ A B f, by { ext1, dsimp, rw [comp_id], apply c.w } } }
/-- (Impl) Prove that the lifted cocone is colimiting. -/
@[simps]
def lifted_cocone_is_colimit : is_colimit (lifted_cocone c t) :=
{ desc := λ s,
{ f := t.desc ((forget T).map_cocone s),
h' := (is_colimit_of_preserves (T : C ⥤ C) t).hom_ext $ λ j,
begin
dsimp,
rw [←functor.map_comp_assoc, ←category.assoc, t.fac, commuting, category.assoc, t.fac],
apply algebra.hom.h,
end },
uniq' := λ s m J,
by { ext1, apply t.hom_ext, intro j, simpa using congr_arg algebra.hom.f (J j) } }
end forget_creates_colimits
open forget_creates_colimits
-- TODO: the converse of this is true as well
/--
The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit
which the monad itself preserves.
-/
noncomputable
instance forget_creates_colimit (D : J ⥤ algebra T)
[preserves_colimit (D ⋙ forget T) (T : C ⥤ C)]
[preserves_colimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)] :
creates_colimit D (forget T) :=
creates_colimit_of_reflects_iso $ λ c t,
{ lifted_cocone :=
{ X := cocone_point c t,
ι :=
{ app := λ j, { f := c.ι.app j, h' := commuting _ _ _ },
naturality' := λ A B f, by { ext1, dsimp, erw [comp_id, c.w] } } },
valid_lift := cocones.ext (iso.refl _) (by tidy),
makes_colimit := lifted_cocone_is_colimit _ _ }
noncomputable
instance forget_creates_colimits_of_shape
[preserves_colimits_of_shape J (T : C ⥤ C)] :
creates_colimits_of_shape J (forget T) :=
{ creates_colimit := λ K, by apply_instance }
noncomputable
instance forget_creates_colimits
[preserves_colimits_of_size.{v u} (T : C ⥤ C)] :
creates_colimits_of_size.{v u} (forget T) :=
{ creates_colimits_of_shape := λ J 𝒥₁, by apply_instance }
/--
For `D : J ⥤ algebra T`, `D ⋙ forget T` has a colimit, then `D` has a colimit provided colimits
of shape `J` are preserved by `T`.
-/
lemma forget_creates_colimits_of_monad_preserves
[preserves_colimits_of_shape J (T : C ⥤ C)] (D : J ⥤ algebra T) [has_colimit (D ⋙ forget T)] :
has_colimit D :=
has_colimit_of_created D (forget T)
end monad
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
variables {J : Type u} [category.{v} J]
instance comp_comparison_forget_has_limit
(F : J ⥤ D) (R : D ⥤ C) [monadic_right_adjoint R] [has_limit (F ⋙ R)] :
has_limit ((F ⋙ monad.comparison (adjunction.of_right_adjoint R)) ⋙ monad.forget _) :=
@has_limit_of_iso _ _ _ _ (F ⋙ R) _ _
(iso_whisker_left F (monad.comparison_forget (adjunction.of_right_adjoint R)).symm)
instance comp_comparison_has_limit
(F : J ⥤ D) (R : D ⥤ C) [monadic_right_adjoint R] [has_limit (F ⋙ R)] :
has_limit (F ⋙ monad.comparison (adjunction.of_right_adjoint R)) :=
monad.has_limit_of_comp_forget_has_limit (F ⋙ monad.comparison (adjunction.of_right_adjoint R))
/-- Any monadic functor creates limits. -/
noncomputable
def monadic_creates_limits (R : D ⥤ C) [monadic_right_adjoint R] :
creates_limits_of_size.{v u} R :=
creates_limits_of_nat_iso (monad.comparison_forget (adjunction.of_right_adjoint R))
/--
The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit
which the monad itself preserves.
-/
noncomputable
def monadic_creates_colimit_of_preserves_colimit (R : D ⥤ C) (K : J ⥤ D)
[monadic_right_adjoint R]
[preserves_colimit (K ⋙ R) (left_adjoint R ⋙ R)]
[preserves_colimit ((K ⋙ R) ⋙ left_adjoint R ⋙ R) (left_adjoint R ⋙ R)] :
creates_colimit K R :=
begin
apply creates_colimit_of_nat_iso (monad.comparison_forget (adjunction.of_right_adjoint R)),
apply category_theory.comp_creates_colimit _ _,
apply_instance,
let i : ((K ⋙ monad.comparison (adjunction.of_right_adjoint R)) ⋙ monad.forget _) ≅ K ⋙ R :=
functor.associator _ _ _ ≪≫
iso_whisker_left K (monad.comparison_forget (adjunction.of_right_adjoint R)),
apply category_theory.monad.forget_creates_colimit _,
{ dsimp,
refine preserves_colimit_of_iso_diagram _ i.symm },
{ dsimp,
refine preserves_colimit_of_iso_diagram _ (iso_whisker_right i (left_adjoint R ⋙ R)).symm },
end
/-- A monadic functor creates any colimits of shapes it preserves. -/
noncomputable
def monadic_creates_colimits_of_shape_of_preserves_colimits_of_shape (R : D ⥤ C)
[monadic_right_adjoint R] [preserves_colimits_of_shape J R] : creates_colimits_of_shape J R :=
begin
have : preserves_colimits_of_shape J (left_adjoint R ⋙ R),
{ apply category_theory.limits.comp_preserves_colimits_of_shape _ _,
apply (adjunction.left_adjoint_preserves_colimits (adjunction.of_right_adjoint R)).1,
apply_instance },
exactI ⟨λ K, monadic_creates_colimit_of_preserves_colimit _ _⟩,
end
/-- A monadic functor creates colimits if it preserves colimits. -/
noncomputable
def monadic_creates_colimits_of_preserves_colimits (R : D ⥤ C) [monadic_right_adjoint R]
[preserves_colimits_of_size.{v u} R] : creates_colimits_of_size.{v u} R :=
{ creates_colimits_of_shape := λ J 𝒥₁,
by exactI monadic_creates_colimits_of_shape_of_preserves_colimits_of_shape _ }
section
lemma has_limit_of_reflective (F : J ⥤ D) (R : D ⥤ C) [has_limit (F ⋙ R)] [reflective R] :
has_limit F :=
by { haveI := monadic_creates_limits.{v u} R, exact has_limit_of_created F R }
/-- If `C` has limits of shape `J` then any reflective subcategory has limits of shape `J`. -/
lemma has_limits_of_shape_of_reflective [has_limits_of_shape J C] (R : D ⥤ C) [reflective R] :
has_limits_of_shape J D :=
{ has_limit := λ F, has_limit_of_reflective F R }
/-- If `C` has limits then any reflective subcategory has limits. -/
lemma has_limits_of_reflective (R : D ⥤ C) [has_limits_of_size.{v u} C] [reflective R] :
has_limits_of_size.{v u} D :=
{ has_limits_of_shape := λ J 𝒥₁, by exactI has_limits_of_shape_of_reflective R }
/-- If `C` has colimits of shape `J` then any reflective subcategory has colimits of shape `J`. -/
lemma has_colimits_of_shape_of_reflective (R : D ⥤ C)
[reflective R] [has_colimits_of_shape J C] : has_colimits_of_shape J D :=
{ has_colimit := λ F,
begin
let c := (left_adjoint R).map_cocone (colimit.cocone (F ⋙ R)),
letI : preserves_colimits_of_shape J _ :=
(adjunction.of_right_adjoint R).left_adjoint_preserves_colimits.1,
let t : is_colimit c := is_colimit_of_preserves (left_adjoint R) (colimit.is_colimit _),
apply has_colimit.mk ⟨_, (is_colimit.precompose_inv_equiv _ _).symm t⟩,
apply (iso_whisker_left F (as_iso (adjunction.of_right_adjoint R).counit) : _) ≪≫ F.right_unitor,
end }
/-- If `C` has colimits then any reflective subcategory has colimits. -/
lemma has_colimits_of_reflective (R : D ⥤ C) [reflective R] [has_colimits_of_size.{v u} C] :
has_colimits_of_size.{v u} D :=
{ has_colimits_of_shape := λ J 𝒥, by exactI has_colimits_of_shape_of_reflective R }
/--
The reflector always preserves terminal objects. Note this in general doesn't apply to any other
limit.
-/
noncomputable def left_adjoint_preserves_terminal_of_reflective (R : D ⥤ C) [reflective R] :
preserves_limits_of_shape (discrete.{v} pempty) (left_adjoint R) :=
{ preserves_limit := λ K, let F := functor.empty.{v} D in
begin
apply preserves_limit_of_iso_diagram _ (functor.empty_ext (F ⋙ R) _),
fsplit, intros c h, haveI : has_limit (F ⋙ R) := ⟨⟨⟨c,h⟩⟩⟩,
haveI : has_limit F := has_limit_of_reflective F R,
apply is_limit_change_empty_cone D (limit.is_limit F),
apply (as_iso ((adjunction.of_right_adjoint R).counit.app _)).symm.trans,
{ apply (left_adjoint R).map_iso, letI := monadic_creates_limits.{v v} R,
let := (category_theory.preserves_limit_of_creates_limit_and_has_limit F R).preserves,
apply (this (limit.is_limit F)).cone_point_unique_up_to_iso h },
apply_instance,
end }
end
end category_theory
|
b1c47d318f4d8c248dbd9d14382c8d130eb203b8 | 19cc34575500ee2e3d4586c15544632aa07a8e66 | /src/number_theory/arithmetic_function.lean | ad3dd53b5c0ab6330c1645177a3eb8df106e5b75 | [
"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,918 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import algebra.big_operators.ring
import number_theory.divisors
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `arithmetic_function R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `is_multiplicative` when `x.coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `arithmetic_function R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y in divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
## Notation
The arithmetic functions `ζ` and `σ` have Greek letter names, which are localized notation in
the namespace `arithmetic_function`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open finset
open_locale big_operators
namespace nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `arithmetic_functions` is by
Dirichlet convolution. -/
structure arithmetic_function [has_zero R] :=
(to_fun : ℕ → R)
(map_zero' : to_fun 0 = 0)
variable {R}
namespace arithmetic_function
section has_zero
variable [has_zero R]
instance : has_coe_to_fun (arithmetic_function R) := ⟨λ _, ℕ → R, to_fun⟩
@[simp] lemma to_fun_eq (f : arithmetic_function R) : f.to_fun = f := rfl
@[simp]
lemma map_zero {f : arithmetic_function R} : f 0 = 0 := f.map_zero'
theorem coe_inj {f g : arithmetic_function R} : (f : ℕ → R) = g ↔ f = g :=
begin
split; intro h,
{ cases f,
cases g,
cases h,
refl },
{ rw h }
end
instance : has_zero (arithmetic_function R) := ⟨⟨λ _, 0, rfl⟩⟩
@[simp]
lemma zero_apply {x : ℕ} : (0 : arithmetic_function R) x = 0 := rfl
instance : inhabited (arithmetic_function R) := ⟨0⟩
@[ext] theorem ext ⦃f g : arithmetic_function R⦄ (h : ∀ x, f x = g x) : f = g :=
coe_inj.1 (funext h)
theorem ext_iff {f g : arithmetic_function R} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, λ h, ext h⟩
section has_one
variable [has_one R]
instance : has_one (arithmetic_function R) := ⟨⟨λ x, ite (x = 1) 1 0, rfl⟩⟩
@[simp]
lemma one_one : (1 : arithmetic_function R) 1 = 1 := rfl
@[simp]
lemma one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : arithmetic_function R) x = 0 := if_neg h
end has_one
end has_zero
instance nat_coe [semiring R] : has_coe (arithmetic_function ℕ) (arithmetic_function R) :=
⟨λ f, ⟨↑(f : ℕ → ℕ), by { transitivity ↑(f 0), refl, simp }⟩⟩
@[simp]
lemma nat_coe_apply [semiring R] {f : arithmetic_function ℕ} {x : ℕ} :
(f : arithmetic_function R) x = f x := rfl
instance int_coe [ring R] : has_coe (arithmetic_function ℤ) (arithmetic_function R) :=
⟨λ f, ⟨↑(f : ℕ → ℤ), by { transitivity ↑(f 0), refl, simp }⟩⟩
@[simp]
lemma int_coe_apply [ring R] {f : arithmetic_function ℤ} {x : ℕ} :
(f : arithmetic_function R) x = f x := rfl
@[simp]
lemma coe_coe [ring R] {f : arithmetic_function ℕ} :
((f : arithmetic_function ℤ) : arithmetic_function R) = f :=
by { ext, simp, }
section add_monoid
variable [add_monoid R]
instance : has_add (arithmetic_function R) := ⟨λ f g, ⟨λ n, f n + g n, by simp⟩⟩
@[simp]
lemma add_apply {f g : arithmetic_function R} {n : ℕ} : (f + g) n = f n + g n := rfl
instance : add_monoid (arithmetic_function R) :=
{ add_assoc := λ _ _ _, ext (λ _, add_assoc _ _ _),
zero_add := λ _, ext (λ _, zero_add _),
add_zero := λ _, ext (λ _, add_zero _),
.. arithmetic_function.has_zero,
.. arithmetic_function.has_add }
end add_monoid
instance [add_comm_monoid R] : add_comm_monoid (arithmetic_function R) :=
{ add_comm := λ _ _, ext (λ _, add_comm _ _),
.. arithmetic_function.add_monoid }
instance [add_group R] : add_group (arithmetic_function R) :=
{ neg := λ f, ⟨λ n, - f n, by simp⟩,
add_left_neg := λ _, ext (λ _, add_left_neg _),
.. arithmetic_function.add_monoid }
instance [add_comm_group R] : add_comm_group (arithmetic_function R) :=
{ .. arithmetic_function.add_comm_monoid,
.. arithmetic_function.add_group }
section dirichlet_ring
variable [semiring R]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : has_mul (arithmetic_function R) :=
⟨λ f g, ⟨λ n, ∑ x in divisors_antidiagonal n, f x.fst * g x.snd, by simp⟩⟩
@[simp]
lemma mul_apply {f g : arithmetic_function R} {n : ℕ} :
(f * g) n = ∑ x in divisors_antidiagonal n, f x.fst * g x.snd := rfl
instance : monoid (arithmetic_function R) :=
{ one_mul := λ f,
begin
ext,
rw mul_apply,
by_cases x0 : x = 0, {simp [x0]},
have h : {(1,x)} ⊆ divisors_antidiagonal x := by simp [x0],
rw ← sum_subset h, {simp},
intros y ymem ynmem,
have y1ne : y.fst ≠ 1,
{ intro con,
simp only [con, mem_divisors_antidiagonal, one_mul, ne.def] at ymem,
simp only [mem_singleton, prod.ext_iff] at ynmem,
tauto },
simp [y1ne],
end,
mul_one := λ f,
begin
ext,
rw mul_apply,
by_cases x0 : x = 0, {simp [x0]},
have h : {(x,1)} ⊆ divisors_antidiagonal x := by simp [x0],
rw ← sum_subset h, {simp},
intros y ymem ynmem,
have y2ne : y.snd ≠ 1,
{ intro con,
simp only [con, mem_divisors_antidiagonal, mul_one, ne.def] at ymem,
simp only [mem_singleton, prod.ext_iff] at ynmem,
tauto },
simp [y2ne],
end,
mul_assoc := λ f g h,
begin
ext n,
simp only [mul_apply],
have := @finset.sum_sigma (ℕ × ℕ) R _ _ (divisors_antidiagonal n)
(λ p, (divisors_antidiagonal p.1)) (λ x, f x.2.1 * g x.2.2 * h x.1.2),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl,
intros p hp, exact finset.sum_mul },
have := @finset.sum_sigma (ℕ × ℕ) R _ _ (divisors_antidiagonal n)
(λ p, (divisors_antidiagonal p.2)) (λ x, f x.1.1 * (g x.2.1 * h x.2.2)),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl, intros p hp, rw finset.mul_sum },
apply finset.sum_bij,
swap 5,
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, exact ⟨(k, l*j), (l, j)⟩ },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H,
simp only [finset.mem_sigma, mem_divisors_antidiagonal] at H ⊢, finish },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, simp only [mul_assoc] },
{ rintros ⟨⟨a,b⟩, ⟨c,d⟩⟩ ⟨⟨i,j⟩, ⟨k,l⟩⟩ H₁ H₂,
simp only [finset.mem_sigma, mem_divisors_antidiagonal,
and_imp, prod.mk.inj_iff, add_comm, heq_iff_eq] at H₁ H₂ ⊢,
finish },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, refine ⟨⟨(i*k, l), (i, k)⟩, _, _⟩;
{ simp only [finset.mem_sigma, mem_divisors_antidiagonal] at H ⊢, finish } }
end,
.. arithmetic_function.has_one,
.. arithmetic_function.has_mul }
instance : semiring (arithmetic_function R) :=
{ zero_mul := λ f, by { ext, simp, },
mul_zero := λ f, by { ext, simp, },
left_distrib := λ a b c, by { ext, simp [← sum_add_distrib, mul_add] },
right_distrib := λ a b c, by { ext, simp [← sum_add_distrib, add_mul] },
.. arithmetic_function.has_zero,
.. arithmetic_function.has_mul,
.. arithmetic_function.has_add,
.. arithmetic_function.add_comm_monoid,
.. arithmetic_function.monoid }
end dirichlet_ring
instance [comm_semiring R] : comm_semiring (arithmetic_function R) :=
{ mul_comm := λ f g, by { ext,
rw [mul_apply, ← map_swap_divisors_antidiagonal, sum_map],
simp [mul_comm] },
.. arithmetic_function.semiring }
instance [comm_ring R] : comm_ring (arithmetic_function R) :=
{ .. arithmetic_function.add_comm_group,
.. arithmetic_function.comm_semiring }
section zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann ζ. -/
def zeta [has_zero R] [has_one R] : arithmetic_function R :=
⟨λ x, ite (x = 0) 0 1, rfl⟩
localized "notation `ζ` := zeta" in arithmetic_function
@[simp]
lemma zeta_apply [has_zero R] [has_one R] {x : ℕ} : (ζ x : R) = if (x = 0) then 0 else 1 := rfl
lemma zeta_apply_ne [has_zero R] [has_one R] {x : ℕ} (h : x ≠ 0) : ζ x = (1 : R) := if_neg h
theorem zeta_mul_apply [semiring R] {f : arithmetic_function R} {x : ℕ} :
(ζ * f) x = ∑ i in divisors x, f i :=
begin
rw mul_apply,
transitivity ∑ i in divisors_antidiagonal x, f i.snd,
{ apply sum_congr rfl,
intros i hi,
rcases mem_divisors_antidiagonal.1 hi with ⟨rfl, h⟩,
rw [zeta_apply_ne (left_ne_zero_of_mul h), one_mul] },
{ apply sum_bij (λ i h, prod.snd i),
{ rintros ⟨a, b⟩ h, simp [snd_mem_divisors_of_mem_antidiagonal h] },
{ rintros ⟨a, b⟩ h, refl },
{ rintros ⟨a1, b1⟩ ⟨a2, b2⟩ h1 h2 h,
dsimp at h,
rw h at *,
rw mem_divisors_antidiagonal at *,
ext, swap, {refl},
simp only [prod.fst, prod.snd] at *,
apply nat.eq_of_mul_eq_mul_right _ (eq.trans h1.1 h2.1.symm),
rcases h1 with ⟨rfl, h⟩,
apply nat.pos_of_ne_zero (right_ne_zero_of_mul h) },
{ intros a ha,
rcases mem_divisors.1 ha with ⟨⟨b, rfl⟩, ne0⟩,
use (b, a),
simp [ne0, mul_comm] } }
end
theorem mul_zeta_apply [semiring R] {f : arithmetic_function R} {x : ℕ} :
(f * ζ) x = ∑ i in divisors x, f i :=
begin
apply opposite.op_injective,
rw [← opposite.coe_op_add_hom, add_monoid_hom.map_sum],
convert @zeta_mul_apply Rᵒᵖ _ { to_fun := opposite.op_add_hom ∘ f, map_zero' := by simp} x,
rw [mul_apply, mul_apply, add_monoid_hom.map_sum],
conv_lhs { rw ← map_swap_divisors_antidiagonal, },
rw sum_map,
apply sum_congr rfl,
intros y hy,
by_cases h1 : y.fst = 0,
{ simp [function.comp_apply, h1] },
{ simp only [h1, mul_one, one_mul, prod.fst_swap, function.embedding.coe_fn_mk, prod.snd_swap,
if_false, zeta_apply, opposite.coe_op_add_hom],
refl }
end
end zeta
open_locale arithmetic_function
section pmul
/-- This is the pointwise product of `arithmetic_function`s. -/
def pmul [mul_zero_class R] (f g : arithmetic_function R) :
arithmetic_function R :=
⟨λ x, f x * g x, by simp⟩
@[simp]
lemma pmul_apply [mul_zero_class R] {f g : arithmetic_function R} {x : ℕ} :
f.pmul g x = f x * g x := rfl
lemma pmul_comm [comm_monoid_with_zero R] (f g : arithmetic_function R) :
f.pmul g = g.pmul f :=
by { ext, simp [mul_comm] }
variable [monoid_with_zero R]
@[simp]
lemma pmul_zeta (f : arithmetic_function R) : f.pmul ζ = f :=
begin
ext x,
cases x;
simp [nat.succ_ne_zero],
end
@[simp]
lemma zeta_pmul (f : arithmetic_function R) : (ζ).pmul f = f :=
begin
ext x,
cases x;
simp [nat.succ_ne_zero],
end
/-- This is the pointwise power of `arithmetic_function`s. -/
def ppow (f : arithmetic_function R) (k : ℕ) :
arithmetic_function R :=
if h0 : k = 0 then ζ else ⟨λ x, (f x) ^ k,
by { rw [map_zero], exact zero_pow (nat.pos_of_ne_zero h0) }⟩
@[simp]
lemma ppow_zero {f : arithmetic_function R} : f.ppow 0 = ζ :=
by rw [ppow, dif_pos rfl]
@[simp]
lemma ppow_apply {f : arithmetic_function R} {k x : ℕ} (kpos : 0 < k) :
f.ppow k x = (f x) ^ k :=
by { rw [ppow, dif_neg (ne_of_gt kpos)], refl }
lemma ppow_succ {f : arithmetic_function R} {k : ℕ} :
f.ppow (k + 1) = f.pmul (f.ppow k) :=
begin
ext x,
rw [ppow_apply (nat.succ_pos k), pow_succ],
induction k; simp,
end
lemma ppow_succ' {f : arithmetic_function R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f :=
begin
ext x,
rw [ppow_apply (nat.succ_pos k), pow_succ'],
induction k; simp,
end
end pmul
/-- Multiplicative functions -/
def is_multiplicative [monoid_with_zero R] (f : arithmetic_function R) : Prop :=
f 1 = 1 ∧ (∀ {m n : ℕ}, m.coprime n → f (m * n) = f m * f n)
namespace is_multiplicative
section monoid_with_zero
variable [monoid_with_zero R]
@[simp]
lemma map_one {f : arithmetic_function R} (h : f.is_multiplicative) : f 1 = 1 :=
h.1
@[simp]
lemma map_mul_of_coprime {f : arithmetic_function R} (hf : f.is_multiplicative)
{m n : ℕ} (h : m.coprime n) : f (m * n) = f m * f n :=
hf.2 h
end monoid_with_zero
lemma nat_cast {f : arithmetic_function ℕ} [semiring R] (h : f.is_multiplicative) :
is_multiplicative (f : arithmetic_function R) :=
⟨by simp [h], λ m n cop, by simp [cop, h]⟩
lemma int_cast {f : arithmetic_function ℤ} [ring R] (h : f.is_multiplicative) :
is_multiplicative (f : arithmetic_function R) :=
⟨by simp [h], λ m n cop, by simp [cop, h]⟩
lemma mul [comm_semiring R] {f g : arithmetic_function R}
(hf : f.is_multiplicative) (hg : g.is_multiplicative) :
is_multiplicative (f * g) :=
⟨by { simp [hf, hg], }, begin
simp only [mul_apply],
intros m n cop,
rw sum_mul_sum,
symmetry,
apply sum_bij (λ (x : (ℕ × ℕ) × ℕ × ℕ) h, (x.1.1 * x.2.1, x.1.2 * x.2.2)),
{ rintros ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩,
simp only [mem_divisors_antidiagonal, nat.mul_eq_zero, ne.def],
split, {ring},
rw nat.mul_eq_zero at *,
apply not_or ha hb },
{ rintros ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩,
dsimp only,
rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,
hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right],
ring, },
{ rintros ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hab hcd h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at hab,
rcases hab with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at hcd,
simp only [prod.mk.inj_iff] at h,
ext; dsimp only,
{ transitivity nat.gcd (a1 * a2) (a1 * b1),
{ rw [nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.1.1, h.1, nat.gcd_mul_left,
cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] } },
{ transitivity nat.gcd (a1 * a2) (a2 * b2),
{ rw [mul_comm, nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,
mul_one] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.1.1, h.2, mul_comm, nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] } },
{ transitivity nat.gcd (b1 * b2) (a1 * b1),
{ rw [mul_comm, nat.gcd_mul_right,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.2.1, h.1, mul_comm c1 d1, nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one] } },
{ transitivity nat.gcd (b1 * b2) (a2 * b2),
{ rw [nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] },
{ rw [← hcd.1.1, ← hcd.2.1] at cop,
rw [← hcd.2.1, h.2, nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] } } },
{ rintros ⟨b1, b2⟩ h,
simp only [mem_divisors_antidiagonal, ne.def, mem_product] at h,
use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n)),
simp only [exists_prop, prod.mk.inj_iff, ne.def, mem_product, mem_divisors_antidiagonal],
rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,
nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _],
{ rw [nat.mul_eq_zero, decidable.not_or_iff_and_not] at h, simp [h.2.1, h.2.2] },
rw [mul_comm n m, h.1] }
end⟩
lemma pmul [comm_semiring R] {f g : arithmetic_function R}
(hf : f.is_multiplicative) (hg : g.is_multiplicative) :
is_multiplicative (f.pmul g) :=
⟨by { simp [hf, hg], }, λ m n cop, begin
simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop],
ring,
end⟩
end is_multiplicative
section special_functions
/-- The identity on `ℕ` as an `arithmetic_function`. -/
def id : arithmetic_function ℕ := ⟨id, rfl⟩
@[simp]
lemma id_apply {x : ℕ} : id x = x := rfl
/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/
def pow (k : ℕ) : arithmetic_function ℕ := id.ppow k
@[simp]
lemma pow_apply {k n : ℕ} : pow k n = if (k = 0 ∧ n = 0) then 0 else n ^ k :=
begin
cases k,
{ simp [pow] },
simp [pow, (ne_of_lt (nat.succ_pos k)).symm],
end
/-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/
def sigma (k : ℕ) : arithmetic_function ℕ :=
⟨λ n, ∑ d in divisors n, d ^ k, by simp⟩
localized "notation `σ` := sigma" in arithmetic_function
@[simp]
lemma sigma_apply {k n : ℕ} : σ k n = ∑ d in divisors n, d ^ k := rfl
lemma zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k :=
begin
ext,
rw [sigma, zeta_mul_apply],
apply sum_congr rfl,
intros x hx,
rw [pow_apply, if_neg (not_and_of_not_right _ _)],
contrapose! hx,
simp [hx],
end
lemma is_multiplicative_zeta [semiring R] : is_multiplicative (ζ : arithmetic_function R) :=
⟨by simp, λ m n cop, begin
cases m, {simp},
cases n, {simp},
rw [zeta_apply_ne (mul_ne_zero _ _), zeta_apply_ne,
zeta_apply_ne, mul_one],
repeat { apply nat.succ_ne_zero },
end⟩
lemma is_multiplicative_id : is_multiplicative arithmetic_function.id :=
⟨rfl, λ _ _ _, rfl⟩
lemma is_multiplicative.ppow [comm_semiring R] {f : arithmetic_function R}
(hf : f.is_multiplicative) {k : ℕ} :
is_multiplicative (f.ppow k) :=
begin
induction k with k hi,
{ exact is_multiplicative_zeta },
{ rw ppow_succ,
apply hf.pmul hi },
end
lemma is_multiplicative_pow {k : ℕ} : is_multiplicative (pow k) :=
is_multiplicative_id.ppow
lemma is_multiplicative_sigma {k : ℕ} :
is_multiplicative (sigma k) :=
begin
rw [← zeta_mul_pow_eq_sigma],
apply ((is_multiplicative_zeta).mul is_multiplicative_pow)
end
end special_functions
end arithmetic_function
end nat
|
5e6c8c5d49e5d0586af71efb7fb6d82409035bd0 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/pp_no_proofs.lean | 8899794a56a8f189f6a9de05917b447458af6ffa | [
"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 | 392 | lean | --
open nat
constants (P : ∀ {t:true}, ℕ → Prop) (P0 : @P trivial 0)
(Ps : ∀ {n}, @P trivial n → @P trivial (succ n))
(f : Π {n}, @P trivial n → ℕ)
noncomputable definition messy := f (Ps (Ps (Ps (Ps (Ps (Ps P0))))))
#reduce messy
set_option pp.proofs false
#reduce messy
set_option pp.implicit true
#reduce messy
set_option pp.proofs true
#reduce messy
|
5abbd85c9b718bd727d6195bafdb2091a37e0fa0 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/sums/default.lean | bc466880ac5de4a49561acb67a7ac496f70f9758 | [
"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 | 39 | lean | import category_theory.sums.associator
|
4797008664ed6a2bf219edef5e08cf1101ba02f3 | 367134ba5a65885e863bdc4507601606690974c1 | /src/group_theory/group_action/basic.lean | fa82ace2bc3d5f8b1c031ee3de539a77f4b67b9a | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 7,617 | 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 group_theory.group_action.defs
import group_theory.group_action.group
import group_theory.coset
/-!
# Basic properties of group actions
-/
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
open_locale big_operators
open function
namespace mul_action
variables (α) [monoid α] [mul_action α β]
/-- The orbit of an element under an action. -/
def orbit (b : β) := set.range (λ x : α, x • b)
variable {α}
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]⟩
variable (α)
/-- The stabilizer of an element under an action, i.e. what sends the element to itself. Note
that this is a set: for the group stabilizer see `stabilizer`. -/
def stabilizer_carrier (b : β) : set α :=
{x : α | x • b = b}
variable {α}
@[simp] lemma mem_stabilizer_iff {b : β} {x : α} :
x ∈ stabilizer_carrier α b ↔ x • b = b := iff.rfl
variables (α) (β)
/-- The set of elements fixed under the whole action. -/
def fixed_points : set β := {b : β | ∀ x : α, x • b = b}
/-- `fixed_by g` is the subfield of elements fixed by `g`. -/
def fixed_by (g : α) : set β :=
{ x | g • x = x }
theorem fixed_eq_Inter_fixed_by : fixed_points α β = ⋂ g : α, fixed_by α β g :=
set.ext $ λ x, ⟨λ hx, set.mem_Inter.2 $ λ g, hx g, λ hx g, by exact (set.mem_Inter.1 hx g : _)⟩
variables {α} (β)
@[simp] lemma mem_fixed_points {b : β} :
b ∈ fixed_points α β ↔ ∀ x : α, x • b = b := iff.rfl
@[simp] lemma mem_fixed_by {g : α} {b : β} :
b ∈ fixed_by α β g ↔ g • 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 _ _))⟩
variables (α) {β}
/-- The stabilizer of a point `b` as a submonoid of `α`. -/
def stabilizer.submonoid (b : β) : submonoid α :=
{ carrier := stabilizer_carrier α 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
variable (α)
variables [group α] [mul_action α β]
/-- The stabilizer of an element under an action, i.e. what sends the element to itself.
A subgroup. -/
def stabilizer (b : β) : subgroup α :=
{ inv_mem' := λ a (ha : a • b = b), show a⁻¹ • b = b, by rw [inv_smul_eq_iff, ha]
..stabilizer.submonoid α b }
variables {α} {β}
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]}⟩⟩)⟩
variables (α) {β}
/-- The stabilizer of a point `b` as a subgroup of `α`. -/
def stabilizer.subgroup (b : β) : subgroup α :=
{ 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],
..stabilizer.submonoid α b }
variables {β}
@[simp] lemma mem_orbit_smul (g : α) (a : β) : a ∈ orbit α (g • a) :=
⟨g⁻¹, by simp⟩
@[simp] lemma smul_mem_orbit_smul (g h : α) (a : β) : g • a ∈ orbit α (h • a) :=
⟨g * h⁻¹, by simp [mul_smul]⟩
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 mul_action
/-- Action on left cosets. -/
def mul_left_cosets (H : subgroup α)
(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 quotient (H : subgroup α) : mul_action α (quotient H) :=
{ smul := mul_left_cosets H,
one_smul := λ a, quotient.induction_on' a (λ a, quotient_group.eq.2
(by simp [subgroup.one_mem])),
mul_smul := λ x y a, quotient.induction_on' a (λ a, quotient_group.eq.2
(by simp [mul_inv_rev, subgroup.one_mem, mul_assoc])) }
@[simp] lemma quotient.smul_mk (H : subgroup α) (a x : α) :
(a • quotient_group.mk x : quotient_group.quotient H) = quotient_group.mk (a * x) := rfl
@[simp] lemma quotient.smul_coe {α : Type*} [comm_group α] (H : subgroup α) (a x : α) :
(a • x : quotient_group.quotient H) = ↑(a * x) := rfl
instance mul_left_cosets_comp_subtype_val (H I : subgroup α) :
mul_action I (quotient H) :=
mul_action.comp_hom (quotient H) (subgroup.subtype I)
variables (α) {β} (x : β)
/-- The canonical map from the quotient of the stabilizer to the set. -/
def of_quotient_stabilizer (g : quotient (mul_action.stabilizer α x)) : β :=
quotient.lift_on' g (•x) $ λ g1 g2 H,
calc g1 • x
= g1 • (g1⁻¹ * g2) • x : congr_arg _ H.symm
... = g2 • x : by rw [smul_smul, mul_inv_cancel_left]
@[simp] theorem of_quotient_stabilizer_mk (g : α) :
of_quotient_stabilizer α x (quotient_group.mk g) = g • x :=
rfl
theorem of_quotient_stabilizer_mem_orbit (g) : of_quotient_stabilizer α x g ∈ orbit α x :=
quotient.induction_on' g $ λ g, ⟨g, rfl⟩
theorem of_quotient_stabilizer_smul (g : α) (g' : quotient (mul_action.stabilizer α x)) :
of_quotient_stabilizer α x (g • g') = g • of_quotient_stabilizer α x g' :=
quotient.induction_on' g' $ λ _, mul_smul _ _ _
theorem injective_of_quotient_stabilizer : function.injective (of_quotient_stabilizer α x) :=
λ y₁ y₂, quotient.induction_on₂' y₁ y₂ $ λ g₁ g₂ (H : g₁ • x = g₂ • x), quotient.sound' $
show (g₁⁻¹ * g₂) • x = x, by rw [mul_smul, ← H, inv_smul_smul]
/-- Orbit-stabilizer theorem. -/
noncomputable def orbit_equiv_quotient_stabilizer (b : β) :
orbit α b ≃ quotient (stabilizer α b) :=
equiv.symm $ equiv.of_bijective
(λ g, ⟨of_quotient_stabilizer α b g, of_quotient_stabilizer_mem_orbit α b g⟩)
⟨λ x y hxy, injective_of_quotient_stabilizer α b (by convert congr_arg subtype.val hxy),
λ ⟨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 mul_action
section
variables [monoid α] [add_monoid β] [distrib_mul_action α β]
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 • ∑ x in s, f x = ∑ x in s, r • f x :=
(const_smul_hom β r).map_sum f s
end
|
aa382f0b3db9f89f56cf382af3e710b9732609d4 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/list/lattice.lean | 5cc1b81d6474ab8afec94612ebc03896063a0153 | [
"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 | 11,457 | 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, Floris van Doorn, Mario Carneiro,
Scott Morrison
-/
import data.list.count
import data.list.infix
/-!
# Lattice structure of lists
This files prove basic properties about `list.disjoint`, `list.union`, `list.inter` and
`list.bag_inter`, which are defined in core Lean and `data.list.defs`.
`l₁ ∪ l₂` is the list where all elements of `l₁` have been inserted in `l₂` in order. For example,
`[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [1, 2, 4, 3, 3, 0]`
`l₁ ∩ l₂` is the list of elements of `l₁` in order which are in `l₂`. For example,
`[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [0, 0, 3]`
`bag_inter l₁ l₂` is the list of elements that are in both `l₁` and `l₂`, counted with multiplicity
and in the order they appear in `l₁`. As opposed to `list.inter`, `list.bag_inter` copes well with
multiplicity. For example,
`bag_inter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1]`
-/
open nat
namespace list
variables {α : Type*} {l l₁ l₂ : list α} {p : α → Prop} {a : α}
/-! ### `disjoint` -/
section disjoint
lemma disjoint.symm (d : disjoint l₁ l₂) : disjoint l₂ l₁ := λ a i₂ i₁, d i₁ i₂
lemma disjoint_comm : disjoint l₁ l₂ ↔ disjoint l₂ l₁ := ⟨disjoint.symm, disjoint.symm⟩
lemma disjoint_left : disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₁ → a ∉ l₂ := iff.rfl
lemma disjoint_right : disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₂ → a ∉ l₁ := disjoint_comm
lemma disjoint_iff_ne : disjoint l₁ l₂ ↔ ∀ a ∈ l₁, ∀ b ∈ l₂, a ≠ b :=
by simp only [disjoint_left, imp_not_comm, forall_eq']
lemma disjoint_of_subset_left (ss : l₁ ⊆ l) (d : disjoint l l₂) : disjoint l₁ l₂ := λ x m, d (ss m)
lemma disjoint_of_subset_right (ss : l₂ ⊆ l) (d : disjoint l₁ l) : disjoint l₁ l₂ :=
λ x m m₁, d m (ss m₁)
lemma disjoint_of_disjoint_cons_left {l₁ l₂} : disjoint (a :: l₁) l₂ → disjoint l₁ l₂ :=
disjoint_of_subset_left (list.subset_cons _ _)
lemma disjoint_of_disjoint_cons_right {l₁ l₂} : disjoint l₁ (a :: l₂) → disjoint l₁ l₂ :=
disjoint_of_subset_right (list.subset_cons _ _)
@[simp] lemma disjoint_nil_left (l : list α) : disjoint [] l := λ a, (not_mem_nil a).elim
@[simp] lemma disjoint_nil_right (l : list α) : disjoint l [] :=
by { rw disjoint_comm, exact disjoint_nil_left _ }
@[simp, priority 1100] lemma singleton_disjoint : disjoint [a] l ↔ a ∉ l :=
by { simp only [disjoint, mem_singleton, forall_eq], refl }
@[simp, priority 1100] lemma disjoint_singleton : disjoint l [a] ↔ a ∉ l :=
by rw [disjoint_comm, singleton_disjoint]
@[simp] lemma disjoint_append_left : disjoint (l₁ ++ l₂) l ↔ disjoint l₁ l ∧ disjoint l₂ l :=
by simp only [disjoint, mem_append, or_imp_distrib, forall_and_distrib]
@[simp] lemma disjoint_append_right : disjoint l (l₁ ++ l₂) ↔ disjoint l l₁ ∧ disjoint l l₂ :=
disjoint_comm.trans $ by simp only [disjoint_comm, disjoint_append_left]
@[simp] lemma disjoint_cons_left : disjoint (a :: l₁) l₂ ↔ a ∉ l₂ ∧ disjoint l₁ l₂ :=
(@disjoint_append_left _ l₂ [a] l₁).trans $ by simp only [singleton_disjoint]
@[simp] lemma disjoint_cons_right : disjoint l₁ (a :: l₂) ↔ a ∉ l₁ ∧ disjoint l₁ l₂ :=
disjoint_comm.trans $ by simp only [disjoint_comm, disjoint_cons_left]
lemma disjoint_of_disjoint_append_left_left (d : disjoint (l₁ ++ l₂) l) : disjoint l₁ l :=
(disjoint_append_left.1 d).1
lemma disjoint_of_disjoint_append_left_right (d : disjoint (l₁ ++ l₂) l) : disjoint l₂ l :=
(disjoint_append_left.1 d).2
lemma disjoint_of_disjoint_append_right_left (d : disjoint l (l₁ ++ l₂)) : disjoint l l₁ :=
(disjoint_append_right.1 d).1
lemma disjoint_of_disjoint_append_right_right (d : disjoint l (l₁ ++ l₂)) : disjoint l l₂ :=
(disjoint_append_right.1 d).2
lemma disjoint_take_drop {m n : ℕ} (hl : l.nodup) (h : m ≤ n) : disjoint (l.take m) (l.drop n) :=
begin
induction l generalizing m n,
case list.nil : m n
{ simp },
case list.cons : x xs xs_ih m n
{ cases m; cases n; simp only [disjoint_cons_left, mem_cons_iff, disjoint_cons_right, drop,
true_or, eq_self_iff_true, not_true, false_and,
disjoint_nil_left, take],
{ cases h },
cases hl with _ _ h₀ h₁, split,
{ intro h, exact h₀ _ (mem_of_mem_drop h) rfl, },
solve_by_elim [le_of_succ_le_succ] { max_depth := 4 } },
end
end disjoint
variable [decidable_eq α]
/-! ### `union` -/
section union
@[simp] lemma nil_union (l : list α) : [] ∪ l = l := rfl
@[simp] lemma cons_union (l₁ l₂ : list α) (a : α) : a :: l₁ ∪ l₂ = insert a (l₁ ∪ l₂) := rfl
@[simp] lemma mem_union : a ∈ l₁ ∪ l₂ ↔ a ∈ l₁ ∨ a ∈ l₂ :=
by induction l₁; simp only [nil_union, not_mem_nil, false_or, cons_union, mem_insert_iff,
mem_cons_iff, or_assoc, *]
lemma mem_union_left (h : a ∈ l₁) (l₂ : list α) : a ∈ l₁ ∪ l₂ := mem_union.2 (or.inl h)
lemma mem_union_right (l₁ : list α) (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ := mem_union.2 (or.inr h)
lemma sublist_suffix_of_union : ∀ l₁ l₂ : list α, ∃ t, t <+ l₁ ∧ t ++ l₂ = l₁ ∪ l₂
| [] l₂ := ⟨[], by refl, rfl⟩
| (a :: l₁) l₂ := let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂ in
if h : a ∈ l₁ ∪ l₂
then ⟨t, sublist_cons_of_sublist _ s, by simp only [e, cons_union, insert_of_mem h]⟩
else ⟨a::t, s.cons_cons _, by simp only [cons_append, cons_union, e, insert_of_not_mem h];
split; refl⟩
lemma suffix_union_right (l₁ l₂ : list α) : l₂ <:+ l₁ ∪ l₂ :=
(sublist_suffix_of_union l₁ l₂).imp (λ a, and.right)
lemma union_sublist_append (l₁ l₂ : list α) : l₁ ∪ l₂ <+ l₁ ++ l₂ :=
let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂ in
e ▸ (append_sublist_append_right _).2 s
lemma forall_mem_union : (∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ (∀ x ∈ l₂, p x) :=
by simp only [mem_union, or_imp_distrib, forall_and_distrib]
lemma forall_mem_of_forall_mem_union_left (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x :=
(forall_mem_union.1 h).1
lemma forall_mem_of_forall_mem_union_right
(h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x :=
(forall_mem_union.1 h).2
end union
/-! ### `inter` -/
section inter
@[simp] lemma inter_nil (l : list α) : [] ∩ l = [] := rfl
@[simp] lemma inter_cons_of_mem (l₁ : list α) (h : a ∈ l₂) :
(a :: l₁) ∩ l₂ = a :: (l₁ ∩ l₂) :=
if_pos h
@[simp] lemma inter_cons_of_not_mem (l₁ : list α) (h : a ∉ l₂) :
(a :: l₁) ∩ l₂ = l₁ ∩ l₂ :=
if_neg h
lemma mem_of_mem_inter_left : a ∈ l₁ ∩ l₂ → a ∈ l₁ := mem_of_mem_filter
lemma mem_of_mem_inter_right : a ∈ l₁ ∩ l₂ → a ∈ l₂ := of_mem_filter
lemma mem_inter_of_mem_of_mem : a ∈ l₁ → a ∈ l₂ → a ∈ l₁ ∩ l₂ :=
mem_filter_of_mem
@[simp] lemma mem_inter : a ∈ l₁ ∩ l₂ ↔ a ∈ l₁ ∧ a ∈ l₂ := mem_filter
lemma inter_subset_left (l₁ l₂ : list α) : l₁ ∩ l₂ ⊆ l₁ := filter_subset _
lemma inter_subset_right (l₁ l₂ : list α) : l₁ ∩ l₂ ⊆ l₂ := λ a, mem_of_mem_inter_right
lemma subset_inter {l l₁ l₂ : list α} (h₁ : l ⊆ l₁) (h₂ : l ⊆ l₂) : l ⊆ l₁ ∩ l₂ :=
λ a h, mem_inter.2 ⟨h₁ h, h₂ h⟩
lemma inter_eq_nil_iff_disjoint : l₁ ∩ l₂ = [] ↔ disjoint l₁ l₂ :=
by { simp only [eq_nil_iff_forall_not_mem, mem_inter, not_and], refl }
lemma forall_mem_inter_of_forall_left (h : ∀ x ∈ l₁, p x)
(l₂ : list α) :
∀ x, x ∈ l₁ ∩ l₂ → p x :=
ball.imp_left (λ x, mem_of_mem_inter_left) h
lemma forall_mem_inter_of_forall_right (l₁ : list α)
(h : ∀ x ∈ l₂, p x) :
∀ x, x ∈ l₁ ∩ l₂ → p x :=
ball.imp_left (λ x, mem_of_mem_inter_right) h
@[simp] lemma inter_reverse {xs ys : list α} : xs.inter ys.reverse = xs.inter ys :=
by simp only [list.inter, mem_reverse]
end inter
/-! ### `bag_inter` -/
section bag_inter
@[simp] lemma nil_bag_inter (l : list α) : [].bag_inter l = [] :=
by cases l; refl
@[simp] lemma bag_inter_nil (l : list α) : l.bag_inter [] = [] :=
by cases l; refl
@[simp] lemma cons_bag_inter_of_pos (l₁ : list α) (h : a ∈ l₂) :
(a :: l₁).bag_inter l₂ = a :: l₁.bag_inter (l₂.erase a) :=
by cases l₂; exact if_pos h
@[simp] lemma cons_bag_inter_of_neg (l₁ : list α) (h : a ∉ l₂) :
(a :: l₁).bag_inter l₂ = l₁.bag_inter l₂ :=
begin
cases l₂, {simp only [bag_inter_nil]},
simp only [erase_of_not_mem h, list.bag_inter, if_neg h]
end
@[simp] lemma mem_bag_inter {a : α} : ∀ {l₁ l₂ : list α}, a ∈ l₁.bag_inter l₂ ↔ a ∈ l₁ ∧ a ∈ l₂
| [] l₂ := by simp only [nil_bag_inter, not_mem_nil, false_and]
| (b :: l₁) l₂ := begin
by_cases b ∈ l₂,
{ rw [cons_bag_inter_of_pos _ h, mem_cons_iff, mem_cons_iff, mem_bag_inter],
by_cases ba : a = b,
{ simp only [ba, h, eq_self_iff_true, true_or, true_and] },
{ simp only [mem_erase_of_ne ba, ba, false_or] } },
{ rw [cons_bag_inter_of_neg _ h, mem_bag_inter, mem_cons_iff, or_and_distrib_right],
symmetry, apply or_iff_right_of_imp,
rintro ⟨rfl, h'⟩, exact h.elim h' }
end
@[simp] lemma count_bag_inter {a : α} :
∀ {l₁ l₂ : list α}, count a (l₁.bag_inter l₂) = min (count a l₁) (count a l₂)
| [] l₂ := by simp
| l₁ [] := by simp
| (h₁ :: l₁) (h₂ :: l₂) :=
begin
simp only [list.bag_inter, list.mem_cons_iff],
by_cases p₁ : h₂ = h₁; by_cases p₂ : h₁ = a,
{ simp only [p₁, p₂, count_bag_inter, min_succ_succ, erase_cons_head, if_true, mem_cons_iff,
count_cons_self, true_or, eq_self_iff_true] },
{ simp only [p₁, ne.symm p₂, count_bag_inter, count_cons, erase_cons_head, if_true, mem_cons_iff,
true_or, eq_self_iff_true, if_false] },
{ rw p₂ at p₁,
by_cases p₃ : a ∈ l₂,
{ simp only [p₁, ne.symm p₁, p₂, p₃, erase_cons, count_bag_inter, eq.symm (min_succ_succ _ _),
succ_pred_eq_of_pos (count_pos.2 p₃), if_true, mem_cons_iff, false_or,
count_cons_self, eq_self_iff_true, if_false, ne.def, not_false_iff,
count_erase_self, list.count_cons_of_ne] },
{ simp [ne.symm p₁, p₂, p₃] } },
{ by_cases p₄ : h₁ ∈ l₂; simp only [ne.symm p₁, ne.symm p₂, p₄, count_bag_inter, if_true,
if_false, mem_cons_iff, false_or, eq_self_iff_true, ne.def, not_false_iff,count_erase_of_ne,
count_cons_of_ne] }
end
lemma bag_inter_sublist_left : ∀ l₁ l₂ : list α, l₁.bag_inter l₂ <+ l₁
| [] l₂ := by simp [nil_sublist]
| (b :: l₁) l₂ := begin
by_cases b ∈ l₂; simp [h],
{ exact (bag_inter_sublist_left _ _).cons_cons _ },
{ apply sublist_cons_of_sublist, apply bag_inter_sublist_left }
end
lemma bag_inter_nil_iff_inter_nil : ∀ l₁ l₂ : list α, l₁.bag_inter l₂ = [] ↔ l₁ ∩ l₂ = []
| [] l₂ := by simp
| (b :: l₁) l₂ :=
begin
by_cases h : b ∈ l₂; simp [h],
exact bag_inter_nil_iff_inter_nil l₁ l₂
end
end bag_inter
end list
|
7d0eda2da7e206e77e723845dc6fc8c14ac3ec01 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/linear_algebra/linear_pmap.lean | a20d1d6a41afbf451481deb185e99c8343ddf7b5 | [
"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 | 30,111 | lean | /-
Copyright (c) 2020 Yury Kudryashov All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Moritz Doll
-/
import linear_algebra.basic
import linear_algebra.prod
/-!
# Partially defined linear maps
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
A `linear_pmap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`.
We define a `semilattice_inf` with `order_bot` instance on this this, and define three operations:
* `mk_span_singleton` defines a partial linear map defined on the span of a singleton.
* `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their
domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that
extends both `f` and `g`.
* `Sup` takes a `directed_on (≤)` set of partial linear maps, and returns the unique
partial linear map on the `Sup` of their domains that extends all these maps.
Moreover, we define
* `linear_pmap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`.
Partially defined maps are currently used in `mathlib` to prove Hahn-Banach theorem
and its variations. Namely, `linear_pmap.Sup` implies that every chain of `linear_pmap`s
is bounded above.
They are also the basis for the theory of unbounded operators.
-/
open set
universes u v w
/-- A `linear_pmap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/
structure linear_pmap (R : Type u) [ring R] (E : Type v) [add_comm_group E] [module R E]
(F : Type w) [add_comm_group F] [module R F] :=
(domain : submodule R E)
(to_fun : domain →ₗ[R] F)
notation E ` →ₗ.[`:25 R:25 `] `:0 F:0 := linear_pmap R E F
variables {R : Type*} [ring R] {E : Type*} [add_comm_group E] [module R E]
{F : Type*} [add_comm_group F] [module R F]
{G : Type*} [add_comm_group G] [module R G]
namespace linear_pmap
open submodule
instance : has_coe_to_fun (E →ₗ.[R] F) (λ f : E →ₗ.[R] F, f.domain → F) :=
⟨λ f, f.to_fun⟩
@[simp] lemma to_fun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) :
f.to_fun x = f x := rfl
@[ext] lemma ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain)
(h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (h : (x:E) = y), f x = g y) : f = g :=
begin
rcases f with ⟨f_dom, f⟩,
rcases g with ⟨g_dom, g⟩,
obtain rfl : f_dom = g_dom := h,
obtain rfl : f = g := linear_map.ext (λ x, h' rfl),
refl,
end
@[simp] lemma map_zero (f : E →ₗ.[R] F) : f 0 = 0 := f.to_fun.map_zero
lemma ext_iff {f g : E →ₗ.[R] F} :
f = g ↔
∃ (domain_eq : f.domain = g.domain),
∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (h : (x:E) = y), f x = g y :=
⟨λ EQ, EQ ▸ ⟨rfl, λ x y h, by { congr, exact_mod_cast h }⟩, λ ⟨deq, feq⟩, ext deq feq⟩
lemma ext' {s : submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g := h ▸ rfl
lemma map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y :=
f.to_fun.map_add x y
lemma map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x :=
f.to_fun.map_neg x
lemma map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y :=
f.to_fun.map_sub x y
lemma map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x :=
f.to_fun.map_smul c x
@[simp] lemma mk_apply (p : submodule R E) (f : p →ₗ[R] F) (x : p) :
mk p f x = f x := rfl
/-- The unique `linear_pmap` on `R ∙ x` that sends `x` to `y`. This version works for modules
over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/
noncomputable def mk_span_singleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) :
E →ₗ.[R] F :=
{ domain := R ∙ x,
to_fun :=
have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y,
{ intros c₁ c₂ h,
rw [← sub_eq_zero, ← sub_smul] at h ⊢,
exact H _ h },
{ to_fun := λ z, (classical.some (mem_span_singleton.1 z.prop) • y),
map_add' := λ y z, begin
rw [← add_smul],
apply H,
simp only [add_smul, sub_smul, classical.some_spec (mem_span_singleton.1 _)],
apply coe_add
end,
map_smul' := λ c z, begin
rw [smul_smul],
apply H,
simp only [mul_smul, classical.some_spec (mem_span_singleton.1 _)],
apply coe_smul
end } }
@[simp] lemma domain_mk_span_singleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) :
(mk_span_singleton' x y H).domain = R ∙ x := rfl
@[simp] lemma mk_span_singleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0)
(c : R) (h) :
mk_span_singleton' x y H ⟨c • x, h⟩ = c • y :=
begin
dsimp [mk_span_singleton'],
rw [← sub_eq_zero, ← sub_smul],
apply H,
simp only [sub_smul, one_smul, sub_eq_zero],
apply classical.some_spec (mem_span_singleton.1 h),
end
@[simp] lemma mk_span_singleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0)
(h) :
mk_span_singleton' x y H ⟨x, h⟩ = y :=
by convert mk_span_singleton'_apply x y H 1 _; rwa one_smul
/-- The unique `linear_pmap` on `span R {x}` that sends a non-zero vector `x` to `y`.
This version works for modules over division rings. -/
@[reducible] noncomputable def mk_span_singleton {K E F : Type*} [division_ring K]
[add_comm_group E] [module K E] [add_comm_group F] [module K F] (x : E) (y : F) (hx : x ≠ 0) :
E →ₗ.[K] F :=
mk_span_singleton' x y $ λ c hc, (smul_eq_zero.1 hc).elim
(λ hc, by rw [hc, zero_smul]) (λ hx', absurd hx' hx)
lemma mk_span_singleton_apply (K : Type*) {E F : Type*} [division_ring K]
[add_comm_group E] [module K E] [add_comm_group F] [module K F] {x : E} (hx : x ≠ 0) (y : F) :
mk_span_singleton x y hx
⟨x, (submodule.mem_span_singleton_self x : x ∈ submodule.span K {x})⟩ = y :=
linear_pmap.mk_span_singleton'_apply_self _ _ _ _
/-- Projection to the first coordinate as a `linear_pmap` -/
protected def fst (p : submodule R E) (p' : submodule R F) : (E × F) →ₗ.[R] E :=
{ domain := p.prod p',
to_fun := (linear_map.fst R E F).comp (p.prod p').subtype }
@[simp] lemma fst_apply (p : submodule R E) (p' : submodule R F) (x : p.prod p') :
linear_pmap.fst p p' x = (x : E × F).1 := rfl
/-- Projection to the second coordinate as a `linear_pmap` -/
protected def snd (p : submodule R E) (p' : submodule R F) : (E × F) →ₗ.[R] F :=
{ domain := p.prod p',
to_fun := (linear_map.snd R E F).comp (p.prod p').subtype }
@[simp] lemma snd_apply (p : submodule R E) (p' : submodule R F) (x : p.prod p') :
linear_pmap.snd p p' x = (x : E × F).2 := rfl
instance : has_neg (E →ₗ.[R] F) :=
⟨λ f, ⟨f.domain, -f.to_fun⟩⟩
@[simp] lemma neg_apply (f : E →ₗ.[R] F) (x) : (-f) x = -(f x) := rfl
instance : has_le (E →ₗ.[R] F) :=
⟨λ f g, f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (h : (x:E) = y), f x = g y⟩
lemma apply_comp_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) :
T x = S (submodule.of_le h.1 x) :=
h.2 rfl
lemma exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) :
∃ (y : S.domain), (x : E) = y ∧ T x = S y :=
⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩
lemma eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) :
f = g :=
ext heq hle.2
/-- Given two partial linear maps `f`, `g`, the set of points `x` such that
both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/
def eq_locus (f g : E →ₗ.[R] F) : submodule R E :=
{ carrier := {x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩},
zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩,
add_mem' := λ x y ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩, ⟨add_mem hfx hfy, add_mem hgx hgy,
by erw [f.map_add ⟨x, hfx⟩ ⟨y, hfy⟩, g.map_add ⟨x, hgx⟩ ⟨y, hgy⟩, hx, hy]⟩,
smul_mem' := λ c x ⟨hfx, hgx, hx⟩, ⟨smul_mem _ c hfx, smul_mem _ c hgx,
by erw [f.map_smul c ⟨x, hfx⟩, g.map_smul c ⟨x, hgx⟩, hx]⟩ }
instance : has_inf (E →ₗ.[R] F) :=
⟨λ f g, ⟨f.eq_locus g, f.to_fun.comp $ of_le $ λ x hx, hx.fst⟩⟩
instance : has_bot (E →ₗ.[R] F) := ⟨⟨⊥, 0⟩⟩
instance : inhabited (E →ₗ.[R] F) := ⟨⊥⟩
instance : semilattice_inf (E →ₗ.[R] F) :=
{ le := (≤),
le_refl := λ f, ⟨le_refl f.domain, λ x y h, subtype.eq h ▸ rfl⟩,
le_trans := λ f g h ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩,
⟨le_trans fg_le gh_le, λ x z hxz,
have hxy : (x:E) = of_le fg_le x, from rfl,
(fg_eq hxy).trans (gh_eq $ hxy.symm.trans hxz)⟩,
le_antisymm := λ f g fg gf, eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1),
inf := (⊓),
le_inf := λ f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩,
⟨λ x hx, ⟨fg_le hx, fh_le hx,
by refine (fg_eq _).symm.trans (fh_eq _); [exact ⟨x, hx⟩, refl, refl]⟩,
λ x ⟨y, yg, hy⟩ h, by { apply fg_eq, exact h }⟩,
inf_le_left := λ f g, ⟨λ x hx, hx.fst,
λ x y h, congr_arg f $ subtype.eq $ by exact h⟩,
inf_le_right := λ f g, ⟨λ x hx, hx.snd.fst,
λ ⟨x, xf, xg, hx⟩ y h, hx.trans $ congr_arg g $ subtype.eq $ by exact h⟩ }
instance : order_bot (E →ₗ.[R] F) :=
{ bot := ⊥,
bot_le := λ f, ⟨bot_le, λ x y h,
have hx : x = 0, from subtype.eq ((mem_bot R).1 x.2),
have hy : y = 0, from subtype.eq (h.symm.trans (congr_arg _ hx)),
by rw [hx, hy, map_zero, map_zero]⟩ }
lemma le_of_eq_locus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eq_locus g) :
f ≤ g :=
suffices f ≤ f ⊓ g, from le_trans this inf_le_right,
⟨H, λ x y hxy, ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩
lemma domain_mono : strict_mono (@domain R _ E _ _ F _ _) :=
λ f g hlt, lt_of_le_of_ne hlt.1.1 $ λ heq, ne_of_lt hlt $
eq_of_le_of_domain_eq (le_of_lt hlt) heq
private lemma sup_aux (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x:E) = y → f x = g y) :
∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F,
∀ (x : f.domain) (y : g.domain) (z),
(x:E) + y = ↑z → fg z = f x + g y :=
begin
choose x hx y hy hxy using λ z : f.domain ⊔ g.domain, mem_sup.1 z.prop,
set fg := λ z, f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩,
have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : f.domain ⊔ g.domain) (H : (x':E) + y' = z'),
fg z' = f x' + g y',
{ intros x' y' z' H,
dsimp [fg],
rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub],
apply h,
simp only [← eq_sub_iff_add_eq] at hxy,
simp only [add_subgroup_class.coe_sub, coe_mk, coe_mk, hxy, ← sub_add, ← sub_sub, sub_self,
zero_sub, ← H],
apply neg_add_eq_sub },
refine ⟨{ to_fun := fg, .. }, fg_eq⟩,
{ rintros ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩,
rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add],
apply fg_eq,
simp only [coe_add, coe_mk, ← add_assoc],
rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk] },
{ intros c z,
rw [smul_add, ← map_smul, ← map_smul],
apply fg_eq,
simp only [coe_smul, coe_mk, ← smul_add, hxy, ring_hom.id_apply] },
end
/-- Given two partial linear maps that agree on the intersection of their domains,
`f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees
with `f` and `g`. -/
protected noncomputable def sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x:E) = y → f x = g y) :
E →ₗ.[R] F :=
⟨_, classical.some (sup_aux f g h)⟩
@[simp] lemma domain_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x:E) = y → f x = g y) :
(f.sup g h).domain = f.domain ⊔ g.domain :=
rfl
lemma sup_apply {f g : E →ₗ.[R] F}
(H : ∀ (x : f.domain) (y : g.domain), (x:E) = y → f x = g y)
(x y z) (hz : (↑x:E) + ↑y = ↑z) :
f.sup g H z = f x + g y :=
classical.some_spec (sup_aux f g H) x y z hz
protected lemma left_le_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x:E) = y → f x = g y) :
f ≤ f.sup g h :=
begin
refine ⟨le_sup_left, λ z₁ z₂ hz, _⟩,
rw [← add_zero (f _), ← g.map_zero],
refine (sup_apply h _ _ _ _).symm,
simpa
end
protected lemma right_le_sup (f g : E →ₗ.[R] F)
(h : ∀ (x : f.domain) (y : g.domain), (x:E) = y → f x = g y) :
g ≤ f.sup g h :=
begin
refine ⟨le_sup_right, λ z₁ z₂ hz, _⟩,
rw [← zero_add (g _), ← f.map_zero],
refine (sup_apply h _ _ _ _).symm,
simpa
end
protected lemma sup_le {f g h : E →ₗ.[R] F}
(H : ∀ (x : f.domain) (y : g.domain), (x:E) = y → f x = g y)
(fh : f ≤ h) (gh : g ≤ h) :
f.sup g H ≤ h :=
have Hf : f ≤ (f.sup g H) ⊓ h, from le_inf (f.left_le_sup g H) fh,
have Hg : g ≤ (f.sup g H) ⊓ h, from le_inf (f.right_le_sup g H) gh,
le_of_eq_locus_ge $ sup_le Hf.1 Hg.1
/-- Hypothesis for `linear_pmap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/
lemma sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : disjoint f.domain g.domain)
(x : f.domain) (y : g.domain) (hxy : (x:E) = y) :
f x = g y :=
begin
rw [disjoint_def] at h,
have hy : y = 0, from subtype.eq (h y (hxy ▸ x.2) y.2),
have hx : x = 0, from subtype.eq (hxy.trans $ congr_arg _ hy),
simp [*]
end
section smul
variables {M N : Type*} [monoid M] [distrib_mul_action M F] [smul_comm_class R M F]
variables [monoid N] [distrib_mul_action N F] [smul_comm_class R N F]
instance : has_smul M (E →ₗ.[R] F) :=
⟨λ a f,
{ domain := f.domain,
to_fun := a • f.to_fun }⟩
@[simp] lemma smul_domain (a : M) (f : E →ₗ.[R] F) : (a • f).domain = f.domain := rfl
lemma smul_apply (a : M) (f : E →ₗ.[R] F) (x : ((a • f).domain)) :
(a • f) x = a • f x := rfl
@[simp] lemma coe_smul (a : M) (f : E →ₗ.[R] F) : ⇑(a • f) = a • f := rfl
instance [smul_comm_class M N F] : smul_comm_class M N (E →ₗ.[R] F) :=
⟨λ a b f, ext' $ smul_comm a b f.to_fun⟩
instance [has_smul M N] [is_scalar_tower M N F] : is_scalar_tower M N (E →ₗ.[R] F) :=
⟨λ a b f, ext' $ smul_assoc a b f.to_fun⟩
instance : mul_action M (E →ₗ.[R] F) :=
{ smul := (•),
one_smul := λ ⟨s, f⟩, ext' $ one_smul M f,
mul_smul := λ a b f, ext' $ mul_smul a b f.to_fun }
end smul
section vadd
instance : has_vadd (E →ₗ[R] F) (E →ₗ.[R] F) :=
⟨λ f g,
{ domain := g.domain,
to_fun := f.comp g.domain.subtype + g.to_fun }⟩
@[simp] lemma vadd_domain (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : (f +ᵥ g).domain = g.domain := rfl
lemma vadd_apply (f : E →ₗ[R] F) (g : E →ₗ.[R] F) (x : (f +ᵥ g).domain) :
(f +ᵥ g) x = f x + g x := rfl
@[simp] lemma coe_vadd (f : E →ₗ[R] F) (g : E →ₗ.[R] F) :
⇑(f +ᵥ g) = f.comp g.domain.subtype + g := rfl
instance : add_action (E →ₗ[R] F) (E →ₗ.[R] F) :=
{ vadd := (+ᵥ),
zero_vadd := λ ⟨s, f⟩, ext' $ zero_add _,
add_vadd := λ f₁ f₂ ⟨s, g⟩, ext' $ linear_map.ext $ λ x, add_assoc _ _ _ }
end vadd
section
variables {K : Type*} [division_ring K] [module K E] [module K F]
/-- Extend a `linear_pmap` to `f.domain ⊔ K ∙ x`. -/
noncomputable def sup_span_singleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) :
E →ₗ.[K] F :=
f.sup (mk_span_singleton x y (λ h₀, hx $ h₀.symm ▸ f.domain.zero_mem)) $
sup_h_of_disjoint _ _ $ by simpa [disjoint_span_singleton]
@[simp] lemma domain_sup_span_singleton (f : E →ₗ.[K] F) (x : E) (y : F)
(hx : x ∉ f.domain) :
(f.sup_span_singleton x y hx).domain = f.domain ⊔ K ∙ x := rfl
@[simp] lemma sup_span_singleton_apply_mk (f : E →ₗ.[K] F) (x : E) (y : F)
(hx : x ∉ f.domain) (x' : E) (hx' : x' ∈ f.domain) (c : K) :
f.sup_span_singleton x y hx ⟨x' + c • x,
mem_sup.2 ⟨x', hx', _, mem_span_singleton.2 ⟨c, rfl⟩, rfl⟩⟩ = f ⟨x', hx'⟩ + c • y :=
begin
erw [sup_apply _ ⟨x', hx'⟩ ⟨c • x, _⟩, mk_span_singleton'_apply],
refl,
exact mem_span_singleton.2 ⟨c, rfl⟩
end
end
private lemma Sup_aux (c : set (E →ₗ.[R] F)) (hc : directed_on (≤) c) :
∃ f : ↥(Sup (domain '' c)) →ₗ[R] F, (⟨_, f⟩ : E →ₗ.[R] F) ∈ upper_bounds c :=
begin
cases c.eq_empty_or_nonempty with ceq cne, { subst c, simp },
have hdir : directed_on (≤) (domain '' c),
from directed_on_image.2 (hc.mono domain_mono.monotone),
have P : Π x : Sup (domain '' c), {p : c // (x : E) ∈ p.val.domain },
{ rintros x,
apply classical.indefinite_description,
have := (mem_Sup_of_directed (cne.image _) hdir).1 x.2,
rwa [bex_image_iff, set_coe.exists'] at this },
set f : Sup (domain '' c) → F := λ x, (P x).val.val ⟨x, (P x).property⟩,
have f_eq : ∀ (p : c) (x : Sup (domain '' c)) (y : p.1.1) (hxy : (x : E) = y), f x = p.1 y,
{ intros p x y hxy,
rcases hc (P x).1.1 (P x).1.2 p.1 p.2 with ⟨q, hqc, hxq, hpq⟩,
refine (hxq.2 _).trans (hpq.2 _).symm,
exacts [of_le hpq.1 y, hxy, rfl] },
refine ⟨{ to_fun := f, .. }, _⟩,
{ intros x y,
rcases hc (P x).1.1 (P x).1.2 (P y).1.1 (P y).1.2 with ⟨p, hpc, hpx, hpy⟩,
set x' := of_le hpx.1 ⟨x, (P x).2⟩,
set y' := of_le hpy.1 ⟨y, (P y).2⟩,
rw [f_eq ⟨p, hpc⟩ x x' rfl, f_eq ⟨p, hpc⟩ y y' rfl, f_eq ⟨p, hpc⟩ (x + y) (x' + y') rfl,
map_add] },
{ intros c x,
simp [f_eq (P x).1 (c • x) (c • ⟨x, (P x).2⟩) rfl, ← map_smul] },
{ intros p hpc,
refine ⟨le_Sup $ mem_image_of_mem domain hpc, λ x y hxy, eq.symm _⟩,
exact f_eq ⟨p, hpc⟩ _ _ hxy.symm }
end
/-- Glue a collection of partially defined linear maps to a linear map defined on `Sup`
of these submodules. -/
protected noncomputable def Sup (c : set (E →ₗ.[R] F)) (hc : directed_on (≤) c) :
E →ₗ.[R] F :=
⟨_, classical.some $ Sup_aux c hc⟩
protected lemma le_Sup {c : set (E →ₗ.[R] F)} (hc : directed_on (≤) c)
{f : E →ₗ.[R] F} (hf : f ∈ c) : f ≤ linear_pmap.Sup c hc :=
classical.some_spec (Sup_aux c hc) hf
protected lemma Sup_le {c : set (E →ₗ.[R] F)} (hc : directed_on (≤) c)
{g : E →ₗ.[R] F} (hg : ∀ f ∈ c, f ≤ g) : linear_pmap.Sup c hc ≤ g :=
le_of_eq_locus_ge $ Sup_le $ λ _ ⟨f, hf, eq⟩, eq ▸
have f ≤ (linear_pmap.Sup c hc) ⊓ g, from le_inf (linear_pmap.le_Sup _ hf) (hg f hf),
this.1
protected lemma Sup_apply {c : set (E →ₗ.[R] F)} (hc : directed_on (≤) c)
{l : E →ₗ.[R] F} (hl : l ∈ c) (x : l.domain) :
(linear_pmap.Sup c hc) ⟨x, (linear_pmap.le_Sup hc hl).1 x.2⟩ = l x :=
begin
symmetry,
apply (classical.some_spec (Sup_aux c hc) hl).2,
refl,
end
end linear_pmap
namespace linear_map
/-- Restrict a linear map to a submodule, reinterpreting the result as a `linear_pmap`. -/
def to_pmap (f : E →ₗ[R] F) (p : submodule R E) : E →ₗ.[R] F :=
⟨p, f.comp p.subtype⟩
@[simp] lemma to_pmap_apply (f : E →ₗ[R] F) (p : submodule R E) (x : p) :
f.to_pmap p x = f x := rfl
@[simp] lemma to_pmap_domain (f : E →ₗ[R] F) (p : submodule R E) : (f.to_pmap p).domain = p := rfl
/-- Compose a linear map with a `linear_pmap` -/
def comp_pmap (g : F →ₗ[R] G) (f : E →ₗ.[R] F) : E →ₗ.[R] G :=
{ domain := f.domain,
to_fun := g.comp f.to_fun }
@[simp] lemma comp_pmap_apply (g : F →ₗ[R] G) (f : E →ₗ.[R] F) (x) :
g.comp_pmap f x = g (f x) := rfl
end linear_map
namespace linear_pmap
/-- Restrict codomain of a `linear_pmap` -/
def cod_restrict (f : E →ₗ.[R] F) (p : submodule R F) (H : ∀ x, f x ∈ p) : E →ₗ.[R] p :=
{ domain := f.domain,
to_fun := f.to_fun.cod_restrict p H }
/-- Compose two `linear_pmap`s -/
def comp (g : F →ₗ.[R] G) (f : E →ₗ.[R] F)
(H : ∀ x : f.domain, f x ∈ g.domain) : E →ₗ.[R] G :=
g.to_fun.comp_pmap $ f.cod_restrict _ H
/-- `f.coprod g` is the partially defined linear map defined on `f.domain × g.domain`,
and sending `p` to `f p.1 + g p.2`. -/
def coprod (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) : (E × F) →ₗ.[R] G :=
{ domain := f.domain.prod g.domain,
to_fun := (f.comp (linear_pmap.fst f.domain g.domain) (λ x, x.2.1)).to_fun +
(g.comp (linear_pmap.snd f.domain g.domain) (λ x, x.2.2)).to_fun }
@[simp] lemma coprod_apply (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) (x) :
f.coprod g x = f ⟨(x : E × F).1, x.2.1⟩ + g ⟨(x : E × F).2, x.2.2⟩ :=
rfl
/-- Restrict a partially defined linear map to a submodule of `E` contained in `f.domain`. -/
def dom_restrict (f : E →ₗ.[R] F) (S : submodule R E) :
E →ₗ.[R] F :=
⟨S ⊓ f.domain, f.to_fun.comp (submodule.of_le (by simp))⟩
@[simp] lemma dom_restrict_domain (f : E →ₗ.[R] F) {S : submodule R E} :
(f.dom_restrict S).domain = S ⊓ f.domain := rfl
lemma dom_restrict_apply {f : E →ₗ.[R] F} {S : submodule R E}
⦃x : S ⊓ f.domain⦄ ⦃y : f.domain⦄ (h : (x : E) = y) :
f.dom_restrict S x = f y :=
begin
have : submodule.of_le (by simp) x = y :=
by { ext, simp[h] },
rw ←this,
exact linear_pmap.mk_apply _ _ _,
end
lemma dom_restrict_le {f : E →ₗ.[R] F} {S : submodule R E} : f.dom_restrict S ≤ f :=
⟨by simp, λ x y hxy, dom_restrict_apply hxy⟩
/-! ### Graph -/
section graph
/-- The graph of a `linear_pmap` viewed as a submodule on `E × F`. -/
def graph (f : E →ₗ.[R] F) : submodule R (E × F) :=
f.to_fun.graph.map (f.domain.subtype.prod_map (linear_map.id : F →ₗ[R] F))
lemma mem_graph_iff' (f : E →ₗ.[R] F) {x : E × F} :
x ∈ f.graph ↔ ∃ y : f.domain, (↑y, f y) = x :=
by simp [graph]
@[simp] lemma mem_graph_iff (f : E →ₗ.[R] F) {x : E × F} :
x ∈ f.graph ↔ ∃ y : f.domain, (↑y : E) = x.1 ∧ f y = x.2 :=
by { cases x, simp_rw [mem_graph_iff', prod.mk.inj_iff] }
/-- The tuple `(x, f x)` is contained in the graph of `f`. -/
lemma mem_graph (f : E →ₗ.[R] F) (x : domain f) : ((x : E), f x) ∈ f.graph :=
by simp
variables {M : Type*} [monoid M] [distrib_mul_action M F] [smul_comm_class R M F] (y : M)
/-- The graph of `z • f` as a pushforward. -/
lemma smul_graph (f : E →ₗ.[R] F) (z : M) :
(z • f).graph =
f.graph.map ((linear_map.id : E →ₗ[R] E).prod_map (z • (linear_map.id : F →ₗ[R] F))) :=
begin
ext x, cases x,
split; intros h,
{ rw mem_graph_iff at h,
rcases h with ⟨y, hy, h⟩,
rw linear_pmap.smul_apply at h,
rw submodule.mem_map,
simp only [mem_graph_iff, linear_map.prod_map_apply, linear_map.id_coe, id.def,
linear_map.smul_apply, prod.mk.inj_iff, prod.exists, exists_exists_and_eq_and],
use [x_fst, y],
simp [hy, h] },
rw submodule.mem_map at h,
rcases h with ⟨x', hx', h⟩,
cases x',
simp only [linear_map.prod_map_apply, linear_map.id_coe, id.def, linear_map.smul_apply,
prod.mk.inj_iff] at h,
rw mem_graph_iff at hx' ⊢,
rcases hx' with ⟨y, hy, hx'⟩,
use y,
rw [←h.1, ←h.2],
simp[hy, hx'],
end
/-- The graph of `-f` as a pushforward. -/
lemma neg_graph (f : E →ₗ.[R] F) :
(-f).graph = f.graph.map ((linear_map.id : E →ₗ[R] E).prod_map (-(linear_map.id : F →ₗ[R] F))) :=
begin
ext, cases x,
split; intros h,
{ rw mem_graph_iff at h,
rcases h with ⟨y, hy, h⟩,
rw linear_pmap.neg_apply at h,
rw submodule.mem_map,
simp only [mem_graph_iff, linear_map.prod_map_apply, linear_map.id_coe, id.def,
linear_map.neg_apply, prod.mk.inj_iff, prod.exists, exists_exists_and_eq_and],
use [x_fst, y],
simp [hy, h] },
rw submodule.mem_map at h,
rcases h with ⟨x', hx', h⟩,
cases x',
simp only [linear_map.prod_map_apply, linear_map.id_coe, id.def, linear_map.neg_apply,
prod.mk.inj_iff] at h,
rw mem_graph_iff at hx' ⊢,
rcases hx' with ⟨y, hy, hx'⟩,
use y,
rw [←h.1, ←h.2],
simp [hy, hx'],
end
lemma mem_graph_snd_inj (f : E →ₗ.[R] F) {x y : E} {x' y' : F} (hx : (x,x') ∈ f.graph)
(hy : (y,y') ∈ f.graph) (hxy : x = y) : x' = y' :=
begin
rw [mem_graph_iff] at hx hy,
rcases hx with ⟨x'', hx1, hx2⟩,
rcases hy with ⟨y'', hy1, hy2⟩,
simp only at hx1 hx2 hy1 hy2,
rw [←hx1, ←hy1, set_like.coe_eq_coe] at hxy,
rw [←hx2, ←hy2, hxy],
end
lemma mem_graph_snd_inj' (f : E →ₗ.[R] F) {x y : E × F} (hx : x ∈ f.graph) (hy : y ∈ f.graph)
(hxy : x.1 = y.1) : x.2 = y.2 :=
by { cases x, cases y, exact f.mem_graph_snd_inj hx hy hxy }
/-- The property that `f 0 = 0` in terms of the graph. -/
lemma graph_fst_eq_zero_snd (f : E →ₗ.[R] F) {x : E} {x' : F} (h : (x,x') ∈ f.graph)
(hx : x = 0) : x' = 0 :=
f.mem_graph_snd_inj h f.graph.zero_mem hx
lemma mem_domain_iff {f : E →ₗ.[R] F} {x : E} : x ∈ f.domain ↔ ∃ y : F, (x,y) ∈ f.graph :=
begin
split; intro h,
{ use f ⟨x, h⟩,
exact f.mem_graph ⟨x, h⟩ },
cases h with y h,
rw mem_graph_iff at h,
cases h with x' h,
simp only at h,
rw ←h.1,
simp,
end
lemma mem_domain_of_mem_graph {f : E →ₗ.[R] F} {x : E} {y : F} (h : (x,y) ∈ f.graph) :
x ∈ f.domain :=
by { rw mem_domain_iff, exact ⟨y, h⟩ }
lemma image_iff {f : E →ₗ.[R] F} {x : E} {y : F} (hx : x ∈ f.domain) :
y = f ⟨x, hx⟩ ↔ (x, y) ∈ f.graph :=
begin
rw mem_graph_iff,
split; intro h,
{ use ⟨x, hx⟩,
simp [h] },
rcases h with ⟨⟨x', hx'⟩, ⟨h1, h2⟩⟩,
simp only [submodule.coe_mk] at h1 h2,
simp only [←h2, h1],
end
lemma mem_range_iff {f : E →ₗ.[R] F} {y : F} : y ∈ set.range f ↔ ∃ x : E, (x,y) ∈ f.graph :=
begin
split; intro h,
{ rw set.mem_range at h,
rcases h with ⟨⟨x, hx⟩, h⟩,
use x,
rw ←h,
exact f.mem_graph ⟨x, hx⟩ },
cases h with x h,
rw mem_graph_iff at h,
cases h with x h,
rw set.mem_range,
use x,
simp only at h,
rw h.2,
end
lemma mem_domain_iff_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) {x : E} :
x ∈ f.domain ↔ x ∈ g.domain :=
by simp_rw [mem_domain_iff, h]
lemma le_of_le_graph {f g : E →ₗ.[R] F} (h : f.graph ≤ g.graph) : f ≤ g :=
begin
split,
{ intros x hx,
rw mem_domain_iff at hx ⊢,
cases hx with y hx,
use y,
exact h hx },
rintros ⟨x, hx⟩ ⟨y, hy⟩ hxy,
rw image_iff,
refine h _,
simp only [submodule.coe_mk] at hxy,
rw hxy at hx,
rw ←image_iff hx,
simp [hxy],
end
lemma le_graph_of_le {f g : E →ₗ.[R] F} (h : f ≤ g) : f.graph ≤ g.graph :=
begin
intros x hx,
rw mem_graph_iff at hx ⊢,
cases hx with y hx,
use y,
{ exact h.1 y.2 },
simp only [hx, submodule.coe_mk, eq_self_iff_true, true_and],
convert hx.2,
refine (h.2 _).symm,
simp only [hx.1, submodule.coe_mk],
end
lemma le_graph_iff {f g : E →ₗ.[R] F} : f.graph ≤ g.graph ↔ f ≤ g :=
⟨le_of_le_graph, le_graph_of_le⟩
lemma eq_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) : f = g :=
by {ext, exact mem_domain_iff_of_eq_graph h, exact (le_of_le_graph h.le).2 }
end graph
end linear_pmap
namespace submodule
section submodule_to_linear_pmap
lemma exists_unique_from_graph {g : submodule R (E × F)}
(hg : ∀ {x : E × F} (hx : x ∈ g) (hx' : x.fst = 0), x.snd = 0) {a : E}
(ha : a ∈ g.map (linear_map.fst R E F)) :
∃! (b : F), (a,b) ∈ g :=
begin
refine exists_unique_of_exists_of_unique _ _,
{ convert ha, simp },
intros y₁ y₂ hy₁ hy₂,
have hy : ((0 : E), y₁ - y₂) ∈ g :=
begin
convert g.sub_mem hy₁ hy₂,
exact (sub_self _).symm,
end,
exact sub_eq_zero.mp (hg hy (by simp)),
end
/-- Auxiliary definition to unfold the existential quantifier. -/
noncomputable
def val_from_graph {g : submodule R (E × F)}
(hg : ∀ (x : E × F) (hx : x ∈ g) (hx' : x.fst = 0), x.snd = 0) {a : E}
(ha : a ∈ g.map (linear_map.fst R E F)) : F :=
(exists_of_exists_unique (exists_unique_from_graph hg ha)).some
lemma val_from_graph_mem {g : submodule R (E × F)}
(hg : ∀ (x : E × F) (hx : x ∈ g) (hx' : x.fst = 0), x.snd = 0) {a : E}
(ha : a ∈ g.map (linear_map.fst R E F)) : (a, val_from_graph hg ha) ∈ g :=
(exists_of_exists_unique (exists_unique_from_graph hg ha)).some_spec
/-- Define a `linear_pmap` from its graph. -/
noncomputable
def to_linear_pmap (g : submodule R (E × F))
(hg : ∀ (x : E × F) (hx : x ∈ g) (hx' : x.fst = 0), x.snd = 0) : E →ₗ.[R] F :=
{ domain := g.map (linear_map.fst R E F),
to_fun :=
{ to_fun := λ x, val_from_graph hg x.2,
map_add' := λ v w, begin
have hadd := (g.map (linear_map.fst R E F)).add_mem v.2 w.2,
have hvw := val_from_graph_mem hg hadd,
have hvw' := g.add_mem (val_from_graph_mem hg v.2) (val_from_graph_mem hg w.2),
rw [prod.mk_add_mk] at hvw',
exact (exists_unique_from_graph hg hadd).unique hvw hvw',
end,
map_smul' := λ a v, begin
have hsmul := (g.map (linear_map.fst R E F)).smul_mem a v.2,
have hav := val_from_graph_mem hg hsmul,
have hav' := g.smul_mem a (val_from_graph_mem hg v.2),
rw [prod.smul_mk] at hav',
exact (exists_unique_from_graph hg hsmul).unique hav hav',
end } }
lemma mem_graph_to_linear_pmap (g : submodule R (E × F))
(hg : ∀ (x : E × F) (hx : x ∈ g) (hx' : x.fst = 0), x.snd = 0)
(x : g.map (linear_map.fst R E F)) : (x.val, g.to_linear_pmap hg x) ∈ g :=
val_from_graph_mem hg x.2
@[simp] lemma to_linear_pmap_graph_eq (g : submodule R (E × F))
(hg : ∀ (x : E × F) (hx : x ∈ g) (hx' : x.fst = 0), x.snd = 0) :
(g.to_linear_pmap hg).graph = g :=
begin
ext,
split; intro hx,
{ rw [linear_pmap.mem_graph_iff] at hx,
rcases hx with ⟨y,hx1,hx2⟩,
convert g.mem_graph_to_linear_pmap hg y,
rw [subtype.val_eq_coe],
exact prod.ext hx1.symm hx2.symm },
rw linear_pmap.mem_graph_iff,
cases x,
have hx_fst : x_fst ∈ g.map (linear_map.fst R E F) :=
begin
simp only [mem_map, linear_map.fst_apply, prod.exists, exists_and_distrib_right,
exists_eq_right],
exact ⟨x_snd, hx⟩,
end,
refine ⟨⟨x_fst, hx_fst⟩, subtype.coe_mk x_fst hx_fst, _⟩,
exact (exists_unique_from_graph hg hx_fst).unique (val_from_graph_mem hg hx_fst) hx,
end
end submodule_to_linear_pmap
end submodule
|
489630bbe0c5357512e190b6b59e6130140c9a46 | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /stage0/src/Lean/Meta/InferType.lean | 6f8235b51f16973f1b926d96387623f36b3cd761 | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 17,260 | 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.Data.LBool
import Lean.Meta.Basic
namespace Lean
/-
Auxiliary function for instantiating the loose bound variables in `e` with `args[start:stop]`.
This function is similar to `instantiateRevRange`, but it applies beta-reduction when
we instantiate a bound variable with a lambda expression.
Example: Given the term `#0 a`, and `start := 0, stop := 1, args := #[fun x => x]` the result is
`a` instead of `(fun x => x) a`.
This reduction is useful when we are inferring the type of eliminator-like applications.
For example, given `(n m : Nat) (f : Nat → Nat) (h : m = n)`,
the type of `Eq.subst (motive := fun x => f m = f x) h rfl`
is `motive n` which is `(fun (x : Nat) => f m = f x) n`
This function reduces the new application to `f m = f n`
We use it to implement `inferAppType`
-/
partial def Expr.instantiateBetaRevRange (e : Expr) (start : Nat) (stop : Nat) (args : Array Expr) : Expr :=
if e.hasLooseBVars && stop > start then
assert! stop ≤ args.size
visit e 0 |>.run
else
e
where
visit (e : Expr) (offset : Nat) : MonadStateCacheT (Expr × Nat) Expr Id Expr :=
if offset >= e.looseBVarRange then
-- `e` doesn't have free variables
return e
else checkCache (e, offset) fun _ => do
match e with
| Expr.forallE _ d b _ => return e.updateForallE! (← visit d offset) (← visit b (offset+1))
| Expr.lam _ d b _ => return e.updateLambdaE! (← visit d offset) (← visit b (offset+1))
| Expr.letE _ t v b _ => return e.updateLet! (← visit t offset) (← visit v offset) (← visit b (offset+1))
| Expr.mdata _ b _ => return e.updateMData! (← visit b offset)
| Expr.proj _ _ b _ => return e.updateProj! (← visit b offset)
| Expr.app f a _ =>
e.withAppRev fun f revArgs => do
let fNew ← visit f offset
let revArgs ← revArgs.mapM (visit · offset)
if f.isBVar then
-- try to beta reduce if `f` was a bound variable
return fNew.betaRev revArgs
else
return mkAppRev fNew revArgs
| Expr.bvar vidx _ =>
-- Recall that looseBVarRange for `Expr.bvar` is `vidx+1`.
-- So, we must have offset ≤ vidx, since we are in the "else" branch of `if offset >= e.looseBVarRange`
let n := stop - start
if vidx < offset + n then
return args[stop - (vidx - offset) - 1].liftLooseBVars 0 offset
else
return mkBVar (vidx - n)
-- The following cases are unreachable because they never contain loose bound variables
| Expr.const .. => unreachable!
| Expr.fvar .. => unreachable!
| Expr.mvar .. => unreachable!
| Expr.sort .. => unreachable!
| Expr.lit .. => unreachable!
namespace Meta
def throwFunctionExpected {α} (f : Expr) : MetaM α :=
throwError "function expected{indentExpr f}"
private def inferAppType (f : Expr) (args : Array Expr) : MetaM Expr := do
let mut fType ← inferType f
let mut j := 0
/- TODO: check whether `instantiateBetaRevRange` is too expensive, and
use it only when `args` contains a lambda expression. -/
for i in [:args.size] do
match fType with
| Expr.forallE _ _ b _ => fType := b
| _ =>
match (← whnf <| fType.instantiateBetaRevRange j i args) with
| Expr.forallE _ _ b _ => j := i; fType := b
| _ => throwFunctionExpected <| mkAppRange f 0 (i+1) args
return fType.instantiateBetaRevRange j args.size args
def throwIncorrectNumberOfLevels {α} (constName : Name) (us : List Level) : MetaM α :=
throwError "incorrect number of universe levels {mkConst constName us}"
private def inferConstType (c : Name) (us : List Level) : MetaM Expr := do
let cinfo ← getConstInfo c
if cinfo.levelParams.length == us.length then
return cinfo.instantiateTypeLevelParams us
else
throwIncorrectNumberOfLevels c us
private def inferProjType (structName : Name) (idx : Nat) (e : Expr) : MetaM Expr := do
let failed {α} : Unit → MetaM α := fun _ =>
throwError "invalid projection{indentExpr (mkProj structName idx e)}"
let structType ← inferType e
let structType ← whnf structType
matchConstStruct structType.getAppFn failed fun structVal structLvls ctorVal =>
let n := structVal.numParams
let structParams := structType.getAppArgs
if n != structParams.size then failed ()
else do
let mut ctorType ← inferAppType (mkConst ctorVal.name structLvls) structParams
for i in [:idx] do
ctorType ← whnf ctorType
match ctorType with
| Expr.forallE _ _ body _ =>
if body.hasLooseBVars then
ctorType := body.instantiate1 $ mkProj structName i e
else
ctorType := body
| _ => failed ()
ctorType ← whnf ctorType
match ctorType with
| Expr.forallE _ d _ _ => pure d
| _ => failed ()
def throwTypeExcepted {α} (type : Expr) : MetaM α :=
throwError "type expected{indentExpr type}"
def getLevel (type : Expr) : MetaM Level := do
let typeType ← inferType type
let typeType ← whnfD typeType
match typeType with
| Expr.sort lvl _ => pure lvl
| Expr.mvar mvarId _ =>
if (← isReadOnlyOrSyntheticOpaqueExprMVar mvarId) then
throwTypeExcepted type
else
let lvl ← mkFreshLevelMVar
assignExprMVar mvarId (mkSort lvl)
pure lvl
| _ => throwTypeExcepted type
private def inferForallType (e : Expr) : MetaM Expr :=
forallTelescope e fun xs e => do
let lvl ← getLevel e
let lvl ← xs.foldrM (init := lvl) fun x lvl => do
let xType ← inferType x
let xTypeLvl ← getLevel xType
pure $ mkLevelIMax' xTypeLvl lvl
pure $ mkSort lvl.normalize
/- Infer type of lambda and let expressions -/
private def inferLambdaType (e : Expr) : MetaM Expr :=
lambdaLetTelescope e fun xs e => do
let type ← inferType e
mkForallFVars xs type
@[inline] private def withLocalDecl' {α} (name : Name) (bi : BinderInfo) (type : Expr) (x : Expr → MetaM α) : MetaM α :=
savingCache do
let fvarId ← mkFreshId
withReader (fun ctx => { ctx with lctx := ctx.lctx.mkLocalDecl fvarId name type bi }) do
x (mkFVar fvarId)
def throwUnknownMVar {α} (mvarId : MVarId) : MetaM α :=
throwError "unknown metavariable '?{mvarId}'"
private def inferMVarType (mvarId : MVarId) : MetaM Expr := do
match (← getMCtx).findDecl? mvarId with
| some d => pure d.type
| none => throwUnknownMVar mvarId
private def inferFVarType (fvarId : FVarId) : MetaM Expr := do
match (← getLCtx).find? fvarId with
| some d => pure d.type
| none => throwUnknownFVar fvarId
@[inline] private def checkInferTypeCache (e : Expr) (inferType : MetaM Expr) : MetaM Expr := do
match (← get).cache.inferType.find? e with
| some type => pure type
| none =>
let type ← inferType
unless e.hasMVar || type.hasMVar do
modifyInferTypeCache fun c => c.insert e type
pure type
def inferTypeImp (e : Expr) : MetaM Expr :=
let rec infer : Expr → MetaM Expr
| Expr.const c [] _ => inferConstType c []
| Expr.const c us _ => checkInferTypeCache e (inferConstType c us)
| e@(Expr.proj n i s _) => checkInferTypeCache e (inferProjType n i s)
| e@(Expr.app f _ _) => checkInferTypeCache e (inferAppType f.getAppFn e.getAppArgs)
| Expr.mvar mvarId _ => inferMVarType mvarId
| Expr.fvar fvarId _ => inferFVarType fvarId
| Expr.bvar bidx _ => throwError "unexpected bound variable {mkBVar bidx}"
| Expr.mdata _ e _ => infer e
| Expr.lit v _ => pure v.type
| Expr.sort lvl _ => pure $ mkSort (mkLevelSucc lvl)
| e@(Expr.forallE _ _ _ _) => checkInferTypeCache e (inferForallType e)
| e@(Expr.lam _ _ _ _) => checkInferTypeCache e (inferLambdaType e)
| e@(Expr.letE _ _ _ _ _) => checkInferTypeCache e (inferLambdaType e)
withTransparency TransparencyMode.default (infer e)
@[builtinInit] def setInferTypeRef : IO Unit :=
inferTypeRef.set inferTypeImp
/--
Return `LBool.true` if given level is always equivalent to universe level zero.
It is used to implement `isProp`. -/
private def isAlwaysZero : Level → Bool
| Level.zero _ => true
| Level.mvar _ _ => false
| Level.param _ _ => false
| Level.succ _ _ => false
| Level.max u v _ => isAlwaysZero u && isAlwaysZero v
| Level.imax _ u _ => isAlwaysZero u
/--
`isArrowProp type n` is an "approximate" predicate which returns `LBool.true`
if `type` is of the form `A_1 -> ... -> A_n -> Prop`.
Remark: `type` can be a dependent arrow. -/
private partial def isArrowProp : Expr → Nat → MetaM LBool
| Expr.sort u _, 0 => return isAlwaysZero (← instantiateLevelMVars u) |>.toLBool
| Expr.forallE _ _ _ _, 0 => pure LBool.false
| Expr.forallE _ _ b _, n+1 => isArrowProp b n
| Expr.letE _ _ _ b _, n => isArrowProp b n
| Expr.mdata _ e _, n => isArrowProp e n
| _, _ => pure LBool.undef
/--
`isPropQuickApp f n` is an "approximate" predicate which returns `LBool.true`
if `f` applied to `n` arguments is a proposition. -/
private partial def isPropQuickApp : Expr → Nat → MetaM LBool
| Expr.const c lvls _, arity => do let constType ← inferConstType c lvls; isArrowProp constType arity
| Expr.fvar fvarId _, arity => do let fvarType ← inferFVarType fvarId; isArrowProp fvarType arity
| Expr.mvar mvarId _, arity => do let mvarType ← inferMVarType mvarId; isArrowProp mvarType arity
| Expr.app f _ _, arity => isPropQuickApp f (arity+1)
| Expr.mdata _ e _, arity => isPropQuickApp e arity
| Expr.letE _ _ _ b _, arity => isPropQuickApp b arity
| Expr.lam _ _ _ _, 0 => pure LBool.false
| Expr.lam _ _ b _, arity+1 => isPropQuickApp b arity
| _, _ => pure LBool.undef
/--
`isPropQuick e` is an "approximate" predicate which returns `LBool.true`
if `e` is a proposition. -/
partial def isPropQuick : Expr → MetaM LBool
| Expr.bvar _ _ => pure LBool.undef
| Expr.lit _ _ => pure LBool.false
| Expr.sort _ _ => pure LBool.false
| Expr.lam _ _ _ _ => pure LBool.false
| Expr.letE _ _ _ b _ => isPropQuick b
| Expr.proj _ _ _ _ => pure LBool.undef
| Expr.forallE _ _ b _ => isPropQuick b
| Expr.mdata _ e _ => isPropQuick e
| Expr.const c lvls _ => do let constType ← inferConstType c lvls; isArrowProp constType 0
| Expr.fvar fvarId _ => do let fvarType ← inferFVarType fvarId; isArrowProp fvarType 0
| Expr.mvar mvarId _ => do let mvarType ← inferMVarType mvarId; isArrowProp mvarType 0
| Expr.app f _ _ => isPropQuickApp f 1
/-- `isProp whnf e` return `true` if `e` is a proposition.
If `e` contains metavariables, it may not be possible
to decide whether is a proposition or not. We return `false` in this
case. We considered using `LBool` and retuning `LBool.undef`, but
we have no applications for it. -/
def isProp (e : Expr) : MetaM Bool := do
let r ← isPropQuick e
match r with
| LBool.true => pure true
| LBool.false => pure false
| LBool.undef =>
let type ← inferType e
let type ← whnfD type
match type with
| Expr.sort u _ => return isAlwaysZero (← instantiateLevelMVars u)
| _ => pure false
/--
`isArrowProposition type n` is an "approximate" predicate which returns `LBool.true`
if `type` is of the form `A_1 -> ... -> A_n -> B`, where `B` is a proposition.
Remark: `type` can be a dependent arrow. -/
private partial def isArrowProposition : Expr → Nat → MetaM LBool
| Expr.forallE _ _ b _, n+1 => isArrowProposition b n
| Expr.letE _ _ _ b _, n => isArrowProposition b n
| Expr.mdata _ e _, n => isArrowProposition e n
| type, 0 => isPropQuick type
| _, _ => pure LBool.undef
mutual
/--
`isProofQuickApp f n` is an "approximate" predicate which returns `LBool.true`
if `f` applied to `n` arguments is a proof. -/
private partial def isProofQuickApp : Expr → Nat → MetaM LBool
| Expr.const c lvls _, arity => do let constType ← inferConstType c lvls; isArrowProposition constType arity
| Expr.fvar fvarId _, arity => do let fvarType ← inferFVarType fvarId; isArrowProposition fvarType arity
| Expr.mvar mvarId _, arity => do let mvarType ← inferMVarType mvarId; isArrowProposition mvarType arity
| Expr.app f _ _, arity => isProofQuickApp f (arity+1)
| Expr.mdata _ e _, arity => isProofQuickApp e arity
| Expr.letE _ _ _ b _, arity => isProofQuickApp b arity
| Expr.lam _ _ b _, 0 => isProofQuick b
| Expr.lam _ _ b _, arity+1 => isProofQuickApp b arity
| _, _ => pure LBool.undef
/--
`isProofQuick e` is an "approximate" predicate which returns `LBool.true`
if `e` is a proof. -/
partial def isProofQuick : Expr → MetaM LBool
| Expr.bvar _ _ => pure LBool.undef
| Expr.lit _ _ => pure LBool.false
| Expr.sort _ _ => pure LBool.false
| Expr.lam _ _ b _ => isProofQuick b
| Expr.letE _ _ _ b _ => isProofQuick b
| Expr.proj _ _ _ _ => pure LBool.undef
| Expr.forallE _ _ b _ => pure LBool.false
| Expr.mdata _ e _ => isProofQuick e
| Expr.const c lvls _ => do let constType ← inferConstType c lvls; isArrowProposition constType 0
| Expr.fvar fvarId _ => do let fvarType ← inferFVarType fvarId; isArrowProposition fvarType 0
| Expr.mvar mvarId _ => do let mvarType ← inferMVarType mvarId; isArrowProposition mvarType 0
| Expr.app f _ _ => isProofQuickApp f 1
end
def isProof (e : Expr) : MetaM Bool := do
let r ← isProofQuick e
match r with
| LBool.true => pure true
| LBool.false => pure false
| LBool.undef => do
let type ← inferType e
Meta.isProp type
/--
`isArrowType type n` is an "approximate" predicate which returns `LBool.true`
if `type` is of the form `A_1 -> ... -> A_n -> Sort _`.
Remark: `type` can be a dependent arrow. -/
private partial def isArrowType : Expr → Nat → MetaM LBool
| Expr.sort u _, 0 => pure LBool.true
| Expr.forallE _ _ _ _, 0 => pure LBool.false
| Expr.forallE _ _ b _, n+1 => isArrowType b n
| Expr.letE _ _ _ b _, n => isArrowType b n
| Expr.mdata _ e _, n => isArrowType e n
| _, _ => pure LBool.undef
/--
`isTypeQuickApp f n` is an "approximate" predicate which returns `LBool.true`
if `f` applied to `n` arguments is a type. -/
private partial def isTypeQuickApp : Expr → Nat → MetaM LBool
| Expr.const c lvls _, arity => do let constType ← inferConstType c lvls; isArrowType constType arity
| Expr.fvar fvarId _, arity => do let fvarType ← inferFVarType fvarId; isArrowType fvarType arity
| Expr.mvar mvarId _, arity => do let mvarType ← inferMVarType mvarId; isArrowType mvarType arity
| Expr.app f _ _, arity => isTypeQuickApp f (arity+1)
| Expr.mdata _ e _, arity => isTypeQuickApp e arity
| Expr.letE _ _ _ b _, arity => isTypeQuickApp b arity
| Expr.lam _ _ _ _, 0 => pure LBool.false
| Expr.lam _ _ b _, arity+1 => isTypeQuickApp b arity
| _, _ => pure LBool.undef
/--
`isTypeQuick e` is an "approximate" predicate which returns `LBool.true`
if `e` is a type. -/
partial def isTypeQuick : Expr → MetaM LBool
| Expr.bvar _ _ => pure LBool.undef
| Expr.lit _ _ => pure LBool.false
| Expr.sort _ _ => pure LBool.true
| Expr.lam _ _ _ _ => pure LBool.false
| Expr.letE _ _ _ b _ => isTypeQuick b
| Expr.proj _ _ _ _ => pure LBool.undef
| Expr.forallE _ _ b _ => pure LBool.true
| Expr.mdata _ e _ => isTypeQuick e
| Expr.const c lvls _ => do let constType ← inferConstType c lvls; isArrowType constType 0
| Expr.fvar fvarId _ => do let fvarType ← inferFVarType fvarId; isArrowType fvarType 0
| Expr.mvar mvarId _ => do let mvarType ← inferMVarType mvarId; isArrowType mvarType 0
| Expr.app f _ _ => isTypeQuickApp f 1
def isType (e : Expr) : MetaM Bool := do
let r ← isTypeQuick e
match r with
| LBool.true => pure true
| LBool.false => pure false
| LBool.undef =>
let type ← inferType e
let type ← whnfD type
match type with
| Expr.sort _ _ => pure true
| _ => pure false
partial def isTypeFormerType (type : Expr) : MetaM Bool := do
let type ← whnfD type
match type with
| Expr.sort _ _ => pure true
| Expr.forallE n d b c =>
withLocalDecl' n c.binderInfo d fun fvar =>
isTypeFormerType (b.instantiate1 fvar)
| _ => pure false
/--
Return true iff `e : Sort _` or `e : (forall As, Sort _)`.
Remark: it subsumes `isType` -/
def isTypeFormer (e : Expr) : MetaM Bool := do
let type ← inferType e
isTypeFormerType type
end Lean.Meta
|
77793b4650b86d217ffe3984568e76b9a67b7e4d | 92b50235facfbc08dfe7f334827d47281471333b | /tests/lean/run/forest_height.lean | aa9460f6a4595851d8cd59c1debde7a6be5dbb68 | [
"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 | 4,298 | lean | import data.nat.basic data.sum data.sigma data.bool
open nat sigma
inductive tree (A : Type) : Type :=
| node : A → forest A → tree A
with forest : Type :=
| nil : forest A
| cons : tree A → forest A → forest A
namespace manual
check tree.rec_on
definition tree.height {A : Type} (t : tree A) : nat :=
tree.rec_on t
(λ (a : A) (f : forest A) (ih : nat), succ ih)
zero
(λ (t : tree A) (f : forest A) (ih₁ : nat) (ih₂ : nat), succ (max ih₁ ih₂))
definition forest.height {A : Type} (f : forest A) : nat :=
forest.rec_on f
(λ (a : A) (f : forest A) (ih : nat), succ ih)
zero
(λ (t : tree A) (f : forest A) (ih₁ : nat) (ih₂ : nat), succ (max ih₁ ih₂))
definition tree_forest (A : Type) := sum (tree A) (forest A)
definition tree_forest_height {A : Type} (t : tree_forest A) : nat :=
sum.rec_on t (λ t, tree.height t) (λ f, forest.height f)
definition tree_forest.subterm {A : Type} : tree_forest A → tree_forest A → Prop :=
inv_image lt tree_forest_height
definition tree_forest.subterm.wf [instance] (A : Type) : well_founded (@tree_forest.subterm A) :=
inv_image.wf tree_forest_height lt.wf
local infix `≺`:50 := tree_forest.subterm
definition tree_forest.height_lt.node {A : Type} (a : A) (f : forest A) : sum.inr f ≺ sum.inl (tree.node a f) :=
have aux : forest.height f < tree.height (tree.node a f), from
lt.base (forest.height f),
aux
definition tree_forest.height_lt.cons₁ {A : Type} (t : tree A) (f : forest A) : sum.inl t ≺ sum.inr (forest.cons t f) :=
have aux : tree.height t < forest.height (forest.cons t f), from
lt_succ_of_le (le_max_left _ _),
aux
definition tree_forest.height_lt.cons₂ {A : Type} (t : tree A) (f : forest A) : sum.inr f ≺ sum.inr (forest.cons t f) :=
have aux : forest.height f < forest.height (forest.cons t f), from
lt_succ_of_le (le_max_right _ _),
aux
definition kind {A : Type} (t : tree_forest A) : bool :=
sum.cases_on t (λ t, bool.tt) (λ f, bool.ff)
definition map.res {A : Type} (B : Type) (t : tree_forest A) :=
Σ r : tree_forest B, kind r = kind t
set_option find_decl.expensive true
find_decl bool.ff ≠ bool.tt
-- map using well-founded recursion. We could have used the default recursor.
-- this is just a test for the definitional package
definition map.F {A B : Type₁} (f : A → B) (tf₁ : tree_forest A) : (Π tf₂ : tree_forest A, tf₂ ≺ tf₁ → map.res B tf₂) → map.res B tf₁ :=
sum.cases_on tf₁
(λ t : tree A, tree.cases_on t
(λ a₁ f₁ (r : Π (tf₂ : tree_forest A), tf₂ ≺ sum.inl (tree.node a₁ f₁) → map.res B tf₂),
show map.res B (sum.inl (tree.node a₁ f₁)), from
have rf₁ : map.res B (sum.inr f₁), from r (sum.inr f₁) (tree_forest.height_lt.node a₁ f₁),
have nf₁ : forest B, from sum.cases_on (pr₁ rf₁)
(λf (h : kind (sum.inl f) = kind (sum.inr f₁)), absurd (eq.symm h) bool.ff_ne_tt)
(λf h, f)
(pr₂ rf₁),
sigma.mk (sum.inl (tree.node (f a₁) nf₁)) rfl))
(λ f : forest A, forest.cases_on f
(λ r : Π (tf₂ : tree_forest A), tf₂ ≺ sum.inr (forest.nil A) → map.res B tf₂,
show map.res B (sum.inr (forest.nil A)), from
sigma.mk (sum.inr (forest.nil B)) rfl)
(λ t₁ f₁ (r : Π (tf₂ : tree_forest A), tf₂ ≺ sum.inr (forest.cons t₁ f₁) → map.res B tf₂),
show map.res B (sum.inr (forest.cons t₁ f₁)), from
have rt₁ : map.res B (sum.inl t₁), from r (sum.inl t₁) (tree_forest.height_lt.cons₁ t₁ f₁),
have rf₁ : map.res B (sum.inr f₁), from r (sum.inr f₁) (tree_forest.height_lt.cons₂ t₁ f₁),
have nt₁ : tree B, from sum.cases_on (pr₁ rt₁)
(λ t h, t)
(λ f h, absurd h bool.ff_ne_tt)
(pr₂ rt₁),
have nf₁ : forest B, from sum.cases_on (pr₁ rf₁)
(λf (h : kind (sum.inl f) = kind (sum.inr f₁)), absurd (eq.symm h) bool.ff_ne_tt)
(λf h, f)
(pr₂ rf₁),
sigma.mk (sum.inr (forest.cons nt₁ nf₁)) rfl))
definition map {A B : Type₁} (f : A → B) (tf : tree_forest A) : map.res B tf :=
well_founded.fix (@map.F A B f) tf
eval map succ (sum.inl (tree.node 2 (forest.cons (tree.node 1 (forest.nil nat)) (forest.nil nat))))
end manual
|
f6ec15693cdbaf4498cdd2f90caf02b163c77a4b | 3618c6e11aa822fd542440674dfb9a7b9921dba0 | /src/solve.lean | 1acda6b507c2cce6c71ac7e29bfe2f1062694cc7 | [] | no_license | ChrisHughes24/single_relation | 99ceedcc02d236ce46d6c65d72caa669857533c5 | 057e157a59de6d0e43b50fcb537d66792ec20450 | refs/heads/master | 1,683,652,062,698 | 1,683,360,089,000 | 1,683,360,089,000 | 279,346,432 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,473 | lean | import exp_sum_eq_zero
import base_case
import choose_letters
import no_exp_sum_zero
import solve_by_subst
import no_letters
import golf
open semidirect_product
meta def solve : Π ⦃ι : Type⦄ [decidable_eq ι]
(r : free_group ι) (T : set ι) [decidable_pred T],
by exactI solver r T :=
λ ι _ r T _ w, by exactI
let vars_w := vars w in
-- heuristic; algorithm is still complete without this line below
(guard (vars_w.all (∈ T)) >> return (inr w)) <|>
let (c₁, cyc_r) := cyclically_reduce r in
P.change_r c₁ <$>
match cyc_r with
| ⟨[], _⟩ := by exactI guard (mem_closure_var T w) >> some (inr w)
| ⟨[⟨r₁, r₂⟩], _⟩ := by exactI base_case_solver T r₁ r₂ w
| cyc_r := by exactI
-- heuristic; algorithm is still complete wihout below line. Without trying
-- `guard (vars_w.all (∈ T)) >> return (inr w))` first,
-- below line would break completeness.
let vars_cyc_r := vars cyc_r in
guard (vars_cyc_r.all (λ i, i ∈ vars_w ∨ i ∈ T)) >>
-- heuristic; algorithm is still complete without this line below
-- solve_by_subst seems to usually make it slower, but maybe worth doing anyway if it is
-- a lot faster in some cases
solve_by_subst T cyc_r w <|>
match choose_t_and_x cyc_r T vars_cyc_r with
| none := no_letters T r (by exactI solve r ∅) w
| some ((t, α), (x, β)) :=
if α = 1
then exp_sum_eq_zero T t x (λ r T _, by exactI solve r T) cyc_r w
else exp_sum_ne_zero T t x α β (λ r T _, by exactI solve r T) cyc_r w
end
end
meta def golf_solve ⦃ι : Type⦄ [decidable_eq ι] [has_lt ι] [decidable_rel ((<) : ι → ι → Prop)]
(r : free_group ι) (T : set ι) [decidable_pred T] : solver r T :=
λ w, (golf₂ r ∘ golf₁ r) <$> solve r T w
set_option profiler true
variables {ι : Type} [decidable_eq ι] [has_lt ι] [decidable_rel ((<) : ι → ι → Prop)] (T : set ι)
meta def test (r : free_group ι) (T : set ι) [decidable_pred T] (w : free_group ι) : bool :=
match golf_solve r T w with
| some p' := P.lhs r p' = w ∧ mem_closure_var T p'.right
| none := ff
end
open free_group
-- #eval let r := (of 0 * of 1 * (of 0)⁻¹ * (of 1) ^ (-2 : int)) in
-- (solve r ∅ (of 0 ^ 10 * of 1 * of 0 ^ (-10 : int) * of 1 ^ (-1024 : int))).iget.left.length
#eval let r := (of 0 * of 1 * (of 0)⁻¹ * (of 1) ^ (-2 : int)) in
let n := 9 in
(solve r ∅ (of 0 ^ n * of 1 * of 0 ^ (-n : int) * of 1 * of 0 ^ n *
(of 1)⁻¹ * of 0 ^ (-n : int) * (of 1)⁻¹)).iget.left.length
#eval let r := (of 0 * of 1 * (of 0)⁻¹ * (of 1) ^ (-2 : int)) in
(solve r ∅ ((of 0) ^ (5 : int) * of 1 * (of 0) ^ (- 5 : int) * of 1 * (of 0) ^
(5 : int) * (of 1)⁻¹ * of 0 ^ (- 5 : int) * (of 1)⁻¹)).iget.left.length
#eval let a := of 1 in let b := of 0 in
let r := a * b * a⁻¹ * b ^ (-2 : int) in
solve r ∅ (a^(10 : int) * b * a^(-10 : int)* b * a^(10 : int) * b⁻¹ * a^(-10 : int) * b⁻¹)
-- #eval
-- let a := of 1 * of 0 in let b := (of 0)^2 * of 1 * of 2 in
-- let r := a * b * a⁻¹ * b ^ (-2 : int) in
-- (golf_solve r ∅ (a^(-5 : int) * b * a^5 * b * a^(-5 : int) * b⁻¹ * a^5 * b⁻¹)).iget.left.length
-- #eval test (of 0 * of 1 * (of 0)⁻¹) ∅ (of 0 * of 1 * (of 0)⁻¹)
-- --#eval solve (of 0 ^ 88 * of 1 ^ 88) {1} (of 0 * of 1 * (of 0)⁻¹)
-- #eval test (of 0 * of 1) ∅ (of 0 * (of 1) * (of 0)⁻¹ * (of 1)⁻¹)
-- -- #eval ((solve (of 0 * of 1) ∅
-- -- (of 0 * (of 1) * (of 0)⁻¹ * (of 1)⁻¹)).is_some)
-- #eval test (of 0 * of 1 * (of 0)⁻¹ * (of 1)⁻¹) ∅
-- (of 0 ^ 2 * (of 1)⁻¹ ^ 2 * (of 0)⁻¹ ^ 2 * (of 1) ^ 2)
-- -- #eval (solve (of 0 * of 1 * (of 0)⁻¹ * (of 1)⁻¹) ∅
-- -- (of 0 ^ 2 * (of 1)⁻¹ ^ 2 * (of 0)⁻¹ ^ 2 * (of 1) ^ 2)).iget.left
-- #eval test (of "a" * of "b" * (of "a")⁻¹ * (of "b")⁻¹) ∅
-- (of "a" ^ 2 * (of "b") * (of "a")⁻¹ ^ 2 * (of "b")⁻¹)
-- --P.lhs (of "a" * of "b" * (of "a")⁻¹ * (of "b")⁻¹)
-- --free_group.map (golf_single (of "a" * of "b" * (of "a")⁻¹ * (of "b")⁻¹))
-- -- ((solve (of "a" * of "b" * (of "a")⁻¹ * (of "b")⁻¹) ∅
-- -- (of "a" ^ 2 * (of "b") * (of "a")⁻¹ ^ 2 * (of "b")⁻¹)).iget)
#eval let r := of 0 * of 1 * (of 0)^(-3 : ℤ) * (of 1)^4 in
-- test r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0) * r⁻¹ * (of 0)⁻¹ * r)
(solve r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0) * r⁻¹ * (of 0)⁻¹ * r)).iget.left
#eval let r := of 0 * of 1 * (of 0)^(-5 : ℤ) * (of 1)^4 in
(golf_solve r {0} (of 0 * of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)
* r⁻¹ * (of 0)⁻¹ * r)).iget.left.length
-- #eval let r := of 0 * of 1 * (of 0)^(-5 : ℤ) * (of 1)^4 in
-- (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0) * r⁻¹ * (of 0)⁻¹ * r)
#eval let r := of 0 * of 1 * (of 0)^(-11 : ℤ) * (of 1)^(4 : int) in
(solve r ∅ (of 0 ^ 15 * of 1 * r * (of 1)⁻¹ * of 0 ^ (-15 : int) * r⁻¹)).iget.left.to_list.length
#eval let r := of 0 * of 1 * (of 0)^(-11 : ℤ) * (of 1)^4 in
(solve r ∅ (of 0 ^ 10 * of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)
* r⁻¹ * (of 0)⁻¹ * r * of 0 ^ (-10 : ℤ))⁻¹).iget.left.to_list.length
#eval let r := of 0 * of 1 * (of 0)^(-11 : ℤ) * (of 1)^4 in
(of 0 ^ 10 * of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)
* r⁻¹ * (of 0)⁻¹ * r * of 0 ^ (-10 : ℤ))⁻¹
#eval let r := of 0 * of 1 * (of 0)^(-11 : ℤ) * (of 1)^4 in
let a := of 0 in let b := of 1 in
(solve r ∅ (a ^ 10 * b * a * b * a ^ (-11 : ℤ) * b ^ 3 * a ^ (-10 : ℤ) * b ^ (-4 : ℤ)
* a ^ 11 * b⁻¹ * a⁻¹)).iget.left.length
-- #eval let r := of 0 * of 1 * (of 0)^(-9 : ℤ) * (of 1)^6 in
-- (solve r {0} (of 0 ^ 7 * of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)
-- * r⁻¹ * (of 0)⁻¹ * r)⁻¹).iget.left.to_list.length
-- #eval let r := (of 0 ^ 20 * of 1 ^ 11)^2 in
-- solve r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)
-- * r⁻¹ * (of 0)⁻¹ * r)
-- def r : free_group ℕ := (of 0 ^ 5 * of 1 ^ 5)^2
-- #eval let r := (of 0 ^ 7 * of 1 ^ 3)^2 in --BUG
-- (solve r ∅ r)
-- open multiplicative
-- #eval choose_t_and_x r ∅ [0, 1]
-- #eval ((cyclically_conjugate 0 r).2 = r : bool)
-- #eval add_subscript 1
-- (psi 1 0 (of_add 6) (of_add 6) r)
-- def r₁ := (add_subscript 1
-- (psi 1 0 (of_add 6) (of_add 6) r)).left
-- #eval (psi 1 0 (of_add 6) (of_add 6) r).to_list
-- #eval HNN_normalize_core 1 0
-- (add_subscript 0 (psi 1 0 (of_add 6) (of_add 6) r)).left
-- (of_add (-12)) (of_add 0)
-- (λ r T _, by exactI solve r T) []
-- [⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩, ⟨0, of_add 1⟩,
-- ⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩]
-- meta def Z := HNN_normalize_core 1 0
-- (add_subscript 0 (psi 1 0 (of_add 6) (of_add 6) r)).left
-- (of_add (-12)) (of_add 0)
-- (λ r T _, by exactI solve r T)
-- [(⟨1, of_list [⟨(0, 1), of_add 1⟩]⟩, 1)]
-- [⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩, ⟨0, of_add 1⟩,
-- ⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩]
-- #eval solve r₁ { x | x ≠ (0, of_add 0) } (of_list [⟨(0, 1), of_add 1⟩])
-- #eval HNN_normalize_core 1 0
-- (add_subscript 0 (psi 1 0 (of_add 6) (of_add 6) r)).left
-- (of_add (-12)) (of_add 0)
-- (λ r T _, by exactI solve r T)
-- [(1, of_add (-6)), (⟨1, of_list [⟨(0, 1), of_add 1⟩]⟩, 1)]
-- [⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩, ⟨0, of_add 1⟩,
-- ⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩]
-- #eval (HNN_normalize_core 1 0
-- (add_subscript 0 (psi 1 0 (of_add 6) (of_add 6) r)).left
-- (of_add (-12)) (of_add 0)
-- (λ r T _, by exactI solve r T)
-- [(inr (of_list [⟨(0, of_add 0), of_add 1⟩]), of_add (-6)),
-- (⟨1, of_list [⟨(0, 1), of_add 1⟩]⟩, 1)]
-- [⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩, ⟨0, of_add 1⟩,
-- ⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩])
-- #eval (HNN_normalize_core 1 0
-- (add_subscript 0 (psi 1 0 (of_add 6) (of_add 6) r)).left
-- (of_add (-12)) (of_add 0)
-- (λ r T _, by exactI solve r T)
-- [(1, of_add (-6)), (inr (of_list [⟨(0, of_add 0), of_add 1⟩]), of_add (-6)),
-- (⟨1, of_list [⟨(0, 1), of_add 1⟩]⟩, 1)]
-- [⟨0, of_add 1⟩, ⟨1, of_add 12⟩, ⟨0, of_add 1⟩,
-- ⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩])
-- #eval (HNN_normalize_core 1 0
-- (add_subscript 0 (psi 1 0 (of_add 6) (of_add 6) r)).left
-- (of_add (-12)) (of_add 0)
-- (λ r T _, by exactI solve r T)
-- [(inr (of_list [⟨(0, of_add 0), of_add 1⟩]), of_add (-6)),
-- (inr (of_list [⟨(0, of_add 0), of_add 1⟩]), of_add (-6)),
-- (⟨1, of_list [⟨(0, 1), of_add 1⟩]⟩, 1)]
-- [⟨1, of_add 12⟩, ⟨0, of_add 1⟩,
-- ⟨1, of_add (-6)⟩, ⟨0, of_add 1⟩, ⟨1, of_add (-6)⟩,
-- ⟨0, of_add 1⟩, ⟨1, of_add 12⟩] = Z: bool)
-- #eval show C∞, from
-- match solve r₁ {x | x ≠ (0, of_add (-12))} (of_list [⟨(0, of_add 0), of_add 1⟩]) with
-- | none := sorry
-- | some q := let k : C∞ :=
-- match min_subscript 0 q.right with
-- | some m := max ((of_add 12)⁻¹) ((of_add (-12)) * m⁻¹)
-- | none := (of_add 12)⁻¹
-- end in k
-- end
-- #eval HNN_normalize 1 0 (add_subscript 0 (psi 1 0 (of_add 6) (of_add 6) r)).left
-- (of_add (-12)) (of_add 0)
-- (λ r T _, by exactI solve r T)
-- (psi 1 0 (of_add 6) (of_add 6) r)
-- def r' := (add_subscript 1 (psi 1 0 (of_add 4) (of_add 4) r)).left
-- #eval choose_t_and_x r' ∅ (vars r')
-- def r₂ := (add_subscript (0, of_add (0 : ℤ))
-- (psi (0, of_add 0) (0, of_add (-4 : ℤ)) (of_add 2) (of_add 2) r')).left
-- #eval r₂
-- #eval base_case_solver ∅ ((0, of_add (-4 : ℤ)), of_add (2 : ℤ)) (of_add (-2 : ℤ)) r₂
#eval let r := of 0 * of 1 * (of 0)^(-16 : ℤ) * (of 1)^5 in
(test r ∅ ((of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)
* r⁻¹ * (of 0)⁻¹ * r))⁻¹)
-- #eval let r := of 0 * of 1 * (of 0)^(-1 : ℤ) * (of 1)^1 in
-- let w := (of 2 * r * (of 2)⁻¹ * of 1 * r * (of 1)⁻¹ * r⁻¹ *
-- (of 0) * r⁻¹ * (of 0)⁻¹ * r * of 2 * r * (of 2)⁻¹) in
-- test r {x | x ≠ 2} w.
-- -- #eval solve (of 0 * of 1) (of 0 * of 1 * )
-- #eval let r := (of 0)^1 * of 1 * (of 0)^(-2 : ℤ) * (of 1)^(-1 : ℤ) in
-- (test r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)⁻¹ * r⁻¹ * (of 0) * r))
-- -- (P.lhs r
-- -- (solve r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)⁻¹ * r⁻¹ * (of 0) * r)).iget =
-- -- (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)⁻¹ * r⁻¹ * (of 0) * r) : bool)
-- #eval let r := (of 'a') ^ (-2 : ℤ) in
-- test r ∅ ((of 'a') ^ 22)
-- #eval let r := (of 'a') ^ (-2 : ℤ) in
-- test r {'b'} ((of 'a') ^ 22 * of 'b' * of 'a' ^ (-10 : ℤ) * (of 'b'))
-- #eval let r := (1 : free_group ℕ) in test r {0} 1
-- #eval let r := (1 : free_group ℕ) in test r ∅ 1
-- #eval let r := of 0 * of 1 * (of 0)⁻¹ * (of 1) in
-- test r {x | x = 1 ∨ x = 2}
-- (of 1 * r * (of 1) * r⁻¹ * of 2 * (of 1) * (of 0) * r⁻¹ * (of 0)⁻¹ * r * of 1)
-- #eval let r := of 0 * of 1 * (of 0) * (of 1)^2 in
-- test r ∅ (of 0 * of 1 * (of 1 * of 0)⁻¹)
-- #eval let r := of 0 * of 1 * of 0 * of 1 * (of 0)^2 * of 1 in
-- test r ∅ ((of 0) * (of 1) * (of 0)⁻¹ * (of 1)⁻¹)
#eval let r := of 0 * of 1 * (of 0) ^ 3 * (of 1) ^ (4 : int) in
test r ∅ (r * (of 1)⁻¹ * r * (of 1) * r)
-- #eval choose_t_and_x (of 0 * of 1 * (of 0) ^ 3 * (of 1) ^ (4 : int)) {0} [0, 1]
-- #eval let r := (of 0) * of 1 * (of 0)^(-1 : ℤ) * (of 1)^(2 : ℤ) in
-- test r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)⁻¹ * r⁻¹ * (of 0) * r)
-- #eval let r := (of 0 * (of 1)^2)^8 in
-- test r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)⁻¹ * r⁻¹ * (of 0) * r)
-- #eval let r := (of 0 * (of 1)^2)^2 in
-- test r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)⁻¹ * r⁻¹ * (of 0) * r)
-- #eval let r := of 0 * of 1 * of 0 * of 1 * (of 0)^2 * of 1 in
-- test r ∅ (of 1 ^ 3 * of 0 ^ 4)⁻¹
-- -- #eval let r := (of 0 * (of 1) * (of 0)⁻¹ * of 1)^2 in
-- -- (solve r ∅ (of 1 * r * (of 1)⁻¹ * r⁻¹ * (of 0)⁻¹ * r⁻¹ * (of 0) * r)).iget.left.to_list.length
def w : ℕ → free_group char
| 0 := of 'a'
| (n+1) := ((of 'b')⁻¹ * w n * of 'b')⁻¹ * of 'a' * ((of 'b')⁻¹ * w n * of 'b')
-- --#print string.decidable_eq
#eval (solve (w 1 * (of 'a') ^ (-2 : ℤ)) {'a'} (w 3)).iget.left.to_list.length
-- #eval P.lhs (w 1 * (of 'a') ^ (2 : ℤ))
-- (golf_solve (w 1 * (of 'a') ^ (-2 : ℤ)) {'a'} (w 2)).iget
-- #eval w 2
-- #eval (of 'b')⁻¹ * (of 'a')^(2 : ℤ)
-- --#eval (golf_solve (w 1 * (of 'a') ^ (2 : ℤ)) {'a'} (w 2)) --HARD
-- #eval choose_t_and_x (w 1 * (of 'a') ^ (-2 : ℤ)) {'a'} (vars (w 1 * (of 'a') ^ (-2 : ℤ)))
-- #eval (golf_solve
-- (w 1 * (of 'a') ^ (-2 : ℤ))
-- ⊥
-- ((of 'a') * w 3 * (of 'a')⁻¹ * (w 3)⁻¹)).iget.left.to_list.length
-- open multiplicative
|
3c7610d8c4f25b1e0a5f32faaa9cbbf879080d74 | 8cd4726d66eec7673bcc0325fed07d5ba5bf17c4 | /hw4.lean | 424b95da73af3cb2c47a043f41a89a44ac838a72 | [] | no_license | justinqcai/CS2102 | 8c5fddedffa6147fedd4b6ee7d5d39fc21f0ddab | d309f0db3f1df52eb77206ee1e8665a3b49d7a0c | refs/heads/master | 1,590,108,991,894 | 1,557,610,044,000 | 1,557,610,044,000 | 186,064,169 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,214 | lean | /-
0. Read the class notes through Section
3.7, Implication. It is important that
you do this before classes next week, as
we will move somewhat quickly through a
few of these chapters.
To complete the rest of this homework,
solve the problems given as specified,
then save and submit this file.
-/
/-
1.
Show that if you're given proofs
of a = b and c = b you can construct
a proof of a = c. Do it by completing
the following function. Note that we
can use parenthesis to enclose terms
that appear within larger terms. This
is often necessary to make sure that
Lean understands how you want to group
things.
-/
theorem eq_snart { T : Type}
{ a b c: T }
(ab: a = b)
(cb: c = b) :
a = c :=
eq.trans
ab
(eq.symm cb)
/-
Now, given the following assumptions, apply
your newly proved inference rule, eq.snart,
to show that Harry = Bob. Yes: Once you've
proved a theorem, you can apply it as if it
were a function, to arguments of the right
types, to get a proof that you need. Try it.
-/
axiom Person : Type
axioms Harry Bob Jose: Person
axioms (hj : Harry = Bob) (jb : Jose = Bob)
example : Harry = Jose := eq_snart hj jb
/-
2. Use example to assert and then prove that if
a, b, c, and d are nats, and if you have proofs
of a = b, b = c, and c = d, you can construct a
proof of a = d. Put the proof in the placeholder
below.
Hint: Equality propositions are types. Think of
the problem here as one of producing a function
of the specific type. Use lambdas. We've gotten
you started. The first lambda "assumes" that a,
b, c, and d are natural numbers. What's left to
do is to prove a function (yes, start with lambda)
that takes three arguments of the specified kinds
(use lambda to give them names) and that finally
produces a result of the type at the end of the
chain.
-/
theorem transit :
∀ a b c d : ℕ,
(a = b) → (b = c) → (c = d) → (a = d)
:=
λ a b c d,
λ (ab: a = b),
λ (bc: b = c),
λ (cd: c = d),
eq.trans (eq.trans ab bc) cd
/-
3. In the context of the axioms in the following
namespace, write an exact proof term to prove
that Yuanfang is friendly. Hint #1: Just apply
the relevant inference rule as a function to the
right arguments. Hint #2: The direction in which
an equality is written matters. If, for example,
you have a proof of x = y and you want to apply
an inference rule that requires a proof of y = x,
then you need to find a way to get what you need
from what you have to work with in your context.
-/
axioms Mary Yuanfang : Person
axiom Friendly : Person → Prop
axiom mf : Friendly Mary
axiom yeqm : Yuanfang = Mary
example : Friendly Yuanfang :=
eq.subst (eq.symm yeqm) mf
/-
4. The subtitution rule for equality lets
you rewrite proof goals by substituting one
term for another, in a goal, as long as you
already have a proof that the two terms
are equal. The reasoning is that replacing
one term with another makes no difference to
the truth of a proposition if the two terms
are equal.
Suppose for example that you have a proof,
h, of y = x (yes we can and do give names
to proofs, as we consider them to be values),
and a proof, y1, of y = 1, and that your
goal is to prove (x = 1). You can justify
rewriting this goal as (y = 1), for which
you already have a proof, because you know
that y = x; so making this substitution
doesn't change the truth of the proposition.
In the tactic scripting libraries that Lean
provides, there is a tactic for rewriting a
goal in this way. If h is a proof of x = y,
then the tactic, "rw h" ("rw" is short for
"rewrite") replaces all occurrences of x (the
left side of h) with y (it's right side).
Here's an example.
-/
def foo (x y : ℕ) (y1 : y = 1) (h: x = y) : (x = 1) :=
begin
rewrite h,
exact y1,
end
/-
Use what you just learned to state and prove
the proposition that for any type, T, and for
any objects, a, b, and c, of this type, if
(a = b) and (b = c) then (c = a). Do this by
finishing off the tactic script that follows.
Note that to apply an inference rule within a
tactic script you use the "apply" tactic. Read
the further explanation and hint that follow
before attempting to solve this problem.
-/
def ac (T : Type) (a b c : T)
(ab : a = b) (bc : b = c)
: (c = a) :=
begin
rewrite ab,
exact eq.symm bc
end
/-
Note that the "foralls" in the natural language
statement are represented in this code *not* by
using ∀ but by declaring them to be arguments
to our function. If you can write a function of
the specified type then you have in effect proven
that for *any* T and any a, b, c, of type T, if
if you also have a proof of a=b and a proof of
b=c, then a value of type c=a can be constructed
and returned. The reason this is true is that in
Lean all functions are total, as you now recall!
Key hint: The tactic application "rw h" changes
all occurrences of the left side of the equality
h, in the goal, into what's on its right side.
If you want the rewriting to go from right to
left, use "rw<-h". When you're just about done,
don't be surprised if the rewrite tactic applies
rfl automatically.
-/ |
b7a26d5fe6d3a13226bf813a1b7dd0b70bad97b4 | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /src/algebra/group/basic.lean | 2ea391779086364e7bcd9e4b65f8822994450cce | [
"Apache-2.0"
] | permissive | anrddh/mathlib | 6a374da53c7e3a35cb0298b0cd67824efef362b4 | a4266a01d2dcb10de19369307c986d038c7bb6a6 | refs/heads/master | 1,656,710,827,909 | 1,589,560,456,000 | 1,589,560,456,000 | 264,271,800 | 0 | 0 | Apache-2.0 | 1,589,568,062,000 | 1,589,568,061,000 | null | UTF-8 | Lean | false | false | 9,769 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Simon Hudon, Mario Carneiro
-/
import algebra.group.to_additive
import logic.function.basic
attribute [simp] sub_neg_eq_add
/-!
# Extra identities for semigroups, monoids, and groups
-/
universes u v w
variables {M : Type u} {A : Type v} {G : Type w}
section
set_option default_priority 100
set_option old_structure_cmd true
/-- An algebraic class missing in core: 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. -/
class add_left_cancel_monoid G extends add_left_cancel_semigroup G, add_monoid G
instance ordered_cancel_add_comm_monoid.to_add_left_cancel_monoid [h : ordered_cancel_add_comm_monoid G] :
add_left_cancel_monoid G := { ..h }
instance add_group.to_add_left_cancel_monoid [h : add_group G] :
add_left_cancel_monoid G := { ..h, .. add_group.to_left_cancel_add_semigroup }
end
@[to_additive add_monoid_to_is_left_id]
instance monoid_to_is_left_id [monoid M] : is_left_id M (*) 1 :=
⟨ monoid.one_mul ⟩
@[to_additive add_monoid_to_is_right_id]
instance monoid_to_is_right_id [monoid M] : is_right_id M (*) 1 :=
⟨ monoid.mul_one ⟩
@[to_additive]
theorem mul_right_injective [left_cancel_semigroup M] (a : M) : function.injective ((*) a) :=
λ b c, mul_left_cancel
@[to_additive]
theorem mul_left_injective [right_cancel_semigroup M] (a : M) : function.injective (λ x, x * a) :=
λ b c, mul_right_cancel
@[simp, to_additive]
theorem mul_right_inj [left_cancel_semigroup M] (a : M) {b c : M} : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congr_arg _⟩
@[simp, to_additive]
theorem mul_left_inj [right_cancel_semigroup M] (a : M) {b c : M} : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congr_arg _⟩
@[to_additive]
theorem mul_mul_mul_comm [comm_semigroup M] {a b c d : M} :
(a * b) * (c * d) = (a * c) * (b * d) :=
by simp only [mul_left_comm, mul_assoc]
section group
variables [group G] {a b c : G}
@[simp, to_additive]
theorem inv_inj' : a⁻¹ = b⁻¹ ↔ a = b :=
⟨λ h, by rw [← inv_inv a, h, inv_inv], congr_arg _⟩
@[to_additive]
theorem mul_left_surjective (a : G) : function.surjective ((*) a) :=
λ x, ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩
@[to_additive]
theorem mul_right_surjective (a : G) : function.surjective (λ x, x * a) :=
λ x, ⟨x * a⁻¹, inv_mul_cancel_right x a⟩
@[to_additive]
theorem eq_of_inv_eq_inv : a⁻¹ = b⁻¹ → a = b :=
inv_inj'.1
@[to_additive]
theorem mul_self_iff_eq_one : a * a = a ↔ a = 1 :=
by have := @mul_right_inj _ _ a a 1; rwa mul_one at this
@[simp, to_additive]
theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=
by rw [← @inv_inj' _ _ a 1, one_inv]
@[to_additive]
theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=
not_congr inv_eq_one
@[to_additive]
theorem left_inverse_inv (G) [group G] :
function.left_inverse (λ a : G, a⁻¹) (λ a, a⁻¹) :=
inv_inv
attribute [simp] mul_inv_cancel_left add_neg_cancel_left mul_inv_cancel_right add_neg_cancel_right
@[to_additive]
theorem eq_inv_iff_eq_inv : a = b⁻¹ ↔ b = a⁻¹ :=
⟨eq_inv_of_eq_inv, eq_inv_of_eq_inv⟩
@[to_additive]
theorem inv_eq_iff_inv_eq : a⁻¹ = b ↔ b⁻¹ = a :=
eq_comm.trans $ eq_inv_iff_eq_inv.trans eq_comm
@[to_additive]
theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ :=
by simpa [mul_left_inv, -mul_left_inj] using @mul_left_inj _ _ b a (b⁻¹)
@[to_additive]
theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b :=
by rw [mul_eq_one_iff_eq_inv, eq_inv_iff_eq_inv, eq_comm]
@[to_additive]
theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 :=
mul_eq_one_iff_eq_inv.symm
@[to_additive]
theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 :=
mul_eq_one_iff_inv_eq.symm
@[to_additive]
theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b :=
⟨λ h, by rw [h, inv_mul_cancel_right], λ h, by rw [← h, mul_inv_cancel_right]⟩
@[to_additive]
theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c :=
⟨λ h, by rw [h, mul_inv_cancel_left], λ h, by rw [← h, inv_mul_cancel_left]⟩
@[to_additive]
theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c :=
⟨λ h, by rw [← h, mul_inv_cancel_left], λ h, by rw [h, inv_mul_cancel_left]⟩
@[to_additive]
theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b :=
⟨λ h, by rw [← h, inv_mul_cancel_right], λ h, by rw [h, mul_inv_cancel_right]⟩
@[to_additive]
theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b :=
by rw [mul_eq_one_iff_eq_inv, inv_inv]
@[to_additive]
theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b :=
by rw [mul_eq_one_iff_eq_inv, inv_inj']
@[to_additive]
theorem inv_comm_of_comm (H : a * b = b * a) : a⁻¹ * b = b * a⁻¹ :=
begin
have : a⁻¹ * (b * a) * a⁻¹ = a⁻¹ * (a * b) * a⁻¹ :=
congr_arg (λ x:G, a⁻¹ * x * a⁻¹) H.symm,
rwa [inv_mul_cancel_left, mul_assoc, mul_inv_cancel_right] at this
end
@[simp, to_additive]
lemma mul_left_eq_self : a * b = b ↔ a = 1 :=
⟨λ h, @mul_right_cancel _ _ a b 1 (by simp [h]), λ h, by simp [h]⟩
@[simp, to_additive]
lemma mul_right_eq_self : a * b = a ↔ b = 1 :=
⟨λ h, @mul_left_cancel _ _ a b 1 (by simp [h]), λ h, by simp [h]⟩
end group
section add_group
variables [add_group A] {a b c d : A}
local attribute [simp] sub_eq_add_neg
@[simp] lemma sub_right_inj : a - b = a - c ↔ b = c :=
(add_right_inj _).trans neg_inj'
@[simp] lemma sub_left_inj : b - a = c - a ↔ b = c :=
add_left_inj _
lemma sub_add_sub_cancel (a b c : A) : (a - b) + (b - c) = a - c :=
by rw [← add_sub_assoc, sub_add_cancel]
lemma sub_sub_sub_cancel_right (a b c : A) : (a - c) - (b - c) = a - b :=
by rw [← neg_sub c b, sub_neg_eq_add, sub_add_sub_cancel]
theorem sub_sub_assoc_swap : a - (b - c) = a + c - b :=
by simp
theorem sub_eq_zero : a - b = 0 ↔ a = b :=
⟨eq_of_sub_eq_zero, λ h, by rw [h, sub_self]⟩
theorem sub_ne_zero : a - b ≠ 0 ↔ a ≠ b :=
not_congr sub_eq_zero
theorem eq_sub_iff_add_eq : a = b - c ↔ a + c = b :=
eq_add_neg_iff_add_eq
theorem sub_eq_iff_eq_add : a - b = c ↔ a = c + b :=
add_neg_eq_iff_eq_add
theorem eq_iff_eq_of_sub_eq_sub (H : a - b = c - d) : a = b ↔ c = d :=
by rw [← sub_eq_zero, H, sub_eq_zero]
theorem left_inverse_sub_add_left (c : A) : function.left_inverse (λ x, x - c) (λ x, x + c) :=
assume x, add_sub_cancel x c
theorem left_inverse_add_left_sub (c : A) : function.left_inverse (λ x, x + c) (λ x, x - c) :=
assume x, sub_add_cancel x c
theorem left_inverse_add_right_neg_add (c : A) :
function.left_inverse (λ x, c + x) (λ x, - c + x) :=
assume x, add_neg_cancel_left c x
theorem left_inverse_neg_add_add_right (c : A) :
function.left_inverse (λ x, - c + x) (λ x, c + x) :=
assume x, neg_add_cancel_left c x
end add_group
section add_comm_group
variables [add_comm_group A] {a b c : A}
lemma sub_sub_cancel (a b : A) : a - (a - b) = b := sub_sub_self a b
lemma sub_eq_neg_add (a b : A) : a - b = -b + a :=
add_comm _ _
theorem neg_add' (a b : A) : -(a + b) = -a - b := neg_add a b
attribute [simp] zero_sub sub_zero sub_self neg_sub
@[simp]
lemma neg_sub_neg (a b : A) : -a - -b = b - a :=
by simp [sub_eq_neg_add, add_comm]
lemma eq_sub_iff_add_eq' : a = b - c ↔ c + a = b :=
by rw [eq_sub_iff_add_eq, add_comm]
lemma sub_eq_iff_eq_add' : a - b = c ↔ a = b + c :=
by rw [sub_eq_iff_eq_add, add_comm]
attribute [simp] add_sub_cancel sub_add_cancel
attribute [simp] add_sub_add_left_eq_sub add_sub_add_right_eq_sub
@[simp]
lemma add_sub_cancel' (a b : A) : a + b - a = b :=
by rw [sub_eq_neg_add, neg_add_cancel_left]
@[simp]
lemma add_sub_cancel'_right (a b : A) : a + (b - a) = b :=
by rw [← add_sub_assoc, add_sub_cancel']
@[simp] lemma add_add_neg_cancel'_right (a b : A) : a + (b + -a) = b :=
add_sub_cancel'_right a b
lemma sub_right_comm (a b c : A) : a - b - c = a - c - b :=
add_right_comm _ _ _
lemma add_add_sub_cancel (a b c : A) : (a + c) + (b - c) = a + b :=
by rw [add_assoc, add_sub_cancel'_right]
lemma sub_add_add_cancel (a b c : A) : (a - c) + (b + c) = a + b :=
by rw [add_left_comm, sub_add_cancel, add_comm]
lemma sub_add_sub_cancel' (a b c : A) : (a - b) + (c - a) = c - b :=
by rw add_comm; apply sub_add_sub_cancel
lemma add_sub_sub_cancel (a b c : A) : (a + b) - (a - c) = b + c :=
by rw [← sub_add, add_sub_cancel']
lemma sub_sub_sub_cancel_left (a b c : A) : (c - a) - (c - b) = b - a :=
by rw [← neg_sub b c, sub_neg_eq_add, add_comm, sub_add_sub_cancel]
lemma sub_eq_sub_iff_add_eq_add {d : A} :
a - b = c - d ↔ a + d = c + b :=
begin
rw [sub_eq_iff_eq_add, sub_add_eq_add_sub, eq_comm, sub_eq_iff_eq_add'],
simp only [add_comm, eq_comm]
end
lemma sub_eq_sub_iff_sub_eq_sub {d : A} :
a - b = c - d ↔ a - c = b - d :=
by simp [sub_eq_sub_iff_add_eq_add, add_comm]
end add_comm_group
section add_monoid
variables [add_monoid A] {a b c : A}
@[simp] lemma bit0_zero : bit0 (0 : A) = 0 := add_zero _
@[simp] lemma bit1_zero [has_one A] : bit1 (0 : A) = 1 :=
by rw [bit1, bit0_zero, zero_add]
end add_monoid
section monoid
variables [monoid M]
@[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
section comm_monoid
variables [comm_monoid M]
@[to_additive] lemma inv_unique {x y z : M}
(hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (trans (mul_comm _ _) hy) hz
end comm_monoid
@[to_additive]
lemma inv_involutive {α} [group α] : function.involutive (has_inv.inv : α → α) := inv_inv
|
dce09d43ca47441b50cca58acc8a79ef3d715c53 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/finset/sigma.lean | 6b24cf5fc1a91c2b1c1ca4bc612eda122a89e159 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 5,822 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yaël Dillies, Bhavik Mehta
-/
import data.finset.lattice
import data.set.sigma
/-!
# Finite sets in a sigma type
This file defines a few `finset` constructions on `Σ i, α i`.
## Main declarations
* `finset.sigma`: Given a finset `s` in `ι` and finsets `t i` in each `α i`, `s.sigma t` is the
finset of the dependent sum `Σ i, α i`
* `finset.sigma_lift`: Lifts maps `α i → β i → finset (γ i)` to a map
`Σ i, α i → Σ i, β i → finset (Σ i, γ i)`.
## TODO
`finset.sigma_lift` can be generalized to any alternative functor. But to make the generalization
worth it, we must first refactor the functor library so that the `alternative` instance for `finset`
is computable and universe-polymorphic.
-/
open function multiset
variables {ι : Type*}
namespace finset
section sigma
variables {α : ι → Type*} {β : Type*} (s s₁ s₂ : finset ι) (t t₁ t₂ : Π i, finset (α i))
/-- `s.sigma t` is the finset of dependent pairs `⟨i, a⟩` such that `i ∈ s` and `a ∈ t i`. -/
protected def sigma : finset (Σ i, α i) := ⟨_, s.nodup.sigma $ λ i, (t i).nodup⟩
variables {s s₁ s₂ t t₁ t₂}
@[simp] lemma mem_sigma {a : Σ i, α i} : a ∈ s.sigma t ↔ a.1 ∈ s ∧ a.2 ∈ t a.1 := mem_sigma
@[simp, norm_cast] lemma coe_sigma (s : finset ι) (t : Π i, finset (α i)) :
(s.sigma t : set (Σ i, α i)) = (s : set ι).sigma (λ i, t i) :=
set.ext $ λ _, mem_sigma
@[simp] lemma sigma_nonempty : (s.sigma t).nonempty ↔ ∃ i ∈ s, (t i).nonempty :=
by simp [finset.nonempty]
@[simp] lemma sigma_eq_empty : s.sigma t = ∅ ↔ ∀ i ∈ s, t i = ∅ :=
by simp only [← not_nonempty_iff_eq_empty, sigma_nonempty, not_exists]
@[mono] lemma sigma_mono (hs : s₁ ⊆ s₂) (ht : ∀ i, t₁ i ⊆ t₂ i) : s₁.sigma t₁ ⊆ s₂.sigma t₂ :=
λ ⟨i, a⟩ h, let ⟨hi, ha⟩ := mem_sigma.1 h in mem_sigma.2 ⟨hs hi, ht i ha⟩
lemma sigma_eq_bUnion [decidable_eq (Σ i, α i)] (s : finset ι) (t : Π i, finset (α i)) :
s.sigma t = s.bUnion (λ i, (t i).map $ embedding.sigma_mk i) :=
by { ext ⟨x, y⟩, simp [and.left_comm] }
variables (s t) (f : (Σ i, α i) → β)
lemma sup_sigma [semilattice_sup β] [order_bot β] :
(s.sigma t).sup f = s.sup (λ i, (t i).sup $ λ b, f ⟨i, b⟩) :=
begin
refine (sup_le _).antisymm (sup_le $ λ i hi, sup_le $ λ b hb, le_sup $ mem_sigma.2 ⟨hi, hb⟩),
rintro ⟨i, b⟩ hb,
rw mem_sigma at hb,
refine le_trans _ (le_sup hb.1),
convert le_sup hb.2,
end
lemma inf_sigma [semilattice_inf β] [order_top β] :
(s.sigma t).inf f = s.inf (λ i, (t i).inf $ λ b, f ⟨i, b⟩) :=
@sup_sigma _ _ βᵒᵈ _ _ _ _ _
end sigma
section sigma_lift
variables {α β γ : ι → Type*} [decidable_eq ι]
/-- Lifts maps `α i → β i → finset (γ i)` to a map `Σ i, α i → Σ i, β i → finset (Σ i, γ i)`. -/
def sigma_lift (f : Π ⦃i⦄, α i → β i → finset (γ i)) (a : sigma α) (b : sigma β) :
finset (sigma γ) :=
dite (a.1 = b.1) (λ h, (f (h.rec a.2) b.2).map $ embedding.sigma_mk _) (λ _, ∅)
lemma mem_sigma_lift (f : Π ⦃i⦄, α i → β i → finset (γ i))
(a : sigma α) (b : sigma β) (x : sigma γ) :
x ∈ sigma_lift f a b ↔ ∃ (ha : a.1 = x.1) (hb : b.1 = x.1), x.2 ∈ f (ha.rec a.2) (hb.rec b.2) :=
begin
obtain ⟨⟨i, a⟩, j, b⟩ := ⟨a, b⟩,
obtain rfl | h := decidable.eq_or_ne i j,
{ split,
{ simp_rw [sigma_lift, dif_pos rfl, mem_map, embedding.sigma_mk_apply],
rintro ⟨x, hx, rfl⟩,
exact ⟨rfl, rfl, hx⟩ },
{ rintro ⟨⟨⟩, ⟨⟩, hx⟩,
rw [sigma_lift, dif_pos rfl, mem_map],
exact ⟨_, hx, by simp [sigma.ext_iff]⟩ } },
{ rw [sigma_lift, dif_neg h],
refine iff_of_false (not_mem_empty _) _,
rintro ⟨⟨⟩, ⟨⟩, _⟩,
exact h rfl }
end
lemma mk_mem_sigma_lift (f : Π ⦃i⦄, α i → β i → finset (γ i)) (i : ι) (a : α i) (b : β i)
(x : γ i) :
(⟨i, x⟩ : sigma γ) ∈ sigma_lift f ⟨i, a⟩ ⟨i, b⟩ ↔ x ∈ f a b :=
begin
rw [sigma_lift, dif_pos rfl, mem_map],
refine ⟨_, λ hx, ⟨_, hx, rfl⟩⟩,
rintro ⟨x, hx, _, rfl⟩,
exact hx,
end
lemma not_mem_sigma_lift_of_ne_left (f : Π ⦃i⦄, α i → β i → finset (γ i))
(a : sigma α) (b : sigma β) (x : sigma γ) (h : a.1 ≠ x.1) :
x ∉ sigma_lift f a b :=
by { rw mem_sigma_lift, exact λ H, h H.fst }
lemma not_mem_sigma_lift_of_ne_right (f : Π ⦃i⦄, α i → β i → finset (γ i))
{a : sigma α} (b : sigma β) {x : sigma γ} (h : b.1 ≠ x.1) :
x ∉ sigma_lift f a b :=
by { rw mem_sigma_lift, exact λ H, h H.snd.fst }
variables {f g : Π ⦃i⦄, α i → β i → finset (γ i)} {a : Σ i, α i} {b : Σ i, β i}
lemma sigma_lift_nonempty :
(sigma_lift f a b).nonempty ↔ ∃ h : a.1 = b.1, (f (h.rec a.2) b.2).nonempty :=
begin
simp_rw nonempty_iff_ne_empty,
convert dite_ne_right_iff,
ext h,
simp_rw ←nonempty_iff_ne_empty,
exact map_nonempty.symm,
end
lemma sigma_lift_eq_empty : (sigma_lift f a b) = ∅ ↔ ∀ h : a.1 = b.1, (f (h.rec a.2) b.2) = ∅ :=
begin
convert dite_eq_right_iff,
exact forall_congr_eq (λ h, propext map_eq_empty.symm),
end
lemma sigma_lift_mono (h : ∀ ⦃i⦄ ⦃a : α i⦄ ⦃b : β i⦄, f a b ⊆ g a b) (a : Σ i, α i) (b : Σ i, β i) :
sigma_lift f a b ⊆ sigma_lift g a b :=
begin
rintro x hx,
rw mem_sigma_lift at ⊢ hx,
obtain ⟨ha, hb, hx⟩ := hx,
exact ⟨ha, hb, h hx⟩,
end
variables (f a b)
lemma card_sigma_lift :
(sigma_lift f a b).card = dite (a.1 = b.1) (λ h, (f (h.rec a.2) b.2).card) (λ _, 0) :=
by { convert apply_dite _ _ _ _, ext h, exact (card_map _).symm }
end sigma_lift
end finset
|
f8169f0394b6fd64e6f7d7bc0923d60631a0bf1a | ea11767c9c6a467c4b7710ec6f371c95cfc023fd | /src/monoidal_categories/examples/types/monoidal_category_of_types.lean | dd155d68c86afa0ded0f6203b885b94fb36dc654 | [] | 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 | 686 | 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 ...braided_monoidal_category
import ...monoidal_structure_from_products
import categories.types
namespace categories.types
open categories
open categories.monoidal_category
open categories.braided_monoidal_category
definition MonoidalCategoryOfTypes : MonoidalStructure CategoryOfTypes := MonoidalStructure_from_Products CategoryOfTypes
definition SymmetricMonoidalCategoryOfTypes : Symmetry MonoidalCategoryOfTypes := Symmetry_on_MonoidalStructure_from_Products CategoryOfTypes
end categories.types
|
29c0c840114ae490f6ab00e77cc935cd63c1af39 | ebf7140a9ea507409ff4c994124fa36e79b4ae35 | /src/hints/category_theory/exercise3/hint6.lean | 1e7a339977c0d03f1523ac608c78e1aefc6c890f | [] | no_license | fundou/lftcm2020 | 3e88d58a92755ea5dd49f19c36239c35286ecf5e | 99d11bf3bcd71ffeaef0250caa08ecc46e69b55b | refs/heads/master | 1,685,610,799,304 | 1,624,070,416,000 | 1,624,070,416,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 574 | lean | import category_theory.equivalence
open category_theory
variables {C : Type*} [category C]
variables {D : Type*} [category D]
/-!
Let's get started on the second half of the exercise.
-/
lemma equiv_preserves_mono {X Y : C} (f : X ⟶ Y) [mono f] (e : C ≌ D) :
mono (e.functor.map f) :=
begin
-- Again I've started with:
tidy,
-- Now we want to map the equation in `w` over to `C`.
-- This is actually a bit of a hassle, and probably deserves custom tactic support. Want to help?
replace w := congr_arg (λ k, e.inverse.map k) w,
simp at w,
sorry
end
|
2b11fe978f3f060a4121848b85b5004b5b9d043c | a4673261e60b025e2c8c825dfa4ab9108246c32e | /stage0/src/Lean/ToExpr.lean | fcefb058763d2b3dab9dd503807656dc4ff95102 | [
"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 | 2,697 | 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
universe u
namespace Lean
class ToExpr (α : Type u) :=
(toExpr : α → Expr)
(toTypeExpr : Expr)
export ToExpr (toExpr toTypeExpr)
instance : ToExpr Expr := {
toExpr := id,
toTypeExpr := mkConst `Expr
}
instance : ToExpr Nat := {
toExpr := mkNatLit,
toTypeExpr := mkConst `Nat
}
instance : ToExpr Bool := {
toExpr := fun b => if b then mkConst `Bool.true else mkConst `Bool.false,
toTypeExpr := mkConst `Bool
}
instance : ToExpr Char := {
toExpr := fun c => mkApp (mkConst `Char.ofNat) (toExpr c.toNat),
toTypeExpr := mkConst `Char
}
instance : ToExpr String := {
toExpr := mkStrLit,
toTypeExpr := mkConst `String
}
instance : ToExpr Unit := {
toExpr := fun _ => mkConst `Unit.unit,
toTypeExpr := mkConst `Unit
}
def Name.toExprAux : Name → Expr
| Name.anonymous => mkConst `Lean.Name.anonymous
| Name.str p s _ => mkAppB (mkConst `Lean.Name.mkStr) (toExprAux p) (toExpr s)
| Name.num p n _ => mkAppB (mkConst `Lean.Name.mkNum) (toExprAux p) (toExpr n)
instance : ToExpr Name := {
toExpr := Name.toExprAux,
toTypeExpr := mkConst `Name
}
instance {α : Type} [ToExpr α] : ToExpr (Option α) :=
let type := toTypeExpr α
{ toExpr := fun o => match o with
| none => mkApp (mkConst `Option.none [levelZero]) type
| some a => mkApp2 (mkConst `Option.cons [levelZero]) type (toExpr a),
toTypeExpr := mkApp (mkConst `Option [levelZero]) type }
def List.toExprAux {α} [ToExpr α] (nilFn : Expr) (consFn : Expr) : List α → Expr
| [] => nilFn
| a::as => mkApp2 consFn (toExpr a) (toExprAux nilFn consFn as)
instance {α : Type} [ToExpr α] : ToExpr (List α) :=
let type := toTypeExpr α
let nil := mkApp (mkConst `List.nil [levelZero]) type
let cons := mkApp (mkConst `List.cons [levelZero]) type
{ toExpr := List.toExprAux nil cons,
toTypeExpr := mkApp (mkConst `List [levelZero]) type }
instance {α : Type} [ToExpr α] : ToExpr (Array α) :=
let type := toTypeExpr α
{ toExpr := fun as => mkApp2 (mkConst `List.toArray [levelZero]) type (toExpr as.toList),
toTypeExpr := mkApp (mkConst `Array [levelZero]) type }
instance {α : Type} {β : Type} [ToExpr α] [ToExpr β] : ToExpr (α × β) :=
let αType := toTypeExpr α
let βType := toTypeExpr β
{ toExpr := fun ⟨a, b⟩ => mkApp4 (mkConst `Prod.mk [levelZero, levelZero]) αType βType (toExpr a) (toExpr b),
toTypeExpr := mkApp2 (mkConst `Prod [levelZero, levelZero]) αType βType }
end Lean
|
79be5ea330d59bb048a3b298a169756d92e6a013 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/ring_theory/simple_module.lean | 86aa419277002afd04885167f791303b8a9c35a4 | [
"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,319 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import linear_algebra.basic
import order.atoms
/-!
# Simple Modules
## Main Definitions
* `is_simple_module` indicates that a module has no proper submodules
(the only submodules are `⊥` and `⊤`).
* `is_semisimple_module` indicates that every submodule has a complement, or equivalently,
the module is a direct sum of simple modules.
* A `division_ring` structure on the endomorphism ring of a simple module.
## Main Results
* Schur's Lemma: `bijective_or_eq_zero` shows that a linear map between simple modules
is either bijective or 0, leading to a `division_ring` structure on the endomorphism ring.
## TODO
* Artin-Wedderburn Theory
* Unify with the work on Schur's Lemma in a category theory context
-/
variables (R : Type*) [ring R] (M : Type*) [add_comm_group M] [module R M]
/-- A module is simple when it has only two submodules, `⊥` and `⊤`. -/
abbreviation is_simple_module := (is_simple_lattice (submodule R M))
/-- A module is semisimple when every submodule has a complement, or equivalently, the module
is a direct sum of simple modules. -/
abbreviation is_semisimple_module := (is_complemented (submodule R M))
-- Making this an instance causes the linter to complain of "dangerous instances"
theorem is_simple_module.nontrivial [is_simple_module R M] : nontrivial M :=
⟨⟨0, begin
have h : (⊥ : submodule R M) ≠ ⊤ := bot_ne_top,
contrapose! h,
ext,
simp [submodule.mem_bot,submodule.mem_top, h x],
end⟩⟩
variables {R} {M} {m : submodule R M} {N : Type*} [add_comm_group N] [module R N]
theorem is_simple_module_iff_is_atom :
is_simple_module R m ↔ is_atom m :=
begin
rw ← set.is_simple_lattice_Iic_iff_is_atom,
apply order_iso.is_simple_lattice_iff,
exact submodule.map_subtype.rel_iso m,
end
namespace is_simple_module
variable [hm : is_simple_module R m]
@[simp]
lemma is_atom : is_atom m := is_simple_module_iff_is_atom.1 hm
end is_simple_module
theorem is_semisimple_of_Sup_simples_eq_top
(h : Sup {m : submodule R M | is_simple_module R m} = ⊤) :
is_semisimple_module R M :=
is_complemented_of_Sup_atoms_eq_top (by simp_rw [← h, is_simple_module_iff_is_atom])
namespace is_semisimple_module
variable [is_semisimple_module R M]
theorem Sup_simples_eq_top : Sup {m : submodule R M | is_simple_module R m} = ⊤ :=
begin
simp_rw is_simple_module_iff_is_atom,
exact Sup_atoms_eq_top,
end
instance is_semisimple_submodule {m : submodule R M} : is_semisimple_module R m :=
begin
have f : submodule R m ≃o set.Iic m := submodule.map_subtype.rel_iso m,
exact f.is_complemented_iff.2 is_modular_lattice.is_complemented_Iic,
end
end is_semisimple_module
theorem is_semisimple_iff_top_eq_Sup_simples :
Sup {m : submodule R M | is_simple_module R m} = ⊤ ↔ is_semisimple_module R M :=
⟨is_semisimple_of_Sup_simples_eq_top, by { introI, exact is_semisimple_module.Sup_simples_eq_top }⟩
namespace linear_map
theorem injective_or_eq_zero [is_simple_module R M] (f : M →ₗ[R] N) :
function.injective f ∨ f = 0 :=
begin
rw [← ker_eq_bot, ← ker_eq_top],
apply eq_bot_or_eq_top,
end
theorem injective_of_ne_zero [is_simple_module R M] {f : M →ₗ[R] N} (h : f ≠ 0) :
function.injective f :=
f.injective_or_eq_zero.resolve_right h
theorem surjective_or_eq_zero [is_simple_module R N] (f : M →ₗ[R] N) :
function.surjective f ∨ f = 0 :=
begin
rw [← range_eq_top, ← range_eq_bot, or_comm],
apply eq_bot_or_eq_top,
end
theorem surjective_of_ne_zero [is_simple_module R N] {f : M →ₗ[R] N} (h : f ≠ 0) :
function.surjective f :=
f.surjective_or_eq_zero.resolve_right h
/-- Schur's Lemma for linear maps between (possibly distinct) simple modules -/
theorem bijective_or_eq_zero [is_simple_module R M] [is_simple_module R N]
(f : M →ₗ[R] N) :
function.bijective f ∨ f = 0 :=
begin
by_cases h : f = 0,
{ right,
exact h },
exact or.intro_left _ ⟨injective_of_ne_zero h, surjective_of_ne_zero h⟩,
end
theorem bijective_of_ne_zero [is_simple_module R M] [is_simple_module R N]
{f : M →ₗ[R] N} (h : f ≠ 0):
function.bijective f :=
f.bijective_or_eq_zero.resolve_right h
/-- Schur's Lemma makes the endomorphism ring of a simple module a division ring. -/
noncomputable instance [decidable_eq (module.End R M)] [is_simple_module R M] :
division_ring (module.End R M) :=
{ inv := λ f, if h : f = 0 then 0 else (linear_map.inverse f
(equiv.of_bijective _ (bijective_of_ne_zero h)).inv_fun
(equiv.of_bijective _ (bijective_of_ne_zero h)).left_inv
(equiv.of_bijective _ (bijective_of_ne_zero h)).right_inv),
exists_pair_ne := ⟨0, 1, begin
haveI := is_simple_module.nontrivial R M,
have h := exists_pair_ne M,
contrapose! h,
intros x y,
simp_rw [ext_iff, one_apply, zero_apply] at h,
rw [← h x, h y],
end⟩,
mul_inv_cancel := begin
intros a a0,
change (a * (dite _ _ _)) = 1,
ext,
rw [dif_neg a0, mul_eq_comp, one_apply, comp_apply],
exact (equiv.of_bijective _ (bijective_of_ne_zero a0)).right_inv x,
end,
inv_zero := dif_pos rfl,
.. (linear_map.endomorphism_ring : ring (module.End R M))}
end linear_map
|
8748457a236594403b40367e9b21ea4d6e3b80cd | 367134ba5a65885e863bdc4507601606690974c1 | /src/topology/metric_space/isometry.lean | 8bf04ee6637d2a6b9617575b85dd14a063a56665 | [
"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 | 18,952 | lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Isometries of emetric and metric spaces
Authors: Sébastien Gouëzel
-/
import topology.bounded_continuous_function
import topology.compacts
/-!
# Isometries
We define isometries, i.e., maps between emetric spaces that preserve
the edistance (on metric spaces, these are exactly the maps that preserve distances),
and prove their basic properties. We also introduce isometric bijections.
-/
noncomputable theory
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
open function set
/-- An isometry (also known as isometric embedding) is a map preserving the edistance
between emetric spaces, or equivalently the distance between metric space. -/
def isometry [emetric_space α] [emetric_space β] (f : α → β) : Prop :=
∀x1 x2 : α, edist (f x1) (f x2) = edist x1 x2
/-- On metric spaces, a map is an isometry if and only if it preserves distances. -/
lemma isometry_emetric_iff_metric [metric_space α] [metric_space β] {f : α → β} :
isometry f ↔ (∀x y, dist (f x) (f y) = dist x y) :=
⟨assume H x y, by simp [dist_edist, H x y],
assume H x y, by simp [edist_dist, H x y]⟩
/-- An isometry preserves edistances. -/
theorem isometry.edist_eq [emetric_space α] [emetric_space β] {f : α → β} (hf : isometry f)
(x y : α) :
edist (f x) (f y) = edist x y :=
hf x y
/-- An isometry preserves distances. -/
theorem isometry.dist_eq [metric_space α] [metric_space β] {f : α → β} (hf : isometry f) (x y : α) :
dist (f x) (f y) = dist x y :=
by rw [dist_edist, dist_edist, hf]
section emetric_isometry
variables [emetric_space α] [emetric_space β] [emetric_space γ]
variables {f : α → β} {x y z : α} {s : set α}
lemma isometry.lipschitz (h : isometry f) : lipschitz_with 1 f :=
lipschitz_with.of_edist_le $ λ x y, le_of_eq (h x y)
lemma isometry.antilipschitz (h : isometry f) : antilipschitz_with 1 f :=
λ x y, by simp only [h x y, ennreal.coe_one, one_mul, le_refl]
/-- An isometry is injective -/
lemma isometry.injective (h : isometry f) : injective f := h.antilipschitz.injective
/-- Any map on a subsingleton is an isometry -/
theorem isometry_subsingleton [subsingleton α] : isometry f :=
λx y, by rw subsingleton.elim x y; simp
/-- The identity is an isometry -/
lemma isometry_id : isometry (id : α → α) :=
λx y, rfl
/-- The composition of isometries is an isometry -/
theorem isometry.comp {g : β → γ} {f : α → β} (hg : isometry g) (hf : isometry f) :
isometry (g ∘ f) :=
assume x y, calc
edist ((g ∘ f) x) ((g ∘ f) y) = edist (f x) (f y) : hg _ _
... = edist x y : hf _ _
/-- An isometry is an embedding -/
theorem isometry.uniform_embedding (hf : isometry f) : uniform_embedding f :=
hf.antilipschitz.uniform_embedding hf.lipschitz.uniform_continuous
/-- An isometry is continuous. -/
lemma isometry.continuous (hf : isometry f) : continuous f :=
hf.lipschitz.continuous
/-- The right inverse of an isometry is an isometry. -/
lemma isometry.right_inv {f : α → β} {g : β → α} (h : isometry f) (hg : right_inverse g f) :
isometry g :=
λ x y, by rw [← h, hg _, hg _]
/-- Isometries preserve the diameter in emetric spaces. -/
lemma isometry.ediam_image (hf : isometry f) (s : set α) :
emetric.diam (f '' s) = emetric.diam s :=
eq_of_forall_ge_iff $ λ d,
by simp only [emetric.diam_le_iff_forall_edist_le, ball_image_iff, hf.edist_eq]
lemma isometry.ediam_range (hf : isometry f) :
emetric.diam (range f) = emetric.diam (univ : set α) :=
by { rw ← image_univ, exact hf.ediam_image univ }
/-- The injection from a subtype is an isometry -/
lemma isometry_subtype_coe {s : set α} : isometry (coe : s → α) :=
λx y, rfl
lemma isometry.comp_continuous_on_iff {γ} [topological_space γ] (hf : isometry f)
{g : γ → α} {s : set γ} :
continuous_on (f ∘ g) s ↔ continuous_on g s :=
hf.uniform_embedding.to_uniform_inducing.inducing.continuous_on_iff.symm
lemma isometry.comp_continuous_iff {γ} [topological_space γ] (hf : isometry f) {g : γ → α} :
continuous (f ∘ g) ↔ continuous g :=
hf.uniform_embedding.to_uniform_inducing.inducing.continuous_iff.symm
end emetric_isometry --section
/-- An isometry preserves the diameter in metric spaces. -/
lemma isometry.diam_image [metric_space α] [metric_space β]
{f : α → β} (hf : isometry f) (s : set α) : metric.diam (f '' s) = metric.diam s :=
by rw [metric.diam, metric.diam, hf.ediam_image]
lemma isometry.diam_range [metric_space α] [metric_space β] {f : α → β} (hf : isometry f) :
metric.diam (range f) = metric.diam (univ : set α) :=
by { rw ← image_univ, exact hf.diam_image univ }
namespace add_monoid_hom
variables {E F : Type*} [normed_group E] [normed_group F]
lemma isometry_iff_norm (f : E →+ F) : isometry f ↔ ∀ x, ∥f x∥ = ∥x∥ :=
begin
simp only [isometry_emetric_iff_metric, dist_eq_norm, ← f.map_sub],
refine ⟨λ h x, _, λ h x y, h _⟩,
simpa using h x 0
end
lemma isometry_of_norm (f : E →+ F) (hf : ∀ x, ∥f x∥ = ∥x∥) : isometry f :=
f.isometry_iff_norm.2 hf
end add_monoid_hom
/-- `α` and `β` are isometric if there is an isometric bijection between them. -/
@[nolint has_inhabited_instance] -- such a bijection need not exist
structure isometric (α : Type*) (β : Type*) [emetric_space α] [emetric_space β]
extends α ≃ β :=
(isometry_to_fun : isometry to_fun)
infix ` ≃ᵢ `:25 := isometric
namespace isometric
variables [emetric_space α] [emetric_space β] [emetric_space γ]
instance : has_coe_to_fun (α ≃ᵢ β) := ⟨λ_, α → β, λe, e.to_equiv⟩
lemma coe_eq_to_equiv (h : α ≃ᵢ β) (a : α) : h a = h.to_equiv a := rfl
@[simp] lemma coe_to_equiv (h : α ≃ᵢ β) : ⇑h.to_equiv = h := rfl
protected lemma isometry (h : α ≃ᵢ β) : isometry h := h.isometry_to_fun
protected lemma edist_eq (h : α ≃ᵢ β) (x y : α) : edist (h x) (h y) = edist x y :=
h.isometry.edist_eq x y
protected lemma dist_eq {α β : Type*} [metric_space α] [metric_space β] (h : α ≃ᵢ β) (x y : α) :
dist (h x) (h y) = dist x y :=
h.isometry.dist_eq x y
protected lemma continuous (h : α ≃ᵢ β) : continuous h := h.isometry.continuous
@[simp] lemma ediam_image (h : α ≃ᵢ β) (s : set α) : emetric.diam (h '' s) = emetric.diam s :=
h.isometry.ediam_image s
lemma to_equiv_inj : ∀ ⦃h₁ h₂ : α ≃ᵢ β⦄, (h₁.to_equiv = h₂.to_equiv) → h₁ = h₂
| ⟨e₁, h₁⟩ ⟨e₂, h₂⟩ H := by { dsimp at H, subst e₁ }
@[ext] lemma ext ⦃h₁ h₂ : α ≃ᵢ β⦄ (H : ∀ x, h₁ x = h₂ x) : h₁ = h₂ :=
to_equiv_inj $ equiv.ext H
/-- Alternative constructor for isometric bijections,
taking as input an isometry, and a right inverse. -/
def mk' (f : α → β) (g : β → α) (hfg : ∀ x, f (g x) = x) (hf : isometry f) : α ≃ᵢ β :=
{ to_fun := f,
inv_fun := g,
left_inv := λ x, hf.injective $ hfg _,
right_inv := hfg,
isometry_to_fun := hf }
/-- The identity isometry of a space. -/
protected def refl (α : Type*) [emetric_space α] : α ≃ᵢ α :=
{ isometry_to_fun := isometry_id, .. equiv.refl α }
/-- The composition of two isometric isomorphisms, as an isometric isomorphism. -/
protected def trans (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) : α ≃ᵢ γ :=
{ isometry_to_fun := h₂.isometry_to_fun.comp h₁.isometry_to_fun,
.. equiv.trans h₁.to_equiv h₂.to_equiv }
@[simp] lemma trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : α) : h₁.trans h₂ x = h₂ (h₁ x) := rfl
/-- The inverse of an isometric isomorphism, as an isometric isomorphism. -/
protected def symm (h : α ≃ᵢ β) : β ≃ᵢ α :=
{ isometry_to_fun := h.isometry.right_inv h.right_inv,
to_equiv := h.to_equiv.symm }
@[simp] lemma symm_symm (h : α ≃ᵢ β) : h.symm.symm = h := to_equiv_inj h.to_equiv.symm_symm
@[simp] lemma apply_symm_apply (h : α ≃ᵢ β) (y : β) : h (h.symm y) = y :=
h.to_equiv.apply_symm_apply y
@[simp] lemma symm_apply_apply (h : α ≃ᵢ β) (x : α) : h.symm (h x) = x :=
h.to_equiv.symm_apply_apply x
lemma symm_apply_eq (h : α ≃ᵢ β) {x : α} {y : β} :
h.symm y = x ↔ y = h x :=
h.to_equiv.symm_apply_eq
lemma eq_symm_apply (h : α ≃ᵢ β) {x : α} {y : β} :
x = h.symm y ↔ h x = y :=
h.to_equiv.eq_symm_apply
lemma symm_comp_self (h : α ≃ᵢ β) : ⇑h.symm ∘ ⇑h = id :=
funext $ assume a, h.to_equiv.left_inv a
lemma self_comp_symm (h : α ≃ᵢ β) : ⇑h ∘ ⇑h.symm = id :=
funext $ assume a, h.to_equiv.right_inv a
@[simp] lemma range_eq_univ (h : α ≃ᵢ β) : range h = univ :=
eq_univ_of_forall $ assume b, ⟨h.symm b, congr_fun h.self_comp_symm b⟩
lemma image_symm (h : α ≃ᵢ β) : image h.symm = preimage h :=
image_eq_preimage_of_inverse h.symm.to_equiv.left_inv h.symm.to_equiv.right_inv
lemma preimage_symm (h : α ≃ᵢ β) : preimage h.symm = image h :=
(image_eq_preimage_of_inverse h.to_equiv.left_inv h.to_equiv.right_inv).symm
@[simp] lemma symm_trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : γ) :
(h₁.trans h₂).symm x = h₁.symm (h₂.symm x) := rfl
lemma ediam_univ (h : α ≃ᵢ β) : emetric.diam (univ : set α) = emetric.diam (univ : set β) :=
by rw [← h.range_eq_univ, h.isometry.ediam_range]
@[simp] lemma ediam_preimage (h : α ≃ᵢ β) (s : set β) : emetric.diam (h ⁻¹' s) = emetric.diam s :=
by rw [← image_symm, ediam_image]
/-- The (bundled) homeomorphism associated to an isometric isomorphism. -/
protected def to_homeomorph (h : α ≃ᵢ β) : α ≃ₜ β :=
{ continuous_to_fun := h.continuous,
continuous_inv_fun := h.symm.continuous,
to_equiv := h.to_equiv }
@[simp] lemma coe_to_homeomorph (h : α ≃ᵢ β) : ⇑(h.to_homeomorph) = h := rfl
@[simp] lemma coe_to_homeomorph_symm (h : α ≃ᵢ β) : ⇑(h.to_homeomorph.symm) = h.symm := rfl
@[simp] lemma to_homeomorph_to_equiv (h : α ≃ᵢ β) :
h.to_homeomorph.to_equiv = h.to_equiv :=
rfl
@[simp] lemma comp_continuous_on_iff {γ} [topological_space γ] (h : α ≃ᵢ β)
{f : γ → α} {s : set γ} :
continuous_on (h ∘ f) s ↔ continuous_on f s :=
h.to_homeomorph.comp_continuous_on_iff _ _
@[simp] lemma comp_continuous_iff {γ} [topological_space γ] (h : α ≃ᵢ β) {f : γ → α} :
continuous (h ∘ f) ↔ continuous f :=
h.to_homeomorph.comp_continuous_iff
@[simp] lemma comp_continuous_iff' {γ} [topological_space γ] (h : α ≃ᵢ β) {f : β → γ} :
continuous (f ∘ h) ↔ continuous f :=
h.to_homeomorph.comp_continuous_iff'
/-- The group of isometries. -/
instance : group (α ≃ᵢ α) :=
{ one := isometric.refl _,
mul := λ e₁ e₂, e₂.trans e₁,
inv := isometric.symm,
mul_assoc := λ e₁ e₂ e₃, rfl,
one_mul := λ e, ext $ λ _, rfl,
mul_one := λ e, ext $ λ _, rfl,
mul_left_inv := λ e, ext e.symm_apply_apply }
@[simp] lemma coe_one : ⇑(1 : α ≃ᵢ α) = id := rfl
@[simp] lemma coe_mul (e₁ e₂ : α ≃ᵢ α) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl
lemma mul_apply (e₁ e₂ : α ≃ᵢ α) (x : α) : (e₁ * e₂) x = e₁ (e₂ x) := rfl
@[simp] lemma inv_apply_self (e : α ≃ᵢ α) (x: α) : e⁻¹ (e x) = x := e.symm_apply_apply x
@[simp] lemma apply_inv_self (e : α ≃ᵢ α) (x: α) : e (e⁻¹ x) = x := e.apply_symm_apply x
section normed_group
variables {G : Type*} [normed_group G]
/-- Addition `y ↦ y + x` as an `isometry`. -/
protected def add_right (x : G) : G ≃ᵢ G :=
{ isometry_to_fun := isometry_emetric_iff_metric.2 $ λ y z, dist_add_right _ _ _,
.. equiv.add_right x }
@[simp] lemma add_right_to_equiv (x : G) :
(isometric.add_right x).to_equiv = equiv.add_right x := rfl
@[simp] lemma coe_add_right (x : G) : (isometric.add_right x : G → G) = λ y, y + x := rfl
lemma add_right_apply (x y : G) : (isometric.add_right x : G → G) y = y + x := rfl
@[simp] lemma add_right_symm (x : G) :
(isometric.add_right x).symm = isometric.add_right (-x) :=
ext $ λ y, rfl
/-- Addition `y ↦ x + y` as an `isometry`. -/
protected def add_left (x : G) : G ≃ᵢ G :=
{ isometry_to_fun := isometry_emetric_iff_metric.2 $ λ y z, dist_add_left _ _ _,
to_equiv := equiv.add_left x }
@[simp] lemma add_left_to_equiv (x : G) :
(isometric.add_left x).to_equiv = equiv.add_left x := rfl
@[simp] lemma coe_add_left (x : G) : ⇑(isometric.add_left x) = (+) x := rfl
@[simp] lemma add_left_symm (x : G) :
(isometric.add_left x).symm = isometric.add_left (-x) :=
ext $ λ y, rfl
variable (G)
/-- Negation `x ↦ -x` as an `isometry`. -/
protected def neg : G ≃ᵢ G :=
{ isometry_to_fun := isometry_emetric_iff_metric.2 $ λ x y, dist_neg_neg _ _,
to_equiv := equiv.neg G }
variable {G}
@[simp] lemma neg_symm : (isometric.neg G).symm = isometric.neg G := rfl
@[simp] lemma neg_to_equiv : (isometric.neg G).to_equiv = equiv.neg G := rfl
@[simp] lemma coe_neg : ⇑(isometric.neg G) = has_neg.neg := rfl
end normed_group
end isometric
namespace isometric
variables [metric_space α] [metric_space β] (h : α ≃ᵢ β)
@[simp] lemma diam_image (s : set α) : metric.diam (h '' s) = metric.diam s :=
h.isometry.diam_image s
@[simp] lemma diam_preimage (s : set β) : metric.diam (h ⁻¹' s) = metric.diam s :=
by rw [← image_symm, diam_image]
lemma diam_univ : metric.diam (univ : set α) = metric.diam (univ : set β) :=
congr_arg ennreal.to_real h.ediam_univ
end isometric
/-- An isometry induces an isometric isomorphism between the source space and the
range of the isometry. -/
def isometry.isometric_on_range [emetric_space α] [emetric_space β] {f : α → β} (h : isometry f) :
α ≃ᵢ range f :=
{ isometry_to_fun := λx y, by simpa [subtype.edist_eq] using h x y,
.. equiv.set.range f h.injective }
@[simp] lemma isometry.isometric_on_range_apply [emetric_space α] [emetric_space β]
{f : α → β} (h : isometry f) (x : α) : h.isometric_on_range x = ⟨f x, mem_range_self _⟩ :=
rfl
/-- In a normed algebra, the inclusion of the base field in the extended field is an isometry. -/
lemma algebra_map_isometry (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜] [normed_ring 𝕜']
[normed_algebra 𝕜 𝕜'] : isometry (algebra_map 𝕜 𝕜') :=
begin
refine isometry_emetric_iff_metric.2 (λx y, _),
rw [dist_eq_norm, dist_eq_norm, ← ring_hom.map_sub, norm_algebra_map_eq],
end
/-- The space of bounded sequences, with its sup norm -/
@[reducible] def ℓ_infty_ℝ : Type := bounded_continuous_function ℕ ℝ
open bounded_continuous_function metric topological_space
namespace Kuratowski_embedding
/-! ### In this section, we show that any separable metric space can be embedded isometrically in ℓ^∞(ℝ) -/
variables {f g : ℓ_infty_ℝ} {n : ℕ} {C : ℝ} [metric_space α] (x : ℕ → α) (a b : α)
/-- A metric space can be embedded in `l^∞(ℝ)` via the distances to points in
a fixed countable set, if this set is dense. This map is given in the next definition,
without density assumptions. -/
def embedding_of_subset : ℓ_infty_ℝ :=
of_normed_group_discrete (λn, dist a (x n) - dist (x 0) (x n)) (dist a (x 0))
(λ_, abs_dist_sub_le _ _ _)
lemma embedding_of_subset_coe : embedding_of_subset x a n = dist a (x n) - dist (x 0) (x n) := rfl
/-- The embedding map is always a semi-contraction. -/
lemma embedding_of_subset_dist_le (a b : α) :
dist (embedding_of_subset x a) (embedding_of_subset x b) ≤ dist a b :=
begin
refine (dist_le dist_nonneg).2 (λn, _),
simp only [embedding_of_subset_coe, real.dist_eq],
convert abs_dist_sub_le a b (x n) using 2,
ring
end
/-- When the reference set is dense, the embedding map is an isometry on its image. -/
lemma embedding_of_subset_isometry (H : dense_range x) : isometry (embedding_of_subset x) :=
begin
refine isometry_emetric_iff_metric.2 (λa b, _),
refine (embedding_of_subset_dist_le x a b).antisymm (le_of_forall_pos_le_add (λe epos, _)),
/- First step: find n with dist a (x n) < e -/
rcases metric.mem_closure_range_iff.1 (H a) (e/2) (half_pos epos) with ⟨n, hn⟩,
/- Second step: use the norm control at index n to conclude -/
have C : dist b (x n) - dist a (x n) = embedding_of_subset x b n - embedding_of_subset x a n :=
by { simp only [embedding_of_subset_coe, sub_sub_sub_cancel_right] },
have := calc
dist a b ≤ dist a (x n) + dist (x n) b : dist_triangle _ _ _
... = 2 * dist a (x n) + (dist b (x n) - dist a (x n)) : by { simp [dist_comm], ring }
... ≤ 2 * dist a (x n) + abs (dist b (x n) - dist a (x n)) :
by apply_rules [add_le_add_left, le_abs_self]
... ≤ 2 * (e/2) + abs (embedding_of_subset x b n - embedding_of_subset x a n) :
begin rw C, apply_rules [add_le_add, mul_le_mul_of_nonneg_left, hn.le, le_refl], norm_num end
... ≤ 2 * (e/2) + dist (embedding_of_subset x b) (embedding_of_subset x a) :
by simp [← real.dist_eq, dist_coe_le_dist]
... = dist (embedding_of_subset x b) (embedding_of_subset x a) + e : by ring,
simpa [dist_comm] using this
end
/-- Every separable metric space embeds isometrically in ℓ_infty_ℝ. -/
theorem exists_isometric_embedding (α : Type u) [metric_space α] [separable_space α] :
∃(f : α → ℓ_infty_ℝ), isometry f :=
begin
cases (univ : set α).eq_empty_or_nonempty with h h,
{ use (λ_, 0), assume x, exact absurd h (nonempty.ne_empty ⟨x, mem_univ x⟩) },
{ /- We construct a map x : ℕ → α with dense image -/
rcases h with ⟨basepoint⟩,
haveI : inhabited α := ⟨basepoint⟩,
have : ∃s:set α, countable s ∧ dense s := exists_countable_dense α,
rcases this with ⟨S, ⟨S_countable, S_dense⟩⟩,
rcases countable_iff_exists_surjective.1 S_countable with ⟨x, x_range⟩,
/- Use embedding_of_subset to construct the desired isometry -/
exact ⟨embedding_of_subset x, embedding_of_subset_isometry x (S_dense.mono x_range)⟩ }
end
end Kuratowski_embedding
open topological_space Kuratowski_embedding
/-- The Kuratowski embedding is an isometric embedding of a separable metric space in ℓ^∞(ℝ) -/
def Kuratowski_embedding (α : Type u) [metric_space α] [separable_space α] : α → ℓ_infty_ℝ :=
classical.some (Kuratowski_embedding.exists_isometric_embedding α)
/-- The Kuratowski embedding is an isometry -/
protected lemma Kuratowski_embedding.isometry (α : Type u) [metric_space α] [separable_space α] :
isometry (Kuratowski_embedding α) :=
classical.some_spec (exists_isometric_embedding α)
/-- Version of the Kuratowski embedding for nonempty compacts -/
def nonempty_compacts.Kuratowski_embedding (α : Type u) [metric_space α] [compact_space α]
[nonempty α] :
nonempty_compacts ℓ_infty_ℝ :=
⟨range (Kuratowski_embedding α), range_nonempty _,
compact_range (Kuratowski_embedding.isometry α).continuous⟩
|
1f2224314c8d884eb85d1af35fc1bcf9d23029a3 | 3f7026ea8bef0825ca0339a275c03b911baef64d | /src/category_theory/natural_isomorphism.lean | 7d7eff80d329b4a15888575b313a38a7d4e5aa77 | [
"Apache-2.0"
] | permissive | rspencer01/mathlib | b1e3afa5c121362ef0881012cc116513ab09f18c | c7d36292c6b9234dc40143c16288932ae38fdc12 | refs/heads/master | 1,595,010,346,708 | 1,567,511,503,000 | 1,567,511,503,000 | 206,071,681 | 0 | 0 | Apache-2.0 | 1,567,513,643,000 | 1,567,513,643,000 | null | UTF-8 | Lean | false | false | 5,489 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import category_theory.functor_category
import category_theory.isomorphism
open category_theory
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ -- declare the `v`'s first; see `category_theory.category` for an explanation
namespace category_theory
open nat_trans
/-- The application of a natural isomorphism to an object. We put this definition in a different namespace, so that we can use α.app -/
@[simp, reducible] def iso.app {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
{F G : C ⥤ D} (α : F ≅ G) (X : C) : F.obj X ≅ G.obj X :=
{ hom := α.hom.app X,
inv := α.inv.app X,
hom_inv_id' := begin rw [← comp_app, iso.hom_inv_id], refl end,
inv_hom_id' := begin rw [← comp_app, iso.inv_hom_id], refl end }
namespace nat_iso
open category_theory.category category_theory.functor
variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D]
{E : Type u₃} [ℰ : category.{v₃} E]
include 𝒞 𝒟
@[simp] lemma trans_app {F G H : C ⥤ D} (α : F ≅ G) (β : G ≅ H) (X : C) :
(α ≪≫ β).app X = α.app X ≪≫ β.app X := rfl
@[simp] lemma app_hom {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).hom = α.hom.app X := rfl
@[simp] lemma app_inv {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).inv = α.inv.app X := rfl
@[simp] lemma hom_inv_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) : α.hom.app X ≫ α.inv.app X = 𝟙 (F.obj X) :=
congr_fun (congr_arg app α.hom_inv_id) X
@[simp] lemma inv_hom_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) : α.inv.app X ≫ α.hom.app X = 𝟙 (G.obj X) :=
congr_fun (congr_arg app α.inv_hom_id) X
variables {F G : C ⥤ D}
instance hom_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.hom.app X) :=
{ inv := α.inv.app X,
hom_inv_id' := begin rw [←comp_app, iso.hom_inv_id, ←id_app] end,
inv_hom_id' := begin rw [←comp_app, iso.inv_hom_id, ←id_app] end }
instance inv_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.inv.app X) :=
{ inv := α.hom.app X,
hom_inv_id' := begin rw [←comp_app, iso.inv_hom_id, ←id_app] end,
inv_hom_id' := begin rw [←comp_app, iso.hom_inv_id, ←id_app] end }
@[simp] lemma hom_app_inv_app_id (α : F ≅ G) (X : C) : α.hom.app X ≫ α.inv.app X = 𝟙 _ :=
begin
rw ←comp_app, simp,
end
@[simp] lemma inv_app_hom_app_id (α : F ≅ G) (X : C) : α.inv.app X ≫ α.hom.app X = 𝟙 _ :=
begin
rw ←comp_app, simp,
end
variables {X Y : C}
@[simp] lemma naturality_1 (α : F ≅ G) (f : X ⟶ Y) :
(α.inv.app X) ≫ (F.map f) ≫ (α.hom.app Y) = G.map f :=
begin erw [naturality, ←category.assoc, is_iso.hom_inv_id, category.id_comp] end
@[simp] lemma naturality_2 (α : F ≅ G) (f : X ⟶ Y) :
(α.hom.app X) ≫ (G.map f) ≫ (α.inv.app Y) = F.map f :=
begin erw [naturality, ←category.assoc, is_iso.hom_inv_id, category.id_comp] end
def is_iso_of_is_iso_app (α : F ⟶ G) [∀ X : C, is_iso (α.app X)] : is_iso α :=
{ inv :=
{ app := λ X, inv (α.app X),
naturality' := λ X Y f,
begin
have h := congr_arg (λ f, inv (α.app X) ≫ (f ≫ inv (α.app Y))) (α.naturality f).symm,
simp only [is_iso.inv_hom_id_assoc, is_iso.hom_inv_id, assoc, comp_id, cancel_mono] at h,
exact h
end } }
instance is_iso_of_is_iso_app' (α : F ⟶ G) [H : ∀ X : C, is_iso (nat_trans.app α X)] : is_iso α :=
@nat_iso.is_iso_of_is_iso_app _ _ _ _ _ _ α H
-- TODO can we make this an instance?
def is_iso_app_of_is_iso (α : F ⟶ G) [is_iso α] (X) : is_iso (α.app X) :=
{ inv := (inv α).app X,
hom_inv_id' := congr_fun (congr_arg nat_trans.app (is_iso.hom_inv_id α)) X,
inv_hom_id' := congr_fun (congr_arg nat_trans.app (is_iso.inv_hom_id α)) X }
def of_components (app : ∀ X : C, (F.obj X) ≅ (G.obj X))
(naturality : ∀ {X Y : C} (f : X ⟶ Y), (F.map f) ≫ ((app Y).hom) = ((app X).hom) ≫ (G.map f)) :
F ≅ G :=
as_iso { app := λ X, (app X).hom }
@[simp] def of_components.app (app' : ∀ X : C, (F.obj X) ≅ (G.obj X)) (naturality) (X) :
(of_components app' naturality).app X = app' X :=
by tidy
@[simp] def of_components.hom_app (app : ∀ X : C, (F.obj X) ≅ (G.obj X)) (naturality) (X) :
(of_components app naturality).hom.app X = (app X).hom := rfl
@[simp] def of_components.inv_app (app : ∀ X : C, (F.obj X) ≅ (G.obj X)) (naturality) (X) :
(of_components app naturality).inv.app X = (app X).inv := rfl
include ℰ
def hcomp {F G : C ⥤ D} {H I : D ⥤ E} (α : F ≅ G) (β : H ≅ I) : F ⋙ H ≅ G ⋙ I :=
begin
refine ⟨α.hom ◫ β.hom, α.inv ◫ β.inv, _, _⟩,
{ ext, rw [←nat_trans.exchange], simp, refl },
ext, rw [←nat_trans.exchange], simp, refl
end
omit ℰ
-- suggested local notation for nat_iso.hcomp. Currently unused.
local infix ` ■ `:80 := hcomp
end nat_iso
namespace functor
variables {C : Type u₁} [𝒞 : category.{v₁} C]
include 𝒞
def ulift_down_up : ulift_down.{v₁} C ⋙ ulift_up C ≅ 𝟭 (ulift.{u₂} C) :=
{ hom := { app := λ X, @category_struct.id (ulift.{u₂} C) _ X },
inv := { app := λ X, @category_struct.id (ulift.{u₂} C) _ X } }
def ulift_up_down : ulift_up.{v₁} C ⋙ ulift_down C ≅ 𝟭 C :=
{ hom := { app := λ X, 𝟙 X },
inv := { app := λ X, 𝟙 X } }
end functor
end category_theory
|
83bddae3bd8718435758172c6f4ead9b047cbb13 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/deprecated/subgroup.lean | d44481cb736145257a6d548824f11c93364d9a36 | [
"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 | 25,120 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mitchell Rowett, Scott Morrison, Johan Commelin, Mario Carneiro,
Michael Howes
-/
import group_theory.subgroup.basic
import deprecated.submonoid
/-!
# Unbundled subgroups
This file defines unbundled multiplicative and additive subgroups `is_subgroup` and
`is_add_subgroup`. These are not the preferred way to talk about subgroups and should
not be used for any new projects. The preferred way in mathlib are the bundled
versions `subgroup G` and `add_subgroup G`.
## Main definitions
`is_add_subgroup (S : set G)` : the predicate that `S` is the underlying subset of an additive
subgroup of `G`. The bundled variant `add_subgroup G` should be used in preference to this.
`is_subgroup (S : set G)` : the predicate that `S` is the underlying subset of a subgroup
of `G`. The bundled variant `subgroup G` should be used in preference to this.
## Tags
subgroup, subgroups, is_subgroup
-/
open set function
variables {G : Type*} {H : Type*} {A : Type*} {a a₁ a₂ b c: G}
section group
variables [group G] [add_group A]
/-- `s` is an additive subgroup: a set containing 0 and closed under addition and negation. -/
structure is_add_subgroup (s : set A) extends is_add_submonoid s : Prop :=
(neg_mem {a} : a ∈ s → -a ∈ s)
/-- `s` is a subgroup: a set containing 1 and closed under multiplication and inverse. -/
@[to_additive]
structure is_subgroup (s : set G) extends is_submonoid s : Prop :=
(inv_mem {a} : a ∈ s → a⁻¹ ∈ s)
@[to_additive]
lemma is_subgroup.div_mem {s : set G} (hs : is_subgroup s) {x y : G} (hx : x ∈ s) (hy : y ∈ s) :
x / y ∈ s :=
by simpa only [div_eq_mul_inv] using hs.mul_mem hx (hs.inv_mem hy)
lemma additive.is_add_subgroup
{s : set G} (hs : is_subgroup s) : @is_add_subgroup (additive G) _ s :=
@is_add_subgroup.mk (additive G) _ _ (additive.is_add_submonoid hs.to_is_submonoid)
hs.inv_mem
theorem additive.is_add_subgroup_iff
{s : set G} : @is_add_subgroup (additive G) _ s ↔ is_subgroup s :=
⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @is_subgroup.mk G _ _ ⟨h₁, @h₂⟩ @h₃,
λ h, by exactI additive.is_add_subgroup h⟩
lemma multiplicative.is_subgroup
{s : set A} (hs : is_add_subgroup s) : @is_subgroup (multiplicative A) _ s :=
@is_subgroup.mk (multiplicative A) _ _ (multiplicative.is_submonoid hs.to_is_add_submonoid)
hs.neg_mem
theorem multiplicative.is_subgroup_iff
{s : set A} : @is_subgroup (multiplicative A) _ s ↔ is_add_subgroup s :=
⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @is_add_subgroup.mk A _ _ ⟨h₁, @h₂⟩ @h₃,
λ h, by exactI multiplicative.is_subgroup h⟩
@[to_additive of_add_neg]
theorem is_subgroup.of_div (s : set G)
(one_mem : (1:G) ∈ s) (div_mem : ∀{a b:G}, a ∈ s → b ∈ s → a * b⁻¹ ∈ s) :
is_subgroup s :=
have inv_mem : ∀a, a ∈ s → a⁻¹ ∈ s, from
assume a ha,
have 1 * a⁻¹ ∈ s, from div_mem one_mem ha,
by simpa,
{ inv_mem := inv_mem,
mul_mem := assume a b ha hb,
have a * b⁻¹⁻¹ ∈ s, from div_mem ha (inv_mem b hb),
by simpa,
one_mem := one_mem }
theorem is_add_subgroup.of_sub (s : set A)
(zero_mem : (0:A) ∈ s) (sub_mem : ∀{a b:A}, a ∈ s → b ∈ s → a - b ∈ s) :
is_add_subgroup s :=
is_add_subgroup.of_add_neg s zero_mem
(λ x y hx hy, by simpa only [sub_eq_add_neg] using sub_mem hx hy)
@[to_additive]
lemma is_subgroup.inter {s₁ s₂ : set G} (hs₁ : is_subgroup s₁) (hs₂ : is_subgroup s₂) :
is_subgroup (s₁ ∩ s₂) :=
{ inv_mem := λ x hx, ⟨hs₁.inv_mem hx.1, hs₂.inv_mem hx.2⟩,
..is_submonoid.inter hs₁.to_is_submonoid hs₂.to_is_submonoid}
@[to_additive]
lemma is_subgroup.Inter {ι : Sort*} {s : ι → set G} (hs : ∀ y : ι, is_subgroup (s y)) :
is_subgroup (set.Inter s) :=
{ inv_mem := λ x h, set.mem_Inter.2 $ λ y, is_subgroup.inv_mem (hs _) (set.mem_Inter.1 h y),
..is_submonoid.Inter (λ y, (hs y).to_is_submonoid) }
@[to_additive]
lemma is_subgroup_Union_of_directed {ι : Type*} [hι : nonempty ι]
{s : ι → set G} (hs : ∀ i, is_subgroup (s i))
(directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) :
is_subgroup (⋃i, s i) :=
{ inv_mem := λ a ha,
let ⟨i, hi⟩ := set.mem_Union.1 ha in
set.mem_Union.2 ⟨i, (hs i).inv_mem hi⟩,
to_is_submonoid := is_submonoid_Union_of_directed (λ i, (hs i).to_is_submonoid) directed }
end group
namespace is_subgroup
open is_submonoid
variables [group G] {s : set G} (hs : is_subgroup s)
include hs
@[to_additive]
lemma inv_mem_iff : a⁻¹ ∈ s ↔ a ∈ s :=
⟨λ h, by simpa using hs.inv_mem h, inv_mem hs⟩
@[to_additive]
lemma mul_mem_cancel_right (h : a ∈ s) : b * a ∈ s ↔ b ∈ s :=
⟨λ hba, by simpa using hs.mul_mem hba (hs.inv_mem h), λ hb, hs.mul_mem hb h⟩
@[to_additive]
lemma mul_mem_cancel_left (h : a ∈ s) : a * b ∈ s ↔ b ∈ s :=
⟨λ hab, by simpa using hs.mul_mem (hs.inv_mem h) hab, hs.mul_mem h⟩
end is_subgroup
/-- `is_normal_add_subgroup (s : set A)` expresses the fact that `s` is a normal additive subgroup
of the additive group `A`. Important: the preferred way to say this in Lean is via bundled
subgroups `S : add_subgroup A` and `hs : S.normal`, and not via this structure. -/
structure is_normal_add_subgroup [add_group A] (s : set A) extends is_add_subgroup s : Prop :=
(normal : ∀ n ∈ s, ∀ g : A, g + n + -g ∈ s)
/-- `is_normal_subgroup (s : set G)` expresses the fact that `s` is a normal subgroup
of the group `G`. Important: the preferred way to say this in Lean is via bundled
subgroups `S : subgroup G` and not via this structure. -/
@[to_additive]
structure is_normal_subgroup [group G] (s : set G) extends is_subgroup s : Prop :=
(normal : ∀ n ∈ s, ∀ g : G, g * n * g⁻¹ ∈ s)
@[to_additive]
lemma is_normal_subgroup_of_comm_group [comm_group G] {s : set G} (hs : is_subgroup s) :
is_normal_subgroup s :=
{ normal := λ n hn g, by rwa [mul_right_comm, mul_right_inv, one_mul],
..hs }
lemma additive.is_normal_add_subgroup [group G]
{s : set G} (hs : is_normal_subgroup s) : @is_normal_add_subgroup (additive G) _ s :=
@is_normal_add_subgroup.mk (additive G) _ _
(additive.is_add_subgroup hs.to_is_subgroup)
(is_normal_subgroup.normal hs)
theorem additive.is_normal_add_subgroup_iff [group G]
{s : set G} : @is_normal_add_subgroup (additive G) _ s ↔ is_normal_subgroup s :=
⟨by rintro ⟨h₁, h₂⟩; exact
@is_normal_subgroup.mk G _ _ (additive.is_add_subgroup_iff.1 h₁) @h₂,
λ h, by exactI additive.is_normal_add_subgroup h⟩
lemma multiplicative.is_normal_subgroup [add_group A]
{s : set A} (hs : is_normal_add_subgroup s) : @is_normal_subgroup (multiplicative A) _ s :=
@is_normal_subgroup.mk (multiplicative A) _ _
(multiplicative.is_subgroup hs.to_is_add_subgroup)
(is_normal_add_subgroup.normal hs)
theorem multiplicative.is_normal_subgroup_iff [add_group A]
{s : set A} : @is_normal_subgroup (multiplicative A) _ s ↔ is_normal_add_subgroup s :=
⟨by rintro ⟨h₁, h₂⟩; exact
@is_normal_add_subgroup.mk A _ _ (multiplicative.is_subgroup_iff.1 h₁) @h₂,
λ h, by exactI multiplicative.is_normal_subgroup h⟩
namespace is_subgroup
variable [group G]
-- Normal subgroup properties
@[to_additive]
lemma mem_norm_comm {s : set G} (hs : is_normal_subgroup s) {a b : G} (hab : a * b ∈ s) :
b * a ∈ s :=
have h : a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ s, from hs.normal (a * b) hab a⁻¹,
by simp at h; exact h
@[to_additive]
lemma mem_norm_comm_iff {s : set G} (hs : is_normal_subgroup s) {a b : G} : a * b ∈ s ↔ b * a ∈ s :=
⟨mem_norm_comm hs, mem_norm_comm hs⟩
/-- The trivial subgroup -/
@[to_additive "the trivial additive subgroup"]
def trivial (G : Type*) [group G] : set G := {1}
@[simp, to_additive]
lemma mem_trivial {g : G} : g ∈ trivial G ↔ g = 1 :=
mem_singleton_iff
@[to_additive]
lemma trivial_normal : is_normal_subgroup (trivial G) :=
by refine {..}; simp [trivial] {contextual := tt}
@[to_additive]
lemma eq_trivial_iff {s : set G} (hs : is_subgroup s) :
s = trivial G ↔ (∀ x ∈ s, x = (1 : G)) :=
by simp only [set.ext_iff, is_subgroup.mem_trivial];
exact ⟨λ h x, (h x).1, λ h x, ⟨h x, λ hx, hx.symm ▸ hs.to_is_submonoid.one_mem⟩⟩
@[to_additive]
lemma univ_subgroup : is_normal_subgroup (@univ G) :=
by refine {..}; simp
/-- The underlying set of the center of a group. -/
@[to_additive add_center "The underlying set of the center of an additive group."]
def center (G : Type*) [group G] : set G := {z | ∀ g, g * z = z * g}
@[to_additive mem_add_center]
lemma mem_center {a : G} : a ∈ center G ↔ ∀g, g * a = a * g := iff.rfl
@[to_additive add_center_normal]
lemma center_normal : is_normal_subgroup (center G) :=
{ one_mem := by simp [center],
mul_mem := assume a b ha hb g,
by rw [←mul_assoc, mem_center.2 ha g, mul_assoc, mem_center.2 hb g, ←mul_assoc],
inv_mem := assume a ha g,
calc
g * a⁻¹ = a⁻¹ * (g * a) * a⁻¹ : by simp [ha g]
... = a⁻¹ * g : by rw [←mul_assoc, mul_assoc]; simp,
normal := assume n ha g h,
calc
h * (g * n * g⁻¹) = h * n : by simp [ha g, mul_assoc]
... = g * g⁻¹ * n * h : by rw ha h; simp
... = g * n * g⁻¹ * h : by rw [mul_assoc g, ha g⁻¹, ←mul_assoc] }
/-- The underlying set of the normalizer of a subset `S : set G` of a group `G`. That is,
the elements `g : G` such that `g * S * g⁻¹ = S`. -/
@[to_additive add_normalizer "The underlying set of the normalizer of a subset `S : set A` of an
additive group `A`. That is, the elements `a : A` such that `a + S - a = S`."]
def normalizer (s : set G) : set G :=
{g : G | ∀ n, n ∈ s ↔ g * n * g⁻¹ ∈ s}
@[to_additive]
lemma normalizer_is_subgroup (s : set G) : is_subgroup (normalizer s) :=
{ one_mem := by simp [normalizer],
mul_mem := λ a b (ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s)
(hb : ∀ n, n ∈ s ↔ b * n * b⁻¹ ∈ s) n,
by rw [mul_inv_rev, ← mul_assoc, mul_assoc a, mul_assoc a, ← ha, ← hb],
inv_mem := λ a (ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s) n,
by rw [ha (a⁻¹ * n * a⁻¹⁻¹)];
simp [mul_assoc] }
@[to_additive subset_add_normalizer]
lemma subset_normalizer {s : set G} (hs : is_subgroup s) : s ⊆ normalizer s :=
λ g hg n, by rw [is_subgroup.mul_mem_cancel_right hs ((is_subgroup.inv_mem_iff hs).2 hg),
is_subgroup.mul_mem_cancel_left hs hg]
end is_subgroup
-- Homomorphism subgroups
namespace is_group_hom
open is_submonoid is_subgroup
open is_mul_hom (map_mul)
/-- `ker f : set G` is the underlying subset of the kernel of a map `G → H`. -/
@[to_additive "`ker f : set A` is the underlying subset of the kernel of a map `A → B`"]
def ker [group H] (f : G → H) : set G := preimage f (trivial H)
@[to_additive]
lemma mem_ker [group H] (f : G → H) {x : G} : x ∈ ker f ↔ f x = 1 :=
mem_trivial
variables [group G] [group H]
@[to_additive]
lemma one_ker_inv {f : G → H} (hf : is_group_hom f) {a b : G} (h : f (a * b⁻¹) = 1) : f a = f b :=
begin
rw [hf.map_mul, hf.map_inv] at h,
rw [←inv_inv (f b), eq_inv_of_mul_eq_one h]
end
@[to_additive]
lemma one_ker_inv' {f : G → H} (hf : is_group_hom f) {a b : G} (h : f (a⁻¹ * b) = 1) : f a = f b :=
begin
rw [hf.map_mul, hf.map_inv] at h,
apply inv_injective,
rw eq_inv_of_mul_eq_one h
end
@[to_additive]
lemma inv_ker_one {f : G → H} (hf : is_group_hom f) {a b : G} (h : f a = f b) : f (a * b⁻¹) = 1 :=
have f a * (f b)⁻¹ = 1, by rw [h, mul_right_inv],
by rwa [←hf.map_inv, ←hf.map_mul] at this
@[to_additive]
lemma inv_ker_one' {f : G → H} (hf : is_group_hom f) {a b : G} (h : f a = f b) : f (a⁻¹ * b) = 1 :=
have (f a)⁻¹ * f b = 1, by rw [h, mul_left_inv],
by rwa [←hf.map_inv, ←hf.map_mul] at this
@[to_additive]
lemma one_iff_ker_inv {f : G → H} (hf : is_group_hom f) (a b : G) : f a = f b ↔ f (a * b⁻¹) = 1 :=
⟨hf.inv_ker_one, hf.one_ker_inv⟩
@[to_additive]
lemma one_iff_ker_inv' {f : G → H} (hf : is_group_hom f) (a b : G) : f a = f b ↔ f (a⁻¹ * b) = 1 :=
⟨hf.inv_ker_one', hf.one_ker_inv'⟩
@[to_additive]
lemma inv_iff_ker {f : G → H} (hf : is_group_hom f) (a b : G) : f a = f b ↔ a * b⁻¹ ∈ ker f :=
by rw [mem_ker]; exact one_iff_ker_inv hf _ _
@[to_additive]
lemma inv_iff_ker' {f : G → H} (hf : is_group_hom f) (a b : G) : f a = f b ↔ a⁻¹ * b ∈ ker f :=
by rw [mem_ker]; exact one_iff_ker_inv' hf _ _
@[to_additive]
lemma image_subgroup {f : G → H} (hf : is_group_hom f) {s : set G} (hs : is_subgroup s) :
is_subgroup (f '' s) :=
{ mul_mem := assume a₁ a₂ ⟨b₁, hb₁, eq₁⟩ ⟨b₂, hb₂, eq₂⟩,
⟨b₁ * b₂, hs.mul_mem hb₁ hb₂, by simp [eq₁, eq₂, hf.map_mul]⟩,
one_mem := ⟨1, hs.to_is_submonoid.one_mem, hf.map_one⟩,
inv_mem := assume a ⟨b, hb, eq⟩, ⟨b⁻¹, hs.inv_mem hb, by { rw hf.map_inv, simp * }⟩ }
@[to_additive]
lemma range_subgroup {f : G → H} (hf : is_group_hom f) : is_subgroup (set.range f) :=
@set.image_univ _ _ f ▸ hf.image_subgroup univ_subgroup.to_is_subgroup
local attribute [simp] one_mem inv_mem mul_mem is_normal_subgroup.normal
@[to_additive]
lemma preimage {f : G → H} (hf : is_group_hom f) {s : set H} (hs : is_subgroup s) :
is_subgroup (f ⁻¹' s) :=
by { refine {..};
simp [hs.one_mem, hs.mul_mem, hs.inv_mem, hf.map_mul, hf.map_one, hf.map_inv, @inv_mem H _ s]
{contextual := tt} }
@[to_additive]
lemma preimage_normal {f : G → H} (hf : is_group_hom f) {s : set H} (hs : is_normal_subgroup s) :
is_normal_subgroup (f ⁻¹' s) :=
{ one_mem := by simp [hf.map_one, hs.to_is_subgroup.one_mem],
mul_mem := by simp [hf.map_mul, hs.to_is_subgroup.mul_mem] {contextual := tt},
inv_mem := by simp [hf.map_inv, hs.to_is_subgroup.inv_mem] {contextual := tt},
normal := by simp [hs.normal, hf.map_mul, hf.map_inv] {contextual := tt}}
@[to_additive]
lemma is_normal_subgroup_ker {f : G → H} (hf : is_group_hom f) : is_normal_subgroup (ker f) :=
hf.preimage_normal (trivial_normal)
@[to_additive]
lemma injective_of_trivial_ker {f : G → H} (hf : is_group_hom f) (h : ker f = trivial G) :
function.injective f :=
begin
intros a₁ a₂ hfa,
simp [ext_iff, ker, is_subgroup.trivial] at h,
have ha : a₁ * a₂⁻¹ = 1, by rw ←h; exact hf.inv_ker_one hfa,
rw [eq_inv_of_mul_eq_one ha, inv_inv a₂]
end
@[to_additive]
lemma trivial_ker_of_injective {f : G → H} (hf : is_group_hom f) (h : function.injective f) :
ker f = trivial G :=
set.ext $ assume x, iff.intro
(assume hx,
suffices f x = f 1, by simpa using h this,
by simp [hf.map_one]; rwa [mem_ker] at hx)
(by simp [mem_ker, hf.map_one] {contextual := tt})
@[to_additive]
lemma injective_iff_trivial_ker {f : G → H} (hf : is_group_hom f) :
function.injective f ↔ ker f = trivial G :=
⟨hf.trivial_ker_of_injective, hf.injective_of_trivial_ker⟩
@[to_additive]
lemma trivial_ker_iff_eq_one {f : G → H} (hf : is_group_hom f) :
ker f = trivial G ↔ ∀ x, f x = 1 → x = 1 :=
by rw set.ext_iff; simp [ker]; exact
⟨λ h x hx, (h x).1 hx, λ h x, ⟨h x, λ hx, by rw [hx, hf.map_one]⟩⟩
end is_group_hom
namespace add_group
variables [add_group A]
/-- If `A` is an additive group and `s : set A`, then `in_closure s : set A` is the underlying
subset of the subgroup generated by `s`. -/
inductive in_closure (s : set A) : A → Prop
| basic {a : A} : a ∈ s → in_closure a
| zero : in_closure 0
| neg {a : A} : in_closure a → in_closure (-a)
| add {a b : A} : in_closure a → in_closure b → in_closure (a + b)
end add_group
namespace group
open is_submonoid is_subgroup
variables [group G] {s : set G}
/-- If `G` is a group and `s : set G`, then `in_closure s : set G` is the underlying
subset of the subgroup generated by `s`. -/
@[to_additive]
inductive in_closure (s : set G) : G → Prop
| basic {a : G} : a ∈ s → in_closure a
| one : in_closure 1
| inv {a : G} : in_closure a → in_closure a⁻¹
| mul {a b : G} : in_closure a → in_closure b → in_closure (a * b)
/-- `group.closure s` is the subgroup generated by `s`, i.e. the smallest subgroup containg `s`. -/
@[to_additive "`add_group.closure s` is the additive subgroup generated by `s`, i.e., the
smallest additive subgroup containing `s`."]
def closure (s : set G) : set G := {a | in_closure s a }
@[to_additive]
lemma mem_closure {a : G} : a ∈ s → a ∈ closure s := in_closure.basic
@[to_additive]
lemma closure.is_subgroup (s : set G) : is_subgroup (closure s) :=
{ one_mem := in_closure.one,
mul_mem := assume a b, in_closure.mul,
inv_mem := assume a, in_closure.inv }
@[to_additive]
theorem subset_closure {s : set G} : s ⊆ closure s := λ a, mem_closure
@[to_additive]
theorem closure_subset {s t : set G} (ht : is_subgroup t) (h : s ⊆ t) : closure s ⊆ t :=
assume a ha, by induction ha; simp [h _, *, ht.one_mem, ht.mul_mem, inv_mem_iff]
@[to_additive]
lemma closure_subset_iff {s t : set G} (ht : is_subgroup t) : closure s ⊆ t ↔ s ⊆ t :=
⟨assume h b ha, h (mem_closure ha), assume h b ha, closure_subset ht h ha⟩
@[to_additive]
theorem closure_mono {s t : set G} (h : s ⊆ t) : closure s ⊆ closure t :=
closure_subset (closure.is_subgroup _) $ set.subset.trans h subset_closure
@[simp, to_additive]
lemma closure_subgroup {s : set G} (hs : is_subgroup s) : closure s = s :=
set.subset.antisymm (closure_subset hs $ set.subset.refl s) subset_closure
@[to_additive]
theorem exists_list_of_mem_closure {s : set G} {a : G} (h : a ∈ closure s) :
(∃l:list G, (∀x∈l, x ∈ s ∨ x⁻¹ ∈ s) ∧ l.prod = a) :=
in_closure.rec_on h
(λ x hxs, ⟨[x], list.forall_mem_singleton.2 $ or.inl hxs, one_mul _⟩)
⟨[], list.forall_mem_nil _, rfl⟩
(λ x _ ⟨L, HL1, HL2⟩, ⟨L.reverse.map has_inv.inv,
λ x hx, let ⟨y, hy1, hy2⟩ := list.exists_of_mem_map hx in
hy2 ▸ or.imp id (by rw [inv_inv]; exact id) (HL1 _ $ list.mem_reverse.1 hy1).symm,
HL2 ▸ list.rec_on L one_inv.symm (λ hd tl ih,
by rw [list.reverse_cons, list.map_append, list.prod_append, ih, list.map_singleton,
list.prod_cons, list.prod_nil, mul_one, list.prod_cons, mul_inv_rev])⟩)
(λ x y hx hy ⟨L1, HL1, HL2⟩ ⟨L2, HL3, HL4⟩, ⟨L1 ++ L2, list.forall_mem_append.2 ⟨HL1, HL3⟩,
by rw [list.prod_append, HL2, HL4]⟩)
@[to_additive]
lemma image_closure [group H] {f : G → H} (hf : is_group_hom f) (s : set G) :
f '' closure s = closure (f '' s) :=
le_antisymm
begin
rintros _ ⟨x, hx, rfl⟩,
apply in_closure.rec_on hx; intros,
{ solve_by_elim [subset_closure, set.mem_image_of_mem] },
{ rw [hf.to_is_monoid_hom.map_one],
apply is_submonoid.one_mem (closure.is_subgroup _).to_is_submonoid, },
{ rw [hf.map_inv],
apply is_subgroup.inv_mem (closure.is_subgroup _), assumption },
{ rw [hf.to_is_monoid_hom.map_mul],
solve_by_elim [is_submonoid.mul_mem (closure.is_subgroup _).to_is_submonoid] }
end
(closure_subset (hf.image_subgroup $ closure.is_subgroup _) $ set.image_subset _ subset_closure)
@[to_additive]
theorem mclosure_subset {s : set G} : monoid.closure s ⊆ closure s :=
monoid.closure_subset (closure.is_subgroup _).to_is_submonoid $ subset_closure
@[to_additive]
theorem mclosure_inv_subset {s : set G} : monoid.closure (has_inv.inv ⁻¹' s) ⊆ closure s :=
monoid.closure_subset (closure.is_subgroup _).to_is_submonoid $ λ x hx,
inv_inv x ▸ ((closure.is_subgroup _).inv_mem $ subset_closure hx)
@[to_additive]
theorem closure_eq_mclosure {s : set G} : closure s = monoid.closure (s ∪ has_inv.inv ⁻¹' s) :=
set.subset.antisymm
(@closure_subset _ _ _ (monoid.closure (s ∪ has_inv.inv ⁻¹' s))
{ one_mem := (monoid.closure.is_submonoid _).one_mem,
mul_mem := (monoid.closure.is_submonoid _).mul_mem,
inv_mem := λ x hx, monoid.in_closure.rec_on hx
(λ x hx, or.cases_on hx (λ hx, monoid.subset_closure $ or.inr $
show x⁻¹⁻¹ ∈ s, from (inv_inv x).symm ▸ hx)
(λ hx, monoid.subset_closure $ or.inl hx))
((@one_inv G _).symm ▸ is_submonoid.one_mem (monoid.closure.is_submonoid _))
(λ x y hx hy ihx ihy,
(mul_inv_rev x y).symm ▸ is_submonoid.mul_mem (monoid.closure.is_submonoid _) ihy ihx) }
(set.subset.trans (set.subset_union_left _ _) monoid.subset_closure))
(monoid.closure_subset (closure.is_subgroup _).to_is_submonoid $ set.union_subset subset_closure $
λ x hx, inv_inv x ▸ (is_subgroup.inv_mem (closure.is_subgroup _) $ subset_closure hx))
@[to_additive]
theorem mem_closure_union_iff {G : Type*} [comm_group G] {s t : set G} {x : G} :
x ∈ closure (s ∪ t) ↔ ∃ y ∈ closure s, ∃ z ∈ closure t, y * z = x :=
begin
simp only [closure_eq_mclosure, monoid.mem_closure_union_iff, exists_prop, preimage_union], split,
{ rintro ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, rfl⟩,
refine ⟨_, ⟨_, hys, _, hzs, rfl⟩, _, ⟨_, hyt, _, hzt, rfl⟩, _⟩,
rw [mul_assoc, mul_assoc, mul_left_comm zs] },
{ rintro ⟨_, ⟨ys, hys, zs, hzs, rfl⟩, _, ⟨yt, hyt, zt, hzt, rfl⟩, rfl⟩,
refine ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, _⟩,
rw [mul_assoc, mul_assoc, mul_left_comm yt] }
end
end group
namespace is_subgroup
variable [group G]
@[to_additive]
lemma trivial_eq_closure : trivial G = group.closure ∅ :=
subset.antisymm
(by simp [set.subset_def, (group.closure.is_subgroup _).one_mem])
(group.closure_subset (trivial_normal).to_is_subgroup $ by simp)
end is_subgroup
/-The normal closure of a set s is the subgroup closure of all the conjugates of
elements of s. It is the smallest normal subgroup containing s. -/
namespace group
variables {s : set G} [group G]
lemma conjugates_of_subset {t : set G} (ht : is_normal_subgroup t) {a : G} (h : a ∈ t) :
conjugates_of a ⊆ t :=
λ x hc,
begin
obtain ⟨c, w⟩ := is_conj_iff.1 hc,
have H := is_normal_subgroup.normal ht a h c,
rwa ←w,
end
theorem conjugates_of_set_subset' {s t : set G} (ht : is_normal_subgroup t) (h : s ⊆ t) :
conjugates_of_set s ⊆ t :=
set.bUnion_subset (λ x H, conjugates_of_subset ht (h H))
/-- The normal closure of a set s is the subgroup closure of all the conjugates of
elements of s. It is the smallest normal subgroup containing s. -/
def normal_closure (s : set G) : set G := closure (conjugates_of_set s)
theorem conjugates_of_set_subset_normal_closure : conjugates_of_set s ⊆ normal_closure s :=
subset_closure
theorem subset_normal_closure : s ⊆ normal_closure s :=
set.subset.trans subset_conjugates_of_set conjugates_of_set_subset_normal_closure
/-- The normal closure of a set is a subgroup. -/
lemma normal_closure.is_subgroup (s : set G) : is_subgroup (normal_closure s) :=
closure.is_subgroup (conjugates_of_set s)
/-- The normal closure of s is a normal subgroup. -/
lemma normal_closure.is_normal : is_normal_subgroup (normal_closure s) :=
{ normal := λ n h g,
begin
induction h with x hx x hx ihx x y hx hy ihx ihy,
{exact (conjugates_of_set_subset_normal_closure (conj_mem_conjugates_of_set hx))},
{simpa using (normal_closure.is_subgroup s).one_mem},
{rw ←conj_inv,
exact ((normal_closure.is_subgroup _).inv_mem ihx)},
{rw ←conj_mul,
exact ((normal_closure.is_subgroup _).to_is_submonoid.mul_mem ihx ihy)},
end,
..normal_closure.is_subgroup _ }
/-- The normal closure of s is the smallest normal subgroup containing s. -/
theorem normal_closure_subset {s t : set G} (ht : is_normal_subgroup t) (h : s ⊆ t) :
normal_closure s ⊆ t :=
λ a w,
begin
induction w with x hx x hx ihx x y hx hy ihx ihy,
{exact (conjugates_of_set_subset' ht h $ hx)},
{exact ht.to_is_subgroup.to_is_submonoid.one_mem},
{exact ht.to_is_subgroup.inv_mem ihx},
{exact ht.to_is_subgroup.to_is_submonoid.mul_mem ihx ihy}
end
lemma normal_closure_subset_iff {s t : set G} (ht : is_normal_subgroup t) :
s ⊆ t ↔ normal_closure s ⊆ t :=
⟨normal_closure_subset ht, set.subset.trans (subset_normal_closure)⟩
theorem normal_closure_mono {s t : set G} : s ⊆ t → normal_closure s ⊆ normal_closure t :=
λ h, normal_closure_subset normal_closure.is_normal (set.subset.trans h (subset_normal_closure))
end group
/-- Create a bundled subgroup from a set `s` and `[is_subgroup s]`. -/
@[to_additive "Create a bundled additive subgroup from a set `s` and `[is_add_subgroup s]`."]
def subgroup.of [group G] {s : set G} (h : is_subgroup s) : subgroup G :=
{ carrier := s,
one_mem' := h.1.1,
mul_mem' := h.1.2,
inv_mem' := h.2 }
@[to_additive]
lemma subgroup.is_subgroup [group G] (K : subgroup G) : is_subgroup (K : set G) :=
{ one_mem := K.one_mem',
mul_mem := K.mul_mem',
inv_mem := K.inv_mem' }
-- this will never fire if it's an instance
@[to_additive]
lemma subgroup.of_normal [group G] (s : set G) (h : is_subgroup s) (n : is_normal_subgroup s) :
subgroup.normal (subgroup.of h) :=
{ conj_mem := n.normal, }
|
6268cf02f921f3872bc3081ac84411ec2ff600dd | 3d1007ef1e9e4040cf016d87cf9e6494be0c29fd | /src/discrete_valuation_ring/basic.lean | da4fdd1bc1d5b3e19df1f9a239665e65dd468b4e | [] | no_license | ImperialCollegeLondon/local-fields | 77e535111bb9841bcbea4a45c37a742085366e41 | 18ae1205b3fddd43b7447c6f090940f07cb2c52b | refs/heads/master | 1,609,728,387,873 | 1,581,629,682,000 | 1,581,629,682,000 | 240,342,840 | 3 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 264 | lean | import ring_theory.principal_ideal_domain
/-!
Basic theory of DVRs
-/
set_option old_structure_cmd true
class discrete_valuation_ring (R : Type*) extends principal_ideal_domain R,
local_ring R :=
(exists_nonzero_nonunit : ∃ a : R, a ≠ 0 ∧ ¬ is_unit a)
|
cecd0769b93204b5894cfabc92bfd82820969844 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/finset/nat_antidiagonal.lean | bf3d7ca1235b2aaff392cd019c920c374bdcb588 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 2,636 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import data.finset.basic
import data.multiset.nat_antidiagonal
/-!
# Antidiagonals in ℕ × ℕ as finsets
This file defines the antidiagonals of ℕ × ℕ as finsets: the `n`-th antidiagonal is the finset of
pairs `(i, j)` such that `i + j = n`. This is useful for polynomial multiplication and more
generally for sums going from `0` to `n`.
## Notes
This refines files `data.list.nat_antidiagonal` and `data.multiset.nat_antidiagonal`.
-/
namespace finset
namespace nat
/-- The antidiagonal of a natural number `n` is
the finset of pairs `(i, j)` such that `i + j = n`. -/
def antidiagonal (n : ℕ) : finset (ℕ × ℕ) :=
⟨multiset.nat.antidiagonal n, multiset.nat.nodup_antidiagonal n⟩
/-- A pair (i, j) is contained in the antidiagonal of `n` if and only if `i + j = n`. -/
@[simp] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :
x ∈ antidiagonal n ↔ x.1 + x.2 = n :=
by rw [antidiagonal, mem_def, multiset.nat.mem_antidiagonal]
/-- The cardinality of the antidiagonal of `n` is `n + 1`. -/
@[simp] lemma card_antidiagonal (n : ℕ) : (antidiagonal n).card = n+1 :=
by simp [antidiagonal]
/-- The antidiagonal of `0` is the list `[(0, 0)]` -/
@[simp] lemma antidiagonal_zero : antidiagonal 0 = {(0, 0)} :=
rfl
lemma antidiagonal_succ {n : ℕ} :
antidiagonal (n + 1) = insert (0, n + 1) ((antidiagonal n).map
(function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ (function.embedding.refl _))) :=
begin
apply eq_of_veq,
rw [insert_val_of_not_mem, map_val],
{apply multiset.nat.antidiagonal_succ},
{ intro con, rcases mem_map.1 con with ⟨⟨a,b⟩, ⟨h1, h2⟩⟩,
simp only [prod.mk.inj_iff, function.embedding.coe_prod_map, prod.map_mk] at h2,
apply nat.succ_ne_zero a h2.1, }
end
lemma map_swap_antidiagonal {n : ℕ} :
(antidiagonal n).map ⟨prod.swap, prod.swap_right_inverse.injective⟩ = antidiagonal n :=
begin
ext,
simp only [exists_prop, mem_map, mem_antidiagonal, prod.exists],
rw add_comm,
split,
{ rintro ⟨b, c, ⟨rfl, rfl⟩⟩,
simp },
{ rintro rfl,
use [a.snd, a.fst],
simp }
end
/-- A point in the antidiagonal is determined by its first co-ordinate. -/
lemma antidiagonal_congr {n : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)
(hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst :=
begin
refine ⟨congr_arg prod.fst, (λ h, prod.ext h ((add_right_inj q.fst).mp _))⟩,
rw mem_antidiagonal at hp hq,
rw [hq, ← h, hp],
end
end nat
end finset
|
3ab4aa8fb32746efe883b9a4a9ebc3fdfb6b5c4d | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/lie/classical_auto.lean | 400c70e80cc7da48bfbf45dab3dde0d2ab7a4b7c | [] | 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 | 14,389 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.invertible
import Mathlib.algebra.lie.skew_adjoint
import Mathlib.linear_algebra.matrix
import Mathlib.PostPort
universes u₂ u_1 u_4 u_2 u_3
namespace Mathlib
/-!
# Classical Lie algebras
This file is the place to find definitions and basic properties of the classical Lie algebras:
* Aₗ = sl(l+1)
* Bₗ ≃ so(l+1, l) ≃ so(2l+1)
* Cₗ = sp(l)
* Dₗ ≃ so(l, l) ≃ so(2l)
## Main definitions
* `lie_algebra.special_linear.sl`
* `lie_algebra.symplectic.sp`
* `lie_algebra.orthogonal.so`
* `lie_algebra.orthogonal.so'`
* `lie_algebra.orthogonal.so_indefinite_equiv`
* `lie_algebra.orthogonal.type_D`
* `lie_algebra.orthogonal.type_B`
* `lie_algebra.orthogonal.type_D_equiv_so'`
* `lie_algebra.orthogonal.type_B_equiv_so'`
## Implementation notes
### Matrices or endomorphisms
Given a finite type and a commutative ring, the corresponding square matrices are equivalent to the
endomorphisms of the corresponding finite-rank free module as Lie algebras, see `lie_equiv_matrix'`.
We can thus define the classical Lie algebras as Lie subalgebras either of matrices or of
endomorphisms. We have opted for the former. At the time of writing (August 2020) it is unclear
which approach should be preferred so the choice should be assumed to be somewhat arbitrary.
### Diagonal quadratic form or diagonal Cartan subalgebra
For the algebras of type `B` and `D`, there are two natural definitions. For example since the
the `2l × 2l` matrix:
$$
J = \left[\begin{array}{cc}
0_l & 1_l\\\\
1_l & 0_l
\end{array}\right]
$$
defines a symmetric bilinear form equivalent to that defined by the identity matrix `I`, we can
define the algebras of type `D` to be the Lie subalgebra of skew-adjoint matrices either for `J` or
for `I`. Both definitions have their advantages (in particular the `J`-skew-adjoint matrices define
a Lie algebra for which the diagonal matrices form a Cartan subalgebra) and so we provide both.
We thus also provide equivalences `type_D_equiv_so'`, `so_indefinite_equiv` which show the two
definitions are equivalent. Similarly for the algebras of type `B`.
## Tags
classical lie algebra, special linear, symplectic, orthogonal
-/
namespace lie_algebra
@[simp] theorem matrix_trace_commutator_zero (n : Type u_1) (R : Type u₂) [fintype n]
[DecidableEq n] [comm_ring R] (X : matrix n n R) (Y : matrix n n R) :
coe_fn (matrix.trace n R R) (has_bracket.bracket X Y) = 0 :=
sorry
namespace special_linear
/-- The special linear Lie algebra: square matrices of trace zero. -/
def sl (n : Type u_1) (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R] :
lie_subalgebra R (matrix n n R) :=
lie_subalgebra.mk (submodule.carrier (linear_map.ker (matrix.trace n R R))) sorry sorry sorry
sorry
theorem sl_bracket (n : Type u_1) (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R]
(A : ↥(sl n R)) (B : ↥(sl n R)) :
subtype.val (has_bracket.bracket A B) =
matrix.mul (subtype.val A) (subtype.val B) - matrix.mul (subtype.val B) (subtype.val A) :=
rfl
/-- It is useful to define these matrices for explicit calculations in sl n R. -/
def E {n : Type u_1} (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R] (i : n) (j : n) :
matrix n n R :=
fun (i' j' : n) => ite (i = i' ∧ j = j') 1 0
@[simp] theorem E_apply_one {n : Type u_1} (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R]
(i : n) (j : n) : E R i j i j = 1 :=
if_pos { left := rfl, right := rfl }
@[simp] theorem E_apply_zero {n : Type u_1} (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R]
(i : n) (j : n) (i' : n) (j' : n) (h : ¬(i = i' ∧ j = j')) : E R i j i' j' = 0 :=
if_neg h
@[simp] theorem E_diag_zero {n : Type u_1} (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R]
(i : n) (j : n) (h : j ≠ i) : coe_fn (matrix.diag n R R) (E R i j) = 0 :=
sorry
theorem E_trace_zero {n : Type u_1} (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R] (i : n)
(j : n) (h : j ≠ i) : coe_fn (matrix.trace n R R) (E R i j) = 0 :=
sorry
/-- When j ≠ i, the elementary matrices are elements of sl n R, in fact they are part of a natural
basis of sl n R. -/
def Eb {n : Type u_1} (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R] (i : n) (j : n)
(h : j ≠ i) : ↥(sl n R) :=
{ val := E R i j, property := sorry }
@[simp] theorem Eb_val {n : Type u_1} (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R]
(i : n) (j : n) (h : j ≠ i) : subtype.val (Eb R i j h) = E R i j :=
rfl
theorem sl_non_abelian (n : Type u_1) (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R]
[nontrivial R] (h : 1 < fintype.card n) : ¬is_lie_abelian ↥(sl n R) :=
sorry
end special_linear
namespace symplectic
/-- The matrix defining the canonical skew-symmetric bilinear form. -/
def J (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix (l ⊕ l) (l ⊕ l) R :=
matrix.from_blocks 0 (-1) 1 0
/-- The symplectic Lie algebra: skew-adjoint matrices with respect to the canonical skew-symmetric
bilinear form. -/
def sp (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
lie_subalgebra R (matrix (l ⊕ l) (l ⊕ l) R) :=
skew_adjoint_matrices_lie_subalgebra (J l R)
end symplectic
namespace orthogonal
/-- The definite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric
bilinear form defined by the identity matrix. -/
def so (n : Type u_1) (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R] :
lie_subalgebra R (matrix n n R) :=
skew_adjoint_matrices_lie_subalgebra 1
@[simp] theorem mem_so (n : Type u_1) (R : Type u₂) [fintype n] [DecidableEq n] [comm_ring R]
(A : matrix n n R) : A ∈ so n R ↔ matrix.transpose A = -A :=
sorry
/-- The indefinite diagonal matrix with `p` 1s and `q` -1s. -/
def indefinite_diagonal (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p] [fintype q]
[DecidableEq p] [DecidableEq q] [comm_ring R] : matrix (p ⊕ q) (p ⊕ q) R :=
matrix.diagonal (sum.elim (fun (_x : p) => 1) fun (_x : q) => -1)
/-- The indefinite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric
bilinear form defined by the indefinite diagonal matrix. -/
def so' (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p] [fintype q] [DecidableEq p]
[DecidableEq q] [comm_ring R] : lie_subalgebra R (matrix (p ⊕ q) (p ⊕ q) R) :=
skew_adjoint_matrices_lie_subalgebra (indefinite_diagonal p q R)
/-- A matrix for transforming the indefinite diagonal bilinear form into the definite one, provided
the parameter `i` is a square root of -1. -/
def Pso (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p] [fintype q] [DecidableEq p]
[DecidableEq q] [comm_ring R] (i : R) : matrix (p ⊕ q) (p ⊕ q) R :=
matrix.diagonal (sum.elim (fun (_x : p) => 1) fun (_x : q) => i)
theorem Pso_inv (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p] [fintype q] [DecidableEq p]
[DecidableEq q] [comm_ring R] {i : R} (hi : i * i = -1) : Pso p q R i * Pso p q R (-i) = 1 :=
sorry
theorem is_unit_Pso (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p] [fintype q]
[DecidableEq p] [DecidableEq q] [comm_ring R] {i : R} (hi : i * i = -1) :
is_unit (Pso p q R i) :=
sorry
theorem indefinite_diagonal_transform (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p]
[fintype q] [DecidableEq p] [DecidableEq q] [comm_ring R] {i : R} (hi : i * i = -1) :
matrix.mul (matrix.mul (matrix.transpose (Pso p q R i)) (indefinite_diagonal p q R))
(Pso p q R i) =
1 :=
sorry
/-- An equivalence between the indefinite and definite orthogonal Lie algebras, over a ring
containing a square root of -1. -/
def so_indefinite_equiv (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p] [fintype q]
[DecidableEq p] [DecidableEq q] [comm_ring R] {i : R} (hi : i * i = -1) :
equiv R ↥(so' p q R) ↥(so (p ⊕ q) R) :=
equiv.trans
(skew_adjoint_matrices_lie_subalgebra_equiv (indefinite_diagonal p q R) (Pso p q R i) sorry)
(equiv.of_eq
(skew_adjoint_matrices_lie_subalgebra
(matrix.mul (matrix.mul (matrix.transpose (Pso p q R i)) (indefinite_diagonal p q R))
(Pso p q R i)))
(so (p ⊕ q) R) sorry)
theorem so_indefinite_equiv_apply (p : Type u_2) (q : Type u_3) (R : Type u₂) [fintype p]
[fintype q] [DecidableEq p] [DecidableEq q] [comm_ring R] {i : R} (hi : i * i = -1)
(A : ↥(so' p q R)) :
↑(coe_fn (so_indefinite_equiv p q R hi) A) =
matrix.mul (matrix.mul (Pso p q R i⁻¹) ↑A) (Pso p q R i) :=
sorry
/-- A matrix defining a canonical even-rank symmetric bilinear form.
It looks like this as a `2l x 2l` matrix of `l x l` blocks:
[ 0 1 ]
[ 1 0 ]
-/
def JD (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix (l ⊕ l) (l ⊕ l) R :=
matrix.from_blocks 0 1 1 0
/-- The classical Lie algebra of type D as a Lie subalgebra of matrices associated to the matrix
`JD`. -/
def type_D (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
lie_subalgebra R (matrix (l ⊕ l) (l ⊕ l) R) :=
skew_adjoint_matrices_lie_subalgebra (JD l R)
/-- A matrix transforming the bilinear form defined by the matrix `JD` into a split-signature
diagonal matrix.
It looks like this as a `2l x 2l` matrix of `l x l` blocks:
[ 1 -1 ]
[ 1 1 ]
-/
def PD (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix (l ⊕ l) (l ⊕ l) R :=
matrix.from_blocks 1 (-1) 1 1
/-- The split-signature diagonal matrix. -/
def S (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix (l ⊕ l) (l ⊕ l) R :=
indefinite_diagonal l l R
theorem S_as_blocks (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
S l R = matrix.from_blocks 1 0 0 (-1) :=
sorry
theorem JD_transform (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix.mul (matrix.mul (matrix.transpose (PD l R)) (JD l R)) (PD l R) = bit0 1 • S l R :=
sorry
theorem PD_inv (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R]
[invertible (bit0 1)] : PD l R * ⅟ • matrix.transpose (PD l R) = 1 :=
sorry
theorem is_unit_PD (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R]
[invertible (bit0 1)] : is_unit (PD l R) :=
sorry
/-- An equivalence between two possible definitions of the classical Lie algebra of type D. -/
def type_D_equiv_so' (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R]
[invertible (bit0 1)] : equiv R ↥(type_D l R) ↥(so' l l R) :=
equiv.trans (skew_adjoint_matrices_lie_subalgebra_equiv (JD l R) (PD l R) sorry)
(equiv.of_eq
(skew_adjoint_matrices_lie_subalgebra
(matrix.mul (matrix.mul (matrix.transpose (PD l R)) (JD l R)) (PD l R)))
(so' l l R) sorry)
/-- A matrix defining a canonical odd-rank symmetric bilinear form.
It looks like this as a `(2l+1) x (2l+1)` matrix of blocks:
[ 2 0 0 ]
[ 0 0 1 ]
[ 0 1 0 ]
where sizes of the blocks are:
[`1 x 1` `1 x l` `1 x l`]
[`l x 1` `l x l` `l x l`]
[`l x 1` `l x l` `l x l`]
-/
def JB (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix (Unit ⊕ l ⊕ l) (Unit ⊕ l ⊕ l) R :=
matrix.from_blocks (bit0 1 • 1) 0 0 (JD l R)
/-- The classical Lie algebra of type B as a Lie subalgebra of matrices associated to the matrix
`JB`. -/
def type_B (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
lie_subalgebra R (matrix (Unit ⊕ l ⊕ l) (Unit ⊕ l ⊕ l) R) :=
skew_adjoint_matrices_lie_subalgebra (JB l R)
/-- A matrix transforming the bilinear form defined by the matrix `JB` into an
almost-split-signature diagonal matrix.
It looks like this as a `(2l+1) x (2l+1)` matrix of blocks:
[ 1 0 0 ]
[ 0 1 -1 ]
[ 0 1 1 ]
where sizes of the blocks are:
[`1 x 1` `1 x l` `1 x l`]
[`l x 1` `l x l` `l x l`]
[`l x 1` `l x l` `l x l`]
-/
def PB (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix (Unit ⊕ l ⊕ l) (Unit ⊕ l ⊕ l) R :=
matrix.from_blocks 1 0 0 (PD l R)
theorem PB_inv (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R]
[invertible (bit0 1)] : PB l R * matrix.from_blocks 1 0 0 (PD l R⁻¹) = 1 :=
sorry
theorem is_unit_PB (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R]
[invertible (bit0 1)] : is_unit (PB l R) :=
sorry
theorem JB_transform (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R] :
matrix.mul (matrix.mul (matrix.transpose (PB l R)) (JB l R)) (PB l R) =
bit0 1 • matrix.from_blocks 1 0 0 (S l R) :=
sorry
theorem indefinite_diagonal_assoc (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l]
[comm_ring R] :
indefinite_diagonal (Unit ⊕ l) l R =
coe_fn (matrix.reindex_lie_equiv (equiv.symm (equiv.sum_assoc Unit l l)))
(matrix.from_blocks 1 0 0 (indefinite_diagonal l l R)) :=
sorry
/-- An equivalence between two possible definitions of the classical Lie algebra of type B. -/
def type_B_equiv_so' (l : Type u_4) (R : Type u₂) [fintype l] [DecidableEq l] [comm_ring R]
[invertible (bit0 1)] : equiv R ↥(type_B l R) ↥(so' (Unit ⊕ l) l R) :=
equiv.trans (skew_adjoint_matrices_lie_subalgebra_equiv (JB l R) (PB l R) sorry)
(equiv.symm
(equiv.trans
(skew_adjoint_matrices_lie_subalgebra_equiv_transpose (indefinite_diagonal (Unit ⊕ l) l R)
(matrix.reindex_alg_equiv (equiv.sum_assoc PUnit l l)) sorry)
(equiv.of_eq
(skew_adjoint_matrices_lie_subalgebra
(coe_fn (matrix.reindex_alg_equiv (equiv.sum_assoc PUnit l l))
(indefinite_diagonal (Unit ⊕ l) l R)))
(skew_adjoint_matrices_lie_subalgebra
(matrix.mul (matrix.mul (matrix.transpose (PB l R)) (JB l R)) (PB l R)))
sorry)))
end Mathlib |
956ce12ec699e45bda844d42e45afe90ed871338 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/limits/essentially_small.lean | 99b2104c7cefd98553f8e786db89172f00f8615f | [
"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,647 | lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import category_theory.limits.shapes.products
import category_theory.essentially_small
/-!
# Limits over essentially small indexing categories
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
If `C` has limits of size `w` and `J` is `w`-essentially small, then `C` has limits of shape `J`.
-/
universes w₁ w₂ v₁ v₂ u₁ u₂
noncomputable theory
open category_theory
namespace category_theory.limits
variables (J : Type u₂) [category.{v₂} J] (C : Type u₁) [category.{v₁} C]
lemma has_limits_of_shape_of_essentially_small [essentially_small.{w₁} J]
[has_limits_of_size.{w₁ w₁} C] : has_limits_of_shape J C :=
has_limits_of_shape_of_equivalence $ equivalence.symm $ equiv_small_model.{w₁} J
lemma has_colimits_of_shape_of_essentially_small [essentially_small.{w₁} J]
[has_colimits_of_size.{w₁ w₁} C] : has_colimits_of_shape J C :=
has_colimits_of_shape_of_equivalence $ equivalence.symm $ equiv_small_model.{w₁} J
lemma has_products_of_shape_of_small (β : Type w₂) [small.{w₁} β] [has_products.{w₁} C] :
has_products_of_shape β C :=
has_limits_of_shape_of_equivalence $ discrete.equivalence $ equiv.symm $ equiv_shrink β
lemma has_coproducts_of_shape_of_small (β : Type w₂) [small.{w₁} β] [has_coproducts.{w₁} C] :
has_coproducts_of_shape β C :=
has_colimits_of_shape_of_equivalence $ discrete.equivalence $ equiv.symm $ equiv_shrink β
end category_theory.limits
|
d3108fef17dac241cc600a6b720601c0110c0fdf | 6b45072eb2b3db3ecaace2a7a0241ce81f815787 | /algebra/ring.lean | 56d9e242a585aab028ec3e562dade17e25cacda8 | [] | no_license | avigad/library_dev | 27b47257382667b5eb7e6476c4f5b0d685dd3ddc | 9d8ac7c7798ca550874e90fed585caad030bbfac | refs/heads/master | 1,610,452,468,791 | 1,500,712,839,000 | 1,500,713,478,000 | 69,311,142 | 1 | 0 | null | 1,474,942,903,000 | 1,474,942,902,000 | null | UTF-8 | Lean | false | false | 5,932 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn
-/
open eq
universe variable uu
variable {A : Type uu}
/- ring -/
section
variables [ring A] (a b c d e : A)
theorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d ↔ (a - b) * e + c = d :=
calc
a * e + c = b * e + d ↔ a * e + c = d + b * e : by simp
... ↔ a * e + c - b * e = d : iff.intro (λ h, begin simp [h] end) (λ h,
begin simp [h^.symm] end)
... ↔ (a - b) * e + c = d : begin simp [@sub_eq_add_neg A, @right_distrib A] end
theorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d → (a - b) * e + c = d :=
assume h,
calc
(a - b) * e + c = (a * e + c) - b * e : begin simp [@sub_eq_add_neg A, @right_distrib A] end
... = d : begin rewrite h, simp [@add_sub_cancel A] end
theorem mul_neg_one_eq_neg : a * (-1) = -a :=
have a + a * -1 = 0, from calc
a + a * -1 = a * 1 + a * -1 : by simp
... = a * (1 + -1) : eq.symm (left_distrib a 1 (-1))
... = 0 : by simp,
symm (neg_eq_of_add_eq_zero this)
theorem ne_zero_and_ne_zero_of_mul_ne_zero {a b : A} (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 :=
begin
split,
intro ha, apply h, simp [ha],
intro hb, apply h, simp [hb]
end
end
/- integral domains -/
section
variables [s : integral_domain A] (a b c d e : A)
include s
theorem eq_of_mul_eq_mul_right_of_ne_zero {a b c : A} (ha : a ≠ 0) (h : b * a = c * a) : b = c :=
have b * a - c * a = 0, by simp [h],
have (b - c) * a = 0, by rewrite [mul_sub_right_distrib, this],
have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_right ha,
eq_of_sub_eq_zero this
theorem eq_of_mul_eq_mul_left_of_ne_zero {a b c : A} (ha : a ≠ 0) (h : a * b = a * c) : b = c :=
have a * b - a * c = 0, by simp [h],
have a * (b - c) = 0, by rewrite [mul_sub_left_distrib, this],
have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_left ha,
eq_of_sub_eq_zero this
-- TODO: do we want the iff versions?
-- theorem dvd_of_mul_dvd_mul_left {a b c : A} (Ha : a ≠ 0) (Hdvd : (a * b ∣ a * c)) : (b ∣ c) :=
-- sorry
/-
dvd.elim Hdvd
(assume d,
assume : a * c = a * b * d,
have b * d = c, from eq_of_mul_eq_mul_left Ha begin rewrite ←mul.assoc, symmetry, exact this end,
dvd.intro this)
-/
-- theorem dvd_of_mul_dvd_mul_right {a b c : A} (Ha : a ≠ 0) (Hdvd : (b * a ∣ c * a)) : (b ∣ c) :=
-- sorry
/-
dvd.elim Hdvd
(assume d,
assume : c * a = b * a * d,
have b * d * a = c * a, from by rewrite [mul.right_comm, ←this],
have b * d = c, from eq_of_mul_eq_mul_right Ha this,
dvd.intro this)
-/
end
/-
namespace norm_num
local attribute bit0 bit1 add1 [reducible]
local attribute right_distrib left_distrib [simp]
theorem mul_zero [mul_zero_class A] (a : A) : a * zero = zero :=
sorry -- by simp
theorem zero_mul [mul_zero_class A] (a : A) : zero * a = zero :=
sorry -- by simp
theorem mul_one [monoid A] (a : A) : a * one = a :=
sorry -- by simp
theorem mul_bit0 [distrib A] (a b : A) : a * (bit0 b) = bit0 (a * b) :=
sorry -- by simp
theorem mul_bit0_helper [distrib A] (a b t : A) (h : a * b = t) : a * (bit0 b) = bit0 t :=
sorry -- by rewrite -H; simp
theorem mul_bit1 [semiring A] (a b : A) : a * (bit1 b) = bit0 (a * b) + a :=
sorry -- by simp
theorem mul_bit1_helper [semiring A] (a b s t : A) (Hs : a * b = s) (Ht : bit0 s + a = t) :
a * (bit1 b) = t :=
sorry -- by simp
theorem subst_into_prod [has_mul A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)
(prt : tl * tr = t) :
l * r = t :=
sorry -- by simp
theorem mk_cong (op : A → A) (a b : A) (h : a = b) : op a = op b :=
sorry -- by simp
theorem neg_add_neg_eq_of_add_add_eq_zero [add_comm_group A] (a b c : A) (h : c + a + b = 0) :
-a + -b = c :=
sorry
/-
begin
apply add_neg_eq_of_eq_add,
apply neg_eq_of_add_eq_zero,
simp
end
-/
theorem neg_add_neg_helper [add_comm_group A] (a b c : A) (h : a + b = c) : -a + -b = -c :=
sorry -- begin apply iff.mp !neg_eq_neg_iff_eq, simp end
theorem neg_add_pos_eq_of_eq_add [add_comm_group A] (a b c : A) (h : b = c + a) : -a + b = c :=
sorry -- begin apply neg_add_eq_of_eq_add, simp end
theorem neg_add_pos_helper1 [add_comm_group A] (a b c : A) (h : b + c = a) : -a + b = -c :=
sorry -- begin apply neg_add_eq_of_eq_add, apply eq_add_neg_of_add_eq H end
theorem neg_add_pos_helper2 [add_comm_group A] (a b c : A) (h : a + c = b) : -a + b = c :=
sorry -- begin apply neg_add_eq_of_eq_add, rewrite H end
theorem pos_add_neg_helper [add_comm_group A] (a b c : A) (h : b + a = c) : a + b = c :=
sorry -- by simp
theorem sub_eq_add_neg_helper [add_comm_group A] (t₁ t₂ e w₁ w₂: A) (H₁ : t₁ = w₁)
(H₂ : t₂ = w₂) (h : w₁ + -w₂ = e) : t₁ - t₂ = e :=
sorry -- by simp
theorem pos_add_pos_helper [add_comm_group A] (a b c h₁ h₂ : A) (H₁ : a = h₁) (H₂ : b = h₂)
(h : h₁ + h₂ = c) : a + b = c :=
sorry -- by simp
theorem subst_into_subtr [add_group A] (l r t : A) (prt : l + -r = t) : l - r = t :=
sorry -- by simp
theorem neg_neg_helper [add_group A] (a b : A) (h : a = -b) : -a = b :=
sorry -- by simp
theorem neg_mul_neg_helper [ring A] (a b c : A) (h : a * b = c) : (-a) * (-b) = c :=
sorry -- by simp
theorem neg_mul_pos_helper [ring A] (a b c : A) (h : a * b = c) : (-a) * b = -c :=
sorry -- by simp
theorem pos_mul_neg_helper [ring A] (a b c : A) (h : a * b = c) : a * (-b) = -c :=
sorry -- by simp
end norm_num
attribute [simp]
zero_mul mul_zero
attribute [simp]
neg_mul_eq_neg_mul_symm mul_neg_eq_neg_mul_symm
attribute [simp]
left_distrib right_distrib
-/
|
ee46a5bb6d1e793b0117a1c90474b7532892290b | c8af905dcd8475f414868d303b2eb0e9d3eb32f9 | /src/data/cpi/name.lean | 2ca756cee791e0a402e888cd935e909a22c5454d | [
"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 | 14,002 | lean | /- The definition of environments, contexts and names within the continuous-π
calculus.
Names are represented as de Bruijn indicies for obvious reasons. We use the
same representation of names as [1], indexing them by the context that they
exist in. This ensures that names are always well formed, thus avoiding many
common pitfalls that occur when renaming and shuffling terms.
We have two kinds of names which, while sharing a context type, do have
rather different meanings:
- References to species definitions: The context here acts as a global
environment `ω', holding the definitions of species. Species invocations
`D(a̅)' index into this table.
Each reference within this environment is given an arity, holding the
arity of its corresponding definition.
Unlike other contexts, the environment should remain constant across a
whole series of processes.
- Names exist on the main π-calculus level, either introduced by the global
affinity network or locall bound by restrictions.
Each name also has an arity, representing the arity of the corresponding
affinity network. Names then index into that affinity network, using finite
number bounded by the arity.
[1]: Proof-relevant π-calculus: a constructive account of concurrency and
causality, Roly Perera, James Cheney
-/
import data.fin data.vector data.vector2
namespace cpi
/-- A context under which terms may be evaluated and names resolved.
Each level of the context holds the arity of the name defined at that point.
-/
@[derive decidable_eq, nolint has_inhabited_instance]
inductive context : Type
| nil : context
| extend : ℕ → context → context
/-- A reference to a species definition within the global definition context. -/
@[derive decidable_eq, nolint has_inhabited_instance]
inductive reference : ℕ → context → Type
| zero {ω : context} (n : ℕ) : reference n (context.extend n ω)
| extend {ω : context} {n m : ℕ} : reference n ω → reference n (context.extend m ω)
/-- The set of names within the continuous π-calculus. -/
@[derive decidable_eq, nolint has_inhabited_instance]
inductive name : context → Type
| zero {Γ} {n : ℕ} : fin n → name (context.extend n Γ)
| extend {Γ} {n : ℕ} : name Γ → name (context.extend n Γ)
/-- The "depth" of a variable.
This is effectively a name, but without the index into the affinity network.
It is used to determine if the affinity network appears at all within a
term.
Technically this property could be defined as "does any name of this level
appear" - it may be worth seeing if that simplifies things in the future. -/
@[derive decidable_eq, nolint has_inhabited_instance]
inductive level : context → Type
| zero {Γ} {n} : level (context.extend n Γ)
| extend {Γ} {n} : level Γ → level (context.extend n Γ)
/-- Get the variable level/depth. This doesn't have much use aside for pretty-printing. -/
protected def reference.level : ∀ {Γ n}, reference Γ n → ℕ
| Γ n (reference.zero _) := 0
| Γ n (reference.extend r) := 1 + reference.level r
instance {Γ n} : has_repr (reference Γ n) := ⟨ λ x, repr (reference.level x) ⟩
namespace name
/-- Get the variable index. This doesn't have much use aside for pretty-printing. -/
protected def idx : ∀ {Γ}, name Γ → ℕ
| ._ (name.zero a) := a
| ._ (name.extend a) := idx a
/-- Get the variable level/depth. This doesn't have much use aside for pretty-printing. -/
protected def level : ∀ {Γ}, name Γ → ℕ
| ._ (name.zero a) := 0
| ._ (name.extend a) := 1 + level a
instance {Γ} : has_repr (name Γ) := ⟨ λ x, repr (name.level x) ++ "." ++ repr (name.idx x) ⟩
/-- Get the level of this name. -/
def to_level : ∀ {Γ}, name Γ → level Γ
| ._ (zero _) := level.zero
| ._ (extend a) := level.extend (to_level a)
section free
/-- Determine if this variable is on a specific level or depth.
This can be thought of as a determining if a given level is free within
this variable. -/
def at_level : ∀ {Γ}, level Γ → name Γ → Prop
| ._ level.zero (zero _) := true
| ._ (level.extend l) (extend a) := at_level l a
| ._ level.zero (extend _) := false
| ._ (level.extend _) (zero _) := false
instance {Γ} : has_mem (level Γ) (name Γ) := ⟨ at_level ⟩
private def at_level_decide :
∀ {Γ} (l : level Γ) (a : name Γ), decidable (at_level l a)
| ._ level.zero (zero _) := decidable.true
| ._ (level.extend l) (extend a) := at_level_decide l a
| ._ level.zero (extend _) := decidable.false
| ._ (level.extend _) (zero _) := decidable.false
instance at_level.decidable {Γ} {l} {a : name Γ} : decidable (at_level l a)
:= at_level_decide l a
/-- Any variable is always at the level provided by to_level. -/
theorem to_level_at : ∀ {Γ} (a : name Γ), name.to_level a ∈ a
| ._ (zero _) := by unfold to_level
| ._ (extend n) := to_level_at n
end free
/- Renaming applies a function to all variables in the current context,
mapping them to a new set of variables in a different (or the same)
context.
Our renaming code is pretty typical, though with some additional
complexities. The actual renaming function receives evidence that the
provided variable is used (typically, that it is free within the term
begin renamed).
While this may seem like an obvious fact, it is crucial to allow lowering
the level of names - if we know `name.zero ∉ A', then we can safely reduce
all variables by one, as we can show by contradiction that our renaming
function doesn't receive `name.zero'.
Any functions suffixed with `_with' use this more complex definition of
renaming - we also provide simpler ones which provide a simple
`name Γ → name Δ' interface (and a few additional guarantees). -/
section rename
/-- Wrap a renaming function, making it suitable for a nested context. -/
def ext_with {Γ Δ} {n}
(P : level (context.extend n Γ) → Prop)
(ρ : Π (x : name Γ), P (level.extend (name.to_level x)) → name Δ)
: Π (x : name (context.extend n Γ)), P (name.to_level x) → name (context.extend n Δ)
| (zero idx) p := zero idx
| (extend a) p := extend (ρ a p)
/-- Extending with `id' does nothing. -/
lemma ext_with_identity :
∀ {Γ} {n : ℕ}
(P : level (context.extend n Γ) → Prop)
(a : name (context.extend n Γ)) (p : P (name.to_level a))
, ext_with P (λ x _, x) a p = a
| Γ n P (zero lt) _ := rfl
| Γ n P (extend a) _ := rfl
/-- Extending with `id' is equivalent to the identity function. -/
lemma ext_with_id {Γ} {n : ℕ} (P : level (context.extend n Γ) → Prop)
: ext_with P (λ x _, x) = λ x _, x
:= funext $ λ a, funext (ext_with_identity P a)
/-- Wrap a simple renaming function, making it suitable for a nested
context. -/
@[reducible]
def ext {Γ Δ} {n} (ρ : name Γ → name Δ)
: name (context.extend n Γ) → name (context.extend n Δ)
| a := ext_with (λ _, true) (λ x p, ρ x) a true.intro
/-- Extending with the identity does nothing. -/
lemma ext_identity {Γ} {n : ℕ} (a : name (context.extend n Γ))
: ext id a = a
:= ext_with_identity _ a _
/-- Extending with `id' is equivalent to the identity function. -/
lemma ext_id : ∀ {Γ} {n : ℕ}, @ext Γ Γ n id = id
| Γ n := funext ext_identity
/-- Composing extensions is equivalent extending a composition. -/
lemma ext_with_compose :
∀ {Γ Δ η} {n : ℕ}
(P : level (context.extend n Γ) → Prop)
(ρ : Π (x : name Γ), P (level.extend (name.to_level x)) → name Δ)
(σ : name Δ → name η)
(a : name (context.extend n Γ)) (p : P (name.to_level a))
, ext σ (ext_with P ρ a p) = ext_with P (λ a p, σ (ρ a p)) a p
| Γ Δ η n P ρ σ (zero lt) _ := rfl
| Γ Δ η n P ρ σ (extend a) _ := rfl
/-- Composing extensions is equivalent extending a composition. -/
lemma ext_with_comp {Γ Δ η} {n : ℕ}
(P : level (context.extend n Γ) → Prop)
(ρ : Π (x : name Γ), P (level.extend (name.to_level x)) → name Δ)
(σ : name Δ → name η)
: (λ a p, ext σ (ext_with P ρ a p)) = ext_with P (λ a p, σ (ρ a p))
:= funext $ λ a, funext (ext_with_compose P ρ σ a)
/-- Composing simple extensions is equivalent extending a composition. -/
lemma ext_compose {Γ Δ η} (ρ : name Γ → name Δ) (σ : name Δ → name η) {n : ℕ}
(a : name (context.extend n Γ))
: ext σ (ext ρ a) = ext (σ ∘ ρ) a
:= ext_with_compose (λ _, true) (λ x _, ρ x) σ a true.intro
/-- Composing simple extensions is equivalent extending a composition. -/
lemma ext_comp {Γ Δ η} (ρ : name Γ → name Δ) (σ : name Δ → name η) {n : ℕ}
: (ext σ ∘ ext ρ) = @ext _ _ n (σ ∘ ρ)
:= funext (ext_compose ρ σ)
/-- Extending then renaming with an extended function, is equivalent to
renaming then extending. -/
lemma ext_extend {Γ Δ} {n : ℕ} (ρ : name Γ → name Δ)
: (ext ρ ∘ extend) = (@extend Δ n ∘ ρ) := funext (λ x, rfl)
lemma ext_zero {Γ Δ} {n : ℕ} (ρ : name Γ → name Δ)
: (ext ρ ∘ zero) = (@zero Δ n) := funext (λ x, rfl)
/-- Rewrite one ext_with to another.
This is largely useful when proving renaming properties in more complex
types. -/
lemma ext_with_discard {Γ Δ} {n}
(P : level (context.extend n Γ) → Prop)
(ρ : name Γ → name Δ)
: (ext_with P (λ a _, ρ a))
= (λ a _, name.ext_with (λ _x, true) (λ x _, ρ x) a true.intro)
:= funext $ λ a, funext $ λ free, by { cases a; from rfl }
lemma ext.inj {Γ Δ n} {ρ : name Γ → name Δ} (inj : function.injective ρ)
: function.injective (@ext Γ Δ n ρ)
| (name.zero i) (name.zero j) eq := by { cases eq, from rfl }
| (name.zero i) (name.extend b) eq := by contradiction
| (name.extend i) (name.zero j) eq := by contradiction
| (name.extend a) (name.extend b) eq := congr_arg extend (inj (extend.inj eq))
end rename
section swap
/-- Swap the two topmost variables. Used for exchange of ν(_) terms. -/
def swap {Γ} {M N : ℕ}
: name (context.extend M (context.extend N Γ))
→ name (context.extend N (context.extend M Γ))
| (zero lt) := extend (zero lt)
| (extend (zero lt)) := zero lt
| (extend (extend n)) := extend (extend n)
/-- A twice-extended renaming function can be applied before or after a
swap. -/
lemma swap_ext_ext {Γ Δ} {ρ : name Γ → name Δ} {m n : ℕ}
: (ext (ext ρ) ∘ swap)
= (swap ∘ @ext _ _ n (@ext _ _ m ρ))
:= funext $ λ α,
match α with
| zero p := rfl
| extend (zero lt) := rfl
| extend (extend _) := rfl
end
/-- Incrementing names and swapping, is just the same as incrementing
everything above 0. -/
lemma swap_comp_extend {Γ} {m n : ℕ}
: (@name.swap Γ m n ∘ name.extend) = (name.ext name.extend)
:= funext $ λ a, by { cases a; from rfl }
/-- Incrementing all names above 0 and swapping is the same as just
incrementing everything. -/
lemma swap_comp_ext_extend {Γ} {m n : ℕ}
: (@name.swap Γ m n ∘ name.ext name.extend) = name.extend
:= funext $ λ a, by { cases a; from rfl }
/-- Swapping twice does nothing. -/
lemma swap_swap_identity :
∀ {Γ} {a b : ℕ} (a : name (context.extend b (context.extend a Γ)))
, name.swap (name.swap a) = a
| Γ a b (name.zero _) := rfl
| Γ a b (name.extend (name.zero _)) := rfl
| Γ a b (name.extend (name.extend _)) := rfl
/-- Swapping twice gives the identity. -/
lemma swap_swap :
∀ {Γ} {a b : ℕ}
, (@name.swap Γ a b) ∘ name.swap = id
| Γ a b := funext swap_swap_identity
end swap
section application
/-- Given a list of names bs, construct a renaming function which renames
level-0 names to the corresponding names in bs. -/
def mk_apply {Γ} {b} (bs : vector (name Γ) b)
: name (context.extend b Γ) → name Γ
| (zero idx) := vector.nth bs idx
| (extend e) := e
lemma mk_apply_rename
{Γ Δ} {b} (ρ : name Γ → name Δ) {bs : vector (name Γ) b}
: ρ ∘ mk_apply bs = mk_apply (vector.map ρ bs) ∘ name.ext ρ
:= funext $ λ a,
by { cases a; simp only [mk_apply, ext, ext_with, vector.nth_map, function.comp] }
lemma mk_apply_ext {Γ} {b} {bs : vector (name Γ) b}
: mk_apply bs ∘ (@extend Γ b) = id
:= funext $λ α, by { cases α; unfold mk_apply id function.comp }
end application
section drop
/-- Reduce the level of a variable by one, given a proof it's unused. -/
def drop_var {Γ} {n}
(P : level (context.extend n Γ) → Prop) (p : (¬ P level.zero))
: Π a, P (name.to_level a) → name Γ
| (name.zero idx) q := by { unfold name.to_level at q, contradiction }
| (name.extend a) _ := a
/-- Show a renaming function which drops then extends is the identity. -/
lemma drop_var_compose {Γ} {n}
(P : level (context.extend n Γ) → Prop) (p : (¬ P level.zero))
: (λ a f, name.extend (drop_var P p a f)) = λ a _, a
:= funext $ λ a, funext $ λ q, begin
cases a,
case name.zero { unfold name.to_level at q, contradiction },
case name.extend { from rfl }
end
end drop
/-- Get the index of a name in the singleton context . -/
def to_idx {n : ℕ} : name (context.extend n context.nil) → fin n
| (name.zero i) := i
| (name.extend a) := by cases a
end name
end cpi
#lint-
|
cc55ac1b1945f671dd90ad3d67db934b07436d3f | 4727251e0cd73359b15b664c3170e5d754078599 | /src/ring_theory/flat.lean | 7e0bae6227572ba4b7774781ea52f054e10d3780 | [
"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 | 2,615 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import ring_theory.noetherian
/-!
# Flat modules
A module `M` over a commutative ring `R` is *flat*
if for all finitely generated ideals `I` of `R`,
the canonical map `I ⊗ M →ₗ M` is injective.
This is equivalent to the claim that for all injective `R`-linear maps `f : M₁ → M₂`
the induced map `M₁ ⊗ M → M₂ ⊗ M` is injective.
See <https://stacks.math.columbia.edu/tag/00HD>.
This result is not yet formalised.
## Main declaration
* `module.flat`: the predicate asserting that an `R`-module `M` is flat.
## TODO
* Show that tensoring with a flat module preserves injective morphisms.
Show that this is equivalent to be flat.
See <https://stacks.math.columbia.edu/tag/00HD>.
To do this, it is probably a good idea to think about a suitable
categorical induction principle that should be applied to the category of `R`-modules,
and that will take care of the administrative side of the proof.
* Define flat `R`-algebras
* Define flat ring homomorphisms
- Show that the identity is flat
- Show that composition of flat morphisms is flat
* Show that flatness is stable under base change (aka extension of scalars)
For base change, it will be very useful to have a "characteristic predicate"
instead of relying on the construction `A ⊗ B`.
Indeed, such a predicate should allow us to treat both
`polynomial A` and `A ⊗ polynomial R` as the base change of `polynomial R` to `A`.
(Similar examples exist with `fin n → R`, `R × R`, `ℤ[i] ⊗ ℝ`, etc...)
* Generalize flatness to noncommutative rings.
-/
universes u v
namespace module
open function (injective)
open linear_map (lsmul)
open_locale tensor_product
/-- An `R`-module `M` is flat if for all finitely generated ideals `I` of `R`,
the canonical map `I ⊗ M →ₗ M` is injective. -/
class flat (R : Type u) (M : Type v) [comm_ring R] [add_comm_group M] [module R M] : Prop :=
(out : ∀ ⦃I : ideal R⦄ (hI : I.fg), injective (tensor_product.lift ((lsmul R M).comp I.subtype)))
namespace flat
open tensor_product linear_map _root_.submodule
instance self (R : Type u) [comm_ring R] : flat R R :=
⟨begin
intros I hI,
rw ← equiv.injective_comp (tensor_product.rid R I).symm.to_equiv,
convert subtype.coe_injective using 1,
ext x,
simp only [function.comp_app, linear_equiv.coe_to_equiv, rid_symm_apply, comp_apply,
mul_one, lift.tmul, subtype_apply, algebra.id.smul_eq_mul, lsmul_apply]
end⟩
end flat
end module
|
760f6a3d490eb4dd0be071cfdf249abb47850a7d | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Elab/Tactic/BuiltinTactic.lean | 46f7556064de7bc2651bde591c914632724fa2a0 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 14,239 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Tactic.Refl
import Lean.Elab.Tactic.Basic
import Lean.Elab.Tactic.ElabTerm
namespace Lean.Elab.Tactic
open Meta
open Parser.Tactic
@[builtinTactic withAnnotateState] def evalWithAnnotateState : Tactic
| `(tactic| with_annotate_state $stx $t) =>
withTacticInfoContext stx (evalTactic t)
| _ => throwUnsupportedSyntax
@[builtinTactic Lean.Parser.Tactic.«done»] def evalDone : Tactic := fun _ =>
done
@[builtinTactic seq1] def evalSeq1 : Tactic := fun stx => do
let args := stx[0].getArgs
for i in [:args.size] do
if i % 2 == 0 then
evalTactic args[i]!
else
saveTacticInfoForToken args[i]! -- add `TacticInfo` node for `;`
@[builtinTactic paren] def evalParen : Tactic := fun stx =>
evalTactic stx[1]
def isCheckpointableTactic (arg : Syntax) : TacticM Bool := do
-- TODO: make it parametric
let kind := arg.getKind
return kind == ``Lean.Parser.Tactic.save
partial def addCheckpoints (args : Array Syntax) : TacticM (Array Syntax) := do
-- if (← readThe Term.Context).tacticCache? |>.isSome then
if (← args.anyM fun arg => isCheckpointableTactic arg[0]) then
let argsNew ← go 0 #[] #[]
return argsNew
return args
where
push (acc : Array Syntax) (result : Array Syntax) : Array Syntax :=
if acc.isEmpty then
result
else
let ref := acc.back
let accSeq := mkNode ``Lean.Parser.Tactic.tacticSeq1Indented #[mkNullNode acc]
let checkpoint := mkNode ``Lean.Parser.Tactic.checkpoint #[mkAtomFrom ref "checkpoint", accSeq]
result.push (mkNode groupKind #[checkpoint, mkNullNode])
go (i : Nat) (acc : Array Syntax) (result : Array Syntax) : TacticM (Array Syntax) := do
if h : i < args.size then
let arg := args.get ⟨i, h⟩
if (← isCheckpointableTactic arg[0]) then
-- `argNew` is `arg` as singleton sequence. The idea is to make sure it does not satisfy `isCheckpointableTactic` anymore
let argNew := arg.setArg 0 (mkNullNode #[arg[0]])
let acc := acc.push argNew
go (i+1) #[] (push acc result)
else
go (i+1) (acc.push arg) result
else
return result ++ acc
/-- Evaluate `many (group (tactic >> optional ";")) -/
def evalManyTacticOptSemi (stx : Syntax) : TacticM Unit := do
for seqElem in (← addCheckpoints stx.getArgs) do
evalTactic seqElem[0]
saveTacticInfoForToken seqElem[1] -- add TacticInfo node for `;`
@[builtinTactic tacticSeq1Indented] def evalTacticSeq1Indented : Tactic := fun stx =>
evalManyTacticOptSemi stx[0]
@[builtinTactic tacticSeqBracketed] def evalTacticSeqBracketed : Tactic := fun stx => do
let initInfo ← mkInitialTacticInfo stx[0]
withRef stx[2] <| closeUsingOrAdmit do
-- save state before/after entering focus on `{`
withInfoContext (pure ()) initInfo
evalManyTacticOptSemi stx[1]
@[builtinTactic Parser.Tactic.focus] def evalFocus : Tactic := fun stx => do
let mkInfo ← mkInitialTacticInfo stx[0]
focus do
-- show focused state on `focus`
withInfoContext (pure ()) mkInfo
evalTactic stx[1]
private def getOptRotation (stx : Syntax) : Nat :=
if stx.isNone then 1 else stx[0].toNat
@[builtinTactic Parser.Tactic.rotateLeft] def evalRotateLeft : Tactic := fun stx => do
let n := getOptRotation stx[1]
setGoals <| (← getGoals).rotateLeft n
@[builtinTactic Parser.Tactic.rotateRight] def evalRotateRight : Tactic := fun stx => do
let n := getOptRotation stx[1]
setGoals <| (← getGoals).rotateRight n
@[builtinTactic Parser.Tactic.open] def evalOpen : Tactic := fun stx => do
try
pushScope
let openDecls ← elabOpenDecl stx[1]
withTheReader Core.Context (fun ctx => { ctx with openDecls := openDecls }) do
evalTactic stx[3]
finally
popScope
@[builtinTactic Parser.Tactic.set_option] def elabSetOption : Tactic := fun stx => do
let options ← Elab.elabSetOption stx[1] stx[2]
withTheReader Core.Context (fun ctx => { ctx with maxRecDepth := maxRecDepth.get options, options := options }) do
evalTactic stx[4]
@[builtinTactic Parser.Tactic.allGoals] def evalAllGoals : Tactic := fun stx => do
let mvarIds ← getGoals
let mut mvarIdsNew := #[]
for mvarId in mvarIds do
unless (← mvarId.isAssigned) do
setGoals [mvarId]
try
evalTactic stx[1]
mvarIdsNew := mvarIdsNew ++ (← getUnsolvedGoals)
catch ex =>
if (← read).recover then
logException ex
mvarIdsNew := mvarIdsNew.push mvarId
else
throw ex
setGoals mvarIdsNew.toList
@[builtinTactic Parser.Tactic.anyGoals] def evalAnyGoals : Tactic := fun stx => do
let mvarIds ← getGoals
let mut mvarIdsNew := #[]
let mut succeeded := false
for mvarId in mvarIds do
unless (← mvarId.isAssigned) do
setGoals [mvarId]
try
evalTactic stx[1]
mvarIdsNew := mvarIdsNew ++ (← getUnsolvedGoals)
succeeded := true
catch _ =>
mvarIdsNew := mvarIdsNew.push mvarId
unless succeeded do
throwError "failed on all goals"
setGoals mvarIdsNew.toList
@[builtinTactic tacticSeq] def evalTacticSeq : Tactic := fun stx =>
evalTactic stx[0]
partial def evalChoiceAux (tactics : Array Syntax) (i : Nat) : TacticM Unit :=
if h : i < tactics.size then
let tactic := tactics.get ⟨i, h⟩
catchInternalId unsupportedSyntaxExceptionId
(evalTactic tactic)
(fun _ => evalChoiceAux tactics (i+1))
else
throwUnsupportedSyntax
@[builtinTactic choice] def evalChoice : Tactic := fun stx =>
evalChoiceAux stx.getArgs 0
@[builtinTactic skip] def evalSkip : Tactic := fun _ => pure ()
@[builtinTactic unknown] def evalUnknown : Tactic := fun stx => do
addCompletionInfo <| CompletionInfo.tactic stx (← getGoals)
@[builtinTactic failIfSuccess] def evalFailIfSuccess : Tactic := fun stx =>
Term.withoutErrToSorry <| withoutRecover do
let tactic := stx[1]
if (← try evalTactic tactic; pure true catch _ => pure false) then
throwError "tactic succeeded"
@[builtinTactic traceState] def evalTraceState : Tactic := fun _ => do
let gs ← getUnsolvedGoals
withPPForTacticGoal <| addRawTrace (goalsToMessageData gs)
@[builtinTactic traceMessage] def evalTraceMessage : Tactic := fun stx => do
match stx[1].isStrLit? with
| none => throwIllFormedSyntax
| some msg => withRef stx[0] <| addRawTrace msg
@[builtinTactic Lean.Parser.Tactic.assumption] def evalAssumption : Tactic := fun _ =>
liftMetaTactic fun mvarId => do mvarId.assumption; pure []
@[builtinTactic Lean.Parser.Tactic.contradiction] def evalContradiction : Tactic := fun _ =>
liftMetaTactic fun mvarId => do mvarId.contradiction; pure []
@[builtinTactic Lean.Parser.Tactic.refl] def evalRefl : Tactic := fun _ =>
liftMetaTactic fun mvarId => do mvarId.refl; pure []
@[builtinTactic Lean.Parser.Tactic.intro] def evalIntro : Tactic := fun stx => do
match stx with
| `(tactic| intro) => introStep none `_
| `(tactic| intro $h:ident) => introStep h h.getId
| `(tactic| intro _%$tk) => introStep tk `_
| `(tactic| intro $pat:term) => evalTactic (← `(tactic| intro h; match h with | $pat:term => ?_; try clear h))
| `(tactic| intro $h:term $hs:term*) => evalTactic (← `(tactic| intro $h:term; intro $hs:term*))
| _ => throwUnsupportedSyntax
where
introStep (ref : Option Syntax) (n : Name) : TacticM Unit := do
let fvar ← liftMetaTacticAux fun mvarId => do
let (fvar, mvarId) ← mvarId.intro n
pure (fvar, [mvarId])
if let some stx := ref then
withMainContext do
Term.addLocalVarInfo stx (mkFVar fvar)
@[builtinTactic Lean.Parser.Tactic.introMatch] def evalIntroMatch : Tactic := fun stx => do
let matchAlts := stx[1]
let stxNew ← liftMacroM <| Term.expandMatchAltsIntoMatchTactic stx matchAlts
withMacroExpansion stx stxNew <| evalTactic stxNew
@[builtinTactic «intros»] def evalIntros : Tactic := fun stx =>
match stx with
| `(tactic| intros) => liftMetaTactic fun mvarId => do
let (_, mvarId) ← mvarId.intros
return [mvarId]
| `(tactic| intros $ids*) => do
let fvars ← liftMetaTacticAux fun mvarId => do
let (fvars, mvarId) ← mvarId.introN ids.size (ids.map getNameOfIdent').toList
return (fvars, [mvarId])
withMainContext do
for stx in ids, fvar in fvars do
Term.addLocalVarInfo stx (mkFVar fvar)
| _ => throwUnsupportedSyntax
@[builtinTactic Lean.Parser.Tactic.revert] def evalRevert : Tactic := fun stx =>
match stx with
| `(tactic| revert $hs*) => do
let (_, mvarId) ← (← getMainGoal).revert (← getFVarIds hs)
replaceMainGoal [mvarId]
| _ => throwUnsupportedSyntax
@[builtinTactic Lean.Parser.Tactic.clear] def evalClear : Tactic := fun stx =>
match stx with
| `(tactic| clear $hs*) => do
let fvarIds ← getFVarIds hs
let fvarIds ← withMainContext <| sortFVarIds fvarIds
for fvarId in fvarIds.reverse do
withMainContext do
let mvarId ← (← getMainGoal).clear fvarId
replaceMainGoal [mvarId]
| _ => throwUnsupportedSyntax
def forEachVar (hs : Array Syntax) (tac : MVarId → FVarId → MetaM MVarId) : TacticM Unit := do
for h in hs do
withMainContext do
let fvarId ← getFVarId h
let mvarId ← tac (← getMainGoal) fvarId
replaceMainGoal [mvarId]
@[builtinTactic Lean.Parser.Tactic.subst] def evalSubst : Tactic := fun stx =>
match stx with
| `(tactic| subst $hs*) => forEachVar hs Meta.subst
| _ => throwUnsupportedSyntax
@[builtinTactic Lean.Parser.Tactic.substVars] def evalSubstVars : Tactic := fun _ =>
liftMetaTactic fun mvarId => return [← substVars mvarId]
/--
Searches for a metavariable `g` s.t. `tag` is its exact name.
If none then searches for a metavariable `g` s.t. `tag` is a suffix of its name.
If none, then it searches for a metavariable `g` s.t. `tag` is a prefix of its name. -/
private def findTag? (mvarIds : List MVarId) (tag : Name) : TacticM (Option MVarId) := do
match (← mvarIds.findM? fun mvarId => return tag == (← mvarId.getDecl).userName) with
| some mvarId => return mvarId
| none =>
match (← mvarIds.findM? fun mvarId => return tag.isSuffixOf (← mvarId.getDecl).userName) with
| some mvarId => return mvarId
| none => mvarIds.findM? fun mvarId => return tag.isPrefixOf (← mvarId.getDecl).userName
def renameInaccessibles (mvarId : MVarId) (hs : TSyntaxArray ``binderIdent) : TacticM MVarId := do
if hs.isEmpty then
return mvarId
else
let mvarDecl ← mvarId.getDecl
let mut lctx := mvarDecl.lctx
let mut hs := hs
let mut info := #[]
let mut found : NameSet := {}
let n := lctx.numIndices
for i in [:n] do
let j := n - i - 1
match lctx.getAt? j with
| none => pure ()
| some localDecl =>
if localDecl.userName.hasMacroScopes || found.contains localDecl.userName then
if let `(binderIdent| $h:ident) := hs.back then
let newName := h.getId
lctx := lctx.setUserName localDecl.fvarId newName
info := info.push (localDecl.fvarId, h)
hs := hs.pop
if hs.isEmpty then
break
found := found.insert localDecl.userName
unless hs.isEmpty do
logError m!"too many variable names provided"
let mvarNew ← mkFreshExprMVarAt lctx mvarDecl.localInstances mvarDecl.type MetavarKind.syntheticOpaque mvarDecl.userName
withSaveInfoContext <| mvarNew.mvarId!.withContext do
for (fvarId, stx) in info do
Term.addLocalVarInfo stx (mkFVar fvarId)
mvarId.assign mvarNew
return mvarNew.mvarId!
private def getCaseGoals (tag : TSyntax ``binderIdent) : TacticM (MVarId × List MVarId) := do
let gs ← getUnsolvedGoals
let g ← if let `(binderIdent| $tag:ident) := tag then
let tag := tag.getId
let some g ← findTag? gs tag | throwError "tag not found"
pure g
else
getMainGoal
return (g, gs.erase g)
@[builtinTactic «case»] def evalCase : Tactic
| stx@`(tactic| case $tag $hs* =>%$arr $tac:tacticSeq) => do
let (g, gs) ← getCaseGoals tag
let g ← renameInaccessibles g hs
setGoals [g]
g.setTag Name.anonymous
withCaseRef arr tac do
closeUsingOrAdmit (withTacticInfoContext stx (evalTactic tac))
setGoals gs
| _ => throwUnsupportedSyntax
@[builtinTactic «case'»] def evalCase' : Tactic
| `(tactic| case' $tag $hs* =>%$arr $tac:tacticSeq) => do
let (g, gs) ← getCaseGoals tag
let g ← renameInaccessibles g hs
let mvarTag ← g.getTag
setGoals [g]
withCaseRef arr tac (evalTactic tac)
let gs' ← getUnsolvedGoals
if let [g'] := gs' then
g'.setTag mvarTag
setGoals (gs' ++ gs)
| _ => throwUnsupportedSyntax
@[builtinTactic «renameI»] def evalRenameInaccessibles : Tactic
| `(tactic| rename_i $hs*) => do replaceMainGoal [← renameInaccessibles (← getMainGoal) hs]
| _ => throwUnsupportedSyntax
@[builtinTactic «first»] partial def evalFirst : Tactic := fun stx => do
let tacs := stx[1].getArgs
if tacs.isEmpty then throwUnsupportedSyntax
loop tacs 0
where
loop (tacs : Array Syntax) (i : Nat) :=
if i == tacs.size - 1 then
evalTactic tacs[i]![1]
else
evalTactic tacs[i]![1] <|> loop tacs (i+1)
@[builtinTactic «fail»] def evalFail : Tactic := fun stx => do
let goals ← getGoals
let goalsMsg := MessageData.joinSep (goals.map MessageData.ofGoal) m!"\n\n"
match stx with
| `(tactic| fail) => throwError "tactic 'fail' failed\n{goalsMsg}"
| `(tactic| fail $msg:str) => throwError "{msg.getString}\n{goalsMsg}"
| _ => throwUnsupportedSyntax
@[builtinTactic dbgTrace] def evalDbgTrace : Tactic := fun stx => do
match stx[1].isStrLit? with
| none => throwIllFormedSyntax
| some msg => dbg_trace msg
@[builtinTactic sleep] def evalSleep : Tactic := fun stx => do
match stx[1].isNatLit? with
| none => throwIllFormedSyntax
| some ms => IO.sleep ms.toUInt32
end Lean.Elab.Tactic
|
ae209082628b2b7d9a9f5551e51fdc6a98def50a | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/types.lean | ed0d159202683615cd3286ca7652b30d807ff4c3 | [
"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 | 10,666 | 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, Johannes Hölzl
-/
import category_theory.fully_faithful
import data.equiv.basic
/-!
# The category `Type`.
In this section we set up the theory so that Lean's types and functions between them
can be viewed as a `large_category` in our framework.
Lean can not transparently view a function as a morphism in this category,
and needs a hint in order to be able to type check.
We provide the abbreviation `as_hom f` to guide type checking,
as well as a corresponding notation `↾ f`. (Entered as `\upr `.)
We provide various simplification lemmas for functors and natural transformations valued in `Type`.
We define `ulift_functor`, from `Type u` to `Type (max u v)`, and show that it is fully faithful
(but not, of course, essentially surjective).
We prove some basic facts about the category `Type`:
* epimorphisms are surjections and monomorphisms are injections,
* `iso` is both `iso` and `equiv` to `equiv` (at least within a fixed universe),
* every type level `is_lawful_functor` gives a categorical functor `Type ⥤ Type`
(the corresponding fact about monads is in `src/category_theory/monad/types.lean`).
-/
namespace category_theory
universes v v' w u u' -- declare the `v`'s first; see `category_theory.category` for an explanation
instance types : large_category (Type u) :=
{ hom := λ a b, (a → b),
id := λ a, id,
comp := λ _ _ _ f g, g ∘ f }
lemma types_hom {α β : Type u} : (α ⟶ β) = (α → β) := rfl
lemma types_id (X : Type u) : 𝟙 X = id := rfl
lemma types_comp {X Y Z : Type u} (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ g = g ∘ f := rfl
@[simp]
lemma types_id_apply (X : Type u) (x : X) : ((𝟙 X) : X → X) x = x := rfl
@[simp]
lemma types_comp_apply {X Y Z : Type u} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := rfl
@[simp]
lemma hom_inv_id_apply {X Y : Type u} (f : X ≅ Y) (x : X) : f.inv (f.hom x) = x :=
congr_fun f.hom_inv_id x
@[simp]
lemma inv_hom_id_apply {X Y : Type u} (f : X ≅ Y) (y : Y) : f.hom (f.inv y) = y :=
congr_fun f.inv_hom_id y
/-- `as_hom f` helps Lean type check a function as a morphism in the category `Type`. -/
-- Unfortunately without this wrapper we can't use `category_theory` idioms, such as `is_iso f`.
abbreviation as_hom {α β : Type u} (f : α → β) : α ⟶ β := f
-- If you don't mind some notation you can use fewer keystrokes:
notation `↾` f : 200 := as_hom f -- type as \upr in VScode
section -- We verify the expected type checking behaviour of `as_hom`.
variables (α β γ : Type u) (f : α → β) (g : β → γ)
example : α → γ := ↾f ≫ ↾g
example [is_iso ↾f] : mono ↾f := by apply_instance
example [is_iso ↾f] : ↾f ≫ inv ↾f = 𝟙 α := by simp
end
namespace functor
variables {J : Type u} [category.{v} J]
/--
The sections of a functor `J ⥤ Type` are
the choices of a point `u j : F.obj j` for each `j`,
such that `F.map f (u j) = u j` for every morphism `f : j ⟶ j'`.
We later use these to define limits in `Type` and in many concrete categories.
-/
def sections (F : J ⥤ Type w) : set (Π j, F.obj j) :=
{ u | ∀ {j j'} (f : j ⟶ j'), F.map f (u j) = u j'}
end functor
namespace functor_to_types
variables {C : Type u} [category.{v} C] (F G H : C ⥤ Type w) {X Y Z : C}
variables (σ : F ⟶ G) (τ : G ⟶ H)
@[simp] lemma map_comp_apply (f : X ⟶ Y) (g : Y ⟶ Z) (a : F.obj X) :
(F.map (f ≫ g)) a = (F.map g) ((F.map f) a) :=
by simp [types_comp]
@[simp] lemma map_id_apply (a : F.obj X) : (F.map (𝟙 X)) a = a :=
by simp [types_id]
lemma naturality (f : X ⟶ Y) (x : F.obj X) : σ.app Y ((F.map f) x) = (G.map f) (σ.app X x) :=
congr_fun (σ.naturality f) x
@[simp] lemma comp (x : F.obj X) : (σ ≫ τ).app X x = τ.app X (σ.app X x) := rfl
variables {D : Type u'} [𝒟 : category.{u'} D] (I J : D ⥤ C) (ρ : I ⟶ J) {W : D}
@[simp] lemma hcomp (x : (I ⋙ F).obj W) :
(ρ ◫ σ).app W x = (G.map (ρ.app W)) (σ.app (I.obj W) x) :=
rfl
@[simp] lemma map_inv_map_hom_apply (f : X ≅ Y) (x : F.obj X) : F.map f.inv (F.map f.hom x) = x :=
congr_fun (F.map_iso f).hom_inv_id x
@[simp] lemma map_hom_map_inv_apply (f : X ≅ Y) (y : F.obj Y) : F.map f.hom (F.map f.inv y) = y :=
congr_fun (F.map_iso f).inv_hom_id y
@[simp] lemma hom_inv_id_app_apply (α : F ≅ G) (X) (x) : α.inv.app X (α.hom.app X x) = x :=
congr_fun (α.hom_inv_id_app X) x
@[simp] lemma inv_hom_id_app_apply (α : F ≅ G) (X) (x) : α.hom.app X (α.inv.app X x) = x :=
congr_fun (α.inv_hom_id_app X) x
end functor_to_types
/--
The isomorphism between a `Type` which has been `ulift`ed to the same universe,
and the original type.
-/
def ulift_trivial (V : Type u) : ulift.{u} V ≅ V := by tidy
/--
The functor embedding `Type u` into `Type (max u v)`.
Write this as `ulift_functor.{5 2}` to get `Type 2 ⥤ Type 5`.
-/
def ulift_functor : Type u ⥤ Type (max u v) :=
{ obj := λ X, ulift.{v} X,
map := λ X Y f, λ x : ulift.{v} X, ulift.up (f x.down) }
@[simp] lemma ulift_functor_map {X Y : Type u} (f : X ⟶ Y) (x : ulift.{v} X) :
ulift_functor.map f x = ulift.up (f x.down) := rfl
instance ulift_functor_full : full.{u} ulift_functor :=
{ preimage := λ X Y f x, (f (ulift.up x)).down }
instance ulift_functor_faithful : faithful ulift_functor :=
{ map_injective' := λ X Y f g p, funext $ λ x,
congr_arg ulift.down ((congr_fun p (ulift.up x)) : ((ulift.up (f x)) = (ulift.up (g x)))) }
/-- Any term `x` of a type `X` corresponds to a morphism `punit ⟶ X`. -/
-- TODO We should connect this to a general story about concrete categories
-- whose forgetful functor is representable.
def hom_of_element {X : Type u} (x : X) : punit ⟶ X := λ _, x
lemma hom_of_element_eq_iff {X : Type u} (x y : X) :
hom_of_element x = hom_of_element y ↔ x = y :=
⟨λ H, congr_fun H punit.star, by cc⟩
/--
A morphism in `Type` is a monomorphism if and only if it is injective.
See https://stacks.math.columbia.edu/tag/003C.
-/
lemma mono_iff_injective {X Y : Type u} (f : X ⟶ Y) : mono f ↔ function.injective f :=
begin
split,
{ intros H x x' h,
resetI,
rw ←hom_of_element_eq_iff at ⊢ h,
exact (cancel_mono f).mp h },
{ refine λ H, ⟨λ Z g h H₂, _⟩,
ext z,
replace H₂ := congr_fun H₂ z,
exact H H₂ }
end
/--
A morphism in `Type` is an epimorphism if and only if it is surjective.
See https://stacks.math.columbia.edu/tag/003C.
-/
lemma epi_iff_surjective {X Y : Type u} (f : X ⟶ Y) : epi f ↔ function.surjective f :=
begin
split,
{ intros H,
let g : Y ⟶ ulift Prop := λ y, ⟨true⟩,
let h : Y ⟶ ulift Prop := λ y, ⟨∃ x, f x = y⟩,
suffices : f ≫ g = f ≫ h,
{ resetI,
rw cancel_epi at this,
intro y,
replace this := congr_fun this y,
replace this : true = ∃ x, f x = y := congr_arg ulift.down this,
rw ←this,
trivial },
ext x,
change true ↔ ∃ x', f x' = f x,
rw true_iff,
exact ⟨x, rfl⟩ },
{ intro H,
constructor,
intros Z g h H₂,
apply funext,
rw ←forall_iff_forall_surj H,
intro x,
exact (congr_fun H₂ x : _) }
end
section
/-- `of_type_functor m` converts from Lean's `Type`-based `category` to `category_theory`. This
allows us to use these functors in category theory. -/
def of_type_functor (m : Type u → Type v) [_root_.functor m] [is_lawful_functor m] :
Type u ⥤ Type v :=
{ obj := m,
map := λα β, _root_.functor.map,
map_id' := assume α, _root_.functor.map_id,
map_comp' := assume α β γ f g, funext $ assume a, is_lawful_functor.comp_map f g _ }
variables (m : Type u → Type v) [_root_.functor m] [is_lawful_functor m]
@[simp]
lemma of_type_functor_obj : (of_type_functor m).obj = m := rfl
@[simp]
lemma of_type_functor_map {α β} (f : α → β) :
(of_type_functor m).map f = (_root_.functor.map f : m α → m β) := rfl
end
end category_theory
-- Isomorphisms in Type and equivalences.
namespace equiv
universe u
variables {X Y : Type u}
/--
Any equivalence between types in the same universe gives
a categorical isomorphism between those types.
-/
def to_iso (e : X ≃ Y) : X ≅ Y :=
{ hom := e.to_fun,
inv := e.inv_fun,
hom_inv_id' := funext e.left_inv,
inv_hom_id' := funext e.right_inv }
@[simp] lemma to_iso_hom {e : X ≃ Y} : e.to_iso.hom = e := rfl
@[simp] lemma to_iso_inv {e : X ≃ Y} : e.to_iso.inv = e.symm := rfl
end equiv
universe u
namespace category_theory.iso
open category_theory
variables {X Y : Type u}
/--
Any isomorphism between types gives an equivalence.
-/
def to_equiv (i : X ≅ Y) : X ≃ Y :=
{ to_fun := i.hom,
inv_fun := i.inv,
left_inv := λ x, congr_fun i.hom_inv_id x,
right_inv := λ y, congr_fun i.inv_hom_id y }
@[simp] lemma to_equiv_fun (i : X ≅ Y) : (i.to_equiv : X → Y) = i.hom := rfl
@[simp] lemma to_equiv_symm_fun (i : X ≅ Y) : (i.to_equiv.symm : Y → X) = i.inv := rfl
@[simp] lemma to_equiv_id (X : Type u) : (iso.refl X).to_equiv = equiv.refl X := rfl
@[simp] lemma to_equiv_comp {X Y Z : Type u} (f : X ≅ Y) (g : Y ≅ Z) :
(f ≪≫ g).to_equiv = f.to_equiv.trans (g.to_equiv) := rfl
end category_theory.iso
namespace category_theory
/-- A morphism in `Type u` is an isomorphism if and only if it is bijective. -/
noncomputable
def is_iso_equiv_bijective {X Y : Type u} (f : X ⟶ Y) : is_iso f ≃ function.bijective f :=
equiv_of_subsingleton_of_subsingleton
(λ i, ({ hom := f, .. i } : X ≅ Y).to_equiv.bijective)
(λ b, { .. (equiv.of_bijective f b).to_iso })
end category_theory
-- We prove `equiv_iso_iso` and then use that to sneakily construct `equiv_equiv_iso`.
-- (In this order the proofs are handled by `obviously`.)
/-- Equivalences (between types in the same universe) are the same as (isomorphic to) isomorphisms
of types. -/
@[simps] def equiv_iso_iso {X Y : Type u} : (X ≃ Y) ≅ (X ≅ Y) :=
{ hom := λ e, e.to_iso,
inv := λ i, i.to_equiv, }
/-- Equivalences (between types in the same universe) are the same as (equivalent to) isomorphisms
of types. -/
-- We leave `X` and `Y` as explicit arguments here, because the coercions from `equiv` to a function
-- won't fire without them.
-- TODO: is it still true?
def equiv_equiv_iso (X Y : Type u) : (X ≃ Y) ≃ (X ≅ Y) :=
(equiv_iso_iso).to_equiv
@[simp] lemma equiv_equiv_iso_hom {X Y : Type u} (e : X ≃ Y) :
(equiv_equiv_iso X Y) e = e.to_iso := rfl
@[simp] lemma equiv_equiv_iso_inv {X Y : Type u} (e : X ≅ Y) :
(equiv_equiv_iso X Y).symm e = e.to_equiv := rfl
|
ca90a82c3ff6e628bfcd399e00610f36f4deae33 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/do_eqv.lean | 9c3519386ed36e1fcc2a9e7db3c9f142d3ea608e | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,692 | lean | theorem byCases_Bool_bind [Monad m] (x : m Bool) (f g : Bool → m β) (isTrue : f true = g true) (isFalse : f false = g false) : (x >>= f) = (x >>= g) := by
have : f = g := by
funext b; cases b <;> assumption
rw [this]
theorem eq_findM [Monad m] [LawfulMonad m] (p : α → m Bool) (xs : List α) :
(do for x in xs do
let b ← p x
if b then
return some x
return none)
=
xs.findM? p := by
induction xs with simp [List.findM?]
| cons x xs ih =>
rw [← ih]; simp
apply byCases_Bool_bind <;> simp
theorem eq_findSomeM_findM [Monad m] [LawfulMonad m] (p : α → m Bool) (xss : List (List α)) :
(do for xs in xss do
for x in xs do
let b ← p x
if b then
return some x
return none)
=
xss.findSomeM? (fun xs => xs.findM? p) := by
induction xss with simp [List.findSomeM?]
| cons xs xss ih =>
rw [← ih, ← eq_findM]
induction xs with simp
| cons x xs ih =>
apply byCases_Bool_bind <;> simp [ih]
theorem eq_findSomeM_findM' [Monad m] [LawfulMonad m] (p : α → m Bool) (xss : List (List α)) :
(do for xs in xss do
for x in xs do
let b ← p x
if b then
return some x
return none)
=
xss.findSomeM? (fun xs => xs.findM? p) := by
induction xss <;> simp [List.findSomeM?]
rename List α => xs
rename _ = _ => ih
rw [← ih, ← eq_findM]
induction xs <;> simp
rename _ = _ => ih
apply byCases_Bool_bind <;> simp [ih]
theorem z_add (x : Nat) : 0 + x = x := by
induction x
rfl
rename _ = _ => ih
show Nat.succ (0 + _) = _
rw [ih]
|
ad1a44a212a63a69aa4cd9b94a724e15a5b1203f | 8930e38ac0fae2e5e55c28d0577a8e44e2639a6d | /computability/turing_machine.lean | d0bc3b849ca7a9fc14dc10b6ae6d5c3d1f3095a9 | [
"Apache-2.0"
] | permissive | SG4316/mathlib | 3d64035d02a97f8556ad9ff249a81a0a51a3321a | a7846022507b531a8ab53b8af8a91953fceafd3a | refs/heads/master | 1,584,869,960,527 | 1,530,718,645,000 | 1,530,724,110,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 61,769 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Define a sequence of simple machine languages, starting with Turing
machines and working up to more complex lanaguages based on
Wang B-machines.
-/
import data.finset data.pfun logic.relation
open relation
namespace turing
/-- A direction for the turing machine `move` command, either
left or right. -/
@[derive decidable_eq]
inductive dir | left | right
def tape (Γ) := Γ × list Γ × list Γ
def tape.mk {Γ} [inhabited Γ] (l : list Γ) : tape Γ :=
(l.head, [], l.tail)
def tape.mk' {Γ} [inhabited Γ] (L R : list Γ) : tape Γ :=
(R.head, L, R.tail)
def tape.move {Γ} [inhabited Γ] : dir → tape Γ → tape Γ
| dir.left (a, L, R) := (L.head, L.tail, a :: R)
| dir.right (a, L, R) := (R.head, a :: L, R.tail)
def tape.nth {Γ} [inhabited Γ] : tape Γ → ℤ → Γ
| (a, L, R) 0 := a
| (a, L, R) (n+1:ℕ) := R.inth n
| (a, L, R) -[1+ n] := L.inth n
@[simp] theorem tape.nth_zero {Γ} [inhabited Γ] :
∀ (T : tape Γ), T.nth 0 = T.1
| (a, L, R) := rfl
@[simp] theorem tape.move_left_nth {Γ} [inhabited Γ] :
∀ (T : tape Γ) (i : ℤ), (T.move dir.left).nth i = T.nth (i-1)
| (a, L, R) -[1+ n] := by cases L; refl
| (a, L, R) 0 := by cases L; refl
| (a, L, R) 1 := rfl
| (a, L, R) ((n+1:ℕ)+1) := by rw add_sub_cancel; refl
@[simp] theorem tape.move_right_nth {Γ} [inhabited Γ] :
∀ (T : tape Γ) (i : ℤ), (T.move dir.right).nth i = T.nth (i+1)
| (a, L, R) (n+1:ℕ) := by cases R; refl
| (a, L, R) 0 := by cases R; refl
| (a, L, R) -1 := rfl
| (a, L, R) -[1+ n+1] := show _ = tape.nth _ (-[1+ n] - 1 + 1),
by rw sub_add_cancel; refl
def tape.write {Γ} (b : Γ) : tape Γ → tape Γ
| (a, LR) := (b, LR)
@[simp] theorem tape.write_self {Γ} : ∀ (T : tape Γ), T.write T.1 = T
| (a, LR) := rfl
@[simp] theorem tape.write_nth {Γ} [inhabited Γ] (b : Γ) :
∀ (T : tape Γ) {i : ℤ}, (T.write b).nth i = if i = 0 then b else T.nth i
| (a, L, R) 0 := rfl
| (a, L, R) (n+1:ℕ) := rfl
| (a, L, R) -[1+ n] := rfl
def tape.map {Γ Γ'} (f : Γ → Γ') : tape Γ → tape Γ'
| (a, L, R) := (f a, L.map f, R.map f)
@[simp] theorem tape.map_fst {Γ Γ'} (f : Γ → Γ') : ∀ (T : tape Γ), (T.map f).1 = f T.1
| (a, L, R) := rfl
@[simp] theorem tape.map_write {Γ Γ'} (f : Γ → Γ') (b : Γ) :
∀ (T : tape Γ), (T.write b).map f = (T.map f).write (f b)
| (a, L, R) := rfl
@[class] def pointed_map {Γ Γ'} [inhabited Γ] [inhabited Γ'] (f : Γ → Γ') :=
f (default _) = default _
theorem tape.map_move {Γ Γ'} [inhabited Γ] [inhabited Γ']
(f : Γ → Γ') [pointed_map f] :
∀ (T : tape Γ) d, (T.move d).map f = (T.map f).move d
| (a, [], R) dir.left := by simpa!
| (a, b::L, R) dir.left := by simp!
| (a, L, []) dir.right := by simpa!
| (a, L, b::R) dir.right := by simp!
theorem tape.map_mk {Γ Γ'} [inhabited Γ] [inhabited Γ']
(f : Γ → Γ') [f0 : pointed_map f] :
∀ (l : list Γ), (tape.mk l).map f = tape.mk (l.map f)
| [] := by simpa! [tape.mk]
| (a::l) := rfl
def eval {σ} (f : σ → option σ) : σ → roption σ :=
pfun.fix (λ s, roption.some $
match f s with none := sum.inl s | some s' := sum.inr s' end)
def reaches {σ} (f : σ → option σ) : σ → σ → Prop :=
refl_trans_gen (λ a b, b ∈ f a)
def reaches₁ {σ} (f : σ → option σ) : σ → σ → Prop :=
trans_gen (λ a b, b ∈ f a)
theorem reaches₁_eq {σ} {f : σ → option σ} {a b c}
(h : f a = f b) : reaches₁ f a c ↔ reaches₁ f b c :=
trans_gen.head'_iff.trans (trans_gen.head'_iff.trans $ by rw h).symm
theorem reaches_total {σ} {f : σ → option σ}
{a b c} : reaches f a b → reaches f a c →
reaches f b c ∨ reaches f c b :=
refl_trans_gen.total_of_right_unique $ λ _ _ _, option.mem_unique
theorem reaches₁_fwd {σ} {f : σ → option σ}
{a b c} (h₁ : reaches₁ f a c) (h₂ : b ∈ f a) : reaches f b c :=
begin
rcases trans_gen.head'_iff.1 h₁ with ⟨b', hab, hbc⟩,
cases option.mem_unique hab h₂, exact hbc
end
def reaches₀ {σ} (f : σ → option σ) (a b : σ) : Prop :=
∀ c, reaches₁ f b c → reaches₁ f a c
theorem reaches₀.trans {σ} {f : σ → option σ} {a b c : σ}
(h₁ : reaches₀ f a b) (h₂ : reaches₀ f b c) : reaches₀ f a c
| d h₃ := h₁ _ (h₂ _ h₃)
@[refl] theorem reaches₀.refl {σ} {f : σ → option σ} (a : σ) : reaches₀ f a a
| b h := h
theorem reaches₀.single {σ} {f : σ → option σ} {a b : σ}
(h : b ∈ f a) : reaches₀ f a b
| c h₂ := h₂.head h
theorem reaches₀.head {σ} {f : σ → option σ} {a b c : σ}
(h : b ∈ f a) (h₂ : reaches₀ f b c) : reaches₀ f a c :=
(reaches₀.single h).trans h₂
theorem reaches₀.tail {σ} {f : σ → option σ} {a b c : σ}
(h₁ : reaches₀ f a b) (h : c ∈ f b) : reaches₀ f a c :=
h₁.trans (reaches₀.single h)
theorem reaches₀_eq {σ} {f : σ → option σ} {a b}
(e : f a = f b) : reaches₀ f a b
| d h := (reaches₁_eq e).2 h
theorem reaches₁.to₀ {σ} {f : σ → option σ} {a b : σ}
(h : reaches₁ f a b) : reaches₀ f a b
| c h₂ := h.trans h₂
theorem reaches.to₀ {σ} {f : σ → option σ} {a b : σ}
(h : reaches f a b) : reaches₀ f a b
| c h₂ := h₂.trans_right h
theorem reaches₀.tail' {σ} {f : σ → option σ} {a b c : σ}
(h : reaches₀ f a b) (h₂ : c ∈ f b) : reaches₁ f a c :=
h _ (trans_gen.single h₂)
theorem mem_eval {σ} {f : σ → option σ} {a b} :
b ∈ eval f a ↔ reaches f a b ∧ f b = none :=
⟨λ h, begin
refine pfun.fix_induction h (λ a h IH, _),
cases e : f a with a',
{ rw roption.mem_unique h (pfun.mem_fix_iff.2 $ or.inl $
roption.mem_some_iff.2 $ by rw e; refl),
exact ⟨refl_trans_gen.refl, e⟩ },
{ rcases pfun.mem_fix_iff.1 h with h | ⟨_, h, h'⟩;
rw e at h; cases roption.mem_some_iff.1 h,
cases IH a' h' (by rwa e) with h₁ h₂,
exact ⟨refl_trans_gen.head e h₁, h₂⟩ }
end, λ ⟨h₁, h₂⟩, begin
refine refl_trans_gen.head_induction_on h₁ _ (λ a a' h _ IH, _),
{ refine pfun.mem_fix_iff.2 (or.inl _),
rw h₂, apply roption.mem_some },
{ refine pfun.mem_fix_iff.2 (or.inr ⟨_, _, IH⟩),
rw show f a = _, from h,
apply roption.mem_some }
end⟩
theorem eval_maximal₁ {σ} {f : σ → option σ} {a b}
(h : b ∈ eval f a) (c) : ¬ reaches₁ f b c | bc :=
let ⟨ab, b0⟩ := mem_eval.1 h, ⟨b', h', _⟩ := trans_gen.head'_iff.1 bc in
by cases b0.symm.trans h'
theorem eval_maximal {σ} {f : σ → option σ} {a b}
(h : b ∈ eval f a) {c} : reaches f b c ↔ c = b :=
let ⟨ab, b0⟩ := mem_eval.1 h in
refl_trans_gen_iff_eq $ λ b' h', by cases b0.symm.trans h'
theorem reaches_eval {σ} {f : σ → option σ} {a b}
(ab : reaches f a b) : eval f a = eval f b :=
roption.ext $ λ c,
⟨λ h, let ⟨ac, c0⟩ := mem_eval.1 h in
mem_eval.2 ⟨(or_iff_left_of_imp $ by exact
λ cb, (eval_maximal h).1 cb ▸ refl_trans_gen.refl).1
(reaches_total ab ac), c0⟩,
λ h, let ⟨bc, c0⟩ := mem_eval.1 h in mem_eval.2 ⟨ab.trans bc, c0⟩,⟩
def respects {σ₁ σ₂}
(f₁ : σ₁ → option σ₁) (f₂ : σ₂ → option σ₂) (tr : σ₁ → σ₂ → Prop) :=
∀ ⦃a₁ a₂⦄, tr a₁ a₂ → (match f₁ a₁ with
| some b₁ := ∃ b₂, tr b₁ b₂ ∧ reaches₁ f₂ a₂ b₂
| none := f₂ a₂ = none
end : Prop)
theorem tr_reaches₁ {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop}
(H : respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : reaches₁ f₁ a₁ b₁) :
∃ b₂, tr b₁ b₂ ∧ reaches₁ f₂ a₂ b₂ :=
begin
induction ab with c₁ ac c₁ d₁ ac cd IH,
{ have := H aa,
rwa (show f₁ a₁ = _, from ac) at this },
{ rcases IH with ⟨c₂, cc, ac₂⟩,
have := H cc,
rw (show f₁ c₁ = _, from cd) at this,
rcases this with ⟨d₂, dd, cd₂⟩,
exact ⟨_, dd, ac₂.trans cd₂⟩ }
end
theorem tr_reaches {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop}
(H : respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : reaches f₁ a₁ b₁) :
∃ b₂, tr b₁ b₂ ∧ reaches f₂ a₂ b₂ :=
begin
rcases refl_trans_gen_iff_eq_or_trans_gen.1 ab with rfl | ab,
{ exact ⟨_, aa, refl_trans_gen.refl⟩ },
{ exact let ⟨b₂, bb, h⟩ := tr_reaches₁ H aa ab in
⟨b₂, bb, h.to_refl⟩ }
end
theorem tr_reaches_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop}
(H : respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₂} (ab : reaches f₂ a₂ b₂) :
∃ c₁ c₂, reaches f₂ b₂ c₂ ∧ tr c₁ c₂ ∧ reaches f₁ a₁ c₁ :=
begin
induction ab with c₂ d₂ ac cd IH,
{ exact ⟨_, _, refl_trans_gen.refl, aa, refl_trans_gen.refl⟩ },
{ rcases IH with ⟨e₁, e₂, ce, ee, ae⟩,
rcases refl_trans_gen.cases_head ce with rfl | ⟨d', cd', de⟩,
{ have := H ee, revert this,
cases eg : f₁ e₁ with g₁; simp [respects],
{ intro c0, cases cd.symm.trans c0 },
{ intros g₂ gg cg,
rcases trans_gen.head'_iff.1 cg with ⟨d', cd', dg⟩,
cases option.mem_unique cd cd',
exact ⟨_, _, dg, gg, ae.tail eg⟩ } },
{ cases option.mem_unique cd cd',
exact ⟨_, _, de, ee, ae⟩ } }
end
theorem tr_eval {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop}
(H : respects f₁ f₂ tr) {a₁ b₁ a₂} (aa : tr a₁ a₂)
(ab : b₁ ∈ eval f₁ a₁) : ∃ b₂, tr b₁ b₂ ∧ b₂ ∈ eval f₂ a₂ :=
begin
cases mem_eval.1 ab with ab b0,
rcases tr_reaches H aa ab with ⟨b₂, bb, ab⟩,
refine ⟨_, bb, mem_eval.2 ⟨ab, _⟩⟩,
have := H bb, rwa b0 at this
end
theorem tr_eval_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop}
(H : respects f₁ f₂ tr) {a₁ b₂ a₂} (aa : tr a₁ a₂)
(ab : b₂ ∈ eval f₂ a₂) : ∃ b₁, tr b₁ b₂ ∧ b₁ ∈ eval f₁ a₁ :=
begin
cases mem_eval.1 ab with ab b0,
rcases tr_reaches_rev H aa ab with ⟨c₁, c₂, bc, cc, ac⟩,
cases (refl_trans_gen_iff_eq
(by exact option.eq_none_iff_forall_not_mem.1 b0)).1 bc,
refine ⟨_, cc, mem_eval.2 ⟨ac, _⟩⟩,
have := H cc, cases f₁ c₁ with d₁, {refl},
rcases this with ⟨d₂, dd, bd⟩,
rcases trans_gen.head'_iff.1 bd with ⟨e, h, _⟩,
cases b0.symm.trans h
end
theorem tr_eval_dom {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop}
(H : respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) :
(eval f₂ a₂).dom ↔ (eval f₁ a₁).dom :=
⟨λ h, let ⟨b₂, tr, h, _⟩ := tr_eval_rev H aa ⟨h, rfl⟩ in h,
λ h, let ⟨b₂, tr, h, _⟩ := tr_eval H aa ⟨h, rfl⟩ in h⟩
def frespects {σ₁ σ₂} (f₂ : σ₂ → option σ₂) (tr : σ₁ → σ₂) (a₂ : σ₂) : option σ₁ → Prop
| (some b₁) := reaches₁ f₂ a₂ (tr b₁)
| none := f₂ a₂ = none
theorem frespects_eq {σ₁ σ₂} {f₂ : σ₂ → option σ₂} {tr : σ₁ → σ₂} {a₂ b₂}
(h : f₂ a₂ = f₂ b₂) : ∀ {b₁}, frespects f₂ tr a₂ b₁ ↔ frespects f₂ tr b₂ b₁
| (some b₁) := reaches₁_eq h
| none := by simp [frespects, h]
theorem fun_respects {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂} :
respects f₁ f₂ (λ a b, tr a = b) ↔ ∀ ⦃a₁⦄, frespects f₂ tr (tr a₁) (f₁ a₁) :=
forall_congr $ λ a₁, by cases f₁ a₁; simp [frespects, respects]
theorem tr_eval' {σ₁ σ₂}
(f₁ : σ₁ → option σ₁) (f₂ : σ₂ → option σ₂) (tr : σ₁ → σ₂)
(H : respects f₁ f₂ (λ a b, tr a = b))
(a₁) : eval f₂ (tr a₁) = tr <$> eval f₁ a₁ :=
roption.ext $ λ b₂, by simp; exact
⟨λ h, let ⟨b₁, bb, hb⟩ :=
tr_eval_rev H rfl h in ⟨b₁, hb, bb⟩,
λ ⟨b₁, ab, bb⟩, begin
rcases tr_eval H rfl ab with ⟨_, rfl, h⟩,
rwa bb at h
end⟩
def dwrite {K} [decidable_eq K] {C : K → Type*}
(S : ∀ k, C k) (k') (l : C k') (k) : C k :=
if h : k = k' then eq.rec_on h.symm l else S k
@[simp] theorem dwrite_eq {K} [decidable_eq K] {C : K → Type*}
(S : ∀ k, C k) (k) (l : C k) : dwrite S k l k = l :=
by simp [dwrite]
@[simp] theorem dwrite_ne {K} [decidable_eq K] {C : K → Type*}
(S : ∀ k, C k) (k') (l : C k') (k) (h : ¬ k = k') : dwrite S k' l k = S k :=
by simp [dwrite, h]
@[simp] theorem dwrite_self
{K} [decidable_eq K] {C : K → Type*}
(S : ∀ k, C k) (k) : dwrite S k (S k) = S :=
funext $ λ k', by unfold dwrite; split_ifs; [subst h, refl]
namespace TM0
section
parameters (Γ : Type*) [inhabited Γ] -- type of tape symbols
parameters (Λ : Type*) [inhabited Λ] -- type of "labels" or TM states
/-- A Turing machine "statement" is just a command to either move
left or right, or write a symbol on the tape. -/
inductive stmt
| move {} : dir → stmt
| write {} : Γ → stmt
/-- A Post-Turing machine with symbol type `Γ` and label type `Λ`
is a function which, given the current state `q : Λ` and
the tape head `a : Γ`, either halts (returns `none`) or returns
a new state `q' : Λ` and a `stmt` describing what to do,
either a move left or right, or a write command.
Both `Λ` and `Γ` are required to be inhabited; the default value
for `Γ` is the "blank" tape value, and the default value of `Λ` is
the initial state. -/
def machine := Λ → Γ → option (Λ × stmt)
/-- The configuration state of a Turing machine during operation
consists of a label (machine state), and a tape, represented in
the form `(a, L, R)` meaning the tape looks like `L.rev ++ [a] ++ R`
with the machine currently reading the `a`. The lists are
automatically extended with blanks as the machine moves around. -/
structure cfg :=
(q : Λ)
(tape : tape Γ)
parameters {Γ Λ}
/-- Execution semantics of the Turing machine. -/
def step (M : machine) : cfg → option cfg
| ⟨q, T⟩ := (M q T.1).map (λ ⟨q', a⟩, ⟨q',
match a with
| stmt.move d := T.move d
| stmt.write a := T.write a
end⟩)
/-- The statement `reaches M s₁ s₂` means that `s₂` is obtained
starting from `s₁` after a finite number of steps from `s₂`. -/
def reaches (M : machine) : cfg → cfg → Prop :=
refl_trans_gen (λ a b, b ∈ step M a)
/-- The initial configuration. -/
def init (l : list Γ) : cfg :=
⟨default Λ, tape.mk l⟩
/-- Evaluate a Turing machine on initial input to a final state,
if it terminates. -/
def eval (M : machine) (l : list Γ) : roption (list Γ) :=
(eval (step M) (init l)).map (λ c, c.tape.2.2)
/-- The raw definition of a Turing machine does not require that
`Γ` and `Λ` are finite, and in practice we will be interested
in the infinite `Λ` case. We recover instead a notion of
"effectively finite" Turing machines, which only make use of a
finite subset of their states. We say that a set `S ⊆ Λ`
supports a Turing machine `M` if `S` is closed under the
transition function and contains the initial state. -/
def supports (M : machine) (S : set Λ) :=
default Λ ∈ S ∧ ∀ {q a q' s}, (q', s) ∈ M q a → q ∈ S → q' ∈ S
theorem step_supports (M : machine) {S}
(ss : supports M S) : ∀ {c c' : cfg},
c' ∈ step M c → c.q ∈ S → c'.q ∈ S
| ⟨q, T⟩ c' h₁ h₂ := begin
rcases option.map_eq_some'.1 h₁ with ⟨⟨q', a⟩, h, rfl⟩,
exact ss.2 h h₂,
end
theorem univ_supports (M : machine) : supports M set.univ :=
⟨trivial, λ q a q' s h₁ h₂, trivial⟩
end
section
variables {Γ : Type*} [inhabited Γ]
variables {Γ' : Type*} [inhabited Γ']
variables {Λ : Type*} [inhabited Λ]
variables {Λ' : Type*} [inhabited Λ']
def stmt.map (f : Γ → Γ') : stmt Γ → stmt Γ'
| (stmt.move d) := stmt.move d
| (stmt.write a) := stmt.write (f a)
def cfg.map (f : Γ → Γ') (g : Λ → Λ') : cfg Γ Λ → cfg Γ' Λ'
| ⟨q, T⟩ := ⟨g q, T.map f⟩
variables (M : machine Γ Λ)
(f₁ : Γ → Γ') (f₂ : Γ' → Γ) (g₁ : Λ → Λ') (g₂ : Λ' → Λ)
def machine.map : machine Γ' Λ'
| q l := (M (g₂ q) (f₂ l)).map (prod.map g₁ (stmt.map f₁))
theorem machine.map_step {S} (ss : supports M S)
[pointed_map f₁] (f₂₁ : function.right_inverse f₁ f₂)
(g₂₁ : ∀ q ∈ S, g₂ (g₁ q) = q) :
∀ c : cfg Γ Λ, c.q ∈ S →
(step M c).map (cfg.map f₁ g₁) =
step (M.map f₁ f₂ g₁ g₂) (cfg.map f₁ g₁ c)
| ⟨q, T⟩ h := begin
simp! [g₂₁ q h, f₂₁ _],
rcases M q T.1 with _|⟨q', d|a⟩, {refl},
{ simp! [option.map, tape.map_move f₁] },
{ simp! [option.map] }
end
theorem map_init [pointed_map f₁] [g0 : pointed_map g₁] (l : list Γ) :
(init l).map f₁ g₁ = init (l.map f₁) :=
by simp [init, cfg.map]; exact ⟨g0, tape.map_mk _ _⟩
theorem machine.map_respects {S} (ss : supports M S)
[pointed_map f₁] [pointed_map g₁]
(f₂₁ : function.right_inverse f₁ f₂)
(g₂₁ : ∀ q ∈ S, g₂ (g₁ q) = q) :
respects (step M) (step (M.map f₁ f₂ g₁ g₂))
(λ a b, a.q ∈ S ∧ cfg.map f₁ g₁ a = b)
| c _ ⟨cs, rfl⟩ := begin
cases e : step M c with c'; simp!,
{ rw [← M.map_step f₁ f₂ g₁ g₂ ss f₂₁ g₂₁ _ cs, e], refl },
{ refine ⟨_, ⟨step_supports M ss e cs, rfl⟩, trans_gen.single _⟩,
rw [← M.map_step f₁ f₂ g₁ g₂ ss f₂₁ g₂₁ _ cs, e], exact rfl }
end
end
end TM0
namespace TM1
section
parameters (Γ : Type*) [inhabited Γ] -- Type of tape symbols
parameters (Λ : Type*) -- Type of function labels
parameters (σ : Type*) -- Type of variable settings
/-- The TM1 model is a simplification and extension of TM0
(Post-Turing model) in the direction of Wang B-machines. The machine's
internal state is extended with a (finite) store `σ` of variables
that may be accessed and updated at any time.
A machine is given by a `Λ` indexed set of procedures or functions.
Each function has a body which is a `stmt`, which can either be a
`move` or `write` command, a `branch` (if statement based on the
current tape value), a `load` (set the variable value),
a `goto` (call another function), or `halt`. Note that here
most statements do not have labels; `goto` commands can only
go to a new function. All commands have access to the variable value
and current tape value. -/
inductive stmt
| move : dir → stmt → stmt
| write : (Γ → σ → Γ) → stmt → stmt
| load : (Γ → σ → σ) → stmt → stmt
| branch : (Γ → σ → bool) → stmt → stmt → stmt
| goto {} : (Γ → σ → Λ) → stmt
| halt {} : stmt
open stmt
/-- The configuration of a TM1 machine is given by the currently
evaluating statement, the variable store value, and the tape. -/
structure cfg :=
(l : option Λ)
(var : σ)
(tape : tape Γ)
parameters {Γ Λ σ}
/-- The semantics of TM1 evaluation. -/
def step_aux : stmt → σ → tape Γ → cfg
| (move d q) v T := step_aux q v (T.move d)
| (write a q) v T := step_aux q v (T.write (a T.1 v))
| (load s q) v T := step_aux q (s T.1 v) T
| (branch p q₁ q₂) v T :=
cond (p T.1 v) (step_aux q₁ v T) (step_aux q₂ v T)
| (goto l) v T := ⟨some (l T.1 v), v, T⟩
| halt v T := ⟨none, v, T⟩
def step (M : Λ → stmt) : cfg → option cfg
| ⟨none, v, T⟩ := none
| ⟨some l, v, T⟩ := some (step_aux (M l) v T)
variables [inhabited Λ] [inhabited σ]
def init (l : list Γ) : cfg :=
⟨some (default _), default _, tape.mk l⟩
def eval (M : Λ → stmt) (l : list Γ) : roption (list Γ) :=
(eval (step M) (init l)).map (λ c, c.tape.2.2)
variables [fintype Γ]
def supports_stmt (S : finset Λ) : stmt → Prop
| (move d q) := supports_stmt q
| (write a q) := supports_stmt q
| (load s q) := supports_stmt q
| (branch p q₁ q₂) := supports_stmt q₁ ∧ supports_stmt q₂
| (goto l) := ∀ a v, l a v ∈ S
| halt := true
/-- A set `S` of labels supports machine `M` if all the `goto`
statements in the functions in `S` refer only to other functions
in `S`. -/
def supports (M : Λ → stmt) (S : finset Λ) :=
default Λ ∈ S ∧ ∀ q ∈ S, supports_stmt S (M q)
local attribute [instance] classical.dec
noncomputable def stmts₁ : stmt → finset stmt
| Q@(move d q) := insert Q (stmts₁ q)
| Q@(write a q) := insert Q (stmts₁ q)
| Q@(load s q) := insert Q (stmts₁ q)
| Q@(branch p q₁ q₂) := insert Q (stmts₁ q₁ ∪ stmts₁ q₂)
| Q := {Q}
theorem stmts₁_self {q} : q ∈ stmts₁ q :=
by cases q; simp [stmts₁]
theorem stmts₁_trans {q₁ q₂} :
q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ :=
begin
intros h₁₂ q₀ h₀₁,
induction q₂ with _ q IH _ q IH _ q IH;
simp [stmts₁, finset.subset_iff] at h₁₂ ⊢,
iterate 3 {
rcases h₁₂ with rfl | h₁₂,
{ simp [stmts₁] at h₀₁, rcases h₀₁ with rfl | h; simp * },
{ exact or.inr (IH h₁₂) } },
case TM1.stmt.branch : p q₁ q₂ IH₁ IH₂ {
rcases h₁₂ with rfl | h₁₂ | h₁₂,
{ simp [stmts₁] at h₀₁, rcases h₀₁ with rfl | h; simp * },
{ simp [IH₁ h₁₂] }, { simp [IH₂ h₁₂] } },
case TM1.stmt.goto : l {
subst h₁₂, simpa [stmts₁] using h₀₁ },
case TM1.stmt.halt {
subst h₁₂, simpa [stmts₁] using h₀₁ }
end
theorem stmts₁_supports_stmt_mono {S q₁ q₂}
(h : q₁ ∈ stmts₁ q₂) (hs : supports_stmt S q₂) : supports_stmt S q₁ :=
begin
induction q₂ with _ q IH _ q IH _ q IH;
simp [stmts₁, supports_stmt] at h hs,
iterate 3 { rcases h with rfl | h; [exact hs, exact IH h hs] },
case TM1.stmt.branch : p q₁ q₂ IH₁ IH₂ {
rcases h with rfl | h | h, exacts [hs, IH₁ h hs.1, IH₂ h hs.2] },
case TM1.stmt.goto : l { subst h, exact hs },
case TM1.stmt.halt { subst h, trivial }
end
noncomputable def stmts
(M : Λ → stmt) (S : finset Λ) : finset (option stmt) :=
(S.bind (λ q, stmts₁ (M q))).insert_none
theorem stmts_trans {M : Λ → stmt} {S q₁ q₂}
(h₁ : q₁ ∈ stmts₁ q₂) : some q₂ ∈ stmts M S → some q₁ ∈ stmts M S :=
by simp [stmts]; exact λ l ls h₂, ⟨_, ls, stmts₁_trans h₂ h₁⟩
theorem stmts_supports_stmt {M : Λ → stmt} {S q}
(ss : supports M S) : some q ∈ stmts M S → supports_stmt S q :=
by simp [stmts]; exact
λ l ls h, stmts₁_supports_stmt_mono h (ss.2 _ ls)
local attribute [-simp] finset.mem_insert_none
theorem step_supports (M : Λ → stmt) {S}
(ss : supports M S) : ∀ {c c' : cfg},
c' ∈ step M c → c.l ∈ S.insert_none → c'.l ∈ S.insert_none
| ⟨some l₁, v, T⟩ c' h₁ h₂ := begin
replace h₂ := ss.2 _ (finset.some_mem_insert_none.1 h₂),
simp [step] at h₁, subst c',
revert h₂, induction M l₁ with _ q IH _ q IH _ q IH generalizing v T;
intro hs,
iterate 3 { exact IH _ _ hs },
case TM1.stmt.branch : p q₁' q₂' IH₁ IH₂ {
simp [step_aux], cases p T.1 v,
{ exact IH₂ _ _ hs.2 },
{ exact IH₁ _ _ hs.1 } },
case TM1.stmt.goto { exact finset.some_mem_insert_none.2 (hs _ _) },
case TM1.stmt.halt { apply multiset.mem_cons_self }
end
end
end TM1
namespace TM1to0
section
parameters {Γ : Type*} [inhabited Γ]
parameters {Λ : Type*} [inhabited Λ]
parameters {σ : Type*} [inhabited σ]
local notation `stmt₁` := TM1.stmt Γ Λ σ
local notation `cfg₁` := TM1.cfg Γ Λ σ
local notation `stmt₀` := TM0.stmt Γ
parameters (M : Λ → stmt₁)
include M
def Λ' := option stmt₁ × σ
instance : inhabited Λ' := ⟨(some (M (default _)), default _)⟩
open TM0.stmt
def tr_aux (s : Γ) : stmt₁ → σ → Λ' × stmt₀
| (TM1.stmt.move d q) v := ((some q, v), move d)
| (TM1.stmt.write a q) v := ((some q, v), write (a s v))
| (TM1.stmt.load a q) v := tr_aux q (a s v)
| (TM1.stmt.branch p q₁ q₂) v := cond (p s v) (tr_aux q₁ v) (tr_aux q₂ v)
| (TM1.stmt.goto l) v := ((some (M (l s v)), v), write s)
| TM1.stmt.halt v := ((none, v), write s)
local notation `cfg₀` := TM0.cfg Γ Λ'
def tr : TM0.machine Γ Λ'
| (none, v) s := none
| (some q, v) s := some (tr_aux s q v)
def tr_cfg : cfg₁ → cfg₀
| ⟨l, v, T⟩ := ⟨(l.map M, v), T⟩
theorem tr_respects : respects (TM1.step M) (TM0.step tr)
(λ c₁ c₂, tr_cfg c₁ = c₂) :=
fun_respects.2 $ λ ⟨l₁, v, T⟩, begin
cases l₁ with l₁, {exact rfl},
simp! [option.map],
induction M l₁ with _ q IH _ q IH _ q IH generalizing v T,
case TM1.stmt.move : d q IH { exact trans_gen.head rfl (IH _ _) },
case TM1.stmt.write : a q IH { exact trans_gen.head rfl (IH _ _) },
case TM1.stmt.load : a q IH { exact (reaches₁_eq (by refl)).2 (IH _ _) },
case TM1.stmt.branch : p q₁ q₂ IH₁ IH₂ {
simp [TM1.step_aux], cases e : p T.1 v,
{ exact (reaches₁_eq (by simp! [e])).2 (IH₂ _ _) },
{ exact (reaches₁_eq (by simp! [e])).2 (IH₁ _ _) } },
case TM1.stmt.goto : l { apply trans_gen.single, simp!, refl },
case TM1.stmt.halt { apply trans_gen.single, simp!, refl }
end
variables [fintype Γ] [fintype σ]
noncomputable def tr_stmts (S : finset Λ) : finset Λ' :=
(TM1.stmts M S).product finset.univ
local attribute [instance] classical.dec
local attribute [simp] TM1.stmts₁_self
theorem tr_supports {S : finset Λ} (ss : TM1.supports M S) :
TM0.supports tr (↑(tr_stmts S)) :=
⟨by simp [tr_stmts]; exact finset.some_mem_insert_none.2
(finset.mem_bind.2 ⟨_, ss.1, TM1.stmts₁_self⟩),
λ q a q' s h₁ h₂, begin
rcases q with ⟨_|q, v⟩, {cases h₁},
cases q' with q' v', simp [tr_stmts] at h₂ ⊢,
cases q', {simp [TM1.stmts]},
simp [tr] at h₁,
have := TM1.stmts_supports_stmt ss h₂,
revert this, induction q generalizing v; intro hs,
case TM1.stmt.move : d q {
cases h₁, refine TM1.stmts_trans _ h₂, simp [TM1.stmts₁] },
case TM1.stmt.write : b q {
cases h₁, refine TM1.stmts_trans _ h₂, simp [TM1.stmts₁] },
case TM1.stmt.load : b q IH {
refine IH (TM1.stmts_trans _ h₂) _ h₁ hs, simp [TM1.stmts₁] },
case TM1.stmt.branch : p q₁ q₂ IH₁ IH₂ {
simp! at h₁, cases p a v,
{ refine IH₂ (TM1.stmts_trans _ h₂) _ h₁ hs.2, simp [TM1.stmts₁] },
{ refine IH₁ (TM1.stmts_trans _ h₂) _ h₁ hs.1, simp [TM1.stmts₁] } },
case TM1.stmt.goto : l {
cases h₁, exact finset.some_mem_insert_none.2
(finset.mem_bind.2 ⟨_, hs _ _, TM1.stmts₁_self⟩) },
case TM1.stmt.halt { cases h₁ }
end⟩
theorem tr_eval (l : list Γ) : TM0.eval tr l = TM1.eval M l :=
(congr_arg _ (tr_eval' _ _ _ tr_respects ⟨some _, _, _⟩)).trans begin
simp [tr_cfg],
rw [roption.map_map, TM1.eval],
congr', exact funext (λ ⟨_, _, _⟩, rfl)
end
end
end TM1to0
/- Reduce an n-symbol Turing machine to a 2-symbol Turing machine -/
namespace TM1to1
open TM1
section
parameters {Γ : Type*} [inhabited Γ]
theorem exists_enc_dec [fintype Γ] :
∃ n (enc : Γ → vector bool n) (dec : vector bool n → Γ),
enc (default _) = vector.repeat ff n ∧ ∀ a, dec (enc a) = a :=
begin
rcases fintype.exists_equiv_fin Γ with ⟨n, ⟨F⟩⟩,
let G : fin n ↪ fin n → bool := ⟨λ a b, a = b,
λ a b h, by simpa using congr_fun h b⟩,
let H := (F.to_embedding.trans G).trans
(equiv.vector_equiv_fin _ _).symm.to_embedding,
let enc := H.set_value (default _) (vector.repeat ff n),
exact ⟨_, enc, function.inv_fun enc,
H.set_value_eq _ _, function.left_inverse_inv_fun enc.2⟩
end
parameters {Λ : Type*} [inhabited Λ]
parameters {σ : Type*} [inhabited σ]
local notation `stmt₁` := stmt Γ Λ σ
local notation `cfg₁` := cfg Γ Λ σ
inductive Λ' : Type (max u_1 u_2 u_3)
| normal : Λ → Λ'
| write : Γ → stmt₁ → Λ'
instance : inhabited Λ' := ⟨Λ'.normal (default _)⟩
local notation `stmt'` := stmt bool Λ' σ
local notation `cfg'` := cfg bool Λ' σ
def read_aux : ∀ n, (vector bool n → stmt') → stmt'
| 0 f := f vector.nil
| (i+1) f := stmt.branch (λ a s, a)
(stmt.move dir.right $ read_aux i (λ v, f (tt :: v)))
(stmt.move dir.right $ read_aux i (λ v, f (ff :: v)))
parameters {n : ℕ} (enc : Γ → vector bool n) (dec : vector bool n → Γ)
def move (d : dir) (q : stmt') : stmt' := (stmt.move d)^[n] q
def read (f : Γ → stmt') : stmt' :=
read_aux n (λ v, move dir.left $ f (dec v))
def write : list bool → stmt' → stmt'
| [] q := q
| (a :: l) q := stmt.write (λ _ _, a) $ stmt.move dir.right $ write l q
def tr_normal : stmt₁ → stmt'
| (stmt.move dir.left q) := move dir.right $ (move dir.left)^[2] $ tr_normal q
| (stmt.move dir.right q) := move dir.right $ tr_normal q
| (stmt.write f q) := read $ λ a, stmt.goto $ λ _ s, Λ'.write (f a s) q
| (stmt.load f q) := read $ λ a, stmt.load (λ _ s, f a s) $ tr_normal q
| (stmt.branch p q₁ q₂) := read $ λ a,
stmt.branch (λ _ s, p a s) (tr_normal q₁) (tr_normal q₂)
| (stmt.goto l) := read $ λ a,
stmt.goto (λ _ s, Λ'.normal (l a s))
| stmt.halt := move dir.right $ move dir.left $ stmt.halt
def tr_tape' (L R : list Γ) : tape bool :=
tape.mk'
(L.bind (λ x, (enc x).to_list.reverse))
(R.bind (λ x, (enc x).to_list) ++ [default _])
def tr_tape : tape Γ → tape bool
| (a, L, R) := tr_tape' L (a :: R)
theorem tr_tape_drop_right : ∀ R : list Γ,
list.drop n (R.bind (λ x, (enc x).to_list)) =
R.tail.bind (λ x, (enc x).to_list)
| [] := list.drop_nil _
| (a::R) := by simp; exact list.drop_left' (enc a).2
parameters (enc0 : enc (default _) = vector.repeat ff n)
section
include enc0
theorem tr_tape_take_right : ∀ R : list Γ,
list.take' n (R.bind (λ x, (enc x).to_list)) =
(enc R.head).to_list
| [] := by simp; exact (congr_arg vector.to_list enc0).symm
| (a::R) := by simp; exact list.take'_left' (enc a).2
end
parameters (M : Λ → stmt₁)
def tr : Λ' → stmt'
| (Λ'.normal l) := tr_normal (M l)
| (Λ'.write a q) := write (enc a).to_list $ move dir.left $ tr_normal q
def tr_cfg : cfg₁ → cfg'
| ⟨l, v, T⟩ := ⟨l.map Λ'.normal, v, tr_tape T⟩
include enc0
theorem tr_tape'_move_left (L R) :
(tape.move dir.left)^[n] (tr_tape' L R) =
(tr_tape' L.tail (L.head :: R)) :=
begin
cases L with a L,
{ simp [enc0, vector.repeat, tr_tape'],
suffices : ∀ i R', default _ ∈ R' →
(tape.move dir.left^[i]) (tape.mk' [] R') =
tape.mk' [] (list.repeat ff i ++ R'),
from this n _ (by simp),
intros i R' hR, induction i with i IH, {refl},
rw [nat.iterate_succ', IH],
simp [tape.mk', tape.move],
exact list.cons_head_tail
(list.ne_nil_of_mem $ list.mem_append_right _ hR) },
{ simp [tr_tape'],
suffices : ∀ L' R' l₁ l₂
(hR : default _ ∈ R')
(e : vector.to_list (enc a) = list.reverse_core l₁ l₂),
(tape.move dir.left^[l₁.length]) (tape.mk' (l₁ ++ L') (l₂ ++ R')) =
tape.mk' L' (vector.to_list (enc a) ++ R'),
{ simpa using this _ _ _ _ _ (list.reverse_reverse _).symm,
simp },
intros, induction l₁ with b l₁ IH generalizing l₂,
{ cases e, refl },
simp [nat.iterate_succ, -add_comm],
convert IH _ e,
simp [tape.move, tape.mk'],
exact list.cons_head_tail
(list.ne_nil_of_mem $ list.mem_append_right _ hR) }
end
theorem tr_tape'_move_right (L R) :
(tape.move dir.right)^[n] (tr_tape' L R) =
(tr_tape' (R.head :: L) R.tail) :=
begin
cases R with a R,
{ simp [enc0, vector.repeat, tr_tape'],
suffices : ∀ i L',
(tape.move dir.right^[i]) (ff, L', []) =
(ff, list.repeat ff i ++ L', []),
from this n _,
intros, induction i;
simp [nat.iterate_succ', tape.move, *]; refl },
{ simp [tr_tape'],
suffices : ∀ L' R' l₁ l₂ : list bool,
(tape.move dir.right^[l₂.length]) (tape.mk' (l₁ ++ L') (l₂ ++ R')) =
tape.mk' (list.reverse_core l₂ l₁ ++ L') R',
{ simpa using this _ _ [] (enc a).to_list },
intros, induction l₂ with b l₂ IH generalizing l₁, {refl},
simp [-add_comm, nat.iterate_succ],
exact IH (b::l₁) }
end
theorem step_aux_move (d q v T) :
step_aux (move d q) v T =
step_aux q v ((tape.move d)^[n] T) :=
begin
simp [move],
suffices : ∀ i,
step_aux (stmt.move d^[i] q) v T =
step_aux q v (tape.move d^[i] T), from this n,
intro, induction i with i IH generalizing T, {refl},
rw [nat.iterate_succ', step_aux, IH, ← nat.iterate_succ]
end
parameters (encdec : ∀ a, dec (enc a) = a)
include encdec
theorem step_aux_read (f v L R) :
step_aux (read f) v (tr_tape' L R) =
step_aux (f R.head) v (tr_tape' L (R.head :: R.tail)) :=
begin
suffices : ∀ f,
step_aux (read_aux n f) v (tr_tape' enc L R) =
step_aux (f (enc R.head)) v
(tr_tape' enc (R.head :: L) R.tail),
{ rw [read, this, step_aux_move enc enc0, encdec,
tr_tape'_move_left enc enc0], refl },
cases R with a R,
{ suffices : ∀ i f L',
step_aux (read_aux i f) v (ff, L', []) =
step_aux (f (vector.repeat ff i)) v
(ff, list.repeat ff i ++ L', []),
{ intro f, convert this n f _,
simp [tr_tape', tape.mk', enc0, vector.repeat] },
clear f L, intros, induction i with i IH generalizing L', {refl},
simp [read_aux, step_aux, tape.mk', tape.move],
rw [IH], congr',
simpa using congr_arg (++ L') (list.repeat_add ff i 1).symm },
{ simp [tr_tape'],
suffices : ∀ i f L' R' l₁ l₂ h,
step_aux (read_aux i f) v
(tape.mk' (l₁ ++ L') (l₂ ++ R')) =
step_aux (f ⟨l₂, h⟩) v
(tape.mk' (l₂.reverse_core l₁ ++ L') R'),
{ intro f, convert this n f _ _ _ _ (enc a).2; simp },
clear f L a R, intros, subst i,
induction l₂ with a l₂ IH generalizing l₁, {refl},
dsimp [read_aux, step_aux],
change (tape.mk' (l₁ ++ L') (a :: (l₂ ++ R'))).1 with a,
transitivity step_aux
(read_aux l₂.length (λ v, f (a :: v))) v
(tape.mk' (a :: l₁ ++ L') (l₂ ++ R')),
{ cases a; refl },
rw IH, refl }
end
theorem step_aux_write (q v a b L R) :
step_aux (write (enc a).to_list q) v (tr_tape' L (b :: R)) =
step_aux q v (tr_tape' (a :: L) R) :=
begin
simp [tr_tape'],
suffices : ∀ {L' R'} (l₁ l₂ l₂' : list bool)
(e : l₂'.length = l₂.length),
step_aux (write l₂ q) v (tape.mk' (l₁ ++ L') (l₂' ++ R')) =
step_aux q v (tape.mk' (list.reverse_core l₂ l₁ ++ L') R'),
from this [] _ _ ((enc b).2.trans (enc a).2.symm),
clear a b L R, intros,
induction l₂ with a l₂ IH generalizing l₁ l₂',
{ cases list.length_eq_zero.1 e, refl },
cases l₂' with b l₂'; injection e with e,
simp [write, step_aux],
convert IH _ _ e, refl
end
theorem tr_respects : respects (step M) (step tr)
(λ c₁ c₂, tr_cfg c₁ = c₂) :=
fun_respects.2 $ λ ⟨l₁, v, (a, L, R)⟩, begin
cases l₁ with l₁, {exact rfl},
suffices : ∀ q R, reaches (step (tr enc dec M))
(step_aux (tr_normal dec q) v (tr_tape' enc L R))
(tr_cfg enc (step_aux q v (tape.mk' L R))),
{ refine trans_gen.head' rfl (this _ (a::R)) },
clear R l₁, intros,
induction q with _ q IH _ q IH _ q IH generalizing v L R,
case TM1.stmt.move : d q IH {
cases d; simp [tr_normal, step_aux_move enc enc0, step_aux,
tr_tape'_move_left enc enc0, tr_tape'_move_right enc enc0];
apply IH },
case TM1.stmt.write : a q IH {
simp [tr_normal, step_aux_read enc dec enc0 encdec, step_aux],
refine refl_trans_gen.head rfl _,
simp [tr, tr_normal, step_aux,
step_aux_write enc dec enc0 encdec,
step_aux_move enc enc0, tr_tape'_move_left enc enc0],
apply IH },
case TM1.stmt.load : a q IH {
simp [tr_normal, step_aux_read enc dec enc0 encdec],
apply IH },
case TM1.stmt.branch : p q₁ q₂ IH₁ IH₂ {
simp [tr_normal, step_aux_read enc dec enc0 encdec, step_aux],
change (tape.mk' L R).1 with R.head,
cases p R.head v; [apply IH₂, apply IH₁] },
case TM1.stmt.goto : l {
simp [tr_normal, step_aux_read enc dec enc0 encdec, step_aux],
apply refl_trans_gen.refl },
case TM1.stmt.halt {
simp [tr_normal, step_aux, tr_cfg, step_aux_move enc enc0,
tr_tape'_move_left enc enc0, tr_tape'_move_right enc enc0],
apply refl_trans_gen.refl }
end
omit enc0 encdec
local attribute [instance] classical.dec
parameters [fintype Γ]
noncomputable def writes : stmt₁ → finset Λ'
| (stmt.move d q) := writes q
| (stmt.write f q) := finset.univ.image (λ a, Λ'.write a q) ∪ writes q
| (stmt.load f q) := writes q
| (stmt.branch p q₁ q₂) := writes q₁ ∪ writes q₂
| (stmt.goto l) := ∅
| stmt.halt := ∅
noncomputable def tr_supp (S : finset Λ) : finset Λ' :=
S.bind (λ l, insert (Λ'.normal l) (writes (M l)))
theorem supports_stmt_move {S d q} :
supports_stmt S (move d q) = supports_stmt S q :=
suffices ∀ {i}, supports_stmt S (stmt.move d^[i] q) = _, from this,
by intro; induction i generalizing q; simp [*, supports_stmt]
theorem supports_stmt_write {S l q} :
supports_stmt S (write l q) = supports_stmt S q :=
by induction l with a l IH; simp [write, supports_stmt, *]
local attribute [simp] supports_stmt_move supports_stmt_write
theorem supports_stmt_read {S} : ∀ {f : Γ → stmt'},
(∀ a, supports_stmt S (f a)) → supports_stmt S (read f) :=
suffices ∀ i (f : vector bool i → stmt'),
(∀ v, supports_stmt S (f v)) → supports_stmt S (read_aux i f),
from λ f hf, this n _ (by simp [hf]),
λ i f hf, begin
induction i with i IH, {exact hf _},
split; simp [supports_stmt]; apply IH; simp [hf],
end
theorem tr_supports {S} (ss : supports M S) :
supports tr (tr_supp S) :=
⟨by simp [tr_supp]; exact ⟨_, ss.1, or.inl rfl⟩, λ q h, begin
simp [tr_supp] at h,
suffices : ∀ q, supports_stmt S q →
(∀ q' ∈ writes q, q' ∈ tr_supp M S) →
supports_stmt (tr_supp M S) (tr_normal dec q) ∧
∀ q' ∈ writes q, supports_stmt (tr_supp M S) (tr enc dec M q'),
{ rcases h with ⟨l, hl, h⟩,
have := this _ (ss.2 _ hl) (λ q' hq,
by simp [tr_supp]; exact ⟨_, hl, or.inr hq⟩),
rcases h with rfl | h,
exacts [this.1, this.2 _ h] },
intros q hs hw, induction q,
case TM1.stmt.move : d q IH {
dsimp [writes] at hw ⊢,
replace IH := IH hs hw, refine ⟨_, IH.2⟩,
cases d; simp [tr_normal, IH] },
case TM1.stmt.write : f q IH {
simp [writes] at hw ⊢,
replace IH := IH hs (λ q hq, hw q (or.inl hq)),
refine ⟨supports_stmt_read _ $ λ a _ s,
hw _ (or.inr ⟨_, rfl⟩), λ q' hq, _⟩,
rcases hq with hq | ⟨a, q₂, rfl⟩,
{ exact IH.2 _ hq }, { simp [tr, IH.1] } },
case TM1.stmt.load : a q IH {
dsimp [writes] at hw ⊢,
replace IH := IH hs hw,
refine ⟨supports_stmt_read _ (λ a, _), IH.2⟩,
simp [tr_normal, supports_stmt, IH.1] },
case TM1.stmt.branch : p q₁ q₂ IH₁ IH₂ {
simp [writes] at hw ⊢,
replace IH₁ := IH₁ hs.1 (λ q hq, hw q (or.inl hq)),
replace IH₂ := IH₂ hs.2 (λ q hq, hw q (or.inr hq)),
exact ⟨supports_stmt_read _ (λ a, ⟨IH₁.1, IH₂.1⟩),
λ q, or.rec (IH₁.2 _) (IH₂.2 _)⟩ },
case TM1.stmt.goto : l {
simp [writes],
refine supports_stmt_read _ (λ a _ s, _),
simp [tr_supp], exact ⟨_, hs _ _, or.inl rfl⟩ },
case TM1.stmt.halt {
simp [supports_stmt, writes, tr_normal] }
end⟩
end
end TM1to1
namespace TM0to1
section
parameters {Γ : Type*} [inhabited Γ]
parameters {Λ : Type*} [inhabited Λ]
inductive Λ'
| normal : Λ → Λ'
| act : TM0.stmt Γ → Λ → Λ'
instance : inhabited Λ' := ⟨Λ'.normal (default _)⟩
local notation `cfg₀` := TM0.cfg Γ Λ
local notation `stmt₁` := TM1.stmt Γ Λ' unit
local notation `cfg₁` := TM1.cfg Γ Λ' unit
parameters (M : TM0.machine Γ Λ)
open TM1.stmt
def tr : Λ' → stmt₁
| (Λ'.normal q) :=
branch (λ a _, (M q a).is_none) halt $
goto (λ a _, match M q a with
| none := default _
| some (q', s) := Λ'.act s q'
end)
| (Λ'.act (TM0.stmt.move d) q) :=
move d $ goto (λ _ _, Λ'.normal q)
| (Λ'.act (TM0.stmt.write a) q) :=
write (λ _ _, a) $ goto (λ _ _, Λ'.normal q)
def tr_cfg : cfg₀ → cfg₁
| ⟨q, T⟩ := ⟨cond (M q T.1).is_some
(some (Λ'.normal q)) none, (), T⟩
theorem tr_respects : respects (TM0.step M) (TM1.step tr)
(λ a b, tr_cfg a = b) :=
fun_respects.2 $ λ ⟨q, T⟩, begin
simp [TM0.step],
cases e : M q T.1,
{ simp [frespects, TM1.step, tr_cfg, e] },
cases val with q' s,
simp [frespects, TM0.step, tr_cfg, e],
have : TM1.step (tr M) ⟨some (Λ'.act s q'), (), T⟩ =
some ⟨some (Λ'.normal q'), (), TM0.step._match_1 T s⟩,
{ cases s with d a; refl },
refine trans_gen.head _ (trans_gen.head' this _);
simp [TM1.step, TM1.step_aux, tr, e, TM0.step],
cases e' : M q' (TM0.step._match_1 T s).1,
{ apply refl_trans_gen.single,
simp [TM1.step, e', tr, TM1.step_aux] },
{ refl }
end
end
end TM0to1
namespace TM2
section
parameters {K : Type*} [decidable_eq K] -- Index type of stacks
parameters (Γ : K → Type*) -- Type of stack elements
parameters (Λ : Type*) -- Type of function labels
parameters (σ : Type*) -- Type of variable settings
/-- The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. -/
inductive stmt
| push {} : ∀ k, (σ → Γ k) → stmt → stmt
| peek {} : ∀ k, (σ → option (Γ k) → σ) → stmt → stmt
| pop {} : ∀ k, (σ → option (Γ k) → σ) → stmt → stmt
| load : (σ → σ) → stmt → stmt
| branch : (σ → bool) → stmt → stmt → stmt
| goto {} : (σ → Λ) → stmt
| halt {} : stmt
open stmt
structure cfg :=
(l : option Λ)
(var : σ)
(stk : ∀ k, list (Γ k))
parameters {Γ Λ σ K}
def step_aux : stmt → σ → (∀ k, list (Γ k)) → cfg
| (push k f q) v S := step_aux q v (dwrite S k (f v :: S k))
| (peek k f q) v S := step_aux q (f v (S k).head') S
| (pop k f q) v S := step_aux q (f v (S k).head') (dwrite S k (S k).tail)
| (load a q) v S := step_aux q (a v) S
| (branch f q₁ q₂) v S :=
cond (f v) (step_aux q₁ v S) (step_aux q₂ v S)
| (goto f) v S := ⟨some (f v), v, S⟩
| halt v S := ⟨none, v, S⟩
def step (M : Λ → stmt) : cfg → option cfg
| ⟨none, v, S⟩ := none
| ⟨some l, v, S⟩ := some (step_aux (M l) v S)
def reaches (M : Λ → stmt) : cfg → cfg → Prop :=
refl_trans_gen (λ a b, b ∈ step M a)
variables [inhabited Λ] [inhabited σ]
def init (k) (L : list (Γ k)) : cfg :=
⟨some (default _), default _, dwrite (λ _, []) k L⟩
def eval (M : Λ → stmt) (k) (L : list (Γ k)) : roption (list (Γ k)) :=
(eval (step M) (init k L)).map $ λ c, c.stk k
variables [fintype K] [∀ k, fintype (Γ k)] [fintype σ]
def supports_stmt (S : finset Λ) : stmt → Prop
| (push k f q) := supports_stmt q
| (peek k f q) := supports_stmt q
| (pop k f q) := supports_stmt q
| (load a q) := supports_stmt q
| (branch f q₁ q₂) := supports_stmt q₁ ∧ supports_stmt q₂
| (goto l) := ∀ v, l v ∈ S
| halt := true
def supports (M : Λ → stmt) (S : finset Λ) :=
default Λ ∈ S ∧ ∀ q ∈ S, supports_stmt S (M q)
local attribute [instance] classical.dec
noncomputable def stmts₁ : stmt → finset stmt
| Q@(push k f q) := insert Q (stmts₁ q)
| Q@(peek k f q) := insert Q (stmts₁ q)
| Q@(pop k f q) := insert Q (stmts₁ q)
| Q@(load a q) := insert Q (stmts₁ q)
| Q@(branch f q₁ q₂) := insert Q (stmts₁ q₁ ∪ stmts₁ q₂)
| Q@(goto l) := {Q}
| Q@halt := {Q}
theorem stmts₁_self {q} : q ∈ stmts₁ q :=
by cases q; simp [stmts₁]
theorem stmts₁_trans {q₁ q₂} :
q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ :=
begin
intros h₁₂ q₀ h₀₁,
induction q₂ with _ _ q IH _ _ q IH _ _ q IH _ q IH;
simp [stmts₁, finset.subset_iff] at h₁₂ ⊢,
iterate 4 {
rcases h₁₂ with rfl | h₁₂,
{ simp [stmts₁] at h₀₁, rcases h₀₁ with rfl | h; simp * },
{ exact or.inr (IH h₁₂) } },
case TM2.stmt.branch : f q₁ q₂ IH₁ IH₂ {
rcases h₁₂ with rfl | h₁₂ | h₁₂,
{ simp [stmts₁] at h₀₁, rcases h₀₁ with rfl | h; simp * },
{ simp [IH₁ h₁₂] }, { simp [IH₂ h₁₂] } },
case TM2.stmt.goto : l {
subst h₁₂, simpa [stmts₁] using h₀₁ },
case TM2.stmt.halt {
subst h₁₂, simpa [stmts₁] using h₀₁ }
end
theorem stmts₁_supports_stmt_mono {S q₁ q₂}
(h : q₁ ∈ stmts₁ q₂) (hs : supports_stmt S q₂) : supports_stmt S q₁ :=
begin
induction q₂ with _ _ q IH _ _ q IH _ _ q IH _ q IH;
simp [stmts₁, supports_stmt] at h hs,
iterate 4 { rcases h with rfl | h; [exact hs, exact IH h hs] },
case TM2.stmt.branch : f q₁ q₂ IH₁ IH₂ {
rcases h with rfl | h | h, exacts [hs, IH₁ h hs.1, IH₂ h hs.2] },
case TM2.stmt.goto : l { subst h, exact hs },
case TM2.stmt.halt { subst h, trivial }
end
noncomputable def stmts
(M : Λ → stmt) (S : finset Λ) : finset (option stmt) :=
(S.bind (λ q, stmts₁ (M q))).insert_none
theorem stmts_trans {M : Λ → stmt} {S q₁ q₂}
(h₁ : q₁ ∈ stmts₁ q₂) : some q₂ ∈ stmts M S → some q₁ ∈ stmts M S :=
by simp [stmts]; exact λ l ls h₂, ⟨_, ls, stmts₁_trans h₂ h₁⟩
theorem stmts_supports_stmt {M : Λ → stmt} {S q}
(ss : supports M S) : some q ∈ stmts M S → supports_stmt S q :=
by simp [stmts]; exact
λ l ls h, stmts₁_supports_stmt_mono h (ss.2 _ ls)
local attribute [-simp] finset.mem_insert_none
theorem step_supports (M : Λ → stmt) {S}
(ss : supports M S) : ∀ {c c' : cfg},
c' ∈ step M c → c.l ∈ S.insert_none → c'.l ∈ S.insert_none
| ⟨some l₁, v, T⟩ c' h₁ h₂ := begin
replace h₂ := ss.2 _ (finset.some_mem_insert_none.1 h₂),
simp [step] at h₁, subst c',
revert h₂, induction M l₁ with _ _ q IH _ _ q IH _ _ q IH _ q IH generalizing v T;
intro hs,
iterate 4 { exact IH _ _ hs },
case TM2.stmt.branch : p q₁' q₂' IH₁ IH₂ {
simp [step_aux], cases p v,
{ exact IH₂ _ _ hs.2 },
{ exact IH₁ _ _ hs.1 } },
case TM2.stmt.goto { exact finset.some_mem_insert_none.2 (hs _) },
case TM2.stmt.halt { apply multiset.mem_cons_self }
end
end
end TM2
namespace TM2to1
section
parameters {K : Type*} [decidable_eq K]
parameters {Γ : K → Type*}
parameters {Λ : Type*} [inhabited Λ]
parameters {σ : Type*} [inhabited σ]
local notation `stmt₂` := TM2.stmt Γ Λ σ
local notation `cfg₂` := TM2.cfg Γ Λ σ
inductive stackel (k : K)
| val : Γ k → stackel
| bottom : stackel
| top : stackel
instance stackel.inhabited (k) : inhabited (stackel k) :=
⟨stackel.top _⟩
def stackel.is_bottom {k} : stackel k → bool
| (stackel.bottom _) := tt
| _ := ff
def stackel.is_top {k} : stackel k → bool
| (stackel.top _) := tt
| _ := ff
def stackel.get {k} : stackel k → option (Γ k)
| (stackel.val a) := some a
| _ := none
section
open stackel
def stackel_equiv {k} : stackel k ≃ option (option (Γ k)) :=
begin
refine ⟨λ s, _, λ s, _, _, _⟩,
{ cases s, exacts [some (some s), none, some none] },
{ rcases s with _|_|s, exacts [bottom _, top _, val s] },
{ intro s, cases s; refl },
{ intro s, rcases s with _|_|s; refl },
end
end
def Γ' := ∀ k, stackel k
instance Γ'.inhabited : inhabited Γ' := ⟨λ _, default _⟩
instance stackel.fintype {k} [fintype (Γ k)] : fintype (stackel k) :=
fintype.of_equiv _ stackel_equiv.symm
instance Γ'.fintype [fintype K] [∀ k, fintype (Γ k)] : fintype Γ' :=
pi.fintype
inductive st_act (k : K)
| push {} : (σ → Γ k) → st_act
| pop {} : bool → (σ → option (Γ k) → σ) → st_act
section
open st_act
def st_run {k : K} : st_act k → stmt₂ → stmt₂
| (push f) := TM2.stmt.push k f
| (pop ff f) := TM2.stmt.peek k f
| (pop tt f) := TM2.stmt.pop k f
def st_var {k : K} (v : σ) (l : list (Γ k)) : st_act k → σ
| (push f) := v
| (pop b f) := f v l.head'
def st_write {k : K} (v : σ) (l : list (Γ k)) : st_act k → list (Γ k)
| (push f) := f v :: l
| (pop ff f) := l
| (pop tt f) := l.tail
@[elab_as_eliminator] theorem {l} stmt_st_rec
{C : stmt₂ → Sort l}
(H₁ : Π k (s : st_act k) q (IH : C q), C (st_run s q))
(H₂ : Π a q (IH : C q), C (TM2.stmt.load a q))
(H₃ : Π p q₁ q₂ (IH₁ : C q₁) (IH₂ : C q₂), C (TM2.stmt.branch p q₁ q₂))
(H₄ : Π l, C (TM2.stmt.goto l))
(H₅ : C TM2.stmt.halt) : ∀ n, C n
| (TM2.stmt.push k f q) := H₁ _ (push f) _ (stmt_st_rec q)
| (TM2.stmt.peek k f q) := H₁ _ (pop ff f) _ (stmt_st_rec q)
| (TM2.stmt.pop k f q) := H₁ _ (pop tt f) _ (stmt_st_rec q)
| (TM2.stmt.load a q) := H₂ _ _ (stmt_st_rec q)
| (TM2.stmt.branch a q₁ q₂) := H₃ _ _ _ (stmt_st_rec q₁) (stmt_st_rec q₂)
| (TM2.stmt.goto l) := H₄ _
| TM2.stmt.halt := H₅
theorem supports_run [fintype K] [∀ k, fintype (Γ k)] [fintype σ]
(S : finset Λ) {k} (s : st_act k) (q) :
TM2.supports_stmt S (st_run s q) ↔ TM2.supports_stmt S q :=
by rcases s with _|_|_; refl
end
inductive Λ' : Type (max u_1 u_2 u_3 u_4)
| normal {} : Λ → Λ'
| go (k) : st_act k → stmt₂ → Λ'
| ret {} : K → stmt₂ → Λ'
open Λ'
instance : inhabited Λ' := ⟨normal (default _)⟩
local notation `stmt₁` := TM1.stmt Γ' Λ' σ
local notation `cfg₁` := TM1.cfg Γ' Λ' σ
open TM1.stmt
def tr_st_act {k} (q : stmt₁) : st_act k → stmt₁
| (st_act.push f) :=
write (λ a s, dwrite a k $ stackel.val $ f s) $
move dir.right $
write (λ a s, dwrite a k $ stackel.top k) q
| (st_act.pop b f) :=
move dir.left $
load (λ a s, f s (a k).get) $
cond b
( branch (λ a s, (a k).is_bottom)
( move dir.right q )
( move dir.right $
write (λ a s, dwrite a k $ default _) $
move dir.left $
write (λ a s, dwrite a k $ stackel.top k) q ) )
( move dir.right q )
def tr_init (k) (L : list (Γ k)) : list Γ' :=
stackel.bottom :: match L.reverse with
| [] := [stackel.top]
| (a::L') := dwrite stackel.top k (stackel.val a) ::
(L'.map stackel.val ++ [stackel.top k]).map (dwrite (default _) k)
end
theorem step_run {k : K} (q v S) : ∀ s : st_act k,
TM2.step_aux (st_run s q) v S =
TM2.step_aux q (st_var v (S k) s) (dwrite S k (st_write v (S k) s))
| (st_act.push f) := rfl
| (st_act.pop ff f) := by simp!
| (st_act.pop tt f) := rfl
def tr_normal : stmt₂ → stmt₁
| (TM2.stmt.push k f q) := goto (λ _ _, go k (st_act.push f) q)
| (TM2.stmt.peek k f q) := goto (λ _ _, go k (st_act.pop ff f) q)
| (TM2.stmt.pop k f q) := goto (λ _ _, go k (st_act.pop tt f) q)
| (TM2.stmt.load a q) := load (λ _, a) (tr_normal q)
| (TM2.stmt.branch f q₁ q₂) := branch (λ a, f) (tr_normal q₁) (tr_normal q₂)
| (TM2.stmt.goto l) := goto (λ a s, normal (l s))
| TM2.stmt.halt := halt
theorem tr_normal_run {k} (s q) :
tr_normal (st_run s q) = goto (λ _ _, go k s q) :=
by rcases s with _|_|_; refl
parameters (M : Λ → stmt₂)
include M
def tr : Λ' → stmt₁
| (normal q) := tr_normal (M q)
| (go k s q) :=
branch (λ a s, (a k).is_top) (tr_st_act (goto (λ _ _, ret k q)) s)
(move dir.right $ goto (λ _ _, go k s q))
| (ret k q) :=
branch (λ a s, (a k).is_bottom) (tr_normal q)
(move dir.left $ goto (λ _ _, ret k q))
def tr_stk {k} (S : list (Γ k)) (L : list (stackel k)) : Prop :=
∃ n, L = (S.map stackel.val).reverse_core (stackel.top k :: list.repeat (default _) n)
local attribute [pp_using_anonymous_constructor] turing.TM1.cfg
inductive tr_cfg : cfg₂ → cfg₁ → Prop
| mk {q v} {S : ∀ k, list (Γ k)} {L : list Γ'} :
(∀ k, tr_stk (S k) (L.map (λ a, a k))) →
tr_cfg ⟨q, v, S⟩ ⟨q.map normal, v, (stackel.bottom, [], L)⟩
theorem tr_respects_aux₁ {k} (o q v) : ∀ S₁ {s S₂} {T : list Γ'},
T.map (λ (a : Γ'), a k) = (list.map stackel.val S₁).reverse_core (s :: S₂) →
∃ a T₁ T₂,
T = list.reverse_core T₁ (a :: T₂) ∧
a k = s ∧
T₁.map (λ (a : Γ'), a k) = S₁.map stackel.val ∧
T₂.map (λ (a : Γ'), a k) = S₂ ∧
reaches₀ (TM1.step tr)
⟨some (go k o q), v, (stackel.bottom, [], T)⟩
⟨some (go k o q), v, (a, T₁ ++ [stackel.bottom], T₂)⟩
| [] s S₂ (a :: T) hT := by injection hT with es e₂; exact
⟨a, [], _, rfl, es, rfl, e₂, reaches₀.single rfl⟩
| (s' :: S₁) s S₂ T hT :=
let ⟨a, T₁, b'::T₂, e, es', e₁, e₂, H⟩ := tr_respects_aux₁ S₁ hT in
by injection e₂ with es e₂; exact
⟨b', a::T₁, T₂, e, es, by simpa [es'], e₂, H.tail (by simp! [es'])⟩
local attribute [simp] TM1.step TM1.step_aux tr tr_st_act st_var st_write
tape.move tape.write list.reverse_core stackel.get stackel.is_bottom
theorem tr_respects_aux₂
{k q v} {S : Π k, list (Γ k)} {T₁ T₂ : list Γ'} {a : Γ'}
(hT : ∀ k, tr_stk (S k) ((T₁.reverse_core (a :: T₂)).map (λ (a : Γ'), a k)))
(e₁ : T₁.map (λ (a : Γ'), a k) = list.map stackel.val (S k))
(ea : a k = stackel.top k) (o) :
let v' := st_var v (S k) o,
Sk' := st_write v (S k) o,
S' : ∀ k, list (Γ k) := dwrite S k Sk' in
∃ b (T₁' T₂' : list Γ'),
(∀ (k' : K), tr_stk (S' k') ((T₁'.reverse_core (b :: T₂')).map (λ (a : Γ'), a k'))) ∧
T₁'.map (λ a, a k) = Sk'.map stackel.val ∧
b k = stackel.top k ∧
TM1.step_aux (tr_st_act q o) v (a, T₁ ++ [stackel.bottom], T₂) =
TM1.step_aux q v' (b, T₁' ++ [stackel.bottom], T₂') :=
begin
dsimp, cases o with f b f,
{ -- push
refine ⟨_, dwrite a k (stackel.val (f v)) :: T₁,
_, _, by simp [e₁]; refl, by simp, rfl⟩,
intro k', cases hT k' with n e,
by_cases h : k' = k,
{ subst k', existsi n.pred,
simp [list.reverse_core_eq, e₁, list.append_left_inj] at e ⊢,
simp [e] },
{ cases T₂ with t T₂,
{ existsi n+1,
simpa [h, list.reverse_core_eq, e₁, list.repeat_add] using
congr_arg (++ [default Γ' k']) e },
{ existsi n,
simpa [h, list.reverse_core_eq] using e } } },
have dw := dwrite_self S k,
cases T₁ with t T₁; cases eS : S k with s Sk;
rw eS at e₁ dw; injection e₁ with tk e₁'; cases b,
{ -- peek nil
simp [eS, dw],
exact ⟨_, [], _, hT, rfl, ea, rfl⟩ },
{ -- pop nil
simp [eS, dw],
exact ⟨_, [], _, hT, rfl, ea, rfl⟩ },
{ -- peek cons
dsimp at tk,
simp [eS, tk, dw],
exact ⟨_, t::T₁, _, hT, e₁, ea, rfl⟩ },
{ -- pop cons
dsimp at tk,
simp [eS, tk],
refine ⟨_, _, _, _, e₁', by simp, rfl⟩,
intro k', cases hT k' with n e,
by_cases h : k' = k,
{ subst k', existsi n+1,
simp [list.reverse_core_eq, eS, e₁', list.append_left_inj] at e ⊢,
simp [e] },
{ existsi n, simpa [h, list.map_reverse_core] using e } },
end
theorem tr_respects_aux₃ {k q v}
{S : Π k, list (Γ k)} {T : list Γ'}
(hT : ∀ k, tr_stk (S k) (T.map (λ (a : Γ'), a k))) :
∀ (T₁ : list Γ') {T₂ : list Γ'} {a : Γ'} {S₁}
(e : T = T₁.reverse_core (a :: T₂))
(ha : (a k).is_bottom = ff)
(e₁ : T₁.map (λ (a : Γ'), a k) = list.map stackel.val S₁),
reaches₀ (TM1.step tr)
⟨some (ret k q), v, (a, T₁ ++ [stackel.bottom], T₂)⟩
⟨some (ret k q), v, (stackel.bottom, [], T)⟩
| [] T₂ a S₁ e ha e₁ := reaches₀.single (by simp [ha, e])
| (b :: T₁) T₂ a (s :: S₁) e ha e₁ := begin
injection e₁ with es e₁, dsimp at es,
refine reaches₀.head _ (tr_respects_aux₃ T₁ e (by simp [es]) e₁),
simp [ha]
end
theorem tr_respects_aux {q v T k} {S : Π k, list (Γ k)}
(hT : ∀ (k : K), tr_stk (S k) (list.map (λ (a : Γ'), a k) T))
(o : st_act k)
(IH : ∀ {v : σ} {S : Π (k : K), list (Γ k)} {T : list Γ'},
(∀ (k : K), tr_stk (S k) (list.map (λ (a : Γ'), a k) T)) →
(∃ b, tr_cfg (TM2.step_aux q v S) b ∧
reaches (TM1.step tr) (TM1.step_aux (tr_normal q) v (stackel.bottom, [], T)) b)) :
∃ b, tr_cfg (TM2.step_aux (st_run o q) v S) b ∧
reaches (TM1.step tr) (TM1.step_aux (tr_normal (st_run o q))
v (stackel.bottom, [], T)) b :=
begin
rcases hT k with ⟨n, hTk⟩,
simp [tr_normal_run],
rcases tr_respects_aux₁ M o q v _ hTk with ⟨a, T₁, T₂, rfl, ea, e₁, e₂, hgo⟩,
rcases tr_respects_aux₂ M hT e₁ ea _ with ⟨b, T₁', T₂', hT', e₁', eb, hrun⟩,
have hret := tr_respects_aux₃ M hT' _ rfl (by simp [eb]) e₁',
have := hgo.tail' rfl,
simp [ea, tr] at this, rw [hrun, TM1.step_aux] at this,
rcases IH hT' with ⟨c, gc, rc⟩,
simp [step_run],
refine ⟨c, gc, (this.to₀.trans hret _ (trans_gen.head' rfl rc)).to_refl⟩
end
local attribute [simp] respects TM2.step TM2.step_aux tr_normal
theorem tr_respects : respects (TM2.step M) (TM1.step tr) tr_cfg :=
λ c₁ c₂ h, begin
cases h with l v S L hT, clear h,
cases l; simp! [option.map],
suffices : ∃ b, _ ∧ reaches (TM1.step (tr M)) _ _,
from let ⟨b, c, r⟩ := this in ⟨b, c, trans_gen.head' rfl r⟩,
rw [tr],
revert v S L hT, refine stmt_st_rec _ _ _ _ _ (M l); intros,
{ exact tr_respects_aux M hT s @IH },
{ simp [IH hT] },
{ simp, cases p v; [exact IH₂ hT, exact IH₁ hT] },
{ exact ⟨_, ⟨hT⟩, refl_trans_gen.refl⟩ },
{ exact ⟨_, ⟨hT⟩, refl_trans_gen.refl⟩ }
end
theorem tr_cfg_init (k) (L : list (Γ k)) :
tr_cfg (TM2.init k L) (TM1.init (tr_init k L)) :=
⟨λ k', begin
simp [tr_init, (∘)],
cases e : L.reverse with a L'; simp [tr_init],
{ cases list.reverse_eq_nil.1 e, simp, exact ⟨0, rfl⟩ },
by_cases k' = k,
{ subst k', existsi 0,
simp [list.reverse_core_eq, (∘)],
rw [← list.map_reverse, e], refl },
{ simp [h, (∘)],
existsi L'.length + 1,
rw list.repeat_add, refl }
end⟩
theorem tr_eval_dom (k) (L : list (Γ k)) :
(TM1.eval tr (tr_init k L)).dom ↔ (TM2.eval M k L).dom :=
tr_eval_dom tr_respects (tr_cfg_init _ _)
theorem tr_eval (k) (L : list (Γ k)) {L₁ L₂}
(H₁ : L₁ ∈ TM1.eval tr (tr_init k L))
(H₂ : L₂ ∈ TM2.eval M k L) :
∃ S : ∀ k, list (Γ k),
(∀ k', tr_stk (S k') (L₁.map (λ a, a k'))) ∧ S k = L₂ :=
begin
rcases (roption.mem_map_iff _).1 H₁ with ⟨c₁, h₁, rfl⟩,
rcases (roption.mem_map_iff _).1 H₂ with ⟨c₂, h₂, rfl⟩,
rcases tr_eval (tr_respects M) (tr_cfg_init M k L) h₂
with ⟨_, ⟨q, v, S, L₁', hT⟩, h₃⟩,
cases roption.mem_unique h₁ h₃,
exact ⟨S, hT, rfl⟩
end
variables [fintype K] [∀ k, fintype (Γ k)] [fintype σ]
local attribute [instance] classical.dec
local attribute [simp] TM2.stmts₁_self
noncomputable def tr_stmts₁ : stmt₂ → finset Λ'
| Q@(TM2.stmt.push k f q) := {go k (st_act.push f) q, ret k q} ∪ tr_stmts₁ q
| Q@(TM2.stmt.peek k f q) := {go k (st_act.pop ff f) q, ret k q} ∪ tr_stmts₁ q
| Q@(TM2.stmt.pop k f q) := {go k (st_act.pop tt f) q, ret k q} ∪ tr_stmts₁ q
| Q@(TM2.stmt.load a q) := tr_stmts₁ q
| Q@(TM2.stmt.branch f q₁ q₂) := tr_stmts₁ q₁ ∪ tr_stmts₁ q₂
| _ := ∅
theorem tr_stmts₁_run {k s q} : tr_stmts₁ (st_run s q) = {go k s q, ret k q} ∪ tr_stmts₁ q :=
by rcases s with _|_|_; dsimp [tr_stmts₁, st_run]; congr
noncomputable def tr_supp (S : finset Λ) : finset Λ' :=
S.bind (λ l, insert (normal l) (tr_stmts₁ (M l)))
local attribute [simp] tr_stmts₁ tr_stmts₁_run supports_run
tr_normal_run TM1.supports_stmt TM2.supports_stmt
theorem tr_supports {S} (ss : TM2.supports M S) :
TM1.supports tr (tr_supp S) :=
⟨finset.mem_bind.2 ⟨_, ss.1, finset.mem_insert.2 $ or.inl rfl⟩,
λ l' h, begin
suffices : ∀ q (ss' : TM2.supports_stmt S q)
(sub : ∀ x ∈ tr_stmts₁ M q, x ∈ tr_supp M S),
TM1.supports_stmt (tr_supp M S) (tr_normal q) ∧
(∀ l' ∈ tr_stmts₁ M q, TM1.supports_stmt (tr_supp M S) (tr M l')),
{ simp [tr_supp] at h,
rcases h with ⟨l, lS, h⟩,
have := this _ (ss.2 l lS) (λ x hx,
finset.mem_bind.2 ⟨_, lS, finset.mem_insert_of_mem hx⟩),
rcases h with rfl | h; [exact this.1, exact this.2 _ h] },
refine stmt_st_rec _ _ _ _ _; clear h l'; intros,
{ -- stack op
simp at sub ss',
have hgo := sub _ (or.inr $ or.inr rfl),
have hret := sub _ (or.inl rfl),
cases IH ss' (λ x hx, sub x $ or.inr $ or.inl hx) with IH₁ IH₂,
refine ⟨by simp [hgo], λ l h, _⟩,
rw [tr_stmts₁_run] at h, simp at h,
rcases h with rfl | h | rfl,
{ simp [hret], exact IH₁ },
{ exact IH₂ _ h },
{ simp [hgo],
rcases s with _|_|_; simp! [hret] } },
{ -- load
dsimp at sub ⊢, exact IH ss' sub },
{ -- branch
simp at sub,
cases IH₁ ss'.1 (λ x hx, sub x $ or.inl hx) with IH₁₁ IH₁₂,
cases IH₂ ss'.2 (λ x hx, sub x $ or.inr hx) with IH₂₁ IH₂₂,
refine ⟨⟨IH₁₁, IH₂₁⟩, λ l h, _⟩,
rw [tr_stmts₁] at h, simp at h,
rcases h with h | h; [exact IH₁₂ _ h, exact IH₂₂ _ h] },
{ -- goto
rw tr_stmts₁, simp [tr_normal],
exact λ v, finset.mem_bind.2 ⟨_, ss' v, by simp⟩ },
{ simp } -- halt
end⟩
end
end TM2to1
end turing
|
4f6a3abe75f14704b91c75ac9109811ef5bb6d8a | e5c11e5a7d990ce404047c2bd848eeafac3c0a85 | /src/trace.lean | d43dc133dbd7e39a4ed7f9931d50bea1a24d25b9 | [
"LPPL-1.3c"
] | permissive | lean-forward/class-number | 9ec63c24845e46efc8fa8b15324d0815918292c7 | 4fccf36d5e0e16accae84c16df77a3839ad964e4 | refs/heads/main | 1,686,927,014,542 | 1,624,886,724,000 | 1,624,886,724,000 | 327,319,245 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 54,137 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Anne Baanen
-/
import order.conditionally_complete_lattice
import field_theory.adjoin
import field_theory.algebraic_closure
import field_theory.galois
import field_theory.primitive_element
import linear_algebra.bilinear_form
import linear_algebra.char_poly.coeff
import linear_algebra.vandermonde
import ring_theory.algebra_tower
import ring_theory.localization
/-!
# Trace for (finite) ring extensions.
Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`,
the trace of the linear map given by multiplying by `s` gives information about
the roots of the minimal polynomial of `s` over `R`.
## Implementation notes
Typically, the trace is defined specifically for finite field extensions.
The definition is as general as possible and the assumption that we have
fields or that the extension is finite is added to the lemmas as needed.
We only define the trace for left multiplication (`algebra.lmul_left`).
For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway.
## References
* https://en.wikipedia.org/wiki/Field_trace
-/
universes u v w
variables {R S T : Type*} [comm_ring R] [comm_ring S] [comm_ring T]
variables {A: Type*} [integral_domain A] [algebra A S]
variables [algebra R S] [algebra R T]
variables {K L : Type*} [field K] [field L] [algebra K L]
variables {ι : Type w} [fintype ι]
open finite_dimensional
open intermediate_field
open linear_map
open matrix
open_locale big_operators
open_locale matrix
namespace algebra
variables {b : ι → S} (hb : is_basis R b)
variables (R S)
/-- The trace of an element `s` of an `R`-algebra is the trace of `(*) s`,
as an `R`-linear map. -/
noncomputable def trace : S →ₗ[R] R :=
(linear_map.trace R S).comp (lmul R S).to_linear_map
variables {S}
@[simp] lemma trace_apply (s : S) : trace R S s = linear_map.trace R S (lmul R S s) := rfl
lemma trace_eq_zero_of_not_exists_basis
(h : ¬ ∃ s : finset S, is_basis R (λ x, x : (↑s : set S) → S)) : trace R S = 0 :=
by { ext s, simp [linear_map.trace, h] }
lemma findim_eq_zero_of_not_exists_basis
(h : ¬ ∃ s : finset L, is_basis K (λ x, x : (↑s : set L) → L)) : findim K L = 0 :=
dif_neg (mt (λ h, @exists_is_basis_finset K L _ _ _ (finite_dimensional_iff_dim_lt_omega.mpr h)) h)
include hb
variables {R}
lemma trace_eq_matrix_trace [decidable_eq ι] (hb : is_basis R b) (s : S) :
trace R S s = matrix.trace _ R _ (matrix.lmul hb s) :=
by rw [trace_apply, linear_map.trace_eq_matrix_trace _ hb, to_matrix_lmul_eq]
/-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. -/
lemma trace_algebra_map_of_basis (x : R) :
trace R S (algebra_map R S x) = fintype.card ι • x :=
begin
haveI := classical.dec_eq ι,
rw [trace_apply, linear_map.trace_eq_matrix_trace R hb, trace_diag],
convert finset.sum_const _,
ext i,
simp,
end
omit hb
/-- If `x` is in the base field `K`, then the trace is `[L : K] * x`.
(If `L` is not finite-dimensional over `K`, then `trace` and `findim` return `0`.)
-/
@[simp]
lemma trace_algebra_map (x : K) : trace K L (algebra_map K L x) = findim K L • x :=
begin
by_cases H : ∃ s : finset L, is_basis K (λ x, x : (↑s : set L) → L),
{ rw [trace_algebra_map_of_basis H.some_spec, findim_eq_card_basis H.some_spec] },
{ simp [trace_eq_zero_of_not_exists_basis K H, findim_eq_zero_of_not_exists_basis H] },
end
section trace_form
variables (R S)
/-- The `trace_form` maps `x y : S` to the trace of `x * y`.
It is a symmetric bilinear form and is nondegenerate if the extension is separable. -/
noncomputable def trace_form : bilin_form R S :=
{ bilin := λ x y, trace R S (x * y),
bilin_add_left := λ x y z, by rw [add_mul, linear_map.map_add],
bilin_smul_left := λ x y z, by rw [smul_mul_assoc, linear_map.map_smul, smul_eq_mul],
bilin_add_right := λ x y z, by rw [mul_add, linear_map.map_add],
bilin_smul_right := λ x y z, by rw [mul_smul_comm, linear_map.map_smul, smul_eq_mul], }
variables {S}
@[simp] lemma trace_form_apply (x y : S) : trace_form R S x y = trace R S (x * y) := rfl
lemma trace_form_is_sym : sym_bilin_form.is_sym (trace_form R S) :=
λ x y, congr_arg (trace R S) (mul_comm _ _)
lemma trace_form_to_matrix [decidable_eq ι] (i j) :
bilin_form.to_matrix hb (trace_form R S) i j = trace R S (b i * b j) :=
by rw [bilin_form.to_matrix_apply, trace_form_apply]
lemma trace_form_to_matrix_power_basis (h : power_basis R S) :
bilin_form.to_matrix h.is_basis (trace_form R S) = λ i j, (trace R S (h.gen ^ (i + j : ℕ))) :=
by { ext, rw [trace_form_to_matrix, pow_add] }
end trace_form
end algebra
section trace_eq_sum_roots
variables {b : ι → S} (hb : is_basis R b)
open intermediate_field.adjoin_simple
open algebra
section
open polynomial
lemma matrix.card_le_card_of_left_inv' {m n : ℕ}
{M : matrix (fin m) (fin n) A} {M' : matrix (fin n) (fin m) A}
(hMM' : M ⬝ M' = 1) :
m ≤ n :=
have function.left_inverse
((M.map (algebra_map A (fraction_ring A))).mul_vec)
((M'.map (algebra_map A (fraction_ring A))).mul_vec) :=
λ x, by rw [mul_vec_mul_vec, ← matrix.map_mul, hMM', matrix.ring_hom_map_one, mul_vec_one],
have function.injective ((M'.map (algebra_map A (fraction_ring A))).to_lin') :=
function.left_inverse.injective this,
calc m = findim (fraction_ring A) (fin m → fraction_ring A) : (findim_fin_fun _).symm
... ≤ findim (fraction_ring A) (fin n → fraction_ring A) : findim_le_findim_of_injective this
... = n : findim_fin_fun _
lemma matrix.card_le_card_of_left_inv {m n : Type*}
[fintype m] [decidable_eq m] [fintype n]
{M : matrix m n A} {M' : matrix n m A} (hMM' : M ⬝ M' = 1) :
fintype.card m ≤ fintype.card n :=
begin
haveI : decidable_eq n := classical.dec_eq n,
let em := trunc.out (fintype.equiv_fin m),
let en := trunc.out (fintype.equiv_fin n),
apply @matrix.card_le_card_of_left_inv' A,
calc reindex_linear_equiv em en M ⬝ reindex_linear_equiv en em M'
= reindex_linear_equiv em em (M ⬝ M') : reindex_mul em en em M M'
... = reindex_linear_equiv em em 1 : by rw hMM'
... = 1 : (reindex_alg_equiv em).map_one
end
/-- If an `m × n` matrix has an inverse, then `m = n`. -/
noncomputable def matrix.equiv_of_inv {m n : Type*}
[fintype m] [decidable_eq m] [fintype n] [decidable_eq n]
{M : matrix m n A} {M' : matrix n m A}
(hMM' : M ⬝ M' = 1) (hM'M : M' ⬝ M = 1) :
m ≃ n :=
classical.choice (fintype.card_eq.mp (le_antisymm
(matrix.card_le_card_of_left_inv hMM')
(matrix.card_le_card_of_left_inv hM'M)))
/-- If `A'` is a two-sided inverse for `A` (indexed differently), `det (A ⬝ B ⬝ A') = det B`. -/
lemma det_conjugate_aux {m n : Type*} [fintype m] [decidable_eq m]
[fintype n] [decidable_eq n] {M : matrix m n A} {M' : matrix n m A} {N : matrix n n A}
(hMM' : M ⬝ M' = 1) (hM'M : M' ⬝ M = 1) :
det (M ⬝ N ⬝ M') = det N :=
begin
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e : m ≃ n := matrix.equiv_of_inv hMM' hM'M,
have :
det (reindex_linear_equiv e (equiv.refl _) M ⬝ N ⬝ reindex_linear_equiv (equiv.refl _) e M')
= det N,
{ rw [det_mul, det_mul, mul_comm, ← mul_assoc, ← det_mul, reindex_mul,
reindex_linear_equiv_refl_refl, hM'M, det_one, one_mul] },
convert this,
rw [← det_reindex_linear_equiv_self e (M ⬝ N ⬝ M'), ← reindex_mul e (equiv.refl n) e,
← reindex_mul e (equiv.refl n) (equiv.refl n), reindex_linear_equiv_refl_refl],
end
/-- If `A'` is a two-sided inverse for `A`, `char_poly (A ⬝ B ⬝ A') = char_poly B`. -/
lemma char_poly_conjugate_aux {m n : Type*} [fintype m] [decidable_eq m]
[fintype n] [decidable_eq n] {M : matrix m n A} {M' : matrix n m A} {N : matrix n n A}
(hMM' : M ⬝ M' = 1) (hM'M : M' ⬝ M = 1) :
char_poly (M ⬝ N ⬝ M') = char_poly N :=
have hCACA' : M.map C ⬝ M'.map C = 1 := by rw [← matrix.map_mul, hMM', matrix.ring_hom_map_one],
have hCA'CA : M'.map C ⬝ M.map C = 1 := by rw [← matrix.map_mul, hM'M, matrix.ring_hom_map_one],
calc (X • 1 - C.map_matrix (M ⬝ N ⬝ M')).det
= (M.map C ⬝ (scalar n X - N.map C) ⬝ M'.map C).det :
by rw [matrix.mul_sub, matrix.sub_mul, ring_hom.map_matrix_apply, matrix.map_mul,
matrix.map_mul, coe_scalar, matrix.mul_smul, matrix.mul_one,
matrix.smul_mul, hCACA']
... = (X • 1 - C.map_matrix N).det : det_conjugate_aux hCACA' hCA'CA
lemma char_poly_conjugate {n : Type*} [fintype n] [decidable_eq n] {M B : matrix n n A}
(hM : is_unit M.det) :
char_poly (M⁻¹ ⬝ B ⬝ M) = char_poly B :=
char_poly_conjugate_aux (nonsing_inv_mul _ hM) (mul_nonsing_inv _ hM)
end
variables {M M' : Type*} [add_comm_group M] [module R M] [add_comm_group M'] [module R M']
section
variables {ι' κ κ' : Type*} [fintype ι'] [decidable_eq ι']
variables [decidable_eq ι] [fintype κ] [fintype κ']
variables {b' : ι' → M} (hb' : is_basis R b')
variables {c : κ → M'} {c' : κ' → M'} (hc : is_basis R c) (hc' : is_basis R c')
variables (f : M →ₗ[R] M')
lemma to_matrix_basis_change
{b : ι → M} (hb : is_basis R b) :
to_matrix hb hc f = hc.to_matrix c' ⬝ to_matrix hb' hc' f ⬝ hb'.to_matrix b :=
by rw [is_basis_to_matrix_mul_linear_map_to_matrix, linear_map_to_matrix_mul_is_basis_to_matrix]
end
lemma char_poly_lmul_matrix_basis_invariant [decidable_eq ι]
{ι' : Type*} [fintype ι'] [decidable_eq ι']
(hb : is_basis A b) {b' : ι' → S} (hb' : is_basis A b') (x : S) :
char_poly (matrix.lmul hb x) = char_poly (matrix.lmul hb' x) :=
begin
change char_poly (to_matrix hb hb (lmul A S x)) = char_poly (to_matrix hb' hb' (lmul A S x)),
rw [to_matrix_basis_change hb hb' hb, char_poly_conjugate_aux];
rw [is_basis.to_matrix_mul_to_matrix, is_basis.to_matrix_self];
assumption
end
section
/-- `(l : M →ₗ[S] M').restrict_base R` is `l` as an `R`-linear map. -/
def linear_map.restrict_base (R : Type*) [comm_semiring R]
{S M M' : Type*} [semiring S] [algebra R S]
[add_comm_monoid M] [semimodule R M] [semimodule S M] [is_scalar_tower R S M]
[add_comm_monoid M'] [semimodule R M'] [semimodule S M'] [is_scalar_tower R S M']
(l : M →ₗ[S] M') : M →ₗ[R] M' :=
{ map_smul' := λ c x,
show l (c • x) = c • l x,
by rw [← is_scalar_tower.algebra_map_smul S c x, l.map_smul, is_scalar_tower.algebra_map_smul],
.. (l.to_add_monoid_hom) }
@[simp] lemma linear_map.restrict_base_apply
(R : Type*) {S M M' : Type*} [comm_semiring R] [semiring S] [algebra R S]
[add_comm_monoid M] [semimodule R M] [semimodule S M] [is_scalar_tower R S M]
[add_comm_monoid M'] [semimodule R M'] [semimodule S M'] [is_scalar_tower R S M']
(l : M →ₗ[S] M') (x : M) : l.restrict_base R x = l x := rfl
instance is_scalar_tower.finsupp {α : Type*} : is_scalar_tower R S (α →₀ S) :=
⟨λ r s t, finsupp.ext (λ x, show ((r • s) • t x) = (r • s • t x), by rw smul_assoc)⟩
end
lemma trace_comp_of_basis [algebra S T] [is_scalar_tower R S T]
{ι κ : Type*} [fintype ι] [fintype κ] {b : ι → S} {c : κ → T}
(hb : is_basis R b) (hc : is_basis S c) (x : T) :
algebra.trace R T x = trace R S (trace S T x) :=
begin
haveI := classical.dec_eq ι,
haveI := classical.dec_eq κ,
rw [trace_eq_matrix_trace (hb.smul hc), trace_eq_matrix_trace hb, trace_eq_matrix_trace hc,
matrix.trace_apply, matrix.trace_apply, matrix.trace_apply,
← finset.univ_product_univ, finset.sum_product],
refine finset.sum_congr rfl (λ i _, _),
rw [alg_hom.map_sum, finset.sum_apply, finset.sum_apply],
refine finset.sum_congr rfl (λ j _, _),
apply matrix.smul_lmul
end
lemma trace_comp (L : Type*) [field L]
[algebra K L] [algebra K T] [algebra L T] [is_scalar_tower K L T]
[finite_dimensional K L] [finite_dimensional L T] (x : T) :
algebra.trace K T x = trace K L (trace L T x) :=
trace_comp_of_basis
(classical.some_spec (exists_is_basis_finset K L))
(classical.some_spec (exists_is_basis_finset L T))
x
lemma aeval_lmul_matrix [decidable_eq ι] (p : polynomial R) (x : S) :
polynomial.aeval (matrix.lmul hb x) p = matrix.lmul hb (polynomial.aeval x p) :=
p.aeval_alg_hom_apply (matrix.lmul hb) x
lemma linear_map.injective_iff {V V' : Type*} [add_comm_group V] [add_comm_monoid V']
[semimodule R V] [semimodule R V']
(f : V →ₗ[R] V') : function.injective f ↔ ∀ x, f x = 0 → x = 0 :=
f.to_add_monoid_hom.injective_iff
lemma char_poly_lmul_power_basis [algebra K S] (h : power_basis K S) :
char_poly (matrix.lmul h.is_basis h.gen) = minpoly K h.gen :=
begin
apply minpoly.unique,
{ apply char_poly_monic },
{ have := matrix.lmul_injective h.is_basis,
apply (matrix.lmul _).injective_iff.mp this,
rw [← aeval_lmul_matrix, aeval_self_char_poly] },
{ intros q q_monic root_q,
rw [char_poly_degree_eq_dim, fintype.card_fin,
polynomial.degree_eq_nat_degree q_monic.ne_zero],
apply with_bot.some_le_some.mpr,
exact h.dim_le_nat_degree_of_root q_monic.ne_zero root_q }
end
section
open polynomial
lemma multiset.sum_const_one {α R : Type*} [semiring R] (s : multiset α) :
(s.map (λ _, (1 : R))).sum = s.card :=
begin
refine multiset.induction_on s _ _,
{ rw [multiset.map_zero, multiset.card_zero, multiset.sum_zero],
norm_cast },
{ intros a s ih,
rw [multiset.map_cons, multiset.sum_cons, multiset.card_cons, ih, add_comm],
norm_cast }
end
lemma coeff_prod_X_sub_C {R : Type*} [comm_ring R] [nontrivial R] (s : multiset R) :
(s.map (λ x, X - C x)).prod.coeff s.card = 1 :=
begin
have monic : ∀ p ∈ s.map (λ x, X - C x), p.monic,
{ simp only [multiset.mem_map],
rintros _ ⟨a, ha, rfl⟩,
exact monic_X_sub_C a },
have nat_degree_eq' : (nat_degree ∘ λ (x : R), X - C x) = (λ _, 1),
{ ext a,
exact nat_degree_X_sub_C a },
have leading_coeff_eq' : (leading_coeff ∘ λ (x : R), X - C x) = (λ _, 1),
{ ext a,
exact monic_X_sub_C a },
convert leading_coeff_multiset_prod' _ _,
{ simp [nat_degree_multiset_prod_of_monic _ monic, nat_degree_eq', multiset.sum_const_one] },
{ rw [multiset.map_map, leading_coeff_eq', multiset.prod_map_one] },
{ convert (one_ne_zero : (1 : R) ≠ 0),
rw [multiset.map_map, leading_coeff_eq', multiset.prod_map_one] },
end
lemma coeff_prod_X_sub_C_of_succ_eq_aux {R : Type*} [comm_ring R] [nontrivial R]
(a : R) (s : multiset R) :
((a ::ₘ s).map (λ x, X - C x)).prod.coeff s.card = - (a ::ₘ s).sum :=
begin
refine multiset.induction_on s _ (λ b s ih, _),
{ simp only [multiset.map_cons, multiset.map_zero, multiset.prod_cons, multiset.prod_zero,
mul_one, multiset.sum_cons, multiset.sum_zero, add_zero, multiset.card_zero,
coeff_sub, coeff_X_zero, coeff_C_zero, zero_sub] },
rw [multiset.cons_swap a b s, multiset.map_cons, multiset.prod_cons, multiset.sum_cons,
multiset.card_cons, coeff_mul, finset.nat.antidiagonal_succ, finset.sum_insert, neg_add],
congr,
{ simp only [coeff_sub, coeff_X_zero, coeff_C_zero, zero_sub],
rw [← multiset.card_cons a s, coeff_prod_X_sub_C (a ::ₘ s), mul_one] },
{ rw [finset.sum_eq_single (1, s.card), ih, coeff_sub, coeff_X_one, coeff_C,
if_neg (one_ne_zero : (1 : ℕ) ≠ 0), sub_zero, one_mul],
{ simp only [finset.mem_map],
rintros _ ⟨⟨i, j⟩, hij, rfl⟩ ij_ne,
have one_ne : 1 ≠ nat.succ i,
{ intro hi,
apply ij_ne,
cases nat.succ_injective hi,
simp only [finset.nat.mem_antidiagonal, zero_add] at hij,
cases hij,
refl },
simp only [function.embedding.prod_map, function.embedding.coe_fn_mk, prod.map,
coeff_sub, coeff_X, if_neg one_ne, coeff_C, if_neg (nat.succ_ne_zero i),
sub_zero, zero_mul] },
{ simp only [finset.mem_map, not_exists],
intros hx,
exfalso,
simpa using hx ⟨0, multiset.card s⟩ } },
{ simp only [finset.mem_map, not_exists],
rintros ⟨i, j⟩ hij,
simp [i.succ_ne_zero] }
end
lemma coeff_prod_X_sub_C_of_succ_eq {R : Type*} [comm_ring R] [nontrivial R]
(s : multiset R) :
∀ {i : ℕ} (hi : i + 1 = s.card), (s.map (λ x, X - C x)).prod.coeff i = - s.sum :=
begin
refine multiset.induction _ _ s,
{ rintros i ⟨⟩ },
intros a s ih i hi,
rw [multiset.card_cons, add_left_inj] at hi,
cases hi,
exact coeff_prod_X_sub_C_of_succ_eq_aux a s
end
lemma coeff_sub_one_eq {K L : Type*} [field K] [field L]
{p : polynomial K} {hp : 0 < p.nat_degree} {f : K →+* L} (h : p.splits f) :
f (p.coeff (p.nat_degree - 1)) = - f (p.leading_coeff) * multiset.sum (p.map f).roots :=
begin
conv_lhs { rw [← coeff_map, eq_prod_roots_of_splits h] },
rw [coeff_C_mul, coeff_prod_X_sub_C_of_succ_eq, neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm],
rw [nat.sub_add_cancel hp, nat_degree_eq_card_roots h],
end
end
lemma fin.nonempty {n : ℕ} (hn : 0 < n) : nonempty (fin n) :=
by { cases n, { cases hn }, { exact has_zero.nonempty } }
lemma power_basis.trace_gen_eq_sum_roots {F : Type*} [field F] [algebra K F]
(pb : power_basis K L)
(h : polynomial.splits (algebra_map K F) pb.minpoly_gen) :
algebra_map _ F (algebra.trace K L pb.gen) =
(pb.minpoly_gen.map (algebra_map K F)).roots.sum :=
begin
rw [trace_eq_matrix_trace pb.is_basis,
trace_eq_neg_char_poly_coeff (matrix.lmul _ (power_basis.gen _)),
char_poly_lmul_power_basis, ← pb.minpoly_gen_eq,
fintype.card_fin, ← pb.nat_degree_minpoly_gen,
ring_hom.map_neg, coeff_sub_one_eq h,
show pb.minpoly_gen.leading_coeff = 1, from pb.minpoly_gen_monic,
ring_hom.map_one, neg_mul_eq_neg_mul_symm, one_mul, neg_neg],
{ exact pb.nat_degree_minpoly_gen_pos },
{ apply fin.nonempty,
rw [← pb.nat_degree_minpoly, polynomial.nat_degree_pos_iff_degree_pos],
exact minpoly.degree_pos pb.is_integral_gen }
end
section
open intermediate_field
lemma trace_gen_eq_sum_roots {F : Type*} [field F] [algebra K F]
{x : L} (hx : is_integral K x) (h : polynomial.splits (algebra_map K F) (minpoly K x)) :
algebra_map _ F (algebra.trace K K⟮x⟯ (gen K x)) =
((minpoly K x).map (algebra_map K F)).roots.sum :=
begin
rw ← adjoin.power_basis.minpoly_gen_eq hx at ⊢ h,
exact power_basis.trace_gen_eq_sum_roots _ h
end
@[simp] lemma multiset.length_to_list {α : Type*} (m : multiset α) :
m.to_list.length = m.card :=
calc m.to_list.length = multiset.card ↑m.to_list : (multiset.coe_card _).symm
... = m.card : congr_arg _ m.coe_to_list
section conjugates
open polynomial
/-- `alg_hom_of_root (hx : is_integral K x) (hy : aeval y (minpoly hx) = 0)`
is the algebra homomorphism sending `K` to the image of `K` in `F` and `x` to `y`. -/
noncomputable def alg_hom_of_root {F : Type*} [field F] [algebra K F]
{x : L} (hx : is_integral K x) {y : F} (hy : aeval y (minpoly K x) = 0) :
↥K⟮x⟯ →ₐ[K] F :=
(alg_hom_adjoin_integral_equiv _ hx).symm
⟨y, by simpa [mem_roots_map (minpoly.ne_zero hx)] using hy⟩
noncomputable instance algebra_adjoin_splitting_field {x : L} (hx : is_integral K x) :
algebra ↥K⟮x⟯ (splitting_field (minpoly K x)) :=
(alg_hom_of_root hx (map_root_of_splits _ (splitting_field.splits _)
(ne_of_gt (minpoly.degree_pos hx)))).to_ring_hom.to_algebra
variables {F : Type*} [field F] [algebra K F] (pb : power_basis K L)
(hF : pb.minpoly_gen.splits (algebra_map K F))
lemma power_basis.dim_eq_card_roots
(hF : pb.minpoly_gen.splits (algebra_map K F)) :
pb.dim = (pb.minpoly_gen.map (algebra_map K F)).roots.card :=
by rw [← power_basis.nat_degree_minpoly_gen, nat_degree_eq_card_roots hF]
@[simp]
lemma multiset.to_list_nodup {α : Type*} {m : multiset α} :
m.to_list.nodup ↔ m.nodup :=
by rw [← multiset.coe_nodup, m.coe_to_list]
@[simp]
lemma list.sum_nth_le {α β : Type*} [add_comm_monoid β] (l : list α) (f : α → β)
{n : ℕ} (hn : n = l.length) :
∑ i : fin n, f (l.nth_le i (lt_of_lt_of_le i.2 (le_of_eq hn))) = (l.map f).sum :=
begin
cases hn,
induction l with a l ih,
{ rw [list.map_nil, list.sum_nil, ← finset.sum_empty, finset.sum_congr _ (λ _ _, rfl)],
ext i,
cases i.2 },
{ rw [list.map_cons, list.sum_cons, ← ih rfl, finset.sum_fin_eq_sum_range,
finset.sum_fin_eq_sum_range],
conv in (finset.range (a :: l).length)
{ rw list.length_cons a l},
rw [finset.sum_range_succ', add_comm],
dsimp only [list.length_cons],
refine congr (congr_arg (+) _) _,
{ simp [dif_pos (nat.zero_lt_succ _)] },
{ refine finset.sum_congr rfl _,
intros i hi,
rw finset.mem_range at hi,
rw [dif_pos hi, dif_pos (nat.succ_lt_succ hi)],
refl } },
end
-- TODO: `@[to_additive]` doesn't work
@[simp]
lemma list.prod_nth_le {α β : Type*} [comm_monoid β] (l : list α) (f : α → β)
{n : ℕ} (hn : n = l.length) :
∏ i : fin n, f (l.nth_le i (lt_of_lt_of_le i.2 (le_of_eq hn))) = (l.map f).prod :=
begin
cases hn,
induction l with a l ih,
{ rw [list.map_nil, list.prod_nil, ← finset.prod_empty, finset.prod_congr _ (λ _ _, rfl)],
ext i,
cases i.2 },
{ rw [list.map_cons, list.prod_cons, ← ih rfl, finset.prod_fin_eq_prod_range,
finset.prod_fin_eq_prod_range],
conv in (finset.range (a :: l).length)
{ rw list.length_cons a l},
rw [finset.prod_range_succ', mul_comm],
dsimp only [list.length_cons],
refine congr (congr_arg (*) _) _,
{ simp [dif_pos (nat.zero_lt_succ _)] },
{ refine finset.prod_congr rfl _,
intros i hi,
rw finset.mem_range at hi,
simp only [dif_pos hi, dif_pos (nat.succ_lt_succ hi)],
refl } },
end
@[simp, to_additive]
lemma multiset.prod_to_list {α : Type*} [comm_monoid α] (m : multiset α) :
m.to_list.prod = m.prod :=
by rw [← multiset.coe_prod m.to_list, m.coe_to_list]
include hF
/-- `power_basis.conjugates hF` is the vector of all conjugates to the generator of `L / K`,
in a field `F` where `hF` shows the appropriate minimal polynomial splits.
The order of the conjugates is arbitrary.
-/
noncomputable def power_basis.conjugates :
fin pb.dim → F :=
λ i, (pb.minpoly_gen.map (algebra_map K F)).roots.to_list.nth_le i
(by simpa [pb.dim_eq_card_roots hF] using i.2)
/-- `power_basis.conjugate_matrix hF` is a Vandermonde matrix of conjugates to
the generator of `L / K`, in a field `F` where `hF` shows the appropriate minimal polynomial splits.
The order of the conjugates is arbitrary.
-/
noncomputable def power_basis.conjugate_matrix :
matrix (fin pb.dim) (fin pb.dim) F
| i j := pb.conjugates hF j ^ (i : ℕ)
lemma power_basis.conjugates_injective (hpb : pb.minpoly_gen.separable) :
function.injective (pb.conjugates hF) :=
λ i j h, fin.coe_injective (list.nodup_iff_nth_le_inj.mp
(multiset.to_list_nodup.mpr (nodup_roots (separable.map hpb)))
_ _ _ _ h)
lemma sum_conjugates (f : F → R) :
∑ i, f (pb.conjugates hF i) = ((pb.minpoly_gen.map (algebra_map K F)).roots.map f).sum :=
begin
refine trans (list.sum_nth_le _ _ _) _,
{ rw [pb.dim_eq_card_roots hF, multiset.length_to_list] },
rw [← multiset.coe_sum, ← multiset.coe_map, multiset.coe_to_list]
end
omit hF
/-- A `S`-algebra structure on `T` given by a map fixing `R` gives a tower of algebras. -/
@[priority(100)] -- See note [lower instance priority]
instance algebra_tower_alg_hom (f : S →ₐ[R] T) :
@is_scalar_tower R S T _ f.to_ring_hom.to_algebra.to_has_scalar _ :=
{ smul_assoc := λ x y z, show f (x • y) • z = x • (f y • z), by rw [f.map_smul, smul_assoc] }
lemma trace_eq_sum_roots [finite_dimensional K L]
{x : L} (hx : is_integral K x) (hF : (minpoly K x).splits (algebra_map K F)) :
algebra_map K F (algebra.trace K L x) =
findim ↥K⟮x⟯ L • ((minpoly K x).map (algebra_map K _)).roots.sum :=
begin
haveI : finite_dimensional K⟮x⟯ L := finite_dimensional.right K _ L,
rw trace_comp K⟮x⟯ x,
conv in x { rw [← algebra_map_gen K x] },
rw [trace_algebra_map, ← is_scalar_tower.algebra_map_smul K, (algebra.trace K K⟮x⟯).map_smul,
smul_eq_mul, ring_hom.map_mul, ← is_scalar_tower.algebra_map_apply ℕ K _, ← smul_def,
trace_gen_eq_sum_roots hx hF],
all_goals { apply_instance }
end
noncomputable instance multiset.fintype_mem {α : Type*} (m : multiset α) :
fintype {x // x ∈ m} :=
by classical; exact
fintype.of_injective
(λ x, (⟨x.1, finset.mem_coe.mpr (multiset.mem_to_finset.mpr x.2)⟩ : (m.to_finset : set α)))
(λ ⟨x, hx⟩ ⟨y, hy⟩ h, by { ext, simpa using h })
@[simp] lemma multiset.univ_mem_zero {α : Type*} :
(finset.univ : finset {x // x ∈ (0 : multiset α)}) = ∅ :=
by { ext x, cases x with _ hx, cases hx }
@[to_additive, simp] lemma multiset.prod_mem {α M : Type*} [decidable_eq α]
[comm_monoid M] (m : multiset α) (f : {x // x ∈ m} → M) (g : α → M)
(hfg : ∀ x, f x = g x) :
∏ (x : {x // x ∈ m}), f x = ∏ x in m.to_finset, g x :=
finset.prod_bij (λ x _, x.1) (λ x _, multiset.mem_to_finset.mpr x.2)
(λ _ _, hfg _)
(λ _ _ _ _ h, by { ext, assumption })
(λ y hy, ⟨⟨y, multiset.mem_to_finset.mp hy⟩, finset.mem_univ _, rfl⟩)
/-- Specialize `finset.sum_bij'` to sums over fintypes with an equiv. -/
lemma finset.sum_equiv {M : Type*} [add_comm_monoid M]
{m n : Type*} [fintype m] [fintype n] (e : m ≃ n) (f : m → M) :
∑ x : m, f x = ∑ y : n, f (e.symm y) :=
finset.sum_bij'
(λ x _, e x) (λ _ _, finset.mem_univ _) (λ _ _, by rw e.symm_apply_apply)
(λ y _, e.symm y) (λ _ _, finset.mem_univ _) (λ _ _, by rw e.symm_apply_apply)
(λ _ _, by rw e.apply_symm_apply)
@[simp] lemma adjoin_root_equiv_adjoin_symm_gen {x : L} (h : is_integral K x) :
(adjoin_root_equiv_adjoin K h).symm (adjoin_simple.gen K x) =
adjoin_root.root (minpoly K x) :=
(adjoin_root_equiv_adjoin K h).injective (by simp [adjoin_root_equiv_adjoin_apply_root])
@[simp] lemma adjoin_root_equiv_symm_apply_root {f : polynomial K} (hf : f ≠ 0)
(x : {x // x ∈ (f.map (algebra_map K L)).roots}) :
(adjoin_root.equiv K L f hf).symm x (adjoin_root.root _) = x :=
by { simp only [adjoin_root.equiv, equiv.coe_fn_symm_mk],
exact @adjoin_root.lift_root _ _ _ f _ _ _ ((mem_roots_map hf).mp x.2) }
lemma alg_hom_adjoin_integral_equiv_apply
{x : L} (hx : is_integral K x)
(y : {y // y ∈ ((minpoly K x).map (algebra_map K F)).roots}) :
(alg_hom_adjoin_integral_equiv K hx).symm y (gen K x) = y :=
by simp only [alg_hom_adjoin_integral_equiv, equiv.symm_trans_apply,
adjoin_root_equiv_adjoin_symm_gen, alg_equiv.coe_alg_hom, equiv.coe_fn_symm_mk,
alg_equiv.to_alg_hom_eq_coe, adjoin_root_equiv_symm_apply_root, alg_hom.comp_apply]
lemma sum_embeddings_gen {M : Type*} [add_comm_monoid M]
{x : L} (hx : is_integral K x) (hfx : (minpoly K x).separable)
(f : F → M) :
@finset.sum _ _ _ (@finset.univ _ (fintype_of_alg_hom_adjoin_integral _ hx))
(λ σ : ↥K⟮x⟯ →ₐ[K] F, f (σ (adjoin_simple.gen K x)))
= (((minpoly K x).map (algebra_map K F)).roots.map f).sum :=
begin
classical,
rw [finset.sum_equiv (alg_hom_adjoin_integral_equiv K hx), multiset.sum_mem _ _ f],
{ rw [finset.sum_eq_multiset_sum, multiset.to_finset_val,
multiset.erase_dup_eq_self.mpr (nodup_roots ((separable_map _).mpr hfx))] },
{ intro x,
rw alg_hom_adjoin_integral_equiv_apply hx }
end
-- TODO: prove this directly assuming `is_power_basis`
lemma trace_eq_sum_embeddings_gen [finite_dimensional K L]
{x : L} (hx : is_integral K x) (hfx : (minpoly K x).separable)
(hF : (minpoly K x).splits (algebra_map K F)) :
algebra_map K F (algebra.trace K L x) =
findim ↥K⟮x⟯ L • @finset.sum _ _ _ (@finset.univ _ (fintype_of_alg_hom_adjoin_integral _ hx))
(λ σ : ↥K⟮x⟯ →ₐ[K] F, σ (adjoin_simple.gen K x)) :=
by simp_rw [trace_eq_sum_roots hx hF, sum_embeddings_gen hx hfx (λ x, x), multiset.map_id']
/-- Apply an `alg_equiv` to the left side of an `alg_hom`. -/
def alg_hom_congr_left {S' : Type*} (T : Type*) [comm_semiring S'] [algebra R S']
[comm_semiring T] [algebra R T]
(e : S ≃ₐ[R] S') : (S →ₐ[R] T) ≃ (S' →ₐ[R] T) :=
{ to_fun := λ f, f.comp e.symm,
inv_fun := λ f, f.comp e,
left_inv := λ x,
by { ext, simp only [alg_equiv.symm_apply_apply, alg_equiv.coe_alg_hom, alg_hom.comp_apply] },
right_inv := λ x,
by { ext, simp only [alg_equiv.apply_symm_apply, alg_equiv.coe_alg_hom, alg_hom.comp_apply] } }
@[simp] lemma alg_hom_congr_left_apply {S' T : Type*} [comm_semiring S'] [algebra R S']
[comm_semiring T] [algebra R T]
(e : S ≃ₐ[R] S') (f : S →ₐ[R] T) (x : S') : alg_hom_congr_left T e f x = f (e.symm x) :=
rfl
@[simp] lemma alg_hom_congr_left_symm_apply {S' T : Type*} [comm_semiring S'] [algebra R S']
[comm_semiring T] [algebra R T]
(e : S ≃ₐ[R] S') (f : S' →ₐ[R] T) (x : S) : (alg_hom_congr_left T e).symm f x = f (e x) :=
rfl
/-- A rephrasing of the primitive element theorem:
in a finite separable field extension, there is an `x` such that `L ≃ K⟮x⟯`. -/
noncomputable def field.equiv_primitive_element (K L : Type*) [field K] [field L] [algebra K L]
[is_separable K L] [finite_dimensional K L] :
Σ x : L, L ≃ₐ[K] K⟮x⟯ :=
let f := (@intermediate_field.top_equiv K _ L _ _).symm in
⟨classical.some (field.exists_primitive_element K L),
by rwa ← classical.some_spec (field.exists_primitive_element K L) at f⟩
/-- If `L` has a power basis over `K`, there are finitely many maps `L → F` fixing `K`. -/
noncomputable def power_basis.fintype_alg_hom (pb : power_basis K L) :
fintype (L →ₐ[K] F) :=
@fintype.of_equiv _ (K⟮pb.gen⟯ →ₐ[K] F)
(fintype_of_alg_hom_adjoin_integral _ pb.is_integral_gen)
(alg_hom_congr_left F pb.equiv_adjoin_simple)
lemma finite_dimensional.is_integral (K : Type*) [field K] [algebra K L] [finite_dimensional K L]
(x : L) : is_integral K x :=
((is_algebraic_iff_is_integral K).mp (is_algebraic_of_finite x))
noncomputable instance alg_hom.fintype_of_separable
[hsep : is_separable K L] [finite_dimensional K L] :
fintype (L →ₐ[K] F) :=
@fintype.of_equiv _ (K⟮(field.equiv_primitive_element K L).1⟯ →ₐ[K] F)
(fintype_of_alg_hom_adjoin_integral _ (finite_dimensional.is_integral _ _))
(alg_hom_congr_left F (field.equiv_primitive_element K L).2.symm)
noncomputable instance adjoin.fintype_alg_hom_of_finite_dimensional (x : L)
[finite_dimensional K L] :
fintype (K⟮x⟯ →ₐ[K] F) :=
power_basis.fintype_alg_hom
(intermediate_field.adjoin.power_basis (finite_dimensional.is_integral _ _))
-- TODO: to_additive this from prod_surj
lemma finset.sum_eq_card_smul {α β : Type*} [decidable_eq β]
(f : α → β) {M : Type*} [add_comm_monoid M] (gf : α → M) (g : β → M)
(s : finset α) (t : finset β)
(hf : ∀ x ∈ s, f x ∈ t) (hgf : ∀ x ∈ s, gf x = g (f x)) (n : ℕ)
(hcard : ∀ y ∈ t, (s.filter (λ x, f x = y)).card = n) :
∑ x in s, gf x = n • (∑ y in t, g y) :=
calc ∑ x in s, gf x = ∑ x in s, g (f x) : finset.sum_congr rfl hgf
... = ∑ y in finset.image f s, (s.filter (λ x, f x = y)).card • g y : finset.sum_comp g f
... = ∑ y in t, (s.filter (λ x, f x = y)).card • g y :
finset.sum_subset
(λ y hy, by { rcases finset.mem_image.mp hy with ⟨x, hx, rfl⟩, exact hf x hx })
(λ y hyt hys, (by { have := mt (finset.fiber_card_ne_zero_iff_mem_image _ _ _).mp hys,
rw [ne.def, not_not] at this,
rw [this, zero_smul] }))
... = ∑ y in t, n • g y : finset.sum_congr rfl (λ y hy, by rw hcard y hy)
... = n • ∑ y in t, g y : finset.smul_sum.symm
lemma adjoin_root.nontrivial {R : Type*} [integral_domain R]
{f : polynomial R} (hf : 0 < degree f) :
nontrivial (adjoin_root f) :=
⟨⟨0, 1, λ h,
begin
apply not_le_of_gt (nat_degree_pos_iff_degree_pos.mpr hf),
simpa using nat_degree_le_of_dvd ((adjoin_root.mk_eq_mk _ _ _).mp h) (by simp),
end ⟩⟩
/-- Algebra homomorphism `F⟮α⟯ →ₐ[F] K` are in bijection with the set of roots
of `minpoly α` in `K`. -/
noncomputable def power_basis.alg_hom_adjoin_equiv (pb : power_basis K L) :
(L →ₐ[K] F) ≃ {x // x ∈ (pb.minpoly_gen.map (algebra_map K F)).roots} :=
begin
haveI : nontrivial (adjoin_root pb.minpoly_gen) :=
adjoin_root.nontrivial pb.degree_minpoly_gen_pos,
let ϕ := (adjoin_root.power_basis pb.minpoly_gen_ne_zero).equiv pb _,
{ let swap1 : (L →ₐ[K] F) ≃ (adjoin_root pb.minpoly_gen →ₐ[K] F) :=
{ to_fun := λ f, f.comp ϕ.to_alg_hom,
inv_fun := λ f, f.comp ϕ.symm.to_alg_hom,
left_inv := λ _, by { ext, simp only [alg_equiv.coe_alg_hom,
alg_equiv.to_alg_hom_eq_coe, alg_hom.comp_apply, alg_equiv.apply_symm_apply]},
right_inv := λ _, by { ext, simp only [alg_equiv.symm_apply_apply,
alg_equiv.coe_alg_hom, alg_equiv.to_alg_hom_eq_coe, alg_hom.comp_apply] } },
let swap2 := adjoin_root.equiv K F pb.minpoly_gen pb.minpoly_gen_ne_zero,
exact swap1.trans swap2 },
rw [adjoin_root.minpoly_gen_eq _ pb.minpoly_gen_monic],
{ rw pb.minpoly_gen_eq, exact minpoly.irreducible pb.is_integral_gen }
end
-- generalizes card_alg_hom_adjoin_integral
-- TODO: merge this with the field.adjoin version
lemma power_basis.card_alg_hom (pb : power_basis K L)
(h_sep : pb.minpoly_gen.separable)
(h_splits : pb.minpoly_gen.splits (algebra_map K F)) :
@fintype.card (L →ₐ[K] F) pb.fintype_alg_hom = pb.dim :=
begin
classical,
let s := (pb.minpoly_gen.map (algebra_map K F)).roots.to_finset,
have H := λ x, multiset.mem_to_finset,
rw [fintype.card_congr pb.alg_hom_adjoin_equiv, fintype.card_of_subtype s H,
multiset.to_finset_card_of_nodup, ← nat_degree_eq_card_roots h_splits,
pb.nat_degree_minpoly_gen],
exact polynomial.nodup_roots h_sep.map
end
lemma polynomial.splits_of_is_alg_closed (L : Type*) [field L] [algebra K L]
[is_alg_closed L] (f : polynomial K) :
f.splits (algebra_map K L) :=
begin
convert (splits_map_iff _ (ring_hom.id L)).mp (f.map (algebra_map K L)).splits',
exact (ring_hom.id_comp _).symm
end
lemma alg_hom.to_linear_map_injective :
function.injective (alg_hom.to_linear_map : (L →ₐ[K] F) → (L →ₗ[K] F)) :=
λ f g h, alg_hom.ext (λ x, by rw [← f.to_linear_map_apply, h, g.to_linear_map_apply])
lemma power_basis.alg_hom_ext (pb : power_basis K L) (f g : L →ₐ[K] F)
(h : f pb.gen = g pb.gen) : f = g :=
alg_hom.to_linear_map_injective (pb.is_basis.ext (λ i,
by rw [f.to_linear_map_apply, g.to_linear_map_apply, alg_hom.map_pow, alg_hom.map_pow, h]))
lemma is_scalar_tower.restrict_base_injective {A B : Type*}
[semiring A] [semiring B]
[algebra R A] [algebra S A] [algebra R B] [algebra S B]
[is_scalar_tower R S A] [is_scalar_tower R S B] :
function.injective (is_scalar_tower.restrict_base R : (A →ₐ[S] B) → (A →ₐ[R] B)) :=
λ f g h, alg_hom.ext (λ x,
by rw [← is_scalar_tower.restrict_base_apply R f x, h, is_scalar_tower.restrict_base_apply])
@[simp] lemma intermediate_field.algebra_map_mk (S : intermediate_field K L)
{x : L} (hx : x ∈ S) : algebra_map S L ⟨x, hx⟩ = x := rfl
@[simp] lemma intermediate_field.algebra_map_algebra_map (S : intermediate_field K L)
[algebra S F] [is_scalar_tower K S F] (x : K) :
algebra_map S F ⟨algebra_map K L x, S.algebra_map_mem x⟩ = algebra_map K F x :=
by { rw [is_scalar_tower.algebra_map_apply K S F], refl }
/-- If `f` fixes `K` and `x`, then `f` fixes `K⟮x⟯`. -/
def intermediate_field.adjoin.extend_base (x : L) [algebra K⟮x⟯ F] [is_scalar_tower K K⟮x⟯ F]
(f : L →ₐ[K] F) (hf : f x = algebra_map _ _ (gen K x)) :
L →ₐ[K⟮x⟯] F :=
{ commutes' := begin
rintro ⟨r, hr⟩,
simp only [intermediate_field.algebra_map_mk, ring_hom.to_fun_eq_coe, alg_hom.coe_to_ring_hom],
suffices : ∃ hr, f r = algebra_map K⟮x⟯ F ⟨r, hr⟩,
{ obtain ⟨_, h⟩ := this,
exact h },
refine intermediate_field.adjoin_induction K hr _ _ _ _ _ _,
{ rintros x' (hx' | hx'), exact ⟨intermediate_field.subset_adjoin K _ H, hf⟩ },
{ rintros c,
use K⟮x⟯.algebra_map_mem c,
simp only [f.commutes],
apply (K⟮x⟯.algebra_map_algebra_map c).symm.trans _, assumption, assumption,
congr },
{ rintros a b ⟨ha, a_eq⟩ ⟨hb, b_eq⟩,
use K⟮x⟯.add_mem ha hb,
simp only [f.map_add, a_eq, b_eq, ← ring_hom.map_add],
congr },
{ rintros a ⟨ha, a_eq⟩,
use K⟮x⟯.neg_mem ha,
simp only [f.map_neg, a_eq, ← ring_hom.map_neg],
congr },
{ rintros a ⟨ha, a_eq⟩,
use K⟮x⟯.inv_mem ha,
simp only [f.map_inv, a_eq, ← ring_hom.map_inv],
congr },
{ rintros a b ⟨ha, a_eq⟩ ⟨hb, b_eq⟩,
use K⟮x⟯.mul_mem ha hb,
simp only [f.map_mul, a_eq, b_eq, ← ring_hom.map_mul],
congr },
end,
.. (f : L →+* F) }
@[simp]
lemma restrict_base_extend_base (x : L) [algebra K⟮x⟯ F] [is_scalar_tower K K⟮x⟯ F]
(f : L →ₐ[K] F) (hf : f x = algebra_map _ _ (gen K x)) :
is_scalar_tower.restrict_base K (intermediate_field.adjoin.extend_base x f hf) = f :=
by { ext, refl }
lemma card_filter_apply_eq [decidable_eq F] [is_alg_closed F]
[is_separable K L] [finite_dimensional K L]
(x : L) (hx : is_integral K x) (y : F)
(hy : aeval y ((intermediate_field.adjoin.power_basis hx).minpoly_gen) = 0) :
(finset.univ.filter (λ (σ : L →ₐ[K] F), σ x = y)).card = findim K⟮x⟯ L :=
begin
let pb : power_basis K L := field.power_basis_of_finite_of_separable K L,
let emb_y : K⟮x⟯ →ₐ[K] F := (intermediate_field.adjoin.power_basis hx).lift y hy,
letI : algebra K⟮x⟯ F := (emb_y : K⟮x⟯ →+* F).to_algebra,
haveI : is_scalar_tower K K⟮x⟯ F := is_scalar_tower.of_algebra_map_eq
(λ x, (emb_y.commutes x).symm),
have emb_y_gen : emb_y (adjoin_simple.gen K x) = y,
{ rw [← adjoin.power_basis.gen_eq hx, (intermediate_field.adjoin.power_basis hx).lift_gen] },
have algebra_map_gen : algebra_map _ F (adjoin_simple.gen K x) = y := emb_y_gen,
haveI sep_x : is_separable K⟮x⟯ L :=
is_separable_tower_top_of_is_separable K K⟮x⟯ L,
let pb_x : power_basis K⟮x⟯ L := field.power_basis_of_finite_of_separable _ L,
letI : fintype (L →ₐ[K⟮x⟯] F) := pb_x.fintype_alg_hom,
calc (finset.univ.filter (λ (σ : L →ₐ[K] F), σ x = y)).card
= fintype.card (L →ₐ[K⟮x⟯] F) :
(finset.card_congr (λ f _, is_scalar_tower.restrict_base K f) _ _ _).symm
... = pb_x.dim : pb_x.card_alg_hom _ _
... = findim ↥K⟮x⟯ L : pb_x.findim.symm,
{ intros f _,
simp only [finset.mem_filter, finset.mem_univ, true_and, is_scalar_tower.restrict_base_apply,
← adjoin_simple.algebra_map_gen K x, f.commutes, algebra_map_gen] },
{ intros f g _ _ h,
ext x,
rw is_scalar_tower.restrict_base_injective h },
{ intros f hf,
simp only [finset.mem_filter, finset.mem_univ, true_and] at hf,
refine ⟨intermediate_field.adjoin.extend_base _ f (hf.trans algebra_map_gen.symm),
finset.mem_univ _,
_⟩,
simp },
{ rw [pb_x.minpoly_gen_eq], apply is_separable.separable },
{ apply polynomial.splits_of_is_alg_closed },
end
lemma sum_embeddings_eq_findim_mul [is_alg_closed F]
[finite_dimensional K L] [hsep : is_separable K L]
{x : L} (hx : is_integral K x) :
∑ σ : L →ₐ[K] F, (σ x) = findim K⟮x⟯ L •
@finset.sum _ _ _ (@finset.univ _ (fintype_of_alg_hom_adjoin_integral _ hx))
(λ σ : ↥K⟮x⟯ →ₐ[K] F, σ (adjoin_simple.gen K x)) :=
begin
classical,
letI : fintype (K⟮x⟯ →ₐ[K] F) := fintype_of_alg_hom_adjoin_integral _ hx,
apply finset.sum_eq_card_smul (λ σ : L →ₐ[K] F, σ.comp (is_scalar_tower.to_alg_hom K K⟮x⟯ L)),
{ intros, apply finset.mem_univ },
{ intros σ hσ,
simp only [alg_hom.comp_apply, is_scalar_tower.to_alg_hom_apply, algebra_map_gen] },
intros σ' _,
rw ← card_filter_apply_eq x hx (σ' (adjoin_simple.gen K x)),
apply finset.card_congr (λ σ _, σ),
{ intros σ hσ,
simp only [finset.mem_filter, finset.mem_univ, true_and] at ⊢ hσ,
simp only [← hσ, alg_hom.comp_apply, is_scalar_tower.to_alg_hom_apply, algebra_map_gen] },
{ intros σ τ hσ hτ h,
exact h },
{ intros σ hσ,
refine ⟨σ, _, rfl⟩,
simp only [finset.mem_filter, finset.mem_univ, true_and] at ⊢ hσ,
apply (intermediate_field.adjoin.power_basis hx).alg_hom_ext,
simp only [← hσ, alg_hom.comp_apply, is_scalar_tower.to_alg_hom_apply,
intermediate_field.adjoin.power_basis.gen_eq, algebra_map_gen] },
{ rw [aeval_alg_hom, alg_hom.comp_apply, ← intermediate_field.adjoin.power_basis.gen_eq,
(intermediate_field.adjoin.power_basis hx).aeval_minpoly_gen, σ'.map_zero] }
end
section
lemma power_basis.sum_embeddings_gen [is_separable K L] (f : F → R) :
∑ σ in (@finset.univ _ (@alg_hom.fintype_of_separable _ _ _ _ _ _ _ _ _
pb.finite_dimensional)),
f (σ pb.gen) =
((pb.minpoly_gen.map (algebra_map K F)).roots.map f).sum :=
begin
haveI := pb.finite_dimensional,
haveI : fintype (↥K⟮pb.gen⟯ →ₐ[K] F) :=
fintype_of_alg_hom_adjoin_integral _ pb.is_integral_gen,
convert sum_embeddings_gen pb.is_integral_gen _ f using 1,
{ rw finset.sum_equiv (alg_hom_congr_left F pb.equiv_adjoin_simple.symm),
convert finset.sum_congr rfl (λ x _, _),
rw [alg_hom_congr_left_symm_apply, power_basis.equiv_adjoin_simple_symm_gen] },
{ rw pb.minpoly_gen_eq },
{ apply is_separable.separable }
end
lemma power_basis.trace_gen_eq_sum_embeddings [is_separable K L]
(hF : pb.minpoly_gen.splits (algebra_map K F)) :
algebra_map K F (algebra.trace K L pb.gen) =
∑ σ in (@finset.univ _
(@alg_hom.fintype_of_separable _ _ _ _ _ F _ _ _ pb.finite_dimensional)),
σ pb.gen :=
by simp only [pb.trace_gen_eq_sum_roots hF, pb.sum_embeddings_gen (λ x, x), multiset.map_id']
end
section
variables (K)
-- TODO: go via `power_basis` instead of adjoin K x
lemma trace_eq_sum_embeddings
[is_alg_closed F] [finite_dimensional K L] [is_separable K L]
{x : L} (hx : is_integral K x) :
algebra_map K F (algebra.trace K L x) = ∑ σ : L →ₐ[K] F, σ x :=
by { rw trace_eq_sum_embeddings_gen hx (is_separable.separable K x)
(polynomial.splits_of_is_alg_closed F _),
exact (sum_embeddings_eq_findim_mul hx).symm }
end
lemma algebraic_closure.splits (f : polynomial K) :
f.splits (algebra_map K (algebraic_closure K)) :=
f.splits_of_is_alg_closed (algebraic_closure K)
lemma trace_form_gen_pow_gen_pow
[is_alg_closed F] [is_separable K L] [finite_dimensional K L]
(i j : ℕ) :
algebra_map K F (trace_form K L (pb.gen ^ i) (pb.gen ^ j)) =
((pb.minpoly_gen.map (algebra_map K F)).roots.map (λ x, x ^ i * x ^ j)).sum :=
calc algebra_map K F (trace_form K L (pb.gen ^ i) (pb.gen ^ j))
= algebra_map K F (trace K L (pb.gen ^ (i + j))) : by rw [pow_add, trace_form_apply]
... = ∑ (σ : L →ₐ[K] F), σ (pb.gen ^ (i + j)) :
trace_eq_sum_embeddings _ (is_integral_pow _ pb.is_integral_gen)
... = ∑ (σ : L →ₐ[K] F), (σ pb.gen) ^ i * (σ pb.gen) ^ j :
by simp only [pow_add, alg_hom.map_mul, alg_hom.map_pow]
... = ((pb.minpoly_gen.map (algebra_map K F)).roots.map (λ x, x ^ i * x ^ j)).sum :
by rw ← pb.sum_embeddings_gen (λ x, x ^ i * x ^ j)
lemma conjugate_matrix_mul_conjugate_matrix [is_separable K L] :
(pb.conjugate_matrix (algebraic_closure.splits _)) ⬝
(pb.conjugate_matrix (algebraic_closure.splits _))ᵀ =
((bilin_form.to_matrix pb.is_basis (trace_form K L)).map
(algebra_map K (algebraic_closure K))) :=
begin
ext i k,
simp only [matrix.mul_apply, map_apply, trace_form_to_matrix_power_basis, transpose_apply,
power_basis.conjugate_matrix],
haveI := pb.finite_dimensional,
rw trace_eq_sum_embeddings K (is_integral_pow (i + k) pb.is_integral_gen),
{ simp only [← pow_add, alg_hom.map_pow],
refine trans (sum_conjugates pb (algebraic_closure.splits _) (λ x, x ^ (i + k : ℕ))) _,
exact (pb.sum_embeddings_gen (λ x, x ^ (i + k : ℕ))).symm },
{ apply algebraic_closure.is_alg_closed }
end
@[simp] lemma det_conjugate_matrix :
(pb.conjugate_matrix hF).det = ∏ (i : fin pb.dim),
∏ j in finset.univ.filter (λ (j : fin pb.dim), i < j),
(pb.conjugates hF j - pb.conjugates hF i) :=
matrix.det_vandermonde _
lemma sum_repr (x : S) : ∑ i, hb.repr x i • b i = x :=
begin
convert hb.total_repr x using 1,
rw finsupp.total_apply,
refine (finset.sum_subset (finset.subset_univ _) (λ i _ hi, _)).symm,
rw [finsupp.not_mem_support_iff.mp hi, zero_smul]
end
lemma lmul_one : lmul R S 1 = linear_map.id :=
by { ext, simp }
@[simp] lemma det_map {R S : Type*} [comm_ring R] [comm_ring S]
{n : Type*} [fintype n] [decidable_eq n] (f : R →+* S) (M : matrix n n R) :
(M.map f).det = f M.det :=
by { unfold det, simp only [f.map_sum, f.map_mul, f.map_prod, f.map_int_cast, map_apply] }
lemma det_trace_form_ne_zero' [is_separable K L] :
det (bilin_form.to_matrix pb.is_basis (trace_form K L)) ≠ 0 :=
begin
suffices : algebra_map K (algebraic_closure K)
(det (bilin_form.to_matrix pb.is_basis (trace_form K L))) ≠ 0,
{ refine mt (λ ht, _) this,
rw [ht, ring_hom.map_zero] },
have hF := algebraic_closure.splits _,
calc algebra_map K (algebraic_closure K) (det _)
= det (pb.conjugate_matrix hF ⬝ (pb.conjugate_matrix hF)ᵀ) : _
... = det (pb.conjugate_matrix hF) ^ 2 : by simp [pow_two]
... = (∏ (i : fin pb.dim), ∏ j in finset.univ.filter (λ (j : fin pb.dim), i < j),
(pb.conjugates hF j - pb.conjugates hF i)) ^ 2 : by rw det_conjugate_matrix pb
... ≠ 0 : _,
{ rw [← det_map, conjugate_matrix_mul_conjugate_matrix] },
{ simp only [pow_two, ne.def, mul_self_eq_zero, finset.prod_eq_zero_iff, not_exists, sub_eq_zero],
intros i _ j hj,
refine mt (λ hij, pb.conjugates_injective hF _ hij) (ne_of_lt (finset.mem_filter.mp hj).2).symm,
rw pb.minpoly_gen_eq,
exact is_separable.separable K pb.gen }
end
lemma det_transpose_mul_mul_self {n m : Type*} [fintype m] [fintype n]
[decidable_eq m] [decidable_eq n]
{A : matrix n n K} {B : matrix n m K} {C : matrix m n K} (hBC : B ⬝ C = 1) (hCB : C ⬝ B = 1) :
det (Bᵀ ⬝ A ⬝ B) = det (B ⬝ Bᵀ) * det A :=
begin
rw ← det_conjugate_aux hBC hCB,
calc (B ⬝ (Bᵀ ⬝ A ⬝ B) ⬝ C).det = ((B ⬝ Bᵀ) ⬝ (A ⬝ (B ⬝ C))).det : by simp only [matrix.mul_assoc]
... = ((B ⬝ Bᵀ) ⬝ A).det : by rw [hBC, matrix.mul_one]
... = det (B ⬝ Bᵀ) * det A : matrix.det_mul _ _
end
lemma det_trace_form_ne_zero [is_separable K L] [decidable_eq ι] {b : ι → L} (hb : is_basis K b) :
det (bilin_form.to_matrix hb (trace_form K L)) ≠ 0 :=
begin
haveI : finite_dimensional K L := finite_dimensional.of_fintype_basis hb,
let pb : power_basis K L := field.power_basis_of_finite_of_separable _ _,
have hph : pb.is_basis.to_matrix b ⬝ hb.to_matrix (λ i : fin pb.dim, pb.gen ^ (i : ℕ)) = 1,
{ apply (matrix.to_lin pb.is_basis pb.is_basis).injective,
rw [matrix.to_lin_mul pb.is_basis hb pb.is_basis, is_basis.to_lin_to_matrix,
is_basis.to_lin_to_matrix, id_comp, to_lin_one] },
have hhp : hb.to_matrix (λ i : fin pb.dim, pb.gen ^ (i : ℕ)) ⬝ pb.is_basis.to_matrix b = 1,
{ apply (matrix.to_lin hb hb).injective,
rw [matrix.to_lin_mul hb pb.is_basis hb, is_basis.to_lin_to_matrix, is_basis.to_lin_to_matrix,
id_comp, to_lin_one] },
rw [← bilin_form.to_matrix_basis_change hb pb.is_basis, det_transpose_mul_mul_self hph hhp],
apply mul_ne_zero (is_unit.ne_zero _) (det_trace_form_ne_zero' pb),
apply is_unit_det_of_left_inverse _ (_ᵀ ⬝ _),
rw [matrix.mul_assoc, ← matrix.mul_assoc _ (pb.is_basis.to_matrix b), hhp, matrix.one_mul,
← matrix.transpose_mul, hph, matrix.transpose_one],
end
end conjugates
end
end trace_eq_sum_roots
section dual_basis
open algebra
variables [decidable_eq ι] {b : ι → L} (hb : is_basis K b)
lemma nonsing_inv_det_zero (A : matrix ι ι K) (hA : det A = 0) :
A⁻¹ = 0 :=
begin
unfold has_inv.inv nonsing_inv,
rw [hA, dif_neg not_is_unit_zero],
apply_instance
end
lemma det_inv_ne_zero {A : matrix ι ι K} :
det (A⁻¹) ≠ 0 ↔ det A ≠ 0 :=
begin
by_cases hι : nonempty ι,
swap,
{ have : fintype.card ι = 0,
{ rw fintype.card_eq_zero_iff, exact λ i, hι ⟨i⟩ },
simp only [matrix.det_eq_one_of_card_eq_zero, matrix.det_eq_one_of_card_eq_zero this] },
by_cases hA : det A = 0,
{ simp [hA, nonsing_inv_det_zero A hA, matrix.det_zero hι] },
simp only [hA, ne.def, not_false_iff, iff_true],
exact is_unit_iff_ne_zero.mp (is_unit_nonsing_inv_det A (is_unit.mk0 _ hA)),
end
include hb
/-- If `pb` is a power basis for the finite separable field extension `L / K`,
`dual_basis pb` is another basis such that
`trace_form (pb.gen ^ i) (dual_basis pb j) = if i = j then 1 else 0`. -/
noncomputable def dual_basis : ι → L :=
λ i, matrix.to_lin hb hb
(bilin_form.to_matrix hb (trace_form K L))⁻¹ (b i)
lemma dual_basis_apply (i : ι) :
dual_basis hb i = matrix.to_lin hb hb
(bilin_form.to_matrix hb (trace_form K L))⁻¹ (b i) :=
rfl
lemma trace_form_dual_basis_power_basis [is_separable K L] (i j : ι) :
trace_form K L (b i) (dual_basis hb j) = (1 : matrix _ _ K) i j :=
calc trace_form K L (b i) (dual_basis hb j)
= ((bilin_form.to_matrix hb (trace_form K L)) ⬝
(bilin_form.to_matrix hb (trace_form K L))⁻¹) i j :
by simp_rw [dual_basis, ← bilin_form.comp_right_apply,
bilin_form.to_matrix_mul hb, bilin_form.to_matrix_apply]
... = (1 : matrix _ _ K) i j :
by rw matrix.mul_nonsing_inv _ (is_unit.mk0 _ (det_trace_form_ne_zero hb))
lemma trace_dual_basis_mul_power_basis [is_separable K L] (i j : ι) :
algebra.trace K L (b i * dual_basis hb j) = if i = j then 1 else 0 :=
trace_form_dual_basis_power_basis hb i j
lemma is_basis_dual_basis [is_separable K L] :
is_basis K (dual_basis hb) :=
let e : L ≃ₗ[K] L := linear_equiv.of_bijective
(matrix.to_lin hb hb (bilin_form.to_matrix hb (trace_form K L))⁻¹)
(matrix.ker_to_lin_eq_bot hb _ (det_inv_ne_zero.mpr (det_trace_form_ne_zero _)))
(matrix.range_to_lin_eq_top hb _ (det_inv_ne_zero.mpr (det_trace_form_ne_zero _)))
in
@linear_equiv.is_basis ι _ _ _ _ _ _ _ _ _ hb e
lemma trace_gen_pow_mul [is_separable K L] (x : L) (i : ι) :
algebra.trace K L (b i * x) = (is_basis_dual_basis hb).repr x i :=
begin
calc algebra.trace K L (b i * x)
= algebra.trace K L (b i * (∑ j, (is_basis_dual_basis hb).repr x j • dual_basis hb j)) :
by rw sum_repr
... = algebra.trace K L (∑ j, (is_basis_dual_basis hb).repr x j • (b i * dual_basis hb j)) :
by simp_rw [finset.mul_sum, mul_smul_comm]
... = ∑ j, (is_basis_dual_basis hb).repr x j • algebra.trace K L (b i * dual_basis hb j) :
by simp_rw [linear_map.map_sum, linear_map.map_smul]
... = (is_basis_dual_basis hb).repr x i * algebra.trace K L (b i * dual_basis hb i) :
finset.sum_eq_single _ _ _
... = (is_basis_dual_basis hb).repr x i :
by rw [trace_dual_basis_mul_power_basis, if_pos rfl, mul_one],
{ intros j _ ne,
rw [trace_dual_basis_mul_power_basis, if_neg ne.symm, smul_zero] },
{ intro not_mem_univ,
have := finset.mem_univ i,
contradiction }
end
end dual_basis
section trace_mem
open polynomial
variables {F : Type*} [field F] [algebra R L] [algebra L F] [algebra R F] [is_scalar_tower R L F]
lemma is_integral.nat_smul (n : ℕ) (x : F) (hx : is_integral R x) : is_integral R (n • x) :=
begin
rw [algebra.smul_def, is_scalar_tower.algebra_map_apply ℕ R F],
exact is_integral_mul is_integral_algebra_map hx,
end
lemma is_integral.multiset_sum (m : multiset F) :
(∀ x ∈ m, is_integral R x) → is_integral R m.sum :=
begin
refine m.induction _ _,
{ intros, simpa only [multiset.sum_zero] using is_integral_zero },
{ intros x m ih h,
simpa [multiset.sum_cons] using
is_integral_add
(h x (multiset.mem_cons_self x m))
(ih (λ x hx, h x (multiset.mem_cons.mpr (or.inr hx)))) }
end
lemma eval₂_dvd {R S : Type*} [semiring R] [comm_semiring S]
{f : R →+* S} {p q : polynomial R} {x : S}
(hpq : p ∣ q) : eval₂ f x p ∣ eval₂ f x q :=
begin
rcases hpq with ⟨q, rfl⟩,
exact ⟨eval₂ f x q, eval₂_mul f x⟩,
end
lemma eval₂_eq_zero_of_dvd_of_eval₂_eq_zero {R S : Type*} [semiring R] [comm_semiring S]
{f : R →+* S} {p q : polynomial R} {x : S}
(hpq : p ∣ q) (hxp : eval₂ f x p = 0) : eval₂ f x q = 0 :=
zero_dvd_iff.mp (dvd_trans (zero_dvd_iff.mpr hxp) (eval₂_dvd hpq))
lemma is_integral_trace [finite_dimensional L F] {x : F} (hx : is_integral R x) :
is_integral R (algebra.trace L F x) :=
begin
have hx' : is_integral L x := is_integral_of_is_scalar_tower _ hx,
letI : algebra L (algebraic_closure F) := ((algebra_map F _).comp (algebra_map _ F)).to_algebra,
letI : algebra R (algebraic_closure F) := ((algebra_map L _).comp (algebra_map _ L)).to_algebra,
letI : is_scalar_tower L F (algebraic_closure F) := is_scalar_tower.of_algebra_map_eq (λ x, rfl),
letI : is_scalar_tower R L (algebraic_closure F) := is_scalar_tower.of_algebra_map_eq (λ x, rfl),
apply (is_integral_algebra_map_iff (algebra_map L (algebraic_closure F)).injective).mp,
rw trace_eq_sum_roots hx',
{ apply is_integral.nat_smul,
apply is_integral.multiset_sum,
intros y hy,
rw mem_roots_map (minpoly.ne_zero hx') at hy,
use [minpoly R x, minpoly.monic hx],
rw [← aeval_def, is_scalar_tower.aeval_apply R L, aeval_def],
apply eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (minpoly.dvd L x _) hy,
rw ← is_scalar_tower.aeval_apply R L,
apply minpoly.aeval },
{ apply splits_of_is_alg_closed },
{ apply_instance }
end
end trace_mem
|
043b9e97d3c997c0c5ebf3b3373931d95ff1baf6 | 4950bf76e5ae40ba9f8491647d0b6f228ddce173 | /src/analysis/calculus/deriv.lean | 1a805cd277099626dbb7b0725d910e7c741cf8df | [
"Apache-2.0"
] | permissive | ntzwq/mathlib | ca50b21079b0a7c6781c34b62199a396dd00cee2 | 36eec1a98f22df82eaccd354a758ef8576af2a7f | refs/heads/master | 1,675,193,391,478 | 1,607,822,996,000 | 1,607,822,996,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 71,663 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel
-/
import analysis.calculus.fderiv
import data.polynomial.derivative
/-!
# One-dimensional derivatives
This file defines the derivative of a function `f : 𝕜 → F` where `𝕜` is a
normed field and `F` is a normed space over this field. The derivative of
such a function `f` at a point `x` is given by an element `f' : F`.
The theory is developed analogously to the [Fréchet
derivatives](./fderiv.lean). We first introduce predicates defined in terms
of the corresponding predicates for Fréchet derivatives:
- `has_deriv_at_filter f f' x L` states that the function `f` has the
derivative `f'` at the point `x` as `x` goes along the filter `L`.
- `has_deriv_within_at f f' s x` states that the function `f` has the
derivative `f'` at the point `x` within the subset `s`.
- `has_deriv_at f f' x` states that the function `f` has the derivative `f'`
at the point `x`.
- `has_strict_deriv_at f f' x` states that the function `f` has the derivative `f'`
at the point `x` in the sense of strict differentiability, i.e.,
`f y - f z = (y - z) • f' + o (y - z)` as `y, z → x`.
For the last two notions we also define a functional version:
- `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the
derivative does not exist, then `deriv_within f s x` equals zero.
- `deriv f x` is a derivative of `f` at `x`. If the derivative does not
exist, then `deriv f x` equals zero.
The theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the
one-dimensional derivatives coincide with the general Fréchet derivatives.
We also show the existence and compute the derivatives of:
- constants
- the identity function
- linear maps
- addition
- sum of finitely many functions
- negation
- subtraction
- multiplication
- inverse `x → x⁻¹`
- multiplication of two functions in `𝕜 → 𝕜`
- multiplication of a function in `𝕜 → 𝕜` and of a function in `𝕜 → E`
- composition of a function in `𝕜 → F` with a function in `𝕜 → 𝕜`
- composition of a function in `F → E` with a function in `𝕜 → F`
- inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)
- division
- polynomials
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,
and they more frequently lead to the desired result.
We set up the simplifier so that it can compute the derivative of simple functions. For instance,
```lean
example (x : ℝ) : deriv (λ x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=
by { simp, ring }
```
## Implementation notes
Most of the theorems are direct restatements of the corresponding theorems
for Fréchet derivatives.
The strategy to construct simp lemmas that give the simplifier the possibility to compute
derivatives is the same as the one for differentiability statements, as explained in `fderiv.lean`.
See the explanations there.
-/
universes u v w
noncomputable theory
open_locale classical topological_space big_operators filter
open filter asymptotics set
open continuous_linear_map (smul_right smul_right_one_eq_iff)
variables {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
section
variables {F : Type v} [normed_group F] [normed_space 𝕜 F]
variables {E : Type w} [normed_group E] [normed_space 𝕜 E]
/--
`f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges along the filter `L`.
-/
def has_deriv_at_filter (f : 𝕜 → F) (f' : F) (x : 𝕜) (L : filter 𝕜) :=
has_fderiv_at_filter f (smul_right 1 f' : 𝕜 →L[𝕜] F) x L
/--
`f` has the derivative `f'` at the point `x` within the subset `s`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def has_deriv_within_at (f : 𝕜 → F) (f' : F) (s : set 𝕜) (x : 𝕜) :=
has_deriv_at_filter f f' x (𝓝[s] x)
/--
`f` has the derivative `f'` at the point `x`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x`.
-/
def has_deriv_at (f : 𝕜 → F) (f' : F) (x : 𝕜) :=
has_deriv_at_filter f f' x (𝓝 x)
/-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability.
That is, `f y - f z = (y - z) • f' + o(y - z)` as `y, z → x`. -/
def has_strict_deriv_at (f : 𝕜 → F) (f' : F) (x : 𝕜) :=
has_strict_fderiv_at f (smul_right 1 f' : 𝕜 →L[𝕜] F) x
/--
Derivative of `f` at the point `x` within the set `s`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_within_at f f' s x`), then
`f x' = f x + (x' - x) • deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def deriv_within (f : 𝕜 → F) (s : set 𝕜) (x : 𝕜) :=
(fderiv_within 𝕜 f s x : 𝕜 →L[𝕜] F) 1
/--
Derivative of `f` at the point `x`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_at f f' x`), then
`f x' = f x + (x' - x) • deriv f x + o(x' - x)` where `x'` converges to `x`.
-/
def deriv (f : 𝕜 → F) (x : 𝕜) :=
(fderiv 𝕜 f x : 𝕜 →L[𝕜] F) 1
variables {f f₀ f₁ g : 𝕜 → F}
variables {f' f₀' f₁' g' : F}
variables {x : 𝕜}
variables {s t : set 𝕜}
variables {L L₁ L₂ : filter 𝕜}
/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/
lemma has_fderiv_at_filter_iff_has_deriv_at_filter {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at_filter f f' x L ↔ has_deriv_at_filter f (f' 1) x L :=
by simp [has_deriv_at_filter]
lemma has_fderiv_at_filter.has_deriv_at_filter {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at_filter f f' x L → has_deriv_at_filter f (f' 1) x L :=
has_fderiv_at_filter_iff_has_deriv_at_filter.mp
/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/
lemma has_fderiv_within_at_iff_has_deriv_within_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_within_at f f' s x ↔ has_deriv_within_at f (f' 1) s x :=
has_fderiv_at_filter_iff_has_deriv_at_filter
/-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/
lemma has_deriv_within_at_iff_has_fderiv_within_at {f' : F} :
has_deriv_within_at f f' s x ↔
has_fderiv_within_at f (smul_right 1 f' : 𝕜 →L[𝕜] F) s x :=
iff.rfl
lemma has_fderiv_within_at.has_deriv_within_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_within_at f f' s x → has_deriv_within_at f (f' 1) s x :=
has_fderiv_within_at_iff_has_deriv_within_at.mp
lemma has_deriv_within_at.has_fderiv_within_at {f' : F} :
has_deriv_within_at f f' s x → has_fderiv_within_at f (smul_right 1 f' : 𝕜 →L[𝕜] F) s x :=
has_deriv_within_at_iff_has_fderiv_within_at.mp
/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/
lemma has_fderiv_at_iff_has_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at f f' x ↔ has_deriv_at f (f' 1) x :=
has_fderiv_at_filter_iff_has_deriv_at_filter
lemma has_fderiv_at.has_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at f f' x → has_deriv_at f (f' 1) x :=
has_fderiv_at_iff_has_deriv_at.mp
lemma has_strict_fderiv_at_iff_has_strict_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_strict_fderiv_at f f' x ↔ has_strict_deriv_at f (f' 1) x :=
by simp [has_strict_deriv_at, has_strict_fderiv_at]
protected lemma has_strict_fderiv_at.has_strict_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_strict_fderiv_at f f' x → has_strict_deriv_at f (f' 1) x :=
has_strict_fderiv_at_iff_has_strict_deriv_at.mp
/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/
lemma has_deriv_at_iff_has_fderiv_at {f' : F} :
has_deriv_at f f' x ↔
has_fderiv_at f (smul_right 1 f' : 𝕜 →L[𝕜] F) x :=
iff.rfl
lemma deriv_within_zero_of_not_differentiable_within_at
(h : ¬ differentiable_within_at 𝕜 f s x) : deriv_within f s x = 0 :=
by { unfold deriv_within, rw fderiv_within_zero_of_not_differentiable_within_at, simp, assumption }
lemma deriv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : deriv f x = 0 :=
by { unfold deriv, rw fderiv_zero_of_not_differentiable_at, simp, assumption }
theorem unique_diff_within_at.eq_deriv (s : set 𝕜) (H : unique_diff_within_at 𝕜 s x)
(h : has_deriv_within_at f f' s x) (h₁ : has_deriv_within_at f f₁' s x) : f' = f₁' :=
smul_right_one_eq_iff.mp $ unique_diff_within_at.eq H h h₁
theorem has_deriv_at_filter_iff_tendsto :
has_deriv_at_filter f f' x L ↔
tendsto (λ x' : 𝕜, ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) L (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_within_at_iff_tendsto : has_deriv_within_at f f' s x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (𝓝[s] x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_at_iff_tendsto : has_deriv_at f f' x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (𝓝 x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_strict_deriv_at.has_deriv_at (h : has_strict_deriv_at f f' x) :
has_deriv_at f f' x :=
h.has_fderiv_at
/-- If the domain has dimension one, then Fréchet derivative is equivalent to the classical
definition with a limit. In this version we have to take the limit along the subset `-{x}`,
because for `y=x` the slope equals zero due to the convention `0⁻¹=0`. -/
lemma has_deriv_at_filter_iff_tendsto_slope {x : 𝕜} {L : filter 𝕜} :
has_deriv_at_filter f f' x L ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') :=
begin
conv_lhs { simp only [has_deriv_at_filter_iff_tendsto, (normed_field.norm_inv _).symm,
(norm_smul _ _).symm, tendsto_zero_iff_norm_tendsto_zero.symm] },
conv_rhs { rw [← nhds_translation f', tendsto_comap_iff] },
refine (tendsto_inf_principal_nhds_iff_of_forall_eq $ by simp).symm.trans (tendsto_congr' _),
refine (eventually_principal.2 $ λ z hz, _).filter_mono inf_le_right,
simp only [(∘)],
rw [smul_sub, ← mul_smul, inv_mul_cancel (sub_ne_zero.2 hz), one_smul]
end
lemma has_deriv_within_at_iff_tendsto_slope {x : 𝕜} {s : set 𝕜} :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[s \ {x}] x) (𝓝 f') :=
begin
simp only [has_deriv_within_at, nhds_within, diff_eq, inf_assoc.symm, inf_principal.symm],
exact has_deriv_at_filter_iff_tendsto_slope
end
lemma has_deriv_within_at_iff_tendsto_slope' {x : 𝕜} {s : set 𝕜} (hs : x ∉ s) :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[s] x) (𝓝 f') :=
begin
convert ← has_deriv_within_at_iff_tendsto_slope,
exact diff_singleton_eq_self hs
end
lemma has_deriv_at_iff_tendsto_slope {x : 𝕜} :
has_deriv_at f f' x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[{x}ᶜ] x) (𝓝 f') :=
has_deriv_at_filter_iff_tendsto_slope
theorem has_deriv_at_iff_is_o_nhds_zero : has_deriv_at f f' x ↔
is_o (λh, f (x + h) - f x - h • f') (λh, h) (𝓝 0) :=
has_fderiv_at_iff_is_o_nhds_zero
theorem has_deriv_at_filter.mono (h : has_deriv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) :
has_deriv_at_filter f f' x L₁ :=
has_fderiv_at_filter.mono h hst
theorem has_deriv_within_at.mono (h : has_deriv_within_at f f' t x) (hst : s ⊆ t) :
has_deriv_within_at f f' s x :=
has_fderiv_within_at.mono h hst
theorem has_deriv_at.has_deriv_at_filter (h : has_deriv_at f f' x) (hL : L ≤ 𝓝 x) :
has_deriv_at_filter f f' x L :=
has_fderiv_at.has_fderiv_at_filter h hL
theorem has_deriv_at.has_deriv_within_at
(h : has_deriv_at f f' x) : has_deriv_within_at f f' s x :=
has_fderiv_at.has_fderiv_within_at h
lemma has_deriv_within_at.differentiable_within_at (h : has_deriv_within_at f f' s x) :
differentiable_within_at 𝕜 f s x :=
has_fderiv_within_at.differentiable_within_at h
lemma has_deriv_at.differentiable_at (h : has_deriv_at f f' x) : differentiable_at 𝕜 f x :=
has_fderiv_at.differentiable_at h
@[simp] lemma has_deriv_within_at_univ : has_deriv_within_at f f' univ x ↔ has_deriv_at f f' x :=
has_fderiv_within_at_univ
theorem has_deriv_at_unique
(h₀ : has_deriv_at f f₀' x) (h₁ : has_deriv_at f f₁' x) : f₀' = f₁' :=
smul_right_one_eq_iff.mp $ has_fderiv_at_unique h₀ h₁
lemma has_deriv_within_at_inter' (h : t ∈ 𝓝[s] x) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter' h
lemma has_deriv_within_at_inter (h : t ∈ 𝓝 x) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter h
lemma has_deriv_within_at.union (hs : has_deriv_within_at f f' s x) (ht : has_deriv_within_at f f' t x) :
has_deriv_within_at f f' (s ∪ t) x :=
begin
simp only [has_deriv_within_at, nhds_within_union],
exact hs.join ht,
end
lemma has_deriv_within_at.nhds_within (h : has_deriv_within_at f f' s x)
(ht : s ∈ 𝓝[t] x) : has_deriv_within_at f f' t x :=
(has_deriv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
lemma has_deriv_within_at.has_deriv_at (h : has_deriv_within_at f f' s x) (hs : s ∈ 𝓝 x) :
has_deriv_at f f' x :=
has_fderiv_within_at.has_fderiv_at h hs
lemma differentiable_within_at.has_deriv_within_at (h : differentiable_within_at 𝕜 f s x) :
has_deriv_within_at f (deriv_within f s x) s x :=
show has_fderiv_within_at _ _ _ _, by { convert h.has_fderiv_within_at, simp [deriv_within] }
lemma differentiable_at.has_deriv_at (h : differentiable_at 𝕜 f x) : has_deriv_at f (deriv f x) x :=
show has_fderiv_at _ _ _, by { convert h.has_fderiv_at, simp [deriv] }
lemma has_deriv_at.deriv (h : has_deriv_at f f' x) : deriv f x = f' :=
has_deriv_at_unique h.differentiable_at.has_deriv_at h
lemma has_deriv_within_at.deriv_within
(h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within f s x = f' :=
hxs.eq_deriv _ h.differentiable_within_at.has_deriv_within_at h
lemma fderiv_within_deriv_within : (fderiv_within 𝕜 f s x : 𝕜 → F) 1 = deriv_within f s x :=
rfl
lemma deriv_within_fderiv_within :
smul_right 1 (deriv_within f s x) = fderiv_within 𝕜 f s x :=
by simp [deriv_within]
lemma fderiv_deriv : (fderiv 𝕜 f x : 𝕜 → F) 1 = deriv f x :=
rfl
lemma deriv_fderiv :
smul_right 1 (deriv f x) = fderiv 𝕜 f x :=
by simp [deriv]
lemma differentiable_at.deriv_within (h : differentiable_at 𝕜 f x)
(hxs : unique_diff_within_at 𝕜 s x) : deriv_within f s x = deriv f x :=
by { unfold deriv_within deriv, rw h.fderiv_within hxs }
lemma deriv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f t x) :
deriv_within f s x = deriv_within f t x :=
((differentiable_within_at.has_deriv_within_at h).mono st).deriv_within ht
@[simp] lemma deriv_within_univ : deriv_within f univ = deriv f :=
by { ext, unfold deriv_within deriv, rw fderiv_within_univ }
lemma deriv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) :
deriv_within f (s ∩ t) x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_inter ht hs }
lemma deriv_within_of_open (hs : is_open s) (hx : x ∈ s) :
deriv_within f s x = deriv f x :=
by { unfold deriv_within, rw fderiv_within_of_open hs hx, refl }
section congr
/-! ### Congruence properties of derivatives -/
theorem filter.eventually_eq.has_deriv_at_filter_iff
(h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') :
has_deriv_at_filter f₀ f₀' x L ↔ has_deriv_at_filter f₁ f₁' x L :=
h₀.has_fderiv_at_filter_iff hx (by simp [h₁])
lemma has_deriv_at_filter.congr_of_eventually_eq (h : has_deriv_at_filter f f' x L)
(hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_deriv_at_filter f₁ f' x L :=
by rwa hL.has_deriv_at_filter_iff hx rfl
lemma has_deriv_within_at.congr_mono (h : has_deriv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : has_deriv_within_at f₁ f' t x :=
has_fderiv_within_at.congr_mono h ht hx h₁
lemma has_deriv_within_at.congr (h : has_deriv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
h.congr_mono hs hx (subset.refl _)
lemma has_deriv_within_at.congr_of_eventually_eq (h : has_deriv_within_at f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
has_deriv_at_filter.congr_of_eventually_eq h h₁ hx
lemma has_deriv_at.congr_of_eventually_eq (h : has_deriv_at f f' x)
(h₁ : f₁ =ᶠ[𝓝 x] f) : has_deriv_at f₁ f' x :=
has_deriv_at_filter.congr_of_eventually_eq h h₁ (mem_of_nhds h₁ : _)
lemma filter.eventually_eq.deriv_within_eq (hs : unique_diff_within_at 𝕜 s x)
(hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw hL.fderiv_within_eq hs hx }
lemma deriv_within_congr (hs : unique_diff_within_at 𝕜 s x)
(hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_congr hs hL hx }
lemma filter.eventually_eq.deriv_eq (hL : f₁ =ᶠ[𝓝 x] f) : deriv f₁ x = deriv f x :=
by { unfold deriv, rwa filter.eventually_eq.fderiv_eq }
end congr
section id
/-! ### Derivative of the identity -/
variables (s x L)
theorem has_deriv_at_filter_id : has_deriv_at_filter id 1 x L :=
(has_fderiv_at_filter_id x L).has_deriv_at_filter
theorem has_deriv_within_at_id : has_deriv_within_at id 1 s x :=
has_deriv_at_filter_id _ _
theorem has_deriv_at_id : has_deriv_at id 1 x :=
has_deriv_at_filter_id _ _
theorem has_deriv_at_id' : has_deriv_at (λ (x : 𝕜), x) 1 x :=
has_deriv_at_filter_id _ _
theorem has_strict_deriv_at_id : has_strict_deriv_at id 1 x :=
(has_strict_fderiv_at_id x).has_strict_deriv_at
lemma deriv_id : deriv id x = 1 :=
has_deriv_at.deriv (has_deriv_at_id x)
@[simp] lemma deriv_id' : deriv (@id 𝕜) = λ _, 1 :=
funext deriv_id
@[simp] lemma deriv_id'' : deriv (λ x : 𝕜, x) x = 1 :=
deriv_id x
lemma deriv_within_id (hxs : unique_diff_within_at 𝕜 s x) : deriv_within id s x = 1 :=
(has_deriv_within_at_id x s).deriv_within hxs
end id
section const
/-! ### Derivative of constant functions -/
variables (c : F) (s x L)
theorem has_deriv_at_filter_const : has_deriv_at_filter (λ x, c) 0 x L :=
(has_fderiv_at_filter_const c x L).has_deriv_at_filter
theorem has_strict_deriv_at_const : has_strict_deriv_at (λ x, c) 0 x :=
(has_strict_fderiv_at_const c x).has_strict_deriv_at
theorem has_deriv_within_at_const : has_deriv_within_at (λ x, c) 0 s x :=
has_deriv_at_filter_const _ _ _
theorem has_deriv_at_const : has_deriv_at (λ x, c) 0 x :=
has_deriv_at_filter_const _ _ _
lemma deriv_const : deriv (λ x, c) x = 0 :=
has_deriv_at.deriv (has_deriv_at_const x c)
@[simp] lemma deriv_const' : deriv (λ x:𝕜, c) = λ x, 0 :=
funext (λ x, deriv_const x c)
lemma deriv_within_const (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (λ x, c) s x = 0 :=
(has_deriv_within_at_const _ _ _).deriv_within hxs
end const
section continuous_linear_map
/-! ### Derivative of continuous linear maps -/
variables (e : 𝕜 →L[𝕜] F)
lemma continuous_linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.has_fderiv_at_filter.has_deriv_at_filter
lemma continuous_linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.has_strict_fderiv_at.has_strict_deriv_at
lemma continuous_linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
lemma continuous_linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] lemma continuous_linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
lemma continuous_linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end continuous_linear_map
section linear_map
/-! ### Derivative of bundled linear maps -/
variables (e : 𝕜 →ₗ[𝕜] F)
lemma linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.to_continuous_linear_map₁.has_deriv_at_filter
lemma linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.to_continuous_linear_map₁.has_strict_deriv_at
lemma linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
lemma linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] lemma linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
lemma linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end linear_map
section add
/-! ### Derivative of the sum of two functions -/
theorem has_deriv_at_filter.add
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_at_filter (λ y, f y + g y) (f' + g') x L :=
by simpa using (hf.add hg).has_deriv_at_filter
theorem has_strict_deriv_at.add
(hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :
has_strict_deriv_at (λ y, f y + g y) (f' + g') x :=
by simpa using (hf.add hg).has_strict_deriv_at
theorem has_deriv_within_at.add
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ y, f y + g y) (f' + g') s x :=
hf.add hg
theorem has_deriv_at.add
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x + g x) (f' + g') x :=
hf.add hg
lemma deriv_within_add (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y + g y) s x = deriv_within f s x + deriv_within g s x :=
(hf.has_deriv_within_at.add hg.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λy, f y + g y) x = deriv f x + deriv g x :=
(hf.has_deriv_at.add hg.has_deriv_at).deriv
theorem has_deriv_at_filter.add_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ y, f y + c) f' x L :=
add_zero f' ▸ hf.add (has_deriv_at_filter_const x L c)
theorem has_deriv_within_at.add_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ y, f y + c) f' s x :=
hf.add_const c
theorem has_deriv_at.add_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x + c) f' x :=
hf.add_const c
lemma deriv_within_add_const (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
deriv_within (λy, f y + c) s x = deriv_within f s x :=
(hf.has_deriv_within_at.add_const c).deriv_within hxs
lemma deriv_add_const (hf : differentiable_at 𝕜 f x) (c : F) :
deriv (λy, f y + c) x = deriv f x :=
(hf.has_deriv_at.add_const c).deriv
theorem has_deriv_at_filter.const_add (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ y, c + f y) f' x L :=
zero_add f' ▸ (has_deriv_at_filter_const x L c).add hf
theorem has_deriv_within_at.const_add (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c + f y) f' s x :=
hf.const_add c
theorem has_deriv_at.const_add (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c + f x) f' x :=
hf.const_add c
lemma deriv_within_const_add (hxs : unique_diff_within_at 𝕜 s x)
(c : F) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λy, c + f y) s x = deriv_within f s x :=
(hf.has_deriv_within_at.const_add c).deriv_within hxs
lemma deriv_const_add (c : F) (hf : differentiable_at 𝕜 f x) :
deriv (λy, c + f y) x = deriv f x :=
(hf.has_deriv_at.const_add c).deriv
end add
section sum
/-! ### Derivative of a finite sum of functions -/
open_locale big_operators
variables {ι : Type*} {u : finset ι} {A : ι → (𝕜 → F)} {A' : ι → F}
theorem has_deriv_at_filter.sum (h : ∀ i ∈ u, has_deriv_at_filter (A i) (A' i) x L) :
has_deriv_at_filter (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x L :=
by simpa [continuous_linear_map.sum_apply] using (has_fderiv_at_filter.sum h).has_deriv_at_filter
theorem has_strict_deriv_at.sum (h : ∀ i ∈ u, has_strict_deriv_at (A i) (A' i) x) :
has_strict_deriv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
by simpa [continuous_linear_map.sum_apply] using (has_strict_fderiv_at.sum h).has_strict_deriv_at
theorem has_deriv_within_at.sum (h : ∀ i ∈ u, has_deriv_within_at (A i) (A' i) s x) :
has_deriv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x :=
has_deriv_at_filter.sum h
theorem has_deriv_at.sum (h : ∀ i ∈ u, has_deriv_at (A i) (A' i) x) :
has_deriv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
has_deriv_at_filter.sum h
lemma deriv_within_sum (hxs : unique_diff_within_at 𝕜 s x)
(h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :
deriv_within (λ y, ∑ i in u, A i y) s x = ∑ i in u, deriv_within (A i) s x :=
(has_deriv_within_at.sum (λ i hi, (h i hi).has_deriv_within_at)).deriv_within hxs
@[simp] lemma deriv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :
deriv (λ y, ∑ i in u, A i y) x = ∑ i in u, deriv (A i) x :=
(has_deriv_at.sum (λ i hi, (h i hi).has_deriv_at)).deriv
end sum
section mul_vector
/-! ### Derivative of the multiplication of a scalar function and a vector function -/
variables {c : 𝕜 → 𝕜} {c' : 𝕜}
theorem has_deriv_within_at.smul
(hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c y • f y) (c x • f' + c' • f x) s x :=
by simpa using (has_fderiv_within_at.smul hc hf).has_deriv_within_at
theorem has_deriv_at.smul
(hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c y • f y) (c x • f' + c' • f x) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul hf
end
theorem has_strict_deriv_at.smul
(hc : has_strict_deriv_at c c' x) (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ y, c y • f y) (c x • f' + c' • f x) x :=
by simpa using (hc.smul hf).has_strict_deriv_at
lemma deriv_within_smul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c y • f y) s x = c x • deriv_within f s x + (deriv_within c s x) • f x :=
(hc.has_deriv_within_at.smul hf.has_deriv_within_at).deriv_within hxs
lemma deriv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c y • f y) x = c x • deriv f x + (deriv c x) • f x :=
(hc.has_deriv_at.smul hf.has_deriv_at).deriv
theorem has_deriv_within_at.smul_const
(hc : has_deriv_within_at c c' s x) (f : F) :
has_deriv_within_at (λ y, c y • f) (c' • f) s x :=
begin
have := hc.smul (has_deriv_within_at_const x s f),
rwa [smul_zero, zero_add] at this
end
theorem has_deriv_at.smul_const
(hc : has_deriv_at c c' x) (f : F) :
has_deriv_at (λ y, c y • f) (c' • f) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul_const f
end
lemma deriv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
deriv_within (λ y, c y • f) s x = (deriv_within c s x) • f :=
(hc.has_deriv_within_at.smul_const f).deriv_within hxs
lemma deriv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
deriv (λ y, c y • f) x = (deriv c x) • f :=
(hc.has_deriv_at.smul_const f).deriv
theorem has_deriv_within_at.const_smul
(c : 𝕜) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c • f y) (c • f') s x :=
begin
convert (has_deriv_within_at_const x s c).smul hf,
rw [zero_smul, add_zero]
end
theorem has_deriv_at.const_smul (c : 𝕜) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c • f y) (c • f') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hf.const_smul c
end
lemma deriv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝕜) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c • f y) s x = c • deriv_within f s x :=
(hf.has_deriv_within_at.const_smul c).deriv_within hxs
lemma deriv_const_smul (c : 𝕜) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c • f y) x = c • deriv f x :=
(hf.has_deriv_at.const_smul c).deriv
end mul_vector
section neg
/-! ### Derivative of the negative of a function -/
theorem has_deriv_at_filter.neg (h : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, -f x) (-f') x L :=
by simpa using h.neg.has_deriv_at_filter
theorem has_deriv_within_at.neg (h : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, -f x) (-f') s x :=
h.neg
theorem has_deriv_at.neg (h : has_deriv_at f f' x) : has_deriv_at (λ x, -f x) (-f') x :=
h.neg
theorem has_strict_deriv_at.neg (h : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, -f x) (-f') x :=
by simpa using h.neg.has_strict_deriv_at
lemma deriv_within.neg (hxs : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f s x) :
deriv_within (λy, -f y) s x = - deriv_within f s x :=
h.has_deriv_within_at.neg.deriv_within hxs
lemma deriv.neg : deriv (λy, -f y) x = - deriv f x :=
if h : differentiable_at 𝕜 f x then h.has_deriv_at.neg.deriv else
have ¬differentiable_at 𝕜 (λ y, -f y) x, from λ h', by simpa only [neg_neg] using h'.neg,
by simp only [deriv_zero_of_not_differentiable_at h,
deriv_zero_of_not_differentiable_at this, neg_zero]
@[simp] lemma deriv.neg' : deriv (λy, -f y) = (λ x, - deriv f x) :=
funext $ λ x, deriv.neg
end neg
section neg2
/-! ### Derivative of the negation function (i.e `has_neg.neg`) -/
variables (s x L)
theorem has_deriv_at_filter_neg : has_deriv_at_filter has_neg.neg (-1) x L :=
has_deriv_at_filter.neg $ has_deriv_at_filter_id _ _
theorem has_deriv_within_at_neg : has_deriv_within_at has_neg.neg (-1) s x :=
has_deriv_at_filter_neg _ _
theorem has_deriv_at_neg : has_deriv_at has_neg.neg (-1) x :=
has_deriv_at_filter_neg _ _
theorem has_deriv_at_neg' : has_deriv_at (λ x, -x) (-1) x :=
has_deriv_at_filter_neg _ _
theorem has_strict_deriv_at_neg : has_strict_deriv_at has_neg.neg (-1) x :=
has_strict_deriv_at.neg $ has_strict_deriv_at_id _
lemma deriv_neg : deriv has_neg.neg x = -1 :=
has_deriv_at.deriv (has_deriv_at_neg x)
@[simp] lemma deriv_neg' : deriv (has_neg.neg : 𝕜 → 𝕜) = λ _, -1 :=
funext deriv_neg
@[simp] lemma deriv_neg'' : deriv (λ x : 𝕜, -x) x = -1 :=
deriv_neg x
lemma deriv_within_neg (hxs : unique_diff_within_at 𝕜 s x) : deriv_within has_neg.neg s x = -1 :=
(has_deriv_within_at_neg x s).deriv_within hxs
lemma differentiable_neg : differentiable 𝕜 (has_neg.neg : 𝕜 → 𝕜) :=
differentiable.neg differentiable_id
lemma differentiable_on_neg : differentiable_on 𝕜 (has_neg.neg : 𝕜 → 𝕜) s :=
differentiable_on.neg differentiable_on_id
end neg2
section sub
/-! ### Derivative of the difference of two functions -/
theorem has_deriv_at_filter.sub
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_at_filter (λ x, f x - g x) (f' - g') x L :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem has_deriv_within_at.sub
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ x, f x - g x) (f' - g') s x :=
hf.sub hg
theorem has_deriv_at.sub
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x - g x) (f' - g') x :=
hf.sub hg
theorem has_strict_deriv_at.sub
(hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :
has_strict_deriv_at (λ x, f x - g x) (f' - g') x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma deriv_within_sub (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y - g y) s x = deriv_within f s x - deriv_within g s x :=
(hf.has_deriv_within_at.sub hg.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λ y, f y - g y) x = deriv f x - deriv g x :=
(hf.has_deriv_at.sub hg.has_deriv_at).deriv
theorem has_deriv_at_filter.is_O_sub (h : has_deriv_at_filter f f' x L) :
is_O (λ x', f x' - f x) (λ x', x' - x) L :=
has_fderiv_at_filter.is_O_sub h
theorem has_deriv_at_filter.sub_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ x, f x - c) f' x L :=
by simpa only [sub_eq_add_neg] using hf.add_const (-c)
theorem has_deriv_within_at.sub_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ x, f x - c) f' s x :=
hf.sub_const c
theorem has_deriv_at.sub_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x - c) f' x :=
hf.sub_const c
lemma deriv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
deriv_within (λy, f y - c) s x = deriv_within f s x :=
(hf.has_deriv_within_at.sub_const c).deriv_within hxs
lemma deriv_sub_const (c : F) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, f y - c) x = deriv f x :=
(hf.has_deriv_at.sub_const c).deriv
theorem has_deriv_at_filter.const_sub (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, c - f x) (-f') x L :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_deriv_within_at.const_sub (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, c - f x) (-f') s x :=
hf.const_sub c
theorem has_deriv_at.const_sub (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c - f x) (-f') x :=
hf.const_sub c
lemma deriv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x)
(c : F) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λy, c - f y) s x = -deriv_within f s x :=
(hf.has_deriv_within_at.const_sub c).deriv_within hxs
lemma deriv_const_sub (c : F) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c - f y) x = -deriv f x :=
(hf.has_deriv_at.const_sub c).deriv
end sub
section continuous
/-! ### Continuity of a function admitting a derivative -/
theorem has_deriv_at_filter.tendsto_nhds
(hL : L ≤ 𝓝 x) (h : has_deriv_at_filter f f' x L) :
tendsto f L (𝓝 (f x)) :=
h.tendsto_nhds hL
theorem has_deriv_within_at.continuous_within_at
(h : has_deriv_within_at f f' s x) : continuous_within_at f s x :=
has_deriv_at_filter.tendsto_nhds inf_le_left h
theorem has_deriv_at.continuous_at (h : has_deriv_at f f' x) : continuous_at f x :=
has_deriv_at_filter.tendsto_nhds (le_refl _) h
end continuous
section cartesian_product
/-! ### Derivative of the cartesian product of two functions -/
variables {G : Type w} [normed_group G] [normed_space 𝕜 G]
variables {f₂ : 𝕜 → G} {f₂' : G}
lemma has_deriv_at_filter.prod
(hf₁ : has_deriv_at_filter f₁ f₁' x L) (hf₂ : has_deriv_at_filter f₂ f₂' x L) :
has_deriv_at_filter (λ x, (f₁ x, f₂ x)) (f₁', f₂') x L :=
show has_fderiv_at_filter _ _ _ _,
by convert has_fderiv_at_filter.prod hf₁ hf₂
lemma has_deriv_within_at.prod
(hf₁ : has_deriv_within_at f₁ f₁' s x) (hf₂ : has_deriv_within_at f₂ f₂' s x) :
has_deriv_within_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') s x :=
hf₁.prod hf₂
lemma has_deriv_at.prod (hf₁ : has_deriv_at f₁ f₁' x) (hf₂ : has_deriv_at f₂ f₂' x) :
has_deriv_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') x :=
hf₁.prod hf₂
end cartesian_product
section composition
/-!
### Derivative of the composition of a vector function and a scalar function
We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`
in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also
because the `comp` version with the shorter name will show up much more often in applications).
The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to
usual multiplication in `comp` lemmas.
-/
variables {h h₁ h₂ : 𝕜 → 𝕜} {h' h₁' h₂' : 𝕜}
/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable (x)
theorem has_deriv_at_filter.scomp
(hg : has_deriv_at_filter g g' (h x) (L.map h))
(hh : has_deriv_at_filter h h' x L) :
has_deriv_at_filter (g ∘ h) (h' • g') x L :=
by simpa using (hg.comp x hh).has_deriv_at_filter
theorem has_deriv_within_at.scomp {t : set 𝕜}
(hg : has_deriv_within_at g g' t (h x))
(hh : has_deriv_within_at h h' s x) (hst : s ⊆ h ⁻¹' t) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
has_deriv_at_filter.scomp _ (has_deriv_at_filter.mono hg $
hh.continuous_within_at.tendsto_nhds_within hst) hh
/-- The chain rule. -/
theorem has_deriv_at.scomp
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_at h h' x) :
has_deriv_at (g ∘ h) (h' • g') x :=
(hg.mono hh.continuous_at).scomp x hh
theorem has_strict_deriv_at.scomp
(hg : has_strict_deriv_at g g' (h x)) (hh : has_strict_deriv_at h h' x) :
has_strict_deriv_at (g ∘ h) (h' • g') x :=
by simpa using (hg.comp x hh).has_strict_deriv_at
theorem has_deriv_at.scomp_has_deriv_within_at
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_within_at h h' s x) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
begin
rw ← has_deriv_within_at_univ at hg,
exact has_deriv_within_at.scomp x hg hh subset_preimage_univ
end
lemma deriv_within.scomp
(hg : differentiable_within_at 𝕜 g t (h x)) (hh : differentiable_within_at 𝕜 h s x)
(hs : s ⊆ h ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (g ∘ h) s x = deriv_within h s x • deriv_within g t (h x) :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact has_deriv_within_at.scomp x (hg.has_deriv_within_at) (hh.has_deriv_within_at) hs
end
lemma deriv.scomp
(hg : differentiable_at 𝕜 g (h x)) (hh : differentiable_at 𝕜 h x) :
deriv (g ∘ h) x = deriv h x • deriv g (h x) :=
begin
apply has_deriv_at.deriv,
exact has_deriv_at.scomp x hg.has_deriv_at hh.has_deriv_at
end
/-! ### Derivative of the composition of a scalar and vector functions -/
theorem has_deriv_at_filter.comp_has_fderiv_at_filter {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
{L : filter E} (hh₁ : has_deriv_at_filter h₁ h₁' (f x) (L.map f))
(hf : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (h₁ ∘ f) (h₁' • f') x L :=
by { convert has_fderiv_at_filter.comp x hh₁ hf, ext x, simp [mul_comm] }
theorem has_deriv_at.comp_has_fderiv_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
(hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_at f f' x) :
has_fderiv_at (h₁ ∘ f) (h₁' • f') x :=
(hh₁.mono hf.continuous_at).comp_has_fderiv_at_filter x hf
theorem has_deriv_at.comp_has_fderiv_within_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} {s} (x)
(hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x :=
(hh₁.mono hf.continuous_within_at).comp_has_fderiv_at_filter x hf
theorem has_deriv_within_at.comp_has_fderiv_within_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} {s t} (x)
(hh₁ : has_deriv_within_at h₁ h₁' t (f x)) (hf : has_fderiv_within_at f f' s x)
(hst : maps_to f s t) :
has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x :=
(has_deriv_at_filter.mono hh₁ $
hf.continuous_within_at.tendsto_nhds_within hst).comp_has_fderiv_at_filter x hf
/-! ### Derivative of the composition of two scalar functions -/
theorem has_deriv_at_filter.comp
(hh₁ : has_deriv_at_filter h₁ h₁' (h₂ x) (L.map h₂))
(hh₂ : has_deriv_at_filter h₂ h₂' x L) :
has_deriv_at_filter (h₁ ∘ h₂) (h₁' * h₂') x L :=
by { rw mul_comm, exact hh₁.scomp x hh₂ }
theorem has_deriv_within_at.comp {t : set 𝕜}
(hh₁ : has_deriv_within_at h₁ h₁' t (h₂ x))
(hh₂ : has_deriv_within_at h₂ h₂' s x) (hst : s ⊆ h₂ ⁻¹' t) :
has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=
by { rw mul_comm, exact hh₁.scomp x hh₂ hst, }
/-- The chain rule. -/
theorem has_deriv_at.comp
(hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_at h₂ h₂' x) :
has_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=
(hh₁.mono hh₂.continuous_at).comp x hh₂
theorem has_strict_deriv_at.comp
(hh₁ : has_strict_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_strict_deriv_at h₂ h₂' x) :
has_strict_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=
by { rw mul_comm, exact hh₁.scomp x hh₂ }
theorem has_deriv_at.comp_has_deriv_within_at
(hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_within_at h₂ h₂' s x) :
has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=
begin
rw ← has_deriv_within_at_univ at hh₁,
exact has_deriv_within_at.comp x hh₁ hh₂ subset_preimage_univ
end
lemma deriv_within.comp
(hh₁ : differentiable_within_at 𝕜 h₁ t (h₂ x)) (hh₂ : differentiable_within_at 𝕜 h₂ s x)
(hs : s ⊆ h₂ ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (h₁ ∘ h₂) s x = deriv_within h₁ t (h₂ x) * deriv_within h₂ s x :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact has_deriv_within_at.comp x (hh₁.has_deriv_within_at) (hh₂.has_deriv_within_at) hs
end
lemma deriv.comp
(hh₁ : differentiable_at 𝕜 h₁ (h₂ x)) (hh₂ : differentiable_at 𝕜 h₂ x) :
deriv (h₁ ∘ h₂) x = deriv h₁ (h₂ x) * deriv h₂ x :=
begin
apply has_deriv_at.deriv,
exact has_deriv_at.comp x hh₁.has_deriv_at hh₂.has_deriv_at
end
protected lemma has_deriv_at_filter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) :
has_deriv_at_filter (f^[n]) (f'^n) x L :=
begin
have := hf.iterate hL hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_deriv_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_at f f' x) (hx : f x = x) (n : ℕ) :
has_deriv_at (f^[n]) (f'^n) x :=
begin
have := has_fderiv_at.iterate hf hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_deriv_within_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) :
has_deriv_within_at (f^[n]) (f'^n) s x :=
begin
have := has_fderiv_within_at.iterate hf hx hs n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_strict_deriv_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_strict_deriv_at f f' x) (hx : f x = x) (n : ℕ) :
has_strict_deriv_at (f^[n]) (f'^n) x :=
begin
have := hf.iterate hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
end composition
section composition_vector
/-! ### Derivative of the composition of a function between vector spaces and of a function defined on `𝕜` -/
variables {l : F → E} {l' : F →L[𝕜] E}
variable (x)
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set
equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_within_at.comp_has_deriv_within_at {t : set F}
(hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x) (hst : s ⊆ f ⁻¹' t) :
has_deriv_within_at (l ∘ f) (l' (f')) s x :=
begin
rw has_deriv_within_at_iff_has_fderiv_within_at,
convert has_fderiv_within_at.comp x hl hf hst,
ext,
simp
end
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the
Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_at.comp_has_deriv_at
(hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) :
has_deriv_at (l ∘ f) (l' (f')) x :=
begin
rw has_deriv_at_iff_has_fderiv_at,
convert has_fderiv_at.comp x hl hf,
ext,
simp
end
theorem has_fderiv_at.comp_has_deriv_within_at
(hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (l ∘ f) (l' (f')) s x :=
begin
rw ← has_fderiv_within_at_univ at hl,
exact has_fderiv_within_at.comp_has_deriv_within_at x hl hf subset_preimage_univ
end
lemma fderiv_within.comp_deriv_within {t : set F}
(hl : differentiable_within_at 𝕜 l t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(hs : s ⊆ f ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (l ∘ f) s x = (fderiv_within 𝕜 l t (f x) : F → E) (deriv_within f s x) :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact (hl.has_fderiv_within_at).comp_has_deriv_within_at x (hf.has_deriv_within_at) hs
end
lemma fderiv.comp_deriv
(hl : differentiable_at 𝕜 l (f x)) (hf : differentiable_at 𝕜 f x) :
deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) :=
begin
apply has_deriv_at.deriv _,
exact (hl.has_fderiv_at).comp_has_deriv_at x (hf.has_deriv_at)
end
end composition_vector
section mul
/-! ### Derivative of the multiplication of two scalar functions -/
variables {c d : 𝕜 → 𝕜} {c' d' : 𝕜}
theorem has_deriv_within_at.mul
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c y * d y) (c' * d x + c x * d') s x :=
begin
convert hc.smul hd using 1,
rw [smul_eq_mul, smul_eq_mul, add_comm]
end
theorem has_deriv_at.mul (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c y * d y) (c' * d x + c x * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul hd
end
theorem has_strict_deriv_at.mul
(hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) :
has_strict_deriv_at (λ y, c y * d y) (c' * d x + c x * d') x :=
begin
convert hc.smul hd using 1,
rw [smul_eq_mul, smul_eq_mul, add_comm]
end
lemma deriv_within_mul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x :=
(hc.has_deriv_within_at.mul hd.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c y * d y) x = deriv c x * d x + c x * deriv d x :=
(hc.has_deriv_at.mul hd.has_deriv_at).deriv
theorem has_deriv_within_at.mul_const (hc : has_deriv_within_at c c' s x) (d : 𝕜) :
has_deriv_within_at (λ y, c y * d) (c' * d) s x :=
begin
convert hc.mul (has_deriv_within_at_const x s d),
rw [mul_zero, add_zero]
end
theorem has_deriv_at.mul_const (hc : has_deriv_at c c' x) (d : 𝕜) :
has_deriv_at (λ y, c y * d) (c' * d) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul_const d
end
lemma deriv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (d : 𝕜) :
deriv_within (λ y, c y * d) s x = deriv_within c s x * d :=
(hc.has_deriv_within_at.mul_const d).deriv_within hxs
lemma deriv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝕜) :
deriv (λ y, c y * d) x = deriv c x * d :=
(hc.has_deriv_at.mul_const d).deriv
theorem has_deriv_within_at.const_mul (c : 𝕜) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c * d y) (c * d') s x :=
begin
convert (has_deriv_within_at_const x s c).mul hd,
rw [zero_mul, zero_add]
end
theorem has_deriv_at.const_mul (c : 𝕜) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c * d y) (c * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hd.const_mul c
end
lemma deriv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝕜) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c * d y) s x = c * deriv_within d s x :=
(hd.has_deriv_within_at.const_mul c).deriv_within hxs
lemma deriv_const_mul (c : 𝕜) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c * d y) x = c * deriv d x :=
(hd.has_deriv_at.const_mul c).deriv
end mul
section inverse
/-! ### Derivative of `x ↦ x⁻¹` -/
theorem has_strict_deriv_at_inv (hx : x ≠ 0) : has_strict_deriv_at has_inv.inv (-(x^2)⁻¹) x :=
begin
suffices : is_o (λ p : 𝕜 × 𝕜, (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹))
(λ (p : 𝕜 × 𝕜), (p.1 - p.2) * 1) (𝓝 (x, x)),
{ refine this.congr' _ (eventually_of_forall $ λ _, mul_one _),
refine eventually.mono (mem_nhds_sets (is_open_ne.prod is_open_ne) ⟨hx, hx⟩) _,
rintro ⟨y, z⟩ ⟨hy, hz⟩,
simp only [mem_set_of_eq] at hy hz, -- hy : y ≠ 0, hz : z ≠ 0
field_simp [hx, hy, hz], ring, },
refine (is_O_refl (λ p : 𝕜 × 𝕜, p.1 - p.2) _).mul_is_o ((is_o_one_iff _).2 _),
rw [← sub_self (x * x)⁻¹],
exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv' $ mul_ne_zero hx hx)
end
theorem has_deriv_at_inv (x_ne_zero : x ≠ 0) :
has_deriv_at (λy, y⁻¹) (-(x^2)⁻¹) x :=
(has_strict_deriv_at_inv x_ne_zero).has_deriv_at
theorem has_deriv_within_at_inv (x_ne_zero : x ≠ 0) (s : set 𝕜) :
has_deriv_within_at (λx, x⁻¹) (-(x^2)⁻¹) s x :=
(has_deriv_at_inv x_ne_zero).has_deriv_within_at
lemma differentiable_at_inv (x_ne_zero : x ≠ 0) :
differentiable_at 𝕜 (λx, x⁻¹) x :=
(has_deriv_at_inv x_ne_zero).differentiable_at
lemma differentiable_within_at_inv (x_ne_zero : x ≠ 0) :
differentiable_within_at 𝕜 (λx, x⁻¹) s x :=
(differentiable_at_inv x_ne_zero).differentiable_within_at
lemma differentiable_on_inv : differentiable_on 𝕜 (λx:𝕜, x⁻¹) {x | x ≠ 0} :=
λx hx, differentiable_within_at_inv hx
lemma deriv_inv (x_ne_zero : x ≠ 0) :
deriv (λx, x⁻¹) x = -(x^2)⁻¹ :=
(has_deriv_at_inv x_ne_zero).deriv
lemma deriv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x⁻¹) s x = -(x^2)⁻¹ :=
begin
rw differentiable_at.deriv_within (differentiable_at_inv x_ne_zero) hxs,
exact deriv_inv x_ne_zero
end
lemma has_fderiv_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_at (λx, x⁻¹) (smul_right 1 (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x :=
has_deriv_at_inv x_ne_zero
lemma has_fderiv_within_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_within_at (λx, x⁻¹) (smul_right 1 (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) s x :=
(has_fderiv_at_inv x_ne_zero).has_fderiv_within_at
lemma fderiv_inv (x_ne_zero : x ≠ 0) :
fderiv 𝕜 (λx, x⁻¹) x = smul_right 1 (-(x^2)⁻¹) :=
(has_fderiv_at_inv x_ne_zero).fderiv
lemma fderiv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, x⁻¹) s x = smul_right 1 (-(x^2)⁻¹) :=
begin
rw differentiable_at.fderiv_within (differentiable_at_inv x_ne_zero) hxs,
exact fderiv_inv x_ne_zero
end
variables {c : 𝕜 → 𝕜} {c' : 𝕜}
lemma has_deriv_within_at.inv
(hc : has_deriv_within_at c c' s x) (hx : c x ≠ 0) :
has_deriv_within_at (λ y, (c y)⁻¹) (- c' / (c x)^2) s x :=
begin
convert (has_deriv_at_inv hx).comp_has_deriv_within_at x hc,
field_simp
end
lemma has_deriv_at.inv (hc : has_deriv_at c c' x) (hx : c x ≠ 0) :
has_deriv_at (λ y, (c y)⁻¹) (- c' / (c x)^2) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hc.inv hx
end
lemma differentiable_within_at.inv (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0) :
differentiable_within_at 𝕜 (λx, (c x)⁻¹) s x :=
(hc.has_deriv_within_at.inv hx).differentiable_within_at
@[simp] lemma differentiable_at.inv (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) :
differentiable_at 𝕜 (λx, (c x)⁻¹) x :=
(hc.has_deriv_at.inv hx).differentiable_at
lemma differentiable_on.inv (hc : differentiable_on 𝕜 c s) (hx : ∀ x ∈ s, c x ≠ 0) :
differentiable_on 𝕜 (λx, (c x)⁻¹) s :=
λx h, (hc x h).inv (hx x h)
@[simp] lemma differentiable.inv (hc : differentiable 𝕜 c) (hx : ∀ x, c x ≠ 0) :
differentiable 𝕜 (λx, (c x)⁻¹) :=
λx, (hc x).inv (hx x)
lemma deriv_within_inv' (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, (c x)⁻¹) s x = - (deriv_within c s x) / (c x)^2 :=
(hc.has_deriv_within_at.inv hx).deriv_within hxs
@[simp] lemma deriv_inv' (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) :
deriv (λx, (c x)⁻¹) x = - (deriv c x) / (c x)^2 :=
(hc.has_deriv_at.inv hx).deriv
end inverse
section division
/-! ### Derivative of `x ↦ c x / d x` -/
variables {c d : 𝕜 → 𝕜} {c' d' : 𝕜}
lemma has_deriv_within_at.div
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x ≠ 0) :
has_deriv_within_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) s x :=
begin
have A : (d x)⁻¹ * (d x)⁻¹ * (c' * d x) = (d x)⁻¹ * c',
by rw [← mul_assoc, mul_comm, ← mul_assoc, ← mul_assoc, mul_inv_cancel hx, one_mul],
convert hc.mul ((has_deriv_at_inv hx).comp_has_deriv_within_at x hd),
simp [div_eq_inv_mul, pow_two, mul_inv', mul_add, A, sub_eq_add_neg],
ring
end
lemma has_deriv_at.div (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x ≠ 0) :
has_deriv_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hc.div hd hx
end
lemma differentiable_within_at.div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0) :
differentiable_within_at 𝕜 (λx, c x / d x) s x :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).differentiable_within_at
@[simp] lemma differentiable_at.div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
differentiable_at 𝕜 (λx, c x / d x) x :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).differentiable_at
lemma differentiable_on.div
(hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) (hx : ∀ x ∈ s, d x ≠ 0) :
differentiable_on 𝕜 (λx, c x / d x) s :=
λx h, (hc x h).div (hd x h) (hx x h)
@[simp] lemma differentiable.div
(hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) (hx : ∀ x, d x ≠ 0) :
differentiable 𝕜 (λx, c x / d x) :=
λx, (hc x).div (hd x) (hx x)
lemma deriv_within_div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, c x / d x) s x
= ((deriv_within c s x) * d x - c x * (deriv_within d s x)) / (d x)^2 :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).deriv_within hxs
@[simp] lemma deriv_div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
deriv (λx, c x / d x) x = ((deriv c x) * d x - c x * (deriv d x)) / (d x)^2 :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).deriv
lemma differentiable_within_at.div_const (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜} :
differentiable_within_at 𝕜 (λx, c x / d) s x :=
by simp [div_eq_inv_mul, differentiable_within_at.const_mul, hc]
@[simp] lemma differentiable_at.div_const (hc : differentiable_at 𝕜 c x) {d : 𝕜} :
differentiable_at 𝕜 (λ x, c x / d) x :=
by simp [div_eq_inv_mul, hc]
lemma differentiable_on.div_const (hc : differentiable_on 𝕜 c s) {d : 𝕜} :
differentiable_on 𝕜 (λx, c x / d) s :=
by simp [div_eq_inv_mul, differentiable_on.const_mul, hc]
@[simp] lemma differentiable.div_const (hc : differentiable 𝕜 c) {d : 𝕜} :
differentiable 𝕜 (λx, c x / d) :=
by simp [div_eq_inv_mul, differentiable.const_mul, hc]
lemma deriv_within_div_const (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜}
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, c x / d) s x = (deriv_within c s x) / d :=
by simp [div_eq_inv_mul, deriv_within_const_mul, hc, hxs]
@[simp] lemma deriv_div_const (hc : differentiable_at 𝕜 c x) {d : 𝕜} :
deriv (λx, c x / d) x = (deriv c x) / d :=
by simp [div_eq_inv_mul, deriv_const_mul, hc]
end division
theorem has_strict_deriv_at.has_strict_fderiv_at_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜}
(hf : has_strict_deriv_at f f' x) (hf' : f' ≠ 0) :
has_strict_fderiv_at f
(continuous_linear_equiv.units_equiv_aut 𝕜 (units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x :=
hf
theorem has_deriv_at.has_fderiv_at_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜}
(hf : has_deriv_at f f' x) (hf' : f' ≠ 0) :
has_fderiv_at f
(continuous_linear_equiv.units_equiv_aut 𝕜 (units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x :=
hf
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a`
in the strict sense.
This is one of the easy parts of the inverse function theorem: it assumes that we already have an
inverse function. -/
theorem has_strict_deriv_at.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜}
(hg : continuous_at g a) (hf : has_strict_deriv_at f f' (g a)) (hf' : f' ≠ 0)
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_strict_deriv_at g f'⁻¹ a :=
(hf.has_strict_fderiv_at_equiv hf').of_local_left_inverse hg hfg
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem has_deriv_at.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜}
(hg : continuous_at g a) (hf : has_deriv_at f f' (g a)) (hf' : f' ≠ 0)
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_deriv_at g f'⁻¹ a :=
(hf.has_fderiv_at_equiv hf').of_local_left_inverse hg hfg
end
namespace polynomial
/-! ### Derivative of a polynomial -/
variables {x : 𝕜} {s : set 𝕜}
variable (p : polynomial 𝕜)
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected lemma has_strict_deriv_at (x : 𝕜) :
has_strict_deriv_at (λx, p.eval x) (p.derivative.eval x) x :=
begin
apply p.induction_on,
{ simp [has_strict_deriv_at_const] },
{ assume p q hp hq,
convert hp.add hq;
simp },
{ assume n a h,
convert h.mul (has_strict_deriv_at_id x),
{ ext y, simp [pow_add, mul_assoc] },
{ simp [pow_add], ring } }
end
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected lemma has_deriv_at (x : 𝕜) : has_deriv_at (λx, p.eval x) (p.derivative.eval x) x :=
(p.has_strict_deriv_at x).has_deriv_at
protected theorem has_deriv_within_at (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, p.eval x) (p.derivative.eval x) s x :=
(p.has_deriv_at x).has_deriv_within_at
protected lemma differentiable_at : differentiable_at 𝕜 (λx, p.eval x) x :=
(p.has_deriv_at x).differentiable_at
protected lemma differentiable_within_at : differentiable_within_at 𝕜 (λx, p.eval x) s x :=
p.differentiable_at.differentiable_within_at
protected lemma differentiable : differentiable 𝕜 (λx, p.eval x) :=
λx, p.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 (λx, p.eval x) s :=
p.differentiable.differentiable_on
@[simp] protected lemma deriv : deriv (λx, p.eval x) x = p.derivative.eval x :=
(p.has_deriv_at x).deriv
protected lemma deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, p.eval x) s x = p.derivative.eval x :=
begin
rw differentiable_at.deriv_within p.differentiable_at hxs,
exact p.deriv
end
protected lemma has_fderiv_at (x : 𝕜) :
has_fderiv_at (λx, p.eval x) (smul_right 1 (p.derivative.eval x) : 𝕜 →L[𝕜] 𝕜) x :=
by simpa [has_deriv_at_iff_has_fderiv_at] using p.has_deriv_at x
protected lemma has_fderiv_within_at (x : 𝕜) :
has_fderiv_within_at (λx, p.eval x) (smul_right 1 (p.derivative.eval x) : 𝕜 →L[𝕜] 𝕜) s x :=
(p.has_fderiv_at x).has_fderiv_within_at
@[simp] protected lemma fderiv : fderiv 𝕜 (λx, p.eval x) x = smul_right 1 (p.derivative.eval x) :=
(p.has_fderiv_at x).fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, p.eval x) s x = smul_right 1 (p.derivative.eval x) :=
begin
rw differentiable_at.fderiv_within p.differentiable_at hxs,
exact p.fderiv
end
end polynomial
section pow
/-! ### Derivative of `x ↦ x^n` for `n : ℕ` -/
variables {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜}
variable {n : ℕ }
lemma has_strict_deriv_at_pow (n : ℕ) (x : 𝕜) :
has_strict_deriv_at (λx, x^n) ((n : 𝕜) * x^(n-1)) x :=
begin
convert (polynomial.C (1 : 𝕜) * (polynomial.X)^n).has_strict_deriv_at x,
{ simp },
{ rw [polynomial.derivative_C_mul_X_pow], simp }
end
lemma has_deriv_at_pow (n : ℕ) (x : 𝕜) : has_deriv_at (λx, x^n) ((n : 𝕜) * x^(n-1)) x :=
(has_strict_deriv_at_pow n x).has_deriv_at
theorem has_deriv_within_at_pow (n : ℕ) (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, x^n) ((n : 𝕜) * x^(n-1)) s x :=
(has_deriv_at_pow n x).has_deriv_within_at
lemma differentiable_at_pow : differentiable_at 𝕜 (λx, x^n) x :=
(has_deriv_at_pow n x).differentiable_at
lemma differentiable_within_at_pow : differentiable_within_at 𝕜 (λx, x^n) s x :=
differentiable_at_pow.differentiable_within_at
lemma differentiable_pow : differentiable 𝕜 (λx:𝕜, x^n) :=
λx, differentiable_at_pow
lemma differentiable_on_pow : differentiable_on 𝕜 (λx, x^n) s :=
differentiable_pow.differentiable_on
lemma deriv_pow : deriv (λx, x^n) x = (n : 𝕜) * x^(n-1) :=
(has_deriv_at_pow n x).deriv
@[simp] lemma deriv_pow' : deriv (λx, x^n) = λ x, (n : 𝕜) * x^(n-1) :=
funext $ λ x, deriv_pow
lemma deriv_within_pow (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x^n) s x = (n : 𝕜) * x^(n-1) :=
(has_deriv_within_at_pow n x s).deriv_within hxs
lemma iter_deriv_pow' {k : ℕ} :
deriv^[k] (λx:𝕜, x^n) = λ x, (∏ i in finset.range k, (n - i) : ℕ) * x^(n-k) :=
begin
induction k with k ihk,
{ simp only [one_mul, finset.prod_range_zero, function.iterate_zero_apply, nat.sub_zero,
nat.cast_one] },
{ simp only [function.iterate_succ_apply', ihk, finset.prod_range_succ],
ext x,
rw [((has_deriv_at_pow (n - k) x).const_mul _).deriv, nat.cast_mul, mul_left_comm, mul_assoc,
nat.succ_eq_add_one, nat.sub_sub] }
end
lemma iter_deriv_pow {k : ℕ} :
deriv^[k] (λx:𝕜, x^n) x = (∏ i in finset.range k, (n - i) : ℕ) * x^(n-k) :=
congr_fun iter_deriv_pow' x
lemma has_deriv_within_at.pow (hc : has_deriv_within_at c c' s x) :
has_deriv_within_at (λ y, (c y)^n) ((n : 𝕜) * (c x)^(n-1) * c') s x :=
(has_deriv_at_pow n (c x)).comp_has_deriv_within_at x hc
lemma has_deriv_at.pow (hc : has_deriv_at c c' x) :
has_deriv_at (λ y, (c y)^n) ((n : 𝕜) * (c x)^(n-1) * c') x :=
by { rw ← has_deriv_within_at_univ at *, exact hc.pow }
lemma differentiable_within_at.pow (hc : differentiable_within_at 𝕜 c s x) :
differentiable_within_at 𝕜 (λx, (c x)^n) s x :=
hc.has_deriv_within_at.pow.differentiable_within_at
@[simp] lemma differentiable_at.pow (hc : differentiable_at 𝕜 c x) :
differentiable_at 𝕜 (λx, (c x)^n) x :=
hc.has_deriv_at.pow.differentiable_at
lemma differentiable_on.pow (hc : differentiable_on 𝕜 c s) :
differentiable_on 𝕜 (λx, (c x)^n) s :=
λx h, (hc x h).pow
@[simp] lemma differentiable.pow (hc : differentiable 𝕜 c) :
differentiable 𝕜 (λx, (c x)^n) :=
λx, (hc x).pow
lemma deriv_within_pow' (hc : differentiable_within_at 𝕜 c s x)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, (c x)^n) s x = (n : 𝕜) * (c x)^(n-1) * (deriv_within c s x) :=
hc.has_deriv_within_at.pow.deriv_within hxs
@[simp] lemma deriv_pow'' (hc : differentiable_at 𝕜 c x) :
deriv (λx, (c x)^n) x = (n : 𝕜) * (c x)^(n-1) * (deriv c x) :=
hc.has_deriv_at.pow.deriv
end pow
section fpow
/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/
variables {x : 𝕜} {s : set 𝕜}
variable {m : ℤ}
lemma has_strict_deriv_at_fpow (m : ℤ) (hx : x ≠ 0) :
has_strict_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
begin
have : ∀ m : ℤ, 0 < m → has_strict_deriv_at (λx, x^m) ((m:𝕜) * x^(m-1)) x,
{ assume m hm,
lift m to ℕ using (le_of_lt hm),
simp only [fpow_of_nat, int.cast_coe_nat],
convert has_strict_deriv_at_pow _ _ using 2,
rw [← int.coe_nat_one, ← int.coe_nat_sub, fpow_coe_nat],
norm_cast at hm,
exact nat.succ_le_of_lt hm },
rcases lt_trichotomy m 0 with hm|hm|hm,
{ have := (has_strict_deriv_at_inv _).scomp _ (this (-m) (neg_pos.2 hm));
[skip, exact fpow_ne_zero_of_ne_zero hx _],
simp only [(∘), fpow_neg, one_div, inv_inv', smul_eq_mul] at this,
convert this using 1,
rw [pow_two, mul_inv', inv_inv', int.cast_neg, ← neg_mul_eq_neg_mul, neg_mul_neg,
← fpow_add hx, mul_assoc, ← fpow_add hx], congr, abel },
{ simp only [hm, fpow_zero, int.cast_zero, zero_mul, has_strict_deriv_at_const] },
{ exact this m hm }
end
lemma has_deriv_at_fpow (m : ℤ) (hx : x ≠ 0) :
has_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
(has_strict_deriv_at_fpow m hx).has_deriv_at
theorem has_deriv_within_at_fpow (m : ℤ) (hx : x ≠ 0) (s : set 𝕜) :
has_deriv_within_at (λx, x^m) ((m : 𝕜) * x^(m-1)) s x :=
(has_deriv_at_fpow m hx).has_deriv_within_at
lemma differentiable_at_fpow (hx : x ≠ 0) : differentiable_at 𝕜 (λx, x^m) x :=
(has_deriv_at_fpow m hx).differentiable_at
lemma differentiable_within_at_fpow (hx : x ≠ 0) :
differentiable_within_at 𝕜 (λx, x^m) s x :=
(differentiable_at_fpow hx).differentiable_within_at
lemma differentiable_on_fpow (hs : (0:𝕜) ∉ s) : differentiable_on 𝕜 (λx, x^m) s :=
λ x hxs, differentiable_within_at_fpow (λ hx, hs $ hx ▸ hxs)
-- TODO : this is true at `x=0` as well
lemma deriv_fpow (hx : x ≠ 0) : deriv (λx, x^m) x = (m : 𝕜) * x^(m-1) :=
(has_deriv_at_fpow m hx).deriv
lemma deriv_within_fpow (hxs : unique_diff_within_at 𝕜 s x) (hx : x ≠ 0) :
deriv_within (λx, x^m) s x = (m : 𝕜) * x^(m-1) :=
(has_deriv_within_at_fpow m hx s).deriv_within hxs
lemma iter_deriv_fpow {k : ℕ} (hx : x ≠ 0) :
deriv^[k] (λx:𝕜, x^m) x = (∏ i in finset.range k, (m - i) : ℤ) * x^(m-k) :=
begin
induction k with k ihk generalizing x hx,
{ simp only [one_mul, finset.prod_range_zero, function.iterate_zero_apply, int.coe_nat_zero,
sub_zero, int.cast_one] },
{ rw [function.iterate_succ', finset.prod_range_succ, int.cast_mul, mul_assoc, mul_left_comm,
int.coe_nat_succ, ← sub_sub, ← ((has_deriv_at_fpow _ hx).const_mul _).deriv],
exact filter.eventually_eq.deriv_eq (eventually.mono (mem_nhds_sets is_open_ne hx) @ihk) }
end
end fpow
/-! ### Upper estimates on liminf and limsup -/
section real
variables {f : ℝ → ℝ} {f' : ℝ} {s : set ℝ} {x : ℝ} {r : ℝ}
lemma has_deriv_within_at.limsup_slope_le (hf : has_deriv_within_at f f' s x) (hr : f' < r) :
∀ᶠ z in 𝓝[s \ {x}] x, (z - x)⁻¹ * (f z - f x) < r :=
has_deriv_within_at_iff_tendsto_slope.1 hf (mem_nhds_sets is_open_Iio hr)
lemma has_deriv_within_at.limsup_slope_le' (hf : has_deriv_within_at f f' s x)
(hs : x ∉ s) (hr : f' < r) :
∀ᶠ z in 𝓝[s] x, (z - x)⁻¹ * (f z - f x) < r :=
(has_deriv_within_at_iff_tendsto_slope' hs).1 hf (mem_nhds_sets is_open_Iio hr)
lemma has_deriv_within_at.liminf_right_slope_le
(hf : has_deriv_within_at f f' (Ioi x) x) (hr : f' < r) :
∃ᶠ z in 𝓝[Ioi x] x, (z - x)⁻¹ * (f z - f x) < r :=
(hf.limsup_slope_le' (lt_irrefl x) hr).frequently
end real
section real_space
open metric
variables {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {s : set ℝ}
{x r : ℝ}
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`. -/
lemma has_deriv_within_at.limsup_norm_slope_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in 𝓝[s] x, ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
begin
have hr₀ : 0 < r, from lt_of_le_of_lt (norm_nonneg f') hr,
have A : ∀ᶠ z in 𝓝[s \ {x}] x, ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from (has_deriv_within_at_iff_tendsto_slope.1 hf).norm (mem_nhds_sets is_open_Iio hr),
have B : ∀ᶠ z in 𝓝[{x}] x, ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from mem_sets_of_superset self_mem_nhds_within
(singleton_subset_iff.2 $ by simp [hr₀]),
have C := mem_sup_sets.2 ⟨A, B⟩,
rw [← nhds_within_union, diff_union_self, nhds_within_union, mem_sup_sets] at C,
filter_upwards [C.1],
simp only [norm_smul, mem_Iio, normed_field.norm_inv],
exact λ _, id
end
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`.
This lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`
where `∥f z∥ - ∥f x∥` is replaced by `∥f z - f x∥`. -/
lemma has_deriv_within_at.limsup_slope_norm_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in 𝓝[s] x, ∥z - x∥⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
apply (hf.limsup_norm_slope_le hr).mono,
assume z hz,
refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz,
exact inv_nonneg.2 (norm_nonneg _)
end
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`. See also `has_deriv_within_at.limsup_norm_slope_le`
for a stronger version using limit superior and any set `s`. -/
lemma has_deriv_within_at.liminf_right_norm_slope_le
(hf : has_deriv_within_at f f' (Ioi x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in 𝓝[Ioi x] x, ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
(hf.limsup_norm_slope_le hr).frequently
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / (z - x)` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`.
See also
* `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using
limit superior and any set `s`;
* `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using
`∥f z - f x∥` instead of `∥f z∥ - ∥f x∥`. -/
lemma has_deriv_within_at.liminf_right_slope_norm_le
(hf : has_deriv_within_at f f' (Ioi x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in 𝓝[Ioi x] x, (z - x)⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
have := (hf.limsup_slope_norm_le hr).frequently,
refine this.mp (eventually.mono self_mem_nhds_within _),
assume z hxz hz,
rwa [real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz
end
end real_space
|
08836148ec03451884d0467576994ad65b22e2d0 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/idempotents/functor_extension.lean | cd9bdb86f05fcd2dc734b9af09fc0ae9426fc62f | [
"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 | 4,118 | lean | /-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import category_theory.idempotents.karoubi
/-!
# Extension of functors to the idempotent completion
In this file, we construct an extension `functor_extension₁`
of functors `C ⥤ karoubi D` to functors `karoubi C ⥤ karoubi D`.
TODO : Obtain the equivalences
`karoubi_universal₁ C D : C ⥤ karoubi D ≌ karoubi C ⥤ karoubi D`
for all categories, and
`karoubi_universal C D : C ⥤ D ≌ karoubi C ⥤ D`.
when `D` is idempotent complete
-/
open category_theory.category
open category_theory.idempotents.karoubi
namespace category_theory
namespace idempotents
variables {C D E : Type*} [category C] [category D] [category E]
/-- A natural transformation between functors `karoubi C ⥤ D` is determined
by its value on objects coming from `C`. -/
lemma nat_trans_eq {F G : karoubi C ⥤ D} (φ : F ⟶ G) (P : karoubi C) :
φ.app P = F.map (decomp_id_i P) ≫ φ.app P.X ≫ G.map (decomp_id_p P) :=
begin
rw [← φ.naturality, ← assoc, ← F.map_comp],
conv { to_lhs, rw [← id_comp (φ.app P), ← F.map_id], },
congr,
apply decomp_id,
end
namespace functor_extension₁
/-- The canonical extension of a functor `C ⥤ karoubi D` to a functor
`karoubi C ⥤ karoubi D` -/
@[simps]
def obj (F : C ⥤ karoubi D) : karoubi C ⥤ karoubi D :=
{ obj := λ P, ⟨(F.obj P.X).X, (F.map P.p).f,
by simpa only [F.map_comp, hom_ext] using F.congr_map P.idem⟩,
map := λ P Q f, ⟨(F.map f.f).f,
by simpa only [F.map_comp, hom_ext] using F.congr_map f.comm⟩, }
/-- Extension of a natural transformation `φ` between functors
`C ⥤ karoubi D` to a natural transformation between the
extension of these functors to `karoubi C ⥤ karoubi D` -/
@[simps]
def map {F G : C ⥤ karoubi D} (φ : F ⟶ G) : obj F ⟶ obj G :=
{ app := λ P,
{ f := (F.map P.p).f ≫ (φ.app P.X).f,
comm := begin
have h := φ.naturality P.p,
have h' := F.congr_map P.idem,
simp only [hom_ext, karoubi.comp_f, F.map_comp] at h h',
simp only [obj_obj_p, assoc, ← h],
slice_rhs 1 3 { rw [h', h'], },
end, },
naturality' := λ P Q f, begin
ext,
dsimp [obj],
have h := φ.naturality f.f,
have h' := F.congr_map (comp_p f),
have h'' := F.congr_map (p_comp f),
simp only [hom_ext, functor.map_comp, comp_f] at ⊢ h h' h'',
slice_rhs 2 3 { rw ← h, },
slice_lhs 1 2 { rw h', },
slice_rhs 1 2 { rw h'', },
end }
end functor_extension₁
variables (C D E)
/-- The canonical functor `(C ⥤ karoubi D) ⥤ (karoubi C ⥤ karoubi D)` -/
@[simps]
def functor_extension₁ : (C ⥤ karoubi D) ⥤ (karoubi C ⥤ karoubi D) :=
{ obj := functor_extension₁.obj,
map := λ F G, functor_extension₁.map,
map_id' := λ F, by { ext P, exact comp_p (F.map P.p), },
map_comp' := λ F G H φ φ', begin
ext P,
simp only [comp_f, functor_extension₁.map_app_f, nat_trans.comp_app, assoc],
have h := φ.naturality P.p,
have h' := F.congr_map P.idem,
simp only [hom_ext, comp_f, F.map_comp] at h h',
slice_rhs 2 3 { rw ← h, },
slice_rhs 1 2 { rw h', },
simp only [assoc],
end, }
lemma functor_extension₁_comp_whiskering_left_to_karoubi :
functor_extension₁ C D ⋙
(whiskering_left C (karoubi C) (karoubi D)).obj (to_karoubi C) = 𝟭 _ :=
begin
refine functor.ext _ _,
{ intro F,
refine functor.ext _ _,
{ intro X,
ext,
{ dsimp,
rw [id_comp, comp_id, F.map_id, id_eq], },
{ refl, }, },
{ intros X Y f,
ext,
dsimp,
simp only [comp_id, eq_to_hom_f, eq_to_hom_refl, comp_p, functor_extension₁.obj_obj_p,
to_karoubi_obj_p, comp_f],
dsimp,
simp only [functor.map_id, id_eq, p_comp], }, },
{ intros F G φ,
ext X,
dsimp,
simp only [eq_to_hom_app, F.map_id, comp_f, eq_to_hom_f, id_eq, p_comp,
eq_to_hom_refl, comp_id, comp_p, functor_extension₁.obj_obj_p,
to_karoubi_obj_p, F.map_id X], },
end
end idempotents
end category_theory
|
56904e7ed227c1402e9b1cee323f8d3734ddc837 | 41e069072396dcd54bd9fdadb27cfd35fd07016a | /src/apps/examples.lean | 15659d9544c01ff6e6a17861fd49f3df2132bd27 | [
"MIT"
] | permissive | semorrison/ModalTab | 438ad601bd2631ab9cfe1e61f0d1337a36e2367e | cc94099194a2b69f84eb7a770b7aac711825179f | refs/heads/master | 1,585,939,884,891 | 1,540,961,947,000 | 1,540,961,947,000 | 155,500,181 | 0 | 0 | MIT | 1,540,961,175,000 | 1,540,961,175,000 | null | UTF-8 | Lean | false | false | 358 | lean | import .topo_translation ..K.jump
open nnf
def boom : nnf := dia (and (var 1) (neg 1))
-- #eval is_sat [boom]
-- #check tableau [boom]
def topo_fact_of (φ : nnf) : psum (∀ (α) (tm : topo_model α) s, ¬ topo_force tm s φ) unit :=
match tableau [φ] with
| node.closed _ h _ := psum.inl $ not_topo_force_of_unsat h
| node.open_ _ := psum.inr ()
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.